drawnui-react 0.1.0-preview.41 → 0.1.0-preview.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 (51) hide show
  1. package/README.md +89 -7
  2. package/SKIPPED.md +7 -7
  3. package/dist/controls/GridStructure.d.ts +9 -1
  4. package/dist/controls/GridStructure.js +41 -1
  5. package/dist/controls/SkiaEditor.d.ts +4 -1
  6. package/dist/controls/SkiaEditor.js +25 -6
  7. package/dist/controls/SkiaImage.d.ts +5 -0
  8. package/dist/controls/SkiaImage.js +32 -5
  9. package/dist/controls/SkiaLabel.d.ts +85 -4
  10. package/dist/controls/SkiaLabel.js +406 -20
  11. package/dist/controls/SkiaLabelFps.d.ts +0 -3
  12. package/dist/controls/SkiaLabelFps.js +1 -11
  13. package/dist/controls/SkiaLayout.js +33 -2
  14. package/dist/controls/SkiaScroll.d.ts +51 -2
  15. package/dist/controls/SkiaScroll.js +150 -9
  16. package/dist/controls/SkiaShape.d.ts +2 -0
  17. package/dist/controls/SkiaShape.js +7 -0
  18. package/dist/controls/SkiaShell.d.ts +282 -0
  19. package/dist/controls/SkiaShell.js +972 -0
  20. package/dist/controls/SkiaSprite.js +5 -1
  21. package/dist/core/Accessibility.d.ts +30 -13
  22. package/dist/core/Accessibility.js +237 -43
  23. package/dist/core/Canvas.d.ts +122 -14
  24. package/dist/core/Canvas.js +585 -47
  25. package/dist/core/Gestures.d.ts +11 -1
  26. package/dist/core/Gestures.js +12 -1
  27. package/dist/core/PopupWindows.js +2 -0
  28. package/dist/core/Props.d.ts +11 -0
  29. package/dist/core/Props.js +44 -0
  30. package/dist/core/ScrollAnimators.d.ts +6 -0
  31. package/dist/core/ScrollAnimators.js +7 -1
  32. package/dist/core/SkiaControl.d.ts +24 -4
  33. package/dist/core/SkiaControl.js +59 -13
  34. package/dist/core/SkiaEffect.d.ts +12 -1
  35. package/dist/core/SkiaEffect.js +35 -8
  36. package/dist/core/SkiaImageManager.d.ts +101 -18
  37. package/dist/core/SkiaImageManager.js +318 -63
  38. package/dist/core/Styles.js +7 -1
  39. package/dist/core/Super.d.ts +4 -0
  40. package/dist/core/Super.js +4 -9
  41. package/dist/core/TextInputProxy.d.ts +31 -1
  42. package/dist/core/TextInputProxy.js +97 -15
  43. package/dist/index.d.ts +1 -0
  44. package/dist/index.js +1 -0
  45. package/dist/react/SkiaShell.d.ts +8 -74
  46. package/dist/react/SkiaShell.js +163 -514
  47. package/dist/react/index.d.ts +6 -1
  48. package/dist/react/index.js +51 -40
  49. package/dist/react/reconciler.d.ts +12 -0
  50. package/dist/react/reconciler.js +22 -46
  51. package/package.json +37 -4
