@squadico/chatbot 1.0.0 → 1.1.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.
@@ -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;AAMjC,OAAO,KAAK,EAAkB,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAW5E,0EAA0E;AAC1E,MAAM,WAAW,eAAe;IAC9B,IAAI,IAAI,IAAI,CAAA;IACZ,KAAK,IAAI,IAAI,CAAA;IACb,MAAM,IAAI,IAAI,CAAA;IACd,KAAK,IAAI,IAAI,CAAA;IACb,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,MAAM,IAAI,OAAO,CAAA;IACjB,SAAS,IAAI,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;IACvC,+DAA+D;IAC/D,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,KAAK,IAAI,CAAA;CAClD;AAkED,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAgSpE"}
1
+ {"version":3,"file":"ChatbotWidget.d.ts","sourceRoot":"","sources":["../../src/components/ChatbotWidget.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAMjC,OAAO,KAAK,EAAkB,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAW5E,0EAA0E;AAC1E,MAAM,WAAW,eAAe;IAC9B,IAAI,IAAI,IAAI,CAAA;IACZ,KAAK,IAAI,IAAI,CAAA;IACb,MAAM,IAAI,IAAI,CAAA;IACd,KAAK,IAAI,IAAI,CAAA;IACb,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,MAAM,IAAI,OAAO,CAAA;IACjB,SAAS,IAAI,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;IACvC,+DAA+D;IAC/D,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,KAAK,IAAI,CAAA;CAClD;AAkED,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAkSpE"}
@@ -1 +1 @@
1
- {"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.tsx"],"names":[],"mappings":"AAYA,eAAO,MAAM,QAAQ,qBAAqB,CAAA;AAsU1C;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,GAAE,MAAiB,GAAG,IAAI,CAM1D"}
1
+ {"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.tsx"],"names":[],"mappings":"AAkBA,eAAO,MAAM,QAAQ,qBAAqB,CAAA;AAyV1C;;;;;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("./src-DvRdkFTu.cjs");exports.API_URL=e.r,exports.ChatHttpError=e.i,exports.DEFAULT_LANGUAGE=e.s,exports.MAX_MESSAGE_LENGTH=e.a,exports.SUPPORTED_LANGUAGES=e.c,exports.TAG_NAME=e.t,exports.defineChatbot=e.n;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./src-wGegp_8B.cjs");exports.API_URL=e.r,exports.ChatHttpError=e.i,exports.DEFAULT_LANGUAGE=e.s,exports.MAX_MESSAGE_LENGTH=e.a,exports.SUPPORTED_LANGUAGES=e.c,exports.TAG_NAME=e.t,exports.defineChatbot=e.n;
package/dist/index.d.ts CHANGED
@@ -11,5 +11,5 @@
11
11
  export { defineChatbot, TAG_NAME } from './element';
12
12
  export { DEFAULT_LANGUAGE, SUPPORTED_LANGUAGES, type LanguageCode } from './lib/i18n';
13
13
  export { API_URL, ChatHttpError, MAX_MESSAGE_LENGTH } from './lib/client';
14
- export type { AgentHandle, ApprovalDecision, ChatbotContext, ChatbotEvent, ChatbotEventMap, ChatbotEventName, ChatbotOptions, ChatbotTheme, ChatMessage, ChatRole, ContextObject, ContextValue, HostUser, LauncherPosition, PendingApproval, SquadicoChatbotElement, } from './types';
14
+ export type { AgentHandle, ApprovalDecision, ChatbotContext, ChatbotEvent, ChatbotEventMap, ChatbotEventName, ChatbotLayout, ChatbotOptions, ChatbotTheme, ChatMessage, ChatRole, ContextObject, ContextValue, HostUser, LauncherPosition, PendingApproval, SquadicoChatbotElement, SubjectTokenSource, } from './types';
15
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AACrF,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACzE,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,sBAAsB,GACvB,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AACrF,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACzE,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,EACtB,kBAAkB,GACnB,MAAM,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e, c as t, i as n, n as r, r as i, s as a, t as o } from "./src-CN1vDssu.js";
1
+ import { a as e, c as t, i as n, n as r, r as i, s as a, t as o } from "./src-D4ZbNlbK.js";
2
2
  export { i as API_URL, n as ChatHttpError, a as DEFAULT_LANGUAGE, e as MAX_MESSAGE_LENGTH, t as SUPPORTED_LANGUAGES, o as TAG_NAME, r as defineChatbot };
