@yuneta/gobj-ui 7.26.42 → 7.26.44

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.
Files changed (47) hide show
  1. package/README.md +227 -36
  2. package/dist/gobj-ui.cjs.js +770 -192
  3. package/dist/gobj-ui.es.js +770 -192
  4. package/package.json +2 -2
  5. package/scripts/validate-locales.mjs +355 -63
  6. package/src/c_yui_form.js +268 -155
  7. package/src/c_yui_node.js +51 -7
  8. package/src/c_yui_schema_editor.js +49 -3
  9. package/src/c_yui_shell.css +4 -1
  10. package/src/c_yui_shell.js +28 -2
  11. package/src/c_yui_window.js +373 -62
  12. package/src/c_yui_window_manager.js +74 -2
  13. package/src/escape_taken.js +58 -0
  14. package/src/form_close_asks_for_edits.wiring.test.js +6 -3
  15. package/src/form_json_editor_names.js +3 -1
  16. package/src/form_json_editor_names.wiring.test.js +8 -4
  17. package/src/form_json_expand.wiring.test.js +6 -3
  18. package/src/form_json_field.wiring.test.js +8 -4
  19. package/src/form_label_i18n.wiring.test.js +10 -5
  20. package/src/form_table_edits_ask.wiring.test.js +18 -8
  21. package/src/form_table_rearm.wiring.test.js +13 -5
  22. package/src/form_table_rows.wiring.test.js +533 -0
  23. package/src/form_table_validator.wiring.test.js +8 -4
  24. package/src/form_template_field.wiring.test.js +6 -3
  25. package/src/g6_long_press_clock.test.js +8 -3
  26. package/src/i18n_key_functions.js +63 -25
  27. package/src/i18n_key_functions.test.js +230 -8
  28. package/src/modal_guard_back.wiring.test.js +53 -0
  29. package/src/named_controls.wiring.test.js +53 -13
  30. package/src/node_nav_events.wiring.test.js +93 -1
  31. package/src/schema_editor_diagram_click.wiring.test.js +277 -0
  32. package/src/shell_dialog_names.wiring.test.js +149 -0
  33. package/src/shell_escape_taken.wiring.test.js +142 -0
  34. package/src/shell_focus_trap.js +30 -2
  35. package/src/shell_focus_trap.test.js +90 -6
  36. package/src/shell_modals.js +90 -19
  37. package/src/table_editor_name.wiring.test.js +10 -5
  38. package/src/treedb_column_title.wiring.test.js +8 -4
  39. package/src/treedb_graph_writes.wiring.test.js +6 -3
  40. package/src/treedb_json_drill.wiring.test.js +6 -3
  41. package/src/uplot_add_serie.test.js +6 -3
  42. package/src/uplot_ink.test.js +8 -4
  43. package/src/window_dialog.wiring.test.js +486 -0
  44. package/src/window_dock_band.wiring.test.js +189 -0
  45. package/src/window_rect_rounding.wiring.test.js +121 -0
  46. package/src/yui_tabulator_i18n.js +31 -1
  47. package/src/yui_tabulator_i18n.test.js +46 -0
