@cratis/scene.engine 4.25.0 → 4.27.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.
Files changed (223) hide show
  1. package/dist/cjs/editing/resolveEffectiveConfiguration.js +8 -0
  2. package/dist/cjs/editing/resolveEffectiveConfiguration.js.map +1 -1
  3. package/dist/cjs/index.js +64 -0
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/navigation/NavigationDiagnosticCode.js +5 -0
  6. package/dist/cjs/navigation/NavigationDiagnosticCode.js.map +1 -1
  7. package/dist/cjs/navigation/NavigationEditKind.js +16 -0
  8. package/dist/cjs/navigation/NavigationEditKind.js.map +1 -0
  9. package/dist/cjs/navigation/NavigationItemOrigin.js +14 -0
  10. package/dist/cjs/navigation/NavigationItemOrigin.js.map +1 -0
  11. package/dist/cjs/navigation/NavigationSourcesKind.js +16 -0
  12. package/dist/cjs/navigation/NavigationSourcesKind.js.map +1 -0
  13. package/dist/cjs/navigation/diagnoseNavigation.js +8 -1
  14. package/dist/cjs/navigation/diagnoseNavigation.js.map +1 -1
  15. package/dist/cjs/navigation/diagnoseNavigationRegions.js +99 -0
  16. package/dist/cjs/navigation/diagnoseNavigationRegions.js.map +1 -0
  17. package/dist/cjs/navigation/effectiveNavigation.js +133 -0
  18. package/dist/cjs/navigation/effectiveNavigation.js.map +1 -0
  19. package/dist/cjs/navigation/navigationEdits.js +230 -0
  20. package/dist/cjs/navigation/navigationEdits.js.map +1 -0
  21. package/dist/cjs/navigation/navigationRegions.js +42 -0
  22. package/dist/cjs/navigation/navigationRegions.js.map +1 -0
  23. package/dist/cjs/sampleData/SampleRandom.js +77 -0
  24. package/dist/cjs/sampleData/SampleRandom.js.map +1 -0
  25. package/dist/cjs/sampleData/describeSampleDataCatalog.js +61 -0
  26. package/dist/cjs/sampleData/describeSampleDataCatalog.js.map +1 -0
  27. package/dist/cjs/sampleData/findSampleDataSet.js +18 -0
  28. package/dist/cjs/sampleData/findSampleDataSet.js.map +1 -0
  29. package/dist/cjs/sampleData/findSampleRowLiterals.js +73 -0
  30. package/dist/cjs/sampleData/findSampleRowLiterals.js.map +1 -0
  31. package/dist/cjs/sampleData/generateSample.js +188 -0
  32. package/dist/cjs/sampleData/generateSample.js.map +1 -0
  33. package/dist/cjs/sampleData/inferSampleFieldKind.js +176 -0
  34. package/dist/cjs/sampleData/inferSampleFieldKind.js.map +1 -0
  35. package/dist/cjs/sampleData/resolveSampleData.js +107 -0
  36. package/dist/cjs/sampleData/resolveSampleData.js.map +1 -0
  37. package/dist/cjs/sampleData/sampleDataRules.js +26 -0
  38. package/dist/cjs/sampleData/sampleDataRules.js.map +1 -0
  39. package/dist/cjs/sampleData/sampleLocales.js +359 -0
  40. package/dist/cjs/sampleData/sampleLocales.js.map +1 -0
  41. package/dist/cjs/sampleData/validateSampleDataPack.js +44 -0
  42. package/dist/cjs/sampleData/validateSampleDataPack.js.map +1 -0
  43. package/dist/cjs/sampleData/validateSampleDataPackages.js +71 -0
  44. package/dist/cjs/sampleData/validateSampleDataPackages.js.map +1 -0
  45. package/dist/cjs/sampleData/validateSampleDataSelection.js +52 -0
  46. package/dist/cjs/sampleData/validateSampleDataSelection.js.map +1 -0
  47. package/dist/cjs/validateNavigationDestinations.js +2 -0
  48. package/dist/cjs/validateNavigationDestinations.js.map +1 -1
  49. package/dist/esm/editing/resolveEffectiveConfiguration.d.ts.map +1 -1
  50. package/dist/esm/editing/resolveEffectiveConfiguration.js +8 -0
  51. package/dist/esm/editing/resolveEffectiveConfiguration.js.map +1 -1
  52. package/dist/esm/index.d.ts +1 -0
  53. package/dist/esm/index.d.ts.map +1 -1
  54. package/dist/esm/index.js +19 -0
  55. package/dist/esm/index.js.map +1 -1
  56. package/dist/esm/navigation/EffectiveNavItem.d.ts +14 -0
  57. package/dist/esm/navigation/EffectiveNavItem.d.ts.map +1 -0
  58. package/dist/esm/navigation/EffectiveNavItem.js +2 -0
  59. package/dist/esm/navigation/EffectiveNavItem.js.map +1 -0
  60. package/dist/esm/navigation/EffectiveNavigationRegion.d.ts +11 -0
  61. package/dist/esm/navigation/EffectiveNavigationRegion.d.ts.map +1 -0
  62. package/dist/esm/navigation/EffectiveNavigationRegion.js +2 -0
  63. package/dist/esm/navigation/EffectiveNavigationRegion.js.map +1 -0
  64. package/dist/esm/navigation/NavigationDiagnosticCode.d.ts +6 -1
  65. package/dist/esm/navigation/NavigationDiagnosticCode.d.ts.map +1 -1
  66. package/dist/esm/navigation/NavigationDiagnosticCode.js +5 -0
  67. package/dist/esm/navigation/NavigationDiagnosticCode.js.map +1 -1
  68. package/dist/esm/navigation/NavigationEdit.d.ts +13 -0
  69. package/dist/esm/navigation/NavigationEdit.d.ts.map +1 -0
  70. package/dist/esm/navigation/NavigationEdit.js +2 -0
  71. package/dist/esm/navigation/NavigationEdit.js.map +1 -0
  72. package/dist/esm/navigation/NavigationEditKind.d.ts +7 -0
  73. package/dist/esm/navigation/NavigationEditKind.d.ts.map +1 -0
  74. package/dist/esm/navigation/NavigationEditKind.js +14 -0
  75. package/dist/esm/navigation/NavigationEditKind.js.map +1 -0
  76. package/dist/esm/navigation/NavigationEditOutcome.d.ts +7 -0
  77. package/dist/esm/navigation/NavigationEditOutcome.d.ts.map +1 -0
  78. package/dist/esm/navigation/NavigationEditOutcome.js +2 -0
  79. package/dist/esm/navigation/NavigationEditOutcome.js.map +1 -0
  80. package/dist/esm/navigation/NavigationEditPlan.d.ts +6 -0
  81. package/dist/esm/navigation/NavigationEditPlan.d.ts.map +1 -0
  82. package/dist/esm/navigation/NavigationEditPlan.js +2 -0
  83. package/dist/esm/navigation/NavigationEditPlan.js.map +1 -0
  84. package/dist/esm/navigation/NavigationGraph.d.ts +4 -1
  85. package/dist/esm/navigation/NavigationGraph.d.ts.map +1 -1
  86. package/dist/esm/navigation/NavigationItemOrigin.d.ts +5 -0
  87. package/dist/esm/navigation/NavigationItemOrigin.d.ts.map +1 -0
  88. package/dist/esm/navigation/NavigationItemOrigin.js +12 -0
  89. package/dist/esm/navigation/NavigationItemOrigin.js.map +1 -0
  90. package/dist/esm/navigation/NavigationSources.d.ts +6 -0
  91. package/dist/esm/navigation/NavigationSources.d.ts.map +1 -0
  92. package/dist/esm/navigation/NavigationSources.js +2 -0
  93. package/dist/esm/navigation/NavigationSources.js.map +1 -0
  94. package/dist/esm/navigation/NavigationSourcesKind.d.ts +7 -0
  95. package/dist/esm/navigation/NavigationSourcesKind.d.ts.map +1 -0
  96. package/dist/esm/navigation/NavigationSourcesKind.js +14 -0
  97. package/dist/esm/navigation/NavigationSourcesKind.js.map +1 -0
  98. package/dist/esm/navigation/ResolvedNavigationTarget.d.ts +6 -0
  99. package/dist/esm/navigation/ResolvedNavigationTarget.d.ts.map +1 -0
  100. package/dist/esm/navigation/ResolvedNavigationTarget.js +2 -0
  101. package/dist/esm/navigation/ResolvedNavigationTarget.js.map +1 -0
  102. package/dist/esm/navigation/diagnoseNavigation.d.ts.map +1 -1
  103. package/dist/esm/navigation/diagnoseNavigation.js +8 -1
  104. package/dist/esm/navigation/diagnoseNavigation.js.map +1 -1
  105. package/dist/esm/navigation/diagnoseNavigationRegions.d.ts +8 -0
  106. package/dist/esm/navigation/diagnoseNavigationRegions.d.ts.map +1 -0
  107. package/dist/esm/navigation/diagnoseNavigationRegions.js +97 -0
  108. package/dist/esm/navigation/diagnoseNavigationRegions.js.map +1 -0
  109. package/dist/esm/navigation/effectiveNavigation.d.ts +5 -0
  110. package/dist/esm/navigation/effectiveNavigation.d.ts.map +1 -0
  111. package/dist/esm/navigation/effectiveNavigation.js +131 -0
  112. package/dist/esm/navigation/effectiveNavigation.js.map +1 -0
  113. package/dist/esm/navigation/index.d.ts +14 -0
  114. package/dist/esm/navigation/index.d.ts.map +1 -1
  115. package/dist/esm/navigation/index.js +14 -0
  116. package/dist/esm/navigation/index.js.map +1 -1
  117. package/dist/esm/navigation/navigationEdits.d.ts +11 -0
  118. package/dist/esm/navigation/navigationEdits.d.ts.map +1 -0
  119. package/dist/esm/navigation/navigationEdits.js +225 -0
  120. package/dist/esm/navigation/navigationEdits.js.map +1 -0
  121. package/dist/esm/navigation/navigationRegions.d.ts +9 -0
  122. package/dist/esm/navigation/navigationRegions.d.ts.map +1 -0
  123. package/dist/esm/navigation/navigationRegions.js +34 -0
  124. package/dist/esm/navigation/navigationRegions.js.map +1 -0
  125. package/dist/esm/sampleData/SampleDataPackSource.d.ts +6 -0
  126. package/dist/esm/sampleData/SampleDataPackSource.d.ts.map +1 -0
  127. package/dist/esm/sampleData/SampleDataPackSource.js +2 -0
  128. package/dist/esm/sampleData/SampleDataPackSource.js.map +1 -0
  129. package/dist/esm/sampleData/SampleDataResolution.d.ts +29 -0
  130. package/dist/esm/sampleData/SampleDataResolution.d.ts.map +1 -0
  131. package/dist/esm/sampleData/SampleDataResolution.js +2 -0
  132. package/dist/esm/sampleData/SampleDataResolution.js.map +1 -0
  133. package/dist/esm/sampleData/SampleRandom.d.ts +14 -0
  134. package/dist/esm/sampleData/SampleRandom.d.ts.map +1 -0
  135. package/dist/esm/sampleData/SampleRandom.js +72 -0
  136. package/dist/esm/sampleData/SampleRandom.js.map +1 -0
  137. package/dist/esm/sampleData/describeSampleDataCatalog.d.ts +24 -0
  138. package/dist/esm/sampleData/describeSampleDataCatalog.d.ts.map +1 -0
  139. package/dist/esm/sampleData/describeSampleDataCatalog.js +57 -0
  140. package/dist/esm/sampleData/describeSampleDataCatalog.js.map +1 -0
  141. package/dist/esm/sampleData/findSampleDataSet.d.ts +3 -0
  142. package/dist/esm/sampleData/findSampleDataSet.d.ts.map +1 -0
  143. package/dist/esm/sampleData/findSampleDataSet.js +16 -0
  144. package/dist/esm/sampleData/findSampleDataSet.js.map +1 -0
  145. package/dist/esm/sampleData/findSampleRowLiterals.d.ts +11 -0
  146. package/dist/esm/sampleData/findSampleRowLiterals.d.ts.map +1 -0
  147. package/dist/esm/sampleData/findSampleRowLiterals.js +69 -0
  148. package/dist/esm/sampleData/findSampleRowLiterals.js.map +1 -0
  149. package/dist/esm/sampleData/generateSample.d.ts +6 -0
  150. package/dist/esm/sampleData/generateSample.d.ts.map +1 -0
  151. package/dist/esm/sampleData/generateSample.js +183 -0
  152. package/dist/esm/sampleData/generateSample.js.map +1 -0
  153. package/dist/esm/sampleData/index.d.ts +15 -0
  154. package/dist/esm/sampleData/index.d.ts.map +1 -0
  155. package/dist/esm/sampleData/index.js +15 -0
  156. package/dist/esm/sampleData/index.js.map +1 -0
  157. package/dist/esm/sampleData/inferSampleFieldKind.d.ts +3 -0
  158. package/dist/esm/sampleData/inferSampleFieldKind.d.ts.map +1 -0
  159. package/dist/esm/sampleData/inferSampleFieldKind.js +174 -0
  160. package/dist/esm/sampleData/inferSampleFieldKind.js.map +1 -0
  161. package/dist/esm/sampleData/resolveSampleData.d.ts +3 -0
  162. package/dist/esm/sampleData/resolveSampleData.d.ts.map +1 -0
  163. package/dist/esm/sampleData/resolveSampleData.js +105 -0
  164. package/dist/esm/sampleData/resolveSampleData.js.map +1 -0
  165. package/dist/esm/sampleData/sampleDataRules.d.ts +7 -0
  166. package/dist/esm/sampleData/sampleDataRules.d.ts.map +1 -0
  167. package/dist/esm/sampleData/sampleDataRules.js +19 -0
  168. package/dist/esm/sampleData/sampleDataRules.js.map +1 -0
  169. package/dist/esm/sampleData/sampleLocales.d.ts +13 -0
  170. package/dist/esm/sampleData/sampleLocales.d.ts.map +1 -0
  171. package/dist/esm/sampleData/sampleLocales.js +355 -0
  172. package/dist/esm/sampleData/sampleLocales.js.map +1 -0
  173. package/dist/esm/sampleData/validateSampleDataPack.d.ts +3 -0
  174. package/dist/esm/sampleData/validateSampleDataPack.d.ts.map +1 -0
  175. package/dist/esm/sampleData/validateSampleDataPack.js +42 -0
  176. package/dist/esm/sampleData/validateSampleDataPack.js.map +1 -0
  177. package/dist/esm/sampleData/validateSampleDataPackages.d.ts +3 -0
  178. package/dist/esm/sampleData/validateSampleDataPackages.d.ts.map +1 -0
  179. package/dist/esm/sampleData/validateSampleDataPackages.js +69 -0
  180. package/dist/esm/sampleData/validateSampleDataPackages.js.map +1 -0
  181. package/dist/esm/sampleData/validateSampleDataSelection.d.ts +3 -0
  182. package/dist/esm/sampleData/validateSampleDataSelection.d.ts.map +1 -0
  183. package/dist/esm/sampleData/validateSampleDataSelection.js +50 -0
  184. package/dist/esm/sampleData/validateSampleDataSelection.js.map +1 -0
  185. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  186. package/dist/esm/validateNavigationDestinations.js +2 -0
  187. package/dist/esm/validateNavigationDestinations.js.map +1 -1
  188. package/editing/resolveEffectiveConfiguration.ts +13 -0
  189. package/index.ts +1 -0
  190. package/navigation/EffectiveNavItem.ts +37 -0
  191. package/navigation/EffectiveNavigationRegion.ts +26 -0
  192. package/navigation/NavigationDiagnosticCode.ts +15 -0
  193. package/navigation/NavigationEdit.ts +36 -0
  194. package/navigation/NavigationEditKind.ts +19 -0
  195. package/navigation/NavigationEditOutcome.ts +18 -0
  196. package/navigation/NavigationEditPlan.ts +15 -0
  197. package/navigation/NavigationGraph.ts +10 -1
  198. package/navigation/NavigationItemOrigin.ts +13 -0
  199. package/navigation/NavigationSources.ts +15 -0
  200. package/navigation/NavigationSourcesKind.ts +19 -0
  201. package/navigation/ResolvedNavigationTarget.ts +19 -0
  202. package/navigation/diagnoseNavigation.ts +7 -1
  203. package/navigation/diagnoseNavigationRegions.ts +122 -0
  204. package/navigation/effectiveNavigation.ts +105 -0
  205. package/navigation/index.ts +14 -0
  206. package/navigation/navigationEdits.ts +176 -0
  207. package/navigation/navigationRegions.ts +39 -0
  208. package/package.json +3 -3
  209. package/sampleData/SampleDataPackSource.ts +13 -0
  210. package/sampleData/SampleDataResolution.ts +93 -0
  211. package/sampleData/SampleRandom.ts +85 -0
  212. package/sampleData/describeSampleDataCatalog.ts +108 -0
  213. package/sampleData/findSampleDataSet.ts +18 -0
  214. package/sampleData/findSampleRowLiterals.ts +86 -0
  215. package/sampleData/generateSample.ts +156 -0
  216. package/sampleData/index.ts +17 -0
  217. package/sampleData/inferSampleFieldKind.ts +64 -0
  218. package/sampleData/resolveSampleData.ts +96 -0
  219. package/sampleData/sampleDataRules.ts +30 -0
  220. package/sampleData/sampleLocales.ts +91 -0
  221. package/sampleData/validateSampleDataPack.ts +48 -0
  222. package/sampleData/validateSampleDataPackages.ts +79 -0
  223. package/sampleData/validateSampleDataSelection.ts +55 -0
