drawnui-react 0.1.0-preview.25 → 0.1.0-preview.27
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/dist/controls/SkiaCarousel.d.ts +12 -1
- package/dist/controls/SkiaCarousel.js +33 -2
- package/dist/controls/SkiaEditor.d.ts +2 -0
- package/dist/controls/SkiaEditor.js +14 -0
- package/dist/controls/SkiaLayout.d.ts +8 -0
- package/dist/controls/SkiaLayout.js +13 -0
- package/dist/core/Accessibility.js +57 -1
- package/package.json +4 -1
|
@@ -103,8 +103,19 @@ export declare class SkiaCarousel extends SnappingLayout {
|
|
|
103
103
|
protected FindNearestAnchorInternal(current: SKPoint, velocity: SKPoint): SKPoint;
|
|
104
104
|
/** C# SkiaCarousel.ScrollToNearestAnchor: velocity below SnapVelocityThreshold counts as none; looped snaps around virtual anchors. */
|
|
105
105
|
ScrollToNearestAnchor(location: SKPoint, velocity: SKPoint): void;
|
|
106
|
-
/** C# SkiaCarousel.SelectNextAnchor:
|
|
106
|
+
/** C# SkiaCarousel.SelectNextAnchor: the choice below, at most one slide from where a finger gesture started. */
|
|
107
107
|
SelectNextAnchor(origin: SKPoint, velocity: SKPoint): SKPoint;
|
|
108
|
+
/**
|
|
109
|
+
* A finger release moves at most one slide from the slide its gesture started on, as iOS paging and the Android
|
|
110
|
+
* ViewPager do (C# 1070e0db): a drag past the middle makes the next slide the nearest one, and the flick then went one
|
|
111
|
+
* further. Code moves (ScrollTo, SelectedIndex) are not limited: releaseHome is set only while a release snaps.
|
|
112
|
+
*/
|
|
113
|
+
private LimitToNeighbours;
|
|
114
|
+
/** The slide a finger gesture started on (the target when it caught a snap in flight), see LimitToNeighbours. */
|
|
115
|
+
private gestureHome?;
|
|
116
|
+
private releaseHome?;
|
|
117
|
+
/** Base choice, plus a wrap to the virtual anchor at the strip borders when looped. */
|
|
118
|
+
private SelectNextAnchorInternal;
|
|
108
119
|
/** C# FixIndex: a virtual anchor becomes the real one, the position keeps its offset (visually identical, looped drawing wraps). */
|
|
109
120
|
private FixIndex;
|
|
110
121
|
private FixPosition;
|
|
@@ -247,8 +247,30 @@ export class SkiaCarousel extends SnappingLayout {
|
|
|
247
247
|
}
|
|
248
248
|
super.ScrollToNearestAnchor(location, velocity);
|
|
249
249
|
}
|
|
250
|
-
/** C# SkiaCarousel.SelectNextAnchor:
|
|
250
|
+
/** C# SkiaCarousel.SelectNextAnchor: the choice below, at most one slide from where a finger gesture started. */
|
|
251
251
|
SelectNextAnchor(origin, velocity) {
|
|
252
|
+
return this.LimitToNeighbours(this.SelectNextAnchorInternal(origin, velocity));
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* A finger release moves at most one slide from the slide its gesture started on, as iOS paging and the Android
|
|
256
|
+
* ViewPager do (C# 1070e0db): a drag past the middle makes the next slide the nearest one, and the flick then went one
|
|
257
|
+
* further. Code moves (ScrollTo, SelectedIndex) are not limited: releaseHome is set only while a release snaps.
|
|
258
|
+
*/
|
|
259
|
+
LimitToNeighbours(target) {
|
|
260
|
+
const home = this.releaseHome;
|
|
261
|
+
if (!home)
|
|
262
|
+
return target;
|
|
263
|
+
const at = (p) => this.SnapPoints.findIndex((s) => Math.abs(s.X - p.X) <= 1 && Math.abs(s.Y - p.Y) <= 1);
|
|
264
|
+
const from = at(home), to = at(target);
|
|
265
|
+
if (from < 0 || to < 0 || Math.abs(to - from) <= 1)
|
|
266
|
+
return target; // a looped wrap goes to a virtual point next to the edge: one slide already
|
|
267
|
+
return this.SnapPoints[from + Math.sign(to - from)];
|
|
268
|
+
}
|
|
269
|
+
/** The slide a finger gesture started on (the target when it caught a snap in flight), see LimitToNeighbours. */
|
|
270
|
+
gestureHome;
|
|
271
|
+
releaseHome;
|
|
272
|
+
/** Base choice, plus a wrap to the virtual anchor at the strip borders when looped. */
|
|
273
|
+
SelectNextAnchorInternal(origin, velocity) {
|
|
252
274
|
if (!this.ApplyLoopedLogic)
|
|
253
275
|
return super.SelectNextAnchor(origin, velocity);
|
|
254
276
|
const baseTarget = super.SelectNextAnchor(origin, velocity);
|
|
@@ -551,6 +573,9 @@ export class SkiaCarousel extends SnappingLayout {
|
|
|
551
573
|
this.FixPosition();
|
|
552
574
|
this.panningOffset = this.CurrentPosition;
|
|
553
575
|
this.panningStart = this.CurrentPosition;
|
|
576
|
+
// a swipe that catches a snap in flight starts from the slide that snap was going to
|
|
577
|
+
const going = this.snapIfNoPanOnUp ? this.SnapPoints.find((s) => Math.abs(s.X - this.CurrentSnap.X) <= 1 && Math.abs(s.Y - this.CurrentSnap.Y) <= 1) : undefined;
|
|
578
|
+
this.gestureHome = going ?? (this.SnapPoints.length > 0 ? this.FindNearestAnchor(this.CurrentPosition) : undefined);
|
|
554
579
|
};
|
|
555
580
|
switch (args.Type) {
|
|
556
581
|
case "Down":
|
|
@@ -591,7 +616,13 @@ export class SkiaCarousel extends SnappingLayout {
|
|
|
591
616
|
consumed = this;
|
|
592
617
|
const final = this.velocityAccumulator.CalculateFinalVelocity(500);
|
|
593
618
|
this.CurrentSnap = this.CurrentPosition;
|
|
594
|
-
this.
|
|
619
|
+
this.releaseHome = this.gestureHome;
|
|
620
|
+
try {
|
|
621
|
+
this.ScrollToNearestAnchor(this.CurrentSnap, new SKPoint(final.X, final.Y));
|
|
622
|
+
}
|
|
623
|
+
finally {
|
|
624
|
+
this.releaseHome = undefined;
|
|
625
|
+
}
|
|
595
626
|
this.IsUserPanning = false;
|
|
596
627
|
this.IsUserFocused = false;
|
|
597
628
|
this.snapIfNoPanOnUp = false;
|
|
@@ -51,6 +51,8 @@ export declare class SkiaEditor extends SkiaShape {
|
|
|
51
51
|
CanShowCursor: boolean;
|
|
52
52
|
SelectionColor: Color;
|
|
53
53
|
private cursorPosition;
|
|
54
|
+
/** A caret position was given (by the app, a tap, a selection): focusing keeps it; otherwise focusing puts the caret at the end. */
|
|
55
|
+
private cursorPlaced;
|
|
54
56
|
private selectionLength;
|
|
55
57
|
private isFocused;
|
|
56
58
|
private controlStyle;
|
|
@@ -58,6 +58,8 @@ export class SkiaEditor extends SkiaShape {
|
|
|
58
58
|
CanShowCursor = true;
|
|
59
59
|
SelectionColor = "#5590CFFE";
|
|
60
60
|
cursorPosition = 0;
|
|
61
|
+
/** A caret position was given (by the app, a tap, a selection): focusing keeps it; otherwise focusing puts the caret at the end. */
|
|
62
|
+
cursorPlaced = false;
|
|
61
63
|
selectionLength = 0;
|
|
62
64
|
isFocused = false;
|
|
63
65
|
controlStyle = "Unset";
|
|
@@ -174,6 +176,7 @@ export class SkiaEditor extends SkiaShape {
|
|
|
174
176
|
/** Caret index (UTF-16 units) = the left edge of the selection when one exists. */
|
|
175
177
|
get CursorPosition() { return this.cursorPosition; }
|
|
176
178
|
set CursorPosition(v) {
|
|
179
|
+
this.cursorPlaced = true;
|
|
177
180
|
const p = Math.max(0, Math.min(this.text.length, v | 0));
|
|
178
181
|
if (p === this.cursorPosition)
|
|
179
182
|
return;
|
|
@@ -218,6 +221,14 @@ export class SkiaEditor extends SkiaShape {
|
|
|
218
221
|
if (SkiaEditor.Focused && SkiaEditor.Focused !== this)
|
|
219
222
|
SkiaEditor.Focused.IsFocused = false;
|
|
220
223
|
SkiaEditor.Focused = this;
|
|
224
|
+
// focused with no caret placed (from code, by the keyboard): the caret goes to the end of the text, as a tap after
|
|
225
|
+
// the text does, and the native field takes that position when it attaches (C# 2285b422: typing appends)
|
|
226
|
+
if (!this.cursorPlaced) {
|
|
227
|
+
this.cursorPlaced = true;
|
|
228
|
+
this.cursorPosition = this.text.length;
|
|
229
|
+
this.selectionLength = 0;
|
|
230
|
+
this.ScrollToCaret();
|
|
231
|
+
}
|
|
221
232
|
this.SetFocusNative(true);
|
|
222
233
|
this.StartBlink();
|
|
223
234
|
}
|
|
@@ -484,6 +495,7 @@ export class SkiaEditor extends SkiaShape {
|
|
|
484
495
|
this.stubSelectionStop = -1;
|
|
485
496
|
this.selectionMovingEdge = -1;
|
|
486
497
|
}
|
|
498
|
+
this.cursorPlaced = true;
|
|
487
499
|
if (!this.isFocused)
|
|
488
500
|
this.IsFocused = true;
|
|
489
501
|
this.OnCursorMoved();
|
|
@@ -505,6 +517,7 @@ export class SkiaEditor extends SkiaShape {
|
|
|
505
517
|
this.SelectWord(this.HitTestIndex(p.X, p.Y));
|
|
506
518
|
this.dragSelecting = true;
|
|
507
519
|
this.selectionAnchor = this.cursorPosition;
|
|
520
|
+
this.cursorPlaced = true;
|
|
508
521
|
if (!this.isFocused)
|
|
509
522
|
this.IsFocused = true;
|
|
510
523
|
return this;
|
|
@@ -541,6 +554,7 @@ export class SkiaEditor extends SkiaShape {
|
|
|
541
554
|
}
|
|
542
555
|
SelectAll() { this.SetSelection(0, this.text.length); }
|
|
543
556
|
SetSelection(start, end) {
|
|
557
|
+
this.cursorPlaced = true;
|
|
544
558
|
const s = Math.max(0, Math.min(this.text.length, Math.min(start, end))), e = Math.max(0, Math.min(this.text.length, Math.max(start, end)));
|
|
545
559
|
this.cursorPosition = s;
|
|
546
560
|
this.selectionLength = e - s;
|
|
@@ -165,6 +165,14 @@ export declare class SkiaLayout extends SkiaControl {
|
|
|
165
165
|
* its slot, also while no view shows it (ScrollToIndex to an item off screen); undefined otherwise.
|
|
166
166
|
*/
|
|
167
167
|
GetItemRect(index: number): SKRect | undefined;
|
|
168
|
+
/**
|
|
169
|
+
* Masonry: every placed item with its rect (pixels), in item order: what keyboard navigation follows, since the
|
|
170
|
+
* columns have uneven heights and the item `Split` places later is rarely under the focused one.
|
|
171
|
+
*/
|
|
172
|
+
GetMasonryPlacement(): {
|
|
173
|
+
Index: number;
|
|
174
|
+
Rect: SKRect;
|
|
175
|
+
}[];
|
|
168
176
|
/** Masonry: where the slot of item `index` was arranged (pixels); see GetItemRect. */
|
|
169
177
|
GetMasonryItemRect(index: number): SKRect | undefined;
|
|
170
178
|
/** Port of C# MeasureGrid: build the structure in points, stretch the last track when the grid fills, remeasure at final cells. */
|
|
@@ -622,6 +622,19 @@ export class SkiaLayout extends SkiaControl {
|
|
|
622
622
|
const d = this.slots?.[index]?.Destination;
|
|
623
623
|
return d && d.Width > 0 ? d : undefined;
|
|
624
624
|
}
|
|
625
|
+
/**
|
|
626
|
+
* Masonry: every placed item with its rect (pixels), in item order: what keyboard navigation follows, since the
|
|
627
|
+
* columns have uneven heights and the item `Split` places later is rarely under the focused one.
|
|
628
|
+
*/
|
|
629
|
+
GetMasonryPlacement() {
|
|
630
|
+
if (!this.IsMasonry)
|
|
631
|
+
return [];
|
|
632
|
+
const r = this.DrawingRect, p = this.Padding, s = this.RenderingScale, left = r.Left + p.Left * s, top = r.Top + p.Top * s;
|
|
633
|
+
return this.wrapSlots.map((w) => ({
|
|
634
|
+
Index: w.view instanceof TemplatedSlot ? w.view.Index : this.IsTemplated ? w.view.ContextIndex : this.views.indexOf(w.view),
|
|
635
|
+
Rect: SKRect.Create(left + w.x, top + w.y, w.w, w.h),
|
|
636
|
+
}));
|
|
637
|
+
}
|
|
625
638
|
/** Masonry: where the slot of item `index` was arranged (pixels); see GetItemRect. */
|
|
626
639
|
GetMasonryItemRect(index) { return this.IsMasonry ? this.GetItemRect(index) : undefined; }
|
|
627
640
|
/** Port of C# MeasureGrid: build the structure in points, stretch the last track when the grid fills, remeasure at final cells. */
|
|
@@ -167,7 +167,12 @@ export class SkiaAccessibilityManager {
|
|
|
167
167
|
const vertical = axis !== "Horizontal";
|
|
168
168
|
const page = () => PageSize(scroll, item, vertical) * row;
|
|
169
169
|
let target, step;
|
|
170
|
-
|
|
170
|
+
const layout = asLayout(group), masonry = layout?.Type === "Masonry" ? MasonryTarget(layout, current, key, scroll) : undefined;
|
|
171
|
+
if (masonry !== undefined) {
|
|
172
|
+
target = masonry;
|
|
173
|
+
step = key === "ArrowDown" || key === "ArrowRight" || key === "PageDown" ? 1 : -1;
|
|
174
|
+
}
|
|
175
|
+
else if ((key === "ArrowDown" && axis === "Vertical") || (key === "ArrowRight" && axis !== "Vertical")) {
|
|
171
176
|
target = current + 1;
|
|
172
177
|
step = 1;
|
|
173
178
|
}
|
|
@@ -479,6 +484,57 @@ function IsDrawn(control) {
|
|
|
479
484
|
return !!control.Superview && r.Width > 0 && r.Height > 0;
|
|
480
485
|
}
|
|
481
486
|
/** Items per viewport of the scroll around the group. */
|
|
487
|
+
/**
|
|
488
|
+
* C# MasonryTarget (2ad608d1): the target of an arrow or page key in a Masonry group, from the placed items. Up / Down go
|
|
489
|
+
* to the previous / next item of the same column, Left / Right to the item of the neighbour column nearest in height,
|
|
490
|
+
* PageUp / PageDown up to one viewport along the column (else the next / previous item of the column). `current` when
|
|
491
|
+
* there is no item that way; undefined for other keys or no placement (the generic rules apply).
|
|
492
|
+
*/
|
|
493
|
+
function MasonryTarget(layout, current, key, scroll) {
|
|
494
|
+
if (key !== "ArrowDown" && key !== "ArrowUp" && key !== "ArrowLeft" && key !== "ArrowRight" && key !== "PageDown" && key !== "PageUp")
|
|
495
|
+
return undefined;
|
|
496
|
+
const cells = layout.GetMasonryPlacement?.() ?? [];
|
|
497
|
+
const focused = cells.find((c) => c.Index === current);
|
|
498
|
+
if (!focused)
|
|
499
|
+
return undefined;
|
|
500
|
+
const lefts = [...new Set(cells.map((c) => Math.round(c.Rect.Left)))].sort((a, b) => a - b);
|
|
501
|
+
const columnOf = (c) => lefts.indexOf(Math.round(c.Rect.Left));
|
|
502
|
+
const col = columnOf(focused), top = focused.Rect.Top, mid = (focused.Rect.Top + focused.Rect.Bottom) / 2;
|
|
503
|
+
const column = cells.filter((c) => columnOf(c) === col).sort((a, b) => a.Rect.Top - b.Rect.Top);
|
|
504
|
+
const below = column.filter((c) => c.Rect.Top > top), above = column.filter((c) => c.Rect.Top < top);
|
|
505
|
+
const viewport = scroll ? scroll.DrawingRect.Height : 0;
|
|
506
|
+
let found;
|
|
507
|
+
if (key === "ArrowDown")
|
|
508
|
+
found = below[0];
|
|
509
|
+
else if (key === "ArrowUp")
|
|
510
|
+
found = above[above.length - 1];
|
|
511
|
+
else if (key === "ArrowRight" || key === "ArrowLeft") {
|
|
512
|
+
const next = col + (key === "ArrowRight" ? 1 : -1);
|
|
513
|
+
let best = Infinity;
|
|
514
|
+
for (const c of cells) {
|
|
515
|
+
if (columnOf(c) !== next)
|
|
516
|
+
continue;
|
|
517
|
+
const d = Math.abs((c.Rect.Top + c.Rect.Bottom) / 2 - mid);
|
|
518
|
+
if (d < best) {
|
|
519
|
+
best = d;
|
|
520
|
+
found = c;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
if (!scroll)
|
|
526
|
+
return undefined;
|
|
527
|
+
if (key === "PageDown") {
|
|
528
|
+
const within = below.filter((c) => c.Rect.Top <= top + viewport);
|
|
529
|
+
found = within[within.length - 1] ?? below[0];
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
const within = above.filter((c) => c.Rect.Top >= top - viewport);
|
|
533
|
+
found = within[0] ?? above[above.length - 1];
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return found?.Index ?? current;
|
|
537
|
+
}
|
|
482
538
|
function PageSize(scroll, item, vertical) {
|
|
483
539
|
const v = scroll.DrawingRect, size = item.MeasuredSize.Pixels;
|
|
484
540
|
const viewport = vertical ? v.Height : v.Width, s = vertical ? size.Height : size.Width;
|
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.27",
|
|
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)",
|
|
@@ -82,6 +82,9 @@
|
|
|
82
82
|
"check:masonry": "node dev/check.mjs dev/check-masonry.ts",
|
|
83
83
|
"check:thickness": "node dev/check.mjs dev/check-thickness.ts",
|
|
84
84
|
"check:scroll-recycled": "node dev/check.mjs dev/check-scroll-recycled.ts",
|
|
85
|
+
"check:masonry-keys": "node dev/check.mjs dev/check-masonry-keys.ts",
|
|
86
|
+
"check:carousel-swipe": "node dev/check.mjs dev/check-carousel-swipe.ts",
|
|
87
|
+
"check:editor-focus": "node dev/check.mjs dev/check-editor-focus.ts",
|
|
85
88
|
"site:extras": "node dev/site-extras.mjs dist/demo",
|
|
86
89
|
"build:lib": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
87
90
|
"prepublishOnly": "npm run build:lib",
|