@yuneta/gobj-ui 7.26.7 → 7.26.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/gobj-ui.cjs.js +372 -175
  2. package/dist/gobj-ui.es.js +372 -175
  3. package/package.json +1 -1
  4. package/src/c_g6_nodes_tree.js +28 -24
  5. package/src/c_yui_form.js +197 -63
  6. package/src/c_yui_gclass.js +22 -21
  7. package/src/c_yui_gobj_tree_js.js +7 -7
  8. package/src/c_yui_json.js +7 -6
  9. package/src/c_yui_json_graph.js +8 -7
  10. package/src/c_yui_json_pad.js +2 -1
  11. package/src/c_yui_map.js +25 -1
  12. package/src/c_yui_nav.js +7 -6
  13. package/src/c_yui_schema_editor.js +3 -2
  14. package/src/c_yui_shell.js +7 -0
  15. package/src/c_yui_treedb_topic_with_form.js +22 -17
  16. package/src/c_yui_treedb_topics.js +8 -7
  17. package/src/c_yui_window.js +72 -31
  18. package/src/c_yui_window_manager.js +3 -2
  19. package/src/form_json_field.js +10 -3
  20. package/src/form_json_field.test.js +6 -0
  21. package/src/form_json_field.wiring.test.js +1 -1
  22. package/src/form_table_rearm.wiring.test.js +158 -0
  23. package/src/g6_event_kw.js +36 -0
  24. package/src/nav_cards_helpers.js +2 -1
  25. package/src/nav_cards_helpers.test.js +7 -3
  26. package/src/schema_to_c.js +10 -0
  27. package/src/schema_to_c.test.js +8 -1
  28. package/src/shell_modals.js +5 -3
  29. package/src/shell_route_map.js +12 -13
  30. package/src/treedb_topics_transport.wiring.test.js +26 -0
  31. package/src/vite_plugin_yuneta_html.test.js +79 -0
  32. package/src/window_show.wiring.test.js +83 -0
  33. package/src/window_veto_back.wiring.test.js +35 -0
  34. package/src/yui_dev.js +13 -11
  35. package/src/yui_frontend_view.js +4 -4
  36. package/src/yui_gclass_view.js +3 -3
  37. package/src/yui_text.js +31 -0
  38. package/src/yui_text.test.js +39 -0
  39. package/vite-plugin-yuneta-html.js +9 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.26.7",
3
+ "version": "7.26.8",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -176,6 +176,7 @@ import {
176
176
  import {yui_theme_now, yui_watch_theme} from "./yui_theme.js";
177
177
  import {yui_shell_of} from "./c_yui_shell.js";
178
178
  import {yui_shell_show_error} from "./shell_modals.js";
179
+ import {g6_event_kw} from "./g6_event_kw.js";
179
180
 
180
181
  /***************************************************************
181
182
  * YuiToolbar — G6 Toolbar subclass that adds per-item className
@@ -473,6 +474,7 @@ SDATA_END()
473
474
  ];
474
475
 
475
476
  let PRIVATE_DATA = {
477
+ _drag_unwire: null, // removes the document listeners of a drag in flight
476
478
  /*---------------- camera anchor ----------------*/
477
479
  anchor_id: "", // the node the camera keeps in the middle
478
480
  anchor_state: "off", // "off" | "arming" | "on"
@@ -717,6 +719,11 @@ function mt_destroy(gobj)
717
719
 
718
720
  uninstall_fold_listener(gobj);
719
721
 
722
+ if(priv._drag_unwire) {
723
+ priv._drag_unwire(); // a resize or a link drag still in flight
724
+ priv._drag_unwire = null;
725
+ }
726
+
720
727
  if(priv._on_pointerdown_focus) {
721
728
  priv.$container.removeEventListener(
722
729
  "pointerdown", priv._on_pointerdown_focus, true
@@ -1059,30 +1066,6 @@ function build_graph(gobj)
1059
1066
  });
1060
1067
  }
1061
1068
 
