@yuneta/gobj-ui 7.26.42 → 7.26.43

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 (47) hide show
  1. package/README.md +227 -36
  2. package/dist/gobj-ui.cjs.js +768 -191
  3. package/dist/gobj-ui.es.js +768 -191
  4. package/package.json +1 -1
  5. package/scripts/validate-locales.mjs +355 -63
  6. package/src/c_yui_form.js +261 -154
  7. package/src/c_yui_node.js +51 -7
  8. package/src/c_yui_schema_editor.js +49 -3
  9. package/src/c_yui_shell.css +4 -1
  10. package/src/c_yui_shell.js +28 -2
  11. package/src/c_yui_window.js +373 -62
  12. package/src/c_yui_window_manager.js +74 -2
  13. package/src/escape_taken.js +58 -0
  14. package/src/form_close_asks_for_edits.wiring.test.js +6 -3
  15. package/src/form_json_editor_names.js +3 -1
  16. package/src/form_json_editor_names.wiring.test.js +8 -4
  17. package/src/form_json_expand.wiring.test.js +6 -3
  18. package/src/form_json_field.wiring.test.js +8 -4
  19. package/src/form_label_i18n.wiring.test.js +10 -5
  20. package/src/form_table_edits_ask.wiring.test.js +18 -8
  21. package/src/form_table_rearm.wiring.test.js +13 -5
  22. package/src/form_table_rows.wiring.test.js +489 -0
  23. package/src/form_table_validator.wiring.test.js +8 -4
  24. package/src/form_template_field.wiring.test.js +6 -3
  25. package/src/g6_long_press_clock.test.js +8 -3
  26. package/src/i18n_key_functions.js +63 -25
  27. package/src/i18n_key_functions.test.js +230 -8
  28. package/src/modal_guard_back.wiring.test.js +53 -0
  29. package/src/named_controls.wiring.test.js +53 -13
  30. package/src/node_nav_events.wiring.test.js +93 -1
  31. package/src/schema_editor_diagram_click.wiring.test.js +277 -0
  32. package/src/shell_dialog_names.wiring.test.js +149 -0
  33. package/src/shell_escape_taken.wiring.test.js +142 -0
  34. package/src/shell_focus_trap.js +30 -2
  35. package/src/shell_focus_trap.test.js +90 -6
  36. package/src/shell_modals.js +90 -19
  37. package/src/table_editor_name.wiring.test.js +10 -5
  38. package/src/treedb_column_title.wiring.test.js +8 -4
  39. package/src/treedb_graph_writes.wiring.test.js +6 -3
  40. package/src/treedb_json_drill.wiring.test.js +6 -3
  41. package/src/uplot_add_serie.test.js +6 -3
  42. package/src/uplot_ink.test.js +8 -4
  43. package/src/window_dialog.wiring.test.js +486 -0
  44. package/src/window_dock_band.wiring.test.js +189 -0
  45. package/src/window_rect_rounding.wiring.test.js +121 -0
  46. package/src/yui_tabulator_i18n.js +31 -1
  47. package/src/yui_tabulator_i18n.test.js +46 -0
@@ -3,6 +3,30 @@
3
3
  *
4
4
  * Window - position fixed
5
5
  *
