@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.
@@ -1,9 +1,12 @@
1
1
  /* @ts-self-types="./opengrid_web_components.d.ts" */
2
- import { __opengrid_intl_formatter } from './snippets/opengrid-web-components-56667a20e9158a6a/inline0.js';
3
- import { __opengrid_define_element } from './snippets/opengrid-web-core-a3505e32fee0c1ed/inline1.js';
4
- import * as import1 from "./snippets/opengrid-web-core-a3505e32fee0c1ed/inline0.js"
5
- import * as import2 from "./snippets/opengrid-web-core-a3505e32fee0c1ed/inline0.js"
6
- import * as import3 from "./snippets/opengrid-web-core-a3505e32fee0c1ed/inline0.js"
2
+ import { __opengrid_numbers } from './snippets/opengrid-web-components-ef3def04de0cb619/inline0.js';
3
+ import { __opengrid_intl_formatter, __opengrid_page_lang } from './snippets/opengrid-web-components-ef3def04de0cb619/inline1.js';
4
+ import { __opengrid_define_element } from './snippets/opengrid-web-core-78fdded9b8a374ed/inline1.js';
5
+ import { __opengrid_apply_frame, __opengrid_remove_attribute, __opengrid_set_attribute, __opengrid_set_text } from './snippets/opengrid-web-core-78fdded9b8a374ed/inline2.js';
6
+ import * as import1 from "./snippets/opengrid-web-components-ef3def04de0cb619/inline1.js"
7
+ import * as import2 from "./snippets/opengrid-web-core-78fdded9b8a374ed/inline0.js"
8
+ import * as import3 from "./snippets/opengrid-web-core-78fdded9b8a374ed/inline0.js"
9
+ import * as import4 from "./snippets/opengrid-web-core-78fdded9b8a374ed/inline0.js"
7
10
 
8
11
 
9
12
  /**
@@ -230,22 +233,6 @@ export function set_columns(host, columns) {
230
233
  }
231
234
 
232
235
  /**
233
- * Overrides the texts a component writes itself (point 48).
234
- *
235
- * `texts` is a plain JS object with any subset of the keys `lang`, `loading`,
236
- * `matchesOne`, `matchesOther`, `empty`, `error`, `errorUnknown`,
237
- * `filterGroup`, `operatorLabel`, `valueLabel`, `clear` and `operators`; every
238
- * key left out keeps its English default. `{count}`, `{column}` and `{cause}`
239
- * are the placeholders. A `lang` is written onto the elements that carry these
240
- * texts — the grid's filter row and status line, the table's error paragraph —
241
- * so they are announced in the language they are written in. Never onto the
242
- * data: the cells are the page's, in the page's language.
243
- *
244
- * Exported as `set_texts` beside `set_provider`, and like it, it takes effect
245
- * immediately: the grid rebuilds, because its labels are part of the one-time
246
- * skeleton (the filter row, the scroll offset and the focus are carried
247
- * across). Call it **before** wiring the provider and the component renders the
248
- * right words from its first paint.
249
236
  * Sets the per-column display formats (plan point 42).
250
237
  *
251
238
  * `formats` is a plain JS object keyed by column name. A value is either a
@@ -297,6 +284,25 @@ export function set_row_state(host, provisional_key, state, detail) {
297
284
  }
298
285
 
299
286
  /**
287
+ * Overrides the texts a component writes itself (point 48).
288
+ *
289
+ * `texts` is a plain JS object with any subset of the keys `lang`, `loading`,
290
+ * `matchesOne`, `matchesOther`, `empty`, `error`, `errorUnknown`,
291
+ * `filterGroup`, `operatorLabel`, `valueLabel`, `clear` and `operators`; every
292
+ * key left out keeps its English default. `{count}`, `{column}` and `{cause}`
293
+ * are the placeholders. A `lang` is written onto the elements that carry these
294
+ * texts — the grid's filter row and status line, the table's error paragraph —
295
+ * so they are announced in the language they are written in. Never onto the
296
+ * data: the cells are the page's, in the page's language.
297
+ *
298
+ * A call adds to the texts an earlier one set; a key left out keeps what it was.
299
+ * `set_texts(host, null)` takes them all back to the English defaults.
300
+ *
301
+ * Exported as `set_texts` beside `set_provider`, and like it, it takes effect
302
+ * immediately: the grid rebuilds, because its labels are part of the one-time
303
+ * skeleton (the filter row, the scroll offset and the focus are carried
304
+ * across). Call it **before** wiring the provider and the component renders the
305
+ * right words from its first paint.
300
306
  * @param {HTMLElement} host
301
307
  * @param {any} values
302
308
  */
