@gramlot/gramlot 0.3.7 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/components/editors.js +116527 -0
  2. package/dist/components/inputs.js +24507 -0
  3. package/dist/components/layout.js +1402 -0
  4. package/dist/components/tree.js +24538 -0
  5. package/dist/components/typst.js +4 -0
  6. package/dist/gramlot.js +1442 -625
  7. package/dist/gramlot.min.js +27 -405
  8. package/dist/runtime-notices.json +208 -0
  9. package/dist/typst-worker-source.js +4 -0
  10. package/package.json +36 -3
  11. package/src/binding/hooks.js +14 -0
  12. package/src/binding/providers.js +4 -0
  13. package/src/binding/remote-resolver.js +52 -0
  14. package/src/binding/remote.js +2 -0
  15. package/src/binding/router.js +11 -4
  16. package/src/binding/rpc-resolver.js +14 -93
  17. package/src/binding/runtime.js +10 -4
  18. package/src/components/bases.js +1 -0
  19. package/src/components/border-container.js +46 -23
  20. package/src/components/buttons.js +3 -0
  21. package/src/components/choice-editor.js +17 -3
  22. package/src/components/choices.js +3 -2
  23. package/src/components/code-mirror-engine.js +91 -0
  24. package/src/components/code-mirror.js +88 -0
  25. package/src/components/editor-options.d.ts +9 -0
  26. package/src/components/editor-options.js +21 -0
  27. package/src/components/editors.js +10 -0
  28. package/src/components/html-document.js +56 -0
  29. package/src/components/html-editor.js +68 -0
  30. package/src/components/html-preview.js +33 -0
  31. package/src/components/inputs.js +2 -2
  32. package/src/components/jodit-engine.js +89 -0
  33. package/src/components/markdown-codec.js +35 -0
  34. package/src/components/markdown-document.js +14 -0
  35. package/src/components/markdown-editor.js +68 -0
  36. package/src/components/prose-mirror-engine.js +65 -0
  37. package/src/components/registry.js +6 -4
  38. package/src/components/tree.js +350 -0
  39. package/src/components/typst-client.js +38 -0
  40. package/src/components/typst-preview.js +88 -0
  41. package/src/components/typst-worker.js +49 -0
  42. package/src/components/typst.js +4 -0
  43. package/src/filesystem.d.ts +22 -0
  44. package/src/filesystem.js +122 -0
  45. package/src/ide-documents.js +153 -0
  46. package/src/ide-runtime.d.ts +18 -0
  47. package/src/ide-runtime.js +238 -0
  48. package/src/index-page-runtime.d.ts +7 -8
  49. package/src/index-page-runtime.js +100 -396
  50. package/src/index.d.ts +7 -1
  51. package/src/index.js +5 -1
  52. package/src/navigation-resolver.d.ts +6 -0
  53. package/src/navigation-resolver.js +60 -0
  54. package/src/renderer/attributes.js +2 -1
  55. package/src/renderer/drag-drop-policy.js +48 -0
  56. package/src/renderer/drag-drop.js +213 -0
  57. package/src/renderer/drag-preparation.js +33 -0
  58. package/src/renderer/gramlot-renderer.d.ts +18 -0
  59. package/src/renderer/gramlot-renderer.js +41 -2
  60. package/src/server/frame-page.d.ts +12 -0
  61. package/src/server/frame-page.js +23 -0
  62. package/src/server/gramlot-server.js +2 -1
  63. package/src/server/index-page.d.ts +10 -14
  64. package/src/server/index-page.js +26 -95
  65. package/src/server/page.d.ts +7 -0
  66. package/src/server/page.js +5 -0
  67. package/src/view/button.js +2 -1
  68. package/src/view/controls.js +7 -11
  69. package/src/view/events.js +4 -8
  70. package/src/view/html.js +6 -1
  71. package/tools/gramlot-tools-inspector.js +16 -9
