@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.
Files changed (117) hide show
  1. package/dist/components/charts/__init__.py +1 -1
  2. package/dist/components/charts/assets/collection.js +9 -9
  3. package/dist/components/charts/assets/index.js +1 -1
  4. package/dist/components/charts/grammar.json +0 -30
  5. package/dist/components/drawing/__init__.py +1 -1
  6. package/dist/components/drawing/assets/collection.js +3 -3
  7. package/dist/components/drawing/assets/index.js +1 -1
  8. package/dist/components/editors/__init__.py +2 -2
  9. package/dist/components/editors/assets/collection.js +4 -2
  10. package/dist/components/editors/assets/index.js +1 -1
  11. package/dist/components/editors/assets/modules/addon-fit-L6JK4OJX.js +12 -0
  12. package/dist/components/editors/assets/modules/xterm-BF3OSWRI.js +286 -0
  13. package/dist/components/editors/assets/modules/xterm-UBEXZEYY.js +47 -0
  14. package/dist/components/editors/grammar.json +207 -0
  15. package/dist/components/grid/__init__.py +1 -1
  16. package/dist/components/grid/assets/collection.js +6 -6
  17. package/dist/components/grid/assets/index.js +1 -1
  18. package/dist/components/grid/grammar.json +0 -2
  19. package/dist/components/inputs/__init__.py +1 -1
  20. package/dist/components/inputs/assets/collection.js +8 -8
  21. package/dist/components/inputs/assets/index.js +1 -1
  22. package/dist/components/inputs/grammar.json +2 -1
  23. package/dist/components/layout/__init__.py +1 -1
  24. package/dist/components/layout/assets/collection.js +9 -9
  25. package/dist/components/layout/assets/index.js +1 -1
  26. package/dist/components/layout/grammar.json +2 -2
  27. package/dist/components/selection_trial/__init__.py +1 -1
  28. package/dist/components/selection_trial/assets/collection.js +3 -3
  29. package/dist/components/selection_trial/assets/index.js +1 -1
  30. package/dist/components/tree/__init__.py +1 -1
  31. package/dist/components/tree/assets/collection.js +6 -6
  32. package/dist/components/tree/assets/index.js +1 -1
  33. package/dist/components/tree/grammar.json +0 -1
  34. package/dist/components/uploads/__init__.py +1 -1
  35. package/dist/components/uploads/assets/collection.js +3 -3
  36. package/dist/components/uploads/assets/index.js +1 -1
  37. package/dist/components/uploads/grammar.json +0 -3
  38. package/dist/gramlot.js +1238 -627
  39. package/dist/gramlot.min.js +45 -45
  40. package/dist/libraries.json +27 -0
  41. package/dist/standard-collections.js +1 -1
  42. package/package.json +4 -3
  43. package/src/binding/data-binder.js +11 -3
  44. package/src/binding/grid-struct.js +7 -4
  45. package/src/binding/runtime.js +203 -46
  46. package/src/builder/binding.json +23 -1
  47. package/src/builder/gramlot-builder.d.ts +1 -4
  48. package/src/builder/source.js +185 -29
  49. package/src/chat.js +26 -20
  50. package/src/components/attachment-manager.js +38 -34
  51. package/src/components/chart-data-view.js +4 -7
  52. package/src/components/chart-fields.js +18 -6
  53. package/src/components/chart-renderer.js +10 -3
  54. package/src/components/chart-timeline.js +7 -5
  55. package/src/components/charts.js +74 -67
  56. package/src/components/check-box-text-editor.js +3 -3
  57. package/src/components/check-box-text.js +7 -22
  58. package/src/components/check-box-tree.js +20 -16
  59. package/src/components/choice-editor.js +1 -1
  60. package/src/components/drawing.js +47 -34
  61. package/src/components/editors.js +3 -1
  62. package/src/components/grid-cell-editor.js +72 -29
  63. package/src/components/grid-column-filters.js +47 -40
  64. package/src/components/grid-formulas.js +22 -17
  65. package/src/components/grid-header-interaction.js +9 -11
  66. package/src/components/grid-row-interaction.js +25 -24
  67. package/src/components/grid-row-layout.js +28 -29
  68. package/src/components/grid-search-box.js +3 -3
  69. package/src/components/grid-search.js +3 -8
  70. package/src/components/grid-selection.js +33 -29
  71. package/src/components/grid-structure.js +48 -10
  72. package/src/components/grid-tools.js +14 -14
  73. package/src/components/grid.js +83 -79
  74. package/src/components/image-crop-dialog.js +2 -2
  75. package/src/components/image-crop.js +16 -9
  76. package/src/components/image-uploader.js +21 -28
  77. package/src/components/inputs.js +19 -1
  78. package/src/components/registry.js +3 -5
  79. package/src/components/terminal.js +158 -0
  80. package/src/components/tray-pane.js +85 -61
  81. package/src/components/tree.js +332 -239
  82. package/src/components/upload-engine.js +10 -2
  83. package/src/components/uploader.js +31 -27
  84. package/src/editing-session.d.ts +4 -1
  85. package/src/editing-session.js +120 -83
  86. package/src/experiments/window-selection.js +4 -6
  87. package/src/filesystem.js +2 -2
  88. package/src/gramlot.js +1 -0
  89. package/src/handlers/device-handler.js +219 -213
  90. package/src/handlers/rpc-handler.d.ts +17 -0
  91. package/src/handlers/rpc-handler.js +22 -0
  92. package/src/ide-documents.js +29 -11
  93. package/src/ide-runtime.js +33 -31
  94. package/src/index-page-runtime.d.ts +2 -2
  95. package/src/index-page-runtime.js +67 -48
  96. package/src/libraries.js +9 -0
  97. package/src/message-port-connection.js +100 -0
  98. package/src/message-port-store.js +158 -0
  99. package/src/page-store-connection.js +14 -1
  100. package/src/renderer/gramlot-renderer.js +21 -2
  101. package/src/source-picker.d.ts +2 -2
  102. package/src/source-picker.js +15 -6
  103. package/src/stores/bag-collection-store.js +25 -7
  104. package/src/stores/bag-collection-view.js +23 -22
  105. package/src/view/controls.js +1 -1
  106. package/src/view/html.js +45 -20
  107. package/src/visual-editor-canvas.js +1 -1
  108. package/src/visual-editor.js +18 -19
  109. package/tools/gramlot-tools-inspector.js +400 -374
  110. package/tools/inspector-agent.js +223 -49
  111. package/dist/components/vizabi/__init__.py +0 -13
  112. package/dist/components/vizabi/assets/collection.js +0 -4
  113. package/dist/components/vizabi/assets/index.js +0 -3
  114. package/dist/components/vizabi/commands.json +0 -7
  115. package/dist/components/vizabi/grammar.json +0 -128
  116. package/src/components/vizabi-session.js +0 -66
  117. package/src/components/vizabi.js +0 -66
