@casoon/opengrid 0.1.0 → 0.3.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 +58 -0
- package/README.md +4 -2
- package/engine/opengrid_wasm_bg.wasm +0 -0
- package/loader.d.ts +34 -0
- package/loader.js +10 -0
- package/package.json +47 -3
- package/pkg/opengrid_web_components.d.ts +4 -4
- package/pkg/opengrid_web_components.js +39 -22
- package/pkg/opengrid_web_components_bg.wasm +0 -0
- package/pkg/opengrid_web_components_bg.wasm.d.ts +4 -4
- package/react/index.d.ts +89 -0
- package/react/index.js +176 -0
- package/svelte/Opengrid.svelte +106 -0
- package/svelte/OpengridGrid.svelte +51 -0
- package/svelte/OpengridPivot.svelte +14 -0
- package/svelte/OpengridTable.svelte +8 -0
- package/svelte/index.d.ts +86 -0
- package/svelte/index.js +11 -0
- package/vue/index.d.ts +77 -0
- package/vue/index.js +168 -0
- /package/pkg/snippets/{opengrid-web-core-e0ef3c8948ce8a1e → opengrid-web-core-51c93662af7982d2}/inline0.js +0 -0
- /package/pkg/snippets/{opengrid-web-core-e0ef3c8948ce8a1e → opengrid-web-core-51c93662af7982d2}/inline1.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -18,6 +18,64 @@ Two things belong in every release entry and are easy to leave out:
|
|
|
18
18
|
|
|
19
19
|
## [Unreleased]
|
|
20
20
|
|
|
21
|
+
## [0.3.0] — 2026-09-27
|
|
22
|
+
|
|
23
|
+
**Screen-reader pairings tested: none yet** — unchanged since 0.1.0
|
|
24
|
+
([issue #5](https://github.com/casoon/opengrid/issues/5)). **Browsers:** as in 0.1.0.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- **The look of the design prototype is the default** ([#32](https://github.com/casoon/opengrid/issues/32)).
|
|
29
|
+
A grid, table or pivot without page CSS looks like the prototype's *Base*: Geist,
|
|
30
|
+
white surfaces, accent `#3d5fd6`, radius 12px.
|
|
31
|
+
- **`theme`** on all three elements picks a built-in look: `base` (default), `paper`,
|
|
32
|
+
`violet`, `orange`, `dark`. `--og-*` properties set by the page still win. The adapters
|
|
33
|
+
take `theme` as a prop. The fonts are named, not loaded.
|
|
34
|
+
|
|
35
|
+
- **The grid's parts look like the design prototype** ([#33](https://github.com/casoon/opengrid/issues/33)):
|
|
36
|
+
the search field, the switches, the column list and the density (a segmented control) in
|
|
37
|
+
one toolbar row; pill chips, the grouping chip inverted; small uppercase column headers;
|
|
38
|
+
32px filter and facet fields.
|
|
39
|
+
- **"+ Filter" and "+ Group"** in the toolbar ([#34](https://github.com/casoon/opengrid/issues/34)),
|
|
40
|
+
the prototype's two quick doors. *+ Filter* opens a non-modal dialog (column, condition,
|
|
41
|
+
value) that writes the filter row's own entry; *+ Group* opens a menu of the groupable
|
|
42
|
+
columns with the column menu's keys and adds a grouping level. New parts `add-filter`,
|
|
43
|
+
`add-grouping`, `filter-dialog`, `grouping-menu`; nine text keys (`addFilter`,
|
|
44
|
+
`addFilterTitle`, `filterColumnLabel`, `filterConditionLabel`, `filterValueLabel`,
|
|
45
|
+
`cancel`, `apply`, `addGrouping`, `groupingFull`).
|
|
46
|
+
- **A footer**: the status line moved below the rows — the same live region, so the
|
|
47
|
+
announcements are unchanged, but a screen reader reading through meets the count after the
|
|
48
|
+
table. Beside it, where the queries ran and how many were asked for what is shown
|
|
49
|
+
(`local · wasm · 2 queries`): providers carry an optional **`kind`** (`local`, `worker`,
|
|
50
|
+
`remote`, `hybrid`; the built-in ones set it), and six new text keys (`sourceLocal`,
|
|
51
|
+
`sourceWorker`, `sourceRemote`, `sourceHybrid`, `queriesOne`, `queriesOther`). New parts
|
|
52
|
+
`footer` and `source`.
|
|
53
|
+
|
|
54
|
+
**What breaks:** the defaults were the system colours (`Canvas`, `CanvasText`,
|
|
55
|
+
`LinkText`) and followed the reader's light or dark mode. A page that relied on that sets
|
|
56
|
+
`theme="dark"` itself, or its own `--og-*` properties. Under `forced-colors` nothing
|
|
57
|
+
changes. A page that styled `::part(status)` as a line above the rows finds it in the
|
|
58
|
+
footer now.
|
|
59
|
+
|
|
60
|
+
## [0.2.0] — 2026-09-27
|
|
61
|
+
|
|
62
|
+
**Screen-reader pairings tested: none yet** — unchanged since 0.1.0
|
|
63
|
+
([issue #5](https://github.com/casoon/opengrid/issues/5)). **Browsers:** as in 0.1.0.
|
|
64
|
+
|
|
65
|
+
### Changed
|
|
66
|
+
|
|
67
|
+
- **One package instead of four** ([#27](https://github.com/casoon/opengrid/issues/27)).
|
|
68
|
+
The React, Vue and Svelte components are subpaths of `@casoon/opengrid`:
|
|
69
|
+
`@casoon/opengrid/react`, `@casoon/opengrid/vue`, `@casoon/opengrid/svelte`. `react`,
|
|
70
|
+
`vue` and `svelte` are optional peer dependencies — a page without a framework installs
|
|
71
|
+
none of them.
|
|
72
|
+
|
|
73
|
+
**What breaks:** `@casoon/opengrid-react`, `@casoon/opengrid-vue` and
|
|
74
|
+
`@casoon/opengrid-svelte` are gone (unpublished from npm within 72 hours of 0.1.0).
|
|
75
|
+
Replace the import — `from "@casoon/opengrid-react"` becomes
|
|
76
|
+
`from "@casoon/opengrid/react"` — and drop the package from `dependencies`. The
|
|
77
|
+
components, their props and their events are unchanged.
|
|
78
|
+
|
|
21
79
|
## [0.1.0] — 2026-09-26
|
|
22
80
|
|
|
23
81
|
The first release: `@casoon/opengrid`, `@casoon/opengrid-react`,
|
package/README.md
CHANGED
|
@@ -73,12 +73,14 @@ See [Where queries run](https://github.com/casoon/opengrid/blob/main/docs/guides
|
|
|
73
73
|
|
|
74
74
|
## React, Vue, Svelte
|
|
75
75
|
|
|
76
|
+
One package: the components are its subpaths, and the framework is an optional peer.
|
|
77
|
+
|
|
76
78
|
```sh
|
|
77
|
-
npm install @casoon/opengrid
|
|
79
|
+
npm install @casoon/opengrid react # or vue, svelte
|
|
78
80
|
```
|
|
79
81
|
|
|
80
82
|
```jsx
|
|
81
|
-
import { OpengridGrid } from "@casoon/opengrid
|
|
83
|
+
import { OpengridGrid } from "@casoon/opengrid/react"; // or /vue, /svelte
|
|
82
84
|
|
|
83
85
|
<OpengridGrid label="Orders" datasource="orders" columns="id,customer,amount"
|
|
84
86
|
provider={provider} view={view} onViewChange={setView} />
|
|
Binary file
|
package/loader.d.ts
CHANGED
|
@@ -135,6 +135,12 @@ export function connect(host: HTMLElement, options?: ConnectOptions): Connection
|
|
|
135
135
|
*/
|
|
136
136
|
export interface Provider {
|
|
137
137
|
execute(queryJson: string, mode: string, options?: ExecuteOptions): string | Promise<string>;
|
|
138
|
+
/**
|
|
139
|
+
* Optional: where the queries run. The grid names it in its footer, beside
|
|
140
|
+
* the number of queries asked for what is shown; the built-in providers set
|
|
141
|
+
* it. A provider without it is shown with the count alone.
|
|
142
|
+
*/
|
|
143
|
+
kind?: ProviderKind;
|
|
138
144
|
/**
|
|
139
145
|
* Optional: the whole export of `query` in one go. `exportRows` uses it when
|
|
140
146
|
* it is there instead of fetching pieces over `execute` —
|
|
@@ -350,8 +356,17 @@ export interface CodedError extends Error {
|
|
|
350
356
|
/** Where a query may run; handed to the provider unchanged. */
|
|
351
357
|
export type Mode = "local" | "remote" | "hybrid" | "auto";
|
|
352
358
|
|
|
359
|
+
/** What a provider's `kind` says: where its queries run. */
|
|
360
|
+
export type ProviderKind = "local" | "worker" | "remote" | "hybrid";
|
|
361
|
+
|
|
353
362
|
export type Density = "compact" | "normal" | "comfortable";
|
|
354
363
|
|
|
364
|
+
/**
|
|
365
|
+
* The built-in looks of the `theme` attribute; `base` is the default. The
|
|
366
|
+
* `--og-*` custom properties a page sets on the element win over them.
|
|
367
|
+
*/
|
|
368
|
+
export type Theme = "base" | "paper" | "violet" | "orange" | "dark";
|
|
369
|
+
|
|
355
370
|
/** The filter operators, by wire token. */
|
|
356
371
|
export type FilterOperator =
|
|
357
372
|
| "eq"
|
|
@@ -543,6 +558,21 @@ export type TextKey =
|
|
|
543
558
|
| "facetTo"
|
|
544
559
|
| "facetQueries"
|
|
545
560
|
| "facetChipValues"
|
|
561
|
+
| "addFilter"
|
|
562
|
+
| "addFilterTitle"
|
|
563
|
+
| "filterColumnLabel"
|
|
564
|
+
| "filterConditionLabel"
|
|
565
|
+
| "filterValueLabel"
|
|
566
|
+
| "cancel"
|
|
567
|
+
| "apply"
|
|
568
|
+
| "addGrouping"
|
|
569
|
+
| "groupingFull"
|
|
570
|
+
| "sourceLocal"
|
|
571
|
+
| "sourceWorker"
|
|
572
|
+
| "sourceRemote"
|
|
573
|
+
| "sourceHybrid"
|
|
574
|
+
| "queriesOne"
|
|
575
|
+
| "queriesOther"
|
|
546
576
|
| "searchLabel"
|
|
547
577
|
| "searchPlaceholder"
|
|
548
578
|
| "queryAnd"
|
|
@@ -643,12 +673,15 @@ export interface OpengridGridAttributes {
|
|
|
643
673
|
"column-menu"?: string;
|
|
644
674
|
selection?: string;
|
|
645
675
|
density?: Density;
|
|
676
|
+
/** One of the built-in looks; Base when absent. */
|
|
677
|
+
theme?: Theme;
|
|
646
678
|
}
|
|
647
679
|
|
|
648
680
|
export interface OpengridTableAttributes {
|
|
649
681
|
label?: string;
|
|
650
682
|
datasource?: string;
|
|
651
683
|
columns?: string;
|
|
684
|
+
theme?: Theme;
|
|
652
685
|
}
|
|
653
686
|
|
|
654
687
|
export interface OpengridPivotAttributes {
|
|
@@ -660,6 +693,7 @@ export interface OpengridPivotAttributes {
|
|
|
660
693
|
columns?: string;
|
|
661
694
|
/** The measures as the contract's JSON: `[{"field":"qty","fn":"sum","as":"total"}]`. */
|
|
662
695
|
values?: string;
|
|
696
|
+
theme?: Theme;
|
|
663
697
|
}
|
|
664
698
|
|
|
665
699
|
/** `<opengrid-grid>`; it fires the three events. */
|
package/loader.js
CHANGED
|
@@ -189,6 +189,8 @@ export function createWorkerProvider({
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
return {
|
|
192
|
+
/** Where the queries run; the grid names it in its footer (issue #33). */
|
|
193
|
+
kind: "worker",
|
|
192
194
|
/** Loads CSV bytes against a schema, starting the worker on first use. */
|
|
193
195
|
async load(name, bytes, schema) {
|
|
194
196
|
await start();
|
|
@@ -230,6 +232,8 @@ export function createWorkerProvider({
|
|
|
230
232
|
*/
|
|
231
233
|
export function createLocalProvider(engine) {
|
|
232
234
|
return {
|
|
235
|
+
/** Where the queries run; the grid names it in its footer (issue #33). */
|
|
236
|
+
kind: "local",
|
|
233
237
|
async load(name, bytes, schema) {
|
|
234
238
|
engine.load_csv(
|
|
235
239
|
name,
|
|
@@ -277,6 +281,8 @@ export function createRestProvider({ url, source, token } = {}) {
|
|
|
277
281
|
}
|
|
278
282
|
|
|
279
283
|
return {
|
|
284
|
+
/** Where the queries run; the grid names it in its footer (issue #33). */
|
|
285
|
+
kind: "remote",
|
|
280
286
|
/**
|
|
281
287
|
* What the server says this source is: `{ name, schema, capabilities }`.
|
|
282
288
|
*
|
|
@@ -446,6 +452,8 @@ export function createPivotProvider({ url, source, token } = {}) {
|
|
|
446
452
|
}
|
|
447
453
|
|
|
448
454
|
return {
|
|
455
|
+
/** Where the queries run; the grid names it in its footer (issue #33). */
|
|
456
|
+
kind: "remote",
|
|
449
457
|
async execute(pivotJson, _mode, { signal } = {}) {
|
|
450
458
|
const response = await fetch(endpoint, {
|
|
451
459
|
method: "POST",
|
|
@@ -493,6 +501,8 @@ export function createPivotProvider({ url, source, token } = {}) {
|
|
|
493
501
|
*/
|
|
494
502
|
export function createHybridProvider({ remote, planner, mode = "auto", onPlan } = {}) {
|
|
495
503
|
return {
|
|
504
|
+
/** Where the queries run; the grid names it in its footer (issue #33). */
|
|
505
|
+
kind: "hybrid",
|
|
496
506
|
async execute(queryJson, elementMode, { signal } = {}) {
|
|
497
507
|
// The element's attribute wins when it has one: the page sets the default,
|
|
498
508
|
// the markup can override it per grid.
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@casoon/opengrid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Accessible data grid, table and pivot as web components, driven by a portable Rust/WASM query engine.",
|
|
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": [
|
|
7
7
|
"datagrid",
|
|
8
8
|
"pivot",
|
|
9
9
|
"web-components",
|
|
10
10
|
"accessibility",
|
|
11
|
-
"wasm"
|
|
11
|
+
"wasm",
|
|
12
|
+
"react",
|
|
13
|
+
"vue",
|
|
14
|
+
"svelte"
|
|
12
15
|
],
|
|
13
16
|
"license": "MIT OR Apache-2.0",
|
|
14
17
|
"repository": {
|
|
@@ -28,6 +31,19 @@
|
|
|
28
31
|
"types": "./loader.d.ts",
|
|
29
32
|
"default": "./loader.js"
|
|
30
33
|
},
|
|
34
|
+
"./react": {
|
|
35
|
+
"types": "./react/index.d.ts",
|
|
36
|
+
"default": "./react/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./vue": {
|
|
39
|
+
"types": "./vue/index.d.ts",
|
|
40
|
+
"default": "./vue/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./svelte": {
|
|
43
|
+
"types": "./svelte/index.d.ts",
|
|
44
|
+
"svelte": "./svelte/index.js",
|
|
45
|
+
"default": "./svelte/index.js"
|
|
46
|
+
},
|
|
31
47
|
"./worker.js": "./worker.js",
|
|
32
48
|
"./pkg/*": "./pkg/*",
|
|
33
49
|
"./engine/*": "./engine/*",
|
|
@@ -42,6 +58,9 @@
|
|
|
42
58
|
"loader.js",
|
|
43
59
|
"loader.d.ts",
|
|
44
60
|
"worker.js",
|
|
61
|
+
"react/",
|
|
62
|
+
"vue/",
|
|
63
|
+
"svelte/",
|
|
45
64
|
"pkg/",
|
|
46
65
|
"engine/",
|
|
47
66
|
"LICENSE-MIT",
|
|
@@ -49,6 +68,31 @@
|
|
|
49
68
|
"README.md",
|
|
50
69
|
"CHANGELOG.md"
|
|
51
70
|
],
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"@types/react": ">=18",
|
|
73
|
+
"react": ">=18",
|
|
74
|
+
"svelte": "^5.0.0",
|
|
75
|
+
"vue": ">=3.3"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"@types/react": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"react": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"svelte": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"vue": {
|
|
88
|
+
"optional": true
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"devDependencies": {
|
|
92
|
+
"@types/react": "19.3.0",
|
|
93
|
+
"svelte": "5.57.1",
|
|
94
|
+
"vue": "3.5.43"
|
|
95
|
+
},
|
|
52
96
|
"engines": {
|
|
53
97
|
"node": ">=18"
|
|
54
98
|
},
|
|
@@ -181,11 +181,11 @@ export interface InitOutput {
|
|
|
181
181
|
readonly set_provider: (a: any, b: any) => void;
|
|
182
182
|
readonly set_texts: (a: any, b: any) => void;
|
|
183
183
|
readonly set_view: (a: any, b: any) => void;
|
|
184
|
-
readonly
|
|
184
|
+
readonly wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement__alloc_508e33bd5656020b___string__String__core_ed718c3d60ebd546___option__Option_alloc_508e33bd5656020b___string__String___core_ed718c3d60ebd546___option__Option_alloc_508e33bd5656020b___string__String_______true_: (a: number, b: number, c: any, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
185
185
|
readonly wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___wasm_bindgen_66404d18cc2edcc2___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_66404d18cc2edcc2___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
186
|
-
readonly
|
|
187
|
-
readonly
|
|
188
|
-
readonly
|
|
186
|
+
readonly wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true_: (a: number, b: number, c: any) => void;
|
|
187
|
+
readonly wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true__3: (a: number, b: number, c: any) => void;
|
|
188
|
+
readonly wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true__4: (a: number, b: number, c: any) => void;
|
|
189
189
|
readonly wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___u32______true_: (a: number, b: number, c: number) => void;
|
|
190
190
|
readonly wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke_______true_: (a: number, b: number) => void;
|
|
191
191
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
@@ -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-51c93662af7982d2/inline1.js';
|
|
3
|
+
import * as import1 from "./snippets/opengrid-web-core-51c93662af7982d2/inline0.js"
|
|
4
|
+
import * as import2 from "./snippets/opengrid-web-core-51c93662af7982d2/inline0.js"
|
|
5
|
+
import * as import3 from "./snippets/opengrid-web-core-51c93662af7982d2/inline0.js"
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -270,7 +270,7 @@ function __wbg_get_imports() {
|
|
|
270
270
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
271
271
|
return ret;
|
|
272
272
|
},
|
|
273
|
-
|
|
273
|
+
__wbg___opengrid_define_element_807a943a07794ca2: function(arg0, arg1, arg2, arg3, arg4, arg5) {
|
|
274
274
|
__opengrid_define_element(getStringFromWasm0(arg0, arg1), arg2, arg3, arg4, arg5);
|
|
275
275
|
},
|
|
276
276
|
__wbg___wbindgen_boolean_get_fa956cfa2d1bd751: function(arg0) {
|
|
@@ -610,6 +610,10 @@ function __wbg_get_imports() {
|
|
|
610
610
|
const ret = new Object();
|
|
611
611
|
return ret;
|
|
612
612
|
},
|
|
613
|
+
__wbg_new_ff9311947c25f0ab: function() { return handleError(function () {
|
|
614
|
+
const ret = new CSSStyleSheet();
|
|
615
|
+
return ret;
|
|
616
|
+
}, arguments); },
|
|
613
617
|
__wbg_new_with_args_200d82645b6544eb: function(arg0, arg1, arg2, arg3) {
|
|
614
618
|
const ret = new Function(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));
|
|
615
619
|
return ret;
|
|
@@ -618,6 +622,10 @@ function __wbg_get_imports() {
|
|
|
618
622
|
const ret = new CustomEvent(getStringFromWasm0(arg0, arg1), arg2);
|
|
619
623
|
return ret;
|
|
620
624
|
}, arguments); },
|
|
625
|
+
__wbg_of_85f52f8b6491a7ca: function(arg0) {
|
|
626
|
+
const ret = Array.of(arg0);
|
|
627
|
+
return ret;
|
|
628
|
+
},
|
|
621
629
|
__wbg_ownerDocument_5a7a5473f8709b3e: function(arg0) {
|
|
622
630
|
const ret = arg0.ownerDocument;
|
|
623
631
|
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
@@ -670,6 +678,9 @@ function __wbg_get_imports() {
|
|
|
670
678
|
__wbg_remove_ce1b54059317fe8a: function(arg0) {
|
|
671
679
|
arg0.remove();
|
|
672
680
|
},
|
|
681
|
+
__wbg_replaceSync_4449064c4c827515: function() { return handleError(function (arg0, arg1, arg2) {
|
|
682
|
+
arg0.replaceSync(getStringFromWasm0(arg1, arg2));
|
|
683
|
+
}, arguments); },
|
|
673
684
|
__wbg_requestAnimationFrame_1a85deeab66448c2: function() { return handleError(function (arg0, arg1) {
|
|
674
685
|
const ret = arg0.requestAnimationFrame(arg1);
|
|
675
686
|
return ret;
|
|
@@ -703,6 +714,9 @@ function __wbg_get_imports() {
|
|
|
703
714
|
const ret = Reflect.set(arg0, arg1, arg2);
|
|
704
715
|
return ret;
|
|
705
716
|
}, arguments); },
|
|
717
|
+
__wbg_set_adoptedStyleSheets_5f0e5fd87d2f8755: function(arg0, arg1) {
|
|
718
|
+
arg0.adoptedStyleSheets = arg1;
|
|
719
|
+
},
|
|
706
720
|
__wbg_set_block_8135b3acafa1ca88: function(arg0, arg1) {
|
|
707
721
|
arg0.block = __wbindgen_enum_ScrollLogicalPosition[arg1];
|
|
708
722
|
},
|
|
@@ -742,6 +756,9 @@ function __wbg_get_imports() {
|
|
|
742
756
|
__wbg_set_textContent_54dcad83ae15772d: function(arg0, arg1, arg2) {
|
|
743
757
|
arg0.textContent = arg1 === 0 ? undefined : getStringFromWasm0(arg1, arg2);
|
|
744
758
|
},
|
|
759
|
+
__wbg_set_type_d2a9a3c584ce2f9a: function(arg0, arg1, arg2) {
|
|
760
|
+
arg0.type = getStringFromWasm0(arg1, arg2);
|
|
761
|
+
},
|
|
745
762
|
__wbg_set_value_e0caa78ebf9917a8: function(arg0, arg1, arg2) {
|
|
746
763
|
arg0.value = getStringFromWasm0(arg1, arg2);
|
|
747
764
|
},
|
|
@@ -839,32 +856,32 @@ function __wbg_get_imports() {
|
|
|
839
856
|
return ret;
|
|
840
857
|
},
|
|
841
858
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
842
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
859
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 186, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
843
860
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___wasm_bindgen_66404d18cc2edcc2___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_66404d18cc2edcc2___JsError___true_);
|
|
844
861
|
return ret;
|
|
845
862
|
},
|
|
846
863
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
847
864
|
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 17, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
848
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
865
|
+
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true_);
|
|
849
866
|
return ret;
|
|
850
867
|
},
|
|
851
868
|
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
852
869
|
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("HTMLElement"), String, Option(String), Option(String)], shim_idx: 18, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
853
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
870
|
+
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement__alloc_508e33bd5656020b___string__String__core_ed718c3d60ebd546___option__Option_alloc_508e33bd5656020b___string__String___core_ed718c3d60ebd546___option__Option_alloc_508e33bd5656020b___string__String_______true_);
|
|
854
871
|
return ret;
|
|
855
872
|
},
|
|
856
873
|
__wbindgen_cast_0000000000000004: function(arg0, arg1) {
|
|
857
874
|
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("HTMLElement")], shim_idx: 17, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
858
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
875
|
+
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true__3);
|
|
859
876
|
return ret;
|
|
860
877
|
},
|
|
861
878
|
__wbindgen_cast_0000000000000005: function(arg0, arg1) {
|
|
862
879
|
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 17, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
863
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
880
|
+
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true__4);
|
|
864
881
|
return ret;
|
|
865
882
|
},
|
|
866
883
|
__wbindgen_cast_0000000000000006: function(arg0, arg1) {
|
|
867
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [U32], shim_idx:
|
|
884
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [U32], shim_idx: 173, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
868
885
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___u32______true_);
|
|
869
886
|
return ret;
|
|
870
887
|
},
|
|
@@ -896,9 +913,9 @@ function __wbg_get_imports() {
|
|
|
896
913
|
return {
|
|
897
914
|
__proto__: null,
|
|
898
915
|
"./opengrid_web_components_bg.js": import0,
|
|
899
|
-
"./snippets/opengrid-web-core-
|
|
900
|
-
"./snippets/opengrid-web-core-
|
|
901
|
-
"./snippets/opengrid-web-core-
|
|
916
|
+
"./snippets/opengrid-web-core-51c93662af7982d2/inline0.js": import1,
|
|
917
|
+
"./snippets/opengrid-web-core-51c93662af7982d2/inline0.js": import2,
|
|
918
|
+
"./snippets/opengrid-web-core-51c93662af7982d2/inline0.js": import3,
|
|
902
919
|
};
|
|
903
920
|
}
|
|
904
921
|
|
|
@@ -906,16 +923,16 @@ function wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke_______true
|
|
|
906
923
|
wasm.wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke_______true_(arg0, arg1);
|
|
907
924
|
}
|
|
908
925
|
|
|
909
|
-
function
|
|
910
|
-
wasm.
|
|
926
|
+
function wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true_(arg0, arg1, arg2) {
|
|
927
|
+
wasm.wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true_(arg0, arg1, arg2);
|
|
911
928
|
}
|
|
912
929
|
|
|
913
|
-
function
|
|
914
|
-
wasm.
|
|
930
|
+
function wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true__3(arg0, arg1, arg2) {
|
|
931
|
+
wasm.wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true__3(arg0, arg1, arg2);
|
|
915
932
|
}
|
|
916
933
|
|
|
917
|
-
function
|
|
918
|
-
wasm.
|
|
934
|
+
function wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true__4(arg0, arg1, arg2) {
|
|
935
|
+
wasm.wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true__4(arg0, arg1, arg2);
|
|
919
936
|
}
|
|
920
937
|
|
|
921
938
|
function wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___wasm_bindgen_66404d18cc2edcc2___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_66404d18cc2edcc2___JsError___true_(arg0, arg1, arg2) {
|
|
@@ -925,14 +942,14 @@ function wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___wasm_bin
|
|
|
925
942
|
}
|
|
926
943
|
}
|
|
927
944
|
|
|
928
|
-
function
|
|
945
|
+
function wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement__alloc_508e33bd5656020b___string__String__core_ed718c3d60ebd546___option__Option_alloc_508e33bd5656020b___string__String___core_ed718c3d60ebd546___option__Option_alloc_508e33bd5656020b___string__String_______true_(arg0, arg1, arg2, arg3, arg4, arg5) {
|
|
929
946
|
const ptr0 = passStringToWasm0(arg3, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
930
947
|
const len0 = WASM_VECTOR_LEN;
|
|
931
948
|
var ptr1 = isLikeNone(arg4) ? 0 : passStringToWasm0(arg4, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
932
949
|
var len1 = WASM_VECTOR_LEN;
|
|
933
950
|
var ptr2 = isLikeNone(arg5) ? 0 : passStringToWasm0(arg5, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
934
951
|
var len2 = WASM_VECTOR_LEN;
|
|
935
|
-
wasm.
|
|
952
|
+
wasm.wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement__alloc_508e33bd5656020b___string__String__core_ed718c3d60ebd546___option__Option_alloc_508e33bd5656020b___string__String___core_ed718c3d60ebd546___option__Option_alloc_508e33bd5656020b___string__String_______true_(arg0, arg1, arg2, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
936
953
|
}
|
|
937
954
|
|
|
938
955
|
function wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___u32______true_(arg0, arg1, arg2) {
|
|
Binary file
|
|
@@ -13,11 +13,11 @@ export const set_formats: (a: any, b: any) => void;
|
|
|
13
13
|
export const set_provider: (a: any, b: any) => void;
|
|
14
14
|
export const set_texts: (a: any, b: any) => void;
|
|
15
15
|
export const set_view: (a: any, b: any) => void;
|
|
16
|
-
export const
|
|
16
|
+
export const wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement__alloc_508e33bd5656020b___string__String__core_ed718c3d60ebd546___option__Option_alloc_508e33bd5656020b___string__String___core_ed718c3d60ebd546___option__Option_alloc_508e33bd5656020b___string__String_______true_: (a: number, b: number, c: any, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
17
17
|
export const wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___wasm_bindgen_66404d18cc2edcc2___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_66404d18cc2edcc2___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
18
|
-
export const
|
|
19
|
-
export const
|
|
20
|
-
export const
|
|
18
|
+
export const wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true_: (a: number, b: number, c: any) => void;
|
|
19
|
+
export const wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true__3: (a: number, b: number, c: any) => void;
|
|
20
|
+
export const wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___web_sys_c43fef36ea7eb37c___features__gen_HtmlElement__HtmlElement______true__4: (a: number, b: number, c: any) => void;
|
|
21
21
|
export const wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke___u32______true_: (a: number, b: number, c: number) => void;
|
|
22
22
|
export const wasm_bindgen_66404d18cc2edcc2___convert__closures_____invoke_______true_: (a: number, b: number) => void;
|
|
23
23
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
package/react/index.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for `@casoon/opengrid/react` (plan point 77).
|
|
3
|
+
*
|
|
4
|
+
* The props are the element's attributes in camelCase plus the options of
|
|
5
|
+
* `connect` from `@casoon/opengrid` — no names of their own. Everything else
|
|
6
|
+
* (`id`, `className`, `style`, `aria-*`, `data-*`) goes to the element.
|
|
7
|
+
*
|
|
8
|
+
* Three things to know, from `connect`:
|
|
9
|
+
*
|
|
10
|
+
* - `provider` and format functions compare by **identity**. An inline
|
|
11
|
+
* `provider={createRestProvider(…)}` is a new provider on every render, and
|
|
12
|
+
* each one asks the source again — create it once (`useMemo`, or outside the
|
|
13
|
+
* component).
|
|
14
|
+
* - `view` is controlled at **render**: a view the page does not take back
|
|
15
|
+
* from `onViewChange` is written again the next time the component renders.
|
|
16
|
+
* - `density` and `groupBy` are attributes the reader can change too (they are
|
|
17
|
+
* part of the view). As props they set the start; with a controlled `view`,
|
|
18
|
+
* leave them out and let the view carry them.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type { ForwardRefExoticComponent, HTMLAttributes, RefAttributes } from "react";
|
|
22
|
+
import type {
|
|
23
|
+
ConnectOptions,
|
|
24
|
+
Density,
|
|
25
|
+
Theme,
|
|
26
|
+
Mode,
|
|
27
|
+
OpengridGridElement,
|
|
28
|
+
OpengridPivotElement,
|
|
29
|
+
OpengridTableElement,
|
|
30
|
+
} from "../loader.js";
|
|
31
|
+
|
|
32
|
+
/** What the element itself takes from React, minus what the component owns. */
|
|
33
|
+
type ElementProps = Omit<
|
|
34
|
+
HTMLAttributes<HTMLElement>,
|
|
35
|
+
"children" | keyof ConnectOptions
|
|
36
|
+
>;
|
|
37
|
+
|
|
38
|
+
export interface OpengridGridProps extends ConnectOptions, ElementProps {
|
|
39
|
+
/** The accessible name of the table. */
|
|
40
|
+
label?: string;
|
|
41
|
+
/** The source; becomes the query's `source`. */
|
|
42
|
+
datasource?: string;
|
|
43
|
+
/** Comma-separated output fields, in order. */
|
|
44
|
+
columns?: string;
|
|
45
|
+
/** Rows rendered and fetched at once while scrolling. Default 40. */
|
|
46
|
+
windowSize?: number;
|
|
47
|
+
/** Switches from scrolling to paging. */
|
|
48
|
+
pageSize?: number;
|
|
49
|
+
mode?: Mode;
|
|
50
|
+
/** Up to two columns, outermost first: `"country,customer"`. */
|
|
51
|
+
groupBy?: string;
|
|
52
|
+
search?: boolean;
|
|
53
|
+
facets?: boolean;
|
|
54
|
+
toolbar?: boolean;
|
|
55
|
+
columnMenu?: boolean;
|
|
56
|
+
selection?: boolean;
|
|
57
|
+
density?: Density;
|
|
58
|
+
/** One of the built-in looks; Base when absent. */
|
|
59
|
+
theme?: Theme;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface OpengridTableProps extends ConnectOptions, ElementProps {
|
|
63
|
+
label?: string;
|
|
64
|
+
datasource?: string;
|
|
65
|
+
columns?: string;
|
|
66
|
+
theme?: Theme;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface OpengridPivotProps extends ConnectOptions, ElementProps {
|
|
70
|
+
label?: string;
|
|
71
|
+
datasource?: string;
|
|
72
|
+
/** Comma-separated row dimensions, outermost first. */
|
|
73
|
+
rows?: string;
|
|
74
|
+
/** Comma-separated column dimensions; V1 allows one. */
|
|
75
|
+
columns?: string;
|
|
76
|
+
/** The measures as the contract's JSON. */
|
|
77
|
+
values?: string;
|
|
78
|
+
theme?: Theme;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const OpengridGrid: ForwardRefExoticComponent<
|
|
82
|
+
OpengridGridProps & RefAttributes<OpengridGridElement>
|
|
83
|
+
>;
|
|
84
|
+
export const OpengridTable: ForwardRefExoticComponent<
|
|
85
|
+
OpengridTableProps & RefAttributes<OpengridTableElement>
|
|
86
|
+
>;
|
|
87
|
+
export const OpengridPivot: ForwardRefExoticComponent<
|
|
88
|
+
OpengridPivotProps & RefAttributes<OpengridPivotElement>
|
|
89
|
+
>;
|
package/react/index.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* React components for `@casoon/opengrid` (plan point 77, E32).
|
|
5
|
+
*
|
|
6
|
+
* A thin shell around `connect`: the component renders the custom element with
|
|
7
|
+
* its attributes, and hands everything else — provider, texts, formats,
|
|
8
|
+
* presentation, choices, the view and the three event callbacks — to one
|
|
9
|
+
* connection. The rules of the module functions live in `connect`, not here.
|
|
10
|
+
*
|
|
11
|
+
* Three things only a React shell has to know:
|
|
12
|
+
*
|
|
13
|
+
* - **Attributes are rendered, not set later.** So they are in the server
|
|
14
|
+
* HTML too. A boolean attribute (`selection`, `toolbar`, …) is present or
|
|
15
|
+
* absent: React 18 would write `selection="false"` for `false`, and for a
|
|
16
|
+
* boolean attribute presence is what counts, so `true` becomes `""` and
|
|
17
|
+
* `false` leaves it out — the same in React 18 and 19. (`""` is safe only
|
|
18
|
+
* because the element has no JS property of those names: React 19 sets a
|
|
19
|
+
* property where one exists, and `""` is falsy.) The HTML booleans a page
|
|
20
|
+
* passes through — `hidden`, `inert`, `autoFocus` — *are* properties of
|
|
21
|
+
* every element, so they go on as `true`, which React 19 sets as the
|
|
22
|
+
* property and React 18 writes as a present attribute; `false` leaves them
|
|
23
|
+
* out, where React 18 would write `hidden="false"` and hide the grid.
|
|
24
|
+
* - **`"use client"`:** hooks and refs, so a Server Component imports it as a
|
|
25
|
+
* client boundary.
|
|
26
|
+
* - **StrictMode mounts twice in development**, and that costs nothing:
|
|
27
|
+
* `connect` applies only once the module has loaded, a microtask later at
|
|
28
|
+
* the earliest, so the first connection is disconnected before it has
|
|
29
|
+
* written anything, and only the second one asks the source.
|
|
30
|
+
* - **An option is passed when it is set, or was set last time** — so a prop
|
|
31
|
+
* that goes away is reset (`connect`'s `undefined`), and one that was never
|
|
32
|
+
* there is not reset on every render.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import { createElement, forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
36
|
+
import { connect } from "../loader.js";
|
|
37
|
+
|
|
38
|
+
/** The HTML boolean attributes a page may pass through, by prop name. */
|
|
39
|
+
const HTML_BOOLEANS = { hidden: "hidden", inert: "inert", autoFocus: "autofocus" };
|
|
40
|
+
|
|
41
|
+
/** What `connect` takes, by prop name. */
|
|
42
|
+
const OPTIONS = [
|
|
43
|
+
"provider",
|
|
44
|
+
"texts",
|
|
45
|
+
"formats",
|
|
46
|
+
"presentation",
|
|
47
|
+
"choices",
|
|
48
|
+
"view",
|
|
49
|
+
"defaultView",
|
|
50
|
+
"onViewChange",
|
|
51
|
+
"onSelectionChange",
|
|
52
|
+
"onCellChange",
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Builds one component.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} tag the custom element.
|
|
59
|
+
* @param {string} displayName the component's name in the React tools.
|
|
60
|
+
* @param {Record<string, string>} attributes prop name → attribute name.
|
|
61
|
+
* @param {string[]} booleans the props that are boolean attributes.
|
|
62
|
+
*/
|
|
63
|
+
function component(tag, displayName, attributes, booleans) {
|
|
64
|
+
const Component = forwardRef(function OpengridComponent(props, ref) {
|
|
65
|
+
const element = useRef(null);
|
|
66
|
+
const connection = useRef(null);
|
|
67
|
+
/** The options of the last render, to tell a removed prop from an absent one. */
|
|
68
|
+
const previous = useRef({});
|
|
69
|
+
useImperativeHandle(ref, () => element.current, []);
|
|
70
|
+
|
|
71
|
+
const rendered = { ref: element };
|
|
72
|
+
const options = {};
|
|
73
|
+
for (const [name, value] of Object.entries(props)) {
|
|
74
|
+
if (OPTIONS.includes(name)) {
|
|
75
|
+
options[name] = value;
|
|
76
|
+
} else if (name in HTML_BOOLEANS) {
|
|
77
|
+
rendered[HTML_BOOLEANS[name]] = value ? true : undefined;
|
|
78
|
+
} else if (name in attributes) {
|
|
79
|
+
if (booleans.includes(name)) {
|
|
80
|
+
rendered[attributes[name]] = value ? "" : undefined;
|
|
81
|
+
} else {
|
|
82
|
+
rendered[attributes[name]] = value == null ? undefined : String(value);
|
|
83
|
+
}
|
|
84
|
+
} else if (name === "className") {
|
|
85
|
+
// `class` on a custom element: React 18 would write `classname`.
|
|
86
|
+
rendered.class = value;
|
|
87
|
+
} else {
|
|
88
|
+
rendered[name] = value;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Unmount: the listeners go; the element keeps its state for as long as
|
|
93
|
+
// it lives (docs/api.md §Connecting).
|
|
94
|
+
useEffect(
|
|
95
|
+
() => () => {
|
|
96
|
+
connection.current?.disconnect();
|
|
97
|
+
connection.current = null;
|
|
98
|
+
},
|
|
99
|
+
[],
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// Every render: connect once, then update — `connect` writes only what
|
|
103
|
+
// changed, so passing everything each time costs nothing.
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
const last = previous.current;
|
|
106
|
+
previous.current = options;
|
|
107
|
+
if (connection.current) {
|
|
108
|
+
const changed = {};
|
|
109
|
+
for (const name of OPTIONS) {
|
|
110
|
+
if (options[name] !== undefined || last[name] !== undefined) {
|
|
111
|
+
changed[name] = options[name];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
connection.current.update(changed);
|
|
115
|
+
} else {
|
|
116
|
+
if (props.view != null && props.defaultView != null) {
|
|
117
|
+
console.warn(
|
|
118
|
+
`[opengrid] <${displayName}> has both view and defaultView; the view is controlled and leads`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
// Only what is set: `texts={undefined}` is no texts, not a reset.
|
|
122
|
+
connection.current = connect(
|
|
123
|
+
element.current,
|
|
124
|
+
Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined)),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return createElement(tag, rendered);
|
|
130
|
+
});
|
|
131
|
+
Component.displayName = displayName;
|
|
132
|
+
return Component;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const OpengridGrid = component(
|
|
136
|
+
"opengrid-grid",
|
|
137
|
+
"OpengridGrid",
|
|
138
|
+
{
|
|
139
|
+
label: "label",
|
|
140
|
+
datasource: "datasource",
|
|
141
|
+
columns: "columns",
|
|
142
|
+
windowSize: "window-size",
|
|
143
|
+
pageSize: "page-size",
|
|
144
|
+
mode: "mode",
|
|
145
|
+
groupBy: "group-by",
|
|
146
|
+
search: "search",
|
|
147
|
+
facets: "facets",
|
|
148
|
+
toolbar: "toolbar",
|
|
149
|
+
columnMenu: "column-menu",
|
|
150
|
+
selection: "selection",
|
|
151
|
+
density: "density",
|
|
152
|
+
theme: "theme",
|
|
153
|
+
},
|
|
154
|
+
["search", "facets", "toolbar", "columnMenu", "selection"],
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
export const OpengridTable = component(
|
|
158
|
+
"opengrid-table",
|
|
159
|
+
"OpengridTable",
|
|
160
|
+
{ label: "label", datasource: "datasource", columns: "columns", theme: "theme" },
|
|
161
|
+
[],
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
export const OpengridPivot = component(
|
|
165
|
+
"opengrid-pivot",
|
|
166
|
+
"OpengridPivot",
|
|
167
|
+
{
|
|
168
|
+
label: "label",
|
|
169
|
+
datasource: "datasource",
|
|
170
|
+
rows: "rows",
|
|
171
|
+
columns: "columns",
|
|
172
|
+
values: "values",
|
|
173
|
+
theme: "theme",
|
|
174
|
+
},
|
|
175
|
+
[],
|
|
176
|
+
);
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The element and its connection (plan point 79) — internal; the page uses
|
|
3
|
+
OpengridGrid, OpengridTable and OpengridPivot.
|
|
4
|
+
|
|
5
|
+
The element is rendered with its attributes, so they are in the server HTML
|
|
6
|
+
too; everything else goes to one `connect` from `@casoon/opengrid`:
|
|
7
|
+
|
|
8
|
+
- One effect reads every option — objects through `$state.snapshot`, so a
|
|
9
|
+
change inside a `$state` object counts (for `formats`, the functions in it
|
|
10
|
+
keep their identity) — and passes on what is set now or was set last time:
|
|
11
|
+
a prop taken away is reset, one never given is left alone (the same rule
|
|
12
|
+
as the React adapter).
|
|
13
|
+
- `bind:view`: the view the reader changed is written into the bound prop;
|
|
14
|
+
the effect then hands it back, and `connect` knows that is no change. A
|
|
15
|
+
binding that refuses it (`bind:view={get, set}` whose setter keeps the old
|
|
16
|
+
view) gets its own view written back after the tick — controlled, as in
|
|
17
|
+
React and Vue. A `view={…}` without `bind:` follows Svelte's rule for
|
|
18
|
+
bindable props: the reader's change becomes the component's own value,
|
|
19
|
+
as a typed-in `value` does on an `<input>` without `bind:`.
|
|
20
|
+
- `bind:element` gives the page the element, as `ref` does in React.
|
|
21
|
+
- The connection is made once the element exists and closed when the
|
|
22
|
+
component is destroyed. The element keeps its own state for as long as it
|
|
23
|
+
lives (docs/api.md §Connecting).
|
|
24
|
+
-->
|
|
25
|
+
<script>
|
|
26
|
+
import { tick, untrack } from "svelte";
|
|
27
|
+
import { connect } from "../loader.js";
|
|
28
|
+
|
|
29
|
+
let {
|
|
30
|
+
tag,
|
|
31
|
+
attributes,
|
|
32
|
+
view = $bindable(),
|
|
33
|
+
element = $bindable(),
|
|
34
|
+
defaultView,
|
|
35
|
+
provider,
|
|
36
|
+
texts,
|
|
37
|
+
formats,
|
|
38
|
+
presentation,
|
|
39
|
+
choices,
|
|
40
|
+
onviewchange,
|
|
41
|
+
onselectionchange,
|
|
42
|
+
oncellchange,
|
|
43
|
+
...rest
|
|
44
|
+
} = $props();
|
|
45
|
+
|
|
46
|
+
let connection = null;
|
|
47
|
+
let previous = {};
|
|
48
|
+
|
|
49
|
+
$effect(() => {
|
|
50
|
+
const options = {
|
|
51
|
+
provider,
|
|
52
|
+
texts: $state.snapshot(texts),
|
|
53
|
+
formats: formats && snapshotFormats(formats),
|
|
54
|
+
presentation: $state.snapshot(presentation),
|
|
55
|
+
choices: $state.snapshot(choices),
|
|
56
|
+
view: $state.snapshot(view),
|
|
57
|
+
defaultView: $state.snapshot(defaultView),
|
|
58
|
+
};
|
|
59
|
+
untrack(() => {
|
|
60
|
+
const callbacks = {
|
|
61
|
+
onViewChange: (next) => {
|
|
62
|
+
view = next;
|
|
63
|
+
onviewchange?.(next);
|
|
64
|
+
tick().then(() => {
|
|
65
|
+
if (view != null) connection?.update({ view: $state.snapshot(view) });
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
onSelectionChange: (detail) => onselectionchange?.(detail),
|
|
69
|
+
onCellChange: (detail) => oncellchange?.(detail),
|
|
70
|
+
};
|
|
71
|
+
if (!connection) {
|
|
72
|
+
if (options.view != null && options.defaultView != null) {
|
|
73
|
+
console.warn(`[opengrid] <${tag}> has both view and defaultView; the view is controlled and leads`);
|
|
74
|
+
}
|
|
75
|
+
const set = Object.entries(options).filter(([, value]) => value !== undefined);
|
|
76
|
+
connection = connect(element, { ...Object.fromEntries(set), ...callbacks });
|
|
77
|
+
} else {
|
|
78
|
+
const changed = { ...callbacks };
|
|
79
|
+
for (const [name, value] of Object.entries(options)) {
|
|
80
|
+
if (value !== undefined || previous[name] !== undefined) {
|
|
81
|
+
changed[name] = value;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
connection.update(changed);
|
|
85
|
+
}
|
|
86
|
+
previous = options;
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/** The formats as plain values, their functions kept as they are. */
|
|
91
|
+
function snapshotFormats(value) {
|
|
92
|
+
return Object.fromEntries(
|
|
93
|
+
Object.entries(value).map(([column, format]) => [
|
|
94
|
+
column,
|
|
95
|
+
typeof format === "function" ? format : $state.snapshot(format),
|
|
96
|
+
]),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
$effect(() => () => {
|
|
101
|
+
connection?.disconnect();
|
|
102
|
+
connection = null;
|
|
103
|
+
});
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<svelte:element this={tag} bind:this={element} {...attributes} {...rest}></svelte:element>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<!-- `<opengrid-grid>` for Svelte 5 (plan point 79). See Opengrid.svelte. -->
|
|
2
|
+
<script>
|
|
3
|
+
import Opengrid from "./Opengrid.svelte";
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
label,
|
|
7
|
+
datasource,
|
|
8
|
+
columns,
|
|
9
|
+
windowSize,
|
|
10
|
+
pageSize,
|
|
11
|
+
mode,
|
|
12
|
+
groupBy,
|
|
13
|
+
search = false,
|
|
14
|
+
facets = false,
|
|
15
|
+
toolbar = false,
|
|
16
|
+
columnMenu = false,
|
|
17
|
+
selection = false,
|
|
18
|
+
density,
|
|
19
|
+
theme,
|
|
20
|
+
view = $bindable(),
|
|
21
|
+
element = $bindable(),
|
|
22
|
+
...rest
|
|
23
|
+
} = $props();
|
|
24
|
+
|
|
25
|
+
/** A boolean attribute is present or absent; `false` is absent. */
|
|
26
|
+
const flag = (on) => (on ? "" : undefined);
|
|
27
|
+
const text = (value) => (value == null ? undefined : String(value));
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<Opengrid
|
|
31
|
+
tag="opengrid-grid"
|
|
32
|
+
attributes={{
|
|
33
|
+
label,
|
|
34
|
+
datasource,
|
|
35
|
+
columns,
|
|
36
|
+
"window-size": text(windowSize),
|
|
37
|
+
"page-size": text(pageSize),
|
|
38
|
+
mode,
|
|
39
|
+
"group-by": groupBy,
|
|
40
|
+
search: flag(search),
|
|
41
|
+
facets: flag(facets),
|
|
42
|
+
toolbar: flag(toolbar),
|
|
43
|
+
"column-menu": flag(columnMenu),
|
|
44
|
+
selection: flag(selection),
|
|
45
|
+
density,
|
|
46
|
+
theme,
|
|
47
|
+
}}
|
|
48
|
+
bind:view
|
|
49
|
+
bind:element
|
|
50
|
+
{...rest}
|
|
51
|
+
/>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!-- `<opengrid-pivot>` for Svelte 5 (plan point 79). See Opengrid.svelte. -->
|
|
2
|
+
<script>
|
|
3
|
+
import Opengrid from "./Opengrid.svelte";
|
|
4
|
+
|
|
5
|
+
let { label, datasource, rows, columns, values, theme, view = $bindable(), element = $bindable(), ...rest } = $props();
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<Opengrid
|
|
9
|
+
tag="opengrid-pivot"
|
|
10
|
+
attributes={{ label, datasource, rows, columns, values, theme }}
|
|
11
|
+
bind:view
|
|
12
|
+
bind:element
|
|
13
|
+
{...rest}
|
|
14
|
+
/>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<!-- `<opengrid-table>` for Svelte 5 (plan point 79). See Opengrid.svelte. -->
|
|
2
|
+
<script>
|
|
3
|
+
import Opengrid from "./Opengrid.svelte";
|
|
4
|
+
|
|
5
|
+
let { label, datasource, columns, theme, view = $bindable(), element = $bindable(), ...rest } = $props();
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<Opengrid tag="opengrid-table" attributes={{ label, datasource, columns, theme }} bind:view bind:element {...rest} />
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for `@casoon/opengrid/svelte` (plan point 79).
|
|
3
|
+
*
|
|
4
|
+
* The props are the element's attributes in camelCase plus the options of
|
|
5
|
+
* `connect` from `@casoon/opengrid`, with the callbacks in Svelte's own
|
|
6
|
+
* spelling — `onviewchange`, `onselectionchange`, `oncellchange` — `view`
|
|
7
|
+
* bindable (`bind:view`), and the element itself through `bind:element`.
|
|
8
|
+
* Everything else (`id`, `class`, `style`, `aria-*`) goes to the element.
|
|
9
|
+
*
|
|
10
|
+
* `view` is controlled through `bind:view`: a binding whose setter refuses the
|
|
11
|
+
* reader's change gets its view written back. A `view={…}` without `bind:`
|
|
12
|
+
* follows Svelte's rule for bindable props — the reader's change becomes the
|
|
13
|
+
* component's own value, as on an `<input>` without `bind:`.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { Component } from "svelte";
|
|
17
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
18
|
+
import type {
|
|
19
|
+
CellChangeDetail,
|
|
20
|
+
ConnectOptions,
|
|
21
|
+
Density,
|
|
22
|
+
Theme,
|
|
23
|
+
Mode,
|
|
24
|
+
SelectionChangeDetail,
|
|
25
|
+
View,
|
|
26
|
+
} from "../loader.js";
|
|
27
|
+
|
|
28
|
+
/** `connect`'s options, the callbacks in Svelte's spelling. */
|
|
29
|
+
type Options = Omit<ConnectOptions, "onViewChange" | "onSelectionChange" | "onCellChange"> & {
|
|
30
|
+
/** The element, for `bind:element`. */
|
|
31
|
+
element?: HTMLElement;
|
|
32
|
+
/** The reader changed the view; `bind:view` has it already. */
|
|
33
|
+
onviewchange?: (view: View) => void;
|
|
34
|
+
onselectionchange?: (detail: SelectionChangeDetail) => void;
|
|
35
|
+
oncellchange?: (detail: CellChangeDetail) => void;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** What the element itself takes, minus what the component owns. */
|
|
39
|
+
type ElementProps = Omit<HTMLAttributes<HTMLElement>, "children" | keyof Options>;
|
|
40
|
+
|
|
41
|
+
export interface OpengridGridProps extends Options, ElementProps {
|
|
42
|
+
/** The accessible name of the table. */
|
|
43
|
+
label?: string;
|
|
44
|
+
/** The source; becomes the query's `source`. */
|
|
45
|
+
datasource?: string;
|
|
46
|
+
/** Comma-separated output fields, in order. */
|
|
47
|
+
columns?: string;
|
|
48
|
+
/** Rows rendered and fetched at once while scrolling. Default 40. */
|
|
49
|
+
windowSize?: number;
|
|
50
|
+
/** Switches from scrolling to paging. */
|
|
51
|
+
pageSize?: number;
|
|
52
|
+
mode?: Mode;
|
|
53
|
+
/** Up to two columns, outermost first: `"country,customer"`. */
|
|
54
|
+
groupBy?: string;
|
|
55
|
+
search?: boolean;
|
|
56
|
+
facets?: boolean;
|
|
57
|
+
toolbar?: boolean;
|
|
58
|
+
columnMenu?: boolean;
|
|
59
|
+
selection?: boolean;
|
|
60
|
+
density?: Density;
|
|
61
|
+
/** One of the built-in looks; Base when absent. */
|
|
62
|
+
theme?: Theme;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface OpengridTableProps extends Options, ElementProps {
|
|
66
|
+
label?: string;
|
|
67
|
+
datasource?: string;
|
|
68
|
+
columns?: string;
|
|
69
|
+
theme?: Theme;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface OpengridPivotProps extends Options, ElementProps {
|
|
73
|
+
label?: string;
|
|
74
|
+
datasource?: string;
|
|
75
|
+
/** Comma-separated row dimensions, outermost first. */
|
|
76
|
+
rows?: string;
|
|
77
|
+
/** Comma-separated column dimensions; V1 allows one. */
|
|
78
|
+
columns?: string;
|
|
79
|
+
/** The measures as the contract's JSON. */
|
|
80
|
+
values?: string;
|
|
81
|
+
theme?: Theme;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const OpengridGrid: Component<OpengridGridProps, {}, "view" | "element">;
|
|
85
|
+
export const OpengridTable: Component<OpengridTableProps, {}, "view" | "element">;
|
|
86
|
+
export const OpengridPivot: Component<OpengridPivotProps, {}, "view" | "element">;
|
package/svelte/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte 5 components for `@casoon/opengrid` (plan point 79, E32).
|
|
3
|
+
*
|
|
4
|
+
* Shipped as `.svelte` sources, the Svelte convention: the page's bundler
|
|
5
|
+
* compiles them with the page's Svelte. The three components are thin: each
|
|
6
|
+
* maps its props onto its element's attributes and hands the rest to
|
|
7
|
+
* `Opengrid.svelte`, which renders the element and keeps one `connect`.
|
|
8
|
+
*/
|
|
9
|
+
export { default as OpengridGrid } from "./OpengridGrid.svelte";
|
|
10
|
+
export { default as OpengridTable } from "./OpengridTable.svelte";
|
|
11
|
+
export { default as OpengridPivot } from "./OpengridPivot.svelte";
|
package/vue/index.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for `@casoon/opengrid/vue` (plan point 78).
|
|
3
|
+
*
|
|
4
|
+
* The props are the element's attributes in camelCase plus the options of
|
|
5
|
+
* `connect` from `@casoon/opengrid`; the callbacks are Vue events instead:
|
|
6
|
+
* `update:view` (so `v-model:view` works), `selectionChange` and `cellChange`
|
|
7
|
+
* — `@selection-change` and `@cell-change` in a template.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { DefineSetupFnComponent } from "vue";
|
|
11
|
+
import type {
|
|
12
|
+
CellChangeDetail,
|
|
13
|
+
ConnectOptions,
|
|
14
|
+
Density,
|
|
15
|
+
Theme,
|
|
16
|
+
Mode,
|
|
17
|
+
SelectionChangeDetail,
|
|
18
|
+
View,
|
|
19
|
+
} from "../loader.js";
|
|
20
|
+
|
|
21
|
+
/** `connect`'s options, less the callbacks — those are events here. */
|
|
22
|
+
type Options = Omit<ConnectOptions, "onViewChange" | "onSelectionChange" | "onCellChange">;
|
|
23
|
+
|
|
24
|
+
/** A type, not an interface: Vue's `EmitsOptions` wants an index signature. */
|
|
25
|
+
export type OpengridEmits = {
|
|
26
|
+
/** The reader changed the view; `v-model:view` writes it back. */
|
|
27
|
+
"update:view": (view: View) => void;
|
|
28
|
+
selectionChange: (detail: SelectionChangeDetail) => void;
|
|
29
|
+
cellChange: (detail: CellChangeDetail) => void;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export interface OpengridGridProps extends Options {
|
|
33
|
+
/** The accessible name of the table. */
|
|
34
|
+
label?: string;
|
|
35
|
+
/** The source; becomes the query's `source`. */
|
|
36
|
+
datasource?: string;
|
|
37
|
+
/** Comma-separated output fields, in order. */
|
|
38
|
+
columns?: string;
|
|
39
|
+
/** Rows rendered and fetched at once while scrolling. Default 40. */
|
|
40
|
+
windowSize?: number;
|
|
41
|
+
/** Switches from scrolling to paging. */
|
|
42
|
+
pageSize?: number;
|
|
43
|
+
mode?: Mode;
|
|
44
|
+
/** Up to two columns, outermost first: `"country,customer"`. */
|
|
45
|
+
groupBy?: string;
|
|
46
|
+
search?: boolean;
|
|
47
|
+
facets?: boolean;
|
|
48
|
+
toolbar?: boolean;
|
|
49
|
+
columnMenu?: boolean;
|
|
50
|
+
selection?: boolean;
|
|
51
|
+
density?: Density;
|
|
52
|
+
/** One of the built-in looks; Base when absent. */
|
|
53
|
+
theme?: Theme;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface OpengridTableProps extends Options {
|
|
57
|
+
label?: string;
|
|
58
|
+
datasource?: string;
|
|
59
|
+
columns?: string;
|
|
60
|
+
theme?: Theme;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface OpengridPivotProps extends Options {
|
|
64
|
+
label?: string;
|
|
65
|
+
datasource?: string;
|
|
66
|
+
/** Comma-separated row dimensions, outermost first. */
|
|
67
|
+
rows?: string;
|
|
68
|
+
/** Comma-separated column dimensions; V1 allows one. */
|
|
69
|
+
columns?: string;
|
|
70
|
+
/** The measures as the contract's JSON. */
|
|
71
|
+
values?: string;
|
|
72
|
+
theme?: Theme;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const OpengridGrid: DefineSetupFnComponent<OpengridGridProps, OpengridEmits>;
|
|
76
|
+
export const OpengridTable: DefineSetupFnComponent<OpengridTableProps, OpengridEmits>;
|
|
77
|
+
export const OpengridPivot: DefineSetupFnComponent<OpengridPivotProps, OpengridEmits>;
|
package/vue/index.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue components for `@casoon/opengrid` (plan point 78, E32).
|
|
3
|
+
*
|
|
4
|
+
* The same thin shell as the React adapter: the component renders the custom
|
|
5
|
+
* element with its attributes, and hands everything else — provider, texts,
|
|
6
|
+
* formats, presentation, choices, the view and the events — to one `connect`.
|
|
7
|
+
*
|
|
8
|
+
* What only a Vue shell has to know:
|
|
9
|
+
*
|
|
10
|
+
* - **The element is rendered with `h()`,** so Vue never tries to resolve
|
|
11
|
+
* `opengrid-grid` as a component — no `compilerOptions.isCustomElement` for
|
|
12
|
+
* the page. (A page that writes the bare element in a template needs it.)
|
|
13
|
+
* `class`, `style`, `id` and `aria-*` fall through to it, as Vue does for a
|
|
14
|
+
* component's root.
|
|
15
|
+
* - **Events in camelCase** (`selectionChange`, `cellChange`), which a
|
|
16
|
+
* template writes as `@selection-change` — Vue normalizes the two, and only
|
|
17
|
+
* the camelCase form gives typed `onSelectionChange` props.
|
|
18
|
+
* - **`v-model:view`:** the view comes in as a prop and goes out as
|
|
19
|
+
* `update:view`, which is the reader's change `connect` reports. Writing it
|
|
20
|
+
* back is no change, so the loop ends there.
|
|
21
|
+
* - **`<KeepAlive>` detaches, it does not unmount:** the connection stays, and
|
|
22
|
+
* the element brings back its own view and selection when it returns
|
|
23
|
+
* (docs/api.md §Connecting, plan point 74). Only an unmount disconnects. A
|
|
24
|
+
* view that changed while the grid was away waited in `connect` (there is no
|
|
25
|
+
* view to set on a detached element); reactivation hands it over.
|
|
26
|
+
* - **Watchers run after the render** (`flush: "post"`), so the element has
|
|
27
|
+
* its new attributes before an option follows: a new `datasource` and a new
|
|
28
|
+
* `provider` together ask once, a view naming a new column finds it.
|
|
29
|
+
* - **The view is controlled like in React:** a view the page does not take
|
|
30
|
+
* back from `update:view` is written again — on the next tick, once Vue has
|
|
31
|
+
* had its chance to pass the new one down.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import { defineComponent, h, nextTick, onActivated, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
35
|
+
import { connect } from "../loader.js";
|
|
36
|
+
|
|
37
|
+
/** The options of `connect` that are props; deep ones compare by value. */
|
|
38
|
+
const SHALLOW = ["provider"];
|
|
39
|
+
const DEEP = ["texts", "formats", "presentation", "choices", "view"];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Builds one component.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} tag the custom element.
|
|
45
|
+
* @param {string} name the component's name in the Vue tools.
|
|
46
|
+
* @param {Record<string, string>} attributes prop name → attribute name.
|
|
47
|
+
* @param {string[]} booleans the props that are boolean attributes.
|
|
48
|
+
*/
|
|
49
|
+
function component(tag, name, attributes, booleans) {
|
|
50
|
+
const props = {};
|
|
51
|
+
for (const prop of Object.keys(attributes)) {
|
|
52
|
+
props[prop] = booleans.includes(prop) ? { type: Boolean, default: false } : null;
|
|
53
|
+
}
|
|
54
|
+
for (const option of [...SHALLOW, ...DEEP, "defaultView"]) {
|
|
55
|
+
props[option] = { type: null, default: undefined };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return defineComponent({
|
|
59
|
+
name,
|
|
60
|
+
props,
|
|
61
|
+
emits: ["update:view", "selectionChange", "cellChange"],
|
|
62
|
+
setup(props, { emit }) {
|
|
63
|
+
const element = ref(null);
|
|
64
|
+
let connection = null;
|
|
65
|
+
|
|
66
|
+
onMounted(() => {
|
|
67
|
+
if (props.view != null && props.defaultView != null) {
|
|
68
|
+
console.warn(`[opengrid] <${name}> has both view and defaultView; the view is controlled and leads`);
|
|
69
|
+
}
|
|
70
|
+
const options = {
|
|
71
|
+
onViewChange: (view) => {
|
|
72
|
+
emit("update:view", view);
|
|
73
|
+
nextTick(() => {
|
|
74
|
+
if (props.view != null) connection?.update({ view: props.view });
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
onSelectionChange: (detail) => emit("selectionChange", detail),
|
|
78
|
+
onCellChange: (detail) => emit("cellChange", detail),
|
|
79
|
+
};
|
|
80
|
+
for (const option of [...SHALLOW, ...DEEP, "defaultView"]) {
|
|
81
|
+
if (props[option] !== undefined) {
|
|
82
|
+
options[option] = props[option];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
connection = connect(element.value, options);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// A changed option is passed on, and one that went away is passed as
|
|
89
|
+
// `undefined`, which resets it (`connect`).
|
|
90
|
+
for (const option of SHALLOW) {
|
|
91
|
+
watch(
|
|
92
|
+
() => props[option],
|
|
93
|
+
(value) => connection?.update({ [option]: value }),
|
|
94
|
+
{ flush: "post" },
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
for (const option of DEEP) {
|
|
98
|
+
watch(
|
|
99
|
+
() => props[option],
|
|
100
|
+
(value) => connection?.update({ [option]: value }),
|
|
101
|
+
{ deep: true, flush: "post" },
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
onActivated(() => connection?.update({}));
|
|
105
|
+
|
|
106
|
+
onBeforeUnmount(() => {
|
|
107
|
+
connection?.disconnect();
|
|
108
|
+
connection = null;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return () => {
|
|
112
|
+
const rendered = { ref: element };
|
|
113
|
+
for (const [prop, attribute] of Object.entries(attributes)) {
|
|
114
|
+
const value = props[prop];
|
|
115
|
+
if (booleans.includes(prop)) {
|
|
116
|
+
rendered[attribute] = value ? "" : undefined;
|
|
117
|
+
} else {
|
|
118
|
+
rendered[attribute] = value == null ? undefined : String(value);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return h(tag, rendered);
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const OpengridGrid = component(
|
|
128
|
+
"opengrid-grid",
|
|
129
|
+
"OpengridGrid",
|
|
130
|
+
{
|
|
131
|
+
label: "label",
|
|
132
|
+
datasource: "datasource",
|
|
133
|
+
columns: "columns",
|
|
134
|
+
windowSize: "window-size",
|
|
135
|
+
pageSize: "page-size",
|
|
136
|
+
mode: "mode",
|
|
137
|
+
groupBy: "group-by",
|
|
138
|
+
search: "search",
|
|
139
|
+
facets: "facets",
|
|
140
|
+
toolbar: "toolbar",
|
|
141
|
+
columnMenu: "column-menu",
|
|
142
|
+
selection: "selection",
|
|
143
|
+
density: "density",
|
|
144
|
+
theme: "theme",
|
|
145
|
+
},
|
|
146
|
+
["search", "facets", "toolbar", "columnMenu", "selection"],
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
export const OpengridTable = component(
|
|
150
|
+
"opengrid-table",
|
|
151
|
+
"OpengridTable",
|
|
152
|
+
{ label: "label", datasource: "datasource", columns: "columns", theme: "theme" },
|
|
153
|
+
[],
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
export const OpengridPivot = component(
|
|
157
|
+
"opengrid-pivot",
|
|
158
|
+
"OpengridPivot",
|
|
159
|
+
{
|
|
160
|
+
label: "label",
|
|
161
|
+
datasource: "datasource",
|
|
162
|
+
rows: "rows",
|
|
163
|
+
columns: "columns",
|
|
164
|
+
values: "values",
|
|
165
|
+
theme: "theme",
|
|
166
|
+
},
|
|
167
|
+
[],
|
|
168
|
+
);
|
|
File without changes
|
|
File without changes
|