package/dist/jsx.d.ts CHANGED
@@ -33,6 +33,8 @@ export interface SquadicoChatbotAttributes {
33
33
  accent?: string;
34
34
  theme?: 'light' | 'dark' | 'auto';
35
35
  position?: 'bottom-right' | 'bottom-left';
36
+ /** `sidebar` (default) or `floating`: a window in the launcher's corner. */
37
+ layout?: 'sidebar' | 'floating';
36
38
  /** Presence = open. `open="false"` closes it. */
37
39
  open?: string | boolean;
38
40
  /** `persist-open="false"`: the panel starts from `open` on every mount. */
package/dist/jsx.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../src/jsx.ts"],"names":[],"mappings":"AAAA;;;;;;;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AAQ,OAAO,CAAC;IAErB,UAAU,GAAG,CAAC;QACZ,UAAU,iBAAiB;YACzB,kBAAkB,EAAE,yBAAyB,CAAA;SAC9C;KACF;CACF"}
@@ -112,6 +112,9 @@ export interface SendMessageInit {
112
112
  /** What the page knows about where the visitor is. Sent as data, never as
113
113
  * instructions — see `ChatbotContext`. */
114
114
  context?: Record<string, unknown>;
115
+ /** The access token the host site holds for its signed-in user — see
116
+ * `getSubjectToken` on the props. */
117
+ subjectToken?: string;
115
118
  onToken: (token: string) => void;
116
119
  signal?: AbortSignal;
117
120
  }
@@ -124,6 +127,7 @@ export interface ResolveApprovalInit {
124
127
  * wrong thing. */
125
128
  toolCallId: string;
126
129
  approved: boolean;
130
+ subjectToken?: string;
127
131
  onToken: (token: string) => void;
128
132
  signal?: AbortSignal;
129
133
  }
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/lib/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,WAAW,EAEX,eAAe,EAChB,MAAM,UAAU,CAAA;AAGjB;kFACkF;AAClF,eAAO,MAAM,OAAO,EAAE,MAA6B,CAAA;AAEnD;sFACsF;AACtF,eAAO,MAAM,kBAAkB,QAAS,CAAA;AAExC,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB;;;;;oCAKgC;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;gBAEV,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAM5D;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;oFAEgF;IAChF,MAAM,CAAC,EAAE,MAAM,CAAA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ED,gEAAgE;AAChE,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,cAAc,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,GAC9C,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,cAAc,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,GAC9C,OAAO,CAAC,IAAI,CAAC,CAOf;AASD,kEAAkE;AAClE,wBAAsB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAc1E;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAMlF"}
@@ -1,4 +1,4 @@
1
- import type { AgentHandle, ChatAttachment, ChatbotContext, ChatbotEvent, ChatMessage, HostUser, PendingApproval } from '../types';
1
+ import type { AgentHandle, ChatAttachment, ChatbotContext, ChatbotEvent, ChatMessage, HostUser, PendingApproval, SubjectTokenSource } from '../types';
2
2
  import { type Locale } from './i18n';
3
3
  export interface UseChatOptions {
4
4
  /** Where the calls go. Not reachable from the element or the React wrapper:
@@ -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
+ /** Hands over the access token the host site holds for its signed-in user, asked
13
+ * before every message so it is always fresh. See `ChatbotProps`. */
14
+ getSubjectToken?: SubjectTokenSource;
12
15
  /** The handle to open the conversation on, for a page that knows who should
13
16
  * answer. The visitor can still address somebody else afterwards. */
14
17
  agent?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../../src/lib/useChat.ts"],"names":[],"mappings":"AAsCA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,cAAc,EACd,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,eAAe,EAChB,MAAM,UAAU,CAAA;AA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,SAAS,GAAG,YAAY,GAAG,QAAQ,CAAA;AA0ChG,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,aAAa,CAqd9D"}
package/dist/react.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./src-DvRdkFTu.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`,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`),t.context=i.context,t.user=i.user,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;
1
+ "use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./src-wGegp_8B.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`),t.context=i.context,t.user=i.user,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
@@ -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 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 // Objects have no attribute representation: properties.\n element.context = props.context\n element.user = props.user\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 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,QACV,EAEA,SAAS,EACP,EACA,EACM,CACF,OAAO,GAAW,WAA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D,EAEA,OADA,EAAQ,iBAAiB,EAAM,CAAQ,MAC1B,EAAQ,oBAAoB,EAAM,CAAQ,CACzD,CAAC,EAEH,UAAa,EAAU,QAAS,GAAW,EAAO,CAAC,CACrD,EAAG,CAAC,EAAQ,EAAS,EAAW,EAAS,CAAO,CAAC,GAEjD,EAAO,EAAA,cAAA,CACL,EAAA,EACA,CACE,IAAM,GAAwC,CAC5C,EAAK,QAAU,EACf,EAAU,EAAW,CAAI,CAC3B,EACA,MAAO,EAAM,UACb,MAAO,EAAM,MACb,GAAI,EAAM,EACZ,EAKA,EAAM,cAAgB,KAClB,MAAA,EACA,EAAA,cAAA,CAAc,OAAQ,CAAE,KAAM,eAAgB,EAAG,EAAM,YAAY,CACzE,CACF,CAAC"}
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 // 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,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,EA7B5C,CA+BhC,CAAC,EAED,GAAM,CAAE,SAAQ,UAAS,YAAW,UAAS,WAAY,EA0BzD,OAzBA,EAAA,EAAA,UAAA,KAAgB,CACd,IAAM,EAAU,EAAK,QACrB,GAAI,CAAC,EAAS,OAUd,IAAM,EAAY,OAAO,QAAQ,CAP/B,eAAgB,EAChB,gBAAiB,EACjB,kBAAmB,EACnB,gBAAiB,EACjB,gBAAiB,CAGc,CAAQ,CAAC,CACvC,QAAQ,EAAG,KAAa,OAAO,GAAY,UAAU,CAAC,CACtD,KAAK,CAAC,EAAM,KAAa,CACxB,IAAM,EAAY,GAAuB,CACvC,IAAW,EAA+B,MAAM,CAClD,EAEA,OADA,EAAQ,iBAAiB,EAAM,CAAQ,MAC1B,EAAQ,oBAAoB,EAAM,CAAQ,CACzD,CAAC,EAEH,UAAa,EAAU,QAAS,GAAW,EAAO,CAAC,CACrD,EAAG,CAAC,EAAQ,EAAS,EAAW,EAAS,CAAO,CAAC,GAEjD,EAAO,EAAA,cAAA,CACL,EAAA,EACA,CACE,IAAM,GAAwC,CAC5C,EAAK,QAAU,EACf,EAAU,EAAW,CAAI,CAC3B,EACA,MAAO,EAAM,UACb,MAAO,EAAM,MACb,GAAI,EAAM,EACZ,EAKA,EAAM,cAAgB,KAClB,MAAA,EACA,EAAA,cAAA,CAAc,OAAQ,CAAE,KAAM,eAAgB,EAAG,EAAM,YAAY,CACzE,CACF,CAAC"}
package/dist/react.d.ts CHANGED
@@ -26,5 +26,5 @@ export interface SquadicoChatbotProps extends ChatbotOptions {
26
26
  }
27
27
  export declare const SquadicoChatbot: import("react").ForwardRefExoticComponent<SquadicoChatbotProps & import("react").RefAttributes<SquadicoChatbotElement | null>>;
28
28
  export { defineChatbot, TAG_NAME } from './index';
29
- export type { AgentHandle, ApprovalDecision, ChatbotContext, ChatbotEvent, ChatbotEventMap, ChatbotEventName, ChatbotOptions, ChatbotTheme, ChatMessage, ChatRole, ContextObject, ContextValue, HostUser, LauncherPosition, PendingApproval, SquadicoChatbotElement, } from './types';
29
+ export type { AgentHandle, ApprovalDecision, ChatbotContext, ChatbotEvent, ChatbotEventMap, ChatbotEventName, ChatbotLayout, ChatbotOptions, ChatbotTheme, ChatMessage, ChatRole, ContextObject, ContextValue, HostUser, LauncherPosition, PendingApproval, SquadicoChatbotElement, } from './types';
30
30
  //# sourceMappingURL=react.d.ts.map
@@ -1 +1 @@
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,SAA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A;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AA2BD,eAAO,MAAM,eAAe,gIAoG1B,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-CN1vDssu.js";
2
+ import { n as e, o as t, t as n } from "./src-D4ZbNlbK.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 = {
@@ -14,6 +14,7 @@ var s = {
14
14
  accent: "accent",
15
15
  theme: "theme",
16
16
  position: "position",
17
+ layout: "layout",
17
18
  locale: "locale"
18
19
  };
19
20
  function c(e, t) {
@@ -29,7 +30,7 @@ var l = i(function(i, l) {
29
30
  let r = i[e];
30
31
  typeof r == "string" && r ? n.setAttribute(t, r) : n.removeAttribute(t);
31
32
  }
32
- 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"), n.context = i.context, n.user = i.user, 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"), 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
34
  }
34
35
  });