@@ -1,6 +1,9 @@
1
- /** Per-grid row geometry. BagNode identity survives sorting and filtering. */
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
- #store;
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
- #nodes = [];
24
+ #labels = [];
22
25
  #offsets = [0];
23
26
  #dirty = true;
24
27
  #estimate = 32;
25
- bindStore(store) {
26
- if (store !== this.#store) {
27
- this.#heights.clear(); this.resetMeasurements();
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 node of map.keys()) if (!current.has(node)) map.delete(node);
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(node) { return this.#heights.get(node) ?? null; }
39
- setHeight(node, height) {
40
- if (node.parentBag !== this.#store) return;
41
- if (height === null) this.#heights.delete(node);
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(node, Math.round(height));
42
+ this.#heights.set(label, Math.round(height));
45
43
  }
46
- this.forget(node);
44
+ this.forget(label);
47
45
  }
48
- setRows(nodes) { this.#nodes = nodes; this.#dirty = true; }
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(node) { this.#measured.delete(node); this.#dirty = true; }
51
- measure(node, height) {
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(node) === height) return false;
54
- this.#measured.set(node, height);
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 [node, height] of this.#measured) if (!this.#heights.has(node)) natural = Math.min(natural, height);
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 node of this.#nodes) this.#offsets.push(this.#offsets.at(-1) +
67
- (this.#measured.get(node) ?? Math.max(this.#heights.get(node) ?? 0, this.#estimate)));
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.#nodes.length) return this.#window.start * this.#estimate + this.#offsets[local];
76
- return index * this.#estimate + this.#offsets.at(-1) - this.#nodes.length * this.#estimate;
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.#nodes.length; }
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; #bag;
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 || this.#bag !== this.#grid.view.bag || !this.#releaseView) {
105
- this.#cancel(); this.#releaseView?.(); this.#view = this.#grid.view; this.#bag = this.#view.bag;
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.#bag === view.bag && this.columns === columns) return;
9
- this.view = view; this.#bag = view.bag; this.columns = columns;
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
- if (!Object.hasOwn(node, 'gridSearch')) {
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`. Selected rows are
11
- * the visible rows of the view: a row leaving the view (filter, deletion) leaves the selection;
12
- * sorting keeps it.
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(node) { return this.#selected.has(node); }
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 `node`: `toggle` (Ctrl/Cmd) and `range` (Shift) apply in multi mode. */
35
- select(node, {toggle = false, range = false} = {}) {
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 rows = this.#host.view().getRows();
38
- if (this.mode === 'multi' && range && this.#anchor !== null && rows.includes(this.#anchor)) {
39
- const [from, to] = [rows.indexOf(this.#anchor), rows.indexOf(node)].sort((a, b) => a - b);
40
- this.#apply(new Set(rows.slice(from, to + 1)), node, this.#anchor);
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(node)) selected.delete(node); else selected.add(node);
44
- this.#apply(selected, selected.has(node) ? node : this.nodes.find(row => selected.has(row)) ?? null, node);
45
- } else this.#apply(new Set([node]), node, node);
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 rows = this.#host.view().getRows();
52
- if (!rows.length) return null;
53
- const index = this.#current === null ? (step > 0 ? -1 : rows.length) : rows.indexOf(this.#current);
54
- const next = rows[Math.max(0, Math.min(rows.length - 1, index + step))];
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 rows = this.#host.view().getRows();
63
- this.#apply(new Set(rows), this.#current ?? rows[0] ?? null, this.#anchor ?? rows[0] ?? null);
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(node => visible.has(node)) && (this.#current === null || visible.has(this.#current))) return;
71
- const selected = new Set([...this.#selected].filter(node => visible.has(node)));
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(), view = this.#host.view(), nodes = this.nodes, current = this.#current;
96
- const idx = current === null ? -1 : view.getRows().indexOf(current);
97
- const selectedId = current === null ? null : current.label;
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
- /** Legacy Data contract: ordered cells and independent columnset definitions. */
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
- #nodes = new Map();
13
- constructor(bag) {
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.#nodes.set(attrs.field, node);
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
- columnNode(field) { return this.#nodes.get(field); }
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 node = this.#nodes.get(field), target = this.#nodes.get(targetField);
84
- if (!node || !target || node === target) return;
85
- const bag = node.parentBag, nodes = bag.getNodes();
86
- const from = nodes.indexOf(node), targetIndex = nodes.indexOf(target);
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.#nodes.get(field).setAttr({width: `${Math.round(width)}px`});
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()` ({bag, mode}), `selected()` (selected rows in view order), `selectionMode()`,
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
- /** Append one row with `defaults` to the store Bag; an editing session records it as a change. */
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 {bag, mode} = this.#host.store();
191
- const label = `r_${crypto.randomUUID().replaceAll('-', '')}`;
192
- if (mode === 'values') bag.setItem(label, new Bag(defaults));
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 {bag, mode} = this.#host.store();
200
+ const values = this.#host.store().mode === 'values';
200
201
  for (const node of this.#host.selected()) {
201
- const label = `r_${crypto.randomUUID().replaceAll('-', '')}`;
202
- if (mode === 'values') bag.setItem(label, node.staticValue.deepcopy());
203
- else bag.setItem(label, null, {...node.getAttr()});
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 from the store Bag; an editing session records each removal. */
208
+ /** Remove the selected rows at their paths in the store; an editing session records each removal. */
208
209
  deleteRows() {
209
- const {bag} = this.#host.store();
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. */