@gramlot/gramlot 0.2.19 → 0.3.0

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 (66) hide show
  1. package/dist/gramlot.js +2145 -224
  2. package/dist/gramlot.min.js +363 -21
  3. package/package.json +6 -3
  4. package/src/binding/ask-dialog.js +2 -2
  5. package/src/binding/inline.js +11 -12
  6. package/src/binding/installation.js +4 -1
  7. package/src/binding/pointer.js +63 -0
  8. package/src/binding/providers.js +8 -4
  9. package/src/binding/runtime.js +11 -5
  10. package/src/bootstrap.d.ts +2 -0
  11. package/src/bootstrap.js +9 -2
  12. package/src/builder/gramlot-builder.js +24 -3
  13. package/src/builder/source.js +33 -9
  14. package/src/components/bases.js +182 -0
  15. package/src/components/buttons.js +254 -0
  16. package/src/components/choice-editor.js +221 -0
  17. package/src/components/choices.js +13 -0
  18. package/src/components/date-calendar.js +139 -0
  19. package/src/components/field-state.js +166 -0
  20. package/src/components/formlet-labels.js +80 -0
  21. package/src/components/index.js +5 -0
  22. package/src/components/inputs.js +196 -0
  23. package/src/components/labelbox.js +74 -0
  24. package/src/components/layout.js +190 -0
  25. package/src/components/parameters.js +6 -0
  26. package/src/components/popup.js +22 -0
  27. package/src/components/registry.js +83 -0
  28. package/src/components/typed-editor.js +260 -0
  29. package/src/components/validation.js +138 -0
  30. package/src/date-parser/civil.js +61 -0
  31. package/src/date-parser/index.d.ts +18 -0
  32. package/src/date-parser/index.js +196 -0
  33. package/src/date-parser/locales.js +257 -0
  34. package/src/format.js +128 -0
  35. package/src/gramlot.d.ts +25 -0
  36. package/src/gramlot.js +15 -1
  37. package/src/handlers/dom-handler.d.ts +1 -0
  38. package/src/handlers/dom-handler.js +7 -0
  39. package/src/index-page-runtime.js +78 -30
  40. package/src/index-page-styles.js +2 -2
  41. package/src/index-theme.js +1 -1
  42. package/src/index.d.ts +4 -1
  43. package/src/index.js +2 -0
  44. package/src/renderer/attributes.js +25 -50
  45. package/src/renderer/gramlot-html-renderer.js +4 -3
  46. package/src/renderer/gramlot-renderer.js +63 -3
  47. package/src/server/gramlot-server.d.ts +5 -0
  48. package/src/server/gramlot-server.js +14 -5
  49. package/src/server/index-page.d.ts +1 -0
  50. package/src/server/index-page.js +8 -3
  51. package/src/server/page-base.js +3 -0
  52. package/src/server/page.d.ts +3 -0
  53. package/src/server/resources.d.ts +2 -0
  54. package/src/view/button.js +17 -13
  55. package/src/view/controls.js +152 -4
  56. package/src/view/html.js +18 -0
  57. package/themes/gramlot-base/README.md +6 -0
  58. package/themes/gramlot-base/theme.css +34 -6
  59. package/themes/gramlot-compact/README.md +6 -0
  60. package/themes/gramlot-compact/theme.css +8 -4
  61. package/themes/joanna/README.md +23 -0
  62. package/themes/joanna/theme.css +89 -0
  63. package/themes/mimi/README.md +23 -0
  64. package/themes/mimi/theme.css +89 -0
  65. package/tools/gramlot-tools-inspector.js +42 -18
  66. package/tools/inspector-agent.js +8 -4
@@ -1,6 +1,7 @@
1
1
  // Attribute rules shared by GramlotHtmlRenderer, GramlotSvgRenderer and the live GramlotRenderer.
2
2
  // Same table and same functions as src/gramlot/renderer/attributes.py (source plan §1 rule 10).
3
3
  import {sourceAttributeItems} from '@genrojs/builders';
4
+ import {applyMask} from '../format.js';
4
5
 
5
6
  export const XHTML_NS = 'http://www.w3.org/1999/xhtml';
6
7
  export const SVG_NS = 'http://www.w3.org/2000/svg';
@@ -23,11 +24,8 @@ const NATIVE_ATTRIBUTES = {
23
24
  canvas: ['width', 'height'],
24
25
  };
