@astryxdesign/core 0.7.7-canary.fc68123 → 0.7.7
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/CHANGELOG.md +104 -0
- package/dist/AlertDialog/AlertDialog.d.ts +1 -4
- package/dist/AlertDialog/AlertDialog.d.ts.map +1 -1
- package/dist/AlertDialog/AlertDialog.js +6 -36
- package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheetPanel.js +4 -23
- package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
- package/dist/BottomSheet/useSheetGestures.js +1 -3
- package/dist/Button/Button.d.ts.map +1 -1
- package/dist/Button/Button.js +1 -17
- package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
- package/dist/CheckboxInput/CheckboxInput.js +2 -13
- package/dist/ComplexSelector/ComplexSelector.d.ts +1 -4
- package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
- package/dist/ComplexSelector/ComplexSelector.js +4 -14
- package/dist/ContextMenu/ContextMenu.js +2 -2
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +31 -7
- package/dist/Field/Field.js +2 -2
- package/dist/HoverCard/HoverCard.d.ts +3 -4
- package/dist/HoverCard/HoverCard.d.ts.map +1 -1
- package/dist/HoverCard/HoverCard.js +2 -27
- package/dist/HoverCard/useHoverCard.d.ts +4 -5
- package/dist/HoverCard/useHoverCard.d.ts.map +1 -1
- package/dist/HoverCard/useHoverCard.js +31 -17
- package/dist/Icon/Icon.d.ts +1 -5
- package/dist/Icon/Icon.d.ts.map +1 -1
- package/dist/Icon/Icon.js +2 -5
- package/dist/Layer/usePressPin.d.ts +5 -17
- package/dist/Layer/usePressPin.d.ts.map +1 -1
- package/dist/Layer/usePressPin.js +12 -62
- package/dist/Lightbox/Lightbox.d.ts.map +1 -1
- package/dist/Lightbox/Lightbox.js +0 -18
- package/dist/PowerSearch/PowerSearch.d.ts +3 -36
- package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearch.js +127 -433
- package/dist/PowerSearch/PowerSearchEditPopover.d.ts +1 -32
- package/dist/PowerSearch/PowerSearchEditPopover.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchEditPopover.js +6 -17
- package/dist/PowerSearch/PowerSearchValueEditor.d.ts +3 -38
- package/dist/PowerSearch/PowerSearchValueEditor.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchValueEditor.js +61 -170
- package/dist/PowerSearch/formatFilterValue.d.ts +0 -7
- package/dist/PowerSearch/formatFilterValue.d.ts.map +1 -1
- package/dist/PowerSearch/formatFilterValue.js +1 -11
- package/dist/RadioList/RadioList.d.ts.map +1 -1
- package/dist/RadioList/RadioList.js +2 -3
- package/dist/RadioList/RadioListItem.d.ts +1 -1
- package/dist/RadioList/RadioListItem.d.ts.map +1 -1
- package/dist/RadioList/RadioListItem.js +3 -5
- package/dist/Resizable/ResizeHandle.d.ts +1 -2
- package/dist/Resizable/ResizeHandle.d.ts.map +1 -1
- package/dist/Resizable/ResizeHandle.js +77 -99
- package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts.map +1 -1
- package/dist/SegmentedControl/useSegmentedSelectionMotion.js +3 -3
- package/dist/Slider/sliderTouchController.js +2 -2
- package/dist/Spinner/Spinner.d.ts +1 -1
- package/dist/Spinner/Spinner.d.ts.map +1 -1
- package/dist/Spinner/Spinner.js +58 -60
- package/dist/Switch/useSwitchTouch.js +4 -4
- package/dist/Table/BaseTable.d.ts.map +1 -1
- package/dist/Table/BaseTable.js +8 -29
- package/dist/TextInput/TextInput.d.ts +2 -2
- package/dist/TextInput/TextInput.d.ts.map +1 -1
- package/dist/TextInput/TextInput.js +7 -10
- package/dist/Toast/Toast.d.ts +1 -11
- package/dist/Toast/Toast.d.ts.map +1 -1
- package/dist/Toast/Toast.js +15 -25
- package/dist/Toast/ToastViewport.d.ts.map +1 -1
- package/dist/Toast/ToastViewport.js +34 -94
- package/dist/Toast/types.d.ts +3 -9
- package/dist/Toast/types.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.d.ts +1 -19
- package/dist/Tooltip/useTooltip.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.js +53 -34
- package/dist/Typeahead/TypeaheadItem.d.ts +1 -2
- package/dist/Typeahead/TypeaheadItem.d.ts.map +1 -1
- package/dist/astryx.css +6 -35
- package/dist/gestures/PressTracker.d.ts.map +1 -1
- package/dist/gestures/PressTracker.js +3 -4
- package/dist/hooks/actionGroupTracker.d.ts +1 -4
- package/dist/hooks/actionGroupTracker.d.ts.map +1 -1
- package/dist/hooks/actionGroupTracker.js +3 -13
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +0 -1
- package/dist/hooks/useAttachment.d.ts +1 -1
- package/dist/hooks/useAttachment.js +1 -1
- package/dist/hooks/useInputStatusIcon.d.ts +1 -1
- package/dist/hooks/useInputStatusIcon.d.ts.map +1 -1
- package/dist/hooks/useInputStatusIcon.js +2 -2
- package/dist/hooks/useLongPress.d.ts +2 -6
- package/dist/hooks/useLongPress.d.ts.map +1 -1
- package/dist/hooks/useLongPress.js +15 -95
- package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.d.ts.map +1 -1
- package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.js +0 -6
- package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/en.generated.js +0 -30
- package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/pseudo.generated.js +0 -30
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/motion/animatedLayout.d.ts.map +1 -1
- package/dist/motion/animatedLayout.js +6 -5
- package/dist/motion/animator.d.ts +14 -14
- package/dist/motion/animator.d.ts.map +1 -1
- package/dist/motion/animator.js +18 -41
- package/dist/utils/dateParser.d.ts.map +1 -1
- package/dist/utils/dateParser.js +0 -12
- package/dist/utils/focusReturn.d.ts +0 -15
- package/dist/utils/focusReturn.d.ts.map +1 -1
- package/dist/utils/focusReturn.js +0 -28
- package/dist/utils/interactionOverlay.stylex.d.ts +2 -3
- package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
- package/dist/utils/interactionOverlay.stylex.js +2 -3
- package/dist/utils/pressFeedback.d.ts.map +1 -1
- package/dist/utils/pressFeedback.js +6 -19
- package/locales/en.json +0 -120
- package/locales/pseudo.json +0 -90
- package/package.json +5 -10
- package/src/AlertDialog/AlertDialog.doc.mjs +2 -2
- package/src/AlertDialog/AlertDialog.tsx +5 -37
- package/src/BottomSheet/BottomSheetPanel.tsx +3 -37
- package/src/BottomSheet/useSheetGestures.ts +1 -3
- package/src/Button/Button.tsx +4 -26
- package/src/CheckboxInput/CheckboxInput.doc.mjs +0 -18
- package/src/CheckboxInput/CheckboxInput.tsx +9 -36
- package/src/ComplexSelector/ComplexSelector.tsx +5 -20
- package/src/ContextMenu/ContextMenu.tsx +2 -2
- package/src/Dialog/Dialog.tsx +31 -10
- package/src/Field/Field.tsx +2 -2
- package/src/HoverCard/HoverCard.doc.mjs +2 -4
- package/src/HoverCard/HoverCard.tsx +4 -35
- package/src/HoverCard/useHoverCard.doc.mjs +36 -178
- package/src/HoverCard/useHoverCard.tsx +52 -46
- package/src/Icon/Icon.doc.mjs +8 -49
- package/src/Icon/Icon.tsx +7 -15
- package/src/Layer/usePressPin.ts +15 -81
- package/src/Lightbox/Lightbox.tsx +0 -18
- package/src/PowerSearch/PowerSearch.doc.mjs +5 -54
- package/src/PowerSearch/PowerSearch.tsx +155 -609
- package/src/PowerSearch/PowerSearchEditPopover.tsx +6 -28
- package/src/PowerSearch/PowerSearchValueEditor.tsx +38 -203
- package/src/PowerSearch/formatFilterValue.ts +1 -18
- package/src/RadioList/RadioList.tsx +2 -3
- package/src/RadioList/RadioListItem.tsx +3 -5
- package/src/Resizable/Resizable.doc.mjs +4 -5
- package/src/Resizable/ResizeHandle.tsx +109 -167
- package/src/SegmentedControl/useSegmentedSelectionMotion.ts +3 -6
- package/src/Slider/sliderTouchController.ts +2 -2
- package/src/Spinner/Spinner.tsx +63 -77
- package/src/Switch/useSwitchTouch.ts +4 -4
- package/src/Table/BaseTable.tsx +12 -46
- package/src/TextInput/TextInput.tsx +10 -11
- package/src/Toast/Toast.doc.mjs +3 -4
- package/src/Toast/Toast.tsx +32 -52
- package/src/Toast/ToastViewport.tsx +35 -121
- package/src/Toast/types.ts +3 -9
- package/src/Tooltip/useTooltip.doc.mjs +0 -24
- package/src/Tooltip/useTooltip.tsx +56 -61
- package/src/Typeahead/TypeaheadItem.doc.mjs +3 -6
- package/src/Typeahead/TypeaheadItem.tsx +1 -2
- package/src/gestures/PressTracker.ts +3 -4
- package/src/gestures/README.md +1 -7
- package/src/hooks/actionGroupTracker.ts +5 -20
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useAttachment.ts +1 -1
- package/src/hooks/useInputStatusIcon.tsx +2 -3
- package/src/hooks/useLongPress.doc.mjs +2 -2
- package/src/hooks/useLongPress.ts +15 -136
- package/src/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.ts +0 -6
- package/src/i18n/generated-locales/en.generated.ts +0 -41
- package/src/i18n/generated-locales/pseudo.generated.ts +0 -42
- package/src/index.ts +0 -13
- package/src/motion/README.md +5 -9
- package/src/motion/animatedLayout.ts +4 -5
- package/src/motion/animator.ts +29 -61
- package/src/utils/dateParser.ts +0 -16
- package/src/utils/focusReturn.ts +0 -30
- package/src/utils/interactionOverlay.stylex.ts +2 -3
- package/src/utils/pressFeedback.ts +6 -19
- package/dist/PowerSearch/PowerSearchBottomSheet.d.ts +0 -100
- package/dist/PowerSearch/PowerSearchBottomSheet.d.ts.map +0 -1
- package/dist/PowerSearch/PowerSearchBottomSheet.js +0 -1913
- package/dist/PowerSearch/formatTokenValue.d.ts +0 -28
- package/dist/PowerSearch/formatTokenValue.d.ts.map +0 -1
- package/dist/PowerSearch/formatTokenValue.js +0 -160
- package/dist/PowerSearch/powerSearchSheetUtils.d.ts +0 -65
- package/dist/PowerSearch/powerSearchSheetUtils.d.ts.map +0 -1
- package/dist/PowerSearch/powerSearchSheetUtils.js +0 -168
- package/dist/animator/createAnimator.d.ts +0 -98
- package/dist/animator/createAnimator.d.ts.map +0 -1
- package/dist/animator/createAnimator.js +0 -259
- package/dist/hooks/pressGroupContext.d.ts +0 -6
- package/dist/hooks/pressGroupContext.d.ts.map +0 -1
- package/dist/hooks/pressGroupContext.js +0 -20
- package/dist/hooks/useActionGroupTracking.d.ts +0 -53
- package/dist/hooks/useActionGroupTracking.d.ts.map +0 -1
- package/dist/hooks/useActionGroupTracking.js +0 -174
- package/dist/hooks/useAnimator.d.ts +0 -41
- package/dist/hooks/useAnimator.d.ts.map +0 -1
- package/dist/hooks/useAnimator.js +0 -70
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts +0 -8
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts.map +0 -1
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.js +0 -42
- package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts +0 -8
- package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts.map +0 -1
- package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.js +0 -14
- package/dist/internal/indicatorPress.stylex.d.ts +0 -20
- package/dist/internal/indicatorPress.stylex.d.ts.map +0 -1
- package/dist/internal/indicatorPress.stylex.js +0 -26
- package/dist/motion/progress.d.ts +0 -88
- package/dist/motion/progress.d.ts.map +0 -1
- package/dist/motion/progress.js +0 -128
- package/dist/motion/uikit/alert.d.ts +0 -41
- package/dist/motion/uikit/alert.d.ts.map +0 -1
- package/dist/motion/uikit/alert.js +0 -43
- package/dist/privateAttributes/pressGroupItem.stylex.d.ts +0 -15
- package/dist/privateAttributes/pressGroupItem.stylex.d.ts.map +0 -1
- package/dist/privateAttributes/pressGroupItem.stylex.js +0 -23
- package/dist/utils/triggerFocus.d.ts +0 -36
- package/dist/utils/triggerFocus.d.ts.map +0 -1
- package/dist/utils/triggerFocus.js +0 -65
- package/src/PowerSearch/PowerSearchBottomSheet.tsx +0 -2515
- package/src/PowerSearch/formatTokenValue.ts +0 -215
- package/src/PowerSearch/powerSearchSheetUtils.ts +0 -224
- package/src/animator/createAnimator.doc.mjs +0 -153
- package/src/animator/createAnimator.ts +0 -324
- package/src/hooks/pressGroupContext.ts +0 -21
- package/src/hooks/useActionGroupTracking.ts +0 -224
- package/src/hooks/useAnimator.doc.mjs +0 -109
- package/src/hooks/useAnimator.ts +0 -67
- package/src/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.ts +0 -43
- package/src/i18n/generated-english/PowerSearch/formatTokenValue.generated.ts +0 -15
- package/src/internal/indicatorPress.stylex.ts +0 -24
- package/src/motion/progress.ts +0 -155
- package/src/motion/uikit/alert.ts +0 -43
- package/src/privateAttributes/pressGroupItem.stylex.ts +0 -23
- package/src/utils/triggerFocus.ts +0 -80
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
'use client';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @file createAnimator.ts
|
|
7
|
-
* @input An element; the internal motion animator (motion/animator.ts), the
|
|
8
|
-
* `springs.stateChange` motion role and the momentum coast (motion/coast.ts)
|
|
9
|
-
* @output The public animator: `createAnimator`, the `AnimatorHandle` it
|
|
10
|
-
* returns, and their value types
|
|
11
|
-
* @position Public entry point, re-exported from the package root. The
|
|
12
|
-
* `useAnimator` hook wraps it. Importing it does no DOM work.
|
|
13
|
-
*
|
|
14
|
-
* SYNC: When modified, update:
|
|
15
|
-
* - /packages/core/src/animator/createAnimator.test.ts
|
|
16
|
-
* - /packages/core/src/animator/createAnimator.doc.mjs
|
|
17
|
-
* - /packages/core/src/hooks/useAnimator.ts
|
|
18
|
-
*/
|
|
19
|
-
import { createMotionAnimator, SETTLE_THRESHOLD } from "../motion/animator.js";
|
|
20
|
-
import { coast } from "../motion/coast.js";
|
|
21
|
-
import { solveDecay } from "../motion/decay.js";
|
|
22
|
-
import { registerSpringsTable, springs } from "../motion/uikit/springs.js";
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A channel the animator drives. `x` and `y` translate the element (px).
|
|
26
|
-
* `scale` scales it about its transform origin (1 is its size). `rotate`
|
|
27
|
-
* turns it (degrees, clockwise), and `opacity` fades it (0 to 1).
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Values by channel. A velocity uses the same keys, in units per second:
|
|
32
|
-
* px/s, scale per second, deg/s, opacity per second.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
/** Every channel's value (or velocity), as `get` and `getVelocity` read it. */
|
|
36
|
-
|
|
37
|
-
/** Options of `AnimatorHandle.animate`. */
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* A release velocity for `AnimatorHandle.decay`, per channel, in its units
|
|
41
|
-
* per second. That is px/s for `x` and `y`, and degrees per second for
|
|
42
|
-
* `rotate`. `scale` and `opacity` take their units per second.
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Animates one element. Each method acts on the channels it is given and
|
|
47
|
-
* leaves the others where they are.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
/** What `createAnimator` returns: the handle, and `destroy`. */
|
|
51
|
-
|
|
52
|
-
const CHANNELS = ['x', 'y', 'scale', 'rotate', 'opacity'];
|
|
53
|
-
|
|
54
|
-
/** The values of the channels the public API names, and nothing else. */
|
|
55
|
-
function motionValues(values) {
|
|
56
|
-
const out = {};
|
|
57
|
-
if (values == null) {
|
|
58
|
-
return out;
|
|
59
|
-
}
|
|
60
|
-
for (const channel of CHANNELS) {
|
|
61
|
-
const value = values[channel];
|
|
62
|
-
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
63
|
-
out[channel] = value;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return out;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* A coast from `from` at `velocity` on the momentum decay a scroll view
|
|
71
|
-
* uses, ending at rest. The theme does not change this decay. An opacity
|
|
72
|
-
* coast stops at 0 or 1.
|
|
73
|
-
*/
|
|
74
|
-
function momentum(from, velocity, threshold, isUnit) {
|
|
75
|
-
const glide = solveDecay({
|
|
76
|
-
from,
|
|
77
|
-
velocity
|
|
78
|
-
});
|
|
79
|
-
const edge = !isUnit ? null : glide.rest < 0 ? 0 : glide.rest > 1 ? 1 : null;
|
|
80
|
-
const hit = edge == null ? null : glide.timeToReach(edge);
|
|
81
|
-
const duration = hit ?? glide.settleTime(threshold);
|
|
82
|
-
const end = edge ?? glide.rest;
|
|
83
|
-
return {
|
|
84
|
-
duration,
|
|
85
|
-
at: t => t >= duration ? end : glide.value(t),
|
|
86
|
-
velocity: t => t >= duration ? 0 : glide.velocity(t)
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function snapshot(read) {
|
|
90
|
-
return {
|
|
91
|
-
x: read('x'),
|
|
92
|
-
y: read('y'),
|
|
93
|
-
scale: read('scale'),
|
|
94
|
-
rotate: read('rotate'),
|
|
95
|
-
opacity: read('opacity')
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Resolves once every motion of one call has finished, or as soon as any of
|
|
101
|
-
* them is interrupted (`finished` resolves `false`). A later call that takes
|
|
102
|
-
* over one channel ends the whole call where it stopped, as one `animate`
|
|
103
|
-
* does. The other channels move on.
|
|
104
|
-
*/
|
|
105
|
-
async function settledOrTakenOver(moving) {
|
|
106
|
-
if (moving.length === 0) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
await new Promise(resolve => {
|
|
110
|
-
let left = moving.length;
|
|
111
|
-
for (const finished of moving) {
|
|
112
|
-
void finished.then(completed => {
|
|
113
|
-
left -= 1;
|
|
114
|
-
if (!completed || left === 0) {
|
|
115
|
-
resolve();
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* An animator whose element is attached later, through `attach`. It is the
|
|
124
|
-
* one construction `createAnimator` and `useAnimator` share, so the hook has
|
|
125
|
-
* no behavior of its own. Not exported from the package.
|
|
126
|
-
*/
|
|
127
|
-
export function createAttachableAnimator() {
|
|
128
|
-
const motion = createMotionAnimator(null);
|
|
129
|
-
// Calls do nothing while no element is attached, before the ref attaches
|
|
130
|
-
// or after it lets go. They also do nothing after destroy, and animate and
|
|
131
|
-
// decay then resolve at once.
|
|
132
|
-
let element = null;
|
|
133
|
-
let destroyed = false;
|
|
134
|
-
const inactive = () => destroyed || element == null;
|
|
135
|
-
const animator = {
|
|
136
|
-
async animate(target, options) {
|
|
137
|
-
const to = motionValues(target);
|
|
138
|
-
if (inactive() || Object.keys(to).length === 0) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
// The role registry is written on first use, never on import.
|
|
142
|
-
registerSpringsTable();
|
|
143
|
-
const velocity = motionValues(options?.velocity);
|
|
144
|
-
await motion.animate(to, {
|
|
145
|
-
spring: springs.stateChange,
|
|
146
|
-
...(Object.keys(velocity).length > 0 ? {
|
|
147
|
-
velocity
|
|
148
|
-
} : {})
|
|
149
|
-
}).finished;
|
|
150
|
-
},
|
|
151
|
-
async decay(velocity) {
|
|
152
|
-
if (inactive()) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const given = motionValues(velocity);
|
|
156
|
-
// The translate axes coast as a throw, which Reduce Motion lets
|
|
157
|
-
// continue. The others coast as a transition, which it replaces.
|
|
158
|
-
const translate = coast(motion, {
|
|
159
|
-
x: given.x,
|
|
160
|
-
y: given.y
|
|
161
|
-
});
|
|
162
|
-
const others = {};
|
|
163
|
-
for (const channel of ['scale', 'rotate', 'opacity']) {
|
|
164
|
-
const v0 = given[channel];
|
|
165
|
-
if (v0 != null) {
|
|
166
|
-
const property = channel === 'scale' ? 'scaleX' : channel;
|
|
167
|
-
others[channel] = momentum(motion.get(property), v0, SETTLE_THRESHOLD[property], channel === 'opacity');
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
const moving = [];
|
|
171
|
-
if (Object.keys(translate).length > 0) {
|
|
172
|
-
moving.push(motion.decay(translate).finished);
|
|
173
|
-
}
|
|
174
|
-
if (Object.keys(others).length > 0) {
|
|
175
|
-
moving.push(motion.play(others).finished);
|
|
176
|
-
}
|
|
177
|
-
await settledOrTakenOver(moving);
|
|
178
|
-
},
|
|
179
|
-
set(values) {
|
|
180
|
-
if (!inactive()) {
|
|
181
|
-
motion.set(motionValues(values));
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
get() {
|
|
185
|
-
return snapshot(channel => motion.get(channel));
|
|
186
|
-
},
|
|
187
|
-
getVelocity() {
|
|
188
|
-
return snapshot(channel => motion.getVelocity(channel));
|
|
189
|
-
},
|
|
190
|
-
stop() {
|
|
191
|
-
if (!inactive()) {
|
|
192
|
-
motion.stop();
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
destroy() {
|
|
196
|
-
if (!destroyed) {
|
|
197
|
-
destroyed = true;
|
|
198
|
-
// Halts every channel where it shows, so the element keeps those
|
|
199
|
-
// values and nothing reads as moving, then lets go of it.
|
|
200
|
-
motion.stop();
|
|
201
|
-
motion.dispose();
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
return {
|
|
206
|
-
animator,
|
|
207
|
-
attach: next => {
|
|
208
|
-
if (destroyed || next === element) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
if (element != null) {
|
|
212
|
-
// The old node takes its values with it, so the next node, or a
|
|
213
|
-
// remount, starts at rest.
|
|
214
|
-
motion.attach(null);
|
|
215
|
-
motion.stop();
|
|
216
|
-
motion.set(motionValues(REST));
|
|
217
|
-
}
|
|
218
|
-
element = next;
|
|
219
|
-
motion.attach(next);
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/** A new or remounted element starts from these values. */
|
|
225
|
-
const REST = {
|
|
226
|
-
x: 0,
|
|
227
|
-
y: 0,
|
|
228
|
-
scale: 1,
|
|
229
|
-
rotate: 0,
|
|
230
|
-
opacity: 1
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Animates `element` with the motion Core uses. `animate` springs channels to
|
|
235
|
-
* a target on the state-change motion, and `decay` coasts them from a release
|
|
236
|
-
* velocity. `set` jumps them, `get` and `getVelocity` read them, `stop` halts
|
|
237
|
-
* them, and `destroy` lets the element go. Under Reduce Motion every call is
|
|
238
|
-
* planned. A move becomes a short cross-fade on a touch screen, and it lands
|
|
239
|
-
* at once with a mouse.
|
|
240
|
-
*
|
|
241
|
-
* Use one animator per element: two on one element overwrite each other.
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* ```
|
|
245
|
-
* const card = document.querySelector('.card');
|
|
246
|
-
* const animator = createAnimator(card);
|
|
247
|
-
* await animator.animate({x: 0, rotate: 0}, {velocity: {x: -900}});
|
|
248
|
-
* animator.decay({x: 2400});
|
|
249
|
-
* animator.destroy();
|
|
250
|
-
* ```
|
|
251
|
-
*/
|
|
252
|
-
export function createAnimator(element) {
|
|
253
|
-
const {
|
|
254
|
-
animator,
|
|
255
|
-
attach
|
|
256
|
-
} = createAttachableAnimator();
|
|
257
|
-
attach(element);
|
|
258
|
-
return animator;
|
|
259
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* True inside a group whose tracker paints a pointer's press on its actions.
|
|
3
|
-
* Those actions take no `:active` paint, so one press never lights two.
|
|
4
|
-
*/
|
|
5
|
-
export declare const PressGroupContext: import("react").Context<boolean>;
|
|
6
|
-
//# sourceMappingURL=pressGroupContext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pressGroupContext.d.ts","sourceRoot":"","sources":["../../src/hooks/pressGroupContext.ts"],"names":[],"mappings":"AAeA;;;GAGG;AACH,eAAO,MAAM,iBAAiB,kCAAuB,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
'use client';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @file pressGroupContext.ts
|
|
7
|
-
* @input Nothing
|
|
8
|
-
* @output PressGroupContext: true inside a group whose own tracker paints
|
|
9
|
-
* its actions' press
|
|
10
|
-
* @position Internal; not exported from the hooks entry. AlertDialog
|
|
11
|
-
* provides it around its tracked actions, and Button reads it.
|
|
12
|
-
*/
|
|
13
|
-
import { createContext } from 'react';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* True inside a group whose tracker paints a pointer's press on its actions.
|
|
17
|
-
* Those actions take no `:active` paint, so one press never lights two.
|
|
18
|
-
*/
|
|
19
|
-
export const PressGroupContext = /*#__PURE__*/createContext(false);
|
|
20
|
-
PressGroupContext.displayName = 'PressGroupContext';
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file useActionGroupTracking.ts
|
|
3
|
-
* @input A ref to a group of sibling actions, the actions' selector, and the
|
|
4
|
-
* component's tracking constants
|
|
5
|
-
* @output Exports useActionGroupTracking and ActionGroupTrackingOptions
|
|
6
|
-
* @position Internal hook, not exported from the hooks entry. A long press
|
|
7
|
-
* drives the shared action-group tracker (hooks/actionGroupTracker.ts) for
|
|
8
|
-
* a group that a held pointer slides across. AlertDialog consumes it.
|
|
9
|
-
*
|
|
10
|
-
* SYNC: When modified, update useActionGroupTracking.test.tsx
|
|
11
|
-
*/
|
|
12
|
-
import { type RefObject } from 'react';
|
|
13
|
-
import { LongPressGestureRecognizer } from '../gestures/LongPressGestureRecognizer.js';
|
|
14
|
-
import type { GestureTouch, PointerKind } from '../gestures/types.js';
|
|
15
|
-
export interface ActionGroupTrackingOptions {
|
|
16
|
-
/** Selects the actions inside the tracked element. */
|
|
17
|
-
itemSelector: string;
|
|
18
|
-
/** How long after touch-down the touched action highlights, ms. */
|
|
19
|
-
highlightOnsetMs: number;
|
|
20
|
-
/**
|
|
21
|
-
* How far outside an action a finger keeps it highlighted, px. A mouse or a
|
|
22
|
-
* pen hit-tests the actions' exact rects.
|
|
23
|
-
*/
|
|
24
|
-
highlightExpansion: number;
|
|
25
|
-
/** Pointers that are tracked; others keep the browser's click. @default every pointer */
|
|
26
|
-
pointerTypes?: ReadonlyArray<PointerKind>;
|
|
27
|
-
/** A press whose target this rejects is not tracked. */
|
|
28
|
-
shouldTrack?: (target: unknown) => boolean;
|
|
29
|
-
/** Off, nothing is attached and nothing is tracked. @default true */
|
|
30
|
-
isEnabled?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Let the gesture host write the group's `touch-action` and refuse a text
|
|
33
|
-
* selection while a finger or a pen holds it.
|
|
34
|
-
* @default true
|
|
35
|
-
*/
|
|
36
|
-
manageStyle?: boolean;
|
|
37
|
-
/** Runs the action under the finger at the lift. @default its own click */
|
|
38
|
-
onActivate?: (item: HTMLElement) => void;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The group's press: a long press that a second finger on the group ends with
|
|
42
|
-
* nothing acting. A plain long press ignores a second finger.
|
|
43
|
-
*/
|
|
44
|
-
declare class ActionGroupPress extends LongPressGestureRecognizer {
|
|
45
|
-
protected acceptsTouch(touch: GestureTouch): boolean;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Track a held pointer on the group behind `ref` across the actions inside
|
|
49
|
-
* it, through the shared action-group tracker.
|
|
50
|
-
*/
|
|
51
|
-
export declare function useActionGroupTracking(ref: RefObject<HTMLElement | null>, options: ActionGroupTrackingOptions): ActionGroupPress;
|
|
52
|
-
export {};
|
|
53
|
-
//# sourceMappingURL=useActionGroupTracking.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useActionGroupTracking.d.ts","sourceRoot":"","sources":["../../src/hooks/useActionGroupTracking.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AAEH,OAAO,EAA8B,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAElE,OAAO,EAAC,0BAA0B,EAAC,MAAM,wCAAwC,CAAC;AAElF,OAAO,KAAK,EAAC,YAAY,EAAE,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAOjE,MAAM,WAAW,0BAA0B;IACzC,sDAAsD;IACtD,YAAY,EAAE,MAAM,CAAC;IACrB,mEAAmE;IACnE,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B,yFAAyF;IACzF,YAAY,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAC1C,wDAAwD;IACxD,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC;IAC3C,qEAAqE;IACrE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;CAC1C;AASD;;;GAGG;AACH,cAAM,gBAAiB,SAAQ,0BAA0B;cACpC,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO;CAO9D;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAClC,OAAO,EAAE,0BAA0B,GAClC,gBAAgB,CAoHlB"}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
'use client';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @file useActionGroupTracking.ts
|
|
7
|
-
* @input A ref to a group of sibling actions, the actions' selector, and the
|
|
8
|
-
* component's tracking constants
|
|
9
|
-
* @output Exports useActionGroupTracking and ActionGroupTrackingOptions
|
|
10
|
-
* @position Internal hook, not exported from the hooks entry. A long press
|
|
11
|
-
* drives the shared action-group tracker (hooks/actionGroupTracker.ts) for
|
|
12
|
-
* a group that a held pointer slides across. AlertDialog consumes it.
|
|
13
|
-
*
|
|
14
|
-
* SYNC: When modified, update useActionGroupTracking.test.tsx
|
|
15
|
-
*/
|
|
16
|
-
import { useEffect, useRef, useState } from 'react';
|
|
17
|
-
import { isActive } from "../gestures/GestureRecognizer.js";
|
|
18
|
-
import { LongPressGestureRecognizer } from "../gestures/LongPressGestureRecognizer.js";
|
|
19
|
-
import { lockSelection } from "../utils/selectionLock.js";
|
|
20
|
-
import { useGestureRecognizer } from "../gestures/useGestureRecognizer.js";
|
|
21
|
-
import { UIKIT_PRESS } from "../motion/uikit/gestures.js";
|
|
22
|
-
import { isIosWebKit } from "../utils/touchQueries.js";
|
|
23
|
-
import { createActionGroupTracker } from "./actionGroupTracker.js";
|
|
24
|
-
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
|
|
25
|
-
const PRESS = UIKIT_PRESS;
|
|
26
|
-
|
|
27
|
-
/** The ref handed to the recognizer while tracking is off: no element. */
|
|
28
|
-
const DETACHED = {
|
|
29
|
-
current: null
|
|
30
|
-
};
|
|
31
|
-
const EVERY_POINTER = ['touch', 'pen', 'mouse'];
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The group's press: a long press that a second finger on the group ends with
|
|
35
|
-
* nothing acting. A plain long press ignores a second finger.
|
|
36
|
-
*/
|
|
37
|
-
class ActionGroupPress extends LongPressGestureRecognizer {
|
|
38
|
-
acceptsTouch(touch) {
|
|
39
|
-
if (isActive(this.state)) {
|
|
40
|
-
this.setState('cancelled');
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
return super.acceptsTouch(touch);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Track a held pointer on the group behind `ref` across the actions inside
|
|
49
|
-
* it, through the shared action-group tracker.
|
|
50
|
-
*/
|
|
51
|
-
export function useActionGroupTracking(ref, options) {
|
|
52
|
-
const optionsRef = useRef(options);
|
|
53
|
-
// Keeps the recognizer's delegate and the tracker, which run outside
|
|
54
|
-
// render, reading the latest options.
|
|
55
|
-
useIsomorphicLayoutEffect(() => {
|
|
56
|
-
optionsRef.current = options;
|
|
57
|
-
});
|
|
58
|
-
// The pointer that started the current press. Only a finger gets the hit
|
|
59
|
-
// expansion; a mouse or a pen hit-tests the actions' exact rects.
|
|
60
|
-
const pointerRef = useRef('touch');
|
|
61
|
-
const landedRef = useRef(null);
|
|
62
|
-
const [tracker] = useState(() => createActionGroupTracker(() => ({
|
|
63
|
-
roots: () => [ref.current],
|
|
64
|
-
itemSelector: optionsRef.current.itemSelector,
|
|
65
|
-
highlightExpansion: pointerRef.current === 'touch' ? optionsRef.current.highlightExpansion : 0,
|
|
66
|
-
onActivate: optionsRef.current.onActivate,
|
|
67
|
-
// The browser's own click for a press the group ran is taken, so the
|
|
68
|
-
// action runs once. The gesture host swallows it for a press it claims.
|
|
69
|
-
// This covers one it does not claim, a mouse under a coarse pointer.
|
|
70
|
-
swallowsNativeClick: true
|
|
71
|
-
})));
|
|
72
|
-
const isEnabled = options.isEnabled ?? true;
|
|
73
|
-
// Synchronizes the tracker with tracking on and mounted. Turning tracking
|
|
74
|
-
// off, or unmounting, drops a tracked press and ends its release fades.
|
|
75
|
-
// The host reports no cancellation to a disabled recognizer, and the lift
|
|
76
|
-
// that runs an action often closes the owner before its fade ends.
|
|
77
|
-
useEffect(() => () => {
|
|
78
|
-
tracker.cancel();
|
|
79
|
-
tracker.dispose();
|
|
80
|
-
}, [tracker, isEnabled]);
|
|
81
|
-
return useGestureRecognizer(isEnabled ? ref : DETACHED, () => new ActionGroupPress({
|
|
82
|
-
name: 'ActionGroupTracking',
|
|
83
|
-
minimumPressDuration: options.highlightOnsetMs,
|
|
84
|
-
allowableMovement: Number.POSITIVE_INFINITY,
|
|
85
|
-
allowedPointerTypes: options.pointerTypes ?? EVERY_POINTER,
|
|
86
|
-
delaysTouchesBegan: true,
|
|
87
|
-
// The hold picks an action, so a held finger or pen starts no text
|
|
88
|
-
// selection and opens no callout while down. A long press brings this
|
|
89
|
-
// lock by default; this hold has no minimum duration, so it names it.
|
|
90
|
-
selectionLock: lockSelection,
|
|
91
|
-
shouldReceiveTouch: (recognizer, touch) => {
|
|
92
|
-
if (recognizer.numberOfTouches === 0) {
|
|
93
|
-
pointerRef.current = touch.pointerType;
|
|
94
|
-
const target = touch.target;
|
|
95
|
-
landedRef.current = typeof target?.nodeType === 'number' ? target : null;
|
|
96
|
-
}
|
|
97
|
-
return receiveTouch(recognizer, touch, optionsRef.current);
|
|
98
|
-
}
|
|
99
|
-
}), recognizer => {
|
|
100
|
-
switch (recognizer.state) {
|
|
101
|
-
case 'began':
|
|
102
|
-
{
|
|
103
|
-
const {
|
|
104
|
-
x,
|
|
105
|
-
y
|
|
106
|
-
} = recognizer.location();
|
|
107
|
-
tracker.begin(x, y, {
|
|
108
|
-
landed: landedRef.current
|
|
109
|
-
});
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
case 'changed':
|
|
113
|
-
{
|
|
114
|
-
const {
|
|
115
|
-
x,
|
|
116
|
-
y
|
|
117
|
-
} = recognizer.location();
|
|
118
|
-
tracker.move(x, y);
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
case 'ended':
|
|
122
|
-
{
|
|
123
|
-
const doc = ref.current?.ownerDocument;
|
|
124
|
-
const focusedBefore = doc?.activeElement ?? null;
|
|
125
|
-
const beganOn = tracker.beganOn;
|
|
126
|
-
// Whether a click on the lifted action would focus it. A mouse's or
|
|
127
|
-
// a pen's pointerdown already gave the engine's answer, on the action
|
|
128
|
-
// it began on. A tap focuses on a later mousedown, which the claimed
|
|
129
|
-
// touch cancels, so the platform answers for a finger.
|
|
130
|
-
// iOS WebKit focuses no tapped button; Chromium and Firefox do.
|
|
131
|
-
const clickFocuses = pointerRef.current === 'touch' ? !isIosWebKit(doc?.defaultView) : beganOn != null && focusedBefore === beganOn;
|
|
132
|
-
const lifted = tracker.end();
|
|
133
|
-
// The lift runs the action's own click(), which moves no focus. So
|
|
134
|
-
// focus moves to the lifted action, unless its click moved focus.
|
|
135
|
-
if (clickFocuses && lifted != null && lifted.isConnected && doc?.activeElement === focusedBefore && focusedBefore !== lifted) {
|
|
136
|
-
lifted.focus({
|
|
137
|
-
preventScroll: true,
|
|
138
|
-
focusVisible: false
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
case 'cancelled':
|
|
144
|
-
tracker.cancel();
|
|
145
|
-
break;
|
|
146
|
-
case 'possible':
|
|
147
|
-
case 'failed':
|
|
148
|
-
// Listeners are not called for these.
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
}, {
|
|
152
|
-
isEnabled,
|
|
153
|
-
manageStyle: options.manageStyle ?? true,
|
|
154
|
-
actionGroup: true
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* The recognizer's should-receive delegate. It also picks the press's clock.
|
|
160
|
-
* Inside a scroller the press waits the content-touch delay and fails past
|
|
161
|
-
* the slop, so the scroller takes a flick. Elsewhere it begins at once, with
|
|
162
|
-
* no movement limit.
|
|
163
|
-
*/
|
|
164
|
-
function receiveTouch(recognizer, touch, options) {
|
|
165
|
-
if (options.shouldTrack?.(touch.target) === false) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
if (recognizer.numberOfTouches === 0) {
|
|
169
|
-
const isInsideScroller = touch.scroll?.isInsideScroller === true;
|
|
170
|
-
recognizer.minimumPressDuration = isInsideScroller ? PRESS.contentTouchDelay.value : options.highlightOnsetMs;
|
|
171
|
-
recognizer.allowableMovement = isInsideScroller ? PRESS.slop.value : Number.POSITIVE_INFINITY;
|
|
172
|
-
}
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file useAnimator.ts
|
|
3
|
-
* @input React (useState), the element ref the caller owns, the public
|
|
4
|
-
* animator factory (animator/createAnimator.ts) and useAttachment
|
|
5
|
-
* @output Exports `useAnimator(ref)`: the public animator for the element
|
|
6
|
-
* behind `ref`
|
|
7
|
-
* @position Public hook, exported from `@astryxdesign/core/hooks`. A thin
|
|
8
|
-
* wrapper over `createAnimator` with no behavior of its own.
|
|
9
|
-
*
|
|
10
|
-
* SYNC: When modified, update:
|
|
11
|
-
* - /packages/core/src/hooks/useAnimator.test.tsx
|
|
12
|
-
* - /packages/core/src/hooks/useAnimator.doc.mjs
|
|
13
|
-
*/
|
|
14
|
-
import { type RefObject } from 'react';
|
|
15
|
-
import { type AnimatorHandle } from '../animator/createAnimator.js';
|
|
16
|
-
/**
|
|
17
|
-
* Animates the element behind `ref` with the motion Core uses. Call
|
|
18
|
-
* `animate`, `decay`, `set`, `get`, `getVelocity` or `stop` on the returned
|
|
19
|
-
* animator from event handlers and effects. Pass the same `ref` to a gesture
|
|
20
|
-
* hook to drag and animate one element.
|
|
21
|
-
*
|
|
22
|
-
* The hook makes the animator once, and animating never re-renders the
|
|
23
|
-
* component. After each commit, the animator follows the element behind
|
|
24
|
-
* `ref`, also a node that replaces it. An unmount stops running motion and
|
|
25
|
-
* drops the values. A remount, or a node that replaces the element, starts
|
|
26
|
-
* at rest. While no element is attached, every call does nothing, and
|
|
27
|
-
* `animate` and `decay` resolve at once.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```
|
|
31
|
-
* const ref = useRef<HTMLDivElement>(null);
|
|
32
|
-
* const animator = useAnimator(ref);
|
|
33
|
-
* return (
|
|
34
|
-
* <div ref={ref} onClick={() => animator.animate({scale: 1.2})}>
|
|
35
|
-
* Card
|
|
36
|
-
* </div>
|
|
37
|
-
* );
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export declare function useAnimator(ref: RefObject<HTMLElement | null>): AnimatorHandle;
|
|
41
|
-
//# sourceMappingURL=useAnimator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAnimator.d.ts","sourceRoot":"","sources":["../../src/hooks/useAnimator.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAW,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAC/C,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,4BAA4B,CAAC;AAGpC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GACjC,cAAc,CAehB"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
'use client';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @file useAnimator.ts
|
|
7
|
-
* @input React (useState), the element ref the caller owns, the public
|
|
8
|
-
* animator factory (animator/createAnimator.ts) and useAttachment
|
|
9
|
-
* @output Exports `useAnimator(ref)`: the public animator for the element
|
|
10
|
-
* behind `ref`
|
|
11
|
-
* @position Public hook, exported from `@astryxdesign/core/hooks`. A thin
|
|
12
|
-
* wrapper over `createAnimator` with no behavior of its own.
|
|
13
|
-
*
|
|
14
|
-
* SYNC: When modified, update:
|
|
15
|
-
* - /packages/core/src/hooks/useAnimator.test.tsx
|
|
16
|
-
* - /packages/core/src/hooks/useAnimator.doc.mjs
|
|
17
|
-
*/
|
|
18
|
-
import { useState } from 'react';
|
|
19
|
-
import { createAttachableAnimator } from "../animator/createAnimator.js";
|
|
20
|
-
import { useAttachment } from "./useAttachment.js";
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Animates the element behind `ref` with the motion Core uses. Call
|
|
24
|
-
* `animate`, `decay`, `set`, `get`, `getVelocity` or `stop` on the returned
|
|
25
|
-
* animator from event handlers and effects. Pass the same `ref` to a gesture
|
|
26
|
-
* hook to drag and animate one element.
|
|
27
|
-
*
|
|
28
|
-
* The hook makes the animator once, and animating never re-renders the
|
|
29
|
-
* component. After each commit, the animator follows the element behind
|
|
30
|
-
* `ref`, also a node that replaces it. An unmount stops running motion and
|
|
31
|
-
* drops the values. A remount, or a node that replaces the element, starts
|
|
32
|
-
* at rest. While no element is attached, every call does nothing, and
|
|
33
|
-
* `animate` and `decay` resolve at once.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```
|
|
37
|
-
* const ref = useRef<HTMLDivElement>(null);
|
|
38
|
-
* const animator = useAnimator(ref);
|
|
39
|
-
* return (
|
|
40
|
-
* <div ref={ref} onClick={() => animator.animate({scale: 1.2})}>
|
|
41
|
-
* Card
|
|
42
|
-
* </div>
|
|
43
|
-
* );
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export function useAnimator(ref) {
|
|
47
|
-
const [{
|
|
48
|
-
handle,
|
|
49
|
-
attach
|
|
50
|
-
}] = useState(() => {
|
|
51
|
-
const {
|
|
52
|
-
animator,
|
|
53
|
-
attach: attachElement
|
|
54
|
-
} = createAttachableAnimator();
|
|
55
|
-
// The handle without `destroy`: the hook owns the element's lifetime.
|
|
56
|
-
const {
|
|
57
|
-
destroy: _destroy,
|
|
58
|
-
...handle
|
|
59
|
-
} = animator;
|
|
60
|
-
return {
|
|
61
|
-
handle,
|
|
62
|
-
attach: element => {
|
|
63
|
-
attachElement(element);
|
|
64
|
-
return () => attachElement(null);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
useAttachment(ref, attach, null);
|
|
69
|
-
return handle;
|
|
70
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @generated by scripts/generate-i18n-runtime.mjs from packages/core/locales/en.json,
|
|
3
|
-
* holding the English for the catalog keys named in packages/core/src/PowerSearch/PowerSearchBottomSheet.tsx.
|
|
4
|
-
* Do not edit by hand. Run `pnpm generate:i18n-runtime` instead.
|
|
5
|
-
*/
|
|
6
|
-
declare const english: Readonly<Record<string, string>>;
|
|
7
|
-
export default english;
|
|
8
|
-
//# sourceMappingURL=PowerSearchBottomSheet.generated.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PowerSearchBottomSheet.generated.d.ts","sourceRoot":"","sources":["../../../../src/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,QAAA,MAAM,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgC7C,CAAC;AAEF,eAAe,OAAO,CAAC"}
|