6
+ * A window is a DIALOG for the keyboard and for a reader:
7
+ *
8
+ * - it says so (`role="dialog"`) and is named by its title
9
+ * (`aria-labelledby` on its two halves, the kind half carrying
10
+ * its key, so the name changes language with it);
11
+ * - when it starts in answer to the reader (a press, a key) it
12
+ * takes the focus (`focus`: an element, a selector, a number;
13
+ * by default the window itself, which is focusable with
14
+ * tabindex=-1) -- not one the app restores on its own at start
15
+ * up -- and when it goes it gives the focus back to where it
16
+ * came from, if the focus was in it;
17
+ * - Escape closes it (`keyboard`) the way its ✕ does, through
18
+ * EV_CLOSE_WINDOW, so EV_WINDOW_TO_CLOSE can still veto or
19
+ * ask; not an Escape that what it was typed in took first
20
+ * (escape_is_taken());
21
+ * - a `modal` one blocks the rest of the app: it hangs over a
22
+ * backdrop in the shell's dialog layer (above the dock, the
23
+ * drawer, every other window), a press outside it does
24
+ * nothing, Tab stays inside (activate_focus_trap_on(), the
25
+ * trap of the shell's dialogs), and it never goes to the dock.
26
+ *
27
+ * Up to 7.26.42 `focus`, `modal` and `keyboard` were declared and
28
+ * did nothing.
29
+ *
6
30
  * Copyright (c) 2025-2026, ArtGins.
7
31
  * All Rights Reserved.
8
32
  ***********************************************************************/
@@ -54,10 +78,13 @@ import {
54
78
  yui_shell_register_overlay,
55
79
  yui_shell_overlay_dismissed,
56
80
  yui_shell_window_layer,
81
+ yui_shell_modal_layer,
57
82
  yui_shell_raise_window,
58
83
  yui_shell_watch_changes,
59
84
  yui_shell_unwatch_changes,
60
85
  } from "./c_yui_shell.js";
86
+ import {activate_focus_trap_on, FOCUSABLE_SELECTOR} from "./shell_focus_trap.js";
87
+ import {escape_is_taken} from "./escape_taken.js";
61
88
 
62
89
  import "./c_yui_window.css";
63
90
  import {text_node} from "./yui_text.js";
@@ -80,6 +107,22 @@ const WC_CLOSE = '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 4 L12
80
107
  * full-screen sheet (no float / drag / resize). */
81
108
  const MOBILE_MAX = 768;
82
109
 
110
+ /* The band a FLOATING dock keeps at the top or the foot of the
111
+ * viewport (C_YUI_WINDOW_MANAGER publishes it on the root element).
112
+ * A window that fills the screen -- the sheet of a phone, a
113
+ * maximized one -- leaves it free: under the dock it lost its foot,
114
+ * or its ✕ at a top corner. */
115
+ const DOCK_INSET_TOP = "var(--yui-dock-inset-top, 0px)";
116
+ const DOCK_INSET_BOTTOM = "var(--yui-dock-inset-bottom, 0px)";
117
+
118
+ /* The z-index Bulma gives a `.modal` (--bulma-modal-z): a modal
119
+ * window and the shell's dialogs, in the same layer, stack in the
120
+ * order they opened in. */
121
+ const MODAL_WINDOW_Z = 40;
122
+
123
+ /* Unique ids for the title node a window is named by. */
124
+ let __title_seq__ = 0;
125
+
83
126
  /***************************************************************
84
127
  * Data
85
128
  ***************************************************************/
@@ -110,10 +153,9 @@ SDATA(data_type_t.DTP_STRING, "logical_class",0, "", "Logical UPPER_SNAKE
110
153
  SDATA(data_type_t.DTP_STRING, "title_prefix", 0, "", "Optional DATA half of the title (a topic/service/marker name), shown before `title` and never translated. Use it instead of composing `${name} · ${t(key)}` into `title`, which cannot re-translate"),
111
154
  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"),
112
155
  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"),
113
- // TODO declared, NOT implemented yet: focus, modal, keyboard (Escape does not close a window)
114
- SDATA(data_type_t.DTP_POINTER, "focus", 0, null, "NOT implemented yet: would bring focus to the element, a number or a selector"),
115
- SDATA(data_type_t.DTP_BOOLEAN, "modal", 0, false, "NOT implemented yet: would enable modal mode"),
116
- SDATA(data_type_t.DTP_BOOLEAN, "keyboard", 0, true, "NOT implemented yet: would close the window on ESC (Escape does nothing today)"),
156
+ SDATA(data_type_t.DTP_POINTER, "focus", 0, null, "What takes the focus when the window starts in answer to the reader (a press, a key; a window the app restores on its own leaves the focus in the page, a modal one takes it always): an element of the window, a CSS selector looked up in it, or a number (the n-th control of the body, from 0). Null: the window itself. The focus goes back where it came from when the window goes, if it was in the window"),
157
+ SDATA(data_type_t.DTP_BOOLEAN, "modal", 0, false, "Block the rest of the app while the window is open: a backdrop in the shell's dialog layer (above the dock, the drawer, every other window), a press outside does nothing, Tab stays inside, aria-modal. A modal window never goes to the dock: `manager` is ignored"),
158
+ SDATA(data_type_t.DTP_BOOLEAN, "keyboard", 0, true, "Escape closes the window the way its ✕ does (EV_WINDOW_TO_CLOSE can veto or ask), when the focus is in it -- not an Escape that what it was typed in took first: a handler that used it, a cell editor that closed with it, a textarea or a contenteditable"),
117
159
  SDATA(data_type_t.DTP_BOOLEAN, "back_dismissable", 0, true, "Browser Back closes this window (floating overlays only; ignored when it has a `manager`)"),
118
160
  SDATA(data_type_t.DTP_BOOLEAN, "keep_on_navigate", 0, false, "This window is a navigation PANEL: a route change does not close it"),
119
161
  SDATA(data_type_t.DTP_POINTER, "back_overlay", 0, null, "Internal: overlay-history entry (Back-button integration)"),
@@ -131,6 +173,14 @@ let PRIVATE_DATA = {
131
173
  placed_by_shell: false,
132
174
  /* The shell that holds this window's Back entry (`back_overlay`). */
133
175
  back_shell: null,
176
+ /* Where the focus was when the window started: it goes back
177
+ * there when the window goes. */
178
+ opener: null,
179
+ /* A modal window: the element that holds it over its backdrop
180
+ * (what is placed and removed instead of $container), and the
181
+ * release of its focus trap. */
182
+ $lock: null,
183
+ release_focus: null,
134
184
  };
135
185
 
136
186
  let __gclass__ = null;
@@ -161,6 +211,13 @@ function mt_create(gobj)
161
211
  let window_id = "window-" + clean_name(gobj_short_name(gobj));
162
212
  gobj_write_attr(gobj, "window_id", window_id);
163
213
 
214
+ /* A modal window blocks the dock too: minimized to it, it would
215
+ * leave its backdrop up and nothing to bring it back with. */
216
+ if(gobj_read_bool_attr(gobj, "modal") && gobj_read_pointer_attr(gobj, "manager")) {
217
+ log_warning(`${gobj_short_name(gobj)}: a modal window does not go to the dock: its manager is ignored`);
218
+ gobj_write_attr(gobj, "manager", null);
219
+ }
220
+
164
221
  /* Optional window manager (dock/taskbar): register, and raise/
165
222
  * highlight on any pointer press. Resolved BEFORE build_ui: minimize
166
223
  * means "send to the dock", so without a manager there is nowhere to
@@ -243,6 +300,44 @@ function mt_create(gobj)
243
300
  window.addEventListener("resize", on_win_resize);
244
301
  }
245
302
 
303
+ /***************************************************************
304
+ * Framework Method: Start
305
+ *
306
+ * The window takes the focus when it STARTS, not when it is
307
+ * created: a host fills the body between the two (the json pad,
308
+ * the frontend view), and `focus` may name what it put there.
309
+ *
310
+ * Only a window the READER opened takes it (opened_by_the_reader()).
311
+ * One the app opens on its own -- the Developer window restored at
312
+ * start up from the last session -- leaves the focus in the page:
313
+ * the first Tab of a keyboard reader landed in a window they had
314
+ * not opened. A modal window takes it all the same: nothing else
315
+ * can be used while it is up.
316
+ ***************************************************************/
317
+ function mt_start(gobj)
318
+ {
319
+ let priv = gobj.priv;
320
+
321
+ let $container = gobj_read_attr(gobj, "$container");
322
+ if(!$container) {
323
+ log_error(`${gobj_short_name(gobj)}: started without a container`);
324
+ return;
325
+ }
326
+
327
+ let active = document.activeElement;
328
+ if(active && active !== document.body && !$container.contains(active)) {
329
+ priv.opener = active;
330
+ }
331
+ let modal = gobj_read_bool_attr(gobj, "modal");
332
+ if(modal && !priv.release_focus) {
333
+ /* Saves the opener itself, and gives it back on release. */
334
+ priv.release_focus = activate_focus_trap_on($container);
335
+ }
336
+ if(modal || opened_by_the_reader()) {
337
+ focus_target(gobj, $container).focus();
338
+ }
339
+ }
340
+
246
341
  /***************************************************************
247
342
  * Framework Method: Destroy
248
343
  ***************************************************************/
@@ -250,10 +345,13 @@ function mt_destroy(gobj)
250
345
  {
251
346
  let priv = gobj.priv;
252
347
 
348
+ give_focus_back(gobj);
349
+
253
350
  yui_shell_unwatch_changes(gobj);
254
351
 
352
+ /* A dock destroyed first took this window's chip with it. */
255
353
  let manager = gobj_read_pointer_attr(gobj, "manager");
256
- if(manager) {
354
+ if(manager && !gobj_is_destroying(manager)) {
257
355
  gobj_send_event(manager, "EV_UNREGISTER_WINDOW", {window: gobj_full_name(gobj)}, gobj);
258
356
  }
259
357
 
@@ -309,9 +407,12 @@ function ensure_window_style()
309
407
  .yui-window-title .icon { flex: 0 0 auto; }
310
408
  .yui-window-title svg { width: 14px; height: 14px; display: block; }
311
409
  /* Separator between the data half and the translated kind half. CSS,
312
- * not a text node: createElement2 trims text nodes and eats the spaces. */
410
+ * not a text node: createElement2 trims text nodes and eats the spaces.
411
+ * Decorative ("/ ''"): the halves NAME the window, and a reader read
412
+ * the dot into the kind half ("#1 ·demo window"). */
313
413
  .WINDOW_TITLE_PREFIX + .WINDOW_TITLE_KIND::before {
314
414
  content: "·";
415
+ content: "·" / "";
315
416
  padding: 0 0.4em;
316
417
  color: var(--bulma-text-weak);
317
418
  }
@@ -325,6 +426,13 @@ function ensure_window_style()
325
426
  .yui-wc svg { width: 15px; height: 15px; display: block; }
326
427
  .yui-window-resize { color: var(--bulma-text-weak); opacity: 0.55; }
327
428
  .yui-window-resize:hover { opacity: 1; color: var(--bulma-text); }
429
+ /* A modal window over its backdrop: the backdrop of a Bulma .modal,
430
+ * which the shell's dialogs wear (its variable lives on .modal). */
431
+ .yui-window-lock { position: fixed; inset: 0; }
432
+ .yui-window-backdrop {
433
+ position: absolute; inset: 0;
434
+ background-color: hsla(var(--bulma-scheme-h), var(--bulma-scheme-s), var(--bulma-scheme-invert-l), 0.86);
435
+ }
328
436
  @media (max-width: ${MOBILE_MAX}px) {
329
437
  .C_YUI_WINDOW.is-mobile-sheet { border-radius: 0 !important; box-shadow: none !important; }
330
438
  .C_YUI_WINDOW.is-mobile-sheet .yui-window-resize { display: none !important; }
@@ -361,8 +469,15 @@ function ensure_window_style()
361
469
  * refresh_language() re-translates just that one. The separator is
362
470
  * CSS (::before), never a text node: createElement2 TRIMS text nodes
363
471
  * and would eat the spaces around it.
472
+ *
473
+ * The same halves NAME the window: aria-labelledby lists them
474
+ * (`<id>-prefix`, `<id>-kind`), so a reader joins them with a space
475
+ * and leaves out the CSS separator, and the kind half changes
476
+ * language. Under a `header` of the caller's the node is still
477
+ * built, `hidden` (is-sr-only, no icon): a header is a toolbar more
478
+ * often than a title, and the name of a dialog is its title.
364
479
  ************************************************************/
365
- function build_default_header(gobj)
480
+ function build_title_node(gobj, id, hidden)
366
481
  {
367
482
  let title = gobj_read_str_attr(gobj, "title");
368
483
  let prefix = gobj_read_str_attr(gobj, "title_prefix");
@@ -370,7 +485,7 @@ function build_default_header(gobj)
370
485
  return null;
371
486
  }
372
487
 
373
- let icon = gobj_read_str_attr(gobj, "icon");
488
+ let icon = hidden ? "" : gobj_read_str_attr(gobj, "icon");
374
489
  let items = [];
375
490
  if(!empty_string(icon)) {
376
491
  if(icon.charAt(0) === '<') {
@@ -382,19 +497,22 @@ function build_default_header(gobj)
382
497
  }
383
498
  if(!empty_string(prefix)) {
384
499
  items.push(
385
- ['span', {class: 'WINDOW_TITLE_PREFIX has-text-weight-semibold'},
500
+ ['span', {class: 'WINDOW_TITLE_PREFIX has-text-weight-semibold', id: `${id}-prefix`},
386
501
  text_node(prefix)] // data, not markup
387
502
  );
388
503
  }
389
504
  if(!empty_string(title)) {
390
505
  items.push(
391
- ['span', {class: 'WINDOW_TITLE_KIND has-text-weight-semibold',
506
+ ['span', {class: 'WINDOW_TITLE_KIND has-text-weight-semibold', id: `${id}-kind`,
392
507
  i18n: title}, text_node(title)]
393
508
  );
394
509
  }
395
510
 
396
511
  return createElement2(
397
- ['span', {class: 'WINDOW_TITLE yui-window-title icon-text ml-1'}, items]
512
+ ['span', {
513
+ id: id,
514
+ class: hidden ? 'WINDOW_TITLE is-sr-only' : 'WINDOW_TITLE yui-window-title icon-text ml-1'
515
+ }, items]
398
516
  );
399
517
  }
400
518
 
@@ -415,6 +533,142 @@ function composed_title(gobj)
415
533
  return empty_string(prefix) ? kind : prefix;
416
534
  }
417
535
 
536
+ /************************************************************
537
+ * Is the window opening in answer to the reader -- a press, a
538
+ * key (the browser's user activation)? Not one the app restores
539
+ * at start up. A browser that cannot say is taken at its word
540
+ * that the reader asked.
541
+ ************************************************************/
542
+ function opened_by_the_reader()
543
+ {
544
+ let ua = (typeof navigator !== "undefined") ? navigator.userActivation : null;
545
+ if(!ua) {
546
+ return true;
547
+ }
548
+ return !!ua.isActive;
549
+ }
550
+
551
+ /************************************************************
552
+ * What takes the focus when the window starts (`focus`): an
553
+ * element of the window, a selector looked up in it, or the
554
+ * n-th control of the body. Null, or one that names nothing
555
+ * (said): the window itself.
556
+ ************************************************************/
557
+ function focus_target(gobj, $container)
558
+ {
559
+ let focus = gobj_read_attr(gobj, "focus");
560
+ if(focus === null || focus === undefined) {
561
+ return $container;
562
+ }
563
+
564
+ let $target = null;
565
+ if(typeof focus === "number") {
566
+ let $body = $container.querySelector(".WINDOW_BODY");
567
+ let controls = $body ? $body.querySelectorAll(FOCUSABLE_SELECTOR) : [];
568
+ $target = controls[focus] || null;
569
+ } else if(typeof focus === "string") {
570
+ $target = $container.querySelector(focus);
571
+ } else if(focus && typeof focus.focus === "function" && $container.contains(focus)) {
572
+ $target = focus;
573
+ }
574
+
575
+ if(!$target) {
576
+ log_warning(`${gobj_short_name(gobj)}: focus '${String(focus)}' names nothing in the window: the window takes it`);
577
+ return $container;
578
+ }
579
+ return $target;
580
+ }
581
+
582
+ /************************************************************
583
+ * The window goes: the focus goes back where it came from --
584
+ * if it was in the window, or lost with what the window held
585
+ * (a child torn down first takes its focused element with
586
+ * it). A focus the reader has put elsewhere stays there. A
587
+ * modal window's trap gives it back itself.
588
+ ************************************************************/
589
+ function give_focus_back(gobj)
590
+ {
591
+ let priv = gobj.priv;
592
+
593
+ let opener = priv.opener;
594
+ priv.opener = null;
595
+
596
+ if(priv.release_focus) {
597
+ let release = priv.release_focus;
598
+ priv.release_focus = null;
599
+ release();
600
+ return;
601
+ }
602
+
603
+ let $container = gobj_read_attr(gobj, "$container");
604
+ let active = document.activeElement;
605
+ let lost = !active || active === document.body;
606
+ if(!lost && !($container && $container.contains(active))) {
607
+ return;
608
+ }
609
+ if(opener && opener.isConnected !== false && typeof opener.focus === "function") {
610
+ opener.focus();
611
+ }
612
+ }
613
+
614
+ /************************************************************
615
+ * A window that fills the screen -- the sheet of a phone, a
616
+ * maximized one -- fills it but for the band a floating dock
617
+ * keeps (DOCK_INSET_*). CSS, so the band moves with the dock
618
+ * and no one has to tell the window.
619
+ ************************************************************/
620
+ function fill_work_area($container)
621
+ {
622
+ let vw = window.innerWidth || document.documentElement.offsetWidth;
623
+ let vh = window.innerHeight || document.documentElement.offsetHeight;
624
+
625
+ $container.style.left = '0px';
626
+ $container.style.top = DOCK_INSET_TOP;
627
+ $container.style.width = vw + 'px';
628
+ $container.style.height = `calc(${vh}px - ${DOCK_INSET_TOP} - ${DOCK_INSET_BOTTOM})`;
629
+ return {x: 0, y: 0, width: vw, height: vh};
630
+ }
631
+
632
+ /************************************************************
633
+ * What is placed in the DOM, and removed from it: the window,
634
+ * or the lock that holds a modal one over its backdrop.
635
+ ************************************************************/
636
+ function window_root(gobj)
637
+ {
638
+ return gobj.priv.$lock || gobj_read_attr(gobj, "$container");
639
+ }
640
+
641
+ /************************************************************
642
+ * An Escape typed in the window. The callback only decides
643
+ * whether the key is the window's -- not when `keyboard` is
644
+ * off, nor one that what it was typed in took -- and sends
645
+ * the event: the close is the ✕'s, in the action.
646
+ ************************************************************/
647
+ function on_escape_key(gobj, evt)
648
+ {
649
+ if(evt.key !== "Escape" && evt.keyCode !== 27) {
650
+ return;
651
+ }
652
+ if(gobj_is_destroying(gobj) || !gobj_read_bool_attr(gobj, "keyboard")) {
653
+ return;
654
+ }
655
+ if(escape_is_taken(evt)) {
656
+ /* An inline editor that closed with the key took the focus
657
+ * with it (to <body>): the window takes it back, or the next
658
+ * Escape -- and Tab -- would not be heard here. */
659
+ let $container = gobj_read_attr(gobj, "$container");
660
+ let active = document.activeElement;
661
+ if(evt.target && evt.target.isConnected === false && $container &&
662
+ (!active || active === document.body)) {
663
+ $container.focus();
664
+ }
665
+ return;
666
+ }
667
+ evt.preventDefault();
668
+ evt.stopPropagation();
669
+ gobj_send_event(gobj, "EV_CLOSE_WINDOW", {key: "Escape"}, gobj);
670
+ }
671
+
418
672
  /************************************************************
419
673
  * Below the mobile breakpoint the window is a full-screen
420
674
  * sheet (no float / drag / resize).
@@ -472,9 +726,13 @@ function build_ui(gobj)
472
726
  if(is_gobj(header)) {
473
727
  header = gobj_read_attr(header, "$container");
474
728
  }
729
+ let title_id = `yui-window-title-${++__title_seq__}`;
730
+ let $title = build_title_node(gobj, title_id, !!header);
731
+ let $hidden_title = header ? $title : null;
475
732
  if(!header) {
476
- header = build_default_header(gobj);
733
+ header = $title;
477
734
  }
735
+ let modal = gobj_read_bool_attr(gobj, "modal");
478
736
  let body = gobj_read_attr(gobj, "body");
479
737
  if(is_gobj(body)) {
480
738
  body = gobj_read_attr(body, "$container");
@@ -489,7 +747,7 @@ function build_ui(gobj)
489
747
  *----------------------------------------------*/
490
748
  if(gobj_read_bool_attr(gobj, "auto_save_size_and_position")) {
491
749
  if(gobj_is_service(gobj)) {
492
- let rect = kw_get_local_storage_value(`${gobj_name(gobj)}-rect`);
750
+ let rect = whole_rect(kw_get_local_storage_value(`${gobj_name(gobj)}-rect`));
493
751
  if(rect) {
494
752
  rect.x = rect.x<0?0:rect.x;
495
753
  rect.y = rect.y<0?0:rect.y;
@@ -549,11 +807,26 @@ function build_ui(gobj)
549
807
  * only this tells them apart in the Inspector or in a selector. */
550
808
  let logical = gobj_read_str_attr(gobj, "logical_class");
551
809
 
810
+ let dialog_attrs = {role: 'dialog', tabindex: '-1'};
811
+ let label_ids = [];
812
+ if(!empty_string(gobj_read_str_attr(gobj, "title_prefix"))) {
813
+ label_ids.push(`${title_id}-prefix`);
814
+ }
815
+ if(!empty_string(gobj_read_str_attr(gobj, "title"))) {
816
+ label_ids.push(`${title_id}-kind`);
817
+ }
818
+ if(label_ids.length > 0) {
819
+ dialog_attrs['aria-labelledby'] = label_ids.join(' ');
820
+ }
821
+ if(modal) {
822
+ dialog_attrs['aria-modal'] = 'true';
823
+ }
824
+
552
825
  let $container = createElement2(
553
- ['div', {
826
+ ['div', Object.assign({
554
827
  class: 'C_YUI_WINDOW' + (logical ? ' ' + logical : '') +
555
828
  ' strong-shadow is-flex is-flex-direction-column' + (mobile ? ' is-mobile-sheet' : ''),
556
- style: window_style}, [
829
+ style: window_style}, dialog_attrs), [
557
830
 
558
831
  /*----------------------------*
559
832
  * Header
@@ -728,6 +1001,16 @@ function build_ui(gobj)
728
1001
  );
729
1002
  gobj_write_attr(gobj, "$container", $container);
730
1003
 
1004
+ if($hidden_title) {
1005
+ $container.insertBefore($hidden_title, $container.firstChild);
1006
+ }
1007
+ $container.addEventListener("keydown", function(evt) {
1008
+ on_escape_key(gobj, evt);
1009
+ });
1010
+ if(mobile) {
1011
+ fill_work_area($container);
1012
+ }
1013
+
731
1014
  /*----------------------------*
732
1015
  * Resize button in body
733
1016
  *----------------------------*/
@@ -762,12 +1045,30 @@ function build_ui(gobj)
762
1045
 
763
1046
  refresh_language($container, t);
764
1047
 
1048
+ if(modal) {
1049
+ /* A press on the backdrop closes nothing: a modal is answered,
1050
+ * not dismissed by a click beside it. Nor does it take the
1051
+ * focus out of the window, where Escape and Tab are heard. */
1052
+ let $lock = createElement2(
1053
+ ['div', {class: 'WINDOW_MODAL_LOCK yui-window-lock',
1054
+ style: `z-index:${MODAL_WINDOW_Z};`}, [
1055
+ ['div', {class: 'WINDOW_MODAL_BACKDROP yui-window-backdrop'}, [], {
1056
+ mousedown: (evt) => {
1057
+ evt.preventDefault();
1058
+ }
1059
+ }]
1060
+ ]]
1061
+ );
1062
+ $lock.appendChild($container);
1063
+ gobj.priv.$lock = $lock;
1064
+ }
1065
+
765
1066
  let $parent = gobj_read_attr(gobj, "$parent");
766
1067
  gobj.priv.placed_by_shell = !$parent;
767
1068
  if(!$parent) {
768
1069
  $parent = window_place(gobj);
769
1070
  }
770
- $parent.appendChild($container);
1071
+ $parent.appendChild(window_root(gobj));
771
1072
 
772
1073
  if (gobj_read_bool_attr(gobj, "openMaximized")) {
773
1074
  max(gobj);
@@ -789,13 +1090,12 @@ function build_ui(gobj)
789
1090
  ************************************************************/
790
1091
  function destroy_ui(gobj)
791
1092
  {
792
- let $container = gobj_read_attr(gobj, "$container");
793
- if($container) {
794
- if($container.parentNode) {
795
- $container.parentNode.removeChild($container);
796
- }
797
- gobj_write_attr(gobj, "$container", null);
1093
+ let $root = window_root(gobj);
1094
+ if($root && $root.parentNode) {
1095
+ $root.parentNode.removeChild($root);
798
1096
  }
1097
+ gobj.priv.$lock = null;
1098
+ gobj_write_attr(gobj, "$container", null);
799
1099
  }
800
1100
 
801
1101
  /************************************************************
@@ -925,10 +1225,19 @@ function close_window(gobj)
925
1225
  * The place is the shell's, and a window parented to the app
926
1226
  * outlives it: ac_shell_changed() moves it when a shell goes or
927
1227
  * comes.
1228
+ *
1229
+ * A MODAL window lives in the shell's dialog layer instead, with
1230
+ * its backdrop: it blocks the drawer, the dock and every other
1231
+ * window, and a question it asks (a dialog of the same layer)
1232
+ * opens above it.
928
1233
  ************************************************************/
929
1234
  function window_place(gobj)
930
1235
  {
931
- return yui_shell_window_layer(yui_shell_of(gobj)) || document.body;
1236
+ let shell = yui_shell_of(gobj);
1237
+ if(gobj_read_bool_attr(gobj, "modal")) {
1238
+ return yui_shell_modal_layer(shell) || document.body;
1239
+ }
1240
+ return yui_shell_window_layer(shell) || document.body;
932
1241
  }
933
1242
 
934
1243
  /************************************************************
@@ -953,15 +1262,7 @@ function max(gobj)
953
1262
  let $container = gobj_read_attr(gobj, "$container");
954
1263
  priv.prevSize = $container.getBoundingClientRect();
955
1264
 
956
- let rect = do_fix_dimension_to_screen(gobj, 0, 0, 10000, 10000);
957
- if (gobj_read_bool_attr(gobj, "center")) {
958
- rect = do_center(gobj, rect.x, rect.y, rect.width, rect.height);
959
- }
960
-
961
- $container.style.left = parseInt(rect.x) + 'px';
962
- $container.style.top = parseInt(rect.y) + 'px';
963
- $container.style.width = parseInt(rect.width) +'px';
964
- $container.style.height = parseInt(rect.height) +'px';
1265
+ let rect = fill_work_area($container);
965
1266
 
966
1267
  gobj_write_bool_attr(gobj, "maximized", true);
967
1268
  set_max_icon(gobj, true);
@@ -1014,6 +1315,28 @@ function min(gobj)
1014
1315
  return rect;
1015
1316
  }
1016
1317
 
1318
+ /************************************************************
1319
+ * The rect of a window in whole pixels: x, y, width and height
1320
+ * are DTP_INTEGER, and getBoundingClientRect() answers fractions
1321
+ * under a zoom or a device pixel ratio (an integer attr refuses
1322
+ * 2.5, as in C). Also a rect saved with fractions before. null
1323
+ * when it is not a rect of four numbers.
1324
+ ************************************************************/
1325
+ function whole_rect(rect)
1326
+ {
1327
+ if(!rect || typeof rect !== "object") {
1328
+ return null;
1329
+ }
1330
+ let whole = {};
1331
+ for(const key of ["x", "y", "width", "height"]) {
1332
+ if(typeof rect[key] !== "number" || !Number.isFinite(rect[key])) {
1333
+ return null;
1334
+ }
1335
+ whole[key] = Math.round(rect[key]);
1336
+ }
1337
+ return whole;
1338
+ }
1339
+
1017
1340
  /************************************************************
1018
1341
  * handlers moving
1019
1342
  ************************************************************/
@@ -1072,16 +1395,15 @@ function mvStart(gobj, evt)
1072
1395
  // trigger event
1073
1396
  let rect = $container.getBoundingClientRect();
1074
1397
 
1075
- gobj_write_integer_attr(gobj, "x", rect.x);
1076
- gobj_write_integer_attr(gobj, "y", rect.y);
1077
- gobj_write_integer_attr(gobj, "width", rect.width);
1078
- gobj_write_integer_attr(gobj, "height", rect.height);
1398
+ let whole = whole_rect(rect);
1399
+ gobj_write_integer_attr(gobj, "x", whole.x);
1400
+ gobj_write_integer_attr(gobj, "y", whole.y);
1401
+ gobj_write_integer_attr(gobj, "width", whole.width);
1402
+ gobj_write_integer_attr(gobj, "height", whole.height);
1079
1403
 
1080
1404
  if(gobj_read_bool_attr(gobj, "auto_save_size_and_position")) {
1081
1405
  if(gobj_is_service(gobj)) {
1082
- kw_set_local_storage_value(`${gobj_name(gobj)}-rect`, {
1083
- x:rect.x, y:rect.y, width:rect.width, height: rect.height
1084
- });
1406
+ kw_set_local_storage_value(`${gobj_name(gobj)}-rect`, whole);
1085
1407
  }
1086
1408
  }
1087
1409
  gobj_publish_event(gobj, "EV_WINDOW_MOVED", {rect: rect});
@@ -1147,16 +1469,15 @@ function rsStart(gobj, evt)
1147
1469
  $container.style.height = rect.height +'px';
1148
1470
  }
1149
1471
 
1150
- gobj_write_integer_attr(gobj, "x", rect.x);
1151
- gobj_write_integer_attr(gobj, "y", rect.y);
1152
- gobj_write_integer_attr(gobj, "width", rect.width);
1153
- gobj_write_integer_attr(gobj, "height", rect.height);
1472
+ let whole = whole_rect(rect);
1473
+ gobj_write_integer_attr(gobj, "x", whole.x);
1474
+ gobj_write_integer_attr(gobj, "y", whole.y);
1475
+ gobj_write_integer_attr(gobj, "width", whole.width);
1476
+ gobj_write_integer_attr(gobj, "height", whole.height);
1154
1477
 
1155
1478
  if(gobj_read_bool_attr(gobj, "auto_save_size_and_position")) {
1156
1479
  if(gobj_is_service(gobj)) {
1157
- kw_set_local_storage_value(`${gobj_name(gobj)}-rect`, {
1158
- x:rect.x, y:rect.y, width:rect.width, height: rect.height
1159
- });
1480
+ kw_set_local_storage_value(`${gobj_name(gobj)}-rect`, whole);
1160
1481
  }
1161
1482
  }
1162
1483
  gobj_publish_event(gobj, "EV_WINDOW_RESIZED", {rect: rect});
@@ -1242,26 +1563,14 @@ function handleResize(gobj)
1242
1563
  /* Mobile: full-screen sheet, refit to the viewport and stop. */
1243
1564
  if(is_mobile()) {
1244
1565
  $container.classList.add("is-mobile-sheet");
1245
- let vw = window.innerWidth || document.documentElement.offsetWidth;
1246
- let vh = window.innerHeight || document.documentElement.offsetHeight;
1247
- $container.style.left = '0px';
1248
- $container.style.top = '0px';
1249
- $container.style.width = vw + 'px';
1250
- $container.style.height = vh + 'px';
1566
+ fill_work_area($container);
1251
1567
  return;
1252
1568
  }
1253
1569
  $container.classList.remove("is-mobile-sheet");
1254
1570
 
1255
1571
  /* Maximized: just refit to the (new) viewport. */
1256
1572
  if(gobj_read_bool_attr(gobj, "maximized") === true) {
1257
- let r = do_fix_dimension_to_screen(gobj, 0, 0, 10000, 10000);
1258
- if(gobj_read_bool_attr(gobj, "center")) {
1259
- r = do_center(gobj, r.x, r.y, r.width, r.height);
1260
- }
1261
- $container.style.left = parseInt(r.x) + 'px';
1262
- $container.style.top = parseInt(r.y) + 'px';
1263
- $container.style.width = parseInt(r.width) + 'px';
1264
- $container.style.height = parseInt(r.height) + 'px';
1573
+ fill_work_area($container);
1265
1574
  return;
1266
1575
  }
1267
1576
 
@@ -1396,8 +1705,9 @@ function ac_shell_changed(gobj, event, kw, src)
1396
1705
  }
1397
1706
 
1398
1707
  let $place = window_place(gobj);
1399
- if($container.parentNode !== $place) {
1400
- $place.appendChild($container);
1708
+ let $root = window_root(gobj);
1709
+ if($root.parentNode !== $place) {
1710
+ $place.appendChild($root);
1401
1711
  }
1402
1712
  return 0;
1403
1713
  }
@@ -1417,6 +1727,7 @@ function ac_shell_changed(gobj, event, kw, src)
1417
1727
  *---------------------------------------------*/
1418
1728
  const gmt = {
1419
1729
  mt_create: mt_create,
1730
+ mt_start: mt_start,
1420
1731
  mt_destroy: mt_destroy
1421
1732
  };
1422
1733