@yuneta/gobj-ui 7.26.7 → 7.26.9

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 (46) hide show
  1. package/README.md +53 -0
  2. package/dist/gobj-ui.cjs.js +534 -232
  3. package/dist/gobj-ui.es.js +534 -232
  4. package/package.json +2 -2
  5. package/src/c_g6_nodes_tree.js +65 -31
  6. package/src/c_yui_form.js +230 -63
  7. package/src/c_yui_gclass.js +23 -22
  8. package/src/c_yui_gobj_tree_js.js +13 -9
  9. package/src/c_yui_json.js +7 -6
  10. package/src/c_yui_json_graph.js +8 -7
  11. package/src/c_yui_json_pad.js +2 -1
  12. package/src/c_yui_map.js +25 -1
  13. package/src/c_yui_nav.js +9 -8
  14. package/src/c_yui_schema_editor.js +25 -24
  15. package/src/c_yui_shell.js +64 -3
  16. package/src/c_yui_treedb_topic_with_form.js +26 -21
  17. package/src/c_yui_treedb_topics.js +17 -16
  18. package/src/c_yui_window.js +73 -32
  19. package/src/c_yui_window_manager.js +3 -2
  20. package/src/form_json_field.js +10 -3
  21. package/src/form_json_field.test.js +6 -0
  22. package/src/form_json_field.wiring.test.js +1 -1
  23. package/src/form_table_rearm.wiring.test.js +158 -0
  24. package/src/form_toolbar_plan.js +5 -5
  25. package/src/g6_event_kw.js +36 -0
  26. package/src/map_stop_windows.wiring.test.js +112 -0
  27. package/src/nav_cards_helpers.js +2 -1
  28. package/src/nav_cards_helpers.test.js +7 -3
  29. package/src/overlay_marker_after_back.wiring.test.js +212 -0
  30. package/src/schema_to_c.js +10 -0
  31. package/src/schema_to_c.test.js +8 -1
  32. package/src/shell_modals.js +7 -5
  33. package/src/shell_route_map.js +12 -13
  34. package/src/treedb_topics_transport.wiring.test.js +26 -0
  35. package/src/vite_plugin_yuneta_html.test.js +94 -0
  36. package/src/window_show.wiring.test.js +83 -0
  37. package/src/window_veto_back.wiring.test.js +35 -0
  38. package/src/yui_asset.js +3 -2
  39. package/src/yui_data_color.js +33 -0
  40. package/src/yui_data_color.test.js +27 -0
  41. package/src/yui_dev.js +15 -13
  42. package/src/yui_frontend_view.js +4 -4
  43. package/src/yui_gclass_view.js +3 -3
  44. package/src/yui_text.js +43 -0
  45. package/src/yui_text.test.js +67 -0
  46. package/vite-plugin-yuneta-html.js +24 -5
@@ -155,6 +155,9 @@ let PRIVATE_DATA = {
155
155
  /* Count of history.back() calls WE issued to retire a dismissed
156
156
  * overlay; the popstate they trigger is expected and ignored. */
157
157
  expected_pops: 0,
158
+ /* Overlays registered while one of those history.back() calls is
159
+ * still in flight: their marker is pushed once it has landed. */
160
+ pending_markers: [],
158
161
  popstate_handler: null,
159
162
  /* Avatar item support — every toolbar item with type:"avatar"
160
163
  * registers its <span> here so refresh_avatars() can repaint
@@ -278,6 +281,9 @@ function mt_start(gobj)
278
281
  /* A history.back() we issued to retire a dismissed
279
282
  * overlay — the teardown already happened. */
280
283
  p.expected_pops--;
284
+ if(p.expected_pops === 0) {
285
+ push_pending_markers(gobj);
286
+ }
281
287
  return;
282
288
  }
