@itwin/presentation-hierarchies-react 2.0.0-alpha.52 → 2.0.0-alpha.54
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/CHANGELOG.md +33 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts +62 -55
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts +33 -29
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts +27 -16
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js +181 -54
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts +12 -6
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js +54 -49
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts +7 -30
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js +116 -74
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +67 -54
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +283 -226
- package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/Utils.js +44 -27
- package/lib/esm/presentation-hierarchies-react/Utils.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.js +6 -7
- package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js +271 -298
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js +91 -82
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts +3 -47
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js +114 -151
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +32 -37
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js +128 -101
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.js +29 -44
- package/lib/esm/presentation-hierarchies-react/internal/Utils.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +24 -13
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +344 -67
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts +16 -15
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js +78 -60
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +122 -117
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js +59 -38
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts +16 -5
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +161 -35
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.d.ts +21 -17
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.js +84 -31
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +22 -14
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +61 -26
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts +15 -6
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js +75 -25
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts +16 -40
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js +140 -61
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +14 -42
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +489 -121
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +58 -55
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +412 -181
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react.d.ts +17 -17
- package/lib/esm/presentation-hierarchies-react.js +15 -18
- package/package.json +17 -14
- package/lib/esm/presentation-hierarchies-react/Renderers.js +0 -6
- package/lib/esm/presentation-hierarchies-react/Renderers.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/TreeNode.js +0 -6
- package/lib/esm/presentation-hierarchies-react/TreeNode.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts +0 -8
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.d.ts +0 -2
- package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts +0 -53
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts +0 -62
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.d.ts +0 -23
- package/lib/esm/presentation-hierarchies-react/internal/Utils.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelTree.js","
|
|
1
|
+
{"version":3,"file":"UseIModelTree.js","names":["useCallback","createIModelHierarchyProvider","useTree","useUnifiedSelectionTree","HierarchyDefinition","HierarchySearchPath","Props","UseUnifiedTreeSelectionProps","UseTreeProps","UseTreeResult","IModelHierarchyProviderProps","IModelAccess","UseIModelTreeProps","Omit","Pick","getHierarchyDefinition","props","imodelAccess","getSearchPaths","abortSignal","AbortSignal","Promise","useIModelTree","$","_c","imodelChanged","localizedStrings","rest","t0","t1","useIModelTreeProps","t2","useIModelUnifiedSelectionTree","hierarchyDefinition","t3","t4","getHierarchyProvider"],"sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback } from \"react\";\nimport { createIModelHierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport { useTree, useUnifiedSelectionTree } from \"./UseTree.js\";\n\nimport type { HierarchyDefinition, HierarchySearchPath } from \"@itwin/presentation-hierarchies\";\nimport type { Props } from \"@itwin/presentation-shared\";\nimport type { UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport type { UseTreeProps, UseTreeResult } from \"./UseTree.js\";\n\n/** @public */\ntype IModelHierarchyProviderProps = Props<typeof createIModelHierarchyProvider>;\n\n/** @public */\ntype IModelAccess = IModelHierarchyProviderProps[\"imodelAccess\"];\n\n/**\n * Props for `useIModelTree` and `useIModelUnifiedSelectionTree` hooks.\n * @public\n */\ntype UseIModelTreeProps = Omit<UseTreeProps, \"getHierarchyProvider\" | \"getSearchPaths\"> &\n Pick<IModelHierarchyProviderProps, \"localizedStrings\" | \"imodelAccess\" | \"imodelChanged\"> & {\n /**\n * Provides the hierarchy definition for the tree.\n */\n getHierarchyDefinition: (props: { imodelAccess: IModelAccess }) => HierarchyDefinition;\n\n /**\n * Provides paths to target nodes.\n */\n getSearchPaths?: (props: {\n /**\n * Object that provides access to the iModel schema and can run queries against the iModel.\n */\n imodelAccess: IModelAccess;\n /**\n * Signal indicating that that the request was canceled\n */\n abortSignal: AbortSignal;\n }) => Promise<HierarchySearchPath[] | undefined>;\n };\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @public\n */\nexport function useIModelTree(props: UseIModelTreeProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, localizedStrings, ...rest } = props;\n return useTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, localizedStrings }),\n });\n}\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data and that is integrated with unified selection through the given selection\n * storage (previously the storage was provided through the, now deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useIModelTree`\n * @see `useUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useIModelUnifiedSelectionTree(props: UseIModelTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, localizedStrings, ...rest } = props;\n return useUnifiedSelectionTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, localizedStrings }),\n });\n}\n\nfunction useIModelTreeProps(\n props: Pick<UseIModelTreeProps, \"imodelAccess\" | \"imodelChanged\" | \"getHierarchyDefinition\" | \"getSearchPaths\" | \"localizedStrings\">,\n): Pick<UseTreeProps, \"getHierarchyProvider\" | \"getSearchPaths\"> {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, localizedStrings } = props;\n return {\n getHierarchyProvider: useCallback(\n () =>\n createIModelHierarchyProvider({\n imodelAccess,\n imodelChanged,\n hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),\n localizedStrings,\n }),\n [imodelAccess, imodelChanged, getHierarchyDefinition, localizedStrings],\n ),\n getSearchPaths: useCallback(\n async ({ abortSignal }: { abortSignal: AbortSignal }) => getSearchPaths?.({ imodelAccess, abortSignal }),\n [imodelAccess, getSearchPaths],\n ),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2DA,SAAOsB,cAAAN,OAAA;CAAA,MAAAO,IAAAC,EAAA,GAAA;CAAA,IAAAT;CAAA,IAAAG;CAAA,IAAAD;CAAA,IAAAQ;CAAA,IAAAC;CAAA,IAAAC;AAAA,KAAAJ,EAAA,OAAAP,OAAA;AACL,GAAA,CAAAC,cAAAQ,eAAAV,wBAAAG,gBAAAQ,qBAAAC,QAA2GX;AAAMO,IAAA,KAAAP;AAAAO,IAAA,KAAAR;AAAAQ,IAAA,KAAAL;AAAAK,IAAA,KAAAN;AAAAM,IAAA,KAAAE;AAAAF,IAAA,KAAAG;AAAAH,IAAA,KAAAI;QAAA;AAAAZ,2BAAAQ,EAAA;AAAAL,mBAAAK,EAAA;AAAAN,iBAAAM,EAAA;AAAAE,kBAAAF,EAAA;AAAAG,qBAAAH,EAAA;AAAAI,SAAAJ,EAAA;;CAAA,IAAAK;AAAA,KAAAL,EAAA,OAAAR,0BAAAQ,EAAA,OAAAL,kBAAAK,EAAA,OAAAN,gBAAAM,EAAA,QAAAE,iBAAAF,EAAA,QAAAG,kBAAA;AAGzFE,OAAA;GAAAX;GAAAQ;GAAAV;GAAAG;GAAAQ;GAAyF;AAAAH,IAAA,KAAAR;AAAAQ,IAAA,KAAAL;AAAAK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MAAAY;OAAAA,MAAAZ,EAAA;AAAA,QAfMY"}
|
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
import { TreeNode } from "./TreeNode.js";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/presentation-hierarchies-react/UseNodeHighlighting.d.ts
|
|
2
5
|
/**
|
|
3
6
|
* Props for `useNodeHighlighting` hook.
|
|
4
7
|
* @alpha
|
|
5
8
|
*/
|
|
6
9
|
interface UseNodeHighlightingProps {
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
/** Text that should be highlighted */
|
|
11
|
+
highlightText?: string;
|
|
9
12
|
}
|
|
10
13
|
/**
|
|
11
14
|
* Result of `useNodeHighlighting` hook.
|
|
12
15
|
* @alpha
|
|
13
16
|
*/
|
|
14
17
|
interface UseNodeHighlightingResult {
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
/** Function that creates highlighted node labels. */
|
|
19
|
+
getLabel: (node: TreeNode) => ReactElement;
|
|
17
20
|
}
|
|
18
21
|
/**
|
|
19
22
|
* A react hook that helps create highlighted node labels based on provided highlight.
|
|
20
23
|
* @alpha
|
|
21
24
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
declare function useNodeHighlighting({
|
|
26
|
+
highlightText
|
|
27
|
+
}: UseNodeHighlightingProps): UseNodeHighlightingResult;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { useNodeHighlighting };
|
|
24
30
|
//# sourceMappingURL=UseNodeHighlighting.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseNodeHighlighting.d.ts","
|
|
1
|
+
{"version":3,"file":"UseNodeHighlighting.d.ts","names":[],"sources":["../../../src/presentation-hierarchies-react/UseNodeHighlighting.tsx"],"mappings":";;;;;;AAS8C;;UAMpC,wBAAA;EAER;EAAA,aAAA;AAAA;;;;;UAOQ,yBAAA;EAEG;EAAX,QAAA,GAAW,IAAA,EAAM,QAAA,KAAa,YAAA;AAAA;;AAOhC;;;iBAAgB,mBAAA,CAAA;EAAsB;AAAA,GAAiB,wBAAA,GAA2B,yBAAA"}
|
|
@@ -1,53 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
import { useCallback } from "react";
|
|
1
|
+
import { c } from "react-compiler-runtime";
|
|
7
2
|
import { HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
3
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/presentation-hierarchies-react/UseNodeHighlighting.tsx
|
|
8
6
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
7
|
+
* A react hook that helps create highlighted node labels based on provided highlight.
|
|
8
|
+
* @alpha
|
|
9
|
+
*/
|
|
10
|
+
function useNodeHighlighting(t0) {
|
|
11
|
+
const $ = c(4);
|
|
12
|
+
const { highlightText } = t0;
|
|
13
|
+
let t1;
|
|
14
|
+
if ($[0] !== highlightText) {
|
|
15
|
+
t1 = (node) => {
|
|
16
|
+
if (!highlightText || HierarchyNode.isGroupingNode(node.nodeData) || !node.nodeData.search?.isSearchTarget) return /* @__PURE__ */ jsx("span", { children: node.label });
|
|
17
|
+
const matchedIndexes = new Array();
|
|
18
|
+
const nodeLabel = node.label.toLocaleLowerCase();
|
|
19
|
+
const searchText = highlightText.toLocaleLowerCase();
|
|
20
|
+
let fromPosition = 0;
|
|
21
|
+
while (true) {
|
|
22
|
+
const foundIndex = nodeLabel.indexOf(searchText, fromPosition);
|
|
23
|
+
if (foundIndex === -1) break;
|
|
24
|
+
matchedIndexes.push(foundIndex);
|
|
25
|
+
fromPosition = foundIndex + searchText.length;
|
|
26
|
+
}
|
|
27
|
+
if (matchedIndexes.length === 0) return /* @__PURE__ */ jsx("span", { children: node.label });
|
|
28
|
+
const finalLabel = new Array();
|
|
29
|
+
let lastAddedPosition = 0;
|
|
30
|
+
for (let i = 0; i < matchedIndexes.length; ++i) {
|
|
31
|
+
const matchedIndex = matchedIndexes[i];
|
|
32
|
+
if (matchedIndex > lastAddedPosition) {
|
|
33
|
+
finalLabel.push(/* @__PURE__ */ jsx("span", { children: node.label.substring(lastAddedPosition, matchedIndex) }, `normal-${i}`));
|
|
34
|
+
lastAddedPosition = matchedIndex;
|
|
35
|
+
}
|
|
36
|
+
const endingPlace = matchedIndex + highlightText.length;
|
|
37
|
+
finalLabel.push(/* @__PURE__ */ jsx("mark", { children: node.label.substring(lastAddedPosition, endingPlace) }, `marked-${i}`));
|
|
38
|
+
lastAddedPosition = endingPlace;
|
|
39
|
+
}
|
|
40
|
+
if (lastAddedPosition < node.label.length) finalLabel.push(/* @__PURE__ */ jsx("span", { children: node.label.substring(lastAddedPosition) }, `normal-${matchedIndexes.length + 1}`));
|
|
41
|
+
return /* @__PURE__ */ jsx(Fragment, { children: finalLabel });
|
|
42
|
+
};
|
|
43
|
+
$[0] = highlightText;
|
|
44
|
+
$[1] = t1;
|
|
45
|
+
} else t1 = $[1];
|
|
46
|
+
const getLabel = t1;
|
|
47
|
+
let t2;
|
|
48
|
+
if ($[2] !== getLabel) {
|
|
49
|
+
t2 = { getLabel };
|
|
50
|
+
$[2] = getLabel;
|
|
51
|
+
$[3] = t2;
|
|
52
|
+
} else t2 = $[3];
|
|
53
|
+
return t2;
|
|
52
54
|
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { useNodeHighlighting };
|
|
53
58
|
//# sourceMappingURL=UseNodeHighlighting.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseNodeHighlighting.js","
|
|
1
|
+
{"version":3,"file":"UseNodeHighlighting.js","names":["useCallback","HierarchyNode","JSX","ReactElement","TreeNode","UseNodeHighlightingProps","highlightText","UseNodeHighlightingResult","getLabel","node","useNodeHighlighting","t0","$","_c","t1","isGroupingNode","nodeData","search","isSearchTarget","label","matchedIndexes","Array","nodeLabel","toLocaleLowerCase","searchText","fromPosition","foundIndex","indexOf","push","length","finalLabel","lastAddedPosition","i","matchedIndex","substring","endingPlace","t2"],"sources":["../../../src/presentation-hierarchies-react/UseNodeHighlighting.tsx"],"sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback } from \"react\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\n\nimport type { JSX, ReactElement } from \"react\";\nimport type { TreeNode } from \"./TreeNode.js\";\n\n/**\n * Props for `useNodeHighlighting` hook.\n * @alpha\n */\ninterface UseNodeHighlightingProps {\n /** Text that should be highlighted */\n highlightText?: string;\n}\n\n/**\n * Result of `useNodeHighlighting` hook.\n * @alpha\n */\ninterface UseNodeHighlightingResult {\n /** Function that creates highlighted node labels. */\n getLabel: (node: TreeNode) => ReactElement;\n}\n\n/**\n * A react hook that helps create highlighted node labels based on provided highlight.\n * @alpha\n */\nexport function useNodeHighlighting({ highlightText }: UseNodeHighlightingProps): UseNodeHighlightingResult {\n const getLabel = useCallback(\n (node: TreeNode) => {\n if (!highlightText || HierarchyNode.isGroupingNode(node.nodeData) || !node.nodeData.search?.isSearchTarget) {\n return <span>{node.label}</span>;\n }\n\n const matchedIndexes = new Array<number>();\n const nodeLabel = node.label.toLocaleLowerCase();\n const searchText = highlightText.toLocaleLowerCase();\n let fromPosition = 0;\n // Find all occurrences of the search text in the node label\n while (true) {\n const foundIndex = nodeLabel.indexOf(searchText, fromPosition);\n if (foundIndex === -1) {\n break;\n }\n matchedIndexes.push(foundIndex);\n fromPosition = foundIndex + searchText.length;\n }\n\n if (matchedIndexes.length === 0) {\n return <span>{node.label}</span>;\n }\n\n // Create the final label with highlighted parts\n const finalLabel = new Array<JSX.Element>();\n let lastAddedPosition = 0;\n for (let i = 0; i < matchedIndexes.length; ++i) {\n const matchedIndex = matchedIndexes[i];\n if (matchedIndex > lastAddedPosition) {\n finalLabel.push(<span key={`normal-${i}`}>{node.label.substring(lastAddedPosition, matchedIndex)}</span>);\n lastAddedPosition = matchedIndex;\n }\n const endingPlace = matchedIndex + highlightText.length;\n finalLabel.push(<mark key={`marked-${i}`}>{node.label.substring(lastAddedPosition, endingPlace)}</mark>);\n lastAddedPosition = endingPlace;\n }\n if (lastAddedPosition < node.label.length) {\n finalLabel.push(<span key={`normal-${matchedIndexes.length + 1}`}>{node.label.substring(lastAddedPosition)}</span>);\n }\n\n return <>{finalLabel}</>;\n },\n [highlightText],\n );\n\n return { getLabel };\n}\n"],"mappings":";;;;;;;;;AAiCA,SAAOU,oBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAA6B,MAAA,EAAAP,kBAAAK;CAA2C,IAAAG;AAAA,KAAAF,EAAA,OAAAN,eAAA;AAE3EQ,QAAAL,SAAA;AACE,OAAI,CAACH,iBAAiBL,cAAac,eAAgBN,KAAIO,SAAmD,IAAtG,CAAkEP,KAAIO,SAASC,QAAuBC,eAAA,QACjG,oBAAA,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AA,KAAAwB;OAAAA,MAAAxB,EAAA;AAAA,QAAZwB"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./Renderers.js";
|
|
2
|
+
|
|
3
|
+
//#region src/presentation-hierarchies-react/UseSelectionHandler.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* A union of different supported selection modes in a tree component:
|
|
4
6
|
* - `none` - no selection is allowed,
|
|
@@ -8,7 +10,7 @@ import { TreeRendererProps } from "./Renderers.js";
|
|
|
8
10
|
*
|
|
9
11
|
* @public
|
|
10
12
|
*/
|
|
11
|
-
|
|
13
|
+
type SelectionMode = "none" | "single" | "extended" | "multiple";
|
|
12
14
|
/**
|
|
13
15
|
* Type of selection change.
|
|
14
16
|
* - `add` - a node was added to the selection,
|
|
@@ -17,32 +19,7 @@ export type SelectionMode = "none" | "single" | "extended" | "multiple";
|
|
|
17
19
|
*
|
|
18
20
|
* @public
|
|
19
21
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* @alpha
|
|
24
|
-
*/
|
|
25
|
-
type UseSelectionHandlerProps = Pick<TreeRendererProps, "selectNodes" | "rootNodes"> & {
|
|
26
|
-
/** Selection mode that the component is working in. */
|
|
27
|
-
selectionMode: SelectionMode;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Result of `useSelectionHandler` hook.
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
interface UseSelectionHandlerResult {
|
|
34
|
-
/** Updates nodes selection based on current node state and modifier keys used. */
|
|
35
|
-
handleNodeSelect: (props: {
|
|
36
|
-
nodeId: string;
|
|
37
|
-
isSelected: boolean;
|
|
38
|
-
shiftDown: boolean;
|
|
39
|
-
ctrlDown: boolean;
|
|
40
|
-
}) => void;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* A react hook that helps implement different selection modes in a tree component created using `useTree` hook.
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
export declare function useSelectionHandler(props: UseSelectionHandlerProps): UseSelectionHandlerResult;
|
|
47
|
-
export {};
|
|
22
|
+
type SelectionChangeType = "add" | "replace" | "remove";
|
|
23
|
+
//#endregion
|
|
24
|
+
export { SelectionChangeType, SelectionMode };
|
|
48
25
|
//# sourceMappingURL=UseSelectionHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseSelectionHandler.d.ts","
|
|
1
|
+
{"version":3,"file":"UseSelectionHandler.d.ts","names":[],"sources":["../../../src/presentation-hierarchies-react/UseSelectionHandler.ts"],"mappings":";;;;;AAmBA;;;;;AAUA;;KAVY,aAAA;;;;;;;;;KAUA,mBAAA"}
|
|
@@ -1,83 +1,125 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { useCallback, useEffect, useRef } from "react";
|
|
1
|
+
import { c } from "react-compiler-runtime";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/presentation-hierarchies-react/UseSelectionHandler.ts
|
|
6
5
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
6
|
+
* A react hook that helps implement different selection modes in a tree component created using `useTree` hook.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
function useSelectionHandler(props) {
|
|
10
|
+
const $ = c(10);
|
|
11
|
+
const { rootNodes, selectionMode, selectNodes } = props;
|
|
12
|
+
const previousSelectionRef = useRef(void 0);
|
|
13
|
+
let t0;
|
|
14
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
15
|
+
t0 = {
|
|
16
|
+
flatNodeList: [],
|
|
17
|
+
nodeIdToIndexMap: /* @__PURE__ */ new Map()
|
|
18
|
+
};
|
|
19
|
+
$[0] = t0;
|
|
20
|
+
} else t0 = $[0];
|
|
21
|
+
const state = useRef(t0);
|
|
22
|
+
let t1;
|
|
23
|
+
let t2;
|
|
24
|
+
if ($[1] !== rootNodes) {
|
|
25
|
+
t1 = () => {
|
|
26
|
+
state.current = computeFlatNodeList(rootNodes);
|
|
27
|
+
};
|
|
28
|
+
t2 = [rootNodes];
|
|
29
|
+
$[1] = rootNodes;
|
|
30
|
+
$[2] = t1;
|
|
31
|
+
$[3] = t2;
|
|
32
|
+
} else {
|
|
33
|
+
t1 = $[2];
|
|
34
|
+
t2 = $[3];
|
|
35
|
+
}
|
|
36
|
+
useEffect(t1, t2);
|
|
37
|
+
let t3;
|
|
38
|
+
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
|
39
|
+
t3 = (firstId, secondId) => {
|
|
40
|
+
const getIndex = (nodeId) => nodeId ? state.current.nodeIdToIndexMap.get(nodeId) : 0;
|
|
41
|
+
const firstIndex = getIndex(firstId);
|
|
42
|
+
const secondIndex = getIndex(secondId);
|
|
43
|
+
if (firstIndex === void 0 || secondIndex === void 0) return [];
|
|
44
|
+
const startingIndex = Math.min(firstIndex, secondIndex);
|
|
45
|
+
const endIndex = Math.max(firstIndex, secondIndex);
|
|
46
|
+
return state.current.flatNodeList.slice(startingIndex, endIndex + 1);
|
|
47
|
+
};
|
|
48
|
+
$[4] = t3;
|
|
49
|
+
} else t3 = $[4];
|
|
50
|
+
const getNodeRange = t3;
|
|
51
|
+
let t4;
|
|
52
|
+
if ($[5] !== selectNodes || $[6] !== selectionMode) {
|
|
53
|
+
t4 = (t5) => {
|
|
54
|
+
const { nodeId: nodeId_0, isSelected, shiftDown, ctrlDown } = t5;
|
|
55
|
+
const selection = getSelectionAction(selectionMode, isSelected, shiftDown, ctrlDown);
|
|
56
|
+
if (selection.type === "disabled") return;
|
|
57
|
+
const nodes = selection.select === "range" ? getNodeRange(previousSelectionRef.current, nodeId_0) : [nodeId_0];
|
|
58
|
+
if (!nodes.length) return;
|
|
59
|
+
selection.select !== "range" && (previousSelectionRef.current = nodeId_0);
|
|
60
|
+
selectNodes(nodes, selection.type);
|
|
61
|
+
};
|
|
62
|
+
$[5] = selectNodes;
|
|
63
|
+
$[6] = selectionMode;
|
|
64
|
+
$[7] = t4;
|
|
65
|
+
} else t4 = $[7];
|
|
66
|
+
const handleNodeSelect = t4;
|
|
67
|
+
let t5;
|
|
68
|
+
if ($[8] !== handleNodeSelect) {
|
|
69
|
+
t5 = { handleNodeSelect };
|
|
70
|
+
$[8] = handleNodeSelect;
|
|
71
|
+
$[9] = t5;
|
|
72
|
+
} else t5 = $[9];
|
|
73
|
+
return t5;
|
|
46
74
|
}
|
|
47
75
|
function getSelectionAction(selectionMode, isSelected, shiftDown, ctrlDown) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
76
|
+
switch (selectionMode) {
|
|
77
|
+
case "none": return {
|
|
78
|
+
select: "node",
|
|
79
|
+
type: "disabled"
|
|
80
|
+
};
|
|
81
|
+
case "single": return {
|
|
82
|
+
select: "node",
|
|
83
|
+
type: isSelected ? "remove" : "replace"
|
|
84
|
+
};
|
|
85
|
+
case "multiple": return {
|
|
86
|
+
select: "node",
|
|
87
|
+
type: isSelected ? "remove" : "add"
|
|
88
|
+
};
|
|
89
|
+
case "extended": return getExtendedSelectionAction(isSelected, shiftDown, ctrlDown);
|
|
90
|
+
}
|
|
58
91
|
}
|
|
59
92
|
function getExtendedSelectionAction(isSelected, shiftDown, ctrlDown) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
93
|
+
if (shiftDown) return {
|
|
94
|
+
select: "range",
|
|
95
|
+
type: "replace"
|
|
96
|
+
};
|
|
97
|
+
if (ctrlDown) return {
|
|
98
|
+
select: "node",
|
|
99
|
+
type: isSelected ? "remove" : "add"
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
select: "node",
|
|
103
|
+
type: "replace"
|
|
104
|
+
};
|
|
67
105
|
}
|
|
68
106
|
function computeFlatNodeList(rootNodes) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
107
|
+
const flatNodeList = [];
|
|
108
|
+
const nodeIdToIndexMap = /* @__PURE__ */ new Map();
|
|
109
|
+
const flattenNodeRecursively = (nodes) => {
|
|
110
|
+
nodes.forEach((node) => {
|
|
111
|
+
nodeIdToIndexMap.set(node.id, flatNodeList.length);
|
|
112
|
+
flatNodeList.push(node.id);
|
|
113
|
+
if (node.isExpanded && typeof node.children !== "boolean") flattenNodeRecursively(node.children);
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
flattenNodeRecursively(rootNodes);
|
|
117
|
+
return {
|
|
118
|
+
flatNodeList,
|
|
119
|
+
nodeIdToIndexMap
|
|
120
|
+
};
|
|
82
121
|
}
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
export { useSelectionHandler };
|
|
83
125
|
//# sourceMappingURL=UseSelectionHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseSelectionHandler.js","
|
|
1
|
+
{"version":3,"file":"UseSelectionHandler.js","names":["useCallback","useEffect","useRef","TreeRendererProps","TreeNode","SelectionMode","SelectionChangeType","UseSelectionHandlerProps","Pick","selectionMode","UseSelectionHandlerResult","handleNodeSelect","props","nodeId","isSelected","shiftDown","ctrlDown","FlatTreeState","flatNodeList","Array","nodeIdToIndexMap","Map","useSelectionHandler","$","_c","rootNodes","selectNodes","previousSelectionRef","undefined","t0","Symbol","for","state","t1","t2","current","computeFlatNodeList","t3","firstId","secondId","getIndex","get","firstIndex","secondIndex","startingIndex","Math","min","endIndex","max","slice","getNodeRange","t4","t5","nodeId_0","selection","getSelectionAction","type","nodes","select","length","SelectionAction","getExtendedSelectionAction","flattenNodeRecursively","forEach","node","set","id","push","isExpanded","children"],"sources":["../../../src/presentation-hierarchies-react/UseSelectionHandler.ts"],"sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback, useEffect, useRef } from \"react\";\n\nimport type { TreeRendererProps } from \"./Renderers.js\";\nimport type { TreeNode } from \"./TreeNode.js\";\n\n/**\n * A union of different supported selection modes in a tree component:\n * - `none` - no selection is allowed,\n * - `single` - only one node can be selected at a time,\n * - `extended` - multiple nodes can be selected using shift and ctrl keys,\n * - `multiple` - multiple nodes can be selected without using shift or ctrl keys.\n *\n * @public\n */\nexport type SelectionMode = \"none\" | \"single\" | \"extended\" | \"multiple\";\n\n/**\n * Type of selection change.\n * - `add` - a node was added to the selection,\n * - `replace` - a selected node was replaced with a different one,\n * - `remove` - a node was removed from the selection.\n *\n * @public\n */\nexport type SelectionChangeType = \"add\" | \"replace\" | \"remove\";\n\n/**\n * Props for `useSelectionHandler` hook.\n * @alpha\n */\ntype UseSelectionHandlerProps = Pick<TreeRendererProps, \"selectNodes\" | \"rootNodes\"> & {\n /**\n * Selection mode that the component is working in.\n */\n selectionMode: SelectionMode;\n};\n\n/**\n * Result of `useSelectionHandler` hook.\n * @internal\n */\ninterface UseSelectionHandlerResult {\n /** Updates nodes selection based on current node state and modifier keys used. */\n handleNodeSelect: (props: { nodeId: string; isSelected: boolean; shiftDown: boolean; ctrlDown: boolean }) => void;\n}\n\ninterface FlatTreeState {\n flatNodeList: Array<string>;\n nodeIdToIndexMap: Map<string, number>;\n}\n\n/**\n * A react hook that helps implement different selection modes in a tree component created using `useTree` hook.\n * @internal\n */\nexport function useSelectionHandler(props: UseSelectionHandlerProps): UseSelectionHandlerResult {\n const { rootNodes, selectionMode, selectNodes } = props;\n const previousSelectionRef = useRef<string | undefined>(undefined);\n const state = useRef<FlatTreeState>({\n flatNodeList: [],\n nodeIdToIndexMap: new Map(),\n });\n\n useEffect(() => {\n state.current = computeFlatNodeList(rootNodes);\n }, [rootNodes]);\n\n const getNodeRange = (firstId?: string, secondId?: string) => {\n const getIndex = (nodeId?: string) => {\n return nodeId ? state.current.nodeIdToIndexMap.get(nodeId) : 0;\n };\n const firstIndex = getIndex(firstId);\n const secondIndex = getIndex(secondId);\n if (firstIndex === undefined || secondIndex === undefined) {\n return [];\n }\n\n const startingIndex = Math.min(firstIndex, secondIndex);\n const endIndex = Math.max(firstIndex, secondIndex);\n return state.current.flatNodeList.slice(startingIndex, endIndex + 1);\n };\n\n const handleNodeSelect = useCallback<UseSelectionHandlerResult[\"handleNodeSelect\"]>(\n ({ nodeId, isSelected, shiftDown, ctrlDown }) => {\n const selection = getSelectionAction(selectionMode, isSelected, shiftDown, ctrlDown);\n if (selection.type === \"disabled\") {\n return;\n }\n\n const nodes = selection.select === \"range\" ? getNodeRange(previousSelectionRef.current, nodeId) : [nodeId];\n if (!nodes.length) {\n return;\n }\n\n selection.select !== \"range\" && (previousSelectionRef.current = nodeId);\n selectNodes(nodes, selection.type);\n },\n [selectionMode, selectNodes],\n );\n\n return { handleNodeSelect };\n}\n\ninterface SelectionAction {\n select: \"node\" | \"range\";\n type: SelectionChangeType | \"disabled\";\n}\n\nfunction getSelectionAction(selectionMode: SelectionMode, isSelected: boolean, shiftDown: boolean, ctrlDown: boolean): SelectionAction {\n switch (selectionMode) {\n case \"none\":\n return { select: \"node\", type: \"disabled\" };\n case \"single\":\n return { select: \"node\", type: isSelected ? \"remove\" : \"replace\" };\n case \"multiple\":\n return { select: \"node\", type: isSelected ? \"remove\" : \"add\" };\n case \"extended\":\n return getExtendedSelectionAction(isSelected, shiftDown, ctrlDown);\n }\n}\n\nfunction getExtendedSelectionAction(isSelected: boolean, shiftDown: boolean, ctrlDown: boolean): SelectionAction {\n if (shiftDown) {\n return { select: \"range\", type: \"replace\" };\n }\n if (ctrlDown) {\n return { select: \"node\", type: isSelected ? \"remove\" : \"add\" };\n }\n return { select: \"node\", type: \"replace\" };\n}\n\nfunction computeFlatNodeList(rootNodes: Array<TreeNode>): FlatTreeState {\n const flatNodeList: Array<string> = [];\n const nodeIdToIndexMap: Map<string, number> = new Map();\n\n const flattenNodeRecursively = (nodes: Array<TreeNode>) => {\n nodes.forEach((node) => {\n nodeIdToIndexMap.set(node.id, flatNodeList.length);\n flatNodeList.push(node.id);\n if (node.isExpanded && typeof node.children !== \"boolean\") {\n flattenNodeRecursively(node.children);\n }\n });\n };\n\n flattenNodeRecursively(rootNodes);\n return { flatNodeList, nodeIdToIndexMap };\n}\n"],"mappings":";;;;;;;;AA4DA,SAAOsB,oBAAAV,OAAA;CAAA,MAAAW,IAAAC,EAAA,GAAA;CACL,MAAA,EAAAC,WAAAhB,eAAAiB,gBAAkDd;CAClD,MAAAe,uBAA6BzB,OAA2B0B,OAAU;CAAC,IAAAC;AAAA,KAAAN,EAAA,OAAAO,OAAAC,IAAA,4BAAA,EAAA;AAC/BF,OAAA;GAAAX,cACpB,EAAE;GAAAE,kCACE,IAAIC,KAAI;GAC3B;AAAAE,IAAA,KAAAM;OAAAA,MAAAN,EAAA;CAHD,MAAAS,QAAc9B,OAAsB2B,GAGlC;CAAC,IAAAI;CAAA,IAAAC;AAAA,KAAAX,EAAA,OAAAE,WA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