@btst/plugin-search 1.0.0 → 1.1.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.
Files changed (48) hide show
  1. package/dist/api/index.cjs +2 -0
  2. package/dist/api/index.d.cts +3 -2
  3. package/dist/api/index.d.mts +3 -2
  4. package/dist/api/index.d.ts +3 -2
  5. package/dist/api/index.mjs +1 -1
  6. package/dist/api/operations.cjs +20 -18
  7. package/dist/api/operations.mjs +15 -13
  8. package/dist/client/components/index.cjs +2 -0
  9. package/dist/client/components/index.d.cts +15 -7
  10. package/dist/client/components/index.d.mts +15 -7
  11. package/dist/client/components/index.d.ts +15 -7
  12. package/dist/client/components/index.mjs +1 -0
  13. package/dist/client/components/pages/search-page.internal.cjs +12 -4
  14. package/dist/client/components/pages/search-page.internal.mjs +12 -4
  15. package/dist/client/components/search-dialog.cjs +93 -57
  16. package/dist/client/components/search-dialog.mjs +94 -58
  17. package/dist/client/components/search-highlight.cjs +22 -0
  18. package/dist/client/components/search-highlight.mjs +20 -0
  19. package/dist/client/components/search-results.cjs +31 -24
  20. package/dist/client/components/search-results.mjs +32 -25
  21. package/dist/client/hooks/use-search-state.cjs +1 -1
  22. package/dist/client/hooks/use-search-state.mjs +1 -1
  23. package/dist/client/index.d.cts +3 -12
  24. package/dist/client/index.d.mts +3 -12
  25. package/dist/client/index.d.ts +3 -12
  26. package/dist/constants.cjs +11 -0
  27. package/dist/constants.mjs +6 -0
  28. package/dist/providers.cjs +21 -2
  29. package/dist/providers.d.cts +10 -3
  30. package/dist/providers.d.mts +10 -3
  31. package/dist/providers.d.ts +10 -3
  32. package/dist/providers.mjs +20 -3
  33. package/dist/query-keys.cjs +2 -1
  34. package/dist/query-keys.mjs +2 -1
  35. package/dist/response-schema.cjs +57 -0
  36. package/dist/response-schema.mjs +40 -0
  37. package/dist/schemas.cjs +10 -9
  38. package/dist/schemas.d.cts +39 -8
  39. package/dist/schemas.d.mts +39 -8
  40. package/dist/schemas.d.ts +39 -8
  41. package/dist/schemas.mjs +5 -5
  42. package/dist/shared/plugin-search.BDlgoPEb.d.ts +18 -0
  43. package/dist/shared/plugin-search.QfsGS8no.d.cts +18 -0
  44. package/dist/shared/plugin-search.WwLtD6lV.d.mts +18 -0
  45. package/dist/types.d.cts +4 -2
  46. package/dist/types.d.mts +4 -2
  47. package/dist/types.d.ts +4 -2
  48. package/package.json +3 -3
@@ -1,12 +1,14 @@
1
1
  'use client';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
- import { useState, useRef, useEffect } from 'react';
3
+ import { useRef, useState, useEffect } from 'react';
4
+ import { cn } from '../../ui/src/lib/utils.mjs';
4
5
  import { useStack } from '@btst/stack/context';
5
6
  import { Button } from '../../ui/src/components/button.mjs';
6
7
  import { Command, CommandInput, CommandList, CommandItem } from '../../ui/src/components/command.mjs';
7
8
  import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '../../ui/src/components/dialog.mjs';
8
9
  import { SearchStatus, SearchPagination } from './search-results.mjs';
9
10
  import { SourceFilter } from './source-filter.mjs';
11
+ import { SearchHighlight } from './search-highlight.mjs';
10
12
  import { useSearchState } from '../hooks/use-search-state.mjs';
11
13
 