283
289
  if(p.overlay_stack.length === 0) {
@@ -2552,6 +2558,9 @@ function drain_overlays(gobj)
2552
2558
  let kept = [];
2553
2559
  while(entries.length > 0) {
2554
2560
  let entry = entries.pop();
2561
+ if(entry.dismissed) {
2562
+ continue; // its owner went with an earlier close of this drain
2563
+ }
2555
2564
  if(entry.keep_on_navigate) {
2556
2565
  kept.unshift(entry);
2557
2566
  continue;
@@ -2600,16 +2609,60 @@ function push_overlay_history(gobj, close, opts)
2600
2609
  * dock-managed window registers no overlay at all. */
2601
2610
  keep_on_navigate: !!(opts && opts.keep_on_navigate) };
2602
2611
  priv.overlay_stack.push(entry);
2612
+
2613
+ /* A history.back() of ours still in flight (an overlay closed by a
2614
+ * button, and this one opened in the same turn: a window that takes
2615
+ * its entry back when its question is answered, a dialog that opens
2616
+ * another). back() is ASYNCHRONOUS and pushState is not, so a marker
2617
+ * pushed now lands BEFORE the traversal, which then runs from it:
2618
+ * the marker is left orphaned ahead of the old one, and the pop we
2619
+ * counted is the user's next Back. The marker waits for the landing. */
2620
+ if(priv.expected_pops > 0) {
2621
+ entry.marker_pending = true;
2622
+ priv.pending_markers.push(entry);
2623
+ return entry;
2624
+ }
2625
+ if(!push_overlay_marker(gobj, entry)) {
2626
+ return null; // Error already logged
2627
+ }
2628
+ return entry;
2629
+ }
2630
+
2631
+ function push_overlay_marker(gobj, entry)
2632
+ {
2633
+ let priv = gobj.priv;
2603
2634
  try {
2604
2635
  window.history.pushState({ __yui_overlay__: entry.id }, "");
2605
2636
  } catch(e) {
2606
2637
  /* pushState failed (rare): drop the entry so overlay_dismissed
2607
2638
  * won't later history.back() past a real route. */
2608
- priv.overlay_stack.pop();
2639
+ let idx = priv.overlay_stack.indexOf(entry);
2640
+ if(idx >= 0) {
2641
+ priv.overlay_stack.splice(idx, 1);
2642
+ }
2609
2643
  log_warning(`C_YUI_SHELL: overlay pushState failed: ${e}`);
2610
- return null;
2644
+ return false;
2645
+ }
2646
+ return true;
2647
+ }
2648
+
2649
+ /* The history.back() calls of ours have all landed: push the markers of
2650
+ * the overlays registered meanwhile, in their order. One closed in the
2651
+ * meantime (dismissed, drained, or no longer on the stack) has none. */
2652
+ function push_pending_markers(gobj)
2653
+ {
2654
+ let priv = gobj.priv;
2655
+ let pending = priv.pending_markers.splice(0);
2656
+ for(let entry of pending) {
2657
+ entry.marker_pending = false;
2658
+ if(entry.dismissed || priv.overlay_stack.indexOf(entry) < 0) {
2659
+ continue;
2660
+ }
2661
+ /* The traversal was same-hash, but a route may have moved
2662
+ * meanwhile: the marker lives on the hash it is pushed on. */
2663
+ entry.hash = window.location.hash;
2664
+ push_overlay_marker(gobj, entry); // Error already logged
2611
2665
  }
2612
- return entry;
2613
2666
  }
2614
2667
 
2615
2668
  function overlay_dismissed(gobj, entry)
@@ -2618,12 +2671,20 @@ function overlay_dismissed(gobj, entry)
2618
2671
  if(!priv || !priv.overlay_stack || !entry) {
2619
2672
  return;
2620
2673
  }
2674
+ /* Marked even when it is no longer on the stack: drain_overlays()
2675
+ * works on a COPY, and an entry whose owner an earlier close of the
2676
+ * same drain already took down must not be closed a second time. */
2677
+ entry.dismissed = true;
2621
2678
  let idx = priv.overlay_stack.indexOf(entry);
2622
2679
  if(idx < 0) {
2623
2680
  /* Already removed by the popstate handler (closed via Back). */
2624
2681
  return;
2625
2682
  }
2626
2683
  priv.overlay_stack.splice(idx, 1);
2684
+ if(entry.marker_pending) {
2685
+ /* Its marker was never pushed: there is nothing to retire. */
2686
+ return;
2687
+ }
2627
2688
  /* Retire the synthetic browser entry ONLY when it is the CURRENT
2628
2689
  * one — its state marker is live — so history.back() steps off it
2629
2690
  * invisibly (same hash, no route change). In every other case the
@@ -122,6 +122,7 @@ import "./tabulator.css";
122
122
  import {cell_text, hook_cell_spec} from "./table_cell_text.js";
123
123
 
124
124
  import { TabulatorFull as Tabulator } from "tabulator-tables";
125
+ import {text_node} from "./yui_text.js";
125
126
 
126
127
  /***************************************************************
127
128
  * Constants
@@ -612,8 +613,8 @@ function build_ui(gobj)
612
613
  {
613
614
  function create_table_toolbar()
614
615
  {
615
- // TODO pon autorización, solo si está autorizado a modificar los datos!!!
616
- // TODO deja que estos botones se queden en el top cuando se hace scroll (clip ?)
616
+ // TODO authorization: only when the user may modify the data!!!
617
+ // TODO keep these buttons at the top when scrolling (clip ?)
617
618
  let $table_toolbar = [];
618
619
  /* One plan decides every write affordance (treedb_write_plan.js):
619
620
  * `readonly` is the STATE of the topic and beats each with_* flag,
@@ -1146,7 +1147,7 @@ function col_title_formatter(gobj, col)
1146
1147
  if(t(col.id, {defaultValue: NO_I18N}) !== NO_I18N) {
1147
1148
  attrs.i18n = col.id;
1148
1149
  }
1149
- return createElement2(['span', attrs, text]);
1150
+ return createElement2(['span', attrs, text_node(text)]);
1150
1151
  };
1151
1152
  }
1152
1153
 
@@ -1886,9 +1887,9 @@ function create_tabulator(gobj)
1886
1887
  tabulator._ready = true;
1887
1888
  apply_row_filters(gobj);
1888
1889
  update_rowcount();
1889
- /* La ✕ de cada filtro de cabecera. Un filtro se quita borrando lo
1890
- * escrito, y con varias columnas filtradas volver a la tabla entera
1891
- * era acordarse de cuáles se tocaron. */
1890
+ /* The ✕ of each header filter. A filter is removed by erasing what
1891
+ * was typed, and with several columns filtered, getting back to the
1892
+ * whole table meant remembering which ones were touched. */
1892
1893
  yui_table_filter_clear(tabulator);
1893
1894
  if(tabulator._pendingData !== undefined) {
1894
1895
  tabulator.setData(tabulator._pendingData);
@@ -2044,7 +2045,7 @@ function file_cell_formatter(cell, formatterParams, onRendered)
2044
2045
  }
2045
2046
  const children = [
2046
2047
  ['span', {class: 'FILE_CELL_ICON icon yi-eye'}],
2047
- ['span', {class: 'FILE_CELL_ID'}, yui_file_id_label(ids[0])]
2048
+ ['span', {class: 'FILE_CELL_ID'}, text_node(yui_file_id_label(ids[0]))]
2048
2049
  ];
2049
2050
  if(ids.length > 1) {
2050
2051
  children.push(['span', {class: 'FILE_CELL_MORE'}, `+${ids.length - 1}`]);
@@ -2146,7 +2147,7 @@ function build_json_cell_preview(value)
2146
2147
  'data-i18n-aria-label': 'show json'
2147
2148
  }, [
2148
2149
  ['span', {class: 'JSON_CELL_ICON icon yi-eye'}],
2149
- ['span', {class: 'JSON_CELL_PREVIEW'}, text]
2150
+ ['span', {class: 'JSON_CELL_PREVIEW'}, text_node(text)]
2150
2151
  ]]
