@yuneta/gobj-ui 7.26.9 → 7.26.11

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.
@@ -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
@@ -333,7 +335,8 @@ function build_default_header(gobj)
333
335
  let items = [];
334
336
  if(!empty_string(icon)) {
335
337
  if(icon.charAt(0) === '<') {
336
- items.push(['span', {class: 'icon'}, icon]);
338
+ /* The `icon` attr is the app's own: inline svg is markup. */
339
+ items.push(['span', {class: 'icon'}, html_markup(icon)]);
337
340
  } else {
338
341
  items.push(['span', {class: 'icon'}, [['i', {class: icon}]]]);
339
342
  }
@@ -415,7 +418,7 @@ function do_minimize(gobj)
415
418
  log_error(`${gobj_short_name(gobj)}: minimize without a window manager`);
416
419
  return;
417
420
  }
418
- gobj_send_event(manager, "EV_MINIMIZE_WINDOW", {window: gobj}, gobj);
421
+ gobj_send_event(manager, "EV_MINIMIZE_WINDOW", {window: gobj_full_name(gobj)}, gobj);
419
422
  }
420
423
 
421
424
  /************************************************************
@@ -553,7 +556,7 @@ function build_ui(gobj)
553
556
  'aria-label': t('minimize'), 'data-i18n-aria-label': 'minimize',
554
557
  style: (gobj_read_bool_attr(gobj, "showMin") &&
555
558
  gobj_read_pointer_attr(gobj, "manager")) ? '' : 'display:none;',
556
- }, WC_MIN, {
559
+ }, html_markup(WC_MIN), {
557
560
  click: (evt) => {
558
561
  evt.stopPropagation();
559
562
  do_minimize(gobj);
@@ -567,7 +570,7 @@ function build_ui(gobj)
567
570
  title: t('maximize'), 'data-i18n-title': 'maximize',
568
571
  'aria-label': t('maximize'), 'data-i18n-aria-label': 'maximize',
569
572
  style: gobj_read_bool_attr(gobj, "showMax") ? '' : 'display:none;',
570
- }, WC_MAX, {
573
+ }, html_markup(WC_MAX), {
571
574
  click: (evt) => {
572
575
  evt.stopPropagation();
573
576
  toggle(gobj);
@@ -580,7 +583,7 @@ function build_ui(gobj)
580
583
  class: 'WINDOW_CLOSE yui-wc wc-close', type: 'button',
581
584
  title: t('close'), 'data-i18n-title': 'close',
582
585
  'aria-label': t('close'), 'data-i18n-aria-label': 'close',
583
- }, WC_CLOSE, {
586
+ }, html_markup(WC_CLOSE), {
584
587
  click: (evt) => {
585
588
  evt.stopPropagation();
586
589
  gobj_send_event(gobj, "EV_CLOSE_WINDOW", {}, gobj);
@@ -672,7 +675,7 @@ function build_ui(gobj)
672
675
  "box-sizing": "border-box",
673
676
  }
674
677
  }, [
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>']
678
+ ['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
679
 
677
680
  ], {
678
681
  pointerdown: (evt) => {
@@ -706,7 +709,7 @@ function build_ui(gobj)
706
709
  {
707
710
  style: 'display:inline-block;height:1.4em; width:1.4em;'
708
711
  },
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>'
712
+ 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
713
  ]
711
714
 
712
715
  ], {
@@ -1240,7 +1243,7 @@ function ac_show(gobj, event, kw, src)
1240
1243
  * moved to the top of its layer. */
1241
1244
  let manager = gobj_read_pointer_attr(gobj, "manager");
1242
1245
  if(manager) {
1243
- gobj_send_event(manager, "EV_FOCUS_WINDOW", {window: gobj}, gobj);
1246
+ gobj_send_event(manager, "EV_FOCUS_WINDOW", {window: gobj_full_name(gobj)}, gobj);
1244
1247
  return 0;
1245
1248
  }
1246
1249
  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";
@@ -334,11 +339,53 @@ function chip_lead(icon)
334
339
  return ['span', {class: 'yui-dock-dot'}, ''];
335
340
  }
336
341
  if(icon.charAt(0) === '<') {
337
- return ['span', {class: 'yui-dock-icon'}, icon];
342
+ /* The window's `icon` attr, the app's own: inline svg is markup. */
343
+ return ['span', {class: 'yui-dock-icon'}, html_markup(icon)];
338
344
  }
339
345
  return ['span', {class: 'yui-dock-icon'}, [['i', {class: icon}]]];
340
346
  }
341
347
 
