@apia/tree 1.0.2 → 2.0.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 (57) hide show
  1. package/dist/OOTree/OOTreeChildren.d.ts +14 -0
  2. package/dist/OOTree/OOTreeChildren.d.ts.map +1 -0
  3. package/dist/OOTree/OOTreeChildren.js +17 -0
  4. package/dist/OOTree/OOTreeChildren.js.map +1 -0
  5. package/dist/OOTree/OOTreeNode.d.ts +30 -0
  6. package/dist/OOTree/OOTreeNode.d.ts.map +1 -0
  7. package/dist/OOTree/OOTreeNode.js +133 -0
  8. package/dist/OOTree/OOTreeNode.js.map +1 -0
  9. package/dist/OOTree/index.d.ts +36 -0
  10. package/dist/OOTree/index.d.ts.map +1 -0
  11. package/dist/OOTree/index.js +126 -0
  12. package/dist/OOTree/index.js.map +1 -0
  13. package/dist/OOTree/types.d.ts +11 -0
  14. package/dist/OOTree/types.d.ts.map +1 -0
  15. package/dist/SearchLabel.js +32 -0
  16. package/dist/SearchLabel.js.map +1 -0
  17. package/dist/Tree.d.ts +7 -0
  18. package/dist/Tree.d.ts.map +1 -0
  19. package/dist/Tree.js +131 -0
  20. package/dist/Tree.js.map +1 -0
  21. package/dist/TreeContext.d.ts +13 -0
  22. package/dist/TreeContext.d.ts.map +1 -0
  23. package/dist/TreeContext.js +22 -0
  24. package/dist/TreeContext.js.map +1 -0
  25. package/dist/TreeDataController.d.ts +116 -0
  26. package/dist/TreeDataController.d.ts.map +1 -0
  27. package/dist/TreeDataController.js +616 -0
  28. package/dist/TreeDataController.js.map +1 -0
  29. package/dist/TreeItem.js +51 -0
  30. package/dist/TreeItem.js.map +1 -0
  31. package/dist/TreeItemChildren.js +20 -0
  32. package/dist/TreeItemChildren.js.map +1 -0
  33. package/dist/TreeItemLabel.js +72 -0
  34. package/dist/TreeItemLabel.js.map +1 -0
  35. package/dist/getDomProps.js +37 -0
  36. package/dist/getDomProps.js.map +1 -0
  37. package/dist/index.d.ts +8 -407
  38. package/dist/index.js +7 -1749
  39. package/dist/index.js.map +1 -1
  40. package/dist/renderers/DefaultIconRenderer.js +18 -0
  41. package/dist/renderers/DefaultIconRenderer.js.map +1 -0
  42. package/dist/renderers/DefaultLabelRenderer.js +10 -0
  43. package/dist/renderers/DefaultLabelRenderer.js.map +1 -0
  44. package/dist/renderers/Spacer.js +10 -0
  45. package/dist/renderers/Spacer.js.map +1 -0
  46. package/dist/types.d.ts +211 -0
  47. package/dist/types.d.ts.map +1 -0
  48. package/dist/useTreeData.d.ts +25 -0
  49. package/dist/useTreeData.d.ts.map +1 -0
  50. package/dist/useTreeData.js +131 -0
  51. package/dist/useTreeData.js.map +1 -0
  52. package/dist/util.js +220 -0
  53. package/dist/util.js.map +1 -0
  54. package/package.json +22 -33
  55. package/LICENSE.md +0 -21
  56. package/README.md +0 -28
  57. package/cleanDist.json +0 -3