2151
2152
  );
2152
2153
  }
@@ -3002,7 +3003,7 @@ function open_cell_file_dialog(gobj, row_id, col_id)
3002
3003
  ['span', {class: 'CELL_FILE_LOADING', i18n: 'loading'}, 'loading']
3003
3004
  ]],
3004
3005
  ['div', {class: 'CELL_FILE_CAPTION'}, [
3005
- ['span', {class: 'CELL_FILE_ID'}, id]
3006
+ ['span', {class: 'CELL_FILE_ID'}, text_node(id)]
3006
3007
  ]]
3007
3008
  ]]
3008
3009
  ));
@@ -3065,7 +3066,7 @@ function fill_cell_file_slot(gobj, pend, answer, error)
3065
3066
  .filter((s) => !!s).join(" · ");
3066
3067
  if(meta) {
3067
3068
  $caption.appendChild(
3068
- createElement2(['span', {class: 'CELL_FILE_META'}, meta])
3069
+ createElement2(['span', {class: 'CELL_FILE_META'}, text_node(meta)])
3069
3070
  );
3070
3071
  }
3071
3072
  /* Full size, in the browser's own viewer: a photo is read at its
@@ -3149,7 +3150,7 @@ function open_hook_choice_dialog(gobj, targets, parent_id, hook)
3149
3150
  'aria-label': t(tg.topic_name),
3150
3151
  'data-i18n-aria-label': tg.topic_name
3151
3152
  }, [
3152
- ['span', {i18n: tg.topic_name}, tg.topic_name]
3153
+ ['span', {i18n: tg.topic_name}, text_node(tg.topic_name)]
3153
3154
  ], {
3154
3155
  click: () => {
3155
3156
  gobj_send_event(gobj, "EV_CHOOSE_LINKED", {
@@ -3489,13 +3490,17 @@ function transform__form_value_2_treedb_value(gobj, col, value, operation)
3489
3490
  case "list":
3490
3491
  case "coordinates":
3491
3492
  case "blob": {
3492
- /* A value that is no json of the column's shape becomes the
3493
- * empty one -- said, not quiet. */
3493
+ /* A value that is no json of the column's shape is logged and
3494
+ * handed on AS IT IS, the same as C_YUI_FORM does: an empty
3495
+ * {} / [] in its place is a value nobody wrote (a copy put it
3496
+ * on the clipboard, a save wiped the column). The form refuses
3497
+ * to save such a field before it gets here. */
3494
3498
  let r = parse_json_field(value, field_desc.type);
