@yuneta/gobj-ui 7.26.45 → 7.26.47

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.
@@ -139,7 +139,17 @@ function yui_tint(colour) {
139
139
  * that wrapped to it, did nothing and was prevented -- the
140
140
  * keyboard never got into the dialog.
141
141
  *
142
- * Pure module — no gobj / Yuneta dependencies. The optional
142
+ * A trap whose panel is out of the document is not the top:
143
+ * the top is the highest trap whose panel is in it. Up to
144
+ * gobj-ui 7.26.45 a trap left behind by an owner torn down with
145
+ * it stayed the top: every window opened later believed itself
146
+ * under an overlay and took no focus, and a live trap under it
147
+ * no longer heard Tab. 7.26.46 dropped such a trap from the
148
+ * stack, which was for good: a panel that only moved (taken out
149
+ * and put back, its trap never released) lost its trap. It is
150
+ * skipped now, and leaves the stack only by its release().
151
+ *
152
+ * No gobj dependency: only gobj-js's logger. The optional
143
153
  * second argument lets callers inject a mock document object
144
154
  * for unit tests.
145
155
  *
@@ -148,6 +158,13 @@ function yui_tint(colour) {
148
158
  ***********************************************************************/
149
159
  var FOCUSABLE_SELECTOR = "a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
150
160
  var __trap_stack__ = [];
161
+ function top_trap() {
162
+ for (let i = __trap_stack__.length - 1; i >= 0; i--) {
163
+ let trap = __trap_stack__[i];
164
+ if (trap.$panel.isConnected !== false) return trap;
165
+ }
166
+ return null;
167
+ }
151
168
  function is_drawn(el) {
152
169
  if (typeof el.checkVisibility === "function") return el.checkVisibility();
153
170
  if (typeof el.getClientRects === "function") return el.getClientRects().length > 0;
@@ -172,7 +189,7 @@ function activate_focus_trap_on($panel, doc) {
172
189
  let released = false;
173
190
  let trap = function(ev) {
174
191
  if (ev.key !== "Tab" && ev.keyCode !== 9) return;
175
- if (__trap_stack__[__trap_stack__.length - 1] !== trap) return;
192
+ if (top_trap() !== trap) return;
176
193
  let nodes = focusables_of($panel);
177
194
  if (nodes.length === 0) return;
178
195
  let first = nodes[0];
@@ -210,7 +227,7 @@ function activate_focus_trap_on($panel, doc) {
210
227
  * where it cannot be seen, and the next Tab would give it back.
211
228
  ***************************************************************/
212
229
  function focus_trap_panel() {
213
- let top = __trap_stack__[__trap_stack__.length - 1];
230
+ let top = top_trap();
214
231
  return top ? top.$panel : null;
215
232
  }
216
233
  //#endregion
@@ -1416,6 +1433,7 @@ function mt_start$21(gobj) {
1416
1433
  function mt_stop$20(gobj) {
1417
1434
  let priv = gobj.priv;
1418
1435
  if (!priv) return 0;
1436
+ retire_overlays(gobj);
1419
1437
  close_toolbar_dropdown(gobj);
1420
1438
  if (priv.hash_handler) {
1421
1439
  window.removeEventListener("hashchange", priv.hash_handler);
@@ -1470,6 +1488,7 @@ function mt_stop$20(gobj) {
1470
1488
  * Framework Method: Destroy
1471
1489
  ***************************************************************/
1472
1490
  function mt_destroy$22(gobj) {
1491
+ retire_overlays(gobj);
1473
1492
  close_toolbar_dropdown(gobj);
1474
1493
  let live_idx = __live_shells__.indexOf(gobj);
1475
1494
  if (live_idx >= 0) __live_shells__.splice(live_idx, 1);
@@ -2570,7 +2589,7 @@ function open_toolbar_dropdown(gobj, item, action, $trigger) {
2570
2589
  $panel.__yui_backdrop_handler__ = backdrop;
2571
2590
  $panel.__yui_dismiss_handler__ = dismiss;
2572
2591
  $panel.__yui_trigger__ = $trigger || null;
2573
- push_escape(gobj, "popup", close_fn);
2592
+ push_escape(gobj, "popup", close_fn, close_fn);
2574
2593
  $panel.__yui_focus_release__ = activate_focus_trap_on($panel);
2575
2594
  if ($trigger) $trigger.setAttribute("aria-expanded", "true");
2576
2595
  priv.active_dropdown = $panel;
@@ -2735,8 +2754,12 @@ function take_back_focus(ev) {
2735
2754
  * only and consumes the event; LIFO ordering naturally matches
2736
2755
  * the z-index layering most apps use (drawer at the bottom,
2737
2756
  * modal on top, popup on top of that).
2757
+ *
2758
+ * `teardown` is the overlay's UNCONDITIONAL close, what the shell
2759
+ * runs when it stops with the overlay still up (close_overlays);
2760
+ * `handler` may be a guarded one (a modal's before_close).
2738
2761
  ************************************************************/
2739
- function push_escape(gobj, layer, handler) {
2762
+ function push_escape(gobj, layer, handler, teardown) {
2740
2763
  let priv = gobj.priv;
2741
2764
  if (!priv || !priv.escape_stack) {
2742
2765
  (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: push_escape('${layer}') on a shell that is gone: Escape will not close it`);
@@ -2746,9 +2769,53 @@ function push_escape(gobj, layer, handler) {
2746
2769
  priv.escape_stack.push({
2747
2770
  layer,
2748
2771
  handler,
2772
+ teardown: typeof teardown === "function" ? teardown : null,
2749
2773
  seq: priv.escape_seq
2750
2774
  });
2751
2775
  }
2776
+ /************************************************************
2777
+ * Close every overlay still up, the top first, as if each had
2778
+ * been dismissed: a shell that stops -- a logout, a session cut
2779
+ * -- with a drawer, a modal or a question open. Up to gobj-ui
2780
+ * 7.26.45 only the toolbar dropdown was closed: the others kept
2781
+ * their focus trap, and every window opened afterwards believed
2782
+ * itself under an overlay and took no focus; a question never
2783
+ * answered. Run before the views stop, so what an overlay's
2784
+ * on_close calls is still alive. An overlay pushed with no
2785
+ * teardown is left to its owner.
2786
+ ************************************************************/
2787
+ function close_overlays(gobj) {
2788
+ let priv = gobj.priv;
2789
+ if (!priv || !priv.escape_stack) return;
2790
+ let entries = priv.escape_stack.slice().reverse();
2791
+ for (let entry of entries) {
2792
+ if (!entry.teardown) continue;
2793
+ try {
2794
+ entry.teardown();
2795
+ } catch (e) {
2796
+ (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: closing the '${entry.layer}' overlay at stop failed: ${e}`);
2797
+ }
2798
+ }
2799
+ }
2800
+ /************************************************************
2801
+ * What a shell that stops does with its overlays: their
2802
+ * history markers are left where they are, and then they are
2803
+ * closed (close_overlays). The overlay stack is emptied FIRST,
2804
+ * so no close -- of an overlay closed here, or of a window
2805
+ * closed later -- retires its marker with a history.back().
2806
+ * Such a back() is asynchronous and a stopped shell no longer
2807
+ * hears where it lands: up to gobj-ui 7.26.46 a logout followed
2808
+ * by a new shell in the same turn had it taken by the new
2809
+ * shell's first window (Chromium stepped back off that window's
2810
+ * marker, Firefox dropped the back()), and the next Back left
2811
+ * the page. A marker left in place is inert, as a drained one
2812
+ * is: a later Back lands on it and is absorbed.
2813
+ ************************************************************/
2814
+ function retire_overlays(gobj) {
2815
+ let priv = gobj.priv;
2816
+ if (priv && priv.overlay_stack) priv.overlay_stack.splice(0);
2817
+ close_overlays(gobj);
2818
+ }
2752
2819
  function pop_escape(gobj, handler) {
2753
2820
  let priv = gobj.priv;
2754
2821
  if (!priv || !priv.escape_stack) return;
@@ -2958,7 +3025,7 @@ function open_drawer_one(gobj, $c) {
2958
3025
  if ($c.classList.contains("is-active")) return;
2959
3026
  let close_fn = () => close_drawer_one(gobj, $c);
2960
3027
  $c.__yui_close_handler__ = close_fn;
2961
- push_escape(gobj, "overlay", close_fn);
3028
+ push_escape(gobj, "overlay", close_fn, close_fn);
2962
3029
  $c.classList.add("is-active");
2963
3030
  $c.__yui_focus_release__ = activate_focus_trap_on($c.querySelector(".yui-drawer-panel") || $c);
2964
3031
  }
@@ -3660,8 +3727,8 @@ function yui_shell_close_drawer(shell_gobj, menu_id) {
3660
3727
  function yui_shell_toggle_drawer(shell_gobj, menu_id) {
3661
3728
  toggle_drawer(shell_gobj, menu_id);
3662
3729
  }
3663
- function yui_shell_push_escape(shell_gobj, layer, handler) {
3664
- push_escape(shell_gobj, layer, handler);
3730
+ function yui_shell_push_escape(shell_gobj, layer, handler, teardown) {
3731
+ push_escape(shell_gobj, layer, handler, teardown);
3665
3732
  }
3666
3733
  function yui_shell_pop_escape(shell_gobj, handler) {
3667
3734
  pop_escape(shell_gobj, handler);
@@ -4270,7 +4337,7 @@ function yui_shell_show_modal(shell, content, opts) {
4270
4337
  });
4271
4338
  };
4272
4339
  escape_handler = request_close;
4273
- yui_shell_push_escape(shell, "modal", request_close);
4340
+ yui_shell_push_escape(shell, "modal", request_close, do_close);
4274
4341
  overlay = yui_shell_register_overlay(shell, on_back);
4275
4342
  release_focus = activate_focus_trap_on($modal);
4276
4343
  if (opts == null || opts.dismiss_on_background !== false) $modal.querySelector(".modal-background").addEventListener("click", request_close);
@@ -4425,7 +4492,7 @@ function build_dialog(shell, message, buttons, opts) {
4425
4492
  resolve(value);
4426
4493
  };
4427
4494
  close_fn = () => close(dismiss_value);
4428
- yui_shell_push_escape(shell, "modal", close_fn);
4495
+ yui_shell_push_escape(shell, "modal", close_fn, close_fn);
4429
4496
  overlay = yui_shell_register_overlay(shell, close_fn);
4430
4497
  release_focus = activate_focus_trap_on($modal.querySelector(".modal-card"));
4431
4498
  $modal.querySelector(".modal-background").addEventListener("click", () => close(dismiss_value));
@@ -5037,9 +5104,15 @@ function build_ui$18(gobj) {
5037
5104
  if ((0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "auto_save_size_and_position")) {
5038
5105
  if ((0, _yuneta_gobj_js.gobj_is_service)(gobj)) {
5039
5106
  let key = `${(0, _yuneta_gobj_js.gobj_name)(gobj)}-rect`;
5040
- let stored = (0, _yuneta_gobj_js.kw_get_local_storage_value)(key);
5041
- let rect = whole_rect(stored);
5042
- if (!rect && stored != null) (0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: the saved position '${key}' is not a rect of four numbers: ignored`);
5107
+ let rect = whole_rect((0, _yuneta_gobj_js.kw_get_local_storage_value)(key));
5108
+ if (!rect && local_storage_holds(key)) {
5109
+ (0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: the saved position '${key}' is not a rect of four numbers: ignored`);
5110
+ (0, _yuneta_gobj_js.kw_remove_local_storage_value)(key);
5111
+ } else if (rect && (rect.width <= 0 || rect.height <= 0)) {
5112
+ (0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: the saved position '${key}' has no size (${rect.width} x ${rect.height}): ignored`);
5113
+ (0, _yuneta_gobj_js.kw_remove_local_storage_value)(key);
5114
+ rect = null;
5115
+ }
5043
5116
  if (rect) {
5044
5117
  rect.x = rect.x < 0 ? 0 : rect.x;
5045
5118
  rect.y = rect.y < 0 ? 0 : rect.y;
@@ -5479,6 +5552,17 @@ function min$1(gobj) {
5479
5552
  return rect;
5480
5553
  }
5481
5554
  /************************************************************
5555
+ * Whether localStorage holds anything under `key`, readable
5556
+ * or not.
5557
+ ************************************************************/
5558
+ function local_storage_holds(key) {
5559
+ try {
5560
+ return window.localStorage.getItem(key) !== null;
5561
+ } catch (e) {
5562
+ return false;
5563
+ }
5564
+ }
5565
+ /************************************************************
5482
5566
  * The rect of a window in whole pixels: x, y, width and height
5483
5567
  * are DTP_INTEGER, and getBoundingClientRect() answers fractions
5484
5568
  * under a zoom or a device pixel ratio (an integer attr refuses
@@ -7807,8 +7891,14 @@ function yui_tabulator_name_filters(table, t) {
7807
7891
  * from `yui_tabulator_relocalize()` so a language change
7808
7892
  * reaches them.
7809
7893
  *
7810
- * It matches Tabulator's OWN literal and only that, so a box a
7811
- * view named itself is left alone.
7894
+ * It matches Tabulator's OWN literal, and the boxes it named itself
7895
+ * (they carry `data-yui-row-select`), so a box a view named itself is
7896
+ * left alone. Up to 7.26.46 it matched only the literal: a box named
7897
+ * once was never found again, and a language change through
7898
+ * yui_tabulator_relocalize() left it in the old language.
7899
+ *
7900
+ * The box in the HEADER selects every row, and is named so
7901
+ * ("select all rows"); up to 7.26.46 it was "select row" too.
7812
7902
  ***************************************************************/
7813
7903
  var TABULATOR_ROW_SELECT_ARIA = "Select Row";
7814
7904
  function yui_tabulator_name_row_selects(table, t) {
@@ -7819,12 +7909,16 @@ function yui_tabulator_name_row_selects(table, t) {
7819
7909
  (0, _yuneta_gobj_js.log_warning)("yui_tabulator_name_row_selects: table has no element: its row-selection boxes keep Tabulator's English name");
7820
7910
  return;
7821
7911
  }
7822
- let boxes = $el.querySelectorAll(`input[type=checkbox][aria-label="${TABULATOR_ROW_SELECT_ARIA}"]`);
7912
+ let boxes = $el.querySelectorAll(`input[type=checkbox][aria-label="${TABULATOR_ROW_SELECT_ARIA}"], input[type=checkbox][data-yui-row-select]`);
7823
7913
  for (let $box of boxes) {
7824
- $box.setAttribute("aria-label", t("select row"));
7825
- $box.setAttribute("data-i18n-aria-label", "select row");
7826
- $box.setAttribute("title", t("select row"));
7827
- $box.setAttribute("data-i18n-title", "select row");
7914
+ let all = typeof $box.closest === "function" && !!$box.closest(".tabulator-header");
7915
+ let name = all ? t("select all rows") : t("select row");
7916
+ let key = all ? "select all rows" : "select row";
7917
+ $box.setAttribute("aria-label", name);
7918
+ $box.setAttribute("data-i18n-aria-label", key);
7919
+ $box.setAttribute("title", name);
7920
+ $box.setAttribute("data-i18n-title", key);
7921
+ $box.setAttribute("data-yui-row-select", "");
7828
7922
  }
7829
7923
  } catch (e) {}
7830
7924
  }
@@ -9677,6 +9771,170 @@ function datetime_local_to_epoch(value) {
9677
9771
  if (isNaN(date.getTime())) return null;
9678
9772
  return Math.floor(date.getTime() / 1e3);
9679
9773
  }
9774
+ /************************************************************
9775
+ * The value of a time column -> a Date, or null when it holds
9776
+ * none. A `string` column holds an ISO text, any other an epoch
9777
+ * in SECONDS. The form's time field and the cell editor of a
9778
+ * table read it here, so the two agree: up to gobj-ui 7.26.46 the
9779
+ * field read every column with parseInt -- an ISO text as the
9780
+ * year 2026 in SECONDS, in January 1970 -- and showed an empty
9781
+ * one as January 1970 too, which a save then wrote back as 0.
9782
+ ************************************************************/
9783
+ function time_value_to_date(value, real_type) {
9784
+ if (value === null || value === void 0 || value === "") return null;
9785
+ let date = real_type === "string" ? new Date(String(value)) : /* @__PURE__ */ new Date(Number(value) * 1e3);
9786
+ return isNaN(date.getTime()) ? null : date;
9787
+ }
9788
+ /************************************************************
9789
+ * An epoch in seconds (null: no time) -> the value of a time
9790
+ * column: an ISO text for a `string` column, the epoch for any
9791
+ * other. Up to gobj-ui 7.26.46 the field wrote the epoch into a
9792
+ * `string` column too.
9793
+ ************************************************************/
9794
+ function epoch_to_time_value(epoch, real_type) {
9795
+ if (epoch === null || epoch === void 0) return null;
9796
+ if (typeof epoch !== "number" || !Number.isFinite(epoch)) return epoch;
9797
+ if (real_type === "string") return (/* @__PURE__ */ new Date(epoch * 1e3)).toISOString();
9798
+ return epoch;
9799
+ }
9800
+ /************************************************************
9801
+ * The value of a time column as a table cell shows it: the
9802
+ * local clock the editor opens on, "YYYY-MM-DD HH:mm:ss", as
9803
+ * fmt_epoch() of yui_time.js writes a timestamp in a table. ""
9804
+ * for no time; a value that is not one is shown as it is, so the
9805
+ * reader sees what the column holds.
9806
+ ************************************************************/
9807
+ function time_value_to_text(value, real_type) {
9808
+ let date = time_value_to_date(value, real_type);
9809
+ if (!date) return value === null || value === void 0 ? "" : String(value);
9810
+ return date_to_datetime_local(date).replace("T", " ");
9811
+ }
9812
+ //#endregion
9813
+ //#region src/form_time_cell_editor.js
9814
+ /****************************************************************************
9815
+ * form_time_cell_editor.js
9816
+ *
9817
+ * The cell editor of a `time` / `now` column in a table of
9818
+ * C_YUI_FORM: a `datetime-local` box, as the form's own time
9819
+ * field, converting with the same helpers (form_time_value.js)
9820
+ * -- an epoch in SECONDS for an integer column, an ISO text
9821
+ * for a string one -- and to the second (`step` 1).
9822
+ *
9823
+ * Up to gobj-ui 7.26.45 the column used Tabulator's `datetime`
9824
+ * editor with a `format`, which needs luxon, and nothing gives
9825
+ * gobj-ui luxon: the editor said "'date' editor 'format' param
9826
+ * is dependant on luxon.js" in the console, opened empty, and
9827
+ * threw when it was committed. Its format ("dd/MM/yyyy hh:mm",
9828
+ * 12-hour) could not have read an epoch either. Luxon is not
9829
+ * taken in for it: one editor is not worth a dependency every
9830
+ * app would have to dedupe, and the conversion it needs is the
9831
+ * one the form already makes.
9832
+ *
9833
+ * It behaves as Tabulator's own: `elementAttributes` are
9834
+ * written on the box (the column's name, see
9835
+ * yui_tabulator_name_editor), a true blur or Enter commits,
9836
+ * Escape cancels, `verticalNavigation: "editor"` keeps the
9837
+ * arrows, and a value that did not change is a cancel.
9838
+ *
9839
+ * A date with a part cleared is NOT a value: the box answers
9840
+ * `value ""` for it, as for an empty box, and only
9841
+ * `validity.badInput` tells them apart. Enter leaves the
9842
+ * editor open with `aria-invalid` until the date is whole
9843
+ * again (or Escape); a blur cancels, and the cell keeps what
9844
+ * it had. Up to gobj-ui 7.26.46 both committed null: one
9845
+ * Backspace and Enter erased the stored time. To clear a time
9846
+ * on purpose, clear EVERY part of the box: an empty box
9847
+ * commits null. (Inside the box Tab moves between its parts,
9848
+ * as the browser does: it does not leave the cell.)
9849
+ *
9850
+ * Copyright (c) 2026, ArtGins.
9851
+ * All Rights Reserved.
9852
+ ****************************************************************************/
9853
+ /************************************************************
9854
+ * A cell's value -> the text of the box ("" when empty).
9855
+ ************************************************************/
9856
+ function time_to_datetime_local(value, real_type) {
9857
+ return date_to_datetime_local(time_value_to_date(value, real_type));
9858
+ }
9859
+ /************************************************************
9860
+ * The text of the box -> the cell's value (null when empty).
9861
+ ************************************************************/
9862
+ function datetime_local_to_time(text, real_type) {
9863
+ return epoch_to_time_value(datetime_local_to_epoch(text), real_type);
9864
+ }
9865
+ /************************************************************
9866
+ * The editor of a time column whose values are `real_type`
9867
+ * ("integer": epoch seconds; "string": ISO text).
9868
+ ************************************************************/
9869
+ function form_time_cell_editor(real_type) {
9870
+ return function(cell, onRendered, success, cancel, editorParams) {
9871
+ let params = editorParams || {};
9872
+ let vertical = params.verticalNavigation || "editor";
9873
+ let original = cell.getValue();
9874
+ let original_text = time_to_datetime_local(original, real_type);
9875
+ let input = document.createElement("input");
9876
+ input.type = "datetime-local";
9877
+ input.setAttribute("step", "1");
9878
+ input.style.padding = "4px";
9879
+ input.style.width = "100%";
9880
+ input.style.boxSizing = "border-box";
9881
+ let attrs = params.elementAttributes;
9882
+ if (attrs && typeof attrs === "object") for (let key of Object.keys(attrs)) input.setAttribute(key, attrs[key]);
9883
+ input.value = original_text;
9884
+ onRendered(function() {
9885
+ if (cell.getType() === "cell") {
9886
+ input.focus({ preventScroll: true });
9887
+ input.style.height = "100%";
9888
+ }
9889
+ });
9890
+ let incomplete = function() {
9891
+ return !!(input.validity && input.validity.badInput);
9892
+ };
9893
+ let commit = function(from_blur) {
9894
+ if (incomplete()) {
9895
+ if (from_blur) cancel();
9896
+ else input.setAttribute("aria-invalid", "true");
9897
+ return;
9898
+ }
9899
+ if (input.value === original_text) {
9900
+ cancel();
9901
+ return;
9902
+ }
9903
+ let value = datetime_local_to_time(input.value, real_type);
9904
+ if (value === original || value === null && original_text === "") {
9905
+ cancel();
9906
+ return;
9907
+ }
9908
+ success(value);
9909
+ };
9910
+ input.addEventListener("blur", function(e) {
9911
+ if (e.relatedTarget || e.rangeParent || e.explicitOriginalTarget !== input) commit(true);
9912
+ });
9913
+ input.addEventListener("input", function() {
9914
+ if (!incomplete()) input.removeAttribute("aria-invalid");
9915
+ });
9916
+ input.addEventListener("keydown", function(e) {
9917
+ switch (e.key) {
9918
+ case "Enter":
9919
+ commit(false);
9920
+ break;
9921
+ case "Escape":
9922
+ cancel();
9923
+ break;
9924
+ case "End":
9925
+ case "Home":
9926
+ e.stopPropagation();
9927
+ break;
9928
+ case "ArrowUp":
9929
+ case "ArrowDown": if (vertical === "editor") {
9930
+ e.stopImmediatePropagation();
9931
+ e.stopPropagation();
9932
+ }
9933
+ }
9934
+ });
9935
+ return input;
9936
+ };
9937
+ }
9680
9938
  //#endregion
9681
9939
  //#region src/form_json_field.js
9682
9940
  /***********************************************************************
@@ -10103,7 +10361,7 @@ var attrs_table$17 = [
10103
10361
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "editable", 0, false, "Default is editable, set false to readonly"),
10104
10362
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.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"),
10105
10363
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "selectable", 0, true, "A click selects a row, when tabulator_settings selects rows (selectableRows)"),
10106
- (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "with_checkbox", 0, false, "Show a first column with checkbox to select rows"),
10364
+ (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "with_checkbox", 0, false, "Show a first column with checkbox to select rows (hidden while the form is not `selectable`)"),
10107
10365
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "with_rownum", 0, false, "Print first column with row number"),
10108
10366
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "with_delete_row_btn", 0, false, "Print last column with delete row button"),
10109
10367
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_JSON, "toolbar", 0, DEFAULT_TOOLBAR.slice(), "Toolbar buttons to show. The order inside each group is the order given here; which side each group takes is form_toolbar_plan.js. [] hides the toolbar"),
@@ -10125,7 +10383,9 @@ var PRIVATE_DATA$17 = {
10125
10383
  tables: null,
10126
10384
  table_seq: 0,
10127
10385
  json_names_posted: false,
10128
- lang_shell: null
10386
+ lang_shell: null,
10387
+ change_seq: 0,
10388
+ cell_edit: null
10129
10389
  };
10130
10390
  var __gclass__$17 = null;
10131
10391
  /***************************
@@ -10144,6 +10404,16 @@ function mt_create$17(gobj) {
10144
10404
  build_ui$15(gobj);
10145
10405
  }
10146
10406
  /************************************************************
10407
+ * Framework Method writing
10408
+ ************************************************************/
10409
+ function mt_writing$2(gobj, path) {
10410
+ if (path === "selectable") {
10411
+ let $container = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "$container");
10412
+ if (!$container) return;
10413
+ for (let $table of $container.querySelectorAll(".yui-tabulator-table, .yui-tabulator-table-nested")) if ($table.tabulator) show_row_selection(gobj, $table.tabulator);
10414
+ }
10415
+ }
10416
+ /************************************************************
10147
10417
  * Framework Method destroy
10148
10418
  * In this point, all children
10149
10419
  * and subscriptions are already deleted.
@@ -10181,6 +10451,7 @@ function mt_stop$17(gobj) {
10181
10451
  * not switched here: they always say it (create_tabulator).
10182
10452
  ************************************************************/
10183
10453
  function set_changed_stated(gobj, changed) {
10454
+ gobj.priv.change_seq += 1;
10184
10455
  let $container = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "$container");
10185
10456
  $container.querySelector("form");
10186
10457
  const enable = ($btn, on, color) => {
@@ -10520,10 +10791,28 @@ function destroy_widget(gobj, what, widget) {
10520
10791
  * walks the rows already wiped: a reload, a Clear or a destroy
10521
10792
  * with an editor open in any row but the first threw, and left
10522
10793
  * the table half wiped.
10794
+ *
10795
+ * Tabulator has no public way to ask which cell is edited: this
10796
+ * reads its edit module (`modules.edit`, `currentCell`,
10797
+ * `cancelEdit()`), names pinned against the installed Tabulator
10798
+ * by tabulator_edit_internals.test.js. A Tabulator without them
10799
+ * is said: the guard would do nothing, and the crash come back.
10523
10800
  ************************************************************/
10524
- function close_table_editor(tabulator) {
10801
+ function close_table_editor(gobj, tabulator) {
10525
10802
  let edit = tabulator.modules ? tabulator.modules.edit : null;
10526
- if (edit && edit.currentCell) edit.cancelEdit();
10803
+ if (!edit || !("currentCell" in edit) || typeof edit.cancelEdit !== "function") {
10804
+ (0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: this Tabulator has no modules.edit.currentCell/cancelEdit(): an open cell editor is not closed before its table is wiped`);
10805
+ return;
10806
+ }
10807
+ if (edit.currentCell) edit.cancelEdit();
10808
+ }
10809
+ /************************************************************
10810
+ * The element of the table (`.tabulator` kept on it) that holds
10811
+ * $el, the innermost one.
10812
+ ************************************************************/
10813
+ function table_element_of($el) {
10814
+ for (let $n = $el; $n; $n = $n.parentNode) if ($n.tabulator) return $n;
10815
+ return null;
10527
10816
  }
10528
10817
  /************************************************************
10529
10818
  * A table element that is gone: its identity is no table now,
@@ -10546,7 +10835,7 @@ function destroy_row_tables(gobj, $row) {
10546
10835
  $row.yui_nested = null;
10547
10836
  for (let $nested of nested) {
10548
10837
  if ($nested.tabulator) {
10549
- close_table_editor($nested.tabulator);
10838
+ close_table_editor(gobj, $nested.tabulator);
10550
10839
  destroy_rows_tables(gobj, $nested.tabulator);
10551
10840
  destroy_widget(gobj, "nested table", $nested.tabulator);
10552
10841
  $nested.tabulator = null;
@@ -10579,7 +10868,7 @@ function destroy_widgets(gobj, $container) {
10579
10868
  $el.jsoneditor = null;
10580
10869
  }
10581
10870
  if ($el.tabulator) {
10582
- close_table_editor($el.tabulator);
10871
+ close_table_editor(gobj, $el.tabulator);
10583
10872
  destroy_rows_tables(gobj, $el.tabulator);
10584
10873
  destroy_widget(gobj, "table", $el.tabulator);
10585
10874
  $el.tabulator = null;
@@ -10727,6 +11016,9 @@ function build_form(gobj) {
10727
11016
  id: form_id,
10728
11017
  class: "yui-form"
10729
11018
  }]);
11019
+ $form.addEventListener("submit", function(ev) {
11020
+ ev.preventDefault();
11021
+ });
10730
11022
  let template = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "template");
10731
11023
  if (!(0, _yuneta_gobj_js.is_object)(template) && !(0, _yuneta_gobj_js.is_array)(template)) {
10732
11024
  $form.appendChild((0, _yuneta_gobj_js.createOneHtml)(template));
@@ -11238,6 +11530,7 @@ function create_form_field(gobj, $form, prefix, field_desc, { tag, inputType, na
11238
11530
  "button",
11239
11531
  {
11240
11532
  class: "button p-1",
11533
+ type: "button",
11241
11534
  title: (0, i18next.t)("add"),
11242
11535
  "data-i18n-title": "add",
11243
11536
  "aria-label": (0, i18next.t)("add"),
@@ -11817,6 +12110,22 @@ function create_coordinates(gobj, attrs) {
11817
12110
  return $extend;
11818
12111
  }
11819
12112
  /******************************************************************
12113
+ * Show the checkbox column of a table while the form is
12114
+ * `selectable`, hide it while it is not. The column is the table's
12115
+ * row header, the first of its structured columns. A table not
12116
+ * built yet does it when it is (tableBuilt).
12117
+ ******************************************************************/
12118
+ function show_row_selection(gobj, tabulator) {
12119
+ if (!(0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "with_checkbox") || !tabulator.initialized) return;
12120
+ let column = tabulator.getColumns(true).find((c) => c.getDefinition().formatter === "rowSelection");
12121
+ if (!column) {
12122
+ (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: the table has no checkbox column to show or hide`);
12123
+ return;
12124
+ }
12125
+ if ((0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "selectable")) column.show();
12126
+ else column.hide();
12127
+ }
12128
+ /******************************************************************
11820
12129
  * Create tabulator
11821
12130
  *
11822
12131
  * A row builds its nested tables the first time it is drawn, each
@@ -11844,13 +12153,27 @@ function create_coordinates(gobj, attrs) {
11844
12153
  * the form's `selectable` -- first. Up to 7.26.44 the form toggled
11845
12154
  * the row again in `rowClick`, which undid every click. The default
11846
12155
  * `"highlight"` is left as it is, hover and all.
12156
+ *
12157
+ * The checkbox column (`with_checkbox`) asks `selectable` too, and is
12158
+ * not shown while the form is not selectable: Tabulator's row box
12159
+ * ticks before its toggle is refused (a ticked box over a row not
12160
+ * selected), and its header box selects every row asking nothing. Up
12161
+ * to 7.26.45 the boxes were drawn and lied; with the default
12162
+ * `selectableRows` they selected whatever `selectable` said. Up to
12163
+ * 7.26.46 `selectable` was read when the table was built; the column
12164
+ * now follows every write of it (mt_writing, show_row_selection).
12165
+ *
12166
+ * A click in a nested table stays there: it bubbled to the row that
12167
+ * holds the table, whose own click listener (SelectRow's) toggled
12168
+ * that row too.
11847
12169
  ******************************************************************/
11848
12170
  function create_tabulator$1(gobj, $extend, name, template, rows) {
11849
12171
  $extend.template = template;
11850
12172
  let tabulator_settings = (0, _yuneta_gobj_js.json_deep_copy)((0, _yuneta_gobj_js.gobj_read_attr)(gobj, "tabulator_settings"));
11851
12173
  if ((0, _yuneta_gobj_js.is_array)(rows) && rows.length > 0) tabulator_settings.data = (0, _yuneta_gobj_js.json_deep_copy)(rows);
12174
+ let with_checkbox = (0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "with_checkbox");
11852
12175
  let selectable_rows = tabulator_settings.selectableRows;
11853
- if (selectable_rows === true || typeof selectable_rows === "number") tabulator_settings.selectableRowsCheck = function() {
12176
+ if (selectable_rows === true || typeof selectable_rows === "number" || with_checkbox) tabulator_settings.selectableRowsCheck = function() {
11854
12177
  return (0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "selectable");
11855
12178
  };
11856
12179
  let columns = [];
@@ -11877,6 +12200,12 @@ function create_tabulator$1(gobj, $extend, name, template, rows) {
11877
12200
  "name": sub_element.name
11878
12201
  }];
11879
12202
  let $extend = (0, _yuneta_gobj_js.createElement2)(extend);
12203
+ $extend.addEventListener("click", function(ev) {
12204
+ ev.stopPropagation();
12205
+ });
12206
+ $extend.addEventListener("mousedown", function(ev) {
12207
+ if (ev.shiftKey) ev.stopPropagation();
12208
+ });
11880
12209
  let rows = data[sub_element.name];
11881
12210
  $extend.tabulator = create_tabulator$1(gobj, $extend, sub_element.name, sub_element.template, rows);
11882
12211
  $row.appendChild($extend);
@@ -11898,22 +12227,37 @@ function create_tabulator$1(gobj, $extend, name, template, rows) {
11898
12227
  cell.getRow().delete();
11899
12228
  }
11900
12229
  });
11901
- if ((0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "with_checkbox")) tabulator_settings.rowHeader = {
12230
+ if (with_checkbox) tabulator_settings.rowHeader = {
11902
12231
  formatter: "rowSelection",
11903
12232
  titleFormatter: "rowSelection",
11904
12233
  headerSort: false,
11905
12234
  resizable: false,
11906
12235
  frozen: true,
11907
12236
  headerHozAlign: "center",
11908
- hozAlign: "center"
12237
+ hozAlign: "center",
12238
+ visible: (0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "selectable")
11909
12239
  };
11910
12240
  let tabulator = new tabulator_tables.TabulatorFull($extend, tabulator_settings);
11911
12241
  tabulator.on("dataChanged", function() {
11912
12242
  if (gobj.priv.loading_rows > 0) return;
11913
12243
  (0, _yuneta_gobj_js.gobj_send_event)(gobj, "EV_RECORD_CHANGED", {}, gobj);
11914
12244
  });
12245
+ $extend.addEventListener("input", function(ev) {
12246
+ let $target = ev.target;
12247
+ if (!$target || typeof $target.closest !== "function" || !$target.closest(".tabulator-cell.tabulator-editing") || table_element_of($target) !== $extend) return;
12248
+ (0, _yuneta_gobj_js.gobj_send_event)(gobj, "EV_RECORD_CHANGED", { typed_in: table_identity(gobj, $extend) }, gobj);
12249
+ });
12250
+ tabulator.on("cellEditing", function() {
12251
+ if ((0, _yuneta_gobj_js.gobj_is_destroying)(gobj)) return;
12252
+ (0, _yuneta_gobj_js.gobj_send_event)(gobj, "EV_CELL_EDIT_OPENED", { table_id: table_identity(gobj, $extend) }, gobj);
12253
+ });
12254
+ tabulator.on("cellEditCancelled", function() {
12255
+ if ((0, _yuneta_gobj_js.gobj_is_destroying)(gobj)) return;
12256
+ (0, _yuneta_gobj_js.gobj_send_event)(gobj, "EV_CELL_EDIT_CANCELLED", { table_id: table_identity(gobj, $extend) }, gobj);
12257
+ });
11915
12258
  $extend.yui_pending_rows = null;
11916
12259
  tabulator.on("tableBuilt", function() {
12260
+ show_row_selection(gobj, tabulator);
11917
12261
  let rows = $extend.yui_pending_rows;
11918
12262
  $extend.yui_pending_rows = null;
11919
12263
  if (rows && !(0, _yuneta_gobj_js.gobj_is_destroying)(gobj)) (0, _yuneta_gobj_js.gobj_send_event)(gobj, "EV_LOAD_TABLE_ROWS", {
@@ -12066,13 +12410,11 @@ function template2columns(gobj, columns, template, sub_elements) {
12066
12410
  break;
12067
12411
  case "now":
12068
12412
  case "time":
12069
- column.editor = "datetime";
12070
- column.editorParams = {
12071
- format: "dd/MM/yyyy hh:mm",
12072
- verticalNavigation: "table",
12073
- elementAttributes: { title: (0, i18next.t)("slide bar to choose option") }
12413
+ column.editor = form_time_cell_editor(field_desc.real_type);
12414
+ column.editorParams = { verticalNavigation: "table" };
12415
+ column.formatter = function(cell) {
12416
+ return text_node(time_value_to_text(cell.getValue(), field_desc.real_type));
12074
12417
  };
12075
- field_desc.real_type;
12076
12418
  break;
12077
12419
  case "color":
12078
12420
  column.editor = "input";
@@ -12363,7 +12705,7 @@ function clear_data(gobj, $form) {
12363
12705
  $form.querySelectorAll(".yui-tabulator-table").forEach(($table) => {
12364
12706
  $table.yui_pending_rows = null;
12365
12707
  if ($table.tabulator.initialized) {
12366
- close_table_editor($table.tabulator);
12708
+ close_table_editor(gobj, $table.tabulator);
12367
12709
  destroy_rows_tables(gobj, $table.tabulator);
12368
12710
  $table.tabulator.clearData();
12369
12711
  }
@@ -12560,7 +12902,7 @@ function treedb_value_2_form_value(gobj, field_desc, value) {
12560
12902
  case "url": break;
12561
12903
  case "now":
12562
12904
  case "time":
12563
- value = /* @__PURE__ */ new Date((parseInt(value) || 0) * 1e3);
12905
+ value = time_value_to_date(value, field_desc.real_type);
12564
12906
  break;
12565
12907
  case "date":
12566
12908
  case "color":
@@ -12654,10 +12996,9 @@ function form_value_2_treedb_value(gobj, field_desc, value) {
12654
12996
  case "time":
12655
12997
  switch (real_type) {
12656
12998
  case "string":
12657
- if (value && (0, _yuneta_gobj_js.is_date)(value)) value = value.toISOString();
12658
- break;
12659
12999
  case "integer":
12660
- if (value && (0, _yuneta_gobj_js.is_date)(value)) value = value.getTime() / 1e3;
13000
+ if ((0, _yuneta_gobj_js.is_date)(value)) value = Math.floor(value.getTime() / 1e3);
13001
+ value = epoch_to_time_value(value, real_type);
12661
13002
  break;
12662
13003
  default: (0, _yuneta_gobj_js.log_error)("incompatible type for time: " + real_type);
12663
13004
  }
@@ -12905,7 +13246,44 @@ function ac_load_table_rows(gobj, event, kw, src) {
12905
13246
  * Internal event
12906
13247
  ************************************************************/
12907
13248
  function ac_record_changed(gobj, event, kw, src) {
12908
- if ((0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "initialized")) set_edited_by_reader(gobj);
13249
+ if ((0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "initialized")) {
13250
+ let priv = gobj.priv;
13251
+ let open = priv.cell_edit;
13252
+ let own = !!(open && kw && kw.typed_in === open.table_id && open.seq === priv.change_seq);
13253
+ set_edited_by_reader(gobj);
13254
+ if (own) open.seq = priv.change_seq;
13255
+ }
13256
+ return 0;
13257
+ }
13258
+ /************************************************************
13259
+ * A cell editor opened, in the table `table_id`: what the form
13260
+ * says now is what a cancel of it gives back.
13261
+ ************************************************************/
13262
+ function ac_cell_edit_opened(gobj, event, kw, src) {
13263
+ let priv = gobj.priv;
13264
+ priv.cell_edit = {
13265
+ table_id: kw.table_id,
13266
+ edited: (0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "edited"),
13267
+ changes: (0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "changes"),
13268
+ seq: priv.change_seq
13269
+ };
13270
+ return 0;
13271
+ }
13272
+ /************************************************************
13273
+ * A cell editor cancelled -- Escape, or a box left as it was:
13274
+ * the value comes back, and so do the `edited` and `changes` the
13275
+ * form had when it opened. Up to gobj-ui 7.26.46 what was typed
13276
+ * in it still counted, and closing asked about a change that was
13277
+ * gone. Nothing is given back when anything but that editor's
13278
+ * own typing changed the form meanwhile: that change is real.
13279
+ ************************************************************/
13280
+ function ac_cell_edit_cancelled(gobj, event, kw, src) {
13281
+ let priv = gobj.priv;
13282
+ let open = priv.cell_edit;
13283
+ priv.cell_edit = null;
13284
+ if (!open || open.table_id !== kw.table_id || open.seq !== priv.change_seq) return 0;
13285
+ if ((0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "changes") !== open.changes) set_changed_stated(gobj, open.changes);
13286
+ (0, _yuneta_gobj_js.gobj_write_bool_attr)(gobj, "edited", open.edited);
12909
13287
  return 0;
12910
13288
  }
12911
13289
  /************************************************************
@@ -13049,6 +13427,7 @@ function cmd_get_picked_files(gobj, cmd, kw, src) {
13049
13427
  }
13050
13428
  var gmt$17 = {
13051
13429
  mt_create: mt_create$17,
13430
+ mt_writing: mt_writing$2,
13052
13431
  mt_start: mt_start$17,
13053
13432
  mt_stop: mt_stop$17,
13054
13433
  mt_destroy: mt_destroy$17,
@@ -13098,6 +13477,16 @@ function create_gclass$17(gclass_name) {
13098
13477
  ac_record_changed,
13099
13478
  null
13100
13479
  ],
13480
+ [
13481
+ "EV_CELL_EDIT_OPENED",
13482
+ ac_cell_edit_opened,
13483
+ null
13484
+ ],
13485
+ [
13486
+ "EV_CELL_EDIT_CANCELLED",
13487
+ ac_cell_edit_cancelled,
13488
+ null
13489
+ ],
13101
13490
  [
13102
13491
  "EV_COPY_RECORD",
13103
13492
  ac_copy_record,
@@ -13167,6 +13556,8 @@ function create_gclass$17(gclass_name) {
13167
13556
  ["EV_ADD_TABLE_ROW", 0],
13168
13557
  ["EV_LOAD_TABLE_ROWS", 0],
13169
13558
  ["EV_RECORD_CHANGED", 0],
13559
+ ["EV_CELL_EDIT_OPENED", 0],
13560
+ ["EV_CELL_EDIT_CANCELLED", 0],
13170
13561
  ["EV_COPY_RECORD", 0],
13171
13562
  ["EV_PASTE_RECORD", 0],
13172
13563
  ["EV_SET_FILE_PREVIEW", 0],
@@ -32276,8 +32667,11 @@ function transform__treedb_value_2_table_value(gobj, col, value, row, field) {
32276
32667
  switch (field_desc.real_type) {
32277
32668
  case "string":
32278
32669
  case "integer":
32279
- value = parseInt(value) || 0;
32280
- value = /* @__PURE__ */ new Date(value * 1e3);
32670
+ value = time_value_to_date(value, field_desc.real_type);
32671
+ if (!value) {
32672
+ value = "";
32673
+ break;
32674
+ }
32281
32675
  const rawLocale = navigator.language;
32282
32676
  const userLocale = typeof rawLocale === "string" && rawLocale && rawLocale !== "undefined" ? rawLocale : void 0;
32283
32677
  const formatter = new Intl.DateTimeFormat(userLocale, {