@squadico/chatbot 1.4.0 → 1.5.0
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/README.md +5 -4
- package/dist/answer-CDGrP8YE.js.map +1 -1
- package/dist/answer-DRaV2dVt.cjs.map +1 -1
- package/dist/chatbot.global.js +11 -11
- package/dist/chatbot.global.js.map +1 -1
- package/dist/components/ChatbotWidget.d.ts.map +1 -1
- package/dist/element.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/conversation.d.ts +5 -1
- package/dist/lib/conversation.d.ts.map +1 -1
- package/dist/lib/useChat.d.ts +6 -0
- package/dist/lib/useChat.d.ts.map +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +2 -2
- package/dist/react.js.map +1 -1
- package/dist/{src-BjqOavOO.js → src-BWDC0W4O.js} +456 -435
- package/dist/src-BWDC0W4O.js.map +1 -0
- package/dist/src-DvrmRR89.cjs +7 -0
- package/dist/src-DvrmRR89.cjs.map +1 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/widgets/extras-loader.d.ts +1 -1
- package/package.json +1 -1
- package/dist/src-BjqOavOO.js.map +0 -1
- package/dist/src-DS8P9HdZ.cjs +0 -7
- package/dist/src-DS8P9HdZ.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatbotWidget.d.ts","sourceRoot":"","sources":["../../src/components/ChatbotWidget.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAOjC,OAAO,KAAK,EAAkB,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAa5E,0EAA0E;AAC1E,MAAM,WAAW,eAAe;IAC9B,IAAI,IAAI,IAAI,CAAA;IACZ,KAAK,IAAI,IAAI,CAAA;I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pE"}
|
package/dist/element.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.tsx"],"names":[],"mappings":"AAkBA,eAAO,MAAM,QAAQ,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.tsx"],"names":[],"mappings":"AAkBA,eAAO,MAAM,QAAQ,qBAAqB,CAAA;AA2X1C;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,GAAE,MAAiB,GAAG,IAAI,CAM1D"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./answer-DRaV2dVt.cjs"),t=require("./src-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./answer-DRaV2dVt.cjs"),t=require("./src-DvrmRR89.cjs");exports.API_URL=t.r,exports.ChatHttpError=t.i,exports.DEFAULT_LANGUAGE=e._,exports.MAX_MESSAGE_LENGTH=t.a,exports.SUPPORTED_LANGUAGES=e.v,exports.TAG_NAME=t.t,exports.defineChatbot=t.n;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { _ as e, v as t } from "./answer-CDGrP8YE.js";
|
|
2
|
-
import { a as n, i as r, n as i, r as a, t as o } from "./src-
|
|
2
|
+
import { a as n, i as r, n as i, r as a, t as o } from "./src-BWDC0W4O.js";
|
|
3
3
|
export { a as API_URL, r as ChatHttpError, e as DEFAULT_LANGUAGE, n as MAX_MESSAGE_LENGTH, t as SUPPORTED_LANGUAGES, o as TAG_NAME, i as defineChatbot };
|
|
@@ -26,6 +26,9 @@ export interface StoredConversation {
|
|
|
26
26
|
embedKey: string;
|
|
27
27
|
/** Who the host said was in front of it, when it said anybody. */
|
|
28
28
|
user?: string;
|
|
29
|
+
/** The host's own partition of its users' conversations (an organization, a
|
|
30
|
+
* workspace), when it gave one. */
|
|
31
|
+
scope?: string;
|
|
29
32
|
}
|
|
30
33
|
/** The conversation this page was having, if it is still the same page's.
|
|
31
34
|
*
|
|
@@ -42,8 +45,9 @@ export declare function forgetConversation(): void;
|
|
|
42
45
|
* Checked here rather than at each call site so the two reasons to drop one stay
|
|
43
46
|
* together: it belongs to another application, or to another person.
|
|
44
47
|
*/
|
|
45
|
-
export declare function belongsTo(conversation: StoredConversation, { embedKey, user }: {
|
|
48
|
+
export declare function belongsTo(conversation: StoredConversation, { embedKey, user, scope }: {
|
|
46
49
|
embedKey: string;
|
|
47
50
|
user?: string;
|
|
51
|
+
scope?: string;
|
|
48
52
|
}): boolean;
|
|
49
53
|
//# sourceMappingURL=conversation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../src/lib/conversation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,gFAAgF;IAChF,QAAQ,EAAE,MAAM,CAAA;IAChB,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../src/lib/conversation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,gFAAgF;IAChF,QAAQ,EAAE,MAAM,CAAA;IAChB,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;wCACoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;oCAKoC;AACpC,wBAAgB,gBAAgB,IAAI,kBAAkB,GAAG,SAAS,CAkBjE;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAOxE;AAED,wBAAgB,kBAAkB,IAAI,IAAI,CAOzC;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,YAAY,EAAE,kBAAkB,EAChC,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7E,OAAO,CAIT"}
|
package/dist/lib/useChat.d.ts
CHANGED
|
@@ -9,6 +9,9 @@ export interface UseChatOptions {
|
|
|
9
9
|
embedKey?: string;
|
|
10
10
|
/** Who the host application has signed in, when it has anybody. */
|
|
11
11
|
user?: HostUser;
|
|
12
|
+
/** The host's partition of conversations (an organization, a workspace): a
|
|
13
|
+
* conversation opened under another scope is never replayed or continued. */
|
|
14
|
+
scope?: string;
|
|
12
15
|
/** Hands over the access token the host site holds for its signed-in user, asked
|
|
13
16
|
* before every message so it is always fresh. See `ChatbotProps`. */
|
|
14
17
|
getSubjectToken?: SubjectTokenSource;
|
|
@@ -31,6 +34,9 @@ export interface UseChatResult {
|
|
|
31
34
|
busy: boolean;
|
|
32
35
|
/** The conversation's id, as the server named it. Empty until it is opened. */
|
|
33
36
|
sessionId: string;
|
|
37
|
+
/** Counts the times the conversation was dropped, so a panel that stays open
|
|
38
|
+
* can tell it has to read what an empty panel draws again. */
|
|
39
|
+
resets: number;
|
|
34
40
|
/** The handles this application offers a visitor. Empty until an organization
|
|
35
41
|
* ticks one, which is the ordinary case. */
|
|
36
42
|
handles: AgentHandle[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../../src/lib/useChat.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EACV,WAAW,EAEX,cAAc,EACd,cAAc,EACd,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,eA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E,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAClD,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,yEAAyE;IACzE,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AA2BD,iEAAiE;AACjE,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,GAAG,YAAY,GAAG,QAAQ,CAAA;AA0ChG,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,aAAa,CA6jB9D"}
|
package/dist/react.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./src-
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./src-DvrmRR89.cjs");let t=require("react");var n={embedKey:`embed-key`,agent:`agent`,heading:`heading`,subheading:`subheading`,assistantName:`assistant-name`,placeholder:`placeholder`,greeting:`greeting`,width:`width`,accent:`accent`,theme:`theme`,position:`position`,layout:`layout`,locale:`locale`};function r(e,t){typeof e==`function`?e(t):e&&(e.current=t)}var i=(0,t.forwardRef)(function(i,a){let o=(0,t.useRef)(null),s=(0,t.useRef)(!1);(0,t.useEffect)(()=>{let t=o.current;if(t){e.n(),customElements.upgrade(t);for(let[e,r]of Object.entries(n)){let n=i[e];typeof n==`string`&&n?t.setAttribute(r,n):t.removeAttribute(r)}i.suggestions?.length?t.setAttribute(`suggestions`,JSON.stringify(i.suggestions)):t.removeAttribute(`suggestions`),i.persistOpen===!1?t.setAttribute(`persist-open`,`false`):t.removeAttribute(`persist-open`),i.showContext===!1?t.setAttribute(`show-context`,`false`):t.removeAttribute(`show-context`),t.context=i.context,t.user=i.user,t.scope=i.scope,t.getSubjectToken=i.getSubjectToken,s.current||(s.current=!0,e.o(i.defaultOpen,i.persistOpen)&&t.openChat())}});let{onOpen:c,onClose:l,onMessage:u,onError:d,onReset:f}=i;return(0,t.useEffect)(()=>{let e=o.current;if(!e)return;let t=Object.entries({"chatbot-open":c,"chatbot-close":l,"chatbot-message":u,"chatbot-error":d,"chatbot-reset":f}).filter(([,e])=>typeof e==`function`).map(([t,n])=>{let r=e=>{n?.(e.detail)};return e.addEventListener(t,r),()=>e.removeEventListener(t,r)});return()=>t.forEach(e=>e())},[c,l,u,d,f]),(0,t.createElement)(e.t,{ref:e=>{o.current=e,r(a,e)},class:i.className,style:i.style,id:i.id},i.launcherIcon==null?null:(0,t.createElement)(`span`,{slot:`launcher-icon`},i.launcherIcon))});exports.SquadicoChatbot=i,exports.TAG_NAME=e.t,exports.defineChatbot=e.n;
|
|
2
2
|
//# sourceMappingURL=react.cjs.map
|
package/dist/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.cjs","names":[],"sources":["../src/react.tsx"],"sourcesContent":["/**\n * React wrapper around `<squadico-chatbot>`.\n *\n * import { SquadicoChatbot } from '@squadico/chatbot/react'\n * <SquadicoChatbot context={{ order: { id: 'ORD-1', name: 'Order #1042' } }} onMessage={…} />\n *\n * This is not a second widget: it is a thin adapter (it renders nothing of its\n * own) around the custom element. It gives typed props, React callbacks instead\n * of `addEventListener`, and a `ref` on the imperative API.\n *\n * `react` is an **optional** peer dependency: this subpath is the only one\n * importing it, so a Vue or HTML host never has to install it.\n */\n'use client'\n\nimport { createElement, forwardRef, useEffect, useRef } from 'react'\nimport type { CSSProperties, ReactNode, Ref } from 'react'\nimport { defineChatbot, TAG_NAME } from './index'\nimport { initialOpen } from './lib/openState'\nimport type { ChatbotEventMap, ChatbotOptions, SquadicoChatbotElement } from './types'\n\nexport interface SquadicoChatbotProps extends ChatbotOptions {\n /**\n * Icon of the floating button, in place of the default spark — any React node\n * (`<BotIcon />`, an `<img>`, a font ligature).\n *\n * It is the only option that does not go through an attribute: the panel\n * renders inside a shadow root, where React cannot mount anything. The node is\n * therefore rendered as a child of the custom element, in the host's own tree\n * (where its CSS applies normally), then projected into the button by\n * `slot=\"launcher-icon\"`. It inherits the button's colour, so a\n * `stroke=\"currentColor\"` is enough; the frame is 26 px, and an icon sizing\n * itself in `1em` or `100%` fits it.\n */\n launcherIcon?: ReactNode\n onOpen?: (detail: ChatbotEventMap['chatbot-open']) => void\n onClose?: (detail: ChatbotEventMap['chatbot-close']) => void\n onMessage?: (detail: ChatbotEventMap['chatbot-message']) => void\n onError?: (detail: ChatbotEventMap['chatbot-error']) => void\n onReset?: (detail: ChatbotEventMap['chatbot-reset']) => void\n /** Set on the custom element — useful to override the `--sqc-*` variables. */\n className?: string\n style?: CSSProperties\n id?: string\n}\n\n/** Options driven by a plain string attribute. */\nconst STRING_ATTRS = {\n embedKey: 'embed-key',\n agent: 'agent',\n heading: 'heading',\n subheading: 'subheading',\n assistantName: 'assistant-name',\n placeholder: 'placeholder',\n greeting: 'greeting',\n width: 'width',\n accent: 'accent',\n theme: 'theme',\n position: 'position',\n layout: 'layout',\n locale: 'locale',\n} as const satisfies Partial<Record<keyof ChatbotOptions, string>>\n\nfunction assignRef(\n target: Ref<SquadicoChatbotElement | null> | undefined,\n node: SquadicoChatbotElement | null,\n): void {\n if (typeof target === 'function') target(node)\n else if (target) (target as { current: SquadicoChatbotElement | null }).current = node\n}\n\nexport const SquadicoChatbot = forwardRef<\n SquadicoChatbotElement | null,\n SquadicoChatbotProps\n>(function SquadicoChatbot(props, forwarded) {\n const host = useRef<SquadicoChatbotElement | null>(null)\n const mounted = useRef(false)\n\n /*\n * Nothing is passed to `createElement` besides `ref` / `class` / `style`:\n * depending on the React version, an unknown prop on a custom element is set\n * either as an attribute or as a property. Everything is therefore written\n * here, for identical behaviour from React 17 to 19.\n */\n useEffect(() => {\n const element = host.current\n if (!element) return\n\n // `defineChatbot()` already ran when `./index` was imported, but it is\n // called again for safety (it is idempotent), then the upgrade is forced: an\n // element created during hydration may not be upgraded yet, and a property\n // assignment would then shadow the class accessor.\n defineChatbot()\n customElements.upgrade(element)\n\n for (const [prop, attribute] of Object.entries(STRING_ATTRS)) {\n const value = props[prop as keyof typeof STRING_ATTRS]\n if (typeof value === 'string' && value) element.setAttribute(attribute, value)\n else element.removeAttribute(attribute)\n }\n\n if (props.suggestions?.length) {\n element.setAttribute('suggestions', JSON.stringify(props.suggestions))\n } else {\n element.removeAttribute('suggestions')\n }\n\n if (props.persistOpen === false) element.setAttribute('persist-open', 'false')\n else element.removeAttribute('persist-open')\n\n if (props.showContext === false) element.setAttribute('show-context', 'false')\n else element.removeAttribute('show-context')\n\n // Objects have no attribute representation: properties.\n element.context = props.context\n element.user = props.user\n element.getSubjectToken = props.getSubjectToken\n\n // `defaultOpen` is only honoured at mount: afterwards opening is driven\n // through the `ref` (`openChat()` / `closeChat()`), not by a render. It goes\n // through the same arbitration as the custom element — the element has\n // already restored the remembered panel when this effect runs, and an\n // `openChat()` on top would reopen what the user had just closed.\n if (!mounted.current) {\n mounted.current = true\n if (initialOpen(props.defaultOpen, props.persistOpen)) element.openChat()\n }\n })\n\n const { onOpen, onClose, onMessage, onError, onReset } = props\n useEffect(() => {\n const element = host.current\n if (!element) return\n\n const handlers: Partial<Record<keyof ChatbotEventMap, (detail: unknown) => void>> = {\n 'chatbot-open': onOpen as ((detail: unknown) => void) | undefined,\n 'chatbot-close': onClose as ((detail: unknown) => void) | undefined,\n 'chatbot-message': onMessage as ((detail: unknown) => void) | undefined,\n 'chatbot-error': onError as ((detail: unknown) => void) | undefined,\n 'chatbot-reset': onReset as ((detail: unknown) => void) | undefined,\n }\n\n const detachers = Object.entries(handlers)\n .filter(([, handler]) => typeof handler === 'function')\n .map(([name, handler]) => {\n const listener = (event: Event): void => {\n handler?.((event as CustomEvent<unknown>).detail)\n }\n element.addEventListener(name, listener)\n return () => element.removeEventListener(name, listener)\n })\n\n return () => detachers.forEach((detach) => detach())\n }, [onOpen, onClose, onMessage, onError, onReset])\n\n return createElement(\n TAG_NAME,\n {\n ref: (node: SquadicoChatbotElement | null) => {\n host.current = node\n assignRef(forwarded, node)\n },\n class: props.className,\n style: props.style,\n id: props.id,\n },\n // Wrapped rather than cloned with a `slot`: an icon component that does not\n // forward unknown props to its root element would never be projected, and a\n // child assigned to no slot is not rendered at all — the icon would vanish\n // without a word.\n props.launcherIcon == null\n ? null\n : createElement('span', { slot: 'launcher-icon' }, props.launcherIcon),\n )\n})\n\nexport { defineChatbot, TAG_NAME } from './index'\nexport type {\n AgentHandle,\n ApprovalDecision,\n ChatbotContext,\n ChatbotEvent,\n ChatbotEventMap,\n ChatbotEventName,\n ChatbotLayout,\n ChatbotOptions,\n ChatbotTheme,\n ChatMessage,\n ChatRole,\n ContextObject,\n ContextValue,\n HostUser,\n LauncherPosition,\n PendingApproval,\n SquadicoChatbotElement,\n} from './types'\n"],"mappings":"6IA+CA,IAAM,EAAe,CACnB,SAAU,YACV,MAAO,QACP,QAAS,UACT,WAAY,aACZ,cAAe,iBACf,YAAa,cACb,SAAU,WACV,MAAO,QACP,OAAQ,SACR,MAAO,QACP,SAAU,WACV,OAAQ,SACR,OAAQ,QACV,EAEA,SAAS,EACP,EACA,EACM,CACF,OAAO,GAAW,WAAY,EAAO,CAAI,EACpC,IAAQ,EAAuD,QAAU,EACpF,CAEA,IAAa,GAAA,EAAkB,EAAA,WAAA,CAG7B,SAAyB,EAAO,EAAW,CAC3C,IAAM,GAAA,EAAO,EAAA,OAAA,CAAsC,IAAI,EACjD,GAAA,EAAU,EAAA,OAAA,CAAO,EAAK,GAQ5B,EAAA,EAAA,UAAA,KAAgB,CACd,IAAM,EAAU,EAAK,QAChB,KAOL,CADA,EAAA,EAAc,EACd,eAAe,QAAQ,CAAO,EAE9B,IAAK,GAAM,CAAC,EAAM,KAAc,OAAO,QAAQ,CAAY,EAAG,CAC5D,IAAM,EAAQ,EAAM,GAChB,OAAO,GAAU,UAAY,EAAO,EAAQ,aAAa,EAAW,CAAK,EACxE,EAAQ,gBAAgB,CAAS,CACxC,CAEI,EAAM,aAAa,OACrB,EAAQ,aAAa,cAAe,KAAK,UAAU,EAAM,WAAW,CAAC,EAErE,EAAQ,gBAAgB,aAAa,EAGnC,EAAM,cAAgB,GAAO,EAAQ,aAAa,eAAgB,OAAO,EACxE,EAAQ,gBAAgB,cAAc,EAEvC,EAAM,cAAgB,GAAO,EAAQ,aAAa,eAAgB,OAAO,EACxE,EAAQ,gBAAgB,cAAc,EAG3C,EAAQ,QAAU,EAAM,QACxB,EAAQ,KAAO,EAAM,KACrB,EAAQ,gBAAkB,EAAM,gBAO3B,EAAQ,UACX,EAAQ,QAAU,GACd,EAAA,EAAY,EAAM,YAAa,EAAM,WAAW,GAAG,EAAQ,SAAS,
|
|
1
|
+
{"version":3,"file":"react.cjs","names":[],"sources":["../src/react.tsx"],"sourcesContent":["/**\n * React wrapper around `<squadico-chatbot>`.\n *\n * import { SquadicoChatbot } from '@squadico/chatbot/react'\n * <SquadicoChatbot context={{ order: { id: 'ORD-1', name: 'Order #1042' } }} onMessage={…} />\n *\n * This is not a second widget: it is a thin adapter (it renders nothing of its\n * own) around the custom element. It gives typed props, React callbacks instead\n * of `addEventListener`, and a `ref` on the imperative API.\n *\n * `react` is an **optional** peer dependency: this subpath is the only one\n * importing it, so a Vue or HTML host never has to install it.\n */\n'use client'\n\nimport { createElement, forwardRef, useEffect, useRef } from 'react'\nimport type { CSSProperties, ReactNode, Ref } from 'react'\nimport { defineChatbot, TAG_NAME } from './index'\nimport { initialOpen } from './lib/openState'\nimport type { ChatbotEventMap, ChatbotOptions, SquadicoChatbotElement } from './types'\n\nexport interface SquadicoChatbotProps extends ChatbotOptions {\n /**\n * Icon of the floating button, in place of the default spark — any React node\n * (`<BotIcon />`, an `<img>`, a font ligature).\n *\n * It is the only option that does not go through an attribute: the panel\n * renders inside a shadow root, where React cannot mount anything. The node is\n * therefore rendered as a child of the custom element, in the host's own tree\n * (where its CSS applies normally), then projected into the button by\n * `slot=\"launcher-icon\"`. It inherits the button's colour, so a\n * `stroke=\"currentColor\"` is enough; the frame is 26 px, and an icon sizing\n * itself in `1em` or `100%` fits it.\n */\n launcherIcon?: ReactNode\n onOpen?: (detail: ChatbotEventMap['chatbot-open']) => void\n onClose?: (detail: ChatbotEventMap['chatbot-close']) => void\n onMessage?: (detail: ChatbotEventMap['chatbot-message']) => void\n onError?: (detail: ChatbotEventMap['chatbot-error']) => void\n onReset?: (detail: ChatbotEventMap['chatbot-reset']) => void\n /** Set on the custom element — useful to override the `--sqc-*` variables. */\n className?: string\n style?: CSSProperties\n id?: string\n}\n\n/** Options driven by a plain string attribute. */\nconst STRING_ATTRS = {\n embedKey: 'embed-key',\n agent: 'agent',\n heading: 'heading',\n subheading: 'subheading',\n assistantName: 'assistant-name',\n placeholder: 'placeholder',\n greeting: 'greeting',\n width: 'width',\n accent: 'accent',\n theme: 'theme',\n position: 'position',\n layout: 'layout',\n locale: 'locale',\n} as const satisfies Partial<Record<keyof ChatbotOptions, string>>\n\nfunction assignRef(\n target: Ref<SquadicoChatbotElement | null> | undefined,\n node: SquadicoChatbotElement | null,\n): void {\n if (typeof target === 'function') target(node)\n else if (target) (target as { current: SquadicoChatbotElement | null }).current = node\n}\n\nexport const SquadicoChatbot = forwardRef<\n SquadicoChatbotElement | null,\n SquadicoChatbotProps\n>(function SquadicoChatbot(props, forwarded) {\n const host = useRef<SquadicoChatbotElement | null>(null)\n const mounted = useRef(false)\n\n /*\n * Nothing is passed to `createElement` besides `ref` / `class` / `style`:\n * depending on the React version, an unknown prop on a custom element is set\n * either as an attribute or as a property. Everything is therefore written\n * here, for identical behaviour from React 17 to 19.\n */\n useEffect(() => {\n const element = host.current\n if (!element) return\n\n // `defineChatbot()` already ran when `./index` was imported, but it is\n // called again for safety (it is idempotent), then the upgrade is forced: an\n // element created during hydration may not be upgraded yet, and a property\n // assignment would then shadow the class accessor.\n defineChatbot()\n customElements.upgrade(element)\n\n for (const [prop, attribute] of Object.entries(STRING_ATTRS)) {\n const value = props[prop as keyof typeof STRING_ATTRS]\n if (typeof value === 'string' && value) element.setAttribute(attribute, value)\n else element.removeAttribute(attribute)\n }\n\n if (props.suggestions?.length) {\n element.setAttribute('suggestions', JSON.stringify(props.suggestions))\n } else {\n element.removeAttribute('suggestions')\n }\n\n if (props.persistOpen === false) element.setAttribute('persist-open', 'false')\n else element.removeAttribute('persist-open')\n\n if (props.showContext === false) element.setAttribute('show-context', 'false')\n else element.removeAttribute('show-context')\n\n // Objects have no attribute representation: properties.\n element.context = props.context\n element.user = props.user\n element.scope = props.scope\n element.getSubjectToken = props.getSubjectToken\n\n // `defaultOpen` is only honoured at mount: afterwards opening is driven\n // through the `ref` (`openChat()` / `closeChat()`), not by a render. It goes\n // through the same arbitration as the custom element — the element has\n // already restored the remembered panel when this effect runs, and an\n // `openChat()` on top would reopen what the user had just closed.\n if (!mounted.current) {\n mounted.current = true\n if (initialOpen(props.defaultOpen, props.persistOpen)) element.openChat()\n }\n })\n\n const { onOpen, onClose, onMessage, onError, onReset } = props\n useEffect(() => {\n const element = host.current\n if (!element) return\n\n const handlers: Partial<Record<keyof ChatbotEventMap, (detail: unknown) => void>> = {\n 'chatbot-open': onOpen as ((detail: unknown) => void) | undefined,\n 'chatbot-close': onClose as ((detail: unknown) => void) | undefined,\n 'chatbot-message': onMessage as ((detail: unknown) => void) | undefined,\n 'chatbot-error': onError as ((detail: unknown) => void) | undefined,\n 'chatbot-reset': onReset as ((detail: unknown) => void) | undefined,\n }\n\n const detachers = Object.entries(handlers)\n .filter(([, handler]) => typeof handler === 'function')\n .map(([name, handler]) => {\n const listener = (event: Event): void => {\n handler?.((event as CustomEvent<unknown>).detail)\n }\n element.addEventListener(name, listener)\n return () => element.removeEventListener(name, listener)\n })\n\n return () => detachers.forEach((detach) => detach())\n }, [onOpen, onClose, onMessage, onError, onReset])\n\n return createElement(\n TAG_NAME,\n {\n ref: (node: SquadicoChatbotElement | null) => {\n host.current = node\n assignRef(forwarded, node)\n },\n class: props.className,\n style: props.style,\n id: props.id,\n },\n // Wrapped rather than cloned with a `slot`: an icon component that does not\n // forward unknown props to its root element would never be projected, and a\n // child assigned to no slot is not rendered at all — the icon would vanish\n // without a word.\n props.launcherIcon == null\n ? null\n : createElement('span', { slot: 'launcher-icon' }, props.launcherIcon),\n )\n})\n\nexport { defineChatbot, TAG_NAME } from './index'\nexport type {\n AgentHandle,\n ApprovalDecision,\n ChatbotContext,\n ChatbotEvent,\n ChatbotEventMap,\n ChatbotEventName,\n ChatbotLayout,\n ChatbotOptions,\n ChatbotTheme,\n ChatMessage,\n ChatRole,\n ContextObject,\n ContextValue,\n HostUser,\n LauncherPosition,\n PendingApproval,\n SquadicoChatbotElement,\n} from './types'\n"],"mappings":"6IA+CA,IAAM,EAAe,CACnB,SAAU,YACV,MAAO,QACP,QAAS,UACT,WAAY,aACZ,cAAe,iBACf,YAAa,cACb,SAAU,WACV,MAAO,QACP,OAAQ,SACR,MAAO,QACP,SAAU,WACV,OAAQ,SACR,OAAQ,QACV,EAEA,SAAS,EACP,EACA,EACM,CACF,OAAO,GAAW,WAAY,EAAO,CAAI,EACpC,IAAQ,EAAuD,QAAU,EACpF,CAEA,IAAa,GAAA,EAAkB,EAAA,WAAA,CAG7B,SAAyB,EAAO,EAAW,CAC3C,IAAM,GAAA,EAAO,EAAA,OAAA,CAAsC,IAAI,EACjD,GAAA,EAAU,EAAA,OAAA,CAAO,EAAK,GAQ5B,EAAA,EAAA,UAAA,KAAgB,CACd,IAAM,EAAU,EAAK,QAChB,KAOL,CADA,EAAA,EAAc,EACd,eAAe,QAAQ,CAAO,EAE9B,IAAK,GAAM,CAAC,EAAM,KAAc,OAAO,QAAQ,CAAY,EAAG,CAC5D,IAAM,EAAQ,EAAM,GAChB,OAAO,GAAU,UAAY,EAAO,EAAQ,aAAa,EAAW,CAAK,EACxE,EAAQ,gBAAgB,CAAS,CACxC,CAEI,EAAM,aAAa,OACrB,EAAQ,aAAa,cAAe,KAAK,UAAU,EAAM,WAAW,CAAC,EAErE,EAAQ,gBAAgB,aAAa,EAGnC,EAAM,cAAgB,GAAO,EAAQ,aAAa,eAAgB,OAAO,EACxE,EAAQ,gBAA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{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAO,MAAM,OAAO,CAAA;AAG1D,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAEtF,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D;;;;;;;;;;;OAWG;IACH,YAAY,CAAC,EAAE,SAAS,CAAA;IACxB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,cAAc,CAAC,KAAK,IAAI,CAAA;IAC1D,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,eAAe,CAAC,KAAK,IAAI,CAAA;IAC5D,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAA;IAChE,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,eAAe,CAAC,KAAK,IAAI,CAAA;IAC5D,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,eAAe,CAAC,KAAK,IAAI,CAAA;IAC5D,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AA2BD,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAO,MAAM,OAAO,CAAA;AAG1D,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAEtF,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D;;;;;;;;;;;OAWG;IACH,YAAY,CAAC,EAAE,SAAS,CAAA;IACxB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,cAAc,CAAC,KAAK,IAAI,CAAA;IAC1D,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,eAAe,CAAC,KAAK,IAAI,CAAA;IAC5D,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAA;IAChE,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,eAAe,CAAC,KAAK,IAAI,CAAA;IAC5D,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,eAAe,CAAC,KAAK,IAAI,CAAA;IAC5D,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AA2BD,eAAO,MAAM,eAAe,gIAwG1B,CAAA;AAEF,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACjD,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,sBAAsB,GACvB,MAAM,SAAS,CAAA"}
|
package/dist/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { n as e, o as t, t as n } from "./src-
|
|
2
|
+
import { n as e, o as t, t as n } from "./src-BWDC0W4O.js";
|
|
3
3
|
import { createElement as r, forwardRef as i, useEffect as a, useRef as o } from "react";
|
|
4
4
|
//#region src/react.tsx
|
|
5
5
|
var s = {
|
|
@@ -30,7 +30,7 @@ var l = i(function(i, l) {
|
|
|
30
30
|
let r = i[e];
|
|
31
31
|
typeof r == "string" && r ? n.setAttribute(t, r) : n.removeAttribute(t);
|
|
32
32
|
}
|
|
33
|
-
i.suggestions?.length ? n.setAttribute("suggestions", JSON.stringify(i.suggestions)) : n.removeAttribute("suggestions"), i.persistOpen === !1 ? n.setAttribute("persist-open", "false") : n.removeAttribute("persist-open"), i.showContext === !1 ? n.setAttribute("show-context", "false") : n.removeAttribute("show-context"), n.context = i.context, n.user = i.user, n.getSubjectToken = i.getSubjectToken, d.current || (d.current = !0, t(i.defaultOpen, i.persistOpen) && n.openChat());
|
|
33
|
+
i.suggestions?.length ? n.setAttribute("suggestions", JSON.stringify(i.suggestions)) : n.removeAttribute("suggestions"), i.persistOpen === !1 ? n.setAttribute("persist-open", "false") : n.removeAttribute("persist-open"), i.showContext === !1 ? n.setAttribute("show-context", "false") : n.removeAttribute("show-context"), n.context = i.context, n.user = i.user, n.scope = i.scope, n.getSubjectToken = i.getSubjectToken, d.current || (d.current = !0, t(i.defaultOpen, i.persistOpen) && n.openChat());
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
let { onOpen: f, onClose: p, onMessage: m, onError: h, onReset: g } = i;
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","names":[],"sources":["../src/react.tsx"],"sourcesContent":["/**\n * React wrapper around `<squadico-chatbot>`.\n *\n * import { SquadicoChatbot } from '@squadico/chatbot/react'\n * <SquadicoChatbot context={{ order: { id: 'ORD-1', name: 'Order #1042' } }} onMessage={…} />\n *\n * This is not a second widget: it is a thin adapter (it renders nothing of its\n * own) around the custom element. It gives typed props, React callbacks instead\n * of `addEventListener`, and a `ref` on the imperative API.\n *\n * `react` is an **optional** peer dependency: this subpath is the only one\n * importing it, so a Vue or HTML host never has to install it.\n */\n'use client'\n\nimport { createElement, forwardRef, useEffect, useRef } from 'react'\nimport type { CSSProperties, ReactNode, Ref } from 'react'\nimport { defineChatbot, TAG_NAME } from './index'\nimport { initialOpen } from './lib/openState'\nimport type { ChatbotEventMap, ChatbotOptions, SquadicoChatbotElement } from './types'\n\nexport interface SquadicoChatbotProps extends ChatbotOptions {\n /**\n * Icon of the floating button, in place of the default spark — any React node\n * (`<BotIcon />`, an `<img>`, a font ligature).\n *\n * It is the only option that does not go through an attribute: the panel\n * renders inside a shadow root, where React cannot mount anything. The node is\n * therefore rendered as a child of the custom element, in the host's own tree\n * (where its CSS applies normally), then projected into the button by\n * `slot=\"launcher-icon\"`. It inherits the button's colour, so a\n * `stroke=\"currentColor\"` is enough; the frame is 26 px, and an icon sizing\n * itself in `1em` or `100%` fits it.\n */\n launcherIcon?: ReactNode\n onOpen?: (detail: ChatbotEventMap['chatbot-open']) => void\n onClose?: (detail: ChatbotEventMap['chatbot-close']) => void\n onMessage?: (detail: ChatbotEventMap['chatbot-message']) => void\n onError?: (detail: ChatbotEventMap['chatbot-error']) => void\n onReset?: (detail: ChatbotEventMap['chatbot-reset']) => void\n /** Set on the custom element — useful to override the `--sqc-*` variables. */\n className?: string\n style?: CSSProperties\n id?: string\n}\n\n/** Options driven by a plain string attribute. */\nconst STRING_ATTRS = {\n embedKey: 'embed-key',\n agent: 'agent',\n heading: 'heading',\n subheading: 'subheading',\n assistantName: 'assistant-name',\n placeholder: 'placeholder',\n greeting: 'greeting',\n width: 'width',\n accent: 'accent',\n theme: 'theme',\n position: 'position',\n layout: 'layout',\n locale: 'locale',\n} as const satisfies Partial<Record<keyof ChatbotOptions, string>>\n\nfunction assignRef(\n target: Ref<SquadicoChatbotElement | null> | undefined,\n node: SquadicoChatbotElement | null,\n): void {\n if (typeof target === 'function') target(node)\n else if (target) (target as { current: SquadicoChatbotElement | null }).current = node\n}\n\nexport const SquadicoChatbot = forwardRef<\n SquadicoChatbotElement | null,\n SquadicoChatbotProps\n>(function SquadicoChatbot(props, forwarded) {\n const host = useRef<SquadicoChatbotElement | null>(null)\n const mounted = useRef(false)\n\n /*\n * Nothing is passed to `createElement` besides `ref` / `class` / `style`:\n * depending on the React version, an unknown prop on a custom element is set\n * either as an attribute or as a property. Everything is therefore written\n * here, for identical behaviour from React 17 to 19.\n */\n useEffect(() => {\n const element = host.current\n if (!element) return\n\n // `defineChatbot()` already ran when `./index` was imported, but it is\n // called again for safety (it is idempotent), then the upgrade is forced: an\n // element created during hydration may not be upgraded yet, and a property\n // assignment would then shadow the class accessor.\n defineChatbot()\n customElements.upgrade(element)\n\n for (const [prop, attribute] of Object.entries(STRING_ATTRS)) {\n const value = props[prop as keyof typeof STRING_ATTRS]\n if (typeof value === 'string' && value) element.setAttribute(attribute, value)\n else element.removeAttribute(attribute)\n }\n\n if (props.suggestions?.length) {\n element.setAttribute('suggestions', JSON.stringify(props.suggestions))\n } else {\n element.removeAttribute('suggestions')\n }\n\n if (props.persistOpen === false) element.setAttribute('persist-open', 'false')\n else element.removeAttribute('persist-open')\n\n if (props.showContext === false) element.setAttribute('show-context', 'false')\n else element.removeAttribute('show-context')\n\n // Objects have no attribute representation: properties.\n element.context = props.context\n element.user = props.user\n element.getSubjectToken = props.getSubjectToken\n\n // `defaultOpen` is only honoured at mount: afterwards opening is driven\n // through the `ref` (`openChat()` / `closeChat()`), not by a render. It goes\n // through the same arbitration as the custom element — the element has\n // already restored the remembered panel when this effect runs, and an\n // `openChat()` on top would reopen what the user had just closed.\n if (!mounted.current) {\n mounted.current = true\n if (initialOpen(props.defaultOpen, props.persistOpen)) element.openChat()\n }\n })\n\n const { onOpen, onClose, onMessage, onError, onReset } = props\n useEffect(() => {\n const element = host.current\n if (!element) return\n\n const handlers: Partial<Record<keyof ChatbotEventMap, (detail: unknown) => void>> = {\n 'chatbot-open': onOpen as ((detail: unknown) => void) | undefined,\n 'chatbot-close': onClose as ((detail: unknown) => void) | undefined,\n 'chatbot-message': onMessage as ((detail: unknown) => void) | undefined,\n 'chatbot-error': onError as ((detail: unknown) => void) | undefined,\n 'chatbot-reset': onReset as ((detail: unknown) => void) | undefined,\n }\n\n const detachers = Object.entries(handlers)\n .filter(([, handler]) => typeof handler === 'function')\n .map(([name, handler]) => {\n const listener = (event: Event): void => {\n handler?.((event as CustomEvent<unknown>).detail)\n }\n element.addEventListener(name, listener)\n return () => element.removeEventListener(name, listener)\n })\n\n return () => detachers.forEach((detach) => detach())\n }, [onOpen, onClose, onMessage, onError, onReset])\n\n return createElement(\n TAG_NAME,\n {\n ref: (node: SquadicoChatbotElement | null) => {\n host.current = node\n assignRef(forwarded, node)\n },\n class: props.className,\n style: props.style,\n id: props.id,\n },\n // Wrapped rather than cloned with a `slot`: an icon component that does not\n // forward unknown props to its root element would never be projected, and a\n // child assigned to no slot is not rendered at all — the icon would vanish\n // without a word.\n props.launcherIcon == null\n ? null\n : createElement('span', { slot: 'launcher-icon' }, props.launcherIcon),\n )\n})\n\nexport { defineChatbot, TAG_NAME } from './index'\nexport type {\n AgentHandle,\n ApprovalDecision,\n ChatbotContext,\n ChatbotEvent,\n ChatbotEventMap,\n ChatbotEventName,\n ChatbotLayout,\n ChatbotOptions,\n ChatbotTheme,\n ChatMessage,\n ChatRole,\n ContextObject,\n ContextValue,\n HostUser,\n LauncherPosition,\n PendingApproval,\n SquadicoChatbotElement,\n} from './types'\n"],"mappings":";;;;AA+CA,IAAM,IAAe;CACnB,UAAU;CACV,OAAO;CACP,SAAS;CACT,YAAY;CACZ,eAAe;CACf,aAAa;CACb,UAAU;CACV,OAAO;CACP,QAAQ;CACR,OAAO;CACP,UAAU;CACV,QAAQ;CACR,QAAQ;AACV;AAEA,SAAS,EACP,GACA,GACM;CACN,AAAI,OAAO,KAAW,aAAY,EAAO,CAAI,IACpC,MAAQ,EAAuD,UAAU;AACpF;AAEA,IAAa,IAAkB,EAG7B,SAAyB,GAAO,GAAW;CAC3C,IAAM,IAAO,EAAsC,IAAI,GACjD,IAAU,EAAO,EAAK;CAQ5B,QAAgB;EACd,IAAM,IAAU,EAAK;EAChB,OAOL;GADA,EAAc,GACd,eAAe,QAAQ,CAAO;GAE9B,KAAK,IAAM,CAAC,GAAM,MAAc,OAAO,QAAQ,CAAY,GAAG;IAC5D,IAAM,IAAQ,EAAM;IACpB,AAAI,OAAO,KAAU,YAAY,IAAO,EAAQ,aAAa,GAAW,CAAK,IACxE,EAAQ,gBAAgB,CAAS;GACxC;
|
|
1
|
+
{"version":3,"file":"react.js","names":[],"sources":["../src/react.tsx"],"sourcesContent":["/**\n * React wrapper around `<squadico-chatbot>`.\n *\n * import { SquadicoChatbot } from '@squadico/chatbot/react'\n * <SquadicoChatbot context={{ order: { id: 'ORD-1', name: 'Order #1042' } }} onMessage={…} />\n *\n * This is not a second widget: it is a thin adapter (it renders nothing of its\n * own) around the custom element. It gives typed props, React callbacks instead\n * of `addEventListener`, and a `ref` on the imperative API.\n *\n * `react` is an **optional** peer dependency: this subpath is the only one\n * importing it, so a Vue or HTML host never has to install it.\n */\n'use client'\n\nimport { createElement, forwardRef, useEffect, useRef } from 'react'\nimport type { CSSProperties, ReactNode, Ref } from 'react'\nimport { defineChatbot, TAG_NAME } from './index'\nimport { initialOpen } from './lib/openState'\nimport type { ChatbotEventMap, ChatbotOptions, SquadicoChatbotElement } from './types'\n\nexport interface SquadicoChatbotProps extends ChatbotOptions {\n /**\n * Icon of the floating button, in place of the default spark — any React node\n * (`<BotIcon />`, an `<img>`, a font ligature).\n *\n * It is the only option that does not go through an attribute: the panel\n * renders inside a shadow root, where React cannot mount anything. The node is\n * therefore rendered as a child of the custom element, in the host's own tree\n * (where its CSS applies normally), then projected into the button by\n * `slot=\"launcher-icon\"`. It inherits the button's colour, so a\n * `stroke=\"currentColor\"` is enough; the frame is 26 px, and an icon sizing\n * itself in `1em` or `100%` fits it.\n */\n launcherIcon?: ReactNode\n onOpen?: (detail: ChatbotEventMap['chatbot-open']) => void\n onClose?: (detail: ChatbotEventMap['chatbot-close']) => void\n onMessage?: (detail: ChatbotEventMap['chatbot-message']) => void\n onError?: (detail: ChatbotEventMap['chatbot-error']) => void\n onReset?: (detail: ChatbotEventMap['chatbot-reset']) => void\n /** Set on the custom element — useful to override the `--sqc-*` variables. */\n className?: string\n style?: CSSProperties\n id?: string\n}\n\n/** Options driven by a plain string attribute. */\nconst STRING_ATTRS = {\n embedKey: 'embed-key',\n agent: 'agent',\n heading: 'heading',\n subheading: 'subheading',\n assistantName: 'assistant-name',\n placeholder: 'placeholder',\n greeting: 'greeting',\n width: 'width',\n accent: 'accent',\n theme: 'theme',\n position: 'position',\n layout: 'layout',\n locale: 'locale',\n} as const satisfies Partial<Record<keyof ChatbotOptions, string>>\n\nfunction assignRef(\n target: Ref<SquadicoChatbotElement | null> | undefined,\n node: SquadicoChatbotElement | null,\n): void {\n if (typeof target === 'function') target(node)\n else if (target) (target as { current: SquadicoChatbotElement | null }).current = node\n}\n\nexport const SquadicoChatbot = forwardRef<\n SquadicoChatbotElement | null,\n SquadicoChatbotProps\n>(function SquadicoChatbot(props, forwarded) {\n const host = useRef<SquadicoChatbotElement | null>(null)\n const mounted = useRef(false)\n\n /*\n * Nothing is passed to `createElement` besides `ref` / `class` / `style`:\n * depending on the React version, an unknown prop on a custom element is set\n * either as an attribute or as a property. Everything is therefore written\n * here, for identical behaviour from React 17 to 19.\n */\n useEffect(() => {\n const element = host.current\n if (!element) return\n\n // `defineChatbot()` already ran when `./index` was imported, but it is\n // called again for safety (it is idempotent), then the upgrade is forced: an\n // element created during hydration may not be upgraded yet, and a property\n // assignment would then shadow the class accessor.\n defineChatbot()\n customElements.upgrade(element)\n\n for (const [prop, attribute] of Object.entries(STRING_ATTRS)) {\n const value = props[prop as keyof typeof STRING_ATTRS]\n if (typeof value === 'string' && value) element.setAttribute(attribute, value)\n else element.removeAttribute(attribute)\n }\n\n if (props.suggestions?.length) {\n element.setAttribute('suggestions', JSON.stringify(props.suggestions))\n } else {\n element.removeAttribute('suggestions')\n }\n\n if (props.persistOpen === false) element.setAttribute('persist-open', 'false')\n else element.removeAttribute('persist-open')\n\n if (props.showContext === false) element.setAttribute('show-context', 'false')\n else element.removeAttribute('show-context')\n\n // Objects have no attribute representation: properties.\n element.context = props.context\n element.user = props.user\n element.scope = props.scope\n element.getSubjectToken = props.getSubjectToken\n\n // `defaultOpen` is only honoured at mount: afterwards opening is driven\n // through the `ref` (`openChat()` / `closeChat()`), not by a render. It goes\n // through the same arbitration as the custom element — the element has\n // already restored the remembered panel when this effect runs, and an\n // `openChat()` on top would reopen what the user had just closed.\n if (!mounted.current) {\n mounted.current = true\n if (initialOpen(props.defaultOpen, props.persistOpen)) element.openChat()\n }\n })\n\n const { onOpen, onClose, onMessage, onError, onReset } = props\n useEffect(() => {\n const element = host.current\n if (!element) return\n\n const handlers: Partial<Record<keyof ChatbotEventMap, (detail: unknown) => void>> = {\n 'chatbot-open': onOpen as ((detail: unknown) => void) | undefined,\n 'chatbot-close': onClose as ((detail: unknown) => void) | undefined,\n 'chatbot-message': onMessage as ((detail: unknown) => void) | undefined,\n 'chatbot-error': onError as ((detail: unknown) => void) | undefined,\n 'chatbot-reset': onReset as ((detail: unknown) => void) | undefined,\n }\n\n const detachers = Object.entries(handlers)\n .filter(([, handler]) => typeof handler === 'function')\n .map(([name, handler]) => {\n const listener = (event: Event): void => {\n handler?.((event as CustomEvent<unknown>).detail)\n }\n element.addEventListener(name, listener)\n return () => element.removeEventListener(name, listener)\n })\n\n return () => detachers.forEach((detach) => detach())\n }, [onOpen, onClose, onMessage, onError, onReset])\n\n return createElement(\n TAG_NAME,\n {\n ref: (node: SquadicoChatbotElement | null) => {\n host.current = node\n assignRef(forwarded, node)\n },\n class: props.className,\n style: props.style,\n id: props.id,\n },\n // Wrapped rather than cloned with a `slot`: an icon component that does not\n // forward unknown props to its root element would never be projected, and a\n // child assigned to no slot is not rendered at all — the icon would vanish\n // without a word.\n props.launcherIcon == null\n ? null\n : createElement('span', { slot: 'launcher-icon' }, props.launcherIcon),\n )\n})\n\nexport { defineChatbot, TAG_NAME } from './index'\nexport type {\n AgentHandle,\n ApprovalDecision,\n ChatbotContext,\n ChatbotEvent,\n ChatbotEventMap,\n ChatbotEventName,\n ChatbotLayout,\n ChatbotOptions,\n ChatbotTheme,\n ChatMessage,\n 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