3495
3499
  if(r.error) {
3496
- log_warning(`${gobj_short_name(gobj)}: column '${col.id}' (${field_desc.type}) holds no valid json, taken as empty`);
3500
+ log_error(`${gobj_short_name(gobj)}: column '${col.id}' (${field_desc.type}) holds no valid json, handed on as it is`);
3501
+ } else {
3502
+ value = r.value;
3497
3503
  }
3498
- value = r.value;
3499
3504
  break;
3500
3505
  }
3501
3506
 
@@ -3820,7 +3825,7 @@ function ac_load_nodes(gobj, event, kw, src)
3820
3825
  }
3821
3826
 
3822
3827
  /*
3823
- * TODO situate en el row updated ???
3828
+ * TODO scroll to the updated row ???
3824
3829
  * Select only if it has update/create mode
3825
3830
  */
3826
3831
  // if(data.length == 1) {
@@ -3860,7 +3865,7 @@ function ac_load_node_created(gobj, event, kw, src)
3860
3865
  }
3861
3866
 
3862
3867
  /*
3863
- * TODO situate en el row updated ???
3868
+ * TODO scroll to the updated row ???
3864
3869
  * Select only if it has update/create mode
3865
3870
  */
3866
3871
 
@@ -3902,7 +3907,7 @@ function ac_load_node_updated(gobj, event, kw, src)
3902
3907
  }
3903
3908
 
3904
3909
  /*
3905
- * TODO situate en el row updated ???
3910
+ * TODO scroll to the updated row ???
3906
3911
  * Select only if it has update/create mode
3907
3912
  */
3908
3913
 
@@ -4056,7 +4061,7 @@ function ac_new_row(gobj, event, kw, src)
4056
4061
  return -1; /* Error already logged */
4057
4062
  }
4058
4063
  /*
4059
- * Build default values. TODO no debería estar en desc configuration?
4064
+ * Build default values. TODO should this not be in the desc configuration?
4060
4065
  */
4061
4066
  let row = {};
4062
4067
  let desc = gobj_read_attr(gobj, "desc");
