@ariakit/react-core 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +108 -0
- package/cjs/__chunks/{XFZ3MEQZ.cjs → 27JG67F3.cjs} +3 -3
- package/cjs/__chunks/{ASQZCUUA.cjs → 4SZYU2PD.cjs} +2 -2
- package/cjs/__chunks/5P6HRGY6.cjs +21 -0
- package/cjs/__chunks/{DCDTT7UY.cjs → A6ZSQXNQ.cjs} +2 -2
- package/cjs/__chunks/{QXXZLOZG.cjs → D3EUPD6P.cjs} +22 -41
- package/cjs/__chunks/{EEXWIKOB.cjs → GOXUG4RX.cjs} +41 -53
- package/cjs/__chunks/{RHO5OVPE.cjs → GRL5KGV3.cjs} +2 -2
- package/cjs/__chunks/MHL3EECX.cjs +363 -0
- package/cjs/__chunks/{AUDANYMJ.cjs → W2XKIB23.cjs} +1 -20
- package/cjs/__chunks/{PFD4TS6B.cjs → WWDX5YPG.cjs} +28 -15
- package/cjs/combobox/combobox-item.cjs +1 -1
- package/cjs/combobox/combobox-popover.cjs +12 -11
- package/cjs/combobox/combobox-store.cjs +3 -3
- package/cjs/combobox/combobox-store.d.ts +0 -7
- package/cjs/combobox/combobox.cjs +3 -3
- package/cjs/composite/composite-item.cjs +1 -1
- package/cjs/composite/composite-overflow-disclosure.cjs +5 -5
- package/cjs/composite/composite-overflow-store.cjs +3 -3
- package/cjs/composite/composite-overflow-store.d.ts +1 -13
- package/cjs/composite/composite-overflow.cjs +12 -11
- package/cjs/composite/composite.cjs +3 -3
- package/cjs/dialog/dialog-backdrop.cjs +6 -3
- package/cjs/dialog/dialog-backdrop.d.ts +2 -5
- package/cjs/dialog/dialog-dismiss.cjs +1 -1
- package/cjs/dialog/dialog.cjs +11 -10
- package/cjs/dialog/dialog.d.ts +21 -8
- package/cjs/dialog/utils/is-backdrop.cjs +21 -0
- package/cjs/dialog/utils/is-backdrop.d.ts +1 -0
- package/cjs/form/form-radio.cjs +1 -1
- package/cjs/heading/heading-level.d.ts +1 -1
- package/cjs/hovercard/hovercard-dismiss.cjs +1 -1
- package/cjs/hovercard/hovercard-store.cjs +3 -3
- package/cjs/hovercard/hovercard-store.d.ts +1 -13
- package/cjs/hovercard/hovercard.cjs +13 -12
- package/cjs/menu/menu-bar.cjs +3 -3
- package/cjs/menu/menu-button.cjs +8 -8
- package/cjs/menu/menu-dismiss.cjs +1 -1
- package/cjs/menu/menu-item-checkbox.cjs +1 -1
- package/cjs/menu/menu-item-radio.cjs +1 -1
- package/cjs/menu/menu-item.cjs +1 -1
- package/cjs/menu/menu-list.cjs +4 -4
- package/cjs/menu/menu-store.cjs +7 -7
- package/cjs/menu/menu-store.d.ts +0 -7
- package/cjs/menu/menu.cjs +21 -20
- package/cjs/popover/popover-disclosure.cjs +4 -4
- package/cjs/popover/popover-dismiss.cjs +1 -1
- package/cjs/popover/popover-store.cjs +2 -2
- package/cjs/popover/popover-store.d.ts +1 -13
- package/cjs/popover/popover.cjs +12 -11
- package/cjs/popover/popover.d.ts +96 -0
- package/cjs/portal/portal.cjs +2 -2
- package/cjs/radio/radio-group.cjs +3 -3
- package/cjs/radio/radio.cjs +1 -1
- package/cjs/role/role.cjs +3 -14
- package/cjs/select/select-item.cjs +1 -1
- package/cjs/select/select-list.cjs +4 -4
- package/cjs/select/select-popover.cjs +21 -20
- package/cjs/select/select-store.cjs +3 -3
- package/cjs/select/select-store.d.ts +0 -7
- package/cjs/select/select.cjs +5 -5
- package/cjs/tab/tab-list.cjs +3 -3
- package/cjs/tab/tab-panel.cjs +3 -3
- package/cjs/tab/tab.cjs +1 -1
- package/cjs/toolbar/toolbar-container.cjs +1 -1
- package/cjs/toolbar/toolbar-input.cjs +1 -1
- package/cjs/toolbar/toolbar-item.cjs +1 -1
- package/cjs/toolbar/toolbar.cjs +3 -3
- package/cjs/tooltip/tooltip-anchor.cjs +58 -28
- package/cjs/tooltip/tooltip-anchor.d.ts +2 -18
- package/cjs/tooltip/tooltip-store.cjs +4 -3
- package/cjs/tooltip/tooltip-store.d.ts +5 -17
- package/cjs/tooltip/tooltip.cjs +66 -67
- package/cjs/tooltip/tooltip.d.ts +6 -25
- package/cjs/tsconfig.build.tsbuildinfo +1 -1
- package/dialog/utils/is-backdrop/package.json +7 -0
- package/esm/__chunks/{USCWE5QL.js → 2CA5JWPW.js} +28 -15
- package/esm/__chunks/5PIH3SMS.js +35 -0
- package/esm/__chunks/{PZK3B6LX.js → 776K5FXB.js} +1 -1
- package/esm/__chunks/{DQSQP4IL.js → GDDVBILZ.js} +1 -1
- package/esm/__chunks/{3L2YBPR3.js → HJWYYQGA.js} +1 -1
- package/esm/__chunks/{3FKA4P4C.js → K5R24MFH.js} +1 -1
- package/esm/__chunks/MLEIJKSM.js +363 -0
- package/esm/__chunks/{JXNLCNWG.js → MR75RQGW.js} +25 -44
- package/esm/__chunks/{TCX5FQUL.js → NAG6UD2X.js} +43 -55
- package/esm/__chunks/XIACQCPS.js +21 -0
- package/esm/combobox/combobox-item.js +1 -1
- package/esm/combobox/combobox-popover.js +11 -10
- package/esm/combobox/combobox-store.d.ts +0 -7
- package/esm/combobox/combobox-store.js +1 -1
- package/esm/combobox/combobox.js +2 -2
- package/esm/composite/composite-item.js +1 -1
- package/esm/composite/composite-overflow-disclosure.js +4 -4
- package/esm/composite/composite-overflow-store.d.ts +1 -13
- package/esm/composite/composite-overflow-store.js +1 -1
- package/esm/composite/composite-overflow.js +11 -10
- package/esm/composite/composite.js +2 -2
- package/esm/dialog/dialog-backdrop.d.ts +2 -5
- package/esm/dialog/dialog-backdrop.js +5 -2
- package/esm/dialog/dialog-dismiss.js +1 -1
- package/esm/dialog/dialog.d.ts +21 -8
- package/esm/dialog/dialog.js +10 -9
- package/esm/dialog/utils/is-backdrop.d.ts +1 -0
- package/esm/dialog/utils/is-backdrop.js +21 -0
- package/esm/form/form-radio.js +1 -1
- package/esm/heading/heading-level.d.ts +1 -1
- package/esm/hovercard/hovercard-dismiss.js +1 -1
- package/esm/hovercard/hovercard-store.d.ts +1 -13
- package/esm/hovercard/hovercard-store.js +2 -2
- package/esm/hovercard/hovercard.js +12 -11
- package/esm/menu/menu-bar.js +2 -2
- package/esm/menu/menu-button.js +7 -7
- package/esm/menu/menu-dismiss.js +1 -1
- package/esm/menu/menu-item-checkbox.js +1 -1
- package/esm/menu/menu-item-radio.js +1 -1
- package/esm/menu/menu-item.js +1 -1
- package/esm/menu/menu-list.js +3 -3
- package/esm/menu/menu-store.d.ts +0 -7
- package/esm/menu/menu-store.js +5 -5
- package/esm/menu/menu.js +20 -19
- package/esm/popover/popover-disclosure.js +3 -3
- package/esm/popover/popover-dismiss.js +1 -1
- package/esm/popover/popover-store.d.ts +1 -13
- package/esm/popover/popover-store.js +1 -1
- package/esm/popover/popover.d.ts +96 -0
- package/esm/popover/popover.js +11 -10
- package/esm/portal/portal.js +1 -1
- package/esm/radio/radio-group.js +2 -2
- package/esm/radio/radio.js +1 -1
- package/esm/role/role.js +4 -15
- package/esm/select/select-item.js +1 -1
- package/esm/select/select-list.js +3 -3
- package/esm/select/select-popover.js +19 -18
- package/esm/select/select-store.d.ts +0 -7
- package/esm/select/select-store.js +1 -1
- package/esm/select/select.js +4 -4
- package/esm/tab/tab-list.js +2 -2
- package/esm/tab/tab-panel.js +3 -3
- package/esm/tab/tab.js +1 -1
- package/esm/toolbar/toolbar-container.js +1 -1
- package/esm/toolbar/toolbar-input.js +1 -1
- package/esm/toolbar/toolbar-item.js +1 -1
- package/esm/toolbar/toolbar.js +2 -2
- package/esm/tooltip/tooltip-anchor.d.ts +2 -18
- package/esm/tooltip/tooltip-anchor.js +59 -29
- package/esm/tooltip/tooltip-store.d.ts +5 -17
- package/esm/tooltip/tooltip-store.js +6 -5
- package/esm/tooltip/tooltip.d.ts +6 -25
- package/esm/tooltip/tooltip.js +67 -68
- package/esm/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -2
- package/cjs/__chunks/FU76FHC2.cjs +0 -125
- package/esm/__chunks/RVIGSXKO.js +0 -125
- package/esm/__chunks/SHGWT5HV.js +0 -54
- package/cjs/__chunks/{OV363CW6.cjs → BDJYHP43.cjs} +2 -2
- package/cjs/__chunks/{5I6IQHKQ.cjs → BIPONQXE.cjs} +2 -2
- package/esm/__chunks/{OY5YT7OV.js → RTOWJJVI.js} +3 -3
- package/esm/__chunks/{6O3TZMB4.js → U2KSDJ3W.js} +3 -3
|
@@ -62,10 +62,10 @@ var usePortal = createHook(
|
|
|
62
62
|
const refProp = useForkRef(ref, props.ref);
|
|
63
63
|
const context = useContext(PortalContext);
|
|
64
64
|
const [portalNode, setPortalNode] = useState(null);
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
65
|
+
const outerBeforeRef = useRef(null);
|
|
66
|
+
const innerBeforeRef = useRef(null);
|
|
67
|
+
const innerAfterRef = useRef(null);
|
|
68
|
+
const outerAfterRef = useRef(null);
|
|
69
69
|
useSafeLayoutEffect(() => {
|
|
70
70
|
const element = ref.current;
|
|
71
71
|
if (!element || !portal) {
|
|
@@ -83,7 +83,7 @@ var usePortal = createHook(
|
|
|
83
83
|
rootElement.appendChild(portalEl);
|
|
84
84
|
}
|
|
85
85
|
if (!portalEl.id) {
|
|
86
|
-
portalEl.id = element.id ?
|
|
86
|
+
portalEl.id = element.id ? `portal/${element.id}` : getRandomId();
|
|
87
87
|
}
|
|
88
88
|
setPortalNode(portalEl);
|
|
89
89
|
setRef(portalRef, portalEl);
|
|
@@ -142,12 +142,13 @@ var usePortal = createHook(
|
|
|
142
142
|
preserveTabOrder && portalNode && /* @__PURE__ */ jsx(
|
|
143
143
|
FocusTrap,
|
|
144
144
|
{
|
|
145
|
-
ref:
|
|
145
|
+
ref: innerBeforeRef,
|
|
146
|
+
className: "__focus-trap-inner-before",
|
|
146
147
|
onFocus: (event) => {
|
|
147
148
|
if (isFocusEventOutside(event, portalNode)) {
|
|
148
149
|
queueFocus(getNextTabbable());
|
|
149
150
|
} else {
|
|
150
|
-
queueFocus(
|
|
151
|
+
queueFocus(outerBeforeRef.current);
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
154
|
}
|
|
@@ -156,12 +157,13 @@ var usePortal = createHook(
|
|
|
156
157
|
preserveTabOrder && portalNode && /* @__PURE__ */ jsx(
|
|
157
158
|
FocusTrap,
|
|
158
159
|
{
|
|
159
|
-
ref:
|
|
160
|
+
ref: innerAfterRef,
|
|
161
|
+
className: "__focus-trap-inner-after",
|
|
160
162
|
onFocus: (event) => {
|
|
161
163
|
if (isFocusEventOutside(event, portalNode)) {
|
|
162
164
|
queueFocus(getPreviousTabbable());
|
|
163
165
|
} else {
|
|
164
|
-
queueFocus(
|
|
166
|
+
queueFocus(outerAfterRef.current);
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
}
|
|
@@ -174,10 +176,12 @@ var usePortal = createHook(
|
|
|
174
176
|
preserveTabOrder && portalNode && /* @__PURE__ */ jsx(
|
|
175
177
|
FocusTrap,
|
|
176
178
|
{
|
|
177
|
-
ref:
|
|
179
|
+
ref: outerBeforeRef,
|
|
180
|
+
className: "__focus-trap-outer-before",
|
|
178
181
|
onFocus: (event) => {
|
|
179
|
-
|
|
180
|
-
|
|
182
|
+
const fromOuter = event.relatedTarget === outerAfterRef.current;
|
|
183
|
+
if (!fromOuter && isFocusEventOutside(event, portalNode)) {
|
|
184
|
+
queueFocus(innerBeforeRef.current);
|
|
181
185
|
} else {
|
|
182
186
|
queueFocus(getPreviousTabbable());
|
|
183
187
|
}
|
|
@@ -191,12 +195,21 @@ var usePortal = createHook(
|
|
|
191
195
|
preserveTabOrder && portalNode && /* @__PURE__ */ jsx(
|
|
192
196
|
FocusTrap,
|
|
193
197
|
{
|
|
194
|
-
ref:
|
|
198
|
+
ref: outerAfterRef,
|
|
199
|
+
className: "__focus-trap-outer-after",
|
|
195
200
|
onFocus: (event) => {
|
|
196
201
|
if (isFocusEventOutside(event, portalNode)) {
|
|
197
|
-
queueFocus(
|
|
202
|
+
queueFocus(innerAfterRef.current);
|
|
198
203
|
} else {
|
|
199
|
-
|
|
204
|
+
const nextTabbable = getNextTabbable();
|
|
205
|
+
if (nextTabbable === innerBeforeRef.current) {
|
|
206
|
+
requestAnimationFrame(() => {
|
|
207
|
+
var _a2;
|
|
208
|
+
return (_a2 = getNextTabbable()) == null ? void 0 : _a2.focus();
|
|
209
|
+
});
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
queueFocus(nextTabbable);
|
|
200
213
|
}
|
|
201
214
|
}
|
|
202
215
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useDialogStoreOptions,
|
|
3
|
+
useDialogStoreProps
|
|
4
|
+
} from "./OBNQHP6V.js";
|
|
5
|
+
import {
|
|
6
|
+
useStore,
|
|
7
|
+
useStoreProps
|
|
8
|
+
} from "./AV5WE37O.js";
|
|
9
|
+
import {
|
|
10
|
+
__spreadValues
|
|
11
|
+
} from "./4BKCJXBM.js";
|
|
12
|
+
|
|
13
|
+
// src/popover/popover-store.ts
|
|
14
|
+
import * as Core from "@ariakit/core/popover/popover-store";
|
|
15
|
+
function usePopoverStoreOptions(props) {
|
|
16
|
+
return useDialogStoreOptions(props);
|
|
17
|
+
}
|
|
18
|
+
function usePopoverStoreProps(store, props) {
|
|
19
|
+
store = useDialogStoreProps(store, props);
|
|
20
|
+
useStoreProps(store, props, "placement");
|
|
21
|
+
return store;
|
|
22
|
+
}
|
|
23
|
+
function usePopoverStore(props = {}) {
|
|
24
|
+
const options = usePopoverStoreOptions(props);
|
|
25
|
+
const store = useStore(
|
|
26
|
+
() => Core.createPopoverStore(__spreadValues(__spreadValues({}, props), options))
|
|
27
|
+
);
|
|
28
|
+
return usePopoverStoreProps(store, props);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
usePopoverStoreOptions,
|
|
33
|
+
usePopoverStoreProps,
|
|
34
|
+
usePopoverStore
|
|
35
|
+
};
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useDialog
|
|
3
|
+
} from "./NAG6UD2X.js";
|
|
4
|
+
import {
|
|
5
|
+
PopoverContext
|
|
6
|
+
} from "./6GS36SYX.js";
|
|
7
|
+
import {
|
|
8
|
+
createComponent,
|
|
9
|
+
createElement,
|
|
10
|
+
createHook
|
|
11
|
+
} from "./5ETIGB6O.js";
|
|
12
|
+
import {
|
|
13
|
+
useEvent,
|
|
14
|
+
usePortalRef,
|
|
15
|
+
useSafeLayoutEffect,
|
|
16
|
+
useWrapElement
|
|
17
|
+
} from "./ASYR66PQ.js";
|
|
18
|
+
import {
|
|
19
|
+
__objRest,
|
|
20
|
+
__spreadProps,
|
|
21
|
+
__spreadValues
|
|
22
|
+
} from "./4BKCJXBM.js";
|
|
23
|
+
|
|
24
|
+
// src/popover/popover.tsx
|
|
25
|
+
import { useState } from "react";
|
|
26
|
+
import { invariant } from "@ariakit/core/utils/misc";
|
|
27
|
+
import {
|
|
28
|
+
arrow,
|
|
29
|
+
autoUpdate,
|
|
30
|
+
computePosition,
|
|
31
|
+
flip,
|
|
32
|
+
offset,
|
|
33
|
+
shift,
|
|
34
|
+
size
|
|
35
|
+
} from "@floating-ui/dom";
|
|
36
|
+
import { jsx } from "react/jsx-runtime";
|
|
37
|
+
function createDOMRect(x = 0, y = 0, width = 0, height = 0) {
|
|
38
|
+
if (typeof DOMRect === "function") {
|
|
39
|
+
return new DOMRect(x, y, width, height);
|
|
40
|
+
}
|
|
41
|
+
const rect = {
|
|
42
|
+
x,
|
|
43
|
+
y,
|
|
44
|
+
width,
|
|
45
|
+
height,
|
|
46
|
+
top: y,
|
|
47
|
+
right: x + width,
|
|
48
|
+
bottom: y + height,
|
|
49
|
+
left: x
|
|
50
|
+
};
|
|
51
|
+
return __spreadProps(__spreadValues({}, rect), { toJSON: () => rect });
|
|
52
|
+
}
|
|
53
|
+
function getDOMRect(anchorRect) {
|
|
54
|
+
if (!anchorRect)
|
|
55
|
+
return createDOMRect();
|
|
56
|
+
const { x, y, width, height } = anchorRect;
|
|
57
|
+
return createDOMRect(x, y, width, height);
|
|
58
|
+
}
|
|
59
|
+
function getAnchorElement(anchorElement, getAnchorRect) {
|
|
60
|
+
const contextElement = anchorElement || void 0;
|
|
61
|
+
return {
|
|
62
|
+
contextElement,
|
|
63
|
+
getBoundingClientRect: () => {
|
|
64
|
+
const anchor = anchorElement;
|
|
65
|
+
const anchorRect = getAnchorRect == null ? void 0 : getAnchorRect(anchor);
|
|
66
|
+
if (anchorRect || !anchor) {
|
|
67
|
+
return getDOMRect(anchorRect);
|
|
68
|
+
}
|
|
69
|
+
return anchor.getBoundingClientRect();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function isValidPlacement(flip2) {
|
|
74
|
+
return /^(?:top|bottom|left|right)(?:-(?:start|end))?$/.test(flip2);
|
|
75
|
+
}
|
|
76
|
+
function roundByDPR(value) {
|
|
77
|
+
const dpr = window.devicePixelRatio || 1;
|
|
78
|
+
return Math.round(value * dpr) / dpr;
|
|
79
|
+
}
|
|
80
|
+
function getOffsetMiddleware(arrowElement, props) {
|
|
81
|
+
return offset(({ placement }) => {
|
|
82
|
+
var _a;
|
|
83
|
+
const arrowOffset = ((arrowElement == null ? void 0 : arrowElement.clientHeight) || 0) / 2;
|
|
84
|
+
const finalGutter = typeof props.gutter === "number" ? props.gutter + arrowOffset : (_a = props.gutter) != null ? _a : arrowOffset;
|
|
85
|
+
const hasAlignment = !!placement.split("-")[1];
|
|
86
|
+
return {
|
|
87
|
+
crossAxis: !hasAlignment ? props.shift : void 0,
|
|
88
|
+
mainAxis: finalGutter,
|
|
89
|
+
alignmentAxis: props.shift
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function getFlipMiddleware(props) {
|
|
94
|
+
if (props.flip === false)
|
|
95
|
+
return;
|
|
96
|
+
const fallbackPlacements = typeof props.flip === "string" ? props.flip.split(" ") : void 0;
|
|
97
|
+
invariant(
|
|
98
|
+
!fallbackPlacements || fallbackPlacements.every(isValidPlacement),
|
|
99
|
+
process.env.NODE_ENV !== "production" && "`flip` expects a spaced-delimited list of placements"
|
|
100
|
+
);
|
|
101
|
+
return flip({
|
|
102
|
+
padding: props.overflowPadding,
|
|
103
|
+
fallbackPlacements
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function getShiftMiddleware(props) {
|
|
107
|
+
if (!props.slide && !props.overlap)
|
|
108
|
+
return;
|
|
109
|
+
return shift({
|
|
110
|
+
mainAxis: props.slide,
|
|
111
|
+
crossAxis: props.overlap,
|
|
112
|
+
padding: props.overflowPadding
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function getSizeMiddleware(props) {
|
|
116
|
+
return size({
|
|
117
|
+
padding: props.overflowPadding,
|
|
118
|
+
apply({ elements, availableWidth, availableHeight, rects }) {
|
|
119
|
+
const wrapper = elements.floating;
|
|
120
|
+
const referenceWidth = Math.round(rects.reference.width);
|
|
121
|
+
availableWidth = Math.floor(availableWidth);
|
|
122
|
+
availableHeight = Math.floor(availableHeight);
|
|
123
|
+
wrapper.style.setProperty(
|
|
124
|
+
"--popover-anchor-width",
|
|
125
|
+
`${referenceWidth}px`
|
|
126
|
+
);
|
|
127
|
+
wrapper.style.setProperty(
|
|
128
|
+
"--popover-available-width",
|
|
129
|
+
`${availableWidth}px`
|
|
130
|
+
);
|
|
131
|
+
wrapper.style.setProperty(
|
|
132
|
+
"--popover-available-height",
|
|
133
|
+
`${availableHeight}px`
|
|
134
|
+
);
|
|
135
|
+
if (props.sameWidth) {
|
|
136
|
+
wrapper.style.width = `${referenceWidth}px`;
|
|
137
|
+
}
|
|
138
|
+
if (props.fitViewport) {
|
|
139
|
+
wrapper.style.maxWidth = `${availableWidth}px`;
|
|
140
|
+
wrapper.style.maxHeight = `${availableHeight}px`;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function getArrowMiddleware(arrowElement, props) {
|
|
146
|
+
if (!arrowElement)
|
|
147
|
+
return;
|
|
148
|
+
return arrow({
|
|
149
|
+
element: arrowElement,
|
|
150
|
+
padding: props.arrowPadding
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
var usePopover = createHook(
|
|
154
|
+
(_a) => {
|
|
155
|
+
var _b = _a, {
|
|
156
|
+
store,
|
|
157
|
+
modal = false,
|
|
158
|
+
portal = !!modal,
|
|
159
|
+
preserveTabOrder = true,
|
|
160
|
+
autoFocusOnShow = true,
|
|
161
|
+
wrapperProps,
|
|
162
|
+
fixed = false,
|
|
163
|
+
flip: flip2 = true,
|
|
164
|
+
shift: shift2 = 0,
|
|
165
|
+
slide = true,
|
|
166
|
+
overlap = false,
|
|
167
|
+
sameWidth = false,
|
|
168
|
+
fitViewport = false,
|
|
169
|
+
gutter,
|
|
170
|
+
arrowPadding = 4,
|
|
171
|
+
overflowPadding = 8,
|
|
172
|
+
getAnchorRect,
|
|
173
|
+
updatePosition
|
|
174
|
+
} = _b, props = __objRest(_b, [
|
|
175
|
+
"store",
|
|
176
|
+
"modal",
|
|
177
|
+
"portal",
|
|
178
|
+
"preserveTabOrder",
|
|
179
|
+
"autoFocusOnShow",
|
|
180
|
+
"wrapperProps",
|
|
181
|
+
"fixed",
|
|
182
|
+
"flip",
|
|
183
|
+
"shift",
|
|
184
|
+
"slide",
|
|
185
|
+
"overlap",
|
|
186
|
+
"sameWidth",
|
|
187
|
+
"fitViewport",
|
|
188
|
+
"gutter",
|
|
189
|
+
"arrowPadding",
|
|
190
|
+
"overflowPadding",
|
|
191
|
+
"getAnchorRect",
|
|
192
|
+
"updatePosition"
|
|
193
|
+
]);
|
|
194
|
+
const arrowElement = store.useState("arrowElement");
|
|
195
|
+
const anchorElement = store.useState("anchorElement");
|
|
196
|
+
const popoverElement = store.useState("popoverElement");
|
|
197
|
+
const contentElement = store.useState("contentElement");
|
|
198
|
+
const placement = store.useState("placement");
|
|
199
|
+
const mounted = store.useState("mounted");
|
|
200
|
+
const rendered = store.useState("rendered");
|
|
201
|
+
const [positioned, setPositioned] = useState(false);
|
|
202
|
+
const { portalRef, domReady } = usePortalRef(portal, props.portalRef);
|
|
203
|
+
const getAnchorRectProp = useEvent(getAnchorRect);
|
|
204
|
+
const hasCustomUpdatePosition = !!updatePosition;
|
|
205
|
+
const updatePositionProp = useEvent(updatePosition);
|
|
206
|
+
useSafeLayoutEffect(() => {
|
|
207
|
+
if (!(popoverElement == null ? void 0 : popoverElement.isConnected))
|
|
208
|
+
return;
|
|
209
|
+
popoverElement.style.setProperty(
|
|
210
|
+
"--popover-overflow-padding",
|
|
211
|
+
`${overflowPadding}px`
|
|
212
|
+
);
|
|
213
|
+
const anchor = getAnchorElement(anchorElement, getAnchorRectProp);
|
|
214
|
+
const update = async () => {
|
|
215
|
+
if (!mounted)
|
|
216
|
+
return;
|
|
217
|
+
const middleware = [
|
|
218
|
+
getOffsetMiddleware(arrowElement, { gutter, shift: shift2 }),
|
|
219
|
+
getFlipMiddleware({ flip: flip2, overflowPadding }),
|
|
220
|
+
getShiftMiddleware({ slide, overlap, overflowPadding }),
|
|
221
|
+
getArrowMiddleware(arrowElement, { arrowPadding }),
|
|
222
|
+
getSizeMiddleware({
|
|
223
|
+
sameWidth,
|
|
224
|
+
fitViewport,
|
|
225
|
+
overflowPadding
|
|
226
|
+
})
|
|
227
|
+
];
|
|
228
|
+
const pos = await computePosition(anchor, popoverElement, {
|
|
229
|
+
placement,
|
|
230
|
+
strategy: fixed ? "fixed" : "absolute",
|
|
231
|
+
middleware
|
|
232
|
+
});
|
|
233
|
+
store.setState("currentPlacement", pos.placement);
|
|
234
|
+
setPositioned(true);
|
|
235
|
+
const x = roundByDPR(pos.x);
|
|
236
|
+
const y = roundByDPR(pos.y);
|
|
237
|
+
Object.assign(popoverElement.style, {
|
|
238
|
+
top: "0",
|
|
239
|
+
left: "0",
|
|
240
|
+
transform: `translate3d(${x}px,${y}px,0)`
|
|
241
|
+
});
|
|
242
|
+
if (arrowElement && pos.middlewareData.arrow) {
|
|
243
|
+
const { x: arrowX, y: arrowY } = pos.middlewareData.arrow;
|
|
244
|
+
const dir = pos.placement.split("-")[0];
|
|
245
|
+
Object.assign(arrowElement.style, {
|
|
246
|
+
left: arrowX != null ? `${arrowX}px` : "",
|
|
247
|
+
top: arrowY != null ? `${arrowY}px` : "",
|
|
248
|
+
[dir]: "100%"
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
return autoUpdate(
|
|
253
|
+
anchor,
|
|
254
|
+
popoverElement,
|
|
255
|
+
() => {
|
|
256
|
+
if (hasCustomUpdatePosition) {
|
|
257
|
+
updatePositionProp({ updatePosition: update });
|
|
258
|
+
} else {
|
|
259
|
+
update();
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
// JSDOM doesn't support ResizeObserver
|
|
264
|
+
elementResize: typeof ResizeObserver === "function"
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
}, [
|
|
268
|
+
store,
|
|
269
|
+
rendered,
|
|
270
|
+
popoverElement,
|
|
271
|
+
arrowElement,
|
|
272
|
+
anchorElement,
|
|
273
|
+
popoverElement,
|
|
274
|
+
placement,
|
|
275
|
+
mounted,
|
|
276
|
+
domReady,
|
|
277
|
+
fixed,
|
|
278
|
+
flip2,
|
|
279
|
+
shift2,
|
|
280
|
+
slide,
|
|
281
|
+
overlap,
|
|
282
|
+
sameWidth,
|
|
283
|
+
fitViewport,
|
|
284
|
+
gutter,
|
|
285
|
+
arrowPadding,
|
|
286
|
+
overflowPadding,
|
|
287
|
+
getAnchorRectProp,
|
|
288
|
+
hasCustomUpdatePosition,
|
|
289
|
+
updatePositionProp
|
|
290
|
+
]);
|
|
291
|
+
useSafeLayoutEffect(() => {
|
|
292
|
+
if (!mounted)
|
|
293
|
+
return;
|
|
294
|
+
if (!domReady)
|
|
295
|
+
return;
|
|
296
|
+
if (!(popoverElement == null ? void 0 : popoverElement.isConnected))
|
|
297
|
+
return;
|
|
298
|
+
if (!(contentElement == null ? void 0 : contentElement.isConnected))
|
|
299
|
+
return;
|
|
300
|
+
const applyZIndex = () => {
|
|
301
|
+
popoverElement.style.zIndex = getComputedStyle(contentElement).zIndex;
|
|
302
|
+
};
|
|
303
|
+
applyZIndex();
|
|
304
|
+
let raf = requestAnimationFrame(() => {
|
|
305
|
+
raf = requestAnimationFrame(applyZIndex);
|
|
306
|
+
});
|
|
307
|
+
return () => cancelAnimationFrame(raf);
|
|
308
|
+
}, [mounted, domReady, popoverElement, contentElement]);
|
|
309
|
+
const position = fixed ? "fixed" : "absolute";
|
|
310
|
+
props = useWrapElement(
|
|
311
|
+
props,
|
|
312
|
+
(element) => /* @__PURE__ */ jsx(
|
|
313
|
+
"div",
|
|
314
|
+
__spreadProps(__spreadValues({
|
|
315
|
+
role: "presentation"
|
|
316
|
+
}, wrapperProps), {
|
|
317
|
+
style: __spreadValues({
|
|
318
|
+
// https://floating-ui.com/docs/computeposition#initial-layout
|
|
319
|
+
position,
|
|
320
|
+
top: 0,
|
|
321
|
+
left: 0,
|
|
322
|
+
width: "max-content"
|
|
323
|
+
}, wrapperProps == null ? void 0 : wrapperProps.style),
|
|
324
|
+
ref: store.setPopoverElement,
|
|
325
|
+
children: element
|
|
326
|
+
})
|
|
327
|
+
),
|
|
328
|
+
[store, position, wrapperProps]
|
|
329
|
+
);
|
|
330
|
+
props = useWrapElement(
|
|
331
|
+
props,
|
|
332
|
+
(element) => /* @__PURE__ */ jsx(PopoverContext.Provider, { value: store, children: element }),
|
|
333
|
+
[store]
|
|
334
|
+
);
|
|
335
|
+
props = __spreadProps(__spreadValues({}, props), {
|
|
336
|
+
style: __spreadValues({
|
|
337
|
+
position: "relative"
|
|
338
|
+
}, props.style)
|
|
339
|
+
});
|
|
340
|
+
props = useDialog(__spreadProps(__spreadValues({
|
|
341
|
+
store,
|
|
342
|
+
modal,
|
|
343
|
+
preserveTabOrder,
|
|
344
|
+
portal,
|
|
345
|
+
autoFocusOnShow: positioned && autoFocusOnShow
|
|
346
|
+
}, props), {
|
|
347
|
+
portalRef
|
|
348
|
+
}));
|
|
349
|
+
return props;
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
var Popover = createComponent((props) => {
|
|
353
|
+
const htmlProps = usePopover(props);
|
|
354
|
+
return createElement("div", htmlProps);
|
|
355
|
+
});
|
|
356
|
+
if (process.env.NODE_ENV !== "production") {
|
|
357
|
+
Popover.displayName = "Popover";
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export {
|
|
361
|
+
usePopover,
|
|
362
|
+
Popover
|
|
363
|
+
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./
|
|
2
|
+
markAncestor
|
|
3
|
+
} from "./BH4YAZB2.js";
|
|
4
|
+
import {
|
|
5
|
+
Role
|
|
6
|
+
} from "./XIACQCPS.js";
|
|
4
7
|
import {
|
|
5
8
|
useDisclosureContent
|
|
6
9
|
} from "./6AJCHLAV.js";
|
|
7
10
|
import {
|
|
8
|
-
useBooleanEvent,
|
|
9
|
-
useEvent,
|
|
10
11
|
useForkRef,
|
|
11
12
|
useSafeLayoutEffect
|
|
12
13
|
} from "./ASYR66PQ.js";
|
|
@@ -16,18 +17,14 @@ import {
|
|
|
16
17
|
} from "./4BKCJXBM.js";
|
|
17
18
|
|
|
18
19
|
// src/dialog/dialog-backdrop.tsx
|
|
19
|
-
import { useMemo, useRef } from "react";
|
|
20
|
-
import { isSelfTarget } from "@ariakit/core/utils/events";
|
|
20
|
+
import { cloneElement, isValidElement, useMemo, useRef } from "react";
|
|
21
21
|
import { noop } from "@ariakit/core/utils/misc";
|
|
22
22
|
import { jsx } from "react/jsx-runtime";
|
|
23
23
|
function DialogBackdrop({
|
|
24
24
|
store,
|
|
25
25
|
backdrop,
|
|
26
26
|
backdropProps,
|
|
27
|
-
|
|
28
|
-
hideOnEscape = true,
|
|
29
|
-
hidden,
|
|
30
|
-
children
|
|
27
|
+
hidden
|
|
31
28
|
}) {
|
|
32
29
|
const ref = useRef(null);
|
|
33
30
|
store = useMemo(
|
|
@@ -48,47 +45,26 @@ function DialogBackdrop({
|
|
|
48
45
|
return;
|
|
49
46
|
backdrop2.style.zIndex = getComputedStyle(dialog).zIndex;
|
|
50
47
|
}, [contentElement]);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const previousMouseDownRef = usePreviousMouseDownRef(mounted);
|
|
55
|
-
const onClick = useEvent((event) => {
|
|
56
|
-
onClickProp == null ? void 0 : onClickProp(event);
|
|
57
|
-
if (event.defaultPrevented)
|
|
58
|
-
return;
|
|
59
|
-
if (!isSelfTarget(event))
|
|
60
|
-
return;
|
|
61
|
-
if (previousMouseDownRef.current !== event.currentTarget)
|
|
62
|
-
return;
|
|
63
|
-
if (!hideOnInteractOutsideProp(event))
|
|
64
|
-
return;
|
|
65
|
-
event.stopPropagation();
|
|
66
|
-
store.hide();
|
|
67
|
-
});
|
|
68
|
-
const onKeyDownProp = backdropProps == null ? void 0 : backdropProps.onKeyDown;
|
|
69
|
-
const hideOnEscapeProp = useBooleanEvent(hideOnEscape);
|
|
70
|
-
const onKeyDown = useEvent((event) => {
|
|
71
|
-
onKeyDownProp == null ? void 0 : onKeyDownProp(event);
|
|
72
|
-
if (event.defaultPrevented)
|
|
73
|
-
return;
|
|
74
|
-
if (event.key !== "Escape")
|
|
75
|
-
return;
|
|
76
|
-
if (!isSelfTarget(event))
|
|
48
|
+
useSafeLayoutEffect(() => {
|
|
49
|
+
const id = contentElement == null ? void 0 : contentElement.id;
|
|
50
|
+
if (!id)
|
|
77
51
|
return;
|
|
78
|
-
|
|
52
|
+
const backdrop2 = ref.current;
|
|
53
|
+
if (!backdrop2)
|
|
79
54
|
return;
|
|
80
|
-
|
|
81
|
-
});
|
|
55
|
+
return markAncestor(backdrop2, id);
|
|
56
|
+
}, [contentElement]);
|
|
57
|
+
backdropProps = isValidElement(backdrop) ? __spreadValues(__spreadValues({
|
|
58
|
+
ref: "ref" in backdrop ? backdrop.ref : void 0
|
|
59
|
+
}, backdrop.props), backdropProps) : backdropProps;
|
|
82
60
|
const props = useDisclosureContent(__spreadProps(__spreadValues({
|
|
83
61
|
store,
|
|
84
62
|
id: void 0,
|
|
85
63
|
role: "presentation",
|
|
86
|
-
|
|
87
|
-
|
|
64
|
+
hidden,
|
|
65
|
+
"data-backdrop": (contentElement == null ? void 0 : contentElement.id) || ""
|
|
88
66
|
}, backdropProps), {
|
|
89
67
|
ref: useForkRef(backdropProps == null ? void 0 : backdropProps.ref, ref),
|
|
90
|
-
onClick,
|
|
91
|
-
onKeyDown,
|
|
92
68
|
style: __spreadValues({
|
|
93
69
|
position: "fixed",
|
|
94
70
|
top: 0,
|
|
@@ -97,8 +73,13 @@ function DialogBackdrop({
|
|
|
97
73
|
left: 0
|
|
98
74
|
}, backdropProps == null ? void 0 : backdropProps.style)
|
|
99
75
|
}));
|
|
76
|
+
if (!backdrop)
|
|
77
|
+
return null;
|
|
78
|
+
if (isValidElement(backdrop)) {
|
|
79
|
+
return /* @__PURE__ */ jsx(Role, __spreadProps(__spreadValues({}, props), { children: (props2) => cloneElement(backdrop, props2) }));
|
|
80
|
+
}
|
|
100
81
|
const Component = typeof backdrop !== "boolean" ? backdrop || "div" : "div";
|
|
101
|
-
return /* @__PURE__ */ jsx(
|
|
82
|
+
return /* @__PURE__ */ jsx(Role, __spreadProps(__spreadValues({}, props), { as: Component }));
|
|
102
83
|
}
|
|
103
84
|
|
|
104
85
|
export {
|