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.
- package/SKIPPED.md +3 -0
- package/dist/controls/SkiaButton.js +2 -2
- package/dist/controls/SkiaCarousel.js +31 -3
- package/dist/controls/SkiaCheckbox.js +2 -1
- package/dist/controls/SkiaEditor.d.ts +4 -0
- package/dist/controls/SkiaEditor.js +16 -4
- package/dist/controls/SkiaLabel.d.ts +2 -0
- package/dist/controls/SkiaLabel.js +2 -0
- package/dist/controls/SkiaLayout.d.ts +2 -0
- package/dist/controls/SkiaLayout.js +2 -0
- package/dist/controls/SkiaProgress.js +2 -2
- package/dist/controls/SkiaRadioButton.js +2 -1
- package/dist/controls/SkiaShaderCarousel.js +5 -0
- package/dist/controls/SkiaSlider.js +2 -2
- package/dist/controls/SkiaSwitch.js +4 -2
- package/dist/controls/TooltipStyle.d.ts +52 -0
- package/dist/controls/TooltipStyle.js +88 -0
- package/dist/core/Accessibility.d.ts +30 -0
- package/dist/core/Accessibility.js +162 -3
- package/dist/core/Canvas.d.ts +76 -3
- package/dist/core/Canvas.js +239 -8
- package/dist/core/ControlStyle.d.ts +2 -0
- package/dist/core/ControlStyle.js +2 -0
- package/dist/core/Hover.d.ts +4 -0
- package/dist/core/Hover.js +6 -0
- package/dist/core/KeyboardManager.d.ts +7 -0
- package/dist/core/KeyboardManager.js +35 -4
- package/dist/core/PopupWindows.d.ts +92 -0
- package/dist/core/PopupWindows.js +203 -0
- package/dist/core/SkiaControl.d.ts +30 -0
- package/dist/core/SkiaControl.js +60 -3
- package/dist/core/Super.d.ts +7 -0
- package/dist/core/Super.js +7 -0
- package/dist/core/Tooltips.d.ts +71 -0
- package/dist/core/Tooltips.js +205 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/react/index.d.ts +16 -1
- package/dist/react/index.js +51 -11
- package/dist/react/reconciler.d.ts +2 -0
- package/dist/react/reconciler.js +5 -0
- package/package.json +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -10,10 +10,13 @@ export * from "./core/Canvas";
|
|
|
10
10
|
export * from "./controls/SkiaLayout";
|
|
11
11
|
export * from "./core/Accessibility";
|
|
12
12
|
export * from "./core/Hover";
|
|
13
|
+
export * from "./core/Tooltips";
|
|
14
|
+
export * from "./core/PopupWindows";
|
|
13
15
|
export * from "./controls/SkiaLabel";
|
|
14
16
|
export * from "./controls/TextSpan";
|
|
15
17
|
export * from "./controls/SkiaRichLabel";
|
|
16
18
|
export * from "./controls/SkiaLabelFps";
|
|
19
|
+
export * from "./controls/TooltipStyle";
|
|
17
20
|
export * from "./core/ControlStyle";
|
|
18
21
|
export * from "./core/ImageEffects";
|
|
19
22
|
export * from "./controls/SkiaToggle";
|
package/dist/index.js
CHANGED
|
@@ -10,10 +10,13 @@ export * from "./core/Canvas";
|
|
|
10
10
|
export * from "./controls/SkiaLayout";
|
|
11
11
|
export * from "./core/Accessibility";
|
|
12
12
|
export * from "./core/Hover";
|
|
13
|
+
export * from "./core/Tooltips";
|
|
14
|
+
export * from "./core/PopupWindows";
|
|
13
15
|
export * from "./controls/SkiaLabel";
|
|
14
16
|
export * from "./controls/TextSpan";
|
|
15
17
|
export * from "./controls/SkiaRichLabel";
|
|
16
18
|
export * from "./controls/SkiaLabelFps";
|
|
19
|
+
export * from "./controls/TooltipStyle";
|
|
17
20
|
export * from "./core/ControlStyle";
|
|
18
21
|
export * from "./core/ImageEffects";
|
|
19
22
|
export * from "./controls/SkiaToggle";
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type CSSProperties, type FC, type ReactNode, type Ref } from "react";
|
|
2
2
|
import { Canvas as CanvasView } from "../core/Canvas";
|
|
3
3
|
import type { SkiaControl } from "../core/SkiaControl";
|
|
4
|
+
import type { PopupAnchor, PopupId, PopupWindowOptions } from "../core/PopupWindows";
|
|
5
|
+
import type { SKPoint } from "../core/Gestures";
|
|
6
|
+
import type { SKRect } from "../core/Types";
|
|
4
7
|
import type { Thickness, ThicknessValue } from "../core/Types";
|
|
5
8
|
import type { SkiaLabel as SkiaLabelCtrl } from "../controls/SkiaLabel";
|
|
6
9
|
import type { TextSpan as TextSpanCtrl } from "../controls/TextSpan";
|
|
@@ -111,6 +114,8 @@ export interface CanvasProps {
|
|
|
111
114
|
* scrolls it unless a control used the wheel. A page that cannot scroll keeps every touch. Lock keeps all input.
|
|
112
115
|
*/
|
|
113
116
|
Gestures?: GesturesMode;
|
|
117
|
+
/** While nothing has keyboard focus, an arrow key starts keyboard navigation as the first Tab does (off by default: games keep their arrows). */
|
|
118
|
+
ArrowsStartKeyboardNavigation?: boolean;
|
|
114
119
|
children?: ReactNode;
|
|
115
120
|
style?: CSSProperties;
|
|
116
121
|
className?: string;
|
|
@@ -123,11 +128,21 @@ export interface CanvasProps {
|
|
|
123
128
|
/** DrawnView.WasDrawn: after every drawn frame. */
|
|
124
129
|
WasDrawn?: CanvasView["WasDrawn"];
|
|
125
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Opens a popup window (drawnui-cross 6at) whose content is drawn elements, e.g. a menu:
|
|
133
|
+
* `OpenPopupWindow(canvas, <SkiaShape ...>...</SkiaShape>, e.Location)`. The elements are rendered at once in a React
|
|
134
|
+
* root of their own and unmounted when the popup closes; the anchor is a point (canvas points), a rect, a control or a
|
|
135
|
+
* `PopupAnchor`. Returns the popup's id (for `canvas.ClosePopupWindow`).
|
|
136
|
+
*/
|
|
137
|
+
export declare function OpenPopupWindow(canvas: CanvasView, content: ReactNode, anchor: PopupAnchor | SKPoint | SKRect | SkiaControl | {
|
|
138
|
+
X: number;
|
|
139
|
+
Y: number;
|
|
140
|
+
}, options?: PopupWindowOptions): PopupId;
|
|
126
141
|
/**
|
|
127
142
|
* Mirrors DrawnUi Canvas: the bridge between the DOM (react-dom) and the drawn tree (DrawnUi reconciler).
|
|
128
143
|
* Requires Super.UseDrawnUi()...BuildAsync() to have completed.
|
|
129
144
|
*/
|
|
130
|
-
export declare function Canvas({ BackgroundColor, RenderingMode, Gestures, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }: CanvasProps): import("react").JSX.Element;
|
|
145
|
+
export declare function Canvas({ BackgroundColor, RenderingMode, Gestures, ArrowsStartKeyboardNavigation, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }: CanvasProps): import("react").JSX.Element;
|
|
131
146
|
export type { SkiaControl };
|
|
132
147
|
export * from "../index";
|
|
133
148
|
export * from "./SkiaShell";
|
package/dist/react/index.js
CHANGED
|
@@ -68,11 +68,36 @@ function removeStaticContent() {
|
|
|
68
68
|
for (const el of document.querySelectorAll("[data-drawnui-static]"))
|
|
69
69
|
el.remove();
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Opens a popup window (drawnui-cross 6at) whose content is drawn elements, e.g. a menu:
|
|
73
|
+
* `OpenPopupWindow(canvas, <SkiaShape ...>...</SkiaShape>, e.Location)`. The elements are rendered at once in a React
|
|
74
|
+
* root of their own and unmounted when the popup closes; the anchor is a point (canvas points), a rect, a control or a
|
|
75
|
+
* `PopupAnchor`. Returns the popup's id (for `canvas.ClosePopupWindow`).
|
|
76
|
+
*/
|
|
77
|
+
export function OpenPopupWindow(canvas, content, anchor, options) {
|
|
78
|
+
const holder = { Content: undefined };
|
|
79
|
+
const root = createDrawnRoot(holder);
|
|
80
|
+
root.renderSync(content);
|
|
81
|
+
const control = holder.Content;
|
|
82
|
+
if (!control) {
|
|
83
|
+
root.unmount();
|
|
84
|
+
throw new Error("DrawnUi: OpenPopupWindow content rendered no control");
|
|
85
|
+
}
|
|
86
|
+
const id = canvas.OpenPopupWindow(control, anchor, options);
|
|
87
|
+
const closed = (which) => {
|
|
88
|
+
if (which !== id)
|
|
89
|
+
return;
|
|
90
|
+
canvas.PopupWindowClosed.delete(closed);
|
|
91
|
+
root.unmount();
|
|
92
|
+
};
|
|
93
|
+
canvas.PopupWindowClosed.add(closed);
|
|
94
|
+
return id;
|
|
95
|
+
}
|
|
71
96
|
/**
|
|
72
97
|
* Mirrors DrawnUi Canvas: the bridge between the DOM (react-dom) and the drawn tree (DrawnUi reconciler).
|
|
73
98
|
* Requires Super.UseDrawnUi()...BuildAsync() to have completed.
|
|
74
99
|
*/
|
|
75
|
-
export function Canvas({ BackgroundColor, RenderingMode, Gestures, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }) {
|
|
100
|
+
export function Canvas({ BackgroundColor, RenderingMode, Gestures, ArrowsStartKeyboardNavigation, children, style, className, ref: viewRef, ContextMenu, WillFirstTimeDraw, WasDrawn }) {
|
|
76
101
|
const ref = useRef(null);
|
|
77
102
|
const view = useRef(null);
|
|
78
103
|
const root = useRef(null);
|
|
@@ -102,13 +127,16 @@ export function Canvas({ BackgroundColor, RenderingMode, Gestures, children, sty
|
|
|
102
127
|
v.Update();
|
|
103
128
|
}
|
|
104
129
|
v.Gestures = Gestures ?? "Disabled";
|
|
130
|
+
v.ArrowsStartKeyboardNavigation = ArrowsStartKeyboardNavigation ?? false;
|
|
105
131
|
v.ContextMenu = ContextMenu;
|
|
106
132
|
v.WillFirstTimeDraw = WillFirstTimeDraw;
|
|
107
133
|
v.WasDrawn = WasDrawn;
|
|
108
134
|
root.current.render(children);
|
|
109
135
|
});
|
|
110
|
-
// The drawn surface is aria-hidden; the overlay is the accessibility tree (DrawnUi.Blazor pattern).
|
|
111
|
-
|
|
136
|
+
// The drawn surface is aria-hidden; the overlay is the accessibility tree (DrawnUi.Blazor pattern). The host takes the
|
|
137
|
+
// DOM focus (from code only, no ring) when the focused control leaves: no control is focused and the keys belong to the
|
|
138
|
+
// app, as in the other engines, while a screen reader stays at the canvas instead of the top of the page.
|
|
139
|
+
return (_jsxs("div", { className: className, tabIndex: -1, "data-drawnui-host": "1", style: { position: "relative", outline: "none", ...style }, children: [_jsx("canvas", { ref: ref, "aria-hidden": true, style: { display: "block", width: "100%", height: "100%" } }), engine && _jsx(AccessibilityOverlay, { view: engine })] }));
|
|
112
140
|
}
|
|
113
141
|
const A11Y_CSS = `
|
|
114
142
|
.drawnui-a11y-overlay{position:absolute;inset:0;overflow:hidden;pointer-events:none;user-select:none;-webkit-user-select:none}
|
|
@@ -155,22 +183,21 @@ function AccessibilityOverlay({ view }) {
|
|
|
155
183
|
setFocusRequest(undefined);
|
|
156
184
|
elementOf(focusRequest.id)?.focus({ preventScroll: true });
|
|
157
185
|
}, [focusRequest]);
|
|
158
|
-
// the focused node went away (its page or popup closed): the focus
|
|
159
|
-
//
|
|
186
|
+
// the focused node went away (its page or popup closed): no control keeps the focus and its ring goes with it, the keys
|
|
187
|
+
// belong to the app again (as in the other engines); the DOM focus stays on the canvas host, so a screen reader is not
|
|
188
|
+
// thrown to the top of the page and the next Tab starts from the canvas. A focus the user moved away stays away.
|
|
160
189
|
const focusedId = useRef(0);
|
|
161
190
|
useLayoutEffect(() => {
|
|
162
191
|
const id = focusedId.current;
|
|
163
192
|
if (!id || nodes.some((n) => n.Id === id))
|
|
164
193
|
return;
|
|
165
194
|
focusedId.current = 0;
|
|
195
|
+
if (view.AccessibilityManager.FocusedNode?.AccessibilityId === id)
|
|
196
|
+
view.AccessibilityManager.NotifyFocused(undefined);
|
|
166
197
|
const active = document.activeElement;
|
|
167
198
|
if (active && active !== document.body)
|
|
168
199
|
return;
|
|
169
|
-
|
|
170
|
-
const first = nodes.find((n) => n.CanInteract && view.AccessibilityManager.IsTabStop(n.Source)
|
|
171
|
-
&& (!box || (n.Rect.Bottom > 0 && n.Rect.Top < box.height && n.Rect.Right > 0 && n.Rect.Left < box.width)));
|
|
172
|
-
if (first)
|
|
173
|
-
elementOf(first.Id)?.focus({ preventScroll: true });
|
|
200
|
+
overlayRef.current?.parentElement?.focus({ preventScroll: true });
|
|
174
201
|
}, [nodes]);
|
|
175
202
|
// Tab / Shift+Tab in a text field leave it for the next node, also after a click into it: DOM focus goes to the
|
|
176
203
|
// field's own element (without taking the caret again) and the browser's Tab moves on from there
|
|
@@ -220,7 +247,13 @@ function AccessibilityOverlay({ view }) {
|
|
|
220
247
|
return null;
|
|
221
248
|
// the browser scrolls an overflow:hidden container to reveal a focused child; the overlay must stay pinned to the canvas
|
|
222
249
|
const pin = (e) => { e.currentTarget.scrollTop = 0; e.currentTarget.scrollLeft = 0; };
|
|
223
|
-
|
|
250
|
+
// an active modal (drawnui-cross 6av): the overlay itself is the dialog (role, name, aria-modal) around the dialog's
|
|
251
|
+
// controls, which are its elements; aria-modal on a separate element of this flat overlay would hide them
|
|
252
|
+
const modal = view.AccessibilityManager.ActiveModal;
|
|
253
|
+
const modalNode = modal ? nodes.find((n) => n.Source === modal) : undefined;
|
|
254
|
+
return (_jsxs("div", { className: "drawnui-a11y-overlay", onScroll: pin, ref: overlayRef, role: modal ? modalNode?.Role ?? "dialog" : undefined, "aria-label": modalNode?.Label, "aria-modal": modal ? true : undefined, children: [_jsx("style", { children: A11Y_CSS }), nodes.map((n) => {
|
|
255
|
+
if (n === modalNode)
|
|
256
|
+
return null;
|
|
224
257
|
const pos = { left: n.Rect.Left, top: n.Rect.Top, width: n.Rect.Width, height: n.Rect.Height };
|
|
225
258
|
const activate = () => SkiaAccessibilityManager.Activate(n.Source);
|
|
226
259
|
return n.CanInteract ? (_jsx("div", { "data-a11y-id": n.Id, role: n.Role, "aria-label": n.Label, title: n.Hint, ...valueAttributes(n), "aria-pressed": n.Role === "button" ? n.IsPressed : undefined, "aria-checked": n.Role === "switch" || n.Role === "checkbox" || n.Role === "radio" ? n.IsPressed : undefined, "aria-live": n.Live, tabIndex: view.AccessibilityManager.IsTabStop(n.Source) ? 0 : -1, className: "drawnui-a11y-node", style: { ...pos, fontSize: 0, userSelect: "none" }, onClick: activate, onKeyDown: (e) => {
|
|
@@ -228,6 +261,13 @@ function AccessibilityOverlay({ view }) {
|
|
|
228
261
|
e.preventDefault();
|
|
229
262
|
activate();
|
|
230
263
|
}
|
|
264
|
+
else if (e.key === "Tab" && view.AccessibilityManager.KeyboardScope) {
|
|
265
|
+
// an open popup window keeps the keyboard: Tab goes round its stops (a menu is one stop)
|
|
266
|
+
e.preventDefault();
|
|
267
|
+
const next = view.AccessibilityManager.NextTabStop(n.Source, !e.shiftKey);
|
|
268
|
+
if (next)
|
|
269
|
+
elementOf(next.AccessibilityId)?.focus({ preventScroll: true });
|
|
270
|
+
}
|
|
231
271
|
else if (NAVIGATION_KEYS.has(e.key) && SkiaAccessibilityManager.Key(n.Source, e.key))
|
|
232
272
|
e.preventDefault();
|
|
233
273
|
}, onFocus: (e) => {
|
|
@@ -9,6 +9,8 @@ export declare const Registry: Record<string, new () => HostInstance>;
|
|
|
9
9
|
/** Creates a React root whose container is an engine Canvas. */
|
|
10
10
|
export declare function createDrawnRoot(canvas: Canvas): {
|
|
11
11
|
render(children: ReactNode): void;
|
|
12
|
+
/** Renders and commits now: the container holds the drawn controls when it returns. */
|
|
13
|
+
renderSync(children: ReactNode): void;
|
|
12
14
|
unmount(): void;
|
|
13
15
|
};
|
|
14
16
|
export {};
|
package/dist/react/reconciler.js
CHANGED
|
@@ -177,6 +177,11 @@ export function createDrawnRoot(canvas) {
|
|
|
177
177
|
const container = reconciler.createContainer(canvas, ConcurrentRoot, null, false, null, "", onError, onError, onError, noop, null);
|
|
178
178
|
return {
|
|
179
179
|
render(children) { reconciler.updateContainer(children, container, null, null); },
|
|
180
|
+
/** Renders and commits now: the container holds the drawn controls when it returns. */
|
|
181
|
+
renderSync(children) {
|
|
182
|
+
const r = reconciler;
|
|
183
|
+
r.flushSyncFromReconciler(() => reconciler.updateContainer(children, container, null, null));
|
|
184
|
+
},
|
|
180
185
|
unmount() { reconciler.updateContainer(null, container, null, null); },
|
|
181
186
|
};
|
|
182
187
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drawnui-react",
|
|
3
|
-
"version": "0.1.0-preview.
|
|
3
|
+
"version": "0.1.0-preview.37",
|
|
4
4
|
"description": "DrawnUi for React: the DrawnUi (.NET) drawn-UI engine in TypeScript on CanvasKit (Skia WASM). Same controls, same PascalCase API as DrawnUi.Net.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Nick Kovalsky (AppoMobi)",
|
|
@@ -90,6 +90,8 @@
|
|
|
90
90
|
"check:label-direction": "node dev/check.mjs dev/check-label-direction.ts",
|
|
91
91
|
"check:stack-fit": "node dev/check.mjs dev/check-stack-fit.ts",
|
|
92
92
|
"check:label-reuse": "node dev/check.mjs dev/check-label-reuse.ts",
|
|
93
|
+
"check:popups-tooltips": "node dev/check.mjs dev/check-popups-tooltips.ts",
|
|
94
|
+
"check:carousel-loop": "node dev/check.mjs dev/check-carousel-loop.ts",
|
|
93
95
|
"bench:relayout": "node dev/check.mjs dev/bench-relayout.ts",
|
|
94
96
|
"site:extras": "node dev/site-extras.mjs dist/demo",
|
|
95
97
|
"build:lib": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|