@carbon/ai-chat 1.15.0 → 1.16.0-rc.1

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.
@@ -111,7 +111,7 @@
111
111
  inset-inline-start: var(--cds-aichat-left-position, auto);
112
112
  max-block-size: var(--cds-aichat-max-height, 640px);
113
113
  max-inline-size: var(--cds-aichat-messages-max-width, 672px);
114
- min-block-size: var(--cds-aichat-min-height, 150px);
114
+ min-block-size: var(--cds-aichat-min-height, max(150px, min(256px, 100vh) - var(--cds-aichat-bottom-position, 3rem)));
115
115
  }
116
116
 
117
117
  /* ============================================================================
@@ -166,7 +166,7 @@
166
166
  inset-inline-start: var(--cds-aichat-left-position, auto);
167
167
  max-block-size: var(--cds-aichat-max-height, 640px);
168
168
  max-inline-size: 100%;
169
- min-block-size: var(--cds-aichat-min-height, 150px);
169
+ min-block-size: var(--cds-aichat-min-height, max(150px, min(256px, 100vh) - var(--cds-aichat-bottom-position, 3rem)));
170
170
  }
171
171
 
172
172
  .cds-aichat-float--mobile.cds-aichat-float--opening {
@@ -92,6 +92,8 @@ import "lodash-es/throttle.js";
92
92
 
93
93
  import "@carbon/icons/es/down-to-bottom/16.js";
94
94
 
95
+ import "@carbon/ai-chat-components/es/globals/settings.js";
96
+
95
97
  import "@carbon/icons/es/screen--off/16.js";
96
98
 
97
99
  import "@carbon/icons/es/user--avatar/32.js";
@@ -128,8 +130,6 @@ import "@carbon/ai-chat-components/es/react/feedback-buttons.js";
128
130
 
129
131
  import "@carbon/ai-chat-components/es/react/feedback.js";
130
132
 
131
- import "@carbon/ai-chat-components/es/globals/settings.js";
132
-
133
133
  import "@carbon/icons/es/checkmark/16.js";
134
134
 
135
135
  import "@carbon/icons/es/headset/16.js";
@@ -218,12 +218,12 @@ import "lit/decorators.js";
218
218
 
219
219
  import "@carbon/ai-chat-components/es/react/panel.js";
220
220
 
221
- import "@carbon/icons/es/chevron--down/20.js";
222
-
223
- import "@carbon/icons/es/close--large/20.js";
221
+ import "@carbon/icons/es/chevron--left/16.js";
224
222
 
225
223
  import "@carbon/ai-chat-components/es/react/toolbar.js";
226
224
 
225
+ import "@carbon/web-components/es/components/icon-button/icon-button.js";
226
+
227
227
  import "@carbon/web-components/es/components/chat-button/chat-button.js";
228
228
 
229
229
  function readCarbonChatSession(namespace) {
@@ -360,6 +360,17 @@ function ChatContainer(props) {
360
360
  return;
361
361
  }
362
362
  event.preventDefault();
363
+ if (detail.element) {
364
+ const element = detail.element;
365
+ element.setAttribute("slot", detail.slotName);
366
+ if (!detail.isInline) {
367
+ element.style.marginBlockStart = "1rem";
368
+ }
369
+ if (element.parentElement !== wrapper) {
370
+ wrapper.appendChild(element);
371
+ }
372
+ return;
373
+ }
363
374
  let host = hosts.get(detail.slotName);
364
375
  if (!host) {
365
376
  host = document.createElement(detail.isInline ? "span" : "div");
@@ -370,8 +381,8 @@ function ChatContainer(props) {
370
381
  hosts.set(detail.slotName, host);
371
382
  wrapper.appendChild(host);
372
383
  }
373
- if (host.innerHTML !== detail.html) {
374
- host.innerHTML = detail.html;
384
+ if (host.innerHTML !== (detail.html ?? "")) {
385
+ host.innerHTML = detail.html ?? "";
375
386
  }
376
387
  };
377
388
  const handleUpdate = event => {
@@ -1 +1 @@
1
- {"version":3,"file":"aiChatEntry.js","sources":["../../../../src/globals/utils/readCarbonChatSession.ts","../../../../src/react/ChatContainer.tsx","../../../../src/react/ChatCustomElement.tsx"],"sourcesContent":["/*\n * Copyright IBM Corp. 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { VERSION } from \"../../chat/utils/environmentVariables\";\nimport { PersistedState } from \"../../types/state/AppState\";\nimport { IS_SESSION_STORAGE } from \"../../chat/utils/browserUtils\";\nimport { getSuffix } from \"../../chat/services/NamespaceService\";\n\n/**\n * Reads and validates the Carbon AI Chat session from sessionStorage.\n * Returns null if no session exists, if the data is corrupt, or if the\n * session was written by a different version of the library (version mismatch).\n *\n * Pass the same namespace value as {@link PublicConfig.namespace} (if any).\n *\n * @category Utilities\n *\n * @example\n * const session = readCarbonChatSession();\n * const wasOpen = session?.viewState.mainWindow === true;\n *\n * @example\n * // With a namespace matching PublicConfig.namespace\n * const session = readCarbonChatSession(\"myapp\");\n * const wasOpen = session?.viewState.mainWindow === true;\n */\nfunction readCarbonChatSession(namespace?: string): PersistedState | null {\n try {\n if (!IS_SESSION_STORAGE()) {\n return null;\n }\n const key = `CARBON_CHAT_SESSION${getSuffix(namespace)}`;\n const raw = window.sessionStorage.getItem(key);\n if (!raw) {\n return null;\n }\n const session = JSON.parse(raw) as PersistedState;\n if (session?.version !== VERSION) {\n return null;\n }\n return session;\n } catch {\n return null;\n }\n}\n\nexport { readCarbonChatSession };\n","/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { createComponent } from \"@lit/react\";\nimport { css, LitElement, PropertyValues } from \"lit\";\nimport React, {\n type HTMLAttributes,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport ChatAppEntry from \"../chat/ChatAppEntry\";\nimport { carbonElement } from \"@carbon/ai-chat-components/es/globals/decorators/index.js\";\nimport { ChatContainerProps } from \"../types/component/ChatContainer\";\nimport { ChatInstance } from \"../types/instance/ChatInstance\";\nimport { BusEventType } from \"../types/events/eventBusTypes\";\nimport { PublicConfig } from \"../types/config/PublicConfig\";\nimport { isBrowser } from \"../chat/utils/browserUtils\";\n\n/**\n * This component creates a custom element protected by a shadow DOM to render the React application into. It creates\n * slotted elements for user_defined responses and for writable elements.\n *\n * The corresponding slots are defined within the React application and are rendered in place.\n */\n\n/**\n * Create a web component to host the React application. We do this so we can provide custom elements and user_defined responses as\n * slotted content so they maintain their own styling in a safe way.\n */\n@carbonElement(\"cds-aichat-react\")\nclass ChatContainerReact extends LitElement {\n static styles = css`\n :host {\n width: 100%;\n height: 100%;\n }\n `;\n\n /**\n * Dispatch a custom event when the shadow DOM is ready\n * This ensures React can safely access shadowRoot\n */\n firstUpdated(changedProperties: PropertyValues) {\n super.firstUpdated(changedProperties);\n this.dispatchEvent(new CustomEvent(\"shadow-ready\", { bubbles: true }));\n }\n}\n\n// Wrap the custom element as a React component\nconst ReactChatContainer = React.memo(\n createComponent({\n tagName: \"cds-aichat-react\",\n elementClass: ChatContainerReact,\n react: React,\n }),\n);\n\n/**\n * The ChatContainer controls rendering the React application into the shadow DOM of the cds-aichat-react web component.\n * It also injects the writeable element and user_defined response slots into said web component.\n *\n * @category React\n */\nfunction ChatContainer(\n props: ChatContainerProps &\n Omit<HTMLAttributes<HTMLElement>, keyof ChatContainerProps>,\n) {\n const {\n onBeforeRender,\n onAfterRender,\n onViewChange,\n onViewPreChange,\n strings,\n serviceDeskFactory,\n serviceDesk,\n renderUserDefinedResponse,\n renderCustomMessageFooter,\n renderWriteableElements,\n element,\n // Flattened PublicConfig properties\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n markdown,\n ...domProps\n } = props;\n // Reconstruct PublicConfig from flattened props\n const config = useMemo(\n (): PublicConfig => ({\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n }),\n [\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n ],\n );\n\n const wrapperRef = useRef(null); // Ref for the React wrapper component\n const [wrapper, setWrapper] = useState(null);\n const [container, setContainer] = useState<HTMLElement | null>(null); // Actual element we render the React Portal to in the Shadowroot.\n\n const [writeableElementSlots, setWriteableElementSlots] = useState<\n HTMLElement[]\n >([]);\n const [currentInstance, setCurrentInstance] = useState<ChatInstance>(null);\n\n /**\n * Setup the DOM nodes of both the web component to be able to inject slotted content into it, and the element inside the\n * shadow DOM we will inject our React application into.\n */\n useEffect(() => {\n if (!wrapperRef.current) {\n return null; // Early return when there's nothing to set up because the element isn't ready.\n }\n\n let eventListenerAdded = false;\n\n const wrapperElement = wrapperRef.current as unknown as ChatContainerReact;\n\n // We need to check if the element in the shadow DOM we are render the React application to exists.\n // If it doesn't, we need to create and append it.\n\n const handleShadowReady = () => {\n // Now we know shadowRoot is definitely available\n let reactElement = wrapperElement.shadowRoot.querySelector(\n \".cds-aichat--react-app\",\n ) as HTMLElement;\n\n if (!reactElement) {\n reactElement = document.createElement(\"div\");\n reactElement.classList.add(\"cds-aichat--react-app\");\n wrapperElement.shadowRoot.appendChild(reactElement);\n }\n\n if (wrapperElement !== wrapper) {\n setWrapper(wrapperElement);\n }\n if (reactElement !== container) {\n setContainer(reactElement);\n }\n };\n\n if (wrapperElement.shadowRoot) {\n // Already ready\n handleShadowReady();\n } else {\n // Wait for ready event\n eventListenerAdded = true;\n wrapperElement.addEventListener(\"shadow-ready\", handleShadowReady, {\n once: true,\n });\n }\n\n return () => {\n if (eventListenerAdded) {\n wrapperElement.removeEventListener(\"shadow-ready\", handleShadowReady);\n }\n };\n }, [container, wrapper, currentInstance]);\n\n /**\n * Here we write the slotted elements into the wrapper so they are passed into the application to be rendered in their slot.\n */\n useEffect(() => {\n if (wrapper) {\n const combinedNodes: HTMLElement[] = [...writeableElementSlots];\n const currentNodes: HTMLElement[] = Array.from(\n wrapper.childNodes,\n ) as HTMLElement[];\n\n // Append new nodes that aren't already in the container\n combinedNodes.forEach((node) => {\n if (!currentNodes.includes(node)) {\n wrapper.appendChild(node);\n }\n });\n }\n }, [writeableElementSlots, wrapper]);\n\n /**\n * Plugin-fallback slot hosts (e.g. KaTeX rendered by a markdown-it plugin)\n * need to live in the page light DOM so a consumer-loaded stylesheet can\n * reach them — the markdown element's own light DOM sits inside this\n * wrapper's shadow root, where global CSS doesn't apply. The markdown\n * element bubbles a composed `cds-aichat-markdown-plugin-host-mount` event\n * for each new plugin slot; we accept the offer (`preventDefault()`),\n * create the host as a slot-attributed child of the wrapper (= page light\n * DOM, since this is the outermost chat element on the React path), and\n * tear it down when the matching unmount event fires.\n */\n useEffect(() => {\n if (!wrapper) {\n return undefined;\n }\n const hosts = new Map<string, HTMLElement>();\n const handleMount = (event: Event) => {\n const detail = (\n event as CustomEvent<{\n slotName: string;\n html: string;\n isInline: boolean;\n }>\n ).detail;\n if (!detail?.slotName) {\n return;\n }\n event.preventDefault();\n let host = hosts.get(detail.slotName);\n if (!host) {\n host = document.createElement(detail.isInline ? \"span\" : \"div\");\n host.setAttribute(\"slot\", detail.slotName);\n // Match the spacing applied to direct children of\n // `.cds-aichat-markdown-stack`; shadow CSS doesn't reach this host\n // (we mounted it in page light DOM), so apply it inline. Inline\n // plugin output flows with text and gets no extra spacing.\n if (!detail.isInline) {\n host.style.marginBlockStart = \"1rem\";\n }\n hosts.set(detail.slotName, host);\n wrapper.appendChild(host);\n }\n if (host.innerHTML !== detail.html) {\n host.innerHTML = detail.html;\n }\n };\n const handleUpdate = (event: Event) => {\n const detail = (event as CustomEvent<{ slotName: string; html: string }>)\n .detail;\n if (!detail?.slotName) {\n return;\n }\n const host = hosts.get(detail.slotName);\n if (host && host.innerHTML !== detail.html) {\n host.innerHTML = detail.html;\n }\n };\n const handleUnmount = (event: Event) => {\n const detail = (event as CustomEvent<{ slotName: string }>).detail;\n if (!detail?.slotName) {\n return;\n }\n const host = hosts.get(detail.slotName);\n if (host) {\n host.remove();\n hosts.delete(detail.slotName);\n }\n };\n wrapper.addEventListener(\n \"cds-aichat-markdown-plugin-host-mount\",\n handleMount,\n );\n wrapper.addEventListener(\n \"cds-aichat-markdown-plugin-host-update\",\n handleUpdate,\n );\n wrapper.addEventListener(\n \"cds-aichat-markdown-plugin-host-unmount\",\n handleUnmount,\n );\n return () => {\n wrapper.removeEventListener(\n \"cds-aichat-markdown-plugin-host-mount\",\n handleMount,\n );\n wrapper.removeEventListener(\n \"cds-aichat-markdown-plugin-host-update\",\n handleUpdate,\n );\n wrapper.removeEventListener(\n \"cds-aichat-markdown-plugin-host-unmount\",\n handleUnmount,\n );\n for (const host of hosts.values()) {\n host.remove();\n }\n hosts.clear();\n };\n }, [wrapper]);\n\n const onBeforeRenderOverride = useCallback(\n (instance: ChatInstance) => {\n if (instance) {\n const addWriteableElementSlots = () => {\n const slots: HTMLElement[] = Object.entries(\n instance.writeableElements,\n ).map((writeableElement) => {\n const [key, element] = writeableElement;\n element.setAttribute(\"slot\", key); // Assign slot attributes dynamically\n return element;\n });\n setWriteableElementSlots(slots);\n };\n\n addWriteableElementSlots();\n\n // Opt-in view-change observation hooks. The float container manages\n // its own visibility, so there is no default handler — a prop is only\n // subscribed when the consumer provides it.\n if (onViewPreChange) {\n instance.on({\n type: BusEventType.VIEW_PRE_CHANGE,\n handler: onViewPreChange,\n });\n }\n if (onViewChange) {\n instance.on({\n type: BusEventType.VIEW_CHANGE,\n handler: onViewChange,\n });\n }\n\n onBeforeRender?.(instance);\n }\n },\n [onBeforeRender, onViewChange, onViewPreChange],\n );\n\n // If we are in SSR mode, just short circuit here. This prevents all of our window.* and document.* stuff from trying\n // to run and erroring out.\n if (!isBrowser()) {\n return null;\n }\n\n return (\n <>\n <ReactChatContainer ref={wrapperRef} {...domProps} />\n {container &&\n createPortal(\n <ChatAppEntry\n key=\"stable-chat-instance\"\n config={config}\n strings={strings}\n serviceDeskFactory={serviceDeskFactory}\n serviceDesk={serviceDesk}\n renderUserDefinedResponse={renderUserDefinedResponse}\n renderCustomMessageFooter={renderCustomMessageFooter}\n renderWriteableElements={renderWriteableElements}\n markdown={markdown}\n onBeforeRender={onBeforeRenderOverride}\n onAfterRender={onAfterRender}\n container={container}\n setParentInstance={setCurrentInstance}\n element={element}\n chatWrapper={wrapper}\n />,\n container,\n )}\n </>\n );\n}\n\nexport { ChatContainer, ChatContainerProps };\n","/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport React, {\n type HTMLAttributes,\n useCallback,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\n\nimport { ChatInstance } from \"../types/instance/ChatInstance\";\nimport {\n BusEventType,\n BusEventViewChange,\n BusEventViewPreChange,\n} from \"../types/events/eventBusTypes\";\nimport { ChatContainer, ChatContainerProps } from \"./ChatContainer\";\nimport { isBrowser } from \"../chat/utils/browserUtils\";\n\n/**\n * Properties for the ChatContainer React component. This interface extends\n * {@link ChatContainerProps} and {@link PublicConfig} with additional component-specific props, flattening all\n * config properties as top-level props for better TypeScript IntelliSense.\n *\n * @category React\n */\ninterface ChatCustomElementProps extends ChatContainerProps {\n /**\n * A CSS class name that will be added to the custom element. This class must define the size of the\n * your custom element (width and height or using logical inline-size/block-size).\n *\n * You can make use of onViewPreChange and/or onViewChange to mutate this className value so have open/close animations.\n *\n * By default, the chat will just set the chat shell to a 0x0 size and mark everything but the launcher (is you are using it)\n * as display: none; if the chat is set to closed.\n */\n className: string;\n\n /**\n * An optional id that will be added to the custom element.\n */\n id?: string;\n\n /**\n * Called before a view change (chat opening/closing). The chat will hide the chat shell inside your custom element\n * to prevent invisible keyboard stops when the view change is *complete*.\n *\n * Use this callback to update your className value *before* the view change happens if you want to add any open/close\n * animations to your custom element before the chat shell inner contents are hidden. It is async and so you can\n * tie it to native the AnimationEvent and only return when your animations have completed.\n *\n * A common pattern is to use this for when the chat is closing and to use onViewChange for when the chat opens.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded as it is registered before the\n * chat renders. After Carbon AI Chat is loaded, the callback will not be updated.\n */\n onViewPreChange?: (\n event: BusEventViewPreChange,\n instance: ChatInstance,\n ) => Promise<void> | void;\n\n /**\n * Called when the chat view change is complete. If no callback is provided here, the default behavior will be to set\n * the chat shell to 0x0 size and set all inner contents aside from the launcher, if you are using it, to display: none.\n * The inner contents of the chat shell (aside from the launcher if you are using it) are always set to display: none\n * regardless of what is configured with this callback to prevent invisible tab stops and screen reader issues.\n *\n * Use this callback to update your className value when the chat has finished being opened or closed.\n *\n * You can provide a different callback here if you want custom animation behavior when the chat is opened or closed.\n * The animation behavior defined here will run in concert with the chat inside your custom container being hidden.\n *\n * If you want to run animations before the inner contents of the chat shell is shrunk and the inner contents are hidden,\n * make use of onViewPreChange.\n *\n * A common pattern is to use this for when the chat is opening and to use onViewPreChange for when the chat closes.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded as it is registered before the\n * chat renders. After Carbon AI Chat is loaded, the callback will not be updated.\n */\n onViewChange?: (event: BusEventViewChange, instance: ChatInstance) => void;\n}\n\nconst customElementStylesheet =\n isBrowser() && typeof CSSStyleSheet !== \"undefined\"\n ? new CSSStyleSheet()\n : null;\n\nconst hideStyles = `\n .cds-aichat--hidden {\n width: 0 !important;\n height: 0 !important;\n min-width: 0 !important;\n min-height: 0 !important;\n max-width: 0 !important;\n max-height: 0 !important;\n inline-size: 0 !important;\n block-size: 0 !important;\n min-inline-size: 0 !important;\n min-block-size: 0 !important;\n max-inline-size: 0 !important;\n max-block-size: 0 !important;\n overflow: hidden !important;\n }\n`;\n\n// Inject styles using adopted stylesheets when available, fallback to style element\nif (\n isBrowser() &&\n !document.getElementById(\"cds-aichat-custom-element-styles\")\n) {\n if (customElementStylesheet && \"replaceSync\" in customElementStylesheet) {\n customElementStylesheet.replaceSync(hideStyles);\n document.adoptedStyleSheets = [\n ...document.adoptedStyleSheets,\n customElementStylesheet,\n ];\n } else {\n // Fallback for when adoptedStyleSheets are not supported\n const style = document.createElement(\"style\");\n style.id = \"cds-aichat-custom-element-styles\";\n style.textContent = hideStyles;\n document.head.appendChild(style);\n }\n}\n\n/**\n * This is the React component for people injecting a Carbon AI Chat with a custom element.\n *\n * It provides said element any class or id defined on itself for styling. It then calls ChatContainer with the custom\n * element passed in as a property to be used instead of generating an element with the default properties for a\n * floating chat.\n *\n * @category React\n */\nfunction ChatCustomElement(\n props: ChatCustomElementProps &\n Omit<HTMLAttributes<HTMLDivElement>, keyof ChatCustomElementProps>,\n) {\n const {\n strings,\n serviceDeskFactory,\n serviceDesk,\n onBeforeRender,\n onAfterRender,\n renderUserDefinedResponse,\n renderCustomMessageFooter,\n renderWriteableElements,\n className,\n id,\n onViewChange,\n onViewPreChange,\n // Flattened PublicConfig properties\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n markdown,\n ...domProps\n } = props;\n\n const containerRef = useRef<HTMLDivElement>(null);\n const [elementReady, setElementReady] = useState(false);\n\n useLayoutEffect(() => {\n setElementReady(true);\n }, []);\n\n const onBeforeRenderOverride = useCallback(\n async (instance: ChatInstance) => {\n /**\n * A default handler for the \"view:change\" event. This will be used to show or hide the Carbon AI Chat main window\n * by adding/removing a CSS class that sets the element size to 0x0 when hidden.\n */\n function defaultViewChangeHandler(event: BusEventViewChange) {\n const el = containerRef.current;\n if (el) {\n if (event.newViewState.mainWindow) {\n // Show: remove the hidden class, let the provided className handle sizing\n el.classList.remove(\"cds-aichat--hidden\");\n } else {\n // Hide: add the hidden class to set size to 0x0\n el.classList.add(\"cds-aichat--hidden\");\n }\n }\n }\n\n if (onViewPreChange) {\n instance.on({\n type: BusEventType.VIEW_PRE_CHANGE,\n handler: onViewPreChange,\n });\n }\n\n instance.on({\n type: BusEventType.VIEW_CHANGE,\n handler: onViewChange || defaultViewChangeHandler,\n });\n\n return onBeforeRender?.(instance);\n },\n [onViewPreChange, onViewChange, onBeforeRender],\n );\n\n return (\n <div className={className} id={id} ref={containerRef} {...domProps}>\n {elementReady && containerRef.current && (\n <ChatContainer\n // Flattened PublicConfig properties\n onError={onError}\n openChatByDefault={openChatByDefault}\n disclaimer={disclaimer}\n disableCustomElementMobileEnhancements={\n disableCustomElementMobileEnhancements\n }\n debug={debug}\n exposeServiceManagerForTesting={exposeServiceManagerForTesting}\n injectCarbonTheme={injectCarbonTheme}\n aiEnabled={aiEnabled}\n shouldTakeFocusIfOpensAutomatically={\n shouldTakeFocusIfOpensAutomatically\n }\n namespace={namespace}\n shouldSanitizeHTML={shouldSanitizeHTML}\n header={header}\n history={history}\n layout={layout}\n messaging={messaging}\n isReadonly={isReadonly}\n persistFeedback={persistFeedback}\n assistantName={assistantName}\n assistantAvatarUrl={assistantAvatarUrl}\n locale={locale}\n homescreen={homescreen}\n launcher={launcher}\n input={input}\n keyboardShortcuts={keyboardShortcuts}\n upload={upload}\n markdown={markdown}\n // Other ChatContainer props\n strings={strings}\n serviceDeskFactory={serviceDeskFactory}\n serviceDesk={serviceDesk}\n onBeforeRender={onBeforeRenderOverride}\n onAfterRender={onAfterRender}\n renderUserDefinedResponse={renderUserDefinedResponse}\n renderCustomMessageFooter={renderCustomMessageFooter}\n renderWriteableElements={renderWriteableElements}\n element={containerRef.current}\n />\n )}\n </div>\n );\n}\n\nexport { ChatCustomElement, ChatCustomElementProps };\n"],"names":["readCarbonChatSession","namespace","IS_SESSION_STORAGE","key","getSuffix","raw","window","sessionStorage","getItem","session","JSON","parse","version","VERSION","ChatContainerReact","LitElement","firstUpdated","changedProperties","super","this","dispatchEvent","CustomEvent","bubbles","styles","css","__decorate","carbonElement","ReactChatContainer","React","memo","createComponent","tagName","elementClass","react","ChatContainer","props","onBeforeRender","onAfterRender","onViewChange","onViewPreChange","strings","serviceDeskFactory","serviceDesk","renderUserDefinedResponse","renderCustomMessageFooter","renderWriteableElements","element","onError","openChatByDefault","disclaimer","disableCustomElementMobileEnhancements","debug","exposeServiceManagerForTesting","injectCarbonTheme","aiEnabled","shouldTakeFocusIfOpensAutomatically","shouldSanitizeHTML","header","history","layout","messaging","isReadonly","persistFeedback","assistantName","assistantAvatarUrl","locale","homescreen","launcher","input","keyboardShortcuts","upload","markdown","domProps","config","useMemo","wrapperRef","useRef","wrapper","setWrapper","useState","container","setContainer","writeableElementSlots","setWriteableElementSlots","currentInstance","setCurrentInstance","useEffect","current","eventListenerAdded","wrapperElement","handleShadowReady","reactElement","shadowRoot","querySelector","document","createElement","classList","add","appendChild","addEventListener","once","removeEventListener","combinedNodes","currentNodes","Array","from","childNodes","forEach","node","includes","undefined","hosts","Map","handleMount","event","detail","slotName","preventDefault","host","get","isInline","setAttribute","style","marginBlockStart","set","innerHTML","html","handleUpdate","handleUnmount","remove","delete","values","clear","onBeforeRenderOverride","useCallback","instance","addWriteableElementSlots","slots","Object","entries","writeableElements","map","writeableElement","on","type","BusEventType","VIEW_PRE_CHANGE","handler","VIEW_CHANGE","isBrowser","Fragment","ref","createPortal","ChatAppEntry","setParentInstance","chatWrapper","customElementStylesheet","CSSStyleSheet","hideStyles","getElementById","replaceSync","adoptedStyleSheets","id","textContent","head","ChatCustomElement","className","containerRef","elementReady","setElementReady","useLayoutEffect","async","defaultViewChangeHandler","el","newViewState","mainWindow"],"mappings":";;;;;;;;;;;;;;;;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ACAM;IACAC;IACAC;IACAC,SAASyH,aAAahF;;AAKhC;;"}
1
+ {"version":3,"file":"aiChatEntry.js","sources":["../../../../src/globals/utils/readCarbonChatSession.ts","../../../../src/react/ChatContainer.tsx","../../../../src/react/ChatCustomElement.tsx"],"sourcesContent":["/*\n * Copyright IBM Corp. 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { VERSION } from \"../../chat/utils/environmentVariables\";\nimport { PersistedState } from \"../../types/state/AppState\";\nimport { IS_SESSION_STORAGE } from \"../../chat/utils/browserUtils\";\nimport { getSuffix } from \"../../chat/services/NamespaceService\";\n\n/**\n * Reads and validates the Carbon AI Chat session from sessionStorage.\n * Returns null if no session exists, if the data is corrupt, or if the\n * session was written by a different version of the library (version mismatch).\n *\n * Pass the same namespace value as {@link PublicConfig.namespace} (if any).\n *\n * @category Utilities\n *\n * @example\n * const session = readCarbonChatSession();\n * const wasOpen = session?.viewState.mainWindow === true;\n *\n * @example\n * // With a namespace matching PublicConfig.namespace\n * const session = readCarbonChatSession(\"myapp\");\n * const wasOpen = session?.viewState.mainWindow === true;\n */\nfunction readCarbonChatSession(namespace?: string): PersistedState | null {\n try {\n if (!IS_SESSION_STORAGE()) {\n return null;\n }\n const key = `CARBON_CHAT_SESSION${getSuffix(namespace)}`;\n const raw = window.sessionStorage.getItem(key);\n if (!raw) {\n return null;\n }\n const session = JSON.parse(raw) as PersistedState;\n if (session?.version !== VERSION) {\n return null;\n }\n return session;\n } catch {\n return null;\n }\n}\n\nexport { readCarbonChatSession };\n","/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { createComponent } from \"@lit/react\";\nimport { css, LitElement, PropertyValues } from \"lit\";\nimport React, {\n type HTMLAttributes,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport ChatAppEntry from \"../chat/ChatAppEntry\";\nimport { carbonElement } from \"@carbon/ai-chat-components/es/globals/decorators/index.js\";\nimport { ChatContainerProps } from \"../types/component/ChatContainer\";\nimport { ChatInstance } from \"../types/instance/ChatInstance\";\nimport { BusEventType } from \"../types/events/eventBusTypes\";\nimport { PublicConfig } from \"../types/config/PublicConfig\";\nimport { isBrowser } from \"../chat/utils/browserUtils\";\n\n/**\n * This component creates a custom element protected by a shadow DOM to render the React application into. It creates\n * slotted elements for user_defined responses and for writable elements.\n *\n * The corresponding slots are defined within the React application and are rendered in place.\n */\n\n/**\n * Create a web component to host the React application. We do this so we can provide custom elements and user_defined responses as\n * slotted content so they maintain their own styling in a safe way.\n */\n@carbonElement(\"cds-aichat-react\")\nclass ChatContainerReact extends LitElement {\n static styles = css`\n :host {\n width: 100%;\n height: 100%;\n }\n `;\n\n /**\n * Dispatch a custom event when the shadow DOM is ready\n * This ensures React can safely access shadowRoot\n */\n firstUpdated(changedProperties: PropertyValues) {\n super.firstUpdated(changedProperties);\n this.dispatchEvent(new CustomEvent(\"shadow-ready\", { bubbles: true }));\n }\n}\n\n// Wrap the custom element as a React component\nconst ReactChatContainer = React.memo(\n createComponent({\n tagName: \"cds-aichat-react\",\n elementClass: ChatContainerReact,\n react: React,\n }),\n);\n\n/**\n * The ChatContainer controls rendering the React application into the shadow DOM of the cds-aichat-react web component.\n * It also injects the writeable element and user_defined response slots into said web component.\n *\n * @category React\n */\nfunction ChatContainer(\n props: ChatContainerProps &\n Omit<HTMLAttributes<HTMLElement>, keyof ChatContainerProps>,\n) {\n const {\n onBeforeRender,\n onAfterRender,\n onViewChange,\n onViewPreChange,\n strings,\n serviceDeskFactory,\n serviceDesk,\n renderUserDefinedResponse,\n renderCustomMessageFooter,\n renderWriteableElements,\n element,\n // Flattened PublicConfig properties\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n markdown,\n ...domProps\n } = props;\n // Reconstruct PublicConfig from flattened props\n const config = useMemo(\n (): PublicConfig => ({\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n }),\n [\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n ],\n );\n\n const wrapperRef = useRef(null); // Ref for the React wrapper component\n const [wrapper, setWrapper] = useState(null);\n const [container, setContainer] = useState<HTMLElement | null>(null); // Actual element we render the React Portal to in the Shadowroot.\n\n const [writeableElementSlots, setWriteableElementSlots] = useState<\n HTMLElement[]\n >([]);\n const [currentInstance, setCurrentInstance] = useState<ChatInstance>(null);\n\n /**\n * Setup the DOM nodes of both the web component to be able to inject slotted content into it, and the element inside the\n * shadow DOM we will inject our React application into.\n */\n useEffect(() => {\n if (!wrapperRef.current) {\n return null; // Early return when there's nothing to set up because the element isn't ready.\n }\n\n let eventListenerAdded = false;\n\n const wrapperElement = wrapperRef.current as unknown as ChatContainerReact;\n\n // We need to check if the element in the shadow DOM we are render the React application to exists.\n // If it doesn't, we need to create and append it.\n\n const handleShadowReady = () => {\n // Now we know shadowRoot is definitely available\n let reactElement = wrapperElement.shadowRoot.querySelector(\n \".cds-aichat--react-app\",\n ) as HTMLElement;\n\n if (!reactElement) {\n reactElement = document.createElement(\"div\");\n reactElement.classList.add(\"cds-aichat--react-app\");\n wrapperElement.shadowRoot.appendChild(reactElement);\n }\n\n if (wrapperElement !== wrapper) {\n setWrapper(wrapperElement);\n }\n if (reactElement !== container) {\n setContainer(reactElement);\n }\n };\n\n if (wrapperElement.shadowRoot) {\n // Already ready\n handleShadowReady();\n } else {\n // Wait for ready event\n eventListenerAdded = true;\n wrapperElement.addEventListener(\"shadow-ready\", handleShadowReady, {\n once: true,\n });\n }\n\n return () => {\n if (eventListenerAdded) {\n wrapperElement.removeEventListener(\"shadow-ready\", handleShadowReady);\n }\n };\n }, [container, wrapper, currentInstance]);\n\n /**\n * Here we write the slotted elements into the wrapper so they are passed into the application to be rendered in their slot.\n */\n useEffect(() => {\n if (wrapper) {\n const combinedNodes: HTMLElement[] = [...writeableElementSlots];\n const currentNodes: HTMLElement[] = Array.from(\n wrapper.childNodes,\n ) as HTMLElement[];\n\n // Append new nodes that aren't already in the container\n combinedNodes.forEach((node) => {\n if (!currentNodes.includes(node)) {\n wrapper.appendChild(node);\n }\n });\n }\n }, [writeableElementSlots, wrapper]);\n\n /**\n * Plugin-fallback slot hosts (e.g. KaTeX rendered by a markdown-it plugin)\n * need to live in the page light DOM so a consumer-loaded stylesheet can\n * reach them — the markdown element's own light DOM sits inside this\n * wrapper's shadow root, where global CSS doesn't apply. The markdown\n * element bubbles a composed `cds-aichat-markdown-plugin-host-mount` event\n * for each new plugin slot; we accept the offer (`preventDefault()`),\n * create the host as a slot-attributed child of the wrapper (= page light\n * DOM, since this is the outermost chat element on the React path), and\n * tear it down when the matching unmount event fires.\n */\n useEffect(() => {\n if (!wrapper) {\n return undefined;\n }\n const hosts = new Map<string, HTMLElement>();\n const handleMount = (event: Event) => {\n const detail = (\n event as CustomEvent<{\n slotName: string;\n html?: string;\n element?: HTMLElement;\n isInline: boolean;\n }>\n ).detail;\n if (!detail?.slotName) {\n return;\n }\n event.preventDefault();\n // Custom-renderer hosts (table/codeBlock) forward a live element — the\n // markdown element keeps ownership of its content; we only relocate the\n // node into page light DOM so the consumer's global CSS reaches it.\n // Plugin fallbacks forward an HTML string instead.\n if (detail.element) {\n const element = detail.element;\n element.setAttribute(\"slot\", detail.slotName);\n if (!detail.isInline) {\n element.style.marginBlockStart = \"1rem\";\n }\n if (element.parentElement !== wrapper) {\n wrapper.appendChild(element);\n }\n return;\n }\n let host = hosts.get(detail.slotName);\n if (!host) {\n host = document.createElement(detail.isInline ? \"span\" : \"div\");\n host.setAttribute(\"slot\", detail.slotName);\n // Match the spacing applied to direct children of\n // `.cds-aichat-markdown-stack`; shadow CSS doesn't reach this host\n // (we mounted it in page light DOM), so apply it inline. Inline\n // plugin output flows with text and gets no extra spacing.\n if (!detail.isInline) {\n host.style.marginBlockStart = \"1rem\";\n }\n hosts.set(detail.slotName, host);\n wrapper.appendChild(host);\n }\n if (host.innerHTML !== (detail.html ?? \"\")) {\n host.innerHTML = detail.html ?? \"\";\n }\n };\n const handleUpdate = (event: Event) => {\n const detail = (event as CustomEvent<{ slotName: string; html: string }>)\n .detail;\n if (!detail?.slotName) {\n return;\n }\n const host = hosts.get(detail.slotName);\n if (host && host.innerHTML !== detail.html) {\n host.innerHTML = detail.html;\n }\n };\n const handleUnmount = (event: Event) => {\n const detail = (event as CustomEvent<{ slotName: string }>).detail;\n if (!detail?.slotName) {\n return;\n }\n const host = hosts.get(detail.slotName);\n if (host) {\n host.remove();\n hosts.delete(detail.slotName);\n }\n };\n wrapper.addEventListener(\n \"cds-aichat-markdown-plugin-host-mount\",\n handleMount,\n );\n wrapper.addEventListener(\n \"cds-aichat-markdown-plugin-host-update\",\n handleUpdate,\n );\n wrapper.addEventListener(\n \"cds-aichat-markdown-plugin-host-unmount\",\n handleUnmount,\n );\n return () => {\n wrapper.removeEventListener(\n \"cds-aichat-markdown-plugin-host-mount\",\n handleMount,\n );\n wrapper.removeEventListener(\n \"cds-aichat-markdown-plugin-host-update\",\n handleUpdate,\n );\n wrapper.removeEventListener(\n \"cds-aichat-markdown-plugin-host-unmount\",\n handleUnmount,\n );\n for (const host of hosts.values()) {\n host.remove();\n }\n hosts.clear();\n };\n }, [wrapper]);\n\n const onBeforeRenderOverride = useCallback(\n (instance: ChatInstance) => {\n if (instance) {\n const addWriteableElementSlots = () => {\n const slots: HTMLElement[] = Object.entries(\n instance.writeableElements,\n ).map((writeableElement) => {\n const [key, element] = writeableElement;\n element.setAttribute(\"slot\", key); // Assign slot attributes dynamically\n return element;\n });\n setWriteableElementSlots(slots);\n };\n\n addWriteableElementSlots();\n\n // Opt-in view-change observation hooks. The float container manages\n // its own visibility, so there is no default handler — a prop is only\n // subscribed when the consumer provides it.\n if (onViewPreChange) {\n instance.on({\n type: BusEventType.VIEW_PRE_CHANGE,\n handler: onViewPreChange,\n });\n }\n if (onViewChange) {\n instance.on({\n type: BusEventType.VIEW_CHANGE,\n handler: onViewChange,\n });\n }\n\n onBeforeRender?.(instance);\n }\n },\n [onBeforeRender, onViewChange, onViewPreChange],\n );\n\n // If we are in SSR mode, just short circuit here. This prevents all of our window.* and document.* stuff from trying\n // to run and erroring out.\n if (!isBrowser()) {\n return null;\n }\n\n return (\n <>\n <ReactChatContainer ref={wrapperRef} {...domProps} />\n {container &&\n createPortal(\n <ChatAppEntry\n key=\"stable-chat-instance\"\n config={config}\n strings={strings}\n serviceDeskFactory={serviceDeskFactory}\n serviceDesk={serviceDesk}\n renderUserDefinedResponse={renderUserDefinedResponse}\n renderCustomMessageFooter={renderCustomMessageFooter}\n renderWriteableElements={renderWriteableElements}\n markdown={markdown}\n onBeforeRender={onBeforeRenderOverride}\n onAfterRender={onAfterRender}\n container={container}\n setParentInstance={setCurrentInstance}\n element={element}\n chatWrapper={wrapper}\n />,\n container,\n )}\n </>\n );\n}\n\nexport { ChatContainer, ChatContainerProps };\n","/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport React, {\n type HTMLAttributes,\n useCallback,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\n\nimport { ChatInstance } from \"../types/instance/ChatInstance\";\nimport {\n BusEventType,\n BusEventViewChange,\n BusEventViewPreChange,\n} from \"../types/events/eventBusTypes\";\nimport { ChatContainer, ChatContainerProps } from \"./ChatContainer\";\nimport { isBrowser } from \"../chat/utils/browserUtils\";\n\n/**\n * Properties for the ChatContainer React component. This interface extends\n * {@link ChatContainerProps} and {@link PublicConfig} with additional component-specific props, flattening all\n * config properties as top-level props for better TypeScript IntelliSense.\n *\n * @category React\n */\ninterface ChatCustomElementProps extends ChatContainerProps {\n /**\n * A CSS class name that will be added to the custom element. This class must define the size of the\n * your custom element (width and height or using logical inline-size/block-size).\n *\n * You can make use of onViewPreChange and/or onViewChange to mutate this className value so have open/close animations.\n *\n * By default, the chat will just set the chat shell to a 0x0 size and mark everything but the launcher (is you are using it)\n * as display: none; if the chat is set to closed.\n */\n className: string;\n\n /**\n * An optional id that will be added to the custom element.\n */\n id?: string;\n\n /**\n * Called before a view change (chat opening/closing). The chat will hide the chat shell inside your custom element\n * to prevent invisible keyboard stops when the view change is *complete*.\n *\n * Use this callback to update your className value *before* the view change happens if you want to add any open/close\n * animations to your custom element before the chat shell inner contents are hidden. It is async and so you can\n * tie it to native the AnimationEvent and only return when your animations have completed.\n *\n * A common pattern is to use this for when the chat is closing and to use onViewChange for when the chat opens.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded as it is registered before the\n * chat renders. After Carbon AI Chat is loaded, the callback will not be updated.\n */\n onViewPreChange?: (\n event: BusEventViewPreChange,\n instance: ChatInstance,\n ) => Promise<void> | void;\n\n /**\n * Called when the chat view change is complete. If no callback is provided here, the default behavior will be to set\n * the chat shell to 0x0 size and set all inner contents aside from the launcher, if you are using it, to display: none.\n * The inner contents of the chat shell (aside from the launcher if you are using it) are always set to display: none\n * regardless of what is configured with this callback to prevent invisible tab stops and screen reader issues.\n *\n * Use this callback to update your className value when the chat has finished being opened or closed.\n *\n * You can provide a different callback here if you want custom animation behavior when the chat is opened or closed.\n * The animation behavior defined here will run in concert with the chat inside your custom container being hidden.\n *\n * If you want to run animations before the inner contents of the chat shell is shrunk and the inner contents are hidden,\n * make use of onViewPreChange.\n *\n * A common pattern is to use this for when the chat is opening and to use onViewPreChange for when the chat closes.\n *\n * Note that this function can only be provided before Carbon AI Chat is loaded as it is registered before the\n * chat renders. After Carbon AI Chat is loaded, the callback will not be updated.\n */\n onViewChange?: (event: BusEventViewChange, instance: ChatInstance) => void;\n}\n\nconst customElementStylesheet =\n isBrowser() && typeof CSSStyleSheet !== \"undefined\"\n ? new CSSStyleSheet()\n : null;\n\nconst hideStyles = `\n .cds-aichat--hidden {\n width: 0 !important;\n height: 0 !important;\n min-width: 0 !important;\n min-height: 0 !important;\n max-width: 0 !important;\n max-height: 0 !important;\n inline-size: 0 !important;\n block-size: 0 !important;\n min-inline-size: 0 !important;\n min-block-size: 0 !important;\n max-inline-size: 0 !important;\n max-block-size: 0 !important;\n overflow: hidden !important;\n }\n`;\n\n// Inject styles using adopted stylesheets when available, fallback to style element\nif (\n isBrowser() &&\n !document.getElementById(\"cds-aichat-custom-element-styles\")\n) {\n if (customElementStylesheet && \"replaceSync\" in customElementStylesheet) {\n customElementStylesheet.replaceSync(hideStyles);\n document.adoptedStyleSheets = [\n ...document.adoptedStyleSheets,\n customElementStylesheet,\n ];\n } else {\n // Fallback for when adoptedStyleSheets are not supported\n const style = document.createElement(\"style\");\n style.id = \"cds-aichat-custom-element-styles\";\n style.textContent = hideStyles;\n document.head.appendChild(style);\n }\n}\n\n/**\n * This is the React component for people injecting a Carbon AI Chat with a custom element.\n *\n * It provides said element any class or id defined on itself for styling. It then calls ChatContainer with the custom\n * element passed in as a property to be used instead of generating an element with the default properties for a\n * floating chat.\n *\n * @category React\n */\nfunction ChatCustomElement(\n props: ChatCustomElementProps &\n Omit<HTMLAttributes<HTMLDivElement>, keyof ChatCustomElementProps>,\n) {\n const {\n strings,\n serviceDeskFactory,\n serviceDesk,\n onBeforeRender,\n onAfterRender,\n renderUserDefinedResponse,\n renderCustomMessageFooter,\n renderWriteableElements,\n className,\n id,\n onViewChange,\n onViewPreChange,\n // Flattened PublicConfig properties\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n shouldSanitizeHTML,\n header,\n history,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n assistantAvatarUrl,\n locale,\n homescreen,\n launcher,\n input,\n keyboardShortcuts,\n upload,\n markdown,\n ...domProps\n } = props;\n\n const containerRef = useRef<HTMLDivElement>(null);\n const [elementReady, setElementReady] = useState(false);\n\n useLayoutEffect(() => {\n setElementReady(true);\n }, []);\n\n const onBeforeRenderOverride = useCallback(\n async (instance: ChatInstance) => {\n /**\n * A default handler for the \"view:change\" event. This will be used to show or hide the Carbon AI Chat main window\n * by adding/removing a CSS class that sets the element size to 0x0 when hidden.\n */\n function defaultViewChangeHandler(event: BusEventViewChange) {\n const el = containerRef.current;\n if (el) {\n if (event.newViewState.mainWindow) {\n // Show: remove the hidden class, let the provided className handle sizing\n el.classList.remove(\"cds-aichat--hidden\");\n } else {\n // Hide: add the hidden class to set size to 0x0\n el.classList.add(\"cds-aichat--hidden\");\n }\n }\n }\n\n if (onViewPreChange) {\n instance.on({\n type: BusEventType.VIEW_PRE_CHANGE,\n handler: onViewPreChange,\n });\n }\n\n instance.on({\n type: BusEventType.VIEW_CHANGE,\n handler: onViewChange || defaultViewChangeHandler,\n });\n\n return onBeforeRender?.(instance);\n },\n [onViewPreChange, onViewChange, onBeforeRender],\n );\n\n return (\n <div className={className} id={id} ref={containerRef} {...domProps}>\n {elementReady && containerRef.current && (\n <ChatContainer\n // Flattened PublicConfig properties\n onError={onError}\n openChatByDefault={openChatByDefault}\n disclaimer={disclaimer}\n disableCustomElementMobileEnhancements={\n disableCustomElementMobileEnhancements\n }\n debug={debug}\n exposeServiceManagerForTesting={exposeServiceManagerForTesting}\n injectCarbonTheme={injectCarbonTheme}\n aiEnabled={aiEnabled}\n shouldTakeFocusIfOpensAutomatically={\n shouldTakeFocusIfOpensAutomatically\n }\n namespace={namespace}\n shouldSanitizeHTML={shouldSanitizeHTML}\n header={header}\n history={history}\n layout={layout}\n messaging={messaging}\n isReadonly={isReadonly}\n persistFeedback={persistFeedback}\n assistantName={assistantName}\n assistantAvatarUrl={assistantAvatarUrl}\n locale={locale}\n homescreen={homescreen}\n launcher={launcher}\n input={input}\n keyboardShortcuts={keyboardShortcuts}\n upload={upload}\n markdown={markdown}\n // Other ChatContainer props\n strings={strings}\n serviceDeskFactory={serviceDeskFactory}\n serviceDesk={serviceDesk}\n onBeforeRender={onBeforeRenderOverride}\n onAfterRender={onAfterRender}\n renderUserDefinedResponse={renderUserDefinedResponse}\n renderCustomMessageFooter={renderCustomMessageFooter}\n renderWriteableElements={renderWriteableElements}\n element={containerRef.current}\n />\n )}\n </div>\n );\n}\n\nexport { ChatCustomElement, ChatCustomElementProps };\n"],"names":["readCarbonChatSession","namespace","IS_SESSION_STORAGE","key","getSuffix","raw","window","sessionStorage","getItem","session","JSON","parse","version","VERSION","ChatContainerReact","LitElement","firstUpdated","changedProperties","super","this","dispatchEvent","CustomEvent","bubbles","styles","css","__decorate","carbonElement","ReactChatContainer","React","memo","createComponent","tagName","elementClass","react","ChatContainer","props","onBeforeRender","onAfterRender","onViewChange","onViewPreChange","strings","serviceDeskFactory","serviceDesk","renderUserDefinedResponse","renderCustomMessageFooter","renderWriteableElements","element","onError","openChatByDefault","disclaimer","disableCustomElementMobileEnhancements","debug","exposeServiceManagerForTesting","injectCarbonTheme","aiEnabled","shouldTakeFocusIfOpensAutomatically","shouldSanitizeHTML","header","history","layout","messaging","isReadonly","persistFeedback","assistantName","assistantAvatarUrl","locale","homescreen","launcher","input","keyboardShortcuts","upload","markdown","domProps","config","useMemo","wrapperRef","useRef","wrapper","setWrapper","useState","container","setContainer","writeableElementSlots","setWriteableElementSlots","currentInstance","setCurrentInstance","useEffect","current","eventListenerAdded","wrapperElement","handleShadowReady","reactElement","shadowRoot","querySelector","document","createElement","classList","add","appendChild","addEventListener","once","removeEventListener","combinedNodes","currentNodes","Array","from","childNodes","forEach","node","includes","undefined","hosts","Map","handleMount","event","detail","slotName","preventDefault","setAttribute","isInline","style","marginBlockStart","parentElement","host","get","set","innerHTML","html","handleUpdate","handleUnmount","remove","delete","values","clear","onBeforeRenderOverride","useCallback","instance","addWriteableElementSlots","slots","Object","entries","writeableElements","map","writeableElement","on","type","BusEventType","VIEW_PRE_CHANGE","handler","VIEW_CHANGE","isBrowser","Fragment","ref","createPortal","ChatAppEntry","setParentInstance","chatWrapper","customElementStylesheet","CSSStyleSheet","hideStyles","getElementById","replaceSync","adoptedStyleSheets","id","textContent","head","ChatCustomElement","className","containerRef","elementReady","setElementReady","useLayoutEffect","async","defaultViewChangeHandler","el","newViewState","mainWindow"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAASA,sBAAsBC;EAC7B;IACE,KAAKC,sBAAsB;MACzB,OAAO;AACT;IACA,MAAMC,MAAM,sBAAsBC,UAAUH;IAC5C,MAAMI,MAAMC,OAAOC,eAAeC,QAAQL;IAC1C,KAAKE,KAAK;MACR,OAAO;AACT;IACA,MAAMI,UAAUC,KAAKC,MAAMN;IAC3B,IAAII,SAASG,YAAYC,SAAS;MAChC,OAAO;AACT;IACA,OAAOJ;AACT,IAAE;IACA,OAAO;AACT;AACF;;ACTA,IAAMK,qBAAN,MAAMA,2BAA2BC;EAY/B,YAAAC,CAAaC;IACXC,MAAMF,aAAaC;IACnBE,KAAKC,cAAc,IAAIC,YAAY,gBAAgB;MAAEC,SAAS;;AAChE;;;AAdOR,mBAAAS,SAASC,GAAG;;;;;;;AADfV,qBAAkBW,WAAA,EADvBC,cAAc,uBACTZ;;AAmBN,MAAMa,qBAAqBC,MAAMC,KAC/BC,gBAAgB;EACdC,SAAS;EACTC,cAAclB;EACdmB,OAAOL;;;AAUX,SAASM,cACPC;EAGA,OAAMC,gBACUC,eACDC,cACDC,iBACGC,SACRC,oBACWC,aACPC,2BACcC,2BACAC,yBACFC,SAChBC,SAEAC,mBACUC,YACPC,wCAC4BC,OACjCC,gCACyBC,mBACbC,WACRC,qCAC0BtD,WAC1BuD,oBACSC,QACZC,SACCC,QACDC,WACGC,YACCC,iBACKC,eACFC,oBACKC,QACZC,YACIC,UACFC,OACHC,mBACYC,QACXC,aAEHC,YACDrC;EAEJ,MAAMsC,SAASC,QACb,OAAA;IACE3B;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAtD;IACAuD;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;MAEF,EACEvB,SACAC,mBACAC,YACAC,wCACAC,OACAC,gCACAC,mBACAC,WACAC,qCACAtD,WACAuD,oBACAC,QACAC,SACAC,QACAC,WACAC,YACAC,iBACAC,eACAC,oBACAC,QACAC,YACAC,UACAC,OACAC,mBACAC;EAIJ,MAAMK,aAAaC,OAAO;EAC1B,OAAOC,SAASC,cAAcC,SAAS;EACvC,OAAOC,WAAWC,gBAAgBF,SAA6B;EAE/D,OAAOG,uBAAuBC,4B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