@gramlot/gramlot 0.3.24 → 0.3.26

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 (131) hide show
  1. package/dist/components/editors/__init__.py +2 -2
  2. package/dist/components/editors/assets/collection.js +20 -19
  3. package/dist/components/editors/assets/index.js +1 -1
  4. package/dist/components/editors/assets/modules/chunk-74O4WKIV.js +1 -0
  5. package/dist/components/editors/assets/modules/{code-mirror-engine-QX4A5FVO.js → code-mirror-engine-RWQTR5G5.js} +29 -29
  6. package/dist/components/editors/assets/modules/{jodit-engine-MMSPIWM7.js → jodit-engine-MTSA4GZ3.js} +292 -292
  7. package/dist/components/editors/assets/modules/markdown-document-VFC23FAY.js +1 -0
  8. package/dist/components/editors/assets/modules/{prose-mirror-engine-IXTRTG6B.js → prose-mirror-engine-GMZPJPNN.js} +13 -13
  9. package/dist/components/grid/__init__.py +3 -2
  10. package/dist/components/grid/assets/collection.js +68 -17
  11. package/dist/components/grid/assets/index.js +1 -1
  12. package/dist/components/grid/grammar.json +57 -1
  13. package/dist/components/grouplets/__init__.py +2 -2
  14. package/dist/components/grouplets/assets/collection.js +3 -20
  15. package/dist/components/grouplets/assets/index.js +1 -1
  16. package/dist/components/grouplets/assets/modules/chunk-BLMUM44K.js +1 -0
  17. package/dist/components/grouplets/assets/modules/markdown-document-YWNZTOKK.js +1 -0
  18. package/dist/components/inputs/__init__.py +1 -1
  19. package/dist/components/inputs/assets/collection.js +59 -34
  20. package/dist/components/inputs/assets/index.js +1 -1
  21. package/dist/components/inputs/grammar.json +64 -0
  22. package/dist/components/layout/__init__.py +1 -1
  23. package/dist/components/layout/assets/collection.js +67 -57
  24. package/dist/components/layout/assets/index.js +1 -1
  25. package/dist/components/layout/grammar.json +35 -0
  26. package/dist/components/selection_trial/__init__.py +1 -1
  27. package/dist/components/selection_trial/assets/collection.js +3 -3
  28. package/dist/components/selection_trial/assets/index.js +1 -1
  29. package/dist/components/selection_trial/grammar.json +35 -0
  30. package/dist/components/tree/__init__.py +1 -1
  31. package/dist/components/tree/assets/collection.js +26 -23
  32. package/dist/components/tree/assets/index.js +1 -1
  33. package/dist/components/tree/grammar.json +341 -1
  34. package/dist/components/uploads/__init__.py +13 -0
  35. package/dist/components/uploads/assets/collection.js +67 -0
  36. package/dist/components/uploads/assets/index.js +3 -0
  37. package/dist/components/uploads/commands.json +7 -0
  38. package/dist/components/uploads/grammar.json +789 -0
  39. package/dist/{components/editors/assets/modules/chunk-OCFLP2K4.js → gramlot-markdown.js} +12 -12
  40. package/dist/gramlot.js +4910 -566
  41. package/dist/gramlot.min.js +1587 -43
  42. package/dist/runtime-notices.json +28 -0
  43. package/package.json +4 -2
  44. package/src/binding/grid-struct.js +1 -1
  45. package/src/binding/providers.js +4 -1
  46. package/src/binding/remote-resolver.js +1 -8
  47. package/src/binding/runtime.js +40 -1
  48. package/src/binding/validation-context.js +40 -0
  49. package/src/browser-camera-provider.d.ts +8 -0
  50. package/src/browser-camera-provider.js +104 -0
  51. package/src/builder/source.js +13 -2
  52. package/src/components/attachment-manager.js +160 -0
  53. package/src/components/bases.js +17 -6
  54. package/src/components/border-container.js +86 -8
  55. package/src/components/buttons.js +11 -1
  56. package/src/components/choice-editor.js +20 -7
  57. package/src/components/database-choices.js +4 -2
  58. package/src/components/editing-status-styles.js +26 -0
  59. package/src/components/editing-status.js +115 -0
  60. package/src/components/field-state.js +37 -58
  61. package/src/components/grid-cell-editor.js +181 -0
  62. package/src/components/grid-grammar.json +21 -0
  63. package/src/components/grid-structure.js +2 -1
  64. package/src/components/grid-styles.js +51 -1
  65. package/src/components/grid.js +87 -10
  66. package/src/components/grouplet-card.js +11 -3
  67. package/src/components/html-preview.js +17 -4
  68. package/src/components/image-crop-dialog.js +272 -0
  69. package/src/components/image-crop.js +79 -0
  70. package/src/components/image-uploader.js +252 -0
  71. package/src/components/inputs.js +2 -1
  72. package/src/components/jodit-engine.js +1 -1
  73. package/src/components/markdown-document.js +2 -2
  74. package/src/components/screen-capture.js +43 -0
  75. package/src/components/selected-container.js +6 -2
  76. package/src/components/tree.js +416 -17
  77. package/src/components/typed-editor.js +19 -9
  78. package/src/components/upload-engine.js +156 -0
  79. package/src/components/uploader.js +208 -0
  80. package/src/components/uploads.js +7 -0
  81. package/src/editing-session.d.ts +25 -0
  82. package/src/editing-session.js +396 -0
  83. package/src/experiments/selection-trial.js +18 -2
  84. package/src/format.js +22 -7
  85. package/src/gramlot.d.ts +2 -0
  86. package/src/gramlot.js +2 -1
  87. package/src/handlers/device-handler.d.ts +2 -1
  88. package/src/handlers/rpc-handler.d.ts +3 -3
  89. package/src/index-page-styles.js +1 -0
  90. package/src/index.d.ts +13 -0
  91. package/src/index.js +13 -0
  92. package/src/inout.d.ts +2 -0
  93. package/src/inout.js +6 -0
  94. package/src/markdown-loader.d.ts +1 -0
  95. package/src/markdown-loader.js +4 -0
  96. package/src/markdown.d.ts +1 -0
  97. package/src/markdown.js +2 -0
  98. package/src/media-frame.js +9 -0
  99. package/src/renderer/attributes.js +7 -1
  100. package/src/renderer/gramlot-renderer.d.ts +2 -0
  101. package/src/renderer/gramlot-renderer.js +31 -2
  102. package/src/server/assets.d.ts +1 -1
  103. package/src/server/assets.js +1 -1
  104. package/src/server/gramlot-server.d.ts +8 -1
  105. package/src/server/gramlot-server.js +83 -7
  106. package/src/server/index.d.ts +2 -0
  107. package/src/server/index.js +2 -0
  108. package/src/server/page-base.js +17 -4
  109. package/src/server/page.d.ts +13 -1
  110. package/src/server/page.js +6 -0
  111. package/src/server/source-import.d.ts +2 -0
  112. package/src/server/source-import.js +31 -0
  113. package/src/server/upload.d.ts +20 -0
  114. package/src/server/upload.js +142 -0
  115. package/src/server/visual-editor.d.ts +11 -0
  116. package/src/server/visual-editor.js +149 -0
  117. package/src/source-picker.d.ts +9 -0
  118. package/src/source-picker.js +57 -0
  119. package/src/tree-store.d.ts +24 -0
  120. package/src/tree-store.js +193 -0
  121. package/src/validation-run.js +50 -0
  122. package/src/view/button.js +8 -5
  123. package/src/view/controls.js +9 -42
  124. package/src/view/html.js +10 -2
  125. package/src/visual-editor-icons.js +10 -0
  126. package/src/visual-editor.d.ts +56 -0
  127. package/src/visual-editor.js +844 -0
  128. package/themes/gramlot-base/theme.css +99 -0
  129. package/dist/components/editors/assets/modules/chunk-MMJXUHRQ.js +0 -3
  130. package/src/form-state.d.ts +0 -20
  131. package/src/form-state.js +0 -198