@@ -0,0 +1,48 @@
1
+ /** Declarative eligibility only; gesture routing and Logic callbacks own the remaining checks. */
2
+ export class DragDropPolicy {
3
+ static isTarget(attributes) {
4
+ return attributes.dropTarget === true || Boolean(attributes.dropTargetCb)
5
+ || Object.entries(attributes).some(([name, value]) => name.startsWith('dropTargetCb_') && Boolean(value));
6
+ }
7
+
8
+ /** Handler types are already resolved by the dispatcher; no MIME/name encoding is assumed here. */
9
+ static acceptedTypes(payloadTypes, dropTypes = '', handlerTypes = []) {
10
+ const patterns = dropTypes.split(',').map(type => type.trim()).filter(Boolean).map(pattern => {
11
+ const literalParts = pattern.split('*').map(part => part.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
12
+ return new RegExp(`^${literalParts.join('.*')}$`);
13
+ });
14
+ return payloadTypes.filter(type => type !== 'dragTags'
15
+ && (handlerTypes.includes(type) || patterns.some(pattern => pattern.test(type))));
16
+ }
17
+
18
+ static acceptsTags(dragTags = '', dropTags = '') {
19
+ if (!dropTags.trim()) return true;
20
+ const tags = new Set(dragTags.split(',').map(tag => tag.trim()).filter(Boolean));
21
+ if (!tags.size) return false;
22
+ return dropTags.split(',').some(alternative => alternative.split(' AND ').every(term => {
23
+ term = term.trim();
24
+ if (!term || term === '!') return false;
25
+ return term.startsWith('!') ? !tags.has(term.slice(1)) : tags.has(term);
26
+ }));
27
+ }
28
+
29
+ static acceptsEffect(effectAllowed = 'all', dropEffect = 'move') {
30
+ const effects = {
31
+ all: ['copy', 'move', 'link'], none: [],
32
+ copy: ['copy'], move: ['move'], link: ['link'],
33
+ copyMove: ['copy', 'move'], copyLink: ['copy', 'link'], linkMove: ['link', 'move']
34
+ };
35
+ if (!Object.hasOwn(effects, effectAllowed)) throw new TypeError(`Invalid effectAllowed: ${effectAllowed}`);
36
+ if (!['copy', 'move', 'link'].includes(dropEffect)) throw new TypeError(`Invalid dropEffect: ${dropEffect}`);
37
+ return effects[effectAllowed].includes(dropEffect);
38
+ }
39
+
40
+ /** A true result still requires the destination's dynamic callbacks to pass, including at drop. */
41
+ static evaluate(payloadTypes, dragTags, effectAllowed, target, handlerTypes = []) {
42
+ const types = this.acceptedTypes(payloadTypes, target.dropTypes, handlerTypes);
43
+ const dropEffect = target.dropEffect ?? 'move';
44
+ const accepted = this.isTarget(target) && types.length > 0
45
+ && this.acceptsTags(dragTags, target.dropTags) && this.acceptsEffect(effectAllowed, dropEffect);
46
+ return {accepted, types, dropEffect: accepted ? dropEffect : 'none'};
47
+ }
48
+ }
@@ -0,0 +1,213 @@
1
+ import {toTytx, fromTytx} from '@genrojs/tytx';
2
+ import {DragDropPolicy} from './drag-drop-policy.js';
3
+
4
+ const EVENTS = ['dragstart', 'dragover', 'dragleave', 'drop', 'dragend'];
5
+
6
+ /** One renderer's internal gestures. Other windows/instances and external payloads are not admitted. */
7
+ export class DragDrop {
8
+ #renderer;
9
+ #document;
10
+ #session = null;
11
+ #feedback = null;
12
+ #style = null;
13
+ #hide;
14
+
15
+ constructor(renderer) {
16
+ this.#renderer = renderer;
17
+ this.#document = renderer.destination.ownerDocument;
18
+ for (const name of EVENTS) this.#document.addEventListener(name, this);
19
+ this.#hide = () => this.#finish('none');
20
+ this.#document.defaultView.addEventListener('pagehide', this.#hide);
21
+ }
22
+
23
+ handleEvent(event) {
24
+ if (event.type === 'dragstart') this.#start(event);
25
+ else if (event.type === 'dragend') this.#finish(event.dataTransfer.dropEffect);
26
+ else if (event.type === 'dragleave') this.#clearFeedback();
27
+ else if (event.type === 'dragover') this.#over(event);
28
+ else if (event.type === 'drop') void this.#drop(event);
29
+ }
30
+
31
+ #record(event, predicate) {
32
+ for (const element of event.composedPath()) {
33
+ const record = this.#renderer.elements.get(element);
34
+ if (record && predicate(record.resolved)) return record;
35
+ }
36
+ return null;
37
+ }
38
+
39
+ #context(record, event) {
40
+ return record.node._getMeta('gramlot_component')?.dragSource
41
+ ? record.element.getDragContext(event)
42
+ : {element: record.element, item: undefined, path: undefined};
43
+ }
44
+
45
+ #start(event) {
46
+ const record = this.#record(event, attrs => attrs.draggable === true);
47
+ if (!record) return;
48
+ this.#finish('none');
49
+ try {
50
+ const prepared = this.#renderer.prepareDrag(record.node, event);
51
+ if (!prepared || !record.element.isConnected || this.#renderer.records.get(record.node) !== record) {
52
+ event.preventDefault(); return;
53
+ }
54
+ const context = this.#context(record, event);
55
+ if (!context) { event.preventDefault(); return; }
56
+ const wires = new Map(Object.entries(prepared.dragValues).filter(([type]) => type !== 'dragTags')
57
+ .map(([type, value]) => [type, type.startsWith('text/') ? value : toTytx(value)]));
58
+ if (!wires.size) { event.preventDefault(); return; }
59
+ const effectAllowed = record.resolved.effectAllowed ?? 'all';
60
+ DragDropPolicy.acceptsEffect(effectAllowed, 'move'); // Validate the source enum, without negotiating a fallback.
61
+ let declaredTags = '';
62
+ for (let ancestor = record; ancestor; ancestor = ancestor.parent) {
63
+ if (ancestor.resolved?.dragTags != null) { declaredTags = ancestor.resolved.dragTags; break; }
64
+ }
65
+ const session = this.#session = {record, wires, effectAllowed, phase: 'active',
66
+ tags: [declaredTags, prepared.dragValues.dragTags].filter(Boolean).join(','),
67
+ endTopic: this.#renderer.binding.gramlot._subscriptions.topicFor(record.node, 'endDrag'),
68
+ source: {pageId: this.#renderer.binding.gramlot.pageId ?? null,
69
+ sourcePath: record.node.fullpath, itemPath: prepared.path ?? null}, preview: null, release: null};
70
+ event.dataTransfer.clearData();
71
+ for (const [type, wire] of wires) event.dataTransfer.setData(type, wire);
72
+ event.dataTransfer.effectAllowed = effectAllowed;
73
+ this.#style = this.#document.createElement('style');
74
+ this.#style.textContent = '.canBeDropped{outline:2px solid var(--gramlot-brand-blue,#3766b5);outline-offset:-2px}'
75
+ + '.cannotBeDropped{outline:2px dashed currentColor;outline-offset:-2px}.draggedItem{opacity:.75}';
76
+ this.#document.head.append(this.#style);
77
+ this.#preview(session, context.element, event.dataTransfer);
78
+ session.release = this.#renderer.onDispose(record.node, () => this.#finish('none'));
79
+ } catch (error) {
80
+ event.preventDefault();
81
+ this.#clearSession(); // A failed start emits no endDrag.
82
+ this.#report(error);
83
+ }
84
+ }
85
+
86
+ #preview(session, element, transfer) {
87
+ const preview = element.cloneNode(true);
88
+ preview.removeAttribute('id');
89
+ for (const child of preview.querySelectorAll('[id]')) child.removeAttribute('id');
90
+ preview.setAttribute('aria-hidden', 'true');
91
+ preview.classList.add(...(session.record.resolved.dragClass ?? 'draggedItem').split(/\s+/).filter(Boolean));
92
+ Object.assign(preview.style, {position: 'fixed', left: '-10000px', top: '0',
93
+ width: `${element.getBoundingClientRect().width}px`, pointerEvents: 'none'});
94
+ element.parentNode.append(preview);
95
+ session.preview = preview;
96
+ transfer.setDragImage(preview, 0, 0);
97
+ }
98
+
99
+ #target(event) {
100
+ const session = this.#session;
101
+ const record = this.#record(event, attrs => DragDropPolicy.isTarget(attrs));
102
+ if (!record) return null;
103
+ const row = this.#context(record, event);
104
+ if (!row) return {record, element: record.element, accepted: false};
105
+ const policy = DragDropPolicy.evaluate([...session.wires.keys()], session.tags, session.effectAllowed, record.resolved);
106
+ const dropValues = Object.fromEntries(policy.types.map(type => [type,
107
+ type.startsWith('text/') ? session.wires.get(type) : fromTytx(session.wires.get(type))]));
108
+ const context = {dropValues, item: row.item, path: row.path, source: {...session.source},
109
+ selfdrop: record === session.record, dropEffect: policy.dropEffect, dataAvailable: true};
110
+ const accepted = policy.accepted && this.#renderer.checkDropTarget(record.node, context)
111
+ && this.#renderer.records.get(record.node) === record && row.element.isConnected;
112
+ return {record, element: row.element, accepted, context};
113
+ }
114
+
115
+ #over(event) {
116
+ if (!this.#session) {
117
+ if (this.#record(event, attrs => DragDropPolicy.isTarget(attrs))) {
118
+ event.preventDefault(); event.dataTransfer.dropEffect = 'none';
119
+ }
120
+ return;
121
+ }
122
+ event.preventDefault();
123
+ if (this.#session.phase !== 'active') { event.dataTransfer.dropEffect = 'none'; return; }
124
+ try {
125
+ const session = this.#session;
126
+ const target = this.#target(event);
127
+ if (this.#session !== session) { event.dataTransfer.dropEffect = 'none'; return; }
128
+ event.dataTransfer.dropEffect = target?.accepted ? target.context.dropEffect : 'none';
129
+ this.#clearFeedback();
130
+ if (target) this.#showFeedback(target.element, target.accepted);
131
+ } catch (error) {
132
+ event.dataTransfer.dropEffect = 'none';
133
+ if (this.#session) this.#session.phase = 'rejected';
134
+ this.#clearPayload();
135
+ this.#report(error);
136
+ }
137
+ }
138
+
139
+ async #drop(event) {
140
+ if (!this.#session) {
141
+ if (this.#record(event, attrs => DragDropPolicy.isTarget(attrs))) event.preventDefault();
142
+ return;
143
+ }
144
+ event.preventDefault();
145
+ if (this.#session.phase !== 'active') return;
146
+ const session = this.#session;
147
+ try {
148
+ const target = this.#target(event); // Revalidate using current Data and declarations.
149
+ if (this.#session !== session) { event.dataTransfer.dropEffect = 'none'; return; }
150
+ session.phase = 'dropped';
151
+ this.#clearPayload();
152
+ if (!target?.accepted) { event.dataTransfer.dropEffect = 'none'; return; }
153
+ event.dataTransfer.dropEffect = target.context.dropEffect;
154
+ target.record.node.publish('onDrop', target.context);
155
+ await this.#renderer.invokeDrop(target.record.node, target.context);
156
+ } catch (error) {
157
+ if (this.#session === session) {
158
+ session.phase = 'rejected';
159
+ this.#clearPayload();
160
+ }
161
+ this.#report(error);
162
+ }
163
+ }
164
+
165
+ #showFeedback(element, accepted) {
166
+ const name = accepted ? 'canBeDropped' : 'cannotBeDropped';
167
+ const parts = (element.getAttribute('part') ?? '').split(/\s+/).filter(Boolean);
168
+ this.#feedback = {element, name, hadClass: element.classList.contains(name), hadPart: parts.includes(name)};
169
+ element.classList.add(name);
170
+ if (!parts.includes(name)) element.setAttribute('part', [...parts, name].join(' '));
171
+ }
172
+
173
+ #clearFeedback() {
174
+ if (!this.#feedback) return;
175
+ const {element, name, hadClass, hadPart} = this.#feedback;
176
+ if (!hadClass) element.classList.remove(name);
177
+ if (!hadPart) element.setAttribute('part', (element.getAttribute('part') ?? '').split(/\s+/).filter(part => part !== name).join(' '));
178
+ this.#feedback = null;
179
+ }
180
+
181
+ #clearPayload() {
182
+ this.#clearFeedback();
183
+ if (!this.#session) return;
184
+ this.#session.preview?.remove();
185
+ this.#session.preview = null;
186
+ this.#session.wires.clear();
187
+ }
188
+
189
+ #clearSession() {
190
+ const session = this.#session;
191
+ this.#clearPayload();
192
+ this.#session = null;
193
+ session?.release?.();
194
+ this.#style?.remove();
195
+ this.#style = null;
196
+ return session;
197
+ }
198
+
199
+ #finish(dropEffect) {
200
+ const session = this.#clearSession();
201
+ if (!session || this.#renderer.disposed) return;
202
+ void this.#renderer.endDrag(session.record.node, {source: {...session.source}, dropEffect}, session.endTopic)
203
+ .catch(error => this.#report(error));
204
+ }
205
+
206
+ #report(error) { console.error('Gramlot drag/drop failed:', error); }
207
+
208
+ dispose() {
209
+ this.#clearSession();
210
+ for (const name of EVENTS) this.#document.removeEventListener(name, this);
211
+ this.#document.defaultView.removeEventListener('pagehide', this.#hide);
212
+ }
213
+ }
@@ -0,0 +1,33 @@
1
+ import {toTytx, fromTytx} from '@genrojs/tytx';
2
+ import {assertTransportData} from '../references.js';
3
+
4
+ /** Prepare and snapshot local drag data before a browser gesture is committed. */
5
+ export class DragPreparation {
6
+ constructor(renderer) { this.renderer = renderer; }
7
+
8
+ prepare(sourceNode, event) {
9
+ const record = this.renderer.records.get(sourceNode);
10
+ if (!record || record.resolved.draggable !== true) return null;
11
+ const context = sourceNode._getMeta('gramlot_component')?.dragSource
12
+ ? record.element.getDragContext(event)
13
+ : {dragValues: {}, item: undefined, path: undefined};
14
+ if (context === null) return null;
15
+ const {dragValues, item, path} = context;
16
+ if (record.resolved.onDrag) {
17
+ const result = this.renderer.html.callLogic(sourceNode, record.resolved.onDrag, {dragValues, item, path});
18
+ if (result && typeof result.then === 'function') {
19
+ throw new TypeError('onDrag must run synchronously');
20
+ }
21
+ if (result === false) return null;
22
+ }
23
+ assertTransportData(dragValues);
24
+ const snapshot = Object.fromEntries(Object.entries(dragValues).map(([type, value]) => {
25
+ if (type.startsWith('text/') || type === 'dragTags') {
26
+ if (typeof value !== 'string') throw new TypeError(`${type} drag data must be text`);
27
+ return [type, value];
28
+ }
29
+ return [type, fromTytx(toTytx(value))];
30
+ }));
31
+ return {dragValues: snapshot, item, path};
32
+ }
33
+ }
@@ -32,6 +32,24 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
32
32
  get binding(): unknown;
33
33
  /** The inline compiler of the page: the live renderer evaluates the `==` expressions. */
34
34
  get inlineCompiler(): unknown;
35
+ /** Local drag preparation only; null means disabled, unavailable or vetoed. Does not start a gesture. */
36
+ prepareDrag(node: SourceBagNode, event: {composedPath(): unknown[]}): {
37
+ dragValues: Record<string, unknown>; item: unknown; path: string | undefined;
38
+ } | null;
39
+ /** Dynamic target check only; declarative type/tag/effect checks are still required. */
40
+ checkDropTarget(node: SourceBagNode, context: {
41
+ dropValues: Record<string, unknown>; item: unknown; path: string | undefined;
42
+ source: Record<string, unknown>; selfdrop: boolean;
43
+ dropEffect: 'copy' | 'move' | 'link'; dataAvailable: boolean;
44
+ }): boolean;
45
+ /** Invoke the general onDrop action on already accepted data not consumed by typed actions. */
46
+ invokeDrop(node: SourceBagNode, context: {
47
+ dropValues: Record<string, unknown>; item: unknown; path: string | undefined;
48
+ source: Record<string, unknown>; selfdrop: boolean;
49
+ dropEffect: 'copy' | 'move' | 'link'; dataAvailable: boolean;
50
+ }): Promise<void>;
51
+ /** Origin callback, followed by local endDrag publication even if the callback fails. */
52
+ endDrag(node: SourceBagNode, context: {source: Record<string, unknown>; dropEffect: string}, topic: string): Promise<void>;
35
53
  /** The resolved projection of a node: runtime values, then the `==` expressions. */
36
54
  evaluateExpressions(node: SourceBagNode, runtimeAttrs: Record<string, unknown>): Record<string, unknown>;
37
55
  /** Render a node, or a structural Source fragment, to DOM; a data-element renders nothing. */
@@ -1,3 +1,4 @@
1
+ import {callLogic, invokeHook} from '../binding/hooks.js';
1
2
  /* @ts-self-types="./gramlot-renderer.d.ts" */
2
3
  /**
3
4
  * The live renderer of a Gramlot page.
@@ -16,6 +17,8 @@ import {BindingRuntime} from '../binding/runtime.js';
16
17
  import {requireInstallable} from '../binding/installation.js';
17
18
  import {GramlotHtmlRenderer} from './gramlot-html-renderer.js';
18
19
  import {displayItem} from './attributes.js';
20
+ import {DragPreparation} from './drag-preparation.js';
21
+ import {DragDrop} from './drag-drop.js';
19
22
 
20
23
  /**
21
24
  * Own the live DOM lifecycle driven by typed Source insert/update/delete events.
@@ -44,22 +47,57 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
44
47
  this.source = source;
45
48
  this.destination = destination;
46
49
  this.html = new HtmlElement({metadataAttributes: ['__ref'],
47
- invokeScript: (node, name, code, keywords) => this.inlineCompiler.compile(
48
- node, name, code, node.parentNode._getMeta('gramlot_component').childParameters[name].inline)(keywords)});
50
+ callLogic: (node, name, keywords) => {
51
+ const {group, method} = binding.gramlot.src.logicRegistry.resolve(name, node);
52
+ return method.call(group, node, keywords);
53
+ },
54
+ invokeScript: (node, name, code, keywords) => invokeHook(binding, node, name, code, keywords,
55
+ node.parentNode._getMeta('gramlot_component').childParameters[name].inline)});
49
56
  this.records = new Map();
50
57
  this.references = new References(source);
51
58
  this.pending = [];
52
59
  this.building = false;
53
60
  this.disposed = false;
54
61
  this.elements = new WeakMap();
62
+ this.dragPreparation = new DragPreparation(this);
55
63
  // The instance id scopes the generated radio names to this page (P11, S11).
56
64
  this.instanceId = randomId();
57
65
  this.radioGroups = new RadioGroups(this);
66
+ this.dragDrop = new DragDrop(this);
58
67
  this.subscription = `html-source-renderer-${this.instanceId}`;
59
68
  source.subscribe(this.subscription, {any: event => this.receive(event)});
60
69
  }
61
70
 
62
71
  get binding() { return this._binding; }
72
+ /** Prepare a local payload snapshot: no DataTransfer writes or native gesture commit. */
73
+ prepareDrag(node, event) { return this.dragPreparation.prepare(node, event); }
74
+ /** Dynamic eligibility only; cannot replace the independent type/tag/effect policy. */
75
+ checkDropTarget(node, {dropValues, item, path, source, selfdrop, dropEffect, dataAvailable}) {
76
+ const record = this.records.get(node);
77
+ if (!record) return false;
78
+ if (!record.resolved.dropTargetCb) return true;
79
+ const allowed = this.html.callLogic(node, record.resolved.dropTargetCb,
80
+ {dropValues, item, path, source, selfdrop, dropEffect, dataAvailable});
81
+ if (typeof allowed !== 'boolean') throw new TypeError('dropTargetCb must return a boolean synchronously');
82
+ return allowed;
83
+ }
84
+ /** Invoke only the general action, after acceptance and removal of data handled by typed actions. */
85
+ async invokeDrop(node, {dropValues, item, path, source, selfdrop, dropEffect, dataAvailable}) {
86
+ const record = this.records.get(node);
87
+ if (!record || !record.resolved.onDrop || Object.keys(dropValues).length === 0) return;
88
+ await this.html.callLogic(node, record.resolved.onDrop,
89
+ {dropValues, item, path, source, selfdrop, dropEffect, dataAvailable});
90
+ }
91
+ /** Notify origin completion independently of application-operation success. */
92
+ async endDrag(node, {source, dropEffect}, topic) {
93
+ const context = {source, dropEffect}, errors = [];
94
+ const record = this.records.get(node);
95
+ try {
96
+ if (record && !record.binding.closed && record.resolved.onDragEnd) await this.html.callLogic(node, record.resolved.onDragEnd, context);
97
+ } catch (error) { errors.push(error); }
98
+ try { this.binding.gramlot.publish(topic, context); } catch (error) { errors.push(error); }
99
+ if (errors.length) throw new AggregateError(errors, 'Drag completion notification failed');
100
+ }
63
101
  /** The page's InlineCompiler: the live renderer evaluates the `==` expressions (S09). */
64
102
  get inlineCompiler() { return this.binding.inlineCompiler; }
65
103
 
@@ -677,6 +715,7 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
677
715
  dispose() {
678
716
  if (this.disposed) return;
679
717
  this.disposed = true;
718
+ this.dragDrop.dispose();
680
719
  this.source.unsubscribe(this.subscription, {any: true});
681
720
  this.pending.length = 0;
682
721
  const errors = [];
@@ -0,0 +1,12 @@
1
+ import {Page} from './page.js';
2
+ /** Five optional region hooks; the center exists by default. */
3
+ export class FramePage extends Page {
4
+ static shellId: string;
5
+ static datapath: string | null;
6
+ top?(pane: any): void;
7
+ bottom?(pane: any): void;
8
+ left?(pane: any): void;
9
+ right?(pane: any): void;
10
+ center(pane: any): void;
11
+ behavior(shell: any): void;
12
+ }
@@ -0,0 +1,23 @@
1
+ /* @ts-self-types="./frame-page.d.ts" */
2
+ /** A reusable five-region page, composed entirely through Source hooks. */
3
+ import {Page} from './page-base.js';
4
+
5
+ export class FramePage extends Page {
6
+ static shellId = 'frame';
7
+ static datapath = null;
8
+
9
+ main(root) {
10
+ const shell = root.div({id: this.constructor.shellId, datapath: this.constructor.datapath, class: 'frame-page',
11
+ height: '100vh', display: 'flex', flex_direction: 'column', min_height: 0});
12
+ const frame = shell.borderContainer({node_label: 'frame', height: '100%', flex: '1', min_height: 0});
13
+ for (const region of ['top', 'bottom', 'left', 'right', 'center']) {
14
+ if (this[region] !== undefined) {
15
+ const pane = frame.contentPane({region, node_label: region});
16
+ this[region](pane);
17
+ }
18
+ }
19
+ this.behavior(shell);
20
+ }
21
+ center(pane) {}
22
+ behavior(shell) {}
23
+ }
@@ -244,7 +244,8 @@ export class GramlotServer {
244
244
  head.link({rel: 'manifest', href: prefix + '/app.webmanifest'});
245
245
  }
246
246
  // A page module served for its Logic imports the core from the runtime already loaded.
247
- head.script(scriptJson({imports: {'@gramlot/gramlot/page': prefixed(prefix, this.runtimeUrl)}}),
247
+ head.script(scriptJson({imports: {'@gramlot/gramlot/page': prefixed(prefix, this.runtimeUrl),
248
+ '@gramlot/gramlot': prefixed(prefix, this.runtimeUrl)}}),
248
249
  {type: 'importmap', nonce});
249
250
  const body = root.body();
250
251
  body.div({id: this.rootId});
@@ -1,15 +1,11 @@
1
- import {Page} from './page.js';
2
- export interface IndexItem { key: string; title: string; url: string; }
3
- export interface IndexGroup { key: string; title: string; children: IndexItem[]; }
4
- /** One index shell per document. Override footer to replace or extend standard controls. */
5
- export class IndexPage extends Page {
6
- static logoUrl: string;
7
- static shellId: string;
8
- static navigation: IndexGroup[];
9
- introduction(pane: any): void;
10
- groupPanel(pane: any, group: IndexGroup): void;
11
- panel(pane: any, item: IndexItem): void;
12
- header(shell: any): void;
13
- footer(pane: any): void;
14
- behavior(pane: any): void;
1
+ import {FramePage} from './frame-page.js';
2
+ import type {Bag, BagNode} from '@genrojs/bag';
3
+ /** Tree navigation on a Bag and URL-identified retained tab panels. */
4
+ export class IndexPage extends FramePage {
5
+ static navigation: Bag;
6
+ static datapath: string;
7
+ left(pane: any): void;
8
+ center(pane: any): void;
9
+ panel(pane: any, node: BagNode): void;
10
+ index_panel(pane: any, params: {selection: Bag}): void;
15
11
  }
@@ -1,107 +1,38 @@
1
1
  /* @ts-self-types="./index-page.d.ts" */
2
- /** Reusable application index authored with Gramlot Source. */
3
- import {Page as GramlotPage} from './page-base.js';
2
+ /** Bag navigation and retained page tabs on the reusable five-region frame. */
3
+ import {Bag} from '@genrojs/bag';
4
+ import {FramePage} from './frame-page.js';
4
5
 
5
- export class IndexPage extends GramlotPage {
6
+ export class IndexPage extends FramePage {
6
7
  static title = 'Application';
7
- static logoUrl = '';
8
8
  static shellId = 'index';
9
- static navigation = [];
10
- static css = ['/themes/gramlot-index/theme.css'];
9
+ static datapath = 'index';
10
+ static navigation = null;
11
11
 
12
12
  main(root) {
13
- const families = this.constructor.navigation;
14
- const shell = root.div({class: 'index-shell', id: this.constructor.shellId});
15
- this.header(shell);
16
- const sidebar = shell.aside({class: 'index-sidebar', id: 'index-sidebar'});
17
- const brand = sidebar.header();
18
- if (this.constructor.logoUrl) brand.img({src: this.constructor.logoUrl, alt: this.constructor.title, class: 'index-logo'});
19
- brand.h1(this.constructor.title);
20
- const navigation = sidebar.nav({'aria-label': 'Pages'}).ul({class: 'index-list'});
21
- for (const family of families) {
22
- const category = navigation.li().details({open: family === families[0]});
23
- category.summary({tabindex: -1}).a(family.title, {id: `open-${family.key}`, href: `#panel-${family.key}`,
24
- class: 'index-family', aria_current: null, tabindex: -1});
25
- const examplesList = category.ul({class: 'index-list'});
26
- for (const example of family.children) {
27
- examplesList.li().a(example.title, {id: `open-${example.key}`, href: example.url,
28
- aria_current: null, tabindex: -1});
29
- }
30
- }
31
- shell.div({class: 'index-divider', id: 'index-sidebar-divider',
32
- role: 'separator', aria_orientation: 'vertical', tabindex: 0,
33
- aria_label: 'Resize sidebar', aria_controls: 'index-sidebar',
34
- aria_valuemin: 120, aria_valuemax: 460, aria_valuenow: 240});
35
- const content = shell.main({class: 'index-main'});
36
- const tabs = content.div({class: 'index-tabs', role: 'tablist', aria_label: 'Open pages'});
37
- tabs.html_button('Introduction', {type: 'button', role: 'tab', id: 'tab-intro',
38
- aria_controls: 'panel-intro',
39
- aria_selected: 'true', tabindex: -1, hidden: false});
40
- for (const family of families) {
41
- for (const {key, title} of [family, ...family.children]) {
42
- tabs.html_button(title, {type: 'button', role: 'tab', id: `tab-${key}`,
43
- aria_controls: `panel-${key}`,
44
- aria_selected: 'false', tabindex: -1, hidden: true});
45
- }
46
- }
47
-
48
- const panels = content.div({class: 'index-panels'});
49
- const intro = panels.section({id: 'panel-intro', class: 'index-intro', role: 'tabpanel',
50
- aria_labelledby: 'tab-intro', hidden: false});
51
- this.introduction(intro);
52
-
53
- for (const family of families) {
54
- const categoryPanel = panels.section({id: `panel-${family.key}`, class: 'index-category',
55
- role: 'tabpanel',
56
- aria_labelledby: `tab-${family.key}`, hidden: true});
57
- this.groupPanel(categoryPanel, family);
58
- for (const example of family.children) this.panel(panels, example);
59
- }
60
- const footer = shell.footer({class: 'index-footer'});
61
- this.footer(footer);
62
- this.behavior(shell);
13
+ const {navigation, datapath} = this.constructor;
14
+ if (!(navigation instanceof Bag)) throw new TypeError('IndexPage.navigation must be a Bag');
15
+ root.dataSetter({destination_path: `${datapath}.navigation`, value: navigation});
16
+ root.dataSetter({destination_path: `${datapath}.navigationSelection`, value: null});
17
+ root.dataSetter({destination_path: `${datapath}.active`, value: null});
18
+ root.dataSetter({destination_path: `${datapath}.opened`, value: new Bag()});
19
+ super.main(root);
63
20
  }
64
-
65
- header(shell) {}
66
-
67
- behavior(shell) {
68
- shell.dataController({func: 'indexMount', _onStart: true, shell_id: this.constructor.shellId});
21
+ left(pane) {
22
+ pane.setAttr({width: '240px', splitter: true, drawer: true, drawer_label: 'Navigation'});
23
+ pane.tree({node_label: 'tree', storepath: `${this.constructor.datapath}.navigation`,
24
+ labelAttribute: 'title', hideValues: true, selectedPath: `^${this.constructor.datapath}.navigationSelection`});
69
25
  }
70
- introduction(pane) {
71
- pane.h2(this.constructor.title);
72
- pane.p('Choose a page from the navigation. Open pages remain available in tabs.');
26
+ center(pane) {
27
+ pane.tabContainer({node_label: 'tabs', height: '100%', selectedPage: `^${this.constructor.datapath}.active`});
73
28
  }
74
- groupPanel(pane, group) { pane.h2(group.title); }
75
- footer(footer) {
76
- const theme = footer.div({class: 'index-theme'});
77
- theme.html_label('Theme', {for: 'index-appearance'});
78
- const appearance = theme.select({id: 'index-appearance', value: 'compact'});
79
- appearance.option('Base', {value: 'base', selected: false});
80
- appearance.option('Compact', {value: 'compact', selected: true});
81
- appearance.option('mimi', {value: 'mimi'});
82
- appearance.option('joanna', {value: 'joanna'});
83
- const color = footer.div({class: 'index-theme'});
84
- color.html_label('Color mode', {for: 'index-theme'});
85
- const choices = color.select({id: 'index-theme', value: 'light'});
86
- choices.option('Light', {value: 'light', selected: true});
87
- choices.option('Dark', {value: 'dark', selected: false});
88
- const keyboard = footer.div({class: 'index-keyboard'});
89
- const label = keyboard.html_label({for: 'keyboard-navigation'});
90
- label.input({type: 'checkbox', id: 'keyboard-navigation', checked: false});
91
- label.span('Keyboard navigation');
92
-
93
- if (this.constructor.installable) {
94
- const app = footer.details({class: 'index-install'});
95
- app.summary('Install app');
96
- app.html_button('Install', {type: 'button', id: 'index-install-button', hidden: true});
97
- app.p('', {id: 'index-install-status', role: 'status'});
98
- app.p('Chrome: use Install page as app in the browser menu. Safari on macOS Sonoma or later: File > Add to Dock.');
99
- app.p('Use HTTPS or localhost. For a static export, serve the directory; direct file opening is not installable. Keep the server running for hosted pages.');
100
- }
29
+ behavior(shell) {
30
+ shell.dataController({func: 'indexMount', _onStart: true, shell_id: this.constructor.shellId});
101
31
  }
102
- panel(parent, item) {
103
- const pane = parent.section({id: `panel-${item.key}`, class: 'index-panel', role: 'tabpanel',
104
- aria_labelledby: `tab-${item.key}`, hidden: true});
105
- pane.iframe({id: `frame-${item.key}`, title: item.title, name: `page-${item.key}`});
32
+ index_panel(pane, {selection}) { this.panel(pane, selection.getNode('#0')); }
33
+ panel(pane, node) {
34
+ pane.iframe({src: node.attr.url, title: node.attr.title ?? node.label,
35
+ width: '100%', height: '100%', border: 0});
106
36
  }
107
37
  }
38
+ IndexPage.registerSource('index_panel');
@@ -70,8 +70,15 @@ export class Page extends Exposed {
70
70
 
71
71
  export {IndexPage} from "./index-page.js";
72
72
  export {IndexLogic, mountIndexPage} from "../index-page-runtime.js";
73
+
74
+ export {FramePage} from "./frame-page.js";
73
75
  export {ServerAdapter} from "../server-adapter.js";
74
76
  /** The typed literals a page authors, the same names as in the browser entry point: a Bag, and an exact Decimal
75
77
  * made with `createDecimal('12.50')`. A date or a time is a `Date`; TYTX types it from its content. */
76
78
  export {Bag, BagNode} from "@genrojs/bag";
77
79
  export {createDecimal} from "@genrojs/tytx";
80
+
81
+ export {codeMirrorWithOptions} from '../components/editor-options.js';
82
+
83
+ export {fileSystemTree, FileSystemLogic, FileSystemController, DirectoryResolver} from "../filesystem.js";
84
+ export {IdeLogic} from "../ide-runtime.js";
@@ -1,4 +1,5 @@
1
1
  export * from './page-base.js';
2
+ export {FramePage} from './frame-page.js';
2
3
  export {IndexPage} from './index-page.js';
3
4
  export {IndexLogic, mountIndexPage} from '../index-page-runtime.js';
4
5
  // The typed literals a page module authors in main(). In the browser the import map resolves only this name, so a
@@ -8,3 +9,7 @@ export {Bag, BagNode} from '@genrojs/bag';
8
9
  export {createDecimal} from '@genrojs/tytx';
9
10
  // A ServerAdapter module chosen by a server imports its base class from @gramlot/gramlot/page.
10
11
  export {ServerAdapter} from '../server-adapter.js';
12
+ export {codeMirrorWithOptions} from '../components/editor-options.js';
13
+
14
+ export {fileSystemTree, FileSystemLogic, FileSystemController, DirectoryResolver} from "../filesystem.js";
15
+ export {IdeLogic} from "../ide-runtime.js";