@yuneta/gobj-ui 7.26.8 → 7.26.10

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.
@@ -765,10 +765,10 @@ function topic_card_meta(desc)
765
765
  if(desc.topic_version !== undefined && desc.topic_version !== null && desc.topic_version !== "") {
766
766
  head.push(['span', {class: 'TREEDB_TOPIC_CARD_VERSION',
767
767
  title: t('version'), 'data-i18n-title': 'version'},
768
- `v${desc.topic_version}`]);
768
+ text_node(`v${desc.topic_version}`)]);
769
769
  }
770
770
  head.push(['span', {class: 'TREEDB_TOPIC_CARD_COLS'}, [
771
- ['span', {}, `${n_cols}`],
771
+ ['span', {}, text_node(n_cols)],
772
772
  ['span', {i18n: 'columns'}, 'columns']
773
773
  ]]);
774
774
  meta.push(['div', {class: 'TREEDB_TOPIC_CARD_META'}, head]);
@@ -780,7 +780,7 @@ function topic_card_meta(desc)
780
780
  let list = pkey2s.join(", ");
781
781
  meta.push(['div', {class: 'TREEDB_TOPIC_CARD_REL TREEDB_TOPIC_CARD_PKEY2S', title: list}, [
782
782
  ['span', {class: 'TREEDB_TOPIC_CARD_REL_LABEL', i18n: 'pkey2s'}, 'pkey2s'],
783
- ['span', {class: 'TREEDB_TOPIC_CARD_REL_LIST'}, list]
783
+ ['span', {class: 'TREEDB_TOPIC_CARD_REL_LIST'}, text_node(list)]
784
784
  ]]);
785
785
  }
786
786
 
@@ -789,7 +789,7 @@ function topic_card_meta(desc)
789
789
  return ['div', {class: `TREEDB_TOPIC_CARD_REL ${cls}`, title: list}, [
790
790
  ['span', {class: 'TREEDB_TOPIC_CARD_REL_ARROW', 'aria-hidden': 'true'}, arrow],
791
791
  ['span', {class: 'TREEDB_TOPIC_CARD_REL_LABEL', i18n: key}, key],
792
- ['span', {class: 'TREEDB_TOPIC_CARD_REL_LIST'}, list]
792
+ ['span', {class: 'TREEDB_TOPIC_CARD_REL_LIST'}, text_node(list)]
793
793
  ]];
794
794
  };
795
795
  if(parents.length) {
@@ -1163,7 +1163,7 @@ function build_topic_info_panel(gobj, $info, topic, desc)
1163
1163
  );
1164
1164
  };
1165
1165
  if(desc.topic_version !== undefined && desc.topic_version !== null && desc.topic_version !== "") {
1166
- 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)]);
1167
1167
  }
1168
1168
  let sf_names = system_flag_names(desc.system_flag);
