@ninebone/util 1.0.15 → 1.0.17
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 +22 -8
- 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.17"}/dist/css/nine-util.css";
|
|
1286
1286
|
${customImport}
|
|
1287
1287
|
</style>
|
|
1288
1288
|
${gripTmpl}
|
|
@@ -1651,7 +1651,14 @@ class NinePopup extends HTMLElement {
|
|
|
1651
1651
|
}
|
|
1652
1652
|
if (!customElements.get("nine-popup")) customElements.define("nine-popup", NinePopup);
|
|
1653
1653
|
const TreeUtil = {
|
|
1654
|
-
|
|
1654
|
+
/**
|
|
1655
|
+
* @param {Array} data - 원본 데이터 배열
|
|
1656
|
+
* @param {String} sortField - 정렬 기준 필드명
|
|
1657
|
+
* @param {String} idField - 고유 ID 필드명 (기본: 'id')
|
|
1658
|
+
* @param {String} parentIdField - 부모 ID 필드명 (기본: 'parentId')
|
|
1659
|
+
*/
|
|
1660
|
+
sort: (data, idField = "id", parentIdField = "parentId", sortField = "sortOrder") => {
|
|
1661
|
+
if (!data || data.length === 0) return [];
|
|
1655
1662
|
const map = {};
|
|
1656
1663
|
data.forEach((item) => {
|
|
1657
1664
|
map[item[idField]] = { ...item, children: [] };
|
|
@@ -1659,8 +1666,9 @@ const TreeUtil = {
|
|
|
1659
1666
|
const roots = [];
|
|
1660
1667
|
data.forEach((item) => {
|
|
1661
1668
|
const node = map[item[idField]];
|
|
1662
|
-
|
|
1663
|
-
|
|
1669
|
+
const parentId = item[parentIdField];
|
|
1670
|
+
if (parentId && map[parentId]) {
|
|
1671
|
+
map[parentId].children.push(node);
|
|
1664
1672
|
} else {
|
|
1665
1673
|
roots.push(node);
|
|
1666
1674
|
}
|
|
@@ -1669,16 +1677,22 @@ const TreeUtil = {
|
|
|
1669
1677
|
nodes.sort((a, b) => {
|
|
1670
1678
|
const valA = a[sortField];
|
|
1671
1679
|
const valB = b[sortField];
|
|
1672
|
-
|
|
1680
|
+
if (typeof valA === "number" && typeof valB === "number") {
|
|
1681
|
+
return valA - valB;
|
|
1682
|
+
}
|
|
1683
|
+
return String(valA || "").localeCompare(String(valB || ""));
|
|
1684
|
+
});
|
|
1685
|
+
nodes.forEach((node) => {
|
|
1686
|
+
if (node.children.length > 0) sortNodes(node.children);
|
|
1673
1687
|
});
|
|
1674
|
-
nodes.forEach((node) => sortNodes(node.children));
|
|
1675
1688
|
};
|
|
1676
1689
|
sortNodes(roots);
|
|
1677
1690
|
const result = [];
|
|
1678
1691
|
const flatten = (nodes) => {
|
|
1679
1692
|
nodes.forEach((node) => {
|
|
1680
|
-
|
|
1681
|
-
|
|
1693
|
+
const { children, ...item } = node;
|
|
1694
|
+
result.push(item);
|
|
1695
|
+
if (children.length > 0) flatten(children);
|
|
1682
1696
|
});
|
|
1683
1697
|
};
|
|
1684
1698
|
flatten(roots);
|