348
+ /************************************************************
349
+ * The window an event is about. A kw is plain json (the machine
350
+ * trace dumps it), so the window travels in it as its FULL NAME,
351
+ * which the trace can print, and the gobj is the event's src --
352
+ * every sender is the window itself. Up to 7.26.9 the kw carried
353
+ * the gobj; that is still taken, with a warning, for this release.
354
+ ************************************************************/
355
+ let warned_gobj_in_kw = false;
356
+
357
+ function window_of(gobj, event, kw, src)
358
+ {
359
+ let w = kw && kw.window;
360
+ if(is_gobj(w)) {
361
+ if(!warned_gobj_in_kw) {
362
+ warned_gobj_in_kw = true;
363
+ log_warning(
364
+ `${gobj_short_name(gobj)}: ${event} carries the window gobj ` +
365
+ `in its kw: send {window: gobj_full_name(window)} from the window`
366
+ );
367
+ }
368
+ if(w !== src) {
369
+ /* Only the window speaks for itself, in either form. */
370
+ log_error(
371
+ `${gobj_short_name(gobj)}: ${event}: window ` +
372
+ `'${gobj_full_name(w)}' is not the src of the event ` +
373
+ `(${is_gobj(src) ? gobj_full_name(src) : String(src)})`
374
+ );
375
+ return null;
376
+ }
377
+ return w;
378
+ }
379
+ if(!is_gobj(src) || gobj_full_name(src) !== w) {
380
+ log_error(
381
+ `${gobj_short_name(gobj)}: ${event}: window '${w}' is not the ` +
382
+ `src of the event (${is_gobj(src) ? gobj_full_name(src) : String(src)})`
383
+ );
384
+ return null;
385
+ }
386
+ return src;
387
+ }
388
+
342
389
  /************************************************************
343
390
  * Find a registry entry by its window gobj.
344
391
  ************************************************************/
