@ninebone/util 1.0.14 → 1.0.16
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 +41 -15
- 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.16"}/dist/css/nine-util.css";
|
|
1286
1286
|
${customImport}
|
|
1287
1287
|
</style>
|
|
1288
1288
|
${gripTmpl}
|
|
@@ -1652,25 +1652,51 @@ class NinePopup extends HTMLElement {
|
|
|
1652
1652
|
if (!customElements.get("nine-popup")) customElements.define("nine-popup", NinePopup);
|
|
1653
1653
|
const TreeUtil = {
|
|
1654
1654
|
/**
|
|
1655
|
-
* 계층형 트리 데이터를 특정 필드로 정렬하는 만능 엔진
|
|
1656
1655
|
* @param {Array} data - 원본 데이터 배열
|
|
1657
1656
|
* @param {String} sortField - 정렬 기준 필드명
|
|
1658
|
-
* @param {String}
|
|
1657
|
+
* @param {String} idField - 고유 ID 필드명 (기본: 'id')
|
|
1658
|
+
* @param {String} parentIdField - 부모 ID 필드명 (기본: 'parentId')
|
|
1659
1659
|
*/
|
|
1660
|
-
sort: (data,
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
const
|
|
1669
|
-
|
|
1670
|
-
|
|
1660
|
+
sort: (data, idField = "id", parentIdField = "parentId", sortField = "sortOrder") => {
|
|
1661
|
+
if (!data || data.length === 0) return [];
|
|
1662
|
+
const map = {};
|
|
1663
|
+
data.forEach((item) => {
|
|
1664
|
+
map[item[idField]] = { ...item, children: [] };
|
|
1665
|
+
});
|
|
1666
|
+
const roots = [];
|
|
1667
|
+
data.forEach((item) => {
|
|
1668
|
+
const node = map[item[idField]];
|
|
1669
|
+
const parentId = item[parentIdField];
|
|
1670
|
+
if (parentId && map[parentId]) {
|
|
1671
|
+
map[parentId].children.push(node);
|
|
1672
|
+
} else {
|
|
1673
|
+
roots.push(node);
|
|
1671
1674
|
}
|
|
1672
|
-
return String(valA || "").localeCompare(String(valB || ""));
|
|
1673
1675
|
});
|
|
1676
|
+
const sortNodes = (nodes) => {
|
|
1677
|
+
nodes.sort((a, b) => {
|
|
1678
|
+
const valA = a[sortField];
|
|
1679
|
+
const valB = b[sortField];
|
|
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);
|
|
1687
|
+
});
|
|
1688
|
+
};
|
|
1689
|
+
sortNodes(roots);
|
|
1690
|
+
const result = [];
|
|
1691
|
+
const flatten = (nodes) => {
|
|
1692
|
+
nodes.forEach((node) => {
|
|
1693
|
+
const { children, ...item } = node;
|
|
1694
|
+
result.push(item);
|
|
1695
|
+
if (children.length > 0) flatten(children);
|
|
1696
|
+
});
|
|
1697
|
+
};
|
|
1698
|
+
flatten(roots);
|
|
1699
|
+
return result;
|
|
1674
1700
|
}
|
|
1675
1701
|
};
|
|
1676
1702
|
class NineUtil {
|