1062
- /************************************************************
1063
- * A G6 event, as PLAIN JSON.
1064
- *
1065
- * A kw is dumped by the `machine` trace (`trace_json(kw)`), and a
1066
- * G6 / @antv/g event is circular: serializing one THROWS, so the
1067
- * first thing a kw carrying `evt` breaks is the trace the FSM
1068
- * exists to feed. It also drags a live graph element into a
1069
- * message that may be read after that element is gone.
1070
- *
1071
- * What the actions read of it is an id and three scalars. The
1072
- * event itself never leaves the callback that received it.
1073
- ************************************************************/
1074
- function g6_event_kw(evt)
1075
- {
1076
- let target = (evt && evt.target)? evt.target : null;
1077
- let client = (evt && evt.client)? evt.client : null;
1078
-
1079
- return {
1080
- id: (target && target.id)? String(target.id) : "",
1081
- shift: !!(evt && evt.shiftKey),
1082
- client_x: (client && typeof client.x === "number")? client.x : 0,
1083
- client_y: (client && typeof client.y === "number")? client.y : 0
1084
- };
1085
- }
1086
1069
 
1087
1070
  /************************************************************
1088
1071
  * Configure G6 event handlers
@@ -5645,6 +5628,13 @@ function start_node_resize(gobj, e, mx, my)
5645
5628
  document.addEventListener('pointermove', onPointerMove);
5646
5629
  document.addEventListener('pointerup', onPointerUp);
5647
5630
  document.addEventListener('pointercancel', onPointerCancel);
5631
+ /* A view destroyed in the middle of the drag takes them off too
5632
+ * (mt_destroy): they are closures over this gobj, on `document`. */
5633
+ gobj.priv._drag_unwire = function() {
5634
+ document.removeEventListener('pointermove', onPointerMove);
5635
+ document.removeEventListener('pointerup', onPointerUp);
5636
+ document.removeEventListener('pointercancel', onPointerCancel);
5637
+ };
5648
5638
  }
5649
5639
 
5650
5640
  /************************************************************
@@ -6534,6 +6524,13 @@ function start_link_drag(gobj, e)
6534
6524
  document.addEventListener('pointermove', onPointerMove);
6535
6525
  document.addEventListener('pointerup', onPointerUp);
6536
6526
  document.addEventListener('pointercancel', onPointerCancel);
6527
+ /* A view destroyed in the middle of the drag takes them off too
6528
+ * (mt_destroy): they are closures over this gobj, on `document`. */
6529
+ gobj.priv._drag_unwire = function() {
6530
+ document.removeEventListener('pointermove', onPointerMove);
6531
+ document.removeEventListener('pointerup', onPointerUp);
6532
+ document.removeEventListener('pointercancel', onPointerCancel);
6533
+ };
6537
6534
  }
6538
6535
 
6539
6536
  /************************************************************
@@ -6812,6 +6809,13 @@ function start_port_resize(gobj, e)
6812
6809
  document.addEventListener('pointermove', onPointerMove);
6813
6810
  document.addEventListener('pointerup', onPointerUp);
6814
6811
  document.addEventListener('pointercancel', onPointerCancel);
6812
+ /* A view destroyed in the middle of the drag takes them off too
6813
+ * (mt_destroy): they are closures over this gobj, on `document`. */
6814
+ gobj.priv._drag_unwire = function() {
6815
+ document.removeEventListener('pointermove', onPointerMove);
6816
+ document.removeEventListener('pointerup', onPointerUp);
6817
+ document.removeEventListener('pointercancel', onPointerCancel);
6818
+ };
6815
6819
  }
6816
6820
 