@@ -362,13 +368,36 @@ function __wbg_get_imports() {
362
368
  const ret = Error(getStringFromWasm0(arg0, arg1));
363
369
  return ret;
364
370
  },
365
- __wbg___opengrid_define_element_8f22e1bc45c60af7: function(arg0, arg1, arg2, arg3, arg4, arg5) {
371
+ __wbg___opengrid_apply_frame_274006c814153e24: function(arg0, arg1, arg2, arg3, arg4, arg5) {
372
+ __opengrid_apply_frame(arg0, arg1, getArrayU32FromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
373
+ },
374
+ __wbg___opengrid_define_element_e029e9dfe2895c49: function(arg0, arg1, arg2, arg3, arg4, arg5) {
366
375
  __opengrid_define_element(getStringFromWasm0(arg0, arg1), arg2, arg3, arg4, arg5);
367
376
  },
368
- __wbg___opengrid_intl_formatter_c545f3d8646ebd4b: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
377
+ __wbg___opengrid_intl_formatter_752d632f82498378: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
369
378
  const ret = __opengrid_intl_formatter(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), arg4);
370
379
  return ret;
371
380
  }, arguments); },
381
+ __wbg___opengrid_numbers_39e217a2530b2e30: function(arg0, arg1) {
382
+ const ret = __opengrid_numbers(getArrayF64FromWasm0(arg0, arg1));
383
+ return ret;
384
+ },
385
+ __wbg___opengrid_page_lang_589aafc79e2edbc3: function(arg0, arg1) {
386
+ const ret = __opengrid_page_lang(arg1);
387
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
388
+ const len1 = WASM_VECTOR_LEN;
389
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
390
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
391
+ },
392
+ __wbg___opengrid_remove_attribute_4b8f22ea47550b92: function(arg0, arg1, arg2) {
393
+ __opengrid_remove_attribute(arg0, getStringFromWasm0(arg1, arg2));
394
+ },
395
+ __wbg___opengrid_set_attribute_d4730f1b9472777a: function(arg0, arg1, arg2, arg3, arg4) {
396
+ __opengrid_set_attribute(arg0, getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
397
+ },
398
+ __wbg___opengrid_set_text_fbbfddf32358d69a: function(arg0, arg1, arg2) {
399
+ __opengrid_set_text(arg0, getStringFromWasm0(arg1, arg2));
400
+ },
372
401
  __wbg___wbindgen_boolean_get_fa956cfa2d1bd751: function(arg0) {
373
402
  const v = arg0;
374
403
  const ret = typeof(v) === 'boolean' ? v : undefined;
@@ -484,6 +513,14 @@ function __wbg_get_imports() {
484
513
  const ret = arg0.closest(getStringFromWasm0(arg1, arg2));
485
514
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
486
515
  }, arguments); },
