@md-plugins/search-ui 0.1.0-rc.9 → 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.
package/README.md CHANGED
@@ -1,7 +1,18 @@
1
1
  # @md-plugins/search-ui
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@md-plugins/search-ui?label=%40md-plugins%2Fsearch-ui)](https://www.npmjs.com/package/@md-plugins/search-ui)
4
+ [![npm downloads](https://img.shields.io/npm/dt/@md-plugins/search-ui)](https://www.npmjs.com/package/@md-plugins/search-ui)
5
+ [![npm monthly downloads](https://img.shields.io/npm/dm/@md-plugins/search-ui)](https://www.npmjs.com/package/@md-plugins/search-ui)
6
+ [![license](https://img.shields.io/npm/l/@md-plugins/search-ui)](https://www.npmjs.com/package/@md-plugins/search-ui)
7
+
8
+ <span class="badge-github-sponsors"><a href="https://github.com/sponsors/hawkeye64" title="Sponsor this project on GitHub"><img src="https://img.shields.io/badge/github-sponsors-ea4aaa.svg?logo=githubsponsors&logoColor=white" alt="GitHub Sponsors button" /></a></span>
9
+ <span class="badge-paypal"><a href="https://paypal.me/hawkeye64" title="Donate to this project using Paypal"><img src="https://img.shields.io/badge/paypal-donate-yellow.svg" alt="PayPal donate button" /></a></span>
10
+
11
+ [![Discord](https://img.shields.io/badge/discord-join%20server-738ADB?style=for-the-badge&logo=discord&logoColor=738ADB)](https://chat.quasar.dev)
12
+ [![X](https://img.shields.io/badge/follow-@jgalbraith64-1DA1F2?style=for-the-badge&logo=x&logoColor=1DA1F2)](https://twitter.com/jgalbraith64)
13
+
3
14
  Framework-agnostic search UI for search indexes generated by
4
- `@md-plugins/vite-search-plugin`.
15
+ `@md-plugins/vite-search-plugin`. Q-Press uses it for header search, and non-Q-Press sites can use the same Web Component against a generated JSON index or a custom provider.
5
16
 
6
17
  The package provides:
7
18
 
package/dist/index.d.mts CHANGED
@@ -1,133 +1,128 @@
1
1
  type MaybePromise<T> = T | Promise<T>;
2
2
  type SearchRecordType = 'page' | 'heading' | 'content';
3
3
  interface SearchRecordSource {
4
- file: string;
5
- relativeFile: string;
4
+ file: string;
5
+ relativeFile: string;
6
6
  }
7
7
  interface SearchRecord {
8
- id: string;
9
- type: SearchRecordType;
10
- title: string;
11
- content: string;
12
- url: string;
13
- path: string;
14
- anchor?: string;
15
- section?: string;
16
- hierarchy: string[];
17
- tags: string[];
18
- source: SearchRecordSource;
19
- meta?: Record<string, unknown>;
8
+ id: string;
9
+ type: SearchRecordType;
10
+ title: string;
11
+ content: string;
12
+ url: string;
13
+ path: string;
14
+ anchor?: string;
15
+ section?: string;
16
+ hierarchy: string[];
17
+ tags: string[];
18
+ source: SearchRecordSource;
19
+ meta?: Record<string, unknown>;
20
20
  }
21
21
  interface SearchIndex {
22
- generatedAt: string;
23
- recordCount: number;
24
- records: SearchRecord[];
22
+ generatedAt: string;
23
+ recordCount: number;
24
+ records: SearchRecord[];
25
25
  }
26
26
  interface SearchResult {
27
- id: string;
28
- title: string;
29
- url: string;
30
- content: string;
31
- score: number;
32
- type: SearchRecordType;
33
- path: string;
34
- section?: string;
35
- hierarchy: string[];
36
- tags: string[];
37
- record: SearchRecord;
27
+ id: string;
28
+ title: string;
29
+ url: string;
30
+ content: string;
31
+ score: number;
32
+ type: SearchRecordType;
33
+ path: string;
34
+ section?: string;
35
+ hierarchy: string[];
36
+ tags: string[];
37
+ record: SearchRecord;
38
38
  }
39
39
  interface SearchOptions {
40
- limit?: number;
41
- collapseDuplicateResults?: boolean;
40
+ limit?: number;
41
+ collapseDuplicateResults?: boolean;
42
42
  }
43
43
  interface SearchProvider {
44
- search: (query: string, options?: SearchOptions) => MaybePromise<SearchResult[]>;
44
+ search: (query: string, options?: SearchOptions) => MaybePromise<SearchResult[]>;
45
45
  }
46
46
  interface JsonSearchProviderOptions {
47
- src?: string;
48
- index?: SearchIndex | SearchRecord[];
49
- fetcher?: typeof fetch;
47
+ src?: string;
48
+ index?: SearchIndex | SearchRecord[];
49
+ fetcher?: typeof fetch;
50
50
  }
51
51
  interface MdSearchSelectEventDetail {
52
- result: SearchResult;
52
+ result: SearchResult;
53
53
  }
54
54
  interface CreateSearchOptions {
55
- target: Element;
56
- src?: string;
57
- provider?: SearchProvider;
58
- placeholder?: string;
59
- triggerLabel?: string;
60
- panelTitle?: string;
61
- searchLabel?: string;
62
- theme?: 'light' | 'dark';
63
- shortcut?: string;
64
- minQueryLength?: number;
65
- maxResults?: number;
66
- showDuplicateResults?: boolean;
55
+ target: Element;
56
+ src?: string;
57
+ provider?: SearchProvider;
58
+ placeholder?: string;
59
+ triggerLabel?: string;
60
+ panelTitle?: string;
61
+ searchLabel?: string;
62
+ theme?: 'light' | 'dark';
63
+ shortcut?: string;
64
+ minQueryLength?: number;
65
+ maxResults?: number;
66
+ showDuplicateResults?: boolean;
67
67
  }
68
-
69
68
  declare const HTMLElementBase: {
70
- new (): HTMLElement;
71
- prototype: HTMLElement;
69
+ new (): HTMLElement;
70
+ prototype: HTMLElement;
72
71
  };
73
72
  declare class MdSearchElement extends HTMLElementBase {
74
- static observedAttributes: string[];
75
- provider?: SearchProvider;
76
- private readonly root;
77
- private readonly elementId;
78
- private results;
79
- private query;
80
- private opened;
81
- private loading;
82
- private errorMessage;
83
- private activeIndex;
84
- private searchTimer;
85
- private searchRequestId;
86
- private selectionStart;
87
- private selectionEnd;
88
- connectedCallback(): void;
89
- disconnectedCallback(): void;
90
- attributeChangedCallback(name: string): void;
91
- open(): void;
92
- close(): void;
93
- toggle(): void;
94
- private get src();
95
- private get placeholder();
96
- private get triggerLabel();
97
- private get panelTitle();
98
- private get searchLabel();
99
- private get shortcut();
100
- private get minQueryLength();
101
- private get maxResults();
102
- private get showDuplicateResults();
103
- private get activeResult();
104
- private getProvider;
105
- private readonly onGlobalKeydown;
106
- private readonly onInput;
107
- private readonly onDialogKeydown;
108
- private runSearch;
109
- private focusInput;
110
- private setActiveIndex;
111
- private syncInputAria;
112
- private syncActiveResult;
113
- private selectResult;
114
- private bindResultEvents;
115
- private renderResultsContainer;
116
- private renderResults;
117
- private render;
118
- private bindEvents;
73
+ static observedAttributes: string[];
74
+ provider?: SearchProvider;
75
+ private readonly root;
76
+ private readonly elementId;
77
+ private results;
78
+ private query;
79
+ private opened;
80
+ private loading;
81
+ private errorMessage;
82
+ private activeIndex;
83
+ private searchTimer;
84
+ private searchRequestId;
85
+ private selectionStart;
86
+ private selectionEnd;
87
+ connectedCallback(): void;
88
+ disconnectedCallback(): void;
89
+ attributeChangedCallback(name: string): void;
90
+ open(): void;
91
+ close(): void;
92
+ toggle(): void;
93
+ private get src();
94
+ private get placeholder();
95
+ private get triggerLabel();
96
+ private get panelTitle();
97
+ private get searchLabel();
98
+ private get shortcut();
99
+ private get minQueryLength();
100
+ private get maxResults();
101
+ private get showDuplicateResults();
102
+ private get activeResult();
103
+ private getProvider;
104
+ private readonly onGlobalKeydown;
105
+ private readonly onInput;
106
+ private readonly onDialogKeydown;
107
+ private runSearch;
108
+ private focusInput;
109
+ private setActiveIndex;
110
+ private syncInputAria;
111
+ private syncActiveResult;
112
+ private selectResult;
113
+ private bindResultEvents;
114
+ private renderResultsContainer;
115
+ private renderResults;
116
+ private render;
117
+ private bindEvents;
119
118
  }
120
119
  declare function defineMdSearchElement(name?: string): void;
121
120
  declare function createSearch(options: CreateSearchOptions): MdSearchElement;
122
-
123
121
  declare function searchRecords(records: SearchRecord[], query: string, options?: SearchOptions): SearchResult[];
124
122
  declare function createStaticSearchProvider(records: SearchRecord[]): SearchProvider;
125
123
  declare function createJsonSearchProvider(options?: JsonSearchProviderOptions): SearchProvider;
126
-
127
124
  declare function normalizeSearchQuery(value: string): string;
128
125
  declare function createSearchTerms(query: string): string[];
129
126
  declare function normalizeSearchableText(value: unknown): string;
130
127
  declare function createSearchSnippet(content: string, terms: string[], length?: number): string;
131
-
132
- export { MdSearchElement, createJsonSearchProvider, createSearch, createSearchSnippet, createSearchTerms, createStaticSearchProvider, defineMdSearchElement, normalizeSearchQuery, normalizeSearchableText, searchRecords };
133
- export type { CreateSearchOptions, JsonSearchProviderOptions, MaybePromise, MdSearchSelectEventDetail, SearchIndex, SearchOptions, SearchProvider, SearchRecord, SearchRecordSource, SearchRecordType, SearchResult };
128
+ export { type CreateSearchOptions, type JsonSearchProviderOptions, type MaybePromise, MdSearchElement, type MdSearchSelectEventDetail, type SearchIndex, type SearchOptions, type SearchProvider, type SearchRecord, type SearchRecordSource, type SearchRecordType, type SearchResult, createJsonSearchProvider, createSearch, createSearchSnippet, createSearchTerms, createStaticSearchProvider, defineMdSearchElement, normalizeSearchQuery, normalizeSearchableText, searchRecords };
package/dist/index.d.ts CHANGED
@@ -1,133 +1,128 @@
1
1
  type MaybePromise<T> = T | Promise<T>;
2
2
  type SearchRecordType = 'page' | 'heading' | 'content';
3
3
  interface SearchRecordSource {
4
- file: string;
5
- relativeFile: string;
4
+ file: string;
5
+ relativeFile: string;
6
6
  }
7
7
  interface SearchRecord {
8
- id: string;
9
- type: SearchRecordType;
10
- title: string;
11
- content: string;
12
- url: string;
13
- path: string;
14
- anchor?: string;
15
- section?: string;
16
- hierarchy: string[];
17
- tags: string[];
18
- source: SearchRecordSource;
19
- meta?: Record<string, unknown>;
8
+ id: string;
9
+ type: SearchRecordType;
10
+ title: string;
11
+ content: string;
12
+ url: string;
13
+ path: string;
14
+ anchor?: string;
15
+ section?: string;
16
+ hierarchy: string[];
17
+ tags: string[];
18
+ source: SearchRecordSource;
19
+ meta?: Record<string, unknown>;
20
20
  }
21
21
  interface SearchIndex {
22
- generatedAt: string;
23
- recordCount: number;
24
- records: SearchRecord[];
22
+ generatedAt: string;
23
+ recordCount: number;
24
+ records: SearchRecord[];
25
25
  }
26
26
  interface SearchResult {
27
- id: string;
28
- title: string;
29
- url: string;
30
- content: string;
31
- score: number;
32
- type: SearchRecordType;
33
- path: string;
34
- section?: string;
35
- hierarchy: string[];
36
- tags: string[];
37
- record: SearchRecord;
27
+ id: string;
28
+ title: string;
29
+ url: string;
30
+ content: string;
31
+ score: number;
32
+ type: SearchRecordType;
33
+ path: string;
34
+ section?: string;
35
+ hierarchy: string[];
36
+ tags: string[];
37
+ record: SearchRecord;
38
38
  }
39
39
  interface SearchOptions {
40
- limit?: number;
41
- collapseDuplicateResults?: boolean;
40
+ limit?: number;
41
+ collapseDuplicateResults?: boolean;
42
42
  }
43
43
  interface SearchProvider {
44
- search: (query: string, options?: SearchOptions) => MaybePromise<SearchResult[]>;
44
+ search: (query: string, options?: SearchOptions) => MaybePromise<SearchResult[]>;
45
45
  }
46
46
  interface JsonSearchProviderOptions {
47
- src?: string;
48
- index?: SearchIndex | SearchRecord[];
49
- fetcher?: typeof fetch;
47
+ src?: string;
48
+ index?: SearchIndex | SearchRecord[];
49
+ fetcher?: typeof fetch;
50
50
  }
51
51
  interface MdSearchSelectEventDetail {
52
- result: SearchResult;
52
+ result: SearchResult;
53
53
  }
54
54
  interface CreateSearchOptions {
55
- target: Element;
56
- src?: string;
57
- provider?: SearchProvider;
58
- placeholder?: string;
59
- triggerLabel?: string;
60
- panelTitle?: string;
61
- searchLabel?: string;
62
- theme?: 'light' | 'dark';
63
- shortcut?: string;
64
- minQueryLength?: number;
65
- maxResults?: number;
66
- showDuplicateResults?: boolean;
55
+ target: Element;
56
+ src?: string;
57
+ provider?: SearchProvider;
58
+ placeholder?: string;
59
+ triggerLabel?: string;
60
+ panelTitle?: string;
61
+ searchLabel?: string;
62
+ theme?: 'light' | 'dark';
63
+ shortcut?: string;
64
+ minQueryLength?: number;
65
+ maxResults?: number;
66
+ showDuplicateResults?: boolean;
67
67
  }
68
-
69
68
  declare const HTMLElementBase: {
70
- new (): HTMLElement;
71
- prototype: HTMLElement;
69
+ new (): HTMLElement;
70
+ prototype: HTMLElement;
72
71
  };
73
72
  declare class MdSearchElement extends HTMLElementBase {
74
- static observedAttributes: string[];
75
- provider?: SearchProvider;
76
- private readonly root;
77
- private readonly elementId;
78
- private results;
79
- private query;
80
- private opened;
81
- private loading;
82
- private errorMessage;
83
- private activeIndex;
84
- private searchTimer;
85
- private searchRequestId;
86
- private selectionStart;
87
- private selectionEnd;
88
- connectedCallback(): void;
89
- disconnectedCallback(): void;
90
- attributeChangedCallback(name: string): void;
91
- open(): void;
92
- close(): void;
93
- toggle(): void;
94
- private get src();
95
- private get placeholder();
96
- private get triggerLabel();
97
- private get panelTitle();
98
- private get searchLabel();
99
- private get shortcut();
100
- private get minQueryLength();
101
- private get maxResults();
102
- private get showDuplicateResults();
103
- private get activeResult();
104
- private getProvider;
105
- private readonly onGlobalKeydown;
106
- private readonly onInput;
107
- private readonly onDialogKeydown;
108
- private runSearch;
109
- private focusInput;
110
- private setActiveIndex;
111
- private syncInputAria;
112
- private syncActiveResult;
113
- private selectResult;
114
- private bindResultEvents;
115
- private renderResultsContainer;
116
- private renderResults;
117
- private render;
118
- private bindEvents;
73
+ static observedAttributes: string[];
74
+ provider?: SearchProvider;
75
+ private readonly root;
76
+ private readonly elementId;
77
+ private results;
78
+ private query;
79
+ private opened;
80
+ private loading;
81
+ private errorMessage;
82
+ private activeIndex;
83
+ private searchTimer;
84
+ private searchRequestId;
85
+ private selectionStart;
86
+ private selectionEnd;
87
+ connectedCallback(): void;
88
+ disconnectedCallback(): void;
89
+ attributeChangedCallback(name: string): void;
90
+ open(): void;
91
+ close(): void;
92
+ toggle(): void;
93
+ private get src();
94
+ private get placeholder();
95
+ private get triggerLabel();
96
+ private get panelTitle();
97
+ private get searchLabel();
98
+ private get shortcut();
99
+ private get minQueryLength();
100
+ private get maxResults();
101
+ private get showDuplicateResults();
102
+ private get activeResult();
103
+ private getProvider;
104
+ private readonly onGlobalKeydown;
105
+ private readonly onInput;
106
+ private readonly onDialogKeydown;
107
+ private runSearch;
108
+ private focusInput;
109
+ private setActiveIndex;
110
+ private syncInputAria;
111
+ private syncActiveResult;
112
+ private selectResult;
113
+ private bindResultEvents;
114
+ private renderResultsContainer;
115
+ private renderResults;
116
+ private render;
117
+ private bindEvents;
119
118
  }
120
119
  declare function defineMdSearchElement(name?: string): void;
121
120
  declare function createSearch(options: CreateSearchOptions): MdSearchElement;
122
-
123
121
  declare function searchRecords(records: SearchRecord[], query: string, options?: SearchOptions): SearchResult[];
124
122
  declare function createStaticSearchProvider(records: SearchRecord[]): SearchProvider;
125
123
  declare function createJsonSearchProvider(options?: JsonSearchProviderOptions): SearchProvider;
126
-
127
124
  declare function normalizeSearchQuery(value: string): string;
128
125
  declare function createSearchTerms(query: string): string[];
129
126
  declare function normalizeSearchableText(value: unknown): string;
130
127
  declare function createSearchSnippet(content: string, terms: string[], length?: number): string;
131
-
132
- export { MdSearchElement, createJsonSearchProvider, createSearch, createSearchSnippet, createSearchTerms, createStaticSearchProvider, defineMdSearchElement, normalizeSearchQuery, normalizeSearchableText, searchRecords };
133
- export type { CreateSearchOptions, JsonSearchProviderOptions, MaybePromise, MdSearchSelectEventDetail, SearchIndex, SearchOptions, SearchProvider, SearchRecord, SearchRecordSource, SearchRecordType, SearchResult };
128
+ export { type CreateSearchOptions, type JsonSearchProviderOptions, type MaybePromise, MdSearchElement, type MdSearchSelectEventDetail, type SearchIndex, type SearchOptions, type SearchProvider, type SearchRecord, type SearchRecordSource, type SearchRecordType, type SearchResult, createJsonSearchProvider, createSearch, createSearchSnippet, createSearchTerms, createStaticSearchProvider, defineMdSearchElement, normalizeSearchQuery, normalizeSearchableText, searchRecords };