@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,160 @@
1
+ import { MESH_COMPONENT_TYPES } from "@ogw_front/utils/default_styles";
2
+ import { useDataStore } from "@ogw_front/stores/data";
3
+
4
+ // The four per-component-type style composables (Surface/Line/Block/Corner) each expose a different, large set of methods (color, visibility, per-attribute-kind getters/setters...). This module only cares about looking a handful of them up dynamically by name, so a precise structural type for componentStyleFunctions isn't worth modelling here; `any` keeps the dynamic dispatch table honest about that.
5
+ // oxlint-disable-next-line no-explicit-any
6
+ type ComponentStyleFunctions = Record<"Surface" | "Line" | "Block" | "Corner", any>;
7
+
8
+ interface ModelComponent {
9
+ geode_id: string;
10
+ type: string;
11
+ }
12
+
13
+ async function callComponentStyleFunction(
14
+ // oxlint-disable-next-line no-explicit-any
15
+ target: any,
16
+ method: string,
17
+ ...args: unknown[]
18
+ ): Promise<unknown> {
19
+ // oxlint-disable-next-line no-unsafe-call, no-unsafe-member-access, no-unsafe-argument, no-unsafe-assignment -- ComponentStyleFunctions is deliberately dynamically typed; see comment above.
20
+ const result = await target[method](...args);
21
+ return result;
22
+ }
23
+
24
+ async function getModelComponentsMap(
25
+ modelId: string,
26
+ ): Promise<{ allComponents: ModelComponent[]; componentsMap: Record<string, ModelComponent> }> {
27
+ const dataStore = useDataStore();
28
+ const results = await Promise.all(
29
+ MESH_COMPONENT_TYPES.map(async (type) => {
30
+ const geodeIds = await dataStore.getMeshComponentGeodeIds(modelId, type);
31
+ return geodeIds.map((geode_id): ModelComponent => ({
32
+ geode_id,
33
+ type,
34
+ }));
35
+ }),
36
+ );
37
+ const allComponents = results.flat();
38
+ return {
39
+ allComponents,
40
+ componentsMap: Object.fromEntries(
41
+ allComponents.map((component): [string, ModelComponent] => [component.geode_id, component]),
42
+ ),
43
+ };
44
+ }
45
+ async function dispatchToComponentTypes(
46
+ modelId: string,
47
+ componentIds: string[],
48
+ action: string,
49
+ { componentStyleFunctions }: { componentStyleFunctions: ComponentStyleFunctions },
50
+ ...args: unknown[]
51
+ ): Promise<unknown[]> {
52
+ const { componentsMap } = await getModelComponentsMap(modelId);
53
+ const idsByComponent: { Block: string[]; Surface: string[]; Line: string[]; Corner: string[] } = {
54
+ Block: [],
55
+ Surface: [],
56
+ Line: [],
57
+ Corner: [],
58
+ };
59
+ for (const id of componentIds) {
60
+ const type = componentsMap[id]?.type;
61
+ if (type !== undefined && type in idsByComponent) {
62
+ (idsByComponent as Record<string, string[]>)[type]?.push(id);
63
+ }
64
+ }
65
+ const promises: Promise<unknown>[] = [];
66
+ if (action === "Visibility") {
67
+ if (idsByComponent.Block.length > 0) {
68
+ promises.push(
69
+ callComponentStyleFunction(
70
+ componentStyleFunctions.Block,
71
+ "setModelBlocksVisibility",
72
+ modelId,
73
+ idsByComponent.Block,
74
+ ...args,
75
+ ),
76
+ );
77
+ }
78
+ if (idsByComponent.Surface.length > 0) {
79
+ promises.push(
80
+ callComponentStyleFunction(
81
+ componentStyleFunctions.Surface,
82
+ "setModelSurfacesVisibility",
83
+ modelId,
84
+ idsByComponent.Surface,
85
+ ...args,
86
+ ),
87
+ );
88
+ }
89
+ if (idsByComponent.Line.length > 0) {
90
+ promises.push(
91
+ callComponentStyleFunction(
92
+ componentStyleFunctions.Line,
93
+ "setModelLinesVisibility",
94
+ modelId,
95
+ idsByComponent.Line,
96
+ ...args,
97
+ ),
98
+ );
99
+ }
100
+ if (idsByComponent.Corner.length > 0) {
101
+ promises.push(
102
+ callComponentStyleFunction(
103
+ componentStyleFunctions.Corner,
104
+ "setModelCornersVisibility",
105
+ modelId,
106
+ idsByComponent.Corner,
107
+ ...args,
108
+ ),
109
+ );
110
+ }
111
+ } else if (action === "Color") {
112
+ if (idsByComponent.Block.length > 0) {
113
+ promises.push(
114
+ callComponentStyleFunction(
115
+ componentStyleFunctions.Block,
116
+ "setModelBlocksColor",
117
+ modelId,
118
+ idsByComponent.Block,
119
+ ...args,
120
+ ),
121
+ );
122
+ }
123
+ if (idsByComponent.Surface.length > 0) {
124
+ promises.push(
125
+ callComponentStyleFunction(
126
+ componentStyleFunctions.Surface,
127
+ "setModelSurfacesColor",
128
+ modelId,
129
+ idsByComponent.Surface,
130
+ ...args,
131
+ ),
132
+ );
133
+ }
134
+ if (idsByComponent.Line.length > 0) {
135
+ promises.push(
136
+ callComponentStyleFunction(
137
+ componentStyleFunctions.Line,
138
+ "setModelLinesColor",
139
+ modelId,
140
+ idsByComponent.Line,
141
+ ...args,
142
+ ),
143
+ );
144
+ }
145
+ if (idsByComponent.Corner.length > 0) {
146
+ promises.push(
147
+ callComponentStyleFunction(
148
+ componentStyleFunctions.Corner,
149
+ "setModelCornersColor",
150
+ modelId,
151
+ idsByComponent.Corner,
152
+ ...args,
153
+ ),
154
+ );
155
+ }
156
+ }
157
+ return Promise.all(promises);
158
+ }
159
+ export { getModelComponentsMap, dispatchToComponentTypes };
160
+ export type { ComponentStyleFunctions };
@@ -4,189 +4,9 @@ import type {
4
4
  ObjectStyle,
5
5
  StyleValues,
6
6
  } from "./types";
