@geode/opengeodeweb-front 10.44.0-rc.3 → 10.44.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/.build/server/utils/microservices.js +9 -85
  2. package/.build/server/utils/microservices_process.js +85 -0
  3. package/app/components/ClippingPlanes.vue +16 -82
  4. package/app/components/DragAndDrop.vue +1 -74
  5. package/app/components/ThresholdCard.vue +205 -0
  6. package/app/components/ThresholdFilter.vue +77 -216
  7. package/app/components/ViewToolbar.vue +15 -231
  8. package/app/components/Viewer/EdgedCurve/SpecificEdgesColoring.vue +209 -0
  9. package/app/components/Viewer/EdgedCurve/SpecificEdgesOptions.vue +3 -191
  10. package/app/components/Viewer/Generic/Mesh/CellsColoring.vue +228 -0
  11. package/app/components/Viewer/Generic/Mesh/CellsOptions.vue +3 -210
  12. package/app/components/Viewer/Generic/Mesh/EdgesColoring.vue +211 -0
  13. package/app/components/Viewer/Generic/Mesh/EdgesOptions.vue +3 -192
  14. package/app/components/Viewer/Generic/Mesh/PolygonsColoring.vue +234 -0
  15. package/app/components/Viewer/Generic/Mesh/PolygonsOptions.vue +3 -215
  16. package/app/components/Viewer/Generic/Mesh/PolyhedraColoring.vue +221 -0
  17. package/app/components/Viewer/Generic/Mesh/PolyhedraOptions.vue +3 -203
  18. package/app/components/Viewer/Generic/Model/ComponentPointsOptions.vue +2 -18
  19. package/app/components/Viewer/Generic/Model/CornerComponentOptions.vue +145 -0
  20. package/app/components/Viewer/Generic/Model/CornersOptions.vue +13 -294
  21. package/app/components/Viewer/Generic/Model/CornersTypeOptions.vue +173 -0
  22. package/app/components/Viewer/Generic/Model/LineComponentOptions.vue +218 -0
  23. package/app/components/Viewer/Generic/Model/LinesOptions.vue +13 -425
  24. package/app/components/Viewer/Generic/Model/LinesTypeOptions.vue +229 -0
  25. package/app/components/Viewer/Options/AttributeSelector.vue +26 -133
  26. package/app/components/Viewer/Options/ColoringTypeSelector.vue +36 -74
  27. package/app/components/Viewer/Options/NoDataColorInfo.vue +56 -0
  28. package/app/components/Viewer/Solid/SpecificPolyhedraColoring.vue +217 -0
  29. package/app/components/Viewer/Solid/SpecificPolyhedraOptions.vue +4 -199
  30. package/app/components/Viewer/Surface/PolygonsColoring.vue +231 -0
  31. package/app/components/Viewer/Surface/PolygonsOptions.vue +3 -213
  32. package/app/composables/attribute_selector.ts +126 -0
  33. package/app/composables/clipping_slices.ts +166 -0
  34. package/app/composables/view_toolbar_options.ts +126 -0
  35. package/app/composables/view_toolbar_tool_options.ts +115 -0
  36. package/app/composables/view_toolbar_tools.ts +108 -0
  37. package/app/composables/virtual_tree.ts +20 -138
  38. package/app/composables/virtual_tree_flatten.ts +86 -0
  39. package/app/composables/virtual_tree_types.ts +81 -0
  40. package/app/stores/app.ts +8 -55
  41. package/app/stores/app_helpers/registry.ts +69 -0
  42. package/app/stores/menu.ts +1 -124
  43. package/app/stores/menu_helpers/menus_data.ts +127 -0
  44. package/app/stores/viewer.ts +17 -78
  45. package/app/stores/viewer_helpers/actions.ts +68 -0
  46. package/app/stores/viewer_helpers/request.ts +61 -0
  47. package/app/utils/clipping_planes.ts +4 -132
  48. package/app/utils/clipping_planes_scene.ts +131 -0
  49. package/app/utils/coloring_styles.ts +101 -0
  50. package/app/utils/default_styles/mesh_components.ts +168 -0
  51. package/app/utils/default_styles/meshes.ts +13 -153
  52. package/app/utils/default_styles/model_components.ts +170 -0
  53. package/app/utils/default_styles/models.ts +16 -153
  54. package/app/utils/drag_and_drop.ts +80 -0
  55. package/app/utils/model_component_coloring.ts +46 -0
  56. package/app/utils/threshold.ts +33 -0
  57. package/app/utils/threshold_sources.ts +51 -0
  58. package/internal/stores/data_style/mesh/cells/cell.ts +27 -150
  59. package/internal/stores/data_style/mesh/cells/cell_attribute.ts +74 -0
  60. package/internal/stores/data_style/mesh/cells/cell_config.ts +152 -0
  61. package/internal/stores/data_style/mesh/cells/vertex.ts +26 -157
  62. package/internal/stores/data_style/mesh/cells/vertex_attribute.ts +80 -0
  63. package/internal/stores/data_style/mesh/cells/vertex_config.ts +152 -0
  64. package/internal/stores/data_style/mesh/edges/edge.ts +27 -150
  65. package/internal/stores/data_style/mesh/edges/edge_attribute.ts +74 -0
  66. package/internal/stores/data_style/mesh/edges/edge_config.ts +152 -0
  67. package/internal/stores/data_style/mesh/edges/vertex.ts +26 -157
  68. package/internal/stores/data_style/mesh/edges/vertex_attribute.ts +80 -0
  69. package/internal/stores/data_style/mesh/edges/vertex_config.ts +152 -0
  70. package/internal/stores/data_style/mesh/points/vertex.ts +26 -157
  71. package/internal/stores/data_style/mesh/points/vertex_attribute.ts +80 -0
  72. package/internal/stores/data_style/mesh/points/vertex_config.ts +152 -0
  73. package/internal/stores/data_style/mesh/polygons/polygon.ts +27 -152
  74. package/internal/stores/data_style/mesh/polygons/polygon_attribute.ts +80 -0
  75. package/internal/stores/data_style/mesh/polygons/polygon_config.ts +148 -0
  76. package/internal/stores/data_style/mesh/polygons/vertex.ts +26 -157
  77. package/internal/stores/data_style/mesh/polygons/vertex_attribute.ts +80 -0
  78. package/internal/stores/data_style/mesh/polygons/vertex_config.ts +152 -0
  79. package/internal/stores/data_style/mesh/polyhedra/polyhedron.ts +27 -160
  80. package/internal/stores/data_style/mesh/polyhedra/polyhedron_attribute.ts +82 -0
  81. package/internal/stores/data_style/mesh/polyhedra/polyhedron_config.ts +157 -0
  82. package/internal/stores/data_style/mesh/polyhedra/vertex.ts +26 -157
  83. package/internal/stores/data_style/mesh/polyhedra/vertex_attribute.ts +80 -0
  84. package/internal/stores/data_style/mesh/polyhedra/vertex_config.ts +152 -0
  85. package/internal/stores/data_style/model/blocks/apply_coloring.ts +173 -0
  86. package/internal/stores/data_style/model/blocks/coloring_groups.ts +18 -0
  87. package/internal/stores/data_style/model/blocks/index.ts +12 -140
  88. package/internal/stores/data_style/model/common.ts +10 -119
  89. package/internal/stores/data_style/model/common_mutations.ts +184 -0
  90. package/internal/stores/data_style/model/lines/apply_coloring.ts +154 -0
  91. package/internal/stores/data_style/model/lines/coloring_groups.ts +18 -0
  92. package/internal/stores/data_style/model/lines/index.ts +10 -134
  93. package/internal/stores/data_style/model/surfaces/apply_coloring.ts +186 -0
  94. package/internal/stores/data_style/model/surfaces/coloring_groups.ts +18 -0
  95. package/internal/stores/data_style/model/surfaces/index.ts +16 -160
  96. package/internal/stores/data_style/model/visibility.ts +3 -156
  97. package/internal/stores/data_style/model/visibility_dispatch.ts +160 -0
  98. package/internal/stores/data_style/state.ts +1 -181
  99. package/internal/stores/data_style/state_shared.ts +191 -0
  100. package/internal/stores/hybrid_viewer/camera.ts +7 -161
  101. package/internal/stores/hybrid_viewer/camera_helpers.ts +120 -0
  102. package/internal/stores/hybrid_viewer/camera_orientation.ts +60 -0
  103. package/internal/stores/hybrid_viewer/filters.ts +54 -11
  104. package/package.json +1 -1
  105. package/server/utils/microservices.ts +10 -109
  106. package/server/utils/microservices_process.ts +127 -0