12
14
  function SearchDialog({
@@ -16,9 +18,12 @@ function SearchDialog({
16
18
  className,
17
19
  placeholder = "Search content\u2026",
18
20
  emptyMessage,
19
- title = "Search"
21
+ title = "Search",
22
+ renderResult,
23
+ renderLoading
20
24
  }) {
21
25
  const { router } = useStack();
26
+ const inputRef = useRef(null);
22
27
  const { state, setState, result, fixedSources, loading } = useSearchState({
23
28
  sources,
24
29
  enabled: open
@@ -28,32 +33,71 @@ function SearchDialog({
28
33
  else window.location.assign(href);
29
34
  onOpenChange(false);
30
35
  };
31
- return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(DialogContent, { className, "data-testid": "search-modal", children: [
32
- /* @__PURE__ */ jsxs(DialogHeader, { children: [
33
- /* @__PURE__ */ jsx(DialogTitle, { children: title }),
34
- /* @__PURE__ */ jsx(DialogDescription, { children: "Find content across the available sources." })
35
- ] }),
36
- /* @__PURE__ */ jsxs(Command, { shouldFilter: false, children: [
37
- /* @__PURE__ */ jsx(
38
- CommandInput,
39
- {
40
- "aria-label": "Search",
41
- "data-testid": "search-input",
42
- placeholder,
43
- value: state.q,
44
- maxLength: 200,
45
- onValueChange: (q) => setState({ q, page: 1 }, { replace: true })
46
- }
36
+ return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(
37
+ DialogContent,
38
+ {
39
+ className: cn(
40
+ "max-h-[calc(100dvh-2rem)] overflow-y-auto motion-reduce:animate-none",
41
+ className
47
42
  ),
48
- !fixedSources && result.data && /* @__PURE__ */ jsx("div", { className: "p-3", children: /* @__PURE__ */ jsx(
49
- SourceFilter,
50
- {
51
- sources: result.data.sources,
52
- value: state.sources,
53
- onChange: (value) => setState({ sources: value, page: 1 })
54
- }
55
- ) }),
56
- /* @__PURE__ */ jsxs(CommandList, { "aria-busy": loading, className: "max-h-[400px]", children: [
43
+ "data-testid": "search-modal",
44
+ children: [
45
+ /* @__PURE__ */ jsxs(DialogHeader, { children: [
46
+ /* @__PURE__ */ jsx(DialogTitle, { children: title }),
47
+ /* @__PURE__ */ jsx(DialogDescription, { children: "Find content across the available sources." })
48
+ ] }),
49
+ /* @__PURE__ */ jsxs(Command, { shouldFilter: false, className: "h-auto min-w-0", children: [
50
+ /* @__PURE__ */ jsx(
51
+ CommandInput,
52
+ {
53
+ ref: inputRef,
54
+ "aria-label": "Search",
55
+ "data-testid": "search-input",
56
+ placeholder,
57
+ value: state.q,
58
+ maxLength: 200,
59
+ onValueChange: (q) => setState({ q, page: 1 }, { replace: true })
60
+ }
61
+ ),
62
+ !fixedSources && result.data && /* @__PURE__ */ jsx("div", { className: "p-3", children: /* @__PURE__ */ jsx(
63
+ SourceFilter,
64
+ {
65
+ sources: result.data.sources,
66
+ value: state.sources,
67
+ onChange: (value) => setState({ sources: value, page: 1 })
68
+ }
69
+ ) }),
70
+ /* @__PURE__ */ jsx(
71
+ CommandList,
72
+ {
73
+ "aria-label": "Search results",
74
+ "aria-busy": loading,
75
+ className: "max-h-[min(400px,40dvh)]",
76
+ children: !result.error && !loading && result.data?.items.map((item) => /* @__PURE__ */ jsx(
77
+ CommandItem,
78
+ {
79
+ value: item.key,
80
+ "aria-label": `${item.title}, ${item.sourceLabel}`,
81
+ "data-testid": "search-result",
82
+ onSelect: () => void navigate(item.href),
83
+ className: "flex min-w-0 flex-col items-start gap-2 border-b px-4 py-3 [overflow-wrap:anywhere]",
84
+ children: renderResult ? renderResult(item, state.q) : /* @__PURE__ */ jsxs(Fragment, { children: [
85
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: item.sourceLabel }),
86
+ /* @__PURE__ */ jsx("span", { className: "font-medium", children: /* @__PURE__ */ jsx(SearchHighlight, { text: item.title, query: state.q }) }),
87
+ item.snippet && /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: /* @__PURE__ */ jsx(
88
+ SearchHighlight,
89
+ {
90
+ text: item.snippet,
91
+ query: state.q
92
+ }
93
+ ) })
94
+ ] })
95
+ },
96
+ item.key
97
+ ))
98
+ }
99
+ )
100
+ ] }),
57
101
  /* @__PURE__ */ jsx(
58
102
  SearchStatus,
59
103
  {
@@ -62,39 +106,28 @@ function SearchDialog({
62
106
  loading,
63
107
  error: result.error,
64
108
  emptyMessage,
65
- onRetry: () => void result.refetch()
109
+ onRetry: () => {
110
+ void result.refetch();
111
+ inputRef.current?.focus();
112
+ },
113
+ renderLoading
66
114
  }
67
115
  ),
68
- !result.error && !loading && result.data?.items.map((item) => /* @__PURE__ */ jsxs(
69
- CommandItem,
70
- {
71
- value: item.key,
72
- "data-testid": "search-result",
73
- onSelect: () => void navigate(item.href),
74
- className: "flex flex-col items-start gap-2 border-b px-4 py-3",
75
- children: [
76
- /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: item.sourceLabel }),
77
- /* @__PURE__ */ jsx("span", { className: "font-medium", children: item.title }),
78
- item.snippet && /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: item.snippet })
79
- ]
80
- },
81
- item.key
82
- ))
83
- ] })
84
- ] }),
85
- !result.error && state.q.trim() && result.data && /* @__PURE__ */ jsxs(Fragment, { children: [
86
- result.data.truncated && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Showing a limited result window. Refine your query to find more content." }),
87
- /* @__PURE__ */ jsx(
88
- SearchPagination,
89
- {
90
- page: state.page,
91
- hasMore: result.data.hasMore,
92
- loading,
93
- onPageChange: (page) => setState({ page })
94
- }
95
- )
96
- ] })
97
- ] }) });
116
+ !result.error && state.q.trim() && result.data && /* @__PURE__ */ jsxs(Fragment, { children: [
117
+ result.data.truncated && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Showing a limited result window. Refine your query to find more content." }),
118
+ /* @__PURE__ */ jsx(
119
+ SearchPagination,
120
+ {
121
+ page: state.page,
122
+ hasMore: result.data.hasMore,
123
+ loading,
124
+ onPageChange: (page) => setState({ page })
125
+ }
126
+ )
127
+ ] })
128
+ ]
129
+ }
130
+ ) });
98
131
  }
