@onekeyfe/react-native-native-list 6.8.0-24 → 6.8.0-25
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.
|
@@ -278,6 +278,7 @@ type PendingScroll =
|
|
|
278
278
|
kind: 'index';
|
|
279
279
|
index: number;
|
|
280
280
|
scroll: NormalizedPositionScroll;
|
|
281
|
+
behavior: ScrollBehavior;
|
|
281
282
|
}>
|
|
282
283
|
| Readonly<{ kind: 'offset'; offset: number; animated: boolean }>
|
|
283
284
|
| Readonly<{ kind: 'end'; animated: boolean }>;
|
|
@@ -305,6 +306,8 @@ type PointerReorderState = {
|
|
|
305
306
|
}>;
|
|
306
307
|
previewOffsetX?: number;
|
|
307
308
|
previewOffsetY?: number;
|
|
309
|
+
handoff?: { index: number; scrollOffset: number; itemCenter: number };
|
|
310
|
+
restoringKeyboardOrder?: boolean;
|
|
308
311
|
longPressTimer?: number;
|
|
309
312
|
activatedAt?: number;
|
|
310
313
|
active: boolean;
|
|
@@ -853,6 +856,7 @@ export const WEB_LIST_CSS = `
|
|
|
853
856
|
.ok-native-list-wallet-member[data-native-list-selected="true"]>.ok-native-list-wallet-row{background:var(--nl-selected)}
|
|
854
857
|
.ok-native-list-wallet-member:not([data-native-list-selected="true"]):hover>.ok-native-list-wallet-row{background:var(--nl-strong)}
|
|
855
858
|
.ok-native-list-wallet-member:not([data-native-list-selected="true"]):active>.ok-native-list-wallet-row{background:var(--nl-pressed)}
|
|
859
|
+
.ok-native-list-item[data-native-list-reorderable="true"]:focus-visible>:is(.ok-native-list-row,.ok-native-list-wallet-group),
|
|
856
860
|
.ok-native-list-item[data-native-list-row-press-enabled="true"]:focus-visible>.ok-native-list-row{outline:2px solid var(--nl-accent);outline-offset:-2px}
|
|
857
861
|
.ok-native-list-item[data-native-list-reorderable="true"]>.ok-native-list-row{cursor:grab}
|
|
858
862
|
:where(.ok-native-list-root[data-native-list-reorder-activation="handle"]) .ok-native-list-item[data-native-list-reorderable="true"]>.ok-native-list-row{cursor:default}
|
|
@@ -2479,6 +2483,8 @@ export class NativeListWebEngine {
|
|
|
2479
2483
|
const nextCapabilities = validated.capabilities;
|
|
2480
2484
|
if (
|
|
2481
2485
|
this.pointerReorder?.active ||
|
|
2486
|
+
this.pointerReorder?.restoringKeyboardOrder ||
|
|
2487
|
+
this.keyboardReorder ||
|
|
2482
2488
|
capabilities?.reorderable !== nextCapabilities?.reorderable ||
|
|
2483
2489
|
(capabilities?.reorderActivation ?? 'row') !==
|
|
2484
2490
|
(nextCapabilities?.reorderActivation ?? 'row')
|
|
@@ -2589,6 +2595,13 @@ export class NativeListWebEngine {
|
|
|
2589
2595
|
(event as PointerEvent).pointerType !== 'touch'
|
|
2590
2596
|
)
|
|
2591
2597
|
return;
|
|
2598
|
+
if (
|
|
2599
|
+
event.type === 'wheel' &&
|
|
2600
|
+
this.keyboardReorder &&
|
|
2601
|
+
this.wheelReachesScrollOwner(event as WheelEvent)
|
|
2602
|
+
) {
|
|
2603
|
+
this.cancelKeyboardReorder(false);
|
|
2604
|
+
}
|
|
2592
2605
|
this.structuralScrollInterrupted = true;
|
|
2593
2606
|
if (this.structuralPrefixTransition) {
|
|
2594
2607
|
this.cancelStructuralAnimation();
|
|
@@ -2596,6 +2609,62 @@ export class NativeListWebEngine {
|
|
|
2596
2609
|
}
|
|
2597
2610
|
};
|
|
2598
2611
|
|
|
2612
|
+
private wheelReachesScrollOwner(event: WheelEvent) {
|
|
2613
|
+
if (event.defaultPrevented || event.ctrlKey) return false;
|
|
2614
|
+
const view = this.document.defaultView;
|
|
2615
|
+
if (!view) return true;
|
|
2616
|
+
const horizontal =
|
|
2617
|
+
event.shiftKey || Math.abs(event.deltaX) > Math.abs(event.deltaY);
|
|
2618
|
+
const delta = horizontal ? event.deltaX || event.deltaY : event.deltaY;
|
|
2619
|
+
for (const target of event.composedPath()) {
|
|
2620
|
+
if (target === event.currentTarget) break;
|
|
2621
|
+
if (!(target instanceof view.HTMLElement)) continue;
|
|
2622
|
+
const offset = horizontal ? target.scrollLeft : target.scrollTop;
|
|
2623
|
+
const scrollRange = horizontal
|
|
2624
|
+
? target.scrollWidth - target.clientWidth
|
|
2625
|
+
: target.scrollHeight - target.clientHeight;
|
|
2626
|
+
if (scrollRange <= 0) continue;
|
|
2627
|
+
const style = view.getComputedStyle(target);
|
|
2628
|
+
const negativeOffset = this.hasNegativeScrollOffsets(style, horizontal);
|
|
2629
|
+
const minOffset = negativeOffset ? -scrollRange : 0;
|
|
2630
|
+
const maxOffset = negativeOffset ? 0 : scrollRange;
|
|
2631
|
+
const overflow =
|
|
2632
|
+
(horizontal ? style.overflowX : style.overflowY) || style.overflow;
|
|
2633
|
+
if (overflow !== 'auto' && overflow !== 'scroll') continue;
|
|
2634
|
+
const overscroll = horizontal
|
|
2635
|
+
? style.overscrollBehaviorX
|
|
2636
|
+
: style.overscrollBehaviorY;
|
|
2637
|
+
if (
|
|
2638
|
+
overscroll === 'contain' ||
|
|
2639
|
+
overscroll === 'none' ||
|
|
2640
|
+
(delta < 0 ? offset > minOffset : offset < maxOffset)
|
|
2641
|
+
) {
|
|
2642
|
+
return false;
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
return true;
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
private hasNegativeScrollOffsets(
|
|
2649
|
+
style: CSSStyleDeclaration,
|
|
2650
|
+
horizontal: boolean
|
|
2651
|
+
): boolean {
|
|
2652
|
+
const { writingMode, direction, display, flexDirection, flexWrap } = style;
|
|
2653
|
+
const horizontalWritingMode =
|
|
2654
|
+
!writingMode || writingMode === 'horizontal-tb';
|
|
2655
|
+
const inlineAxis = horizontal === horizontalWritingMode;
|
|
2656
|
+
const negative = inlineAxis
|
|
2657
|
+
? (direction === 'rtl') !== (writingMode === 'sideways-lr')
|
|
2658
|
+
: horizontal && writingMode.endsWith('-rl');
|
|
2659
|
+
const isFlexMainAxis = inlineAxis !== flexDirection.startsWith('column');
|
|
2660
|
+
const reversedFlex =
|
|
2661
|
+
(display === 'flex' || display === 'inline-flex') &&
|
|
2662
|
+
(isFlexMainAxis
|
|
2663
|
+
? flexDirection.endsWith('-reverse')
|
|
2664
|
+
: flexWrap === 'wrap-reverse');
|
|
2665
|
+
return negative !== reversedFlex;
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2599
2668
|
private updateStructuralTailWindow() {
|
|
2600
2669
|
const tail = this.structuralTail;
|
|
2601
2670
|
if (!tail) return;
|
|
@@ -2959,7 +3028,7 @@ export class NativeListWebEngine {
|
|
|
2959
3028
|
(next.capabilities?.reorderActivation !== 'handle' ||
|
|
2960
3029
|
hasWebReorderHandle(source));
|
|
2961
3030
|
if (!canContinue) {
|
|
2962
|
-
|
|
3031
|
+
this.cancelPointerReorder(false);
|
|
2963
3032
|
if (keyboard) {
|
|
2964
3033
|
this.keyboardReorder = undefined;
|
|
2965
3034
|
this.updateReorderVisualState();
|
|
@@ -3035,19 +3104,23 @@ export class NativeListWebEngine {
|
|
|
3035
3104
|
this.renderFooter();
|
|
3036
3105
|
}
|
|
3037
3106
|
|
|
3038
|
-
scrollToIndex(
|
|
3107
|
+
scrollToIndex(
|
|
3108
|
+
index: number,
|
|
3109
|
+
scroll: NormalizedPositionScroll,
|
|
3110
|
+
behavior: ScrollBehavior = scroll.animated ? 'smooth' : 'auto'
|
|
3111
|
+
) {
|
|
3039
3112
|
if (index < 0 || index >= this.rows.length) {
|
|
3040
3113
|
this.emitScrollFailure(index, 'index-out-of-range');
|
|
3041
3114
|
return;
|
|
3042
3115
|
}
|
|
3043
3116
|
this.notifyScrollCommandAccepted();
|
|
3044
3117
|
if (!this.canScroll()) {
|
|
3045
|
-
this.pendingScroll = { kind: 'index', index, scroll };
|
|
3118
|
+
this.pendingScroll = { kind: 'index', index, scroll, behavior };
|
|
3046
3119
|
return;
|
|
3047
3120
|
}
|
|
3048
3121
|
const item = this.layout.items[index];
|
|
3049
3122
|
if (!item) {
|
|
3050
|
-
this.pendingScroll = { kind: 'index', index, scroll };
|
|
3123
|
+
this.pendingScroll = { kind: 'index', index, scroll, behavior };
|
|
3051
3124
|
return;
|
|
3052
3125
|
}
|
|
3053
3126
|
const viewportLength = this.viewportLength();
|
|
@@ -3063,7 +3136,7 @@ export class NativeListWebEngine {
|
|
|
3063
3136
|
viewPosition: scroll.viewPosition,
|
|
3064
3137
|
viewOffset: scroll.viewOffset,
|
|
3065
3138
|
});
|
|
3066
|
-
this.scrollToAbsoluteOffset(offset,
|
|
3139
|
+
this.scrollToAbsoluteOffset(offset, behavior);
|
|
3067
3140
|
}
|
|
3068
3141
|
|
|
3069
3142
|
scrollToKey(key: string, scroll: NormalizedPositionScroll) {
|
|
@@ -3080,8 +3153,11 @@ export class NativeListWebEngine {
|
|
|
3080
3153
|
}
|
|
3081
3154
|
if (this.externalScrollHost) {
|
|
3082
3155
|
const geometry = this.externalGeometry();
|
|
3083
|
-
this.writeExternalOffset(
|
|
3084
|
-
|
|
3156
|
+
this.writeExternalOffset(
|
|
3157
|
+
geometry.containerOrigin + offset,
|
|
3158
|
+
animated ? 'smooth' : 'auto'
|
|
3159
|
+
);
|
|
3160
|
+
} else this.scrollToAbsoluteOffset(offset, animated ? 'smooth' : 'auto');
|
|
3085
3161
|
}
|
|
3086
3162
|
|
|
3087
3163
|
scrollToEnd(animated: boolean) {
|
|
@@ -3094,12 +3170,12 @@ export class NativeListWebEngine {
|
|
|
3094
3170
|
const geometry = this.externalGeometry();
|
|
3095
3171
|
this.writeExternalOffset(
|
|
3096
3172
|
geometry.end - this.externalScrollHost.clientHeight,
|
|
3097
|
-
animated
|
|
3173
|
+
animated ? 'smooth' : 'auto'
|
|
3098
3174
|
);
|
|
3099
3175
|
} else
|
|
3100
3176
|
this.scrollToAbsoluteOffset(
|
|
3101
3177
|
Math.max(0, this.contentLength() - this.viewportLength()),
|
|
3102
|
-
animated
|
|
3178
|
+
animated ? 'smooth' : 'auto'
|
|
3103
3179
|
);
|
|
3104
3180
|
}
|
|
3105
3181
|
|
|
@@ -3422,7 +3498,7 @@ export class NativeListWebEngine {
|
|
|
3422
3498
|
this.root.style.height = value;
|
|
3423
3499
|
}
|
|
3424
3500
|
|
|
3425
|
-
private recomputeLayout = () => {
|
|
3501
|
+
private recomputeLayout = (revealIndex?: number) => {
|
|
3426
3502
|
if (this.destroyed) return;
|
|
3427
3503
|
if (
|
|
3428
3504
|
this.structuralPrefixTransition &&
|
|
@@ -3526,7 +3602,21 @@ export class NativeListWebEngine {
|
|
|
3526
3602
|
this.viewport.scrollLeft = 0;
|
|
3527
3603
|
this.viewport.scrollTop = 0;
|
|
3528
3604
|
}
|
|
3529
|
-
|
|
3605
|
+
if (revealIndex !== undefined) {
|
|
3606
|
+
// Mount against the destination offset, even on hosts with smooth scrolling.
|
|
3607
|
+
this.pendingScroll = undefined;
|
|
3608
|
+
this.scrollToIndex(
|
|
3609
|
+
revealIndex,
|
|
3610
|
+
{
|
|
3611
|
+
animated: false,
|
|
3612
|
+
alignment: 'nearest',
|
|
3613
|
+
viewPosition: 0,
|
|
3614
|
+
viewOffset: 0,
|
|
3615
|
+
},
|
|
3616
|
+
'instant'
|
|
3617
|
+
);
|
|
3618
|
+
}
|
|
3619
|
+
this.renderWindow(revealIndex);
|
|
3530
3620
|
this.performPendingScroll();
|
|
3531
3621
|
};
|
|
3532
3622
|
|
|
@@ -3589,7 +3679,7 @@ export class NativeListWebEngine {
|
|
|
3589
3679
|
});
|
|
3590
3680
|
}
|
|
3591
3681
|
|
|
3592
|
-
private renderWindow() {
|
|
3682
|
+
private renderWindow(revealIndex?: number) {
|
|
3593
3683
|
this.updateAvatarWindow();
|
|
3594
3684
|
const viewportLength = this.viewportLength();
|
|
3595
3685
|
const visible =
|
|
@@ -3602,6 +3692,11 @@ export class NativeListWebEngine {
|
|
|
3602
3692
|
this.virtualizationEnabled,
|
|
3603
3693
|
viewportLength * OVERSCAN_VIEWPORTS
|
|
3604
3694
|
);
|
|
3695
|
+
const keyboardSource = this.keyboardReorder?.sourceKey;
|
|
3696
|
+
if (keyboardSource && !visible.some(({ key }) => key === keyboardSource)) {
|
|
3697
|
+
this.cancelKeyboardReorder(false);
|
|
3698
|
+
return;
|
|
3699
|
+
}
|
|
3605
3700
|
const desired = new Set(visible.map((item) => item.index));
|
|
3606
3701
|
this.mounted.forEach((element, index) => {
|
|
3607
3702
|
const nextRow = this.rows[index];
|
|
@@ -3638,7 +3733,6 @@ export class NativeListWebEngine {
|
|
|
3638
3733
|
this.content.appendChild(element);
|
|
3639
3734
|
}
|
|
3640
3735
|
this.positionElement(element, layoutItem);
|
|
3641
|
-
setData(element, 'nativeListReorderable', this.isReorderable(row));
|
|
3642
3736
|
const signature = webRowRenderSignature(row);
|
|
3643
3737
|
if (
|
|
3644
3738
|
element.dataset.nativeListRowKey !== row.key ||
|
|
@@ -3646,6 +3740,8 @@ export class NativeListWebEngine {
|
|
|
3646
3740
|
) {
|
|
3647
3741
|
this.renderElement(element, layoutItem.index, row);
|
|
3648
3742
|
element.dataset.renderSignature = signature;
|
|
3743
|
+
} else {
|
|
3744
|
+
this.updateRowReorderability(element, layoutItem.index, row);
|
|
3649
3745
|
}
|
|
3650
3746
|
});
|
|
3651
3747
|
let measuredHeightChanged = false;
|
|
@@ -3672,7 +3768,7 @@ export class NativeListWebEngine {
|
|
|
3672
3768
|
}
|
|
3673
3769
|
});
|
|
3674
3770
|
if (measuredHeightChanged) {
|
|
3675
|
-
this.recomputeLayout();
|
|
3771
|
+
this.recomputeLayout(revealIndex);
|
|
3676
3772
|
return;
|
|
3677
3773
|
}
|
|
3678
3774
|
this.updateVisibleSelection();
|
|
@@ -3687,6 +3783,29 @@ export class NativeListWebEngine {
|
|
|
3687
3783
|
element.style.height = String(item.height) + 'px';
|
|
3688
3784
|
}
|
|
3689
3785
|
|
|
3786
|
+
private updateRowReorderability(
|
|
3787
|
+
element: HTMLElement,
|
|
3788
|
+
index: number,
|
|
3789
|
+
row: RowModel
|
|
3790
|
+
) {
|
|
3791
|
+
const reorderable =
|
|
3792
|
+
this.snapshot.rows[index] === row && this.isReorderable(row);
|
|
3793
|
+
setData(element, 'nativeListReorderable', reorderable);
|
|
3794
|
+
if (isRowPressEnabled(row) || this.canStartKeyboardReorder(element)) {
|
|
3795
|
+
if (element.tabIndex !== 0) element.tabIndex = 0;
|
|
3796
|
+
} else {
|
|
3797
|
+
element.removeAttribute('tabindex');
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
|
|
3801
|
+
private canStartKeyboardReorder(element: HTMLElement) {
|
|
3802
|
+
return (
|
|
3803
|
+
element.dataset.nativeListReorderable === 'true' &&
|
|
3804
|
+
(this.snapshot.capabilities?.reorderActivation !== 'handle' ||
|
|
3805
|
+
element.querySelector('[data-native-list-reorder-handle]') !== null)
|
|
3806
|
+
);
|
|
3807
|
+
}
|
|
3808
|
+
|
|
3690
3809
|
private renderElement(
|
|
3691
3810
|
element: HTMLElement,
|
|
3692
3811
|
index: number,
|
|
@@ -3721,7 +3840,6 @@ export class NativeListWebEngine {
|
|
|
3721
3840
|
(row.style?.container?.opacity ?? row.opacity ?? 1) *
|
|
3722
3841
|
(row.disabled ? 0.5 : 1)
|
|
3723
3842
|
);
|
|
3724
|
-
setData(element, 'nativeListReorderable', this.isReorderable(row));
|
|
3725
3843
|
setData(
|
|
3726
3844
|
element,
|
|
3727
3845
|
'nativeListDragging',
|
|
@@ -3741,11 +3859,6 @@ export class NativeListWebEngine {
|
|
|
3741
3859
|
'aria-label',
|
|
3742
3860
|
row.accessibilityLabel ?? this.rowLabel(row)
|
|
3743
3861
|
);
|
|
3744
|
-
if (isRowPressEnabled(row)) {
|
|
3745
|
-
element.tabIndex = 0;
|
|
3746
|
-
} else {
|
|
3747
|
-
element.removeAttribute('tabindex');
|
|
3748
|
-
}
|
|
3749
3862
|
element.draggable = false;
|
|
3750
3863
|
const context = {
|
|
3751
3864
|
document: this.document,
|
|
@@ -3779,6 +3892,7 @@ export class NativeListWebEngine {
|
|
|
3779
3892
|
// Template and presentation defaults must precede caller overrides.
|
|
3780
3893
|
applyRowStyle(body, row);
|
|
3781
3894
|
if (body.parentElement !== element) element.replaceChildren(body);
|
|
3895
|
+
this.updateRowReorderability(element, overlay ? -1 : index, row);
|
|
3782
3896
|
if (
|
|
3783
3897
|
row.type === 'market' &&
|
|
3784
3898
|
row.diagnostics?.imageBindActionKey &&
|
|
@@ -4363,7 +4477,7 @@ export class NativeListWebEngine {
|
|
|
4363
4477
|
this.recomputeLayout();
|
|
4364
4478
|
};
|
|
4365
4479
|
|
|
4366
|
-
private writeExternalOffset(rawOffset: number,
|
|
4480
|
+
private writeExternalOffset(rawOffset: number, behavior: ScrollBehavior) {
|
|
4367
4481
|
this.externalGeometryCache = undefined;
|
|
4368
4482
|
const host = this.externalScrollHost!;
|
|
4369
4483
|
const scrollTo: (options: ScrollToOptions) => void =
|
|
@@ -4374,17 +4488,17 @@ export class NativeListWebEngine {
|
|
|
4374
4488
|
0,
|
|
4375
4489
|
Math.min(host.scrollHeight - host.clientHeight, rawOffset)
|
|
4376
4490
|
),
|
|
4377
|
-
behavior
|
|
4491
|
+
behavior,
|
|
4378
4492
|
});
|
|
4379
4493
|
this.scheduleFrame();
|
|
4380
4494
|
}
|
|
4381
4495
|
|
|
4382
|
-
private scrollToAbsoluteOffset(offset: number,
|
|
4496
|
+
private scrollToAbsoluteOffset(offset: number, behavior: ScrollBehavior) {
|
|
4383
4497
|
if (this.externalScrollHost) {
|
|
4384
4498
|
const geometry = this.externalGeometry();
|
|
4385
4499
|
this.writeExternalOffset(
|
|
4386
4500
|
geometry.origin + offset - this.externalStickyInset,
|
|
4387
|
-
|
|
4501
|
+
behavior
|
|
4388
4502
|
);
|
|
4389
4503
|
return;
|
|
4390
4504
|
}
|
|
@@ -4400,8 +4514,8 @@ export class NativeListWebEngine {
|
|
|
4400
4514
|
);
|
|
4401
4515
|
this.viewport.scrollTo(
|
|
4402
4516
|
this.layout.horizontal
|
|
4403
|
-
? { left: rawOffset, top: 0, behavior
|
|
4404
|
-
: { left: 0, top: rawOffset, behavior
|
|
4517
|
+
? { left: rawOffset, top: 0, behavior }
|
|
4518
|
+
: { left: 0, top: rawOffset, behavior }
|
|
4405
4519
|
);
|
|
4406
4520
|
this.scheduleFrame();
|
|
4407
4521
|
}
|
|
@@ -4411,7 +4525,7 @@ export class NativeListWebEngine {
|
|
|
4411
4525
|
if (!pending || !this.canScroll()) return;
|
|
4412
4526
|
this.pendingScroll = undefined;
|
|
4413
4527
|
if (pending.kind === 'index')
|
|
4414
|
-
this.scrollToIndex(pending.index, pending.scroll);
|
|
4528
|
+
this.scrollToIndex(pending.index, pending.scroll, pending.behavior);
|
|
4415
4529
|
else if (pending.kind === 'offset')
|
|
4416
4530
|
this.scrollToOffset(pending.offset, pending.animated);
|
|
4417
4531
|
else this.scrollToEnd(pending.animated);
|
|
@@ -5035,41 +5149,60 @@ export class NativeListWebEngine {
|
|
|
5035
5149
|
};
|
|
5036
5150
|
|
|
5037
5151
|
private handleKeyDown = (event: KeyboardEvent) => {
|
|
5152
|
+
const target = event.target;
|
|
5153
|
+
if (!(target instanceof HTMLElement)) return;
|
|
5154
|
+
if (event.key === 'Escape') {
|
|
5155
|
+
if (this.pointerReorder?.active) {
|
|
5156
|
+
event.preventDefault();
|
|
5157
|
+
this.cancelPointerReorder(true);
|
|
5158
|
+
return;
|
|
5159
|
+
}
|
|
5160
|
+
if (this.keyboardReorder) {
|
|
5161
|
+
event.preventDefault();
|
|
5162
|
+
this.cancelKeyboardReorder();
|
|
5163
|
+
return;
|
|
5164
|
+
}
|
|
5165
|
+
}
|
|
5166
|
+
const rowElement = target.closest<HTMLElement>(
|
|
5167
|
+
'[data-native-list-row-key]'
|
|
5168
|
+
);
|
|
5169
|
+
if (
|
|
5170
|
+
this.keyboardReorder &&
|
|
5171
|
+
(event.key === 'Tab' ||
|
|
5172
|
+
target.dataset.nativeListRowKey !== this.keyboardReorder.sourceKey)
|
|
5173
|
+
) {
|
|
5174
|
+
const bindingEpoch = rowElement?.dataset.nativeListBindingEpoch;
|
|
5175
|
+
this.cancelKeyboardReorder(false);
|
|
5176
|
+
if (event.key === 'Tab') return;
|
|
5177
|
+
if (
|
|
5178
|
+
!this.root.contains(target) ||
|
|
5179
|
+
rowElement?.dataset.nativeListBindingEpoch !== bindingEpoch
|
|
5180
|
+
) {
|
|
5181
|
+
event.preventDefault();
|
|
5182
|
+
return;
|
|
5183
|
+
}
|
|
5184
|
+
}
|
|
5038
5185
|
if (
|
|
5039
5186
|
(event.key === 'Enter' || event.key === ' ') &&
|
|
5040
|
-
|
|
5041
|
-
event.target.matches('[role="button"][data-native-list-hover-action]')
|
|
5187
|
+
target.matches('[role="button"][data-native-list-hover-action]')
|
|
5042
5188
|
) {
|
|
5043
5189
|
event.preventDefault();
|
|
5044
5190
|
if (
|
|
5045
|
-
this.actionAnchor?.actionElement !==
|
|
5191
|
+
this.actionAnchor?.actionElement !== target ||
|
|
5046
5192
|
!this.actionAnchor.open
|
|
5047
5193
|
)
|
|
5048
|
-
this.emitHoverAction(
|
|
5194
|
+
this.emitHoverAction(target);
|
|
5049
5195
|
return;
|
|
5050
5196
|
}
|
|
5051
5197
|
// OneKey patch: non-button title help supports keyboard activation.
|
|
5052
5198
|
if (
|
|
5053
5199
|
(event.key === 'Enter' || event.key === ' ') &&
|
|
5054
|
-
|
|
5055
|
-
event.target.matches('[role="button"][data-native-list-action]')
|
|
5200
|
+
target.matches('[role="button"][data-native-list-action]')
|
|
5056
5201
|
) {
|
|
5057
5202
|
event.preventDefault();
|
|
5058
|
-
|
|
5203
|
+
target.click();
|
|
5059
5204
|
return;
|
|
5060
5205
|
}
|
|
5061
|
-
if (event.key === 'Escape') {
|
|
5062
|
-
if (this.pointerReorder?.active) {
|
|
5063
|
-
event.preventDefault();
|
|
5064
|
-
this.cancelPointerReorder(true);
|
|
5065
|
-
return;
|
|
5066
|
-
}
|
|
5067
|
-
if (this.keyboardReorder) {
|
|
5068
|
-
event.preventDefault();
|
|
5069
|
-
this.cancelKeyboardReorder();
|
|
5070
|
-
return;
|
|
5071
|
-
}
|
|
5072
|
-
}
|
|
5073
5206
|
if (
|
|
5074
5207
|
this.keyboardReorder &&
|
|
5075
5208
|
(event.key === 'ArrowUp' || event.key === 'ArrowLeft')
|
|
@@ -5087,30 +5220,21 @@ export class NativeListWebEngine {
|
|
|
5087
5220
|
return;
|
|
5088
5221
|
}
|
|
5089
5222
|
if (event.key !== 'Enter' && event.key !== ' ') return;
|
|
5090
|
-
const target = event.target;
|
|
5091
|
-
if (!(target instanceof HTMLElement)) return;
|
|
5092
5223
|
if (target.matches('button')) return;
|
|
5093
|
-
const row = this.rowAtElement(
|
|
5224
|
+
const row = this.rowAtElement(rowElement);
|
|
5094
5225
|
if (!row) return;
|
|
5095
5226
|
event.preventDefault();
|
|
5096
|
-
const hasHandle = target
|
|
5097
|
-
.closest('[data-native-list-row-key]')
|
|
5098
|
-
?.querySelector('[data-native-list-reorder-handle]');
|
|
5099
5227
|
if (
|
|
5100
5228
|
event.key === ' ' &&
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
hasHandle)
|
|
5229
|
+
target === rowElement &&
|
|
5230
|
+
!this.pointerReorder?.active &&
|
|
5231
|
+
this.canStartKeyboardReorder(target)
|
|
5105
5232
|
) {
|
|
5106
5233
|
if (this.keyboardReorder) this.finishKeyboardReorder();
|
|
5107
5234
|
else this.startKeyboardReorder(row);
|
|
5108
5235
|
return;
|
|
5109
5236
|
}
|
|
5110
|
-
this.handleRowPress(
|
|
5111
|
-
row,
|
|
5112
|
-
target.closest<HTMLElement>('[data-native-list-row-key]') ?? undefined
|
|
5113
|
-
);
|
|
5237
|
+
this.handleRowPress(row, rowElement ?? undefined);
|
|
5114
5238
|
};
|
|
5115
5239
|
|
|
5116
5240
|
private startKeyboardReorder(row: RowModel) {
|
|
@@ -5137,17 +5261,13 @@ export class NativeListWebEngine {
|
|
|
5137
5261
|
from.sectionKey !== to.sectionKey
|
|
5138
5262
|
)
|
|
5139
5263
|
return;
|
|
5264
|
+
this.cancelPendingPointerReorder();
|
|
5140
5265
|
const rows = moveWebReorderRow(this.snapshot.rows, fromIndex, toIndex);
|
|
5141
|
-
this.
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
alignment: 'nearest',
|
|
5147
|
-
viewPosition: 0,
|
|
5148
|
-
viewOffset: 0,
|
|
5149
|
-
});
|
|
5150
|
-
this.focusMountedRow(state.sourceKey);
|
|
5266
|
+
this.setReorderRows(rows, toIndex);
|
|
5267
|
+
if (this.keyboardReorder === state) {
|
|
5268
|
+
this.updateReorderVisualState();
|
|
5269
|
+
this.focusMountedRow(state.sourceKey);
|
|
5270
|
+
}
|
|
5151
5271
|
}
|
|
5152
5272
|
|
|
5153
5273
|
private finishKeyboardReorder() {
|
|
@@ -5163,17 +5283,25 @@ export class NativeListWebEngine {
|
|
|
5163
5283
|
if (reorderEvent) this.callbacks.onReorder?.(reorderEvent);
|
|
5164
5284
|
}
|
|
5165
5285
|
|
|
5166
|
-
private cancelKeyboardReorder() {
|
|
5286
|
+
private cancelKeyboardReorder(restoreFocus = true, revealIndex?: number) {
|
|
5167
5287
|
const state = this.keyboardReorder;
|
|
5168
5288
|
if (!state) return;
|
|
5169
5289
|
this.keyboardReorder = undefined;
|
|
5170
|
-
this.
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
this.selectedKeys
|
|
5174
|
-
);
|
|
5290
|
+
this.cancelPendingPointerReorder();
|
|
5291
|
+
const rows = cancelWebReorderRows(state.originalRows);
|
|
5292
|
+
this.setReorderRows(rows, revealIndex);
|
|
5175
5293
|
this.updateReorderVisualState();
|
|
5176
|
-
this.
|
|
5294
|
+
if (restoreFocus && this.snapshot.rows === rows)
|
|
5295
|
+
this.focusMountedRow(state.sourceKey);
|
|
5296
|
+
}
|
|
5297
|
+
|
|
5298
|
+
private setReorderRows(rows: readonly RowModel[], revealIndex?: number) {
|
|
5299
|
+
this.cancelMarketPointer();
|
|
5300
|
+
this.pressedHelpElement = undefined;
|
|
5301
|
+
this.remapMountedRows(rows);
|
|
5302
|
+
this.snapshot = { ...this.snapshot, rows };
|
|
5303
|
+
this.rows = rows;
|
|
5304
|
+
this.recomputeLayout(revealIndex);
|
|
5177
5305
|
}
|
|
5178
5306
|
|
|
5179
5307
|
private focusMountedRow(key: string) {
|
|
@@ -5360,7 +5488,6 @@ export class NativeListWebEngine {
|
|
|
5360
5488
|
private handleReorderPointerDown = (event: PointerEvent) => {
|
|
5361
5489
|
if (
|
|
5362
5490
|
this.pointerReorder ||
|
|
5363
|
-
this.keyboardReorder ||
|
|
5364
5491
|
event.isPrimary === false ||
|
|
5365
5492
|
(event.pointerType === 'mouse' && event.button !== 0)
|
|
5366
5493
|
) {
|
|
@@ -5448,34 +5575,65 @@ export class NativeListWebEngine {
|
|
|
5448
5575
|
);
|
|
5449
5576
|
}
|
|
5450
5577
|
|
|
5451
|
-
private
|
|
5452
|
-
|
|
5453
|
-
const rowIndex = this.snapshot.rows.findIndex(
|
|
5578
|
+
private pointerReorderSourceIndex(state: PointerReorderState): number {
|
|
5579
|
+
const index = this.snapshot.rows.findIndex(
|
|
5454
5580
|
(row) => row.key === state.sourceKey
|
|
5455
5581
|
);
|
|
5456
|
-
const
|
|
5582
|
+
const element = this.mounted.get(index);
|
|
5457
5583
|
if (
|
|
5458
|
-
!
|
|
5584
|
+
!element ||
|
|
5459
5585
|
!this.canStartPointerReorder(state, this.snapshot) ||
|
|
5460
|
-
(state.handle && !
|
|
5586
|
+
(state.handle && !element.contains(state.handle))
|
|
5461
5587
|
) {
|
|
5588
|
+
return -1;
|
|
5589
|
+
}
|
|
5590
|
+
return index;
|
|
5591
|
+
}
|
|
5592
|
+
|
|
5593
|
+
private activatePointerReorder(state: PointerReorderState) {
|
|
5594
|
+
if (this.pointerReorder !== state) return;
|
|
5595
|
+
let sourceIndex = this.pointerReorderSourceIndex(state);
|
|
5596
|
+
const keyboard = this.keyboardReorder;
|
|
5597
|
+
const restoredIndex = keyboard
|
|
5598
|
+
? keyboard.originalRows.findIndex((row) => row.key === state.sourceKey)
|
|
5599
|
+
: sourceIndex;
|
|
5600
|
+
if (sourceIndex < 0 || restoredIndex < 0) {
|
|
5462
5601
|
this.cancelPointerReorder(false);
|
|
5463
5602
|
return;
|
|
5464
5603
|
}
|
|
5465
5604
|
this.clearReorderLongPress(state);
|
|
5466
|
-
state.currentIndex = rowIndex;
|
|
5467
|
-
state.originalRows = this.snapshot.rows;
|
|
5468
|
-
state.workingRows = [...this.snapshot.rows];
|
|
5469
|
-
state.active = true;
|
|
5470
5605
|
this.reorderClickPointers.set(state.pointerId, {
|
|
5471
5606
|
suppress: true,
|
|
5472
5607
|
pressTarget: this.reorderClickPointers.get(state.pointerId)?.pressTarget,
|
|
5473
5608
|
});
|
|
5474
5609
|
this.cancelMarketPointer();
|
|
5610
|
+
if (keyboard) {
|
|
5611
|
+
// Capture the pressed row at its visible position before restoring order.
|
|
5612
|
+
state.currentIndex = sourceIndex;
|
|
5613
|
+
state.workingRows = [...this.snapshot.rows];
|
|
5614
|
+
state.restoringKeyboardOrder = true;
|
|
5615
|
+
this.showReorderPreview(state);
|
|
5616
|
+
if (this.pointerReorder !== state) return;
|
|
5617
|
+
this.cancelKeyboardReorder(false, restoredIndex);
|
|
5618
|
+
if (this.pointerReorder !== state) return;
|
|
5619
|
+
sourceIndex = this.pointerReorderSourceIndex(state);
|
|
5620
|
+
if (sourceIndex < 0) {
|
|
5621
|
+
this.cancelPointerReorder(false);
|
|
5622
|
+
return;
|
|
5623
|
+
}
|
|
5624
|
+
state.restoringKeyboardOrder = false;
|
|
5625
|
+
}
|
|
5626
|
+
state.currentIndex = sourceIndex;
|
|
5627
|
+
state.originalRows = this.snapshot.rows;
|
|
5628
|
+
state.workingRows = [...this.snapshot.rows];
|
|
5629
|
+
state.active = true;
|
|
5475
5630
|
state.activatedAt = Date.now();
|
|
5476
5631
|
state.viewportRect = this.reorderViewportRect();
|
|
5477
5632
|
this.captureReorderPointer(state);
|
|
5478
|
-
|
|
5633
|
+
if (!keyboard) {
|
|
5634
|
+
this.showReorderPreview(state);
|
|
5635
|
+
if (this.pointerReorder !== state) return;
|
|
5636
|
+
}
|
|
5479
5637
|
if (
|
|
5480
5638
|
state.workingRows[state.currentIndex]?.type === 'walletGroup' &&
|
|
5481
5639
|
this.reorderCompactKey !== state.sourceKey
|
|
@@ -5484,7 +5642,21 @@ export class NativeListWebEngine {
|
|
|
5484
5642
|
this.mounted.forEach((element) =>
|
|
5485
5643
|
setData(element, 'nativeListAnimateReorder', true)
|
|
5486
5644
|
);
|
|
5487
|
-
this.recomputeLayout();
|
|
5645
|
+
this.recomputeLayout(keyboard ? sourceIndex : undefined);
|
|
5646
|
+
if (this.pointerReorder !== state) return;
|
|
5647
|
+
}
|
|
5648
|
+
if (keyboard) {
|
|
5649
|
+
const item = this.layout.items[sourceIndex];
|
|
5650
|
+
if (item) {
|
|
5651
|
+
state.handoff = {
|
|
5652
|
+
index: sourceIndex,
|
|
5653
|
+
scrollOffset: this.currentOffset(),
|
|
5654
|
+
itemCenter:
|
|
5655
|
+
(itemStart(item, this.layout.horizontal) +
|
|
5656
|
+
itemEnd(item, this.layout.horizontal)) /
|
|
5657
|
+
2,
|
|
5658
|
+
};
|
|
5659
|
+
}
|
|
5488
5660
|
}
|
|
5489
5661
|
this.updateReorderVisualState();
|
|
5490
5662
|
this.scheduleReorderAutoScroll();
|
|
@@ -5571,7 +5743,7 @@ export class NativeListWebEngine {
|
|
|
5571
5743
|
|
|
5572
5744
|
private setCurrentOffset(offset: number) {
|
|
5573
5745
|
if (this.externalScrollHost) {
|
|
5574
|
-
this.scrollToAbsoluteOffset(offset,
|
|
5746
|
+
this.scrollToAbsoluteOffset(offset, 'auto');
|
|
5575
5747
|
return;
|
|
5576
5748
|
}
|
|
5577
5749
|
const maximum = Math.max(0, this.contentLength() - this.viewportLength());
|
|
@@ -5588,6 +5760,7 @@ export class NativeListWebEngine {
|
|
|
5588
5760
|
|
|
5589
5761
|
private showReorderPreview(state: PointerReorderState) {
|
|
5590
5762
|
this.hideReorderPreview();
|
|
5763
|
+
if (this.pointerReorder !== state) return;
|
|
5591
5764
|
const source = [...this.mounted.values()].find(
|
|
5592
5765
|
(element) => element.dataset.nativeListRowKey === state.sourceKey
|
|
5593
5766
|
);
|
|
@@ -5791,7 +5964,7 @@ export class NativeListWebEngine {
|
|
|
5791
5964
|
this.reorderMoveFrame = undefined;
|
|
5792
5965
|
}
|
|
5793
5966
|
|
|
5794
|
-
private
|
|
5967
|
+
private reorderPointerCoordinate(
|
|
5795
5968
|
state: PointerReorderState,
|
|
5796
5969
|
clientX: number,
|
|
5797
5970
|
clientY: number
|
|
@@ -5800,7 +5973,27 @@ export class NativeListWebEngine {
|
|
|
5800
5973
|
const local = this.layout.horizontal
|
|
5801
5974
|
? Math.max(0, Math.min(Math.max(0, rect.width - 1), clientX - rect.left))
|
|
5802
5975
|
: Math.max(0, Math.min(Math.max(0, rect.height - 1), clientY - rect.top));
|
|
5803
|
-
|
|
5976
|
+
return this.currentOffset() + local;
|
|
5977
|
+
}
|
|
5978
|
+
|
|
5979
|
+
private reorderIndexAtPointer(
|
|
5980
|
+
state: PointerReorderState,
|
|
5981
|
+
clientX: number,
|
|
5982
|
+
clientY: number
|
|
5983
|
+
): number {
|
|
5984
|
+
const handoff = state.handoff;
|
|
5985
|
+
let coordinate: number;
|
|
5986
|
+
if (handoff) {
|
|
5987
|
+
const pointerDelta = this.layout.horizontal
|
|
5988
|
+
? clientX - state.startX
|
|
5989
|
+
: clientY - state.startY;
|
|
5990
|
+
const displacement =
|
|
5991
|
+
pointerDelta + (this.currentOffset() - handoff.scrollOffset);
|
|
5992
|
+
if (displacement === 0) return handoff.index;
|
|
5993
|
+
coordinate = handoff.itemCenter + displacement;
|
|
5994
|
+
} else {
|
|
5995
|
+
coordinate = this.reorderPointerCoordinate(state, clientX, clientY);
|
|
5996
|
+
}
|
|
5804
5997
|
const centerAt = (index: number) => {
|
|
5805
5998
|
const item = this.layout.items[index];
|
|
5806
5999
|
return item
|
|
@@ -5835,6 +6028,7 @@ export class NativeListWebEngine {
|
|
|
5835
6028
|
const to = state.workingRows[toIndex];
|
|
5836
6029
|
if (
|
|
5837
6030
|
!from ||
|
|
6031
|
+
from.key !== state.sourceKey ||
|
|
5838
6032
|
!to ||
|
|
5839
6033
|
fromIndex === toIndex ||
|
|
5840
6034
|
!this.isReorderable(from) ||
|
|
@@ -5890,6 +6084,8 @@ export class NativeListWebEngine {
|
|
|
5890
6084
|
if (!state?.active) return 0;
|
|
5891
6085
|
const rect = state.viewportRect ?? this.reorderViewportRect();
|
|
5892
6086
|
const point = this.layout.horizontal ? state.clientX : state.clientY;
|
|
6087
|
+
const pressPoint = this.layout.horizontal ? state.startX : state.startY;
|
|
6088
|
+
if (state.handoff && point === pressPoint) return 0;
|
|
5893
6089
|
const start = this.layout.horizontal ? rect.left : rect.top;
|
|
5894
6090
|
const end = this.layout.horizontal ? rect.right : rect.bottom;
|
|
5895
6091
|
return webReorderAutoScrollVelocity(
|
|
@@ -5941,6 +6137,7 @@ export class NativeListWebEngine {
|
|
|
5941
6137
|
|
|
5942
6138
|
private completePointerReorder(state: PointerReorderState) {
|
|
5943
6139
|
this.flushReorderMove(state);
|
|
6140
|
+
if (this.pointerReorder !== state) return;
|
|
5944
6141
|
const finalRows = this.snapshot.rows;
|
|
5945
6142
|
const reorderEvent = webReorderEventForRows(
|
|
5946
6143
|
state.originalRows,
|
|
@@ -5971,21 +6168,23 @@ export class NativeListWebEngine {
|
|
|
5971
6168
|
this.reorderAutoScrollFrame = undefined;
|
|
5972
6169
|
}
|
|
5973
6170
|
|
|
6171
|
+
private cancelPendingPointerReorder() {
|
|
6172
|
+
const pointer = this.pointerReorder;
|
|
6173
|
+
if (pointer && !pointer.active && !pointer.restoringKeyboardOrder)
|
|
6174
|
+
this.cancelPointerReorder(false);
|
|
6175
|
+
}
|
|
6176
|
+
|
|
5974
6177
|
private cancelPointerReorder(restore: boolean) {
|
|
5975
6178
|
const state = this.pointerReorder;
|
|
5976
6179
|
if (!state) return;
|
|
5977
6180
|
this.clearReorderLongPress(state);
|
|
5978
|
-
this.releaseReorderPointer(state);
|
|
5979
6181
|
this.pointerReorder = undefined;
|
|
6182
|
+
if (!state.active && !state.restoringKeyboardOrder) return;
|
|
6183
|
+
this.releaseReorderPointer(state);
|
|
5980
6184
|
this.stopReorderMove();
|
|
5981
6185
|
this.stopReorderAutoScroll();
|
|
5982
|
-
if (state.active && restore)
|
|
5983
|
-
this.
|
|
5984
|
-
this.setSnapshot(
|
|
5985
|
-
{ ...this.snapshot, rows: cancelWebReorderRows(state.originalRows) },
|
|
5986
|
-
this.selectedKeys
|
|
5987
|
-
);
|
|
5988
|
-
}
|
|
6186
|
+
if (state.active && restore)
|
|
6187
|
+
this.setReorderRows(cancelWebReorderRows(state.originalRows));
|
|
5989
6188
|
if (state.active && restore) this.animateReorderPreviewToCurrent(state);
|
|
5990
6189
|
else this.hideReorderPreview();
|
|
5991
6190
|
this.updateReorderVisualState();
|
|
@@ -6009,9 +6208,10 @@ export class NativeListWebEngine {
|
|
|
6009
6208
|
}
|
|
6010
6209
|
|
|
6011
6210
|
private updateReorderVisualState() {
|
|
6012
|
-
const
|
|
6211
|
+
const pointerSourceKey = this.pointerReorder?.active
|
|
6013
6212
|
? this.pointerReorder.sourceKey
|
|
6014
|
-
: this.
|
|
6213
|
+
: this.reorderSettlingKey;
|
|
6214
|
+
const sourceKey = this.keyboardReorder?.sourceKey ?? pointerSourceKey;
|
|
6015
6215
|
setData(this.root, 'nativeListDragging', Boolean(sourceKey));
|
|
6016
6216
|
if (this.reorderMovementTimer !== undefined) {
|
|
6017
6217
|
this.document.defaultView?.clearTimeout(this.reorderMovementTimer);
|
|
@@ -6034,7 +6234,11 @@ export class NativeListWebEngine {
|
|
|
6034
6234
|
'nativeListReorderExpanding',
|
|
6035
6235
|
element.dataset.nativeListRowKey === this.reorderExpandingKey
|
|
6036
6236
|
);
|
|
6037
|
-
setData(
|
|
6237
|
+
setData(
|
|
6238
|
+
element,
|
|
6239
|
+
'nativeListDragging',
|
|
6240
|
+
element.dataset.nativeListRowKey === pointerSourceKey
|
|
6241
|
+
);
|
|
6038
6242
|
if (dragging) element.setAttribute('aria-grabbed', 'true');
|
|
6039
6243
|
else element.removeAttribute('aria-grabbed');
|
|
6040
6244
|
});
|