@gramlot/gramlot 0.3.16 → 0.3.17
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/__init__.py +1 -1
- package/dist/components/editors/assets/collection.js +16162 -11689
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/grammar.json +3 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +134 -179
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +19 -0
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +4643 -3481
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +509 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +306 -94
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +16 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +2 -2
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/gramlot.js +2124 -506
- package/dist/gramlot.min.js +95 -40
- package/dist/runtime-notices.json +4 -0
- package/package.json +12 -8
- package/src/binding/device-resolver.js +27 -0
- package/src/binding/error-notifications.js +84 -0
- package/src/binding/remote-resolver.d.ts +18 -0
- package/src/binding/remote.js +11 -4
- package/src/binding/runtime.js +6 -2
- package/src/bootstrap.js +4 -4
- package/src/components/buttons.js +10 -3
- package/src/components/code-mirror-engine.js +14 -4
- package/src/components/code-mirror.js +2 -3
- package/src/components/container.js +1 -1
- package/src/components/date-calendar.js +1 -1
- package/src/components/formlet-labels.js +5 -4
- package/src/components/html-document.js +4 -2
- package/src/components/html-editor.js +2 -2
- package/src/components/jodit-engine.js +72 -11
- package/src/components/labelbox.js +19 -63
- package/src/components/layout.js +31 -19
- package/src/components/markdown-document.js +1 -1
- package/src/components/markdown-editor.js +2 -2
- package/src/components/menus.js +7 -6
- package/src/components/prose-mirror-engine.js +14 -1
- package/src/components/registry.js +2 -0
- package/src/components/selected-container.js +107 -14
- package/src/components/toolbar-overflow.js +9 -8
- package/src/components/transform-pane.js +140 -0
- package/src/components/tray-geometry.js +87 -0
- package/src/components/tray-pane.js +435 -0
- package/src/components/tray-settings.js +62 -0
- package/src/components/tree.js +115 -21
- package/src/components/typed-editor.js +1 -1
- package/src/components/typst-client.js +14 -13
- package/src/components/validation.js +1 -1
- package/src/components/window-surface.js +281 -0
- package/src/components/windows.js +32 -261
- package/src/device-frames.js +195 -0
- package/src/filesystem.d.ts +12 -5
- package/src/filesystem.js +8 -8
- package/src/gramlot.d.ts +3 -1
- package/src/gramlot.js +11 -4
- package/src/handlers/device-handler.d.ts +75 -0
- package/src/handlers/device-handler.js +1037 -0
- package/src/handlers/dom-handler.d.ts +2 -0
- package/src/handlers/dom-handler.js +9 -0
- package/src/handlers/rpc-handler.d.ts +2 -2
- package/src/http-transport.d.ts +3 -3
- package/src/http-transport.js +17 -11
- package/src/ide-documents.js +6 -4
- package/src/ide-runtime.d.ts +14 -3
- package/src/ide-runtime.js +123 -94
- package/src/index-page-runtime.d.ts +2 -2
- package/src/index-page-runtime.js +91 -43
- package/src/index-page-styles.js +1 -1
- package/src/index.d.ts +7 -2
- package/src/index.js +5 -1
- package/src/inout.d.ts +1 -1
- package/src/inout.js +5 -1
- package/src/mobile-environment.d.ts +6 -0
- package/src/mobile-environment.js +52 -0
- package/src/navigation-resolver.d.ts +14 -2
- package/src/renderer/attributes.js +5 -2
- package/src/renderer/drag-drop.js +5 -4
- package/src/renderer/gramlot-renderer.d.ts +13 -2
- package/src/renderer/gramlot-renderer.js +49 -13
- package/src/server/index-page.js +4 -4
- package/src/view/controls.js +48 -23
- package/src/view/html.js +85 -4
- package/src/view/labelbox.js +95 -0
- package/themes/gramlot-base/theme.css +4 -0
- package/themes/mela/theme.css +62 -15
- package/src/date-parser/civil.js +0 -61
- package/src/date-parser/index.d.ts +0 -18
- package/src/date-parser/index.js +0 -196
- package/src/date-parser/locales.js +0 -257
|
@@ -1,274 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
/** Shared window chrome. Source owns the frame; native dialog owns modality. */
|
|
1
|
+
/** Source-owned window adapter over the shared window presentation. */
|
|
3
2
|
import {defineComponent} from './registry.js';
|
|
4
3
|
import {projectParameters} from './parameters.js';
|
|
4
|
+
import {labelboxContent} from '../view/labelbox.js';
|
|
5
|
+
import {WindowSurface} from './window-surface.js';
|
|
5
6
|
|
|
6
7
|
function WindowShell(HTMLElement) {
|
|
7
8
|
return class extends HTMLElement {
|
|
8
|
-
#context; #observer; #scheduled = false; #live = false;
|
|
9
|
-
#open = false; #collapsed = false; #maximized = false; #pending = null; #generation = 0;
|
|
10
|
-
#geometry = null; #gesture = null; #previousFocus = null;
|
|
11
|
-
#resize = () => { if (this.#open) this.#fit(); };
|
|
12
9
|
constructor() {
|
|
13
10
|
super();
|
|
14
|
-
const doc = this.ownerDocument;
|
|
15
11
|
const shadow = this.attachShadow({mode:'open'});
|
|
16
|
-
const style =
|
|
17
|
-
style.textContent =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.shell = doc.createElement('dialog'); this.shell.setAttribute('aria-labelledby','title');
|
|
42
|
-
this.titlebar = doc.createElement('header'); this.titlebar.className='titlebar';
|
|
43
|
-
this.heading = doc.createElement('h2'); this.heading.id='title'; this.heading.className='title';
|
|
44
|
-
this.collapseButton = this.#button('Collapse window','−');
|
|
45
|
-
this.maximizeButton = this.#button('Maximize window','□');
|
|
46
|
-
this.closeButton = this.#button('Close window','×');
|
|
47
|
-
this.titlebar.append(this.heading,this.collapseButton,this.maximizeButton,this.closeButton);
|
|
48
|
-
this.body = doc.createElement('div');this.body.className='body';this.body.append(doc.createElement('slot'));
|
|
49
|
-
this.resizeButton = this.#button('Resize window','');this.resizeButton.className='resize';
|
|
50
|
-
const resizeIcon=doc.createElementNS(SVG_NS,'svg');
|
|
51
|
-
resizeIcon.setAttribute('viewBox','0 0 16 16');resizeIcon.setAttribute('aria-hidden','true');resizeIcon.setAttribute('focusable','false');
|
|
52
|
-
const resizePath=doc.createElementNS(SVG_NS,'path');
|
|
53
|
-
resizePath.setAttribute('d','M5 13 13 5M9 13l4-4');resizePath.setAttribute('fill','none');
|
|
54
|
-
resizePath.setAttribute('stroke','currentColor');resizePath.setAttribute('stroke-width','1.25');resizePath.setAttribute('stroke-linecap','round');
|
|
55
|
-
resizeIcon.append(resizePath);this.resizeButton.append(resizeIcon);
|
|
56
|
-
this.status = doc.createElement('div');this.status.className='status';this.status.hidden=true;this.status.setAttribute('role','alert');
|
|
57
|
-
this.shell.append(this.titlebar,this.body,this.status,this.resizeButton);shadow.append(style,this.shell);
|
|
58
|
-
this.closeButton.addEventListener('click',()=>this.requestClose('close'));
|
|
59
|
-
this.collapseButton.addEventListener('click',()=>this.#setCollapsed(!this.#collapsed,true));
|
|
60
|
-
this.maximizeButton.addEventListener('click',()=>this.#setMaximized(!this.#maximized,true));
|
|
61
|
-
this.shell.addEventListener('cancel',event=>{event.preventDefault();this.requestClose('escape');});
|
|
62
|
-
this.shell.addEventListener('keydown',event=>{
|
|
63
|
-
if(!this.modal && event.key==='Escape' && !event.defaultPrevented){event.preventDefault();this.requestClose('escape');}
|
|
64
|
-
});
|
|
65
|
-
this.shell.addEventListener('focusin',()=>this.#raise());
|
|
66
|
-
this.shell.addEventListener('pointerdown',()=>this.#raise());
|
|
67
|
-
for (const [handle,kind] of [[this.titlebar,'move'],[this.resizeButton,'resize']]) {
|
|
68
|
-
handle.addEventListener('pointerdown',event=>this.#startGesture(event,kind));
|
|
69
|
-
handle.addEventListener('pointermove',event=>this.#moveGesture(event));
|
|
70
|
-
handle.addEventListener('pointerup',event=>this.#endGesture(event,true));
|
|
71
|
-
handle.addEventListener('pointercancel',event=>this.#endGesture(event,false));
|
|
72
|
-
handle.addEventListener('lostpointercapture',event=>this.#endGesture(event,false));
|
|
73
|
-
handle.addEventListener('keydown',event=>this.#keyGeometry(event,kind));
|
|
74
|
-
}
|
|
75
|
-
this.#observer=new doc.defaultView.MutationObserver(()=>this.#schedule());
|
|
76
|
-
}
|
|
77
|
-
#button(label,text) { const b=this.ownerDocument.createElement('button');b.type='button';b.textContent=text;b.setAttribute('aria-label',label);b.title=label;return b; }
|
|
78
|
-
get modal() { return this.constructor.gramlotComponent.name==='dialog'; }
|
|
79
|
-
get opened() { return this.#open; }
|
|
80
|
-
setSourceContext(context) { this.#context=context; }
|
|
81
|
-
connectedCallback() {
|
|
82
|
-
this.#live=true;this.#observer.observe(this,{childList:true});
|
|
83
|
-
this.ownerDocument.defaultView.addEventListener('resize',this.#resize);this.#schedule();
|
|
84
|
-
}
|
|
85
|
-
disconnectedCallback() {
|
|
86
|
-
this.#live=false;this.#generation++;this.#pending=null;this.#observer.disconnect();
|
|
87
|
-
this.ownerDocument.defaultView.removeEventListener('resize',this.#resize);this.#cancelGesture();
|
|
88
|
-
if(this.shell.open)this.shell.close();this.#open=false;this.#restoreFocus();
|
|
89
|
-
}
|
|
12
|
+
const style = this.ownerDocument.createElement('style');
|
|
13
|
+
style.textContent = ':host{display:contents;font:inherit;color:var(--gramlot-ink,CanvasText)}';
|
|
14
|
+
const root = this.ownerDocument.createElement('div');
|
|
15
|
+
shadow.append(style, root);
|
|
16
|
+
this.surface = new WindowSurface(this, root, {modal:this.constructor.gramlotComponent.name === 'dialog',
|
|
17
|
+
validateContent:() => {
|
|
18
|
+
if (this.children.length !== 1 || labelboxContent(this.firstElementChild).localName !== 'gramlot-frame-pane') {
|
|
19
|
+
throw new TypeError('A window requires exactly one framePane child');
|
|
20
|
+
}
|
|
21
|
+
}});
|
|
22
|
+
}
|
|
23
|
+
get shell() { return this.surface.shell; }
|
|
24
|
+
get titlebar() { return this.surface.titlebar; }
|
|
25
|
+
get heading() { return this.surface.heading; }
|
|
26
|
+
get body() { return this.surface.body; }
|
|
27
|
+
get status() { return this.surface.status; }
|
|
28
|
+
get closeButton() { return this.surface.closeButton; }
|
|
29
|
+
get collapseButton() { return this.surface.collapseButton; }
|
|
30
|
+
get maximizeButton() { return this.surface.maximizeButton; }
|
|
31
|
+
get resizeButton() { return this.surface.resizeButton; }
|
|
32
|
+
get modal() { return this.surface.modal; }
|
|
33
|
+
get opened() { return this.surface.opened; }
|
|
34
|
+
setSourceContext(context) { this.surface.setSourceContext(context); }
|
|
35
|
+
connectedCallback() { this.surface.connect(); }
|
|
36
|
+
disconnectedCallback() { this.surface.disconnect(); }
|
|
90
37
|
projectAttributes(attrs) {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if(['width','height','left','top','minWidth','minHeight'].some(name=>previous[name]!==this.parameters[name])) {
|
|
95
|
-
this.#cancelGesture();this.#geometry=null;this.#collapsed=false;this.#maximized=false;
|
|
96
|
-
}
|
|
97
|
-
if(previous.open!==this.parameters.open) { this.#generation++;this.#pending=null; }
|
|
98
|
-
if(previous.movable!==this.parameters.movable || previous.resizable!==this.parameters.resizable)this.#cancelGesture();
|
|
99
|
-
}
|
|
100
|
-
this.#schedule();return rest;
|
|
101
|
-
}
|
|
102
|
-
#schedule() {
|
|
103
|
-
if(this.#scheduled)return;this.#scheduled=true;
|
|
104
|
-
queueMicrotask(()=>{this.#scheduled=false;if(this.#live&&this.isConnected&&this.parameters)this.#sync();});
|
|
105
|
-
}
|
|
106
|
-
#sync() {
|
|
107
|
-
if(this.children.length!==1 || this.firstElementChild.localName!=='gramlot-frame-pane')throw new TypeError('A window requires exactly one framePane child');
|
|
108
|
-
const p=this.parameters;
|
|
109
|
-
this.heading.textContent=p.title;this.shell.setAttribute('aria-label',p.title);
|
|
110
|
-
this.closeButton.hidden=!p.closable;this.closeButton.disabled=Boolean(this.#pending);
|
|
111
|
-
this.collapseButton.hidden=!p.collapsible;this.maximizeButton.hidden=!p.maximizable;
|
|
112
|
-
if(!p.open) { this.#close(false);return; }
|
|
113
|
-
if(!this.#open) {
|
|
114
|
-
this.#previousFocus=this.#activeElement();
|
|
115
|
-
this.#collapsed=false;this.#maximized=false;this.body.hidden=false;this.shell.removeAttribute('data-collapsed');
|
|
116
|
-
if(this.modal)this.shell.showModal();else this.shell.show();
|
|
117
|
-
this.#open=true;this.#applySize();this.#fit();this.#raise();
|
|
118
|
-
this.#context.publish('opened',{});
|
|
119
|
-
} else if(!this.#geometry) { this.#applySize();this.#fit(); }
|
|
120
|
-
this.#setMaximized(p.maximizable&&p.maximized,false);
|
|
121
|
-
this.#setCollapsed(p.collapsible&&p.collapsed,false);
|
|
122
|
-
if(!p.maximizable && p.maximized)this.#context.writeParameter('maximized',false);
|
|
123
|
-
if(!p.collapsible && p.collapsed)this.#context.writeParameter('collapsed',false);
|
|
124
|
-
}
|
|
125
|
-
#activeElement() { let active=this.ownerDocument.activeElement;while(active?.shadowRoot?.activeElement)active=active.shadowRoot.activeElement;return active; }
|
|
126
|
-
#restoreFocus() { const previous=this.#previousFocus;this.#previousFocus=null;if(previous?.isConnected)previous.focus({preventScroll:true}); }
|
|
127
|
-
#applySize() {
|
|
128
|
-
const p=this.parameters,s=this.shell.style;
|
|
129
|
-
this.shell.removeAttribute('data-maximized');
|
|
130
|
-
s.width=p.width??'var(--gramlot-window-width,36rem)';s.height=p.height??'var(--gramlot-window-height,24rem)';
|
|
131
|
-
s.minWidth=p.minWidth??'min(220px, calc(100vw - 16px))';s.minHeight=p.minHeight??'min(140px, calc(100dvh - 16px))';
|
|
132
|
-
s.left=p.left??'0px';s.top=p.top??'0px';
|
|
133
|
-
if(this.#geometry){this.#paint(this.#geometry);return;}
|
|
134
|
-
if(!this.#geometry) {
|
|
135
|
-
const r=this.shell.getBoundingClientRect(),w=this.ownerDocument.defaultView;
|
|
136
|
-
if(p.left==null)s.left=`${Math.max(8,(w.document.documentElement.clientWidth-r.width)/2)}px`;
|
|
137
|
-
if(p.top==null)s.top=`${Math.max(8,(w.document.documentElement.clientHeight-r.height)/2)}px`;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
#fit() {
|
|
141
|
-
if(this.#maximized){this.#renderGeometry();return;}
|
|
142
|
-
const r=this.shell.getBoundingClientRect(),w=this.ownerDocument.defaultView;
|
|
143
|
-
const width=Math.min(r.width,Math.max(0,w.document.documentElement.clientWidth-16)),height=Math.min(r.height,Math.max(0,w.document.documentElement.clientHeight-16));
|
|
144
|
-
const rect={left:Math.max(8,Math.min(r.left,w.document.documentElement.clientWidth-width-8)),top:Math.max(8,Math.min(r.top,w.document.documentElement.clientHeight-height-8)),width,height};
|
|
145
|
-
this.#paint(rect);if(!this.#collapsed)this.#geometry=rect;
|
|
146
|
-
else this.#geometry={...this.#geometry,left:rect.left,top:rect.top,width:rect.width};
|
|
147
|
-
}
|
|
148
|
-
#paint(rect) { for(const key of ['left','top','width','height'])this.shell.style[key]=`${rect[key]}px`; }
|
|
149
|
-
#raise() {
|
|
150
|
-
if(this.modal||!this.#open)return;
|
|
151
|
-
// Reserve the page's low stacking levels for layout chrome (splitters/drawers).
|
|
152
|
-
// Modal dialogs and menu popovers remain above these nonmodal windows in the top layer.
|
|
153
|
-
const base=100;
|
|
154
|
-
const peers=[...this.getRootNode().querySelectorAll('gramlot-floating-pane')].filter(n=>n.opened&&n!==this);
|
|
155
|
-
peers.sort((a,b)=>Number(a.shell.style.zIndex)-Number(b.shell.style.zIndex)).forEach((n,i)=>n.shell.style.zIndex=String(base+i));
|
|
156
|
-
this.shell.style.zIndex=String(base+peers.length);
|
|
157
|
-
}
|
|
158
|
-
// #geometry always holds the normal expanded rectangle, never viewport size.
|
|
159
|
-
#renderGeometry() {
|
|
160
|
-
const viewport=this.ownerDocument.documentElement;
|
|
161
|
-
const rect=this.#maximized?{left:0,top:0,width:viewport.clientWidth,height:viewport.clientHeight}:{...this.#geometry};
|
|
162
|
-
if(this.#collapsed)rect.height=this.titlebar.getBoundingClientRect().height+2;
|
|
163
|
-
this.shell.toggleAttribute('data-maximized',this.#maximized);
|
|
164
|
-
this.shell.style.minWidth=this.#maximized?'0':this.parameters.minWidth??'min(220px, calc(100vw - 16px))';
|
|
165
|
-
this.shell.style.minHeight=this.#collapsed||this.#maximized?'0':this.parameters.minHeight??'min(140px, calc(100dvh - 16px))';
|
|
166
|
-
this.#paint(rect);
|
|
167
|
-
const movable=this.parameters.movable&&!this.#maximized;
|
|
168
|
-
this.titlebar.toggleAttribute('data-movable',movable);this.titlebar.tabIndex=movable?0:-1;
|
|
169
|
-
this.titlebar.setAttribute('aria-label',movable?'Move window: use arrow keys':this.parameters.title);
|
|
170
|
-
this.resizeButton.hidden=this.#collapsed||this.#maximized||!this.parameters.resizable;
|
|
171
|
-
}
|
|
172
|
-
#setMaximized(value,write) {
|
|
173
|
-
if(!this.#open)return;
|
|
174
|
-
if(value!==this.#maximized){this.#cancelGesture();this.#maximized=value;}
|
|
175
|
-
this.#renderGeometry();
|
|
176
|
-
if(!value)this.#fit();
|
|
177
|
-
this.maximizeButton.textContent=value?'❐':'□';
|
|
178
|
-
this.maximizeButton.setAttribute('aria-label',value?'Restore size':'Maximize window');
|
|
179
|
-
this.maximizeButton.title=value?'Restore size':'Maximize window';
|
|
180
|
-
this.maximizeButton.setAttribute('aria-pressed',String(value));
|
|
181
|
-
if(write){this.parameters.maximized=value;this.#context.writeParameter('maximized',value);}
|
|
182
|
-
}
|
|
183
|
-
#setCollapsed(value,write) {
|
|
184
|
-
if(!this.#open)return;
|
|
185
|
-
if(value!==this.#collapsed) {
|
|
186
|
-
this.#cancelGesture();
|
|
187
|
-
if(value && this.body.contains(this.#activeElement()))this.collapseButton.focus();
|
|
188
|
-
this.#collapsed=value;
|
|
189
|
-
}
|
|
190
|
-
this.body.hidden=value;
|
|
191
|
-
this.shell.toggleAttribute('data-collapsed',value);this.collapseButton.textContent=value?'+':'−';
|
|
192
|
-
this.collapseButton.setAttribute('aria-label',value?'Expand window':'Collapse window');
|
|
193
|
-
this.collapseButton.title=value?'Expand window':'Collapse window';
|
|
194
|
-
this.collapseButton.setAttribute('aria-expanded',String(!value));
|
|
195
|
-
this.#renderGeometry();this.#fit();
|
|
196
|
-
if(write){this.parameters.collapsed=value;this.#context.writeParameter('collapsed',value);}
|
|
197
|
-
}
|
|
198
|
-
async requestClose(reason='application') {
|
|
199
|
-
if(!this.#open || (!this.parameters.closable&&reason!=='application'))return false;
|
|
200
|
-
if(this.#pending)return this.#pending;
|
|
201
|
-
const generation=this.#generation;
|
|
202
|
-
this.status.hidden=true;
|
|
203
|
-
const run=async()=>{
|
|
204
|
-
try {
|
|
205
|
-
const accepted=this.parameters.beforeClose?await this.#context.callLogic(this.parameters.beforeClose,{reason}):true;
|
|
206
|
-
if(typeof accepted!=='boolean')throw new TypeError('beforeClose must return a boolean');
|
|
207
|
-
if(!this.#live||generation!==this.#generation||!this.#open)return false;
|
|
208
|
-
if(accepted)this.#close(true);return accepted;
|
|
209
|
-
} catch(error) {
|
|
210
|
-
if(this.#live&&generation===this.#generation){this.status.textContent='Unable to close: '+error.message;this.status.hidden=false;this.ownerDocument.defaultView.console.error(error);}
|
|
211
|
-
return false;
|
|
212
|
-
} finally {if(generation===this.#generation){this.#pending=null;this.closeButton.disabled=false;this.shell.removeAttribute('aria-busy');}}
|
|
213
|
-
};
|
|
214
|
-
this.closeButton.disabled=true;this.shell.setAttribute('aria-busy','true');
|
|
215
|
-
// Start after assigning the pending request, also for a synchronous guard.
|
|
216
|
-
this.#pending=Promise.resolve().then(run);return this.#pending;
|
|
217
|
-
}
|
|
218
|
-
#close(write) {
|
|
219
|
-
if(!this.#open)return;
|
|
220
|
-
this.#generation++;this.#pending=null;this.#cancelGesture();this.#open=false;
|
|
221
|
-
if(this.shell.open)this.shell.close();this.shell.removeAttribute('aria-busy');this.closeButton.disabled=false;
|
|
222
|
-
this.#restoreFocus();
|
|
223
|
-
if(write){this.parameters.open=false;this.#context.writeParameter('open',false);}
|
|
224
|
-
this.#context.publish('closed',{});
|
|
225
|
-
}
|
|
226
|
-
#startGesture(event,kind) {
|
|
227
|
-
if(event.button!==0||!this.#open||this.#maximized||kind==='move'&&!this.parameters.movable||kind==='resize'&&(!this.parameters.resizable||this.#collapsed))return;
|
|
228
|
-
if(kind==='move'&&event.target.closest('button'))return;
|
|
229
|
-
event.preventDefault();this.#cancelGesture();
|
|
230
|
-
const r=this.shell.getBoundingClientRect();
|
|
231
|
-
this.#gesture={kind,id:event.pointerId,handle:event.currentTarget,x:event.clientX,y:event.clientY,rect:{left:r.left,top:r.top,width:r.width,height:r.height}};
|
|
232
|
-
event.currentTarget.setPointerCapture(event.pointerId);event.currentTarget.focus();
|
|
233
|
-
}
|
|
234
|
-
#moveGesture(event) {
|
|
235
|
-
const g=this.#gesture;if(!g||g.id!==event.pointerId)return;
|
|
236
|
-
this.#adjust(g.rect,event.clientX-g.x,event.clientY-g.y,g.kind);
|
|
237
|
-
}
|
|
238
|
-
#adjust(start,dx,dy,kind) {
|
|
239
|
-
const rect={...start},w=this.ownerDocument.defaultView;
|
|
240
|
-
if(kind==='move'){rect.left+=dx;rect.top+=dy;}
|
|
241
|
-
else {
|
|
242
|
-
const style=w.getComputedStyle(this.shell);
|
|
243
|
-
rect.width=Math.max(parseFloat(style.minWidth)||0,rect.width+dx);
|
|
244
|
-
rect.height=Math.max(parseFloat(style.minHeight)||0,rect.height+dy);
|
|
245
|
-
}
|
|
246
|
-
rect.width=Math.min(rect.width,Math.max(0,w.document.documentElement.clientWidth-16));rect.height=Math.min(rect.height,Math.max(0,w.document.documentElement.clientHeight-16));
|
|
247
|
-
rect.left=Math.max(8,Math.min(rect.left,w.document.documentElement.clientWidth-rect.width-8));rect.top=Math.max(8,Math.min(rect.top,w.document.documentElement.clientHeight-rect.height-8));
|
|
248
|
-
this.#paint(rect);
|
|
249
|
-
if(this.#collapsed){this.#geometry={...this.#geometry,left:rect.left,top:rect.top,width:rect.width};}
|
|
250
|
-
else this.#geometry=rect;
|
|
251
|
-
}
|
|
252
|
-
#endGesture(event,commit) {
|
|
253
|
-
const g=this.#gesture;if(!g||g.id!==event.pointerId)return;
|
|
254
|
-
this.#gesture=null;if(g.handle.hasPointerCapture(g.id))g.handle.releasePointerCapture(g.id);
|
|
255
|
-
if(commit)this.#commitGeometry(g.kind);else {this.#paint(g.rect);if(!this.#collapsed)this.#geometry=g.rect;else this.#geometry={...this.#geometry,left:g.rect.left,top:g.rect.top,width:g.rect.width};}
|
|
256
|
-
}
|
|
257
|
-
#cancelGesture() { if(this.#gesture)this.#endGesture({pointerId:this.#gesture.id},false); }
|
|
258
|
-
#commitGeometry(kind) {
|
|
259
|
-
const r=this.shell.getBoundingClientRect();
|
|
260
|
-
for(const key of kind==='move'?['left','top']:['width','height']) {
|
|
261
|
-
const value=`${r[key]}px`;this.#context.writeParameter(key,value);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
#keyGeometry(event,kind) {
|
|
265
|
-
if(event.target!==event.currentTarget||!['ArrowLeft','ArrowRight','ArrowUp','ArrowDown'].includes(event.key))return;
|
|
266
|
-
if(this.#maximized||kind==='move'&&!this.parameters.movable||kind==='resize'&&(!this.parameters.resizable||this.#collapsed))return;
|
|
267
|
-
event.preventDefault();event.stopPropagation();
|
|
268
|
-
const r=this.shell.getBoundingClientRect(),step=event.shiftKey?1:10;
|
|
269
|
-
this.#adjust({left:r.left,top:r.top,width:r.width,height:r.height},event.key==='ArrowLeft'?-step:event.key==='ArrowRight'?step:0,event.key==='ArrowUp'?-step:event.key==='ArrowDown'?step:0,kind);
|
|
270
|
-
this.#commitGeometry(kind);
|
|
38
|
+
const rest = projectParameters(this, attrs);
|
|
39
|
+
this.surface.configure(this.parameters);
|
|
40
|
+
return rest;
|
|
271
41
|
}
|
|
42
|
+
requestClose(reason) { return this.surface.requestClose(reason); }
|
|
272
43
|
};
|
|
273
44
|
}
|
|
274
45
|
const bool=(value,binding='read')=>({dtype:'B',default:value,binding});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/** Backend-neutral DeviceProvider delegation to an explicitly trusted parent. */
|
|
2
|
+
const TYPE = 'gramlot:device';
|
|
3
|
+
const methods = {
|
|
4
|
+
openDatabase:['database',1,'database',true],
|
|
5
|
+
startOrientationEvents:['orientation',0,'stream',true],
|
|
6
|
+
startGyroscopeUpdates:['gyroscope',0,'stream',true], startAccelerometerUpdates:['accelerometer',0,'stream',true],
|
|
7
|
+
readAppInfo:['appinfo',0,'value',false], readLocation:['location',0,'value',false],
|
|
8
|
+
copyText:['clipboard',1,'value',true], pasteText:['clipboard',0,'value',true],
|
|
9
|
+
takePhoto:['camera',0,'value',true], choosePhoto:['camera',0,'value',true],
|
|
10
|
+
scanBarcode:['barcode',0,'value',true], verifyBiometrics:['biometrics',0,'value',true],
|
|
11
|
+
impact:['haptics',1,'value',true], vibrate:['haptics',1,'value',true],
|
|
12
|
+
registerPush:['push',0,'value',true], scheduleNotification:['notifications',1,'value',true],
|
|
13
|
+
startNetworkEvents:['network',0,'stream',true], startLifecycleEvents:['lifecycle',0,'stream',true],
|
|
14
|
+
startPushEvents:['push',0,'stream',true], startNotificationEvents:['notifications',0,'stream',true],
|
|
15
|
+
startLocationUpdates:['location',0,'stream',true], startAudioRecording:['audio',0,'audio',true]
|
|
16
|
+
};
|
|
17
|
+
const modal = new Set(['takePhoto','choosePhoto','scanBarcode','verifyBiometrics','pasteText','readLocation','registerPush','scheduleNotification']);
|
|
18
|
+
const failure = (message, code='FAILED') => Object.assign(new Error(message), {code});
|
|
19
|
+
const wire = value => value instanceof Error ? {deviceError:true,message:value.message,code:value.code ?? 'FAILED'} :
|
|
20
|
+
Array.isArray(value) ? value.map(wire) : value && typeof value==='object' ? Object.fromEntries(Object.entries(value).map(([k,v])=>[k,wire(v)])) : value;
|
|
21
|
+
const unwire = value => value?.deviceError === true ? failure(value.message,value.code) :
|
|
22
|
+
Array.isArray(value) ? value.map(unwire) : value && typeof value==='object' ? Object.fromEntries(Object.entries(value).map(([k,v])=>[k,unwire(v)])) : value;
|
|
23
|
+
|
|
24
|
+
/** One host, explicitly authorized Source-owned direct children, one provider per connection. */
|
|
25
|
+
export class DeviceFrameHost {
|
|
26
|
+
constructor({window, origins, resolveFrame, createProvider}) {
|
|
27
|
+
this.window=window; this.origins=new Set(origins); this.resolveFrame=resolveFrame;
|
|
28
|
+
this.createProvider=createProvider; this.connections=new Set(); this.modal=null; this.audio=null;
|
|
29
|
+
this.receive=event=>this.connect(event);
|
|
30
|
+
window.addEventListener('message',this.receive);
|
|
31
|
+
this.load=event=>{for(const c of this.connections)if(c.frame===event.target)void this.close(c);};
|
|
32
|
+
window.document.addEventListener('load',this.load,true);
|
|
33
|
+
this.observer=new window.MutationObserver(()=>this.prune());
|
|
34
|
+
this.observer.observe(window.document.documentElement,{subtree:true,childList:true,attributes:true,attributeFilter:['src','srcdoc','sandbox']});
|
|
35
|
+
this.hide=()=>this.dispose(); window.addEventListener('pagehide',this.hide,{once:true});
|
|
36
|
+
}
|
|
37
|
+
valid(connection) {
|
|
38
|
+
const frame=this.resolveFrame(connection.source);
|
|
39
|
+
return frame===connection.frame && frame.isConnected && frame.getAttribute('src')===connection.src &&
|
|
40
|
+
!frame.hasAttribute('srcdoc') && !frame.hasAttribute('sandbox') &&
|
|
41
|
+
new URL(frame.getAttribute('src'),this.window.document.baseURI).origin===connection.origin;
|
|
42
|
+
}
|
|
43
|
+
connect(event) {
|
|
44
|
+
if(event.data?.type!==TYPE || event.data.kind!=='connect' || event.ports.length!==1 || !this.origins.has(event.origin))return;
|
|
45
|
+
const frame=this.resolveFrame(event.source);
|
|
46
|
+
if(!frame)return;
|
|
47
|
+
const c={source:event.source,frame,src:frame.getAttribute('src'),origin:event.origin,port:event.ports[0],
|
|
48
|
+
provider:this.createProvider(),requests:new Map(),resources:new Map(),closed:false,sequence:0};
|
|
49
|
+
if(!this.valid(c)){c.port.close();return;}
|
|
50
|
+
for(const old of this.connections)if(old.source===c.source)this.close(old);
|
|
51
|
+
this.connections.add(c);
|
|
52
|
+
c.port.onmessage=e=>{void this.request(c,e.data);}; c.port.start();
|
|
53
|
+
c.port.postMessage({kind:'ready',capabilities:c.provider.capabilities.filter(name=>name!=='links'&&name!=='shortcuts')});
|
|
54
|
+
}
|
|
55
|
+
send(c,message){if(!c.closed)c.port.postMessage(message);}
|
|
56
|
+
prune(){for(const c of this.connections)if(!this.valid(c))this.close(c);}
|
|
57
|
+
async close(c) {
|
|
58
|
+
if(c.closed)return;c.closed=true;this.connections.delete(c);
|
|
59
|
+
c.port.postMessage({kind:'closed'});c.port.close();
|
|
60
|
+
for(const controller of c.requests.values())controller.abort();
|
|
61
|
+
const resources=[...c.resources.values()];c.resources.clear();
|
|
62
|
+
await Promise.allSettled(resources.map(resource=>resource.kind==='database'?resource.value.close():resource.kind==='audio'?resource.value.dispose():resource.value()));
|
|
63
|
+
if(this.audio?.connection===c && !c.requests.has(this.audio.id))this.audio=null;
|
|
64
|
+
}
|
|
65
|
+
dispose(){this.window.removeEventListener('message',this.receive);this.window.removeEventListener('pagehide',this.hide);this.observer.disconnect();this.window.document.removeEventListener('load',this.load,true);for(const c of this.connections)void this.close(c);}
|
|
66
|
+
async request(c,message) {
|
|
67
|
+
if(c.closed)return;
|
|
68
|
+
if(!this.valid(c)){void this.close(c);return;}
|
|
69
|
+
if(message?.kind==='close'){void this.close(c);return;}
|
|
70
|
+
if(message?.kind==='cancel'){c.requests.get(message.id)?.abort();return;}
|
|
71
|
+
const {id,method,args,resource:resourceId}=message ?? {};
|
|
72
|
+
if(message?.kind!=='call'||!Number.isSafeInteger(id)||id<1||!Array.isArray(args)||id<=c.sequence)return;
|
|
73
|
+
c.sequence=id;
|
|
74
|
+
const controller=new AbortController(); c.requests.set(id,controller);
|
|
75
|
+
let locked=false;
|
|
76
|
+
try {
|
|
77
|
+
let result, kind='value';
|
|
78
|
+
if(resourceId!==undefined) {
|
|
79
|
+
const resource=c.resources.get(resourceId);
|
|
80
|
+
if(!resource)throw failure('Unknown device resource');
|
|
81
|
+
if(resource.kind==='database') {
|
|
82
|
+
if(method==='close' && args.length===0) { await resource.value.close(); c.resources.delete(resourceId); }
|
|
83
|
+
else if(['query','execute'].includes(method) && args.length===2) result=await resource.value[method](...args);
|
|
84
|
+
else throw failure('Invalid database resource operation');
|
|
85
|
+
} else {
|
|
86
|
+
if(args.length || !['close','stop','share','dispose'].includes(method))throw failure('Unknown device resource');
|
|
87
|
+
if(resource.kind==='stream' && method==='close'){c.resources.delete(resourceId);await resource.value();}
|
|
88
|
+
else if(resource.kind==='audio' && ['stop','share','dispose'].includes(method)) {
|
|
89
|
+
if(resource.busy)throw failure('Audio operation already pending');
|
|
90
|
+
resource.busy=true;
|
|
91
|
+
try {result=method==='share'?await resource.value.share(controller.signal):await resource.value[method]();}
|
|
92
|
+
finally {resource.busy=false;}
|
|
93
|
+
if(method==='dispose'){c.resources.delete(resourceId);if(this.audio?.connection===c)this.audio=null;}
|
|
94
|
+
}else throw failure('Invalid device resource operation');
|
|
95
|
+
}
|
|
96
|
+
}else{
|
|
97
|
+
if(!Object.hasOwn(methods,method))throw failure('Unknown device method');
|
|
98
|
+
const [capability,count,type,signal]=methods[method];kind=type;
|
|
99
|
+
if(!c.provider.capabilities.includes(capability))throw failure('Device capability unavailable','UNAVAILABLE');
|
|
100
|
+
if(args.length!==count)throw failure('Invalid device arguments');
|
|
101
|
+
if(modal.has(method)){
|
|
102
|
+
if(this.modal || this.audio)throw failure('Another frame is using the device');
|
|
103
|
+
this.modal={connection:c,id};locked=true;
|
|
104
|
+
}
|
|
105
|
+
if(type==='audio'){
|
|
106
|
+
if(this.audio || this.modal)throw failure('Another frame is using the microphone');
|
|
107
|
+
this.audio={connection:c,id};
|
|
108
|
+
}
|
|
109
|
+
const callArgs=[...args];
|
|
110
|
+
if(type==='stream'||type==='audio')callArgs.push((...values)=>{if(!controller.signal.aborted&&this.valid(c))this.send(c,{kind:'event',id,args:wire(values)});});
|
|
111
|
+
if(signal)callArgs.push(controller.signal);
|
|
112
|
+
result=await c.provider[method](...callArgs);
|
|
113
|
+
if(type!=='value') {
|
|
114
|
+
if(c.closed||controller.signal.aborted){await(type==='database'?result.close():type==='audio'?result.dispose():result());if(type==='audio' && this.audio?.connection===c && this.audio.id===id)this.audio=null;return;}
|
|
115
|
+
c.resources.set(id,{kind:type,value:result,busy:false});result={resource:id};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if(!controller.signal.aborted)this.send(c,{kind:'result',id,value:wire(result)});
|
|
119
|
+
}catch(error){
|
|
120
|
+
if(method==='startAudioRecording' && this.audio?.connection===c && this.audio.id===id)this.audio=null;
|
|
121
|
+
this.send(c,{kind:'error',id,error:wire(error)});
|
|
122
|
+
}finally{
|
|
123
|
+
c.requests.delete(id);
|
|
124
|
+
if(locked&&this.modal?.connection===c&&this.modal.id===id)this.modal=null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Same provider contract inside an iframe; application Data is unchanged. */
|
|
130
|
+
export class FrameDeviceProvider {
|
|
131
|
+
static async connect({window, parentOrigin, timeout=7000}) {
|
|
132
|
+
if(window.parent===window || new URL(parentOrigin).origin!==parentOrigin || parentOrigin==='null')throw new TypeError('An explicit parent origin is required');
|
|
133
|
+
if(window.document.readyState!=='complete')await new Promise(resolve=>window.addEventListener('load',resolve,{once:true}));
|
|
134
|
+
await new Promise(resolve=>setTimeout(resolve,0));
|
|
135
|
+
return new Promise((resolve,reject)=>{
|
|
136
|
+
const channel=new window.MessageChannel();
|
|
137
|
+
const timer=setTimeout(()=>{channel.port1.close();reject(failure('Device host did not connect','UNAVAILABLE'));},timeout);
|
|
138
|
+
channel.port1.onmessage=event=>{
|
|
139
|
+
if(event.data?.kind!=='ready')return;
|
|
140
|
+
clearTimeout(timer);
|
|
141
|
+
resolve(new FrameDeviceProvider(window,channel.port1,event.data.capabilities));
|
|
142
|
+
};
|
|
143
|
+
channel.port1.start();
|
|
144
|
+
window.parent.postMessage({type:TYPE,kind:'connect'},parentOrigin,[channel.port2]);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
constructor(window,port,capabilities) {
|
|
148
|
+
this.window=window;this.port=port;this.capabilities=Object.freeze([...capabilities]);
|
|
149
|
+
this.pending=new Map();this.events=new Map();this.sequence=0;this.closed=false;
|
|
150
|
+
port.onmessage=event=>this.receive(event.data);
|
|
151
|
+
this.hide=()=>this.dispose();window.addEventListener('pagehide',this.hide,{once:true});
|
|
152
|
+
}
|
|
153
|
+
receive(message) {
|
|
154
|
+
if(message.kind==='closed'){this.dispose();return;}
|
|
155
|
+
if(message.kind==='event'){this.events.get(message.id)?.(...unwire(message.args));return;}
|
|
156
|
+
const pending=this.pending.get(message.id);if(!pending)return;
|
|
157
|
+
this.pending.delete(message.id);pending.release();
|
|
158
|
+
if(message.kind==='error'){this.events.delete(message.id);pending.reject(unwire(message.error));}
|
|
159
|
+
else pending.resolve(unwire(message.value));
|
|
160
|
+
}
|
|
161
|
+
invoke(method,args=[],signal=null,callback=null,resource=undefined) {
|
|
162
|
+
if(this.closed)return Promise.reject(failure('Device frame disconnected','UNAVAILABLE'));
|
|
163
|
+
if(signal?.aborted)return Promise.reject(failure('Device operation cancelled','CANCELLED'));
|
|
164
|
+
const id=++this.sequence;if(callback)this.events.set(id,callback);
|
|
165
|
+
const promise=new Promise((resolve,reject)=>{
|
|
166
|
+
const abort=()=>{
|
|
167
|
+
this.port.postMessage({kind:'cancel',id});this.pending.delete(id);this.events.delete(id);
|
|
168
|
+
signal.removeEventListener('abort',abort);reject(failure('Device operation cancelled','CANCELLED'));
|
|
169
|
+
};
|
|
170
|
+
signal?.addEventListener('abort',abort,{once:true});
|
|
171
|
+
this.pending.set(id,{resolve,reject,release:()=>signal?.removeEventListener('abort',abort)});
|
|
172
|
+
this.port.postMessage({kind:'call',id,method,args,resource});
|
|
173
|
+
});
|
|
174
|
+
return promise;
|
|
175
|
+
}
|
|
176
|
+
dispose() {
|
|
177
|
+
if(this.closed)return;this.closed=true;
|
|
178
|
+
this.window.removeEventListener('pagehide',this.hide);this.port.postMessage({kind:'close'});this.port.close();
|
|
179
|
+
for(const pending of this.pending.values()){pending.release();pending.reject(failure('Device frame disconnected','CANCELLED'));}
|
|
180
|
+
this.pending.clear();this.events.clear();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
for(const [method,[,count,kind,hasSignal]] of Object.entries(methods)) {
|
|
184
|
+
Object.defineProperty(FrameDeviceProvider.prototype,method,{value:async function(...params){
|
|
185
|
+
const args=params.slice(0,count), callback=['value','database'].includes(kind)?null:params[count];
|
|
186
|
+
const signal=hasSignal?params[count+(['value','database'].includes(kind)?0:1)]:null;
|
|
187
|
+
const result=await this.invoke(method,args,signal,callback);
|
|
188
|
+
if(kind==='value')return result;
|
|
189
|
+
const resource=result.resource;
|
|
190
|
+
if(kind==='database')return {query:(sql,params=[])=>this.invoke('query',[sql,params],null,null,resource), execute:(sql,params=[])=>this.invoke('execute',[sql,params],null,null,resource),close:()=>this.invoke('close',[],null,null,resource)};
|
|
191
|
+
if(kind==='stream')return async()=>{this.events.delete(resource);await this.invoke('close',[],null,null,resource);};
|
|
192
|
+
return {stop:()=>this.invoke('stop',[],null,null,resource),share:s=>this.invoke('share',[],s,null,resource),
|
|
193
|
+
dispose:async()=>{this.events.delete(resource);await this.invoke('dispose',[],null,null,resource);}};
|
|
194
|
+
}});
|
|
195
|
+
}
|
package/src/filesystem.d.ts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import type {Bag} from '@genrojs/bag';
|
|
2
|
+
import {RemoteResolver} from './binding/remote-resolver.js';
|
|
2
3
|
import type {SourceBag, SourceBagNode} from '@genrojs/builders';
|
|
3
4
|
import type {Gramlot} from './gramlot.js';
|
|
4
5
|
export function fileSystemTree(parent: SourceBag | SourceBagNode, options: {datapath: string; [key:string]:unknown}): SourceBagNode;
|
|
5
|
-
export class DirectoryResolver {
|
|
6
|
+
export class DirectoryResolver extends RemoteResolver {
|
|
6
7
|
constructor(options: {gramlot:Gramlot; root:string; path?:string; onError:(error:Error)=>void});
|
|
8
|
+
gramlot:Gramlot;
|
|
9
|
+
method:string;
|
|
10
|
+
params:{root:string;path:string};
|
|
11
|
+
children:Set<DirectoryResolver>;
|
|
7
12
|
prepareValue(bag:Bag):Bag;
|
|
8
13
|
readonly closed:boolean;
|
|
9
|
-
loading:Promise<Bag>|null;
|
|
10
|
-
resolve():Bag|null;
|
|
11
|
-
refresh():Promise<Bag>|null;
|
|
14
|
+
loading:Promise<Bag|undefined>|null;
|
|
15
|
+
resolve(options?:{static?:boolean}):Bag|null;
|
|
16
|
+
refresh():Promise<Bag|undefined>|null;
|
|
17
|
+
startLoad(perform: (request: {controller: AbortController; method: string; params: {root: string; path: string}; ignored: boolean}) => Promise<unknown>): Promise<unknown>;
|
|
18
|
+
loadAsync(request: {controller: AbortController; method: string; params: {root: string; path: string}}): Promise<unknown>;
|
|
12
19
|
abort():void;
|
|
13
20
|
}
|
|
14
21
|
export class FileSystemController {
|
|
15
|
-
constructor(gramlot:Gramlot,
|
|
22
|
+
constructor(gramlot:Gramlot, source:SourceBagNode);
|
|
16
23
|
open(root:string):Promise<string|null>;
|
|
17
24
|
dispose():void;
|
|
18
25
|
}
|
package/src/filesystem.js
CHANGED
|
@@ -60,13 +60,14 @@ export class DirectoryResolver extends RemoteResolver {
|
|
|
60
60
|
|
|
61
61
|
/** Own directory requests; the selection and store remain in the component's Data Bag. */
|
|
62
62
|
export class FileSystemController {
|
|
63
|
-
constructor(gramlot,
|
|
63
|
+
constructor(gramlot, source) {
|
|
64
64
|
this.gramlot = gramlot;
|
|
65
|
-
this.
|
|
65
|
+
this.source = source;
|
|
66
66
|
this.request = null;
|
|
67
67
|
this.resolver = null;
|
|
68
68
|
this.disposed = false;
|
|
69
69
|
}
|
|
70
|
+
get state() { return this.source.getRelativeData('.'); }
|
|
70
71
|
async open(root) {
|
|
71
72
|
this.request?.abort();
|
|
72
73
|
const request = this.request = new AbortController();
|
|
@@ -93,17 +94,16 @@ export class FileSystemController {
|
|
|
93
94
|
dispose() { this.disposed = true; this.request?.abort(); this.resolver?.abort(); }
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
/** Named Logic
|
|
97
|
+
/** Named Logic routes through the Source owner; no instance state lives on the Logic group. */
|
|
97
98
|
export class FileSystemLogic {
|
|
98
99
|
fileSystemMount(node) {
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
this.fileSystems.set(state, controller);
|
|
100
|
+
const scope = node.parentNode;
|
|
101
|
+
const controller = new FileSystemController(this.page, scope);
|
|
102
|
+
Object.defineProperty(scope,'fileSystemController',{value:controller,configurable:true});
|
|
103
103
|
this.page.src.renderer.onDispose(scope, () => controller.dispose());
|
|
104
104
|
}
|
|
105
105
|
fileSystemOpen(node, {root}) {
|
|
106
|
-
if (root) return
|
|
106
|
+
if (root) return node.parentNode.fileSystemController.open(root);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
package/src/gramlot.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type {NameSyntaxDescriptor} from './builder/name-syntax.js';
|
|
|
14
14
|
import type {SourceHandler} from './handlers/source-handler.js';
|
|
15
15
|
import type {RpcHandler} from './handlers/rpc-handler.js';
|
|
16
16
|
import type {DomHandler} from './handlers/dom-handler.js';
|
|
17
|
+
import type {DeviceHandler} from './handlers/device-handler.js';
|
|
17
18
|
import type {UtilitiesHandler} from './handlers/utilities-handler.js';
|
|
18
19
|
|
|
19
20
|
/** The options of a `Gramlot` instance. */
|
|
@@ -89,6 +90,7 @@ export class Gramlot {
|
|
|
89
90
|
src: SourceHandler;
|
|
90
91
|
/** The Data Bag of the page. */
|
|
91
92
|
data: Bag;
|
|
93
|
+
dvc: DeviceHandler;
|
|
92
94
|
/** The exchange with the server. */
|
|
93
95
|
rpc: RpcHandler;
|
|
94
96
|
/** The DOM and its correspondence with the Source. */
|
|
@@ -120,5 +122,5 @@ export class Gramlot {
|
|
|
120
122
|
/** Request `main` from the transport and mount it. */
|
|
121
123
|
loadMain(): Promise<Gramlot>;
|
|
122
124
|
/** Dispose the page: abort requests, close bindings and the renderer, and close the server page. */
|
|
123
|
-
dispose(
|
|
125
|
+
dispose(): void;
|
|
124
126
|
}
|