@inkeep/cxkit-primitives 0.5.107 → 0.5.108
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 B=require("react/jsx-runtime"),t=require("react"),f=require("../atoms/api/analytics/events.cjs"),b=require("./config-provider.cjs"),x=require("./user-provider.cjs"),E=t.createContext(void 0),q=({children:e})=>{const{baseSettings:s,componentType:r}=b.useInkeepConfig(),{apiKey:i,analyticsApiBaseUrl:c,tags:a,privacyPreferences:m,env:g,analyticsProperties:v}=s,{userProperties:u}=x.useUser(),l=t.useMemo(()=>({widgetLibraryVersion:"0.5.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("react/jsx-runtime"),t=require("react"),f=require("../atoms/api/analytics/events.cjs"),b=require("./config-provider.cjs"),x=require("./user-provider.cjs"),E=t.createContext(void 0),q=({children:e})=>{const{baseSettings:s,componentType:r}=b.useInkeepConfig(),{apiKey:i,analyticsApiBaseUrl:c,tags:a,privacyPreferences:m,env:g,analyticsProperties:v}=s,{userProperties:u}=x.useUser(),l=t.useMemo(()=>({widgetLibraryVersion:"0.5.108",componentType:r,tags:a}),[r,a]),d=!m.optOutAllAnalytics&&g!=="development",P={logEvent:t.useCallback(async n=>{const o={...l,...n.properties,...v},p={eventName:n.eventName,properties:o,userProperties:u},y=["modal_opened","modal_closed"].includes(n.eventName);if(d&&!y){if("conversation"in o&&!o.conversation?.id)return;f.logEvent(p,i,c)}s.onEvent?.(p)},[d,s,i,c,u,l,v])};return B.jsx(E.Provider,{value:P,children:e})},C=()=>{const e=t.useContext(E);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=q;exports.useBaseEvents=C;
|
|
@@ -7,7 +7,7 @@ import { useUser as A } from "./user-provider.js";
|
|
|
7
7
|
const u = B(void 0), $ = ({ children: e }) => {
|
|
8
8
|
const { baseSettings: t, componentType: s } = w(), { apiKey: r, analyticsApiBaseUrl: i, tags: a, privacyPreferences: d, env: E, analyticsProperties: c } = t, { userProperties: v } = A(), p = P(
|
|
9
9
|
() => ({
|
|
10
|
-
widgetLibraryVersion: "0.5.
|
|
10
|
+
widgetLibraryVersion: "0.5.108",
|
|
11
11
|
componentType: s,
|
|
12
12
|
tags: a
|
|
13
13
|
}),
|
|
@@ -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"),
|
|
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
|
|
4
|
-
import { useForm as
|
|
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 =
|
|
9
|
+
const I = "root.serverError", g = V(void 0);
|
|
10
10
|
function j() {
|
|
11
|
-
const [t, r] =
|
|
12
|
-
r(e),
|
|
13
|
-
},
|
|
14
|
-
r(null),
|
|
15
|
-
}, i =
|
|
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]),
|
|
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:
|
|
21
|
+
formState: { errors: h, isSubmitting: R },
|
|
22
22
|
setError: w,
|
|
23
|
-
reset:
|
|
24
|
-
} =
|
|
23
|
+
reset: v
|
|
24
|
+
} = M({
|
|
25
25
|
defaultValues: n
|
|
26
26
|
});
|
|
27
|
-
|
|
28
|
-
n &&
|
|
29
|
-
}, [
|
|
27
|
+
N(() => {
|
|
28
|
+
n && v(n);
|
|
29
|
+
}, [v, n]);
|
|
30
30
|
const x = y(async (e) => {
|
|
31
|
-
const
|
|
31
|
+
const c = s.id && f && e[f.name] ? s : null;
|
|
32
32
|
try {
|
|
33
|
-
await t?.buttons.submit.onSubmit({ values: e, conversation:
|
|
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:
|
|
38
|
-
conversation:
|
|
37
|
+
getHelpOptionName: u.name,
|
|
38
|
+
conversation: c || s
|
|
39
39
|
}
|
|
40
|
-
}),
|
|
41
|
-
|
|
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:
|
|
49
|
+
message: S instanceof Error ? S.message : "Something went wrong."
|
|
44
50
|
});
|
|
45
51
|
}
|
|
46
|
-
}), H =
|
|
52
|
+
}), H = h?.root?.serverError;
|
|
47
53
|
return {
|
|
48
54
|
form: t,
|
|
49
|
-
openForm:
|
|
50
|
-
closeForm:
|
|
55
|
+
openForm: E,
|
|
56
|
+
closeForm: d,
|
|
51
57
|
handleSubmit: x,
|
|
52
|
-
isSuccess:
|
|
58
|
+
isSuccess: b,
|
|
53
59
|
isSubmitting: R,
|
|
54
60
|
formError: H,
|
|
55
61
|
fields: i,
|
|
56
|
-
errors:
|
|
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 =
|
|
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.5.
|
|
3
|
+
"version": "0.5.108",
|
|
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.5.
|
|
71
|
-
"@inkeep/cxkit-theme": "0.5.
|
|
72
|
-
"@inkeep/cxkit-types": "0.5.
|
|
70
|
+
"@inkeep/cxkit-color-mode": "^0.5.108",
|
|
71
|
+
"@inkeep/cxkit-theme": "0.5.108",
|
|
72
|
+
"@inkeep/cxkit-types": "0.5.108"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@biomejs/biome": "1.9.4",
|