@btst/plugin-search 0.0.0-stage → 1.0.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 (86) hide show
  1. package/LICENSE.md +17 -0
  2. package/dist/api/index.cjs +17 -0
  3. package/dist/api/index.d.cts +62 -0
  4. package/dist/api/index.d.mts +62 -0
  5. package/dist/api/index.d.ts +62 -0
  6. package/dist/api/index.mjs +4 -0
  7. package/dist/api/operations.cjs +127 -0
  8. package/dist/api/operations.mjs +125 -0
  9. package/dist/api/plugin.cjs +23 -0
  10. package/dist/api/plugin.mjs +21 -0
  11. package/dist/client/components/index.cjs +11 -0
  12. package/dist/client/components/index.d.cts +35 -0
  13. package/dist/client/components/index.d.mts +35 -0
  14. package/dist/client/components/index.d.ts +35 -0
  15. package/dist/client/components/index.mjs +3 -0
  16. package/dist/client/components/pages/search-page.cjs +39 -0
  17. package/dist/client/components/pages/search-page.internal.cjs +100 -0
  18. package/dist/client/components/pages/search-page.internal.mjs +98 -0
  19. package/dist/client/components/pages/search-page.mjs +37 -0
  20. package/dist/client/components/search-dialog.cjs +148 -0
  21. package/dist/client/components/search-dialog.mjs +145 -0
  22. package/dist/client/components/search-results.cjs +100 -0
  23. package/dist/client/components/search-results.mjs +96 -0
  24. package/dist/client/components/source-filter.cjs +31 -0
  25. package/dist/client/components/source-filter.mjs +29 -0
  26. package/dist/client/constants.cjs +5 -0
  27. package/dist/client/constants.mjs +3 -0
  28. package/dist/client/hooks/index.cjs +10 -0
  29. package/dist/client/hooks/index.d.cts +340 -0
  30. package/dist/client/hooks/index.d.mts +340 -0
  31. package/dist/client/hooks/index.d.ts +340 -0
  32. package/dist/client/hooks/index.mjs +3 -0
  33. package/dist/client/hooks/use-search-state.cjs +36 -0
  34. package/dist/client/hooks/use-search-state.mjs +34 -0
  35. package/dist/client/hooks/use-search.cjs +44 -0
  36. package/dist/client/hooks/use-search.mjs +42 -0
  37. package/dist/client/index.cjs +7 -0
  38. package/dist/client/index.d.cts +55 -0
  39. package/dist/client/index.d.mts +55 -0
  40. package/dist/client/index.d.ts +55 -0
  41. package/dist/client/index.mjs +1 -0
  42. package/dist/client/plugin.cjs +76 -0
  43. package/dist/client/plugin.mjs +74 -0
  44. package/dist/client/search-state.cjs +20 -0
  45. package/dist/client/search-state.mjs +17 -0
  46. package/dist/permissions.cjs +12 -0
  47. package/dist/permissions.d.cts +12 -0
  48. package/dist/permissions.d.mts +12 -0
  49. package/dist/permissions.d.ts +12 -0
  50. package/dist/permissions.mjs +10 -0
  51. package/dist/providers.cjs +122 -0
  52. package/dist/providers.d.cts +82 -0
  53. package/dist/providers.d.mts +82 -0
  54. package/dist/providers.d.ts +82 -0
  55. package/dist/providers.mjs +116 -0
  56. package/dist/query-keys.cjs +35 -0
  57. package/dist/query-keys.d.cts +71 -0
  58. package/dist/query-keys.d.mts +71 -0
  59. package/dist/query-keys.d.ts +71 -0
  60. package/dist/query-keys.mjs +32 -0
  61. package/dist/schemas.cjs +23 -0
  62. package/dist/schemas.d.cts +14 -0
  63. package/dist/schemas.d.mts +14 -0
  64. package/dist/schemas.d.ts +14 -0
  65. package/dist/schemas.mjs +17 -0
  66. package/dist/shared/plugin-search.5GvThkZW.d.cts +20 -0
  67. package/dist/shared/plugin-search.5GvThkZW.d.mts +20 -0
  68. package/dist/shared/plugin-search.5GvThkZW.d.ts +20 -0
  69. package/dist/style.css +2 -0
  70. package/dist/types.cjs +2 -0
  71. package/dist/types.d.cts +53 -0
  72. package/dist/types.d.mts +53 -0
  73. package/dist/types.d.ts +53 -0
  74. package/dist/types.mjs +1 -0
  75. package/dist/ui/src/components/button.cjs +56 -0
  76. package/dist/ui/src/components/button.mjs +53 -0
  77. package/dist/ui/src/components/command.cjs +88 -0
  78. package/dist/ui/src/components/command.mjs +83 -0
  79. package/dist/ui/src/components/dialog.cjs +127 -0
  80. package/dist/ui/src/components/dialog.mjs +105 -0
  81. package/dist/ui/src/components/input.cjs +23 -0
  82. package/dist/ui/src/components/input.mjs +21 -0
  83. package/dist/ui/src/lib/utils.cjs +10 -0
  84. package/dist/ui/src/lib/utils.mjs +8 -0
  85. package/package.json +181 -3
  86. package/README.md +0 -3
