@yuneta/gobj-ui 7.27.18 → 7.27.19

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
@@ -1213,6 +1213,18 @@ or they render as the key itself in every language:
1213
1213
  "Some records no longer existed when the delete was confirmed; they were not deleted",
1214
1214
  ```
1215
1215
 
1216
+ ### A topic table under a hidden tab keeps its place
1217
+
1218
+ `C_YUI_TREEDB_TOPICS` hides the tables of the other topics with `display:none`,
1219
+ and Tabulator's own `autoResize` took that 0x0 for a resize: it redrew a table
1220
+ with no layout, where every row reads `offsetTop` 0, and each visit to another
1221
+ tab and back moved the reader about a dozen rows up the page. Since 7.27.19
1222
+ `C_YUI_TREEDB_TOPIC_WITH_FORM` watches the size of its table itself
1223
+ (`EV_TABLE_RESIZED`): a hidden table is left alone, and it is redrawn when it
1224
+ is seen again (where the scroll is kept), or when its size really changes.
1225
+ **`autoResize` is forced off** — a host's `tabulator_settings.autoResize` is
1226
+ not honoured.
1227
+
1216
1228
  ### Reading a topic table: filters, columns, CSV
1217
1229
 
1218
1230
  `C_YUI_TREEDB_TOPIC_WITH_FORM` had one global search box over the loaded rows.
@@ -3995,8 +4007,10 @@ It is off by default because the bar takes its words from the HOST's i18n, and
3995
4007
  a host that has not defined `"{{n}} selected"` and `"clear selection"` renders
3996
4008
  the keys. It shows only while the table is in **edition mode** — outside it the
3997
4009
  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.
4010
+ count you cannot act on. For the same reason, **leaving edition mode clears the
4011
+ selection** (7.27.19+; it used to stay, painted, with nothing on screen to untick
4012
+ it). The bar carries no action there: the table's own toolbar already has Delete
4013
+ and Copy, and they act on the selection.
4000
4014
 
4001
4015
  `yui_selection_column({visible: false})` is for a table that reveals the column
4002
4016
  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,49 @@ 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
+ }
33323
+ function unwatch_table_size(gobj) {
33324
+ let priv = gobj.priv;
33325
+ if (priv.table_resize_raf) {
33326
+ cancelAnimationFrame(priv.table_resize_raf);
33327
+ priv.table_resize_raf = 0;
33328
+ }
33329
+ if (priv.table_resize_observer) {
33330
+ priv.table_resize_observer.disconnect();
33331
+ priv.table_resize_observer = null;
33332
+ }
33333
+ }
33334
+ /************************************************************
33295
33335
  * Destroy Tabulator instance
33296
33336
  ************************************************************/
33297
33337
  function table__destroy(gobj) {
33338
+ unwatch_table_size(gobj);
33298
33339
  let tabulator = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "tabulator");
33299
33340
  if (tabulator) {
33300
33341
  yui_tabulator_close_editor(tabulator, (0, _yuneta_gobj_js.gobj_short_name)(gobj));
@@ -34310,6 +34351,11 @@ function show_edit_form(gobj, row) {
34310
34351
  * on a photo opened the popup AND the record on top of it: Tabulator
34311
34352
  * fires `rowClick` from its own dispatcher, and the cell's
34312
34353
  * stopPropagation() does not reach it.
34354
+ *
34355
+ * Asked of the field TYPE only, the one the column's `cellClick` is
34356
+ * chosen by (create_tabulator). It also asked the REAL type, and an
34357
+ * fkey to several parents is an `array` that draws as text with no
34358
+ * click of its own: a click on it opened nothing at all.
34313
34359
  ************************************************************/
34314
34360
  var CELL_WITH_ACTION = [
34315
34361
  "hook",
@@ -34328,7 +34374,7 @@ function cell_has_its_own_action(gobj, field) {
34328
34374
  let col = get_schema_col(gobj, field);
34329
34375
  if (!col) return false;
34330
34376
  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);
34377
+ return CELL_WITH_ACTION.includes(field_desc.type);
34332
34378
  }
34333
34379
  /************************************************************
34334
34380
  * Show a record to be READ: every field, none of them editable.
@@ -34748,6 +34794,7 @@ function ac_edition_mode(gobj, event, kw, src) {
34748
34794
  }
34749
34795
  tabulator.hideColumn("_operation");
34750
34796
  tabulator.hideColumn("_check_box_state_");
34797
+ yui_clear_selection(tabulator);
34751
34798
  if ($button_copy_record) $button_copy_record.setAttribute("disabled", true);
34752
34799
  if ($button_paste_record) $button_paste_record.setAttribute("disabled", true);
34753
34800
  }
@@ -35741,6 +35788,48 @@ function close_table_json_dialog(gobj) {
35741
35788
  teardown_table_json_child(gobj);
35742
35789
  }
35743
35790
  /************************************************************
35791
+ * {width, height}: the table's new size (watch_table_size).
35792
+ *
35793
+ * 0x0 is a HIDDEN table -- its tab, or the whole view, is
35794
+ * `display:none` -- and nothing is laid out to it: a redraw
35795
+ * there reads every row at `offsetTop` 0 and puts the top of
35796
+ * the virtual buffer at the top of the view, which is what
35797
+ * moved the reader a dozen rows up the page on every visit to
35798
+ * another tab.
35799
+ *
35800
+ * The redraw is done when the table is SEEN again, where the
35801
+ * rows have their real offsets and the scroll is kept. It is
35802
+ * needed there even at the same size: Tabulator does not draw
35803
+ * the data that arrives while it is hidden (a node event, a
35804
+ * refresh), it leaves that to its next sight.
35805
+ ************************************************************/
35806
+ function ac_table_resized(gobj, event, kw, src) {
35807
+ let priv = gobj.priv;
35808
+ let tabulator = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "tabulator");
35809
+ if (!tabulator) {
35810
+ (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: a size of a table that is gone`);
35811
+ return -1;
35812
+ }
35813
+ if (!kw.width || !kw.height) {
35814
+ priv.table_hidden = true;
35815
+ return 0;
35816
+ }
35817
+ let was_hidden = priv.table_hidden;
35818
+ priv.table_hidden = false;
35819
+ let last = priv.table_size;
35820
+ priv.table_size = {
35821
+ width: kw.width,
35822
+ height: kw.height
35823
+ };
35824
+ if (!tabulator._ready) return 0;
35825
+ if (!last) {
35826
+ tabulator.redraw(true);
35827
+ return 0;
35828
+ }
35829
+ if (was_hidden || last.width !== kw.width || last.height !== kw.height) tabulator.redraw();
35830
+ return 0;
35831
+ }
35832
+ /************************************************************
35744
35833
  * {
35745
35834
  * href: href
35746
35835
  * }
@@ -36009,6 +36098,11 @@ function create_gclass$5(gclass_name) {
36009
36098
  ac_json_loaded,
36010
36099
  null
36011
36100
  ],
36101
+ [
36102
+ "EV_TABLE_RESIZED",
36103
+ ac_table_resized,
36104
+ null
36105
+ ],
36012
36106
  [
36013
36107
  "EV_SHOW",
36014
36108
  ac_show$4,
@@ -36077,6 +36171,7 @@ function create_gclass$5(gclass_name) {
36077
36171
  ["EV_UPDATE_RECORD", _yuneta_gobj_js.event_flag_t.EVF_OUTPUT_EVENT],
36078
36172
  ["EV_DELETE_RECORD", _yuneta_gobj_js.event_flag_t.EVF_OUTPUT_EVENT],
36079
36173
  ["EV_REFRESH_TOPIC", _yuneta_gobj_js.event_flag_t.EVF_OUTPUT_EVENT],
36174
+ ["EV_TABLE_RESIZED", 0],
36080
36175
  ["EV_SHOW", 0],
36081
36176
  ["EV_HIDE", 0]
36082
36177
  ];
@@ -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,49 @@ 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
+ }
33318
+ function unwatch_table_size(gobj) {
33319
+ let priv = gobj.priv;
33320
+ if (priv.table_resize_raf) {
33321
+ cancelAnimationFrame(priv.table_resize_raf);
33322
+ priv.table_resize_raf = 0;
33323
+ }
33324
+ if (priv.table_resize_observer) {
33325
+ priv.table_resize_observer.disconnect();
33326
+ priv.table_resize_observer = null;
33327
+ }
33328
+ }
33329
+ /************************************************************
33290
33330
  * Destroy Tabulator instance
33291
33331
  ************************************************************/
