@huin-core/react-popover 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,96 @@
1
+ import * as React$1 from 'react';
2
+ import React__default from 'react';
3
+ import * as PopperPrimitive from '@huin-core/react-popper';
4
+ import { Primitive } from '@huin-core/react-primitive';
5
+ import { Portal } from '@huin-core/react-portal';
6
+ import { DismissableLayer } from '@huin-core/react-dismissable-layer';
7
+ import { FocusScope } from '@huin-core/react-focus-scope';
8
+
9
+ type Scope<C = any> = {
10
+ [scopeName: string]: React$1.Context<C>[];
11
+ } | undefined;
12
+ type ScopeHook = (scope: Scope) => {
13
+ [__scopeProp: string]: Scope;
14
+ };
15
+ interface CreateScope {
16
+ scopeName: string;
17
+ (): ScopeHook;
18
+ }
19
+
20
+ declare const createPopoverScope: CreateScope;
21
+ interface PopoverProps {
22
+ children?: React$1.ReactNode;
23
+ open?: boolean;
24
+ defaultOpen?: boolean;
25
+ onOpenChange?: (open: boolean) => void;
26
+ modal?: boolean;
27
+ }
28
+ declare const Popover: React$1.FC<PopoverProps>;
29
+ declare const Root: React$1.FC<PopoverProps>;
30
+
31
+ type PopperAnchorProps = React__default.ComponentPropsWithoutRef<typeof PopperPrimitive.Anchor>;
32
+ interface PopoverAnchorProps extends PopperAnchorProps {
33
+ }
34
+ declare const PopoverAnchor: React__default.ForwardRefExoticComponent<PopoverAnchorProps & React__default.RefAttributes<HTMLDivElement>>;
35
+
36
+ type PrimitiveButtonProps = React__default.ComponentPropsWithoutRef<typeof Primitive.button>;
37
+ interface PopoverTriggerProps extends PrimitiveButtonProps {
38
+ }
39
+ declare const PopoverTrigger: React__default.ForwardRefExoticComponent<PopoverTriggerProps & React__default.RefAttributes<HTMLButtonElement>>;
40
+
41
+ type PortalProps = React.ComponentPropsWithoutRef<typeof Portal>;
42
+ interface PopoverPortalProps {
43
+ children?: React.ReactNode;
44
+ /**
45
+ * Specify a container element to portal the content into.
46
+ */
47
+ container?: PortalProps["container"];
48
+ /**
49
+ * Used to force mounting when more control is needed. Useful when
50
+ * controlling animation with React animation libraries.
51
+ */
52
+ forceMount?: true;
53
+ }
54
+ declare const PopoverPortal: React.FC<PopoverPortalProps>;
55
+
56
+ interface PopoverContentProps extends PopoverContentTypeProps {
57
+ /**
58
+ * Used to force mounting when more control is needed. Useful when
59
+ * controlling animation with React animation libraries.
60
+ */
61
+ forceMount?: true;
62
+ }
63
+ declare const PopoverContent: React__default.ForwardRefExoticComponent<PopoverContentProps & React__default.RefAttributes<HTMLDivElement>>;
64
+ interface PopoverContentTypeProps extends Omit<PopoverContentImplProps, "trapFocus" | "disableOutsidePointerEvents"> {
65
+ }
66
+ type FocusScopeProps = React__default.ComponentPropsWithoutRef<typeof FocusScope>;
67
+ type DismissableLayerProps = React__default.ComponentPropsWithoutRef<typeof DismissableLayer>;
68
+ type PopperContentProps = React__default.ComponentPropsWithoutRef<typeof PopperPrimitive.Content>;
69
+ interface PopoverContentImplProps extends Omit<PopperContentProps, "onPlaced">, Omit<DismissableLayerProps, "onDismiss"> {
70
+ /**
71
+ * Whether focus should be trapped within the `Popover`
72
+ * (default: false)
73
+ */
74
+ trapFocus?: FocusScopeProps["trapped"];
75
+ /**
76
+ * Event handler called when auto-focusing on open.
77
+ * Can be prevented.
78
+ */
79
+ onOpenAutoFocus?: FocusScopeProps["onMountAutoFocus"];
80
+ /**
81
+ * Event handler called when auto-focusing on close.
82
+ * Can be prevented.
83
+ */
84
+ onCloseAutoFocus?: FocusScopeProps["onUnmountAutoFocus"];
85
+ }
86
+
87
+ interface PopoverCloseProps extends PrimitiveButtonProps {
88
+ }
89
+ declare const PopoverClose: React__default.ForwardRefExoticComponent<PopoverCloseProps & React__default.RefAttributes<HTMLButtonElement>>;
90
+
91
+ type PopperArrowProps = React__default.ComponentPropsWithoutRef<typeof PopperPrimitive.Arrow>;
92
+ interface PopoverArrowProps extends PopperArrowProps {
93
+ }
94
+ declare const PopoverArrow: React__default.ForwardRefExoticComponent<PopoverArrowProps & React__default.RefAttributes<SVGSVGElement>>;
95
+
96
+ export { Popover, PopoverAnchor, type PopoverAnchorProps, PopoverArrow, type PopoverArrowProps, PopoverClose, type PopoverCloseProps, PopoverContent, type PopoverContentProps, PopoverPortal, type PopoverPortalProps, type PopoverProps, PopoverTrigger, type PopoverTriggerProps, Root, createPopoverScope };
@@ -0,0 +1,96 @@
1
+ import * as React$1 from 'react';
2
+ import React__default from 'react';
3
+ import * as PopperPrimitive from '@huin-core/react-popper';
4
+ import { Primitive } from '@huin-core/react-primitive';
5
+ import { Portal } from '@huin-core/react-portal';
6
+ import { DismissableLayer } from '@huin-core/react-dismissable-layer';
7
+ import { FocusScope } from '@huin-core/react-focus-scope';
8
+
9
+ type Scope<C = any> = {
10
+ [scopeName: string]: React$1.Context<C>[];
11
+ } | undefined;
12
+ type ScopeHook = (scope: Scope) => {
13
+ [__scopeProp: string]: Scope;
14
+ };
15
+ interface CreateScope {
16
+ scopeName: string;
17
+ (): ScopeHook;
18
+ }
19
+
20
+ declare const createPopoverScope: CreateScope;
21
+ interface PopoverProps {
22
+ children?: React$1.ReactNode;
23
+ open?: boolean;
24
+ defaultOpen?: boolean;
25
+ onOpenChange?: (open: boolean) => void;
26
+ modal?: boolean;
27
+ }
28
+ declare const Popover: React$1.FC<PopoverProps>;
29
+ declare const Root: React$1.FC<PopoverProps>;
30
+
31
+ type PopperAnchorProps = React__default.ComponentPropsWithoutRef<typeof PopperPrimitive.Anchor>;
32
+ interface PopoverAnchorProps extends PopperAnchorProps {
33
+ }
34
+ declare const PopoverAnchor: React__default.ForwardRefExoticComponent<PopoverAnchorProps & React__default.RefAttributes<HTMLDivElement>>;
35
+
36
+ type PrimitiveButtonProps = React__default.ComponentPropsWithoutRef<typeof Primitive.button>;
37
+ interface PopoverTriggerProps extends PrimitiveButtonProps {
38
+ }
39
+ declare const PopoverTrigger: React__default.ForwardRefExoticComponent<PopoverTriggerProps & React__default.RefAttributes<HTMLButtonElement>>;
40
+
41
+ type PortalProps = React.ComponentPropsWithoutRef<typeof Portal>;
42
+ interface PopoverPortalProps {
43
+ children?: React.ReactNode;
44
+ /**
45
+ * Specify a container element to portal the content into.
46
+ */
47
+ container?: PortalProps["container"];
48
+ /**
49
+ * Used to force mounting when more control is needed. Useful when
50
+ * controlling animation with React animation libraries.
51
+ */
52
+ forceMount?: true;
53
+ }
54
+ declare const PopoverPortal: React.FC<PopoverPortalProps>;
55
+
56
+ interface PopoverContentProps extends PopoverContentTypeProps {
57
+ /**
58
+ * Used to force mounting when more control is needed. Useful when
59
+ * controlling animation with React animation libraries.
60
+ */
61
+ forceMount?: true;
62
+ }
63
+ declare const PopoverContent: React__default.ForwardRefExoticComponent<PopoverContentProps & React__default.RefAttributes<HTMLDivElement>>;
64
+ interface PopoverContentTypeProps extends Omit<PopoverContentImplProps, "trapFocus" | "disableOutsidePointerEvents"> {
65
+ }
66
+ type FocusScopeProps = React__default.ComponentPropsWithoutRef<typeof FocusScope>;
67
+ type DismissableLayerProps = React__default.ComponentPropsWithoutRef<typeof DismissableLayer>;
68
+ type PopperContentProps = React__default.ComponentPropsWithoutRef<typeof PopperPrimitive.Content>;
69
+ interface PopoverContentImplProps extends Omit<PopperContentProps, "onPlaced">, Omit<DismissableLayerProps, "onDismiss"> {
70
+ /**
71
+ * Whether focus should be trapped within the `Popover`
72
+ * (default: false)
73
+ */
74
+ trapFocus?: FocusScopeProps["trapped"];
75
+ /**
76
+ * Event handler called when auto-focusing on open.
77
+ * Can be prevented.
78
+ */
79
+ onOpenAutoFocus?: FocusScopeProps["onMountAutoFocus"];
80
+ /**
81
+ * Event handler called when auto-focusing on close.
82
+ * Can be prevented.
83
+ */
84
+ onCloseAutoFocus?: FocusScopeProps["onUnmountAutoFocus"];
85
+ }
86
+
87
+ interface PopoverCloseProps extends PrimitiveButtonProps {
88
+ }
89
+ declare const PopoverClose: React__default.ForwardRefExoticComponent<PopoverCloseProps & React__default.RefAttributes<HTMLButtonElement>>;
90
+
91
+ type PopperArrowProps = React__default.ComponentPropsWithoutRef<typeof PopperPrimitive.Arrow>;
92
+ interface PopoverArrowProps extends PopperArrowProps {
93
+ }
94
+ declare const PopoverArrow: React__default.ForwardRefExoticComponent<PopoverArrowProps & React__default.RefAttributes<SVGSVGElement>>;
95
+
96
+ export { Popover, PopoverAnchor, type PopoverAnchorProps, PopoverArrow, type PopoverArrowProps, PopoverClose, type PopoverCloseProps, PopoverContent, type PopoverContentProps, PopoverPortal, type PopoverPortalProps, type PopoverProps, PopoverTrigger, type PopoverTriggerProps, Root, createPopoverScope };
package/dist/index.js ADDED
@@ -0,0 +1,394 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // packages/react/popover/src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ Popover: () => Popover,
35
+ PopoverAnchor: () => PopoverAnchor,
36
+ PopoverArrow: () => PopoverArrow,
37
+ PopoverClose: () => PopoverClose,
38
+ PopoverContent: () => PopoverContent,
39
+ PopoverPortal: () => PopoverPortal,
40
+ PopoverTrigger: () => PopoverTrigger,
41
+ Root: () => Root2,
42
+ createPopoverScope: () => createPopoverScope
43
+ });
44
+ module.exports = __toCommonJS(src_exports);
45
+
46
+ // packages/react/popover/src/Popover.tsx
47
+ var React = __toESM(require("react"));
48
+ var import_react_context = require("@huin-core/react-context");
49
+ var import_react_id = require("@huin-core/react-id");
50
+ var PopperPrimitive = __toESM(require("@huin-core/react-popper"));
51
+ var import_react_popper = require("@huin-core/react-popper");
52
+ var import_react_use_controllable_state = require("@huin-core/react-use-controllable-state");
53
+ var import_jsx_runtime = require("react/jsx-runtime");
54
+ var POPOVER_NAME = "Popover";
55
+ var [createPopoverContext, createPopoverScope] = (0, import_react_context.createContextScope)(
56
+ POPOVER_NAME,
57
+ [import_react_popper.createPopperScope]
58
+ );
59
+ var usePopperScope = (0, import_react_popper.createPopperScope)();
60
+ var [PopoverProvider, usePopoverContext] = createPopoverContext(POPOVER_NAME);
61
+ var Popover = (props) => {
62
+ const {
63
+ __scopePopover,
64
+ children,
65
+ open: openProp,
66
+ defaultOpen,
67
+ onOpenChange,
68
+ modal = false
69
+ } = props;
70
+ const popperScope = usePopperScope(__scopePopover);
71
+ const triggerRef = React.useRef(null);
72
+ const [hasCustomAnchor, setHasCustomAnchor] = React.useState(false);
73
+ const [open = false, setOpen] = (0, import_react_use_controllable_state.useControllableState)({
74
+ prop: openProp,
75
+ defaultProp: defaultOpen,
76
+ onChange: onOpenChange
77
+ });
78
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperPrimitive.Root, { ...popperScope, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
79
+ PopoverProvider,
80
+ {
81
+ scope: __scopePopover,
82
+ contentId: (0, import_react_id.useId)(),
83
+ triggerRef,
84
+ open,
85
+ onOpenChange: setOpen,
86
+ onOpenToggle: React.useCallback(
87
+ () => setOpen((prevOpen) => !prevOpen),
88
+ [setOpen]
89
+ ),
90
+ hasCustomAnchor,
91
+ onCustomAnchorAdd: React.useCallback(
92
+ () => setHasCustomAnchor(true),
93
+ []
94
+ ),
95
+ onCustomAnchorRemove: React.useCallback(
96
+ () => setHasCustomAnchor(false),
97
+ []
98
+ ),
99
+ modal,
100
+ children
101
+ }
102
+ ) });
103
+ };
104
+ Popover.displayName = POPOVER_NAME;
105
+ var Root2 = Popover;
106
+
107
+ // packages/react/popover/src/PopoverAnchor.tsx
108
+ var PopperPrimitive2 = __toESM(require("@huin-core/react-popper"));
109
+ var import_react = __toESM(require("react"));
110
+ var import_jsx_runtime2 = require("react/jsx-runtime");
111
+ var ANCHOR_NAME = "PopoverAnchor";
112
+ var PopoverAnchor = import_react.default.forwardRef((props, forwardedRef) => {
113
+ const { __scopePopover, ...anchorProps } = props;
114
+ const context = usePopoverContext(ANCHOR_NAME, __scopePopover);
115
+ const popperScope = usePopperScope(__scopePopover);
116
+ const { onCustomAnchorAdd, onCustomAnchorRemove } = context;
117
+ import_react.default.useEffect(() => {
118
+ onCustomAnchorAdd();
119
+ return () => onCustomAnchorRemove();
120
+ }, [onCustomAnchorAdd, onCustomAnchorRemove]);
121
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
122
+ PopperPrimitive2.Anchor,
123
+ {
124
+ ...popperScope,
125
+ ...anchorProps,
126
+ ref: forwardedRef
127
+ }
128
+ );
129
+ });
130
+ PopoverAnchor.displayName = ANCHOR_NAME;
131
+
132
+ // packages/react/popover/src/PopoverTrigger.tsx
133
+ var import_react3 = __toESM(require("react"));
134
+ var import_react_primitive = require("@huin-core/react-primitive");
135
+ var import_react_compose_refs2 = require("@huin-core/react-compose-refs");
136
+ var PopperPrimitive4 = __toESM(require("@huin-core/react-popper"));
137
+ var import_primitive2 = require("@huin-core/primitive");
138
+
139
+ // packages/react/popover/src/PopoverContent.tsx
140
+ var import_react2 = __toESM(require("react"));
141
+ var import_react_presence2 = require("@huin-core/react-presence");
142
+ var import_react_compose_refs = require("@huin-core/react-compose-refs");
143
+ var import_aria_hidden = require("aria-hidden");
144
+ var import_react_remove_scroll = require("react-remove-scroll");
145
+ var import_react_slot = require("@huin-core/react-slot");
146
+ var import_primitive = require("@huin-core/primitive");
147
+ var PopperPrimitive3 = __toESM(require("@huin-core/react-popper"));
148
+ var import_react_dismissable_layer = require("@huin-core/react-dismissable-layer");
149
+ var import_react_focus_scope = require("@huin-core/react-focus-scope");
150
+ var import_react_focus_guards = require("@huin-core/react-focus-guards");
151
+
152
+ // packages/react/popover/src/PopoverPortal.tsx
153
+ var import_react_portal = require("@huin-core/react-portal");
154
+ var import_react_presence = require("@huin-core/react-presence");
155
+ var import_jsx_runtime3 = require("react/jsx-runtime");
156
+ var PORTAL_NAME = "PopoverPortal";
157
+ var [PortalProvider, usePortalContext] = createPopoverContext(PORTAL_NAME, {
158
+ forceMount: void 0
159
+ });
160
+ var PopoverPortal = (props) => {
161
+ const { __scopePopover, forceMount, children, container } = props;
162
+ const context = usePopoverContext(PORTAL_NAME, __scopePopover);
163
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PortalProvider, { scope: __scopePopover, forceMount, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_presence.Presence, { present: forceMount || context.open, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_portal.Portal, { asChild: true, container, children }) }) });
164
+ };
165
+ PopoverPortal.displayName = PORTAL_NAME;
166
+
167
+ // packages/react/popover/src/PopoverContent.tsx
168
+ var import_jsx_runtime4 = require("react/jsx-runtime");
169
+ var CONTENT_NAME = "PopoverContent";
170
+ var PopoverContent = import_react2.default.forwardRef((props, forwardedRef) => {
171
+ const portalContext = usePortalContext(CONTENT_NAME, props.__scopePopover);
172
+ const { forceMount = portalContext.forceMount, ...contentProps } = props;
173
+ const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);
174
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_presence2.Presence, { present: forceMount || context.open, children: context.modal ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PopoverContentModal, { ...contentProps, ref: forwardedRef }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PopoverContentNonModal, { ...contentProps, ref: forwardedRef }) });
175
+ });
176
+ PopoverContent.displayName = CONTENT_NAME;
177
+ var PopoverContentModal = import_react2.default.forwardRef((props, forwardedRef) => {
178
+ const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);
179
+ const contentRef = import_react2.default.useRef(null);
180
+ const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, contentRef);
181
+ const isRightClickOutsideRef = import_react2.default.useRef(false);
182
+ import_react2.default.useEffect(() => {
183
+ const content = contentRef.current;
184
+ if (content) return (0, import_aria_hidden.hideOthers)(content);
185
+ }, []);
186
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_remove_scroll.RemoveScroll, { as: import_react_slot.Slot, allowPinchZoom: true, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
187
+ PopoverContentImpl,
188
+ {
189
+ ...props,
190
+ ref: composedRefs,
191
+ trapFocus: context.open,
192
+ disableOutsidePointerEvents: true,
193
+ onCloseAutoFocus: (0, import_primitive.composeEventHandlers)(
194
+ props.onCloseAutoFocus,
195
+ (event) => {
196
+ event.preventDefault();
197
+ if (!isRightClickOutsideRef.current)
198
+ context.triggerRef.current?.focus();
199
+ }
200
+ ),
201
+ onPointerDownOutside: (0, import_primitive.composeEventHandlers)(
202
+ props.onPointerDownOutside,
203
+ (event) => {
204
+ const originalEvent = event.detail.originalEvent;
205
+ const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
206
+ const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
207
+ isRightClickOutsideRef.current = isRightClick;
208
+ },
209
+ { checkForDefaultPrevented: false }
210
+ ),
211
+ onFocusOutside: (0, import_primitive.composeEventHandlers)(
212
+ props.onFocusOutside,
213
+ (event) => event.preventDefault(),
214
+ { checkForDefaultPrevented: false }
215
+ )
216
+ }
217
+ ) });
218
+ });
219
+ var PopoverContentNonModal = import_react2.default.forwardRef((props, forwardedRef) => {
220
+ const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);
221
+ const hasInteractedOutsideRef = import_react2.default.useRef(false);
222
+ const hasPointerDownOutsideRef = import_react2.default.useRef(false);
223
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
224
+ PopoverContentImpl,
225
+ {
226
+ ...props,
227
+ ref: forwardedRef,
228
+ trapFocus: false,
229
+ disableOutsidePointerEvents: false,
230
+ onCloseAutoFocus: (event) => {
231
+ props.onCloseAutoFocus?.(event);
232
+ if (!event.defaultPrevented) {
233
+ if (!hasInteractedOutsideRef.current)
234
+ context.triggerRef.current?.focus();
235
+ event.preventDefault();
236
+ }
237
+ hasInteractedOutsideRef.current = false;
238
+ hasPointerDownOutsideRef.current = false;
239
+ },
240
+ onInteractOutside: (event) => {
241
+ props.onInteractOutside?.(event);
242
+ if (!event.defaultPrevented) {
243
+ hasInteractedOutsideRef.current = true;
244
+ if (event.detail.originalEvent.type === "pointerdown") {
245
+ hasPointerDownOutsideRef.current = true;
246
+ }
247
+ }
248
+ const target = event.target;
249
+ const targetIsTrigger = context.triggerRef.current?.contains(target);
250
+ if (targetIsTrigger) event.preventDefault();
251
+ if (event.detail.originalEvent.type === "focusin" && hasPointerDownOutsideRef.current) {
252
+ event.preventDefault();
253
+ }
254
+ }
255
+ }
256
+ );
257
+ });
258
+ var PopoverContentImpl = import_react2.default.forwardRef((props, forwardedRef) => {
259
+ const {
260
+ __scopePopover,
261
+ trapFocus,
262
+ onOpenAutoFocus,
263
+ onCloseAutoFocus,
264
+ disableOutsidePointerEvents,
265
+ onEscapeKeyDown,
266
+ onPointerDownOutside,
267
+ onFocusOutside,
268
+ onInteractOutside,
269
+ ...contentProps
270
+ } = props;
271
+ const context = usePopoverContext(CONTENT_NAME, __scopePopover);
272
+ const popperScope = usePopperScope(__scopePopover);
273
+ (0, import_react_focus_guards.useFocusGuards)();
274
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
275
+ import_react_focus_scope.FocusScope,
276
+ {
277
+ asChild: true,
278
+ loop: true,
279
+ trapped: trapFocus,
280
+ onMountAutoFocus: onOpenAutoFocus,
281
+ onUnmountAutoFocus: onCloseAutoFocus,
282
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
283
+ import_react_dismissable_layer.DismissableLayer,
284
+ {
285
+ asChild: true,
286
+ disableOutsidePointerEvents,
287
+ onInteractOutside,
288
+ onEscapeKeyDown,
289
+ onPointerDownOutside,
290
+ onFocusOutside,
291
+ onDismiss: () => context.onOpenChange(false),
292
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
293
+ PopperPrimitive3.Content,
294
+ {
295
+ "data-state": getState(context.open),
296
+ role: "dialog",
297
+ id: context.contentId,
298
+ ...popperScope,
299
+ ...contentProps,
300
+ ref: forwardedRef,
301
+ style: {
302
+ ...contentProps.style,
303
+ // re-namespace exposed content custom properties
304
+ ...{
305
+ "--huin-core-popover-content-transform-origin": "var(--huin-core-popper-transform-origin)",
306
+ "--huin-core-popover-content-available-width": "var(--huin-core-popper-available-width)",
307
+ "--huin-core-popover-content-available-height": "var(--huin-core-popper-available-height)",
308
+ "--huin-core-popover-trigger-width": "var(--huin-core-popper-anchor-width)",
309
+ "--huin-core-popover-trigger-height": "var(--huin-core-popper-anchor-height)"
310
+ }
311
+ }
312
+ }
313
+ )
314
+ }
315
+ )
316
+ }
317
+ );
318
+ });
319
+ function getState(open) {
320
+ return open ? "open" : "closed";
321
+ }
322
+
323
+ // packages/react/popover/src/PopoverTrigger.tsx
324
+ var import_jsx_runtime5 = require("react/jsx-runtime");
325
+ var TRIGGER_NAME = "PopoverTrigger";
326
+ var PopoverTrigger = import_react3.default.forwardRef((props, forwardedRef) => {
327
+ const { __scopePopover, ...triggerProps } = props;
328
+ const context = usePopoverContext(TRIGGER_NAME, __scopePopover);
329
+ const popperScope = usePopperScope(__scopePopover);
330
+ const composedTriggerRef = (0, import_react_compose_refs2.useComposedRefs)(forwardedRef, context.triggerRef);
331
+ const trigger = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
332
+ import_react_primitive.Primitive.button,
333
+ {
334
+ type: "button",
335
+ "aria-haspopup": "dialog",
336
+ "aria-expanded": context.open,
337
+ "aria-controls": context.contentId,
338
+ "data-state": getState(context.open),
339
+ ...triggerProps,
340
+ ref: composedTriggerRef,
341
+ onClick: (0, import_primitive2.composeEventHandlers)(props.onClick, context.onOpenToggle)
342
+ }
343
+ );
344
+ return context.hasCustomAnchor ? trigger : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PopperPrimitive4.Anchor, { asChild: true, ...popperScope, children: trigger });
345
+ });
346
+ PopoverTrigger.displayName = TRIGGER_NAME;
347
+
348
+ // packages/react/popover/src/PopoverClose.tsx
349
+ var import_react4 = __toESM(require("react"));
350
+ var import_react_primitive2 = require("@huin-core/react-primitive");
351
+ var import_primitive3 = require("@huin-core/primitive");
352
+ var import_jsx_runtime6 = require("react/jsx-runtime");
353
+ var CLOSE_NAME = "PopoverClose";
354
+ var PopoverClose = import_react4.default.forwardRef(
355
+ (props, forwardedRef) => {
356
+ const { __scopePopover, ...closeProps } = props;
357
+ const context = usePopoverContext(CLOSE_NAME, __scopePopover);
358
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
359
+ import_react_primitive2.Primitive.button,
360
+ {
361
+ type: "button",
362
+ ...closeProps,
363
+ ref: forwardedRef,
364
+ onClick: (0, import_primitive3.composeEventHandlers)(
365
+ props.onClick,
366
+ () => context.onOpenChange(false)
367
+ )
368
+ }
369
+ );
370
+ }
371
+ );
372
+ PopoverClose.displayName = CLOSE_NAME;
373
+
374
+ // packages/react/popover/src/PopoverArrow.tsx
375
+ var PopperPrimitive5 = __toESM(require("@huin-core/react-popper"));
376
+ var import_react5 = __toESM(require("react"));
377
+ var import_jsx_runtime7 = require("react/jsx-runtime");
378
+ var ARROW_NAME = "PopoverArrow";
379
+ var PopoverArrow = import_react5.default.forwardRef(
380
+ (props, forwardedRef) => {
381
+ const { __scopePopover, ...arrowProps } = props;
382
+ const popperScope = usePopperScope(__scopePopover);
383
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
384
+ PopperPrimitive5.Arrow,
385
+ {
386
+ ...popperScope,
387
+ ...arrowProps,
388
+ ref: forwardedRef
389
+ }
390
+ );
391
+ }
392
+ );
393
+ PopoverArrow.displayName = ARROW_NAME;
394
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/Popover.tsx", "../src/PopoverAnchor.tsx", "../src/PopoverTrigger.tsx", "../src/PopoverContent.tsx", "../src/PopoverPortal.tsx", "../src/PopoverClose.tsx", "../src/PopoverArrow.tsx"],
4
+ "sourcesContent": ["\"use client\";\nexport { createPopoverScope, Popover, Root } from \"./Popover\";\nexport { PopoverAnchor } from \"./PopoverAnchor\";\nexport { PopoverTrigger } from \"./PopoverTrigger\";\nexport { PopoverPortal } from \"./PopoverPortal\";\nexport { PopoverContent } from \"./PopoverContent\";\nexport { PopoverClose } from \"./PopoverClose\";\nexport { PopoverArrow } from \"./PopoverArrow\";\n\nexport type { PopoverProps } from \"./Popover\";\nexport type { PopoverAnchorProps } from \"./PopoverAnchor\";\nexport type { PopoverTriggerProps } from \"./PopoverTrigger\";\nexport type { PopoverPortalProps } from \"./PopoverPortal\";\nexport type { PopoverContentProps } from \"./PopoverContent\";\nexport type { PopoverCloseProps } from \"./PopoverClose\";\nexport type { PopoverArrowProps } from \"./PopoverArrow\";\n", "import * as React from \"react\";\nimport { createContextScope } from \"@huin-core/react-context\";\nimport { useId } from \"@huin-core/react-id\";\nimport * as PopperPrimitive from \"@huin-core/react-popper\";\nimport { createPopperScope } from \"@huin-core/react-popper\";\nimport { useControllableState } from \"@huin-core/react-use-controllable-state\";\nimport type { Scope } from \"@huin-core/react-context\";\n\n/* -------------------------------------------------------------------------------------------------\n * Popover\n * -----------------------------------------------------------------------------------------------*/\n\nconst POPOVER_NAME = \"Popover\";\n\nexport type ScopedProps<P> = P & { __scopePopover?: Scope };\nexport const [createPopoverContext, createPopoverScope] = createContextScope(\n POPOVER_NAME,\n [createPopperScope]\n);\nexport const usePopperScope = createPopperScope();\n\ntype PopoverContextValue = {\n triggerRef: React.RefObject<HTMLButtonElement>;\n contentId: string;\n open: boolean;\n onOpenChange(open: boolean): void;\n onOpenToggle(): void;\n hasCustomAnchor: boolean;\n onCustomAnchorAdd(): void;\n onCustomAnchorRemove(): void;\n modal: boolean;\n};\n\nexport const [PopoverProvider, usePopoverContext] =\n createPopoverContext<PopoverContextValue>(POPOVER_NAME);\n\ninterface PopoverProps {\n children?: React.ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n modal?: boolean;\n}\n\nconst Popover: React.FC<PopoverProps> = (props: ScopedProps<PopoverProps>) => {\n const {\n __scopePopover,\n children,\n open: openProp,\n defaultOpen,\n onOpenChange,\n modal = false,\n } = props;\n const popperScope = usePopperScope(__scopePopover);\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const [hasCustomAnchor, setHasCustomAnchor] = React.useState(false);\n const [open = false, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n\n return (\n <PopperPrimitive.Root {...popperScope}>\n <PopoverProvider\n scope={__scopePopover}\n contentId={useId()}\n triggerRef={triggerRef}\n open={open}\n onOpenChange={setOpen}\n onOpenToggle={React.useCallback(\n () => setOpen((prevOpen) => !prevOpen),\n [setOpen]\n )}\n hasCustomAnchor={hasCustomAnchor}\n onCustomAnchorAdd={React.useCallback(\n () => setHasCustomAnchor(true),\n []\n )}\n onCustomAnchorRemove={React.useCallback(\n () => setHasCustomAnchor(false),\n []\n )}\n modal={modal}\n >\n {children}\n </PopoverProvider>\n </PopperPrimitive.Root>\n );\n};\n\nPopover.displayName = POPOVER_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Popover;\n\nexport { Popover, Root };\nexport type { PopoverProps };\n", "import * as PopperPrimitive from \"@huin-core/react-popper\";\nimport React from \"react\";\nimport { ScopedProps, usePopoverContext, usePopperScope } from \"./Popover\";\n\nconst ANCHOR_NAME = \"PopoverAnchor\";\n\ntype PopoverAnchorElement = React.ElementRef<typeof PopperPrimitive.Anchor>;\ntype PopperAnchorProps = React.ComponentPropsWithoutRef<\n typeof PopperPrimitive.Anchor\n>;\ninterface PopoverAnchorProps extends PopperAnchorProps {}\n\nconst PopoverAnchor = React.forwardRef<\n PopoverAnchorElement,\n PopoverAnchorProps\n>((props: ScopedProps<PopoverAnchorProps>, forwardedRef) => {\n const { __scopePopover, ...anchorProps } = props;\n const context = usePopoverContext(ANCHOR_NAME, __scopePopover);\n const popperScope = usePopperScope(__scopePopover);\n const { onCustomAnchorAdd, onCustomAnchorRemove } = context;\n\n React.useEffect(() => {\n onCustomAnchorAdd();\n return () => onCustomAnchorRemove();\n }, [onCustomAnchorAdd, onCustomAnchorRemove]);\n\n return (\n <PopperPrimitive.Anchor\n {...popperScope}\n {...anchorProps}\n ref={forwardedRef}\n />\n );\n});\n\nPopoverAnchor.displayName = ANCHOR_NAME;\n\nexport { PopoverAnchor };\nexport type { PopoverAnchorProps };\n", "import React from \"react\";\nimport { Primitive } from \"@huin-core/react-primitive\";\nimport { ScopedProps, usePopoverContext, usePopperScope } from \"./Popover\";\nimport { useComposedRefs } from \"@huin-core/react-compose-refs\";\nimport * as PopperPrimitive from \"@huin-core/react-popper\";\nimport { composeEventHandlers } from \"@huin-core/primitive\";\nimport { getState } from \"./PopoverContent\";\n\nconst TRIGGER_NAME = \"PopoverTrigger\";\n\ntype PopoverTriggerElement = React.ElementRef<typeof Primitive.button>;\nexport type PrimitiveButtonProps = React.ComponentPropsWithoutRef<\n typeof Primitive.button\n>;\ninterface PopoverTriggerProps extends PrimitiveButtonProps {}\n\nconst PopoverTrigger = React.forwardRef<\n PopoverTriggerElement,\n PopoverTriggerProps\n>((props: ScopedProps<PopoverTriggerProps>, forwardedRef) => {\n const { __scopePopover, ...triggerProps } = props;\n const context = usePopoverContext(TRIGGER_NAME, __scopePopover);\n const popperScope = usePopperScope(__scopePopover);\n const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);\n\n const trigger = (\n <Primitive.button\n type=\"button\"\n aria-haspopup=\"dialog\"\n aria-expanded={context.open}\n aria-controls={context.contentId}\n data-state={getState(context.open)}\n {...triggerProps}\n ref={composedTriggerRef}\n onClick={composeEventHandlers(props.onClick, context.onOpenToggle)}\n />\n );\n\n return context.hasCustomAnchor ? (\n trigger\n ) : (\n <PopperPrimitive.Anchor asChild {...popperScope}>\n {trigger}\n </PopperPrimitive.Anchor>\n );\n});\n\nPopoverTrigger.displayName = TRIGGER_NAME;\n\nexport { PopoverTrigger };\nexport type { PopoverTriggerProps };\n", "import React from \"react\";\nimport { ScopedProps, usePopoverContext, usePopperScope } from \"./Popover\";\nimport { Presence } from \"@huin-core/react-presence\";\nimport { useComposedRefs } from \"@huin-core/react-compose-refs\";\nimport { hideOthers } from \"aria-hidden\";\nimport { RemoveScroll } from \"react-remove-scroll\";\nimport { Slot } from \"@huin-core/react-slot\";\nimport { composeEventHandlers } from \"@huin-core/primitive\";\nimport * as PopperPrimitive from \"@huin-core/react-popper\";\nimport { DismissableLayer } from \"@huin-core/react-dismissable-layer\";\nimport { FocusScope } from \"@huin-core/react-focus-scope\";\nimport { useFocusGuards } from \"@huin-core/react-focus-guards\";\nimport { usePortalContext } from \"./PopoverPortal\";\n\nconst CONTENT_NAME = \"PopoverContent\";\n\ninterface PopoverContentProps extends PopoverContentTypeProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst PopoverContent = React.forwardRef<\n PopoverContentTypeElement,\n PopoverContentProps\n>((props: ScopedProps<PopoverContentProps>, forwardedRef) => {\n const portalContext = usePortalContext(CONTENT_NAME, props.__scopePopover);\n const { forceMount = portalContext.forceMount, ...contentProps } = props;\n const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);\n return (\n <Presence present={forceMount || context.open}>\n {context.modal ? (\n <PopoverContentModal {...contentProps} ref={forwardedRef} />\n ) : (\n <PopoverContentNonModal {...contentProps} ref={forwardedRef} />\n )}\n </Presence>\n );\n});\n\nPopoverContent.displayName = CONTENT_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype PopoverContentTypeElement = PopoverContentImplElement;\ninterface PopoverContentTypeProps\n extends Omit<\n PopoverContentImplProps,\n \"trapFocus\" | \"disableOutsidePointerEvents\"\n > {}\n\nconst PopoverContentModal = React.forwardRef<\n PopoverContentTypeElement,\n PopoverContentTypeProps\n>((props: ScopedProps<PopoverContentTypeProps>, forwardedRef) => {\n const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);\n const contentRef = React.useRef<HTMLDivElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, contentRef);\n const isRightClickOutsideRef = React.useRef(false);\n\n // aria-hide everything except the content (better supported equivalent to setting aria-modal)\n React.useEffect(() => {\n const content = contentRef.current;\n if (content) return hideOthers(content);\n }, []);\n\n return (\n <RemoveScroll as={Slot} allowPinchZoom>\n <PopoverContentImpl\n {...props}\n ref={composedRefs}\n // we make sure we're not trapping once it's been closed\n // (closed !== unmounted when animating out)\n trapFocus={context.open}\n disableOutsidePointerEvents\n onCloseAutoFocus={composeEventHandlers(\n props.onCloseAutoFocus,\n (event) => {\n event.preventDefault();\n if (!isRightClickOutsideRef.current)\n context.triggerRef.current?.focus();\n }\n )}\n onPointerDownOutside={composeEventHandlers(\n props.onPointerDownOutside,\n (event) => {\n const originalEvent = event.detail.originalEvent;\n const ctrlLeftClick =\n originalEvent.button === 0 && originalEvent.ctrlKey === true;\n const isRightClick = originalEvent.button === 2 || ctrlLeftClick;\n\n isRightClickOutsideRef.current = isRightClick;\n },\n { checkForDefaultPrevented: false }\n )}\n // When focus is trapped, a `focusout` event may still happen.\n // We make sure we don't trigger our `onDismiss` in such case.\n onFocusOutside={composeEventHandlers(\n props.onFocusOutside,\n (event) => event.preventDefault(),\n { checkForDefaultPrevented: false }\n )}\n />\n </RemoveScroll>\n );\n});\n\nconst PopoverContentNonModal = React.forwardRef<\n PopoverContentTypeElement,\n PopoverContentTypeProps\n>((props: ScopedProps<PopoverContentTypeProps>, forwardedRef) => {\n const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);\n const hasInteractedOutsideRef = React.useRef(false);\n const hasPointerDownOutsideRef = React.useRef(false);\n\n return (\n <PopoverContentImpl\n {...props}\n ref={forwardedRef}\n trapFocus={false}\n disableOutsidePointerEvents={false}\n onCloseAutoFocus={(event) => {\n props.onCloseAutoFocus?.(event);\n\n if (!event.defaultPrevented) {\n if (!hasInteractedOutsideRef.current)\n context.triggerRef.current?.focus();\n // Always prevent auto focus because we either focus manually or want user agent focus\n event.preventDefault();\n }\n\n hasInteractedOutsideRef.current = false;\n hasPointerDownOutsideRef.current = false;\n }}\n onInteractOutside={(event) => {\n props.onInteractOutside?.(event);\n\n if (!event.defaultPrevented) {\n hasInteractedOutsideRef.current = true;\n if (event.detail.originalEvent.type === \"pointerdown\") {\n hasPointerDownOutsideRef.current = true;\n }\n }\n\n // Prevent dismissing when clicking the trigger.\n // As the trigger is already setup to close, without doing so would\n // cause it to close and immediately open.\n const target = event.target as HTMLElement;\n const targetIsTrigger = context.triggerRef.current?.contains(target);\n if (targetIsTrigger) event.preventDefault();\n\n // On Safari if the trigger is inside a container with tabIndex={0}, when clicked\n // we will get the pointer down outside event on the trigger, but then a subsequent\n // focus outside event on the container, we ignore any focus outside event when we've\n // already had a pointer down outside event.\n if (\n event.detail.originalEvent.type === \"focusin\" &&\n hasPointerDownOutsideRef.current\n ) {\n event.preventDefault();\n }\n }}\n />\n );\n});\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype PopoverContentImplElement = React.ElementRef<\n typeof PopperPrimitive.Content\n>;\ntype FocusScopeProps = React.ComponentPropsWithoutRef<typeof FocusScope>;\ntype DismissableLayerProps = React.ComponentPropsWithoutRef<\n typeof DismissableLayer\n>;\ntype PopperContentProps = React.ComponentPropsWithoutRef<\n typeof PopperPrimitive.Content\n>;\ninterface PopoverContentImplProps\n extends Omit<PopperContentProps, \"onPlaced\">,\n Omit<DismissableLayerProps, \"onDismiss\"> {\n /**\n * Whether focus should be trapped within the `Popover`\n * (default: false)\n */\n trapFocus?: FocusScopeProps[\"trapped\"];\n\n /**\n * Event handler called when auto-focusing on open.\n * Can be prevented.\n */\n onOpenAutoFocus?: FocusScopeProps[\"onMountAutoFocus\"];\n\n /**\n * Event handler called when auto-focusing on close.\n * Can be prevented.\n */\n onCloseAutoFocus?: FocusScopeProps[\"onUnmountAutoFocus\"];\n}\n\nconst PopoverContentImpl = React.forwardRef<\n PopoverContentImplElement,\n PopoverContentImplProps\n>((props: ScopedProps<PopoverContentImplProps>, forwardedRef) => {\n const {\n __scopePopover,\n trapFocus,\n onOpenAutoFocus,\n onCloseAutoFocus,\n disableOutsidePointerEvents,\n onEscapeKeyDown,\n onPointerDownOutside,\n onFocusOutside,\n onInteractOutside,\n ...contentProps\n } = props;\n const context = usePopoverContext(CONTENT_NAME, __scopePopover);\n const popperScope = usePopperScope(__scopePopover);\n\n // Make sure the whole tree has focus guards as our `Popover` may be\n // the last element in the DOM (beacuse of the `Portal`)\n useFocusGuards();\n\n return (\n <FocusScope\n asChild\n loop\n trapped={trapFocus}\n onMountAutoFocus={onOpenAutoFocus}\n onUnmountAutoFocus={onCloseAutoFocus}\n >\n <DismissableLayer\n asChild\n disableOutsidePointerEvents={disableOutsidePointerEvents}\n onInteractOutside={onInteractOutside}\n onEscapeKeyDown={onEscapeKeyDown}\n onPointerDownOutside={onPointerDownOutside}\n onFocusOutside={onFocusOutside}\n onDismiss={() => context.onOpenChange(false)}\n >\n <PopperPrimitive.Content\n data-state={getState(context.open)}\n role=\"dialog\"\n id={context.contentId}\n {...popperScope}\n {...contentProps}\n ref={forwardedRef}\n style={{\n ...contentProps.style,\n // re-namespace exposed content custom properties\n ...{\n \"--huin-core-popover-content-transform-origin\":\n \"var(--huin-core-popper-transform-origin)\",\n \"--huin-core-popover-content-available-width\":\n \"var(--huin-core-popper-available-width)\",\n \"--huin-core-popover-content-available-height\":\n \"var(--huin-core-popper-available-height)\",\n \"--huin-core-popover-trigger-width\":\n \"var(--huin-core-popper-anchor-width)\",\n \"--huin-core-popover-trigger-height\":\n \"var(--huin-core-popper-anchor-height)\",\n },\n }}\n />\n </DismissableLayer>\n </FocusScope>\n );\n});\n\nexport function getState(open: boolean) {\n return open ? \"open\" : \"closed\";\n}\nexport { PopoverContent };\nexport type { PopoverContentProps };\n", "import { Portal as PortalPrimitive } from \"@huin-core/react-portal\";\nimport {\n createPopoverContext,\n ScopedProps,\n usePopoverContext,\n} from \"./Popover\";\nimport { Presence } from \"@huin-core/react-presence\";\n\nconst PORTAL_NAME = \"PopoverPortal\";\n\ntype PortalContextValue = { forceMount?: true };\nexport const [PortalProvider, usePortalContext] =\n createPopoverContext<PortalContextValue>(PORTAL_NAME, {\n forceMount: undefined,\n });\n\ntype PortalProps = React.ComponentPropsWithoutRef<typeof PortalPrimitive>;\ninterface PopoverPortalProps {\n children?: React.ReactNode;\n /**\n * Specify a container element to portal the content into.\n */\n container?: PortalProps[\"container\"];\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst PopoverPortal: React.FC<PopoverPortalProps> = (\n props: ScopedProps<PopoverPortalProps>\n) => {\n const { __scopePopover, forceMount, children, container } = props;\n const context = usePopoverContext(PORTAL_NAME, __scopePopover);\n return (\n <PortalProvider scope={__scopePopover} forceMount={forceMount}>\n <Presence present={forceMount || context.open}>\n <PortalPrimitive asChild container={container}>\n {children}\n </PortalPrimitive>\n </Presence>\n </PortalProvider>\n );\n};\n\nPopoverPortal.displayName = PORTAL_NAME;\n\nexport { PopoverPortal };\nexport type { PopoverPortalProps };\n", "import React from \"react\";\nimport { Primitive } from \"@huin-core/react-primitive\";\nimport { ScopedProps, usePopoverContext } from \"./Popover\";\nimport { composeEventHandlers } from \"@huin-core/primitive\";\nimport { PrimitiveButtonProps } from \"./PopoverTrigger\";\n\nconst CLOSE_NAME = \"PopoverClose\";\n\ntype PopoverCloseElement = React.ElementRef<typeof Primitive.button>;\ninterface PopoverCloseProps extends PrimitiveButtonProps {}\n\nconst PopoverClose = React.forwardRef<PopoverCloseElement, PopoverCloseProps>(\n (props: ScopedProps<PopoverCloseProps>, forwardedRef) => {\n const { __scopePopover, ...closeProps } = props;\n const context = usePopoverContext(CLOSE_NAME, __scopePopover);\n return (\n <Primitive.button\n type=\"button\"\n {...closeProps}\n ref={forwardedRef}\n onClick={composeEventHandlers(props.onClick, () =>\n context.onOpenChange(false)\n )}\n />\n );\n }\n);\n\nPopoverClose.displayName = CLOSE_NAME;\n\nexport { PopoverClose };\nexport type { PopoverCloseProps };\n", "import * as PopperPrimitive from \"@huin-core/react-popper\";\nimport React from \"react\";\nimport { ScopedProps, usePopperScope } from \"./Popover\";\n\nconst ARROW_NAME = \"PopoverArrow\";\n\ntype PopoverArrowElement = React.ElementRef<typeof PopperPrimitive.Arrow>;\ntype PopperArrowProps = React.ComponentPropsWithoutRef<\n typeof PopperPrimitive.Arrow\n>;\ninterface PopoverArrowProps extends PopperArrowProps {}\n\nconst PopoverArrow = React.forwardRef<PopoverArrowElement, PopoverArrowProps>(\n (props: ScopedProps<PopoverArrowProps>, forwardedRef) => {\n const { __scopePopover, ...arrowProps } = props;\n const popperScope = usePopperScope(__scopePopover);\n return (\n <PopperPrimitive.Arrow\n {...popperScope}\n {...arrowProps}\n ref={forwardedRef}\n />\n );\n }\n);\n\nPopoverArrow.displayName = ARROW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IAAAC,mBAAiC;AACjC,IAAAC,gBAAkB;AAgBZ,IAAAC,sBAAA;AAbN,IAAM,aAAa;AAQnB,IAAM,eAAe,cAAAC,QAAM;AAAA,EACzB,CAAC,OAAuC,iBAAiB;AACvD,UAAM,EAAE,gBAAgB,GAAG,WAAW,IAAI;AAC1C,UAAM,cAAc,eAAe,cAAc;AACjD,WACE;AAAA,MAAiB;AAAA,MAAhB;AAAA,QACE,GAAG;AAAA,QACH,GAAG;AAAA,QACJ,KAAK;AAAA;AAAA,IACP;AAAA,EAEJ;AACF;AAEA,aAAa,cAAc;",
6
+ "names": ["Root", "Root", "PopperPrimitive", "import_jsx_runtime", "React", "import_react", "import_react_compose_refs", "PopperPrimitive", "import_primitive", "import_react", "import_react_presence", "PopperPrimitive", "import_jsx_runtime", "PortalPrimitive", "import_jsx_runtime", "React", "import_jsx_runtime", "React", "import_react", "import_react_primitive", "import_primitive", "import_jsx_runtime", "React", "PopperPrimitive", "import_react", "import_jsx_runtime", "React"]
7
+ }
package/dist/index.mjs ADDED
@@ -0,0 +1,362 @@
1
+ "use client";
2
+
3
+ // packages/react/popover/src/Popover.tsx
4
+ import * as React from "react";
5
+ import { createContextScope } from "@huin-core/react-context";
6
+ import { useId } from "@huin-core/react-id";
7
+ import * as PopperPrimitive from "@huin-core/react-popper";
8
+ import { createPopperScope } from "@huin-core/react-popper";
9
+ import { useControllableState } from "@huin-core/react-use-controllable-state";
10
+ import { jsx } from "react/jsx-runtime";
11
+ var POPOVER_NAME = "Popover";
12
+ var [createPopoverContext, createPopoverScope] = createContextScope(
13
+ POPOVER_NAME,
14
+ [createPopperScope]
15
+ );
16
+ var usePopperScope = createPopperScope();
17
+ var [PopoverProvider, usePopoverContext] = createPopoverContext(POPOVER_NAME);
18
+ var Popover = (props) => {
19
+ const {
20
+ __scopePopover,
21
+ children,
22
+ open: openProp,
23
+ defaultOpen,
24
+ onOpenChange,
25
+ modal = false
26
+ } = props;
27
+ const popperScope = usePopperScope(__scopePopover);
28
+ const triggerRef = React.useRef(null);
29
+ const [hasCustomAnchor, setHasCustomAnchor] = React.useState(false);
30
+ const [open = false, setOpen] = useControllableState({
31
+ prop: openProp,
32
+ defaultProp: defaultOpen,
33
+ onChange: onOpenChange
34
+ });
35
+ return /* @__PURE__ */ jsx(PopperPrimitive.Root, { ...popperScope, children: /* @__PURE__ */ jsx(
36
+ PopoverProvider,
37
+ {
38
+ scope: __scopePopover,
39
+ contentId: useId(),
40
+ triggerRef,
41
+ open,
42
+ onOpenChange: setOpen,
43
+ onOpenToggle: React.useCallback(
44
+ () => setOpen((prevOpen) => !prevOpen),
45
+ [setOpen]
46
+ ),
47
+ hasCustomAnchor,
48
+ onCustomAnchorAdd: React.useCallback(
49
+ () => setHasCustomAnchor(true),
50
+ []
51
+ ),
52
+ onCustomAnchorRemove: React.useCallback(
53
+ () => setHasCustomAnchor(false),
54
+ []
55
+ ),
56
+ modal,
57
+ children
58
+ }
59
+ ) });
60
+ };
61
+ Popover.displayName = POPOVER_NAME;
62
+ var Root2 = Popover;
63
+
64
+ // packages/react/popover/src/PopoverAnchor.tsx
65
+ import * as PopperPrimitive2 from "@huin-core/react-popper";
66
+ import React2 from "react";
67
+ import { jsx as jsx2 } from "react/jsx-runtime";
68
+ var ANCHOR_NAME = "PopoverAnchor";
69
+ var PopoverAnchor = React2.forwardRef((props, forwardedRef) => {
70
+ const { __scopePopover, ...anchorProps } = props;
71
+ const context = usePopoverContext(ANCHOR_NAME, __scopePopover);
72
+ const popperScope = usePopperScope(__scopePopover);
73
+ const { onCustomAnchorAdd, onCustomAnchorRemove } = context;
74
+ React2.useEffect(() => {
75
+ onCustomAnchorAdd();
76
+ return () => onCustomAnchorRemove();
77
+ }, [onCustomAnchorAdd, onCustomAnchorRemove]);
78
+ return /* @__PURE__ */ jsx2(
79
+ PopperPrimitive2.Anchor,
80
+ {
81
+ ...popperScope,
82
+ ...anchorProps,
83
+ ref: forwardedRef
84
+ }
85
+ );
86
+ });
87
+ PopoverAnchor.displayName = ANCHOR_NAME;
88
+
89
+ // packages/react/popover/src/PopoverTrigger.tsx
90
+ import React4 from "react";
91
+ import { Primitive } from "@huin-core/react-primitive";
92
+ import { useComposedRefs as useComposedRefs2 } from "@huin-core/react-compose-refs";
93
+ import * as PopperPrimitive4 from "@huin-core/react-popper";
94
+ import { composeEventHandlers as composeEventHandlers2 } from "@huin-core/primitive";
95
+
96
+ // packages/react/popover/src/PopoverContent.tsx
97
+ import React3 from "react";
98
+ import { Presence as Presence2 } from "@huin-core/react-presence";
99
+ import { useComposedRefs } from "@huin-core/react-compose-refs";
100
+ import { hideOthers } from "aria-hidden";
101
+ import { RemoveScroll } from "react-remove-scroll";
102
+ import { Slot } from "@huin-core/react-slot";
103
+ import { composeEventHandlers } from "@huin-core/primitive";
104
+ import * as PopperPrimitive3 from "@huin-core/react-popper";
105
+ import { DismissableLayer } from "@huin-core/react-dismissable-layer";
106
+ import { FocusScope } from "@huin-core/react-focus-scope";
107
+ import { useFocusGuards } from "@huin-core/react-focus-guards";
108
+
109
+ // packages/react/popover/src/PopoverPortal.tsx
110
+ import { Portal as PortalPrimitive } from "@huin-core/react-portal";
111
+ import { Presence } from "@huin-core/react-presence";
112
+ import { jsx as jsx3 } from "react/jsx-runtime";
113
+ var PORTAL_NAME = "PopoverPortal";
114
+ var [PortalProvider, usePortalContext] = createPopoverContext(PORTAL_NAME, {
115
+ forceMount: void 0
116
+ });
117
+ var PopoverPortal = (props) => {
118
+ const { __scopePopover, forceMount, children, container } = props;
119
+ const context = usePopoverContext(PORTAL_NAME, __scopePopover);
120
+ return /* @__PURE__ */ jsx3(PortalProvider, { scope: __scopePopover, forceMount, children: /* @__PURE__ */ jsx3(Presence, { present: forceMount || context.open, children: /* @__PURE__ */ jsx3(PortalPrimitive, { asChild: true, container, children }) }) });
121
+ };
122
+ PopoverPortal.displayName = PORTAL_NAME;
123
+
124
+ // packages/react/popover/src/PopoverContent.tsx
125
+ import { jsx as jsx4 } from "react/jsx-runtime";
126
+ var CONTENT_NAME = "PopoverContent";
127
+ var PopoverContent = React3.forwardRef((props, forwardedRef) => {
128
+ const portalContext = usePortalContext(CONTENT_NAME, props.__scopePopover);
129
+ const { forceMount = portalContext.forceMount, ...contentProps } = props;
130
+ const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);
131
+ return /* @__PURE__ */ jsx4(Presence2, { present: forceMount || context.open, children: context.modal ? /* @__PURE__ */ jsx4(PopoverContentModal, { ...contentProps, ref: forwardedRef }) : /* @__PURE__ */ jsx4(PopoverContentNonModal, { ...contentProps, ref: forwardedRef }) });
132
+ });
133
+ PopoverContent.displayName = CONTENT_NAME;
134
+ var PopoverContentModal = React3.forwardRef((props, forwardedRef) => {
135
+ const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);
136
+ const contentRef = React3.useRef(null);
137
+ const composedRefs = useComposedRefs(forwardedRef, contentRef);
138
+ const isRightClickOutsideRef = React3.useRef(false);
139
+ React3.useEffect(() => {
140
+ const content = contentRef.current;
141
+ if (content) return hideOthers(content);
142
+ }, []);
143
+ return /* @__PURE__ */ jsx4(RemoveScroll, { as: Slot, allowPinchZoom: true, children: /* @__PURE__ */ jsx4(
144
+ PopoverContentImpl,
145
+ {
146
+ ...props,
147
+ ref: composedRefs,
148
+ trapFocus: context.open,
149
+ disableOutsidePointerEvents: true,
150
+ onCloseAutoFocus: composeEventHandlers(
151
+ props.onCloseAutoFocus,
152
+ (event) => {
153
+ event.preventDefault();
154
+ if (!isRightClickOutsideRef.current)
155
+ context.triggerRef.current?.focus();
156
+ }
157
+ ),
158
+ onPointerDownOutside: composeEventHandlers(
159
+ props.onPointerDownOutside,
160
+ (event) => {
161
+ const originalEvent = event.detail.originalEvent;
162
+ const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
163
+ const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
164
+ isRightClickOutsideRef.current = isRightClick;
165
+ },
166
+ { checkForDefaultPrevented: false }
167
+ ),
168
+ onFocusOutside: composeEventHandlers(
169
+ props.onFocusOutside,
170
+ (event) => event.preventDefault(),
171
+ { checkForDefaultPrevented: false }
172
+ )
173
+ }
174
+ ) });
175
+ });
176
+ var PopoverContentNonModal = React3.forwardRef((props, forwardedRef) => {
177
+ const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);
178
+ const hasInteractedOutsideRef = React3.useRef(false);
179
+ const hasPointerDownOutsideRef = React3.useRef(false);
180
+ return /* @__PURE__ */ jsx4(
181
+ PopoverContentImpl,
182
+ {
183
+ ...props,
184
+ ref: forwardedRef,
185
+ trapFocus: false,
186
+ disableOutsidePointerEvents: false,
187
+ onCloseAutoFocus: (event) => {
188
+ props.onCloseAutoFocus?.(event);
189
+ if (!event.defaultPrevented) {
190
+ if (!hasInteractedOutsideRef.current)
191
+ context.triggerRef.current?.focus();
192
+ event.preventDefault();
193
+ }
194
+ hasInteractedOutsideRef.current = false;
195
+ hasPointerDownOutsideRef.current = false;
196
+ },
197
+ onInteractOutside: (event) => {
198
+ props.onInteractOutside?.(event);
199
+ if (!event.defaultPrevented) {
200
+ hasInteractedOutsideRef.current = true;
201
+ if (event.detail.originalEvent.type === "pointerdown") {
202
+ hasPointerDownOutsideRef.current = true;
203
+ }
204
+ }
205
+ const target = event.target;
206
+ const targetIsTrigger = context.triggerRef.current?.contains(target);
207
+ if (targetIsTrigger) event.preventDefault();
208
+ if (event.detail.originalEvent.type === "focusin" && hasPointerDownOutsideRef.current) {
209
+ event.preventDefault();
210
+ }
211
+ }
212
+ }
213
+ );
214
+ });
215
+ var PopoverContentImpl = React3.forwardRef((props, forwardedRef) => {
216
+ const {
217
+ __scopePopover,
218
+ trapFocus,
219
+ onOpenAutoFocus,
220
+ onCloseAutoFocus,
221
+ disableOutsidePointerEvents,
222
+ onEscapeKeyDown,
223
+ onPointerDownOutside,
224
+ onFocusOutside,
225
+ onInteractOutside,
226
+ ...contentProps
227
+ } = props;
228
+ const context = usePopoverContext(CONTENT_NAME, __scopePopover);
229
+ const popperScope = usePopperScope(__scopePopover);
230
+ useFocusGuards();
231
+ return /* @__PURE__ */ jsx4(
232
+ FocusScope,
233
+ {
234
+ asChild: true,
235
+ loop: true,
236
+ trapped: trapFocus,
237
+ onMountAutoFocus: onOpenAutoFocus,
238
+ onUnmountAutoFocus: onCloseAutoFocus,
239
+ children: /* @__PURE__ */ jsx4(
240
+ DismissableLayer,
241
+ {
242
+ asChild: true,
243
+ disableOutsidePointerEvents,
244
+ onInteractOutside,
245
+ onEscapeKeyDown,
246
+ onPointerDownOutside,
247
+ onFocusOutside,
248
+ onDismiss: () => context.onOpenChange(false),
249
+ children: /* @__PURE__ */ jsx4(
250
+ PopperPrimitive3.Content,
251
+ {
252
+ "data-state": getState(context.open),
253
+ role: "dialog",
254
+ id: context.contentId,
255
+ ...popperScope,
256
+ ...contentProps,
257
+ ref: forwardedRef,
258
+ style: {
259
+ ...contentProps.style,
260
+ // re-namespace exposed content custom properties
261
+ ...{
262
+ "--huin-core-popover-content-transform-origin": "var(--huin-core-popper-transform-origin)",
263
+ "--huin-core-popover-content-available-width": "var(--huin-core-popper-available-width)",
264
+ "--huin-core-popover-content-available-height": "var(--huin-core-popper-available-height)",
265
+ "--huin-core-popover-trigger-width": "var(--huin-core-popper-anchor-width)",
266
+ "--huin-core-popover-trigger-height": "var(--huin-core-popper-anchor-height)"
267
+ }
268
+ }
269
+ }
270
+ )
271
+ }
272
+ )
273
+ }
274
+ );
275
+ });
276
+ function getState(open) {
277
+ return open ? "open" : "closed";
278
+ }
279
+
280
+ // packages/react/popover/src/PopoverTrigger.tsx
281
+ import { jsx as jsx5 } from "react/jsx-runtime";
282
+ var TRIGGER_NAME = "PopoverTrigger";
283
+ var PopoverTrigger = React4.forwardRef((props, forwardedRef) => {
284
+ const { __scopePopover, ...triggerProps } = props;
285
+ const context = usePopoverContext(TRIGGER_NAME, __scopePopover);
286
+ const popperScope = usePopperScope(__scopePopover);
287
+ const composedTriggerRef = useComposedRefs2(forwardedRef, context.triggerRef);
288
+ const trigger = /* @__PURE__ */ jsx5(
289
+ Primitive.button,
290
+ {
291
+ type: "button",
292
+ "aria-haspopup": "dialog",
293
+ "aria-expanded": context.open,
294
+ "aria-controls": context.contentId,
295
+ "data-state": getState(context.open),
296
+ ...triggerProps,
297
+ ref: composedTriggerRef,
298
+ onClick: composeEventHandlers2(props.onClick, context.onOpenToggle)
299
+ }
300
+ );
301
+ return context.hasCustomAnchor ? trigger : /* @__PURE__ */ jsx5(PopperPrimitive4.Anchor, { asChild: true, ...popperScope, children: trigger });
302
+ });
303
+ PopoverTrigger.displayName = TRIGGER_NAME;
304
+
305
+ // packages/react/popover/src/PopoverClose.tsx
306
+ import React5 from "react";
307
+ import { Primitive as Primitive2 } from "@huin-core/react-primitive";
308
+ import { composeEventHandlers as composeEventHandlers3 } from "@huin-core/primitive";
309
+ import { jsx as jsx6 } from "react/jsx-runtime";
310
+ var CLOSE_NAME = "PopoverClose";
311
+ var PopoverClose = React5.forwardRef(
312
+ (props, forwardedRef) => {
313
+ const { __scopePopover, ...closeProps } = props;
314
+ const context = usePopoverContext(CLOSE_NAME, __scopePopover);
315
+ return /* @__PURE__ */ jsx6(
316
+ Primitive2.button,
317
+ {
318
+ type: "button",
319
+ ...closeProps,
320
+ ref: forwardedRef,
321
+ onClick: composeEventHandlers3(
322
+ props.onClick,
323
+ () => context.onOpenChange(false)
324
+ )
325
+ }
326
+ );
327
+ }
328
+ );
329
+ PopoverClose.displayName = CLOSE_NAME;
330
+
331
+ // packages/react/popover/src/PopoverArrow.tsx
332
+ import * as PopperPrimitive5 from "@huin-core/react-popper";
333
+ import React6 from "react";
334
+ import { jsx as jsx7 } from "react/jsx-runtime";
335
+ var ARROW_NAME = "PopoverArrow";
336
+ var PopoverArrow = React6.forwardRef(
337
+ (props, forwardedRef) => {
338
+ const { __scopePopover, ...arrowProps } = props;
339
+ const popperScope = usePopperScope(__scopePopover);
340
+ return /* @__PURE__ */ jsx7(
341
+ PopperPrimitive5.Arrow,
342
+ {
343
+ ...popperScope,
344
+ ...arrowProps,
345
+ ref: forwardedRef
346
+ }
347
+ );
348
+ }
349
+ );
350
+ PopoverArrow.displayName = ARROW_NAME;
351
+ export {
352
+ Popover,
353
+ PopoverAnchor,
354
+ PopoverArrow,
355
+ PopoverClose,
356
+ PopoverContent,
357
+ PopoverPortal,
358
+ PopoverTrigger,
359
+ Root2 as Root,
360
+ createPopoverScope
361
+ };
362
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/Popover.tsx", "../src/PopoverAnchor.tsx", "../src/PopoverTrigger.tsx", "../src/PopoverContent.tsx", "../src/PopoverPortal.tsx", "../src/PopoverClose.tsx", "../src/PopoverArrow.tsx"],
4
+ "sourcesContent": ["import * as React from \"react\";\nimport { createContextScope } from \"@huin-core/react-context\";\nimport { useId } from \"@huin-core/react-id\";\nimport * as PopperPrimitive from \"@huin-core/react-popper\";\nimport { createPopperScope } from \"@huin-core/react-popper\";\nimport { useControllableState } from \"@huin-core/react-use-controllable-state\";\nimport type { Scope } from \"@huin-core/react-context\";\n\n/* -------------------------------------------------------------------------------------------------\n * Popover\n * -----------------------------------------------------------------------------------------------*/\n\nconst POPOVER_NAME = \"Popover\";\n\nexport type ScopedProps<P> = P & { __scopePopover?: Scope };\nexport const [createPopoverContext, createPopoverScope] = createContextScope(\n POPOVER_NAME,\n [createPopperScope]\n);\nexport const usePopperScope = createPopperScope();\n\ntype PopoverContextValue = {\n triggerRef: React.RefObject<HTMLButtonElement>;\n contentId: string;\n open: boolean;\n onOpenChange(open: boolean): void;\n onOpenToggle(): void;\n hasCustomAnchor: boolean;\n onCustomAnchorAdd(): void;\n onCustomAnchorRemove(): void;\n modal: boolean;\n};\n\nexport const [PopoverProvider, usePopoverContext] =\n createPopoverContext<PopoverContextValue>(POPOVER_NAME);\n\ninterface PopoverProps {\n children?: React.ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n modal?: boolean;\n}\n\nconst Popover: React.FC<PopoverProps> = (props: ScopedProps<PopoverProps>) => {\n const {\n __scopePopover,\n children,\n open: openProp,\n defaultOpen,\n onOpenChange,\n modal = false,\n } = props;\n const popperScope = usePopperScope(__scopePopover);\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const [hasCustomAnchor, setHasCustomAnchor] = React.useState(false);\n const [open = false, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n\n return (\n <PopperPrimitive.Root {...popperScope}>\n <PopoverProvider\n scope={__scopePopover}\n contentId={useId()}\n triggerRef={triggerRef}\n open={open}\n onOpenChange={setOpen}\n onOpenToggle={React.useCallback(\n () => setOpen((prevOpen) => !prevOpen),\n [setOpen]\n )}\n hasCustomAnchor={hasCustomAnchor}\n onCustomAnchorAdd={React.useCallback(\n () => setHasCustomAnchor(true),\n []\n )}\n onCustomAnchorRemove={React.useCallback(\n () => setHasCustomAnchor(false),\n []\n )}\n modal={modal}\n >\n {children}\n </PopoverProvider>\n </PopperPrimitive.Root>\n );\n};\n\nPopover.displayName = POPOVER_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Popover;\n\nexport { Popover, Root };\nexport type { PopoverProps };\n", "import * as PopperPrimitive from \"@huin-core/react-popper\";\nimport React from \"react\";\nimport { ScopedProps, usePopoverContext, usePopperScope } from \"./Popover\";\n\nconst ANCHOR_NAME = \"PopoverAnchor\";\n\ntype PopoverAnchorElement = React.ElementRef<typeof PopperPrimitive.Anchor>;\ntype PopperAnchorProps = React.ComponentPropsWithoutRef<\n typeof PopperPrimitive.Anchor\n>;\ninterface PopoverAnchorProps extends PopperAnchorProps {}\n\nconst PopoverAnchor = React.forwardRef<\n PopoverAnchorElement,\n PopoverAnchorProps\n>((props: ScopedProps<PopoverAnchorProps>, forwardedRef) => {\n const { __scopePopover, ...anchorProps } = props;\n const context = usePopoverContext(ANCHOR_NAME, __scopePopover);\n const popperScope = usePopperScope(__scopePopover);\n const { onCustomAnchorAdd, onCustomAnchorRemove } = context;\n\n React.useEffect(() => {\n onCustomAnchorAdd();\n return () => onCustomAnchorRemove();\n }, [onCustomAnchorAdd, onCustomAnchorRemove]);\n\n return (\n <PopperPrimitive.Anchor\n {...popperScope}\n {...anchorProps}\n ref={forwardedRef}\n />\n );\n});\n\nPopoverAnchor.displayName = ANCHOR_NAME;\n\nexport { PopoverAnchor };\nexport type { PopoverAnchorProps };\n", "import React from \"react\";\nimport { Primitive } from \"@huin-core/react-primitive\";\nimport { ScopedProps, usePopoverContext, usePopperScope } from \"./Popover\";\nimport { useComposedRefs } from \"@huin-core/react-compose-refs\";\nimport * as PopperPrimitive from \"@huin-core/react-popper\";\nimport { composeEventHandlers } from \"@huin-core/primitive\";\nimport { getState } from \"./PopoverContent\";\n\nconst TRIGGER_NAME = \"PopoverTrigger\";\n\ntype PopoverTriggerElement = React.ElementRef<typeof Primitive.button>;\nexport type PrimitiveButtonProps = React.ComponentPropsWithoutRef<\n typeof Primitive.button\n>;\ninterface PopoverTriggerProps extends PrimitiveButtonProps {}\n\nconst PopoverTrigger = React.forwardRef<\n PopoverTriggerElement,\n PopoverTriggerProps\n>((props: ScopedProps<PopoverTriggerProps>, forwardedRef) => {\n const { __scopePopover, ...triggerProps } = props;\n const context = usePopoverContext(TRIGGER_NAME, __scopePopover);\n const popperScope = usePopperScope(__scopePopover);\n const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);\n\n const trigger = (\n <Primitive.button\n type=\"button\"\n aria-haspopup=\"dialog\"\n aria-expanded={context.open}\n aria-controls={context.contentId}\n data-state={getState(context.open)}\n {...triggerProps}\n ref={composedTriggerRef}\n onClick={composeEventHandlers(props.onClick, context.onOpenToggle)}\n />\n );\n\n return context.hasCustomAnchor ? (\n trigger\n ) : (\n <PopperPrimitive.Anchor asChild {...popperScope}>\n {trigger}\n </PopperPrimitive.Anchor>\n );\n});\n\nPopoverTrigger.displayName = TRIGGER_NAME;\n\nexport { PopoverTrigger };\nexport type { PopoverTriggerProps };\n", "import React from \"react\";\nimport { ScopedProps, usePopoverContext, usePopperScope } from \"./Popover\";\nimport { Presence } from \"@huin-core/react-presence\";\nimport { useComposedRefs } from \"@huin-core/react-compose-refs\";\nimport { hideOthers } from \"aria-hidden\";\nimport { RemoveScroll } from \"react-remove-scroll\";\nimport { Slot } from \"@huin-core/react-slot\";\nimport { composeEventHandlers } from \"@huin-core/primitive\";\nimport * as PopperPrimitive from \"@huin-core/react-popper\";\nimport { DismissableLayer } from \"@huin-core/react-dismissable-layer\";\nimport { FocusScope } from \"@huin-core/react-focus-scope\";\nimport { useFocusGuards } from \"@huin-core/react-focus-guards\";\nimport { usePortalContext } from \"./PopoverPortal\";\n\nconst CONTENT_NAME = \"PopoverContent\";\n\ninterface PopoverContentProps extends PopoverContentTypeProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst PopoverContent = React.forwardRef<\n PopoverContentTypeElement,\n PopoverContentProps\n>((props: ScopedProps<PopoverContentProps>, forwardedRef) => {\n const portalContext = usePortalContext(CONTENT_NAME, props.__scopePopover);\n const { forceMount = portalContext.forceMount, ...contentProps } = props;\n const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);\n return (\n <Presence present={forceMount || context.open}>\n {context.modal ? (\n <PopoverContentModal {...contentProps} ref={forwardedRef} />\n ) : (\n <PopoverContentNonModal {...contentProps} ref={forwardedRef} />\n )}\n </Presence>\n );\n});\n\nPopoverContent.displayName = CONTENT_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype PopoverContentTypeElement = PopoverContentImplElement;\ninterface PopoverContentTypeProps\n extends Omit<\n PopoverContentImplProps,\n \"trapFocus\" | \"disableOutsidePointerEvents\"\n > {}\n\nconst PopoverContentModal = React.forwardRef<\n PopoverContentTypeElement,\n PopoverContentTypeProps\n>((props: ScopedProps<PopoverContentTypeProps>, forwardedRef) => {\n const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);\n const contentRef = React.useRef<HTMLDivElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, contentRef);\n const isRightClickOutsideRef = React.useRef(false);\n\n // aria-hide everything except the content (better supported equivalent to setting aria-modal)\n React.useEffect(() => {\n const content = contentRef.current;\n if (content) return hideOthers(content);\n }, []);\n\n return (\n <RemoveScroll as={Slot} allowPinchZoom>\n <PopoverContentImpl\n {...props}\n ref={composedRefs}\n // we make sure we're not trapping once it's been closed\n // (closed !== unmounted when animating out)\n trapFocus={context.open}\n disableOutsidePointerEvents\n onCloseAutoFocus={composeEventHandlers(\n props.onCloseAutoFocus,\n (event) => {\n event.preventDefault();\n if (!isRightClickOutsideRef.current)\n context.triggerRef.current?.focus();\n }\n )}\n onPointerDownOutside={composeEventHandlers(\n props.onPointerDownOutside,\n (event) => {\n const originalEvent = event.detail.originalEvent;\n const ctrlLeftClick =\n originalEvent.button === 0 && originalEvent.ctrlKey === true;\n const isRightClick = originalEvent.button === 2 || ctrlLeftClick;\n\n isRightClickOutsideRef.current = isRightClick;\n },\n { checkForDefaultPrevented: false }\n )}\n // When focus is trapped, a `focusout` event may still happen.\n // We make sure we don't trigger our `onDismiss` in such case.\n onFocusOutside={composeEventHandlers(\n props.onFocusOutside,\n (event) => event.preventDefault(),\n { checkForDefaultPrevented: false }\n )}\n />\n </RemoveScroll>\n );\n});\n\nconst PopoverContentNonModal = React.forwardRef<\n PopoverContentTypeElement,\n PopoverContentTypeProps\n>((props: ScopedProps<PopoverContentTypeProps>, forwardedRef) => {\n const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);\n const hasInteractedOutsideRef = React.useRef(false);\n const hasPointerDownOutsideRef = React.useRef(false);\n\n return (\n <PopoverContentImpl\n {...props}\n ref={forwardedRef}\n trapFocus={false}\n disableOutsidePointerEvents={false}\n onCloseAutoFocus={(event) => {\n props.onCloseAutoFocus?.(event);\n\n if (!event.defaultPrevented) {\n if (!hasInteractedOutsideRef.current)\n context.triggerRef.current?.focus();\n // Always prevent auto focus because we either focus manually or want user agent focus\n event.preventDefault();\n }\n\n hasInteractedOutsideRef.current = false;\n hasPointerDownOutsideRef.current = false;\n }}\n onInteractOutside={(event) => {\n props.onInteractOutside?.(event);\n\n if (!event.defaultPrevented) {\n hasInteractedOutsideRef.current = true;\n if (event.detail.originalEvent.type === \"pointerdown\") {\n hasPointerDownOutsideRef.current = true;\n }\n }\n\n // Prevent dismissing when clicking the trigger.\n // As the trigger is already setup to close, without doing so would\n // cause it to close and immediately open.\n const target = event.target as HTMLElement;\n const targetIsTrigger = context.triggerRef.current?.contains(target);\n if (targetIsTrigger) event.preventDefault();\n\n // On Safari if the trigger is inside a container with tabIndex={0}, when clicked\n // we will get the pointer down outside event on the trigger, but then a subsequent\n // focus outside event on the container, we ignore any focus outside event when we've\n // already had a pointer down outside event.\n if (\n event.detail.originalEvent.type === \"focusin\" &&\n hasPointerDownOutsideRef.current\n ) {\n event.preventDefault();\n }\n }}\n />\n );\n});\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype PopoverContentImplElement = React.ElementRef<\n typeof PopperPrimitive.Content\n>;\ntype FocusScopeProps = React.ComponentPropsWithoutRef<typeof FocusScope>;\ntype DismissableLayerProps = React.ComponentPropsWithoutRef<\n typeof DismissableLayer\n>;\ntype PopperContentProps = React.ComponentPropsWithoutRef<\n typeof PopperPrimitive.Content\n>;\ninterface PopoverContentImplProps\n extends Omit<PopperContentProps, \"onPlaced\">,\n Omit<DismissableLayerProps, \"onDismiss\"> {\n /**\n * Whether focus should be trapped within the `Popover`\n * (default: false)\n */\n trapFocus?: FocusScopeProps[\"trapped\"];\n\n /**\n * Event handler called when auto-focusing on open.\n * Can be prevented.\n */\n onOpenAutoFocus?: FocusScopeProps[\"onMountAutoFocus\"];\n\n /**\n * Event handler called when auto-focusing on close.\n * Can be prevented.\n */\n onCloseAutoFocus?: FocusScopeProps[\"onUnmountAutoFocus\"];\n}\n\nconst PopoverContentImpl = React.forwardRef<\n PopoverContentImplElement,\n PopoverContentImplProps\n>((props: ScopedProps<PopoverContentImplProps>, forwardedRef) => {\n const {\n __scopePopover,\n trapFocus,\n onOpenAutoFocus,\n onCloseAutoFocus,\n disableOutsidePointerEvents,\n onEscapeKeyDown,\n onPointerDownOutside,\n onFocusOutside,\n onInteractOutside,\n ...contentProps\n } = props;\n const context = usePopoverContext(CONTENT_NAME, __scopePopover);\n const popperScope = usePopperScope(__scopePopover);\n\n // Make sure the whole tree has focus guards as our `Popover` may be\n // the last element in the DOM (beacuse of the `Portal`)\n useFocusGuards();\n\n return (\n <FocusScope\n asChild\n loop\n trapped={trapFocus}\n onMountAutoFocus={onOpenAutoFocus}\n onUnmountAutoFocus={onCloseAutoFocus}\n >\n <DismissableLayer\n asChild\n disableOutsidePointerEvents={disableOutsidePointerEvents}\n onInteractOutside={onInteractOutside}\n onEscapeKeyDown={onEscapeKeyDown}\n onPointerDownOutside={onPointerDownOutside}\n onFocusOutside={onFocusOutside}\n onDismiss={() => context.onOpenChange(false)}\n >\n <PopperPrimitive.Content\n data-state={getState(context.open)}\n role=\"dialog\"\n id={context.contentId}\n {...popperScope}\n {...contentProps}\n ref={forwardedRef}\n style={{\n ...contentProps.style,\n // re-namespace exposed content custom properties\n ...{\n \"--huin-core-popover-content-transform-origin\":\n \"var(--huin-core-popper-transform-origin)\",\n \"--huin-core-popover-content-available-width\":\n \"var(--huin-core-popper-available-width)\",\n \"--huin-core-popover-content-available-height\":\n \"var(--huin-core-popper-available-height)\",\n \"--huin-core-popover-trigger-width\":\n \"var(--huin-core-popper-anchor-width)\",\n \"--huin-core-popover-trigger-height\":\n \"var(--huin-core-popper-anchor-height)\",\n },\n }}\n />\n </DismissableLayer>\n </FocusScope>\n );\n});\n\nexport function getState(open: boolean) {\n return open ? \"open\" : \"closed\";\n}\nexport { PopoverContent };\nexport type { PopoverContentProps };\n", "import { Portal as PortalPrimitive } from \"@huin-core/react-portal\";\nimport {\n createPopoverContext,\n ScopedProps,\n usePopoverContext,\n} from \"./Popover\";\nimport { Presence } from \"@huin-core/react-presence\";\n\nconst PORTAL_NAME = \"PopoverPortal\";\n\ntype PortalContextValue = { forceMount?: true };\nexport const [PortalProvider, usePortalContext] =\n createPopoverContext<PortalContextValue>(PORTAL_NAME, {\n forceMount: undefined,\n });\n\ntype PortalProps = React.ComponentPropsWithoutRef<typeof PortalPrimitive>;\ninterface PopoverPortalProps {\n children?: React.ReactNode;\n /**\n * Specify a container element to portal the content into.\n */\n container?: PortalProps[\"container\"];\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst PopoverPortal: React.FC<PopoverPortalProps> = (\n props: ScopedProps<PopoverPortalProps>\n) => {\n const { __scopePopover, forceMount, children, container } = props;\n const context = usePopoverContext(PORTAL_NAME, __scopePopover);\n return (\n <PortalProvider scope={__scopePopover} forceMount={forceMount}>\n <Presence present={forceMount || context.open}>\n <PortalPrimitive asChild container={container}>\n {children}\n </PortalPrimitive>\n </Presence>\n </PortalProvider>\n );\n};\n\nPopoverPortal.displayName = PORTAL_NAME;\n\nexport { PopoverPortal };\nexport type { PopoverPortalProps };\n", "import React from \"react\";\nimport { Primitive } from \"@huin-core/react-primitive\";\nimport { ScopedProps, usePopoverContext } from \"./Popover\";\nimport { composeEventHandlers } from \"@huin-core/primitive\";\nimport { PrimitiveButtonProps } from \"./PopoverTrigger\";\n\nconst CLOSE_NAME = \"PopoverClose\";\n\ntype PopoverCloseElement = React.ElementRef<typeof Primitive.button>;\ninterface PopoverCloseProps extends PrimitiveButtonProps {}\n\nconst PopoverClose = React.forwardRef<PopoverCloseElement, PopoverCloseProps>(\n (props: ScopedProps<PopoverCloseProps>, forwardedRef) => {\n const { __scopePopover, ...closeProps } = props;\n const context = usePopoverContext(CLOSE_NAME, __scopePopover);\n return (\n <Primitive.button\n type=\"button\"\n {...closeProps}\n ref={forwardedRef}\n onClick={composeEventHandlers(props.onClick, () =>\n context.onOpenChange(false)\n )}\n />\n );\n }\n);\n\nPopoverClose.displayName = CLOSE_NAME;\n\nexport { PopoverClose };\nexport type { PopoverCloseProps };\n", "import * as PopperPrimitive from \"@huin-core/react-popper\";\nimport React from \"react\";\nimport { ScopedProps, usePopperScope } from \"./Popover\";\n\nconst ARROW_NAME = \"PopoverArrow\";\n\ntype PopoverArrowElement = React.ElementRef<typeof PopperPrimitive.Arrow>;\ntype PopperArrowProps = React.ComponentPropsWithoutRef<\n typeof PopperPrimitive.Arrow\n>;\ninterface PopoverArrowProps extends PopperArrowProps {}\n\nconst PopoverArrow = React.forwardRef<PopoverArrowElement, PopoverArrowProps>(\n (props: ScopedProps<PopoverArrowProps>, forwardedRef) => {\n const { __scopePopover, ...arrowProps } = props;\n const popperScope = usePopperScope(__scopePopover);\n return (\n <PopperPrimitive.Arrow\n {...popperScope}\n {...arrowProps}\n ref={forwardedRef}\n />\n );\n }\n);\n\nPopoverArrow.displayName = ARROW_NAME;\n\nexport { PopoverArrow };\nexport type { PopoverArrowProps };\n"],
5
+ "mappings": ";;;AAAA,YAAY,WAAW;AACvB,SAAS,0BAA0B;AACnC,SAAS,aAAa;AACtB,YAAY,qBAAqB;AACjC,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AA2D/B;AApDN,IAAM,eAAe;AAGd,IAAM,CAAC,sBAAsB,kBAAkB,IAAI;AAAA,EACxD;AAAA,EACA,CAAC,iBAAiB;AACpB;AACO,IAAM,iBAAiB,kBAAkB;AAczC,IAAM,CAAC,iBAAiB,iBAAiB,IAC9C,qBAA0C,YAAY;AAUxD,IAAM,UAAkC,CAAC,UAAqC;AAC5E,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,EACV,IAAI;AACJ,QAAM,cAAc,eAAe,cAAc;AACjD,QAAM,aAAmB,aAA0B,IAAI;AACvD,QAAM,CAAC,iBAAiB,kBAAkB,IAAU,eAAS,KAAK;AAClE,QAAM,CAAC,OAAO,OAAO,OAAO,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AH,KAAiB,yBAAhB,EAAuB,SAAO,MAAE,GAAG,aACjC,mBACH;AAEJ,CAAC;AAED,eAAe,cAAc;;;AG/C7B,OAAOI,YAAW;AAClB,SAAS,aAAAC,kBAAiB;AAE1B,SAAS,wBAAAC,6BAA4B;AAa/B,gBAAAC,YAAA;AAVN,IAAM,aAAa;AAKnB,IAAM,eAAeC,OAAM;AAAA,EACzB,CAAC,OAAuC,iBAAiB;AACvD,UAAM,EAAE,gBAAgB,GAAG,WAAW,IAAI;AAC1C,UAAM,UAAU,kBAAkB,YAAY,cAAc;AAC5D,WACE,gBAAAD;AAAA,MAACE,WAAU;AAAA,MAAV;AAAA,QACC,MAAK;AAAA,QACJ,GAAG;AAAA,QACJ,KAAK;AAAA,QACL,SAASH;AAAA,UAAqB,MAAM;AAAA,UAAS,MAC3C,QAAQ,aAAa,KAAK;AAAA,QAC5B;AAAA;AAAA,IACF;AAAA,EAEJ;AACF;AAEA,aAAa,cAAc;;;AC5B3B,YAAYI,sBAAqB;AACjC,OAAOC,YAAW;AAgBZ,gBAAAC,YAAA;AAbN,IAAM,aAAa;AAQnB,IAAM,eAAeC,OAAM;AAAA,EACzB,CAAC,OAAuC,iBAAiB;AACvD,UAAM,EAAE,gBAAgB,GAAG,WAAW,IAAI;AAC1C,UAAM,cAAc,eAAe,cAAc;AACjD,WACE,gBAAAD;AAAA,MAAiB;AAAA,MAAhB;AAAA,QACE,GAAG;AAAA,QACH,GAAG;AAAA,QACJ,KAAK;AAAA;AAAA,IACP;AAAA,EAEJ;AACF;AAEA,aAAa,cAAc;",
6
+ "names": ["Root", "PopperPrimitive", "React", "jsx", "React", "React", "useComposedRefs", "PopperPrimitive", "composeEventHandlers", "React", "Presence", "PopperPrimitive", "jsx", "jsx", "React", "Presence", "jsx", "React", "useComposedRefs", "composeEventHandlers", "React", "Primitive", "composeEventHandlers", "jsx", "React", "Primitive", "PopperPrimitive", "React", "jsx", "React"]
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huin-core/react-popover",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {
@@ -20,7 +20,8 @@
20
20
  "types": "./dist/index.d.ts",
21
21
  "files": [
22
22
  "dist",
23
- "README.md"
23
+ "README.md",
24
+ "package.json"
24
25
  ],
25
26
  "sideEffects": false,
26
27
  "scripts": {