react-native-tree-multi-select 0.5.0

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.
Files changed (108) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +124 -0
  3. package/android/build.gradle +94 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/java/com/treemultiselect/TreeMultiSelectModule.kt +25 -0
  7. package/android/src/main/java/com/treemultiselect/TreeMultiSelectPackage.kt +17 -0
  8. package/ios/TreeMultiSelect-Bridging-Header.h +2 -0
  9. package/ios/TreeMultiSelect.mm +14 -0
  10. package/ios/TreeMultiSelect.swift +8 -0
  11. package/ios/TreeMultiSelect.xcodeproj/project.pbxproj +283 -0
  12. package/ios/TreeMultiSelect.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  13. package/ios/TreeMultiSelect.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  14. package/ios/TreeMultiSelect.xcodeproj/project.xcworkspace/xcuserdata/guest_jj.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  15. package/ios/TreeMultiSelect.xcodeproj/xcuserdata/guest_jj.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  16. package/lib/commonjs/TreeView.js +99 -0
  17. package/lib/commonjs/TreeView.js.map +1 -0
  18. package/lib/commonjs/components/CheckboxView.js +77 -0
  19. package/lib/commonjs/components/CheckboxView.js.map +1 -0
  20. package/lib/commonjs/components/CustomExpandCollapseIcon.js +20 -0
  21. package/lib/commonjs/components/CustomExpandCollapseIcon.js.map +1 -0
  22. package/lib/commonjs/components/NodeList.js +193 -0
  23. package/lib/commonjs/components/NodeList.js.map +1 -0
  24. package/lib/commonjs/helpers/expandCollapse.helper.js +93 -0
  25. package/lib/commonjs/helpers/expandCollapse.helper.js.map +1 -0
  26. package/lib/commonjs/helpers/index.js +61 -0
  27. package/lib/commonjs/helpers/index.js.map +1 -0
  28. package/lib/commonjs/helpers/initNodeMap.helper.js +44 -0
  29. package/lib/commonjs/helpers/initNodeMap.helper.js.map +1 -0
  30. package/lib/commonjs/helpers/search.helper.js +29 -0
  31. package/lib/commonjs/helpers/search.helper.js.map +1 -0
  32. package/lib/commonjs/helpers/selectAll.helper.js +73 -0
  33. package/lib/commonjs/helpers/selectAll.helper.js.map +1 -0
  34. package/lib/commonjs/helpers/toggleCheckbox.helper.js +153 -0
  35. package/lib/commonjs/helpers/toggleCheckbox.helper.js.map +1 -0
  36. package/lib/commonjs/index.js +28 -0
  37. package/lib/commonjs/index.js.map +1 -0
  38. package/lib/commonjs/signals/global.signals.js +42 -0
  39. package/lib/commonjs/signals/global.signals.js.map +1 -0
  40. package/lib/commonjs/types/treeView.types.js +6 -0
  41. package/lib/commonjs/types/treeView.types.js.map +1 -0
  42. package/lib/module/TreeView.js +89 -0
  43. package/lib/module/TreeView.js.map +1 -0
  44. package/lib/module/components/CheckboxView.js +68 -0
  45. package/lib/module/components/CheckboxView.js.map +1 -0
  46. package/lib/module/components/CustomExpandCollapseIcon.js +13 -0
  47. package/lib/module/components/CustomExpandCollapseIcon.js.map +1 -0
  48. package/lib/module/components/NodeList.js +185 -0
  49. package/lib/module/components/NodeList.js.map +1 -0
  50. package/lib/module/helpers/expandCollapse.helper.js +86 -0
  51. package/lib/module/helpers/expandCollapse.helper.js.map +1 -0
  52. package/lib/module/helpers/index.js +6 -0
  53. package/lib/module/helpers/index.js.map +1 -0
  54. package/lib/module/helpers/initNodeMap.helper.js +39 -0
  55. package/lib/module/helpers/initNodeMap.helper.js.map +1 -0
  56. package/lib/module/helpers/search.helper.js +23 -0
  57. package/lib/module/helpers/search.helper.js.map +1 -0
  58. package/lib/module/helpers/selectAll.helper.js +65 -0
  59. package/lib/module/helpers/selectAll.helper.js.map +1 -0
  60. package/lib/module/helpers/toggleCheckbox.helper.js +148 -0
  61. package/lib/module/helpers/toggleCheckbox.helper.js.map +1 -0
  62. package/lib/module/index.js +4 -0
  63. package/lib/module/index.js.map +1 -0
  64. package/lib/module/signals/global.signals.js +26 -0
  65. package/lib/module/signals/global.signals.js.map +1 -0
  66. package/lib/module/types/treeView.types.js +2 -0
  67. package/lib/module/types/treeView.types.js.map +1 -0
  68. package/lib/typescript/TreeView.d.ts +4 -0
  69. package/lib/typescript/TreeView.d.ts.map +1 -0
  70. package/lib/typescript/components/CheckboxView.d.ts +24 -0
  71. package/lib/typescript/components/CheckboxView.d.ts.map +1 -0
  72. package/lib/typescript/components/CustomExpandCollapseIcon.d.ts +4 -0
  73. package/lib/typescript/components/CustomExpandCollapseIcon.d.ts.map +1 -0
  74. package/lib/typescript/components/NodeList.d.ts +14 -0
  75. package/lib/typescript/components/NodeList.d.ts.map +1 -0
  76. package/lib/typescript/helpers/expandCollapse.helper.d.ts +18 -0
  77. package/lib/typescript/helpers/expandCollapse.helper.d.ts.map +1 -0
  78. package/lib/typescript/helpers/index.d.ts +6 -0
  79. package/lib/typescript/helpers/index.d.ts.map +1 -0
  80. package/lib/typescript/helpers/initNodeMap.helper.d.ts +12 -0
  81. package/lib/typescript/helpers/initNodeMap.helper.d.ts.map +1 -0
  82. package/lib/typescript/helpers/search.helper.d.ts +14 -0
  83. package/lib/typescript/helpers/search.helper.d.ts.map +1 -0
  84. package/lib/typescript/helpers/selectAll.helper.d.ts +25 -0
  85. package/lib/typescript/helpers/selectAll.helper.d.ts.map +1 -0
  86. package/lib/typescript/helpers/toggleCheckbox.helper.d.ts +9 -0
  87. package/lib/typescript/helpers/toggleCheckbox.helper.d.ts.map +1 -0
  88. package/lib/typescript/index.d.ts +5 -0
  89. package/lib/typescript/index.d.ts.map +1 -0
  90. package/lib/typescript/signals/global.signals.d.ts +11 -0
  91. package/lib/typescript/signals/global.signals.d.ts.map +1 -0
  92. package/lib/typescript/types/treeView.types.d.ts +61 -0
  93. package/lib/typescript/types/treeView.types.d.ts.map +1 -0
  94. package/package.json +165 -0
  95. package/react-native-tree-multi-select.podspec +41 -0
  96. package/src/TreeView.tsx +139 -0
  97. package/src/components/CheckboxView.tsx +109 -0
  98. package/src/components/CustomExpandCollapseIcon.tsx +20 -0
  99. package/src/components/NodeList.tsx +278 -0
  100. package/src/helpers/expandCollapse.helper.ts +88 -0
  101. package/src/helpers/index.ts +5 -0
  102. package/src/helpers/initNodeMap.helper.ts +46 -0
  103. package/src/helpers/search.helper.ts +28 -0
  104. package/src/helpers/selectAll.helper.ts +59 -0
  105. package/src/helpers/toggleCheckbox.helper.ts +144 -0
  106. package/src/index.tsx +22 -0
  107. package/src/signals/global.signals.ts +36 -0
  108. package/src/types/treeView.types.ts +86 -0
