@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.
- package/assets/icons/chart.svg +1 -0
- package/dist/components/audio/__init__.py +13 -0
- package/dist/components/audio/assets/collection.js +3 -0
- package/dist/components/audio/assets/index.js +3 -0
- package/dist/components/audio/commands.json +7 -0
- package/dist/components/audio/grammar.json +335 -0
- package/dist/components/charts/__init__.py +13 -0
- package/dist/components/charts/assets/collection.js +47 -0
- package/dist/components/charts/assets/files/55ea01207028f76d844678511f29fc800f8a1e67a8a0fe80470128677847ad32-echarts-gl.txt +29 -0
- package/dist/components/charts/assets/files/63727832aaf62004a2b249c933e327f3c90caf49e41a72f4bf436edf632cbda8-vega.txt +27 -0
- package/dist/components/charts/assets/files/8c45d9eaf50c2f72dd9c7ab9ef440788ba58a3538484b5c51c1f17d5128752e7-plotly.txt +21 -0
- package/dist/components/charts/assets/files/8f989229699b4fe2f1a0432d0e9edc338a8a911e250e2d1b01ecd770a5f5b1bd-uplot.txt +21 -0
- package/dist/components/charts/assets/files/c8fa058cba98f7f288b5d8fa4116f441d6dacb25b96da859e518c973fff41d0c-claygl.txt +23 -0
- package/dist/components/charts/assets/index.js +3 -0
- package/dist/components/charts/assets/modules/chunk-2CCTLZE7.js +76 -0
- package/dist/components/charts/assets/modules/chunk-RMRBEYTI.js +1 -0
- package/dist/components/charts/assets/modules/echarts-gl-CXVTZA6G.js +4409 -0
- package/dist/components/charts/assets/modules/plotly.min-4LB7HE7P.js +3596 -0
- package/dist/components/charts/assets/modules/uPlot.esm-5JJNHHRF.js +3 -0
- package/dist/components/charts/assets/modules/uPlot.min-N3E3FA74.js +1 -0
- package/dist/components/charts/assets/modules/vega.module-2QCOVQ3A.js +13 -0
- package/dist/components/charts/commands.json +7 -0
- package/dist/components/charts/grammar.json +1113 -0
- package/dist/components/chat/__init__.py +1 -1
- package/dist/components/chat/assets/collection.js +3 -3
- package/dist/components/chat/assets/index.js +1 -1
- package/dist/components/drawing/__init__.py +15 -0
- package/dist/components/drawing/assets/collection.js +28 -0
- package/dist/components/drawing/assets/index.js +3 -0
- package/dist/components/drawing/commands.json +7 -0
- package/dist/components/drawing/grammar.json +110 -0
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +18 -18
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/modules/{prose-mirror-engine-GMZPJPNN.js → prose-mirror-engine-DQEAEIMV.js} +2 -2
- package/dist/components/editors/grammar.json +150 -0
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/collection.js +63 -33
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +279 -0
- package/dist/components/grouplets/__init__.py +1 -1
- package/dist/components/grouplets/assets/collection.js +3 -3
- package/dist/components/grouplets/assets/index.js +1 -1
- package/dist/components/inputs/__init__.py +3 -2
- package/dist/components/inputs/assets/collection.js +38 -23
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +1533 -321
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +27 -23
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +85 -0
- package/dist/components/selection_trial/__init__.py +1 -1
- package/dist/components/selection_trial/assets/collection.js +3 -3
- package/dist/components/selection_trial/assets/index.js +1 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +12 -12
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +126 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +3 -3
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/collection.js +9 -9
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/vizabi/__init__.py +13 -0
- package/dist/components/vizabi/assets/collection.js +22 -0
- package/dist/components/vizabi/assets/index.js +3 -0
- package/dist/components/vizabi/commands.json +7 -0
- package/dist/components/vizabi/grammar.json +128 -0
- package/dist/gramlot.js +1190 -256
- package/dist/gramlot.min.js +85 -52
- package/dist/standard-collections.js +2 -0
- package/package.json +12 -4
- package/src/binding/grid-struct.js +2 -2
- package/src/binding/runtime.js +10 -0
- package/src/binding/validation-context.js +2 -1
- package/src/bootstrap.js +1 -1
- package/src/builder/gramlot-builder.d.ts +15 -2
- package/src/builder/gramlot-builder.js +22 -3
- package/src/builder/source.js +24 -1
- package/src/components/audio-analysis-session.js +65 -0
- package/src/components/audio.js +44 -0
- package/src/components/bases.js +11 -7
- package/src/components/border-container.js +6 -3
- package/src/components/buttons.js +47 -3
- package/src/components/chart-bar3d-options.js +30 -0
- package/src/components/chart-controls.js +83 -0
- package/src/components/chart-data-view.js +52 -0
- package/src/components/chart-data.js +42 -0
- package/src/components/chart-domains.js +46 -0
- package/src/components/chart-engines/echarts-options.js +50 -0
- package/src/components/chart-engines/echarts.js +82 -0
- package/src/components/chart-engines/index.js +22 -0
- package/src/components/chart-engines/plotly-map.js +34 -0
- package/src/components/chart-engines/plotly-spatial.js +35 -0
- package/src/components/chart-engines/plotly.js +138 -0
- package/src/components/chart-engines/uplot.js +57 -0
- package/src/components/chart-engines/vega.js +101 -0
- package/src/components/chart-fields.js +110 -0
- package/src/components/chart-geographic-options.js +47 -0
- package/src/components/chart-geojson.js +60 -0
- package/src/components/chart-geometry.js +11 -0
- package/src/components/chart-map-anchors.js +24 -0
- package/src/components/chart-map-bar3d-options.js +41 -0
- package/src/components/chart-map-data.js +25 -0
- package/src/components/chart-map-labels.js +8 -0
- package/src/components/chart-map-options.js +20 -0
- package/src/components/chart-pane.js +91 -0
- package/src/components/chart-renderer.js +58 -0
- package/src/components/chart-sample-view.js +32 -0
- package/src/components/chart-spatial-options.js +40 -0
- package/src/components/chart-time.js +84 -0
- package/src/components/chart-timeline.js +70 -0
- package/src/components/chart-types/area.js +2 -0
- package/src/components/chart-types/bar.js +2 -0
- package/src/components/chart-types/bar3D.js +2 -0
- package/src/components/chart-types/donut.js +2 -0
- package/src/components/chart-types/horizontalBar.js +2 -0
- package/src/components/chart-types/index.js +26 -0
- package/src/components/chart-types/line.js +2 -0
- package/src/components/chart-types/line3D.js +2 -0
- package/src/components/chart-types/lines3D.js +2 -0
- package/src/components/chart-types/map.js +2 -0
- package/src/components/chart-types/map3D.js +2 -0
- package/src/components/chart-types/mapBar3D.js +2 -0
- package/src/components/chart-types/pie.js +2 -0
- package/src/components/chart-types/polygons3D.js +2 -0
- package/src/components/chart-types/scatter.js +2 -0
- package/src/components/chart-types/scatter3D.js +2 -0
- package/src/components/chart-types/stackedArea.js +2 -0
- package/src/components/chart-types/stackedBar.js +2 -0
- package/src/components/chart-types/surface.js +2 -0
- package/src/components/charts.js +152 -0
- package/src/components/check-box-text-editor.js +88 -0
- package/src/components/check-box-text.js +193 -0
- package/src/components/check-box-tree.js +62 -0
- package/src/components/choice-editor.js +35 -18
- package/src/components/choice-field-styles.js +14 -0
- package/src/components/choices.js +5 -0
- package/src/components/database-choices.js +9 -6
- package/src/components/drawing.js +199 -0
- package/src/components/field-state.js +8 -1
- package/src/components/grid-cell-editor.js +83 -19
- package/src/components/grid-check-sets.js +98 -0
- package/src/components/grid-column-filters.js +198 -0
- package/src/components/grid-grammar.json +65 -0
- package/src/components/grid-header-interaction.js +3 -1
- package/src/components/grid-rows.js +2 -2
- package/src/components/grid-search-box.js +38 -22
- package/src/components/grid-search-styles.js +13 -14
- package/src/components/grid-search.js +8 -1
- package/src/components/grid-structure.js +13 -2
- package/src/components/grid-styles.js +34 -2
- package/src/components/grid.js +67 -10
- package/src/components/image-uploader.js +2 -2
- package/src/components/inputs.js +21 -12
- package/src/components/labelbox.js +5 -1
- package/src/components/licenses/claygl.txt +23 -0
- package/src/components/licenses/echarts-gl.txt +29 -0
- package/src/components/licenses/plotly.txt +21 -0
- package/src/components/licenses/uplot.txt +21 -0
- package/src/components/licenses/vega.txt +27 -0
- package/src/components/menus.js +19 -11
- package/src/components/parameters.js +6 -2
- package/src/components/toolbar-overflow.js +12 -8
- package/src/components/tree.js +31 -8
- package/src/components/typed-editor.js +18 -7
- package/src/components/validation.js +1 -1
- package/src/components/vizabi-session.js +66 -0
- package/src/components/vizabi.js +66 -0
- package/src/components/window-surface.js +20 -9
- package/src/components/windows.js +1 -1
- package/src/editing-session.d.ts +1 -0
- package/src/editing-session.js +113 -15
- package/src/editor-values.js +57 -0
- package/src/gramlot.d.ts +2 -0
- package/src/gramlot.js +9 -4
- package/src/handlers/device-handler.js +32 -32
- package/src/handlers/source-handler.d.ts +2 -2
- package/src/ide-documents.js +19 -3
- package/src/ide-runtime.d.ts +1 -0
- package/src/ide-runtime.js +45 -31
- package/src/index.d.ts +2 -1
- package/src/renderer/drag-drop.js +1 -0
- package/src/renderer/gramlot-renderer.d.ts +3 -0
- package/src/renderer/gramlot-renderer.js +16 -4
- package/src/server/assets.d.ts +3 -0
- package/src/server/assets.js +9 -0
- package/src/server/gramlot-server.d.ts +1 -1
- package/src/server/gramlot-server.js +2 -1
- package/src/server/index.d.ts +1 -1
- package/src/server/index.js +1 -1
- package/src/server/source-import.d.ts +1 -1
- package/src/server/source-import.js +5 -1
- package/src/server/visual-editor.d.ts +1 -1
- package/src/server/visual-editor.js +44 -34
- package/src/source-picker.d.ts +1 -1
- package/src/source-picker.js +1 -2
- package/src/stores/bag-collection-view.js +79 -17
- package/src/stores/collection-filter.js +2 -1
- package/src/stores/column-filter.js +49 -0
- package/src/stores/id-set.js +10 -0
- package/src/view/controls.js +8 -0
- package/src/view/html.js +10 -1
- package/src/view/label-menu.js +61 -0
- package/src/view/labelbox.js +15 -2
- package/src/visual-editor-canvas.js +29 -0
- package/src/visual-editor-catalogue.js +34 -0
- package/src/visual-editor.d.ts +5 -0
- package/src/visual-editor.js +244 -26
- package/themes/gramlot-base/theme.css +84 -36
- package/tools/gramlot-tools-inspector.js +170 -506
- package/tools/inspector-agent.js +1 -1
package/src/editing-session.js
CHANGED
|
@@ -28,6 +28,11 @@ export class EditingSession {
|
|
|
28
28
|
this.retainedFields = new Map();
|
|
29
29
|
this.listeners = new Set();
|
|
30
30
|
this.navigators = new Set();
|
|
31
|
+
this.validationSources = new Set();
|
|
32
|
+
this.validationDependencies = new Map();
|
|
33
|
+
this.validationRevision = 0;
|
|
34
|
+
this.validatedRevision = -1;
|
|
35
|
+
this.fullValidation = null;
|
|
31
36
|
if (!(this.data instanceof Bag)) throw new TypeError('A form requires a Bag at its datapath.');
|
|
32
37
|
this.registers.setItem('baseline', copy(this.data));
|
|
33
38
|
for (const name of ['changes', 'errors', 'pending', 'drafts']) this.registers.setItem(name, new Bag());
|
|
@@ -113,7 +118,7 @@ export class EditingSession {
|
|
|
113
118
|
}
|
|
114
119
|
get status() {
|
|
115
120
|
const dirty = this.registers.getItem('changes').length > 0;
|
|
116
|
-
const pending = this.registers.getItem('pending').length > 0;
|
|
121
|
+
const pending = this.fullValidation !== null || this.registers.getItem('pending').length > 0;
|
|
117
122
|
const invalid = this.registers.getItem('errors').length > 0;
|
|
118
123
|
const incomplete = this.registers.getItem('drafts').length > 0;
|
|
119
124
|
return {dirty, pending, valid:!invalid && !incomplete, canSave:dirty && !invalid && !incomplete && !pending,
|
|
@@ -122,15 +127,8 @@ export class EditingSession {
|
|
|
122
127
|
register(adapter) {
|
|
123
128
|
const node = adapter.node;
|
|
124
129
|
this.fields.set(node, adapter);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
field = {node, binding:adapter.binding, context:validationContext(adapter.binding), run:new ValidationRun(),
|
|
128
|
-
execute:adapter.element.validationExecutor, checkValue:adapter.element.validationValueCheck(), path:fieldPath(node), rules:null, value:undefined, target:null, result:null, selection:adapter.element.validationSelection()};
|
|
129
|
-
this.validations.set(node,field);
|
|
130
|
-
adapter.binding.editingSession = this;
|
|
131
|
-
field.release = adapter.binding.track(() => this.forgetField(node));
|
|
132
|
-
this.refreshField(node);
|
|
133
|
-
}
|
|
130
|
+
const field = this.registerField(node,adapter.element.constructor);
|
|
131
|
+
field.selection = adapter.element.validationSelection();
|
|
134
132
|
this.schedule(() => {
|
|
135
133
|
if (this.fields.get(node) !== adapter) return;
|
|
136
134
|
const draft = this.registers.getItem('drafts').getNode(key(node));
|
|
@@ -142,6 +140,96 @@ export class EditingSession {
|
|
|
142
140
|
});
|
|
143
141
|
return () => { this.fields.delete(node); };
|
|
144
142
|
}
|
|
143
|
+
/** A real Source declaration can validate without an element or ControlAdapter. */
|
|
144
|
+
registerField(node, component, schedule = true) {
|
|
145
|
+
let field = this.validations.get(node);
|
|
146
|
+
if (field) return field;
|
|
147
|
+
if (!component.validationExecutor) throw new TypeError('Grid editors require shared input validation.');
|
|
148
|
+
const binding = this.runtime.bindingFor(node), context = validationContext(binding);
|
|
149
|
+
field = {node,binding,context,component,run:new ValidationRun(),
|
|
150
|
+
execute:component.validationExecutor,checkValue:component.validationValueCheck(context),
|
|
151
|
+
path:fieldPath(node),rules:null,value:undefined,target:null,result:null,selection:null};
|
|
152
|
+
this.validations.set(node,field);
|
|
153
|
+
binding.editingSession = this;
|
|
154
|
+
field.release = binding.track(() => this.forgetField(node));
|
|
155
|
+
this.refreshField(node,schedule);
|
|
156
|
+
return field;
|
|
157
|
+
}
|
|
158
|
+
registerValidationSource(fields) {
|
|
159
|
+
this.validationSources.add(fields);
|
|
160
|
+
this.invalidateValidation();
|
|
161
|
+
return () => { this.validationSources.delete(fields); this.invalidateValidation(); };
|
|
162
|
+
}
|
|
163
|
+
invalidateValidation() {
|
|
164
|
+
this.validationRevision++;
|
|
165
|
+
if (this.fullValidation) for (const node of this.fullValidation.active) this.cancelValidation(node);
|
|
166
|
+
}
|
|
167
|
+
trackValidationDependency(absolute) {
|
|
168
|
+
if (absolute === null || this.validationDependencies.has(absolute)) return;
|
|
169
|
+
const [path,attr = null] = absolute.split('?',2);
|
|
170
|
+
this.validationDependencies.set(absolute,this.runtime.router.register({path,attr,subtree:true,
|
|
171
|
+
recipient:{receive:() => this.invalidateValidation()}}));
|
|
172
|
+
}
|
|
173
|
+
clearValidationDependencies() {
|
|
174
|
+
for (const registration of this.validationDependencies.values()) registration.close();
|
|
175
|
+
this.validationDependencies.clear();
|
|
176
|
+
}
|
|
177
|
+
/** Validate the complete declared scope. Bounded work keeps remote checks and UI responsive. */
|
|
178
|
+
validate() {
|
|
179
|
+
if (this.disposed) return Promise.resolve(false);
|
|
180
|
+
if (this.fullValidation) return this.fullValidation.promise;
|
|
181
|
+
for (const adapter of this.fields.values()) if (Object.hasOwn(adapter.node,'formDraft')) adapter.commit();
|
|
182
|
+
this.clearValidationDependencies();
|
|
183
|
+
const pass = {revision:this.validationRevision,promise:null,active:new Set(),failed:false,complete:true};
|
|
184
|
+
this.fullValidation = pass;
|
|
185
|
+
this.notify();
|
|
186
|
+
const fields = this.validationFields();
|
|
187
|
+
const current = () => !this.disposed && !pass.failed && pass.revision === this.validationRevision;
|
|
188
|
+
const seen = new WeakSet();
|
|
189
|
+
const worker = async () => {
|
|
190
|
+
let count = 0;
|
|
191
|
+
while (current()) {
|
|
192
|
+
const next = fields.next();
|
|
193
|
+
if (next.done) return;
|
|
194
|
+
const {node,release} = next.value;
|
|
195
|
+
try {
|
|
196
|
+
if (seen.has(node)) continue;
|
|
197
|
+
seen.add(node);
|
|
198
|
+
for (const [name,pointer] of node.pointers()) if (name !== 'value') {
|
|
199
|
+
this.trackValidationDependency((name === 'datapath' ? node.parentNode : node).absDatapath(pointer));
|
|
200
|
+
}
|
|
201
|
+
pass.active.add(node);
|
|
202
|
+
const outcome = await this.validateField(node);
|
|
203
|
+
if (!outcome?.ok) pass.complete = false;
|
|
204
|
+
} finally { pass.active.delete(node); release(); }
|
|
205
|
+
if (++count % 20 === 0) await new Promise(resolve => setTimeout(resolve,0));
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
pass.promise = Promise.resolve().then(async () => {
|
|
209
|
+
const outcomes = await Promise.allSettled(Array.from({length:8},() => worker().catch(error => {
|
|
210
|
+
pass.failed = true;
|
|
211
|
+
for (const node of pass.active) this.cancelValidation(node);
|
|
212
|
+
throw error;
|
|
213
|
+
})));
|
|
214
|
+
const failure = outcomes.find(outcome => outcome.status === 'rejected');
|
|
215
|
+
if (failure) throw failure.reason;
|
|
216
|
+
if (!current()) return false;
|
|
217
|
+
// fullValidation itself is pending until finally; inspect field registers here.
|
|
218
|
+
const valid = pass.complete && this.status.valid && this.registers.getItem('pending').length === 0;
|
|
219
|
+
if (valid) this.validatedRevision = this.validationRevision;
|
|
220
|
+
return valid;
|
|
221
|
+
}).finally(() => {
|
|
222
|
+
fields.return();
|
|
223
|
+
this.fullValidation = null;
|
|
224
|
+
this.notify();
|
|
225
|
+
});
|
|
226
|
+
return pass.promise;
|
|
227
|
+
}
|
|
228
|
+
*validationFields() {
|
|
229
|
+
const existing = [...this.validations.keys()];
|
|
230
|
+
for (const fields of this.validationSources) yield* fields();
|
|
231
|
+
for (const node of existing) if (this.validations.has(node)) yield {node,release:() => {}};
|
|
232
|
+
}
|
|
145
233
|
forgetField(node) {
|
|
146
234
|
const field = this.validations.get(node);
|
|
147
235
|
if (!field) return;
|
|
@@ -162,16 +250,18 @@ export class EditingSession {
|
|
|
162
250
|
delete node.formDraft;
|
|
163
251
|
this.notify();
|
|
164
252
|
}
|
|
165
|
-
refreshField(node) {
|
|
253
|
+
refreshField(node, schedule = true) {
|
|
166
254
|
const field = this.validations.get(node);
|
|
167
255
|
if (!field || this.disposed || this.writing) return;
|
|
168
256
|
const [, attrs] = node.rootBuilder.runtimeValues(node);
|
|
169
|
-
const resolved = this.runtime.renderer.evaluateExpressions(node,attrs);
|
|
257
|
+
const resolved = field.component.validationParameters(this.runtime.renderer.evaluateExpressions(node,attrs));
|
|
170
258
|
const rules = Object.fromEntries(Object.entries(resolved).filter(([name]) => name.startsWith('validate_')));
|
|
259
|
+
const configuration = toTytx(Object.fromEntries(Object.entries(resolved).filter(([name]) => name !== 'value')));
|
|
171
260
|
const path = fieldPath(node), target = this.runtime.gramlot.data.getNode(path.split('?')[0]);
|
|
172
261
|
const value = node.getRelativeData(node.getAttr('value'));
|
|
173
262
|
const dataChanged = field.path !== path || field.target !== target || !same(field.value,value);
|
|
174
|
-
if (!dataChanged &&
|
|
263
|
+
if (!dataChanged && field.configuration === configuration) return;
|
|
264
|
+
if (field.rules !== null) this.invalidateValidation();
|
|
175
265
|
this.cancelValidation(node);
|
|
176
266
|
if (field.path !== path) {
|
|
177
267
|
for (const name of ['errors','pending','drafts']) {
|
|
@@ -179,9 +269,10 @@ export class EditingSession {
|
|
|
179
269
|
if (bag.getNode(encoded(field.path))) bag.popNode(encoded(field.path));
|
|
180
270
|
}
|
|
181
271
|
}
|
|
182
|
-
Object.assign(field,{path,target,value,rules,result:null
|
|
272
|
+
Object.assign(field,{path,target,value,rules,configuration,result:null,
|
|
273
|
+
selection:field.component.validationSelection(resolved,field.context)});
|
|
183
274
|
if (dataChanged) this.clearDraft(node);
|
|
184
|
-
this.scheduleField(node);
|
|
275
|
+
if (schedule) this.scheduleField(node);
|
|
185
276
|
}
|
|
186
277
|
cancelValidation(node) {
|
|
187
278
|
this.validations.get(node)?.run.cancel();
|
|
@@ -201,6 +292,7 @@ export class EditingSession {
|
|
|
201
292
|
for (const other of this.validations.keys()) if (other !== node) this.refreshField(other);
|
|
202
293
|
}
|
|
203
294
|
validateCandidate(node,value,selection) {
|
|
295
|
+
this.invalidateValidation();
|
|
204
296
|
this.cancelValidation(node);
|
|
205
297
|
this.writeCandidate(node,value);
|
|
206
298
|
const field = this.validations.get(node);
|
|
@@ -261,6 +353,7 @@ export class EditingSession {
|
|
|
261
353
|
this.notify();
|
|
262
354
|
}
|
|
263
355
|
draft(node, text) {
|
|
356
|
+
this.invalidateValidation();
|
|
264
357
|
this.cancelValidation(node);
|
|
265
358
|
node.formDraft = text;
|
|
266
359
|
this.set('drafts',node,text);
|
|
@@ -296,6 +389,7 @@ export class EditingSession {
|
|
|
296
389
|
if (this.disposed) return;
|
|
297
390
|
this.updateChanges(change.path);
|
|
298
391
|
if (this.writing) return;
|
|
392
|
+
this.invalidateValidation();
|
|
299
393
|
for (const node of this.validations.keys()) this.refreshField(node);
|
|
300
394
|
}
|
|
301
395
|
|
|
@@ -358,6 +452,7 @@ export class EditingSession {
|
|
|
358
452
|
if (Object.hasOwn(adapter.node,'formDraft')) adapter.commit();
|
|
359
453
|
}
|
|
360
454
|
if (!this.status.valid || this.status.pending) return false;
|
|
455
|
+
if (this.validationSources.size && this.validatedRevision !== this.validationRevision) return false;
|
|
361
456
|
this.registers.setItem('baseline',copy(this.data));
|
|
362
457
|
this.updateChanges();
|
|
363
458
|
return true;
|
|
@@ -370,6 +465,7 @@ export class EditingSession {
|
|
|
370
465
|
}
|
|
371
466
|
restore() {
|
|
372
467
|
if (this.disposed) return;
|
|
468
|
+
this.invalidateValidation();
|
|
373
469
|
for (const node of this.validations.keys()) this.cancelValidation(node);
|
|
374
470
|
for (const adapter of this.fields.values()) {
|
|
375
471
|
adapter.element.cancelValidation();
|
|
@@ -392,5 +488,7 @@ export class EditingSession {
|
|
|
392
488
|
this.retainedFields.clear();
|
|
393
489
|
this.listeners.clear();
|
|
394
490
|
this.navigators.clear();
|
|
491
|
+
this.validationSources.clear();
|
|
492
|
+
this.clearValidationDependencies();
|
|
395
493
|
}
|
|
396
494
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Scalar editor contract. Containers and unsupported objects remain inspectable. */
|
|
2
|
+
export const editorTypes = ['string', 'number', 'integer', 'boolean', 'date', 'time', 'datetime', 'null'];
|
|
3
|
+
|
|
4
|
+
export function scalarType(value) {
|
|
5
|
+
if (value === null) return 'null';
|
|
6
|
+
if (['string', 'boolean'].includes(typeof value)) return typeof value;
|
|
7
|
+
if (typeof value === 'number' && Number.isFinite(value)) return Number.isSafeInteger(value) ? 'integer' : 'number';
|
|
8
|
+
if (value instanceof Date && Number.isFinite(value.getTime())) {
|
|
9
|
+
const iso = value.toISOString();
|
|
10
|
+
return iso.slice(0, 10) === '1970-01-01' ? 'time' : iso.endsWith('T00:00:00.000Z') ? 'date' : 'datetime';
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function scalarText(value, type) {
|
|
16
|
+
if (type === 'null') return '';
|
|
17
|
+
if (value instanceof Date) {
|
|
18
|
+
const iso = value.toISOString();
|
|
19
|
+
return type === 'date' ? iso.slice(0, 10) : type === 'time' ? iso.slice(11, 23) : iso;
|
|
20
|
+
}
|
|
21
|
+
return String(value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function parseScalar(type, text) {
|
|
25
|
+
if (type === 'string') return text;
|
|
26
|
+
if (type === 'null') return null;
|
|
27
|
+
if (type === 'boolean' && ['true', 'false'].includes(text)) return text === 'true';
|
|
28
|
+
if (type === 'number' || type === 'integer') {
|
|
29
|
+
if (/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(text.trim())) {
|
|
30
|
+
const value = Number(text);
|
|
31
|
+
if (Number.isFinite(value) && (type !== 'integer' || Number.isSafeInteger(value))) return value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (['date', 'time', 'datetime'].includes(type)) {
|
|
35
|
+
const pattern = type === 'date' ? /^\d{4}-\d{2}-\d{2}$/
|
|
36
|
+
: type === 'time' ? /^\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?$/
|
|
37
|
+
: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?Z$/;
|
|
38
|
+
if (pattern.test(text)) {
|
|
39
|
+
const input = type === 'date' ? `${text}T00:00:00Z` : type === 'time' ? `1970-01-01T${text}Z` : text;
|
|
40
|
+
const date = new Date(input);
|
|
41
|
+
if (Number.isFinite(date.getTime())) {
|
|
42
|
+
// Reject Date's normalization of invalid calendar dates and 24:00.
|
|
43
|
+
const iso = date.toISOString();
|
|
44
|
+
const supplied = input.replace(/Z$/, '').split(/[T:.]/);
|
|
45
|
+
const actual = iso.replace(/Z$/, '').split(/[T:.]/);
|
|
46
|
+
if (supplied.every((part, index) => index === 4 ? Number(part.padEnd(3, '0')) === Number(actual[index]) : part === actual[index])) return date;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
throw new Error(`Invalid ${type} value: ${text || '(empty)'}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Read the portable component contract from a real Source node. */
|
|
54
|
+
export function readParameterEnums(node) {
|
|
55
|
+
return Object.fromEntries(Object.entries(node._getMeta('gramlot_component')?.parameters ?? {})
|
|
56
|
+
.filter(([, spec]) => spec.enum).map(([name, spec]) => [name, spec.enum]));
|
|
57
|
+
}
|
package/src/gramlot.d.ts
CHANGED
|
@@ -117,6 +117,8 @@ export class Gramlot {
|
|
|
117
117
|
publish(topic: {topic: string; server: true; pageId?: string}, payload?: Record<string, unknown>): Promise<'ok'>;
|
|
118
118
|
publish(topic: Publication, payload?: Record<string, unknown>): void | Promise<'ok'>;
|
|
119
119
|
/** Subscribe to a local page topic, synchronously in registration order. */
|
|
120
|
+
registerDocument(document:Document):void;
|
|
121
|
+
getCollection(name:string): {readonly name:string; toDocument():unknown; register(window:Window):void} | undefined;
|
|
120
122
|
subscribe(topic: string, callback: (payload: Record<string, unknown>, metadata: {pageId?: string}) => unknown): SubscriptionHandle;
|
|
121
123
|
/** Remove a registration; repeating removal of an owned handle is harmless. */
|
|
122
124
|
unsubscribe(registration: SubscriptionHandle): void;
|
package/src/gramlot.js
CHANGED
|
@@ -28,14 +28,13 @@ import {formatValue} from './format.js';
|
|
|
28
28
|
*/
|
|
29
29
|
export class Gramlot {
|
|
30
30
|
#mobileEnvironment;
|
|
31
|
+
#collections;
|
|
31
32
|
constructor({pageId, uploadUrl = null, rpcUrl = '/gramlot/rpc', closeUrl = '/gramlot/close', rootId = 'gramlot-root', capabilities = [],
|
|
32
33
|
element = null, document = element?.ownerDocument ?? globalThis.document, transport = null, collections = [],
|
|
33
34
|
locale = null, timeZone = null, devices = [], serverAdapter = new ServerAdapter(), nameSyntax = null,
|
|
34
35
|
websocketUrl = null} = {}) {
|
|
35
|
-
buttons.
|
|
36
|
-
|
|
37
|
-
if (collection instanceof ComponentCollection) collection.register(document.defaultView);
|
|
38
|
-
}
|
|
36
|
+
this.#collections = [buttons, ...collections.filter(collection => collection instanceof ComponentCollection)];
|
|
37
|
+
this.registerDocument(document);
|
|
39
38
|
this.commands = new CommandRegistry();
|
|
40
39
|
this.pageId = pageId;
|
|
41
40
|
this.uploadUrl = uploadUrl;
|
|
@@ -68,6 +67,12 @@ export class Gramlot {
|
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
publish(topic, payload = {}) { return this._subscriptions.publish(topic, payload); }
|
|
70
|
+
/** Register this page's activated collections in an additional rendering realm. */
|
|
71
|
+
registerDocument(document) {
|
|
72
|
+
for (const collection of this.#collections) collection.register(document.defaultView);
|
|
73
|
+
}
|
|
74
|
+
/** The prepared collection already activated by this page. */
|
|
75
|
+
getCollection(name) { return this.#collections.find(collection => collection.name === name); }
|
|
71
76
|
subscribe(topic, callback) { return this._subscriptions.subscribe(topic, callback); }
|
|
72
77
|
unsubscribe(registration) { this._subscriptions.unsubscribe(registration); }
|
|
73
78
|
format(value, options) { return formatValue(value, options, {locale: this.locale, timeZone: this.timeZone}); }
|
|
@@ -43,17 +43,17 @@ export class DeviceHandler extends Handler {
|
|
|
43
43
|
|
|
44
44
|
installData() {
|
|
45
45
|
const {gramlot} = this;
|
|
46
|
-
gramlot.data.setItem('
|
|
47
|
-
gramlot.data.setItem('
|
|
46
|
+
gramlot.data.setItem('_gramlot.device.database', null, {status: 'idle', error: null});
|
|
47
|
+
gramlot.data.setItem('_gramlot.device.orientation', null, {status: 'idle', error: null, listening: false});
|
|
48
48
|
for (const name of ['gyroscope', 'accelerometer']) {
|
|
49
|
-
gramlot.data.setItem(`
|
|
49
|
+
gramlot.data.setItem(`_gramlot.device.${name}`, null,
|
|
50
50
|
{enabled: false, watching: false, status: 'idle', error: null});
|
|
51
|
-
gramlot.data.getNode(`
|
|
52
|
-
this.#sensors.set(name, {node: gramlot.data.getNode(`
|
|
51
|
+
gramlot.data.getNode(`_gramlot.device.${name}`).setAttr({error: null}, false, true, false);
|
|
52
|
+
this.#sensors.set(name, {node: gramlot.data.getNode(`_gramlot.device.${name}`),
|
|
53
53
|
stream: null, cleanup: Promise.resolve()});
|
|
54
54
|
}
|
|
55
55
|
for (const name of NAMES) {
|
|
56
|
-
const path = `
|
|
56
|
+
const path = `_gramlot.device.${name}`;
|
|
57
57
|
const attrs = {status: 'idle', error: null, cacheTime: name === 'appinfo' ? -1 : 5};
|
|
58
58
|
if (name === 'location') Object.assign(attrs, {enabled: false, watching: false});
|
|
59
59
|
gramlot.data.setItem(path, null);
|
|
@@ -63,45 +63,45 @@ export class DeviceHandler extends Handler {
|
|
|
63
63
|
node.resolver = resolver;
|
|
64
64
|
this.resolvers.set(name, resolver);
|
|
65
65
|
}
|
|
66
|
-
gramlot.data.setItem('
|
|
66
|
+
gramlot.data.setItem('_gramlot.device.clipboard', null,
|
|
67
67
|
{status: 'idle', error: null, text: '', copy: null, paste: null, operation: null});
|
|
68
|
-
const clipboard = gramlot.data.getNode('
|
|
69
|
-
gramlot.data.setItem('
|
|
70
|
-
const camera = gramlot.data.getNode('
|
|
71
|
-
gramlot.data.setItem('
|
|
72
|
-
const barcode = gramlot.data.getNode('
|
|
73
|
-
gramlot.data.setItem('
|
|
74
|
-
const biometrics = gramlot.data.getNode('
|
|
68
|
+
const clipboard = gramlot.data.getNode('_gramlot.device.clipboard');
|
|
69
|
+
gramlot.data.setItem('_gramlot.device.camera', null, {status: 'idle', error: null, capture: null, choose: null});
|
|
70
|
+
const camera = gramlot.data.getNode('_gramlot.device.camera');
|
|
71
|
+
gramlot.data.setItem('_gramlot.device.barcode', null, {status: 'idle', error: null, scan: null});
|
|
72
|
+
const barcode = gramlot.data.getNode('_gramlot.device.barcode');
|
|
73
|
+
gramlot.data.setItem('_gramlot.device.biometrics', null, {status: 'idle', error: null, verify: null});
|
|
74
|
+
const biometrics = gramlot.data.getNode('_gramlot.device.biometrics');
|
|
75
75
|
const notifications = new Bag();
|
|
76
76
|
notifications.setItem('request', new Bag());
|
|
77
77
|
for (const name of ['scheduled', 'received', 'action']) notifications.setItem(name, null);
|
|
78
|
-
gramlot.data.setItem('
|
|
78
|
+
gramlot.data.setItem('_gramlot.device.notifications', notifications,
|
|
79
79
|
{status: 'idle', error: null, schedule: null, listening: false, listenerError: null});
|
|
80
|
-
const notificationNode = gramlot.data.getNode('
|
|
80
|
+
const notificationNode = gramlot.data.getNode('_gramlot.device.notifications');
|
|
81
81
|
const push = new Bag();
|
|
82
82
|
for (const name of ['registration', 'received', 'action']) push.setItem(name, null);
|
|
83
|
-
gramlot.data.setItem('
|
|
83
|
+
gramlot.data.setItem('_gramlot.device.push', push,
|
|
84
84
|
{status: 'idle', error: null, register: null, listening: false, listenerError: null});
|
|
85
|
-
const pushNode = gramlot.data.getNode('
|
|
85
|
+
const pushNode = gramlot.data.getNode('_gramlot.device.push');
|
|
86
86
|
const links = new Bag();
|
|
87
87
|
links.setItem('request', null);
|
|
88
|
-
gramlot.data.setItem('
|
|
88
|
+
gramlot.data.setItem('_gramlot.device.links', links, {listening: false, listenerError: null});
|
|
89
89
|
const shortcuts = new Bag();
|
|
90
90
|
shortcuts.setItem('request', null);
|
|
91
|
-
gramlot.data.setItem('
|
|
92
|
-
gramlot.data.setItem('
|
|
91
|
+
gramlot.data.setItem('_gramlot.device.shortcuts', shortcuts, {listening: false, listenerError: null});
|
|
92
|
+
gramlot.data.setItem('_gramlot.device.network', null, {status: 'idle', error: null, listening: false});
|
|
93
93
|
const lifecycle = new Bag();
|
|
94
94
|
lifecycle.setItem('active', null);
|
|
95
95
|
lifecycle.setItem('event', null);
|
|
96
96
|
lifecycle.setItem('sequence', 0);
|
|
97
|
-
gramlot.data.setItem('
|
|
98
|
-
gramlot.data.setItem('
|
|
97
|
+
gramlot.data.setItem('_gramlot.device.lifecycle', lifecycle, {status: 'idle', error: null, listening: false});
|
|
98
|
+
gramlot.data.setItem('_gramlot.device.haptics', null,
|
|
99
99
|
{status: 'idle', error: null, impact: null, style: 'medium', vibrate: null, duration: 600});
|
|
100
|
-
const haptics = gramlot.data.getNode('
|
|
101
|
-
gramlot.data.setItem('
|
|
100
|
+
const haptics = gramlot.data.getNode('_gramlot.device.haptics');
|
|
101
|
+
gramlot.data.setItem('_gramlot.device.audio', null,
|
|
102
102
|
{status: 'idle', error: null, recording: false, start: null, stop: null, cancel: null,
|
|
103
103
|
share: null, shareStatus: 'idle', shareError: null, shareActivity: null});
|
|
104
|
-
const audio = gramlot.data.getNode('
|
|
104
|
+
const audio = gramlot.data.getNode('_gramlot.device.audio');
|
|
105
105
|
gramlot.data.subscribe('gramlot.device', {update: event => {
|
|
106
106
|
if (this.disposed) return;
|
|
107
107
|
for (const [name, sensor] of this.#sensors) {
|
|
@@ -199,16 +199,16 @@ export class DeviceHandler extends Handler {
|
|
|
199
199
|
node.setAttr({status: 'success', error: null}, true, true, false);
|
|
200
200
|
});
|
|
201
201
|
if (provider.capabilities.includes('links')) {
|
|
202
|
-
this.#startLinkEvents(this.gramlot.data.getNode('
|
|
202
|
+
this.#startLinkEvents(this.gramlot.data.getNode('_gramlot.device.links'));
|
|
203
203
|
}
|
|
204
204
|
if (provider.capabilities.includes('shortcuts')) {
|
|
205
|
-
this.#startShortcutEvents(this.gramlot.data.getNode('
|
|
205
|
+
this.#startShortcutEvents(this.gramlot.data.getNode('_gramlot.device.shortcuts'));
|
|
206
206
|
}
|
|
207
207
|
if (provider.capabilities.includes('push')) {
|
|
208
|
-
this.#startPushEvents(this.gramlot.data.getNode('
|
|
208
|
+
this.#startPushEvents(this.gramlot.data.getNode('_gramlot.device.push'));
|
|
209
209
|
}
|
|
210
210
|
if (provider.capabilities.includes('notifications')) {
|
|
211
|
-
this.#startNotificationEvents(this.gramlot.data.getNode('
|
|
211
|
+
this.#startNotificationEvents(this.gramlot.data.getNode('_gramlot.device.notifications'));
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
|
|
@@ -251,7 +251,7 @@ export class DeviceHandler extends Handler {
|
|
|
251
251
|
|
|
252
252
|
// Page-owned state streams share lifetime/error handling, never public dispatch.
|
|
253
253
|
#startStateEvents(name, start, accept) {
|
|
254
|
-
const node = this.gramlot.data.getNode(`
|
|
254
|
+
const node = this.gramlot.data.getNode(`_gramlot.device.${name}`);
|
|
255
255
|
if (!this.provider.capabilities.includes(name)) {
|
|
256
256
|
node.setAttr(failureAttributes({code: 'UNAVAILABLE', message: `${name} is unavailable`}), true, true, false);
|
|
257
257
|
return;
|
|
@@ -913,7 +913,7 @@ export class DeviceHandler extends Handler {
|
|
|
913
913
|
this.assertLive();
|
|
914
914
|
if (!/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(name) || typeof name !== 'string') throw new TypeError('Invalid database name');
|
|
915
915
|
if (this.#database) throw new Error('This page already owns a database connection');
|
|
916
|
-
const node = this.gramlot.data.getNode('
|
|
916
|
+
const node = this.gramlot.data.getNode('_gramlot.device.database');
|
|
917
917
|
const state = (status, error = null) => {
|
|
918
918
|
if (!this.disposed) node.setAttr({status, error}, true, true, false);
|
|
919
919
|
};
|
|
@@ -7,7 +7,7 @@ import type {Bag} from '@genrojs/bag';
|
|
|
7
7
|
import type {SourceBag, SourceBagNode} from '@genrojs/builders';
|
|
8
8
|
import type {DomElement} from '../dom.d.ts';
|
|
9
9
|
import type {Gramlot} from '../gramlot.js';
|
|
10
|
-
import type {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
10
|
+
import type {GramlotBuilder, GramlotSourceBag} from '../builder/gramlot-builder.js';
|
|
11
11
|
import type {NameSyntax} from '../builder/name-syntax.js';
|
|
12
12
|
import type {GramlotRenderer} from '../renderer/gramlot-renderer.js';
|
|
13
13
|
import {Handler} from './handler.js';
|
|
@@ -24,7 +24,7 @@ export class SourceHandler extends Handler {
|
|
|
24
24
|
/** The binding runtime of the page. */
|
|
25
25
|
binding: unknown;
|
|
26
26
|
/** The Source Bag observed by the renderer. */
|
|
27
|
-
source:
|
|
27
|
+
source: GramlotSourceBag;
|
|
28
28
|
/** The live renderer of the page. */
|
|
29
29
|
renderer: GramlotRenderer;
|
|
30
30
|
/**
|
package/src/ide-documents.js
CHANGED
|
@@ -14,6 +14,8 @@ export class IdeDocuments {
|
|
|
14
14
|
get state() { return this.source.getRelativeData('.'); }
|
|
15
15
|
get documents() { return this.state.getItem('documents'); }
|
|
16
16
|
async open(root, path) {
|
|
17
|
+
// Only registered IDE document types may create an editor tab.
|
|
18
|
+
if (!/\.(?:py|js|mjs|ts|json|html|css|xml|md|markdown|sql|typ|txt|png|jpg|jpeg|webp)$/i.test(path)) return null;
|
|
17
19
|
const key = documentKey(root, path);
|
|
18
20
|
const existing = this.documents.getNodes().find(node => !node.value.getItem('isNew') && node.value.getItem('root') === root && node.value.getItem('path') === path);
|
|
19
21
|
if (existing) return existing.label;
|
|
@@ -22,7 +24,13 @@ export class IdeDocuments {
|
|
|
22
24
|
const promise = this.gramlot.rpc.call('data', 'document_read', {root,path}, {signal:request.signal}).then(result => {
|
|
23
25
|
if (this.disposed || request.signal.aborted) return null;
|
|
24
26
|
const document = new Bag();
|
|
25
|
-
|
|
27
|
+
const content = result.language === 'image' ? result.content.toTytx() : result.content;
|
|
28
|
+
for (const [name,value] of Object.entries({...result, content, root, saved:content, busy:false})) document.setItem(name,value);
|
|
29
|
+
if (result.language === 'image') {
|
|
30
|
+
const annotations = result.content;
|
|
31
|
+
document.setItem('annotations',annotations);
|
|
32
|
+
annotations.subscribe('ide-annotations',{any:()=>document.setItem('content',annotations.toTytx())});
|
|
33
|
+
}
|
|
26
34
|
this.documents.setItem(key, document);
|
|
27
35
|
return key;
|
|
28
36
|
}).finally(() => this.pending.delete(key));
|
|
@@ -104,8 +112,12 @@ export class IdeDocuments {
|
|
|
104
112
|
if (!doc || doc.getItem('isNew') || !this.dirty(key) || !doc.getItem('writable') || this.pending.has(key)) return false;
|
|
105
113
|
const content = doc.getItem('content'), request = new AbortController();
|
|
106
114
|
doc.setItem('busy',true);
|
|
107
|
-
const
|
|
108
|
-
|
|
115
|
+
const image = doc.getItem('language') === 'image';
|
|
116
|
+
const path = image ? doc.getItem('annotationPath') : doc.getItem('path');
|
|
117
|
+
const creating = image && doc.getItem('revision') === null;
|
|
118
|
+
const promise = this.gramlot.rpc.call('data',creating ? 'document_create' : 'document_save', {
|
|
119
|
+
root:doc.getItem('root'), path, content:image ? Bag.fromTytx(content) : content,
|
|
120
|
+
...(creating ? {} : {revision:doc.getItem('revision')})
|
|
109
121
|
}, {signal:request.signal}).then(result => {
|
|
110
122
|
if (this.disposed || request.signal.aborted) return false;
|
|
111
123
|
doc.setItem('revision',result.revision);
|
|
@@ -119,6 +131,10 @@ export class IdeDocuments {
|
|
|
119
131
|
const doc = this.documents.getItem(key);
|
|
120
132
|
if (!doc || !this.dirty(key) || this.pending.has(key)) return false;
|
|
121
133
|
doc.setItem('content',doc.getItem('saved'));
|
|
134
|
+
if (doc.getItem('language') === 'image') {
|
|
135
|
+
doc.getItem('annotations').replace(Bag.fromTytx(doc.getItem('saved')));
|
|
136
|
+
doc.setItem('content',doc.getItem('saved'));
|
|
137
|
+
}
|
|
122
138
|
return true;
|
|
123
139
|
}
|
|
124
140
|
canClose(key, discard = false) {
|
package/src/ide-runtime.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export class IdeLogic {
|
|
|
9
9
|
fileSystemOpen(node:SourceBagNode,args:{root:string|null}):Promise<string|null>|undefined;
|
|
10
10
|
ideMount(node:SourceBagNode):void;
|
|
11
11
|
ideOpenWorkspace(node:SourceBagNode):void;
|
|
12
|
+
ideUploadCompleted(node:SourceBagNode,args:{result:{root:string,path:string}}):Promise<void>;
|
|
12
13
|
ideDocumentState(node:SourceBagNode,key:string):void;
|
|
13
14
|
ideOpenDocument(node:SourceBagNode,root:string,path:string):Promise<void>;
|
|
14
15
|
ideNew(node:SourceBagNode):void;
|
package/src/ide-runtime.js
CHANGED
|
@@ -65,6 +65,16 @@ export class IdeLogic {
|
|
|
65
65
|
const root = state.getItem('workspace');
|
|
66
66
|
if (root && root !== state.getItem('browser.root')) state.setItem('browser.requestedRoot',root);
|
|
67
67
|
}
|
|
68
|
+
async ideUploadCompleted(node, {result}) {
|
|
69
|
+
const context=ideContext(node), state=context.scope.getRelativeData('.');
|
|
70
|
+
if (state.getItem('browser.root') !== result.root) return;
|
|
71
|
+
state.setItem('upload.open',false);
|
|
72
|
+
const controller=context.scope.value.getNode('frame.left.browser').fileSystemController;
|
|
73
|
+
if (controller.request) return;
|
|
74
|
+
const opened=await controller.open(result.root);
|
|
75
|
+
if (opened === result.root && !context.documents.disposed && state.getItem('browser.root') === result.root)
|
|
76
|
+
await this.ideOpenDocument(context.scope,result.root,result.path);
|
|
77
|
+
}
|
|
68
78
|
ideDocumentState(node, key) {
|
|
69
79
|
const context = ideContext(node), {documents} = context;
|
|
70
80
|
const doc = documents.documents.getItem(key);
|
|
@@ -147,38 +157,42 @@ export class IdeLogic {
|
|
|
147
157
|
form.button('Create file',{disabled:'^.busy'}).dataController({func:'ideCreate',documentKey:key});
|
|
148
158
|
form.button('Cancel',{disabled:'^.busy',class:'button--quiet'}).dataController({func:'ideCancelCreate',documentKey:key});
|
|
149
159
|
const editorArea = target.div({flex:'1',min_height:0});
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
height:'100%',
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
previewPane.
|
|
160
|
+
if (doc.getItem('language') === 'image') {
|
|
161
|
+
editorArea.drawingPane({image:`^.documents.${key}.image`,annotations:`^.documents.${key}.annotations`,height:'100%'});
|
|
162
|
+
} else {
|
|
163
|
+
const html = doc.getItem('language') === 'html';
|
|
164
|
+
const markdown = doc.getItem('language') === 'markdown';
|
|
165
|
+
const rich = html || markdown;
|
|
166
|
+
const typst = doc.getItem('language') === 'typst';
|
|
167
|
+
const preview = rich || typst || recipe;
|
|
168
|
+
const views = preview ? editorArea.tabContainer({height:'100%',selectedPage:`^.documents.${key}.view`}) : null;
|
|
169
|
+
const code = preview ? views.contentPane({title:'Code',pageName:'code',height:'100%'}) : editorArea;
|
|
170
|
+
codeMirrorWithOptions(code,{datapath:`.documents.${key}`,value:'^.content',language:doc.getItem('language'),
|
|
171
|
+
height:'100%', readonly:'^.readonly',nodeId:`${context.editorPrefix}_editor_${key}`,
|
|
172
|
+
editorView:'code',selfsubscribe_historyChanged:'ideHistoryChanged'});
|
|
173
|
+
target.dataController({func:'ideSave',documentKey:key,[`subscribe_${context.editorPrefix}_editor_${key}_save`]:true});
|
|
174
|
+
if (typst) views.contentPane({title:'Preview',pageName:'preview',height:'100%'}).typstPreview({value:`^.documents.${key}.content`,filename:`^.documents.${key}.pdfFilename`,height:'100%'});
|
|
175
|
+
if (recipe) {
|
|
176
|
+
const output = views.contentPane({title:'Preview',pageName:'preview',height:'100%',display:'flex',flex_direction:'column'});
|
|
177
|
+
output.div(`^.documents.${key}.renderStatus`,{role:'status',padding:'8px 12px',white_space:'pre-wrap',overflow:'auto',max_height:'30%'});
|
|
178
|
+
output.typstPreview({value:`^.documents.${key}.typstSource`,filename:`^.documents.${key}.pdfFilename`,
|
|
179
|
+
hidden:`^.documents.${key}.previewHidden`,flex:'1',min_height:0});
|
|
180
|
+
views.contentPane({title:'Generated Typst',pageName:'generated',height:'100%'})
|
|
181
|
+
.codeMirror({value:`^.documents.${key}.typstSource`,language:'typst',readonly:true,height:'100%'});
|
|
182
|
+
}
|
|
183
|
+
if (rich) {
|
|
184
|
+
const previewPane = views.contentPane({title:'Preview',pageName:'preview',height:'100%',display:'flex',flex_direction:'column'});
|
|
185
|
+
if (markdown) {
|
|
186
|
+
doc.setItem('allowHtml',false);
|
|
187
|
+
previewPane.checkbox({value:`^.documents.${key}.allowHtml`,label:'Allow embedded HTML',class:'gramlot-ide-allow-html',padding:'8px 12px',flex_shrink:0});
|
|
188
|
+
}
|
|
189
|
+
previewPane[html ? 'htmlPreview' : 'markdownPreview']({value:`^.documents.${key}.content`,flex:'1',min_height:0,
|
|
190
|
+
...(markdown ? {allowHtml:`^.documents.${key}.allowHtml`} : {})});
|
|
191
|
+
views.contentPane({title:'Rich text',pageName:'rich',height:'100%'})[html ? 'htmlEditor' : 'markdownEditor']({
|
|
192
|
+
datapath:`.documents.${key}`,value:'^.content',readonly:'^.readonly',height:'100%',
|
|
193
|
+
nodeId:`${context.editorPrefix}_rich_editor_${key}`,editorView:'rich',selfsubscribe_historyChanged:'ideHistoryChanged'});
|
|
194
|
+
target.dataController({func:'ideSave',documentKey:key,[`subscribe_${context.editorPrefix}_rich_editor_${key}_save`]:true});
|
|
175
195
|
}
|
|
176
|
-
previewPane[html ? 'htmlPreview' : 'markdownPreview']({value:`^.documents.${key}.content`,flex:'1',min_height:0,
|
|
177
|
-
...(markdown ? {allowHtml:`^.documents.${key}.allowHtml`} : {})});
|
|
178
|
-
views.contentPane({title:'Rich text',pageName:'rich',height:'100%'})[html ? 'htmlEditor' : 'markdownEditor']({
|
|
179
|
-
datapath:`.documents.${key}`,value:'^.content',readonly:'^.readonly',height:'100%',
|
|
180
|
-
nodeId:`${context.editorPrefix}_rich_editor_${key}`,editorView:'rich',selfsubscribe_historyChanged:'ideHistoryChanged'});
|
|
181
|
-
target.dataController({func:'ideSave',documentKey:key,[`subscribe_${context.editorPrefix}_rich_editor_${key}_save`]:true});
|
|
182
196
|
}
|
|
183
197
|
}
|
|
184
198
|
}
|