@yuneta/gobj-ui 7.27.18 → 7.27.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -598,6 +598,14 @@ Back out of a deep data position land on it. Below a link there are no nodes:
598
598
  `link` + `children` (or `link` + `content`) is a config error, because a silent
599
599
  winner in "who owns the subpath" would be the worst outcome.
600
600
 
601
+ **A child already on screen stays in the document** (7.27.20+). Every change of
602
+ url below a node re-activates it, and the node used to hang its active child
603
+ again each time -- out of the document and back in, which a browser answers by
604
+ dropping the scroll of every element inside it. A topic table under a treedb
605
+ view came back at the top of a page whose rows were drawn for the bottom, and
606
+ showed nothing. Now only the node's chrome (navs, path) is rebuilt when the
607
+ active child is the one already hanging in its body.
608
+
601
609
  **The tree is a contract, not runtime state.** Once published, a node's path
602
610
  is a url a client may have bookmarked, scripted, or been sold as another door
603
611
  into the system. So there is deliberately **no reparent/move API**: the shape
@@ -1213,6 +1221,18 @@ or they render as the key itself in every language:
1213
1221
  "Some records no longer existed when the delete was confirmed; they were not deleted",
1214
1222
  ```
1215
1223
 
1224
+ ### A topic table under a hidden tab keeps its place
1225
+
1226
+ `C_YUI_TREEDB_TOPICS` hides the tables of the other topics with `display:none`,
1227
+ and Tabulator's own `autoResize` took that 0x0 for a resize: it redrew a table
1228
+ with no layout, where every row reads `offsetTop` 0, and each visit to another
1229
+ tab and back moved the reader about a dozen rows up the page. Since 7.27.19
1230
+ `C_YUI_TREEDB_TOPIC_WITH_FORM` watches the size of its table itself
1231
+ (`EV_TABLE_RESIZED`): a hidden table is left alone, and it is redrawn when it
1232
+ is seen again (where the scroll is kept), or when its size really changes.
1233
+ **`autoResize` is forced off** — a host's `tabulator_settings.autoResize` is
1234
+ not honoured.
1235
+
1216
1236
  ### Reading a topic table: filters, columns, CSV
1217
1237
 
1218
1238
  `C_YUI_TREEDB_TOPIC_WITH_FORM` had one global search box over the loaded rows.
@@ -3995,8 +4015,10 @@ It is off by default because the bar takes its words from the HOST's i18n, and
3995
4015
  a host that has not defined `"{{n}} selected"` and `"clear selection"` renders
3996
4016
  the keys. It shows only while the table is in **edition mode** — outside it the
3997
4017
  checkbox column is hidden, and a count of rows nobody can see or untick is a
3998
- count you cannot act on. The bar carries no action there: the table's own
3999
- toolbar already has Delete and Copy, and they act on the selection.
4018
+ count you cannot act on. For the same reason, **leaving edition mode clears the
4019
+ selection** (7.27.19+; it used to stay, painted, with nothing on screen to untick
4020
+ it). The bar carries no action there: the table's own toolbar already has Delete
4021
+ and Copy, and they act on the selection.
4000
4022
 
4001
4023
  `yui_selection_column({visible: false})` is for a table that reveals the column
4002
4024
  only in an edit mode — `C_YUI_TREEDB_TOPIC_WITH_FORM` shows it with
@@ -32768,9 +32768,8 @@ function render_selection_state(gobj) {
32768
32768
  *
32769
32769
  * Only while the table is EDITABLE: outside edition its checkbox
32770
32770
  * column is hidden (`hideColumn`), and a count of rows nobody can
32771
- * see or untick is a count you cannot act on. The selection itself
32772
- * is left alone -- coming back to edition finds it, and the bar
32773
- * recounts from the table.
32771
+ * see or untick is a count you cannot act on. Leaving edition also
32772
+ * drops the selection (ac_edition_mode).
32774
32773
  ************************************************************/
32775
32774
  function render_selection_bar(gobj) {
32776
32775
  let bar = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "selection_bar");
@@ -33096,10 +33095,10 @@ function create_tabulator(gobj) {
33096
33095
  }
33097
33096
  function operateFormatter(cell, formatterParams, onRendered) {
33098
33097
  return [
33099
- `<button class="button without-border px-2 edit" title="${attr_text((0, i18next.t)("edit"))}" aria-label="${attr_text((0, i18next.t)("edit"))}">`,
33098
+ `<button class="ROW_OP ROW_OP_EDIT button without-border px-2 edit" title="${attr_text((0, i18next.t)("edit"))}" aria-label="${attr_text((0, i18next.t)("edit"))}">`,
33100
33099
  "<i style=\"\" class=\"yi-pen has-text-link\"></i>",
33101
33100
  "</button>",
33102
- `<button class="button without-border px-2 remove" title="${attr_text((0, i18next.t)("delete"))}" aria-label="${attr_text((0, i18next.t)("delete"))}">`,
33101
+ `<button class="ROW_OP ROW_OP_DELETE button without-border px-2 remove" title="${attr_text((0, i18next.t)("delete"))}" aria-label="${attr_text((0, i18next.t)("delete"))}">`,
33103
33102
  "<i style=\"\" class=\"yi-trash has-text-danger\"></i>",
33104
33103
  "</button>"
33105
33104
  ].join("");
@@ -33178,7 +33177,8 @@ function create_tabulator(gobj) {
33178
33177
  index: pkey,
33179
33178
  columns,
33180
33179
  selectableRows: selectable,
33181
- footerElement: "<span class='yui-tabulator-rowcount yui-text-quiet' style='display:block;text-align:right;font-size:0.8rem;padding:0 0.6rem;'></span>"
33180
+ footerElement: "<span class='yui-tabulator-rowcount yui-text-quiet' style='display:block;text-align:right;font-size:0.8rem;padding:0 0.6rem;'></span>",
33181
+ autoResize: false
33182
33182
  });
33183
33183
  let $view_container = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "$container");
33184
33184
  let $table_el = $view_container ? $view_container.querySelector(`#${table_id}`) : null;