@@ -457,8 +504,11 @@ function ac_register_window(gobj, event, kw, src)
457
504
  {
458
505
  let priv = gobj.priv;
459
506
 
460
- let win = kw.window;
461
- if(!win || find_entry(priv, win)) {
507
+ let win = window_of(gobj, event, kw, src);
508
+ if(!win) {
509
+ return -1; // Error already logged
510
+ }
511
+ if(find_entry(priv, win)) {
462
512
  return 0;
463
513
  }
464
514
 
@@ -501,7 +551,7 @@ function ac_register_window(gobj, event, kw, src)
501
551
  ['span', {class: 'yui-dock-label'}, label_items],
502
552
  ['button', {class: 'yui-dock-close', type: 'button',
503
553
  title: t('close'), 'data-i18n-title': 'close',
504
- 'aria-label': t('close'), 'data-i18n-aria-label': 'close'}, WC_X, {
554
+ 'aria-label': t('close'), 'data-i18n-aria-label': 'close'}, html_markup(WC_X), {
505
555
  click: (evt) => {
506
556
  evt.stopPropagation();
507
557
  gobj_send_event(entry.gobj, "EV_CLOSE_WINDOW", {}, gobj);
@@ -547,7 +597,11 @@ function ac_unregister_window(gobj, event, kw, src)
547
597
  {
548
598
  let priv = gobj.priv;
549
599
 
550
- let entry = find_entry(priv, kw.window);
600
+ let win = window_of(gobj, event, kw, src);
601
+ if(!win) {
602
+ return -1; // Error already logged
603
+ }
604
+ let entry = find_entry(priv, win);
551
605
  if(!entry) {
552
606
  return 0;
553
607
  }
@@ -564,7 +618,11 @@ function ac_unregister_window(gobj, event, kw, src)
564
618
  ************************************************************/
565
619
  function ac_minimize_window(gobj, event, kw, src)
566
620
  {
567
- let entry = find_entry(gobj.priv, kw.window);
621
+ let win = window_of(gobj, event, kw, src);
622
+ if(!win) {
623
+ return -1; // Error already logged
624
+ }
625
+ let entry = find_entry(gobj.priv, win);
568
626
  if(entry) {
569
627
  minimize_entry(gobj, entry);
570
628
  }
@@ -576,7 +634,11 @@ function ac_minimize_window(gobj, event, kw, src)
576
634
  ************************************************************/
577
635
  function ac_focus_window(gobj, event, kw, src)
578
636
  {
579
- let entry = find_entry(gobj.priv, kw.window);
637
+ let win = window_of(gobj, event, kw, src);
638
+ if(!win) {
639
+ return -1; // Error already logged
640
+ }
641
+ let entry = find_entry(gobj.priv, win);
580
642
  if(entry) {
581
643
  focus_entry(gobj, entry);
582
644
  }
@@ -209,4 +209,83 @@ describe("an overlay registered while a back() of ours is in flight", () => {
209
209
  expect(window.history.state).toBe(null);
210
210
  expect(errors()).toEqual([]);
211
211
  });
212
+
213
+ test("a user Back queued after ours is the user's: it closes the next overlay", async () => {
214
+ const app = gobj_create("mapp3", "C_TEST_MARKER_APP", {}, yuno);
215
+ gobj_start(app);
216
+ const shell = gobj_create("mshell3", "C_YUI_SHELL",
217
+ {config: {shell: {}}, default_route: "/home", subscriber: app}, app);
218
+ gobj_start(shell);
219
+ logged.length = 0;
220
+ install_history_model();
221
+
222
+ const {yui_shell_register_overlay, yui_shell_overlay_dismissed} =
223
+ await import("./c_yui_shell.js");
224
+ let closed_a = 0;
225
+ const a = yui_shell_register_overlay(shell, () => { closed_a++; });
226
+ const b = yui_shell_register_overlay(shell, () => {});
227
+ expect(session.entries.length).toBe(3);
228
+ yui_shell_overlay_dismissed(shell, b); // our back(), in flight
229
+ await next_task(); // ours lands first...
230
+ expect(shell.priv.expected_pops).toBe(0);
231
+ user_back(); // ... then the user's
232
+ expect(closed_a).toBe(1);
233
+ expect(shell.priv.overlay_stack).toEqual([]);
234
+ expect(errors()).toEqual([]);
235
+ expect(a).toBeTruthy();
236
+ });
237
+
238
+ test("a back() of ours that never lands does not swallow the next Back", async () => {
239
+ const app = gobj_create("mapp4", "C_TEST_MARKER_APP", {}, yuno);
240
+ gobj_start(app);
241
+ const shell = gobj_create("mshell4", "C_YUI_SHELL",
242
+ {config: {shell: {}}, default_route: "/home", subscriber: app}, app);
243
+ gobj_start(shell);
244
+ logged.length = 0;
245
+ install_history_model();
246
+ window.location.hash = "#/home";
247
+
248
+ const {yui_shell_register_overlay, yui_shell_overlay_dismissed} =
249
+ await import("./c_yui_shell.js");
250
+ const first = yui_shell_register_overlay(shell, () => {});
251
+ window.history.back = () => {}; // the browser drops it
252
+ yui_shell_overlay_dismissed(shell, first);
253
+ expect(shell.priv.expected_pops).toBe(1);
254
+ let closed = 0;
255
+ const second = yui_shell_register_overlay(shell, () => { closed++; },
256
+ {keep_on_navigate: true});
257
+ expect(second.marker_pending).toBe(true);
258
+
259
+ /* A navigation: the hash moves, our back() will never land. */
260
+ window.location.hash = "#/other";
261
+ window.dispatchEvent(new Event("hashchange"));
262
+ expect(shell.priv.expected_pops).toBe(0);
263
+ expect(second.marker_pending).toBe(false);
264
+ expect(window.history.state).toEqual({__yui_overlay__: second.id});
265
+
266
+ /* The next Back is the user's, and it closes the overlay. */
267
+ logged.length = 0;
268
+ user_back();
269
+ expect(closed).toBe(1);
270
+ expect(errors()).toEqual([]);
271
+ });
272
+
273
+ test("mt_stop forgets the landings it can no longer hear", async () => {
274
+ const app = gobj_create("mapp5", "C_TEST_MARKER_APP", {}, yuno);
275
+ gobj_start(app);
276
+ const shell = gobj_create("mshell5", "C_YUI_SHELL",
277
+ {config: {shell: {}}, default_route: "/home", subscriber: app}, app);
278
+ gobj_start(shell);
279
+ install_history_model();
280
+ const {yui_shell_register_overlay, yui_shell_overlay_dismissed} =
281
+ await import("./c_yui_shell.js");
282
+ const {gobj_stop} = await import("@yuneta/gobj-js");
283
+ const first = yui_shell_register_overlay(shell, () => {});
284
+ window.history.back = () => {};
285
+ yui_shell_overlay_dismissed(shell, first);
286
+ yui_shell_register_overlay(shell, () => {});
287
+ gobj_stop(shell);
288
+ expect(shell.priv.expected_pops).toBe(0);
289
+ expect(shell.priv.pending_markers).toEqual([]);
290
+ });
212
291
  });
@@ -22,8 +22,8 @@ if(typeof globalThis.matchMedia === "undefined") {
22
22
  const {
23
23
  SDATA_END, gclass_create,
24
24
  gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
25
- gobj_start, gobj_read_attr, gobj_send_event,
26
- set_log_callback,
25
+ gobj_start, gobj_read_attr, gobj_send_event, gobj_full_name,
26
+ set_log_callback, set_strings_are_text,
27
27
  } = await import("@yuneta/gobj-js");
28
28
  const {register_c_yui_window} = await import("./c_yui_window.js");
29
29
  const {register_c_yui_window_manager} = await import("./c_yui_window_manager.js");
@@ -73,11 +73,106 @@ describe("EV_SHOW", () => {
73
73
  gobj_start(w);
74
74
  const $w = gobj_read_attr(w, "$container");
75
75
 
76
- gobj_send_event(dock, "EV_MINIMIZE_WINDOW", {window: w}, w);
76
+ gobj_send_event(dock, "EV_MINIMIZE_WINDOW", {window: gobj_full_name(w)}, w);
77
77
  expect($w.style.getPropertyValue("display")).toBe("none");
78
78
 
79
79
  gobj_send_event(w, "EV_SHOW", {}, yuno);
80
80
  expect($w.style.getPropertyValue("display")).toBe("");
81
81
  expect(errors()).toEqual([]);
82
82
  });
83
+
84
+ test("the dock's events carry the window's NAME, plain json; the gobj is the src", () => {
85
+ const dock = gobj_create_service("name_dock", "C_YUI_WINDOW_MANAGER", {}, yuno);
86
+ gobj_start(dock);
87
+ const w = gobj_create_service("name_w", "C_YUI_WINDOW",
88
+ {header: "w", body: ["div", {}, "w"], manager: dock}, yuno);
89
+ gobj_start(w);
90
+ const $w = gobj_read_attr(w, "$container");
91
+
92
+ /* What the window itself sent to register is json. */
93
+ expect(dock.priv.windows.some((e) => e.gobj === w)).toBe(true);
94
+
95
+ /* A name that is not the src's is refused, loudly. */
96
+ logged.length = 0;
97
+ gobj_send_event(dock, "EV_MINIMIZE_WINDOW", {window: "someone^else"}, w);
98
+ expect($w.style.getPropertyValue("display")).toBe("");
99
+ expect(errors().some((m) => m.includes("is not the src"))).toBe(true);
100
+
101
+ /* The old form (the gobj in the kw) still works, with a warning. */
102
+ logged.length = 0;
103
+ gobj_send_event(dock, "EV_MINIMIZE_WINDOW", {window: w}, w);
104
+ expect($w.style.getPropertyValue("display")).toBe("none");
105
+ expect(errors()).toEqual([]);
106
+ expect(logged.some((l) => l.level === "warning" && l.msg.includes("gobj_full_name"))).toBe(true);
107
+ });
108
+
109
+ test("with plain strings as TEXT (set_strings_are_text) the controls are still svg", () => {
110
+ set_strings_are_text(true);
111
+ try {
112
+ logged.length = 0;
113
+ const dock = gobj_create_service("strict_dock", "C_YUI_WINDOW_MANAGER", {}, yuno);
114
+ gobj_start(dock);
115
+ const w = gobj_create_service("strict_w", "C_YUI_WINDOW",
116
+ {header: "w", body: ["div", {}, "w"], manager: dock}, yuno);
117
+ gobj_start(w);
118
+ const $w = gobj_read_attr(w, "$container");
119
+ for(const cls of ["wc-min", "wc-max", "wc-close"]) {
120
+ const $b = $w.querySelector(`.yui-wc.${cls}`);
121
+ expect($b, cls).not.toBe(null);
122
+ expect($b.textContent.includes("<svg"), cls).toBe(false);
123
+ expect($b.querySelector("svg"), cls).not.toBe(null);
124
+ }
125
+ expect(logged.some((l) => l.msg.includes("html_markup"))).toBe(false);
126
+ } finally {
127
+ set_strings_are_text(false);
128
+ }
129
+ });
130
+
131
+ test("only the window speaks for itself: a name or a gobj that is not the src is refused", () => {
132
+ const dock = gobj_create_service("src_dock", "C_YUI_WINDOW_MANAGER", {}, yuno);
133
+ gobj_start(dock);
134
+ const w = gobj_create_service("src_w", "C_YUI_WINDOW",
135
+ {header: "w", body: ["div", {}, "w"], manager: dock}, yuno);
136
+ gobj_start(w);
137
+ const other = gobj_create_service("src_other", "C_YUI_WINDOW",
138
+ {header: "o", body: ["div", {}, "o"]}, yuno);
139
+ gobj_start(other);
140
+ const $w = gobj_read_attr(w, "$container");
141
+ const n_windows = dock.priv.windows.length;
142
+
143
+ for(const ev of ["EV_REGISTER_WINDOW", "EV_FOCUS_WINDOW", "EV_UNREGISTER_WINDOW", "EV_MINIMIZE_WINDOW"]) {
144
+ /* w's name, sent by another gobj. */
145
+ logged.length = 0;
146
+ gobj_send_event(dock, ev, {window: gobj_full_name(w)}, other);
147
+ expect(errors().some((m) => m.includes("is not the src"))).toBe(true);
148
+ /* The OLD form (the gobj in the kw), sent by another gobj. */
149
+ logged.length = 0;
150
+ gobj_send_event(dock, ev, {window: w}, other);
151
+ expect(errors().some((m) => m.includes("is not the src"))).toBe(true);
152
+ }
153
+ expect(dock.priv.windows.length).toBe(n_windows); // nothing unregistered
154
+ expect(dock.priv.windows.some((e) => e.gobj === other)).toBe(false); // nothing registered
155
+ expect($w.style.getPropertyValue("display")).toBe(""); // nothing minimized
156
+ });
157
+
158
+ test("an inline-svg icon is the app's markup, in strict mode too", async () => {
159
+ const {set_strings_are_text} = await import("@yuneta/gobj-js");
160
+ set_strings_are_text(true);
161
+ try {
162
+ logged.length = 0;
163
+ const dock = gobj_create_service("icon_dock", "C_YUI_WINDOW_MANAGER", {}, yuno);
164
+ gobj_start(dock);
165
+ const svg = '<svg viewBox="0 0 8 8"><rect width="8" height="8"/></svg>';
166
+ const w = gobj_create_service("icon_w", "C_YUI_WINDOW",
167
+ {title: "w", icon: svg, body: ["div", {}, "w"], manager: dock}, yuno);
168
+ gobj_start(w);
169
+ const $w = gobj_read_attr(w, "$container");
170
+ expect($w.querySelector(".icon svg")).not.toBe(null);
171
+ const $dock = gobj_read_attr(dock, "$container");
172
+ expect($dock.querySelector(".yui-dock-icon svg")).not.toBe(null);
173
+ expect(logged.filter((l) => l.msg.includes("html_markup"))).toEqual([]);
174
+ } finally {
175
+ set_strings_are_text(false);
176
+ }
177
+ });
83
178
  });
package/src/yui_text.js CHANGED
@@ -41,3 +41,19 @@ export function text_title_formatter(cell)
41
41
  {
42
42
  return text_node(cell.getValue());
43
43
  }
44
+
45
+ /************************************************************
46
+ * A Tabulator `itemFormatter` for a `list` editor or header filter
47
+ * that shows each item's label as text.
48
+ *
49
+ * Tabulator appends what an itemFormatter returns only when it is an
50
+ * HTMLElement (a Text node would be innerHTML'd as "[object Text]"),
51
+ * and it puts a bare label in with innerHTML. A label taken from a
52
+ * schema (`enum_list`) is data, so it goes in a span, as text.
53
+ ************************************************************/
54
+ export function text_list_item_formatter(label)
55
+ {
56
+ const span = document.createElement("span");
57
+ span.textContent = (label === null || label === undefined) ? "" : String(label);
58
+ return span;
59
+ }
@@ -17,7 +17,7 @@ const {
17
17
  SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create,
18
18
  gobj_read_attr, set_log_callback
19
19
  } = await import("@yuneta/gobj-js");
20
- const {text_node, text_title_formatter} = await import("./yui_text.js");
20
+ const {text_node, text_title_formatter, text_list_item_formatter} = await import("./yui_text.js");
21
21
  const {register_c_yui_nav} = await import("./c_yui_nav.js");
22
22
  const {card_descriptor} = await import("./nav_cards_helpers.js");
23
23
 
@@ -65,3 +65,15 @@ describe("text_node()", () => {
65
65
  expect($c.querySelector(".yui-accordion-head").textContent).toBe(EVIL);
66
66
  });
67
67
  });
68
+
69
+ describe("text_list_item_formatter (Tabulator list editor / header filter)", () => {
70
+ test("returns an ELEMENT (Tabulator appends only an HTMLElement) holding the label as text", () => {
71
+ const EVIL = '<img src=x onerror="window.__pwned=1">';
72
+ const el = text_list_item_formatter(EVIL, EVIL, {}, null);
73
+ expect(el instanceof HTMLElement).toBe(true);
74
+ expect(el.querySelector("img")).toBe(null);
75
+ expect(el.textContent).toBe(EVIL);
76
+ expect(text_list_item_formatter(null).textContent).toBe("");
77
+ });
78
+ });
79
+