25
26
 
26
- // A `${name}` template reference; `\${` stays text (Builder's runtimeValues rule).
27
- const TEMPLATE_REFERENCE = /(?<!\\)\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;
28
-
29
27
  // Display directives of the node text: consumed by the renderer, never written as attributes.
30
- const DISPLAY_ATTRIBUTES = ['format', 'mask', 'locale', 'places', 'dtype'];
28
+ const DISPLAY_ATTRIBUTES = ['format', 'mask', 'locale', 'timeZone', 'places', 'dtype'];
31
29
 
32
30
  // Output attributes whose `javascript:` value the browser runs as code (`action` never reaches the output).
33
31
  const URL_ATTRIBUTES = new Set(['href', 'src', 'formaction', 'xlink:href', 'xlink_href']);
@@ -79,7 +77,7 @@ function isJavascriptUrl(value) {
79
77
  /**
80
78
  * `attrs` of an `iframe` whose `srcdoc` comes from Data, with an empty `sandbox` first: the browser shows
81
79
  * the HTML of a datum and runs nothing of it. `srcdoc` comes from Data when it is a `^`/`=` pointer, a `==`
82
- * expression or a `${…}` template reading one, or when the node value is a pointer, whose datum can carry
80
+ * expression, or when the node value is a pointer, whose datum can carry
83
81
  * `srcdoc` in its `_wdg`. The declaration decides, so the iframe has `sandbox` while `srcdoc` is still null.
84
82
  * A `sandbox` declared in the Source stays as declared; a literal `srcdoc` gets none. The names are read
85
83
  * without the dialect `prefixes` (`html_`); `sandbox` takes the prefix of `srcdoc`.
@@ -93,15 +91,8 @@ export function withDataSrcdocSandbox(node, attrs, prefixes = []) {
93
91
  const declared = Object.fromEntries(sourceAttributeItems(node.getAttr()));
94
92
  const srcdoc = [...Object.keys(declared), ...Object.keys(attrs)].find(name => bare(name)[1] === 'srcdoc');
95
93
  if (srcdoc === undefined || Object.keys(declared).some(name => bare(name)[1] === 'sandbox')) return attrs;
96
- const fromData = (name, seen) => {
97
- const raw = declared[name];
98
- seen.add(name);
99
- return node.pointerType(raw) !== null || isExpression(raw) || templateParameters(raw)
100
- .some(param => Object.hasOwn(declared, param) && !seen.has(param) && fromData(param, seen));
101
- };
102
- if (node.pointerType(node.value) === null && !(Object.hasOwn(declared, srcdoc) && fromData(srcdoc, new Set()))) {
103
- return attrs;
104
- }
94
+ if (node.pointerType(node.value) === null && !(Object.hasOwn(declared, srcdoc)
95
+ && (node.pointerType(declared[srcdoc]) !== null || isExpression(declared[srcdoc])))) return attrs;
105
96
  const rest = Object.fromEntries(Object.entries(attrs).filter(([name]) => bare(name)[1] !== 'sandbox'));
106
97
  return {[`${bare(srcdoc)[0]}sandbox`]: '', ...rest};
107
98
  }
@@ -145,48 +136,32 @@ export function textValue(value) {
145
136
 
146
137
  /**
147
138
  * `[item, attrs]` with the display directives consumed (HTML only).
148
- * `format`, `places`, `locale` and `dtype` do not format the text in 0.2.0. `mask` follows the
149
- * legacy rule (gnrlang.js asText): `%s` replaced by the value, no mask when the value is empty.
139
+ * The live page supplies its formatter; string renderers retain unformatted values.
140
+ * Plain masks use the same {} composition as the formatter, skipping empty text.
150
141
  */
151
- export function displayItem(item, attrs) {
142
+ export function displayItem(item, attrs, format = null) {
152
143
  const rest = {...attrs};
153
- const mask = rest.mask;
144
+ const {mask, format: pattern, locale, timeZone, dtype, places} = rest;
154
145
  for (const name of DISPLAY_ATTRIBUTES) delete rest[name];
155
- if (Array.isArray(item)) return [item, rest];
156
- if (typeof item === 'boolean') item = textValue(item);
157
- if (mask == null) return [item, rest];
158
- const text = item == null ? '' : textValue(item);
159
- return [text === '' ? text : String(mask).replaceAll('%s', () => text), rest];
160
- }
161
-
162
- /** The parameter names of the `${name}` templates of `value`, in order; none for a value that is not a string. */
163
- export function templateParameters(value) {
164
- return typeof value === 'string' ? [...value.matchAll(TEMPLATE_REFERENCE)].map(([, name]) => name) : [];
146
+ const display = value => {
147
+ if (format && pattern != null) {
148
+ if (places != null) throw new RangeError('places is not implemented; specify precision in format');
149
+ return format(value, {pattern, mask, ...(locale == null ? {} : {locale}),
150
+ ...(timeZone == null ? {} : {timeZone}), ...(dtype == null ? {} : {dtype})});
151
+ }
152
+ if (typeof value === 'boolean') value = textValue(value);
153
+ if (mask == null) return value;
154
+ const text = value == null ? '' : textValue(value);
155
+ return text === '' ? text : applyMask(text, mask);
156
+ };
157
+ if (Array.isArray(item)) {
158
+ if (Object.hasOwn(rest, '_text')) rest._text = display(rest._text);
159
+ return [item, rest];
160
+ }
161
+ return [display(item), rest];
165
162
  }
166
163
 
167
164
  /** Whether `value` is a `==` expression (Q11.2). */
168
165
  export function isExpression(value) {
169
166
  return typeof value === 'string' && value.startsWith('==');
170
167
  }
171
-
172
- /**
173
- * Templates and `==` expressions do not mix (Q11.2): a template that uses a `==` attribute of the same
174
- * node is an error naming both attributes; a `${…}` inside a `==` attribute or node value is an error
175
- * naming it.
176
- */
177
- export function requireNoExpressionTemplate(node) {
178
- if (isExpression(node.value) && templateParameters(node.value).length) {
179
- throw new Error(`${node.nodeTag} '${node.label}': the == node value contains a \${…} template, not accepted in a == expression`);
180
- }
181
- const attrs = Object.fromEntries(sourceAttributeItems(node.getAttr()));
182
- for (const [name, raw] of Object.entries(attrs)) {
183
- if (isExpression(raw) && templateParameters(raw).length) {
184
- throw new Error(`${node.nodeTag} '${node.label}': '${name}' contains a \${…} template, not accepted in a == expression`);
185
- }
186
- for (const param of templateParameters(raw)) {
187
- if (isExpression(attrs[param])) {
188
- throw new Error(`${node.nodeTag} '${node.label}': the template of '${name}' uses '${param}', a == expression`);
189
- }
190
- }
191
- }
192
- }
@@ -8,7 +8,7 @@ import {HtmlBuilder, HtmlRenderer, SvgBuilder, sourceAttributeItems} from '@genr
8
8
  import {GramlotSvgRenderer} from './gramlot-svg-renderer.js';
9
9
  import {webcomponentCode} from '../webcomponent.js';
10
10
  import {
11
- SVG_NS, XHTML_NS, boundaryAttributes, displayItem, domNames, isExpression, requireNoExpressionTemplate,
11
+ SVG_NS, XHTML_NS, boundaryAttributes, displayItem, domNames, isExpression,
12
12
  requireNoScriptAttributes, requireStyleClassAttributes, splitNativeAttributes, textValue, withDataSrcdocSandbox, withoutBindingAttributes,
13
13
  withoutNullValues,
14
14
  } from './attributes.js';
@@ -31,6 +31,8 @@ export class GramlotHtmlRenderer extends HtmlRenderer {
31
31
  /** HTML nodes (GramlotBuilder, HtmlBuilder) → this renderer; SVG nodes → one GramlotSvgRenderer owned by it. */
32
32
  getRender(builder) {
33
33
  if (!this.renders.has(builder)) {
34
+ // HTML/SVG subbuilders share the page's expression hook and compiler.
35
+ builder.evaluatePointerExpression = this.builder.evaluatePointerExpression.bind(this.builder);
34
36
  if (builder instanceof HtmlBuilder) this.addRender(builder, this);
35
37
  else if (builder instanceof SvgBuilder) this.addRender(builder, new GramlotSvgRenderer(builder, this));
36
38
  }
@@ -73,10 +75,9 @@ export class GramlotHtmlRenderer extends HtmlRenderer {
73
75
  /**
74
76
  * Step 3 of Q11.2 on the attributes of `node` resolved by runtimeValues, for HTML and SVG nodes: every
75
77
  * `==` attribute, and a `==` node value, evaluated by the page's InlineCompiler (§4.10); without a
76
- * compiler they are null and nothing is written. A template using a `==` attribute is an error.
78
+ * compiler they are null and nothing is written.
77
79
  */
78
80
  evaluateExpressions(node, runtimeAttrs) {
79
- requireNoExpressionTemplate(node);
80
81
  const compiler = this.inlineCompiler;
81
82
  const evaluate = (attr, expr) => (compiler ? compiler.compileExpression(node, attr, expr)(runtimeAttrs) : null);
82
83
  const attrs = {...runtimeAttrs};
@@ -28,6 +28,8 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
28
28
  #resolvedAttributes = new WeakMap();
29
29
  // The resolved projection that `project` hands to the rebuild of a control whose shape changed.
30
30
  #rebuildAttributes = new WeakMap();
31
+ // Own presentation defaults, resolved once in their declaring Source scope.
32
+ #presentationDefaults = new WeakMap();
31
33
 
32
34
  /** The live renderer of one Gramlot page: `binding` is the page's BindingRuntime (§4.3). */
33
35
  constructor(builder, source, destination, {binding} = {}) {
@@ -66,7 +68,20 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
66
68
  * its `==` are evaluated once.
67
69
  */
68
70
  evaluateExpressions(node, runtimeAttrs) {
69
- const attrs = this.#rebuildAttributes.get(node) ?? super.evaluateExpressions(node, runtimeAttrs);
71
+ let attrs = this.#rebuildAttributes.get(node) ?? super.evaluateExpressions(node, runtimeAttrs);
72
+ const component = node._getMeta('gramlot_component');
73
+ if (component?.presentationDefaults.length) {
74
+ const declared = node.getAttr();
75
+ this.#presentationDefaults.set(node, Object.fromEntries(Object.entries(attrs)
76
+ .filter(([name]) => Object.hasOwn(declared, name) && component.presentationDefaults.some(prefix => name.startsWith(prefix)))));
77
+ }
78
+ if (component && (component.parameters.value?.binding === 'twoWay' || component.presentationDefaults.length)) {
79
+ const ancestors = [];
80
+ for (let parent = node.parentNode; parent; parent = parent.parentNode) {
81
+ if (this.#presentationDefaults.has(parent)) ancestors.unshift(this.#presentationDefaults.get(parent));
82
+ }
83
+ attrs = Object.assign({}, ...ancestors, attrs);
84
+ }
70
85
  this.#rebuildAttributes.delete(node);
71
86
  this.#resolvedAttributes.set(node, attrs);
72
87
  return attrs;
@@ -125,8 +140,12 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
125
140
  let attrs = runtimeAttrs;
126
141
  item = this.expressionValue(node, item);
127
142
  if (this.getRender(node.builder) === this) {
128
- [item, attrs] = displayItem(item, this.restoreNativeAttributes(node, runtimeAttrs));
143
+ attrs = this.restoreNativeAttributes(node, runtimeAttrs);
144
+ // Component parameters (including format/locale/dtype) belong to its editor.
145
+ if (!node._getMeta('gramlot_component')) [item, attrs] = displayItem(item, attrs,
146
+ (value, options) => this._binding.gramlot.format(value, options));
129
147
  }
148
+ attrs = this.componentAttributes(node, attrs);
130
149
  const children = Array.isArray(item) ? item : [];
131
150
  const text = Array.isArray(item) ? attrs._text : item;
132
151
  const resolved = this.#resolvedAttributes.get(node);
@@ -457,6 +476,7 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
457
476
  const record = this.records.get(node);
458
477
  if (!record?.element) return;
459
478
  const renderer = this.getRender(node.builder);
479
+ const previousDefaults = this.#presentationDefaults.get(node);
460
480
  const [value, runtimeAttrs] = node.builder.runtimeValues(node);
461
481
  const [, resolvedAttrs] = renderer._handleMeta(node, runtimeAttrs);
462
482
  const resolved = this.#resolvedAttributes.get(node);
@@ -471,17 +491,55 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
471
491
  let attrs = node._getMeta('subbuilder') ? resolvedAttrs : renderer.adaptAttrs(resolvedAttrs);
472
492
  const branch = node.value instanceof SourceBag;
473
493
  let text = branch ? [] : this.expressionValue(node, value);
474
- if (renderer === this) [text, attrs] = displayItem(text, this.restoreNativeAttributes(node, attrs));
494
+ if (renderer === this) {
495
+ attrs = this.restoreNativeAttributes(node, attrs);
496
+ if (!node._getMeta('gramlot_component')) [text, attrs] = displayItem(text, attrs,
497
+ (value, options) => this._binding.gramlot.format(value, options));
498
+ }
499
+ attrs = this.componentAttributes(node, attrs);
475
500
  this.html.update(record, node, attrs, branch ? attrs._text : text, resolved.visible ?? null);
476
501
  this.#projectControl(record, node, attrs, change);
477
502
  record.control?.refresh();
478
503
  record.button?.refresh();
479
504
  this.#connectEvents(record);
505
+ const defaults = this.#presentationDefaults.get(node);
506
+ if (defaults) {
507
+ const changed = new Set([...Object.keys(previousDefaults ?? {}), ...Object.keys(defaults)]
508
+ .filter(name => !Object.is(previousDefaults?.[name], defaults[name])));
509
+ if (changed.size) this.#refreshPresentation(node, changed);
510
+ }
480
511
  if (record.element.localName === 'option' || record.element.localName === 'optgroup') {
481
512
  this.#optionsChanged(record.parent);
482
513
  }
483
514
  }
484
515
 
516
+ /** Only affected consumers project; nested providers mask their own declared defaults. */
517
+ #refreshPresentation(parent, changed) {
518
+ if (!(parent.value instanceof SourceBag)) return;
519
+ for (const child of parent.value.getNodes()) {
520
+ const component = child._getMeta('gramlot_component');
521
+ const declared = child.getAttr();
522
+ let inherited = changed;
523
+ if (component?.presentationDefaults.length) {
524
+ inherited = new Set([...changed].filter(name => !Object.hasOwn(declared, name)));
525
+ } else if (component?.parameters.value?.binding === 'twoWay'
526
+ && [...changed].some(name => !Object.hasOwn(declared, name))) {
527
+ this.project(child);
528
+ }
529
+ if (inherited.size) this.#refreshPresentation(child, inherited);
530
+ }
531
+ }
532
+
533
+ /** Component parameters use resolved Source values, before HTML-only filtering (e.g. validate_*). */
534
+ componentAttributes(node, attrs) {
535
+ const component = node._getMeta('gramlot_component');
536
+ if (!component) return attrs;
537
+ const resolved = this.#resolvedAttributes.get(node);
538
+ const parameters = Object.fromEntries([...new Set([...Object.keys(component.parameters), ...Object.keys(resolved).filter(name => name.startsWith('validate_'))])]
539
+ .filter(name => Object.hasOwn(resolved, name)).map(name => [name, resolved[name]]));
540
+ return {...attrs, ...parameters};
541
+ }
542
+
485
543
  /**
486
544
  * The resolved `value` to the ControlAdapter of `record` when the node declares a `value`, or declared
487
545
  * one at the previous projection: its removal shows the control empty once, as html.js did (S10).
@@ -608,6 +666,8 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
608
666
  record.end?.remove();
609
667
  record.parent?.children.delete(node);
610
668
  this.records.delete(node);
669
+ this.#resolvedAttributes.delete(node);
670
+ this.#presentationDefaults.delete(node);
611
671
  if (errors.length) throw new AggregateError(errors, 'Source cleanup failed');
612
672
  }
613
673
 
@@ -58,10 +58,15 @@ export interface GramlotServerOptions {
58
58
  pageTtl?: number;
59
59
  /** Maximum number of registered pages. */
60
60
  maxPages?: number;
61
+ /** Application collections: generated Builder grammar and root-relative browser module URL. */
62
+ collections?: {grammar: Record<string, unknown>; module: string}[];
61
63
  }
62
64
 
63
65
  /** The result of `registerPage`. */
64
66
  export interface RegisteredPage {
67
+ devices?: Array<'desktop' | 'tablet' | 'phone'>;
68
+ locale?: string;
69
+ timeZone?: string;
65
70
  /** The id of the registered page. */
66
71
  pageId: string;
67
72
  /** The title of the page. */
@@ -64,7 +64,7 @@ const prefixed = (prefix, url) => url.startsWith('/') && !url.startsWith('//') ?
64
64
  */
65
65
  export class GramlotServer {
66
66
  constructor({runtimeUrl = '/assets/gramlot.js', rpcUrl = '/gramlot/rpc', closeUrl = '/gramlot/close',
67
- rootId = 'gramlot-root', pageTtl = 1800, maxPages = 1000} = {}) {
67
+ rootId = 'gramlot-root', pageTtl = 1800, maxPages = 1000, collections = []} = {}) {
68
68
  if (typeof pageTtl !== 'number' || pageTtl <= 0 ||
69
69
  !Number.isFinite(performance.now() + pageTtl * 1000) ||
70
70
  !Number.isSafeInteger(maxPages) || maxPages < 1) {
@@ -72,6 +72,7 @@ export class GramlotServer {
72
72
  }
73
73
  Object.assign(this, {runtimeUrl, rpcUrl, closeUrl, rootId, pageTtl, maxPages});
74
74
  this.pages = new Map();
75
+ this.collections = [...collections];
75
76
  }
76
77
 
77
78
  /** The Page class of path, or PageNotFound. */
@@ -122,25 +123,32 @@ export class GramlotServer {
122
123
  throw new TypeError('Page modules must export a subclass of Page');
123
124
  }
124
125
  const resources = loadOrder(await this.resolveResources(path, PageClass));
126
+ if (this.collections.length) resources.collections = this.collections.map(item => item.module);
125
127
  this.prune();
126
128
  if (this.pages.size >= this.maxPages) throw new ServerCapacity('Page registry capacity reached');
127
129
  const pageId = crypto.randomUUID().replaceAll('-', '');
128
130
  this.pages.set(pageId, {PageClass, owner, expires: performance.now() + this.pageTtl * 1000});
129
- return {pageId, title: PageClass.title, resources};
131
+ return {pageId, title: PageClass.title, resources,
132
+ ...(PageClass.devices.length ? {devices: [...PageClass.devices]} : {}),
133
+ ...(PageClass.locale == null ? {} : {locale: PageClass.locale}),
134
+ ...(PageClass.timeZone == null ? {} : {timeZone: PageClass.timeZone})};
130
135
  }
131
136
 
132
137
  /** Register the page and return its bootstrap. prefix is the mount prefix chosen
133
138
  * by the adapter, added once to the root-relative bootstrap URLs. */
134
139
  async openPage(path, {owner = null, prefix = ''} = {}) {
135
140
  if (typeof prefix !== 'string') throw new TypeError('Mount prefix must be a string');
136
- const {pageId, title, resources} = await this.registerPage(path, {owner});
141
+ const {pageId, title, resources, locale, timeZone, devices} = await this.registerPage(path, {owner});
137
142
  try {
138
143
  const nonce = createNonce();
139
144
  // The CSS links and the JS modules reach the page through PageBootstrap (§4.12, D9).
140
145
  const bootstrap = scriptJson({
141
146
  config: {pageId, rpcUrl: prefixed(prefix, this.rpcUrl), closeUrl: prefixed(prefix, this.closeUrl),
142
- rootId: this.rootId, capabilities: this.capabilities},
143
- resources: {css: resources.css.map(url => prefixed(prefix, url)),
147
+ rootId: this.rootId, capabilities: this.capabilities,
148
+ ...(devices === undefined ? {} : {devices}),
149
+ ...(locale === undefined ? {} : {locale}), ...(timeZone === undefined ? {} : {timeZone})},
150
+ resources: {...(resources.collections ? {collections: resources.collections.map(url => prefixed(prefix, url))} : {}),
151
+ css: resources.css.map(url => prefixed(prefix, url)),
144
152
  js: resources.js.map(({url, group}) => ({url: prefixed(prefix, url), group}))},
145
153
  });
146
154
  const document = new GramlotBuilder();
@@ -211,6 +219,7 @@ export class GramlotServer {
211
219
  if (!source) return callable.call(page, params);
212
220
  const builder = new record.PageClass.sourceBuilder(name,
213
221
  {auth: elementRule => this.#authOutcome(elementRule, owner)});
222
+ for (const collection of this.collections) builder.loadCollection(collection.grammar);
214
223
  const result = await callable.call(page, builder.root, params);
215
224
  if (result !== undefined && result !== null) throw new TypeError('Source methods populate root and return no value');
216
225
  return builder.toTytx();
@@ -9,6 +9,7 @@ export class IndexPage extends Page {
9
9
  introduction(pane: any): void;
10
10
  groupPanel(pane: any, group: IndexGroup): void;
11
11
  panel(pane: any, item: IndexItem): void;
12
+ header(shell: any): void;
12
13
  footer(pane: any): void;
13
14
  behavior(pane: any): void;
14
15
  }
@@ -12,6 +12,7 @@ export class IndexPage extends GramlotPage {
12
12
  main(root) {
13
13
  const families = this.constructor.navigation;
14
14
  const shell = root.div({class: 'index-shell', id: this.constructor.shellId});
15
+ this.header(shell);
15
16
  const sidebar = shell.aside({class: 'index-sidebar', id: 'index-sidebar'});
16
17
  const brand = sidebar.header();
17
18
  if (this.constructor.logoUrl) brand.img({src: this.constructor.logoUrl, alt: this.constructor.title, class: 'index-logo'});
@@ -33,12 +34,12 @@ export class IndexPage extends GramlotPage {
33
34
  aria_valuemin: 120, aria_valuemax: 460, aria_valuenow: 240});
34
35
  const content = shell.main({class: 'index-main'});
35
36
  const tabs = content.div({class: 'index-tabs', role: 'tablist', aria_label: 'Open pages'});
36
- tabs.button('Introduction', {type: 'button', role: 'tab', id: 'tab-intro',
37
+ tabs.html_button('Introduction', {type: 'button', role: 'tab', id: 'tab-intro',
37
38
  aria_controls: 'panel-intro',
38
39
  aria_selected: 'true', tabindex: -1, hidden: false});
39
40
  for (const family of families) {
40
41
  for (const {key, title} of [family, ...family.children]) {
41
- tabs.button(title, {type: 'button', role: 'tab', id: `tab-${key}`,
42
+ tabs.html_button(title, {type: 'button', role: 'tab', id: `tab-${key}`,
42
43
  aria_controls: `panel-${key}`,
43
44
  aria_selected: 'false', tabindex: -1, hidden: true});
44
45
  }
@@ -61,6 +62,8 @@ export class IndexPage extends GramlotPage {
61
62
  this.behavior(shell);
62
63
  }
63
64
 
65
+ header(shell) {}
66
+
64
67
  behavior(shell) {
65
68
  shell.dataController({func: 'indexMount', _onStart: true, shell_id: this.constructor.shellId});
66
69
  }
@@ -75,6 +78,8 @@ export class IndexPage extends GramlotPage {
75
78
  const appearance = theme.select({id: 'index-appearance', value: 'compact'});
76
79
  appearance.option('Base', {value: 'base', selected: false});
77
80
  appearance.option('Compact', {value: 'compact', selected: true});
81
+ appearance.option('mimi', {value: 'mimi'});
82
+ appearance.option('joanna', {value: 'joanna'});
78
83
  const color = footer.div({class: 'index-theme'});
79
84
  color.html_label('Color mode', {for: 'index-theme'});
80
85
  const choices = color.select({id: 'index-theme', value: 'light'});
@@ -88,7 +93,7 @@ export class IndexPage extends GramlotPage {
88
93
  if (this.constructor.installable) {
89
94
  const app = footer.details({class: 'index-install'});
90
95
  app.summary('Install app');
91
- app.button('Install', {type: 'button', id: 'index-install-button', hidden: true});
96
+ app.html_button('Install', {type: 'button', id: 'index-install-button', hidden: true});
92
97
  app.p('', {id: 'index-install-status', role: 'status'});
93
98
  app.p('Chrome: use Install page as app in the browser menu. Safari on macOS Sonoma or later: File > Add to Dock.');
94
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.');
@@ -48,6 +48,9 @@ function declare(PageClass, methodName, marker, auth) {
48
48
  /** Server-side page base; unrelated to browser view components. */
49
49
  export class Page {
50
50
  static title = 'Gramlot';
51
+ static devices = [];
52
+ static locale = null;
53
+ static timeZone = null;
51
54
  static installable = false;
52
55
  static appIcon = null;
53
56
 
@@ -19,6 +19,9 @@ export function endpointMethod(page: Page, name: string): Function | null;
19
19
  export class Page {
20
20
  /** The title of the page document. */
21
21
  static title: string;
22
+ static devices: Array<'desktop' | 'tablet' | 'phone'>;
23
+ static locale: string | null;
24
+ static timeZone: string | null;
22
25
  static installable: boolean;
23
26
  static appIcon: string | null;
24
27
  manifest(options?: {baseUrl?: string}): Record<string, unknown> | Promise<Record<string, unknown>>;
@@ -22,6 +22,8 @@ export function parseRequires(text: string): string[];
22
22
  export interface Resources {
23
23
  /** CSS URLs. */
24
24
  css: string[];
25
+ /** Application collection module URLs, added by GramlotServer. */
26
+ collections?: string[];
25
27
  /** JS module URLs with their Logic group. */
26
28
  js: {url: string; group: string | null}[];
27
29
  }
@@ -1,16 +1,9 @@
1
- /**
2
- * The click of a `<button>` (source plan §2 Button, §4.11, S12). One mechanism per button (P10): the
3
- * `dataController` or `dataRpc` nested in it, `action`, or the `fire`/`fire_*` family. The nested
4
- * provider is a normal ControllerProvider or RpcProvider (B7); the click is one more trigger. Controller, `action` and counter use
5
- * the button's own node, also when the click hits a descendant (R11).
6
- *
7
- * R3, provisional: only a button with a mechanism gets `type="button"` when the author wrote no
8
- * `type`, and its click stops propagating; no `preventDefault`. A button without a mechanism stays
9
- * native. A closed NodeBinding does nothing (R12).
1
+ /** Shared command engine for the built-in button components (GC-310 §045).
2
+ * One action, nested provider or fire mechanism. Components own presentation and
3
+ * target selection; this binding owns execution, ask, delay and disposal.
10
4
  */
11
5
 
12
6
  import {AskDialog} from '../binding/ask-dialog.js';
13
- import {XHTML_NS} from '../renderer/attributes.js';
14
7
 
15
8
  export class ButtonBinding {
16
9
  #binding;
@@ -21,7 +14,7 @@ export class ButtonBinding {
21
14
  /** The binding of a Gramlot button; html_button remains native despite its DOM tag. */
22
15
  static for(binding, record) {
23
16
  const element = record.element;
24
- if (binding.node.nodeTag !== 'button' || element?.namespaceURI !== XHTML_NS || element.localName !== 'button') return null;
17
+ if (!element?.constructor.gramlotComponent?.command) return null;
25
18
  return new ButtonBinding(binding, record);
26
19
  }
27
20
 
@@ -65,6 +58,8 @@ export class ButtonBinding {
65
58
  /** Check the mechanism, apply R3's `type`, then listen to `click`. */
66
59
  attach() {
67
60
  this.refresh();
61
+ this.element.activateCommand = event => this.onClick(event);
62
+ this.element.attachCommand();
68
63
  this.element.addEventListener('click', this);
69
64
  }
70
65
 
@@ -81,6 +76,8 @@ export class ButtonBinding {
81
76
 
82
77
  detach() {
83
78
  this.element.removeEventListener('click', this);
79
+ this.element.releaseCommand();
80
+ delete this.element.activateCommand;
84
81
  this.#cancelDelay?.();
85
82
  }
86
83
 
@@ -94,7 +91,14 @@ export class ButtonBinding {
94
91
  * the mechanism. An error propagates from the listener.
95
92
  */
96
93
  onClick(event) {
97
- if (this.binding.closed) return;
94
+ if (this.binding.closed || this.element.disabled) return;
95
+ const target = this.element.commandTarget(event);
96
+ if (target === null) return;
97
+ if (target !== this.element) {
98
+ event.stopPropagation();
99
+ return target.activateCommand(event);
100
+ }
101
+ if (!this.element.prepareCommand(event)) return;
98
102
  const mechanism = this.mechanism;
99
103
  if (!mechanism) return;
100
104
  event.stopPropagation();
@@ -144,7 +148,7 @@ export class ButtonBinding {
144
148
  return {...this.binding.runtime.renderer.references.resolveArguments(authored), event, _counter: counter, modifiers};
145
149
  };
146
150
  const execute = result => {
147
- if (this.binding.closed || result === null) return;
151
+ if (this.binding.closed || this.element.disabled || result === null) return;
148
152
  const values = {...read(), ...result};
149
153
  if (result) values._askResult = result;
150
154
  this.binding.runtime.inlineCompiler.compile(node, 'action', node.getAttr('action'), Object.keys(values))(values);