1169
1169
  if(sf_names.length > 0) {
@@ -1200,9 +1200,9 @@ function build_topic_info_panel(gobj, $info, topic, desc)
1200
1200
  let is_key = roles.length > 0;
1201
1201
  $rows.push(
1202
1202
  ["tr", is_key ? {class: "TREEDB_TOPIC_INFO_KEY_COL"} : {}, [
1203
- ["td", {}, [["code", is_key ? {class: "has-text-weight-bold"} : {}, `${col.id}`]]],
1204
- ["td", {}, `${type}`],
1205
- ["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)]
1206
1206
  ]]
1207
1207
  );
1208
1208
  }
@@ -1212,7 +1212,7 @@ function build_topic_info_panel(gobj, $info, topic, desc)
1212
1212
  ["h3", {class: "TREEDB_TOPIC_INFO_TITLE title is-5"}, [
1213
1213
  ["span", {class: "icon-text"}, [
1214
1214
  ["span", {class: "icon"}, [["i", {class: "yi-circle-info"}]]],
1215
- ["span", {i18n: `${topic}`}, `${topic}`]
1215
+ ["span", {i18n: `${topic}`}, text_node(topic)]
1216
1216
  ]]
1217
1217
  ]],
1218
1218
  ["table", {class: "table is-narrow TREEDB_TOPIC_INFO_META mb-4"}, [
@@ -42,6 +42,8 @@ import {
42
42
  gobj_is_destroying,
43
43
  refresh_language,
44
44
  empty_string,
45
+ gobj_full_name,
46
+ html_markup,
45
47
  } from "@yuneta/gobj-js";
46
48
 
47
49
  import {t} from "i18next";
@@ -163,7 +165,7 @@ function mt_create(gobj)
163
165
  $c.addEventListener("pointerdown", function() {
164
166
  let m = gobj_read_pointer_attr(gobj, "manager");
165
167
  if(m) {
166
- gobj_send_event(m, "EV_FOCUS_WINDOW", {window: gobj}, gobj);
168
+ gobj_send_event(m, "EV_FOCUS_WINDOW", {window: gobj_full_name(gobj)}, gobj);
167
169
  }
168
170
  }, true);
169
171
  }
@@ -175,7 +177,7 @@ function mt_create(gobj)
175
177
  * own), `title_prefix` the DATA half, never translated. */
176
178
  let chip_title = composed_title(gobj);
177
179
  gobj_send_event(manager, "EV_REGISTER_WINDOW", {
178
- window: gobj,
180
+ window: gobj_full_name(gobj),
179
181
  title: chip_title ? chip_title : gobj_short_name(gobj),
180
182
  title_key: gobj_read_str_attr(gobj, "title") || "",
181
183
  title_kind_text: empty_string(gobj_read_str_attr(gobj, "title"))
@@ -215,7 +217,7 @@ function mt_destroy(gobj)
215
217
  {
216
218
  let manager = gobj_read_pointer_attr(gobj, "manager");
217
219
  if(manager) {
218
- gobj_send_event(manager, "EV_UNREGISTER_WINDOW", {window: gobj}, gobj);
220
+ gobj_send_event(manager, "EV_UNREGISTER_WINDOW", {window: gobj_full_name(gobj)}, gobj);
219
221
  }
220
222
 
221
223
  /* Retire the overlay-history entry, if this was a Back-dismissable
@@ -347,7 +349,7 @@ function build_default_header(gobj)
347
349
  if(!empty_string(title)) {
348
350
  items.push(
349
351
  ['span', {class: 'WINDOW_TITLE_KIND has-text-weight-semibold',
350
- i18n: title}, title]
352
+ i18n: title}, text_node(title)]
351
353
  );
352
354
  }
353
355
 
@@ -415,7 +417,7 @@ function do_minimize(gobj)
415
417
  log_error(`${gobj_short_name(gobj)}: minimize without a window manager`);
416
418
  return;
417
419
  }
418
- gobj_send_event(manager, "EV_MINIMIZE_WINDOW", {window: gobj}, gobj);
420
+ gobj_send_event(manager, "EV_MINIMIZE_WINDOW", {window: gobj_full_name(gobj)}, gobj);
419
421
  }
420
422
 
421
423
  /************************************************************
@@ -553,7 +555,7 @@ function build_ui(gobj)
553
555
  'aria-label': t('minimize'), 'data-i18n-aria-label': 'minimize',
554
556
  style: (gobj_read_bool_attr(gobj, "showMin") &&
555
557
  gobj_read_pointer_attr(gobj, "manager")) ? '' : 'display:none;',
556
- }, WC_MIN, {
558
+ }, html_markup(WC_MIN), {
557
559
  click: (evt) => {
558
560
  evt.stopPropagation();
559
561
  do_minimize(gobj);
@@ -567,7 +569,7 @@ function build_ui(gobj)
567
569
  title: t('maximize'), 'data-i18n-title': 'maximize',
568
570
  'aria-label': t('maximize'), 'data-i18n-aria-label': 'maximize',
569
571
  style: gobj_read_bool_attr(gobj, "showMax") ? '' : 'display:none;',
570
- }, WC_MAX, {
572
+ }, html_markup(WC_MAX), {
571
573
  click: (evt) => {
572
574
  evt.stopPropagation();
573
575
  toggle(gobj);
@@ -580,7 +582,7 @@ function build_ui(gobj)
580
582
  class: 'WINDOW_CLOSE yui-wc wc-close', type: 'button',
581
583
  title: t('close'), 'data-i18n-title': 'close',
582
584
  'aria-label': t('close'), 'data-i18n-aria-label': 'close',
583
- }, WC_CLOSE, {
585
+ }, html_markup(WC_CLOSE), {
584
586
  click: (evt) => {
585
587
  evt.stopPropagation();
586
588
  gobj_send_event(gobj, "EV_CLOSE_WINDOW", {}, gobj);
@@ -672,7 +674,7 @@ function build_ui(gobj)
672
674
  "box-sizing": "border-box",
673
675
  }
674
676
  }, [
675
- ['span', {style: 'display:inline-block;height:1.4em; width:1.4em;'}, '<svg viewBox="0 0 500 500"><path d="m427.87 493.69a33.778 33.78 0 0 1-23.882-57.661l33.778-33.78a33.799 33.8 0 0 1 47.83 47.763l-33.778 33.78a33.778 33.78 0 0 1-23.882 9.8976zm-190.44 0a33.778 33.78 0 0 1-23.882-57.661l224.22-224.23a33.799 33.8 0 0 1 47.83 47.763l-224.22 224.23a33.778 33.78 0 0 1-23.882 9.8976zm-197.26 0a33.778 33.78 0 0 1-23.882-57.661l421.46-421.47a33.786 33.786 0 1 1 47.797 47.763l-421.49 421.47a33.778 33.78 0 0 1-23.882 9.8976z" fill="var(--bulma-text)" stroke-width="33.78"/></svg>']
677
+ ['span', {style: 'display:inline-block;height:1.4em; width:1.4em;'}, html_markup('<svg viewBox="0 0 500 500"><path d="m427.87 493.69a33.778 33.78 0 0 1-23.882-57.661l33.778-33.78a33.799 33.8 0 0 1 47.83 47.763l-33.778 33.78a33.778 33.78 0 0 1-23.882 9.8976zm-190.44 0a33.778 33.78 0 0 1-23.882-57.661l224.22-224.23a33.799 33.8 0 0 1 47.83 47.763l-224.22 224.23a33.778 33.78 0 0 1-23.882 9.8976zm-197.26 0a33.778 33.78 0 0 1-23.882-57.661l421.46-421.47a33.786 33.786 0 1 1 47.797 47.763l-421.49 421.47a33.778 33.78 0 0 1-23.882 9.8976z" fill="var(--bulma-text)" stroke-width="33.78"/></svg>')]
676
678
 
677
679
  ], {
678
680
  pointerdown: (evt) => {
@@ -706,7 +708,7 @@ function build_ui(gobj)
706
708
  {
707
709
  style: 'display:inline-block;height:1.4em; width:1.4em;'
708
710
  },
709
- '<svg viewBox="0 0 500 500"><path d="m427.87 493.69a33.778 33.78 0 0 1-23.882-57.661l33.778-33.78a33.799 33.8 0 0 1 47.83 47.763l-33.778 33.78a33.778 33.78 0 0 1-23.882 9.8976zm-190.44 0a33.778 33.78 0 0 1-23.882-57.661l224.22-224.23a33.799 33.8 0 0 1 47.83 47.763l-224.22 224.23a33.778 33.78 0 0 1-23.882 9.8976zm-197.26 0a33.778 33.78 0 0 1-23.882-57.661l421.46-421.47a33.786 33.786 0 1 1 47.797 47.763l-421.49 421.47a33.778 33.78 0 0 1-23.882 9.8976z" fill="var(--bulma-text)" stroke-width="33.78"/></svg>'
711
+ html_markup('<svg viewBox="0 0 500 500"><path d="m427.87 493.69a33.778 33.78 0 0 1-23.882-57.661l33.778-33.78a33.799 33.8 0 0 1 47.83 47.763l-33.778 33.78a33.778 33.78 0 0 1-23.882 9.8976zm-190.44 0a33.778 33.78 0 0 1-23.882-57.661l224.22-224.23a33.799 33.8 0 0 1 47.83 47.763l-224.22 224.23a33.778 33.78 0 0 1-23.882 9.8976zm-197.26 0a33.778 33.78 0 0 1-23.882-57.661l421.46-421.47a33.786 33.786 0 1 1 47.797 47.763l-421.49 421.47a33.778 33.78 0 0 1-23.882 9.8976z" fill="var(--bulma-text)" stroke-width="33.78"/></svg>')
710
712
  ]
711
713
 
712
714
  ], {
@@ -1240,7 +1242,7 @@ function ac_show(gobj, event, kw, src)
1240
1242
  * moved to the top of its layer. */
1241
1243
  let manager = gobj_read_pointer_attr(gobj, "manager");
1242
1244
  if(manager) {
1243
- gobj_send_event(manager, "EV_FOCUS_WINDOW", {window: gobj}, gobj);
1245
+ gobj_send_event(manager, "EV_FOCUS_WINDOW", {window: gobj_full_name(gobj)}, gobj);
1244
1246
  return 0;
1245
1247
  }
1246
1248
  let $container = gobj_read_attr(gobj, "$container");
@@ -35,6 +35,10 @@ import {
35
35
  data_type_t,
36
36
  gclass_create,
37
37
  log_error,
38
+ log_warning,
39
+ is_gobj,
40
+ gobj_full_name,
41
+ gobj_short_name,
38
42
  gobj_read_pointer_attr,
39
43
  gobj_subscribe_event,
40
44
  gobj_send_event,
@@ -42,6 +46,7 @@ import {
42
46
  gobj_write_attr,
43
47
  gobj_read_attr,
44
48
  gobj_name,
49
+ html_markup,
45
50
  } from "@yuneta/gobj-js";
46
51
 
47
52
  import {t} from "i18next";
@@ -342,6 +347,38 @@ function chip_lead(icon)
342
347
  /************************************************************
343
348
  * Find a registry entry by its window gobj.
344
349
  ************************************************************/
350
+ /************************************************************
351
+ * The window an event is about. A kw is plain json (the machine
352
+ * trace dumps it), so the window travels in it as its FULL NAME,
353
+ * which the trace can print, and the gobj is the event's src --
354
+ * every sender is the window itself. Up to 7.26.9 the kw carried
355
+ * the gobj; that is still taken, with a warning, for this release.
356
+ ************************************************************/
357
+ let warned_gobj_in_kw = false;
358
+
359
+ function window_of(gobj, event, kw, src)
360
+ {
361
+ let w = kw && kw.window;
362
+ if(is_gobj(w)) {
363
+ if(!warned_gobj_in_kw) {
364
+ warned_gobj_in_kw = true;
365
+ log_warning(
366
+ `${gobj_short_name(gobj)}: ${event} carries the window gobj ` +
367
+ `in its kw: send {window: gobj_full_name(window)} from the window`
368
+ );
369
+ }
370
+ return w;
371
+ }
372
+ if(!is_gobj(src) || gobj_full_name(src) !== w) {
373
+ log_error(
374
+ `${gobj_short_name(gobj)}: ${event}: window '${w}' is not the ` +
375
+ `src of the event (${is_gobj(src) ? gobj_full_name(src) : String(src)})`
376
+ );
377
+ return null;
378
+ }
379
+ return src;
380
+ }
381
+
345
382
  function find_entry(priv, win)
346
383
  {
347
384
  for(let e of priv.windows) {
@@ -457,8 +494,11 @@ function ac_register_window(gobj, event, kw, src)
457
494
  {
458
495
  let priv = gobj.priv;
459
496
 
460
- let win = kw.window;
461
- if(!win || find_entry(priv, win)) {
497
+ let win = window_of(gobj, event, kw, src);
498
+ if(!win) {
499
+ return -1; // Error already logged
500
+ }
501
+ if(find_entry(priv, win)) {
462
502
  return 0;
463
503
  }
464
504
 
@@ -501,7 +541,7 @@ function ac_register_window(gobj, event, kw, src)
501
541
  ['span', {class: 'yui-dock-label'}, label_items],
502
542
  ['button', {class: 'yui-dock-close', type: 'button',
503
543
  title: t('close'), 'data-i18n-title': 'close',
504
- 'aria-label': t('close'), 'data-i18n-aria-label': 'close'}, WC_X, {
544
+ 'aria-label': t('close'), 'data-i18n-aria-label': 'close'}, html_markup(WC_X), {
505
545
  click: (evt) => {
506
546
  evt.stopPropagation();
507
547
  gobj_send_event(entry.gobj, "EV_CLOSE_WINDOW", {}, gobj);
@@ -547,7 +587,11 @@ function ac_unregister_window(gobj, event, kw, src)
547
587
  {
548
588
  let priv = gobj.priv;
549
589
 
550
- let entry = find_entry(priv, kw.window);
590
+ let win = window_of(gobj, event, kw, src);
591
+ if(!win) {
592
+ return -1; // Error already logged
593
+ }
594
+ let entry = find_entry(priv, win);
551
595
  if(!entry) {
552
596
  return 0;
553
597
  }
@@ -564,7 +608,11 @@ function ac_unregister_window(gobj, event, kw, src)
564
608
  ************************************************************/
565
609
  function ac_minimize_window(gobj, event, kw, src)
566
610
  {
567
- let entry = find_entry(gobj.priv, kw.window);
611
+ let win = window_of(gobj, event, kw, src);
612
+ if(!win) {
613
+ return -1; // Error already logged
614
+ }
615
+ let entry = find_entry(gobj.priv, win);
568
616
  if(entry) {
569
617
  minimize_entry(gobj, entry);
570
618
  }
@@ -576,7 +624,11 @@ function ac_minimize_window(gobj, event, kw, src)
576
624
  ************************************************************/
577
625
  function ac_focus_window(gobj, event, kw, src)
578
626
  {
579
- let entry = find_entry(gobj.priv, kw.window);
627
+ let win = window_of(gobj, event, kw, src);
628
+ if(!win) {
629
+ return -1; // Error already logged
630
+ }
631
+ let entry = find_entry(gobj.priv, win);
580
632
  if(entry) {
581
633
  focus_entry(gobj, entry);
582
634
  }
@@ -64,11 +64,11 @@ function plan_toolbar(wanted)
64
64
  }
65
65
  }
66
66
 
67
- /* Con un solo grupo, repartir con `space-between` deja el boton
68
- * pegado a un borde y el hueco entero al otro lado: un dialogo de
69
- * una accion se ve mejor centrado. Lo decide aqui y no el CSS de
70
- * quien llama, porque la clase que lo reparte es un helper de Bulma
71
- * y esos llevan `!important`: una regla de app no puede ganarles. */
67
+ /* With one group only, `space-between` puts the button against one
68
+ * edge and the whole gap on the other side: a dialog of one action
69
+ * looks better centred. It is decided here and not in the caller's
70
+ * CSS, because the class that spreads them is a Bulma helper, and
71
+ * those carry `!important`: an app rule cannot win over them. */
72
72
  const single_group = (left.length === 0) !== (right.length === 0);
73
73
 
74
74
  return {left, right, unknown, single_group};
@@ -0,0 +1,112 @@
1
+ /***********************************************************************
2
+ * map_stop_windows.wiring.test.js
3
+ *
4
+ * C_YUI_MAP opens one C_YUI_WINDOW per marker clicked, as its own
5
+ * child. A C_YUI_WINDOW has no mt_stop: stopping the map with the
6
+ * framework's gobj_stop_children() left each one on screen, holding
7
+ * its service name, so the next click on that marker found the old
8
+ * window. mt_stop destroys them.
9
+ *
10
+ * maplibre is replaced by a stand-in: the test is about the gobjs,
11
+ * not about a map, and node has no WebGL.
12
+ *
13
+ * Copyright (c) 2026, ArtGins.
14
+ * All Rights Reserved.
15
+ ***********************************************************************/
16
+ import {describe, test, expect, beforeAll, vi} from "vitest";
17
+ import {install_dom_double} from "../test/dom_double.js";
18
+
19
+ install_dom_double();
20
+
21
+ vi.mock("maplibre-gl", () => {
22
+ class Map {
23
+ on() {
24
+ }
25
+ addControl() {
26
+ }
27
+ getCanvasContainer() {
28
+ return {querySelector: () => null};
29
+ }
30
+ remove() {
31
+ }
32
+ }
33
+ class NavigationControl {
34
+ }
35
+ class GeolocateControl {
36
+ }
37
+ class Popup {
38
+ }
39
+ return {Map, NavigationControl, GeolocateControl, Popup};
40
+ });
41
+
42
+ const {
43
+ SDATA, SDATA_END, data_type_t, gclass_create,
44
+ gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
45
+ gobj_start, gobj_stop, gobj_find_service, gobj_is_destroying, gobj_send_event,
46
+ set_log_callback,
47
+ } = await import("@yuneta/gobj-js");
48
+ const {register_c_yui_window} = await import("./c_yui_window.js");
49
+ const {register_c_yui_map} = await import("./c_yui_map.js");
50
+
51
+ const logged = [];
52
+ let yuno = null;
53
+
54
+ beforeAll(async () => {
55
+ const i18next = (await import("i18next")).default;
56
+ await i18next.init({lng: "en", resources: {}});
57
+ gobj_start_up(null, null, null, null, null, null, null);
58
+ set_log_callback((level, msg) => {
59
+ logged.push({level: String(level), msg: String(msg)});
60
+ });
61
+ gclass_create("C_TEST_MAP_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
62
+ gclass_create(
63
+ "C_TEST_MAP_DEVICE", [], [["ST_IDLE", []]], {}, 0,
64
+ [SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "What its window shows"), SDATA_END()],
65
+ {}, 0, 0, 0, 0
66
+ );
67
+ register_c_yui_window();
68
+ register_c_yui_map();
69
+ yuno = gobj_create_yuno("map_yuno", "C_TEST_MAP_HOST", {});
70
+ gobj_start(yuno);
71
+ });
72
+
73
+ function errors()
74
+ {
75
+ return logged.filter((l) => l.level === "error").map((l) => l.msg);
76
+ }
77
+
78
+ describe("C_YUI_MAP stopped with marker windows open", () => {
79
+ test("destroys them, so their service names are free again", () => {
80
+ const host = gobj_create("map_host", "C_TEST_MAP_HOST", {}, yuno);
81
+ gobj_start(host);
82
+ const device = gobj_create_service("dev1", "C_TEST_MAP_DEVICE",
83
+ {$container: document.createElement("div")}, host);
84
+ gobj_start(device);
85
+ const map = gobj_create("map1", "C_YUI_MAP",
86
+ {$map: document.createElement("div")}, host);
87
+ gobj_start(map);
88
+ logged.length = 0;
89
+
90
+ gobj_send_marker_click(map, "dev1");
91
+ const win = gobj_find_service("window-map-dev1", false);
92
+ expect(win).toBeTruthy();
93
+
94
+ gobj_stop(map);
95
+ expect(gobj_is_destroying(win)).toBe(true);
96
+ expect(gobj_find_service("window-map-dev1", false)).toBe(null);
97
+
98
+ /* Started again, the marker opens a NEW window. */
99
+ gobj_start(map);
100
+ gobj_send_marker_click(map, "dev1");
101
+ const again = gobj_find_service("window-map-dev1", false);
102
+ expect(again).toBeTruthy();
103
+ expect(again).not.toBe(win);
104
+ expect(errors()).toEqual([]);
105
+ });
106
+ });
107
+
108
+ /* As the marker's click handler sends it. */
109
+ function gobj_send_marker_click(map, service_name)
110
+ {
111
+ return gobj_send_event(map, "EV_MARKER_CLICKED", {gobj_service_name: service_name}, map);
112
+ }
@@ -0,0 +1,212 @@
1
+ /***********************************************************************
2
+ * overlay_marker_after_back.wiring.test.js
3
+ *
4
+ * An overlay registered while a history.back() of the shell is
5
+ * still in flight. The common case: a floating window asks about
6
+ * unsaved changes on Back, and the user answers with a BUTTON
7
+ * (Cancel). The question's close calls history.back() to retire its
8
+ * marker -- asynchronous -- and in the same turn the window takes
9
+ * its entry back with pushState, which is synchronous. The marker
10
+ * landed before the traversal, the traversal then ran FROM it, and
11
+ * the window's marker was left orphaned ahead of the question's
12
+ * dead one.
13
+ *
14
+ * The history here is a model of a browser's session history: a
15
+ * list and an index, pushState truncating what is ahead, and
16
+ * back() traversing on a later task, from whatever entry is current
17
+ * THEN.
18
+ *
19
+ * Copyright (c) 2026, ArtGins.
20
+ * All Rights Reserved.
21
+ ***********************************************************************/
22
+ import {describe, test, expect, beforeAll, beforeEach} from "vitest";
23
+ import {install_dom_double} from "../test/dom_double.js";
24
+
25
+ install_dom_double();
26
+
27
+ const {
28
+ SDATA_END, gclass_create,
29
+ gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
30
+ gobj_start, gobj_read_attr, gobj_is_destroying,
31
+ set_log_callback,
32
+ } = await import("@yuneta/gobj-js");
33
+ const {register_c_yui_shell} = await import("./c_yui_shell.js");
34
+ const {register_c_yui_window} = await import("./c_yui_window.js");
35
+
36
+ const logged = [];
37
+ let veto = true;
38
+ let warning = null;
39
+ let yuno = null;
40
+
41
+ /* The session history of one tab. */
42
+ const session = {entries: [{state: null}], index: 0};
43
+
44
+ function install_history_model()
45
+ {
46
+ session.entries = [{state: null}];
47
+ session.index = 0;
48
+ window.history = {
49
+ get state() {
50
+ return session.entries[session.index].state;
51
+ },
52
+ get length() {
53
+ return session.entries.length;
54
+ },
55
+ pushState(state) {
56
+ session.entries.splice(session.index + 1);
57
+ session.entries.push({state: state});
58
+ session.index++;
59
+ },
60
+ replaceState(state) {
61
+ session.entries[session.index] = {state: state};
62
+ },
63
+ back() {
64
+ setTimeout(() => {
65
+ if(session.index > 0) {
66
+ session.index--;
67
+ fire_popstate();
68
+ }
69
+ }, 0);
70
+ },
71
+ forward() {
72
+ },
73
+ go() {
74
+ }
75
+ };
76
+ }
77
+
78
+ function fire_popstate()
79
+ {
80
+ const ev = new Event("popstate");
81
+ ev.state = window.history.state;
82
+ window.dispatchEvent(ev);
83
+ }
84
+
85
+ /* The user's Back: the browser's own traversal. */
86
+ function user_back()
87
+ {
88
+ session.index--;
89
+ fire_popstate();
90
+ }
91
+
92
+ function next_task()
93
+ {
94
+ return new Promise(resolve => setTimeout(resolve, 0));
95
+ }
96
+
97
+ beforeAll(async () => {
98
+ const i18next = (await import("i18next")).default;
99
+ await i18next.init({lng: "en", resources: {}});
100
+ gobj_start_up(null, null, null, null, null, null, null);
101
+ set_log_callback((level, msg) => {
102
+ logged.push({level: String(level), msg: String(msg)});
103
+ });
104
+ gclass_create("C_TEST_MARKER_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
105
+ gclass_create(
106
+ "C_TEST_MARKER_APP",
107
+ [["EV_WINDOW_TO_CLOSE", 0]],
108
+ [["ST_IDLE", [
109
+ ["EV_WINDOW_TO_CLOSE", (gobj, event, kw) => {
110
+ kw.abort_close = veto;
111
+ if(warning) {
112
+ kw.warning = warning;
113
+ }
114
+ return 0;
115
+ }, null]
116
+ ]]],
117
+ {}, 0, [SDATA_END()], {}, 0, 0, 0, 0
118
+ );
119
+ register_c_yui_shell();
120
+ register_c_yui_window();
121
+ yuno = gobj_create_yuno("marker_yuno", "C_TEST_MARKER_HOST", {});
122
+ gobj_start(yuno);
123
+ });
124
+
125
+ beforeEach(() => {
126
+ logged.length = 0;
127
+ veto = true;
128
+ warning = null;
129
+ install_history_model();
130
+ });
131
+
132
+ function errors()
133
+ {
134
+ return logged.filter((l) => l.level === "error" || l.level === "warning").map((l) => l.msg);
135
+ }
136
+
137
+ describe("an overlay registered while a back() of ours is in flight", () => {
138
+ test("the window's marker lands where it belongs, and the next Back closes it", async () => {
139
+ const app = gobj_create("mapp", "C_TEST_MARKER_APP", {}, yuno);
140
+ gobj_start(app);
141
+ const shell = gobj_create("mshell", "C_YUI_SHELL",
142
+ {config: {shell: {}}, default_route: "/home", subscriber: app}, app);
143
+ gobj_start(shell);
144
+ logged.length = 0; /* the shell's own start: no route table here */
145
+ install_history_model();
146
+
147
+ const win = gobj_create_service("mwin", "C_YUI_WINDOW",
148
+ {subscriber: app, header: "x", body: ["div", {}, "body"]}, app);
149
+ gobj_start(win);
150
+ expect(session.entries.length).toBe(2);
151
+ warning = "unsaved changes";
152
+
153
+ /* Back: the window asks. */
154
+ user_back();
155
+ expect(gobj_is_destroying(win)).toBe(false);
156
+ const question = shell.priv.overlay_stack[0];
157
+ expect(question).toBeTruthy();
158
+ expect(window.history.state).toEqual({__yui_overlay__: question.id});
159
+
160
+ /* The user answers with the Cancel BUTTON, not with Back. */
161
+ const $cancel = document.querySelector('.CONFIRM_BTN[data-modal-button-value="cancel"]');
162
+ expect($cancel).toBeTruthy();
163
+ $cancel.click();
164
+ await next_task();
165
+ await next_task();
166
+
167
+ const entry = gobj_read_attr(win, "back_overlay");
168
+ expect(entry).toBeTruthy();
169
+ expect(shell.priv.overlay_stack).toEqual([entry]);
170
+ expect(shell.priv.expected_pops).toBe(0);
171
+ /* One route entry and the window's marker, current: nothing
172
+ * orphaned ahead, no dead question's marker under it. */
173
+ expect(session.entries.length).toBe(2);
174
+ expect(window.history.state).toEqual({__yui_overlay__: entry.id});
175
+
176
+ /* And the user's next Back is the window's, not swallowed. */
177
+ veto = false;
178
+ warning = null;
179
+ user_back();
180
+ expect(gobj_is_destroying(win)).toBe(true);
181
+ expect(shell.priv.overlay_stack).toEqual([]);
182
+ expect(errors()).toEqual([]);
183
+ });
184
+
185
+ test("an overlay closed before its marker was pushed leaves no marker", async () => {
186
+ const app = gobj_create("mapp2", "C_TEST_MARKER_APP", {}, yuno);
187
+ gobj_start(app);
188
+ const shell = gobj_create("mshell2", "C_YUI_SHELL",
189
+ {config: {shell: {}}, default_route: "/home", subscriber: app}, app);
190
+ gobj_start(shell);
191
+ logged.length = 0;
192
+ install_history_model();
193
+
194
+ const {yui_shell_register_overlay, yui_shell_overlay_dismissed} =
195
+ await import("./c_yui_shell.js");
196
+ const first = yui_shell_register_overlay(shell, () => {});
197
+ expect(session.entries.length).toBe(2);
198
+ yui_shell_overlay_dismissed(shell, first); // back() in flight
199
+ const second = yui_shell_register_overlay(shell, () => {});
200
+ expect(second.marker_pending).toBe(true);
201
+ yui_shell_overlay_dismissed(shell, second); // gone before its marker
202
+ await next_task();
203
+ await next_task();
204
+
205
+ expect(shell.priv.overlay_stack).toEqual([]);
206
+ expect(shell.priv.expected_pops).toBe(0);
207
+ expect(session.entries.length).toBe(2); // the dead first marker, ahead
208
+ expect(session.index).toBe(0);
209
+ expect(window.history.state).toBe(null);
210
+ expect(errors()).toEqual([]);
211
+ });
212
+ });
@@ -285,7 +285,7 @@ export function yui_shell_show_modal(shell, content, opts)
285
285
  ["span", {class: "MODAL_TITLE yui-dialog-title"},
286
286
  (title_prefix ? [["span", {class: "MODAL_TITLE_PREFIX"}, text_node(title_prefix)]] : [])
287
287
  .concat(title
288
- ? [["span", {class: "MODAL_TITLE_KIND", i18n: title}, title]]
288
+ ? [["span", {class: "MODAL_TITLE_KIND", i18n: title}, text_node(title)]]
289
289
  : [])],
290
290
  ["button", {class: "MODAL_CLOSE yui-dialog-x", type: "button", title: t("close"), "data-i18n-title": "close",
291
291
  "aria-label": t("close"), "data-i18n-aria-label": "close"},
@@ -527,7 +527,7 @@ function build_dialog(shell, message, buttons, opts)
527
527
  if(!empty_string(title)) {
528
528
  $card_children.push(
529
529
  ["p", {class: "CONFIRM_TITLE yui-confirm-title has-text-centered",
530
- i18n: title}, title]
530
+ i18n: title}, text_node(title)]
531
531
  );
532
532
  }
533
533
  $card_children.push(