@yuneta/gobj-ui 7.26.43 → 7.26.45

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/src/c_yui_form.js CHANGED
@@ -132,7 +132,7 @@ SDATA(data_type_t.DTP_STRING, "pkey", 0, "id", "Primary key fie
132
132
  SDATA(data_type_t.DTP_STRING, "topic_name", 0, "", "Treedb topic name: labels use the i18n cascade '<topic>.<col>' -> '<col>' -> header (like table headers)"),
133
133
  SDATA(data_type_t.DTP_BOOLEAN, "editable", 0, false, "Default is editable, set false to readonly"),
134
134
  SDATA(data_type_t.DTP_BOOLEAN, "readonly", 0, false, "Show EVERY field read-only, whatever its schema says: a record being LOOKED at, not edited. Independent of `editable`, which drives the TABLE rendering; this one drives the FORM"),
135
- SDATA(data_type_t.DTP_BOOLEAN, "selectable", 0, true, "Rows selectable with 'click' (BAD with editable=true)"),
135
+ SDATA(data_type_t.DTP_BOOLEAN, "selectable", 0, true, "A click selects a row, when tabulator_settings selects rows (selectableRows)"),
136
136
  SDATA(data_type_t.DTP_BOOLEAN, "with_checkbox", 0, false, "Show a first column with checkbox to select rows"),
137
137
  SDATA(data_type_t.DTP_BOOLEAN, "with_rownum", 0, false, "Print first column with row number"),
138
138
  SDATA(data_type_t.DTP_BOOLEAN, "with_delete_row_btn", 0, false, "Print last column with delete row button"),
@@ -613,6 +613,22 @@ function destroy_widget(gobj, what, widget)
613
613
  }
614
614
  }
615
615
 
616
+ /************************************************************
617
+ * Close the cell editor a table has open, dropping what is
618
+ * typed in it, before its rows are wiped. Tabulator 6.6.0
619
+ * closes it while it wipes them, and the redraw that follows
620
+ * walks the rows already wiped: a reload, a Clear or a destroy
621
+ * with an editor open in any row but the first threw, and left
622
+ * the table half wiped.
623
+ ************************************************************/
624
+ function close_table_editor(tabulator)
625
+ {
626
+ let edit = tabulator.modules? tabulator.modules.edit : null;
627
+ if(edit && edit.currentCell) {
628
+ edit.cancelEdit();
629
+ }
630
+ }
631
+
616
632
  /************************************************************
617
633
  * A table element that is gone: its identity is no table now,
618
634
  * and what was waiting to be loaded in it never will be.
@@ -639,6 +655,7 @@ function destroy_row_tables(gobj, $row)
639
655
  $row.yui_nested = null;
640
656
  for(let $nested of nested) {
641
657
  if($nested.tabulator) {
658
+ close_table_editor($nested.tabulator);
642
659
  destroy_rows_tables(gobj, $nested.tabulator);
643
660
  destroy_widget(gobj, "nested table", $nested.tabulator);
644
661
  $nested.tabulator = null;
@@ -677,6 +694,7 @@ function destroy_widgets(gobj, $container)
677
694
  $el.jsoneditor = null;
678
695
  }
679
696
  if($el.tabulator) {
697
+ close_table_editor($el.tabulator);
680
698
  destroy_rows_tables(gobj, $el.tabulator);
681
699
  destroy_widget(gobj, "table", $el.tabulator);
682
700
  $el.tabulator = null;
@@ -2222,7 +2240,8 @@ function create_coordinates(gobj, attrs)
2222
2240
  * Create tabulator
2223
2241
  *
2224
2242
  * A row builds its nested tables the first time it is drawn, each
2225
- * loaded from the row's own data, and keeps them on its element
2243
+ * BUILT with the rows of the row's own data (`rows`, a copy: the
2244
+ * table keeps what it is given), and keeps them on its element
2226
2245
  * (`yui_nested`) until the row goes (destroy_row_tables). A row
2227
2246
  * drawn AGAIN -- a forced redraw, a column rebuilt -- has its
2228
2247
  * children taken off by Tabulator before its formatter runs: they
@@ -2233,25 +2252,35 @@ function create_coordinates(gobj, attrs)
2233
2252
  * `tableBuilt`, ONE per table (`yui_pending_rows`): a later load
2234
2253
  * replaces it, a clear drops it. Each load used to hang a listener
2235
2254
  * of its own, so two loads before the build drew the rows twice.
2255
+ *
2256
+ * A nested table is not loaded after it is built, as the form's
2257
+ * own tables are (EV_LOAD_TABLE_ROWS): each such load laid it out
2258
+ * twice and redrew it once more, and with a nested table per row
2259
+ * that was most of the time of a load.
2260
+ *
2261
+ * A table selects rows only when a host sets `selectableRows` (true
2262
+ * or a number) in `tabulator_settings`. Tabulator's SelectRow then
2263
+ * toggles a row on its own click, asking `selectableRowsCheck` --
2264
+ * the form's `selectable` -- first. Up to 7.26.44 the form toggled
2265
+ * the row again in `rowClick`, which undid every click. The default
2266
+ * `"highlight"` is left as it is, hover and all.
2236
2267
  ******************************************************************/
