@gramlot/gramlot 0.3.2 → 0.3.4
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/dist/gramlot.js +64 -20
- package/dist/gramlot.min.js +23 -23
- package/package.json +1 -1
- package/src/components/border-container.js +13 -4
- package/src/index-page-runtime.d.ts +2 -1
- package/src/index-page-runtime.js +54 -14
- package/src/view/html.js +12 -7
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ const borderRegions = new WeakMap();
|
|
|
8
8
|
const horizontal = side => side === 'top' || side === 'bottom';
|
|
9
9
|
|
|
10
10
|
/** Resolved Source attributes, not DOM scraping, supply the parent's region contract. */
|
|
11
|
-
function projectBorderChild(element, attrs, {adapt, invoke, publish, publishParent}) {
|
|
11
|
+
function projectBorderChild(element, attrs, {adapt, invoke, publish, publishParent, writeParameter}) {
|
|
12
12
|
const rest = {...attrs}, splitter = {}, drawer = {};
|
|
13
13
|
for (const [name, value] of Object.entries(rest)) {
|
|
14
14
|
for (const [prefix, group] of [['splitter_', splitter], ['drawer_', drawer]]) {
|
|
@@ -24,7 +24,14 @@ function projectBorderChild(element, attrs, {adapt, invoke, publish, publishPare
|
|
|
24
24
|
if (![undefined, null, false, true, 'close'].includes(rest.drawer)) throw new TypeError('drawer must be true, false or close');
|
|
25
25
|
const probe = element.ownerDocument.createElement('div');
|
|
26
26
|
probe.style.cssText = rest.style ?? '';
|
|
27
|
-
const
|
|
27
|
+
const dimension = horizontal(region) ? 'height' : 'width';
|
|
28
|
+
const numeric = typeof rest[dimension] === 'number';
|
|
29
|
+
if (numeric) {
|
|
30
|
+
if (!Number.isFinite(rest[dimension]) || rest[dimension] < 0) throw new TypeError('Border numeric dimensions must be finite nonnegative pixels');
|
|
31
|
+
probe.style[dimension] = `${rest[dimension]}px`;
|
|
32
|
+
}
|
|
33
|
+
const size = probe.style[dimension];
|
|
34
|
+
delete rest.width; delete rest.height;
|
|
28
35
|
// The region owns its authored size; its child fills the allotted viewport.
|
|
29
36
|
probe.style.width = '100%'; probe.style.height = '100%';
|
|
30
37
|
rest.style = probe.style.cssText;
|
|
@@ -38,7 +45,8 @@ function projectBorderChild(element, attrs, {adapt, invoke, publish, publishPare
|
|
|
38
45
|
if (drawerAttrs.style != null) drawerAttrs.style = drawerProbe.style.cssText;
|
|
39
46
|
borderRegions.set(element, {region, size, min, max, splitter: rest.splitter === true,
|
|
40
47
|
drawer: rest.drawer, hidden: rest.hidden === true,
|
|
41
|
-
splitterAttrs: adapt(splitter), drawerAttrs, label, icon, minimize,
|
|
48
|
+
splitterAttrs: adapt(splitter), drawerAttrs, label, icon, minimize,
|
|
49
|
+
writeParameter: size => { if (numeric) writeParameter(dimension, size); }, notifications: {
|
|
42
50
|
closableChange: payload => publish('closable_change', payload),
|
|
43
51
|
splitterResize: payload => publishParent('splitter_resize', payload),
|
|
44
52
|
},
|
|
@@ -71,7 +79,7 @@ export const ContentPane = defineComponent({
|
|
|
71
79
|
|
|
72
80
|
export const BorderContainer = defineComponent({
|
|
73
81
|
name: 'borderContainer', tag: 'gramlot-border-container', base: Container, subTags: '*',
|
|
74
|
-
childParameters: {region: {required: true, enum: REGIONS, unique: true}, drawer_onclick: {inline: ['evt', 'show']}},
|
|
82
|
+
childParameters: {region: {required: true, enum: REGIONS, unique: true}, width: {}, height: {}, drawer_onclick: {inline: ['evt', 'show']}},
|
|
75
83
|
parameters: {
|
|
76
84
|
design: {dtype: 'T', default: 'headline', binding: 'read', enum: ['headline', 'sidebar']},
|
|
77
85
|
persist: {dtype: 'B', default: false, binding: 'read'},
|
|
@@ -326,6 +334,7 @@ export const BorderContainer = defineComponent({
|
|
|
326
334
|
const available = Math.max(0, (horizontal(side) ? box.height : box.width) - this.#extent(opposite));
|
|
327
335
|
const size = Math.max(Math.min(c.min, available), Math.min(desired, c.max, available));
|
|
328
336
|
state.size = `${size}px`; this.#render(side);
|
|
337
|
+
c.writeParameter(size);
|
|
329
338
|
}
|
|
330
339
|
#keyResize(side, evt) {
|
|
331
340
|
const state = this.#regions.get(side);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export function mountIndexPage(renderer: any, root: any,
|
|
2
2
|
onSelection?: (entries: Map<string, any>, active: string) => void,
|
|
3
3
|
prepareEntry?: (entry: any, context: any) => void,
|
|
4
|
-
options?: {containerLayout?: boolean; state?: any
|
|
4
|
+
options?: {containerLayout?: boolean; state?: any; createEntry?: (entry: any) => Promise<void>;
|
|
5
|
+
onLoad?: (key: string, status: string, error?: Error) => void}): {dispose(): void};
|
|
5
6
|
/** Re-export as Logic, or delegate indexMount from an application's Logic. */
|
|
6
7
|
export class IndexLogic {
|
|
7
8
|
indexMount(node: any, args: {shell_id: string}): void;
|
|
@@ -3,7 +3,8 @@ import {appearanceStyles} from './index-page-styles.js';
|
|
|
3
3
|
import {THEME_READY, THEME_SET, THEMES, APPEARANCES} from './index-theme.js';
|
|
4
4
|
|
|
5
5
|
/** Index-page behavior; writes UI state through the existing Source records. */
|
|
6
|
-
export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEntry = () => {}, {containerLayout = false, state: suppliedState = null} = {}) {
|
|
6
|
+
export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEntry = () => {}, {containerLayout = false, state: suppliedState = null, createEntry = null, onLoad = () => {}} = {}) {
|
|
7
|
+
if (createEntry && !containerLayout) throw new TypeError('Deferred index entries require containerLayout');
|
|
7
8
|
const shell = renderer.records.get(root).element;
|
|
8
9
|
const document = shell.ownerDocument;
|
|
9
10
|
const window = document.defaultView;
|
|
@@ -113,17 +114,49 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
113
114
|
set(shell, {data_code_visible: String(visible)});
|
|
114
115
|
}
|
|
115
116
|
};
|
|
117
|
+
const prepare = entry => {
|
|
118
|
+
entry.panel = byId(`panel-${entry.key}`);
|
|
119
|
+
entry.tab = containerLayout ? entry.panel : byId(`tab-${entry.key}`);
|
|
120
|
+
entry.code = byId(`codepane-${entry.key}`);
|
|
121
|
+
if (entry.key === 'intro') return;
|
|
122
|
+
prepareEntry(entry, {byId, node, set, listen});
|
|
123
|
+
entry.frame = byId(`frame-${entry.key}`);
|
|
124
|
+
if (entry.frame) listen(entry.frame, 'load', () => send(entry.frame));
|
|
125
|
+
};
|
|
126
|
+
const openEntry = entry => {
|
|
127
|
+
if (opened.getItem(entry.key)) return;
|
|
128
|
+
opened.setItem(entry.key, true);
|
|
129
|
+
set(containerLayout ? entry.panel : entry.tab, {hidden: false});
|
|
130
|
+
if (entry.frame) set(entry.frame, {src: entry.open.getAttribute('href')});
|
|
131
|
+
};
|
|
116
132
|
let selecting = false;
|
|
117
133
|
function select(key) {
|
|
118
|
-
if (selecting) return;
|
|
134
|
+
if (selecting || disposed) return;
|
|
135
|
+
const requested = entries.get(key);
|
|
136
|
+
if (!requested) return;
|
|
137
|
+
state.setItem('requested', key);
|
|
138
|
+
if (!requested.panel) {
|
|
139
|
+
onLoad(key, 'loading');
|
|
140
|
+
if (!requested.loading) {
|
|
141
|
+
requested.loading = Promise.resolve().then(() => { if (!disposed) return createEntry(requested); }).then(() => {
|
|
142
|
+
if (disposed) return;
|
|
143
|
+
prepare(requested);
|
|
144
|
+
openEntry(requested);
|
|
145
|
+
if (state.getItem('requested') === key) {
|
|
146
|
+
onLoad(key, 'ready');
|
|
147
|
+
select(key);
|
|
148
|
+
}
|
|
149
|
+
}).catch(error => {
|
|
150
|
+
if (!disposed && state.getItem('requested') === key) onLoad(key, 'error', error);
|
|
151
|
+
}).finally(() => { requested.loading = null; });
|
|
152
|
+
}
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
onLoad(key, 'ready');
|
|
119
156
|
selecting = true;
|
|
120
157
|
try {
|
|
121
158
|
const entry = entries.get(key);
|
|
122
|
-
|
|
123
|
-
opened.setItem(key, true);
|
|
124
|
-
set(containerLayout ? entry.panel : entry.tab, {hidden: false});
|
|
125
|
-
if (entry.frame) set(entry.frame, {src: entry.open.getAttribute('href')});
|
|
126
|
-
}
|
|
159
|
+
openEntry(entry);
|
|
127
160
|
if (entry.family) set(entry.family, {open: true});
|
|
128
161
|
for (const [current, item] of entries) {
|
|
129
162
|
const active = current === key;
|
|
@@ -282,14 +315,16 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
282
315
|
});
|
|
283
316
|
listen(window, 'resize', () => setSidebarWidth(state.getItem('preferredSidebarWidth')));
|
|
284
317
|
}
|
|
285
|
-
const choices =
|
|
318
|
+
const choices = createEntry
|
|
319
|
+
? [byId('panel-intro'), ...shell.querySelectorAll('.index-sidebar a[id^="open-"]')]
|
|
320
|
+
: containerLayout ? byId('index-pages').children : shell.querySelectorAll('.index-tabs button');
|
|
286
321
|
for (const tab of choices) {
|
|
287
|
-
const key = tab.id.slice(containerLayout ? 'panel-'.length : 'tab-'.length);
|
|
322
|
+
const key = tab.id.slice(createEntry && tab.id.startsWith('open-') ? 'open-'.length : containerLayout ? 'panel-'.length : 'tab-'.length);
|
|
288
323
|
const entry = {key, tab, panel: byId(`panel-${key}`),
|
|
289
324
|
code: byId(`codepane-${key}`),
|
|
290
325
|
open: key === 'intro' ? null : byId(`open-${key}`)};
|
|
291
326
|
entries.set(key, entry);
|
|
292
|
-
if (containerLayout ? node(
|
|
327
|
+
if (entry.panel && (containerLayout ? node(entry.panel).getAttr('hidden') !== true : !tab.hidden)) opened.setItem(key, true);
|
|
293
328
|
if (!containerLayout && tab.getAttribute('aria-selected') === 'true') state.setItem('active', key);
|
|
294
329
|
if (!containerLayout) listen(tab, 'click', () => select(key));
|
|
295
330
|
if (entry.open) listen(entry.open, 'click', event => { event.preventDefault(); select(key); });
|
|
@@ -305,12 +340,17 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
305
340
|
});
|
|
306
341
|
if (key === 'intro') continue;
|
|
307
342
|
entry.family = entry.open.closest('details');
|
|
308
|
-
|
|
309
|
-
if (entry.panel.classList.contains('index-category')) continue;
|
|
310
|
-
entry.frame = byId(`frame-${key}`);
|
|
311
|
-
listen(entry.frame, 'load', () => send(entry.frame));
|
|
343
|
+
if (entry.panel) prepare(entry);
|
|
312
344
|
}
|
|
313
345
|
if (containerLayout) {
|
|
346
|
+
const pages = byId('index-pages');
|
|
347
|
+
listen(pages, 'click', event => {
|
|
348
|
+
// Re-clicking the active tab need not change Data, but supersedes a pending navigation.
|
|
349
|
+
if (event.target === pages && event.composedPath().some(element =>
|
|
350
|
+
element instanceof window.Element && element.getAttribute('role') === 'tab')) {
|
|
351
|
+
select(state.getItem('active'));
|
|
352
|
+
}
|
|
353
|
+
});
|
|
314
354
|
const subscription = `${shell.id}-selection`;
|
|
315
355
|
state.subscribe(subscription, {any: event => {
|
|
316
356
|
if (event.node === state.getNode('active')) select(state.getItem('active'));
|
package/src/view/html.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {SourceBag, META_ATTRS, resolveRenderTag, sourceAttributeItems, SvgBuilder} from '@genrojs/builders';
|
|
1
|
+
import {SourceBag, META_ATTRS, resolveRenderTag, sourceAttributeItems, SvgBuilder, pointerTransform} from '@genrojs/builders';
|
|
2
2
|
import {ControlAdapter} from './controls.js';
|
|
3
3
|
import {SVG_NS, XHTML_NS} from '../renderer/attributes.js';
|
|
4
4
|
import {requireNoScriptAttributes, requireStyleClassAttributes} from '../renderer/attributes.js';
|
|
@@ -94,12 +94,7 @@ export class HtmlElement {
|
|
|
94
94
|
if (meta.gramlot_component?.sourceContext) {
|
|
95
95
|
element.setSourceContext({
|
|
96
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
|
-
},
|
|
97
|
+
writeParameter: (name, value) => this.writeParameter(node, name, value),
|
|
103
98
|
});
|
|
104
99
|
}
|
|
105
100
|
const text = document.createTextNode(this.text(node));
|
|
@@ -115,6 +110,15 @@ export class HtmlElement {
|
|
|
115
110
|
&& record.element.namespaceURI === namespace;
|
|
116
111
|
}
|
|
117
112
|
|
|
113
|
+
/** Write a component interaction through a plain reactive Source pointer. */
|
|
114
|
+
writeParameter(node, name, value) {
|
|
115
|
+
const pointer = node.getAttr(name);
|
|
116
|
+
if (node.pointerType(pointer) === '^' && !pointerTransform(pointer)
|
|
117
|
+
&& !Object.is(node.getRelativeData(pointer.slice(1)), value)) {
|
|
118
|
+
node.setRelativeData(pointer.slice(1), value);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
118
122
|
compose(record, text, children) {
|
|
119
123
|
record.text.data = text ?? '';
|
|
120
124
|
for (const child of children) record.element.append(child);
|
|
@@ -144,6 +148,7 @@ export class HtmlElement {
|
|
|
144
148
|
invoke: (name, code, keywords) => this.invokeScript(node, name, code, keywords),
|
|
145
149
|
publish: (topic, payload) => node.publish(topic, payload),
|
|
146
150
|
publishParent: (topic, payload) => parent.publish(topic, payload),
|
|
151
|
+
writeParameter: (name, value) => this.writeParameter(node, name, value),
|
|
147
152
|
remove: () => node.parentBag.popNode(node.label),
|
|
148
153
|
});
|
|
149
154
|
}
|