@@ -0,0 +1,193 @@
1
+ import {Bag, BagResolver, registerResolver} from '@genrojs/bag';
2
+ import {fromTytx, toTytx} from '@genrojs/tytx';
3
+ import {GramlotBuilder} from './builder/gramlot-builder.js';
4
+ import {randomId} from './random-id.js';
5
+
6
+ /** A branch whose loader is supplied by its owning TreeStore after transport. */
7
+ export class TreeStoreResolver extends BagResolver {
8
+ constructor({readOnly = false} = {}) {
9
+ super({cacheTime: -1, readOnly});
10
+ this.store = null;
11
+ this.path = null;
12
+ this.pending = null;
13
+ }
14
+ bind(store, path) {
15
+ if (this.store !== null) throw new Error('TreeStoreResolver is already bound');
16
+ this.store = store;
17
+ this.path = path;
18
+ }
19
+ load() {
20
+ if (this.store === null) throw new Error('TreeStoreResolver is not bound to a store');
21
+ if (this.pending !== null) return this.pending;
22
+ const node = this.node;
23
+ const path = this.path ? this.store.pathFor(node) : '';
24
+ const pending = this.store.load(path, path ? node.label : null, path ? {...node.attr} : {});
25
+ this.pending = pending;
26
+ pending.finally(() => { if (this.pending === pending) this.pending = null; }).catch(() => {});
27
+ return pending;
28
+ }
29
+ }
30
+
31
+ registerResolver(TreeStoreResolver, {
32
+ module: 'gramlot.tree_store', name: 'TreeStoreResolver',
33
+ encode: () => ({args: [], kwargs: {}}),
34
+ decode: () => new TreeStoreResolver(),
35
+ });
36
+
37
+ /** One RPC method supplies the root and every lazy branch of a Data Bag. */
38
+ export class TreeStore {
39
+ constructor({gramlot, method, params = {}}) {
40
+ if (!gramlot || typeof method !== 'string' || !method) throw new TypeError('TreeStore requires a page and method');
41
+ for (const key of ['path', 'label', 'attributes']) {
42
+ if (Object.hasOwn(params, key)) throw new TypeError(`TreeStore params reserves ${key}`);
43
+ }
44
+ this.gramlot = gramlot;
45
+ this.method = method;
46
+ this.params = {...params};
47
+ this.controller = new AbortController();
48
+ this.root = null;
49
+ }
50
+ pathFor(node) {
51
+ const labels = [];
52
+ while (node && node.parentBag !== this.root) {
53
+ labels.unshift(node.label);
54
+ node = node.parentNode;
55
+ }
56
+ if (!node || this.root === null) throw new Error('TreeStore node is outside its root');
57
+ labels.unshift(node.label);
58
+ return labels.join('.');
59
+ }
60
+ async load(path = '', label = null, attributes = {}) {
61
+ if (this.controller.signal.aborted) throw this.controller.signal.reason;
62
+ const result = await this.gramlot.rpc.call('data', this.method,
63
+ {...this.params, path, label, attributes}, {signal: this.controller.signal});
64
+ if (this.controller.signal.aborted) throw this.controller.signal.reason;
65
+ if (!(result instanceof Bag)) throw new TypeError('TreeStore method must return a Bag');
66
+ if (!path) {
67
+ this.root = result;
68
+ result.setBackref();
69
+ }
70
+ const bind = (bag, prefix) => {
71
+ for (const node of bag.getNodes()) {
72
+ const nodePath = prefix ? `${prefix}.${node.label}` : node.label;
73
+ if (node.resolver instanceof TreeStoreResolver) node.resolver.bind(this, nodePath);
74
+ if (node.staticValue instanceof Bag) bind(node.staticValue, nodePath);
75
+ }
76
+ };
77
+ bind(result, path);
78
+ return result;
79
+ }
80
+ dispose() { this.controller.abort(); }
81
+ }
82
+
83
+ /** Source lifecycle for the Python tree_store composition. */
84
+ export class TreeStoreLogic {
85
+ treeFavoriteActionState(node, {item, state}) {
86
+ const hidden = item.resolver !== null || item.staticValue instanceof Bag;
87
+ if (item.getAttr('favoriteEntry') === true) return {hidden: false, icon: '✕', title: 'Remove favorite'};
88
+ const saved = !hidden && state.getNodes().some(favorite => favorite.getAttr('fieldpath') === item.getAttr('fieldpath'));
89
+ return {hidden, icon: saved ? '♥' : '♡', title: saved ? 'Remove favorite' : 'Add favorite'};
90
+ }
91
+
92
+ treeFavoritesMount(node, {favoriteKey}) {
93
+ const storage = this.page.src.renderer.destination.ownerDocument.defaultView.localStorage;
94
+ const saved = storage.getItem(favoriteKey);
95
+ this.setTreeFavorites(node.getRelativeData('.'), saved === null ? [] : fromTytx(saved));
96
+ }
97
+
98
+ setTreeFavorites(state, records) {
99
+ if (!Array.isArray(records)) throw new TypeError('Tree favorites must be an array');
100
+ const favorites = new Bag();
101
+ records.forEach((record, index) => {
102
+ if (!record || typeof record.fieldpath !== 'string' || typeof record.path !== 'string' ||
103
+ typeof record.caption !== 'string' || !record.attrs || typeof record.attrs !== 'object') {
104
+ throw new TypeError('Invalid tree favorite');
105
+ }
106
+ const attrs = {...record.attrs};
107
+ for (const name of ['caption', 'fullcaption']) {
108
+ if (typeof attrs[name] === 'string')
109
+ attrs[name] = attrs[name].replace(/(^|\.)!!(?:\[[^\]]+\])?/g, '$1');
110
+ }
111
+ favorites.setItem(`favorite_${index}`, null, {...attrs,
112
+ favoriteEntry: true, originalPath: record.path});
113
+ });
114
+ state.setItem('favorites', favorites);
115
+ }
116
+
117
+ treeFavoriteToggle(node, {item, path, favoriteKey}) {
118
+ if (item.resolver || item.staticValue instanceof Bag) return;
119
+ const attrs = item.getAttr();
120
+ const state = node.getRelativeData('.');
121
+ const records = state.getItem('favorites').getNodes().map(favorite => {
122
+ const {favoriteEntry, originalPath, ...attributes} = favorite.getAttr();
123
+ return {fieldpath: attributes.fieldpath, path: originalPath, caption: attributes.caption, attrs: attributes};
124
+ });
125
+ const index = records.findIndex(record => record.fieldpath === attrs.fieldpath);
126
+ if (index === -1) records.push({fieldpath: attrs.fieldpath, path, caption: attrs.caption, attrs: {...attrs}});
127
+ else records.splice(index, 1);
128
+ const storage = this.page.src.renderer.destination.ownerDocument.defaultView.localStorage;
129
+ storage.setItem(favoriteKey, toTytx(records));
130
+ this.setTreeFavorites(state, records);
131
+ }
132
+
133
+ treeStoreMount(node, {storeMethod, storeParams}) {
134
+ const scope = node.parentNode;
135
+ const state = node.getRelativeData('.');
136
+ const store = new TreeStore({gramlot: this.page, method: storeMethod, params: storeParams});
137
+ this.page.src.renderer.onDispose(scope, () => store.dispose());
138
+ const resolver = new TreeStoreResolver({readOnly: true});
139
+ resolver.bind(store, '');
140
+ state.setResolver('store', resolver);
141
+ return Promise.resolve(state.getItem('store')).then(value => {
142
+ if (!store.controller.signal.aborted) state.setItem('store', value);
143
+ });
144
+ }
145
+
146
+ treeInspect(node, {item, path}) {
147
+ const binding = this.page.src.binding.bindingFor(node);
148
+ let closed = false;
149
+ const id = `tree_inspect_${randomId()}`;
150
+ let release = () => {};
151
+ const close = () => {
152
+ if (closed) return;
153
+ closed = true;
154
+ release();
155
+ if (this.page.src.source.getNode(id)) this.page.src.source.popNode(id);
156
+ };
157
+ release = binding.track(close);
158
+ try {
159
+ const builder = new GramlotBuilder();
160
+ const dialog = builder.root.html_dialog({nodeId: id, request: id,
161
+ connect_oncancel: 'treeInspectClose', connect_onclose: 'treeInspectClose',
162
+ 'aria-labelledby': `${id}_title`,
163
+ style: 'width:min(36rem,calc(100% - 48px));max-height:80vh;overflow:auto;'});
164
+ dialog.h2('Attributes', {id: `${id}_title`});
165
+ dialog.p(`==${JSON.stringify(path)}`);
166
+ dialog.html_button('Close', {type: 'button', autofocus: true, request: id, connect_onclick: 'treeInspectClose'});
167
+ const table = dialog.table();
168
+ for (const [name, value] of Object.entries(item.getAttr())) {
169
+ const row = table.tr();
170
+ row.th(`==${JSON.stringify(name)}`, {scope: 'row'});
171
+ const text = typeof value === 'string' ? value : value === undefined ? 'undefined' : toTytx(value);
172
+ row.td(`==${JSON.stringify(text)}`);
173
+ }
174
+ this.page.src.source.setItem(id, this.page.src.prepareSource(builder.source));
175
+ const dialogNode = this.page.src.binding.nodeIds.get(id);
176
+ Object.defineProperty(dialogNode, 'treeInspectClose', {value: close, configurable: true});
177
+ this.page.src.renderer.onDispose(dialogNode, () => {
178
+ close();
179
+ delete dialogNode.treeInspectClose;
180
+ });
181
+ this.page.dom.getDomNode(dialogNode).showModal();
182
+ } catch (error) {
183
+ close();
184
+ throw error;
185
+ }
186
+ }
187
+
188
+ treeInspectClose(node, event) {
189
+ event.preventDefault();
190
+ const dialog = this.page.src.binding.nodeIds.get(node.getAttr('request'));
191
+ if (dialog) dialog.treeInspectClose();
192
+ }
193
+ }
@@ -0,0 +1,50 @@
1
+ /** One validation attempt lifecycle, independent of a mounted control. */
2
+ export class ValidationRun {
3
+ epoch = 0;
4
+ controller = null;
5
+ cancel() {
6
+ this.epoch++;
7
+ this.controller?.abort();
8
+ this.controller = null;
9
+ }
10
+ start(value, rules, context, execute, complete, pending = () => {}) {
11
+ this.cancel();
12
+ const controller = new AbortController(), epoch = this.epoch;
13
+ this.controller = controller;
14
+ const current = context.validationCurrent();
15
+ const isCurrent = () => epoch === this.epoch && !controller.signal.aborted && current();
16
+ const failure = error => ({value, modified:false, error:error.message, warnings:[], issues:[], datachanges:[]});
17
+ let settled = false;
18
+ const finish = result => {
19
+ if (settled || !isCurrent()) return {ok:false};
20
+ settled = true;
21
+ this.controller = null;
22
+ const outcome = {ok:!result.error, value:result.value, result, rules, isCurrent};
23
+ complete(outcome);
24
+ return outcome;
25
+ };
26
+ let result;
27
+ try {
28
+ if (rules.validate_timeout != null && (!Number.isInteger(rules.validate_timeout) || rules.validate_timeout <= 0)) {
29
+ throw new TypeError('validate_timeout must be a positive integer in milliseconds.');
30
+ }
31
+ result = execute(value, rules, {...context, signal:controller.signal});
32
+ } catch (error) { return finish(failure(error)); }
33
+ if (!(result instanceof Promise)) return finish(result);
34
+ pending();
35
+ return new Promise(resolve => {
36
+ let timer;
37
+ const abort = () => { clearTimeout(timer); resolve({ok:false}); };
38
+ controller.signal.addEventListener('abort', abort, {once:true});
39
+ const settle = answer => {
40
+ clearTimeout(timer);
41
+ controller.signal.removeEventListener('abort', abort);
42
+ try { resolve(finish(answer)); } catch (error) { context.reportError(error, 'Validation completion failed'); resolve({ok:false}); }
43
+ };
44
+ if (rules.validate_timeout != null) timer = setTimeout(() => {
45
+ settle(failure(new Error('Validation timed out.'))); controller.abort();
46
+ }, rules.validate_timeout);
47
+ result.then(settle, error => settle(failure(error)));
48
+ });
49
+ }
50
+ }
@@ -122,6 +122,9 @@ export class ButtonBinding {
122
122
  event.stopPropagation();
123
123
  return target.activateCommand(event);
124
124
  }