7
- import type { Observable as RxObservable } from "rxjs";
7
+ import { type SharedState, getSharedState } from "./state_shared";
8
8
  import { getTable } from "@ogw_internal/database/database";
9
- import { liveQuery } from "dexie";
10
9
  import merge from "lodash/merge";
11
- import { useObservable } from "@vueuse/rxjs";
12
-
13
- interface SharedState {
14
- styles: Ref<Record<string, ObjectStyle>>;
15
- modelComponentTypeStyles: Ref<Record<string, ModelComponentTypeStyle>>;
16
- componentStyles: Ref<Record<string, ModelComponentStyle>>;
17
- loadFromDatabase: () => Promise<void>;
18
- updateComponentStyleCache: (
19
- modelId: string,
20
- componentId: string,
21
- styleValues: StyleValues,
22
- ) => void;
23
- bulkUpdateComponentStyleCache: (
24
- modelId: string,
25
- componentStyleUpdates: readonly {
26
- readonly id_component: string;
27
- readonly values: StyleValues;
28
- }[],
29
- ) => void;
30
- bulkUpdateComponentStylesCache: (
31
- modelId: string,
32
- componentIds: readonly string[],
33
- styleValues: StyleValues,
34
- ) => void;
35
- updateModelComponentTypeStyleCache: (
36
- modelId: string,
37
- componentType: string,
38
- styleValues: StyleValues,
39
- ) => void;
40
- updateStyleCache: (objectId: string, styleValues: StyleValues) => void;
41
- }
42
-
43
- let sharedState: SharedState | undefined = undefined;
44
-
45
- // oxlint-disable-next-line max-lines-per-function
46
- function getSharedState(): SharedState {
47
- if (sharedState) {
48
- return sharedState;
49
- }
50
-
51
- const dataStyleTable = getTable<ObjectStyle>("data_style");
52
- const modelComponentDataStyleTable = getTable<ModelComponentStyle>("model_component_datastyle");
53
- const modelComponentTypeDataStyleTable = getTable<ModelComponentTypeStyle>(
54
- "model_component_type_datastyle",
55
- );
56
-
57
- // Dexie's `liveQuery` returns Dexie's own `Observable` type, structurally distinct
58
- // From rxjs's `Observable` that `useObservable` (from @vueuse/rxjs) expects, even
59
- // Though they're interoperable at runtime (both are plain subscribe-based streams).
60
- const dataStyleLiveQuery = liveQuery(async () => {
61
- const objectStyles = await dataStyleTable.toArray();
62
- const stylesByObjectId: Record<string, ObjectStyle> = {};
63
- for (const objectStyle of objectStyles) {
64
- stylesByObjectId[objectStyle.id] = objectStyle;
65
- }
66
- return stylesByObjectId;
67
- });
68
-
69
- const styles = useObservable<Record<string, ObjectStyle>, Record<string, ObjectStyle>>(
70
- // oxlint-disable-next-line no-unsafe-type-assertion
71
- dataStyleLiveQuery as unknown as RxObservable<Record<string, ObjectStyle>>,
72
- { initialValue: {} },
73
- ) as Ref<Record<string, ObjectStyle>>;
74
-
75
- const modelComponentTypeStyles = ref<Record<string, ModelComponentTypeStyle>>({});
76
- const componentStyles = ref<Record<string, ModelComponentStyle>>({});
77
-
78
- async function loadFromDatabase(): Promise<void> {
79
- const [fetchedTypeStyles, fetchedComponentStyles] = await Promise.all([
80
- modelComponentTypeDataStyleTable.toArray(),
81
- modelComponentDataStyleTable.toArray(),
82
- ]);
83
- const typeStylesMap: Record<string, ModelComponentTypeStyle> = {};
84
- for (const typeStyle of fetchedTypeStyles) {
85
- const cacheKey = `${typeStyle.id_model}_${typeStyle.type}`;
86
- typeStylesMap[cacheKey] = typeStyle;
87
- }
88
- modelComponentTypeStyles.value = typeStylesMap;
89
-
90
- const componentStylesMap: Record<string, ModelComponentStyle> = {};
91
- for (const componentStyle of fetchedComponentStyles) {
92
- const cacheKey = `${componentStyle.id_model}_${componentStyle.id_component}`;
93
- componentStylesMap[cacheKey] = componentStyle;
94
- }
95
- componentStyles.value = componentStylesMap;
96
- }
97
-
98
- void loadFromDatabase();
99
-
100
- function updateComponentStyleCache(
101
- modelId: string,
102
- componentId: string,
103
- styleValues: StyleValues,
104
- ): void {
105
- const cacheKey = `${modelId}_${componentId}`;
106
- const existingStyle = componentStyles.value[cacheKey];
107
- if (existingStyle === undefined) {
108
- componentStyles.value[cacheKey] = merge(
109
- { id_model: modelId, id_component: componentId },
110
- styleValues,
111
- );
112
- } else {
113
- merge(existingStyle, styleValues);
114
- }
115
- }
116
-
117
- function bulkUpdateComponentStyleCache(
118
- modelId: string,
119
- componentStyleUpdates: readonly {
120
- readonly id_component: string;
121
- readonly values: StyleValues;
122
- }[],
123
- ): void {
124
- const updatedComponentStyles = { ...componentStyles.value };
125
- for (const { id_component: componentId, values: styleValues } of componentStyleUpdates) {
126
- const cacheKey = `${modelId}_${componentId}`;
127
- const existingStyle = updatedComponentStyles[cacheKey];
128
- if (existingStyle === undefined) {
129
- updatedComponentStyles[cacheKey] = merge(
130
- { id_model: modelId, id_component: componentId },
131
- styleValues,
132
- );
133
- } else {
134
- updatedComponentStyles[cacheKey] = merge({}, existingStyle, styleValues);
135
- }
136
- }
137
- componentStyles.value = updatedComponentStyles;
138
- }
139
-
140
- function bulkUpdateComponentStylesCache(
141
- modelId: string,
142
- componentIds: readonly string[],
143
- styleValues: StyleValues,
144
- ): void {
145
- const updatedComponentStyles = { ...componentStyles.value };
146
- for (const componentId of componentIds) {
147
- const cacheKey = `${modelId}_${componentId}`;
148
- const existingStyle = updatedComponentStyles[cacheKey];
149
- if (existingStyle === undefined) {
150
- updatedComponentStyles[cacheKey] = merge(
151
- { id_model: modelId, id_component: componentId },
152
- styleValues,
153
- );
154
- } else {
155
- updatedComponentStyles[cacheKey] = merge({}, existingStyle, styleValues);
156
- }
157
- }
158
- componentStyles.value = updatedComponentStyles;
159
- }
160
-
161
- function updateModelComponentTypeStyleCache(
162
- modelId: string,
163
- componentType: string,
164
- styleValues: StyleValues,
165
- ): void {
166
- const cacheKey = `${modelId}_${componentType}`;
167
- modelComponentTypeStyles.value[cacheKey] ??= { id_model: modelId, type: componentType };
168
- merge(modelComponentTypeStyles.value[cacheKey], styleValues);
169
- }
170
-
171
- function updateStyleCache(objectId: string, styleValues: StyleValues): void {
172
- styles.value[objectId] ??= { id: objectId };
173
- merge(styles.value[objectId], styleValues);
174
- }
175
-
176
- sharedState = {
177
- styles,
178
- modelComponentTypeStyles,
179
- componentStyles,
180
- loadFromDatabase,
181
- updateComponentStyleCache,
182
- bulkUpdateComponentStyleCache,
183
- bulkUpdateComponentStylesCache,
184
- updateModelComponentTypeStyleCache,
185
- updateStyleCache,
186
- };
187
-
188
- return sharedState;
189
- }
190
10
 
