@vuepress-plume/plugin-search 1.0.0-rc.208 → 1.0.0-rc.210
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/composables/index.d.ts +12 -12
- package/dist/client/composables/index.js +40 -62
- package/dist/client/config.js +19 -15
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +4 -17
- package/dist/client/utils/index.d.ts +8 -11
- package/dist/client/utils/index.js +34 -104
- package/dist/node/index.d.ts +16 -13
- package/dist/node/index.js +323 -429
- package/dist/shared/index.d.ts +25 -28
- package/dist/shared/index.js +1 -1
- package/package.json +4 -3
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/client/composables/locale.d.ts
|
|
1
|
+
import {ComputedRef, MaybeRef, ShallowRef} from 'vue'
|
|
2
|
+
import {SearchBoxLocales, SearchLocaleOptions} from '../../shared/index.js'
|
|
4
3
|
/**
|
|
5
4
|
* Get locale configuration for the current route.
|
|
6
5
|
*
|
|
@@ -12,9 +11,9 @@ import { SearchBoxLocales, SearchLocaleOptions } from "../../shared/index.js";
|
|
|
12
11
|
* const locale = useLocale(locales)
|
|
13
12
|
* console.log(locale.value.placeholder) // 'Search' or localized value
|
|
14
13
|
*/
|
|
15
|
-
declare function useLocale(
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
export declare function useLocale(
|
|
15
|
+
locales: MaybeRef<SearchBoxLocales>,
|
|
16
|
+
): ComputedRef<Partial<SearchLocaleOptions>>
|
|
18
17
|
/**
|
|
19
18
|
* Type definition for search index data.
|
|
20
19
|
*
|
|
@@ -24,9 +23,12 @@ declare function useLocale(locales: MaybeRef<SearchBoxLocales>): ComputedRef<Par
|
|
|
24
23
|
*
|
|
25
24
|
* 将语言路径映射到加载相应搜索索引的函数。
|
|
26
25
|
*/
|
|
27
|
-
type SearchIndexData = Record<
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
type SearchIndexData = Record<
|
|
27
|
+
string,
|
|
28
|
+
() => Promise<{
|
|
29
|
+
default: string
|
|
30
|
+
}>
|
|
31
|
+
>
|
|
30
32
|
/**
|
|
31
33
|
* Get the search index data for all locales.
|
|
32
34
|
*
|
|
@@ -37,6 +39,4 @@ type SearchIndexData = Record<string, () => Promise<{
|
|
|
37
39
|
* const indexData = useSearchIndex()
|
|
38
40
|
* const localeIndex = await indexData.value['/zh/']()
|
|
39
41
|
*/
|
|
40
|
-
declare function useSearchIndex(): ShallowRef<SearchIndexData
|
|
41
|
-
//#endregion
|
|
42
|
-
export { useLocale, useSearchIndex };
|
|
42
|
+
export declare function useSearchIndex(): ShallowRef<SearchIndexData>
|
|
@@ -1,66 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
} };
|
|
25
|
-
/**
|
|
26
|
-
* Get locale configuration for the current route.
|
|
27
|
-
*
|
|
28
|
-
* 获取当前路由的语言配置。
|
|
29
|
-
*
|
|
30
|
-
* @param locales - Locale configuration object / 语言配置对象
|
|
31
|
-
* @returns Computed ref to the current locale settings / 当前语言设置的计算引用
|
|
32
|
-
* @example
|
|
33
|
-
* const locale = useLocale(locales)
|
|
34
|
-
* console.log(locale.value.placeholder) // 'Search' or localized value
|
|
35
|
-
*/
|
|
1
|
+
import {computed, shallowRef, toRef} from 'vue'
|
|
2
|
+
import {useRouteLocale} from 'vuepress/client'
|
|
3
|
+
import {searchIndex} from '@internal/minisearchIndex'
|
|
4
|
+
|
|
5
|
+
const defaultLocales = {
|
|
6
|
+
'/': {
|
|
7
|
+
placeholder: 'Search',
|
|
8
|
+
resetButtonTitle: 'Reset search',
|
|
9
|
+
backButtonTitle: 'Close search',
|
|
10
|
+
noResultsText: 'No results for',
|
|
11
|
+
footer: {
|
|
12
|
+
selectText: 'to select',
|
|
13
|
+
selectKeyAriaLabel: 'enter',
|
|
14
|
+
navigateText: 'to navigate',
|
|
15
|
+
navigateUpKeyAriaLabel: 'up arrow',
|
|
16
|
+
navigateDownKeyAriaLabel: 'down arrow',
|
|
17
|
+
closeText: 'to close',
|
|
18
|
+
closeKeyAriaLabel: 'escape',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
|
|
36
23
|
function useLocale(locales) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
const localesRef = toRef(locales)
|
|
25
|
+
const routeLocale = useRouteLocale()
|
|
26
|
+
return computed(
|
|
27
|
+
() =>
|
|
28
|
+
localesRef.value[routeLocale.value] ??
|
|
29
|
+
defaultLocales[routeLocale.value] ??
|
|
30
|
+
defaultLocales['/'],
|
|
31
|
+
)
|
|
40
32
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* Reactive reference to the search index data.
|
|
45
|
-
*
|
|
46
|
-
* 搜索索引数据的响应式引用。
|
|
47
|
-
*/
|
|
48
|
-
const searchIndexData = shallowRef(searchIndex);
|
|
49
|
-
/**
|
|
50
|
-
* Get the search index data for all locales.
|
|
51
|
-
*
|
|
52
|
-
* 获取所有语言的搜索索引数据。
|
|
53
|
-
*
|
|
54
|
-
* @returns Shallow ref to the search index data / 搜索索引数据的浅层引用
|
|
55
|
-
* @example
|
|
56
|
-
* const indexData = useSearchIndex()
|
|
57
|
-
* const localeIndex = await indexData.value['/zh/']()
|
|
58
|
-
*/
|
|
33
|
+
|
|
34
|
+
const searchIndexData = shallowRef(searchIndex)
|
|
35
|
+
|
|
59
36
|
function useSearchIndex() {
|
|
60
|
-
|
|
37
|
+
return searchIndexData
|
|
61
38
|
}
|
|
62
|
-
if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot))
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
39
|
+
if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot))
|
|
40
|
+
__VUE_HMR_RUNTIME__.updateSearchIndex = (data) => {
|
|
41
|
+
searchIndexData.value = data
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {useLocale, useSearchIndex}
|
package/dist/client/config.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import Search from
|
|
4
|
-
|
|
5
|
-
const locales = __SEARCH_LOCALES__
|
|
6
|
-
const searchOptions = __SEARCH_OPTIONS__
|
|
7
|
-
var config_default = defineClientConfig({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import {h} from 'vue'
|
|
2
|
+
import {defineClientConfig} from 'vuepress/client'
|
|
3
|
+
import Search from './components/Search.vue'
|
|
4
|
+
|
|
5
|
+
const locales = __SEARCH_LOCALES__
|
|
6
|
+
const searchOptions = __SEARCH_OPTIONS__
|
|
7
|
+
var config_default = defineClientConfig({
|
|
8
|
+
enhance({app}) {
|
|
9
|
+
app.component('SearchBox', (props) =>
|
|
10
|
+
h(Search, {
|
|
11
|
+
locales,
|
|
12
|
+
options: searchOptions,
|
|
13
|
+
...props,
|
|
14
|
+
}),
|
|
15
|
+
)
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export {config_default as default}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import SearchBox from
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
1
|
+
import SearchBox from './components/Search.vue'
|
|
2
|
+
import {useSearchIndex} from './composables/index.js'
|
|
3
|
+
export {SearchBox, useSearchIndex}
|
package/dist/client/index.js
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import SearchBox from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* VuePress Search Plugin - Client Side Entry
|
|
6
|
-
*
|
|
7
|
-
* VuePress 搜索插件 - 客户端入口
|
|
8
|
-
*
|
|
9
|
-
* Exports the SearchBox component and search index composable for use in
|
|
10
|
-
* VuePress theme components.
|
|
11
|
-
*
|
|
12
|
-
* 导出 SearchBox 组件和搜索索引组合式函数,供 VuePress 主题组件使用。
|
|
13
|
-
*
|
|
14
|
-
* @module plugin-search/client
|
|
15
|
-
*/
|
|
16
|
-
//#endregion
|
|
17
|
-
export { SearchBox, useSearchIndex };
|
|
1
|
+
import SearchBox from './components/Search.vue'
|
|
2
|
+
import {useSearchIndex} from './composables/index.js'
|
|
3
|
+
|
|
4
|
+
export {SearchBox, useSearchIndex}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/client/utils/lru.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* LRU (Least Recently Used) Cache Implementation
|
|
4
3
|
*
|
|
@@ -28,11 +27,11 @@
|
|
|
28
27
|
* cache.set('d', 4) // 'a' is evicted
|
|
29
28
|
* cache.get('b') // returns 2, 'b' becomes most recent
|
|
30
29
|
*/
|
|
31
|
-
declare class LRUCache<K, V> {
|
|
30
|
+
export declare class LRUCache<K, V> {
|
|
32
31
|
/** Maximum number of items in the cache / 缓存中的最大项数 */
|
|
33
|
-
private max
|
|
32
|
+
private max
|
|
34
33
|
/** Internal Map storage / 内部 Map 存储 */
|
|
35
|
-
private cache
|
|
34
|
+
private cache
|
|
36
35
|
/**
|
|
37
36
|
* Create a new LRU Cache instance.
|
|
38
37
|
*
|
|
@@ -40,7 +39,7 @@ declare class LRUCache<K, V> {
|
|
|
40
39
|
*
|
|
41
40
|
* @param max - Maximum cache size (default: 10) / 最大缓存大小(默认:10)
|
|
42
41
|
*/
|
|
43
|
-
constructor(max?: number)
|
|
42
|
+
constructor(max?: number)
|
|
44
43
|
/**
|
|
45
44
|
* Get a value from the cache.
|
|
46
45
|
*
|
|
@@ -53,7 +52,7 @@ declare class LRUCache<K, V> {
|
|
|
53
52
|
* @param key - Cache key / 缓存键
|
|
54
53
|
* @returns Cached value or undefined if not found / 缓存值,未找到则返回 undefined
|
|
55
54
|
*/
|
|
56
|
-
get(key: K): V | undefined
|
|
55
|
+
get(key: K): V | undefined
|
|
57
56
|
/**
|
|
58
57
|
* Set a value in the cache.
|
|
59
58
|
*
|
|
@@ -67,7 +66,7 @@ declare class LRUCache<K, V> {
|
|
|
67
66
|
* @param key - Cache key / 缓存键
|
|
68
67
|
* @param val - Value to cache / 要缓存的值
|
|
69
68
|
*/
|
|
70
|
-
set(key: K, val: V): void
|
|
69
|
+
set(key: K, val: V): void
|
|
71
70
|
/**
|
|
72
71
|
* Get the first (oldest) key in the cache.
|
|
73
72
|
*
|
|
@@ -75,13 +74,11 @@ declare class LRUCache<K, V> {
|
|
|
75
74
|
*
|
|
76
75
|
* @returns The oldest key or undefined if cache is empty / 最旧的键,缓存为空则返回 undefined
|
|
77
76
|
*/
|
|
78
|
-
first(): K | undefined
|
|
77
|
+
first(): K | undefined
|
|
79
78
|
/**
|
|
80
79
|
* Clear all items from the cache.
|
|
81
80
|
*
|
|
82
81
|
* 清空缓存中的所有项。
|
|
83
82
|
*/
|
|
84
|
-
clear(): void
|
|
83
|
+
clear(): void
|
|
85
84
|
}
|
|
86
|
-
//#endregion
|
|
87
|
-
export { LRUCache };
|
|
@@ -1,105 +1,35 @@
|
|
|
1
|
-
//#region src/client/utils/lru.ts
|
|
2
|
-
/**
|
|
3
|
-
* LRU (Least Recently Used) Cache Implementation
|
|
4
|
-
*
|
|
5
|
-
* LRU(最近最少使用)缓存实现
|
|
6
|
-
*
|
|
7
|
-
* Adapted from https://stackoverflow.com/a/46432113/11613622
|
|
8
|
-
*
|
|
9
|
-
* @module plugin-search/client/utils/lru
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Generic LRU Cache implementation using Map.
|
|
13
|
-
*
|
|
14
|
-
* 使用 Map 实现的通用 LRU 缓存。
|
|
15
|
-
*
|
|
16
|
-
* Automatically evicts the least recently used item when the cache reaches
|
|
17
|
-
* its maximum size.
|
|
18
|
-
*
|
|
19
|
-
* 当缓存达到最大容量时,自动淘汰最近最少使用的项。
|
|
20
|
-
*
|
|
21
|
-
* @template K - Key type / 键类型
|
|
22
|
-
* @template V - Value type / 值类型
|
|
23
|
-
* @example
|
|
24
|
-
* const cache = new LRUCache<string, number>(3)
|
|
25
|
-
* cache.set('a', 1)
|
|
26
|
-
* cache.set('b', 2)
|
|
27
|
-
* cache.set('c', 3)
|
|
28
|
-
* cache.set('d', 4) // 'a' is evicted
|
|
29
|
-
* cache.get('b') // returns 2, 'b' becomes most recent
|
|
30
|
-
*/
|
|
31
1
|
var LRUCache = class {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Set a value in the cache.
|
|
69
|
-
*
|
|
70
|
-
* 在缓存中设置值。
|
|
71
|
-
*
|
|
72
|
-
* If the key already exists, it is moved to the end. If the cache is full,
|
|
73
|
-
* the oldest item is evicted.
|
|
74
|
-
*
|
|
75
|
-
* 如果键已存在,则将其移动到末尾。如果缓存已满,则淘汰最旧的项。
|
|
76
|
-
*
|
|
77
|
-
* @param key - Cache key / 缓存键
|
|
78
|
-
* @param val - Value to cache / 要缓存的值
|
|
79
|
-
*/
|
|
80
|
-
set(key, val) {
|
|
81
|
-
if (this.cache.has(key)) this.cache.delete(key);
|
|
82
|
-
else if (this.cache.size === this.max) this.cache.delete(this.first());
|
|
83
|
-
this.cache.set(key, val);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Get the first (oldest) key in the cache.
|
|
87
|
-
*
|
|
88
|
-
* 获取缓存中的第一个(最旧的)键。
|
|
89
|
-
*
|
|
90
|
-
* @returns The oldest key or undefined if cache is empty / 最旧的键,缓存为空则返回 undefined
|
|
91
|
-
*/
|
|
92
|
-
first() {
|
|
93
|
-
return this.cache.keys().next().value;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Clear all items from the cache.
|
|
97
|
-
*
|
|
98
|
-
* 清空缓存中的所有项。
|
|
99
|
-
*/
|
|
100
|
-
clear() {
|
|
101
|
-
this.cache.clear();
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
//#endregion
|
|
105
|
-
export { LRUCache };
|
|
2
|
+
max
|
|
3
|
+
|
|
4
|
+
cache
|
|
5
|
+
|
|
6
|
+
constructor(max = 10) {
|
|
7
|
+
this.max = max
|
|
8
|
+
this.cache = new Map()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get(key) {
|
|
12
|
+
const item = this.cache.get(key)
|
|
13
|
+
if (item !== void 0) {
|
|
14
|
+
this.cache.delete(key)
|
|
15
|
+
this.cache.set(key, item)
|
|
16
|
+
}
|
|
17
|
+
return item
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
set(key, val) {
|
|
21
|
+
if (this.cache.has(key)) this.cache.delete(key)
|
|
22
|
+
else if (this.cache.size === this.max) this.cache.delete(this.first())
|
|
23
|
+
this.cache.set(key, val)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
first() {
|
|
27
|
+
return this.cache.keys().next().value
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
clear() {
|
|
31
|
+
this.cache.clear()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {LRUCache}
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export * from
|
|
4
|
-
//#region src/node/prepareSearchIndex.d.ts
|
|
1
|
+
import {SearchOptions, SearchPluginOptions} from '../shared/index.js'
|
|
2
|
+
import {App, Plugin} from 'vuepress/core'
|
|
3
|
+
export * from '../shared/index.js'
|
|
5
4
|
/**
|
|
6
5
|
* Options for search index preparation.
|
|
7
6
|
*
|
|
@@ -9,11 +8,11 @@ export * from "../shared/index.js";
|
|
|
9
8
|
*/
|
|
10
9
|
interface SearchIndexOptions {
|
|
11
10
|
/** VuePress application instance / VuePress 应用实例 */
|
|
12
|
-
app: App
|
|
11
|
+
app: App
|
|
13
12
|
/** MiniSearch configuration options / MiniSearch 配置选项 */
|
|
14
|
-
searchOptions: SearchOptions
|
|
13
|
+
searchOptions: SearchOptions
|
|
15
14
|
/** Function to filter searchable pages / 过滤可搜索页面的函数 */
|
|
16
|
-
isSearchable: SearchPluginOptions['isSearchable']
|
|
15
|
+
isSearchable: SearchPluginOptions['isSearchable']
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
19
18
|
* Prepare search indexes for all pages in the VuePress application.
|
|
@@ -31,9 +30,11 @@ interface SearchIndexOptions {
|
|
|
31
30
|
* @param options.isSearchable - Function to filter searchable pages / 过滤可搜索页面的函数
|
|
32
31
|
* @param options.searchOptions - MiniSearch configuration / MiniSearch 配置
|
|
33
32
|
*/
|
|
34
|
-
declare function prepareSearchIndex({
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
export declare function prepareSearchIndex({
|
|
34
|
+
app,
|
|
35
|
+
isSearchable,
|
|
36
|
+
searchOptions,
|
|
37
|
+
}: SearchIndexOptions): Promise<void>
|
|
37
38
|
/**
|
|
38
39
|
* Create a VuePress search plugin instance.
|
|
39
40
|
*
|
|
@@ -64,6 +65,8 @@ declare function prepareSearchIndex({ app, isSearchable, searchOptions }: Search
|
|
|
64
65
|
* ]
|
|
65
66
|
* }
|
|
66
67
|
*/
|
|
67
|
-
declare function searchPlugin({
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
export declare function searchPlugin({
|
|
69
|
+
locales,
|
|
70
|
+
isSearchable,
|
|
71
|
+
...searchOptions
|
|
72
|
+
}?: SearchPluginOptions): Plugin
|