@gramlot/gramlot 0.3.7 → 0.3.9
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/components/editors.js +116527 -0
- package/dist/components/inputs.js +24507 -0
- package/dist/components/layout.js +1402 -0
- package/dist/components/tree.js +24538 -0
- package/dist/components/typst.js +4 -0
- package/dist/gramlot.js +1442 -625
- package/dist/gramlot.min.js +27 -405
- package/dist/runtime-notices.json +208 -0
- package/dist/typst-worker-source.js +4 -0
- package/package.json +36 -3
- package/src/binding/hooks.js +14 -0
- package/src/binding/providers.js +4 -0
- package/src/binding/remote-resolver.js +52 -0
- package/src/binding/remote.js +2 -0
- package/src/binding/router.js +11 -4
- package/src/binding/rpc-resolver.js +14 -93
- package/src/binding/runtime.js +10 -4
- package/src/components/bases.js +1 -0
- package/src/components/border-container.js +46 -23
- package/src/components/buttons.js +3 -0
- package/src/components/choice-editor.js +17 -3
- package/src/components/choices.js +3 -2
- package/src/components/code-mirror-engine.js +91 -0
- package/src/components/code-mirror.js +88 -0
- package/src/components/editor-options.d.ts +9 -0
- package/src/components/editor-options.js +21 -0
- package/src/components/editors.js +10 -0
- package/src/components/html-document.js +56 -0
- package/src/components/html-editor.js +68 -0
- package/src/components/html-preview.js +33 -0
- package/src/components/inputs.js +2 -2
- package/src/components/jodit-engine.js +89 -0
- package/src/components/markdown-codec.js +35 -0
- package/src/components/markdown-document.js +14 -0
- package/src/components/markdown-editor.js +68 -0
- package/src/components/prose-mirror-engine.js +65 -0
- package/src/components/registry.js +6 -4
- package/src/components/tree.js +350 -0
- package/src/components/typst-client.js +38 -0
- package/src/components/typst-preview.js +88 -0
- package/src/components/typst-worker.js +49 -0
- package/src/components/typst.js +4 -0
- package/src/filesystem.d.ts +22 -0
- package/src/filesystem.js +122 -0
- package/src/ide-documents.js +153 -0
- package/src/ide-runtime.d.ts +18 -0
- package/src/ide-runtime.js +238 -0
- package/src/index-page-runtime.d.ts +7 -8
- package/src/index-page-runtime.js +100 -396
- package/src/index.d.ts +7 -1
- package/src/index.js +5 -1
- package/src/navigation-resolver.d.ts +6 -0
- package/src/navigation-resolver.js +60 -0
- package/src/renderer/attributes.js +2 -1
- package/src/renderer/drag-drop-policy.js +48 -0
- package/src/renderer/drag-drop.js +213 -0
- package/src/renderer/drag-preparation.js +33 -0
- package/src/renderer/gramlot-renderer.d.ts +18 -0
- package/src/renderer/gramlot-renderer.js +41 -2
- package/src/server/frame-page.d.ts +12 -0
- package/src/server/frame-page.js +23 -0
- package/src/server/gramlot-server.js +2 -1
- package/src/server/index-page.d.ts +10 -14
- package/src/server/index-page.js +26 -95
- package/src/server/page.d.ts +7 -0
- package/src/server/page.js +5 -0
- package/src/view/button.js +2 -1
- package/src/view/controls.js +7 -11
- package/src/view/events.js +4 -8
- package/src/view/html.js +6 -1
- package/tools/gramlot-tools-inspector.js +16 -9
|
@@ -1,413 +1,118 @@
|
|
|
1
1
|
/* @ts-self-types="./index-page-runtime.d.ts" */
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import {Bag} from '@genrojs/bag';
|
|
3
|
+
import {sourceTarget} from '@genrojs/builders';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const theme = byId('index-theme');
|
|
16
|
-
const appearance = byId('index-appearance');
|
|
17
|
-
const sidebar = byId('index-sidebar');
|
|
18
|
-
const sidebarHandle = byId('index-sidebar-divider');
|
|
19
|
-
const navigationToggle = byId('index-navigation-toggle');
|
|
20
|
-
const codeToggle = byId('index-code-toggle');
|
|
21
|
-
const codeSidebar = byId('index-code');
|
|
22
|
-
const codeHandle = byId('index-code-divider');
|
|
23
|
-
// localStorage is scoped to this origin; the path separates mounted galleries.
|
|
24
|
-
const preferencesKey = `gramlot.${shell.id}.preferences:${window.location.pathname}`;
|
|
25
|
-
let preferences = {};
|
|
26
|
-
try {
|
|
27
|
-
const saved = JSON.parse(window.localStorage.getItem(preferencesKey));
|
|
28
|
-
if (saved !== null && typeof saved === 'object' && !Array.isArray(saved)) preferences = saved;
|
|
29
|
-
} catch (error) {
|
|
30
|
-
if (error.name !== 'SyntaxError' && error.name !== 'SecurityError') throw error;
|
|
31
|
-
}
|
|
32
|
-
const restoreChoice = (control, value, allowed) => {
|
|
33
|
-
if (!control || !allowed.has(value)) return;
|
|
34
|
-
set(control, {value});
|
|
35
|
-
for (const option of control.options) set(option, {selected: option.value === value});
|
|
36
|
-
};
|
|
37
|
-
restoreChoice(theme, preferences.theme, THEMES);
|
|
38
|
-
restoreChoice(appearance, preferences.appearance, APPEARANCES);
|
|
39
|
-
const families = [...shell.querySelectorAll('.index-sidebar details')];
|
|
40
|
-
const Bag = root.builder.data.constructor;
|
|
41
|
-
const state = suppliedState ?? new Bag();
|
|
42
|
-
const opened = new Bag();
|
|
43
|
-
state.setItem('opened', opened);
|
|
44
|
-
state.setItem('keyboard', (keyboard?.checked ?? false));
|
|
45
|
-
state.setItem('theme', (theme?.value ?? 'light'));
|
|
46
|
-
state.setItem('appearance', (appearance?.value ?? 'compact'));
|
|
47
|
-
state.setItem('navigationVisible', preferences.navigationVisible !== false);
|
|
48
|
-
state.setItem('codeVisible', preferences.codeVisible !== false);
|
|
49
|
-
const savePreferences = () => {
|
|
50
|
-
try {
|
|
51
|
-
window.localStorage.setItem(preferencesKey, JSON.stringify({
|
|
52
|
-
theme: state.getItem('theme'), appearance: state.getItem('appearance'),
|
|
53
|
-
sidebarWidth: state.getItem('preferredSidebarWidth'),
|
|
54
|
-
codeWidth: state.getItem('preferredCodeWidth'),
|
|
55
|
-
navigationVisible: state.getItem('navigationVisible'),
|
|
56
|
-
codeVisible: state.getItem('codeVisible'),
|
|
57
|
-
}));
|
|
58
|
-
} catch (error) {
|
|
59
|
-
// A browser may deny storage (including opaque file origins) or exhaust its quota.
|
|
60
|
-
// Keep the current interaction usable; no other persistence mechanism is used.
|
|
61
|
-
if (error.name !== 'SecurityError' && error.name !== 'QuotaExceededError') throw error;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
5
|
+
/** Coordinate a declared navigation Bag and tabContainer through Source and Data.
|
|
6
|
+
* Region contents, drawer presentation, themes and application controls belong to the Page.
|
|
7
|
+
*/
|
|
8
|
+
export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEntry = () => {},
|
|
9
|
+
{state = root.builder.data.getItem(root.getAttr('datapath')), createEntry = null,
|
|
10
|
+
onLoad = () => {}} = {}) {
|
|
11
|
+
const navigation = state.getItem('navigation');
|
|
12
|
+
if (!(navigation instanceof Bag)) throw new TypeError('IndexPage navigation must be a Bag');
|
|
13
|
+
const tabs = root.value.getNode('frame.center.tabs');
|
|
14
|
+
const builder = root.builder;
|
|
64
15
|
const entries = new Map();
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const stopDrag = () => {
|
|
77
|
-
if (!drag) return;
|
|
78
|
-
const {handle, pointerId} = drag;
|
|
79
|
-
drag = null;
|
|
80
|
-
if (!disposed) set(shell, {data_resizing: null});
|
|
81
|
-
if (handle.hasPointerCapture(pointerId)) handle.releasePointerCapture(pointerId);
|
|
82
|
-
};
|
|
83
|
-
const dispose = () => {
|
|
16
|
+
let disposed = false, selecting = false, sequence = 0, requested = null;
|
|
17
|
+
const opened = state.getItem('opened');
|
|
18
|
+
for (const record of opened.getNodes()) {
|
|
19
|
+
const {url, path, title} = record.attr;
|
|
20
|
+
const pane = tabs.value.getNode(record.label);
|
|
21
|
+
const entry = {url, path, title, pane, node: navigation.getNode(path), loading: false};
|
|
22
|
+
prepareEntry(entry);
|
|
23
|
+
entries.set(url, entry);
|
|
24
|
+
sequence++;
|
|
25
|
+
}
|
|
26
|
+
const activate = entry => {
|
|
84
27
|
if (disposed) return;
|
|
85
|
-
disposed = true;
|
|
86
|
-
installPrompt = null;
|
|
87
|
-
stopDrag();
|
|
88
|
-
for (const release of releases.reverse()) release();
|
|
89
|
-
if (style.parentBag) style.parentBag.popNode(style.label);
|
|
90
|
-
if (previousTheme == null) document.documentElement.removeAttribute('data-theme');
|
|
91
|
-
else document.documentElement.setAttribute('data-theme', previousTheme);
|
|
92
|
-
};
|
|
93
|
-
const send = frame => frame.contentWindow.postMessage({type: THEME_SET, theme: state.getItem('theme'), appearance: state.getItem('appearance')}, '*');
|
|
94
|
-
const applyTheme = () => {
|
|
95
|
-
document.documentElement.setAttribute('data-theme', state.getItem('theme'));
|
|
96
|
-
style.setValue(appearanceStyles[state.getItem('appearance')]);
|
|
97
|
-
for (const {frame} of entries.values()) if (frame) send(frame);
|
|
98
|
-
};
|
|
99
|
-
const updateInspector = () => onSelection(entries, state.getItem('active'));
|
|
100
|
-
const updatePanels = () => {
|
|
101
|
-
if (navigationToggle) {
|
|
102
|
-
const visible = state.getItem('navigationVisible');
|
|
103
|
-
set(sidebar, containerLayout ? {drawer: visible ? true : 'close'} : {hidden: !visible});
|
|
104
|
-
if (!containerLayout) set(sidebarHandle, {hidden: !visible});
|
|
105
|
-
set(navigationToggle, {aria_expanded: String(visible)});
|
|
106
|
-
set(shell, {data_navigation_hidden: String(!visible)});
|
|
107
|
-
}
|
|
108
|
-
if (codeSidebar) {
|
|
109
|
-
const available = Boolean(entries.get(state.getItem('active'))?.code);
|
|
110
|
-
const visible = available && state.getItem('codeVisible');
|
|
111
|
-
set(codeSidebar, containerLayout ? {hidden: !available, drawer: visible ? true : 'close'} : {hidden: !visible});
|
|
112
|
-
if (!containerLayout) set(codeHandle, {hidden: !visible});
|
|
113
|
-
set(codeToggle, {disabled: !available, aria_expanded: String(visible)});
|
|
114
|
-
set(shell, {data_code_visible: String(visible)});
|
|
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
|
-
};
|
|
132
|
-
let selecting = false;
|
|
133
|
-
function select(key) {
|
|
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');
|
|
156
28
|
selecting = true;
|
|
157
29
|
try {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
for (const [current, item] of entries) {
|
|
162
|
-
const active = current === key;
|
|
163
|
-
if (!containerLayout) {
|
|
164
|
-
set(item.tab, {aria_selected: String(active), tabindex: active && state.getItem('keyboard') ? 0 : -1});
|
|
165
|
-
set(item.panel, {hidden: !active});
|
|
166
|
-
}
|
|
167
|
-
if (item.code) set(item.code, {hidden: !active});
|
|
168
|
-
if (item.open) set(item.open, {aria_current: active ? 'page' : null});
|
|
169
|
-
}
|
|
170
|
-
if (state.getItem('active') !== key) state.setItem('active', key);
|
|
171
|
-
updatePanels();
|
|
172
|
-
updateInspector();
|
|
30
|
+
state.setItem('active', entry.url);
|
|
31
|
+
state.setItem('navigationSelection', entry.path);
|
|
32
|
+
onSelection(entries, entry.url);
|
|
173
33
|
} finally { selecting = false; }
|
|
174
|
-
}
|
|
175
|
-
const sidebarMaximum = () => Math.max(120, Math.min(460, Math.floor(window.innerWidth * .6)));
|
|
176
|
-
const applyWidths = () => set(shell, {style: `--sidebar-width: ${state.getItem('sidebarWidth')}px; --code-width: ${state.getItem('codeWidth') ?? 420}px`});
|
|
177
|
-
const setSidebarWidth = (value, remember = false) => {
|
|
178
|
-
const maximum = sidebarMaximum();
|
|
179
|
-
const width = Math.max(120, Math.min(maximum, value));
|
|
180
|
-
state.setItem('sidebarWidth', width);
|
|
181
|
-
applyWidths();
|
|
182
|
-
set(sidebarHandle, {aria_valuenow: width, aria_valuemax: maximum});
|
|
183
|
-
if (remember) {
|
|
184
|
-
state.setItem('preferredSidebarWidth', width);
|
|
185
|
-
savePreferences();
|
|
186
|
-
}
|
|
187
34
|
};
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
35
|
+
async function select(path) {
|
|
36
|
+
const node = navigation.getNode(path);
|
|
37
|
+
if (!node) throw new Error(`Unknown index navigation path: ${path}`);
|
|
38
|
+
const url = node.attr.url;
|
|
39
|
+
if (url == null) return; // A folder may have children without its own page.
|
|
40
|
+
if (typeof url !== 'string' || !url) throw new TypeError('IndexPage URL must be nonempty text');
|
|
41
|
+
requested = url;
|
|
42
|
+
let entry = entries.get(url);
|
|
43
|
+
if (entry) {
|
|
44
|
+
entry.path = path;
|
|
45
|
+
activate(entry);
|
|
46
|
+
return;
|
|
198
47
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
48
|
+
while (tabs.value !== null && tabs.value.getNode(`page${sequence}`)) sequence++;
|
|
49
|
+
const pane = sourceTarget(builder.wrapSource(tabs).contentPane({node_label: `page${sequence++}`,
|
|
50
|
+
title: node.attr.title ?? node.label, pageName: url, height: '100%'}));
|
|
51
|
+
const previous = state.getItem('active');
|
|
52
|
+
entry = {url, path, node, pane, title: node.attr.title ?? node.label, loading: true};
|
|
53
|
+
entries.set(url, entry);
|
|
54
|
+
try {
|
|
55
|
+
activate(entry);
|
|
56
|
+
onLoad(url, 'loading');
|
|
57
|
+
if (createEntry) await createEntry(entry);
|
|
58
|
+
else {
|
|
59
|
+
const selection = new Bag();
|
|
60
|
+
selection.setItem(node.label, null, {...node.attr});
|
|
61
|
+
const mounted = await renderer.binding.gramlot.src.remoteSource(pane, 'index_panel', {selection});
|
|
62
|
+
if (!mounted) throw new Error('Panel loading was cancelled');
|
|
63
|
+
}
|
|
64
|
+
if (disposed) return;
|
|
65
|
+
entry.loading = false;
|
|
66
|
+
opened.setItem(pane.label, null, {url, path: entry.path, title: entry.title});
|
|
67
|
+
prepareEntry(entry);
|
|
68
|
+
if (requested === url) { onLoad(url, 'ready'); activate(entry); }
|
|
69
|
+
} catch (error) {
|
|
70
|
+
entries.delete(url);
|
|
71
|
+
if (opened.getNode(pane.label)) opened.popNode(pane.label);
|
|
72
|
+
if (pane.parentBag) pane.parentBag.popNode(pane.label);
|
|
73
|
+
if (!disposed && requested === url) {
|
|
74
|
+
onLoad(url, 'error', error);
|
|
75
|
+
const restored = entries.get(previous);
|
|
76
|
+
requested = restored?.url ?? null;
|
|
77
|
+
if (restored) activate(restored);
|
|
78
|
+
else {
|
|
79
|
+
selecting = true;
|
|
80
|
+
try {
|
|
81
|
+
state.setItem('active', null);
|
|
82
|
+
state.setItem('navigationSelection', null);
|
|
83
|
+
onSelection(entries, null);
|
|
84
|
+
} finally { selecting = false; }
|
|
235
85
|
}
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
set(shell, {data_resizing: null});
|
|
239
|
-
// Retain the preferred width when a narrow viewport temporarily limits the visible sidebar.
|
|
240
|
-
if (!containerLayout) {
|
|
241
|
-
const savedWidth = preferences.sidebarWidth;
|
|
242
|
-
const width = typeof savedWidth === 'number' && Number.isFinite(savedWidth) && savedWidth >= 120 && savedWidth <= 460
|
|
243
|
-
? savedWidth : sidebar.getBoundingClientRect().width || Number(sidebarHandle.getAttribute('aria-valuenow'));
|
|
244
|
-
state.setItem('preferredSidebarWidth', width);
|
|
245
|
-
setSidebarWidth(width);
|
|
246
|
-
} else {
|
|
247
|
-
const gramlot = renderer.binding.gramlot;
|
|
248
|
-
for (const [pane, property, widthProperty] of [[sidebar, 'navigationVisible', 'sidebarWidth'], [codeSidebar, 'codeVisible', 'codeWidth']]) {
|
|
249
|
-
const source = node(pane);
|
|
250
|
-
const savedWidth = preferences[widthProperty];
|
|
251
|
-
if (typeof savedWidth === 'number' && Number.isFinite(savedWidth) && savedWidth > 0) set(pane, {width: `${savedWidth}px`});
|
|
252
|
-
const handle = gramlot.subscribe(`${source.getAttr('nodeId')}_closable_change`, ({open}) => {
|
|
253
|
-
if (source.getAttr('hidden') === true || source.getAttr('drawer') === false) return;
|
|
254
|
-
state.setItem(property, open);
|
|
255
|
-
set(pane, {drawer: open ? true : 'close'});
|
|
256
|
-
set(property === 'navigationVisible' ? navigationToggle : codeToggle, {aria_expanded: String(open)});
|
|
257
|
-
set(shell, {[property === 'navigationVisible' ? 'data_navigation_hidden' : 'data_code_visible']: String(property === 'navigationVisible' ? !open : open)});
|
|
258
|
-
savePreferences();
|
|
259
|
-
});
|
|
260
|
-
releases.push(() => gramlot.unsubscribe(handle));
|
|
261
86
|
}
|
|
262
|
-
const border = shell.querySelector('[data-index-regions]');
|
|
263
|
-
const handle = gramlot.subscribe(`${node(border).getAttr('nodeId')}_splitter_resize`, ({region, size}) => {
|
|
264
|
-
set(region === 'left' ? sidebar : codeSidebar, {width: size});
|
|
265
|
-
state.setItem(region === 'left' ? 'preferredSidebarWidth' : 'preferredCodeWidth', Number.parseFloat(size));
|
|
266
|
-
savePreferences();
|
|
267
|
-
});
|
|
268
|
-
releases.push(() => gramlot.unsubscribe(handle));
|
|
269
|
-
state.setItem('preferredSidebarWidth', preferences.sidebarWidth);
|
|
270
|
-
state.setItem('preferredCodeWidth', preferences.codeWidth);
|
|
271
87
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
if (!containerLayout && codeHandle) {
|
|
283
|
-
const saved = preferences.codeWidth;
|
|
284
|
-
const width = typeof saved === 'number' && Number.isFinite(saved) && saved >= 200 ? saved : 420;
|
|
285
|
-
state.setItem('preferredCodeWidth', width);
|
|
286
|
-
setCodeWidth(width);
|
|
287
|
-
listen(codeHandle, 'keydown', event => {
|
|
288
|
-
const current = state.getItem('codeWidth');
|
|
289
|
-
const value = event.key === 'ArrowLeft' ? current + 10 : event.key === 'ArrowRight' ? current - 10
|
|
290
|
-
: event.key === 'Home' ? 200 : event.key === 'End' ? codeMaximum() : null;
|
|
291
|
-
if (value == null) return;
|
|
292
|
-
event.preventDefault();
|
|
293
|
-
setCodeWidth(value, true);
|
|
294
|
-
});
|
|
295
|
-
listen(codeHandle, 'pointerdown', event => beginDrag(codeHandle, event,
|
|
296
|
-
x => setCodeWidth(Math.round(shell.getBoundingClientRect().right - x), true)));
|
|
297
|
-
listen(codeHandle, 'lostpointercapture', () => {
|
|
298
|
-
if (drag?.handle === codeHandle) stopDrag();
|
|
299
|
-
});
|
|
300
|
-
listen(window, 'resize', () => setCodeWidth(state.getItem('preferredCodeWidth')));
|
|
301
|
-
}
|
|
302
|
-
if (!containerLayout) {
|
|
303
|
-
listen(sidebarHandle, 'keydown', event => {
|
|
304
|
-
const current = state.getItem('sidebarWidth');
|
|
305
|
-
const value = event.key === 'ArrowLeft' ? current - 10 : event.key === 'ArrowRight' ? current + 10
|
|
306
|
-
: event.key === 'Home' ? 120 : event.key === 'End' ? sidebarMaximum() : null;
|
|
307
|
-
if (value == null) return;
|
|
308
|
-
event.preventDefault();
|
|
309
|
-
setSidebarWidth(value, true);
|
|
310
|
-
});
|
|
311
|
-
listen(sidebarHandle, 'pointerdown', event => beginDrag(sidebarHandle, event,
|
|
312
|
-
x => setSidebarWidth(Math.round(x - shell.getBoundingClientRect().left), true)));
|
|
313
|
-
listen(sidebarHandle, 'lostpointercapture', () => {
|
|
314
|
-
if (drag?.handle === sidebarHandle) stopDrag();
|
|
315
|
-
});
|
|
316
|
-
listen(window, 'resize', () => setSidebarWidth(state.getItem('preferredSidebarWidth')));
|
|
317
|
-
}
|
|
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');
|
|
321
|
-
for (const tab of choices) {
|
|
322
|
-
const key = tab.id.slice(createEntry && tab.id.startsWith('open-') ? 'open-'.length : containerLayout ? 'panel-'.length : 'tab-'.length);
|
|
323
|
-
const entry = {key, tab, panel: byId(`panel-${key}`),
|
|
324
|
-
code: byId(`codepane-${key}`),
|
|
325
|
-
open: key === 'intro' ? null : byId(`open-${key}`)};
|
|
326
|
-
entries.set(key, entry);
|
|
327
|
-
if (entry.panel && (containerLayout ? node(entry.panel).getAttr('hidden') !== true : !tab.hidden)) opened.setItem(key, true);
|
|
328
|
-
if (!containerLayout && tab.getAttribute('aria-selected') === 'true') state.setItem('active', key);
|
|
329
|
-
if (!containerLayout) listen(tab, 'click', () => select(key));
|
|
330
|
-
if (entry.open) listen(entry.open, 'click', event => { event.preventDefault(); select(key); });
|
|
331
|
-
if (!containerLayout) listen(tab, 'keydown', event => {
|
|
332
|
-
if (!state.getItem('keyboard') || !['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
|
|
333
|
-
const keys = [...entries.keys()].filter(key => opened.getItem(key));
|
|
334
|
-
const index = keys.indexOf(key);
|
|
335
|
-
const next = event.key === 'Home' ? 0 : event.key === 'End' ? keys.length - 1
|
|
336
|
-
: (index + (event.key === 'ArrowRight' ? 1 : -1) + keys.length) % keys.length;
|
|
337
|
-
event.preventDefault();
|
|
338
|
-
select(keys[next]);
|
|
339
|
-
entries.get(keys[next]).tab.focus();
|
|
340
|
-
});
|
|
341
|
-
if (key === 'intro') continue;
|
|
342
|
-
entry.family = entry.open.closest('details');
|
|
343
|
-
if (entry.panel) prepare(entry);
|
|
88
|
+
}
|
|
89
|
+
const subscription = `${root.getAttr('id')}-selection`;
|
|
90
|
+
state.subscribe(subscription, {any: event => {
|
|
91
|
+
if (selecting || disposed) return;
|
|
92
|
+
if (event.node === state.getNode('navigationSelection')) {
|
|
93
|
+
const path = state.getItem('navigationSelection');
|
|
94
|
+
if (path !== null) void select(path);
|
|
95
|
+
} else if (event.node === state.getNode('active')) {
|
|
96
|
+
const entry = entries.get(state.getItem('active'));
|
|
97
|
+
if (entry) { requested = entry.url; activate(entry); }
|
|
344
98
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
const subscription = `${shell.id}-selection`;
|
|
355
|
-
state.subscribe(subscription, {any: event => {
|
|
356
|
-
if (event.node === state.getNode('active')) select(state.getItem('active'));
|
|
357
|
-
}});
|
|
358
|
-
releases.push(() => state.unsubscribe(subscription, {any: true}));
|
|
99
|
+
}});
|
|
100
|
+
const dispose = () => {
|
|
101
|
+
if (disposed) return;
|
|
102
|
+
disposed = true;
|
|
103
|
+
state.unsubscribe(subscription, {any: true});
|
|
104
|
+
for (const entry of entries.values()) if (entry.loading && entry.pane.parentBag) {
|
|
105
|
+
entry.pane.parentBag.popNode(entry.pane.label);
|
|
359
106
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
});
|
|
367
|
-
for (const family of families) listen(family, 'toggle', () => set(family, {open: family.open}));
|
|
368
|
-
listen(keyboard, 'change', () => {
|
|
369
|
-
state.setItem('keyboard', (keyboard?.checked ?? false));
|
|
370
|
-
set(keyboard, {checked: (keyboard?.checked ?? false)});
|
|
371
|
-
for (const [key, entry] of entries) {
|
|
372
|
-
if (entry.open) set(entry.open, {tabindex: (keyboard?.checked ?? false) ? 0 : -1});
|
|
373
|
-
if (!containerLayout) set(entry.tab, {tabindex: (keyboard?.checked ?? false) && key === state.getItem('active') ? 0 : -1});
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
listen(appearance, 'change', () => {
|
|
377
|
-
if (!APPEARANCES.has((appearance?.value ?? 'compact'))) throw new Error('Unknown index appearance');
|
|
378
|
-
state.setItem('appearance', (appearance?.value ?? 'compact'));
|
|
379
|
-
set(appearance, {value: (appearance?.value ?? 'compact')});
|
|
380
|
-
for (const option of appearance.options) set(option, {selected: option.value === (appearance?.value ?? 'compact')});
|
|
381
|
-
applyTheme();
|
|
382
|
-
savePreferences();
|
|
383
|
-
});
|
|
384
|
-
listen(theme, 'change', () => {
|
|
385
|
-
if (!THEMES.has((theme?.value ?? 'light'))) throw new Error('Index theme must be light or dark');
|
|
386
|
-
state.setItem('theme', (theme?.value ?? 'light'));
|
|
387
|
-
set(theme, {value: (theme?.value ?? 'light')});
|
|
388
|
-
for (const option of theme.options) set(option, {selected: option.value === (theme?.value ?? 'light')});
|
|
389
|
-
applyTheme();
|
|
390
|
-
savePreferences();
|
|
391
|
-
});
|
|
392
|
-
listen(window, 'message', event => {
|
|
393
|
-
if (event.data?.type !== THEME_READY) return;
|
|
394
|
-
for (const {frame} of entries.values()) {
|
|
395
|
-
if (frame && frame.contentWindow === event.source) { send(frame); updateInspector(); break; }
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
applyTheme();
|
|
399
|
-
updatePanels();
|
|
400
|
-
updateInspector();
|
|
401
|
-
renderer.onDispose(root, dispose);
|
|
402
|
-
} catch (error) {
|
|
403
|
-
dispose();
|
|
404
|
-
throw error;
|
|
405
|
-
}
|
|
406
|
-
return {dispose};
|
|
107
|
+
};
|
|
108
|
+
renderer.onDispose(root, dispose);
|
|
109
|
+
const active = entries.get(state.getItem('active'));
|
|
110
|
+
if (active) activate(active);
|
|
111
|
+
else if (state.getItem('navigationSelection') !== null) void select(state.getItem('navigationSelection'));
|
|
112
|
+
return {entries, dispose};
|
|
407
113
|
}
|
|
408
114
|
|
|
409
|
-
|
|
410
|
-
/** Re-export as the page's Logic, or delegate indexMount from a custom Logic. */
|
|
115
|
+
/** Re-export as the page's Logic; application Logic may delegate to indexMount. */
|
|
411
116
|
export class IndexLogic {
|
|
412
117
|
indexMount(node, {shell_id}) {
|
|
413
118
|
const renderer = this.page.src.renderer;
|
|
@@ -415,5 +120,4 @@ export class IndexLogic {
|
|
|
415
120
|
this.index = mountIndexPage(renderer, renderer.elements.get(element).node);
|
|
416
121
|
}
|
|
417
122
|
}
|
|
418
|
-
|
|
419
|
-
export {THEME_READY, THEME_SET, THEMES, APPEARANCES} from "./index-theme.js";
|
|
123
|
+
export {THEME_READY, THEME_SET, THEMES, APPEARANCES} from './index-theme.js';
|
package/src/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export {UtilitiesHandler} from './handlers/utilities-handler.js';
|
|
|
14
14
|
export type {GramlotOptions, GramlotState, Publication, SubscriptionHandle, FormatOptions} from './gramlot.js';
|
|
15
15
|
export {PageBootstrap} from './bootstrap.js';
|
|
16
16
|
export type {PageBootstrapOptions, PageResources} from './bootstrap.js';
|
|
17
|
-
export {Exposed, Page} from './server/page.js';
|
|
17
|
+
export {Exposed, Page, codeMirrorWithOptions} from './server/page.js';
|
|
18
18
|
export {GramlotBuilder} from './builder/gramlot-builder.js';
|
|
19
19
|
export {GramlotRenderer} from './renderer/gramlot-renderer.js';
|
|
20
20
|
export {GramlotHtmlRenderer} from './renderer/gramlot-html-renderer.js';
|
|
@@ -36,3 +36,9 @@ export {IndexLogic, mountIndexPage} from "./index-page-runtime.js";
|
|
|
36
36
|
|
|
37
37
|
export {parseDateExpression} from './date-parser/index.js';
|
|
38
38
|
export type {DateExpressionOptions, DateExpressionResult, DateExpressionErrorCode} from './date-parser/index.js';
|
|
39
|
+
|
|
40
|
+
export {FramePage} from "./server/frame-page.js";
|
|
41
|
+
export {NavigationResolver} from "./navigation-resolver.js";
|
|
42
|
+
|
|
43
|
+
export {fileSystemTree, FileSystemLogic, FileSystemController, DirectoryResolver} from "./filesystem.js";
|
|
44
|
+
export {IdeLogic} from "./ide-runtime.js";
|
package/src/index.js
CHANGED
|
@@ -14,7 +14,7 @@ export {DomHandler} from './handlers/dom-handler.js';
|
|
|
14
14
|
export {UtilitiesHandler} from './handlers/utilities-handler.js';
|
|
15
15
|
export {PageBootstrap} from './bootstrap.js';
|
|
16
16
|
// A page module served for its Logic imports @gramlot/gramlot/page; the bootstrap import map points it here.
|
|
17
|
-
export {Exposed, Page} from './server/page.js';
|
|
17
|
+
export {Exposed, Page, FramePage, codeMirrorWithOptions} from './server/page.js';
|
|
18
18
|
export {GramlotBuilder} from './builder/gramlot-builder.js';
|
|
19
19
|
export {GramlotRenderer} from './renderer/gramlot-renderer.js';
|
|
20
20
|
export {GramlotHtmlRenderer} from './renderer/gramlot-html-renderer.js';
|
|
@@ -31,5 +31,9 @@ export {InOut} from './inout.js';
|
|
|
31
31
|
|
|
32
32
|
export {IndexPage} from './server/index-page.js';
|
|
33
33
|
export {IndexLogic, mountIndexPage} from './index-page-runtime.js';
|
|
34
|
+
export {NavigationResolver} from './navigation-resolver.js';
|
|
34
35
|
|
|
35
36
|
export {parseDateExpression} from './date-parser/index.js';
|
|
37
|
+
|
|
38
|
+
export {fileSystemTree, FileSystemLogic, FileSystemController, DirectoryResolver} from "./filesystem.js";
|
|
39
|
+
export {IdeLogic} from "./ide-runtime.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import {BagResolver} from '@genrojs/bag';
|
|
2
|
+
import type {Gramlot} from './gramlot.js';
|
|
3
|
+
export class NavigationResolver extends BagResolver {
|
|
4
|
+
constructor(options: {gramlot: Gramlot; method: string; directory: string; onError: (error: Error) => void});
|
|
5
|
+
abort(): void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* @ts-self-types="./navigation-resolver.d.ts" */
|
|
2
|
+
import {RemoteResolver} from './binding/remote-resolver.js';
|
|
3
|
+
import {Bag} from '@genrojs/bag';
|
|
4
|
+
|
|
5
|
+
/** One directory per request/cache; children remain unresolved until read. */
|
|
6
|
+
export class NavigationResolver extends RemoteResolver {
|
|
7
|
+
static internalParams = new Set([...RemoteResolver.internalParams, 'gramlot', 'method', 'params', 'onError']);
|
|
8
|
+
#closed = false;
|
|
9
|
+
#controller = null;
|
|
10
|
+
constructor({gramlot, method, directory, onError}) {
|
|
11
|
+
super({cacheTime: -1, onError});
|
|
12
|
+
this.gramlot = gramlot;
|
|
13
|
+
this.method = method;
|
|
14
|
+
this.params = {directory};
|
|
15
|
+
this.children = new Set();
|
|
16
|
+
}
|
|
17
|
+
get closed() { return this.#closed; }
|
|
18
|
+
startLoad(perform) {
|
|
19
|
+
if (this.loading) return this.loading;
|
|
20
|
+
const controller = new AbortController();
|
|
21
|
+
this.#controller = controller;
|
|
22
|
+
return perform({controller, method: this.method, params: this.params, ignored: false});
|
|
23
|
+
}
|
|
24
|
+
async loadAsync({controller, method, params}) {
|
|
25
|
+
const {signal} = controller;
|
|
26
|
+
let abort;
|
|
27
|
+
const cancelled = new Promise((_, reject) => {
|
|
28
|
+
abort = () => reject(signal.reason);
|
|
29
|
+
signal.addEventListener('abort', abort, {once: true});
|
|
30
|
+
});
|
|
31
|
+
try {
|
|
32
|
+
const value = await Promise.race([this.gramlot.rpc.call('data', method, params, {signal}), cancelled]);
|
|
33
|
+
if (signal.aborted) throw signal.reason;
|
|
34
|
+
return value;
|
|
35
|
+
} finally {
|
|
36
|
+
signal.removeEventListener('abort', abort);
|
|
37
|
+
if (this.#controller === controller) this.#controller = null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
prepareValue(bag) {
|
|
41
|
+
if (!(bag instanceof Bag)) throw new TypeError('Directory navigation must return a Bag');
|
|
42
|
+
for (const child of this.children) child.abort();
|
|
43
|
+
this.children.clear();
|
|
44
|
+
for (const node of bag.getNodes()) {
|
|
45
|
+
if (node.attr.directory !== undefined) {
|
|
46
|
+
const resolver = new NavigationResolver({gramlot: this.gramlot, method: this.method,
|
|
47
|
+
directory: node.attr.directory, onError: this.onError});
|
|
48
|
+
this.children.add(resolver);
|
|
49
|
+
bag.setResolver(node.label, resolver);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return bag;
|
|
53
|
+
}
|
|
54
|
+
abort() {
|
|
55
|
+
this.#closed = true;
|
|
56
|
+
this.#controller?.abort();
|
|
57
|
+
for (const child of this.children) child.abort();
|
|
58
|
+
this.children.clear();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -11,7 +11,8 @@ export const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
|
11
11
|
const BINDING_ATTRIBUTES = new Set([
|
|
12
12
|
'default', 'default_value', 'live', 'group', 'visible', 'action', 'fire', 'ask', '_ask', '_ask_if', '_ask_title', '_ask_onCancel',
|
|
13
13
|
'if', 'else', '_init', '_onStart', '_onBuilt', '_delay', '_timing', '_userChanges',
|
|
14
|
-
'remote', '_cachedRemote', '_onRemote', '_onCalling', 'onClose',
|
|
14
|
+
'remote', '_cachedRemote', '_onRemote', '_onCalling', 'onClose', 'onDrag', 'onDrop', 'dropTargetCb', 'onDragEnd',
|
|
15
|
+
'dropTarget', 'dropTypes', 'dragTags', 'dropTags', 'effectAllowed', 'dropEffect', 'dragClass',
|
|
15
16
|
]);
|
|
16
17
|
const BINDING_ATTRIBUTE_PREFIXES = ['default_', 'attr_', 'fire_', 'connect_on', 'subscribe_', 'selfsubscribe_', 'formsubscribe_', 'remote_'];
|
|
17
18
|
|