191
11
  interface DataStyleStateApi extends SharedState {
192
12
  getStyle: (objectId: string) => ObjectStyle;
@@ -0,0 +1,191 @@
1
+ import type {
2
+ ModelComponentStyle,
3
+ ModelComponentTypeStyle,
4
+ ObjectStyle,
5
+ StyleValues,
6
+ } from "./types";
7
+ import type { Observable as RxObservable } from "rxjs";
8
+ import { getTable } from "@ogw_internal/database/database";
9
+ import { liveQuery } from "dexie";
10
+ import merge from "lodash/merge";
11
+ import { useObservable } from "@vueuse/rxjs";
12
+
13
+ interface SharedState {
14
+ styles: Ref<Record<string, ObjectStyle>>;
15
+ modelComponentTypeStyles: Ref<Record<string, ModelComponentTypeStyle>>;
16
+ componentStyles: Ref<Record<string, ModelComponentStyle>>;
17
+ loadFromDatabase: () => Promise<void>;
18
+ updateComponentStyleCache: (
19
+ modelId: string,
20
+ componentId: string,
21
+ styleValues: StyleValues,
22
+ ) => void;
23
+ bulkUpdateComponentStyleCache: (
24
+ modelId: string,
25
+ componentStyleUpdates: readonly {
26
+ readonly id_component: string;
27
+ readonly values: StyleValues;
28
+ }[],
29
+ ) => void;
30
+ bulkUpdateComponentStylesCache: (
31
+ modelId: string,
32
+ componentIds: readonly string[],
33
+ styleValues: StyleValues,
34
+ ) => void;
35
+ updateModelComponentTypeStyleCache: (
36
+ modelId: string,
37
+ componentType: string,
38
+ styleValues: StyleValues,
39
+ ) => void;
40
+ updateStyleCache: (objectId: string, styleValues: StyleValues) => void;
41
+ }
42
+
43
+ let sharedState: SharedState | undefined = undefined;
44
+
45
+ // oxlint-disable-next-line max-lines-per-function
46
+ function getSharedState(): SharedState {
47
+ if (sharedState) {
48
+ return sharedState;
49
+ }
50
+
51
+ const dataStyleTable = getTable<ObjectStyle>("data_style");
52
+ const modelComponentDataStyleTable = getTable<ModelComponentStyle>("model_component_datastyle");
53
+ const modelComponentTypeDataStyleTable = getTable<ModelComponentTypeStyle>(
54
+ "model_component_type_datastyle",
55
+ );
56
+
57
+ // Dexie's `liveQuery` returns Dexie's own `Observable` type, structurally distinct
58
+ // From rxjs's `Observable` that `useObservable` (from @vueuse/rxjs) expects, even
59
+ // Though they're interoperable at runtime (both are plain subscribe-based streams).
60
+ const dataStyleLiveQuery = liveQuery(async () => {
61
+ const objectStyles = await dataStyleTable.toArray();
62
+ const stylesByObjectId: Record<string, ObjectStyle> = {};
63
+ for (const objectStyle of objectStyles) {
64
+ stylesByObjectId[objectStyle.id] = objectStyle;
65
+ }
66
+ return stylesByObjectId;
67
+ });
68
+
69
+ const styles = useObservable<Record<string, ObjectStyle>, Record<string, ObjectStyle>>(
70
+ // oxlint-disable-next-line no-unsafe-type-assertion
71
+ dataStyleLiveQuery as unknown as RxObservable<Record<string, ObjectStyle>>,
72
+ { initialValue: {} },
73
+ ) as Ref<Record<string, ObjectStyle>>;
74
+
75
+ const modelComponentTypeStyles = ref<Record<string, ModelComponentTypeStyle>>({});
76
+ const componentStyles = ref<Record<string, ModelComponentStyle>>({});
77
+
78
+ async function loadFromDatabase(): Promise<void> {
79
+ const [fetchedTypeStyles, fetchedComponentStyles] = await Promise.all([
80
+ modelComponentTypeDataStyleTable.toArray(),
81
+ modelComponentDataStyleTable.toArray(),
82
+ ]);
83
+ const typeStylesMap: Record<string, ModelComponentTypeStyle> = {};
84
+ for (const typeStyle of fetchedTypeStyles) {
85
+ const cacheKey = `${typeStyle.id_model}_${typeStyle.type}`;
86
+ typeStylesMap[cacheKey] = typeStyle;
87
+ }
88
+ modelComponentTypeStyles.value = typeStylesMap;
89
+
90
+ const componentStylesMap: Record<string, ModelComponentStyle> = {};
91
+ for (const componentStyle of fetchedComponentStyles) {
92
+ const cacheKey = `${componentStyle.id_model}_${componentStyle.id_component}`;
93
+ componentStylesMap[cacheKey] = componentStyle;
94
+ }
95
+ componentStyles.value = componentStylesMap;
96
+ }
97
+
98
+ void loadFromDatabase();
99
+
100
+ function updateComponentStyleCache(
101
+ modelId: string,
102
+ componentId: string,
103
+ styleValues: StyleValues,
104
+ ): void {
105
+ const cacheKey = `${modelId}_${componentId}`;
106
+ const existingStyle = componentStyles.value[cacheKey];
107
+ if (existingStyle === undefined) {
108
+ componentStyles.value[cacheKey] = merge(
109
+ { id_model: modelId, id_component: componentId },
110
+ styleValues,
111
+ );
112
+ } else {
113
+ merge(existingStyle, styleValues);
114
+ }
115
+ }
116
+
117
+ function bulkUpdateComponentStyleCache(
118
+ modelId: string,
119
+ componentStyleUpdates: readonly {
120
+ readonly id_component: string;
121
+ readonly values: StyleValues;
122
+ }[],
123
+ ): void {
124
+ const updatedComponentStyles = { ...componentStyles.value };
125
+ for (const { id_component: componentId, values: styleValues } of componentStyleUpdates) {
126
+ const cacheKey = `${modelId}_${componentId}`;
127
+ const existingStyle = updatedComponentStyles[cacheKey];
128
+ if (existingStyle === undefined) {
129
+ updatedComponentStyles[cacheKey] = merge(
130
+ { id_model: modelId, id_component: componentId },
131
+ styleValues,
132
+ );
133
+ } else {
134
+ updatedComponentStyles[cacheKey] = merge({}, existingStyle, styleValues);
135
+ }
136
+ }
137
+ componentStyles.value = updatedComponentStyles;
138
+ }
139
+
140
+ function bulkUpdateComponentStylesCache(
141
+ modelId: string,
142
+ componentIds: readonly string[],
143
+ styleValues: StyleValues,
144
+ ): void {
145
+ const updatedComponentStyles = { ...componentStyles.value };
146
+ for (const componentId of componentIds) {
147
+ const cacheKey = `${modelId}_${componentId}`;
148
+ const existingStyle = updatedComponentStyles[cacheKey];
149
+ if (existingStyle === undefined) {
150
+ updatedComponentStyles[cacheKey] = merge(
151
+ { id_model: modelId, id_component: componentId },
152
+ styleValues,
153
+ );
154
+ } else {
155
+ updatedComponentStyles[cacheKey] = merge({}, existingStyle, styleValues);
156
+ }
157
+ }
158
+ componentStyles.value = updatedComponentStyles;
159
+ }
160
+
161
+ function updateModelComponentTypeStyleCache(
162
+ modelId: string,
163
+ componentType: string,
164
+ styleValues: StyleValues,
165
+ ): void {
166
+ const cacheKey = `${modelId}_${componentType}`;
167
+ modelComponentTypeStyles.value[cacheKey] ??= { id_model: modelId, type: componentType };
168
+ merge(modelComponentTypeStyles.value[cacheKey], styleValues);
169
+ }
170
+
171
+ function updateStyleCache(objectId: string, styleValues: StyleValues): void {
172
+ styles.value[objectId] ??= { id: objectId };
173
+ merge(styles.value[objectId], styleValues);
174
+ }
175
+
176
+ sharedState = {
177
+ styles,
178
+ modelComponentTypeStyles,
179
+ componentStyles,
180
+ loadFromDatabase,
181
+ updateComponentStyleCache,
182
+ bulkUpdateComponentStyleCache,
183
+ bulkUpdateComponentStylesCache,
184
+ updateModelComponentTypeStyleCache,
185
+ updateStyleCache,
186
+ };
187
+
188
+ return sharedState;
189
+ }
190
+ export { getSharedState };
191
+ export type { SharedState };