@@ -0,0 +1,39 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ const jsxRuntime = require('react/jsx-runtime');
5
+ const react = require('react');
6
+ const components = require('@btst/stack/client/components');
7
+ const button = require('../../../ui/src/components/button.cjs');
8
+
9
+ const Page = react.lazy(
10
+ () => import('./search-page.internal.cjs').then((module) => ({
11
+ default: module.SearchPage
12
+ }))
13
+ );
14
+ function SearchLoading() {
15
+ return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "p-8", role: "status", children: "Loading search\u2026" });
16
+ }
17
+ function SearchError({ resetErrorBoundary }) {
18
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 p-8", role: "alert", children: [
19
+ /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Search is unavailable." }),
20
+ /* @__PURE__ */ jsxRuntime.jsx(button.Button, { type: "button", variant: "outline", onClick: resetErrorBoundary, children: "Retry loading" })
21
+ ] });
22
+ }
23
+ function SearchPageComponent({
24
+ initialSearch
25
+ }) {
26
+ return /* @__PURE__ */ jsxRuntime.jsx(
27
+ components.ComposedRoute,
28
+ {
29
+ path: "/search",
30
+ PageComponent: Page,
31
+ LoadingComponent: SearchLoading,
32
+ ErrorComponent: SearchError,
33
+ props: { initialSearch },
34
+ onError: (error) => console.error("[btst/search]", error)
35
+ }
36
+ );
37
+ }
38
+
39
+ exports.SearchPageComponent = SearchPageComponent;
@@ -0,0 +1,100 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ const jsxRuntime = require('react/jsx-runtime');
5
+ const react = require('react');
6
+ const context = require('@btst/stack/context');
7
+ const input = require('../../../ui/src/components/input.cjs');
8
+ const constants = require('../../constants.cjs');
9
+ const searchResults = require('../search-results.cjs');
10
+ const sourceFilter = require('../source-filter.cjs');
11
+ const useSearchState = require('../../hooks/use-search-state.cjs');
12
+
13
+ function SearchPage({
14
+ initialSearch
15
+ }) {
16
+ const id = react.useId();
17
+ const [hydrated, setHydrated] = react.useState(false);
18
+ react.useEffect(() => setHydrated(true), []);
19
+ const overrides = context.usePluginOverrides(constants.SEARCH_PLUGIN_ID);
20
+ const { state, setState, result, loading } = useSearchState.useSearchState({
21
+ initialSearch
22
+ });
23
+ return /* @__PURE__ */ jsxRuntime.jsxs(
24
+ "main",
25
+ {
26
+ className: "container mx-auto min-w-0 max-w-4xl space-y-6 px-4 py-8",
27
+ "data-testid": "search-page",
28
+ children: [
29
+ /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-3xl font-semibold tracking-tight", children: overrides.title ?? "Search" }),
30
+ /* @__PURE__ */ jsxRuntime.jsxs(
31
+ "fieldset",
32
+ {
33
+ disabled: !hydrated,
34
+ "aria-label": "Search controls",
35
+ className: "min-w-0 space-y-6",
36
+ children: [
37
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
38
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, className: "text-sm font-medium", children: "Search" }),
39
+ /* @__PURE__ */ jsxRuntime.jsx(
40
+ input.Input,
41
+ {
42
+ id,
43
+ type: "search",
44
+ "data-testid": "search-input",
45
+ maxLength: 200,
46
+ placeholder: overrides.placeholder ?? "Search content\u2026",
47
+ value: state.q,
48
+ onChange: (event) => setState({ q: event.target.value, page: 1 }, { replace: true })
49
+ }
50
+ )
51
+ ] }),
52
+ result.data && /* @__PURE__ */ jsxRuntime.jsx(
53
+ sourceFilter.SourceFilter,
54
+ {
55
+ sources: result.data.sources,
56
+ value: state.sources,
57
+ onChange: (sources) => setState({ sources, page: 1 })
58
+ }
59
+ ),
60
+ /* @__PURE__ */ jsxRuntime.jsxs(
61
+ "section",
62
+ {
63
+ className: "rounded-md border",
64
+ "aria-label": "Search results",
65
+ "aria-busy": loading,
66
+ children: [
67
+ /* @__PURE__ */ jsxRuntime.jsx("div", { "aria-live": "polite", children: /* @__PURE__ */ jsxRuntime.jsx(
68
+ searchResults.SearchStatus,
69
+ {
70
+ query: state.q,
71
+ data: result.data,
72
+ loading,
73
+ error: result.error,
74
+ emptyMessage: overrides.emptyMessage,
75
+ onRetry: () => void result.refetch()
76
+ }
77
+ ) }),
78
+ !result.error && !loading && result.data && /* @__PURE__ */ jsxRuntime.jsx(searchResults.SearchResults, { data: result.data }),
79
+ !result.error && state.q.trim() && result.data && /* @__PURE__ */ jsxRuntime.jsx(
80
+ searchResults.SearchPagination,
81
+ {
82
+ page: state.page,
83
+ hasMore: result.data.hasMore,
84
+ loading,
85
+ onPageChange: (page) => setState({ page })
86
+ }
87
+ )
88
+ ]
89
+ }
90
+ ),
91
+ result.data?.truncated && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Showing a limited result window. Refine your query to find more content." })
92
+ ]
93
+ }
94
+ )
95
+ ]
96
+ }
97
+ );
98
+ }
99
+
100
+ exports.SearchPage = SearchPage;
@@ -0,0 +1,98 @@
1
+ 'use client';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { useId, useState, useEffect } from 'react';
4
+ import { usePluginOverrides } from '@btst/stack/context';
5
+ import { Input } from '../../../ui/src/components/input.mjs';
6
+ import { SEARCH_PLUGIN_ID } from '../../constants.mjs';
7
+ import { SearchStatus, SearchResults, SearchPagination } from '../search-results.mjs';
8
+ import { SourceFilter } from '../source-filter.mjs';
9
+ import { useSearchState } from '../../hooks/use-search-state.mjs';
10
+
11
+ function SearchPage({
12
+ initialSearch
13
+ }) {
14
+ const id = useId();
15
+ const [hydrated, setHydrated] = useState(false);
16
+ useEffect(() => setHydrated(true), []);
17
+ const overrides = usePluginOverrides(SEARCH_PLUGIN_ID);
18
+ const { state, setState, result, loading } = useSearchState({
19
+ initialSearch
20
+ });
21
+ return /* @__PURE__ */ jsxs(
22
+ "main",
23
+ {
24
+ className: "container mx-auto min-w-0 max-w-4xl space-y-6 px-4 py-8",
25
+ "data-testid": "search-page",
26
+ children: [
27
+ /* @__PURE__ */ jsx("h1", { className: "text-3xl font-semibold tracking-tight", children: overrides.title ?? "Search" }),
28
+ /* @__PURE__ */ jsxs(
29
+ "fieldset",
30
+ {
31
+ disabled: !hydrated,
32
+ "aria-label": "Search controls",
33
+ className: "min-w-0 space-y-6",
34
+ children: [
35
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
36
+ /* @__PURE__ */ jsx("label", { htmlFor: id, className: "text-sm font-medium", children: "Search" }),
37
+ /* @__PURE__ */ jsx(
38
+ Input,
39
+ {
40
+ id,
41
+ type: "search",
42
+ "data-testid": "search-input",
43
+ maxLength: 200,
44
+ placeholder: overrides.placeholder ?? "Search content\u2026",
45
+ value: state.q,
46
+ onChange: (event) => setState({ q: event.target.value, page: 1 }, { replace: true })
47
+ }
48
+ )
49
+ ] }),
50
+ result.data && /* @__PURE__ */ jsx(
51
+ SourceFilter,
52
+ {
53
+ sources: result.data.sources,
54
+ value: state.sources,
55
+ onChange: (sources) => setState({ sources, page: 1 })
56
+ }
57
+ ),
58
+ /* @__PURE__ */ jsxs(
59
+ "section",
60
+ {
61
+ className: "rounded-md border",
62
+ "aria-label": "Search results",
63
+ "aria-busy": loading,
64
+ children: [
65
+ /* @__PURE__ */ jsx("div", { "aria-live": "polite", children: /* @__PURE__ */ jsx(
66
+ SearchStatus,
67
+ {
68
+ query: state.q,
69
+ data: result.data,
70
+ loading,
71
+ error: result.error,
72
+ emptyMessage: overrides.emptyMessage,
73
+ onRetry: () => void result.refetch()
74
+ }
75
+ ) }),
76
+ !result.error && !loading && result.data && /* @__PURE__ */ jsx(SearchResults, { data: result.data }),
77
+ !result.error && state.q.trim() && result.data && /* @__PURE__ */ jsx(
78
+ SearchPagination,
79
+ {
80
+ page: state.page,
81
+ hasMore: result.data.hasMore,
82
+ loading,
83
+ onPageChange: (page) => setState({ page })
84
+ }
85
+ )
86
+ ]
87
+ }
88
+ ),
89
+ result.data?.truncated && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Showing a limited result window. Refine your query to find more content." })
90
+ ]
91
+ }
92
+ )
93
+ ]
94
+ }
95
+ );
96
+ }
97
+
98
+ export { SearchPage };
@@ -0,0 +1,37 @@
1
+ 'use client';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import { lazy } from 'react';
4
+ import { ComposedRoute } from '@btst/stack/client/components';
5
+ import { Button } from '../../../ui/src/components/button.mjs';
6
+
7
+ const Page = lazy(
8
+ () => import('./search-page.internal.mjs').then((module) => ({
9
+ default: module.SearchPage
10
+ }))
11
+ );
12
+ function SearchLoading() {
13
+ return /* @__PURE__ */ jsx("p", { className: "p-8", role: "status", children: "Loading search\u2026" });
14
+ }
15
+ function SearchError({ resetErrorBoundary }) {
16
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-4 p-8", role: "alert", children: [
17
+ /* @__PURE__ */ jsx("p", { children: "Search is unavailable." }),
18
+ /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: resetErrorBoundary, children: "Retry loading" })
19
+ ] });
20
+ }
21
+ function SearchPageComponent({
22
+ initialSearch
23
+ }) {
24
+ return /* @__PURE__ */ jsx(
25
+ ComposedRoute,
26
+ {
27
+ path: "/search",
28
+ PageComponent: Page,
29
+ LoadingComponent: SearchLoading,
30
+ ErrorComponent: SearchError,
31
+ props: { initialSearch },
32
+ onError: (error) => console.error("[btst/search]", error)
33
+ }
34
+ );
35
+ }
36
+
37
+ export { SearchPageComponent };
@@ -0,0 +1,148 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ const jsxRuntime = require('react/jsx-runtime');
5
+ const react = require('react');
6
+ const context = require('@btst/stack/context');
7
+ const button = require('../../ui/src/components/button.cjs');
8
+ const command = require('../../ui/src/components/command.cjs');
9
+ const dialog = require('../../ui/src/components/dialog.cjs');
10
+ const searchResults = require('./search-results.cjs');
11
+ const sourceFilter = require('./source-filter.cjs');
12
+ const useSearchState = require('../hooks/use-search-state.cjs');
13
+
14
+ function SearchDialog({
15
+ open,
16
+ onOpenChange,
17
+ sources,
18
+ className,
19
+ placeholder = "Search content\u2026",
20
+ emptyMessage,
21
+ title = "Search"
22
+ }) {
23
+ const { router } = context.useStack();
24
+ const { state, setState, result, fixedSources, loading } = useSearchState.useSearchState({
25
+ sources,
26
+ enabled: open
27
+ });
28
+ const navigate = async (href) => {
29
+ if (router?.navigate) await router.navigate(href);
30
+ else window.location.assign(href);
31
+ onOpenChange(false);
32
+ };
33
+ return /* @__PURE__ */ jsxRuntime.jsx(dialog.Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogContent, { className, "data-testid": "search-modal", children: [
34
+ /* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogHeader, { children: [
35
+ /* @__PURE__ */ jsxRuntime.jsx(dialog.DialogTitle, { children: title }),
36
+ /* @__PURE__ */ jsxRuntime.jsx(dialog.DialogDescription, { children: "Find content across the available sources." })
37
+ ] }),
38
+ /* @__PURE__ */ jsxRuntime.jsxs(command.Command, { shouldFilter: false, children: [
39
+ /* @__PURE__ */ jsxRuntime.jsx(
40
+ command.CommandInput,
41
+ {
42
+ "aria-label": "Search",
43
+ "data-testid": "search-input",
44
+ placeholder,
45
+ value: state.q,
46
+ maxLength: 200,
47
+ onValueChange: (q) => setState({ q, page: 1 }, { replace: true })
48
+ }
49
+ ),
50
+ !fixedSources && result.data && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-3", children: /* @__PURE__ */ jsxRuntime.jsx(
51
+ sourceFilter.SourceFilter,
52
+ {
53
+ sources: result.data.sources,
54
+ value: state.sources,
55
+ onChange: (value) => setState({ sources: value, page: 1 })
56
+ }
57
+ ) }),
58
+ /* @__PURE__ */ jsxRuntime.jsxs(command.CommandList, { "aria-busy": loading, className: "max-h-[400px]", children: [
59
+ /* @__PURE__ */ jsxRuntime.jsx(
60
+ searchResults.SearchStatus,
61
+ {
62
+ query: state.q,
63
+ data: result.data,
64
+ loading,
65
+ error: result.error,
66
+ emptyMessage,
67
+ onRetry: () => void result.refetch()
68
+ }
69
+ ),
70
+ !result.error && !loading && result.data?.items.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
71
+ command.CommandItem,
72
+ {
73
+ value: item.key,
74
+ "data-testid": "search-result",
75
+ onSelect: () => void navigate(item.href),
76
+ className: "flex flex-col items-start gap-2 border-b px-4 py-3",
77
+ children: [
78
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-muted-foreground", children: item.sourceLabel }),
79
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium", children: item.title }),
80
+ item.snippet && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-muted-foreground", children: item.snippet })
81
+ ]
82
+ },
83
+ item.key
84
+ ))
85
+ ] })
86
+ ] }),
87
+ !result.error && state.q.trim() && result.data && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
88
+ result.data.truncated && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: "Showing a limited result window. Refine your query to find more content." }),
89
+ /* @__PURE__ */ jsxRuntime.jsx(
90
+ searchResults.SearchPagination,
91
+ {
92
+ page: state.page,
93
+ hasMore: result.data.hasMore,
94
+ loading,
95
+ onPageChange: (page) => setState({ page })
96
+ }
97
+ )
98
+ ] })
99
+ ] }) });
100
+ }
101
+ function SearchInput({
102
+ triggerClassName,
103
+ buttonText = "Search",
104
+ keyboardShortcut = true,
105
+ ...props
106
+ }) {
107
+ const [open, setOpen] = react.useState(false);
108
+ const trigger = react.useRef(null);
109
+ const onOpenChange = (nextOpen) => {
110
+ setOpen(nextOpen);
111
+ if (!nextOpen) requestAnimationFrame(() => trigger.current?.focus());
112
+ };
113
+ react.useEffect(() => {
114
+ if (!keyboardShortcut) return;
115
+ const onKeyDown = (event) => {
116
+ if (event.key.toLowerCase() === "k" && (event.metaKey || event.ctrlKey)) {
117
+ event.preventDefault();
118
+ setOpen(!open);
119
+ if (open) requestAnimationFrame(() => trigger.current?.focus());
120
+ }
121
+ };
122
+ document.addEventListener("keydown", onKeyDown);
123
+ return () => document.removeEventListener("keydown", onKeyDown);
124
+ }, [keyboardShortcut, open]);
125
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
126
+ /* @__PURE__ */ jsxRuntime.jsxs(
127
+ button.Button,
128
+ {
129
+ ref: trigger,
130
+ type: "button",
131
+ variant: "outline",
132
+ className: triggerClassName,
133
+ "data-testid": "search-button",
134
+ "aria-haspopup": "dialog",
135
+ "aria-expanded": open,
136
+ onClick: () => setOpen(true),
137
+ children: [
138
+ buttonText,
139
+ keyboardShortcut && /* @__PURE__ */ jsxRuntime.jsx("kbd", { className: "ml-6 text-xs text-muted-foreground", children: "\u2318K" })
140
+ ]
141
+ }
142
+ ),
143
+ /* @__PURE__ */ jsxRuntime.jsx(SearchDialog, { ...props, open, onOpenChange })
144
+ ] });
145
+ }
146
+
147
+ exports.SearchDialog = SearchDialog;
148
+ exports.SearchInput = SearchInput;
@@ -0,0 +1,145 @@
1
+ 'use client';
2
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
+ import { useState, useRef, useEffect } from 'react';
4
+ import { useStack } from '@btst/stack/context';
5
+ import { Button } from '../../ui/src/components/button.mjs';
6
+ import { Command, CommandInput, CommandList, CommandItem } from '../../ui/src/components/command.mjs';
7
+ import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '../../ui/src/components/dialog.mjs';
8
+ import { SearchStatus, SearchPagination } from './search-results.mjs';
9
+ import { SourceFilter } from './source-filter.mjs';
10
+ import { useSearchState } from '../hooks/use-search-state.mjs';
11
+
12
+ function SearchDialog({
13
+ open,
14
+ onOpenChange,
15
+ sources,
16
+ className,
17
+ placeholder = "Search content\u2026",
18
+ emptyMessage,
19
+ title = "Search"
20
+ }) {
21
+ const { router } = useStack();
22
+ const { state, setState, result, fixedSources, loading } = useSearchState({
23
+ sources,
24
+ enabled: open
25
+ });
26
+ const navigate = async (href) => {
27
+ if (router?.navigate) await router.navigate(href);
28
+ else window.location.assign(href);
29
+ onOpenChange(false);
30
+ };
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
+ }
47
+ ),
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: [
57
+ /* @__PURE__ */ jsx(
58
+ SearchStatus,
59
+ {
60
+ query: state.q,
61
+ data: result.data,
62
+ loading,
63
+ error: result.error,
64
+ emptyMessage,
65
+ onRetry: () => void result.refetch()
66
+ }
67
+ ),
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
+ ] }) });
98
+ }
99
+ function SearchInput({
100
+ triggerClassName,
101
+ buttonText = "Search",
102
+ keyboardShortcut = true,
103
+ ...props
104
+ }) {
105
+ const [open, setOpen] = useState(false);
106
+ const trigger = useRef(null);
107
+ const onOpenChange = (nextOpen) => {
108
+ setOpen(nextOpen);
109
+ if (!nextOpen) requestAnimationFrame(() => trigger.current?.focus());
110
+ };
111
+ useEffect(() => {
112
+ if (!keyboardShortcut) return;
113
+ const onKeyDown = (event) => {
114
+ if (event.key.toLowerCase() === "k" && (event.metaKey || event.ctrlKey)) {
115
+ event.preventDefault();
116
+ setOpen(!open);
117
+ if (open) requestAnimationFrame(() => trigger.current?.focus());
118
+ }
119
+ };
120
+ document.addEventListener("keydown", onKeyDown);
121
+ return () => document.removeEventListener("keydown", onKeyDown);
122
+ }, [keyboardShortcut, open]);
123
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
124
+ /* @__PURE__ */ jsxs(
125
+ Button,
126
+ {
127
+ ref: trigger,
128
+ type: "button",
129
+ variant: "outline",
130
+ className: triggerClassName,
131
+ "data-testid": "search-button",
132
+ "aria-haspopup": "dialog",
133
+ "aria-expanded": open,
134
+ onClick: () => setOpen(true),
135
+ children: [
136
+ buttonText,
137
+ keyboardShortcut && /* @__PURE__ */ jsx("kbd", { className: "ml-6 text-xs text-muted-foreground", children: "\u2318K" })
138
+ ]
139
+ }
140
+ ),
141
+ /* @__PURE__ */ jsx(SearchDialog, { ...props, open, onOpenChange })
142
+ ] });
143
+ }
144
+
145
+ export { SearchDialog, SearchInput };
@@ -0,0 +1,100 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ const jsxRuntime = require('react/jsx-runtime');
5
+ const context = require('@btst/stack/context');
6
+ const button = require('../../ui/src/components/button.cjs');
7
+
8
+ function SearchStatus({
9
+ query,
10
+ data,
11
+ loading,
12
+ error,
13
+ emptyMessage = "No results found.",
14
+ onRetry
15
+ }) {
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;
31
+ }
32
+ function SearchResults({ data }) {
33
+ const { router } = context.useStack();
34
+ const Link = router?.Link ?? "a";
35
+ return /* @__PURE__ */ jsxRuntime.jsx(
36
+ "ul",
37
+ {
38
+ className: "divide-y",
39
+ "aria-label": "Search results",
40
+ "data-testid": "search-results",
41
+ children: data.items.map((item) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(
42
+ Link,
43
+ {
44
+ href: item.href,
45
+ className: "block space-y-2 rounded-sm p-4 hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring",
46
+ "data-testid": "search-result",
47
+ children: [
48
+ /* @__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
+ ]
52
+ }
53
+ ) }, item.key))
54
+ }
55
+ );
56
+ }
57
+ function SearchPagination({
58
+ page,
59
+ hasMore,
60
+ loading,
61
+ onPageChange
62
+ }) {
63
+ return /* @__PURE__ */ jsxRuntime.jsxs(
64
+ "nav",
65
+ {
66
+ "aria-label": "Search pagination",
67
+ className: "flex items-center justify-between gap-3 border-t p-4 text-sm",
68
+ children: [
69
+ /* @__PURE__ */ jsxRuntime.jsx(
70
+ button.Button,
71
+ {
72
+ type: "button",
73
+ variant: "outline",
74
+ disabled: page <= 1 || loading,
75
+ onClick: () => onPageChange(page - 1),
76
+ children: "Previous page"
77
+ }
78
+ ),
79
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
80
+ "Page ",
81
+ page
82
+ ] }),
83
+ /* @__PURE__ */ jsxRuntime.jsx(
84
+ button.Button,
85
+ {
86
+ type: "button",
87
+ variant: "outline",
88
+ disabled: !hasMore || loading,
89
+ onClick: () => onPageChange(page + 1),
90
+ children: "Next page"
91
+ }
92
+ )
93
+ ]
94
+ }
95
+ );
96
+ }
97
+
98
+ exports.SearchPagination = SearchPagination;
99
+ exports.SearchResults = SearchResults;
100
+ exports.SearchStatus = SearchStatus;