@casoon/opengrid 0.14.0 → 0.15.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 +375 -19
- package/README.md +16 -1
- package/engine/opengrid_wasm_bg.wasm +0 -0
- package/loader.d.ts +62 -7
- package/loader.js +112 -43
- package/package.json +6 -6
- package/pkg/opengrid_web_components.d.ts +21 -16
- package/pkg/opengrid_web_components.js +134 -28
- package/pkg/opengrid_web_components_bg.wasm +0 -0
- package/pkg/snippets/opengrid-web-components-ef3def04de0cb619/inline0.js +8 -0
- package/pkg/snippets/opengrid-web-components-ef3def04de0cb619/inline1.js +58 -0
- package/pkg/snippets/opengrid-web-core-78fdded9b8a374ed/inline2.js +89 -0
- package/react/index.d.ts +12 -0
- package/react/index.js +24 -4
- package/svelte/Opengrid.svelte +39 -10
- package/svelte/OpengridGrid.svelte +15 -0
- package/svelte/index.d.ts +45 -16
- package/vue/index.d.ts +37 -5
- package/vue/index.js +33 -7
- package/worker.js +5 -1
- package/pkg/snippets/opengrid-web-components-56667a20e9158a6a/inline0.js +0 -17
- /package/pkg/snippets/{opengrid-web-core-a3505e32fee0c1ed → opengrid-web-core-78fdded9b8a374ed}/inline0.js +0 -0
- /package/pkg/snippets/{opengrid-web-core-a3505e32fee0c1ed → opengrid-web-core-78fdded9b8a374ed}/inline1.js +0 -0
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
groupBy,
|
|
13
13
|
tree,
|
|
14
14
|
treeKey,
|
|
15
|
+
rowKey,
|
|
16
|
+
addRow = false,
|
|
15
17
|
search = false,
|
|
16
18
|
facets = false,
|
|
17
19
|
toolbar = false,
|
|
@@ -27,9 +29,20 @@
|
|
|
27
29
|
/** A boolean attribute is present or absent; `false` is absent. */
|
|
28
30
|
const flag = (on) => (on ? "" : undefined);
|
|
29
31
|
const text = (value) => (value == null ? undefined : String(value));
|
|
32
|
+
|
|
33
|
+
let inner;
|
|
34
|
+
|
|
35
|
+
export function setCellState(key, column, state, message) {
|
|
36
|
+
inner.setCellState(key, column, state, message);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function setValues(values) {
|
|
40
|
+
inner.setValues(values);
|
|
41
|
+
}
|
|
30
42
|
</script>
|
|
31
43
|
|
|
32
44
|
<Opengrid
|
|
45
|
+
bind:this={inner}
|
|
33
46
|
tag="opengrid-grid"
|
|
34
47
|
attributes={{
|
|
35
48
|
label,
|
|
@@ -41,6 +54,8 @@
|
|
|
41
54
|
"group-by": groupBy,
|
|
42
55
|
tree,
|
|
43
56
|
"tree-key": treeKey,
|
|
57
|
+
"row-key": rowKey,
|
|
58
|
+
"add-row": flag(addRow),
|
|
44
59
|
search: flag(search),
|
|
45
60
|
facets: flag(facets),
|
|
46
61
|
toolbar: flag(toolbar),
|
package/svelte/index.d.ts
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The props are the element's attributes in camelCase plus the options of
|
|
5
5
|
* `connect` from `@casoon/opengrid`, with the callbacks in Svelte's own
|
|
6
|
-
* spelling — `onviewchange`, `onselectionchange`, `oncellchange
|
|
7
|
-
*
|
|
6
|
+
* spelling — `onviewchange`, `onselectionchange`, `oncellchange`, `onrowadd`,
|
|
7
|
+
* `onpaste`, `onbulkchange`, `onrowaction`, `onsourcereplaced` — `view`
|
|
8
|
+
* bindable (`bind:view`), the element itself through `bind:element`, and the
|
|
9
|
+
* grid's `setCellState` and `setValues` through `bind:this`.
|
|
8
10
|
* Everything else (`id`, `class`, `style`, `aria-*`) goes to the element.
|
|
9
11
|
*
|
|
10
12
|
* `view` is controlled through `bind:view`: a binding whose setter refuses the
|
|
@@ -16,27 +18,54 @@
|
|
|
16
18
|
import type { Component } from "svelte";
|
|
17
19
|
import type { HTMLAttributes } from "svelte/elements";
|
|
18
20
|
import type {
|
|
21
|
+
BulkChangeDetail,
|
|
19
22
|
CellChangeDetail,
|
|
23
|
+
CellWrites,
|
|
20
24
|
ConnectOptions,
|
|
21
25
|
Density,
|
|
22
26
|
Theme,
|
|
23
27
|
Mode,
|
|
24
28
|
PivotConnectOptions,
|
|
29
|
+
PasteDetail,
|
|
25
30
|
PivotView,
|
|
31
|
+
RowActionDetail,
|
|
26
32
|
SelectionChangeDetail,
|
|
33
|
+
SourceReplacedDetail,
|
|
27
34
|
View,
|
|
28
35
|
} from "../loader.js";
|
|
29
36
|
|
|
30
|
-
/** `connect
|
|
31
|
-
type
|
|
37
|
+
/** The callbacks of `connect`, which take Svelte's spelling here. */
|
|
38
|
+
type Callbacks =
|
|
39
|
+
| "onViewChange"
|
|
40
|
+
| "onSelectionChange"
|
|
41
|
+
| "onCellChange"
|
|
42
|
+
| "onRowAdd"
|
|
43
|
+
| "onPaste"
|
|
44
|
+
| "onBulkChange"
|
|
45
|
+
| "onRowAction"
|
|
46
|
+
| "onSourceReplaced";
|
|
47
|
+
|
|
48
|
+
/** The callbacks every component has, in Svelte's spelling. */
|
|
49
|
+
type SvelteCallbacks = {
|
|
32
50
|
/** The element, for `bind:element`. */
|
|
33
51
|
element?: HTMLElement;
|
|
34
|
-
/** The reader changed the view; `bind:view` has it already. */
|
|
35
|
-
onviewchange?: (view: View) => void;
|
|
36
52
|
onselectionchange?: (detail: SelectionChangeDetail) => void;
|
|
37
53
|
oncellchange?: (detail: CellChangeDetail) => void;
|
|
54
|
+
/** Answers with the new row's state, as `onRowAdd` does in `connect`. */
|
|
55
|
+
onrowadd?: ConnectOptions["onRowAdd"];
|
|
56
|
+
onpaste?: (detail: PasteDetail) => void;
|
|
57
|
+
onbulkchange?: (detail: BulkChangeDetail) => void;
|
|
58
|
+
onrowaction?: (detail: RowActionDetail) => void;
|
|
59
|
+
onsourcereplaced?: (detail: SourceReplacedDetail) => void;
|
|
38
60
|
};
|
|
39
61
|
|
|
62
|
+
/** `connect`'s options, the callbacks in Svelte's spelling. */
|
|
63
|
+
type Options = Omit<ConnectOptions, Callbacks> &
|
|
64
|
+
SvelteCallbacks & {
|
|
65
|
+
/** The reader changed the view; `bind:view` has it already. */
|
|
66
|
+
onviewchange?: (view: View) => void;
|
|
67
|
+
};
|
|
68
|
+
|
|
40
69
|
/** What the element itself takes, minus what the component owns. */
|
|
41
70
|
type ElementProps = Omit<HTMLAttributes<HTMLElement>, "children" | keyof Options>;
|
|
42
71
|
|
|
@@ -58,6 +87,10 @@ export interface OpengridGridProps extends Options, ElementProps {
|
|
|
58
87
|
tree?: string;
|
|
59
88
|
/** The field the parent key refers to; `id` when absent. */
|
|
60
89
|
treeKey?: string;
|
|
90
|
+
/** The field that names a record: `key` in the editing events. */
|
|
91
|
+
rowKey?: string;
|
|
92
|
+
/** An empty row after the last one to type a new record into (`onrowadd`). */
|
|
93
|
+
addRow?: boolean;
|
|
61
94
|
search?: boolean;
|
|
62
95
|
facets?: boolean;
|
|
63
96
|
toolbar?: boolean;
|
|
@@ -76,15 +109,10 @@ export interface OpengridTableProps extends Options, ElementProps {
|
|
|
76
109
|
}
|
|
77
110
|
|
|
78
111
|
/** The pivot's options: its view is a `PivotView`. */
|
|
79
|
-
type PivotOptions = Omit<
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
element?: HTMLElement;
|
|
84
|
-
onviewchange?: (view: PivotView) => void;
|
|
85
|
-
onselectionchange?: (detail: SelectionChangeDetail) => void;
|
|
86
|
-
oncellchange?: (detail: CellChangeDetail) => void;
|
|
87
|
-
};
|
|
112
|
+
type PivotOptions = Omit<PivotConnectOptions, Callbacks> &
|
|
113
|
+
SvelteCallbacks & {
|
|
114
|
+
onviewchange?: (view: PivotView) => void;
|
|
115
|
+
};
|
|
88
116
|
|
|
89
117
|
export interface OpengridPivotProps extends PivotOptions, ElementProps {
|
|
90
118
|
label?: string;
|
|
@@ -110,6 +138,7 @@ export interface OpengridPivotProps extends PivotOptions, ElementProps {
|
|
|
110
138
|
theme?: Theme;
|
|
111
139
|
}
|
|
112
140
|
|
|
113
|
-
|
|
141
|
+
/** What `bind:this` on `OpengridGrid` gives: the connection's cell writes. */
|
|
142
|
+
export const OpengridGrid: Component<OpengridGridProps, CellWrites, "view" | "element">;
|
|
114
143
|
export const OpengridTable: Component<OpengridTableProps, {}, "view" | "element">;
|
|
115
144
|
export const OpengridPivot: Component<OpengridPivotProps, {}, "view" | "element">;
|
package/vue/index.d.ts
CHANGED
|
@@ -3,25 +3,43 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The props are the element's attributes in camelCase plus the options of
|
|
5
5
|
* `connect` from `@casoon/opengrid`; the callbacks are Vue events instead:
|
|
6
|
-
* `update:view` (so `v-model:view` works), `selectionChange
|
|
7
|
-
*
|
|
6
|
+
* `update:view` (so `v-model:view` works), `selectionChange`, `cellChange`,
|
|
7
|
+
* `paste`, `bulkChange`, `rowAction` and `sourceReplaced` — `@selection-change`
|
|
8
|
+
* and so on in a template. `onRowAdd` stays a prop, because its answer is the
|
|
9
|
+
* new row's state; a template writes it as `@row-add` all the same.
|
|
8
10
|
*/
|
|
9
11
|
|
|
10
12
|
import type { DefineSetupFnComponent } from "vue";
|
|
11
13
|
import type {
|
|
14
|
+
BulkChangeDetail,
|
|
12
15
|
CellChangeDetail,
|
|
16
|
+
CellWrites,
|
|
13
17
|
ConnectOptions,
|
|
14
18
|
Density,
|
|
15
19
|
Theme,
|
|
16
20
|
Mode,
|
|
17
21
|
PivotConnectOptions,
|
|
22
|
+
OpengridGridElement,
|
|
23
|
+
PasteDetail,
|
|
18
24
|
PivotView,
|
|
25
|
+
RowActionDetail,
|
|
19
26
|
SelectionChangeDetail,
|
|
27
|
+
SourceReplacedDetail,
|
|
20
28
|
View,
|
|
21
29
|
} from "../loader.js";
|
|
22
30
|
|
|
23
|
-
/** `connect`
|
|
24
|
-
type
|
|
31
|
+
/** The callbacks of `connect` that are events here. */
|
|
32
|
+
type Callbacks =
|
|
33
|
+
| "onViewChange"
|
|
34
|
+
| "onSelectionChange"
|
|
35
|
+
| "onCellChange"
|
|
36
|
+
| "onPaste"
|
|
37
|
+
| "onBulkChange"
|
|
38
|
+
| "onRowAction"
|
|
39
|
+
| "onSourceReplaced";
|
|
40
|
+
|
|
41
|
+
/** `connect`'s options, less the callbacks that are events. */
|
|
42
|
+
type Options = Omit<ConnectOptions, Callbacks>;
|
|
25
43
|
|
|
26
44
|
/** A type, not an interface: Vue's `EmitsOptions` wants an index signature. */
|
|
27
45
|
export type OpengridEmits = {
|
|
@@ -29,8 +47,18 @@ export type OpengridEmits = {
|
|
|
29
47
|
"update:view": (view: View) => void;
|
|
30
48
|
selectionChange: (detail: SelectionChangeDetail) => void;
|
|
31
49
|
cellChange: (detail: CellChangeDetail) => void;
|
|
50
|
+
paste: (detail: PasteDetail) => void;
|
|
51
|
+
bulkChange: (detail: BulkChangeDetail) => void;
|
|
52
|
+
rowAction: (detail: RowActionDetail) => void;
|
|
53
|
+
sourceReplaced: (detail: SourceReplacedDetail) => void;
|
|
32
54
|
};
|
|
33
55
|
|
|
56
|
+
/**
|
|
57
|
+
* What a template ref on `OpengridGrid` holds: the connection's `setCellState`
|
|
58
|
+
* and `setValues`, and the element as `$el` — `ref<OpengridGridExposed | null>(null)`.
|
|
59
|
+
*/
|
|
60
|
+
export type OpengridGridExposed = CellWrites & { $el: OpengridGridElement };
|
|
61
|
+
|
|
34
62
|
export interface OpengridGridProps extends Options {
|
|
35
63
|
/** The accessible name of the table. */
|
|
36
64
|
label?: string;
|
|
@@ -49,6 +77,10 @@ export interface OpengridGridProps extends Options {
|
|
|
49
77
|
tree?: string;
|
|
50
78
|
/** The field the parent key refers to; `id` when absent. */
|
|
51
79
|
treeKey?: string;
|
|
80
|
+
/** The field that names a record: `key` in the editing events. */
|
|
81
|
+
rowKey?: string;
|
|
82
|
+
/** An empty row after the last one to type a new record into (`@row-add`). */
|
|
83
|
+
addRow?: boolean;
|
|
52
84
|
search?: boolean;
|
|
53
85
|
facets?: boolean;
|
|
54
86
|
toolbar?: boolean;
|
|
@@ -72,7 +104,7 @@ export type OpengridPivotEmits = Omit<OpengridEmits, "update:view"> & {
|
|
|
72
104
|
};
|
|
73
105
|
|
|
74
106
|
export interface OpengridPivotProps
|
|
75
|
-
extends Omit<PivotConnectOptions,
|
|
107
|
+
extends Omit<PivotConnectOptions, Callbacks> {
|
|
76
108
|
label?: string;
|
|
77
109
|
datasource?: string;
|
|
78
110
|
/** Comma-separated row dimensions, outermost first. */
|
package/vue/index.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The same thin shell as the React adapter: the component renders the custom
|
|
5
5
|
* element with its attributes, and hands everything else — provider, texts,
|
|
6
|
-
* formats, presentation, choices, the view and the
|
|
6
|
+
* formats, presentation, choices, actions, validators, the view and the
|
|
7
|
+
* events — to one `connect`.
|
|
7
8
|
*
|
|
8
9
|
* What only a Vue shell has to know:
|
|
9
10
|
*
|
|
@@ -15,6 +16,11 @@
|
|
|
15
16
|
* - **Events in camelCase** (`selectionChange`, `cellChange`), which a
|
|
16
17
|
* template writes as `@selection-change` — Vue normalizes the two, and only
|
|
17
18
|
* the camelCase form gives typed `onSelectionChange` props.
|
|
19
|
+
* - **`onRowAdd` is a prop, not an event:** its answer is the new row's
|
|
20
|
+
* state, and an emitted event has none. A template still writes it as
|
|
21
|
+
* `@row-add`, which Vue passes as the prop `onRowAdd`.
|
|
22
|
+
* - **The template ref** exposes `setCellState` and `setValues`; `$el` is
|
|
23
|
+
* the element, as before.
|
|
18
24
|
* - **`v-model:view`:** the view comes in as a prop and goes out as
|
|
19
25
|
* `update:view`, which is the reader's change `connect` reports. Writing it
|
|
20
26
|
* back is no change, so the loop ends there.
|
|
@@ -36,7 +42,17 @@ import { connect } from "../loader.js";
|
|
|
36
42
|
|
|
37
43
|
/** The options of `connect` that are props; deep ones compare by value. */
|
|
38
44
|
const SHALLOW = ["provider"];
|
|
39
|
-
const DEEP = ["texts", "formats", "presentation", "choices", "view"];
|
|
45
|
+
const DEEP = ["texts", "formats", "presentation", "choices", "actions", "validators", "view"];
|
|
46
|
+
|
|
47
|
+
/** The events, by `connect`'s callback. */
|
|
48
|
+
const EVENTS = {
|
|
49
|
+
onSelectionChange: "selectionChange",
|
|
50
|
+
onCellChange: "cellChange",
|
|
51
|
+
onPaste: "paste",
|
|
52
|
+
onBulkChange: "bulkChange",
|
|
53
|
+
onRowAction: "rowAction",
|
|
54
|
+
onSourceReplaced: "sourceReplaced",
|
|
55
|
+
};
|
|
40
56
|
|
|
41
57
|
/**
|
|
42
58
|
* Builds one component.
|
|
@@ -54,12 +70,13 @@ function component(tag, name, attributes, booleans) {
|
|
|
54
70
|
for (const option of [...SHALLOW, ...DEEP, "defaultView"]) {
|
|
55
71
|
props[option] = { type: null, default: undefined };
|
|
56
72
|
}
|
|
73
|
+
props.onRowAdd = { type: Function, default: undefined };
|
|
57
74
|
|
|
58
75
|
return defineComponent({
|
|
59
76
|
name,
|
|
60
77
|
props,
|
|
61
|
-
emits: ["update:view",
|
|
62
|
-
setup(props, { emit }) {
|
|
78
|
+
emits: ["update:view", ...Object.values(EVENTS)],
|
|
79
|
+
setup(props, { emit, expose }) {
|
|
63
80
|
const element = ref(null);
|
|
64
81
|
let connection = null;
|
|
65
82
|
|
|
@@ -74,9 +91,11 @@ function component(tag, name, attributes, booleans) {
|
|
|
74
91
|
if (props.view != null) connection?.update({ view: props.view });
|
|
75
92
|
});
|
|
76
93
|
},
|
|
77
|
-
|
|
78
|
-
onCellChange: (detail) => emit("cellChange", detail),
|
|
94
|
+
onRowAdd: (detail) => props.onRowAdd?.(detail),
|
|
79
95
|
};
|
|
96
|
+
for (const [callback, event] of Object.entries(EVENTS)) {
|
|
97
|
+
options[callback] = (detail) => emit(event, detail);
|
|
98
|
+
}
|
|
80
99
|
for (const option of [...SHALLOW, ...DEEP, "defaultView"]) {
|
|
81
100
|
if (props[option] !== undefined) {
|
|
82
101
|
options[option] = props[option];
|
|
@@ -103,6 +122,11 @@ function component(tag, name, attributes, booleans) {
|
|
|
103
122
|
}
|
|
104
123
|
onActivated(() => connection?.update({}));
|
|
105
124
|
|
|
125
|
+
expose({
|
|
126
|
+
setCellState: (...args) => connection?.setCellState(...args),
|
|
127
|
+
setValues: (values) => connection?.setValues(values),
|
|
128
|
+
});
|
|
129
|
+
|
|
106
130
|
onBeforeUnmount(() => {
|
|
107
131
|
connection?.disconnect();
|
|
108
132
|
connection = null;
|
|
@@ -137,6 +161,8 @@ export const OpengridGrid = component(
|
|
|
137
161
|
groupBy: "group-by",
|
|
138
162
|
tree: "tree",
|
|
139
163
|
treeKey: "tree-key",
|
|
164
|
+
rowKey: "row-key",
|
|
165
|
+
addRow: "add-row",
|
|
140
166
|
search: "search",
|
|
141
167
|
facets: "facets",
|
|
142
168
|
toolbar: "toolbar",
|
|
@@ -145,7 +171,7 @@ export const OpengridGrid = component(
|
|
|
145
171
|
density: "density",
|
|
146
172
|
theme: "theme",
|
|
147
173
|
},
|
|
148
|
-
["search", "facets", "toolbar", "columnMenu", "selection"],
|
|
174
|
+
["search", "facets", "toolbar", "columnMenu", "selection", "addRow"],
|
|
149
175
|
);
|
|
150
176
|
|
|
151
177
|
export const OpengridTable = component(
|
package/worker.js
CHANGED
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
* transferred, not copied. Nothing engine-specific is serialised here.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
+
// The packaged engine glue, imported statically so that a bundler follows it and
|
|
27
|
+
// the `.wasm` beside it; `init` names another one with `moduleUrl`.
|
|
28
|
+
import * as packaged from "./engine/opengrid_wasm.js";
|
|
29
|
+
|
|
26
30
|
/** The single engine instance, created on `init` and reused for every query. */
|
|
27
31
|
let engine;
|
|
28
32
|
|
|
@@ -32,7 +36,7 @@ self.onmessage = async ({ data }) => {
|
|
|
32
36
|
case "init": {
|
|
33
37
|
// wasm-bindgen `--target web`: the default export initialises the
|
|
34
38
|
// module; the named `Engine` class is created afterwards.
|
|
35
|
-
const module = await import(data.moduleUrl);
|
|
39
|
+
const module = data.moduleUrl ? await import(/* @vite-ignore */ data.moduleUrl) : packaged;
|
|
36
40
|
await module.default(data.wasmUrl);
|
|
37
41
|
engine = new module.Engine();
|
|
38
42
|
self.postMessage({ type: "ready", id: data.id });
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export function __opengrid_intl_formatter(kind, locale, options) {
|
|
3
|
-
const loc = locale || undefined;
|
|
4
|
-
const format = kind === 'date'
|
|
5
|
-
? new Intl.DateTimeFormat(loc, options)
|
|
6
|
-
: new Intl.NumberFormat(loc, options);
|
|
7
|
-
return (text, value) => {
|
|
8
|
-
if (value === null || value === undefined) return '';
|
|
9
|
-
if (kind === 'date') {
|
|
10
|
-
const at = Date.parse(typeof value === 'string' && value.length === 10
|
|
11
|
-
? value + 'T00:00:00Z' : value);
|
|
12
|
-
return Number.isNaN(at) ? text : format.format(new Date(at));
|
|
13
|
-
}
|
|
14
|
-
const number = Number(value);
|
|
15
|
-
return Number.isFinite(number) ? format.format(number) : text;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
File without changes
|
|
File without changes
|