125
+ const rowActions = this.element.closest('gramlot-row-actions');
126
+ const rowContext = rowActions ? rowActions.getRowContext() : null;
127
+ if (rowActions && rowContext === null) return;
125
128
  if (!this.element.prepareCommand(event)) return;
126
129
  const mechanism = this.mechanism;
127
130
  if (!mechanism) return;
@@ -143,7 +146,7 @@ export class ButtonBinding {
143
146
  release();
144
147
  this.#cancelDelay = null;
145
148
  this.#pendingCount = 0;
146
- this.#execute(event, count, activation);
149
+ this.#execute(event, count, activation, rowContext);
147
150
  }, delay);
148
151
  const release = this.binding.track(() => this.#cancelDelay?.());
149
152
  this.#cancelDelay = () => {
@@ -156,7 +159,7 @@ export class ButtonBinding {
156
159
  return;
157
160
  }
158
161
  this.#cancelDelay?.();
159
- return this.#execute(event, counter, activation);
162
+ return this.#execute(event, counter, activation, rowContext);
160
163
  }
161
164
 
162
165
  async #executeRegistered(activation) {
@@ -175,7 +178,7 @@ export class ButtonBinding {
175
178
  }
176
179
 
177
180
  /** Deliver the last event once; arguments are read when the mechanism executes. */
