@casoon/opengrid 0.13.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 +491 -18
- package/README.md +17 -2
- package/engine/opengrid_wasm.d.ts +9 -0
- package/engine/opengrid_wasm.js +22 -0
- package/engine/opengrid_wasm_bg.wasm +0 -0
- package/engine/opengrid_wasm_bg.wasm.d.ts +1 -0
- package/loader.d.ts +215 -11
- package/loader.js +183 -43
- package/package.json +6 -6
- package/pkg/opengrid_web_components.d.ts +61 -26
- package/pkg/opengrid_web_components.js +250 -60
- package/pkg/opengrid_web_components_bg.wasm +0 -0
- package/pkg/opengrid_web_components_bg.wasm.d.ts +11 -8
- 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 +11 -1
- package/pkg/snippets/opengrid-web-components-ad6dc2c80732d2d3/inline0.js +0 -17
- /package/pkg/snippets/{opengrid-web-core-19b41f3fd18cf51f → opengrid-web-core-78fdded9b8a374ed}/inline0.js +0 -0
- /package/pkg/snippets/{opengrid-web-core-19b41f3fd18cf51f → opengrid-web-core-78fdded9b8a374ed}/inline1.js +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
// The language of the page at `host`: the nearest `lang` attribute, through
|
|
3
|
+
// shadow roots as well; empty when there is none or it is empty.
|
|
4
|
+
export function __opengrid_page_lang(host) {
|
|
5
|
+
for (let node = host; node; node = node.parentElement || (node.getRootNode && node.getRootNode().host) || null) {
|
|
6
|
+
const lang = node.getAttribute && node.getAttribute('lang');
|
|
7
|
+
if (lang !== null && lang !== undefined) return lang.trim();
|
|
8
|
+
}
|
|
9
|
+
return '';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// One observer for every host whose formats follow the page's language. It
|
|
13
|
+
// holds the hosts weakly, so a removed grid is still collected.
|
|
14
|
+
const followers = new Set();
|
|
15
|
+
const known = new WeakSet();
|
|
16
|
+
const roots = new WeakSet();
|
|
17
|
+
let observer = null;
|
|
18
|
+
export function __opengrid_follow_lang(host, relocalize) {
|
|
19
|
+
if (!known.has(host)) {
|
|
20
|
+
known.add(host);
|
|
21
|
+
followers.add(new WeakRef(host));
|
|
22
|
+
}
|
|
23
|
+
if (!observer) {
|
|
24
|
+
observer = new MutationObserver(() => {
|
|
25
|
+
for (const ref of [...followers]) {
|
|
26
|
+
const host = ref.deref();
|
|
27
|
+
if (!host) followers.delete(ref);
|
|
28
|
+
else if (host.isConnected) relocalize(host);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const watch = (node) => {
|
|
33
|
+
if (node && !roots.has(node)) {
|
|
34
|
+
roots.add(node);
|
|
35
|
+
observer.observe(node, { attributes: true, attributeFilter: ['lang'], subtree: true });
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
watch(host.ownerDocument.documentElement);
|
|
39
|
+
const root = host.getRootNode();
|
|
40
|
+
if (root !== host.ownerDocument) watch(root);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function __opengrid_intl_formatter(kind, locale, options) {
|
|
44
|
+
const loc = locale || undefined;
|
|
45
|
+
const format = kind === 'date'
|
|
46
|
+
? new Intl.DateTimeFormat(loc, options)
|
|
47
|
+
: new Intl.NumberFormat(loc, options);
|
|
48
|
+
return (text, value) => {
|
|
49
|
+
if (value === null || value === undefined) return '';
|
|
50
|
+
if (kind === 'date') {
|
|
51
|
+
const at = Date.parse(typeof value === 'string' && value.length === 10
|
|
52
|
+
? value + 'T00:00:00Z' : value);
|
|
53
|
+
return Number.isNaN(at) ? text : format.format(new Date(at));
|
|
54
|
+
}
|
|
55
|
+
const number = Number(value);
|
|
56
|
+
return Number.isFinite(number) ? format.format(number) : text;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
|
|
2
|
+
// Writes nothing when the node already shows exactly this text: one Text node
|
|
3
|
+
// with these characters, or no child for the empty string. A recycled cell
|
|
4
|
+
// that shows the same value again, and the status line on every scroll frame,
|
|
5
|
+
// then neither lose their Text node nor queue a mutation (a live region may
|
|
6
|
+
// announce a replaced node again). Whatever else the node holds, such as the
|
|
7
|
+
// chips drawn over a cell, is not equal and is replaced as before.
|
|
8
|
+
function setText(node, text) {
|
|
9
|
+
const first = node.firstChild;
|
|
10
|
+
if (first === null ? text === "" : first.nodeType === 3 && first.nextSibling === null && first.data === text) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
node.textContent = text;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// The same for attributes: a recycled slot is patched with the whole set of
|
|
17
|
+
// attributes a row has, nearly all of them already as they should be, and most
|
|
18
|
+
// of the removals name an attribute that is not there. Each is one comparison
|
|
19
|
+
// against the element instead of a write the browser has to record.
|
|
20
|
+
// `style` goes through the CSSOM (`style.cssText`), not `setAttribute`: a page
|
|
21
|
+
// whose policy has `style-src` without 'unsafe-inline' refuses a style
|
|
22
|
+
// attribute set from script, and the grid positions its rows with one. The
|
|
23
|
+
// CSSOM is not governed by `style-src`; the attribute reads back the same
|
|
24
|
+
// either way.
|
|
25
|
+
function setAttribute(node, name, value) {
|
|
26
|
+
if (name === "style" && node instanceof HTMLElement) {
|
|
27
|
+
if (node.style.cssText !== value) {
|
|
28
|
+
node.style.cssText = value;
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (node.nodeType === 1 && node.getAttribute(name) !== value) {
|
|
33
|
+
node.setAttribute(name, value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function removeAttribute(node, name) {
|
|
38
|
+
if (node.nodeType === 1 && node.hasAttribute(name)) {
|
|
39
|
+
node.removeAttribute(name);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function __opengrid_set_text(node, text) {
|
|
44
|
+
setText(node, text);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function __opengrid_set_attribute(node, name, value) {
|
|
48
|
+
setAttribute(node, name, value);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function __opengrid_remove_attribute(node, name) {
|
|
52
|
+
removeAttribute(node, name);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// A whole frame in one call. `ops` holds six numbers per patch: its kind, the
|
|
56
|
+
// node it is about, and two (offset, length) pairs into `text`, in UTF-16 units
|
|
57
|
+
// (a create: the tag; an attribute: name and value; a removal: the name; a
|
|
58
|
+
// text: the text; an append: the child's index in the first offset). Names,
|
|
59
|
+
// values and texts are cut from one string instead of crossing one by one.
|
|
60
|
+
function piece(text, ops, at) {
|
|
61
|
+
return text.substring(ops[at], ops[at] + ops[at + 1]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function __opengrid_apply_frame(document, table, ops, text) {
|
|
65
|
+
for (let at = 0; at < ops.length; at += 6) {
|
|
66
|
+
const node = table[ops[at + 1]];
|
|
67
|
+
switch (ops[at]) {
|
|
68
|
+
case 0:
|
|
69
|
+
table[ops[at + 1]] = document.createElement(piece(text, ops, at + 2));
|
|
70
|
+
break;
|
|
71
|
+
case 1:
|
|
72
|
+
setAttribute(
|
|
73
|
+
node,
|
|
74
|
+
piece(text, ops, at + 2),
|
|
75
|
+
piece(text, ops, at + 4),
|
|
76
|
+
);
|
|
77
|
+
break;
|
|
78
|
+
case 2:
|
|
79
|
+
removeAttribute(node, piece(text, ops, at + 2));
|
|
80
|
+
break;
|
|
81
|
+
case 3:
|
|
82
|
+
setText(node, piece(text, ops, at + 2));
|
|
83
|
+
break;
|
|
84
|
+
case 4:
|
|
85
|
+
node.appendChild(table[ops[at + 2]]);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
package/react/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
import type { ForwardRefExoticComponent, HTMLAttributes, RefAttributes } from "react";
|
|
22
22
|
import type {
|
|
23
|
+
CellWrites,
|
|
23
24
|
ConnectOptions,
|
|
24
25
|
Density,
|
|
25
26
|
Theme,
|
|
@@ -54,6 +55,10 @@ export interface OpengridGridProps extends ConnectOptions, ElementProps {
|
|
|
54
55
|
tree?: string;
|
|
55
56
|
/** The field the parent key refers to; `id` when absent. */
|
|
56
57
|
treeKey?: string;
|
|
58
|
+
/** The field that names a record: `key` in the editing events. */
|
|
59
|
+
rowKey?: string;
|
|
60
|
+
/** An empty row after the last one to type a new record into (`onRowAdd`). */
|
|
61
|
+
addRow?: boolean;
|
|
57
62
|
search?: boolean;
|
|
58
63
|
facets?: boolean;
|
|
59
64
|
toolbar?: boolean;
|
|
@@ -96,6 +101,13 @@ export interface OpengridPivotProps extends PivotConnectOptions, ElementProps {
|
|
|
96
101
|
theme?: Theme;
|
|
97
102
|
}
|
|
98
103
|
|
|
104
|
+
/**
|
|
105
|
+
* What the ref holds: the element, carrying the connection's `setCellState`
|
|
106
|
+
* and `setValues` — `useRef<OpengridGridRef>(null)`. The prop takes a ref to
|
|
107
|
+
* the plain element too.
|
|
108
|
+
*/
|
|
109
|
+
export type OpengridGridRef = OpengridGridElement & CellWrites;
|
|
110
|
+
|
|
99
111
|
export const OpengridGrid: ForwardRefExoticComponent<
|
|
100
112
|
OpengridGridProps & RefAttributes<OpengridGridElement>
|
|
101
113
|
>;
|
package/react/index.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* A thin shell around `connect`: the component renders the custom element with
|
|
7
7
|
* its attributes, and hands everything else — provider, texts, formats,
|
|
8
|
-
* presentation, choices, the view and the
|
|
9
|
-
* connection. The rules of the module functions live in `connect`, not here.
|
|
8
|
+
* presentation, choices, actions, validators, the view and the event
|
|
9
|
+
* callbacks — to one connection. The rules of the module functions live in `connect`, not here.
|
|
10
10
|
*
|
|
11
11
|
* Three things only a React shell has to know:
|
|
12
12
|
*
|
|
@@ -30,6 +30,9 @@
|
|
|
30
30
|
* - **An option is passed when it is set, or was set last time** — so a prop
|
|
31
31
|
* that goes away is reset (`connect`'s `undefined`), and one that was never
|
|
32
32
|
* there is not reset on every render.
|
|
33
|
+
* - **The ref is the element,** and the element behind it carries the
|
|
34
|
+
* connection's `setCellState` and `setValues` — there is no other object a
|
|
35
|
+
* React ref could be without ceasing to be the element.
|
|
33
36
|
*/
|
|
34
37
|
|
|
35
38
|
import { createElement, forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
@@ -50,6 +53,13 @@ const OPTIONS = [
|
|
|
50
53
|
"onViewChange",
|
|
51
54
|
"onSelectionChange",
|
|
52
55
|
"onCellChange",
|
|
56
|
+
"actions",
|
|
57
|
+
"validators",
|
|
58
|
+
"onRowAdd",
|
|
59
|
+
"onPaste",
|
|
60
|
+
"onBulkChange",
|
|
61
|
+
"onRowAction",
|
|
62
|
+
"onSourceReplaced",
|
|
53
63
|
];
|
|
54
64
|
|
|
55
65
|
/**
|
|
@@ -66,7 +76,15 @@ function component(tag, displayName, attributes, booleans) {
|
|
|
66
76
|
const connection = useRef(null);
|
|
67
77
|
/** The options of the last render, to tell a removed prop from an absent one. */
|
|
68
78
|
const previous = useRef({});
|
|
69
|
-
useImperativeHandle(
|
|
79
|
+
useImperativeHandle(
|
|
80
|
+
ref,
|
|
81
|
+
() =>
|
|
82
|
+
Object.assign(element.current, {
|
|
83
|
+
setCellState: (...args) => connection.current?.setCellState(...args),
|
|
84
|
+
setValues: (values) => connection.current?.setValues(values),
|
|
85
|
+
}),
|
|
86
|
+
[],
|
|
87
|
+
);
|
|
70
88
|
|
|
71
89
|
const rendered = { ref: element };
|
|
72
90
|
const options = {};
|
|
@@ -145,6 +163,8 @@ export const OpengridGrid = component(
|
|
|
145
163
|
groupBy: "group-by",
|
|
146
164
|
tree: "tree",
|
|
147
165
|
treeKey: "tree-key",
|
|
166
|
+
rowKey: "row-key",
|
|
167
|
+
addRow: "add-row",
|
|
148
168
|
search: "search",
|
|
149
169
|
facets: "facets",
|
|
150
170
|
toolbar: "toolbar",
|
|
@@ -153,7 +173,7 @@ export const OpengridGrid = component(
|
|
|
153
173
|
density: "density",
|
|
154
174
|
theme: "theme",
|
|
155
175
|
},
|
|
156
|
-
["search", "facets", "toolbar", "columnMenu", "selection"],
|
|
176
|
+
["search", "facets", "toolbar", "columnMenu", "selection", "addRow"],
|
|
157
177
|
);
|
|
158
178
|
|
|
159
179
|
export const OpengridTable = component(
|
package/svelte/Opengrid.svelte
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
too; everything else goes to one `connect` from `@casoon/opengrid`:
|
|
7
7
|
|
|
8
8
|
- One effect reads every option — objects through `$state.snapshot`, so a
|
|
9
|
-
change inside a `$state` object counts (for `formats
|
|
10
|
-
keep their identity) — and passes on what is set now or was set last time:
|
|
9
|
+
change inside a `$state` object counts (for `formats` and `validators`,
|
|
10
|
+
the functions in them keep their identity) — and passes on what is set now or was set last time:
|
|
11
11
|
a prop taken away is reset, one never given is left alone (the same rule
|
|
12
12
|
as the React adapter).
|
|
13
13
|
- `bind:view`: the view the reader changed is written into the bound prop;
|
|
@@ -17,7 +17,11 @@
|
|
|
17
17
|
React and Vue. A `view={…}` without `bind:` follows Svelte's rule for
|
|
18
18
|
bindable props: the reader's change becomes the component's own value,
|
|
19
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
|
|
20
|
+
- `bind:element` gives the page the element, as `ref` does in React;
|
|
21
|
+
`bind:this` the component, with the connection's `setCellState` and
|
|
22
|
+
`setValues`.
|
|
23
|
+
- `onrowadd` answers with the new row's state, as `onRowAdd` does in
|
|
24
|
+
`connect`.
|
|
21
25
|
- The connection is made once the element exists and closed when the
|
|
22
26
|
component is destroyed. The element keeps its own state for as long as it
|
|
23
27
|
lives (docs/api.md §Connecting).
|
|
@@ -37,9 +41,16 @@
|
|
|
37
41
|
formats,
|
|
38
42
|
presentation,
|
|
39
43
|
choices,
|
|
44
|
+
actions,
|
|
45
|
+
validators,
|
|
40
46
|
onviewchange,
|
|
41
47
|
onselectionchange,
|
|
42
48
|
oncellchange,
|
|
49
|
+
onrowadd,
|
|
50
|
+
onpaste,
|
|
51
|
+
onbulkchange,
|
|
52
|
+
onrowaction,
|
|
53
|
+
onsourcereplaced,
|
|
43
54
|
...rest
|
|
44
55
|
} = $props();
|
|
45
56
|
|
|
@@ -50,9 +61,11 @@
|
|
|
50
61
|
const options = {
|
|
51
62
|
provider,
|
|
52
63
|
texts: $state.snapshot(texts),
|
|
53
|
-
formats: formats &&
|
|
64
|
+
formats: formats && snapshotKeepingFunctions(formats),
|
|
54
65
|
presentation: $state.snapshot(presentation),
|
|
55
66
|
choices: $state.snapshot(choices),
|
|
67
|
+
actions: $state.snapshot(actions),
|
|
68
|
+
validators: validators && snapshotKeepingFunctions(validators),
|
|
56
69
|
view: $state.snapshot(view),
|
|
57
70
|
defaultView: $state.snapshot(defaultView),
|
|
58
71
|
};
|
|
@@ -67,6 +80,11 @@
|
|
|
67
80
|
},
|
|
68
81
|
onSelectionChange: (detail) => onselectionchange?.(detail),
|
|
69
82
|
onCellChange: (detail) => oncellchange?.(detail),
|
|
83
|
+
onRowAdd: (detail) => onrowadd?.(detail),
|
|
84
|
+
onPaste: (detail) => onpaste?.(detail),
|
|
85
|
+
onBulkChange: (detail) => onbulkchange?.(detail),
|
|
86
|
+
onRowAction: (detail) => onrowaction?.(detail),
|
|
87
|
+
onSourceReplaced: (detail) => onsourcereplaced?.(detail),
|
|
70
88
|
};
|
|
71
89
|
if (!connection) {
|
|
72
90
|
if (options.view != null && options.defaultView != null) {
|
|
@@ -87,16 +105,27 @@
|
|
|
87
105
|
});
|
|
88
106
|
});
|
|
89
107
|
|
|
90
|
-
/**
|
|
91
|
-
function
|
|
108
|
+
/** Plain values all the way down, the functions kept as they are. */
|
|
109
|
+
function snapshotKeepingFunctions(value) {
|
|
110
|
+
if (typeof value === "function" || value === null || typeof value !== "object") {
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
if (Array.isArray(value)) {
|
|
114
|
+
return value.map(snapshotKeepingFunctions);
|
|
115
|
+
}
|
|
92
116
|
return Object.fromEntries(
|
|
93
|
-
Object.entries(value).map(([
|
|
94
|
-
column,
|
|
95
|
-
typeof format === "function" ? format : $state.snapshot(format),
|
|
96
|
-
]),
|
|
117
|
+
Object.entries(value).map(([name, inner]) => [name, snapshotKeepingFunctions(inner)]),
|
|
97
118
|
);
|
|
98
119
|
}
|
|
99
120
|
|
|
121
|
+
export function setCellState(key, column, state, message) {
|
|
122
|
+
connection?.setCellState(key, column, state, message);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function setValues(values) {
|
|
126
|
+
connection?.setValues(values);
|
|
127
|
+
}
|
|
128
|
+
|
|
100
129
|
$effect(() => () => {
|
|
101
130
|
connection?.disconnect();
|
|
102
131
|
connection = null;
|
|
@@ -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(
|