Skip to content

Commit 01b53bf

Browse files
committed
Starting docs.
1 parent d9cc15b commit 01b53bf

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

src/pg/tree/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@
22

33
The `pg-tree` is used to render a tree list of items.
44

5+
- Folder / Item symbols
6+
- Drag and Drop
7+
- Context Menu
8+
59
## Usage
610

11+
While setup for a normal file tree this can be used for any folder structure.

src/pg/tree/__examples__/basic/basic.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ export default class XPgTreeBasic extends HTMLElement {
7070

7171
connectedCallback() {
7272
this.$tree.addEventListener('action', (e: any) => {
73+
const item = e.detail.item as SelectedTreeItem;
7374
// action clicked
74-
const { index, actionIndex } = e.detail;
75-
const action = this.$tree.items[index].actions[actionIndex];
75+
const { actionIndex } = e.detail;
76+
const action = item.getData().actions[actionIndex];
7677
const { enabled } = action;
7778
if (actionIndex === 0 && enabled) {
7879
action.icon = IconEyeOff;

src/pg/tree/tree.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ export default class PgTree extends HTMLElement {
3232
return PgTreeItem;
3333
}
3434
});
35+
this.$items.addEventListener('action', (e: any) => {
36+
e.stopPropagation();
37+
console.log(e.detail);
38+
this.dispatchEvent(new CustomEvent('action', {
39+
detail: {
40+
actionIndex: e.detail.actionIndex,
41+
item: this.#wrap(e.detail.indexes)
42+
}
43+
}));
44+
});
3545
this.$items.addEventListener('toggle', (e: any) => {
3646
const { indexes } = e.detail;
3747
let item = this.#getItem(indexes);
@@ -61,9 +71,6 @@ export default class PgTree extends HTMLElement {
6171
}),
6272
}
6373
}));
64-
//Array.from(this.#selectedIndexes).map(([key, value]) => {
65-
// return this.#getItem(value);
66-
// })
6774
});
6875
this.$items.addEventListener('keydown', (e: any) => {
6976
if (e.key === 'Delete') {

src/pg/treeItem/treeItem.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class PgTreeItem extends HTMLElement {
3838

3939
connectedCallback() {
4040
this.$toggle.addEventListener('click', this.#handleToggleClick.bind(this));
41-
this.$item.addEventListener('action', this.#handleAction.bind(this));
41+
this.$item.addEventListener('action', this.#handleItemAction.bind(this));
4242
this.$item.addEventListener('pointerenter', this.#handlePointerEnter.bind(this));
4343
this.$item.addEventListener('pointerleave', this.#handlePointerLeave.bind(this));
4444
this.$item.addEventListener('dragstart', this.#handleDragStart.bind(this));
@@ -52,6 +52,7 @@ export default class PgTreeItem extends HTMLElement {
5252
this.$input.addEventListener('blur', this.#handleBlur.bind(this));
5353
this.$input.addEventListener('keydown', this.#handleInputKeyDown.bind(this));
5454
// Append Indexes
55+
this.$items.addEventListener('action', this.#handleAction.bind(this));
5556
this.$items.addEventListener('toggle', this.#handleToggle.bind(this));
5657
this.$items.addEventListener('select', this.#handleSelect.bind(this));
5758
this.$items.addEventListener('rename', this.#handleRename.bind(this));
@@ -196,18 +197,22 @@ export default class PgTreeItem extends HTMLElement {
196197
}));
197198
}
198199

199-
#handleAction(e) {
200+
#handleItemAction(e) {
200201
e.stopPropagation();
201202
this.dispatchEvent(new CustomEvent('action', {
202203
bubbles: true,
203204
composed: true,
204205
detail: {
205-
index: this.index,
206+
indexes: [this.index],
206207
actionIndex: e.detail.index
207208
}
208209
}));
209210
}
210211

212+
#handleAction(e) {
213+
e.detail.indexes.unshift(this.index);
214+
}
215+
211216
#handleToggle(e: any) {
212217
e.detail.indexes.unshift(this.index);
213218
}

0 commit comments

Comments
 (0)