@huin-core/react-popper 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,56 @@
1
+ import * as React from 'react';
2
+ import * as ArrowPrimitive from '@huin-core/react-arrow';
3
+ import { Primitive } from '@huin-core/react-primitive';
4
+ import { Measurable } from '@huin-core/rect';
5
+
6
+ type Scope<C = any> = {
7
+ [scopeName: string]: React.Context<C>[];
8
+ } | undefined;
9
+ type ScopeHook = (scope: Scope) => {
10
+ [__scopeProp: string]: Scope;
11
+ };
12
+ interface CreateScope {
13
+ scopeName: string;
14
+ (): ScopeHook;
15
+ }
16
+
17
+ declare const SIDE_OPTIONS: readonly ["top", "right", "bottom", "left"];
18
+ declare const ALIGN_OPTIONS: readonly ["start", "center", "end"];
19
+ type Side = (typeof SIDE_OPTIONS)[number];
20
+ type Align = (typeof ALIGN_OPTIONS)[number];
21
+ declare const createPopperScope: CreateScope;
22
+ interface PopperProps {
23
+ children?: React.ReactNode;
24
+ }
25
+ declare const Popper: React.FC<PopperProps>;
26
+ type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
27
+ interface PopperAnchorProps extends PrimitiveDivProps {
28
+ virtualRef?: React.RefObject<Measurable>;
29
+ }
30
+ declare const PopperAnchor: React.ForwardRefExoticComponent<PopperAnchorProps & React.RefAttributes<HTMLDivElement>>;
31
+ type Boundary = Element | null;
32
+ interface PopperContentProps extends PrimitiveDivProps {
33
+ side?: Side;
34
+ sideOffset?: number;
35
+ align?: Align;
36
+ alignOffset?: number;
37
+ arrowPadding?: number;
38
+ avoidCollisions?: boolean;
39
+ collisionBoundary?: Boundary | Boundary[];
40
+ collisionPadding?: number | Partial<Record<Side, number>>;
41
+ sticky?: 'partial' | 'always';
42
+ hideWhenDetached?: boolean;
43
+ updatePositionStrategy?: 'optimized' | 'always';
44
+ onPlaced?: () => void;
45
+ }
46
+ declare const PopperContent: React.ForwardRefExoticComponent<PopperContentProps & React.RefAttributes<HTMLDivElement>>;
47
+ type ArrowProps = React.ComponentPropsWithoutRef<typeof ArrowPrimitive.Root>;
48
+ interface PopperArrowProps extends ArrowProps {
49
+ }
50
+ declare const PopperArrow: React.ForwardRefExoticComponent<PopperArrowProps & React.RefAttributes<SVGSVGElement>>;
51
+ declare const Root: React.FC<PopperProps>;
52
+ declare const Anchor: React.ForwardRefExoticComponent<PopperAnchorProps & React.RefAttributes<HTMLDivElement>>;
53
+ declare const Content: React.ForwardRefExoticComponent<PopperContentProps & React.RefAttributes<HTMLDivElement>>;
54
+ declare const Arrow: React.ForwardRefExoticComponent<PopperArrowProps & React.RefAttributes<SVGSVGElement>>;
55
+
56
+ export { ALIGN_OPTIONS, Anchor, Arrow, Content, Popper, PopperAnchor, type PopperAnchorProps, PopperArrow, type PopperArrowProps, PopperContent, type PopperContentProps, type PopperProps, Root, SIDE_OPTIONS, createPopperScope };
@@ -0,0 +1,56 @@
1
+ import * as React from 'react';
2
+ import * as ArrowPrimitive from '@huin-core/react-arrow';
3
+ import { Primitive } from '@huin-core/react-primitive';
4
+ import { Measurable } from '@huin-core/rect';
5
+
6
+ type Scope<C = any> = {
7
+ [scopeName: string]: React.Context<C>[];
8
+ } | undefined;
9
+ type ScopeHook = (scope: Scope) => {
10
+ [__scopeProp: string]: Scope;
11
+ };
12
+ interface CreateScope {
13
+ scopeName: string;
14
+ (): ScopeHook;
15
+ }
16
+
17
+ declare const SIDE_OPTIONS: readonly ["top", "right", "bottom", "left"];
18
+ declare const ALIGN_OPTIONS: readonly ["start", "center", "end"];
19
+ type Side = (typeof SIDE_OPTIONS)[number];
20
+ type Align = (typeof ALIGN_OPTIONS)[number];
21
+ declare const createPopperScope: CreateScope;
22
+ interface PopperProps {
23
+ children?: React.ReactNode;
24
+ }
25
+ declare const Popper: React.FC<PopperProps>;
26
+ type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
27
+ interface PopperAnchorProps extends PrimitiveDivProps {
28
+ virtualRef?: React.RefObject<Measurable>;
29
+ }
30
+ declare const PopperAnchor: React.ForwardRefExoticComponent<PopperAnchorProps & React.RefAttributes<HTMLDivElement>>;
31
+ type Boundary = Element | null;
32
+ interface PopperContentProps extends PrimitiveDivProps {
33
+ side?: Side;
34
+ sideOffset?: number;
35
+ align?: Align;
36
+ alignOffset?: number;
37
+ arrowPadding?: number;
38
+ avoidCollisions?: boolean;
39
+ collisionBoundary?: Boundary | Boundary[];
40
+ collisionPadding?: number | Partial<Record<Side, number>>;
41
+ sticky?: 'partial' | 'always';
42
+ hideWhenDetached?: boolean;
43
+ updatePositionStrategy?: 'optimized' | 'always';
44
+ onPlaced?: () => void;
45
+ }
46
+ declare const PopperContent: React.ForwardRefExoticComponent<PopperContentProps & React.RefAttributes<HTMLDivElement>>;
47
+ type ArrowProps = React.ComponentPropsWithoutRef<typeof ArrowPrimitive.Root>;
48
+ interface PopperArrowProps extends ArrowProps {
49
+ }
50
+ declare const PopperArrow: React.ForwardRefExoticComponent<PopperArrowProps & React.RefAttributes<SVGSVGElement>>;
51
+ declare const Root: React.FC<PopperProps>;
52
+ declare const Anchor: React.ForwardRefExoticComponent<PopperAnchorProps & React.RefAttributes<HTMLDivElement>>;
53
+ declare const Content: React.ForwardRefExoticComponent<PopperContentProps & React.RefAttributes<HTMLDivElement>>;
54
+ declare const Arrow: React.ForwardRefExoticComponent<PopperArrowProps & React.RefAttributes<SVGSVGElement>>;
55
+
56
+ export { ALIGN_OPTIONS, Anchor, Arrow, Content, Popper, PopperAnchor, type PopperAnchorProps, PopperArrow, type PopperArrowProps, PopperContent, type PopperContentProps, type PopperProps, Root, SIDE_OPTIONS, createPopperScope };
package/dist/index.js ADDED
@@ -0,0 +1,325 @@
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/popper/src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ ALIGN_OPTIONS: () => ALIGN_OPTIONS,
35
+ Anchor: () => Anchor,
36
+ Arrow: () => Arrow,
37
+ Content: () => Content,
38
+ Popper: () => Popper,
39
+ PopperAnchor: () => PopperAnchor,
40
+ PopperArrow: () => PopperArrow,
41
+ PopperContent: () => PopperContent,
42
+ Root: () => Root2,
43
+ SIDE_OPTIONS: () => SIDE_OPTIONS,
44
+ createPopperScope: () => createPopperScope
45
+ });
46
+ module.exports = __toCommonJS(src_exports);
47
+
48
+ // packages/react/popper/src/Popper.tsx
49
+ var React = __toESM(require("react"));
50
+ var import_react_dom = require("@floating-ui/react-dom");
51
+ var ArrowPrimitive = __toESM(require("@huin-core/react-arrow"));
52
+ var import_react_compose_refs = require("@huin-core/react-compose-refs");
53
+ var import_react_context = require("@huin-core/react-context");
54
+ var import_react_primitive = require("@huin-core/react-primitive");
55
+ var import_react_use_callback_ref = require("@huin-core/react-use-callback-ref");
56
+ var import_react_use_layout_effect = require("@huin-core/react-use-layout-effect");
57
+ var import_react_use_size = require("@huin-core/react-use-size");
58
+ var import_jsx_runtime = require("react/jsx-runtime");
59
+ var SIDE_OPTIONS = ["top", "right", "bottom", "left"];
60
+ var ALIGN_OPTIONS = ["start", "center", "end"];
61
+ var POPPER_NAME = "Popper";
62
+ var [createPopperContext, createPopperScope] = (0, import_react_context.createContextScope)(POPPER_NAME);
63
+ var [PopperProvider, usePopperContext] = createPopperContext(POPPER_NAME);
64
+ var Popper = (props) => {
65
+ const { __scopePopper, children } = props;
66
+ const [anchor, setAnchor] = React.useState(null);
67
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperProvider, { scope: __scopePopper, anchor, onAnchorChange: setAnchor, children });
68
+ };
69
+ Popper.displayName = POPPER_NAME;
70
+ var ANCHOR_NAME = "PopperAnchor";
71
+ var PopperAnchor = React.forwardRef(
72
+ (props, forwardedRef) => {
73
+ const { __scopePopper, virtualRef, ...anchorProps } = props;
74
+ const context = usePopperContext(ANCHOR_NAME, __scopePopper);
75
+ const ref = React.useRef(null);
76
+ const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
77
+ React.useEffect(() => {
78
+ context.onAnchorChange(virtualRef?.current || ref.current);
79
+ });
80
+ return virtualRef ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.div, { ...anchorProps, ref: composedRefs });
81
+ }
82
+ );
83
+ PopperAnchor.displayName = ANCHOR_NAME;
84
+ var CONTENT_NAME = "PopperContent";
85
+ var [PopperContentProvider, useContentContext] = createPopperContext(CONTENT_NAME);
86
+ var PopperContent = React.forwardRef(
87
+ (props, forwardedRef) => {
88
+ const {
89
+ __scopePopper,
90
+ side = "bottom",
91
+ sideOffset = 0,
92
+ align = "center",
93
+ alignOffset = 0,
94
+ arrowPadding = 0,
95
+ avoidCollisions = true,
96
+ collisionBoundary = [],
97
+ collisionPadding: collisionPaddingProp = 0,
98
+ sticky = "partial",
99
+ hideWhenDetached = false,
100
+ updatePositionStrategy = "optimized",
101
+ onPlaced,
102
+ ...contentProps
103
+ } = props;
104
+ const context = usePopperContext(CONTENT_NAME, __scopePopper);
105
+ const [content, setContent] = React.useState(null);
106
+ const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, (node) => setContent(node));
107
+ const [arrow, setArrow] = React.useState(null);
108
+ const arrowSize = (0, import_react_use_size.useSize)(arrow);
109
+ const arrowWidth = arrowSize?.width ?? 0;
110
+ const arrowHeight = arrowSize?.height ?? 0;
111
+ const desiredPlacement = side + (align !== "center" ? "-" + align : "");
112
+ const collisionPadding = typeof collisionPaddingProp === "number" ? collisionPaddingProp : { top: 0, right: 0, bottom: 0, left: 0, ...collisionPaddingProp };
113
+ const boundary = Array.isArray(collisionBoundary) ? collisionBoundary : [collisionBoundary];
114
+ const hasExplicitBoundaries = boundary.length > 0;
115
+ const detectOverflowOptions = {
116
+ padding: collisionPadding,
117
+ boundary: boundary.filter(isNotNull),
118
+ // with `strategy: 'fixed'`, this is the only way to get it to respect boundaries
119
+ altBoundary: hasExplicitBoundaries
120
+ };
121
+ const { refs, floatingStyles, placement, isPositioned, middlewareData } = (0, import_react_dom.useFloating)({
122
+ // default to `fixed` strategy so users don't have to pick and we also avoid focus scroll issues
123
+ strategy: "fixed",
124
+ placement: desiredPlacement,
125
+ whileElementsMounted: (...args) => {
126
+ const cleanup = (0, import_react_dom.autoUpdate)(...args, {
127
+ animationFrame: updatePositionStrategy === "always"
128
+ });
129
+ return cleanup;
130
+ },
131
+ elements: {
132
+ reference: context.anchor
133
+ },
134
+ middleware: [
135
+ (0, import_react_dom.offset)({ mainAxis: sideOffset + arrowHeight, alignmentAxis: alignOffset }),
136
+ avoidCollisions && (0, import_react_dom.shift)({
137
+ mainAxis: true,
138
+ crossAxis: false,
139
+ limiter: sticky === "partial" ? (0, import_react_dom.limitShift)() : void 0,
140
+ ...detectOverflowOptions
141
+ }),
142
+ avoidCollisions && (0, import_react_dom.flip)({ ...detectOverflowOptions }),
143
+ (0, import_react_dom.size)({
144
+ ...detectOverflowOptions,
145
+ apply: ({ elements, rects, availableWidth, availableHeight }) => {
146
+ const { width: anchorWidth, height: anchorHeight } = rects.reference;
147
+ const contentStyle = elements.floating.style;
148
+ contentStyle.setProperty("--huin-core-popper-available-width", `${availableWidth}px`);
149
+ contentStyle.setProperty("--huin-core-popper-available-height", `${availableHeight}px`);
150
+ contentStyle.setProperty("--huin-core-popper-anchor-width", `${anchorWidth}px`);
151
+ contentStyle.setProperty("--huin-core-popper-anchor-height", `${anchorHeight}px`);
152
+ }
153
+ }),
154
+ arrow && (0, import_react_dom.arrow)({ element: arrow, padding: arrowPadding }),
155
+ transformOrigin({ arrowWidth, arrowHeight }),
156
+ hideWhenDetached && (0, import_react_dom.hide)({ strategy: "referenceHidden", ...detectOverflowOptions })
157
+ ]
158
+ });
159
+ const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
160
+ const handlePlaced = (0, import_react_use_callback_ref.useCallbackRef)(onPlaced);
161
+ (0, import_react_use_layout_effect.useLayoutEffect)(() => {
162
+ if (isPositioned) {
163
+ handlePlaced?.();
164
+ }
165
+ }, [isPositioned, handlePlaced]);
166
+ const arrowX = middlewareData.arrow?.x;
167
+ const arrowY = middlewareData.arrow?.y;
168
+ const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;
169
+ const [contentZIndex, setContentZIndex] = React.useState();
170
+ (0, import_react_use_layout_effect.useLayoutEffect)(() => {
171
+ if (content) setContentZIndex(window.getComputedStyle(content).zIndex);
172
+ }, [content]);
173
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
174
+ "div",
175
+ {
176
+ ref: refs.setFloating,
177
+ "data-huin-core-popper-content-wrapper": "",
178
+ style: {
179
+ ...floatingStyles,
180
+ transform: isPositioned ? floatingStyles.transform : "translate(0, -200%)",
181
+ // keep off the page when measuring
182
+ minWidth: "max-content",
183
+ zIndex: contentZIndex,
184
+ ["--huin-core-popper-transform-origin"]: [
185
+ middlewareData.transformOrigin?.x,
186
+ middlewareData.transformOrigin?.y
187
+ ].join(" "),
188
+ // hide the content if using the hide middleware and should be hidden
189
+ // set visibility to hidden and disable pointer events so the UI behaves
190
+ // as if the PopperContent isn't there at all
191
+ ...middlewareData.hide?.referenceHidden && {
192
+ visibility: "hidden",
193
+ pointerEvents: "none"
194
+ }
195
+ },
196
+ dir: props.dir,
197
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
198
+ PopperContentProvider,
199
+ {
200
+ scope: __scopePopper,
201
+ placedSide,
202
+ onArrowChange: setArrow,
203
+ arrowX,
204
+ arrowY,
205
+ shouldHideArrow: cannotCenterArrow,
206
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
207
+ import_react_primitive.Primitive.div,
208
+ {
209
+ "data-side": placedSide,
210
+ "data-align": placedAlign,
211
+ ...contentProps,
212
+ ref: composedRefs,
213
+ style: {
214
+ ...contentProps.style,
215
+ // if the PopperContent hasn't been placed yet (not all measurements done)
216
+ // we prevent animations so that users's animation don't kick in too early referring wrong sides
217
+ animation: !isPositioned ? "none" : void 0
218
+ }
219
+ }
220
+ )
221
+ }
222
+ )
223
+ }
224
+ );
225
+ }
226
+ );
227
+ PopperContent.displayName = CONTENT_NAME;
228
+ var ARROW_NAME = "PopperArrow";
229
+ var OPPOSITE_SIDE = {
230
+ top: "bottom",
231
+ right: "left",
232
+ bottom: "top",
233
+ left: "right"
234
+ };
235
+ var PopperArrow = React.forwardRef(function PopperArrow2(props, forwardedRef) {
236
+ const { __scopePopper, ...arrowProps } = props;
237
+ const contentContext = useContentContext(ARROW_NAME, __scopePopper);
238
+ const baseSide = OPPOSITE_SIDE[contentContext.placedSide];
239
+ return (
240
+ // we have to use an extra wrapper because `ResizeObserver` (used by `useSize`)
241
+ // doesn't report size as we'd expect on SVG elements.
242
+ // it reports their bounding box which is effectively the largest path inside the SVG.
243
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
244
+ "span",
245
+ {
246
+ ref: contentContext.onArrowChange,
247
+ style: {
248
+ position: "absolute",
249
+ left: contentContext.arrowX,
250
+ top: contentContext.arrowY,
251
+ [baseSide]: 0,
252
+ transformOrigin: {
253
+ top: "",
254
+ right: "0 0",
255
+ bottom: "center 0",
256
+ left: "100% 0"
257
+ }[contentContext.placedSide],
258
+ transform: {
259
+ top: "translateY(100%)",
260
+ right: "translateY(50%) rotate(90deg) translateX(-50%)",
261
+ bottom: `rotate(180deg)`,
262
+ left: "translateY(50%) rotate(-90deg) translateX(50%)"
263
+ }[contentContext.placedSide],
264
+ visibility: contentContext.shouldHideArrow ? "hidden" : void 0
265
+ },
266
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
267
+ ArrowPrimitive.Root,
268
+ {
269
+ ...arrowProps,
270
+ ref: forwardedRef,
271
+ style: {
272
+ ...arrowProps.style,
273
+ // ensures the element can be measured correctly (mostly for if SVG)
274
+ display: "block"
275
+ }
276
+ }
277
+ )
278
+ }
279
+ )
280
+ );
281
+ });
282
+ PopperArrow.displayName = ARROW_NAME;
283
+ function isNotNull(value) {
284
+ return value !== null;
285
+ }
286
+ var transformOrigin = (options) => ({
287
+ name: "transformOrigin",
288
+ options,
289
+ fn(data) {
290
+ const { placement, rects, middlewareData } = data;
291
+ const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;
292
+ const isArrowHidden = cannotCenterArrow;
293
+ const arrowWidth = isArrowHidden ? 0 : options.arrowWidth;
294
+ const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;
295
+ const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
296
+ const noArrowAlign = { start: "0%", center: "50%", end: "100%" }[placedAlign];
297
+ const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2;
298
+ const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;
299
+ let x = "";
300
+ let y = "";
301
+ if (placedSide === "bottom") {
302
+ x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
303
+ y = `${-arrowHeight}px`;
304
+ } else if (placedSide === "top") {
305
+ x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
306
+ y = `${rects.floating.height + arrowHeight}px`;
307
+ } else if (placedSide === "right") {
308
+ x = `${-arrowHeight}px`;
309
+ y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
310
+ } else if (placedSide === "left") {
311
+ x = `${rects.floating.width + arrowHeight}px`;
312
+ y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
313
+ }
314
+ return { data: { x, y } };
315
+ }
316
+ });
317
+ function getSideAndAlignFromPlacement(placement) {
318
+ const [side, align = "center"] = placement.split("-");
319
+ return [side, align];
320
+ }
321
+ var Root2 = Popper;
322
+ var Anchor = PopperAnchor;
323
+ var Content = PopperContent;
324
+ var Arrow = PopperArrow;
325
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/Popper.tsx"],
4
+ "sourcesContent": ["'use client';\nexport {\n createPopperScope,\n //\n Popper,\n PopperAnchor,\n PopperContent,\n PopperArrow,\n //\n Root,\n Anchor,\n Content,\n Arrow,\n //\n SIDE_OPTIONS,\n ALIGN_OPTIONS,\n} from './Popper';\nexport type {\n PopperProps,\n PopperAnchorProps,\n PopperContentProps,\n PopperArrowProps,\n} from './Popper';\n", "import * as React from 'react';\nimport {\n useFloating,\n autoUpdate,\n offset,\n shift,\n limitShift,\n hide,\n arrow as floatingUIarrow,\n flip,\n size,\n} from '@floating-ui/react-dom';\nimport * as ArrowPrimitive from '@huin-core/react-arrow';\nimport { useComposedRefs } from '@huin-core/react-compose-refs';\nimport { createContextScope } from '@huin-core/react-context';\nimport { Primitive } from '@huin-core/react-primitive';\nimport { useCallbackRef } from '@huin-core/react-use-callback-ref';\nimport { useLayoutEffect } from '@huin-core/react-use-layout-effect';\nimport { useSize } from '@huin-core/react-use-size';\n\nimport type { Placement, Middleware } from '@floating-ui/react-dom';\nimport type { Scope } from '@huin-core/react-context';\nimport type { Measurable } from '@huin-core/rect';\n\nconst SIDE_OPTIONS = ['top', 'right', 'bottom', 'left'] as const;\nconst ALIGN_OPTIONS = ['start', 'center', 'end'] as const;\n\ntype Side = (typeof SIDE_OPTIONS)[number];\ntype Align = (typeof ALIGN_OPTIONS)[number];\n\n/* -------------------------------------------------------------------------------------------------\n * Popper\n * -----------------------------------------------------------------------------------------------*/\n\nconst POPPER_NAME = 'Popper';\n\ntype ScopedProps<P> = P & { __scopePopper?: Scope };\nconst [createPopperContext, createPopperScope] = createContextScope(POPPER_NAME);\n\ntype PopperContextValue = {\n anchor: Measurable | null;\n onAnchorChange(anchor: Measurable | null): void;\n};\nconst [PopperProvider, usePopperContext] = createPopperContext<PopperContextValue>(POPPER_NAME);\n\ninterface PopperProps {\n children?: React.ReactNode;\n}\nconst Popper: React.FC<PopperProps> = (props: ScopedProps<PopperProps>) => {\n const { __scopePopper, children } = props;\n const [anchor, setAnchor] = React.useState<Measurable | null>(null);\n return (\n <PopperProvider scope={__scopePopper} anchor={anchor} onAnchorChange={setAnchor}>\n {children}\n </PopperProvider>\n );\n};\n\nPopper.displayName = POPPER_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PopperAnchor\n * -----------------------------------------------------------------------------------------------*/\n\nconst ANCHOR_NAME = 'PopperAnchor';\n\ntype PopperAnchorElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface PopperAnchorProps extends PrimitiveDivProps {\n virtualRef?: React.RefObject<Measurable>;\n}\n\nconst PopperAnchor = React.forwardRef<PopperAnchorElement, PopperAnchorProps>(\n (props: ScopedProps<PopperAnchorProps>, forwardedRef) => {\n const { __scopePopper, virtualRef, ...anchorProps } = props;\n const context = usePopperContext(ANCHOR_NAME, __scopePopper);\n const ref = React.useRef<PopperAnchorElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n\n React.useEffect(() => {\n // Consumer can anchor the popper to something that isn't\n // a DOM node e.g. pointer position, so we override the\n // `anchorRef` with their virtual ref in this case.\n context.onAnchorChange(virtualRef?.current || ref.current);\n });\n\n return virtualRef ? null : <Primitive.div {...anchorProps} ref={composedRefs} />;\n }\n);\n\nPopperAnchor.displayName = ANCHOR_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PopperContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'PopperContent';\n\ntype PopperContentContextValue = {\n placedSide: Side;\n onArrowChange(arrow: HTMLSpanElement | null): void;\n arrowX?: number;\n arrowY?: number;\n shouldHideArrow: boolean;\n};\n\nconst [PopperContentProvider, useContentContext] =\n createPopperContext<PopperContentContextValue>(CONTENT_NAME);\n\ntype Boundary = Element | null;\n\ntype PopperContentElement = React.ElementRef<typeof Primitive.div>;\ninterface PopperContentProps extends PrimitiveDivProps {\n side?: Side;\n sideOffset?: number;\n align?: Align;\n alignOffset?: number;\n arrowPadding?: number;\n avoidCollisions?: boolean;\n collisionBoundary?: Boundary | Boundary[];\n collisionPadding?: number | Partial<Record<Side, number>>;\n sticky?: 'partial' | 'always';\n hideWhenDetached?: boolean;\n updatePositionStrategy?: 'optimized' | 'always';\n onPlaced?: () => void;\n}\n\nconst PopperContent = React.forwardRef<PopperContentElement, PopperContentProps>(\n (props: ScopedProps<PopperContentProps>, forwardedRef) => {\n const {\n __scopePopper,\n side = 'bottom',\n sideOffset = 0,\n align = 'center',\n alignOffset = 0,\n arrowPadding = 0,\n avoidCollisions = true,\n collisionBoundary = [],\n collisionPadding: collisionPaddingProp = 0,\n sticky = 'partial',\n hideWhenDetached = false,\n updatePositionStrategy = 'optimized',\n onPlaced,\n ...contentProps\n } = props;\n\n const context = usePopperContext(CONTENT_NAME, __scopePopper);\n\n const [content, setContent] = React.useState<HTMLDivElement | null>(null);\n const composedRefs = useComposedRefs(forwardedRef, (node) => setContent(node));\n\n const [arrow, setArrow] = React.useState<HTMLSpanElement | null>(null);\n const arrowSize = useSize(arrow);\n const arrowWidth = arrowSize?.width ?? 0;\n const arrowHeight = arrowSize?.height ?? 0;\n\n const desiredPlacement = (side + (align !== 'center' ? '-' + align : '')) as Placement;\n\n const collisionPadding =\n typeof collisionPaddingProp === 'number'\n ? collisionPaddingProp\n : { top: 0, right: 0, bottom: 0, left: 0, ...collisionPaddingProp };\n\n const boundary = Array.isArray(collisionBoundary) ? collisionBoundary : [collisionBoundary];\n const hasExplicitBoundaries = boundary.length > 0;\n\n const detectOverflowOptions = {\n padding: collisionPadding,\n boundary: boundary.filter(isNotNull),\n // with `strategy: 'fixed'`, this is the only way to get it to respect boundaries\n altBoundary: hasExplicitBoundaries,\n };\n\n const { refs, floatingStyles, placement, isPositioned, middlewareData } = useFloating({\n // default to `fixed` strategy so users don't have to pick and we also avoid focus scroll issues\n strategy: 'fixed',\n placement: desiredPlacement,\n whileElementsMounted: (...args) => {\n const cleanup = autoUpdate(...args, {\n animationFrame: updatePositionStrategy === 'always',\n });\n return cleanup;\n },\n elements: {\n reference: context.anchor,\n },\n middleware: [\n offset({ mainAxis: sideOffset + arrowHeight, alignmentAxis: alignOffset }),\n avoidCollisions &&\n shift({\n mainAxis: true,\n crossAxis: false,\n limiter: sticky === 'partial' ? limitShift() : undefined,\n ...detectOverflowOptions,\n }),\n avoidCollisions && flip({ ...detectOverflowOptions }),\n size({\n ...detectOverflowOptions,\n apply: ({ elements, rects, availableWidth, availableHeight }) => {\n const { width: anchorWidth, height: anchorHeight } = rects.reference;\n const contentStyle = elements.floating.style;\n contentStyle.setProperty('--huin-core-popper-available-width', `${availableWidth}px`);\n contentStyle.setProperty('--huin-core-popper-available-height', `${availableHeight}px`);\n contentStyle.setProperty('--huin-core-popper-anchor-width', `${anchorWidth}px`);\n contentStyle.setProperty('--huin-core-popper-anchor-height', `${anchorHeight}px`);\n },\n }),\n arrow && floatingUIarrow({ element: arrow, padding: arrowPadding }),\n transformOrigin({ arrowWidth, arrowHeight }),\n hideWhenDetached && hide({ strategy: 'referenceHidden', ...detectOverflowOptions }),\n ],\n });\n\n const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);\n\n const handlePlaced = useCallbackRef(onPlaced);\n useLayoutEffect(() => {\n if (isPositioned) {\n handlePlaced?.();\n }\n }, [isPositioned, handlePlaced]);\n\n const arrowX = middlewareData.arrow?.x;\n const arrowY = middlewareData.arrow?.y;\n const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;\n\n const [contentZIndex, setContentZIndex] = React.useState<string>();\n useLayoutEffect(() => {\n if (content) setContentZIndex(window.getComputedStyle(content).zIndex);\n }, [content]);\n\n return (\n <div\n ref={refs.setFloating}\n data-huin-core-popper-content-wrapper=\"\"\n style={{\n ...floatingStyles,\n transform: isPositioned ? floatingStyles.transform : 'translate(0, -200%)', // keep off the page when measuring\n minWidth: 'max-content',\n zIndex: contentZIndex,\n ['--huin-core-popper-transform-origin' as any]: [\n middlewareData.transformOrigin?.x,\n middlewareData.transformOrigin?.y,\n ].join(' '),\n\n // hide the content if using the hide middleware and should be hidden\n // set visibility to hidden and disable pointer events so the UI behaves\n // as if the PopperContent isn't there at all\n ...(middlewareData.hide?.referenceHidden && {\n visibility: 'hidden',\n pointerEvents: 'none',\n }),\n }}\n // Floating UI interally calculates logical alignment based the `dir` attribute on\n // the reference/floating node, we must add this attribute here to ensure\n // this is calculated when portalled as well as inline.\n dir={props.dir}\n >\n <PopperContentProvider\n scope={__scopePopper}\n placedSide={placedSide}\n onArrowChange={setArrow}\n arrowX={arrowX}\n arrowY={arrowY}\n shouldHideArrow={cannotCenterArrow}\n >\n <Primitive.div\n data-side={placedSide}\n data-align={placedAlign}\n {...contentProps}\n ref={composedRefs}\n style={{\n ...contentProps.style,\n // if the PopperContent hasn't been placed yet (not all measurements done)\n // we prevent animations so that users's animation don't kick in too early referring wrong sides\n animation: !isPositioned ? 'none' : undefined,\n }}\n />\n </PopperContentProvider>\n </div>\n );\n }\n);\n\nPopperContent.displayName = CONTENT_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PopperArrow\n * -----------------------------------------------------------------------------------------------*/\n\nconst ARROW_NAME = 'PopperArrow';\n\nconst OPPOSITE_SIDE: Record<Side, Side> = {\n top: 'bottom',\n right: 'left',\n bottom: 'top',\n left: 'right',\n};\n\ntype PopperArrowElement = React.ElementRef<typeof ArrowPrimitive.Root>;\ntype ArrowProps = React.ComponentPropsWithoutRef<typeof ArrowPrimitive.Root>;\ninterface PopperArrowProps extends ArrowProps {}\n\nconst PopperArrow = React.forwardRef<PopperArrowElement, PopperArrowProps>(function PopperArrow(\n props: ScopedProps<PopperArrowProps>,\n forwardedRef\n) {\n const { __scopePopper, ...arrowProps } = props;\n const contentContext = useContentContext(ARROW_NAME, __scopePopper);\n const baseSide = OPPOSITE_SIDE[contentContext.placedSide];\n\n return (\n // we have to use an extra wrapper because `ResizeObserver` (used by `useSize`)\n // doesn't report size as we'd expect on SVG elements.\n // it reports their bounding box which is effectively the largest path inside the SVG.\n <span\n ref={contentContext.onArrowChange}\n style={{\n position: 'absolute',\n left: contentContext.arrowX,\n top: contentContext.arrowY,\n [baseSide]: 0,\n transformOrigin: {\n top: '',\n right: '0 0',\n bottom: 'center 0',\n left: '100% 0',\n }[contentContext.placedSide],\n transform: {\n top: 'translateY(100%)',\n right: 'translateY(50%) rotate(90deg) translateX(-50%)',\n bottom: `rotate(180deg)`,\n left: 'translateY(50%) rotate(-90deg) translateX(50%)',\n }[contentContext.placedSide],\n visibility: contentContext.shouldHideArrow ? 'hidden' : undefined,\n }}\n >\n <ArrowPrimitive.Root\n {...arrowProps}\n ref={forwardedRef}\n style={{\n ...arrowProps.style,\n // ensures the element can be measured correctly (mostly for if SVG)\n display: 'block',\n }}\n />\n </span>\n );\n});\n\nPopperArrow.displayName = ARROW_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction isNotNull<T>(value: T | null): value is T {\n return value !== null;\n}\n\nconst transformOrigin = (options: { arrowWidth: number; arrowHeight: number }): Middleware => ({\n name: 'transformOrigin',\n options,\n fn(data) {\n const { placement, rects, middlewareData } = data;\n\n const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;\n const isArrowHidden = cannotCenterArrow;\n const arrowWidth = isArrowHidden ? 0 : options.arrowWidth;\n const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;\n\n const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);\n const noArrowAlign = { start: '0%', center: '50%', end: '100%' }[placedAlign];\n\n const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2;\n const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;\n\n let x = '';\n let y = '';\n\n if (placedSide === 'bottom') {\n x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;\n y = `${-arrowHeight}px`;\n } else if (placedSide === 'top') {\n x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;\n y = `${rects.floating.height + arrowHeight}px`;\n } else if (placedSide === 'right') {\n x = `${-arrowHeight}px`;\n y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;\n } else if (placedSide === 'left') {\n x = `${rects.floating.width + arrowHeight}px`;\n y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;\n }\n return { data: { x, y } };\n },\n});\n\nfunction getSideAndAlignFromPlacement(placement: Placement) {\n const [side, align = 'center'] = placement.split('-');\n return [side as Side, align as Align] as const;\n}\n\nconst Root = Popper;\nconst Anchor = PopperAnchor;\nconst Content = PopperContent;\nconst Arrow = PopperArrow;\n\nexport {\n createPopperScope,\n //\n Popper,\n PopperAnchor,\n PopperContent,\n PopperArrow,\n //\n Root,\n Anchor,\n Content,\n Arrow,\n //\n SIDE_OPTIONS,\n ALIGN_OPTIONS,\n};\nexport type { PopperProps, PopperAnchorProps, PopperContentProps, PopperArrowProps };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;A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AAO,KAAK,KAAK,aAAa;AACnE,UAAM,gBAAgB,eAAe,OAAO,KAAK,KAAK,cAAc;AAEpE,QAAI,IAAI;AACR,QAAI,IAAI;AAER,QAAI,eAAe,UAAU;AAC3B,UAAI,gBAAgB,eAAe,GAAG,YAAY;AAClD,UAAI,GAAG,CAAC,WAAW;AAAA,IACrB,WAAW,eAAe,OAAO;AAC/B,UAAI,gBAAgB,eAAe,GAAG,YAAY;AAClD,UAAI,GAAG,MAAM,SAAS,SAAS,WAAW;AAAA,IAC5C,WAAW,eAAe,SAAS;AACjC,UAAI,GAAG,CAAC,WAAW;AACnB,UAAI,gBAAgB,eAAe,GAAG,YAAY;AAAA,IACpD,WAAW,eAAe,QAAQ;AAChC,UAAI,GAAG,MAAM,SAAS,QAAQ,WAAW;AACzC,UAAI,gBAAgB,eAAe,GAAG,YAAY;AAAA,IACpD;AACA,WAAO,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;AAAA,EAC1B;AACF;AAEA,SAAS,6BAA6B,WAAsB;AAC1D,QAAM,CAAC,MAAM,QAAQ,QAAQ,IAAI,UAAU,MAAM,GAAG;AACpD,SAAO,CAAC,MAAc,KAAc;AACtC;AAEA,IAAMC,QAAO;AACb,IAAM,SAAS;AACf,IAAM,UAAU;AAChB,IAAM,QAAQ;",
6
+ "names": ["Root", "floatingUIarrow", "PopperArrow", "Root"]
7
+ }
package/dist/index.mjs ADDED
@@ -0,0 +1,303 @@
1
+ "use client";
2
+
3
+ // packages/react/popper/src/Popper.tsx
4
+ import * as React from "react";
5
+ import {
6
+ useFloating,
7
+ autoUpdate,
8
+ offset,
9
+ shift,
10
+ limitShift,
11
+ hide,
12
+ arrow as floatingUIarrow,
13
+ flip,
14
+ size
15
+ } from "@floating-ui/react-dom";
16
+ import * as ArrowPrimitive from "@huin-core/react-arrow";
17
+ import { useComposedRefs } from "@huin-core/react-compose-refs";
18
+ import { createContextScope } from "@huin-core/react-context";
19
+ import { Primitive } from "@huin-core/react-primitive";
20
+ import { useCallbackRef } from "@huin-core/react-use-callback-ref";
21
+ import { useLayoutEffect } from "@huin-core/react-use-layout-effect";
22
+ import { useSize } from "@huin-core/react-use-size";
23
+ import { jsx } from "react/jsx-runtime";
24
+ var SIDE_OPTIONS = ["top", "right", "bottom", "left"];
25
+ var ALIGN_OPTIONS = ["start", "center", "end"];
26
+ var POPPER_NAME = "Popper";
27
+ var [createPopperContext, createPopperScope] = createContextScope(POPPER_NAME);
28
+ var [PopperProvider, usePopperContext] = createPopperContext(POPPER_NAME);
29
+ var Popper = (props) => {
30
+ const { __scopePopper, children } = props;
31
+ const [anchor, setAnchor] = React.useState(null);
32
+ return /* @__PURE__ */ jsx(PopperProvider, { scope: __scopePopper, anchor, onAnchorChange: setAnchor, children });
33
+ };
34
+ Popper.displayName = POPPER_NAME;
35
+ var ANCHOR_NAME = "PopperAnchor";
36
+ var PopperAnchor = React.forwardRef(
37
+ (props, forwardedRef) => {
38
+ const { __scopePopper, virtualRef, ...anchorProps } = props;
39
+ const context = usePopperContext(ANCHOR_NAME, __scopePopper);
40
+ const ref = React.useRef(null);
41
+ const composedRefs = useComposedRefs(forwardedRef, ref);
42
+ React.useEffect(() => {
43
+ context.onAnchorChange(virtualRef?.current || ref.current);
44
+ });
45
+ return virtualRef ? null : /* @__PURE__ */ jsx(Primitive.div, { ...anchorProps, ref: composedRefs });
46
+ }
47
+ );
48
+ PopperAnchor.displayName = ANCHOR_NAME;
49
+ var CONTENT_NAME = "PopperContent";
50
+ var [PopperContentProvider, useContentContext] = createPopperContext(CONTENT_NAME);
51
+ var PopperContent = React.forwardRef(
52
+ (props, forwardedRef) => {
53
+ const {
54
+ __scopePopper,
55
+ side = "bottom",
56
+ sideOffset = 0,
57
+ align = "center",
58
+ alignOffset = 0,
59
+ arrowPadding = 0,
60
+ avoidCollisions = true,
61
+ collisionBoundary = [],
62
+ collisionPadding: collisionPaddingProp = 0,
63
+ sticky = "partial",
64
+ hideWhenDetached = false,
65
+ updatePositionStrategy = "optimized",
66
+ onPlaced,
67
+ ...contentProps
68
+ } = props;
69
+ const context = usePopperContext(CONTENT_NAME, __scopePopper);
70
+ const [content, setContent] = React.useState(null);
71
+ const composedRefs = useComposedRefs(forwardedRef, (node) => setContent(node));
72
+ const [arrow, setArrow] = React.useState(null);
73
+ const arrowSize = useSize(arrow);
74
+ const arrowWidth = arrowSize?.width ?? 0;
75
+ const arrowHeight = arrowSize?.height ?? 0;
76
+ const desiredPlacement = side + (align !== "center" ? "-" + align : "");
77
+ const collisionPadding = typeof collisionPaddingProp === "number" ? collisionPaddingProp : { top: 0, right: 0, bottom: 0, left: 0, ...collisionPaddingProp };
78
+ const boundary = Array.isArray(collisionBoundary) ? collisionBoundary : [collisionBoundary];
79
+ const hasExplicitBoundaries = boundary.length > 0;
80
+ const detectOverflowOptions = {
81
+ padding: collisionPadding,
82
+ boundary: boundary.filter(isNotNull),
83
+ // with `strategy: 'fixed'`, this is the only way to get it to respect boundaries
84
+ altBoundary: hasExplicitBoundaries
85
+ };
86
+ const { refs, floatingStyles, placement, isPositioned, middlewareData } = useFloating({
87
+ // default to `fixed` strategy so users don't have to pick and we also avoid focus scroll issues
88
+ strategy: "fixed",
89
+ placement: desiredPlacement,
90
+ whileElementsMounted: (...args) => {
91
+ const cleanup = autoUpdate(...args, {
92
+ animationFrame: updatePositionStrategy === "always"
93
+ });
94
+ return cleanup;
95
+ },
96
+ elements: {
97
+ reference: context.anchor
98
+ },
99
+ middleware: [
100
+ offset({ mainAxis: sideOffset + arrowHeight, alignmentAxis: alignOffset }),
101
+ avoidCollisions && shift({
102
+ mainAxis: true,
103
+ crossAxis: false,
104
+ limiter: sticky === "partial" ? limitShift() : void 0,
105
+ ...detectOverflowOptions
106
+ }),
107
+ avoidCollisions && flip({ ...detectOverflowOptions }),
108
+ size({
109
+ ...detectOverflowOptions,
110
+ apply: ({ elements, rects, availableWidth, availableHeight }) => {
111
+ const { width: anchorWidth, height: anchorHeight } = rects.reference;
112
+ const contentStyle = elements.floating.style;
113
+ contentStyle.setProperty("--huin-core-popper-available-width", `${availableWidth}px`);
114
+ contentStyle.setProperty("--huin-core-popper-available-height", `${availableHeight}px`);
115
+ contentStyle.setProperty("--huin-core-popper-anchor-width", `${anchorWidth}px`);
116
+ contentStyle.setProperty("--huin-core-popper-anchor-height", `${anchorHeight}px`);
117
+ }
118
+ }),
119
+ arrow && floatingUIarrow({ element: arrow, padding: arrowPadding }),
120
+ transformOrigin({ arrowWidth, arrowHeight }),
121
+ hideWhenDetached && hide({ strategy: "referenceHidden", ...detectOverflowOptions })
122
+ ]
123
+ });
124
+ const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
125
+ const handlePlaced = useCallbackRef(onPlaced);
126
+ useLayoutEffect(() => {
127
+ if (isPositioned) {
128
+ handlePlaced?.();
129
+ }
130
+ }, [isPositioned, handlePlaced]);
131
+ const arrowX = middlewareData.arrow?.x;
132
+ const arrowY = middlewareData.arrow?.y;
133
+ const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;
134
+ const [contentZIndex, setContentZIndex] = React.useState();
135
+ useLayoutEffect(() => {
136
+ if (content) setContentZIndex(window.getComputedStyle(content).zIndex);
137
+ }, [content]);
138
+ return /* @__PURE__ */ jsx(
139
+ "div",
140
+ {
141
+ ref: refs.setFloating,
142
+ "data-huin-core-popper-content-wrapper": "",
143
+ style: {
144
+ ...floatingStyles,
145
+ transform: isPositioned ? floatingStyles.transform : "translate(0, -200%)",
146
+ // keep off the page when measuring
147
+ minWidth: "max-content",
148
+ zIndex: contentZIndex,
149
+ ["--huin-core-popper-transform-origin"]: [
150
+ middlewareData.transformOrigin?.x,
151
+ middlewareData.transformOrigin?.y
152
+ ].join(" "),
153
+ // hide the content if using the hide middleware and should be hidden
154
+ // set visibility to hidden and disable pointer events so the UI behaves
155
+ // as if the PopperContent isn't there at all
156
+ ...middlewareData.hide?.referenceHidden && {
157
+ visibility: "hidden",
158
+ pointerEvents: "none"
159
+ }
160
+ },
161
+ dir: props.dir,
162
+ children: /* @__PURE__ */ jsx(
163
+ PopperContentProvider,
164
+ {
165
+ scope: __scopePopper,
166
+ placedSide,
167
+ onArrowChange: setArrow,
168
+ arrowX,
169
+ arrowY,
170
+ shouldHideArrow: cannotCenterArrow,
171
+ children: /* @__PURE__ */ jsx(
172
+ Primitive.div,
173
+ {
174
+ "data-side": placedSide,
175
+ "data-align": placedAlign,
176
+ ...contentProps,
177
+ ref: composedRefs,
178
+ style: {
179
+ ...contentProps.style,
180
+ // if the PopperContent hasn't been placed yet (not all measurements done)
181
+ // we prevent animations so that users's animation don't kick in too early referring wrong sides
182
+ animation: !isPositioned ? "none" : void 0
183
+ }
184
+ }
185
+ )
186
+ }
187
+ )
188
+ }
189
+ );
190
+ }
191
+ );
192
+ PopperContent.displayName = CONTENT_NAME;
193
+ var ARROW_NAME = "PopperArrow";
194
+ var OPPOSITE_SIDE = {
195
+ top: "bottom",
196
+ right: "left",
197
+ bottom: "top",
198
+ left: "right"
199
+ };
200
+ var PopperArrow = React.forwardRef(function PopperArrow2(props, forwardedRef) {
201
+ const { __scopePopper, ...arrowProps } = props;
202
+ const contentContext = useContentContext(ARROW_NAME, __scopePopper);
203
+ const baseSide = OPPOSITE_SIDE[contentContext.placedSide];
204
+ return (
205
+ // we have to use an extra wrapper because `ResizeObserver` (used by `useSize`)
206
+ // doesn't report size as we'd expect on SVG elements.
207
+ // it reports their bounding box which is effectively the largest path inside the SVG.
208
+ /* @__PURE__ */ jsx(
209
+ "span",
210
+ {
211
+ ref: contentContext.onArrowChange,
212
+ style: {
213
+ position: "absolute",
214
+ left: contentContext.arrowX,
215
+ top: contentContext.arrowY,
216
+ [baseSide]: 0,
217
+ transformOrigin: {
218
+ top: "",
219
+ right: "0 0",
220
+ bottom: "center 0",
221
+ left: "100% 0"
222
+ }[contentContext.placedSide],
223
+ transform: {
224
+ top: "translateY(100%)",
225
+ right: "translateY(50%) rotate(90deg) translateX(-50%)",
226
+ bottom: `rotate(180deg)`,
227
+ left: "translateY(50%) rotate(-90deg) translateX(50%)"
228
+ }[contentContext.placedSide],
229
+ visibility: contentContext.shouldHideArrow ? "hidden" : void 0
230
+ },
231
+ children: /* @__PURE__ */ jsx(
232
+ ArrowPrimitive.Root,
233
+ {
234
+ ...arrowProps,
235
+ ref: forwardedRef,
236
+ style: {
237
+ ...arrowProps.style,
238
+ // ensures the element can be measured correctly (mostly for if SVG)
239
+ display: "block"
240
+ }
241
+ }
242
+ )
243
+ }
244
+ )
245
+ );
246
+ });
247
+ PopperArrow.displayName = ARROW_NAME;
248
+ function isNotNull(value) {
249
+ return value !== null;
250
+ }
251
+ var transformOrigin = (options) => ({
252
+ name: "transformOrigin",
253
+ options,
254
+ fn(data) {
255
+ const { placement, rects, middlewareData } = data;
256
+ const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;
257
+ const isArrowHidden = cannotCenterArrow;
258
+ const arrowWidth = isArrowHidden ? 0 : options.arrowWidth;
259
+ const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;
260
+ const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
261
+ const noArrowAlign = { start: "0%", center: "50%", end: "100%" }[placedAlign];
262
+ const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2;
263
+ const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;
264
+ let x = "";
265
+ let y = "";
266
+ if (placedSide === "bottom") {
267
+ x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
268
+ y = `${-arrowHeight}px`;
269
+ } else if (placedSide === "top") {
270
+ x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
271
+ y = `${rects.floating.height + arrowHeight}px`;
272
+ } else if (placedSide === "right") {
273
+ x = `${-arrowHeight}px`;
274
+ y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
275
+ } else if (placedSide === "left") {
276
+ x = `${rects.floating.width + arrowHeight}px`;
277
+ y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
278
+ }
279
+ return { data: { x, y } };
280
+ }
281
+ });
282
+ function getSideAndAlignFromPlacement(placement) {
283
+ const [side, align = "center"] = placement.split("-");
284
+ return [side, align];
285
+ }
286
+ var Root2 = Popper;
287
+ var Anchor = PopperAnchor;
288
+ var Content = PopperContent;
289
+ var Arrow = PopperArrow;
290
+ export {
291
+ ALIGN_OPTIONS,
292
+ Anchor,
293
+ Arrow,
294
+ Content,
295
+ Popper,
296
+ PopperAnchor,
297
+ PopperArrow,
298
+ PopperContent,
299
+ Root2 as Root,
300
+ SIDE_OPTIONS,
301
+ createPopperScope
302
+ };
303
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/Popper.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nimport {\n useFloating,\n autoUpdate,\n offset,\n shift,\n limitShift,\n hide,\n arrow as floatingUIarrow,\n flip,\n size,\n} from '@floating-ui/react-dom';\nimport * as ArrowPrimitive from '@huin-core/react-arrow';\nimport { useComposedRefs } from '@huin-core/react-compose-refs';\nimport { createContextScope } from '@huin-core/react-context';\nimport { Primitive } from '@huin-core/react-primitive';\nimport { useCallbackRef } from '@huin-core/react-use-callback-ref';\nimport { useLayoutEffect } from '@huin-core/react-use-layout-effect';\nimport { useSize } from '@huin-core/react-use-size';\n\nimport type { Placement, Middleware } from '@floating-ui/react-dom';\nimport type { Scope } from '@huin-core/react-context';\nimport type { Measurable } from '@huin-core/rect';\n\nconst SIDE_OPTIONS = ['top', 'right', 'bottom', 'left'] as const;\nconst ALIGN_OPTIONS = ['start', 'center', 'end'] as const;\n\ntype Side = (typeof SIDE_OPTIONS)[number];\ntype Align = (typeof ALIGN_OPTIONS)[number];\n\n/* -------------------------------------------------------------------------------------------------\n * Popper\n * -----------------------------------------------------------------------------------------------*/\n\nconst POPPER_NAME = 'Popper';\n\ntype ScopedProps<P> = P & { __scopePopper?: Scope };\nconst [createPopperContext, createPopperScope] = createContextScope(POPPER_NAME);\n\ntype PopperContextValue = {\n anchor: Measurable | null;\n onAnchorChange(anchor: Measurable | null): void;\n};\nconst [PopperProvider, usePopperContext] = createPopperContext<PopperContextValue>(POPPER_NAME);\n\ninterface PopperProps {\n children?: React.ReactNode;\n}\nconst Popper: React.FC<PopperProps> = (props: ScopedProps<PopperProps>) => {\n const { __scopePopper, children } = props;\n const [anchor, setAnchor] = React.useState<Measurable | null>(null);\n return (\n <PopperProvider scope={__scopePopper} anchor={anchor} onAnchorChange={setAnchor}>\n {children}\n </PopperProvider>\n );\n};\n\nPopper.displayName = POPPER_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PopperAnchor\n * -----------------------------------------------------------------------------------------------*/\n\nconst ANCHOR_NAME = 'PopperAnchor';\n\ntype PopperAnchorElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface PopperAnchorProps extends PrimitiveDivProps {\n virtualRef?: React.RefObject<Measurable>;\n}\n\nconst PopperAnchor = React.forwardRef<PopperAnchorElement, PopperAnchorProps>(\n (props: ScopedProps<PopperAnchorProps>, forwardedRef) => {\n const { __scopePopper, virtualRef, ...anchorProps } = props;\n const context = usePopperContext(ANCHOR_NAME, __scopePopper);\n const ref = React.useRef<PopperAnchorElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n\n React.useEffect(() => {\n // Consumer can anchor the popper to something that isn't\n // a DOM node e.g. pointer position, so we override the\n // `anchorRef` with their virtual ref in this case.\n context.onAnchorChange(virtualRef?.current || ref.current);\n });\n\n return virtualRef ? null : <Primitive.div {...anchorProps} ref={composedRefs} />;\n }\n);\n\nPopperAnchor.displayName = ANCHOR_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PopperContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'PopperContent';\n\ntype PopperContentContextValue = {\n placedSide: Side;\n onArrowChange(arrow: HTMLSpanElement | null): void;\n arrowX?: number;\n arrowY?: number;\n shouldHideArrow: boolean;\n};\n\nconst [PopperContentProvider, useContentContext] =\n createPopperContext<PopperContentContextValue>(CONTENT_NAME);\n\ntype Boundary = Element | null;\n\ntype PopperContentElement = React.ElementRef<typeof Primitive.div>;\ninterface PopperContentProps extends PrimitiveDivProps {\n side?: Side;\n sideOffset?: number;\n align?: Align;\n alignOffset?: number;\n arrowPadding?: number;\n avoidCollisions?: boolean;\n collisionBoundary?: Boundary | Boundary[];\n collisionPadding?: number | Partial<Record<Side, number>>;\n sticky?: 'partial' | 'always';\n hideWhenDetached?: boolean;\n updatePositionStrategy?: 'optimized' | 'always';\n onPlaced?: () => void;\n}\n\nconst PopperContent = React.forwardRef<PopperContentElement, PopperContentProps>(\n (props: ScopedProps<PopperContentProps>, forwardedRef) => {\n const {\n __scopePopper,\n side = 'bottom',\n sideOffset = 0,\n align = 'center',\n alignOffset = 0,\n arrowPadding = 0,\n avoidCollisions = true,\n collisionBoundary = [],\n collisionPadding: collisionPaddingProp = 0,\n sticky = 'partial',\n hideWhenDetached = false,\n updatePositionStrategy = 'optimized',\n onPlaced,\n ...contentProps\n } = props;\n\n const context = usePopperContext(CONTENT_NAME, __scopePopper);\n\n const [content, setContent] = React.useState<HTMLDivElement | null>(null);\n const composedRefs = useComposedRefs(forwardedRef, (node) => setContent(node));\n\n const [arrow, setArrow] = React.useState<HTMLSpanElement | null>(null);\n const arrowSize = useSize(arrow);\n const arrowWidth = arrowSize?.width ?? 0;\n const arrowHeight = arrowSize?.height ?? 0;\n\n const desiredPlacement = (side + (align !== 'center' ? '-' + align : '')) as Placement;\n\n const collisionPadding =\n typeof collisionPaddingProp === 'number'\n ? collisionPaddingProp\n : { top: 0, right: 0, bottom: 0, left: 0, ...collisionPaddingProp };\n\n const boundary = Array.isArray(collisionBoundary) ? collisionBoundary : [collisionBoundary];\n const hasExplicitBoundaries = boundary.length > 0;\n\n const detectOverflowOptions = {\n padding: collisionPadding,\n boundary: boundary.filter(isNotNull),\n // with `strategy: 'fixed'`, this is the only way to get it to respect boundaries\n altBoundary: hasExplicitBoundaries,\n };\n\n const { refs, floatingStyles, placement, isPositioned, middlewareData } = useFloating({\n // default to `fixed` strategy so users don't have to pick and we also avoid focus scroll issues\n strategy: 'fixed',\n placement: desiredPlacement,\n whileElementsMounted: (...args) => {\n const cleanup = autoUpdate(...args, {\n animationFrame: updatePositionStrategy === 'always',\n });\n return cleanup;\n },\n elements: {\n reference: context.anchor,\n },\n middleware: [\n offset({ mainAxis: sideOffset + arrowHeight, alignmentAxis: alignOffset }),\n avoidCollisions &&\n shift({\n mainAxis: true,\n crossAxis: false,\n limiter: sticky === 'partial' ? limitShift() : undefined,\n ...detectOverflowOptions,\n }),\n avoidCollisions && flip({ ...detectOverflowOptions }),\n size({\n ...detectOverflowOptions,\n apply: ({ elements, rects, availableWidth, availableHeight }) => {\n const { width: anchorWidth, height: anchorHeight } = rects.reference;\n const contentStyle = elements.floating.style;\n contentStyle.setProperty('--huin-core-popper-available-width', `${availableWidth}px`);\n contentStyle.setProperty('--huin-core-popper-available-height', `${availableHeight}px`);\n contentStyle.setProperty('--huin-core-popper-anchor-width', `${anchorWidth}px`);\n contentStyle.setProperty('--huin-core-popper-anchor-height', `${anchorHeight}px`);\n },\n }),\n arrow && floatingUIarrow({ element: arrow, padding: arrowPadding }),\n transformOrigin({ arrowWidth, arrowHeight }),\n hideWhenDetached && hide({ strategy: 'referenceHidden', ...detectOverflowOptions }),\n ],\n });\n\n const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);\n\n const handlePlaced = useCallbackRef(onPlaced);\n useLayoutEffect(() => {\n if (isPositioned) {\n handlePlaced?.();\n }\n }, [isPositioned, handlePlaced]);\n\n const arrowX = middlewareData.arrow?.x;\n const arrowY = middlewareData.arrow?.y;\n const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;\n\n const [contentZIndex, setContentZIndex] = React.useState<string>();\n useLayoutEffect(() => {\n if (content) setContentZIndex(window.getComputedStyle(content).zIndex);\n }, [content]);\n\n return (\n <div\n ref={refs.setFloating}\n data-huin-core-popper-content-wrapper=\"\"\n style={{\n ...floatingStyles,\n transform: isPositioned ? floatingStyles.transform : 'translate(0, -200%)', // keep off the page when measuring\n minWidth: 'max-content',\n zIndex: contentZIndex,\n ['--huin-core-popper-transform-origin' as any]: [\n middlewareData.transformOrigin?.x,\n middlewareData.transformOrigin?.y,\n ].join(' '),\n\n // hide the content if using the hide middleware and should be hidden\n // set visibility to hidden and disable pointer events so the UI behaves\n // as if the PopperContent isn't there at all\n ...(middlewareData.hide?.referenceHidden && {\n visibility: 'hidden',\n pointerEvents: 'none',\n }),\n }}\n // Floating UI interally calculates logical alignment based the `dir` attribute on\n // the reference/floating node, we must add this attribute here to ensure\n // this is calculated when portalled as well as inline.\n dir={props.dir}\n >\n <PopperContentProvider\n scope={__scopePopper}\n placedSide={placedSide}\n onArrowChange={setArrow}\n arrowX={arrowX}\n arrowY={arrowY}\n shouldHideArrow={cannotCenterArrow}\n >\n <Primitive.div\n data-side={placedSide}\n data-align={placedAlign}\n {...contentProps}\n ref={composedRefs}\n style={{\n ...contentProps.style,\n // if the PopperContent hasn't been placed yet (not all measurements done)\n // we prevent animations so that users's animation don't kick in too early referring wrong sides\n animation: !isPositioned ? 'none' : undefined,\n }}\n />\n </PopperContentProvider>\n </div>\n );\n }\n);\n\nPopperContent.displayName = CONTENT_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PopperArrow\n * -----------------------------------------------------------------------------------------------*/\n\nconst ARROW_NAME = 'PopperArrow';\n\nconst OPPOSITE_SIDE: Record<Side, Side> = {\n top: 'bottom',\n right: 'left',\n bottom: 'top',\n left: 'right',\n};\n\ntype PopperArrowElement = React.ElementRef<typeof ArrowPrimitive.Root>;\ntype ArrowProps = React.ComponentPropsWithoutRef<typeof ArrowPrimitive.Root>;\ninterface PopperArrowProps extends ArrowProps {}\n\nconst PopperArrow = React.forwardRef<PopperArrowElement, PopperArrowProps>(function PopperArrow(\n props: ScopedProps<PopperArrowProps>,\n forwardedRef\n) {\n const { __scopePopper, ...arrowProps } = props;\n const contentContext = useContentContext(ARROW_NAME, __scopePopper);\n const baseSide = OPPOSITE_SIDE[contentContext.placedSide];\n\n return (\n // we have to use an extra wrapper because `ResizeObserver` (used by `useSize`)\n // doesn't report size as we'd expect on SVG elements.\n // it reports their bounding box which is effectively the largest path inside the SVG.\n <span\n ref={contentContext.onArrowChange}\n style={{\n position: 'absolute',\n left: contentContext.arrowX,\n top: contentContext.arrowY,\n [baseSide]: 0,\n transformOrigin: {\n top: '',\n right: '0 0',\n bottom: 'center 0',\n left: '100% 0',\n }[contentContext.placedSide],\n transform: {\n top: 'translateY(100%)',\n right: 'translateY(50%) rotate(90deg) translateX(-50%)',\n bottom: `rotate(180deg)`,\n left: 'translateY(50%) rotate(-90deg) translateX(50%)',\n }[contentContext.placedSide],\n visibility: contentContext.shouldHideArrow ? 'hidden' : undefined,\n }}\n >\n <ArrowPrimitive.Root\n {...arrowProps}\n ref={forwardedRef}\n style={{\n ...arrowProps.style,\n // ensures the element can be measured correctly (mostly for if SVG)\n display: 'block',\n }}\n />\n </span>\n );\n});\n\nPopperArrow.displayName = ARROW_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction isNotNull<T>(value: T | null): value is T {\n return value !== null;\n}\n\nconst transformOrigin = (options: { arrowWidth: number; arrowHeight: number }): Middleware => ({\n name: 'transformOrigin',\n options,\n fn(data) {\n const { placement, rects, middlewareData } = data;\n\n const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;\n const isArrowHidden = cannotCenterArrow;\n const arrowWidth = isArrowHidden ? 0 : options.arrowWidth;\n const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;\n\n const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);\n const noArrowAlign = { start: '0%', center: '50%', end: '100%' }[placedAlign];\n\n const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2;\n const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;\n\n let x = '';\n let y = '';\n\n if (placedSide === 'bottom') {\n x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;\n y = `${-arrowHeight}px`;\n } else if (placedSide === 'top') {\n x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;\n y = `${rects.floating.height + arrowHeight}px`;\n } else if (placedSide === 'right') {\n x = `${-arrowHeight}px`;\n y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;\n } else if (placedSide === 'left') {\n x = `${rects.floating.width + arrowHeight}px`;\n y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;\n }\n return { data: { x, y } };\n },\n});\n\nfunction getSideAndAlignFromPlacement(placement: Placement) {\n const [side, align = 'center'] = placement.split('-');\n return [side as Side, align as Align] as const;\n}\n\nconst Root = Popper;\nconst Anchor = PopperAnchor;\nconst Content = PopperContent;\nconst Arrow = PopperArrow;\n\nexport {\n createPopperScope,\n //\n Popper,\n PopperAnchor,\n PopperContent,\n PopperArrow,\n //\n Root,\n Anchor,\n Content,\n Arrow,\n //\n SIDE_OPTIONS,\n ALIGN_OPTIONS,\n};\nexport type { PopperProps, PopperAnchorProps, PopperContentProps, PopperArrowProps };\n"],
5
+ "mappings": ";;;AAAA,YAAY,WAAW;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,OACK;AACP,YAAY,oBAAoB;AAChC,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAChC,SAAS,eAAe;AAkCpB;AA5BJ,IAAM,eAAe,CAAC,OAAO,SAAS,UAAU,MAAM;AACtD,IAAM,gBAAgB,CAAC,SAAS,UAAU,KAAK;AAS/C,IAAM,cAAc;AAGpB,IAAM,CAAC,qBAAqB,iBAAiB,IAAI,mBAAmB,WAAW;AAM/E,IAAM,CAAC,gBAAgB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I,GAAG,MAAM,SAAS,QAAQ,WAAW;AACzC,UAAI,gBAAgB,eAAe,GAAG,YAAY;AAAA,IACpD;AACA,WAAO,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;AAAA,EAC1B;AACF;AAEA,SAAS,6BAA6B,WAAsB;AAC1D,QAAM,CAAC,MAAM,QAAQ,QAAQ,IAAI,UAAU,MAAM,GAAG;AACpD,SAAO,CAAC,MAAc,KAAc;AACtC;AAEA,IAAMC,QAAO;AACb,IAAM,SAAS;AACf,IAAM,UAAU;AAChB,IAAM,QAAQ;",
6
+ "names": ["PopperArrow", "Root"]
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huin-core/react-popper",
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": {