@iris-ui-kit/react 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin.cjs +10 -3
- package/dist/admin.cjs.map +1 -1
- package/dist/admin.js +2 -2
- package/dist/behaviors.cjs +45 -0
- package/dist/behaviors.cjs.map +1 -1
- package/dist/behaviors.d.cts +38 -1
- package/dist/behaviors.d.ts +38 -1
- package/dist/behaviors.js +1 -1
- package/dist/{chunk-AE2TTLTK.js → chunk-6S6MZC5G.js} +11 -4
- package/dist/chunk-6S6MZC5G.js.map +1 -0
- package/dist/{chunk-OD2O3BPM.js → chunk-KRFZ5KL4.js} +4 -4
- package/dist/chunk-KRFZ5KL4.js.map +1 -0
- package/dist/{chunk-53KFLVIZ.js → chunk-QZJXMCRR.js} +3 -2
- package/dist/chunk-QZJXMCRR.js.map +1 -0
- package/dist/{chunk-APA5KNCK.js → chunk-ZE4GH2GV.js} +49 -5
- package/dist/chunk-ZE4GH2GV.js.map +1 -0
- package/dist/data.cjs +1 -0
- package/dist/data.cjs.map +1 -1
- package/dist/data.d.cts +4 -2
- package/dist/data.d.ts +4 -2
- package/dist/data.js +1 -1
- package/dist/floating.cjs +9 -2
- package/dist/floating.cjs.map +1 -1
- package/dist/floating.js +1 -1
- package/dist/index.cjs +3537 -1802
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +494 -22
- package/dist/index.d.ts +494 -22
- package/dist/index.js +3279 -1597
- package/dist/index.js.map +1 -1
- package/package.json +15 -15
- package/dist/chunk-53KFLVIZ.js.map +0 -1
- package/dist/chunk-AE2TTLTK.js.map +0 -1
- package/dist/chunk-APA5KNCK.js.map +0 -1
- package/dist/chunk-OD2O3BPM.js.map +0 -1
package/dist/floating.cjs
CHANGED
|
@@ -42,6 +42,7 @@ function useFloating(options) {
|
|
|
42
42
|
const [x, setX] = React__namespace.useState(0);
|
|
43
43
|
const [y, setY] = React__namespace.useState(0);
|
|
44
44
|
const [finalPlacement, setFinalPlacement] = React__namespace.useState(placement);
|
|
45
|
+
const [positioned, setPositioned] = React__namespace.useState(false);
|
|
45
46
|
const [arrowX, setArrowX] = React__namespace.useState();
|
|
46
47
|
const [arrowY, setArrowY] = React__namespace.useState();
|
|
47
48
|
const middleware = React__namespace.useMemo(() => {
|
|
@@ -83,6 +84,7 @@ function useFloating(options) {
|
|
|
83
84
|
if (token !== epochRef.current) return;
|
|
84
85
|
setX(result.x);
|
|
85
86
|
setY(result.y);
|
|
87
|
+
setPositioned(true);
|
|
86
88
|
setFinalPlacement(result.placement);
|
|
87
89
|
const arrowData = result.middlewareData.arrow;
|
|
88
90
|
setArrowX(arrowData?.x);
|
|
@@ -93,6 +95,7 @@ function useFloating(options) {
|
|
|
93
95
|
const a = anchor.current;
|
|
94
96
|
const f = floating.current;
|
|
95
97
|
if (!a || !f) return;
|
|
98
|
+
setPositioned(false);
|
|
96
99
|
const cleanup = dom.autoUpdate(a, f, () => {
|
|
97
100
|
void update();
|
|
98
101
|
});
|
|
@@ -107,9 +110,13 @@ function useFloating(options) {
|
|
|
107
110
|
top: 0,
|
|
108
111
|
left: 0,
|
|
109
112
|
transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,
|
|
110
|
-
width: "max-content"
|
|
113
|
+
width: "max-content",
|
|
114
|
+
// Hidden until the first positioning cycle lands — prevents a flash at
|
|
115
|
+
// the viewport origin. `visibility` (not `display:none`) keeps the panel
|
|
116
|
+
// measurable so Floating UI can compute its real coordinates.
|
|
117
|
+
visibility: positioned ? void 0 : "hidden"
|
|
111
118
|
}),
|
|
112
|
-
[strategy, x, y]
|
|
119
|
+
[strategy, x, y, positioned]
|
|
113
120
|
);
|
|
114
121
|
const OPPOSITE = {
|
|
115
122
|
top: "bottom",
|
package/dist/floating.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/floating/useFloating.ts","../src/floating/useDismiss.ts"],"names":["React","offsetMiddleware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CAAC,MAAA,KAAwC;AAC1D,MAAA,IAAI,CAAC,MAAA,IAAU,EAAE,MAAA,YAAkB,OAAO,OAAO,KAAA;AACjD,MAAA,KAAA,MAAW,CAAA,IAAK,WAAW,OAAA,EAAS;AAClC,QAAA,MAAM,KAAK,CAAA,CAAE,OAAA;AACb,QAAA,IAAI,OAAO,EAAA,KAAO,MAAA,IAAU,GAAG,QAAA,CAAS,MAAM,IAAI,OAAO,IAAA;AAAA,MAC3D;AACA,MAAA,OAAO,KAAA;AAAA,IACT,CAAA;AAEA,IAAA,MAAM,aAAA,GAAgB,CAAC,KAAA,KAAwB;AAC7C,MAAA,IAAI,UAAA,CAAW,KAAA,CAAM,MAAM,CAAA,EAAG;AAC9B,MAAA,YAAA,CAAa,OAAA,EAAQ;AAAA,IACvB,CAAA;AACA,IAAA,MAAM,SAAA,GAAY,CAAC,KAAA,KAAyB;AAC1C,MAAA,IAAI,KAAA,CAAM,QAAQ,QAAA,EAAU;AAC1B,QAAA,KAAA,CAAM,eAAA,EAAgB;AACtB,QAAA,YAAA,CAAa,OAAA,EAAQ;AAAA,MACvB;AAAA,IACF,CAAA;AAEA,IAAA,IAAI,kBAAA,EAAoB,QAAA,CAAS,gBAAA,CAAiB,aAAA,EAAe,eAAe,IAAI,CAAA;AACpF,IAAA,IAAI,MAAA,EAAQ,QAAA,CAAS,gBAAA,CAAiB,SAAA,EAAW,SAAS,CAAA;AAC1D,IAAA,OAAO,MAAM;AACX,MAAA,QAAA,CAAS,mBAAA,CAAoB,aAAA,EAAe,aAAA,EAAe,IAAI,CAAA;AAC/D,MAAA,QAAA,CAAS,mBAAA,CAAoB,WAAW,SAAS,CAAA;AAAA,IACnD,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,OAAA,EAAS,MAAA,EAAQ,kBAAkB,CAAC,CAAA;AAC1C","file":"floating.cjs","sourcesContent":["import * as React from 'react'\nimport {\n autoUpdate,\n computePosition,\n arrow as arrowMiddleware,\n flip as flipMiddleware,\n offset as offsetMiddleware,\n shift as shiftMiddleware,\n size as sizeMiddleware,\n type Middleware,\n type Placement,\n type Strategy,\n} from '@floating-ui/dom'\n\nexport interface UseFloatingOptions {\n /** Element the floating panel is positioned relative to. */\n anchor: React.RefObject<HTMLElement | null>\n /** The floating element itself. */\n floating: React.RefObject<HTMLElement | null>\n /** Whether the floating element is visible. Controls `autoUpdate` lifecycle. */\n open: boolean\n /** Default placement. Floating UI may flip it if `flip` is true. */\n placement?: Placement\n /** CSS position strategy. */\n strategy?: Strategy\n /** Pixel offset between anchor and floating element. */\n offset?: number\n /** Flip to the opposite side when the requested side overflows. Default `true`. */\n flip?: boolean\n /** Shift along the cross-axis to stay in view. Default `true`. */\n shift?: boolean\n /**\n * Constrain the floating element to the available viewport space — sets\n * `maxWidth`/`maxHeight` (minus 8px padding) on it so a long dropdown/popover\n * never overflows the screen (pair with `overflow:auto` for scroll). Off by\n * default. Pass a number to override the viewport padding.\n */\n size?: boolean | number\n /** Extra Floating UI middleware to append. */\n middleware?: Middleware[]\n /**\n * Optional ref to an arrow element inside the floating panel. When provided,\n * `arrowX`, `arrowY`, and `arrowSide` in the return value are populated by the\n * `@floating-ui/dom` arrow middleware so you can position the caret CSS.\n */\n arrow?: React.RefObject<HTMLElement | null>\n}\n\nexport interface UseFloatingReturn {\n x: number\n y: number\n strategy: Strategy\n finalPlacement: Placement\n /** Ready-to-bind inline style object for the floating element. */\n floatingStyles: React.CSSProperties\n /** Trigger a manual recompute. Usually not needed — `autoUpdate` handles scroll/resize. */\n update: () => Promise<void>\n /** Arrow x offset (px from floating start edge). Present when `arrow` option is set. */\n arrowX: number | undefined\n /** Arrow y offset (px from floating start edge). Present when `arrow` option is set. */\n arrowY: number | undefined\n /**\n * The side of the floating element the arrow is on — use as the CSS property\n * to apply `bottom: 0` / `top: 0` etc. to the arrow element.\n * E.g. `'bottom'` placement → arrow is on `'top'` of the floating element.\n */\n arrowSide: 'top' | 'right' | 'bottom' | 'left' | undefined\n}\n\n/**\n * Reactive Floating UI integration for React. Subscribes `autoUpdate`\n * whenever `open === true` and both refs are populated; tears it down on\n * close, unmount, or ref clearing.\n *\n * Pure positioning — does NOT render anything, does NOT manage focus,\n * does NOT handle dismiss behavior. Those concerns live in the consuming\n * primitive (Popover, Tooltip, Dialog, Menu, …).\n */\nexport function useFloating(options: UseFloatingOptions): UseFloatingReturn {\n const {\n anchor,\n floating,\n open,\n placement = 'bottom',\n strategy = 'absolute',\n offset,\n flip = true,\n shift = true,\n size = false,\n middleware: extraMiddleware,\n arrow,\n } = options\n\n const [x, setX] = React.useState(0)\n const [y, setY] = React.useState(0)\n const [finalPlacement, setFinalPlacement] = React.useState<Placement>(placement)\n const [arrowX, setArrowX] = React.useState<number | undefined>()\n const [arrowY, setArrowY] = React.useState<number | undefined>()\n\n const middleware = React.useMemo<Middleware[]>(() => {\n const mw: Middleware[] = []\n if (offset !== undefined) mw.push(offsetMiddleware(offset))\n if (flip) mw.push(flipMiddleware())\n if (shift) mw.push(shiftMiddleware({ padding: 8 }))\n if (size) {\n const padding = typeof size === 'number' ? size : 8\n mw.push(\n sizeMiddleware({\n padding,\n apply({ availableWidth, availableHeight, elements }) {\n Object.assign(elements.floating.style, {\n maxWidth: `${Math.max(0, Math.floor(availableWidth))}px`,\n maxHeight: `${Math.max(0, Math.floor(availableHeight))}px`,\n })\n },\n }),\n )\n }\n if (arrow?.current) mw.push(arrowMiddleware({ element: arrow.current }))\n if (extraMiddleware) mw.push(...extraMiddleware)\n return mw\n }, [offset, flip, shift, size, extraMiddleware, arrow])\n\n // Hold the latest middleware in a ref so `update` always sees current value\n // without being re-created (which would churn the autoUpdate subscription).\n const middlewareRef = React.useRef(middleware)\n middlewareRef.current = middleware\n\n // Monotonic token bumped on every new positioning cycle and on teardown.\n // `computePosition` is async; without this guard a result that resolves\n // after the panel closed/unmounted (or after a newer update started) would\n // apply stale coordinates and call setState on an unmounted component.\n const epochRef = React.useRef(0)\n\n const update = React.useCallback(async () => {\n const a = anchor.current\n const f = floating.current\n if (!a || !f) return\n const token = ++epochRef.current\n const result = await computePosition(a, f, {\n placement,\n strategy,\n middleware: middlewareRef.current,\n })\n // A newer update() started, or the effect tore down, while awaiting — drop.\n if (token !== epochRef.current) return\n setX(result.x)\n setY(result.y)\n setFinalPlacement(result.placement)\n const arrowData = result.middlewareData.arrow as { x?: number; y?: number } | undefined\n setArrowX(arrowData?.x)\n setArrowY(arrowData?.y)\n }, [anchor, floating, placement, strategy])\n\n React.useEffect(() => {\n if (!open) return\n const a = anchor.current\n const f = floating.current\n if (!a || !f) return\n const cleanup = autoUpdate(a, f, () => {\n void update()\n })\n return () => {\n // Invalidate any in-flight update() so its late result never lands.\n epochRef.current++\n cleanup()\n }\n }, [open, anchor, floating, update])\n\n const floatingStyles = React.useMemo<React.CSSProperties>(\n () => ({\n position: strategy,\n top: 0,\n left: 0,\n transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,\n width: 'max-content',\n }),\n [strategy, x, y],\n )\n\n const OPPOSITE: Record<string, 'top' | 'right' | 'bottom' | 'left'> = {\n top: 'bottom',\n bottom: 'top',\n left: 'right',\n right: 'left',\n }\n const arrowSide = OPPOSITE[finalPlacement.split('-')[0]] as\n 'top' | 'right' | 'bottom' | 'left' | undefined\n\n return { x, y, strategy, finalPlacement, floatingStyles, update, arrowX, arrowY, arrowSide }\n}\n","import * as React from 'react'\n\nexport interface UseDismissOptions {\n /** While true, the dismiss listeners are active. */\n enabled: boolean\n /** Elements that, if clicked, should NOT trigger dismiss (typically trigger + content). */\n exclude: Array<React.RefObject<HTMLElement | null>>\n /** Called when the user attempts to dismiss the surface. */\n onDismiss: () => void\n /** Close on Escape key. Default `true`. */\n escape?: boolean\n /** Close on pointerdown outside the excluded elements. Default `true`. */\n outsidePointerDown?: boolean\n}\n\n/**\n * Listen for the universal \"dismiss\" gestures: Escape key and outside\n * pointer-down. Used by Popover / Menu / Dropdown. Tooltip does NOT use this —\n * it dismisses on mouseleave/blur instead.\n *\n * Listeners attach to `document` (pointerdown in the capture phase, mirroring\n * the Vue adapter) only while `enabled` is true, and detach on disable /\n * unmount. SSR-safe (no-op without `document`). The latest `onDismiss` /\n * `exclude` are read through refs so toggling them never re-subscribes.\n */\nexport function useDismiss(options: UseDismissOptions): void {\n const { enabled, escape = true, outsidePointerDown = true } = options\n\n const onDismissRef = React.useRef(options.onDismiss)\n const excludeRef = React.useRef(options.exclude)\n React.useEffect(() => {\n onDismissRef.current = options.onDismiss\n excludeRef.current = options.exclude\n })\n\n React.useEffect(() => {\n if (!enabled || typeof document === 'undefined') return\n\n const isExcluded = (target: EventTarget | null): boolean => {\n if (!target || !(target instanceof Node)) return false\n for (const r of excludeRef.current) {\n const el = r.current\n if (el && (el === target || el.contains(target))) return true\n }\n return false\n }\n\n const onPointerDown = (event: PointerEvent) => {\n if (isExcluded(event.target)) return\n onDismissRef.current()\n }\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n event.stopPropagation()\n onDismissRef.current()\n }\n }\n\n if (outsidePointerDown) document.addEventListener('pointerdown', onPointerDown, true)\n if (escape) document.addEventListener('keydown', onKeyDown)\n return () => {\n document.removeEventListener('pointerdown', onPointerDown, true)\n document.removeEventListener('keydown', onKeyDown)\n }\n }, [enabled, escape, outsidePointerDown])\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/floating/useFloating.ts","../src/floating/useDismiss.ts"],"names":["React","offsetMiddleware","flipMiddleware","shiftMiddleware","sizeMiddleware","arrowMiddleware","computePosition","autoUpdate","React2"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8EO,SAAS,YAAY,OAAA,EAAgD;AAC1E,EAAA,MAAM;AAAA,IACJ,MAAA;AAAA,IACA,QAAA;AAAA,IACA,IAAA;AAAA,IACA,SAAA,GAAY,QAAA;AAAA,IACZ,QAAA,GAAW,UAAA;AAAA,IACX,MAAA;AAAA,IACA,IAAA,GAAO,IAAA;AAAA,IACP,KAAA,GAAQ,IAAA;AAAA,IACR,IAAA,G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WAAW,OAAA,EAAS;AAClC,QAAA,MAAM,KAAK,CAAA,CAAE,OAAA;AACb,QAAA,IAAI,OAAO,EAAA,KAAO,MAAA,IAAU,GAAG,QAAA,CAAS,MAAM,IAAI,OAAO,IAAA;AAAA,MAC3D;AACA,MAAA,OAAO,KAAA;AAAA,IACT,CAAA;AAEA,IAAA,MAAM,aAAA,GAAgB,CAAC,KAAA,KAAwB;AAC7C,MAAA,IAAI,UAAA,CAAW,KAAA,CAAM,MAAM,CAAA,EAAG;AAC9B,MAAA,YAAA,CAAa,OAAA,EAAQ;AAAA,IACvB,CAAA;AACA,IAAA,MAAM,SAAA,GAAY,CAAC,KAAA,KAAyB;AAC1C,MAAA,IAAI,KAAA,CAAM,QAAQ,QAAA,EAAU;AAC1B,QAAA,KAAA,CAAM,eAAA,EAAgB;AACtB,QAAA,YAAA,CAAa,OAAA,EAAQ;AAAA,MACvB;AAAA,IACF,CAAA;AAEA,IAAA,IAAI,kBAAA,EAAoB,QAAA,CAAS,gBAAA,CAAiB,aAAA,EAAe,eAAe,IAAI,CAAA;AACpF,IAAA,IAAI,MAAA,EAAQ,QAAA,CAAS,gBAAA,CAAiB,SAAA,EAAW,SAAS,CAAA;AAC1D,IAAA,OAAO,MAAM;AACX,MAAA,QAAA,CAAS,mBAAA,CAAoB,aAAA,EAAe,aAAA,EAAe,IAAI,CAAA;AAC/D,MAAA,QAAA,CAAS,mBAAA,CAAoB,WAAW,SAAS,CAAA;AAAA,IACnD,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,OAAA,EAAS,MAAA,EAAQ,kBAAkB,CAAC,CAAA;AAC1C","file":"floating.cjs","sourcesContent":["import * as React from 'react'\nimport {\n autoUpdate,\n computePosition,\n arrow as arrowMiddleware,\n flip as flipMiddleware,\n offset as offsetMiddleware,\n shift as shiftMiddleware,\n size as sizeMiddleware,\n type Middleware,\n type Placement,\n type Strategy,\n} from '@floating-ui/dom'\n\nexport interface UseFloatingOptions {\n /** Element the floating panel is positioned relative to. */\n anchor: React.RefObject<HTMLElement | null>\n /** The floating element itself. */\n floating: React.RefObject<HTMLElement | null>\n /** Whether the floating element is visible. Controls `autoUpdate` lifecycle. */\n open: boolean\n /** Default placement. Floating UI may flip it if `flip` is true. */\n placement?: Placement\n /** CSS position strategy. */\n strategy?: Strategy\n /** Pixel offset between anchor and floating element. */\n offset?: number\n /** Flip to the opposite side when the requested side overflows. Default `true`. */\n flip?: boolean\n /** Shift along the cross-axis to stay in view. Default `true`. */\n shift?: boolean\n /**\n * Constrain the floating element to the available viewport space — sets\n * `maxWidth`/`maxHeight` (minus 8px padding) on it so a long dropdown/popover\n * never overflows the screen (pair with `overflow:auto` for scroll). Off by\n * default. Pass a number to override the viewport padding.\n */\n size?: boolean | number\n /** Extra Floating UI middleware to append. */\n middleware?: Middleware[]\n /**\n * Optional ref to an arrow element inside the floating panel. When provided,\n * `arrowX`, `arrowY`, and `arrowSide` in the return value are populated by the\n * `@floating-ui/dom` arrow middleware so you can position the caret CSS.\n */\n arrow?: React.RefObject<HTMLElement | null>\n}\n\nexport interface UseFloatingReturn {\n x: number\n y: number\n strategy: Strategy\n finalPlacement: Placement\n /** Ready-to-bind inline style object for the floating element. */\n floatingStyles: React.CSSProperties\n /** Trigger a manual recompute. Usually not needed — `autoUpdate` handles scroll/resize. */\n update: () => Promise<void>\n /** Arrow x offset (px from floating start edge). Present when `arrow` option is set. */\n arrowX: number | undefined\n /** Arrow y offset (px from floating start edge). Present when `arrow` option is set. */\n arrowY: number | undefined\n /**\n * The side of the floating element the arrow is on — use as the CSS property\n * to apply `bottom: 0` / `top: 0` etc. to the arrow element.\n * E.g. `'bottom'` placement → arrow is on `'top'` of the floating element.\n */\n arrowSide: 'top' | 'right' | 'bottom' | 'left' | undefined\n}\n\n/**\n * Reactive Floating UI integration for React. Subscribes `autoUpdate`\n * whenever `open === true` and both refs are populated; tears it down on\n * close, unmount, or ref clearing.\n *\n * Pure positioning — does NOT render anything, does NOT manage focus,\n * does NOT handle dismiss behavior. Those concerns live in the consuming\n * primitive (Popover, Tooltip, Dialog, Menu, …).\n */\nexport function useFloating(options: UseFloatingOptions): UseFloatingReturn {\n const {\n anchor,\n floating,\n open,\n placement = 'bottom',\n strategy = 'absolute',\n offset,\n flip = true,\n shift = true,\n size = false,\n middleware: extraMiddleware,\n arrow,\n } = options\n\n const [x, setX] = React.useState(0)\n const [y, setY] = React.useState(0)\n const [finalPlacement, setFinalPlacement] = React.useState<Placement>(placement)\n // True once the first positioning cycle lands. Until then the panel stays\n // `visibility: hidden` so it never flashes at the viewport origin (0,0)\n // before its real coordinates arrive.\n const [positioned, setPositioned] = React.useState(false)\n const [arrowX, setArrowX] = React.useState<number | undefined>()\n const [arrowY, setArrowY] = React.useState<number | undefined>()\n\n const middleware = React.useMemo<Middleware[]>(() => {\n const mw: Middleware[] = []\n if (offset !== undefined) mw.push(offsetMiddleware(offset))\n if (flip) mw.push(flipMiddleware())\n if (shift) mw.push(shiftMiddleware({ padding: 8 }))\n if (size) {\n const padding = typeof size === 'number' ? size : 8\n mw.push(\n sizeMiddleware({\n padding,\n apply({ availableWidth, availableHeight, elements }) {\n Object.assign(elements.floating.style, {\n maxWidth: `${Math.max(0, Math.floor(availableWidth))}px`,\n maxHeight: `${Math.max(0, Math.floor(availableHeight))}px`,\n })\n },\n }),\n )\n }\n if (arrow?.current) mw.push(arrowMiddleware({ element: arrow.current }))\n if (extraMiddleware) mw.push(...extraMiddleware)\n return mw\n }, [offset, flip, shift, size, extraMiddleware, arrow])\n\n // Hold the latest middleware in a ref so `update` always sees current value\n // without being re-created (which would churn the autoUpdate subscription).\n const middlewareRef = React.useRef(middleware)\n middlewareRef.current = middleware\n\n // Monotonic token bumped on every new positioning cycle and on teardown.\n // `computePosition` is async; without this guard a result that resolves\n // after the panel closed/unmounted (or after a newer update started) would\n // apply stale coordinates and call setState on an unmounted component.\n const epochRef = React.useRef(0)\n\n const update = React.useCallback(async () => {\n const a = anchor.current\n const f = floating.current\n if (!a || !f) return\n const token = ++epochRef.current\n const result = await computePosition(a, f, {\n placement,\n strategy,\n middleware: middlewareRef.current,\n })\n // A newer update() started, or the effect tore down, while awaiting — drop.\n if (token !== epochRef.current) return\n setX(result.x)\n setY(result.y)\n setPositioned(true)\n setFinalPlacement(result.placement)\n const arrowData = result.middlewareData.arrow as { x?: number; y?: number } | undefined\n setArrowX(arrowData?.x)\n setArrowY(arrowData?.y)\n }, [anchor, floating, placement, strategy])\n\n React.useEffect(() => {\n if (!open) return\n const a = anchor.current\n const f = floating.current\n if (!a || !f) return\n // Fresh open → hide until the first computePosition cycle completes.\n setPositioned(false)\n const cleanup = autoUpdate(a, f, () => {\n void update()\n })\n return () => {\n // Invalidate any in-flight update() so its late result never lands.\n epochRef.current++\n cleanup()\n }\n }, [open, anchor, floating, update])\n\n const floatingStyles = React.useMemo<React.CSSProperties>(\n () => ({\n position: strategy,\n top: 0,\n left: 0,\n transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,\n width: 'max-content',\n // Hidden until the first positioning cycle lands — prevents a flash at\n // the viewport origin. `visibility` (not `display:none`) keeps the panel\n // measurable so Floating UI can compute its real coordinates.\n visibility: positioned ? undefined : 'hidden',\n }),\n [strategy, x, y, positioned],\n )\n\n const OPPOSITE: Record<string, 'top' | 'right' | 'bottom' | 'left'> = {\n top: 'bottom',\n bottom: 'top',\n left: 'right',\n right: 'left',\n }\n const arrowSide = OPPOSITE[finalPlacement.split('-')[0]] as\n 'top' | 'right' | 'bottom' | 'left' | undefined\n\n return { x, y, strategy, finalPlacement, floatingStyles, update, arrowX, arrowY, arrowSide }\n}\n","import * as React from 'react'\n\nexport interface UseDismissOptions {\n /** While true, the dismiss listeners are active. */\n enabled: boolean\n /** Elements that, if clicked, should NOT trigger dismiss (typically trigger + content). */\n exclude: Array<React.RefObject<HTMLElement | null>>\n /** Called when the user attempts to dismiss the surface. */\n onDismiss: () => void\n /** Close on Escape key. Default `true`. */\n escape?: boolean\n /** Close on pointerdown outside the excluded elements. Default `true`. */\n outsidePointerDown?: boolean\n}\n\n/**\n * Listen for the universal \"dismiss\" gestures: Escape key and outside\n * pointer-down. Used by Popover / Menu / Dropdown. Tooltip does NOT use this —\n * it dismisses on mouseleave/blur instead.\n *\n * Listeners attach to `document` (pointerdown in the capture phase, mirroring\n * the Vue adapter) only while `enabled` is true, and detach on disable /\n * unmount. SSR-safe (no-op without `document`). The latest `onDismiss` /\n * `exclude` are read through refs so toggling them never re-subscribes.\n */\nexport function useDismiss(options: UseDismissOptions): void {\n const { enabled, escape = true, outsidePointerDown = true } = options\n\n const onDismissRef = React.useRef(options.onDismiss)\n const excludeRef = React.useRef(options.exclude)\n React.useEffect(() => {\n onDismissRef.current = options.onDismiss\n excludeRef.current = options.exclude\n })\n\n React.useEffect(() => {\n if (!enabled || typeof document === 'undefined') return\n\n const isExcluded = (target: EventTarget | null): boolean => {\n if (!target || !(target instanceof Node)) return false\n for (const r of excludeRef.current) {\n const el = r.current\n if (el && (el === target || el.contains(target))) return true\n }\n return false\n }\n\n const onPointerDown = (event: PointerEvent) => {\n if (isExcluded(event.target)) return\n onDismissRef.current()\n }\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n event.stopPropagation()\n onDismissRef.current()\n }\n }\n\n if (outsidePointerDown) document.addEventListener('pointerdown', onPointerDown, true)\n if (escape) document.addEventListener('keydown', onKeyDown)\n return () => {\n document.removeEventListener('pointerdown', onPointerDown, true)\n document.removeEventListener('keydown', onKeyDown)\n }\n }, [enabled, escape, outsidePointerDown])\n}\n"]}
|
package/dist/floating.js
CHANGED