99
132
  function SearchInput({
100
133
  triggerClassName,
@@ -103,6 +136,8 @@ function SearchInput({
103
136
  ...props
104
137
  }) {
105
138
  const [open, setOpen] = useState(false);
139
+ const [hydrated, setHydrated] = useState(false);
140
+ useEffect(() => setHydrated(true), []);
106
141
  const trigger = useRef(null);
107
142
  const onOpenChange = (nextOpen) => {
108
143
  setOpen(nextOpen);
@@ -129,6 +164,7 @@ function SearchInput({
129
164
  variant: "outline",
130
165
  className: triggerClassName,
131
166
  "data-testid": "search-button",
167
+ disabled: !hydrated,
132
168
  "aria-haspopup": "dialog",
133
169
  "aria-expanded": open,
134
170
  onClick: () => setOpen(true),
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('react/jsx-runtime');
4
+
5
+ function SearchHighlight({ text, query }) {
6
+ const phrase = query.trim();
7
+ if (!phrase) return text;
8
+ const escaped = phrase.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9
+ const parts = text.split(new RegExp(`(${escaped})`, "giu"));
10
+ return parts.map(
11
+ (part, index) => index % 2 ? /* @__PURE__ */ jsxRuntime.jsx(
12
+ "mark",
13
+ {
14
+ className: "rounded-sm bg-yellow-200 font-medium text-foreground dark:bg-yellow-800",
15
+ children: part
16
+ },
17
+ index
18
+ ) : part
19
+ );
20
+ }
21
+
22
+ exports.SearchHighlight = SearchHighlight;
@@ -0,0 +1,20 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ function SearchHighlight({ text, query }) {
4
+ const phrase = query.trim();
5
+ if (!phrase) return text;
6
+ const escaped = phrase.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
7
+ const parts = text.split(new RegExp(`(${escaped})`, "giu"));
8
+ return parts.map(
9
+ (part, index) => index % 2 ? /* @__PURE__ */ jsx(
10
+ "mark",
11
+ {
12
+ className: "rounded-sm bg-yellow-200 font-medium text-foreground dark:bg-yellow-800",
13
+ children: part
14
+ },
15
+ index
16
+ ) : part
17
+ );
18
+ }
19
+
20
+ export { SearchHighlight };
@@ -4,6 +4,7 @@
4
4
  const jsxRuntime = require('react/jsx-runtime');
5
5
  const context = require('@btst/stack/context');
6
6
  const button = require('../../ui/src/components/button.cjs');
7
+ const searchHighlight = require('./search-highlight.cjs');
7
8
 
8
9
  function SearchStatus({
9
10
  query,
@@ -11,25 +12,30 @@ function SearchStatus({
11
12
  loading,
12
13
  error,
13
14
  emptyMessage = "No results found.",
14
- onRetry
15
+ onRetry,
16
+ renderLoading
15
17
  }) {
16
- if (error) {
17
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3 p-4", role: "alert", children: [
18
- /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Search could not be completed. Check your access or try again." }),
19
- /* @__PURE__ */ jsxRuntime.jsx(button.Button, { type: "button", variant: "outline", onClick: onRetry, children: "Retry search" })
20
- ] });
21
- }
22
- if (loading)
23
- return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "p-4 text-sm", role: "status", children: "Searching\u2026" });
24
- if (!query.trim()) {
25
- return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "p-4 text-sm text-muted-foreground", children: "Enter a search term." });
26
- }
27
- if (data?.items.length === 0) {
28
- return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "p-4 text-sm text-muted-foreground", role: "status", children: emptyMessage });
29
- }
30
- return null;
18
+ const hasResults = !loading && !error && !!query.trim() && !!data?.items.length;
19
+ const message = loading ? "Searching\u2026" : error ? "Search could not be completed. Check your access or try again." : !query.trim() ? "Enter a search term." : !data?.items.length ? emptyMessage : `${data.items.length} results on this page.`;
20
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: hasResults ? void 0 : "space-y-3 p-4", children: [
21
+ /* @__PURE__ */ jsxRuntime.jsx(
22
+ "p",
23
+ {
24
+ role: !loading && error ? "alert" : "status",
25
+ "aria-atomic": "true",
26
+ className: hasResults || loading && renderLoading ? "sr-only" : "text-sm",
27
+ children: message
28
+ }
29
+ ),
30
+ loading && renderLoading && /* @__PURE__ */ jsxRuntime.jsx("div", { "aria-hidden": "true", children: renderLoading() }),
31
+ !loading && error && /* @__PURE__ */ jsxRuntime.jsx(button.Button, { type: "button", variant: "outline", onClick: onRetry, children: "Retry search" })
32
+ ] });
31
33
  }
