@geode/opengeodeweb-front 12.2.0-rc.3 → 12.2.0-rc.5

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 (135) hide show
  1. package/.build/tests/browser/helpers/object_trees/common.js +3 -1
  2. package/.build/tests/browser/helpers/object_trees/model_tree_bar.js +41 -0
  3. package/.build/tests/browser/helpers/wait_for_action_settled.js +2 -2
  4. package/.build/tests/browser/suites/index.js +2 -0
  5. package/.build/tests/browser/suites/model/collections.js +1 -1
  6. package/.build/tests/browser/suites/object_tree/controls.js +2 -1
  7. package/.build/tests/browser/suites/object_tree/model_tree_bar.js +81 -0
  8. package/app/components/ClippingPlanes.vue +1 -1
  9. package/app/components/FactorFilterPanel.vue +1 -1
  10. package/app/components/Launcher.vue +3 -2
  11. package/app/components/ThresholdFilter.vue +1 -2
  12. package/app/components/Viewer/Basemap/CropOptions.vue +7 -8
  13. package/app/components/Viewer/Basemap/OpacityOptions.vue +7 -8
  14. package/app/components/Viewer/ContextMenu/CircularItems.vue +6 -43
  15. package/app/components/Viewer/ContextMenu/ContextMenu.vue +1 -6
  16. package/app/components/Viewer/ContextMenu/ContextMenuItem.vue +14 -16
  17. package/app/components/Viewer/EdgedCurve/PointsOptions.vue +5 -4
  18. package/app/components/Viewer/EdgedCurve/SpecificEdgesOptions.vue +10 -13
  19. package/app/components/Viewer/Generic/Mesh/CellsOptions.vue +8 -11
  20. package/app/components/Viewer/Generic/Mesh/EdgesOptions.vue +16 -13
  21. package/app/components/Viewer/Generic/Mesh/PointsOptions.vue +28 -31
  22. package/app/components/Viewer/Generic/Mesh/PolygonsOptions.vue +9 -11
  23. package/app/components/Viewer/Generic/Mesh/PolyhedraOptions.vue +8 -11
  24. package/app/components/Viewer/Generic/Model/BlocksOptions.vue +1 -1
  25. package/app/components/Viewer/Generic/Model/CornersOptions.vue +1 -1
  26. package/app/components/Viewer/Generic/Model/CornersTypeOptions.vue +1 -1
  27. package/app/components/Viewer/Generic/Model/EdgesOptions.vue +7 -8
  28. package/app/components/Viewer/Generic/Model/LinesOptions.vue +1 -1
  29. package/app/components/Viewer/Generic/Model/LinesTypeOptions.vue +1 -1
  30. package/app/components/Viewer/Generic/Model/ModelEdgesCard.vue +5 -7
  31. package/app/components/Viewer/Generic/Model/ModelPointsCard.vue +5 -7
  32. package/app/components/Viewer/Generic/Model/ModelStyleCard.vue +5 -7
  33. package/app/components/Viewer/Generic/Model/ModelStyleOptions.vue +7 -8
  34. package/app/components/Viewer/Generic/Model/PointsOptions.vue +7 -8
  35. package/app/components/Viewer/Generic/Model/SurfacesOptions.vue +1 -1
  36. package/app/components/Viewer/Grid/2D/CellsOptions.vue +6 -4
  37. package/app/components/Viewer/Grid/2D/EdgesOptions.vue +6 -4
  38. package/app/components/Viewer/Grid/2D/PointsOptions.vue +5 -4
  39. package/app/components/Viewer/Grid/3D/CellsOptions.vue +6 -4
  40. package/app/components/Viewer/Grid/3D/EdgesOptions.vue +6 -4
  41. package/app/components/Viewer/Grid/3D/FacetsOptions.vue +6 -4
  42. package/app/components/Viewer/Grid/3D/PointsOptions.vue +5 -4
  43. package/app/components/Viewer/Image/ImageOptions.vue +10 -13
  44. package/app/components/Viewer/ObjectTree/Base/CommonTreeView.vue +17 -1
  45. package/app/components/Viewer/ObjectTree/Base/ComponentRelations.vue +2 -2
  46. package/app/components/Viewer/ObjectTree/Base/Controls.vue +26 -2
  47. package/app/components/Viewer/ObjectTree/Base/StickyHeader.vue +4 -1
  48. package/app/components/Viewer/ObjectTree/Base/TreeRow.vue +6 -8
  49. package/app/components/Viewer/ObjectTree/Box.vue +30 -5
  50. package/app/components/Viewer/ObjectTree/Layout.vue +183 -54
  51. package/app/components/Viewer/ObjectTree/Views/GlobalObjects.vue +10 -15
  52. package/app/components/Viewer/ObjectTree/Views/ModelTree.vue +3 -0
  53. package/app/components/Viewer/PointSet/SpecificPointsOptions.vue +28 -31
  54. package/app/components/Viewer/Scene/BackgroundOptions.vue +4 -7
  55. package/app/components/Viewer/Scene/OrientationWidgetOptions.vue +4 -7
  56. package/app/components/Viewer/Scene/TextOptions.vue +4 -7
  57. package/app/components/Viewer/Solid/EdgesOptions.vue +6 -4
  58. package/app/components/Viewer/Solid/PointsOptions.vue +5 -4
  59. package/app/components/Viewer/Solid/PolygonsOptions.vue +6 -4
  60. package/app/components/Viewer/Solid/SpecificPolyhedraOptions.vue +8 -11
  61. package/app/components/Viewer/Surface/EdgesOptions.vue +6 -4
  62. package/app/components/Viewer/Surface/PointsOptions.vue +6 -4
  63. package/app/components/Viewer/Surface/PolygonsOptions.vue +8 -11
  64. package/app/components/Viewer/Surface/Triangulated/TrianglesOptions.vue +5 -4
  65. package/app/components/Viewer/TetrahedralSolid/TetrahedraOptions.vue +6 -4
  66. package/app/components/Viewer/TetrahedralSolid/TrianglesOptions.vue +6 -4
  67. package/app/composables/circular_menu.ts +45 -0
  68. package/app/composables/hover_highlight.ts +1 -1
  69. package/app/composables/model_menu_context.ts +7 -11
  70. package/app/composables/model_tree.ts +3 -3
  71. package/app/composables/model_tree_drag.ts +56 -0
  72. package/app/composables/project_manager_helpers/types.ts +2 -3
  73. package/app/composables/use_adaptive_styles.ts +15 -8
  74. package/app/composables/use_overlapping_picker.ts +7 -19
  75. package/app/composables/viewer_context_menu.ts +2 -1
  76. package/app/composables/virtual_tree.ts +7 -1
  77. package/app/stores/api.ts +6 -59
  78. package/app/stores/app.ts +21 -55
  79. package/app/stores/back.ts +86 -145
  80. package/app/stores/camera_manager.ts +12 -25
  81. package/app/stores/cloud.ts +21 -101
  82. package/app/stores/crs.ts +3 -2
  83. package/app/stores/data.ts +66 -409
  84. package/app/stores/data_style.ts +99 -93
  85. package/app/stores/feedback.ts +57 -53
  86. package/app/stores/infra.ts +61 -101
  87. package/app/stores/treeview.ts +39 -30
  88. package/app/stores/viewer.ts +9 -29
  89. package/app/stores/viewer_helpers/actions.ts +1 -23
  90. package/app/utils/backend_lifecycle.ts +155 -0
  91. package/app/utils/import_item.ts +5 -4
  92. package/app/utils/threshold_sources.ts +3 -2
  93. package/app/utils/treeview.ts +25 -1
  94. package/app/utils/viewer_object_type.ts +21 -0
  95. package/internal/database/base_database.ts +2 -1
  96. package/internal/database/database.ts +90 -7
  97. package/internal/database/queries.ts +45 -0
  98. package/internal/database/tables/camera_positions.ts +11 -1
  99. package/internal/database/tables/data.ts +20 -1
  100. package/internal/database/tables/data_style.ts +3 -1
  101. package/internal/database/tables/model_component_datastyle.ts +3 -1
  102. package/internal/database/tables/model_component_type_datastyle.ts +3 -1
  103. package/internal/database/tables/model_components.ts +12 -1
  104. package/internal/database/tables/model_components_relation.ts +11 -1
  105. package/internal/database/tables/scene_style.ts +3 -1
  106. package/internal/database/tables/treeview_config.ts +31 -0
  107. package/internal/stores/data/items.ts +110 -0
  108. package/internal/stores/data/model/collections.ts +107 -0
  109. package/internal/stores/data/model/components.ts +129 -0
  110. package/internal/stores/data/model/mesh_components.ts +134 -0
  111. package/internal/stores/data/model/relations.ts +76 -0
  112. package/internal/stores/data/model/types.ts +14 -0
  113. package/internal/stores/data/registration.ts +54 -0
  114. package/internal/stores/data/snapshot.ts +83 -0
  115. package/internal/stores/data/types.ts +26 -0
  116. package/internal/stores/data_style/model/common_mutations.ts +47 -77
  117. package/internal/stores/data_style/model/selection.ts +3 -10
  118. package/internal/stores/data_style/scene.ts +2 -2
  119. package/internal/stores/data_style/state.ts +10 -8
  120. package/internal/stores/data_style/state_shared.ts +10 -7
  121. package/internal/stores/hybrid_viewer/brightness.ts +36 -19
  122. package/internal/stores/hybrid_viewer/highlight.ts +9 -14
  123. package/internal/stores/hybrid_viewer/scene.ts +1 -1
  124. package/internal/stores/microservice.ts +192 -0
  125. package/package.json +1 -1
  126. package/tests/browser/helpers/data/helpers/attribute.ts +2 -1
  127. package/tests/browser/helpers/object_trees/common.ts +4 -0
  128. package/tests/browser/helpers/object_trees/model_tree_bar.ts +78 -0
  129. package/tests/browser/helpers/wait_for_action_settled.ts +2 -3
  130. package/tests/browser/suites/model/collections.ts +2 -1
  131. package/tests/browser/suites/object_tree/controls.ts +3 -0
  132. package/tests/browser/suites/object_tree/model_tree_bar.ts +125 -0
  133. package/app/stores/data_helpers/collections.ts +0 -122
  134. package/app/stores/data_helpers/mesh.ts +0 -167
  135. package/app/stores/data_helpers/relations.ts +0 -94
