@gramlot/gramlot 0.3.0 → 0.3.2

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.
@@ -42,7 +42,9 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
42
42
  this._binding = binding;
43
43
  this.source = source;
44
44
  this.destination = destination;
45
- this.html = new HtmlElement({metadataAttributes: ['__ref']});
45
+ this.html = new HtmlElement({metadataAttributes: ['__ref'],
46
+ invokeScript: (node, name, code, keywords) => this.inlineCompiler.compile(
47
+ node, name, code, node.parentNode._getMeta('gramlot_component').childParameters[name].inline)(keywords)});
46
48
  this.records = new Map();
47
49
  this.references = new References(source);
48
50
  this.pending = [];
@@ -533,9 +535,10 @@ export class GramlotRenderer extends GramlotHtmlRenderer {
533
535
  /** Component parameters use resolved Source values, before HTML-only filtering (e.g. validate_*). */
534
536
  componentAttributes(node, attrs) {
535
537
  const component = node._getMeta('gramlot_component');
536
- if (!component) return attrs;
538
+ const childParameters = node.parentNode?._getMeta('gramlot_component')?.childParameters;
539
+ if (!component && !childParameters) return attrs;
537
540
  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_'))])]
541
+ const parameters = Object.fromEntries([...new Set([...Object.keys(component?.parameters ?? {}), ...Object.keys(childParameters ?? {}), ...Object.keys(resolved).filter(name => name.startsWith('validate_'))])]
539
542
  .filter(name => Object.hasOwn(resolved, name)).map(name => [name, resolved[name]]));
540
543
  return {...attrs, ...parameters};
541
544
  }
@@ -155,6 +155,7 @@ export class GramlotServer {
155
155
  const root = document.root.html();
156
156
  const head = root.head();
157
157
  head.meta({charset: 'utf-8'});
158
+ head.meta({name: 'viewport', content: 'width=device-width,initial-scale=1'});
158
159
  head.title(title);
159
160
  if (['', 'index'].includes(path.replace(/^\/+|\/+$/g, '')) && this.pages.get(pageId).PageClass.installable === true) {
160
161
  head.link({rel: 'manifest', href: prefix + '/app.webmanifest'});
package/src/view/html.js CHANGED
@@ -36,7 +36,8 @@ function domPropertyName(name) {
36
36
  * names and style arrive adapted by the renderers (GramlotHtmlRenderer, GramlotSvgRenderer).
37
37
  */
38
38
  export class HtmlElement {
39
- constructor({metadataAttributes = []} = {}) {
39
+ constructor({metadataAttributes = [], invokeScript = null} = {}) {
40
+ this.invokeScript = invokeScript;
40
41
  this.metadataAttributes = new Set([...META_ATTRS, '_text', ...metadataAttributes]);
41
42
  }
42
43
 
@@ -90,6 +91,17 @@ export class HtmlElement {
90
91
  return node.getRelativeData('.');
91
92
  };
92
93
  }
94
+ if (meta.gramlot_component?.sourceContext) {
95
+ element.setSourceContext({
96
+ publish: (topic, payload) => node.publish(topic, payload),
97
+ writeParameter: (name, value) => {
98
+ const pointer = node.getAttr(name);
99
+ if (node.pointerType(pointer) === '^' && !Object.is(node.getRelativeData(pointer.slice(1)), value)) {
100
+ node.setRelativeData(pointer.slice(1), value);
101
+ }
102
+ },
103
+ });
104
+ }
93
105
  const text = document.createTextNode(this.text(node));
94
106
  if (namespace !== XHTML_NS || !meta.void) element.append(text);
95
107
  const record = {element, text, tag};
@@ -119,13 +131,25 @@ export class HtmlElement {
119
131
  const isHtml = element.namespaceURI === XHTML_NS;
120
132
  const renderAttributes = this.definition(node).meta.render_attributes ?? {};
121
133
  const previous = record.attrs ?? {};
122
- if (this.definition(node).meta.gramlot_component) {
123
- attrs = element.projectAttributes(attrs, values => {
124
- requireNoScriptAttributes(node, values, node.builder.constructor.dialectPrefixes);
125
- requireStyleClassAttributes(node, values, node.builder.constructor.dialectPrefixes);
126
- return node.builder.renderer_html.adaptAttrs(values);
134
+ const adapt = values => {
135
+ requireNoScriptAttributes(node, values, node.builder.constructor.dialectPrefixes);
136
+ requireStyleClassAttributes(node, values, node.builder.constructor.dialectPrefixes);
137
+ return node.builder.renderer_html.adaptAttrs(values);
138
+ };
139
+ const parent = node.parentNode;
140
+ if (parent?._getMeta('gramlot_component')?.childParameters) {
141
+ const Parent = element.ownerDocument.defaultView.customElements.get(parent._getMeta('render_tag'));
142
+ attrs = Parent.projectChild(element, attrs, {
143
+ adapt,
144
+ invoke: (name, code, keywords) => this.invokeScript(node, name, code, keywords),
145
+ publish: (topic, payload) => node.publish(topic, payload),
146
+ publishParent: (topic, payload) => parent.publish(topic, payload),
147
+ remove: () => node.parentBag.popNode(node.label),
127
148
  });
128
149
  }
150
+ if (this.definition(node).meta.gramlot_component) {
151
+ attrs = element.projectAttributes(attrs, adapt);
152
+ }
129
153
  attrs = Object.fromEntries(sourceAttributeItems({...attrs, ...renderAttributes}));
130
154
  const controlled = ControlAdapter.classFor(element, attrs) !== null;
131
155
  if (textValue === DEFAULT_TEXT) textValue = this.text(node);
@@ -271,12 +271,13 @@
271
271
 
272
272
  /* Interaction density is independent of the selected color/profile theme. */
273
273
  @layer gramlot.touch {
274
- :root[data-gramlot-touch="on"] {--gramlot-touch-target:44px; --gramlot-field-height:44px; --gramlot-field-font-size:16px;
274
+ :root[data-gramlot-touch="off"] {--gramlot-drawer-reveal:0;}
275
+ :root[data-gramlot-touch="on"] {--gramlot-drawer-reveal:1;--gramlot-touch-target:44px; --gramlot-field-height:44px; --gramlot-field-font-size:16px;
275
276
  --gramlot-field-padding:8px 10px; --gramlot-field-line-height:1.35;
276
277
  --gramlot-label-size:14px; --gramlot-label-gap:6px; --gramlot-space-2:10px;
277
278
  --gramlot-calendar-width:322px; --gramlot-choice-toggle-width:44px;}
278
279
  @media (pointer: coarse) {
279
- :root:not([data-gramlot-touch="off"]) {--gramlot-touch-target:44px; --gramlot-field-height:44px; --gramlot-field-font-size:16px;
280
+ :root:not([data-gramlot-touch="off"]) {--gramlot-drawer-reveal:1;--gramlot-touch-target:44px; --gramlot-field-height:44px; --gramlot-field-font-size:16px;
280
281
  --gramlot-field-padding:8px 10px; --gramlot-field-line-height:1.35;
281
282
  --gramlot-label-size:14px; --gramlot-label-gap:6px; --gramlot-space-2:10px;
282
283
  --gramlot-calendar-width:322px; --gramlot-choice-toggle-width:44px;}
@@ -1,6 +1,15 @@
1
1
  /* Gramlot adaptation of legacy joanna; load after Base and Compact. */
2
2
  @layer gramlot.tokens {
3
3
  :root {
4
+ --gramlot-tab-height: 26px;
5
+ --gramlot-tab-padding: 3px 10px;
6
+ --gramlot-tab-radius: 6px;
7
+ --gramlot-tab-gap: 2px;
8
+ --gramlot-tab-strip-padding: 3px;
9
+ --gramlot-tab-background: var(--gramlot-background);
10
+ --gramlot-tab-selected-background: var(--gramlot-surface);
11
+ --gramlot-tab-selected-color: var(--gramlot-ink);
12
+ --gramlot-tab-border: var(--gramlot-border);
4
13
  --gramlot-background: #F2F2F7;
5
14
  --gramlot-surface: #FFFFFF;
6
15
  --gramlot-surface-subtle: #F2F2F7;
@@ -1,6 +1,15 @@
1
1
  /* Gramlot adaptation of legacy mimi; load after Base and Compact. */
2
2
  @layer gramlot.tokens {
3
3
  :root {
4
+ --gramlot-tab-height: 24px;
5
+ --gramlot-tab-padding: 3px 10px;
6
+ --gramlot-tab-radius: 3px;
7
+ --gramlot-tab-gap: 2px;
8
+ --gramlot-tab-strip-padding: 3px;
9
+ --gramlot-tab-background: var(--gramlot-background);
10
+ --gramlot-tab-selected-background: var(--gramlot-surface);
11
+ --gramlot-tab-selected-color: var(--gramlot-ink);
12
+ --gramlot-tab-border: var(--gramlot-border);
4
13
  --gramlot-background: #EDEEF0;
5
14
  --gramlot-surface: #F5F5F6;
6
15
  --gramlot-surface-subtle: #E0E1E3;