@onekeyfe/react-native-native-list 6.8.0-23 → 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.
@@ -455,6 +455,7 @@ export const WEB_LIST_CSS = `
455
455
  .ok-native-list-wallet-member[data-native-list-selected="true"]>.ok-native-list-wallet-row{background:var(--nl-selected)}
456
456
  .ok-native-list-wallet-member:not([data-native-list-selected="true"]):hover>.ok-native-list-wallet-row{background:var(--nl-strong)}
457
457
  .ok-native-list-wallet-member:not([data-native-list-selected="true"]):active>.ok-native-list-wallet-row{background:var(--nl-pressed)}
458
+ .ok-native-list-item[data-native-list-reorderable="true"]:focus-visible>:is(.ok-native-list-row,.ok-native-list-wallet-group),
458
459
  .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}
459
460
  .ok-native-list-item[data-native-list-reorderable="true"]>.ok-native-list-row{cursor:grab}
460
461
  :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}
@@ -1467,7 +1468,7 @@ export class NativeListWebEngine {
1467
1468
  this.invalidateActionAnchor('snapshot');
1468
1469
  const capabilities = this.snapshot.capabilities;
1469
1470
  const nextCapabilities = validated.capabilities;
1470
- if (this.pointerReorder?.active || capabilities?.reorderable !== nextCapabilities?.reorderable || (capabilities?.reorderActivation ?? 'row') !== (nextCapabilities?.reorderActivation ?? 'row')) {
1471
+ if (this.pointerReorder?.active || this.pointerReorder?.restoringKeyboardOrder || this.keyboardReorder || capabilities?.reorderable !== nextCapabilities?.reorderable || (capabilities?.reorderActivation ?? 'row') !== (nextCapabilities?.reorderActivation ?? 'row')) {
1471
1472
  this.cancelPointerReorder(false);
1472
1473
  }
1473
1474
  const keyboardSource = this.keyboardReorder?.sourceKey;
@@ -1530,12 +1531,55 @@ export class NativeListWebEngine {
1530
1531
  }
1531
1532
  handleStructuralUserScroll = event => {
1532
1533
  if (event.type === 'pointerdown' && event.target !== (this.externalScrollHost ?? this.viewport) && event.pointerType !== 'touch') return;
1534
+ if (event.type === 'wheel' && this.keyboardReorder && this.wheelReachesScrollOwner(event)) {
1535
+ this.cancelKeyboardReorder(false);
1536
+ }
1533
1537
  this.structuralScrollInterrupted = true;
1534
1538
  if (this.structuralPrefixTransition) {
1535
1539
  this.cancelStructuralAnimation();
1536
1540
  this.recomputeLayout();
1537
1541
  }
1538
1542
  };
1543
+ wheelReachesScrollOwner(event) {
1544
+ if (event.defaultPrevented || event.ctrlKey) return false;
1545
+ const view = this.document.defaultView;
1546
+ if (!view) return true;
1547
+ const horizontal = event.shiftKey || Math.abs(event.deltaX) > Math.abs(event.deltaY);
1548
+ const delta = horizontal ? event.deltaX || event.deltaY : event.deltaY;
1549
+ for (const target of event.composedPath()) {
1550
+ if (target === event.currentTarget) break;
1551
+ if (!(target instanceof view.HTMLElement)) continue;
1552
+ const offset = horizontal ? target.scrollLeft : target.scrollTop;
1553
+ const scrollRange = horizontal ? target.scrollWidth - target.clientWidth : target.scrollHeight - target.clientHeight;
1554
+ if (scrollRange <= 0) continue;
1555
+ const style = view.getComputedStyle(target);
1556
+ const negativeOffset = this.hasNegativeScrollOffsets(style, horizontal);
1557
+ const minOffset = negativeOffset ? -scrollRange : 0;
1558
+ const maxOffset = negativeOffset ? 0 : scrollRange;
1559
+ const overflow = (horizontal ? style.overflowX : style.overflowY) || style.overflow;
1560
+ if (overflow !== 'auto' && overflow !== 'scroll') continue;
1561
+ const overscroll = horizontal ? style.overscrollBehaviorX : style.overscrollBehaviorY;
1562
+ if (overscroll === 'contain' || overscroll === 'none' || (delta < 0 ? offset > minOffset : offset < maxOffset)) {
1563
+ return false;
1564
+ }
1565
+ }
1566
+ return true;
1567
+ }
1568
+ hasNegativeScrollOffsets(style, horizontal) {
1569
+ const {
1570
+ writingMode,
1571
+ direction,
1572
+ display,
1573
+ flexDirection,
1574
+ flexWrap
1575
+ } = style;
1576
+ const horizontalWritingMode = !writingMode || writingMode === 'horizontal-tb';
1577
+ const inlineAxis = horizontal === horizontalWritingMode;
1578
+ const negative = inlineAxis ? direction === 'rtl' !== (writingMode === 'sideways-lr') : horizontal && writingMode.endsWith('-rl');
1579
+ const isFlexMainAxis = inlineAxis !== flexDirection.startsWith('column');
1580
+ const reversedFlex = (display === 'flex' || display === 'inline-flex') && (isFlexMainAxis ? flexDirection.endsWith('-reverse') : flexWrap === 'wrap-reverse');
1581
+ return negative !== reversedFlex;
1582
+ }
1539
1583
  updateStructuralTailWindow() {
1540
1584
  const tail = this.structuralTail;
1541
1585
  if (!tail) return;
@@ -1777,7 +1821,7 @@ export class NativeListWebEngine {
1777
1821
  const source = byKey.get(reorder.sourceKey);
1778
1822
  const canContinue = pointer ? this.canStartPointerReorder(pointer, next) : source && isWebRowReorderable(next, source) && (next.capabilities?.reorderActivation !== 'handle' || hasWebReorderHandle(source));
1779
1823
  if (!canContinue) {
1780
- if (pointer) this.cancelPointerReorder(false);
1824
+ this.cancelPointerReorder(false);
1781
1825
  if (keyboard) {
1782
1826
  this.keyboardReorder = undefined;
1783
1827
  this.updateReorderVisualState();
@@ -1833,7 +1877,7 @@ export class NativeListWebEngine {
1833
1877
  this.updateVisibleSelection();
1834
1878
  this.renderFooter();
1835
1879
  }
1836
- scrollToIndex(index, scroll) {
1880
+ scrollToIndex(index, scroll, behavior = scroll.animated ? 'smooth' : 'auto') {
1837
1881
  if (index < 0 || index >= this.rows.length) {
1838
1882
  this.emitScrollFailure(index, 'index-out-of-range');
1839
1883
  return;
@@ -1843,7 +1887,8 @@ export class NativeListWebEngine {
1843
1887
  this.pendingScroll = {
1844
1888
  kind: 'index',
1845
1889
  index,
1846
- scroll
1890
+ scroll,
1891
+ behavior
1847
1892
  };
1848
1893
  return;
1849
1894
  }
@@ -1852,7 +1897,8 @@ export class NativeListWebEngine {
1852
1897
  this.pendingScroll = {
1853
1898
  kind: 'index',
1854
1899
  index,
1855
- scroll
1900
+ scroll,
1901
+ behavior
1856
1902
  };
1857
1903
  return;
1858
1904
  }
@@ -1869,7 +1915,7 @@ export class NativeListWebEngine {
1869
1915
  viewPosition: scroll.viewPosition,
1870
1916
  viewOffset: scroll.viewOffset
1871
1917
  });
1872
- this.scrollToAbsoluteOffset(offset, scroll.animated);
1918
+ this.scrollToAbsoluteOffset(offset, behavior);
1873
1919
  }
1874
1920
  scrollToKey(key, scroll) {
1875
1921
  const index = this.rows.findIndex(row => row.key === key);
@@ -1888,8 +1934,8 @@ export class NativeListWebEngine {
1888
1934
  }
1889
1935
  if (this.externalScrollHost) {
1890
1936
  const geometry = this.externalGeometry();
1891
- this.writeExternalOffset(geometry.containerOrigin + offset, animated);
1892
- } else this.scrollToAbsoluteOffset(offset, animated);
1937
+ this.writeExternalOffset(geometry.containerOrigin + offset, animated ? 'smooth' : 'auto');
1938
+ } else this.scrollToAbsoluteOffset(offset, animated ? 'smooth' : 'auto');
1893
1939
  }
1894
1940
  scrollToEnd(animated) {
1895
1941
  this.notifyScrollCommandAccepted();
@@ -1902,8 +1948,8 @@ export class NativeListWebEngine {
1902
1948
  }
1903
1949
  if (this.externalScrollHost) {
1904
1950
  const geometry = this.externalGeometry();
1905
- this.writeExternalOffset(geometry.end - this.externalScrollHost.clientHeight, animated);
1906
- } else this.scrollToAbsoluteOffset(Math.max(0, this.contentLength() - this.viewportLength()), animated);
1951
+ this.writeExternalOffset(geometry.end - this.externalScrollHost.clientHeight, animated ? 'smooth' : 'auto');
1952
+ } else this.scrollToAbsoluteOffset(Math.max(0, this.contentLength() - this.viewportLength()), animated ? 'smooth' : 'auto');
1907
1953
  }
1908
1954
  scrollToLocation(params, scroll) {
1909
1955
  const index = resolveLocationIndex(this.snapshot.rows, params);
@@ -2111,7 +2157,7 @@ export class NativeListWebEngine {
2111
2157
  this.viewportFrame.style.height = value;
2112
2158
  this.root.style.height = value;
2113
2159
  }
2114
- recomputeLayout = () => {
2160
+ recomputeLayout = revealIndex => {
2115
2161
  if (this.destroyed) return;
2116
2162
  if (this.structuralPrefixTransition && this.lastViewportWidth > 0 && this.viewport.clientWidth > 0 && this.viewport.clientWidth !== this.lastViewportWidth) this.cancelStructuralAnimation();
2117
2163
  if (this.structuralRenderedHeight === undefined) this.reactFooterHeight = this.readReactFooterHeight();else {
@@ -2172,7 +2218,17 @@ export class NativeListWebEngine {
2172
2218
  this.viewport.scrollLeft = 0;
2173
2219
  this.viewport.scrollTop = 0;
2174
2220
  }
2175
- this.renderWindow();
2221
+ if (revealIndex !== undefined) {
2222
+ // Mount against the destination offset, even on hosts with smooth scrolling.
2223
+ this.pendingScroll = undefined;
2224
+ this.scrollToIndex(revealIndex, {
2225
+ animated: false,
2226
+ alignment: 'nearest',
2227
+ viewPosition: 0,
2228
+ viewOffset: 0
2229
+ }, 'instant');
2230
+ }
2231
+ this.renderWindow(revealIndex);
2176
2232
  this.performPendingScroll();
2177
2233
  };
2178
2234
  updateAvatarWindow() {
@@ -2216,10 +2272,17 @@ export class NativeListWebEngine {
2216
2272
  }
2217
2273
  });
2218
2274
  }
2219
- renderWindow() {
2275
+ renderWindow(revealIndex) {
2220
2276
  this.updateAvatarWindow();
2221
2277
  const viewportLength = this.viewportLength();
2222
2278
  const visible = this.externalScrollHost && !this.externalGeometry().visible ? [] : webLayoutItemsForMount(this.layout, this.currentOffset(), viewportLength, this.virtualizationEnabled, viewportLength * OVERSCAN_VIEWPORTS);
2279
+ const keyboardSource = this.keyboardReorder?.sourceKey;
2280
+ if (keyboardSource && !visible.some(({
2281
+ key
2282
+ }) => key === keyboardSource)) {
2283
+ this.cancelKeyboardReorder(false);
2284
+ return;
2285
+ }
2223
2286
  const desired = new Set(visible.map(item => item.index));
2224
2287
  this.mounted.forEach((element, index) => {
2225
2288
  const nextRow = this.rows[index];
@@ -2246,11 +2309,12 @@ export class NativeListWebEngine {
2246
2309
  this.content.appendChild(element);
2247
2310
  }
2248
2311
  this.positionElement(element, layoutItem);
2249
- setData(element, 'nativeListReorderable', this.isReorderable(row));
2250
2312
  const signature = webRowRenderSignature(row);
2251
2313
  if (element.dataset.nativeListRowKey !== row.key || element.dataset.renderSignature !== signature) {
2252
2314
  this.renderElement(element, layoutItem.index, row);
2253
2315
  element.dataset.renderSignature = signature;
2316
+ } else {
2317
+ this.updateRowReorderability(element, layoutItem.index, row);
2254
2318
  }
2255
2319
  });
2256
2320
  let measuredHeightChanged = false;
@@ -2270,7 +2334,7 @@ export class NativeListWebEngine {
2270
2334
  }
2271
2335
  });
2272
2336
  if (measuredHeightChanged) {
2273
- this.recomputeLayout();
2337
+ this.recomputeLayout(revealIndex);
2274
2338
  return;
2275
2339
  }
2276
2340
  this.updateVisibleSelection();
@@ -2282,6 +2346,18 @@ export class NativeListWebEngine {
2282
2346
  element.style.width = String(item.width) + 'px';
2283
2347
  element.style.height = String(item.height) + 'px';
2284
2348
  }
2349
+ updateRowReorderability(element, index, row) {
2350
+ const reorderable = this.snapshot.rows[index] === row && this.isReorderable(row);
2351
+ setData(element, 'nativeListReorderable', reorderable);
2352
+ if (isRowPressEnabled(row) || this.canStartKeyboardReorder(element)) {
2353
+ if (element.tabIndex !== 0) element.tabIndex = 0;
2354
+ } else {
2355
+ element.removeAttribute('tabindex');
2356
+ }
2357
+ }
2358
+ canStartKeyboardReorder(element) {
2359
+ return element.dataset.nativeListReorderable === 'true' && (this.snapshot.capabilities?.reorderActivation !== 'handle' || element.querySelector('[data-native-list-reorder-handle]') !== null);
2360
+ }
2285
2361
  renderElement(element, index, row, overlay = false) {
2286
2362
  this.invalidateActionAnchorForElement(element);
2287
2363
  const registered = rowRenderer(row);
@@ -2299,18 +2375,12 @@ export class NativeListWebEngine {
2299
2375
  setData(element, 'testid', row.testID);
2300
2376
  // OneKey patch: deprecation dims a row without disabling its actions.
2301
2377
  element.style.opacity = String((row.style?.container?.opacity ?? row.opacity ?? 1) * (row.disabled ? 0.5 : 1));
2302
- setData(element, 'nativeListReorderable', this.isReorderable(row));
2303
2378
  setData(element, 'nativeListDragging', this.pointerReorder?.active && this.pointerReorder.sourceKey === row.key);
2304
2379
  setData(element, 'separator', row.separator);
2305
2380
  setData(element, 'groupPosition', row.groupPosition);
2306
2381
  setData(element, 'tableAlternate', this.snapshot.layout.kind === 'table' && row.type === 'dataRow' && (row.index ?? index) % 2 === 0);
2307
2382
  element.setAttribute('role', 'listitem');
2308
2383
  element.setAttribute('aria-label', row.accessibilityLabel ?? this.rowLabel(row));
2309
- if (isRowPressEnabled(row)) {
2310
- element.tabIndex = 0;
2311
- } else {
2312
- element.removeAttribute('tabindex');
2313
- }
2314
2384
  element.draggable = false;
2315
2385
  const context = {
2316
2386
  document: this.document,
@@ -2336,6 +2406,7 @@ export class NativeListWebEngine {
2336
2406
  // Template and presentation defaults must precede caller overrides.
2337
2407
  applyRowStyle(body, row);
2338
2408
  if (body.parentElement !== element) element.replaceChildren(body);
2409
+ this.updateRowReorderability(element, overlay ? -1 : index, row);
2339
2410
  if (row.type === 'market' && row.diagnostics?.imageBindActionKey && body.querySelector('img')) {
2340
2411
  this.callbacks.onRowAction?.({
2341
2412
  rowKey: row.key,
@@ -2698,20 +2769,20 @@ export class NativeListWebEngine {
2698
2769
  handleCollapsiblePagerInsetsChanged = () => {
2699
2770
  this.recomputeLayout();
2700
2771
  };
2701
- writeExternalOffset(rawOffset, animated) {
2772
+ writeExternalOffset(rawOffset, behavior) {
2702
2773
  this.externalGeometryCache = undefined;
2703
2774
  const host = this.externalScrollHost;
2704
2775
  const scrollTo = host.ownerDocument.defaultView?.Element.prototype.scrollTo ?? host.scrollTo;
2705
2776
  scrollTo.call(host, {
2706
2777
  top: Math.max(0, Math.min(host.scrollHeight - host.clientHeight, rawOffset)),
2707
- behavior: animated ? 'smooth' : 'auto'
2778
+ behavior
2708
2779
  });
2709
2780
  this.scheduleFrame();
2710
2781
  }
2711
- scrollToAbsoluteOffset(offset, animated) {
2782
+ scrollToAbsoluteOffset(offset, behavior) {
2712
2783
  if (this.externalScrollHost) {
2713
2784
  const geometry = this.externalGeometry();
2714
- this.writeExternalOffset(geometry.origin + offset - this.externalStickyInset, animated);
2785
+ this.writeExternalOffset(geometry.origin + offset - this.externalStickyInset, behavior);
2715
2786
  return;
2716
2787
  }
2717
2788
  const resolved = Math.min(Math.max(0, offset), Math.max(0, this.contentLength() - this.viewportLength()));
@@ -2719,11 +2790,11 @@ export class NativeListWebEngine {
2719
2790
  this.viewport.scrollTo(this.layout.horizontal ? {
2720
2791
  left: rawOffset,
2721
2792
  top: 0,
2722
- behavior: animated ? 'smooth' : 'auto'
2793
+ behavior
2723
2794
  } : {
2724
2795
  left: 0,
2725
2796
  top: rawOffset,
2726
- behavior: animated ? 'smooth' : 'auto'
2797
+ behavior
2727
2798
  });
2728
2799
  this.scheduleFrame();
2729
2800
  }
@@ -2731,7 +2802,7 @@ export class NativeListWebEngine {
2731
2802
  const pending = this.pendingScroll;
2732
2803
  if (!pending || !this.canScroll()) return;
2733
2804
  this.pendingScroll = undefined;
2734
- if (pending.kind === 'index') this.scrollToIndex(pending.index, pending.scroll);else if (pending.kind === 'offset') this.scrollToOffset(pending.offset, pending.animated);else this.scrollToEnd(pending.animated);
2805
+ if (pending.kind === 'index') this.scrollToIndex(pending.index, pending.scroll, pending.behavior);else if (pending.kind === 'offset') this.scrollToOffset(pending.offset, pending.animated);else this.scrollToEnd(pending.animated);
2735
2806
  }
2736
2807
  rowAtElement(element) {
2737
2808
  if (!element) return undefined;
@@ -3086,17 +3157,8 @@ export class NativeListWebEngine {
3086
3157
  this.handleRowPress(sourceRow, rowElement ?? undefined, memberElement ?? rowElement ?? undefined);
3087
3158
  };
3088
3159
  handleKeyDown = event => {
3089
- if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && event.target.matches('[role="button"][data-native-list-hover-action]')) {
3090
- event.preventDefault();
3091
- if (this.actionAnchor?.actionElement !== event.target || !this.actionAnchor.open) this.emitHoverAction(event.target);
3092
- return;
3093
- }
3094
- // OneKey patch: non-button title help supports keyboard activation.
3095
- if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && event.target.matches('[role="button"][data-native-list-action]')) {
3096
- event.preventDefault();
3097
- event.target.click();
3098
- return;
3099
- }
3160
+ const target = event.target;
3161
+ if (!(target instanceof HTMLElement)) return;
3100
3162
  if (event.key === 'Escape') {
3101
3163
  if (this.pointerReorder?.active) {
3102
3164
  event.preventDefault();
@@ -3109,6 +3171,27 @@ export class NativeListWebEngine {
3109
3171
  return;
3110
3172
  }
3111
3173
  }
3174
+ const rowElement = target.closest('[data-native-list-row-key]');
3175
+ if (this.keyboardReorder && (event.key === 'Tab' || target.dataset.nativeListRowKey !== this.keyboardReorder.sourceKey)) {
3176
+ const bindingEpoch = rowElement?.dataset.nativeListBindingEpoch;
3177
+ this.cancelKeyboardReorder(false);
3178
+ if (event.key === 'Tab') return;
3179
+ if (!this.root.contains(target) || rowElement?.dataset.nativeListBindingEpoch !== bindingEpoch) {
3180
+ event.preventDefault();
3181
+ return;
3182
+ }
3183
+ }
3184
+ if ((event.key === 'Enter' || event.key === ' ') && target.matches('[role="button"][data-native-list-hover-action]')) {
3185
+ event.preventDefault();
3186
+ if (this.actionAnchor?.actionElement !== target || !this.actionAnchor.open) this.emitHoverAction(target);
3187
+ return;
3188
+ }
3189
+ // OneKey patch: non-button title help supports keyboard activation.
3190
+ if ((event.key === 'Enter' || event.key === ' ') && target.matches('[role="button"][data-native-list-action]')) {
3191
+ event.preventDefault();
3192
+ target.click();
3193
+ return;
3194
+ }
3112
3195
  if (this.keyboardReorder && (event.key === 'ArrowUp' || event.key === 'ArrowLeft')) {
3113
3196
  event.preventDefault();
3114
3197
  this.moveKeyboardReorder(-1);
@@ -3120,18 +3203,15 @@ export class NativeListWebEngine {
3120
3203
  return;
3121
3204
  }
3122
3205
  if (event.key !== 'Enter' && event.key !== ' ') return;
3123
- const target = event.target;
3124
- if (!(target instanceof HTMLElement)) return;
3125
3206
  if (target.matches('button')) return;
3126
- const row = this.rowAtElement(target.closest('[data-native-list-row-key]'));
3207
+ const row = this.rowAtElement(rowElement);
3127
3208
  if (!row) return;
3128
3209
  event.preventDefault();
3129
- const hasHandle = target.closest('[data-native-list-row-key]')?.querySelector('[data-native-list-reorder-handle]');
3130
- if (event.key === ' ' && this.isReorderable(row) && (this.keyboardReorder || this.snapshot.capabilities?.reorderActivation !== 'handle' || hasHandle)) {
3210
+ if (event.key === ' ' && target === rowElement && !this.pointerReorder?.active && this.canStartKeyboardReorder(target)) {
3131
3211
  if (this.keyboardReorder) this.finishKeyboardReorder();else this.startKeyboardReorder(row);
3132
3212
  return;
3133
3213
  }
3134
- this.handleRowPress(row, target.closest('[data-native-list-row-key]') ?? undefined);
3214
+ this.handleRowPress(row, rowElement ?? undefined);
3135
3215
  };
3136
3216
  startKeyboardReorder(row) {
3137
3217
  this.keyboardReorder = {
@@ -3148,20 +3228,13 @@ export class NativeListWebEngine {
3148
3228
  const from = this.snapshot.rows[fromIndex];
3149
3229
  const to = this.snapshot.rows[toIndex];
3150
3230
  if (!from || !to || !this.isReorderable(to) || from.sectionKey !== to.sectionKey) return;
3231
+ this.cancelPendingPointerReorder();
3151
3232
  const rows = moveWebReorderRow(this.snapshot.rows, fromIndex, toIndex);
3152
- this.remapMountedRows(rows);
3153
- this.setSnapshot({
3154
- ...this.snapshot,
3155
- rows
3156
- }, this.selectedKeys);
3157
- this.updateReorderVisualState();
3158
- this.scrollToIndex(toIndex, {
3159
- animated: false,
3160
- alignment: 'nearest',
3161
- viewPosition: 0,
3162
- viewOffset: 0
3163
- });
3164
- this.focusMountedRow(state.sourceKey);
3233
+ this.setReorderRows(rows, toIndex);
3234
+ if (this.keyboardReorder === state) {
3235
+ this.updateReorderVisualState();
3236
+ this.focusMountedRow(state.sourceKey);
3237
+ }
3165
3238
  }
3166
3239
  finishKeyboardReorder() {
3167
3240
  const state = this.keyboardReorder;
@@ -3171,17 +3244,26 @@ export class NativeListWebEngine {
3171
3244
  this.updateReorderVisualState();
3172
3245
  if (reorderEvent) this.callbacks.onReorder?.(reorderEvent);
3173
3246
  }
3174
- cancelKeyboardReorder() {
3247
+ cancelKeyboardReorder(restoreFocus = true, revealIndex) {
3175
3248
  const state = this.keyboardReorder;
3176
3249
  if (!state) return;
3177
3250
  this.keyboardReorder = undefined;
3178
- this.remapMountedRows(state.originalRows);
3179
- this.setSnapshot({
3180
- ...this.snapshot,
3181
- rows: cancelWebReorderRows(state.originalRows)
3182
- }, this.selectedKeys);
3251
+ this.cancelPendingPointerReorder();
3252
+ const rows = cancelWebReorderRows(state.originalRows);
3253
+ this.setReorderRows(rows, revealIndex);
3183
3254
  this.updateReorderVisualState();
3184
- this.focusMountedRow(state.sourceKey);
3255
+ if (restoreFocus && this.snapshot.rows === rows) this.focusMountedRow(state.sourceKey);
3256
+ }
3257
+ setReorderRows(rows, revealIndex) {
3258
+ this.cancelMarketPointer();
3259
+ this.pressedHelpElement = undefined;
3260
+ this.remapMountedRows(rows);
3261
+ this.snapshot = {
3262
+ ...this.snapshot,
3263
+ rows
3264
+ };
3265
+ this.rows = rows;
3266
+ this.recomputeLayout(revealIndex);
3185
3267
  }
3186
3268
  focusMountedRow(key) {
3187
3269
  [...this.mounted.values()].find(element => element.dataset.nativeListRowKey === key)?.focus({
@@ -3304,7 +3386,7 @@ export class NativeListWebEngine {
3304
3386
  setData(this.refreshIndicator, 'visible', refreshing);
3305
3387
  }
3306
3388
  handleReorderPointerDown = event => {
3307
- if (this.pointerReorder || this.keyboardReorder || event.isPrimary === false || event.pointerType === 'mouse' && event.button !== 0) {
3389
+ if (this.pointerReorder || event.isPrimary === false || event.pointerType === 'mouse' && event.button !== 0) {
3308
3390
  return;
3309
3391
  }
3310
3392
  const target = event.target;
@@ -3358,32 +3440,71 @@ export class NativeListWebEngine {
3358
3440
  const slot = Number(state.handle.dataset.nativeListAnchorSlot);
3359
3441
  return Boolean(handleRow && 'trailing' in handleRow && handleRow.trailing?.[slot]?.kind === 'drag');
3360
3442
  }
3443
+ pointerReorderSourceIndex(state) {
3444
+ const index = this.snapshot.rows.findIndex(row => row.key === state.sourceKey);
3445
+ const element = this.mounted.get(index);
3446
+ if (!element || !this.canStartPointerReorder(state, this.snapshot) || state.handle && !element.contains(state.handle)) {
3447
+ return -1;
3448
+ }
3449
+ return index;
3450
+ }
3361
3451
  activatePointerReorder(state) {
3362
3452
  if (this.pointerReorder !== state) return;
3363
- const rowIndex = this.snapshot.rows.findIndex(row => row.key === state.sourceKey);
3364
- const source = this.mounted.get(rowIndex);
3365
- if (!source || !this.canStartPointerReorder(state, this.snapshot) || state.handle && !source.contains(state.handle)) {
3453
+ let sourceIndex = this.pointerReorderSourceIndex(state);
3454
+ const keyboard = this.keyboardReorder;
3455
+ const restoredIndex = keyboard ? keyboard.originalRows.findIndex(row => row.key === state.sourceKey) : sourceIndex;
3456
+ if (sourceIndex < 0 || restoredIndex < 0) {
3366
3457
  this.cancelPointerReorder(false);
3367
3458
  return;
3368
3459
  }
3369
3460
  this.clearReorderLongPress(state);
3370
- state.currentIndex = rowIndex;
3371
- state.originalRows = this.snapshot.rows;
3372
- state.workingRows = [...this.snapshot.rows];
3373
- state.active = true;
3374
3461
  this.reorderClickPointers.set(state.pointerId, {
3375
3462
  suppress: true,
3376
3463
  pressTarget: this.reorderClickPointers.get(state.pointerId)?.pressTarget
3377
3464
  });
3378
3465
  this.cancelMarketPointer();
3466
+ if (keyboard) {
3467
+ // Capture the pressed row at its visible position before restoring order.
3468
+ state.currentIndex = sourceIndex;
3469
+ state.workingRows = [...this.snapshot.rows];
3470
+ state.restoringKeyboardOrder = true;
3471
+ this.showReorderPreview(state);
3472
+ if (this.pointerReorder !== state) return;
3473
+ this.cancelKeyboardReorder(false, restoredIndex);
3474
+ if (this.pointerReorder !== state) return;
3475
+ sourceIndex = this.pointerReorderSourceIndex(state);
3476
+ if (sourceIndex < 0) {
3477
+ this.cancelPointerReorder(false);
3478
+ return;
3479
+ }
3480
+ state.restoringKeyboardOrder = false;
3481
+ }
3482
+ state.currentIndex = sourceIndex;
3483
+ state.originalRows = this.snapshot.rows;
3484
+ state.workingRows = [...this.snapshot.rows];
3485
+ state.active = true;
3379
3486
  state.activatedAt = Date.now();
3380
3487
  state.viewportRect = this.reorderViewportRect();
3381
3488
  this.captureReorderPointer(state);
3382
- this.showReorderPreview(state);
3489
+ if (!keyboard) {
3490
+ this.showReorderPreview(state);
3491
+ if (this.pointerReorder !== state) return;
3492
+ }
3383
3493
  if (state.workingRows[state.currentIndex]?.type === 'walletGroup' && this.reorderCompactKey !== state.sourceKey) {
3384
3494
  this.reorderCompactKey = state.sourceKey;
3385
3495
  this.mounted.forEach(element => setData(element, 'nativeListAnimateReorder', true));
3386
- this.recomputeLayout();
3496
+ this.recomputeLayout(keyboard ? sourceIndex : undefined);
3497
+ if (this.pointerReorder !== state) return;
3498
+ }
3499
+ if (keyboard) {
3500
+ const item = this.layout.items[sourceIndex];
3501
+ if (item) {
3502
+ state.handoff = {
3503
+ index: sourceIndex,
3504
+ scrollOffset: this.currentOffset(),
3505
+ itemCenter: (itemStart(item, this.layout.horizontal) + itemEnd(item, this.layout.horizontal)) / 2
3506
+ };
3507
+ }
3387
3508
  }
3388
3509
  this.updateReorderVisualState();
3389
3510
  this.scheduleReorderAutoScroll();
@@ -3453,7 +3574,7 @@ export class NativeListWebEngine {
3453
3574
  };
3454
3575
  setCurrentOffset(offset) {
3455
3576
  if (this.externalScrollHost) {
3456
- this.scrollToAbsoluteOffset(offset, false);
3577
+ this.scrollToAbsoluteOffset(offset, 'auto');
3457
3578
  return;
3458
3579
  }
3459
3580
  const maximum = Math.max(0, this.contentLength() - this.viewportLength());
@@ -3465,6 +3586,7 @@ export class NativeListWebEngine {
3465
3586
  }
3466
3587
  showReorderPreview(state) {
3467
3588
  this.hideReorderPreview();
3589
+ if (this.pointerReorder !== state) return;
3468
3590
  const source = [...this.mounted.values()].find(element => element.dataset.nativeListRowKey === state.sourceKey);
3469
3591
  const row = source?.firstElementChild;
3470
3592
  if (!source || !row) return;
@@ -3617,10 +3739,22 @@ export class NativeListWebEngine {
3617
3739
  this.cancelFrame(this.reorderMoveFrame);
3618
3740
  this.reorderMoveFrame = undefined;
3619
3741
  }
3620
- reorderIndexAtPointer(state, clientX, clientY) {
3742
+ reorderPointerCoordinate(state, clientX, clientY) {
3621
3743
  const rect = state.viewportRect ?? this.reorderViewportRect();
3622
3744
  const local = this.layout.horizontal ? Math.max(0, Math.min(Math.max(0, rect.width - 1), clientX - rect.left)) : Math.max(0, Math.min(Math.max(0, rect.height - 1), clientY - rect.top));
3623
- const coordinate = this.currentOffset() + local;
3745
+ return this.currentOffset() + local;
3746
+ }
3747
+ reorderIndexAtPointer(state, clientX, clientY) {
3748
+ const handoff = state.handoff;
3749
+ let coordinate;
3750
+ if (handoff) {
3751
+ const pointerDelta = this.layout.horizontal ? clientX - state.startX : clientY - state.startY;
3752
+ const displacement = pointerDelta + (this.currentOffset() - handoff.scrollOffset);
3753
+ if (displacement === 0) return handoff.index;
3754
+ coordinate = handoff.itemCenter + displacement;
3755
+ } else {
3756
+ coordinate = this.reorderPointerCoordinate(state, clientX, clientY);
3757
+ }
3624
3758
  const centerAt = index => {
3625
3759
  const item = this.layout.items[index];
3626
3760
  return item ? (itemStart(item, this.layout.horizontal) + itemEnd(item, this.layout.horizontal)) / 2 : Number.POSITIVE_INFINITY;
@@ -3643,7 +3777,7 @@ export class NativeListWebEngine {
3643
3777
  const toIndex = this.reorderIndexAtPointer(state, clientX, clientY);
3644
3778
  const from = state.workingRows[fromIndex];
3645
3779
  const to = state.workingRows[toIndex];
3646
- if (!from || !to || fromIndex === toIndex || !this.isReorderable(from) || !this.isReorderable(to) || from.sectionKey !== to.sectionKey) return;
3780
+ if (!from || from.key !== state.sourceKey || !to || fromIndex === toIndex || !this.isReorderable(from) || !this.isReorderable(to) || from.sectionKey !== to.sectionKey) return;
3647
3781
  const [moved] = state.workingRows.splice(fromIndex, 1);
3648
3782
  if (!moved) return;
3649
3783
  state.workingRows.splice(toIndex, 0, moved);
@@ -3686,6 +3820,8 @@ export class NativeListWebEngine {
3686
3820
  if (!state?.active) return 0;
3687
3821
  const rect = state.viewportRect ?? this.reorderViewportRect();
3688
3822
  const point = this.layout.horizontal ? state.clientX : state.clientY;
3823
+ const pressPoint = this.layout.horizontal ? state.startX : state.startY;
3824
+ if (state.handoff && point === pressPoint) return 0;
3689
3825
  const start = this.layout.horizontal ? rect.left : rect.top;
3690
3826
  const end = this.layout.horizontal ? rect.right : rect.bottom;
3691
3827
  return webReorderAutoScrollVelocity(point, start, end, Date.now() - (state.activatedAt ?? 0));
@@ -3723,6 +3859,7 @@ export class NativeListWebEngine {
3723
3859
  };
3724
3860
  completePointerReorder(state) {
3725
3861
  this.flushReorderMove(state);
3862
+ if (this.pointerReorder !== state) return;
3726
3863
  const finalRows = this.snapshot.rows;
3727
3864
  const reorderEvent = webReorderEventForRows(state.originalRows, finalRows, state.sourceKey);
3728
3865
  this.animateReorderPreviewToCurrent(state);
@@ -3742,21 +3879,20 @@ export class NativeListWebEngine {
3742
3879
  this.cancelFrame(this.reorderAutoScrollFrame);
3743
3880
  this.reorderAutoScrollFrame = undefined;
3744
3881
  }
3882
+ cancelPendingPointerReorder() {
3883
+ const pointer = this.pointerReorder;
3884
+ if (pointer && !pointer.active && !pointer.restoringKeyboardOrder) this.cancelPointerReorder(false);
3885
+ }
3745
3886
  cancelPointerReorder(restore) {
3746
3887
  const state = this.pointerReorder;
3747
3888
  if (!state) return;
3748
3889
  this.clearReorderLongPress(state);
3749
- this.releaseReorderPointer(state);
3750
3890
  this.pointerReorder = undefined;
3891
+ if (!state.active && !state.restoringKeyboardOrder) return;
3892
+ this.releaseReorderPointer(state);
3751
3893
  this.stopReorderMove();
3752
3894
  this.stopReorderAutoScroll();
3753
- if (state.active && restore) {
3754
- this.remapMountedRows(state.originalRows);
3755
- this.setSnapshot({
3756
- ...this.snapshot,
3757
- rows: cancelWebReorderRows(state.originalRows)
3758
- }, this.selectedKeys);
3759
- }
3895
+ if (state.active && restore) this.setReorderRows(cancelWebReorderRows(state.originalRows));
3760
3896
  if (state.active && restore) this.animateReorderPreviewToCurrent(state);else this.hideReorderPreview();
3761
3897
  this.updateReorderVisualState();
3762
3898
  }
@@ -3777,7 +3913,8 @@ export class NativeListWebEngine {
3777
3913
  });
3778
3914
  }
3779
3915
  updateReorderVisualState() {
3780
- const sourceKey = this.pointerReorder?.active ? this.pointerReorder.sourceKey : this.keyboardReorder?.sourceKey ?? this.reorderSettlingKey;
3916
+ const pointerSourceKey = this.pointerReorder?.active ? this.pointerReorder.sourceKey : this.reorderSettlingKey;
3917
+ const sourceKey = this.keyboardReorder?.sourceKey ?? pointerSourceKey;
3781
3918
  setData(this.root, 'nativeListDragging', Boolean(sourceKey));
3782
3919
  if (this.reorderMovementTimer !== undefined) {
3783
3920
  this.document.defaultView?.clearTimeout(this.reorderMovementTimer);
@@ -3796,7 +3933,7 @@ export class NativeListWebEngine {
3796
3933
  this.mounted.forEach(element => {
3797
3934
  const dragging = element.dataset.nativeListRowKey === sourceKey;
3798
3935
  setData(element, 'nativeListReorderExpanding', element.dataset.nativeListRowKey === this.reorderExpandingKey);
3799
- setData(element, 'nativeListDragging', dragging);
3936
+ setData(element, 'nativeListDragging', element.dataset.nativeListRowKey === pointerSourceKey);
3800
3937
  if (dragging) element.setAttribute('aria-grabbed', 'true');else element.removeAttribute('aria-grabbed');
3801
3938
  });
3802
3939
  }