@inkeep/cxkit-primitives 0.0.0-dev-20251211180640 → 0.0.0-dev-20251211192603

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 x=require("react/jsx-runtime"),s=require("react"),H=require("react-hook-form"),O=require("./conversation-provider.cjs"),M=require("../components/modal/modal-provider.cjs"),T=require("../utils/form.cjs"),V=require("./chat-events-provider.cjs"),j="root.serverError",S=s.createContext(void 0);function g(){const[t,i]=s.useState(null),[a,u]=s.useState(null),[C,l]=s.useState(!1),{conversation:r}=O.useInkeepConversation(),F=M.useModal(),{logEvent:b}=V.useChatEvents(),E=(e,o)=>{i(e),u(o||null)},m=()=>{i(null),u(null),l(!1),t?.buttons.close?.action==="close_modal"&&F?.setOpen(!1)},c=s.useMemo(()=>t?.fields.map(e=>{const o={...e};return"_type"in e&&e._type==="include_chat_session"&&(o.inputType="checkbox",r.id?(o.isHidden=e.isHidden,o.isRequired=e.isRequired):(o.isHidden=!0,o.isRequired=!1)),o}),[t?.fields,r.id]),d=c?.find(e=>"_type"in e&&e._type==="include_chat_session"),n=s.useMemo(()=>T.getFormDefaultValues(c),[c]),{control:_,handleSubmit:q,formState:{errors:f,isSubmitting:y},setError:R,reset:p}=H.useForm({defaultValues:n});s.useEffect(()=>{n&&p(n)},[p,n]);const P=q(async e=>{const v=r.id&&d&&e[d.name]?r:null;try{await t?.buttons.submit.onSubmit({values:e,conversation:v}),a&&b({eventName:"user_escalation_indicated",properties:{escalationType:"support_form",getHelpOptionName:a.name,conversation:v||r}}),l(!0),t?.successView||m()}catch(h){R(j,{message:h instanceof Error?h.message:"Something went wrong."})}}),w=f?.root?.serverError;return{form:t,openForm:E,closeForm:m,handleSubmit:P,isSuccess:C,isSubmitting:y,formError:w,fields:c,errors:f,control:_,defaultValues:n}}const k=({children:t})=>{const i=g();return x.jsx(S.Provider,{value:i,children:t})},N=()=>{const t=s.useContext(S);if(!t)throw new Error("useChatForm must be used within a ChatFormProvider");return t};exports.ChatFormProvider=k;exports.useChatForm=N;exports.useChatFormState=g;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),s=require("react"),H=require("react-hook-form"),O=require("./conversation-provider.cjs"),M=require("../components/modal/modal-provider.cjs"),N=require("../utils/form.cjs"),T=require("./chat-events-provider.cjs"),V="root.serverError",g=s.createContext(void 0);function C(){const[t,i]=s.useState(null),[u,m]=s.useState(null),[F,l]=s.useState(!1),{conversation:r}=O.useInkeepConversation(),b=M.useModal(),{logEvent:d}=T.useChatEvents(),_=(e,o)=>{i(e),m(o||null)},p=()=>{i(null),m(null),l(!1),t?.buttons.close?.action==="close_modal"&&b?.setOpen(!1)},c=s.useMemo(()=>t?.fields.map(e=>{const o={...e};return"_type"in e&&e._type==="include_chat_session"&&(o.inputType="checkbox",r.id?(o.isHidden=e.isHidden,o.isRequired=e.isRequired):(o.isHidden=!0,o.isRequired=!1)),o}),[t?.fields,r.id]),f=c?.find(e=>"_type"in e&&e._type==="include_chat_session"),n=s.useMemo(()=>N.getFormDefaultValues(c),[c]),{control:E,handleSubmit:q,formState:{errors:v,isSubmitting:y},setError:R,reset:h}=H.useForm({defaultValues:n});s.useEffect(()=>{n&&h(n)},[h,n]);const P=q(async e=>{const a=r.id&&f&&e[f.name]?r:null;try{await t?.buttons.submit.onSubmit({values:e,conversation:a}),u&&d({eventName:"user_escalation_indicated",properties:{escalationType:"support_form",getHelpOptionName:u.name,conversation:a||r}}),d({eventName:"ai_chat_form_submitted",properties:{conversation:a||r,values:e}}),l(!0),t?.successView||p()}catch(S){R(V,{message:S instanceof Error?S.message:"Something went wrong."})}}),w=v?.root?.serverError;return{form:t,openForm:_,closeForm:p,handleSubmit:P,isSuccess:F,isSubmitting:y,formError:w,fields:c,errors:v,control:E,defaultValues:n}}const j=({children:t})=>{const i=C();return x.jsx(g.Provider,{value:i,children:t})},k=()=>{const t=s.useContext(g);if(!t)throw new Error("useChatForm must be used within a ChatFormProvider");return t};exports.ChatFormProvider=j;exports.useChatForm=k;exports.useChatFormState=C;
@@ -1,60 +1,66 @@
1
1
  "use client";
2
2
  import { jsx as O } from "react/jsx-runtime";
3
- import { useState as c, useMemo as S, useEffect as V, createContext as q, useContext as M } from "react";
4
- import { useForm as N } from "react-hook-form";
3
+ import { useState as a, useMemo as _, useEffect as N, createContext as V, useContext as q } from "react";
4
+ import { useForm as M } from "react-hook-form";
5
5
  import { useInkeepConversation as P } from "./conversation-provider.js";
6
6
  import { useModal as T } from "../components/modal/modal-provider.js";
