@smart-cloud/ai-kit-ui 1.5.6 → 1.5.8

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.
@@ -3,5 +3,12 @@ import { type ComponentType } from "react";
3
3
  export type AiKitShellInjectedProps = {
4
4
  language?: string;
5
5
  rootElement: HTMLElement;
6
+ /** Global portal target for an opened modal; its trigger stays local. */
7
+ modalRootElement?: HTMLElement;
6
8
  };
7
- export declare function withAiKitShell<P extends object>(RootComponent: ComponentType<P & AiKitShellInjectedProps>, propOverrides?: Partial<AiWorkerProps>): import("react").FC<P & Partial<AiWorkerProps>>;
9
+ type AiKitShellOptions = Partial<AiWorkerProps> & {
10
+ /** Used only by intentionally floating components such as the chatbot. */
11
+ overlayWholeComponent?: boolean;
12
+ };
13
+ export declare function withAiKitShell<P extends object>(RootComponent: ComponentType<P & AiKitShellInjectedProps>, propOverrides?: AiKitShellOptions): import("react").FC<P & Partial<AiWorkerProps>>;
14
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-cloud/ai-kit-ui",
3
- "version": "1.5.6",
3
+ "version": "1.5.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "@emotion/cache": "^11.14.0",
23
23
  "@emotion/react": "^11.14.0",
24
24
  "@mantine/colors-generator": "^8.3.18",
25
- "@smart-cloud/ai-kit-core": "^1.5.3",
25
+ "@smart-cloud/ai-kit-core": "^1.5.4",
26
26
  "@smart-cloud/wpsuite-core": "^2.3.2",
27
27
  "@tabler/icons-react": "^3.46.0",
28
28
  "chroma-js": "^3.2.0",
