@yuneta/gobj-ui 7.26.10 → 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.
package/src/c_yui_form.js CHANGED
@@ -92,7 +92,7 @@ import "./tabulator.css";
92
92
  import {is_time_field} from "./json_view_helpers.js";
93
93
  import {date_to_datetime_local, datetime_local_to_epoch} from "./form_time_value.js";
94
94
  import {parse_json_field, json_editor_value} from "./form_json_field.js";
95
- import {text_node, text_title_formatter} from "./yui_text.js";
95
+ import {text_node, text_title_formatter, text_list_item_formatter} from "./yui_text.js";
96
96
  import { TabulatorFull as Tabulator } from "tabulator-tables"; // Import Full Tabulator JS
97
97
  // import { Tabulator } from "tabulator-tables"; // Import light Tabulator JS
98
98
 
@@ -2325,6 +2325,7 @@ function template2columns(gobj, columns, template, sub_elements)
2325
2325
  case "enum":
2326
2326
  column.editor = "list";
2327
2327
  column.editorParams = {
2328
+ itemFormatter: text_list_item_formatter // schema data
2328
2329
  };
2329
2330
  switch(field_desc.real_type) {
2330
2331
  case "string": // TODO review types
@@ -462,7 +462,7 @@ function render_raw(gobj)
462
462
  if(dump.error) {
463
463
  children.push(
464
464
  ['div', {class: 'GCLASS_RAW_ERROR has-text-danger is-size-7 p-2'},
465
- dump.error]);
465
+ text_node(dump.error)]); // the backend's words
466
466
  }
467
467
 
468
468
  let $body = createElement2(['div', {class: 'GCLASS_RAW_WRAP'}, children]);
@@ -819,14 +819,14 @@ function build_methods(model)
819
819
  if(model.methods.length) {
820
820
  blocks.push(['div', {class: 'GCLASS_CHIPS'},
821
821
  model.methods.map((m) =>
822
- ['span', row_attrs(m, {class: 'GCLASS_CHIP GCLASS_METHOD'}), m])]);
822
+ ['span', row_attrs(m, {class: 'GCLASS_CHIP GCLASS_METHOD'}), text_node(m)])]);
823
823
  }
824
824
  if(model.internal_methods.length) {
825
825
  blocks.push(['div', {class: 'GCLASS_SUBTITLE', i18n: 'internal methods'},
826
826
  t("internal methods")]);
827
827
  blocks.push(['div', {class: 'GCLASS_CHIPS'},
828
828
  model.internal_methods.map((m) =>
829
- ['span', row_attrs(m, {class: 'GCLASS_CHIP GCLASS_METHOD'}), m])]);
829
+ ['span', row_attrs(m, {class: 'GCLASS_CHIP GCLASS_METHOD'}), text_node(m)])]);
830
830
  }
831
831
 
832
832
  return ['div', {class: 'GCLASS_METHODS'}, blocks];
package/src/c_yui_json.js CHANGED
@@ -905,7 +905,7 @@ function push_collapsed_row(ctx, value, segments, depth, key, rows)
905
905
  'data-i18n': err.error}, t(err.error)]);
906
906
  } else if(err) {
907
907
  children.push(['span', {class: 'JSON_STUB_ERR has-text-danger is-size-7 ml-2'},
908
- String(err.error)]);
908
+ text_node(err.error)]); // the backend's words
909
909
  }
910
910
 
911
911
  let attrs = {
@@ -1989,7 +1989,7 @@ function select_input(name, value, options)
1989
1989
  let $options = options.map((option) => {
1990
1990
  return ["option", el_attrs({value: `${option}`,
1991
1991
  selected: `${option}` === `${value}` ? "selected" : undefined}),
1992
- `${option}`];
1992
+ text_node(`${option}`)]; // names from the schema: data
1993
1993
  });
1994
1994
 
1995
1995
  return ["div", {class: "select is-fullwidth"}, [
@@ -2002,7 +2002,7 @@ function textarea_input(name, value, rows, placeholder)
2002
2002
  return ["textarea", {class: "textarea", "data-name": name,
2003
2003
  rows: `${rows || 3}`,
2004
2004
  placeholder: placeholder || ""},
2005
- value === undefined || value === null ? "" : `${value}`];
2005
+ text_node(value === undefined || value === null ? "" : `${value}`)];
2006
2006
  }
2007
2007
 
