@yuneta/gobj-ui 7.26.5 → 7.26.7

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/src/c_yui_form.js CHANGED
@@ -73,6 +73,11 @@ import {field_is_readonly} from "./form_field_readonly.js";
73
73
  * dialog rebuilds the form on every open, and re-rendering a form under
74
74
  * the user mid-edit would throw away what they typed. */
75
75
  import {yui_is_dark} from "./yui_theme.js";
76
+ import {
77
+ yui_icons_list,
78
+ yui_icons_is_svg_field,
79
+ yui_svg_icon_element
80
+ } from "./lib_icons.js";
76
81
  /* ORDER MATTERS, and it is this way round: `tabulator.css` is OUR sheet of
77
82
  * fixes ON TOP of Tabulator's theme, and at equal specificity the cascade is
78
83
  * decided by which one the bundle emits last. Imported before the theme (as
@@ -84,6 +89,7 @@ import "tabulator-tables/dist/css/tabulator_bulma.css";
84
89
  import "./tabulator.css";
85
90
  import {is_time_field} from "./json_view_helpers.js";
86
91
  import {date_to_datetime_local, datetime_local_to_epoch} from "./form_time_value.js";
92
+ import {parse_json_field, json_editor_value} from "./form_json_field.js";
87
93
  import { TabulatorFull as Tabulator } from "tabulator-tables"; // Import Full Tabulator JS
88
94
  // import { Tabulator } from "tabulator-tables"; // Import light Tabulator JS
89
95
 
@@ -487,6 +493,7 @@ function destroy_ui(gobj)
487
493
  {
488
494
  let $container = gobj_read_attr(gobj, "$container");
489
495
  if($container) {
496
+ destroy_widgets(gobj, $container);
490
497
  if($container.parentNode) {
491
498
  $container.parentNode.removeChild($container);
492
499
  }
@@ -494,6 +501,60 @@ function destroy_ui(gobj)
494
501
  }
495
502
  }
496
503
 
504
+ /************************************************************
505
+ * The icon a table cell draws as its control (delete the row,
506
+ * add a nested row): an element, so it carries its name. Drawn
507
+ * by Tabulator on every render, so t() at render time is
508
+ * current.
509
+ ************************************************************/
510
+ function cell_icon(icon_class, key)
511
+ {
512
+ let $i = document.createElement('i');
513
+ $i.className = icon_class;
514
+ $i.setAttribute('title', t(key));
515
+ $i.setAttribute('aria-label', t(key));
516
+ return $i;
517
+ }
518
+
519
+ /************************************************************
520
+ * Destroy the third-party widgets the form built. Removing
521
+ * their DOM is not enough: Tom Select keeps listeners on
522
+ * `document` and `window`, the jsoneditor is a live Svelte app
523
+ * and a Tabulator keeps its observers -- each one a closure over
524
+ * this form, alive for the life of the page. Nested tables go
525
+ * first: their parent's destroy drops the rows they hang from.
526
+ ************************************************************/
527
+ function destroy_widgets(gobj, $container)
528
+ {
529
+ let destroy = (what, widget) => {
530
+ try {
531
+ widget.destroy();
532
+ } catch(e) {
533
+ log_warning(`${gobj_short_name(gobj)}: cannot destroy ${what}: ${e}`);
534
+ }
535
+ };
536
+ $container.querySelectorAll('.yui-tabulator-table-nested').forEach(($el) => {
537
+ if($el.tabulator) {
538
+ destroy("nested table", $el.tabulator);
539
+ $el.tabulator = null;
540
+ }
541
+ });
542
+ $container.querySelectorAll('.yui-form-data-input').forEach(($el) => {
543
+ if($el.tom_select) {
544
+ destroy("select", $el.tom_select);
545
+ $el.tom_select = null;
546
+ }
547
+ if($el.jsoneditor) {
548
+ destroy("json editor", $el.jsoneditor);
549
+ $el.jsoneditor = null;
550
+ }
551
+ if($el.tabulator) {
552
+ destroy("table", $el.tabulator);
553
+ $el.tabulator = null;
554
+ }
555
+ });
556
+ }
557
+
497
558
  /******************************************************************
498
559
  * Build form with bulma and createElement2
499
560
  ******************************************************************/
