@itwin/presentation-hierarchies-react 2.0.0-alpha.34 → 2.0.0-alpha.35
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 +13 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +12 -2
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js +3 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +6 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +2 -2
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +6 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +2 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @itwin/presentation-hierarchies-react
|
|
2
2
|
|
|
3
|
+
## 2.0.0-alpha.35
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1075](https://github.com/iTwin/presentation/pull/1075): Fix accessibility issues in `<TreeErrorRenderer />`.
|
|
8
|
+
|
|
9
|
+
This involves a few localized string changes:
|
|
10
|
+
- Added `issuesForTree`, defaulting to "Issues for {{tree_label}}.", used as a region landmark label for the error message container.
|
|
11
|
+
- Added `noIssuesFound`, defaulting to "No issues found.", used as a label for errors' list when there are no issues.
|
|
12
|
+
- Changed `issuesFound` to default to "{{number_of_issues}} issue(s) found.", and updated its usage to inject the number of issues found into the string instead of prefixing it before the string, which allows to place the number at any place in the string (may be a requirement for some languages). This is **a breaking change** for anyone, supplying their own localized strings.
|
|
13
|
+
|
|
14
|
+
Also, **a new required prop** `treeLabel` was added to `<TreeErrorRenderer />` and `<StrataKitTreeRenderer />` components. The label is used to uniquely identify a tree in the application, which is required for accessibility purposes.
|
|
15
|
+
|
|
3
16
|
## 2.0.0-alpha.34
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -55,10 +55,20 @@ export interface LocalizedStrings {
|
|
|
55
55
|
*/
|
|
56
56
|
rootResultLimitExceeded: string;
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
59
|
-
* Default value: `
|
|
58
|
+
* Name for the error region landmark.
|
|
59
|
+
* Default value: `Issues for {{tree_label}}.`.
|
|
60
|
+
*/
|
|
61
|
+
issuesForTree: string;
|
|
62
|
+
/**
|
|
63
|
+
* Label displayed on the error region, when errors are detected.
|
|
64
|
+
* Default value: `{{number_of_issues}} issue(s) found.`.
|
|
60
65
|
*/
|
|
61
66
|
issuesFound: string;
|
|
67
|
+
/**
|
|
68
|
+
* Label displayed on the error region, when no issues are found.
|
|
69
|
+
* Default value: `No issues found.`.
|
|
70
|
+
*/
|
|
71
|
+
noIssuesFound: string;
|
|
62
72
|
/**
|
|
63
73
|
* Message displayed when hierarchy size limit can be overridden.
|
|
64
74
|
* Default value: `Increase limit to {{limit}}`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalizationContext.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/LocalizationContext.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAiB,iBAAiB,EAAmC,MAAM,OAAO,CAAC;AAE1F;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,qCAAqC,EAAE,MAAM,CAAC;IAC9C;;;OAGG;IACH,yBAAyB,EAAE,MAAM,CAAC;IAClC;;;OAGG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,8BAA8B,EAAE,MAAM,CAAC;IACvC;;;OAGG;IACH,uBAAuB,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,2BAA2B,EAAE,MAAM,CAAC;IACpC;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,uBAAuB,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,iCAAiC,EAAE,MAAM,CAAC;IAC1C;;;OAGG;IACH,mCAAmC,EAAE,MAAM,CAAC;IAC5C;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED,gBAAgB;AAChB,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;
|
|
1
|
+
{"version":3,"file":"LocalizationContext.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/LocalizationContext.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAiB,iBAAiB,EAAmC,MAAM,OAAO,CAAC;AAE1F;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,qCAAqC,EAAE,MAAM,CAAC;IAC9C;;;OAGG;IACH,yBAAyB,EAAE,MAAM,CAAC;IAClC;;;OAGG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,8BAA8B,EAAE,MAAM,CAAC;IACvC;;;OAGG;IACH,uBAAuB,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,2BAA2B,EAAE,MAAM,CAAC;IACpC;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,uBAAuB,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,iCAAiC,EAAE,MAAM,CAAC;IAC1C;;;OAGG;IACH,mCAAmC,EAAE,MAAM,CAAC;IAC5C;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED,gBAAgB;AAChB,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AA0BD;;;GAGG;AACH,UAAU,gCAAgC;IACxC,gDAAgD;IAChD,gBAAgB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC9C;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,gBAAgB,EAAE,QAAQ,EAAE,EAAE,iBAAiB,CAAC,gCAAgC,CAAC,2CAQ9H;AAED,gBAAgB;AAChB,wBAAgB,sBAAsB,wBAErC"}
|
|
@@ -15,7 +15,9 @@ const defaultLocalizedStrings = {
|
|
|
15
15
|
failedToCreateRootHierarchy: "Failed to load tree.",
|
|
16
16
|
resultLimitExceeded: "The hierarchy for {{node}} contains {{limit}}+ items. Try using filters or increase the limit.",
|
|
17
17
|
rootResultLimitExceeded: "The root item hierarchy contains {{limit}}+ items. Try increasing the limit.",
|
|
18
|
-
|
|
18
|
+
issuesForTree: "Issues for {{tree_label}}.",
|
|
19
|
+
issuesFound: "{{number_of_issues}} issue(s) found.",
|
|
20
|
+
noIssuesFound: "No issues found.",
|
|
19
21
|
increaseHierarchyLimit: "Increase limit to {{limit}}",
|
|
20
22
|
increaseHierarchyLimitToUnlimited: "Remove limit",
|
|
21
23
|
increaseHierarchyLimitWithFiltering: "Add Filter",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalizationContext.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/LocalizationContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAqB,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"LocalizationContext.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/LocalizationContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAqB,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA6G1F,MAAM,uBAAuB,GAAqB;IAChD,OAAO,EAAE,YAAY;IACrB,oBAAoB,EAAE,cAAc;IACpC,qCAAqC,EAAE,mBAAmB;IAC1D,yBAAyB,EAAE,qBAAqB;IAChD,kBAAkB,EAAE,6CAA6C;IACjE,8BAA8B,EAAE,eAAe;IAC/C,uBAAuB,EAAE,0CAA0C;IACnE,2BAA2B,EAAE,sBAAsB;IACnD,mBAAmB,EAAE,gGAAgG;IACrH,uBAAuB,EAAE,8EAA8E;IACvG,aAAa,EAAE,4BAA4B;IAC3C,WAAW,EAAE,sCAAsC;IACnD,aAAa,EAAE,kBAAkB;IACjC,sBAAsB,EAAE,6BAA6B;IACrD,iCAAiC,EAAE,cAAc;IACjD,mCAAmC,EAAE,YAAY;IACjD,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACb,CAAC;AAEF,MAAM,mBAAmB,GAAG,aAAa,CAAsB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,CAAC,CAAC;AAW9G;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,EAAE,gBAAgB,EAAE,QAAQ,EAAuD;IAC7H,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAAE,GAAG,uBAAuB,EAAE,GAAG,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAE9G,SAAS,CAAC,GAAG,EAAE;QACb,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAAE,GAAG,uBAAuB,EAAE,GAAG,gBAAgB,EAAE,EAAE,CAAC,CAAC;IACtF,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEvB,OAAO,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAgC,CAAC;AAC/F,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,sBAAsB;IACpC,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,CAAC","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 { createContext, PropsWithChildren, useContext, useEffect, useState } from \"react\";\n\n/**\n * Localized strings used in the components.\n * @public\n */\nexport interface LocalizedStrings {\n /**\n * Message displayed when nodes are loading.\n * Default value: `Loading...`.\n */\n loading: string;\n /**\n * Title for apply hierarchy filter button.\n * Default value: `Apply filter`.\n */\n filterHierarchyLevel: string;\n /**\n * Accessible description for applied hierarchy filter button.\n * Default value: `Filter is applied`.\n */\n filterHierarchyLevelActiveDescription: string;\n /**\n * Title for clear hierarchy filter button.\n * Default value: `Clear active filter`.\n */\n clearHierarchyLevelFilter: string;\n /**\n * Message displayed when no nodes matching filter are found.\n * Default value: `No matches for current filter for {{node}}.`.\n */\n noFilteredChildren: string;\n /**\n * Label for change filter action.\n * Default value: `Change filter`.\n */\n noFilteredChildrenChangeFilter: string;\n /**\n * Message displayed when hierarchy creation for a node failed.\n * Default value: `Failed to create hierarchy for {{node}}.`.\n */\n failedToCreateHierarchy: string;\n /**\n * Message displayed when hierarchy creation for a node failed.\n * Default value: `Failed to load tree.`.\n */\n failedToCreateRootHierarchy: string;\n /**\n * Message displayed when result limit exceeds hierarchy size limit.\n * Default value: `The hierarchy for {{node}} contains {{limit}}+ items. Try using filters or increase the limit.`.\n */\n resultLimitExceeded: string;\n /**\n * Message displayed when result limit exceeds hierarchy size limit.\n * Default value: `The root item hierarchy contains {{limit}}+ items. Try increasing the limit.`.\n */\n rootResultLimitExceeded: string;\n /**\n * Name for the error region landmark.\n * Default value: `Issues for {{tree_label}}.`.\n */\n issuesForTree: string;\n /**\n * Label displayed on the error region, when errors are detected.\n * Default value: `{{number_of_issues}} issue(s) found.`.\n */\n issuesFound: string;\n /**\n * Label displayed on the error region, when no issues are found.\n * Default value: `No issues found.`.\n */\n noIssuesFound: string;\n /**\n * Message displayed when hierarchy size limit can be overridden.\n * Default value: `Increase limit to {{limit}}`.\n */\n increaseHierarchyLimit: string;\n /**\n * Message displayed when hierarchy size limit can be overridden.\n * Default value: `Remove limit`.\n */\n increaseHierarchyLimitToUnlimited: string;\n /**\n * Message displayed when hierarchy size limit can be overridden and hierarchy filtering is enabled.\n * Default value: `Add Filter`.\n */\n increaseHierarchyLimitWithFiltering: string;\n /**\n * Label for retry action.\n * Default value: `Retry`.\n */\n retry: string;\n /**\n * Label for rename action.\n * Default value: `Rename`.\n */\n rename: string;\n /**\n * Label for more actions button.\n * Default value: `More`.\n */\n more: string;\n}\n\n/** @internal */\nexport interface LocalizationContext {\n localizedStrings: LocalizedStrings;\n}\n\nconst defaultLocalizedStrings: LocalizedStrings = {\n loading: \"Loading...\",\n filterHierarchyLevel: \"Apply filter\",\n filterHierarchyLevelActiveDescription: \"Filter is applied\",\n clearHierarchyLevelFilter: \"Clear active filter\",\n noFilteredChildren: \"No matches for current filter for {{node}}.\",\n noFilteredChildrenChangeFilter: \"Change filter\",\n failedToCreateHierarchy: \"Failed to create hierarchy for {{node}}.\",\n failedToCreateRootHierarchy: \"Failed to load tree.\",\n resultLimitExceeded: \"The hierarchy for {{node}} contains {{limit}}+ items. Try using filters or increase the limit.\",\n rootResultLimitExceeded: \"The root item hierarchy contains {{limit}}+ items. Try increasing the limit.\",\n issuesForTree: \"Issues for {{tree_label}}.\",\n issuesFound: \"{{number_of_issues}} issue(s) found.\",\n noIssuesFound: \"No issues found.\",\n increaseHierarchyLimit: \"Increase limit to {{limit}}\",\n increaseHierarchyLimitToUnlimited: \"Remove limit\",\n increaseHierarchyLimitWithFiltering: \"Add Filter\",\n retry: \"Retry\",\n rename: \"Rename\",\n more: \"More\",\n};\n\nconst localizationContext = createContext<LocalizationContext>({ localizedStrings: defaultLocalizedStrings });\n\n/**\n * Properties for `LocalizationContextProvider`.\n * @public\n */\ninterface LocalizationContextProviderProps {\n /** Localized strings used in the components. */\n localizedStrings?: Partial<LocalizedStrings>;\n}\n\n/**\n * Context provider for localized strings used in the components.\n * @public\n */\nexport function LocalizationContextProvider({ localizedStrings, children }: PropsWithChildren<LocalizationContextProviderProps>) {\n const [state, setState] = useState({ localizedStrings: { ...defaultLocalizedStrings, ...localizedStrings } });\n\n useEffect(() => {\n setState({ localizedStrings: { ...defaultLocalizedStrings, ...localizedStrings } });\n }, [localizedStrings]);\n\n return <localizationContext.Provider value={state}>{children}</localizationContext.Provider>;\n}\n\n/** @internal */\nexport function useLocalizationContext() {\n return useContext(localizationContext);\n}\n"]}
|
|
@@ -23,6 +23,11 @@ interface TreeErrorItemProps {
|
|
|
23
23
|
* @alpha
|
|
24
24
|
*/
|
|
25
25
|
interface TreeErrorRendererOwnProps {
|
|
26
|
+
/**
|
|
27
|
+
* A user friendly display label of the tree. Should be unique within the consuming application,
|
|
28
|
+
* as it's used for creating a unique accessible label for the error region.
|
|
29
|
+
*/
|
|
30
|
+
treeLabel: string;
|
|
26
31
|
/** List of errors to be displayed */
|
|
27
32
|
errorList: ErrorItem[];
|
|
28
33
|
renderError?: ({ errorItem, scrollToElement }: {
|
|
@@ -38,6 +43,6 @@ export type TreeErrorRendererProps = TreeErrorRendererOwnProps & TreeErrorItemPr
|
|
|
38
43
|
*
|
|
39
44
|
* @alpha
|
|
40
45
|
*/
|
|
41
|
-
export declare function TreeErrorRenderer({ errorList, reloadTree, scrollToElement, getHierarchyLevelDetails, onFilterClick, renderError }: TreeErrorRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
46
|
+
export declare function TreeErrorRenderer({ treeLabel, errorList, reloadTree, scrollToElement, getHierarchyLevelDetails, onFilterClick, renderError, }: TreeErrorRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
42
47
|
export {};
|
|
43
48
|
//# sourceMappingURL=TreeErrorRenderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeErrorRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeErrorRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAIrC,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C;;;;GAIG;AACH,UAAU,kBAAkB;IAC1B,iGAAiG;IACjG,UAAU,EAAE,CAAC,OAAO,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IACpF,yEAAyE;IACzE,aAAa,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACvE,4FAA4F;IAC5F,eAAe,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;CACjD;AACD;;;;GAIG;AACH,UAAU,yBAAyB;IACjC,qCAAqC;IACrC,SAAS,EAAE,SAAS,EAAE,CAAC;IAEvB,WAAW,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,EAAE;QAAE,SAAS,EAAE,SAAS,CAAC;QAAC,eAAe,EAAE,MAAM,IAAI,CAAA;KAAE,KAAK,YAAY,CAAC;CACvH;AAED,aAAa;AACb,MAAM,MAAM,sBAAsB,GAAG,yBAAyB,GAAG,kBAAkB,GAAG,IAAI,CAAC,iBAAiB,EAAE,0BAA0B,CAAC,CAAC;AAE1I;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,
|
|
1
|
+
{"version":3,"file":"TreeErrorRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeErrorRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAIrC,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C;;;;GAIG;AACH,UAAU,kBAAkB;IAC1B,iGAAiG;IACjG,UAAU,EAAE,CAAC,OAAO,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IACpF,yEAAyE;IACzE,aAAa,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACvE,4FAA4F;IAC5F,eAAe,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;CACjD;AACD;;;;GAIG;AACH,UAAU,yBAAyB;IACjC;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,SAAS,EAAE,SAAS,EAAE,CAAC;IAEvB,WAAW,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,EAAE;QAAE,SAAS,EAAE,SAAS,CAAC;QAAC,eAAe,EAAE,MAAM,IAAI,CAAA;KAAE,KAAK,YAAY,CAAC;CACvH;AAED,aAAa;AACb,MAAM,MAAM,sBAAsB,GAAG,yBAAyB,GAAG,kBAAkB,GAAG,IAAI,CAAC,iBAAiB,EAAE,0BAA0B,CAAC,CAAC;AAE1I;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,SAAS,EACT,SAAS,EACT,UAAU,EACV,eAAe,EACf,wBAAwB,EACxB,aAAa,EACb,WAAW,GACZ,EAAE,sBAAsB,2CAmFxB"}
|
|
@@ -9,7 +9,7 @@ import { useLocalizationContext } from "./LocalizationContext.js";
|
|
|
9
9
|
*
|
|
10
10
|
* @alpha
|
|
11
11
|
*/
|
|
12
|
-
export function TreeErrorRenderer({ errorList, reloadTree, scrollToElement, getHierarchyLevelDetails, onFilterClick, renderError }) {
|
|
12
|
+
export function TreeErrorRenderer({ treeLabel, errorList, reloadTree, scrollToElement, getHierarchyLevelDetails, onFilterClick, renderError, }) {
|
|
13
13
|
const { localizedStrings } = useLocalizationContext();
|
|
14
14
|
const errorItems = errorList.map(({ errorNode, expandTo }) => {
|
|
15
15
|
if (renderError) {
|
|
@@ -56,7 +56,7 @@ export function TreeErrorRenderer({ errorList, reloadTree, scrollToElement, getH
|
|
|
56
56
|
},
|
|
57
57
|
], message: localizedStrings.failedToCreateHierarchy, scrollToElement: () => scrollToElement({ errorNode, expandTo }) }, errorNode.id));
|
|
58
58
|
});
|
|
59
|
-
return (_jsx(ErrorRegion.Root, { style: { width: "100%" }, label: errorList.length
|
|
59
|
+
return (_jsx(ErrorRegion.Root, { style: { width: "100%" }, "aria-label": localizedStrings.issuesForTree.replace("{{tree_label}}", treeLabel), label: errorList.length === 0 ? localizedStrings.noIssuesFound : localizedStrings.issuesFound.replace("{{number_of_issues}}", errorList.length.toString()), items: errorItems }));
|
|
60
60
|
}
|
|
61
61
|
function ErrorItemContainer({ errorNode, message, actions, scrollToElement }) {
|
|
62
62
|
return (_jsx(ErrorRegion.Item, { message: _jsx(MessageWithLink, { linkLabel: errorNode.label, scrollToElement: scrollToElement, message: message }), messageId: errorNode.id, actions: _jsx("div", { style: { display: "flex", flexDirection: "column" }, children: actions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeErrorRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeErrorRenderer.tsx"],"names":[],"mappings":";AAMA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,oBAAoB,IAAI,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AA8BlE;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,wBAAwB,EAAE,aAAa,EAAE,WAAW,EAA0B;IACxJ,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACtD,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE;QAC3D,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9H,CAAC;QAED,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,KAAK,mBAAmB,EAAE,CAAC;YAClD,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,kBAAkB,CAAC;YACjD,MAAM,eAAe,GAAG,wB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,CAAC","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 { ReactElement } from \"react\";\nimport { Anchor, Text } from \"@stratakit/bricks\";\nimport { unstable_ErrorRegion as ErrorRegion } from \"@stratakit/structures\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils.js\";\nimport { HierarchyLevelDetails, TreeRendererProps } from \"../Renderers.js\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { ErrorItem } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\n/**\n * Interface containing error item related actions.\n *\n * @alpha\n */\ninterface TreeErrorItemProps {\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n /** Action to perform when the filter button is clicked for this node. */\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n /** Action to perform when an error occurs and node label is clicked in the error message */\n scrollToElement: (errorNode: ErrorItem) => void;\n}\n/**\n * Interface containing building blocks for `TreeErrorRenderer`.\n *\n * @alpha\n */\ninterface TreeErrorRendererOwnProps {\n /** List of errors to be displayed */\n errorList: ErrorItem[];\n // Callback to render custom error messages. Component should be wrapped in `ErrorRegion.Item` from `@itwin/itwinui-react` package.\n renderError?: ({ errorItem, scrollToElement }: { errorItem: ErrorItem; scrollToElement: () => void }) => ReactElement;\n}\n\n/** @alpha */\nexport type TreeErrorRendererProps = TreeErrorRendererOwnProps & TreeErrorItemProps & Pick<TreeRendererProps, \"getHierarchyLevelDetails\">;\n\n/**\n * A component that renders error display dropdown using the `unstable_ErrorRegion` component from `@itwin/itwinui-react`.\n * As input, the component uses a list of `ErrorNode` objects, which are generally created using the `useErrorList` hook.\n *\n * @alpha\n */\nexport function TreeErrorRenderer({ errorList, reloadTree, scrollToElement, getHierarchyLevelDetails, onFilterClick, renderError }: TreeErrorRendererProps) {\n const { localizedStrings } = useLocalizationContext();\n const errorItems = errorList.map(({ errorNode, expandTo }) => {\n if (renderError) {\n return renderError({ errorItem: { errorNode, expandTo }, scrollToElement: () => scrollToElement({ errorNode, expandTo }) });\n }\n\n if (errorNode.error?.type === \"ResultSetTooLarge\") {\n const limit = errorNode.error.resultSetSizeLimit;\n const onOverrideLimit = getHierarchyLevelDetails ? () => getHierarchyLevelDetails(errorNode.id)?.setSizeLimit(MAX_LIMIT_OVERRIDE) : undefined;\n return (\n <ErrorItemContainer\n key={errorNode.error.id}\n errorNode={errorNode}\n actions={[\n {\n action: () => {\n onOverrideLimit?.();\n },\n label: localizedStrings.increaseHierarchyLimit.replace(\"{{limit}}\", MAX_LIMIT_OVERRIDE.toString()),\n condition: () => !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE,\n },\n {\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(errorNode.id);\n hierarchyLevelDetails && onFilterClick?.(hierarchyLevelDetails);\n },\n label: localizedStrings.increaseHierarchyLimitWithFiltering,\n condition: () => !!onFilterClick && !!errorNode?.isFilterable,\n },\n ]}\n message={localizedStrings.resultLimitExceeded.replace(\"{{limit}}\", limit.toString())}\n scrollToElement={() => scrollToElement({ errorNode, expandTo })}\n />\n );\n }\n if (errorNode.error?.type === \"NoFilterMatches\") {\n return (\n <ErrorItemContainer\n key={errorNode.error.id}\n errorNode={errorNode}\n actions={[\n {\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(errorNode.id);\n hierarchyLevelDetails && onFilterClick?.(hierarchyLevelDetails);\n },\n label: localizedStrings.noFilteredChildrenChangeFilter,\n condition: () => true,\n },\n ]}\n message={localizedStrings.noFilteredChildren}\n scrollToElement={() => scrollToElement({ errorNode, expandTo })}\n />\n );\n }\n return (\n <ErrorItemContainer\n key={errorNode.id}\n errorNode={errorNode}\n actions={[\n {\n action: () => reloadTree({ parentNodeId: errorNode.id, state: \"reset\" }),\n label: localizedStrings.retry,\n condition: () => true,\n },\n ]}\n message={localizedStrings.failedToCreateHierarchy}\n scrollToElement={() => scrollToElement({ errorNode, expandTo })}\n />\n );\n });\n\n return (\n <ErrorRegion.Root\n style={{ width: \"100%\" }}\n label={errorList.length !== 0 ? `${errorList.length} ${localizedStrings?.issuesFound}` : undefined}\n items={errorItems}\n />\n );\n}\n\ntype ErrorItemContainerProps = {\n errorNode: PresentationHierarchyNode;\n message: string;\n actions?: { action: () => void; label: string; condition: () => boolean }[];\n} & Pick<MessageWithLinkProps, \"scrollToElement\">;\n\nfunction ErrorItemContainer({ errorNode, message, actions, scrollToElement }: ErrorItemContainerProps) {\n return (\n <ErrorRegion.Item\n message={<MessageWithLink linkLabel={errorNode.label} scrollToElement={scrollToElement} message={message} />}\n messageId={errorNode.id}\n actions={\n <div style={{ display: \"flex\", flexDirection: \"column\" }}>\n {actions\n ?.filter(({ condition }) => condition())\n .map(({ label, action }) => (\n <Anchor key={label} onClick={action}>\n {label}\n </Anchor>\n ))}\n </div>\n }\n />\n );\n}\n\ninterface MessageWithLinkProps {\n scrollToElement: () => void;\n message: string;\n linkLabel?: string;\n}\n\nfunction MessageWithLink({ linkLabel, scrollToElement, message }: MessageWithLinkProps) {\n const splitMessage = message.split(\"{{node}}\", 2);\n return (\n <div style={{ display: \"flex\", whiteSpace: \"pre\", flexWrap: \"wrap\" }}>\n <Text variant={\"body-sm\"}>{splitMessage[0]}</Text>\n <Anchor onClick={scrollToElement}>{linkLabel}</Anchor>\n {splitMessage[1] ? <Text variant={\"body-sm\"}>{splitMessage[1]}</Text> : null}\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeErrorRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeErrorRenderer.tsx"],"names":[],"mappings":";AAMA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,oBAAoB,IA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,EACvB,OAAO,EACL,cAAK,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,YACrD,OAAO;gBACN,EAAE,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,EAAE,CAAC;iBACvC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAC1B,KAAC,MAAM,IAAa,OAAO,EAAE,MAAM,YAChC,KAAK,IADK,KAAK,CAET,CACV,CAAC,GACA,GAER,CACH,CAAC;AACJ,CAAC;AAQD,SAAS,eAAe,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAwB;IACpF,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAClD,OAAO,CACL,eAAK,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,aAClE,KAAC,IAAI,IAAC,OAAO,EAAE,SAAS,YAAG,YAAY,CAAC,CAAC,CAAC,GAAQ,EAClD,KAAC,MAAM,IAAC,OAAO,EAAE,eAAe,YAAG,SAAS,GAAU,EACrD,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAC,IAAI,IAAC,OAAO,EAAE,SAAS,YAAG,YAAY,CAAC,CAAC,CAAC,GAAQ,CAAC,CAAC,CAAC,IAAI,IACxE,CACP,CAAC;AACJ,CAAC","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 { ReactElement } from \"react\";\nimport { Anchor, Text } from \"@stratakit/bricks\";\nimport { unstable_ErrorRegion as ErrorRegion } from \"@stratakit/structures\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils.js\";\nimport { HierarchyLevelDetails, TreeRendererProps } from \"../Renderers.js\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { ErrorItem } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\n/**\n * Interface containing error item related actions.\n *\n * @alpha\n */\ninterface TreeErrorItemProps {\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n /** Action to perform when the filter button is clicked for this node. */\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n /** Action to perform when an error occurs and node label is clicked in the error message */\n scrollToElement: (errorNode: ErrorItem) => void;\n}\n/**\n * Interface containing building blocks for `TreeErrorRenderer`.\n *\n * @alpha\n */\ninterface TreeErrorRendererOwnProps {\n /**\n * A user friendly display label of the tree. Should be unique within the consuming application,\n * as it's used for creating a unique accessible label for the error region.\n */\n treeLabel: string;\n /** List of errors to be displayed */\n errorList: ErrorItem[];\n // Callback to render custom error messages. Component should be wrapped in `ErrorRegion.Item` from `@itwin/itwinui-react` package.\n renderError?: ({ errorItem, scrollToElement }: { errorItem: ErrorItem; scrollToElement: () => void }) => ReactElement;\n}\n\n/** @alpha */\nexport type TreeErrorRendererProps = TreeErrorRendererOwnProps & TreeErrorItemProps & Pick<TreeRendererProps, \"getHierarchyLevelDetails\">;\n\n/**\n * A component that renders error display dropdown using the `unstable_ErrorRegion` component from `@itwin/itwinui-react`.\n * As input, the component uses a list of `ErrorNode` objects, which are generally created using the `useErrorList` hook.\n *\n * @alpha\n */\nexport function TreeErrorRenderer({\n treeLabel,\n errorList,\n reloadTree,\n scrollToElement,\n getHierarchyLevelDetails,\n onFilterClick,\n renderError,\n}: TreeErrorRendererProps) {\n const { localizedStrings } = useLocalizationContext();\n const errorItems = errorList.map(({ errorNode, expandTo }) => {\n if (renderError) {\n return renderError({ errorItem: { errorNode, expandTo }, scrollToElement: () => scrollToElement({ errorNode, expandTo }) });\n }\n\n if (errorNode.error?.type === \"ResultSetTooLarge\") {\n const limit = errorNode.error.resultSetSizeLimit;\n const onOverrideLimit = getHierarchyLevelDetails ? () => getHierarchyLevelDetails(errorNode.id)?.setSizeLimit(MAX_LIMIT_OVERRIDE) : undefined;\n return (\n <ErrorItemContainer\n key={errorNode.error.id}\n errorNode={errorNode}\n actions={[\n {\n action: () => {\n onOverrideLimit?.();\n },\n label: localizedStrings.increaseHierarchyLimit.replace(\"{{limit}}\", MAX_LIMIT_OVERRIDE.toString()),\n condition: () => !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE,\n },\n {\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(errorNode.id);\n hierarchyLevelDetails && onFilterClick?.(hierarchyLevelDetails);\n },\n label: localizedStrings.increaseHierarchyLimitWithFiltering,\n condition: () => !!onFilterClick && !!errorNode?.isFilterable,\n },\n ]}\n message={localizedStrings.resultLimitExceeded.replace(\"{{limit}}\", limit.toString())}\n scrollToElement={() => scrollToElement({ errorNode, expandTo })}\n />\n );\n }\n if (errorNode.error?.type === \"NoFilterMatches\") {\n return (\n <ErrorItemContainer\n key={errorNode.error.id}\n errorNode={errorNode}\n actions={[\n {\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(errorNode.id);\n hierarchyLevelDetails && onFilterClick?.(hierarchyLevelDetails);\n },\n label: localizedStrings.noFilteredChildrenChangeFilter,\n condition: () => true,\n },\n ]}\n message={localizedStrings.noFilteredChildren}\n scrollToElement={() => scrollToElement({ errorNode, expandTo })}\n />\n );\n }\n return (\n <ErrorItemContainer\n key={errorNode.id}\n errorNode={errorNode}\n actions={[\n {\n action: () => reloadTree({ parentNodeId: errorNode.id, state: \"reset\" }),\n label: localizedStrings.retry,\n condition: () => true,\n },\n ]}\n message={localizedStrings.failedToCreateHierarchy}\n scrollToElement={() => scrollToElement({ errorNode, expandTo })}\n />\n );\n });\n\n return (\n <ErrorRegion.Root\n style={{ width: \"100%\" }}\n aria-label={localizedStrings.issuesForTree.replace(\"{{tree_label}}\", treeLabel)}\n label={\n errorList.length === 0 ? localizedStrings.noIssuesFound : localizedStrings.issuesFound.replace(\"{{number_of_issues}}\", errorList.length.toString())\n }\n items={errorItems}\n />\n );\n}\n\ntype ErrorItemContainerProps = {\n errorNode: PresentationHierarchyNode;\n message: string;\n actions?: { action: () => void; label: string; condition: () => boolean }[];\n} & Pick<MessageWithLinkProps, \"scrollToElement\">;\n\nfunction ErrorItemContainer({ errorNode, message, actions, scrollToElement }: ErrorItemContainerProps) {\n return (\n <ErrorRegion.Item\n message={<MessageWithLink linkLabel={errorNode.label} scrollToElement={scrollToElement} message={message} />}\n messageId={errorNode.id}\n actions={\n <div style={{ display: \"flex\", flexDirection: \"column\" }}>\n {actions\n ?.filter(({ condition }) => condition())\n .map(({ label, action }) => (\n <Anchor key={label} onClick={action}>\n {label}\n </Anchor>\n ))}\n </div>\n }\n />\n );\n}\n\ninterface MessageWithLinkProps {\n scrollToElement: () => void;\n message: string;\n linkLabel?: string;\n}\n\nfunction MessageWithLink({ linkLabel, scrollToElement, message }: MessageWithLinkProps) {\n const splitMessage = message.split(\"{{node}}\", 2);\n return (\n <div style={{ display: \"flex\", whiteSpace: \"pre\", flexWrap: \"wrap\" }}>\n <Text variant={\"body-sm\"}>{splitMessage[0]}</Text>\n <Anchor onClick={scrollToElement}>{linkLabel}</Anchor>\n {splitMessage[1] ? <Text variant={\"body-sm\"}>{splitMessage[1]}</Text> : null}\n </div>\n );\n}\n"]}
|
|
@@ -12,6 +12,11 @@ export type TreeProps = ComponentPropsWithoutRef<typeof Tree.Root>;
|
|
|
12
12
|
export type TreeNodeRendererProps = ComponentPropsWithoutRef<typeof StrataKitTreeNodeRenderer>;
|
|
13
13
|
/** @alpha */
|
|
14
14
|
interface TreeRendererOwnProps {
|
|
15
|
+
/**
|
|
16
|
+
* A user friendly display label of the tree. Should be unique within the consuming application,
|
|
17
|
+
* as it's used for accessibility purposes.
|
|
18
|
+
*/
|
|
19
|
+
treeLabel: string;
|
|
15
20
|
/** Active selection mode used by the tree. Defaults to `"single"`. */
|
|
16
21
|
selectionMode?: SelectionMode;
|
|
17
22
|
/** A render function for errors' display component. Defaults to `<TreeErrorRenderer />`. */
|
|
@@ -35,6 +40,6 @@ type StrataKitTreeRendererProps = TreeRendererProps & Pick<TreeErrorRendererProp
|
|
|
35
40
|
* @see https://itwinui.bentley.com/docs/tree
|
|
36
41
|
* @alpha
|
|
37
42
|
*/
|
|
38
|
-
export declare function StrataKitTreeRenderer({ rootNodes, selectNodes, selectionMode, expandNode, localizedStrings, getHierarchyLevelDetails, onFilterClick, reloadTree, isNodeSelected, errorRenderer, onNodeClick: onNodeClickOverride, onNodeKeyDown: onNodeKeyDownOverride, getEditingProps, ...treeProps }: StrataKitTreeRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
export declare function StrataKitTreeRenderer({ rootNodes, selectNodes, selectionMode, expandNode, treeLabel, localizedStrings, getHierarchyLevelDetails, onFilterClick, reloadTree, isNodeSelected, errorRenderer, onNodeClick: onNodeClickOverride, onNodeKeyDown: onNodeKeyDownOverride, getEditingProps, ...treeProps }: StrataKitTreeRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
39
44
|
export {};
|
|
40
45
|
//# sourceMappingURL=TreeRenderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,EAAmC,YAAY,EAA2C,MAAM,OAAO,CAAC;AACzI,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAuB,MAAM,2BAA2B,CAAC;AAG/E,OAAO,EAA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Ae,GAAG,cAAc,GAAG,YAAY,GAAG,UAAU,GAAG,OAAO,CAAC,GAC3H,oBAAoB,GACpB,wBAAwB,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAE/D;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,SAAS,EACT,WAAW,EACX,aAAa,EACb,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,UAAU,EACV,cAAc,EACd,aAAa,EACb,WAAW,EAAE,mBAAmB,EAChC,aAAa,EAAE,qBAAqB,EACpC,eAAe,EACf,GAAG,SAAS,EACb,EAAE,0BAA0B,2CAuF5B"}
|
|
@@ -21,7 +21,7 @@ import { PlaceholderNode, StrataKitTreeNodeRenderer } from "./TreeNodeRenderer.j
|
|
|
21
21
|
* @see https://itwinui.bentley.com/docs/tree
|
|
22
22
|
* @alpha
|
|
23
23
|
*/
|
|
24
|
-
export function StrataKitTreeRenderer({ rootNodes, selectNodes, selectionMode, expandNode, localizedStrings, getHierarchyLevelDetails, onFilterClick, reloadTree, isNodeSelected, errorRenderer, onNodeClick: onNodeClickOverride, onNodeKeyDown: onNodeKeyDownOverride, getEditingProps, ...treeProps }) {
|
|
24
|
+
export function StrataKitTreeRenderer({ rootNodes, selectNodes, selectionMode, expandNode, treeLabel, localizedStrings, getHierarchyLevelDetails, onFilterClick, reloadTree, isNodeSelected, errorRenderer, onNodeClick: onNodeClickOverride, onNodeKeyDown: onNodeKeyDownOverride, getEditingProps, ...treeProps }) {
|
|
25
25
|
const { onNodeClick, onNodeKeyDown } = useSelectionHandler({
|
|
26
26
|
rootNodes,
|
|
27
27
|
selectNodes: selectNodes ?? noopSelectNodes,
|
|
@@ -62,6 +62,7 @@ export function StrataKitTreeRenderer({ rootNodes, selectNodes, selectionMode, e
|
|
|
62
62
|
scrollToNode.current = undefined;
|
|
63
63
|
}, [flatItems, virtualizer]);
|
|
64
64
|
const errorRendererProps = {
|
|
65
|
+
treeLabel,
|
|
65
66
|
errorList,
|
|
66
67
|
scrollToElement,
|
|
67
68
|
getHierarchyLevelDetails,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeRenderer.tsx"],"names":[],"mappings":";;AAAA;;;gGAGgG;AAEhG,OAAO,EAA2C,UAAU,EAAE,IAAI,EAAgB,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACzI,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAiB,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAA2B,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC/G,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAA0B,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAgCnF;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,EACpC,SAAS,EACT,WAAW,EACX,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,UAAU,EACV,cAAc,EACd,aAAa,EACb,WAAW,EAAE,mBAAmB,EAChC,aAAa,EAAE,qBAAqB,EACpC,eAAe,EACf,GAAG,SAAS,EACe;IAC3B,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,mBAAmB,CAAC;QACzD,SAAS;QACT,WAAW,EAAE,WAAW,IAAI,eAAe;QAC3C,aAAa,EAAE,aAAa,IAAI,QA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AK,gBAAc,IAAI,CAAC,KAAK,mBAAiB,CAAC,kBAAgB,CAAC,GAAI,CAAC;IACpI,CAAC;IAED,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,OAAO,CACL,KAAC,qBAAqB,IAAC,cAAc,EAAE,YAAY,EAAE,cAAc,YACjE,KAAC,yBAAyB,OACpB,KAAK,EACT,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,KAAK,gBACA,IAAI,CAAC,KAAK,mBACP,IAAI,CAAC,UAAU,kBAChB,IAAI,CAAC,SAAS,EAC5B,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,cAAc,EAC9B,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,GAC5B,GACoB,CACzB,CAAC;AACJ,CAAC,CAAC,CACH,CAAC;AAEF,SAAS,eAAe,KAAI,CAAC","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 { ComponentPropsWithoutRef, CSSProperties, forwardRef, memo, ReactElement, useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { Tree } from \"@stratakit/structures\";\nimport { useVirtualizer } from \"@tanstack/react-virtual\";\nimport { TreeRendererProps } from \"../Renderers.js\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { SelectionMode, useSelectionHandler } from \"../UseSelectionHandler.js\";\nimport { useEvent } from \"../Utils.js\";\nimport { ErrorItem, FlatTreeItem, isPlaceholderItem, useErrorList, useFlatTreeItems } from \"./FlatTreeNode.js\";\nimport { LocalizationContextProvider } from \"./LocalizationContext.js\";\nimport { RenameContextProvider } from \"./RenameAction.js\";\nimport { TreeErrorRenderer, TreeErrorRendererProps } from \"./TreeErrorRenderer.js\";\nimport { PlaceholderNode, StrataKitTreeNodeRenderer } from \"./TreeNodeRenderer.js\";\n\n/** @alpha */\nexport type TreeProps = ComponentPropsWithoutRef<typeof Tree.Root>;\n\n/** @alpha */\nexport type TreeNodeRendererProps = ComponentPropsWithoutRef<typeof StrataKitTreeNodeRenderer>;\n\n/** @alpha */\ninterface TreeRendererOwnProps {\n /** Active selection mode used by the tree. Defaults to `\"single\"`. */\n selectionMode?: SelectionMode;\n /** A render function for errors' display component. Defaults to `<TreeErrorRenderer />`. */\n errorRenderer?: (props: TreeErrorRendererProps) => ReactElement;\n /** Props that defines if current node supports editing. */\n getEditingProps?: (node: PresentationHierarchyNode) => {\n /**\n * A callback that is invoked when node label is changed. Should be used together\n * with `<RenameAction />` to enter label editing mode. Node label is not editable\n * when this is not supplied.\n */\n onLabelChanged?: (newLabel: string) => void;\n };\n}\n\n/** @alpha */\ntype StrataKitTreeRendererProps = TreeRendererProps &\n Pick<TreeErrorRendererProps, \"onFilterClick\"> &\n Omit<TreeNodeRendererProps, \"node\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"reloadTree\" | \"selected\" | \"error\"> &\n TreeRendererOwnProps &\n ComponentPropsWithoutRef<typeof LocalizationContextProvider>;\n\n/**\n * A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes\n * are rendered using `TreeNodeRenderer` component from this package.\n *\n * @see https://itwinui.bentley.com/docs/tree\n * @alpha\n */\nexport function StrataKitTreeRenderer({\n rootNodes,\n selectNodes,\n selectionMode,\n expandNode,\n localizedStrings,\n getHierarchyLevelDetails,\n onFilterClick,\n reloadTree,\n isNodeSelected,\n errorRenderer,\n onNodeClick: onNodeClickOverride,\n onNodeKeyDown: onNodeKeyDownOverride,\n getEditingProps,\n ...treeProps\n}: StrataKitTreeRendererProps) {\n const { onNodeClick, onNodeKeyDown } = useSelectionHandler({\n rootNodes,\n selectNodes: selectNodes ?? noopSelectNodes,\n selectionMode: selectionMode ?? \"single\",\n });\n const handleNodeClick = useEvent(onNodeClickOverride ?? onNodeClick);\n const handleKeyDown = useEvent(onNodeKeyDownOverride ?? onNodeKeyDown);\n const flatItems = useFlatTreeItems(rootNodes);\n const errorList = useErrorList(rootNodes);\n\n const scrollToNode = useRef<string | undefined>(undefined);\n const parentRef = useRef<HTMLDivElement>(null);\n\n const virtualizer = useVirtualizer({\n count: flatItems.length,\n getScrollElement: () => parentRef.current,\n getItemKey: (index) => flatItems[index].id,\n estimateSize: () => 28,\n overscan: 10,\n });\n\n const items = virtualizer.getVirtualItems();\n\n const scrollToElement = useCallback(\n ({ errorNode, expandTo }: ErrorItem) => {\n const index = flatItems.findIndex((flatItem) => flatItem.id === errorNode.id);\n if (index === -1) {\n expandTo((nodeId) => expandNode(nodeId, true));\n scrollToNode.current = errorNode.id;\n return;\n }\n virtualizer.scrollToIndex(index, { align: \"end\" });\n },\n [expandNode, flatItems, virtualizer],\n );\n\n useEffect(() => {\n if (scrollToNode.current === undefined) {\n return;\n }\n const index = flatItems.findIndex((flatItem) => flatItem.id === scrollToNode.current);\n if (index === -1) {\n return;\n }\n virtualizer.scrollToIndex(index, { align: \"end\" });\n scrollToNode.current = undefined;\n }, [flatItems, virtualizer]);\n\n const errorRendererProps: TreeErrorRendererProps = {\n errorList,\n scrollToElement,\n getHierarchyLevelDetails,\n onFilterClick,\n reloadTree,\n };\n\n return (\n <LocalizationContextProvider localizedStrings={localizedStrings}>\n {errorRenderer ? errorRenderer(errorRendererProps) : <TreeErrorRenderer {...errorRendererProps} />}\n <div style={{ height: \"100%\", width: \"100%\", overflowY: \"auto\" }} ref={parentRef}>\n <Tree.Root style={{ height: virtualizer.getTotalSize(), minHeight: \"100%\", width: \"100%\", position: \"relative\", overflow: \"hidden\" }}>\n {items.map((virtualizedItem) => {\n const item = flatItems[virtualizedItem.index];\n const selected = isNodeSelected?.(item.id) ?? false;\n return (\n <VirtualTreeItem\n {...treeProps}\n onNodeClick={handleNodeClick}\n onNodeKeyDown={handleKeyDown}\n ref={virtualizer.measureElement}\n start={virtualizedItem.start}\n expandNode={expandNode}\n item={item}\n key={virtualizedItem.key}\n data-index={virtualizedItem.index}\n reloadTree={reloadTree}\n selected={selected}\n getEditingProps={getEditingProps}\n />\n );\n })}\n </Tree.Root>\n </div>\n </LocalizationContextProvider>\n );\n}\n\ntype VirtualTreeItemProps = Omit<TreeNodeRendererProps, \"node\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\"> & {\n start: number;\n item: FlatTreeItem;\n getEditingProps?: TreeRendererOwnProps[\"getEditingProps\"];\n};\n\nconst VirtualTreeItem = memo(\n forwardRef<HTMLElement, VirtualTreeItemProps>(function VirtualTreeItem(\n {\n start,\n item,\n getDecorations,\n getMenuActions,\n getInlineActions,\n getLabel,\n getSublabel,\n expandNode,\n reloadTree,\n onNodeClick,\n onNodeKeyDown,\n getEditingProps,\n ...props\n },\n forwardedRef,\n ) {\n const style: CSSProperties = useMemo(\n () => ({\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n transform: `translateY(${start}px)`,\n willChange: \"transform\",\n }),\n [start],\n );\n\n if (isPlaceholderItem(item)) {\n return <PlaceholderNode {...props} ref={forwardedRef} style={style} aria-level={item.level} aria-posinset={1} aria-setsize={1} />;\n }\n\n const editingProps = getEditingProps?.(item.node);\n return (\n <RenameContextProvider onLabelChanged={editingProps?.onLabelChanged}>\n <StrataKitTreeNodeRenderer\n {...props}\n ref={forwardedRef}\n style={style}\n aria-level={item.level}\n aria-posinset={item.posInLevel}\n aria-setsize={item.levelSize}\n node={item.node}\n expandNode={expandNode}\n reloadTree={reloadTree}\n getDecorations={getDecorations}\n getMenuActions={getMenuActions}\n getInlineActions={getInlineActions}\n getLabel={getLabel}\n getSublabel={getSublabel}\n onNodeClick={onNodeClick}\n onNodeKeyDown={onNodeKeyDown}\n />\n </RenameContextProvider>\n );\n }),\n);\n\nfunction noopSelectNodes() {}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeRenderer.tsx"],"names":[],"mappings":";;AAAA;;;gGAGgG;AAEhG,OAAO,EAA2C,UAAU,EAAE,IAAI,EAAgB,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACzI,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAiB,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAA2B,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC/G,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAA0B,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAqCnF;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,EACpC,SAAS,EACT,WAAW,EACX,aAAa,EACb,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,UAAU,EACV,cAAc,EACd,aAAa,EACb,WAAW,EAAE,mBAAmB,EAChC,aAAa,EAAE,qBAAqB,EACpC,eAAe,EACf,GAAG,SAAS,EACe;IAC3B,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,mBAAmB,CAAC;QACzD,SAAS;QACT,WAAW,EAAE,WAAW,IAAI,eAAe;QAC3C,aAAa,EAAE,aAAa,IAAI,QAAQ;KACzC,CAAC,CAAC;IAC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I,CAAC,KAAK,mBAAiB,CAAC,kBAAgB,CAAC,GAAI,CAAC;IACpI,CAAC;IAED,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,OAAO,CACL,KAAC,qBAAqB,IAAC,cAAc,EAAE,YAAY,EAAE,cAAc,YACjE,KAAC,yBAAyB,OACpB,KAAK,EACT,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,KAAK,gBACA,IAAI,CAAC,KAAK,mBACP,IAAI,CAAC,UAAU,kBAChB,IAAI,CAAC,SAAS,EAC5B,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,cAAc,EAC9B,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,GAC5B,GACoB,CACzB,CAAC;AACJ,CAAC,CAAC,CACH,CAAC;AAEF,SAAS,eAAe,KAAI,CAAC","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 { ComponentPropsWithoutRef, CSSProperties, forwardRef, memo, ReactElement, useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { Tree } from \"@stratakit/structures\";\nimport { useVirtualizer } from \"@tanstack/react-virtual\";\nimport { TreeRendererProps } from \"../Renderers.js\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { SelectionMode, useSelectionHandler } from \"../UseSelectionHandler.js\";\nimport { useEvent } from \"../Utils.js\";\nimport { ErrorItem, FlatTreeItem, isPlaceholderItem, useErrorList, useFlatTreeItems } from \"./FlatTreeNode.js\";\nimport { LocalizationContextProvider } from \"./LocalizationContext.js\";\nimport { RenameContextProvider } from \"./RenameAction.js\";\nimport { TreeErrorRenderer, TreeErrorRendererProps } from \"./TreeErrorRenderer.js\";\nimport { PlaceholderNode, StrataKitTreeNodeRenderer } from \"./TreeNodeRenderer.js\";\n\n/** @alpha */\nexport type TreeProps = ComponentPropsWithoutRef<typeof Tree.Root>;\n\n/** @alpha */\nexport type TreeNodeRendererProps = ComponentPropsWithoutRef<typeof StrataKitTreeNodeRenderer>;\n\n/** @alpha */\ninterface TreeRendererOwnProps {\n /**\n * A user friendly display label of the tree. Should be unique within the consuming application,\n * as it's used for accessibility purposes.\n */\n treeLabel: string;\n /** Active selection mode used by the tree. Defaults to `\"single\"`. */\n selectionMode?: SelectionMode;\n /** A render function for errors' display component. Defaults to `<TreeErrorRenderer />`. */\n errorRenderer?: (props: TreeErrorRendererProps) => ReactElement;\n /** Props that defines if current node supports editing. */\n getEditingProps?: (node: PresentationHierarchyNode) => {\n /**\n * A callback that is invoked when node label is changed. Should be used together\n * with `<RenameAction />` to enter label editing mode. Node label is not editable\n * when this is not supplied.\n */\n onLabelChanged?: (newLabel: string) => void;\n };\n}\n\n/** @alpha */\ntype StrataKitTreeRendererProps = TreeRendererProps &\n Pick<TreeErrorRendererProps, \"onFilterClick\"> &\n Omit<TreeNodeRendererProps, \"node\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"reloadTree\" | \"selected\" | \"error\"> &\n TreeRendererOwnProps &\n ComponentPropsWithoutRef<typeof LocalizationContextProvider>;\n\n/**\n * A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes\n * are rendered using `TreeNodeRenderer` component from this package.\n *\n * @see https://itwinui.bentley.com/docs/tree\n * @alpha\n */\nexport function StrataKitTreeRenderer({\n rootNodes,\n selectNodes,\n selectionMode,\n expandNode,\n treeLabel,\n localizedStrings,\n getHierarchyLevelDetails,\n onFilterClick,\n reloadTree,\n isNodeSelected,\n errorRenderer,\n onNodeClick: onNodeClickOverride,\n onNodeKeyDown: onNodeKeyDownOverride,\n getEditingProps,\n ...treeProps\n}: StrataKitTreeRendererProps) {\n const { onNodeClick, onNodeKeyDown } = useSelectionHandler({\n rootNodes,\n selectNodes: selectNodes ?? noopSelectNodes,\n selectionMode: selectionMode ?? \"single\",\n });\n const handleNodeClick = useEvent(onNodeClickOverride ?? onNodeClick);\n const handleKeyDown = useEvent(onNodeKeyDownOverride ?? onNodeKeyDown);\n const flatItems = useFlatTreeItems(rootNodes);\n const errorList = useErrorList(rootNodes);\n\n const scrollToNode = useRef<string | undefined>(undefined);\n const parentRef = useRef<HTMLDivElement>(null);\n\n const virtualizer = useVirtualizer({\n count: flatItems.length,\n getScrollElement: () => parentRef.current,\n getItemKey: (index) => flatItems[index].id,\n estimateSize: () => 28,\n overscan: 10,\n });\n\n const items = virtualizer.getVirtualItems();\n\n const scrollToElement = useCallback(\n ({ errorNode, expandTo }: ErrorItem) => {\n const index = flatItems.findIndex((flatItem) => flatItem.id === errorNode.id);\n if (index === -1) {\n expandTo((nodeId) => expandNode(nodeId, true));\n scrollToNode.current = errorNode.id;\n return;\n }\n virtualizer.scrollToIndex(index, { align: \"end\" });\n },\n [expandNode, flatItems, virtualizer],\n );\n\n useEffect(() => {\n if (scrollToNode.current === undefined) {\n return;\n }\n const index = flatItems.findIndex((flatItem) => flatItem.id === scrollToNode.current);\n if (index === -1) {\n return;\n }\n virtualizer.scrollToIndex(index, { align: \"end\" });\n scrollToNode.current = undefined;\n }, [flatItems, virtualizer]);\n\n const errorRendererProps: TreeErrorRendererProps = {\n treeLabel,\n errorList,\n scrollToElement,\n getHierarchyLevelDetails,\n onFilterClick,\n reloadTree,\n };\n\n return (\n <LocalizationContextProvider localizedStrings={localizedStrings}>\n {errorRenderer ? errorRenderer(errorRendererProps) : <TreeErrorRenderer {...errorRendererProps} />}\n <div style={{ height: \"100%\", width: \"100%\", overflowY: \"auto\" }} ref={parentRef}>\n <Tree.Root style={{ height: virtualizer.getTotalSize(), minHeight: \"100%\", width: \"100%\", position: \"relative\", overflow: \"hidden\" }}>\n {items.map((virtualizedItem) => {\n const item = flatItems[virtualizedItem.index];\n const selected = isNodeSelected?.(item.id) ?? false;\n return (\n <VirtualTreeItem\n {...treeProps}\n onNodeClick={handleNodeClick}\n onNodeKeyDown={handleKeyDown}\n ref={virtualizer.measureElement}\n start={virtualizedItem.start}\n expandNode={expandNode}\n item={item}\n key={virtualizedItem.key}\n data-index={virtualizedItem.index}\n reloadTree={reloadTree}\n selected={selected}\n getEditingProps={getEditingProps}\n />\n );\n })}\n </Tree.Root>\n </div>\n </LocalizationContextProvider>\n );\n}\n\ntype VirtualTreeItemProps = Omit<TreeNodeRendererProps, \"node\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\"> & {\n start: number;\n item: FlatTreeItem;\n getEditingProps?: TreeRendererOwnProps[\"getEditingProps\"];\n};\n\nconst VirtualTreeItem = memo(\n forwardRef<HTMLElement, VirtualTreeItemProps>(function VirtualTreeItem(\n {\n start,\n item,\n getDecorations,\n getMenuActions,\n getInlineActions,\n getLabel,\n getSublabel,\n expandNode,\n reloadTree,\n onNodeClick,\n onNodeKeyDown,\n getEditingProps,\n ...props\n },\n forwardedRef,\n ) {\n const style: CSSProperties = useMemo(\n () => ({\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n transform: `translateY(${start}px)`,\n willChange: \"transform\",\n }),\n [start],\n );\n\n if (isPlaceholderItem(item)) {\n return <PlaceholderNode {...props} ref={forwardedRef} style={style} aria-level={item.level} aria-posinset={1} aria-setsize={1} />;\n }\n\n const editingProps = getEditingProps?.(item.node);\n return (\n <RenameContextProvider onLabelChanged={editingProps?.onLabelChanged}>\n <StrataKitTreeNodeRenderer\n {...props}\n ref={forwardedRef}\n style={style}\n aria-level={item.level}\n aria-posinset={item.posInLevel}\n aria-setsize={item.levelSize}\n node={item.node}\n expandNode={expandNode}\n reloadTree={reloadTree}\n getDecorations={getDecorations}\n getMenuActions={getMenuActions}\n getInlineActions={getInlineActions}\n getLabel={getLabel}\n getSublabel={getSublabel}\n onNodeClick={onNodeClick}\n onNodeKeyDown={onNodeKeyDown}\n />\n </RenameContextProvider>\n );\n }),\n);\n\nfunction noopSelectNodes() {}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/presentation-hierarchies-react",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.35",
|
|
4
4
|
"description": "React components based on `@itwin/presentation-hierarchies`",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"react-error-boundary": "^4.0.13",
|
|
45
45
|
"rxjs": "^7.8.1",
|
|
46
46
|
"@itwin/presentation-hierarchies": "^2.0.0-alpha.4",
|
|
47
|
-
"@itwin/
|
|
48
|
-
"@itwin/
|
|
47
|
+
"@itwin/unified-selection": "^1.5.1-alpha.1",
|
|
48
|
+
"@itwin/presentation-shared": "^2.0.0-alpha.2"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@stratakit/foundations": "^0.2 || ^0.3",
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@itwin/build-tools": "^5.1.1",
|
|
74
74
|
"@itwin/eslint-plugin": "5.1.0",
|
|
75
|
-
"@stratakit/foundations": "^0.3.
|
|
76
|
-
"@stratakit/bricks": "^0.4.
|
|
77
|
-
"@stratakit/structures": "^0.4.
|
|
75
|
+
"@stratakit/foundations": "^0.3.5",
|
|
76
|
+
"@stratakit/bricks": "^0.4.5",
|
|
77
|
+
"@stratakit/structures": "^0.4.5",
|
|
78
78
|
"@stratakit/icons": "^0.1.5",
|
|
79
79
|
"@testing-library/dom": "^10.4.0",
|
|
80
80
|
"@testing-library/react": "^16.2.0",
|