2008
2008
  /***************************************************************
@@ -64,6 +64,7 @@ import {
64
64
  } from "./shell_toolbar_helpers.js";
65
65
 
66
66
  import { resolve_route, normalize_route } from "./route_resolver.js";
67
+ import { text_node } from "./yui_text.js";
67
68
  import { build_nav_map } from "./route_map_model.js";
68
69
  import {
69
70
  section_index_target,
@@ -155,6 +156,11 @@ let PRIVATE_DATA = {
155
156
  /* Count of history.back() calls WE issued to retire a dismissed
156
157
  * overlay; the popstate they trigger is expected and ignored. */
157
158
  expected_pops: 0,
159
+ /* The hash those history.back() calls were issued on: a back() of
160
+ * ours steps off a marker and lands on the SAME hash. A landing on
161
+ * another hash means the browser dropped ours (a navigation in the
162
+ * same turn cancels a queued traversal), see drop_expected_pops(). */
163
+ expected_pop_hash: "",
158
164
  /* Overlays registered while one of those history.back() calls is
159
165
  * still in flight: their marker is pushed once it has landed. */
160
166
  pending_markers: [],
@@ -260,6 +266,11 @@ function mt_start(gobj)
260
266
 
261
267
  if(gobj_read_attr(gobj, "use_hash")) {
262
268
  priv.hash_handler = () => {
269
+ let p = gobj.priv;
270
+ if(p && p.expected_pops > 0 &&
271
+ window.location.hash !== p.expected_pop_hash) {
272
+ drop_expected_pops(gobj); // a back() of ours never landed
273
+ }
263
274
  let route = hash_to_route(window.location.hash);
264
275
  if(!empty_string(route)) {
265
276
  navigate_to(gobj, route);
@@ -277,6 +288,12 @@ function mt_start(gobj)
277
288
  if(!p) {
278
289
  return;
279
290
  }
291
+ if(p.expected_pops > 0 &&
292
+ window.location.hash !== p.expected_pop_hash) {
293
+ /* Not the landing of ours: it was dropped. Whatever
294
+ * this traversal is, it is handled below as any other. */
295
+ drop_expected_pops(gobj);
296
+ }
280
297
  if(p.expected_pops > 0) {
281
298
  /* A history.back() we issued to retire a dismissed
282
299
  * overlay — the teardown already happened. */
@@ -397,6 +414,10 @@ function mt_stop(gobj)
397
414
  window.removeEventListener("popstate", priv.popstate_handler);
398
415
  priv.popstate_handler = null;
399
416
  }
417
+ /* Nothing listens for the landings any more. */
418
+ priv.expected_pops = 0;
419
+ priv.expected_pop_hash = "";
420
+ priv.pending_markers = [];
400
421
  if(priv.keydown_handler) {
401
422
  window.removeEventListener("keydown", priv.keydown_handler);
402
423
  priv.keydown_handler = null;
@@ -1787,7 +1808,7 @@ function build_toolbar_action_item(gobj, it)
1787
1808
  }
1788
1809
  if(!empty_string(it.name)) {
1789
1810
  children.push(["span", {class: "yui-toolbar-item-label", i18n: it.name},
1790
- it.name]);
1811
+ text_node(it.name)]);
1791
1812
  }
1792
1813
 
1793
1814
  let aria_key = it.aria_label || it.name || it.id || "";
@@ -2372,7 +2393,7 @@ function build_dropdown_row(gobj, sub, idx)
2372
2393
  }
2373
2394
  if(!empty_string(sub.name)) {
2374
2395
  children.push(["span", {class: "yui-toolbar-dropdown-label",
2375
- i18n: sub.name}, sub.name]);
2396
+ i18n: sub.name}, text_node(sub.name)]);
2376
2397
  }
2377
2398
  /* Trailing check for the ACTIVE option. The element is always
2378
2399
  * rendered and hidden by CSS when not selected, so every row keeps
@@ -2646,6 +2667,25 @@ function push_overlay_marker(gobj, entry)
2646
2667
  return true;
2647
2668
  }
2648
2669
 
2670
+ /* A history.back() of ours that the browser dropped: nothing will land
2671
+ * for it, so it must not wait for a landing and swallow the reader's
2672
+ * next Back. The overlays that waited for it get their markers now, on
2673
+ * the hash they are on. */
2674
+ function drop_expected_pops(gobj)
2675
+ {
2676
+ let priv = gobj.priv;
2677
+ if(!priv || priv.expected_pops === 0) {
2678
+ return;
2679
+ }
2680
+ log_warning(
2681
+ `C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did ` +
2682
+ `not land on '${priv.expected_pop_hash}' (now '${window.location.hash}'), dropped`
2683
+ );
2684
+ priv.expected_pops = 0;
2685
+ priv.expected_pop_hash = "";
2686
+ push_pending_markers(gobj);
2687
+ }
2688
+
2649
2689
  /* The history.back() calls of ours have all landed: push the markers of
2650
2690
  * the overlays registered meanwhile, in their order. One closed in the
2651
2691
  * meantime (dismissed, drained, or no longer on the stack) has none. */