2237
- function create_tabulator(gobj, $extend, name, template)
2268
+ function create_tabulator(gobj, $extend, name, template, rows)
2238
2269
  {
2239
- function get_selectable_state(row) {
2240
- return gobj_write_bool_attr(gobj, "selectable");
2241
- }
2242
-
2243
2270
  $extend.template = template;
2244
2271
 
2245
2272
  let tabulator_settings = json_deep_copy(gobj_read_attr(gobj, "tabulator_settings"));
2273
+ if(is_array(rows) && rows.length > 0) {
2274
+ tabulator_settings.data = json_deep_copy(rows);
2275
+ }
2246
2276
 
2247
- Object.assign(tabulator_settings, {
2248
- /*
2249
- * HACK initially must be true, else doesn't work.
2250
- * Later could be set to false
2251
- */
2252
- // selectableRows: true, // Rows selected with click, if selectableRowsCheck() return true
2253
- //selectableRowsCheck: get_selectable_state,
2254
- });
2277
+ /* Tabulator toggles the row on its own click: `selectable` only vetoes */
2278
+ let selectable_rows = tabulator_settings.selectableRows;
2279
+ if(selectable_rows === true || typeof selectable_rows === "number") {
2280
+ tabulator_settings.selectableRowsCheck = function() {
2281
+ return gobj_read_bool_attr(gobj, "selectable");
2282
+ };
2283
+ }
2255
2284
 
2256
2285
  let columns = [];
2257
2286
  if(gobj_read_bool_attr(gobj, "with_rownum")) {
@@ -2288,13 +2317,12 @@ function create_tabulator(gobj, $extend, name, template)
2288
2317
  }
2289
2318
  ];
2290
2319
  let $extend = createElement2(extend);
2320
+ let rows = data[sub_element.name];
2291
2321
  $extend.tabulator = create_tabulator(
2292
- gobj, $extend, sub_element.name, sub_element.template
2322
+ gobj, $extend, sub_element.name, sub_element.template, rows
2293
2323
  );
2294
2324
  $row.appendChild($extend);
2295
2325
  $row.yui_nested.push($extend);
2296
- let rows = data[sub_element.name];
2297
- load_tabulator_data(gobj, $extend, is_array(rows)? rows : []);
2298
2326
  }
2299
2327
  };
2300
2328
  }
@@ -2389,20 +2417,12 @@ function create_tabulator(gobj, $extend, name, template)
2389
2417
  //e - the click event object
2390
2418
  //row - row component
2391
2419
  e.preventDefault();
2392
- if(get_selectable_state(row)) {
2393
- row.toggleSelect();
2394
- }
2395
2420
  });
2396
2421
 
2397
2422
  tabulator.on("cellClick", function(e, cell) {
2398
2423
  //e - the click event object
2399
2424
  //cell - cell component
2400
2425
  e.preventDefault();
2401
- let row = cell.getRow();
2402
- // if(get_selectable_state(row)) {
2403
- // // cannot set at same time with rowClick, one select and other de-select
2404
- // row.toggleSelect();
2405
- // }
2406
2426
  });
2407
2427
 
2408
2428
  return tabulator;