@@ -0,0 +1,185 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+ import React from "react";
3
+ import { View, StyleSheet, TouchableOpacity } from "react-native";
4
+ import { computed, effect, useComputed, useSignal } from "@preact/signals-react";
5
+ import { FlashList } from "@shopify/flash-list";
6
+ import { expanded, globalData, innerMostChildrenIds, searchKeys, searchText, state } from "../signals/global.signals";
7
+ import { doesNodeContainSearchTerm, handleToggleExpand, toggleCheckboxes } from "../helpers";
8
+ import { CheckboxView } from "./CheckboxView";
9
+ import CustomExpandCollapseIcon from "./CustomExpandCollapseIcon";
10
+ const NodeList = /*#__PURE__*/React.memo(_NodeList);
11
+ export default NodeList;
12
+ function _NodeList(props) {
13
+ const {
14
+ treeFlashListProps,
15
+ checkBoxViewStyleProps,
16
+ CheckboxComponent,
17
+ ExpandCollapseIconComponent,
18
+ ExpandCollapseTouchableComponent
19
+ } = props;
20
+ const filteredTree = React.useMemo(() => {
21
+ return computed(() => {
22
+ const searchTrimmed = searchText.value.trim().toLowerCase();
23
+ const filterTreeData = _nodes => {
24
+ let filtered = [];
25
+ for (let node of _nodes) {
26
+ if (!searchTrimmed || doesNodeContainSearchTerm(node, searchTrimmed, searchKeys.value)) {
27
+ // If node itself matches, include it and all its descendants
28
+ filtered.push(node);
29
+ } else if (node.children) {
30
+ // If node does not match, check its children and include them if they match
31
+ const childMatches = filterTreeData(node.children);
32
+ if (childMatches.length > 0) {
33
+ // If any children match, include the node, replacing its children with the matching ones
34
+ filtered.push({
35
+ ...node,
36
+ children: childMatches
37
+ });
38
+ }
39
+ }
40
+ }
41
+ return filtered;
42
+ };
43
+ return filterTreeData(globalData.value);
44
+ });
45
+ }, []);
46
+ const flattenedFilteredNodes = React.useMemo(() => {
47
+ return computed(() => {
48
+ const flattenTreeData = function (_nodes) {
49
+ let level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
50
+ let flattened = [];
51
+ for (let node of _nodes) {
52
+ flattened.push({
53
+ ...node,
54
+ level
55
+ });
56
+ if (node.children && expanded.value.has(node.id)) {
57
+ flattened = [...flattened, ...flattenTreeData(node.children, level + 1)];
58
+ }
59
+ }
60
+ return flattened;
61
+ };
62
+ return flattenTreeData(filteredTree.value);
63
+ });
64
+ // eslint-disable-next-line react-hooks/exhaustive-deps
65
+ }, []);
66
+ React.useEffect(() => {
67
+ effect(() => {
68
+ const allLeafIds = [];
69
+ const getLeafNodes = _nodes => {
70
+ for (let node of _nodes) {
71
+ if (node.children) {
72
+ getLeafNodes(node.children);
73
+ } else {
74
+ allLeafIds.push(node.id);
75
+ }
76
+ }
77
+ };
78
+ getLeafNodes(filteredTree.value);
79
+ innerMostChildrenIds.value = allLeafIds;
80
+ });
81
+ // eslint-disable-next-line react-hooks/exhaustive-deps
82
+ }, []);
83
+ const nodeRenderer = React.useCallback(_ref => {
84
+ let {
85
+ item
86
+ } = _ref;
87
+ return /*#__PURE__*/React.createElement(Node, {
88
+ node: item,
89
+ level: item.level || 0,
90
+ checkBoxViewStyleProps: checkBoxViewStyleProps,
91
+ CheckboxComponent: CheckboxComponent,
92
+ ExpandCollapseIconComponent: ExpandCollapseIconComponent,
93
+ ExpandCollapseTouchableComponent: ExpandCollapseTouchableComponent
94
+ });
95
+ }, [CheckboxComponent, ExpandCollapseIconComponent, ExpandCollapseTouchableComponent, checkBoxViewStyleProps]);
96
+ const keyExtractor = React.useCallback(item => item.id, []);
97
+ return /*#__PURE__*/React.createElement(FlashList, _extends({
98
+ estimatedItemSize: 36,
99
+ removeClippedSubviews: true,
100
+ keyboardShouldPersistTaps: "handled",
101
+ drawDistance: 50,
102
+ data: flattenedFilteredNodes.value,
103
+ renderItem: nodeRenderer,
104
+ keyExtractor: keyExtractor,
105
+ ListHeaderComponent: /*#__PURE__*/React.createElement(HeaderFooterView, null),
106
+ ListFooterComponent: /*#__PURE__*/React.createElement(HeaderFooterView, null)
107
+ }, treeFlashListProps));
108
+ }
109
+ ;
110
+ function HeaderFooterView() {
111
+ return /*#__PURE__*/React.createElement(View, {
112
+ style: styles.defaultHeaderFooter
113
+ });
114
+ }
115
+ const Node = /*#__PURE__*/React.memo(_Node);
116
+ function _Node(props) {
117
+ var _node$value$children;
118
+ const {
119
+ node: _node,
120
+ level,
121
+ checkBoxViewStyleProps,
122
+ ExpandCollapseIconComponent = CustomExpandCollapseIcon,
123
+ CheckboxComponent = CheckboxView,
124
+ ExpandCollapseTouchableComponent = TouchableOpacity
125
+ } = props;
126
+ const node = useSignal(_node);
127
+ React.useEffect(() => {
128
+ node.value = _node;
129
+ // eslint-disable-next-line react-hooks/exhaustive-deps
130
+ }, [_node]);
131
+ const isChecked = useComputed(() => state.value.checked.has(node.value.id));
132
+ const isIndeterminate = useComputed(() => state.value.indeterminate.has(node.value.id));
133
+ const value = useComputed(() => {
134
+ if (isIndeterminate.value) {
135
+ return 'indeterminate';
136
+ } else if (isChecked.value) {
137
+ return true;
138
+ } else {
139
+ return false;
140
+ }
141
+ });
142
+ const isExpanded = useComputed(() => expanded.value.has(node.value.id));
143
+ const _onToggleExpand = React.useCallback(() => {
144
+ handleToggleExpand(node.value.id);
145
+ // eslint-disable-next-line react-hooks/exhaustive-deps
146
+ }, []);
147
+ const _onCheck = React.useCallback(() => {
148
+ toggleCheckboxes([node.value.id]);
149
+ // eslint-disable-next-line react-hooks/exhaustive-deps
150
+ }, []);
151
+ return /*#__PURE__*/React.createElement(View, {
152
+ style: [styles.nodeParentView, {
153
+ marginLeft: level * 15
154
+ }]
155
+ }, /*#__PURE__*/React.createElement(View, {
156
+ style: styles.nodeCheckboxAndArrowRow
157
+ }, /*#__PURE__*/React.createElement(CheckboxComponent, _extends({
158
+ text: node.value.name,
159
+ onValueChange: _onCheck,
160
+ value: value.value
161
+ }, checkBoxViewStyleProps)), (_node$value$children = node.value.children) !== null && _node$value$children !== void 0 && _node$value$children.length ? /*#__PURE__*/React.createElement(ExpandCollapseTouchableComponent, {
162
+ style: styles.nodeExpandableArrowTouchable,
163
+ onPress: _onToggleExpand
164
+ }, /*#__PURE__*/React.createElement(ExpandCollapseIconComponent, {
165
+ isExpanded: isExpanded.value
166
+ })) : null));
167
+ }
168
+ ;
169
+ const styles = StyleSheet.create({
170
+ defaultHeaderFooter: {
171
+ padding: 5
172
+ },
173
+ nodeParentView: {
174
+ flex: 1
175
+ },
176
+ nodeExpandableArrowTouchable: {
177
+ flex: 1
178
+ },
179
+ nodeCheckboxAndArrowRow: {
180
+ flexDirection: 'row',
181
+ alignItems: 'center',
182
+ minWidth: "100%"
183
+ }
184
+ });
185
+ //# sourceMappingURL=NodeList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","View","StyleSheet","TouchableOpacity","computed","effect","useComputed","useSignal","FlashList","expanded","globalData","innerMostChildrenIds","searchKeys","searchText","state","doesNodeContainSearchTerm","handleToggleExpand","toggleCheckboxes","CheckboxView","CustomExpandCollapseIcon","NodeList","memo","_NodeList","props","treeFlashListProps","checkBoxViewStyleProps","CheckboxComponent","ExpandCollapseIconComponent","ExpandCollapseTouchableComponent","filteredTree","useMemo","searchTrimmed","value","trim","toLowerCase","filterTreeData","_nodes","filtered","node","push","children","childMatches","length","flattenedFilteredNodes","flattenTreeData","level","arguments","undefined","flattened","has","id","useEffect","allLeafIds","getLeafNodes","nodeRenderer","useCallback","_ref","item","createElement","Node","keyExtractor","_extends","estimatedItemSize","removeClippedSubviews","keyboardShouldPersistTaps","drawDistance","data","renderItem","ListHeaderComponent","HeaderFooterView","ListFooterComponent","style","styles","defaultHeaderFooter","_Node","_node$value$children","_node","isChecked","checked","isIndeterminate","indeterminate","isExpanded","_onToggleExpand","_onCheck","nodeParentView","marginLeft","nodeCheckboxAndArrowRow","text","name","onValueChange","nodeExpandableArrowTouchable","onPress","create","padding","flex","flexDirection","alignItems","minWidth"],"sourceRoot":"../../../src","sources":["components/NodeList.tsx"],"mappings":";AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SACIC,IAAI,EACJC,UAAU,EAEVC,gBAAgB,QAEb,cAAc;AACrB,SACIC,QAAQ,EACRC,MAAM,EAENC,WAAW,EACXC,SAAS,QACN,uBAAuB;AAC9B,SAASC,SAAS,QAAQ,qBAAqB;AAa/C,SACIC,QAAQ,EACRC,UAAU,EACVC,oBAAoB,EACpBC,UAAU,EACVC,UAAU,EACVC,KAAK,QACF,2BAA2B;AAClC,SACIC,yBAAyB,EACzBC,kBAAkB,EAClBC,gBAAgB,QACb,YAAY;AACnB,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,OAAOC,wBAAwB,MAAM,4BAA4B;AAWjE,MAAMC,QAAQ,gBAAGpB,KAAK,CAACqB,IAAI,CAACC,SAAS,CAAC;AACtC,eAAeF,QAAQ;AAEvB,SAASE,SAASA,CAACC,KAAoB,EAAE;EACrC,MAAM;IACFC,kBAAkB;IAClBC,sBAAsB;IAEtBC,iBAAiB;IACjBC,2BAA2B;IAC3BC;EACJ,CAAC,GAAGL,KAAK;EAET,MAAMM,YAAY,GAAG7B,KAAK,CAAC8B,OAAO,CAAC,MAAM;IACrC,OAAO1B,QAAQ,CAAC,MAAM;MAClB,MAAM2B,aAAa,GAAGlB,UAAU,CAACmB,KAAK,CAACC,IAAI,CAAC,CAAC,CAAC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,iBAAiB,EAAAmC,QAAA;IACd0B,IAAI,EAAEjD,IAAI,CAACN,KAAK,CAACwD,IAAK;IACtBC,aAAa,EAAEN,QAAS;IACxBnD,KAAK,EAAEA,KAAK,CAACA;EAAM,GACfP,sBAAsB,CAAG,CAAC,EAEjC,CAAAkD,oBAAA,GAAArC,IAAI,CAACN,KAAK,CAACQ,QAAQ,cAAAmC,oBAAA,eAAnBA,oBAAA,CAAqBjC,MAAM,gBACxB1C,KAAA,CAAA0D,aAAA,CAAC9B,gCAAgC;IAC7B2C,KAAK,EAAEC,MAAM,CAACkB,4BAA6B;IAC3CC,OAAO,EAAET;EAAgB,gBACzBlF,KAAA,CAAA0D,aAAA,CAAC/B,2BAA2B;IACxBsD,UAAU,EAAEA,UAAU,CAACjD;EAAM,CAChC,CAC6B,CAAC,GACnC,IACF,CACJ,CAAC;AAEf;AAAC;AAED,MAAMwC,MAAM,GAAGtE,UAAU,CAAC0F,MAAM,CAAC;EAC7BnB,mBAAmB,EAAE;IACjBoB,OAAO,EAAE;EACb,CAAC;EACDT,cAAc,EAAE;IACZU,IAAI,EAAE;EACV,CAAC;EACDJ,4BAA4B,EAAE;IAC1BI,IAAI,EAAE;EACV,CAAC;EACDR,uBAAuB,EAAE;IACrBS,aAAa,EAAE,KAAK;IACpBC,UAAU,EAAE,QAAQ;IACpBC,QAAQ,EAAE;EACd;AACJ,CAAC,CAAC"}
@@ -0,0 +1,86 @@
1
+ import { expanded, globalData, nodeMap } from "../signals/global.signals";
2
+
3
+ /**
4
+ * Toggle the expanded state of a tree node by its ID.
5
+ *
6
+ * If the node is currently expanded, it and its descendants will be collapsed.
7
+ * If it is currently collapsed, it will be expanded.
8
+ *
9
+ * @param id - The ID of the tree node to toggle.
10
+ */
11
+ export function handleToggleExpand(id) {
12
+ // Create a new Set based on the current expanded state
13
+ const newExpanded = new Set(expanded.value);
14
+
15
+ /**
16
+ * Recursively deletes a node and its descendants from the expanded set.
17
+ *
18
+ * @param node - The tree node to start deleting from.
19
+ */
20
+ function deleteChildrenFromExpanded(node) {
21
+ if (node.children) {
22
+ for (let child of node.children) {
23
+ newExpanded.delete(child.id);
24
+ deleteChildrenFromExpanded(child);
25
+ }
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Finds a node in the tree by its ID.
31
+ *
32
+ * @param nodes - The array of tree nodes to search through.
33
+ * @returns The found tree node, or undefined if not found.
34
+ */
35
+ function findNode(nodes) {
36
+ for (let node of nodes) {
37
+ if (node.id === id) {
38
+ return node;
39
+ } else if (node.children) {
40
+ const found = findNode(node.children);
41
+ if (found) {
42
+ return found;
43
+ }
44
+ }
45
+ }
46
+ return undefined;
47
+ }
48
+
49
+ // Find the node to expand or collapse
50
+ const node = findNode(globalData.value);
51
+ if (expanded.value.has(id)) {
52
+ // If the node is currently expanded, collapse it and its descendants
53
+ newExpanded.delete(id);
54
+ if (node) {
55
+ deleteChildrenFromExpanded(node);
56
+ }
57
+ } else {
58
+ // If the node is currently collapsed, expand it
59
+ newExpanded.add(id);
60
+ }
61
+
62
+ // Set the new expanded state
63
+ expanded.value = newExpanded;
64
+ }
65
+ ;
66
+
67
+ /**
68
+ * Expand all nodes in the tree.
69
+ */
70
+ export function expandAll() {
71
+ // Create a new Set containing the IDs of all nodes
72
+ const newExpanded = new Set(nodeMap.value.keys());
73
+ expanded.value = newExpanded;
74
+ }
75
+ ;
76
+
77
+ /**
78
+ * Collapse all nodes in the tree.
79
+ */
80
+ export function collapseAll() {
81
+ // Create an empty Set
82
+ const newExpanded = new Set();
83
+ expanded.value = newExpanded;
84
+ }
85
+ ;
86
+ //# sourceMappingURL=expandCollapse.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["expanded","globalData","nodeMap","handleToggleExpand","id","newExpanded","Set","value","deleteChildrenFromExpanded","node","children","child","delete","findNode","nodes","found","undefined","has","add","expandAll","keys","collapseAll"],"sourceRoot":"../../../src","sources":["helpers/expandCollapse.helper.ts"],"mappings":"AACA,SACIA,QAAQ,EACRC,UAAU,E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;AACA;AACA;AACA,OAAO,SAASc,SAASA,CAAA,EAAG;EACxB;EACA,MAAMd,WAAW,GAAG,IAAIC,GAAG,CAACJ,OAAO,CAACK,KAAK,CAACa,IAAI,CAAC,CAAC,CAAC;EACjDpB,QAAQ,CAACO,KAAK,GAAGF,WAAW;AAChC;AAAC;;AAED;AACA;AACA;AACA,OAAO,SAASgB,WAAWA,CAAA,EAAG;EAC1B;EACA,MAAMhB,WAAW,GAAG,IAAIC,GAAG,CAAS,CAAC;EACrCN,QAAQ,CAACO,KAAK,GAAGF,WAAW;AAChC;AAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./expandCollapse.helper";
2
+ export * from "./initNodeMap.helper";
3
+ export * from "./selectAll.helper";
4
+ export * from "./toggleCheckbox.helper";
5
+ export * from "./search.helper";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["helpers/index.ts"],"mappings":"AAAA,cAAc,yBAAyB;AACvC,cAAc,sBAAsB;AACpC,cAAc,oBAAoB;AAClC,cAAc,yBAAyB;AACvC,cAAc,iBAAiB"}
@@ -0,0 +1,39 @@
1
+ import { childToParentMap, nodeMap } from "../signals/global.signals";
2
+ import { toggleCheckboxes } from "./toggleCheckbox.helper";
3
+
4
+ /**
5
+ * Initialize the maps for tracking tree nodes and their parent-child relationships.
6
+ *
7
+ * This function is intended to be called once, during component initialization,
8
+ * with the initial tree data and any preselected node IDs.
9
+ *
10
+ * @param initialData - An array of TreeNode objects that represent the initial tree structure.
11
+ * @param preselectedIds - An optional array of TreeNode IDs that should be preselected.
12
+ */
13
+ export function initializeNodeMaps(initialData) {
14
+ let preselectedIds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
15
+ /**
16
+ * Recursively processes nodes, adding them to the nodeMap and childToParentMap.
17
+ *
18
+ * @param nodes - An array of TreeNode objects to be processed.
19
+ * @param parentId - The ID of the parent node, if applicable.
20
+ */
21
+ const processNodes = function (nodes) {
22
+ let parentId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
23
+ nodes.forEach(node => {
24
+ // Each node is added to the nodeMap with its ID as the key
25
+ nodeMap.value.set(node.id, node);
26
+ // If the node has a parent, its ID is mapped to the parent's ID in the childToParentMap
27
+ if (parentId) childToParentMap.value.set(node.id, parentId);
28
+ // If the node has children, recursively process them
29
+ if (node.children) processNodes(node.children, node.id);
30
+ });
31
+ };
32
+
33
+ // Begin processing with the initial tree data
34
+ processNodes(initialData);
35
+
36
+ // Check any preselected nodes
37
+ toggleCheckboxes(preselectedIds, true);
38
+ }
39
+ //# sourceMappingURL=initNodeMap.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["childToParentMap","nodeMap","toggleCheckboxes","initializeNodeMaps","initialData","preselectedIds","arguments","length","undefined","processNodes","nodes","parentId","forEach","node","value","set","id","children"],"sourceRoot":"../../../src","sources":["helpers/initNodeMap.helper.ts"],"mappings":"AACA,SACIA,gBAAgB,EAChBC,OAAO,QACJ,2BAA2B;AAClC,SAASC,gBAAgB,QAAQ,yBAAyB;;AAE1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAC9BC,WAAuB,EAEzB;EAAA,IADEC,cAAwB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAE7B;AACJ;AACA;AACA;AACA;AACA;EACI,MAAMG,YAAY,GAAG,SAAAA,CACjBC,KAAiB,EAEhB;IAAA,IADDC,QAAuB,GAAAL,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;IAE9BI,KAAK,CAACE,OAAO,CAAEC,IAAI,IAAK;MACpB;MACAZ,OAAO,CAACa,KAAK,CAACC,GAAG,CAACF,IAAI,CAACG,EAAE,EAAEH,IAAI,CAAC;MAChC;MACA,IAAIF,QAAQ,EAAEX,gBAAgB,CAACc,KAAK,CAACC,GAAG,CAACF,IAAI,CAACG,EAAE,EAAEL,QAAQ,CAAC;MAC3D;MACA,IAAIE,IAAI,CAACI,QAAQ,EAAER,YAAY,CAACI,IAAI,CAACI,QAAQ,EAAEJ,IAAI,CAACG,EAAE,CAAC;IAC3D,CAAC,CAAC;EACN,CAAC;;EAED;EACAP,YAAY,CAACL,WAAW,CAAC;;EAEzB;EACAF,gBAAgB,CAACG,cAAc,EAAE,IAAI,CAAC;AAC1C"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Checks if a given tree node contains a specific search term in any of its specified keys.
3
+ *
4
+ * This function will check each of the specified keys in the tree node, convert the key's value to a string,
5
+ * and check if it includes the search term.
6
+ *
7
+ * @param node - The tree node to search through.
8
+ * @param searchTerm - The term to search for.
9
+ * @param searchKeys - The keys in the tree node to search in.
10
+ * @returns True if the search term is found in any of the specified keys, false otherwise.
11
+ */
12
+ export function doesNodeContainSearchTerm(node, searchTerm, searchKeys) {
13
+ // We're using the `some` method on the array of keys to check each one
14
+ return searchKeys.some(key => {
15
+ // Get the value of the key in the tree node
16
+ const nodeValue = node[key];
17
+ // Check if the string representation of the key's value includes the search term
18
+ // If the value is undefined or null, `nodeValue?.toString()` will return undefined,
19
+ // and the call to `toLowerCase().includes(searchTerm)` will return false.
20
+ return nodeValue === null || nodeValue === void 0 ? void 0 : nodeValue.toString().toLowerCase().includes(searchTerm);
21
+ });
22
+ }
23
+ //# sourceMappingURL=search.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["doesNodeContainSearchTerm","node","searchTerm","searchKeys","some","key","nodeValue","toString","toLowerCase","includes"],"sourceRoot":"../../../src","sources":["helpers/search.helper.ts"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,yBAAyBA,CACrCC,IAAc,EACdC,UAAkB,EAClBC,UAAoB,EACb;EACP;EACA,OAAOA,UAAU,CAACC,IAAI,CAACC,GAAG,IAAI;IAC1B;IACA,MAAMC,SAAS,GAAGL,IAAI,CAACI,GAAG,CAAC;IAC3B;IACA;IACA;IACA,OAAQC,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEC,QAAQ,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,CAACC,QAAQ,CAACP,UAAU,CAAC;EACpE,CAAC,CAAC;AACN"}
@@ -0,0 +1,65 @@
1
+ import { innerMostChildrenIds, nodeMap, searchText, state } from "../signals/global.signals";
2
+ import { toggleCheckboxes } from "./toggleCheckbox.helper";
3
+
4
+ /**
5
+ * Selects all nodes that are currently visible due to the applied filter.
6
+ *
7
+ * If there is no search text, then it selects all nodes; otherwise, it selects all visible nodes.
8
+ */
9
+ export function selectAllFiltered() {
10
+ // If there's no search text, select all nodes
11
+ if (!searchText.value) {
12
+ selectAll();
13
+ } else {
14
+ // If there's search text, only select the visible nodes
15
+ toggleCheckboxes(innerMostChildrenIds.value, true);
16
+ }
17
+ }
18
+ ;
19
+
20
+ /**
21
+ * Unselects all nodes that are currently visible due to the applied filter.
22
+ *
23
+ * If there is no search text, then it unselects all nodes; otherwise, it unselects all visible nodes.
24
+ */
25
+ export function unselectAllFiltered() {
26
+ // If there's no search text, unselect all nodes
27
+ if (!searchText.value) {
28
+ unselectAll();
29
+ } else {
30
+ // If there's search text, only unselect the visible nodes
31
+ toggleCheckboxes(innerMostChildrenIds.value, false);
32
+ }
33
+ }
34
+ ;
35
+
36
+ /**
37
+ * Selects all nodes in the tree.
38
+ *
39
+ * This function selects all nodes by adding all node ids to the checked set and clearing the indeterminate set.
40
+ */
41
+ export function selectAll() {
42
+ // Create a new set containing the ids of all nodes
43
+ const newChecked = new Set(nodeMap.value.keys());
44
+ // Update the state to mark all nodes as checked
45
+ state.value = {
46
+ checked: newChecked,
47
+ indeterminate: new Set()
48
+ };
49
+ }
50
+ ;
51
+
52
+ /**
53
+ * Unselects all nodes in the tree.
54
+ *
55
+ * This function unselects all nodes by clearing both the checked and indeterminate sets.
56
+ */
57
+ export function unselectAll() {
58
+ // Update the state to mark all nodes as unchecked
59
+ state.value = {
60
+ checked: new Set(),
61
+ indeterminate: new Set()
62
+ };
63
+ }
64
+ ;
65
+ //# sourceMappingURL=selectAll.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["innerMostChildrenIds","nodeMap","searchText","state","toggleCheckboxes","selectAllFiltered","value","selectAll","unselectAllFiltered","unselectAll","newChecked","Set","keys","checked","indeterminate"],"sourceRoot":"../../../src","sources":["helpers/selectAll.helper.ts"],"mappings":"AAAA,SACIA,oBAAoB,EACpBC,OAAO,EACPC,UAAU,EACVC,KAAK,QACF,2BAA2B;AAClC,SAASC,gBAAgB,QAAQ,yBAAyB;;AAE1D;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAAA,EAAG;EAChC;EACA,IAAI,CAACH,UAAU,CAACI,KAAK,EAAE;IACnBC,SAAS,CAAC,CAAC;EACf,CAAC,MAAM;IACH;IACAH,gBAAgB,CAACJ,oBAAoB,CAACM,KAAK,EAAE,IAAI,CAAC;EACtD;AACJ;AAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,mBAAmBA,CAAA,EAAG;EAClC;EACA,IAAI,CAACN,UAAU,CAACI,KAAK,EAAE;IACnBG,WAAW,CAAC,CAAC;EACjB,CAAC,MAAM;IACH;IACAL,gBAAgB,CAACJ,oBAAoB,CAACM,KAAK,EAAE,KAAK,CAAC;EACvD;AACJ;AAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,SAASA,CAAA,EAAG;EACxB;EACA,MAAMG,UAAU,GAAG,IAAIC,GAAG,CAACV,OAAO,CAACK,KAAK,CAACM,IAAI,CAAC,CAAC,CAAC;EAChD;EACAT,KAAK,CAACG,KAAK,GAAI;IAAEO,OAAO,EAAEH,UAAU;IAAEI,aAAa,EAAE,IAAIH,GAAG,CAAC;EAAE,CAAE;AACrE;AAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,SAASF,WAAWA,CAAA,EAAG;EAC1B;EACAN,KAAK,CAACG,KAAK,GAAI;IAAEO,OAAO,EAAE,IAAIF,GAAG,CAAC,CAAC;IAAEG,aAAa,EAAE,IAAIH,GAAG,CAAC;EAAE,CAAE;AACpE;AAAC"}
@@ -0,0 +1,148 @@
1
+ import { childToParentMap, nodeMap, state } from "../signals/global.signals";
2
+
3
+ /**
4
+ * Function to toggle checkbox state for a tree structure.
5
+ * It sets the checked and indeterminate state for all affected nodes in the tree after an action to check/uncheck is made.
6
+ * @param {string[]} ids - The ids of nodes that need to be checked or unchecked.
7
+ * @param {boolean} [forceCheck] - Optional. If provided, will force the check state of the nodes to be this value.
8
+ * If not provided, the check state will be toggled based on the current state.
9
+ */
10
+ export function toggleCheckboxes(ids, forceCheck) {
11
+ // Create new sets for checked and indeterminate state so as not to mutate the original state.
12
+ const checked = new Set(state.value.checked);
13
+ const indeterminate = new Set(state.value.indeterminate);
14
+
15
+ // Maps for memoization of the recursive functions areAllDescendantsChecked and areAnyDescendantsChecked.
16
+ const memoAllDescendantsChecked = new Map();
17
+ const memoAnyDescendantsChecked = new Map();
18
+
19
+ /**
20
+ * Recursive function to check/uncheck a node and all its children.
21
+ * @param {string} nodeId - The id of the node to be checked or unchecked.
22
+ * @param {boolean} isChecked - Whether the node should be checked or unchecked.
23
+ */
24
+ const toggleNodeAndChildren = (nodeId, isChecked) => {
25
+ var _node$children;
26
+ // Set or unset this node in the checked set, and remove it from the indeterminate set.
27
+ if (isChecked) {
28
+ checked.add(nodeId);
29
+ indeterminate.delete(nodeId);
30
+ } else {
31
+ checked.delete(nodeId);
32
+ }
33
+
34
+ // Get the node from the node map and recursively apply the same state to all its children.
35
+ const node = nodeMap.value.get(nodeId);
36
+ node === null || node === void 0 || (_node$children = node.children) === null || _node$children === void 0 ? void 0 : _node$children.forEach(childNode => {
37
+ if (isChecked) indeterminate.delete(childNode.id);
38
+ toggleNodeAndChildren(childNode.id, isChecked);
39
+ });
40
+ };
41
+
42
+ /**
43
+ * Recursive function to check if all descendants of a node are checked.
44
+ * It uses memoization to avoid redundant calculations.
45
+ * @param {string} nodeId - The id of the node to be checked.
46
+ * @returns {boolean} - Whether all descendants of the node are checked.
47
+ */
48
+ const areAllDescendantsChecked = nodeId => {
49
+ // If the result for this node is already in the map, return it.
50
+ if (memoAllDescendantsChecked.has(nodeId)) {
51
+ return memoAllDescendantsChecked.get(nodeId);
52
+ }
53
+ const node = nodeMap.value.get(nodeId);
54
+ let allChecked = true;
55
+ if (node !== null && node !== void 0 && node.children) {
56
+ // If the node has children, recursively check all children.
57
+ for (const childNode of node.children) {
58
+ allChecked = allChecked && areAllDescendantsChecked(childNode.id);
59
+ }
60
+ } else {
61
+ // If the node has no children, its state is equal to whether it is in the checked set.
62
+ allChecked = checked.has(nodeId);
63
+ }
64
+
65
+ // Store the result in the map and return it.
66
+ memoAllDescendantsChecked.set(nodeId, allChecked);
67
+ return allChecked;
68
+ };
69
+
70
+ /**
71
+ * Recursive function to check if any descendants of a node are checked.
72
+ * It uses memoization to avoid redundant calculations.
73
+ * @param {string} nodeId - The id of the node to be checked.
74
+ * @returns {boolean} - Whether any descendants of the node are checked.
75
+ */
76
+ const areAnyDescendantsChecked = nodeId => {
77
+ // If the result for this node is already in the map, return it.
78
+ if (memoAnyDescendantsChecked.has(nodeId)) {
79
+ return memoAnyDescendantsChecked.get(nodeId);
80
+ }
81
+ const node = nodeMap.value.get(nodeId);
82
+ let anyChecked = false;
83
+ if (node !== null && node !== void 0 && node.children) {
84
+ // If the node has children, recursively check all children.
85
+ for (const childNode of node.children) {
86
+ anyChecked = anyChecked || areAnyDescendantsChecked(childNode.id);
87
+ }
88
+ } else {
89
+ // If the node has no children, its state is equal to whether it is in the checked set.
90
+ anyChecked = checked.has(nodeId);
91
+ }
92
+
93
+ // Store the result in the map and return it.
94
+ memoAnyDescendantsChecked.set(nodeId, anyChecked);
95
+ return anyChecked;
96
+ };
97
+
98
+ /**
99
+ * Function to update the indeterminate and checked state of a node and its ancestors.
100
+ * @param {string} nodeId - The id of the node to be updated.
101
+ */
102
+ const updateNodeAndAncestorsState = nodeId => {
103
+ const node = nodeMap.value.get(nodeId);
104
+ const hasOnlyOneChild = (node === null || node === void 0 ? void 0 : node.children) && node.children.length === 1;
105
+
106
+ // Update the node's state based on the state of its descendants.
107
+ if (areAllDescendantsChecked(nodeId)) {
108
+ checked.add(nodeId);
109
+ indeterminate.delete(nodeId);
110
+ } else if (areAnyDescendantsChecked(nodeId)) {
111
+ if (hasOnlyOneChild) {
112
+ // If a node has only one child and it's not checked,
113
+ // remove this node from both checked and indeterminate sets.
114
+ checked.delete(nodeId);
115
+ indeterminate.delete(nodeId);
116
+ } else {
117
+ checked.delete(nodeId);
118
+ indeterminate.add(nodeId);
119
+ }
120
+ } else {
121
+ checked.delete(nodeId);
122
+ indeterminate.delete(nodeId);
123
+ }
124
+ };
125
+
126
+ // Toggle the clicked nodes and their children.
127
+ ids.forEach(id => {
128
+ const isChecked = checked.has(id);
129
+ toggleNodeAndChildren(id, forceCheck === undefined ? !isChecked : forceCheck);
130
+ });
131
+
132
+ // Update the state of all affected nodes.
133
+ ids.forEach(id => {
134
+ let currentNodeId = id;
135
+ while (currentNodeId) {
136
+ updateNodeAndAncestorsState(currentNodeId);
137
+ currentNodeId = childToParentMap.value.get(currentNodeId);
138
+ }
139
+ });
140
+
141
+ // Update the state object with the new checked and indeterminate sets.
142
+ state.value = {
143
+ checked,
144
+ indeterminate
145
+ };
146
+ }
147
+ ;
148
+ //# sourceMappingURL=toggleCheckbox.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["childToParentMap","nodeMap","state","toggleCheckboxes","ids","forceCheck","checked","Set","value","indeterminate","memoAllDescendantsChecked","Map","memoAnyDescendantsChecked","toggleNodeAndChildren","nodeId","isChecked","_node$children","add","delete","node","get","children","forEach","childNode","id","areAllDescendantsChecked","has","allChecked","set","areAnyDescendantsChecked","anyChecked","updateNodeAndAncestorsState","hasOnlyOneChild","length","undefined","currentNodeId"],"sourceRoot":"../../../src","sources":["helpers/toggleCheckbox.helper.ts"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,OAAO,EAAEC,KAAK,QAAQ,2BAA2B;;AAE5E;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAACC,GAAa,EAAEC,UAAoB,EAAE;EAClE;EACA,MAAMC,OAAO,GAAG,IAAIC,GAAG,CAACL,KAAK,CAACM,KAAK,CAACF,OAAO,CAAC;EAC5C,MAAMG,aAAa,GAAG,IAAIF,GAAG,CAACL,KAAK,CAACM,KAAK,CAACC,aAAa,CAAC;;EAExD;EACA,MAAMC,yBAAyB,GAAG,IAAIC,GAAG,CAAC,CAAC;EAC3C,MAAMC,yBAAyB,GAAG,IAAID,GAAG,CAAC,CAAC;;EAE3C;AACJ;AACA;AACA;AACA;EACI,MAAME,qBAAqB,GAAGA,CAACC,MAAc,EAAEC,SAAkB,KAAK;IAAA,IAAAC,cAAA;IAClE;IACA,IAAID,SAAS,EAAE;MACXT,OAAO,CAACW,GAAG,CAACH,MAAM,CAAC;MACnBL,aAAa,CAACS,MAAM,CAACJ,MAAM,CAAC;IAChC,CAAC,MAAM;MACHR,OAAO,CAACY,MAAM,CAACJ,MAAM,CAAC;IAC1B;;IAEA;IACA,MAAMK,IAAI,GAAGlB,OAAO,CAACO,KAAK,CAACY,GAAG,CAACN,MAAM,CAAC;IACtCK,IAAI,aAAJA,IAAI,gBAAAH,cAAA,GAAJG,IAAI,CAAEE,QAAQ,cAAAL,cAAA,uBAAdA,cAAA,CAAgBM,OAAO,CAAEC,SAAS,IAAK;MACnC,IAAIR,SAAS,EAAEN,aAAa,CAACS,MAAM,CAACK,SAAS,CAACC,EAAE,CAAC;MACjDX,qBAAqB,CAACU,SAAS,CAACC,EAAE,EAAET,SAAS,CAAC;IAClD,CAAC,CAAC;EACN,CAAC;;EAED;AACJ;AACA;AACA;AACA;AACA;EACI,MAAMU,wBAAwB,GAAIX,MAAc,IAAc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AE;IAC1C,OAAOW,aAAa,EAAE;MAClBJ,2BAA2B,CAACI,aAAa,CAAC;MAC1CA,aAAa,GAAGnC,gBAAgB,CAACQ,KAAK,CAACY,GAAG,CAACe,aAAa,CAAC;IAC7D;EACJ,CAAC,CAAC;;EAEF;EACAjC,KAAK,CAACM,KAAK,GAAI;IAAEF,OAAO;IAAEG;EAAc,CAAE;AAC9C;AAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./TreeView";
2
+ export * from "./components/CheckboxView";
3
+ export {};
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAUA,cAAc,YAAY;AAC1B,cAAc,2BAA2B;AAAC"}
@@ -0,0 +1,26 @@
1
+ import { signal } from "@preact/signals-react";
2
+ export const state = signal({
3
+ checked: new Set(),
4
+ indeterminate: new Set()
5
+ });
6
+ export const expanded = signal(new Set());
7
+ export const globalData = signal([]);
8
+ export const nodeMap = signal(new Map());
9
+ export const childToParentMap = signal(new Map());
10
+ export const searchText = signal("");
11
+ export const searchKeys = signal([""]);
12
+ export const innerMostChildrenIds = signal([]);
13
+ export function cleanUpGlobalSignals() {
14
+ state.value = {
15
+ checked: new Set(),
16
+ indeterminate: new Set()
17
+ };
18
+ expanded.value = new Set();
19
+ globalData.value = [];
20
+ nodeMap.value = new Map();
21
+ childToParentMap.value = new Map();
22
+ searchText.value = "";
23
+ searchKeys.value = [];
24
+ innerMostChildrenIds.value = [];
25
+ }
26
+ //# sourceMappingURL=global.signals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["signal","state","checked","Set","indeterminate","expanded","globalData","nodeMap","Map","childToParentMap","searchText","searchKeys","innerMostChildrenIds","cleanUpGlobalSignals","value"],"sourceRoot":"../../../src","sources":["signals/global.signals.ts"],"mappings":"AAAA,SAASA,MAAM,QAAQ,uBAAuB;AAG9C,OAAO,MAAMC,KAAK,GAAGD,MAAM,CAAoB;EAC3CE,OAAO,EAAE,IAAIC,GAAG,CAAC,CAAC;EAClBC,aAAa,EAAE,IAAID,GAAG,CAAC;AAC3B,CAAC,CAAC;AACF,OAAO,MAAME,QAAQ,GAAGL,MAAM,CAAC,IAAIG,GAAG,CAAS,CAAC,CAAC;AAEjD,OAAO,MAAMG,UAAU,GAAGN,MAAM,CAAa,EAAE,CAAC;AAEhD,OAAO,MAAMO,OAAO,GAAGP,MAAM,CAAC,IAAIQ,GAAG,CAAmB,CAAC,CAAC;AAC1D,OAAO,MAAMC,gBAAgB,GAAGT,MAAM,CAAC,IAAIQ,GAAG,CAAiB,CAAC,CAAC;AAEjE,OAAO,MAAME,UAAU,GAAGV,MAAM,CAAC,EAAE,CAAC;AACpC,OAAO,MAAMW,UAAU,GAAGX,MAAM,CAAW,CAAC,EAAE,CAAC,CAAC;AAEhD,OAAO,MAAMY,oBAAoB,GAAGZ,MAAM,CAAW,EAAE,CAAC;AAExD,OAAO,SAASa,oBAAoBA,CAAA,EAAG;EACnCZ,KAAK,CAACa,KAAK,GAAI;IACXZ,OAAO,EAAE,IAAIC,GAAG,CAAC,CAAC;IAClBC,aAAa,EAAE,IAAID,GAAG,CAAC;EAC3B,CAAE;EACFE,QAAQ,CAACS,KAAK,GAAG,IAAIX,GAAG,CAAS,CAAC;EAElCG,UAAU,CAACQ,KAAK,GAAG,EAAE;EAErBP,OAAO,CAACO,KAAK,GAAG,IAAIN,GAAG,CAAmB,CAAC;EAC3CC,gBAAgB,CAACK,KAAK,GAAG,IAAIN,GAAG,CAAiB,CAAC;EAElDE,UAAU,CAACI,KAAK,GAAG,EAAE;EACrBH,UAAU,CAACG,KAAK,GAAG,EAAE;EAErBF,oBAAoB,CAACE,KAAK,GAAG,EAAE;AACnC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=treeView.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/treeView.types.ts"],"mappings":""}