@@ -2699,6 +2739,7 @@ function overlay_dismissed(gobj, entry)
2699
2739
  let st = window.history.state;
2700
2740
  if(st && st.__yui_overlay__ === entry.id) {
2701
2741
  priv.expected_pops++;
2742
+ priv.expected_pop_hash = window.location.hash;
2702
2743
  try {
2703
2744
  window.history.back();
2704
2745
  } catch(e) {
@@ -122,7 +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
+ import {text_node, text_list_item_formatter} from "./yui_text.js";
126
126
 
127
127
  /***************************************************************
128
128
  * Constants
@@ -1288,7 +1288,10 @@ function create_tabulator(gobj)
1288
1288
  break;
1289
1289
  case "enum":
1290
1290
  colDef.editor = "list";
1291
- colDef.editorParams = {values: field_desc.enum_list || []};
1291
+ colDef.editorParams = {
1292
+ values: field_desc.enum_list || [],
1293
+ itemFormatter: text_list_item_formatter // schema data
1294
+ };
1292
1295
  break;
1293
1296
  case "integer":
1294
1297
  case "real":
@@ -1339,7 +1342,8 @@ function create_tabulator(gobj)
1339
1342
  colDef.headerFilter = "list";
1340
1343
  colDef.headerFilterParams = {
1341
1344
  values: field_desc.enum_list || [],
1342
- clearable: true
1345
+ clearable: true,
1346
+ itemFormatter: text_list_item_formatter // schema data
1343
1347
  };
1344
1348
  break;
1345
1349
  case "fkey":
@@ -2080,7 +2084,7 @@ function icon_formatter(cell)
2080
2084
  return createElement2([
2081
2085
  "span",
2082
2086
  {class: "ICON_CELL_UNKNOWN is-size-7 yui-text-quiet", title: name},
2083
- name
2087
+ text_node(name) // data, not markup: it failed the name check
2084
2088
  ]);
2085
2089
  }
2086
2090
 
@@ -335,7 +335,8 @@ function build_default_header(gobj)
335
335
  let items = [];
336
336
  if(!empty_string(icon)) {
337
337
  if(icon.charAt(0) === '<') {
338
- 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)]);
339
340
  } else {
340
341
  items.push(['span', {class: 'icon'}, [['i', {class: icon}]]]);
341
342
  }
@@ -339,14 +339,12 @@ function chip_lead(icon)
339
339
  return ['span', {class: 'yui-dock-dot'}, ''];
340
340
  }
341
341
  if(icon.charAt(0) === '<') {
342
- 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)];
343
344
  }
344
345
  return ['span', {class: 'yui-dock-icon'}, [['i', {class: icon}]]];
345
346
  }
346
347
 
347
- /************************************************************
348
- * Find a registry entry by its window gobj.
349
- ************************************************************/
350
348
  /************************************************************
351
349
  * The window an event is about. A kw is plain json (the machine
352
350
  * trace dumps it), so the window travels in it as its FULL NAME,
@@ -367,6 +365,15 @@ function window_of(gobj, event, kw, src)
367
365
  `in its kw: send {window: gobj_full_name(window)} from the window`
368
366
  );
369
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
+ }
370
377
  return w;
371
378
  }
372
379
  if(!is_gobj(src) || gobj_full_name(src) !== w) {
@@ -379,6 +386,9 @@ function window_of(gobj, event, kw, src)
379
386
  return src;
380
387
  }
381
388
 
389
+ /************************************************************
390
+ * Find a registry entry by its window gobj.
391
+ ************************************************************/
382
392
  function find_entry(priv, win)
383
393
  {
384
394
  for(let e of priv.windows) {
@@ -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
  });
@@ -127,4 +127,52 @@ describe("EV_SHOW", () => {
127
127
  set_strings_are_text(false);
128
128
  }
129
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
+ });
130
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
+