Skip to content

Commit 2cadeab

Browse files
committed
Updated documentation.
1 parent f0239be commit 2cadeab

File tree

4 files changed

+36
-49
lines changed

4 files changed

+36
-49
lines changed

Examples/simple-tree-view.vue

Whitespace-only changes.

README.md

+35-49
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
A light-weight library for management of hierachical content. Most solutions I found did not offer the depth of flexibility I needed with the tree. I decided to solve my problem and also give back to the Vue community. Feel free to log issues, I will jump on them at the slightest opportunity. 😊
44

5-
## What it does.
5+
## Features
66

77
1. :heavy_check_mark: Hierachical rendering of content.
88
2. ✔️ Subscribing to items checked event (based on type)
99
3. :heavy_check_mark: Moving Items between folders (drag-and-drop)
1010
4. :heavy_check_mark: Customising Item Rendering based on item type
1111
5. ✔️ Rendering selectable items like checkboxes or plain content
1212
6. ✔️ Double clicking to rename item
13-
7. Programmatically toggle item visibility based on the `type` property.
14-
8. Sorting items alphametically or grouping based on types
15-
9. Disabling and Enabling Item
16-
10. Programmatically determining what item can be dragged into another item.
17-
11. Custom Context Menu depending on item type.
1813

19-
## What it looks like.
14+
## Features in Development
15+
1. Programmatically toggle item visibility based on the `type` property.
16+
2. Sorting items alphametically or grouping based on types
17+
3. Disabling and Enabling Item(s)
18+
4. Programmatically determining what item can be dragged into another item.
19+
5. -Custom Context Menu depending on item type.
20+
2021

2122
![image](https://user-images.githubusercontent.com/39003759/125176959-e320f580-e1cf-11eb-886f-7a9c8808c178.png)
2223

23-
## How to use (Basic).
24-
24+
### Basic Component Rendering
2525
``` html
2626
<template>
2727
<tree-view :treeViewItems="treeViewNodes" />
@@ -71,10 +71,9 @@ You can customise item based on their `type` property.
7171

7272
```
7373

74-
### Making Items Checkable Or Plain TreeView Item
75-
76-
`Tree-vue` supports 2-major types of tree items. Checkable items or plain items. You can set your preferences for a particular `type`. To do so listen to the createdEvent of the `tree-view` component.
74+
## Advanced Customisation
7775

76+
The library provides a way to further customise the tree view by listening to the `v-on:created` event from the tree-view component. The payload surplied provides robust set of options for configuring the tree.
7877

7978
#### Schema of CreatedEvent Payload
8079

@@ -86,7 +85,29 @@ You can customise item based on their `type` property.
8685
}
8786
```
8887

89-
#### Example
88+
Schema for `ItemTypeCustomisations`
89+
90+
```ts
91+
export interface ItemTypeCustomisations {
92+
isDropValid(droppedNode: TreeViewItem, dropHost: TreeViewItem): boolean;
93+
makeItemsCheckable(types: string[]): void;
94+
registerItemRenamedHandler(type: string, callback: (renamedItem: TreeViewItem) => Promise<TreeViewItem>): void;
95+
registerDragAndDropValidator(canItemMoveCallBack: (movingItem: TreeViewItem, destinationItem: TreeViewItem) => boolean): void;
96+
disableDragAndDrop(): void;
97+
98+
getCustomisation(type: string): Customisations;
99+
getRenameHandler(type: string): (item: TreeViewItem) => Promise<TreeViewItem>;
100+
101+
registerItemDeletedHandler(type: string, callback: (item: TreeViewItem) => Promise<boolean>): void;
102+
registerItemMovedHandler(callBack: (movedItem: TreeViewItem) => Promise<TreeViewItem>): void;
103+
104+
registerAnyItemDeleted(callback: (item: TreeViewItem) => Promise<boolean>): void;
105+
registerAnyItemRenamed(callback: (item: TreeViewItem) => Promise<TreeViewItem>): void;
106+
registerAnyItemDragAndDrop(): void;
107+
}
108+
```
109+
110+
## Example
90111

91112
```html
92113
<template>
@@ -107,6 +128,7 @@ export default class App extends Vue {
107128
customiseTreeView(treeCreatedEvent: TreeViewCreatedEventPayload) {
108129
const customisations = treeCreatedEvent.itemCustomisations;
109130

131+
// `Tree-vue` supports 2-major types of tree items. Checkable items or plain items.
110132
customisations.makeItemsCheckable([".doc", ".excel", "media" ]);
111133
}
112134

@@ -183,39 +205,3 @@ export default class App extends Vue {
183205
| treeViewItems | Empty array | An array of `TreeViewItem`. |
184206
| hideGuideLines | `false` | Determines the visibility of the guidelines
185207
| selectionMode | `Multiple` | `Single` or `Multiple`. This determines how many items can be simultaneously selected/checked in the tree. |
186-
187-
<br>
188-
189-
## :construction: Managing Default Behaviors (WIP)
190-
191-
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:
192-
193-
```ts
194-
export interface ItemBehavior {
195-
// Allow customisation of items that can be renamed on the tree.
196-
enableRenaming(type: string): void;
197-
// Allow customisation of items that can be deleted on the tree.
198-
enableDeleting(type: string): void;
199-
// Allow registration of handler to be called when an item of a particular type has been deleted.
200-
registerItemDeletedHandler(type: string, callback: (item: TreeViewItem) => Promise<TreeViewItem>): void;
201-
// Allow registration of a handler to be called when an item of a particular type has been renamed.
202-
registerItemRenamedHandler(type: string, callback: (renamedItem: TreeViewItem) => Promise<TreeViewItem>): void;
203-
// Allow registration of a handler to be called to verify if a drag-and-drop move operation is valid.
204-
registerItemCanMoveHandler(canItemMoveCallBack: (movingItem: TreeViewItem, destinationItem: TreeViewItem) => Promise<boolean>): void;
205-
// Allow registration of a handler to be called when a move operation is succesful. The moved item property will contain
206-
// the information of the parentID of it's new parent or undefined if it was moved to the root directory.
207-
registerItemMovedHandler(callBack: (movedItem: TreeViewItem) => Promise<TreeViewItem>): void;
208-
}
209-
```
210-
211-
## One Handler for all Types ? (We've got you covered).
212-
213-
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.
214-
215-
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.
216-
217-
```ts
218-
import { ANY_TYPE } from '@/constants.ts';
219-
```
220-
221-
> 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'.

src/businessLogic/itemCustomisations/itemCustomisations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const ItemCustomisations: ItemTypeCustomisations = {
6161
},
6262

6363
isDropValid(droppedNode: TreeViewItem, dropHost: TreeViewItem): boolean {
64+
if (!canItemDrop) return false;
6465
return canItemDrop(droppedNode, dropHost);
6566
},
6667

src/components/treeViewItem/treeviewItemView.scss

Whitespace-only changes.

0 commit comments

Comments
 (0)