@@ -0,0 +1,115 @@
1
+ import CameraBookmarkIcon from "@ogw_front/assets/viewer_svgs/camera-bookmark.svg";
2
+ import type { ViewToolbarTools } from "@ogw_front/composables/view_toolbar_tools";
3
+
4
+ interface CameraOptionAction {
5
+ title?: string;
6
+ testId: string;
7
+ tooltip?: string;
8
+ icon: string;
9
+ iconSize?: number;
10
+ color?: string;
11
+ action?: () => void;
12
+ menu?: CameraOptionAction[];
13
+ }
14
+
15
+ // The buttons opening a panel
16
+ function panelOptions(tools: ViewToolbarTools): CameraOptionAction[] {
17
+ return [
18
+ {
19
+ testId: "cameraOrientationButton",
20
+ tooltip: "Camera orientation",
21
+ icon: "mdi-rotate-3d",
22
+ action: (): void => {
23
+ tools.toggleTool(tools.showCameraOrientation);
24
+ },
25
+ },
26
+ {
27
+ testId: "cameraManagerButton",
28
+ tooltip: "Manage camera positions",
29
+ icon: CameraBookmarkIcon,
30
+ iconSize: 34,
31
+ action: (): void => {
32
+ tools.toggleTool(tools.showCameraManager);
33
+ },
34
+ },
35
+ {
36
+ testId: "screenshotButton",
37
+ tooltip: "Take a screenshot",
38
+ icon: "mdi-camera",
39
+ action: (): void => {
40
+ tools.toggleTool(tools.showScreenshot);
41
+ },
42
+ },
43
+ ];
44
+ }
45
+
46
+ // The buttons opening the scene controls
47
+ function controlOptions(tools: ViewToolbarTools): CameraOptionAction[] {
48
+ return [
49
+ {
50
+ testId: "zScalingButton",
51
+ tooltip: "Z Scaling Control",
52
+ icon: "mdi-sort",
53
+ action: (): void => {
54
+ tools.toggleTool(tools.showZScaling);
55
+ },
56
+ },
57
+ {
58
+ testId: "clippingPlanesButton",
59
+ tooltip: "Clipping Planes",
60
+ icon: "mdi-content-cut",
61
+ color: tools.showClippingPlanes.value ? "primary" : undefined,
62
+ action: (): void => {
63
+ tools.toggleTool(tools.showClippingPlanes);
64
+ },
65
+ },
66
+ ];
67
+ }
68
+
69
+ // The buttons opening the filters
70
+ function filterOptions(tools: ViewToolbarTools): CameraOptionAction[] {
71
+ return [
72
+ {
73
+ testId: "shrinkFilterButton",
74
+ tooltip: "Shrink Filter",
75
+ icon: "mdi-arrow-collapse-all",
76
+ color: tools.showShrinkFilter.value ? "primary" : undefined,
77
+ action: (): void => {
78
+ tools.toggleTool(tools.showShrinkFilter);
79
+ },
80
+ },
81
+ {
82
+ testId: "explodeFilterButton",
83
+ tooltip: "Exploded View",
84
+ icon: "mdi-arrow-expand-all",
85
+ color: tools.showExplodeFilter.value ? "primary" : undefined,
86
+ action: (): void => {
87
+ tools.toggleTool(tools.showExplodeFilter);
88
+ },
89
+ },
90
+ {
91
+ testId: "thresholdFilterButton",
92
+ tooltip: "Threshold Filter",
93
+ icon: "mdi-filter-variant",
94
+ color: tools.showThresholdFilter.value ? "primary" : undefined,
95
+ action: (): void => {
96
+ tools.toggleTool(tools.showThresholdFilter);
97
+ },
98
+ },
99
+ ];
100
+ }
101
+
102
+ function rulerOption(tools: ViewToolbarTools): CameraOptionAction {
103
+ return {
104
+ testId: "rulerButton",
105
+ tooltip: "Ruler",
106
+ icon: "mdi-ruler",
107
+ color: tools.showRuler.value ? "primary" : undefined,
108
+ action: (): void => {
109
+ tools.toggleTool(tools.showRuler);
110
+ },
111
+ };
112
+ }
113
+
114
+ export { controlOptions, filterOptions, panelOptions, rulerOption };
115
+ export type { CameraOptionAction };
@@ -0,0 +1,108 @@
1
+ import type { PickedFieldType } from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
2
+ import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
3
+ import { useViewerStore } from "@ogw_front/stores/viewer";
4
+
5
+ interface ToolRefs {
6
+ showScreenshot: Ref<boolean>;
7
+ showCameraManager: Ref<boolean>;
8
+ showCameraOrientation: Ref<boolean>;
9
+ showZScaling: Ref<boolean>;
10
+ showClippingPlanes: Ref<boolean>;
11
+ showShrinkFilter: Ref<boolean>;
12
+ showExplodeFilter: Ref<boolean>;
13
+ showThresholdFilter: Ref<boolean>;
14
+ showRuler: Ref<boolean>;
15
+ }
16
+
17
+ interface ViewToolbarTools extends ToolRefs {
18
+ is_picking: Ref<boolean>;
19
+ is_zoom_box_active: Ref<boolean>;
20
+ stopHoverHighlight: () => void;
21
+ toggleTool: (toolRef: Ref<boolean>) => void;
22
+ toggleHoverHighlight: (fieldType: PickedFieldType) => void;
23
+ }
24
+
25
+ function createToolRefs(): ToolRefs {
26
+ return {
27
+ showScreenshot: ref<boolean>(false),
28
+ showCameraManager: ref<boolean>(false),
29
+ showCameraOrientation: ref<boolean>(false),
30
+ showZScaling: ref<boolean>(false),
31
+ showClippingPlanes: ref<boolean>(false),
32
+ showShrinkFilter: ref<boolean>(false),
33
+ showExplodeFilter: ref<boolean>(false),
34
+ showThresholdFilter: ref<boolean>(false),
35
+ showRuler: ref<boolean>(false),
36
+ };
37
+ }
38
+
39
+ function exclusiveTools(toolRefs: ToolRefs, pickingTools: Ref<boolean>[]): Ref<boolean>[] {
40
+ return [
41
+ toolRefs.showCameraOrientation,
42
+ toolRefs.showCameraManager,
43
+ toolRefs.showScreenshot,
44
+ toolRefs.showZScaling,
45
+ toolRefs.showClippingPlanes,
46
+ toolRefs.showShrinkFilter,
47
+ toolRefs.showExplodeFilter,
48
+ toolRefs.showThresholdFilter,
49
+ toolRefs.showRuler,
50
+ ...pickingTools,
51
+ ];
52
+ }
53
+
54
+ // The toolbar tools are exclusive: opening one closes the others
55
+ function useViewToolbarTools(): ViewToolbarTools {
56
+ const hybridViewerStore = useHybridViewerStore();
57
+ const viewerStore = useViewerStore();
58
+ const { is_picking, is_zoom_box_active } = storeToRefs(hybridViewerStore);
59
+ const { picking_mode } = storeToRefs(viewerStore);
60
+ const toolRefs = createToolRefs();
61
+ const allTools = exclusiveTools(toolRefs, [is_picking, is_zoom_box_active, picking_mode]);
62
+
63
+ function stopHoverHighlight(): void {
64
+ hybridViewerStore.is_hover_highlight = false;
65
+ hybridViewerStore.clearHoverHighlight();
66
+ }
67
+
68
+ function closeAllToolsExcept(toolRef: Ref<boolean>): void {
69
+ for (const tool of allTools) {
70
+ if (tool !== toolRef) {
71
+ tool.value = false;
72
+ }
73
+ }
74
+ if (toolRef !== toolRefs.showRuler) {
75
+ void nextTick(stopHoverHighlight);
76
+ }
77
+ }
78
+
79
+ function toggleTool(toolRef: Ref<boolean>): void {
80
+ closeAllToolsExcept(toolRef);
81
+ toolRef.value = !toolRef.value;
82
+ }
83
+
84
+ function toggleHoverHighlight(fieldType: PickedFieldType): void {
85
+ const activate =
86
+ !hybridViewerStore.is_hover_highlight ||
87
+ hybridViewerStore.hover_highlight_field_type !== fieldType;
88
+ closeAllToolsExcept(toolRefs.showRuler);
89
+ if (activate) {
90
+ hybridViewerStore.is_hover_highlight = true;
91
+ hybridViewerStore.hover_highlight_field_type = fieldType;
92
+ } else {
93
+ stopHoverHighlight();
94
+ }
95
+ }
96
+
97
+ return {
98
+ ...toolRefs,
99
+ is_picking,
100
+ is_zoom_box_active,
101
+ stopHoverHighlight,
102
+ toggleTool,
103
+ toggleHoverHighlight,
104
+ };
105
+ }
106
+
107
+ export { useViewToolbarTools };
108
+ export type { ViewToolbarTools };
@@ -1,72 +1,14 @@
1
- import type { Ref } from "vue";
2
-
3
- // Same shape as Vue's MaybeRefOrGetter<T>, kept as a local alias for readability at call sites.
4
- type ReadonlyMaybeRefOrGetter<Value> = Value | Ref<Value> | (() => Value);
5
-
6
- type TreeItem = Record<string, unknown>;
7
-
8
- interface ItemPropsConfig {
9
- value: string;
10
- title: string;
11
- children: string;
12
- height: number;
13
- [key: string]: unknown;
14
- }
15
-
16
- interface SelectionConfig {
17
- selectable: boolean;
18
- strategy: string;
19
- [key: string]: unknown;
20
- }
21
-
22
- interface VirtualTreeProps {
23
- readonly items?: readonly TreeItem[];
24
- readonly opened?: readonly unknown[];
25
- readonly selected?: readonly unknown[];
26
- readonly active?: readonly unknown[];
27
- readonly itemProps?: Partial<ItemPropsConfig>;
28
- readonly selection?: Partial<SelectionConfig>;
29
- readonly search?: string;
30
- readonly customFilter?: (id: unknown, search: string, context: { raw: TreeItem }) => boolean;
31
- }
32
-
33
- interface DisplayItem {
34
- raw: TreeItem;
35
- id: unknown;
36
- depth: number;
37
- isOpen: boolean;
38
- isActive: boolean;
39
- isLeaf: boolean;
40
- }
41
-
42
- type EmitFn = (event: string, ...args: readonly unknown[]) => void;
43
-
44
- interface UseVirtualTreeReturn {
45
- actualItemProps: ComputedRef<ItemPropsConfig>;
46
- actualSelection: ComputedRef<SelectionConfig>;
47
- displayItems: ComputedRef<DisplayItem[]>;
48
- toggleOpen: (item: TreeItem) => void;
49
- toggleSelect: (item: TreeItem) => void;
50
- isSelected: (item: TreeItem) => boolean;
51
- getIndeterminate: (item: TreeItem) => boolean;
52
- }
53
-
54
- // Real runtime check (rather than an `as TreeItem[]` cast) for the duck-typed "children" field:
55
- // Item shapes vary across callers (treeview groups, model component/collection groups, ...), so
56
- // This only verifies it is actually an array, same as the assumption the old cast silently made.
57
- function isTreeItemArray(value: unknown): value is TreeItem[] {
58
- return Array.isArray(value);
59
- }
60
-
61
- // Extracted so we never call String() directly on a value typed as `unknown` (ids and titles can
62
- // Be anything at runtime): only stringify primitives that have a sane toString, and fall back to
63
- // "" for anything else instead of risking "[object Object]".
64
- function toDisplayString(value: unknown): string {
65
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
66
- return String(value);
67
- }
68
- return "";
69
- }
1
+ import {
2
+ type EmitFn,
3
+ type ItemPropsConfig,
4
+ type ReadonlyMaybeRefOrGetter,
5
+ type SelectionConfig,
6
+ type TreeItem,
7
+ type UseVirtualTreeReturn,
8
+ type VirtualTreeProps,
9
+ isTreeItemArray,
10
+ } from "./virtual_tree_types";
11
+ import { flattenTree } from "./virtual_tree_flatten";
70
12
 