@@ -33188,6 +33188,7 @@ function create_tabulator(gobj) {
33188
33188
  }
33189
33189
  let tabulator = new tabulator_tables.TabulatorFull($table_el, Object.assign({}, tabulator_settings, yui_tabulator_lang(i18next.t), { placeholder: (0, i18next.t)("no data available", { defaultValue: "No data available" }) }));
33190
33190
  yui_tabulator_keep_edit_on_redraw(tabulator);
33191
+ watch_table_size(gobj, tabulator);
33191
33192
  if (with_checkbox) $table_el.classList.add("yui-no-row-hover");
33192
33193
  function update_rowcount(explicit_count) {
33193
33194
  let $rc = tabulator.element && tabulator.element.querySelector(".yui-tabulator-rowcount");
@@ -33292,9 +33293,59 @@ function create_tabulator(gobj) {
33292
33293
  (0, _yuneta_gobj_js.refresh_language)((0, _yuneta_gobj_js.gobj_read_attr)(gobj, "$container"), i18next.t);
33293
33294
  }
33294
33295
  /************************************************************
33296
+ * Tell the machine when the table changes size.
33297
+ *
33298
+ * What Tabulator's `autoResize` did, minus its mistake: a
33299
+ * table under a hidden tab measures 0x0, and that is not a
33300
+ * size to lay a table out to (ac_table_resized ignores it).
33301
+ * One event per frame, as the graphs do.
33302
+ ************************************************************/
33303
+ function watch_table_size(gobj, tabulator) {
33304
+ let priv = gobj.priv;
33305
+ unwatch_table_size(gobj);
33306
+ priv.table_size = null;
33307
+ if (typeof ResizeObserver === "undefined") return;
33308
+ let ro = new ResizeObserver((entries) => {
33309
+ let rect = entries[entries.length - 1].contentRect;
33310
+ let size = {
33311
+ width: Math.floor(rect.width),
33312
+ height: Math.floor(rect.height)
33313
+ };
33314
+ if (priv.table_resize_raf) cancelAnimationFrame(priv.table_resize_raf);
33315
+ priv.table_resize_raf = requestAnimationFrame(() => {
33316
+ priv.table_resize_raf = 0;
33317
+ (0, _yuneta_gobj_js.gobj_send_event)(gobj, "EV_TABLE_RESIZED", size, gobj);
33318
+ });
33319
+ });
33320
+ ro.observe(tabulator.element);
33321
+ priv.table_resize_observer = ro;
33322
+ priv.table_scroll = {
33323
+ top: 0,
33324
+ left: 0
33325
+ };
33326
+ tabulator.on("scrollVertical", (top) => {
33327
+ priv.table_scroll.top = top;
33328
+ });
33329
+ tabulator.on("scrollHorizontal", (left) => {
33330
+ priv.table_scroll.left = left;
33331
+ });
33332
+ }
33333
+ function unwatch_table_size(gobj) {
33334
+ let priv = gobj.priv;
33335
+ if (priv.table_resize_raf) {
33336
+ cancelAnimationFrame(priv.table_resize_raf);
33337
+ priv.table_resize_raf = 0;
33338
+ }
33339
+ if (priv.table_resize_observer) {
33340
+ priv.table_resize_observer.disconnect();
33341
+ priv.table_resize_observer = null;
33342
+ }
33343
+ }
33344
+ /************************************************************
33295
33345
  * Destroy Tabulator instance
33296
33346
  ************************************************************/
33297
33347
  function table__destroy(gobj) {
33348
+ unwatch_table_size(gobj);
33298
33349
  let tabulator = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "tabulator");
33299
33350
  if (tabulator) {
33300
33351
  yui_tabulator_close_editor(tabulator, (0, _yuneta_gobj_js.gobj_short_name)(gobj));
@@ -34310,6 +34361,11 @@ function show_edit_form(gobj, row) {
34310
34361
  * on a photo opened the popup AND the record on top of it: Tabulator
34311
34362
  * fires `rowClick` from its own dispatcher, and the cell's
34312
34363
  * stopPropagation() does not reach it.
34364
+ *
34365
+ * Asked of the field TYPE only, the one the column's `cellClick` is
34366
+ * chosen by (create_tabulator). It also asked the REAL type, and an
34367
+ * fkey to several parents is an `array` that draws as text with no
34368
+ * click of its own: a click on it opened nothing at all.
34313
34369
  ************************************************************/
34314
34370
  var CELL_WITH_ACTION = [
34315
34371
  "hook",
@@ -34328,7 +34384,7 @@ function cell_has_its_own_action(gobj, field) {
34328
34384
  let col = get_schema_col(gobj, field);
34329
34385
  if (!col) return false;
34330
34386
  const field_desc = (0, _yuneta_gobj_js.treedb_get_field_desc)(col);
34331
- return CELL_WITH_ACTION.includes(field_desc.type) || CELL_WITH_ACTION.includes(field_desc.real_type);
34387
+ return CELL_WITH_ACTION.includes(field_desc.type);
34332
34388
  }
34333
34389
  /************************************************************
34334
34390
  * Show a record to be READ: every field, none of them editable.
@@ -34748,6 +34804,7 @@ function ac_edition_mode(gobj, event, kw, src) {
34748
34804
  }
34749
34805
  tabulator.hideColumn("_operation");
34750
34806
  tabulator.hideColumn("_check_box_state_");
34807
+ yui_clear_selection(tabulator);
34751
34808
  if ($button_copy_record) $button_copy_record.setAttribute("disabled", true);
34752
34809
  if ($button_paste_record) $button_paste_record.setAttribute("disabled", true);
34753
34810
  }
@@ -35741,6 +35798,56 @@ function close_table_json_dialog(gobj) {
35741
35798
  teardown_table_json_child(gobj);
35742
35799
  }
35743
35800
  /************************************************************
35801
+ * {width, height}: the table's new size (watch_table_size).
35802
+ *
35803
+ * 0x0 is a HIDDEN table -- its tab, or the whole view, is
35804
+ * `display:none` -- and nothing is laid out to it: a redraw
35805
+ * there reads every row at `offsetTop` 0 and puts the top of
35806
+ * the virtual buffer at the top of the view, which is what
35807
+ * moved the reader a dozen rows up the page on every visit to
35808
+ * another tab.
35809
+ *
35810
+ * The redraw is done when the table is SEEN again, where the
35811
+ * rows have their real offsets, after giving back the scroll the
35812
+ * browser dropped with the `display:none` (watch_table_size). It is
35813
+ * needed there even at the same size: Tabulator does not draw
35814
+ * the data that arrives while it is hidden (a node event, a
35815
+ * refresh), it leaves that to its next sight.
35816
+ ************************************************************/
35817
+ function ac_table_resized(gobj, event, kw, src) {
35818
+ let priv = gobj.priv;
35819
+ let tabulator = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "tabulator");
35820
+ if (!tabulator) {
35821
+ (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: a size of a table that is gone`);
35822
+ return -1;
35823
+ }
35824
+ if (!kw.width || !kw.height) {
35825
+ priv.table_hidden = true;
35826
+ return 0;
35827
+ }
35828
+ let was_hidden = priv.table_hidden;
35829
+ priv.table_hidden = false;
35830
+ let last = priv.table_size;
35831
+ priv.table_size = {
35832
+ width: kw.width,
35833
+ height: kw.height
35834
+ };
35835
+ if (!tabulator._ready) return 0;
35836
+ if (!last) {
35837
+ tabulator.redraw(true);
35838
+ return 0;
35839
+ }
35840
+ if (was_hidden) {
35841
+ let $holder = tabulator.element.querySelector(".tabulator-tableholder");
35842
+ if ($holder) {
35843
+ $holder.scrollTop = priv.table_scroll.top;
35844
+ $holder.scrollLeft = priv.table_scroll.left;
35845
+ }
35846
+ }
35847
+ if (was_hidden || last.width !== kw.width || last.height !== kw.height) tabulator.redraw();
35848
+ return 0;
35849
+ }
35850
+ /************************************************************
35744
35851
  * {
35745
35852
  * href: href
35746
35853
  * }
@@ -36009,6 +36116,11 @@ function create_gclass$5(gclass_name) {
36009
36116
  ac_json_loaded,
36010
36117
  null
36011
36118
  ],
36119
+ [
36120
+ "EV_TABLE_RESIZED",
36121
+ ac_table_resized,
36122
+ null
36123
+ ],
36012
36124
  [
36013
36125
  "EV_SHOW",
36014
36126
  ac_show$4,
@@ -36077,6 +36189,7 @@ function create_gclass$5(gclass_name) {
36077
36189
  ["EV_UPDATE_RECORD", _yuneta_gobj_js.event_flag_t.EVF_OUTPUT_EVENT],
36078
36190
  ["EV_DELETE_RECORD", _yuneta_gobj_js.event_flag_t.EVF_OUTPUT_EVENT],
36079
36191
  ["EV_REFRESH_TOPIC", _yuneta_gobj_js.event_flag_t.EVF_OUTPUT_EVENT],
36192
+ ["EV_TABLE_RESIZED", 0],
36080
36193
  ["EV_SHOW", 0],
36081
36194
  ["EV_HIDE", 0]
36082
36195
  ];
@@ -32763,9 +32763,8 @@ function render_selection_state(gobj) {
32763
32763
  *
32764
32764
  * Only while the table is EDITABLE: outside edition its checkbox
32765
32765
  * column is hidden (`hideColumn`), and a count of rows nobody can
32766
- * see or untick is a count you cannot act on. The selection itself
32767
- * is left alone -- coming back to edition finds it, and the bar
32768
- * recounts from the table.
32766
+ * see or untick is a count you cannot act on. Leaving edition also
32767
+ * drops the selection (ac_edition_mode).
32769
32768
  ************************************************************/
32770
32769
  function render_selection_bar(gobj) {
32771
32770
  let bar = gobj_read_attr(gobj, "selection_bar");
@@ -33091,10 +33090,10 @@ function create_tabulator(gobj) {
33091
33090
  }
33092
33091
  function operateFormatter(cell, formatterParams, onRendered) {
33093
33092
  return [
33094
- `<button class="button without-border px-2 edit" title="${attr_text(t("edit"))}" aria-label="${attr_text(t("edit"))}">`,
33093
+ `<button class="ROW_OP ROW_OP_EDIT button without-border px-2 edit" title="${attr_text(t("edit"))}" aria-label="${attr_text(t("edit"))}">`,
33095
33094
  "<i style=\"\" class=\"yi-pen has-text-link\"></i>",
33096
33095
  "</button>",
33097
- `<button class="button without-border px-2 remove" title="${attr_text(t("delete"))}" aria-label="${attr_text(t("delete"))}">`,
33096
+ `<button class="ROW_OP ROW_OP_DELETE button without-border px-2 remove" title="${attr_text(t("delete"))}" aria-label="${attr_text(t("delete"))}">`,
33098
33097
  "<i style=\"\" class=\"yi-trash has-text-danger\"></i>",
33099
33098
  "</button>"
33100
33099
  ].join("");
@@ -33173,7 +33172,8 @@ function create_tabulator(gobj) {
33173
33172
  index: pkey,
33174
33173
  columns,
33175
33174
  selectableRows: selectable,
33176
- footerElement: "<span class='yui-tabulator-rowcount yui-text-quiet' style='display:block;text-align:right;font-size:0.8rem;padding:0 0.6rem;'></span>"
33175
+ footerElement: "<span class='yui-tabulator-rowcount yui-text-quiet' style='display:block;text-align:right;font-size:0.8rem;padding:0 0.6rem;'></span>",
33176
+ autoResize: false
33177
33177
  });
33178
33178
  let $view_container = gobj_read_attr(gobj, "$container");
33179
33179
  let $table_el = $view_container ? $view_container.querySelector(`#${table_id}`) : null;
@@ -33183,6 +33183,7 @@ function create_tabulator(gobj) {
33183
33183
  }
33184
33184
  let tabulator = new TabulatorFull($table_el, Object.assign({}, tabulator_settings, yui_tabulator_lang(t), { placeholder: t("no data available", { defaultValue: "No data available" }) }));
33185
33185
  yui_tabulator_keep_edit_on_redraw(tabulator);
33186
+ watch_table_size(gobj, tabulator);
33186
33187
  if (with_checkbox) $table_el.classList.add("yui-no-row-hover");
33187
33188
  function update_rowcount(explicit_count) {
33188
33189
  let $rc = tabulator.element && tabulator.element.querySelector(".yui-tabulator-rowcount");
@@ -33287,9 +33288,59 @@ function create_tabulator(gobj) {
33287
33288
  refresh_language(gobj_read_attr(gobj, "$container"), t);
33288
33289
  }
33289
33290
  /************************************************************
33291
+ * Tell the machine when the table changes size.
33292
+ *
33293
+ * What Tabulator's `autoResize` did, minus its mistake: a
33294
+ * table under a hidden tab measures 0x0, and that is not a
33295
+ * size to lay a table out to (ac_table_resized ignores it).
33296
+ * One event per frame, as the graphs do.
33297
+ ************************************************************/
33298
+ function watch_table_size(gobj, tabulator) {
33299
+ let priv = gobj.priv;
33300
+ unwatch_table_size(gobj);
33301
+ priv.table_size = null;
33302
+ if (typeof ResizeObserver === "undefined") return;
33303
+ let ro = new ResizeObserver((entries) => {
33304
+ let rect = entries[entries.length - 1].contentRect;
33305
+ let size = {
33306
+ width: Math.floor(rect.width),
33307
+ height: Math.floor(rect.height)
33308
+ };
33309
+ if (priv.table_resize_raf) cancelAnimationFrame(priv.table_resize_raf);
33310
+ priv.table_resize_raf = requestAnimationFrame(() => {
33311
+ priv.table_resize_raf = 0;
33312
+ gobj_send_event(gobj, "EV_TABLE_RESIZED", size, gobj);
33313
+ });
33314
+ });
33315
+ ro.observe(tabulator.element);
33316
+ priv.table_resize_observer = ro;
33317
+ priv.table_scroll = {
33318
+ top: 0,
33319
+ left: 0
33320
+ };
33321
+ tabulator.on("scrollVertical", (top) => {
33322
+ priv.table_scroll.top = top;
33323
+ });
33324
+ tabulator.on("scrollHorizontal", (left) => {
33325
+ priv.table_scroll.left = left;
33326
+ });
33327
+ }
33328
+ function unwatch_table_size(gobj) {
33329
+ let priv = gobj.priv;
33330
+ if (priv.table_resize_raf) {
33331
+ cancelAnimationFrame(priv.table_resize_raf);
33332
+ priv.table_resize_raf = 0;
33333
+ }
33334
+ if (priv.table_resize_observer) {
33335
+ priv.table_resize_observer.disconnect();
33336
+ priv.table_resize_observer = null;
33337
+ }
33338
+ }
33339
+ /************************************************************
33290
33340
  * Destroy Tabulator instance
33291
33341
  ************************************************************/
33292
33342
  function table__destroy(gobj) {
33343
+ unwatch_table_size(gobj);
33293
33344
  let tabulator = gobj_read_attr(gobj, "tabulator");
33294
33345
  if (tabulator) {
33295
33346
  yui_tabulator_close_editor(tabulator, gobj_short_name(gobj));
@@ -34305,6 +34356,11 @@ function show_edit_form(gobj, row) {
34305
34356
  * on a photo opened the popup AND the record on top of it: Tabulator
34306
34357
  * fires `rowClick` from its own dispatcher, and the cell's
34307
34358
  * stopPropagation() does not reach it.
34359
+ *
34360
+ * Asked of the field TYPE only, the one the column's `cellClick` is
34361
+ * chosen by (create_tabulator). It also asked the REAL type, and an
34362
+ * fkey to several parents is an `array` that draws as text with no
34363
+ * click of its own: a click on it opened nothing at all.
34308
34364
  ************************************************************/
34309
34365
  var CELL_WITH_ACTION = [
34310
34366
  "hook",
@@ -34323,7 +34379,7 @@ function cell_has_its_own_action(gobj, field) {
34323
34379
  let col = get_schema_col(gobj, field);
34324
34380
  if (!col) return false;
34325
34381
  const field_desc = treedb_get_field_desc(col);
34326
- return CELL_WITH_ACTION.includes(field_desc.type) || CELL_WITH_ACTION.includes(field_desc.real_type);
34382
+ return CELL_WITH_ACTION.includes(field_desc.type);
34327
34383
  }
34328
34384
  /************************************************************
34329
34385
  * Show a record to be READ: every field, none of them editable.
@@ -34743,6 +34799,7 @@ function ac_edition_mode(gobj, event, kw, src) {
34743
34799
  }
34744
34800
  tabulator.hideColumn("_operation");
34745
34801
  tabulator.hideColumn("_check_box_state_");
34802
+ yui_clear_selection(tabulator);
34746
34803
  if ($button_copy_record) $button_copy_record.setAttribute("disabled", true);
34747
34804
  if ($button_paste_record) $button_paste_record.setAttribute("disabled", true);
34748
34805
  }
@@ -35736,6 +35793,56 @@ function close_table_json_dialog(gobj) {
35736
35793
  teardown_table_json_child(gobj);
35737
35794
  }
35738
35795
  /************************************************************
35796
+ * {width, height}: the table's new size (watch_table_size).
35797
+ *
35798
+ * 0x0 is a HIDDEN table -- its tab, or the whole view, is
35799
+ * `display:none` -- and nothing is laid out to it: a redraw
35800
+ * there reads every row at `offsetTop` 0 and puts the top of
35801
+ * the virtual buffer at the top of the view, which is what
35802
+ * moved the reader a dozen rows up the page on every visit to
35803
+ * another tab.
35804
+ *
35805
+ * The redraw is done when the table is SEEN again, where the
35806
+ * rows have their real offsets, after giving back the scroll the
35807
+ * browser dropped with the `display:none` (watch_table_size). It is
35808
+ * needed there even at the same size: Tabulator does not draw
35809
+ * the data that arrives while it is hidden (a node event, a
35810
+ * refresh), it leaves that to its next sight.
35811
+ ************************************************************/
35812
+ function ac_table_resized(gobj, event, kw, src) {
35813
+ let priv = gobj.priv;
35814
+ let tabulator = gobj_read_attr(gobj, "tabulator");
35815
+ if (!tabulator) {
35816
+ log_error(`${gobj_short_name(gobj)}: a size of a table that is gone`);
35817
+ return -1;
35818
+ }
35819
+ if (!kw.width || !kw.height) {
35820
+ priv.table_hidden = true;
35821
+ return 0;
35822
+ }
35823
+ let was_hidden = priv.table_hidden;
35824
+ priv.table_hidden = false;
35825
+ let last = priv.table_size;
35826
+ priv.table_size = {
35827
+ width: kw.width,
35828
+ height: kw.height
35829
+ };
35830
+ if (!tabulator._ready) return 0;
35831
+ if (!last) {
35832
+ tabulator.redraw(true);
35833
+ return 0;
35834
+ }
35835
+ if (was_hidden) {
35836
+ let $holder = tabulator.element.querySelector(".tabulator-tableholder");
35837
+ if ($holder) {
35838
+ $holder.scrollTop = priv.table_scroll.top;
35839
+ $holder.scrollLeft = priv.table_scroll.left;
35840
+ }
35841
+ }
35842
+ if (was_hidden || last.width !== kw.width || last.height !== kw.height) tabulator.redraw();
35843
+ return 0;
35844
+ }
35845
+ /************************************************************
35739
35846
  * {
35740
35847
  * href: href
35741
35848
  * }
@@ -36004,6 +36111,11 @@ function create_gclass$5(gclass_name) {
36004
36111
  ac_json_loaded,
36005
36112
  null
36006
36113
  ],
36114
+ [
36115
+ "EV_TABLE_RESIZED",
36116
+ ac_table_resized,
36117
+ null
36118
+ ],
36007
36119
  [
36008
36120
  "EV_SHOW",
36009
36121
  ac_show$4,
@@ -36072,6 +36184,7 @@ function create_gclass$5(gclass_name) {
36072
36184
  ["EV_UPDATE_RECORD", event_flag_t.EVF_OUTPUT_EVENT],
36073
36185
  ["EV_DELETE_RECORD", event_flag_t.EVF_OUTPUT_EVENT],
36074
36186
  ["EV_REFRESH_TOPIC", event_flag_t.EVF_OUTPUT_EVENT],
36187
+ ["EV_TABLE_RESIZED", 0],
36075
36188
  ["EV_SHOW", 0],
36076
36189
  ["EV_HIDE", 0]
36077
36190
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.27.18",
3
+ "version": "7.27.20",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
package/src/c_yui_node.js CHANGED
@@ -931,10 +931,25 @@ function render_self(gobj)
931
931
  function render_child(gobj, child)
932
932
  {
933
933
  let priv = gobj.priv;
934
+ let $child = gobj_read_attr(child, "$container");
935
+
936
+ /* The child already hanging in my body is left where it is: only
937
+ * the chrome (the navs, the path) follows the route. Every change
938
+ * of url below me -- a tab of a treedb view is one -- re-activates
939
+ * this level, and re-hanging the child took its whole subtree out
940
+ * of the document and put it back, which drops the scroll of every
941
+ * element in it: a table came back at 0 with its rows still drawn
942
+ * for where the reader was, and showed only the padding above
943
+ * them. */
944
+ let in_place = !!$child && !!$child.parentNode &&
945
+ $child.parentNode.classList.contains("NODE_CHILD") &&
946
+ $child.parentNode.parentNode === priv.$body;
934
947
 
935
948
  clear_navs(gobj);
936
949
  priv.$chrome.replaceChildren();
937
- priv.$body.replaceChildren();
950
+ if(!in_place) {
951
+ priv.$body.replaceChildren();
952
+ }
938
953
 
939
954
  /* Every ancestor painting its own chrome stacks one strip per
940
955
  * level. `chrome_depth` is how a node caps that for its corner
@@ -948,8 +963,10 @@ function render_child(gobj, child)
948
963
  }
949
964
  render_path(gobj, priv.$chrome);
950
965
 
966
+ if(in_place) {
967
+ return;
968
+ }
951
969
  let $slot = createElement2(["div", {class: "NODE_CHILD"}]);
952
- let $child = gobj_read_attr(child, "$container");
953
970
  if($child) {
954
971
  $slot.appendChild($child);
955
972
  }
@@ -116,6 +116,17 @@
116
116
  background: transparent !important;
117
117
  }
118
118
 
119
+ /* The edit / delete buttons of a row (the Op column of edition mode):
120
+ * no taller than a line of text. Bulma's `2.5em` button made every row
121
+ * drawn while the column was shown 14px taller than the rows drawn
122
+ * before it -- rows of two heights in one table, the text of the tall
123
+ * ones sitting at the top of the row. */
124
+ .ROW_OP.button {
125
+ height: auto;
126
+ padding-top: 0;
127
+ padding-bottom: 0;
128
+ }
129
+
119
130
 
120
131
  /* Cell of a col flagged `icon`: the glyph is a CSS mask sized in `em`,
121
132
  * so it comes out at the row's font size -- smaller than the 18px the
@@ -1061,9 +1061,8 @@ function render_selection_state(gobj)
1061
1061
  *
1062
1062
  * Only while the table is EDITABLE: outside edition its checkbox
1063
1063
  * column is hidden (`hideColumn`), and a count of rows nobody can
1064
- * see or untick is a count you cannot act on. The selection itself
1065
- * is left alone -- coming back to edition finds it, and the bar
1066
- * recounts from the table.
1064
+ * see or untick is a count you cannot act on. Leaving edition also
1065
+ * drops the selection (ac_edition_mode).
1067
1066
  ************************************************************/
1068
1067
  function render_selection_bar(gobj)
1069
1068
  {
@@ -1592,12 +1591,12 @@ function create_tabulator(gobj)
1592
1591
 
1593
1592
  function operateFormatter(cell, formatterParams, onRendered) {
1594
1593
  return [
1595
- `<button class="button without-border px-2 edit" ` +
1594
+ `<button class="ROW_OP ROW_OP_EDIT button without-border px-2 edit" ` +
1596
1595
  `title="${attr_text(t("edit"))}" ` +
1597
1596
  `aria-label="${attr_text(t("edit"))}">`,
1598
1597
  '<i style="" class="yi-pen has-text-link"></i>',
1599
1598
  '</button>',
1600
- `<button class="button without-border px-2 remove" ` +
1599
+ `<button class="ROW_OP ROW_OP_DELETE button without-border px-2 remove" ` +
1601
1600
  `title="${attr_text(t("delete"))}" ` +
1602
1601
  `aria-label="${attr_text(t("delete"))}">`,
1603
1602
  '<i style="" class="yi-trash has-text-danger"></i>',
@@ -1755,6 +1754,13 @@ function create_tabulator(gobj)
1755
1754
  footerElement: "<span class='yui-tabulator-rowcount yui-text-quiet' " +
1756
1755
  "style='display:block;text-align:right;font-size:0.8rem;" +
1757
1756
  "padding:0 0.6rem;'></span>",
1757
+ /* The size of the table is watched HERE (watch_table_size), not by
1758
+ * Tabulator. Its own observers took a hidden tab -- `display:none`,
1759
+ * 0x0 -- for a resize, and redrew a table that had no layout: a row
1760
+ * reads `offsetTop` 0 there, so the redraw put the top of the
1761
+ * virtual buffer at the top of the view, and every visit to another
1762
+ * tab and back moved the reader a dozen rows up the page. */
1763
+ autoResize: false,
1758
1764
  });
1759
1765
 
1760
1766
  /*
@@ -1784,6 +1790,7 @@ function create_tabulator(gobj)
1784
1790
  placeholder: t("no data available", {defaultValue: "No data available"})
1785
1791
  }));
1786
1792
  yui_tabulator_keep_edit_on_redraw(tabulator);
1793
+ watch_table_size(gobj, tabulator);
1787
1794
 
1788
1795
  /* "highlight" still paints the whole-row hover wash (and a pointer
1789
1796
  * cursor), which reads as a selection. This table selects only via the
@@ -2014,11 +2021,69 @@ function create_tabulator(gobj)
2014
2021
  refresh_language(gobj_read_attr(gobj, "$container"), t);
2015
2022
  }
2016
2023
 
2024
+ /************************************************************
2025
+ * Tell the machine when the table changes size.
2026
+ *
2027
+ * What Tabulator's `autoResize` did, minus its mistake: a
2028
+ * table under a hidden tab measures 0x0, and that is not a
2029
+ * size to lay a table out to (ac_table_resized ignores it).
2030
+ * One event per frame, as the graphs do.
2031
+ ************************************************************/
2032
+ function watch_table_size(gobj, tabulator)
2033
+ {
2034
+ let priv = gobj.priv;
2035
+ unwatch_table_size(gobj);
2036
+ priv.table_size = null;
2037
+ if(typeof ResizeObserver === "undefined") {
2038
+ return;
2039
+ }
2040
+ let ro = new ResizeObserver((entries) => {
2041
+ let rect = entries[entries.length - 1].contentRect;
2042
+ let size = {width: Math.floor(rect.width), height: Math.floor(rect.height)};
2043
+ if(priv.table_resize_raf) {
2044
+ cancelAnimationFrame(priv.table_resize_raf);
2045
+ }
2046
+ priv.table_resize_raf = requestAnimationFrame(() => {
2047
+ priv.table_resize_raf = 0;
2048
+ gobj_send_event(gobj, "EV_TABLE_RESIZED", size, gobj);
2049
+ });
2050
+ });
2051
+ ro.observe(tabulator.element);
2052
+ priv.table_resize_observer = ro;
2053
+
2054
+ /* Where the reader is, kept for the next sight: a browser drops the
2055
+ * scroll of an element that goes `display:none`, and gives it back
2056
+ * at 0 -- the rows Tabulator drew for the old position are still
2057
+ * there, under 0, and the view shows only the padding above them.
2058
+ * Plumbing, not an action: one per scrolled pixel. */
2059
+ priv.table_scroll = {top: 0, left: 0};
2060
+ tabulator.on("scrollVertical", (top) => {
2061
+ priv.table_scroll.top = top;
2062
+ });
2063
+ tabulator.on("scrollHorizontal", (left) => {
2064
+ priv.table_scroll.left = left;
2065
+ });
2066
+ }
2067
+
2068
+ function unwatch_table_size(gobj)
2069
+ {
2070
+ let priv = gobj.priv;
2071
+ if(priv.table_resize_raf) {
2072
+ cancelAnimationFrame(priv.table_resize_raf);
2073
+ priv.table_resize_raf = 0;
2074
+ }
2075
+ if(priv.table_resize_observer) {
2076
+ priv.table_resize_observer.disconnect();
2077
+ priv.table_resize_observer = null;
2078
+ }
2079
+ }
2080
+
2017
2081
  /************************************************************
2018
2082
  * Destroy Tabulator instance
2019
2083
  ************************************************************/
2020
2084
  function table__destroy(gobj)
2021
2085
  {
2086
+ unwatch_table_size(gobj);
2022
2087
  let tabulator = gobj_read_attr(gobj, "tabulator");
2023
2088
  if(tabulator) {
2024
2089
  yui_tabulator_close_editor(tabulator, gobj_short_name(gobj));
@@ -3357,6 +3422,11 @@ function show_edit_form(gobj, row)
3357
3422
  * on a photo opened the popup AND the record on top of it: Tabulator
3358
3423
  * fires `rowClick` from its own dispatcher, and the cell's
3359
3424
  * stopPropagation() does not reach it.
3425
+ *
3426
+ * Asked of the field TYPE only, the one the column's `cellClick` is
3427
+ * chosen by (create_tabulator). It also asked the REAL type, and an
3428
+ * fkey to several parents is an `array` that draws as text with no
3429
+ * click of its own: a click on it opened nothing at all.
3360
3430
  ************************************************************/
3361
3431
  const CELL_WITH_ACTION = [
3362
3432
  "hook", "object", "dict", "template", "array", "list",
@@ -3373,8 +3443,7 @@ function cell_has_its_own_action(gobj, field)
3373
3443
  return false;
3374
3444
  }
3375
3445
  const field_desc = treedb_get_field_desc(col);
3376
- return CELL_WITH_ACTION.includes(field_desc.type) ||
3377
- CELL_WITH_ACTION.includes(field_desc.real_type);
3446
+ return CELL_WITH_ACTION.includes(field_desc.type);
3378
3447
  }
3379
3448
 
3380
3449
  /************************************************************
@@ -4081,6 +4150,11 @@ function ac_edition_mode(gobj, event, kw, src)
4081
4150
  tabulator.hideColumn('_operation');
4082
4151
  tabulator.hideColumn('_check_box_state_');
4083
4152
 
4153
+ /* The selection belongs to edition: outside it the checkbox
4154
+ * column is hidden, and a row left ticked stayed painted with
4155
+ * nothing on screen to untick it or to act on it. */
4156
+ yui_clear_selection(tabulator);
4157
+
4084
4158
  if($button_copy_record) {
4085
4159
  $button_copy_record.setAttribute("disabled", true);
4086
4160
  }
@@ -5391,6 +5465,63 @@ function close_table_json_dialog(gobj)
5391
5465
  teardown_table_json_child(gobj);
5392
5466
  }
5393
5467
 
5468
+ /************************************************************
5469
+ * {width, height}: the table's new size (watch_table_size).
5470
+ *
5471
+ * 0x0 is a HIDDEN table -- its tab, or the whole view, is
5472
+ * `display:none` -- and nothing is laid out to it: a redraw
5473
+ * there reads every row at `offsetTop` 0 and puts the top of
5474
+ * the virtual buffer at the top of the view, which is what
5475
+ * moved the reader a dozen rows up the page on every visit to
5476
+ * another tab.
5477
+ *
5478
+ * The redraw is done when the table is SEEN again, where the
5479
+ * rows have their real offsets, after giving back the scroll the
5480
+ * browser dropped with the `display:none` (watch_table_size). It is
5481
+ * needed there even at the same size: Tabulator does not draw
5482
+ * the data that arrives while it is hidden (a node event, a
5483
+ * refresh), it leaves that to its next sight.
5484
+ ************************************************************/
5485
+ function ac_table_resized(gobj, event, kw, src)
5486
+ {
5487
+ let priv = gobj.priv;
5488
+ let tabulator = gobj_read_attr(gobj, "tabulator");
5489
+ if(!tabulator) {
5490
+ log_error(`${gobj_short_name(gobj)}: a size of a table that is gone`);
5491
+ return -1;
5492
+ }
5493
+
5494
+ if(!kw.width || !kw.height) {
5495
+ priv.table_hidden = true;
5496
+ return 0;
5497
+ }
5498
+ let was_hidden = priv.table_hidden;
5499
+ priv.table_hidden = false;
5500
+
5501
+ let last = priv.table_size;
5502
+ priv.table_size = {width: kw.width, height: kw.height};
5503
+
5504
+ if(!tabulator._ready) {
5505
+ return 0; /* Tabulator lays its first build out itself, at this size */
5506
+ }
5507
+ if(!last) {
5508
+ tabulator.redraw(true); /* built hidden: never laid out */
5509
+ return 0;
5510
+ }
5511
+ if(was_hidden) {
5512
+ let $holder = tabulator.element.querySelector(".tabulator-tableholder");
5513
+ if($holder) {
5514
+ $holder.scrollTop = priv.table_scroll.top;
5515
+ $holder.scrollLeft = priv.table_scroll.left;
5516
+ }
5517
+ }
5518
+ if(was_hidden ||
5519
+ last.width !== kw.width || last.height !== kw.height) {
5520
+ tabulator.redraw();
5521
+ }
5522
+ return 0;
5523
+ }
5524
+
5394
5525
  /************************************************************
5395
5526
  * {
5396
5527
  * href: href
@@ -5496,6 +5627,7 @@ function create_gclass(gclass_name)
5496
5627
  ["EV_EXPORT_TABLE", ac_export_table, null],
5497
5628
  ["EV_SHOW_TABLE_JSON", ac_show_table_json, null],
5498
5629
  ["EV_JSON_LOADED", ac_json_loaded, null],
5630
+ ["EV_TABLE_RESIZED", ac_table_resized, null],
5499
5631
  ["EV_SHOW", ac_show, null],
5500
5632
  ["EV_HIDE", ac_hide, null]
5501
5633
  ]]
@@ -5564,6 +5696,7 @@ function create_gclass(gclass_name)
5564
5696
  ["EV_DELETE_RECORD", event_flag_t.EVF_OUTPUT_EVENT],
5565
5697
  ["EV_REFRESH_TOPIC", event_flag_t.EVF_OUTPUT_EVENT],
5566
5698
 
5699
+ ["EV_TABLE_RESIZED", 0],
5567
5700
  ["EV_SHOW", 0],
5568
5701
  ["EV_HIDE", 0]
5569
5702
  ];