onchain-utility 0.0.7 → 0.0.8
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/OnchainUtility.js +22 -0
- package/dist/OnchainUtility.mjs +22 -1
- package/dist/Tree.js +22 -0
- package/dist/Tree.mjs +22 -1
- package/package.json +1 -1
- package/src/Tree/index.ts +23 -0
package/dist/OnchainUtility.js
CHANGED
|
@@ -1607,6 +1607,27 @@ function insert({
|
|
|
1607
1607
|
}
|
|
1608
1608
|
}
|
|
1609
1609
|
|
|
1610
|
+
/** 树结构搜索 */
|
|
1611
|
+
function treeSearch({
|
|
1612
|
+
data,
|
|
1613
|
+
searchValue,
|
|
1614
|
+
childrenKey = 'children'
|
|
1615
|
+
}) {
|
|
1616
|
+
return data.map(row => {
|
|
1617
|
+
const children = treeSearch({
|
|
1618
|
+
childrenKey,
|
|
1619
|
+
data: row[childrenKey] || [],
|
|
1620
|
+
searchValue
|
|
1621
|
+
});
|
|
1622
|
+
if (searchValue(row) || children.length) {
|
|
1623
|
+
return {
|
|
1624
|
+
...row,
|
|
1625
|
+
[childrenKey]: children
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
}).filter(row => !!row);
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1610
1631
|
exports._isMoment = _isMoment;
|
|
1611
1632
|
exports.arrayAttributeFlat = arrayAttributeFlat;
|
|
1612
1633
|
exports.asyncDfs = asyncDfs;
|
|
@@ -1640,6 +1661,7 @@ exports.t = t;
|
|
|
1640
1661
|
exports.toRawType = toRawType;
|
|
1641
1662
|
exports.toTypeString = toTypeString;
|
|
1642
1663
|
exports.translateI18n = translateI18n;
|
|
1664
|
+
exports.treeSearch = treeSearch;
|
|
1643
1665
|
exports.upgrade = upgrade;
|
|
1644
1666
|
exports.useReactive = useReactive;
|
|
1645
1667
|
exports.useShallowReactive = useShallowReactive;
|
package/dist/OnchainUtility.mjs
CHANGED
|
@@ -1605,4 +1605,25 @@ function insert({
|
|
|
1605
1605
|
}
|
|
1606
1606
|
}
|
|
1607
1607
|
|
|
1608
|
-
|
|
1608
|
+
/** 树结构搜索 */
|
|
1609
|
+
function treeSearch({
|
|
1610
|
+
data,
|
|
1611
|
+
searchValue,
|
|
1612
|
+
childrenKey = 'children'
|
|
1613
|
+
}) {
|
|
1614
|
+
return data.map(row => {
|
|
1615
|
+
const children = treeSearch({
|
|
1616
|
+
childrenKey,
|
|
1617
|
+
data: row[childrenKey] || [],
|
|
1618
|
+
searchValue
|
|
1619
|
+
});
|
|
1620
|
+
if (searchValue(row) || children.length) {
|
|
1621
|
+
return {
|
|
1622
|
+
...row,
|
|
1623
|
+
[childrenKey]: children
|
|
1624
|
+
};
|
|
1625
|
+
}
|
|
1626
|
+
}).filter(row => !!row);
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
export { _isMoment, arrayAttributeFlat, asyncDfs, base64ToFile, base64ToMimeType, baseTemplate, bfs, createEnumObject, deleteTreeNodes, dfs, downgrade, generateSecureUUID, generatedAcrossHierarchySort, getBase64Regular, getHTMLTagString, getI18nText, getSiblings, getTreeRelation, hasOwnProperty, initTranslateI18nFn, insert, isEmptyObject, isIntegerKey, levelTransformTree, makeDestructurable, mergeAdjacent, movUp, move, moveDown, t, toRawType, toTypeString, translateI18n, treeSearch, upgrade, useReactive, useShallowReactive, useStore };
|
package/dist/Tree.js
CHANGED
|
@@ -600,6 +600,27 @@ function insert({
|
|
|
600
600
|
}
|
|
601
601
|
}
|
|
602
602
|
|
|
603
|
+
/** 树结构搜索 */
|
|
604
|
+
function treeSearch({
|
|
605
|
+
data,
|
|
606
|
+
searchValue,
|
|
607
|
+
childrenKey = 'children'
|
|
608
|
+
}) {
|
|
609
|
+
return data.map(row => {
|
|
610
|
+
const children = treeSearch({
|
|
611
|
+
childrenKey,
|
|
612
|
+
data: row[childrenKey] || [],
|
|
613
|
+
searchValue
|
|
614
|
+
});
|
|
615
|
+
if (searchValue(row) || children.length) {
|
|
616
|
+
return {
|
|
617
|
+
...row,
|
|
618
|
+
[childrenKey]: children
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
}).filter(row => !!row);
|
|
622
|
+
}
|
|
623
|
+
|
|
603
624
|
exports.arrayAttributeFlat = arrayAttributeFlat;
|
|
604
625
|
exports.deleteTreeNodes = deleteTreeNodes;
|
|
605
626
|
exports.downgrade = downgrade;
|
|
@@ -612,4 +633,5 @@ exports.mergeAdjacent = mergeAdjacent;
|
|
|
612
633
|
exports.movUp = movUp;
|
|
613
634
|
exports.move = move;
|
|
614
635
|
exports.moveDown = moveDown;
|
|
636
|
+
exports.treeSearch = treeSearch;
|
|
615
637
|
exports.upgrade = upgrade;
|
package/dist/Tree.mjs
CHANGED
|
@@ -598,4 +598,25 @@ function insert({
|
|
|
598
598
|
}
|
|
599
599
|
}
|
|
600
600
|
|
|
601
|
-
|
|
601
|
+
/** 树结构搜索 */
|
|
602
|
+
function treeSearch({
|
|
603
|
+
data,
|
|
604
|
+
searchValue,
|
|
605
|
+
childrenKey = 'children'
|
|
606
|
+
}) {
|
|
607
|
+
return data.map(row => {
|
|
608
|
+
const children = treeSearch({
|
|
609
|
+
childrenKey,
|
|
610
|
+
data: row[childrenKey] || [],
|
|
611
|
+
searchValue
|
|
612
|
+
});
|
|
613
|
+
if (searchValue(row) || children.length) {
|
|
614
|
+
return {
|
|
615
|
+
...row,
|
|
616
|
+
[childrenKey]: children
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
}).filter(row => !!row);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
export { arrayAttributeFlat, deleteTreeNodes, downgrade, generatedAcrossHierarchySort, getSiblings, getTreeRelation, insert, levelTransformTree, mergeAdjacent, movUp, move, moveDown, treeSearch, upgrade };
|
package/package.json
CHANGED
package/src/Tree/index.ts
CHANGED
|
@@ -670,3 +670,26 @@ export function insert<T extends Item>({
|
|
|
670
670
|
}
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
|
+
|
|
674
|
+
/** 树结构搜索 */
|
|
675
|
+
export function treeSearch<T extends Record<string, any>>({
|
|
676
|
+
data,
|
|
677
|
+
searchValue,
|
|
678
|
+
childrenKey = 'children',
|
|
679
|
+
}: {
|
|
680
|
+
data: T[];
|
|
681
|
+
searchValue: (item: T) => boolean;
|
|
682
|
+
childrenKey?: string;
|
|
683
|
+
}) {
|
|
684
|
+
return data
|
|
685
|
+
.map((row) => {
|
|
686
|
+
const children: T[] = treeSearch({ childrenKey, data: row[childrenKey] || [], searchValue });
|
|
687
|
+
if (searchValue(row) || children.length) {
|
|
688
|
+
return {
|
|
689
|
+
...row,
|
|
690
|
+
[childrenKey]: children,
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
})
|
|
694
|
+
.filter((row): row is T => !!row);
|
|
695
|
+
}
|