@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
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Per-grid row geometry. A row is identified by its key (node label): heights survive sorting,
|
|
3
|
+
* filtering and a replacement of the Bag at the store path for the rows still present.
|
|
4
|
+
*/
|
|
2
5
|
export class GridRowLayout {
|
|
3
|
-
#
|
|
6
|
+
#present = new Set();
|
|
4
7
|
#window = null;
|
|
5
8
|
setWindow(info) {
|
|
6
9
|
if (info !== null && (!Number.isSafeInteger(info.start) || info.start < 0
|
|
@@ -18,40 +21,36 @@ export class GridRowLayout {
|
|
|
18
21
|
}
|
|
19
22
|
#heights = new Map();
|
|
20
23
|
#measured = new Map();
|
|
21
|
-
#
|
|
24
|
+
#labels = [];
|
|
22
25
|
#offsets = [0];
|
|
23
26
|
#dirty = true;
|
|
24
27
|
#estimate = 32;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.#store = store;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
retain(nodes) {
|
|
32
|
-
const current = new Set(nodes);
|
|
28
|
+
/** Keep the geometry of the resident row keys `labels` only. */
|
|
29
|
+
retain(labels) {
|
|
30
|
+
this.#present = new Set(labels);
|
|
33
31
|
for (const map of [this.#heights, this.#measured]) {
|
|
34
|
-
for (const
|
|
32
|
+
for (const label of map.keys()) if (!this.#present.has(label)) map.delete(label);
|
|
35
33
|
}
|
|
36
34
|
this.#dirty = true;
|
|
37
35
|
}
|
|
38
|
-
height(
|
|
39
|
-
setHeight(
|
|
40
|
-
if (
|
|
41
|
-
if (height === null) this.#heights.delete(
|
|
36
|
+
height(label) { return this.#heights.get(label) ?? null; }
|
|
37
|
+
setHeight(label, height) {
|
|
38
|
+
if (!this.#present.has(label)) return;
|
|
39
|
+
if (height === null) this.#heights.delete(label);
|
|
42
40
|
else {
|
|
43
41
|
if (!Number.isFinite(height) || height <= 0) throw new TypeError('Grid row height must be positive pixels');
|
|
44
|
-
this.#heights.set(
|
|
42
|
+
this.#heights.set(label, Math.round(height));
|
|
45
43
|
}
|
|
46
|
-
this.forget(
|
|
44
|
+
this.forget(label);
|
|
47
45
|
}
|
|
48
|
-
|
|
46
|
+
/** The row keys of the view, in view order. */
|
|
47
|
+
setRows(labels) { this.#labels = [...labels]; this.#dirty = true; }
|
|
49
48
|
resetMeasurements() { this.#measured.clear(); this.#dirty = true; }
|
|
50
|
-
forget(
|
|
51
|
-
measure(
|
|
49
|
+
forget(label) { this.#measured.delete(label); this.#dirty = true; }
|
|
50
|
+
measure(label, height) {
|
|
52
51
|
// Hidden/unlaid-out rows have no usable measurement yet.
|
|
53
|
-
if (height <= 0 || this.#measured.get(
|
|
54
|
-
this.#measured.set(
|
|
52
|
+
if (height <= 0 || this.#measured.get(label) === height) return false;
|
|
53
|
+
this.#measured.set(label, height);
|
|
55
54
|
this.#dirty = true;
|
|
56
55
|
return true;
|
|
57
56
|
}
|
|
@@ -60,11 +59,11 @@ export class GridRowLayout {
|
|
|
60
59
|
// The smallest observed natural row gives a theme-derived estimate for
|
|
61
60
|
// unseen rows. Explicit heights and measured wrapped rows take priority.
|
|
62
61
|
let natural = Infinity;
|
|
63
|
-
for (const [
|
|
62
|
+
for (const [label, height] of this.#measured) if (!this.#heights.has(label)) natural = Math.min(natural, height);
|
|
64
63
|
if (natural !== Infinity) this.#estimate = natural;
|
|
65
64
|
this.#offsets = [0];
|
|
66
|
-
for (const
|
|
67
|
-
(this.#measured.get(
|
|
65
|
+
for (const label of this.#labels) this.#offsets.push(this.#offsets.at(-1) +
|
|
66
|
+
(this.#measured.get(label) ?? Math.max(this.#heights.get(label) ?? 0, this.#estimate)));
|
|
68
67
|
this.#dirty = false;
|
|
69
68
|
}
|
|
70
69
|
offset(index) {
|
|
@@ -72,10 +71,10 @@ export class GridRowLayout {
|
|
|
72
71
|
if (!this.#window) return this.#offsets[index];
|
|
73
72
|
const local = index - this.#window.start;
|
|
74
73
|
if (local <= 0) return index * this.#estimate;
|
|
75
|
-
if (local <= this.#
|
|
76
|
-
return index * this.#estimate + this.#offsets.at(-1) - this.#
|
|
74
|
+
if (local <= this.#labels.length) return this.#window.start * this.#estimate + this.#offsets[local];
|
|
75
|
+
return index * this.#estimate + this.#offsets.at(-1) - this.#labels.length * this.#estimate;
|
|
77
76
|
}
|
|
78
|
-
get count() { return this.#window?.total ?? this.#
|
|
77
|
+
get count() { return this.#window?.total ?? this.#labels.length; }
|
|
79
78
|
get totalHeight() { return this.offset(this.count); }
|
|
80
79
|
indexAt(position) {
|
|
81
80
|
this.#index();
|
|
@@ -13,7 +13,7 @@ export const SearchBox = defineComponent({
|
|
|
13
13
|
searchTime:{dtype:'R', nullable:true, default:null, binding:'write'}},
|
|
14
14
|
implementation:Base => class extends Base {
|
|
15
15
|
#context; #grid; #release; #releaseView; #view; #timer = null;
|
|
16
|
-
#input; #error; #info; #help; #helpText; #filterSignature;
|
|
16
|
+
#input; #error; #info; #help; #helpText; #filterSignature;
|
|
17
17
|
constructor() {
|
|
18
18
|
super();
|
|
19
19
|
const doc = this.ownerDocument;
|
|
@@ -101,8 +101,8 @@ export const SearchBox = defineComponent({
|
|
|
101
101
|
}
|
|
102
102
|
#update() {
|
|
103
103
|
if (!this.#grid.view) return;
|
|
104
|
-
if (this.#view !== this.#grid.view ||
|
|
105
|
-
this.#cancel(); this.#releaseView?.(); this.#view = this.#grid.view;
|
|
104
|
+
if (this.#view !== this.#grid.view || !this.#releaseView) {
|
|
105
|
+
this.#cancel(); this.#releaseView?.(); this.#view = this.#grid.view;
|
|
106
106
|
this.#filterSignature = undefined;
|
|
107
107
|
this.#releaseView = this.#view.subscribe(() => this.#sync());
|
|
108
108
|
}
|
|
@@ -2,17 +2,15 @@
|
|
|
2
2
|
export class GridSearch {
|
|
3
3
|
#listeners = new Set();
|
|
4
4
|
view = null;
|
|
5
|
-
#bag;
|
|
6
5
|
columns = [];
|
|
7
6
|
update(view, columns) {
|
|
8
|
-
if (this.view === view && this
|
|
9
|
-
this.view = view; this
|
|
7
|
+
if (this.view === view && this.columns === columns) return;
|
|
8
|
+
this.view = view; this.columns = columns;
|
|
10
9
|
for (const listener of this.#listeners) listener();
|
|
11
10
|
}
|
|
12
11
|
detach(view) {
|
|
13
12
|
if (this.view !== view) return;
|
|
14
13
|
this.view = null;
|
|
15
|
-
this.#bag = null;
|
|
16
14
|
this.columns = [];
|
|
17
15
|
for (const listener of this.#listeners) listener();
|
|
18
16
|
}
|
|
@@ -20,10 +18,7 @@ export class GridSearch {
|
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
export function gridSearch(node) {
|
|
23
|
-
|
|
24
|
-
Object.defineProperty(node, 'gridSearch', {value:new GridSearch(), configurable:true});
|
|
25
|
-
}
|
|
26
|
-
return node.gridSearch;
|
|
21
|
+
return node._internal.gridSearch ??= new GridSearch();
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
export function searchColumns(searchOn, columns) {
|
|
@@ -7,9 +7,10 @@ const PUBLISHED = ['selectedId', 'selectedIndex', 'selectedLabel', 'selectedPkey
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Row selection of one grid (legacy genro_grid.js selection publication). The identity of a row is
|
|
10
|
-
* its node label in both row modes, as the legacy Bag store identifier `nodelabel
|
|
11
|
-
* the visible rows of the view: a row
|
|
12
|
-
* sorting
|
|
10
|
+
* its key (node label) in both row modes, as the legacy Bag store identifier `nodelabel`: the
|
|
11
|
+
* selection keeps only keys, never row nodes. Selected rows are the visible rows of the view: a row
|
|
12
|
+
* leaving the view (filter, deletion) leaves the selection; sorting and a replacement of the Bag at
|
|
13
|
+
* the store path keep the keys still visible.
|
|
13
14
|
*/
|
|
14
15
|
export class GridSelection {
|
|
15
16
|
#context;
|
|
@@ -26,32 +27,33 @@ export class GridSelection {
|
|
|
26
27
|
|
|
27
28
|
get source() { return this.#context.sourceNode; }
|
|
28
29
|
get mode() { return this.#host.mode(); }
|
|
30
|
+
/** The key of the current row, or null. */
|
|
29
31
|
get current() { return this.#current; }
|
|
30
|
-
isSelected(
|
|
32
|
+
isSelected(label) { return this.#selected.has(label); }
|
|
31
33
|
/** Selected rows in view order. */
|
|
32
|
-
get nodes() { return this.#host.view().getRows().filter(node => this.#selected.has(node)); }
|
|
34
|
+
get nodes() { return this.#host.view().getRows().filter(node => this.#selected.has(node.label)); }
|
|
33
35
|
|
|
34
|
-
/** Click or keyboard selection of `
|
|
35
|
-
select(
|
|
36
|
+
/** Click or keyboard selection of the row of key `label`: `toggle` (Ctrl/Cmd) and `range` (Shift) apply in multi mode. */
|
|
37
|
+
select(label, {toggle = false, range = false} = {}) {
|
|
36
38
|
if (this.mode === 'none') return;
|
|
37
|
-
const
|
|
38
|
-
if (this.mode === 'multi' && range && this.#anchor !== null &&
|
|
39
|
-
const [from, to] = [
|
|
40
|
-
this.#apply(new Set(
|
|
39
|
+
const labels = this.#host.view().getRows().map(row => row.label);
|
|
40
|
+
if (this.mode === 'multi' && range && this.#anchor !== null && labels.includes(this.#anchor)) {
|
|
41
|
+
const [from, to] = [labels.indexOf(this.#anchor), labels.indexOf(label)].sort((a, b) => a - b);
|
|
42
|
+
this.#apply(new Set(labels.slice(from, to + 1)), label, this.#anchor);
|
|
41
43
|
} else if (this.mode === 'multi' && toggle) {
|
|
42
44
|
const selected = new Set(this.#selected);
|
|
43
|
-
if (selected.has(
|
|
44
|
-
this.#apply(selected, selected.has(
|
|
45
|
-
} else this.#apply(new Set([
|
|
45
|
+
if (selected.has(label)) selected.delete(label); else selected.add(label);
|
|
46
|
+
this.#apply(selected, selected.has(label) ? label : labels.find(key => selected.has(key)) ?? null, label);
|
|
47
|
+
} else this.#apply(new Set([label]), label, label);
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
/** Up/Down: move the current row by `step`; `extend` (Shift, multi mode) extends from the anchor. */
|
|
50
|
+
/** Up/Down: move the current row by `step`; `extend` (Shift, multi mode) extends from the anchor. Gives the key of the new current row. */
|
|
49
51
|
move(step, extend = false) {
|
|
50
52
|
if (this.mode === 'none') return null;
|
|
51
|
-
const
|
|
52
|
-
if (!
|
|
53
|
-
const index = this.#current === null ? (step > 0 ? -1 :
|
|
54
|
-
const next =
|
|
53
|
+
const labels = this.#host.view().getRows().map(row => row.label);
|
|
54
|
+
if (!labels.length) return null;
|
|
55
|
+
const index = this.#current === null ? (step > 0 ? -1 : labels.length) : labels.indexOf(this.#current);
|
|
56
|
+
const next = labels[Math.max(0, Math.min(labels.length - 1, index + step))];
|
|
55
57
|
this.select(next, {range:extend});
|
|
56
58
|
return next;
|
|
57
59
|
}
|
|
@@ -59,16 +61,16 @@ export class GridSelection {
|
|
|
59
61
|
/** Ctrl/Cmd+A in multi mode: every visible row. */
|
|
60
62
|
selectAll() {
|
|
61
63
|
if (this.mode !== 'multi') return;
|
|
62
|
-
const
|
|
63
|
-
this.#apply(new Set(
|
|
64
|
+
const labels = this.#host.view().getRows().map(row => row.label);
|
|
65
|
+
this.#apply(new Set(labels), this.#current ?? labels[0] ?? null, this.#anchor ?? labels[0] ?? null);
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
/** Keep only visible rows (after a filter, deletion or store replacement); publishes when it changes. */
|
|
67
69
|
prune() {
|
|
68
70
|
// selectionMode 'none' keeps no selection.
|
|
69
|
-
const visible = new Set(this.mode === 'none' ? [] : this.#host.view().getRows());
|
|
70
|
-
if ([...this.#selected].every(
|
|
71
|
-
const selected = new Set([...this.#selected].filter(
|
|
71
|
+
const visible = new Set(this.mode === 'none' ? [] : this.#host.view().getRows().map(row => row.label));
|
|
72
|
+
if ([...this.#selected].every(label => visible.has(label)) && (this.#current === null || visible.has(this.#current))) return;
|
|
73
|
+
const selected = new Set([...this.#selected].filter(label => visible.has(label)));
|
|
72
74
|
this.#apply(selected, visible.has(this.#current) ? this.#current : null, visible.has(this.#anchor) ? this.#anchor : null);
|
|
73
75
|
}
|
|
74
76
|
|
|
@@ -92,14 +94,16 @@ export class GridSelection {
|
|
|
92
94
|
|
|
93
95
|
/** Publish the selection to the declared Data paths, `.selectionLength` (with a datapath context) and `onSelectedRow`. */
|
|
94
96
|
publish() {
|
|
95
|
-
const store = this.#host.store(),
|
|
96
|
-
const
|
|
97
|
-
const
|
|
97
|
+
const store = this.#host.store(), rows = this.#host.view().getRows();
|
|
98
|
+
const nodes = rows.filter(node => this.#selected.has(node.label));
|
|
99
|
+
const idx = this.#current === null ? -1 : rows.findIndex(node => node.label === this.#current);
|
|
100
|
+
const current = idx < 0 ? null : rows[idx];
|
|
101
|
+
const selectedId = this.#current;
|
|
98
102
|
const selectedPkeys = nodes.map(node => node.label);
|
|
99
|
-
const resident = store.getRows();
|
|
103
|
+
const resident = store.getRows().map(node => node.label);
|
|
100
104
|
const values = {
|
|
101
105
|
selectedId, selectedIndex:idx < 0 ? null : idx, selectedLabel:selectedId, selectedPkeys,
|
|
102
|
-
selectedRowidx:nodes.map(node => resident.indexOf(node)).join(','),
|
|
106
|
+
selectedRowidx:nodes.map(node => resident.indexOf(node.label)).join(','),
|
|
103
107
|
selectedNodes:() => {
|
|
104
108
|
const bag = new Bag();
|
|
105
109
|
for (const node of nodes) bag.setItem(node.label, null, this.#host.rowData(node));
|
|
@@ -7,10 +7,32 @@ const COLUMN_KEYS = new Set(['tag', 'field', 'name', 'title', 'dtype', 'width',
|
|
|
7
7
|
const FORMULA_PARAMETER = /^formula_[A-Za-z_$][\w$]*$/;
|
|
8
8
|
const GROUP_KEYS = new Set(['tag', 'code', 'name', 'background', 'color']);
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* A Bag among the editor options of `edit` is used as is only when it is independent: a Bag with a parent
|
|
12
|
+
* is a sub Bag of other data, which a column reaches by its path (`storepath` or a `^` pointer), never by
|
|
13
|
+
* holding it. Plain objects and arrays among the options are checked through, Bags are not entered.
|
|
14
|
+
*/
|
|
15
|
+
function requireIndependentBags(value, key) {
|
|
16
|
+
if (value instanceof Bag) {
|
|
17
|
+
if (value.parent || value.parentNode) throw new TypeError(`grid edit option ${key} holds a Bag with a parent; pass its path (storepath or a ^ pointer) instead`);
|
|
18
|
+
} else if (Array.isArray(value)) value.forEach((item, index) => requireIndependentBags(item, `${key}[${index}]`));
|
|
19
|
+
else if (value !== null && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype) {
|
|
20
|
+
for (const [name, item] of Object.entries(value)) requireIndependentBags(item, `${key}.${name}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Legacy Data contract: ordered cells and independent columnset definitions. The model keeps plain
|
|
26
|
+
* values and the cell key (label) of each field, never struct nodes; with its Data address
|
|
27
|
+
* (`data`, the page Data root, and `path`, the absolute struct path) it writes the struct by path.
|
|
28
|
+
*/
|
|
11
29
|
export class GridStructure {
|
|
12
|
-
#
|
|
13
|
-
|
|
30
|
+
#labels = new Map();
|
|
31
|
+
#data;
|
|
32
|
+
#path;
|
|
33
|
+
constructor(bag, {data = null, path = null} = {}) {
|
|
34
|
+
this.#data = data;
|
|
35
|
+
this.#path = path;
|
|
14
36
|
if (!(bag instanceof Bag)) throw new TypeError('grid structpath must resolve to a Bag');
|
|
15
37
|
const view = branch(bag, 'view_0'), info = branch(bag, 'info');
|
|
16
38
|
const cells = branch(view, 'rows_0'), definitions = branch(info, 'columnsets');
|
|
@@ -36,7 +58,7 @@ export class GridStructure {
|
|
|
36
58
|
if (attrs.tag !== 'cell' || node.staticValue != null || node.resolver) throw new TypeError('grid cell must be a scalar declaration');
|
|
37
59
|
requireIdentity(attrs.field, 'field');
|
|
38
60
|
if (fields.has(attrs.field)) throw new TypeError(`Duplicate grid field: ${attrs.field}`);
|
|
39
|
-
fields.add(attrs.field); this.#
|
|
61
|
+
fields.add(attrs.field); this.#labels.set(attrs.field, node.label);
|
|
40
62
|
if (attrs.columnset != null && !groups.has(attrs.columnset)) throw new TypeError(`Unknown grid columnset: ${attrs.columnset}`);
|
|
41
63
|
if (attrs.dtype != null && !TYPES.has(attrs.dtype)) throw new TypeError(`Unsupported grid dtype: ${attrs.dtype}`);
|
|
42
64
|
if (attrs.align != null && !['start', 'center', 'end'].includes(attrs.align)) throw new TypeError('grid align requires start, center or end');
|
|
@@ -49,6 +71,7 @@ export class GridStructure {
|
|
|
49
71
|
if (attrs.white_space != null && !['normal','nowrap','pre-wrap'].includes(attrs.white_space)) throw new TypeError('grid white_space requires normal, nowrap or pre-wrap');
|
|
50
72
|
for (const key of ['name', 'title', 'format']) if (attrs[key] != null && typeof attrs[key] !== 'string') throw new TypeError(`grid ${key} must be text`);
|
|
51
73
|
if (attrs.edit != null && typeof attrs.edit !== 'boolean' && (typeof attrs.edit !== 'object' || Array.isArray(attrs.edit))) throw new TypeError('grid edit requires a boolean or editor options');
|
|
74
|
+
if (attrs.edit != null && typeof attrs.edit === 'object') for (const [key, value] of Object.entries(attrs.edit)) requireIndependentBags(value, key);
|
|
52
75
|
if (attrs.check != null || attrs.checked != null || attrs.checkedField != null) {
|
|
53
76
|
if (!['multiple','single'].includes(attrs.check) || typeof attrs.checked !== 'string' ||
|
|
54
77
|
!attrs.checked.startsWith('^') || attrs.checked.length < 2 || attrs.checked.includes('?')) {
|
|
@@ -78,18 +101,33 @@ export class GridStructure {
|
|
|
78
101
|
for (const group of this.groups) { Object.freeze(group.columns); Object.freeze(group); }
|
|
79
102
|
Object.freeze(this.columns); Object.freeze(this.groups); Object.freeze(this);
|
|
80
103
|
}
|
|
81
|
-
|
|
104
|
+
/** The cells Bag at the struct address, read at each use. */
|
|
105
|
+
#cells() {
|
|
106
|
+
if (this.#data === null || this.#path === null) throw new TypeError('grid structure without a Data address cannot be read or written');
|
|
107
|
+
const bag = this.#data.getItem(this.#path, null, true);
|
|
108
|
+
if (!(bag instanceof Bag)) throw new TypeError('grid structpath must resolve to a Bag');
|
|
109
|
+
return branch(branch(bag, 'view_0'), 'rows_0');
|
|
110
|
+
}
|
|
111
|
+
/** The width written in the struct for `field`, read at its address. */
|
|
112
|
+
columnWidth(field) { return this.#cells().getNode(this.#labels.get(field))?.getAttr('width'); }
|
|
113
|
+
/** The field of the cell `step` places after (negative: before) the cell of `field`, or null. */
|
|
114
|
+
adjacentField(field, step) {
|
|
115
|
+
const nodes = this.#cells().getNodes();
|
|
116
|
+
const target = nodes[nodes.findIndex(node => node.label === this.#labels.get(field)) + step];
|
|
117
|
+
return target?.getAttr('tag') === 'cell' ? target.getAttr('field') : null;
|
|
118
|
+
}
|
|
82
119
|
moveColumn(field, targetField, after = false) {
|
|
83
|
-
const
|
|
84
|
-
if (
|
|
85
|
-
const bag =
|
|
86
|
-
const from =
|
|
120
|
+
const label = this.#labels.get(field), targetLabel = this.#labels.get(targetField);
|
|
121
|
+
if (label === undefined || targetLabel === undefined || label === targetLabel) return;
|
|
122
|
+
const bag = this.#cells(), labels = bag.keys();
|
|
123
|
+
const from = labels.indexOf(label), targetIndex = labels.indexOf(targetLabel);
|
|
124
|
+
if (from < 0 || targetIndex < 0) return;
|
|
87
125
|
const position = targetIndex + Number(after) - Number(from < targetIndex);
|
|
88
126
|
if (position !== from) bag.move(from, position);
|
|
89
127
|
}
|
|
90
128
|
setColumnWidth(field, width) {
|
|
91
129
|
if (!Number.isFinite(width) || width <= 0) throw new TypeError('grid resized width must be positive pixels');
|
|
92
|
-
this.#
|
|
130
|
+
this.#cells().getNode(this.#labels.get(field)).setAttr({width: `${Math.round(width)}px`});
|
|
93
131
|
}
|
|
94
132
|
}
|
|
95
133
|
|
|
@@ -51,7 +51,7 @@ export class GridTools {
|
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* `host` gives `columns()`, `rows()` (visible, in view order), `reader()` (shown values),
|
|
54
|
-
* `store()` ({
|
|
54
|
+
* `store()` ({mode}), `selected()` (selected rows in view order), `selectionMode()`,
|
|
55
55
|
* `parameters()` and `document`.
|
|
56
56
|
*/
|
|
57
57
|
constructor(context, host) {
|
|
@@ -185,29 +185,29 @@ export class GridTools {
|
|
|
185
185
|
else this.source.setAttr({rowHeaders:value});
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
/**
|
|
188
|
+
/** The Data path of the row of key `label`: `#ROW` of the grid for that row. */
|
|
189
|
+
#rowPath(label) { return this.source.absDatapath('#ROW', {row:label}); }
|
|
190
|
+
|
|
191
|
+
/** Append one row with `defaults` at its path in the store; an editing session records it as a change. */
|
|
189
192
|
addRow(defaults) {
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
else bag.setItem(label, null, defaults);
|
|
194
|
-
return bag.getNode(label);
|
|
193
|
+
const path = this.#rowPath(`r_${crypto.randomUUID().replaceAll('-', '')}`);
|
|
194
|
+
if (this.#host.store().mode === 'values') this.source.data.setItem(path, new Bag(defaults));
|
|
195
|
+
else this.source.data.setItem(path, null, defaults);
|
|
195
196
|
}
|
|
196
197
|
|
|
197
198
|
/** Append a copy of each selected row, with a new identity. */
|
|
198
199
|
duplicateRows() {
|
|
199
|
-
const
|
|
200
|
+
const values = this.#host.store().mode === 'values';
|
|
200
201
|
for (const node of this.#host.selected()) {
|
|
201
|
-
const
|
|
202
|
-
if (
|
|
203
|
-
else
|
|
202
|
+
const path = this.#rowPath(`r_${crypto.randomUUID().replaceAll('-', '')}`);
|
|
203
|
+
if (values) this.source.data.setItem(path, node.staticValue.deepcopy());
|
|
204
|
+
else this.source.data.setItem(path, null, {...node.getAttr()});
|
|
204
205
|
}
|
|
205
206
|
}
|
|
206
207
|
|
|
207
|
-
/** Remove the selected rows
|
|
208
|
+
/** Remove the selected rows at their paths in the store; an editing session records each removal. */
|
|
208
209
|
deleteRows() {
|
|
209
|
-
const
|
|
210
|
-
for (const node of this.#host.selected()) bag.popNode(node.label);
|
|
210
|
+
for (const label of this.#host.selected().map(node => node.label)) this.source.data.popNode(this.#rowPath(label));
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
/** Edit tools declared in the grid's frame require an editable column; selection tools a selection mode. */
|