@@ -126,6 +126,14 @@ function yui_tint(colour) {
126
126
  * - restores focus to whatever element had it before
127
127
  * activation when release() runs.
128
128
  *
129
+ * Only a control that is DRAWN counts: focus() on one that is
130
+ * not (display:none) does nothing. The adaptive dialog's back
131
+ * arrow is the first control of every dialog and is hidden on a
132
+ * laptop: up to 7.26.42 the trap gave it the focus on activation
133
+ * (so the focus stayed outside the dialog), and every Tab after
134
+ * that wrapped to it, did nothing and was prevented -- the
135
+ * keyboard never got into the dialog.
136
+ *
129
137
  * Pure module — no gobj / Yuneta dependencies. The optional
130
138
  * second argument lets callers inject a mock document object
131
139
  * for unit tests.
@@ -135,6 +143,14 @@ function yui_tint(colour) {
135
143
  ***********************************************************************/
136
144
  var FOCUSABLE_SELECTOR = "a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
137
145
  var __trap_stack__ = [];
146
+ function is_drawn(el) {
147
+ if (typeof el.checkVisibility === "function") return el.checkVisibility();
148
+ if (typeof el.getClientRects === "function") return el.getClientRects().length > 0;
149
+ return true;
150
+ }
151
+ function focusables_of($panel) {
152
+ return Array.from($panel.querySelectorAll(FOCUSABLE_SELECTOR)).filter(is_drawn);
153
+ }
138
154
  /***************************************************************
139
155
  * Activate the focus-trap on $panel.
140
156
  *
@@ -152,7 +168,7 @@ function activate_focus_trap_on($panel, doc) {
152
168
  let trap = function(ev) {
153
169
  if (ev.key !== "Tab" && ev.keyCode !== 9) return;
154
170
  if (__trap_stack__[__trap_stack__.length - 1] !== trap) return;
155
- let nodes = $panel.querySelectorAll(FOCUSABLE_SELECTOR);
171
+ let nodes = focusables_of($panel);
156
172
  if (nodes.length === 0) return;
157
173
  let first = nodes[0];
158
174
  let last = nodes[nodes.length - 1];
@@ -169,7 +185,7 @@ function activate_focus_trap_on($panel, doc) {
169
185
  };
170
186
  doc.addEventListener("keydown", trap, true);
171
187
  __trap_stack__.push(trap);
172
- let firstFocusable = $panel.querySelector(FOCUSABLE_SELECTOR);
188
+ let firstFocusable = focusables_of($panel)[0];
173
189
  if (firstFocusable && typeof firstFocusable.focus === "function") firstFocusable.focus();
174
190
  return function release_focus_trap() {
175
191
  if (released) return;
@@ -257,6 +273,51 @@ function bulma_hidden_class(bp) {
257
273
  return "";
258
274
  }
259
275
  //#endregion
276
+ //#region src/escape_taken.js
277
+ /***********************************************************************
278
+ * escape_taken.js
279
+ *
280
+ * Whose is an Escape? The overlay around the focus (a window, the
281
+ * shell's dialog on top) closes with it -- unless what the key was
282
+ * typed in took it first:
283
+ *
284
+ * - a handler used it and said so (`preventDefault()`): Tom
285
+ * Select closing its list, the json editor its search box;
286
+ * - an input method is composing (the key cancels the
287
+ * composition);
288
+ * - the element it was typed in is no longer in the document:
289
+ * an inline editor closed with it. Tabulator cancels a cell
290
+ * edit on Escape by removing the box, and says nothing else
291
+ * -- so this is the only trace the key leaves;
292
+ * - it was typed in a search box that holds text: the browser
293
+ * clears the box with it (a default action, not a
294
+ * preventDefault() anyone can see -- and taking the key would
295
+ * prevent it). An empty one gives it on;
296
+ * - it was typed in a text editor (a textarea, a
297
+ * contenteditable): what is being written there is not lost
298
+ * to a key that also means "stop" inside the editor. The
299
+ * overlay is one Tab away.
300
+ *
301
+ * Pure module: an event in, a boolean out.
302
+ *
303
+ * Copyright (c) 2026, ArtGins.
304
+ * All Rights Reserved.
305
+ ***********************************************************************/
306
+ /***************************************************************
307
+ * True when the Escape `evt` belongs to what it was typed in,
308
+ * and not to the overlay around it.
309
+ ***************************************************************/
310
+ function escape_is_taken(evt) {
311
+ if (!evt) return false;
312
+ if (evt.defaultPrevented || evt.isComposing) return true;
313
+ let target = evt.target;
314
+ if (!target || target.nodeType !== 1) return false;
315
+ if (target.isConnected === false) return true;
316
+ if (target.tagName === "INPUT" && target.type === "search" && target.value) return true;
317
+ if (target.tagName === "TEXTAREA" || target.isContentEditable === true) return true;
318
+ return false;
319
+ }
320
+ //#endregion
260
321
  //#region src/shell_toolbar_helpers.js
261
322
  var TOOLBAR_ACTION_TYPES = [
262
323
  "navigate",
@@ -1209,7 +1270,7 @@ function mt_create$22(gobj) {
1209
1270
  /***************************************************************
1210
1271
  * Framework Method: Start
1211
1272
  ***************************************************************/
1212
- function mt_start$20(gobj) {
1273
+ function mt_start$21(gobj) {
1213
1274
  let config = gobj_read_attr(gobj, "config") || {};
1214
1275
  let priv = gobj.priv;
1215
1276
  if (!validate_config(config)) {
@@ -1313,6 +1374,7 @@ function mt_start$20(gobj) {
1313
1374
  priv.keydown_handler = (ev) => {
1314
1375
  if (ev.key !== "Escape" && ev.keyCode !== 27) return;
1315
1376
  if (priv.escape_stack.length === 0) return;
1377
+ if (escape_is_taken(ev)) return;
1316
1378
  let top = priv.escape_stack[priv.escape_stack.length - 1];
1317
1379
  ev.preventDefault();
1318
1380
  ev.stopPropagation();
@@ -2297,13 +2359,17 @@ function refresh_avatars(gobj) {
2297
2359
  * Wire an optional secondary (right-click) action on a
2298
2360
  * toolbar item. Same action shape as `action`; used e.g. by
2299
2361
  * the connection indicator to open a dev panel on right-click.
2362
+ * The item goes along whole, with the secondary action in place
2363
+ * of its own: a menu it opens is named as its trigger is (up to
2364
+ * 7.26.42 it went as `{id, action}`, and the menu was named by
2365
+ * the raw id whatever the item declared).
2300
2366
  ************************************************************/
2301
2367
  function attach_context_action(gobj, $item, it) {
2302
2368
  if (!it || !it.context_action) return;
2303
2369
  $item.addEventListener("contextmenu", (ev) => {
2304
2370
  ev.preventDefault();
2305
2371
  handle_toolbar_action(gobj, {
2306
- id: it.id,
2372
+ ...it,
2307
2373
  action: it.context_action
2308
2374
  }, $item);
2309
2375
  });
@@ -3206,7 +3272,7 @@ function mt_publication_pre_filter(gobj, subs, event, kw) {
3206
3272
  }
3207
3273
  var gmt$22 = {
3208
3274
  mt_create: mt_create$22,
3209
- mt_start: mt_start$20,
3275
+ mt_start: mt_start$21,
3210
3276
  mt_stop: mt_stop$20,
3211
3277
  mt_destroy: mt_destroy$22,
3212
3278
  mt_publication_pre_filter
@@ -3399,6 +3465,16 @@ function yui_shell_window_layer(shell_gobj) {
3399
3465
  return priv.window_layer || priv.layers && priv.layers.overlay || null;
3400
3466
  }
3401
3467
  /************************************************************
3468
+ * The DOM where a MODAL C_YUI_WINDOW lives when its host names
3469
+ * no `$parent`: the shell's dialog layer, with the dialogs of
3470
+ * shell_modals.js -- above the drawer, the dock and every other
3471
+ * window, below the toasts. Null with no shell.
3472
+ ************************************************************/
3473
+ function yui_shell_modal_layer(shell_gobj) {
3474
+ if (!shell_gobj || !shell_gobj.priv || !shell_gobj.priv.layers) return null;
3475
+ return shell_gobj.priv.layers.modal || null;
3476
+ }
3477
+ /************************************************************
3402
3478
  * Put a window on top of the others: the next number of ONE
3403
3479
  * counter, the same for a window of the dock and for a floating
3404
3480
  * one.
@@ -3823,6 +3899,14 @@ function modal_layer(shell) {
3823
3899
  let priv = shell.priv;
3824
3900
  return priv && priv.layers && priv.layers.modal;
3825
3901
  }
3902
+ var __opened_by_shell__ = /* @__PURE__ */ new WeakMap();
3903
+ function note_opened(shell) {
3904
+ __opened_by_shell__.set(shell, opened_count(shell) + 1);
3905
+ }
3906
+ function opened_count(shell) {
3907
+ return __opened_by_shell__.get(shell) || 0;
3908
+ }
3909
+ var __dialog_seq__ = 0;
3826
3910
  function yui_shell_popup_layer(shell) {
3827
3911
  if (!shell) return null;
3828
3912
  let priv = shell.priv;
@@ -3957,18 +4041,43 @@ function yui_shell_show_modal(shell, content, opts) {
3957
4041
  log_warning("yui_shell_show_modal: shell has no modal layer");
3958
4042
  return { close: () => {} };
3959
4043
  }
4044
+ let label_id = `yui-modal-${++__dialog_seq__}`;
3960
4045
  let inner = typeof content === "string" ? [
3961
4046
  "div",
3962
4047
  { class: "box" },
3963
4048
  [[
3964
4049
  "p",
3965
- { i18n: content },
4050
+ {
4051
+ class: "MODAL_MESSAGE",
4052
+ id: `${label_id}-msg`,
4053
+ i18n: content
4054
+ },
3966
4055
  content
3967
4056
  ]]
3968
4057
  ] : null;
3969
4058
  let dialog = !!(opts && opts.dialog);
3970
4059
  let title = opts && opts.title || "";
3971
4060
  let title_prefix = opts && opts.title_prefix || "";
4061
+ let title_halves = (title_prefix ? [[
4062
+ "span",
4063
+ {
4064
+ class: "MODAL_TITLE_PREFIX",
4065
+ id: `${label_id}-prefix`
4066
+ },
4067
+ text_node(title_prefix)
4068
+ ]] : []).concat(title ? [[
4069
+ "span",
4070
+ {
4071
+ class: "MODAL_TITLE_KIND",
4072
+ id: `${label_id}-kind`,
4073
+ i18n: title
4074
+ },
4075
+ text_node(title)
4076
+ ]] : []);
4077
+ let label_ids = [];
4078
+ if (title_prefix) label_ids.push(`${label_id}-prefix`);
4079
+ if (title) label_ids.push(`${label_id}-kind`);
4080
+ if (label_ids.length === 0 && inner) label_ids.push(`${label_id}-msg`);
3972
4081
  let with_close = !(opts && opts.with_close_button === false);
3973
4082
  let modal_children;
3974
4083
  if (dialog) {
@@ -3994,18 +4103,7 @@ function yui_shell_show_modal(shell, content, opts) {
3994
4103
  [
3995
4104
  "span",
3996
4105
  { class: "MODAL_TITLE yui-dialog-title" },
3997
- (title_prefix ? [[
3998
- "span",
3999
- { class: "MODAL_TITLE_PREFIX" },
4000
- text_node(title_prefix)
4001
- ]] : []).concat(title ? [[
4002
- "span",
4003
- {
4004
- class: "MODAL_TITLE_KIND",
4005
- i18n: title
4006
- },
4007
- text_node(title)
4008
- ]] : [])
4106
+ title_halves
4009
4107
  ],
4010
4108
  [
4011
4109
  "button",
@@ -4033,6 +4131,11 @@ function yui_shell_show_modal(shell, content, opts) {
4033
4131
  { class: "MODAL_CONTENT modal-content" },
4034
4132
  inner ? [inner] : []
4035
4133
  ]];
4134
+ if (title_halves.length > 0) modal_children.unshift([
4135
+ "span",
4136
+ { class: "MODAL_TITLE is-sr-only" },
4137
+ title_halves
4138
+ ]);
4036
4139
  if (with_close) modal_children.push(["button", {
4037
4140
  class: "MODAL_CLOSE modal-close is-large",
4038
4141
  title: t("close"),
@@ -4043,16 +4146,20 @@ function yui_shell_show_modal(shell, content, opts) {
4043
4146
  }
4044
4147
  let logical = opts && opts.logical_class || "";
4045
4148
  let wide = !!(opts && opts.wide);
4149
+ let modal_attrs = {
4150
+ class: "MODAL" + (logical ? " " + logical : "") + " modal yui-modal" + (dialog ? " yui-dialog" : "") + (dialog && wide ? " yui-dialog-wide" : "") + " is-active",
4151
+ role: "dialog",
4152
+ "aria-modal": "true"
4153
+ };
4154
+ if (label_ids.length > 0) modal_attrs["aria-labelledby"] = label_ids.join(" ");
4155
+ else log_warning(`yui_shell_show_modal: a dialog with no title and no message has no name for a reader` + (logical ? ` (${logical})` : "") + `: give it opts.title`);
4046
4156
  let $modal = createElement2([
4047
4157
  "div",
4048
- {
4049
- class: "MODAL" + (logical ? " " + logical : "") + " modal yui-modal" + (dialog ? " yui-dialog" : "") + (dialog && wide ? " yui-dialog-wide" : "") + " is-active",
4050
- role: "dialog",
4051
- "aria-modal": "true"
4052
- },
4158
+ modal_attrs,
4053
4159
  modal_children
4054
4160
  ]);
4055
4161
  $layer.appendChild($modal);
4162
+ note_opened(shell);
4056
4163
  if (!inner && content && typeof content.appendChild !== "undefined") (dialog ? $modal.querySelector(".yui-dialog-body") : $modal.querySelector(".modal-content")).appendChild(content);
4057
4164
  maybe_apply_translator($modal, opts);
4058
4165
  let closed = false;
@@ -4081,6 +4188,7 @@ function yui_shell_show_modal(shell, content, opts) {
4081
4188
  let guarded_close = function(on_veto) {
4082
4189
  if (closed) return;
4083
4190
  let allow = true;
4191
+ let opened_before = opened_count(shell);
4084
4192
  if (opts && typeof opts.before_close === "function") try {
4085
4193
  allow = opts.before_close();
4086
4194
  } catch (e) {
@@ -4096,6 +4204,7 @@ function yui_shell_show_modal(shell, content, opts) {
4096
4204
  do_close();
4097
4205
  return;
4098
4206
  }
4207
+ if (answer === void 0 && !closed && opened_count(shell) === opened_before) log_warning("yui_shell_show_modal: before_close settled with undefined and asked nothing: the modal stays open (only true closes it)");
4099
4208
  vetoed();
4100
4209
  }, function(e) {
4101
4210
  log_warning(`yui_shell_show_modal: before_close rejected: ${e}`);
@@ -4203,10 +4312,12 @@ function build_dialog(shell, message, buttons, opts) {
4203
4312
  "aria-hidden": "true"
4204
4313
  }]]
4205
4314
  ]];
4315
+ let label_id = `yui-confirm-${++__dialog_seq__}`;
4206
4316
  if (!empty_string(title)) $card_children.push([
4207
4317
  "p",
4208
4318
  {
4209
4319
  class: "CONFIRM_TITLE yui-confirm-title has-text-centered",
4320
+ id: `${label_id}-title`,
4210
4321
  i18n: title
4211
4322
  },
4212
4323
  text_node(title)
@@ -4219,21 +4330,28 @@ function build_dialog(shell, message, buttons, opts) {
4219
4330
  "data-i18n-aria-label": "close"
4220
4331
  }], [
4221
4332
  "section",
4222
- { class: "CONFIRM_BODY modal-card-body has-text-centered" },
4333
+ {
4334
+ class: "CONFIRM_BODY modal-card-body has-text-centered",
4335
+ id: `${label_id}-body`
4336
+ },
4223
4337
  $body_children
4224
4338
  ], [
4225
4339
  "footer",
4226
4340
  { class: "CONFIRM_FOOT modal-card-foot" },
4227
4341
  $footer_children
4228
4342
  ]);
4229
- let logical = opts && opts.logical_class ? " " + opts.logical_class : "";
4343
+ let confirm_attrs = {
4344
+ class: `CONFIRM${opts && opts.logical_class ? " " + opts.logical_class : ""} modal yui-modal yui-confirm is-active is-${type}`,
4345
+ role: "dialog",
4346
+ "aria-modal": "true"
4347
+ };
4348
+ if (!empty_string(title)) {
4349
+ confirm_attrs["aria-labelledby"] = `${label_id}-title`;
4350
+ confirm_attrs["aria-describedby"] = `${label_id}-body`;
4351
+ } else confirm_attrs["aria-labelledby"] = `${label_id}-body`;
4230
4352
  let $modal = createElement2([
4231
4353
  "div",
4232
- {
4233
- class: `CONFIRM${logical} modal yui-modal yui-confirm is-active is-${type}`,
4234
- role: "dialog",
4235
- "aria-modal": "true"
4236
- },
4354
+ confirm_attrs,
4237
4355
  [["div", { class: "CONFIRM_BACKDROP modal-background" }], [
4238
4356
  "div",
4239
4357
  { class: "CONFIRM_CARD modal-card" },
@@ -4241,6 +4359,7 @@ function build_dialog(shell, message, buttons, opts) {
4241
4359
  ]]
4242
4360
  ]);
4243
4361
  $layer.appendChild($modal);
4362
+ note_opened(shell);
4244
4363
  maybe_apply_translator($modal, opts);
4245
4364
  return new Promise((resolve) => {
4246
4365
  let resolved = false;
@@ -4375,6 +4494,30 @@ function yui_shell_confirm_yesnocancel(shell, message, opts) {
4375
4494
  *
4376
4495
  * Window - position fixed
4377
4496
  *
4497
+ * A window is a DIALOG for the keyboard and for a reader:
4498
+ *
4499
+ * - it says so (`role="dialog"`) and is named by its title
4500
+ * (`aria-labelledby` on its two halves, the kind half carrying
4501
+ * its key, so the name changes language with it);
4502
+ * - when it starts in answer to the reader (a press, a key) it
4503
+ * takes the focus (`focus`: an element, a selector, a number;
4504
+ * by default the window itself, which is focusable with
4505
+ * tabindex=-1) -- not one the app restores on its own at start
4506
+ * up -- and when it goes it gives the focus back to where it
4507
+ * came from, if the focus was in it;
4508
+ * - Escape closes it (`keyboard`) the way its ✕ does, through
4509
+ * EV_CLOSE_WINDOW, so EV_WINDOW_TO_CLOSE can still veto or
4510
+ * ask; not an Escape that what it was typed in took first
4511
+ * (escape_is_taken());
4512
+ * - a `modal` one blocks the rest of the app: it hangs over a
4513
+ * backdrop in the shell's dialog layer (above the dock, the
4514
+ * drawer, every other window), a press outside it does
4515
+ * nothing, Tab stays inside (activate_focus_trap_on(), the
4516
+ * trap of the shell's dialogs), and it never goes to the dock.
4517
+ *
4518
+ * Up to 7.26.42 `focus`, `modal` and `keyboard` were declared and
4519
+ * did nothing.
4520
+ *
4378
4521
  * Copyright (c) 2025-2026, ArtGins.
4379
4522
  * All Rights Reserved.
4380
4523
  ***********************************************************************/
@@ -4387,6 +4530,10 @@ var WC_MAX = "<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><rect x=\"3.3\" y=
4387
4530
  var WC_RESTORE = "<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><rect x=\"5.2\" y=\"3\" width=\"7.8\" height=\"7.8\" rx=\"1.3\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\"/><rect x=\"3\" y=\"5.2\" width=\"7.8\" height=\"7.8\" rx=\"1.3\" fill=\"var(--bulma-scheme-main)\" stroke=\"currentColor\" stroke-width=\"1.4\"/></svg>";
4388
4531
  var WC_CLOSE = "<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"M4 4 L12 12 M12 4 L4 12\" stroke=\"currentColor\" stroke-width=\"1.7\" stroke-linecap=\"round\"/></svg>";
4389
4532
  var MOBILE_MAX = 768;
4533
+ var DOCK_INSET_TOP = "var(--yui-dock-inset-top, 0px)";
4534
+ var DOCK_INSET_BOTTOM = "var(--yui-dock-inset-bottom, 0px)";
4535
+ var MODAL_WINDOW_Z = 40;
4536
+ var __title_seq__ = 0;
4390
4537
  /***************************************************************
4391
4538
  * Data
4392
4539
  ***************************************************************/
@@ -4417,9 +4564,9 @@ var attrs_table$21 = [
4417
4564
  SDATA(data_type_t.DTP_STRING, "title_prefix", 0, "", "Optional DATA half of the title (a topic/service/marker name), shown before `title` and never translated. Use it instead of composing `${name} · ${t(key)}` into `title`, which cannot re-translate"),
4418
4565
  SDATA(data_type_t.DTP_STRING, "title", 0, "", "Window title, an i18n KEY: painted in the title bar (unless `header` overrides it) and on the dock chip. Pass the key, not t(key), or it cannot re-translate"),
4419
4566
  SDATA(data_type_t.DTP_STRING, "icon", 0, "", "Window icon (by window type), leading the title bar and the dock chip: a yi-* class name or inline SVG"),
4420
- SDATA(data_type_t.DTP_POINTER, "focus", 0, null, "NOT implemented yet: would bring focus to the element, a number or a selector"),
4421
- SDATA(data_type_t.DTP_BOOLEAN, "modal", 0, false, "NOT implemented yet: would enable modal mode"),
4422
- SDATA(data_type_t.DTP_BOOLEAN, "keyboard", 0, true, "NOT implemented yet: would close the window on ESC (Escape does nothing today)"),
4567
+ SDATA(data_type_t.DTP_POINTER, "focus", 0, null, "What takes the focus when the window starts in answer to the reader (a press, a key; a window the app restores on its own leaves the focus in the page, a modal one takes it always): an element of the window, a CSS selector looked up in it, or a number (the n-th control of the body, from 0). Null: the window itself. The focus goes back where it came from when the window goes, if it was in the window"),
4568
+ SDATA(data_type_t.DTP_BOOLEAN, "modal", 0, false, "Block the rest of the app while the window is open: a backdrop in the shell's dialog layer (above the dock, the drawer, every other window), a press outside does nothing, Tab stays inside, aria-modal. A modal window never goes to the dock: `manager` is ignored"),
4569
+ SDATA(data_type_t.DTP_BOOLEAN, "keyboard", 0, true, "Escape closes the window the way its ✕ does (EV_WINDOW_TO_CLOSE can veto or ask), when the focus is in it -- not an Escape that what it was typed in took first: a handler that used it, a cell editor that closed with it, a textarea or a contenteditable"),
4423
4570
  SDATA(data_type_t.DTP_BOOLEAN, "back_dismissable", 0, true, "Browser Back closes this window (floating overlays only; ignored when it has a `manager`)"),
4424
4571
  SDATA(data_type_t.DTP_BOOLEAN, "keep_on_navigate", 0, false, "This window is a navigation PANEL: a route change does not close it"),
4425
4572
  SDATA(data_type_t.DTP_POINTER, "back_overlay", 0, null, "Internal: overlay-history entry (Back-button integration)"),
@@ -4431,7 +4578,10 @@ var attrs_table$21 = [
4431
4578
  var PRIVATE_DATA$21 = {
4432
4579
  prevSize: 0,
4433
4580
  placed_by_shell: false,
4434
- back_shell: null
4581
+ back_shell: null,
4582
+ opener: null,
4583
+ $lock: null,
4584
+ release_focus: null
4435
4585
  };
4436
4586
  var __gclass__$21 = null;
4437
4587
  /******************************
@@ -4445,6 +4595,10 @@ function mt_create$21(gobj) {
4445
4595
  if (subscriber) gobj_subscribe_event(gobj, null, {}, subscriber);
4446
4596
  let window_id = "window-" + clean_name(gobj_short_name(gobj));
4447
4597
  gobj_write_attr(gobj, "window_id", window_id);
4598
+ if (gobj_read_bool_attr(gobj, "modal") && gobj_read_pointer_attr(gobj, "manager")) {
4599
+ log_warning(`${gobj_short_name(gobj)}: a modal window does not go to the dock: its manager is ignored`);
4600
+ gobj_write_attr(gobj, "manager", null);
4601
+ }
4448
4602
  let manager = resolve_manager(gobj);
4449
4603
  build_ui$18(gobj);
4450
4604
  yui_shell_watch_changes(gobj);
@@ -4480,13 +4634,41 @@ function mt_create$21(gobj) {
4480
4634
  window.addEventListener("resize", on_win_resize);
4481
4635
  }
4482
4636
  /***************************************************************
4637
+ * Framework Method: Start
4638
+ *
4639
+ * The window takes the focus when it STARTS, not when it is
4640
+ * created: a host fills the body between the two (the json pad,
4641
+ * the frontend view), and `focus` may name what it put there.
4642
+ *
4643
+ * Only a window the READER opened takes it (opened_by_the_reader()).
4644
+ * One the app opens on its own -- the Developer window restored at
4645
+ * start up from the last session -- leaves the focus in the page:
4646
+ * the first Tab of a keyboard reader landed in a window they had
4647
+ * not opened. A modal window takes it all the same: nothing else
4648
+ * can be used while it is up.
4649
+ ***************************************************************/
4650
+ function mt_start$20(gobj) {
4651
+ let priv = gobj.priv;
4652
+ let $container = gobj_read_attr(gobj, "$container");
4653
+ if (!$container) {
4654
+ log_error(`${gobj_short_name(gobj)}: started without a container`);
4655
+ return;
4656
+ }
4657
+ let active = document.activeElement;
4658
+ if (active && active !== document.body && !$container.contains(active)) priv.opener = active;
4659
+ let modal = gobj_read_bool_attr(gobj, "modal");
4660
+ if (modal && !priv.release_focus) priv.release_focus = activate_focus_trap_on($container);
4661
+ if (modal || opened_by_the_reader()) focus_target(gobj, $container).focus();
4662
+ }
4663
+ /***************************************************************
4483
4664
  * Framework Method: Destroy
4484
4665
  ***************************************************************/
4485
4666
  function mt_destroy$21(gobj) {
4486
4667
  let priv = gobj.priv;
4668
+ give_focus_back(gobj);
4487
4669
  yui_shell_unwatch_changes(gobj);
4488
4670
  let manager = gobj_read_pointer_attr(gobj, "manager");
4489
- if (manager) gobj_send_event(manager, "EV_UNREGISTER_WINDOW", { window: gobj_full_name(gobj) }, gobj);
4671
+ if (manager && !gobj_is_destroying(manager)) gobj_send_event(manager, "EV_UNREGISTER_WINDOW", { window: gobj_full_name(gobj) }, gobj);
4490
4672
  let back_overlay = gobj_read_attr(gobj, "back_overlay");
4491
4673
  if (back_overlay) {
4492
4674
  if (priv.back_shell) yui_shell_overlay_dismissed(priv.back_shell, back_overlay);
@@ -4521,9 +4703,12 @@ function ensure_window_style() {
4521
4703
  .yui-window-title .icon { flex: 0 0 auto; }
4522
4704
  .yui-window-title svg { width: 14px; height: 14px; display: block; }
4523
4705
  /* Separator between the data half and the translated kind half. CSS,
4524
- * not a text node: createElement2 trims text nodes and eats the spaces. */
4706
+ * not a text node: createElement2 trims text nodes and eats the spaces.
4707
+ * Decorative ("/ ''"): the halves NAME the window, and a reader read
4708
+ * the dot into the kind half ("#1 ·demo window"). */
4525
4709
  .WINDOW_TITLE_PREFIX + .WINDOW_TITLE_KIND::before {
4526
4710
  content: "·";
4711
+ content: "·" / "";
4527
4712
  padding: 0 0.4em;
4528
4713
  color: var(--bulma-text-weak);
4529
4714
  }
@@ -4537,6 +4722,13 @@ function ensure_window_style() {
4537
4722
  .yui-wc svg { width: 15px; height: 15px; display: block; }
4538
4723
  .yui-window-resize { color: var(--bulma-text-weak); opacity: 0.55; }
4539
4724
  .yui-window-resize:hover { opacity: 1; color: var(--bulma-text); }
4725
+ /* A modal window over its backdrop: the backdrop of a Bulma .modal,
4726
+ * which the shell's dialogs wear (its variable lives on .modal). */
4727
+ .yui-window-lock { position: fixed; inset: 0; }
4728
+ .yui-window-backdrop {
4729
+ position: absolute; inset: 0;
4730
+ background-color: hsla(var(--bulma-scheme-h), var(--bulma-scheme-s), var(--bulma-scheme-invert-l), 0.86);
4731
+ }
4540
4732
  @media (max-width: ${MOBILE_MAX}px) {
4541
4733
  .C_YUI_WINDOW.is-mobile-sheet { border-radius: 0 !important; box-shadow: none !important; }
4542
4734
  .C_YUI_WINDOW.is-mobile-sheet .yui-window-resize { display: none !important; }
@@ -4572,12 +4764,19 @@ function ensure_window_style() {
4572
4764
  * refresh_language() re-translates just that one. The separator is
4573
4765
  * CSS (::before), never a text node: createElement2 TRIMS text nodes
4574
4766
  * and would eat the spaces around it.
4767
+ *
4768
+ * The same halves NAME the window: aria-labelledby lists them
4769
+ * (`<id>-prefix`, `<id>-kind`), so a reader joins them with a space
4770
+ * and leaves out the CSS separator, and the kind half changes
4771
+ * language. Under a `header` of the caller's the node is still
4772
+ * built, `hidden` (is-sr-only, no icon): a header is a toolbar more
4773
+ * often than a title, and the name of a dialog is its title.
4575
4774
  ************************************************************/
4576
- function build_default_header(gobj) {
4775
+ function build_title_node(gobj, id, hidden) {
4577
4776
  let title = gobj_read_str_attr(gobj, "title");
4578
4777
  let prefix = gobj_read_str_attr(gobj, "title_prefix");
4579
4778
  if (empty_string(title) && empty_string(prefix)) return null;
4580
- let icon = gobj_read_str_attr(gobj, "icon");
4779
+ let icon = hidden ? "" : gobj_read_str_attr(gobj, "icon");
4581
4780
  let items = [];
4582
4781
  if (!empty_string(icon)) {
4583
4782
  if (icon.charAt(0) === "<") items.push([
@@ -4593,20 +4792,27 @@ function build_default_header(gobj) {
4593
4792
  }
4594
4793
  if (!empty_string(prefix)) items.push([
4595
4794
  "span",
4596
- { class: "WINDOW_TITLE_PREFIX has-text-weight-semibold" },
4795
+ {
4796
+ class: "WINDOW_TITLE_PREFIX has-text-weight-semibold",
4797
+ id: `${id}-prefix`
4798
+ },
4597
4799
  text_node(prefix)
4598
4800
  ]);
4599
4801
  if (!empty_string(title)) items.push([
4600
4802
  "span",
4601
4803
  {
4602
4804
  class: "WINDOW_TITLE_KIND has-text-weight-semibold",
4805
+ id: `${id}-kind`,
4603
4806
  i18n: title
4604
4807
  },
4605
4808
  text_node(title)
4606
4809
  ]);
4607
4810
  return createElement2([
4608
4811
  "span",
4609
- { class: "WINDOW_TITLE yui-window-title icon-text ml-1" },
4812
+ {
4813
+ id,
4814
+ class: hidden ? "WINDOW_TITLE is-sr-only" : "WINDOW_TITLE yui-window-title icon-text ml-1"
4815
+ },
4610
4816
  items
4611
4817
  ]);
4612
4818
  }
@@ -4623,6 +4829,106 @@ function composed_title(gobj) {
4623
4829
  return empty_string(prefix) ? kind : prefix;
4624
4830
  }
4625
4831
  /************************************************************
4832
+ * Is the window opening in answer to the reader -- a press, a
4833
+ * key (the browser's user activation)? Not one the app restores
4834
+ * at start up. A browser that cannot say is taken at its word
4835
+ * that the reader asked.
4836
+ ************************************************************/
4837
+ function opened_by_the_reader() {
4838
+ let ua = typeof navigator !== "undefined" ? navigator.userActivation : null;
4839
+ if (!ua) return true;
4840
+ return !!ua.isActive;
4841
+ }
4842
+ /************************************************************
4843
+ * What takes the focus when the window starts (`focus`): an
4844
+ * element of the window, a selector looked up in it, or the
4845
+ * n-th control of the body. Null, or one that names nothing
4846
+ * (said): the window itself.
4847
+ ************************************************************/
4848
+ function focus_target(gobj, $container) {
4849
+ let focus = gobj_read_attr(gobj, "focus");
4850
+ if (focus === null || focus === void 0) return $container;
4851
+ let $target = null;
4852
+ if (typeof focus === "number") {
4853
+ let $body = $container.querySelector(".WINDOW_BODY");
4854
+ $target = ($body ? $body.querySelectorAll("a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])") : [])[focus] || null;
4855
+ } else if (typeof focus === "string") $target = $container.querySelector(focus);
4856
+ else if (focus && typeof focus.focus === "function" && $container.contains(focus)) $target = focus;
4857
+ if (!$target) {
4858
+ log_warning(`${gobj_short_name(gobj)}: focus '${String(focus)}' names nothing in the window: the window takes it`);
4859
+ return $container;
4860
+ }
4861
+ return $target;
4862
+ }
4863
+ /************************************************************
4864
+ * The window goes: the focus goes back where it came from --
4865
+ * if it was in the window, or lost with what the window held
4866
+ * (a child torn down first takes its focused element with
4867
+ * it). A focus the reader has put elsewhere stays there. A
4868
+ * modal window's trap gives it back itself.
4869
+ ************************************************************/
4870
+ function give_focus_back(gobj) {
4871
+ let priv = gobj.priv;
4872
+ let opener = priv.opener;
4873
+ priv.opener = null;
4874
+ if (priv.release_focus) {
4875
+ let release = priv.release_focus;
4876
+ priv.release_focus = null;
4877
+ release();
4878
+ return;
4879
+ }
4880
+ let $container = gobj_read_attr(gobj, "$container");
4881
+ let active = document.activeElement;
4882
+ if (!(!active || active === document.body) && !($container && $container.contains(active))) return;
4883
+ if (opener && opener.isConnected !== false && typeof opener.focus === "function") opener.focus();
4884
+ }
4885
+ /************************************************************
4886
+ * A window that fills the screen -- the sheet of a phone, a
4887
+ * maximized one -- fills it but for the band a floating dock
4888
+ * keeps (DOCK_INSET_*). CSS, so the band moves with the dock
4889
+ * and no one has to tell the window.
4890
+ ************************************************************/
4891
+ function fill_work_area($container) {
4892
+ let vw = window.innerWidth || document.documentElement.offsetWidth;
4893
+ let vh = window.innerHeight || document.documentElement.offsetHeight;
4894
+ $container.style.left = "0px";
4895
+ $container.style.top = DOCK_INSET_TOP;
4896
+ $container.style.width = vw + "px";
4897
+ $container.style.height = `calc(${vh}px - ${DOCK_INSET_TOP} - ${DOCK_INSET_BOTTOM})`;
4898
+ return {
4899
+ x: 0,
4900
+ y: 0,
4901
+ width: vw,
4902
+ height: vh
4903
+ };
4904
+ }
4905
+ /************************************************************
4906
+ * What is placed in the DOM, and removed from it: the window,
4907
+ * or the lock that holds a modal one over its backdrop.
4908
+ ************************************************************/
4909
+ function window_root(gobj) {
4910
+ return gobj.priv.$lock || gobj_read_attr(gobj, "$container");
4911
+ }
4912
+ /************************************************************
4913
+ * An Escape typed in the window. The callback only decides
4914
+ * whether the key is the window's -- not when `keyboard` is
4915
+ * off, nor one that what it was typed in took -- and sends
4916
+ * the event: the close is the ✕'s, in the action.
4917
+ ************************************************************/
4918
+ function on_escape_key(gobj, evt) {
4919
+ if (evt.key !== "Escape" && evt.keyCode !== 27) return;
4920
+ if (gobj_is_destroying(gobj) || !gobj_read_bool_attr(gobj, "keyboard")) return;
4921
+ if (escape_is_taken(evt)) {
4922
+ let $container = gobj_read_attr(gobj, "$container");
4923
+ let active = document.activeElement;
4924
+ if (evt.target && evt.target.isConnected === false && $container && (!active || active === document.body)) $container.focus();
4925
+ return;
4926
+ }
4927
+ evt.preventDefault();
4928
+ evt.stopPropagation();
4929
+ gobj_send_event(gobj, "EV_CLOSE_WINDOW", { key: "Escape" }, gobj);
4930
+ }
4931
+ /************************************************************
4626
4932
  * Below the mobile breakpoint the window is a full-screen
4627
4933
  * sheet (no float / drag / resize).
4628
4934
  ************************************************************/
@@ -4664,14 +4970,18 @@ function build_ui$18(gobj) {
4664
4970
  let mobile = is_mobile$4();
4665
4971
  let header = gobj_read_attr(gobj, "header");
4666
4972
  if (is_gobj(header)) header = gobj_read_attr(header, "$container");
4667
- if (!header) header = build_default_header(gobj);
4973
+ let title_id = `yui-window-title-${++__title_seq__}`;
4974
+ let $title = build_title_node(gobj, title_id, !!header);
4975
+ let $hidden_title = header ? $title : null;
4976
+ if (!header) header = $title;
4977
+ let modal = gobj_read_bool_attr(gobj, "modal");
4668
4978
  let body = gobj_read_attr(gobj, "body");
4669
4979
  if (is_gobj(body)) body = gobj_read_attr(body, "$container");
4670
4980
  let footer = gobj_read_attr(gobj, "footer");
4671
4981
  if (is_gobj(footer)) footer = gobj_read_attr(footer, "$container");
4672
4982
  if (gobj_read_bool_attr(gobj, "auto_save_size_and_position")) {
4673
4983
  if (gobj_is_service(gobj)) {
4674
- let rect = kw_get_local_storage_value(`${gobj_name(gobj)}-rect`);
4984
+ let rect = whole_rect(kw_get_local_storage_value(`${gobj_name(gobj)}-rect`));
4675
4985
  if (rect) {
4676
4986
  rect.x = rect.x < 0 ? 0 : rect.x;
4677
4987
  rect.y = rect.y < 0 ? 0 : rect.y;
@@ -4710,12 +5020,21 @@ function build_ui$18(gobj) {
4710
5020
  };
4711
5021
  Object.assign(window_style, gobj_read_attr(gobj, "window_style"));
4712
5022
  let logical = gobj_read_str_attr(gobj, "logical_class");
5023
+ let dialog_attrs = {
5024
+ role: "dialog",
5025
+ tabindex: "-1"
5026
+ };
5027
+ let label_ids = [];
5028
+ if (!empty_string(gobj_read_str_attr(gobj, "title_prefix"))) label_ids.push(`${title_id}-prefix`);
5029
+ if (!empty_string(gobj_read_str_attr(gobj, "title"))) label_ids.push(`${title_id}-kind`);
5030
+ if (label_ids.length > 0) dialog_attrs["aria-labelledby"] = label_ids.join(" ");
5031
+ if (modal) dialog_attrs["aria-modal"] = "true";
4713
5032
  let $container = createElement2([
4714
5033
  "div",
4715
- {
5034
+ Object.assign({
4716
5035
  class: "C_YUI_WINDOW" + (logical ? " " + logical : "") + " strong-shadow is-flex is-flex-direction-column" + (mobile ? " is-mobile-sheet" : ""),
4717
5036
  style: window_style
4718
- },
5037
+ }, dialog_attrs),
4719
5038
  [
4720
5039
  [
4721
5040
  "div",
@@ -4875,6 +5194,11 @@ function build_ui$18(gobj) {
4875
5194
  ]
4876
5195
  ]);
4877
5196
  gobj_write_attr(gobj, "$container", $container);
5197
+ if ($hidden_title) $container.insertBefore($hidden_title, $container.firstChild);
5198
+ $container.addEventListener("keydown", function(evt) {
5199
+ on_escape_key(gobj, evt);
5200
+ });
5201
+ if (mobile) fill_work_area($container);
4878
5202
  if (gobj_read_bool_attr(gobj, "resizable") && !gobj_read_bool_attr(gobj, "showFooter")) {
4879
5203
  let $resizable_btn = createElement2([
4880
5204
  "div",
@@ -4902,10 +5226,29 @@ function build_ui$18(gobj) {
4902
5226
  $container.appendChild($resizable_btn);
4903
5227
  }
4904
5228
  refresh_language($container, t);
5229
+ if (modal) {
5230
+ let $lock = createElement2([
5231
+ "div",
5232
+ {
5233
+ class: "WINDOW_MODAL_LOCK yui-window-lock",
5234
+ style: `z-index:${MODAL_WINDOW_Z};`
5235
+ },
5236
+ [[
5237
+ "div",
5238
+ { class: "WINDOW_MODAL_BACKDROP yui-window-backdrop" },
5239
+ [],
5240
+ { mousedown: (evt) => {
5241
+ evt.preventDefault();
5242
+ } }
5243
+ ]]
5244
+ ]);
5245
+ $lock.appendChild($container);
5246
+ gobj.priv.$lock = $lock;
5247
+ }
4905
5248
  let $parent = gobj_read_attr(gobj, "$parent");
4906
5249
  gobj.priv.placed_by_shell = !$parent;
4907
5250
  if (!$parent) $parent = window_place(gobj);
4908
- $parent.appendChild($container);
5251
+ $parent.appendChild(window_root(gobj));
4909
5252
  if (gobj_read_bool_attr(gobj, "openMaximized")) max$2(gobj);
4910
5253
  else if (!mobile) {
4911
5254
  if (gobj_read_bool_attr(gobj, "content_size")) $container.style.height = "auto";
@@ -4921,11 +5264,10 @@ function build_ui$18(gobj) {
4921
5264
  * Destroy UI
4922
5265
  ************************************************************/
4923
5266
  function destroy_ui$13(gobj) {
4924
- let $container = gobj_read_attr(gobj, "$container");
4925
- if ($container) {
4926
- if ($container.parentNode) $container.parentNode.removeChild($container);
4927
- gobj_write_attr(gobj, "$container", null);
4928
- }
5267
+ let $root = window_root(gobj);
5268
+ if ($root && $root.parentNode) $root.parentNode.removeChild($root);
5269
+ gobj.priv.$lock = null;
5270
+ gobj_write_attr(gobj, "$container", null);
4929
5271
  }
4930
5272
  /************************************************************
4931
5273
  * Register this floating window in the shell's overlay history,
@@ -5016,9 +5358,16 @@ function close_window(gobj) {
5016
5358
  * The place is the shell's, and a window parented to the app
5017
5359
  * outlives it: ac_shell_changed() moves it when a shell goes or
5018
5360
  * comes.
5361
+ *
5362
+ * A MODAL window lives in the shell's dialog layer instead, with
5363
+ * its backdrop: it blocks the drawer, the dock and every other
5364
+ * window, and a question it asks (a dialog of the same layer)
5365
+ * opens above it.
5019
5366
  ************************************************************/
5020
5367
  function window_place(gobj) {
5021
- return yui_shell_window_layer(yui_shell_of(gobj)) || document.body;
5368
+ let shell = yui_shell_of(gobj);
5369
+ if (gobj_read_bool_attr(gobj, "modal")) return yui_shell_modal_layer(shell) || document.body;
5370
+ return yui_shell_window_layer(shell) || document.body;
5022
5371
  }
5023
5372
  /************************************************************
5024
5373
  *
@@ -5034,12 +5383,7 @@ function max$2(gobj) {
5034
5383
  let priv = gobj.priv;
5035
5384
  let $container = gobj_read_attr(gobj, "$container");
5036
5385
  priv.prevSize = $container.getBoundingClientRect();
5037
- let rect = do_fix_dimension_to_screen(gobj, 0, 0, 1e4, 1e4);
5038
- if (gobj_read_bool_attr(gobj, "center")) rect = do_center(gobj, rect.x, rect.y, rect.width, rect.height);
5039
- $container.style.left = parseInt(rect.x) + "px";
5040
- $container.style.top = parseInt(rect.y) + "px";
5041
- $container.style.width = parseInt(rect.width) + "px";
5042
- $container.style.height = parseInt(rect.height) + "px";
5386
+ let rect = fill_work_area($container);
5043
5387
  gobj_write_bool_attr(gobj, "maximized", true);
5044
5388
  set_max_icon(gobj, true);
5045
5389
  return rect;
@@ -5077,6 +5421,27 @@ function min$1(gobj) {
5077
5421
  return rect;
5078
5422
  }
5079
5423
  /************************************************************
5424
+ * The rect of a window in whole pixels: x, y, width and height
5425
+ * are DTP_INTEGER, and getBoundingClientRect() answers fractions
5426
+ * under a zoom or a device pixel ratio (an integer attr refuses
5427
+ * 2.5, as in C). Also a rect saved with fractions before. null
5428
+ * when it is not a rect of four numbers.
5429
+ ************************************************************/
5430
+ function whole_rect(rect) {
5431
+ if (!rect || typeof rect !== "object") return null;
5432
+ let whole = {};
5433
+ for (const key of [
5434
+ "x",
5435
+ "y",
5436
+ "width",
5437
+ "height"
5438
+ ]) {
5439
+ if (typeof rect[key] !== "number" || !Number.isFinite(rect[key])) return null;
5440
+ whole[key] = Math.round(rect[key]);
5441
+ }
5442
+ return whole;
5443
+ }
5444
+ /************************************************************
5080
5445
  * handlers moving
5081
5446
  ************************************************************/
5082
5447
  function mvStart(gobj, evt) {
@@ -5111,17 +5476,13 @@ function mvStart(gobj, evt) {
5111
5476
  $container.style.transition = "none";
5112
5477
  $container.style.transform = "translate3d(0px, 0px, 0px)";
5113
5478
  let rect = $container.getBoundingClientRect();
5114
- gobj_write_integer_attr(gobj, "x", rect.x);
5115
- gobj_write_integer_attr(gobj, "y", rect.y);
5116
- gobj_write_integer_attr(gobj, "width", rect.width);
5117
- gobj_write_integer_attr(gobj, "height", rect.height);
5479
+ let whole = whole_rect(rect);
5480
+ gobj_write_integer_attr(gobj, "x", whole.x);
5481
+ gobj_write_integer_attr(gobj, "y", whole.y);
5482
+ gobj_write_integer_attr(gobj, "width", whole.width);
5483
+ gobj_write_integer_attr(gobj, "height", whole.height);
5118
5484
  if (gobj_read_bool_attr(gobj, "auto_save_size_and_position")) {
5119
- if (gobj_is_service(gobj)) kw_set_local_storage_value(`${gobj_name(gobj)}-rect`, {
5120
- x: rect.x,
5121
- y: rect.y,
5122
- width: rect.width,
5123
- height: rect.height
5124
- });
5485
+ if (gobj_is_service(gobj)) kw_set_local_storage_value(`${gobj_name(gobj)}-rect`, whole);
5125
5486
  }
5126
5487
  gobj_publish_event(gobj, "EV_WINDOW_MOVED", { rect });
5127
5488
  }
@@ -5164,17 +5525,13 @@ function rsStart(gobj, evt) {
5164
5525
  $container.style.width = rect.width + "px";
5165
5526
  $container.style.height = rect.height + "px";
5166
5527
  }
5167
- gobj_write_integer_attr(gobj, "x", rect.x);
5168
- gobj_write_integer_attr(gobj, "y", rect.y);
5169
- gobj_write_integer_attr(gobj, "width", rect.width);
5170
- gobj_write_integer_attr(gobj, "height", rect.height);
5528
+ let whole = whole_rect(rect);
5529
+ gobj_write_integer_attr(gobj, "x", whole.x);
5530
+ gobj_write_integer_attr(gobj, "y", whole.y);
5531
+ gobj_write_integer_attr(gobj, "width", whole.width);
5532
+ gobj_write_integer_attr(gobj, "height", whole.height);
5171
5533
  if (gobj_read_bool_attr(gobj, "auto_save_size_and_position")) {
5172
- if (gobj_is_service(gobj)) kw_set_local_storage_value(`${gobj_name(gobj)}-rect`, {
5173
- x: rect.x,
5174
- y: rect.y,
5175
- width: rect.width,
5176
- height: rect.height
5177
- });
5534
+ if (gobj_is_service(gobj)) kw_set_local_storage_value(`${gobj_name(gobj)}-rect`, whole);
5178
5535
  }
5179
5536
  gobj_publish_event(gobj, "EV_WINDOW_RESIZED", { rect });
5180
5537
  }
@@ -5241,22 +5598,12 @@ function handleResize(gobj) {
5241
5598
  if (!$container) return;
5242
5599
  if (is_mobile$4()) {
5243
5600
  $container.classList.add("is-mobile-sheet");
5244
- let vw = window.innerWidth || document.documentElement.offsetWidth;
5245
- let vh = window.innerHeight || document.documentElement.offsetHeight;
5246
- $container.style.left = "0px";
5247
- $container.style.top = "0px";
5248
- $container.style.width = vw + "px";
5249
- $container.style.height = vh + "px";
5601
+ fill_work_area($container);
5250
5602
  return;
5251
5603
  }
5252
5604
  $container.classList.remove("is-mobile-sheet");
5253
5605
  if (gobj_read_bool_attr(gobj, "maximized") === true) {
5254
- let r = do_fix_dimension_to_screen(gobj, 0, 0, 1e4, 1e4);
5255
- if (gobj_read_bool_attr(gobj, "center")) r = do_center(gobj, r.x, r.y, r.width, r.height);
5256
- $container.style.left = parseInt(r.x) + "px";
5257
- $container.style.top = parseInt(r.y) + "px";
5258
- $container.style.width = parseInt(r.width) + "px";
5259
- $container.style.height = parseInt(r.height) + "px";
5606
+ fill_work_area($container);
5260
5607
  return;
5261
5608
  }
5262
5609
  let rect = do_fix_dimension_to_screen(gobj, gobj_read_integer_attr(gobj, "x"), gobj_read_integer_attr(gobj, "y"), gobj_read_integer_attr(gobj, "width"), gobj_read_integer_attr(gobj, "height"));
@@ -5347,7 +5694,8 @@ function ac_shell_changed$1(gobj, event, kw, src) {
5347
5694
  priv.placed_by_shell = true;
5348
5695
  }
5349
5696
  let $place = window_place(gobj);
5350
- if ($container.parentNode !== $place) $place.appendChild($container);
5697
+ let $root = window_root(gobj);
5698
+ if ($root.parentNode !== $place) $place.appendChild($root);
5351
5699
  return 0;
5352
5700
  }
5353
5701
  /***************************
@@ -5355,6 +5703,7 @@ function ac_shell_changed$1(gobj, event, kw, src) {
5355
5703
  ***************************/
5356
5704
  var gmt$21 = {
5357
5705
  mt_create: mt_create$21,
5706
+ mt_start: mt_start$20,
5358
5707
  mt_destroy: mt_destroy$21
5359
5708
  };
5360
5709
  /***************************************************************
@@ -5442,6 +5791,15 @@ function register_c_yui_window() {
5442
5791
  * (`responsive_query`) — so on mobile it lives above
5443
5792
  * the bottom menu instead of covering it.
5444
5793
  *
5794
+ * A FLOATING dock that shows says the band it keeps at the top or
5795
+ * the foot of the viewport: `--yui-dock-inset-top` /
5796
+ * `--yui-dock-inset-bottom` on the root element (publish_dock_band).
5797
+ * A window that fills the screen -- the sheet of a phone, a
5798
+ * maximized one -- leaves that band free. It used to go under the
5799
+ * dock: at a bottom corner the dock covered its foot, at a top
5800
+ * corner its ✕ and its minimize (a 'responsive' dock with no
5801
+ * `inline_selector` floats on a phone too).
5802
+ *
5445
5803
  * Copyright (c) 2026, ArtGins.
5446
5804
  * All Rights Reserved.
5447
5805
  ***********************************************************************/
@@ -5511,6 +5869,7 @@ function mt_destroy$20(gobj) {
5511
5869
  priv.mql_handler = null;
5512
5870
  }
5513
5871
  destroy_dock(gobj);
5872
+ publish_dock_band(gobj);
5514
5873
  }
5515
5874
  /***************************
5516
5875
  * Local Methods
@@ -5615,8 +5974,10 @@ function ensure_dock_style() {
5615
5974
  .yui-dock-label { flex: 0 0 auto; }
5616
5975
  /* Split label halves (prefix = DATA, kind = translatable). The
5617
5976
  * separator is CSS, never a text node — same rule as the window
5618
- * title bar (createElement2 trims text nodes). */
5619
- .yui-dock-label .yui-dock-label-prefix + .yui-dock-label-kind::before { content: " \\00b7 "; }
5977
+ * title bar (createElement2 trims text nodes). Decorative ("/ ''"):
5978
+ * the halves NAME the toggle (aria-labelledby), and a reader read
5979
+ * the dot into the kind half ("#1 ·demo window"). */
5980
+ .yui-dock-label .yui-dock-label-prefix + .yui-dock-label-kind::before { content: " \\00b7 "; content: " \\00b7 " / ""; }
5620
5981
  .yui-dock-close {
5621
5982
  width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
5622
5983
  padding: 0; margin-left: 1px; border: 0; border-radius: 4px;
@@ -5688,6 +6049,32 @@ function apply_placement(gobj) {
5688
6049
  ]) $dock.classList.toggle(`yui-dock--${c}`, !inline && c === corner);
5689
6050
  let target = inline ? $inline : gobj_read_attr(gobj, "$parent") || dock_place(gobj);
5690
6051
  if ($dock.parentNode !== target) target.appendChild($dock);
6052
+ publish_dock_band(gobj);
6053
+ }
6054
+ /************************************************************
6055
+ * Say the band the dock keeps over the windows: a FLOATING
6056
+ * dock that shows takes the top or the foot of the viewport,
6057
+ * from its edge to its far side. A window that fills the
6058
+ * screen leaves it free (C_YUI_WINDOW's fill_work_area()). An
6059
+ * inline dock keeps none: it is in the layout. Nor does an
6060
+ * empty one, or one that is not drawn.
6061
+ ************************************************************/
6062
+ function publish_dock_band(gobj) {
6063
+ let $dock = gobj_read_attr(gobj, "$container");
6064
+ let top = 0;
6065
+ let bottom = 0;
6066
+ if ($dock && $dock.parentNode && $dock.classList.contains("yui-dock--floating") && !$dock.classList.contains("is-empty")) {
6067
+ let r = $dock.getBoundingClientRect();
6068
+ if (r.height > 0) {
6069
+ if ((gobj_read_attr(gobj, "dock_corner") || "bottom-left").indexOf("top") === 0) top = Math.ceil(r.bottom);
6070
+ else bottom = Math.ceil((window.innerHeight || 0) - r.top);
6071
+ }
6072
+ }
6073
+ let style = document.documentElement.style;
6074
+ if (top > 0) style.setProperty("--yui-dock-inset-top", `${top}px`);
6075
+ else style.removeProperty("--yui-dock-inset-top");
6076
+ if (bottom > 0) style.setProperty("--yui-dock-inset-bottom", `${bottom}px`);
6077
+ else style.removeProperty("--yui-dock-inset-bottom");
5691
6078
  }
5692
6079
  /************************************************************
5693
6080
  * Where the FLOATING dock lives when the app names no
@@ -5777,6 +6164,7 @@ function sync_dock_visibility(gobj) {
5777
6164
  let priv = gobj.priv;
5778
6165
  let $dock = gobj_read_attr(gobj, "$container");
5779
6166
  if ($dock) $dock.classList.toggle("is-empty", priv.windows.length === 0);
6167
+ publish_dock_band(gobj);
5780
6168
  }
5781
6169
  /************************************************************
5782
6170
  * Mark one entry active (raised), the rest inactive.
@@ -5815,10 +6203,17 @@ function minimize_entry(gobj, entry) {
5815
6203
  /************************************************************
5816
6204
  * Dock chip click: taskbar toggle — restore+focus a
5817
6205
  * minimized/inactive window, minimize the active one.
6206
+ *
6207
+ * The window brought back takes the keyboard focus too: the
6208
+ * reader pressed its chip to go there, and a window is heard
6209
+ * (Escape, Tab) only with the focus in it.
5818
6210
  ************************************************************/
5819
6211
  function on_chip_click(gobj, entry) {
5820
- if (entry.minimized || !entry.$chip.classList.contains("is-active")) focus_entry(gobj, entry);
5821
- else minimize_entry(gobj, entry);
6212
+ if (entry.minimized || !entry.$chip.classList.contains("is-active")) {
6213
+ focus_entry(gobj, entry);
6214
+ let $win = gobj_read_attr(entry.gobj, "$container");
6215
+ if ($win) $win.focus();
6216
+ } else minimize_entry(gobj, entry);
5822
6217
  }
5823
6218
  /***************************
5824
6219
  * Actions
@@ -5947,7 +6342,13 @@ function ac_minimize_window(gobj, event, kw, src) {
5947
6342
  let win = window_of(gobj, event, kw, src);
5948
6343
  if (!win) return -1;
5949
6344
  let entry = find_entry(gobj.priv, win);
5950
- if (entry) minimize_entry(gobj, entry);
6345
+ if (entry) {
6346
+ let $win = gobj_read_attr(win, "$container");
6347
+ let had_focus = !!($win && $win.contains(document.activeElement));
6348
+ minimize_entry(gobj, entry);
6349
+ let $toggle = had_focus && entry.$chip ? entry.$chip.querySelector(".DOCK_CHIP_TOGGLE") : null;
6350
+ if ($toggle) $toggle.focus();
6351
+ }
5951
6352
  return 0;
5952
6353
  }
5953
6354
  /************************************************************
@@ -7241,6 +7642,10 @@ function register_c_yui_wizard() {
7241
7642
  *
7242
7643
  * yui_tabulator_relocalize(table, t, {device_id: t("device id")});
7243
7644
  *
7645
+ * A column GROUP is bound by field too, and Tabulator gives it none:
7646
+ * give it one (`{title, field: "sizes", columns: [...]}`, no row reads
7647
+ * it) and its title goes in the same object. One without is said.
7648
+ *
7244
7649
  * Every key carries an English `defaultValue`, so an app that does not
7245
7650
  * define it renders exactly what Tabulator rendered before — the
7246
7651
  * keys are an OPPORTUNITY to translate, never a requirement.
@@ -7400,6 +7805,22 @@ function yui_tabulator_name_editor(column_def, name_of) {
7400
7805
  };
7401
7806
  }
7402
7807
  /***************************************************************
7808
+ * A column GROUP whose title cannot change language, said.
7809
+ *
7810
+ * Tabulator binds a column's title to the locale by its `field`, and
7811
+ * a group has none: its title stays in the language the table was
7812
+ * built in. Given a `field` (no row reads a group's), a group is
7813
+ * bound like any other column, and its title goes in `titles`.
7814
+ ***************************************************************/
7815
+ function say_groups_without_field(columns) {
7816
+ for (let column of columns || []) {
7817
+ let def = column.getDefinition() || {};
7818
+ if (!Array.isArray(def.columns)) continue;
7819
+ if (!def.field) log_warning(`yui_tabulator_relocalize: column group '${def.title}' has no field: its title stays in the language it was built in`);
7820
+ say_groups_without_field(column.getSubColumns());
7821
+ }
7822
+ }
7823
+ /***************************************************************
7403
7824
  * yui_tabulator_relocalize() -- see "Put an EXISTING table in the
7404
7825
  * current language" above.
7405
7826
  *
@@ -7408,14 +7829,19 @@ function yui_tabulator_name_editor(column_def, name_of) {
7408
7829
  * (`columns`), where Tabulator binds each column's title: setLocale()
7409
7830
  * draws them again without rebuilding a column -- updateDefinition()
7410
7831
  * re-renders every row, and a row whose formatter builds something (a
7411
- * nested table) builds it anew. A field left out keeps its title.
7832
+ * nested table) builds it anew. A field left out keeps its title. A
7833
+ * column GROUP is bound only if it has a `field` of its own: one
7834
+ * without is said (say_groups_without_field).
7412
7835
  ***************************************************************/
7413
7836
  function yui_tabulator_relocalize(table, t, titles) {
7414
7837
  if (!table) return;
7415
7838
  try {
7416
7839
  let name = next_lang_name();
7417
7840
  let strings = tabulator_strings(t);
7418
- if (titles && typeof titles === "object") strings.columns = Object.assign({}, titles);
7841
+ if (titles && typeof titles === "object") {
7842
+ strings.columns = Object.assign({}, titles);
7843
+ say_groups_without_field(table.getColumns(true));
7844
+ }
7419
7845
  table.options.langs = table.options.langs || {};
7420
7846
  table.options.langs[name] = strings;
7421
7847
  let localize = table.modules && table.modules.localize;
@@ -9342,7 +9768,9 @@ function json_editor_value(content) {
9342
9768
  * Not reached, because the editor gives them no hook: its search
9343
9769
  * box, its repair messages, the tip at the foot of the context
9344
9770
  * menu, and its modals (sort, transform). They stay in its
9345
- * English.
9771
+ * English. vanilla-jsoneditor (3.13.0) has no i18n option: they
9772
+ * are literals inside its Svelte components, and the only way to
9773
+ * them would be rewriting its DOM by its English words.
9346
9774
  *
9347
9775
  * Copyright (c) 2026, ArtGins.
9348
9776
  * All Rights Reserved.
@@ -9984,11 +10412,11 @@ function cell_icon(icon_class, key) {
9984
10412
  }
9985
10413
  /************************************************************
9986
10414
  * The identity of a table element, for the kw of
9987
- * EV_ADD_TABLE_ROW: a kw is plain json, and an element (with its
9988
- * `.tabulator`, circular) broke the `machine` trace that dumps it.
9989
- * Given on first use and kept on the element; the registry holds
9990
- * it weakly, so a nested table re-built by its row formatter is
9991
- * not kept alive by it.
10415
+ * EV_ADD_TABLE_ROW and EV_LOAD_TABLE_ROWS: a kw is plain json,
10416
+ * and an element (with its `.tabulator`, circular) broke the
10417
+ * `machine` trace that dumps it. Given on first use and kept on
10418
+ * the element; the registry holds it weakly, so a nested table
10419
+ * whose row is gone is not kept alive by it.
9992
10420
  ************************************************************/
9993
10421
  function table_identity(gobj, $table) {
9994
10422
  if (!$table.yui_table_id) {
@@ -10014,6 +10442,53 @@ function find_table(gobj, table_id) {
10014
10442
  return $table;
10015
10443
  }
10016
10444
  /************************************************************
10445
+ * Destroy one third-party widget, saying why it could not be.
10446
+ ************************************************************/
10447
+ function destroy_widget(gobj, what, widget) {
10448
+ try {
10449
+ let r = widget.destroy();
10450
+ if (r && typeof r.then === "function") r.catch((e) => {
10451
+ log_warning(`${gobj_short_name(gobj)}: cannot destroy ${what}: ${e}`);
10452
+ });
10453
+ } catch (e) {
10454
+ log_warning(`${gobj_short_name(gobj)}: cannot destroy ${what}: ${e}`);
10455
+ }
10456
+ }
10457
+ /************************************************************
10458
+ * A table element that is gone: its identity is no table now,
10459
+ * and what was waiting to be loaded in it never will be.
10460
+ ************************************************************/
10461
+ function forget_table(gobj, $table) {
10462
+ $table.yui_pending_rows = null;
10463
+ if ($table.yui_table_id && gobj.priv && gobj.priv.tables) gobj.priv.tables.delete($table.yui_table_id);
10464
+ }
10465
+ /************************************************************
10466
+ * Destroy the nested tables a row of a table built (its row
10467
+ * formatter keeps them on the row's element), theirs first.
10468
+ * Tabulator takes the row's DOM away when the row goes -- a
10469
+ * reload, an undo, a deleted row -- and destroys nothing in it:
10470
+ * each nested table stayed in Tabulator's registry, with its
10471
+ * observers, for the life of the page.
10472
+ ************************************************************/
10473
+ function destroy_row_tables(gobj, $row) {
10474
+ let nested = $row.yui_nested || [];
10475
+ $row.yui_nested = null;
10476
+ for (let $nested of nested) {
10477
+ if ($nested.tabulator) {
10478
+ destroy_rows_tables(gobj, $nested.tabulator);
10479
+ destroy_widget(gobj, "nested table", $nested.tabulator);
10480
+ $nested.tabulator = null;
10481
+ }
10482
+ forget_table(gobj, $nested);
10483
+ }
10484
+ }
10485
+ /************************************************************
10486
+ * Destroy the nested tables of every row of a table.
10487
+ ************************************************************/
10488
+ function destroy_rows_tables(gobj, tabulator) {
10489
+ for (let row of tabulator.getRows()) destroy_row_tables(gobj, row.getElement());
10490
+ }
10491
+ /************************************************************
10017
10492
  * Destroy the third-party widgets the form built. Removing
10018
10493
  * their DOM is not enough: Tom Select keeps listeners on
10019
10494
  * `document` and `window`, the jsoneditor is a live Svelte app
@@ -10022,40 +10497,21 @@ function find_table(gobj, table_id) {
10022
10497
  * first: their parent's destroy drops the rows they hang from.
10023
10498
  ************************************************************/
10024
10499
  function destroy_widgets(gobj, $container) {
10025
- let destroy = (what, widget) => {
10026
- try {
10027
- let r = widget.destroy();
10028
- if (r && typeof r.then === "function") r.catch((e) => {
10029
- log_warning(`${gobj_short_name(gobj)}: cannot destroy ${what}: ${e}`);
10030
- });
10031
- } catch (e) {
10032
- log_warning(`${gobj_short_name(gobj)}: cannot destroy ${what}: ${e}`);
10033
- }
10034
- };
10035
- let forget = ($el) => {
10036
- if ($el.yui_table_id && gobj.priv && gobj.priv.tables) gobj.priv.tables.delete($el.yui_table_id);
10037
- };
10038
- $container.querySelectorAll(".yui-tabulator-table-nested").forEach(($el) => {
10039
- if ($el.tabulator) {
10040
- destroy("nested table", $el.tabulator);
10041
- $el.tabulator = null;
10042
- }
10043
- forget($el);
10044
- });
10045
10500
  $container.querySelectorAll(".yui-form-data-input").forEach(($el) => {
10046
10501
  if ($el.tom_select) {
10047
- destroy("select", $el.tom_select);
10502
+ destroy_widget(gobj, "select", $el.tom_select);
10048
10503
  $el.tom_select = null;
10049
10504
  }
10050
10505
  if ($el.jsoneditor) {
10051
- destroy("json editor", $el.jsoneditor);
10506
+ destroy_widget(gobj, "json editor", $el.jsoneditor);
10052
10507
  $el.jsoneditor = null;
10053
10508
  }
10054
10509
  if ($el.tabulator) {
10055
- destroy("table", $el.tabulator);
10510
+ destroy_rows_tables(gobj, $el.tabulator);
10511
+ destroy_widget(gobj, "table", $el.tabulator);
10056
10512
  $el.tabulator = null;
10513
+ forget_table(gobj, $el);
10057
10514
  }
10058
- forget($el);
10059
10515
  });
10060
10516
  }
10061
10517
  /******************************************************************
@@ -10735,8 +11191,7 @@ function create_form_field(gobj, $form, prefix, field_desc, { tag, inputType, na
10735
11191
  }
10736
11192
  gobj_send_event(gobj, "EV_ADD_TABLE_ROW", {
10737
11193
  table_id: table_identity(gobj, $add_table),
10738
- record: {},
10739
- loading: false
11194
+ record: {}
10740
11195
  }, gobj);
10741
11196
  } }
10742
11197
  ]]
@@ -11290,10 +11745,24 @@ function create_coordinates(gobj, attrs) {
11290
11745
  }
11291
11746
  /******************************************************************
11292
11747
  * Create tabulator
11748
+ *
11749
+ * A row builds its nested tables the first time it is drawn, each
11750
+ * loaded from the row's own data, and keeps them on its element
11751
+ * (`yui_nested`) until the row goes (destroy_row_tables). A row
11752
+ * drawn AGAIN -- a forced redraw, a column rebuilt -- has its
11753
+ * children taken off by Tabulator before its formatter runs: they
11754
+ * are put back as they are. Built anew, they came back empty, and
11755
+ * the old ones stayed alive in Tabulator's registry.
11756
+ *
11757
+ * A load that comes before the table is built waits for its
11758
+ * `tableBuilt`, ONE per table (`yui_pending_rows`): a later load
11759
+ * replaces it, a clear drops it. Each load used to hang a listener
11760
+ * of its own, so two loads before the build drew the rows twice.
11293
11761
  ******************************************************************/
11294
11762
  function create_tabulator$1(gobj, $extend, name, template) {
11295
11763
  function get_selectable_state(row) {
11296
- return gobj_write_bool_attr(gobj, "selectable");
11764
+ let selectable_rows = tabulator.options.selectableRows;
11765
+ return gobj_read_bool_attr(gobj, "selectable") && (selectable_rows === true || typeof selectable_rows === "number");
11297
11766
  }
11298
11767
  $extend.template = template;
11299
11768
  let tabulator_settings = json_deep_copy(gobj_read_attr(gobj, "tabulator_settings"));
@@ -11309,6 +11778,13 @@ function create_tabulator$1(gobj, $extend, name, template) {
11309
11778
  let sub_elements = [];
11310
11779
  tabulator_settings.columns = template2columns(gobj, columns, template, sub_elements);
11311
11780
  if (sub_elements.length > 0) tabulator_settings.rowFormatter = function(row) {
11781
+ let $row = row.getElement();
11782
+ if ($row.yui_nested) {
11783
+ for (let $nested of $row.yui_nested) $row.appendChild($nested);
11784
+ return;
11785
+ }
11786
+ $row.yui_nested = [];
11787
+ let data = row.getData() || {};
11312
11788
  for (let sub_element of sub_elements) {
11313
11789
  let extend = ["div", {
11314
11790
  class: "yui-tabulator-table-nested pl-6 is-bordered is-striped",
@@ -11316,7 +11792,10 @@ function create_tabulator$1(gobj, $extend, name, template) {
11316
11792
  }];
11317
11793
  let $extend = createElement2(extend);
11318
11794
  $extend.tabulator = create_tabulator$1(gobj, $extend, sub_element.name, sub_element.template);
11319
- row.getElement().appendChild($extend);
11795
+ $row.appendChild($extend);
11796
+ $row.yui_nested.push($extend);
11797
+ let rows = data[sub_element.name];
11798
+ load_tabulator_data(gobj, $extend, is_array(rows) ? rows : []);
11320
11799
  }
11321
11800
  };
11322
11801
  if (gobj_read_bool_attr(gobj, "with_delete_row_btn")) columns.push({
@@ -11348,6 +11827,18 @@ function create_tabulator$1(gobj, $extend, name, template) {
11348
11827
  if (gobj.priv.loading_rows > 0) return;
11349
11828
  gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
11350
11829
  });
11830
+ $extend.yui_pending_rows = null;
11831
+ tabulator.on("tableBuilt", function() {
11832
+ let rows = $extend.yui_pending_rows;
11833
+ $extend.yui_pending_rows = null;
11834
+ if (rows && !gobj_is_destroying(gobj)) gobj_send_event(gobj, "EV_LOAD_TABLE_ROWS", {
11835
+ table_id: table_identity(gobj, $extend),
11836
+ rows
11837
+ }, gobj);
11838
+ });
11839
+ tabulator.on("rowDeleted", function(row) {
11840
+ destroy_row_tables(gobj, row.getElement());
11841
+ });
11351
11842
  tabulator.on("renderComplete", function() {
11352
11843
  yui_tabulator_name_row_selects(tabulator, t);
11353
11844
  });
@@ -11438,8 +11929,7 @@ function template2columns(gobj, columns, template, sub_elements) {
11438
11929
  }
11439
11930
  gobj_send_event(gobj, "EV_ADD_TABLE_ROW", {
11440
11931
  table_id: table_identity(gobj, $extend),
11441
- record: {},
11442
- loading: false
11932
+ record: {}
11443
11933
  }, gobj);
11444
11934
  }
11445
11935
  });
@@ -11667,6 +12157,21 @@ function getInputValue($input) {
11667
12157
  else return $input.value;
11668
12158
  }
11669
12159
  /************************************************************
12160
+ * The rows of a table as the form saves them: copies, each with
12161
+ * the rows of the nested tables its row holds. A row's
12162
+ * getData() is the row's OWN object: handed out in the save, a
12163
+ * later edit wrote into what the host had been given.
12164
+ ************************************************************/
12165
+ function table_values(tabulator) {
12166
+ let value = [];
12167
+ for (let row of tabulator.getRows()) {
12168
+ let d = json_deep_copy(row.getData());
12169
+ for (let $nested of row.getElement().yui_nested || []) if ($nested.tabulator) d[$nested.getAttribute("name")] = table_values($nested.tabulator);
12170
+ value.push(d);
12171
+ }
12172
+ return value;
12173
+ }
12174
+ /************************************************************
11670
12175
  * Function to get input value based on its type
11671
12176
  ************************************************************/
11672
12177
  function get_form_values(gobj, $form) {
@@ -11720,18 +12225,7 @@ function get_form_values(gobj, $form) {
11720
12225
  break;
11721
12226
  case "table":
11722
12227
  let template = gobj_read_attr(gobj, "template");
11723
- if (!empty_string(name) && kw_has_key(template, name)) {
11724
- value = [];
11725
- let rows = $input.tabulator.getRows();
11726
- for (let row of rows) {
11727
- let d = row.getData();
11728
- value.push(d);
11729
- row.getElement().querySelectorAll(".yui-tabulator-table-nested").forEach(($nested) => {
11730
- let name_n = $nested.getAttribute("name");
11731
- d[name_n] = $nested.tabulator.getData();
11732
- });
11733
- }
11734
- }
12228
+ if (!empty_string(name) && kw_has_key(template, name)) value = table_values($input.tabulator);
11735
12229
  break;
11736
12230
  case "coordinates":
11737
12231
  if ($input.tagName !== "INPUT") $input = $input.querySelector("input");
@@ -11748,7 +12242,10 @@ function get_form_values(gobj, $form) {
11748
12242
  return record;
11749
12243
  }
11750
12244
  /************************************************************
11751
- *
12245
+ * Empty the form. A table not built yet has no rows to clear
12246
+ * but may have a load waiting for its build: it is dropped too,
12247
+ * or the rows cleared here came back when the table was built.
12248
+ * The nested tables go with the rows that hold them.
11752
12249
  ************************************************************/
11753
12250
  function clear_data(gobj, $form) {
11754
12251
  let pkey = gobj_read_str_attr(gobj, "pkey");
@@ -11781,10 +12278,11 @@ function clear_data(gobj, $form) {
11781
12278
  if ($file.yui_file_render) $file.yui_file_render();
11782
12279
  });
11783
12280
  $form.querySelectorAll(".yui-tabulator-table").forEach(($table) => {
11784
- if ($table.tabulator.initialized) $table.tabulator.clearData();
11785
- $table.querySelectorAll(".yui-tabulator-table-nested").forEach(($table_nested) => {
11786
- if ($table_nested.tabulator.initialized) $table_nested.tabulator.clearData();
11787
- });
12281
+ $table.yui_pending_rows = null;
12282
+ if ($table.tabulator.initialized) {
12283
+ destroy_rows_tables(gobj, $table.tabulator);
12284
+ $table.tabulator.clearData();
12285
+ }
11788
12286
  });
11789
12287
  }
11790
12288
  /************************************************************
@@ -11909,27 +12407,35 @@ function set_form_values(gobj, template, $form, record) {
11909
12407
  return modified;
11910
12408
  }
11911
12409
  /************************************************************
11912
- * loading data from backend to tabulator,
11913
- * check if the table is built
12410
+ * Load the rows of a record in a table: all of them at once
12411
+ * (EV_LOAD_TABLE_ROWS), now if the table is built, else when it
12412
+ * is (create_tabulator's `tableBuilt`).
11914
12413
  ************************************************************/
11915
12414
  function load_tabulator_data(gobj, $table, value) {
11916
- if (!value) {
12415
+ if (!is_array(value)) {
11917
12416
  log_error(sprintf("%s: no data to load_tabulator_data()", gobj_short_name(gobj)));
11918
12417
  return;
11919
12418
  }
11920
- let tabulator = $table.tabulator;
11921
- if (tabulator.initialized) for (let row of value) gobj_send_event(gobj, "EV_ADD_TABLE_ROW", {
12419
+ if (!$table.tabulator.initialized) {
12420
+ $table.yui_pending_rows = value.length > 0 ? value : null;
12421
+ return;
12422
+ }
12423
+ $table.yui_pending_rows = null;
12424
+ if (value.length === 0) return;
12425
+ gobj_send_event(gobj, "EV_LOAD_TABLE_ROWS", {
11922
12426
  table_id: table_identity(gobj, $table),
11923
- record: row,
11924
- loading: true
12427
+ rows: value
11925
12428
  }, gobj);
11926
- else tabulator.on("tableBuilt", function() {
11927
- for (let row of value) gobj_send_event(gobj, "EV_ADD_TABLE_ROW", {
11928
- table_id: table_identity(gobj, $table),
11929
- record: row,
11930
- loading: true
11931
- }, gobj);
11932
- });
12429
+ }
12430
+ /************************************************************
12431
+ * Redraw a table once what was added to it is drawn: the
12432
+ * "double scrollbar" Tabulator leaves when its rows grow.
12433
+ ************************************************************/
12434
+ function redraw_table_later(gobj, $table) {
12435
+ setTimeout(function() {
12436
+ if (gobj_is_destroying(gobj)) return;
12437
+ if ($table && $table.tabulator) $table.tabulator.redraw();
12438
+ }, 30);
11933
12439
  }
11934
12440
  /************************************************************
11935
12441
  * Convert a record column value from backend
@@ -12237,8 +12743,16 @@ function ac_set_file_preview(gobj, event, kw, src) {
12237
12743
  return 0;
12238
12744
  }
12239
12745
  /************************************************************
12240
- * From internal form button for new rows
12241
- * or from load_tabulator_data() to load data from backend
12746
+ * From the add button of a table, outer or nested: the
12747
+ * reader's new row. A change of the reader's (`dataChanged`).
12748
+ * Tabulator keeps the object it is given and writes the
12749
+ * reader's edits into it: it is given a copy. A row added to a
12750
+ * nested table makes the row it lives in grow: the outer table
12751
+ * is the one redrawn.
12752
+ * {
12753
+ * table_id: the table (table_identity())
12754
+ * record: the new row, {} from the button
12755
+ * }
12242
12756
  ************************************************************/
12243
12757
  function ac_add_table_row(gobj, event, kw, src) {
12244
12758
  let table_id = kw.table_id;
@@ -12248,34 +12762,59 @@ function ac_add_table_row(gobj, event, kw, src) {
12248
12762
  log_error(`${gobj_short_name(gobj)}: EV_ADD_TABLE_ROW to a table that is gone: '${table_id}'`);
12249
12763
  return -1;
12250
12764
  }
12251
- let record = kw.record;
12252
- let loading = kw.loading;
12765
+ tabulator.addRow(json_deep_copy(is_object(kw.record) ? kw.record : {})).catch(function(error) {
12766
+ log_error(`${gobj_short_name(gobj)}: cannot add a table row: ${error}`);
12767
+ });
12768
+ redraw_table_later(gobj, $table.closest(".yui-tabulator-table"));
12769
+ return 0;
12770
+ }
12771
+ /************************************************************
12772
+ * From load_tabulator_data(): the rows of the record a table
12773
+ * shows, all of them in ONE call and one redraw. A row at a time
12774
+ * redrew every row of the table after each one: 300 rows took
12775
+ * 20 s, 300 with a nested table each 39 s.
12776
+ *
12777
+ * Tabulator keeps the objects it is given (Row.setData() copies
12778
+ * nothing) and a cell edit writes into them: handed the
12779
+ * `record`'s own, an edit wrote into the record, and Undo --
12780
+ * which loads the record again -- loaded the edit. It is given
12781
+ * a copy.
12782
+ *
12783
+ * And it says `dataChanged` INSIDE addData(), synchronously,
12784
+ * once per row: rows the FORM loads are muted there, whenever
12785
+ * they land -- also from a `tableBuilt` that comes after the
12786
+ * load returned, which is why no timer can tell them from the
12787
+ * reader's.
12788
+ * {
12789
+ * table_id: the table (table_identity())
12790
+ * rows: [record, ...]
12791
+ * }
12792
+ ************************************************************/
12793
+ function ac_load_table_rows(gobj, event, kw, src) {
12794
+ let table_id = kw.table_id;
12795
+ let $table = find_table(gobj, table_id);
12796
+ let tabulator = $table ? $table.tabulator : null;
12797
+ if (!tabulator) {
12798
+ log_error(`${gobj_short_name(gobj)}: EV_LOAD_TABLE_ROWS to a table that is gone: '${table_id}'`);
12799
+ return -1;
12800
+ }
12801
+ if (!is_array(kw.rows)) {
12802
+ log_error(`${gobj_short_name(gobj)}: EV_LOAD_TABLE_ROWS without rows: '${table_id}'`);
12803
+ return -1;
12804
+ }
12805
+ if (kw.rows.length === 0) return 0;
12806
+ let rows = json_deep_copy(kw.rows);
12253
12807
  let added;
12254
- if (loading) gobj.priv.loading_rows++;
12808
+ gobj.priv.loading_rows++;
12255
12809
  try {
12256
- added = tabulator.addRow(record);
12810
+ added = tabulator.addData(rows);
12257
12811
  } finally {
12258
- if (loading) gobj.priv.loading_rows--;
12259
- }
12260
- added.then(function(row) {
12261
- if (loading) {
12262
- let template = $table.template;
12263
- Object.entries(template).forEach(([key, template_value]) => {
12264
- if (str_in_list(template_value.flag, "table")) {
12265
- let $table_nested = row.getElement().querySelector(`.yui-tabulator-table-nested[name="${key}"]`);
12266
- if ($table_nested) load_tabulator_data(gobj, $table_nested, record[key]);
12267
- else log_error(sprintf("%s: nested table not found '%s'", gobj_short_name(gobj), key));
12268
- }
12269
- });
12270
- }
12271
- }).catch(function(error) {
12272
- log_error(`${gobj_short_name(gobj)}: cannot add a table row: ${error}`);
12812
+ gobj.priv.loading_rows--;
12813
+ }
12814
+ added.catch(function(error) {
12815
+ log_error(`${gobj_short_name(gobj)}: cannot load the rows of a table: ${error}`);
12273
12816
  });
12274
- setTimeout(function() {
12275
- if (gobj_is_destroying(gobj)) return;
12276
- let $target = loading ? $table : $table.closest(".yui-tabulator-table");
12277
- if ($target && $target.tabulator) $target.tabulator.redraw();
12278
- }, 30);
12817
+ redraw_table_later(gobj, $table);
12279
12818
  return 0;
12280
12819
  }
12281
12820
  /************************************************************
@@ -12465,6 +13004,11 @@ function create_gclass$17(gclass_name) {
12465
13004
  ac_add_table_row,
12466
13005
  null
12467
13006
  ],
13007
+ [
13008
+ "EV_LOAD_TABLE_ROWS",
13009
+ ac_load_table_rows,
13010
+ null
13011
+ ],
12468
13012
  [
12469
13013
  "EV_RECORD_CHANGED",
12470
13014
  ac_record_changed,
@@ -12537,6 +13081,7 @@ function create_gclass$17(gclass_name) {
12537
13081
  ["EV_UNDO_RECORD", 0],
12538
13082
  ["EV_CLEAR_RECORD", 0],
12539
13083
  ["EV_ADD_TABLE_ROW", 0],
13084
+ ["EV_LOAD_TABLE_ROWS", 0],
12540
13085
  ["EV_RECORD_CHANGED", 0],
12541
13086
  ["EV_COPY_RECORD", 0],
12542
13087
  ["EV_PASTE_RECORD", 0],
@@ -76840,6 +77385,7 @@ var PRIVATE_DATA$1 = {
76840
77385
  host_ids: null,
76841
77386
  order_undo: null,
76842
77387
  diagram_gobj: null,
77388
+ retired_diagrams: null,
76843
77389
  dialog: null,
76844
77390
  dialog_gen: 0,
76845
77391
  dialog_kind: "",
@@ -76876,6 +77422,7 @@ function mt_create$1(gobj) {
76876
77422
  priv.host_drafts = {};
76877
77423
  priv.host_ids = {};
76878
77424
  priv.save_queue = [];
77425
+ priv.retired_diagrams = [];
76879
77426
  build_ui$1(gobj);
76880
77427
  let subscriber = gobj_read_pointer_attr(gobj, "subscriber");
76881
77428
  if (!subscriber) subscriber = gobj_parent(gobj);
@@ -76897,6 +77444,7 @@ function mt_stop$1(gobj) {
76897
77444
  if (shell) gobj_unsubscribe_event(shell, "EV_LANGUAGE_CHANGED", {}, gobj);
76898
77445
  close_dialog(gobj);
76899
77446
  destroy_diagram(gobj);
77447
+ destroy_retired_diagrams(gobj);
76900
77448
  }
76901
77449
  /***************************************************************
76902
77450
  * Framework Method: Destroy
@@ -78412,12 +78960,29 @@ function render_diagram(gobj) {
78412
78960
  gobj_start(diagram);
78413
78961
  gobj_send_event(diagram, "EV_SHOW", {}, gobj);
78414
78962
  }
78963
+ /***************************************************************
78964
+ * The drawing leaves the screen at once and is destroyed on the
78965
+ * next turn (EV_DESTROY_DIAGRAMS). It can be leaving because of
78966
+ * its own node click, which it publishes from inside G6's dispatch
78967
+ * of that click: stopped there, the gobj went from under its own
78968
+ * publication and the G6 graph from under its own event.
78969
+ ***************************************************************/
78415
78970
  function destroy_diagram(gobj) {
78416
78971
  let priv = gobj.priv;
78417
78972
  if (!priv.diagram_gobj) return;
78418
- gobj_stop(priv.diagram_gobj);
78419
- gobj_destroy(priv.diagram_gobj);
78973
+ let diagram = priv.diagram_gobj;
78420
78974
  priv.diagram_gobj = null;
78975
+ let $d = gobj_read_attr(diagram, "$container");
78976
+ if ($d && $d.parentNode) $d.parentNode.removeChild($d);
78977
+ priv.retired_diagrams.push(diagram);
78978
+ if (priv.retired_diagrams.length === 1) gobj_post_event(gobj, "EV_DESTROY_DIAGRAMS", {}, gobj);
78979
+ }
78980
+ function destroy_retired_diagrams(gobj) {
78981
+ let priv = gobj.priv;
78982
+ for (let diagram of priv.retired_diagrams.splice(0)) {
78983
+ if (gobj_is_running(diagram)) gobj_stop(diagram);
78984
+ gobj_destroy(diagram);
78985
+ }
78421
78986
  }
78422
78987
  /***************************
78423
78988
  * The forms
@@ -80406,6 +80971,13 @@ function ac_node_click(gobj, event, kw, src) {
80406
80971
  go(gobj, gobj.priv.treedb_id, topic, false, true);
80407
80972
  return reload_after_move(gobj);
80408
80973
  }
80974
+ /***************************************************************
80975
+ * The drawings left on the previous turn (destroy_diagram()).
80976
+ ***************************************************************/
80977
+ function ac_destroy_diagrams(gobj, event, kw, src) {
80978
+ destroy_retired_diagrams(gobj);
80979
+ return 0;
80980
+ }
80409
80981
  function ac_show_orphans(gobj, event, kw, src) {
80410
80982
  if (reload_first(gobj, event)) return -1;
80411
80983
  open_orphans(gobj);
@@ -81050,6 +81622,11 @@ function create_gclass$1(gclass_name) {
81050
81622
  "EV_EXPORT_VIEW",
81051
81623
  ac_export_view,
81052
81624
  null
81625
+ ],
81626
+ [
81627
+ "EV_DESTROY_DIAGRAMS",
81628
+ ac_destroy_diagrams,
81629
+ null
81053
81630
  ]
81054
81631
  ];
81055
81632
  const TREEDB_WIDE = [
@@ -81267,6 +81844,7 @@ function create_gclass$1(gclass_name) {
81267
81844
  ["EV_APPLY_IMPORT", 0],
81268
81845
  ["EV_CONFIRMED", 0],
81269
81846
  ["EV_NODE_CLICK", 0],
81847
+ ["EV_DESTROY_DIAGRAMS", 0],
81270
81848
  ["EV_POSITION_CHANGED", event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_NO_WARN_SUBS],
81271
81849
  ["EV_RECORD_WRITTEN", event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_NO_WARN_SUBS],
81272
81850
  ["EV_SCHEMA_CHECKED", event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_NO_WARN_SUBS]