@octanejs/base-ui 0.1.31 → 0.1.33
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,506 @@
|
|
|
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 useDismiss_exports = {};
|
|
20
|
+
__export(useDismiss_exports, {
|
|
21
|
+
normalizeProp: () => normalizeProp,
|
|
22
|
+
useDismiss: () => useDismiss
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useDismiss_exports);
|
|
25
|
+
var import_octane = require("octane");
|
|
26
|
+
var import_dom = require("@floating-ui/utils/dom");
|
|
27
|
+
var import_internal = require("../../internal.cjs");
|
|
28
|
+
var import_addEventListener = require("../addEventListener.cjs");
|
|
29
|
+
var import_mergeCleanups = require("../mergeCleanups.cjs");
|
|
30
|
+
var import_owner = require("../owner.cjs");
|
|
31
|
+
var import_useStableCallback = require("../useStableCallback.cjs");
|
|
32
|
+
var import_useTimeout = require("../useTimeout.cjs");
|
|
33
|
+
var import_platform = require("../platform.cjs");
|
|
34
|
+
var import_FloatingTree = require("./FloatingTree.cjs");
|
|
35
|
+
var import_createChangeEventDetails = require("../createChangeEventDetails.cjs");
|
|
36
|
+
var import_createAttribute = require("./createAttribute.cjs");
|
|
37
|
+
var import_element = require("./element.cjs");
|
|
38
|
+
var import_event = require("./event.cjs");
|
|
39
|
+
var import_nodes = require("./nodes.cjs");
|
|
40
|
+
function alwaysFalse() {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
function normalizeProp(normalizable) {
|
|
44
|
+
return {
|
|
45
|
+
escapeKey: typeof normalizable === "boolean" ? normalizable : normalizable?.escapeKey ?? false,
|
|
46
|
+
outsidePress: typeof normalizable === "boolean" ? normalizable : normalizable?.outsidePress ?? true
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function useDismiss(context, props, slot) {
|
|
50
|
+
const {
|
|
51
|
+
enabled = true,
|
|
52
|
+
escapeKey = true,
|
|
53
|
+
outsidePress: outsidePressProp = true,
|
|
54
|
+
outsidePressEvent = "sloppy",
|
|
55
|
+
referencePress = alwaysFalse,
|
|
56
|
+
bubbles,
|
|
57
|
+
externalTree
|
|
58
|
+
} = props;
|
|
59
|
+
const store = context && "rootStore" in context ? context.rootStore : context;
|
|
60
|
+
const open = store.useState("open", (0, import_internal.subSlot)(slot, "open"));
|
|
61
|
+
const floatingElement = store.useState("floatingElement", (0, import_internal.subSlot)(slot, "fel"));
|
|
62
|
+
const { dataRef } = store.context;
|
|
63
|
+
const tree = (0, import_FloatingTree.useFloatingTree)(externalTree);
|
|
64
|
+
const outsidePressFn = (0, import_useStableCallback.useStableCallback)(
|
|
65
|
+
typeof outsidePressProp === "function" ? outsidePressProp : () => false,
|
|
66
|
+
(0, import_internal.subSlot)(slot, "opf")
|
|
67
|
+
);
|
|
68
|
+
const outsidePress = typeof outsidePressProp === "function" ? outsidePressFn : outsidePressProp;
|
|
69
|
+
const outsidePressEnabled = outsidePress !== false;
|
|
70
|
+
const getOutsidePressEventProp = (0, import_useStableCallback.useStableCallback)(
|
|
71
|
+
() => outsidePressEvent,
|
|
72
|
+
(0, import_internal.subSlot)(slot, "gope")
|
|
73
|
+
);
|
|
74
|
+
const { escapeKey: escapeKeyBubbles, outsidePress: outsidePressBubbles } = normalizeProp(bubbles);
|
|
75
|
+
const pressStartedInsideRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "psi"));
|
|
76
|
+
const pressStartPreventedRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "psp"));
|
|
77
|
+
const suppressNextOutsideClickRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "snoc"));
|
|
78
|
+
const isComposingRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "ic"));
|
|
79
|
+
const currentPointerTypeRef = (0, import_octane.useRef)("", (0, import_internal.subSlot)(slot, "cpt"));
|
|
80
|
+
const touchStateRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "ts"));
|
|
81
|
+
const cancelDismissOnEndTimeout = (0, import_useTimeout.useTimeout)((0, import_internal.subSlot)(slot, "cdet"));
|
|
82
|
+
const clearInsideReactTreeTimeout = (0, import_useTimeout.useTimeout)((0, import_internal.subSlot)(slot, "cirt"));
|
|
83
|
+
const clearInsideReactTree = (0, import_useStableCallback.useStableCallback)(
|
|
84
|
+
() => {
|
|
85
|
+
clearInsideReactTreeTimeout.clear();
|
|
86
|
+
dataRef.current.insideReactTree = false;
|
|
87
|
+
},
|
|
88
|
+
(0, import_internal.subSlot)(slot, "cir")
|
|
89
|
+
);
|
|
90
|
+
const hasBlockingChild = (0, import_useStableCallback.useStableCallback)(
|
|
91
|
+
(bubbleKey) => {
|
|
92
|
+
const nodeId = dataRef.current.floatingContext?.nodeId;
|
|
93
|
+
const children = tree ? (0, import_nodes.getNodeChildren)(tree.nodesRef.current, nodeId) : [];
|
|
94
|
+
return children.some(
|
|
95
|
+
(child) => child.context?.open && !child.context.dataRef.current[bubbleKey]
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
(0, import_internal.subSlot)(slot, "hbc")
|
|
99
|
+
);
|
|
100
|
+
const isEventWithinOwnElements = (0, import_useStableCallback.useStableCallback)(
|
|
101
|
+
(event) => {
|
|
102
|
+
return (0, import_element.isEventTargetWithin)(event, store.select("floatingElement")) || (0, import_element.isEventTargetWithin)(event, store.select("domReferenceElement"));
|
|
103
|
+
},
|
|
104
|
+
(0, import_internal.subSlot)(slot, "iewoe")
|
|
105
|
+
);
|
|
106
|
+
const closeOnReferencePress = (0, import_useStableCallback.useStableCallback)(
|
|
107
|
+
(event) => {
|
|
108
|
+
if (!referencePress()) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
store.setOpen(false, (0, import_createChangeEventDetails.createChangeEventDetails)(import_createChangeEventDetails.REASONS.triggerPress, event));
|
|
112
|
+
},
|
|
113
|
+
(0, import_internal.subSlot)(slot, "corp")
|
|
114
|
+
);
|
|
115
|
+
const closeOnEscapeKeyDown = (0, import_useStableCallback.useStableCallback)(
|
|
116
|
+
(event) => {
|
|
117
|
+
if (!open || !enabled || !escapeKey || event.key !== "Escape") {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (isComposingRef.current) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (!escapeKeyBubbles && hasBlockingChild("__escapeKeyBubbles")) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const native = (0, import_event.isReactEvent)(event) ? event.nativeEvent : event;
|
|
127
|
+
const eventDetails = (0, import_createChangeEventDetails.createChangeEventDetails)(import_createChangeEventDetails.REASONS.escapeKey, native);
|
|
128
|
+
store.setOpen(false, eventDetails);
|
|
129
|
+
if (!eventDetails.isCanceled) {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
}
|
|
132
|
+
if (!escapeKeyBubbles && !eventDetails.isPropagationAllowed) {
|
|
133
|
+
event.stopPropagation();
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
(0, import_internal.subSlot)(slot, "coekd")
|
|
137
|
+
);
|
|
138
|
+
const markInsideReactTree = (0, import_useStableCallback.useStableCallback)(
|
|
139
|
+
() => {
|
|
140
|
+
dataRef.current.insideReactTree = true;
|
|
141
|
+
clearInsideReactTreeTimeout.start(0, clearInsideReactTree);
|
|
142
|
+
},
|
|
143
|
+
(0, import_internal.subSlot)(slot, "mirt")
|
|
144
|
+
);
|
|
145
|
+
const markPressStartedInsideReactTree = (0, import_useStableCallback.useStableCallback)(
|
|
146
|
+
(event) => {
|
|
147
|
+
if (!open || !enabled || event.button !== 0) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const target = (0, import_element.getTarget)(event);
|
|
151
|
+
if (!(0, import_element.contains)(store.select("floatingElement"), target)) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (!pressStartedInsideRef.current) {
|
|
155
|
+
pressStartedInsideRef.current = true;
|
|
156
|
+
pressStartPreventedRef.current = false;
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
(0, import_internal.subSlot)(slot, "mpsirt")
|
|
160
|
+
);
|
|
161
|
+
const markInsidePressStartPrevented = (0, import_useStableCallback.useStableCallback)(
|
|
162
|
+
(event) => {
|
|
163
|
+
if (!open || !enabled) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (!event.defaultPrevented) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (pressStartedInsideRef.current) {
|
|
170
|
+
pressStartPreventedRef.current = true;
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
(0, import_internal.subSlot)(slot, "mipsp")
|
|
174
|
+
);
|
|
175
|
+
(0, import_octane.useEffect)(
|
|
176
|
+
() => {
|
|
177
|
+
if (!open || !enabled) {
|
|
178
|
+
return void 0;
|
|
179
|
+
}
|
|
180
|
+
dataRef.current.__escapeKeyBubbles = escapeKeyBubbles;
|
|
181
|
+
dataRef.current.__outsidePressBubbles = outsidePressBubbles;
|
|
182
|
+
const compositionTimeout = new import_useTimeout.Timeout();
|
|
183
|
+
const preventedPressSuppressionTimeout = new import_useTimeout.Timeout();
|
|
184
|
+
function handleCompositionStart() {
|
|
185
|
+
compositionTimeout.clear();
|
|
186
|
+
isComposingRef.current = true;
|
|
187
|
+
}
|
|
188
|
+
function handleCompositionEnd() {
|
|
189
|
+
compositionTimeout.start(import_platform.platform.engine.webkit ? 5 : 0, () => {
|
|
190
|
+
isComposingRef.current = false;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
function suppressImmediateOutsideClickAfterPreventedStart() {
|
|
194
|
+
suppressNextOutsideClickRef.current = true;
|
|
195
|
+
preventedPressSuppressionTimeout.start(0, () => {
|
|
196
|
+
suppressNextOutsideClickRef.current = false;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function resetPressStartState() {
|
|
200
|
+
pressStartedInsideRef.current = false;
|
|
201
|
+
pressStartPreventedRef.current = false;
|
|
202
|
+
}
|
|
203
|
+
function getOutsidePressEvent() {
|
|
204
|
+
const type = currentPointerTypeRef.current;
|
|
205
|
+
const computedType = type === "pen" || !type ? "mouse" : type;
|
|
206
|
+
const outsidePressEventValue = getOutsidePressEventProp();
|
|
207
|
+
const resolved = typeof outsidePressEventValue === "function" ? outsidePressEventValue() : outsidePressEventValue;
|
|
208
|
+
if (typeof resolved === "string") {
|
|
209
|
+
return resolved;
|
|
210
|
+
}
|
|
211
|
+
return resolved[computedType];
|
|
212
|
+
}
|
|
213
|
+
function shouldIgnoreEvent(event) {
|
|
214
|
+
const computedOutsidePressEvent = getOutsidePressEvent();
|
|
215
|
+
return computedOutsidePressEvent === "intentional" && event.type !== "click" || computedOutsidePressEvent === "sloppy" && event.type === "click";
|
|
216
|
+
}
|
|
217
|
+
function isEventWithinFloatingTree(event) {
|
|
218
|
+
const nodeId = dataRef.current.floatingContext?.nodeId;
|
|
219
|
+
const targetIsInsideChildren = tree && (0, import_nodes.getNodeChildren)(tree.nodesRef.current, nodeId).some(
|
|
220
|
+
(node) => (0, import_element.isEventTargetWithin)(event, node.context?.elements.floating)
|
|
221
|
+
);
|
|
222
|
+
return isEventWithinOwnElements(event) || targetIsInsideChildren;
|
|
223
|
+
}
|
|
224
|
+
function closeOnPressOutside(event) {
|
|
225
|
+
if (shouldIgnoreEvent(event)) {
|
|
226
|
+
if (event.type !== "click" && !isEventWithinOwnElements(event)) {
|
|
227
|
+
preventedPressSuppressionTimeout.clear();
|
|
228
|
+
suppressNextOutsideClickRef.current = false;
|
|
229
|
+
}
|
|
230
|
+
clearInsideReactTree();
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (dataRef.current.insideReactTree) {
|
|
234
|
+
clearInsideReactTree();
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const target = (0, import_element.getTarget)(event);
|
|
238
|
+
const inertSelector = `[${(0, import_createAttribute.createAttribute)("inert")}]`;
|
|
239
|
+
const targetRoot = (0, import_dom.isElement)(target) ? target.getRootNode() : null;
|
|
240
|
+
const markers = Array.from(
|
|
241
|
+
((0, import_dom.isShadowRoot)(targetRoot) ? targetRoot : (0, import_owner.ownerDocument)(store.select("floatingElement"))).querySelectorAll(inertSelector)
|
|
242
|
+
);
|
|
243
|
+
const triggers = store.context.triggerElements;
|
|
244
|
+
if (target && (triggers.hasElement(target) || triggers.hasMatchingElement((trigger) => (0, import_element.contains)(trigger, target)))) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
let targetRootAncestor = (0, import_dom.isElement)(target) ? target : null;
|
|
248
|
+
while (targetRootAncestor && !(0, import_dom.isLastTraversableNode)(targetRootAncestor)) {
|
|
249
|
+
const nextParent = (0, import_dom.getParentNode)(targetRootAncestor);
|
|
250
|
+
if ((0, import_dom.isLastTraversableNode)(nextParent) || !(0, import_dom.isElement)(nextParent)) {
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
targetRootAncestor = nextParent;
|
|
254
|
+
}
|
|
255
|
+
if (markers.length && (0, import_dom.isElement)(target) && !(0, import_element.isRootElement)(target) && !(0, import_element.contains)(target, store.select("floatingElement")) && markers.every((marker) => !(0, import_element.contains)(targetRootAncestor, marker))) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if ((0, import_dom.isHTMLElement)(target) && !("touches" in event)) {
|
|
259
|
+
const lastTraversableNode = (0, import_dom.isLastTraversableNode)(target);
|
|
260
|
+
const style = (0, import_dom.getComputedStyle)(target);
|
|
261
|
+
const scrollRe = /auto|scroll/;
|
|
262
|
+
const isScrollableX = lastTraversableNode || scrollRe.test(style.overflowX);
|
|
263
|
+
const isScrollableY = lastTraversableNode || scrollRe.test(style.overflowY);
|
|
264
|
+
const canScrollX = isScrollableX && target.clientWidth > 0 && target.scrollWidth > target.clientWidth;
|
|
265
|
+
const canScrollY = isScrollableY && target.clientHeight > 0 && target.scrollHeight > target.clientHeight;
|
|
266
|
+
const isRTL = style.direction === "rtl";
|
|
267
|
+
const pressedVerticalScrollbar = canScrollY && (isRTL ? event.offsetX <= target.offsetWidth - target.clientWidth : event.offsetX > target.clientWidth);
|
|
268
|
+
const pressedHorizontalScrollbar = canScrollX && event.offsetY > target.clientHeight;
|
|
269
|
+
if (pressedVerticalScrollbar || pressedHorizontalScrollbar) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (isEventWithinFloatingTree(event)) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (getOutsidePressEvent() === "intentional" && suppressNextOutsideClickRef.current) {
|
|
277
|
+
preventedPressSuppressionTimeout.clear();
|
|
278
|
+
suppressNextOutsideClickRef.current = false;
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (typeof outsidePress === "function" && !outsidePress(event)) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
if (hasBlockingChild("__outsidePressBubbles")) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
store.setOpen(false, (0, import_createChangeEventDetails.createChangeEventDetails)(import_createChangeEventDetails.REASONS.outsidePress, event));
|
|
288
|
+
clearInsideReactTree();
|
|
289
|
+
}
|
|
290
|
+
function handlePointerDown(event) {
|
|
291
|
+
if (getOutsidePressEvent() !== "sloppy" || event.pointerType === "touch" || !store.select("open") || !enabled || isEventWithinOwnElements(event)) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
closeOnPressOutside(event);
|
|
295
|
+
}
|
|
296
|
+
function handleTouchStart(event) {
|
|
297
|
+
if (getOutsidePressEvent() !== "sloppy" || !store.select("open") || !enabled || isEventWithinOwnElements(event)) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const touch = event.touches[0];
|
|
301
|
+
if (touch) {
|
|
302
|
+
touchStateRef.current = {
|
|
303
|
+
startTime: Date.now(),
|
|
304
|
+
startX: touch.clientX,
|
|
305
|
+
startY: touch.clientY,
|
|
306
|
+
dismissOnTouchEnd: false,
|
|
307
|
+
dismissOnMouseDown: true
|
|
308
|
+
};
|
|
309
|
+
cancelDismissOnEndTimeout.start(1e3, () => {
|
|
310
|
+
if (touchStateRef.current) {
|
|
311
|
+
touchStateRef.current.dismissOnTouchEnd = false;
|
|
312
|
+
touchStateRef.current.dismissOnMouseDown = false;
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function addTargetEventListenerOnce(event, listener) {
|
|
318
|
+
const target = (0, import_element.getTarget)(event);
|
|
319
|
+
if (!target) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const unsubscribe2 = (0, import_addEventListener.addEventListener)(target, event.type, () => {
|
|
323
|
+
listener(event);
|
|
324
|
+
unsubscribe2();
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
function handleTouchStartCapture(event) {
|
|
328
|
+
currentPointerTypeRef.current = "touch";
|
|
329
|
+
addTargetEventListenerOnce(event, handleTouchStart);
|
|
330
|
+
}
|
|
331
|
+
function closeOnPressOutsideCapture(event) {
|
|
332
|
+
cancelDismissOnEndTimeout.clear();
|
|
333
|
+
if (event.type === "pointerdown") {
|
|
334
|
+
currentPointerTypeRef.current = event.pointerType;
|
|
335
|
+
}
|
|
336
|
+
if (event.type === "mousedown" && touchStateRef.current && !touchStateRef.current.dismissOnMouseDown) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
addTargetEventListenerOnce(event, (targetEvent) => {
|
|
340
|
+
if (targetEvent.type === "pointerdown") {
|
|
341
|
+
handlePointerDown(targetEvent);
|
|
342
|
+
} else {
|
|
343
|
+
closeOnPressOutside(targetEvent);
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
function handlePressEndCapture(event) {
|
|
348
|
+
if (!pressStartedInsideRef.current) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
const pressStartedInsideDefaultPrevented = pressStartPreventedRef.current;
|
|
352
|
+
resetPressStartState();
|
|
353
|
+
if (getOutsidePressEvent() !== "intentional") {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (event.type === "pointercancel") {
|
|
357
|
+
if (pressStartedInsideDefaultPrevented) {
|
|
358
|
+
suppressImmediateOutsideClickAfterPreventedStart();
|
|
359
|
+
}
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (isEventWithinFloatingTree(event)) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (pressStartedInsideDefaultPrevented) {
|
|
366
|
+
suppressImmediateOutsideClickAfterPreventedStart();
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (typeof outsidePress === "function" && !outsidePress(event)) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
preventedPressSuppressionTimeout.clear();
|
|
373
|
+
suppressNextOutsideClickRef.current = true;
|
|
374
|
+
clearInsideReactTree();
|
|
375
|
+
}
|
|
376
|
+
function handleTouchMove(event) {
|
|
377
|
+
if (getOutsidePressEvent() !== "sloppy" || !touchStateRef.current || isEventWithinOwnElements(event)) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const touch = event.touches[0];
|
|
381
|
+
if (!touch) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
const deltaX = Math.abs(touch.clientX - touchStateRef.current.startX);
|
|
385
|
+
const deltaY = Math.abs(touch.clientY - touchStateRef.current.startY);
|
|
386
|
+
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
387
|
+
if (distance > 5) {
|
|
388
|
+
touchStateRef.current.dismissOnTouchEnd = true;
|
|
389
|
+
}
|
|
390
|
+
if (distance > 10) {
|
|
391
|
+
closeOnPressOutside(event);
|
|
392
|
+
cancelDismissOnEndTimeout.clear();
|
|
393
|
+
touchStateRef.current = null;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function handleTouchMoveCapture(event) {
|
|
397
|
+
addTargetEventListenerOnce(event, handleTouchMove);
|
|
398
|
+
}
|
|
399
|
+
function handleTouchEnd(event) {
|
|
400
|
+
if (getOutsidePressEvent() !== "sloppy" || !touchStateRef.current || isEventWithinOwnElements(event)) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (touchStateRef.current.dismissOnTouchEnd) {
|
|
404
|
+
closeOnPressOutside(event);
|
|
405
|
+
}
|
|
406
|
+
cancelDismissOnEndTimeout.clear();
|
|
407
|
+
touchStateRef.current = null;
|
|
408
|
+
}
|
|
409
|
+
function handleTouchEndCapture(event) {
|
|
410
|
+
addTargetEventListenerOnce(event, handleTouchEnd);
|
|
411
|
+
}
|
|
412
|
+
const doc = (0, import_owner.ownerDocument)(floatingElement);
|
|
413
|
+
const unsubscribe = (0, import_mergeCleanups.mergeCleanups)(
|
|
414
|
+
escapeKey && (0, import_mergeCleanups.mergeCleanups)(
|
|
415
|
+
(0, import_addEventListener.addEventListener)(doc, "keydown", closeOnEscapeKeyDown),
|
|
416
|
+
(0, import_addEventListener.addEventListener)(doc, "compositionstart", handleCompositionStart),
|
|
417
|
+
(0, import_addEventListener.addEventListener)(doc, "compositionend", handleCompositionEnd)
|
|
418
|
+
),
|
|
419
|
+
outsidePressEnabled && (0, import_mergeCleanups.mergeCleanups)(
|
|
420
|
+
(0, import_addEventListener.addEventListener)(doc, "click", closeOnPressOutsideCapture, true),
|
|
421
|
+
(0, import_addEventListener.addEventListener)(doc, "pointerdown", closeOnPressOutsideCapture, true),
|
|
422
|
+
(0, import_addEventListener.addEventListener)(doc, "pointerup", handlePressEndCapture, true),
|
|
423
|
+
(0, import_addEventListener.addEventListener)(doc, "pointercancel", handlePressEndCapture, true),
|
|
424
|
+
(0, import_addEventListener.addEventListener)(doc, "mousedown", closeOnPressOutsideCapture, true),
|
|
425
|
+
(0, import_addEventListener.addEventListener)(doc, "mouseup", handlePressEndCapture, true),
|
|
426
|
+
(0, import_addEventListener.addEventListener)(doc, "touchstart", handleTouchStartCapture, true),
|
|
427
|
+
(0, import_addEventListener.addEventListener)(doc, "touchmove", handleTouchMoveCapture, true),
|
|
428
|
+
(0, import_addEventListener.addEventListener)(doc, "touchend", handleTouchEndCapture, true)
|
|
429
|
+
)
|
|
430
|
+
);
|
|
431
|
+
return () => {
|
|
432
|
+
unsubscribe();
|
|
433
|
+
compositionTimeout.clear();
|
|
434
|
+
preventedPressSuppressionTimeout.clear();
|
|
435
|
+
resetPressStartState();
|
|
436
|
+
suppressNextOutsideClickRef.current = false;
|
|
437
|
+
};
|
|
438
|
+
},
|
|
439
|
+
[
|
|
440
|
+
dataRef,
|
|
441
|
+
floatingElement,
|
|
442
|
+
escapeKey,
|
|
443
|
+
outsidePressEnabled,
|
|
444
|
+
outsidePress,
|
|
445
|
+
open,
|
|
446
|
+
enabled,
|
|
447
|
+
escapeKeyBubbles,
|
|
448
|
+
outsidePressBubbles,
|
|
449
|
+
closeOnEscapeKeyDown,
|
|
450
|
+
clearInsideReactTree,
|
|
451
|
+
getOutsidePressEventProp,
|
|
452
|
+
hasBlockingChild,
|
|
453
|
+
isEventWithinOwnElements,
|
|
454
|
+
tree,
|
|
455
|
+
store,
|
|
456
|
+
cancelDismissOnEndTimeout
|
|
457
|
+
],
|
|
458
|
+
(0, import_internal.subSlot)(slot, "e:main")
|
|
459
|
+
);
|
|
460
|
+
(0, import_octane.useEffect)(clearInsideReactTree, [outsidePress, clearInsideReactTree], (0, import_internal.subSlot)(slot, "e:cir"));
|
|
461
|
+
const reference = (0, import_octane.useMemo)(
|
|
462
|
+
() => ({
|
|
463
|
+
onKeyDown: closeOnEscapeKeyDown,
|
|
464
|
+
onPointerDown: closeOnReferencePress,
|
|
465
|
+
onClick: closeOnReferencePress
|
|
466
|
+
}),
|
|
467
|
+
[closeOnEscapeKeyDown, closeOnReferencePress],
|
|
468
|
+
(0, import_internal.subSlot)(slot, "ref")
|
|
469
|
+
);
|
|
470
|
+
const floating = (0, import_octane.useMemo)(
|
|
471
|
+
() => ({
|
|
472
|
+
onKeyDown: closeOnEscapeKeyDown,
|
|
473
|
+
onPointerDown: markInsidePressStartPrevented,
|
|
474
|
+
onMouseDown: markInsidePressStartPrevented,
|
|
475
|
+
onClickCapture: markInsideReactTree,
|
|
476
|
+
onMouseDownCapture(event) {
|
|
477
|
+
markInsideReactTree();
|
|
478
|
+
markPressStartedInsideReactTree(event);
|
|
479
|
+
},
|
|
480
|
+
onPointerDownCapture(event) {
|
|
481
|
+
markInsideReactTree();
|
|
482
|
+
markPressStartedInsideReactTree(event);
|
|
483
|
+
},
|
|
484
|
+
onMouseUpCapture: markInsideReactTree,
|
|
485
|
+
onTouchEndCapture: markInsideReactTree,
|
|
486
|
+
onTouchMoveCapture: markInsideReactTree
|
|
487
|
+
}),
|
|
488
|
+
[
|
|
489
|
+
closeOnEscapeKeyDown,
|
|
490
|
+
markInsideReactTree,
|
|
491
|
+
markPressStartedInsideReactTree,
|
|
492
|
+
markInsidePressStartPrevented
|
|
493
|
+
],
|
|
494
|
+
(0, import_internal.subSlot)(slot, "floating")
|
|
495
|
+
);
|
|
496
|
+
return (0, import_octane.useMemo)(
|
|
497
|
+
() => enabled ? { reference, floating, trigger: reference } : {},
|
|
498
|
+
[enabled, reference, floating],
|
|
499
|
+
(0, import_internal.subSlot)(slot, "out")
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
503
|
+
0 && (module.exports = {
|
|
504
|
+
normalizeProp,
|
|
505
|
+
useDismiss
|
|
506
|
+
});
|
|
@@ -0,0 +1,186 @@
|
|
|
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 useFloating_exports = {};
|
|
20
|
+
__export(useFloating_exports, {
|
|
21
|
+
useFloating: () => useFloating
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useFloating_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
var import_floating_ui = require("@octanejs/floating-ui");
|
|
26
|
+
var import_internal = require("../../internal.cjs");
|
|
27
|
+
var import_dom = require("../dom.cjs");
|
|
28
|
+
var import_FloatingTree = require("./FloatingTree.cjs");
|
|
29
|
+
var import_useFloatingRootContext = require("./useFloatingRootContext.cjs");
|
|
30
|
+
function useFloating(options = {}, slot) {
|
|
31
|
+
const localSlot = slot ?? (0, import_internal.S)("useFloating");
|
|
32
|
+
const { nodeId, externalTree } = options;
|
|
33
|
+
const internalStore = (0, import_useFloatingRootContext.useFloatingRootContext)(options, (0, import_internal.subSlot)(localSlot, "internal"));
|
|
34
|
+
const store = options.rootContext || internalStore;
|
|
35
|
+
const referenceElement = store.useState("referenceElement", (0, import_internal.subSlot)(localSlot, "ref"));
|
|
36
|
+
const floatingElement = store.useState("floatingElement", (0, import_internal.subSlot)(localSlot, "flo"));
|
|
37
|
+
const domReferenceElement = store.useState("domReferenceElement", (0, import_internal.subSlot)(localSlot, "dref"));
|
|
38
|
+
const open = store.useState("open", (0, import_internal.subSlot)(localSlot, "open"));
|
|
39
|
+
const floatingId = store.useState("floatingId", (0, import_internal.subSlot)(localSlot, "fid"));
|
|
40
|
+
const [positionReference, setPositionReferenceRaw] = (0, import_octane.useState)(
|
|
41
|
+
null,
|
|
42
|
+
(0, import_internal.subSlot)(localSlot, "posref")
|
|
43
|
+
);
|
|
44
|
+
const [localDomReference, setLocalDomReference] = (0, import_octane.useState)(
|
|
45
|
+
void 0,
|
|
46
|
+
(0, import_internal.subSlot)(localSlot, "ldref")
|
|
47
|
+
);
|
|
48
|
+
const [localFloatingElement, setLocalFloatingElement] = (0, import_octane.useState)(
|
|
49
|
+
void 0,
|
|
50
|
+
(0, import_internal.subSlot)(localSlot, "lflo")
|
|
51
|
+
);
|
|
52
|
+
const domReferenceRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(localSlot, "drefref"));
|
|
53
|
+
const tree = (0, import_FloatingTree.useFloatingTree)(externalTree);
|
|
54
|
+
const storeElements = (0, import_octane.useMemo)(
|
|
55
|
+
() => ({
|
|
56
|
+
reference: referenceElement,
|
|
57
|
+
floating: floatingElement,
|
|
58
|
+
domReference: domReferenceElement
|
|
59
|
+
}),
|
|
60
|
+
[referenceElement, floatingElement, domReferenceElement],
|
|
61
|
+
(0, import_internal.subSlot)(localSlot, "m:se")
|
|
62
|
+
);
|
|
63
|
+
const position = (0, import_floating_ui.usePositionFloating)([
|
|
64
|
+
{
|
|
65
|
+
...options,
|
|
66
|
+
elements: {
|
|
67
|
+
...storeElements,
|
|
68
|
+
...positionReference && { reference: positionReference }
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
(0, import_internal.subSlot)(localSlot, "pos")
|
|
72
|
+
]);
|
|
73
|
+
const localDomReferenceElement = (0, import_dom.isElement)(localDomReference) ? localDomReference : null;
|
|
74
|
+
const syncedFloatingElement = localFloatingElement === void 0 ? store.state.floatingElement : localFloatingElement;
|
|
75
|
+
store.useSyncedValue("referenceElement", localDomReference ?? null, (0, import_internal.subSlot)(localSlot, "s:ref"));
|
|
76
|
+
store.useSyncedValue(
|
|
77
|
+
"domReferenceElement",
|
|
78
|
+
localDomReference === void 0 ? domReferenceElement : localDomReferenceElement,
|
|
79
|
+
(0, import_internal.subSlot)(localSlot, "s:dref")
|
|
80
|
+
);
|
|
81
|
+
store.useSyncedValue("floatingElement", syncedFloatingElement, (0, import_internal.subSlot)(localSlot, "s:flo"));
|
|
82
|
+
const setPositionReference = (0, import_octane.useCallback)(
|
|
83
|
+
(node) => {
|
|
84
|
+
const computedPositionReference = (0, import_dom.isElement)(node) ? {
|
|
85
|
+
getBoundingClientRect: () => node.getBoundingClientRect(),
|
|
86
|
+
getClientRects: () => node.getClientRects(),
|
|
87
|
+
contextElement: node
|
|
88
|
+
} : node;
|
|
89
|
+
setPositionReferenceRaw(computedPositionReference);
|
|
90
|
+
position.refs.setReference(computedPositionReference);
|
|
91
|
+
},
|
|
92
|
+
[position.refs],
|
|
93
|
+
(0, import_internal.subSlot)(localSlot, "spr")
|
|
94
|
+
);
|
|
95
|
+
const setReference = (0, import_octane.useCallback)(
|
|
96
|
+
(node) => {
|
|
97
|
+
if ((0, import_dom.isElement)(node) || node === null) {
|
|
98
|
+
domReferenceRef.current = node;
|
|
99
|
+
setLocalDomReference(node);
|
|
100
|
+
}
|
|
101
|
+
if ((0, import_dom.isElement)(position.refs.reference.current) || position.refs.reference.current === null || node !== null && !(0, import_dom.isElement)(node)) {
|
|
102
|
+
position.refs.setReference(node);
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
[position.refs],
|
|
106
|
+
(0, import_internal.subSlot)(localSlot, "sr")
|
|
107
|
+
);
|
|
108
|
+
const setFloating = (0, import_octane.useCallback)(
|
|
109
|
+
(node) => {
|
|
110
|
+
setLocalFloatingElement(node);
|
|
111
|
+
position.refs.setFloating(node);
|
|
112
|
+
},
|
|
113
|
+
[position.refs],
|
|
114
|
+
(0, import_internal.subSlot)(localSlot, "sf")
|
|
115
|
+
);
|
|
116
|
+
const refs = (0, import_octane.useMemo)(
|
|
117
|
+
() => ({
|
|
118
|
+
...position.refs,
|
|
119
|
+
setReference,
|
|
120
|
+
setFloating,
|
|
121
|
+
setPositionReference,
|
|
122
|
+
domReference: domReferenceRef
|
|
123
|
+
}),
|
|
124
|
+
[position.refs, setReference, setFloating, setPositionReference],
|
|
125
|
+
(0, import_internal.subSlot)(localSlot, "m:refs")
|
|
126
|
+
);
|
|
127
|
+
const elements = (0, import_octane.useMemo)(
|
|
128
|
+
() => ({
|
|
129
|
+
...position.elements,
|
|
130
|
+
domReference: domReferenceElement
|
|
131
|
+
}),
|
|
132
|
+
[position.elements, domReferenceElement],
|
|
133
|
+
(0, import_internal.subSlot)(localSlot, "m:el")
|
|
134
|
+
);
|
|
135
|
+
const context = (0, import_octane.useMemo)(
|
|
136
|
+
() => ({
|
|
137
|
+
...position,
|
|
138
|
+
dataRef: store.context.dataRef,
|
|
139
|
+
open,
|
|
140
|
+
onOpenChange: store.setOpen,
|
|
141
|
+
events: store.context.events,
|
|
142
|
+
floatingId,
|
|
143
|
+
refs,
|
|
144
|
+
elements,
|
|
145
|
+
nodeId,
|
|
146
|
+
rootStore: store
|
|
147
|
+
}),
|
|
148
|
+
[position, refs, elements, nodeId, store, open, floatingId],
|
|
149
|
+
(0, import_internal.subSlot)(localSlot, "m:ctx")
|
|
150
|
+
);
|
|
151
|
+
(0, import_octane.useLayoutEffect)(
|
|
152
|
+
() => {
|
|
153
|
+
if (domReferenceElement) {
|
|
154
|
+
domReferenceRef.current = domReferenceElement;
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
[domReferenceElement],
|
|
158
|
+
(0, import_internal.subSlot)(localSlot, "e:dref")
|
|
159
|
+
);
|
|
160
|
+
(0, import_octane.useLayoutEffect)(
|
|
161
|
+
() => {
|
|
162
|
+
store.context.dataRef.current.floatingContext = context;
|
|
163
|
+
const node = tree?.nodesRef.current.find((n) => n.id === nodeId);
|
|
164
|
+
if (node) {
|
|
165
|
+
node.context = context;
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
void 0,
|
|
169
|
+
(0, import_internal.subSlot)(localSlot, "e:ctx")
|
|
170
|
+
);
|
|
171
|
+
return (0, import_octane.useMemo)(
|
|
172
|
+
() => ({
|
|
173
|
+
...position,
|
|
174
|
+
context,
|
|
175
|
+
refs,
|
|
176
|
+
elements,
|
|
177
|
+
rootStore: store
|
|
178
|
+
}),
|
|
179
|
+
[position, refs, elements, context, store],
|
|
180
|
+
(0, import_internal.subSlot)(localSlot, "m:ret")
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
184
|
+
0 && (module.exports = {
|
|
185
|
+
useFloating
|
|
186
|
+
});
|