@itwin/appui-react 5.9.1 → 5.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/lib/appui-react/toolbar/useActiveToolIdSynchedItems.d.ts +5 -5
- package/lib/appui-react/toolbar/useActiveToolIdSynchedItems.d.ts.map +1 -1
- package/lib/appui-react/toolbar/useActiveToolIdSynchedItems.js +23 -35
- package/lib/appui-react/toolbar/useActiveToolIdSynchedItems.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Change Log - @itwin/appui-react
|
|
2
2
|
|
|
3
|
+
## 5.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- bdfb8fe: Updated `ToolbarComposer` component to highlight group items that contain an active toolbar item.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- @itwin/components-react@5.10.0
|
|
12
|
+
- @itwin/core-react@5.10.0
|
|
13
|
+
- @itwin/imodel-components-react@5.10.0
|
|
14
|
+
|
|
3
15
|
## 5.9.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { BeEvent } from "@itwin/core-bentley";
|
|
2
|
-
|
|
2
|
+
interface Item {
|
|
3
3
|
id: string;
|
|
4
4
|
isActive?: boolean;
|
|
5
|
-
}
|
|
6
|
-
|
|
5
|
+
}
|
|
6
|
+
type ActiveToolIdSynchedItem<T> = Item | (Item & {
|
|
7
7
|
items: T[];
|
|
8
|
-
};
|
|
8
|
+
});
|
|
9
9
|
interface ActiveToolIdSynchedHost {
|
|
10
10
|
activeToolId: string;
|
|
11
11
|
onToolActivatedEvent: BeEvent<(args: {
|
|
@@ -20,6 +20,6 @@ interface ActiveToolIdSynchedHost {
|
|
|
20
20
|
* @returns Up to date itemsToSynch.
|
|
21
21
|
* @internal
|
|
22
22
|
*/
|
|
23
|
-
export declare function useActiveToolIdSynchedItems<T extends ActiveToolIdSynchedItem<T>>(itemsToSynch:
|
|
23
|
+
export declare function useActiveToolIdSynchedItems<T extends ActiveToolIdSynchedItem<T>>(itemsToSynch: T[], syncHost: ActiveToolIdSynchedHost): T[];
|
|
24
24
|
export {};
|
|
25
25
|
//# sourceMappingURL=useActiveToolIdSynchedItems.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveToolIdSynchedItems.d.ts","sourceRoot":"","sources":["../../../src/appui-react/toolbar/useActiveToolIdSynchedItems.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"useActiveToolIdSynchedItems.d.ts","sourceRoot":"","sources":["../../../src/appui-react/toolbar/useActiveToolIdSynchedItems.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGnD,UAAU,IAAI;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,KAAK,uBAAuB,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,GAAG;IAAE,KAAK,EAAE,CAAC,EAAE,CAAA;CAAE,CAAC,CAAC;AAEjE,UAAU,uBAAuB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC,CAAC;CACnE;AAgCD;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,CAAC,SAAS,uBAAuB,CAAC,CAAC,CAAC,EACpC,YAAY,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,uBAAuB,GAAG,CAAC,EAAE,CAW3D"}
|
|
@@ -3,41 +3,29 @@
|
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import * as React from "react";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
import { produce } from "immer";
|
|
7
|
+
function updateActiveItems(items, toolId) {
|
|
8
|
+
return produce(items, (draft) => {
|
|
9
|
+
// Iterative DFS with ancestor backtracking.
|
|
10
|
+
const stack = draft.map((item) => [item, []]);
|
|
11
|
+
while (stack.length > 0) {
|
|
12
|
+
const [current, ancestors] = stack.pop();
|
|
13
|
+
const isActive = current.id === toolId;
|
|
14
|
+
current.isActive = isActive;
|
|
15
|
+
if ("items" in current) {
|
|
16
|
+
for (const child of current.items) {
|
|
17
|
+
stack.push([child, [...ancestors, current]]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!isActive)
|
|
21
|
+
continue;
|
|
22
|
+
// Mark ancestors of active item as active.
|
|
23
|
+
for (const ancestor of ancestors) {
|
|
24
|
+
ancestor.isActive = true;
|
|
25
|
+
}
|
|
17
26
|
}
|
|
18
|
-
return ((item.isActive && item.id !== toolId) ||
|
|
19
|
-
(!item.isActive && item.id === toolId));
|
|
20
27
|
});
|
|
21
28
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Recursively updates the isActive for the tools and only activate
|
|
24
|
-
* the one with the id equal to toolId.
|
|
25
|
-
* @param items list of items to update
|
|
26
|
-
* @param toolId toolId to check
|
|
27
|
-
* @returns updated list of items
|
|
28
|
-
*/
|
|
29
|
-
function refreshItems(items, toolId) {
|
|
30
|
-
return items.map((item) => "items" in item
|
|
31
|
-
? {
|
|
32
|
-
...item,
|
|
33
|
-
isActive: item.id === toolId,
|
|
34
|
-
items: refreshItems(item.items, toolId),
|
|
35
|
-
}
|
|
36
|
-
: {
|
|
37
|
-
...item,
|
|
38
|
-
isActive: item.id === toolId,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
29
|
/**
|
|
42
30
|
* Synch the provided items to only show the item with id === activeToolId to be
|
|
43
31
|
* active, as determined by the UiFramework.frontstages.activeToolId.
|
|
@@ -47,11 +35,11 @@ function refreshItems(items, toolId) {
|
|
|
47
35
|
* @internal
|
|
48
36
|
*/
|
|
49
37
|
export function useActiveToolIdSynchedItems(itemsToSynch, syncHost) {
|
|
50
|
-
const [items, setItems] = React.useState(() =>
|
|
38
|
+
const [items, setItems] = React.useState(() => updateActiveItems(itemsToSynch, syncHost.activeToolId));
|
|
51
39
|
React.useEffect(() => {
|
|
52
|
-
setItems(
|
|
40
|
+
setItems(updateActiveItems(itemsToSynch, syncHost.activeToolId));
|
|
53
41
|
return syncHost.onToolActivatedEvent.addListener(({ toolId }) => {
|
|
54
|
-
setItems((current) =>
|
|
42
|
+
setItems((current) => updateActiveItems(current, toolId));
|
|
55
43
|
});
|
|
56
44
|
}, [itemsToSynch, syncHost.activeToolId, syncHost.onToolActivatedEvent]);
|
|
57
45
|
return items;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveToolIdSynchedItems.js","sourceRoot":"","sources":["../../../src/appui-react/toolbar/useActiveToolIdSynchedItems.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useActiveToolIdSynchedItems.js","sourceRoot":"","sources":["../../../src/appui-react/toolbar/useActiveToolIdSynchedItems.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAchC,SAAS,iBAAiB,CACxB,KAAU,EACV,MAAc;IAEd,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QAC9B,4CAA4C;QAC5C,MAAM,KAAK,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AQ,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,YAAY,EAAE,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAAC,CAAC;IACzE,OAAO,KAAK,CAAC;AACf,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 *--------------------------------------------------------------------------------------------*/\nimport * as React from \"react\";\nimport type { BeEvent } from \"@itwin/core-bentley\";\nimport { produce } from \"immer\";\n\ninterface Item {\n id: string;\n isActive?: boolean;\n}\n\ntype ActiveToolIdSynchedItem<T> = Item | (Item & { items: T[] });\n\ninterface ActiveToolIdSynchedHost {\n activeToolId: string;\n onToolActivatedEvent: BeEvent<(args: { toolId: string }) => void>;\n}\n\nfunction updateActiveItems<T extends ActiveToolIdSynchedItem<T>>(\n items: T[],\n toolId: string\n) {\n return produce(items, (draft) => {\n // Iterative DFS with ancestor backtracking.\n const stack = draft.map((item) => [item, [] as typeof draft] as const);\n\n while (stack.length > 0) {\n const [current, ancestors] = stack.pop()!;\n\n const isActive = current.id === toolId;\n current.isActive = isActive;\n\n if (\"items\" in current) {\n for (const child of current.items) {\n stack.push([child, [...ancestors, current]]);\n }\n }\n\n if (!isActive) continue;\n\n // Mark ancestors of active item as active.\n for (const ancestor of ancestors) {\n ancestor.isActive = true;\n }\n }\n });\n}\n\n/**\n * Synch the provided items to only show the item with id === activeToolId to be\n * active, as determined by the UiFramework.frontstages.activeToolId.\n * @param itemsToSynch List of items to keep in synch.\n * @param syncHost Source of information to synch to (UiFramework.frontstages)\n * @returns Up to date itemsToSynch.\n * @internal\n */\nexport function useActiveToolIdSynchedItems<\n T extends ActiveToolIdSynchedItem<T>\n>(itemsToSynch: T[], syncHost: ActiveToolIdSynchedHost): T[] {\n const [items, setItems] = React.useState<T[]>(() =>\n updateActiveItems(itemsToSynch, syncHost.activeToolId)\n );\n React.useEffect(() => {\n setItems(updateActiveItems(itemsToSynch, syncHost.activeToolId));\n return syncHost.onToolActivatedEvent.addListener(({ toolId }) => {\n setItems((current) => updateActiveItems(current, toolId));\n });\n }, [itemsToSynch, syncHost.activeToolId, syncHost.onToolActivatedEvent]);\n return items;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/appui-react",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.10.0",
|
|
4
4
|
"description": "A react component library for AppUI framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./lib/appui-react.d.ts",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"react-dom": "^18.0.0",
|
|
46
46
|
"react-redux": "^7.2.2 || ^8.0.0 || ^9.0.0",
|
|
47
47
|
"redux": "^4.1.0 || ^5.0.0",
|
|
48
|
-
"@itwin/components-react": "5.
|
|
49
|
-
"@itwin/core-react": "5.
|
|
50
|
-
"@itwin/imodel-components-react": "5.
|
|
48
|
+
"@itwin/components-react": "5.10.0",
|
|
49
|
+
"@itwin/core-react": "5.10.0",
|
|
50
|
+
"@itwin/imodel-components-react": "5.10.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@itwin/appui-abstract": "rc",
|
|
@@ -91,9 +91,9 @@
|
|
|
91
91
|
"typescript": "~5.6.2",
|
|
92
92
|
"upath": "^2.0.1",
|
|
93
93
|
"vitest": "^3.0.6",
|
|
94
|
-
"@itwin/
|
|
95
|
-
"@itwin/core-react": "5.
|
|
96
|
-
"@itwin/components-react": "5.
|
|
94
|
+
"@itwin/components-react": "5.10.0",
|
|
95
|
+
"@itwin/core-react": "5.10.0",
|
|
96
|
+
"@itwin/imodel-components-react": "5.10.0"
|
|
97
97
|
},
|
|
98
98
|
"dependencies": {
|
|
99
99
|
"@itwin/itwinui-icons-react": "^2.8.0",
|