@@ -0,0 +1,176 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { ApplicationLogo, NavigationModel, NavigationRegion, NavigationRegionKind, NavigationRegionMode, NavItem } from '@cratis/scene.model';
5
+ import { NavigationEdit } from './NavigationEdit';
6
+ import { NavigationEditKind } from './NavigationEditKind';
7
+ import { NavigationEditOutcome } from './NavigationEditOutcome';
8
+ import { NavigationEditPlan } from './NavigationEditPlan';
9
+ import { applicationItems, collectItemIds, findModuleNavigation, findNavigationRegion, modeOfModuleRegion } from './navigationRegions';
10
+
11
+ const noMode = 'The application is the base of the navigation and has no region mode.';
12
+ const logoLevel = 'The logo is defined at the application level only.';
13
+ const flatTopbar = 'A topbar is flat; only a sidebar item has sub-items.';
14
+
15
+ /**
16
+ * Plans a change of a module region's mode. Switching to `inherit` clears the module's items (NAV3); switching from
17
+ * `inherit` to `override` with `copy` first copies the application's items so the module starts from them (NAV5).
18
+ * @param navigation The navigation as it is.
19
+ * @param module The module whose region changes; the application has no mode and is refused.
20
+ * @param region The region.
21
+ * @param mode The mode to switch to.
22
+ * @param options `copy` copies the application items when switching from inherit to override.
23
+ */
24
+ export function switchRegionMode(
25
+ navigation: NavigationModel,
26
+ module: string | undefined,
27
+ region: NavigationRegionKind,
28
+ mode: NavigationRegionMode,
29
+ options: { copy?: boolean } = {},
30
+ ): NavigationEditPlan {
31
+ if (module === undefined) return { edits: [], rejected: noMode };
32
+
33
+ const current = modeOfModuleRegion(navigation, module, region);
34
+ if (current === mode) return { edits: [] };
35
+
36
+ const setMode: NavigationEdit = { kind: NavigationEditKind.SetRegionMode, module, region, mode };
37
+ if (mode === NavigationRegionMode.Inherit) {
38
+ return { edits: [{ kind: NavigationEditKind.SetRegionItems, module, region, items: [] }, setMode] };
39
+ }
40
+
41
+ if (mode === NavigationRegionMode.Override && current === NavigationRegionMode.Inherit && options.copy === true) {
42
+ return { edits: [{ kind: NavigationEditKind.SetRegionItems, module, region, items: structuredClone(applicationItems(navigation.application, region)) }, setMode] };
43
+ }
44
+
45
+ return { edits: [setMode] };
46
+ }
47
+
48
+ /**
49
+ * Plans adding an item to a region, after the ones already there. Adding to an inheriting module region first
50
+ * switches it to `extend` (NAV6), so the application's items stay and the new item follows them.
51
+ * @param navigation The navigation as it is.
52
+ * @param module The module that gets the item; undefined for the application.
53
+ * @param region The region.
54
+ * @param item The item to add.
55
+ * @param parent The id of the item it becomes a sub-item of; sidebar only.
56
+ */
57
+ export function addNavItem(
58
+ navigation: NavigationModel,
59
+ module: string | undefined,
60
+ region: NavigationRegionKind,
61
+ item: NavItem,
62
+ parent?: string,
63
+ ): NavigationEditPlan {
64
+ if (parent !== undefined && region !== NavigationRegionKind.Sidebar) return { edits: [], rejected: flatTopbar };
65
+
66
+ const own = ownItems(navigation, module, region);
67
+ const ids = collectItemIds(own, region);
68
+ if (ids.includes(item.id)) return { edits: [], rejected: `Navigation item id '${item.id}' is already used in this region.` };
69
+ if (parent !== undefined && !ids.includes(parent)) return { edits: [], rejected: `There is no item '${parent}' to add a sub-item to.` };
70
+
71
+ const add: NavigationEdit = { kind: NavigationEditKind.AddItem, module, region, item: structuredClone(item) };
72
+ if (parent !== undefined) add.parent = parent;
73
+ if (module !== undefined && modeOfModuleRegion(navigation, module, region) === NavigationRegionMode.Inherit) {
74
+ return { edits: [{ kind: NavigationEditKind.SetRegionMode, module, region, mode: NavigationRegionMode.Extend }, add] };
75
+ }
76
+
77
+ return { edits: [add] };
78
+ }
79
+
80
+ /**
81
+ * Plans setting the logo. The logo is defined at the application level only, so a module is refused.
82
+ * @param navigation The navigation as it is.
83
+ * @param module The module asking; only undefined (the application) is allowed.
84
+ * @param logo The logo.
85
+ */
86
+ export function setApplicationLogo(navigation: NavigationModel, module: string | undefined, logo: ApplicationLogo): NavigationEditPlan {
87
+ void navigation;
88
+ return module === undefined ? { edits: [{ kind: NavigationEditKind.SetLogo, logo: { ...logo } }] } : { edits: [], rejected: logoLevel };
89
+ }
90
+
91
+ /**
92
+ * Applies navigation edits to a copy of the model. Either every edit applies, or none does.
93
+ * @param navigation The navigation as it is; never changed.
94
+ * @param edits The edits, in order.
95
+ */
96
+ export function applyNavigationEdits(navigation: NavigationModel, edits: NavigationEdit[]): NavigationEditOutcome {
97
+ const model = structuredClone(navigation);
98
+ for (const edit of edits) {
99
+ const rejected = apply(model, edit);
100
+ if (rejected !== undefined) return { applied: false, model: navigation, rejected };
101
+ }
102
+
103
+ return { applied: true, model };
104
+ }
105
+
106
+ function ownItems(navigation: NavigationModel, module: string | undefined, region: NavigationRegionKind): NavItem[] {
107
+ return module === undefined
108
+ ? applicationItems(navigation.application, region)
109
+ : findNavigationRegion(findModuleNavigation(navigation, module)?.regions, region)?.items ?? [];
110
+ }
111
+
112
+ function regionOf(model: NavigationModel, module: string | undefined, region: NavigationRegionKind): NavigationRegion {
113
+ let regions: NavigationRegion[];
114
+ if (module === undefined) {
115
+ regions = model.application.regions;
116
+ } else {
117
+ let block = findModuleNavigation(model, module);
118
+ if (!block) {
119
+ block = { module, regions: [] };
120
+ model.modules.push(block);
121
+ }
122
+
123
+ regions = block.regions;
124
+ }
125
+
126
+ let found = findNavigationRegion(regions, region);
127
+ if (!found) {
128
+ found = { region, items: [] };
129
+ regions.push(found);
130
+ }
131
+
132
+ return found;
133
+ }
134
+
135
+ function apply(model: NavigationModel, edit: NavigationEdit): string | undefined {
136
+ switch (edit.kind) {
137
+ case NavigationEditKind.SetRegionMode:
138
+ if (edit.module === undefined) return noMode;
139
+ regionOf(model, edit.module, edit.region!).mode = edit.mode;
140
+ return undefined;
141
+ case NavigationEditKind.SetRegionItems:
142
+ regionOf(model, edit.module, edit.region!).items = structuredClone(edit.items ?? []);
143
+ return undefined;
144
+ case NavigationEditKind.AddItem: {
145
+ const target = regionOf(model, edit.module, edit.region!);
146
+ const item = structuredClone(edit.item!);
147
+ if (collectItemIds(target.items, target.region).includes(item.id)) return `Navigation item id '${item.id}' is already used in this region.`;
148
+ if (edit.parent === undefined) {
149
+ target.items.push(item);
150
+ return undefined;
151
+ }
152
+
153
+ if (target.region !== NavigationRegionKind.Sidebar) return flatTopbar;
154
+ const owner = findItem(target.items, edit.parent);
155
+ if (!owner) return `There is no item '${edit.parent}' to add a sub-item to.`;
156
+ (owner.children ??= []).push(item);
157
+ return undefined;
158
+ }
159
+ case NavigationEditKind.SetLogo:
160
+ if (edit.module !== undefined) return logoLevel;
161
+ model.application.logo = { ...edit.logo! };
162
+ return undefined;
163
+ default:
164
+ return `'${String((edit as NavigationEdit).kind)}' is not a navigation edit.`;
165
+ }
166
+ }
167
+
168
+ function findItem(items: NavItem[], id: string): NavItem | undefined {
169
+ for (const item of items) {
170
+ if (item.id === id) return item;
171
+ const nested = findItem(item.children ?? [], id);
172
+ if (nested) return nested;
173
+ }
174
+
175
+ return undefined;
176
+ }
@@ -0,0 +1,39 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { ApplicationNavigation, ModuleNavigation, NavigationModel, NavigationRegion, NavigationRegionKind, NavigationRegionMode, NavItem } from '@cratis/scene.model';
5
+
6
+ /** The regions in the order every result lists them. */
7
+ export const navigationRegionOrder: NavigationRegionKind[] = [NavigationRegionKind.Topbar, NavigationRegionKind.Sidebar];
8
+
9
+ /** The slot an item renders into when it names none: the primary outlet. */
10
+ export const primarySlot = 'content';
11
+
12
+ /**
13
+ * Finds the items a level defines for a region.
14
+ * @param regions The regions of the application or of a module.
15
+ * @param region The region to look for.
16
+ */
17
+ export function findNavigationRegion(regions: NavigationRegion[] | undefined, region: NavigationRegionKind): NavigationRegion | undefined {
18
+ return regions?.find(candidate => candidate.region === region);
19
+ }
20
+
21
+ /** Finds what a module declares; undefined when it declares nothing. */
22
+ export function findModuleNavigation(navigation: NavigationModel, module: string): ModuleNavigation | undefined {
23
+ return navigation.modules.find(candidate => candidate.module === module);
24
+ }
25
+
26
+ /** The mode of a module's region: `inherit` when the module does not declare the region or its mode. */
27
+ export function modeOfModuleRegion(navigation: NavigationModel, module: string, region: NavigationRegionKind): NavigationRegionMode {
28
+ return findNavigationRegion(findModuleNavigation(navigation, module)?.regions, region)?.mode ?? NavigationRegionMode.Inherit;
29
+ }
30
+
31
+ /** The application-level items of a region. */
32
+ export function applicationItems(application: ApplicationNavigation, region: NavigationRegionKind): NavItem[] {
33
+ return findNavigationRegion(application.regions, region)?.items ?? [];
34
+ }
35
+
36
+ /** Every id in a list of items, depth first. Sub-items count only in the sidebar. */
37
+ export function collectItemIds(items: NavItem[], region: NavigationRegionKind): string[] {
38
+ return items.flatMap(item => [item.id, ...(region === NavigationRegionKind.Sidebar ? collectItemIds(item.children ?? [], region) : [])]);
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/scene.engine",
3
- "version": "4.25.0",
3
+ "version": "4.27.0",
4
4
  "description": "The Scene runtime: walks a Scene element tree and drives whichever renderer is plugged in. Does not know React, or any other rendering platform, exists.",
5
5
  "keywords": [
6
6
  "cratis",
@@ -48,9 +48,9 @@
48
48
  "up": "yarn g:up"
49
49
  },
50
50
  "dependencies": {
51
- "@cratis/scene.model": "4.25.0"
51
+ "@cratis/scene.model": "4.27.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@cratis/scene.model": "4.25.0"
54
+ "@cratis/scene.model": "4.27.0"
55
55
  }
56
56
  }
