@gramlot/gramlot 0.3.6 → 0.3.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gramlot/gramlot",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "Declarative HTML/SVG interfaces with live data binding, authored in JavaScript or Python.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -17,8 +17,9 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@genrojs/bag": ">=0.11.0",
20
- "@genrojs/builders": ">=0.6.0",
21
- "@genrojs/tytx": ">=0.16.3"
20
+ "@genrojs/builders": ">=0.7.0",
21
+ "@genrojs/tytx": ">=0.16.3",
22
+ "dompurify": "3.4.16"
22
23
  },
23
24
  "devDependencies": {
24
25
  "c8": "10.1.3",
@@ -38,7 +39,8 @@
38
39
  "./tools/inspector-agent": "./tools/inspector-agent.js",
39
40
  "./components": "./src/components/index.js",
40
41
  "./components/inputs": "./src/components/inputs.js",
41
- "./components/layout": "./src/components/layout.js"
42
+ "./components/layout": "./src/components/layout.js",
43
+ "./components/tree": "./src/components/tree.js"
42
44
  },
43
45
  "files": [
44
46
  "LICENSE",
@@ -82,7 +82,7 @@ export class AskDialog {
82
82
  release = binding.track(() => finish(false));
83
83
  try {
84
84
  const builder = new GramlotBuilder();
85
- const dialog = builder.root.dialog({node_id: id, datapath: id, request: id,
85
+ const dialog = builder.root.dialog({nodeId: id, datapath: id, request: id,
86
86
  connect_oncancel: `${group}.cancel`, connect_onclose: `${group}.cancel`,
87
87
  class: 'gramlot-ask', 'aria-labelledby': `${id}_title`,
88
88
  style: 'border:1px solid #aab4c2;border-radius:8px;padding:16px;max-width:32rem;width:calc(100% - 48px);font:inherit;'});
@@ -0,0 +1,52 @@
1
+ import {BagResolver} from '@genrojs/bag';
2
+
3
+ /** Shared asynchronous endpoint cache; subclasses own request scheduling and lifetime. */
4
+ export class RemoteResolver extends BagResolver {
5
+ static classKwargs = {...BagResolver.classKwargs, asBag: false};
6
+ constructor({cacheTime, onError}) {
7
+ super({cacheTime: cacheTime ?? -1});
8
+ this.onError = onError;
9
+ this.loading = null;
10
+ this.loaded = false;
11
+ this.writing = false;
12
+ }
13
+ resolve({static: isStatic = false} = {}) {
14
+ if (!isStatic && !this.closed && !this.loading && !this.writing && this.expired) this.refresh();
15
+ return this.cachedValue;
16
+ }
17
+ refresh() {
18
+ if (this.closed) return null;
19
+ const loading = this.startLoad(request => this.#load(request));
20
+ if (loading === null) return null;
21
+ const settle = () => { if (this.loading === loading) this.loading = null; };
22
+ loading.then(settle, settle);
23
+ this.loading = loading;
24
+ loading.catch(error => { if (error?.name !== 'AbortError') this.onError(error); });
25
+ return loading;
26
+ }
27
+ resolveSync(options) { return super.resolve(options); }
28
+ prepareValue(value) { return value; }
29
+ #fingerprint() {
30
+ const kwargs = {...this._kw};
31
+ for (const [name, value] of Object.entries(this.node?.attr ?? {})) {
32
+ if (!this.constructor.internalParams.has(name)) kwargs[name] = value;
33
+ }
34
+ return this._computeEffectiveFingerprint(kwargs);
35
+ }
36
+ async #load(request) {
37
+ if (this.closed) return undefined;
38
+ const fingerprint = this.#fingerprint();
39
+ const received = await this.loadAsync(request);
40
+ if (this.closed || request.ignored) return undefined;
41
+ const value = this.prepareValue(received);
42
+ this._lastUpdate = Date.now();
43
+ this._lastEffectiveFingerprint = fingerprint;
44
+ this.loaded = true;
45
+ this.writing = true;
46
+ try {
47
+ if (this.node) this.node.setValue(value, this.cacheTime !== 0);
48
+ else this.cachedValue = value;
49
+ } finally { this.writing = false; }
50
+ return value;
51
+ }
52
+ }
@@ -27,19 +27,23 @@ export class DataRegistration {
27
27
  #recipient;
28
28
  #order;
29
29
  #active = true;
30
+ #subtree;
30
31
 
31
- constructor(router, {path, attr, recipient, order}) {
32
+ constructor(router, {path, attr, recipient, order, subtree = false}) {
32
33
  this.#router = router;
33
34
  this.#path = path;
34
35
  this.#attr = attr;
35
36
  this.#recipient = recipient;
36
37
  this.#order = order;
38
+ this.#subtree = subtree;
37
39
  }
38
40
 
39
41
  get router() { return this.#router; }
40
42
  get path() { return this.#path; }
41
43
  get attr() { return this.#attr; }
42
44
  get recipient() { return this.#recipient; }
45
+ /** Store registration: structural, value and attribute events throughout the subtree. */
46
+ get subtree() { return this.#subtree; }
43
47
  get active() { return this.#active; }
44
48
  /** Registration order, which is also the delivery order of one event. */
45
49
  get order() { return this.#order; }
@@ -82,8 +86,10 @@ export class DataRouter {
82
86
  /** Active registrations. */
83
87
  get size() { return this.#size; }
84
88
 
85
- /** Register `recipient` on the absolute Data `path` (without `_root_`), optionally on its attribute `attr`. */
86
- register({path, attr = null, recipient}) {
89
+ /** Register on an absolute Data path, optionally on an attribute.
90
+ * `subtree` includes descendant attribute events for Bag-backed components.
91
+ */
92
+ register({path, attr = null, recipient, subtree = false}) {
87
93
  if (typeof path !== 'string' || path === '') throw new TypeError(`A Data registration requires a path: ${path}`);
88
94
  let route = this.#root;
89
95
  for (const segment of path.split('.')) {
@@ -95,7 +101,7 @@ export class DataRouter {
95
101
  route = next;
96
102
  }
97
103
  this.#order += 1;
98
- const registration = new DataRegistration(this, {path, attr, recipient, order: this.#order});
104
+ const registration = new DataRegistration(this, {path, attr, recipient, order: this.#order, subtree});
99
105
  route.registrations.add(registration);
100
106
  this.#routes.set(registration, route);
101
107
  this.#size += 1;
@@ -176,6 +182,7 @@ export class DataRouter {
176
182
  */
177
183
  #accepts(registration, level, event) {
178
184
  const {evt} = event;
185
+ if (registration.subtree) return level !== 'container' || evt !== 'upd_attrs';
179
186
  if (registration.attr === null) {
180
187
  if (evt === 'upd_attrs') return false;
181
188
  return !(level === 'child' && event.fired);
@@ -1,4 +1,4 @@
1
- import {BagResolver} from '@genrojs/bag';
1
+ import {RemoteResolver} from './remote-resolver.js';
2
2
 
3
3
  /**
4
4
  * The resolver a `dataRemote` installs on its Data node: the value is the answer of the endpoint
@@ -29,114 +29,35 @@ import {BagResolver} from '@genrojs/bag';
29
29
  * nothing: `loading` rejects with its error and `onError` receives it. A load aborted by the removal of the
30
30
  * node writes nothing, even when its answer had already arrived; a load ignored by `cancel()` writes nothing.
31
31
  */
32
- export class RpcResolver extends BagResolver {
33
- static classKwargs = {...BagResolver.classKwargs, asBag: false};
34
- static internalParams = new Set([...BagResolver.internalParams, 'binding', 'method', 'params', 'onCalling', 'onError',
35
- 'sync']);
36
-
32
+ export class RpcResolver extends RemoteResolver {
33
+ static internalParams = new Set([...RemoteResolver.internalParams, 'binding', 'method', 'params', 'onCalling', 'onError', 'sync']);
37
34
  constructor({binding, method, params, cacheTime, onCalling = null, onError, sync = false}) {
38
- // null: resolve once, as a negative cacheTime.
39
- super({cacheTime: cacheTime ?? -1});
40
- // The NodeBinding of the `dataRemote` node.
35
+ super({cacheTime, onError});
41
36
  this.binding = binding;
42
- // A read waits for the answer of a synchronous call.
43
37
  this.sync = sync;
44
38
  this.method = method;
45
39
  this.params = params;
46
40
  this.onCalling = onCalling;
47
- // Receives the error of a failed load, never an abort.
48
- this.onError = onError;
49
- // The promise of the load in flight or waiting, or null.
50
- this.loading = null;
51
- // A load has written its value; the loaded value is being written.
52
- this.loaded = false;
53
- this.writing = false;
54
41
  }
55
-
56
- /**
57
- * The current value. With `sync` an expired read calls the endpoint and returns its value (BagResolver
58
- * `resolve`, then `load`); without, it starts the load and returns the current value. A static read, or
59
- * a read during a load or its write, returns the current value.
60
- */
42
+ get closed() { return this.binding.closed; }
61
43
  resolve(options = {}) {
62
- const {static: isStatic = false} = options;
63
- if (isStatic || this.loading || this.writing) return this.cachedValue;
64
- if (!this.sync) {
65
- if (this.expired) this.refresh();
66
- return this.cachedValue;
67
- }
44
+ if (!this.sync) return super.resolve(options);
45
+ if (options.static || this.loading || this.writing) return this.cachedValue;
68
46
  if (this.expired && !this.binding.node.requests.calling(this.onCalling)) return this.cachedValue;
69
- return super.resolve(options);
47
+ // A synchronous read uses BagResolver's normal cache and load path.
48
+ return super.resolveSync(options);
70
49
  }
71
-
72
- /** The synchronous call of a `sync` read: BagResolver `resolve` stores the value it returns. */
73
50
  load() {
74
51
  let value;
75
- try {
76
- value = this.binding.callSync('data', this.method, this.params);
77
- } catch (error) {
78
- this.onError(error);
79
- }
52
+ try { value = this.binding.callSync('data', this.method, this.params); }
53
+ catch (error) { this.onError(error); }
80
54
  this.loaded = true;
81
55
  return value;
82
56
  }
83
-
84
- /**
85
- * Start a load and write its value on the node, with the Data event unless `cacheTime` is 0; returns
86
- * `loading`, which settles with the written value, or undefined when nothing was written. A false
87
- * `_onCalling` starts no load and returns null.
88
- */
89
- refresh() {
57
+ startLoad(perform) {
90
58
  const requests = this.binding.node.requests;
91
59
  if (!requests.calling(this.onCalling)) return null;
92
- const loading = requests.submit(this.method, this.params, request => this.#load(request));
93
- const settle = () => {
94
- if (this.loading === loading) this.loading = null;
95
- };
96
- loading.then(settle, settle);
97
- this.loading = loading;
98
- // A load nobody awaits: its failure reaches `onError`, an abort is not a failure.
99
- loading.catch(error => {
100
- if (error?.name !== 'AbortError') this.onError(error);
101
- });
102
- return loading;
103
- }
104
-
105
- /**
106
- * The fingerprint of the parameters of a read without call kwargs, as `BagResolver.resolve` computes it:
107
- * the kwargs of the resolver and the attributes of its node that are not internal.
108
- */
109
- #fingerprint() {
110
- const kwargs = {...this._kw};
111
- for (const [name, value] of Object.entries(this.node?.attr ?? {})) {
112
- if (!this.constructor.internalParams.has(name)) kwargs[name] = value;
113
- }
114
- return this._computeEffectiveFingerprint(kwargs);
115
- }
116
-
117
- /** The asynchronous call of the endpoint with the params given at construction; the read kwargs are not sent. */
118
- async #load(request) {
119
- const binding = this.binding;
120
- // A waiting load of a node that left the Source sends nothing.
121
- if (binding.closed) return undefined;
122
- // The parameters of this load, as `resolve` takes them before a load: the value answers these.
123
- const fingerprint = this.#fingerprint();
124
- const value = await binding.call('data', request);
125
- if (binding.closed || request.ignored) return undefined;
126
- // The cache time and the fingerprint of the parameters of BagResolver: no public member records a load made
127
- // outside `resolve`. A `sync` read loads through `resolve`, which records both and does not write them here;
128
- // this asynchronous load is a debt of the async-resolvers plan. Without the fingerprint, the first explicit
129
- // read after this load finds another one, loads again and sends a call the cache should have answered.
130
- this._lastUpdate = Date.now();
131
- this._lastEffectiveFingerprint = fingerprint;
132
- this.loaded = true;
133
- this.writing = true;
134
- try {
135
- if (this.node) this.node.setValue(value, this.cacheTime !== 0);
136
- else this.cachedValue = value;
137
- } finally {
138
- this.writing = false;
139
- }
140
- return value;
60
+ return requests.submit(this.method, this.params, perform);
141
61
  }
62
+ loadAsync(request) { return this.binding.call('data', request); }
142
63
  }
@@ -16,14 +16,14 @@ const PROVIDERS = {
16
16
  };
17
17
 
18
18
  // Attributes whose change moves the Data context of a whole branch (§4.4, upd_attrs row).
19
- const CONTEXT_ATTRIBUTES = ['datapath', '_anchor', 'node_id', 'form', 'formId'];
19
+ const CONTEXT_ATTRIBUTES = ['datapath', '_anchor', 'nodeId', 'form', 'formId'];
20
20
 
21
21
  /**
22
22
  * Semantic lifetime of one Gramlot page (source plan §4.4).
23
23
  *
24
24
  * The runtime owns the one Data subscription of the page, on Builder's Data
25
25
  * wrapper (`_dataroot` → `_root_` → `builder.data`), the DataRouter it feeds,
26
- * the `node_id → node` map of the Source (R06) and one NodeBinding per Source
26
+ * the `nodeId → node` map of the Source (R06) and one NodeBinding per Source
27
27
  * node, created once per node identity. The DOM lifetime stays in the
28
28
  * renderer records.
29
29
  */
@@ -67,7 +67,7 @@ export class BindingRuntime {
67
67
  get inlineCompiler() { return this.#inlineCompiler; }
68
68
  /** The ask dialogs of the page (`_ask` of a provider, `ask` of a button). */
69
69
  get askDialog() { return this.#askDialog; }
70
- /** `node_id → node` of the Source nodes with an open NodeBinding (R06). */
70
+ /** `nodeId → node` of the Source nodes with an open NodeBinding (R06). */
71
71
  get nodeIds() { return this.#nodeIds; }
72
72
 
73
73
  /** Subscribe once on Builder's Data wrapper; nothing is created. */
@@ -107,7 +107,7 @@ export class BindingRuntime {
107
107
  const binding = this.bindingFor(node);
108
108
  if (binding) {
109
109
  this.#bindings.delete(node);
110
- const nodeId = node.getAttr('node_id');
110
+ const nodeId = node.getAttr('nodeId');
111
111
  if (this.nodeIds.get(nodeId) === node) this.nodeIds.delete(nodeId);
112
112
  try { binding.close(); } catch (error) { errors.push(error); }
113
113
  }
@@ -131,7 +131,7 @@ export class BindingRuntime {
131
131
  * Semantic work of one Source event, called inside the renderer FIFO (§5.2).
132
132
  *
133
133
  * The rows of the event matrix: opening and closing of the NodeBindings,
134
- * the `node_id` map, the rebinding, and the installation of the `ins` and
134
+ * the `nodeId` map, the rebinding, and the installation of the `ins` and
135
135
  * new-branch rows (§5.1 steps 2-5).
136
136
  *
137
137
  * A failing disposer does not block the rest of the event: the errors of the
@@ -200,7 +200,7 @@ export class BindingRuntime {
200
200
  }
201
201
  }
202
202
 
203
- /** Close every NodeBinding, the `node_id` map and the Data subscription; a second call does nothing. */
203
+ /** Close every NodeBinding, the `nodeId` map and the Data subscription; a second call does nothing. */
204
204
  dispose() {
205
205
  if (this.disposed) return;
206
206
  this.#disposed = true;
@@ -215,8 +215,8 @@ export class BindingRuntime {
215
215
  }
216
216
 
217
217
  /**
218
- * Steps 2-4 of §5.1 on `branch` (a SourceBagNode or a new SourceBag value). The `node_id` map is
219
- * complete, and a duplicate refused, before the first write or registration, so a `#<node_id>`
218
+ * Steps 2-4 of §5.1 on `branch` (a SourceBagNode or a new SourceBag value). The `nodeId` map is
219
+ * complete, and a duplicate refused, before the first write or registration, so a `#<nodeId>`
220
220
  * of the branch translates; then the installation (`dataSetter`s and defaults), then one
221
221
  * NodeBinding per node and the registrations, providers included. On an error the NodeBindings
222
222
  * opened here are closed and the map entries they brought are removed; the Data is not rolled
@@ -231,10 +231,10 @@ export class BindingRuntime {
231
231
  const known = new Set(nodes.filter(node => this.bindingFor(node)));
232
232
  const entering = new Map();
233
233
  for (const node of nodes) {
234
- const nodeId = node.getAttr('node_id');
234
+ const nodeId = node.getAttr('nodeId');
235
235
  if (nodeId == null) continue;
236
236
  if (entering.has(nodeId) || (this.nodeIds.has(nodeId) && this.nodeIds.get(nodeId) !== node)) {
237
- throw new Error(`Duplicate node_id '${nodeId}'`);
237
+ throw new Error(`Duplicate nodeId '${nodeId}'`);
238
238
  }
239
239
  entering.set(nodeId, node);
240
240
  }
@@ -246,7 +246,7 @@ export class BindingRuntime {
246
246
  } catch (error) {
247
247
  const errors = [error];
248
248
  for (const node of nodes.filter(node => !known.has(node)).reverse()) {
249
- const nodeId = node.getAttr('node_id');
249
+ const nodeId = node.getAttr('nodeId');
250
250
  if (entering.get(nodeId) === node && this.nodeIds.get(nodeId) === node) this.nodeIds.delete(nodeId);
251
251
  const binding = this.bindingFor(node);
252
252
  if (!binding) continue;
@@ -295,16 +295,16 @@ export class BindingRuntime {
295
295
 
296
296
  /**
297
297
  * An attribute change: the NodeBinding of the node is required first (GC-210 §090), then the inline
298
- * declarations of the changed attributes are released (S09), then the `node_id` map, then the
298
+ * declarations of the changed attributes are released (S09), then the `nodeId` map, then the
299
299
  * rebinding of the node, or of its branch for a context attribute.
300
300
  */
301
301
  #attributesChanged(node, diff) {
302
302
  const binding = this.#installedBinding(node);
303
303
  this.inlineCompiler.release(node, Object.keys(diff));
304
- if (Object.hasOwn(diff, 'node_id')) {
305
- const {old: previous, new: current} = diff.node_id;
304
+ if (Object.hasOwn(diff, 'nodeId')) {
305
+ const {old: previous, new: current} = diff.nodeId;
306
306
  if (current != null && this.nodeIds.has(current) && this.nodeIds.get(current) !== node) {
307
- throw new Error(`Duplicate node_id '${current}'`);
307
+ throw new Error(`Duplicate nodeId '${current}'`);
308
308
  }
309
309
  if (this.nodeIds.get(previous) === node) this.nodeIds.delete(previous);
310
310
  if (current != null) this.nodeIds.set(current, node);
@@ -412,6 +412,14 @@ export class NodeBinding {
412
412
  if (dataElement && !PROVIDERS[node.nodeTag]) return;
413
413
  if (!dataElement && typeof node.getAttr('remote') === 'string') this.#remote ??= new RemoteBinding(this);
414
414
  const remoteDependencies = new Set();
415
+ if (node._getMeta('gramlot_component')?.bagStore) {
416
+ const storepath = node.getAttr('storepath');
417
+ if (typeof storepath !== 'string' || !storepath || /^[\^=]/.test(storepath) || storepath.includes('?')) {
418
+ throw new TypeError('storepath requires a plain Bag data path');
419
+ }
420
+ const path = node.absDatapath(storepath);
421
+ this.#registrations.push(this.runtime.router.register({path, recipient: this, subtree: true}));
422
+ }
415
423
  const timingDependencies = this.remote ? pointerDependencies(node, node.getAttr('_timing')) : new Set();
416
424
  if (this.remote) for (const [name, raw] of Object.entries(node.getAttr())) {
417
425
  if (name.startsWith('remote_')) for (const dependency of pointerDependencies(node, raw)) remoteDependencies.add(dependency);
@@ -117,11 +117,11 @@ export class GramlotBuilder extends HtmlBuilder {
117
117
  : null;
118
118
  }
119
119
 
120
- /** Builder's nodeById; inside a Gramlot page it reads the node_id map of the BindingRuntime (R06). */
120
+ /** Builder's nodeById; inside a Gramlot page it reads the nodeId map of the BindingRuntime (R06). */
121
121
  nodeById(nodeId) {
122
122
  if (!this.binding) return super.nodeById(nodeId);
123
123
  const node = this.binding.nodeIds.get(nodeId);
124
- if (!node) throw new Error(`node_id not found: ${nodeId}`);
124
+ if (!node) throw new Error(`nodeId not found: ${nodeId}`);
125
125
  return node.builder.wrapSource(node);
126
126
  }
127
127
  loadCollection(document) {
@@ -447,7 +447,7 @@ export class GramlotBuilderBagNode extends SourceBagNode {
447
447
  return path === null ? null : super._finalizeAbsPath(path, attr);
448
448
  }
449
449
 
450
- /** Builder's symbolic resolution; `#<node_id>` reads the node_id map of the page runtime when there is one (R06). */
450
+ /** Builder's symbolic resolution; `#<nodeId>` reads the nodeId map of the page runtime when there is one (R06). */
451
451
  _resolveSymbolicDatapath(path, raw) {
452
452
  const symbol = path.slice(1).split('.', 1)[0];
453
453
  if (symbol === 'FORM' || symbol === 'ANCHOR') return super._resolveSymbolicDatapath(path, raw);
@@ -116,6 +116,7 @@ export const BorderContainer = defineComponent({
116
116
  grid-template-columns:var(--left,0px) minmax(0,1fr) var(--right,0px);
117
117
  grid-template-rows:var(--top,0px) minmax(0,1fr) var(--bottom,0px);
118
118
  grid-template-areas:'top top top' 'left center right' 'bottom bottom bottom'}
119
+ .control-box[data-drawer-motion]{transition:grid-template-columns var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),grid-template-rows var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out)}
119
120
  .control-box[data-design=sidebar]{grid-template-areas:'left top right' 'left center right' 'left bottom right'}
120
121
  .region{position:relative;min-width:0;min-height:0;overflow:visible}
121
122
  .viewport{height:100%;min-width:0;min-height:0;overflow:auto}
@@ -123,7 +124,10 @@ export const BorderContainer = defineComponent({
123
124
  .region[data-side=right]>.viewport{padding-left:var(--region-splitter,0px)}
124
125
  .region[data-side=top]>.viewport{padding-bottom:var(--region-splitter,0px)}
125
126
  .region[data-side=bottom]>.viewport{padding-top:var(--region-splitter,0px)}
126
- .viewport[hidden]{display:none}::slotted(*){min-height:0}
127
+ .viewport[hidden]{display:none}
128
+ .control-box[data-drawer-motion] .viewport{transition:opacity var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out);opacity:1;visibility:visible}
129
+ .control-box[data-drawer-motion] .viewport[hidden]{display:block;opacity:0;visibility:hidden;
130
+ transition:opacity var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),visibility 0s var(--gramlot-drawer-duration,.24s)}::slotted(*){min-height:0}
127
131
  .separator{position:absolute;z-index:2;touch-action:none;user-select:none;background:var(--gramlot-splitter-background,var(--gramlot-border-control,#aaa))}
128
132
  .separator[data-axis=x]{top:0;bottom:0;width:var(--gramlot-splitter-size,1px);cursor:col-resize}
129
133
  .separator[data-axis=y]{left:0;right:0;height:var(--gramlot-splitter-size,1px);cursor:row-resize}
@@ -140,19 +144,19 @@ export const BorderContainer = defineComponent({
140
144
  .separator:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:1px}
141
145
  .drawer{position:absolute;z-index:3;cursor:pointer;appearance:none;font:inherit;
142
146
  font-size:var(--gramlot-drawer-font-size,11px);line-height:1.2;white-space:nowrap;
143
- --drawer-background:var(--gramlot-drawer-background,#777);
147
+ --drawer-background:var(--gramlot-drawer-background,var(--gramlot-text-secondary,#777));
144
148
  color:var(--gramlot-drawer-color,hsl(from var(--drawer-background) 0 0 clamp(20,calc((60 - l) * 1000),100)));
145
149
  background:var(--drawer-background);outline:none;
146
150
  border:0;border-radius:0;box-shadow:none;
147
151
  min-width:0;min-height:0;padding:0;
148
- opacity:var(--gramlot-drawer-opacity,.45);
149
- transition:opacity var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out),
150
- transform var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out),
151
- width var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out),
152
- height var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out),
153
- max-width var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out),
154
- max-height var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out),
155
- margin var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out)}
152
+ opacity:var(--gramlot-drawer-opacity,.20);
153
+ transition:opacity var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
154
+ transform var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
155
+ width var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
156
+ height var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
157
+ max-width var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
158
+ max-height var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
159
+ margin var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out)}
156
160
  .drawer:hover,.drawer:focus-visible{opacity:var(--gramlot-drawer-active-opacity,1)}
157
161
  [data-axis=x]>.drawer[data-resizable]{cursor:col-resize}
158
162
  [data-axis=y]>.drawer[data-resizable]{cursor:row-resize}
@@ -162,18 +166,18 @@ export const BorderContainer = defineComponent({
162
166
  .separator>.drawer:is([data-labelled],[data-icon]):hover{transform:scale(var(--gramlot-drawer-label-hover-scale,1.04))}
163
167
  }
164
168
 
165
- [data-axis=x]>.drawer{--drawer-closed-width:var(--gramlot-drawer-thickness,4px);--drawer-closed-height:var(--gramlot-drawer-length,28px);
166
- top:50%;margin-top:calc(var(--gramlot-drawer-length,28px) / -2);width:var(--drawer-closed-width);height:var(--drawer-closed-height)}
167
- [data-axis=y]>.drawer{--drawer-closed-width:var(--gramlot-drawer-length,28px);--drawer-closed-height:var(--gramlot-drawer-thickness,4px);
168
- left:50%;margin-left:calc(var(--gramlot-drawer-length,28px) / -2);width:var(--drawer-closed-width);height:var(--drawer-closed-height)}
169
+ [data-axis=x]>.drawer{--drawer-closed-width:var(--gramlot-drawer-thickness,6px);--drawer-closed-height:var(--gramlot-drawer-length,40px);
170
+ top:50%;margin-top:calc(var(--gramlot-drawer-length,40px) / -2);width:var(--drawer-closed-width);height:var(--drawer-closed-height)}
171
+ [data-axis=y]>.drawer{--drawer-closed-width:var(--gramlot-drawer-length,40px);--drawer-closed-height:var(--gramlot-drawer-thickness,6px);
172
+ left:50%;margin-left:calc(var(--gramlot-drawer-length,40px) / -2);width:var(--drawer-closed-width);height:var(--drawer-closed-height)}
169
173
  .drawer::after{content:'';position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);
170
174
  width:max(100%,var(--gramlot-touch-target,var(--gramlot-drawer-hit-target,12px)));height:max(100%,var(--gramlot-touch-target,var(--gramlot-drawer-hit-target,12px)))}
171
175
  .drawer{--drawer-reveal-width:var(--gramlot-drawer-reveal-width,var(--drawer-content-width,0px));--drawer-reveal-height:var(--gramlot-drawer-reveal-height,var(--drawer-content-height,0px))}
172
176
  .drawer[data-labelled]{opacity:var(--gramlot-drawer-active-opacity,1)}
173
- [data-side=left]>.drawer{transform-origin:left center;left:100%;border-left:0;border-radius:0 var(--gramlot-radius-sm,4px) var(--gramlot-radius-sm,4px) 0}
174
- [data-side=right]>.drawer{transform-origin:right center;right:100%;border-right:0;border-radius:var(--gramlot-radius-sm,4px) 0 0 var(--gramlot-radius-sm,4px)}
175
- [data-side=top]>.drawer{transform-origin:center top;top:100%;border-top:0;border-radius:0 0 var(--gramlot-radius-sm,4px) var(--gramlot-radius-sm,4px)}
176
- [data-side=bottom]>.drawer{transform-origin:center bottom;bottom:100%;border-bottom:0;border-radius:var(--gramlot-radius-sm,4px) var(--gramlot-radius-sm,4px) 0 0}
177
+ [data-side=left]>.drawer{transform-origin:left center;left:100%;border-left:0;border-radius:0 calc(var(--gramlot-radius-sm,4px) * 2) calc(var(--gramlot-radius-sm,4px) * 2) 0}
178
+ [data-side=right]>.drawer{transform-origin:right center;right:100%;border-right:0;border-radius:calc(var(--gramlot-radius-sm,4px) * 2) 0 0 calc(var(--gramlot-radius-sm,4px) * 2)}
179
+ [data-side=top]>.drawer{transform-origin:center top;top:100%;border-top:0;border-radius:0 0 calc(var(--gramlot-radius-sm,4px) * 2) calc(var(--gramlot-radius-sm,4px) * 2)}
180
+ [data-side=bottom]>.drawer{transform-origin:center bottom;bottom:100%;border-bottom:0;border-radius:calc(var(--gramlot-radius-sm,4px) * 2) calc(var(--gramlot-radius-sm,4px) * 2) 0 0}
177
181
  .drawer:is([data-labelled],[data-icon]){width:max-content;height:max-content;padding:0}
178
182
  .drawer-viewport{display:block;overflow:hidden;min-width:0;min-height:0;max-width:inherit;max-height:inherit}
179
183
  .drawer-content{display:flex;width:max-content;height:max-content;align-items:center;gap:var(--gramlot-drawer-content-gap,4px);box-sizing:border-box;
@@ -187,7 +191,7 @@ export const BorderContainer = defineComponent({
187
191
  .separator[data-axis=x]>.drawer.drawer-rotated{margin-top:0;translate:0 -50%}
188
192
  /* Icon and caption reveal as one unit; the resting grip stays thin. */
189
193
  .separator>.drawer.drawer-reveal:is([data-labelled],[data-icon]){--drawer-open:var(--gramlot-drawer-reveal,0);
190
- opacity:calc(var(--gramlot-drawer-opacity,.45) + (var(--gramlot-drawer-active-opacity,1) - var(--gramlot-drawer-opacity,.45)) * var(--drawer-open));
194
+ opacity:calc(var(--gramlot-drawer-opacity,.20) + (var(--gramlot-drawer-active-opacity,1) - var(--gramlot-drawer-opacity,.20)) * var(--drawer-open));
191
195
  display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr);
192
196
  min-width:0;min-height:0;
193
197
  max-width:calc(var(--drawer-closed-width) + (var(--drawer-reveal-width) - var(--drawer-closed-width)) * var(--drawer-open));
@@ -195,12 +199,12 @@ export const BorderContainer = defineComponent({
195
199
  .separator[data-axis=x]>.drawer.drawer-reveal{margin-top:0;translate:0 -50%}
196
200
  [data-axis=y]>.drawer:is([data-labelled],[data-icon]){margin-left:0;translate:-50% 0}
197
201
  .drawer-reveal .drawer-content{opacity:var(--drawer-open);
198
- transition:opacity var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out)}
202
+ transition:opacity var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out)}
199
203
  @media (hover:none),(pointer:coarse){.separator>.drawer.drawer-reveal:is([data-labelled],[data-icon]){--drawer-open:1}}
200
204
  @media (hover:hover){.separator>.drawer.drawer-reveal:is([data-labelled],[data-icon]):hover{--drawer-open:1;transform:scale(var(--gramlot-drawer-label-hover-scale,1.04))}}
201
205
  .separator>.drawer:is([data-labelled],[data-icon]):is(:active,[data-active]){transform:scale(var(--gramlot-drawer-label-hover-scale,1.04))}
202
206
  .separator>.drawer.drawer-reveal:is([data-labelled],[data-icon]):is(:focus-visible,:active,[data-active]){--drawer-open:1;transform:scale(var(--gramlot-drawer-label-hover-scale,1.04))}
203
- @media (prefers-reduced-motion:reduce){.drawer,.drawer-reveal .drawer-content{transition:none}}
207
+ @media (prefers-reduced-motion:reduce){.drawer,.drawer-reveal .drawer-content,.control-box[data-drawer-motion],.control-box[data-drawer-motion] .viewport{transition:none!important}}
204
208
  .drawer[hidden],.separator[hidden]{display:none}
205
209
  .drag-cover{position:absolute;inset:0;z-index:4;display:none}
206
210
  :host{position:relative}.drag-cover[data-active]{display:block}`;
@@ -236,7 +240,7 @@ export const BorderContainer = defineComponent({
236
240
  drawer.addEventListener('click', evt => {
237
241
  evt.stopPropagation();
238
242
  if (state.suppressDrawerClick && evt.detail !== 0) { state.suppressDrawerClick = false; return; }
239
- state.closed = !state.closed; this.#render(side);
243
+ state.closed = !state.closed; this.#render(side, true);
240
244
  state.config.onToggle?.(evt, !state.closed);
241
245
  });
242
246
  }
@@ -245,6 +249,13 @@ export const BorderContainer = defineComponent({
245
249
  }
246
250
  this.cover = doc.createElement('div'); this.cover.className = 'drag-cover';
247
251
  this.shadowRoot.append(style, this.cover);
252
+ this.control.addEventListener('transitionend', event => {
253
+ if (event.target !== this.control) return;
254
+ this.control.removeAttribute('data-drawer-motion');
255
+ for (const [side, state] of this.#regions) {
256
+ state.separator?.setAttribute('aria-valuenow', String(Math.round(this.#extent(side))));
257
+ }
258
+ });
248
259
  this.#observer = new doc.defaultView.MutationObserver(() => this.#sync());
249
260
  }
250
261
  connectedCallback() {
@@ -306,11 +317,22 @@ export const BorderContainer = defineComponent({
306
317
  }
307
318
  this.#render(side);
308
319
  }
309
- #render(side) {
320
+ #render(side, animate = false) {
310
321
  const state = this.#regions.get(side), c = state.config;
311
322
  const visible = !!c && !c.hidden && !state.closed;
312
323
  const previous = state.visibility;
313
324
  state.visibility = c ? {open: visible, drawer: !!c.drawer} : null;
325
+ // Retain the viewport through the closing transition, but disable interaction immediately.
326
+ state.viewport.inert = !visible;
327
+ if (previous && previous.open !== visible) {
328
+ this.control.toggleAttribute('data-drawer-motion', !!c?.drawer && animate && !this.#drag);
329
+ if (this.control.hasAttribute('data-drawer-motion')) {
330
+ const durations = this.ownerDocument.defaultView.getComputedStyle(this.control).transitionDuration;
331
+ if (durations.split(',').every(duration => Number.parseFloat(duration) === 0)) {
332
+ this.control.removeAttribute('data-drawer-motion');
333
+ }
334
+ }
335
+ }
314
336
  state.viewport.hidden = !visible;
315
337
  if (side === 'center') return;
316
338
  this.control.style.setProperty(`--${side}`, visible ? state.size : '0px');
@@ -335,6 +357,7 @@ export const BorderContainer = defineComponent({
335
357
  }
336
358
  #extent(side) { const box = this.#regions.get(side).cell.getBoundingClientRect(); return horizontal(side) ? box.height : box.width; }
337
359
  #resize(side, desired) {
360
+ this.control.removeAttribute('data-drawer-motion');
338
361
  const state = this.#regions.get(side), c = state.config;
339
362
  const opposite = {left:'right',right:'left',top:'bottom',bottom:'top'}[side];
340
363
  const box = this.control.getBoundingClientRect();
@@ -16,7 +16,7 @@ function annotation(parameter) {
16
16
  }
17
17
 
18
18
  /** Compose effective metadata without invoking a DOM class factory. */
19
- export function defineComponent({name, tag, base, mixins = [], parameters = {}, subTags = '', presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = false, implementation}) {
19
+ export function defineComponent({name, tag, base, mixins = [], parameters = {}, subTags = '', presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = false, bagStore = false, dragSource = false, implementation}) {
20
20
  webcomponentCode({code: tag});
21
21
  if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(name)) throw new TypeError('Invalid component authoring name');
22
22
  const effective = {...base.parameters};
@@ -28,8 +28,8 @@ export function defineComponent({name, tag, base, mixins = [], parameters = {},
28
28
  }
29
29
  Object.assign(effective, parameters);
30
30
  for (const spec of Object.values(effective)) annotation(spec);
31
- return Object.freeze({name, tag, base, subTags, presentationDefaults: Object.freeze([...presentationDefaults]), dataScope, command, mixins: Object.freeze([...mixins]),
32
- parameters: freeze(structuredClone(effective)), childParameters: freeze(structuredClone(childParameters)), sourceContext, implementation});
31
+ return Object.freeze({name, tag, base, subTags, presentationDefaults: Object.freeze([...presentationDefaults]), dataScope, command, bagStore, mixins: Object.freeze([...mixins]),
32
+ parameters: freeze(structuredClone(effective)), childParameters: freeze(structuredClone(childParameters)), sourceContext, dragSource, implementation});
33
33
  }
34
34
 
35
35
  export class ComponentCollection {
@@ -62,7 +62,9 @@ export class ComponentCollection {
62
62
  _meta: {render_tag: component.tag, gramlot_component: {parameters: structuredClone(component.parameters),
63
63
  presentationDefaults: [...component.presentationDefaults], dataScope: component.dataScope, command: component.command,
64
64
  ...(Object.keys(component.childParameters).length ? {childParameters: structuredClone(component.childParameters)} : {}),
65
- ...(component.sourceContext ? {sourceContext: true} : {})}}
65
+ ...(component.sourceContext ? {sourceContext: true} : {}),
66
+ ...(component.dragSource ? {dragSource: true} : {}),
67
+ ...(component.bagStore ? {bagStore: true} : {})}}
66
68
  }]))};
67
69
  }
68
70
  /** Register once per document realm, only when the collection is activated. */