@gramlot/gramlot 0.3.10 → 0.3.16
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 +13 -0
- package/dist/components/{editors.js → editors/assets/collection.js} +131 -246
- package/dist/components/editors/assets/index.js +2 -0
- package/dist/components/editors/commands.json +7 -0
- package/dist/components/editors/grammar.json +7045 -0
- package/dist/components/inputs/__init__.py +13 -0
- package/dist/components/{inputs.js → inputs/assets/collection.js} +287 -198
- package/dist/components/inputs/assets/index.js +2 -0
- package/dist/components/inputs/commands.json +7 -0
- package/dist/components/inputs/grammar.json +42881 -0
- package/dist/components/layout/__init__.py +13 -0
- package/dist/components/layout/assets/collection.js +25737 -0
- package/dist/components/layout/assets/index.js +2 -0
- package/dist/components/layout/commands.json +7 -0
- package/dist/components/layout/grammar.json +1798 -0
- package/dist/components/tree/__init__.py +13 -0
- package/dist/components/{tree.js → tree/assets/collection.js} +62 -175
- package/dist/components/tree/assets/index.js +2 -0
- package/dist/components/tree/commands.json +7 -0
- package/dist/components/tree/grammar.json +339 -0
- package/dist/components/typst/__init__.py +13 -0
- package/dist/components/typst/assets/collection.js +4 -0
- package/dist/components/typst/assets/index.js +2 -0
- package/dist/components/typst/commands.json +7 -0
- package/dist/components/typst/grammar.json +81 -0
- package/dist/gramlot.js +2496 -905
- package/dist/gramlot.min.js +109 -28
- package/dist/runtime-notices.json +0 -196
- package/package.json +1 -1
- package/src/binding/ask-dialog.js +1 -1
- package/src/binding/installation.js +5 -6
- package/src/binding/runtime.js +4 -2
- package/src/bootstrap.d.ts +1 -1
- package/src/bootstrap.js +52 -30
- package/src/builder/binding.json +25 -0
- package/src/builder/gramlot-builder.js +16 -3
- package/src/builder/source.js +33 -1
- package/src/collection-artifact.d.ts +11 -0
- package/src/collection-artifact.js +57 -0
- package/src/commands.d.ts +9 -0
- package/src/commands.js +36 -0
- package/src/components/bases.js +1 -1
- package/src/components/border-container.js +26 -1
- package/src/components/buttons.js +84 -161
- package/src/components/choice-editor.js +31 -10
- package/src/components/database-choices.js +110 -0
- package/src/components/inputs.js +15 -2
- package/src/components/layout.js +5 -3
- package/src/components/menus.js +346 -0
- package/src/components/popup.js +15 -2
- package/src/components/registry.js +18 -3
- package/src/components/toolbar-overflow.js +181 -0
- package/src/components/tree.js +14 -4
- package/src/components/windows.js +284 -0
- package/src/filesystem.js +1 -0
- package/src/gramlot.d.ts +2 -0
- package/src/gramlot.js +4 -2
- package/src/handlers/rpc-handler.d.ts +6 -1
- package/src/handlers/rpc-handler.js +7 -2
- package/src/handlers/source-handler.d.ts +2 -1
- package/src/handlers/source-handler.js +10 -1
- package/src/ide-documents.js +1 -1
- package/src/ide-runtime.js +3 -2
- package/src/index-page-styles.js +1 -1
- package/src/index-theme.js +1 -1
- package/src/index.d.ts +5 -0
- package/src/index.js +5 -0
- package/src/renderer/gramlot-html-renderer.js +1 -0
- package/src/renderer/gramlot-renderer.js +13 -3
- package/src/server/gramlot-file-server.d.ts +2 -0
- package/src/server/gramlot-file-server.js +45 -1
- package/src/server/gramlot-server.d.ts +20 -2
- package/src/server/gramlot-server.js +86 -6
- package/src/server/page-base.js +1 -0
- package/src/server/page.d.ts +3 -0
- package/src/view/button.js +47 -3
- package/src/view/controls.js +8 -0
- package/src/view/html.js +1 -0
- package/src/view/menu-command.js +45 -0
- package/src/view/menu.js +87 -0
- package/themes/gramlot-compact/README.md +19 -0
- package/themes/gramlot-compact/theme.css +138 -45
- package/themes/joanna/README.md +19 -0
- package/themes/joanna/theme.css +134 -78
- package/themes/mela/theme.css +184 -0
- package/themes/mimi/README.md +19 -0
- package/themes/mimi/theme.css +133 -77
- package/themes/palettes/README.md +3 -0
- package/themes/palettes/compact.css +86 -0
- package/themes/palettes/joanna.css +86 -0
- package/themes/palettes/mimi.css +86 -0
- package/tools/gramlot-tools-inspector.js +3 -3
- package/dist/components/layout.js +0 -3385
- package/dist/components/typst.js +0 -4
package/src/components/tree.js
CHANGED
|
@@ -46,7 +46,7 @@ export const Tree = defineComponent({
|
|
|
46
46
|
style.textContent = `
|
|
47
47
|
.control-box{overflow:auto;padding:4px;min-height:32px}
|
|
48
48
|
ul{list-style:none;margin:0;padding:0} ul ul{padding-inline-start:20px}
|
|
49
|
-
.row{display:flex;align-items:center;min-height:var(--gramlot-tree-row-height,28px);gap:
|
|
49
|
+
.row{display:flex;align-items:center;min-height:var(--gramlot-tree-row-height,28px);gap:2px;border-radius:3px;cursor:default}
|
|
50
50
|
.row:hover{background:var(--gramlot-tree-hover-background,var(--gramlot-field-readonly-background,#f2f4f7))}
|
|
51
51
|
.canBeDropped{outline:2px solid var(--gramlot-brand-blue,#3766b5);outline-offset:-2px}
|
|
52
52
|
.cannotBeDropped{outline:2px dashed currentColor;outline-offset:-2px}.draggedItem{opacity:.75}
|
|
@@ -54,8 +54,11 @@ export const Tree = defineComponent({
|
|
|
54
54
|
color:var(--gramlot-tree-selected-color,#214f91)}
|
|
55
55
|
[role=treeitem]:focus{outline:none}
|
|
56
56
|
[role=treeitem]:focus-visible>.row{outline:2px solid var(--gramlot-brand-blue,#3766b5);outline-offset:-2px}
|
|
57
|
-
button{border:0;background:transparent;color:inherit;width:
|
|
58
|
-
.
|
|
57
|
+
button{border:0;background:transparent;color:inherit;width:max(20px,var(--gramlot-touch-target,0px));height:24px;padding:0;font:inherit;cursor:pointer}
|
|
58
|
+
.expander{display:grid;place-items:center;flex:none}
|
|
59
|
+
.expander svg{display:block;width:14px;height:14px;pointer-events:none}
|
|
60
|
+
[aria-expanded=true]>.row>.expander svg{transform:rotate(90deg)}
|
|
61
|
+
.spacer{width:max(20px,var(--gramlot-touch-target,0px));flex:none}.caption{min-width:0;overflow-wrap:anywhere}
|
|
59
62
|
.icon{width:16px;height:16px;flex:none;background:currentColor;opacity:.7;mask:center/contain no-repeat;
|
|
60
63
|
mask-image:url("data:image/svg+xml,%3Csvg xmlns='${SVG_NS}' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='black' stroke-width='1.7' d='M5 3h9l5 5v13H5zM14 3v6h5M8 13h8M8 17h8'/%3E%3C/svg%3E")}
|
|
61
64
|
.branch-icon{mask-image:url("data:image/svg+xml,%3Csvg xmlns='${SVG_NS}' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='black' stroke-width='1.7' d='M3 7V4h7l3 3h8v13H3z'/%3E%3C/svg%3E")}
|
|
@@ -162,6 +165,14 @@ export const Tree = defineComponent({
|
|
|
162
165
|
if (branch) {
|
|
163
166
|
expander.className = 'expander';
|
|
164
167
|
expander.type = 'button'; expander.tabIndex = -1;
|
|
168
|
+
const chevron = this.ownerDocument.createElementNS(SVG_NS, 'svg');
|
|
169
|
+
chevron.setAttribute('viewBox', '0 0 24 24');
|
|
170
|
+
chevron.setAttribute('aria-hidden', 'true'); chevron.setAttribute('focusable', 'false');
|
|
171
|
+
const chevronPath = this.ownerDocument.createElementNS(SVG_NS, 'path');
|
|
172
|
+
chevronPath.setAttribute('d', 'm9 5 7 7-7 7'); chevronPath.setAttribute('fill', 'none');
|
|
173
|
+
chevronPath.setAttribute('stroke', 'currentColor'); chevronPath.setAttribute('stroke-width', '1.8');
|
|
174
|
+
chevronPath.setAttribute('stroke-linecap', 'round'); chevronPath.setAttribute('stroke-linejoin', 'round');
|
|
175
|
+
chevron.append(chevronPath); expander.append(chevron);
|
|
165
176
|
expander.addEventListener('click', event => {
|
|
166
177
|
event.stopPropagation(); toggle(); entry.focus();
|
|
167
178
|
});
|
|
@@ -238,7 +249,6 @@ export const Tree = defineComponent({
|
|
|
238
249
|
entry.classList.toggle('closed', !opened);
|
|
239
250
|
icon.classList.toggle('opened-icon', opened);
|
|
240
251
|
icon.setAttribute('part', `icon branch-icon ${opened ? 'opened-icon' : 'closed-icon'}`);
|
|
241
|
-
expander.textContent = opened ? '▾' : '▸';
|
|
242
252
|
group.hidden = !opened;
|
|
243
253
|
present();
|
|
244
254
|
};
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import {SVG_NS} from '../renderer/attributes.js';
|
|
2
|
+
/** Shared window chrome. Source owns the frame; native dialog owns modality. */
|
|
3
|
+
import {defineComponent} from './registry.js';
|
|
4
|
+
import {projectParameters} from './parameters.js';
|
|
5
|
+
|
|
6
|
+
function WindowShell(HTMLElement) {
|
|
7
|
+
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
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
const doc = this.ownerDocument;
|
|
15
|
+
const shadow = this.attachShadow({mode:'open'});
|
|
16
|
+
const style = doc.createElement('style');
|
|
17
|
+
style.textContent = `:host{display:contents;font:inherit;color:var(--gramlot-ink,CanvasText)}
|
|
18
|
+
*,*::before,*::after{box-sizing:border-box}
|
|
19
|
+
dialog{position:fixed;inset:auto;margin:0;padding:0;border:1px solid var(--gramlot-border-control,#8793a4);
|
|
20
|
+
border-radius:var(--gramlot-window-radius,9px);color:inherit;font:inherit;
|
|
21
|
+
background:var(--gramlot-surface,Canvas);box-shadow:0 12px 40px #0005;overflow:hidden;
|
|
22
|
+
max-width:calc(100vw - 16px);max-height:calc(100dvh - 16px)}
|
|
23
|
+
dialog[open]{display:flex;flex-direction:column}
|
|
24
|
+
dialog[data-maximized]{max-width:100vw;max-height:100dvh;border-radius:0}
|
|
25
|
+
dialog::backdrop{background:var(--gramlot-window-backdrop,#0006)}
|
|
26
|
+
.titlebar{display:flex;align-items:center;gap:var(--gramlot-space-2,8px);flex:none;min-height:max(28px,var(--gramlot-field-height,36px));padding:2px 4px 2px 10px;
|
|
27
|
+
background:var(--gramlot-surface-subtle,#e5e9ef);border-bottom:1px solid var(--gramlot-border-control,#8793a4)}
|
|
28
|
+
.title{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin:0;font-size:1em;font-weight:600}
|
|
29
|
+
.titlebar[data-movable]{cursor:move;touch-action:none;user-select:none}
|
|
30
|
+
button{font:inherit;color:inherit;background:transparent;border:0;border-radius:4px;cursor:pointer;min-width:max(24px,var(--gramlot-touch-target,0px));min-height:max(24px,var(--gramlot-touch-target,0px))}
|
|
31
|
+
button:hover{background:color-mix(in srgb,currentColor 12%,transparent)}
|
|
32
|
+
button:focus-visible,.titlebar:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}
|
|
33
|
+
.body{flex:1;min-height:0;min-width:0;display:flex;overflow:hidden}
|
|
34
|
+
slot{display:contents}::slotted(gramlot-frame-pane){flex:1;width:100%;height:100%;min-height:0;min-width:0}
|
|
35
|
+
.resize{position:absolute;right:0;bottom:0;width:20px;height:20px;min-width:20px;min-height:20px;
|
|
36
|
+
display:grid;place-items:end;padding:2px;cursor:nwse-resize;touch-action:none;opacity:.65}
|
|
37
|
+
.resize:hover,.resize:focus-visible{opacity:1}
|
|
38
|
+
.resize svg{width:14px;height:14px;pointer-events:none}
|
|
39
|
+
[hidden]{display:none!important}.status{flex:none;font-size:.85em;padding:4px 10px;color:var(--gramlot-error,#b22)}
|
|
40
|
+
dialog[data-collapsed] .titlebar{border-bottom:0}`;
|
|
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
|
+
}
|
|
90
|
+
projectAttributes(attrs) {
|
|
91
|
+
const previous=this.parameters;
|
|
92
|
+
const rest=projectParameters(this,attrs);
|
|
93
|
+
if(previous) {
|
|
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);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
const bool=(value,binding='read')=>({dtype:'B',default:value,binding});
|
|
275
|
+
WindowShell.parameters={
|
|
276
|
+
title:{dtype:'T',default:'',binding:'read'},open:bool(false,'twoWay'),collapsed:bool(false,'twoWay'),closable:bool(true),
|
|
277
|
+
movable:bool(false),resizable:bool(false),collapsible:bool(false),maximizable:bool(false),maximized:bool(false,'twoWay'),
|
|
278
|
+
beforeClose:{dtype:'T',nullable:true},
|
|
279
|
+
...Object.fromEntries(['width','height','left','top'].map(name=>[name,{dtype:'T',nullable:true,binding:'twoWay'}])),
|
|
280
|
+
...Object.fromEntries(['minWidth','minHeight'].map(name=>[name,{dtype:'T',nullable:true,binding:'read'}])),
|
|
281
|
+
};
|
|
282
|
+
export const Dialog=defineComponent({name:'dialog',tag:'gramlot-dialog',base:WindowShell,sourceContext:true,subTags:'framePane',implementation:Base=>class extends Base{}});
|
|
283
|
+
export const FloatingPane=defineComponent({name:'floatingPane',tag:'gramlot-floating-pane',base:WindowShell,sourceContext:true,subTags:'framePane',
|
|
284
|
+
parameters:{movable:bool(true),resizable:bool(true),collapsible:bool(true)},implementation:Base=>class extends Base{}});
|
package/src/filesystem.js
CHANGED
|
@@ -81,6 +81,7 @@ export class FileSystemController {
|
|
|
81
81
|
this.resolver = resolver;
|
|
82
82
|
this.state.setItem('selectedPath', null);
|
|
83
83
|
this.state.setItem('store', store);
|
|
84
|
+
this.state.setItem('writable', result.writable);
|
|
84
85
|
this.state.setItem('root', result.root);
|
|
85
86
|
this.state.setItem('status', '');
|
|
86
87
|
return result.root;
|
package/src/gramlot.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type {CommandRegistry} from './commands.js';
|
|
1
2
|
/**
|
|
2
3
|
* One Gramlot page in the browser.
|
|
3
4
|
*
|
|
@@ -72,6 +73,7 @@ export type Publication = string | {topic: string; nodeId: string} |
|
|
|
72
73
|
|
|
73
74
|
/** One Gramlot page: lifecycle, Data and the four proxies `src`, `rpc`, `dom`, `utl`. */
|
|
74
75
|
export class Gramlot {
|
|
76
|
+
readonly commands: CommandRegistry;
|
|
75
77
|
readonly devices: readonly ('desktop' | 'tablet' | 'phone')[];
|
|
76
78
|
locale: string;
|
|
77
79
|
timeZone: string;
|
package/src/gramlot.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
+
import {CommandRegistry} from './commands.js';
|
|
7
8
|
import {ServerAdapter} from './server-adapter.js';
|
|
8
9
|
import {NAME_SYNTAX, NameSyntax} from './builder/name-syntax.js';
|
|
9
10
|
import {SourceHandler} from './handlers/source-handler.js';
|
|
@@ -29,6 +30,7 @@ export class Gramlot {
|
|
|
29
30
|
for (const collection of collections) {
|
|
30
31
|
if (collection instanceof ComponentCollection) collection.register(document.defaultView);
|
|
31
32
|
}
|
|
33
|
+
this.commands = new CommandRegistry();
|
|
32
34
|
this.pageId = pageId;
|
|
33
35
|
const browserContext = locale == null || timeZone == null
|
|
34
36
|
? document.defaultView.Intl.DateTimeFormat().resolvedOptions() : null;
|
|
@@ -71,7 +73,7 @@ export class Gramlot {
|
|
|
71
73
|
async loadMain() {
|
|
72
74
|
let wire;
|
|
73
75
|
try {
|
|
74
|
-
wire = await this.rpc.
|
|
76
|
+
wire = await this.rpc.callEnvelope('source', 'main');
|
|
75
77
|
} catch (error) {
|
|
76
78
|
// The dispose aborts the call at once (RpcHandler.call): the start rejects naming the dispose.
|
|
77
79
|
if (this.state === 'disposed') throw new Error('Gramlot was disposed during main', {cause: error});
|
|
@@ -80,7 +82,7 @@ export class Gramlot {
|
|
|
80
82
|
}
|
|
81
83
|
if (this.state === 'disposed') throw new Error('Gramlot was disposed during main');
|
|
82
84
|
try {
|
|
83
|
-
return this.src.mountMainSource(wire);
|
|
85
|
+
return this.src.mountMainSource(wire.value, wire.data);
|
|
84
86
|
} catch (error) {
|
|
85
87
|
if (this.state !== 'disposed') this.state = 'failed';
|
|
86
88
|
throw error;
|
|
@@ -66,6 +66,11 @@ export class RpcHandler extends Handler {
|
|
|
66
66
|
options?: {signal?: AbortSignal}): Promise<unknown>;
|
|
67
67
|
/** Whether the transport sends a synchronous call (`supportsCallSync`). */
|
|
68
68
|
readonly supportsCallSync: boolean;
|
|
69
|
-
/**
|
|
69
|
+
/** Return the checked response envelope, including optional initial-main Data. */
|
|
70
|
+
callEnvelope(contentType: 'source' | 'data', name: string, params?: Record<string, unknown>,
|
|
71
|
+
options?: {signal?: AbortSignal | null}): Promise<{
|
|
72
|
+
id: string; contentType: string; value: unknown; data?: import('@genrojs/bag').Bag;
|
|
73
|
+
}>;
|
|
74
|
+
/** Send one envelope synchronously; only with a transport that supports it. */
|
|
70
75
|
callSync(contentType: 'source' | 'data', name: string, params?: Record<string, unknown>): unknown;
|
|
71
76
|
}
|
|
@@ -59,7 +59,12 @@ export class RpcHandler extends Handler {
|
|
|
59
59
|
return response.value;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
async call(contentType, name, params = {},
|
|
62
|
+
async call(contentType, name, params = {}, options = {}) {
|
|
63
|
+
return (await this.callEnvelope(contentType, name, params, options)).value;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Return the checked response envelope, including optional initial-main Data. */
|
|
67
|
+
async callEnvelope(contentType, name, params = {}, {signal = null} = {}) {
|
|
63
68
|
if (!this.transport?.call) throw new Error(`rpc '${name}' is unavailable without a server transport`);
|
|
64
69
|
assertTransportData(params);
|
|
65
70
|
const id = randomId();
|
|
@@ -82,7 +87,7 @@ export class RpcHandler extends Handler {
|
|
|
82
87
|
const response = fromTytx(await Promise.race([this.transport.call(text, controller.signal), aborted]));
|
|
83
88
|
if (response.id !== id) throw new Error('rpc response id mismatch');
|
|
84
89
|
if (response.error) throw new RpcError(response.error);
|
|
85
|
-
return response
|
|
90
|
+
return response;
|
|
86
91
|
} finally {
|
|
87
92
|
this.remoteRequests.delete(id);
|
|
88
93
|
for (const source of sources) source.removeEventListener('abort', forward);
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
+
import type {Bag} from '@genrojs/bag';
|
|
6
7
|
import type {SourceBag, SourceBagNode} from '@genrojs/builders';
|
|
7
8
|
import type {DomElement} from '../dom.d.ts';
|
|
8
9
|
import type {Gramlot} from '../gramlot.js';
|
|
@@ -35,7 +36,7 @@ export class SourceHandler extends Handler {
|
|
|
35
36
|
/** Start from an embedded typed Source, with the same observed insertion as `main`. */
|
|
36
37
|
startSource(wire: SourceBag | string): Gramlot;
|
|
37
38
|
/** Validate and insert `main` in the Source. */
|
|
38
|
-
mountMainSource(wire: SourceBag | string): Gramlot;
|
|
39
|
+
mountMainSource(wire: SourceBag | string, initialData?: Bag | null): Gramlot;
|
|
39
40
|
/**
|
|
40
41
|
* A Source from a SourceBag or a TYTX wire; only Gramlot Source Bags are accepted, before any
|
|
41
42
|
* effect. The received Source activates its inline code.
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
+
import {Bag} from '@genrojs/bag';
|
|
7
8
|
import {SourceBag, sourceBagFromTytx} from '@genrojs/builders';
|
|
8
9
|
import {Handler} from './handler.js';
|
|
9
10
|
import {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
@@ -44,9 +45,17 @@ export class SourceHandler extends Handler {
|
|
|
44
45
|
* new one; the Data is not rolled back. A later error (`_init`, DOM) keeps `main` and its
|
|
45
46
|
* NodeBindings (P12, no rollback).
|
|
46
47
|
*/
|
|
47
|
-
mountMainSource(wire) {
|
|
48
|
+
mountMainSource(wire, initialData = null) {
|
|
48
49
|
const source = this.prepareSource(wire);
|
|
49
50
|
this.renderer.validateCandidate(source);
|
|
51
|
+
if (initialData !== null) {
|
|
52
|
+
if (!(initialData instanceof Bag) || initialData instanceof SourceBag) {
|
|
53
|
+
throw new TypeError('Initial page data must be a Data Bag');
|
|
54
|
+
}
|
|
55
|
+
for (const node of initialData.getNodes()) {
|
|
56
|
+
this.builder.data.setItem([node.label], node.getValue(), node.attr, '>', false, false);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
50
59
|
try {
|
|
51
60
|
this.source.setItem('main', source);
|
|
52
61
|
} catch (error) {
|
package/src/ide-documents.js
CHANGED
|
@@ -38,7 +38,7 @@ export class IdeDocuments {
|
|
|
38
38
|
}
|
|
39
39
|
async create(key) {
|
|
40
40
|
const doc = this.documents.getItem(key);
|
|
41
|
-
if (!doc || !doc.getItem('isNew') || this.pending.has(key)) return false;
|
|
41
|
+
if (!doc || !doc.getItem('isNew') || !doc.getItem('writable') || this.pending.has(key)) return false;
|
|
42
42
|
const root = doc.getItem('saveRoot'), path = doc.getItem('savePath');
|
|
43
43
|
if (doc.getItem('path').endsWith('.typ.py') !== path.endsWith('.typ.py')) {
|
|
44
44
|
throw new Error('The .typ.py extension is required for the Typst Python recipe document type.');
|
package/src/ide-runtime.js
CHANGED
|
@@ -71,7 +71,7 @@ export class IdeLogic {
|
|
|
71
71
|
this.ideShowDocument(key);
|
|
72
72
|
if (requested === this.ideRequested) {
|
|
73
73
|
this.ideState.setItem('active',key);
|
|
74
|
-
this.ideState.setItem('status',`${path}${this.ideDocuments.documents.getItem(key).getItem('writable') ? '' : ' (
|
|
74
|
+
this.ideState.setItem('status',`${path}${this.ideDocuments.documents.getItem(key).getItem('writable') ? '' : ' (draft only — Remote Edit is disabled)'}`);
|
|
75
75
|
}
|
|
76
76
|
} catch (error) { if (!this.ideDisposed) this.ideState.setItem('status',error.message); }
|
|
77
77
|
}
|
|
@@ -81,6 +81,7 @@ export class IdeLogic {
|
|
|
81
81
|
const extensions = {typstRecipe:'.typ.py',typst:'.typ',markdown:'.md',html:'.html',python:'.py',javascript:'.js',
|
|
82
82
|
typescript:'.ts',json:'.json',css:'.css',sql:'.sql',xml:'.xml',text:'.txt'};
|
|
83
83
|
const key = this.ideDocuments.newDocument(language,extensions[type],this.ideState.getItem('workspace'));
|
|
84
|
+
this.ideDocuments.documents.getItem(key).setItem('writable',this.ideState.getItem('browser.writable') === true);
|
|
84
85
|
++this.ideRequested;
|
|
85
86
|
this.ideShowDocument(key);
|
|
86
87
|
this.ideState.setItem('active',key);
|
|
@@ -93,7 +94,7 @@ export class IdeLogic {
|
|
|
93
94
|
const doc = this.ideDocuments.documents.getItem(key);
|
|
94
95
|
const recipe = path.endsWith('.typ.py');
|
|
95
96
|
if (recipe) this.ideDocuments.invalidateRecipe(key);
|
|
96
|
-
doc.setItem('readonly'
|
|
97
|
+
doc.setItem('readonly',false);
|
|
97
98
|
this.ideDocumentState(key);
|
|
98
99
|
doc.setItem('view','code');
|
|
99
100
|
doc.setItem('createHidden',true);
|