@gramlot/gramlot 0.3.36 → 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/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 +1205 -627
- package/dist/gramlot.min.js +45 -45
- package/dist/standard-collections.js +1 -1
- package/package.json +2 -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/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/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/message-port-connection.js +100 -0
- package/src/message-port-store.js +158 -0
- package/src/page-store-connection.js +6 -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 +40 -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,7 +1,15 @@
|
|
|
1
|
-
import {sourceTarget, toTytx} from '@gramlot/gramlot';
|
|
1
|
+
import {Bag, sourceTarget, toTytx} from '@gramlot/gramlot';
|
|
2
|
+
import {pointerTransform} from '@genrojs/builders';
|
|
2
3
|
|
|
3
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Grid navigation and temporary Source controls; all editing registers belong to the shared session.
|
|
6
|
+
* A row is its key (node label): the editor keeps keys and Data paths, never row nodes.
|
|
7
|
+
*/
|
|
4
8
|
export class GridCellEditor {
|
|
9
|
+
/**
|
|
10
|
+
* `cellFor(label, field)` gives the rendered cell; `store()` gives `{labels(), window}`;
|
|
11
|
+
* `renderedRows()` the rendered rows by key; `navigate(label, field, step)` opens a neighbour editor.
|
|
12
|
+
*/
|
|
5
13
|
constructor(grid, context, cellFor, store, renderedRows, navigate, focusField) {
|
|
6
14
|
this.grid = grid;
|
|
7
15
|
this.context = context;
|
|
@@ -23,7 +31,7 @@ export class GridCellEditor {
|
|
|
23
31
|
if (event.key === 'Escape') {
|
|
24
32
|
event.preventDefault();
|
|
25
33
|
const cell = this.cellFor(this.active.row,this.active.column.field);
|
|
26
|
-
this.session.clearDraft(this.active
|
|
34
|
+
this.session.clearDraft(this.control(this.active));
|
|
27
35
|
this.close(); cell?.focus({preventScroll:true});
|
|
28
36
|
} else if (event.key === 'Enter' || event.key === 'Tab') {
|
|
29
37
|
if (event.key === 'Enter' && this.active.element.control.localName === 'textarea' && !event.ctrlKey && !event.metaKey) return;
|
|
@@ -74,9 +82,9 @@ export class GridCellEditor {
|
|
|
74
82
|
this.grid.removeEventListener('keydown',this.arrowKeydown,true);
|
|
75
83
|
this.releaseNavigator?.(); this.releaseNavigator = null;
|
|
76
84
|
}
|
|
85
|
+
/** The Data path of `field` in the row of key `row`: `#ROW.<field>` of the grid for that row. */
|
|
77
86
|
path(row, field) {
|
|
78
|
-
|
|
79
|
-
return this.context.sourceNode.absDatapath(this.context.sourceNode.getAttr('storepath')) + '.' + row.label + (mode === 'attributes' ? '?' : '.') + field;
|
|
87
|
+
return this.context.sourceNode.absDatapath(`#ROW.${field}`, {row});
|
|
80
88
|
}
|
|
81
89
|
configure(columns) {
|
|
82
90
|
const editable = columns.filter(column => column.edit);
|
|
@@ -100,7 +108,7 @@ export class GridCellEditor {
|
|
|
100
108
|
if (this.active?.path === path) this.close();
|
|
101
109
|
this.releaseField(path);
|
|
102
110
|
} else {
|
|
103
|
-
declaration.
|
|
111
|
+
this.control(declaration).setAttr({...Object.fromEntries(Object.keys(declaration.options).map(key => [key,null])),...this.rowOptions(options,this.retained.get(path))});
|
|
104
112
|
declaration.options = options;
|
|
105
113
|
}
|
|
106
114
|
}
|
|
@@ -121,17 +129,33 @@ export class GridCellEditor {
|
|
|
121
129
|
delete options.tag;
|
|
122
130
|
return {tag,options:{...options,dtype:column.dtype ?? 'T'}};
|
|
123
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* The control options of `options` for the row of key `row`: an option holding a `=#ROW` or `^#ROW`
|
|
134
|
+
* pointer (`#ROW`, `#ROW.<field>`, `#ROW?<attr>`, `#ROW.<field>?<attr>`, with any `:` template or
|
|
135
|
+
* expression after it) keeps its prefix and tail, its path becomes the Data path of that row, as legacy
|
|
136
|
+
* GenroPy evaluated `#ROW` edit attributes against the edited row. The control has no row context.
|
|
137
|
+
*/
|
|
138
|
+
rowOptions(options, row) {
|
|
139
|
+
const owner = this.context.sourceNode;
|
|
140
|
+
return Object.fromEntries(Object.entries(options).map(([key,value]) => {
|
|
141
|
+
const pointer = pointerTransform(value)?.pointer ?? value, type = owner.pointerType(pointer);
|
|
142
|
+
const bare = type ? pointer.slice(1) : null;
|
|
143
|
+
if (bare !== '#ROW' && !bare?.startsWith('#ROW.') && !bare?.startsWith('#ROW?')) return [key,value];
|
|
144
|
+
return [key,`${type}${owner.absDatapath(pointer,{row})}${value.slice(pointer.length)}`];
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
124
147
|
*validationFields() {
|
|
125
148
|
const owner = this.context.sourceNode;
|
|
126
149
|
this.session.trackValidationDependency(owner.absDatapath(owner.getAttr('structpath')));
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
150
|
+
for (const row of this.store().labels()) for (const column of this.columns) {
|
|
151
|
+
// A row deleted while the validation pass runs has no field to declare.
|
|
152
|
+
const bag = this.collection();
|
|
153
|
+
if (!(bag instanceof Bag) || !bag.getNode(row)) continue;
|
|
130
154
|
const path = this.path(row,column.field);
|
|
131
155
|
this.checking.add(path);
|
|
132
156
|
try {
|
|
133
157
|
const declaration = this.declare(row,column,false);
|
|
134
|
-
yield {node:declaration
|
|
158
|
+
yield {node:this.control(declaration),release:() => {
|
|
135
159
|
this.checking.delete(path);
|
|
136
160
|
if (path !== this.active?.path) this.releaseCleanField(path);
|
|
137
161
|
}};
|
|
@@ -161,24 +185,36 @@ export class GridCellEditor {
|
|
|
161
185
|
// Unmount the branch before declaring a control: no editor element is constructed.
|
|
162
186
|
if (!mount) builder.binding.renderer.unmountView(sourceTarget(container));
|
|
163
187
|
try {
|
|
164
|
-
const control = container[tag]({...options, value:'^'+path, id, width:'100%', margin:'0'});
|
|
165
|
-
declaration = {
|
|
166
|
-
const component = this.grid.ownerDocument.defaultView.customElements.get(
|
|
167
|
-
this.session.registerField(
|
|
188
|
+
const control = sourceTarget(container[tag]({...this.rowOptions(options,row), value:'^'+path, id, width:'100%', margin:'0'}));
|
|
189
|
+
declaration = {id,tag,options,field:column.field};
|
|
190
|
+
const component = this.grid.ownerDocument.defaultView.customElements.get(control._getMeta('render_tag'));
|
|
191
|
+
this.session.registerField(control,component,mount);
|
|
168
192
|
this.declarations.set(path,declaration);
|
|
169
193
|
} catch (error) {
|
|
170
194
|
const node = sourceTarget(container); node.parentBag.popNode(node.label);
|
|
171
195
|
this.releaseCleanField(path);
|
|
172
196
|
throw error;
|
|
173
197
|
}
|
|
174
|
-
} else if (mount) owner.rootBuilder.binding.renderer.mountView(
|
|
198
|
+
} else if (mount) owner.rootBuilder.binding.renderer.mountView(this.container(declaration));
|
|
175
199
|
return declaration;
|
|
176
200
|
}
|
|
201
|
+
/** The editor container of `declaration`: the grid Source child labelled with its id, read at each call. */
|
|
202
|
+
container(declaration) {
|
|
203
|
+
const node = this.context.sourceNode.value.getNode(declaration.id);
|
|
204
|
+
if (!node) throw new Error(`Grid cell editor container ${declaration.id} is missing from the grid Source.`);
|
|
205
|
+
return node;
|
|
206
|
+
}
|
|
207
|
+
/** The editor control of `declaration`: the only child of its container. */
|
|
208
|
+
control(declaration) {
|
|
209
|
+
const nodes = this.container(declaration).value.getNodes();
|
|
210
|
+
if (nodes.length !== 1) throw new Error(`Grid cell editor container ${declaration.id} must hold exactly one control, found ${nodes.length}.`);
|
|
211
|
+
return nodes[0];
|
|
212
|
+
}
|
|
177
213
|
close() {
|
|
178
214
|
const active = this.active;
|
|
179
215
|
this.active = null; this.layer.hidden = true;
|
|
180
216
|
if (active) {
|
|
181
|
-
this.context.sourceNode.rootBuilder.binding.renderer.unmountView(
|
|
217
|
+
this.context.sourceNode.rootBuilder.binding.renderer.unmountView(this.container(active));
|
|
182
218
|
this.releaseCleanField(active.path);
|
|
183
219
|
}
|
|
184
220
|
}
|
|
@@ -192,7 +228,8 @@ export class GridCellEditor {
|
|
|
192
228
|
releaseField(path) {
|
|
193
229
|
const declaration = this.declarations.get(path);
|
|
194
230
|
this.declarations.delete(path);
|
|
195
|
-
|
|
231
|
+
// The container may already be gone with its grid Source branch; nothing is left to remove then.
|
|
232
|
+
if (declaration && this.context.sourceNode.value.getNode(declaration.id)) this.context.sourceNode.value.popNode(declaration.id);
|
|
196
233
|
this.session.releaseField(path); this.retained.delete(path);
|
|
197
234
|
}
|
|
198
235
|
position(cell = null) {
|
|
@@ -222,24 +259,30 @@ export class GridCellEditor {
|
|
|
222
259
|
else { cell.removeAttribute('aria-invalid'); cell.removeAttribute('title'); }
|
|
223
260
|
}
|
|
224
261
|
}
|
|
262
|
+
/** The value at the store path, read by address at each call and never kept. */
|
|
263
|
+
collection() {
|
|
264
|
+
const owner = this.context.sourceNode;
|
|
265
|
+
return this.context.getStaticData(owner.absDatapath(owner.getAttr('storepath')));
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Retained fields follow the row key: a field whose row key left the store is released, and the
|
|
269
|
+
* fields of the keys still present survive a replacement of the Bag at the store path.
|
|
270
|
+
*/
|
|
225
271
|
refresh() {
|
|
226
|
-
const bag = this.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
272
|
+
const bag = this.collection();
|
|
273
|
+
const rows = new Set(bag instanceof Bag ? bag.keys() : []);
|
|
274
|
+
for (const [path,label] of this.retained) if (!rows.has(label)) {
|
|
275
|
+
// Close before releasing: closing unmounts the container, which releasing removes from the Source.
|
|
276
|
+
if (this.active?.row === label) this.close();
|
|
277
|
+
if (this.retained.has(path)) this.releaseField(path);
|
|
230
278
|
}
|
|
231
279
|
for (const path of this.retained.keys()) if (path !== this.active?.path) this.releaseCleanField(path);
|
|
232
280
|
for (const [row,tr] of this.renderedRows()) this.decorate(tr,row);
|
|
233
281
|
}
|
|
234
|
-
replaceData() {
|
|
235
|
-
this.close();
|
|
236
|
-
if (this.session) {
|
|
237
|
-
for (const path of this.retained.keys()) this.releaseField(path);
|
|
238
|
-
this.retained.clear();
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
282
|
dispose() {
|
|
242
283
|
this.releaseValidation?.(); this.releaseValidation = null;
|
|
243
|
-
this.disconnect();
|
|
284
|
+
this.disconnect();
|
|
285
|
+
if (this.session) for (const path of [...this.retained.keys()]) this.releaseField(path);
|
|
286
|
+
this.releaseStatus?.(); this.layer.remove();
|
|
244
287
|
}
|
|
245
288
|
}
|
|
@@ -4,11 +4,16 @@ import {cellText} from './grid-rows.js';
|
|
|
4
4
|
import {SVG_NS} from '../renderer/attributes.js';
|
|
5
5
|
import {randomId} from '../random-id.js';
|
|
6
6
|
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Source composition over derived Data in the grid's private area (`<workspaceDatapath>.columnFilter`),
|
|
9
|
+
* read and written by path; accepted filters remain in the outer view. The popup Source nodes are reached
|
|
10
|
+
* by childname from the grid Source node when used (`columnFilter`, then `frame`, `frame/search`, `from`, `to`);
|
|
11
|
+
* the instance lives in `_internal.gridColumnFilters` of its action bar and holds no child Source node.
|
|
12
|
+
*/
|
|
8
13
|
export class GridColumnFilters {
|
|
9
14
|
#host; #head; #view; #columns = []; #format; #context;
|
|
10
|
-
#panel; #anchor = null; #field = null; #
|
|
11
|
-
#rangeQueued = false;
|
|
15
|
+
#panel; #anchor = null; #field = null; #path = null;
|
|
16
|
+
#rangeQueued = false;
|
|
12
17
|
#release; #registrations = []; #connected = false; #syncing = false;
|
|
13
18
|
constructor(host, head) {
|
|
14
19
|
this.#host=host;this.#head=head;
|
|
@@ -30,27 +35,24 @@ export class GridColumnFilters {
|
|
|
30
35
|
context.sourceNode.rootBuilder.binding.bindingFor(context.sourceNode).track(()=>this.dispose());
|
|
31
36
|
}
|
|
32
37
|
#build() {
|
|
33
|
-
if(this.#
|
|
38
|
+
if(this.#path!==null)return;
|
|
34
39
|
const owner=this.#context.sourceNode,builder=owner.rootBuilder;
|
|
35
|
-
this.#path
|
|
36
|
-
this.#
|
|
37
|
-
owner.
|
|
38
|
-
const container=builder.wrapSource(owner).div({node_label:`column_filter_${randomId()}`,slot:'column-filter',
|
|
40
|
+
this.#path=`${owner.workspaceDatapath}.columnFilter`;
|
|
41
|
+
owner.setRelativeData(this.#path,new Bag({rows:new Bag(),checked:'',title:'',summary:'',from:null,to:null,hideRange:true,rangeError:''}));
|
|
42
|
+
const container=builder.wrapSource(owner).div({node_label:`column_filter_${randomId()}`,childname:'columnFilter',slot:'column-filter',
|
|
39
43
|
display:'flex',flex_direction:'column',gap:'8px',padding:'10px',
|
|
40
44
|
style:'font-size:12px;--gramlot-grid-row-height:28px;--gramlot-grid-font-size:12px;--gramlot-grid-cell-padding:4px 7px;--gramlot-menu-item-padding:4px 7px'});
|
|
41
|
-
|
|
42
|
-
this.#pane.setAttr({datapath:this.#path});
|
|
45
|
+
sourceTarget(container).setAttr({datapath:this.#path});
|
|
43
46
|
const fragment=new builder.source.constructor(null,builder);
|
|
44
47
|
const pane=builder.wrapSource(fragment);
|
|
45
48
|
pane.div('^.title',{font_weight:'600',padding:'0 2px'});
|
|
46
49
|
const dates=pane.div({display:'flex',gap:'8px',hidden:'^.hideRange'});
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
dates.dateTextBox({value:'^.from',period_to:'.to',lbl:'From',width:'136px',childname:'from'});
|
|
51
|
+
dates.dateTextBox({value:'^.to',lbl:'To',width:'136px',childname:'to'});
|
|
49
52
|
pane.div('^.rangeError',{role:'alert',color:'var(--gramlot-error)'});
|
|
50
|
-
const frame=pane.frameGrid({storepath:'.rows',rowMode:'attributes',height:'270px',width:'100%'});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
.searchBox({searchOn:'Value:caption',searchLiteral:true}));
|
|
53
|
+
const frame=pane.frameGrid({storepath:'.rows',rowMode:'attributes',height:'270px',width:'100%',childname:'frame'});
|
|
54
|
+
frame.toolbar.menuline({group:true,class:'gramlot-grid-search'})
|
|
55
|
+
.searchBox({searchOn:'Value:caption',searchLiteral:true,childname:'search'});
|
|
54
56
|
const grid=frame.grid;
|
|
55
57
|
grid.setAttr({sortedBy:'caption:a'});
|
|
56
58
|
const struct=grid.struct();
|
|
@@ -58,26 +60,33 @@ export class GridColumnFilters {
|
|
|
58
60
|
struct.column({field:'caption',name:'Value',width:'170px'});
|
|
59
61
|
struct.column({field:'count',name:'Rows',dtype:'L',width:'64px',align:'end'});
|
|
60
62
|
const bar=pane.menu({presentation:'bar',aria_label:'Column filter actions'});
|
|
61
|
-
|
|
63
|
+
sourceTarget(bar)._internal.gridColumnFilters=this;
|
|
62
64
|
for(const [caption,method] of [['All','selectAll'],['None','selectNone'],['Reset','reset']]) {
|
|
63
|
-
bar.menuline({caption,action:`this.parentBag.parentNode.gridColumnFilters.${method}()`});
|
|
65
|
+
bar.menuline({caption,action:`this.parentBag.parentNode._internal.gridColumnFilters.${method}()`});
|
|
64
66
|
}
|
|
65
67
|
pane.div('^.summary',{color:'var(--gramlot-text-secondary)',font_size:'11px',padding:'0 2px'});
|
|
66
68
|
const prepared=builder.binding.gramlot.src.prepareSource(fragment);
|
|
67
69
|
builder.binding.renderer.validateCandidate(prepared);
|
|
68
|
-
|
|
70
|
+
sourceTarget(container).setValue(prepared);
|
|
69
71
|
this.#subscribeData();
|
|
70
72
|
}
|
|
73
|
+
/** The popup Source node at `childpath` below the column filter pane, reached by childname from the grid Source node. */
|
|
74
|
+
#child(childpath) { return this.#context.sourceNode.getChild(`columnFilter/${childpath}`); }
|
|
75
|
+
/** The DOM node of the popup Source node at `childpath`. */
|
|
76
|
+
#childDom(childpath) { return this.#context.sourceNode.rootBuilder.binding.renderer.getDomNode(this.#child(childpath)); }
|
|
77
|
+
/** The value of `key` in the column filter Data, read at its path. */
|
|
78
|
+
#get(key) { return this.#context.sourceNode.data.getItem(`${this.#path}.${key}`); }
|
|
79
|
+
#set(key,value) { this.#context.sourceNode.data.setItem(`${this.#path}.${key}`,value); }
|
|
71
80
|
#subscribeData() {
|
|
72
|
-
if(
|
|
81
|
+
if(this.#path===null || this.#registrations.length)return;
|
|
73
82
|
const router=this.#context.sourceNode.rootBuilder.binding.router;
|
|
74
83
|
this.#registrations.push(router.register({path:this.#path+'.checked',recipient:{receive:()=>this.#selectionChanged()}}));
|
|
75
84
|
for(const name of ['from','to'])this.#registrations.push(router.register({path:this.#path+'.'+name,recipient:{receive:()=>this.#queueRange()}}));
|
|
76
85
|
}
|
|
77
86
|
#selectionChanged() {
|
|
78
87
|
if(this.#syncing || this.#field===null)return;
|
|
79
|
-
const checked=','+this.#
|
|
80
|
-
const nodes=this.#
|
|
88
|
+
const checked=','+this.#get('checked')+',';
|
|
89
|
+
const nodes=this.#get('rows').getNodes();
|
|
81
90
|
const values=nodes.filter(node=>checked.includes(','+node.label+',' )).map(node=>node.getAttr('value'));
|
|
82
91
|
this.#view.applyColumnFilter(this.#field,this.#view.columnRange(this.#field) && values.length===nodes.length ? null : values);
|
|
83
92
|
}
|
|
@@ -90,11 +99,11 @@ export class GridColumnFilters {
|
|
|
90
99
|
#rangeChanged() {
|
|
91
100
|
const column=this.#columns.find(item=>item.field===this.#field);
|
|
92
101
|
if(!['D','DH','DHZ'].includes(column.dtype))return;
|
|
93
|
-
let from=this.#
|
|
102
|
+
let from=this.#get('from'),to=this.#get('to');
|
|
94
103
|
const previous=this.#view.columnRange(this.#field);
|
|
95
|
-
if(previous?.from && !from){to=null;this.#syncing=true;this.#
|
|
96
|
-
if(from && to && from>to){this.#
|
|
97
|
-
this.#
|
|
104
|
+
if(previous?.from && !from){to=null;this.#syncing=true;this.#set('to',null);this.#syncing=false;}
|
|
105
|
+
if(from && to && from>to){this.#set('rangeError','From must not be after To.');return;}
|
|
106
|
+
this.#set('rangeError','');
|
|
98
107
|
if(+from===+(previous?.from ?? null) && +to===+(previous?.to ?? null))return;
|
|
99
108
|
const values=!from && !to ? this.#view.columnFacets(this.#field).filter(item=>item.selected).map(item=>item.value) : null;
|
|
100
109
|
this.#view.applyColumnFilter(this.#field,values,{from,to,dtype:column.dtype,timeZone:this.#context.timeZone});
|
|
@@ -104,9 +113,8 @@ export class GridColumnFilters {
|
|
|
104
113
|
reset() {
|
|
105
114
|
this.#syncing=true;
|
|
106
115
|
try {
|
|
107
|
-
this.#
|
|
108
|
-
const
|
|
109
|
-
for(const node of this.#rangeFields)renderer.getDomNode(node).restoreFormValue(null);
|
|
116
|
+
this.#set('from',null);this.#set('to',null);this.#set('rangeError','');
|
|
117
|
+
for(const key of ['from','to'])this.#childDom(key).restoreFormValue(null);
|
|
110
118
|
} finally {this.#syncing=false;}
|
|
111
119
|
this.#view.applyColumnFilter(this.#field,null,null);
|
|
112
120
|
}
|
|
@@ -134,15 +142,14 @@ export class GridColumnFilters {
|
|
|
134
142
|
this.close();this.#build();this.#anchor=anchor;this.#field=anchor.dataset.field;
|
|
135
143
|
this.#syncing=true;
|
|
136
144
|
const range=this.#view.columnRange(this.#field);
|
|
137
|
-
this.#
|
|
145
|
+
this.#set('from',range?.from ?? null);this.#set('to',range?.to ?? null);this.#set('rangeError','');
|
|
138
146
|
const column=this.#columns.find(item=>item.field===this.#field);
|
|
139
|
-
this.#
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
this.#data.getItem('rows').clear();this.#data.setItem('checked','');renderer.getDomNode(this.#search).clear();
|
|
147
|
+
this.#set('hideRange',!['D','DH','DHZ'].includes(column.dtype));
|
|
148
|
+
for(const key of ['from','to'])this.#childDom(key).restoreFormValue(this.#get(key));
|
|
149
|
+
this.#get('rows').clear();this.#set('checked','');this.#childDom('frame/search').clear();
|
|
143
150
|
this.#syncing=false;
|
|
144
151
|
this.refresh();this.#panel.showPopover();anchor.setAttribute('aria-expanded','true');this.#position();
|
|
145
|
-
this.#
|
|
152
|
+
this.#childDom('frame/search').focus();
|
|
146
153
|
};
|
|
147
154
|
refresh = () => {
|
|
148
155
|
if(!this.#view)return;
|
|
@@ -156,13 +163,13 @@ export class GridColumnFilters {
|
|
|
156
163
|
if(!column){this.close();return;}
|
|
157
164
|
const title=column.title??column.name;
|
|
158
165
|
this.#panel.setAttribute('aria-label',`Filter ${title}`);
|
|
159
|
-
const entries=this.#view.columnFacets(this.#field),rows=this.#
|
|
160
|
-
this.#frame.setAttr({height:`${76+28*Math.max(1,Math.min(entries.length,8))}px`});
|
|
166
|
+
const entries=this.#view.columnFacets(this.#field),rows=this.#get('rows');
|
|
167
|
+
this.#child('frame').setAttr({height:`${76+28*Math.max(1,Math.min(entries.length,8))}px`});
|
|
161
168
|
const existing=new Map(rows.getNodes().map(node=>[node.getAttr('key'),node]));
|
|
162
169
|
const selected=[];
|
|
163
170
|
this.#syncing=true;
|
|
164
171
|
try {
|
|
165
|
-
this.#
|
|
172
|
+
this.#set('title',title);
|
|
166
173
|
for(const entry of entries) {
|
|
167
174
|
const caption=entry.value===null?'Empty':cellText(entry.value,column,this.#format);
|
|
168
175
|
const attrs={key:entry.key,value:entry.value,caption,count:entry.count};
|
|
@@ -173,8 +180,8 @@ export class GridColumnFilters {
|
|
|
173
180
|
}
|
|
174
181
|
for(const node of existing.values())rows.popNode(node.label);
|
|
175
182
|
const checked=selected.join(',');
|
|
176
|
-
if(this.#
|
|
177
|
-
this.#
|
|
183
|
+
if(this.#get('checked')!==checked)this.#set('checked',checked);
|
|
184
|
+
this.#set('summary',`${selected.length} of ${entries.length} values selected`);
|
|
178
185
|
} finally {this.#syncing=false;}
|
|
179
186
|
this.#position();
|
|
180
187
|
};
|
|
@@ -233,17 +233,18 @@ export class GridFormulas {
|
|
|
233
233
|
this.#store = store; this.#view = view;
|
|
234
234
|
this.#errors.clear();
|
|
235
235
|
if (!this.formulas.definitions.size) return;
|
|
236
|
+
// `^` parameters resolve before any subscription: a path without registration (`^#ROW`) is an
|
|
237
|
+
// error at every configuration, and leaves nothing registered.
|
|
238
|
+
const pointers = [...this.formulas.definitions.values()].flatMap(definition => [...definition.parameters.values()]
|
|
239
|
+
.filter(raw => typeof raw === 'string' && raw.startsWith('^'))
|
|
240
|
+
.map(raw => [definition, ...this.source.absDatapath(raw).split('?')]));
|
|
236
241
|
this.#release = [store.subscribe(change => this.#storeChanged(change)),
|
|
237
242
|
view.subscribe(() => { this.#viewValues = null; })];
|
|
238
|
-
for (const definition of
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
this.#viewValues = null;
|
|
244
|
-
this.recalculate(this.#closure([definition.field]));
|
|
245
|
-
}}}));
|
|
246
|
-
}
|
|
243
|
+
for (const [definition, path, attr = null] of pointers) {
|
|
244
|
+
this.#registrations.push(this.runtime.router.register({path, attr, recipient:{receive:() => {
|
|
245
|
+
this.#viewValues = null;
|
|
246
|
+
this.recalculate(this.#closure([definition.field]));
|
|
247
|
+
}}}));
|
|
247
248
|
}
|
|
248
249
|
this.recalculate(this.#closure(this.#selected(definition => definition.calculated)));
|
|
249
250
|
}
|
|
@@ -260,7 +261,7 @@ export class GridFormulas {
|
|
|
260
261
|
value(node, field) {
|
|
261
262
|
if (!this.viewFields.has(field)) return this.#store.value(node, field);
|
|
262
263
|
// A row filtered out of the view has no view value.
|
|
263
|
-
const values = this.#computeViewValues().get(node);
|
|
264
|
+
const values = this.#computeViewValues().get(node.label);
|
|
264
265
|
return values === undefined ? null : values[field];
|
|
265
266
|
}
|
|
266
267
|
|
|
@@ -299,11 +300,15 @@ export class GridFormulas {
|
|
|
299
300
|
this.recalculate(closure, global ? null : [row]);
|
|
300
301
|
}
|
|
301
302
|
|
|
302
|
-
|
|
303
|
+
/**
|
|
304
|
+
* The `formula_<name>` parameters for the row `row`: a `^`/`=` pointer is read at its path, resolved
|
|
305
|
+
* with the row key as row context, so `=#ROW.<field>` reads that field of the evaluated row.
|
|
306
|
+
*/
|
|
307
|
+
#parameters(definition, row) {
|
|
303
308
|
const result = {};
|
|
304
309
|
for (const [name, raw] of definition.parameters) {
|
|
305
310
|
result[name] = typeof raw === 'string' && (raw.startsWith('^') || raw.startsWith('='))
|
|
306
|
-
? this.source.getRelativeData(raw) : raw;
|
|
311
|
+
? this.source.getRelativeData(this.source.absDatapath(raw, {row:row.label})) : raw;
|
|
307
312
|
}
|
|
308
313
|
return result;
|
|
309
314
|
}
|
|
@@ -313,7 +318,7 @@ export class GridFormulas {
|
|
|
313
318
|
if (definition.special?.kind === 'index') return index;
|
|
314
319
|
if (definition.special?.kind === 'running') return addNumeric(aggregate, read(row, definition.special.field));
|
|
315
320
|
if (definition.special?.kind === 'percent') return dividePercent(read(row, definition.special.field), aggregate);
|
|
316
|
-
const parameters = this.#parameters(definition);
|
|
321
|
+
const parameters = this.#parameters(definition, row);
|
|
317
322
|
const scope = {};
|
|
318
323
|
for (const name of definition.references) {
|
|
319
324
|
if (Object.hasOwn(parameters, name)) scope[name] = parameters[name];
|
|
@@ -376,12 +381,12 @@ export class GridFormulas {
|
|
|
376
381
|
}
|
|
377
382
|
}
|
|
378
383
|
|
|
379
|
-
/** View values of the visible rows in this grid's view order, cached until the next store or view change. */
|
|
384
|
+
/** View values of the visible rows by row key, in this grid's view order, cached until the next store or view change. */
|
|
380
385
|
#computeViewValues() {
|
|
381
386
|
if (this.#viewValues !== null) return this.#viewValues;
|
|
382
387
|
const ordered = this.#view.getRows();
|
|
383
|
-
const values = new Map(ordered.map(row => [row, {}]));
|
|
384
|
-
const read = (row, field) => this.viewFields.has(field) ? values.get(row)[field] : this.#store.value(row, field);
|
|
388
|
+
const values = new Map(ordered.map(row => [row.label, {}]));
|
|
389
|
+
const read = (row, field) => this.viewFields.has(field) ? values.get(row.label)[field] : this.#store.value(row, field);
|
|
385
390
|
for (const field of this.formulas.order) {
|
|
386
391
|
const definition = this.formulas.definitions.get(field);
|
|
387
392
|
if (!definition.view) continue;
|
|
@@ -392,7 +397,7 @@ export class GridFormulas {
|
|
|
392
397
|
value = this.#evaluate(definition, row, index + 1, aggregate, read);
|
|
393
398
|
if (definition.special?.kind === 'running') aggregate = value;
|
|
394
399
|
} catch (error) { failure = error; }
|
|
395
|
-
values.get(row)[field] = value;
|
|
400
|
+
values.get(row.label)[field] = value;
|
|
396
401
|
}
|
|
397
402
|
if (failure) this.#errors.set(field, failure);
|
|
398
403
|
else this.#errors.delete(field);
|
|
@@ -55,7 +55,7 @@ export class GridHeaderInteraction {
|
|
|
55
55
|
const header = event.target.closest('th[data-field]');
|
|
56
56
|
if (!header || this.#gesture) { event.preventDefault(); return; }
|
|
57
57
|
this.#suppressClick = true;
|
|
58
|
-
this.#drag = {field:header.dataset.field
|
|
58
|
+
this.#drag = {field:header.dataset.field};
|
|
59
59
|
event.dataTransfer.effectAllowed = 'move';
|
|
60
60
|
event.dataTransfer.setData('text/plain', header.textContent);
|
|
61
61
|
header.classList.add('column-dragging');
|
|
@@ -63,9 +63,8 @@ export class GridHeaderInteraction {
|
|
|
63
63
|
#dropTarget(event) {
|
|
64
64
|
const header = event.target.closest('th[data-field]');
|
|
65
65
|
if (!this.#drag || !header) return null;
|
|
66
|
-
|
|
67
|
-
if (this.#structure().
|
|
68
|
-
target === this.#drag.node || target.parentBag !== this.#drag.node.parentBag) return null;
|
|
66
|
+
// Columns are matched by field: a field that left the structure during the drag has no drop.
|
|
67
|
+
if (header.dataset.field === this.#drag.field || !this.#structure().fields.includes(this.#drag.field)) return null;
|
|
69
68
|
return {header, field:header.dataset.field,
|
|
70
69
|
after:event.clientX > header.getBoundingClientRect().left + header.getBoundingClientRect().width / 2};
|
|
71
70
|
}
|
|
@@ -99,8 +98,8 @@ export class GridHeaderInteraction {
|
|
|
99
98
|
layout.setHeaderWidth(width); this.#layoutChanged();
|
|
100
99
|
}};
|
|
101
100
|
}
|
|
102
|
-
const structure = this.#structure()
|
|
103
|
-
return {identity:
|
|
101
|
+
const structure = this.#structure();
|
|
102
|
+
return {identity:field, width:structure.columnWidth(field), setWidth:width => structure.setColumnWidth(field, width)};
|
|
104
103
|
}
|
|
105
104
|
#minimum(header) {
|
|
106
105
|
if (header.classList.contains('row-heading')) {
|
|
@@ -144,7 +143,7 @@ export class GridHeaderInteraction {
|
|
|
144
143
|
const current = this.#target(gesture.header);
|
|
145
144
|
this.#suppressClick = true;
|
|
146
145
|
this.cancel();
|
|
147
|
-
// A
|
|
146
|
+
// A concurrent width edit, also by a replaced struct, wins over this gesture.
|
|
148
147
|
if (current.identity !== gesture.identity || current.width !== gesture.originalWidth) return;
|
|
149
148
|
current.setWidth(gesture.width);
|
|
150
149
|
this.#focus(gesture.field);
|
|
@@ -165,10 +164,9 @@ export class GridHeaderInteraction {
|
|
|
165
164
|
const header = event.target.closest('th[data-field]');
|
|
166
165
|
if (!header || !event.altKey) return;
|
|
167
166
|
const field = header.dataset.field, structure = this.#structure();
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
structure.moveColumn(field, target.getAttr('field'), event.key === 'ArrowRight');
|
|
167
|
+
const target = structure.adjacentField(field, event.key === 'ArrowRight' ? 1 : -1);
|
|
168
|
+
if (target !== null) {
|
|
169
|
+
structure.moveColumn(field, target, event.key === 'ArrowRight');
|
|
172
170
|
this.#head.querySelector(`th[data-field="${field}"]`).focus({preventScroll:true});
|
|
173
171
|
}
|
|
174
172
|
event.preventDefault(); return;
|
|
@@ -3,17 +3,18 @@ export class GridRowInteraction {
|
|
|
3
3
|
#body;
|
|
4
4
|
#control;
|
|
5
5
|
#layout;
|
|
6
|
-
#
|
|
6
|
+
#labelForRow;
|
|
7
7
|
#gesture = null;
|
|
8
8
|
#drag = null;
|
|
9
9
|
#store;
|
|
10
10
|
#dragEnabled;
|
|
11
11
|
#layoutChanged;
|
|
12
|
-
|
|
12
|
+
/** `labelForRow(tr)` gives the row key of a rendered row, or null; `store()` the collection view. */
|
|
13
|
+
constructor(body, control, layout, labelForRow, store, dragEnabled, layoutChanged) {
|
|
13
14
|
this.#body = body;
|
|
14
15
|
this.#control = control;
|
|
15
16
|
this.#layout = layout;
|
|
16
|
-
this.#
|
|
17
|
+
this.#labelForRow = labelForRow;
|
|
17
18
|
this.#store = store;
|
|
18
19
|
this.#dragEnabled = dragEnabled;
|
|
19
20
|
this.#layoutChanged = layoutChanged;
|
|
@@ -51,20 +52,20 @@ export class GridRowInteraction {
|
|
|
51
52
|
}
|
|
52
53
|
#dragStart = event => {
|
|
53
54
|
const row = event.target.closest('tr');
|
|
54
|
-
const
|
|
55
|
-
if (!this.#dragEnabled() ||
|
|
55
|
+
const label = this.#labelForRow(row);
|
|
56
|
+
if (!this.#dragEnabled() || label === null || this.#gesture || event.target.closest('.row-height-handle')) {
|
|
56
57
|
event.preventDefault(); return;
|
|
57
58
|
}
|
|
58
|
-
this.#drag = {
|
|
59
|
+
this.#drag = {label};
|
|
59
60
|
event.dataTransfer.effectAllowed = 'move';
|
|
60
|
-
event.dataTransfer.setData('text/plain',
|
|
61
|
+
event.dataTransfer.setData('text/plain', label);
|
|
61
62
|
row.classList.add('row-dragging');
|
|
62
63
|
};
|
|
63
64
|
#dropTarget(event) {
|
|
64
65
|
if (!this.#drag || !this.#dragEnabled()) return null;
|
|
65
|
-
|
|
66
|
-
const row = event.target.closest('tr'), target = this.#
|
|
67
|
-
if (
|
|
66
|
+
// Rows are matched by key: the view ignores a move whose keys left the collection.
|
|
67
|
+
const row = event.target.closest('tr'), target = this.#labelForRow(row);
|
|
68
|
+
if (target === null || target === this.#drag.label) return null;
|
|
68
69
|
const box = row.getBoundingClientRect();
|
|
69
70
|
return {row, target, after:event.clientY > box.top + box.height/2};
|
|
70
71
|
}
|
|
@@ -85,9 +86,9 @@ export class GridRowInteraction {
|
|
|
85
86
|
const target = this.#dropTarget(event);
|
|
86
87
|
if (!target) return;
|
|
87
88
|
event.preventDefault(); event.stopPropagation();
|
|
88
|
-
const {
|
|
89
|
+
const {label} = this.#drag;
|
|
89
90
|
this.cancelDrag();
|
|
90
|
-
this.#store().moveRow(
|
|
91
|
+
this.#store().moveRow(label, target.target, target.after);
|
|
91
92
|
};
|
|
92
93
|
#dragEnd = () => { this.cancelDrag(); };
|
|
93
94
|
cancelDrag() {
|
|
@@ -99,11 +100,11 @@ export class GridRowInteraction {
|
|
|
99
100
|
const handle = event.target.closest('.row-height-handle');
|
|
100
101
|
if (!handle) return null;
|
|
101
102
|
const row = handle.closest('tr');
|
|
102
|
-
const
|
|
103
|
-
return
|
|
103
|
+
const label = this.#labelForRow(row);
|
|
104
|
+
return label === null ? null : {handle, row, label};
|
|
104
105
|
}
|
|
105
|
-
project(row,
|
|
106
|
-
const height = this.#layout().height(
|
|
106
|
+
project(row, label) {
|
|
107
|
+
const height = this.#layout().height(label);
|
|
107
108
|
row.style.height = height === null ? '' : `${height}px`;
|
|
108
109
|
}
|
|
109
110
|
#value(row) {
|
|
@@ -139,9 +140,9 @@ export class GridRowInteraction {
|
|
|
139
140
|
if (!gesture || gesture.pointerId !== event.pointerId) return;
|
|
140
141
|
this.#move(event);
|
|
141
142
|
this.cancel();
|
|
142
|
-
if (this.#
|
|
143
|
-
this.#layout().setHeight(gesture.
|
|
144
|
-
this.project(gesture.row, gesture.
|
|
143
|
+
if (this.#labelForRow(gesture.row) !== gesture.label || gesture.preview === gesture.height) return;
|
|
144
|
+
this.#layout().setHeight(gesture.label, gesture.preview);
|
|
145
|
+
this.project(gesture.row, gesture.label);
|
|
145
146
|
this.#value(gesture.row);
|
|
146
147
|
};
|
|
147
148
|
#key = event => {
|
|
@@ -158,8 +159,8 @@ export class GridRowInteraction {
|
|
|
158
159
|
const minimum = target.row.getBoundingClientRect().height;
|
|
159
160
|
height = Math.max(minimum, current + (event.key === 'ArrowDown' ? 10 : -10));
|
|
160
161
|
}
|
|
161
|
-
this.#layout().setHeight(target.
|
|
162
|
-
this.project(target.row, target.
|
|
162
|
+
this.#layout().setHeight(target.label, height);
|
|
163
|
+
this.project(target.row, target.label);
|
|
163
164
|
this.#value(target.row);
|
|
164
165
|
event.preventDefault();
|
|
165
166
|
};
|
|
@@ -167,8 +168,8 @@ export class GridRowInteraction {
|
|
|
167
168
|
const target = this.#target(event);
|
|
168
169
|
if (!target) return;
|
|
169
170
|
this.cancel();
|
|
170
|
-
this.#layout().setHeight(target.
|
|
171
|
-
this.project(target.row, target.
|
|
171
|
+
this.#layout().setHeight(target.label, null);
|
|
172
|
+
this.project(target.row, target.label);
|
|
172
173
|
this.#value(target.row);
|
|
173
174
|
event.preventDefault();
|
|
174
175
|
};
|
|
@@ -177,7 +178,7 @@ export class GridRowInteraction {
|
|
|
177
178
|
const gesture = this.#gesture;
|
|
178
179
|
if (!gesture) return;
|
|
179
180
|
this.#gesture = null;
|
|
180
|
-
this.project(gesture.row, gesture.
|
|
181
|
+
this.project(gesture.row, gesture.label);
|
|
181
182
|
this.#control.classList.remove('resizing-row');
|
|
182
183
|
if (gesture.handle.hasPointerCapture(gesture.pointerId)) gesture.handle.releasePointerCapture(gesture.pointerId);
|
|
183
184
|
}
|