Skip to content

Commit 0a28509

Browse files
committed
📚 Updated documentation
1 parent 3e0d2d6 commit 0a28509

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ A light-weight library for management of hierachical content. Most solutions I f
88
2. Event publishing/subscription from items
99
- ✔️ Subscribing to items checked event (based on type)
1010
3. :heavy_check_mark: Moving Items between folders (drag-and-drop)
11-
4. Custom formating of items on the tree based on the `type` property. (Coming soon)
11+
4. Custom formating of items on the tree based on the `type` property.
1212
- :heavy_check_mark: Customising Icons
1313
- ✔️ Rendering (checkboxes or plain content)
14-
- Custom Context Menu depending on item type.
14+
1515
5. Programmatically toggle item visibility based on the `type` property.
1616
6. Sorting items alphametically or grouping based on types
17+
7. Disabling and Enabling Item
18+
8. Double clicking to rename item
19+
9. Programmatically determining what item can be dragged into another item.
20+
10. Custom Context Menu depending on item type.
1721

1822
## What it looks like.
1923

@@ -178,4 +182,46 @@ export default class App extends Vue {
178182
]
179183
}
180184
```
185+
## Properties
186+
187+
| Property | Default | Description |
188+
| ----------- | ----------- |-------------
189+
| treeViewItems | Empty array | An array of `TreeViewItem`. |
190+
| hideGuideLines | `false` | Determines the visibility of the guidelines
191+
| selectionMode | `Multiple` | `Single` or `Multiple`. This determines how many items can be simultaneously selected/checked in the tree. |
192+
193+
<br>
194+
195+
## :construction: Managing Default Behaviors (WIP)
196+
197+
Out-of-the-box, `v-tree-vue` ships with default behaviors like double clicking an item to rename, pushing the `DEL` key to delete and moving (drag-and-drop) items into new locations. However, this is totally customisable. The default command API exposes the following configurations:
198+
199+
```ts
200+
export interface DefaultBehaviors {
201+
// Allow customisation of items that can be renamed on the tree.
202+
enableRenaming(type: string): void;
203+
// Allow customisation of items that can be deleted on the tree.
204+
enableDeleting(type: string): void;
205+
// Allow registration of handler to be called when an item of a particular type has been deleted.
206+
registerItemDeletedHandler(type: string, callback: (item: TreeViewItem) => Promise<TreeViewItem>): void;
207+
// Allow registration of a handler to be called when an item of a particular type has been renamed.
208+
registerItemRenamedHandler(type: string, callback: (renamedItem: TreeViewItem) => Promise<TreeViewItem>): void;
209+
// Allow registration of a handler to be called to verify if a drag-and-drop move operation is valid.
210+
registerItemCanMoveHandler(canItemMoveCallBack: (movingItem: TreeViewItem, destinationItem: TreeViewItem) => Promise<boolean>): void;
211+
// Allow registration of a handler to be called when a move operation is succesful. The moved item property will contain
212+
// the information of the parentID of it's new parent or undefined if it was moved to the root directory.
213+
registerItemMovedHandler(callBack: (movedItem: TreeViewItem) => Promise<TreeViewItem>): void;
214+
}
215+
```
216+
217+
## One Handler for all Types ? (We've got you covered).
218+
219+
In many cases and existing apps, a single handler is called whenever an item is renamed or deleted irrespective of it's type. This handler may then make an API call that takes care of the rest.
220+
221+
To do so when calling the `registerItemRenamedHandler` or `registerItemDeletedHandler` pass 'ANY_TYPE' as the `type` property. The `callback` will be called whenever ANY item is renamed or deleted.
222+
223+
```ts
224+
import { ANY_TYPE } from '@/constants.ts';
225+
```
181226

227+
> This avoids moving magic strings around and provides a central point of change in the future should the need arise. However, you can get rid of the extra import statement and use a string with value 'ANY_TYPE'.

0 commit comments

Comments
 (0)