@@ -4809,7 +4814,7 @@ function build_delete_question(gobj, records)
4809
4814
  if(one && one[pkey] !== undefined && one[pkey] !== null) {
4810
4815
  lines.push(["p", {class: "DELETE_ASK_WHAT", style: ROW}, [
4811
4816
  ["span", {i18n: "delete"}, t("delete")],
4812
- ["strong", {}, String(one[pkey])]
4817
+ ["strong", {}, text_node(one[pkey])]
4813
4818
  ]]);
4814
4819
  } else {
4815
4820
  lines.push(["p", {class: "DELETE_ASK_WHAT", style: ROW}, [
@@ -5064,7 +5069,7 @@ function ac_open_columns(gobj, event, kw, src)
5064
5069
  $list.appendChild(createElement2(
5065
5070
  ['label', {class: 'checkbox is-block mb-1 TREEDB_COLUMN_ITEM'}, [
5066
5071
  $cb,
5067
- ['span', {class: 'ml-2'}, column.getDefinition().title || field]
5072
+ ['span', {class: 'ml-2'}, text_node(column.getDefinition().title || field)]
5068
5073
  ]]
5069
5074
  ));
5070
5075
  }
@@ -85,6 +85,7 @@ import {
85
85
  } from "./treedb_topic_keys.js";
86
86
 
87
87
  import {t} from "i18next";
88
+ import {text_node} from "./yui_text.js";
88
89
 
89
90
  /***************************************************************
90
91
  * Constants
@@ -440,7 +441,7 @@ function build_ui(gobj)
440
441
  'TREEDB_TOPICS_SOURCE' : 'TREEDB_TOPICS_SOURCE is-hidden',
441
442
  title: source_url, 'aria-label': source_url}, [
442
443
  ['span', {class: 'icon'}, [yui_toolbar_icon('yi-cloudversify')]],
443
- ['span', {class: 'TREEDB_TOPICS_SOURCE_URL'}, source_url]
444
+ ['span', {class: 'TREEDB_TOPICS_SOURCE_URL'}, text_node(source_url)]
444
445
  ]],
445
446
  ...graph_items,
446
447
  /* Inspect the treedb's raw tranger json (whole service,
@@ -622,7 +623,7 @@ function add_tab(gobj, gobj2, id, text, icon)
622
623
  * TAB: Add text
623
624
  */
624
625
  $a.appendChild(
625
- createElement2(['span', {i18n: text, class: ''}, text])
626
+ createElement2(['span', {i18n: text, class: ''}, text_node(text)])
626
627
  );
627
628
 
628
629
  /*
@@ -764,10 +765,10 @@ function topic_card_meta(desc)
764
765
  if(desc.topic_version !== undefined && desc.topic_version !== null && desc.topic_version !== "") {
765
766
  head.push(['span', {class: 'TREEDB_TOPIC_CARD_VERSION',
766
767
  title: t('version'), 'data-i18n-title': 'version'},
767
- `v${desc.topic_version}`]);
768
+ text_node(`v${desc.topic_version}`)]);
768
769
  }
769
770
  head.push(['span', {class: 'TREEDB_TOPIC_CARD_COLS'}, [
770
- ['span', {}, `${n_cols}`],
771
+ ['span', {}, text_node(n_cols)],
771
772
  ['span', {i18n: 'columns'}, 'columns']
772
773
  ]]);
773
774
  meta.push(['div', {class: 'TREEDB_TOPIC_CARD_META'}, head]);
@@ -779,7 +780,7 @@ function topic_card_meta(desc)
779
780
  let list = pkey2s.join(", ");
780
781
  meta.push(['div', {class: 'TREEDB_TOPIC_CARD_REL TREEDB_TOPIC_CARD_PKEY2S', title: list}, [
781
782
  ['span', {class: 'TREEDB_TOPIC_CARD_REL_LABEL', i18n: 'pkey2s'}, 'pkey2s'],
782
- ['span', {class: 'TREEDB_TOPIC_CARD_REL_LIST'}, list]
783
+ ['span', {class: 'TREEDB_TOPIC_CARD_REL_LIST'}, text_node(list)]
783
784
  ]]);
784
785
  }
785
786
 
@@ -788,7 +789,7 @@ function topic_card_meta(desc)
788
789
  return ['div', {class: `TREEDB_TOPIC_CARD_REL ${cls}`, title: list}, [
789
790
  ['span', {class: 'TREEDB_TOPIC_CARD_REL_ARROW', 'aria-hidden': 'true'}, arrow],
790
791
  ['span', {class: 'TREEDB_TOPIC_CARD_REL_LABEL', i18n: key}, key],
791
- ['span', {class: 'TREEDB_TOPIC_CARD_REL_LIST'}, list]
792
+ ['span', {class: 'TREEDB_TOPIC_CARD_REL_LIST'}, text_node(list)]
792
793
  ]];
793
794
  };
794
795
  if(parents.length) {
@@ -824,7 +825,7 @@ function add_topic_card(gobj, id, text, icon, desc)
824
825
  'aria-label': text, 'data-i18n-aria-label': text}, [
825
826
  ['span', {class: 'icon is-medium'}, [['i', {class: icon || 'yi-table',
826
827
  'aria-hidden': 'true'}]]],
827
- ['span', {class: 'yui-nav-label', i18n: text}, text]
828
+ ['span', {class: 'yui-nav-label', i18n: text}, text_node(text)]
828
829
  ]]
829
830
  );
830
831
  $card.addEventListener("click", function(ev) {
@@ -861,7 +862,7 @@ function add_topic_card(gobj, id, text, icon, desc)
861
862
 
862
863
  let $card = createElement2(
863
864
  ['div', {class: 'TREEDB_TOPIC_CARD', 'data-topic': topic}, [
864
- ['span', {class: 'TREEDB_TOPIC_CARD_NAME', i18n: text}, text],
865
+ ['span', {class: 'TREEDB_TOPIC_CARD_NAME', i18n: text}, text_node(text)],
865
866
  ...topic_card_meta(desc),
866
867
  ['div', {class: 'TREEDB_TOPIC_CARD_ACTIONS'}, actions]
867
868
  ]]
@@ -1162,22 +1163,22 @@ function build_topic_info_panel(gobj, $info, topic, desc)
1162
1163
  );
1163
1164
  };
1164
1165
  if(desc.topic_version !== undefined && desc.topic_version !== null && desc.topic_version !== "") {
1165
- push_meta("version", ["span", {class: "tag is-info"}, `${desc.topic_version}`]);
1166
+ push_meta("version", ["span", {class: "tag is-info"}, text_node(desc.topic_version)]);
1166
1167
  }
1167
1168
  let sf_names = system_flag_names(desc.system_flag);
1168
1169
  if(sf_names.length > 0) {
1169
1170
  push_meta("system", ["code", {title: `${desc.system_flag}`}, sf_names.join(" | ")]);
1170
1171
  }
1171
1172
  if(pkey) {
1172
- push_meta("pkey", ["code", {}, pkey]);
1173
+ push_meta("pkey", ["code", {}, text_node(pkey)]);
1173
1174
  }
1174
1175
  if(pkey2s.length > 0) {
1175
1176
  push_meta("pkey2s", ["span", {class: "tags"},
1176
- pkey2s.map(name => ["span", {class: "tag is-warning"}, name])
1177
+ pkey2s.map(name => ["span", {class: "tag is-warning"}, text_node(name)])
1177
1178
  ]);
1178
1179
  }
1179
1180
  push_meta("tkey", tkey
1180
- ? ["code", {}, tkey]
1181
+ ? ["code", {}, text_node(tkey)]
1181
1182
  : ["span", {class: "has-text-grey", i18n: "append time"}, "append time"]
1182
1183
  );
1183
1184
 
@@ -1199,9 +1200,9 @@ function build_topic_info_panel(gobj, $info, topic, desc)
1199
1200
  let is_key = roles.length > 0;
1200
1201
  $rows.push(
1201
1202
  ["tr", is_key ? {class: "TREEDB_TOPIC_INFO_KEY_COL"} : {}, [
1202
- ["td", {}, [["code", is_key ? {class: "has-text-weight-bold"} : {}, `${col.id}`]]],
1203
- ["td", {}, `${type}`],
1204
- ["td", is_key ? {class: "has-text-weight-semibold"} : {}, `${rel}`]
1203
+ ["td", {}, [["code", is_key ? {class: "has-text-weight-bold"} : {}, text_node(col.id)]]],
1204
+ ["td", {}, text_node(type)],
1205
+ ["td", is_key ? {class: "has-text-weight-semibold"} : {}, text_node(rel)]
1205
1206
  ]]
1206
1207
  );
1207
1208
  }
@@ -1211,7 +1212,7 @@ function build_topic_info_panel(gobj, $info, topic, desc)
1211
1212
  ["h3", {class: "TREEDB_TOPIC_INFO_TITLE title is-5"}, [
1212
1213
  ["span", {class: "icon-text"}, [
1213
1214
  ["span", {class: "icon"}, [["i", {class: "yi-circle-info"}]]],
1214
- ["span", {i18n: `${topic}`}, `${topic}`]
1215
+ ["span", {i18n: `${topic}`}, text_node(topic)]
1215
1216
  ]]
1216
1217
  ]],
1217
1218
  ["table", {class: "table is-narrow TREEDB_TOPIC_INFO_META mb-4"}, [
@@ -54,6 +54,7 @@ import {
54
54
  } from "./c_yui_shell.js";
55
55
 
56
56
  import "./c_yui_window.css";
57
+ import {text_node} from "./yui_text.js";
57
58
 
58
59
  /***************************************************************
59
60
  * Constants
@@ -104,9 +105,9 @@ SDATA(data_type_t.DTP_STRING, "title_prefix", 0, "", "Optional DATA half
104
105
  SDATA(data_type_t.DTP_STRING, "title", 0, "", "Window title, an i18n KEY: painted in the title bar (unless `header` overrides it) and on the dock chip. Pass the key, not t(key), or it cannot re-translate"),
105
106
  SDATA(data_type_t.DTP_STRING, "icon", 0, "", "Window icon (by window type), leading the title bar and the dock chip: a yi-* class name or inline SVG"),
106
107
  // TODO declared, NOT implemented yet: focus, modal, keyboard (Escape does not close a window)
107
- SDATA(data_type_t.DTP_POINTER, "focus", 0, null, "Brings focus to the element, can be a number or selector"),
108
- SDATA(data_type_t.DTP_BOOLEAN, "modal", 0, false, "Enable modal mode"),
109
- SDATA(data_type_t.DTP_BOOLEAN, "keyboard", 0, true, "Close window on ESC if not modal"),
108
+ SDATA(data_type_t.DTP_POINTER, "focus", 0, null, "NOT implemented yet: would bring focus to the element, a number or a selector"),
109
+ SDATA(data_type_t.DTP_BOOLEAN, "modal", 0, false, "NOT implemented yet: would enable modal mode"),
110
+ SDATA(data_type_t.DTP_BOOLEAN, "keyboard", 0, true, "NOT implemented yet: would close the window on ESC (Escape does nothing today)"),
110
111
  SDATA(data_type_t.DTP_BOOLEAN, "back_dismissable", 0, true, "Browser Back closes this window (floating overlays only; ignored when it has a `manager`)"),
111
112
  SDATA(data_type_t.DTP_BOOLEAN, "keep_on_navigate", 0, false, "This window is a navigation PANEL: a route change does not close it"),
112
113
  SDATA(data_type_t.DTP_POINTER, "back_overlay", 0, null, "Internal: overlay-history entry (Back-button integration)"),
@@ -340,13 +341,13 @@ function build_default_header(gobj)
340
341
  if(!empty_string(prefix)) {
341
342
  items.push(
342
343
  ['span', {class: 'WINDOW_TITLE_PREFIX has-text-weight-semibold'},
343
- document.createTextNode(String(prefix))] // data, not markup
344
+ text_node(prefix)] // data, not markup
344
345
  );
345
346
  }
346
347
  if(!empty_string(title)) {
347
348
  items.push(
348
349
  ['span', {class: 'WINDOW_TITLE_KIND has-text-weight-semibold',
349
- i18n: title}, title]
350
+ i18n: title}, text_node(title)]
350
351
  );
351
352
  }
352
353
 
@@ -772,13 +773,25 @@ function register_back_overlay(gobj)
772
773
  if(!shell) {
773
774
  return;
774
775
  }
776
+ /* A window that survives its close gets its entry back -- but only
777
+ * once the question is over. A close that ASKS (unsaved changes)
778
+ * opened a dialog that registered its own entry; one put back now
779
+ * would sit ABOVE the question, and every Back would stack another
780
+ * dialog instead of closing the one on screen. */
781
+ const rearm = function() {
782
+ if(!gobj_is_destroying(gobj) && !gobj_read_attr(gobj, "back_overlay")) {
783
+ register_back_overlay(gobj);
784
+ }
785
+ };
775
786
  let overlay = yui_shell_register_overlay(
776
787
  shell,
777
788
  function() {
778
789
  gobj_write_attr(gobj, "back_overlay", null);
779
- close_window(gobj);
780
- if(!gobj_is_destroying(gobj) && !gobj_read_attr(gobj, "back_overlay")) {
781
- register_back_overlay(gobj);
790
+ const closing = close_window(gobj);
791
+ if(closing.state === "vetoed") {
792
+ rearm();
793
+ } else if(closing.state === "asking") {
794
+ closing.answer.then(rearm);
782
795
  }
783
796
  },
784
797
  {keep_on_navigate: gobj_read_bool_attr(gobj, "keep_on_navigate")}
@@ -787,7 +800,12 @@ function register_back_overlay(gobj)
787
800
  }
788
801
 
789
802
  /************************************************************
790
- *
803
+ * Ask to close the window. Answers what happened:
804
+ * {state: "closed"} the window is destroyed
805
+ * {state: "vetoed"} a subscriber kept it open
806
+ * {state: "asking", answer} a subscriber asked a question
807
+ * first; `answer` resolves to
808
+ * it once it is over
791
809
  ************************************************************/
792
810
  function close_window(gobj)
793
811
  {
@@ -809,29 +827,34 @@ function close_window(gobj)
809
827
  }
810
828
  gobj_stop_children(gobj);
811
829
  gobj_destroy(gobj);
812
- } else if(kw_close.warning) {
813
- yui_shell_confirm_yesnocancel(
814
- yui_shell_of(gobj), kw_close.warning,
815
- {t: t, yes_label: "yes", no_label: "no", cancel_label: "cancel"}
816
- ).then(function(answer) {
817
- if(answer !== "yes") {
818
- return;
819
- }
820
- /* The question was asynchronous: the window may have been
821
- * torn down by another path while it was open. */
822
- if(gobj_is_destroying(gobj)) {
823
- return;
824
- }
825
- if(on_close) {
826
- on_close();
827
- }
828
- if(gobj_is_running(gobj)) {
829
- gobj_stop(gobj);
830
- }
831
- gobj_stop_children(gobj);
832
- gobj_destroy(gobj);
833
- });
830
+ return {state: "closed"};
831
+ }
832
+ if(!kw_close.warning) {
833
+ return {state: "vetoed"};
834
834
  }
835
+ const answer = yui_shell_confirm_yesnocancel(
836
+ yui_shell_of(gobj), kw_close.warning,
837
+ {t: t, yes_label: "yes", no_label: "no", cancel_label: "cancel"}
838
+ ).then(function(answer) {
839
+ if(answer !== "yes") {
840
+ return answer;
841
+ }
842
+ /* The question was asynchronous: the window may have been
843
+ * torn down by another path while it was open. */
844
+ if(gobj_is_destroying(gobj)) {
845
+ return answer;
846
+ }
847
+ if(on_close) {
848
+ on_close();
849
+ }
850
+ if(gobj_is_running(gobj)) {
851
+ gobj_stop(gobj);
852
+ }
853
+ gobj_stop_children(gobj);
854
+ gobj_destroy(gobj);
855
+ return answer;
856
+ });
857
+ return {state: "asking", answer: answer};
835
858
  }
836
859
 
837
860
  /************************************************************
@@ -1211,7 +1234,25 @@ function ac_refresh(gobj, event, kw, src)
1211
1234
  ************************************************************/
1212
1235
  function ac_show(gobj, event, kw, src)
1213
1236
  {
1214
-
1237
+ /* Bring the window back in front of the reader: out of the dock if
1238
+ * it was minimized, above the others. The manager owns both when
1239
+ * there is one; without one the window is just made visible and
1240
+ * moved to the top of its layer. */
1241
+ let manager = gobj_read_pointer_attr(gobj, "manager");
1242
+ if(manager) {
1243
+ gobj_send_event(manager, "EV_FOCUS_WINDOW", {window: gobj}, gobj);
1244
+ return 0;
1245
+ }
1246
+ let $container = gobj_read_attr(gobj, "$container");
1247
+ if(!$container) {
1248
+ log_error(`${gobj_short_name(gobj)}: EV_SHOW without a container`);
1249
+ return -1;
1250
+ }
1251
+ $container.style.removeProperty('display');
1252
+ let $parent = $container.parentNode;
1253
+ if($parent && $parent.lastChild !== $container) {
1254
+ $parent.appendChild($container);
1255
+ }
1215
1256
  return 0;
1216
1257
  }
1217
1258
 
@@ -45,6 +45,7 @@ import {
45
45
  } from "@yuneta/gobj-js";
46
46
 
47
47
  import {t} from "i18next";
48
+ import {text_node} from "./yui_text.js";
48
49
 
49
50
 
50
51
  /***************************************************************
@@ -470,7 +471,7 @@ function ac_register_window(gobj, event, kw, src)
470
471
  let label_items = [];
471
472
  if(prefix) {
472
473
  label_items.push(['span', {class: 'yui-dock-label-prefix'},
473
- document.createTextNode(String(prefix))]); // data, not markup
474
+ text_node(prefix)]); // data, not markup
474
475
  }
475
476
  if(title_key) {
476
477
  label_items.push(
@@ -481,7 +482,7 @@ function ac_register_window(gobj, event, kw, src)
481
482
  if(label_items.length === 0) {
482
483
  /* No split halves supplied (legacy caller): plain text. */
483
484
  label_items.push(['span', {class: 'yui-dock-label-kind'},
484
- document.createTextNode(String(title))]); // data, not markup
485
+ text_node(title)]); // data, not markup
485
486
  }