32
- function SearchResults({ data }) {
34
+ function SearchResults({
35
+ data,
36
+ query,
37
+ renderResult
38
+ }) {
33
39
  const { router } = context.useStack();
34
40
  const Link = router?.Link ?? "a";
35
41
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -38,17 +44,18 @@ function SearchResults({ data }) {
38
44
  className: "divide-y",
39
45
  "aria-label": "Search results",
40
46
  "data-testid": "search-results",
41
- children: data.items.map((item) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(
47
+ children: data.items.map((item) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsx(
42
48
  Link,
43
49
  {
44
50
  href: item.href,
45
- className: "block space-y-2 rounded-sm p-4 hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring",
51
+ "aria-label": `${item.title}, ${item.sourceLabel}`,
52
+ className: "block space-y-2 [overflow-wrap:anywhere] rounded-sm p-4 hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring",
46
53
  "data-testid": "search-result",
47
- children: [
54
+ children: renderResult ? renderResult(item, query) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
48
55
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block text-xs text-muted-foreground", children: item.sourceLabel }),
49
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block font-medium", children: item.title }),
50
- item.snippet && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block text-sm text-muted-foreground", children: item.snippet })
51
- ]
56
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block font-medium", children: /* @__PURE__ */ jsxRuntime.jsx(searchHighlight.SearchHighlight, { text: item.title, query }) }),
57
+ item.snippet && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block text-sm text-muted-foreground", children: /* @__PURE__ */ jsxRuntime.jsx(searchHighlight.SearchHighlight, { text: item.snippet, query }) })
58
+ ] })
52
59
  }
53
60
  ) }, item.key))
