@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
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Literal membership shared by checkbox projections and collection-view predicates. */
|
|
2
|
+
export function containsId(value, id) { return (',' + value + ',').includes(',' + id + ','); }
|
|
3
|
+
export function requireIdSet(value) {
|
|
4
|
+
if (typeof value !== 'string') throw new TypeError('grid checked must refer to a string (empty string for an empty set)');
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
export function requireId(id) {
|
|
8
|
+
if (typeof id !== 'string' || !id || id.includes(',')) throw new TypeError('grid checkedField requires nonempty text IDs without commas');
|
|
9
|
+
return id;
|
|
10
|
+
}
|
package/src/view/controls.js
CHANGED
|
@@ -623,6 +623,14 @@ function componentContext(adapter) {
|
|
|
623
623
|
callLogic:(name, keywords) => callLogic(binding.runtime, node, name, keywords),
|
|
624
624
|
format:(value, options) => app.format(value, options),
|
|
625
625
|
...validationContext(binding),
|
|
626
|
+
selectionDisplay:(caption, value) => {
|
|
627
|
+
if (binding.closed) return;
|
|
628
|
+
const pointer = node.getAttr('value');
|
|
629
|
+
if (node.pointerType(pointer) !== '^' || pointer.includes('?') || !Object.is(node.getRelativeData(pointer), value)) return;
|
|
630
|
+
const path = pointer.slice(1) + '?_displayedValue';
|
|
631
|
+
if (node.getRelativeData(path) !== caption) node.setRelativeData(path, caption);
|
|
632
|
+
},
|
|
633
|
+
periodOutput:(path, value) => node.setRelativeData(path, value),
|
|
626
634
|
selectionOutputs:({selectedCaption, selectedRecord, fields}, row) => {
|
|
627
635
|
if (binding.closed) return;
|
|
628
636
|
if (selectedCaption) node.setRelativeData(selectedCaption, row?.caption ?? null);
|
package/src/view/html.js
CHANGED
|
@@ -146,6 +146,10 @@ export class HtmlElement {
|
|
|
146
146
|
this.validateLabelbox(node);
|
|
147
147
|
const controlBox = document.createElement('div'); controlBox.append(element);
|
|
148
148
|
record.labelbox = createLabelbox(document,controlBox);
|
|
149
|
+
record.labelbox.choose = value => {
|
|
150
|
+
if (node.pointerType(node.getAttr('lbl_value'))) this.writeParameter(node, 'lbl_value', value);
|
|
151
|
+
else node.setAttr({lbl_value:value});
|
|
152
|
+
};
|
|
149
153
|
record.presentation = record.labelbox.box;
|
|
150
154
|
record.labelId = `gramlot-label-${randomId()}`;
|
|
151
155
|
record.controlId = `gramlot-control-${randomId()}`;
|
|
@@ -224,7 +228,12 @@ export class HtmlElement {
|
|
|
224
228
|
}
|
|
225
229
|
if (record.labelbox) {
|
|
226
230
|
record.labelbox.box.style.visibility = '';
|
|
227
|
-
|
|
231
|
+
const parameters = this.definition(node).meta.gramlot_component?.parameters ?? {};
|
|
232
|
+
const defaults = Object.fromEntries(Object.entries(parameters)
|
|
233
|
+
.filter(([name, spec]) => name.startsWith('lbl_') && Object.hasOwn(spec, 'default'))
|
|
234
|
+
.map(([name, spec]) => [name, spec.default]));
|
|
235
|
+
if (attrs.lbl_variant === 'card' && attrs.lbl_position == null) delete defaults.lbl_position;
|
|
236
|
+
projectLabelbox(record.labelbox, {...defaults, ...attrs}, adapt);
|
|
228
237
|
}
|
|
229
238
|
if (this.definition(node).meta.gramlot_component) {
|
|
230
239
|
if (this.definition(node).meta.gramlot_component.bagStore) {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {parseChoices, choiceCaption} from '../components/choices.js';
|
|
2
|
+
|
|
3
|
+
/** Label presentation over the shared menu. Source/Data own choices and selection. */
|
|
4
|
+
export class LabelMenu {
|
|
5
|
+
constructor(layout, choose) {
|
|
6
|
+
this.layout = layout;
|
|
7
|
+
const doc = layout.box.ownerDocument;
|
|
8
|
+
this.button = doc.createElement('button');
|
|
9
|
+
this.button.type = 'button';
|
|
10
|
+
this.button.className = 'label-menu-trigger';
|
|
11
|
+
this.button.setAttribute('aria-haspopup', 'menu');
|
|
12
|
+
this.button.setAttribute('aria-expanded', 'false');
|
|
13
|
+
this.menu = doc.createElement('gramlot-menu');
|
|
14
|
+
this.menu.projectAttributes({});
|
|
15
|
+
layout.labelBox.append(this.button, this.menu);
|
|
16
|
+
this.button.addEventListener('click', event => {
|
|
17
|
+
event.preventDefault(); event.stopPropagation();
|
|
18
|
+
if (this.menu.opened) this.menu.close();
|
|
19
|
+
else this.menu.open(this.button);
|
|
20
|
+
});
|
|
21
|
+
this.button.addEventListener('keydown', event => {
|
|
22
|
+
if (!['ArrowDown', 'ArrowUp'].includes(event.key)) return;
|
|
23
|
+
event.preventDefault(); event.stopPropagation();
|
|
24
|
+
this.menu.open(this.button, event.key === 'ArrowUp');
|
|
25
|
+
});
|
|
26
|
+
this.choose = choose;
|
|
27
|
+
}
|
|
28
|
+
project({lbl, lbl_value, lbl_values, disabled, readonly}, adapt) {
|
|
29
|
+
const choices = parseChoices(lbl_values);
|
|
30
|
+
if (this.values !== lbl_values) {
|
|
31
|
+
this.menu.close(false);
|
|
32
|
+
for (const item of this.menu.items) item.releaseCommand();
|
|
33
|
+
this.menu.replaceChildren(...choices.map(({id, caption}) => {
|
|
34
|
+
const item = this.menu.ownerDocument.createElement('gramlot-menu-line');
|
|
35
|
+
item.projectAttributes({code:id, caption}, adapt);
|
|
36
|
+
item.activateCommand = event => {
|
|
37
|
+
if (item.prepareCommand(event)) this.choose(id);
|
|
38
|
+
};
|
|
39
|
+
item.control.addEventListener('click', event => item.activateCommand(event));
|
|
40
|
+
return item;
|
|
41
|
+
}));
|
|
42
|
+
this.values = lbl_values;
|
|
43
|
+
}
|
|
44
|
+
const caption = choiceCaption(choices, lbl_value, lbl);
|
|
45
|
+
this.button.textContent = caption;
|
|
46
|
+
this.button.disabled = Boolean(disabled || readonly || !choices.length);
|
|
47
|
+
if (this.button.disabled) this.menu.close(false);
|
|
48
|
+
for (const item of this.menu.items) {
|
|
49
|
+
item.projectAttributes({...item.parameters, checked:item.parameters.code === lbl_value}, adapt);
|
|
50
|
+
}
|
|
51
|
+
this.layout.fieldLabel.textContent = caption;
|
|
52
|
+
this.layout.fieldLabel.hidden = true;
|
|
53
|
+
this.layout.labelBox.hidden = false;
|
|
54
|
+
}
|
|
55
|
+
dispose() {
|
|
56
|
+
this.menu.close(false);
|
|
57
|
+
for (const item of this.menu.items) item.releaseCommand();
|
|
58
|
+
this.menu.remove(); this.button.remove();
|
|
59
|
+
this.layout.fieldLabel.hidden = false;
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/view/labelbox.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import {LabelMenu} from './label-menu.js';
|
|
2
|
+
|
|
1
3
|
/** Shared DOM presentation; instance-owned projection cache, no application state. */
|
|
2
4
|
export const labelboxPositions = ['TL', 'TC', 'TR', 'L', 'R', 'BL', 'BC', 'BR'];
|
|
3
|
-
export const labelboxStyle = `.gramlot-labelbox
|
|
5
|
+
export const labelboxStyle = `.gramlot-labelbox>.label-box>.label-menu-trigger{font:inherit;color:inherit;background:transparent;border:0;padding:0;min-width:0;min-height:var(--gramlot-touch-target,0px);height:auto;display:inline-flex;align-items:center;gap:.4em;cursor:pointer;text-align:inherit;line-height:inherit}
|
|
6
|
+
.gramlot-labelbox>.label-box>.label-menu-trigger::after{content:'';width:.35em;height:.35em;border-right:1.5px solid currentColor;border-bottom:1.5px solid currentColor;transform:translateY(-.1em) rotate(45deg);flex:none}
|
|
7
|
+
.gramlot-labelbox>.label-box>.label-menu-trigger:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:3px;border-radius:2px}
|
|
8
|
+
.gramlot-labelbox>.label-box>.label-menu-trigger:disabled{opacity:.5;cursor:default}
|
|
9
|
+
.gramlot-labelbox>.label-box>label[hidden]{display:none}
|
|
10
|
+
.gramlot-labelbox[hidden]{display:none!important}
|
|
4
11
|
.gramlot-labelbox{box-sizing:border-box;min-width:0;min-height:0;--gramlot-label-width:initial;--gramlot-formlet-label-width:initial;display:grid;gap:var(--gramlot-label-gap,.25em);grid-template-areas:'label' 'control';grid-template-columns:minmax(0,1fr);grid-template-rows:max-content minmax(0,1fr)}
|
|
5
12
|
.gramlot-labelbox>.label-box{grid-area:label;color:var(--gramlot-label-color,var(--gramlot-text-secondary,inherit));font-size:var(--gramlot-label-size,1em)} .gramlot-labelbox>.control-box{box-sizing:border-box;grid-area:control;min-width:0;min-height:0;display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr)}
|
|
6
13
|
.gramlot-labelbox>.control-box>*{max-width:100%;box-sizing:border-box}
|
|
@@ -59,7 +66,7 @@ export function createLabelbox(document, controlBox) {
|
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
export function projectLabelbox(layout, attrs, adapt) {
|
|
62
|
-
const {lbl, lbl_variant, lbl_position = lbl_variant === 'card' ? 'TC' : 'TL', ...rest} = attrs;
|
|
69
|
+
const {lbl, lbl_value, lbl_values, lbl_variant, lbl_position = lbl_variant === 'card' ? 'TC' : 'TL', ...rest} = attrs;
|
|
63
70
|
if (!labelboxPositions.includes(lbl_position)) throw new TypeError(`Invalid lbl_position: ${lbl_position}`);
|
|
64
71
|
const groups = {box:{},label:{},labelBox:{},controlBox:{}};
|
|
65
72
|
const prefixes = [['box_l_','labelBox'],['box_c_','controlBox'],['lbl_','label'],['box_','box']];
|
|
@@ -85,6 +92,12 @@ export function projectLabelbox(layout, attrs, adapt) {
|
|
|
85
92
|
else layout.box.dataset.variant = lbl_variant;
|
|
86
93
|
layout.fieldLabel.textContent = lbl ?? '';
|
|
87
94
|
layout.labelBox.hidden = lbl == null || lbl === '';
|
|
95
|
+
if (lbl_values != null) {
|
|
96
|
+
layout.menu ??= new LabelMenu(layout, value => layout.choose(value));
|
|
97
|
+
layout.menu.project(attrs, adapt);
|
|
98
|
+
} else if (layout.menu) {
|
|
99
|
+
layout.menu.dispose(); layout.menu = null;
|
|
100
|
+
}
|
|
88
101
|
layout.box.dispatchEvent(new layout.box.ownerDocument.defaultView.Event('gramlot-label-layout', {bubbles:true}));
|
|
89
102
|
return rest;
|
|
90
103
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** An editor-owned document destination for the same live Source and renderer. */
|
|
2
|
+
export class VisualEditorCanvas {
|
|
3
|
+
constructor({app, editor, design}) {
|
|
4
|
+
this.renderer = app.src.renderer;
|
|
5
|
+
this.design = design;
|
|
6
|
+
const presentation = this.renderer.records.get(design).presentation;
|
|
7
|
+
this.frame = presentation.ownerDocument.createElement('iframe');
|
|
8
|
+
this.frame.title = 'Page canvas';
|
|
9
|
+
this.frame.className = 'visual-editor-canvas-frame';
|
|
10
|
+
this.frame.style.cssText = 'display:block;width:100%;height:100%;min-height:240px;border:0;background:white';
|
|
11
|
+
presentation.before(this.frame);
|
|
12
|
+
const document = this.frame.contentDocument;
|
|
13
|
+
app.registerDocument(document);
|
|
14
|
+
const base = document.createElement('style');
|
|
15
|
+
base.textContent = 'html,body{margin:0;min-height:100%;} .visual-editor-canvas{min-height:100vh;}';
|
|
16
|
+
this.styles = document.createElement('style');
|
|
17
|
+
const selection = document.createElement('style');
|
|
18
|
+
selection.textContent = '.gramlot-source-selected{outline:2px solid #8ab4f8!important;outline-offset:-2px!important;}';
|
|
19
|
+
document.head.append(base, this.styles, selection);
|
|
20
|
+
this.body = document.body;
|
|
21
|
+
this.renderer.mountDestination(design, this.body);
|
|
22
|
+
this.release = this.renderer.onDispose(editor, () => this.dispose());
|
|
23
|
+
}
|
|
24
|
+
setCss(texts) { this.styles.textContent = texts.join('\n'); }
|
|
25
|
+
dispose() {
|
|
26
|
+
this.release?.(); this.release = null;
|
|
27
|
+
this.frame.remove();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {HtmlBuilder, SourceBag} from '@genrojs/builders';
|
|
2
|
+
|
|
3
|
+
const htmlTags = new Set(Object.entries(new HtmlBuilder().schema)
|
|
4
|
+
.filter(([, info]) => !info._meta?.data_element && !info._meta?.subbuilder && !info._meta?.container)
|
|
5
|
+
.map(([tag]) => tag));
|
|
6
|
+
|
|
7
|
+
export function validateCatalogue(catalogue) {
|
|
8
|
+
if (catalogue == null || catalogue === 'html') return;
|
|
9
|
+
if (!Array.isArray(catalogue) || catalogue.some(tag => typeof tag !== 'string' || !tag || tag.trim() !== tag))
|
|
10
|
+
throw new TypeError('catalogue must be "html" or a list of tag names');
|
|
11
|
+
if (!catalogue.includes('div')) throw new Error('catalogue must include div for pageRoot');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function catalogueAllows(catalogue, tag, meta = {}) {
|
|
15
|
+
if (catalogue == null) return true;
|
|
16
|
+
if (Array.isArray(catalogue)) return catalogue.includes(tag);
|
|
17
|
+
return !meta.gramlot_component && !meta.data_element && !meta.subbuilder && !meta.container
|
|
18
|
+
&& htmlTags.has(meta.render_tag ?? tag);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function validateCatalogueSource(catalogue, source) {
|
|
22
|
+
if (catalogue == null) return;
|
|
23
|
+
const visit = (bag, prefix) => {
|
|
24
|
+
for (const node of bag.getNodes()) {
|
|
25
|
+
const path = prefix ? `${prefix}.${node.label}` : node.label;
|
|
26
|
+
if (!catalogueAllows(catalogue, node.nodeTag, node.getAttr('_meta') ?? {}))
|
|
27
|
+
throw new Error(`Tag ${node.nodeTag} is outside the editor catalogue at ${path}`);
|
|
28
|
+
if (node.resolver) throw new Error(`Catalogue scope requires materialized Source at ${path}`);
|
|
29
|
+
const value = node.getValue(true);
|
|
30
|
+
if (value instanceof SourceBag) visit(value, path);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
visit(source, '');
|
|
34
|
+
}
|
package/src/visual-editor.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type {SourceBagNode} from '@genrojs/builders';
|
|
2
2
|
export function visualEditorScope(node:SourceBagNode):SourceBagNode;
|
|
3
3
|
export class VisualEditorLogic {
|
|
4
|
+
setCanvasCss(node:SourceBagNode, texts:string[]):void;
|
|
5
|
+
loadSource(node:SourceBagNode, document:{source:string; filename:string}):void;
|
|
6
|
+
currentSource(node:SourceBagNode):string;
|
|
7
|
+
markSaved(node:SourceBagNode):void;
|
|
8
|
+
initializeDocument(node:SourceBagNode):void;
|
|
4
9
|
chatRender(node:SourceBagNode, ...args:unknown[]):unknown;
|
|
5
10
|
chatCompleted(node:SourceBagNode, ...args:unknown[]):unknown;
|
|
6
11
|
chatReset(node:SourceBagNode, ...args:unknown[]):unknown;
|