516
+ __wbg_contains_7189b09a477442a6: function(arg0, arg1) {
517
+ const ret = arg0.contains(arg1);
518
+ return ret;
519
+ },
520
+ __wbg_createDocumentFragment_ce446e0179ac5610: function(arg0) {
521
+ const ret = arg0.createDocumentFragment();
522
+ return ret;
523
+ },
487
524
  __wbg_createElement_fcbc0805de826d62: function() { return handleError(function (arg0, arg1, arg2) {
488
525
  const ret = arg0.createElement(getStringFromWasm0(arg1, arg2));
489
526
  return ret;
@@ -520,6 +557,10 @@ function __wbg_get_imports() {
520
557
  const ret = arg0.firstChild;
521
558
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
522
559
  },
560
+ __wbg_firstElementChild_09d2c7dc8dd1cfd9: function(arg0) {
561
+ const ret = arg0.firstElementChild;
562
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
563
+ },
523
564
  __wbg_focus_2f77051f98540625: function() { return handleError(function (arg0) {
524
565
  arg0.focus();
525
566
  }, arguments); },
@@ -690,6 +731,16 @@ function __wbg_get_imports() {
690
731
  const ret = result;
691
732
  return ret;
692
733
  },
734
+ __wbg_instanceof_Node_d29e7ded486fd76a: function(arg0) {
735
+ let result;
736
+ try {
737
+ result = arg0 instanceof Node;
738
+ } catch (_) {
739
+ result = false;
740
+ }
741
+ const ret = result;
742
+ return ret;
743
+ },
693
744
  __wbg_instanceof_Object_33f20e6f12439f3e: function(arg0) {
694
745
  let result;
695
746
  try {
@@ -775,6 +826,10 @@ function __wbg_get_imports() {
775
826
  const ret = Object.keys(arg0);
776
827
  return ret;
777
828
  },
829
+ __wbg_lastChild_40cbea243f82ab94: function(arg0) {
830
+ const ret = arg0.lastChild;
831
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
832
+ },
778
833
  __wbg_left_7e76a74d0db1754f: function(arg0) {
779
834
  const ret = arg0.left;
780
835
  return ret;
@@ -827,6 +882,14 @@ function __wbg_get_imports() {
827
882
  const ret = new CustomEvent(getStringFromWasm0(arg0, arg1), arg2);
828
883
  return ret;
829
884
  }, arguments); },
885
+ __wbg_nextElementSibling_2c75764f70deca9d: function(arg0) {
886
+ const ret = arg0.nextElementSibling;
887
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
888
+ },
889
+ __wbg_nextSibling_0e94ccfa3c22fa3c: function(arg0) {
890
+ const ret = arg0.nextSibling;
891
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
892
+ },
830
893
  __wbg_now_86c0d4ba3fa605b8: function() {
831
894
  const ret = Date.now();
832
895
  return ret;
@@ -916,6 +979,10 @@ function __wbg_get_imports() {
916
979
  const ret = arg0.right;
917
980
  return ret;
918
981
  },
982
+ __wbg_scrollHeight_8cf19eb16ebc9b9b: function(arg0) {
983
+ const ret = arg0.scrollHeight;
984
+ return ret;
985
+ },
919
986
  __wbg_scrollIntoView_5262843155744b69: function(arg0) {
920
987
  arg0.scrollIntoView();
921
988
  },
@@ -947,6 +1014,9 @@ function __wbg_get_imports() {
947
1014
  const ret = Reflect.set(arg0, arg1, arg2);
948
1015
  return ret;
949
1016
  }, arguments); },
1017
+ __wbg_set_8a16b38e4805b298: function(arg0, arg1, arg2) {
1018
+ arg0[arg1 >>> 0] = arg2;
1019
+ },
950
1020
  __wbg_set_adoptedStyleSheets_5f0e5fd87d2f8755: function(arg0, arg1) {
951
1021
  arg0.adoptedStyleSheets = arg1;
952
1022
  },
@@ -977,6 +1047,9 @@ function __wbg_get_imports() {
977
1047
  __wbg_set_disabled_cad2c12b3643aa52: function(arg0, arg1) {
978
1048
  arg0.disabled = arg1 !== 0;
979
1049
  },
1050
+ __wbg_set_id_4beae8b813c092d8: function(arg0, arg1, arg2) {
1051
+ arg0.id = getStringFromWasm0(arg1, arg2);
1052
+ },
980
1053
  __wbg_set_inline_77b0fb4f96d76814: function(arg0, arg1) {
981
1054
  arg0.inline = __wbindgen_enum_ScrollLogicalPosition[arg1];
982
1055
  },
@@ -1097,12 +1170,16 @@ function __wbg_get_imports() {
1097
1170
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1098
1171
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1099
1172
  },
1173
+ __wbg_values_3151680f2b3c0a44: function(arg0) {
1174
+ const ret = Object.values(arg0);
1175
+ return ret;
1176
+ },
1100
1177
  __wbg_width_219185400361db86: function(arg0) {
1101
1178
  const ret = arg0.width;
1102
1179
  return ret;
1103
1180
  },
1104
1181
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1105
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 227, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1182
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 237, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1106
1183
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_4cfd459b66780f67___convert__closures_____invoke___wasm_bindgen_4cfd459b66780f67___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_4cfd459b66780f67___JsError___true_);
1107
1184
  return ret;
1108
1185
  },
@@ -1132,7 +1209,7 @@ function __wbg_get_imports() {
1132
1209
  return ret;
1133
1210
  },
1134
1211
  __wbindgen_cast_0000000000000007: function(arg0, arg1) {
1135
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [U32], shim_idx: 213, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1212
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [U32], shim_idx: 223, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1136
1213
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_4cfd459b66780f67___convert__closures_____invoke___u32______true_);
1137
1214
  return ret;
1138
1215
  },
@@ -1164,9 +1241,10 @@ function __wbg_get_imports() {
1164
1241
  return {
1165
1242
  __proto__: null,
1166
1243
  "./opengrid_web_components_bg.js": import0,
1167
- "./snippets/opengrid-web-core-a3505e32fee0c1ed/inline0.js": import1,
1168
- "./snippets/opengrid-web-core-a3505e32fee0c1ed/inline0.js": import2,
1169
- "./snippets/opengrid-web-core-a3505e32fee0c1ed/inline0.js": import3,
1244
+ "./snippets/opengrid-web-components-ef3def04de0cb619/inline1.js": import1,
1245
+ "./snippets/opengrid-web-core-78fdded9b8a374ed/inline0.js": import2,
1246
+ "./snippets/opengrid-web-core-78fdded9b8a374ed/inline0.js": import3,
1247
+ "./snippets/opengrid-web-core-78fdded9b8a374ed/inline0.js": import4,
1170
1248
  };
1171
1249
  }
1172
1250
 
@@ -1292,6 +1370,16 @@ function debugString(val) {
1292
1370
  return className;
1293
1371
  }
1294
1372
 
1373
+ function getArrayF64FromWasm0(ptr, len) {
1374
+ ptr = ptr >>> 0;
1375
+ return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
1376
+ }
1377
+
1378
+ function getArrayU32FromWasm0(ptr, len) {
1379
+ ptr = ptr >>> 0;
1380
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
1381
+ }
1382
+
1295
1383
  function getArrayU8FromWasm0(ptr, len) {
1296
1384
  ptr = ptr >>> 0;
1297
1385
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
@@ -1305,10 +1393,26 @@ function getDataViewMemory0() {
1305
1393
  return cachedDataViewMemory0;
1306
1394
  }
1307
1395
 
1396
+ let cachedFloat64ArrayMemory0 = null;
1397
+ function getFloat64ArrayMemory0() {
1398
+ if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
1399
+ cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
1400
+ }
1401
+ return cachedFloat64ArrayMemory0;
1402
+ }
1403
+
1308
1404
  function getStringFromWasm0(ptr, len) {
1309
1405
  return decodeText(ptr >>> 0, len);
1310
1406
  }
1311
1407
 
1408
+ let cachedUint32ArrayMemory0 = null;
1409
+ function getUint32ArrayMemory0() {
1410
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
1411
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
1412
+ }
1413
+ return cachedUint32ArrayMemory0;
1414
+ }
1415
+
1312
1416
  let cachedUint8ArrayMemory0 = null;
1313
1417
  function getUint8ArrayMemory0() {
1314
1418
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
@@ -1436,6 +1540,8 @@ function __wbg_finalize_init(instance, module) {
1436
1540
  wasm = instance.exports;
1437
1541
  wasmModule = module;
1438
1542
  cachedDataViewMemory0 = null;
1543
+ cachedFloat64ArrayMemory0 = null;
1544
+ cachedUint32ArrayMemory0 = null;
1439
1545
  cachedUint8ArrayMemory0 = null;
1440
1546
  wasm.__wbindgen_start();
1441
1547
  return wasm;
Binary file
@@ -0,0 +1,8 @@
1
+
2
+ export function __opengrid_numbers(values) {
3
+ const list = new Array(values.length);
4
+ for (let at = 0; at < list.length; at += 1) {
5
+ list[at] = values[at];
6
+ }
7
+ return list;
8
+ }
@@ -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 three event callbacks — to one
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(ref, () => element.current, []);
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(
@@ -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`, the functions in it
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 && snapshotFormats(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
- /** The formats as plain values, their functions kept as they are. */
91
- function snapshotFormats(value) {
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(([column, format]) => [
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;