@octanejs/base-ui 0.1.31 → 0.1.32
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/cjs/accordion.cjs +497 -0
- package/dist/cjs/alert-dialog.cjs +65 -0
- package/dist/cjs/avatar.cjs +234 -0
- package/dist/cjs/button.cjs +54 -0
- package/dist/cjs/checkbox-group.cjs +165 -0
- package/dist/cjs/checkbox.cjs +475 -0
- package/dist/cjs/collapsible.cjs +700 -0
- package/dist/cjs/context-menu.cjs +257 -0
- package/dist/cjs/csp-provider.cjs +40 -0
- package/dist/cjs/dialog.cjs +741 -0
- package/dist/cjs/direction-provider.cjs +35 -0
- package/dist/cjs/field.cjs +559 -0
- package/dist/cjs/fieldset.cjs +101 -0
- package/dist/cjs/form.cjs +177 -0
- package/dist/cjs/index.cjs +133 -0
- package/dist/cjs/input.cjs +32 -0
- package/dist/cjs/internal.cjs +51 -0
- package/dist/cjs/menu.cjs +2420 -0
- package/dist/cjs/menubar.cjs +132 -0
- package/dist/cjs/merge-props.cjs +34 -0
- package/dist/cjs/meter.cjs +169 -0
- package/dist/cjs/number-field.cjs +812 -0
- package/dist/cjs/popover.cjs +966 -0
- package/dist/cjs/preview-card.cjs +632 -0
- package/dist/cjs/progress.cjs +206 -0
- package/dist/cjs/radio-group.cjs +264 -0
- package/dist/cjs/radio.cjs +327 -0
- package/dist/cjs/separator.cjs +44 -0
- package/dist/cjs/slider.cjs +1384 -0
- package/dist/cjs/switch.cjs +306 -0
- package/dist/cjs/tabs.cjs +727 -0
- package/dist/cjs/toast.cjs +1766 -0
- package/dist/cjs/toggle-group.cjs +118 -0
- package/dist/cjs/toggle.cjs +121 -0
- package/dist/cjs/tooltip.cjs +835 -0
- package/dist/cjs/unstable-use-media-query.cjs +79 -0
- package/dist/cjs/use-render.cjs +40 -0
- package/dist/cjs/utils/CSPContext.cjs +38 -0
- package/dist/cjs/utils/CheckboxGroupContext.cjs +40 -0
- package/dist/cjs/utils/CompositeRootContext.cjs +40 -0
- package/dist/cjs/utils/ContextMenuRootContext.cjs +42 -0
- package/dist/cjs/utils/DirectionContext.cjs +34 -0
- package/dist/cjs/utils/FloatingPortalLite.cjs +47 -0
- package/dist/cjs/utils/InternalBackdrop.cjs +49 -0
- package/dist/cjs/utils/MenubarContext.cjs +40 -0
- package/dist/cjs/utils/RadioGroupContext.cjs +34 -0
- package/dist/cjs/utils/RequestQueue.cjs +111 -0
- package/dist/cjs/utils/TimeoutManager.cjs +50 -0
- package/dist/cjs/utils/ToggleGroupContext.cjs +40 -0
- package/dist/cjs/utils/adaptiveOriginMiddleware.cjs +94 -0
- package/dist/cjs/utils/addEventListener.cjs +33 -0
- package/dist/cjs/utils/areArraysEqual.cjs +30 -0
- package/dist/cjs/utils/clamp.cjs +30 -0
- package/dist/cjs/utils/closePart.cjs +70 -0
- package/dist/cjs/utils/collapsibleOpenStateMapping.cjs +42 -0
- package/dist/cjs/utils/composeRefs.cjs +68 -0
- package/dist/cjs/utils/composite/CompositeItem.cjs +59 -0
- package/dist/cjs/utils/composite/CompositeList.cjs +177 -0
- package/dist/cjs/utils/composite/CompositeListContext.cjs +43 -0
- package/dist/cjs/utils/composite/CompositeRoot.cjs +118 -0
- package/dist/cjs/utils/composite/grid-utils.cjs +343 -0
- package/dist/cjs/utils/composite/gridNavigation.cjs +92 -0
- package/dist/cjs/utils/composite/keys.cjs +174 -0
- package/dist/cjs/utils/composite/list-utils.cjs +90 -0
- package/dist/cjs/utils/composite/useCompositeItem.cjs +63 -0
- package/dist/cjs/utils/composite/useCompositeListItem.cjs +104 -0
- package/dist/cjs/utils/composite/useCompositeRoot.cjs +263 -0
- package/dist/cjs/utils/constants.cjs +56 -0
- package/dist/cjs/utils/contains.cjs +46 -0
- package/dist/cjs/utils/createChangeEventDetails.cjs +92 -0
- package/dist/cjs/utils/dom.cjs +35 -0
- package/dist/cjs/utils/empty.cjs +34 -0
- package/dist/cjs/utils/field/FieldItemContext.cjs +34 -0
- package/dist/cjs/utils/field/FieldRootContext.cjs +80 -0
- package/dist/cjs/utils/field/FormContext.cjs +41 -0
- package/dist/cjs/utils/field/LabelableContext.cjs +43 -0
- package/dist/cjs/utils/field/LabelableProvider.cjs +115 -0
- package/dist/cjs/utils/field/constants.cjs +68 -0
- package/dist/cjs/utils/field/getCombinedFieldValidityData.cjs +36 -0
- package/dist/cjs/utils/field/useAriaLabelledBy.cjs +87 -0
- package/dist/cjs/utils/field/useFieldControlRegistration.cjs +165 -0
- package/dist/cjs/utils/field/useFieldValidation.cjs +285 -0
- package/dist/cjs/utils/field/useLabel.cjs +99 -0
- package/dist/cjs/utils/field/useLabelableId.cjs +105 -0
- package/dist/cjs/utils/field/useRegisterFieldControl.cjs +60 -0
- package/dist/cjs/utils/findRootOwnerId.cjs +37 -0
- package/dist/cjs/utils/floating/FloatingDelayGroup.cjs +219 -0
- package/dist/cjs/utils/floating/FloatingFocusManager.cjs +685 -0
- package/dist/cjs/utils/floating/FloatingPortal.cjs +230 -0
- package/dist/cjs/utils/floating/FloatingRootStore.cjs +87 -0
- package/dist/cjs/utils/floating/FloatingTree.cjs +86 -0
- package/dist/cjs/utils/floating/FloatingTreeStore.cjs +41 -0
- package/dist/cjs/utils/floating/FocusGuard.cjs +54 -0
- package/dist/cjs/utils/floating/composite.cjs +42 -0
- package/dist/cjs/utils/floating/constants.cjs +34 -0
- package/dist/cjs/utils/floating/createAttribute.cjs +30 -0
- package/dist/cjs/utils/floating/createEventEmitter.cjs +44 -0
- package/dist/cjs/utils/floating/element.cjs +103 -0
- package/dist/cjs/utils/floating/enqueueFocus.cjs +51 -0
- package/dist/cjs/utils/floating/event.cjs +65 -0
- package/dist/cjs/utils/floating/getEmptyRootContext.cjs +42 -0
- package/dist/cjs/utils/floating/gridNavigation.cjs +45 -0
- package/dist/cjs/utils/floating/markOthers.cjs +181 -0
- package/dist/cjs/utils/floating/nodes.cjs +48 -0
- package/dist/cjs/utils/floating/safePolygon.cjs +301 -0
- package/dist/cjs/utils/floating/tabbable.cjs +242 -0
- package/dist/cjs/utils/floating/types.cjs +16 -0
- package/dist/cjs/utils/floating/useClick.cjs +153 -0
- package/dist/cjs/utils/floating/useClientPoint.cjs +225 -0
- package/dist/cjs/utils/floating/useDismiss.cjs +506 -0
- package/dist/cjs/utils/floating/useFloating.cjs +186 -0
- package/dist/cjs/utils/floating/useFloatingRootContext.cjs +75 -0
- package/dist/cjs/utils/floating/useFocus.cjs +184 -0
- package/dist/cjs/utils/floating/useHoverFloatingInteraction.cjs +231 -0
- package/dist/cjs/utils/floating/useHoverInteractionSharedState.cjs +113 -0
- package/dist/cjs/utils/floating/useHoverReferenceInteraction.cjs +380 -0
- package/dist/cjs/utils/floating/useHoverShared.cjs +65 -0
- package/dist/cjs/utils/floating/useListNavigation.cjs +665 -0
- package/dist/cjs/utils/floating/useSyncedFloatingRootContext.cjs +91 -0
- package/dist/cjs/utils/floating/useTypeahead.cjs +187 -0
- package/dist/cjs/utils/formatNumber.cjs +60 -0
- package/dist/cjs/utils/generateId.cjs +32 -0
- package/dist/cjs/utils/getCssDimensions.cjs +42 -0
- package/dist/cjs/utils/getDefaultFormSubmitter.cjs +42 -0
- package/dist/cjs/utils/getDisabledMountTransitionStyles.cjs +32 -0
- package/dist/cjs/utils/getElementRef.cjs +35 -0
- package/dist/cjs/utils/getPseudoElementBounds.cjs +56 -0
- package/dist/cjs/utils/getStateAttributesProps.cjs +46 -0
- package/dist/cjs/utils/hideMiddleware.cjs +42 -0
- package/dist/cjs/utils/inertValue.cjs +30 -0
- package/dist/cjs/utils/matchesFocusVisible.cjs +38 -0
- package/dist/cjs/utils/mergeCleanups.cjs +37 -0
- package/dist/cjs/utils/mergeObjects.cjs +39 -0
- package/dist/cjs/utils/mergeProps.cjs +182 -0
- package/dist/cjs/utils/noop.cjs +29 -0
- package/dist/cjs/utils/number/constants.cjs +34 -0
- package/dist/cjs/utils/number/parse.cjs +258 -0
- package/dist/cjs/utils/number/types.cjs +16 -0
- package/dist/cjs/utils/number/validate.cjs +104 -0
- package/dist/cjs/utils/owner.cjs +35 -0
- package/dist/cjs/utils/platform.cjs +83 -0
- package/dist/cjs/utils/popupStateMapping.cjs +74 -0
- package/dist/cjs/utils/popups/index.cjs +39 -0
- package/dist/cjs/utils/popups/inlineRect.cjs +218 -0
- package/dist/cjs/utils/popups/popupStoreUtils.cjs +379 -0
- package/dist/cjs/utils/popups/popupTriggerMap.cjs +76 -0
- package/dist/cjs/utils/popups/store.cjs +118 -0
- package/dist/cjs/utils/popups/useTriggerFocusGuards.cjs +72 -0
- package/dist/cjs/utils/resolveAriaLabelledBy.cjs +35 -0
- package/dist/cjs/utils/resolveClassName.cjs +30 -0
- package/dist/cjs/utils/resolveRef.cjs +33 -0
- package/dist/cjs/utils/resolveStyle.cjs +30 -0
- package/dist/cjs/utils/serializeValue.cjs +40 -0
- package/dist/cjs/utils/slider/asc.cjs +30 -0
- package/dist/cjs/utils/slider/getMidpoint.cjs +34 -0
- package/dist/cjs/utils/slider/getPushedThumbValues.cjs +73 -0
- package/dist/cjs/utils/slider/getSliderValue.cjs +42 -0
- package/dist/cjs/utils/slider/replaceArrayItemAtIndex.cjs +33 -0
- package/dist/cjs/utils/slider/resolveThumbCollision.cjs +155 -0
- package/dist/cjs/utils/slider/roundValueToStep.cjs +45 -0
- package/dist/cjs/utils/slider/validateMinimumDistance.cjs +40 -0
- package/dist/cjs/utils/slider/valueArrayToPercentages.cjs +36 -0
- package/dist/cjs/utils/store/ReactStore.cjs +135 -0
- package/dist/cjs/utils/store/Store.cjs +83 -0
- package/dist/cjs/utils/store/createSelector.cjs +74 -0
- package/dist/cjs/utils/store/useStore.cjs +51 -0
- package/dist/cjs/utils/stringifyLocale.cjs +36 -0
- package/dist/cjs/utils/useAnchorPositioning.cjs +421 -0
- package/dist/cjs/utils/useAnchoredPopupScrollLock.cjs +59 -0
- package/dist/cjs/utils/useAnimationFrame.cjs +93 -0
- package/dist/cjs/utils/useAnimationsFinished.cjs +98 -0
- package/dist/cjs/utils/useBaseUiId.cjs +36 -0
- package/dist/cjs/utils/useButton.cjs +177 -0
- package/dist/cjs/utils/useCheckboxGroupParent.cjs +114 -0
- package/dist/cjs/utils/useControlled.cjs +47 -0
- package/dist/cjs/utils/useEnhancedClickHandler.cjs +60 -0
- package/dist/cjs/utils/useFocusableWhenDisabled.cjs +77 -0
- package/dist/cjs/utils/useForcedRerendering.cjs +35 -0
- package/dist/cjs/utils/useIsHydrating.cjs +44 -0
- package/dist/cjs/utils/useMixedToggleClickHandler.cjs +66 -0
- package/dist/cjs/utils/useOnFirstRender.cjs +35 -0
- package/dist/cjs/utils/useOnMount.cjs +36 -0
- package/dist/cjs/utils/useOpenChangeComplete.cjs +57 -0
- package/dist/cjs/utils/useOpenInteractionType.cjs +69 -0
- package/dist/cjs/utils/usePopupAutoResize.cjs +191 -0
- package/dist/cjs/utils/usePopupViewport.cjs +283 -0
- package/dist/cjs/utils/usePositioner.cjs +53 -0
- package/dist/cjs/utils/usePressAndHold.cjs +51 -0
- package/dist/cjs/utils/usePreviousValue.cjs +47 -0
- package/dist/cjs/utils/useRefWithInit.cjs +41 -0
- package/dist/cjs/utils/useRegisteredLabelId.cjs +48 -0
- package/dist/cjs/utils/useRenderElement.cjs +106 -0
- package/dist/cjs/utils/useScrollLock.cjs +232 -0
- package/dist/cjs/utils/useStableCallback.cjs +41 -0
- package/dist/cjs/utils/useTimeout.cjs +66 -0
- package/dist/cjs/utils/useTransitionStatus.cjs +116 -0
- package/dist/cjs/utils/useValueAsRef.cjs +43 -0
- package/dist/cjs/utils/useValueChanged.cjs +55 -0
- package/dist/cjs/utils/valueToPercent.cjs +30 -0
- package/dist/cjs/utils/visuallyHidden.cjs +49 -0
- package/package.json +20 -8
|
@@ -0,0 +1,1766 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var toast_exports = {};
|
|
20
|
+
__export(toast_exports, {
|
|
21
|
+
Toast: () => Toast,
|
|
22
|
+
ToastPositionerCssVars: () => ToastPositionerCssVars,
|
|
23
|
+
ToastRootCssVars: () => ToastRootCssVars,
|
|
24
|
+
ToastStore: () => ToastStore,
|
|
25
|
+
ToastViewportCssVars: () => ToastViewportCssVars,
|
|
26
|
+
createToastManager: () => createToastManager,
|
|
27
|
+
resolvePromiseOptions: () => resolvePromiseOptions,
|
|
28
|
+
toastSelectors: () => toastSelectors,
|
|
29
|
+
useToastManager: () => useToastManager,
|
|
30
|
+
useToastPositionerContext: () => useToastPositionerContext,
|
|
31
|
+
useToastProviderContext: () => useToastProviderContext,
|
|
32
|
+
useToastRootContext: () => useToastRootContext
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(toast_exports);
|
|
35
|
+
var import_octane = require("octane");
|
|
36
|
+
var import_internal = require("./internal.cjs");
|
|
37
|
+
var import_useRenderElement = require("./utils/useRenderElement.cjs");
|
|
38
|
+
var import_usePositioner = require("./utils/usePositioner.cjs");
|
|
39
|
+
var import_useButton = require("./utils/useButton.cjs");
|
|
40
|
+
var import_useStableCallback = require("./utils/useStableCallback.cjs");
|
|
41
|
+
var import_useRefWithInit = require("./utils/useRefWithInit.cjs");
|
|
42
|
+
var import_useOnMount = require("./utils/useOnMount.cjs");
|
|
43
|
+
var import_useTimeout = require("./utils/useTimeout.cjs");
|
|
44
|
+
var import_useOpenChangeComplete = require("./utils/useOpenChangeComplete.cjs");
|
|
45
|
+
var import_generateId = require("./utils/generateId.cjs");
|
|
46
|
+
var import_owner = require("./utils/owner.cjs");
|
|
47
|
+
var import_addEventListener = require("./utils/addEventListener.cjs");
|
|
48
|
+
var import_mergeCleanups = require("./utils/mergeCleanups.cjs");
|
|
49
|
+
var import_visuallyHidden = require("./utils/visuallyHidden.cjs");
|
|
50
|
+
var import_inertValue = require("./utils/inertValue.cjs");
|
|
51
|
+
var import_empty = require("./utils/empty.cjs");
|
|
52
|
+
var import_noop = require("./utils/noop.cjs");
|
|
53
|
+
var import_dom = require("./utils/dom.cjs");
|
|
54
|
+
var import_ReactStore = require("./utils/store/ReactStore.cjs");
|
|
55
|
+
var import_createSelector = require("./utils/store/createSelector.cjs");
|
|
56
|
+
var import_useTransitionStatus = require("./utils/useTransitionStatus.cjs");
|
|
57
|
+
var import_matchesFocusVisible = require("./utils/matchesFocusVisible.cjs");
|
|
58
|
+
var import_element = require("./utils/floating/element.cjs");
|
|
59
|
+
var import_list_utils = require("./utils/composite/list-utils.cjs");
|
|
60
|
+
var import_FocusGuard = require("./utils/floating/FocusGuard.cjs");
|
|
61
|
+
var import_FloatingPortalLite = require("./utils/FloatingPortalLite.cjs");
|
|
62
|
+
var import_useFloatingRootContext = require("./utils/floating/useFloatingRootContext.cjs");
|
|
63
|
+
var import_useAnchorPositioning = require("./utils/useAnchorPositioning.cjs");
|
|
64
|
+
var import_constants = require("./utils/constants.cjs");
|
|
65
|
+
const ToastRootCssVars = {
|
|
66
|
+
/** The index of the toast in the list. */
|
|
67
|
+
index: "--toast-index",
|
|
68
|
+
/** The vertical pixel offset of the toast in the list when expanded. */
|
|
69
|
+
offsetY: "--toast-offset-y",
|
|
70
|
+
/** The measured natural height of the toast in pixels. */
|
|
71
|
+
height: "--toast-height",
|
|
72
|
+
/** The horizontal swipe movement of the toast. */
|
|
73
|
+
swipeMovementX: "--toast-swipe-movement-x",
|
|
74
|
+
/** The vertical swipe movement of the toast. */
|
|
75
|
+
swipeMovementY: "--toast-swipe-movement-y"
|
|
76
|
+
};
|
|
77
|
+
const ToastViewportCssVars = {
|
|
78
|
+
/** The height of the frontmost toast. */
|
|
79
|
+
frontmostHeight: "--toast-frontmost-height"
|
|
80
|
+
};
|
|
81
|
+
const ToastPositionerCssVars = {
|
|
82
|
+
availableWidth: "--available-width",
|
|
83
|
+
availableHeight: "--available-height",
|
|
84
|
+
anchorWidth: "--anchor-width",
|
|
85
|
+
anchorHeight: "--anchor-height",
|
|
86
|
+
transformOrigin: "--transform-origin"
|
|
87
|
+
};
|
|
88
|
+
function resolvePromiseOptions(options, result) {
|
|
89
|
+
if (typeof options === "string") {
|
|
90
|
+
return { description: options };
|
|
91
|
+
}
|
|
92
|
+
if (typeof options === "function") {
|
|
93
|
+
const resolvedOptions = options(result);
|
|
94
|
+
return typeof resolvedOptions === "string" ? { description: resolvedOptions } : resolvedOptions;
|
|
95
|
+
}
|
|
96
|
+
return options;
|
|
97
|
+
}
|
|
98
|
+
function createToastMetadata(toasts) {
|
|
99
|
+
const metadata = /* @__PURE__ */ new Map();
|
|
100
|
+
let visibleIndex = 0;
|
|
101
|
+
let offsetY = 0;
|
|
102
|
+
toasts.forEach((toast, toastIndex) => {
|
|
103
|
+
const isEnding = toast.transitionStatus === "ending";
|
|
104
|
+
metadata.set(toast.id, {
|
|
105
|
+
value: toast,
|
|
106
|
+
domIndex: toastIndex,
|
|
107
|
+
visibleIndex: isEnding ? -1 : visibleIndex,
|
|
108
|
+
offsetY
|
|
109
|
+
});
|
|
110
|
+
offsetY += toast.height || 0;
|
|
111
|
+
if (!isEnding) {
|
|
112
|
+
visibleIndex += 1;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return metadata;
|
|
116
|
+
}
|
|
117
|
+
function applyLimited(toasts, limit) {
|
|
118
|
+
let activeIndex = 0;
|
|
119
|
+
return toasts.map((toast) => {
|
|
120
|
+
if (toast.transitionStatus === "ending") {
|
|
121
|
+
return toast;
|
|
122
|
+
}
|
|
123
|
+
const limited = activeIndex >= limit;
|
|
124
|
+
activeIndex += 1;
|
|
125
|
+
return toast.limited === limited ? toast : { ...toast, limited };
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const toastMetadataSelector = (state) => state.toastMetadata;
|
|
129
|
+
const toastSelectors = {
|
|
130
|
+
toasts: (0, import_createSelector.createSelector)((state) => state.toasts),
|
|
131
|
+
isEmpty: (0, import_createSelector.createSelector)((state) => state.toasts.length === 0),
|
|
132
|
+
toast: (0, import_createSelector.createSelector)(
|
|
133
|
+
toastMetadataSelector,
|
|
134
|
+
(toastMetadata, id) => toastMetadata.get(id)?.value
|
|
135
|
+
),
|
|
136
|
+
toastIndex: (0, import_createSelector.createSelector)(
|
|
137
|
+
toastMetadataSelector,
|
|
138
|
+
(toastMetadata, id) => toastMetadata.get(id)?.domIndex ?? -1
|
|
139
|
+
),
|
|
140
|
+
toastOffsetY: (0, import_createSelector.createSelector)(
|
|
141
|
+
toastMetadataSelector,
|
|
142
|
+
(toastMetadata, id) => toastMetadata.get(id)?.offsetY ?? 0
|
|
143
|
+
),
|
|
144
|
+
toastVisibleIndex: (0, import_createSelector.createSelector)(
|
|
145
|
+
toastMetadataSelector,
|
|
146
|
+
(toastMetadata, id) => toastMetadata.get(id)?.visibleIndex ?? -1
|
|
147
|
+
),
|
|
148
|
+
hovering: (0, import_createSelector.createSelector)((state) => state.hovering),
|
|
149
|
+
focused: (0, import_createSelector.createSelector)((state) => state.focused),
|
|
150
|
+
expanded: (0, import_createSelector.createSelector)((state) => state.hovering || state.focused),
|
|
151
|
+
expandedOrOutOfFocus: (0, import_createSelector.createSelector)(
|
|
152
|
+
(state) => state.hovering || state.focused || !state.isWindowFocused
|
|
153
|
+
),
|
|
154
|
+
prevFocusElement: (0, import_createSelector.createSelector)((state) => state.prevFocusElement)
|
|
155
|
+
};
|
|
156
|
+
class ToastStore extends import_ReactStore.ReactStore {
|
|
157
|
+
timers = /* @__PURE__ */ new Map();
|
|
158
|
+
areTimersPaused = false;
|
|
159
|
+
constructor(initialState) {
|
|
160
|
+
super(
|
|
161
|
+
{
|
|
162
|
+
...initialState,
|
|
163
|
+
toastMetadata: createToastMetadata(initialState.toasts)
|
|
164
|
+
},
|
|
165
|
+
{},
|
|
166
|
+
toastSelectors
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
setFocused(focused) {
|
|
170
|
+
this.set("focused", focused);
|
|
171
|
+
}
|
|
172
|
+
setHovering(hovering) {
|
|
173
|
+
this.set("hovering", hovering);
|
|
174
|
+
}
|
|
175
|
+
setIsWindowFocused(isWindowFocused) {
|
|
176
|
+
this.set("isWindowFocused", isWindowFocused);
|
|
177
|
+
}
|
|
178
|
+
setPrevFocusElement(prevFocusElement) {
|
|
179
|
+
this.set("prevFocusElement", prevFocusElement);
|
|
180
|
+
}
|
|
181
|
+
setViewport = (viewport) => {
|
|
182
|
+
this.set("viewport", viewport);
|
|
183
|
+
};
|
|
184
|
+
syncProviderProps(props) {
|
|
185
|
+
const limitChanged = this.state.limit !== props.limit;
|
|
186
|
+
if (this.state.timeout === props.timeout && !limitChanged) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const updates = {
|
|
190
|
+
timeout: props.timeout,
|
|
191
|
+
limit: props.limit
|
|
192
|
+
};
|
|
193
|
+
if (limitChanged) {
|
|
194
|
+
const newToasts = applyLimited(this.state.toasts, props.limit);
|
|
195
|
+
updates.toasts = newToasts;
|
|
196
|
+
updates.toastMetadata = createToastMetadata(newToasts);
|
|
197
|
+
}
|
|
198
|
+
this.update(updates);
|
|
199
|
+
}
|
|
200
|
+
disposeEffect = () => {
|
|
201
|
+
return () => {
|
|
202
|
+
this.timers.forEach((timer) => {
|
|
203
|
+
timer.timeout?.clear();
|
|
204
|
+
});
|
|
205
|
+
this.timers.clear();
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
removeToast(toastId, behavior = {}) {
|
|
209
|
+
const index = toastSelectors.toastIndex(this.state, toastId);
|
|
210
|
+
if (index === -1) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const toast = this.state.toasts[index];
|
|
214
|
+
if (!behavior.skipOnRemove) {
|
|
215
|
+
toast?.onRemove?.();
|
|
216
|
+
}
|
|
217
|
+
const newToasts = [...this.state.toasts];
|
|
218
|
+
newToasts.splice(index, 1);
|
|
219
|
+
this.setToasts(newToasts);
|
|
220
|
+
}
|
|
221
|
+
addToast = (toast) => {
|
|
222
|
+
const { timeout, limit } = this.state;
|
|
223
|
+
const id = toast.id || (0, import_generateId.generateId)("toast");
|
|
224
|
+
if (toast.id) {
|
|
225
|
+
const existingToast = toastSelectors.toast(this.state, toast.id);
|
|
226
|
+
if (existingToast) {
|
|
227
|
+
if (existingToast.transitionStatus === "ending") {
|
|
228
|
+
this.removeToast(toast.id, { skipOnRemove: true });
|
|
229
|
+
} else {
|
|
230
|
+
const { id: ignoredId, transitionStatus: ignoredTransitionStatus, ...updates } = toast;
|
|
231
|
+
this.updateToastInternal(toast.id, updates, {
|
|
232
|
+
resetTimer: true,
|
|
233
|
+
markUpdated: true
|
|
234
|
+
});
|
|
235
|
+
return toast.id;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const toastToAdd = {
|
|
240
|
+
...toast,
|
|
241
|
+
id,
|
|
242
|
+
updateKey: 0,
|
|
243
|
+
transitionStatus: "starting"
|
|
244
|
+
};
|
|
245
|
+
const updatedToasts = [toastToAdd, ...this.state.toasts];
|
|
246
|
+
this.setToasts(applyLimited(updatedToasts, limit));
|
|
247
|
+
const duration = toastToAdd.timeout ?? timeout;
|
|
248
|
+
if (toastToAdd.type !== "loading" && duration > 0) {
|
|
249
|
+
this.scheduleTimer(id, duration, () => this.closeToast(id));
|
|
250
|
+
}
|
|
251
|
+
if (toastSelectors.expandedOrOutOfFocus(this.state)) {
|
|
252
|
+
this.pauseTimers();
|
|
253
|
+
}
|
|
254
|
+
return id;
|
|
255
|
+
};
|
|
256
|
+
updateToast = (id, updates) => {
|
|
257
|
+
this.updateToastInternal(id, updates, { markUpdated: true });
|
|
258
|
+
};
|
|
259
|
+
updateToastInternal = (id, updates, behavior = {}) => {
|
|
260
|
+
const { timeout, toasts } = this.state;
|
|
261
|
+
const prevToast = toastSelectors.toast(this.state, id) ?? null;
|
|
262
|
+
if (!prevToast) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (prevToast.transitionStatus === "ending") {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const nextToast = {
|
|
269
|
+
...prevToast,
|
|
270
|
+
...updates,
|
|
271
|
+
...behavior.markUpdated && {
|
|
272
|
+
updateKey: (prevToast.updateKey ?? 0) + 1
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
this.setToasts(toasts.map((toast) => toast.id === id ? nextToast : toast));
|
|
276
|
+
const nextTimeout = nextToast.timeout ?? timeout;
|
|
277
|
+
const prevTimeout = prevToast?.timeout ?? timeout;
|
|
278
|
+
const timeoutUpdated = Object.hasOwn(updates, "timeout");
|
|
279
|
+
const shouldHaveTimer = nextToast.transitionStatus !== "ending" && nextToast.type !== "loading" && nextTimeout > 0;
|
|
280
|
+
const hasTimer = this.timers.has(id);
|
|
281
|
+
const timeoutChanged = prevTimeout !== nextTimeout;
|
|
282
|
+
const wasLoading = prevToast?.type === "loading";
|
|
283
|
+
if (!shouldHaveTimer && hasTimer) {
|
|
284
|
+
this.clearTimer(id);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (shouldHaveTimer && (!hasTimer || timeoutChanged || timeoutUpdated || wasLoading || behavior.resetTimer)) {
|
|
288
|
+
this.clearTimer(id);
|
|
289
|
+
this.scheduleTimer(id, nextTimeout, () => this.closeToast(id));
|
|
290
|
+
if (toastSelectors.expandedOrOutOfFocus(this.state)) {
|
|
291
|
+
this.pauseTimers();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
closeToast = (toastId) => {
|
|
296
|
+
const closeAll = toastId === void 0;
|
|
297
|
+
const { limit, toasts } = this.state;
|
|
298
|
+
let toastsToClose;
|
|
299
|
+
if (closeAll) {
|
|
300
|
+
toastsToClose = toasts;
|
|
301
|
+
this.clearTimers();
|
|
302
|
+
} else {
|
|
303
|
+
const toast = toastSelectors.toast(this.state, toastId);
|
|
304
|
+
if (!toast) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
toastsToClose = [toast];
|
|
308
|
+
this.clearTimer(toastId);
|
|
309
|
+
}
|
|
310
|
+
const endingToasts = toasts.map(
|
|
311
|
+
(item) => closeAll || item.id === toastId ? { ...item, transitionStatus: "ending", height: 0 } : item
|
|
312
|
+
);
|
|
313
|
+
const newToasts = applyLimited(endingToasts, limit);
|
|
314
|
+
const updates = {
|
|
315
|
+
toasts: newToasts,
|
|
316
|
+
toastMetadata: createToastMetadata(newToasts)
|
|
317
|
+
};
|
|
318
|
+
const hasActiveToasts = newToasts.some((toast) => toast.transitionStatus !== "ending");
|
|
319
|
+
if (!hasActiveToasts) {
|
|
320
|
+
updates.hovering = false;
|
|
321
|
+
updates.focused = false;
|
|
322
|
+
}
|
|
323
|
+
this.update(updates);
|
|
324
|
+
toastsToClose.forEach((toast) => {
|
|
325
|
+
if (toast.transitionStatus !== "ending") {
|
|
326
|
+
toast.onClose?.();
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
this.handleFocusManagement(toastId);
|
|
330
|
+
};
|
|
331
|
+
promiseToast = (promiseValue, options) => {
|
|
332
|
+
const loadingOptions = resolvePromiseOptions(options.loading);
|
|
333
|
+
const id = this.addToast({
|
|
334
|
+
...loadingOptions,
|
|
335
|
+
type: "loading"
|
|
336
|
+
});
|
|
337
|
+
const handledPromise = promiseValue.then((result) => {
|
|
338
|
+
const successOptions = resolvePromiseOptions(options.success, result);
|
|
339
|
+
this.updateToast(id, {
|
|
340
|
+
...successOptions,
|
|
341
|
+
type: "success",
|
|
342
|
+
timeout: successOptions.timeout
|
|
343
|
+
});
|
|
344
|
+
return result;
|
|
345
|
+
}).catch((error) => {
|
|
346
|
+
const errorOptions = resolvePromiseOptions(options.error, error);
|
|
347
|
+
this.updateToast(id, {
|
|
348
|
+
...errorOptions,
|
|
349
|
+
type: "error",
|
|
350
|
+
timeout: errorOptions.timeout
|
|
351
|
+
});
|
|
352
|
+
return Promise.reject(error);
|
|
353
|
+
});
|
|
354
|
+
if ({}.hasOwnProperty.call(options, "setPromise")) {
|
|
355
|
+
options.setPromise(handledPromise);
|
|
356
|
+
}
|
|
357
|
+
return handledPromise;
|
|
358
|
+
};
|
|
359
|
+
pauseTimers() {
|
|
360
|
+
if (this.areTimersPaused) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
this.areTimersPaused = true;
|
|
364
|
+
this.timers.forEach((timer) => {
|
|
365
|
+
if (timer.timeout) {
|
|
366
|
+
timer.timeout.clear();
|
|
367
|
+
const elapsed = Date.now() - timer.start;
|
|
368
|
+
const remaining = timer.delay - elapsed;
|
|
369
|
+
timer.remaining = remaining > 0 ? remaining : 0;
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
resumeTimers() {
|
|
374
|
+
if (!this.areTimersPaused) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
this.areTimersPaused = false;
|
|
378
|
+
this.timers.forEach((timer, id) => {
|
|
379
|
+
timer.remaining = timer.remaining > 0 ? timer.remaining : timer.delay;
|
|
380
|
+
timer.timeout ??= import_useTimeout.Timeout.create();
|
|
381
|
+
timer.timeout.start(timer.remaining, () => {
|
|
382
|
+
this.handleTimerFired(id);
|
|
383
|
+
timer.callback();
|
|
384
|
+
});
|
|
385
|
+
timer.start = Date.now();
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
restoreFocusToPrevElement() {
|
|
389
|
+
this.state.prevFocusElement?.focus({ preventScroll: true });
|
|
390
|
+
}
|
|
391
|
+
handleDocumentPointerDown = (event) => {
|
|
392
|
+
if (event.pointerType !== "touch") {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
const target = (0, import_list_utils.getTarget)(event);
|
|
396
|
+
if ((0, import_element.contains)(this.state.viewport, target)) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
this.resumeTimers();
|
|
400
|
+
this.update({ hovering: false, focused: false });
|
|
401
|
+
};
|
|
402
|
+
scheduleTimer(id, delay, callback) {
|
|
403
|
+
const start = Date.now();
|
|
404
|
+
const shouldStartActive = !toastSelectors.expandedOrOutOfFocus(this.state);
|
|
405
|
+
const currentTimeout = shouldStartActive ? import_useTimeout.Timeout.create() : void 0;
|
|
406
|
+
currentTimeout?.start(delay, () => {
|
|
407
|
+
this.handleTimerFired(id);
|
|
408
|
+
callback();
|
|
409
|
+
});
|
|
410
|
+
this.timers.set(id, {
|
|
411
|
+
timeout: currentTimeout,
|
|
412
|
+
start: shouldStartActive ? start : 0,
|
|
413
|
+
delay,
|
|
414
|
+
remaining: delay,
|
|
415
|
+
callback
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
clearTimers() {
|
|
419
|
+
this.timers.forEach((timer) => {
|
|
420
|
+
timer.timeout?.clear();
|
|
421
|
+
});
|
|
422
|
+
this.timers.clear();
|
|
423
|
+
this.areTimersPaused = false;
|
|
424
|
+
}
|
|
425
|
+
clearTimer(id) {
|
|
426
|
+
const timer = this.timers.get(id);
|
|
427
|
+
timer?.timeout?.clear();
|
|
428
|
+
this.timers.delete(id);
|
|
429
|
+
this.resetPausedStateIfNoTimersRemain();
|
|
430
|
+
}
|
|
431
|
+
handleTimerFired(id) {
|
|
432
|
+
this.timers.delete(id);
|
|
433
|
+
this.resetPausedStateIfNoTimersRemain();
|
|
434
|
+
}
|
|
435
|
+
resetPausedStateIfNoTimersRemain() {
|
|
436
|
+
if (this.timers.size === 0) {
|
|
437
|
+
this.areTimersPaused = false;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
setToasts(newToasts) {
|
|
441
|
+
const updates = {
|
|
442
|
+
toasts: newToasts,
|
|
443
|
+
toastMetadata: createToastMetadata(newToasts)
|
|
444
|
+
};
|
|
445
|
+
if (newToasts.length === 0) {
|
|
446
|
+
updates.hovering = false;
|
|
447
|
+
updates.focused = false;
|
|
448
|
+
}
|
|
449
|
+
this.update(updates);
|
|
450
|
+
}
|
|
451
|
+
handleFocusManagement(toastId) {
|
|
452
|
+
const activeEl = (0, import_element.activeElement)((0, import_owner.ownerDocument)(this.state.viewport));
|
|
453
|
+
if (!this.state.viewport || !(0, import_element.contains)(this.state.viewport, activeEl) || !(0, import_matchesFocusVisible.matchesFocusVisible)(activeEl)) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (toastId === void 0) {
|
|
457
|
+
this.restoreFocusToPrevElement();
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const toasts = toastSelectors.toasts(this.state);
|
|
461
|
+
const currentIndex = toastSelectors.toastIndex(this.state, toastId);
|
|
462
|
+
let nextToast = null;
|
|
463
|
+
let index = currentIndex + 1;
|
|
464
|
+
while (index < toasts.length) {
|
|
465
|
+
if (toasts[index].transitionStatus !== "ending") {
|
|
466
|
+
nextToast = toasts[index];
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
index += 1;
|
|
470
|
+
}
|
|
471
|
+
if (!nextToast) {
|
|
472
|
+
index = currentIndex - 1;
|
|
473
|
+
while (index >= 0) {
|
|
474
|
+
if (toasts[index].transitionStatus !== "ending") {
|
|
475
|
+
nextToast = toasts[index];
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
index -= 1;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
if (nextToast) {
|
|
482
|
+
nextToast.ref?.current?.focus();
|
|
483
|
+
} else {
|
|
484
|
+
this.restoreFocusToPrevElement();
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
function createToastManager() {
|
|
489
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
490
|
+
function emit(data) {
|
|
491
|
+
listeners.forEach((listener) => listener(data));
|
|
492
|
+
}
|
|
493
|
+
return {
|
|
494
|
+
// Private aside from ToastProvider needing to access it.
|
|
495
|
+
" subscribe": function subscribe(listener) {
|
|
496
|
+
listeners.add(listener);
|
|
497
|
+
return () => {
|
|
498
|
+
listeners.delete(listener);
|
|
499
|
+
};
|
|
500
|
+
},
|
|
501
|
+
add(options) {
|
|
502
|
+
const id = options.id || (0, import_generateId.generateId)("toast");
|
|
503
|
+
const toastToAdd = {
|
|
504
|
+
...options,
|
|
505
|
+
id,
|
|
506
|
+
transitionStatus: "starting"
|
|
507
|
+
};
|
|
508
|
+
emit({ action: "add", options: toastToAdd });
|
|
509
|
+
return id;
|
|
510
|
+
},
|
|
511
|
+
close(id) {
|
|
512
|
+
emit({ action: "close", options: { id } });
|
|
513
|
+
},
|
|
514
|
+
update(id, updates) {
|
|
515
|
+
emit({ action: "update", options: { ...updates, id } });
|
|
516
|
+
},
|
|
517
|
+
promise(promiseValue, options) {
|
|
518
|
+
let handledPromise = promiseValue;
|
|
519
|
+
emit({
|
|
520
|
+
action: "promise",
|
|
521
|
+
options: {
|
|
522
|
+
...options,
|
|
523
|
+
promise: promiseValue,
|
|
524
|
+
setPromise(promise) {
|
|
525
|
+
handledPromise = promise;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
return handledPromise;
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
const ToastContext = (0, import_octane.createContext)(void 0);
|
|
534
|
+
function useToastProviderContext() {
|
|
535
|
+
const context = (0, import_octane.useContext)(ToastContext);
|
|
536
|
+
if (!context) {
|
|
537
|
+
throw new Error("Base UI: useToastManager must be used within <Toast.Provider>.");
|
|
538
|
+
}
|
|
539
|
+
return context;
|
|
540
|
+
}
|
|
541
|
+
const ToastRootContext = (0, import_octane.createContext)(void 0);
|
|
542
|
+
function useToastRootContext() {
|
|
543
|
+
const context = (0, import_octane.useContext)(ToastRootContext);
|
|
544
|
+
if (!context) {
|
|
545
|
+
throw new Error(
|
|
546
|
+
"Base UI: ToastRootContext is missing. Toast parts must be used within <Toast.Root>."
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
return context;
|
|
550
|
+
}
|
|
551
|
+
const ToastPositionerContext = (0, import_octane.createContext)(void 0);
|
|
552
|
+
function useToastPositionerContext() {
|
|
553
|
+
const context = (0, import_octane.useContext)(ToastPositionerContext);
|
|
554
|
+
if (context === void 0) {
|
|
555
|
+
throw new Error(
|
|
556
|
+
"Base UI: ToastPositionerContext is missing. ToastPositioner parts must be placed within <Toast.Positioner>."
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
return context;
|
|
560
|
+
}
|
|
561
|
+
function useToastManager(slotArg) {
|
|
562
|
+
const slot = slotArg ?? (0, import_internal.S)("useToastManager");
|
|
563
|
+
const store = (0, import_octane.useContext)(ToastContext);
|
|
564
|
+
if (!store) {
|
|
565
|
+
throw new Error("Base UI: useToastManager must be used within <Toast.Provider>.");
|
|
566
|
+
}
|
|
567
|
+
const toasts = store.useState("toasts", (0, import_internal.subSlot)(slot, "toasts"));
|
|
568
|
+
return (0, import_octane.useMemo)(
|
|
569
|
+
() => ({
|
|
570
|
+
toasts,
|
|
571
|
+
add: store.addToast,
|
|
572
|
+
close: store.closeToast,
|
|
573
|
+
update: store.updateToast,
|
|
574
|
+
promise: store.promiseToast
|
|
575
|
+
}),
|
|
576
|
+
[toasts, store],
|
|
577
|
+
(0, import_internal.subSlot)(slot, "m")
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
function ToastProvider(props) {
|
|
581
|
+
const slot = (0, import_internal.S)("ToastProvider");
|
|
582
|
+
const { children, timeout = 5e3, limit = 3, toastManager } = props;
|
|
583
|
+
const store = (0, import_useRefWithInit.useRefWithInit)(
|
|
584
|
+
() => new ToastStore({
|
|
585
|
+
timeout,
|
|
586
|
+
limit,
|
|
587
|
+
viewport: null,
|
|
588
|
+
toasts: [],
|
|
589
|
+
hovering: false,
|
|
590
|
+
focused: false,
|
|
591
|
+
isWindowFocused: true,
|
|
592
|
+
prevFocusElement: null
|
|
593
|
+
}),
|
|
594
|
+
(0, import_internal.subSlot)(slot, "store")
|
|
595
|
+
).current;
|
|
596
|
+
(0, import_useOnMount.useOnMount)(store.disposeEffect, (0, import_internal.subSlot)(slot, "dispose"));
|
|
597
|
+
(0, import_octane.useEffect)(
|
|
598
|
+
function subscribeToToastManager() {
|
|
599
|
+
if (!toastManager) {
|
|
600
|
+
return void 0;
|
|
601
|
+
}
|
|
602
|
+
const unsubscribe = toastManager[" subscribe"](({ action, options }) => {
|
|
603
|
+
const id = options.id;
|
|
604
|
+
if (action === "promise" && options.promise) {
|
|
605
|
+
store.promiseToast(options.promise, options);
|
|
606
|
+
} else if (action === "update" && id) {
|
|
607
|
+
store.updateToast(id, options);
|
|
608
|
+
} else if (action === "close") {
|
|
609
|
+
store.closeToast(id);
|
|
610
|
+
} else {
|
|
611
|
+
store.addToast(options);
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
return unsubscribe;
|
|
615
|
+
},
|
|
616
|
+
[store, toastManager],
|
|
617
|
+
(0, import_internal.subSlot)(slot, "e:subscribe")
|
|
618
|
+
);
|
|
619
|
+
(0, import_octane.useLayoutEffect)(
|
|
620
|
+
() => {
|
|
621
|
+
store.syncProviderProps({ timeout, limit });
|
|
622
|
+
},
|
|
623
|
+
[store, timeout, limit],
|
|
624
|
+
(0, import_internal.subSlot)(slot, "e:sync")
|
|
625
|
+
);
|
|
626
|
+
return (0, import_octane.createElement)(ToastContext.Provider, { value: store, children });
|
|
627
|
+
}
|
|
628
|
+
function ToastViewport(componentProps) {
|
|
629
|
+
const slot = (0, import_internal.S)("ToastViewport");
|
|
630
|
+
const { render, className, style, children, ref: forwardedRef, ...elementProps } = componentProps;
|
|
631
|
+
const store = useToastProviderContext();
|
|
632
|
+
const windowFocusTimeout = (0, import_useTimeout.useTimeout)((0, import_internal.subSlot)(slot, "wft"));
|
|
633
|
+
const handlingFocusGuardRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "hfg"));
|
|
634
|
+
const markedReadyForMouseLeaveRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "mrml"));
|
|
635
|
+
const touchActiveRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "touch"));
|
|
636
|
+
const isEmpty = store.useState("isEmpty", (0, import_internal.subSlot)(slot, "empty"));
|
|
637
|
+
const toasts = store.useState("toasts", (0, import_internal.subSlot)(slot, "toasts"));
|
|
638
|
+
const focused = store.useState("focused", (0, import_internal.subSlot)(slot, "focused"));
|
|
639
|
+
const expanded = store.useState("expanded", (0, import_internal.subSlot)(slot, "expanded"));
|
|
640
|
+
const prevFocusElement = store.useState("prevFocusElement", (0, import_internal.subSlot)(slot, "prevFocus"));
|
|
641
|
+
const frontmostHeight = toasts[0]?.height ?? 0;
|
|
642
|
+
const hasTransitioningToasts = (0, import_octane.useMemo)(
|
|
643
|
+
() => toasts.some((toast) => toast.transitionStatus === "ending"),
|
|
644
|
+
[toasts],
|
|
645
|
+
(0, import_internal.subSlot)(slot, "transitioning")
|
|
646
|
+
);
|
|
647
|
+
const highPriorityToasts = (0, import_octane.useMemo)(
|
|
648
|
+
() => toasts.filter((toast) => toast.priority === "high"),
|
|
649
|
+
[toasts],
|
|
650
|
+
(0, import_internal.subSlot)(slot, "highPriority")
|
|
651
|
+
);
|
|
652
|
+
(0, import_octane.useEffect)(
|
|
653
|
+
() => {
|
|
654
|
+
const viewport = store.state.viewport;
|
|
655
|
+
if (!viewport) {
|
|
656
|
+
return void 0;
|
|
657
|
+
}
|
|
658
|
+
function handleGlobalKeyDown(event) {
|
|
659
|
+
if (isEmpty) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
if (event.key === "F6" && (0, import_list_utils.getTarget)(event) !== viewport) {
|
|
663
|
+
event.preventDefault();
|
|
664
|
+
store.setPrevFocusElement((0, import_element.activeElement)((0, import_owner.ownerDocument)(viewport)));
|
|
665
|
+
viewport?.focus({ preventScroll: true });
|
|
666
|
+
store.pauseTimers();
|
|
667
|
+
store.setFocused(true);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
const win = (0, import_owner.ownerWindow)(viewport);
|
|
671
|
+
return (0, import_addEventListener.addEventListener)(win, "keydown", handleGlobalKeyDown);
|
|
672
|
+
},
|
|
673
|
+
[store, isEmpty],
|
|
674
|
+
(0, import_internal.subSlot)(slot, "e:f6")
|
|
675
|
+
);
|
|
676
|
+
(0, import_octane.useEffect)(
|
|
677
|
+
() => {
|
|
678
|
+
const viewport = store.state.viewport;
|
|
679
|
+
if (!viewport || isEmpty) {
|
|
680
|
+
return void 0;
|
|
681
|
+
}
|
|
682
|
+
const win = (0, import_owner.ownerWindow)(viewport);
|
|
683
|
+
function handleWindowBlur(event) {
|
|
684
|
+
if ((0, import_list_utils.getTarget)(event) !== win) {
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
store.setIsWindowFocused(false);
|
|
688
|
+
store.pauseTimers();
|
|
689
|
+
}
|
|
690
|
+
function handleWindowFocus(event) {
|
|
691
|
+
if (event.relatedTarget) {
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
const target = (0, import_list_utils.getTarget)(event);
|
|
695
|
+
const activeEl = (0, import_element.activeElement)((0, import_owner.ownerDocument)(viewport));
|
|
696
|
+
if (target === win || !(0, import_element.contains)(viewport, target) || !(0, import_matchesFocusVisible.matchesFocusVisible)(activeEl)) {
|
|
697
|
+
store.resumeTimers();
|
|
698
|
+
}
|
|
699
|
+
windowFocusTimeout.start(0, () => store.setIsWindowFocused(true));
|
|
700
|
+
}
|
|
701
|
+
return (0, import_mergeCleanups.mergeCleanups)(
|
|
702
|
+
(0, import_addEventListener.addEventListener)(win, "blur", handleWindowBlur, true),
|
|
703
|
+
(0, import_addEventListener.addEventListener)(win, "focus", handleWindowFocus, true)
|
|
704
|
+
);
|
|
705
|
+
},
|
|
706
|
+
[
|
|
707
|
+
store,
|
|
708
|
+
windowFocusTimeout,
|
|
709
|
+
// `store.state.viewport` isn't available on the first render, since the portal node
|
|
710
|
+
// hasn't yet been created. This dependency ensures the window listeners are added once
|
|
711
|
+
// toasts have been created and the ref is available.
|
|
712
|
+
isEmpty
|
|
713
|
+
],
|
|
714
|
+
(0, import_internal.subSlot)(slot, "e:window")
|
|
715
|
+
);
|
|
716
|
+
(0, import_octane.useEffect)(
|
|
717
|
+
() => {
|
|
718
|
+
const viewport = store.state.viewport;
|
|
719
|
+
if (!viewport || isEmpty) {
|
|
720
|
+
return void 0;
|
|
721
|
+
}
|
|
722
|
+
const doc = (0, import_owner.ownerDocument)(viewport);
|
|
723
|
+
return (0, import_addEventListener.addEventListener)(doc, "pointerdown", store.handleDocumentPointerDown, true);
|
|
724
|
+
},
|
|
725
|
+
[isEmpty, store],
|
|
726
|
+
(0, import_internal.subSlot)(slot, "e:pointerdown")
|
|
727
|
+
);
|
|
728
|
+
function handleFocusGuard(event) {
|
|
729
|
+
const viewport = store.state.viewport;
|
|
730
|
+
if (!viewport) {
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
handlingFocusGuardRef.current = true;
|
|
734
|
+
if (event.relatedTarget === viewport) {
|
|
735
|
+
const firstFocusableToast = toasts.find(
|
|
736
|
+
(toast) => toast.transitionStatus !== "ending" && !toast.limited
|
|
737
|
+
);
|
|
738
|
+
if (firstFocusableToast) {
|
|
739
|
+
firstFocusableToast.ref?.current?.focus();
|
|
740
|
+
} else {
|
|
741
|
+
store.restoreFocusToPrevElement();
|
|
742
|
+
}
|
|
743
|
+
} else {
|
|
744
|
+
store.restoreFocusToPrevElement();
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
function handleKeyDown(event) {
|
|
748
|
+
if (event.key === "Tab" && event.shiftKey && (0, import_list_utils.getTarget)(event) === store.state.viewport) {
|
|
749
|
+
event.preventDefault();
|
|
750
|
+
store.restoreFocusToPrevElement();
|
|
751
|
+
store.resumeTimers();
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
function flushMouseLeave() {
|
|
755
|
+
const hasEndingToasts = store.state.toasts.some(
|
|
756
|
+
(toast) => toast.transitionStatus === "ending"
|
|
757
|
+
);
|
|
758
|
+
if (hasEndingToasts || touchActiveRef.current || !markedReadyForMouseLeaveRef.current) {
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
if (store.state.isWindowFocused) {
|
|
762
|
+
store.resumeTimers();
|
|
763
|
+
}
|
|
764
|
+
store.setHovering(false);
|
|
765
|
+
markedReadyForMouseLeaveRef.current = false;
|
|
766
|
+
}
|
|
767
|
+
(0, import_octane.useEffect)(flushMouseLeave, [hasTransitioningToasts, store], (0, import_internal.subSlot)(slot, "e:flushLeave"));
|
|
768
|
+
function handleMouseEnter() {
|
|
769
|
+
store.pauseTimers();
|
|
770
|
+
store.setHovering(true);
|
|
771
|
+
markedReadyForMouseLeaveRef.current = false;
|
|
772
|
+
}
|
|
773
|
+
function resumeTimersIfWindowFocused() {
|
|
774
|
+
if (store.state.isWindowFocused) {
|
|
775
|
+
store.resumeTimers();
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
function handleMouseLeave() {
|
|
779
|
+
const hasEndingToasts = store.state.toasts.some(
|
|
780
|
+
(toast) => toast.transitionStatus === "ending"
|
|
781
|
+
);
|
|
782
|
+
if (hasEndingToasts || touchActiveRef.current) {
|
|
783
|
+
markedReadyForMouseLeaveRef.current = true;
|
|
784
|
+
} else {
|
|
785
|
+
resumeTimersIfWindowFocused();
|
|
786
|
+
store.setHovering(false);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
function handlePointerDown(event) {
|
|
790
|
+
if (event.pointerType === "touch") {
|
|
791
|
+
touchActiveRef.current = true;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
function handlePointerEnd(event) {
|
|
795
|
+
if (event.pointerType !== "touch") {
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
touchActiveRef.current = false;
|
|
799
|
+
flushMouseLeave();
|
|
800
|
+
}
|
|
801
|
+
function handleFocus() {
|
|
802
|
+
if (handlingFocusGuardRef.current) {
|
|
803
|
+
handlingFocusGuardRef.current = false;
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
if (focused) {
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
if ((0, import_matchesFocusVisible.matchesFocusVisible)((0, import_element.activeElement)((0, import_owner.ownerDocument)(store.state.viewport)))) {
|
|
810
|
+
store.setFocused(true);
|
|
811
|
+
store.pauseTimers();
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
function handleBlur(event) {
|
|
815
|
+
if (!focused || (0, import_element.contains)(store.state.viewport, event.relatedTarget)) {
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
store.setFocused(false);
|
|
819
|
+
resumeTimersIfWindowFocused();
|
|
820
|
+
}
|
|
821
|
+
const defaultProps = {
|
|
822
|
+
tabIndex: -1,
|
|
823
|
+
role: "region",
|
|
824
|
+
"aria-live": "polite",
|
|
825
|
+
"aria-atomic": false,
|
|
826
|
+
"aria-relevant": "additions text",
|
|
827
|
+
"aria-label": "Notifications",
|
|
828
|
+
onMouseEnter: handleMouseEnter,
|
|
829
|
+
onMouseMove: handleMouseEnter,
|
|
830
|
+
onMouseLeave: handleMouseLeave,
|
|
831
|
+
onFocus: handleFocus,
|
|
832
|
+
onBlur: handleBlur,
|
|
833
|
+
onKeyDown: handleKeyDown,
|
|
834
|
+
onClick: handleFocus,
|
|
835
|
+
onPointerDown: handlePointerDown,
|
|
836
|
+
onPointerUp: handlePointerEnd,
|
|
837
|
+
onPointerCancel: handlePointerEnd
|
|
838
|
+
};
|
|
839
|
+
const state = {
|
|
840
|
+
expanded
|
|
841
|
+
};
|
|
842
|
+
const showGuards = !isEmpty && Boolean(prevFocusElement);
|
|
843
|
+
const element = (0, import_useRenderElement.useRenderElement)(
|
|
844
|
+
"div",
|
|
845
|
+
componentProps,
|
|
846
|
+
{
|
|
847
|
+
ref: [forwardedRef, store.setViewport],
|
|
848
|
+
state,
|
|
849
|
+
props: [
|
|
850
|
+
defaultProps,
|
|
851
|
+
{
|
|
852
|
+
style: {
|
|
853
|
+
[ToastViewportCssVars.frontmostHeight]: frontmostHeight ? `${frontmostHeight}px` : void 0
|
|
854
|
+
}
|
|
855
|
+
},
|
|
856
|
+
elementProps,
|
|
857
|
+
{
|
|
858
|
+
children: [
|
|
859
|
+
showGuards ? (0, import_octane.createElement)(import_FocusGuard.FocusGuard, { key: "guard-in-start", onFocus: handleFocusGuard }) : null,
|
|
860
|
+
(0, import_octane.createElement)(import_octane.Fragment, { key: "children", children }),
|
|
861
|
+
showGuards ? (0, import_octane.createElement)(import_FocusGuard.FocusGuard, { key: "guard-in-end", onFocus: handleFocusGuard }) : null
|
|
862
|
+
]
|
|
863
|
+
}
|
|
864
|
+
]
|
|
865
|
+
},
|
|
866
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
867
|
+
);
|
|
868
|
+
return [
|
|
869
|
+
showGuards ? (0, import_octane.createElement)(import_FocusGuard.FocusGuard, { key: "guard-out-start", onFocus: handleFocusGuard }) : null,
|
|
870
|
+
(0, import_octane.createElement)(import_octane.Fragment, { key: "viewport", children: element }),
|
|
871
|
+
!focused && highPriorityToasts.length > 0 ? (0, import_octane.createElement)("div", {
|
|
872
|
+
key: "live-region",
|
|
873
|
+
style: import_visuallyHidden.visuallyHidden,
|
|
874
|
+
children: highPriorityToasts.map(
|
|
875
|
+
(toast) => (0, import_octane.createElement)("div", {
|
|
876
|
+
key: toast.id,
|
|
877
|
+
role: "alert",
|
|
878
|
+
"aria-atomic": true,
|
|
879
|
+
children: [
|
|
880
|
+
(0, import_octane.createElement)("div", { key: "title", children: toast.title }),
|
|
881
|
+
(0, import_octane.createElement)("div", { key: "description", children: toast.description })
|
|
882
|
+
]
|
|
883
|
+
})
|
|
884
|
+
)
|
|
885
|
+
}) : null
|
|
886
|
+
];
|
|
887
|
+
}
|
|
888
|
+
const toastRootStateAttributesMapping = {
|
|
889
|
+
...import_useTransitionStatus.transitionStatusMapping,
|
|
890
|
+
swipeDirection(value) {
|
|
891
|
+
return value ? { "data-swipe-direction": value } : null;
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
const SWIPE_THRESHOLD = 40;
|
|
895
|
+
const REVERSE_CANCEL_THRESHOLD = 10;
|
|
896
|
+
const OPPOSITE_DIRECTION_DAMPING_FACTOR = 0.5;
|
|
897
|
+
const MIN_DRAG_THRESHOLD = 1;
|
|
898
|
+
const TOAST_SWIPE_IGNORE_SELECTOR = `${import_constants.BASE_UI_SWIPE_IGNORE_SELECTOR},${import_constants.LEGACY_SWIPE_IGNORE_SELECTOR}`;
|
|
899
|
+
function getDisplacement(direction, deltaX, deltaY) {
|
|
900
|
+
switch (direction) {
|
|
901
|
+
case "up":
|
|
902
|
+
return -deltaY;
|
|
903
|
+
case "down":
|
|
904
|
+
return deltaY;
|
|
905
|
+
case "left":
|
|
906
|
+
return -deltaX;
|
|
907
|
+
case "right":
|
|
908
|
+
return deltaX;
|
|
909
|
+
default:
|
|
910
|
+
return 0;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
function getElementTransform(element) {
|
|
914
|
+
const computedStyle = (0, import_owner.ownerWindow)(element).getComputedStyle(element);
|
|
915
|
+
const transform = computedStyle.transform;
|
|
916
|
+
let translateX = 0;
|
|
917
|
+
let translateY = 0;
|
|
918
|
+
let scale = 1;
|
|
919
|
+
if (transform && transform !== "none") {
|
|
920
|
+
const matrix = transform.match(/matrix(?:3d)?\(([^)]+)\)/);
|
|
921
|
+
if (matrix) {
|
|
922
|
+
const values = matrix[1].split(", ").map(parseFloat);
|
|
923
|
+
if (values.length === 6) {
|
|
924
|
+
translateX = values[4];
|
|
925
|
+
translateY = values[5];
|
|
926
|
+
scale = Math.sqrt(values[0] * values[0] + values[1] * values[1]);
|
|
927
|
+
} else if (values.length === 16) {
|
|
928
|
+
translateX = values[12];
|
|
929
|
+
translateY = values[13];
|
|
930
|
+
scale = values[0];
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
return { x: translateX, y: translateY, scale };
|
|
935
|
+
}
|
|
936
|
+
function ToastRoot(componentProps) {
|
|
937
|
+
const slot = (0, import_internal.S)("ToastRoot");
|
|
938
|
+
const {
|
|
939
|
+
toast,
|
|
940
|
+
render,
|
|
941
|
+
className,
|
|
942
|
+
swipeDirection = ["down", "right"],
|
|
943
|
+
style,
|
|
944
|
+
ref: forwardedRef,
|
|
945
|
+
...elementProps
|
|
946
|
+
} = componentProps;
|
|
947
|
+
const isAnchored = toast.positionerProps?.anchor !== void 0;
|
|
948
|
+
let swipeDirections = [];
|
|
949
|
+
if (!isAnchored) {
|
|
950
|
+
swipeDirections = Array.isArray(swipeDirection) ? swipeDirection : [swipeDirection];
|
|
951
|
+
}
|
|
952
|
+
const swipeEnabled = swipeDirections.length > 0;
|
|
953
|
+
const store = useToastProviderContext();
|
|
954
|
+
const [currentSwipeDirection, setCurrentSwipeDirection] = (0, import_octane.useState)(
|
|
955
|
+
void 0,
|
|
956
|
+
(0, import_internal.subSlot)(slot, "csd")
|
|
957
|
+
);
|
|
958
|
+
const [isSwiping, setIsSwiping] = (0, import_octane.useState)(false, (0, import_internal.subSlot)(slot, "swiping"));
|
|
959
|
+
const [isRealSwipe, setIsRealSwipe] = (0, import_octane.useState)(false, (0, import_internal.subSlot)(slot, "realSwipe"));
|
|
960
|
+
const [dragDismissed, setDragDismissed] = (0, import_octane.useState)(false, (0, import_internal.subSlot)(slot, "dismissed"));
|
|
961
|
+
const [dragOffset, setDragOffset] = (0, import_octane.useState)({ x: 0, y: 0 }, (0, import_internal.subSlot)(slot, "offset"));
|
|
962
|
+
const [initialTransform, setInitialTransform] = (0, import_octane.useState)(
|
|
963
|
+
{ x: 0, y: 0, scale: 1 },
|
|
964
|
+
(0, import_internal.subSlot)(slot, "initTransform")
|
|
965
|
+
);
|
|
966
|
+
const [titleId, setTitleId] = (0, import_octane.useState)(void 0, (0, import_internal.subSlot)(slot, "titleId"));
|
|
967
|
+
const [descriptionId, setDescriptionId] = (0, import_octane.useState)(
|
|
968
|
+
void 0,
|
|
969
|
+
(0, import_internal.subSlot)(slot, "descId")
|
|
970
|
+
);
|
|
971
|
+
const [lockedDirection, setLockedDirection] = (0, import_octane.useState)(
|
|
972
|
+
null,
|
|
973
|
+
(0, import_internal.subSlot)(slot, "locked")
|
|
974
|
+
);
|
|
975
|
+
const rootRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "root"));
|
|
976
|
+
const dragStartPosRef = (0, import_octane.useRef)({ x: 0, y: 0 }, (0, import_internal.subSlot)(slot, "dragStart"));
|
|
977
|
+
const initialTransformRef = (0, import_octane.useRef)({ x: 0, y: 0, scale: 1 }, (0, import_internal.subSlot)(slot, "itRef"));
|
|
978
|
+
const intendedSwipeDirectionRef = (0, import_octane.useRef)(
|
|
979
|
+
void 0,
|
|
980
|
+
(0, import_internal.subSlot)(slot, "intended")
|
|
981
|
+
);
|
|
982
|
+
const maxSwipeDisplacementRef = (0, import_octane.useRef)(0, (0, import_internal.subSlot)(slot, "maxDisp"));
|
|
983
|
+
const cancelledSwipeRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "cancelled"));
|
|
984
|
+
const swipeCancelBaselineRef = (0, import_octane.useRef)({ x: 0, y: 0 }, (0, import_internal.subSlot)(slot, "baseline"));
|
|
985
|
+
const isFirstPointerMoveRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "firstMove"));
|
|
986
|
+
const dragOffsetRef = (0, import_octane.useRef)({ x: 0, y: 0 }, (0, import_internal.subSlot)(slot, "offsetRef"));
|
|
987
|
+
const activePointerIdRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "pointerId"));
|
|
988
|
+
const dragAbortControllerRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "abort"));
|
|
989
|
+
const domIndex = store.useState("toastIndex", (0, import_internal.subSlot)(slot, "domIndex"), toast.id);
|
|
990
|
+
const visibleIndex = store.useState("toastVisibleIndex", (0, import_internal.subSlot)(slot, "visIndex"), toast.id);
|
|
991
|
+
const offsetY = store.useState("toastOffsetY", (0, import_internal.subSlot)(slot, "offsetY"), toast.id);
|
|
992
|
+
const focused = store.useState("focused", (0, import_internal.subSlot)(slot, "focused"));
|
|
993
|
+
const expanded = store.useState("expanded", (0, import_internal.subSlot)(slot, "expanded"));
|
|
994
|
+
(0, import_useOpenChangeComplete.useOpenChangeComplete)(
|
|
995
|
+
{
|
|
996
|
+
open: toast.transitionStatus !== "ending",
|
|
997
|
+
ref: rootRef,
|
|
998
|
+
onComplete() {
|
|
999
|
+
if (toast.transitionStatus === "ending") {
|
|
1000
|
+
store.removeToast(toast.id);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
},
|
|
1004
|
+
(0, import_internal.subSlot)(slot, "occ")
|
|
1005
|
+
);
|
|
1006
|
+
const recalculateHeight = (0, import_useStableCallback.useStableCallback)(
|
|
1007
|
+
(shouldFlush = false) => {
|
|
1008
|
+
const element2 = rootRef.current;
|
|
1009
|
+
if (!element2) {
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
const previousHeight = element2.style.height;
|
|
1013
|
+
element2.style.height = "auto";
|
|
1014
|
+
const height = element2.offsetHeight;
|
|
1015
|
+
element2.style.height = previousHeight;
|
|
1016
|
+
function update() {
|
|
1017
|
+
store.updateToastInternal(toast.id, {
|
|
1018
|
+
ref: rootRef,
|
|
1019
|
+
height,
|
|
1020
|
+
...toast.transitionStatus === "starting" ? { transitionStatus: void 0 } : {}
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
if (shouldFlush) {
|
|
1024
|
+
(0, import_octane.flushSync)(update);
|
|
1025
|
+
} else {
|
|
1026
|
+
update();
|
|
1027
|
+
}
|
|
1028
|
+
},
|
|
1029
|
+
(0, import_internal.subSlot)(slot, "recalc")
|
|
1030
|
+
);
|
|
1031
|
+
(0, import_octane.useLayoutEffect)(recalculateHeight, [recalculateHeight], (0, import_internal.subSlot)(slot, "e:recalc"));
|
|
1032
|
+
function setResolvedDragOffset(nextDragOffset) {
|
|
1033
|
+
dragOffsetRef.current = nextDragOffset;
|
|
1034
|
+
setDragOffset(nextDragOffset);
|
|
1035
|
+
}
|
|
1036
|
+
(0, import_octane.useLayoutEffect)(
|
|
1037
|
+
() => {
|
|
1038
|
+
return () => {
|
|
1039
|
+
dragAbortControllerRef.current?.abort();
|
|
1040
|
+
};
|
|
1041
|
+
},
|
|
1042
|
+
[],
|
|
1043
|
+
(0, import_internal.subSlot)(slot, "e:abort")
|
|
1044
|
+
);
|
|
1045
|
+
function applyDirectionalDamping(deltaX, deltaY) {
|
|
1046
|
+
let newDeltaX = deltaX;
|
|
1047
|
+
let newDeltaY = deltaY;
|
|
1048
|
+
if (!swipeDirections.includes("left") && !swipeDirections.includes("right")) {
|
|
1049
|
+
newDeltaX = deltaX > 0 ? deltaX ** OPPOSITE_DIRECTION_DAMPING_FACTOR : -(Math.abs(deltaX) ** OPPOSITE_DIRECTION_DAMPING_FACTOR);
|
|
1050
|
+
} else {
|
|
1051
|
+
if (!swipeDirections.includes("right") && deltaX > 0) {
|
|
1052
|
+
newDeltaX = deltaX ** OPPOSITE_DIRECTION_DAMPING_FACTOR;
|
|
1053
|
+
}
|
|
1054
|
+
if (!swipeDirections.includes("left") && deltaX < 0) {
|
|
1055
|
+
newDeltaX = -(Math.abs(deltaX) ** OPPOSITE_DIRECTION_DAMPING_FACTOR);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
if (!swipeDirections.includes("up") && !swipeDirections.includes("down")) {
|
|
1059
|
+
newDeltaY = deltaY > 0 ? deltaY ** OPPOSITE_DIRECTION_DAMPING_FACTOR : -(Math.abs(deltaY) ** OPPOSITE_DIRECTION_DAMPING_FACTOR);
|
|
1060
|
+
} else {
|
|
1061
|
+
if (!swipeDirections.includes("down") && deltaY > 0) {
|
|
1062
|
+
newDeltaY = deltaY ** OPPOSITE_DIRECTION_DAMPING_FACTOR;
|
|
1063
|
+
}
|
|
1064
|
+
if (!swipeDirections.includes("up") && deltaY < 0) {
|
|
1065
|
+
newDeltaY = -(Math.abs(deltaY) ** OPPOSITE_DIRECTION_DAMPING_FACTOR);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
return { x: newDeltaX, y: newDeltaY };
|
|
1069
|
+
}
|
|
1070
|
+
const handleSwipeEnd = (0, import_useStableCallback.useStableCallback)(
|
|
1071
|
+
(event) => {
|
|
1072
|
+
if (event.pointerId !== activePointerIdRef.current) {
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
activePointerIdRef.current = null;
|
|
1076
|
+
dragAbortControllerRef.current?.abort();
|
|
1077
|
+
dragAbortControllerRef.current = null;
|
|
1078
|
+
setIsSwiping(false);
|
|
1079
|
+
setIsRealSwipe(false);
|
|
1080
|
+
setLockedDirection(null);
|
|
1081
|
+
const resolvedInitialTransform = initialTransformRef.current;
|
|
1082
|
+
if (event.type === "pointercancel" || cancelledSwipeRef.current) {
|
|
1083
|
+
setResolvedDragOffset({ x: resolvedInitialTransform.x, y: resolvedInitialTransform.y });
|
|
1084
|
+
setCurrentSwipeDirection(void 0);
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
let shouldClose = false;
|
|
1088
|
+
const resolvedDragOffset = dragOffsetRef.current;
|
|
1089
|
+
const deltaX = resolvedDragOffset.x - resolvedInitialTransform.x;
|
|
1090
|
+
const deltaY = resolvedDragOffset.y - resolvedInitialTransform.y;
|
|
1091
|
+
let dismissDirection;
|
|
1092
|
+
for (const direction of swipeDirections) {
|
|
1093
|
+
switch (direction) {
|
|
1094
|
+
case "right":
|
|
1095
|
+
if (deltaX > SWIPE_THRESHOLD) {
|
|
1096
|
+
shouldClose = true;
|
|
1097
|
+
dismissDirection = "right";
|
|
1098
|
+
}
|
|
1099
|
+
break;
|
|
1100
|
+
case "left":
|
|
1101
|
+
if (deltaX < -SWIPE_THRESHOLD) {
|
|
1102
|
+
shouldClose = true;
|
|
1103
|
+
dismissDirection = "left";
|
|
1104
|
+
}
|
|
1105
|
+
break;
|
|
1106
|
+
case "down":
|
|
1107
|
+
if (deltaY > SWIPE_THRESHOLD) {
|
|
1108
|
+
shouldClose = true;
|
|
1109
|
+
dismissDirection = "down";
|
|
1110
|
+
}
|
|
1111
|
+
break;
|
|
1112
|
+
case "up":
|
|
1113
|
+
if (deltaY < -SWIPE_THRESHOLD) {
|
|
1114
|
+
shouldClose = true;
|
|
1115
|
+
dismissDirection = "up";
|
|
1116
|
+
}
|
|
1117
|
+
break;
|
|
1118
|
+
default:
|
|
1119
|
+
break;
|
|
1120
|
+
}
|
|
1121
|
+
if (shouldClose) {
|
|
1122
|
+
break;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
if (shouldClose) {
|
|
1126
|
+
setCurrentSwipeDirection(dismissDirection);
|
|
1127
|
+
setDragDismissed(true);
|
|
1128
|
+
store.closeToast(toast.id);
|
|
1129
|
+
} else {
|
|
1130
|
+
setResolvedDragOffset({ x: resolvedInitialTransform.x, y: resolvedInitialTransform.y });
|
|
1131
|
+
setCurrentSwipeDirection(void 0);
|
|
1132
|
+
}
|
|
1133
|
+
},
|
|
1134
|
+
(0, import_internal.subSlot)(slot, "swipeEnd")
|
|
1135
|
+
);
|
|
1136
|
+
function handlePointerDown(event) {
|
|
1137
|
+
if (event.button !== 0) {
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
if (event.pointerType === "touch") {
|
|
1141
|
+
store.pauseTimers();
|
|
1142
|
+
}
|
|
1143
|
+
const target = (0, import_list_utils.getTarget)(event);
|
|
1144
|
+
const isInteractiveElement = target ? target.closest(`button,a,input,textarea,[role="button"],${TOAST_SWIPE_IGNORE_SELECTOR}`) : false;
|
|
1145
|
+
if (isInteractiveElement) {
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
cancelledSwipeRef.current = false;
|
|
1149
|
+
intendedSwipeDirectionRef.current = void 0;
|
|
1150
|
+
maxSwipeDisplacementRef.current = 0;
|
|
1151
|
+
activePointerIdRef.current = event.pointerId;
|
|
1152
|
+
dragStartPosRef.current = { x: event.clientX, y: event.clientY };
|
|
1153
|
+
swipeCancelBaselineRef.current = dragStartPosRef.current;
|
|
1154
|
+
if (rootRef.current) {
|
|
1155
|
+
const transform = getElementTransform(rootRef.current);
|
|
1156
|
+
initialTransformRef.current = transform;
|
|
1157
|
+
setInitialTransform(transform);
|
|
1158
|
+
setResolvedDragOffset({
|
|
1159
|
+
x: transform.x,
|
|
1160
|
+
y: transform.y
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
store.setHovering(true);
|
|
1164
|
+
setIsSwiping(true);
|
|
1165
|
+
setIsRealSwipe(false);
|
|
1166
|
+
setLockedDirection(null);
|
|
1167
|
+
isFirstPointerMoveRef.current = true;
|
|
1168
|
+
const element2 = rootRef.current;
|
|
1169
|
+
if (element2) {
|
|
1170
|
+
dragAbortControllerRef.current?.abort();
|
|
1171
|
+
const dragAbortController = new AbortController();
|
|
1172
|
+
dragAbortControllerRef.current = dragAbortController;
|
|
1173
|
+
const doc = (0, import_owner.ownerDocument)(element2);
|
|
1174
|
+
doc.addEventListener("pointerup", handleSwipeEnd, {
|
|
1175
|
+
signal: dragAbortController.signal
|
|
1176
|
+
});
|
|
1177
|
+
doc.addEventListener("pointercancel", handleSwipeEnd, {
|
|
1178
|
+
signal: dragAbortController.signal
|
|
1179
|
+
});
|
|
1180
|
+
element2.setPointerCapture?.(event.pointerId);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
function handlePointerMove(event) {
|
|
1184
|
+
if (event.pointerId !== activePointerIdRef.current) {
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
event.preventDefault();
|
|
1188
|
+
if (isFirstPointerMoveRef.current) {
|
|
1189
|
+
dragStartPosRef.current = { x: event.clientX, y: event.clientY };
|
|
1190
|
+
isFirstPointerMoveRef.current = false;
|
|
1191
|
+
}
|
|
1192
|
+
const { clientY, clientX, movementX, movementY } = event;
|
|
1193
|
+
if (movementY < 0 && clientY > swipeCancelBaselineRef.current.y || movementY > 0 && clientY < swipeCancelBaselineRef.current.y) {
|
|
1194
|
+
swipeCancelBaselineRef.current = { x: swipeCancelBaselineRef.current.x, y: clientY };
|
|
1195
|
+
}
|
|
1196
|
+
if (movementX < 0 && clientX > swipeCancelBaselineRef.current.x || movementX > 0 && clientX < swipeCancelBaselineRef.current.x) {
|
|
1197
|
+
swipeCancelBaselineRef.current = { x: clientX, y: swipeCancelBaselineRef.current.y };
|
|
1198
|
+
}
|
|
1199
|
+
const deltaX = clientX - dragStartPosRef.current.x;
|
|
1200
|
+
const deltaY = clientY - dragStartPosRef.current.y;
|
|
1201
|
+
const cancelDeltaY = clientY - swipeCancelBaselineRef.current.y;
|
|
1202
|
+
const cancelDeltaX = clientX - swipeCancelBaselineRef.current.x;
|
|
1203
|
+
if (!isRealSwipe) {
|
|
1204
|
+
const movementDistance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
1205
|
+
if (movementDistance >= MIN_DRAG_THRESHOLD) {
|
|
1206
|
+
setIsRealSwipe(true);
|
|
1207
|
+
if (lockedDirection === null) {
|
|
1208
|
+
const hasHorizontal = swipeDirections.includes("left") || swipeDirections.includes("right");
|
|
1209
|
+
const hasVertical = swipeDirections.includes("up") || swipeDirections.includes("down");
|
|
1210
|
+
if (hasHorizontal && hasVertical) {
|
|
1211
|
+
const absX = Math.abs(deltaX);
|
|
1212
|
+
const absY = Math.abs(deltaY);
|
|
1213
|
+
setLockedDirection(absX > absY ? "horizontal" : "vertical");
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
let candidate;
|
|
1219
|
+
if (!intendedSwipeDirectionRef.current) {
|
|
1220
|
+
if (lockedDirection === "vertical") {
|
|
1221
|
+
if (deltaY > 0) {
|
|
1222
|
+
candidate = "down";
|
|
1223
|
+
} else if (deltaY < 0) {
|
|
1224
|
+
candidate = "up";
|
|
1225
|
+
}
|
|
1226
|
+
} else if (lockedDirection === "horizontal") {
|
|
1227
|
+
if (deltaX > 0) {
|
|
1228
|
+
candidate = "right";
|
|
1229
|
+
} else if (deltaX < 0) {
|
|
1230
|
+
candidate = "left";
|
|
1231
|
+
}
|
|
1232
|
+
} else if (Math.abs(deltaX) >= Math.abs(deltaY)) {
|
|
1233
|
+
candidate = deltaX > 0 ? "right" : "left";
|
|
1234
|
+
} else {
|
|
1235
|
+
candidate = deltaY > 0 ? "down" : "up";
|
|
1236
|
+
}
|
|
1237
|
+
if (candidate && swipeDirections.includes(candidate)) {
|
|
1238
|
+
intendedSwipeDirectionRef.current = candidate;
|
|
1239
|
+
maxSwipeDisplacementRef.current = getDisplacement(candidate, deltaX, deltaY);
|
|
1240
|
+
setCurrentSwipeDirection(candidate);
|
|
1241
|
+
}
|
|
1242
|
+
} else {
|
|
1243
|
+
const direction = intendedSwipeDirectionRef.current;
|
|
1244
|
+
const currentDisplacement = getDisplacement(direction, cancelDeltaX, cancelDeltaY);
|
|
1245
|
+
if (currentDisplacement > SWIPE_THRESHOLD) {
|
|
1246
|
+
cancelledSwipeRef.current = false;
|
|
1247
|
+
setCurrentSwipeDirection(direction);
|
|
1248
|
+
} else if (!(swipeDirections.includes("left") && swipeDirections.includes("right")) && !(swipeDirections.includes("up") && swipeDirections.includes("down")) && maxSwipeDisplacementRef.current - currentDisplacement >= REVERSE_CANCEL_THRESHOLD) {
|
|
1249
|
+
cancelledSwipeRef.current = true;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
const dampedDelta = applyDirectionalDamping(deltaX, deltaY);
|
|
1253
|
+
let newOffsetX = initialTransformRef.current.x;
|
|
1254
|
+
let newOffsetY = initialTransformRef.current.y;
|
|
1255
|
+
if (lockedDirection === "horizontal") {
|
|
1256
|
+
if (swipeDirections.includes("left") || swipeDirections.includes("right")) {
|
|
1257
|
+
newOffsetX += dampedDelta.x;
|
|
1258
|
+
}
|
|
1259
|
+
} else if (lockedDirection === "vertical") {
|
|
1260
|
+
if (swipeDirections.includes("up") || swipeDirections.includes("down")) {
|
|
1261
|
+
newOffsetY += dampedDelta.y;
|
|
1262
|
+
}
|
|
1263
|
+
} else {
|
|
1264
|
+
if (swipeDirections.includes("left") || swipeDirections.includes("right")) {
|
|
1265
|
+
newOffsetX += dampedDelta.x;
|
|
1266
|
+
}
|
|
1267
|
+
if (swipeDirections.includes("up") || swipeDirections.includes("down")) {
|
|
1268
|
+
newOffsetY += dampedDelta.y;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
setResolvedDragOffset({ x: newOffsetX, y: newOffsetY });
|
|
1272
|
+
}
|
|
1273
|
+
function handleKeyDown(event) {
|
|
1274
|
+
if (event.key === "Escape") {
|
|
1275
|
+
if (!rootRef.current || !(0, import_element.contains)(rootRef.current, (0, import_element.activeElement)((0, import_owner.ownerDocument)(rootRef.current)))) {
|
|
1276
|
+
return;
|
|
1277
|
+
}
|
|
1278
|
+
store.closeToast(toast.id);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
(0, import_octane.useEffect)(
|
|
1282
|
+
() => {
|
|
1283
|
+
if (!swipeEnabled) {
|
|
1284
|
+
return void 0;
|
|
1285
|
+
}
|
|
1286
|
+
const element2 = rootRef.current;
|
|
1287
|
+
if (!element2) {
|
|
1288
|
+
return void 0;
|
|
1289
|
+
}
|
|
1290
|
+
function preventDefaultTouchStart(event) {
|
|
1291
|
+
if (activePointerIdRef.current === null || !(0, import_element.contains)(element2, (0, import_list_utils.getTarget)(event))) {
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
event.preventDefault();
|
|
1295
|
+
}
|
|
1296
|
+
return (0, import_addEventListener.addEventListener)(element2, "touchmove", preventDefaultTouchStart, {
|
|
1297
|
+
passive: false
|
|
1298
|
+
});
|
|
1299
|
+
},
|
|
1300
|
+
[swipeEnabled],
|
|
1301
|
+
(0, import_internal.subSlot)(slot, "e:touchmove")
|
|
1302
|
+
);
|
|
1303
|
+
function getDragStyles() {
|
|
1304
|
+
if (!isSwiping && dragOffset.x === initialTransform.x && dragOffset.y === initialTransform.y && !dragDismissed) {
|
|
1305
|
+
return {
|
|
1306
|
+
[ToastRootCssVars.swipeMovementX]: "0px",
|
|
1307
|
+
[ToastRootCssVars.swipeMovementY]: "0px"
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
const deltaX = dragOffset.x - initialTransform.x;
|
|
1311
|
+
const deltaY = dragOffset.y - initialTransform.y;
|
|
1312
|
+
return {
|
|
1313
|
+
transition: isSwiping ? "none" : void 0,
|
|
1314
|
+
// While swiping, freeze the element at its current visual transform so it doesn't snap
|
|
1315
|
+
// to the end position.
|
|
1316
|
+
transform: isSwiping ? `translateX(${dragOffset.x}px) translateY(${dragOffset.y}px) scale(${initialTransform.scale})` : void 0,
|
|
1317
|
+
[ToastRootCssVars.swipeMovementX]: `${deltaX}px`,
|
|
1318
|
+
[ToastRootCssVars.swipeMovementY]: `${deltaY}px`
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
const isHighPriority = toast.priority === "high";
|
|
1322
|
+
const defaultProps = {
|
|
1323
|
+
role: isHighPriority ? "alertdialog" : "dialog",
|
|
1324
|
+
tabIndex: 0,
|
|
1325
|
+
"aria-modal": false,
|
|
1326
|
+
"aria-labelledby": titleId,
|
|
1327
|
+
"aria-describedby": descriptionId,
|
|
1328
|
+
"aria-hidden": isHighPriority && !focused ? true : void 0,
|
|
1329
|
+
onPointerDown: swipeEnabled ? handlePointerDown : void 0,
|
|
1330
|
+
onPointerMove: swipeEnabled ? handlePointerMove : void 0,
|
|
1331
|
+
onPointerUp: swipeEnabled ? handleSwipeEnd : void 0,
|
|
1332
|
+
onPointerCancel: swipeEnabled ? handleSwipeEnd : void 0,
|
|
1333
|
+
onKeyDown: handleKeyDown,
|
|
1334
|
+
inert: (0, import_inertValue.inertValue)(toast.limited),
|
|
1335
|
+
style: {
|
|
1336
|
+
...getDragStyles(),
|
|
1337
|
+
[ToastRootCssVars.index]: toast.transitionStatus === "ending" ? domIndex : visibleIndex,
|
|
1338
|
+
[ToastRootCssVars.offsetY]: `${offsetY}px`,
|
|
1339
|
+
[ToastRootCssVars.height]: toast.height ? `${toast.height}px` : void 0
|
|
1340
|
+
}
|
|
1341
|
+
};
|
|
1342
|
+
const toastRoot = (0, import_octane.useMemo)(
|
|
1343
|
+
() => ({
|
|
1344
|
+
rootRef,
|
|
1345
|
+
toast,
|
|
1346
|
+
titleId,
|
|
1347
|
+
setTitleId,
|
|
1348
|
+
descriptionId,
|
|
1349
|
+
setDescriptionId,
|
|
1350
|
+
swiping: isSwiping,
|
|
1351
|
+
swipeDirection: currentSwipeDirection,
|
|
1352
|
+
recalculateHeight,
|
|
1353
|
+
index: domIndex,
|
|
1354
|
+
visibleIndex,
|
|
1355
|
+
expanded
|
|
1356
|
+
}),
|
|
1357
|
+
[
|
|
1358
|
+
toast,
|
|
1359
|
+
titleId,
|
|
1360
|
+
descriptionId,
|
|
1361
|
+
isSwiping,
|
|
1362
|
+
currentSwipeDirection,
|
|
1363
|
+
recalculateHeight,
|
|
1364
|
+
domIndex,
|
|
1365
|
+
visibleIndex,
|
|
1366
|
+
expanded
|
|
1367
|
+
],
|
|
1368
|
+
(0, import_internal.subSlot)(slot, "ctx")
|
|
1369
|
+
);
|
|
1370
|
+
const state = {
|
|
1371
|
+
transitionStatus: toast.transitionStatus,
|
|
1372
|
+
expanded,
|
|
1373
|
+
limited: toast.limited || false,
|
|
1374
|
+
type: toast.type,
|
|
1375
|
+
swiping: toastRoot.swiping,
|
|
1376
|
+
swipeDirection: toastRoot.swipeDirection
|
|
1377
|
+
};
|
|
1378
|
+
const element = (0, import_useRenderElement.useRenderElement)(
|
|
1379
|
+
"div",
|
|
1380
|
+
componentProps,
|
|
1381
|
+
{
|
|
1382
|
+
ref: [forwardedRef, toastRoot.rootRef],
|
|
1383
|
+
state,
|
|
1384
|
+
stateAttributesMapping: toastRootStateAttributesMapping,
|
|
1385
|
+
props: [defaultProps, elementProps]
|
|
1386
|
+
},
|
|
1387
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
1388
|
+
);
|
|
1389
|
+
return (0, import_octane.createElement)(ToastRootContext.Provider, { value: toastRoot, children: element });
|
|
1390
|
+
}
|
|
1391
|
+
function ToastTitle(componentProps) {
|
|
1392
|
+
const slot = (0, import_internal.S)("ToastTitle");
|
|
1393
|
+
const {
|
|
1394
|
+
render,
|
|
1395
|
+
className,
|
|
1396
|
+
style,
|
|
1397
|
+
id: idProp,
|
|
1398
|
+
children: childrenProp,
|
|
1399
|
+
ref: forwardedRef,
|
|
1400
|
+
...elementProps
|
|
1401
|
+
} = componentProps;
|
|
1402
|
+
const { toast, setTitleId } = useToastRootContext();
|
|
1403
|
+
const children = childrenProp ?? toast.title;
|
|
1404
|
+
const shouldRender = Boolean(children);
|
|
1405
|
+
const generatedId = (0, import_octane.useId)((0, import_internal.subSlot)(slot, "id"));
|
|
1406
|
+
const id = idProp ?? generatedId;
|
|
1407
|
+
(0, import_octane.useLayoutEffect)(
|
|
1408
|
+
() => {
|
|
1409
|
+
if (!shouldRender) {
|
|
1410
|
+
return void 0;
|
|
1411
|
+
}
|
|
1412
|
+
setTitleId(id);
|
|
1413
|
+
return () => {
|
|
1414
|
+
setTitleId(void 0);
|
|
1415
|
+
};
|
|
1416
|
+
},
|
|
1417
|
+
[shouldRender, id, setTitleId],
|
|
1418
|
+
(0, import_internal.subSlot)(slot, "e")
|
|
1419
|
+
);
|
|
1420
|
+
const state = {
|
|
1421
|
+
type: toast.type
|
|
1422
|
+
};
|
|
1423
|
+
const element = (0, import_useRenderElement.useRenderElement)(
|
|
1424
|
+
"h2",
|
|
1425
|
+
componentProps,
|
|
1426
|
+
{
|
|
1427
|
+
ref: forwardedRef,
|
|
1428
|
+
state,
|
|
1429
|
+
props: {
|
|
1430
|
+
...elementProps,
|
|
1431
|
+
id,
|
|
1432
|
+
children
|
|
1433
|
+
}
|
|
1434
|
+
},
|
|
1435
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
1436
|
+
);
|
|
1437
|
+
if (!shouldRender) {
|
|
1438
|
+
return null;
|
|
1439
|
+
}
|
|
1440
|
+
return element;
|
|
1441
|
+
}
|
|
1442
|
+
function ToastDescription(componentProps) {
|
|
1443
|
+
const slot = (0, import_internal.S)("ToastDescription");
|
|
1444
|
+
const {
|
|
1445
|
+
render,
|
|
1446
|
+
className,
|
|
1447
|
+
style,
|
|
1448
|
+
id: idProp,
|
|
1449
|
+
children: childrenProp,
|
|
1450
|
+
ref: forwardedRef,
|
|
1451
|
+
...elementProps
|
|
1452
|
+
} = componentProps;
|
|
1453
|
+
const { toast, setDescriptionId } = useToastRootContext();
|
|
1454
|
+
const children = childrenProp ?? toast.description;
|
|
1455
|
+
const shouldRender = Boolean(children);
|
|
1456
|
+
const generatedId = (0, import_octane.useId)((0, import_internal.subSlot)(slot, "id"));
|
|
1457
|
+
const id = idProp ?? generatedId;
|
|
1458
|
+
(0, import_octane.useLayoutEffect)(
|
|
1459
|
+
() => {
|
|
1460
|
+
if (!shouldRender) {
|
|
1461
|
+
return void 0;
|
|
1462
|
+
}
|
|
1463
|
+
setDescriptionId(id);
|
|
1464
|
+
return () => {
|
|
1465
|
+
setDescriptionId(void 0);
|
|
1466
|
+
};
|
|
1467
|
+
},
|
|
1468
|
+
[shouldRender, id, setDescriptionId],
|
|
1469
|
+
(0, import_internal.subSlot)(slot, "e")
|
|
1470
|
+
);
|
|
1471
|
+
const state = {
|
|
1472
|
+
type: toast.type
|
|
1473
|
+
};
|
|
1474
|
+
const element = (0, import_useRenderElement.useRenderElement)(
|
|
1475
|
+
"p",
|
|
1476
|
+
componentProps,
|
|
1477
|
+
{
|
|
1478
|
+
ref: forwardedRef,
|
|
1479
|
+
state,
|
|
1480
|
+
props: {
|
|
1481
|
+
...elementProps,
|
|
1482
|
+
id,
|
|
1483
|
+
children
|
|
1484
|
+
}
|
|
1485
|
+
},
|
|
1486
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
1487
|
+
);
|
|
1488
|
+
if (!shouldRender) {
|
|
1489
|
+
return null;
|
|
1490
|
+
}
|
|
1491
|
+
return element;
|
|
1492
|
+
}
|
|
1493
|
+
function ToastContent(componentProps) {
|
|
1494
|
+
const slot = (0, import_internal.S)("ToastContent");
|
|
1495
|
+
const { render, className, style, ref: forwardedRef, ...elementProps } = componentProps;
|
|
1496
|
+
const { visibleIndex, expanded, recalculateHeight } = useToastRootContext();
|
|
1497
|
+
const contentRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "content"));
|
|
1498
|
+
(0, import_octane.useLayoutEffect)(
|
|
1499
|
+
() => {
|
|
1500
|
+
const node = contentRef.current;
|
|
1501
|
+
if (!node) {
|
|
1502
|
+
return void 0;
|
|
1503
|
+
}
|
|
1504
|
+
recalculateHeight();
|
|
1505
|
+
if (typeof ResizeObserver !== "function" || typeof MutationObserver !== "function") {
|
|
1506
|
+
return void 0;
|
|
1507
|
+
}
|
|
1508
|
+
const resizeObserver = new ResizeObserver(() => recalculateHeight(true));
|
|
1509
|
+
const mutationObserver = new MutationObserver(() => recalculateHeight(true));
|
|
1510
|
+
resizeObserver.observe(node);
|
|
1511
|
+
mutationObserver.observe(node, { childList: true, subtree: true, characterData: true });
|
|
1512
|
+
return () => {
|
|
1513
|
+
resizeObserver.disconnect();
|
|
1514
|
+
mutationObserver.disconnect();
|
|
1515
|
+
};
|
|
1516
|
+
},
|
|
1517
|
+
[recalculateHeight],
|
|
1518
|
+
(0, import_internal.subSlot)(slot, "e")
|
|
1519
|
+
);
|
|
1520
|
+
const behind = visibleIndex > 0;
|
|
1521
|
+
const state = {
|
|
1522
|
+
expanded,
|
|
1523
|
+
behind
|
|
1524
|
+
};
|
|
1525
|
+
return (0, import_useRenderElement.useRenderElement)(
|
|
1526
|
+
"div",
|
|
1527
|
+
componentProps,
|
|
1528
|
+
{
|
|
1529
|
+
ref: [forwardedRef, contentRef],
|
|
1530
|
+
state,
|
|
1531
|
+
props: elementProps
|
|
1532
|
+
},
|
|
1533
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
1534
|
+
);
|
|
1535
|
+
}
|
|
1536
|
+
function ToastClose(componentProps) {
|
|
1537
|
+
const slot = (0, import_internal.S)("ToastClose");
|
|
1538
|
+
const {
|
|
1539
|
+
render,
|
|
1540
|
+
className,
|
|
1541
|
+
style,
|
|
1542
|
+
disabled,
|
|
1543
|
+
nativeButton = true,
|
|
1544
|
+
ref: forwardedRef,
|
|
1545
|
+
...elementProps
|
|
1546
|
+
} = componentProps;
|
|
1547
|
+
const store = useToastProviderContext();
|
|
1548
|
+
const { toast } = useToastRootContext();
|
|
1549
|
+
const expanded = store.useState("expanded", (0, import_internal.subSlot)(slot, "expanded"));
|
|
1550
|
+
const [hasFocus, setHasFocus] = (0, import_octane.useState)(false, (0, import_internal.subSlot)(slot, "focus"));
|
|
1551
|
+
const { getButtonProps, buttonRef } = (0, import_useButton.useButton)(
|
|
1552
|
+
{ disabled, native: nativeButton },
|
|
1553
|
+
(0, import_internal.subSlot)(slot, "btn")
|
|
1554
|
+
);
|
|
1555
|
+
const state = {
|
|
1556
|
+
type: toast.type
|
|
1557
|
+
};
|
|
1558
|
+
return (0, import_useRenderElement.useRenderElement)(
|
|
1559
|
+
"button",
|
|
1560
|
+
componentProps,
|
|
1561
|
+
{
|
|
1562
|
+
ref: [forwardedRef, buttonRef],
|
|
1563
|
+
state,
|
|
1564
|
+
props: [
|
|
1565
|
+
{
|
|
1566
|
+
"aria-hidden": !expanded && !hasFocus,
|
|
1567
|
+
onClick() {
|
|
1568
|
+
store.closeToast(toast.id);
|
|
1569
|
+
},
|
|
1570
|
+
onFocus() {
|
|
1571
|
+
setHasFocus(true);
|
|
1572
|
+
},
|
|
1573
|
+
onBlur() {
|
|
1574
|
+
setHasFocus(false);
|
|
1575
|
+
}
|
|
1576
|
+
},
|
|
1577
|
+
elementProps,
|
|
1578
|
+
getButtonProps
|
|
1579
|
+
]
|
|
1580
|
+
},
|
|
1581
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
1582
|
+
);
|
|
1583
|
+
}
|
|
1584
|
+
function ToastAction(componentProps) {
|
|
1585
|
+
const slot = (0, import_internal.S)("ToastAction");
|
|
1586
|
+
const {
|
|
1587
|
+
render,
|
|
1588
|
+
className,
|
|
1589
|
+
style,
|
|
1590
|
+
disabled,
|
|
1591
|
+
nativeButton = true,
|
|
1592
|
+
ref: forwardedRef,
|
|
1593
|
+
...elementProps
|
|
1594
|
+
} = componentProps;
|
|
1595
|
+
const { toast } = useToastRootContext();
|
|
1596
|
+
const computedChildren = toast.actionProps?.children ?? elementProps.children;
|
|
1597
|
+
const shouldRender = Boolean(computedChildren);
|
|
1598
|
+
const { getButtonProps, buttonRef } = (0, import_useButton.useButton)(
|
|
1599
|
+
{ disabled, native: nativeButton },
|
|
1600
|
+
(0, import_internal.subSlot)(slot, "btn")
|
|
1601
|
+
);
|
|
1602
|
+
const state = {
|
|
1603
|
+
type: toast.type
|
|
1604
|
+
};
|
|
1605
|
+
const element = (0, import_useRenderElement.useRenderElement)(
|
|
1606
|
+
"button",
|
|
1607
|
+
componentProps,
|
|
1608
|
+
{
|
|
1609
|
+
ref: [forwardedRef, buttonRef],
|
|
1610
|
+
state,
|
|
1611
|
+
props: [
|
|
1612
|
+
elementProps,
|
|
1613
|
+
toast.actionProps,
|
|
1614
|
+
getButtonProps,
|
|
1615
|
+
{
|
|
1616
|
+
children: computedChildren
|
|
1617
|
+
}
|
|
1618
|
+
]
|
|
1619
|
+
},
|
|
1620
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
1621
|
+
);
|
|
1622
|
+
if (!shouldRender) {
|
|
1623
|
+
return null;
|
|
1624
|
+
}
|
|
1625
|
+
return element;
|
|
1626
|
+
}
|
|
1627
|
+
function ToastPositioner(componentProps) {
|
|
1628
|
+
const slot = (0, import_internal.S)("ToastPositioner");
|
|
1629
|
+
const { toast, ...props } = componentProps;
|
|
1630
|
+
const store = useToastProviderContext();
|
|
1631
|
+
const positionerProps = toast.positionerProps ?? import_empty.EMPTY_OBJECT;
|
|
1632
|
+
const {
|
|
1633
|
+
render,
|
|
1634
|
+
className,
|
|
1635
|
+
anchor: anchorProp = positionerProps.anchor,
|
|
1636
|
+
positionMethod = positionerProps.positionMethod ?? "absolute",
|
|
1637
|
+
side = positionerProps.side ?? "top",
|
|
1638
|
+
align = positionerProps.align ?? "center",
|
|
1639
|
+
sideOffset = positionerProps.sideOffset ?? 0,
|
|
1640
|
+
alignOffset = positionerProps.alignOffset ?? 0,
|
|
1641
|
+
collisionBoundary = positionerProps.collisionBoundary ?? "clipping-ancestors",
|
|
1642
|
+
collisionPadding = positionerProps.collisionPadding ?? 5,
|
|
1643
|
+
arrowPadding = positionerProps.arrowPadding ?? 5,
|
|
1644
|
+
sticky = positionerProps.sticky ?? false,
|
|
1645
|
+
disableAnchorTracking = positionerProps.disableAnchorTracking ?? false,
|
|
1646
|
+
collisionAvoidance = positionerProps.collisionAvoidance ?? import_constants.POPUP_COLLISION_AVOIDANCE,
|
|
1647
|
+
style,
|
|
1648
|
+
ref: forwardedRef,
|
|
1649
|
+
...elementProps
|
|
1650
|
+
} = props;
|
|
1651
|
+
const [positionerElement, setPositionerElement] = (0, import_octane.useState)(
|
|
1652
|
+
null,
|
|
1653
|
+
(0, import_internal.subSlot)(slot, "el")
|
|
1654
|
+
);
|
|
1655
|
+
const domIndex = store.useState("toastIndex", (0, import_internal.subSlot)(slot, "domIndex"), toast.id);
|
|
1656
|
+
const visibleIndex = store.useState("toastVisibleIndex", (0, import_internal.subSlot)(slot, "visIndex"), toast.id);
|
|
1657
|
+
const anchor = (0, import_dom.isElement)(anchorProp) ? anchorProp : null;
|
|
1658
|
+
const floatingRootContext = (0, import_useFloatingRootContext.useFloatingRootContext)(
|
|
1659
|
+
{
|
|
1660
|
+
open: true,
|
|
1661
|
+
onOpenChange: import_noop.NOOP,
|
|
1662
|
+
elements: {
|
|
1663
|
+
floating: positionerElement,
|
|
1664
|
+
reference: anchor
|
|
1665
|
+
}
|
|
1666
|
+
},
|
|
1667
|
+
(0, import_internal.subSlot)(slot, "frc")
|
|
1668
|
+
);
|
|
1669
|
+
const positioning = (0, import_useAnchorPositioning.useAnchorPositioning)(
|
|
1670
|
+
{
|
|
1671
|
+
anchor,
|
|
1672
|
+
positionMethod,
|
|
1673
|
+
floatingRootContext,
|
|
1674
|
+
mounted: true,
|
|
1675
|
+
side,
|
|
1676
|
+
sideOffset,
|
|
1677
|
+
align,
|
|
1678
|
+
alignOffset,
|
|
1679
|
+
collisionBoundary,
|
|
1680
|
+
collisionPadding,
|
|
1681
|
+
sticky,
|
|
1682
|
+
arrowPadding,
|
|
1683
|
+
disableAnchorTracking,
|
|
1684
|
+
keepMounted: true,
|
|
1685
|
+
collisionAvoidance
|
|
1686
|
+
},
|
|
1687
|
+
(0, import_internal.subSlot)(slot, "positioning")
|
|
1688
|
+
);
|
|
1689
|
+
const state = (0, import_octane.useMemo)(
|
|
1690
|
+
() => ({
|
|
1691
|
+
side: positioning.side,
|
|
1692
|
+
align: positioning.align,
|
|
1693
|
+
anchorHidden: positioning.anchorHidden
|
|
1694
|
+
}),
|
|
1695
|
+
[positioning.side, positioning.align, positioning.anchorHidden],
|
|
1696
|
+
(0, import_internal.subSlot)(slot, "state")
|
|
1697
|
+
);
|
|
1698
|
+
const element = (0, import_usePositioner.usePositioner)(
|
|
1699
|
+
componentProps,
|
|
1700
|
+
state,
|
|
1701
|
+
{
|
|
1702
|
+
styles: {
|
|
1703
|
+
...positioning.positionerStyles,
|
|
1704
|
+
[ToastRootCssVars.index]: toast.transitionStatus === "ending" ? domIndex : visibleIndex
|
|
1705
|
+
},
|
|
1706
|
+
transitionStatus: toast.transitionStatus,
|
|
1707
|
+
props: elementProps,
|
|
1708
|
+
refs: [forwardedRef, setPositionerElement]
|
|
1709
|
+
},
|
|
1710
|
+
(0, import_internal.subSlot)(slot, "positioner")
|
|
1711
|
+
);
|
|
1712
|
+
return (0, import_octane.createElement)(ToastPositionerContext.Provider, {
|
|
1713
|
+
value: positioning,
|
|
1714
|
+
children: element
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
function ToastArrow(componentProps) {
|
|
1718
|
+
const slot = (0, import_internal.S)("ToastArrow");
|
|
1719
|
+
const { className, render, style, ref: forwardedRef, ...elementProps } = componentProps;
|
|
1720
|
+
const { arrowRef, side, align, arrowUncentered, arrowStyles } = useToastPositionerContext();
|
|
1721
|
+
const state = {
|
|
1722
|
+
side,
|
|
1723
|
+
align,
|
|
1724
|
+
uncentered: arrowUncentered
|
|
1725
|
+
};
|
|
1726
|
+
return (0, import_useRenderElement.useRenderElement)(
|
|
1727
|
+
"div",
|
|
1728
|
+
componentProps,
|
|
1729
|
+
{
|
|
1730
|
+
state,
|
|
1731
|
+
ref: [forwardedRef, arrowRef],
|
|
1732
|
+
props: [{ style: arrowStyles, "aria-hidden": true }, elementProps]
|
|
1733
|
+
},
|
|
1734
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
1735
|
+
);
|
|
1736
|
+
}
|
|
1737
|
+
const Toast = {
|
|
1738
|
+
Provider: ToastProvider,
|
|
1739
|
+
Viewport: ToastViewport,
|
|
1740
|
+
Root: ToastRoot,
|
|
1741
|
+
Content: ToastContent,
|
|
1742
|
+
Description: ToastDescription,
|
|
1743
|
+
Title: ToastTitle,
|
|
1744
|
+
Close: ToastClose,
|
|
1745
|
+
Action: ToastAction,
|
|
1746
|
+
Portal: import_FloatingPortalLite.FloatingPortalLite,
|
|
1747
|
+
Positioner: ToastPositioner,
|
|
1748
|
+
Arrow: ToastArrow,
|
|
1749
|
+
useToastManager,
|
|
1750
|
+
createToastManager
|
|
1751
|
+
};
|
|
1752
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1753
|
+
0 && (module.exports = {
|
|
1754
|
+
Toast,
|
|
1755
|
+
ToastPositionerCssVars,
|
|
1756
|
+
ToastRootCssVars,
|
|
1757
|
+
ToastStore,
|
|
1758
|
+
ToastViewportCssVars,
|
|
1759
|
+
createToastManager,
|
|
1760
|
+
resolvePromiseOptions,
|
|
1761
|
+
toastSelectors,
|
|
1762
|
+
useToastManager,
|
|
1763
|
+
useToastPositionerContext,
|
|
1764
|
+
useToastProviderContext,
|
|
1765
|
+
useToastRootContext
|
|
1766
|
+
});
|