@ninebone/util 1.0.14 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/nine-util.js +31 -19
- package/dist/nine-util.js.map +1 -1
- package/dist/nine-util.umd.js +1 -1
- package/dist/nine-util.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/nine-util.js
CHANGED
|
@@ -1282,7 +1282,7 @@ class UxSplitter extends HTMLElement {
|
|
|
1282
1282
|
const htmlTmpl = document.createElement("template");
|
|
1283
1283
|
htmlTmpl.innerHTML = `
|
|
1284
1284
|
<style>
|
|
1285
|
-
@import "https://cdn.jsdelivr.net/npm/@ninebone/util@${"1.0.
|
|
1285
|
+
@import "https://cdn.jsdelivr.net/npm/@ninebone/util@${"1.0.15"}/dist/css/nine-util.css";
|
|
1286
1286
|
${customImport}
|
|
1287
1287
|
</style>
|
|
1288
1288
|
${gripTmpl}
|
|
@@ -1651,26 +1651,38 @@ class NinePopup extends HTMLElement {
|
|
|
1651
1651
|
}
|
|
1652
1652
|
if (!customElements.get("nine-popup")) customElements.define("nine-popup", NinePopup);
|
|
1653
1653
|
const TreeUtil = {
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
}
|
|
1667
|
-
const valA = a[sortField];
|
|
1668
|
-
const valB = b[sortField];
|
|
1669
|
-
if (typeof valA === "number" && typeof valB === "number") {
|
|
1670
|
-
return valA - valB;
|
|
1654
|
+
sort: (data, sortField, idField = "id", parentIdField = "parentId") => {
|
|
1655
|
+
const map = {};
|
|
1656
|
+
data.forEach((item) => {
|
|
1657
|
+
map[item[idField]] = { ...item, children: [] };
|
|
1658
|
+
});
|
|
1659
|
+
const roots = [];
|
|
1660
|
+
data.forEach((item) => {
|
|
1661
|
+
const node = map[item[idField]];
|
|
1662
|
+
if (item[parentIdField] && map[item[parentIdField]]) {
|
|
1663
|
+
map[item[parentIdField]].children.push(node);
|
|
1664
|
+
} else {
|
|
1665
|
+
roots.push(node);
|
|
1671
1666
|
}
|
|
1672
|
-
return String(valA || "").localeCompare(String(valB || ""));
|
|
1673
1667
|
});
|
|
1668
|
+
const sortNodes = (nodes) => {
|
|
1669
|
+
nodes.sort((a, b) => {
|
|
1670
|
+
const valA = a[sortField];
|
|
1671
|
+
const valB = b[sortField];
|
|
1672
|
+
return typeof valA === "number" ? valA - valB : String(valA || "").localeCompare(String(valB || ""));
|
|
1673
|
+
});
|
|
1674
|
+
nodes.forEach((node) => sortNodes(node.children));
|
|
1675
|
+
};
|
|
1676
|
+
sortNodes(roots);
|
|
1677
|
+
const result = [];
|
|
1678
|
+
const flatten = (nodes) => {
|
|
1679
|
+
nodes.forEach((node) => {
|
|
1680
|
+
result.push(node);
|
|
1681
|
+
if (node.children.length > 0) flatten(node.children);
|
|
1682
|
+
});
|
|
1683
|
+
};
|
|
1684
|
+
flatten(roots);
|
|
1685
|
+
return result;
|
|
1674
1686
|
}
|
|
1675
1687
|
};
|
|
1676
1688
|
class NineUtil {
|