54
61
  }
@@ -64,7 +71,7 @@ function SearchPagination({
64
71
  "nav",
65
72
  {
66
73
  "aria-label": "Search pagination",
67
- className: "flex items-center justify-between gap-3 border-t p-4 text-sm",
74
+ className: "flex flex-wrap items-center justify-between gap-3 border-t p-4 text-sm",
68
75
  children: [
69
76
  /* @__PURE__ */ jsxRuntime.jsx(
70
77
  button.Button,
@@ -1,7 +1,8 @@
1
1
  'use client';
2
- import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
3
  import { useStack } from '@btst/stack/context';
4
4
  import { Button } from '../../ui/src/components/button.mjs';
5
+ import { SearchHighlight } from './search-highlight.mjs';
5
6
 
6
7
  function SearchStatus({
7
8
  query,
@@ -9,25 +10,30 @@ function SearchStatus({
9
10
  loading,
10
11
  error,
11
12
  emptyMessage = "No results found.",
12
- onRetry
13
+ onRetry,
14
+ renderLoading
13
15
  }) {
14
- if (error) {
15
- return /* @__PURE__ */ jsxs("div", { className: "space-y-3 p-4", role: "alert", children: [
16
- /* @__PURE__ */ jsx("p", { children: "Search could not be completed. Check your access or try again." }),
17
- /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: onRetry, children: "Retry search" })
18
- ] });
19
- }
20
- if (loading)
21
- return /* @__PURE__ */ jsx("p", { className: "p-4 text-sm", role: "status", children: "Searching\u2026" });
22
- if (!query.trim()) {
23
- return /* @__PURE__ */ jsx("p", { className: "p-4 text-sm text-muted-foreground", children: "Enter a search term." });
24
- }
25
- if (data?.items.length === 0) {
26
- return /* @__PURE__ */ jsx("p", { className: "p-4 text-sm text-muted-foreground", role: "status", children: emptyMessage });
27
- }
28
- return null;
16
+ const hasResults = !loading && !error && !!query.trim() && !!data?.items.length;
17
+ const message = loading ? "Searching\u2026" : error ? "Search could not be completed. Check your access or try again." : !query.trim() ? "Enter a search term." : !data?.items.length ? emptyMessage : `${data.items.length} results on this page.`;
18
+ return /* @__PURE__ */ jsxs("div", { className: hasResults ? void 0 : "space-y-3 p-4", children: [
19
+ /* @__PURE__ */ jsx(
20
+ "p",
21
+ {
22
+ role: !loading && error ? "alert" : "status",
23
+ "aria-atomic": "true",
24
+ className: hasResults || loading && renderLoading ? "sr-only" : "text-sm",
25
+ children: message
26
+ }
27
+ ),
28
+ loading && renderLoading && /* @__PURE__ */ jsx("div", { "aria-hidden": "true", children: renderLoading() }),
29
+ !loading && error && /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: onRetry, children: "Retry search" })
30
+ ] });
29
31
  }
30
- function SearchResults({ data }) {
32
+ function SearchResults({
33
+ data,
34
+ query,
35
+ renderResult
36
+ }) {
31
37
  const { router } = useStack();
32
38
  const Link = router?.Link ?? "a";
33
39
  return /* @__PURE__ */ jsx(
@@ -36,17 +42,18 @@ function SearchResults({ data }) {
36
42
  className: "divide-y",
37
43
  "aria-label": "Search results",
38
44
  "data-testid": "search-results",
39
- children: data.items.map((item) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
45
+ children: data.items.map((item) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
40
46
  Link,
41
47
  {
42
48
  href: item.href,
43
- className: "block space-y-2 rounded-sm p-4 hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring",
49
+ "aria-label": `${item.title}, ${item.sourceLabel}`,
50
+ className: "block space-y-2 [overflow-wrap:anywhere] rounded-sm p-4 hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring",
44
51
  "data-testid": "search-result",
45
- children: [
52
+ children: renderResult ? renderResult(item, query) : /* @__PURE__ */ jsxs(Fragment, { children: [
46
53
  /* @__PURE__ */ jsx("span", { className: "block text-xs text-muted-foreground", children: item.sourceLabel }),
47
- /* @__PURE__ */ jsx("span", { className: "block font-medium", children: item.title }),
48
- item.snippet && /* @__PURE__ */ jsx("span", { className: "block text-sm text-muted-foreground", children: item.snippet })
49
- ]
54
+ /* @__PURE__ */ jsx("span", { className: "block font-medium", children: /* @__PURE__ */ jsx(SearchHighlight, { text: item.title, query }) }),
55
+ item.snippet && /* @__PURE__ */ jsx("span", { className: "block text-sm text-muted-foreground", children: /* @__PURE__ */ jsx(SearchHighlight, { text: item.snippet, query }) })
56
+ ] })
50
57
  }
51
58
  ) }, item.key))
52
59
  }
@@ -62,7 +69,7 @@ function SearchPagination({
62
69
  "nav",
63
70
  {
64
71
  "aria-label": "Search pagination",
65
- className: "flex items-center justify-between gap-3 border-t p-4 text-sm",
72
+ className: "flex flex-wrap items-center justify-between gap-3 border-t p-4 text-sm",
66
73
  children: [
67
74
  /* @__PURE__ */ jsx(
68
75
  Button,
@@ -29,7 +29,7 @@ function useSearchState({
29
29
  setState,
30
30
  fixedSources,
31
31
  result: fixedSources && sources.length === 0 ? { ...result, data: void 0 } : result,
32
- loading: result.isLoading || enabled && q !== state.q
32
+ loading: result.isFetching || result.isLoading || enabled && q !== state.q
33
33
  };
34
34
  }
35
35
 
@@ -27,7 +27,7 @@ function useSearchState({
27
27
  setState,
28
28
  fixedSources,
29
29
  result: fixedSources && sources.length === 0 ? { ...result, data: void 0 } : result,
30
- loading: result.isLoading || enabled && q !== state.q
30
+ loading: result.isFetching || result.isLoading || enabled && q !== state.q
31
31
  };
32
32
  }
33
33
 
@@ -3,21 +3,12 @@ import * as _btst_yar from '@btst/yar';
3
3
  import * as react from 'react';
4
4
  import { ComponentType } from 'react';
5
5
  import { SearchIdentityPartition } from '../query-keys.cjs';
6
+ import { S as SearchPluginOverrides } from '../shared/plugin-search.QfsGS8no.cjs';
6
7
  import '@btst/stack/plugins/client';
7
8
  import '@btst/stack/context';
8
9
  import '../types.cjs';
9
10
  import '@btst/stack/plugins/api';
10
11
 
11
- /** Presentation choices for the shared Search UI. */
12
- interface SearchPluginOverrides {
13
- /** Label above the results route. */
14
- title?: string;
15
- /** Search field prompt. */
16
- placeholder?: string;
17
- /** Message shown when a completed query has no matches. */
18
- emptyMessage?: string;
19
- }
20
-
21
12
  /** Search route views and request-local SSR state. */
22
13
  interface SearchClientConfig {
23
14
  /** The request query string, forwarded by the framework's server route. */
@@ -51,5 +42,5 @@ declare const searchClientPlugin: (config?: SearchClientConfig) => _btst_stack_c
51
42
  }, _btst_yar.RouteMeta>;
52
43
  }, "search", Readonly<Record<string, never>>, never>;
53
44
 
54
- export { searchClientPlugin };
55
- export type { SearchClientConfig, SearchPluginOverrides };
45
+ export { SearchPluginOverrides, searchClientPlugin };
46
+ export type { SearchClientConfig };
@@ -3,21 +3,12 @@ import * as _btst_yar from '@btst/yar';
3
3
  import * as react from 'react';
4
4
  import { ComponentType } from 'react';
5
5
  import { SearchIdentityPartition } from '../query-keys.mjs';
6
+ import { S as SearchPluginOverrides } from '../shared/plugin-search.WwLtD6lV.mjs';
6
7
  import '@btst/stack/plugins/client';
7
8
  import '@btst/stack/context';
8
9
  import '../types.mjs';
9
10
  import '@btst/stack/plugins/api';
10
11
 
11
- /** Presentation choices for the shared Search UI. */
12
- interface SearchPluginOverrides {
13
- /** Label above the results route. */
14
- title?: string;
15
- /** Search field prompt. */
16
- placeholder?: string;
17
- /** Message shown when a completed query has no matches. */
18
- emptyMessage?: string;
19
- }
20
-
21
12
  /** Search route views and request-local SSR state. */
22
13
  interface SearchClientConfig {
23
14
  /** The request query string, forwarded by the framework's server route. */
@@ -51,5 +42,5 @@ declare const searchClientPlugin: (config?: SearchClientConfig) => _btst_stack_c
51
42
  }, _btst_yar.RouteMeta>;
52
43
  }, "search", Readonly<Record<string, never>>, never>;
53
44
 
54
- export { searchClientPlugin };
55
- export type { SearchClientConfig, SearchPluginOverrides };
45
+ export { SearchPluginOverrides, searchClientPlugin };
46
+ export type { SearchClientConfig };
@@ -3,21 +3,12 @@ import * as _btst_yar from '@btst/yar';
3
3
  import * as react from 'react';
4
4
  import { ComponentType } from 'react';
5
5
  import { SearchIdentityPartition } from '../query-keys.js';
6
+ import { S as SearchPluginOverrides } from '../shared/plugin-search.BDlgoPEb.js';
6
7
  import '@btst/stack/plugins/client';
7
8
  import '@btst/stack/context';
8
9
  import '../types.js';
9
10
  import '@btst/stack/plugins/api';
10
11
 
11
- /** Presentation choices for the shared Search UI. */
12
- interface SearchPluginOverrides {
13
- /** Label above the results route. */
14
- title?: string;
15
- /** Search field prompt. */
16
- placeholder?: string;
17
- /** Message shown when a completed query has no matches. */
18
- emptyMessage?: string;
19
- }
20
-
21
12
  /** Search route views and request-local SSR state. */
22
13
  interface SearchClientConfig {
23
14
  /** The request query string, forwarded by the framework's server route. */
@@ -51,5 +42,5 @@ declare const searchClientPlugin: (config?: SearchClientConfig) => _btst_stack_c
51
42
  }, _btst_yar.RouteMeta>;
52
43
  }, "search", Readonly<Record<string, never>>, never>;
53
44
 
54
- export { searchClientPlugin };
55
- export type { SearchClientConfig, SearchPluginOverrides };
45
+ export { SearchPluginOverrides, searchClientPlugin };
46
+ export type { SearchClientConfig };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const SEARCH_MAX_SOURCES = 8;
4
+ const SEARCH_MAX_RESULTS = 200;
5
+ const SEARCH_MAX_PAGES = 10;
6
+ const SEARCH_SOURCE_ID_PATTERN = /^[a-z][a-z0-9-]{0,63}$/;
7
+
8
+ exports.SEARCH_MAX_PAGES = SEARCH_MAX_PAGES;
9
+ exports.SEARCH_MAX_RESULTS = SEARCH_MAX_RESULTS;
10
+ exports.SEARCH_MAX_SOURCES = SEARCH_MAX_SOURCES;
11
+ exports.SEARCH_SOURCE_ID_PATTERN = SEARCH_SOURCE_ID_PATTERN;
@@ -0,0 +1,6 @@
1
+ const SEARCH_MAX_SOURCES = 8;
2
+ const SEARCH_MAX_RESULTS = 200;
3
+ const SEARCH_MAX_PAGES = 10;
4
+ const SEARCH_SOURCE_ID_PATTERN = /^[a-z][a-z0-9-]{0,63}$/;
5
+
6
+ export { SEARCH_MAX_PAGES, SEARCH_MAX_RESULTS, SEARCH_MAX_SOURCES, SEARCH_SOURCE_ID_PATTERN };
@@ -3,6 +3,22 @@
3
3
  function searchSnippet(value) {
4
4
  return value.slice(0, 2e3).replace(/<[^>]*>/g, " ").replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/[`*_#>~]/g, "").replace(/\s+/g, " ").trim().slice(0, 240);
5
5
  }
6
+ function normalizeSearchText(value) {
7
+ return value.normalize("NFKD").toLowerCase().replace(/[^\p{L}\p{N}]/gu, "");
8
+ }
9
+ function searchRelevance(result, query) {
10
+ const q = normalizeSearchText(query);
11
+ if (!q) return 7;
12
+ const title = normalizeSearchText(result.title);
13
+ const aliases = result.aliases?.map(normalizeSearchText) ?? [];
14
+ if (title === q) return 0;
15
+ if (aliases.includes(q)) return 1;
16
+ if (title.startsWith(q)) return 2;
17
+ if (aliases.some((alias) => alias.startsWith(q))) return 3;
18
+ if (title.includes(q)) return 4;
19
+ if (aliases.some((alias) => alias.includes(q))) return 5;
20
+ return normalizeSearchText(result.snippet).includes(q) ? 6 : 7;
21
+ }
6
22
  function destination(basePath, slug) {
7
23
  return `${basePath.replace(/\/$/, "")}/${encodeURIComponent(slug)}`;
8
24
  }
@@ -12,14 +28,15 @@ function blogSearchProvider(options) {
12
28
  label: "Blog",
13
29
  async search({ q, limit, request }) {
14
30
  const operations = options.operations(request);
31
+ const batchSize = options.batchSize ?? 100;
15
32
  const items = [];
16
33
  let omittedDestination = false;
17
34
  let total = 0;
18
- for (let offset = 0; offset < limit; offset += 100) {
35
+ for (let offset = 0; offset < limit; offset += batchSize) {
19
36
  const page = await operations.listPosts({
20
37
  query: q,
21
38
  published: true,
22
- limit: Math.min(100, limit - offset),
39
+ limit: Math.min(batchSize, limit - offset),
23
40
  offset
24
41
  });
25
42
  total = page.total;
@@ -118,5 +135,7 @@ function cmsSearchProvider(options) {
118
135
  exports.blogSearchProvider = blogSearchProvider;
119
136
  exports.cmsSearchProvider = cmsSearchProvider;
120
137
  exports.ecommerceSearchProvider = ecommerceSearchProvider;
138
+ exports.normalizeSearchText = normalizeSearchText;
121
139
  exports.schoolSearchProvider = schoolSearchProvider;
140
+ exports.searchRelevance = searchRelevance;
122
141
  exports.searchSnippet = searchSnippet;
@@ -1,4 +1,4 @@
1
- import { SearchProvider } from './types.cjs';
1
+ import { SearchProvider, SearchProviderResult } from './types.cjs';
2
2
  import '@btst/stack/plugins/api';
3
3
 
4
4
  interface PublicPost {
@@ -62,8 +62,15 @@ interface SourceOptions<Operations> {
62
62
  * Bound input before regex work so malformed markup cannot trigger unbounded scans.
63
63
  */
64
64
  declare function searchSnippet(value: string): string;
65
+ /** Shared discovery normalization; punctuation and combining marks do not affect rank. */
66
+ declare function normalizeSearchText(value: string): string;
67
+ /** Lower values rank first. Providers still own matching and visibility. */
68
+ declare function searchRelevance(result: SearchProviderResult, query: string): number;
65
69
  /** Reuses Blog's publication filter and domain text matching. */
66
- declare function blogSearchProvider(options: SourceOptions<BlogSearchOperations>): SearchProvider;
70
+ declare function blogSearchProvider(options: SourceOptions<BlogSearchOperations> & {
71
+ /** Opt into 201 only with a Blog release whose list operation accepts it. */
72
+ batchSize?: 100 | 201;
73
+ }): SearchProvider;
67
74
  /** Uses only the public School catalog; lessons never participate. */
68
75
  declare function schoolSearchProvider(options: SourceOptions<SchoolSearchOperations>): SearchProvider;
69
76
  /** Uses Ecommerce's public product projection, including its visibility rules. */
@@ -78,5 +85,5 @@ declare function cmsSearchProvider(options: {
78
85
  search: SearchProvider["search"];
79
86
  }): SearchProvider;
80
87
 
81
- export { blogSearchProvider, cmsSearchProvider, ecommerceSearchProvider, schoolSearchProvider, searchSnippet };
88
+ export { blogSearchProvider, cmsSearchProvider, ecommerceSearchProvider, normalizeSearchText, schoolSearchProvider, searchRelevance, searchSnippet };
82
89
  export type { BlogSearchOperations, EcommerceSearchOperations, SchoolSearchOperations };