@@ -3136,6 +3156,7 @@ function clear_data(gobj, $form)
3136
3156
  $form.querySelectorAll('.yui-tabulator-table').forEach($table => {
3137
3157
  $table.yui_pending_rows = null;
3138
3158
  if($table.tabulator.initialized) {
3159
+ close_table_editor($table.tabulator);
3139
3160
  destroy_rows_tables(gobj, $table.tabulator);
3140
3161
  $table.tabulator.clearData();
3141
3162
  }
package/src/c_yui_node.js CHANGED
@@ -623,7 +623,8 @@ function translate_own_dom(gobj, $el)
623
623
  * A render can come from a click on one of them -- the active item
624
624
  * clicked again is a navigation to the same hash, done in the same
625
625
  * turn -- and that nav is still inside its publication of
626
- * EV_NAV_CLICKED.
626
+ * EV_NAV_CLICKED. They are not heard from the moment they leave:
627
+ * what one published in that turn was taken as the current nav's.
627
628
  ************************************************************/
628
629
  function clear_navs(gobj)
629
630
  {
@@ -637,6 +638,7 @@ function clear_navs(gobj)
637
638
  if($nav && $nav.parentNode) {
638
639
  $nav.parentNode.removeChild($nav);
639
640
  }
641
+ gobj_unsubscribe_event(nav, null, {}, gobj);
640
642
  priv.retired_navs.push(nav);
641
643
  }
642
644
  priv.navs = [];
@@ -1922,6 +1922,8 @@ function render_diagram(gobj)
1922
1922
  * its own node click, which it publishes from inside G6's dispatch
1923
1923
  * of that click: stopped there, the gobj went from under its own
1924
1924
  * publication and the G6 graph from under its own event.
1925
+ * It is not heard from the moment it leaves: what it published in
1926
+ * that turn reached the editor as the current drawing's.
1925
1927
  ***************************************************************/
1926
1928
  function destroy_diagram(gobj)
1927
1929
  {
@@ -1937,6 +1939,7 @@ function destroy_diagram(gobj)
1937
1939
  if($d && $d.parentNode) {
1938
1940
  $d.parentNode.removeChild($d);
1939
1941
  }
1942
+ gobj_unsubscribe_event(diagram, null, {}, gobj);
1940
1943
  priv.retired_diagrams.push(diagram);
1941
1944
  if(priv.retired_diagrams.length === 1) {
1942
1945
  gobj_post_event(gobj, "EV_DESTROY_DIAGRAMS", {}, gobj);
@@ -59,6 +59,7 @@ import {
59
59
 
60
60
  import {
61
61
  activate_focus_trap_on,
62
+ focus_trap_panel,
62
63
  } from "./shell_focus_trap.js";
63
64
  import {escape_is_taken} from "./escape_taken.js";
64
65
 
@@ -185,6 +186,10 @@ let PRIVATE_DATA = {
185
186
  * pushes its close handler when it opens and pops it when
186
187
  * it closes. Escape calls the top handler only — LIFO. */
187
188
  escape_stack: [],
189
+ /* The order of the last entry pushed: every entry carries its
190
+ * own (`seq`), so a window can tell an overlay opened after it
191
+ * (yui_shell_escape_order). */
192
+ escape_seq: 0,
188
193
  /* Overlay history integration (Back button ↔ modals/windows).
189
194
  * Each history-participating overlay (modal, floating window)
190
195
  * pushes a { id, close } record here when it opens, plus a
@@ -532,6 +537,7 @@ function mt_start(gobj)
532
537
  return;
533
538
  }
534
539
  if(escape_is_taken(ev)) {
540
+ take_back_focus(ev);
535
541
  return;
536
542
  }
537
543
  let top = priv.escape_stack[priv.escape_stack.length - 1];
@@ -2711,6 +2717,31 @@ function drawers(gobj, menu_id)
2711
2717
  return out;
2712
2718
  }
2713
2719
 
2720
+ /************************************************************
2721
+ * An Escape that closed an inline editor (a table cell) took the
2722
+ * focus with it, to <body>: the overlay that holds the focus (the
2723
+ * top trap: a dialog, a drawer) takes it back, as a window does --
2724
+ * a reader was left on the page, outside the dialog it was in.
2725
+ ************************************************************/
2726
+ function take_back_focus(ev)
2727
+ {
2728
+ if(!ev.target || ev.target.isConnected !== false) {
2729
+ return;
2730
+ }
2731
+ let active = document.activeElement;
2732
+ if(active && active !== document.body) {
2733
+ return;
2734
+ }
2735
+ let $panel = focus_trap_panel();
2736
+ if(!$panel || $panel.isConnected === false) {
2737
+ return;
2738
+ }
2739
+ if(!$panel.hasAttribute("tabindex")) {
2740
+ $panel.setAttribute("tabindex", "-1"); /* focusable, not in the Tab order */
2741
+ }
2742
+ $panel.focus();
2743
+ }
2744
+
2714
2745
  /************************************************************
2715
2746
  * Escape priority chain helpers — push/pop a {layer, handler}
2716
2747
  * record on `priv.escape_stack`. Escape calls the top entry
@@ -2725,7 +2756,8 @@ function push_escape(gobj, layer, handler)
2725
2756
  log_warning(`C_YUI_SHELL: push_escape('${layer}') on a shell that is gone: Escape will not close it`);
2726
2757
  return;
2727
2758
  }
2728
- priv.escape_stack.push({ layer: layer, handler: handler });
2759
+ priv.escape_seq += 1;
2760
+ priv.escape_stack.push({ layer: layer, handler: handler, seq: priv.escape_seq });
2729
2761
  }
2730
2762
 
2731
2763
  function pop_escape(gobj, handler)
@@ -4430,6 +4462,27 @@ function yui_shell_pop_escape(shell_gobj, handler)
4430
4462
  pop_escape(shell_gobj, handler);
4431
4463
  }
4432
4464
 
4465
+ /* The order of the overlay Escape closes first (the top of the
4466
+ * stack), 0 when there is none. The orders only grow, so a window
4467
+ * that kept the answer when it opened knows, at its own Escape,
4468
+ * whether an overlay was opened after it -- and yields the key to
4469
+ * the shell, which closes that overlay first:
4470
+ *
4471
+ * priv.escape_order = yui_shell_escape_order(shell); // opened
4472
+ * ...
4473
+ * if(yui_shell_escape_order(shell) > priv.escape_order) {
4474
+ * return; // not mine: the shell's
4475
+ * }
4476
+ */
4477
+ function yui_shell_escape_order(shell_gobj)
4478
+ {
4479
+ let priv = shell_gobj && shell_gobj.priv;
4480
+ if(!priv || !priv.escape_stack || priv.escape_stack.length === 0) {
4481
+ return 0;
4482
+ }
4483
+ return priv.escape_stack[priv.escape_stack.length - 1].seq;
4484
+ }
4485
+
4433
4486
  /* Overlay history integration — public API for overlays the shell does
4434
4487
  * not own (modals from shell_modals.js, floating C_YUI_WINDOW popups).
4435
4488
  *
@@ -4819,6 +4872,7 @@ export {
4819
4872
  yui_shell_toggle_drawer,
4820
4873
  yui_shell_push_escape,
4821
4874
  yui_shell_pop_escape,
4875
+ yui_shell_escape_order,
4822
4876
  yui_shell_register_overlay,
4823
4877
  yui_shell_overlay_dismissed,
4824
4878
  yui_shell_unpark_route,
@@ -80,10 +80,11 @@ import {
80
80
  yui_shell_window_layer,
81
81
  yui_shell_modal_layer,
82
82
  yui_shell_raise_window,
83
+ yui_shell_escape_order,
83
84
  yui_shell_watch_changes,
84
85
  yui_shell_unwatch_changes,
85
86
  } from "./c_yui_shell.js";
86
- import {activate_focus_trap_on, FOCUSABLE_SELECTOR} from "./shell_focus_trap.js";
87
+ import {activate_focus_trap_on, focus_trap_panel, FOCUSABLE_SELECTOR} from "./shell_focus_trap.js";
87
88
  import {escape_is_taken} from "./escape_taken.js";
88
89
 
89
90
  import "./c_yui_window.css";
@@ -181,6 +182,9 @@ let PRIVATE_DATA = {
181
182
  * release of its focus trap. */
182
183
  $lock: null,
183
184
  release_focus: null,
185
+ /* The top of the shell's Escape stack when the window started:
186
+ * an overlay opened after it takes the key first. */
187
+ escape_order: 0,
184
188
  };
185
189
 
186
190
  let __gclass__ = null;
@@ -313,6 +317,12 @@ function mt_create(gobj)
313
317
  * the first Tab of a keyboard reader landed in a window they had
314
318
  * not opened. A modal window takes it all the same: nothing else
315
319
  * can be used while it is up.
320
+ *
321
+ * Nor does one opened under an overlay that holds the focus (a
322
+ * modal window, a dialog, a drawer, a menu: all are drawn above
323
+ * the window layer). Up to gobj-ui 7.26.44 it took the focus where
324
+ * it could not be seen, and the next Tab gave it back to the
325
+ * overlay; it opens under it now, and is there when it goes.
316
326
  ***************************************************************/
317
327
  function mt_start(gobj)
318
328
  {
@@ -328,12 +338,16 @@ function mt_start(gobj)
328
338
  if(active && active !== document.body && !$container.contains(active)) {
329
339
  priv.opener = active;
330
340
  }
341
+ priv.escape_order = yui_shell_escape_order(yui_shell_of(gobj));
331
342
  let modal = gobj_read_bool_attr(gobj, "modal");
343
+ /* Read before a modal one puts up its own. */
344
+ let $trap = focus_trap_panel();
345
+ let under_an_overlay = !!$trap && !$trap.contains($container);
332
346
  if(modal && !priv.release_focus) {
333
347
  /* Saves the opener itself, and gives it back on release. */
334
348
  priv.release_focus = activate_focus_trap_on($container);
335
349
  }
336
- if(modal || opened_by_the_reader()) {
350
+ if(modal || (opened_by_the_reader() && !under_an_overlay)) {
337
351
  focus_target(gobj, $container).focus();
338
352
  }
339
353
  }
@@ -641,8 +655,9 @@ function window_root(gobj)
641
655
  /************************************************************
642
656
  * An Escape typed in the window. The callback only decides
643
657
  * whether the key is the window's -- not when `keyboard` is
644
- * off, nor one that what it was typed in took -- and sends
645
- * the event: the close is the ✕'s, in the action.
658
+ * off, nor one that what it was typed in took, nor while an
659
+ * overlay of the shell opened after the window is up -- and
660
+ * sends the event: the close is the ✕'s, in the action.
646
661
  ************************************************************/
647
662
  function on_escape_key(gobj, evt)
648
663
  {
@@ -664,6 +679,9 @@ function on_escape_key(gobj, evt)
664
679
  }
665
680
  return;
666
681
  }
682
+ if(yui_shell_escape_order(yui_shell_of(gobj)) > gobj.priv.escape_order) {
683
+ return; /* a shell overlay opened after the window: the shell closes it */
684
+ }
667
685
  evt.preventDefault();
668
686
  evt.stopPropagation();
669
687
  gobj_send_event(gobj, "EV_CLOSE_WINDOW", {key: "Escape"}, gobj);
@@ -747,7 +765,12 @@ function build_ui(gobj)
747
765
  *----------------------------------------------*/
748
766
  if(gobj_read_bool_attr(gobj, "auto_save_size_and_position")) {
749
767
  if(gobj_is_service(gobj)) {
750
- let rect = whole_rect(kw_get_local_storage_value(`${gobj_name(gobj)}-rect`));
768
+ let key = `${gobj_name(gobj)}-rect`;
769
+ let stored = kw_get_local_storage_value(key);
770
+ let rect = whole_rect(stored);
771
+ if(!rect && stored != null) {
772
+ log_warning(`${gobj_short_name(gobj)}: the saved position '${key}' is not a rect of four numbers: ignored`);
773
+ }
751
774
  if(rect) {
752
775
  rect.x = rect.x<0?0:rect.x;
753
776
  rect.y = rect.y<0?0:rect.y;
@@ -1689,6 +1712,8 @@ function ac_shell_changed(gobj, event, kw, src)
1689
1712
  gobj_write_attr(gobj, "back_overlay", null);
1690
1713
  priv.back_shell = null;
1691
1714
  }
1715
+ /* The order it kept is of the other shell's Escape stack. */
1716
+ priv.escape_order = going? 0 : yui_shell_escape_order(src);
1692
1717
 
1693
1718
  let $container = gobj_read_attr(gobj, "$container");
1694
1719
  if(!$container) {
@@ -60,6 +60,13 @@ vi.mock("tabulator-tables", () => {
60
60
  }
61
61
  };
62
62
  tables.push(this);
63
+ /* The rows it is built with (`data`): drawn, and no
64
+ * `dataChanged`, as Tabulator loads them. */
65
+ if(settings && Array.isArray(settings.data)) {
66
+ for(const record of settings.data) {
67
+ this.add(record, true);
68
+ }
69
+ }
63
70
  return new Proxy(this, {
64
71
  get(target, prop) {
65
72
  if(prop in target) {
@@ -80,7 +87,7 @@ vi.mock("tabulator-tables", () => {
80
87
  fn([]);
81
88
  }
82
89
  }
83
- add(record) {
90
+ add(record, silent) {
84
91
  /* The row's element lives in the table's, as in Tabulator:
85
92
  * a nested table drawn in it is inside the form. */
86
93
  const $row = document.createElement("div");
@@ -90,7 +97,9 @@ vi.mock("tabulator-tables", () => {
90
97
  this.settings.rowFormatter(row);
91
98
  }
92
99
  this.rows.push(row);
93
- this.emit("dataChanged");
100
+ if(!silent) {
101
+ this.emit("dataChanged");
102
+ }
94
103
  return row;
95
104
  }
96
105
  addRow(record) {
@@ -26,6 +26,9 @@
26
26
  * getData() with copies and a row's getData() with the row itself,
27
27
  * draws a row by running its formatter, says `dataChanged` per row
28
28
  * added, synchronously, and builds itself a turn after it is made.
29
+ * A click on a row toggles it before `rowClick`, as Tabulator's
30
+ * SelectRow does when the table selects rows: a form that toggled
31
+ * it again in `rowClick` (7.26.44) undid every click.
29
32
  *
30
33
  * Copyright (c) 2026, ArtGins.
31
34
  * All Rights Reserved.
@@ -52,7 +55,7 @@ vi.mock("tabulator-tables", () => {
52
55
  constructor($el, settings) {
53
56
  this.element = $el;
54
57
  this.settings = settings;
55
- this.options = {};
58
+ this.options = Object.assign({}, settings);
56
59
  this.handlers = {};
57
60
  this.initialized = false;
58
61
  this.destroyed = false;
@@ -62,12 +65,22 @@ vi.mock("tabulator-tables", () => {
62
65
  localize: {
63
66
  installLang: () => {
64
67
  }
68
+ },
69
+ edit: {
70
+ currentCell: false,
71
+ cancelEdit: () => {
72
+ this.modules.edit.currentCell = false;
73
+ }
65
74
  }
66
75
  };
67
76
  tables.push(this);
68
- /* Tabulator builds itself a turn after it is made. */
77
+ /* Tabulator builds itself a turn after it is made, with
78
+ * the rows it was given (`data`), saying no `dataChanged`. */
69
79
  setTimeout(() => {
70
80
  if(!this.destroyed) {
81
+ for(const record of (settings && settings.data) || []) {
82
+ this.add(record, true);
83
+ }
71
84
  this.initialized = true;
72
85
  this.emit("tableBuilt");
73
86
  }
@@ -97,13 +110,16 @@ vi.mock("tabulator-tables", () => {
97
110
  throw new Error("Table Not Initialized");
98
111
  }
99
112
  }
100
- add(record) {
113
+ add(record, silent) {
101
114
  const $row = document.createElement("div");
102
115
  this.element.appendChild($row);
103
116
  const row = {data: record, $row: $row};
104
117
  row.component = {
105
118
  getElement: () => row.$row,
106
119
  getData: () => row.data,
120
+ toggleSelect: () => {
121
+ this.toggle_row(row);
122
+ },
107
123
  delete: () => {
108
124
  this.delete_row(this.rows.indexOf(row));
109
125
  },
@@ -112,7 +128,9 @@ vi.mock("tabulator-tables", () => {
112
128
  this.settings.rowFormatter(row.component);
113
129
  }
114
130
  this.rows.push(row);
115
- this.emit("dataChanged");
131
+ if(!silent) {
132
+ this.emit("dataChanged");
133
+ }
116
134
  return row.component;
117
135
  }
118
136
  addRow(record) {
@@ -125,6 +143,26 @@ vi.mock("tabulator-tables", () => {
125
143
  this.calls.addData++;
126
144
  return Promise.resolve(records.map((record) => this.add(record)));
127
145
  }
146
+ /* SelectRow's own toggle, gated by `selectableRowsCheck`. */
147
+ toggle_row(row) {
148
+ let check = this.options.selectableRowsCheck || (() => true);
149
+ if(check(row.component)) {
150
+ row.selected = !row.selected;
151
+ }
152
+ }
153
+ /* A click on a row: SelectRow toggles it on its own `click`
154
+ * when the table selects rows, then Tabulator says `rowClick`. */
155
+ click_row(index) {
156
+ const row = this.rows[index];
157
+ let selectable_rows = this.options.selectableRows;
158
+ if(selectable_rows === true || typeof selectable_rows === "number") {
159
+ this.toggle_row(row);
160
+ }
161
+ this.emit("rowClick", {
162
+ preventDefault: () => {
163
+ }
164
+ }, row.component);
165
+ }
128
166
  getRows() {
129
167
  return this.rows.map((row) => row.component);
130
168
  }
@@ -156,8 +194,23 @@ vi.mock("tabulator-tables", () => {
156
194
  }
157
195
  this.settings.rowFormatter(row.component);
158
196
  }
197
+ /* A cell editor opened in a row, as a click on a cell does. */
198
+ open_editor(index) {
199
+ this.modules.edit.currentCell = this.rows[index];
200
+ }
201
+ /* What Tabulator 6.6.0 does when it wipes its rows with an
202
+ * editor open: the row that holds it closes it, and the redraw
203
+ * that follows walks the rows already wiped -- it throws when
204
+ * any row came before. */
205
+ wipe_rows() {
206
+ const editing = this.modules.edit.currentCell;
207
+ if(editing && this.rows.indexOf(editing) > 0) {
208
+ throw new TypeError("Cannot read properties of undefined (reading 'add')");
209
+ }
210
+ }
159
211
  clearData() {
160
212
  this.must_be_built();
213
+ this.wipe_rows();
161
214
  for(const row of this.rows) {
162
215
  while(row.$row.firstChild) {
163
216
  row.$row.removeChild(row.$row.firstChild);
@@ -175,6 +228,7 @@ vi.mock("tabulator-tables", () => {
175
228
  setLocale() {
176
229
  }
177
230
  destroy() {
231
+ this.wipe_rows();
178
232
  this.destroyed = true;
179
233
  }
180
234
  }
@@ -274,16 +328,16 @@ let seq = 0;
274
328
 
275
329
  /* `then(form)` runs in the same turn as the start, before any table
276
330
  * is built. */
277
- function build(rec, then)
331
+ function build(rec, then, extra)
278
332
  {
279
333
  const first = tables.length;
280
334
  const app = gobj_create_pure_child(`trapp${++seq}`, "C_TEST_TR_APP", {}, yuno);
281
335
  gobj_start(app);
282
- const form = gobj_create_pure_child(`trform${seq}`, "C_YUI_FORM", {
336
+ const form = gobj_create_pure_child(`trform${seq}`, "C_YUI_FORM", Object.assign({
283
337
  template: TEMPLATE,
284
338
  record: rec,
285
339
  editable: true,
286
- }, app);
340
+ }, extra || {}), app);
287
341
  gobj_start(form);
288
342
  if(then) {
289
343
  then(form);
@@ -486,4 +540,106 @@ describe("a table is loaded in one call", () => {
486
540
  expect(close_asks(form)).toBe(false);
487
541
  expect(errors()).toEqual([]);
488
542
  });
543
+
544
+ /* Up to 7.26.44 a nested table was built empty and loaded after
545
+ * its build -- laid out twice and redrawn once more, per row: with
546
+ * a nested table per row, most of the time of a load. */
547
+ test("a nested table is BUILT with its rows: no load of its own, no redraw", async () => {
548
+ const host_record = record();
549
+ const {form, first} = build(host_record);
550
+ await settle();
551
+ await new Promise(resolve => setTimeout(resolve, 60));
552
+ const alarms = alarms_of(first);
553
+ const triggers = triggers_of(alarms, 0);
554
+ expect(triggers.rows.map((r) => r.data)).toEqual([{measure: "temperature", value: 30}]);
555
+ expect(triggers.calls.addData).toBe(0);
556
+ expect(triggers.calls.redraw).toBe(0);
557
+ /* A copy: an edit there does not write into the record. */
558
+ triggers.edit_cell(0, "value", 31);
559
+ expect(host_record.alarms[0].triggers[0].value).toBe(30);
560
+ expect(gobj_read_attr(form, "record").alarms[0].triggers[0].value).toBe(30);
561
+ expect(gobj_read_attr(form, "edited")).toBe(true);
562
+ expect(errors()).toEqual([]);
563
+ });
564
+ });
565
+
566
+ describe("a click on a row", () => {
567
+ function click(alarms, index)
568
+ {
569
+ alarms.click_row(index);
570
+ }
571
+
572
+ test("does not WRITE the `selectable` attribute, and selects nothing when Tabulator selects no rows", async () => {
573
+ const {form, first} = build(record());
574
+ await settle();
575
+ const alarms = alarms_of(first);
576
+ click(alarms, 0);
577
+ expect(gobj_read_attr(form, "selectable")).toBe(true);
578
+ expect(alarms.rows[0].selected).toBeFalsy();
579
+ expect(errors()).toEqual([]);
580
+ });
581
+
582
+ test("selects the row when the form is selectable and its table selects rows", async () => {
583
+ const {first} = build(record(), null, {tabulator_settings: {selectableRows: true}});
584
+ await settle();
585
+ const alarms = alarms_of(first);
586
+ click(alarms, 1);
587
+ expect(alarms.rows[1].selected).toBe(true);
588
+ click(alarms, 1);
589
+ expect(alarms.rows[1].selected).toBeFalsy();
590
+ expect(errors()).toEqual([]);
591
+ });
592
+
593
+ test("selects nothing when the form is not selectable", async () => {
594
+ const {first} = build(record(), null, {
595
+ selectable: false,
596
+ tabulator_settings: {selectableRows: true}
597
+ });
598
+ await settle();
599
+ const alarms = alarms_of(first);
600
+ click(alarms, 1);
601
+ expect(alarms.rows[1].selected).toBeFalsy();
602
+ expect(errors()).toEqual([]);
603
+ });
604
+ });
605
+
606
+ describe("a cell editor open while its table goes", () => {
607
+ function warnings()
608
+ {
609
+ return logged.filter((l) => /warn|error/i.test(l.level) || /WARNING|ERROR/.test(l.msg));
610
+ }
611
+
612
+ test("a reload with an editor open in the second row reloads the rows", async () => {
613
+ const {form, first} = build(record());
614
+ await settle();
615
+ const alarms = alarms_of(first);
616
+ alarms.open_editor(1);
617
+ triggers_of(alarms, 1).open_editor(0);
618
+ gobj_send_event(form, "EV_LOAD_RECORD", {
619
+ template_version: 7,
620
+ alarms: [{name: "cold", triggers: [{measure: "temperature", value: 5}]}]
621
+ }, form);
622
+ await settle();
623
+ expect(shown(alarms)).toEqual([{name: "cold", values: [5]}]);
624
+ expect(warnings()).toEqual([]);
625
+ });
626
+
627
+ test("a destroy with an editor open in a second row destroys every table, silently", async () => {
628
+ const before = live();
629
+ const {form, first} = build({
630
+ template_version: 7,
631
+ alarms: [
632
+ {name: "a", triggers: [{measure: "m", value: 1}, {measure: "n", value: 2}]},
633
+ {name: "b", triggers: [{measure: "m", value: 3}]}
634
+ ]
635
+ });
636
+ await settle();
637
+ const alarms = alarms_of(first);
638
+ alarms.open_editor(1);
639
+ triggers_of(alarms, 0).open_editor(1);
640
+ gobj_stop(form);
641
+ gobj_destroy(form);
642
+ expect(live() - before).toBe(0);
643
+ expect(warnings()).toEqual([]);
644
+ });
489
645
  });