@@ -0,0 +1,13 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { SampleDataPack, ScenePackage } from '@cratis/scene.model';
5
+
6
+ /**
7
+ * A package and the sample-data packs it ships, loaded. A React `ScenePackageBundle` already has the manifest;
8
+ * hosts add the loaded packs the manifest's `sampleData` references point to.
9
+ */
10
+ export interface SampleDataPackSource {
11
+ manifest: ScenePackage;
12
+ packs?: SampleDataPack[];
13
+ }
@@ -0,0 +1,93 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { SampleDataPack, SampleShape, UiProfile } from '@cratis/scene.model';
5
+
6
+ /** Which rung of the resolution order supplied the rows. */
7
+ export type SampleDataResolutionSource =
8
+ /** A pack explicitly bound to the read model or shape. */
9
+ | 'binding'
10
+ /** The application's active pack: the profile's `sampleData.activePack`, or the session override. */
11
+ | 'activePack'
12
+ /** The default pack of the blueprint the template came from. */
13
+ | 'blueprintDefault'
14
+ /** Generated, typed by field kind. */
15
+ | 'generated'
16
+ /** Not resolved, because the host is not in design or preview mode (SD6). */
17
+ | 'disabled'
18
+ /** No pack had rows and no shape was given to generate from. */
19
+ | 'none';
20
+
21
+ /** What is being asked for: rows for a read model or shape. */
22
+ export interface SampleDataRequest {
23
+ /** The read model or shape name; defaults to the `shape`'s name when only a shape is given. */
24
+ target?: string;
25
+
26
+ /** The shape of one row; needed for the generated rung to produce anything. */
27
+ shape?: SampleShape;
28
+ }
29
+
30
+ /** What the host knows when it asks for sample data. */
31
+ export interface SampleDataContext {
32
+ /** Every pack available: blueprint packs and the author's own. */
33
+ packs: SampleDataPack[];
34
+
35
+ /**
36
+ * The application's UI profile, whose `sampleData` is the one place the active pack is chosen (plus the
37
+ * rare mappings and bindings). Absent, or a profile without `sampleData`, behaves as no active pack, no
38
+ * mappings and no bindings.
39
+ */
40
+ profile?: Pick<UiProfile, 'sampleData'>;
41
+
42
+ /**
43
+ * A session-only override of the profile's active pack, as the preview strip's selector sets it: a pack
44
+ * id replaces `profile.sampleData.activePack`, the empty string (the generated entry's id) means no
45
+ * active pack, and `undefined` (absent) leaves the profile's choice. It is never a second source of truth: it is not stored, and bindings and
46
+ * mappings still come from the profile.
47
+ */
48
+ sessionActivePack?: string;
49
+
50
+ /** The default pack of the blueprint the template came from. */
51
+ blueprintDefaultPack?: string;
52
+
53
+ /** The locale of generated data when no pack supplies one; defaults to `en-GB`. */
54
+ locale?: string;
55
+
56
+ /** The seed for generated data; defaults to 1 so previews are stable. */
57
+ seed?: number;
58
+
59
+ /** The number of generated rows; defaults to 5. */
60
+ rowCount?: number;
61
+
62
+ /**
63
+ * Whether the host is design time or preview. Sample data resolves only when this is true; a Stage
64
+ * production build leaves it false (the default) and gets nothing (SD6).
65
+ */
66
+ isDesignOrPreview?: boolean;
67
+ }
68
+
69
+ /** A problem found while resolving, which never stops the resolution falling through to the next rung. */
70
+ export interface SampleDataDiagnostic {
71
+ /** `packNotFound` or `shapeNotInPack`. */
72
+ code: string;
73
+ message: string;
74
+ }
75
+
76
+ /** The outcome of {@link resolveSampleData}. */
77
+ export interface SampleDataResolution {
78
+ /** Which rung supplied the rows. */
79
+ source: SampleDataResolutionSource;
80
+
81
+ /** The identity of the pack that supplied the rows; absent for generated, disabled and none. */
82
+ pack?: string;
83
+
84
+ /** The locale of the data: the pack's, or the one generated data followed. */
85
+ locale: string;
86
+
87
+ /** The shape name the rows belong to. */
88
+ shape?: string;
89
+
90
+ rows: Record<string, unknown>[];
91
+
92
+ diagnostics: SampleDataDiagnostic[];
93
+ }
@@ -0,0 +1,85 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ /**
5
+ * The pseudo-random generator behind generated sample data. The C# engine implements the identical
6
+ * algorithm, and both are asserted against golden rows in `sample-data-resolution-fixtures.json`.
7
+ *
8
+ * Algorithm (all arithmetic on unsigned 32-bit integers, wrapping):
9
+ *
10
+ * - `hash32(x)`: `x = (x ^ (x >>> 16)) * 0x85EBCA6B; x = (x ^ (x >>> 13)) * 0xC2B2AE35; return x ^ (x >>> 16)`.
11
+ * - `splitmix32(state)`: `state += 0x9E3779B9`, then `hash32(state)`.
12
+ * - `fnv1a32(text)`: FNV-1a over the UTF-8 bytes of the text (offset basis `0x811C9DC5`, prime `0x01000193`).
13
+ * - The generator is xoshiro128** seeded with four consecutive `splitmix32` outputs of the seed.
14
+ * - `nextInt(bound)` is `next() % bound`.
15
+ * - Row `i` of a shape named `S` generated with seed `n` uses its own generator seeded with
16
+ * `hash32((n ^ fnv1a32(S)) + (i + 1) * 0x9E3779B9)`, so a row never depends on how many rows are asked for.
17
+ */
18
+ export function hash32(value: number): number {
19
+ let x = value >>> 0;
20
+ x = Math.imul(x ^ (x >>> 16), 0x85EBCA6B) >>> 0;
21
+ x = Math.imul(x ^ (x >>> 13), 0xC2B2AE35) >>> 0;
22
+ return (x ^ (x >>> 16)) >>> 0;
23
+ }
24
+
25
+ /** FNV-1a (32-bit) over the UTF-8 bytes of a string. */
26
+ export function fnv1a32(text: string): number {
27
+ let hash = 0x811C9DC5;
28
+ for (const byte of new TextEncoder().encode(text)) {
29
+ hash = Math.imul(hash ^ byte, 0x01000193) >>> 0;
30
+ }
31
+ return hash;
32
+ }
33
+
34
+ /** The seed of the generator for one row of one shape. */
35
+ export function rowSeed(seed: number, shapeName: string, rowIndex: number): number {
36
+ return hash32((((seed ^ fnv1a32(shapeName)) >>> 0) + Math.imul(rowIndex + 1, 0x9E3779B9)) >>> 0);
37
+ }
38
+
39
+ /** xoshiro128** with splitmix32 seeding. */
40
+ export class SampleRandom {
41
+ private s0: number;
42
+ private s1: number;
43
+ private s2: number;
44
+ private s3: number;
45
+
46
+ constructor(seed: number) {
47
+ let state = seed >>> 0;
48
+ const step = () => {
49
+ state = (state + 0x9E3779B9) >>> 0;
50
+ return hash32(state);
51
+ };
52
+ this.s0 = step();
53
+ this.s1 = step();
54
+ this.s2 = step();
55
+ this.s3 = step();
56
+ if ((this.s0 | this.s1 | this.s2 | this.s3) === 0) this.s0 = 1;
57
+ }
58
+
59
+ /** The next unsigned 32-bit value. */
60
+ next(): number {
61
+ const result = Math.imul(rotateLeft(Math.imul(this.s1, 5) >>> 0, 7), 9) >>> 0;
62
+ const t = (this.s1 << 9) >>> 0;
63
+ this.s2 = (this.s2 ^ this.s0) >>> 0;
64
+ this.s3 = (this.s3 ^ this.s1) >>> 0;
65
+ this.s1 = (this.s1 ^ this.s2) >>> 0;
66
+ this.s0 = (this.s0 ^ this.s3) >>> 0;
67
+ this.s2 = (this.s2 ^ t) >>> 0;
68
+ this.s3 = rotateLeft(this.s3, 11);
69
+ return result;
70
+ }
71
+
72
+ /** A value in `[0, bound)`; zero when the bound is zero. */
73
+ nextInt(bound: number): number {
74
+ return bound <= 0 ? 0 : this.next() % bound;
75
+ }
76
+
77
+ /** One element of a non-empty list. */
78
+ pick<T>(items: readonly T[]): T {
79
+ return items[this.nextInt(items.length)];
80
+ }
81
+ }
82
+
83
+ function rotateLeft(value: number, bits: number): number {
84
+ return ((value << bits) | (value >>> (32 - bits))) >>> 0;
85
+ }
@@ -0,0 +1,108 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { SampleDataPackReference, ScenePackage } from '@cratis/scene.model';
5
+ import { SampleDataPackSource } from './SampleDataPackSource';
6
+ import { validateSampleDataPackages } from './validateSampleDataPackages';
7
+
8
+ /** The separator between blueprint and pack in a label (`CRM · Nordic SMB`). */
9
+ export const sampleDataLabelSeparator = ' \u00b7 ';
10
+
11
+ /** One entry of the sample data selector. */
12
+ export interface SampleDataCatalogEntry {
13
+ /** The pack identity a selection stores as `activePack`; empty for the generated entry. */
14
+ id: string;
15
+
16
+ /** Whether this is the generated entry, the choice that stores no active pack. */
17
+ isGenerated: boolean;
18
+
19
+ /** The pack's name within its group (`Nordic SMB`). */
20
+ name: string;
21
+
22
+ /** The full label (`CRM · Nordic SMB`, or just the name for generated and own packs). */
23
+ label: string;
24
+
25
+ /** The locale tag, absent for the generated entry. */
26
+ locale?: string;
27
+
28
+ /** Whether it is the active pack (the generated entry is selected when no pack is active). */
29
+ selected: boolean;
30
+ }
31
+
32
+ /** A blueprint's packs, one group of the Blueprints submenu. */
33
+ export interface SampleDataCatalogGroup {
34
+ /** The blueprint's display name (`CRM`). */
35
+ blueprint: string;
36
+
37
+ packs: SampleDataCatalogEntry[];
38
+ }
39
+
40
+ /** The selector's content: generated, the author's own sets, then blueprint groups. */
41
+ export interface SampleDataCatalog {
42
+ /** `Generic (typed by field kind)`. */
43
+ generated: SampleDataCatalogEntry;
44
+
45
+ /** The author's own data sets, in the order given. */
46
+ own: SampleDataCatalogEntry[];
47
+
48
+ /** Blueprints that ship at least one pack, in package order; blueprints with none are not listed. */
49
+ blueprints: SampleDataCatalogGroup[];
50
+
51
+ /** Problems found validating what the packages ship. */
52
+ problems: string[];
53
+ }
54
+
55
+ /** The name of the generated entry. */
56
+ export const generatedSampleDataName = 'Generic (typed by field kind)';
57
+
58
+ /**
59
+ * Describes the sample data selector's content: the generated entry first, then the author's own packs, then
60
+ * each blueprint's packs grouped by the blueprint's display name (falling back to its package name). A pack
61
+ * whose title already starts with `<Blueprint> · ` shows the rest as its name, so `CRM · Nordic SMB` under
62
+ * `CRM` is `Nordic SMB`. Same own-first, then Blueprints menu pattern as the template picker (spec §11).
63
+ *
64
+ * @param sources The packages and the packs they ship (only their `sampleData` references are listed).
65
+ * @param ownPacks The author's own packs (id, title, locale).
66
+ * @param activePack The selection's active pack id, if any.
67
+ */
68
+ export function describeSampleDataCatalog(
69
+ sources: readonly SampleDataPackSource[],
70
+ ownPacks: readonly Pick<SampleDataPackReference, 'id' | 'title' | 'locale'>[] = [],
71
+ activePack?: string,
72
+ ): SampleDataCatalog {
73
+ const entry = (id: string, name: string, label: string, locale: string): SampleDataCatalogEntry => ({
74
+ id, isGenerated: false, name, label, locale, selected: id === activePack,
75
+ });
76
+
77
+ const blueprints: SampleDataCatalogGroup[] = [];
78
+ for (const source of sources) {
79
+ const references = source.manifest.sampleData ?? [];
80
+ if (references.length === 0) continue;
81
+ const group = groupName(source.manifest);
82
+ const prefix = `${group}${sampleDataLabelSeparator}`;
83
+ blueprints.push({
84
+ blueprint: group,
85
+ packs: references.map(reference => {
86
+ const name = reference.title.startsWith(prefix) ? reference.title.slice(prefix.length) : reference.title;
87
+ return entry(reference.id, name, `${group}${sampleDataLabelSeparator}${name}`, reference.locale);
88
+ }),
89
+ });
90
+ }
91
+
92
+ return {
93
+ generated: {
94
+ id: '',
95
+ isGenerated: true,
96
+ name: generatedSampleDataName,
97
+ label: generatedSampleDataName,
98
+ selected: activePack === undefined || activePack === null || activePack === '',
99
+ },
100
+ own: ownPacks.map(pack => entry(pack.id, pack.title, pack.title, pack.locale)),
101
+ blueprints,
102
+ problems: validateSampleDataPackages(sources),
103
+ };
104
+ }
105
+
106
+ function groupName(manifest: ScenePackage): string {
107
+ return manifest.displayName !== undefined && manifest.displayName.trim() !== '' ? manifest.displayName : manifest.name;
108
+ }
@@ -0,0 +1,18 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { SampleDataMapping, SampleDataPack, SampleDataSet } from '@cratis/scene.model';
5
+
6
+ /**
7
+ * Finds the set of a pack that supplies rows for a read model or shape. An explicit mapping whose read model is
8
+ * the target wins; otherwise a set whose shape has the target's name (compared exactly, case-sensitively).
9
+ */
10
+ export function findSampleDataSet(pack: SampleDataPack, target: string, mappings: readonly SampleDataMapping[] = []): SampleDataSet | undefined {
11
+ for (const mapping of mappings) {
12
+ if (mapping.readModel !== target) continue;
13
+ const mapped = (pack.sets ?? []).find(set => set.shape === mapping.shape);
14
+ if (mapped !== undefined) return mapped;
15
+ }
16
+
17
+ return (pack.sets ?? []).find(set => set.shape === target);
18
+ }
@@ -0,0 +1,86 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { ComponentDescriptor } from '@cratis/scene.model';
5
+
6
+ /**
7
+ * Finds sample-row literals inside a value: an array holding plain objects of two or more keys, which is what
8
+ * a hand-written list of demo rows looks like. Returns the path of each, e.g. `rows` or `items[2].children`.
9
+ * A single-key object is a choice or a token, not a row, and is not reported.
10
+ *
11
+ * Spec §11 SD1: components keep declaring shapes only, so a component descriptor's defaults and a template's
12
+ * properties must not carry row literals; demo rows belong to sample-data packs.
13
+ *
14
+ * @param value The value to inspect.
15
+ * @param path The path prefix of the value, empty for the root.
16
+ */
17
+ export function findSampleRowLiterals(value: unknown, path = ''): string[] {
18
+ const found: string[] = [];
19
+ if (Array.isArray(value)) {
20
+ if (value.some(isRow)) found.push(path === '' ? '(root)' : path);
21
+ value.forEach((item, index) => found.push(...findSampleRowLiterals(item, `${path}[${index}]`)));
22
+ } else if (typeof value === 'object' && value !== null) {
23
+ for (const [key, child] of Object.entries(value)) {
24
+ found.push(...findSampleRowLiterals(child, path === '' ? key : `${path}.${key}`));
25
+ }
26
+ }
27
+
28
+ return found;
29
+ }
30
+
31
+ /**
32
+ * Finds the sample-row literals in the defaults of component descriptors, as `<component>: <property path>`
33
+ * entries (the property path is followed by the location inside the default).
34
+ *
35
+ * @param descriptors The descriptors to inspect.
36
+ */
37
+ export function findDescriptorSampleRowLiterals(descriptors: readonly ComponentDescriptor[]): string[] {
38
+ const found: string[] = [];
39
+ for (const descriptor of descriptors) {
40
+ for (const property of descriptor.properties ?? []) {
41
+ for (const location of findSampleRowLiterals(property.default)) {
42
+ const suffix = location === '(root)' ? '' : (location.startsWith('[') ? location : `.${location}`);
43
+ found.push(`${descriptor.component}: ${property.path}${suffix}`);
44
+ }
45
+ }
46
+ }
47
+
48
+ return found;
49
+ }
50
+
51
+ function isRow(item: unknown): boolean {
52
+ return typeof item === 'object' && item !== null && !Array.isArray(item) && Object.keys(item).length >= 2;
53
+ }
54
+
55
+ /** The part of a scene element the scan reads: its properties and the child elements in its slots. */
56
+ interface ScannedElement {
57
+ componentName?: string;
58
+ properties?: Record<string, unknown>;
59
+ slots?: Record<string, ScannedElement[]>;
60
+ }
61
+
62
+ /**
63
+ * Finds the sample-row literals in the element properties of a template's content, as
64
+ * `<componentName>.<property>` entries (with the location inside the value when it is nested). Only property
65
+ * values are scanned: the element tree itself is made of objects and is not data.
66
+ *
67
+ * @param content A template's content, keyed by slot name.
68
+ */
69
+ export function findTemplateSampleRowLiterals(content: Record<string, ScannedElement[]> | undefined): string[] {
70
+ const found: string[] = [];
71
+ const visit = (elements: ScannedElement[] | undefined) => {
72
+ for (const element of elements ?? []) {
73
+ for (const [name, value] of Object.entries(element.properties ?? {})) {
74
+ for (const location of findSampleRowLiterals(value)) {
75
+ const suffix = location === '(root)' ? '' : (location.startsWith('[') ? location : `.${location}`);
76
+ found.push(`${element.componentName ?? '(unnamed)'}.${name}${suffix}`);
77
+ }
78
+ }
79
+
80
+ Object.values(element.slots ?? {}).forEach(visit);
81
+ }
82
+ };
83
+
84
+ Object.values(content ?? {}).forEach(visit);
85
+ return found;
86
+ }