@smart-cloud/ai-kit-ui 1.5.7 → 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.
- package/dist/ShadowBoundary.d.ts +3 -1
- package/dist/index.cjs +9 -9
- package/dist/index.js +9 -9
- package/dist/withAiKitShell.d.ts +8 -1
- package/package.json +1 -1
- package/src/ShadowBoundary.tsx +4 -0
- package/src/ai-chatbot/AiChatbot.tsx +1 -0
- package/src/ai-feature/AiFeature.tsx +5 -1
- package/src/doc-search/DocSearch.tsx +5 -1
- package/src/withAiKitShell.tsx +50 -17
package/dist/withAiKitShell.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
package/src/ShadowBoundary.tsx
CHANGED
|
@@ -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();
|
|
@@ -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
|
-
? {
|
|
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
|
-
? {
|
|
718
|
+
? {
|
|
719
|
+
target: modalRootElement ?? rootElement,
|
|
720
|
+
reuseTargetNode: true,
|
|
721
|
+
}
|
|
718
722
|
: undefined
|
|
719
723
|
}
|
|
720
724
|
data-ai-kit-theme={colorMode}
|
package/src/withAiKitShell.tsx
CHANGED
|
@@ -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,7 +49,7 @@ 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?:
|
|
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.
|
|
@@ -59,6 +66,9 @@ export function withAiKitShell<P extends object>(
|
|
|
59
66
|
} = { ...props, ...propOverrides } as AiWorkerProps & P;
|
|
60
67
|
|
|
61
68
|
const [host, setHost] = useState<HTMLElement | null>(null);
|
|
69
|
+
const [modalRootElement, setModalRootElement] =
|
|
70
|
+
useState<HTMLDivElement | null>(null);
|
|
71
|
+
const overlayWholeComponent = Boolean(propOverrides?.overlayWholeComponent);
|
|
62
72
|
const languageInStore: string | undefined | null = useSelect(() =>
|
|
63
73
|
getStoreSelect(store).getLanguage(),
|
|
64
74
|
);
|
|
@@ -254,21 +264,38 @@ export function withAiKitShell<P extends object>(
|
|
|
254
264
|
}
|
|
255
265
|
}, [host, themeOverrides, themeOverridesHash]);
|
|
256
266
|
|
|
267
|
+
const usesSeparateModalPortal =
|
|
268
|
+
variation === "modal" && !overlayWholeComponent;
|
|
269
|
+
|
|
257
270
|
return (
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
336
|
+
}}
|
|
337
|
+
</ShadowBoundary>
|
|
338
|
+
</>
|
|
306
339
|
);
|
|
307
340
|
};
|
|
308
341
|
|