package/dist/index.js CHANGED
@@ -1,1749 +1,7 @@
1
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { useMount, useDebounceFn, useUnmount } from 'ahooks';
3
- import React, { useState, useEffect, memo } from 'react';
4
- import { shallowEqual } from 'react-redux';
5
- import { makeStyledComponent, Spinner, getVariant, Box } from '@apia/theme';
6
- import { EventEmitter, PropsStore, addBoundary, getSpecificParent, usePropsSelector, formatMessage, useLatest, HashedEventEmitter } from '@apia/util';
7
- import { IconButton } from '@apia/components';
8
- import { Icon } from '@apia/icons';
9
- import { uniqueId } from 'lodash-es';
10
-
11
- const getLastVisibleChild = (handler, id, avoidFiltered) => {
12
- const nodeProps = handler.propsStore.getFieldProps(id);
13
- if (id !== "root" && (nodeProps.isDisabled || !nodeProps.isExpanded) || nodeProps.children.length === 0)
14
- return null;
15
- for (let i = nodeProps.children.length - 1; i >= 0; i--) {
16
- const currentId = nodeProps.children[i];
17
- const currentProps = handler.propsStore.getFieldProps(currentId);
18
- if (!avoidFiltered || !currentProps.isFiltered) {
19
- const lastChildrenLastChildren = getLastVisibleChild(
20
- handler,
21
- currentId,
22
- avoidFiltered
23
- );
24
- return lastChildrenLastChildren !== null ? lastChildrenLastChildren : currentId;
25
- }
26
- }
27
- return null;
28
- };
29
- const getPreviousChild = (handler, id, avoidFiltered) => {
30
- var _a, _b;
31
- const nodeProps = handler.propsStore.getFieldProps(id);
32
- const fatherProps = handler.propsStore.getFieldProps(nodeProps.parentId);
33
- let childPosition = (_b = (_a = fatherProps.children) == null ? void 0 : _a.findIndex((current) => current === nodeProps.id)) != null ? _b : -1;
34
- while (childPosition > 0) {
35
- const prevSibling = handler.propsStore.getFieldProps(
36
- fatherProps.children[childPosition - 1]
37
- );
38
- const prevSiblingLastChild = getLastVisibleChild(
39
- handler,
40
- prevSibling.id,
41
- avoidFiltered
42
- );
43
- if (prevSiblingLastChild !== null)
44
- return prevSiblingLastChild;
45
- if (!avoidFiltered || !prevSibling.isFiltered)
46
- return prevSibling.id;
47
- childPosition--;
48
- }
49
- if (nodeProps.parentId === "root")
50
- return null;
51
- return nodeProps.parentId;
52
- };
53
- const getFirstNonFilteredChild = (handler, id) => {
54
- const nodeProps = handler.propsStore.getFieldProps(id);
55
- for (const child of nodeProps.children) {
56
- if (!handler.propsStore.getFieldProps(child).isFiltered)
57
- return child;
58
- }
59
- return null;
60
- };
61
- const getNextChild = (handler, id, avoidChildren, avoidFiltered) => {
62
- var _a, _b;
63
- const nodeProps = handler.propsStore.getFieldProps(id);
64
- const fatherProps = handler.propsStore.getFieldProps(nodeProps.parentId);
65
- let childPosition = (_b = (_a = fatherProps.children) == null ? void 0 : _a.findIndex((current) => current === nodeProps.id)) != null ? _b : Infinity;
66
- if (!avoidChildren && nodeProps.isExpanded) {
67
- if (!avoidFiltered && nodeProps.children.length > 0)
68
- return nodeProps.children[0];
69
- const firstNonFilteredChild = getFirstNonFilteredChild(
70
- handler,
71
- nodeProps.id
72
- );
73
- if (firstNonFilteredChild !== null)
74
- return firstNonFilteredChild;
75
- }
76
- while (childPosition < fatherProps.children.length - 1) {
77
- const nextSibling = fatherProps.children[childPosition + 1];
78
- if (!avoidFiltered || !handler.propsStore.getFieldProps(nextSibling).isFiltered)
79
- return nextSibling;
80
- childPosition++;
81
- }
82
- if (nodeProps.parentId === "root")
83
- return null;
84
- return getNextChild(handler, fatherProps.id, true, avoidFiltered);
85
- };
86
- const getNextNodeWithKey = (handler, id, firstKey, avoidFiltered) => {
87
- let nextChildWithKey = id;
88
- do {
89
- nextChildWithKey = getNextChild(
90
- handler,
91
- nextChildWithKey,
92
- false,
93
- avoidFiltered
94
- );
95
- if (nextChildWithKey !== null) {
96
- const nodeProps2 = handler.propsStore.getFieldProps(nextChildWithKey);
97
- if ((!nodeProps2.isFiltered || !avoidFiltered) && nodeProps2.label.toUpperCase().startsWith(firstKey.toUpperCase()))
98
- return nextChildWithKey;
99
- }
100
- } while (nextChildWithKey !== null);
101
- const nodeProps = handler.propsStore.getFieldProps(id);
102
- const positionInParent = handler.propsStore.getFieldProps(nodeProps.parentId).children.findIndex((current) => current === id);
103
- if (nodeProps.parentId !== "root" || positionInParent > 0) {
104
- const [firstChildOfTree] = handler.propsStore.getFieldProps("root").children;
105
- const firstChildProps = handler.propsStore.getFieldProps(firstChildOfTree);
106
- if (firstChildOfTree && (!avoidFiltered || !firstChildProps.isFiltered) && firstChildProps.label.toUpperCase().startsWith(firstKey.toUpperCase()))
107
- return firstChildOfTree;
108
- nextChildWithKey = firstChildOfTree;
109
- do {
110
- nextChildWithKey = getNextChild(
111
- handler,
112
- nextChildWithKey,
113
- false,
114
- avoidFiltered
115
- );
116
- if (nextChildWithKey) {
117
- const currentNodeProps = handler.propsStore.getFieldProps(nextChildWithKey);
118
- if ((!avoidFiltered || !currentNodeProps.isFiltered) && currentNodeProps.label.toUpperCase().startsWith(firstKey.toUpperCase()))
119
- return nextChildWithKey;
120
- }
121
- } while (nextChildWithKey !== id && nextChildWithKey !== null);
122
- }
123
- return null;
124
- };
125
- const getNodePath = (handler, nodeId) => {
126
- const path = [nodeId];
127
- let currentStep = nodeId;
128
- do {
129
- currentStep = handler.propsStore.getFieldProps(currentStep).parentId;
130
- path.unshift(currentStep);
131
- } while (currentStep !== "root");
132
- return path;
133
- };
134
- const getCommonAncestor = (handler, oneNodeId, anotherNodeId) => {
135
- const oneNodePath = getNodePath(handler, oneNodeId);
136
- const anotherNodePath = getNodePath(handler, anotherNodeId);
137
- for (let i = oneNodePath.length - 1; i >= 0; i--) {
138
- const anotherNodeIndex = anotherNodePath.indexOf(oneNodePath[i]);
139
- if (anotherNodeIndex !== -1)
140
- return {
141
- commonAncestor: oneNodePath[i],
142
- oneNodeAncestorChild: oneNodePath[i + 1],
143
- anotherNodeAncestorChild: anotherNodePath[anotherNodeIndex + 1]
144
- };
145
- }
146
- console.warn(
147
- "This point should have never been reached since the root node is common to all nodes",
148
- { oneNodeId, anotherNodeId, oneNodePath, anotherNodePath }
149
- );
150
- return null;
151
- };
152
- const unfilterNodes = (handler) => {
153
- handler.state.filteredNodes.forEach((current) => {
154
- handler.propsStore.updateField(
155
- current,
156
- { isFiltered: false },
157
- { noEmit: true }
158
- );
159
- });
160
- const firstChild = handler.propsStore.getFieldProps("root").children[0];
161
- if (firstChild)
162
- handler.setFocusedNode(firstChild);
163
- handler.setState({ filteredNodes: [] });
164
- };
165
- const matchNodesAgainstString = (handler, searchString, nodeId = "root") => {
166
- let hasMatched = false;
167
- let matchNode = null;
168
- const nodeProps = handler.propsStore.getFieldProps(nodeId);
169
- if (nodeId !== "root" && nodeProps.label.match(new RegExp(searchString, "i"))) {
170
- handler.propsStore.updateField(nodeId, { isFiltered: false });
171
- hasMatched = true;
172
- matchNode = nodeProps.id;
173
- handler.setState({
174
- filteredNodes: handler.state.filteredNodes.filter(
175
- (current) => current !== nodeId
176
- )
177
- });
178
- }
179
- let hasChildrenMatched = false;
180
- nodeProps.children.forEach((current) => {
181
- hasChildrenMatched = matchNodesAgainstString(handler, searchString, current) || hasMatched;
182
- hasMatched = hasChildrenMatched || hasMatched;
183
- if (hasMatched && !matchNode)
184
- matchNode = current;
185
- });
186
- if (hasChildrenMatched) {
187
- handler.propsStore.updateField(nodeId, { isExpanded: true });
188
- if (hasMatched && !matchNode)
189
- matchNode = nodeId;
190
- }
191
- if (!hasMatched) {
192
- handler.propsStore.updateField(
193
- nodeId,
194
- { isFiltered: true },
195
- { noEmit: true }
196
- );
197
- handler.setState({
198
- filteredNodes: [...handler.state.filteredNodes, nodeId]
199
- });
200
- }
201
- if (matchNode !== null)
202
- handler.setFocusedNode(matchNode);
203
- return hasMatched;
204
- };
205
- const selectAllNodesBetweenTwoNodes = (handler, oneNodeId, anotherNodeId, avoidFiltered) => {
206
- const commonAncestorData = getCommonAncestor(
207
- handler,
208
- oneNodeId,
209
- anotherNodeId
210
- );
211
- if (commonAncestorData) {
212
- const { anotherNodeAncestorChild, commonAncestor, oneNodeAncestorChild } = commonAncestorData;
213
- const ancestorProps = handler.propsStore.getFieldProps(commonAncestor);
214
- const oneNodePosition = ancestorProps.children.findIndex(
215
- (current) => current === oneNodeAncestorChild
216
- );
217
- const anotherNodePosition = ancestorProps.children.findIndex(
218
- (current) => current === anotherNodeAncestorChild
219
- );
220
- let currentId = oneNodePosition >= anotherNodePosition ? anotherNodeId : oneNodeId;
221
- const lastNodeId = oneNodePosition < anotherNodePosition ? anotherNodeId : oneNodeId;
222
- handler.toggleNodeSelectedState(currentId, true);
223
- do {
224
- currentId = getNextChild(handler, currentId, avoidFiltered);
225
- if (currentId !== null)
226
- handler.toggleNodeSelectedState(currentId, true);
227
- } while (currentId !== lastNodeId && currentId !== null);
228
- }
229
- };
230
-
231
- var __defProp$8 = Object.defineProperty;
232
- var __defProps$7 = Object.defineProperties;
233
- var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
234
- var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
235
- var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
236
- var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
237
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
238
- var __spreadValues$8 = (a, b) => {
239
- for (var prop in b || (b = {}))
240
- if (__hasOwnProp$8.call(b, prop))
241
- __defNormalProp$8(a, prop, b[prop]);
242
- if (__getOwnPropSymbols$8)
243
- for (var prop of __getOwnPropSymbols$8(b)) {
244
- if (__propIsEnum$8.call(b, prop))
245
- __defNormalProp$8(a, prop, b[prop]);
246
- }
247
- return a;
248
- };
249
- var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
250
- const trees = {};
251
- const treesRecordEmitter = new class TreesRecordEmitter extends EventEmitter {
252
- emit(eventName, params) {
253
- super.emit(eventName, params);
254
- trees[params.name] = params.controller;
255
- }
256
- }();
257
- function useTreeDataController(name) {
258
- const [controller, setDataController] = useState(
259
- trees[name]
260
- );
261
- useEffect(() => {
262
- if (trees[name] !== controller)
263
- setDataController(trees[name]);
264
- return treesRecordEmitter.on("addController", (ev) => {
265
- if (ev.name === name)
266
- setDataController(ev.controller);
267
- });
268
- }, []);
269
- return controller;
270
- }
271
- function getTreeDataController(name) {
272
- return trees[name];
273
- }
274
- class TreeDataController extends EventEmitter {
275
- constructor(name, configuration, propsStore = new PropsStore({
276
- logCommands: {
277
- propsStore: `treeProps_${name}`,
278
- propsLog: `treeLog_${name}`,
279
- propsSuscriptors: `propsSuscriptors_${name}`,
280
- updateProp: `updateProp_${name}`
281
- }
282
- })) {
283
- var _a;
284
- super();
285
- this.name = name;
286
- this.propsStore = propsStore;
287
- this.hasApendedFirstChild = false;
288
- /**
289
- * Este array se usa para conocer los padres faltantes al momento de la
290
- * construcción del árbol, de forma de optimizar el proceso
291
- */
292
- this.missingParents = [];
293
- this.nonEmittedUpdates = [];
294
- this.stateKey = "treeState";
295
- this.previousNodes = [];
296
- this._configuration = configuration != null ? configuration : {
297
- current: { emitUpdates: true }
298
- };
299
- this._configuration.current.emitUpdates = (_a = this._configuration.current.emitUpdates) != null ? _a : true;
300
- this.setState(this.getInitialState());
301
- treesRecordEmitter.emit("addController", {
302
- name,
303
- controller: this
304
- });
305
- this.initRoot();
306
- }
307
- get configuration() {
308
- return __spreadValues$8({}, this._configuration);
309
- }
310
- get state() {
311
- return this.propsStore.getFieldProps(
312
- this.stateKey
313
- );
314
- }
315
- get stateStore() {
316
- return this.propsStore;
317
- }
318
- destructor() {
319
- this.propsStore.destructor();
320
- }
321
- append(node) {
322
- var _a, _b, _c, _d, _e;
323
- const newNode = __spreadProps$7(__spreadValues$8({}, node), { nodeProps: (_a = node.nodeProps) != null ? _a : {} });
324
- let father;
325
- if (newNode.parentId !== void 0 && ((_b = this.propsStore.getFieldProps(newNode.parentId)) == null ? void 0 : _b.children)) {
326
- father = newNode.parentId;
327
- } else {
328
- father = "root";
329
- if (newNode.parentId)
330
- this.missingParents.push(newNode.parentId);
331
- newNode.actualParentId = newNode.parentId;
332
- newNode.parentId = "root";
333
- }
334
- this.propsStore.updateField(
335
- newNode.id,
336
- __spreadProps$7(__spreadValues$8({}, newNode), {
337
- children: (_c = newNode.children) != null ? _c : []
338
- }),
339
- { isUrgent: true }
340
- );
341
- this.setState({ length: this.state.length + 1 });
342
- if (this.missingParents.includes(newNode.id)) {
343
- this.propsStore.getFieldProps("root").children.forEach((currentChild) => {
344
- if (this.propsStore.getFieldProps(currentChild).actualParentId === newNode.id) {
345
- this.move(currentChild, newNode.id);
346
- }
347
- });
348
- this.missingParents = this.missingParents.filter(
349
- (current) => current !== newNode.id
350
- );
351
- }
352
- this.propsStore.updateField(
353
- father,
354
- {
355
- children: [
356
- ...this.propsStore.getFieldProps(father).children,
357
- newNode.id
358
- ],
359
- hasLoaded: true
360
- },
361
- { noEmit: ((_d = this._configuration.current) == null ? void 0 : _d.emitUpdates) === false }
362
- );
363
- if (((_e = this._configuration.current) == null ? void 0 : _e.emitUpdates) === false)
364
- this.nonEmittedUpdates.push(father);
365
- if (!this.hasApendedFirstChild) {
366
- this.hasApendedFirstChild = true;
367
- this.setFocusedNode(newNode.id, true);
368
- }
369
- if (newNode.isExpanded)
370
- this.toggleNodeExpandedState(newNode.id, true);
371
- }
372
- /**
373
- * Cuando se quieren agregar muchos nodos, es conveniente llamar primero al
374
- * método batchInit y luego de finalizar, al método batchFinish()
375
- */
376
- batchInit() {
377
- this.config({ emitUpdates: false });
378
- this.setState({ isLoading: true }, { isUrgent: true });
379
- }
380
- getNodesRecursive(nodeId = "root") {
381
- const node = this.propsStore.getFieldProps(nodeId);
382
- return node.children.reduce(
383
- (prev, current) => [...prev, ...this.getNodesRecursive(current)],
384
- [...node.children]
385
- );
386
- }
387
- /**
388
- * Cuando se quieren agregar muchos nodos, es conveniente llamar primero al
389
- * método batchInit y luego de finalizar, al método batchFinish()
390
- */
391
- batchFinish() {
392
- this.config({ emitUpdates: true });
393
- setTimeout(() => this.setState({ isLoading: false }), 0);
394
- const children = [...this.getNodesRecursive()];
395
- const deleteNodes = this.previousNodes.filter(
396
- (current) => !children.find((search) => search === current)
397
- );
398
- deleteNodes.forEach((current) => this.remove(current));
399
- this.config({ emitUpdates: true });
400
- setTimeout(() => this.setState({ isLoading: false }), 0);
401
- }
402
- config(newConf) {
403
- var _a;
404
- if (((_a = this._configuration.current) == null ? void 0 : _a.emitUpdates) === false && newConf.emitUpdates !== false) {
405
- this.nonEmittedUpdates.forEach(
406
- (current) => this.propsStore.updateField(current, {
407
- children: [...this.propsStore.getFieldProps(current).children]
408
- })
409
- );
410
- this.nonEmittedUpdates = [];
411
- }
412
- Object.assign(
413
- this._configuration.current,
414
- newConf
415
- );
416
- }
417
- deselectAll() {
418
- this.state.selectedNodes.forEach(
419
- (currentId) => this.propsStore.updateField(currentId, { isSelected: false })
420
- );
421
- this.setState({ selectedNodes: [] });
422
- }
423
- forceEmitUpdate() {
424
- var _a;
425
- this.propsStore.updateField("root", {
426
- forceUpdate: ((_a = this.propsStore.getFieldProps("root").forceUpdate) != null ? _a : 0) + 1
427
- });
428
- }
429
- getInitialState() {
430
- return {
431
- expandedNodes: [],
432
- filteredNodes: [],
433
- focusedNode: null,
434
- isLoading: false,
435
- length: 0,
436
- selectedNodes: []
437
- };
438
- }
439
- getNodesAsArray() {
440
- const allFields = __spreadValues$8({}, this.propsStore.fields);
441
- delete allFields[this.stateKey];
442
- delete allFields.root;
443
- return Object.values(allFields);
444
- }
445
- /**
446
- * Devuelve un array que contiene el id de todos los nodos pertenecientes al
447
- * árbol
448
- */
449
- getNodesIds() {
450
- const allFields = __spreadValues$8({}, this.propsStore.fields);
451
- delete allFields[this.stateKey];
452
- delete allFields.root;
453
- return Object.keys(allFields);
454
- }
455
- getParentId(parentId) {
456
- return this.propsStore.getFieldProps(parentId).parentId;
457
- }
458
- /**
459
- * Este método permite controlar el comportamiento con el teclado desde fuera
460
- * del componente.
461
- */
462
- handleKey(ev) {
463
- var _a;
464
- const focusedId = this.state.focusedNode;
465
- const nodeProps = this.propsStore.getFieldProps(focusedId);
466
- if (ev.key === "*") {
467
- if (this.state.focusedNode === null)
468
- return;
469
- const parent = this.propsStore.getFieldProps(
470
- this.propsStore.getFieldProps(this.state.focusedNode).parentId
471
- );
472
- parent.children.forEach(
473
- (current) => this.toggleNodeExpandedState(current, true)
474
- );
475
- } else if (ev.key.match(/^\w$/)) {
476
- const nextChildWithKey = getNextNodeWithKey(
477
- this,
478
- focusedId,
479
- ev.key,
480
- true
481
- );
482
- if (nextChildWithKey !== null) {
483
- this.setFocusedNode(nextChildWithKey);
484
- this.emit("mustFocus", nextChildWithKey);
485
- }
486
- } else
487
- switch (ev.code) {
488
- case "Home": {
489
- const firstChild = getFirstNonFilteredChild(this, "root");
490
- if (firstChild === null)
491
- return;
492
- if (ev.shiftKey && ev.ctrlKey && this.state.focusedNode !== null) {
493
- selectAllNodesBetweenTwoNodes(
494
- this,
495
- firstChild,
496
- this.state.focusedNode,
497
- true
498
- );
499
- }
500
- this.setFocusedNode(firstChild);
501
- this.emit("mustFocus", firstChild);
502
- break;
503
- }
504
- case "End": {
505
- const lastVisibleChild = getLastVisibleChild(this, "root", true);
506
- if (lastVisibleChild !== null) {
507
- if (ev.shiftKey && ev.ctrlKey && this.state.focusedNode !== null) {
508
- selectAllNodesBetweenTwoNodes(
509
- this,
510
- lastVisibleChild,
511
- this.state.focusedNode,
512
- true
513
- );
514
- }
515
- this.setFocusedNode(lastVisibleChild);
516
- this.emit("mustFocus", lastVisibleChild);
517
- }
518
- break;
519
- }
520
- case "ArrowRight": {
521
- if (nodeProps.isLeaf)
522
- return;
523
- ev.preventDefault();
524
- if (nodeProps.isExpanded) {
525
- const firstChild = getFirstNonFilteredChild(this, nodeProps.id);
526
- if (firstChild !== null) {
527
- this.setFocusedNode(firstChild);
528
- this.emit("mustFocus", firstChild);
529
- }
530
- } else
531
- this.toggleNodeExpandedState(nodeProps.id, true);
532
- break;
533
- }
534
- case "ArrowLeft": {
535
- ev.preventDefault();
536
- if (nodeProps.isLeaf || !nodeProps.isExpanded) {
537
- if (nodeProps.parentId !== "root" && nodeProps.parentId !== void 0) {
538
- this.setFocusedNode(nodeProps.parentId);
539
- this.emit("mustFocus", nodeProps.parentId);
540
- }
541
- } else
542
- this.toggleNodeExpandedState(nodeProps.id, false);
543
- break;
544
- }
545
- case "ArrowUp": {
546
- ev.preventDefault();
547
- const prevChild = getPreviousChild(this, nodeProps.id, true);
548
- if (prevChild !== null) {
549
- if (ev.shiftKey)
550
- this.toggleNodeSelectedState(prevChild, true);
551
- this.setFocusedNode(prevChild);
552
- this.emit("mustFocus", prevChild);
553
- } else
554
- this.emit("onArrowUpOnFirstElement", true);
555
- break;
556
- }
557
- case "ArrowDown": {
558
- ev.preventDefault();
559
- const nextChild = getNextChild(this, nodeProps.id, false, true);
560
- if (nextChild !== null) {
561
- if (ev.shiftKey)
562
- this.toggleNodeSelectedState(nextChild, true);
563
- this.setFocusedNode(nextChild);
564
- this.emit("mustFocus", nextChild);
565
- }
566
- break;
567
- }
568
- case "Space": {
569
- if ((_a = this._configuration.current) == null ? void 0 : _a.disableSelection)
570
- return;
571
- ev.preventDefault();
572
- this.toggleNodeSelectedState(nodeProps.id);
573
- break;
574
- }
575
- }
576
- }
577
- isNode(node) {
578
- return typeof node === "object" && "parentId" in node;
579
- }
580
- isNodeContainer(node) {
581
- return typeof node === "object" && !this.isNode(node);
582
- }
583
- includes(searchNode) {
584
- return !!this.propsStore.getFieldProps(searchNode.id);
585
- }
586
- initRoot() {
587
- this.propsStore.updateField(
588
- "root",
589
- { children: [], id: "root" },
590
- { isUrgent: true }
591
- );
592
- }
593
- move(moveNode, destinationNode, afterOrBefore) {
594
- var _a, _b;
595
- const currentFather = this.propsStore.getFieldProps(
596
- this.propsStore.getFieldProps(moveNode).parentId
597
- );
598
- const newFather = this.propsStore.getFieldProps(destinationNode);
599
- if (!currentFather) {
600
- console.warn("The current node does not belong to the tree.", moveNode);
601
- return;
602
- }
603
- if (!newFather) {
604
- console.warn(
605
- "The destination node does not belong to the tree. No action will be made",
606
- destinationNode
607
- );
608
- return;
609
- }
610
- currentFather.children = (_a = currentFather.children) == null ? void 0 : _a.filter(
611
- (search) => search !== moveNode
612
- );
613
- if (!newFather.children)
614
- newFather.children = [];
615
- if (!afterOrBefore)
616
- newFather.children.push(moveNode);
617
- else if (afterOrBefore.position) {
618
- newFather.children.splice(afterOrBefore.position - 1, 0, moveNode);
619
- } else {
620
- const key = afterOrBefore.after ? afterOrBefore.after : afterOrBefore.before;
621
- const relatedNodeKey = key && this.isNode(key) ? key.id : key;
622
- const relatedNodeIndex = newFather.children.findIndex(
623
- (search) => search === relatedNodeKey
624
- );
625
- const actualIndex = addBoundary(
626
- afterOrBefore.before !== void 0 ? relatedNodeIndex : relatedNodeIndex + 1,
627
- 0
628
- );
629
- if (actualIndex === -1 || actualIndex === newFather.children.length)
630
- newFather.children.push(moveNode);
631
- else
632
- newFather.children.splice(actualIndex, 0, moveNode);
633
- }
634
- this.propsStore.updateField(currentFather.id, {
635
- children: [...(_b = currentFather.children) != null ? _b : []]
636
- });
637
- this.propsStore.updateField(newFather.id, {
638
- children: [...newFather.children]
639
- });
640
- this.propsStore.updateField(moveNode, {
641
- parentId: newFather.id
642
- });
643
- }
644
- /**
645
- * Borra el nodo del árbol, y dependiendo del parámetro removeChildren, borra
646
- * también sus hijos.
647
- *
648
- * @param removeChildren - Si se pasa en false, los nodos hijos son movidos al root
649
- */
650
- remove(removeNode, removeChildren = true) {
651
- var _a, _b;
652
- const removeNodeId = this.isNode(removeNode) ? removeNode.id : removeNode;
653
- const removingNode = this.propsStore.getFieldProps(removeNodeId);
654
- if (!removingNode)
655
- return;
656
- const father = this.propsStore.getFieldProps(removingNode.parentId);
657
- if (father) {
658
- this.propsStore.updateField(father.id, {
659
- children: (_a = father.children) == null ? void 0 : _a.filter((search) => search !== removeNodeId)
660
- });
661
- }
662
- (_b = removingNode.children) == null ? void 0 : _b.forEach((current) => {
663
- if (removeChildren) {
664
- this.remove(current);
665
- } else {
666
- this.move(current, "root");
667
- }
668
- });
669
- this.setState({
670
- selectedNodes: this.state.selectedNodes.filter(
671
- (current) => current !== removeNodeId
672
- ),
673
- focusedNode: this.state.focusedNode === removeNodeId ? null : this.state.focusedNode,
674
- length: this.state.length - 1
675
- });
676
- this.propsStore.removeField(removeNodeId);
677
- }
678
- removeMultiple(nodes, removeChildren = true) {
679
- nodes.forEach((current) => this.remove(current, removeChildren));
680
- }
681
- /**
682
- * Borra todos los nodos del árbol.
683
- */
684
- removeAll() {
685
- var _a;
686
- if (((_a = this.configuration.current) == null ? void 0 : _a.emitUpdates) === false) {
687
- this.previousNodes = this.getNodesIds();
688
- this.propsStore.updateField(
689
- "root",
690
- { children: [], id: "root" },
691
- { isUrgent: true, noEmit: true }
692
- );
693
- } else {
694
- this.hasApendedFirstChild = false;
695
- this.setState({ focusedNode: null }, { isUrgent: true });
696
- this.setSelectedNodes([]);
697
- this.initRoot();
698
- Object.keys(this.propsStore.fields).forEach((current) => {
699
- if (!["root", this.stateKey].includes(current))
700
- this.propsStore.removeField(current);
701
- });
702
- }
703
- }
704
- selectAll() {
705
- this.setState({
706
- selectedNodes: this.getNodesIds()
707
- });
708
- this.state.selectedNodes.forEach(
709
- (currentId) => this.propsStore.updateField(currentId, { isSelected: true })
710
- );
711
- }
712
- setExpandedNodes(nodes) {
713
- this.state.expandedNodes.forEach(
714
- (current) => this.propsStore.updateField(current, { isExpanded: false })
715
- );
716
- this.setState({ expandedNodes: nodes });
717
- nodes.forEach(
718
- (current) => this.propsStore.updateField(current, { isExpanded: true })
719
- );
720
- }
721
- setFocusedNode(key, avoidSelection) {
722
- var _a, _b;
723
- if (this.state.focusedNode !== null)
724
- this.propsStore.updateField(this.state.focusedNode, { isFocused: false });
725
- this.setState({
726
- focusedNode: key
727
- });
728
- if (!((_a = this._configuration.current) == null ? void 0 : _a.isMultiple) && !avoidSelection && ((_b = this._configuration.current) == null ? void 0 : _b.selectionMode) !== "explicit")
729
- this.setSelectedNodes([key]);
730
- this.propsStore.updateField(key, { isFocused: true });
731
- }
732
- setSelectedNodes(nodes, force = false) {
733
- var _a;
734
- if (((_a = this._configuration.current) == null ? void 0 : _a.disableSelection) && !force)
735
- return;
736
- this.state.selectedNodes.forEach(
737
- (current) => this.propsStore.updateField(current, { isSelected: false })
738
- );
739
- this.setState({
740
- selectedNodes: nodes.filter((current) => {
741
- const { isSelectable } = this.propsStore.getFieldProps(current);
742
- if (isSelectable !== false)
743
- this.propsStore.updateField(current, { isSelected: true });
744
- return isSelectable !== false;
745
- })
746
- });
747
- }
748
- setSelectedNodesByClickEvent(ev) {
749
- var _a, _b, _c, _d;
750
- if ((_a = this._configuration.current) == null ? void 0 : _a.disableSelection)
751
- return;
752
- const nodeKey = (_b = getSpecificParent(
753
- ev.target,
754
- (current) => current.getAttribute("role") === "treeitem"
755
- )) == null ? void 0 : _b.getAttribute("data-key");
756
- if (nodeKey) {
757
- const nodeProps = this.propsStore.getFieldProps(nodeKey);
758
- if (nodeProps.isDisabled || nodeProps.isSelectable === false)
759
- return;
760
- const previousSelectionKeys = [...this.state.selectedNodes];
761
- const newSelection = ((_c = this._configuration.current) == null ? void 0 : _c.isMultiple) ? nodeProps.isSelected ? previousSelectionKeys.filter((current) => current !== nodeKey) : [...previousSelectionKeys, nodeKey] : [nodeKey];
762
- this.setState({
763
- selectedNodes: newSelection
764
- });
765
- previousSelectionKeys.forEach((current) => {
766
- if (!newSelection.includes(current))
767
- this.propsStore.updateField(current, { isSelected: false });
768
- });
769
- this.propsStore.updateField(nodeKey, {
770
- isSelected: ((_d = this._configuration.current) == null ? void 0 : _d.isMultiple) ? !nodeProps.isSelected : true
771
- });
772
- } else
773
- console.warn("Cannot set selection, no treeitem found", ev);
774
- }
775
- setState(updateProps, conf) {
776
- this.propsStore.updateField(
777
- this.stateKey,
778
- __spreadValues$8(__spreadValues$8({}, this.state), updateProps),
779
- conf
780
- );
781
- }
782
- toggleNodeExpandedState(key, shouldExpand) {
783
- var _a, _b, _c, _d, _e;
784
- const nodeProps = this.propsStore.getFieldProps(key);
785
- if (nodeProps.isDisabled || nodeProps.isLeaf || nodeProps.isLoading)
786
- return;
787
- if (((_a = this._configuration.current) == null ? void 0 : _a.onLoadData) && !nodeProps.hasLoaded) {
788
- this.propsStore.updateField(key, { isLoading: true });
789
- (_b = this._configuration.current) == null ? void 0 : _b.onLoadData(nodeProps).finally(() => {
790
- var _a2, _b2;
791
- this.propsStore.updateField(key, {
792
- isLoading: false,
793
- isExpanded: true,
794
- hasLoaded: true
795
- });
796
- this.setState({
797
- expandedNodes: [...this.state.expandedNodes, key]
798
- });
799
- (_b2 = (_a2 = this._configuration.current) == null ? void 0 : _a2.onExpand) == null ? void 0 : _b2.call(
800
- _a2,
801
- this.propsStore.getFieldProps(key)
802
- );
803
- });
804
- } else {
805
- const { expandedNodes } = this.state;
806
- const shouldExpandInner = shouldExpand !== void 0 ? shouldExpand : !expandedNodes.includes(key);
807
- if ((_c = this.propsStore.getFieldProps(key)) == null ? void 0 : _c.isDisabled)
808
- return;
809
- this.setState({
810
- expandedNodes: shouldExpandInner ? [...expandedNodes, key] : expandedNodes.filter((current) => current !== key)
811
- });
812
- this.propsStore.updateField(key, { isExpanded: shouldExpandInner });
813
- (_e = (_d = this._configuration.current) == null ? void 0 : _d.onExpand) == null ? void 0 : _e.call(
814
- _d,
815
- this.propsStore.getFieldProps(key)
816
- );
817
- }
818
- }
819
- toggleNodeSelectedState(key, isSelected) {
820
- var _a, _b;
821
- if ((_a = this._configuration.current) == null ? void 0 : _a.disableSelection)
822
- return;
823
- const nodeProps = this.propsStore.getFieldProps(key);
824
- if (nodeProps.isDisabled || nodeProps.isSelectable === false)
825
- return;
826
- const shouldSelect = isSelected !== void 0 ? isSelected : !this.state.selectedNodes.includes(key);
827
- if (shouldSelect && !((_b = this._configuration.current) == null ? void 0 : _b.isMultiple) && this.state.selectedNodes[0])
828
- this.toggleNodeSelectedState(this.state.selectedNodes[0], false);
829
- this.propsStore.updateField(key, { isSelected: shouldSelect });
830
- this.setState({
831
- selectedNodes: shouldSelect ? [...this.state.selectedNodes, key] : this.state.selectedNodes.filter((current) => current !== key)
832
- });
833
- }
834
- }
835
- function useTreeSelector(handler, configuration) {
836
- var _a;
837
- return usePropsSelector(
838
- (_a = handler == null ? void 0 : handler.stateKey) != null ? _a : "__NO__TREE__KEY__",
839
- __spreadValues$8({
840
- propsStore: handler == null ? void 0 : handler.propsStore
841
- }, configuration)
842
- );
843
- }
844
- function useTreeSelectorByName(treeName, configuration) {
845
- var _a;
846
- const handler = useTreeDataController(treeName);
847
- const selection = usePropsSelector(
848
- (_a = handler == null ? void 0 : handler.stateKey) != null ? _a : "__NO__TREE__KEY__",
849
- __spreadValues$8({
850
- propsStore: handler == null ? void 0 : handler.propsStore
851
- }, configuration)
852
- );
853
- return { selection, handler };
854
- }
855
-
856
- var __defProp$7 = Object.defineProperty;
857
- var __defProps$6 = Object.defineProperties;
858
- var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
859
- var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
860
- var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
861
- var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
862
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
863
- var __spreadValues$7 = (a, b) => {
864
- for (var prop in b || (b = {}))
865
- if (__hasOwnProp$7.call(b, prop))
866
- __defNormalProp$7(a, prop, b[prop]);
867
- if (__getOwnPropSymbols$7)
868
- for (var prop of __getOwnPropSymbols$7(b)) {
869
- if (__propIsEnum$7.call(b, prop))
870
- __defNormalProp$7(a, prop, b[prop]);
871
- }
872
- return a;
873
- };
874
- var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
875
- function getActiveDescendantName(treeName, nodeId) {
876
- return `${treeName}__${nodeId}`;
877
- }
878
- function getDomProps(_, treeName, type, par) {
879
- var _a;
880
- switch (type) {
881
- case "node": {
882
- const node = par;
883
- const tree = getTreeDataController(treeName);
884
- return __spreadProps$6(__spreadValues$7({
885
- "aria-disabled": node.isDisabled,
886
- "aria-expanded": node.isLeaf ? void 0 : !!node.isExpanded,
887
- "aria-label": node.label
888
- }, ((_a = tree.configuration.current) == null ? void 0 : _a.disableSelection) ? void 0 : {
889
- "aria-selected": node.isSelectable !== false && !node.isDisabled ? !!node.isSelected : void 0
890
- }), {
891
- className: node.className,
892
- color: node.color,
893
- "data-key": node.id,
894
- id: getActiveDescendantName(treeName, node.id),
895
- role: "treeitem",
896
- title: node.title
897
- });
898
- }
899
- default: {
900
- const tree = par;
901
- return {
902
- role: "tree",
903
- "aria-multiselectable": tree.isMultiple
904
- };
905
- }
906
- }
907
- }
908
-
909
- var __defProp$6 = Object.defineProperty;
910
- var __defProps$5 = Object.defineProperties;
911
- var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
912
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
913
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
914
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
915
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
916
- var __spreadValues$6 = (a, b) => {
917
- for (var prop in b || (b = {}))
918
- if (__hasOwnProp$6.call(b, prop))
919
- __defNormalProp$6(a, prop, b[prop]);
920
- if (__getOwnPropSymbols$6)
921
- for (var prop of __getOwnPropSymbols$6(b)) {
922
- if (__propIsEnum$6.call(b, prop))
923
- __defNormalProp$6(a, prop, b[prop]);
924
- }
925
- return a;
926
- };
927
- var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
928
- const styles = {
929
- height: "iconmd",
930
- width: "iconmd",
931
- background: "palette.background.paper"
932
- };
933
- const LoaderSpinner = makeStyledComponent(
934
- "LoaderSpinner",
935
- "layout.common.components.loaderSpinner",
936
- styles,
937
- ({ className }) => {
938
- return /* @__PURE__ */ jsx(
939
- Spinner,
940
- __spreadProps$5(__spreadValues$6({}, getVariant("layout.common.components.loaderSpinner")), {
941
- className
942
- })
943
- );
944
- }
945
- );
946
-
947
- var __defProp$5 = Object.defineProperty;
948
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
949
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
950
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
951
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
952
- var __spreadValues$5 = (a, b) => {
953
- for (var prop in b || (b = {}))
954
- if (__hasOwnProp$5.call(b, prop))
955
- __defNormalProp$5(a, prop, b[prop]);
956
- if (__getOwnPropSymbols$5)
957
- for (var prop of __getOwnPropSymbols$5(b)) {
958
- if (__propIsEnum$5.call(b, prop))
959
- __defNormalProp$5(a, prop, b[prop]);
960
- }
961
- return a;
962
- };
963
- const SearchLabel = ({
964
- isLoading: isSearching,
965
- onDelete,
966
- searchString
967
- }) => {
968
- if (!searchString && !isSearching)
969
- return null;
970
- return /* @__PURE__ */ jsx(Box, { className: `tree__searchLabelBox ${isSearching ? "isLoading" : ""}`, children: isSearching ? /* @__PURE__ */ jsx(LoaderSpinner, { className: "tree__loading" }) : /* @__PURE__ */ jsxs(Box, { as: "label", className: "tree__searchLabel", children: [
971
- formatMessage(window.LBL_FILTERING_BY, { TOK1: searchString }),
972
- /* @__PURE__ */ jsx(
973
- IconButton,
974
- __spreadValues$5({
975
- icon: "Close",
976
- "aria-label": window.LBL_DELETE_FILTER,
977
- onClick: onDelete,
978
- title: window.LBL_DELETE_FILTER,
979
- size: "Sm"
980
- }, getVariant("icon-inherit"))
981
- )
982
- ] }) });
983
- };
984
-
985
- const TreeContext = React.createContext({});
986
- function useTreeContext() {
987
- const context = React.useContext(TreeContext);
988
- if (!context)
989
- throw new Error("There is no tree context");
990
- return context;
991
- }
992
- const TreeContextProvider = ({
993
- children,
994
- value
995
- }) => {
996
- const Provider = React.useMemo(() => {
997
- return TreeContext.Provider;
998
- }, []);
999
- return /* @__PURE__ */ jsx(Provider, { value, children });
1000
- };
1001
-
1002
- const DefaultIconRenderer = (props) => {
1003
- var _a;
1004
- return /* @__PURE__ */ jsx(
1005
- Icon,
1006
- {
1007
- name: props.icon,
1008
- title: "",
1009
- size: (_a = props.iconSize) != null ? _a : "iconSm",
1010
- className: "tree__node__icon"
1011
- }
1012
- );
1013
- };
1014
-
1015
- const DefaultLabelRenderer = (props) => {
1016
- return /* @__PURE__ */ jsx(Box, { as: "span", children: props.label });
1017
- };
1018
-
1019
- const Spacer = ({ level }) => {
1020
- return /* @__PURE__ */ jsx(Fragment, { children: Array(level).fill("").map((_, i) => i).map((current) => /* @__PURE__ */ jsx(Box, { className: "spacer" }, current)) });
1021
- };
1022
-
1023
- var __defProp$4 = Object.defineProperty;
1024
- var __defProps$4 = Object.defineProperties;
1025
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
1026
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
1027
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
1028
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
1029
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1030
- var __spreadValues$4 = (a, b) => {
1031
- for (var prop in b || (b = {}))
1032
- if (__hasOwnProp$4.call(b, prop))
1033
- __defNormalProp$4(a, prop, b[prop]);
1034
- if (__getOwnPropSymbols$4)
1035
- for (var prop of __getOwnPropSymbols$4(b)) {
1036
- if (__propIsEnum$4.call(b, prop))
1037
- __defNormalProp$4(a, prop, b[prop]);
1038
- }
1039
- return a;
1040
- };
1041
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
1042
- const TreeItemLabel = ({ level, treeKey }) => {
1043
- var _a, _b, _c;
1044
- const {
1045
- handler,
1046
- treeProps: { toggleNodesOnLabelClick }
1047
- } = useTreeContext();
1048
- const props = usePropsSelector(treeKey, {
1049
- selector: (current) => current,
1050
- comparator: (prevProps, newProps) => {
1051
- return shallowEqual(prevProps, newProps) && shallowEqual(prevProps == null ? void 0 : prevProps.children, newProps == null ? void 0 : newProps.children);
1052
- },
1053
- propsStore: handler.propsStore
1054
- });
1055
- const Renderer = React.useMemo(
1056
- () => {
1057
- var _a2;
1058
- return (_a2 = props.labelRenderer) != null ? _a2 : DefaultLabelRenderer;
1059
- },
1060
- [props.labelRenderer]
1061
- );
1062
- const handleToggle = React.useCallback(() => {
1063
- handler.toggleNodeExpandedState(treeKey);
1064
- }, [handler, treeKey]);
1065
- const IconRenderer = React.useMemo(() => {
1066
- return typeof props.icon === "string" ? DefaultIconRenderer : props.icon;
1067
- }, [props.icon]);
1068
- const onClick = React.useCallback(() => {
1069
- if (props.allowToggleExpandedFromLabel !== false)
1070
- handler.toggleNodeExpandedState(treeKey);
1071
- }, [handler, props.allowToggleExpandedFromLabel, treeKey]);
1072
- return /* @__PURE__ */ jsxs(
1073
- Box,
1074
- {
1075
- as: "span",
1076
- className: `tree__nodeItemLabel ${props.isFocused ? "focus" : ""}`,
1077
- children: [
1078
- /* @__PURE__ */ jsx(Spacer, { level }),
1079
- (props.isLoading || props.isExpanded && props.isLeaf !== true || props.isLeaf === false || ((_b = (_a = props.children) == null ? void 0 : _a.length) != null ? _b : 0) > 0 || props.isLeaf === void 0 && !props.hasLoaded && ((_c = handler.configuration.current) == null ? void 0 : _c.onLoadData)) && /* @__PURE__ */ jsx(Box, { className: "tree__expanderWrapper", children: props.isLoading ? /* @__PURE__ */ jsx(Spinner, { sx: { width: "iconSm", height: "iconSm" } }) : /* @__PURE__ */ jsx(
1080
- Icon,
1081
- {
1082
- className: "tree__expandIcon",
1083
- onClick: handleToggle,
1084
- name: props.isExpanded ? "ArrowDownThin" : "ArrowRightThin",
1085
- title: "",
1086
- size: 20
1087
- }
1088
- ) }),
1089
- props.icon && IconRenderer && /* @__PURE__ */ jsx(IconRenderer, __spreadValues$4({}, props)),
1090
- /* @__PURE__ */ jsx(
1091
- Box,
1092
- {
1093
- as: "span",
1094
- className: "tree__nodeItemLabelRenderer",
1095
- onClick: toggleNodesOnLabelClick !== false ? onClick : void 0,
1096
- children: /* @__PURE__ */ jsx(Renderer, __spreadProps$4(__spreadValues$4({}, props), { level }))
1097
- }
1098
- )
1099
- ]
1100
- }
1101
- );
1102
- };
1103
- var TreeItemLabel$1 = React.memo(TreeItemLabel);
1104
-
1105
- var __defProp$3 = Object.defineProperty;
1106
- var __defProps$3 = Object.defineProperties;
1107
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
1108
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
1109
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
1110
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
1111
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1112
- var __spreadValues$3 = (a, b) => {
1113
- for (var prop in b || (b = {}))
1114
- if (__hasOwnProp$3.call(b, prop))
1115
- __defNormalProp$3(a, prop, b[prop]);
1116
- if (__getOwnPropSymbols$3)
1117
- for (var prop of __getOwnPropSymbols$3(b)) {
1118
- if (__propIsEnum$3.call(b, prop))
1119
- __defNormalProp$3(a, prop, b[prop]);
1120
- }
1121
- return a;
1122
- };
1123
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
1124
- const TreeItem = ({ level, treeKey }) => {
1125
- var _a;
1126
- const { handler, name, forceUpdate, treeProps } = useTreeContext();
1127
- const props = usePropsSelector(treeKey, {
1128
- selector: (current) => current,
1129
- comparator: (prevProps, newProps) => {
1130
- return shallowEqual(prevProps, newProps) && shallowEqual(prevProps == null ? void 0 : prevProps.children, newProps == null ? void 0 : newProps.children);
1131
- },
1132
- propsStore: handler.propsStore
1133
- });
1134
- const nodes = React.useMemo(
1135
- () => {
1136
- var _a2, _b;
1137
- return (_b = (_a2 = props.children) == null ? void 0 : _a2.map(
1138
- (current) => handler.propsStore.getFieldProps(current)
1139
- )) != null ? _b : [];
1140
- },
1141
- [props.children, handler.propsStore]
1142
- );
1143
- const domProps = getDomProps(treeProps, name, "node", props);
1144
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
1145
- Box,
1146
- __spreadProps$3(__spreadValues$3({
1147
- as: "li"
1148
- }, domProps), {
1149
- className: `${(_a = domProps.className) != null ? _a : ""} tree__item`,
1150
- children: [
1151
- /* @__PURE__ */ jsx(TreeItemLabel$1, { level, treeKey }),
1152
- props.isExpanded && /* @__PURE__ */ jsx(
1153
- TreeItemChildren$1,
1154
- {
1155
- forceUpdate,
1156
- role: "group",
1157
- level,
1158
- nodes
1159
- }
1160
- )
1161
- ]
1162
- })
1163
- ) });
1164
- };
1165
- var TreeItem$1 = React.memo(TreeItem);
1166
-
1167
- var __defProp$2 = Object.defineProperty;
1168
- var __defProps$2 = Object.defineProperties;
1169
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
1170
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
1171
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
1172
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
1173
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1174
- var __spreadValues$2 = (a, b) => {
1175
- for (var prop in b || (b = {}))
1176
- if (__hasOwnProp$2.call(b, prop))
1177
- __defNormalProp$2(a, prop, b[prop]);
1178
- if (__getOwnPropSymbols$2)
1179
- for (var prop of __getOwnPropSymbols$2(b)) {
1180
- if (__propIsEnum$2.call(b, prop))
1181
- __defNormalProp$2(a, prop, b[prop]);
1182
- }
1183
- return a;
1184
- };
1185
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1186
- var __objRest = (source, exclude) => {
1187
- var target = {};
1188
- for (var prop in source)
1189
- if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
1190
- target[prop] = source[prop];
1191
- if (source != null && __getOwnPropSymbols$2)
1192
- for (var prop of __getOwnPropSymbols$2(source)) {
1193
- if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
1194
- target[prop] = source[prop];
1195
- }
1196
- return target;
1197
- };
1198
- const TreeItemChildren = React.forwardRef((_a, ref) => {
1199
- var _b = _a, { level, nodes, forceUpdate } = _b, props = __objRest(_b, ["level", "nodes", "forceUpdate"]);
1200
- const { handler } = useTreeContext();
1201
- return /* @__PURE__ */ jsx(Box, __spreadProps$2(__spreadValues$2({ ref, as: "ul" }, props), { children: nodes == null ? void 0 : nodes.map((current) => {
1202
- const currentProps = handler.propsStore.getFieldProps(current.id);
1203
- if (!currentProps)
1204
- return null;
1205
- return currentProps.isFiltered ? null : /* @__PURE__ */ jsx(TreeItem$1, { level: level + 1, treeKey: current.id }, current.id);
1206
- }) }));
1207
- });
1208
- TreeItemChildren.displayName = "TreeItemChildren";
1209
- var TreeItemChildren$1 = React.memo(TreeItemChildren);
1210
-
1211
- function useTreeData({ name, treeProps }) {
1212
- const props = useLatest(treeProps);
1213
- const handler = React.useMemo(
1214
- () => {
1215
- var _a;
1216
- return (_a = props == null ? void 0 : props.current.controller) != null ? _a : new TreeDataController(name, props);
1217
- },
1218
- // eslint-disable-next-line react-hooks/exhaustive-deps
1219
- []
1220
- );
1221
- useMount(() => {
1222
- var _a;
1223
- (_a = treeProps == null ? void 0 : treeProps.initialNodes) == null ? void 0 : _a.forEach((current) => handler.append(current));
1224
- });
1225
- const data = usePropsSelector("root", {
1226
- comparator: shallowEqual,
1227
- propsStore: handler.propsStore,
1228
- selector: (current) => {
1229
- var _a;
1230
- return {
1231
- children: (_a = current.children) != null ? _a : [],
1232
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
1233
- forceUpdate: current.forceUpdate
1234
- };
1235
- }
1236
- });
1237
- const keyHandlerId = React.useMemo(() => `keyHandler${uniqueId()}`, []);
1238
- const keyHandlerRef = React.useRef(null);
1239
- const focusOnNode = React.useCallback(
1240
- (key, retry = 3) => {
1241
- var _a, _b;
1242
- if (keyHandlerRef.current) {
1243
- const focusElement = keyHandlerRef.current.querySelector(
1244
- `[data-key="${key}"]`
1245
- );
1246
- (_a = keyHandlerRef.current) == null ? void 0 : _a.focus();
1247
- if (focusElement) {
1248
- const actualFocusElement = ((_b = treeProps.focusGetter) != null ? _b : (liElement) => liElement.querySelector(
1249
- ":scope > .tree__nodeItemLabel"
1250
- ))(focusElement);
1251
- const nodeProps = handler.propsStore.getFieldProps(key);
1252
- if (!treeProps.focusGetter || !nodeProps.labelRenderer)
1253
- actualFocusElement.classList.add("focused");
1254
- actualFocusElement.scrollIntoView({
1255
- inline: "nearest",
1256
- block: "nearest"
1257
- });
1258
- } else if (retry > 0)
1259
- setTimeout(() => focusOnNode(key, retry - 1), 30);
1260
- }
1261
- },
1262
- [handler.propsStore, treeProps.focusGetter]
1263
- );
1264
- React.useEffect(() => {
1265
- const unsuscribe1 = handler.on("mustFocus", (node) => focusOnNode(node));
1266
- const unsuscribe2 = handler.on(
1267
- "onArrowUpOnFirstElement",
1268
- () => {
1269
- var _a;
1270
- return (_a = treeProps.onArrowUpOnFirstElement) == null ? void 0 : _a.call(treeProps);
1271
- }
1272
- );
1273
- return () => {
1274
- unsuscribe1();
1275
- unsuscribe2();
1276
- };
1277
- }, [focusOnNode, handler, treeProps]);
1278
- return {
1279
- data,
1280
- handler,
1281
- keyHandler: {
1282
- id: keyHandlerId,
1283
- onKeyDown: React.useCallback(
1284
- (ev) => {
1285
- var _a;
1286
- if (ev.key === "Enter") {
1287
- const key = handler.state.focusedNode;
1288
- if (key) {
1289
- const nodeProps = handler.propsStore.getFieldProps(key);
1290
- (_a = treeProps.onNodeClick) == null ? void 0 : _a.call(treeProps, ev, nodeProps);
1291
- }
1292
- } else {
1293
- handler.handleKey(ev);
1294
- }
1295
- },
1296
- [handler, treeProps]
1297
- ),
1298
- onMouseDown: React.useCallback(
1299
- (ev) => {
1300
- var _a;
1301
- const previousFocused = handler.state.focusedNode;
1302
- if (previousFocused !== null && ev.shiftKey && ((_a = handler.configuration.current) == null ? void 0 : _a.isMultiple))
1303
- ev.preventDefault();
1304
- },
1305
- [handler.configuration, handler.state.focusedNode]
1306
- ),
1307
- onClick: React.useCallback(
1308
- (ev) => {
1309
- var _a, _b;
1310
- if (getSpecificParent(
1311
- ev.target,
1312
- (current) => current.classList.contains("tree__expandIcon")
1313
- ))
1314
- return;
1315
- const node = getSpecificParent(
1316
- ev.target,
1317
- (current) => !!current.getAttribute("data-key")
1318
- );
1319
- if (node) {
1320
- const previousFocused = handler.state.focusedNode;
1321
- const key = node.getAttribute("data-key");
1322
- const nodeProps = handler.propsStore.getFieldProps(key);
1323
- (_a = treeProps.onNodeClick) == null ? void 0 : _a.call(treeProps, ev, nodeProps);
1324
- if (previousFocused !== null && ev.shiftKey && ((_b = handler.configuration.current) == null ? void 0 : _b.isMultiple)) {
1325
- selectAllNodesBetweenTwoNodes(
1326
- handler,
1327
- previousFocused,
1328
- key,
1329
- true
1330
- );
1331
- } else {
1332
- handler.setFocusedNode(key);
1333
- handler.setSelectedNodesByClickEvent(ev);
1334
- }
1335
- if (key)
1336
- focusOnNode(key);
1337
- }
1338
- },
1339
- [focusOnNode, handler, treeProps]
1340
- ),
1341
- ref: keyHandlerRef
1342
- }
1343
- };
1344
- }
1345
-
1346
- var __defProp$1 = Object.defineProperty;
1347
- var __defProps$1 = Object.defineProperties;
1348
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
1349
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1350
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1351
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1352
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1353
- var __spreadValues$1 = (a, b) => {
1354
- for (var prop in b || (b = {}))
1355
- if (__hasOwnProp$1.call(b, prop))
1356
- __defNormalProp$1(a, prop, b[prop]);
1357
- if (__getOwnPropSymbols$1)
1358
- for (var prop of __getOwnPropSymbols$1(b)) {
1359
- if (__propIsEnum$1.call(b, prop))
1360
- __defNormalProp$1(a, prop, b[prop]);
1361
- }
1362
- return a;
1363
- };
1364
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1365
- const Tree = (props) => {
1366
- var _a, _b, _c;
1367
- const { data, handler, keyHandler } = useTreeData({
1368
- name: props.name,
1369
- treeProps: __spreadValues$1({}, props)
1370
- });
1371
- const [isLoading, setIsLoading] = React.useState(false);
1372
- const [currentSearchString, setCurrentSearchString] = React.useState("");
1373
- const isTreeLoading = useTreeSelector(handler, {
1374
- selector: (current) => current.isLoading
1375
- });
1376
- React.useEffect(() => {
1377
- setIsLoading(isTreeLoading);
1378
- }, [isTreeLoading]);
1379
- const search = useDebounceFn(
1380
- () => {
1381
- if (props.filterString === void 0)
1382
- return;
1383
- setIsLoading(true);
1384
- React.startTransition(() => {
1385
- setCurrentSearchString(props.filterString);
1386
- });
1387
- if (props.filterString !== void 0 && props.filterString !== "") {
1388
- unfilterNodes(handler);
1389
- matchNodesAgainstString(handler, props.filterString);
1390
- handler.forceEmitUpdate();
1391
- } else {
1392
- unfilterNodes(handler);
1393
- handler.forceEmitUpdate();
1394
- }
1395
- setTimeout(() => setIsLoading(false), 0);
1396
- },
1397
- { wait: 200 }
1398
- );
1399
- React.useEffect(() => {
1400
- search.run();
1401
- if (!props.filterString)
1402
- search.flush();
1403
- }, [props.filterString]);
1404
- usePropsSelector(
1405
- handler.stateKey,
1406
- {
1407
- propsStore: handler.propsStore,
1408
- selector: (current) => current,
1409
- comparator: (prevProps, newProps) => {
1410
- var _a2;
1411
- if (props.onSelect && !shallowEqual(prevProps == null ? void 0 : prevProps.selectedNodes, newProps == null ? void 0 : newProps.selectedNodes)) {
1412
- props.onSelect(
1413
- ((_a2 = newProps == null ? void 0 : newProps.selectedNodes) != null ? _a2 : []).map(
1414
- (currentId) => handler.propsStore.getFieldProps(currentId)
1415
- )
1416
- );
1417
- }
1418
- return true;
1419
- }
1420
- }
1421
- );
1422
- const { focusedNode } = usePropsSelector(handler.stateKey, {
1423
- propsStore: handler.propsStore,
1424
- selector: (current) => ({
1425
- focusedNode: current.focusedNode
1426
- })
1427
- });
1428
- useMount(() => {
1429
- if (props.getHandler)
1430
- props.getHandler(handler);
1431
- });
1432
- useUnmount(() => handler.destructor());
1433
- const contextValue = React.useMemo(() => {
1434
- const actualValue = {
1435
- handler,
1436
- name: props.name,
1437
- forceUpdate: data.forceUpdate,
1438
- focusGetter: props.focusGetter,
1439
- treeProps: props
1440
- };
1441
- return actualValue;
1442
- }, [handler, props, data.forceUpdate]);
1443
- return /* @__PURE__ */ jsx(TreeContextProvider, { value: contextValue, children: /* @__PURE__ */ jsxs(
1444
- Box,
1445
- __spreadProps$1(__spreadValues$1({
1446
- className: `tree ${(_a = props.className) != null ? _a : ""}`
1447
- }, getVariant((_b = props.variant) != null ? _b : "layout.common.trees.primary")), {
1448
- children: [
1449
- /* @__PURE__ */ jsx(
1450
- SearchLabel,
1451
- {
1452
- isLoading: (_c = props.isLoading) != null ? _c : isLoading,
1453
- onDelete: props.onDeleteFilterString,
1454
- searchString: props.hideSearchLabel ? "" : currentSearchString
1455
- }
1456
- ),
1457
- /* @__PURE__ */ jsx(
1458
- TreeItemChildren$1,
1459
- __spreadValues$1({
1460
- "aria-activedescendant": focusedNode !== null ? getActiveDescendantName(props.name, focusedNode) : void 0,
1461
- "aria-label": props.label,
1462
- as: "ul",
1463
- forceUpdate: data.forceUpdate,
1464
- level: -1,
1465
- nodes: React.useMemo(
1466
- () => data.children.map(
1467
- (current) => handler.propsStore.getFieldProps(current)
1468
- ),
1469
- [data.children, handler.propsStore]
1470
- ),
1471
- role: "tree",
1472
- tabIndex: 0
1473
- }, keyHandler)
1474
- )
1475
- ]
1476
- })
1477
- ) });
1478
- };
1479
- var Tree$1 = memo(Tree);
1480
-
1481
- var __defProp = Object.defineProperty;
1482
- var __defProps = Object.defineProperties;
1483
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1484
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1485
- var __hasOwnProp = Object.prototype.hasOwnProperty;
1486
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
1487
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1488
- var __spreadValues = (a, b) => {
1489
- for (var prop in b || (b = {}))
1490
- if (__hasOwnProp.call(b, prop))
1491
- __defNormalProp(a, prop, b[prop]);
1492
- if (__getOwnPropSymbols)
1493
- for (var prop of __getOwnPropSymbols(b)) {
1494
- if (__propIsEnum.call(b, prop))
1495
- __defNormalProp(a, prop, b[prop]);
1496
- }
1497
- return a;
1498
- };
1499
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1500
- var __accessCheck$1 = (obj, member, msg) => {
1501
- if (!member.has(obj))
1502
- throw TypeError("Cannot " + msg);
1503
- };
1504
- var __privateGet$1 = (obj, member, getter) => {
1505
- __accessCheck$1(obj, member, "read from private field");
1506
- return getter ? getter.call(obj) : member.get(obj);
1507
- };
1508
- var __privateAdd$1 = (obj, member, value) => {
1509
- if (member.has(obj))
1510
- throw TypeError("Cannot add the same private member more than once");
1511
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1512
- };
1513
- var _getByAbsoluteId;
1514
- function isOOTreeNode(element) {
1515
- return typeof element.attachToTree === "function";
1516
- }
1517
- const _OOTreeNode = class {
1518
- constructor(tree, parent, props) {
1519
- this.tree = tree;
1520
- this.parent = parent;
1521
- this.props = props;
1522
- this.id = "";
1523
- this.prefix = "";
1524
- __privateAdd$1(this, _getByAbsoluteId, (id) => {
1525
- const props = this.tree.getController().propsStore.getFieldProps(id);
1526
- if (props === void 0)
1527
- return void 0;
1528
- return new _OOTreeNode(this.tree, props, props);
1529
- });
1530
- if (parent) {
1531
- if (isOOTreeNode(parent)) {
1532
- Object.assign(
1533
- this,
1534
- this.tree.calculateNodePrefix(props.id, parent == null ? void 0 : parent.prefix)
1535
- );
1536
- } else {
1537
- this.prefix = props.nodeProps.__prefix;
1538
- this.id = String(props.id);
1539
- }
1540
- }
1541
- }
1542
- attachToTree() {
1543
- var _a, _b;
1544
- const parentId = (_b = (_a = this.parent) == null ? void 0 : _a.id) != null ? _b : void 0;
1545
- this.tree.getController().append(__spreadProps(__spreadValues({}, this.props), {
1546
- id: this.id,
1547
- label: this.props.label,
1548
- parentId,
1549
- nodeProps: __spreadProps(__spreadValues({}, this.props.nodeProps), {
1550
- __prefix: this.prefix,
1551
- __id: this.props.id
1552
- })
1553
- }));
1554
- }
1555
- append(props) {
1556
- const newNode = new _OOTreeNode(this.tree, this, props);
1557
- newNode.attachToTree();
1558
- return newNode;
1559
- }
1560
- collapse() {
1561
- this.tree.getController().setExpandedNodes(
1562
- this.tree.getController().state.expandedNodes.filter(
1563
- (current) => current !== this.getProps().id
1564
- )
1565
- );
1566
- }
1567
- expand() {
1568
- var _a, _b;
1569
- this.tree.getController().setExpandedNodes([
1570
- ...this.tree.getController().state.expandedNodes,
1571
- this.getProps().id
1572
- ]);
1573
- (_b = (_a = this.parent).expand) == null ? void 0 : _b.call(_a);
1574
- }
1575
- focus(expand) {
1576
- this.tree.getController().setFocusedNode(this.getProps().id);
1577
- if (expand) {
1578
- this.expand();
1579
- }
1580
- }
1581
- getAll() {
1582
- return this.tree.getController().propsStore.getFieldProps(this.id).children.map((current) => {
1583
- return () => {
1584
- return __privateGet$1(this, _getByAbsoluteId).call(this, String(current));
1585
- };
1586
- });
1587
- }
1588
- getById(id) {
1589
- const { id: actualId } = this.tree.calculateNodePrefix(id, this.prefix);
1590
- const props = this.tree.getController().propsStore.getFieldProps(actualId);
1591
- if (props === void 0)
1592
- return void 0;
1593
- return new _OOTreeNode(this.tree, props, props);
1594
- }
1595
- getOriginalId() {
1596
- return this.getProps().nodeProps.__id;
1597
- }
1598
- getParent() {
1599
- if (!this.parent)
1600
- return null;
1601
- const props = this.tree.getController().propsStore.getFieldProps(this.parent.id);
1602
- const parent = props.parentId;
1603
- const parentProps = this.tree.getController().propsStore.getFieldProps(parent);
1604
- return new _OOTreeNode(this.tree, parentProps, props);
1605
- }
1606
- getProps() {
1607
- return this.tree.getController().propsStore.getFieldProps(this.id);
1608
- }
1609
- remove() {
1610
- this.tree.getController().remove(this.id, true);
1611
- }
1612
- sort(sortFunction) {
1613
- const children = this.getProps().children.map(
1614
- (current) => this.tree.getController().propsStore.getFieldProps(current)
1615
- ).sort((a, b) => sortFunction(a, b)).map((current) => current.id);
1616
- this.tree.getController().propsStore.updateField(this.id, { children });
1617
- }
1618
- update(props) {
1619
- this.tree.getController().propsStore.updateField(this.id, props);
1620
- }
1621
- };
1622
- let OOTreeNode = _OOTreeNode;
1623
- _getByAbsoluteId = new WeakMap();
1624
-
1625
- class OOTreeChildren extends OOTreeNode {
1626
- constructor(tree) {
1627
- super(tree, null, {});
1628
- this.tree = tree;
1629
- this.prefix = "c";
1630
- }
1631
- /**
1632
- * Se sobreescribe para evitar problemas
1633
- */
1634
- expand() {
1635
- }
1636
- }
1637
-
1638
- var __accessCheck = (obj, member, msg) => {
1639
- if (!member.has(obj))
1640
- throw TypeError("Cannot " + msg);
1641
- };
1642
- var __privateGet = (obj, member, getter) => {
1643
- __accessCheck(obj, member, "read from private field");
1644
- return getter ? getter.call(obj) : member.get(obj);
1645
- };
1646
- var __privateAdd = (obj, member, value) => {
1647
- if (member.has(obj))
1648
- throw TypeError("Cannot add the same private member more than once");
1649
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1650
- };
1651
- var __privateSet = (obj, member, value, setter) => {
1652
- __accessCheck(obj, member, "write to private field");
1653
- setter ? setter.call(obj, value) : member.set(obj, value);
1654
- return value;
1655
- };
1656
- var _children, _controller, _makeHandler;
1657
- class OOTree extends HashedEventEmitter {
1658
- constructor(label, name, hashMethod) {
1659
- super(hashMethod);
1660
- this.label = label;
1661
- this.name = name;
1662
- /**
1663
- * Accessors
1664
- */
1665
- __privateAdd(this, _children, null);
1666
- __privateAdd(this, _controller, {});
1667
- this.getChildren = () => {
1668
- if (__privateGet(this, _children) === null)
1669
- throw new Error(
1670
- "Children was not assigned yet, maybe you forgot to listen to onReady event on OOTree component."
1671
- );
1672
- return __privateGet(this, _children);
1673
- };
1674
- this.getController = () => {
1675
- if (__privateGet(this, _controller) === null)
1676
- throw new Error(
1677
- "Controller was not assigned yet, maybe you forgot to listen to onReady event on OOTree component."
1678
- );
1679
- const c = this;
1680
- return new Proxy(__privateGet(this, _controller), {
1681
- get(target, prop) {
1682
- if (prop === "removeAll") {
1683
- return () => {
1684
- var _a;
1685
- c.prefixesMap = {};
1686
- (_a = __privateGet(c, _controller)) == null ? void 0 : _a.removeAll();
1687
- };
1688
- }
1689
- return target[prop];
1690
- }
1691
- });
1692
- };
1693
- /**
1694
- * Component
1695
- */
1696
- __privateAdd(this, _makeHandler, () => {
1697
- __privateSet(this, _controller, new TreeDataController(this.name, {
1698
- current: {}
1699
- }));
1700
- __privateSet(this, _children, new OOTreeChildren(this));
1701
- });
1702
- this.Component = () => {
1703
- return /* @__PURE__ */ jsx(
1704
- Tree$1,
1705
- {
1706
- label: this.label,
1707
- name: this.name,
1708
- controller: __privateGet(this, _controller)
1709
- }
1710
- );
1711
- };
1712
- /**
1713
- * Data manipulation
1714
- */
1715
- this.prefixJoinCharacter = "$";
1716
- this.prefixWithIdJoinCharacter = "__";
1717
- this.prefixesMap = {};
1718
- /**
1719
- * Calcula el prefijo de un nodo que se está agregando al árbol evitando
1720
- * colisiones. Ese prefijo estará asociado a cada nodo y se utilizará para dar
1721
- * nombres únicos a sus hijos, no para el nodo en sí. Entonces, cada vez que
1722
- * se construye un nodo, se le asigna un prefijo considerando el prefijo de su
1723
- * padre, pero su nombre se hace a partir del prefijo del padre y su id.
1724
- */
1725
- this.calculateNodePrefix = (id, prefix) => {
1726
- const expectedPrefix = [prefix, String(id).charAt(0)].filter(Boolean).join(this.prefixJoinCharacter);
1727
- let i = 1;
1728
- let actualPrefix = expectedPrefix;
1729
- while (this.prefixesMap[actualPrefix] !== void 0) {
1730
- actualPrefix = `${expectedPrefix}${i++}`;
1731
- }
1732
- this.prefixesMap[actualPrefix] = {
1733
- nodeId: id,
1734
- prefix: actualPrefix
1735
- };
1736
- const data = {
1737
- prefix: actualPrefix,
1738
- id: [[prefix].filter(Boolean).join(this.prefixJoinCharacter), id].filter(Boolean).join(this.prefixWithIdJoinCharacter)
1739
- };
1740
- return data;
1741
- };
1742
- __privateGet(this, _makeHandler).call(this);
1743
- }
1744
- }
1745
- _children = new WeakMap();
1746
- _controller = new WeakMap();
1747
- _makeHandler = new WeakMap();
1748
-
1749
- export { OOTree, OOTreeNode, Tree$1 as Tree, TreeDataController, isOOTreeNode, useTreeContext, useTreeData, useTreeDataController, useTreeSelector, useTreeSelectorByName };
1
+ export { default as Tree } from './Tree.js';
2
+ export { useTreeContext } from './TreeContext.js';
3
+ export { default as TreeDataController, useTreeDataController, useTreeSelector, useTreeSelectorByName } from './TreeDataController.js';
4
+ export { default as useTreeData } from './useTreeData.js';
5
+ export { OOTree } from './OOTree/index.js';
6
+ export { OOTreeNode, isOOTreeNode } from './OOTree/OOTreeNode.js';
7
+ //# sourceMappingURL=index.js.map