@astryxdesign/core 0.7.15-canary.gbe99721 → 0.7.15-canary.gbef2f83
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/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheet.js +11 -6
- package/dist/Layer/layerAnimations.stylex.d.ts.map +1 -1
- package/dist/Layer/layerAnimations.stylex.js +17 -13
- package/dist/Layer/layerEntranceSide.d.ts +12 -4
- package/dist/Layer/layerEntranceSide.d.ts.map +1 -1
- package/dist/Layer/layerEntranceSide.js +19 -7
- package/dist/List/ListItem.d.ts +3 -2
- package/dist/List/ListItem.d.ts.map +1 -1
- package/dist/List/ListReorderHandle.d.ts +7 -0
- package/dist/List/ListReorderHandle.d.ts.map +1 -1
- package/dist/List/ListReorderHandle.js +42 -58
- package/dist/List/listReorderContext.d.ts.map +1 -1
- package/dist/List/listReorderContext.js +4 -4
- package/dist/List/listReorderEngine.d.ts +50 -2
- package/dist/List/listReorderEngine.d.ts.map +1 -1
- package/dist/List/listReorderEngine.js +205 -10
- package/dist/Slider/Slider.d.ts.map +1 -1
- package/dist/Slider/Slider.js +6 -8
- package/dist/Table/BaseTable.d.ts.map +1 -1
- package/dist/Table/BaseTable.js +35 -5
- package/dist/Table/index.d.ts +3 -1
- package/dist/Table/index.d.ts.map +1 -1
- package/dist/Table/index.js +1 -0
- package/dist/Table/plugins/infiniteScroll/TableInfiniteScrollWide.a11y.chromium.spec.d.ts.map +1 -0
- package/dist/Table/plugins/infiniteScroll/index.d.ts +9 -0
- package/dist/Table/plugins/infiniteScroll/index.d.ts.map +1 -0
- package/dist/Table/plugins/infiniteScroll/index.js +9 -0
- package/dist/Table/plugins/infiniteScroll/useTableInfiniteScroll.d.ts +29 -0
- package/dist/Table/plugins/infiniteScroll/useTableInfiniteScroll.d.ts.map +1 -0
- package/dist/Table/plugins/infiniteScroll/useTableInfiniteScroll.js +394 -0
- package/dist/Table/tableRuntime.d.ts +1 -0
- package/dist/Table/tableRuntime.d.ts.map +1 -1
- package/dist/Table/types.d.ts +23 -0
- package/dist/Table/types.d.ts.map +1 -1
- package/dist/Table/useBaseTablePlugins.js +2 -2
- package/dist/TextArea/TextArea.d.ts +10 -1
- package/dist/TextArea/TextArea.d.ts.map +1 -1
- package/dist/TextArea/TextArea.js +2 -0
- package/dist/astryx.css +10 -10
- package/dist/dragToSnapPoints/createDragToSnapPoints.d.ts +156 -0
- package/dist/dragToSnapPoints/createDragToSnapPoints.d.ts.map +1 -1
- package/dist/dragToSnapPoints/createDragToSnapPoints.js +313 -97
- package/dist/gestures/createPanGesture.d.ts +41 -0
- package/dist/gestures/createPanGesture.d.ts.map +1 -1
- package/dist/gestures/createPanGesture.js +66 -22
- package/dist/i18n/generated-english/Table/plugins/infiniteScroll/useTableInfiniteScroll.generated.d.ts +8 -0
- package/dist/i18n/generated-english/Table/plugins/infiniteScroll/useTableInfiniteScroll.generated.d.ts.map +1 -0
- package/dist/i18n/generated-english/Table/plugins/infiniteScroll/useTableInfiniteScroll.generated.js +12 -0
- package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/en.generated.js +2 -0
- package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/pseudo.generated.js +2 -0
- package/dist/motion/animator.d.ts +28 -1
- package/dist/motion/animator.d.ts.map +1 -1
- package/dist/motion/animator.js +99 -19
- package/dist/utils/timeParser.d.ts +3 -1
- package/dist/utils/timeParser.d.ts.map +1 -1
- package/dist/utils/timeParser.js +7 -3
- package/locales/en.json +8 -0
- package/locales/pseudo.json +6 -0
- package/package.json +4 -4
- package/src/BottomSheet/BottomSheet.tsx +12 -8
- package/src/Layer/layerAnimations.stylex.ts +13 -9
- package/src/Layer/layerEntranceSide.ts +31 -5
- package/src/List/ListItem.tsx +3 -2
- package/src/List/ListReorderHandle.tsx +59 -77
- package/src/List/listReorderContext.ts +3 -4
- package/src/List/listReorderEngine.tsx +246 -11
- package/src/Slider/Slider.tsx +6 -8
- package/src/Table/BaseTable.tsx +62 -3
- package/src/Table/index.ts +3 -0
- package/src/Table/plugins/infiniteScroll/index.ts +10 -0
- package/src/Table/plugins/infiniteScroll/useTableInfiniteScroll.tsx +523 -0
- package/src/Table/tableRuntime.ts +1 -1
- package/src/Table/types.ts +18 -0
- package/src/Table/useBaseTablePlugins.ts +2 -2
- package/src/Table/useTableInfiniteScroll.doc.mjs +58 -0
- package/src/TextArea/TextArea.doc.mjs +12 -0
- package/src/TextArea/TextArea.tsx +11 -0
- package/src/dragToSnapPoints/createDragToSnapPoints.ts +437 -119
- package/src/gestures/createPanGesture.ts +112 -39
- package/src/i18n/generated-english/Table/plugins/infiniteScroll/useTableInfiniteScroll.generated.ts +13 -0
- package/src/i18n/generated-locales/en.generated.ts +2 -0
- package/src/i18n/generated-locales/pseudo.generated.ts +2 -0
- package/src/motion/animator.ts +181 -23
- package/src/utils/timeParser.ts +7 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheet.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/BottomSheet.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAuBH,OAAO,EAQL,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"BottomSheet.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/BottomSheet.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAuBH,OAAO,EAQL,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAKf,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AA4DhD,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E,gBAAgB,+BA6BlD;yBA7Be,WAAW"}
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
// stack, but they replace each other. Each open modal sheet is an outlet for
|
|
51
51
|
// toasts (Layer/modalOutlet.ts), in stack order.
|
|
52
52
|
import { use, useCallback, useEffect, useInsertionEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
53
|
+
import { useCommittedRef } from "../hooks/useCommittedRef.js";
|
|
53
54
|
import { useIsHydrating } from "../hooks/useIsHydrating.js";
|
|
54
55
|
import { useSettledOpen } from "../hooks/useSettledOpen.js";
|
|
55
56
|
import * as stylex from '@stylexjs/stylex';
|
|
@@ -294,8 +295,9 @@ function StandaloneBottomSheet({
|
|
|
294
295
|
// sheet leaves the page interactive, so it returns focus to its opener
|
|
295
296
|
// only if the person was still in the sheet; a modal sheet always does.
|
|
296
297
|
const hadFocusAtCloseRef = useRef(false);
|
|
297
|
-
|
|
298
|
-
|
|
298
|
+
// The committed `finalFocusRef`. The stack reads it when it closes the
|
|
299
|
+
// sheet, which can happen in a layout effect.
|
|
300
|
+
const finalFocusRefRef = useCommittedRef(finalFocusRef);
|
|
299
301
|
// A sheet rendered in another sheet's content is presented only while that
|
|
300
302
|
// sheet is open: it leaves with its host and, if its own state is still
|
|
301
303
|
// open, comes back when the host does (see BottomSheetHostContext). Its
|
|
@@ -391,8 +393,9 @@ function StandaloneBottomSheet({
|
|
|
391
393
|
const handlePanelElementChange = useCallback(element => {
|
|
392
394
|
panelRef.current = element;
|
|
393
395
|
}, []);
|
|
396
|
+
// The stack's view for the handlers. The registry's `onView` writes it with
|
|
397
|
+
// each view it reports, together with the state.
|
|
394
398
|
const stackViewRef = useRef(stackView);
|
|
395
|
-
stackViewRef.current = stackView;
|
|
396
399
|
const scrimWriteRef = useRef({
|
|
397
400
|
frame: null
|
|
398
401
|
});
|
|
@@ -436,6 +439,8 @@ function StandaloneBottomSheet({
|
|
|
436
439
|
const repairOnRemoval = dialog == null ? null : prepareFocusRepairOnRemoval(dialog, {
|
|
437
440
|
keepRestingFocus: true
|
|
438
441
|
});
|
|
442
|
+
// Where focus returns when the sheet leaves, read when it leaves.
|
|
443
|
+
const getReturnTarget = () => finalFocusRefRef.current?.current ?? triggerRef.current;
|
|
439
444
|
const leave = registerBottomSheet({
|
|
440
445
|
key,
|
|
441
446
|
getElement: () => dialogRef.current,
|
|
@@ -456,7 +461,7 @@ function StandaloneBottomSheet({
|
|
|
456
461
|
},
|
|
457
462
|
hide: () => closeDialogKeepingFocus(dialogRef.current),
|
|
458
463
|
focus: reason => focusSheetPanel(panelRef.current, reason, hasScrim),
|
|
459
|
-
getReturnTarget
|
|
464
|
+
getReturnTarget,
|
|
460
465
|
onView: view => {
|
|
461
466
|
stackViewRef.current = view;
|
|
462
467
|
setStackView(view);
|
|
@@ -491,7 +496,7 @@ function StandaloneBottomSheet({
|
|
|
491
496
|
// person had already moved out of the sheet to the page body stays
|
|
492
497
|
// there: the removal did not lose it.
|
|
493
498
|
if (repairOnRemoval != null && isSheetHostPresented(dialog)) {
|
|
494
|
-
const returnTarget =
|
|
499
|
+
const returnTarget = getReturnTarget();
|
|
495
500
|
const revealed = hasScrim ? getBottomSheetBeneath(key) : null;
|
|
496
501
|
repairOnRemoval(() => {
|
|
497
502
|
// The sheet beneath left too. Its own repair returns focus for the
|
|
@@ -508,7 +513,7 @@ function StandaloneBottomSheet({
|
|
|
508
513
|
}
|
|
509
514
|
leave();
|
|
510
515
|
};
|
|
511
|
-
}, [hasScrim, shouldPresent, writeScrim]);
|
|
516
|
+
}, [finalFocusRefRef, hasScrim, shouldPresent, writeScrim]);
|
|
512
517
|
useLayoutEffect(() => {
|
|
513
518
|
if (!isOpen) {
|
|
514
519
|
// Where focus was when the person closed the sheet. The closing sheet
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layerAnimations.stylex.d.ts","sourceRoot":"","sources":["../../src/Layer/layerAnimations.stylex.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"layerAnimations.stylex.d.ts","sourceRoot":"","sources":["../../src/Layer/layerAnimations.stylex.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AA8F3C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuC1B,CAAC"}
|
|
@@ -41,24 +41,28 @@ import "../theme/tokens.stylex.js";
|
|
|
41
41
|
import { durationVars, easeVars, spacingVars } from "../theme/tokens.stylex.js";
|
|
42
42
|
|
|
43
43
|
// The layer runtime writes the side a shown anchored layer landed on. It
|
|
44
|
-
// writes a step toward the trigger on each axis (-1, 0 or 1)
|
|
45
|
-
//
|
|
46
|
-
// nothing is written.
|
|
44
|
+
// writes a step toward the trigger on each axis (-1, 0 or 1) and the scale's
|
|
45
|
+
// origin. It also writes the room to the trigger, which caps the step. Each
|
|
46
|
+
// fallback is the placement's own side, used when nothing is written.
|
|
47
47
|
const ENTER_X = '--_astryx-layer-enter-x';
|
|
48
48
|
const ENTER_Y = '--_astryx-layer-enter-y';
|
|
49
49
|
const ENTER_ORIGIN = '--_astryx-layer-enter-origin';
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
50
|
+
const ENTER_GAP = '--_astryx-layer-enter-gap';
|
|
51
|
+
// One step: the spacing token, or the room to the trigger when that is less.
|
|
52
|
+
// Without a written gap, the step is the token.
|
|
53
|
+
const STEP = `min(${spacingVars['--spacing-2']}, var(${ENTER_GAP}, ${spacingVars['--spacing-2']}))`;
|
|
54
|
+
const enterBelow = "x1fbltco-B";
|
|
55
|
+
const enterAbove = "xmqt0mh-B";
|
|
56
|
+
const enterEnd = "x1yqd01s-B";
|
|
57
|
+
const enterStart = "x12ghk8m-B";
|
|
54
58
|
|
|
55
59
|
// RTL: the horizontal fallback is a physical translateX, so it mirrors under
|
|
56
60
|
// RTL. A layer on the inline-end or inline-start side then slides in from
|
|
57
61
|
// the physical side that follows the reading flow. Only the horizontal
|
|
58
62
|
// fallbacks mirror; the vertical ones are direction-neutral. The side the
|
|
59
63
|
// runtime writes is physical already.
|
|
60
|
-
const enterEndRtl = "
|
|
61
|
-
const enterStartRtl = "
|
|
64
|
+
const enterEndRtl = "x12ghk8m-B";
|
|
65
|
+
const enterStartRtl = "x1yqd01s-B";
|
|
62
66
|
|
|
63
67
|
// Reduce Motion under a finger: the same entrance without its travel. A touch
|
|
64
68
|
// presentation substitutes a cross-fade for motion, never a jump.
|
|
@@ -95,7 +99,7 @@ const animationBase = {
|
|
|
95
99
|
*/
|
|
96
100
|
export const layerAnimations = {
|
|
97
101
|
below: {
|
|
98
|
-
kKVMdj: "
|
|
102
|
+
kKVMdj: "x1d5jn3a x2g3n7u xaqowwx",
|
|
99
103
|
k44tkh: "x9uej1z x10got5w",
|
|
100
104
|
kyAemX: "x128ha8g",
|
|
101
105
|
kWV6AL: "xskzprw",
|
|
@@ -103,7 +107,7 @@ export const layerAnimations = {
|
|
|
103
107
|
$$css: true
|
|
104
108
|
},
|
|
105
109
|
above: {
|
|
106
|
-
kKVMdj: "
|
|
110
|
+
kKVMdj: "xksu0ym x2g3n7u xaqowwx",
|
|
107
111
|
k44tkh: "x9uej1z x10got5w",
|
|
108
112
|
kyAemX: "x128ha8g",
|
|
109
113
|
kWV6AL: "xskzprw",
|
|
@@ -111,7 +115,7 @@ export const layerAnimations = {
|
|
|
111
115
|
$$css: true
|
|
112
116
|
},
|
|
113
117
|
end: {
|
|
114
|
-
kKVMdj: "
|
|
118
|
+
kKVMdj: "xyzx0um xixcm9l x2g3n7u xaqowwx",
|
|
115
119
|
k44tkh: "x9uej1z x10got5w",
|
|
116
120
|
kyAemX: "x128ha8g",
|
|
117
121
|
kWV6AL: "xskzprw",
|
|
@@ -119,7 +123,7 @@ export const layerAnimations = {
|
|
|
119
123
|
$$css: true
|
|
120
124
|
},
|
|
121
125
|
start: {
|
|
122
|
-
kKVMdj: "
|
|
126
|
+
kKVMdj: "x1qqotkc x1g7o29q x2g3n7u xaqowwx",
|
|
123
127
|
k44tkh: "x9uej1z x10got5w",
|
|
124
128
|
kyAemX: "x128ha8g",
|
|
125
129
|
kWV6AL: "xskzprw",
|
|
@@ -4,6 +4,8 @@ export declare const LAYER_ENTER_X_PROPERTY = "--_astryx-layer-enter-x";
|
|
|
4
4
|
export declare const LAYER_ENTER_Y_PROPERTY = "--_astryx-layer-enter-y";
|
|
5
5
|
/** The scale's origin, in px from the layer's top-left corner. */
|
|
6
6
|
export declare const LAYER_ENTER_ORIGIN_PROPERTY = "--_astryx-layer-enter-origin";
|
|
7
|
+
/** The room between the layer and its anchor: the longest step it takes. */
|
|
8
|
+
export declare const LAYER_ENTER_GAP_PROPERTY = "--_astryx-layer-enter-gap";
|
|
7
9
|
interface Box {
|
|
8
10
|
readonly left: number;
|
|
9
11
|
readonly top: number;
|
|
@@ -17,12 +19,16 @@ export interface LayerEntranceSide {
|
|
|
17
19
|
/** Where the layer meets its anchor, in px from the layer's top-left. */
|
|
18
20
|
readonly originX: number;
|
|
19
21
|
readonly originY: number;
|
|
22
|
+
/** The room between the layer and its anchor on the step's axis, in px. */
|
|
23
|
+
readonly gap: number;
|
|
20
24
|
}
|
|
21
25
|
/**
|
|
22
26
|
* The side that `layer` sits on against `anchor`, with the step toward the
|
|
23
27
|
* anchor. The origin is where the two meet: on the layer's edge that faces
|
|
24
|
-
* the anchor, on the anchor's center line. It stays on that edge. The
|
|
25
|
-
*
|
|
28
|
+
* the anchor, on the anchor's center line. It stays on that edge. The gap is
|
|
29
|
+
* the room between the two on the step's axis. The step never goes past it,
|
|
30
|
+
* so no frame of the entrance covers an anchor the layer sits clear of. The
|
|
31
|
+
* side is the axis on which the two centers are furthest apart, in half their
|
|
26
32
|
* joint size. A layer that overlaps its anchor by a few pixels (a submenu
|
|
27
33
|
* against its row) thus still has a side. A layer over its anchor's center
|
|
28
34
|
* (a list over its selected item) has no side. It does not move, and it
|
|
@@ -37,8 +43,10 @@ export declare function layerEntranceSide(layer: Box, anchor: Box): LayerEntranc
|
|
|
37
43
|
export declare function readLayerEntranceSide(layer: HTMLElement, anchor: Element): LayerEntranceSide | null;
|
|
38
44
|
/**
|
|
39
45
|
* Gives the layer's entrance the side the layer landed on after any flip.
|
|
40
|
-
* The entrance then slides from that side,
|
|
41
|
-
* the layer meets its anchor.
|
|
46
|
+
* The entrance then slides from that side, no further than the gap, and
|
|
47
|
+
* scales about the point where the layer meets its anchor. A layer against
|
|
48
|
+
* its anchor, as a menu at the pointer, has no gap and keeps the whole step.
|
|
49
|
+
* It only writes, so it can follow a pass that
|
|
42
50
|
* read the boxes. `null` sets the properties to `initial`. The entrance then
|
|
43
51
|
* keeps its placement's side, and a layer inside never inherits the values.
|
|
44
52
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layerEntranceSide.d.ts","sourceRoot":"","sources":["../../src/Layer/layerEntranceSide.ts"],"names":[],"mappings":"AAkBA,mEAAmE;AACnE,eAAO,MAAM,sBAAsB,4BAA4B,CAAC;AAChE,8DAA8D;AAC9D,eAAO,MAAM,sBAAsB,4BAA4B,CAAC;AAChE,kEAAkE;AAClE,eAAO,MAAM,2BAA2B,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"layerEntranceSide.d.ts","sourceRoot":"","sources":["../../src/Layer/layerEntranceSide.ts"],"names":[],"mappings":"AAkBA,mEAAmE;AACnE,eAAO,MAAM,sBAAsB,4BAA4B,CAAC;AAChE,8DAA8D;AAC9D,eAAO,MAAM,sBAAsB,4BAA4B,CAAC;AAChE,kEAAkE;AAClE,eAAO,MAAM,2BAA2B,iCAAiC,CAAC;AAC1E,4EAA4E;AAC5E,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AAEpE,UAAU,GAAG;IACX,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,yEAAyE;IACzE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,2EAA2E;IAC3E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,GAAG,EACV,MAAM,EAAE,GAAG,GACV,iBAAiB,GAAG,IAAI,CAkD1B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,OAAO,GACd,iBAAiB,GAAG,IAAI,CAG1B;AAID;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,iBAAiB,GAAG,IAAI,GAC7B,IAAI,CAmBN"}
|
|
@@ -22,13 +22,17 @@ export const LAYER_ENTER_X_PROPERTY = '--_astryx-layer-enter-x';
|
|
|
22
22
|
export const LAYER_ENTER_Y_PROPERTY = '--_astryx-layer-enter-y';
|
|
23
23
|
/** The scale's origin, in px from the layer's top-left corner. */
|
|
24
24
|
export const LAYER_ENTER_ORIGIN_PROPERTY = '--_astryx-layer-enter-origin';
|
|
25
|
+
/** The room between the layer and its anchor: the longest step it takes. */
|
|
26
|
+
export const LAYER_ENTER_GAP_PROPERTY = '--_astryx-layer-enter-gap';
|
|
25
27
|
const clamp = (value, max) => Math.min(max, Math.max(0, value));
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* The side that `layer` sits on against `anchor`, with the step toward the
|
|
29
31
|
* anchor. The origin is where the two meet: on the layer's edge that faces
|
|
30
|
-
* the anchor, on the anchor's center line. It stays on that edge. The
|
|
31
|
-
*
|
|
32
|
+
* the anchor, on the anchor's center line. It stays on that edge. The gap is
|
|
33
|
+
* the room between the two on the step's axis. The step never goes past it,
|
|
34
|
+
* so no frame of the entrance covers an anchor the layer sits clear of. The
|
|
35
|
+
* side is the axis on which the two centers are furthest apart, in half their
|
|
32
36
|
* joint size. A layer that overlaps its anchor by a few pixels (a submenu
|
|
33
37
|
* against its row) thus still has a side. A layer over its anchor's center
|
|
34
38
|
* (a list over its selected item) has no side. It does not move, and it
|
|
@@ -48,7 +52,8 @@ export function layerEntranceSide(layer, anchor) {
|
|
|
48
52
|
x: 0,
|
|
49
53
|
y: 0,
|
|
50
54
|
originX,
|
|
51
|
-
originY
|
|
55
|
+
originY,
|
|
56
|
+
gap: 0
|
|
52
57
|
};
|
|
53
58
|
}
|
|
54
59
|
const apartX = (layer.left + layer.width / 2 - anchorX) / ((layer.width + anchor.width) / 2);
|
|
@@ -59,7 +64,8 @@ export function layerEntranceSide(layer, anchor) {
|
|
|
59
64
|
x: 0,
|
|
60
65
|
y: below ? -1 : 1,
|
|
61
66
|
originX,
|
|
62
|
-
originY: below ? 0 : layer.height
|
|
67
|
+
originY: below ? 0 : layer.height,
|
|
68
|
+
gap: Math.max(0, below ? layer.top - (anchor.top + anchor.height) : anchor.top - (layer.top + layer.height))
|
|
63
69
|
};
|
|
64
70
|
}
|
|
65
71
|
const right = apartX > 0;
|
|
@@ -67,7 +73,8 @@ export function layerEntranceSide(layer, anchor) {
|
|
|
67
73
|
x: right ? -1 : 1,
|
|
68
74
|
y: 0,
|
|
69
75
|
originX: right ? 0 : layer.width,
|
|
70
|
-
originY
|
|
76
|
+
originY,
|
|
77
|
+
gap: Math.max(0, right ? layer.left - (anchor.left + anchor.width) : anchor.left - (layer.left + layer.width))
|
|
71
78
|
};
|
|
72
79
|
}
|
|
73
80
|
|
|
@@ -84,8 +91,10 @@ const px = value => `${Math.round(value * 1000) / 1000}px`;
|
|
|
84
91
|
|
|
85
92
|
/**
|
|
86
93
|
* Gives the layer's entrance the side the layer landed on after any flip.
|
|
87
|
-
* The entrance then slides from that side,
|
|
88
|
-
* the layer meets its anchor.
|
|
94
|
+
* The entrance then slides from that side, no further than the gap, and
|
|
95
|
+
* scales about the point where the layer meets its anchor. A layer against
|
|
96
|
+
* its anchor, as a menu at the pointer, has no gap and keeps the whole step.
|
|
97
|
+
* It only writes, so it can follow a pass that
|
|
89
98
|
* read the boxes. `null` sets the properties to `initial`. The entrance then
|
|
90
99
|
* keeps its placement's side, and a layer inside never inherits the values.
|
|
91
100
|
*/
|
|
@@ -93,4 +102,7 @@ export function writeLayerEntranceSide(layer, side) {
|
|
|
93
102
|
layer.style.setProperty(LAYER_ENTER_X_PROPERTY, side == null ? 'initial' : String(side.x));
|
|
94
103
|
layer.style.setProperty(LAYER_ENTER_Y_PROPERTY, side == null ? 'initial' : String(side.y));
|
|
95
104
|
layer.style.setProperty(LAYER_ENTER_ORIGIN_PROPERTY, side == null ? 'initial' : `${px(side.originX)} ${px(side.originY)}`);
|
|
105
|
+
// Floored, so rounding never carries the step past the anchor's edge.
|
|
106
|
+
const gap = side == null ? 0 : Math.floor(side.gap * 1000) / 1000;
|
|
107
|
+
layer.style.setProperty(LAYER_ENTER_GAP_PROPERTY, gap > 0 ? `${gap}px` : 'initial');
|
|
96
108
|
}
|
package/dist/List/ListItem.d.ts
CHANGED
|
@@ -61,12 +61,13 @@ export interface ListItemProps extends BaseProps<HTMLLIElement> {
|
|
|
61
61
|
*/
|
|
62
62
|
description?: ReactNode;
|
|
63
63
|
/**
|
|
64
|
-
* Content
|
|
64
|
+
* Content before the label, inside the row (icon, avatar, checkbox).
|
|
65
65
|
* Uses start/end naming for RTL support.
|
|
66
66
|
*/
|
|
67
67
|
startContent?: ReactNode;
|
|
68
68
|
/**
|
|
69
|
-
* Content
|
|
69
|
+
* Content after the label and description, inside the row (badge, action
|
|
70
|
+
* button, chevron).
|
|
70
71
|
*/
|
|
71
72
|
endContent?: ReactNode;
|
|
72
73
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListItem.d.ts","sourceRoot":"","sources":["../../src/List/ListItem.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAuB,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAS3D,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAU5C,OAAO,KAAK,EAAC,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAa5E,MAAM,WAAW,aAAc,SAAQ,SAAS,CAAC,aAAa,CAAC;IAC7D,wCAAwC;IACxC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC/B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;;;;;OAMG;IACH,KAAK,EAAE,SAAS,CAAC;IAEjB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,SAAS,CAAC;IAExB;;;OAGG;IACH,YAAY,CAAC,EAAE,SAAS,CAAC;IAEzB
|
|
1
|
+
{"version":3,"file":"ListItem.d.ts","sourceRoot":"","sources":["../../src/List/ListItem.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAuB,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAS3D,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAU5C,OAAO,KAAK,EAAC,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAC,MAAM,SAAS,CAAC;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S,EACT,KAAK,EACL,GAAG,EACH,GAAG,SAAS,EACb,EAAE,aAAa,+BA8Mf;yBAjOe,QAAQ"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as stylex from '@stylexjs/stylex';
|
|
2
2
|
import type { ListReorderHandleProps, ListReorderRowNameProps } from './listReorderContext.js';
|
|
3
|
+
import type { ListReorderHandleName } from './listReorderEngine.js';
|
|
3
4
|
/**
|
|
4
5
|
* The style of a row that ends with a handle, which ListItem applies. Its
|
|
5
6
|
* ring on focus within stays off for the handle, which rings itself.
|
|
@@ -47,6 +48,12 @@ export declare function ListReorderHandle({ label, itemKey, isDisabled, rowLabel
|
|
|
47
48
|
export declare namespace ListReorderHandle {
|
|
48
49
|
var displayName: string;
|
|
49
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* A handle's name before the session reads it: its server snapshot, and the
|
|
53
|
+
* session's answer for a handle it has not read. One object keeps the
|
|
54
|
+
* snapshot through hydration and the first read.
|
|
55
|
+
*/
|
|
56
|
+
export declare const UNREAD_HANDLE_NAME: ListReorderHandleName;
|
|
50
57
|
/**
|
|
51
58
|
* Names a reorderable List's row that has no handle, for the announcements
|
|
52
59
|
* of the moves beside it. That is a row that stays, or one without an item
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListReorderHandle.d.ts","sourceRoot":"","sources":["../../src/List/ListReorderHandle.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ListReorderHandle.d.ts","sourceRoot":"","sources":["../../src/List/ListReorderHandle.tsx"],"names":[],"mappings":"AA2CA,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAoB3C,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAEV,qBAAqB,EACtB,MAAM,qBAAqB,CAAC;AA+G7B;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;EAAqC,CAAC;AAElE,2EAA2E;AAC3E,eAAO,MAAM,wBAAwB,IAAI,CAAC;AA6B1C,6EAA6E;AAC7E,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;KAA4C,CAAC;AAW1E;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,OAAO,EACP,UAAkB,EAClB,QAAQ,EACR,aAAa,EACb,QAAQ,GACT,EAAE,sBAAsB,sCAuJxB;yBA9Je,iBAAiB;;;AAoKjC;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,qBAGhC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,EAAC,GAAG,EAAE,KAAK,EAAC,EAAE,uBAAuB,QAUvE;yBAVe,kBAAkB"}
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
* @file ListReorderHandle.tsx
|
|
7
7
|
* @input The List's reorder session (List/listReorderEngine.tsx, through
|
|
8
8
|
* ListContext's `reorder`), the translator and theme tokens
|
|
9
|
-
* @output `ListReorderHandle`, `ListReorderRowName` and
|
|
10
|
-
* The handle ends a reorderable List row. A finger
|
|
11
|
-
* it, and so does a pen where the primary pointer is
|
|
12
|
-
* pen where it is fine, drags it at once. It is also a
|
|
13
|
-
* (`aria-pressed`): a click, Space or Enter turns its row's reorder
|
|
14
|
-
* and off. The row name serves a row without one, and the style a
|
|
15
|
-
* has one
|
|
9
|
+
* @output `ListReorderHandle`, `ListReorderRowName`, `reorderRowStyle` and
|
|
10
|
+
* `UNREAD_HANDLE_NAME`. The handle ends a reorderable List row. A finger
|
|
11
|
+
* held still on it drags it, and so does a pen where the primary pointer is
|
|
12
|
+
* coarse. A mouse, or a pen where it is fine, drags it at once. It is also a
|
|
13
|
+
* toggle (`aria-pressed`): a click, Space or Enter turns its row's reorder
|
|
14
|
+
* mode on and off. The row name serves a row without one, and the style a
|
|
15
|
+
* row that has one
|
|
16
16
|
* @position Part of the reorder machinery that createReorderable carries.
|
|
17
17
|
* ListItem renders it, from the List's context, at the end of each row
|
|
18
18
|
* that can move
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* SYNC: When modified, update List/listReorderEngine.tsx and
|
|
32
32
|
* List/ListItem.tsx.
|
|
33
33
|
*/
|
|
34
|
-
import { use,
|
|
34
|
+
import { use, useRef, useSyncExternalStore, useId } from 'react';
|
|
35
35
|
import { useIsomorphicLayoutEffect } from "../hooks/useIsomorphicLayoutEffect.js";
|
|
36
36
|
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
37
37
|
import * as stylex from '@stylexjs/stylex';
|
|
@@ -46,7 +46,6 @@ import { useTouchHitArea } from "../utils/touchHitArea.js";
|
|
|
46
46
|
import { touchHitAreaStyles } from "../internal/touchHitArea.stylex.js";
|
|
47
47
|
import { registerEnglishFallback, useComponentTranslator } from "../i18n/useComponentTranslator.js";
|
|
48
48
|
import english from "../i18n/generated-english/List/ListReorderHandle.generated.js";
|
|
49
|
-
import { createDevWarnings } from "../utils/devWarning.js";
|
|
50
49
|
import { getNodeText } from "../utils/getNodeText.js";
|
|
51
50
|
import { ItemLabelContext } from "../Item/ItemLabelContext.js";
|
|
52
51
|
import { ListContext } from "./ListContext.js";
|
|
@@ -147,17 +146,6 @@ function labelTextOf(handle, labelID) {
|
|
|
147
146
|
return (element?.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
148
147
|
}
|
|
149
148
|
|
|
150
|
-
/**
|
|
151
|
-
* Whether the row's label element names it: it shows text, or holds an icon
|
|
152
|
-
* or image with an accessible name of its own.
|
|
153
|
-
*/
|
|
154
|
-
function namesRow(element) {
|
|
155
|
-
if (element == null) {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
return (element.textContent ?? '').trim() !== '' || element.querySelector('[aria-label]:not([aria-label=""]), [aria-labelledby], img[alt]:not([alt=""])') != null;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
149
|
/**
|
|
162
150
|
* The reorder handle of a List row. Renders nothing outside a reorderable
|
|
163
151
|
* List.
|
|
@@ -186,7 +174,9 @@ export function ListReorderHandle({
|
|
|
186
174
|
const labelledBy = callerLabel != null ? undefined : rowLabelledBy ?? labelID ?? undefined;
|
|
187
175
|
const named = callerLabel != null || labelledBy != null || text !== '';
|
|
188
176
|
const verb = t('@astryx.list.reorderHandleVerb');
|
|
189
|
-
|
|
177
|
+
// Named by Item's label element only while it shows a name: a label of an
|
|
178
|
+
// unnamed icon alone falls back to the place.
|
|
179
|
+
const byLabel = labelID != null && labelledBy === labelID;
|
|
190
180
|
// Syncs the handle into the reorder session, which lives outside React. The
|
|
191
181
|
// session moves the row only with its handle recorded, and reports its
|
|
192
182
|
// moves with the row's key.
|
|
@@ -194,10 +184,19 @@ export function ListReorderHandle({
|
|
|
194
184
|
// Syncs the row's name into the session, which announces the moves with
|
|
195
185
|
// it. A new name keeps the handle recorded, so its row stays in reorder
|
|
196
186
|
// mode. A component label's text is read from its element, rendered by now.
|
|
187
|
+
// The session also reads, from the DOM, whether the label element names the
|
|
188
|
+
// row and where the row sits, for the handle's name.
|
|
197
189
|
useIsomorphicLayoutEffect(() => {
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
190
|
+
const handle = ref.current;
|
|
191
|
+
const spoken = callerLabel ?? (text !== '' ? text : labelTextOf(handle, labelID ?? null));
|
|
192
|
+
const unname = controller?.registerName(handle, spoken);
|
|
193
|
+
const unlabel = controller?.registerHandleLabel(handle, byLabel ? labelID ?? null : null, named);
|
|
194
|
+
return () => {
|
|
195
|
+
unname?.();
|
|
196
|
+
unlabel?.();
|
|
197
|
+
};
|
|
198
|
+
}, [controller, callerLabel, text, labelID, byLabel, named]);
|
|
199
|
+
const shown = useSyncExternalStore(controller?.subscribeHandleNames ?? subscribeNothing, () => controller?.handleNameOf(ref.current) ?? UNREAD_HANDLE_NAME, () => UNREAD_HANDLE_NAME);
|
|
201
200
|
const isPressed = useSyncExternalStore(controller?.subscribeMode ?? subscribeNothing, () => controller?.isInMode(ref.current) ?? false, () => false);
|
|
202
201
|
const isEnabled = controller != null && !isDisabled;
|
|
203
202
|
// A finger's target: the shared touch hit area grows the handle's hit
|
|
@@ -214,51 +213,26 @@ export function ListReorderHandle({
|
|
|
214
213
|
}
|
|
215
214
|
return () => controller.release(handle);
|
|
216
215
|
}, [controller, isEnabled]);
|
|
217
|
-
// That place is read from the DOM after each commit (the row does not
|
|
218
|
-
// know its index). A passive effect: the list's own ref is attached after
|
|
219
|
-
// its rows' layout effects run.
|
|
220
|
-
useEffect(() => {
|
|
221
|
-
const handle = ref.current;
|
|
222
|
-
if (handle == null) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
// Named by Item's label element only while it shows a name: a label of
|
|
226
|
-
// an unnamed icon alone falls back to the place.
|
|
227
|
-
if (labelID != null && labelledBy === labelID) {
|
|
228
|
-
if (namesRow(handle.ownerDocument.getElementById(labelID))) {
|
|
229
|
-
handle.setAttribute('aria-labelledby', `${verbID} ${labelID}`);
|
|
230
|
-
handle.setAttribute('aria-label', verb);
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
handle.removeAttribute('aria-labelledby');
|
|
234
|
-
} else if (named) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
const position = controller?.positionOf(handle) ?? null;
|
|
238
|
-
if (position == null) {
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
// Named after its place only: a person hears "Reorder item 3" with
|
|
242
|
-
// nothing to tell the rows apart. Development says so, once a handle.
|
|
243
|
-
warn('ListItem', 'A reorderable row has no accessible name, so its reorder handle is ' + 'named after its place ("Reorder item N"). Give the row a text ' + 'label or an aria-label.');
|
|
244
|
-
handle.setAttribute('aria-label', t('@astryx.list.reorderHandleAt', {
|
|
245
|
-
position
|
|
246
|
-
}));
|
|
247
|
-
});
|
|
248
216
|
if (controller == null) {
|
|
249
217
|
return null;
|
|
250
218
|
}
|
|
219
|
+
// A label element that shows no name falls back to the row's place.
|
|
220
|
+
const labelShowsName = byLabel && !shown.labelShowsNoName;
|
|
221
|
+
const byPlace = byLabel ? !labelShowsName : !named;
|
|
222
|
+
const shownLabelledBy = byLabel && !labelShowsName ? undefined : labelledBy;
|
|
251
223
|
// Named through the label element. The handle's own `aria-label` is the
|
|
252
224
|
// verb. It lists itself first in its `aria-labelledby`, which reads its
|
|
253
225
|
// `aria-label` there: "Reorder", then the row's label.
|
|
254
|
-
const name =
|
|
226
|
+
const name = byPlace && shown.position != null ? t('@astryx.list.reorderHandleAt', {
|
|
227
|
+
position: shown.position
|
|
228
|
+
}) : callerLabel != null ? t('@astryx.list.reorderHandle', {
|
|
255
229
|
label: callerLabel
|
|
256
230
|
}) : labelledBy != null ? verb : text !== '' ? t('@astryx.list.reorderHandle', {
|
|
257
231
|
label: text
|
|
258
232
|
}) : undefined;
|
|
259
233
|
return /*#__PURE__*/_jsx("button", {
|
|
260
234
|
ref: handleRef,
|
|
261
|
-
id:
|
|
235
|
+
id: shownLabelledBy == null ? undefined : verbID,
|
|
262
236
|
type: "button",
|
|
263
237
|
...listReorderHandleProps,
|
|
264
238
|
// The handle takes its own press, so the row does not highlight under
|
|
@@ -268,7 +242,7 @@ export function ListReorderHandle({
|
|
|
268
242
|
,
|
|
269
243
|
...ownRingProps,
|
|
270
244
|
"aria-label": name,
|
|
271
|
-
"aria-labelledby":
|
|
245
|
+
"aria-labelledby": shownLabelledBy == null ? undefined : `${verbID} ${shownLabelledBy}`,
|
|
272
246
|
"aria-describedby": controller.hintId,
|
|
273
247
|
"aria-disabled": isDisabled || undefined,
|
|
274
248
|
"aria-pressed": isPressed
|
|
@@ -307,6 +281,16 @@ export function ListReorderHandle({
|
|
|
307
281
|
ListReorderHandle.displayName = 'ListReorderHandle';
|
|
308
282
|
const subscribeNothing = () => () => {};
|
|
309
283
|
|
|
284
|
+
/**
|
|
285
|
+
* A handle's name before the session reads it: its server snapshot, and the
|
|
286
|
+
* session's answer for a handle it has not read. One object keeps the
|
|
287
|
+
* snapshot through hydration and the first read.
|
|
288
|
+
*/
|
|
289
|
+
export const UNREAD_HANDLE_NAME = {
|
|
290
|
+
position: null,
|
|
291
|
+
labelShowsNoName: false
|
|
292
|
+
};
|
|
293
|
+
|
|
310
294
|
/**
|
|
311
295
|
* Names a reorderable List's row that has no handle, for the announcements
|
|
312
296
|
* of the moves beside it. That is a row that stays, or one without an item
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listReorderContext.d.ts","sourceRoot":"","sources":["../../src/List/listReorderContext.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,
|
|
1
|
+
{"version":3,"file":"listReorderContext.d.ts","sourceRoot":"","sources":["../../src/List/listReorderContext.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,GAAG,EACR,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAIf,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,kCAAkC,CAAC;AAClE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAC;AAE1D;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAsC,CAAC;AAElE,8EAA8E;AAC9E,MAAM,WAAW,kBAAkB;IACjC,6EAA6E;IAC7E,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE;QAAC,GAAG,EAAE,GAAG,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAC,KAAK,IAAI,CAAC;IAC3D,qEAAqE;IACrE,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC;IAC/C;;;;OAIG;IACH,QAAQ,CAAC,SAAS,C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
21
|
* reorderable/createReorderable.ts.
|
|
22
22
|
*/
|
|
23
|
-
import { useMemo
|
|
23
|
+
import { useMemo } from 'react';
|
|
24
|
+
import { useCommittedRef } from "../hooks/useCommittedRef.js";
|
|
24
25
|
import { useIsomorphicLayoutEffect } from "../hooks/useIsomorphicLayoutEffect.js";
|
|
25
26
|
import { sharedKey } from "../utils/sharedRealm.js";
|
|
26
27
|
/**
|
|
@@ -61,9 +62,8 @@ export const REORDER_ENGINE = sharedKey('list/reorder-engine', 1);
|
|
|
61
62
|
export function useReorderSession(reorderable, getList, hintId) {
|
|
62
63
|
const reorder = reorderable;
|
|
63
64
|
const engine = reorder?.[REORDER_ENGINE];
|
|
64
|
-
const getListRef =
|
|
65
|
-
getListRef.current
|
|
66
|
-
const session = useMemo(() => engine?.createSession(() => getListRef.current(), hintId) ?? null, [engine, hintId]);
|
|
65
|
+
const getListRef = useCommittedRef(getList);
|
|
66
|
+
const session = useMemo(() => engine?.createSession(() => getListRef.current(), hintId) ?? null, [engine, hintId, getListRef]);
|
|
67
67
|
return {
|
|
68
68
|
session,
|
|
69
69
|
options: reorder?.options ?? null
|
|
@@ -71,6 +71,16 @@ import type { ListReorderContextValue, ListReorderEngine, ListReorderOptions, Li
|
|
|
71
71
|
* (DateInput/usePointerDragScroll.ts `DRAG_SLOP`); a test keeps them equal.
|
|
72
72
|
*/
|
|
73
73
|
export declare const MOUSE_DRAG_SLOP = 4;
|
|
74
|
+
/**
|
|
75
|
+
* What names a handle besides its own text, as the list last showed it. Its
|
|
76
|
+
* row's 1-based place among the list's rows, null until the session reads
|
|
77
|
+
* it. And whether Item's label element shows no name: an unread label counts
|
|
78
|
+
* as one that shows a name, so a first read that finds a name changes nothing.
|
|
79
|
+
*/
|
|
80
|
+
export interface ListReorderHandleName {
|
|
81
|
+
readonly position: number | null;
|
|
82
|
+
readonly labelShowsNoName: boolean;
|
|
83
|
+
}
|
|
74
84
|
/** The strings the controller announces, from the translator. */
|
|
75
85
|
interface ReorderMessages {
|
|
76
86
|
/**
|
|
@@ -155,6 +165,23 @@ export declare class ListReorderController implements ListReorderSession {
|
|
|
155
165
|
* text) and each handle-less row's own.
|
|
156
166
|
*/
|
|
157
167
|
private readonly names;
|
|
168
|
+
/**
|
|
169
|
+
* For each handle: the id of Item's label element, when that element names
|
|
170
|
+
* the row. Also whether the handle is named some other way.
|
|
171
|
+
*/
|
|
172
|
+
private readonly handleLabels;
|
|
173
|
+
/** Each handle's place and label naming, as the list last showed them. */
|
|
174
|
+
private readonly handleNames;
|
|
175
|
+
private readonly nameListeners;
|
|
176
|
+
/**
|
|
177
|
+
* The list's rows and the label elements, watched through Core's shared
|
|
178
|
+
* mutation observer while the list is up, with each registration's release.
|
|
179
|
+
*/
|
|
180
|
+
private namesWatch;
|
|
181
|
+
private namesQueued;
|
|
182
|
+
/** The handles already warned for being named after their place. */
|
|
183
|
+
private readonly warnedNameless;
|
|
184
|
+
private namelessCount;
|
|
158
185
|
/** The handle whose row is in reorder mode, if any. */
|
|
159
186
|
private modeHandle;
|
|
160
187
|
private readonly modeListeners;
|
|
@@ -215,6 +242,29 @@ export declare class ListReorderController implements ListReorderSession {
|
|
|
215
242
|
registerHandle(handle: Element | null, key: Key): () => void;
|
|
216
243
|
/** Records the name of a row, or of its handle; returns the removal. */
|
|
217
244
|
registerName(row: Element | null, name: string): () => void;
|
|
245
|
+
/**
|
|
246
|
+
* Records how `handle` is named besides its place: by Item's label element
|
|
247
|
+
* `labelId`, or otherwise (`isNamed`). Returns the removal.
|
|
248
|
+
*/
|
|
249
|
+
registerHandleLabel(handle: Element | null, labelId: string | null, isNamed: boolean): () => void;
|
|
250
|
+
/** `handle`'s place and label naming, as the list last showed them. */
|
|
251
|
+
handleNameOf(handle: Element | null): ListReorderHandleName;
|
|
252
|
+
/** Calls `listener` when a handle's place or label naming changes. */
|
|
253
|
+
subscribeHandleNames: (listener: () => void) => (() => void);
|
|
254
|
+
/**
|
|
255
|
+
* Watches the list's rows and the handles' label elements through Core's
|
|
256
|
+
* shared mutation observer. A row's place, and whether its label names it,
|
|
257
|
+
* come from the DOM. Returns the release.
|
|
258
|
+
*/
|
|
259
|
+
attachNames(): () => void;
|
|
260
|
+
private readonly onNamesMutation;
|
|
261
|
+
/** Reads the names once the current commit is done, for every handle. */
|
|
262
|
+
private queueNames;
|
|
263
|
+
/**
|
|
264
|
+
* Reads each handle's place and label naming from the DOM. Only a change
|
|
265
|
+
* reaches the handles. A handle named after its place warns, once.
|
|
266
|
+
*/
|
|
267
|
+
private refreshNames;
|
|
218
268
|
/** What the announcements call the row at `index`. */
|
|
219
269
|
private nameOf;
|
|
220
270
|
/** Whether `handle`'s row is in reorder mode: its `aria-pressed`. */
|
|
@@ -370,8 +420,6 @@ export declare class ListReorderController implements ListReorderSession {
|
|
|
370
420
|
* whatever its tag. Null outside the list.
|
|
371
421
|
*/
|
|
372
422
|
rowOf(element: Element | null): HTMLElement | null;
|
|
373
|
-
/** The 1-based place of the row that holds `element`, or null. */
|
|
374
|
-
positionOf(element: Element | null): number | null;
|
|
375
423
|
/**
|
|
376
424
|
* A handle's key in reorder mode: the arrows move its
|
|
377
425
|
* row a place at once, and Escape ends the mode, keeping the moves. Space
|