6817
6821
  /************************************************************
package/src/c_yui_form.js CHANGED
@@ -47,6 +47,7 @@ import {
47
47
  refresh_language,
48
48
  treedb_decoder_fkey,
49
49
  gclass_find_by_name,
50
+ gobj_is_destroying,
50
51
  } from "@yuneta/gobj-js";
51
52
 
52
53
  import {t} from "i18next";
@@ -90,6 +91,7 @@ import "./tabulator.css";
90
91
  import {is_time_field} from "./json_view_helpers.js";
91
92
  import {date_to_datetime_local, datetime_local_to_epoch} from "./form_time_value.js";
92
93
  import {parse_json_field, json_editor_value} from "./form_json_field.js";
94
+ import {text_node} from "./yui_text.js";
93
95
  import { TabulatorFull as Tabulator } from "tabulator-tables"; // Import Full Tabulator JS
94
96
  // import { Tabulator } from "tabulator-tables"; // Import light Tabulator JS
95
97
 
@@ -159,7 +161,15 @@ SDATA(data_type_t.DTP_BOOLEAN, "changes", 0, false, "Indicates if ch
159
161
  SDATA_END()
160
162
  ];
161
163
 
162
- let PRIVATE_DATA = {};
164
+ let PRIVATE_DATA = {
165
+ /* The deferred re-wiring of the tables' dataChanged after a
166
+ * save/undo (see set_changed_stated): cancelled in destroy_ui. */
167
+ rearm_timer: null,
168
+ /* table_id -> WeakRef of its element: EV_ADD_TABLE_ROW names a
169
+ * table by id (a kw is plain json), see table_identity(). */
170
+ tables: null,
171
+ table_seq: 0,
172
+ };
163
173
 
164
174
  let __gclass__ = null;
165
175
 
@@ -190,6 +200,7 @@ function mt_create(gobj)
190
200
  let name = clean_name(gobj_name(gobj));
191
201
  gobj_write_attr(gobj, "form_id", "form" + name);
192
202
 
203
+ gobj.priv.tables = new Map();
193
204
  build_ui(gobj);
194
205
  }
195
206
 
@@ -253,11 +264,11 @@ function set_changed_stated(gobj, changed)
253
264
  let $form = $container.querySelector('form');
254
265
 
255
266
  /*
256
- * Los dos pueden NO estar: desde que la botonera es configurable
257
- * (`toolbar`), un dialogo de una sola accion pide ["save"] y aqui no
258
- * hay undo que habilitar. Antes se daban por presentes y quitar uno
259
- * reventaba con "can't access property setAttribute, a is null" al
260
- * primer cambio en el formulario.
267
+ * Either of the two may be MISSING: since the toolbar is configurable
268
+ * (`toolbar`), a one-action dialog asks for ["save"] and there is no
269
+ * undo to enable here. They used to be taken for granted, and leaving
270
+ * one out blew up with "can't access property setAttribute, a is null"
271
+ * at the first change in the form.
261
272
  */