7
7
  import { getFormDefaultValues as k } from "../utils/form.js";
8
8
  import { useChatEvents as G } from "./chat-events-provider.js";
9
- const I = "root.serverError", g = q(void 0);
9
+ const I = "root.serverError", g = V(void 0);
10
10
  function j() {
11
- const [t, r] = c(null), [a, u] = c(null), [C, m] = c(!1), { conversation: s } = P(), E = T(), { logEvent: b } = G(), F = (e, o) => {
12
- r(e), u(o || null);
13
- }, l = () => {
14
- r(null), u(null), m(!1), t?.buttons.close?.action === "close_modal" && E?.setOpen(!1);
15
- }, i = S(() => t?.fields.map((e) => {
11
+ const [t, r] = a(null), [u, m] = a(null), [b, l] = a(!1), { conversation: s } = P(), C = T(), { logEvent: p } = G(), E = (e, o) => {
12
+ r(e), m(o || null);
13
+ }, d = () => {
14
+ r(null), m(null), l(!1), t?.buttons.close?.action === "close_modal" && C?.setOpen(!1);
15
+ }, i = _(() => t?.fields.map((e) => {
16
16
  const o = { ...e };
17
17
  return "_type" in e && e._type === "include_chat_session" && (o.inputType = "checkbox", s.id ? (o.isHidden = e.isHidden, o.isRequired = e.isRequired) : (o.isHidden = !0, o.isRequired = !1)), o;
18
- }), [t?.fields, s.id]), p = i?.find((e) => "_type" in e && e._type === "include_chat_session"), n = S(() => k(i), [i]), {
19
- control: _,
18
+ }), [t?.fields, s.id]), f = i?.find((e) => "_type" in e && e._type === "include_chat_session"), n = _(() => k(i), [i]), {
19
+ control: F,
20
20
  handleSubmit: y,
21
- formState: { errors: d, isSubmitting: R },
21
+ formState: { errors: h, isSubmitting: R },
22
22
  setError: w,
23
- reset: f
24
- } = N({
23
+ reset: v
24
+ } = M({
25
25
  defaultValues: n
26
26
  });
27
- V(() => {
28
- n && f(n);
29
- }, [f, n]);
27
+ N(() => {
28
+ n && v(n);
29
+ }, [v, n]);
30
30
  const x = y(async (e) => {
31
- const h = s.id && p && e[p.name] ? s : null;
31
+ const c = s.id && f && e[f.name] ? s : null;
32
32
  try {
33
- await t?.buttons.submit.onSubmit({ values: e, conversation: h }), a && b({
33
+ await t?.buttons.submit.onSubmit({ values: e, conversation: c }), u && p({
34
34
  eventName: "user_escalation_indicated",
35
35
  properties: {
36
36
  escalationType: "support_form",
37
- getHelpOptionName: a.name,
38
- conversation: h || s
37
+ getHelpOptionName: u.name,
38
+ conversation: c || s
39
39
  }
40
- }), m(!0), t?.successView || l();
41
- } catch (v) {
40
+ }), p({
41
+ eventName: "ai_chat_form_submitted",
42
+ properties: {
43
+ conversation: c || s,
44
+ values: e
45
+ }
46
+ }), l(!0), t?.successView || d();
47
+ } catch (S) {
42
48
  w(I, {
43
- message: v instanceof Error ? v.message : "Something went wrong."
49
+ message: S instanceof Error ? S.message : "Something went wrong."
44
50
  });
45
51
  }
46
- }), H = d?.root?.serverError;
52
+ }), H = h?.root?.serverError;
47
53
  return {
48
54
  form: t,
49
- openForm: F,
50
- closeForm: l,
55
+ openForm: E,
56
+ closeForm: d,
51
57
  handleSubmit: x,
52
- isSuccess: C,
58
+ isSuccess: b,
53
59
  isSubmitting: R,
54
60
  formError: H,
55
61
  fields: i,
56
- errors: d,
57
- control: _,
62
+ errors: h,
63
+ control: F,
58
64
  defaultValues: n
59
65
  };
60
66
  }
@@ -62,7 +68,7 @@ const U = ({ children: t }) => {
62
68
  const r = j();
63
69
  return /* @__PURE__ */ O(g.Provider, { value: r, children: t });
64
70
  }, W = () => {
65
- const t = M(g);
71
+ const t = q(g);
66
72
  if (!t)
67
73
  throw new Error("useChatForm must be used within a ChatFormProvider");
68
74
  return t;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/cxkit-primitives",
3
- "version": "0.0.0-dev-20251211180640",
3
+ "version": "0.0.0-dev-20251211192603",
4
4
  "description": "",
5
5
  "license": "Inkeep, Inc. Customer License (IICL) v1.1",
6
6
  "homepage": "",
@@ -67,9 +67,9 @@
67
67
  "remark-gfm": "^4.0.1",
68
68
  "unist-util-visit": "^5.0.0",
69
69
  "use-sync-external-store": "^1.4.0",
70
- "@inkeep/cxkit-color-mode": "^0.0.0-dev-20251211180640",
71
- "@inkeep/cxkit-theme": "0.0.0-dev-20251211180640",
72
- "@inkeep/cxkit-types": "0.0.0-dev-20251211180640"
70
+ "@inkeep/cxkit-color-mode": "^0.0.0-dev-20251211192603",
71
+ "@inkeep/cxkit-theme": "0.0.0-dev-20251211192603",
72
+ "@inkeep/cxkit-types": "0.0.0-dev-20251211192603"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@biomejs/biome": "1.9.4",