35
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 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 // Objects have no attribute representation: properties.\n element.context = props.context\n element.user = props.user\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 ChatbotOptions,\n ChatbotTheme,\n ChatMessage,\n ChatRole,\n ContextObject,\n ContextValue,\n HostUser,\n LauncherPosition,\n PendingApproval,\n SquadicoChatbotElement,\n} from './types'\n"],"mappings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CACvC,QAAQ,GAAG,OAAa,OAAO,KAAY,UAAU,CAAC,CACtD,KAAK,CAAC,GAAM,OAAa;GACxB,IAAM,KAAY,MAAuB;IACvC,IAAW,EAA+B,MAAM;GAClD;GAEA,OADA,EAAQ,iBAAiB,GAAM,CAAQ,SAC1B,EAAQ,oBAAoB,GAAM,CAAQ;EACzD,CAAC;EAEH,aAAa,EAAU,SAAS,MAAW,EAAO,CAAC;CACrD,GAAG;EAAC;EAAQ;EAAS;EAAW;EAAS;CAAO,CAAC,GAE1C,EACL,GACA;EACE,MAAM,MAAwC;GAE5C,AADA,EAAK,UAAU,GACf,EAAU,GAAW,CAAI;EAC3B;EACA,OAAO,EAAM;EACb,OAAO,EAAM;EACb,IAAI,EAAM;CACZ,GAKA,EAAM,gBAAgB,OAClB,OACA,EAAc,QAAQ,EAAE,MAAM,gBAAgB,GAAG,EAAM,YAAY,CACzE;AACF,CAAC"}
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 // 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;GAqBA,AAnBI,EAAM,aAAa,SACrB,EAAQ,aAAa,eAAe,KAAK,UAAU,EAAM,WAAW,CAAC,IAErE,EAAQ,gBAAgB,aAAa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