486
487
 
487
488
  let entry = {gobj: win, $chip: null, minimized: false};
@@ -101,8 +101,12 @@ export function parse_json_field(value, type)
101
101
  }
102
102
 
103
103
  /************************************************************
104
- * What a jsoneditor content ({text} or {json}) holds: the
105
- * text as typed, or the tree-mode json.
104
+ * What a jsoneditor content ({text} or {json}) holds, as TEXT:
105
+ * the text as typed, or the tree-mode json serialized -- which is
106
+ * what get_form_values() reads out of the editor too. Handing the
107
+ * tree-mode value back as is made parse_json_field() parse a
108
+ * string ROOT a second time: "123" was checked as the number 123,
109
+ * and "abc" as a text that is no json.
106
110
  ************************************************************/
107
111
  export function json_editor_value(content)
108
112
  {
@@ -112,5 +116,8 @@ export function json_editor_value(content)
112
116
  if(content.text !== undefined) {
113
117
  return content.text;
114
118
  }
115
- return content.json;
119
+ if(content.json === undefined) {
120
+ return undefined;
121
+ }
122
+ return JSON.stringify(content.json);
116
123
  }
@@ -40,4 +40,10 @@ describe("parse_json_field", () => {
40
40
  expect(json_field_shape("table")).toBe("list");
41
41
  expect(json_field_shape("blob")).toBe("any");
42
42
  });
43
+
44
+ it("a tree-mode string root is read as the string it is, as the save reads it", () => {
45
+ expect(json_editor_value({json: "123"})).toBe('"123"');
46
+ expect(parse_json_field(json_editor_value({json: "123"}), "blob")).toEqual({value: "123", error: ""});
47
+ expect(parse_json_field(json_editor_value({json: "abc"}), "blob")).toEqual({value: "abc", error: ""});
48
+ });
43
49
  });
@@ -132,6 +132,6 @@ describe("a json field that does not parse", () => {
132
132
  expect($editor.classList.contains("is-danger")).toBe(false);
133
133
  gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
134
134
  expect(saved.length).toBe(1);
135
- expect(saved[0].settings).toBe('{"a": 1}');
135
+ expect(saved[0].settings).toEqual({a: 1}); // parsed: the backend gets json, not text
136
136
  });
137
137
  });