@@ -579,6 +640,12 @@ function build_html_form(gobj, $form, prefix, template)
579
640
  {
580
641
  Object.entries(template).forEach(([key, value]) => {
581
642
  const field_desc = template_get_field_desc(key, value);
643
+ /* The drawing of a user icon (`svg` of __icons__): a text area
644
+ * with the icon it draws below it. */
645
+ if(!prefix && yui_icons_is_svg_field(
646
+ gobj_read_str_attr(gobj, "topic_name"), field_desc.name)) {
647
+ field_desc.type = "svg";
648
+ }
582
649
  let html_field_conf = build_form_field_conf(gobj, field_desc);
583
650
 
584
651
  /*
@@ -740,8 +807,21 @@ function build_form_field_conf(gobj, field_desc)
740
807
  field_conf.tag = "file";
741
808
  break;
742
809
 
743
- case "image":
810
+ /* The NAME of an icon, chosen from the icons there are -- each
811
+ * drawn beside its name -- and not typed from memory. */
744
812
  case "icon":
813
+ field_conf.tag = "select2";
814
+ field_conf.options = yui_icons_list().map(icon => icon.name);
815
+ break;
816
+
817
+ case "svg":
818
+ field_conf.tag = "textarea";
819
+ field_conf.extras.rows = 6;
820
+ field_conf.extras.spellcheck = "false";
821
+ field_conf.extras.class = "textarea is-family-monospace";
822
+ break;
823
+
824
+ case "image":
745
825
  case "string":
746
826
  field_conf.tag = 'input';
747
827
  field_conf.inputType = 'text';
@@ -1176,7 +1256,9 @@ function create_form_field(
1176
1256
  ['div', {class: 'field-body'}, [
1177
1257
  ['div', {class: 'field'}, [
1178
1258
  ['div', {class: '' }, [
1179
- ['button', {class: 'button p-1'}, [
1259
+ ['button', {class: 'button p-1',
1260
+ title: t('add'), 'data-i18n-title': 'add',
1261
+ 'aria-label': t('add'), 'data-i18n-aria-label': 'add'}, [
1180
1262
  ['span', {class: 'icon m-0'}, '<i class="yi-plus"></i>'],
1181
1263
  ['span', {class: 'p-1 pr-2 is-hidden-mobile', i18n: 'add'}, 'add'],
1182
1264
  ], {
@@ -1308,6 +1390,9 @@ function create_form_field(
1308
1390
  let extend = ['textarea', attrs];
1309
1391
  $extend = createElement2(extend);
1310
1392
  $control.appendChild($extend);
1393
+ if(field_desc.type === "svg") {
1394
+ attach_svg_preview(gobj, $control, $extend);
1395
+ }
1311
1396
  break;
1312
1397
  }
1313
1398
 
@@ -1329,7 +1414,8 @@ function create_form_field(
1329
1414
  name: name
1330
1415
  },
1331
1416
  opts.map(option =>
1332
- ['option', {value:option, i18n:option}, option]
1417
+ ['option', {value:option, i18n:option},
1418
+ document.createTextNode(String(option))] // data, not markup
1333
1419
  ),
1334
1420
  {
1335
1421
  'change': function (evt) {
@@ -1362,14 +1448,17 @@ function create_form_field(
1362
1448
  ));
1363
1449
  opts = [];
1364
1450
  }
1451
+ /* An icon name is not text to translate: it is a class. */
1452
+ let is_icon = (field_desc.type === "icon");
1365
1453
  let extend = ["select",
1366
1454
  {
1367
1455
  name: name,
1368
1456
  class: '',
1369
1457
  multiple: true,
1370
1458
  },
1371
- opts.map(option =>
1372
- ['option', {value:option, i18n:option}, option]
1459
+ opts.map(option => is_icon
1460
+ ? ['option', {value:option}, option]
1461
+ : ['option', {value:option, i18n:option}, option]
1373
1462
  )
1374
1463
  ];
1375
1464
  $extend = createElement2(extend);
@@ -1377,9 +1466,11 @@ function create_form_field(
1377
1466
  $extend.tom_select = new TomSelect($extend, {
1378
1467
  allowEmptyOption: true,
1379
1468
  placeholder: placeholder,
1380
- /* single-valued fkey (real_type string): one selection only */
1381
- maxItems: (field_desc.type === "fkey" &&
1382
- field_desc.real_type === "string")? 1 : null,
1469
+ /* single-valued fkey (real_type string): one selection only.
1470
+ * An icon column holds one name. */
1471
+ maxItems: (is_icon || (field_desc.type === "fkey" &&
1472
+ field_desc.real_type === "string"))? 1 : null,
1473
+ render: is_icon? icon_select_render() : undefined,
1383
1474
  plugins: {
1384
1475
  'clear_button': {
1385
1476
  /* i18n keys are lower-case by convention (the apps'
@@ -1418,19 +1509,18 @@ function create_form_field(
1418
1509
 
1419
1510
  case 'radio':
1420
1511
  {
1421
- // TODO review, not tested
1422
- // for(const option of options) {
1423
- // // WARNING here can't use data-i18n, the radio element is destroyed.
1424
- let elm = `
1425
- <label class="radio">
1426
- <input type="radio" name="${name}">
1427
- ${t(options)}
1428
- </label>
1429
- `;
1430
-
1431
- $extend = createOneHtml(elm);
1432
- $control.appendChild($extend);
1433
- // }
1512
+ // TODO review, not tested: one radio, labelled by `options`
1513
+ /* Built as nodes: the name and the label are data, and the
1514
+ * label keeps its key so it re-translates. The <label> WRAPS
1515
+ * its control, which is what names it. */
1516
+ let label_key = String(options === undefined || options === null ? "" : options);
1517
+ $extend = createElement2(
1518
+ ['label', {class: 'radio'}, [
1519
+ ['input', {type: 'radio', name: name}],
1520
+ ['span', {i18n: label_key}, label_key]
1521
+ ]]
1522
+ );
1523
+ $control.appendChild($extend);
1434
1524
  break;
1435
1525
  }
1436
1526
 
@@ -1456,12 +1546,18 @@ function create_form_field(
1456
1546
  props: {
1457
1547
  readOnly: !!readonly,
1458
1548
  onChange: function() {
1549
+ /* A field marked wrong clears its mark as soon as
1550
+ * it holds good json again. */
1551
+ if($extend.yui_json_error) {
1552
+ check_json_editor($extend);
1553
+ mark_field_validity($extend);
1554
+ }
1459
1555
  gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
1460
1556
  },
1461
- /* La lista vive en json_view_helpers.js: el visor de
1462
- * JSON y este editor tienen que reconocer los MISMOS
1463
- * campos, y tener cada uno su copia es como dejaron de
1464
- * hacerlo. */
1557
+ /* The list lives in json_view_helpers.js: the JSON
1558
+ * viewer and this editor must recognise the SAME
1559
+ * fields, and a copy each is how they stopped
1560
+ * doing so. */
1465
1561
  timestampTag: function({field, value, path}) {
1466
1562
  return is_time_field(field);
1467
1563
  },
@@ -1598,6 +1694,92 @@ function attach_color_value($control, $input)
1598
1694
  $control.appendChild($value);
1599
1695
  }
1600
1696
 
1697
+ /******************************************************************
1698
+ * How the icon picker draws a name: the icon, then the name.
1699
+ * The names come from yui_icons_list() -- class names, already
1700
+ * [a-z0-9-] -- and are escaped anyway, because they are written
1701
+ * as markup.
1702
+ ******************************************************************/
1703
+ function icon_select_render()
1704
+ {
1705
+ function draw(data, escape) {
1706
+ let name = escape(data.value);
1707
+ return `<div class="ICON_SELECT_ITEM"><span class="icon"><i class="${name}" aria-hidden="true"></i></span><span>${escape(data.text)}</span></div>`;
1708
+ }
1709
+ return {
1710
+ option: draw,
1711
+ item: draw
1712
+ };
1713
+ }
1714
+
1715
+ /******************************************************************
1716
+ * Why a drawing cannot be an icon, in the reader's language.
1717
+ * The causes are the fixed set yui_svg_sanitize() answers, each
1718
+ * written here as a literal t() so validate-locales sees it.
1719
+ ******************************************************************/
1720
+ function svg_error_text(error)
1721
+ {
1722
+ switch(error) {
1723
+ case "empty svg":
1724
+ return t("empty svg");
1725
+ case "svg too big":
1726
+ return t("svg too big");
1727
+ case "not an svg document":
1728
+ return t("not an svg document");
1729
+ case "svg without size":
1730
+ return t("svg without size");
1731
+ case "svg without shapes":
1732
+ return t("svg without shapes");
1733
+ default:
1734
+ log_error(`svg_error_text(): unknown cause '${error}'`);
1735
+ return error;
1736
+ }
1737
+ }
1738
+
1739
+ /******************************************************************
1740
+ * The icon a drawing (`svg` of __icons__) makes, below its text
1741
+ * area, redrawn as it is typed: what is saved is what the app
1742
+ * will show. A drawing that cannot be drawn says why, and what
1743
+ * the sanitizer left out is named.
1744
+ ******************************************************************/
1745
+ function attach_svg_preview(gobj, $control, $textarea)
1746
+ {
1747
+ let $preview = createElement2(
1748
+ ['div', {class: 'SVG_PREVIEW is-flex is-align-items-center mt-2'}, [
1749
+ ['span', {class: 'SVG_PREVIEW_ICON icon is-large is-size-3'}],
1750
+ ['span', {class: 'SVG_PREVIEW_NOTE is-size-7 yui-text-quiet ml-2'}]
1751
+ ]]
1752
+ );
1753
+ $control.appendChild($preview);
1754
+ let $icon = $preview.querySelector('.SVG_PREVIEW_ICON');
1755
+ let $note = $preview.querySelector('.SVG_PREVIEW_NOTE');
1756
+
1757
+ function redraw() {
1758
+ $icon.replaceChildren();
1759
+ $note.textContent = "";
1760
+ if(!$textarea.value || !$textarea.value.trim()) {
1761
+ return;
1762
+ }
1763
+ let preview = yui_svg_icon_element($textarea.value);
1764
+ if(preview.error) {
1765
+ $note.textContent = svg_error_text(preview.error);
1766
+ return;
1767
+ }
1768
+ $icon.appendChild(preview.element);
1769
+ if(preview.dropped && preview.dropped.length > 0) {
1770
+ /* What the sanitizer left out is named as the svg names it
1771
+ * (`script`, `@onclick`): it is the reader's own markup. */
1772
+ $note.textContent = `${t("left out")}: ${preview.dropped.join(" ")}`;
1773
+ }
1774
+ }
1775
+
1776
+ $textarea.yui_svg_preview = redraw;
1777
+ $textarea.addEventListener('input', function() {
1778
+ redraw();
1779
+ gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
1780
+ });
1781
+ }
1782
+
1601
1783
  /******************************************************************
1602
1784
  * `readonly` is an attribute of a TEXT control and of nothing else.
1603
1785
  *
@@ -1833,7 +2015,7 @@ function create_tabulator(gobj, $extend, name, template)
1833
2015
  columns.push(
1834
2016
  {
1835
2017
  formatter: function(cell, formatterParams) {
1836
- return '<i style="" class="yi-trash has-text-danger"></i>';
2018
+ return cell_icon('yi-trash has-text-danger', 'delete');
1837
2019
  },
1838
2020
  width:40,
1839
2021
  hozAlign:"center",
@@ -1944,7 +2126,7 @@ function template2columns(gobj, columns, template, sub_elements)
1944
2126
  validator.push("required");
1945
2127
  }
1946
2128
 
1947
- // TODO añade los validator necesarios, como validator.push("integer");
2129
+ // TODO add the validators needed, like validator.push("integer");
1948
2130
 
1949
2131
  switch(field_desc.type) {
1950
2132
  case "object":
@@ -1957,7 +2139,7 @@ function template2columns(gobj, columns, template, sub_elements)
1957
2139
 
1958
2140
  case "template":
1959
2141
  // field_conf.tag = "fieldset";
1960
- // TODO si es para editar, tiene que ser field_conf.tag = "jsoneditor";
2142
+ // TODO when editing, it must be field_conf.tag = "jsoneditor";
1961
2143
  break;
1962
2144
 
1963
2145
  case "blob":
@@ -1973,8 +2155,8 @@ function template2columns(gobj, columns, template, sub_elements)
1973
2155
  // field_conf.tag = "table";
1974
2156
  // field_conf.options = enum_list;
1975
2157
  // column.editor = "false";
1976
- // TODO es otra tabla, poner buttons:
1977
- // TODO - para mostrar/ocultar la segunda tabla
2158
+ // TODO it is another table: give it buttons
2159
+ // TODO - to show/hide the second table
1978
2160
 
1979
2161
  let template = field_desc.enum_list;
1980
2162
  sub_elements.push({
@@ -1984,7 +2166,7 @@ function template2columns(gobj, columns, template, sub_elements)
1984
2166
 
1985
2167
  Object.assign(column, {
1986
2168
  formatter: function(cell, formatterParams) {
1987
- return '<i style="" class="yi-plus has-text-link"></i>';
2169
+ return cell_icon('yi-plus has-text-link', 'add');
1988
2170
  },
1989
2171
  hozAlign:"center",
1990
2172
  cellClick: function(evt, cell) {
@@ -2227,6 +2409,9 @@ function template2columns(gobj, columns, template, sub_elements)
2227
2409
  ************************************************************/
2228
2410
  function field_validation_message($input)
2229
2411
  {
2412
+ if($input.yui_json_error) {
2413
+ return t($input.yui_json_error);
2414
+ }
2230
2415
  let v = $input.validity;
2231
2416
  if(v && v.valueMissing) {
2232
2417
  return t("this field is required");
@@ -2251,7 +2436,7 @@ function mark_field_validity($input)
2251
2436
  * field. Reading `validity` asks the same question and fires nothing.
2252
2437
  * A control with no `validity` (a wrapper div) is not invalid. */
2253
2438
  let v = $input.validity;
2254
- let ok = !v || v.valid;
2439
+ let ok = (!v || v.valid) && !$input.yui_json_error;
2255
2440
 
2256
2441
  if(ok) {
2257
2442
  $input.classList.remove('is-danger');
@@ -2281,6 +2466,16 @@ function validate_form(gobj, $form)
2281
2466
  validated = false;
2282
2467
  }
2283
2468
 
2469
+ /* checkValidity() does not see a jsoneditor: it is no form control.
2470
+ * A text that is not json -- or not the column's shape -- used to be
2471
+ * saved as {} or []. */
2472
+ $form.querySelectorAll('.jsoneditor.yui-form-data-input').forEach($editor => {
2473
+ if(!check_json_editor($editor)) {
2474
+ validated = false;
2475
+ mark_field_validity($editor);
2476
+ }
2477
+ });
2478
+
2284
2479
  $form.querySelectorAll('.yui-tabulator-table').forEach($table => {
2285
2480
  if(!$table.tabulator.validate()) {
2286
2481
  validated = false;
@@ -2296,6 +2491,24 @@ function validate_form(gobj, $form)
2296
2491
  return validated;
2297
2492
  }
2298
2493
 
2494
+ /************************************************************
2495
+ * Does the jsoneditor `$editor` hold json its column can store?
2496
+ * Leaves the answer on the element (`yui_json_error`, an i18n key
2497
+ * or ""), where mark_field_validity() reads it.
2498
+ ************************************************************/
2499
+ function check_json_editor($editor)
2500
+ {
2501
+ let jsoneditor = $editor.jsoneditor;
2502
+ let field_desc = $editor.field_desc;
2503
+ if(!jsoneditor || !field_desc || $editor.hasAttribute('readonly')) {
2504
+ $editor.yui_json_error = "";
2505
+ return true;
2506
+ }
2507
+ let r = parse_json_field(json_editor_value(jsoneditor.get()), field_desc.type);
2508
+ $editor.yui_json_error = r.error;
2509
+ return !r.error;
2510
+ }
2511
+
2299
2512
  /************************************************************
2300
2513
  * Function to get input value based on its type
2301
2514
  ************************************************************/
@@ -2455,6 +2668,9 @@ function clear_data(gobj, $form)
2455
2668
  $input.tom_select.clear();
2456
2669
  } else {
2457
2670
  $input.value = null;
2671
+ if($input.yui_svg_preview) {
2672
+ $input.yui_svg_preview();
2673
+ }
2458
2674
  }
2459
2675
  }
2460
2676
  });
@@ -2611,12 +2827,23 @@ function set_form_values(gobj, template, $form, record)
2611
2827
  break;
2612
2828
  case "textarea":
2613
2829
  $input.value = value;
2830
+ if($input.yui_svg_preview) {
2831
+ $input.yui_svg_preview();
2832
+ }
2614
2833
  break;
2615
2834
  case "select":
2616
2835
  $input.value = value;
2617
2836
  break;
2618
2837
  case "select2":
2619
2838
  $input.tom_select.clear();
2839
+ /* A name the list does not carry (an icon deleted, or
2840
+ * not loaded yet) is kept, not dropped: dropping it would
2841
+ * write "" on the next save of an unrelated field. */
2842
+ if(field_desc && field_desc.type === "icon" &&
2843
+ is_string(value) && value &&
2844
+ !$input.tom_select.options[value]) {
2845
+ $input.tom_select.addOption({value: value, text: value});
2846
+ }
2620
2847
  $input.tom_select.setValue(value);
2621
2848
  break;
2622
2849
  case "checkbox":
@@ -2797,6 +3024,7 @@ function treedb_value_2_form_value(gobj, field_desc, value)
2797
3024
  case "color":
2798
3025
  case "image":
2799
3026
  case "icon":
3027
+ case "svg":
2800
3028
  case "tel":
2801
3029
  case "template":
2802
3030
  case "table":
@@ -2867,6 +3095,20 @@ function treedb_value_2_form_value(gobj, field_desc, value)
2867
3095
  return value;
2868
3096
  }
2869
3097
 
3098
+ /************************************************************
3099
+ * A json field's value, parsed. validate_form() refuses a field
3100
+ * that does not parse, so reaching the error here is a path that
3101
+ * skipped it: logged, never quiet.
3102
+ ************************************************************/
3103
+ function parse_json_value(gobj, field_desc, value)
3104
+ {
3105
+ let r = parse_json_field(value, field_desc.type);
3106
+ if(r.error) {
3107
+ log_error(`${gobj_short_name(gobj)}: field '${field_desc.name}' (${field_desc.type}) holds no valid json, stored as empty`);
3108
+ }
3109
+ return r.value;
3110
+ }
3111
+
2870
3112
  /************************************************************
2871
3113
  * Convert from frontend to backend
2872
3114
  * operation: "create" "update"
@@ -2881,21 +3123,7 @@ function form_value_2_treedb_value(gobj, field_desc, value)
2881
3123
  * interpreted-widget conversions ('exec' mode) below. */
2882
3124
  if(gobj_read_str_attr(gobj, "render_mode") === "edit" &&
2883
3125
  (type === "template" || type === "table" || type === "coordinates")) {
2884
- if(is_string(value)) {
2885
- try {
2886
- value = JSON.parse(value);
2887
- } catch (e) {
2888
- value = (type === "table")? [] : {};
2889
- }
2890
- }
2891
- if(type === "table") {
2892
- if(!is_array(value)) {
2893
- value = [];
2894
- }
2895
- } else if(!is_object(value) && !is_array(value)) {
2896
- value = {};
2897
- }
2898
- return value;
3126
+ return parse_json_value(gobj, field_desc, value);
2899
3127
  }
2900
3128
 
2901
3129
  switch(type) {
@@ -2938,26 +3166,20 @@ function form_value_2_treedb_value(gobj, field_desc, value)
2938
3166
  break;
2939
3167
  }
2940
3168
  break;
3169
+ case "icon":
3170
+ /* The picker is a tom-select of one item, which answers a list */
3171
+ if(Array.isArray(value)) {
3172
+ value = value.length > 0? value[0] : "";
3173
+ }
3174
+ break;
2941
3175
  case "date":
2942
3176
  case "color":
2943
3177
  case "image":
2944
- case "icon":
2945
3178
  case "tel":
3179
+ case "svg":
2946
3180
  break;
2947
3181
  case "template":
2948
- if(is_string(value)) {
2949
- // Come from the form
2950
- try {
2951
- value = JSON.parse(value);
2952
- } catch (e) {
2953
- value = {};
2954
- }
2955
- } else if(is_object(value)) {
2956
- // Come from the table
2957
- }
2958
- if(!is_object(value)) {
2959
- value = {};
2960
- }
3182
+ value = parse_json_value(gobj, field_desc, value);
2961
3183
  break;
2962
3184
  case "table":
2963
3185
  case "id":
@@ -2978,19 +3200,7 @@ function form_value_2_treedb_value(gobj, field_desc, value)
2978
3200
  break;
2979
3201
  case "array":
2980
3202
  case "list":
2981
- if(is_string(value)) {
2982
- // Come from the form
2983
- try {
2984
- value = JSON.parse(value);
2985
- } catch (e) {
2986
- value = [];
2987
- }
2988
- } else if(is_array(value)) {
2989
- // Come from the table
2990
- }
2991
- if(!is_array(value)) {
2992
- value = [];
2993
- }
3203
+ value = parse_json_value(gobj, field_desc, value);
2994
3204
  break;
2995
3205
  case "real":
2996
3206
  value = parseFloat(value) || 0.0;
@@ -2999,21 +3209,7 @@ function form_value_2_treedb_value(gobj, field_desc, value)
2999
3209
  value = parseBoolean(value);
3000
3210
  break;
3001
3211
  case "blob":
3002
- if(is_string(value)) {
3003
- // Come from the form
3004
- try {
3005
- value = JSON.parse(value);
3006
- } catch (e) {
3007
- value = {};
3008
- }
3009
-
3010
- } else if(is_object(value)) {
3011
- // Come from the table
3012
- } else if(is_array(value)) {
3013
- // Come from the table
3014
- } else {
3015
- value = {};
3016
- }
3212
+ value = parse_json_value(gobj, field_desc, value);
3017
3213
  break;
3018
3214
  case "number":
3019
3215
  break;
@@ -3231,7 +3427,7 @@ function ac_add_table_row(gobj, event, kw, src)
3231
3427
  }
3232
3428
  })
3233
3429
  .catch(function(error){
3234
- //handle error updating data
3430
+ log_error(`${gobj_short_name(gobj)}: cannot add a table row: ${error}`);
3235
3431
  });
3236
3432
 
3237
3433
  // TODO improve, to use only once the timeout?
@@ -3504,4 +3700,4 @@ function register_c_yui_form()
3504
3700
  return create_gclass(GCLASS_NAME);
3505
3701
  }
3506
3702
 
3507
- export { register_c_yui_form };
3703
+ export { register_c_yui_form, svg_error_text };
@@ -633,6 +633,8 @@ function build_zone(gobj, zone)
633
633
 
634
634
  let $toggle = createElement2(
635
635
  ['button', {class: 'GCLASS_ZONE_TOGGLE', type: 'button',
636
+ title: t(zone.key), 'data-i18n-title': zone.key,
637
+ 'aria-label': t(zone.key), 'data-i18n-aria-label': zone.key,
636
638
  'aria-expanded': collapsed? 'false': 'true'}, [
637
639
  ['span', {class: 'icon GCLASS_ZONE_ARROW'}, [
638
640
  ['i', {class: collapsed? 'yi-chevron-right': 'yi-chevron-down'}]
@@ -726,8 +728,10 @@ function build_attrs(attrs)
726
728
  ['td', {class: 'GCLASS_CELL_KEY'}, a.id],
727
729
  ['td', {class: 'GCLASS_CELL_TYPE'}, a.type],
728
730
  ['td', {class: 'GCLASS_CELL_FLAGS'}, flag_chips(a.flags)],
729
- ['td', {class: 'GCLASS_CELL_DEFAULT'}, a.default_value],
730
- ['td', {class: 'GCLASS_CELL_DESC'}, a.description]
731
+ /* What a remote yuno answers is data, not markup: Text nodes,
732
+ * or a default starting with '<' would be parsed as HTML. */
733
+ ['td', {class: 'GCLASS_CELL_DEFAULT'}, document.createTextNode(String(a.default_value ?? ""))],
734
+ ['td', {class: 'GCLASS_CELL_DESC'}, document.createTextNode(String(a.description ?? ""))]
731
735
  ]];
732
736
  });
733
737