drawnui-react 0.1.0-preview.39 → 0.1.0-preview.40
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/README.md +11 -1
- package/dist/controls/SkiaEditor.d.ts +4 -1
- package/dist/controls/SkiaEditor.js +24 -2
- package/dist/core/Canvas.d.ts +16 -0
- package/dist/core/Canvas.js +43 -0
- package/dist/react/index.js +2 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -49,6 +49,16 @@ property names, layout and drawing rules. What you learn here works there, and s
|
|
|
49
49
|
|
|
50
50
|
DrawnUI is MIT licensed in every language and on every platform: desktop, mobile, web and embedded devices. Ship it in commercial products with no attribution badge, no about screen and no per-device royalty.
|
|
51
51
|
|
|
52
|
+
## What's new in 0.1.0-preview.40
|
|
53
|
+
|
|
54
|
+
- **Context menus from the keyboard:** the Menu key, Shift+F10 and a screen reader's context-menu command (VoiceOver
|
|
55
|
+
VO+Shift+M) open the context menu of the control in keyboard focus, at its center, from that control or the first one
|
|
56
|
+
above it with a `ContextMenu` handler, then the `Canvas` one; `e.Source` is `"keyboard"`. Controls with a context
|
|
57
|
+
menu are reachable without a mouse.
|
|
58
|
+
- **Editor caret and the window:** a focused `SkiaEditor` keeps its focus while the browser window or tab is inactive,
|
|
59
|
+
its caret hidden and still (no redraws); when the window gets the keyboard back the caret shows again in the same
|
|
60
|
+
field. `Canvas.IsWindowActive` and `Canvas.WindowActiveChanged` tell your own controls the same.
|
|
61
|
+
|
|
52
62
|
## What's new in 0.1.0-preview.39
|
|
53
63
|
|
|
54
64
|
- **Tap feedback for the primary pointer:** tap and press animations (`AnimationTapped="Ripple"`, `SkiaButton`'s press
|
|
@@ -161,7 +171,7 @@ The request is routed like a tap: deepest visible control under the point first
|
|
|
161
171
|
parents, then the `Canvas` prop. The first handler returning `true` takes it and the browser menu is suppressed;
|
|
162
172
|
with no handler the browser menu shows as before. `e` carries `Location` (points on the canvas), `Pixels`, `Local`
|
|
163
173
|
(pixels inside the handling control), `Source` (`"mouse"`, `"touch"` for a long press, `"keyboard"` for the Menu
|
|
164
|
-
key) and `Native` (the DOM event, for modifiers). Web-only: DrawnUi.Net has no mouse buttons.
|
|
174
|
+
key or Shift+F10 on the control in keyboard focus, opened at its center) and `Native` (the DOM event, for modifiers). Web-only: DrawnUi.Net has no mouse buttons.
|
|
165
175
|
|
|
166
176
|
## Menu bar
|
|
167
177
|
|
|
@@ -113,7 +113,7 @@ export declare class SkiaEditor extends SkiaShape {
|
|
|
113
113
|
set CursorPosition(v: number);
|
|
114
114
|
get SelectionLength(): number;
|
|
115
115
|
set SelectionLength(v: number);
|
|
116
|
-
/** Shows the caret for a full half second, then blinks every 500 ms. */
|
|
116
|
+
/** Shows the caret for a full half second, then blinks every 500 ms; while the window is inactive no caret, no timer. */
|
|
117
117
|
private StartBlink;
|
|
118
118
|
private StopBlink;
|
|
119
119
|
private OnCursorMoved;
|
|
@@ -180,6 +180,9 @@ export declare class SkiaEditor extends SkiaShape {
|
|
|
180
180
|
PasteFromClipboard(): void;
|
|
181
181
|
private ReplaceSelection;
|
|
182
182
|
private SetFocusNative;
|
|
183
|
+
private windowCanvas?;
|
|
184
|
+
/** The window lost the keyboard: the caret hides and stops blinking (no redraws); back: it shows again in this field. */
|
|
185
|
+
private readonly onWindowActive;
|
|
183
186
|
/** Removed from the canvas while focused: the editing ends (caret timer, keys, text proxy). */
|
|
184
187
|
OnLeftCanvas(): void;
|
|
185
188
|
private OnKeyDown;
|
|
@@ -200,10 +200,13 @@ export class SkiaEditor extends SkiaShape {
|
|
|
200
200
|
this.selectionLength = l;
|
|
201
201
|
this.OnCursorMoved();
|
|
202
202
|
}
|
|
203
|
-
/** Shows the caret for a full half second, then blinks every 500 ms. */
|
|
203
|
+
/** Shows the caret for a full half second, then blinks every 500 ms; while the window is inactive no caret, no timer. */
|
|
204
204
|
StartBlink() {
|
|
205
205
|
this.StopBlink();
|
|
206
|
-
|
|
206
|
+
const canvas = this.Superview;
|
|
207
|
+
this.caretVisible = canvas?.IsWindowActive !== false;
|
|
208
|
+
if (!this.caretVisible)
|
|
209
|
+
return;
|
|
207
210
|
this.blinkTimer = window.setInterval(() => { this.caretVisible = !this.caretVisible; this.InvalidateCache(); this.RepaintComposition(); }, 500);
|
|
208
211
|
}
|
|
209
212
|
StopBlink() { if (this.blinkTimer) {
|
|
@@ -725,13 +728,32 @@ export class SkiaEditor extends SkiaShape {
|
|
|
725
728
|
KeyboardManager.BlurExternalTextInput();
|
|
726
729
|
TextInputProxy.Attach(this);
|
|
727
730
|
CanvasLeaveWatchers.add(this);
|
|
731
|
+
this.windowCanvas = this.Superview;
|
|
732
|
+
this.windowCanvas?.WindowActiveChanged?.add(this.onWindowActive);
|
|
728
733
|
}
|
|
729
734
|
else {
|
|
730
735
|
TextInputProxy.Detach(this);
|
|
731
736
|
KeyboardManager.Unsubscribe(this.onKeyDown, this.onKeyChar);
|
|
732
737
|
CanvasLeaveWatchers.delete(this);
|
|
738
|
+
this.windowCanvas?.WindowActiveChanged?.delete(this.onWindowActive);
|
|
739
|
+
this.windowCanvas = undefined;
|
|
733
740
|
}
|
|
734
741
|
}
|
|
742
|
+
// the window the editor is focused in (C# WindowActiveChanged, subscribed only while focused)
|
|
743
|
+
windowCanvas;
|
|
744
|
+
/** The window lost the keyboard: the caret hides and stops blinking (no redraws); back: it shows again in this field. */
|
|
745
|
+
onWindowActive = (active) => {
|
|
746
|
+
if (!this.isFocused)
|
|
747
|
+
return;
|
|
748
|
+
if (active)
|
|
749
|
+
this.StartBlink();
|
|
750
|
+
else {
|
|
751
|
+
this.StopBlink();
|
|
752
|
+
this.caretVisible = false;
|
|
753
|
+
}
|
|
754
|
+
this.InvalidateCache();
|
|
755
|
+
this.RepaintComposition();
|
|
756
|
+
};
|
|
735
757
|
/** Removed from the canvas while focused: the editing ends (caret timer, keys, text proxy). */
|
|
736
758
|
OnLeftCanvas() { this.IsFocused = false; }
|
|
737
759
|
OnKeyDown(key, e) {
|
package/dist/core/Canvas.d.ts
CHANGED
|
@@ -104,11 +104,21 @@ export declare class Canvas {
|
|
|
104
104
|
get TopPopupWindow(): SkiaControl | undefined;
|
|
105
105
|
/** The window stopped being active (blur): popup windows and the tooltip close, as native menus do. */
|
|
106
106
|
OnWindowDeactivated(): void;
|
|
107
|
+
/**
|
|
108
|
+
* The browser window (tab) has the keyboard (C# DrawnView.IsWindowActive): false after its blur, true again after its
|
|
109
|
+
* focus. A focused editor hides its caret while it is false.
|
|
110
|
+
*/
|
|
111
|
+
IsWindowActive: boolean;
|
|
112
|
+
/** Raised when IsWindowActive changes (C# WindowActiveChanged). */
|
|
113
|
+
readonly WindowActiveChanged: Set<(active: boolean) => void>;
|
|
114
|
+
private SetWindowActive;
|
|
107
115
|
RaisePopupWindowClosed(id: PopupId): void;
|
|
108
116
|
private AfterPopupsChanged;
|
|
109
117
|
private readonly onPopupKey;
|
|
110
118
|
private HookPopupKeys;
|
|
111
119
|
private readonly onWindowBlur;
|
|
120
|
+
private readonly onWindowInactive;
|
|
121
|
+
private readonly onWindowActive;
|
|
112
122
|
private content?;
|
|
113
123
|
get Content(): SkiaControl | undefined;
|
|
114
124
|
set Content(value: SkiaControl | undefined);
|
|
@@ -220,6 +230,12 @@ export declare class Canvas {
|
|
|
220
230
|
ContextMenu?: (sender: Canvas, e: ContextMenuEventArgs) => boolean | void;
|
|
221
231
|
/** DOM contextmenu (right click / long press / Menu key) -> ContextMenuEventArgs routed through the tree like a tap. */
|
|
222
232
|
private readonly onContextMenu;
|
|
233
|
+
/**
|
|
234
|
+
* The Menu key, Shift+F10 or a screen reader's context-menu command on the control in keyboard focus (the DOM
|
|
235
|
+
* `contextmenu` of its overlay node): its context menu opens at its center, from it or the first control above it with
|
|
236
|
+
* a ContextMenu handler, then the Canvas' own (Source "keyboard", as every DrawnUI engine). True when one took it.
|
|
237
|
+
*/
|
|
238
|
+
OpenContextMenuFromKeyboard(control: SkiaControl, native: MouseEvent): boolean;
|
|
223
239
|
private cursorPointer;
|
|
224
240
|
/**
|
|
225
241
|
* DrawnUi.Blazor shows `cursor: pointer` over interactive controls through its overlay elements; here the overlay
|
package/dist/core/Canvas.js
CHANGED
|
@@ -117,6 +117,20 @@ export class Canvas {
|
|
|
117
117
|
get TopPopupWindow() { return this.popups.TopInteractive; }
|
|
118
118
|
/** The window stopped being active (blur): popup windows and the tooltip close, as native menus do. */
|
|
119
119
|
OnWindowDeactivated() { this.ClosePopupWindows(); this.tooltip.CloseOnInput(); }
|
|
120
|
+
/**
|
|
121
|
+
* The browser window (tab) has the keyboard (C# DrawnView.IsWindowActive): false after its blur, true again after its
|
|
122
|
+
* focus. A focused editor hides its caret while it is false.
|
|
123
|
+
*/
|
|
124
|
+
IsWindowActive = typeof document === "undefined" || typeof document.hasFocus !== "function" || document.hasFocus();
|
|
125
|
+
/** Raised when IsWindowActive changes (C# WindowActiveChanged). */
|
|
126
|
+
WindowActiveChanged = new Set();
|
|
127
|
+
SetWindowActive(active) {
|
|
128
|
+
if (this.IsWindowActive === active)
|
|
129
|
+
return;
|
|
130
|
+
this.IsWindowActive = active;
|
|
131
|
+
for (const h of [...this.WindowActiveChanged])
|
|
132
|
+
h(active);
|
|
133
|
+
}
|
|
120
134
|
RaisePopupWindowClosed(id) { for (const h of [...this.PopupWindowClosed])
|
|
121
135
|
h(id); }
|
|
122
136
|
AfterPopupsChanged() {
|
|
@@ -141,6 +155,9 @@ export class Canvas {
|
|
|
141
155
|
KeyboardManager.UnsubscribeNavigation(this.onPopupKey);
|
|
142
156
|
}
|
|
143
157
|
onWindowBlur = () => this.OnWindowDeactivated();
|
|
158
|
+
// IsWindowActive follows the window for the canvas' whole life, input on or off (a focused editor needs it)
|
|
159
|
+
onWindowInactive = () => this.SetWindowActive(false);
|
|
160
|
+
onWindowActive = () => this.SetWindowActive(true);
|
|
144
161
|
content;
|
|
145
162
|
get Content() { return this.content; }
|
|
146
163
|
set Content(value) {
|
|
@@ -178,6 +195,8 @@ export class Canvas {
|
|
|
178
195
|
init?.(this);
|
|
179
196
|
Element.addEventListener("webglcontextlost", this.onContextLost);
|
|
180
197
|
Element.addEventListener("webglcontextrestored", this.onContextRestored);
|
|
198
|
+
window.addEventListener("blur", this.onWindowInactive);
|
|
199
|
+
window.addEventListener("focus", this.onWindowActive);
|
|
181
200
|
this.Hover.RootAt = (x, y) => this.popupLayer?.At(x, y) ?? this.content;
|
|
182
201
|
this.observer = new ResizeObserver(() => this.OnResized());
|
|
183
202
|
this.observer.observe(Element);
|
|
@@ -500,6 +519,9 @@ export class Canvas {
|
|
|
500
519
|
}
|
|
501
520
|
this.Element.removeEventListener("webglcontextlost", this.onContextLost);
|
|
502
521
|
this.Element.removeEventListener("webglcontextrestored", this.onContextRestored);
|
|
522
|
+
window.removeEventListener("blur", this.onWindowInactive);
|
|
523
|
+
window.removeEventListener("focus", this.onWindowActive);
|
|
524
|
+
this.WindowActiveChanged.clear();
|
|
503
525
|
this.Gestures = "Disabled";
|
|
504
526
|
this.ArrowsStartKeyboardNavigation = false;
|
|
505
527
|
this.tooltipController?.Dispose();
|
|
@@ -628,6 +650,27 @@ export class Canvas {
|
|
|
628
650
|
if (handled)
|
|
629
651
|
e.preventDefault();
|
|
630
652
|
};
|
|
653
|
+
/**
|
|
654
|
+
* The Menu key, Shift+F10 or a screen reader's context-menu command on the control in keyboard focus (the DOM
|
|
655
|
+
* `contextmenu` of its overlay node): its context menu opens at its center, from it or the first control above it with
|
|
656
|
+
* a ContextMenu handler, then the Canvas' own (Source "keyboard", as every DrawnUI engine). True when one took it.
|
|
657
|
+
*/
|
|
658
|
+
OpenContextMenuFromKeyboard(control, native) {
|
|
659
|
+
const r = control.GetAccessibilityPixelRect(), scale = this.RenderingScale;
|
|
660
|
+
const pixels = new SKPoint((r.Left + r.Right) / 2, (r.Top + r.Bottom) / 2);
|
|
661
|
+
const args = new ContextMenuEventArgs(new SKPoint(pixels.X / scale, pixels.Y / scale), pixels, "keyboard", native);
|
|
662
|
+
this.tooltip.CloseOnInput();
|
|
663
|
+
for (let c = control; c; c = c.Parent) {
|
|
664
|
+
if (!c.ContextMenu)
|
|
665
|
+
continue;
|
|
666
|
+
args.Control = c;
|
|
667
|
+
args.Local = new SKPoint(pixels.X - c.DrawingRect.Left, pixels.Y - c.DrawingRect.Top);
|
|
668
|
+
if (c.ContextMenu(c, args) === true)
|
|
669
|
+
return true;
|
|
670
|
+
}
|
|
671
|
+
args.Control = undefined;
|
|
672
|
+
return !!this.ContextMenu && this.ContextMenu(this, args) === true;
|
|
673
|
+
}
|
|
631
674
|
cursorPointer = false;
|
|
632
675
|
/**
|
|
633
676
|
* DrawnUi.Blazor shows `cursor: pointer` over interactive controls through its overlay elements; here the overlay
|
package/dist/react/index.js
CHANGED
|
@@ -262,7 +262,8 @@ function AccessibilityOverlay({ view }) {
|
|
|
262
262
|
return null;
|
|
263
263
|
const pos = { left: n.Rect.Left, top: n.Rect.Top, width: n.Rect.Width, height: n.Rect.Height };
|
|
264
264
|
const activate = () => SkiaAccessibilityManager.Activate(n.Source);
|
|
265
|
-
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-expanded": n.Expanded, "aria-haspopup": n.Expanded !== undefined && n.Role === "menuitem" ? "menu" : 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,
|
|
265
|
+
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-expanded": n.Expanded, "aria-haspopup": n.Expanded !== undefined && n.Role === "menuitem" ? "menu" : 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, onContextMenu: (e) => { if (view.OpenContextMenuFromKeyboard(n.Source, e.nativeEvent))
|
|
266
|
+
e.preventDefault(); }, onKeyDown: (e) => {
|
|
266
267
|
// the canvas navigation gets the key first; the app's KeyDown runs after it with IsKeyHandled (6az)
|
|
267
268
|
if (e.key === "Enter" || e.key === " ") {
|
|
268
269
|
e.preventDefault();
|
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.40",
|
|
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)",
|
|
@@ -105,6 +105,11 @@
|
|
|
105
105
|
"check:multitouch": "node dev/check.mjs dev/check-multitouch.ts",
|
|
106
106
|
"check:scroll-size": "node dev/check.mjs dev/check-scroll-size.ts",
|
|
107
107
|
"check:ripple-primary": "node dev/check.mjs dev/check-ripple-primary.ts",
|
|
108
|
+
"check:stack-margins": "node dev/check.mjs dev/check-stack-margins.ts",
|
|
109
|
+
"check:fallback-single": "node dev/check.mjs dev/check-fallback-single.ts",
|
|
110
|
+
"check:composite-effect": "node dev/check.mjs dev/check-composite-effect.ts",
|
|
111
|
+
"check:keyboard-contextmenu": "node dev/check.mjs dev/check-keyboard-contextmenu.ts",
|
|
112
|
+
"check:editor-window": "node dev/check.mjs dev/check-editor-window.ts",
|
|
108
113
|
"audit:a11y": "node dev/audit-a11y.mjs",
|
|
109
114
|
"bench:relayout": "node dev/check.mjs dev/bench-relayout.ts",
|
|
110
115
|
"site:extras": "node dev/site-extras.mjs dist/demo",
|