@gramlot/gramlot 0.3.35 → 0.3.37
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/charts/__init__.py +1 -1
- package/dist/components/charts/assets/collection.js +9 -9
- package/dist/components/charts/assets/index.js +1 -1
- package/dist/components/charts/grammar.json +0 -30
- package/dist/components/drawing/__init__.py +1 -1
- package/dist/components/drawing/assets/collection.js +3 -3
- package/dist/components/drawing/assets/index.js +1 -1
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +4 -2
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/modules/addon-fit-L6JK4OJX.js +12 -0
- package/dist/components/editors/assets/modules/xterm-BF3OSWRI.js +286 -0
- package/dist/components/editors/assets/modules/xterm-UBEXZEYY.js +47 -0
- package/dist/components/editors/grammar.json +207 -0
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/collection.js +6 -6
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +0 -2
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +8 -8
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +2 -1
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +9 -9
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +2 -2
- package/dist/components/selection_trial/__init__.py +1 -1
- package/dist/components/selection_trial/assets/collection.js +3 -3
- package/dist/components/selection_trial/assets/index.js +1 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +6 -6
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +0 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/collection.js +3 -3
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/uploads/grammar.json +0 -3
- package/dist/gramlot.js +1238 -627
- package/dist/gramlot.min.js +45 -45
- package/dist/libraries.json +27 -0
- package/dist/standard-collections.js +1 -1
- package/package.json +4 -3
- package/src/binding/data-binder.js +11 -3
- package/src/binding/grid-struct.js +7 -4
- package/src/binding/runtime.js +203 -46
- package/src/builder/binding.json +23 -1
- package/src/builder/gramlot-builder.d.ts +1 -4
- package/src/builder/source.js +185 -29
- package/src/chat.js +26 -20
- package/src/components/attachment-manager.js +38 -34
- package/src/components/chart-data-view.js +4 -7
- package/src/components/chart-fields.js +18 -6
- package/src/components/chart-renderer.js +10 -3
- package/src/components/chart-timeline.js +7 -5
- package/src/components/charts.js +74 -67
- package/src/components/check-box-text-editor.js +3 -3
- package/src/components/check-box-text.js +7 -22
- package/src/components/check-box-tree.js +20 -16
- package/src/components/choice-editor.js +1 -1
- package/src/components/drawing.js +47 -34
- package/src/components/editors.js +3 -1
- package/src/components/grid-cell-editor.js +72 -29
- package/src/components/grid-column-filters.js +47 -40
- package/src/components/grid-formulas.js +22 -17
- package/src/components/grid-header-interaction.js +9 -11
- package/src/components/grid-row-interaction.js +25 -24
- package/src/components/grid-row-layout.js +28 -29
- package/src/components/grid-search-box.js +3 -3
- package/src/components/grid-search.js +3 -8
- package/src/components/grid-selection.js +33 -29
- package/src/components/grid-structure.js +48 -10
- package/src/components/grid-tools.js +14 -14
- package/src/components/grid.js +83 -79
- package/src/components/image-crop-dialog.js +2 -2
- package/src/components/image-crop.js +16 -9
- package/src/components/image-uploader.js +21 -28
- package/src/components/inputs.js +19 -1
- package/src/components/registry.js +3 -5
- package/src/components/terminal.js +158 -0
- package/src/components/tray-pane.js +85 -61
- package/src/components/tree.js +332 -239
- package/src/components/upload-engine.js +10 -2
- package/src/components/uploader.js +31 -27
- package/src/editing-session.d.ts +4 -1
- package/src/editing-session.js +120 -83
- package/src/experiments/window-selection.js +4 -6
- package/src/filesystem.js +2 -2
- package/src/gramlot.js +1 -0
- package/src/handlers/device-handler.js +219 -213
- package/src/handlers/rpc-handler.d.ts +17 -0
- package/src/handlers/rpc-handler.js +22 -0
- package/src/ide-documents.js +29 -11
- package/src/ide-runtime.js +33 -31
- package/src/index-page-runtime.d.ts +2 -2
- package/src/index-page-runtime.js +67 -48
- package/src/libraries.js +9 -0
- package/src/message-port-connection.js +100 -0
- package/src/message-port-store.js +158 -0
- package/src/page-store-connection.js +14 -1
- package/src/renderer/gramlot-renderer.js +21 -2
- package/src/source-picker.d.ts +2 -2
- package/src/source-picker.js +15 -6
- package/src/stores/bag-collection-store.js +25 -7
- package/src/stores/bag-collection-view.js +23 -22
- package/src/view/controls.js +1 -1
- package/src/view/html.js +45 -20
- package/src/visual-editor-canvas.js +1 -1
- package/src/visual-editor.js +18 -19
- package/tools/gramlot-tools-inspector.js +400 -374
- package/tools/inspector-agent.js +223 -49
- package/dist/components/vizabi/__init__.py +0 -13
- package/dist/components/vizabi/assets/collection.js +0 -4
- package/dist/components/vizabi/assets/index.js +0 -3
- package/dist/components/vizabi/commands.json +0 -7
- package/dist/components/vizabi/grammar.json +0 -128
- package/src/components/vizabi-session.js +0 -66
- package/src/components/vizabi.js +0 -66
|
@@ -17,7 +17,7 @@ function annotation(parameter) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/** Compose effective metadata without invoking a DOM class factory. */
|
|
20
|
-
export function defineComponent({name, tag, base, doc = null, mixins = [], parameters = {}, subTags = '', presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = false,
|
|
20
|
+
export function defineComponent({name, tag, base, doc = null, mixins = [], parameters = {}, subTags = '', presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = false, dragSource = false, implementation}) {
|
|
21
21
|
webcomponentCode({code: tag});
|
|
22
22
|
if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(name)) throw new TypeError('Invalid component authoring name');
|
|
23
23
|
const effective = {...base.parameters};
|
|
@@ -32,7 +32,7 @@ export function defineComponent({name, tag, base, doc = null, mixins = [], param
|
|
|
32
32
|
annotation(spec);
|
|
33
33
|
if (spec.required !== undefined && (spec.required !== true || Object.hasOwn(spec, 'default'))) throw new TypeError('A required component parameter is true and has no default');
|
|
34
34
|
}
|
|
35
|
-
return Object.freeze({name, tag, base, doc, subTags, presentationDefaults: Object.freeze([...presentationDefaults]), dataScope, command,
|
|
35
|
+
return Object.freeze({name, tag, base, doc, subTags, presentationDefaults: Object.freeze([...presentationDefaults]), dataScope, command, mixins: Object.freeze([...mixins]),
|
|
36
36
|
labelbox: mixins.some(mixin => mixin.labelbox === true),
|
|
37
37
|
parameters: freeze(structuredClone(effective)), childParameters: freeze(structuredClone(childParameters)), sourceContext, dragSource, implementation});
|
|
38
38
|
}
|
|
@@ -84,9 +84,7 @@ export class ComponentCollection {
|
|
|
84
84
|
...(Object.keys(component.childParameters).length ? {childParameters: structuredClone(component.childParameters)} : {}),
|
|
85
85
|
...(component.sourceContext ? {sourceContext: true} : {}),
|
|
86
86
|
...(component.labelbox ? {labelbox: true} : {}),
|
|
87
|
-
...(component.dragSource ? {dragSource: true} : {})
|
|
88
|
-
...(component.bagStore ? {bagStore: true} : {}),
|
|
89
|
-
...(component.bagStruct ? {bagStruct: true} : {})}}
|
|
87
|
+
...(component.dragSource ? {dragSource: true} : {})}}
|
|
90
88
|
}]))};
|
|
91
89
|
}
|
|
92
90
|
/** Register once per document realm, only when the collection is activated. */
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import {loadLibrary} from '../libraries.js';
|
|
2
|
+
import {defineComponent} from './registry.js';
|
|
3
|
+
import {projectParameters} from './parameters.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The frames of a terminal session (#87), the same as `gramlot.server.terminal`: one binary WebSocket message,
|
|
7
|
+
* first byte the channel. `INPUT` (0) carries the keys, `OUTPUT` (1) the bytes to write, `RESIZE` (4) the JSON
|
|
8
|
+
* `{"Width": columns, "Height": rows}` of the Kubernetes exec protocol (1 to 65535), `ACK` (5) a 32-bit big-endian count of
|
|
9
|
+
* output bytes the terminal has written. The server stops sending output while 1 MB is unacknowledged.
|
|
10
|
+
*/
|
|
11
|
+
export const INPUT = 0, OUTPUT = 1, RESIZE = 4, ACK = 5;
|
|
12
|
+
|
|
13
|
+
function frame(channel, payload) {
|
|
14
|
+
const bytes = new Uint8Array(payload.length + 1);
|
|
15
|
+
bytes[0] = channel; bytes.set(payload, 1);
|
|
16
|
+
return bytes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function inputFrame(text) { return frame(INPUT, new TextEncoder().encode(text)); }
|
|
20
|
+
export function binaryInputFrame(text) { return frame(INPUT, Uint8Array.from(text, character => character.charCodeAt(0) & 255)); }
|
|
21
|
+
export function resizeFrame(rows, columns) {
|
|
22
|
+
for (const value of [rows, columns]) if (!Number.isInteger(value) || value < 1 || value > 65535) throw new RangeError('A terminal size is 1 to 65535');
|
|
23
|
+
return frame(RESIZE, new TextEncoder().encode(JSON.stringify({Width: columns, Height: rows}))); }
|
|
24
|
+
export function ackFrame(count) {
|
|
25
|
+
if (!Number.isInteger(count) || count < 0 || count > 0xffffffff) throw new RangeError('An acknowledgement counts 0 to 2^32-1 bytes');
|
|
26
|
+
const payload = new Uint8Array(4); new DataView(payload.buffer).setUint32(0, count);
|
|
27
|
+
return frame(ACK, payload);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The output bytes of a server frame; a frame on another channel is an error. */
|
|
31
|
+
export function outputPayload(data) {
|
|
32
|
+
const bytes = new Uint8Array(data);
|
|
33
|
+
if (bytes.length === 0 || bytes[0] !== OUTPUT) throw new Error(`Unexpected terminal frame on channel ${bytes[0]}`);
|
|
34
|
+
return bytes.subarray(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let engineModules;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* xterm.js, its fit addon and its style for a terminal of `document`, loaded once on first use. Resolves with
|
|
41
|
+
* `{Terminal, FitAddon, style}`.
|
|
42
|
+
*/
|
|
43
|
+
export function loadTerminalEngine(document) {
|
|
44
|
+
return engineModules ??= Promise.all([
|
|
45
|
+
loadLibrary('xterm', document, () => import('@xterm/xterm/lib/xterm.mjs')),
|
|
46
|
+
loadLibrary('xtermFit', document, () => import('@xterm/addon-fit/lib/addon-fit.mjs')),
|
|
47
|
+
loadLibrary('xtermStyle', document, () => import('@xterm/xterm/css/xterm.css')),
|
|
48
|
+
]).then(([xterm, fit, style]) => ({Terminal: xterm.Terminal, FitAddon: fit.FitAddon, style}));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function TerminalElement(HTMLElement) {
|
|
52
|
+
return class extends HTMLElement {
|
|
53
|
+
constructor() {
|
|
54
|
+
super();
|
|
55
|
+
const shadow = this.attachShadow({mode: 'open'});
|
|
56
|
+
this.engineStyle = this.ownerDocument.createElement('style');
|
|
57
|
+
const style = this.ownerDocument.createElement('style');
|
|
58
|
+
style.textContent = `:host{display:block;height:300px;min-height:0;min-width:0}
|
|
59
|
+
.terminal-control{height:100%;min-height:0;padding:4px;background:#000;box-sizing:border-box}
|
|
60
|
+
.terminal-status{padding:1em;color:var(--gramlot-text-secondary,GrayText)}`;
|
|
61
|
+
this.control = this.ownerDocument.createElement('div');
|
|
62
|
+
this.control.className = 'terminal-control';
|
|
63
|
+
shadow.append(this.engineStyle, style, this.control);
|
|
64
|
+
}
|
|
65
|
+
projectAttributes(attrs) { return projectParameters(this, attrs); }
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const Terminal = defineComponent({name: 'terminal', tag: 'gramlot-terminal', base: TerminalElement, sourceContext: true,
|
|
70
|
+
doc: 'An interactive terminal connected to the @terminal method `session` of the page store.',
|
|
71
|
+
parameters: {session: {dtype: 'T', default: '', binding: 'read'},
|
|
72
|
+
fontSize: {dtype: 'L', default: 14, binding: 'read'}, fontFamily: {dtype: 'T', default: 'monospace', binding: 'read'},
|
|
73
|
+
connected: {dtype: 'B', default: false, binding: 'write'},
|
|
74
|
+
rows: {dtype: 'L', default: 0, binding: 'write'}, columns: {dtype: 'L', default: 0, binding: 'write'}},
|
|
75
|
+
implementation: Base => class extends Base {
|
|
76
|
+
#context; #generation = 0; #session = null; #socket = null; #terminal = null; #fit = null; #observer = null;
|
|
77
|
+
setSourceContext(context) { this.#context = context; }
|
|
78
|
+
connectedCallback() { this.#start(); }
|
|
79
|
+
disconnectedCallback() { this.#stop(); }
|
|
80
|
+
projectAttributes(attrs) {
|
|
81
|
+
const rest = super.projectAttributes(attrs), p = this.parameters;
|
|
82
|
+
if (typeof p.session !== 'string' || !p.session) throw new TypeError('terminal requires a session name');
|
|
83
|
+
if (!Number.isInteger(p.fontSize) || p.fontSize < 8 || p.fontSize > 48) throw new TypeError('fontSize must be from 8 to 48');
|
|
84
|
+
if (this.#terminal) {
|
|
85
|
+
this.#terminal.options.fontSize = p.fontSize; this.#terminal.options.fontFamily = p.fontFamily;
|
|
86
|
+
this.#fit.fit();
|
|
87
|
+
}
|
|
88
|
+
if (this.isConnected && this.#session !== null && this.#session !== p.session) { this.#stop(); this.#start(); }
|
|
89
|
+
return rest;
|
|
90
|
+
}
|
|
91
|
+
/** Send keys to the session as if typed. */
|
|
92
|
+
input(text) { this.#send(inputFrame(text)); }
|
|
93
|
+
focus() { this.#terminal?.focus(); }
|
|
94
|
+
#write(name, value) { if (this.#context) this.#context.writeParameter(name, value); }
|
|
95
|
+
#send(bytes) { if (this.#socket?.readyState === 1) this.#socket.send(bytes); }
|
|
96
|
+
#start() {
|
|
97
|
+
const generation = ++this.#generation, document = this.ownerDocument;
|
|
98
|
+
this.#session = this.parameters.session;
|
|
99
|
+
this.control.textContent = 'Loading terminal…'; this.control.classList.add('terminal-status');
|
|
100
|
+
this.ready = loadTerminalEngine(document).then(({Terminal, FitAddon, style}) => {
|
|
101
|
+
if (generation !== this.#generation || !this.isConnected) return;
|
|
102
|
+
this.control.textContent = ''; this.control.classList.remove('terminal-status');
|
|
103
|
+
this.engineStyle.textContent = style;
|
|
104
|
+
const p = this.parameters;
|
|
105
|
+
const terminal = this.#terminal = new Terminal({fontSize: p.fontSize, fontFamily: p.fontFamily, convertEol: false});
|
|
106
|
+
const fit = this.#fit = new FitAddon();
|
|
107
|
+
terminal.loadAddon(fit);
|
|
108
|
+
terminal.open(this.control);
|
|
109
|
+
const socket = this.#socket = new document.defaultView.WebSocket(this.#context.terminalUrl(this.#session));
|
|
110
|
+
socket.binaryType = 'arraybuffer';
|
|
111
|
+
terminal.onData(text => this.#send(inputFrame(text)));
|
|
112
|
+
terminal.onBinary(text => this.#send(binaryInputFrame(text)));
|
|
113
|
+
terminal.onResize(({rows, cols}) => {
|
|
114
|
+
this.#send(resizeFrame(rows, cols));
|
|
115
|
+
this.#write('rows', rows); this.#write('columns', cols);
|
|
116
|
+
});
|
|
117
|
+
socket.addEventListener('open', () => {
|
|
118
|
+
if (generation !== this.#generation) return;
|
|
119
|
+
this.#write('connected', true);
|
|
120
|
+
this.#send(resizeFrame(terminal.rows, terminal.cols));
|
|
121
|
+
this.#write('rows', terminal.rows); this.#write('columns', terminal.cols);
|
|
122
|
+
});
|
|
123
|
+
socket.addEventListener('message', event => {
|
|
124
|
+
if (generation !== this.#generation) return;
|
|
125
|
+
let payload;
|
|
126
|
+
try { payload = outputPayload(event.data); }
|
|
127
|
+
catch (error) {
|
|
128
|
+
// A frame the terminal cannot read ends the session, as on the server side.
|
|
129
|
+
socket.close();
|
|
130
|
+
this.#context ? this.#context.reportError(error, 'Terminal') : console.error(error);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
// The acknowledgement follows xterm's parsing: a slow screen slows the server.
|
|
134
|
+
terminal.write(payload, () => this.#send(ackFrame(payload.length)));
|
|
135
|
+
});
|
|
136
|
+
socket.addEventListener('close', () => {
|
|
137
|
+
if (generation === this.#generation) this.#write('connected', false);
|
|
138
|
+
});
|
|
139
|
+
this.#observer = new document.defaultView.ResizeObserver(() => { if (this.#terminal === terminal) fit.fit(); });
|
|
140
|
+
this.#observer.observe(this);
|
|
141
|
+
fit.fit();
|
|
142
|
+
}).catch(error => {
|
|
143
|
+
if (generation !== this.#generation) return;
|
|
144
|
+
this.control.textContent = `The terminal could not start: ${error.message}`;
|
|
145
|
+
this.control.setAttribute('role', 'alert');
|
|
146
|
+
throw error;
|
|
147
|
+
});
|
|
148
|
+
this.ready.catch(error => this.#context ? this.#context.reportError(error, 'Terminal') : console.error(error));
|
|
149
|
+
}
|
|
150
|
+
#stop() {
|
|
151
|
+
++this.#generation;
|
|
152
|
+
this.#observer?.disconnect(); this.#observer = null;
|
|
153
|
+
if (this.#socket) { this.#socket.close(1000); this.#socket = null; this.#write('connected', false); }
|
|
154
|
+
this.#terminal?.dispose(); this.#terminal = null; this.#fit = null;
|
|
155
|
+
this.#session = null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
@@ -3,12 +3,11 @@ import {Bag} from '@gramlot/gramlot';
|
|
|
3
3
|
import {defineComponent} from './registry.js';
|
|
4
4
|
import {Container} from './container.js';
|
|
5
5
|
import {SVG_NS} from '../renderer/attributes.js';
|
|
6
|
-
import {randomId} from '../random-id.js';
|
|
7
6
|
import {corners, overlaps, contactFraction} from './tray-geometry.js';
|
|
8
7
|
import {createTraySettings} from './tray-settings.js';
|
|
9
8
|
|
|
10
9
|
export const TrayPane = defineComponent({
|
|
11
|
-
name: 'trayPane', tag: 'gramlot-tray-pane', base: Container, subTags: '*',
|
|
10
|
+
name: 'trayPane', tag: 'gramlot-tray-pane', base: Container, subTags: '*', sourceContext: true,
|
|
12
11
|
parameters: {storepath: {dtype: 'T'}, locked: {dtype:'B',default:false,binding:'read'},
|
|
13
12
|
gridStep:{dtype:'L',default:10,binding:'read'},gridVisible:{dtype:'B',default:false,binding:'read'},
|
|
14
13
|
rotationStep:{dtype:'N',default:15,binding:'read'}},
|
|
@@ -80,9 +79,10 @@ export const TrayPane = defineComponent({
|
|
|
80
79
|
return {...rest, box_position: 'absolute',
|
|
81
80
|
...(rest.lbl_variant == null ? {lbl_variant: 'card'} : {})};
|
|
82
81
|
}
|
|
83
|
-
#
|
|
82
|
+
#context;
|
|
83
|
+
// The router registration on the storepath address: the geometry events reach the tray by path.
|
|
84
|
+
#geometry = null;
|
|
84
85
|
#settings=new Set();
|
|
85
|
-
#subscription = `tray-${randomId()}`;
|
|
86
86
|
#events;
|
|
87
87
|
#scheduled = false;
|
|
88
88
|
#drag;
|
|
@@ -105,24 +105,19 @@ export const TrayPane = defineComponent({
|
|
|
105
105
|
this.style.setProperty('--tray-grid-size',`${this.parameters.gridStep}px`);
|
|
106
106
|
this.style.setProperty('--tray-grid-display',this.parameters.gridVisible&&this.parameters.gridStep>0?'block':'none');
|
|
107
107
|
if(this.parameters.locked)this.#finish();
|
|
108
|
+
if(this.isConnected)this.#observeGeometry();
|
|
108
109
|
this.#schedule();
|
|
109
110
|
return rest;
|
|
110
111
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
this.#store?.unsubscribe(this.#subscription,{any:true});
|
|
119
|
-
this.#store = bag;
|
|
120
|
-
if(this.isConnected)this.#observeGeometry();
|
|
121
|
-
}
|
|
122
|
-
this.#schedule();
|
|
112
|
+
setSourceContext(context) { this.#context = context; }
|
|
113
|
+
/** The geometry Bag, read at the storepath address at each use; the tray never keeps it. */
|
|
114
|
+
#storeBag() {
|
|
115
|
+
const store = this.#context.getStaticData(this.#context.attrDatapath('storepath'));
|
|
116
|
+
if (!(store instanceof Bag)) throw new TypeError('trayPane storepath must resolve to a Bag');
|
|
117
|
+
return store;
|
|
123
118
|
}
|
|
124
119
|
connectedCallback() {
|
|
125
|
-
|
|
120
|
+
this.#observeGeometry();
|
|
126
121
|
this.#events = new this.ownerDocument.defaultView.AbortController();
|
|
127
122
|
const options = {signal:this.#events.signal};
|
|
128
123
|
this.shadowRoot.querySelector('slot').addEventListener('slotchange', () => this.#schedule(), options);
|
|
@@ -156,7 +151,7 @@ export const TrayPane = defineComponent({
|
|
|
156
151
|
box.labelbox.traySettings.remove();
|
|
157
152
|
this.#settings.delete(box.labelbox.traySettings);
|
|
158
153
|
block.remove();
|
|
159
|
-
if(
|
|
154
|
+
const store=this.#storeBag();if(store.getNode(block.label))store.popNode(block.label);
|
|
160
155
|
return;
|
|
161
156
|
}
|
|
162
157
|
const settings=box.labelbox.traySettings;
|
|
@@ -168,39 +163,52 @@ export const TrayPane = defineComponent({
|
|
|
168
163
|
disconnectedCallback() {
|
|
169
164
|
for(const settings of this.#settings)settings.remove();
|
|
170
165
|
this.#finish(); this.#events.abort();
|
|
171
|
-
this.#
|
|
166
|
+
this.#geometry?.close(); this.#geometry=null;
|
|
172
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Observe the geometry at the storepath address through a router registration. External
|
|
170
|
+
* geometry changes, a replacement of the Bag at the address and a new address end an
|
|
171
|
+
* in-progress gesture, without overwriting the new store. Own writes retain pointer capture.
|
|
172
|
+
*/
|
|
173
173
|
#observeGeometry() {
|
|
174
|
-
this.#
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
174
|
+
const path=this.#context.attrDatapath('storepath');
|
|
175
|
+
if(this.#geometry?.path===path)return;
|
|
176
|
+
if(this.#geometry){this.#finish();this.#geometry.close();}
|
|
177
|
+
this.#geometry=this.#context.sourceNode.rootBuilder.binding.router.register({path,subtree:true,
|
|
178
|
+
recipient:{receive:change=>this.#geometryChange(change)}});
|
|
179
|
+
}
|
|
180
|
+
#geometryChange(event) {
|
|
181
|
+
if(this.#writing)return;
|
|
182
|
+
if(event.node.label!=='selected'||this.#drag?.members||this.#drag?.marquee)this.#finish();
|
|
183
|
+
if(!['layer','rotation','scale'].includes(event.node.label) || !['upd_value','upd_value_attr'].includes(event.evt))return;
|
|
184
|
+
// The row of the event, by address: <storepath>.<row label>.<key>.
|
|
185
|
+
const prefix=`${this.#geometry.path}.`,suffix=`.${event.node.label}`;
|
|
186
|
+
if(!event.path.startsWith(prefix)||!event.path.endsWith(suffix))return;
|
|
187
|
+
const label=event.path.slice(prefix.length,-suffix.length);
|
|
188
|
+
const box=[...this.children].find(child=>TrayPane.#blocks.get(child).label===label);
|
|
189
|
+
if(!box)return;
|
|
190
|
+
const key=event.node.label,value=event.node.value;
|
|
191
|
+
let accepted=value;
|
|
192
|
+
if(key==='layer') {
|
|
193
|
+
if(!Number.isInteger(value) || this.#obstacles(box,value).some(other=>overlaps(this.#rectangle(box),other)))accepted=event.oldvalue;
|
|
194
|
+
} else if(typeof value!=='number'||!Number.isFinite(value)||(key==='scale'&&value<=0))accepted=event.oldvalue;
|
|
195
|
+
else {
|
|
196
|
+
const to=this.#rectangle(box),from={...to,[key]:event.oldvalue};
|
|
197
|
+
const fraction=contactFraction(from,to,this.#obstacles(box,event.node.parentBag.getItem('layer')),this.#bounds());
|
|
198
|
+
accepted=event.oldvalue+(value-event.oldvalue)*fraction;
|
|
199
|
+
}
|
|
200
|
+
if(accepted!==value) {
|
|
201
|
+
this.#writing=true;
|
|
202
|
+
try { event.node.setValue(accepted); } finally { this.#writing=false; }
|
|
203
|
+
}
|
|
204
|
+
this.#schedule();
|
|
197
205
|
}
|
|
198
206
|
#schedule() {
|
|
199
207
|
if (this.#scheduled) return;
|
|
200
208
|
this.#scheduled = true;
|
|
201
209
|
queueMicrotask(() => {
|
|
202
210
|
this.#scheduled = false;
|
|
203
|
-
if (!this.isConnected
|
|
211
|
+
if (!this.isConnected) return;
|
|
204
212
|
for(const settings of this.#settings)if(![...this.children].some(box=>box.labelbox.traySettings===settings)) {
|
|
205
213
|
settings.remove();this.#settings.delete(settings);
|
|
206
214
|
}
|
|
@@ -238,11 +246,11 @@ export const TrayPane = defineComponent({
|
|
|
238
246
|
});
|
|
239
247
|
}
|
|
240
248
|
#row(label) {
|
|
241
|
-
const
|
|
249
|
+
const store = this.#storeBag(), node = store.getNode([label]);
|
|
242
250
|
let row = node?.value;
|
|
243
251
|
if (!node) {
|
|
244
252
|
row = new Bag({left:0, top:0, layer:0, selected:false});
|
|
245
|
-
|
|
253
|
+
store.setItem([label], row);
|
|
246
254
|
}
|
|
247
255
|
if (!(row instanceof Bag)) throw new TypeError(`trayPane position '${label}' must be a Bag`);
|
|
248
256
|
if(!row.getNode('selected'))row.setItem('selected',false);
|
|
@@ -298,7 +306,7 @@ export const TrayPane = defineComponent({
|
|
|
298
306
|
if (!block) {
|
|
299
307
|
const rect=this.getBoundingClientRect(),overlay=this.ownerDocument.createElement('div');
|
|
300
308
|
overlay.className='tray-marquee';overlay.hidden=true;overlay.setAttribute('aria-hidden','true');
|
|
301
|
-
const marquee=[...this.children].map(child=>({box:child,
|
|
309
|
+
const marquee=[...this.children].map(child=>({box:child,label:TrayPane.#blocks.get(child).label,
|
|
302
310
|
selected:this.#row(TrayPane.#blocks.get(child).label).getItem('selected')}));
|
|
303
311
|
this.#drag={id:event.pointerId,marquee,overlay,extend:event.shiftKey,
|
|
304
312
|
x:event.clientX-rect.left-this.clientLeft,y:event.clientY-rect.top-this.clientTop};
|
|
@@ -316,8 +324,8 @@ export const TrayPane = defineComponent({
|
|
|
316
324
|
if(!rotate&&!resize&&!move)return;
|
|
317
325
|
const row = this.#row(block.label), rect = this.getBoundingClientRect();
|
|
318
326
|
const members=!rotate&&!resize ? [...this.children].filter(child=>child===box||this.#row(TrayPane.#blocks.get(child).label).getItem('selected'))
|
|
319
|
-
.map(child=>({box:child,
|
|
320
|
-
this.#drag = {box,
|
|
327
|
+
.map(child=>({box:child,label:TrayPane.#blocks.get(child).label,...this.#rectangle(child)})) : null;
|
|
328
|
+
this.#drag = {box, label:block.label, members, pendingSelection, extend:event.shiftKey, moved:false, id:event.pointerId, left:row.getItem('left'), top:row.getItem('top'),
|
|
321
329
|
resize, rotate, angle:row.getItem('rotation'), ...this.#rectangle(box),
|
|
322
330
|
x:event.clientX-rect.left, y:event.clientY-rect.top};
|
|
323
331
|
if(rotate)this.#drag.pointerAngle=Math.atan2(event.clientY-rect.top-this.clientTop-this.#drag.top-this.#drag.height/2,
|
|
@@ -335,6 +343,15 @@ export const TrayPane = defineComponent({
|
|
|
335
343
|
this.#write(row,{selected});
|
|
336
344
|
}
|
|
337
345
|
}
|
|
346
|
+
/**
|
|
347
|
+
* The rows of an in-progress gesture, read at their addresses in the store. Null when a
|
|
348
|
+
* row has left the store: the gesture ends instead of recreating it.
|
|
349
|
+
*/
|
|
350
|
+
#gestureRows(labels) {
|
|
351
|
+
const store=this.#storeBag();
|
|
352
|
+
if(!labels.every(label=>store.getNode([label])))return null;
|
|
353
|
+
return labels.map(label=>this.#row(label));
|
|
354
|
+
}
|
|
338
355
|
#write(row, values) {
|
|
339
356
|
this.#writing = true;
|
|
340
357
|
try {
|
|
@@ -348,6 +365,9 @@ export const TrayPane = defineComponent({
|
|
|
348
365
|
if (!drag || event.pointerId !== drag.id) return;
|
|
349
366
|
if(drag.marquee){this.#marqueeMove(event);return;}
|
|
350
367
|
if (drag.box.parentElement !== this||drag.members?.some(member=>member.box.parentElement!==this)) { this.#finish(); return; }
|
|
368
|
+
const rows=this.#gestureRows([drag.label,...(drag.members ?? []).map(member=>member.label)]);
|
|
369
|
+
if(!rows){this.#finish();return;}
|
|
370
|
+
const [row,...memberRows]=rows;
|
|
351
371
|
const rect = this.getBoundingClientRect();
|
|
352
372
|
const dx=event.clientX-rect.left-drag.x,dy=event.clientY-rect.top-drag.y;
|
|
353
373
|
if(drag.rotate){
|
|
@@ -358,12 +378,12 @@ export const TrayPane = defineComponent({
|
|
|
358
378
|
drag.pointerAngle=angle;
|
|
359
379
|
drag.angle+=delta;
|
|
360
380
|
const rotation=this.#snap(drag.angle,this.parameters.rotationStep,event.shiftKey);
|
|
361
|
-
this.#write(
|
|
381
|
+
this.#write(row,this.#constrain(drag.box,row,{rotation}));
|
|
362
382
|
this.#suppressClick=true;event.preventDefault();return;
|
|
363
383
|
}
|
|
364
384
|
if(drag.resize){
|
|
365
385
|
const angle=drag.rotation*Math.PI/180,c=Math.cos(angle),s=Math.sin(angle);
|
|
366
|
-
this.#resize(drag.box,
|
|
386
|
+
this.#resize(drag.box,row,
|
|
367
387
|
this.#snap(drag.width+(c*dx+s*dy)/drag.scale,this.parameters.gridStep,event.shiftKey),
|
|
368
388
|
this.#snap(drag.height+(-s*dx+c*dy)/drag.scale,this.parameters.gridStep,event.shiftKey),drag);
|
|
369
389
|
this.#suppressClick=true;event.preventDefault();return;
|
|
@@ -373,18 +393,18 @@ export const TrayPane = defineComponent({
|
|
|
373
393
|
const left=this.#snap(Math.round(drag.left+dx),this.parameters.gridStep,event.shiftKey),
|
|
374
394
|
top=this.#snap(Math.round(drag.top+dy),this.parameters.gridStep,event.shiftKey);
|
|
375
395
|
if (left !== drag.left || top !== drag.top) this.#suppressClick = true;
|
|
376
|
-
const delta={left:left-
|
|
396
|
+
const delta={left:left-row.getItem('left'),top:top-row.getItem('top')};
|
|
377
397
|
const moving=new Set(drag.members.map(member=>member.box));
|
|
378
398
|
let fraction=1;
|
|
379
|
-
for(const member of drag.members) {
|
|
399
|
+
for(const [index,member] of drag.members.entries()) {
|
|
380
400
|
const from=this.#rectangle(member.box),to={...from,left:from.left+delta.left,top:from.top+delta.top};
|
|
381
401
|
const obstacles=[...this.children].filter(other=>!moving.has(other)
|
|
382
|
-
&&this.#row(TrayPane.#blocks.get(other).label).getItem('layer')===
|
|
402
|
+
&&this.#row(TrayPane.#blocks.get(other).label).getItem('layer')===memberRows[index].getItem('layer'))
|
|
383
403
|
.map(other=>this.#rectangle(other));
|
|
384
404
|
fraction=Math.min(fraction,contactFraction(from,to,obstacles,this.#bounds()));
|
|
385
405
|
}
|
|
386
|
-
for(const
|
|
387
|
-
left:
|
|
406
|
+
for(const memberRow of memberRows)this.#write(memberRow,{
|
|
407
|
+
left:memberRow.getItem('left')+delta.left*fraction,top:memberRow.getItem('top')+delta.top*fraction});
|
|
388
408
|
event.preventDefault();
|
|
389
409
|
}
|
|
390
410
|
#marqueeMove(event) {
|
|
@@ -395,10 +415,12 @@ export const TrayPane = defineComponent({
|
|
|
395
415
|
const moved=right>left&&bottom>top;
|
|
396
416
|
Object.assign(drag.overlay.style,{left:`${left}px`,top:`${top}px`,width:`${right-left}px`,height:`${bottom-top}px`});
|
|
397
417
|
drag.overlay.hidden=!moved;
|
|
398
|
-
|
|
399
|
-
|
|
418
|
+
const members=drag.marquee.filter(member=>member.box.parentElement===this);
|
|
419
|
+
const rows=this.#gestureRows(members.map(member=>member.label));
|
|
420
|
+
if(!rows){this.#finish();return;}
|
|
421
|
+
for(const [index,member] of members.entries()) {
|
|
400
422
|
const inside=moved&&corners(this.#rectangle(member.box)).every(p=>p.x>=left&&p.x<=right&&p.y>=top&&p.y<=bottom);
|
|
401
|
-
this.#write(
|
|
423
|
+
this.#write(rows[index],{selected:inside||(drag.extend&&member.selected)});
|
|
402
424
|
}
|
|
403
425
|
this.#suppressClick ||= moved;event.preventDefault();
|
|
404
426
|
}
|
|
@@ -406,12 +428,14 @@ export const TrayPane = defineComponent({
|
|
|
406
428
|
#cancel() {
|
|
407
429
|
const drag = this.#drag;
|
|
408
430
|
if(drag.marquee) {
|
|
409
|
-
for(const member of drag.marquee)if(member.box.parentElement===this
|
|
431
|
+
for(const member of drag.marquee)if(member.box.parentElement===this&&this.#gestureRows([member.label]))
|
|
432
|
+
this.#write(this.#row(member.label),{selected:member.selected});
|
|
410
433
|
}
|
|
411
434
|
else if(drag.members)for(const member of drag.members) {
|
|
412
|
-
if(member.box.parentElement===this
|
|
435
|
+
if(member.box.parentElement===this&&this.#gestureRows([member.label]))
|
|
436
|
+
this.#write(this.#row(member.label),{left:member.left,top:member.top});
|
|
413
437
|
}
|
|
414
|
-
else if (drag.box.parentElement === this) this.#write(drag.
|
|
438
|
+
else if (drag.box.parentElement === this&&this.#gestureRows([drag.label])) this.#write(this.#row(drag.label),drag.rotate ? {rotation:drag.rotation} : drag.resize
|
|
415
439
|
? {left:drag.left,top:drag.top,width:drag.width,height:drag.height} : {left:drag.left,top:drag.top});
|
|
416
440
|
this.#suppressClick = false;
|
|
417
441
|
this.#finish();
|