drawnui-react 0.1.0-preview.35 → 0.1.0-preview.37

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 (42) hide show
  1. package/SKIPPED.md +3 -0
  2. package/dist/controls/SkiaButton.js +2 -2
  3. package/dist/controls/SkiaCarousel.js +31 -3
  4. package/dist/controls/SkiaCheckbox.js +2 -1
  5. package/dist/controls/SkiaEditor.d.ts +4 -0
  6. package/dist/controls/SkiaEditor.js +16 -4
  7. package/dist/controls/SkiaLabel.d.ts +2 -0
  8. package/dist/controls/SkiaLabel.js +2 -0
  9. package/dist/controls/SkiaLayout.d.ts +2 -0
  10. package/dist/controls/SkiaLayout.js +2 -0
  11. package/dist/controls/SkiaProgress.js +2 -2
  12. package/dist/controls/SkiaRadioButton.js +2 -1
  13. package/dist/controls/SkiaShaderCarousel.js +5 -0
  14. package/dist/controls/SkiaSlider.js +2 -2
  15. package/dist/controls/SkiaSwitch.js +4 -2
  16. package/dist/controls/TooltipStyle.d.ts +52 -0
  17. package/dist/controls/TooltipStyle.js +88 -0
  18. package/dist/core/Accessibility.d.ts +30 -0
  19. package/dist/core/Accessibility.js +162 -3
  20. package/dist/core/Canvas.d.ts +76 -3
  21. package/dist/core/Canvas.js +239 -8
  22. package/dist/core/ControlStyle.d.ts +2 -0
  23. package/dist/core/ControlStyle.js +2 -0
  24. package/dist/core/Hover.d.ts +4 -0
  25. package/dist/core/Hover.js +6 -0
  26. package/dist/core/KeyboardManager.d.ts +7 -0
  27. package/dist/core/KeyboardManager.js +35 -4
  28. package/dist/core/PopupWindows.d.ts +92 -0
  29. package/dist/core/PopupWindows.js +203 -0
  30. package/dist/core/SkiaControl.d.ts +30 -0
  31. package/dist/core/SkiaControl.js +60 -3
  32. package/dist/core/Super.d.ts +7 -0
  33. package/dist/core/Super.js +7 -0
  34. package/dist/core/Tooltips.d.ts +71 -0
  35. package/dist/core/Tooltips.js +205 -0
  36. package/dist/index.d.ts +3 -0
  37. package/dist/index.js +3 -0
  38. package/dist/react/index.d.ts +16 -1
  39. package/dist/react/index.js +51 -11
  40. package/dist/react/reconciler.d.ts +2 -0
  41. package/dist/react/reconciler.js +5 -0
  42. package/package.json +3 -1
@@ -1,4 +1,6 @@
1
1
  import { SKRect } from "./Types";
2
+ /** Controls with `AccessibilityModal` set, on every canvas (drawnui-cross 6av). Empty: no modal work at all. */
3
+ export const AccessibilityModals = new Set();
2
4
  /** ARIA role constants (DrawnUi.Models.Aria) for `AccessibilityRole`. */
