@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
@@ -1,3 +1,6 @@
1
+ import {VisualEditorCanvas} from './visual-editor-canvas.js';
2
+ import {validateCatalogue, catalogueAllows, validateCatalogueSource} from './visual-editor-catalogue.js';
3
+ import {editorTypes, scalarType, scalarText, parseScalar} from './editor-values.js';
1
4
  import {SourcePicker} from './source-picker.js';
2
5
  import {appearanceStyles, paletteStyles} from './index-page-styles.js';
3
6
  import {toolIcons} from './visual-editor-icons.js';
@@ -70,6 +73,7 @@ const specifications = (node, tag, current = null) => {
70
73
 
71
74
  // Editor-local view resources; selection itself remains in the Data Bag.
72
75
  const canvasSelections = new WeakMap();
76
+ const canvasDocuments = new WeakMap();
73
77
 
74
78
  export class VisualEditorLogic {
75
79
  chatRender(node, params) { return chatRender(this.page, node, params); }
@@ -90,8 +94,10 @@ export class VisualEditorLogic {
90
94
  const content = mode === 'code' ? editor.GET('.codeDocument.content') : wire;
91
95
  if (mode === 'code' && !editor.GET('.codeDocument.writable')) { node.SET('.error', 'Page code editing is disabled by the host'); return; }
92
96
  const run = (editor.GET('.assistantRun.run') ?? 0) + 1;
97
+ const scope = editor.GET('.catalogueScope');
93
98
  const schema = {commonParameters:styleParameters, labelboxParameters, widgets:{}};
94
99
  for (const [tag, info] of Object.entries(node.builder.schema)) {
100
+ if (!catalogueAllows(scope, tag, info._meta ?? {})) continue;
95
101
  if (info._meta?.data_element || info._meta?.subbuilder || info._meta?.container) continue;
96
102
  const component = info._meta?.gramlot_component;
97
103
  schema.widgets[tag] = {parameters:component?.parameters ?? {}, labelbox:!!component?.labelbox,
@@ -205,6 +211,7 @@ export class VisualEditorLogic {
205
211
  }
206
212
  };
207
213
  candidate.getNodes().forEach(validateChildren);
214
+ validateCatalogueSource(visualEditorScope(node).GET('.catalogueScope'), candidate);
208
215
  app.src.renderer.validateCandidate(candidate, {replacingNode:design});
209
216
  const current = node.builder.source.getNode(`${sourceRoot(node)}.${path}`);
210
217
  let selected = path;
@@ -229,14 +236,39 @@ export class VisualEditorLogic {
229
236
  initializeCanvasSelection(node) {
230
237
  const renderer = node.rootBuilder.binding.renderer;
231
238
  const design = node.builder.source.getNode(sourceRoot(node));
232
- const picker = new SourcePicker({renderer, root:design, onSelect:selected => {
233
- node.SET('.sourceSearch', '');
234
- node.SET('.selection', selected.fullpath.slice(design.fullpath.length + 1));
235
- }});
239
+ const editor = visualEditorScope(node), css = editor.GET('.canvasCss');
240
+ if (css != null) this.applyCanvasCss(editor, css);
241
+ const previous = canvasSelections.get(design);
242
+ previous?.dispose();
243
+ const picker = new SourcePicker({renderer, root:design,
244
+ ...(canvasDocuments.has(design) ? {canvas:canvasDocuments.get(design).body} : {}),
245
+ onSelect:selected => {
246
+ node.SET('.sourceSearch', '');
247
+ node.SET('.selection', selected.fullpath.slice(design.fullpath.length + 1));
248
+ }});
236
249
  canvasSelections.set(design, picker);
237
- renderer.onDispose(design.parentNode, () => canvasSelections.delete(design));
250
+ if (!previous) renderer.onDispose(design.parentNode, () => {
251
+ canvasSelections.delete(design); canvasDocuments.delete(design);
252
+ });
238
253
  this.highlightSelection(node);
239
254
  }
255
+ applyCanvasCss(node, texts) {
256
+ if (!Array.isArray(texts) || texts.some(text => typeof text !== 'string'))
257
+ throw new TypeError('canvas CSS must be a list of CSS texts');
258
+ const editor = visualEditorScope(node), design = editor.builder.source.getNode(sourceRoot(editor));
259
+ let canvas = canvasDocuments.get(design);
260
+ if (!canvas) {
261
+ canvas = new VisualEditorCanvas({app:editor.rootBuilder.binding.gramlot, editor, design});
262
+ canvasDocuments.set(design, canvas);
263
+ }
264
+ canvas.setCss(texts);
265
+ }
266
+ setCanvasCss(node, texts) {
267
+ const editor = visualEditorScope(node);
268
+ this.applyCanvasCss(editor, texts);
269
+ editor.SET('.canvasCss', texts);
270
+ this.initializeCanvasSelection(editor);
271
+ }
240
272
  highlightSelection(node) {
241
273
  const design = node.builder.source.getNode(sourceRoot(node));
242
274
  const path = node.GET('.selection');
@@ -330,6 +362,7 @@ export class VisualEditorLogic {
330
362
  const parent = path ? node.builder.source.getNode(`${sourceRoot(node)}.${path}`) : null;
331
363
  if (!parent) throw new Error('Choose a destination in the Source tree');
332
364
  const source = node.rootBuilder.binding.gramlot.src.prepareSource(saved.getValue(true), parent.builder);
365
+ validateCatalogueSource(visualEditorScope(node).GET('.catalogueScope'), source);
333
366
  const branch = source.getNodes()[0];
334
367
  parent.builder.validateParent(branch.nodeTag, parent.nodeTag);
335
368
  const body = parent.getValue(true);
@@ -349,7 +382,7 @@ export class VisualEditorLogic {
349
382
  fields.getValue(true).clear();
350
383
  const root = node.builder.wrapSource(fields);
351
384
  root.p(`Paste ${saved.getAttr('name')} into ${parent.label} [${parent.nodeTag}]`, {class:'visual-editor-hint'});
352
- const form = root.formlet({columns:2, gap:'8px 10px', lbl_position:'TL', box_c_width:'100%', align_items:'start'});
385
+ const form = root.formlet({columns:2, gap:'4px 6px', lbl_position:'TL', box_c_width:'100%', align_items:'start'});
353
386
  for (const [name, spec] of required) this.parameterField(node, form, branch.nodeTag, name, spec, 'insertion', spec.default);
354
387
  node.SET('.insertionOpen', true);
355
388
  }
@@ -372,6 +405,7 @@ export class VisualEditorLogic {
372
405
  if (!parent) throw new Error('The destination no longer exists');
373
406
  const app = node.rootBuilder.binding.gramlot;
374
407
  const source = app.src.prepareSource(node.GET('.insertion.clipboard'), parent.builder);
408
+ validateCatalogueSource(visualEditorScope(node).GET('.catalogueScope'), source);
375
409
  const branch = source.getNodes()[0];
376
410
  const attrs = {...branch.getAttr()};
377
411
  for (const [name, spec] of Object.entries(specifications(parent, branch.nodeTag))) {
@@ -394,6 +428,7 @@ export class VisualEditorLogic {
394
428
  candidateParent.builder.validateChildren(candidateParent.nodeTag, [...(children instanceof node.builder.source.constructor
395
429
  ? children.getNodes().map(child => child.nodeTag) : []), branch.nodeTag]);
396
430
  const inserted = this.appendBranch(candidateParent, branch, label);
431
+ validateCatalogueSource(visualEditorScope(node).GET('.catalogueScope'), candidate);
397
432
  app.src.renderer.validateCandidate(candidate, {replacingNode:design});
398
433
  this.appendBranch(parent, inserted, label);
399
434
  node.SET('.insertionOpen', false);
@@ -453,6 +488,7 @@ export class VisualEditorLogic {
453
488
  if (request.signal.aborted) return;
454
489
  if (design.value.toTytx() !== before) throw new Error('Source changed while preparing preview; it was retained');
455
490
  const candidate = this.page.src.prepareSource(wire, design.builder);
491
+ validateCatalogueSource(editor.GET('.catalogueScope'), candidate);
456
492
  this.page.src.renderer.validateCandidate(candidate, {replacingNode:design});
457
493
  if (editor.GET('.assistantRun')) editor.SET('.assistantRun.blocked', true);
458
494
  editor.SET('.selection', null);
@@ -482,29 +518,18 @@ export class VisualEditorLogic {
482
518
  async copySource(node) {
483
519
  node.SET('.fileStatus', '');
484
520
  try {
485
- const page = node.builder.source.getNode(sourceRoot(node)).getValue(true);
486
- await node.rootBuilder.binding.gramlot.utl.inout.copyText(page.toTytx());
521
+ await node.rootBuilder.binding.gramlot.utl.inout.copyText(this.currentSource(node));
487
522
  node.SET('.fileStatus', 'Source copied');
488
523
  } catch (error) { node.SET('.fileStatus', `Copy failed: ${error.message}`); }
489
524
  }
490
525
  downloadPage(node) {
491
- const page = node.builder.source.getNode(sourceRoot(node)).getValue(true);
492
- node.rootBuilder.binding.gramlot.utl.inout.saveText(page.toTytx(), node.GET('.filename'), 'application/json');
526
+ node.rootBuilder.binding.gramlot.utl.inout.saveText(this.currentSource(node), node.GET('.filename'), 'application/json');
493
527
  }
494
528
 
495
529
  openUpload(node) { node.SET('.uploadOpen', true); }
496
530
  sourceUploaded(node, {item, result}) {
497
531
  try {
498
- const app = node.rootBuilder.binding.gramlot;
499
- const target = node.builder.source.getNode(sourceRoot(node));
500
- const source = app.src.prepareSource(result, target.builder);
501
- const roots = source.getNodes();
502
- if (roots.length !== 1 || roots[0].label !== 'pageRoot') throw new Error('Expected one pageRoot Source');
503
- app.src.renderer.validateCandidate(source, {replacingNode:target});
504
- if (node.GET('.assistantRun')) node.SET('.assistantRun.blocked', true);
505
- target.setValue(source, true, {_text:null}, true);
506
- node.SET('.filename', item.value.getItem('name'));
507
- node.SET('.selection', 'pageRoot');
532
+ this.loadSource(node, {source:result, filename:item.value.getItem('name')});
508
533
  node.SET('.fileStatus', 'Source opened');
509
534
  node.SET('.uploadOpen', false);
510
535
  } catch (error) {
@@ -512,6 +537,41 @@ export class VisualEditorLogic {
512
537
  throw error;
513
538
  }
514
539
  }
540
+ initializeDocument(node) {
541
+ const editor = visualEditorScope(node), source = editor.builder.source;
542
+ const prefix = sourceRoot(editor).split('.');
543
+ const subscription = `${editor.getAttr('visualEditorId')}-document`;
544
+ editor.SET('.modified', false);
545
+ source.subscribe(subscription, {any:event => {
546
+ if (prefix.every((part, index) => event.pathlist[index] === part)) editor.SET('.modified', true);
547
+ }});
548
+ editor.rootBuilder.binding.renderer.onDispose(editor, () => source.unsubscribe(subscription, {any:true}));
549
+ }
550
+ currentSource(node) {
551
+ const editor = visualEditorScope(node);
552
+ return editor.builder.source.getNode(sourceRoot(editor)).getValue(true).toTytx();
553
+ }
554
+ markSaved(node) { visualEditorScope(node).SET('.modified', false); }
555
+ loadSource(node, {source, filename}) {
556
+ const editor = visualEditorScope(node);
557
+ if (typeof source !== 'string') throw new TypeError('source must be Source TYTX');
558
+ if (typeof filename !== 'string' || !filename.trim()) throw new TypeError('filename must be a non-empty string');
559
+ const app = editor.rootBuilder.binding.gramlot;
560
+ const target = editor.builder.source.getNode(sourceRoot(editor));
561
+ const candidate = app.src.prepareSource(source, target.builder);
562
+ const roots = candidate.getNodes();
563
+ if (roots.length !== 1 || roots[0].label !== 'pageRoot') throw new Error('Expected one pageRoot Source');
564
+ validateCatalogueSource(editor.GET('.catalogueScope'), candidate);
565
+ app.src.renderer.validateCandidate(candidate, {replacingNode:target});
566
+ if (editor.GET('.assistantRun')) editor.SET('.assistantRun.blocked', true);
567
+ editor.SET('.selection', null);
568
+ target.setValue(candidate, true, {_text:null}, true);
569
+ editor.SET('.filename', filename);
570
+ editor.SET('.insertionOpen', false);
571
+ editor.SET('.sourceSearch', '');
572
+ editor.SET('.selection', 'pageRoot');
573
+ this.markSaved(editor);
574
+ }
515
575
  toggleNavigation(node) { node.SET('.navigationOpen', node.GET('.navigationOpen') === 'close' ? true : 'close'); }
516
576
  openCatalogue(node) { node.SET(`${editorData(node)}.catalogueOpen`, true); }
517
577
  openProperties(node) { this.showProperties(node, {path:node.GET('.selection')}); }
@@ -542,6 +602,11 @@ export class VisualEditorLogic {
542
602
  node.rootBuilder.binding.renderer.destination.ownerDocument.documentElement.setAttribute('data-theme', mode);
543
603
  }
544
604
  initializeEditor(node, {dataRoot}) {
605
+ const scope = node.GET('.catalogueScope');
606
+ validateCatalogue(scope);
607
+ if (Array.isArray(scope)) for (const tag of scope) {
608
+ if (!node.builder.schema[tag]) throw new Error(`Unknown catalogue tag: ${tag}`);
609
+ }
545
610
  node.SET('.editingMode', 'source');
546
611
  node.SET('.clipboard', new Bag());
547
612
  node.SET('.clipboardVisible', false);
@@ -572,9 +637,10 @@ export class VisualEditorLogic {
572
637
  return bag;
573
638
  };
574
639
  for (const [path, caption, tags] of catalogueSections) {
575
- if (tags.split(' ').some(tag => node.builder.schema[tag])) ensureGroup(path, caption);
640
+ if (tags.split(' ').some(tag => node.builder.schema[tag] && catalogueAllows(scope, tag, node.builder.schema[tag]._meta ?? {}))) ensureGroup(path, caption);
576
641
  }
577
642
  for (const [tag, info] of Object.entries(node.builder.schema).sort(([a], [b]) => a.localeCompare(b))) {
643
+ if (!catalogueAllows(scope, tag, info._meta ?? {})) continue;
578
644
  if (info._meta?.data_element || info._meta?.subbuilder || info._meta?.container) continue;
579
645
  const root = info._meta?.gramlot_component ? 'components' : 'html';
580
646
  const section = catalogueSections.find(([path, , tags]) => path.startsWith(root + '.') && tags.split(' ').includes(tag));
@@ -602,6 +668,7 @@ export class VisualEditorLogic {
602
668
  const targetPath = `${sourceRoot(node)}.${path}`;
603
669
  const moving = node.builder.source.getNode(sourcePath);
604
670
  if (!moving || sourcePath === `${sourceRoot(node)}.pageRoot`) throw new Error('The page root cannot be moved');
671
+ validateCatalogueSource(visualEditorScope(node).GET('.catalogueScope'), moving.parentBag);
605
672
  if (moving.resolver) throw new Error('Resolver-backed Source nodes cannot be moved in this trial');
606
673
  if (sourcePath === targetPath || targetPath.startsWith(sourcePath + '.')) throw new Error('A node cannot be moved into itself');
607
674
  const parent = item, origin = moving.parentBag, Source = node.builder.source.constructor;
@@ -631,6 +698,7 @@ export class VisualEditorLogic {
631
698
  return;
632
699
  }
633
700
  const tag = dropValues['app/widget'].tag;
701
+ this.validateCatalogueTag(node, tag);
634
702
  item.builder.validateParent(tag, item.nodeTag);
635
703
  const body = item.getValue(true);
636
704
  item.builder.validateChildren(item.nodeTag, [...(body instanceof node.builder.source.constructor ? body.getNodes().map(child => child.nodeTag) : []), tag]);
@@ -644,7 +712,7 @@ export class VisualEditorLogic {
644
712
  fields.getValue(true).clear();
645
713
  const root = node.builder.wrapSource(fields);
646
714
  root.p(`Insert ${tag} into ${item.label} [${item.nodeTag}]`, {class:'visual-editor-hint'});
647
- const form = root.formlet({columns:2, gap:'8px 10px', lbl_position:'TL', box_c_width:'100%', align_items:'start'});
715
+ const form = root.formlet({columns:2, gap:'4px 6px', lbl_position:'TL', box_c_width:'100%', align_items:'start'});
648
716
  for (const [name, spec] of required) this.parameterField(node, form, tag, name, spec, 'insertion', spec.default);
649
717
  node.SET('.insertionOpen', true);
650
718
  }
@@ -659,8 +727,9 @@ export class VisualEditorLogic {
659
727
  const parent = current.parentNode;
660
728
  const entries = specifications(parent, current.nodeTag, current);
661
729
  node.SET('.properties.path', path);
730
+ this.attributeRows(node, current);
662
731
  node.SET('.propertiesTitle', `${current.label} [${current.nodeTag}]`);
663
- node.SET('.propertiesHeight', `${Math.min(340, 120 + Math.ceil(Object.keys(entries).filter(name => parameterTheme(name, new Set()) === 'general').length / 2) * 48)}px`);
732
+ node.SET('.propertiesHeight', `${Math.min(300, Math.max(180, 80 + Math.ceil(Object.keys(entries).filter(name => parameterTheme(name, new Set()) === 'general').length / 2) * 38))}px`);
664
733
  const root = node.builder.wrapSource(fields);
665
734
  if (path !== 'pageRoot') root.p(path, {class:'visual-editor-destination'});
666
735
  const parentFields = new Set(Object.keys(parent._getMeta('gramlot_component')?.childParameters ?? {}));
@@ -671,11 +740,13 @@ export class VisualEditorLogic {
671
740
  tabMode:'underline', height:'100%', min_height:0, flex:1});
672
741
  for (const [key, title] of parameterThemes) {
673
742
  if (!groups.get(key).length) continue;
674
- const panel = tabs.contentPane({pageName:key, title, overflow:'auto', padding:'10px', min_height:0});
743
+ const panel = tabs.contentPane({pageName:key, title, overflow:'auto', padding:'4px', min_height:0,
744
+ ...(key === 'styles' ? {nodeId:visualEditorScope(node).getAttr('visualEditorId') + 'StyleAttributes'} : {})});
745
+ if (key === 'styles') { this.attributeFields(node, panel, current, 'styles'); continue; }
675
746
  if (key === 'container') panel.p(`Child parameters of ${parent.nodeTag}`, {class:'visual-editor-hint'});
676
747
  if (key === 'behaviour' && Object.hasOwn(entries, 'action')) panel.p('action: use a named Logic method, for example openCatalogue.', {class:'visual-editor-hint'});
677
748
  if (key === 'behaviour' && current.nodeTag === 'borderContainer') panel.p('persist remembers splitter sizes and requires a stable container id.', {class:'visual-editor-hint'});
678
- const form = panel.formlet({columns:2, gap:'8px 10px', lbl_position:'TL', box_c_width:'100%', align_items:'start'});
749
+ const form = panel.formlet({columns:2, gap:'4px 6px', lbl_position:'TL', box_c_width:'100%', align_items:'start'});
679
750
  if (key === 'general' && current._getMeta('gramlot_component')?.labelbox) {
680
751
  this.labelboxFields(node, form, current, entries);
681
752
  }
@@ -692,7 +763,7 @@ export class VisualEditorLogic {
692
763
  if (!advanced) {
693
764
  const details = panel.details({class:'visual-validation-advanced'});
694
765
  details.summary('Conditions and messages');
695
- advanced = details.formlet({columns:2, gap:'8px 10px', lbl_position:'TL', box_c_width:'100%', align_items:'start'});
766
+ advanced = details.formlet({columns:2, gap:'4px 6px', lbl_position:'TL', box_c_width:'100%', align_items:'start'});
696
767
  }
697
768
  target = advanced;
698
769
  }
@@ -700,8 +771,142 @@ export class VisualEditorLogic {
700
771
  this.parameterField(node, target, current.nodeTag, name, spec, 'properties', value ?? spec.default);
701
772
  }
702
773
  }
774
+ const more = tabs.contentPane({nodeId:visualEditorScope(node).getAttr('visualEditorId') + 'MoreAttributes', pageName:'attributes', title:'More attributes', overflow:'auto', padding:'4px', min_height:0});
775
+ this.attributeFields(node, more, current);
703
776
  node.SET('.propertiesOpen', true);
704
777
  }
778
+ attributeRows(node, current) {
779
+ const rows = new Bag();
780
+ for (const [name, value] of Object.entries(current.getAttr())) {
781
+ if (name === '_meta') continue;
782
+ const type = scalarType(value);
783
+ const text = type ? scalarText(value, type) : '[non-scalar value]';
784
+ rows.setItem(`r${rows.length}`, new Bag({name, type:type ?? 'readonly', text, original:text}));
785
+ }
786
+ node.SET('.properties.attributeRows', rows);
787
+ node.SET('.properties.attributeDraft', new Bag({name:'', type:'string', text:''}));
788
+ node.SET('.properties.attributeDraftHidden', true);
789
+ }
790
+ attributeFields(node, panel, current, scope = 'attributes') {
791
+ const path = node.GET('.properties.path');
792
+ const base = `${editorData(node)}.properties`;
793
+ const renderer = node.rootBuilder.binding.gramlot.src.renderer;
794
+ const parentFields = new Set(Object.keys(current.parentNode._getMeta('gramlot_component')?.childParameters ?? {}));
795
+ const list = panel.div({class:'visual-editor-attribute-list', 'aria-label':scope === 'styles' ? 'Style attributes' : 'Node attributes'});
796
+ const heading = list.div({class:'visual-editor-attribute-row visual-editor-attribute-heading'});
797
+ heading.span('Attribute', {class:'visual-editor-attribute-name'});
798
+ const headingValue = heading.div({class:'visual-editor-attribute-value'});
799
+ headingValue.span('Value');
800
+ headingValue.button('+', {action:'beginAttribute', editingPath:path,
801
+ 'aria-label':scope === 'styles' ? 'Add style attribute' : 'Add attribute', title:'Add attribute', class:'visual-editor-attribute-command'});
802
+ for (const row of node.GET('.properties.attributeRows').getNodes()) {
803
+ const name = row.value.getItem('name'), type = row.value.getItem('type'), key = row.label;
804
+ if (scope === 'styles' && parameterTheme(name, parentFields) !== 'styles' && !renderer._isStyleContribution(name)) continue;
805
+ const editable = type !== 'readonly';
806
+ const line = list.div({class:'visual-editor-attribute-row'});
807
+ line.span(name, {class:'visual-editor-attribute-name', title:name});
808
+ const cell = line.div({class:'visual-editor-attribute-value'});
809
+ cell.input({value:`^${base}.attributeRows.${key}.text`, disabled:!editable,
810
+ 'aria-label':`${name} attribute value`, title:editable ? type : 'Non-scalar values are read-only'});
811
+ cell.button('×', {action:'removeAttribute', attributeRow:key, editingPath:path, disabled:!editable,
812
+ 'aria-label':`Remove ${name} attribute`, title:`Remove ${name}`, class:'visual-editor-attribute-command'});
813
+ // Both tabs bind the same row; one controller owns each write.
814
+ if (editable && scope === 'attributes') line.dataController({func:'changeAttribute', value:`^${base}.attributeRows.${key}.text`,
815
+ attributeRow:key, editingPath:path, _userChanges:true});
816
+ }
817
+ const add = list.div({class:'visual-editor-attribute-row', hidden:`^${base}.attributeDraftHidden`,
818
+ connect_onkeydown:'attributeDraftKey'});
819
+ const nameCell = add.div({class:'visual-editor-attribute-name'});
820
+ nameCell.input({value:`^${base}.attributeDraft.name`, live:true, 'aria-label':'New attribute name', placeholder:'Attribute name'});
821
+ const valueCell = add.div({class:'visual-editor-attribute-value'});
822
+ valueCell.input({value:`^${base}.attributeDraft.text`, live:true, 'aria-label':'New attribute value', placeholder:'Value'});
823
+ const types = valueCell.select({value:`^${base}.attributeDraft.type`, 'aria-label':'New attribute type'});
824
+ for (const type of editorTypes) types.option(type, {value:type});
825
+ valueCell.button('✓', {action:'addAttribute', editingPath:path, 'aria-label':'Apply new attribute', title:'Apply (Enter)', class:'visual-editor-attribute-command'});
826
+ valueCell.button('×', {action:'cancelAttribute', 'aria-label':'Cancel new attribute', title:'Cancel (Escape)', class:'visual-editor-attribute-command'});
827
+ }
828
+ beginAttribute(node, {editingPath}) {
829
+ const editor = visualEditorScope(node);
830
+ if (editingPath !== editor.GET('.selection')) return;
831
+ editor.SET('.properties.attributeDraft', new Bag({name:'', type:'string', text:''}));
832
+ editor.SET('.properties.attributeDraftHidden', false);
833
+ editor.SET('.propertyError', '');
834
+ }
835
+ cancelAttribute(node) {
836
+ visualEditorScope(node).SET('.properties.attributeDraftHidden', true);
837
+ }
838
+ attributeDraftKey(node, event) {
839
+ if (event.isComposing || !['Enter', 'Escape'].includes(event.key)) return;
840
+ event.preventDefault();
841
+ event.stopPropagation();
842
+ const editor = visualEditorScope(node);
843
+ if (event.key === 'Escape') this.cancelAttribute(editor);
844
+ else this.addAttribute(editor, {editingPath:editor.GET('.properties.path')});
845
+ }
846
+ addAttribute(node, {editingPath}) {
847
+ const editor = visualEditorScope(node);
848
+ if (editingPath !== editor.GET('.selection')) return;
849
+ editor.SET('.propertyError', '');
850
+ try {
851
+ const draft = editor.GET('.properties.attributeDraft');
852
+ const name = draft.getItem('name');
853
+ if (!name || !/^[^\s"'<>/=]+$/.test(name)) throw new Error('Enter a valid attribute name.');
854
+ if (['_meta', '__proto__', 'constructor', 'prototype'].includes(name)) throw new Error('Unsupported attribute name.');
855
+ const current = editor.builder.source.getNode(`${sourceRoot(editor)}.${editingPath}`);
856
+ if (!current) throw new Error('The selected Source node no longer exists');
857
+ if (Object.hasOwn(current.getAttr(), name)) throw new Error(`Duplicate attribute: ${name}`);
858
+ const value = parseScalar(draft.getItem('type'), String(draft.getItem('text') ?? ''));
859
+ this.writeAttribute(editor, current, editingPath, name, value, false);
860
+ } catch (error) { editor.SET('.propertyError', error.message); }
861
+ }
862
+ changeAttribute(node, {attributeRow, editingPath, value}) {
863
+ this.editAttribute(node, {attributeRow, editingPath, value, remove:false});
864
+ }
865
+ removeAttribute(node, {attributeRow, editingPath}) {
866
+ this.editAttribute(node, {attributeRow, editingPath, remove:true});
867
+ }
868
+ editAttribute(node, {attributeRow, editingPath, value, remove}) {
869
+ const editor = visualEditorScope(node);
870
+ if (editingPath !== editor.GET('.selection')) return;
871
+ editor.SET('.propertyError', '');
872
+ try {
873
+ const row = editor.GET('.properties.attributeRows').getItem(attributeRow);
874
+ if (!row || row.getItem('type') === 'readonly') throw new Error('This attribute is not editable');
875
+ const name = row.getItem('name');
876
+ if (['_meta', '__proto__', 'constructor', 'prototype'].includes(name)) throw new Error('Unsupported attribute name.');
877
+ const current = editor.builder.source.getNode(`${sourceRoot(editor)}.${editingPath}`);
878
+ if (!current) throw new Error('The selected Source node no longer exists');
879
+ const attrs = current.getAttr(), type = scalarType(attrs[name]);
880
+ if (!Object.hasOwn(attrs, name) || type !== row.getItem('type') || scalarText(attrs[name], type) !== row.getItem('original'))
881
+ throw new Error('Attribute changed; select the node again before editing.');
882
+ const parsed = remove ? null : parseScalar(type, String(value ?? ''));
883
+ this.writeAttribute(editor, current, editingPath, name, parsed, remove, row);
884
+ } catch (error) { editor.SET('.propertyError', error.message); }
885
+ }
886
+ writeAttribute(editor, current, path, name, value, remove, row = null) {
887
+ const attrs = {...current.getAttr()};
888
+ if (remove) delete attrs[name]; else attrs[name] = value;
889
+ const specs = specifications(current.parentNode, current.nodeTag, current);
890
+ if (specs[name]) this.validateParameter(current.parentNode, current, name, specs[name], remove ? null : value);
891
+ const design = editor.builder.source.getNode(sourceRoot(editor)), app = editor.rootBuilder.binding.gramlot;
892
+ const candidate = app.src.prepareSource(design.getValue(true).toTytx(), design.builder);
893
+ candidate.getNode(path).setAttr(attrs, true, false, false);
894
+ validateCatalogueSource(editor.GET('.catalogueScope'), candidate);
895
+ app.src.renderer.validateCandidate(candidate, {replacingNode:design});
896
+ current.setAttr(attrs, true, false, false);
897
+ if (row && !remove) {
898
+ const text = scalarText(value, row.getItem('type'));
899
+ row.setItem('original', text);
900
+ row.setItem('text', text);
901
+ const type = editor.GET(`.properties.types.${name}`);
902
+ if (specs[name]?.enum) editor.SET(`.properties.parameters.${name}`, value);
903
+ else if (type) editor.SET(`.properties.parameters.${name}.${type}`, value);
904
+ } else {
905
+ const tab = editor.GET('.parameterTab') === 'styles' ? 'styles' : 'attributes';
906
+ this.showProperties(editor, {path});
907
+ editor.SET('.parameterTab', tab);
908
+ }
909
+ }
705
910
  toggleLabelboxAttributes(node, {prefix}) {
706
911
  node.SET(`.properties.${prefix}Hidden`, !node.GET(`.properties.${prefix}Hidden`));
707
912
  }
@@ -803,6 +1008,7 @@ export class VisualEditorLogic {
803
1008
  try {
804
1009
  const current = node.builder.source.getNode(`${sourceRoot(node)}.${editingPath}`);
805
1010
  if (!current) throw new Error('The selected Source node no longer exists');
1011
+ if (parameterName !== '_text' && Object.is(current.getAttr(parameterName), value)) return;
806
1012
  const specs = specifications(current.parentNode, current.nodeTag, current);
807
1013
  const spec = specs[parameterName];
808
1014
  if (!spec) throw new Error(`Unknown parameter: ${parameterName}`);
@@ -814,6 +1020,12 @@ export class VisualEditorLogic {
814
1020
  else attrs[parameterName] = value;
815
1021
  current.setAttr(attrs, true, false, false);
816
1022
  }
1023
+ this.attributeRows(node, current);
1024
+ for (const [field, scope] of [['MoreAttributes', 'attributes'], ['StyleAttributes', 'styles']]) {
1025
+ const panel = editorField(node, field);
1026
+ panel.getValue(true).clear();
1027
+ this.attributeFields(node, node.builder.wrapSource(panel), current, scope);
1028
+ }
817
1029
  } catch (error) { node.SET('.propertyError', error.message); }
818
1030
  }
819
1031
  validateParameter(parent, current, name, spec, value) {
@@ -824,12 +1036,18 @@ export class VisualEditorLogic {
824
1036
  if (!empty && spec.unique && children instanceof parent.builder.source.constructor &&
825
1037
  children.getNodes().some(child => child !== current && child.getAttr(name) === value)) throw new Error(`${name} is already in use`);
826
1038
  }
1039
+ validateCatalogueTag(node, tag) {
1040
+ const scope = visualEditorScope(node).GET('.catalogueScope');
1041
+ if (!catalogueAllows(scope, tag, node.builder.schema[tag]?._meta ?? {}))
1042
+ throw new Error(`Tag ${tag} is outside the editor catalogue`);
1043
+ }
827
1044
  applyInsert(node) {
828
1045
  if (node.GET('.insertion.clipboard')) { this.finishPaste(node); return; }
829
1046
  const path = node.GET('.insertion.parentPath');
830
1047
  const parent = node.builder.source.getNode(`${sourceRoot(node)}.${path}`);
831
1048
  if (!parent) throw new Error('The target Source node is no longer available');
832
1049
  const tag = node.GET('.insertion.tag');
1050
+ this.validateCatalogueTag(node, tag);
833
1051
  const attrs = {};
834
1052
  for (const [name, spec] of Object.entries(specifications(parent, tag)).filter(([, spec]) => spec.required)) {
835
1053
  const type = node.GET(`.insertion.types.${name}`);