@gramlot/gramlot 0.3.26 → 0.3.30

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 (213) hide show
  1. package/assets/icons/chart.svg +1 -0
  2. package/dist/components/audio/__init__.py +13 -0
  3. package/dist/components/audio/assets/collection.js +3 -0
  4. package/dist/components/audio/assets/index.js +3 -0
  5. package/dist/components/audio/commands.json +7 -0
  6. package/dist/components/audio/grammar.json +335 -0
  7. package/dist/components/charts/__init__.py +13 -0
  8. package/dist/components/charts/assets/collection.js +47 -0
  9. package/dist/components/charts/assets/files/55ea01207028f76d844678511f29fc800f8a1e67a8a0fe80470128677847ad32-echarts-gl.txt +29 -0
  10. package/dist/components/charts/assets/files/63727832aaf62004a2b249c933e327f3c90caf49e41a72f4bf436edf632cbda8-vega.txt +27 -0
  11. package/dist/components/charts/assets/files/8c45d9eaf50c2f72dd9c7ab9ef440788ba58a3538484b5c51c1f17d5128752e7-plotly.txt +21 -0
  12. package/dist/components/charts/assets/files/8f989229699b4fe2f1a0432d0e9edc338a8a911e250e2d1b01ecd770a5f5b1bd-uplot.txt +21 -0
  13. package/dist/components/charts/assets/files/c8fa058cba98f7f288b5d8fa4116f441d6dacb25b96da859e518c973fff41d0c-claygl.txt +23 -0
  14. package/dist/components/charts/assets/index.js +3 -0
  15. package/dist/components/charts/assets/modules/chunk-2CCTLZE7.js +76 -0
  16. package/dist/components/charts/assets/modules/chunk-RMRBEYTI.js +1 -0
  17. package/dist/components/charts/assets/modules/echarts-gl-CXVTZA6G.js +4409 -0
  18. package/dist/components/charts/assets/modules/plotly.min-4LB7HE7P.js +3596 -0
  19. package/dist/components/charts/assets/modules/uPlot.esm-5JJNHHRF.js +3 -0
  20. package/dist/components/charts/assets/modules/uPlot.min-N3E3FA74.js +1 -0
  21. package/dist/components/charts/assets/modules/vega.module-2QCOVQ3A.js +13 -0
  22. package/dist/components/charts/commands.json +7 -0
  23. package/dist/components/charts/grammar.json +1113 -0
  24. package/dist/components/chat/__init__.py +1 -1
  25. package/dist/components/chat/assets/collection.js +3 -3
  26. package/dist/components/chat/assets/index.js +1 -1
  27. package/dist/components/drawing/__init__.py +15 -0
  28. package/dist/components/drawing/assets/collection.js +28 -0
  29. package/dist/components/drawing/assets/index.js +3 -0
  30. package/dist/components/drawing/commands.json +7 -0
  31. package/dist/components/drawing/grammar.json +110 -0
  32. package/dist/components/editors/__init__.py +2 -2
  33. package/dist/components/editors/assets/collection.js +18 -18
  34. package/dist/components/editors/assets/index.js +1 -1
  35. package/dist/components/editors/assets/modules/{prose-mirror-engine-GMZPJPNN.js → prose-mirror-engine-DQEAEIMV.js} +2 -2
  36. package/dist/components/editors/grammar.json +150 -0
  37. package/dist/components/grid/__init__.py +1 -1
  38. package/dist/components/grid/assets/collection.js +63 -33
  39. package/dist/components/grid/assets/index.js +1 -1
  40. package/dist/components/grid/grammar.json +279 -0
  41. package/dist/components/grouplets/__init__.py +1 -1
  42. package/dist/components/grouplets/assets/collection.js +3 -3
  43. package/dist/components/grouplets/assets/index.js +1 -1
  44. package/dist/components/inputs/__init__.py +3 -2
  45. package/dist/components/inputs/assets/collection.js +38 -23
  46. package/dist/components/inputs/assets/index.js +1 -1
  47. package/dist/components/inputs/grammar.json +1533 -321
  48. package/dist/components/layout/__init__.py +1 -1
  49. package/dist/components/layout/assets/collection.js +27 -23
  50. package/dist/components/layout/assets/index.js +1 -1
  51. package/dist/components/layout/grammar.json +85 -0
  52. package/dist/components/selection_trial/__init__.py +1 -1
  53. package/dist/components/selection_trial/assets/collection.js +3 -3
  54. package/dist/components/selection_trial/assets/index.js +1 -1
  55. package/dist/components/tree/__init__.py +1 -1
  56. package/dist/components/tree/assets/collection.js +12 -12
  57. package/dist/components/tree/assets/index.js +1 -1
  58. package/dist/components/tree/grammar.json +126 -0
  59. package/dist/components/typst/__init__.py +1 -1
  60. package/dist/components/typst/assets/collection.js +3 -3
  61. package/dist/components/typst/assets/index.js +1 -1
  62. package/dist/components/uploads/__init__.py +1 -1
  63. package/dist/components/uploads/assets/collection.js +9 -9
  64. package/dist/components/uploads/assets/index.js +1 -1
  65. package/dist/components/vizabi/__init__.py +13 -0
  66. package/dist/components/vizabi/assets/collection.js +22 -0
  67. package/dist/components/vizabi/assets/index.js +3 -0
  68. package/dist/components/vizabi/commands.json +7 -0
  69. package/dist/components/vizabi/grammar.json +128 -0
  70. package/dist/gramlot.js +1190 -256
  71. package/dist/gramlot.min.js +85 -52
  72. package/dist/standard-collections.js +2 -0
  73. package/package.json +12 -4
  74. package/src/binding/grid-struct.js +2 -2
  75. package/src/binding/runtime.js +10 -0
  76. package/src/binding/validation-context.js +2 -1
  77. package/src/bootstrap.js +1 -1
  78. package/src/builder/gramlot-builder.d.ts +15 -2
  79. package/src/builder/gramlot-builder.js +22 -3
  80. package/src/builder/source.js +24 -1
  81. package/src/components/audio-analysis-session.js +65 -0
  82. package/src/components/audio.js +44 -0
  83. package/src/components/bases.js +11 -7
  84. package/src/components/border-container.js +6 -3
  85. package/src/components/buttons.js +47 -3
  86. package/src/components/chart-bar3d-options.js +30 -0
  87. package/src/components/chart-controls.js +83 -0
  88. package/src/components/chart-data-view.js +52 -0
  89. package/src/components/chart-data.js +42 -0
  90. package/src/components/chart-domains.js +46 -0
  91. package/src/components/chart-engines/echarts-options.js +50 -0
  92. package/src/components/chart-engines/echarts.js +82 -0
  93. package/src/components/chart-engines/index.js +22 -0
  94. package/src/components/chart-engines/plotly-map.js +34 -0
  95. package/src/components/chart-engines/plotly-spatial.js +35 -0
  96. package/src/components/chart-engines/plotly.js +138 -0
  97. package/src/components/chart-engines/uplot.js +57 -0
  98. package/src/components/chart-engines/vega.js +101 -0
  99. package/src/components/chart-fields.js +110 -0
  100. package/src/components/chart-geographic-options.js +47 -0
  101. package/src/components/chart-geojson.js +60 -0
  102. package/src/components/chart-geometry.js +11 -0
  103. package/src/components/chart-map-anchors.js +24 -0
  104. package/src/components/chart-map-bar3d-options.js +41 -0
  105. package/src/components/chart-map-data.js +25 -0
  106. package/src/components/chart-map-labels.js +8 -0
  107. package/src/components/chart-map-options.js +20 -0
  108. package/src/components/chart-pane.js +91 -0
  109. package/src/components/chart-renderer.js +58 -0
  110. package/src/components/chart-sample-view.js +32 -0
  111. package/src/components/chart-spatial-options.js +40 -0
  112. package/src/components/chart-time.js +84 -0
  113. package/src/components/chart-timeline.js +70 -0
  114. package/src/components/chart-types/area.js +2 -0
  115. package/src/components/chart-types/bar.js +2 -0
  116. package/src/components/chart-types/bar3D.js +2 -0
  117. package/src/components/chart-types/donut.js +2 -0
  118. package/src/components/chart-types/horizontalBar.js +2 -0
  119. package/src/components/chart-types/index.js +26 -0
  120. package/src/components/chart-types/line.js +2 -0
  121. package/src/components/chart-types/line3D.js +2 -0
  122. package/src/components/chart-types/lines3D.js +2 -0
  123. package/src/components/chart-types/map.js +2 -0
  124. package/src/components/chart-types/map3D.js +2 -0
  125. package/src/components/chart-types/mapBar3D.js +2 -0
  126. package/src/components/chart-types/pie.js +2 -0
  127. package/src/components/chart-types/polygons3D.js +2 -0
  128. package/src/components/chart-types/scatter.js +2 -0
  129. package/src/components/chart-types/scatter3D.js +2 -0
  130. package/src/components/chart-types/stackedArea.js +2 -0
  131. package/src/components/chart-types/stackedBar.js +2 -0
  132. package/src/components/chart-types/surface.js +2 -0
  133. package/src/components/charts.js +152 -0
  134. package/src/components/check-box-text-editor.js +88 -0
  135. package/src/components/check-box-text.js +193 -0
  136. package/src/components/check-box-tree.js +62 -0
  137. package/src/components/choice-editor.js +35 -18
  138. package/src/components/choice-field-styles.js +14 -0
  139. package/src/components/choices.js +5 -0
  140. package/src/components/database-choices.js +9 -6
  141. package/src/components/drawing.js +199 -0
  142. package/src/components/field-state.js +8 -1
  143. package/src/components/grid-cell-editor.js +83 -19
  144. package/src/components/grid-check-sets.js +98 -0
  145. package/src/components/grid-column-filters.js +198 -0
  146. package/src/components/grid-grammar.json +65 -0
  147. package/src/components/grid-header-interaction.js +3 -1
  148. package/src/components/grid-rows.js +2 -2
  149. package/src/components/grid-search-box.js +38 -22
  150. package/src/components/grid-search-styles.js +13 -14
  151. package/src/components/grid-search.js +8 -1
  152. package/src/components/grid-structure.js +13 -2
  153. package/src/components/grid-styles.js +34 -2
  154. package/src/components/grid.js +67 -10
  155. package/src/components/image-uploader.js +2 -2
  156. package/src/components/inputs.js +21 -12
  157. package/src/components/labelbox.js +5 -1
  158. package/src/components/licenses/claygl.txt +23 -0
  159. package/src/components/licenses/echarts-gl.txt +29 -0
  160. package/src/components/licenses/plotly.txt +21 -0
  161. package/src/components/licenses/uplot.txt +21 -0
  162. package/src/components/licenses/vega.txt +27 -0
  163. package/src/components/menus.js +19 -11
  164. package/src/components/parameters.js +6 -2
  165. package/src/components/toolbar-overflow.js +12 -8
  166. package/src/components/tree.js +31 -8
  167. package/src/components/typed-editor.js +18 -7
  168. package/src/components/validation.js +1 -1
  169. package/src/components/vizabi-session.js +66 -0
  170. package/src/components/vizabi.js +66 -0
  171. package/src/components/window-surface.js +20 -9
  172. package/src/components/windows.js +1 -1
  173. package/src/editing-session.d.ts +1 -0
  174. package/src/editing-session.js +113 -15
  175. package/src/editor-values.js +57 -0
  176. package/src/gramlot.d.ts +2 -0
  177. package/src/gramlot.js +9 -4
  178. package/src/handlers/device-handler.js +32 -32
  179. package/src/handlers/source-handler.d.ts +2 -2
  180. package/src/ide-documents.js +19 -3
  181. package/src/ide-runtime.d.ts +1 -0
  182. package/src/ide-runtime.js +45 -31
  183. package/src/index.d.ts +2 -1
  184. package/src/renderer/drag-drop.js +1 -0
  185. package/src/renderer/gramlot-renderer.d.ts +3 -0
  186. package/src/renderer/gramlot-renderer.js +16 -4
  187. package/src/server/assets.d.ts +3 -0
  188. package/src/server/assets.js +9 -0
  189. package/src/server/gramlot-server.d.ts +1 -1
  190. package/src/server/gramlot-server.js +2 -1
  191. package/src/server/index.d.ts +1 -1
  192. package/src/server/index.js +1 -1
  193. package/src/server/source-import.d.ts +1 -1
  194. package/src/server/source-import.js +5 -1
  195. package/src/server/visual-editor.d.ts +1 -1
  196. package/src/server/visual-editor.js +44 -34
  197. package/src/source-picker.d.ts +1 -1
  198. package/src/source-picker.js +1 -2
  199. package/src/stores/bag-collection-view.js +79 -17
  200. package/src/stores/collection-filter.js +2 -1
  201. package/src/stores/column-filter.js +49 -0
  202. package/src/stores/id-set.js +10 -0
  203. package/src/view/controls.js +8 -0
  204. package/src/view/html.js +10 -1
  205. package/src/view/label-menu.js +61 -0
  206. package/src/view/labelbox.js +15 -2
  207. package/src/visual-editor-canvas.js +29 -0
  208. package/src/visual-editor-catalogue.js +34 -0
  209. package/src/visual-editor.d.ts +5 -0
  210. package/src/visual-editor.js +244 -26
  211. package/themes/gramlot-base/theme.css +84 -36
  212. package/tools/gramlot-tools-inspector.js +170 -506
  213. package/tools/inspector-agent.js +1 -1