3
5
  export const Aria = {
4
6
  // interactive widgets
@@ -106,9 +108,19 @@ export class SkiaAccessibilityManager {
106
108
  * Aria.RoleList on a SkiaStack), and the item of that group holding the control (one of its children, a cell).
107
109
  */
108
110
  static TryFindGroup(control) {
111
+ const path = [];
109
112
  for (let child = control, parent = control.Parent; parent; child = parent, parent = parent.Parent) {
110
- if (Aria.IsCompositeRole(parent.AccessibilityRole))
111
- return { Group: parent, Item: child };
113
+ path.push(child);
114
+ if (!Aria.IsCompositeRole(parent.AccessibilityRole))
115
+ continue;
116
+ // drawnui-cross 6ao: the role may sit on a wrapper (a menu shape around a column of lines); the items are the
117
+ // children of the control that holds them, found down the path through single children that are not nodes
118
+ let holder = parent, k = path.length - 1;
119
+ while (k > 0 && ViewsOf(holder).length === 1 && !IsInteractiveNode(path[k])) {
120
+ holder = path[k];
121
+ k--;
122
+ }
123
+ return { Group: parent, Item: path[k], Holder: holder };
112
124
  }
113
125
  return undefined;
114
126
  }
@@ -124,6 +136,15 @@ export class SkiaAccessibilityManager {
124
136
  * item; the arrow keys move between items. Every node outside a group is a stop.
125
137
  */
126
138
  IsTabStop(node) {
139
+ // an open popup window keeps the keyboard: Tab never leaves it, as with native menus
140
+ const scope = this.KeyboardScope;
141
+ if (scope) {
142
+ let c = node;
143
+ while (c && c !== scope)
144
+ c = c.Parent;
145
+ if (!c)
146
+ return false;
147
+ }
127
148
  const found = SkiaAccessibilityManager.TryFindGroup(node);
128
149
  if (!found)
129
150
  return true;
@@ -158,7 +179,7 @@ export class SkiaAccessibilityManager {
158
179
  const found = SkiaAccessibilityManager.TryFindGroup(focused);
159
180
  if (!found)
160
181
  return false;
161
- const { Group: group, Item: item } = found;
182
+ const { Holder: group, Item: item } = found;
162
183
  const scroll = FindScroll(group), axis = AxisOf(group), count = ItemCount(group);
163
184
  const current = this.groupRequest?.Group === group ? this.groupRequest.Index : IndexOf(group, item);
164
185
  if (current < 0 || count < 1)
@@ -212,6 +233,97 @@ export class SkiaAccessibilityManager {
212
233
  group.Superview?.Update(); // resolved at the end of the next frame, together with the snapshot
213
234
  return true;
214
235
  }
236
+ // ---- keyboard focus moved by popup windows (drawnui-cross 6ao rule 2, and back to the opener on close) ----
237
+ focusRequest;
238
+ popupFocusRoot;
239
+ focusAnyInside = false;
240
+ /** The keyboard goes to this control at the end of the next frame (a popup closed: back to what opened it). */
241
+ RequestKeyboardFocus(control) { this.focusRequest = control; }
242
+ popupScope;
243
+ /**
244
+ * While set, Tab stays inside this control: only its nodes are Tab stops and Tab / Shift+Tab go round them: the top
245
+ * popup window that takes input (a menu, a dropdown; set by the canvas), else the active modal.
246
+ */
247
+ get KeyboardScope() { return this.popupScope ?? this.ActiveModal; }
248
+ set KeyboardScope(v) { this.popupScope = v; }
249
+ // ---- modal accessibility scope (drawnui-cross 6av, C# AccessibilityModal) ----
250
+ /** The modal that accessibility is limited to: the topmost `AccessibilityModal` control that shows. Undefined when none. */
251
+ ActiveModal;
252
+ // where the keyboard was when each modal became active, to go back there when it goes
253
+ modalReturns = new Map();
254
+ /** A control behind the active modal (not in it, not in a popup window over it): no focus for navigation. */
255
+ IsOutsideModal(control) {
256
+ const modal = this.ActiveModal;
257
+ return !!modal && !IsInside(control, modal) && TopRoot(control) === TopRoot(modal);
258
+ }
259
+ /** Frame end, only while some control is flagged modal or one was active: follows the top modal. */
260
+ UpdateActiveModal() {
261
+ let next;
262
+ for (const m of AccessibilityModals) {
263
+ if (m.IsDisposed || !m.IsVisible || m.Opacity <= 0 || AccessibilityManagerHiddenByAncestor(m)
264
+ || m.Superview?.AccessibilityManager !== this || !IsDrawn(m))
265
+ continue;
266
+ if (!next || IsDrawnAbove(m, next))
267
+ next = m;
268
+ }
269
+ const previous = this.ActiveModal;
270
+ if (previous === next)
271
+ return;
272
+ this.ActiveModal = next;
273
+ this.ForceRebuildOnNextFrame(); // readers and Tab switch to the new scope in this frame
274
+ const keyboard = this.FocusedNode;
275
+ if (next && keyboard && !IsInside(keyboard, next)) {
276
+ // the keyboard is in use: into the modal, and back here when it goes
277
+ this.modalReturns.set(next, keyboard);
278
+ this.popupFocusRoot = next;
279
+ this.focusAnyInside = true;
280
+ }
281
+ const back = previous && this.modalReturns.get(previous);
282
+ if (previous)
283
+ this.modalReturns.delete(previous);
284
+ // back unless the keyboard went elsewhere meanwhile; a keyboard node that left with the modal (disposed, detached) was in it
285
+ const leftWithIt = !!keyboard && (keyboard.IsDisposed || !keyboard.Superview);
286
+ if (back && (!keyboard || leftWithIt || IsInside(keyboard, previous)) && (!next || IsInside(back, next)))
287
+ this.focusRequest = back;
288
+ }
289
+ /** The Tab stop after (or before) `from` in reading order; inside a KeyboardScope it goes round, never leaving. */
290
+ NextTabStop(from, forward) {
291
+ const stops = this.Snapshot.filter((n) => n.CanInteract && this.IsTabStop(n.Source)).map((n) => n.Source);
292
+ if (stops.length === 0)
293
+ return undefined;
294
+ let current = from ? stops.indexOf(from) : -1;
295
+ if (current < 0)
296
+ current = forward ? -1 : stops.length;
297
+ const next = forward ? current + 1 : current - 1;
298
+ if (this.KeyboardScope)
299
+ return stops[(next + stops.length) % stops.length];
300
+ return next >= 0 && next < stops.length ? stops[next] : undefined;
301
+ }
302
+ /**
303
+ * A popup window just opened: at the end of the frame that draws it, the keyboard goes to its arrow-key group's current
304
+ * choice (a checked radio, menuitemradio, option or tab), else to its first interactive item, however it was opened.
305
+ */
306
+ FocusOpenedPopup(root) { this.popupFocusRoot = root; this.focusAnyInside = false; }
307
+ ProcessFocusRequests(scale, w, h) {
308
+ const request = this.focusRequest, root = this.popupFocusRoot;
309
+ this.focusRequest = this.popupFocusRoot = undefined;
310
+ if (root && !root.IsDisposed && root.Superview) {
311
+ this.Rebuild(scale, w, h);
312
+ const inside = (c) => { for (let p = c; p; p = p.Parent)
313
+ if (p === root)
314
+ return true; return false; };
315
+ const choice = (role) => role === Aria.RoleRadio || role === Aria.RoleMenuItemRadio || role === "option" || role === "tab";
316
+ // a popup: the items of its arrow-key group; a modal: its first control that takes input
317
+ const items = this.Snapshot.filter((n) => n.CanInteract && inside(n.Source) && (this.focusAnyInside || SkiaAccessibilityManager.TryFindGroup(n.Source)));
318
+ const target = items.find((n) => n.IsPressed === true && choice(n.Role)) ?? items[0];
319
+ if (target) {
320
+ this.FocusFromKeyboard(target.Source, scale, w, h);
321
+ return;
322
+ }
323
+ }
324
+ if (request && !request.IsDisposed && request.Superview && request.AccessibilityCanInteract)
325
+ this.FocusFromKeyboard(request, scale, w, h);
326
+ }
215
327
  /** Frame end: focus the requested item once it is drawn, skipping items that cannot take input. */
216
328
  ProcessGroupFocus(scale, w, h, requestFrame) {
217
329
  const request = this.groupRequest;
@@ -284,7 +396,11 @@ export class SkiaAccessibilityManager {
284
396
  * per MinUpdateIntervalMs otherwise (keeps rects in sync with scrolling); notifies only when the snapshot differs.
285
397
  */
286
398
  OnFrameEnd(scale, canvasWidthPx, canvasHeightPx, requestFrame) {
399
+ if (AccessibilityModals.size > 0 || this.ActiveModal)
400
+ this.UpdateActiveModal();
287
401
  this.ProcessGroupFocus(scale, canvasWidthPx, canvasHeightPx, requestFrame);
402
+ if (this.focusRequest || this.popupFocusRoot)
403
+ this.ProcessFocusRequests(scale, canvasWidthPx, canvasHeightPx);
288
404
  if (this.nodes.size === 0 && this.Snapshot.length === 0)
289
405
  return;
290
406
  const now = performance.now();
@@ -301,6 +417,7 @@ export class SkiaAccessibilityManager {
301
417
  this.dirty = false;
302
418
  this.lastRebuild = performance.now();
303
419
  let list = [];
420
+ const modal = this.ActiveModal;
304
421
  for (const n of this.nodes) {
305
422
  if (!n.Superview) {
306
423
  this.nodes.delete(n);
@@ -309,6 +426,8 @@ export class SkiaAccessibilityManager {
309
426
  } // detached from the tree
310
427
  if (!n.IsVisible || !n.IsAccessibilityElement || n.AccessibilityRole === Aria.RolePresentation)
311
428
  continue;
429
+ if (modal && this.IsOutsideModal(n))
430
+ continue; // a modal is shown: only its nodes, and those of popup windows over it
312
431
  if (AccessibilityManagerHiddenByAncestor(n))
313
432
  continue; // e.g. the root page kept mounted under a pushed shell page
314
433
  const px = n.GetAccessibilityPixelRect();
@@ -390,6 +509,9 @@ function SayNamesOnce(list) {
390
509
  owner = bySource.get(p);
391
510
  if (!owner || owner.Label !== x.Label)
392
511
  continue;
512
+ // a dialog keeps its name though its title says it too: readers announce the dialog by name on entry
513
+ if (owner.Role === Aria.RoleDialog || owner.Role === Aria.RoleAlertDialog)
514
+ continue;
393
515
  if (owner.CanInteract)
394
516
  said.add(x);
395
517
  else
@@ -401,6 +523,43 @@ function SameValue(a, b) {
401
523
  return a === b || (!!a && !!b && a.Now === b.Now && a.Min === b.Min && a.Max === b.Max && a.Step === b.Step && a.Text === b.Text);
402
524
  }
403
525
  // ---- group helpers (duck-typed layouts and scrolls) ----
526
+ function IsInside(control, root) {
527
+ for (let c = control; c; c = c.Parent)
528
+ if (c === root)
529
+ return true;
530
+ return false;
531
+ }
532
+ /** The top of the tree a control is in: the canvas content, or a popup window's root. */
533
+ function TopRoot(control) {
534
+ let c = control;
535
+ while (c.Parent)
536
+ c = c.Parent;
537
+ return c;
538
+ }
539
+ /** Drawing order: `a` draws over `b` (ZIndex, then tree order; a nested control over its ancestor). */
540
+ function IsDrawnAbove(a, b) {
541
+ const path = (c) => { const p = []; for (let x = c; x; x = x.Parent)
542
+ p.unshift(x); return p; };
543
+ const pa = path(a), pb = path(b);
544
+ let i = 0;
545
+ while (i < pa.length && i < pb.length && pa[i] === pb[i])
546
+ i++;
547
+ if (i === pa.length)
548
+ return false; // a contains b
549
+ if (i === pb.length)
550
+ return true; // b contains a
551
+ if (i === 0)
552
+ return false; // different trees (a popup window): the first one found stays
553
+ const sa = pa[i], sb = pb[i];
554
+ if (sa.ZIndex !== sb.ZIndex)
555
+ return sa.ZIndex > sb.ZIndex;
556
+ const views = ViewsOf(sa.Parent);
557
+ return views.indexOf(sa) > views.indexOf(sb);
558
+ }
559
+ /** A node the keyboard can land on: a role that is not presentation and takes input. */
560
+ function IsInteractiveNode(c) {
561
+ return !!c.AccessibilityRole && c.AccessibilityRole !== Aria.RolePresentation && c.IsAccessibilityElement && c.AccessibilityCanInteract;
562
+ }
404
563
  /** Children of a control (a layout's Views, a scroll's Content). */
405
564
  function ViewsOf(c) {
406
565
  if ("Views" in c)
@@ -3,8 +3,10 @@ import type { DrawingContext, SkiaControl } from "./SkiaControl";
3
3
  import type { AnimatorBase } from "./Animators";
4
4
  import { SkiaAccessibilityManager } from "./Accessibility";
5
5
  import { HoverManager } from "./Hover";
6
- import { type Color, type RenderingModeType } from "./Types";
7
- import { ContextMenuEventArgs, type GesturesMode, SkiaGesturesParameters, TouchActionEventArgs } from "./Gestures";
6
+ import { type TooltipStyleLike } from "./Tooltips";
7
+ import { PopupAnchor, type PopupId, type PopupWindowOptions } from "./PopupWindows";
8
+ import { type Color, type RenderingModeType, SKRect } from "./Types";
9
+ import { ContextMenuEventArgs, type GesturesMode, SKPoint, SkiaGesturesParameters, TouchActionEventArgs } from "./Gestures";
8
10
  /**
9
11
  * Mirrors DrawnUi Canvas (DrawnView): hosts one Content control on an HTML canvas element,
10
12
  * owns RenderingScale (devicePixelRatio), the surface, the on-demand frame loop and raw input.
@@ -45,6 +47,47 @@ export declare class Canvas {
45
47
  readonly AccessibilityManager: SkiaAccessibilityManager;
46
48
  /** Mouse hover of the controls (drawnui-cross 6m): ReceivesHover / IsHovered / HoverChanged. */
47
49
  readonly Hover: HoverManager;
50
+ private tooltipController?;
51
+ /** Made on first use: a canvas that never shows a tooltip allocates nothing for it. */
52
+ private get tooltip();
53
+ /** Look and timing of the tooltips on this canvas; unset uses `Super.TooltipStyle`. */
54
+ TooltipStyle?: TooltipStyleLike;
55
+ get TooltipStyleUsed(): TooltipStyleLike;
56
+ /** The text of the tooltip shown now, undefined when none is shown. */
57
+ get ShownTooltip(): string | undefined;
58
+ private popupLayer?;
59
+ /** Made on first use, like the tooltip. */
60
+ private get popups();
61
+ private popupKeysHooked;
62
+ /** Raised when a popup window closed: picked, a press outside, Escape, the wheel, window blur or ClosePopupWindow. */
63
+ readonly PopupWindowClosed: Set<(id: PopupId) => void>;
64
+ /**
65
+ * Shows `content` over everything, opening from `anchor` the way native menus do: at a point (a right click, canvas
66
+ * points), or below a rect or a control (a dropdown), flipped to the other side where it does not fit. It closes with
67
+ * a press outside it, Escape, the wheel outside it, window blur, `ClosePopupWindow` and the options.
68
+ */
69
+ OpenPopupWindow(content: SkiaControl, anchor: PopupAnchor | SKPoint | SKRect | SkiaControl | {
70
+ X: number;
71
+ Y: number;
72
+ }, options?: PopupWindowOptions): PopupId;
73
+ /** Closes the popup window (nothing when it is closed already). */
74
+ ClosePopupWindow(id: PopupId): void;
75
+ /** Closes every popup window. */
76
+ ClosePopupWindows(): void;
77
+ /** The popup window is still open. */
78
+ IsPopupWindowOpen(id: PopupId): boolean;
79
+ /** True while a popup window that takes input is open. */
80
+ get HasPopupWindows(): boolean;
81
+ /** The content of the top popup window that takes input. */
82
+ get TopPopupWindow(): SkiaControl | undefined;
83
+ /** The window stopped being active (blur): popup windows and the tooltip close, as native menus do. */
84
+ OnWindowDeactivated(): void;
85
+ RaisePopupWindowClosed(id: PopupId): void;
86
+ private AfterPopupsChanged;
87
+ private readonly onPopupKey;
88
+ private readonly onPopupChar;
89
+ private HookPopupKeys;
90
+ private readonly onWindowBlur;
48
91
  private content?;
49
92
  get Content(): SkiaControl | undefined;
50
93
  set Content(value: SkiaControl | undefined);
@@ -210,6 +253,36 @@ export declare class Canvas {
210
253
  private gestureOwner;
211
254
  /** DrawnUi IsSavedGesture: the types replayed to the owner instead of being routed again. */
212
255
  private static IsSavedGesture;
213
- /** Entry into the control tree, same shape as DrawnUi Canvas.ProcessGestures. */
256
+ private arrowsStart;
257
+ /**
258
+ * While no drawn control has keyboard focus (or only one behind the active modal), the arrow keys start keyboard
259
+ * navigation as the first Tab does: Down and Right go to the first Tab stop, Up and Left to the last, and the key is used
260
+ * for that. Once a control has focus the arrows work as usual (inside a list or a menu). Off by default, since games use
261
+ * the arrows as their own keys while nothing is focused: an app turns it on for its menu screens and off while playing.
262
+ */
263
+ get ArrowsStartKeyboardNavigation(): boolean;
264
+ set ArrowsStartKeyboardNavigation(v: boolean);
265
+ private readonly onArrowChar;
266
+ private readonly onArrowKey;
267
+ private focusedChild?;
268
+ private focusAtDown?;
269
+ private tapNoFocus;
270
+ private reportingFocus;
271
+ /**
272
+ * A control that left the canvas (removed or disposed) is let go by the focus, the gesture dispatch and the tooltips,
273
+ * so the last control that took input does not keep its page alive (C# 4cb28ab6). Checked once per frame.
274
+ */
275
+ private ForgetGoneControls;
276
+ /** The control that has the canvas focus (an editor while it edits, a CanBeFocused control that was tapped). */
277
+ get FocusedChild(): SkiaControl | undefined;
278
+ /**
279
+ * Moves the focus. The new control is asked first and the focus moves only when it takes it (a tap on a button leaves an
280
+ * editor focused); undefined clears it. Nothing moves while the focused control has LockFocus. `setter` is a control
281
+ * that focused itself already (an editor on its press) or the focused control letting go itself (Escape, submit).
282
+ */
283
+ ReportFocus(value: SkiaControl | undefined, setter?: SkiaControl): void;
284
+ /** Entry into the control tree; on a completed tap the focus follows it (C# Canvas: focus only on Tapped). */
214
285
  protected ProcessGestures(root: SkiaControl, args: SkiaGesturesParameters): SkiaControl | null;
286
+ /** Same shape as DrawnUi Canvas.ProcessGestures. */
287
+ private RouteGestures;
215
288
  }