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

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-cloud/ai-kit-ui",
3
- "version": "1.5.8",
3
+ "version": "1.5.10",
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.4",
25
+ "@smart-cloud/ai-kit-core": "^1.5.5",
26
26
  "@smart-cloud/wpsuite-core": "^2.3.2",
27
27
  "@tabler/icons-react": "^3.46.0",
28
28
  "chroma-js": "^3.2.0",
@@ -47,6 +47,7 @@ import { translations } from "../i18n";
47
47
  import { PoweredBy } from "../poweredBy";
48
48
  import { useAiRun } from "../useAiRun";
49
49
  import { AiKitShellInjectedProps, withAiKitShell } from "../withAiKitShell";
50
+ import { normalizeInitialFilterValues } from "./initialFilters";
50
51
 
51
52
  I18n.putVocabularies(translations);
52
53
 
@@ -198,6 +199,9 @@ const DocSearchBase: FC<Props> = (props) => {
198
199
  enableUserFilters = false,
199
200
  availableCategories,
200
201
  availableTags,
202
+ initialSelectedCategories,
203
+ initialSelectedSubcategories,
204
+ initialSelectedTags,
201
205
 
202
206
  variation,
203
207
  rootElement,
@@ -219,12 +223,21 @@ const DocSearchBase: FC<Props> = (props) => {
219
223
  const analyserRef = useRef<AnalyserNode | null>(null);
220
224
 
221
225
  // User filter states
222
- const [filtersOpen, setFiltersOpen] = useState(false);
223
- const [selectedCategories, setSelectedCategories] = useState<string[]>([]);
226
+ const [filtersOpen, setFiltersOpen] = useState(
227
+ () =>
228
+ normalizeInitialFilterValues(initialSelectedCategories).length > 0 ||
229
+ normalizeInitialFilterValues(initialSelectedSubcategories).length > 0 ||
230
+ normalizeInitialFilterValues(initialSelectedTags).length > 0,
231
+ );
232
+ const [selectedCategories, setSelectedCategories] = useState<string[]>(() =>
233
+ normalizeInitialFilterValues(initialSelectedCategories),
234
+ );
224
235
  const [selectedSubcategories, setSelectedSubcategories] = useState<string[]>(
225
- [],
236
+ () => normalizeInitialFilterValues(initialSelectedSubcategories),
237
+ );
238
+ const [selectedTags, setSelectedTags] = useState<string[]>(() =>
239
+ normalizeInitialFilterValues(initialSelectedTags),
226
240
  );
227
- const [selectedTags, setSelectedTags] = useState<string[]>([]);
228
241
  const [tagSearchValue, setTagSearchValue] = useState<string>("");
229
242
  const [metadataOptions, setMetadataOptions] =
230
243
  useState<MetadataOptions | null>(null);
@@ -0,0 +1,10 @@
1
+ export const normalizeInitialFilterValues = (
2
+ values: readonly string[] | undefined,
3
+ ): string[] =>
4
+ Array.from(
5
+ new Set(
6
+ (values ?? [])
7
+ .map((value) => value.trim())
8
+ .filter((value) => value.length > 0),
9
+ ),
10
+ );
@@ -312,6 +312,23 @@ export function withAiKitShell<P extends object>(
312
312
  : "light"
313
313
  : colorMode;
314
314
 
315
+ // Modal content is portalled into a different shadow tree. Mantine
316
+ // color-scheme attributes do not cross that boundary, so copy the
317
+ // contextual attributes that the global overlay needs explicitly.
318
+ if (usesSeparateModalPortal && modalRootElement) {
319
+ modalRootElement.setAttribute("data-ai-kit-variation", "modal");
320
+ modalRootElement.setAttribute(
321
+ "data-mantine-color-scheme",
322
+ resolved ?? "light",
323
+ );
324
+ modalRootElement.setAttribute("dir", currentDirection);
325
+ if (currentLanguage) {
326
+ modalRootElement.setAttribute("lang", currentLanguage);
327
+ } else {
328
+ modalRootElement.removeAttribute("lang");
329
+ }
330
+ }
331
+
315
332
  return (
316
333
  <DirectionProvider initialDirection={currentDirection}>
317
334
  <MantineProvider
@@ -0,0 +1,20 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+
4
+ import { normalizeInitialFilterValues } from "../src/doc-search/initialFilters.ts";
5
+
6
+ test("normalizes, deduplicates, and preserves initial DocSearch filters", () => {
7
+ assert.deepEqual(
8
+ normalizeInitialFilterValues([
9
+ " Solutions ",
10
+ "",
11
+ "Solution Guide",
12
+ "Solutions",
13
+ ]),
14
+ ["Solutions", "Solution Guide"],
15
+ );
16
+ });
17
+
18
+ test("uses an empty selection when initial DocSearch filters are omitted", () => {
19
+ assert.deepEqual(normalizeInitialFilterValues(undefined), []);
20
+ });