Skip to content

Commit e9fce3c

Browse files
committed
Breaking more
1 parent e104a48 commit e9fce3c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ export default class XPgTreeBasic extends HTMLElement {
9191
}
9292
});
9393
this.$tree.addEventListener('move', (e: any) => {
94-
console.log('move', e.detail.indexes, e.detail.position);
95-
this.#selectedItems.forEach((item) => {
96-
94+
this.#selectedItems.forEach((item: any) => {
95+
item.move(e.detail.item, e.detail.position);
9796
});
9897
});
9998
this.$tree.addEventListener('rename', (e: any) => {

src/pg/tree/tree.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class PgTree extends HTMLElement {
5151
e.stopPropagation();
5252
this.dispatchEvent(new CustomEvent('move', {
5353
detail: {
54-
indexes,
54+
item: this.#wrap(e.detail.indexes),
5555
position
5656
}
5757
}));
@@ -177,8 +177,21 @@ export default class PgTree extends HTMLElement {
177177
}
178178
return this.#getItem(parent);
179179
},
180-
move: (newIndexes) => {
181-
180+
move: (item, position) => {
181+
console.log(item, position);
182+
const index = item.indexes[item.indexes.length - 1];
183+
const parent = item.indexes.slice(0, item.indexes.length - 1);
184+
const cache = this.#getItem(indexes);
185+
this.#removeItem(indexes);
186+
if (position === 'on') {
187+
this.#getItem(item.indexes).items.push(cache);
188+
this.#getItem(item.indexes).expanded = true;
189+
} else if (parent.length === 0) {
190+
this.items.splice(position === 'after' ? index + 1 : index, 0, cache);
191+
} else {
192+
this.#getItem(parent).items.splice(position === 'after' ? index + 1 : index, 0, cache);
193+
}
194+
this.#selectedIndexes.clear();
182195
}
183196
}
184197
}

0 commit comments

Comments
 (0)