@inkeep/cxkit-primitives 0.5.48 → 0.5.50

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.
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),k=require("react"),f=require("@radix-ui/primitive"),O=require("@radix-ui/react-compose-refs"),L=require("@radix-ui/react-context"),m=require("@radix-ui/react-id"),H=require("@radix-ui/react-use-controllable-state"),G=require("@radix-ui/react-dismissable-layer"),U=require("@radix-ui/react-focus-scope");require("@radix-ui/react-portal");const I=require("@radix-ui/react-presence"),g=require("@radix-ui/react-primitive"),z=require("@radix-ui/react-focus-guards"),K=require("react-remove-scroll"),V=require("aria-hidden"),Y=require("@radix-ui/react-slot");function Z(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(s,o,r.get?r:{enumerable:!0,get:()=>e[o]})}}return s.default=e,Object.freeze(s)}const i=Z(k),P="Dialog",[j,B]=L.createContextScope(P),[J,l]=j(P),_=e=>{const{__scopeDialog:s,children:o,open:r,defaultOpen:n,onOpenChange:t,modal:u=!0}=e,a=i.useRef(null),p=i.useRef(null),[C=!1,R]=H.useControllableState({prop:r,defaultProp:n,onChange:t});return c.jsx(J,{scope:s,triggerRef:a,contentRef:p,contentId:m.useId(),titleId:m.useId(),descriptionId:m.useId(),open:C,onOpenChange:R,onOpenToggle:i.useCallback(()=>R(w=>!w),[R]),modal:u,children:o})};_.displayName=P;const h="DialogTrigger",T=i.forwardRef((e,s)=>{const{__scopeDialog:o,...r}=e,n=l(h,o),t=O.useComposedRefs(s,n.triggerRef);return c.jsx(g.Primitive.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":b(n.open),...r,ref:t,onClick:f.composeEventHandlers(e.onClick,n.onOpenToggle)})});T.displayName=h;const Q="DialogPortal",[se,N]=j(Q,{forceMount:void 0}),D="DialogOverlay",x=i.forwardRef((e,s)=>{const o=N(D,e.__scopeDialog),{forceMount:r=o.forceMount,...n}=e,t=l(D,e.__scopeDialog);return t.modal?c.jsx(I.Presence,{present:r||t.open,children:c.jsx(W,{...n,ref:s})}):null});x.displayName=D;const W=i.forwardRef((e,s)=>{const{__scopeDialog:o,...r}=e,n=l(D,o);return c.jsx(K.RemoveScroll,{as:Y.Slot,allowPinchZoom:!0,shards:[n.contentRef],children:c.jsx(g.Primitive.div,{"data-state":b(n.open),...r,ref:s,style:{pointerEvents:"auto",...r.style}})})}),d="DialogContent",v=i.forwardRef((e,s)=>{const o=N(d,e.__scopeDialog),{forceMount:r=o.forceMount,...n}=e,t=l(d,e.__scopeDialog);return c.jsx(I.Presence,{present:r||t.open,children:t.modal?c.jsx(X,{...n,ref:s}):c.jsx($,{...n,ref:s})})});v.displayName=d;const X=i.forwardRef((e,s)=>{const o=l(d,e.__scopeDialog),r=i.useRef(null),n=O.useComposedRefs(s,o.contentRef,r);return i.useEffect(()=>{const t=r.current;if(t)return V.hideOthers(t)},[]),c.jsx(A,{...e,ref:n,trapFocus:o.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:f.composeEventHandlers(e.onCloseAutoFocus,t=>{t.preventDefault(),o.triggerRef.current?.focus()}),onPointerDownOutside:f.composeEventHandlers(e.onPointerDownOutside,t=>{const u=t.detail.originalEvent,a=u.button===0&&u.ctrlKey===!0;(u.button===2||a)&&t.preventDefault()}),onFocusOutside:f.composeEventHandlers(e.onFocusOutside,t=>t.preventDefault())})}),$=i.forwardRef((e,s)=>{const o=l(d,e.__scopeDialog),r=i.useRef(!1),n=i.useRef(!1);return c.jsx(A,{...e,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||o.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,n.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const u=t.target;o.triggerRef.current?.contains(u)&&t.preventDefault(),t.detail.originalEvent.type==="focusin"&&n.current&&t.preventDefault()}})}),A=i.forwardRef((e,s)=>{const{__scopeDialog:o,trapFocus:r,onOpenAutoFocus:n,onCloseAutoFocus:t,...u}=e,a=l(d,o),p=i.useRef(null),C=O.useComposedRefs(s,p);return z.useFocusGuards(),c.jsx(c.Fragment,{children:c.jsx(U.FocusScope,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:n,onUnmountAutoFocus:t,children:c.jsx(G.DismissableLayer,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":b(a.open),...u,ref:C,onDismiss:()=>a.onOpenChange(!1)})})})}),F="DialogTitle",y=i.forwardRef((e,s)=>{const{__scopeDialog:o,...r}=e,n=l(F,o);return c.jsx(g.Primitive.h2,{id:n.titleId,...r,ref:s})});y.displayName=F;const M="DialogDescription",S=i.forwardRef((e,s)=>{const{__scopeDialog:o,...r}=e,n=l(M,o);return c.jsx(g.Primitive.p,{id:n.descriptionId,...r,ref:s})});S.displayName=M;const q="DialogClose",E=i.forwardRef((e,s)=>{const{__scopeDialog:o,...r}=e,n=l(q,o);return c.jsx(g.Primitive.button,{type:"button",...r,ref:s,onClick:f.composeEventHandlers(e.onClick,()=>n.onOpenChange(!1))})});E.displayName=q;function b(e){return e?"open":"closed"}const ee=_,te=x,oe=v,ne=y,re=E;exports.Close=re;exports.Content=oe;exports.Dialog=_;exports.DialogClose=E;exports.DialogContent=v;exports.DialogDescription=S;exports.DialogOverlay=x;exports.DialogTitle=y;exports.DialogTrigger=T;exports.Overlay=te;exports.Root=ee;exports.Title=ne;exports.createDialogScope=B;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),T=require("react"),p=require("@radix-ui/primitive"),P=require("@radix-ui/react-compose-refs"),H=require("@radix-ui/react-context"),m=require("@radix-ui/react-id"),z=require("@radix-ui/react-use-controllable-state"),K=require("@radix-ui/react-dismissable-layer"),U=require("@zag-js/focus-trap"),V=require("@radix-ui/react-portal"),_=require("@radix-ui/react-presence"),g=require("@radix-ui/react-primitive"),Y=require("@radix-ui/react-focus-guards"),Z=require("react-remove-scroll"),B=require("aria-hidden"),J=require("@radix-ui/react-slot");function Q(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,s.get?s:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const c=Q(T),x="Dialog",[N,W]=H.createContextScope(x),[X,l]=N(x),O=e=>{const{__scopeDialog:n,children:t,open:s,defaultOpen:o,onOpenChange:r,modal:a=!0}=e,u=c.useRef(null),f=c.useRef(null),[R=!1,C]=z.useControllableState({prop:s,defaultProp:o,onChange:r});return i.jsx(X,{scope:n,triggerRef:u,contentRef:f,contentId:m.useId(),titleId:m.useId(),descriptionId:m.useId(),open:R,onOpenChange:C,onOpenToggle:c.useCallback(()=>C(G=>!G),[C]),modal:a,children:t})};O.displayName=x;const M="DialogTrigger",S=c.forwardRef((e,n)=>{const{__scopeDialog:t,...s}=e,o=l(M,t),r=P.useComposedRefs(n,o.triggerRef);return i.jsx(g.Primitive.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":j(o.open),...s,ref:r,onClick:p.composeEventHandlers(e.onClick,o.onOpenToggle)})});S.displayName=M;const v="DialogPortal",[$,q]=N(v,{forceMount:void 0}),y=e=>{const{__scopeDialog:n,forceMount:t,children:s,container:o}=e,r=l(v,n);return i.jsx($,{scope:n,forceMount:t,children:c.Children.map(s,a=>i.jsx(_.Presence,{present:t||r.open,children:i.jsx(V.Portal,{asChild:!0,container:o,children:a})}))})};y.displayName=v;const D="DialogOverlay",E=c.forwardRef((e,n)=>{const t=q(D,e.__scopeDialog),{forceMount:s=t.forceMount,...o}=e,r=l(D,e.__scopeDialog);return r.modal?i.jsx(_.Presence,{present:s||r.open,children:i.jsx(ee,{...o,ref:n})}):null});E.displayName=D;const ee=c.forwardRef((e,n)=>{const{__scopeDialog:t,...s}=e,o=l(D,t);return i.jsx(Z.RemoveScroll,{as:J.Slot,allowPinchZoom:!0,shards:[o.contentRef],children:i.jsx(g.Primitive.div,{"data-state":j(o.open),...s,ref:n,style:{pointerEvents:"auto",...s.style}})})}),d="DialogContent",b=c.forwardRef((e,n)=>{const t=q(d,e.__scopeDialog),{forceMount:s=t.forceMount,...o}=e,r=l(d,e.__scopeDialog);return i.jsx(_.Presence,{present:s||r.open,children:r.modal?i.jsx(te,{...o,ref:n}):i.jsx(oe,{...o,ref:n})})});b.displayName=d;const te=c.forwardRef((e,n)=>{const t=l(d,e.__scopeDialog),s=c.useRef(null),o=P.useComposedRefs(n,t.contentRef,s);return c.useEffect(()=>{const r=s.current;if(r)return B.hideOthers(r)},[]),i.jsx(w,{...e,ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onPointerDownOutside:p.composeEventHandlers(e.onPointerDownOutside,r=>{const a=r.detail.originalEvent,u=a.button===0&&a.ctrlKey===!0;(a.button===2||u)&&r.preventDefault()}),onFocusOutside:p.composeEventHandlers(e.onFocusOutside,r=>r.preventDefault())})}),oe=c.forwardRef((e,n)=>{const t=l(d,e.__scopeDialog),s=c.useRef(!1),o=c.useRef(!1);return i.jsx(w,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onInteractOutside:r=>{e.onInteractOutside?.(r),r.defaultPrevented||(s.current=!0,r.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const a=r.target;t.triggerRef.current?.contains(a)&&r.preventDefault(),r.detail.originalEvent.type==="focusin"&&o.current&&r.preventDefault()}})}),w=c.forwardRef((e,n)=>{const{__scopeDialog:t,trapFocus:s,onOpenAutoFocus:o,onCloseAutoFocus:r,...a}=e,u=l(d,t),f=c.useRef(null),R=P.useComposedRefs(n,f);return Y.useFocusGuards(),T.useEffect(()=>{if(s)return U.trapFocus(f.current,{preventScroll:!0,onActivate:o,onDeactivate:r})},[]),i.jsx(K.DismissableLayer,{role:"dialog",id:u.contentId,"aria-describedby":u.descriptionId,"aria-labelledby":u.titleId,"data-state":j(u.open),...a,ref:R,onDismiss:()=>u.onOpenChange(!1)})}),A="DialogTitle",h=c.forwardRef((e,n)=>{const{__scopeDialog:t,...s}=e,o=l(A,t);return i.jsx(g.Primitive.h2,{id:o.titleId,...s,ref:n})});h.displayName=A;const F="DialogDescription",k=c.forwardRef((e,n)=>{const{__scopeDialog:t,...s}=e,o=l(F,t);return i.jsx(g.Primitive.p,{id:o.descriptionId,...s,ref:n})});k.displayName=F;const L="DialogClose",I=c.forwardRef((e,n)=>{const{__scopeDialog:t,...s}=e,o=l(L,t);return i.jsx(g.Primitive.button,{type:"button",...s,ref:n,onClick:p.composeEventHandlers(e.onClick,()=>o.onOpenChange(!1))})});I.displayName=L;function j(e){return e?"open":"closed"}const ne=O,re=y,se=E,ce=b,ie=h,ae=I;exports.Close=ae;exports.Content=ce;exports.Dialog=O;exports.DialogClose=I;exports.DialogContent=b;exports.DialogDescription=k;exports.DialogOverlay=E;exports.DialogPortal=y;exports.DialogTitle=h;exports.DialogTrigger=S;exports.Overlay=se;exports.Portal=re;exports.Root=ne;exports.Title=ie;exports.createDialogScope=W;
@@ -1,216 +1,215 @@
1
1
  "use client";
2
- import { jsx as i, Fragment as k } from "react/jsx-runtime";
2
+ import { jsx as i } from "react/jsx-runtime";
3
3
  import * as c from "react";
4
- import { composeEventHandlers as d } from "@radix-ui/primitive";
4
+ import { useEffect as G } from "react";
5
+ import { composeEventHandlers as g } from "@radix-ui/primitive";
5
6
  import { useComposedRefs as _ } from "@radix-ui/react-compose-refs";
6
- import { createContextScope as L } from "@radix-ui/react-context";
7
+ import { createContextScope as $ } from "@radix-ui/react-context";
7
8
  import { useId as C } from "@radix-ui/react-id";
8
- import { useControllableState as G } from "@radix-ui/react-use-controllable-state";
9
- import { DismissableLayer as j } from "@radix-ui/react-dismissable-layer";
10
- import { FocusScope as H } from "@radix-ui/react-focus-scope";
11
- import "@radix-ui/react-portal";
12
- import { Presence as y } from "@radix-ui/react-presence";
13
- import { Primitive as p } from "@radix-ui/react-primitive";
14
- import { useFocusGuards as K } from "@radix-ui/react-focus-guards";
15
- import { RemoveScroll as U } from "react-remove-scroll";
16
- import { hideOthers as V } from "aria-hidden";
17
- import { Slot as Y } from "@radix-ui/react-slot";
18
- const O = "Dialog", [E, go] = L(O), [Z, l] = E(O), h = (o) => {
19
- const { __scopeDialog: s, children: r, open: n, defaultOpen: t, onOpenChange: e, modal: u = !0 } = o, a = c.useRef(null), g = c.useRef(null), [D = !1, R] = G({
20
- prop: n,
9
+ import { useControllableState as j } from "@radix-ui/react-use-controllable-state";
10
+ import { DismissableLayer as H } from "@radix-ui/react-dismissable-layer";
11
+ import { trapFocus as K } from "@zag-js/focus-trap";
12
+ import { Portal as V } from "@radix-ui/react-portal";
13
+ import { Presence as O } from "@radix-ui/react-presence";
14
+ import { Primitive as d } from "@radix-ui/react-primitive";
15
+ import { useFocusGuards as Y } from "@radix-ui/react-focus-guards";
16
+ import { RemoveScroll as Z } from "react-remove-scroll";
17
+ import { hideOthers as q } from "aria-hidden";
18
+ import { Slot as z } from "@radix-ui/react-slot";
19
+ const P = "Dialog", [E, Co] = $(P), [B, l] = E(P), I = (o) => {
20
+ const { __scopeDialog: n, children: r, open: s, defaultOpen: t, onOpenChange: e, modal: a = !0 } = o, f = c.useRef(null), p = c.useRef(null), [D = !1, R] = j({
21
+ prop: s,
21
22
  defaultProp: t,
22
23
  onChange: e
23
24
  });
24
25
  return /* @__PURE__ */ i(
25
- Z,
26
+ B,
26
27
  {
27
- scope: s,
28
- triggerRef: a,
29
- contentRef: g,
28
+ scope: n,
29
+ triggerRef: f,
30
+ contentRef: p,
30
31
  contentId: C(),
31
32
  titleId: C(),
32
33
  descriptionId: C(),
33
34
  open: D,
34
35
  onOpenChange: R,
35
- onOpenToggle: c.useCallback(() => R((S) => !S), [R]),
36
- modal: u,
36
+ onOpenToggle: c.useCallback(() => R((L) => !L), [R]),
37
+ modal: a,
37
38
  children: r
38
39
  }
39
40
  );
40
41
  };
41
- h.displayName = O;
42
- const I = "DialogTrigger", q = c.forwardRef(
43
- (o, s) => {
44
- const { __scopeDialog: r, ...n } = o, t = l(I, r), e = _(s, t.triggerRef);
42
+ I.displayName = P;
43
+ const v = "DialogTrigger", J = c.forwardRef(
44
+ (o, n) => {
45
+ const { __scopeDialog: r, ...s } = o, t = l(v, r), e = _(n, t.triggerRef);
45
46
  return /* @__PURE__ */ i(
46
- p.button,
47
+ d.button,
47
48
  {
48
49
  type: "button",
49
50
  "aria-haspopup": "dialog",
50
51
  "aria-expanded": t.open,
51
52
  "aria-controls": t.contentId,
52
- "data-state": P(t.open),
53
- ...n,
53
+ "data-state": y(t.open),
54
+ ...s,
54
55
  ref: e,
55
- onClick: d(o.onClick, t.onOpenToggle)
56
+ onClick: g(o.onClick, t.onOpenToggle)
56
57
  }
57
58
  );
58
59
  }
59
60
  );
60
- q.displayName = I;
61
- const z = "DialogPortal", [mo, v] = E(z, {
61
+ J.displayName = v;
62
+ const h = "DialogPortal", [Q, x] = E(h, {
62
63
  forceMount: void 0
63
- }), m = "DialogOverlay", x = c.forwardRef(
64
- (o, s) => {
65
- const r = v(m, o.__scopeDialog), { forceMount: n = r.forceMount, ...t } = o, e = l(m, o.__scopeDialog);
66
- return e.modal ? /* @__PURE__ */ i(y, { present: n || e.open, children: /* @__PURE__ */ i(B, { ...t, ref: s }) }) : null;
64
+ }), N = (o) => {
65
+ const { __scopeDialog: n, forceMount: r, children: s, container: t } = o, e = l(h, n);
66
+ return /* @__PURE__ */ i(Q, { scope: n, forceMount: r, children: c.Children.map(s, (a) => /* @__PURE__ */ i(O, { present: r || e.open, children: /* @__PURE__ */ i(V, { asChild: !0, container: t, children: a }) })) });
67
+ };
68
+ N.displayName = h;
69
+ const m = "DialogOverlay", T = c.forwardRef(
70
+ (o, n) => {
71
+ const r = x(m, o.__scopeDialog), { forceMount: s = r.forceMount, ...t } = o, e = l(m, o.__scopeDialog);
72
+ return e.modal ? /* @__PURE__ */ i(O, { present: s || e.open, children: /* @__PURE__ */ i(U, { ...t, ref: n }) }) : null;
67
73
  }
68
74
  );
69
- x.displayName = m;
70
- const B = c.forwardRef(
71
- (o, s) => {
72
- const { __scopeDialog: r, ...n } = o, t = l(m, r);
75
+ T.displayName = m;
76
+ const U = c.forwardRef(
77
+ (o, n) => {
78
+ const { __scopeDialog: r, ...s } = o, t = l(m, r);
73
79
  return (
74
80
  // Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
75
81
  // ie. when `Overlay` and `Content` are siblings
76
- /* @__PURE__ */ i(U, { as: Y, allowPinchZoom: !0, shards: [t.contentRef], children: /* @__PURE__ */ i(
77
- p.div,
82
+ /* @__PURE__ */ i(Z, { as: z, allowPinchZoom: !0, shards: [t.contentRef], children: /* @__PURE__ */ i(
83
+ d.div,
78
84
  {
79
- "data-state": P(t.open),
80
- ...n,
81
- ref: s,
82
- style: { pointerEvents: "auto", ...n.style }
85
+ "data-state": y(t.open),
86
+ ...s,
87
+ ref: n,
88
+ style: { pointerEvents: "auto", ...s.style }
83
89
  }
84
90
  ) })
85
91
  );
86
92
  }
87
- ), f = "DialogContent", A = c.forwardRef(
88
- (o, s) => {
89
- const r = v(f, o.__scopeDialog), { forceMount: n = r.forceMount, ...t } = o, e = l(f, o.__scopeDialog);
90
- return /* @__PURE__ */ i(y, { present: n || e.open, children: e.modal ? /* @__PURE__ */ i(J, { ...t, ref: s }) : /* @__PURE__ */ i(Q, { ...t, ref: s }) });
93
+ ), u = "DialogContent", M = c.forwardRef(
94
+ (o, n) => {
95
+ const r = x(u, o.__scopeDialog), { forceMount: s = r.forceMount, ...t } = o, e = l(u, o.__scopeDialog);
96
+ return /* @__PURE__ */ i(O, { present: s || e.open, children: e.modal ? /* @__PURE__ */ i(W, { ...t, ref: n }) : /* @__PURE__ */ i(X, { ...t, ref: n }) });
91
97
  }
92
98
  );
93
- A.displayName = f;
94
- const J = c.forwardRef(
95
- (o, s) => {
96
- const r = l(f, o.__scopeDialog), n = c.useRef(null), t = _(s, r.contentRef, n);
99
+ M.displayName = u;
100
+ const W = c.forwardRef(
101
+ (o, n) => {
102
+ const r = l(u, o.__scopeDialog), s = c.useRef(null), t = _(n, r.contentRef, s);
97
103
  return c.useEffect(() => {
98
- const e = n.current;
99
- if (e) return V(e);
104
+ const e = s.current;
105
+ if (e) return q(e);
100
106
  }, []), /* @__PURE__ */ i(
101
- N,
107
+ b,
102
108
  {
103
109
  ...o,
104
110
  ref: t,
105
111
  trapFocus: r.open,
106
112
  disableOutsidePointerEvents: !0,
107
- onCloseAutoFocus: d(o.onCloseAutoFocus, (e) => {
108
- e.preventDefault(), r.triggerRef.current?.focus();
109
- }),
110
- onPointerDownOutside: d(o.onPointerDownOutside, (e) => {
111
- const u = e.detail.originalEvent, a = u.button === 0 && u.ctrlKey === !0;
112
- (u.button === 2 || a) && e.preventDefault();
113
+ onPointerDownOutside: g(o.onPointerDownOutside, (e) => {
114
+ const a = e.detail.originalEvent, f = a.button === 0 && a.ctrlKey === !0;
115
+ (a.button === 2 || f) && e.preventDefault();
113
116
  }),
114
- onFocusOutside: d(
117
+ onFocusOutside: g(
115
118
  o.onFocusOutside,
116
119
  (e) => e.preventDefault()
117
120
  )
118
121
  }
119
122
  );
120
123
  }
121
- ), Q = c.forwardRef(
122
- (o, s) => {
123
- const r = l(f, o.__scopeDialog), n = c.useRef(!1), t = c.useRef(!1);
124
+ ), X = c.forwardRef(
125
+ (o, n) => {
126
+ const r = l(u, o.__scopeDialog), s = c.useRef(!1), t = c.useRef(!1);
124
127
  return /* @__PURE__ */ i(
125
- N,
128
+ b,
126
129
  {
127
130
  ...o,
128
- ref: s,
131
+ ref: n,
129
132
  trapFocus: !1,
130
133
  disableOutsidePointerEvents: !1,
131
- onCloseAutoFocus: (e) => {
132
- o.onCloseAutoFocus?.(e), e.defaultPrevented || (n.current || r.triggerRef.current?.focus(), e.preventDefault()), n.current = !1, t.current = !1;
133
- },
134
134
  onInteractOutside: (e) => {
135
- o.onInteractOutside?.(e), e.defaultPrevented || (n.current = !0, e.detail.originalEvent.type === "pointerdown" && (t.current = !0));
136
- const u = e.target;
137
- r.triggerRef.current?.contains(u) && e.preventDefault(), e.detail.originalEvent.type === "focusin" && t.current && e.preventDefault();
135
+ o.onInteractOutside?.(e), e.defaultPrevented || (s.current = !0, e.detail.originalEvent.type === "pointerdown" && (t.current = !0));
136
+ const a = e.target;
137
+ r.triggerRef.current?.contains(a) && e.preventDefault(), e.detail.originalEvent.type === "focusin" && t.current && e.preventDefault();
138
138
  }
139
139
  }
140
140
  );
141
141
  }
142
- ), N = c.forwardRef(
143
- (o, s) => {
144
- const { __scopeDialog: r, trapFocus: n, onOpenAutoFocus: t, onCloseAutoFocus: e, ...u } = o, a = l(f, r), g = c.useRef(null), D = _(s, g);
145
- return K(), /* @__PURE__ */ i(k, { children: /* @__PURE__ */ i(
142
+ ), b = c.forwardRef(
143
+ (o, n) => {
144
+ const { __scopeDialog: r, trapFocus: s, onOpenAutoFocus: t, onCloseAutoFocus: e, ...a } = o, f = l(u, r), p = c.useRef(null), D = _(n, p);
145
+ return Y(), G(() => {
146
+ if (s)
147
+ return K(p.current, {
148
+ preventScroll: !0,
149
+ onActivate: t,
150
+ onDeactivate: e
151
+ });
152
+ }, []), /* @__PURE__ */ i(
146
153
  H,
147
154
  {
148
- asChild: !0,
149
- loop: !0,
150
- trapped: n,
151
- onMountAutoFocus: t,
152
- onUnmountAutoFocus: e,
153
- children: /* @__PURE__ */ i(
154
- j,
155
- {
156
- role: "dialog",
157
- id: a.contentId,
158
- "aria-describedby": a.descriptionId,
159
- "aria-labelledby": a.titleId,
160
- "data-state": P(a.open),
161
- ...u,
162
- ref: D,
163
- onDismiss: () => a.onOpenChange(!1)
164
- }
165
- )
155
+ role: "dialog",
156
+ id: f.contentId,
157
+ "aria-describedby": f.descriptionId,
158
+ "aria-labelledby": f.titleId,
159
+ "data-state": y(f.open),
160
+ ...a,
161
+ ref: D,
162
+ onDismiss: () => f.onOpenChange(!1)
166
163
  }
167
- ) });
164
+ );
168
165
  }
169
- ), T = "DialogTitle", F = c.forwardRef(
170
- (o, s) => {
171
- const { __scopeDialog: r, ...n } = o, t = l(T, r);
172
- return /* @__PURE__ */ i(p.h2, { id: t.titleId, ...n, ref: s });
166
+ ), w = "DialogTitle", A = c.forwardRef(
167
+ (o, n) => {
168
+ const { __scopeDialog: r, ...s } = o, t = l(w, r);
169
+ return /* @__PURE__ */ i(d.h2, { id: t.titleId, ...s, ref: n });
173
170
  }
174
171
  );
175
- F.displayName = T;
176
- const M = "DialogDescription", W = c.forwardRef(
177
- (o, s) => {
178
- const { __scopeDialog: r, ...n } = o, t = l(M, r);
179
- return /* @__PURE__ */ i(p.p, { id: t.descriptionId, ...n, ref: s });
172
+ A.displayName = w;
173
+ const F = "DialogDescription", oo = c.forwardRef(
174
+ (o, n) => {
175
+ const { __scopeDialog: r, ...s } = o, t = l(F, r);
176
+ return /* @__PURE__ */ i(d.p, { id: t.descriptionId, ...s, ref: n });
180
177
  }
181
178
  );
182
- W.displayName = M;
183
- const b = "DialogClose", w = c.forwardRef(
184
- (o, s) => {
185
- const { __scopeDialog: r, ...n } = o, t = l(b, r);
179
+ oo.displayName = F;
180
+ const S = "DialogClose", k = c.forwardRef(
181
+ (o, n) => {
182
+ const { __scopeDialog: r, ...s } = o, t = l(S, r);
186
183
  return /* @__PURE__ */ i(
187
- p.button,
184
+ d.button,
188
185
  {
189
186
  type: "button",
190
- ...n,
191
- ref: s,
192
- onClick: d(o.onClick, () => t.onOpenChange(!1))
187
+ ...s,
188
+ ref: n,
189
+ onClick: g(o.onClick, () => t.onOpenChange(!1))
193
190
  }
194
191
  );
195
192
  }
196
193
  );
197
- w.displayName = b;
198
- function P(o) {
194
+ k.displayName = S;
195
+ function y(o) {
199
196
  return o ? "open" : "closed";
200
197
  }
201
- const Do = h, Ro = x, Co = A, _o = F, Oo = w;
198
+ const _o = I, Oo = N, Po = T, ho = M, yo = A, Eo = k;
202
199
  export {
203
- Oo as Close,
204
- Co as Content,
205
- h as Dialog,
206
- w as DialogClose,
207
- A as DialogContent,
208
- W as DialogDescription,
209
- x as DialogOverlay,
210
- F as DialogTitle,
211
- q as DialogTrigger,
212
- Ro as Overlay,
213
- Do as Root,
214
- _o as Title,
215
- go as createDialogScope
200
+ Eo as Close,
201
+ ho as Content,
202
+ I as Dialog,
203
+ k as DialogClose,
204
+ M as DialogContent,
205
+ oo as DialogDescription,
206
+ T as DialogOverlay,
207
+ N as DialogPortal,
208
+ A as DialogTitle,
209
+ J as DialogTrigger,
210
+ Po as Overlay,
211
+ Oo as Portal,
212
+ _o as Root,
213
+ yo as Title,
214
+ Co as createDialogScope
216
215
  };
@@ -1,4 +1,4 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Le=require("openai"),t=require("react"),xe=require("../../providers/config-provider.cjs"),Be=require("../../providers/conversation-provider.cjs"),De=require("../../providers/chat-events-provider.cjs"),D=require("../../utils/get-message-metadata.cjs"),Oe=require("../../utils/misc.cjs"),ae=require("../../utils/reset-query-params.cjs"),Fe=require("../../providers/chat-form-provider.cjs"),Te=require("../../providers/widget-provider.cjs"),Ke=require("../../hooks/use-media-query.cjs"),Qe=require("./use-captcha.cjs"),We=require("../modal/modal-provider.cjs"),l=require("../../utils/generate-uid.cjs"),Je=require("../../utils/tools/links-tool.cjs"),ze=require("../../atoms/api/analytics/conversation.cjs"),He=()=>{const{chatId:p,setConversation:re,conversation:N,resetConversation:ie}=Be.useInkeepConversation(),{baseSettings:b,aiChatSettings:O}=xe.useInkeepConfig(),{aiApiBaseUrl:F,shouldBypassCaptcha:T,filters:K}=b,Q=We.useModal(),{getSolution:ce,prefetchSolution:q,invalidateSolution:W}=Qe.useCaptcha({fetchUrl:`${F}/v1/challenge`,shouldBypassCaptcha:T,shouldMakeInitialRequest:Q?Q.isOpen:!0}),ue=new Le({baseURL:`${F}/v1`,apiKey:b.apiKey,dangerouslyAllowBrowser:!0}),{onInputMessageChange:le,getTools:de,prompts:ge,model:me,filters:J,onToolCall:pe}=O,[f,_]=t.useState(""),z=t.useRef(null);t.useEffect(()=>{le?.(f)},[f]);const[d,u]=t.useState([]),[H,h]=t.useState(!1),[fe,v]=t.useState(!1),[he,j]=t.useState(null),[A,G]=t.useState(null),[y,S]=t.useState([]),ve=e=>{S(s=>[...s,e])},[ye,V]=t.useState({}),r=t.useRef([]),C=t.useRef(null),{logEvent:P,logConversation:Se}=De.useChatEvents(),X=ge?.map((e,s)=>({id:`system-${Date.now().toString()}-${l.generateUid(4)}-${s}`,role:"system",content:e})),[Ce,we]=t.useState(!!p);t.useEffect(()=>{if(p){const{apiKey:e,analyticsApiBaseUrl:s}=b;ze.getConversation(p,e,s).then(o=>{if(o){P({eventName:"shared_chat_loaded",properties:{conversation:o}}),we(!1),re({...o,id:""});const a=o.messages.map(c=>({id:Date.now().toString()+l.generateUid(4)+c.id,content:Oe.parseIfJson(c.content),role:c.role,links:c.links}));u(a),r.current=a}})}},[p]);const Me=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${b.organizationDisplayName??"Administrator"}`;default:return`Hmm..
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ae=require("openai"),t=require("react"),Re=require("../../providers/config-provider.cjs"),Le=require("../../providers/conversation-provider.cjs"),xe=require("../../providers/chat-events-provider.cjs"),D=require("../../utils/get-message-metadata.cjs"),Be=require("../../utils/misc.cjs"),ae=require("../../utils/reset-query-params.cjs"),De=require("../../providers/chat-form-provider.cjs"),Oe=require("../../providers/widget-provider.cjs"),Fe=require("../../hooks/use-media-query.cjs"),Te=require("./use-captcha.cjs"),Ke=require("../modal/modal-provider.cjs"),l=require("../../utils/generate-uid.cjs"),Qe=require("../../utils/tools/links-tool.cjs"),We=require("../../atoms/api/analytics/conversation.cjs"),Je=()=>{const{chatId:f,setConversation:re,conversation:N,resetConversation:ie}=Le.useInkeepConversation(),{baseSettings:b,aiChatSettings:O}=Re.useInkeepConfig(),{aiApiBaseUrl:F,shouldBypassCaptcha:T,filters:K}=b,Q=Ke.useModal(),{getSolution:ce,prefetchSolution:q,invalidateSolution:W}=Te.useCaptcha({fetchUrl:`${F}/v1/challenge`,shouldBypassCaptcha:T,shouldMakeInitialRequest:Q?Q.isOpen:!0}),ue=new Ae({baseURL:`${F}/v1`,apiKey:b.apiKey,dangerouslyAllowBrowser:!0}),{onInputMessageChange:le,getTools:ge,prompts:de,model:me,filters:J,onToolCall:fe}=O,[p,_]=t.useState(""),z=t.useRef(null);t.useEffect(()=>{le?.(p)},[p]);const[g,u]=t.useState([]),[H,h]=t.useState(!1),[pe,v]=t.useState(!1),[he,j]=t.useState(null),[A,G]=t.useState(null),[y,S]=t.useState([]),ve=e=>{S(s=>[...s,e])},[ye,V]=t.useState({}),r=t.useRef([]),C=t.useRef(null),{logEvent:P}=xe.useChatEvents(),X=de?.map((e,s)=>({id:`system-${Date.now().toString()}-${l.generateUid(4)}-${s}`,role:"system",content:e})),[Se,Ce]=t.useState(!!f);t.useEffect(()=>{if(f){const{apiKey:e,analyticsApiBaseUrl:s}=b;We.getConversation(f,e,s).then(o=>{if(o){P({eventName:"shared_chat_loaded",properties:{conversation:o}}),Ce(!1),re({...o,id:""});const a=o.messages.map(c=>({id:Date.now().toString()+l.generateUid(4)+c.id,content:Be.parseIfJson(c.content),role:c.role,links:c.links}));u(a),r.current=a}})}},[f]);const Me=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${b.organizationDisplayName??"Administrator"}`;default:return`Hmm..
2
2
 
3
- It seems I might be having some issues right now. Please clear the chat and try again.`}},Y=e=>{j(e),u(s=>{const o=[...s],a=o[o.length-1];return a&&(a.content=Me(e)),o}),h(!1),v(!1),W(),q()},R=!f.trim()&&!y.length||H,Ie=e=>{e.key==="Enter"&&!e.shiftKey&&!R&&!e.nativeEvent.isComposing&&(e.preventDefault(),L())},ke=e=>{const s=e.target.value;_(s)},L=async(e=f)=>{if(R&&(!e||e.trim().length===0))return;h(!0);const s=A?d.length===2:d.length===0,o=D.getMessageMetadata(A,y,s);let a;const c=D.serializeAttachments(y);y.length&&c?a=[{type:"text",text:c}]:a=e;const ee={id:`${Date.now().toString()}-${l.generateUid(4)}-1`,role:"user",content:a,metadata:o},E=[...d.length?[]:X,ee];p&&ae.resetQueryParams(),u(w=>[...w,...E]),r.current=[...r.current,...E],S([]),_(""),P({eventName:"user_message_submitted",properties:{}},r.current);const te=[Je.provideLinksTool,...de?.({conversation:N})||[]];try{const w={model:me,messages:r.current,stream:!0,tools:te,tool_choice:"auto"},se=await ce(),ne=se?btoa(JSON.stringify(se)):null,oe=K||J?JSON.stringify({...K,...J}):void 0,U={};!T&&ne&&(U["X-INKEEP-CHALLENGE-SOLUTION"]=ne),oe&&(U["inkeep-filters"]=oe);const g=ue.beta.chat.completions.stream(w,Object.keys(U).length>0?{headers:U}:void 0),n={id:`${Date.now().toString()}-${l.generateUid(4)}-2`,role:"assistant",content:"",links:[],toolCalls:[]};u(M=>[...M,n]),g.on("content",(M,I)=>{v(!0),n.content=I,u($=>{const i=[...$],x=i.findIndex(k=>k.id===n.id);return x===-1?[...i,n]:(i[x]={...n},i)})}),g.on("tool_calls.function.arguments.done",async M=>{const{name:I,arguments:$}=M,i=te?.find(m=>m.function.name===I);if(!i)return;const k=("parse"in i.function?i.function.parse:JSON.parse)($),$e=i.function.function?.(k,g),Ne=i.renderMessageButtons?.({args:k,execution:$e})??[];I==="provideLinks"?n.links=k.links??[]:V(m=>({...m,[n.id]:[...m[n.id]??[],...Ne]})),n.toolCalls?.push({id:"call_"+l.generateUid(24),type:"function",function:{name:I,arguments:$}}),u(m=>{const B=[...m],Ae=B.findIndex(Re=>Re.id===n.id);return B[Ae]={...n},B});const _e=await Se([...r.current,n]);pe?.(M,{conversation:_e??N})}),g.on("error",Y),g.finalChatCompletion().then(()=>{r.current=[...r.current,n],C.current=null,h(!1),v(!1),q(),P({eventName:"assistant_message_received",properties:{}},r.current)}),C.current=g.controller}catch(w){Y(w),h(!1),v(!1)}},be=()=>{C.current&&(C.current.abort(),C.current=null),h(!1),v(!1),q()},Z=()=>{j(null),u([]),r.current=[],ie(),V({}),S([]),ae.resetQueryParams(),G(null),W(),q(),P({eventName:"chat_clear_button_clicked",properties:{conversation:N}})},qe=e=>{G(e);const{initialReplyMessage:s,displayName:o}=e,a={id:d.length.toString()+l.generateUid(4),role:"user",content:o},c={id:(d.length+1).toString()+l.generateUid(4),role:"assistant",content:s,links:[]},E=[{id:`system-${Date.now().toString()}-${l.generateUid(4)}-${e.id}`,role:"system",content:`Company has asked user to follow this guided workflow:
4
- ${D.serializeWorkflow(e)}`},...X,a,c];u(E),S([])},{openForm:Pe}=Fe.useChatForm(),Ee=Te.useWidget();t.useImperativeHandle(O.chatFunctionsRef,()=>({submitMessage:L,updateInputMessage(e){_(e)},clearChat:Z,openForm:e=>{Ee?.setView("chat"),Pe(e)},focusInput:()=>{z.current?.focus()}}));const Ue=Ke.useMediaQuery("(max-width: 768px)");return{messages:d,input:f,isLoading:H,isStreaming:fe,isLoadingConversation:Ce,error:he,isSubmitDisabled:R,handleInputChange:ke,handleInputKeyDown:Ie,handleSubmit:L,stop:be,clear:Z,handleWorkflow:qe,selectedWorkflow:A,messageAttachments:y,setMessageAttachments:S,addAttachment:ve,messageButtons:ye,isEmpty:d.length===0,inputRef:z,isMobile:Ue}};exports.useInkeepChat=He;
3
+ It seems I might be having some issues right now. Please clear the chat and try again.`}},Y=e=>{j(e),u(s=>{const o=[...s],a=o[o.length-1];return a&&(a.content=Me(e)),o}),h(!1),v(!1),W(),q()},R=!p.trim()&&!y.length||H,we=e=>{e.key==="Enter"&&!e.shiftKey&&!R&&!e.nativeEvent.isComposing&&(e.preventDefault(),L())},Ie=e=>{const s=e.target.value;_(s)},L=async(e=p)=>{if(R&&(!e||e.trim().length===0))return;h(!0);const s=A?g.length===2:g.length===0,o=D.getMessageMetadata(A,y,s);let a;const c=D.serializeAttachments(y);y.length&&c?a=[{type:"text",text:c}]:a=e;const ee={id:`${Date.now().toString()}-${l.generateUid(4)}-1`,role:"user",content:a,metadata:o},E=[...g.length?[]:X,ee];f&&ae.resetQueryParams(),u(M=>[...M,...E]),r.current=[...r.current,...E],S([]),_(""),P({eventName:"user_message_submitted",properties:{}},r.current);const te=[Qe.provideLinksTool,...ge?.({conversation:N})||[]];try{const M={model:me,messages:r.current,stream:!0,tools:te,tool_choice:"auto"},se=await ce(),ne=se?btoa(JSON.stringify(se)):null,oe=K||J?JSON.stringify({...K,...J}):void 0,U={};!T&&ne&&(U["X-INKEEP-CHALLENGE-SOLUTION"]=ne),oe&&(U["inkeep-filters"]=oe);const d=ue.beta.chat.completions.stream(M,Object.keys(U).length>0?{headers:U}:void 0),n={id:`${Date.now().toString()}-${l.generateUid(4)}-2`,role:"assistant",content:"",links:[],toolCalls:[]};u(w=>[...w,n]),d.on("content",(w,I)=>{v(!0),n.content=I,u($=>{const i=[...$],x=i.findIndex(k=>k.id===n.id);return x===-1?[...i,n]:(i[x]={...n},i)})}),d.on("tool_calls.function.arguments.done",async w=>{const{name:I,arguments:$}=w,i=te?.find(m=>m.function.name===I);if(!i)return;const k=("parse"in i.function?i.function.parse:JSON.parse)($),Ue=i.function.function?.(k,d),$e=i.renderMessageButtons?.({args:k,execution:Ue})??[];I==="provideLinks"?n.links=k.links??[]:V(m=>({...m,[n.id]:[...m[n.id]??[],...$e]})),n.toolCalls?.push({id:"call_"+l.generateUid(24),type:"function",function:{name:I,arguments:$}}),u(m=>{const B=[...m],Ne=B.findIndex(_e=>_e.id===n.id);return B[Ne]={...n},B}),fe?.(w,{conversation:{...N,messages:[...r.current,n]}})}),d.on("error",Y),d.finalChatCompletion().then(()=>{r.current=[...r.current,n],C.current=null,h(!1),v(!1),q(),P({eventName:"assistant_message_received",properties:{}},r.current)}),C.current=d.controller}catch(M){Y(M),h(!1),v(!1)}},ke=()=>{C.current&&(C.current.abort(),C.current=null),h(!1),v(!1),q()},Z=()=>{j(null),u([]),r.current=[],ie(),V({}),S([]),ae.resetQueryParams(),G(null),W(),q(),P({eventName:"chat_clear_button_clicked",properties:{conversation:N}})},be=e=>{G(e);const{initialReplyMessage:s,displayName:o}=e,a={id:g.length.toString()+l.generateUid(4),role:"user",content:o},c={id:(g.length+1).toString()+l.generateUid(4),role:"assistant",content:s,links:[]},E=[{id:`system-${Date.now().toString()}-${l.generateUid(4)}-${e.id}`,role:"system",content:`Company has asked user to follow this guided workflow:
4
+ ${D.serializeWorkflow(e)}`},...X,a,c];u(E),S([])},{openForm:qe}=De.useChatForm(),Pe=Oe.useWidget();t.useImperativeHandle(O.chatFunctionsRef,()=>({submitMessage:L,updateInputMessage(e){_(e)},clearChat:Z,openForm:e=>{Pe?.setView("chat"),qe(e)},focusInput:()=>{z.current?.focus()}}));const Ee=Fe.useMediaQuery("(max-width: 768px)");return{messages:g,input:p,isLoading:H,isStreaming:pe,isLoadingConversation:Se,error:he,isSubmitDisabled:R,handleInputChange:Ie,handleInputKeyDown:we,handleSubmit:L,stop:ke,clear:Z,handleWorkflow:be,selectedWorkflow:A,messageAttachments:y,setMessageAttachments:S,addAttachment:ve,messageButtons:ye,isEmpty:g.length===0,inputRef:z,isMobile:Ee}};exports.useInkeepChat=Je;