@apia/tree 3.0.1 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +415 -7
- package/dist/index.js +1547 -6
- package/dist/index.js.map +1 -1
- package/package.json +11 -7
- package/dist/OOTree/OOTreeChildren.d.ts +0 -14
- package/dist/OOTree/OOTreeChildren.d.ts.map +0 -1
- package/dist/OOTree/OOTreeChildren.js +0 -17
- package/dist/OOTree/OOTreeChildren.js.map +0 -1
- package/dist/OOTree/OOTreeNode.d.ts +0 -30
- package/dist/OOTree/OOTreeNode.d.ts.map +0 -1
- package/dist/OOTree/OOTreeNode.js +0 -133
- package/dist/OOTree/OOTreeNode.js.map +0 -1
- package/dist/OOTree/index.d.ts +0 -36
- package/dist/OOTree/index.d.ts.map +0 -1
- package/dist/OOTree/index.js +0 -126
- package/dist/OOTree/index.js.map +0 -1
- package/dist/OOTree/types.d.ts +0 -11
- package/dist/OOTree/types.d.ts.map +0 -1
- package/dist/SearchLabel.js +0 -32
- package/dist/SearchLabel.js.map +0 -1
- package/dist/Tree.d.ts +0 -7
- package/dist/Tree.d.ts.map +0 -1
- package/dist/Tree.js +0 -131
- package/dist/Tree.js.map +0 -1
- package/dist/TreeContext.d.ts +0 -13
- package/dist/TreeContext.d.ts.map +0 -1
- package/dist/TreeContext.js +0 -22
- package/dist/TreeContext.js.map +0 -1
- package/dist/TreeDataController.d.ts +0 -116
- package/dist/TreeDataController.d.ts.map +0 -1
- package/dist/TreeDataController.js +0 -616
- package/dist/TreeDataController.js.map +0 -1
- package/dist/TreeItem.js +0 -51
- package/dist/TreeItem.js.map +0 -1
- package/dist/TreeItemChildren.js +0 -20
- package/dist/TreeItemChildren.js.map +0 -1
- package/dist/TreeItemLabel.js +0 -72
- package/dist/TreeItemLabel.js.map +0 -1
- package/dist/getDomProps.js +0 -37
- package/dist/getDomProps.js.map +0 -1
- package/dist/renderers/DefaultIconRenderer.js +0 -18
- package/dist/renderers/DefaultIconRenderer.js.map +0 -1
- package/dist/renderers/DefaultLabelRenderer.js +0 -10
- package/dist/renderers/DefaultLabelRenderer.js.map +0 -1
- package/dist/renderers/Spacer.js +0 -10
- package/dist/renderers/Spacer.js.map +0 -1
- package/dist/types.d.ts +0 -211
- package/dist/types.d.ts.map +0 -1
- package/dist/useTreeData.d.ts +0 -25
- package/dist/useTreeData.d.ts.map +0 -1
- package/dist/useTreeData.js +0 -131
- package/dist/useTreeData.js.map +0 -1
- package/dist/util.js +0 -220
- package/dist/util.js.map +0 -1
package/dist/OOTree/index.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { jsx } from '@apia/theme/jsx-runtime';
|
|
2
|
-
import { EventEmitter } from '@apia/util';
|
|
3
|
-
import TreeDataController from '../TreeDataController.js';
|
|
4
|
-
import Tree from '../Tree.js';
|
|
5
|
-
import { OOTreeChildren } from './OOTreeChildren.js';
|
|
6
|
-
|
|
7
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __publicField = (obj, key, value) => {
|
|
10
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11
|
-
return value;
|
|
12
|
-
};
|
|
13
|
-
var __accessCheck = (obj, member, msg) => {
|
|
14
|
-
if (!member.has(obj))
|
|
15
|
-
throw TypeError("Cannot " + msg);
|
|
16
|
-
};
|
|
17
|
-
var __privateGet = (obj, member, getter) => {
|
|
18
|
-
__accessCheck(obj, member, "read from private field");
|
|
19
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
20
|
-
};
|
|
21
|
-
var __privateAdd = (obj, member, value) => {
|
|
22
|
-
if (member.has(obj))
|
|
23
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
24
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
-
};
|
|
26
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
27
|
-
__accessCheck(obj, member, "write to private field");
|
|
28
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
29
|
-
return value;
|
|
30
|
-
};
|
|
31
|
-
var _children, _controller, _makeHandler;
|
|
32
|
-
class OOTree extends EventEmitter {
|
|
33
|
-
constructor(props) {
|
|
34
|
-
super();
|
|
35
|
-
this.props = props;
|
|
36
|
-
/**
|
|
37
|
-
* Accessors
|
|
38
|
-
*/
|
|
39
|
-
__privateAdd(this, _children, null);
|
|
40
|
-
__privateAdd(this, _controller, {});
|
|
41
|
-
__publicField(this, "getChildren", () => {
|
|
42
|
-
if (__privateGet(this, _children) === null)
|
|
43
|
-
throw new Error(
|
|
44
|
-
"Children was not assigned yet, maybe you forgot to listen to onReady event on OOTree component."
|
|
45
|
-
);
|
|
46
|
-
return __privateGet(this, _children);
|
|
47
|
-
});
|
|
48
|
-
__publicField(this, "getController", () => {
|
|
49
|
-
if (__privateGet(this, _controller) === null)
|
|
50
|
-
throw new Error(
|
|
51
|
-
"Controller was not assigned yet, maybe you forgot to listen to onReady event on OOTree component."
|
|
52
|
-
);
|
|
53
|
-
const c = this;
|
|
54
|
-
return new Proxy(__privateGet(this, _controller), {
|
|
55
|
-
get(target, prop) {
|
|
56
|
-
if (prop === "removeAll") {
|
|
57
|
-
return () => {
|
|
58
|
-
c.prefixesMap = {};
|
|
59
|
-
__privateGet(c, _controller)?.removeAll();
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
return target[prop];
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
/**
|
|
67
|
-
* Component
|
|
68
|
-
*/
|
|
69
|
-
__privateAdd(this, _makeHandler, () => {
|
|
70
|
-
__privateSet(this, _controller, new TreeDataController(this.props.name, {
|
|
71
|
-
current: this.props
|
|
72
|
-
}));
|
|
73
|
-
__privateSet(this, _children, new OOTreeChildren(this));
|
|
74
|
-
});
|
|
75
|
-
__publicField(this, "Component", (props) => {
|
|
76
|
-
return /* @__PURE__ */ jsx(
|
|
77
|
-
Tree,
|
|
78
|
-
{
|
|
79
|
-
controller: __privateGet(this, _controller),
|
|
80
|
-
...this.props,
|
|
81
|
-
...props
|
|
82
|
-
}
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
/**
|
|
86
|
-
* Data manipulation
|
|
87
|
-
*/
|
|
88
|
-
__publicField(this, "prefixJoinCharacter", "$$");
|
|
89
|
-
__publicField(this, "prefixWithIdJoinCharacter", "__");
|
|
90
|
-
__publicField(this, "prefixesMap", {});
|
|
91
|
-
__publicField(this, "calculateDepth", (id) => {
|
|
92
|
-
return [...String(id).matchAll(/\$\$/g)].length;
|
|
93
|
-
});
|
|
94
|
-
/**
|
|
95
|
-
* Calcula el prefijo de un nodo que se está agregando al árbol evitando
|
|
96
|
-
* colisiones. Ese prefijo estará asociado a cada nodo y se utilizará para dar
|
|
97
|
-
* nombres únicos a sus hijos, no para el nodo en sí. Entonces, cada vez que
|
|
98
|
-
* se construye un nodo, se le asigna un prefijo considerando el prefijo de su
|
|
99
|
-
* padre, pero su nombre se hace a partir del prefijo del padre y su id.
|
|
100
|
-
*/
|
|
101
|
-
__publicField(this, "calculateNodePrefix", (id, prefix) => {
|
|
102
|
-
const expectedPrefix = [prefix, String(id).charAt(0)].filter(Boolean).join(this.prefixJoinCharacter);
|
|
103
|
-
let i = 1;
|
|
104
|
-
let actualPrefix = expectedPrefix;
|
|
105
|
-
while (this.prefixesMap[actualPrefix] !== void 0) {
|
|
106
|
-
actualPrefix = `${expectedPrefix}${i++}`;
|
|
107
|
-
}
|
|
108
|
-
this.prefixesMap[actualPrefix] = {
|
|
109
|
-
nodeId: id,
|
|
110
|
-
prefix: actualPrefix
|
|
111
|
-
};
|
|
112
|
-
const data = {
|
|
113
|
-
prefix: actualPrefix,
|
|
114
|
-
id: [[prefix].filter(Boolean).join(this.prefixJoinCharacter), id].filter(Boolean).join(this.prefixWithIdJoinCharacter)
|
|
115
|
-
};
|
|
116
|
-
return data;
|
|
117
|
-
});
|
|
118
|
-
__privateGet(this, _makeHandler).call(this);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
_children = new WeakMap();
|
|
122
|
-
_controller = new WeakMap();
|
|
123
|
-
_makeHandler = new WeakMap();
|
|
124
|
-
|
|
125
|
-
export { OOTree };
|
|
126
|
-
//# sourceMappingURL=index.js.map
|
package/dist/OOTree/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/OOTree/index.tsx"],"sourcesContent":["import { EventEmitter, TId } from '@apia/util';\nimport TreeDataController from '../TreeDataController';\nimport Tree from '../Tree';\nimport { PrefixMapEntry } from './types';\nimport { OOTreeChildren } from './OOTreeChildren';\nimport { TTreeProps } from '../types';\n\nexport class OOTree<\n NodeProps extends Record<string, unknown> = Record<string, unknown>,\n Events extends Record<string, unknown> = Record<string, unknown>,\n> extends EventEmitter<Events> {\n constructor(public props: TTreeProps<NodeProps>) {\n super();\n\n this.#makeHandler();\n }\n\n /**\n * Accessors\n */\n #children: OOTreeChildren<NodeProps> | null = null;\n\n #controller: TreeDataController<NodeProps> =\n {} as TreeDataController<NodeProps>;\n\n getChildren = () => {\n if (this.#children === null)\n throw new Error(\n 'Children was not assigned yet, maybe you forgot to listen to onReady event on OOTree component.',\n );\n\n return this.#children;\n };\n\n getController = () => {\n if (this.#controller === null)\n throw new Error(\n 'Controller was not assigned yet, maybe you forgot to listen to onReady event on OOTree component.',\n );\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const c = this;\n\n return new Proxy(this.#controller, {\n get(target, prop) {\n if (prop === 'removeAll') {\n return () => {\n c.prefixesMap = {};\n c.#controller?.removeAll();\n };\n }\n\n return target[prop as keyof typeof target];\n },\n });\n };\n\n /**\n * Component\n */\n #makeHandler = () => {\n this.#controller = new TreeDataController<NodeProps>(this.props.name, {\n current: this.props,\n });\n this.#children = new OOTreeChildren<NodeProps>(this);\n };\n\n Component = (props: Partial<TTreeProps<NodeProps>>) => {\n return (\n <Tree<NodeProps>\n controller={this.#controller}\n {...this.props}\n {...props}\n />\n );\n };\n\n /**\n * Data manipulation\n */\n private prefixJoinCharacter = '$$';\n private prefixWithIdJoinCharacter = '__';\n\n protected prefixesMap: Record<string, PrefixMapEntry> = {};\n\n calculateDepth = (id: TId) => {\n return [...String(id).matchAll(/\\$\\$/g)].length;\n };\n\n /**\n * Calcula el prefijo de un nodo que se está agregando al árbol evitando\n * colisiones. Ese prefijo estará asociado a cada nodo y se utilizará para dar\n * nombres únicos a sus hijos, no para el nodo en sí. Entonces, cada vez que\n * se construye un nodo, se le asigna un prefijo considerando el prefijo de su\n * padre, pero su nombre se hace a partir del prefijo del padre y su id.\n */\n calculateNodePrefix = (id: TId, prefix?: string) => {\n const expectedPrefix = [prefix, String(id).charAt(0)]\n .filter(Boolean)\n .join(this.prefixJoinCharacter);\n\n let i = 1;\n let actualPrefix = expectedPrefix;\n while (this.prefixesMap[actualPrefix] !== undefined) {\n actualPrefix = `${expectedPrefix}${i++}`;\n }\n\n this.prefixesMap[actualPrefix] = {\n nodeId: id,\n prefix: actualPrefix,\n };\n\n const data = {\n prefix: actualPrefix,\n id: [[prefix].filter(Boolean).join(this.prefixJoinCharacter), id]\n .filter(Boolean)\n .join(this.prefixWithIdJoinCharacter),\n };\n return data;\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,SAAA,EAAA,WAAA,EAAA,YAAA,CAAA;AAOO,MAAM,eAGH,YAAqB,CAAA;AAAA,EAC7B,YAAmB,KAA8B,EAAA;AAC/C,IAAM,KAAA,EAAA,CAAA;AADW,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA,CAAA;AASnB;AAAA;AAAA;AAAA,IAA8C,YAAA,CAAA,IAAA,EAAA,SAAA,EAAA,IAAA,CAAA,CAAA;AAE9C,IAAA,YAAA,CAAA,IAAA,EAAA,WAAA,EACE,EAAC,C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,EAAA,CAAA,CAAA,CAAA;AAAA,OACxC;AAEA,MAAK,IAAA,CAAA,WAAA,CAAY,YAAY,CAAI,GAAA;AAAA,QAC/B,MAAQ,EAAA,EAAA;AAAA,QACR,MAAQ,EAAA,YAAA;AAAA,OACV,CAAA;AAEA,MAAA,MAAM,IAAO,GAAA;AAAA,QACX,MAAQ,EAAA,YAAA;AAAA,QACR,IAAI,CAAC,CAAC,MAAM,CAAE,CAAA,MAAA,CAAO,OAAO,CAAE,CAAA,IAAA,CAAK,KAAK,mBAAmB,CAAA,EAAG,EAAE,CAC7D,CAAA,MAAA,CAAO,OAAO,CACd,CAAA,IAAA,CAAK,KAAK,yBAAyB,CAAA;AAAA,OACxC,CAAA;AACA,MAAO,OAAA,IAAA,CAAA;AAAA,KACT,CAAA,CAAA;AAzGE,IAAA,YAAA,CAAA,IAAA,EAAK,YAAL,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA,CAAA;AAAA,GACF;AAyGF,CAAA;AApGE,SAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AAEA,WAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AAsCA,YAAA,GAAA,IAAA,OAAA,EAAA;;;;"}
|
package/dist/OOTree/types.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TId, TDataNode } from '../types.js';
|
|
2
|
-
|
|
3
|
-
type PrefixMapEntry = {
|
|
4
|
-
nodeId: TId;
|
|
5
|
-
prefix: string;
|
|
6
|
-
};
|
|
7
|
-
type TOOTreeNodeProps<NodeProps extends Record<string, unknown> = Record<string, unknown>> = Omit<TDataNode<NodeProps>, 'actualParentId' | 'parentId' | 'children' | 'hasLoaded'>;
|
|
8
|
-
type TSortOOTreeChildren<NodeProps extends Record<string, unknown> = Record<string, unknown>> = (a: TDataNode<NodeProps>, b: TDataNode<NodeProps>) => number;
|
|
9
|
-
|
|
10
|
-
export type { PrefixMapEntry, TOOTreeNodeProps, TSortOOTreeChildren };
|
|
11
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/SearchLabel.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from '@apia/theme/jsx-runtime';
|
|
2
|
-
import { IconButton } from '@apia/components';
|
|
3
|
-
import { Box, getVariant } from '@apia/theme';
|
|
4
|
-
import { formatMessage } from '@apia/util';
|
|
5
|
-
import LoaderSpinner from './components/src/components/loaders/LoaderSpinner.js';
|
|
6
|
-
|
|
7
|
-
const SearchLabel = ({
|
|
8
|
-
isLoading: isSearching,
|
|
9
|
-
onDelete,
|
|
10
|
-
searchString
|
|
11
|
-
}) => {
|
|
12
|
-
if (!searchString && !isSearching)
|
|
13
|
-
return null;
|
|
14
|
-
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: [
|
|
15
|
-
formatMessage(window.LBL_FILTERING_BY, { TOK1: searchString }),
|
|
16
|
-
/* @__PURE__ */ jsx(
|
|
17
|
-
IconButton,
|
|
18
|
-
{
|
|
19
|
-
icon: "Close",
|
|
20
|
-
"aria-label": window.LBL_DELETE_FILTER,
|
|
21
|
-
onClick: onDelete,
|
|
22
|
-
title: window.LBL_DELETE_FILTER,
|
|
23
|
-
size: "Sm",
|
|
24
|
-
...getVariant("icon-inherit")
|
|
25
|
-
}
|
|
26
|
-
)
|
|
27
|
-
] }) });
|
|
28
|
-
};
|
|
29
|
-
var SearchLabel$1 = SearchLabel;
|
|
30
|
-
|
|
31
|
-
export { SearchLabel$1 as default };
|
|
32
|
-
//# sourceMappingURL=SearchLabel.js.map
|
package/dist/SearchLabel.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SearchLabel.js","sources":["../src/SearchLabel.tsx"],"sourcesContent":["import { IconButton } from '@apia/components';\nimport { getVariant } from '@apia/theme';\nimport { formatMessage } from '@apia/util';\nimport { Box } from '@apia/theme';\nimport LoaderSpinner from '../../components/src/components/loaders/LoaderSpinner';\nconst SearchLabel = ({\n isLoading: isSearching,\n onDelete,\n searchString,\n}: {\n isLoading: boolean;\n onDelete?: () => unknown;\n searchString: string;\n}) => {\n if (!searchString && !isSearching) return null;\n return (\n <Box className={`tree__searchLabelBox ${isSearching ? 'isLoading' : ''}`}>\n {isSearching ? (\n <LoaderSpinner className=\"tree__loading\" />\n ) : (\n <Box as=\"label\" className=\"tree__searchLabel\">\n {formatMessage(window.LBL_FILTERING_BY, { TOK1: searchString })}\n <IconButton\n icon=\"Close\"\n aria-label={window.LBL_DELETE_FILTER}\n onClick={onDelete}\n title={window.LBL_DELETE_FILTER}\n size=\"Sm\"\n {...getVariant('icon-inherit')}\n />\n </Box>\n )}\n </Box>\n );\n};\n\nexport default SearchLabel;\n"],"names":[],"mappings":";;;;;;AAKA,MAAM,cAAc,CAAC;AAAA,EACnB,SAAW,EAAA,WAAA;AAAA,EACX,QAAA;AAAA,EACA,YAAA;AACF,CAIM,KAAA;AACJ,EAAI,IAAA,CAAC,gBAAgB,CAAC,WAAA;AAAa,IAAO,OAAA,IAAA,CAAA;AAC1C,EAAA,2BACG,GAAI,EAAA,EAAA,SAAA,EAAW,wBAAwB,WAAc,GAAA,WAAA,GAAc,EAAE,CACnE,CAAA,EAAA,QAAA,EAAA,WAAA,uBACE,aAAc,EAAA,EAAA,SAAA,EAAU,iBAAgB,CAEzC,mBAAA,IAAA,CAAC,OAAI,EAAG,EAAA,OAAA,EAAQ,WAAU,mBACvB,EAAA,QAAA,EAAA;AAAA,IAAA,aAAA,CAAc,MAAO,CAAA,gBAAA,EAAkB,EAAE,IAAA,EAAM,cAAc,CAAA;AAAA,oBAC9D,GAAA;AAAA,MAAC,UAAA;AAAA,MAAA;AAAA,QACC,IAAK,EAAA,OAAA;AAAA,QACL,cAAY,MAAO,CAAA,iBAAA;AAAA,QACnB,OAAS,EAAA,QAAA;AAAA,QACT,OAAO,MAAO,CAAA,iBAAA;AAAA,QACd,IAAK,EAAA,IAAA;AAAA,QACJ,GAAG,WAAW,cAAc,CAAA;AAAA,OAAA;AAAA,KAC/B;AAAA,GAAA,EACF,CAEJ,EAAA,CAAA,CAAA;AAEJ,CAAA,CAAA;AAEA,oBAAe,WAAA;;;;"}
|
package/dist/Tree.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import React__default from 'react';
|
|
2
|
-
import { TDataNode, TTreeProps } from './types.js';
|
|
3
|
-
|
|
4
|
-
declare const _default: <NodeProps extends Record<string, unknown> = Record<string, unknown>, NodeType extends TDataNode<NodeProps> = TDataNode<NodeProps>>(props: TTreeProps<NodeProps, NodeType>) => React__default.JSX.Element;
|
|
5
|
-
|
|
6
|
-
export { _default as default };
|
|
7
|
-
//# sourceMappingURL=Tree.d.ts.map
|
package/dist/Tree.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Tree.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/Tree.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from '@apia/theme/jsx-runtime';
|
|
2
|
-
import { useDebounceFn, useMount, useUnmount } from 'ahooks';
|
|
3
|
-
import React, { memo } from 'react';
|
|
4
|
-
import { shallowEqual } from 'react-redux';
|
|
5
|
-
import { Box, getVariant } from '@apia/theme';
|
|
6
|
-
import { getActiveDescendantName } from './getDomProps.js';
|
|
7
|
-
import SearchLabel from './SearchLabel.js';
|
|
8
|
-
import { TreeContextProvider } from './TreeContext.js';
|
|
9
|
-
import { useTreeSelector } from './TreeDataController.js';
|
|
10
|
-
import TreeItemChildren from './TreeItemChildren.js';
|
|
11
|
-
import useTreeData from './useTreeData.js';
|
|
12
|
-
import { unfilterNodes, matchNodesAgainstString } from './util.js';
|
|
13
|
-
import { usePropsSelector } from '@apia/util';
|
|
14
|
-
|
|
15
|
-
const Tree = (props) => {
|
|
16
|
-
const { data, handler, keyHandler } = useTreeData({
|
|
17
|
-
name: props.name,
|
|
18
|
-
treeProps: { ...props }
|
|
19
|
-
});
|
|
20
|
-
const [isLoading, setIsLoading] = React.useState(false);
|
|
21
|
-
const [currentSearchString, setCurrentSearchString] = React.useState("");
|
|
22
|
-
const isTreeLoading = useTreeSelector(handler, {
|
|
23
|
-
selector: (current) => current.isLoading
|
|
24
|
-
});
|
|
25
|
-
React.useEffect(() => {
|
|
26
|
-
setIsLoading(isTreeLoading);
|
|
27
|
-
}, [isTreeLoading]);
|
|
28
|
-
const search = useDebounceFn(
|
|
29
|
-
() => {
|
|
30
|
-
if (props.filterString === void 0)
|
|
31
|
-
return;
|
|
32
|
-
setIsLoading(true);
|
|
33
|
-
React.startTransition(() => {
|
|
34
|
-
setCurrentSearchString(props.filterString);
|
|
35
|
-
});
|
|
36
|
-
if (props.filterString !== void 0 && props.filterString !== "") {
|
|
37
|
-
unfilterNodes(handler);
|
|
38
|
-
matchNodesAgainstString(handler, props.filterString);
|
|
39
|
-
handler.forceEmitUpdate();
|
|
40
|
-
} else {
|
|
41
|
-
unfilterNodes(handler);
|
|
42
|
-
handler.forceEmitUpdate();
|
|
43
|
-
}
|
|
44
|
-
setTimeout(() => setIsLoading(false), 0);
|
|
45
|
-
},
|
|
46
|
-
{ wait: 200 }
|
|
47
|
-
);
|
|
48
|
-
React.useEffect(() => {
|
|
49
|
-
search.run();
|
|
50
|
-
if (!props.filterString)
|
|
51
|
-
search.flush();
|
|
52
|
-
}, [props.filterString]);
|
|
53
|
-
usePropsSelector(
|
|
54
|
-
handler.stateKey,
|
|
55
|
-
{
|
|
56
|
-
propsStore: handler.propsStore,
|
|
57
|
-
selector: (current) => current,
|
|
58
|
-
comparator: (prevProps, newProps) => {
|
|
59
|
-
if (props.onSelect && !shallowEqual(prevProps?.selectedNodes, newProps?.selectedNodes)) {
|
|
60
|
-
props.onSelect(
|
|
61
|
-
(newProps?.selectedNodes ?? []).map(
|
|
62
|
-
(currentId) => handler.propsStore.getFieldProps(currentId)
|
|
63
|
-
)
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
const { focusedNode } = usePropsSelector(handler.stateKey, {
|
|
71
|
-
propsStore: handler.propsStore,
|
|
72
|
-
selector: (current) => ({
|
|
73
|
-
focusedNode: current.focusedNode
|
|
74
|
-
})
|
|
75
|
-
});
|
|
76
|
-
useMount(() => {
|
|
77
|
-
if (props.getHandler)
|
|
78
|
-
props.getHandler(handler);
|
|
79
|
-
});
|
|
80
|
-
useUnmount(() => handler.destructor());
|
|
81
|
-
const contextValue = React.useMemo(() => {
|
|
82
|
-
const actualValue = {
|
|
83
|
-
handler,
|
|
84
|
-
name: props.name,
|
|
85
|
-
forceUpdate: data.forceUpdate,
|
|
86
|
-
focusGetter: props.focusGetter,
|
|
87
|
-
treeProps: props
|
|
88
|
-
};
|
|
89
|
-
return actualValue;
|
|
90
|
-
}, [handler, props, data.forceUpdate]);
|
|
91
|
-
return /* @__PURE__ */ jsx(TreeContextProvider, { value: contextValue, children: /* @__PURE__ */ jsxs(
|
|
92
|
-
Box,
|
|
93
|
-
{
|
|
94
|
-
className: `tree ${props.className ?? ""}`,
|
|
95
|
-
...getVariant(props.variant ?? "layout.common.trees.primary"),
|
|
96
|
-
children: [
|
|
97
|
-
/* @__PURE__ */ jsx(
|
|
98
|
-
SearchLabel,
|
|
99
|
-
{
|
|
100
|
-
isLoading: props.isLoading ?? isLoading,
|
|
101
|
-
onDelete: props.onDeleteFilterString,
|
|
102
|
-
searchString: props.hideSearchLabel ? "" : currentSearchString
|
|
103
|
-
}
|
|
104
|
-
),
|
|
105
|
-
/* @__PURE__ */ jsx(
|
|
106
|
-
TreeItemChildren,
|
|
107
|
-
{
|
|
108
|
-
"aria-activedescendant": focusedNode !== null ? getActiveDescendantName(props.name, focusedNode) : void 0,
|
|
109
|
-
"aria-label": props.label,
|
|
110
|
-
as: "ul",
|
|
111
|
-
forceUpdate: data.forceUpdate,
|
|
112
|
-
level: -1,
|
|
113
|
-
nodes: React.useMemo(
|
|
114
|
-
() => data.children.map(
|
|
115
|
-
(current) => handler.propsStore.getFieldProps(current)
|
|
116
|
-
),
|
|
117
|
-
[data.children, handler.propsStore]
|
|
118
|
-
),
|
|
119
|
-
role: "tree",
|
|
120
|
-
tabIndex: 0,
|
|
121
|
-
...keyHandler
|
|
122
|
-
}
|
|
123
|
-
)
|
|
124
|
-
]
|
|
125
|
-
}
|
|
126
|
-
) });
|
|
127
|
-
};
|
|
128
|
-
var Tree$1 = memo(Tree);
|
|
129
|
-
|
|
130
|
-
export { Tree$1 as default };
|
|
131
|
-
//# sourceMappingURL=Tree.js.map
|
package/dist/Tree.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Tree.js","sources":["../src/Tree.tsx"],"sourcesContent":["import { useDebounceFn, useMount, useUnmount } from 'ahooks';\nimport React, { memo } from 'react';\nimport { shallowEqual } from 'react-redux';\nimport { Box } from '@apia/theme';\nimport { getActiveDescendantName } from './getDomProps';\nimport SearchLabel from './SearchLabel';\nimport { TTreeContext, TreeContextProvider } from './TreeContext';\nimport { useTreeSelector } from './TreeDataController';\nimport TreeItemChildren from './TreeItemChildren';\nimport { TDataNode, TId, TTreeDataControllerState, TTreeProps } from './types';\nimport useTreeData from './useTreeData';\nimport { unfilterNodes, matchNodesAgainstString } from './util';\nimport { PropsStore, usePropsSelector } from '@apia/util';\nimport { getVariant } from '@apia/theme';\n\nconst Tree = <\n NodeProps extends Record<string, unknown> = Record<string, unknown>,\n NodeType extends TDataNode<NodeProps> = TDataNode<NodeProps>,\n>(\n props: TTreeProps<NodeProps, NodeType>,\n) => {\n const { data, handler, keyHandler } = useTreeData<NodeProps, NodeType>({\n name: props.name,\n treeProps: { ...props },\n });\n\n const [isLoading, setIsLoading] = React.useState(false);\n const [currentSearchString, setCurrentSearchString] = React.useState('');\n const isTreeLoading = useTreeSelector(handler, {\n selector: (current) => current.isLoading,\n });\n React.useEffect(() => {\n setIsLoading(isTreeLoading);\n }, [isTreeLoading]);\n\n const search = useDebounceFn(\n () => {\n if (props.filterString === undefined) return;\n setIsLoading(true);\n React.startTransition(() => {\n setCurrentSearchString(props.filterString as string);\n });\n if (props.filterString !== undefined && props.filterString !== '') {\n unfilterNodes(handler);\n matchNodesAgainstString(handler, props.filterString);\n handler.forceEmitUpdate();\n } else {\n unfilterNodes(handler);\n handler.forceEmitUpdate();\n }\n setTimeout(() => setIsLoading(false), 0);\n },\n { wait: 200 },\n );\n\n React.useEffect(() => {\n search.run();\n if (!props.filterString) search.flush();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props.filterString]);\n\n usePropsSelector<TTreeDataControllerState, TTreeDataControllerState>(\n handler.stateKey,\n {\n propsStore:\n handler.propsStore as unknown as PropsStore<TTreeDataControllerState>,\n selector: (current) => current,\n comparator: (prevProps, newProps) => {\n if (\n props.onSelect &&\n !shallowEqual(prevProps?.selectedNodes, newProps?.selectedNodes)\n ) {\n props.onSelect(\n (newProps?.selectedNodes ?? []).map((currentId) =>\n handler.propsStore.getFieldProps(currentId),\n ),\n );\n }\n return true;\n },\n },\n );\n\n const { focusedNode } = usePropsSelector<\n { focusedNode: TId | null },\n TTreeDataControllerState\n >(handler.stateKey, {\n propsStore:\n handler.propsStore as unknown as PropsStore<TTreeDataControllerState>,\n selector: (current) => ({\n focusedNode: current.focusedNode,\n }),\n });\n\n useMount(() => {\n if (props.getHandler) props.getHandler(handler);\n });\n\n useUnmount(() => handler.destructor());\n\n const contextValue = React.useMemo(() => {\n const actualValue: TTreeContext<NodeProps, NodeType> = {\n handler,\n name: props.name,\n forceUpdate: data.forceUpdate,\n focusGetter: props.focusGetter,\n treeProps: props,\n };\n return actualValue;\n }, [handler, props, data.forceUpdate]);\n\n return (\n <TreeContextProvider value={contextValue}>\n <Box\n className={`tree ${props.className ?? ''}`}\n {...getVariant(props.variant ?? 'layout.common.trees.primary')}\n >\n <SearchLabel\n isLoading={props.isLoading ?? isLoading}\n onDelete={props.onDeleteFilterString}\n searchString={props.hideSearchLabel ? '' : currentSearchString}\n />\n <TreeItemChildren\n aria-activedescendant={\n focusedNode !== null\n ? getActiveDescendantName(props.name, focusedNode)\n : undefined\n }\n aria-label={props.label}\n as=\"ul\"\n forceUpdate={data.forceUpdate}\n level={-1}\n nodes={React.useMemo(\n () =>\n data.children.map((current) =>\n handler.propsStore.getFieldProps(current),\n ),\n [data.children, handler.propsStore],\n )}\n role=\"tree\"\n tabIndex={0}\n {...keyHandler}\n />\n </Box>\n </TreeContextProvider>\n );\n};\n\nexport default memo(Tree) as typeof Tree;\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAeA,MAAM,IAAA,GAAO,CAIX,KACG,KAAA;AACH,EAAA,MAAM,EAAE,IAAA,EAAM,OAAS,EAAA,UAAA,KAAe,WAAiC,CAAA;AAAA,IACrE,MAAM,KAAM,CAAA,IAAA;AAAA,IACZ,SAAA,EAAW,EAAE,GAAG,KAAM,EAAA;AAAA,GACvB,CAAA,CAAA;AAED,EAAA,MAAM,CAAC,SAAW,EAAA,YAAY,CAAI,GAAA,KAAA,CAAM,SAAS,KAAK,CAAA,CAAA;AACtD,EAAA,MAAM,CAAC,mBAAqB,EAAA,sBAAsB,CAAI,GAAA,KAAA,CAAM,SAAS,EAAE,CAAA,CAAA;AACvE,EAAM,MAAA,aAAA,GAAgB,gBAAgB,OAAS,EAAA;AAAA,IAC7C,QAAA,EAAU,CAAC,OAAA,KAAY,OAAQ,CAAA,SAAA;AAAA,GAChC,CAAA,CAAA;AACD,EAAA,KAAA,CAAM,UAAU,MAAM;AACpB,IAAA,YAAA,CAAa,aAAa,CAAA,CAAA;AAAA,GAC5B,EAAG,CAAC,aAAa,CAAC,CAAA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1,13 +0,0 @@
|
|
|
1
|
-
import TreeDataController from './TreeDataController.js';
|
|
2
|
-
import { TDataNode, TTreeProps } from './types.js';
|
|
3
|
-
|
|
4
|
-
type TTreeContext<NodeProps extends Record<string, unknown> = Record<string, unknown>, NodeType extends TDataNode<NodeProps> = TDataNode<NodeProps>> = {
|
|
5
|
-
forceUpdate: number;
|
|
6
|
-
name: string;
|
|
7
|
-
handler: TreeDataController<NodeProps, NodeType>;
|
|
8
|
-
treeProps: TTreeProps<NodeProps, NodeType>;
|
|
9
|
-
} & Pick<TTreeProps, 'focusGetter'>;
|
|
10
|
-
declare function useTreeContext<NodeProps extends Record<string, unknown> = Record<string, unknown>, NodeType extends TDataNode<NodeProps> = TDataNode<NodeProps>>(): TTreeContext<NodeProps, NodeType>;
|
|
11
|
-
|
|
12
|
-
export { type TTreeContext, useTreeContext };
|
|
13
|
-
//# sourceMappingURL=TreeContext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeContext.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/TreeContext.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { jsx } from '@apia/theme/jsx-runtime';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
|
|
4
|
-
const TreeContext = React.createContext({});
|
|
5
|
-
function useTreeContext() {
|
|
6
|
-
const context = React.useContext(TreeContext);
|
|
7
|
-
if (!context)
|
|
8
|
-
throw new Error("There is no tree context");
|
|
9
|
-
return context;
|
|
10
|
-
}
|
|
11
|
-
const TreeContextProvider = ({
|
|
12
|
-
children,
|
|
13
|
-
value
|
|
14
|
-
}) => {
|
|
15
|
-
const Provider = React.useMemo(() => {
|
|
16
|
-
return TreeContext.Provider;
|
|
17
|
-
}, []);
|
|
18
|
-
return /* @__PURE__ */ jsx(Provider, { value, children });
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export { TreeContextProvider, TreeContext as default, useTreeContext };
|
|
22
|
-
//# sourceMappingURL=TreeContext.js.map
|
package/dist/TreeContext.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeContext.js","sources":["../src/TreeContext.tsx"],"sourcesContent":["import React from 'react';\nimport TreeDataController from './TreeDataController';\nimport { TDataNode, TTreeProps } from './types';\n\nexport type TTreeContext<\n NodeProps extends Record<string, unknown> = Record<string, unknown>,\n NodeType extends TDataNode<NodeProps> = TDataNode<NodeProps>,\n> = {\n forceUpdate: number;\n name: string;\n handler: TreeDataController<NodeProps, NodeType>;\n treeProps: TTreeProps<NodeProps, NodeType>;\n} & Pick<TTreeProps, 'focusGetter'>;\n\nconst TreeContext = React.createContext({} as TTreeContext);\n\nexport function useTreeContext<\n NodeProps extends Record<string, unknown> = Record<string, unknown>,\n NodeType extends TDataNode<NodeProps> = TDataNode<NodeProps>,\n>() {\n const context = React.useContext(TreeContext);\n if (!context) throw new Error('There is no tree context');\n return context as unknown as TTreeContext<NodeProps, NodeType>;\n}\n\nexport const TreeContextProvider = <\n NodeProps extends Record<string, unknown> = Record<string, unknown>,\n NodeType extends TDataNode<NodeProps> = TDataNode<NodeProps>,\n>({\n children,\n value,\n}: {\n children: React.ReactNode;\n value: TTreeContext<NodeProps, NodeType>;\n}) => {\n const Provider = React.useMemo(() => {\n return TreeContext.Provider as unknown as React.Provider<\n TTreeContext<NodeProps, NodeType>\n >;\n }, []);\n\n return <Provider value={value}>{children}</Provider>;\n};\n\nexport default TreeContext;\n"],"names":[],"mappings":";;;AAcA,MAAM,WAAc,GAAA,KAAA,CAAM,aAAc,CAAA,EAAkB,EAAA;AAEnD,SAAS,cAGZ,GAAA;AACF,EAAM,MAAA,OAAA,GAAU,KAAM,CAAA,UAAA,CAAW,WAAW,CAAA,CAAA;AAC5C,EAAA,IAAI,CAAC,OAAA;AAAS,IAAM,MAAA,IAAI,MAAM,0BAA0B,CAAA,CAAA;AACxD,EAAO,OAAA,OAAA,CAAA;AACT,CAAA;AAEO,MAAM,sBAAsB,CAGjC;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AACF,CAGM,KAAA;AACJ,EAAM,MAAA,QAAA,GAAW,KAAM,CAAA,OAAA,CAAQ,MAAM;AACnC,IAAA,OAAO,WAAY,CAAA,QAAA,CAAA;AAAA,GAGrB,EAAG,EAAE,CAAA,CAAA;AAEL,EAAO,uBAAA,GAAA,CAAC,QAAS,EAAA,EAAA,KAAA,EAAe,QAAS,EAAA,CAAA,CAAA;AAC3C;;;;"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import React__default, { RefObject } from 'react';
|
|
2
|
-
import { TDataNode, TId, TTreeDataControllerConfig, TTreeDataControllerState, TDataNodeContainer } from './types.js';
|
|
3
|
-
import { EventEmitter, PropsStore, TModify, TRequireOnlyOne, TUpdateFieldConfiguration, TPropsConfiguration } from '@apia/util';
|
|
4
|
-
|
|
5
|
-
declare function useTreeDataController<TreeType extends TreeDataController<any, any> = TreeDataController<any, any>>(name: string): TreeType;
|
|
6
|
-
declare class TreeDataController<NodeProps extends Record<string, unknown> = Record<string, unknown>, NodeType extends TDataNode<NodeProps> = TDataNode<NodeProps>> extends EventEmitter<{
|
|
7
|
-
onArrowUpOnFirstElement: boolean;
|
|
8
|
-
expandNode: NodeType;
|
|
9
|
-
mustFocus: TId;
|
|
10
|
-
stateUpdate: null;
|
|
11
|
-
}> {
|
|
12
|
-
name: string;
|
|
13
|
-
propsStore: PropsStore<NodeType>;
|
|
14
|
-
_configuration: RefObject<TTreeDataControllerConfig<NodeProps, NodeType>>;
|
|
15
|
-
get configuration(): {
|
|
16
|
-
current: TTreeDataControllerConfig<NodeProps, NodeType> | null;
|
|
17
|
-
};
|
|
18
|
-
hasApendedFirstChild: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Este array se usa para conocer los padres faltantes al momento de la
|
|
21
|
-
* construcción del árbol, de forma de optimizar el proceso
|
|
22
|
-
*/
|
|
23
|
-
missingParents: TId[];
|
|
24
|
-
nonEmittedUpdates: TId[];
|
|
25
|
-
get state(): TTreeDataControllerState;
|
|
26
|
-
stateKey: string;
|
|
27
|
-
get stateStore(): PropsStore<TTreeDataControllerState>;
|
|
28
|
-
constructor(name: string, configuration: RefObject<Partial<TTreeDataControllerConfig<NodeProps, NodeType>>>, propsStore?: PropsStore<NodeType>);
|
|
29
|
-
destructor(): void;
|
|
30
|
-
append(node: Omit<TModify<NodeType, {
|
|
31
|
-
children?: NodeType['children'];
|
|
32
|
-
parentId?: NodeType['parentId'];
|
|
33
|
-
}>, 'nodeProps' | 'actualParentId'> & Partial<Pick<NodeType, 'nodeProps'>>): void;
|
|
34
|
-
/**
|
|
35
|
-
* Cuando se quieren agregar muchos nodos, es conveniente llamar primero al
|
|
36
|
-
* método batchInit y luego de finalizar, al método batchFinish()
|
|
37
|
-
*/
|
|
38
|
-
batchInit(): void;
|
|
39
|
-
private getNodesRecursive;
|
|
40
|
-
/**
|
|
41
|
-
* Cuando se quieren agregar muchos nodos, es conveniente llamar primero al
|
|
42
|
-
* método batchInit y luego de finalizar, al método batchFinish()
|
|
43
|
-
*/
|
|
44
|
-
batchFinish(): void;
|
|
45
|
-
config(newConf: Partial<TTreeDataControllerConfig<NodeProps, NodeType>>): void;
|
|
46
|
-
deselectAll(): void;
|
|
47
|
-
forceEmitUpdate(): void;
|
|
48
|
-
getInitialState(): TTreeDataControllerState;
|
|
49
|
-
getNodesAsArray(): NodeType[];
|
|
50
|
-
/**
|
|
51
|
-
* Devuelve un array que contiene el id de todos los nodos pertenecientes al
|
|
52
|
-
* árbol
|
|
53
|
-
*/
|
|
54
|
-
getNodesIds(): string[];
|
|
55
|
-
getParentId(parentId: TId): TId;
|
|
56
|
-
/**
|
|
57
|
-
* Este método permite controlar el comportamiento con el teclado desde fuera
|
|
58
|
-
* del componente.
|
|
59
|
-
*/
|
|
60
|
-
handleKey(ev: React__default.KeyboardEvent): void;
|
|
61
|
-
isNode(node: NodeType | TDataNodeContainer<NodeProps> | TId): node is NodeType;
|
|
62
|
-
isNodeContainer(node: NodeType | TDataNodeContainer<NodeProps> | TId): node is TDataNodeContainer<NodeProps>;
|
|
63
|
-
includes(searchNode: NodeType): boolean;
|
|
64
|
-
initRoot(): void;
|
|
65
|
-
move(moveNode: TId, destinationNode: TId, afterOrBefore?: TRequireOnlyOne<{
|
|
66
|
-
after: NodeType | TId;
|
|
67
|
-
before: NodeType | TId;
|
|
68
|
-
position: number;
|
|
69
|
-
}>): void;
|
|
70
|
-
/**
|
|
71
|
-
* Borra el nodo del árbol, y dependiendo del parámetro removeChildren, borra
|
|
72
|
-
* también sus hijos.
|
|
73
|
-
*
|
|
74
|
-
* @param removeChildren - Si se pasa en false, los nodos hijos son movidos al root
|
|
75
|
-
*/
|
|
76
|
-
remove(removeNode: NodeType | TId, removeChildren?: boolean): void;
|
|
77
|
-
removeMultiple(nodes: TId[], removeChildren?: boolean): void;
|
|
78
|
-
previousNodes: TId[];
|
|
79
|
-
/**
|
|
80
|
-
* Borra todos los nodos del árbol.
|
|
81
|
-
*/
|
|
82
|
-
removeAll(): void;
|
|
83
|
-
selectAll(): void;
|
|
84
|
-
setExpandedNodes(nodes: TId[]): void;
|
|
85
|
-
setFocusedNode(key: TId, avoidSelection?: boolean): void;
|
|
86
|
-
setSelectedNodes(nodes: TId[], force?: boolean): void;
|
|
87
|
-
setSelectedNodesByClickEvent(ev: React__default.MouseEvent): void;
|
|
88
|
-
setState: (updateProps: Partial<TTreeDataControllerState>, conf?: TUpdateFieldConfiguration) => void;
|
|
89
|
-
useState: <T>(selector: (state: TTreeDataControllerState) => T) => T;
|
|
90
|
-
toggleNodeExpandedState(key: TId, shouldExpand?: boolean): void;
|
|
91
|
-
toggleNodeSelectedState(key: TId, isSelected?: boolean): void;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Este hook permite escuchar las props de un árbol, para ello es necesario
|
|
95
|
-
* pasar el handler.
|
|
96
|
-
*
|
|
97
|
-
* @param handler
|
|
98
|
-
* @param configuration
|
|
99
|
-
* @returns
|
|
100
|
-
*/
|
|
101
|
-
declare function useTreeSelector<NodeProps extends Record<string, unknown> = Record<string, unknown>, NodeType extends TDataNode<NodeProps> = TDataNode<NodeProps>, Selected = Record<string, unknown>, PropsType extends Record<string, unknown> = TTreeDataControllerState>(handler: TreeDataController<NodeProps, NodeType>, configuration?: TPropsConfiguration<Selected, PropsType>): Selected;
|
|
102
|
-
/**
|
|
103
|
-
* Este hook permite escuchar las props de un árbol, para ello es necesario
|
|
104
|
-
* pasar el handler.
|
|
105
|
-
*
|
|
106
|
-
* @param handler
|
|
107
|
-
* @param configuration
|
|
108
|
-
* @returns
|
|
109
|
-
*/
|
|
110
|
-
declare function useTreeSelectorByName<NodeProps extends Record<string, unknown> = Record<string, unknown>, NodeType extends TDataNode<NodeProps> = TDataNode<NodeProps>, Selected = Record<string, unknown>, PropsType extends Record<string, unknown> = TTreeDataControllerState>(treeName: string, configuration?: TPropsConfiguration<Selected, PropsType>): {
|
|
111
|
-
handler: TreeDataController<NodeProps, NodeType>;
|
|
112
|
-
selection: Selected;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export { TreeDataController as default, useTreeDataController, useTreeSelector, useTreeSelectorByName };
|
|
116
|
-
//# sourceMappingURL=TreeDataController.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeDataController.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|