@casoon/opengrid 0.5.0 → 0.6.0
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/CHANGELOG.md +79 -0
- package/README.md +45 -14
- package/engine/opengrid_wasm.d.ts +12 -0
- package/engine/opengrid_wasm.js +43 -0
- package/engine/opengrid_wasm_bg.wasm +0 -0
- package/engine/opengrid_wasm_bg.wasm.d.ts +2 -0
- package/loader.d.ts +17 -3
- package/loader.js +62 -18
- package/package.json +1 -1
- package/pkg/opengrid_web_components.js +10 -10
- package/pkg/opengrid_web_components_bg.wasm +0 -0
- package/worker.js +6 -0
- /package/pkg/snippets/{opengrid-web-core-54e8640e6ad3b889 → opengrid-web-core-9731ccd8c20c4826}/inline0.js +0 -0
- /package/pkg/snippets/{opengrid-web-core-54e8640e6ad3b889 → opengrid-web-core-9731ccd8c20c4826}/inline1.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -18,6 +18,85 @@ Two things belong in every release entry and are easy to leave out:
|
|
|
18
18
|
|
|
19
19
|
## [Unreleased]
|
|
20
20
|
|
|
21
|
+
## [0.6.0] — 2026-09-29
|
|
22
|
+
|
|
23
|
+
**Screen-reader pairings tested: none yet** — the VoiceOver pass is prepared and not yet run
|
|
24
|
+
([issue #5](https://github.com/casoon/opengrid/issues/5)). **Browsers:** Chromium, the whole
|
|
25
|
+
e2e suite. WebKit (Playwright's, not Safari): the whole suite; its one failure, the plain-DOM
|
|
26
|
+
stand-in counting a second table, is fixed in this release (#93). Firefox: **not run**:
|
|
27
|
+
Playwright's Firefox does not start on the release machine.
|
|
28
|
+
|
|
29
|
+
**What breaks** (details in the entries below):
|
|
30
|
+
- the pivot's `header` part moved from its `<thead>` to each column header cell (#29);
|
|
31
|
+
- in the Rust crates, the opengrid types no longer implement `serde` — read and write them
|
|
32
|
+
with `opengrid_json` (#41). The npm package's JavaScript API is unchanged apart from
|
|
33
|
+
additions.
|
|
34
|
+
|
|
35
|
+
**Module sizes** (brotli, `just measure-modules`): the elements 215.8 → 204.1 KiB, the engine
|
|
36
|
+
124.9 → 115.2 KiB — `serde` left both modules (#41), and the engine now answers pivots (#28).
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
|
|
40
|
+
- **Data without JavaScript** ([#84](https://github.com/casoon/opengrid/issues/84)). A page
|
|
41
|
+
can write its data as a plain `<table>` inside an element. Without script, that's what
|
|
42
|
+
readers and crawlers see; once the element has rendered, its shadow root replaces it, so
|
|
43
|
+
nothing is read twice. When the module can't load, the plain-DOM stand-in now shows the
|
|
44
|
+
page's table (through a `<slot>`) instead of hiding it behind an empty skeleton. The
|
|
45
|
+
skeleton only shows when there is no table of its own.
|
|
46
|
+
- **The pivot in the browser** ([#28](https://github.com/casoon/opengrid/issues/28)).
|
|
47
|
+
`createLocalProvider` and `createWorkerProvider` answer `<opengrid-pivot>`: the engine runs
|
|
48
|
+
the pivot's grouping sets over the data the page loaded, with the server's limits
|
|
49
|
+
(`Engine.pivot`, `Engine.pivot_columns`, a `pivot` message in the worker). The element calls
|
|
50
|
+
a provider's new optional `pivot(json)` and falls back to `execute`, so providers of a page's
|
|
51
|
+
own keep working; `createPivotProvider` has `pivot` too. `examples/pivot-demo/browser.html`
|
|
52
|
+
shows it without a server.
|
|
53
|
+
- **XLSX export on the server** ([#72](https://github.com/casoon/opengrid/issues/72)).
|
|
54
|
+
`POST /export/{source}?format=xlsx` writes an Excel workbook, and `exportRows(rest, query,
|
|
55
|
+
{ format: "xlsx" })` asks for it through `createRestProvider` — with any other provider it is
|
|
56
|
+
a `TypeError`. Values are Excel types where Excel holds them exactly (numbers, dates,
|
|
57
|
+
date-times in UTC, booleans) and text where it cannot (integers past 2⁵³, decimals past 15
|
|
58
|
+
digits, sub-millisecond timestamps), so no value changes; Excel's row and cell limits are
|
|
59
|
+
errors, never a shortened file. New server-side dependency: `rust_xlsxwriter`, behind the
|
|
60
|
+
feature `xlsx` of `opengrid-export`, so the browser modules do not carry it.
|
|
61
|
+
- **`<opengrid-table>` and `<opengrid-pivot>` can be styled, and the table takes formats**
|
|
62
|
+
([#29](https://github.com/casoon/opengrid/issues/29)). Both render into a shadow root, so
|
|
63
|
+
no page rule reached their cells. They now carry parts named like the grid's — `table`,
|
|
64
|
+
`caption`, `header`, `row`, `cell`, the table's `sort-button`, the pivot's `row-header` and
|
|
65
|
+
`total-row` — and `examples/pivot-demo` and `examples/table-demo` style them through
|
|
66
|
+
`::part`. The table shows its values as the grid does: `formats` apply to its cells, and
|
|
67
|
+
`presentation` (`set_columns`) gives a column its `title`, `align`, `mono`, `emphasis` and
|
|
68
|
+
`muted`; the grid's `width`, `aggregate` and `facet` are refused for a table with an alert
|
|
69
|
+
rather than ignored. A number is right-aligned by its type, as in the grid.
|
|
70
|
+
**What breaks:** the pivot's `header` part was on its `<thead>`; it is now on each column
|
|
71
|
+
header cell, like the grid's.
|
|
72
|
+
|
|
73
|
+
### Changed
|
|
74
|
+
|
|
75
|
+
- **One JSON codec for browser and server, and no `serde` in the browser**
|
|
76
|
+
([#41](https://github.com/casoon/opengrid/issues/41)). `opengrid-json` reads and writes
|
|
77
|
+
every JSON form — query, schema, view, texts, errors, the JSON result — on both sides,
|
|
78
|
+
so the two cannot read the same bytes two ways. `serde` and `serde_json` are gone from
|
|
79
|
+
both browser modules. Against 0.5.0, with everything else in this release (`just
|
|
80
|
+
measure-modules`, brotli): the elements 215.8 → 204.1 KiB, the engine 124.9 → 115.2 KiB,
|
|
81
|
+
although the engine now answers pivots too. What is read and refused is what `serde_json` read
|
|
82
|
+
and refused (checked against it as an oracle); what is written is what it wrote, keys
|
|
83
|
+
aside — an object now keeps the order it is written in instead of sorting its keys —
|
|
84
|
+
and one rare case: where a float has two shortest spellings, the one closer to the
|
|
85
|
+
value is written. Both read back to the same number.
|
|
86
|
+
|
|
87
|
+
**What breaks** (Rust crates only; the npm package and its JavaScript API are
|
|
88
|
+
unchanged): the opengrid types no longer implement `serde::Serialize`/`Deserialize`.
|
|
89
|
+
Read and write them with `opengrid_json` (`from_str`, `to_string`, `FromJson`, `ToJson`);
|
|
90
|
+
`Value::deserialize_typed` is `Value::from_json_typed`, and a filter literal is an
|
|
91
|
+
`opengrid_json::Json`.
|
|
92
|
+
|
|
93
|
+
### Fixed
|
|
94
|
+
|
|
95
|
+
- **`<opengrid-table>` says it is loading** ([#86](https://github.com/casoon/opengrid/issues/86)).
|
|
96
|
+
Until its first answer it was a table with a caption and no rows, which a screen reader
|
|
97
|
+
couldn't tell from an empty one. The waiting table now carries `aria-busy="true"`, and
|
|
98
|
+
the table with its answer doesn't.
|
|
99
|
+
|
|
21
100
|
## [0.5.0] — 2026-09-28
|
|
22
101
|
|
|
23
102
|
**Screen-reader pairings tested: none yet** — unchanged since 0.1.0
|
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@casoon/opengrid)
|
|
4
4
|
[](#licence)
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
runs in the browser (WebAssembly), on a server (PostgreSQL),
|
|
8
|
-
the same results everywhere.
|
|
6
|
+
Data grid, table and pivot as Web Components, built to be accessible and machine-readable —
|
|
7
|
+
driven by one query engine that runs in the browser (WebAssembly), on a server (PostgreSQL),
|
|
8
|
+
or split between the two, with the same results everywhere.
|
|
9
9
|
|
|
10
10
|
<p>
|
|
11
11
|
<img src="https://raw.githubusercontent.com/casoon/opengrid/main/docs/assets/grid-base.png" alt="opengrid-grid in the Base look: search, + Filter, + Group, filter row and 5,000 orders" width="49%">
|
|
@@ -13,11 +13,19 @@ the same results everywhere.
|
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
15
|
- **`<opengrid-grid>`** — sorting, filtering, search, facets, grouping with totals,
|
|
16
|
-
selection, editing, virtualized or paged;
|
|
16
|
+
selection, editing, virtualized or paged; operated from the keyboard.
|
|
17
17
|
- **`<opengrid-table>`** — a plain semantic `<table>` for displaying data.
|
|
18
|
-
- **`<opengrid-pivot>`** — a pivot with subtotals and a grand total
|
|
19
|
-
|
|
20
|
-
- **
|
|
18
|
+
- **`<opengrid-pivot>`** — a pivot with subtotals and a grand total, from a server or from
|
|
19
|
+
the engine in the tab.
|
|
20
|
+
- **Column titles** — the page names its columns, in its own language, wherever the grid
|
|
21
|
+
names them.
|
|
22
|
+
- **Export** — what the reader sees, every match of it, as CSV or JSON; XLSX from the server.
|
|
23
|
+
- **A resource report** — every answer as an event (where it ran, how long, how big), and
|
|
24
|
+
what the engine holds in memory.
|
|
25
|
+
- **Data without JavaScript** — a page can put its own `<table>` inside an element, for
|
|
26
|
+
readers and crawlers that run no script.
|
|
27
|
+
- **Five built-in looks** — `theme="paper"`, your own `--og-*` properties on top, and
|
|
28
|
+
`::part` for every element.
|
|
21
29
|
|
|
22
30
|
## Live demos
|
|
23
31
|
|
|
@@ -141,8 +149,9 @@ const query = module.get_query(grid); // the reader's view, withou
|
|
|
141
149
|
const blob = await exportRows(provider, query, { format: "csv" });
|
|
142
150
|
```
|
|
143
151
|
|
|
144
|
-
CSV per RFC 4180 with a guard against formula injection, or JSON;
|
|
145
|
-
|
|
152
|
+
CSV per RFC 4180 with a guard against formula injection, or JSON; through
|
|
153
|
+
`createRestProvider` also XLSX, written by the server (`format: "xlsx"`). A pivot exports as
|
|
154
|
+
shown with `get_pivot`. See [Export](https://github.com/casoon/opengrid/blob/main/docs/guides/export.md).
|
|
146
155
|
|
|
147
156
|
## Documentation
|
|
148
157
|
|
|
@@ -151,17 +160,39 @@ with `get_pivot`. See [Export](https://github.com/casoon/opengrid/blob/main/docs
|
|
|
151
160
|
- [Guides](https://github.com/casoon/opengrid/tree/main/docs/guides) and the
|
|
152
161
|
[project page](https://casoon.github.io/opengrid/)
|
|
153
162
|
|
|
154
|
-
##
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
## Accessible and machine-readable: the aim
|
|
164
|
+
|
|
165
|
+
opengrid is meant to be more than a WebAssembly engine that draws a grid. Its data should
|
|
166
|
+
reach **everyone and everything** that reads a page: a person using a keyboard or a screen
|
|
167
|
+
reader, and a program — a test, a browser agent, an export. How it is built toward that:
|
|
168
|
+
|
|
169
|
+
- **One structure for people and programs.** A native `<table>` where reading is all there
|
|
170
|
+
is to do, `role="grid"` (or `treegrid` when grouped) where interaction needs it: row and
|
|
171
|
+
column headers, `aria-rowcount` for the whole result behind a virtualized window,
|
|
172
|
+
`aria-sort`, `aria-selected`, a name for every control. The accessibility tree a screen
|
|
173
|
+
reader reads is the one an automation tool or an AI agent reads.
|
|
174
|
+
- **Designed for the keyboard.** The WAI-ARIA grid pattern for the keys, nothing that needs
|
|
175
|
+
dragging, and one polite live region for every change of state.
|
|
176
|
+
- **Open data at every step.** The schema is a JSON document, a query is a JSON AST, the view
|
|
177
|
+
is JSON, an export is CSV, JSON or XLSX, and a page can write its data as a plain table
|
|
178
|
+
inside the element for readers that run no script.
|
|
179
|
+
- **Tested, not assumed.** axe-core runs over every state of the end-to-end suite; target
|
|
180
|
+
sizes, reflow at 320 px and forced colours are tests; the announcements are recorded in
|
|
181
|
+
order.
|
|
182
|
+
|
|
183
|
+
**This is not a statement of conformance yet.** A pass with a screen reader is still to come
|
|
184
|
+
([#5](https://github.com/casoon/opengrid/issues/5)), and a conformance report follows it. What
|
|
185
|
+
is tested and what is not: [Accessibility](https://github.com/casoon/opengrid/blob/main/docs/guides/accessibility.md).
|
|
159
186
|
|
|
160
187
|
## Status
|
|
161
188
|
|
|
162
189
|
Pre-1.0: a minor version may change the API, a patch version does not
|
|
163
190
|
([CHANGELOG](https://github.com/casoon/opengrid/blob/main/CHANGELOG.md)).
|
|
164
191
|
|
|
192
|
+
This page describes `main`. The pivot in the browser, XLSX export, the table's parts and
|
|
193
|
+
formats, and data without JavaScript are in it but not yet on npm: they come with the next
|
|
194
|
+
release ([Unreleased](https://github.com/casoon/opengrid/blob/main/CHANGELOG.md#unreleased)).
|
|
195
|
+
|
|
165
196
|
## Licence
|
|
166
197
|
|
|
167
198
|
MIT OR Apache-2.0.
|
|
@@ -38,6 +38,16 @@ export class Engine {
|
|
|
38
38
|
* An engine without data. `load_csv` adds sources.
|
|
39
39
|
*/
|
|
40
40
|
constructor();
|
|
41
|
+
/**
|
|
42
|
+
* Runs a pivot JSON over the source it names and answers the pivot's JSON
|
|
43
|
+
* form (issue #28) — what `POST /pivot/{source}` answers, computed here.
|
|
44
|
+
*/
|
|
45
|
+
pivot(pivot_json: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* The same pivot in the binary form (E35) — what the tab and the worker
|
|
48
|
+
* hand the element.
|
|
49
|
+
*/
|
|
50
|
+
pivot_columns(pivot_json: string): Uint8Array;
|
|
41
51
|
/**
|
|
42
52
|
* The names of the registered sources, in unspecified order.
|
|
43
53
|
*/
|
|
@@ -116,6 +126,8 @@ export interface InitOutput {
|
|
|
116
126
|
readonly engine_execute_columns: (a: number, b: number, c: number) => [number, number, number, number];
|
|
117
127
|
readonly engine_load_csv: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
|
|
118
128
|
readonly engine_new: () => number;
|
|
129
|
+
readonly engine_pivot: (a: number, b: number, c: number) => [number, number, number, number];
|
|
130
|
+
readonly engine_pivot_columns: (a: number, b: number, c: number) => [number, number, number, number];
|
|
119
131
|
readonly engine_source_names: (a: number) => [number, number];
|
|
120
132
|
readonly engine_stats: (a: number) => [number, number];
|
|
121
133
|
readonly planner_finish: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
package/engine/opengrid_wasm.js
CHANGED
|
@@ -97,6 +97,49 @@ export class Engine {
|
|
|
97
97
|
EngineFinalization.register(this, this.__wbg_ptr, this);
|
|
98
98
|
return this;
|
|
99
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Runs a pivot JSON over the source it names and answers the pivot's JSON
|
|
102
|
+
* form (issue #28) — what `POST /pivot/{source}` answers, computed here.
|
|
103
|
+
* @param {string} pivot_json
|
|
104
|
+
* @returns {string}
|
|
105
|
+
*/
|
|
106
|
+
pivot(pivot_json) {
|
|
107
|
+
let deferred3_0;
|
|
108
|
+
let deferred3_1;
|
|
109
|
+
try {
|
|
110
|
+
const ptr0 = passStringToWasm0(pivot_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
111
|
+
const len0 = WASM_VECTOR_LEN;
|
|
112
|
+
const ret = wasm.engine_pivot(this.__wbg_ptr, ptr0, len0);
|
|
113
|
+
var ptr2 = ret[0];
|
|
114
|
+
var len2 = ret[1];
|
|
115
|
+
if (ret[3]) {
|
|
116
|
+
ptr2 = 0; len2 = 0;
|
|
117
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
118
|
+
}
|
|
119
|
+
deferred3_0 = ptr2;
|
|
120
|
+
deferred3_1 = len2;
|
|
121
|
+
return getStringFromWasm0(ptr2, len2);
|
|
122
|
+
} finally {
|
|
123
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The same pivot in the binary form (E35) — what the tab and the worker
|
|
128
|
+
* hand the element.
|
|
129
|
+
* @param {string} pivot_json
|
|
130
|
+
* @returns {Uint8Array}
|
|
131
|
+
*/
|
|
132
|
+
pivot_columns(pivot_json) {
|
|
133
|
+
const ptr0 = passStringToWasm0(pivot_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
134
|
+
const len0 = WASM_VECTOR_LEN;
|
|
135
|
+
const ret = wasm.engine_pivot_columns(this.__wbg_ptr, ptr0, len0);
|
|
136
|
+
if (ret[3]) {
|
|
137
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
138
|
+
}
|
|
139
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
140
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
141
|
+
return v2;
|
|
142
|
+
}
|
|
100
143
|
/**
|
|
101
144
|
* The names of the registered sources, in unspecified order.
|
|
102
145
|
* @returns {string[]}
|
|
Binary file
|
|
@@ -7,6 +7,8 @@ export const engine_execute: (a: number, b: number, c: number) => [number, numbe
|
|
|
7
7
|
export const engine_execute_columns: (a: number, b: number, c: number) => [number, number, number, number];
|
|
8
8
|
export const engine_load_csv: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
|
|
9
9
|
export const engine_new: () => number;
|
|
10
|
+
export const engine_pivot: (a: number, b: number, c: number) => [number, number, number, number];
|
|
11
|
+
export const engine_pivot_columns: (a: number, b: number, c: number) => [number, number, number, number];
|
|
10
12
|
export const engine_source_names: (a: number) => [number, number];
|
|
11
13
|
export const engine_stats: (a: number) => [number, number];
|
|
12
14
|
export const planner_finish: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
package/loader.d.ts
CHANGED
|
@@ -142,6 +142,12 @@ export type Answer = string | Uint8Array | ArrayBuffer;
|
|
|
142
142
|
*/
|
|
143
143
|
export interface Provider {
|
|
144
144
|
execute(queryJson: string, mode: string, options?: ExecuteOptions): Answer | Promise<Answer>;
|
|
145
|
+
/**
|
|
146
|
+
* Optional: a pivot JSON in, the pivot's answer out (issue #28).
|
|
147
|
+
* `<opengrid-pivot>` calls it when it is there, `execute` otherwise. The
|
|
148
|
+
* tab, worker and pivot providers have it.
|
|
149
|
+
*/
|
|
150
|
+
pivot?(pivotJson: string, mode: string, options?: ExecuteOptions): Answer | Promise<Answer>;
|
|
145
151
|
/**
|
|
146
152
|
* Optional: where the queries run. The grid names it in its footer, beside
|
|
147
153
|
* the number of queries asked for what is shown; the built-in providers set
|
|
@@ -193,6 +199,10 @@ export interface Engine {
|
|
|
193
199
|
execute_columns(queryJson: string): Uint8Array;
|
|
194
200
|
/** What it holds, as JSON (see `EngineStats`). */
|
|
195
201
|
stats(): string;
|
|
202
|
+
/** A pivot over the engine's sources, as JSON (issue #28). */
|
|
203
|
+
pivot(pivotJson: string): string;
|
|
204
|
+
/** The same pivot in the binary form — what the tab and worker providers answer. */
|
|
205
|
+
pivot_columns(pivotJson: string): Uint8Array;
|
|
196
206
|
}
|
|
197
207
|
|
|
198
208
|
/** What a server says a source is. */
|
|
@@ -289,11 +299,15 @@ export interface ExportProgress {
|
|
|
289
299
|
/**
|
|
290
300
|
* How `exportRows` fetches and writes: its own keys, plus the
|
|
291
301
|
* {@link CsvOptions} `get_pivot` takes too. Any other key is an error, and so
|
|
292
|
-
* is a CSV option on a JSON export.
|
|
302
|
+
* is a CSV option on a JSON or XLSX export.
|
|
293
303
|
*/
|
|
294
304
|
export interface ExportOptions extends CsvOptions {
|
|
295
|
-
/**
|
|
296
|
-
|
|
305
|
+
/**
|
|
306
|
+
* `"csv"` (the default), `"json"` — an array of row objects — or `"xlsx"`,
|
|
307
|
+
* which only a provider that exports on the server (`createRestProvider`)
|
|
308
|
+
* writes; with any other provider it is a `TypeError`.
|
|
309
|
+
*/
|
|
310
|
+
format?: "csv" | "json" | "xlsx";
|
|
297
311
|
/** Rows per request; 10 000 by default, the server's `max_limit`. */
|
|
298
312
|
chunkSize?: number;
|
|
299
313
|
/** More matches than this is an error, never a truncated file; 1 000 000 by default. */
|
package/loader.js
CHANGED
|
@@ -85,6 +85,12 @@ async function start({ moduleUrl = DEFAULT_MODULE_URL, wasmUrl } = {}) {
|
|
|
85
85
|
* Defines the elements in plain DOM, mirroring the Rust skeleton: an open
|
|
86
86
|
* shadow root, a native `<table>` with a `<caption>`, and `label` -> `aria-label`.
|
|
87
87
|
*
|
|
88
|
+
* A page that wrote its data as a table inside the element (issue #84) keeps
|
|
89
|
+
* showing it when the module cannot load, which is when it is needed most: the
|
|
90
|
+
* stand-in then renders only a `<slot>`. Without such content it renders the
|
|
91
|
+
* skeleton, as before. Never both — as the slot's default content the skeleton
|
|
92
|
+
* still counted as a second table in WebKit's accessibility tree.
|
|
93
|
+
*
|
|
88
94
|
* Not exported: `loadOpengrid` installs it when the module fails to load, and a
|
|
89
95
|
* page that reaches for it directly is asking for the broken state on purpose
|
|
90
96
|
* (plan point 39 — an export is a promise).
|
|
@@ -106,6 +112,10 @@ function installFallback(name = "opengrid-table") {
|
|
|
106
112
|
return;
|
|
107
113
|
}
|
|
108
114
|
const root = this.attachShadow({ mode: "open" });
|
|
115
|
+
if (this.firstElementChild) {
|
|
116
|
+
root.append(document.createElement("slot"));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
109
119
|
const table = document.createElement("table");
|
|
110
120
|
const caption = document.createElement("caption");
|
|
111
121
|
table.append(caption);
|
|
@@ -121,6 +131,9 @@ function installFallback(name = "opengrid-table") {
|
|
|
121
131
|
|
|
122
132
|
#applyLabel() {
|
|
123
133
|
const table = this.shadowRoot.querySelector("table");
|
|
134
|
+
if (!table) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
124
137
|
const caption = this.shadowRoot.querySelector("caption");
|
|
125
138
|
const label = this.getAttribute("label");
|
|
126
139
|
if (label) {
|
|
@@ -219,6 +232,12 @@ export function createWorkerProvider({
|
|
|
219
232
|
return { kind: "worker", ...JSON.parse(await request({ type: "stats" })) };
|
|
220
233
|
},
|
|
221
234
|
|
|
235
|
+
/** Runs a pivot JSON and resolves with the pivot in the binary form (issue #28). */
|
|
236
|
+
async pivot(pivotJson) {
|
|
237
|
+
await start();
|
|
238
|
+
return request({ type: "pivot", pivot: pivotJson });
|
|
239
|
+
},
|
|
240
|
+
|
|
222
241
|
/** Stops the worker and rejects everything still in flight. */
|
|
223
242
|
terminate() {
|
|
224
243
|
worker?.terminate();
|
|
@@ -263,6 +282,10 @@ export function createLocalProvider(engine) {
|
|
|
263
282
|
async stats() {
|
|
264
283
|
return { kind: "local", ...JSON.parse(engine.stats()) };
|
|
265
284
|
},
|
|
285
|
+
/** A pivot over the engine's sources, in the binary form (issue #28). */
|
|
286
|
+
pivot(pivotJson) {
|
|
287
|
+
return engine.pivot_columns(pivotJson);
|
|
288
|
+
},
|
|
266
289
|
terminate() {},
|
|
267
290
|
};
|
|
268
291
|
}
|
|
@@ -398,9 +421,7 @@ export function createRestProvider({ url, source, token } = {}) {
|
|
|
398
421
|
const blob = await response.blob();
|
|
399
422
|
onProgress?.({ rows: total, total });
|
|
400
423
|
// The type `exportRows` gives its Blob, whatever the header's spelling.
|
|
401
|
-
return new Blob([blob], {
|
|
402
|
-
type: format === "json" ? "application/json" : "text/csv;charset=utf-8",
|
|
403
|
-
});
|
|
424
|
+
return new Blob([blob], { type: EXPORT_TYPES[format] ?? EXPORT_TYPES.csv });
|
|
404
425
|
},
|
|
405
426
|
};
|
|
406
427
|
}
|
|
@@ -491,19 +512,24 @@ export function createPivotProvider({ url, source, token } = {}) {
|
|
|
491
512
|
headers.Authorization = `Bearer ${token}`;
|
|
492
513
|
}
|
|
493
514
|
|
|
515
|
+
async function pivot(pivotJson, _mode, { signal } = {}) {
|
|
516
|
+
const response = await fetch(endpoint, {
|
|
517
|
+
method: "POST",
|
|
518
|
+
headers,
|
|
519
|
+
body: pivotJson,
|
|
520
|
+
signal,
|
|
521
|
+
redirect: "error",
|
|
522
|
+
});
|
|
523
|
+
return answerOf(response);
|
|
524
|
+
}
|
|
525
|
+
|
|
494
526
|
return {
|
|
495
527
|
/** Where the queries run; the grid names it in its footer (issue #33). */
|
|
496
528
|
kind: "remote",
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
body: pivotJson,
|
|
502
|
-
signal,
|
|
503
|
-
redirect: "error",
|
|
504
|
-
});
|
|
505
|
-
return answerOf(response);
|
|
506
|
-
},
|
|
529
|
+
// `pivot` is what `<opengrid-pivot>` calls (issue #28); `execute` stays for
|
|
530
|
+
// a page that called it before.
|
|
531
|
+
execute: pivot,
|
|
532
|
+
pivot,
|
|
507
533
|
};
|
|
508
534
|
}
|
|
509
535
|
|
|
@@ -561,6 +587,13 @@ export function createHybridProvider({ remote, planner, mode = "auto", onPlan }
|
|
|
561
587
|
};
|
|
562
588
|
}
|
|
563
589
|
|
|
590
|
+
/** The media type of each export's `Blob`. */
|
|
591
|
+
const EXPORT_TYPES = {
|
|
592
|
+
csv: "text/csv;charset=utf-8",
|
|
593
|
+
json: "application/json",
|
|
594
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
595
|
+
};
|
|
596
|
+
|
|
564
597
|
/** The options of `exportRows` that are its own. */
|
|
565
598
|
const EXPORT_OPTIONS = ["format", "chunkSize", "maxRows", "onProgress", "signal"];
|
|
566
599
|
/**
|
|
@@ -639,14 +672,25 @@ export async function exportRows(provider, query, options = {}) {
|
|
|
639
672
|
protectFormulas,
|
|
640
673
|
null: nullText,
|
|
641
674
|
} = options;
|
|
642
|
-
if (format !== "csv" && format !== "json") {
|
|
643
|
-
throw new TypeError(
|
|
675
|
+
if (format !== "csv" && format !== "json" && format !== "xlsx") {
|
|
676
|
+
throw new TypeError(
|
|
677
|
+
`exportRows: format is "csv", "json" or "xlsx", not ${JSON.stringify(format)}`,
|
|
678
|
+
);
|
|
644
679
|
}
|
|
645
|
-
if (format === "
|
|
646
|
-
//
|
|
680
|
+
if (format === "xlsx" && typeof provider?.export !== "function") {
|
|
681
|
+
// An XLSX file is written on the server (issue #72); pieces fetched here
|
|
682
|
+
// cannot become one.
|
|
683
|
+
throw new TypeError(
|
|
684
|
+
"exportRows: an XLSX export needs a provider that exports on the server (createRestProvider)",
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
if (format !== "csv") {
|
|
688
|
+
// A CSV option on another export would do nothing, and do it silently.
|
|
647
689
|
const stray = CSV_OPTIONS.find((key) => options[key] !== undefined);
|
|
648
690
|
if (stray) {
|
|
649
|
-
throw new TypeError(
|
|
691
|
+
throw new TypeError(
|
|
692
|
+
`exportRows: "${stray}" is a CSV option, and this export is ${format.toUpperCase()}`,
|
|
693
|
+
);
|
|
650
694
|
}
|
|
651
695
|
}
|
|
652
696
|
if (!Number.isSafeInteger(chunkSize) || chunkSize < 1) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@casoon/opengrid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Accessible data grid, table and pivot as web components, driven by a portable Rust/WASM query engine — with React, Vue and Svelte components.",
|
|
6
6
|
"keywords": [
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* @ts-self-types="./opengrid_web_components.d.ts" */
|
|
2
|
-
import { __opengrid_define_element } from './snippets/opengrid-web-core-
|
|
3
|
-
import * as import1 from "./snippets/opengrid-web-core-
|
|
4
|
-
import * as import2 from "./snippets/opengrid-web-core-
|
|
5
|
-
import * as import3 from "./snippets/opengrid-web-core-
|
|
2
|
+
import { __opengrid_define_element } from './snippets/opengrid-web-core-9731ccd8c20c4826/inline1.js';
|
|
3
|
+
import * as import1 from "./snippets/opengrid-web-core-9731ccd8c20c4826/inline0.js"
|
|
4
|
+
import * as import2 from "./snippets/opengrid-web-core-9731ccd8c20c4826/inline0.js"
|
|
5
|
+
import * as import3 from "./snippets/opengrid-web-core-9731ccd8c20c4826/inline0.js"
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -266,7 +266,7 @@ function __wbg_get_imports() {
|
|
|
266
266
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
267
267
|
return ret;
|
|
268
268
|
},
|
|
269
|
-
|
|
269
|
+
__wbg___opengrid_define_element_9f1634216a398bd3: function(arg0, arg1, arg2, arg3, arg4, arg5) {
|
|
270
270
|
__opengrid_define_element(getStringFromWasm0(arg0, arg1), arg2, arg3, arg4, arg5);
|
|
271
271
|
},
|
|
272
272
|
__wbg___wbindgen_boolean_get_fa956cfa2d1bd751: function(arg0) {
|
|
@@ -932,7 +932,7 @@ function __wbg_get_imports() {
|
|
|
932
932
|
return ret;
|
|
933
933
|
},
|
|
934
934
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
935
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
935
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 182, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
936
936
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___wasm_bindgen_66404d18cc2edcc2___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_66404d18cc2edcc2___JsError___true_);
|
|
937
937
|
return ret;
|
|
938
938
|
},
|
|
@@ -962,7 +962,7 @@ function __wbg_get_imports() {
|
|
|
962
962
|
return ret;
|
|
963
963
|
},
|
|
964
964
|
__wbindgen_cast_0000000000000007: function(arg0, arg1) {
|
|
965
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [U32], shim_idx:
|
|
965
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [U32], shim_idx: 168, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
966
966
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___u32______true_);
|
|
967
967
|
return ret;
|
|
968
968
|
},
|
|
@@ -994,9 +994,9 @@ function __wbg_get_imports() {
|
|
|
994
994
|
return {
|
|
995
995
|
__proto__: null,
|
|
996
996
|
"./opengrid_web_components_bg.js": import0,
|
|
997
|
-
"./snippets/opengrid-web-core-
|
|
998
|
-
"./snippets/opengrid-web-core-
|
|
999
|
-
"./snippets/opengrid-web-core-
|
|
997
|
+
"./snippets/opengrid-web-core-9731ccd8c20c4826/inline0.js": import1,
|
|
998
|
+
"./snippets/opengrid-web-core-9731ccd8c20c4826/inline0.js": import2,
|
|
999
|
+
"./snippets/opengrid-web-core-9731ccd8c20c4826/inline0.js": import3,
|
|
1000
1000
|
};
|
|
1001
1001
|
}
|
|
1002
1002
|
|
|
Binary file
|
package/worker.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* -> { type:"loaded", id }
|
|
15
15
|
* query { type:"query", id, query } -> { id, result }
|
|
16
16
|
* stats { type:"stats", id } -> { id, result } (issue #70)
|
|
17
|
+
* pivot { type:"pivot", id, pivot } -> { id, result } (issue #28)
|
|
17
18
|
*
|
|
18
19
|
* Any request that throws answers `{ id, type:"error", message }`. The `bytes`
|
|
19
20
|
* of `load` arrive as a transferable `ArrayBuffer`; a `result` is the engine's
|
|
@@ -51,6 +52,11 @@ self.onmessage = async ({ data }) => {
|
|
|
51
52
|
self.postMessage({ id: data.id, result }, [result.buffer]);
|
|
52
53
|
break;
|
|
53
54
|
}
|
|
55
|
+
case "pivot": {
|
|
56
|
+
const result = engine.pivot_columns(data.pivot);
|
|
57
|
+
self.postMessage({ id: data.id, result }, [result.buffer]);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
54
60
|
default:
|
|
55
61
|
throw new Error(`unknown message type ${data.type}`);
|
|
56
62
|
}
|
|
File without changes
|
|
File without changes
|