71
13
  function useVirtualTree(
72
14
  propsIn: ReadonlyMaybeRefOrGetter<VirtualTreeProps>,
@@ -171,73 +113,6 @@ function useVirtualTree(
171
113
  emit("update:selected", [...newSelected]);
172
114
  }
173
115
 
174
- function matchesSearch(item: TreeItem, id: unknown, search: string): boolean {
175
- const { customFilter } = props.value;
176
- if (customFilter) {
177
- return customFilter(id, search, { raw: item });
178
- }
179
- const lowerSearch = search.toLowerCase();
180
- return (
181
- toDisplayString(item[actualItemProps.value.title]).toLowerCase().includes(lowerSearch) ||
182
- toDisplayString(id).toLowerCase().includes(lowerSearch)
183
- );
184
- }
185
-
186
- function flattenTree(itemsList: readonly TreeItem[], depth = 0): DisplayItem[] {
187
- const { search } = props.value;
188
- const result: DisplayItem[] = [];
189
-
190
- for (const item of itemsList) {
191
- const id = item[actualItemProps.value.value];
192
- const children = getChildrenOf(item);
193
- const hasChildren = Boolean(children && children.length > 0);
194
-
195
- const isOpen = openedSet.value.has(id);
196
- const isActive = activeSet.value.has(id);
197
-
198
- if (search !== undefined && search !== "") {
199
- const matches = matchesSearch(item, id, search);
200
-
201
- if (hasChildren) {
202
- const subtree = flattenTree(children ?? [], depth + 1);
203
- if (subtree.length === 0 && !matches) {
204
- continue;
205
- }
206
-
207
- result.push({
208
- raw: item,
209
- id,
210
- depth,
211
- isOpen,
212
- isActive,
213
- isLeaf: false,
214
- });
215
- if (isOpen) {
216
- result.push(...subtree);
217
- }
218
- continue;
219
- }
220
- if (!matches) {
221
- continue;
222
- }
223
- }
224
-
225
- result.push({
226
- raw: item,
227
- id,
228
- depth,
229
- isOpen,
230
- isActive,
231
- isLeaf: !hasChildren,
232
- });
233
-
234
- if (isOpen && hasChildren) {
235
- result.push(...flattenTree(children ?? [], depth + 1));
236
- }
237
- }
238
- return result;
239
- }
240
-
241
116
  function collectNonLeafIds(itemsList: readonly TreeItem[]): unknown[] {
242
117
  const allIds: unknown[] = [];
243
118
  for (const item of itemsList) {
@@ -249,7 +124,8 @@ function useVirtualTree(
249
124
  return allIds;
250
125
  }
251
126
 
252
- const displayItems = computed(() => flattenTree(props.value.items ?? []));
127
+ const flattenContext = { props, actualItemProps, openedSet, activeSet, getChildrenOf };
128
+ const displayItems = computed(() => flattenTree(flattenContext, props.value.items ?? []));
253
129
 
254
130
  watch(
255
131
  () => props.value.search,
@@ -274,5 +150,11 @@ function useVirtualTree(
274
150
  };
275
151
  }
276
152
 
153
+ export type {
154
+ DisplayItem,
155
+ EmitFn,
156
+ ItemPropsConfig,
157
+ SelectionConfig,
158
+ TreeItem,
159
+ } from "./virtual_tree_types";
277
160
  export { useVirtualTree };
278
- export type { TreeItem, ItemPropsConfig, SelectionConfig, DisplayItem, EmitFn };
@@ -0,0 +1,86 @@
1
+ import type { ComputedRef, Ref } from "vue";
2
+ import {
3
+ type DisplayItem,
4
+ type ItemPropsConfig,
5
+ type TreeItem,
6
+ type VirtualTreeProps,
7
+ toDisplayString,
8
+ } from "./virtual_tree_types";
9
+
10
+ interface FlattenContext {
11
+ props: Ref<VirtualTreeProps>;
12
+ actualItemProps: ComputedRef<ItemPropsConfig>;
13
+ openedSet: ComputedRef<Set<unknown>>;
14
+ activeSet: ComputedRef<Set<unknown>>;
15
+ getChildrenOf: (item: TreeItem) => TreeItem[] | undefined;
16
+ }
17
+
18
+ function matchesSearch(ctx: FlattenContext, item: TreeItem, id: unknown, search: string): boolean {
19
+ const { customFilter } = ctx.props.value;
20
+ if (customFilter) {
21
+ return customFilter(id, search, { raw: item });
22
+ }
23
+ const lowerSearch = search.toLowerCase();
24
+ return (
25
+ toDisplayString(item[ctx.actualItemProps.value.title]).toLowerCase().includes(lowerSearch) ||
26
+ toDisplayString(id).toLowerCase().includes(lowerSearch)
27
+ );
28
+ }
29
+
30
+ function flattenTree(ctx: FlattenContext, nodes: readonly TreeItem[], depth = 0): DisplayItem[] {
31
+ const { search } = ctx.props.value;
32
+ const result: DisplayItem[] = [];
33
+
34
+ for (const item of nodes) {
35
+ const id = item[ctx.actualItemProps.value.value];
36
+ const children = ctx.getChildrenOf(item);
37
+ const hasChildren = Boolean(children && children.length > 0);
38
+
39
+ const isOpen = ctx.openedSet.value.has(id);
40
+ const isActive = ctx.activeSet.value.has(id);
41
+
42
+ if (search !== undefined && search !== "") {
43
+ const matches = matchesSearch(ctx, item, id, search);
44
+
45
+ if (hasChildren) {
46
+ const subtree = flattenTree(ctx, children ?? [], depth + 1);
47
+ if (subtree.length === 0 && !matches) {
48
+ continue;
49
+ }
50
+
51
+ result.push({
52
+ raw: item,
53
+ id,
54
+ depth,
55
+ isOpen,
56
+ isActive,
57
+ isLeaf: false,
58
+ });
59
+ if (isOpen) {
60
+ result.push(...subtree);
61
+ }
62
+ continue;
63
+ }
64
+ if (!matches) {
65
+ continue;
66
+ }
67
+ }
68
+
69
+ result.push({
70
+ raw: item,
71
+ id,
72
+ depth,
73
+ isOpen,
74
+ isActive,
75
+ isLeaf: !hasChildren,
76
+ });
77
+
78
+ if (isOpen && hasChildren) {
79
+ result.push(...flattenTree(ctx, children ?? [], depth + 1));
80
+ }
81
+ }
82
+ return result;
83
+ }
84
+
85
+ export { flattenTree };
86
+ export type { FlattenContext };
@@ -0,0 +1,81 @@
1
+ import type { ComputedRef, Ref } from "vue";
2
+
3
+ // Same shape as Vue's MaybeRefOrGetter<T>, kept as a local alias for readability at call sites.
4
+ type ReadonlyMaybeRefOrGetter<Value> = Value | Ref<Value> | (() => Value);
5
+
6
+ type TreeItem = Record<string, unknown>;
7
+
8
+ interface ItemPropsConfig {
9
+ value: string;
10
+ title: string;
11
+ children: string;
12
+ height: number;
13
+ [key: string]: unknown;
14
+ }
15
+
16
+ interface SelectionConfig {
17
+ selectable: boolean;
18
+ strategy: string;
19
+ [key: string]: unknown;
20
+ }
21
+
22
+ interface VirtualTreeProps {
23
+ readonly items?: readonly TreeItem[];
24
+ readonly opened?: readonly unknown[];
25
+ readonly selected?: readonly unknown[];
26
+ readonly active?: readonly unknown[];
27
+ readonly itemProps?: Partial<ItemPropsConfig>;
28
+ readonly selection?: Partial<SelectionConfig>;
29
+ readonly search?: string;
30
+ readonly customFilter?: (id: unknown, search: string, context: { raw: TreeItem }) => boolean;
31
+ }
32
+
33
+ interface DisplayItem {
34
+ raw: TreeItem;
35
+ id: unknown;
36
+ depth: number;
37
+ isOpen: boolean;
38
+ isActive: boolean;
39
+ isLeaf: boolean;
40
+ }
41
+
42
+ type EmitFn = (event: string, ...args: readonly unknown[]) => void;
43
+
44
+ interface UseVirtualTreeReturn {
45
+ actualItemProps: ComputedRef<ItemPropsConfig>;
46
+ actualSelection: ComputedRef<SelectionConfig>;
47
+ displayItems: ComputedRef<DisplayItem[]>;
48
+ toggleOpen: (item: TreeItem) => void;
49
+ toggleSelect: (item: TreeItem) => void;
50
+ isSelected: (item: TreeItem) => boolean;
51
+ getIndeterminate: (item: TreeItem) => boolean;
52
+ }
53
+
54
+ // Real runtime check (rather than an `as TreeItem[]` cast) for the duck-typed "children" field:
55
+ // Item shapes vary across callers (treeview groups, model component/collection groups, ...), so
56
+ // This only verifies it is actually an array, same as the assumption the old cast silently made.
57
+ function isTreeItemArray(value: unknown): value is TreeItem[] {
58
+ return Array.isArray(value);
59
+ }
60
+
61
+ // Extracted so we never call String() directly on a value typed as `unknown` (ids and titles can
62
+ // Be anything at runtime): only stringify primitives that have a sane toString, and fall back to
63
+ // "" for anything else instead of risking "[object Object]".
64
+ function toDisplayString(value: unknown): string {
65
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
66
+ return String(value);
67
+ }
68
+ return "";
69
+ }
70
+
71
+ export { isTreeItemArray, toDisplayString };
72
+ export type {
73
+ DisplayItem,
74
+ EmitFn,
75
+ ItemPropsConfig,
76
+ ReadonlyMaybeRefOrGetter,
77
+ SelectionConfig,
78
+ TreeItem,
79
+ UseVirtualTreeReturn,
80
+ VirtualTreeProps,
81
+ };
package/app/stores/app.ts CHANGED
@@ -1,6 +1,9 @@
1
- import { consola } from "consola";
2
-
3
1
  // Local imports
2
+ import {
3
+ type RegisterableStore,
4
+ exportRegisteredStores,
5
+ importRegisteredStores,
6
+ } from "./app_helpers/registry.js";
4
7
  import { getRestApiPort, getRestApiProtocol, isCloudMode } from "@ogw_front/utils/stores.js";
5
8
  import { Status } from "@ogw_front/utils/status";
6
9
  import { api_fetch } from "@ogw_internal/utils/api_fetch.js";
@@ -27,16 +30,6 @@ declare module "pinia" {
27
30
  }
28
31
  }
29
32
 
30
- interface RegisterableStore {
31
- $id: string;
32
- $patch?: (partial: Record<string, unknown>) => void;
33
- exportStores?: (params?: Record<string, unknown>) => Promise<unknown>;
34
- importStores?: (snapshot: unknown) => Promise<void> | void;
35
- connect?: () => Promise<void>;
36
- kill?: () => Promise<void>;
37
- [key: string]: unknown;
38
- }
39
-
40
33
  // oxlint-disable-next-line max-lines-per-function, max-statements
41
34
  export const useAppStore = defineStore("app", () => {
42
35
  const stores: RegisterableStore[] = [];
@@ -85,52 +78,12 @@ export const useAppStore = defineStore("app", () => {
85
78
  async function exportStores(
86
79
  params: Record<string, unknown> = {},
87
80
  ): Promise<Record<string, unknown>> {
88
- const snapshot: Record<string, unknown> = {};
89
-
90
- await Promise.all(
91
- stores.map(async (store: RegisterableStore) => {
92
- if (!store.exportStores) {
93
- return;
94
- }
95
- const storeId = store.$id;
96
- try {
97
- snapshot[storeId] = await store.exportStores(params);
98
- } catch {
99
- // Ignore stores that fail to export; other stores still complete independently.
100
- }
101
- }),
102
- );
81
+ const snapshot = await exportRegisteredStores(stores, params);
103
82
  return snapshot;
104
83
  }
105
84
 
106
85
  async function importStores(snapshot: Record<string, unknown> | undefined): Promise<void> {
107
- if (!snapshot) {
108
- return;
109
- }
110
-
111
- const missingStoreIds: string[] = [];
112
-
113
- await Promise.all(
114
- stores.map(async (store: RegisterableStore) => {
115
- if (!store.importStores) {
116
- return;
117
- }
118
- const storeId = store.$id;
119
- if (snapshot[storeId] === undefined) {
120
- missingStoreIds.push(storeId);
121
- return;
122
- }
123
- try {
124
- await store.importStores(snapshot[storeId]);
125
- } catch {
126
- // Ignore stores that fail to import; other stores still complete independently.
127
- }
128
- }),
129
- );
130
-
131
- if (missingStoreIds.length > 0) {
132
- consola.warn(`Stores not found in snapshot: ${missingStoreIds.join(", ")}`);
133
- }
86
+ await importRegisteredStores(stores, snapshot);
134
87
  }
135
88
 
136
89
  const {
@@ -253,4 +206,4 @@ export const useAppStore = defineStore("app", () => {
253
206
  };
254
207
  });
255
208
 
256
- export type { RegisterableStore };
209
+ export type { RegisterableStore } from "./app_helpers/registry.js";