178
- #execute(event, counter, activation = null) {
181
+ #execute(event, counter, activation = null, rowContext = null) {
179
182
  if (activation) return this.#executeRegistered(activation);
180
183
  if (this.binding.closed || this.element.disabled) return;
181
184
  const mechanism = this.mechanism;
@@ -184,12 +187,12 @@ export class ButtonBinding {
184
187
  const modifiers = eventToString(event);
185
188
  if (mechanism === 'controller') {
186
189
  const provider = this.binding.runtime.bindingFor(this.controllers[0])?.providers[0];
187
- provider?.invoke({kind: 'click', event, counter});
190
+ provider?.invoke({kind: 'click', event, counter, rowContext});
188
191
  } else if (mechanism === 'action') {
189
192
  const read = () => {
190
193
  const [, attrs] = node.rootBuilder.runtimeValues(node);
191
194
  const authored = Object.fromEntries(Object.entries(attrs).filter(([name]) => name !== 'ask'));
192
- return {...this.binding.runtime.renderer.references.resolveArguments(authored), event, _counter: counter, modifiers};
195
+ return {...this.binding.runtime.renderer.references.resolveArguments(authored), ...rowContext, event, _counter: counter, modifiers};
193
196
  };
194
197
  const execute = result => {
195
198
  if (this.binding.closed || this.element.disabled || result === null) return;
@@ -7,8 +7,9 @@
7
7
 
8
8
  import {createDecimal, isDecimal, getDecimalLibrary} from '@genrojs/tytx';
9
9
  import {Bag} from '@genrojs/bag';
10
+ import {validationContext} from '../binding/validation-context.js';
10
11
  import {XHTML_NS} from '../renderer/attributes.js';
11
- import {callLogic, invokeHook} from '../binding/hooks.js';
12
+ import {callLogic} from '../binding/hooks.js';
12
13
 
13
14
  // Native input.type and input/select.multiple use setters; radio group updates membership.
14
15
  const CONTROL_TAGS = new Set(['input', 'select', 'textarea']);
@@ -207,14 +208,6 @@ export class ControlAdapter {
207
208
  class ComponentControl extends ControlAdapter {
208
209
  #releaseForm;
209
210
  form = null;
210
- commitFormValue(value) { super.commit(null,value); }
211
- validateForm() {
212
- const value = this.node.getRelativeData(this.node.getAttr('value'));
213
- commitComponent(this.element,this.element.validateCandidate(value, () => {}), result => {
214
- this.form.candidate(this,result.value);
215
- });
216
- }
217
-
218
211
  static writesDefault = false;
219
212
  static preservesUnchangedValue = true;
220
213
  get eventElement() { return this.element.control; }
@@ -239,7 +232,8 @@ class ComponentControl extends ControlAdapter {
239
232
  detach() { this.element.releaseControl(); this.#releaseForm?.(); super.detach(); }
240
233
  commit(event) {
241
234
  if (this.binding.closed || this.element.control.disabled || this.element.control.readOnly) return;
242
- commitComponent(this.element, this.element.acceptControlValue(), result => super.commit(event, result.value));
235
+ const outcome = this.element.acceptControlValue();
236
+ if (!this.form) commitComponent(this.element, outcome, result => super.commit(event, result.value));
243
237
  }
244
238
  get writeEvent() {
245
239
  if (this.element.commitOnChange) return 'change';
@@ -613,18 +607,12 @@ const INPUT_CONTROLS = {
613
607
  /** Component validation uses the same Source, activated code and RPC services as controllers. */
614
608
  function componentContext(adapter) {
615
609
  const {binding, node} = adapter, app = binding.runtime.gramlot;
616
- const invoke = (attribute, code, keywords, expression = false) => {
617
- if (!expression) return invokeHook(binding.runtime, node, attribute, code, keywords);
618
- return binding.runtime.inlineCompiler.compile(node, attribute, code, Object.keys(keywords),
619
- `return (${code});`)(keywords);
620
- };
621
610
  return {
622
611
  locale:app.locale, timeZone:app.timeZone, createDecimal, isDecimal, getDecimalLibrary,
623
612
  form:adapter.form,
624
- formCandidate:value => adapter.form?.candidate(adapter,value),
625
- formPending:pending => adapter.form?.pending(adapter,pending),
613
+ formCancelValidation:() => adapter.form?.cancelValidation(node),
614
+ formValidateCandidate:(value, selection) => adapter.form.validateCandidate(node,value,selection),
626
615
  formValidate:() => adapter.form?.scheduleValidation(adapter),
627
- formResult:result => adapter.form?.result(node,result),
628
616
  formSelectionPending:active => adapter.form?.pendingPart(node,'selection',active ? 'active' : null),
629
617
  formSelectionError:message => adapter.form?.issue(node,'selection',message),
630
618
  formParseError:message => adapter.form?.parseError(node,message),
@@ -633,8 +621,8 @@ function componentContext(adapter) {
633
621
  isActive:() => !binding.closed,
634
622
  reportError:(error, title) => { if (!binding.closed) binding.runtime.reportError(error, title); },
635
623
  callLogic:(name, keywords) => callLogic(binding.runtime, node, name, keywords),
636
- format:(value, options) => app.format(value, options), invoke,
637
- remote:(method, keywords, signal) => app.rpc.call('data', method, keywords, {signal}),
624
+ format:(value, options) => app.format(value, options),
625
+ ...validationContext(binding),
638
626
  selectionOutputs:({selectedCaption, selectedRecord, fields}, row) => {
639
627
  if (binding.closed) return;
640
628
  if (selectedCaption) node.setRelativeData(selectedCaption, row?.caption ?? null);
@@ -643,30 +631,9 @@ function componentContext(adapter) {
643
631
  node.setRelativeData(path, row?.record[name.slice(9)] ?? null);
644
632
  }
645
633
  },
646
- validationCurrent:() => {
647
- const pointer = node.getAttr('value');
648
- const path = node.pointerType(pointer) ? node.absDatapath(pointer) : null;
649
- return () => !binding.closed && node.getAttr('value') === pointer && (path === null || node.absDatapath(pointer) === path);
650
- },
651
- finishValidation:({ok, result, rules}) => {
652
- if (binding.closed) return;
653
- if (ok) for (const patch of result.datachanges) node.getRelativeData('.').update(patch);
654
- const attribute = ok ? 'validate_onAccept' : 'validate_onReject';
655
- if (rules[attribute]) {
656
- const report = error => { if (!binding.closed) binding.runtime.reportError(error, 'Validation callback failed'); };
657
- try {
658
- const validations = Object.fromEntries(Object.entries(rules).map(([key, value]) => [key.slice(9), value]));
659
- const returned = invoke(attribute, rules[attribute], {value:result.value, result, validations, userChange:true});
660
- if (returned instanceof Promise) returned.catch(report);
661
- } catch (error) { report(error); }
662
- }
663
- },
664
- checkDataPatch:patch => {
665
- if (!(patch instanceof Bag)) throw new TypeError('Validation data changes must be a Bag.');
666
- if (!(node.getRelativeData('.') instanceof Bag)) throw new TypeError('Validation data changes require a Bag datapath.');
667
- }
668
634
  };
669
635
  }
636
+
670
637
  function commitComponent(host, outcome, commit) {
671
638
  const context = host.pageContext;
672
639
  const finish = result => { if (result.ok && result.isCurrent()) { commit(result); host.finishValidation(result); } };
package/src/view/html.js CHANGED
@@ -39,8 +39,9 @@ function domPropertyName(name) {
39
39
  * names and style arrive adapted by the renderers (GramlotHtmlRenderer, GramlotSvgRenderer).
40
40
  */
41
41
  export class HtmlElement {
42
- constructor({format, metadataAttributes = [], invokeScript = null, callLogic = null, reportError = null} = {}) {
42
+ constructor({format, metadataAttributes = [], invokeScript = null, callLogic = null, reportError = null, uploadContext = null} = {}) {
43
43
  this.format = format;
44
+ this.uploadContext = uploadContext;
44
45
  this.invokeScript = invokeScript;
45
46
  this.callLogic = callLogic;
46
47
  this.reportError = reportError;
@@ -131,6 +132,7 @@ export class HtmlElement {
131
132
  timeZone: node.rootBuilder.binding.gramlot.timeZone,
132
133
  collectionView: (bag, rowMode) => node.rootBuilder.binding.collectionView(node, bag, rowMode),
133
134
  format: this.format,
135
+ upload: () => this.uploadContext(),
134
136
  reportError: (error, title) => this.reportError(node, error, title),
135
137
  publish: (topic, payload) => node.publish(topic, payload),
136
138
  writeParameter: (name, value) => this.writeParameter(node, name, value),
@@ -226,7 +228,13 @@ export class HtmlElement {
226
228
  }
227
229
  if (this.definition(node).meta.gramlot_component) {
228
230
  if (this.definition(node).meta.gramlot_component.bagStore) {
229
- element.setStoreBag(node.getRelativeData(node.getAttr('storepath')));
231
+ if (node.nodeTag === 'tree') element.setStoreBag(node.rootBuilder.binding.treeStore(node));
232
+ else {
233
+ const path = node.absDatapath(node.getAttr('storepath'));
234
+ if (!change || change.path === path || change.path.startsWith(`${path}.`) || path.startsWith(`${change.path}.`)) {
235
+ element.setStoreBag(node.getRelativeData(node.getAttr('storepath')));
236
+ }
237
+ }
230
238
  }
231
239
  if (this.definition(node).meta.gramlot_component.bagStruct) {
232
240
  const path = node.absDatapath(node.getAttr('structpath'));
@@ -0,0 +1,10 @@
1
+ export const toolIcons = {"navigation": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%237b8795%22%20stroke-width%3D%221.7%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Crect%20x%3D%223%22%20y%3D%224%22%20width%3D%2218%22%20height%3D%2216%22%20rx%3D%222%22%2F%3E%3Cpath%20d%3D%22M9%204v16M5.5%208h1M5.5%2012h1%22%2F%3E%3C%2Fsvg%3E", "catalogue": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%237b8795%22%20stroke-width%3D%221.7%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Crect%20x%3D%223%22%20y%3D%223%22%20width%3D%227%22%20height%3D%227%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%2214%22%20y%3D%223%22%20width%3D%227%22%20height%3D%227%22%20rx%3D%221%22%2F%3E%3Crect%20x%3D%223%22%20y%3D%2214%22%20width%3D%227%22%20height%3D%227%22%20rx%3D%221%22%2F%3E%3Cpath%20d%3D%22M14%2017.5h7M17.5%2014v7%22%2F%3E%3C%2Fsvg%3E", "properties": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%237b8795%22%20stroke-width%3D%221.7%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M4%206h16M4%2012h16M4%2018h16%22%2F%3E%3Ccircle%20cx%3D%228%22%20cy%3D%226%22%20r%3D%222%22%2F%3E%3Ccircle%20cx%3D%2216%22%20cy%3D%2212%22%20r%3D%222%22%2F%3E%3Ccircle%20cx%3D%2210%22%20cy%3D%2218%22%20r%3D%222%22%2F%3E%3C%2Fsvg%3E", "new": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%237b8795%22%20stroke-width%3D%221.7%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M14%202H6a2%202%200%200%200-2%202v16a2%202%200%200%200%202%202h12a2%202%200%200%200%202-2V8Z%20M14%202v6h6%20M8%2015h8%20M12%2011v8%22%2F%3E%3C%2Fsvg%3E", "download": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%237b8795%22%20stroke-width%3D%221.7%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M12%203v12m-5-5%205%205%205-5%20M4%2016v4a1%201%200%200%200%201%201h14a1%201%200%200%200%201-1v-4%22%2F%3E%3C%2Fsvg%3E", "copy": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%237b8795%22%20stroke-width%3D%221.7%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Crect%20x%3D%228%22%20y%3D%228%22%20width%3D%2212%22%20height%3D%2213%22%20rx%3D%222%22%2F%3E%3Cpath%20d%3D%22M16%208V5a2%202%200%200%200-2-2H5a2%202%200%200%200-2%202v9a2%202%200%200%200%202%202h3%22%2F%3E%3C%2Fsvg%3E"};
2
+
3
+ toolIcons.open = "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%237b8795%22%20stroke-width%3D%221.7%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M3%207V5a2%202%200%200%201%202-2h5l2%202h7a2%202%200%200%201%202%202v2M3%209h18l-2%2011H4z%22%2F%3E%3C%2Fsvg%3E";
4
+
5
+ toolIcons.cut = 'data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%237b8795%22%20stroke-width%3D%221.7%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Ccircle%20cx%3D%226%22%20cy%3D%226%22%20r%3D%223%22%2F%3E%3Ccircle%20cx%3D%226%22%20cy%3D%2218%22%20r%3D%223%22%2F%3E%3Cpath%20d%3D%22m8%208%2012%2012M8%2016%2020%204%22%2F%3E%3C%2Fsvg%3E';
6
+
7
+ toolIcons.paste = 'data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%237b8795%22%20stroke-width%3D%221.7%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Crect%20x%3D%225%22%20y%3D%225%22%20width%3D%2214%22%20height%3D%2216%22%20rx%3D%222%22%2F%3E%3Crect%20x%3D%229%22%20y%3D%222%22%20width%3D%226%22%20height%3D%225%22%20rx%3D%221%22%2F%3E%3Cpath%20d%3D%22M9%2012h6m-6%204h6%22%2F%3E%3C%2Fsvg%3E';
8
+
9
+
10
+ toolIcons.appearance = 'data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Ccircle%20cx%3D%2212%22%20cy%3D%2212%22%20r%3D%228%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%221.7%22%2F%3E%3Cpath%20d%3D%22M12%204a8%208%200%200%201%200%2016z%22%20fill%3D%22black%22%2F%3E%3C%2Fsvg%3E';
@@ -0,0 +1,56 @@
1
+ import type {SourceBagNode} from '@genrojs/builders';
2
+ export function visualEditorScope(node:SourceBagNode):SourceBagNode;
3
+ export class VisualEditorLogic {
4
+ chatRender(node:SourceBagNode, ...args:unknown[]):unknown;
5
+ chatCompleted(node:SourceBagNode, ...args:unknown[]):unknown;
6
+ chatReset(node:SourceBagNode, ...args:unknown[]):unknown;
7
+ chatResize(node:SourceBagNode, ...args:unknown[]):unknown;
8
+ chatPickAttachments(node:SourceBagNode, ...args:unknown[]):unknown;
9
+ chatRenderAttachments(node:SourceBagNode, ...args:unknown[]):unknown;
10
+ chatRemoveAttachment(node:SourceBagNode, ...args:unknown[]):unknown;
11
+ chatSend(node:SourceBagNode, ...args:unknown[]):unknown;
12
+ assistantState(node:SourceBagNode, ...args:unknown[]):unknown;
13
+ assistantApply(node:SourceBagNode, ...args:unknown[]):unknown;
14
+ applySourceEdit(node:SourceBagNode, ...args:unknown[]):unknown;
15
+ initializeCanvasSelection(node:SourceBagNode, ...args:unknown[]):unknown;
16
+ highlightSelection(node:SourceBagNode, ...args:unknown[]):unknown;
17
+ clipboardShortcut(node:SourceBagNode, ...args:unknown[]):unknown;
18
+ clipboardModifiers(node:SourceBagNode, ...args:unknown[]):unknown;
19
+ cutBranch(node:SourceBagNode, ...args:unknown[]):unknown;
20
+ copyBranch(node:SourceBagNode, ...args:unknown[]):unknown;
21
+ dropClipboard(node:SourceBagNode, ...args:unknown[]):unknown;
22
+ prepareClipboard(node:SourceBagNode, ...args:unknown[]):unknown;
23
+ branchSnapshot(node:SourceBagNode, ...args:unknown[]):unknown;
24
+ beginClipboard(node:SourceBagNode, ...args:unknown[]):unknown;
25
+ saveClipboard(node:SourceBagNode, ...args:unknown[]):unknown;
26
+ pasteBranch(node:SourceBagNode, ...args:unknown[]):unknown;
27
+ beginPaste(node:SourceBagNode, ...args:unknown[]):unknown;
28
+ finishPaste(node:SourceBagNode, ...args:unknown[]):unknown;
29
+ openCode(node:SourceBagNode, ...args:unknown[]):unknown;
30
+ codeSave(node:SourceBagNode, ...args:unknown[]):unknown;
31
+ codePreview(node:SourceBagNode, ...args:unknown[]):unknown;
32
+ newPage(node:SourceBagNode, ...args:unknown[]):unknown;
33
+ copySource(node:SourceBagNode, ...args:unknown[]):unknown;
34
+ downloadPage(node:SourceBagNode, ...args:unknown[]):unknown;
35
+ openUpload(node:SourceBagNode, ...args:unknown[]):unknown;
36
+ sourceUploaded(node:SourceBagNode, ...args:unknown[]):unknown;
37
+ toggleNavigation(node:SourceBagNode, ...args:unknown[]):unknown;
38
+ openCatalogue(node:SourceBagNode, ...args:unknown[]):unknown;
39
+ openProperties(node:SourceBagNode, ...args:unknown[]):unknown;
40
+ sourceLabel(node:SourceBagNode, ...args:unknown[]):unknown;
41
+ dropNode(node:SourceBagNode, ...args:unknown[]):unknown;
42
+ insertWidget(node:SourceBagNode, ...args:unknown[]):unknown;
43
+ initializeEditor(node:SourceBagNode, ...args:unknown[]):unknown;
44
+ prepareWidget(node:SourceBagNode, ...args:unknown[]):unknown;
45
+ prepareSource(node:SourceBagNode, ...args:unknown[]):unknown;
46
+ applyDrop(node:SourceBagNode, ...args:unknown[]):unknown;
47
+ showProperties(node:SourceBagNode, ...args:unknown[]):unknown;
48
+ toggleLabelboxAttributes(node:SourceBagNode, ...args:unknown[]):unknown;
49
+ labelboxFields(node:SourceBagNode, ...args:unknown[]):unknown;
50
+ renderLabelboxAttribute(node:SourceBagNode, ...args:unknown[]):unknown;
51
+ parameterField(node:SourceBagNode, ...args:unknown[]):unknown;
52
+ renderParameterInput(node:SourceBagNode, ...args:unknown[]):unknown;
53
+ changePropertyType(node:SourceBagNode, ...args:unknown[]):unknown;
54
+ changeProperty(node:SourceBagNode, ...args:unknown[]):unknown;
55
+ applyInsert(node:SourceBagNode, ...args:unknown[]):unknown;
56
+ }