@gramlot/gramlot 0.3.1 → 0.3.3

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.1",
3
+ "version": "0.3.3",
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": {
@@ -45,6 +45,7 @@ export class GramlotBuilderBagNode extends SourceBagNode {
45
45
  */
46
46
  codeAttributes() {
47
47
  const own = [...(CODE_ATTRIBUTES[this.nodeTag] ?? []),
48
+ ...Object.entries(this.parentNode?._getMeta('gramlot_component')?.childParameters ?? {}).filter(([, spec]) => spec.inline).map(([name]) => name),
48
49
  ...(this._getMeta('gramlot_component')?.command ? ['action', '_ask_if'] : []),
49
50
  ...(typeof this.getAttr('remote') === 'string' ? REMOTE_CODE_ATTRIBUTES : [])];
50
51
  const items = [];
@@ -0,0 +1,399 @@
1
+ /** Parent-owned regions. Layout changes never move or recreate slotted content. */
2
+ import {defineComponent} from './registry.js';
3
+ import {Container} from './container.js';
4
+
5
+ const SIDES = ['top', 'bottom', 'left', 'right'];
6
+ const REGIONS = [...SIDES, 'center'];
7
+ const borderRegions = new WeakMap();
8
+ const horizontal = side => side === 'top' || side === 'bottom';
9
+
10
+ /** Resolved Source attributes, not DOM scraping, supply the parent's region contract. */
11
+ function projectBorderChild(element, attrs, {adapt, invoke, publish, publishParent}) {
12
+ const rest = {...attrs}, splitter = {}, drawer = {};
13
+ for (const [name, value] of Object.entries(rest)) {
14
+ for (const [prefix, group] of [['splitter_', splitter], ['drawer_', drawer]]) {
15
+ if (name.startsWith(prefix)) { group[name.slice(prefix.length)] = value; delete rest[name]; }
16
+ }
17
+ }
18
+ const region = rest.region;
19
+ if (!REGIONS.includes(region)) throw new TypeError(`Invalid border region: ${region}`);
20
+ const min = rest.minSize ?? 0, max = rest.maxSize ?? Infinity;
21
+ if (typeof min !== 'number' || typeof max !== 'number' || !Number.isFinite(min) || min < 0 || max < min || Number.isNaN(max)) {
22
+ throw new TypeError('Border minSize/maxSize must be nonnegative pixel limits, with maxSize >= minSize');
23
+ }
24
+ if (![undefined, null, false, true, 'close'].includes(rest.drawer)) throw new TypeError('drawer must be true, false or close');
25
+ const probe = element.ownerDocument.createElement('div');
26
+ probe.style.cssText = rest.style ?? '';
27
+ const size = probe.style[horizontal(region) ? 'height' : 'width'];
28
+ // The region owns its authored size; its child fills the allotted viewport.
29
+ probe.style.width = '100%'; probe.style.height = '100%';
30
+ rest.style = probe.style.cssText;
31
+ const {label, icon, minimize = true, onclick, ...drawerStyle} = drawer;
32
+ if (typeof minimize !== 'boolean') throw new TypeError('drawer_minimize must be a boolean');
33
+ const drawerAttrs = adapt(drawerStyle);
34
+ const drawerProbe = element.ownerDocument.createElement('div');
35
+ drawerProbe.style.cssText = drawerAttrs.style ?? '';
36
+ const background = drawerProbe.style.backgroundColor;
37
+ if (background) drawerProbe.style.setProperty('--gramlot-drawer-background', background);
38
+ if (drawerAttrs.style != null) drawerAttrs.style = drawerProbe.style.cssText;
39
+ borderRegions.set(element, {region, size, min, max, splitter: rest.splitter === true,
40
+ drawer: rest.drawer, hidden: rest.hidden === true,
41
+ splitterAttrs: adapt(splitter), drawerAttrs, label, icon, minimize, notifications: {
42
+ closableChange: payload => publish('closable_change', payload),
43
+ splitterResize: payload => publishParent('splitter_resize', payload),
44
+ },
45
+ onToggle: onclick ? (evt, show) => invoke('drawer_onclick', onclick, {evt, show}) : null});
46
+ for (const key of ['region', 'splitter', 'drawer', 'minSize', 'maxSize']) delete rest[key];
47
+ rest.slot = region;
48
+ if (element.parentElement?.constructor.gramlotComponent?.name === 'borderContainer') element.parentElement.projectRegion(element);
49
+ return rest;
50
+ }
51
+
52
+ function applyAttributes(element, attrs, previous) {
53
+ for (const key of new Set([...Object.keys(previous), ...Object.keys(attrs)])) {
54
+ if (attrs[key] == null) element.removeAttribute(key);
55
+ else element.setAttribute(key, String(attrs[key]));
56
+ }
57
+ return attrs;
58
+ }
59
+
60
+ export const ContentPane = defineComponent({
61
+ name: 'contentPane', tag: 'gramlot-content-pane', base: Container, subTags: '*',
62
+ implementation: Base => class extends Base {
63
+ constructor() {
64
+ super();
65
+ const style = this.ownerDocument.createElement('style');
66
+ style.textContent = ':host{min-height:0;overflow:auto}.control-box{height:100%;min-height:0}';
67
+ this.shadowRoot.append(style);
68
+ }
69
+ }
70
+ });
71
+
72
+ export const BorderContainer = defineComponent({
73
+ name: 'borderContainer', tag: 'gramlot-border-container', base: Container, subTags: '*',
74
+ childParameters: {region: {required: true, enum: REGIONS, unique: true}, drawer_onclick: {inline: ['evt', 'show']}},
75
+ parameters: {
76
+ design: {dtype: 'T', default: 'headline', binding: 'read', enum: ['headline', 'sidebar']},
77
+ persist: {dtype: 'B', default: false, binding: 'read'},
78
+ },
79
+ implementation: Base => class extends Base {
80
+ static projectChild(element, attrs, context) {
81
+ return projectBorderChild(element, attrs, context);
82
+ }
83
+ #regions = new Map();
84
+ #observer;
85
+ #contentObserver;
86
+ #drag;
87
+ constructor() {
88
+ super();
89
+ this.control.replaceChildren();
90
+ const doc = this.ownerDocument;
91
+ this.#contentObserver = new doc.defaultView.ResizeObserver(entries => {
92
+ for (const {target} of entries) {
93
+ const region = target.closest('.region');
94
+ region.style.setProperty('--drawer-content-width', `${target.offsetWidth}px`);
95
+ region.style.setProperty('--drawer-content-height', `${target.offsetHeight}px`);
96
+ }
97
+ });
98
+ const style = doc.createElement('style');
99
+ style.textContent = `:host{min-height:0;overflow:hidden}
100
+ .control-box{height:100%;min-height:0;display:grid;
101
+ grid-template-columns:var(--left,0px) minmax(0,1fr) var(--right,0px);
102
+ grid-template-rows:var(--top,0px) minmax(0,1fr) var(--bottom,0px);
103
+ grid-template-areas:'top top top' 'left center right' 'bottom bottom bottom'}
104
+ .control-box[data-design=sidebar]{grid-template-areas:'left top right' 'left center right' 'left bottom right'}
105
+ .region{position:relative;min-width:0;min-height:0;overflow:visible}
106
+ .viewport{height:100%;min-width:0;min-height:0;overflow:auto}
107
+ .region[data-side=left]>.viewport{padding-right:var(--region-splitter,0px)}
108
+ .region[data-side=right]>.viewport{padding-left:var(--region-splitter,0px)}
109
+ .region[data-side=top]>.viewport{padding-bottom:var(--region-splitter,0px)}
110
+ .region[data-side=bottom]>.viewport{padding-top:var(--region-splitter,0px)}
111
+ .viewport[hidden]{display:none}::slotted(*){min-height:0}
112
+ .separator{position:absolute;z-index:2;touch-action:none;user-select:none;background:var(--gramlot-splitter-background,var(--gramlot-border-control,#aaa))}
113
+ .separator[data-axis=x]{top:0;bottom:0;width:var(--gramlot-splitter-size,1px);cursor:col-resize}
114
+ .separator[data-axis=y]{left:0;right:0;height:var(--gramlot-splitter-size,1px);cursor:row-resize}
115
+ .separator[data-side=left]{right:0}.separator[data-side=right]{left:0}
116
+ .separator[data-side=top]{bottom:0}.separator[data-side=bottom]{top:0}
117
+ .separator:hover{background:var(--gramlot-splitter-hover,#91a4bd)}
118
+ .separator::before{content:'';position:absolute;inset:0}
119
+ .separator[data-axis=x]::before{left:calc((100% - max(100%,var(--gramlot-touch-target,12px))) / 2);width:max(100%,var(--gramlot-touch-target,12px))}
120
+ .separator[data-axis=y]::before{top:calc((100% - max(100%,var(--gramlot-touch-target,12px))) / 2);height:max(100%,var(--gramlot-touch-target,12px))}
121
+ .separator[data-draggable=false]{cursor:default;background:transparent}
122
+ .separator[data-draggable=false]::before{display:none}
123
+ .separator[data-axis=x][data-draggable=false]{width:0!important}
124
+ .separator[data-axis=y][data-draggable=false]{height:0!important}
125
+ .separator:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:1px}
126
+ .drawer{position:absolute;z-index:3;cursor:pointer;appearance:none;font:inherit;
127
+ font-size:var(--gramlot-drawer-font-size,11px);line-height:1.2;white-space:nowrap;
128
+ --drawer-background:var(--gramlot-drawer-background,#777);
129
+ color:var(--gramlot-drawer-color,hsl(from var(--drawer-background) 0 0 clamp(20,calc((60 - l) * 1000),100)));
130
+ background:var(--drawer-background);outline:none;
131
+ border:0;border-radius:0;box-shadow:none;
132
+ min-width:0;min-height:0;padding:0;
133
+ opacity:var(--gramlot-drawer-opacity,.45);
134
+ transition:opacity var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out),
135
+ transform var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out),
136
+ width var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out),
137
+ height var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out),
138
+ max-width var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out),
139
+ max-height var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out),
140
+ margin var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out)}
141
+ .drawer:hover,.drawer:focus-visible{opacity:var(--gramlot-drawer-active-opacity,1)}
142
+ [data-axis=x]>.drawer[data-resizable]{cursor:col-resize}
143
+ [data-axis=y]>.drawer[data-resizable]{cursor:row-resize}
144
+ @media (hover:hover){
145
+ [data-axis=x]>.drawer:hover{transform:scale(var(--gramlot-drawer-hover-cross-scale,1.75),var(--gramlot-drawer-hover-length-scale,1.12))}
146
+ [data-axis=y]>.drawer:hover{transform:scale(var(--gramlot-drawer-hover-length-scale,1.12),var(--gramlot-drawer-hover-cross-scale,1.75))}
147
+ .separator>.drawer:is([data-labelled],[data-icon]):hover{transform:scale(var(--gramlot-drawer-label-hover-scale,1.04))}
148
+ }
149
+
150
+ [data-axis=x]>.drawer{--drawer-closed-width:var(--gramlot-drawer-thickness,4px);--drawer-closed-height:var(--gramlot-drawer-length,28px);
151
+ top:50%;margin-top:calc(var(--gramlot-drawer-length,28px) / -2);width:var(--drawer-closed-width);height:var(--drawer-closed-height)}
152
+ [data-axis=y]>.drawer{--drawer-closed-width:var(--gramlot-drawer-length,28px);--drawer-closed-height:var(--gramlot-drawer-thickness,4px);
153
+ left:50%;margin-left:calc(var(--gramlot-drawer-length,28px) / -2);width:var(--drawer-closed-width);height:var(--drawer-closed-height)}
154
+ .drawer::after{content:'';position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);
155
+ 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)))}
156
+ .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))}
157
+ .drawer[data-labelled]{opacity:var(--gramlot-drawer-active-opacity,1)}
158
+ [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}
159
+ [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)}
160
+ [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)}
161
+ [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}
162
+ .drawer:is([data-labelled],[data-icon]){width:max-content;height:max-content;padding:0}
163
+ .drawer-viewport{display:block;overflow:hidden;min-width:0;min-height:0;max-width:inherit;max-height:inherit}
164
+ .drawer-content{display:flex;width:max-content;height:max-content;align-items:center;gap:var(--gramlot-drawer-content-gap,4px);box-sizing:border-box;
165
+ padding:var(--gramlot-drawer-padding,2px 8px);overflow:hidden;pointer-events:none;
166
+ min-width:0;min-height:0}
167
+ .drawer-icon{display:block;flex:none;font-size:var(--gramlot-drawer-icon-size,1em);line-height:1}
168
+ .drawer-icon[hidden],.drawer-label:empty{display:none}
169
+ .drawer-label{display:block;flex:none;pointer-events:none}
170
+ .drawer-rotated .drawer-content{flex-direction:column;padding:var(--gramlot-drawer-padding,8px 2px)}
171
+ .drawer-rotated .drawer-label{writing-mode:vertical-rl;text-orientation:mixed}
172
+ .separator[data-axis=x]>.drawer.drawer-rotated{margin-top:0;translate:0 -50%}
173
+ /* Icon and caption reveal as one unit; the resting grip stays thin. */
174
+ .separator>.drawer.drawer-reveal:is([data-labelled],[data-icon]){--drawer-open:var(--gramlot-drawer-reveal,0);
175
+ opacity:calc(var(--gramlot-drawer-opacity,.45) + (var(--gramlot-drawer-active-opacity,1) - var(--gramlot-drawer-opacity,.45)) * var(--drawer-open));
176
+ display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr);
177
+ min-width:0;min-height:0;
178
+ max-width:calc(var(--drawer-closed-width) + (var(--drawer-reveal-width) - var(--drawer-closed-width)) * var(--drawer-open));
179
+ max-height:calc(var(--drawer-closed-height) + (var(--drawer-reveal-height) - var(--drawer-closed-height)) * var(--drawer-open))}
180
+ .separator[data-axis=x]>.drawer.drawer-reveal{margin-top:0;translate:0 -50%}
181
+ [data-axis=y]>.drawer:is([data-labelled],[data-icon]){margin-left:0;translate:-50% 0}
182
+ .drawer-reveal .drawer-content{opacity:var(--drawer-open);
183
+ transition:opacity var(--gramlot-drawer-duration,.16s) var(--gramlot-drawer-easing,ease-out)}
184
+ @media (hover:none),(pointer:coarse){.separator>.drawer.drawer-reveal:is([data-labelled],[data-icon]){--drawer-open:1}}
185
+ @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))}}
186
+ .separator>.drawer:is([data-labelled],[data-icon]):is(:active,[data-active]){transform:scale(var(--gramlot-drawer-label-hover-scale,1.04))}
187
+ .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))}
188
+ @media (prefers-reduced-motion:reduce){.drawer,.drawer-reveal .drawer-content{transition:none}}
189
+ .drawer[hidden],.separator[hidden]{display:none}
190
+ .drag-cover{position:absolute;inset:0;z-index:4;display:none}
191
+ :host{position:relative}.drag-cover[data-active]{display:block}`;
192
+ for (const side of REGIONS) {
193
+ const cell = doc.createElement('div'); cell.className = 'region'; cell.style.gridArea = side;
194
+ const viewport = doc.createElement('div'); viewport.className = 'viewport'; cell.dataset.side = side; viewport.id = `region-${side}`;
195
+ const slot = doc.createElement('slot'); slot.name = side; viewport.append(slot); cell.append(viewport);
196
+ const state = {cell, viewport, child:null, config:null, visibility:null, closed:false, suppressDrawerClick:false, size:null, splitterAttrs:{}, drawerAttrs:{}};
197
+ if (side !== 'center') {
198
+ const separator = doc.createElement('div'); separator.className = 'separator';
199
+ separator.dataset.side = side; separator.dataset.axis = horizontal(side) ? 'y' : 'x';
200
+ separator.setAttribute('role', 'separator'); separator.setAttribute('aria-label', `Resize ${side} region`);
201
+ separator.setAttribute('aria-orientation', horizontal(side) ? 'horizontal' : 'vertical');
202
+ separator.setAttribute('aria-controls', viewport.id);
203
+ const drawer = doc.createElement('button'); drawer.type = 'button'; drawer.className = 'drawer';
204
+ drawer.setAttribute('aria-controls', viewport.id);
205
+ const drawerIcon = doc.createElement('span'); drawerIcon.className = 'drawer-icon'; drawerIcon.setAttribute('aria-hidden', 'true');
206
+ const drawerLabel = doc.createElement('span'); drawerLabel.className = 'drawer-label';
207
+ const drawerContent = doc.createElement('span'); drawerContent.className = 'drawer-content';
208
+ const drawerViewport = doc.createElement('span'); drawerViewport.className = 'drawer-viewport';
209
+ drawerContent.append(drawerIcon, drawerLabel); drawerViewport.append(drawerContent);
210
+ drawer.append(drawerViewport); separator.append(drawer); cell.append(separator);
211
+ // Touch pointer capture can clear :active before release; keep only the pressed presentation.
212
+ drawer.addEventListener('pointerdown', evt => { if (evt.button === 0) drawer.setAttribute('data-active', ''); });
213
+ for (const event of ['pointerup', 'pointercancel', 'lostpointercapture', 'pointerleave']) {
214
+ drawer.addEventListener(event, evt => {
215
+ if (event !== 'pointerleave' || !drawer.hasPointerCapture(evt.pointerId)) drawer.removeAttribute('data-active');
216
+ });
217
+ }
218
+ Object.assign(state, {separator, drawer, drawerIcon, drawerLabel, drawerContent});
219
+ separator.addEventListener('pointerdown', evt => this.#startDrag(side, evt));
220
+ separator.addEventListener('keydown', evt => this.#keyResize(side, evt));
221
+ drawer.addEventListener('click', evt => {
222
+ evt.stopPropagation();
223
+ if (state.suppressDrawerClick && evt.detail !== 0) { state.suppressDrawerClick = false; return; }
224
+ state.closed = !state.closed; this.#render(side);
225
+ state.config.onToggle?.(evt, !state.closed);
226
+ });
227
+ }
228
+ this.#regions.set(side, state); this.control.append(cell);
229
+ slot.addEventListener('slotchange', () => this.#sync());
230
+ }
231
+ this.cover = doc.createElement('div'); this.cover.className = 'drag-cover';
232
+ this.shadowRoot.append(style, this.cover);
233
+ this.#observer = new doc.defaultView.MutationObserver(() => this.#sync());
234
+ }
235
+ connectedCallback() {
236
+ this.#observer.observe(this, {childList:true});
237
+ for (const state of this.#regions.values()) if (state.drawerContent) this.#contentObserver.observe(state.drawerContent);
238
+ this.#sync();
239
+ }
240
+ disconnectedCallback() { this.#observer.disconnect(); this.#contentObserver.disconnect(); this.#stopDrag(); }
241
+ projectAttributes(attrs, adapt) {
242
+ const rest = super.projectAttributes(attrs, adapt);
243
+ if (!['headline', 'sidebar'].includes(this.parameters.design)) throw new TypeError('Invalid border design');
244
+ if (Object.hasOwn(attrs, 'liveSplitters')) throw new TypeError('Border splitters are always live; omit liveSplitters');
245
+ if (this.parameters.persist && !attrs.id) throw new TypeError('Persistent borderContainer requires a stable id');
246
+ this.control.dataset.design = this.parameters.design;
247
+ return rest;
248
+ }
249
+ #sync() {
250
+ const children = new Map();
251
+ for (const child of this.children) {
252
+ const config = borderRegions.get(child);
253
+ if (!config) continue;
254
+ if (children.has(config.region)) throw new Error(`Duplicate border region: ${config.region}`);
255
+ children.set(config.region, child);
256
+ }
257
+ for (const [side, state] of this.#regions) {
258
+ const child = children.get(side) ?? null;
259
+ if (state.child !== child) {
260
+ if (this.#drag?.side === side) this.#stopDrag();
261
+ state.child = child; state.config = null; state.visibility = null; state.size = null; state.closed = false;
262
+ }
263
+ if (child) this.projectRegion(child);
264
+ else { state.config = null; this.#render(side); }
265
+ }
266
+ }
267
+ projectRegion(child) {
268
+ const config = borderRegions.get(child), side = config.region, state = this.#regions.get(side);
269
+ if (state.child !== child) { this.#sync(); return; }
270
+ const before = state.config;
271
+ if (!before || before.size !== config.size) {
272
+ state.size = config.size || 'auto';
273
+ if (!before && this.parameters.persist) {
274
+ const saved = this.ownerDocument.cookie.split('; ').find(item => item.startsWith(`${this.#cookie(side)}=`));
275
+ if (saved) state.size = decodeURIComponent(saved.split('=').slice(1).join('='));
276
+ }
277
+ }
278
+ if (!before || before.drawer !== config.drawer) state.closed = config.drawer === 'close';
279
+ state.config = config;
280
+ if (side !== 'center') {
281
+ state.splitterAttrs = applyAttributes(state.separator, config.splitterAttrs, state.splitterAttrs);
282
+ state.drawerAttrs = applyAttributes(state.drawer, config.drawerAttrs, state.drawerAttrs);
283
+ state.separator.classList.add('separator'); state.drawer.classList.add('drawer');
284
+ state.drawer.classList.toggle('drawer-reveal', config.minimize);
285
+ state.drawer.classList.toggle('drawer-rotated', !horizontal(side));
286
+ state.drawerLabel.innerHTML = config.label ?? '';
287
+ state.drawerIcon.textContent = config.icon ?? '';
288
+ state.drawerIcon.hidden = !config.icon;
289
+ state.drawer.toggleAttribute('data-icon', !!config.icon);
290
+ state.drawer.toggleAttribute('data-labelled', !!config.label);
291
+ }
292
+ this.#render(side);
293
+ }
294
+ #render(side) {
295
+ const state = this.#regions.get(side), c = state.config;
296
+ const visible = !!c && !c.hidden && !state.closed;
297
+ const previous = state.visibility;
298
+ state.visibility = c ? {open: visible, drawer: !!c.drawer} : null;
299
+ state.viewport.hidden = !visible;
300
+ if (side === 'center') return;
301
+ this.control.style.setProperty(`--${side}`, visible ? state.size : '0px');
302
+ state.separator.hidden = !c || c.hidden || (!c.splitter && !c.drawer);
303
+ const draggable = visible && c.splitter;
304
+ state.cell.style.setProperty('--region-splitter', draggable ? (state.separator.style[horizontal(side) ? 'height' : 'width'] || 'var(--gramlot-splitter-size,1px)') : '0px');
305
+ state.separator.dataset.draggable = String(!!draggable);
306
+ state.separator.setAttribute('role', draggable ? 'separator' : 'presentation');
307
+ state.separator.tabIndex = draggable ? 0 : -1;
308
+ state.drawer.hidden = !c?.drawer;
309
+ state.drawer.toggleAttribute('data-resizable', !!c?.splitter);
310
+ state.drawer.setAttribute('aria-expanded', String(visible));
311
+ state.drawer.setAttribute('aria-label', `${visible ? 'Close' : 'Open'} ${side} region`);
312
+ state.drawer.title = c?.drawerAttrs.title ?? state.drawer.getAttribute('aria-label');
313
+ state.separator.setAttribute('aria-valuemin', String(c?.min ?? 0));
314
+ state.separator.setAttribute('aria-valuenow', String(Math.round(this.#extent(side))));
315
+ if (c && Number.isFinite(c.max)) state.separator.setAttribute('aria-valuemax', String(c.max));
316
+ else state.separator.removeAttribute('aria-valuemax');
317
+ if (c && previous && (previous.drawer || c.drawer) && previous.open !== visible) {
318
+ c.notifications.closableChange({open: visible, region: side});
319
+ }
320
+ }
321
+ #extent(side) { const box = this.#regions.get(side).cell.getBoundingClientRect(); return horizontal(side) ? box.height : box.width; }
322
+ #resize(side, desired) {
323
+ const state = this.#regions.get(side), c = state.config;
324
+ const opposite = {left:'right',right:'left',top:'bottom',bottom:'top'}[side];
325
+ const box = this.control.getBoundingClientRect();
326
+ const available = Math.max(0, (horizontal(side) ? box.height : box.width) - this.#extent(opposite));
327
+ const size = Math.max(Math.min(c.min, available), Math.min(desired, c.max, available));
328
+ state.size = `${size}px`; this.#render(side);
329
+ }
330
+ #keyResize(side, evt) {
331
+ const state = this.#regions.get(side);
332
+ if (evt.target !== state.separator || !state.config?.splitter || state.closed) return;
333
+ const keys = horizontal(side) ? ['ArrowUp','ArrowDown'] : ['ArrowLeft','ArrowRight'];
334
+ if (!keys.includes(evt.key)) return;
335
+ evt.preventDefault();
336
+ const sign = ['left','top'].includes(side) ? 1 : -1;
337
+ const previousSize = this.#extent(side);
338
+ this.#resize(side, previousSize + (evt.key === keys[0] ? -1 : 1) * sign);
339
+ this.#commitResize(side, previousSize);
340
+ }
341
+ #startDrag(side, evt) {
342
+ const state = this.#regions.get(side);
343
+ if (evt.button !== 0) return;
344
+ state.suppressDrawerClick = false;
345
+ if (!state.config?.splitter) return;
346
+ const fromDrawer = state.drawer.contains(evt.target);
347
+ if (!fromDrawer) evt.preventDefault();
348
+ this.#stopDrag();
349
+ const axis = horizontal(side) ? 'clientY' : 'clientX', start = evt[axis], size = this.#extent(side);
350
+ const sign = ['left','top'].includes(side) ? 1 : -1;
351
+ const controller = new this.ownerDocument.defaultView.AbortController();
352
+ const captureTarget = fromDrawer ? state.drawer : state.separator, pointerId = evt.pointerId;
353
+ let resizing = !fromDrawer;
354
+ this.#drag = {side, controller, captureTarget, pointerId};
355
+ captureTarget.setPointerCapture(pointerId);
356
+ if (resizing) this.cover.setAttribute('data-active', '');
357
+ const options = {signal:controller.signal};
358
+ captureTarget.addEventListener('pointermove', event => {
359
+ if (event.pointerId !== pointerId) return;
360
+ const distance = event[axis] - start;
361
+ // Allow small click jitter before treating a drawer press as a drag.
362
+ if (!resizing && Math.abs(distance) < 4) return;
363
+ state.suppressDrawerClick = fromDrawer;
364
+ // A closed drawer opens only when pulled towards the content.
365
+ if (state.closed && sign * distance <= 0) return;
366
+ const opening = state.closed;
367
+ state.closed = false;
368
+ resizing = true;
369
+ this.cover.setAttribute('data-active', '');
370
+ this.#resize(side, size + sign * distance);
371
+ if (opening) state.config.onToggle?.(event, true);
372
+ }, options);
373
+ const finish = event => {
374
+ if (event.pointerId !== pointerId) return;
375
+ this.#stopDrag();
376
+ if (resizing) this.#commitResize(side, size);
377
+ };
378
+ captureTarget.addEventListener('pointerup', finish, options);
379
+ captureTarget.addEventListener('pointercancel', finish, options);
380
+ captureTarget.addEventListener('lostpointercapture', finish, options);
381
+ }
382
+ #stopDrag() {
383
+ if (!this.#drag) return;
384
+ const {controller, captureTarget, pointerId} = this.#drag; this.#drag = null;
385
+ controller.abort(); this.cover.removeAttribute('data-active');
386
+ if (captureTarget.hasPointerCapture(pointerId)) captureTarget.releasePointerCapture(pointerId);
387
+ }
388
+ #commitResize(side, previousSize) {
389
+ const state = this.#regions.get(side), size = this.#extent(side);
390
+ if (size === previousSize) return;
391
+ this.#save(side);
392
+ state.config.notifications.splitterResize({region: side, size: `${size}px`, previousSize: `${previousSize}px`});
393
+ }
394
+ #cookie(side) { return encodeURIComponent(`gramlot-border-${this.id}-${side}`); }
395
+ #save(side) {
396
+ if (this.parameters.persist) this.ownerDocument.cookie = `${this.#cookie(side)}=${encodeURIComponent(this.#regions.get(side).size)}; Path=/; SameSite=Lax`;
397
+ }
398
+ }
399
+ });
@@ -19,6 +19,7 @@ export function ChoiceEditor(HTMLElement) {
19
19
  const doc = this.ownerDocument;
20
20
  const style = doc.createElement('style');
21
21
  style.textContent = `.option{position:relative} #control{width:100%;padding-right:calc(var(--gramlot-choice-toggle-width,1.6em) + .2em)}
22
+ #control:focus-visible{outline:1px solid var(--gramlot-border-control,#7a8798);outline-offset:-3px}
22
23
  .toggle{position:absolute;right:0;top:0;bottom:0;width:var(--gramlot-choice-toggle-width,1.6em);min-width:0;min-height:0;font:inherit;font-size:var(--gramlot-field-font-size,1em);padding:0;border:0;background:transparent;color:inherit}
23
24
  .choices{max-width:var(--gramlot-popup-available-width,100vw);position:fixed;inset:auto;margin:0;padding:var(--gramlot-popup-padding,4px);box-sizing:border-box;max-height:min(var(--gramlot-choice-max-height,12rem),var(--gramlot-popup-available-height,100vh));overflow:auto;
24
25
  border:1px solid var(--gramlot-border-control,#aab4c2);border-radius:var(--gramlot-radius-sm,4px);background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);font:inherit;box-shadow:var(--gramlot-shadow,0 3px 9px #0002)}
@@ -158,7 +159,8 @@ export function ChoiceEditor(HTMLElement) {
158
159
  if (!rows.length) this.choices.textContent = 'No results';
159
160
  const view = doc.defaultView;
160
161
  this.choices.hidden = false; this.choices.showPopover(); this.#opened = true;
161
- positionPopup(this.choices, this.control, {matchWidth: true});
162
+ const inset = parseFloat(view.getComputedStyle(this).getPropertyValue('--gramlot-choice-popup-inset') || '2');
163
+ positionPopup(this.choices, this.control, {matchWidth: true, inset});
162
164
  this.control.setAttribute('aria-expanded', 'true'); this.activate(0);
163
165
  const close = () => this.closeChoices();
164
166
  const outside = event => { if (!event.composedPath().includes(this)) close(); };
@@ -0,0 +1,25 @@
1
+ /** Shared stable slotted container base. */
2
+ import {projectParameters} from './parameters.js';
3
+
4
+ export function Container(HTMLElement) {
5
+ return class extends HTMLElement {
6
+ constructor() {
7
+ super();
8
+ const shadow = this.attachShadow({mode: 'open'});
9
+ const style = this.ownerDocument.createElement('style');
10
+ style.textContent = `:host{display:block;min-width:0;font:inherit;color:var(--gramlot-ink,CanvasText)}
11
+ *,*::before,*::after{box-sizing:border-box}.control-box{min-width:0}slot{display:contents}
12
+ ::slotted(*){min-width:0;max-width:100%}`;
13
+ this.controlBox = this.ownerDocument.createElement('div');
14
+ this.controlBox.className = 'control-box';
15
+ this.control = this.controlBox; this.control.id = 'control';
16
+ this.control.append(this.ownerDocument.createElement('slot'));
17
+ shadow.append(style, this.controlBox);
18
+ }
19
+ projectAttributes(attrs) {
20
+ return projectParameters(this, attrs);
21
+ }
22
+ };
23
+ }
24
+ Container.parameters = {};
25
+
@@ -1,33 +1,16 @@
1
1
  /** Slotted layout components; Source owns children and Data owns field values. */
2
2
  import {defineComponent, defineCollection} from './registry.js';
3
3
  import {Labelbox} from './labelbox.js';
4
- import {projectParameters} from './parameters.js';
4
+ import {Container} from './container.js';
5
+ import {BorderContainer, ContentPane} from './border-container.js';
6
+ export {BorderContainer, ContentPane};
7
+ import {StackContainer, TabContainer} from './selected-container.js';
8
+ export {StackContainer, TabContainer};
5
9
  import {positionPopup} from './popup.js';
6
10
  import {FormletLabels} from './formlet-labels.js';
7
11
 
8
12
  const COPY_FEEDBACK_DURATION = 1600;
9
13
 
10
- function Container(HTMLElement) {
11
- return class extends HTMLElement {
12
- constructor() {
13
- super();
14
- const shadow = this.attachShadow({mode: 'open'});
15
- const style = this.ownerDocument.createElement('style');
16
- style.textContent = `:host{display:block;min-width:0;font:inherit;color:var(--gramlot-ink,CanvasText)}
17
- *,*::before,*::after{box-sizing:border-box}.control-box{min-width:0}slot{display:contents}
18
- ::slotted(*){min-width:0;max-width:100%}`;
19
- this.controlBox = this.ownerDocument.createElement('div');
20
- this.controlBox.className = 'control-box';
21
- this.control = this.controlBox; this.control.id = 'control';
22
- this.control.append(this.ownerDocument.createElement('slot'));
23
- shadow.append(style, this.controlBox);
24
- }
25
- projectAttributes(attrs) {
26
- return projectParameters(this, attrs);
27
- }
28
- };
29
- }
30
- Container.parameters = {};
31
14
 
32
15
  export const Formlet = defineComponent({
33
16
  name: 'formlet', tag: 'gramlot-formlet', base: Container, subTags: '*', presentationDefaults: ['lbl_', 'box_'],
@@ -187,4 +170,4 @@ export const GroupBox = defineComponent({
187
170
  }
188
171
  }
189
172
  });
190
- export default defineCollection({name: 'layout', components: [Formlet, GroupBox]});
173
+ export default defineCollection({name: 'layout', components: [Formlet, GroupBox, ContentPane, BorderContainer, StackContainer, TabContainer]});
@@ -2,12 +2,12 @@
2
2
  const VIEWPORT_MARGIN = 8;
3
3
  const ANCHOR_GAP = 3;
4
4
 
5
- export function positionPopup(popup, anchor, {align = 'start', matchWidth = false} = {}) {
5
+ export function positionPopup(popup, anchor, {align = 'start', matchWidth = false, inset = 0} = {}) {
6
6
  const view = anchor.ownerDocument.defaultView;
7
7
  const field = anchor.getBoundingClientRect();
8
8
  const availableWidth = Math.max(0, view.innerWidth - 2 * VIEWPORT_MARGIN);
9
9
  popup.style.setProperty('--gramlot-popup-available-width', `${availableWidth}px`);
10
- if (matchWidth) popup.style.width = `${Math.min(field.width, availableWidth)}px`;
10
+ if (matchWidth) popup.style.width = `${Math.min(Math.max(0, field.width - 2 * inset), availableWidth)}px`;
11
11
  popup.style.removeProperty('--gramlot-popup-available-height');
12
12
  const natural = popup.getBoundingClientRect();
13
13
  const below = Math.max(0, view.innerHeight - VIEWPORT_MARGIN - field.bottom - ANCHOR_GAP);
@@ -15,7 +15,7 @@ export function positionPopup(popup, anchor, {align = 'start', matchWidth = fals
15
15
  const upwards = natural.height > below && above > below;
16
16
  popup.style.setProperty('--gramlot-popup-available-height', `${upwards ? above : below}px`);
17
17
  const size = popup.getBoundingClientRect();
18
- const left = align === 'end' ? field.right - size.width : field.left;
18
+ const left = align === 'end' ? field.right - size.width - inset : field.left + inset;
19
19
  const top = upwards ? field.top - size.height - ANCHOR_GAP : field.bottom + ANCHOR_GAP;
20
20
  popup.style.left = `${Math.max(VIEWPORT_MARGIN, Math.min(left, view.innerWidth - size.width - VIEWPORT_MARGIN))}px`;
21
21
  popup.style.top = `${Math.max(VIEWPORT_MARGIN, Math.min(top, view.innerHeight - size.height - VIEWPORT_MARGIN))}px`;
@@ -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, implementation}) {
19
+ export function defineComponent({name, tag, base, mixins = [], parameters = {}, subTags = '', presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = 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};
@@ -29,7 +29,7 @@ export function defineComponent({name, tag, base, mixins = [], parameters = {},
29
29
  Object.assign(effective, parameters);
30
30
  for (const spec of Object.values(effective)) annotation(spec);
31
31
  return Object.freeze({name, tag, base, subTags, presentationDefaults: Object.freeze([...presentationDefaults]), dataScope, command, mixins: Object.freeze([...mixins]),
32
- parameters: freeze(structuredClone(effective)), implementation});
32
+ parameters: freeze(structuredClone(effective)), childParameters: freeze(structuredClone(childParameters)), sourceContext, implementation});
33
33
  }
34
34
 
35
35
  export class ComponentCollection {
@@ -60,7 +60,9 @@ export class ComponentCollection {
60
60
  annotation: {kind: 'any'}, has_default: false}],
61
61
  accepts_var_keyword: true, accepts_var_positional: false},
62
62
  _meta: {render_tag: component.tag, gramlot_component: {parameters: structuredClone(component.parameters),
63
- presentationDefaults: [...component.presentationDefaults], dataScope: component.dataScope, command: component.command}}
63
+ presentationDefaults: [...component.presentationDefaults], dataScope: component.dataScope, command: component.command,
64
+ ...(Object.keys(component.childParameters).length ? {childParameters: structuredClone(component.childParameters)} : {}),
65
+ ...(component.sourceContext ? {sourceContext: true} : {})}}
64
66
  }]))};
65
67
  }
66
68
  /** Register once per document realm, only when the collection is activated. */