@@ -34,6 +34,8 @@ export type ShadowBoundaryProps = {
34
34
  overlayRootId?: string;
35
35
 
36
36
  setHost: React.Dispatch<SetStateAction<HTMLElement | null>>;
37
+ /** Optional notification for consumers that need a distinct modal portal. */
38
+ setRootElement?: React.Dispatch<SetStateAction<HTMLDivElement | null>>;
37
39
  children: (api: {
38
40
  /** Portal target element inside the shadow root. */
39
41
  rootElement: HTMLDivElement;
@@ -91,6 +93,7 @@ export function ShadowBoundary({
91
93
  mode = "local",
92
94
  overlayRootId = "ai-kit-overlay-root",
93
95
  setHost,
96
+ setRootElement,
94
97
  }: ShadowBoundaryProps) {
95
98
  const hostRef = useRef<HTMLDivElement | null>(null);
96
99
 
@@ -187,6 +190,7 @@ export function ShadowBoundary({
187
190
 
188
191
  setShadowRoot(shadow);
189
192
  setPortalTarget(rootEl);
193
+ setRootElement?.(rootEl);
190
194
 
191
195
  return () => {
192
196
  mo.disconnect();
@@ -2279,4 +2279,5 @@ const AiChatbotBase: FC<AiChatbotProps & AiKitShellInjectedProps> = (props) => {
2279
2279
  export const AiChatbot = withAiKitShell(AiChatbotBase, {
2280
2280
  showOpenButton: true,
2281
2281
  variation: "modal",
2282
+ overlayWholeComponent: true,
2282
2283
  });
@@ -417,6 +417,7 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
417
417
  language,
418
418
  direction,
419
419
  rootElement,
420
+ modalRootElement,
420
421
  } = props;
421
422
 
422
423
  const [languageOverride, setLanguageOverride] = useState<
@@ -1462,7 +1463,10 @@ Follow these additional instructions: ${instructions}`
1462
1463
  size="md"
1463
1464
  portalProps={
1464
1465
  variation === "modal"
1465
- ? { target: rootElement, reuseTargetNode: true }
1466
+ ? {
1467
+ target: modalRootElement ?? rootElement,
1468
+ reuseTargetNode: true,
1469
+ }
1466
1470
  : undefined
1467
1471
  }
1468
1472
  data-ai-kit-theme={colorMode}
@@ -201,6 +201,7 @@ const DocSearchBase: FC<Props> = (props) => {
201
201
 
202
202
  variation,
203
203
  rootElement,
204
+ modalRootElement,
204
205
  colorMode,
205
206
  language,
206
207
  onClose,
@@ -714,7 +715,10 @@ const DocSearchBase: FC<Props> = (props) => {
714
715
  size="xl"
715
716
  portalProps={
716
717
  variation === "modal"
717
- ? { target: rootElement, reuseTargetNode: true }
718
+ ? {
719
+ target: modalRootElement ?? rootElement,
720
+ reuseTargetNode: true,
721
+ }
718
722
  : undefined
719
723
  }
720
724
  data-ai-kit-theme={colorMode}
@@ -20,6 +20,13 @@ import { ShadowBoundary } from "./ShadowBoundary";
20
20
  export type AiKitShellInjectedProps = {
21
21
  language?: string;
22
22
  rootElement: HTMLElement;
23
+ /** Global portal target for an opened modal; its trigger stays local. */
24
+ modalRootElement?: HTMLElement;
25
+ };
26
+
27
+ type AiKitShellOptions = Partial<AiWorkerProps> & {
28
+ /** Used only by intentionally floating components such as the chatbot. */
29
+ overlayWholeComponent?: boolean;
23
30
  };
24
31
 
25
32
  const hashStringDjb2 = (str: string): string => {
@@ -42,14 +49,13 @@ const STYLE_TEXT_ID = "ai-kit-style-text";
42
49
 
43
50
  export function withAiKitShell<P extends object>(
44
51
  RootComponent: ComponentType<P & AiKitShellInjectedProps>,
45
- propOverrides?: Partial<AiWorkerProps>,
52
+ propOverrides?: AiKitShellOptions,
46
53
  ) {
47
54
  const Wrapped: React.FC<P & Partial<AiWorkerProps>> = (props) => {
48
55
  // Duck-typing merge: supports both explicit shell props or defaults.
49
56
  const {
50
57
  store,
51
58
  variation,
52
- showOpenButton,
53
59
  colors,
54
60
  colorMode,
55
61
  primaryColor,
@@ -60,6 +66,9 @@ export function withAiKitShell<P extends object>(
60
66
  } = { ...props, ...propOverrides } as AiWorkerProps & P;
61
67
 
62
68
  const [host, setHost] = useState<HTMLElement | null>(null);
69
+ const [modalRootElement, setModalRootElement] =
70
+ useState<HTMLDivElement | null>(null);
71
+ const overlayWholeComponent = Boolean(propOverrides?.overlayWholeComponent);
63
72
  const languageInStore: string | undefined | null = useSelect(() =>
64
73
  getStoreSelect(store).getLanguage(),
65
74
  );
@@ -255,20 +264,38 @@ export function withAiKitShell<P extends object>(
255
264
  }
256
265
  }, [host, themeOverrides, themeOverridesHash]);
257
266
 
267
+ const usesSeparateModalPortal =
268
+ variation === "modal" && !overlayWholeComponent;
269
+
258
270
  return (
259
- <ShadowBoundary
260
- mode={variation === "modal" && !showOpenButton ? "overlay" : "local"}
261
- variation={variation}
262
- overlayRootId="ai-kit-overlay-root"
263
- stylesheets={stylesheets}
264
- setHost={setHost}
265
- rootElementId={
266
- variation === "modal" && !showOpenButton
267
- ? "ai-kit-portal-root"
268
- : "ai-kit-inline-root"
269
- }
270
- >
271
- {({ rootElement }) => {
271
+ <>
272
+ {usesSeparateModalPortal ? (
273
+ <ShadowBoundary
274
+ mode="overlay"
275
+ overlayRootId="ai-kit-overlay-root"
276
+ stylesheets={stylesheets}
277
+ setHost={() => undefined}
278
+ setRootElement={setModalRootElement}
279
+ rootElementId="ai-kit-portal-root"
280
+ >
281
+ {() => null}
282
+ </ShadowBoundary>
283
+ ) : null}
284
+ <ShadowBoundary
285
+ // Header controls must remain in their authored block. Only the
286
+ // opened dialog belongs in the global, viewport-sized overlay.
287
+ mode={overlayWholeComponent && variation === "modal" ? "overlay" : "local"}
288
+ variation={variation}
289
+ overlayRootId="ai-kit-overlay-root"
290
+ stylesheets={stylesheets}
291
+ setHost={setHost}
292
+ rootElementId={
293
+ overlayWholeComponent && variation === "modal"
294
+ ? "ai-kit-portal-root"
295
+ : "ai-kit-inline-root"
296
+ }
297
+ >
298
+ {({ rootElement }) => {
272
299
  rootElement.setAttribute(
273
300
  "data-ai-kit-variation",
274
301
  variation || "default",
@@ -297,12 +324,18 @@ export function withAiKitShell<P extends object>(
297
324
  colorMode={resolved}
298
325
  language={currentLanguage}
299
326
  rootElement={rootElement}
327
+ modalRootElement={
328
+ usesSeparateModalPortal
329
+ ? modalRootElement ?? rootElement
330
+ : rootElement
331
+ }
300
332
  />
301
333
  </MantineProvider>
302
334
  </DirectionProvider>
303
335
  );
304
- }}
305
- </ShadowBoundary>
336
+ }}
337
+ </ShadowBoundary>
338
+ </>
306
339
  );
307
340
  };
308
341