@@ -53,13 +53,17 @@ export const Tree = defineComponent({
53
53
  excludeRoot: {dtype: 'T', nullable: true, default: null, binding: 'read'},
54
54
  labelCb: {dtype: 'T', nullable: true, default: null},
55
55
  getLabel: {dtype: 'T', nullable: true, default: null},
56
+ labelState: {dtype: 'X', nullable: true, default: null, binding: 'read'},
56
57
  getLabelClass: {dtype: 'T', nullable: true, default: null},
57
58
  getIconClass: {dtype: 'T', nullable: true, default: null},
58
59
  selectedLabelClass: {dtype: 'T', default: '', binding: 'read'},
59
60
  searchText: {dtype: 'T', default: '', binding: 'read'},
61
+ searchEager: {dtype: 'B', default: true, binding: 'read'},
62
+ searchAttributes: {dtype: 'T', default: '', binding: 'read'},
60
63
  favorites: {dtype: 'X', nullable: true, default: null, binding: 'read'},
61
64
  favoritesLabel: {dtype: 'T', default: 'Favorites', binding: 'read'},
62
65
  autoCollapse: {dtype: 'B', default: false, binding: 'read'},
66
+ resolveLazy: {dtype: 'B', default: true, binding: 'read'},
63
67
  selectedPath: {dtype: 'T', nullable: true, default: null, binding: 'twoWay'},
64
68
  onChecked: {dtype: ['B', 'T'], nullable: true, default: null},
65
69
  checkedPaths: {dtype: 'T', nullable: true, default: null, binding: 'twoWay'},
@@ -146,13 +150,17 @@ export const Tree = defineComponent({
146
150
  });
147
151
  }
148
152
  setSourceContext(context) { this.#context = context; }
153
+ get storeBag() { return this.#store; }
149
154
  /** Read only the rendered row and its BagNode; never request a resolver value. */
150
155
  getDragContext(event) {
151
156
  for (const element of event.composedPath()) {
152
157
  const row = this.#dragRows.get(element);
153
158
  if (!row) continue;
154
159
  const {item, path, caption} = row;
155
- return {element, item, path, dragValues: {
160
+ const rect = element.getBoundingClientRect();
161
+ const fraction = rect.height ? (event.clientY - rect.top) / rect.height : 0.5;
162
+ const placement = fraction < 0.25 ? 'before' : fraction > 0.75 ? 'after' : 'inside';
163
+ return {element, item, path, placement, dragValues: {
156
164
  'text/plain': caption.textContent,
157
165
  nodeattr: {...item.getAttr()},
158
166
  treenode: {fullpath: item.fullpath, relpath: path}
@@ -179,7 +187,13 @@ export const Tree = defineComponent({
179
187
  projectAttributes(attrs, adapt) {
180
188
  this.#pathsEnabled = Object.hasOwn(attrs, 'checkedPaths');
181
189
  this.#checksEnabled = this.#pathsEnabled || Boolean(attrs.onChecked);
190
+ const previousEager = this.parameters?.searchEager;
191
+ const previousResolve = this.parameters?.resolveLazy;
182
192
  const rest = super.projectAttributes(attrs, adapt);
193
+ if (previousEager !== this.parameters.searchEager || previousResolve !== this.parameters.resolveLazy) {
194
+ this.#resetSearch();
195
+ this.#searchText = this.#searchInput.toLowerCase();
196
+ }
183
197
  if (this.#excludedRoot !== this.parameters.excludeRoot) {
184
198
  this.#excludedRoot = this.parameters.excludeRoot;
185
199
  this.#resetSearch();
@@ -210,7 +224,8 @@ export const Tree = defineComponent({
210
224
  #opened(node) { return this.#searchText ? this.#searchOpen.has(node) : this.#expanded.has(node); }
211
225
  async #searchBranches() {
212
226
  const version = this.#searchVersion, store = this.#store;
213
- const current = () => this.isConnected && version === this.#searchVersion && store === this.#store;
227
+ const current = () => this.isConnected && version === this.#searchVersion && store === this.#store
228
+ && this.parameters.searchEager && this.parameters.resolveLazy;
214
229
  this.#searching = true;
215
230
  const visit = async (bag, ancestors = new Set()) => {
216
231
  if (!current()) return;
@@ -220,6 +235,7 @@ export const Tree = defineComponent({
220
235
  if (bag === this.#store && node.label === this.parameters.excludeRoot) continue;
221
236
  if (!current()) return;
222
237
  if (node.attr.loop === true) continue;
238
+ if (node.resolver !== null && !this.parameters.resolveLazy) continue;
223
239
  if (node.resolver !== null && node.resolver.expired && !this.#searchAttempted.has(node)) {
224
240
  this.#searchAttempted.add(node);
225
241
  await this.#resolve(node, true);
@@ -272,14 +288,14 @@ export const Tree = defineComponent({
272
288
  for (const node of bag.getNodes()) {
273
289
  if (bag === this.#store && node.label === this.parameters.excludeRoot) continue;
274
290
  const path = prefix ? `${prefix}.${node.label}` : node.label;
275
- const value = node.staticValue; // Rendering never evaluates resolvers.
291
+ const value = node.resolver !== null && !this.parameters.resolveLazy ? null : node.staticValue;
276
292
  items.set(path, {node, ancestors, children: value instanceof Bag ? value : null});
277
293
  if (value instanceof Bag) visit(value, path, [...ancestors, node]);
278
294
  }
279
295
  seen.delete(bag);
280
296
  };
281
297
  visit(this.#store, '', []);
282
- if (this.#searchText && this.#searchTimer === null && !this.#searching && [...items.values()].some(({node}) =>
298
+ if (this.parameters.searchEager && this.parameters.resolveLazy && this.#searchText && this.#searchTimer === null && !this.#searching && [...items.values()].some(({node}) =>
283
299
  node.attr.loop !== true && node.resolver !== null && node.resolver.expired && !this.#searchAttempted.has(node))) {
284
300
  void this.#searchBranches();
285
301
  }
@@ -295,6 +311,7 @@ export const Tree = defineComponent({
295
311
  const initial = this.#checkedPaths === undefined;
296
312
  this.#checkedPaths = this.parameters.checkedPaths;
297
313
  for (const {node} of items.values()) {
314
+ if (node.attr.checked === 'disabled:on' || node.attr.checked === 'disabled:off') continue;
298
315
  if (!initial || this.#checkedPaths !== null) node.setAttr({checked: false});
299
316
  }
300
317
  for (const path of (this.#checkedPaths || '').split(this.parameters.checkedPaths_joiner).filter(Boolean)) {
@@ -350,7 +367,7 @@ export const Tree = defineComponent({
350
367
  const {children} = items.get(path);
351
368
  const scalar = children === null && !this.parameters.hideValues && (node.resolver === null || !node.resolver.expired);
352
369
  const branch = children !== null ? children.length > 0
353
- : scalar || (node.resolver !== null && node.attr.child_count !== 0);
370
+ : scalar || (node.resolver !== null && this.parameters.resolveLazy && node.attr.child_count !== 0);
354
371
  const entry = this.ownerDocument.createElement('li');
355
372
  entry.className = `node ${branch ? 'branch' : 'leaf'}`;
356
373
  entry.setAttribute('part', `node ${branch ? 'branch' : 'leaf'}`);
@@ -452,7 +469,7 @@ export const Tree = defineComponent({
452
469
  badge.hidden = value == null || value === '';
453
470
  badge.style.backgroundColor = color ?? '';
454
471
  badge.toggleAttribute('data-colored', color != null && color !== '');
455
- const keywords = {item: node, path, opened, selected};
472
+ const keywords = {item: node, path, opened, selected, state: this.parameters.labelState};
456
473
  const attribute = this.parameters.labelAttribute;
457
474
  const label = this.parameters.internalNames && node.getAttr('fieldpath') ? node.label
458
475
  : this.parameters.getLabel !== null ? this.#call('getLabel', keywords)
@@ -548,7 +565,12 @@ export const Tree = defineComponent({
548
565
  for (const [path, row] of this.#rows) {
549
566
  const caption = row.firstElementChild.querySelector('.caption'), item = items.get(path);
550
567
  if (item.ancestors.some(ancestor => ancestor.attr.loop === true)) continue;
551
- const match = caption.textContent.toLowerCase().includes(this.#searchText);
568
+ const metadata = this.parameters.searchAttributes.split(',').map(name => name.trim()).filter(Boolean)
569
+ .flatMap(name => {
570
+ const value = item.node.getAttr(name);
571
+ return Array.isArray(value) ? value.filter(part => typeof part === 'string') : typeof value === 'string' ? [value] : [];
572
+ });
573
+ const match = [caption.textContent, ...metadata].some(text => text.toLowerCase().includes(this.#searchText));
552
574
  if (match) matches.push(caption);
553
575
  if (match || this.#errors.has(item.node) || this.#loading.has(item.node)) {
554
576
  visible.add(item.node);
@@ -647,6 +669,7 @@ export const Tree = defineComponent({
647
669
  if (!current()) return;
648
670
  const node = bag.getNode(part);
649
671
  if (!node) return;
672
+ if (node.resolver !== null && !this.parameters.resolveLazy) return;
650
673
  if (node.resolver === null && !(node.staticValue instanceof Bag)) return;
651
674
  if (!current() || bag.getNode(part) !== node) return;
652
675
  this.#expand(node);
@@ -773,7 +796,7 @@ export const Tree = defineComponent({
773
796
  return value.split(/\s+/).filter(Boolean);
774
797
  }
775
798
  #rowActions() {
776
- const bars = this.querySelectorAll(':scope > gramlot-row-actions');
799
+ const bars = [...this.children].filter(child => child.localName === 'gramlot-row-actions');
777
800
  if (bars.length > 1) throw new Error('tree accepts one rowActions bar');
778
801
  return bars[0] ?? null;
779
802
  }
@@ -90,12 +90,14 @@ export function TypedEditor(HTMLElement) {
90
90
  this.checkValue(value);
91
91
  return this.validateCandidate(value, accepted => {
92
92
  this.checkValue(accepted);
93
+ this.acceptDraft(accepted, this.#selection ? null : this.control.value, this.#policy ?? this.context());
93
94
  this.#value = accepted; this.#selection = null; this.#dirty = false;
94
95
  // Preserve accepted spelling unless validation normalized the candidate.
95
96
  if (!this.#focused || !this.sameControlValue(value, accepted)) { this.#policy = null; this.display(); }
96
97
  });
97
98
  } catch (error) { if (this.pageContext.form) this.pageContext.formParseError(error.message); this.error(error.message); return {ok: false}; }
98
99
  }
100
+ acceptDraft(value, text, context) {}
99
101
  restoreFormDraft(text) { this.#dirty = true; this.#policy = this.context(); this.control.value = text; }
100
102
  restoreFormValue(value) { this.#dirty = false; this.#policy = null; this.#selection = null; this.error(''); this.writeControlValue(value); this.display(); }
101
103
  display() {
@@ -119,8 +121,8 @@ TypedEditor.parameters = {...NativeControl.parameters,
119
121
 
120
122
  export const numberEditor = Base => class extends Base {
121
123
  createControl() { const control = super.createControl(); control.inputMode = 'decimal'; return control; }
122
- validationValueCheck() {
123
- const isDecimal = this.pageContext.isDecimal;
124
+ static validationValueCheck(context) {
125
+ const isDecimal = context.isDecimal;
124
126
  return value => checkNumber(value,isDecimal);
125
127
  }
126
128
  checkValue(value) { checkNumber(value,this.pageContext.isDecimal); }
@@ -231,24 +233,33 @@ export const dateEditor = Base => class extends Base {
231
233
  }
232
234
  releaseControl() { this.closeCalendar(); super.releaseControl(); }
233
235
  context() { return {...super.context(), dtype: 'D', pattern: this.parameters.format ?? 'short'}; }
234
- validationValueCheck() { return checkCivilDate; }
236
+ static validationValueCheck() { return checkCivilDate; }
235
237
  checkValue(value) { checkCivilDate(value); }
236
238
  editText(value, context) { return this.pageContext.format(value, {...context, pattern: 'short'}); }
237
- parse(text, context) {
239
+ dateExpression(text, context) {
238
240
  const now = new Date();
239
241
  const workdate = this.parameters.workdate ?? `${now.getFullYear()}-${pad(now.getMonth()+1)}-${pad(now.getDate())}`;
240
242
  const options = {locale: context.locale, workdate};
241
243
  const result = parseDateExpression(text, options);
242
244
  if (!result.ok) throw new Error(result.error.message);
243
- if (result.kind !== 'date') throw new Error('Enter one complete date, not a period.');
244
- const [y, m, d] = result.date.split('-').map(Number);
245
+ if (result.kind !== 'date' && !this.parameters.period_to) throw new Error('Enter one complete date, not a period.');
246
+ return result;
247
+ }
248
+ acceptDraft(value, text, context) {
249
+ if (!text?.trim() || !this.parameters.period_to) return;
250
+ const result = this.dateExpression(text, context);
251
+ if (result.kind === 'period') this.pageContext.periodOutput(this.parameters.period_to, new Date(result.end + 'T00:00:00Z'));
252
+ }
253
+ parse(text, context) {
254
+ const result = this.dateExpression(text, context);
255
+ const [y, m, d] = (result.kind === 'date' ? result.date : result.start).split('-').map(Number);
245
256
  const value = new Date(0); value.setUTCFullYear(y, m - 1, d); return value;
246
257
  }
247
258
  };
248
259
 
249
260
  export const timeEditor = Base => class extends Base {
250
261
  context() { return {...super.context(), dtype: 'H', pattern: this.parameters.format ?? 'short'}; }
251
- validationValueCheck() { return checkTime; }
262
+ static validationValueCheck() { return checkTime; }
252
263
  checkValue(value) { checkTime(value); }
253
264
  editText(value) {
254
265
  return `${pad(value.getUTCHours())}:${pad(value.getUTCMinutes())}:${pad(value.getUTCSeconds())}` +
@@ -72,7 +72,7 @@ function remoteArguments(parameters) {
72
72
  }
73
73
  function fail(errorcode, message, extra = {}) { return {errorcode, message, ...extra}; }
74
74
  function localRule(rule, param, value, context) {
75
- if (rule === 'select') return context.selection(value);
75
+ if (rule === 'select') return context.selection(value,context.signal);
76
76
  if (rule === 'notnull') return empty(value) && param ? fail('notnull', 'A value is required.', {required:true}) : null;
77
77
  if (rule === 'empty') return empty(value) ? {value:param} : null;
78
78
  if (rule === 'len') {
@@ -0,0 +1,66 @@
1
+ import {randomId} from '../random-id.js';
2
+
3
+ /** One optional Vizabi instance; the Gramlot Bag owns authored state. */
4
+ export class VizabiSession {
5
+ constructor(library, element, view, configuration) {
6
+ this.library=library; this.configuration=configuration; this.element=element;
7
+ const {Vizabi,BubbleChart,mobx}=library;
8
+ if(!Number.isInteger(configuration.getItem('year'))||typeof configuration.getItem('playing')!=='boolean'||!Number.isFinite(configuration.getItem('speed'))||configuration.getItem('speed')<=0)throw new TypeError('Vizabi requires an integer year, Boolean playing and positive speed in milliseconds');
9
+ const keys=['entityField','timeField','xField','yField','sizeField','colorField'];
10
+ const fields=Object.fromEntries(keys.map(key=>[key,configuration.getItem(key)]));
11
+ for(const [key,value] of Object.entries(fields))if(typeof value!=='string'||!value)throw new TypeError(`${key} requires a field name`);
12
+ if(Object.entries(fields).some(([key,value])=>value==='name'&&key!=='entityField'))throw new TypeError('The Vizabi entity catalogue reserves name for the entity display name');
13
+ const rows=view.getRows().map(node=>Object.fromEntries([...new Set(Object.values(fields))].map(field=>[field,view.value(node,field)])));
14
+ const identities=new Set();
15
+ for(const row of rows) {
16
+ if(typeof row[fields.entityField]!=='string'||!Number.isInteger(row[fields.timeField]))throw new TypeError('Vizabi trial requires text entities and integer years');
17
+ const key=JSON.stringify([row[fields.entityField],row[fields.timeField]]);
18
+ if(identities.has(key))throw new TypeError('Vizabi requires one prepared row per entity and year');
19
+ identities.add(key);
20
+ for(const field of [fields.xField,fields.yField,fields.sizeField])if(typeof row[field]!=='number'||!Number.isFinite(row[field]))throw new TypeError(`${field} requires finite numbers`);
21
+ if(row[fields.sizeField]<0)throw new TypeError('Bubble size cannot be negative');
22
+ if(typeof row[fields.colorField]!=='string')throw new TypeError('Bubble color requires a text category');
23
+ }
24
+ // Vizabi's entity catalogue requires its reserved display-name property.
25
+ for(const row of rows)row.name=row[fields.entityField];
26
+ if(!rows.length)throw new TypeError('No data to display');
27
+ this.id=`bubble_${randomId()}`;this.legendId=`legend_${randomId()}`;this.sourceId=`data_${randomId()}`;
28
+ const defaults=JSON.parse(JSON.stringify(BubbleChart.DEFAULT_MODEL).replaceAll('markers.bubble',`markers.${this.id}`).replaceAll('markers.legend',`markers.${this.legendId}`));
29
+ const bubble=defaults.bubble;
30
+ bubble.data={source:this.sourceId,space:[fields.entityField,fields.timeField]};
31
+ for(const [encoding,field] of Object.entries({x:fields.xField,y:fields.yField,size:fields.sizeField,color:fields.colorField,label:fields.entityField}))bubble.encoding[encoding].data={concept:field,constant:null};
32
+ bubble.encoding.label.data={modelType:'entityPropertyDataConfig',concept:'name'};
33
+ bubble.requiredEncodings=['x','y','size','color','label'];
34
+ bubble.encoding.y.modelType='baseType';
35
+ bubble.encoding.y.scale.type='linear';
36
+ bubble.encoding.frame={modelType:'frame',data:{concept:fields.timeField},value:String(configuration.getItem('year')),speed:configuration.getItem('speed'),splash:false,loop:true};
37
+ const models=Vizabi({dataSources:{[this.sourceId]:{values:rows,keyConcepts:[fields.entityField,fields.timeField],dtypes:{[fields.timeField]:'year'}}},markers:{[this.id]:bubble,[this.legendId]:defaults.legend}});
38
+ this.models=models;
39
+ this.frame=models.markers[this.id].encoding.frame;
40
+ this.tool=new BubbleChart({Vizabi,placeholder:element,model:{config:models.config,dataSources:models.dataSources,markers:{bubble:models.markers[this.id],legend:models.markers[this.legendId]}},locale:{id:'en',resolve:{en:library.locale},placeholder:element},layout:{placeholder:element},ui:{buttons:{buttons:[]},dialogs:{dialogs:{sidebar:[],popup:[]}}}});
41
+ this.release=mobx.reaction(()=>{const marker=models.markers[this.id];return [marker.state==='fulfilled'?this.frame.value.getUTCFullYear():null,this.frame.playing,...['x','y','size','color'].map(key=>marker.encoding[key].data.concept)];},([year,playing,x,y,size,color])=>{
42
+ if(!Number.isFinite(year))return;
43
+ this.writing=true;
44
+ try { for(const [key,value] of Object.entries({xField:x,yField:y,sizeField:size,colorField:color}))if(configuration.getItem(key)!==value)configuration.setItem(key,value);if(configuration.getItem('year')!==year)configuration.setItem('year',year);if(configuration.getItem('playing')!==playing)configuration.setItem('playing',playing); }
45
+ finally {this.writing=false;}
46
+ });
47
+ this.ready=mobx.when(()=>models.markers[this.id].state==='fulfilled',()=>this.update());
48
+ }
49
+ update() {
50
+
51
+ if(this.writing||this.models.markers[this.id].state!=='fulfilled')return;
52
+ const c=this.configuration,f=this.frame;
53
+ this.library.mobx.runInAction(()=>{
54
+ f.setSpeed(c.getItem('speed'));
55
+ if(f.value?.getUTCFullYear()!==c.getItem('year'))f.setValue(String(c.getItem('year')));
56
+ if(f.playing!==c.getItem('playing'))f.setPlaying(c.getItem('playing'));
57
+ });
58
+ }
59
+ resize() { this.tool.services.layout._resizeHandler(); }
60
+ dispose() {
61
+ this.release();this.ready();this.frame.stopPlaying();this.tool.deconstruct();
62
+ const stores=this.library.Vizabi.stores;
63
+ stores.markers.dispose(this.legendId);stores.markers.dispose(this.id);stores.dataSources.dispose(this.sourceId);
64
+ this.element.replaceChildren();
65
+ }
66
+ }
@@ -0,0 +1,66 @@
1
+ import {Bag} from '@gramlot/gramlot';
2
+ import {defineCollection,defineComponent} from '@gramlot/gramlot/components';
3
+ import {Container} from './container.js';
4
+ import {BagCollectionView} from '../stores/bag-collection-view.js';
5
+ import {VizabiSession} from './vizabi-session.js';
6
+
7
+ const VizabiBubble=defineComponent({
8
+ name:'vizabiBubble',tag:'gramlot-vizabi-bubble',base:Container,sourceContext:true,bagStore:true,
9
+ parameters:{storepath:{dtype:'T'},rowMode:{dtype:'T',default:'attributes'},configuration:{dtype:'X',binding:'read'},libraryUrl:{dtype:'T'}},
10
+ implementation:Base=>class extends Base {
11
+ #context;#bag;#signature;#libraryUrl;#configuration;#view;#release;#session;#resize;#revision=0;#active=false;#subscription=Symbol('vizabi-config');#style;#message;#host;
12
+ constructor(){
13
+ super();this.control.replaceChildren();
14
+ this.#style=this.ownerDocument.createElement('style');this.shadowRoot.append(this.#style);
15
+ this.#message=this.ownerDocument.createElement('div');this.#message.setAttribute('role','status');
16
+ this.#host=this.ownerDocument.createElement('div');this.#host.style.cssText='width:100%;height:100%;position:relative;background:white;color:#222';
17
+ this.control.append(this.#message,this.#host);this.control.style.height='100%';
18
+ this.#resize=new this.ownerDocument.defaultView.ResizeObserver(()=>this.#session?.resize());
19
+ }
20
+ setSourceContext(context){this.#context=context;}
21
+ setStoreBag(bag){this.#bag=bag;}
22
+ projectAttributes(attrs,adapt){const result=super.projectAttributes(attrs,adapt);if(this.#active)this.#connect();return result;}
23
+ connectedCallback(){this.#active=true;this.#connect();this.#resize.observe(this.#host);}
24
+ #connect(){
25
+ let changed=this.#libraryUrl!==this.parameters.libraryUrl;this.#libraryUrl=this.parameters.libraryUrl;
26
+ const configuration=this.parameters.configuration;
27
+ if(!(configuration instanceof Bag))throw new TypeError('vizabiBubble requires a configuration Bag');
28
+ if(this.#configuration!==configuration){
29
+ changed=true;
30
+ this.#configuration?.unsubscribe(this.#subscription,{any:true});this.#configuration=configuration;
31
+ configuration.subscribe(this.#subscription,{any:()=>{
32
+ if(this.#session?.writing)return;
33
+ this.#refreshConfiguration();
34
+ }});
35
+ }
36
+ const store=this.#context.sourceNode.rootBuilder.binding.collectionStore(this.#bag,this.parameters.rowMode);
37
+ if(!this.#view){changed=true;this.#view=new BagCollectionView(store);this.#view.connect();this.#release=this.#view.subscribe(()=>this.#render());}
38
+ else if(this.#view.bag!==this.#bag){this.#view.bindStore(store);return;}
39
+ if(changed)this.#signature=null;
40
+ this.#refreshConfiguration();
41
+ }
42
+ #refreshConfiguration(){
43
+ const signature=JSON.stringify(['entityField','timeField','xField','yField','sizeField','colorField'].map(key=>this.#configuration.getItem(key)));
44
+ if(this.#session?.writing){this.#signature=signature;return;}
45
+ if(signature!==this.#signature){this.#signature=signature;this.#render();}
46
+ else this.#session?.update();
47
+ }
48
+ async #render(){
49
+ const revision=++this.#revision;this.#session?.dispose();this.#session=null;
50
+ this.#message.hidden=false;this.#message.textContent='Loading optional Vizabi library…';
51
+ try{
52
+ if(!this.parameters.libraryUrl)throw new Error('Provide libraryUrl to load the optional Vizabi module');
53
+ const library=await import(this.parameters.libraryUrl);
54
+ if(!this.#active||revision!==this.#revision)return;
55
+ this.#style.textContent=library.style+'\n:host{display:block;height:100%;min-height:0}.control-box{height:100%}';
56
+ this.#session=new VizabiSession(library,this.#host,this.#view,this.#configuration);
57
+ this.#message.hidden=true;
58
+ }catch(error){if(revision!==this.#revision)return;this.#message.setAttribute('role','alert');this.#message.textContent=error.message;}
59
+ }
60
+ disconnectedCallback(){
61
+ this.#active=false;this.#revision++;this.#resize.disconnect();this.#configuration?.unsubscribe(this.#subscription,{any:true});
62
+ this.#release?.();this.#view?.disconnect();this.#session?.dispose();this.#session=null;this.#view=null;this.#configuration=null;
63
+ }
64
+ }
65
+ });
66
+ export default defineCollection({name:'vizabi',components:[VizabiBubble]});
@@ -6,7 +6,7 @@ export class WindowSurface {
6
6
  #context; #observer; #scheduled = false; #live = false;
7
7
  #open = false; #collapsed = false; #maximized = false; #pending = null; #generation = 0;
8
8
  #geometry = null; #gesture = null; #previousFocus = null;
9
- #resize = () => { if (this.#open) this.#fit(); };
9
+ #resize = () => { if (this.#open && !this.parameters.docked) this.#fit(); };
10
10
  constructor(host, root, {modal, validateContent}) {
11
11
  this.host = host; this.root = root; this.modal = modal;
12
12
  this.validateContent = validateContent;
@@ -20,6 +20,10 @@ export class WindowSurface {
20
20
  background:var(--gramlot-surface,Canvas);box-shadow:0 2px 6px #00000014,0 16px 36px #00000029;overflow:hidden;
21
21
  max-width:calc(100vw - 16px);max-height:calc(100dvh - 16px)}
22
22
  .window-surface dialog[open]{display:flex;flex-direction:column}
23
+ .window-surface dialog[data-docked]{position:relative!important;inset:0!important;width:100%!important;height:100%!important;
24
+ min-width:0!important;min-height:0!important;max-width:none!important;max-height:none!important;
25
+ border:0;border-radius:0;box-shadow:none;z-index:auto!important}
26
+ .window-surface dialog[data-docked] .titlebar,.window-surface dialog[data-docked] .resize{display:none!important}
23
27
  .window-surface dialog[data-maximized]{max-width:100vw;max-height:100dvh;border-radius:0}
24
28
  .window-surface dialog::backdrop{background:var(--gramlot-window-backdrop,#0006)}
25
29
  .window-surface .titlebar{display:flex;align-items:center;gap:4px;flex:none;min-height:max(32px,var(--gramlot-tab-height,32px));padding:3px 5px 3px 12px;
@@ -104,7 +108,7 @@ export class WindowSurface {
104
108
  this.#cancelGesture();this.#geometry=null;this.#collapsed=false;this.#maximized=false;
105
109
  }
106
110
  if(previous.open!==this.parameters.open) { this.#generation++;this.#pending=null; }
107
- if(previous.movable!==this.parameters.movable || previous.resizable!==this.parameters.resizable)this.#cancelGesture();
111
+ if(previous.movable!==this.parameters.movable || previous.resizable!==this.parameters.resizable || previous.docked!==this.parameters.docked)this.#cancelGesture();
108
112
  }
109
113
  this.#schedule();
110
114
  }
@@ -118,14 +122,16 @@ export class WindowSurface {
118
122
  this.heading.textContent=p.title;this.shell.setAttribute('aria-label',p.title);
119
123
  this.closeButton.hidden=!p.closable;this.closeButton.disabled=Boolean(this.#pending);
120
124
  this.collapseButton.hidden=!p.collapsible;this.maximizeButton.hidden=!p.maximizable;
125
+ this.shell.toggleAttribute('data-docked', p.docked === true);
121
126
  if(!p.open) { this.#close(false);return; }
122
127
  if(!this.#open) {
123
128
  this.#previousFocus=this.#activeElement();
124
129
  this.#collapsed=false;this.#maximized=false;this.body.hidden=false;this.shell.removeAttribute('data-collapsed');
125
130
  if(this.modal)this.shell.showModal();else this.shell.show();
126
- this.#open=true;this.#applySize();this.#fit();this.#raise();
131
+ this.#open=true;if(!p.docked){this.#applySize();this.#fit();this.#raise();}
127
132
  this.#context.publish('opened',{});
128
- } else if(!this.#geometry) { this.#applySize();this.#fit(); }
133
+ } else if(!p.docked && !this.#geometry) { this.#applySize();this.#fit(); }
134
+ if(p.docked) { this.body.hidden=false;this.resizeButton.hidden=true;return; }
129
135
  this.#setMaximized(p.maximizable&&p.maximized,false);
130
136
  this.#setCollapsed(p.collapsible&&p.collapsed,false);
131
137
  if(!p.maximizable && p.maximized)this.#context.writeParameter('maximized',false);
@@ -156,7 +162,7 @@ export class WindowSurface {
156
162
  }
157
163
  #paint(rect) { for(const key of ['left','top','width','height'])this.shell.style[key]=`${rect[key]}px`; }
158
164
  #raise() {
159
- if(this.modal||!this.#open)return;
165
+ if(this.modal||!this.#open||this.parameters.docked)return;
160
166
  // Reserve the page's low stacking levels for layout chrome (splitters/drawers).
161
167
  // Modal dialogs and menu popovers remain above these nonmodal windows in the top layer.
162
168
  const base=100;
@@ -175,7 +181,7 @@ export class WindowSurface {
175
181
  this.#paint(rect);
176
182
  const movable=this.parameters.movable&&!this.#maximized;
177
183
  this.titlebar.toggleAttribute('data-movable',movable);this.titlebar.tabIndex=movable?0:-1;
178
- this.titlebar.setAttribute('aria-label',movable?'Move window: use arrow keys':this.parameters.title);
184
+ this.titlebar.setAttribute('aria-label',movable?'Move window: use arrow keys, Home to reset':this.parameters.title);
179
185
  this.resizeButton.hidden=this.#collapsed||this.#maximized||!this.parameters.resizable;
180
186
  }
181
187
  #setMaximized(value,write) {
@@ -233,7 +239,7 @@ export class WindowSurface {
233
239
  this.#context.publish('closed',{});
234
240
  }
235
241
  #startGesture(event,kind) {
236
- if(event.button!==0||!this.#open||this.#maximized||kind==='move'&&!this.parameters.movable||kind==='resize'&&(!this.parameters.resizable||this.#collapsed))return;
242
+ if(event.button!==0||!this.#open||this.parameters.docked||this.#maximized||kind==='move'&&!this.parameters.movable||kind==='resize'&&(!this.parameters.resizable||this.#collapsed))return;
237
243
  if(kind==='move'&&event.target.closest('button'))return;
238
244
  event.preventDefault();this.#cancelGesture();
239
245
  const r=this.shell.getBoundingClientRect();
@@ -271,10 +277,15 @@ export class WindowSurface {
271
277
  }
272
278
  }
273
279
  #keyGeometry(event,kind) {
274
- if(event.target!==event.currentTarget||!['ArrowLeft','ArrowRight','ArrowUp','ArrowDown'].includes(event.key))return;
275
- if(this.#maximized||kind==='move'&&!this.parameters.movable||kind==='resize'&&(!this.parameters.resizable||this.#collapsed))return;
280
+ if(event.target!==event.currentTarget||!['ArrowLeft','ArrowRight','ArrowUp','ArrowDown','Home'].includes(event.key))return;
281
+ if(this.parameters.docked||this.#maximized||kind==='move'&&!this.parameters.movable||kind==='resize'&&(!this.parameters.resizable||this.#collapsed)||event.key==='Home'&&kind!=='move')return;
276
282
  event.preventDefault();event.stopPropagation();
277
283
  const r=this.shell.getBoundingClientRect(),step=event.shiftKey?1:10;
284
+ if(event.key==='Home') {
285
+ const x=parseFloat(this.parameters.left),y=parseFloat(this.parameters.top);
286
+ this.#adjust({left:r.left,top:r.top,width:r.width,height:r.height},(Number.isFinite(x)?x:8)-r.left,(Number.isFinite(y)?y:8)-r.top,kind);
287
+ this.#commitGeometry(kind);return;
288
+ }
278
289
  this.#adjust({left:r.left,top:r.top,width:r.width,height:r.height},event.key==='ArrowLeft'?-step:event.key==='ArrowRight'?step:0,event.key==='ArrowUp'?-step:event.key==='ArrowDown'?step:0,kind);
279
290
  this.#commitGeometry(kind);
280
291
  }
@@ -52,4 +52,4 @@ WindowShell.parameters={
52
52
  };
53
53
  export const Dialog=defineComponent({name:'dialog',tag:'gramlot-dialog',base:WindowShell,sourceContext:true,subTags:'framePane',implementation:Base=>class extends Base{}});
54
54
  export const FloatingPane=defineComponent({name:'floatingPane',tag:'gramlot-floating-pane',base:WindowShell,sourceContext:true,subTags:'framePane',
55
- parameters:{movable:bool(true),resizable:bool(true),collapsible:bool(true)},implementation:Base=>class extends Base{}});
55
+ parameters:{movable:bool(true),resizable:bool(true),collapsible:bool(true),docked:bool(false)},implementation:Base=>class extends Base{}});
@@ -20,6 +20,7 @@ export class EditingSession {
20
20
  focusField(path: string): boolean;
21
21
  registerNavigator(navigate: (path: string) => boolean): () => void;
22
22
  load(data: Bag): void;
23
+ validate(): Promise<boolean>;
23
24
  accept(): boolean;
24
25
  restore(): void;
25
26
  }