@@ -0,0 +1,76 @@
1
+ import { type FormattedComponent, toFormattedComponent } from "./mesh_components.js";
2
+ import {
3
+ componentRelationsOf,
4
+ modelComponentRelationsOf,
5
+ modelComponentsByGeodeIds,
6
+ } from "@ogw_internal/database/queries.js";
7
+ import type { ModelComponentRelationRecord } from "@ogw_internal/database/tables/model_components_relation";
8
+ import type { ModelId } from "@ogw_front/types/identifiers";
9
+
10
+ interface ComponentRelations {
11
+ readonly boundaries: readonly FormattedComponent[];
12
+ readonly internals: readonly FormattedComponent[];
13
+ }
14
+
15
+ const RELATION_KEYS: Readonly<Record<string, keyof ComponentRelations>> = {
16
+ boundary: "boundaries",
17
+ internal: "internals",
18
+ };
19
+
20
+ type MutableComponentRelations = { [Key in keyof ComponentRelations]: FormattedComponent[] };
21
+
22
+ function groupRelationsByParent(
23
+ relations: readonly ModelComponentRelationRecord[],
24
+ components: readonly FormattedComponent[],
25
+ ): Record<string, ComponentRelations> {
26
+ const componentsById = new Map(components.map((component) => [component.id, component]));
27
+ const byParent: Record<string, MutableComponentRelations> = {};
28
+ for (const relation of relations) {
29
+ const key = RELATION_KEYS[relation.type];
30
+ const child = componentsById.get(relation.child);
31
+ if (key !== undefined && child !== undefined) {
32
+ byParent[relation.parent] ??= { boundaries: [], internals: [] };
33
+ byParent[relation.parent]?.[key].push(child);
34
+ }
35
+ }
36
+ return byParent;
37
+ }
38
+
39
+ async function getRelatedComponents(
40
+ modelId: ModelId,
41
+ relations: readonly ModelComponentRelationRecord[],
42
+ type: string,
43
+ ): Promise<FormattedComponent[]> {
44
+ const childIds = relations
45
+ .filter((relation) => relation.type === type)
46
+ .map((relation) => relation.child);
47
+ const components = await modelComponentsByGeodeIds(modelId, childIds).toArray();
48
+ return components.map((component) => toFormattedComponent(component));
49
+ }
50
+
51
+ async function getComponentRelations(
52
+ modelId: ModelId,
53
+ componentId: string,
54
+ ): Promise<ComponentRelations> {
55
+ const relations = await componentRelationsOf(modelId, componentId).toArray();
56
+ const [boundaries, internals] = await Promise.all([
57
+ getRelatedComponents(modelId, relations, "boundary"),
58
+ getRelatedComponents(modelId, relations, "internal"),
59
+ ]);
60
+ return { boundaries, internals };
61
+ }
62
+
63
+ // The boundaries and internals of every component of the model, among the given components:
64
+ // The caller already holds them, so only the relations are read
65
+ async function fetchAllComponentRelations(
66
+ modelId: ModelId,
67
+ components: readonly FormattedComponent[],
68
+ ): Promise<Record<string, ComponentRelations>> {
69
+ const relations = await modelComponentRelationsOf(modelId).toArray();
70
+ return groupRelationsByParent(relations, components);
71
+ }
72
+
73
+ export type { ComponentRelations };
74
+ export type { ModelComponentRelationRecord } from "@ogw_internal/database/tables/model_components_relation";
75
+
76
+ export { fetchAllComponentRelations, getComponentRelations };
@@ -0,0 +1,14 @@
1
+ import type { GeodeIdentified } from "@ogw_front/types/identifiers";
2
+
3
+ // A model component as the back sends it, with the ids of its related components
4
+ interface ModelComponentInput extends GeodeIdentified {
5
+ type: string;
6
+ viewer_id: string | number;
7
+ name: string;
8
+ is_active: boolean;
9
+ boundaries?: string[];
10
+ internals?: string[];
11
+ items?: string[];
12
+ }
13
+
14
+ export type { ModelComponentInput };
@@ -0,0 +1,54 @@
1
+ import type { ComputedRef, Ref } from "vue";
2
+ import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
3
+ import type { DataItem } from "@ogw_internal/database/tables/data";
4
+ import { useViewerStore } from "@ogw_front/stores/viewer";
5
+ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
6
+
7
+ const viewerGenericSchemas = viewer_schemas.opengeodeweb_viewer.generic;
8
+
9
+ // Ids the viewer holds a pipeline for: an item is stored before it is registered, and non viewable items never are
10
+ function useDataRegistration(items: Readonly<Ref<DataItem[]>>): {
11
+ registeredItems: ComputedRef<DataItem[]>;
12
+ isRegistered: typeof isRegistered;
13
+ registerObject: typeof registerObject;
14
+ deregisterObject: typeof deregisterObject;
15
+ clearRegistrations: typeof clearRegistrations;
16
+ } {
17
+ const viewerStore = useViewerStore();
18
+ const registeredIds = reactive(new Set<string>());
19
+
20
+ function isRegistered(dataId: DataId): boolean {
21
+ return registeredIds.has(dataId);
22
+ }
23
+
24
+ const registeredItems = computed(() =>
25
+ items.value.filter((dataItem) => isRegistered(dataItem.data_id)),
26
+ );
27
+
28
+ async function registerObject(dataId: DataId, name: string): Promise<unknown> {
29
+ const result = await viewerStore.request({
30
+ schema: viewerGenericSchemas.register,
31
+ params: { id: dataId, name },
32
+ timeout: 0,
33
+ });
34
+ registeredIds.add(dataId);
35
+ return result;
36
+ }
37
+
38
+ async function deregisterObject(dataId: DataId): Promise<unknown> {
39
+ registeredIds.delete(dataId);
40
+ const result = await viewerStore.request({
41
+ schema: viewerGenericSchemas.deregister,
42
+ params: { id: dataId },
43
+ });
44
+ return result;
45
+ }
46
+
47
+ function clearRegistrations(): void {
48
+ registeredIds.clear();
49
+ }
50
+
51
+ return { registeredItems, isRegistered, registerObject, deregisterObject, clearRegistrations };
52
+ }
53
+
54
+ export { useDataRegistration };
@@ -0,0 +1,83 @@
1
+ import { type LegacyDataId, fromLegacyDataId } from "@ogw_front/utils/legacy_data_id";
2
+ import {
3
+ dataDb,
4
+ modelComponentsDb,
5
+ modelComponentsRelationDb,
6
+ writeTransaction,
7
+ } from "@ogw_internal/database/database.js";
8
+ import { modelComponentRelationsOf, modelComponentsOf } from "@ogw_internal/database/queries.js";
9
+ import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
10
+ import type { DataItem } from "@ogw_internal/database/tables/data";
11
+ import type { ModelComponentRecord } from "@ogw_internal/database/tables/model_components";
12
+ import type { ModelComponentRelationRecord } from "@ogw_internal/database/tables/model_components_relation";
13
+ import type { ModelId } from "@ogw_front/types/identifiers";
14
+
15
+ const dataTable = dataDb();
16
+ const modelComponentsTable = modelComponentsDb();
17
+ const modelComponentsRelationTable = modelComponentsRelationDb();
18
+ const dataTables = [dataTable, modelComponentsTable, modelComponentsRelationTable];
19
+
20
+ interface DataSnapshot {
21
+ readonly modelComponents: readonly (LegacyDataId<ModelComponentRecord> | ModelComponentRecord)[];
22
+ readonly modelComponentsRelations: readonly (
23
+ | LegacyDataId<ModelComponentRelationRecord>
24
+ | ModelComponentRelationRecord
25
+ )[];
26
+ }
27
+
28
+ async function deleteModelComponents(modelId: ModelId): Promise<void> {
29
+ await writeTransaction([modelComponentsTable, modelComponentsRelationTable], async () => {
30
+ await modelComponentsOf(modelId).delete();
31
+ await modelComponentRelationsOf(modelId).delete();
32
+ });
33
+ }
34
+
35
+ // A data is deleted with its components and their relations, or not at all
36
+ async function deleteItem(dataId: DataId): Promise<void> {
37
+ await writeTransaction(dataTables, async () => {
38
+ await dataTable.delete(dataId);
39
+ await deleteModelComponents(dataId);
40
+ });
41
+ }
42
+
43
+ async function exportStores(): Promise<{
44
+ items: DataItem[];
45
+ modelComponents: ModelComponentRecord[];
46
+ modelComponentsRelations: ModelComponentRelationRecord[];
47
+ }> {
48
+ return {
49
+ items: await dataTable.toArray(),
50
+ modelComponents: await modelComponentsTable.toArray(),
51
+ modelComponentsRelations: await modelComponentsRelationTable.toArray(),
52
+ };
53
+ }
54
+
55
+ async function clearTables(): Promise<void> {
56
+ await writeTransaction(dataTables, async () => {
57
+ await dataTable.clear();
58
+ await modelComponentsTable.clear();
59
+ await modelComponentsRelationTable.clear();
60
+ });
61
+ }
62
+
63
+ // The snapshot replaces the stored data as a whole: a failed import leaves the previous one.
64
+ // Dexie's bulkPut expects mutable arrays, so this snapshot parameter can't deeply satisfy
65
+ // The prefer-readonly-parameter-types rule; same pattern as app/utils/import_workflow.ts.
66
+ async function importTables(snapshot: DataSnapshot): Promise<void> {
67
+ await writeTransaction(dataTables, async () => {
68
+ await clearTables();
69
+ await modelComponentsTable.bulkPut(
70
+ snapshot.modelComponents.map((component) =>
71
+ fromLegacyDataId<ModelComponentRecord>(component),
72
+ ),
73
+ );
74
+ await modelComponentsRelationTable.bulkPut(
75
+ snapshot.modelComponentsRelations.map((relation) =>
76
+ fromLegacyDataId<ModelComponentRelationRecord>(relation),
77
+ ),
78
+ );
79
+ });
80
+ }
81
+
82
+ export { clearTables, deleteItem, exportStores, importTables };
83
+ export type { DataSnapshot };
@@ -0,0 +1,26 @@
1
+ import type {
2
+ DataIdentified,
3
+ GeodeIdentified,
4
+ GeodeObjectTyped,
5
+ ViewerObjectTyped,
6
+ } from "@ogw_front/types/identifiers";
7
+ import type { CRS } from "@geode/opengeodeweb-back/schema_types";
8
+ import type { DataItem } from "@ogw_internal/database/tables/data";
9
+ import type { ModelComponentInput } from "@ogw_internal/stores/data/model/types";
10
+
11
+ // What the CRS features read of a data: light to copy on each change
12
+ type CrsItem = Pick<DataItem, "data_id" | "name" | "crs" | "created_at">;
13
+
14
+ interface NewDataItem extends DataIdentified, GeodeIdentified, GeodeObjectTyped, ViewerObjectTyped {
15
+ name?: string;
16
+ is_viewable?: boolean;
17
+ binary_light_viewable?: string;
18
+ crs?: CRS;
19
+ // Set on saved data: kept by the project snapshot
20
+ created_at?: string;
21
+ mesh_components?: ModelComponentInput[];
22
+ collection_components?: ModelComponentInput[];
23
+ nb_vertices?: number;
24
+ }
25
+
26
+ export type { CrsItem, NewDataItem };
@@ -1,34 +1,21 @@
1
- import type { Dexie, Table } from "dexie";
2
1
  import type {
3
2
  ModelComponentStyle,
4
3
  ModelComponentTypeStyle,
5
4
  StyleValues,
6
5
  } from "@ogw_internal/stores/data_style/types.js";
