@gramlot/gramlot 0.3.15 → 0.3.17
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/dist/components/editors/__init__.py +1 -1
- package/dist/components/editors/assets/collection.js +16162 -11689
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/grammar.json +3 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +134 -179
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +19 -0
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +4643 -3481
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +509 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +306 -94
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +16 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +2 -2
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/gramlot.js +2127 -507
- package/dist/gramlot.min.js +95 -40
- package/dist/runtime-notices.json +4 -0
- package/package.json +12 -8
- package/src/binding/device-resolver.js +27 -0
- package/src/binding/error-notifications.js +84 -0
- package/src/binding/remote-resolver.d.ts +18 -0
- package/src/binding/remote.js +11 -4
- package/src/binding/runtime.js +6 -2
- package/src/bootstrap.js +4 -4
- package/src/components/buttons.js +10 -3
- package/src/components/code-mirror-engine.js +14 -4
- package/src/components/code-mirror.js +2 -3
- package/src/components/container.js +1 -1
- package/src/components/date-calendar.js +1 -1
- package/src/components/formlet-labels.js +5 -4
- package/src/components/html-document.js +4 -2
- package/src/components/html-editor.js +2 -2
- package/src/components/jodit-engine.js +72 -11
- package/src/components/labelbox.js +19 -63
- package/src/components/layout.js +31 -19
- package/src/components/markdown-document.js +1 -1
- package/src/components/markdown-editor.js +2 -2
- package/src/components/menus.js +7 -6
- package/src/components/prose-mirror-engine.js +14 -1
- package/src/components/registry.js +2 -0
- package/src/components/selected-container.js +107 -14
- package/src/components/toolbar-overflow.js +9 -8
- package/src/components/transform-pane.js +140 -0
- package/src/components/tray-geometry.js +87 -0
- package/src/components/tray-pane.js +435 -0
- package/src/components/tray-settings.js +62 -0
- package/src/components/tree.js +115 -21
- package/src/components/typed-editor.js +1 -1
- package/src/components/typst-client.js +14 -13
- package/src/components/validation.js +1 -1
- package/src/components/window-surface.js +281 -0
- package/src/components/windows.js +32 -261
- package/src/device-frames.js +195 -0
- package/src/filesystem.d.ts +12 -5
- package/src/filesystem.js +9 -8
- package/src/gramlot.d.ts +3 -1
- package/src/gramlot.js +11 -4
- package/src/handlers/device-handler.d.ts +75 -0
- package/src/handlers/device-handler.js +1037 -0
- package/src/handlers/dom-handler.d.ts +2 -0
- package/src/handlers/dom-handler.js +9 -0
- package/src/handlers/rpc-handler.d.ts +2 -2
- package/src/http-transport.d.ts +3 -3
- package/src/http-transport.js +17 -11
- package/src/ide-documents.js +7 -5
- package/src/ide-runtime.d.ts +14 -3
- package/src/ide-runtime.js +124 -94
- package/src/index-page-runtime.d.ts +2 -2
- package/src/index-page-runtime.js +91 -43
- package/src/index-page-styles.js +1 -1
- package/src/index.d.ts +7 -2
- package/src/index.js +5 -1
- package/src/inout.d.ts +1 -1
- package/src/inout.js +5 -1
- package/src/mobile-environment.d.ts +6 -0
- package/src/mobile-environment.js +52 -0
- package/src/navigation-resolver.d.ts +14 -2
- package/src/renderer/attributes.js +5 -2
- package/src/renderer/drag-drop.js +5 -4
- package/src/renderer/gramlot-renderer.d.ts +13 -2
- package/src/renderer/gramlot-renderer.js +49 -13
- package/src/server/index-page.js +4 -4
- package/src/view/controls.js +48 -23
- package/src/view/html.js +85 -4
- package/src/view/labelbox.js +95 -0
- package/themes/gramlot-base/theme.css +4 -0
- package/themes/mela/theme.css +62 -15
- package/src/date-parser/civil.js +0 -61
- package/src/date-parser/index.d.ts +0 -18
- package/src/date-parser/index.js +0 -196
- package/src/date-parser/locales.js +0 -257
|
@@ -11,7 +11,7 @@ export const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
|
11
11
|
const BINDING_ATTRIBUTES = new Set([
|
|
12
12
|
'default', 'default_value', 'live', 'group', 'visible', 'action', 'fire', 'ask', '_ask', '_ask_if', '_ask_title', '_ask_onCancel',
|
|
13
13
|
'if', 'else', '_init', '_onStart', '_onBuilt', '_delay', '_timing', '_userChanges',
|
|
14
|
-
'remote', '_cachedRemote', '_onRemote', '_onCalling', 'onClose', 'onDrag', 'onDrop', 'dropTargetCb', 'onDragEnd',
|
|
14
|
+
'remote', '_cachedRemote', '_onRemote', '_onCalling', 'onClose', 'onEnd', 'onDrag', 'onDrop', 'dropTargetCb', 'onDragEnd',
|
|
15
15
|
'dropTarget', 'dropTypes', 'dragTags', 'dropTags', 'effectAllowed', 'dropEffect', 'dragClass',
|
|
16
16
|
]);
|
|
17
17
|
const BINDING_ATTRIBUTE_PREFIXES = ['default_', 'attr_', 'fire_', 'connect_on', 'subscribe_', 'selfsubscribe_', 'formsubscribe_', 'remote_'];
|
|
@@ -29,7 +29,7 @@ const NATIVE_ATTRIBUTES = {
|
|
|
29
29
|
const DISPLAY_ATTRIBUTES = ['format', 'mask', 'locale', 'timeZone', 'places', 'dtype'];
|
|
30
30
|
|
|
31
31
|
// Output URL attributes, including the native form action authored as html_action.
|
|
32
|
-
const URL_ATTRIBUTES = new Set(['href', 'src', 'action', 'formaction', 'xlink:href', 'xlink_href']);
|
|
32
|
+
const URL_ATTRIBUTES = new Set(['href', 'src', 'data', 'action', 'formaction', 'xlink:href', 'xlink_href']);
|
|
33
33
|
|
|
34
34
|
/** The attributes of `attrs` that are not binding attributes. */
|
|
35
35
|
export function withoutBindingAttributes(attrs) {
|
|
@@ -65,6 +65,9 @@ export function requireNoScriptAttributes(node, attrs, prefixes = []) {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
+
if (attrs.onEnd != null && (node.nodeTag.toLowerCase() !== 'transformpane' || !node._getMeta('gramlot_component')?.parameters?.onEnd)) {
|
|
69
|
+
throw new Error('onEnd is only supported on transformPane');
|
|
70
|
+
}
|
|
68
71
|
if (attrs.onClose != null && !node.parentNode?._getMeta('gramlot_component')?.childParameters?.onClose) {
|
|
69
72
|
throw new Error('onClose is only supported on a tab/stack panel');
|
|
70
73
|
}
|
|
@@ -64,7 +64,7 @@ export class DragDrop {
|
|
|
64
64
|
}
|
|
65
65
|
const session = this.#session = {record, wires, effectAllowed, phase: 'active',
|
|
66
66
|
tags: [declaredTags, prepared.dragValues.dragTags].filter(Boolean).join(','),
|
|
67
|
-
endTopic: this.#renderer.binding.
|
|
67
|
+
endTopic: this.#renderer.binding.subscriptions.topicFor(record.node, 'endDrag'),
|
|
68
68
|
source: {pageId: this.#renderer.binding.gramlot.pageId ?? null,
|
|
69
69
|
sourcePath: record.node.fullpath, itemPath: prepared.path ?? null}, preview: null, release: null};
|
|
70
70
|
event.dataTransfer.clearData();
|
|
@@ -144,8 +144,9 @@ export class DragDrop {
|
|
|
144
144
|
event.preventDefault();
|
|
145
145
|
if (this.#session.phase !== 'active') return;
|
|
146
146
|
const session = this.#session;
|
|
147
|
+
let target;
|
|
147
148
|
try {
|
|
148
|
-
|
|
149
|
+
target = this.#target(event); // Revalidate using current Data and declarations.
|
|
149
150
|
if (this.#session !== session) { event.dataTransfer.dropEffect = 'none'; return; }
|
|
150
151
|
session.phase = 'dropped';
|
|
151
152
|
this.#clearPayload();
|
|
@@ -158,7 +159,7 @@ export class DragDrop {
|
|
|
158
159
|
session.phase = 'rejected';
|
|
159
160
|
this.#clearPayload();
|
|
160
161
|
}
|
|
161
|
-
this.#report(error);
|
|
162
|
+
if (!target || this.#renderer.records.has(target.record.node)) this.#report(error);
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
165
|
|
|
@@ -203,7 +204,7 @@ export class DragDrop {
|
|
|
203
204
|
.catch(error => this.#report(error));
|
|
204
205
|
}
|
|
205
206
|
|
|
206
|
-
#report(error) {
|
|
207
|
+
#report(error) { this.#renderer.binding.reportError(error, 'Drag and drop failed'); }
|
|
207
208
|
|
|
208
209
|
dispose() {
|
|
209
210
|
this.#clearSession();
|
|
@@ -61,7 +61,7 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
61
61
|
renderedItem(node: SourceBagNode, item: unknown, runtimeAttrs: Record<string, unknown>,
|
|
62
62
|
opts?: {tag?: string; document?: DomDocument}): any;
|
|
63
63
|
/** Validate a detached candidate Source without changing the observed Source. */
|
|
64
|
-
validateCandidate(block: SourceBag, options?: {replacingNode?: SourceBagNode | null}):
|
|
64
|
+
validateCandidate(block: SourceBag, options?: {replacingNode?: SourceBagNode | null}): SourceBag;
|
|
65
65
|
/** Suspend rendering for a mounted branch; the Source keeps changing normally. */
|
|
66
66
|
freeze(node: SourceBagNode): void;
|
|
67
67
|
/** Resume the whole branch and build its current Source once. */
|
|
@@ -73,7 +73,18 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
73
73
|
/** Build an inserted node and report the build to the binding runtime. */
|
|
74
74
|
insert(node: SourceBagNode): void;
|
|
75
75
|
/** Build the DOM of a node inside `container`, before `before`. */
|
|
76
|
-
buildNode(node: SourceBagNode, container: DomNode, before?: DomNode | null, parent?: unknown):
|
|
76
|
+
buildNode(node: SourceBagNode, container: DomNode, before?: DomNode | null, parent?: unknown): {
|
|
77
|
+
node: SourceBagNode;
|
|
78
|
+
binding: unknown;
|
|
79
|
+
container: DomNode;
|
|
80
|
+
parent: unknown;
|
|
81
|
+
children: Set<SourceBagNode>;
|
|
82
|
+
cleanup: Array<() => void>;
|
|
83
|
+
/** Element records have element; structural fragments have start/end markers. */
|
|
84
|
+
element?: DomElement;
|
|
85
|
+
start?: DomNode;
|
|
86
|
+
end?: DomNode;
|
|
87
|
+
};
|
|
77
88
|
/** Set the container of a render record and of its children. */
|
|
78
89
|
assignContainer(record: unknown, container: DomNode): void;
|
|
79
90
|
/** Apply a Source update event to the DOM of a node. */
|
|
@@ -7,7 +7,7 @@ import {callLogic, invokeHook} from '../binding/hooks.js';
|
|
|
7
7
|
*/
|
|
8
8
|
import {BuilderBase, SourceBag, sourceTarget} from '@genrojs/builders';
|
|
9
9
|
import {HtmlElement} from '../view/html.js';
|
|
10
|
-
import {ControlAdapter, RadioGroups, SelectControl} from '../view/controls.js';
|
|
10
|
+
import {ControlAdapter, RadioControl, RadioGroups, SelectControl} from '../view/controls.js';
|
|
11
11
|
import {ButtonBinding} from '../view/button.js';
|
|
12
12
|
import {MenuBinding} from '../view/menu.js';
|
|
13
13
|
import {NativeEventBinding} from '../view/events.js';
|
|
@@ -17,7 +17,7 @@ import {GramlotBuilderBag, GramlotBuilderBagNode} from '../builder/source.js';
|
|
|
17
17
|
import {BindingRuntime} from '../binding/runtime.js';
|
|
18
18
|
import {requireInstallable} from '../binding/installation.js';
|
|
19
19
|
import {GramlotHtmlRenderer} from './gramlot-html-renderer.js';
|
|
20
|
-
import {displayItem} from './attributes.js';
|
|
20
|
+
import {displayItem, XHTML_NS} from './attributes.js';
|
|
21
21
|
import {DragPreparation} from './drag-preparation.js';
|
|
22
22
|
import {DragDrop} from './drag-drop.js';
|
|
23
23
|
|
|
@@ -48,6 +48,7 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
48
48
|
this.source = source;
|
|
49
49
|
this.destination = destination;
|
|
50
50
|
this.html = new HtmlElement({metadataAttributes: ['__ref'],
|
|
51
|
+
reportError: (node, error, title) => { if (this.records.has(node)) binding.reportError(error, title); },
|
|
51
52
|
callLogic: (node, name, keywords) => {
|
|
52
53
|
const {group, method} = binding.gramlot.src.logicRegistry.resolve(name, node);
|
|
53
54
|
return method.call(group, node, keywords);
|
|
@@ -116,7 +117,7 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
116
117
|
this.#presentationDefaults.set(node, Object.fromEntries(Object.entries(attrs)
|
|
117
118
|
.filter(([name]) => Object.hasOwn(declared, name) && component.presentationDefaults.some(prefix => name.startsWith(prefix)))));
|
|
118
119
|
}
|
|
119
|
-
if (
|
|
120
|
+
if (this.html.hasLabelbox(node) || component?.presentationDefaults.length) {
|
|
120
121
|
const ancestors = [];
|
|
121
122
|
for (let parent = node.parentNode; parent; parent = parent.parentNode) {
|
|
122
123
|
if (this.#presentationDefaults.has(parent)) ancestors.unshift(this.#presentationDefaults.get(parent));
|
|
@@ -206,11 +207,14 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
206
207
|
// cleanup removes, listeners included (ASTRA-06).
|
|
207
208
|
this.records.set(node, record);
|
|
208
209
|
this.elements.set(record.element, record);
|
|
210
|
+
this.elements.set(record.presentation, record);
|
|
209
211
|
const control = ControlAdapter.for(record.binding, record);
|
|
212
|
+
// An input can acquire/change its adapter through type while its DOM record survives.
|
|
213
|
+
if (control || (record.element.namespaceURI === XHTML_NS && record.element.localName === 'input'))
|
|
214
|
+
record.cleanup.push(() => record.control?.detach());
|
|
210
215
|
if (control) {
|
|
211
216
|
record.control = control;
|
|
212
217
|
control.attach();
|
|
213
|
-
record.cleanup.push(() => control.detach());
|
|
214
218
|
this.#projectControl(record, node, attrs, null);
|
|
215
219
|
}
|
|
216
220
|
const button = ButtonBinding.for(record.binding, record);
|
|
@@ -233,7 +237,7 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
233
237
|
child.container = record.element;
|
|
234
238
|
record.children.add(child.node);
|
|
235
239
|
}
|
|
236
|
-
return record.
|
|
240
|
+
return record.presentation;
|
|
237
241
|
}
|
|
238
242
|
|
|
239
243
|
/**
|
|
@@ -444,7 +448,7 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
444
448
|
let before = parent?.end ?? null;
|
|
445
449
|
for (let i = siblings.indexOf(node) + 1; i < siblings.length; i++) {
|
|
446
450
|
const record = this.records.get(siblings[i]);
|
|
447
|
-
if (record) { before = record.
|
|
451
|
+
if (record) { before = record.presentation ?? record.start; break; }
|
|
448
452
|
}
|
|
449
453
|
this.buildNode(node, container, before, parent);
|
|
450
454
|
}
|
|
@@ -502,7 +506,7 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
502
506
|
if ((event === 'upd_attrs' || scalarValueUpdate) && record.element && this.html.matches(record, node)) {
|
|
503
507
|
if (node.nodeTag) this.html.validate(node, node._getMeta('subbuilder') ? node.parentBag._builder : node.builder);
|
|
504
508
|
this.project(node);
|
|
505
|
-
// A
|
|
509
|
+
// A remaining shape change rebuilt the element inside project.
|
|
506
510
|
if (event === 'upd_attrs' && this.records.get(node) === record) {
|
|
507
511
|
this.references?.remove(node);
|
|
508
512
|
this.references?.register(node, record.element);
|
|
@@ -517,18 +521,27 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
517
521
|
* adaptation as the first render, by the node's own renderer (R16). A node without an element
|
|
518
522
|
* (not built yet, frozen before its first build, a fragment) is left alone; under freeze the
|
|
519
523
|
* elements already built are projected. `change` is the DataChange that asked for it, or null.
|
|
520
|
-
*
|
|
524
|
+
* Native input.type and input/select.multiple use setters. Other shape changes rebuild, keeping
|
|
521
525
|
* its NodeBinding; under freeze the rebuild waits for the thaw (C04.1, D7). The resolved projection
|
|
522
526
|
* (runtimeValues, then `==`) is computed once and is what every consumer reads, the rebuild included.
|
|
523
527
|
*/
|
|
524
528
|
project(node, change = null) {
|
|
525
529
|
const record = this.records.get(node);
|
|
526
|
-
if (!record?.element) return;
|
|
530
|
+
if (!record?.element || !this.attached(node)) return;
|
|
527
531
|
const renderer = this.getRender(node.builder);
|
|
528
532
|
const previousDefaults = this.#presentationDefaults.get(node);
|
|
529
533
|
const [value, runtimeAttrs] = node.rootBuilder.runtimeValues(node);
|
|
530
534
|
const [, resolvedAttrs] = renderer._handleMeta(node, runtimeAttrs);
|
|
531
535
|
const resolved = this.#resolvedAttributes.get(node);
|
|
536
|
+
const typeChanged = record.element.namespaceURI === XHTML_NS && record.element.localName === 'input'
|
|
537
|
+
&& !Object.is(record.resolved.type, resolved.type);
|
|
538
|
+
const multipleChanged = record.element.namespaceURI === XHTML_NS
|
|
539
|
+
&& ['input', 'select'].includes(record.element.localName)
|
|
540
|
+
&& Boolean(record.resolved.multiple) !== Boolean(resolved.multiple);
|
|
541
|
+
const previousGroup = record.resolved.group;
|
|
542
|
+
const groupChanged = record.control instanceof RadioControl
|
|
543
|
+
&& !Object.is(previousGroup ?? null, resolved.group ?? null);
|
|
544
|
+
if ((typeChanged || multipleChanged || groupChanged) && this.#isFrozen(node)) return;
|
|
532
545
|
if (record.shape !== ControlAdapter.shape(record.element, resolved)) {
|
|
533
546
|
if (this.#isFrozen(node)) return;
|
|
534
547
|
this.#rebuildAttributes.set(node, resolved);
|
|
@@ -536,6 +549,18 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
536
549
|
finally { this.#rebuildAttributes.delete(node); }
|
|
537
550
|
return;
|
|
538
551
|
}
|
|
552
|
+
const Control = typeChanged ? ControlAdapter.classFor(record.element, resolved) : null;
|
|
553
|
+
const replaceControl = typeChanged && (record.control?.constructor ?? null) !== Control;
|
|
554
|
+
const keepDraft = (typeChanged || (multipleChanged && record.element.localName === 'input'))
|
|
555
|
+
&& !replaceControl && record.control
|
|
556
|
+
&& Object.is(record.resolved.value, resolved.value);
|
|
557
|
+
if (replaceControl) {
|
|
558
|
+
record.control?.detach();
|
|
559
|
+
record.control = null;
|
|
560
|
+
}
|
|
561
|
+
if (groupChanged && !replaceControl && resolved.group != null && node.getAttr('name') != null) {
|
|
562
|
+
throw new TypeError(`${node.nodeTag} '${node.label}': name and group are two names`);
|
|
563
|
+
}
|
|
539
564
|
record.resolved = resolved;
|
|
540
565
|
let attrs = node._getMeta('subbuilder') ? resolvedAttrs : renderer.adaptAttrs(resolvedAttrs);
|
|
541
566
|
const branch = node.value instanceof SourceBag;
|
|
@@ -547,7 +572,17 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
547
572
|
}
|
|
548
573
|
attrs = this.componentAttributes(node, attrs);
|
|
549
574
|
this.html.update(record, node, attrs, branch ? attrs._text : text, resolved.visible ?? null);
|
|
550
|
-
|
|
575
|
+
if (replaceControl && Control) {
|
|
576
|
+
record.control = new Control(record.binding, record);
|
|
577
|
+
record.control.attach();
|
|
578
|
+
}
|
|
579
|
+
if (groupChanged && !replaceControl) {
|
|
580
|
+
record.control.refresh(previousGroup ?? null);
|
|
581
|
+
// Reset writes can synchronously change values or remove this node. Re-read Data.
|
|
582
|
+
if (this.records.get(node) === record && !record.binding.closed) this.project(node);
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
if (!keepDraft) this.#projectControl(record, node, attrs, change);
|
|
551
586
|
record.control?.refresh();
|
|
552
587
|
record.button?.refresh();
|
|
553
588
|
record.menu?.refresh();
|
|
@@ -572,7 +607,7 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
572
607
|
let inherited = changed;
|
|
573
608
|
if (component?.presentationDefaults.length) {
|
|
574
609
|
inherited = new Set([...changed].filter(name => !Object.hasOwn(declared, name)));
|
|
575
|
-
} else if (
|
|
610
|
+
} else if (this.html.hasLabelbox(child)
|
|
576
611
|
&& [...changed].some(name => !Object.hasOwn(declared, name))) {
|
|
577
612
|
this.project(child);
|
|
578
613
|
}
|
|
@@ -670,7 +705,7 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
670
705
|
|
|
671
706
|
#rebuild(node) {
|
|
672
707
|
const record = this.records.get(node);
|
|
673
|
-
const before = record.
|
|
708
|
+
const before = record.presentation?.nextSibling ?? record.end?.nextSibling ?? null;
|
|
674
709
|
const container = record.container;
|
|
675
710
|
const parent = record.parent;
|
|
676
711
|
let removeError = null;
|
|
@@ -712,7 +747,8 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
|
712
747
|
}
|
|
713
748
|
this.references?.remove(node);
|
|
714
749
|
if (record.element) this.elements.delete(record.element);
|
|
715
|
-
record.
|
|
750
|
+
if (record.presentation) this.elements.delete(record.presentation);
|
|
751
|
+
record.presentation?.remove();
|
|
716
752
|
record.start?.remove();
|
|
717
753
|
record.end?.remove();
|
|
718
754
|
record.parent?.children.delete(node);
|
package/src/server/index-page.js
CHANGED
|
@@ -20,14 +20,14 @@ export class IndexPage extends FramePage {
|
|
|
20
20
|
}
|
|
21
21
|
left(pane) {
|
|
22
22
|
pane.setAttr({width: '240px', splitter: true, drawer: true, drawer_label: 'Navigation'});
|
|
23
|
-
pane.tree({node_label: 'tree', storepath:
|
|
24
|
-
labelAttribute: 'title', hideValues: true, selectedPath:
|
|
23
|
+
pane.tree({node_label: 'tree', storepath: '.navigation',
|
|
24
|
+
labelAttribute: 'title', hideValues: true, selectedPath: '^.navigationSelection'});
|
|
25
25
|
}
|
|
26
26
|
center(pane) {
|
|
27
|
-
pane.tabContainer({node_label: 'tabs', height: '100%', selectedPage:
|
|
27
|
+
pane.tabContainer({node_label: 'tabs', height: '100%', selectedPage: '^.active'});
|
|
28
28
|
}
|
|
29
29
|
behavior(shell) {
|
|
30
|
-
shell.dataController({func: 'indexMount', _onStart: true
|
|
30
|
+
shell.dataController({func: 'indexMount', _onStart: true});
|
|
31
31
|
}
|
|
32
32
|
index_panel(pane, {selection}) { this.panel(pane, selection.getNode('#0')); }
|
|
33
33
|
panel(pane, node) {
|
package/src/view/controls.js
CHANGED
|
@@ -10,14 +10,14 @@ import {Bag} from '@genrojs/bag';
|
|
|
10
10
|
import {XHTML_NS} from '../renderer/attributes.js';
|
|
11
11
|
import {callLogic, invokeHook} from '../binding/hooks.js';
|
|
12
12
|
|
|
13
|
-
//
|
|
13
|
+
// Native input.type and input/select.multiple use setters; radio group updates membership.
|
|
14
14
|
const CONTROL_TAGS = new Set(['input', 'select', 'textarea']);
|
|
15
|
-
const REBUILD_ATTRIBUTES = ['type', 'multiple'
|
|
15
|
+
const REBUILD_ATTRIBUTES = ['type', 'multiple'];
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
function resolved(
|
|
19
|
-
const value = node.getAttr(name);
|
|
20
|
-
return node.pointerType(value) ? node.getRelativeData(value) :
|
|
17
|
+
/** Read current pointer Data, including during freeze; expressions use the resolved projection. */
|
|
18
|
+
function resolved(control, name) {
|
|
19
|
+
const node = control.node, value = node.getAttr(name);
|
|
20
|
+
return node.pointerType(value) ? node.getRelativeData(value) : control.resolved[name];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export class ControlAdapter {
|
|
@@ -59,14 +59,18 @@ export class ControlAdapter {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
62
|
+
* Attributes still requiring reconstruction, as one comparable string, or null for other
|
|
63
|
+
* elements. Native input.type and input/select.multiple use setters; radio group changes
|
|
64
|
+
* update the existing membership and never contribute to this signature.
|
|
64
65
|
* `attrs` are the attributes of the renderer's resolved projection (`^`, `=` and `==` resolved).
|
|
65
66
|
*/
|
|
66
67
|
static shape(element, attrs) {
|
|
67
|
-
if (element?.constructor.gramlotComponent?.parameters.value?.binding === 'twoWay' && element.control.type === 'radio') return JSON.stringify([
|
|
68
|
+
if (element?.constructor.gramlotComponent?.parameters.value?.binding === 'twoWay' && element.control.type === 'radio') return JSON.stringify([]);
|
|
68
69
|
if (element?.namespaceURI !== XHTML_NS || !CONTROL_TAGS.has(element.localName)) return null;
|
|
69
|
-
return JSON.stringify(REBUILD_ATTRIBUTES.
|
|
70
|
+
return JSON.stringify(REBUILD_ATTRIBUTES.filter(name =>
|
|
71
|
+
(name !== 'type' || element.localName !== 'input') &&
|
|
72
|
+
(name !== 'multiple' || !['input', 'select'].includes(element.localName)))
|
|
73
|
+
.map(name => attrs[name] ?? null));
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
constructor(binding, record) {
|
|
@@ -100,7 +104,11 @@ export class ControlAdapter {
|
|
|
100
104
|
this.#pending = true;
|
|
101
105
|
return;
|
|
102
106
|
}
|
|
103
|
-
|
|
107
|
+
// A synchronous Data rule can reject an edit and restore the previous
|
|
108
|
+
// projection. The control may already hold the rejected candidate.
|
|
109
|
+
if (this.constructor.preservesUnchangedValue && this.#hasProjectedValue
|
|
110
|
+
&& this.same(this.#projectedValue, value)
|
|
111
|
+
&& (!this.#committing || this.same(this.read(), value))) return;
|
|
104
112
|
this.#projectedValue = value;
|
|
105
113
|
this.#hasProjectedValue = true;
|
|
106
114
|
if (this.#committing && this.same(this.read(), value)) return;
|
|
@@ -380,15 +388,28 @@ export class RadioControl extends CheckboxControl {
|
|
|
380
388
|
}
|
|
381
389
|
|
|
382
390
|
/**
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
* meets another button on in the new scope raises before any effect, as at the join (P11).
|
|
391
|
+
* A changed group clears writable selections in both scopes without replacing the control.
|
|
392
|
+
* Membership moves before Data writes so synchronous binding projections see the new group.
|
|
393
|
+
* Form-owner-only moves keep their existing initial-conflict rule.
|
|
387
394
|
*/
|
|
388
|
-
refresh() {
|
|
389
|
-
|
|
390
|
-
const group = this.resolved.group;
|
|
395
|
+
refresh(previousGroup = this.resolved.group) {
|
|
396
|
+
const group = this.resolved.group ?? null;
|
|
391
397
|
const form = formNode(this.node);
|
|
398
|
+
if (!Object.is(previousGroup ?? null, group)) {
|
|
399
|
+
const affected = new Set([this, ...this.groups.peers(this),
|
|
400
|
+
...(group === null ? [] : this.groups.peersOf(group, form))]);
|
|
401
|
+
this.groups.leave(this);
|
|
402
|
+
this.#name = group === null ? null : this.groups.join(this, group, form);
|
|
403
|
+
if (this.#name === null) this.element.removeAttribute('name');
|
|
404
|
+
else this.element.setAttribute('name', this.#name);
|
|
405
|
+
for (const peer of affected) {
|
|
406
|
+
if (this.binding.closed || !this.binding.runtime.renderer.attached(this.node)) return;
|
|
407
|
+
if (peer.binding.closed || !peer.binding.runtime.renderer.attached(peer.node)) continue;
|
|
408
|
+
peer.binding.runtime.renderer.html.writeParameter(peer.node, 'value', false);
|
|
409
|
+
}
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
if (this.#name === null) return;
|
|
392
413
|
if (this.groups.nameOf(group, form) === this.#name) return;
|
|
393
414
|
this.#requireSingleTrue(group, form);
|
|
394
415
|
this.groups.leave(this);
|
|
@@ -402,7 +423,7 @@ export class RadioControl extends CheckboxControl {
|
|
|
402
423
|
*/
|
|
403
424
|
#requireSingleTrue(group, form) {
|
|
404
425
|
const node = this.node;
|
|
405
|
-
if (resolved(
|
|
426
|
+
if (resolved(this, 'value') && this.groups.peersOf(group, form).some(peer => !peer.binding.closed && peer.read())) {
|
|
406
427
|
throw new Error(`${node.nodeTag} '${node.label}': several true values in radio group '${group}'`);
|
|
407
428
|
}
|
|
408
429
|
}
|
|
@@ -439,7 +460,7 @@ export class RadioControl extends CheckboxControl {
|
|
|
439
460
|
if (this.binding.closed) return;
|
|
440
461
|
if (peer.binding.closed) continue;
|
|
441
462
|
if (peer.element.checked) peer.element.checked = false;
|
|
442
|
-
if (resolved(peer
|
|
463
|
+
if (resolved(peer, 'value')) peer.commit(null);
|
|
443
464
|
}
|
|
444
465
|
}
|
|
445
466
|
}
|
|
@@ -578,6 +599,7 @@ function componentContext(adapter) {
|
|
|
578
599
|
locale:app.locale, timeZone:app.timeZone, createDecimal, isDecimal, getDecimalLibrary,
|
|
579
600
|
publish:(topic, payload) => node.publish(topic, payload),
|
|
580
601
|
isActive:() => !binding.closed,
|
|
602
|
+
reportError:(error, title) => { if (!binding.closed) binding.runtime.reportError(error, title); },
|
|
581
603
|
callLogic:(name, keywords) => callLogic(binding.runtime, node, name, keywords),
|
|
582
604
|
format:(value, options) => app.format(value, options), invoke,
|
|
583
605
|
remote:(method, keywords, signal) => app.rpc.call('data', method, keywords, {signal}),
|
|
@@ -599,7 +621,7 @@ function componentContext(adapter) {
|
|
|
599
621
|
if (ok) for (const patch of result.datachanges) node.getRelativeData('.').update(patch);
|
|
600
622
|
const attribute = ok ? 'validate_onAccept' : 'validate_onReject';
|
|
601
623
|
if (rules[attribute]) {
|
|
602
|
-
const report = error =>
|
|
624
|
+
const report = error => { if (!binding.closed) binding.runtime.reportError(error, 'Validation callback failed'); };
|
|
603
625
|
try {
|
|
604
626
|
const validations = Object.fromEntries(Object.entries(rules).map(([key, value]) => [key.slice(9), value]));
|
|
605
627
|
const returned = invoke(attribute, rules[attribute], {value:result.value, result, validations, userChange:true});
|
|
@@ -614,7 +636,10 @@ function componentContext(adapter) {
|
|
|
614
636
|
};
|
|
615
637
|
}
|
|
616
638
|
function commitComponent(host, outcome, commit) {
|
|
639
|
+
const context = host.pageContext;
|
|
617
640
|
const finish = result => { if (result.ok && result.isCurrent()) { commit(result); host.finishValidation(result); } };
|
|
618
|
-
if (outcome instanceof Promise) outcome.then(finish).catch(error =>
|
|
619
|
-
else
|
|
641
|
+
if (outcome instanceof Promise) outcome.then(finish).catch(error => context.reportError(error, 'Field update failed'));
|
|
642
|
+
else {
|
|
643
|
+
try { finish(outcome); } catch (error) { context.reportError(error, 'Field update failed'); }
|
|
644
|
+
}
|
|
620
645
|
}
|
package/src/view/html.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {createLabelbox, projectLabelbox, labelboxStyle} from './labelbox.js';
|
|
2
|
+
import {randomId} from '../random-id.js';
|
|
1
3
|
import {SourceBag, META_ATTRS, resolveRenderTag, sourceAttributeItems, SvgBuilder, pointerTransform} from '@genrojs/builders';
|
|
2
4
|
import {ControlAdapter} from './controls.js';
|
|
3
5
|
import {SVG_NS, XHTML_NS} from '../renderer/attributes.js';
|
|
@@ -36,9 +38,10 @@ function domPropertyName(name) {
|
|
|
36
38
|
* names and style arrive adapted by the renderers (GramlotHtmlRenderer, GramlotSvgRenderer).
|
|
37
39
|
*/
|
|
38
40
|
export class HtmlElement {
|
|
39
|
-
constructor({metadataAttributes = [], invokeScript = null, callLogic = null} = {}) {
|
|
41
|
+
constructor({metadataAttributes = [], invokeScript = null, callLogic = null, reportError = null} = {}) {
|
|
40
42
|
this.invokeScript = invokeScript;
|
|
41
43
|
this.callLogic = callLogic;
|
|
44
|
+
this.reportError = reportError;
|
|
42
45
|
this.metadataAttributes = new Set([...META_ATTRS, '_text', ...metadataAttributes]);
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -58,6 +61,7 @@ export class HtmlElement {
|
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
validate(node, builder = node.builder) {
|
|
64
|
+
this.validateLabelbox(node);
|
|
61
65
|
const branch = node.value instanceof SourceBag;
|
|
62
66
|
const text = branch ? node.getAttr('_text') : node.value;
|
|
63
67
|
if (text != null && !['string', 'number', 'boolean'].includes(typeof text)) {
|
|
@@ -79,6 +83,27 @@ export class HtmlElement {
|
|
|
79
83
|
builder.validateNode(node, {value: text, attrs: declaredAttrs, childTags});
|
|
80
84
|
}
|
|
81
85
|
|
|
86
|
+
hasLabelbox(node) {
|
|
87
|
+
const component = this.definition(node).meta.gramlot_component;
|
|
88
|
+
if (component?.labelbox) return true;
|
|
89
|
+
if (component?.presentationDefaults.length) return Object.hasOwn(node.attr, 'lbl');
|
|
90
|
+
return Object.keys(node.attr).some(name => name === 'lbl' || name.startsWith('lbl_') || name.startsWith('box_'));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
validateLabelbox(node) {
|
|
94
|
+
if (!this.hasLabelbox(node)) return;
|
|
95
|
+
const {tag,namespace} = this.definition(node);
|
|
96
|
+
if ((namespace !== XHTML_NS && tag !== 'svg') || ['html','head','body','style','script','link','meta','title','base','tr','td','th','thead','tbody','tfoot','col','colgroup','caption','option','optgroup','li','dt','dd','source','track','param','area'].includes(tag))
|
|
97
|
+
throw new TypeError('Labelbox requires content that can be placed in an HTML flow container');
|
|
98
|
+
const parent = node.parentNode;
|
|
99
|
+
if (parent?.nodeTag) {
|
|
100
|
+
const definition = this.definition(parent);
|
|
101
|
+
if ((definition.namespace !== XHTML_NS && definition.tag !== 'foreignObject')
|
|
102
|
+
|| ['table','thead','tbody','tfoot','tr','colgroup','select','optgroup','ul','ol','dl','p','button','label'].includes(definition.tag))
|
|
103
|
+
throw new TypeError('Labelbox requires an HTML flow container');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
82
107
|
create(node, document, tag = null, attrs = node.attr, visible = null) {
|
|
83
108
|
const {tag: defaultTag, namespace, meta} = this.definition(node);
|
|
84
109
|
tag ??= defaultTag;
|
|
@@ -95,6 +120,7 @@ export class HtmlElement {
|
|
|
95
120
|
}
|
|
96
121
|
if (meta.gramlot_component?.sourceContext) {
|
|
97
122
|
element.setSourceContext({
|
|
123
|
+
reportError: (error, title) => this.reportError(node, error, title),
|
|
98
124
|
publish: (topic, payload) => node.publish(topic, payload),
|
|
99
125
|
writeParameter: (name, value) => this.writeParameter(node, name, value),
|
|
100
126
|
callLogic: (name, keywords) => this.callLogic(node, name, keywords),
|
|
@@ -102,7 +128,18 @@ export class HtmlElement {
|
|
|
102
128
|
}
|
|
103
129
|
const text = document.createTextNode(this.text(node));
|
|
104
130
|
if (namespace !== XHTML_NS || !meta.void) element.append(text);
|
|
105
|
-
const record = {element, text, tag};
|
|
131
|
+
const record = {element, text, tag, presentation: element};
|
|
132
|
+
if (this.hasLabelbox(node)) {
|
|
133
|
+
this.validateLabelbox(node);
|
|
134
|
+
const controlBox = document.createElement('div'); controlBox.append(element);
|
|
135
|
+
record.labelbox = createLabelbox(document,controlBox);
|
|
136
|
+
record.presentation = record.labelbox.box;
|
|
137
|
+
record.labelId = `gramlot-label-${randomId()}`;
|
|
138
|
+
record.controlId = `gramlot-control-${randomId()}`;
|
|
139
|
+
const style = document.createElement('style'); style.textContent = labelboxStyle;
|
|
140
|
+
record.presentation.prepend(style);
|
|
141
|
+
if (meta.gramlot_component?.labelbox) element.setLabelbox(record.labelbox);
|
|
142
|
+
}
|
|
106
143
|
this.update(record, node, attrs, DEFAULT_TEXT, visible);
|
|
107
144
|
return record;
|
|
108
145
|
}
|
|
@@ -148,6 +185,8 @@ export class HtmlElement {
|
|
|
148
185
|
}
|
|
149
186
|
}
|
|
150
187
|
const {element, text} = record;
|
|
188
|
+
if (this.hasLabelbox(node) && !record.labelbox)
|
|
189
|
+
throw new TypeError('Declare lbl or box_* when creating an experimental HTML labelbox');
|
|
151
190
|
const isHtml = element.namespaceURI === XHTML_NS;
|
|
152
191
|
const renderAttributes = this.definition(node).meta.render_attributes ?? {};
|
|
153
192
|
const previous = record.attrs ?? {};
|
|
@@ -159,21 +198,35 @@ export class HtmlElement {
|
|
|
159
198
|
const parent = node.parentNode;
|
|
160
199
|
if (parent?._getMeta('gramlot_component')?.childParameters) {
|
|
161
200
|
const Parent = element.ownerDocument.defaultView.customElements.get(parent._getMeta('render_tag'));
|
|
162
|
-
attrs = Parent.projectChild(
|
|
201
|
+
attrs = Parent.projectChild(record.presentation, attrs, {
|
|
202
|
+
label: node.label,
|
|
163
203
|
adapt,
|
|
164
204
|
invoke: (name, code, keywords) => this.invokeScript(node, name, code, keywords),
|
|
205
|
+
reportError: (error, title) => this.reportError(node, error, title),
|
|
165
206
|
publish: (topic, payload) => node.publish(topic, payload),
|
|
166
207
|
publishParent: (topic, payload) => parent.publish(topic, payload),
|
|
167
208
|
writeParameter: (name, value) => this.writeParameter(node, name, value),
|
|
168
209
|
remove: () => node.parentBag.popNode(node.label),
|
|
169
210
|
});
|
|
170
211
|
}
|
|
212
|
+
if (record.labelbox) {
|
|
213
|
+
record.labelbox.box.style.visibility = '';
|
|
214
|
+
projectLabelbox(record.labelbox, attrs, adapt);
|
|
215
|
+
}
|
|
171
216
|
if (this.definition(node).meta.gramlot_component) {
|
|
172
217
|
if (this.definition(node).meta.gramlot_component.bagStore) {
|
|
173
218
|
element.setStoreBag(node.getRelativeData(node.getAttr('storepath')));
|
|
174
219
|
}
|
|
175
220
|
attrs = element.projectAttributes(attrs, adapt);
|
|
176
221
|
}
|
|
222
|
+
if (record.labelbox) {
|
|
223
|
+
attrs = Object.fromEntries(Object.entries(attrs).filter(([name]) =>
|
|
224
|
+
name !== 'lbl' && !name.startsWith('lbl_') && !name.startsWith('box_')));
|
|
225
|
+
if (attrs.slot != null) record.presentation.setAttribute('slot', attrs.slot);
|
|
226
|
+
else if (record.presentationSlot != null) record.presentation.removeAttribute('slot');
|
|
227
|
+
record.presentationSlot = attrs.slot;
|
|
228
|
+
delete attrs.slot;
|
|
229
|
+
}
|
|
177
230
|
attrs = Object.fromEntries(sourceAttributeItems({...attrs, ...renderAttributes}));
|
|
178
231
|
const controlled = ControlAdapter.classFor(element, attrs) !== null;
|
|
179
232
|
if (textValue === DEFAULT_TEXT) textValue = this.text(node);
|
|
@@ -181,10 +234,22 @@ export class HtmlElement {
|
|
|
181
234
|
if (text.data !== nextText) text.data = nextText;
|
|
182
235
|
const keys = [...new Set([...Object.keys(previous), ...Object.keys(attrs)])];
|
|
183
236
|
// The browser reads `sandbox` when `src` or `srcdoc` starts a navigation: `sandbox` is written first.
|
|
184
|
-
keys.sort((a, b) => (b === 'sandbox') - (a === 'sandbox')
|
|
237
|
+
keys.sort((a, b) => (b === 'sandbox') - (a === 'sandbox')
|
|
238
|
+
|| (isHtml && element.localName === 'input' ? (b === 'type') - (a === 'type') : 0));
|
|
185
239
|
for (const key of keys) {
|
|
186
240
|
if (this.metadataAttributes.has(key) || ['ask', '_ask'].includes(key) || (controlled && key === 'value')) continue;
|
|
187
241
|
const value = attrs[key];
|
|
242
|
+
if (isHtml && key === 'multiple' && ['input', 'select'].includes(element.localName)) {
|
|
243
|
+
if (element.multiple !== Boolean(value)) element.multiple = Boolean(value);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (isHtml && element.localName === 'input' && key === 'type') {
|
|
247
|
+
if (!Object.is(previous.type, value)) {
|
|
248
|
+
if (value == null) element.removeAttribute('type');
|
|
249
|
+
else element.type = String(value);
|
|
250
|
+
}
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
188
253
|
const attrName = key;
|
|
189
254
|
const propertyName = domPropertyName(attrName);
|
|
190
255
|
const isBoolean = isHtml && BOOLEAN_PROPERTIES.has(propertyName)
|
|
@@ -212,6 +277,22 @@ export class HtmlElement {
|
|
|
212
277
|
}
|
|
213
278
|
record.visible = visible;
|
|
214
279
|
// Retain what was applied, including metadata, so later updates can remove it.
|
|
280
|
+
if (record.labelbox) {
|
|
281
|
+
const {fieldLabel,labelBox,box} = record.labelbox;
|
|
282
|
+
if (['input','textarea','select','button','output','meter','progress'].includes(record.tag)) {
|
|
283
|
+
if (!element.id) element.id = record.controlId;
|
|
284
|
+
fieldLabel.htmlFor = element.id;
|
|
285
|
+
} else {
|
|
286
|
+
fieldLabel.id = record.labelId;
|
|
287
|
+
if (!this.definition(node).meta.gramlot_component?.labelbox) {
|
|
288
|
+
box.setAttribute('role','group');
|
|
289
|
+
if (labelBox.hidden) box.removeAttribute('aria-labelledby');
|
|
290
|
+
else box.setAttribute('aria-labelledby',fieldLabel.id);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
box.hidden = !!attrs.hidden;
|
|
294
|
+
if (visible === false) box.style.visibility = 'hidden';
|
|
295
|
+
}
|
|
215
296
|
record.attrs = attrs;
|
|
216
297
|
}
|
|
217
298
|
|