262
273
  const enable = ($btn, on, color) => {
263
274
  if(!$btn) {
@@ -288,12 +299,12 @@ function set_changed_stated(gobj, changed)
288
299
  enable($button_undo, true, "Magenta");
289
300
 
290
301
  $form.querySelectorAll('.yui-tabulator-table').forEach($table => {
291
- if(isEventSet($table.tabulator, "dataChanged")) {
302
+ if($table.tabulator && isEventSet($table.tabulator, "dataChanged")) {
292
303
  $table.tabulator.off("dataChanged");
293
304
  }
294
305
 
295
306
  $table.querySelectorAll('.yui-tabulator-table-nested').forEach($table_nested => {
296
- if(isEventSet($table_nested.tabulator, "dataChanged")) {
307
+ if($table_nested.tabulator && isEventSet($table_nested.tabulator, "dataChanged")) {
297
308
  $table_nested.tabulator.off("dataChanged");
298
309
  }
299
310
  });
@@ -308,25 +319,37 @@ function set_changed_stated(gobj, changed)
308
319
  enable($button_save, false, OFF_COLOR);
309
320
  enable($button_undo, false, OFF_COLOR);
310
321
 
311
- // TODO improve
312
- setTimeout(function() {
313
- $form.querySelectorAll('.yui-tabulator-table').forEach($table => {
314
- if(isEventSet($table.tabulator, "dataChanged")) {
315
- $table.tabulator.off("dataChanged");
322
+ /*
323
+ * TODO improve. The tables are re-wired a moment later, once the
324
+ * data just loaded has settled. The timer is kept so that
325
+ * destroy_ui() cancels it: a form closed right after a save (what
326
+ * a dialog does) destroyed its widgets first, and the timer then
327
+ * called .on() on a null tabulator -- an uncaught TypeError.
328
+ */
329
+ if(gobj.priv.rearm_timer) {
330
+ clearTimeout(gobj.priv.rearm_timer);
331
+ }
332
+ gobj.priv.rearm_timer = setTimeout(function() {
333
+ gobj.priv.rearm_timer = null;
334
+ if(gobj_is_destroying(gobj)) {
335
+ return; // destroy_ui() cancels it; this is the belt
336
+ }
337
+ const rearm = (tabulator) => {
338
+ if(!tabulator) {
339
+ return; // destroyed with its form
340
+ }
341
+ if(isEventSet(tabulator, "dataChanged")) {
342
+ tabulator.off("dataChanged");
316
343
  }
317
- $table.tabulator.on("dataChanged", function(data) {
344
+ tabulator.on("dataChanged", function(data) {
318
345
  //data - the updated table data
319
346
  gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
320
347
  });
321
-
348
+ };
349
+ $form.querySelectorAll('.yui-tabulator-table').forEach($table => {
350
+ rearm($table.tabulator);
322
351
  $table.querySelectorAll('.yui-tabulator-table-nested').forEach($table_nested => {
323
- if(isEventSet($table_nested.tabulator, "dataChanged")) {
324
- $table_nested.tabulator.off("dataChanged");
325
- }
326
- $table_nested.tabulator.on("dataChanged", function(data) {
327
- //data - the updated table data
328
- gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
329
- });
352
+ rearm($table_nested.tabulator);
330
353
  });
331
354
  });
332
355
  }, 200);
@@ -491,6 +514,10 @@ function build_ui(gobj)
491
514
  ************************************************************/
492
515
  function destroy_ui(gobj)
493
516
  {
517
+ if(gobj.priv && gobj.priv.rearm_timer) {
518
+ clearTimeout(gobj.priv.rearm_timer);
519
+ gobj.priv.rearm_timer = null;
520
+ }
494
521
  let $container = gobj_read_attr(gobj, "$container");
495
522
  if($container) {
496
523
  destroy_widgets(gobj, $container);
@@ -509,13 +536,62 @@ function destroy_ui(gobj)
509
536
  ************************************************************/
510
537
  function cell_icon(icon_class, key)
511
538
  {
539
+ /* A control, not a picture: role, focus and the keys of a button. A
540
+ * key press clicks it, so it reaches the same Tabulator cellClick as
541
+ * the pointer. */
512
542
  let $i = document.createElement('i');
513
543
  $i.className = icon_class;
544
+ $i.setAttribute('role', 'button');
545
+ $i.setAttribute('tabindex', '0');
514
546
  $i.setAttribute('title', t(key));
547
+ $i.setAttribute('data-i18n-title', key);
515
548
  $i.setAttribute('aria-label', t(key));
549
+ $i.setAttribute('data-i18n-aria-label', key);
550
+ $i.addEventListener('keydown', function(evt) {
551
+ if(evt.key === 'Enter' || evt.key === ' ') {
552
+ evt.preventDefault();
553
+ $i.click();
554
+ }
555
+ });
516
556
  return $i;
517
557
  }
518
558
 
559
+ /************************************************************
560
+ * The identity of a table element, for the kw of
561
+ * EV_ADD_TABLE_ROW: a kw is plain json, and an element (with its
562
+ * `.tabulator`, circular) broke the `machine` trace that dumps it.
563
+ * Given on first use and kept on the element; the registry holds
564
+ * it weakly, so a nested table re-built by its row formatter is
565
+ * not kept alive by it.
566
+ ************************************************************/
567
+ function table_identity(gobj, $table)
568
+ {
569
+ if(!$table.yui_table_id) {
570
+ let priv = gobj.priv;
571
+ priv.table_seq += 1;
572
+ $table.yui_table_id = `t${priv.table_seq}`;
573
+ priv.tables.set($table.yui_table_id, new WeakRef($table));
574
+ }
575
+ return $table.yui_table_id;
576
+ }
577
+
578
+ /************************************************************
579
+ * The element of a table identity, or null when it is gone.
580
+ ************************************************************/
581
+ function find_table(gobj, table_id)
582
+ {
583
+ let priv = gobj.priv;
584
+ let ref = priv.tables? priv.tables.get(table_id) : null;
585
+ let $table = ref? ref.deref() : null;
586
+ if(!$table) {
587
+ if(priv.tables) {
588
+ priv.tables.delete(table_id);
589
+ }
590
+ return null;
591
+ }
592
+ return $table;
593
+ }
594
+
519
595
  /************************************************************
520
596
  * Destroy the third-party widgets the form built. Removing
521
597
  * their DOM is not enough: Tom Select keeps listeners on
@@ -528,7 +604,14 @@ function destroy_widgets(gobj, $container)
528
604
  {
529
605
  let destroy = (what, widget) => {
530
606
  try {
531
- widget.destroy();
607
+ /* vanilla-jsoneditor 3 destroys asynchronously: its failure
608
+ * is a rejected promise, which no try/catch sees. */
609
+ let r = widget.destroy();
610
+ if(r && typeof r.then === "function") {
611
+ r.catch((e) => {
612
+ log_warning(`${gobj_short_name(gobj)}: cannot destroy ${what}: ${e}`);
613
+ });
614
+ }
532
615
  } catch(e) {
533
616
  log_warning(`${gobj_short_name(gobj)}: cannot destroy ${what}: ${e}`);
534
617
  }
@@ -599,6 +682,19 @@ function name_form_control($field, conf)
599
682
  $ts.setAttribute("aria-label", t(key));
600
683
  $ts.setAttribute("data-i18n-aria-label", key);
601
684
  }
685
+
686
+ /* The ✕ of the clear_button plugin is drawn by Tom Select too, with a
687
+ * title written once with t() and no key: named here, after the
688
+ * render, with its key, so it re-translates. */
689
+ let $clear = $field.querySelector(".ts-wrapper .clear-button");
690
+ if($clear) {
691
+ const CLEAR_KEY = "remove all selected options";
692
+ $clear.setAttribute("role", "button");
693
+ $clear.setAttribute("title", t(CLEAR_KEY));
694
+ $clear.setAttribute("data-i18n-title", CLEAR_KEY);
695
+ $clear.setAttribute("aria-label", t(CLEAR_KEY));
696
+ $clear.setAttribute("data-i18n-aria-label", CLEAR_KEY);
697
+ }
602
698
  }
603
699
 
604
700
  function build_form(gobj)
@@ -1161,12 +1257,7 @@ function create_form_field(
1161
1257
  *
1162
1258
  *--------------------------------------*/
1163
1259
  let $element;
1164
- let kw_add_table_row = {
1165
- $row: null, // not null if it's a nested table
1166
- $table: null, // Element of tabulator
1167
- record: {},
1168
- loading: false,
1169
- };
1260
+ let $add_table = null; // the table the field's "add" button adds a row to
1170
1261
 
1171
1262
  switch (tag) {
1172
1263
  case 'input':
@@ -1175,7 +1266,7 @@ function create_form_field(
1175
1266
  $element = createElement2(
1176
1267
  ['div', {class: 'xfield field is-horizontal'}, [
1177
1268
  ['div', {class: 'field-label is-normal' }, [
1178
- ["label", {class:"label ", i18n:(label_i18n||label), for:name}, label]
1269
+ ["label", {class:"label ", i18n:(label_i18n||label), for:name}, text_node(label)]
1179
1270
  ]],
1180
1271
 
1181
1272
  ['div', {class: 'field-body'}, [
@@ -1192,7 +1283,7 @@ function create_form_field(
1192
1283
  $element = createElement2(
1193
1284
  ['div', {class: 'xfield field is-horizontal'}, [
1194
1285
  ['div', {class: 'field-label is-normal' }, [
1195
- ["label", {class:"label ", i18n:(label_i18n||label), for:name}, label]
1286
+ ["label", {class:"label ", i18n:(label_i18n||label), for:name}, text_node(label)]
1196
1287
  ]],
1197
1288
 
1198
1289
  ['div', {class: 'field-body'}, [
@@ -1215,7 +1306,7 @@ function create_form_field(
1215
1306
  $element = createElement2(
1216
1307
  ['div', {class: 'xfield field is-horizontal'}, [
1217
1308
  ['div', {class: 'field-label is-normal' }, [
1218
- ["label", {class:"label ", i18n:(label_i18n||label), for:name}, label]
1309
+ ["label", {class:"label ", i18n:(label_i18n||label), for:name}, text_node(label)]
1219
1310
  ]],
1220
1311
 
1221
1312
  ['div', {class: 'field-body'}, [
@@ -1231,7 +1322,7 @@ function create_form_field(
1231
1322
  $element = createElement2(
1232
1323
  ['div', {class: 'xfield field is-horizontal'}, [
1233
1324
  ['div', {class: 'field-label is-normal' }, [
1234
- ["label", {class:"label ", i18n:(label_i18n||label), for:name}, label]
1325
+ ["label", {class:"label ", i18n:(label_i18n||label), for:name}, text_node(label)]
1235
1326
  ]],
1236
1327
 
1237
1328
  ['div', {class: 'field-body'}, [
@@ -1250,7 +1341,7 @@ function create_form_field(
1250
1341
  $element = createElement2(
1251
1342
  ['div', {class: 'field is-horizontal tabulator-buttons'}, [
1252
1343
  ['div', {class: 'field-label is-normal' }, [
1253
- ['label', {class:'label', i18n:(label_i18n||label)}, label]
1344
+ ['label', {class:'label', i18n:(label_i18n||label)}, text_node(label)]
1254
1345
  ]],
1255
1346
 
1256
1347
  ['div', {class: 'field-body'}, [
@@ -1265,8 +1356,18 @@ function create_form_field(
1265
1356
  click: function(evt) {
1266
1357
  evt.stopPropagation();
1267
1358
  evt.preventDefault();
1359
+ if(!$add_table) {
1360
+ log_error(`${gobj_short_name(gobj)}: "add" of a field without a table`);
1361
+ return;
1362
+ }
1268
1363
  gobj_send_event(gobj,
1269
- "EV_ADD_TABLE_ROW", kw_add_table_row, gobj
1364
+ "EV_ADD_TABLE_ROW",
1365
+ {
1366
+ table_id: table_identity(gobj, $add_table),
1367
+ record: {},
1368
+ loading: false,
1369
+ },
1370
+ gobj
1270
1371
  );
1271
1372
  }
1272
1373
  }]
@@ -1295,7 +1396,7 @@ function create_form_field(
1295
1396
  $element = createElement2(
1296
1397
  ['div', {class: 'xfield field is-horizontal'}, [
1297
1398
  ['div', {class: 'field-label is-normal' }, [
1298
- ["label", {class:"label ", i18n:(label_i18n||label), for:name}, label]
1399
+ ["label", {class:"label ", i18n:(label_i18n||label), for:name}, text_node(label)]
1299
1400
  ]],
1300
1401
 
1301
1402
  ['div', {class: 'field-body'}, [
@@ -1415,7 +1516,7 @@ function create_form_field(
1415
1516
  },
1416
1517
  opts.map(option =>
1417
1518
  ['option', {value:option, i18n:option},
1418
- document.createTextNode(String(option))] // data, not markup
1519
+ text_node(option)] // data, not markup
1419
1520
  ),
1420
1521
  {
1421
1522
  'change': function (evt) {
@@ -1457,8 +1558,8 @@ function create_form_field(
1457
1558
  multiple: true,
1458
1559
  },
1459
1560
  opts.map(option => is_icon
1460
- ? ['option', {value:option}, option]
1461
- : ['option', {value:option, i18n:option}, option]
1561
+ ? ['option', {value:option}, text_node(option)]
1562
+ : ['option', {value:option, i18n:option}, text_node(option)]
1462
1563
  )
1463
1564
  ];
1464
1565
  $extend = createElement2(extend);
@@ -1517,7 +1618,7 @@ function create_form_field(
1517
1618
  $extend = createElement2(
1518
1619
  ['label', {class: 'radio'}, [
1519
1620
  ['input', {type: 'radio', name: name}],
1520
- ['span', {i18n: label_key}, label_key]
1621
+ ['span', {i18n: label_key}, text_node(label_key)]
1521
1622
  ]]
1522
1623
  );
1523
1624
  $control.appendChild($extend);
@@ -1595,7 +1696,7 @@ function create_form_field(
1595
1696
  $extend = createElement2(extend);
1596
1697
  $control.appendChild($extend);
1597
1698
  $extend.tabulator = create_tabulator(gobj, $extend, name, options);
1598
- kw_add_table_row["$table"] = $extend;
1699
+ $add_table = $extend;
1599
1700
  break;
1600
1701
  }
1601
1702
 
@@ -2131,7 +2232,7 @@ function template2columns(gobj, columns, template, sub_elements)
2131
2232
  switch(field_desc.type) {
2132
2233
  case "object":
2133
2234
  case "dict":
2134
- // TODO es otro formulario, pongo un button y que abra un popup?
2235
+ // TODO it is another form: a button that opens it in a popup?
2135
2236
  // Object.entries(value).forEach(([key, value]) => {
2136
2237
  // build_html_form_field_conf_from_template(gobj, $form, key, value);
2137
2238
  // });
@@ -2173,11 +2274,14 @@ function template2columns(gobj, columns, template, sub_elements)
2173
2274
  evt.stopPropagation();
2174
2275
  let $row = cell.getRow().getElement();
2175
2276
  let $extend = $row.querySelector(`[name="${field_desc.name}"]`);
2277
+ if(!$extend) {
2278
+ log_error(`${gobj_short_name(gobj)}: nested table '${field_desc.name}' not found in its row`);
2279
+ return;
2280
+ }
2176
2281
  gobj_send_event(gobj,
2177
2282
  "EV_ADD_TABLE_ROW",
2178
2283
  {
2179
- $row: $row, // not null if it's a nested table
2180
- $table: $extend, // Element of tabulator
2284
+ table_id: table_identity(gobj, $extend),
2181
2285
  record: {},
2182
2286
  loading: false,
2183
2287
  },
@@ -2408,15 +2512,29 @@ function template2columns(gobj, columns, template, sub_elements)
2408
2512
  * out-of-range number is more precise than anything generic here.
2409
2513
  ************************************************************/
2410
2514
  function field_validation_message($input)
2515
+ {
2516
+ let key = field_validation_key($input);
2517
+ if(key) {
2518
+ return t(key);
2519
+ }
2520
+ return $input.validationMessage;
2521
+ }
2522
+
2523
+ /************************************************************
2524
+ * The i18n key of the message, when the message is ours ("" when
2525
+ * it is the browser's): written as the help line's data-i18n, so
2526
+ * a language change re-translates the line on screen.
2527
+ ************************************************************/
2528
+ function field_validation_key($input)
2411
2529
  {
2412
2530
  if($input.yui_json_error) {
2413
- return t($input.yui_json_error);
2531
+ return $input.yui_json_error;
2414
2532
  }
2415
2533
  let v = $input.validity;
2416
2534
  if(v && v.valueMissing) {
2417
- return t("this field is required");
2535
+ return "this field is required";
2418
2536
  }
2419
- return $input.validationMessage;
2537
+ return "";
2420
2538
  }
2421
2539
 
2422
2540
  /************************************************************
@@ -2442,6 +2560,7 @@ function mark_field_validity($input)
2442
2560
  $input.classList.remove('is-danger');
2443
2561
  if($h) {
2444
2562
  $h.textContent = '';
2563
+ $h.removeAttribute('data-i18n');
2445
2564
  $h.style.display = 'none';
2446
2565
  }
2447
2566
  return true;
@@ -2449,6 +2568,12 @@ function mark_field_validity($input)
2449
2568
 
2450
2569
  $input.classList.add('is-danger');
2451
2570
  if($h) {
2571
+ let key = field_validation_key($input);
2572
+ if(key) {
2573
+ $h.setAttribute('data-i18n', key);
2574
+ } else {
2575
+ $h.removeAttribute('data-i18n'); // the browser's own sentence
2576
+ }
2452
2577
  $h.textContent = field_validation_message($input);
2453
2578
  $h.style.display = 'block';
2454
2579
  }
@@ -2920,8 +3045,7 @@ function load_tabulator_data(gobj, $table, value)
2920
3045
  gobj_send_event(gobj,
2921
3046
  "EV_ADD_TABLE_ROW",
2922
3047
  {
2923
- $row: null, // not null if it's a nested table
2924
- $table: $table, // Element of tabulator
3048
+ table_id: table_identity(gobj, $table),
2925
3049
  record: row,
2926
3050
  loading: true,
2927
3051
  },
@@ -2934,8 +3058,7 @@ function load_tabulator_data(gobj, $table, value)
2934
3058
  gobj_send_event(gobj,
2935
3059
  "EV_ADD_TABLE_ROW",
2936
3060
  {
2937
- $row: null, // not null if it's a nested table
2938
- $table: $table, // Element of tabulator
3061
+ table_id: table_identity(gobj, $table),
2939
3062
  record: row,
2940
3063
  loading: true,
2941
3064
  },
@@ -3098,13 +3221,16 @@ function treedb_value_2_form_value(gobj, field_desc, value)
3098
3221
  /************************************************************
3099
3222
  * A json field's value, parsed. validate_form() refuses a field
3100
3223
  * that does not parse, so reaching the error here is a path that
3101
- * skipped it: logged, never quiet.
3224
+ * skipped it: logged, and the value is handed on AS IT IS. An
3225
+ * empty `{}` / `[]` in its place is a value nobody wrote, and
3226
+ * saved it wipes the column.
3102
3227
  ************************************************************/
3103
3228
  function parse_json_value(gobj, field_desc, value)
3104
3229
  {
3105
3230
  let r = parse_json_field(value, field_desc.type);
3106
3231
  if(r.error) {
3107
- log_error(`${gobj_short_name(gobj)}: field '${field_desc.name}' (${field_desc.type}) holds no valid json, stored as empty`);
3232
+ log_error(`${gobj_short_name(gobj)}: field '${field_desc.name}' (${field_desc.type}) holds no valid json, handed on as it is`);
3233
+ return value;
3108
3234
  }
3109
3235
  return r.value;
3110
3236
  }
@@ -3197,6 +3323,9 @@ function form_value_2_treedb_value(gobj, field_desc, value)
3197
3323
  break;
3198
3324
  case "object":
3199
3325
  case "dict":
3326
+ /* Parsed like a list: it went out as the editor's TEXT, and a
3327
+ * backend that reads a bad text stores {} without a word. */
3328
+ value = parse_json_value(gobj, field_desc, value);
3200
3329
  break;
3201
3330
  case "array":
3202
3331
  case "list":
@@ -3400,9 +3529,13 @@ function ac_set_file_preview(gobj, event, kw, src)
3400
3529
  ************************************************************/
3401
3530
  function ac_add_table_row(gobj, event, kw, src)
3402
3531
  {
3403
- let $row = kw["$row"]; // not null if it's a nested table in this row
3404
- let $table = kw.$table; // Element of tabulator
3405
- let tabulator = $table.tabulator;
3532
+ let table_id = kw.table_id;
3533
+ let $table = find_table(gobj, table_id);
3534
+ let tabulator = $table? $table.tabulator : null;
3535
+ if(!tabulator) {
3536
+ log_error(`${gobj_short_name(gobj)}: EV_ADD_TABLE_ROW to a table that is gone: '${table_id}'`);
3537
+ return -1;
3538
+ }
3406
3539
  let record = kw.record;
3407
3540
  let loading = kw.loading;
3408
3541
 
@@ -3432,13 +3565,14 @@ function ac_add_table_row(gobj, event, kw, src)
3432
3565
 
3433
3566
  // TODO improve, to use only once the timeout?
3434
3567
  setTimeout(function() {
3435
- if($row) {
3436
- let $tabulator = $row.closest('.yui-tabulator-table');
3437
- if($tabulator && $tabulator.tabulator) {
3438
- $tabulator.tabulator.redraw(); /* Delete double scrollbar */
3439
- }
3440
- } else {
3441
- tabulator.redraw(); /* Delete double scrollbar */
3568
+ if(gobj_is_destroying(gobj)) {
3569
+ return; // the form went in the meantime: nothing to redraw
3570
+ }
3571
+ /* The table itself, or -- for a nested one -- the table of the
3572
+ * row it lives in. Re-checked: it may be destroyed by now. */
3573
+ let $outer = $table.closest('.yui-tabulator-table');
3574
+ if($outer && $outer.tabulator) {
3575
+ $outer.tabulator.redraw(); /* Delete double scrollbar */
3442
3576
  }
3443
3577
  }, 30);
3444
3578