@btst/plugin-search 1.1.0 → 1.2.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.
- package/dist/client/components/index.d.cts +5 -5
- package/dist/client/components/index.d.mts +5 -5
- package/dist/client/components/index.d.ts +5 -5
- package/dist/client/components/search-dialog.cjs +6 -2
- package/dist/client/components/search-dialog.mjs +6 -2
- package/dist/client/hooks/index.d.cts +3 -3
- package/dist/client/hooks/index.d.mts +3 -3
- package/dist/client/hooks/index.d.ts +3 -3
- package/dist/client/hooks/use-search-state.cjs +28 -3
- package/dist/client/hooks/use-search-state.mjs +28 -3
- package/dist/providers.cjs +11 -2
- package/dist/providers.mjs +11 -2
- package/dist/shared/{plugin-search.5GvThkZW.d.cts → plugin-search.C-Ip75Y6.d.cts} +8 -1
- package/dist/shared/{plugin-search.5GvThkZW.d.mts → plugin-search.C-Ip75Y6.d.mts} +8 -1
- package/dist/shared/{plugin-search.5GvThkZW.d.ts → plugin-search.C-Ip75Y6.d.ts} +8 -1
- package/package.json +2 -2
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
+
import { S as SearchStateControl, a as SearchListState } from '../../shared/plugin-search.C-Ip75Y6.cjs';
|
|
3
4
|
import { SearchPluginOverrides } from '../index.cjs';
|
|
4
|
-
import
|
|
5
|
+
import '@btst/stack/client';
|
|
5
6
|
import '../../types.cjs';
|
|
6
7
|
import '@btst/stack/plugins/api';
|
|
7
|
-
import '@btst/stack/client';
|
|
8
8
|
|
|
9
9
|
/** Shared discovery options. Supplying sources fixes the allowed UI scope. */
|
|
10
|
-
interface SearchPresentationProps extends SearchPluginOverrides {
|
|
10
|
+
interface SearchPresentationProps extends SearchPluginOverrides, SearchStateControl {
|
|
11
11
|
/** Fixed provider IDs; URL source filters cannot expand this selection. */
|
|
12
12
|
sources?: readonly string[];
|
|
13
13
|
className?: string;
|
|
@@ -17,7 +17,7 @@ interface SearchDialogProps extends SearchPresentationProps {
|
|
|
17
17
|
open: boolean;
|
|
18
18
|
onOpenChange: (open: boolean) => void;
|
|
19
19
|
}
|
|
20
|
-
declare function SearchDialog({ open, onOpenChange, sources, className, placeholder, emptyMessage, title, renderResult, renderLoading, }: SearchDialogProps): react.JSX.Element;
|
|
20
|
+
declare function SearchDialog({ open, onOpenChange, sources, className, placeholder, emptyMessage, title, renderResult, renderLoading, searchState, onSearchStateChange, }: SearchDialogProps): react.JSX.Element;
|
|
21
21
|
/** Trigger for the shared dialog, including the optional Cmd/Ctrl+K shortcut. */
|
|
22
22
|
interface SearchInputProps extends SearchPresentationProps {
|
|
23
23
|
triggerClassName?: string;
|
|
@@ -39,5 +39,5 @@ interface SearchHighlightProps {
|
|
|
39
39
|
/** Highlights case-insensitive phrase matches while preserving the original text. */
|
|
40
40
|
declare function SearchHighlight({ text, query }: SearchHighlightProps): string | (string | react.JSX.Element)[];
|
|
41
41
|
|
|
42
|
-
export { SearchDialog, SearchHighlight, SearchInput, SearchPageComponent };
|
|
42
|
+
export { SearchDialog, SearchHighlight, SearchInput, SearchListState, SearchPageComponent, SearchStateControl };
|
|
43
43
|
export type { SearchDialogProps, SearchHighlightProps, SearchInputProps, SearchPresentationProps };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
+
import { S as SearchStateControl, a as SearchListState } from '../../shared/plugin-search.C-Ip75Y6.mjs';
|
|
3
4
|
import { SearchPluginOverrides } from '../index.mjs';
|
|
4
|
-
import
|
|
5
|
+
import '@btst/stack/client';
|
|
5
6
|
import '../../types.mjs';
|
|
6
7
|
import '@btst/stack/plugins/api';
|
|
7
|
-
import '@btst/stack/client';
|
|
8
8
|
|
|
9
9
|
/** Shared discovery options. Supplying sources fixes the allowed UI scope. */
|
|
10
|
-
interface SearchPresentationProps extends SearchPluginOverrides {
|
|
10
|
+
interface SearchPresentationProps extends SearchPluginOverrides, SearchStateControl {
|
|
11
11
|
/** Fixed provider IDs; URL source filters cannot expand this selection. */
|
|
12
12
|
sources?: readonly string[];
|
|
13
13
|
className?: string;
|
|
@@ -17,7 +17,7 @@ interface SearchDialogProps extends SearchPresentationProps {
|
|
|
17
17
|
open: boolean;
|
|
18
18
|
onOpenChange: (open: boolean) => void;
|
|
19
19
|
}
|
|
20
|
-
declare function SearchDialog({ open, onOpenChange, sources, className, placeholder, emptyMessage, title, renderResult, renderLoading, }: SearchDialogProps): react.JSX.Element;
|
|
20
|
+
declare function SearchDialog({ open, onOpenChange, sources, className, placeholder, emptyMessage, title, renderResult, renderLoading, searchState, onSearchStateChange, }: SearchDialogProps): react.JSX.Element;
|
|
21
21
|
/** Trigger for the shared dialog, including the optional Cmd/Ctrl+K shortcut. */
|
|
22
22
|
interface SearchInputProps extends SearchPresentationProps {
|
|
23
23
|
triggerClassName?: string;
|
|
@@ -39,5 +39,5 @@ interface SearchHighlightProps {
|
|
|
39
39
|
/** Highlights case-insensitive phrase matches while preserving the original text. */
|
|
40
40
|
declare function SearchHighlight({ text, query }: SearchHighlightProps): string | (string | react.JSX.Element)[];
|
|
41
41
|
|
|
42
|
-
export { SearchDialog, SearchHighlight, SearchInput, SearchPageComponent };
|
|
42
|
+
export { SearchDialog, SearchHighlight, SearchInput, SearchListState, SearchPageComponent, SearchStateControl };
|
|
43
43
|
export type { SearchDialogProps, SearchHighlightProps, SearchInputProps, SearchPresentationProps };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
+
import { S as SearchStateControl, a as SearchListState } from '../../shared/plugin-search.C-Ip75Y6.js';
|
|
3
4
|
import { SearchPluginOverrides } from '../index.js';
|
|
4
|
-
import
|
|
5
|
+
import '@btst/stack/client';
|
|
5
6
|
import '../../types.js';
|
|
6
7
|
import '@btst/stack/plugins/api';
|
|
7
|
-
import '@btst/stack/client';
|
|
8
8
|
|
|
9
9
|
/** Shared discovery options. Supplying sources fixes the allowed UI scope. */
|
|
10
|
-
interface SearchPresentationProps extends SearchPluginOverrides {
|
|
10
|
+
interface SearchPresentationProps extends SearchPluginOverrides, SearchStateControl {
|
|
11
11
|
/** Fixed provider IDs; URL source filters cannot expand this selection. */
|
|
12
12
|
sources?: readonly string[];
|
|
13
13
|
className?: string;
|
|
@@ -17,7 +17,7 @@ interface SearchDialogProps extends SearchPresentationProps {
|
|
|
17
17
|
open: boolean;
|
|
18
18
|
onOpenChange: (open: boolean) => void;
|
|
19
19
|
}
|
|
20
|
-
declare function SearchDialog({ open, onOpenChange, sources, className, placeholder, emptyMessage, title, renderResult, renderLoading, }: SearchDialogProps): react.JSX.Element;
|
|
20
|
+
declare function SearchDialog({ open, onOpenChange, sources, className, placeholder, emptyMessage, title, renderResult, renderLoading, searchState, onSearchStateChange, }: SearchDialogProps): react.JSX.Element;
|
|
21
21
|
/** Trigger for the shared dialog, including the optional Cmd/Ctrl+K shortcut. */
|
|
22
22
|
interface SearchInputProps extends SearchPresentationProps {
|
|
23
23
|
triggerClassName?: string;
|
|
@@ -39,5 +39,5 @@ interface SearchHighlightProps {
|
|
|
39
39
|
/** Highlights case-insensitive phrase matches while preserving the original text. */
|
|
40
40
|
declare function SearchHighlight({ text, query }: SearchHighlightProps): string | (string | react.JSX.Element)[];
|
|
41
41
|
|
|
42
|
-
export { SearchDialog, SearchHighlight, SearchInput, SearchPageComponent };
|
|
42
|
+
export { SearchDialog, SearchHighlight, SearchInput, SearchListState, SearchPageComponent, SearchStateControl };
|
|
43
43
|
export type { SearchDialogProps, SearchHighlightProps, SearchInputProps, SearchPresentationProps };
|
|
@@ -22,13 +22,17 @@ function SearchDialog({
|
|
|
22
22
|
emptyMessage,
|
|
23
23
|
title = "Search",
|
|
24
24
|
renderResult,
|
|
25
|
-
renderLoading
|
|
25
|
+
renderLoading,
|
|
26
|
+
searchState,
|
|
27
|
+
onSearchStateChange
|
|
26
28
|
}) {
|
|
27
29
|
const { router } = context.useStack();
|
|
28
30
|
const inputRef = react.useRef(null);
|
|
29
31
|
const { state, setState, result, fixedSources, loading } = useSearchState.useSearchState({
|
|
30
32
|
sources,
|
|
31
|
-
enabled: open
|
|
33
|
+
enabled: open,
|
|
34
|
+
searchState,
|
|
35
|
+
onSearchStateChange
|
|
32
36
|
});
|
|
33
37
|
const navigate = async (href) => {
|
|
34
38
|
if (router?.navigate) await router.navigate(href);
|
|
@@ -20,13 +20,17 @@ function SearchDialog({
|
|
|
20
20
|
emptyMessage,
|
|
21
21
|
title = "Search",
|
|
22
22
|
renderResult,
|
|
23
|
-
renderLoading
|
|
23
|
+
renderLoading,
|
|
24
|
+
searchState,
|
|
25
|
+
onSearchStateChange
|
|
24
26
|
}) {
|
|
25
27
|
const { router } = useStack();
|
|
26
28
|
const inputRef = useRef(null);
|
|
27
29
|
const { state, setState, result, fixedSources, loading } = useSearchState({
|
|
28
30
|
sources,
|
|
29
|
-
enabled: open
|
|
31
|
+
enabled: open,
|
|
32
|
+
searchState,
|
|
33
|
+
onSearchStateChange
|
|
30
34
|
});
|
|
31
35
|
const navigate = async (href) => {
|
|
32
36
|
if (router?.navigate) await router.navigate(href);
|
|
@@ -3,7 +3,7 @@ import * as _tanstack_react_query from '@tanstack/react-query';
|
|
|
3
3
|
import { SearchResponse } from '../../types.cjs';
|
|
4
4
|
import { SearchQueryParams } from '../../query-keys.cjs';
|
|
5
5
|
import * as _btst_stack_client from '@btst/stack/client';
|
|
6
|
-
import { S as SearchListState } from '../../shared/plugin-search.
|
|
6
|
+
import { S as SearchStateControl, a as SearchListState } from '../../shared/plugin-search.C-Ip75Y6.cjs';
|
|
7
7
|
import '@btst/stack/plugins/api';
|
|
8
8
|
import '@btst/stack/plugins/client';
|
|
9
9
|
import '@btst/stack/context';
|
|
@@ -167,7 +167,7 @@ declare function useSearch(params: SearchQueryParams, enabled?: boolean): {
|
|
|
167
167
|
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
168
168
|
};
|
|
169
169
|
|
|
170
|
-
declare function useSearchState({ sources, initialSearch, enabled, }?: {
|
|
170
|
+
declare function useSearchState({ sources, initialSearch, enabled, searchState, onSearchStateChange, }?: SearchStateControl & {
|
|
171
171
|
sources?: readonly string[];
|
|
172
172
|
initialSearch?: SearchListState;
|
|
173
173
|
enabled?: boolean;
|
|
@@ -337,4 +337,4 @@ declare function useSearchState({ sources, initialSearch, enabled, }?: {
|
|
|
337
337
|
loading: boolean;
|
|
338
338
|
};
|
|
339
339
|
|
|
340
|
-
export { useSearch, useSearchState };
|
|
340
|
+
export { SearchListState, SearchStateControl, useSearch, useSearchState };
|
|
@@ -3,7 +3,7 @@ import * as _tanstack_react_query from '@tanstack/react-query';
|
|
|
3
3
|
import { SearchResponse } from '../../types.mjs';
|
|
4
4
|
import { SearchQueryParams } from '../../query-keys.mjs';
|
|
5
5
|
import * as _btst_stack_client from '@btst/stack/client';
|
|
6
|
-
import { S as SearchListState } from '../../shared/plugin-search.
|
|
6
|
+
import { S as SearchStateControl, a as SearchListState } from '../../shared/plugin-search.C-Ip75Y6.mjs';
|
|
7
7
|
import '@btst/stack/plugins/api';
|
|
8
8
|
import '@btst/stack/plugins/client';
|
|
9
9
|
import '@btst/stack/context';
|
|
@@ -167,7 +167,7 @@ declare function useSearch(params: SearchQueryParams, enabled?: boolean): {
|
|
|
167
167
|
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
168
168
|
};
|
|
169
169
|
|
|
170
|
-
declare function useSearchState({ sources, initialSearch, enabled, }?: {
|
|
170
|
+
declare function useSearchState({ sources, initialSearch, enabled, searchState, onSearchStateChange, }?: SearchStateControl & {
|
|
171
171
|
sources?: readonly string[];
|
|
172
172
|
initialSearch?: SearchListState;
|
|
173
173
|
enabled?: boolean;
|
|
@@ -337,4 +337,4 @@ declare function useSearchState({ sources, initialSearch, enabled, }?: {
|
|
|
337
337
|
loading: boolean;
|
|
338
338
|
};
|
|
339
339
|
|
|
340
|
-
export { useSearch, useSearchState };
|
|
340
|
+
export { SearchListState, SearchStateControl, useSearch, useSearchState };
|
|
@@ -3,7 +3,7 @@ import * as _tanstack_react_query from '@tanstack/react-query';
|
|
|
3
3
|
import { SearchResponse } from '../../types.js';
|
|
4
4
|
import { SearchQueryParams } from '../../query-keys.js';
|
|
5
5
|
import * as _btst_stack_client from '@btst/stack/client';
|
|
6
|
-
import { S as SearchListState } from '../../shared/plugin-search.
|
|
6
|
+
import { S as SearchStateControl, a as SearchListState } from '../../shared/plugin-search.C-Ip75Y6.js';
|
|
7
7
|
import '@btst/stack/plugins/api';
|
|
8
8
|
import '@btst/stack/plugins/client';
|
|
9
9
|
import '@btst/stack/context';
|
|
@@ -167,7 +167,7 @@ declare function useSearch(params: SearchQueryParams, enabled?: boolean): {
|
|
|
167
167
|
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
168
168
|
};
|
|
169
169
|
|
|
170
|
-
declare function useSearchState({ sources, initialSearch, enabled, }?: {
|
|
170
|
+
declare function useSearchState({ sources, initialSearch, enabled, searchState, onSearchStateChange, }?: SearchStateControl & {
|
|
171
171
|
sources?: readonly string[];
|
|
172
172
|
initialSearch?: SearchListState;
|
|
173
173
|
enabled?: boolean;
|
|
@@ -337,4 +337,4 @@ declare function useSearchState({ sources, initialSearch, enabled, }?: {
|
|
|
337
337
|
loading: boolean;
|
|
338
338
|
};
|
|
339
339
|
|
|
340
|
-
export { useSearch, useSearchState };
|
|
340
|
+
export { SearchListState, SearchStateControl, useSearch, useSearchState };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
const react = require('react');
|
|
4
5
|
const hooks = require('@btst/stack/client/hooks');
|
|
5
6
|
const hooks$1 = require('@btst/stack/plugins/client/hooks');
|
|
6
7
|
const useSearch = require('./use-search.cjs');
|
|
@@ -10,13 +11,37 @@ const searchState = require('../search-state.cjs');
|
|
|
10
11
|
function useSearchState({
|
|
11
12
|
sources,
|
|
12
13
|
initialSearch,
|
|
13
|
-
enabled = true
|
|
14
|
+
enabled = true,
|
|
15
|
+
searchState: searchState$1,
|
|
16
|
+
onSearchStateChange
|
|
14
17
|
} = {}) {
|
|
15
|
-
const [urlState,
|
|
18
|
+
const [urlState, setUrlState] = hooks.useListState(
|
|
16
19
|
constants.SEARCH_PLUGIN_ID,
|
|
17
20
|
searchState.SEARCH_LIST_STATE_SCHEMA
|
|
18
21
|
);
|
|
19
|
-
const state = typeof window === "undefined" && initialSearch ? initialSearch : urlState;
|
|
22
|
+
const state = searchState$1 ?? (typeof window === "undefined" && initialSearch ? initialSearch : urlState);
|
|
23
|
+
const pendingState = react.useRef(void 0);
|
|
24
|
+
react.useEffect(() => {
|
|
25
|
+
pendingState.current = void 0;
|
|
26
|
+
});
|
|
27
|
+
const setState = react.useCallback(
|
|
28
|
+
(updates, options) => {
|
|
29
|
+
if (searchState$1 === void 0) {
|
|
30
|
+
setUrlState(updates, options);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!onSearchStateChange) return;
|
|
34
|
+
const previous = pendingState.current ?? searchState$1;
|
|
35
|
+
const patch = typeof updates === "function" ? updates(previous) : updates;
|
|
36
|
+
const next = { ...previous, ...patch };
|
|
37
|
+
pendingState.current = next;
|
|
38
|
+
queueMicrotask(() => {
|
|
39
|
+
if (pendingState.current === next) pendingState.current = void 0;
|
|
40
|
+
});
|
|
41
|
+
onSearchStateChange(next);
|
|
42
|
+
},
|
|
43
|
+
[searchState$1, onSearchStateChange, setUrlState]
|
|
44
|
+
);
|
|
20
45
|
const q = hooks$1.useDebounce(state.q, 300);
|
|
21
46
|
const fixedSources = sources !== void 0;
|
|
22
47
|
const selectedSources = sources ?? (state.sources ? state.sources.split(",") : void 0);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { useRef, useEffect, useCallback } from 'react';
|
|
2
3
|
import { useListState } from '@btst/stack/client/hooks';
|
|
3
4
|
import { useDebounce } from '@btst/stack/plugins/client/hooks';
|
|
4
5
|
import { useSearch } from './use-search.mjs';
|
|
@@ -8,13 +9,37 @@ import { SEARCH_LIST_STATE_SCHEMA } from '../search-state.mjs';
|
|
|
8
9
|
function useSearchState({
|
|
9
10
|
sources,
|
|
10
11
|
initialSearch,
|
|
11
|
-
enabled = true
|
|
12
|
+
enabled = true,
|
|
13
|
+
searchState,
|
|
14
|
+
onSearchStateChange
|
|
12
15
|
} = {}) {
|
|
13
|
-
const [urlState,
|
|
16
|
+
const [urlState, setUrlState] = useListState(
|
|
14
17
|
SEARCH_PLUGIN_ID,
|
|
15
18
|
SEARCH_LIST_STATE_SCHEMA
|
|
16
19
|
);
|
|
17
|
-
const state = typeof window === "undefined" && initialSearch ? initialSearch : urlState;
|
|
20
|
+
const state = searchState ?? (typeof window === "undefined" && initialSearch ? initialSearch : urlState);
|
|
21
|
+
const pendingState = useRef(void 0);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
pendingState.current = void 0;
|
|
24
|
+
});
|
|
25
|
+
const setState = useCallback(
|
|
26
|
+
(updates, options) => {
|
|
27
|
+
if (searchState === void 0) {
|
|
28
|
+
setUrlState(updates, options);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!onSearchStateChange) return;
|
|
32
|
+
const previous = pendingState.current ?? searchState;
|
|
33
|
+
const patch = typeof updates === "function" ? updates(previous) : updates;
|
|
34
|
+
const next = { ...previous, ...patch };
|
|
35
|
+
pendingState.current = next;
|
|
36
|
+
queueMicrotask(() => {
|
|
37
|
+
if (pendingState.current === next) pendingState.current = void 0;
|
|
38
|
+
});
|
|
39
|
+
onSearchStateChange(next);
|
|
40
|
+
},
|
|
41
|
+
[searchState, onSearchStateChange, setUrlState]
|
|
42
|
+
);
|
|
18
43
|
const q = useDebounce(state.q, 300);
|
|
19
44
|
const fixedSources = sources !== void 0;
|
|
20
45
|
const selectedSources = sources ?? (state.sources ? state.sources.split(",") : void 0);
|
package/dist/providers.cjs
CHANGED
|
@@ -8,7 +8,7 @@ function normalizeSearchText(value) {
|
|
|
8
8
|
}
|
|
9
9
|
function searchRelevance(result, query) {
|
|
10
10
|
const q = normalizeSearchText(query);
|
|
11
|
-
if (!q) return
|
|
11
|
+
if (!q) return 9;
|
|
12
12
|
const title = normalizeSearchText(result.title);
|
|
13
13
|
const aliases = result.aliases?.map(normalizeSearchText) ?? [];
|
|
14
14
|
if (title === q) return 0;
|
|
@@ -17,7 +17,16 @@ function searchRelevance(result, query) {
|
|
|
17
17
|
if (aliases.some((alias) => alias.startsWith(q))) return 3;
|
|
18
18
|
if (title.includes(q)) return 4;
|
|
19
19
|
if (aliases.some((alias) => alias.includes(q))) return 5;
|
|
20
|
-
|
|
20
|
+
const terms = [
|
|
21
|
+
...new Set(query.split(/\s+/).map(normalizeSearchText).filter(Boolean))
|
|
22
|
+
];
|
|
23
|
+
const containsTerms = (value) => {
|
|
24
|
+
const words = value.split(/\s+/).map(normalizeSearchText);
|
|
25
|
+
return terms.every((term) => words.some((word) => word.includes(term)));
|
|
26
|
+
};
|
|
27
|
+
if (containsTerms(result.title)) return 6;
|
|
28
|
+
if (result.aliases?.some(containsTerms)) return 7;
|
|
29
|
+
return normalizeSearchText(result.snippet).includes(q) ? 8 : 9;
|
|
21
30
|
}
|
|
22
31
|
function destination(basePath, slug) {
|
|
23
32
|
return `${basePath.replace(/\/$/, "")}/${encodeURIComponent(slug)}`;
|
package/dist/providers.mjs
CHANGED
|
@@ -6,7 +6,7 @@ function normalizeSearchText(value) {
|
|
|
6
6
|
}
|
|
7
7
|
function searchRelevance(result, query) {
|
|
8
8
|
const q = normalizeSearchText(query);
|
|
9
|
-
if (!q) return
|
|
9
|
+
if (!q) return 9;
|
|
10
10
|
const title = normalizeSearchText(result.title);
|
|
11
11
|
const aliases = result.aliases?.map(normalizeSearchText) ?? [];
|
|
12
12
|
if (title === q) return 0;
|
|
@@ -15,7 +15,16 @@ function searchRelevance(result, query) {
|
|
|
15
15
|
if (aliases.some((alias) => alias.startsWith(q))) return 3;
|
|
16
16
|
if (title.includes(q)) return 4;
|
|
17
17
|
if (aliases.some((alias) => alias.includes(q))) return 5;
|
|
18
|
-
|
|
18
|
+
const terms = [
|
|
19
|
+
...new Set(query.split(/\s+/).map(normalizeSearchText).filter(Boolean))
|
|
20
|
+
];
|
|
21
|
+
const containsTerms = (value) => {
|
|
22
|
+
const words = value.split(/\s+/).map(normalizeSearchText);
|
|
23
|
+
return terms.every((term) => words.some((word) => word.includes(term)));
|
|
24
|
+
};
|
|
25
|
+
if (containsTerms(result.title)) return 6;
|
|
26
|
+
if (result.aliases?.some(containsTerms)) return 7;
|
|
27
|
+
return normalizeSearchText(result.snippet).includes(q) ? 8 : 9;
|
|
19
28
|
}
|
|
20
29
|
function destination(basePath, slug) {
|
|
21
30
|
return `${basePath.replace(/\/$/, "")}/${encodeURIComponent(slug)}`;
|
|
@@ -16,5 +16,12 @@ declare function parseSearchState(searchParams?: URLSearchParams | string): _bts
|
|
|
16
16
|
};
|
|
17
17
|
}>;
|
|
18
18
|
type SearchListState = ReturnType<typeof parseSearchState>;
|
|
19
|
+
/** Opt-in host ownership of embedded search state, independent of router queries. */
|
|
20
|
+
interface SearchStateControl {
|
|
21
|
+
/** Controlled query, comma-separated source IDs and page. Omit for existing router/local state. */
|
|
22
|
+
searchState?: SearchListState;
|
|
23
|
+
/** Receives the complete next state. Supply with searchState to make controls editable. */
|
|
24
|
+
onSearchStateChange?: (state: SearchListState) => void;
|
|
25
|
+
}
|
|
19
26
|
|
|
20
|
-
export type {
|
|
27
|
+
export type { SearchStateControl as S, SearchListState as a };
|
|
@@ -16,5 +16,12 @@ declare function parseSearchState(searchParams?: URLSearchParams | string): _bts
|
|
|
16
16
|
};
|
|
17
17
|
}>;
|
|
18
18
|
type SearchListState = ReturnType<typeof parseSearchState>;
|
|
19
|
+
/** Opt-in host ownership of embedded search state, independent of router queries. */
|
|
20
|
+
interface SearchStateControl {
|
|
21
|
+
/** Controlled query, comma-separated source IDs and page. Omit for existing router/local state. */
|
|
22
|
+
searchState?: SearchListState;
|
|
23
|
+
/** Receives the complete next state. Supply with searchState to make controls editable. */
|
|
24
|
+
onSearchStateChange?: (state: SearchListState) => void;
|
|
25
|
+
}
|
|
19
26
|
|
|
20
|
-
export type {
|
|
27
|
+
export type { SearchStateControl as S, SearchListState as a };
|
|
@@ -16,5 +16,12 @@ declare function parseSearchState(searchParams?: URLSearchParams | string): _bts
|
|
|
16
16
|
};
|
|
17
17
|
}>;
|
|
18
18
|
type SearchListState = ReturnType<typeof parseSearchState>;
|
|
19
|
+
/** Opt-in host ownership of embedded search state, independent of router queries. */
|
|
20
|
+
interface SearchStateControl {
|
|
21
|
+
/** Controlled query, comma-separated source IDs and page. Omit for existing router/local state. */
|
|
22
|
+
searchState?: SearchListState;
|
|
23
|
+
/** Receives the complete next state. Supply with searchState to make controls editable. */
|
|
24
|
+
onSearchStateChange?: (state: SearchListState) => void;
|
|
25
|
+
}
|
|
19
26
|
|
|
20
|
-
export type {
|
|
27
|
+
export type { SearchStateControl as S, SearchListState as a };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btst/plugin-search",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
"@btst/stack": "6.2.2",
|
|
176
176
|
"@workspace/ui": "0.0.0"
|
|
177
177
|
},
|
|
178
|
-
"gitHead": "
|
|
178
|
+
"gitHead": "1537a8869f180c480e600dc5e62087353aadd6f3",
|
|
179
179
|
"scripts": {
|
|
180
180
|
"build": "unbuild --clean",
|
|
181
181
|
"typecheck": "tsc --project tsconfig.json",
|