@gramlot/gramlot 0.3.27 → 0.3.31
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/assets/icons/chart.svg +1 -0
- package/dist/components/audio/__init__.py +13 -0
- package/dist/components/audio/assets/collection.js +3 -0
- package/dist/components/audio/assets/index.js +3 -0
- package/dist/components/audio/commands.json +7 -0
- package/dist/components/audio/grammar.json +335 -0
- package/dist/components/charts/__init__.py +13 -0
- package/dist/components/charts/assets/collection.js +47 -0
- package/dist/components/charts/assets/files/55ea01207028f76d844678511f29fc800f8a1e67a8a0fe80470128677847ad32-echarts-gl.txt +29 -0
- package/dist/components/charts/assets/files/63727832aaf62004a2b249c933e327f3c90caf49e41a72f4bf436edf632cbda8-vega.txt +27 -0
- package/dist/components/charts/assets/files/8c45d9eaf50c2f72dd9c7ab9ef440788ba58a3538484b5c51c1f17d5128752e7-plotly.txt +21 -0
- package/dist/components/charts/assets/files/8f989229699b4fe2f1a0432d0e9edc338a8a911e250e2d1b01ecd770a5f5b1bd-uplot.txt +21 -0
- package/dist/components/charts/assets/files/c8fa058cba98f7f288b5d8fa4116f441d6dacb25b96da859e518c973fff41d0c-claygl.txt +23 -0
- package/dist/components/charts/assets/index.js +3 -0
- package/dist/components/charts/assets/modules/chunk-2CCTLZE7.js +76 -0
- package/dist/components/charts/assets/modules/chunk-RMRBEYTI.js +1 -0
- package/dist/components/charts/assets/modules/echarts-gl-CXVTZA6G.js +4409 -0
- package/dist/components/charts/assets/modules/plotly.min-4LB7HE7P.js +3596 -0
- package/dist/components/charts/assets/modules/uPlot.esm-5JJNHHRF.js +3 -0
- package/dist/components/charts/assets/modules/uPlot.min-N3E3FA74.js +1 -0
- package/dist/components/charts/assets/modules/vega.module-2QCOVQ3A.js +13 -0
- package/dist/components/charts/commands.json +7 -0
- package/dist/components/charts/grammar.json +1113 -0
- package/dist/components/chat/__init__.py +1 -1
- package/dist/components/chat/assets/collection.js +3 -3
- package/dist/components/chat/assets/index.js +1 -1
- package/dist/components/drawing/__init__.py +15 -0
- package/dist/components/drawing/assets/collection.js +28 -0
- package/dist/components/drawing/assets/index.js +3 -0
- package/dist/components/drawing/commands.json +7 -0
- package/dist/components/drawing/grammar.json +110 -0
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +18 -18
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/modules/{prose-mirror-engine-GMZPJPNN.js → prose-mirror-engine-DQEAEIMV.js} +2 -2
- package/dist/components/editors/grammar.json +150 -0
- package/dist/components/grid/__init__.py +2 -2
- package/dist/components/grid/assets/collection.js +71 -34
- package/dist/components/grid/assets/files/0a1df3a083d0c010560aa342e87959c8c1070e6fd54545741f083f22d0c8b551-fflate.txt +21 -0
- package/dist/components/grid/assets/files/8cf9b31947daf7adb4a7a00a037459e58241af050cd0a603bfcf1756e533f75e-write-excel-file.txt +21 -0
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/assets/modules/browser-LVJHKBBV.js +19 -0
- package/dist/components/grid/assets/modules/chunk-RMRBEYTI.js +1 -0
- package/dist/components/grid/commands.json +42 -1
- package/dist/components/grid/grammar.json +650 -10
- package/dist/components/grouplets/__init__.py +1 -1
- package/dist/components/grouplets/assets/collection.js +3 -3
- package/dist/components/grouplets/assets/index.js +1 -1
- package/dist/components/inputs/__init__.py +3 -2
- package/dist/components/inputs/assets/collection.js +38 -23
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +1533 -321
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +27 -23
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +85 -0
- 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 +11 -11
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +126 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +2 -2
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/collection.js +8 -8
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/vizabi/__init__.py +13 -0
- package/dist/components/vizabi/assets/collection.js +22 -0
- package/dist/components/vizabi/assets/index.js +3 -0
- package/dist/components/vizabi/commands.json +7 -0
- package/dist/components/vizabi/grammar.json +128 -0
- package/dist/gramlot.js +944 -193
- package/dist/gramlot.min.js +85 -53
- package/dist/standard-collections.js +2 -0
- package/package.json +13 -4
- package/src/binding/grid-struct.js +5 -2
- package/src/binding/runtime.js +12 -1
- package/src/bootstrap.js +1 -1
- package/src/builder/gramlot-builder.d.ts +15 -2
- package/src/builder/gramlot-builder.js +116 -8
- package/src/builder/source.js +42 -1
- package/src/components/audio-analysis-session.js +65 -0
- package/src/components/audio.js +44 -0
- package/src/components/bases.js +6 -4
- package/src/components/border-container.js +6 -3
- package/src/components/buttons.js +47 -3
- package/src/components/chart-bar3d-options.js +30 -0
- package/src/components/chart-controls.js +83 -0
- package/src/components/chart-data-view.js +52 -0
- package/src/components/chart-data.js +42 -0
- package/src/components/chart-domains.js +46 -0
- package/src/components/chart-engines/echarts-options.js +50 -0
- package/src/components/chart-engines/echarts.js +82 -0
- package/src/components/chart-engines/index.js +22 -0
- package/src/components/chart-engines/plotly-map.js +34 -0
- package/src/components/chart-engines/plotly-spatial.js +35 -0
- package/src/components/chart-engines/plotly.js +138 -0
- package/src/components/chart-engines/uplot.js +57 -0
- package/src/components/chart-engines/vega.js +101 -0
- package/src/components/chart-fields.js +110 -0
- package/src/components/chart-geographic-options.js +47 -0
- package/src/components/chart-geojson.js +60 -0
- package/src/components/chart-geometry.js +11 -0
- package/src/components/chart-map-anchors.js +24 -0
- package/src/components/chart-map-bar3d-options.js +41 -0
- package/src/components/chart-map-data.js +25 -0
- package/src/components/chart-map-labels.js +8 -0
- package/src/components/chart-map-options.js +20 -0
- package/src/components/chart-pane.js +91 -0
- package/src/components/chart-renderer.js +58 -0
- package/src/components/chart-sample-view.js +32 -0
- package/src/components/chart-spatial-options.js +40 -0
- package/src/components/chart-time.js +84 -0
- package/src/components/chart-timeline.js +70 -0
- package/src/components/chart-types/area.js +2 -0
- package/src/components/chart-types/bar.js +2 -0
- package/src/components/chart-types/bar3D.js +2 -0
- package/src/components/chart-types/donut.js +2 -0
- package/src/components/chart-types/horizontalBar.js +2 -0
- package/src/components/chart-types/index.js +26 -0
- package/src/components/chart-types/line.js +2 -0
- package/src/components/chart-types/line3D.js +2 -0
- package/src/components/chart-types/lines3D.js +2 -0
- package/src/components/chart-types/map.js +2 -0
- package/src/components/chart-types/map3D.js +2 -0
- package/src/components/chart-types/mapBar3D.js +2 -0
- package/src/components/chart-types/pie.js +2 -0
- package/src/components/chart-types/polygons3D.js +2 -0
- package/src/components/chart-types/scatter.js +2 -0
- package/src/components/chart-types/scatter3D.js +2 -0
- package/src/components/chart-types/stackedArea.js +2 -0
- package/src/components/chart-types/stackedBar.js +2 -0
- package/src/components/chart-types/surface.js +2 -0
- package/src/components/charts.js +152 -0
- package/src/components/check-box-text-editor.js +88 -0
- package/src/components/check-box-text.js +193 -0
- package/src/components/check-box-tree.js +62 -0
- package/src/components/choice-editor.js +7 -5
- package/src/components/choice-field-styles.js +14 -0
- package/src/components/choices.js +5 -0
- package/src/components/drawing.js +199 -0
- package/src/components/grid-check-sets.js +98 -0
- package/src/components/grid-column-filters.js +198 -0
- package/src/components/grid-footer.js +120 -0
- package/src/components/grid-formulas.js +403 -0
- package/src/components/grid-grammar.json +131 -2
- package/src/components/grid-header-interaction.js +3 -1
- package/src/components/grid-rows.js +2 -2
- package/src/components/grid-search-box.js +38 -22
- package/src/components/grid-search-styles.js +13 -14
- package/src/components/grid-search.js +8 -1
- package/src/components/grid-selection.js +118 -0
- package/src/components/grid-structure.js +36 -5
- package/src/components/grid-styles.js +37 -1
- package/src/components/grid-tools.js +229 -0
- package/src/components/grid.js +223 -15
- package/src/components/image-uploader.js +2 -2
- package/src/components/inputs.js +19 -10
- package/src/components/labelbox.js +5 -1
- package/src/components/licenses/claygl.txt +23 -0
- package/src/components/licenses/echarts-gl.txt +29 -0
- package/src/components/licenses/fflate.txt +21 -0
- package/src/components/licenses/plotly.txt +21 -0
- package/src/components/licenses/uplot.txt +21 -0
- package/src/components/licenses/vega.txt +27 -0
- package/src/components/licenses/write-excel-file.txt +21 -0
- package/src/components/menus.js +19 -11
- package/src/components/toolbar-overflow.js +12 -8
- package/src/components/tree.js +30 -8
- package/src/components/typed-editor.js +14 -3
- package/src/components/vizabi-session.js +66 -0
- package/src/components/vizabi.js +66 -0
- package/src/components/window-surface.js +20 -9
- package/src/components/windows.js +1 -1
- package/src/editing-session.d.ts +2 -0
- package/src/editing-session.js +35 -3
- package/src/gramlot.d.ts +1 -0
- package/src/gramlot.js +2 -0
- package/src/handlers/device-handler.js +32 -32
- package/src/handlers/source-handler.d.ts +2 -2
- package/src/ide-documents.js +19 -3
- package/src/ide-runtime.d.ts +1 -0
- package/src/ide-runtime.js +45 -31
- package/src/index.d.ts +1 -0
- package/src/renderer/drag-drop.js +1 -0
- package/src/renderer/gramlot-renderer.d.ts +2 -0
- package/src/renderer/gramlot-renderer.js +5 -4
- package/src/server/assets.d.ts +3 -0
- package/src/server/assets.js +9 -0
- package/src/server/gramlot-server.d.ts +1 -1
- package/src/server/gramlot-server.js +2 -1
- package/src/server/index.d.ts +1 -1
- package/src/server/index.js +1 -1
- package/src/server/visual-editor.js +17 -17
- package/src/stores/bag-collection-store.js +14 -5
- package/src/stores/bag-collection-view.js +80 -18
- package/src/stores/collection-filter.js +2 -1
- package/src/stores/column-filter.js +49 -0
- package/src/stores/id-set.js +10 -0
- package/src/view/controls.js +8 -0
- package/src/view/html.js +10 -1
- package/src/view/label-menu.js +61 -0
- package/src/view/labelbox.js +15 -2
- package/themes/gramlot-base/theme.css +6 -0
- package/tools/gramlot-tools-inspector.js +169 -505
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import {Bag} from '@gramlot/gramlot';
|
|
2
|
+
import {isDecimal} from '@genrojs/tytx';
|
|
3
|
+
import {GridRows} from './grid-rows.js';
|
|
4
|
+
|
|
5
|
+
/** Export formats of `grid:export`, by `format` parameter: caption, file extension and media type. */
|
|
6
|
+
export const EXPORT_FORMATS = Object.freeze({
|
|
7
|
+
csv: {caption:'CSV', extension:'csv', type:'text/csv'},
|
|
8
|
+
json: {caption:'JSON', extension:'json', type:'application/json'},
|
|
9
|
+
tytx: {caption:'TYTX', extension:'tytx', type:'text/plain'},
|
|
10
|
+
xml: {caption:'XML', extension:'xml', type:'application/xml'},
|
|
11
|
+
xlsx: {caption:'Excel', extension:'xlsx', type:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// The Excel writer is an external engine, loaded on first use.
|
|
15
|
+
let excelEngine = null;
|
|
16
|
+
|
|
17
|
+
/** Grid toolbar commands of the `grid` namespace, delivered to the frame's target grid by publication. */
|
|
18
|
+
export const GRID_COMMANDS = Object.freeze({
|
|
19
|
+
export: {label:'Export', publish:'export', icon:'⇩', tooltip:'Export the visible rows'},
|
|
20
|
+
printRows: {label:'Print', publish:'printRows', icon:'⎙', tooltip:'Print the visible rows'},
|
|
21
|
+
lineNumbers: {label:'Line numbers', publish:'lineNumbers', tooltip:'Show or hide the row numbers'},
|
|
22
|
+
addrow: {label:'Add row', publish:'addrow', icon:'+', tooltip:'Add a row'},
|
|
23
|
+
duprow: {label:'Duplicate', publish:'duprow', icon:'⧉', tooltip:'Duplicate the selected rows'},
|
|
24
|
+
delrow: {label:'Delete', publish:'delrow', icon:'−', tooltip:'Delete the selected rows'},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Commands that change rows: they require at least one editable column.
|
|
28
|
+
const EDIT_COMMANDS = new Set(['grid:addrow', 'grid:duprow', 'grid:delrow']);
|
|
29
|
+
// Commands that act on the selected rows: they require a selection mode.
|
|
30
|
+
const SELECTION_COMMANDS = new Set(['grid:duprow', 'grid:delrow']);
|
|
31
|
+
|
|
32
|
+
/** Register the grid command group on one Gramlot page. */
|
|
33
|
+
export function registerGridCommands(gramlot) {
|
|
34
|
+
const group = gramlot.commands.registerGroup('grid', {description:'Grid toolbar tools'});
|
|
35
|
+
for (const [name, definition] of Object.entries(GRID_COMMANDS)) group.register(name, definition);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function csvField(text) {
|
|
39
|
+
return /[",\r\n]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Toolbar tools of one grid element: subscriptions to the grid's own command topics while it is
|
|
44
|
+
* connected, export and print of the visible rows, the row-number toggle and row insertion.
|
|
45
|
+
*/
|
|
46
|
+
export class GridTools {
|
|
47
|
+
#context;
|
|
48
|
+
#host;
|
|
49
|
+
#handles = [];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* `host` gives `columns()`, `rows()` (visible, in view order), `reader()` (shown values),
|
|
53
|
+
* `store()` ({bag, mode}), `selected()` (selected rows in view order), `selectionMode()`,
|
|
54
|
+
* `parameters()` and `document`.
|
|
55
|
+
*/
|
|
56
|
+
constructor(context, host) {
|
|
57
|
+
this.#context = context;
|
|
58
|
+
this.#host = host;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get source() { return this.#context.sourceNode; }
|
|
62
|
+
get runtime() { return this.source.rootBuilder.binding; }
|
|
63
|
+
|
|
64
|
+
connect() {
|
|
65
|
+
if (this.#handles.length) return;
|
|
66
|
+
const subscriptions = this.runtime.subscriptions;
|
|
67
|
+
const handlers = {export:message => this.exportRows(message.parameters.format), printRows:() => this.printRows(),
|
|
68
|
+
lineNumbers:() => this.toggleLineNumbers(), addrow:message => this.addRow(message.parameters.defaults ?? {}),
|
|
69
|
+
duprow:() => this.duplicateRows(), delrow:() => this.deleteRows()};
|
|
70
|
+
for (const [topic, handler] of Object.entries(handlers)) {
|
|
71
|
+
this.#handles.push(subscriptions.subscribe(subscriptions.topicFor(this.source, topic), async message => {
|
|
72
|
+
try { await handler(message); } catch (error) { this.#context.reportError(error, 'Grid tool'); }
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
disconnect() {
|
|
78
|
+
for (const handle of this.#handles) this.runtime.subscriptions.unsubscribe(handle);
|
|
79
|
+
this.#handles = [];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The visible rows as text cells of the displayed columns, as shown by the grid. */
|
|
83
|
+
#table() {
|
|
84
|
+
const columns = this.#host.columns().filter(column => !column.check);
|
|
85
|
+
const rows = new GridRows(this.#host.reader(), this.#context.format).read(columns, this.#host.rows());
|
|
86
|
+
return {captions:columns.map(column => column.name), cells:rows.map(row => row.cells)};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** CSV of the visible rows in view order, with the column captions. */
|
|
90
|
+
csv() {
|
|
91
|
+
const {captions, cells} = this.#table();
|
|
92
|
+
return [captions, ...cells].map(line => line.map(csvField).join(',')).join('\r\n') + '\r\n';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The visible columns and rows with their raw values (view values included). */
|
|
96
|
+
#records() {
|
|
97
|
+
const columns = this.#host.columns().filter(column => !column.check), reader = this.#host.reader();
|
|
98
|
+
return {columns, rows:this.#host.rows().map(node => [node, columns.map(column => reader.value(node, column.field) ?? null)])};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The visible rows as a Bag shaped like the store: one row per label, values or attributes. */
|
|
102
|
+
rowsBag() {
|
|
103
|
+
const {columns, rows} = this.#records(), bag = new Bag(), values = this.#host.store().mode === 'values';
|
|
104
|
+
for (const [node, cells] of rows) {
|
|
105
|
+
const fields = Object.fromEntries(columns.map((column, index) => [column.field, cells[index]]));
|
|
106
|
+
if (values) bag.setItem(node.label, new Bag(fields));
|
|
107
|
+
else bag.setItem(node.label, null, fields);
|
|
108
|
+
}
|
|
109
|
+
return bag;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** XML of the visible rows under the legacy `GenRoBag` root element (values as text, no type markers). */
|
|
113
|
+
xml() {
|
|
114
|
+
const root = new Bag();
|
|
115
|
+
root.setItem('GenRoBag', this.rowsBag());
|
|
116
|
+
return root.toXml({docHeader:true});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** JSON array of the visible rows, keyed by field, converted as the groupBox Copy JSON. */
|
|
120
|
+
json() {
|
|
121
|
+
const {columns, rows} = this.#records();
|
|
122
|
+
return JSON.stringify(rows.map(([, cells]) => new Bag(Object.fromEntries(columns.map((column, index) => [column.field, cells[index]])))
|
|
123
|
+
.asDict(false, false, true)), null, 2);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** XLSX Blob of the visible rows: captions, then typed cells (numbers, dates, booleans, text). */
|
|
127
|
+
async xlsx() {
|
|
128
|
+
const {columns, rows} = this.#records();
|
|
129
|
+
const writeExcelFile = (await (excelEngine ??= import('write-excel-file/browser'))).default;
|
|
130
|
+
const cell = (value, column) => {
|
|
131
|
+
if (value === null) return null;
|
|
132
|
+
if (isDecimal(value)) return Number(value.toString());
|
|
133
|
+
if (value instanceof Date) return {value, type:Date, format:['DH', 'DHZ'].includes(column.dtype) ? 'yyyy-mm-dd hh:mm:ss' : 'yyyy-mm-dd'};
|
|
134
|
+
if (['number', 'boolean', 'string'].includes(typeof value)) return value;
|
|
135
|
+
return String(value);
|
|
136
|
+
};
|
|
137
|
+
const header = columns.map(column => ({value:column.name, fontWeight:'bold'}));
|
|
138
|
+
const data = [header, ...rows.map(([, cells]) => cells.map((value, index) => cell(value, columns[index])))];
|
|
139
|
+
return writeExcelFile(data, {sheet:this.source.label, stickyRowsCount:1}).toBlob();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Save the visible rows in `format` (EXPORT_FORMATS) as `<grid label>.<extension>`. */
|
|
143
|
+
async exportRows(format) {
|
|
144
|
+
const definition = EXPORT_FORMATS[format];
|
|
145
|
+
if (!definition) throw new TypeError(`grid export format must be one of ${Object.keys(EXPORT_FORMATS).join(', ')}`);
|
|
146
|
+
const content = format === 'csv' ? this.csv() : format === 'json' ? this.json() : format === 'tytx' ? this.rowsBag().toTytx()
|
|
147
|
+
: format === 'xml' ? this.xml() : await this.xlsx();
|
|
148
|
+
// saveText takes any Blob part: text or the XLSX Blob.
|
|
149
|
+
this.runtime.gramlot.utl.inout.saveText(content, `${this.source.label}.${definition.extension}`, definition.type);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Print the visible rows as a plain table in a temporary frame. */
|
|
153
|
+
printRows() {
|
|
154
|
+
const document = this.#host.document;
|
|
155
|
+
const {captions, cells} = this.#table();
|
|
156
|
+
const frame = document.createElement('iframe');
|
|
157
|
+
frame.className = 'gramlot-grid-print';
|
|
158
|
+
frame.setAttribute('aria-hidden', 'true');
|
|
159
|
+
frame.style.cssText = 'position:fixed;inset-inline-start:-10000px;inline-size:1px;block-size:1px;border:0';
|
|
160
|
+
document.body.append(frame);
|
|
161
|
+
const page = frame.contentDocument;
|
|
162
|
+
const table = page.createElement('table');
|
|
163
|
+
const head = page.createElement('thead'), body = page.createElement('tbody');
|
|
164
|
+
const line = (parent, values, tag) => {
|
|
165
|
+
const row = page.createElement('tr');
|
|
166
|
+
for (const value of values) { const cell = page.createElement(tag); cell.textContent = value; row.append(cell); }
|
|
167
|
+
parent.append(row);
|
|
168
|
+
};
|
|
169
|
+
line(head, captions, 'th');
|
|
170
|
+
for (const values of cells) line(body, values, 'td');
|
|
171
|
+
table.append(head, body);
|
|
172
|
+
const style = page.createElement('style');
|
|
173
|
+
style.textContent = 'table{border-collapse:collapse;font:12px sans-serif}th,td{border:1px solid #888;padding:2px 6px;text-align:start}';
|
|
174
|
+
page.head.append(style);
|
|
175
|
+
page.body.append(table);
|
|
176
|
+
frame.contentWindow.addEventListener('afterprint', () => frame.remove());
|
|
177
|
+
frame.contentWindow.print();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Show or hide the row numbers (legacy showLineNumber): a `^` pointer writes Data, a literal the Source. */
|
|
181
|
+
toggleLineNumbers() {
|
|
182
|
+
const value = !this.#host.parameters().rowHeaders;
|
|
183
|
+
if (this.source.pointerType(this.source.getAttr('rowHeaders'))) this.#context.writeParameter('rowHeaders', value);
|
|
184
|
+
else this.source.setAttr({rowHeaders:value});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Append one row with `defaults` to the store Bag; an editing session records it as a change. */
|
|
188
|
+
addRow(defaults) {
|
|
189
|
+
const {bag, mode} = this.#host.store();
|
|
190
|
+
const label = `r_${crypto.randomUUID().replaceAll('-', '')}`;
|
|
191
|
+
if (mode === 'values') bag.setItem(label, new Bag(defaults));
|
|
192
|
+
else bag.setItem(label, null, defaults);
|
|
193
|
+
return bag.getNode(label);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** Append a copy of each selected row, with a new identity. */
|
|
197
|
+
duplicateRows() {
|
|
198
|
+
const {bag, mode} = this.#host.store();
|
|
199
|
+
for (const node of this.#host.selected()) {
|
|
200
|
+
const label = `r_${crypto.randomUUID().replaceAll('-', '')}`;
|
|
201
|
+
if (mode === 'values') bag.setItem(label, node.staticValue.deepcopy());
|
|
202
|
+
else bag.setItem(label, null, {...node.getAttr()});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Remove the selected rows from the store Bag; an editing session records each removal. */
|
|
207
|
+
deleteRows() {
|
|
208
|
+
const {bag} = this.#host.store();
|
|
209
|
+
for (const node of this.#host.selected()) bag.popNode(node.label);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Edit tools declared in the grid's frame require an editable column; selection tools a selection mode. */
|
|
213
|
+
requireEditableTools(columns) {
|
|
214
|
+
const editable = columns.some(column => column.edit), selecting = this.#host.selectionMode() !== 'none';
|
|
215
|
+
if (editable && selecting) return;
|
|
216
|
+
let frame = this.source.parentNode;
|
|
217
|
+
while (frame && frame.nodeTag !== 'framePane') frame = frame.parentNode;
|
|
218
|
+
if (!frame) return;
|
|
219
|
+
const visit = node => {
|
|
220
|
+
if (node.nodeTag === 'framePane') return;
|
|
221
|
+
const command = node.nodeTag === 'menuline' ? node.getAttr('command') : null;
|
|
222
|
+
if (!editable && EDIT_COMMANDS.has(command)) throw new TypeError(`grid tool '${command}' requires an editable column`);
|
|
223
|
+
if (!selecting && SELECTION_COMMANDS.has(command)) throw new TypeError(`grid tool '${command}' requires selectionMode single or multi`);
|
|
224
|
+
if (!editable && node.nodeTag === 'editingStatus') throw new TypeError('grid editing status requires an editable column');
|
|
225
|
+
if (node.value instanceof Bag) for (const child of node.value.getNodes()) visit(child);
|
|
226
|
+
};
|
|
227
|
+
for (const child of frame.value.getNodes()) visit(child);
|
|
228
|
+
}
|
|
229
|
+
}
|