Libraries & Collections: Add sibling after *all* children

Not only direct children
This commit is contained in:
Abe Jellinek 2024-01-03 10:13:49 -08:00 committed by Dan Stillman
parent f0c9e42a8e
commit ccdd6c08ba

View file

@ -166,14 +166,14 @@ import { getCSSIcon } from 'components/icons';
return this._body.querySelector(`.row[data-id="${obj.treeViewID}"]`);
}
_getChildren(row = null) {
_getChildren(row = null, deep = false) {
let rows = Array.from(this._body.querySelectorAll('.row'));
let startIndex = row ? rows.indexOf(row) + 1 : 0;
let level = row ? parseInt(row.dataset.level) + 1 : 0;
let children = [];
for (let i = startIndex; i < rows.length; i++) {
let childLevel = parseInt(rows[i].dataset.level);
if (childLevel == level) {
if (childLevel == level || deep && childLevel > level) {
children.push(rows[i]);
}
else if (childLevel < level) {
@ -210,7 +210,7 @@ import { getCSSIcon } from 'components/icons';
if (!added) {
if (siblings.length) {
let lastSibling = siblings[siblings.length - 1];
let childrenOfLastSibling = this._getChildren(lastSibling);
let childrenOfLastSibling = this._getChildren(lastSibling, true);
if (childrenOfLastSibling.length) {
childrenOfLastSibling[childrenOfLastSibling.length - 1].after(row);
}