@astryxdesign/core 0.7.8 → 0.7.9-canary.3b44b43
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/Calendar/styles.d.ts +1 -1
- package/dist/ClickableCard/ClickableCard.d.ts +1 -1
- package/dist/ClickableCard/ClickableCard.d.ts.map +1 -1
- package/dist/ClickableCard/ClickableCard.js +5 -1
- package/dist/DateInput/PickerWheel.d.ts.map +1 -1
- package/dist/DateInput/PickerWheel.js +7 -1
- package/dist/DateRangeInput/DateRangeInput.js +1 -1
- package/dist/Dialog/Dialog.d.ts +2 -1
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +8 -1
- package/dist/Drawer/useDrawerDialogPresence.d.ts +2 -1
- package/dist/Drawer/useDrawerDialogPresence.d.ts.map +1 -1
- package/dist/Drawer/useDrawerDialogPresence.js +11 -2
- package/dist/DropdownMenu/DropdownMenu.d.ts +9 -1
- package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenu.js +9 -4
- package/dist/DropdownMenu/DropdownMenuCheckboxItem.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuCheckboxItem.js +3 -2
- package/dist/DropdownMenu/DropdownMenuItem.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuItem.js +3 -2
- package/dist/DropdownMenu/DropdownMenuRadioItem.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuRadioItem.js +3 -2
- package/dist/DropdownMenu/DropdownMenuSubMenu.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuSubMenu.js +3 -2
- package/dist/Field/inputDisabledFocus.d.ts +4 -4
- package/dist/Field/inputStyles.stylex.d.ts +1 -1
- package/dist/FileInput/FileInput.d.ts.map +1 -1
- package/dist/FileInput/FileInput.js +16 -2
- package/dist/Icon/Icon.d.ts +1 -1
- package/dist/InfoTip/InfoTip.d.ts +1 -0
- package/dist/InfoTip/InfoTip.d.ts.map +1 -1
- package/dist/InfoTip/InfoTip.js +1 -0
- package/dist/Item/Item.d.ts +2 -1
- package/dist/Item/Item.d.ts.map +1 -1
- package/dist/Item/Item.js +29 -6
- package/dist/Layer/holdEntranceInput.d.ts +24 -0
- package/dist/Layer/holdEntranceInput.d.ts.map +1 -0
- package/dist/Layer/holdEntranceInput.js +65 -0
- package/dist/Layer/inputHold.d.ts +49 -0
- package/dist/Layer/inputHold.d.ts.map +1 -0
- package/dist/Layer/inputHold.js +636 -0
- package/dist/Layer/preserveAnimations.d.ts +1 -5
- package/dist/Layer/preserveAnimations.d.ts.map +1 -1
- package/dist/Layer/preserveAnimations.js +12 -214
- package/dist/MetadataList/MetadataList.js +1 -1
- package/dist/MobileNav/MobileNav.d.ts +11 -1
- package/dist/MobileNav/MobileNav.d.ts.map +1 -1
- package/dist/MobileNav/MobileNav.js +34 -1
- package/dist/MoreMenu/MoreMenu.d.ts +5 -3
- package/dist/MoreMenu/MoreMenu.d.ts.map +1 -1
- package/dist/RadioList/RadioListItem.d.ts.map +1 -1
- package/dist/RadioList/RadioListItem.js +4 -1
- package/dist/SelectableCard/SelectableCard.d.ts +1 -1
- package/dist/SelectableCard/SelectableCard.d.ts.map +1 -1
- package/dist/SelectableCard/SelectableCard.js +5 -1
- package/dist/Spinner/Spinner.d.ts.map +1 -1
- package/dist/Spinner/Spinner.js +12 -2
- package/dist/Table/plugins/sortable/useTableSortable.js +1 -1
- package/dist/Token/Token.d.ts.map +1 -1
- package/dist/Token/Token.js +9 -0
- package/dist/Token/TokenLink.d.ts +1 -1
- package/dist/Token/TokenLink.d.ts.map +1 -1
- package/dist/Token/TokenLink.js +4 -1
- package/dist/Tooltip/useTooltip.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.js +162 -59
- package/dist/TreeList/TreeListItem.d.ts +2 -1
- package/dist/TreeList/TreeListItem.d.ts.map +1 -1
- package/dist/TreeList/TreeListItem.js +27 -3
- package/dist/astryx.css +30 -7
- package/dist/gestures/GestureHost.d.ts +2 -2
- package/dist/gestures/GestureHost.d.ts.map +1 -1
- package/dist/gestures/GestureHost.js +21 -6
- package/dist/gestures/nativeScroll.d.ts +3 -6
- package/dist/gestures/nativeScroll.d.ts.map +1 -1
- package/dist/gestures/nativeScroll.js +7 -52
- package/dist/gestures/wheelSegmenter.d.ts +68 -1
- package/dist/gestures/wheelSegmenter.d.ts.map +1 -1
- package/dist/gestures/wheelSegmenter.js +199 -10
- package/dist/hooks/menuPressGesture.d.ts +133 -21
- package/dist/hooks/menuPressGesture.d.ts.map +1 -1
- package/dist/hooks/menuPressGesture.js +155 -30
- package/dist/hooks/menuPressValues.d.ts +16 -0
- package/dist/hooks/menuPressValues.d.ts.map +1 -0
- package/dist/hooks/menuPressValues.js +18 -0
- package/dist/hooks/useClickableContainer.d.ts +27 -5
- package/dist/hooks/useClickableContainer.d.ts.map +1 -1
- package/dist/hooks/useClickableContainer.js +41 -5
- package/dist/hooks/useMenuPress.d.ts +34 -1
- package/dist/hooks/useMenuPress.d.ts.map +1 -1
- package/dist/hooks/useMenuPress.js +93 -5
- package/dist/hooks/usePressFeedback.d.ts +6 -6
- package/dist/hooks/usePressFeedback.js +6 -6
- package/dist/motion/carryAnimations.d.ts +58 -0
- package/dist/motion/carryAnimations.d.ts.map +1 -0
- package/dist/motion/carryAnimations.js +305 -0
- package/dist/motion/transientCopy.d.ts +4 -2
- package/dist/motion/transientCopy.d.ts.map +1 -1
- package/dist/motion/transientCopy.js +34 -5
- package/dist/motion/uikit/gestures.d.ts +41 -0
- package/dist/motion/uikit/gestures.d.ts.map +1 -1
- package/dist/motion/uikit/gestures.js +25 -0
- package/dist/motion/uikit/index.d.ts +1 -1
- package/dist/motion/uikit/index.d.ts.map +1 -1
- package/dist/motion/uikit/index.js +1 -1
- package/dist/privateAttributes/menuPressLit.stylex.d.ts +52 -0
- package/dist/privateAttributes/menuPressLit.stylex.d.ts.map +1 -0
- package/dist/privateAttributes/menuPressLit.stylex.js +99 -0
- package/dist/privateAttributes/press.stylex.d.ts +139 -0
- package/dist/privateAttributes/press.stylex.d.ts.map +1 -0
- package/dist/privateAttributes/press.stylex.js +98 -0
- package/dist/theme/tokens.stylex.d.ts +2 -2
- package/dist/theme/tokens.stylex.js +1 -1
- package/dist/utils/flatTree.d.ts +6 -3
- package/dist/utils/flatTree.d.ts.map +1 -1
- package/dist/utils/flatTree.js +13 -3
- package/dist/utils/hitArea.d.ts.map +1 -1
- package/dist/utils/hitArea.js +82 -5
- package/dist/utils/inputStream.d.ts +14 -1
- package/dist/utils/inputStream.d.ts.map +1 -1
- package/dist/utils/inputStream.js +40 -9
- package/dist/utils/interactionOverlay.stylex.d.ts +2 -1
- package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
- package/dist/utils/interactionOverlay.stylex.js +7 -2
- package/dist/utils/pressFeedback.d.ts +7 -0
- package/dist/utils/pressFeedback.d.ts.map +1 -1
- package/dist/utils/pressFeedback.js +32 -7
- package/dist/utils/pressGesture.d.ts +6 -0
- package/dist/utils/pressGesture.d.ts.map +1 -1
- package/dist/utils/pressGesture.js +17 -0
- package/dist/utils/rowPressLayer.stylex.d.ts +14 -0
- package/dist/utils/rowPressLayer.stylex.d.ts.map +1 -0
- package/dist/utils/rowPressLayer.stylex.js +25 -0
- package/dist/utils/scrollView.d.ts +25 -0
- package/dist/utils/scrollView.d.ts.map +1 -0
- package/dist/utils/scrollView.js +108 -0
- package/dist/utils/selectionLock.d.ts.map +1 -1
- package/dist/utils/selectionLock.js +1 -10
- package/dist/utils/triggerFocus.d.ts +5 -0
- package/dist/utils/triggerFocus.d.ts.map +1 -1
- package/dist/utils/triggerFocus.js +9 -2
- package/package.json +5 -5
- package/src/ClickableCard/ClickableCard.tsx +8 -1
- package/src/DateInput/PickerWheel.tsx +7 -2
- package/src/DateRangeInput/DateRangeInput.tsx +1 -1
- package/src/Dialog/Dialog.doc.mjs +1 -1
- package/src/Dialog/Dialog.tsx +8 -1
- package/src/Drawer/Drawer.doc.mjs +1 -1
- package/src/Drawer/useDrawerDialogPresence.ts +9 -2
- package/src/DropdownMenu/DropdownMenu.doc.mjs +1 -2
- package/src/DropdownMenu/DropdownMenu.tsx +29 -5
- package/src/DropdownMenu/DropdownMenuCheckboxItem.tsx +5 -1
- package/src/DropdownMenu/DropdownMenuItem.tsx +8 -4
- package/src/DropdownMenu/DropdownMenuRadioItem.tsx +5 -1
- package/src/DropdownMenu/DropdownMenuSubMenu.tsx +5 -1
- package/src/FileInput/FileInput.tsx +16 -2
- package/src/InfoTip/InfoTip.doc.mjs +26 -2
- package/src/InfoTip/InfoTip.tsx +1 -0
- package/src/Item/Item.tsx +51 -9
- package/src/Layer/holdEntranceInput.ts +84 -0
- package/src/Layer/inputHold.ts +734 -0
- package/src/Layer/preserveAnimations.ts +12 -275
- package/src/MetadataList/MetadataList.tsx +1 -1
- package/src/MobileNav/MobileNav.doc.mjs +3 -3
- package/src/MobileNav/MobileNav.tsx +34 -1
- package/src/MoreMenu/MoreMenu.doc.mjs +2 -4
- package/src/MoreMenu/MoreMenu.tsx +5 -3
- package/src/RadioList/RadioListItem.tsx +4 -5
- package/src/SelectableCard/SelectableCard.tsx +8 -1
- package/src/Spinner/Spinner.tsx +13 -3
- package/src/Table/plugins/sortable/useTableSortable.tsx +1 -1
- package/src/Token/Token.tsx +18 -1
- package/src/Token/TokenLink.tsx +7 -1
- package/src/Tooltip/useTooltip.tsx +175 -79
- package/src/TreeList/TreeListItem.tsx +36 -2
- package/src/gestures/GestureHost.ts +21 -5
- package/src/gestures/README.md +12 -4
- package/src/gestures/nativeScroll.ts +12 -68
- package/src/gestures/wheelSegmenter.ts +243 -10
- package/src/hooks/menuPressGesture.ts +244 -38
- package/src/hooks/menuPressValues.ts +18 -0
- package/src/hooks/useClickableContainer.doc.mjs +8 -2
- package/src/hooks/useClickableContainer.ts +72 -6
- package/src/hooks/useMenuPress.ts +118 -11
- package/src/hooks/usePressFeedback.doc.mjs +3 -3
- package/src/hooks/usePressFeedback.ts +6 -6
- package/src/motion/MEASUREMENTS.md +11 -0
- package/src/motion/carryAnimations.ts +389 -0
- package/src/motion/transientCopy.ts +45 -5
- package/src/motion/uikit/gestures.ts +22 -0
- package/src/motion/uikit/index.ts +1 -0
- package/src/privateAttributes/menuPressLit.stylex.ts +104 -0
- package/src/privateAttributes/press.stylex.ts +244 -0
- package/src/theme/tokens.stylex.ts +1 -1
- package/src/utils/flatTree.ts +15 -3
- package/src/utils/hitArea.ts +107 -5
- package/src/utils/inputStream.ts +47 -10
- package/src/utils/interactionOverlay.stylex.ts +7 -2
- package/src/utils/pressFeedback.ts +31 -6
- package/src/utils/pressGesture.ts +24 -1
- package/src/utils/rowPressLayer.stylex.ts +27 -0
- package/src/utils/scrollView.ts +135 -0
- package/src/utils/selectionLock.ts +5 -10
- package/src/utils/triggerFocus.ts +17 -4
package/dist/Item/Item.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file Item.tsx
|
|
7
|
-
* @input Uses React, ReactNode, StyleXStyles, theme tokens, useClickableContainer
|
|
7
|
+
* @input Uses React, ReactNode, StyleXStyles, theme tokens, useClickableContainer,
|
|
8
|
+
* the shared press overlays and the compositor press layer
|
|
8
9
|
* @output Exports Item component, ItemProps type; publishes the shared inline inset.
|
|
9
10
|
* Only numbered composing rows keep their start/label/end slots in one flex
|
|
10
11
|
* group, through Item's private exact-marker scope; other marked rows keep
|
|
@@ -34,17 +35,19 @@ import "../theme/tokens.stylex.js";
|
|
|
34
35
|
import { colorVars, radiusVars, spacingVars, durationVars, easeVars, typeScaleVars } from "../theme/tokens.stylex.js";
|
|
35
36
|
import { isRenderable } from "../utils/isRenderable.js";
|
|
36
37
|
import { mergeProps } from "../utils/mergeProps.js";
|
|
38
|
+
import { chainEventHandlers } from "../utils/chainEventHandlers.js";
|
|
37
39
|
import { useFocusAcrossSwap } from "../utils/useFocusAcrossSwap.js";
|
|
38
40
|
import { ItemDescriptionContext } from "./ItemDescriptionContext.js";
|
|
39
41
|
import { ItemMarkerColumnsContext } from "./ItemMarkerColumnsContext.js";
|
|
40
42
|
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
41
43
|
import { computeTargetAndRel } from "../Link/computeTargetAndRel.js";
|
|
42
44
|
import { useLinkComponent } from "../Link/useLinkComponent.js";
|
|
43
|
-
import { useClickableContainer } from "../hooks/useClickableContainer.js";
|
|
45
|
+
import { cancelNestedTouchPress, useClickableContainer } from "../hooks/useClickableContainer.js";
|
|
44
46
|
import { useDevWarning } from "../hooks/useDevWarning.js";
|
|
45
47
|
import { themeProps } from "../utils/themeProps.js";
|
|
46
48
|
import { focusOutlineProps } from "../utils/focusOutline.stylex.js";
|
|
47
49
|
import { interactionOverlayStyles } from "../utils/interactionOverlay.stylex.js";
|
|
50
|
+
import { rowPressLayerStyles } from "../privateAttributes/press.stylex.js";
|
|
48
51
|
import { usePressFeedback } from "../hooks/usePressFeedback.js";
|
|
49
52
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
50
53
|
// The gesture and the panels, loaded only by a row that has swipe actions: a
|
|
@@ -190,7 +193,6 @@ const styles = {
|
|
|
190
193
|
$$css: true
|
|
191
194
|
},
|
|
192
195
|
swipeRoot: {
|
|
193
|
-
kHBbk8: "xc8icb0",
|
|
194
196
|
kFalU9: "xge0x1e",
|
|
195
197
|
k3aq6I: "x1kncwj0",
|
|
196
198
|
k1ekBW: "xuo13n2",
|
|
@@ -281,7 +283,11 @@ export function Item({
|
|
|
281
283
|
// the router link component, which may require a live href. The element type
|
|
282
284
|
// then changes with `isDisabled`, so focus follows the swap (FR4).
|
|
283
285
|
const RowAnchor = isDisabled ? 'a' : LinkComponent;
|
|
284
|
-
|
|
286
|
+
// The row's own action, its invisible link or button: a press on it
|
|
287
|
+
// activates the row.
|
|
288
|
+
const actionLinkRef = useRef(null);
|
|
289
|
+
const actionButtonRef = useRef(null);
|
|
290
|
+
const anchorRef = useFocusAcrossSwap(actionLinkRef);
|
|
285
291
|
|
|
286
292
|
// Delegation mode: the row is an enlarged click/tap target for a nested
|
|
287
293
|
// control (e.g. a checkbox) that owns the keyboard access and action. The
|
|
@@ -291,7 +297,8 @@ export function Item({
|
|
|
291
297
|
// Only onClick is needed: onMouseUp handles middle-click href navigation,
|
|
292
298
|
// which delegation mode never has (href is ignored here).
|
|
293
299
|
const {
|
|
294
|
-
onClick: delegatedOnClick
|
|
300
|
+
onClick: delegatedOnClick,
|
|
301
|
+
onPointerDown: delegatedOnPointerDown
|
|
295
302
|
} = useClickableContainer({
|
|
296
303
|
containerRef,
|
|
297
304
|
interactiveRef: interactiveRef ?? undefined,
|
|
@@ -311,6 +318,12 @@ export function Item({
|
|
|
311
318
|
// component means the root itself is the anchor, so the address rides it
|
|
312
319
|
// and the invisible anchor below is not rendered.
|
|
313
320
|
const isLinkRoot = typeof Component !== 'string' && href != null;
|
|
321
|
+
// A press on a nested control does not run this row's action, so the row
|
|
322
|
+
// shows no touch press. A row with a parent role or a link root runs it, so
|
|
323
|
+
// it keeps the press. Such a row is not a clickable container: an enclosing
|
|
324
|
+
// card still treats it as part of its own surface.
|
|
325
|
+
const hasOwnAction = (onClick != null || href != null) && !hasParentRole && !isLinkRoot;
|
|
326
|
+
const pressOnRow = event => cancelNestedTouchPress(event, event.currentTarget, href != null ? actionLinkRef.current : actionButtonRef.current);
|
|
314
327
|
|
|
315
328
|
// Swipe actions exist where the row's role permits interactive descendants
|
|
316
329
|
// (a swipe panel's buttons are such descendants): a `listitem`, or no role
|
|
@@ -434,6 +447,7 @@ export function Item({
|
|
|
434
447
|
}[!!isInline << 1 | !!isDisabled << 0],
|
|
435
448
|
children: labelAndDescription
|
|
436
449
|
}) : onClick != null ? /*#__PURE__*/_jsx("button", {
|
|
450
|
+
ref: actionButtonRef,
|
|
437
451
|
type: "button",
|
|
438
452
|
onClick: onClick,
|
|
439
453
|
disabled: isDisabled,
|
|
@@ -517,6 +531,11 @@ export function Item({
|
|
|
517
531
|
...restProps,
|
|
518
532
|
...swipeHandlers,
|
|
519
533
|
...linkRootProps,
|
|
534
|
+
...(isDelegate ? {
|
|
535
|
+
onPointerDown: chainEventHandlers(restProps.onPointerDown, delegatedOnPointerDown)
|
|
536
|
+
} : hasOwnAction && !isDisabled ? {
|
|
537
|
+
onPointerDown: chainEventHandlers(swipeHandlers?.onPointerDown ?? restProps.onPointerDown, pressOnRow)
|
|
538
|
+
} : null),
|
|
520
539
|
"aria-selected": allowsAriaSelected && isSelected || undefined
|
|
521
540
|
// aria-selected is invalid on roles that don't permit it (listitem, a
|
|
522
541
|
// bare div, etc.). For those, convey selection via aria-current — valid
|
|
@@ -529,7 +548,11 @@ export function Item({
|
|
|
529
548
|
...mergeProps(themeProps('item', {
|
|
530
549
|
density,
|
|
531
550
|
align
|
|
532
|
-
}), focusOutlineProps.focusWithin(styles.root, densityStyles[density], align === 'start' && styles.alignStart, align === 'first-line' && styles.alignFirstLine, isInteractive && styles.interactive, isInteractive && interactionOverlayStyles.backgroundColor,
|
|
551
|
+
}), focusOutlineProps.focusWithin(styles.root, densityStyles[density], align === 'start' && styles.alignStart, align === 'first-line' && styles.alignFirstLine, isInteractive && styles.interactive, isInteractive && interactionOverlayStyles.backgroundColor,
|
|
552
|
+
// The touch press on a compositor layer (after the overlay, whose
|
|
553
|
+
// own touch paint it turns off): the release keeps fading while
|
|
554
|
+
// script runs.
|
|
555
|
+
isInteractive && rowPressLayerStyles.cell, isLinkRoot && styles.linkRoot, isHighlighted && styles.highlighted, isSelected && styles.selected, isDisabled && !hasParentRole && styles.disabled, hasSwipe && styles.swipeRoot, xstyle), className, style),
|
|
533
556
|
role: role,
|
|
534
557
|
onClick: rootOnClick,
|
|
535
558
|
children: [/*#__PURE__*/_jsxs(ItemDescriptionContext, {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Options for {@link holdEntranceInput}. */
|
|
2
|
+
export interface EntranceHoldOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Holds input anywhere while true. While false, only what lands on the layer
|
|
5
|
+
* is held, and the page stays live.
|
|
6
|
+
* @default true
|
|
7
|
+
*/
|
|
8
|
+
isModal?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The element whose animations are the entrance, when it is not the layer
|
|
11
|
+
* itself (a drawer inside its dialog).
|
|
12
|
+
* @default the layer
|
|
13
|
+
*/
|
|
14
|
+
entrance?: Element | null;
|
|
15
|
+
/** The longest the hold lasts, ms. An entrance that runs longer ends it. */
|
|
16
|
+
capMs?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Holds a finger's and a pen's input away from `layer` until its entrance
|
|
20
|
+
* ends, or at most `capMs`. Returns the release, or `null` when nothing is
|
|
21
|
+
* held: no entrance runs, or the primary pointer is fine.
|
|
22
|
+
*/
|
|
23
|
+
export declare function holdEntranceInput(layer: Element, { isModal, entrance: animated, capMs }?: EntranceHoldOptions): (() => void) | null;
|
|
24
|
+
//# sourceMappingURL=holdEntranceInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"holdEntranceInput.d.ts","sourceRoot":"","sources":["../../src/Layer/holdEntranceInput.ts"],"names":[],"mappings":"AAmBA,6CAA6C;AAC7C,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1B,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,EAAC,OAAc,EAAE,QAAQ,EAAE,QAAgB,EAAE,KAAK,EAAC,GAAE,mBAAwB,GAC5E,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAuBrB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file holdEntranceInput.ts
|
|
7
|
+
* @input A layer root whose CSS entrance has just started
|
|
8
|
+
* @output holdEntranceInput: under a coarse primary pointer, a finger's or a
|
|
9
|
+
* pen's input held away from the layer until its entrance ends
|
|
10
|
+
* @position The entrance hold for layers that enter through CSS (Dialog,
|
|
11
|
+
* Drawer, MobileNav), on the Layer module's input hold (inputHold.ts)
|
|
12
|
+
*
|
|
13
|
+
* SYNC: When modified, update holdEntranceInput.test.ts and its callers
|
|
14
|
+
* (Dialog.tsx, Drawer/useDrawerDialogPresence.ts, MobileNav/MobileNav.tsx).
|
|
15
|
+
*/
|
|
16
|
+
import { isCoarsePointer } from "../utils/coarsePointer.js";
|
|
17
|
+
import { holdInput } from "./inputHold.js";
|
|
18
|
+
|
|
19
|
+
/** Options for {@link holdEntranceInput}. */
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Holds a finger's and a pen's input away from `layer` until its entrance
|
|
23
|
+
* ends, or at most `capMs`. Returns the release, or `null` when nothing is
|
|
24
|
+
* held: no entrance runs, or the primary pointer is fine.
|
|
25
|
+
*/
|
|
26
|
+
export function holdEntranceInput(layer, {
|
|
27
|
+
isModal = true,
|
|
28
|
+
entrance: animated = layer,
|
|
29
|
+
capMs
|
|
30
|
+
} = {}) {
|
|
31
|
+
if (animated == null || typeof animated.getAnimations !== 'function') {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
// getAnimations() flushes styles, so it lists an entrance the open has just
|
|
35
|
+
// started. A theme's duration, a shorter reduced-motion entrance and a
|
|
36
|
+
// canceled entrance all end the hold when they end.
|
|
37
|
+
const entrance = animated.getAnimations().filter(isEntrance);
|
|
38
|
+
if (entrance.length === 0) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
// A touch presentation only, read as the layer opens. A finger on a device
|
|
42
|
+
// whose primary pointer is fine, such as a touchscreen laptop, is not held.
|
|
43
|
+
if (!isCoarsePointer(layer.ownerDocument.defaultView)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const ended = Promise.all(entrance.map(async animation => animation.finished));
|
|
47
|
+
return holdInput(layer, {
|
|
48
|
+
until: capMs == null ? ended : Promise.race([ended, after(capMs)]),
|
|
49
|
+
scope: isModal ? 'viewport' : 'surface'
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async function after(ms) {
|
|
53
|
+
await new Promise(resolve => {
|
|
54
|
+
setTimeout(resolve, ms);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A running animation that ends on its own: an entrance, not a spin. */
|
|
59
|
+
function isEntrance(animation) {
|
|
60
|
+
if (animation.playState !== 'running') {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const end = animation.effect?.getComputedTiming().endTime;
|
|
64
|
+
return typeof end === 'number' && Number.isFinite(end);
|
|
65
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a hold does. `'viewport'` and `'layer'` add one shield over the whole
|
|
3
|
+
* viewport. `'layer'` also makes the layer's content inert and moves focus
|
|
4
|
+
* out of it. `'surface'` shields only the layer's own box, and the page
|
|
5
|
+
* around it stays live.
|
|
6
|
+
*/
|
|
7
|
+
export type InputHoldScope = 'viewport' | 'layer' | 'surface';
|
|
8
|
+
/** What ends a hold: a promise, or an animator handle (its `finished`). */
|
|
9
|
+
export type InputHoldEnd = PromiseLike<unknown> | {
|
|
10
|
+
readonly finished: PromiseLike<unknown>;
|
|
11
|
+
};
|
|
12
|
+
export interface InputHoldOptions {
|
|
13
|
+
/** The hold ends when this settles. */
|
|
14
|
+
until: InputHoldEnd;
|
|
15
|
+
/**
|
|
16
|
+
* `'viewport'` while presenting, `'layer'` while dismissing, `'surface'`
|
|
17
|
+
* while a non-modal layer presents.
|
|
18
|
+
*/
|
|
19
|
+
scope: InputHoldScope;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether `node` is the shield of a live hold. A hit test that must see past
|
|
23
|
+
* held input takes the first element of `elementsFromPoint` that is not one.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isInputShield(node: Node | null): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether `target` is inside a held layer. It walks the flat tree as the
|
|
28
|
+
* gesture host does: a slotted node goes to its slot, and a shadow root to
|
|
29
|
+
* its host.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isInHeldLayer(target: Node | null): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether the gesture host holds `target` away for the current pointer. A
|
|
34
|
+
* dismissing layer holds every pointer. A presenting layer holds every
|
|
35
|
+
* pointer but a mouse, which keeps today's behavior. The host asks this for
|
|
36
|
+
* every touch. So this module imports nothing from gestures/, and a
|
|
37
|
+
* root-entry component can hold its layer without gesture code. With nothing
|
|
38
|
+
* held, this answers false.
|
|
39
|
+
*/
|
|
40
|
+
export declare function holdsTouch(target: Node): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Holds input away from `layer` until `until` settles. Returns the release
|
|
43
|
+
* (idempotent), for a hold that ends early. Holds on one layer stack, and
|
|
44
|
+
* the layer comes back when the last one ends. Each event is judged by its
|
|
45
|
+
* own pointer, never by the primary pointer. So a mouse on a touch screen
|
|
46
|
+
* keeps its clicks during a presentation.
|
|
47
|
+
*/
|
|
48
|
+
export declare function holdInput(layer: Element, { until, scope }: InputHoldOptions): () => void;
|
|
49
|
+
//# sourceMappingURL=inputHold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputHold.d.ts","sourceRoot":"","sources":["../../src/Layer/inputHold.ts"],"names":[],"mappings":"AAwBA;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,CAAC;AAE9D,2EAA2E;AAC3E,MAAM,MAAM,YAAY,GACtB,WAAW,CAAC,OAAO,CAAC,GAAG;IAAC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CAAC,CAAC;AAEnE,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,KAAK,EAAE,YAAY,CAAC;IACpB;;;OAGG;IACH,KAAK,EAAE,cAAc,CAAC;CACvB;AAsCD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,CAExD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,CAW1D;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,IAAI,GAAG,OAAO,CAyBhD;AAwHD;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,OAAO,EACd,EAAC,KAAK,EAAE,KAAK,EAAC,EAAE,gBAAgB,GAC/B,MAAM,IAAI,CA+EZ"}
|