33292
33332
  function table__destroy(gobj) {
33333
+ unwatch_table_size(gobj);
33293
33334
  let tabulator = gobj_read_attr(gobj, "tabulator");
33294
33335
  if (tabulator) {
33295
33336
  yui_tabulator_close_editor(tabulator, gobj_short_name(gobj));
@@ -34305,6 +34346,11 @@ function show_edit_form(gobj, row) {
34305
34346
  * on a photo opened the popup AND the record on top of it: Tabulator
34306
34347
  * fires `rowClick` from its own dispatcher, and the cell's
34307
34348
  * stopPropagation() does not reach it.
34349
+ *
34350
+ * Asked of the field TYPE only, the one the column's `cellClick` is
34351
+ * chosen by (create_tabulator). It also asked the REAL type, and an
34352
+ * fkey to several parents is an `array` that draws as text with no
34353
+ * click of its own: a click on it opened nothing at all.
34308
34354
  ************************************************************/
34309
34355
  var CELL_WITH_ACTION = [
34310
34356
  "hook",
@@ -34323,7 +34369,7 @@ function cell_has_its_own_action(gobj, field) {
34323
34369
  let col = get_schema_col(gobj, field);
34324
34370
  if (!col) return false;
34325
34371
  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);
34372
+ return CELL_WITH_ACTION.includes(field_desc.type);
34327
34373
  }
34328
34374
  /************************************************************
34329
34375
  * Show a record to be READ: every field, none of them editable.
@@ -34743,6 +34789,7 @@ function ac_edition_mode(gobj, event, kw, src) {
34743
34789
  }
34744
34790
  tabulator.hideColumn("_operation");
34745
34791
  tabulator.hideColumn("_check_box_state_");
34792
+ yui_clear_selection(tabulator);
34746
34793
  if ($button_copy_record) $button_copy_record.setAttribute("disabled", true);
34747
34794
  if ($button_paste_record) $button_paste_record.setAttribute("disabled", true);
34748
34795
  }
@@ -35736,6 +35783,48 @@ function close_table_json_dialog(gobj) {
35736
35783
  teardown_table_json_child(gobj);
35737
35784
  }
35738
35785
  /************************************************************
35786
+ * {width, height}: the table's new size (watch_table_size).
35787
+ *
35788
+ * 0x0 is a HIDDEN table -- its tab, or the whole view, is
35789
+ * `display:none` -- and nothing is laid out to it: a redraw
35790
+ * there reads every row at `offsetTop` 0 and puts the top of
35791
+ * the virtual buffer at the top of the view, which is what
35792
+ * moved the reader a dozen rows up the page on every visit to
35793
+ * another tab.
35794
+ *
35795
+ * The redraw is done when the table is SEEN again, where the
35796
+ * rows have their real offsets and the scroll is kept. It is
35797
+ * needed there even at the same size: Tabulator does not draw
35798
+ * the data that arrives while it is hidden (a node event, a
35799
+ * refresh), it leaves that to its next sight.
35800
+ ************************************************************/
35801
+ function ac_table_resized(gobj, event, kw, src) {
35802
+ let priv = gobj.priv;
35803
+ let tabulator = gobj_read_attr(gobj, "tabulator");
35804
+ if (!tabulator) {
35805
+ log_error(`${gobj_short_name(gobj)}: a size of a table that is gone`);
35806
+ return -1;
35807
+ }
35808
+ if (!kw.width || !kw.height) {
35809
+ priv.table_hidden = true;
35810
+ return 0;
35811
+ }
35812
+ let was_hidden = priv.table_hidden;
35813
+ priv.table_hidden = false;
35814
+ let last = priv.table_size;
35815
+ priv.table_size = {
35816
+ width: kw.width,
35817
+ height: kw.height
35818
+ };
35819
+ if (!tabulator._ready) return 0;
35820
+ if (!last) {
35821
+ tabulator.redraw(true);
35822
+ return 0;
35823
+ }
35824
+ if (was_hidden || last.width !== kw.width || last.height !== kw.height) tabulator.redraw();
35825
+ return 0;
35826
+ }
35827
+ /************************************************************
35739
35828
  * {
35740
35829
  * href: href
35741
35830
  * }
@@ -36004,6 +36093,11 @@ function create_gclass$5(gclass_name) {
36004
36093
  ac_json_loaded,
36005
36094
  null
36006
36095
  ],
36096
+ [
36097
+ "EV_TABLE_RESIZED",
36098
+ ac_table_resized,
36099
+ null
36100
+ ],
36007
36101
  [
36008
36102
  "EV_SHOW",
36009
36103
  ac_show$4,
@@ -36072,6 +36166,7 @@ function create_gclass$5(gclass_name) {
36072
36166
  ["EV_UPDATE_RECORD", event_flag_t.EVF_OUTPUT_EVENT],
36073
36167
  ["EV_DELETE_RECORD", event_flag_t.EVF_OUTPUT_EVENT],
36074
36168
  ["EV_REFRESH_TOPIC", event_flag_t.EVF_OUTPUT_EVENT],
36169
+ ["EV_TABLE_RESIZED", 0],
36075
36170
  ["EV_SHOW", 0],
36076
36171
  ["EV_HIDE", 0]
36077
36172
  ];
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.19",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -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,56 @@ 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
+
2055
+ function unwatch_table_size(gobj)
2056
+ {
2057
+ let priv = gobj.priv;
2058
+ if(priv.table_resize_raf) {
2059
+ cancelAnimationFrame(priv.table_resize_raf);
2060
+ priv.table_resize_raf = 0;
2061
+ }
2062
+ if(priv.table_resize_observer) {
2063
+ priv.table_resize_observer.disconnect();
2064
+ priv.table_resize_observer = null;
2065
+ }
2066
+ }
2067
+
2017
2068
  /************************************************************
2018
2069
  * Destroy Tabulator instance
2019
2070
  ************************************************************/
2020
2071
  function table__destroy(gobj)
2021
2072
  {
2073
+ unwatch_table_size(gobj);
2022
2074
  let tabulator = gobj_read_attr(gobj, "tabulator");
2023
2075
  if(tabulator) {
2024
2076
  yui_tabulator_close_editor(tabulator, gobj_short_name(gobj));
@@ -3357,6 +3409,11 @@ function show_edit_form(gobj, row)
3357
3409
  * on a photo opened the popup AND the record on top of it: Tabulator
3358
3410
  * fires `rowClick` from its own dispatcher, and the cell's
3359
3411
  * stopPropagation() does not reach it.
3412
+ *
3413
+ * Asked of the field TYPE only, the one the column's `cellClick` is
3414
+ * chosen by (create_tabulator). It also asked the REAL type, and an
3415
+ * fkey to several parents is an `array` that draws as text with no
3416
+ * click of its own: a click on it opened nothing at all.
3360
3417
  ************************************************************/
3361
3418
  const CELL_WITH_ACTION = [
3362
3419
  "hook", "object", "dict", "template", "array", "list",
@@ -3373,8 +3430,7 @@ function cell_has_its_own_action(gobj, field)
3373
3430
  return false;
3374
3431
  }
3375
3432
  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);
3433
+ return CELL_WITH_ACTION.includes(field_desc.type);
3378
3434
  }
3379
3435
 
3380
3436
  /************************************************************
@@ -4081,6 +4137,11 @@ function ac_edition_mode(gobj, event, kw, src)
4081
4137
  tabulator.hideColumn('_operation');
4082
4138
  tabulator.hideColumn('_check_box_state_');
4083
4139
 
4140
+ /* The selection belongs to edition: outside it the checkbox
4141
+ * column is hidden, and a row left ticked stayed painted with
4142
+ * nothing on screen to untick it or to act on it. */
4143
+ yui_clear_selection(tabulator);
4144
+
4084
4145
  if($button_copy_record) {
4085
4146
  $button_copy_record.setAttribute("disabled", true);
4086
4147
  }
@@ -5391,6 +5452,55 @@ function close_table_json_dialog(gobj)
5391
5452
  teardown_table_json_child(gobj);
5392
5453
  }
5393
5454
 
5455
+ /************************************************************
5456
+ * {width, height}: the table's new size (watch_table_size).
5457
+ *
5458
+ * 0x0 is a HIDDEN table -- its tab, or the whole view, is
5459
+ * `display:none` -- and nothing is laid out to it: a redraw
5460
+ * there reads every row at `offsetTop` 0 and puts the top of
5461
+ * the virtual buffer at the top of the view, which is what
5462
+ * moved the reader a dozen rows up the page on every visit to
5463
+ * another tab.
5464
+ *
5465
+ * The redraw is done when the table is SEEN again, where the
5466
+ * rows have their real offsets and the scroll is kept. It is
5467
+ * needed there even at the same size: Tabulator does not draw
5468
+ * the data that arrives while it is hidden (a node event, a
5469
+ * refresh), it leaves that to its next sight.
5470
+ ************************************************************/
5471
+ function ac_table_resized(gobj, event, kw, src)
5472
+ {
5473
+ let priv = gobj.priv;
5474
+ let tabulator = gobj_read_attr(gobj, "tabulator");
5475
+ if(!tabulator) {
5476
+ log_error(`${gobj_short_name(gobj)}: a size of a table that is gone`);
5477
+ return -1;
5478
+ }
5479
+
5480
+ if(!kw.width || !kw.height) {
5481
+ priv.table_hidden = true;
5482
+ return 0;
5483
+ }
5484
+ let was_hidden = priv.table_hidden;
5485
+ priv.table_hidden = false;
5486
+
5487
+ let last = priv.table_size;
5488
+ priv.table_size = {width: kw.width, height: kw.height};
5489
+
5490
+ if(!tabulator._ready) {
5491
+ return 0; /* Tabulator lays its first build out itself, at this size */
5492
+ }
5493
+ if(!last) {
5494
+ tabulator.redraw(true); /* built hidden: never laid out */
5495
+ return 0;
5496
+ }
5497
+ if(was_hidden ||
5498
+ last.width !== kw.width || last.height !== kw.height) {
5499
+ tabulator.redraw();
5500
+ }
5501
+ return 0;
5502
+ }
5503
+
5394
5504
  /************************************************************
5395
5505
  * {
5396
5506
  * href: href
@@ -5496,6 +5606,7 @@ function create_gclass(gclass_name)
5496
5606
  ["EV_EXPORT_TABLE", ac_export_table, null],
5497
5607
  ["EV_SHOW_TABLE_JSON", ac_show_table_json, null],
5498
5608
  ["EV_JSON_LOADED", ac_json_loaded, null],
5609
+ ["EV_TABLE_RESIZED", ac_table_resized, null],
5499
5610
  ["EV_SHOW", ac_show, null],
5500
5611
  ["EV_HIDE", ac_hide, null]
5501
5612
  ]]
@@ -5564,6 +5675,7 @@ function create_gclass(gclass_name)
5564
5675
  ["EV_DELETE_RECORD", event_flag_t.EVF_OUTPUT_EVENT],
5565
5676
  ["EV_REFRESH_TOPIC", event_flag_t.EVF_OUTPUT_EVENT],
5566
5677
 
5678
+ ["EV_TABLE_RESIZED", 0],
5567
5679
  ["EV_SHOW", 0],
5568
5680
  ["EV_HIDE", 0]
5569
5681
  ];