@hoosei/voxweave-react
Version:
A customizable and interactive voice UI component for React applications
242 lines (241 loc) • 7.76 kB
JavaScript
import * as c from "react";
import { composeEventHandlers as P } from "./index27.js";
import { useComposedRefs as O } from "./index24.js";
import { createContextScope as L } from "./index28.js";
import { DismissableLayer as G } from "./index31.js";
import { useFocusGuards as H } from "./index36.js";
import { FocusScope as K } from "./index32.js";
import { useId as $ } from "./index29.js";
import { createPopperScope as _, Root as j, Anchor as x, Content as U, Arrow as V } from "./index78.js";
import { Portal as W } from "./index33.js";
import { Presence as w } from "./index34.js";
import { Primitive as E } from "./index35.js";
import { createSlot as Z } from "./index21.js";
import { useControllableState as q } from "./index30.js";
import { hideOthers as z } from "./index38.js";
import B from "./index37.js";
import { jsx as p } from "react/jsx-runtime";
var C = "Popover", [b, _o] = L(C, [
_
]), m = _(), [J, u] = b(C), F = (o) => {
const {
__scopePopover: n,
children: t,
open: a,
defaultOpen: e,
onOpenChange: r,
modal: s = !1
} = o, i = m(n), d = c.useRef(null), [v, g] = c.useState(!1), [h, l] = q({
prop: a,
defaultProp: e ?? !1,
onChange: r,
caller: C
});
return /* @__PURE__ */ p(j, { ...i, children: /* @__PURE__ */ p(
J,
{
scope: n,
contentId: $(),
triggerRef: d,
open: h,
onOpenChange: l,
onOpenToggle: c.useCallback(() => l((R) => !R), [l]),
hasCustomAnchor: v,
onCustomAnchorAdd: c.useCallback(() => g(!0), []),
onCustomAnchorRemove: c.useCallback(() => g(!1), []),
modal: s,
children: t
}
) });
};
F.displayName = C;
var N = "PopoverAnchor", Q = c.forwardRef(
(o, n) => {
const { __scopePopover: t, ...a } = o, e = u(N, t), r = m(t), { onCustomAnchorAdd: s, onCustomAnchorRemove: i } = e;
return c.useEffect(() => (s(), () => i()), [s, i]), /* @__PURE__ */ p(x, { ...r, ...a, ref: n });
}
);
Q.displayName = N;
var S = "PopoverTrigger", y = c.forwardRef(
(o, n) => {
const { __scopePopover: t, ...a } = o, e = u(S, t), r = m(t), s = O(n, e.triggerRef), i = /* @__PURE__ */ p(
E.button,
{
type: "button",
"aria-haspopup": "dialog",
"aria-expanded": e.open,
"aria-controls": e.contentId,
"data-state": T(e.open),
...a,
ref: s,
onClick: P(o.onClick, e.onOpenToggle)
}
);
return e.hasCustomAnchor ? i : /* @__PURE__ */ p(x, { asChild: !0, ...r, children: i });
}
);
y.displayName = S;
var A = "PopoverPortal", [X, Y] = b(A, {
forceMount: void 0
}), D = (o) => {
const { __scopePopover: n, forceMount: t, children: a, container: e } = o, r = u(A, n);
return /* @__PURE__ */ p(X, { scope: n, forceMount: t, children: /* @__PURE__ */ p(w, { present: t || r.open, children: /* @__PURE__ */ p(W, { asChild: !0, container: e, children: a }) }) });
};
D.displayName = A;
var f = "PopoverContent", M = c.forwardRef(
(o, n) => {
const t = Y(f, o.__scopePopover), { forceMount: a = t.forceMount, ...e } = o, r = u(f, o.__scopePopover);
return /* @__PURE__ */ p(w, { present: a || r.open, children: r.modal ? /* @__PURE__ */ p(eo, { ...e, ref: n }) : /* @__PURE__ */ p(ro, { ...e, ref: n }) });
}
);
M.displayName = f;
var oo = Z("PopoverContent.RemoveScroll"), eo = c.forwardRef(
(o, n) => {
const t = u(f, o.__scopePopover), a = c.useRef(null), e = O(n, a), r = c.useRef(!1);
return c.useEffect(() => {
const s = a.current;
if (s) return z(s);
}, []), /* @__PURE__ */ p(B, { as: oo, allowPinchZoom: !0, children: /* @__PURE__ */ p(
k,
{
...o,
ref: e,
trapFocus: t.open,
disableOutsidePointerEvents: !0,
onCloseAutoFocus: P(o.onCloseAutoFocus, (s) => {
s.preventDefault(), r.current || t.triggerRef.current?.focus();
}),
onPointerDownOutside: P(
o.onPointerDownOutside,
(s) => {
const i = s.detail.originalEvent, d = i.button === 0 && i.ctrlKey === !0, v = i.button === 2 || d;
r.current = v;
},
{ checkForDefaultPrevented: !1 }
),
onFocusOutside: P(
o.onFocusOutside,
(s) => s.preventDefault(),
{ checkForDefaultPrevented: !1 }
)
}
) });
}
), ro = c.forwardRef(
(o, n) => {
const t = u(f, o.__scopePopover), a = c.useRef(!1), e = c.useRef(!1);
return /* @__PURE__ */ p(
k,
{
...o,
ref: n,
trapFocus: !1,
disableOutsidePointerEvents: !1,
onCloseAutoFocus: (r) => {
o.onCloseAutoFocus?.(r), r.defaultPrevented || (a.current || t.triggerRef.current?.focus(), r.preventDefault()), a.current = !1, e.current = !1;
},
onInteractOutside: (r) => {
o.onInteractOutside?.(r), r.defaultPrevented || (a.current = !0, r.detail.originalEvent.type === "pointerdown" && (e.current = !0));
const s = r.target;
t.triggerRef.current?.contains(s) && r.preventDefault(), r.detail.originalEvent.type === "focusin" && e.current && r.preventDefault();
}
}
);
}
), k = c.forwardRef(
(o, n) => {
const {
__scopePopover: t,
trapFocus: a,
onOpenAutoFocus: e,
onCloseAutoFocus: r,
disableOutsidePointerEvents: s,
onEscapeKeyDown: i,
onPointerDownOutside: d,
onFocusOutside: v,
onInteractOutside: g,
...h
} = o, l = u(f, t), R = m(t);
return H(), /* @__PURE__ */ p(
K,
{
asChild: !0,
loop: !0,
trapped: a,
onMountAutoFocus: e,
onUnmountAutoFocus: r,
children: /* @__PURE__ */ p(
G,
{
asChild: !0,
disableOutsidePointerEvents: s,
onInteractOutside: g,
onEscapeKeyDown: i,
onPointerDownOutside: d,
onFocusOutside: v,
onDismiss: () => l.onOpenChange(!1),
children: /* @__PURE__ */ p(
U,
{
"data-state": T(l.open),
role: "dialog",
id: l.contentId,
...R,
...h,
ref: n,
style: {
...h.style,
"--radix-popover-content-transform-origin": "var(--radix-popper-transform-origin)",
"--radix-popover-content-available-width": "var(--radix-popper-available-width)",
"--radix-popover-content-available-height": "var(--radix-popper-available-height)",
"--radix-popover-trigger-width": "var(--radix-popper-anchor-width)",
"--radix-popover-trigger-height": "var(--radix-popper-anchor-height)"
}
}
)
}
)
}
);
}
), I = "PopoverClose", to = c.forwardRef(
(o, n) => {
const { __scopePopover: t, ...a } = o, e = u(I, t);
return /* @__PURE__ */ p(
E.button,
{
type: "button",
...a,
ref: n,
onClick: P(o.onClick, () => e.onOpenChange(!1))
}
);
}
);
to.displayName = I;
var no = "PopoverArrow", ao = c.forwardRef(
(o, n) => {
const { __scopePopover: t, ...a } = o, e = m(t);
return /* @__PURE__ */ p(V, { ...e, ...a, ref: n });
}
);
ao.displayName = no;
function T(o) {
return o ? "open" : "closed";
}
var xo = F, wo = y, Eo = D, bo = M;
export {
bo as Content,
F as Popover,
Q as PopoverAnchor,
ao as PopoverArrow,
to as PopoverClose,
M as PopoverContent,
D as PopoverPortal,
y as PopoverTrigger,
Eo as Portal,
xo as Root,
wo as Trigger,
_o as createPopoverScope
};
//# sourceMappingURL=index86.js.map