@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.
@@ -98,3 +98,12 @@
98
98
  .C_YUI_FORM input[type="color"] {
99
99
  vertical-align: middle;
100
100
  }
101
+
102
+ /*--- A cell editor holding what is not a value yet (an incomplete date,
103
+ * form_time_cell_editor.js): it stays open, and says so. Above
104
+ * Tabulator's own `.tabulator-row .tabulator-cell.tabulator-editing
105
+ * input {outline: none}`. ---*/
106
+ .C_YUI_FORM .tabulator-cell.tabulator-editing input[aria-invalid="true"] {
107
+ outline: 2px solid var(--bulma-danger, #ff6685);
108
+ outline-offset: -2px;
109
+ }
package/src/c_yui_form.js CHANGED
@@ -95,7 +95,11 @@ import "tabulator-tables/dist/css/tabulator_bulma.css";
95
95
 
96
96
  import "./tabulator.css";
97
97
  import {is_time_field} from "./json_view_helpers.js";
98
- import {date_to_datetime_local, datetime_local_to_epoch} from "./form_time_value.js";
98
+ import {
99
+ date_to_datetime_local, datetime_local_to_epoch, time_value_to_date, epoch_to_time_value,
100
+ time_value_to_text
101
+ } from "./form_time_value.js";
102
+ import {form_time_cell_editor} from "./form_time_cell_editor.js";
99
103
  import {parse_json_field, json_editor_value} from "./form_json_field.js";
100
104
  import {
101
105
  json_editor_menu_items,
@@ -133,7 +137,7 @@ SDATA(data_type_t.DTP_STRING, "topic_name", 0, "", "Treedb topic na
133
137
  SDATA(data_type_t.DTP_BOOLEAN, "editable", 0, false, "Default is editable, set false to readonly"),
134
138
  SDATA(data_type_t.DTP_BOOLEAN, "readonly", 0, false, "Show EVERY field read-only, whatever its schema says: a record being LOOKED at, not edited. Independent of `editable`, which drives the TABLE rendering; this one drives the FORM"),
135
139
  SDATA(data_type_t.DTP_BOOLEAN, "selectable", 0, true, "A click selects a row, when tabulator_settings selects rows (selectableRows)"),
136
- SDATA(data_type_t.DTP_BOOLEAN, "with_checkbox", 0, false, "Show a first column with checkbox to select rows"),
140
+ SDATA(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`)"),
137
141
  SDATA(data_type_t.DTP_BOOLEAN, "with_rownum", 0, false, "Print first column with row number"),
138
142
  SDATA(data_type_t.DTP_BOOLEAN, "with_delete_row_btn", 0, false, "Print last column with delete row button"),
139
143
  /*
@@ -189,6 +193,13 @@ let PRIVATE_DATA = {
189
193
  json_names_posted: false,
190
194
  /* The shell this form hears the language change from. */
191
195
  lang_shell: null,
196
+ /* Moved by every write of `changes` (set_changed_stated): a cell
197
+ * editor cancelled gives back the state it opened on only if
198
+ * nothing but its own typing moved it since (cell_edit). */
199
+ change_seq: 0,
200
+ /* The cell editor open: {table_id, edited, changes, seq}, see
201
+ * ac_cell_edit_opened. */
202
+ cell_edit: null,
192
203
  };
193
204
 
194
205
  let __gclass__ = null;
@@ -224,6 +235,25 @@ function mt_create(gobj)
224
235
  build_ui(gobj);
225
236
  }
226
237
 
238
+ /************************************************************
239
+ * Framework Method writing
240
+ ************************************************************/
241
+ function mt_writing(gobj, path)
242
+ {
243
+ if(path === "selectable") {
244
+ /* The checkbox column follows it, in every table built */
245
+ let $container = gobj_read_attr(gobj, "$container");
246
+ if(!$container) {
247
+ return;
248
+ }
249
+ for(let $table of $container.querySelectorAll(".yui-tabulator-table, .yui-tabulator-table-nested")) {
250
+ if($table.tabulator) {
251
+ show_row_selection(gobj, $table.tabulator);
252
+ }
253
+ }
254
+ }
255
+ }
256
+
227
257
  /************************************************************
228
258
  * Framework Method destroy
229
259
  * In this point, all children
@@ -291,6 +321,7 @@ function mt_stop(gobj)
291
321
  ************************************************************/
292
322
  function set_changed_stated(gobj, changed)
293
323
  {
324
+ gobj.priv.change_seq += 1;
294
325
  let $container = gobj_read_attr(gobj, "$container");
295
326
  let $form = $container.querySelector('form');
296
327
 
@@ -620,15 +651,40 @@ function destroy_widget(gobj, what, widget)
620
651
  * walks the rows already wiped: a reload, a Clear or a destroy
621
652
  * with an editor open in any row but the first threw, and left
622
653
  * the table half wiped.
654
+ *
655
+ * Tabulator has no public way to ask which cell is edited: this
656
+ * reads its edit module (`modules.edit`, `currentCell`,
657
+ * `cancelEdit()`), names pinned against the installed Tabulator
658
+ * by tabulator_edit_internals.test.js. A Tabulator without them
659
+ * is said: the guard would do nothing, and the crash come back.
623
660
  ************************************************************/
624
- function close_table_editor(tabulator)
661
+ function close_table_editor(gobj, tabulator)
625
662
  {
626
663
  let edit = tabulator.modules? tabulator.modules.edit : null;
627
- if(edit && edit.currentCell) {
664
+ if(!edit || !("currentCell" in edit) || typeof edit.cancelEdit !== "function") {
665
+ log_warning(`${gobj_short_name(gobj)}: this Tabulator has no modules.edit.currentCell/cancelEdit(): ` +
666
+ `an open cell editor is not closed before its table is wiped`);
667
+ return;
668
+ }
669
+ if(edit.currentCell) {
628
670
  edit.cancelEdit();
629
671
  }
630
672
  }
631
673
 
674
+ /************************************************************
675
+ * The element of the table (`.tabulator` kept on it) that holds
676
+ * $el, the innermost one.
677
+ ************************************************************/
678
+ function table_element_of($el)
679
+ {
680
+ for(let $n = $el; $n; $n = $n.parentNode) {
681
+ if($n.tabulator) {
682
+ return $n;
683
+ }
684
+ }
685
+ return null;
686
+ }
687
+
632
688
  /************************************************************
633
689
  * A table element that is gone: its identity is no table now,
634
690
  * and what was waiting to be loaded in it never will be.
@@ -655,7 +711,7 @@ function destroy_row_tables(gobj, $row)
655
711
  $row.yui_nested = null;
656
712
  for(let $nested of nested) {
657
713
  if($nested.tabulator) {
658
- close_table_editor($nested.tabulator);
714
+ close_table_editor(gobj, $nested.tabulator);
659
715
  destroy_rows_tables(gobj, $nested.tabulator);
660
716
  destroy_widget(gobj, "nested table", $nested.tabulator);
661
717
  $nested.tabulator = null;
@@ -694,7 +750,7 @@ function destroy_widgets(gobj, $container)
694
750
  $el.jsoneditor = null;
695
751
  }
696
752
  if($el.tabulator) {
697
- close_table_editor($el.tabulator);
753
+ close_table_editor(gobj, $el.tabulator);
698
754
  destroy_rows_tables(gobj, $el.tabulator);
699
755
  destroy_widget(gobj, "table", $el.tabulator);
700
756
  $el.tabulator = null;
@@ -864,6 +920,12 @@ function build_form(gobj)
864
920
  {
865
921
  let form_id = gobj_read_str_attr(gobj, "form_id");
866
922
  let $form = createElement2(['form', {id: form_id, class: 'yui-form'}]);
923
+ /* Widget plumbing, not an action: the values are read from the
924
+ * controls, never submitted. Enter in a form of a single text box
925
+ * is an implicit submission, and up to 7.26.46 it reloaded the page. */
926
+ $form.addEventListener("submit", function(ev) {
927
+ ev.preventDefault();
928
+ });
867
929
 
868
930
  /*----------------------------*
869
931
  * Check if template exists
@@ -1518,7 +1580,7 @@ function create_form_field(
1518
1580
  ['div', {class: 'field-body'}, [
1519
1581
  ['div', {class: 'field'}, [
1520
1582
  ['div', {class: '' }, [
1521
- ['button', {class: 'button p-1',
1583
+ ['button', {class: 'button p-1', type: 'button',
1522
1584
  title: t('add'), 'data-i18n-title': 'add',
1523
1585
  'aria-label': t('add'), 'data-i18n-aria-label': 'add'}, [
1524
1586
  ['span', {class: 'icon m-0'}, html_markup('<i class="yi-plus"></i>')],
@@ -2236,6 +2298,31 @@ function create_coordinates(gobj, attrs)
2236
2298
  return $extend;
2237
2299
  }
2238
2300
 
2301
+ /******************************************************************
2302
+ * Show the checkbox column of a table while the form is
2303
+ * `selectable`, hide it while it is not. The column is the table's
2304
+ * row header, the first of its structured columns. A table not
2305
+ * built yet does it when it is (tableBuilt).
2306
+ ******************************************************************/
2307
+ function show_row_selection(gobj, tabulator)
2308
+ {
2309
+ if(!gobj_read_bool_attr(gobj, "with_checkbox") || !tabulator.initialized) {
2310
+ return;
2311
+ }
2312
+ let column = tabulator.getColumns(true).find(
2313
+ (c) => c.getDefinition().formatter === "rowSelection"
2314
+ );
2315
+ if(!column) {
2316
+ log_error(`${gobj_short_name(gobj)}: the table has no checkbox column to show or hide`);
2317
+ return;
2318
+ }
2319
+ if(gobj_read_bool_attr(gobj, "selectable")) {
2320
+ column.show();
2321
+ } else {
2322
+ column.hide();
2323
+ }
2324
+ }
2325
+
2239
2326
  /******************************************************************
2240
2327
  * Create tabulator
2241
2328
  *
@@ -2264,6 +2351,19 @@ function create_coordinates(gobj, attrs)
2264
2351
  * the form's `selectable` -- first. Up to 7.26.44 the form toggled
2265
2352
  * the row again in `rowClick`, which undid every click. The default
2266
2353
  * `"highlight"` is left as it is, hover and all.
2354
+ *
2355
+ * The checkbox column (`with_checkbox`) asks `selectable` too, and is
2356
+ * not shown while the form is not selectable: Tabulator's row box
2357
+ * ticks before its toggle is refused (a ticked box over a row not
2358
+ * selected), and its header box selects every row asking nothing. Up
2359
+ * to 7.26.45 the boxes were drawn and lied; with the default
2360
+ * `selectableRows` they selected whatever `selectable` said. Up to
2361
+ * 7.26.46 `selectable` was read when the table was built; the column
2362
+ * now follows every write of it (mt_writing, show_row_selection).
2363
+ *
2364
+ * A click in a nested table stays there: it bubbled to the row that
2365
+ * holds the table, whose own click listener (SelectRow's) toggled
2366
+ * that row too.
2267
2367
  ******************************************************************/
2268
2368
  function create_tabulator(gobj, $extend, name, template, rows)
2269
2369
  {
@@ -2275,8 +2375,9 @@ function create_tabulator(gobj, $extend, name, template, rows)
2275
2375
  }
2276
2376
 
2277
2377
  /* Tabulator toggles the row on its own click: `selectable` only vetoes */
2378
+ let with_checkbox = gobj_read_bool_attr(gobj, "with_checkbox");
2278
2379
  let selectable_rows = tabulator_settings.selectableRows;
2279
- if(selectable_rows === true || typeof selectable_rows === "number") {
2380
+ if(selectable_rows === true || typeof selectable_rows === "number" || with_checkbox) {
2280
2381
  tabulator_settings.selectableRowsCheck = function() {
2281
2382
  return gobj_read_bool_attr(gobj, "selectable");
2282
2383
  };
@@ -2317,6 +2418,15 @@ function create_tabulator(gobj, $extend, name, template, rows)
2317
2418
  }
2318
2419
  ];
2319
2420
  let $extend = createElement2(extend);
2421
+ /* Widget plumbing, not an action: the event is the nested table's */
2422
+ $extend.addEventListener("click", function(ev) {
2423
+ ev.stopPropagation();
2424
+ });
2425
+ $extend.addEventListener("mousedown", function(ev) {
2426
+ if(ev.shiftKey) {
2427
+ ev.stopPropagation();
2428
+ }
2429
+ });
2320
2430
  let rows = data[sub_element.name];
2321
2431
  $extend.tabulator = create_tabulator(
2322
2432
  gobj, $extend, sub_element.name, sub_element.template, rows
@@ -2348,7 +2458,7 @@ function create_tabulator(gobj, $extend, name, template, rows)
2348
2458
  );
2349
2459
  }
2350
2460
 
2351
- if(gobj_read_bool_attr(gobj, "with_checkbox")) {
2461
+ if(with_checkbox) {
2352
2462
  tabulator_settings.rowHeader = {
2353
2463
  formatter: "rowSelection",
2354
2464
  titleFormatter: "rowSelection",
@@ -2356,7 +2466,8 @@ function create_tabulator(gobj, $extend, name, template, rows)
2356
2466
  resizable: false,
2357
2467
  frozen: true,
2358
2468
  headerHozAlign: "center",
2359
- hozAlign: "center"
2469
+ hozAlign: "center",
2470
+ visible: gobj_read_bool_attr(gobj, "selectable")
2360
2471
  };
2361
2472
  }
2362
2473
 
@@ -2380,8 +2491,43 @@ function create_tabulator(gobj, $extend, name, template, rows)
2380
2491
  }
2381
2492
  gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
2382
2493
  });
2494
+ /* What the reader TYPES in a cell editor is `edited` at once, as in a
2495
+ * field of the form (its `input`): `dataChanged` comes only when the
2496
+ * editor commits, and a host that reloads or closes the form by code
2497
+ * asks `edited` first. Up to 7.26.45 a half-typed cell was not
2498
+ * edited, and such a reload dropped it without a question. Only the
2499
+ * editor of a cell of THIS table: not a header filter, not the
2500
+ * selection box, not a nested table's editor (that table says it). */
2501
+ $extend.addEventListener("input", function(ev) {
2502
+ let $target = ev.target;
2503
+ if(!$target || typeof $target.closest !== "function" ||
2504
+ !$target.closest(".tabulator-cell.tabulator-editing") ||
2505
+ table_element_of($target) !== $extend) {
2506
+ return;
2507
+ }
2508
+ gobj_send_event(gobj, "EV_RECORD_CHANGED",
2509
+ {typed_in: table_identity(gobj, $extend)}, gobj);
2510
+ });
2511
+ /* An edit CANCELLED (Escape, a box left as it was) gives back the
2512
+ * `edited` and `changes` the form had when its editor opened: what
2513
+ * was typed in it is gone (ac_cell_edit_cancelled). */
2514
+ tabulator.on("cellEditing", function() {
2515
+ if(gobj_is_destroying(gobj)) {
2516
+ return;
2517
+ }
2518
+ gobj_send_event(gobj, "EV_CELL_EDIT_OPENED",
2519
+ {table_id: table_identity(gobj, $extend)}, gobj);
2520
+ });
2521
+ tabulator.on("cellEditCancelled", function() {
2522
+ if(gobj_is_destroying(gobj)) {
2523
+ return; // closed by the teardown (close_table_editor)
2524
+ }
2525
+ gobj_send_event(gobj, "EV_CELL_EDIT_CANCELLED",
2526
+ {table_id: table_identity(gobj, $extend)}, gobj);
2527
+ });
2383
2528
  $extend.yui_pending_rows = null;
2384
2529
  tabulator.on("tableBuilt", function() {
2530
+ show_row_selection(gobj, tabulator);
2385
2531
  let rows = $extend.yui_pending_rows;
2386
2532
  $extend.yui_pending_rows = null;
2387
2533
  if(rows && !gobj_is_destroying(gobj)) {
@@ -2644,25 +2790,18 @@ function template2columns(gobj, columns, template, sub_elements)
2644
2790
 
2645
2791
  case "now":
2646
2792
  case "time":
2647
- // field_conf.tag = 'input';
2648
- // field_conf.inputType = 'datetime-local';
2649
- column.editor = "datetime";
2793
+ /* Tabulator's `datetime` with a `format` needs luxon: see
2794
+ * form_time_cell_editor.js. Named after its column
2795
+ * (yui_tabulator_name_editor, below). */
2796
+ column.editor = form_time_cell_editor(field_desc.real_type);
2650
2797
  column.editorParams = {
2651
- format: "dd/MM/yyyy hh:mm", // the format of the date value stored in the cell
2652
2798
  verticalNavigation: "table", //navigate cursor around table without changing the value
2653
- elementAttributes: {
2654
- /* Tabulator writes this attribute once, when the
2655
- * editor opens, so it is translated then -- which
2656
- * is also when it is read. */
2657
- title: t("slide bar to choose option")
2658
- }
2659
2799
  };
2660
- switch(field_desc.real_type) {
2661
- case "string":
2662
- break;
2663
- case "integer":
2664
- break;
2665
- }
2800
+ /* The clock, not the epoch: up to 7.26.46 the cell showed
2801
+ * the raw number. */
2802
+ column.formatter = function(cell) {
2803
+ return text_node(time_value_to_text(cell.getValue(), field_desc.real_type));
2804
+ };
2666
2805
  break;
2667
2806
 
2668
2807
  case "color":
@@ -3156,7 +3295,7 @@ function clear_data(gobj, $form)
3156
3295
  $form.querySelectorAll('.yui-tabulator-table').forEach($table => {
3157
3296
  $table.yui_pending_rows = null;
3158
3297
  if($table.tabulator.initialized) {
3159
- close_table_editor($table.tabulator);
3298
+ close_table_editor(gobj, $table.tabulator);
3160
3299
  destroy_rows_tables(gobj, $table.tabulator);
3161
3300
  $table.tabulator.clearData();
3162
3301
  }
@@ -3481,9 +3620,9 @@ function treedb_value_2_form_value(gobj, field_desc, value)
3481
3620
  break;
3482
3621
  case "now":
3483
3622
  case "time":
3484
- /* Stored epoch is in SECONDS (Yuneta/timeranger convention),
3485
- * matching get_form_values() which saves getTime()/1000. */
3486
- value = new Date((parseInt(value) || 0) * 1000);
3623
+ /* An epoch in SECONDS, or an ISO text for a string column;
3624
+ * null when it holds no time (form_time_value.js). */
3625
+ value = time_value_to_date(value, field_desc.real_type);
3487
3626
  break;
3488
3627
  case "date":
3489
3628
  case "color":
@@ -3620,14 +3759,12 @@ function form_value_2_treedb_value(gobj, field_desc, value)
3620
3759
  case "time":
3621
3760
  switch(real_type) {
3622
3761
  case "string":
3623
- if(value && is_date(value)) {
3624
- value = value.toISOString();
3625
- }
3626
- break;
3627
3762
  case "integer":
3628
- if(value && is_date(value)) {
3629
- value = (value.getTime())/1000;
3763
+ /* The box gives an epoch in seconds (get_form_values) */
3764
+ if(is_date(value)) {
3765
+ value = Math.floor(value.getTime() / 1000);
3630
3766
  }
3767
+ value = epoch_to_time_value(value, real_type);
3631
3768
  break;
3632
3769
  default:
3633
3770
  log_error("incompatible type for time: " + real_type);
@@ -3967,8 +4104,55 @@ function ac_load_table_rows(gobj, event, kw, src)
3967
4104
  function ac_record_changed(gobj, event, kw, src)
3968
4105
  {
3969
4106
  if(gobj_read_bool_attr(gobj, "initialized")) {
4107
+ let priv = gobj.priv;
4108
+ let open = priv.cell_edit;
4109
+ /* Typing in the open editor, and nothing else since it opened */
4110
+ let own = !!(open && kw && kw.typed_in === open.table_id &&
4111
+ open.seq === priv.change_seq);
3970
4112
  set_edited_by_reader(gobj);
4113
+ if(own) {
4114
+ open.seq = priv.change_seq;
4115
+ }
4116
+ }
4117
+ return 0;
4118
+ }
4119
+
4120
+ /************************************************************
4121
+ * A cell editor opened, in the table `table_id`: what the form
4122
+ * says now is what a cancel of it gives back.
4123
+ ************************************************************/
4124
+ function ac_cell_edit_opened(gobj, event, kw, src)
4125
+ {
4126
+ let priv = gobj.priv;
4127
+ priv.cell_edit = {
4128
+ table_id: kw.table_id,
4129
+ edited: gobj_read_bool_attr(gobj, "edited"),
4130
+ changes: gobj_read_bool_attr(gobj, "changes"),
4131
+ seq: priv.change_seq
4132
+ };
4133
+ return 0;
4134
+ }
4135
+
4136
+ /************************************************************
4137
+ * A cell editor cancelled -- Escape, or a box left as it was:
4138
+ * the value comes back, and so do the `edited` and `changes` the
4139
+ * form had when it opened. Up to gobj-ui 7.26.46 what was typed
4140
+ * in it still counted, and closing asked about a change that was
4141
+ * gone. Nothing is given back when anything but that editor's
4142
+ * own typing changed the form meanwhile: that change is real.
4143
+ ************************************************************/
4144
+ function ac_cell_edit_cancelled(gobj, event, kw, src)
4145
+ {
4146
+ let priv = gobj.priv;
4147
+ let open = priv.cell_edit;
4148
+ priv.cell_edit = null;
4149
+ if(!open || open.table_id !== kw.table_id || open.seq !== priv.change_seq) {
4150
+ return 0; // not the editor that opened, or the form changed meanwhile
4151
+ }
4152
+ if(gobj_read_bool_attr(gobj, "changes") !== open.changes) {
4153
+ set_changed_stated(gobj, open.changes);
3971
4154
  }
4155
+ gobj_write_bool_attr(gobj, "edited", open.edited);
3972
4156
  return 0;
3973
4157
  }
3974
4158
 
@@ -4174,6 +4358,7 @@ function cmd_get_picked_files(gobj, cmd, kw, src)
4174
4358
  *---------------------------------------------*/
4175
4359
  const gmt = {
4176
4360
  mt_create: mt_create,
4361
+ mt_writing: mt_writing,
4177
4362
  mt_start: mt_start,
4178
4363
  mt_stop: mt_stop,
4179
4364
  mt_destroy: mt_destroy,
@@ -4202,6 +4387,8 @@ function create_gclass(gclass_name)
4202
4387
  ["EV_ADD_TABLE_ROW", ac_add_table_row, null],
4203
4388
  ["EV_LOAD_TABLE_ROWS", ac_load_table_rows, null],
4204
4389
  ["EV_RECORD_CHANGED", ac_record_changed, null],
4390
+ ["EV_CELL_EDIT_OPENED", ac_cell_edit_opened, null],
4391
+ ["EV_CELL_EDIT_CANCELLED", ac_cell_edit_cancelled, null],
4205
4392
  ["EV_COPY_RECORD", ac_copy_record, null],
4206
4393
  ["EV_PASTE_RECORD", ac_paste_record, null],
4207
4394
  ["EV_SET_FILE_PREVIEW", ac_set_file_preview, null],
@@ -4229,6 +4416,8 @@ function create_gclass(gclass_name)
4229
4416
  ["EV_ADD_TABLE_ROW", 0],
4230
4417
  ["EV_LOAD_TABLE_ROWS", 0],
4231
4418
  ["EV_RECORD_CHANGED", 0],
4419
+ ["EV_CELL_EDIT_OPENED", 0],
4420
+ ["EV_CELL_EDIT_CANCELLED", 0],
4232
4421
  ["EV_COPY_RECORD", 0],
4233
4422
  ["EV_PASTE_RECORD", 0],
4234
4423
  ["EV_SET_FILE_PREVIEW", 0],
@@ -181,7 +181,7 @@ let PRIVATE_DATA = {
181
181
  event_handlers: {},
182
182
  hash_handler: null,
183
183
  keydown_handler: null,
184
- /* Escape priority chain: array of { layer, handler }. Each
184
+ /* Escape priority chain: array of { layer, handler, teardown }. Each
185
185
  * interactive overlay (drawer today, modal/popup tomorrow)
186
186
  * pushes its close handler when it opens and pops it when
187
187
  * it closes. Escape calls the top handler only — LIFO. */
@@ -579,9 +579,11 @@ function mt_stop(gobj)
579
579
  return 0;
580
580
  }
581
581
 
582
- /* Tear down any toolbar dropdown that was open at stop time so its
583
- * document-level mousedown listener and escape-stack entry don't
584
- * outlive the shell. */
582
+ /* Tear down every overlay that was open at stop time -- drawers,
583
+ * modals, questions, the toolbar dropdown -- so no focus trap,
584
+ * document-level listener or escape-stack entry outlives the
585
+ * shell. */
586
+ retire_overlays(gobj);
585
587
  close_toolbar_dropdown(gobj);
586
588
 
587
589
  if(priv.hash_handler) {
@@ -654,7 +656,8 @@ function mt_destroy(gobj)
654
656
  * dropdown; calling close_toolbar_dropdown here is idempotent
655
657
  * (it returns early when nothing is open) and prevents a
656
658
  * dangling document mousedown listener / escape-stack entry
657
- * when stop is skipped. */
659
+ * when stop is skipped. The other overlays the same way. */
660
+ retire_overlays(gobj);
658
661
  close_toolbar_dropdown(gobj);
659
662
 
660
663
  let live_idx = __live_shells__.indexOf(gobj);
@@ -2533,7 +2536,7 @@ function open_toolbar_dropdown(gobj, item, action, $trigger)
2533
2536
  $panel.__yui_backdrop_handler__ = backdrop;
2534
2537
  $panel.__yui_dismiss_handler__ = dismiss;
2535
2538
  $panel.__yui_trigger__ = $trigger || null;
2536
- push_escape(gobj, "popup", close_fn);
2539
+ push_escape(gobj, "popup", close_fn, close_fn);
2537
2540
 
2538
2541
  /* Focus trap inside the panel — same module modals/drawers use. */
2539
2542
  $panel.__yui_focus_release__ = activate_focus_trap_on($panel);
@@ -2748,8 +2751,12 @@ function take_back_focus(ev)
2748
2751
  * only and consumes the event; LIFO ordering naturally matches
2749
2752
  * the z-index layering most apps use (drawer at the bottom,
2750
2753
  * modal on top, popup on top of that).
2754
+ *
2755
+ * `teardown` is the overlay's UNCONDITIONAL close, what the shell
2756
+ * runs when it stops with the overlay still up (close_overlays);
2757
+ * `handler` may be a guarded one (a modal's before_close).
2751
2758
  ************************************************************/
2752
- function push_escape(gobj, layer, handler)
2759
+ function push_escape(gobj, layer, handler, teardown)
2753
2760
  {
2754
2761
  let priv = gobj.priv;
2755
2762
  if(!priv || !priv.escape_stack) {
@@ -2757,7 +2764,65 @@ function push_escape(gobj, layer, handler)
2757
2764
  return;
2758
2765
  }
2759
2766
  priv.escape_seq += 1;
2760
- priv.escape_stack.push({ layer: layer, handler: handler, seq: priv.escape_seq });
2767
+ priv.escape_stack.push({
2768
+ layer: layer,
2769
+ handler: handler,
2770
+ teardown: (typeof teardown === "function") ? teardown : null,
2771
+ seq: priv.escape_seq
2772
+ });
2773
+ }
2774
+
2775
+ /************************************************************
2776
+ * Close every overlay still up, the top first, as if each had
2777
+ * been dismissed: a shell that stops -- a logout, a session cut
2778
+ * -- with a drawer, a modal or a question open. Up to gobj-ui
2779
+ * 7.26.45 only the toolbar dropdown was closed: the others kept
2780
+ * their focus trap, and every window opened afterwards believed
2781
+ * itself under an overlay and took no focus; a question never
2782
+ * answered. Run before the views stop, so what an overlay's
2783
+ * on_close calls is still alive. An overlay pushed with no
2784
+ * teardown is left to its owner.
2785
+ ************************************************************/
2786
+ function close_overlays(gobj)
2787
+ {
2788
+ let priv = gobj.priv;
2789
+ if(!priv || !priv.escape_stack) {
2790
+ return;
2791
+ }
2792
+ let entries = priv.escape_stack.slice().reverse();
2793
+ for(let entry of entries) {
2794
+ if(!entry.teardown) {
2795
+ continue;
2796
+ }
2797
+ try {
2798
+ entry.teardown();
2799
+ } catch(e) {
2800
+ log_warning(`C_YUI_SHELL: closing the '${entry.layer}' overlay at stop failed: ${e}`);
2801
+ }
2802
+ }
2803
+ }
2804
+
2805
+ /************************************************************
2806
+ * What a shell that stops does with its overlays: their
2807
+ * history markers are left where they are, and then they are
2808
+ * closed (close_overlays). The overlay stack is emptied FIRST,
2809
+ * so no close -- of an overlay closed here, or of a window
2810
+ * closed later -- retires its marker with a history.back().
2811
+ * Such a back() is asynchronous and a stopped shell no longer
2812
+ * hears where it lands: up to gobj-ui 7.26.46 a logout followed
2813
+ * by a new shell in the same turn had it taken by the new
2814
+ * shell's first window (Chromium stepped back off that window's
2815
+ * marker, Firefox dropped the back()), and the next Back left
2816
+ * the page. A marker left in place is inert, as a drained one
2817
+ * is: a later Back lands on it and is absorbed.
2818
+ ************************************************************/
2819
+ function retire_overlays(gobj)
2820
+ {
2821
+ let priv = gobj.priv;
2822
+ if(priv && priv.overlay_stack) {
2823
+ priv.overlay_stack.splice(0);
2824
+ }
2825
+ close_overlays(gobj);
2761
2826
  }
2762
2827
 
2763
2828
  function pop_escape(gobj, handler)
@@ -3170,7 +3235,7 @@ function open_drawer_one(gobj, $c)
3170
3235
  }
3171
3236
  let close_fn = () => close_drawer_one(gobj, $c);
3172
3237
  $c.__yui_close_handler__ = close_fn;
3173
- push_escape(gobj, "overlay", close_fn);
3238
+ push_escape(gobj, "overlay", close_fn, close_fn);
3174
3239
  $c.classList.add("is-active");
3175
3240
  let panel = $c.querySelector(".yui-drawer-panel") || $c;
3176
3241
  $c.__yui_focus_release__ = activate_focus_trap_on(panel);
@@ -4452,10 +4517,15 @@ function yui_shell_toggle_drawer(shell_gobj, menu_id)
4452
4517
  * `layer` is a free-form tag (e.g. "modal", "popup", "overlay").
4453
4518
  * Today it is informational; the LIFO ordering of the stack is
4454
4519
  * what determines Escape priority — and naturally matches the
4455
- * z-index layering most apps use (drawer < popup < modal). */
4456
- function yui_shell_push_escape(shell_gobj, layer, handler)
4520
+ * z-index layering most apps use (drawer < popup < modal).
4521
+ *
4522
+ * `teardown` (optional): the overlay's unconditional close, which
4523
+ * the shell runs if it stops with the overlay still up (a logout
4524
+ * with a modal open). Give it whenever `handler` may refuse to
4525
+ * close, or the overlay outlives its shell with its focus trap. */
4526
+ function yui_shell_push_escape(shell_gobj, layer, handler, teardown)
4457
4527
  {
4458
- push_escape(shell_gobj, layer, handler);
4528
+ push_escape(shell_gobj, layer, handler, teardown);
4459
4529
  }
4460
4530
  function yui_shell_pop_escape(shell_gobj, handler)
4461
4531
  {
@@ -123,6 +123,7 @@ import {cell_text, hook_cell_spec} from "./table_cell_text.js";
123
123
 
124
124
  import { TabulatorFull as Tabulator } from "tabulator-tables";
125
125
  import {text_node, text_list_item_formatter} from "./yui_text.js";
126
+ import {time_value_to_date} from "./form_time_value.js";
126
127
 
127
128
  /***************************************************************
128
129
  * Constants
@@ -2269,8 +2270,13 @@ function transform__treedb_value_2_table_value(gobj, col, value, row, field)
2269
2270
  switch(field_desc.real_type) {
2270
2271
  case "string":
2271
2272
  case "integer":
2272
- value = parseInt(value) || 0;
2273
- value = new Date(value*1000);
2273
+ /* An ISO text for a string column (up to 7.26.46 read
2274
+ * with parseInt, as 2026 seconds), none for no time. */
2275
+ value = time_value_to_date(value, field_desc.real_type);
2276
+ if(!value) {
2277
+ value = "";
2278
+ break;
2279
+ }
2274
2280
 
2275
2281
  const rawLocale = navigator.language;
2276
2282
  // Playwright Firefox without locale config and some embedded