@@ -12,6 +12,10 @@ export declare class TextInputProxy {
12
12
  private static element?;
13
13
  private static owner?;
14
14
  private static composing;
15
+ /** The field took focus from a touch tap: its keys come from the soft keyboard (the return key ends editing). */
16
+ private static byTouch;
17
+ /** Set by the canvas while it runs a touch release's gestures (a field focused by them was focused by a touch). */
18
+ static TouchGesture: boolean;
15
19
  private static applying;
16
20
  /** The textarea (created on first use); KeyboardManager recognizes it through `data-drawnui-text-input`. */
17
21
  static get Element(): HTMLTextAreaElement | undefined;
@@ -20,12 +24,38 @@ export declare class TextInputProxy {
20
24
  private static Create;
21
25
  /** The editor took focus: the textarea mirrors it and gets DOM focus (soft keyboard, IME). */
22
26
  static Attach(editor: SkiaEditor): void;
27
+ /** The input got DOM focus in the task running now (Attach): a tap that focused the field needs nothing more. */
28
+ private static focusedNow;
29
+ /**
30
+ * The canvas calls it at the end of a tap's release (the pointerup, the user gesture iOS requires to open the soft
31
+ * keyboard): a tap on the focused field gives its input DOM focus inside that gesture, so the keyboard opens on the first
32
+ * tap and comes back on a tap after the user closed it. A touch anywhere else leaves it as it is: the keyboard the user
33
+ * closed stays closed while the page is scrolled. True when the tap was on the focused field (its input has focus now).
34
+ */
35
+ static FocusFromTap(clientX: number, clientY: number, touch?: boolean): boolean;
23
36
  static Detach(editor: SkiaEditor): void;
37
+ private static blurAfterTouch;
38
+ /** The input has focus from a touch release (its keyboard is up): a tap on another field needs no blur and focus. */
39
+ private static keyboardUp;
40
+ /** The canvas calls it at the end of each touch release, after FocusFromTap: a field left during the press lets go now. */
41
+ static AfterTouchEnd(): void;
24
42
  private static Configure;
25
43
  /** Editor text / selection changed: mirror it (never while an IME composition is in flight). */
26
44
  static Sync(editor: SkiaEditor): void;
27
- /** Puts the textarea over the editor so mobile browsers scroll the right spot into view. */
45
+ /**
46
+ * Where the hidden input sits: a field focused by a touch keeps it fixed at the top-left corner, never over the field (as
47
+ * the DrawnUi.Net web heads), so iOS never pans the page to reveal it (a scroll with AdaptToKeyboardAuto moves the
48
+ * field above the keyboard); a field focused by a mouse or the keyboard has it over the field, so a desktop input
49
+ * method opens its candidate window next to the text.
50
+ */
28
51
  private static Place;
52
+ private static placedLeft;
53
+ private static placedTop;
54
+ /**
55
+ * After each frame of the canvas: a focused field that moved (its page scrolled) takes its hidden input along, so a
56
+ * desktop input method keeps its window next to the text. Nothing to do while no field is focused.
57
+ */
58
+ static AfterFrame(canvas: unknown): void;
29
59
  /** The textarea changed (typing, IME commit, paste, undo): diff against the editor and replay through the stubs. */
30
60
  private static ApplyFromElement;
31
61
  }
@@ -11,6 +11,10 @@ export class TextInputProxy {
11
11
  static element;
12
12
  static owner;
13
13
  static composing = false;
14
+ /** The field took focus from a touch tap: its keys come from the soft keyboard (the return key ends editing). */
15
+ static byTouch = false;
16
+ /** Set by the canvas while it runs a touch release's gestures (a field focused by them was focused by a touch). */
17
+ static TouchGesture = false;
14
18
  static applying = false;
15
19
  /** The textarea (created on first use); KeyboardManager recognizes it through `data-drawnui-text-input`. */
16
20
  static get Element() { return TextInputProxy.element; }
@@ -27,12 +31,13 @@ export class TextInputProxy {
27
31
  el.setAttribute("autocorrect", "off");
28
32
  el.setAttribute("autocapitalize", "off");
29
33
  el.rows = 1;
30
- // fixed 1x1 box over the caret: invisible, still focusable, 16px font keeps iOS from zooming the page
34
+ // a fixed 1x1 box (where it sits: Place): invisible, still focusable, the 16px font keeps iOS from zooming the page
31
35
  el.style.cssText = "position:fixed;left:0;top:0;width:1px;height:1px;padding:0;border:0;margin:0;opacity:0.01;font-size:16px;line-height:1;resize:none;overflow:hidden;outline:none;background:transparent;color:transparent;caret-color:transparent;pointer-events:none;z-index:-1;";
32
36
  el.addEventListener("compositionstart", () => { TextInputProxy.composing = true; });
33
37
  el.addEventListener("compositionend", () => { TextInputProxy.composing = false; TextInputProxy.ApplyFromElement(); });
34
38
  el.addEventListener("input", () => TextInputProxy.ApplyFromElement());
35
39
  el.addEventListener("blur", () => {
40
+ TextInputProxy.keyboardUp = false;
36
41
  // focus moved to another DOM text field (a page input): the drawn editor loses focus like C# BlurExternalTextInput
37
42
  queueMicrotask(() => {
38
43
  const a = document.activeElement;
@@ -41,12 +46,6 @@ export class TextInputProxy {
41
46
  owner.IsFocused = false;
42
47
  });
43
48
  });
44
- // a tap on the canvas moves DOM focus to the body: give it back to the proxy synchronously (keeps the soft keyboard)
45
- window.addEventListener("pointerup", (e) => {
46
- const owner = TextInputProxy.owner;
47
- if (owner && owner.IsFocused && e.target?.tagName === "CANVAS")
48
- el.focus({ preventScroll: true });
49
- }, true);
50
49
  document.body.appendChild(el);
51
50
  return el;
52
51
  }
@@ -57,16 +56,73 @@ export class TextInputProxy {
57
56
  return;
58
57
  TextInputProxy.owner = editor;
59
58
  TextInputProxy.composing = false;
59
+ TextInputProxy.byTouch = TextInputProxy.TouchGesture || !!editor.Superview?.TouchPressed;
60
60
  TextInputProxy.Configure(editor, el);
61
61
  TextInputProxy.Sync(editor);
62
+ // a touch press: the input takes focus in its touchend (FocusFromTap), the only place iOS opens the keyboard from; a
63
+ // focus taken earlier would leave it focused with no keyboard
64
+ if (editor.Superview?.TouchPressed)
65
+ return;
62
66
  el.focus({ preventScroll: true });
67
+ TextInputProxy.focusedNow = true;
68
+ queueMicrotask(() => { TextInputProxy.focusedNow = false; });
69
+ }
70
+ /** The input got DOM focus in the task running now (Attach): a tap that focused the field needs nothing more. */
71
+ static focusedNow = false;
72
+ /**
73
+ * The canvas calls it at the end of a tap's release (the pointerup, the user gesture iOS requires to open the soft
74
+ * keyboard): a tap on the focused field gives its input DOM focus inside that gesture, so the keyboard opens on the first
75
+ * tap and comes back on a tap after the user closed it. A touch anywhere else leaves it as it is: the keyboard the user
76
+ * closed stays closed while the page is scrolled. True when the tap was on the focused field (its input has focus now).
77
+ */
78
+ static FocusFromTap(clientX, clientY, touch = false) {
79
+ const owner = TextInputProxy.owner, el = TextInputProxy.element;
80
+ if (!owner || !el || !owner.IsFocused)
81
+ return false;
82
+ const canvas = owner.Superview?.Element;
83
+ if (!canvas)
84
+ return false;
85
+ const b = canvas.getBoundingClientRect(), k = owner.RenderingScale || 1, r = owner.GetAccessibilityPixelRect();
86
+ const x = (clientX - b.left) * k, y = (clientY - b.top) * k;
87
+ if (x < r.Left || x > r.Right || y < r.Top || y > r.Bottom)
88
+ return false;
89
+ TextInputProxy.byTouch = touch;
90
+ if (!TextInputProxy.focusedNow && !(touch && TextInputProxy.keyboardUp && document.activeElement === el)) {
91
+ // focus() on the input that has focus already does not open the keyboard: take it off and back on, inside the tap
92
+ if (document.activeElement === el)
93
+ el.blur();
94
+ el.focus({ preventScroll: true });
95
+ }
96
+ if (touch)
97
+ TextInputProxy.keyboardUp = true;
98
+ TextInputProxy.Sync(owner);
99
+ return true;
63
100
  }
64
101
  static Detach(editor) {
65
102
  if (TextInputProxy.owner !== editor)
66
103
  return;
67
104
  TextInputProxy.owner = undefined;
68
105
  const el = TextInputProxy.element;
69
- if (el && document.activeElement === el)
106
+ if (!el || document.activeElement !== el)
107
+ return;
108
+ // a touch press may be moving to another field: the input keeps focus (the keyboard stays up, no hide and show) until
109
+ // the touch ends (AfterTouchEnd); with no field then, it lets go
110
+ if (TextInputProxy.TouchGesture || editor.Superview?.TouchPressed) {
111
+ TextInputProxy.blurAfterTouch = true;
112
+ return;
113
+ }
114
+ el.blur();
115
+ }
116
+ static blurAfterTouch = false;
117
+ /** The input has focus from a touch release (its keyboard is up): a tap on another field needs no blur and focus. */
118
+ static keyboardUp = false;
119
+ /** The canvas calls it at the end of each touch release, after FocusFromTap: a field left during the press lets go now. */
120
+ static AfterTouchEnd() {
121
+ if (!TextInputProxy.blurAfterTouch)
122
+ return;
123
+ TextInputProxy.blurAfterTouch = false;
124
+ const el = TextInputProxy.element;
125
+ if (!TextInputProxy.owner && el && document.activeElement === el)
70
126
  el.blur();
71
127
  }
72
128
  static Configure(editor, el) {
@@ -88,16 +144,38 @@ export class TextInputProxy {
88
144
  el.setSelectionRange(start, end);
89
145
  TextInputProxy.Place(editor, el);
90
146
  }
91
- /** Puts the textarea over the editor so mobile browsers scroll the right spot into view. */
147
+ /**
148
+ * Where the hidden input sits: a field focused by a touch keeps it fixed at the top-left corner, never over the field (as
149
+ * the DrawnUi.Net web heads), so iOS never pans the page to reveal it (a scroll with AdaptToKeyboardAuto moves the
150
+ * field above the keyboard); a field focused by a mouse or the keyboard has it over the field, so a desktop input
151
+ * method opens its candidate window next to the text.
152
+ */
92
153
  static Place(editor, el) {
154
+ let left = 0, top = 0;
93
155
  const canvas = editor.Superview?.Element;
94
- if (!canvas)
156
+ if (!TextInputProxy.byTouch && canvas) {
157
+ const b = canvas.getBoundingClientRect(), scale = editor.RenderingScale || 1, r = editor.GetAccessibilityPixelRect();
158
+ left = Math.round(b.left + r.Left / scale);
159
+ top = Math.round(b.top + r.Top / scale);
160
+ }
161
+ if (left === TextInputProxy.placedLeft && top === TextInputProxy.placedTop)
162
+ return;
163
+ TextInputProxy.placedLeft = left;
164
+ TextInputProxy.placedTop = top;
165
+ el.style.left = `${left}px`;
166
+ el.style.top = `${top}px`;
167
+ }
168
+ static placedLeft = 0;
169
+ static placedTop = 0;
170
+ /**
171
+ * After each frame of the canvas: a focused field that moved (its page scrolled) takes its hidden input along, so a
172
+ * desktop input method keeps its window next to the text. Nothing to do while no field is focused.
173
+ */
174
+ static AfterFrame(canvas) {
175
+ const owner = TextInputProxy.owner, el = TextInputProxy.element;
176
+ if (!owner || !el || TextInputProxy.byTouch || owner.Superview !== canvas)
95
177
  return;
96
- const b = canvas.getBoundingClientRect();
97
- const scale = editor.RenderingScale || 1;
98
- const r = editor.DrawingRect;
99
- el.style.left = `${Math.round(b.left + r.Left / scale)}px`;
100
- el.style.top = `${Math.round(b.top + r.Top / scale)}px`;
178
+ TextInputProxy.Place(owner, el);
101
179
  }
102
180
  /** The textarea changed (typing, IME commit, paste, undo): diff against the editor and replay through the stubs. */
103
181
  static ApplyFromElement() {
@@ -130,6 +208,10 @@ export class TextInputProxy {
130
208
  else if (endPrev > start)
131
209
  editor.StubBackspace();
132
210
  editor.StubPressEnter(false, false);
211
+ // the soft keyboard's return key (done / go / search / send) in a single-line field ends editing and closes the
212
+ // keyboard, as a MAUI single-line field; a physical keyboard's Enter keeps the field focused (the Blazor rule)
213
+ if (TextInputProxy.byTouch && !editor.IsMultiline && ["done", "go", "search", "send"].includes(el.enterKeyHint))
214
+ editor.IsFocused = false;
133
215
  }
134
216
  else if (inserted)
135
217
  editor.StubTypeText(inserted);
package/dist/index.d.ts CHANGED
@@ -35,6 +35,7 @@ export * from "./controls/RefreshIndicator";
35
35
  export * from "./core/TextInputProxy";
36
36
  export * from "./core/SkiaEffect";
37
37
  export * from "./controls/SkiaDrawer";
38
+ export * from "./controls/SkiaShell";
38
39
  export * from "./controls/SkiaHotspot";
39
40
  export * from "./controls/SkiaShape";
40
41
  export * from "./controls/SkiaButton";
package/dist/index.js CHANGED
@@ -35,6 +35,7 @@ export * from "./controls/RefreshIndicator";
35
35
  export * from "./core/TextInputProxy";
36
36
  export * from "./core/SkiaEffect";
37
37
  export * from "./controls/SkiaDrawer";
38
+ export * from "./controls/SkiaShell";
38
39
  export * from "./controls/SkiaHotspot";
39
40
  export * from "./controls/SkiaShape";
40
41
  export * from "./controls/SkiaButton";
@@ -1,55 +1,9 @@
1
1
  import { type ReactNode } from "react";
2
- import { Thickness } from "../core/Types";
3
- import type { SkiaControl } from "../core/SkiaControl";
4
- /** Arguments passed to a page (C# GoToAsync arguments / query string), e.g. `GoToAsync("detail", true, { id: 42 })` or `GoToAsync("detail?id=42")`. */
5
- export type ShellArguments = Record<string, unknown>;
2
+ import type { Thickness } from "../core/Types";
3
+ import { type ModalOptions, type PopupOptions, type ShellArguments, type ShellTab, type SkiaShellNavigatedArgs, type SkiaShellNavigatingArgs } from "../controls/SkiaShell";
4
+ export { BuildRoute, ShellDefaults, SplitRoute, type ModalOptions, type NavigationSource, type PopupOptions, type ShellArguments, type ShellTab, type SkiaShellNavigatedArgs, type SkiaShellNavigatingArgs } from "../controls/SkiaShell";
6
5
  /** Route name -> page factory receiving the navigation arguments. Pages are plain JSX, rendered inside the shell when navigated to. */
7
6
  export type ShellRoutes = Record<string, (args: ShellArguments) => ReactNode>;
8
- /** C# NavigationSource. */
9
- export type NavigationSource = "Push" | "Pop";
10
- /** C# SkiaShellNavigatingArgs: set Cancel to stop the navigation. */
11
- export interface SkiaShellNavigatingArgs {
12
- Route: string;
13
- Source: NavigationSource;
14
- Cancel: boolean;
15
- View?: SkiaControl;
16
- Previous?: SkiaControl;
17
- }
18
- /** C# SkiaShellNavigatedArgs. */
19
- export interface SkiaShellNavigatedArgs {
20
- Route: string;
21
- Source: NavigationSource;
22
- View?: SkiaControl;
23
- }
24
- /** "name?a=1&b=2" -> name + arguments (query values are strings). */
25
- export declare function SplitRoute(route: string): {
26
- name: string;
27
- args: ShellArguments;
28
- };
29
- /** name + arguments -> "name?a=1" (only string / number / boolean values travel in the route, the rest stays in memory). */
30
- export declare function BuildRoute(name: string, args?: ShellArguments): string;
31
- /** C# OpenPopupAsync parameters. */
32
- export interface PopupOptions {
33
- animated?: boolean;
34
- /** A tap outside the content closes the popup (default true). */
35
- closeWhenBackgroundTapped?: boolean;
36
- /** Dim + blur the page behind (default true). */
37
- showOverlay?: boolean;
38
- backgroundColor?: string;
39
- }
40
- /** C# PushModalAsync parameters. */
41
- export interface ModalOptions {
42
- /** The modal can be dragged down to close (default false). */
43
- useGestures?: boolean;
44
- animated?: boolean;
45
- /** Dim + blur the page behind (C# freezeBackground; the frozen screenshot is not ported). */
46
- freezeBackground?: boolean;
47
- }
48
- /** A shell tab: its root route and the label shown in the tab bar. */
49
- export interface ShellTab {
50
- route: string;
51
- title: string;
52
- }
53
7
  /** Navigation API, same verbs as DrawnUi SkiaShell. */
54
8
  export interface ShellNavigation {
55
9
  /** Pushes a registered route; `route` may carry a query ("detail?id=42") and/or explicit arguments (C# GoToAsync(route, animate, arguments)). */
@@ -114,31 +68,11 @@ export interface SkiaShellProps {
114
68
  /** Safe-area insets (points) reserved above the nav bar and below the tab bar; default Super.Insets (C# Super.Insets). */
115
69
  Insets?: Thickness;
116
70
  }
117
- /** C# SkiaShell static defaults (mutable). */
118
- export declare const ShellDefaults: {
119
- ToastBackgroundColor: string;
120
- ToastTextColor: "#FFFFFF";
121
- ToastTextFont: string;
122
- ToastTextSize: number;
123
- ToastTextMargins: number;
124
- /** Default overlay tint behind popups / modals. */
125
- PopupBackgroundColor: string;
126
- /** Backdrop blur behind popups / modals, points. */
127
- PopupsBackgroundBlur: number;
128
- PopupsAnimationSpeed: number;
129
- PopupsCancelAnimationsAfterMs: number;
130
- ZIndexModals: number;
131
- ZIndexPopups: number;
132
- ZIndexToasts: number;
133
- /** Accent of the selected tab. */
134
- TabSelectedColor: string;
135
- TabColor: string;
136
- };
137
71
  /**
138
- * Mirrors DrawnUi SkiaShell at the React level: a root page (or tabs) plus per-tab stacks of routed pages drawn
139
- * inside one SkiaLayer with a nav bar (pages slide in/out like SkiaViewSwitcher), popups (blurred + dimmed
140
- * backdrop, scale + fade, tap outside to close), modals (full-screen SkiaDrawer from the bottom, optionally
141
- * draggable), toasts (bottom banner, slide + fade, auto close). Pages live in the URL hash and the browser back
142
- * button behaves like C# GoBack (popup, then modal, then page). Navigation via ref or useShell().
72
+ * DrawnUi SkiaShell for React: the engine SkiaShell ("drawnui-react/core") with JSX content. A root page (or tabs) plus
73
+ * per-tab stacks of routed pages with a nav bar (pages slide in/out like SkiaViewSwitcher), popups (blurred + dimmed
74
+ * backdrop, scale + fade, tap outside to close), modals (full-screen SkiaDrawer from the bottom, optionally draggable),
75
+ * toasts (bottom banner, slide + fade, auto close). Pages live in the URL hash and the browser back button behaves like
76
+ * C# GoBack (popup, then modal, then page). Navigation via ref or useShell().
143
77
  */
144
78
  export declare const SkiaShell: import("react").ForwardRefExoticComponent<SkiaShellProps & import("react").RefAttributes<ShellNavigation>>;