@carbon/ai-chat 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/aiChatEntry.js +51 -47
- package/dist/es/aiChatEntry.js.map +1 -1
- package/dist/es/chat.ChatAppEntry.js +5558 -5913
- package/dist/es/chat.ChatAppEntry.js.map +1 -1
- package/dist/es/chat.languageUtils.js +44 -3
- package/dist/es/chat.languageUtils.js.map +1 -1
- package/dist/es/web-components/cds-aichat-container/index.js +64 -47
- package/dist/es/web-components/cds-aichat-container/index.js.map +1 -1
- package/dist/es/web-components/cds-aichat-custom-element/index.js +48 -47
- package/dist/es/web-components/cds-aichat-custom-element/index.js.map +1 -1
- package/dist/es-custom/aiChatEntry.js +51 -47
- package/dist/es-custom/aiChatEntry.js.map +1 -1
- package/dist/es-custom/chat.ChatAppEntry.js +5558 -5913
- package/dist/es-custom/chat.ChatAppEntry.js.map +1 -1
- package/dist/es-custom/chat.languageUtils.js +44 -3
- package/dist/es-custom/chat.languageUtils.js.map +1 -1
- package/dist/es-custom/web-components/cds-aichat-container/index.js +64 -47
- package/dist/es-custom/web-components/cds-aichat-container/index.js.map +1 -1
- package/dist/es-custom/web-components/cds-aichat-custom-element/index.js +48 -47
- package/dist/es-custom/web-components/cds-aichat-custom-element/index.js.map +1 -1
- package/dist/types/aiChatEntry.d.ts +2 -2
- package/dist/types/{serverEntry-DCPrSQXt.d.ts → serverEntry-SHbZYjYo.d.ts} +223 -40
- package/dist/types/serverEntry.d.ts +1 -1
- package/package.json +4 -4
package/dist/es/aiChatEntry.js
CHANGED
|
@@ -44,7 +44,47 @@ import "intl-messageformat";
|
|
|
44
44
|
|
|
45
45
|
import "classnames";
|
|
46
46
|
|
|
47
|
-
import "
|
|
47
|
+
import "@carbon/icons/es/ai-launch/24.js";
|
|
48
|
+
|
|
49
|
+
import "@carbon/icons/es/chat--launch/24.js";
|
|
50
|
+
|
|
51
|
+
import "@carbon/icons/es/close/16.js";
|
|
52
|
+
|
|
53
|
+
import "@carbon/web-components/es/components/button/defs.js";
|
|
54
|
+
|
|
55
|
+
import "@carbon/web-components/es/components/button/button.js";
|
|
56
|
+
|
|
57
|
+
import "@carbon/web-components/es/components/layer/layer.js";
|
|
58
|
+
|
|
59
|
+
import "@carbon/ai-chat-components/es/react/chat-shell.js";
|
|
60
|
+
|
|
61
|
+
import "@carbon/icons/es/close--large/16.js";
|
|
62
|
+
|
|
63
|
+
import "@carbon/icons/es/home/16.js";
|
|
64
|
+
|
|
65
|
+
import "@carbon/icons/es/overflow-menu--vertical/16.js";
|
|
66
|
+
|
|
67
|
+
import "@carbon/icons/es/restart/16.js";
|
|
68
|
+
|
|
69
|
+
import "@carbon/icons/es/side-panel--close/16.js";
|
|
70
|
+
|
|
71
|
+
import "@carbon/icons/es/subtract--large/16.js";
|
|
72
|
+
|
|
73
|
+
import "@carbon/web-components/es/components/ai-label/defs.js";
|
|
74
|
+
|
|
75
|
+
import "@carbon/web-components/es/components/popover/defs.js";
|
|
76
|
+
|
|
77
|
+
import "@carbon/web-components/es/components/ai-label/ai-label-action-button.js";
|
|
78
|
+
|
|
79
|
+
import "@carbon/web-components/es/components/ai-label/ai-label.js";
|
|
80
|
+
|
|
81
|
+
import "@carbon/web-components/es/components/overflow-menu/overflow-menu.js";
|
|
82
|
+
|
|
83
|
+
import "@carbon/web-components/es/components/overflow-menu/overflow-menu-body.js";
|
|
84
|
+
|
|
85
|
+
import "@carbon/web-components/es/components/overflow-menu/overflow-menu-item.js";
|
|
86
|
+
|
|
87
|
+
import "lit/decorators.js";
|
|
48
88
|
|
|
49
89
|
import "lodash-es/throttle.js";
|
|
50
90
|
|
|
@@ -54,10 +94,6 @@ import "@carbon/icons/es/down-to-bottom/16.js";
|
|
|
54
94
|
|
|
55
95
|
import "@carbon/icons/es/screen--off/16.js";
|
|
56
96
|
|
|
57
|
-
import "@carbon/web-components/es/components/button/defs.js";
|
|
58
|
-
|
|
59
|
-
import "@carbon/web-components/es/components/button/button.js";
|
|
60
|
-
|
|
61
97
|
import "@carbon/icons/es/user--avatar/32.js";
|
|
62
98
|
|
|
63
99
|
import "@carbon/ai-chat-components/es/react/markdown.js";
|
|
@@ -98,6 +134,8 @@ import "@carbon/icons/es/logout/16.js";
|
|
|
98
134
|
|
|
99
135
|
import "@carbon/ai-chat-components/es/react/card.js";
|
|
100
136
|
|
|
137
|
+
import "focus-trap-react";
|
|
138
|
+
|
|
101
139
|
import "@carbon/icons/es/music/32.js";
|
|
102
140
|
|
|
103
141
|
import "@carbon/web-components/es/components/ai-skeleton/ai-skeleton-placeholder.js";
|
|
@@ -158,36 +196,6 @@ import "@carbon/ai-chat-components/es/react/tool-call-data.js";
|
|
|
158
196
|
|
|
159
197
|
import "@carbon/ai-chat-components/es/react/processing.js";
|
|
160
198
|
|
|
161
|
-
import "@carbon/icons/es/restart/16.js";
|
|
162
|
-
|
|
163
|
-
import "@carbon/web-components/es/components/chat-button/chat-button.js";
|
|
164
|
-
|
|
165
|
-
import "@carbon/icons/es/home/16.js";
|
|
166
|
-
|
|
167
|
-
import "@carbon/icons/es/close--large/16.js";
|
|
168
|
-
|
|
169
|
-
import "@carbon/icons/es/overflow-menu--vertical/16.js";
|
|
170
|
-
|
|
171
|
-
import "@carbon/icons/es/side-panel--close/16.js";
|
|
172
|
-
|
|
173
|
-
import "@carbon/icons/es/subtract--large/16.js";
|
|
174
|
-
|
|
175
|
-
import "@carbon/web-components/es/components/ai-label/defs.js";
|
|
176
|
-
|
|
177
|
-
import "@carbon/web-components/es/components/popover/defs.js";
|
|
178
|
-
|
|
179
|
-
import "@carbon/web-components/es/components/overflow-menu/overflow-menu.js";
|
|
180
|
-
|
|
181
|
-
import "@carbon/web-components/es/components/overflow-menu/overflow-menu-body.js";
|
|
182
|
-
|
|
183
|
-
import "@carbon/web-components/es/components/overflow-menu/overflow-menu-item.js";
|
|
184
|
-
|
|
185
|
-
import "lit/decorators.js";
|
|
186
|
-
|
|
187
|
-
import "@carbon/web-components/es/components/ai-label/ai-label-action-button.js";
|
|
188
|
-
|
|
189
|
-
import "@carbon/web-components/es/components/ai-label/ai-label.js";
|
|
190
|
-
|
|
191
199
|
import "@carbon/icons/es/send--filled/16.js";
|
|
192
200
|
|
|
193
201
|
import "@carbon/web-components/es/components/file-uploader/defs.js";
|
|
@@ -200,17 +208,15 @@ import "@carbon/web-components/es/globals/internal/icon-loader.js";
|
|
|
200
208
|
|
|
201
209
|
import "@carbon/icons/es/stop--filled/16.js";
|
|
202
210
|
|
|
203
|
-
import "@carbon/
|
|
204
|
-
|
|
205
|
-
import "@carbon/web-components/es/components/modal/modal-body.js";
|
|
211
|
+
import "@carbon/ai-chat-components/es/react/panel.js";
|
|
206
212
|
|
|
207
|
-
import "@carbon/icons/es/
|
|
213
|
+
import "@carbon/icons/es/chevron--down/20.js";
|
|
208
214
|
|
|
209
|
-
import "@carbon/icons/es/
|
|
215
|
+
import "@carbon/icons/es/close--large/20.js";
|
|
210
216
|
|
|
211
|
-
import "@carbon/
|
|
217
|
+
import "@carbon/ai-chat-components/es/react/toolbar.js";
|
|
212
218
|
|
|
213
|
-
import "@carbon/web-components/es/components/
|
|
219
|
+
import "@carbon/web-components/es/components/chat-button/chat-button.js";
|
|
214
220
|
|
|
215
221
|
let ChatContainerReact = class ChatContainerReact extends LitElement {
|
|
216
222
|
firstUpdated(changedProperties) {
|
|
@@ -237,7 +243,7 @@ const ReactChatContainer = React.memo(createComponent({
|
|
|
237
243
|
}));
|
|
238
244
|
|
|
239
245
|
function ChatContainer(props) {
|
|
240
|
-
const {onBeforeRender, onAfterRender, strings, serviceDeskFactory, serviceDesk, renderUserDefinedResponse, renderWriteableElements, element, onError, openChatByDefault, disclaimer, disableCustomElementMobileEnhancements, debug, exposeServiceManagerForTesting, injectCarbonTheme, aiEnabled, shouldTakeFocusIfOpensAutomatically, namespace,
|
|
246
|
+
const {onBeforeRender, onAfterRender, strings, serviceDeskFactory, serviceDesk, renderUserDefinedResponse, renderWriteableElements, element, onError, openChatByDefault, disclaimer, disableCustomElementMobileEnhancements, debug, exposeServiceManagerForTesting, injectCarbonTheme, aiEnabled, shouldTakeFocusIfOpensAutomatically, namespace, shouldSanitizeHTML, header, layout, messaging, isReadonly, persistFeedback, assistantName, locale, homescreen, launcher, input} = props;
|
|
241
247
|
const config = useMemo(() => ({
|
|
242
248
|
onError,
|
|
243
249
|
openChatByDefault,
|
|
@@ -249,7 +255,6 @@ function ChatContainer(props) {
|
|
|
249
255
|
aiEnabled,
|
|
250
256
|
shouldTakeFocusIfOpensAutomatically,
|
|
251
257
|
namespace,
|
|
252
|
-
enableFocusTrap,
|
|
253
258
|
shouldSanitizeHTML,
|
|
254
259
|
header,
|
|
255
260
|
layout,
|
|
@@ -261,7 +266,7 @@ function ChatContainer(props) {
|
|
|
261
266
|
homescreen,
|
|
262
267
|
launcher,
|
|
263
268
|
input
|
|
264
|
-
}), [ onError, openChatByDefault, disclaimer, disableCustomElementMobileEnhancements, debug, exposeServiceManagerForTesting, injectCarbonTheme, aiEnabled, shouldTakeFocusIfOpensAutomatically, namespace,
|
|
269
|
+
}), [ onError, openChatByDefault, disclaimer, disableCustomElementMobileEnhancements, debug, exposeServiceManagerForTesting, injectCarbonTheme, aiEnabled, shouldTakeFocusIfOpensAutomatically, namespace, shouldSanitizeHTML, header, layout, messaging, isReadonly, persistFeedback, assistantName, locale, homescreen, launcher, input ]);
|
|
265
270
|
const wrapperRef = useRef(null);
|
|
266
271
|
const [wrapper, setWrapper] = useState(null);
|
|
267
272
|
const [container, setContainer] = useState(null);
|
|
@@ -365,7 +370,7 @@ if (isBrowser() && !document.getElementById("cds-aichat-custom-element-styles"))
|
|
|
365
370
|
}
|
|
366
371
|
|
|
367
372
|
function ChatCustomElement(props) {
|
|
368
|
-
const {strings, serviceDeskFactory, serviceDesk, onBeforeRender, onAfterRender, renderUserDefinedResponse, renderWriteableElements, className, id, onViewChange, onViewPreChange, onError, openChatByDefault, disclaimer, disableCustomElementMobileEnhancements, debug, exposeServiceManagerForTesting, injectCarbonTheme, aiEnabled, shouldTakeFocusIfOpensAutomatically, namespace,
|
|
373
|
+
const {strings, serviceDeskFactory, serviceDesk, onBeforeRender, onAfterRender, renderUserDefinedResponse, renderWriteableElements, className, id, onViewChange, onViewPreChange, onError, openChatByDefault, disclaimer, disableCustomElementMobileEnhancements, debug, exposeServiceManagerForTesting, injectCarbonTheme, aiEnabled, shouldTakeFocusIfOpensAutomatically, namespace, shouldSanitizeHTML, header, layout, messaging, isReadonly, persistFeedback, assistantName, locale, homescreen, launcher, input} = props;
|
|
369
374
|
const [customElement, setCustomElement] = useState();
|
|
370
375
|
const onBeforeRenderOverride = useCallback(async instance => {
|
|
371
376
|
function defaultViewChangeHandler(event) {
|
|
@@ -404,7 +409,6 @@ function ChatCustomElement(props) {
|
|
|
404
409
|
aiEnabled,
|
|
405
410
|
shouldTakeFocusIfOpensAutomatically,
|
|
406
411
|
namespace,
|
|
407
|
-
enableFocusTrap,
|
|
408
412
|
shouldSanitizeHTML,
|
|
409
413
|
header,
|
|
410
414
|
layout,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiChatEntry.js","sources":["../../../../src/react/ChatContainer.tsx","../../../../src/react/ChatCustomElement.tsx"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025\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 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 { 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(props: ChatContainerProps) {\n const {\n onBeforeRender,\n onAfterRender,\n strings,\n serviceDeskFactory,\n serviceDesk,\n renderUserDefinedResponse,\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 enableFocusTrap,\n shouldSanitizeHTML,\n header,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n locale,\n homescreen,\n launcher,\n input,\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 enableFocusTrap,\n shouldSanitizeHTML,\n header,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n locale,\n homescreen,\n launcher,\n input,\n }),\n [\n onError,\n openChatByDefault,\n disclaimer,\n disableCustomElementMobileEnhancements,\n debug,\n exposeServiceManagerForTesting,\n injectCarbonTheme,\n aiEnabled,\n shouldTakeFocusIfOpensAutomatically,\n namespace,\n enableFocusTrap,\n shouldSanitizeHTML,\n header,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n locale,\n homescreen,\n launcher,\n input,\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 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 onBeforeRender?.(instance);\n }\n },\n [onBeforeRender],\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} />\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 renderWriteableElements={renderWriteableElements}\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\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, { useCallback, useState } 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(props: ChatCustomElementProps) {\n const {\n strings,\n serviceDeskFactory,\n serviceDesk,\n onBeforeRender,\n onAfterRender,\n renderUserDefinedResponse,\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 enableFocusTrap,\n shouldSanitizeHTML,\n header,\n layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n locale,\n homescreen,\n launcher,\n input,\n } = props;\n\n const [customElement, setCustomElement] = useState<HTMLDivElement>();\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 if (customElement) {\n if (event.newViewState.mainWindow) {\n // Show: remove the hidden class, let the provided className handle sizing\n customElement.classList.remove(\"cds-aichat--hidden\");\n } else {\n // Hide: add the hidden class to set size to 0x0\n customElement.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, customElement],\n );\n\n return (\n <div className={className} id={id} ref={setCustomElement}>\n {customElement && (\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 enableFocusTrap={enableFocusTrap}\n shouldSanitizeHTML={shouldSanitizeHTML}\n header={header}\n layout={layout}\n messaging={messaging}\n isReadonly={isReadonly}\n persistFeedback={persistFeedback}\n assistantName={assistantName}\n locale={locale}\n homescreen={homescreen}\n launcher={launcher}\n // Other ChatContainer props\n strings={strings}\n serviceDeskFactory={serviceDeskFactory}\n serviceDesk={serviceDesk}\n onBeforeRender={onBeforeRenderOverride}\n onAfterRender={onAfterRender}\n renderUserDefinedResponse={renderUserDefinedResponse}\n renderWriteableElements={renderWriteableElements}\n element={customElement}\n input={input}\n />\n )}\n </div>\n );\n}\n\nexport { ChatCustomElement, ChatCustomElementProps };\n"],"names":["ChatContainerReact","LitElement","firstUpdated","changedProperties","super","this","dispatchEvent","CustomEvent","bubbles","styles","css","__decorate","carbonElement","ReactChatContainer","React","memo","createComponent","tagName","elementClass","react","ChatContainer","props","onBeforeRender","onAfterRender","strings","serviceDeskFactory","serviceDesk","renderUserDefinedResponse","renderWriteableElements","element","onError","openChatByDefault","disclaimer","disableCustomElementMobileEnhancements","debug","exposeServiceManagerForTesting","injectCarbonTheme","aiEnabled","shouldTakeFocusIfOpensAutomatically","namespace","enableFocusTrap","shouldSanitizeHTML","header","layout","messaging","isReadonly","persistFeedback","assistantName","locale","homescreen","launcher","input","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","onBeforeRenderOverride","useCallback","instance","addWriteableElementSlots","slots","Object","entries","writeableElements","map","writeableElement","key","setAttribute","isBrowser","Fragment","ref","createPortal","ChatAppEntry","setParentInstance","chatWrapper","customElementStylesheet","CSSStyleSheet","hideStyles","getElementById","replaceSync","adoptedStyleSheets","style","id","textContent","head","ChatCustomElement","className","onViewChange","onViewPreChange","customElement","setCustomElement","async","defaultViewChangeHandler","event","newViewState","mainWindow","remove","on","type","BusEventType","VIEW_PRE_CHANGE","handler","VIEW_CHANGE"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAMA,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,cAAcC;EACrB,OAAMC,gBACUC,eACDC,SACNC,oBACWC,aACPC,2BACcC,yBACFC,SAChBC,SAEAC,mBACUC,YACPC,wCAC4BC,OACjCC,gCACyBC,mBACbC,WACRC,qCAC0BC,WAC1BC,iBACMC,oBACGC,QACZC,QACAC,WACGC,YACCC,iBACKC,eACFC,QACPC,YACIC,UACFC,SAEN9B;EAEJ,MAAM+B,SAASC,QACb,OAAA;IACEvB;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;MAEF,EACErB,SACAC,mBACAC,YACAC,wCACAC,OACAC,gCACAC,mBACAC,WACAC,qCACAC,WACAC,iBACAC,oBACAC,QACAC,QACAC,WACAC,YACAC,iBACAC,eACAC,QACAC,YACAC,UACAC;EAIJ,MAAMG,aAA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AI6C,iBAAiB;MACnB9B,SAASuC,GAAG;QACVC,MAAMC,aAAaC;QACnBC,SAASb;;AAEb;IAEA9B,SAASuC,GAAG;MACVC,MAAMC,aAAaG;MACnBD,SAASd,gBAAgBK;;IAG3B,OAAOvG,iBAAiBqE;KAE1B,EAAC8B,iBAAiBD,cAAclG,gBAAgBoG;EAGlD,OACE5G,MAAA4D,cAAA,OAAA;IAAK6C;IAAsBJ;IAAQZ,KAAKoB;KACrCD,iBACC5G,oBAACM;IAECU;IACAC;IACAC;IACAC;IAGAC;IACAC;IACAC;IACAC;IACAC;IAGAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IAEA1B;IACAC;IACAC;IACAJ,gBAAgBmE;IAChBlE;IACAI;IACAC;IACAC,SAAS6F;IACTvE;;AAKV;;"}
|
|
1
|
+
{"version":3,"file":"aiChatEntry.js","sources":["../../../../src/react/ChatContainer.tsx","../../../../src/react/ChatCustomElement.tsx"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025\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 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 { 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(props: ChatContainerProps) {\n const {\n onBeforeRender,\n onAfterRender,\n strings,\n serviceDeskFactory,\n serviceDesk,\n renderUserDefinedResponse,\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 layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n locale,\n homescreen,\n launcher,\n input,\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 layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n locale,\n homescreen,\n launcher,\n input,\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 layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n locale,\n homescreen,\n launcher,\n input,\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 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 onBeforeRender?.(instance);\n }\n },\n [onBeforeRender],\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} />\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 renderWriteableElements={renderWriteableElements}\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\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, { useCallback, useState } 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(props: ChatCustomElementProps) {\n const {\n strings,\n serviceDeskFactory,\n serviceDesk,\n onBeforeRender,\n onAfterRender,\n renderUserDefinedResponse,\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 layout,\n messaging,\n isReadonly,\n persistFeedback,\n assistantName,\n locale,\n homescreen,\n launcher,\n input,\n } = props;\n\n const [customElement, setCustomElement] = useState<HTMLDivElement>();\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 if (customElement) {\n if (event.newViewState.mainWindow) {\n // Show: remove the hidden class, let the provided className handle sizing\n customElement.classList.remove(\"cds-aichat--hidden\");\n } else {\n // Hide: add the hidden class to set size to 0x0\n customElement.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, customElement],\n );\n\n return (\n <div className={className} id={id} ref={setCustomElement}>\n {customElement && (\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 layout={layout}\n messaging={messaging}\n isReadonly={isReadonly}\n persistFeedback={persistFeedback}\n assistantName={assistantName}\n locale={locale}\n homescreen={homescreen}\n launcher={launcher}\n // Other ChatContainer props\n strings={strings}\n serviceDeskFactory={serviceDeskFactory}\n serviceDesk={serviceDesk}\n onBeforeRender={onBeforeRenderOverride}\n onAfterRender={onAfterRender}\n renderUserDefinedResponse={renderUserDefinedResponse}\n renderWriteableElements={renderWriteableElements}\n element={customElement}\n input={input}\n />\n )}\n </div>\n );\n}\n\nexport { ChatCustomElement, ChatCustomElementProps };\n"],"names":["ChatContainerReact","LitElement","firstUpdated","changedProperties","super","this","dispatchEvent","CustomEvent","bubbles","styles","css","__decorate","carbonElement","ReactChatContainer","React","memo","createComponent","tagName","elementClass","react","ChatContainer","props","onBeforeRender","onAfterRender","strings","serviceDeskFactory","serviceDesk","renderUserDefinedResponse","renderWriteableElements","element","onError","openChatByDefault","disclaimer","disableCustomElementMobileEnhancements","debug","exposeServiceManagerForTesting","injectCarbonTheme","aiEnabled","shouldTakeFocusIfOpensAutomatically","namespace","shouldSanitizeHTML","header","layout","messaging","isReadonly","persistFeedback","assistantName","locale","homescreen","launcher","input","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","onBeforeRenderOverride","useCallback","instance","addWriteableElementSlots","slots","Object","entries","writeableElements","map","writeableElement","key","setAttribute","isBrowser","Fragment","ref","createPortal","ChatAppEntry","setParentInstance","chatWrapper","customElementStylesheet","CSSStyleSheet","hideStyles","getElementById","replaceSync","adoptedStyleSheets","style","id","textContent","head","ChatCustomElement","className","onViewChange","onViewPreChange","customElement","setCustomElement","async","defaultViewChangeHandler","event","newViewState","mainWindow","remove","on","type","BusEventType","VIEW_PRE_CHANGE","handler","VIEW_CHANGE"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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