7
- import { database } from "@ogw_internal/database/database";
6
+ import {
7
+ componentDataStyleDb,
8
+ componentTypeDataStyleDb,
9
+ writeTransaction,
10
+ } from "@ogw_internal/database/database";
8
11
  import merge from "lodash/merge";
9
12
  import { useDataStyleState } from "@ogw_internal/stores/data_style/state";
10
13
 
11
- // The underlying dexie tables use compound array keys ([id_model, id_component] /
12
- // [id_model, type]) but the shared `database` proxy types every table as
13
- // Table<Record<string, unknown>, string>. Cast locally to the real key shape.
14
- type ComponentTable = Table<ModelComponentStyle, [string, string]>;
15
- type ComponentTypeTable = Table<ModelComponentTypeStyle, [string, string]>;
16
-
17
14
  interface ComponentStyleUpdate {
18
15
  id_component: string;
19
16
  values: StyleValues;
20
17
  }
21
18
 
22
- function componentDatastyleTable(): ComponentTable {
23
- // oxlint-disable-next-line no-unsafe-type-assertion -- compound-key table cast; see comment above.
24
- return database.model_component_datastyle as unknown as ComponentTable;
25
- }
26
-
27
- function componentTypeDatastyleTable(): ComponentTypeTable {
28
- // oxlint-disable-next-line no-unsafe-type-assertion -- compound-key table cast; see comment above.
29
- return database.model_component_type_datastyle as unknown as ComponentTypeTable;
30
- }
31
-
32
19
  interface UseModelComponentStyleMutationsReturn {
33
20
  mutateComponentStyle: (
34
21
  id_model: string,
@@ -59,8 +46,8 @@ interface UseModelComponentsPerComponentStyleMutationReturn {
59
46
 
60
47
  function useModelComponentStyleMutations(): UseModelComponentStyleMutationsReturn {
61
48
  const dataStyleState = useDataStyleState();
62
- const model_component_datastyle_db = componentDatastyleTable();
63
- const model_component_type_datastyle_db = componentTypeDatastyleTable();
49
+ const componentDataStyleTable = componentDataStyleDb();
50
+ const componentTypeDataStyleTable = componentTypeDataStyleDb();
64
51
 
65
52
  async function mutateComponentStyle(
66
53
  id_model: string,
@@ -69,12 +56,12 @@ function useModelComponentStyleMutations(): UseModelComponentStyleMutationsRetur
69
56
  ): Promise<unknown> {
70
57
  dataStyleState.updateComponentStyleCache(id_model, id_component, values);
71
58
  const key: [string, string] = [id_model, id_component];
72
- const entry: ModelComponentStyle = (await model_component_datastyle_db.get(key)) ?? {
59
+ const entry: ModelComponentStyle = (await componentDataStyleTable.get(key)) ?? {
73
60
  id_model,
74
61
  id_component,
75
62
  };
76
63
  merge(entry, values);
77
- return model_component_datastyle_db.put(structuredClone(toRaw(entry)));
64
+ return componentDataStyleTable.put(structuredClone(toRaw(entry)));
78
65
  }
79
66
 
80
67
  async function mutateModelComponentTypeStyle(
@@ -83,22 +70,15 @@ function useModelComponentStyleMutations(): UseModelComponentStyleMutationsRetur
83
70
  values: StyleValues,
84
71
  ): Promise<void> {
85
72
  dataStyleState.updateModelComponentTypeStyleCache(id_model, type, values);
86
- // oxlint-disable-next-line no-unsafe-type-assertion -- the shared database proxy types every table as Dexie; see comment above.
87
- await (database as unknown as Dexie).transaction(
88
- "rw",
89
- model_component_type_datastyle_db,
90
- async () => {
91
- const key: [string, string] = [id_model, type];
92
- const entry: ModelComponentTypeStyle = (await model_component_type_datastyle_db.get(
93
- key,
94
- )) ?? {
95
- id_model,
96
- type,
97
- };
98
- merge(entry, values);
99
- return model_component_type_datastyle_db.put(structuredClone(toRaw(entry)));
100
- },
101
- );
73
+ await writeTransaction([componentTypeDataStyleTable], async () => {
74
+ const key: [string, string] = [id_model, type];
75
+ const entry: ModelComponentTypeStyle = (await componentTypeDataStyleTable.get(key)) ?? {
76
+ id_model,
77
+ type,
78
+ };
79
+ merge(entry, values);
80
+ return componentTypeDataStyleTable.put(structuredClone(toRaw(entry)));
81
+ });
102
82
  }
103
83
 
104
84
  return {
@@ -109,7 +89,7 @@ function useModelComponentStyleMutations(): UseModelComponentStyleMutationsRetur
109
89
 
110
90
  function useModelComponentsStyleMutation(): UseModelComponentsStyleMutationReturn {
111
91
  const dataStyleState = useDataStyleState();
112
- const model_component_datastyle_db = componentDatastyleTable();
92
+ const componentDataStyleTable = componentDataStyleDb();
113
93
 
114
94
  async function mutateComponentStyles(
115
95
  id_model: string,
@@ -117,25 +97,20 @@ function useModelComponentsStyleMutation(): UseModelComponentsStyleMutationRetur
117
97
  values: StyleValues,
118
98
  ): Promise<void> {
119
99
  dataStyleState.bulkUpdateComponentStylesCache(id_model, id_components, values);
120
- // oxlint-disable-next-line no-unsafe-type-assertion -- the shared database proxy types every table as Dexie; see comment above.
121
- await (database as unknown as Dexie).transaction(
122
- "rw",
123
- model_component_datastyle_db,
124
- async () => {
125
- const keys: [string, string][] = id_components.map((id_component) => [
126
- id_model,
127
- id_component,
128
- ]);
129
- const existing = await model_component_datastyle_db.bulkGet(keys);
130
- const updates = id_components.map((id_component, index) => {
131
- const style: ModelComponentStyle = existing[index] ?? { id_model, id_component };
132
- merge(style, values);
133
- return toRaw(style);
134
- });
135
-
136
- return model_component_datastyle_db.bulkPut(structuredClone(updates));
137
- },
138
- );
100
+ await writeTransaction([componentDataStyleTable], async () => {
101
+ const keys: [string, string][] = id_components.map((id_component) => [
102
+ id_model,
103
+ id_component,
104
+ ]);
105
+ const existing = await componentDataStyleTable.bulkGet(keys);
106
+ const updates = id_components.map((id_component, index) => {
107
+ const style: ModelComponentStyle = existing[index] ?? { id_model, id_component };
108
+ merge(style, values);
109
+ return toRaw(style);
110
+ });
111
+
112
+ return componentDataStyleTable.bulkPut(structuredClone(updates));
113
+ });
139
114
  }
140
115
 
141
116
  return {
@@ -145,31 +120,26 @@ function useModelComponentsStyleMutation(): UseModelComponentsStyleMutationRetur
145
120
 
146
121
  function useModelComponentsPerComponentStyleMutation(): UseModelComponentsPerComponentStyleMutationReturn {
147
122
  const dataStyleState = useDataStyleState();
148
- const model_component_datastyle_db = componentDatastyleTable();
123
+ const componentDataStyleTable = componentDataStyleDb();
149
124
 
150
125
  async function bulkMutateComponentStylesPerComponent(
151
126
  id_model: string,
152
127
  component_updates: ComponentStyleUpdate[],
153
128
  ): Promise<void> {
154
129
  dataStyleState.bulkUpdateComponentStyleCache(id_model, component_updates);
155
- // oxlint-disable-next-line no-unsafe-type-assertion -- the shared database proxy types every table as Dexie; see comment above.
156
- await (database as unknown as Dexie).transaction(
157
- "rw",
158
- model_component_datastyle_db,
159
- async () => {
160
- const keys: [string, string][] = component_updates.map((update) => [
161
- id_model,
162
- update.id_component,
163
- ]);
164
- const existing = await model_component_datastyle_db.bulkGet(keys);
165
- const updates = component_updates.map(({ id_component, values }, index) => {
166
- const style: ModelComponentStyle = existing[index] ?? { id_model, id_component };
167
- merge(style, values);
168
- return toRaw(style);
169
- });
170
- return model_component_datastyle_db.bulkPut(structuredClone(updates));
171
- },
172
- );
130
+ await writeTransaction([componentDataStyleTable], async () => {
131
+ const keys: [string, string][] = component_updates.map((update) => [
132
+ id_model,
133
+ update.id_component,
134
+ ]);
135
+ const existing = await componentDataStyleTable.bulkGet(keys);
136
+ const updates = component_updates.map(({ id_component, values }, index) => {
137
+ const style: ModelComponentStyle = existing[index] ?? { id_model, id_component };
138
+ merge(style, values);
139
+ return toRaw(style);
140
+ });
141
+ return componentDataStyleTable.bulkPut(structuredClone(updates));
142
+ });
173
143
  }
174
144
 
175
145
  return {
@@ -1,19 +1,12 @@
1
1
  import type { ModelId, ModelIdentified } from "@ogw_front/types/identifiers";
2
2
  import { MESH_COMPONENT_TYPES } from "@ogw_front/utils/default_styles";
3
- import type { ModelComponentRecord } from "@ogw_front/stores/data_helpers/mesh";
3
+ import type { ModelComponentRecord } from "@ogw_internal/stores/data/model/mesh_components";
4
4
  import type { StyleValues } from "@ogw_internal/stores/data_style/types.js";
5
- import type { Table } from "dexie";
6
- import { database } from "@ogw_internal/database/database";
5
+ import { modelComponentsOf } from "@ogw_internal/database/queries";
7
6
  import type { useDataStyleState } from "@ogw_internal/stores/data_style/state";
8
7
 
9
8
  type DataStyleState = ReturnType<typeof useDataStyleState>;
10
9
 
11
- // oxlint-disable-next-line no-unsafe-type-assertion -- trusted Dexie table boundary; see other database table casts in this codebase.
12
- const model_components_db = database.model_components as unknown as Table<
13
- ModelComponentRecord,
14
- string
15
- >;
16
-
17
10
  function groupComponentsByType(
18
11
  components: readonly ModelComponentRecord[],
19
12
  ): Record<string, ModelComponentRecord[]> {
@@ -113,7 +106,7 @@ function useModelSelection(
113
106
 
114
107
  void (async (): Promise<void> => {
115
108
  try {
116
- allComponents.value = await model_components_db.where("data_id").equals(modelId).toArray();
109
+ allComponents.value = await modelComponentsOf(modelId).toArray();
117
110
  } catch {
118
111
  allComponents.value = [];
119
112
  }
@@ -10,7 +10,7 @@ import {
10
10
  } from "@ogw_front/composables/orientation_overlay";
11
11
  import { consola } from "consola";
12
12
  import { getDefaultSceneStyle } from "@ogw_front/utils/default_styles";
13
- import { getTable } from "@ogw_internal/database/database";
13
+ import { sceneStyleDb } from "@ogw_internal/database/database";
14
14
  import { toViewerColor } from "@ogw_front/composables/viewer_reset";
15
15
  import { useDataStyleState } from "./state";
16
16
  import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
@@ -32,7 +32,7 @@ export function useSceneStyle(): {
32
32
  const viewerStore = useViewerStore();
33
33
  const hybridViewerStore = useHybridViewerStore();
34
34
  const { sceneStyle } = useDataStyleState();
35
- const sceneStyleTable = getTable<SceneStyle>("scene_style");
35
+ const sceneStyleTable = sceneStyleDb();
36
36
 
37
37
  async function saveSceneStyle(values: Partial<Omit<SceneStyle, "id">>): Promise<void> {
38
38
  // Values may hold nested reactive proxies (e.g. an exported snapshot), which IndexedDB cannot clone
@@ -2,13 +2,17 @@ import type {
2
2
  ModelComponentStyle,
3
3
  ModelComponentTypeStyle,
4
4
  ObjectStyle,
5
- SceneStyle,
6
5
  StyleValues,
7
6
  } from "./types";
8
7
  import { type SharedState, getSharedState } from "./state_shared";
8
+ import {
9
+ componentDataStyleDb,
10
+ componentTypeDataStyleDb,
11
+ dataStyleDb,
12
+ sceneStyleDb,
13
+ } from "@ogw_internal/database/database";
9
14
  import type { ModelId } from "@ogw_front/types/identifiers";
10
15
  import { getDefaultSceneStyle } from "@ogw_front/utils/default_styles";
11
- import { getTable } from "@ogw_internal/database/database";
12
16
  import merge from "lodash/merge";
13
17
 
14
18
  interface DataStyleStateApi extends SharedState {
@@ -23,11 +27,9 @@ interface DataStyleStateApi extends SharedState {
23
27
 
24
28
  // oxlint-disable-next-line max-lines-per-function
25
29
  export function useDataStyleState(): DataStyleStateApi {
26
- const dataStyleTable = getTable<ObjectStyle>("data_style");
27
- const modelComponentDataStyleTable = getTable<ModelComponentStyle>("model_component_datastyle");
28
- const modelComponentTypeDataStyleTable = getTable<ModelComponentTypeStyle>(
29
- "model_component_type_datastyle",
30
- );
30
+ const dataStyleTable = dataStyleDb();
31
+ const modelComponentDataStyleTable = componentDataStyleDb();
32
+ const modelComponentTypeDataStyleTable = componentTypeDataStyleDb();
31
33
 
32
34
  const state = getSharedState();
33
35
  const { styles, modelComponentTypeStyles, componentStyles } = state;
@@ -86,7 +88,7 @@ export function useDataStyleState(): DataStyleStateApi {
86
88
  dataStyleTable.clear(),
87
89
  modelComponentDataStyleTable.clear(),
88
90
  modelComponentTypeDataStyleTable.clear(),
89
- getTable<SceneStyle>("scene_style").clear(),
91
+ sceneStyleDb().clear(),
90
92
  ]);
91
93
  modelComponentTypeStyles.value = {};
92
94
  componentStyles.value = {};
@@ -5,10 +5,15 @@ import type {
5
5
  SceneStyle,
6
6
  StyleValues,
7
7
  } from "./types";
8
+ import {
9
+ componentDataStyleDb,
10
+ componentTypeDataStyleDb,
11
+ dataStyleDb,
12
+ sceneStyleDb,
13
+ } from "@ogw_internal/database/database";
8
14
  import type { ModelId } from "@ogw_front/types/identifiers";
9
15
  import type { Observable as RxObservable } from "rxjs";
10
16
  import { getDefaultSceneStyle } from "@ogw_front/utils/default_styles";
11
- import { getTable } from "@ogw_internal/database/database";
12
17
  import { liveQuery } from "dexie";
13
18
  import merge from "lodash/merge";
14
19
  import { useObservable } from "@vueuse/rxjs";
@@ -52,11 +57,9 @@ function getSharedState(): SharedState {
52
57
  return sharedState;
53
58
  }
54
59
 
55
- const dataStyleTable = getTable<ObjectStyle>("data_style");
56
- const modelComponentDataStyleTable = getTable<ModelComponentStyle>("model_component_datastyle");
57
- const modelComponentTypeDataStyleTable = getTable<ModelComponentTypeStyle>(
58
- "model_component_type_datastyle",
59
- );
60
+ const dataStyleTable = dataStyleDb();
61
+ const modelComponentDataStyleTable = componentDataStyleDb();
62
+ const modelComponentTypeDataStyleTable = componentTypeDataStyleDb();
60
63
 
61
64
  // Dexie's `liveQuery` returns Dexie's own `Observable` type, structurally distinct
62
65
  // From rxjs's `Observable` that `useObservable` (from @vueuse/rxjs) expects, even
@@ -78,7 +81,7 @@ function getSharedState(): SharedState {
78
81
 
79
82
  const modelComponentTypeStyles = ref<Record<string, ModelComponentTypeStyle>>({});
80
83
  const componentStyles = ref<Record<string, ModelComponentStyle>>({});
81
- const sceneStyleTable = getTable<SceneStyle>("scene_style");
84
+ const sceneStyleTable = sceneStyleDb();
82
85
  const sceneStyle = ref<SceneStyle>(getDefaultSceneStyle());
83
86
 
84
87
  async function loadFromDatabase(): Promise<void> {