dsh-plugin-explorer 0.0.0-stage → 0.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.
- package/LICENSE +26 -0
- package/README.md +57 -2
- package/client.js +414 -0
- package/cordis.patch.yml +4 -0
- package/data/plugins.json +1 -0
- package/icon.svg +7 -0
- package/index.js +80 -0
- package/lib/catalog.js +71 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +50 -4
- package/scripts/build-data.mjs +17 -0
- package/scripts/verify.mjs +102 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-plugin-explorer contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
The bundled catalog data in data/plugins.json derives from dsh-plugin-catalog
|
|
26
|
+
(https://www.npmjs.com/package/dsh-plugin-catalog), published under CC0 1.0.
|
package/README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-plugin-explorer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Search the community plugin catalog from the DSH Plugins page and install a matching bundle in
|
|
4
|
+
one click.
|
|
5
|
+
|
|
6
|
+
The plugin adds a **Search** tab next to **Installed**. Typing a name, an author, a category, or a
|
|
7
|
+
keyword filters a bundled directory of installable community bundles; **Install** opens the normal
|
|
8
|
+
DSH install confirmation for that exact `name@version`, so compatibility checks and the source
|
|
9
|
+
review stay in the standard flow.
|
|
10
|
+
|
|
11
|
+
## Use it
|
|
12
|
+
|
|
13
|
+
1. Open **Plugins** in the sidebar.
|
|
14
|
+
2. Select the **Search** tab.
|
|
15
|
+
3. Type a keyword such as `pet`, `memory`, or `theme`, then select **Install** on a result.
|
|
16
|
+
|
|
17
|
+
The catalog ships with the package, so searching works offline. **Refresh catalog** re-reads the
|
|
18
|
+
upstream community index (`dsh-plugin-catalog` on jsDelivr) for the rest of the session.
|
|
19
|
+
|
|
20
|
+
## Data
|
|
21
|
+
|
|
22
|
+
- Bundled directory: 7,400+ community entries that publish an exact npm version, generated from
|
|
23
|
+
[dsh-plugin-catalog](https://www.npmjs.com/package/dsh-plugin-catalog) (CC0 1.0).
|
|
24
|
+
- Each entry carries its package name, version, owner, category, localized description, download
|
|
25
|
+
and star counts, and an icon URL when the index provides one.
|
|
26
|
+
- Regenerate `data/plugins.json` after the upstream index changes:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
node scripts/build-data.mjs <catalog-plugins.json>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Download `plugins.json` from the upstream package (for example
|
|
33
|
+
`https://cdn.jsdelivr.net/npm/dsh-plugin-catalog@latest/plugins.json`) and pass its path.
|
|
34
|
+
|
|
35
|
+
## Limitations
|
|
36
|
+
|
|
37
|
+
- Only npm installs are listed: the Plugins page install dialog takes an exact `name@version`, and
|
|
38
|
+
the upstream catalog's Git-only entries have no pinned commit to install from here.
|
|
39
|
+
- The catalog is third-party content. DSH validates the list format, not the listed projects, and
|
|
40
|
+
the install confirmation shows the source before anything is installed.
|
|
41
|
+
- A bundled version can lag behind npm; the install check reports a missing or newer version.
|
|
42
|
+
- **Refresh catalog** keeps the new copy in this Host session only; restarting DSH returns to the
|
|
43
|
+
bundled snapshot until the package is updated and republished.
|
|
44
|
+
- Icons are loaded from their original hosts; an unavailable icon falls back to a letter tile.
|
|
45
|
+
|
|
46
|
+
## Development
|
|
47
|
+
|
|
48
|
+
- `client.js` is a prebuilt Web module in the deployment's module-loader format; it uses only the
|
|
49
|
+
browser's `react` module.
|
|
50
|
+
- `index.js` serves `data/plugins.json` on `GET /api/plugin-finder/catalog.json`, and refreshes it
|
|
51
|
+
on `?refresh=1`.
|
|
52
|
+
- `lib/catalog.js` normalizes both the bundled snapshot and a refreshed upstream document.
|
|
53
|
+
- `node scripts/verify.mjs` checks the route, the bundled directory, and the search pipeline; add
|
|
54
|
+
`--refresh` to exercise the live upstream read.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
Code: MIT. Bundled catalog data: CC0 1.0 (from `dsh-plugin-catalog`).
|
package/client.js
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-plugin-explorer',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react')
|
|
5
|
+
const h = React.createElement
|
|
6
|
+
const { useEffect, useMemo, useState } = React
|
|
7
|
+
|
|
8
|
+
/** Locale namespace owned by this plugin. */
|
|
9
|
+
const NS = 'pluginFinder'
|
|
10
|
+
/** Results shown per page. */
|
|
11
|
+
const PAGE_SIZE = 30
|
|
12
|
+
/** Exact Fetch route the Host half serves. */
|
|
13
|
+
const CATALOG_PATH = 'api/plugin-finder/catalog.json'
|
|
14
|
+
|
|
15
|
+
const zh = {
|
|
16
|
+
title: '搜索',
|
|
17
|
+
placeholder: '输入插件名称、作者或关键词',
|
|
18
|
+
clear: '清空',
|
|
19
|
+
count: '找到 {count} 个插件',
|
|
20
|
+
loading: '正在读取插件目录…',
|
|
21
|
+
failed: '插件目录读取失败',
|
|
22
|
+
retry: '重试',
|
|
23
|
+
refresh: '刷新目录',
|
|
24
|
+
refreshing: '刷新中…',
|
|
25
|
+
refreshFailed: '刷新失败,当前仍显示已载入的目录',
|
|
26
|
+
empty: '没有匹配的插件',
|
|
27
|
+
install: '安装',
|
|
28
|
+
more: '加载更多',
|
|
29
|
+
note: '目录来自第三方社区索引(CC0),DSH 只校验格式、不验证内容;安装前请核对确认框中的来源。',
|
|
30
|
+
downloads: '{count} 次下载',
|
|
31
|
+
stars: '{count} 个 GitHub star',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const en = {
|
|
35
|
+
title: 'Search',
|
|
36
|
+
placeholder: 'Search by plugin name, author, or keyword',
|
|
37
|
+
clear: 'Clear',
|
|
38
|
+
count: 'Found {count} plugins',
|
|
39
|
+
loading: 'Loading the plugin catalog…',
|
|
40
|
+
failed: 'Could not read the plugin catalog',
|
|
41
|
+
retry: 'Retry',
|
|
42
|
+
refresh: 'Refresh catalog',
|
|
43
|
+
refreshing: 'Refreshing…',
|
|
44
|
+
refreshFailed: 'Refresh failed; still showing the catalog already loaded',
|
|
45
|
+
empty: 'No matching plugins',
|
|
46
|
+
install: 'Install',
|
|
47
|
+
more: 'Show more',
|
|
48
|
+
note: 'The catalog is a third-party community index (CC0). DSH checks its format, not its content; verify the source in the confirmation dialog before installing.',
|
|
49
|
+
downloads: '{count} downloads',
|
|
50
|
+
stars: '{count} GitHub stars',
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const CATEGORIES = {
|
|
54
|
+
agi: ['智能体', 'Agent'],
|
|
55
|
+
ui: ['界面', 'UI'],
|
|
56
|
+
usage: ['体验', 'Experience'],
|
|
57
|
+
theme: ['主题', 'Theme'],
|
|
58
|
+
model: ['模型', 'Model'],
|
|
59
|
+
identity: ['身份', 'Identity'],
|
|
60
|
+
session: ['会话', 'Session'],
|
|
61
|
+
memory: ['记忆', 'Memory'],
|
|
62
|
+
tools: ['工具', 'Tools'],
|
|
63
|
+
wsl: ['WSL', 'WSL'],
|
|
64
|
+
browser: ['浏览器', 'Browser'],
|
|
65
|
+
vision: ['视觉', 'Vision'],
|
|
66
|
+
voice: ['语音', 'Voice'],
|
|
67
|
+
docs: ['文档', 'Docs'],
|
|
68
|
+
skill: ['技能', 'Skill'],
|
|
69
|
+
workflow: ['工作流', 'Workflow'],
|
|
70
|
+
git: ['Git', 'Git'],
|
|
71
|
+
notify: ['通知', 'Notifications'],
|
|
72
|
+
dev: ['开发', 'Developer'],
|
|
73
|
+
security: ['安全', 'Security'],
|
|
74
|
+
remote: ['远程', 'Remote'],
|
|
75
|
+
market: ['市场', 'Market'],
|
|
76
|
+
fun: ['趣味', 'Fun'],
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const CSS = `
|
|
80
|
+
.pf-root { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
|
|
81
|
+
.pf-toolbar { display: flex; align-items: center; gap: 8px; }
|
|
82
|
+
.pf-search { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; }
|
|
83
|
+
.pf-search-icon { position: absolute; left: 11px; color: var(--dsw-alias-label-secondary); pointer-events: none; }
|
|
84
|
+
.pf-input {
|
|
85
|
+
width: 100%; height: 36px; box-sizing: border-box; padding: 0 34px 0 33px;
|
|
86
|
+
border: 1px solid var(--dsw-alias-border-l1); border-radius: 9px;
|
|
87
|
+
background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary);
|
|
88
|
+
font: inherit; font-size: 13px; outline: none;
|
|
89
|
+
}
|
|
90
|
+
.pf-input::placeholder { color: var(--dsw-alias-label-secondary); }
|
|
91
|
+
.pf-input:focus { border-color: var(--dsw-alias-brand-primary); }
|
|
92
|
+
.pf-clear {
|
|
93
|
+
position: absolute; right: 6px; width: 24px; height: 24px; border: 0; border-radius: 6px;
|
|
94
|
+
background: transparent; color: var(--dsw-alias-label-secondary); font-size: 16px; line-height: 1;
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
}
|
|
97
|
+
.pf-clear:hover { background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-primary); }
|
|
98
|
+
.pf-refresh {
|
|
99
|
+
flex: none; height: 36px; padding: 0 13px; border-radius: 9px;
|
|
100
|
+
border: 1px solid var(--dsw-alias-border-l1); background: transparent;
|
|
101
|
+
color: var(--dsw-alias-label-secondary); font: inherit; font-size: 12px; cursor: pointer;
|
|
102
|
+
}
|
|
103
|
+
.pf-refresh:hover:not(:disabled) { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
|
|
104
|
+
.pf-refresh:disabled { opacity: 0.6; cursor: default; }
|
|
105
|
+
.pf-summary { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--dsw-alias-label-secondary); }
|
|
106
|
+
.pf-warn { color: var(--dsw-alias-state-warn-primary); }
|
|
107
|
+
.pf-state {
|
|
108
|
+
display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 120px;
|
|
109
|
+
border: 1px dashed var(--dsw-alias-border-l1); border-radius: 12px; padding: 24px;
|
|
110
|
+
font-size: 13px; color: var(--dsw-alias-label-secondary);
|
|
111
|
+
}
|
|
112
|
+
.pf-link { border: 0; background: transparent; color: var(--dsw-alias-brand-primary); font: inherit; font-size: 13px; cursor: pointer; padding: 0; }
|
|
113
|
+
.pf-list { display: flex; flex-direction: column; border: 1px solid var(--dsw-alias-border-l1); border-radius: 12px; overflow: hidden; background: var(--dsw-alias-bg-layer-1); }
|
|
114
|
+
.pf-row { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--dsw-alias-border-l1); }
|
|
115
|
+
.pf-row:first-child { border-top: 0; }
|
|
116
|
+
.pf-row:hover { background: var(--dsw-alias-bg-layer-2); }
|
|
117
|
+
.pf-avatar {
|
|
118
|
+
flex: none; width: 40px; height: 40px; border-radius: 10px; overflow: hidden;
|
|
119
|
+
display: flex; align-items: center; justify-content: center;
|
|
120
|
+
background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-secondary);
|
|
121
|
+
font-size: 16px; font-weight: 600;
|
|
122
|
+
}
|
|
123
|
+
.pf-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
|
124
|
+
.pf-main { flex: 1; min-width: 0; }
|
|
125
|
+
.pf-title-line { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
|
|
126
|
+
.pf-name { font-size: 13px; font-weight: 600; color: var(--dsw-alias-label-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
127
|
+
.pf-version { flex: none; font-size: 11px; color: var(--dsw-alias-label-secondary); }
|
|
128
|
+
.pf-meta { margin-top: 3px; font-size: 11px; color: var(--dsw-alias-label-secondary); }
|
|
129
|
+
.pf-desc {
|
|
130
|
+
margin: 6px 0 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary);
|
|
131
|
+
display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
|
|
132
|
+
}
|
|
133
|
+
.pf-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; padding-left: 4px; }
|
|
134
|
+
.pf-stat { font-size: 11px; color: var(--dsw-alias-label-secondary); white-space: nowrap; }
|
|
135
|
+
.pf-install {
|
|
136
|
+
border: 0; border-radius: 8px; padding: 6px 14px; background: var(--dsw-alias-brand-primary);
|
|
137
|
+
color: #ffffff; font: inherit; font-size: 12px; cursor: pointer;
|
|
138
|
+
}
|
|
139
|
+
.pf-install:hover { filter: brightness(1.08); }
|
|
140
|
+
.pf-more {
|
|
141
|
+
align-self: center; margin-top: 2px; padding: 7px 16px; border-radius: 9px;
|
|
142
|
+
border: 1px solid var(--dsw-alias-border-l1); background: transparent;
|
|
143
|
+
color: var(--dsw-alias-label-secondary); font: inherit; font-size: 12px; cursor: pointer;
|
|
144
|
+
}
|
|
145
|
+
.pf-more:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
|
|
146
|
+
.pf-note { font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-secondary); }
|
|
147
|
+
.pf-root :focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
|
|
148
|
+
@media (max-width: 640px) {
|
|
149
|
+
.pf-side { flex-direction: row; align-items: center; }
|
|
150
|
+
.pf-stat { display: none; }
|
|
151
|
+
}
|
|
152
|
+
`
|
|
153
|
+
|
|
154
|
+
function catalogUrl(refresh) {
|
|
155
|
+
return new URL(CATALOG_PATH + (refresh ? '?refresh=1' : ''), document.baseURI)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function readCatalog(refresh) {
|
|
159
|
+
const response = await fetch(catalogUrl(refresh), { credentials: 'same-origin', cache: 'no-store' })
|
|
160
|
+
if (!response.ok) {
|
|
161
|
+
let detail = ''
|
|
162
|
+
try {
|
|
163
|
+
const body = await response.json()
|
|
164
|
+
if (body && typeof body.error === 'string') detail = body.error
|
|
165
|
+
} catch {
|
|
166
|
+
detail = ''
|
|
167
|
+
}
|
|
168
|
+
throw new Error(detail === '' ? `HTTP ${response.status}` : detail)
|
|
169
|
+
}
|
|
170
|
+
const data = await response.json()
|
|
171
|
+
if (data === null || typeof data !== 'object' || !Array.isArray(data.plugins)) {
|
|
172
|
+
throw new Error('invalid catalog document')
|
|
173
|
+
}
|
|
174
|
+
return data
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Lowercased description for the active document language. */
|
|
178
|
+
function currentLanguage() {
|
|
179
|
+
const declared = document.documentElement && document.documentElement.lang
|
|
180
|
+
const tag = (declared || (typeof navigator === 'object' ? navigator.language : '') || 'en').toLowerCase()
|
|
181
|
+
return tag.startsWith('zh') ? 'zh' : 'en'
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function categoryLabel(id, language) {
|
|
185
|
+
const entry = id === undefined ? undefined : CATEGORIES[id]
|
|
186
|
+
if (entry === undefined) return id
|
|
187
|
+
return entry[language === 'zh' ? 0 : 1]
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function initialOf(name) {
|
|
191
|
+
const bare = name.replace(/^@[^/]+\//, '')
|
|
192
|
+
return (bare.charAt(0) || '?').toUpperCase()
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function prepare(plugins) {
|
|
196
|
+
const entries = []
|
|
197
|
+
for (const item of plugins) {
|
|
198
|
+
if (item === null || typeof item !== 'object') continue
|
|
199
|
+
if (typeof item.name !== 'string' || typeof item.version !== 'string') continue
|
|
200
|
+
const description = item.description !== null && typeof item.description === 'object'
|
|
201
|
+
? { zh: item.description.zh, en: item.description.en }
|
|
202
|
+
: typeof item.description === 'string' ? { en: item.description } : undefined
|
|
203
|
+
const nameLower = item.name.toLowerCase()
|
|
204
|
+
const ownerLower = typeof item.owner === 'string' ? item.owner.toLowerCase() : ''
|
|
205
|
+
const categoryLower = typeof item.category === 'string' ? item.category.toLowerCase() : ''
|
|
206
|
+
entries.push({
|
|
207
|
+
name: item.name,
|
|
208
|
+
version: item.version,
|
|
209
|
+
owner: item.owner,
|
|
210
|
+
category: item.category,
|
|
211
|
+
icon: typeof item.icon === 'string' ? item.icon : undefined,
|
|
212
|
+
description,
|
|
213
|
+
nameLower,
|
|
214
|
+
ownerLower,
|
|
215
|
+
categoryLower,
|
|
216
|
+
haystack: [nameLower, ownerLower, categoryLower, description?.zh, description?.en].filter(Boolean).join('\n').toLowerCase(),
|
|
217
|
+
downloads: Number.isFinite(item.downloads) ? item.downloads : 0,
|
|
218
|
+
stars: Number.isFinite(item.stars) ? item.stars : 0,
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
return entries
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const CJK = /[\u3040-\u30ff\u3400-\u9fff\uac00-\ud7af]/
|
|
225
|
+
|
|
226
|
+
function tokenize(text) {
|
|
227
|
+
const tokens = new Set()
|
|
228
|
+
for (const part of text.trim().toLowerCase().split(/[\s,;|/]+/)) {
|
|
229
|
+
if (part === '') continue
|
|
230
|
+
if (CJK.test(part)) {
|
|
231
|
+
const characters = [...part]
|
|
232
|
+
if (characters.length === 1) tokens.add(part)
|
|
233
|
+
for (let index = 0; index < characters.length - 1; index += 1) {
|
|
234
|
+
tokens.add(characters[index] + characters[index + 1])
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
tokens.add(part)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return [...tokens]
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function scoreEntry(entry, tokens) {
|
|
244
|
+
let score = 0
|
|
245
|
+
for (const token of tokens) {
|
|
246
|
+
if (entry.haystack.indexOf(token) < 0) return 0
|
|
247
|
+
if (entry.nameLower === token) score += 120
|
|
248
|
+
else if (entry.nameLower.startsWith(token)) score += 70
|
|
249
|
+
else if (entry.nameLower.indexOf(token) >= 0) score += 45
|
|
250
|
+
else if (entry.ownerLower.indexOf(token) >= 0 || entry.categoryLower.indexOf(token) >= 0) score += 20
|
|
251
|
+
else score += 8
|
|
252
|
+
}
|
|
253
|
+
return score
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function searchEntries(entries, tokens) {
|
|
257
|
+
if (tokens.length === 0) return entries
|
|
258
|
+
const matched = []
|
|
259
|
+
for (const entry of entries) {
|
|
260
|
+
const score = scoreEntry(entry, tokens)
|
|
261
|
+
if (score > 0) matched.push({ entry, score })
|
|
262
|
+
}
|
|
263
|
+
matched.sort((left, right) => (
|
|
264
|
+
right.score - left.score
|
|
265
|
+
|| right.entry.downloads - left.entry.downloads
|
|
266
|
+
|| left.entry.name.localeCompare(right.entry.name)
|
|
267
|
+
))
|
|
268
|
+
return matched.map(match => match.entry)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const compact = new Intl.NumberFormat(undefined, { notation: 'compact', maximumFractionDigits: 1 })
|
|
272
|
+
|
|
273
|
+
function SearchIcon() {
|
|
274
|
+
return h('svg', {
|
|
275
|
+
className: 'pf-search-icon', viewBox: '0 0 16 16', width: 16, height: 16, 'aria-hidden': true,
|
|
276
|
+
fill: 'none', stroke: 'currentColor', strokeWidth: 1.5,
|
|
277
|
+
}, h('circle', { cx: 7, cy: 7, r: 4.5 }), h('path', { d: 'M10.5 10.5 14 14', strokeLinecap: 'round' }))
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function FinderRow(props) {
|
|
281
|
+
const { entry, install, language, t } = props
|
|
282
|
+
const [broken, setBroken] = useState(false)
|
|
283
|
+
const description = entry.description?.[language] ?? entry.description?.en ?? entry.description?.zh
|
|
284
|
+
const meta = [entry.owner, categoryLabel(entry.category, language)].filter(Boolean).join(' · ')
|
|
285
|
+
const metric = entry.downloads > 0
|
|
286
|
+
? { text: compact.format(entry.downloads), title: t('downloads', { count: entry.downloads.toLocaleString() }) }
|
|
287
|
+
: entry.stars > 0
|
|
288
|
+
? { text: `${compact.format(entry.stars)} ★`, title: t('stars', { count: entry.stars.toLocaleString() }) }
|
|
289
|
+
: undefined
|
|
290
|
+
return h('div', { className: 'pf-row', 'data-plugin': entry.name },
|
|
291
|
+
h('div', { className: 'pf-avatar' },
|
|
292
|
+
entry.icon !== undefined && !broken
|
|
293
|
+
? h('img', {
|
|
294
|
+
src: entry.icon, alt: '', loading: 'lazy', referrerPolicy: 'no-referrer',
|
|
295
|
+
onError: () => { setBroken(true) },
|
|
296
|
+
})
|
|
297
|
+
: h('span', null, initialOf(entry.name))),
|
|
298
|
+
h('div', { className: 'pf-main' },
|
|
299
|
+
h('div', { className: 'pf-title-line' },
|
|
300
|
+
h('span', { className: 'pf-name', title: entry.name }, entry.name),
|
|
301
|
+
h('span', { className: 'pf-version' }, 'v' + entry.version)),
|
|
302
|
+
meta === '' ? null : h('div', { className: 'pf-meta' }, meta),
|
|
303
|
+
description === undefined || description === '' ? null : h('p', { className: 'pf-desc', title: description }, description)),
|
|
304
|
+
h('div', { className: 'pf-side' },
|
|
305
|
+
metric === undefined ? null : h('span', { className: 'pf-stat', title: metric.title }, metric.text),
|
|
306
|
+
h('button', {
|
|
307
|
+
type: 'button', className: 'pf-install',
|
|
308
|
+
onClick: () => { install({ spec: entry.name + '@' + entry.version, title: entry.name, version: entry.version }) },
|
|
309
|
+
}, t('install'))))
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function FinderTab(props) {
|
|
313
|
+
const t = props.t
|
|
314
|
+
const install = props.install
|
|
315
|
+
const [catalog, setCatalog] = useState(null)
|
|
316
|
+
const [status, setStatus] = useState('loading')
|
|
317
|
+
const [refreshing, setRefreshing] = useState(false)
|
|
318
|
+
const [refreshError, setRefreshError] = useState(false)
|
|
319
|
+
const [text, setText] = useState('')
|
|
320
|
+
const [query, setQuery] = useState('')
|
|
321
|
+
const [limit, setLimit] = useState(PAGE_SIZE)
|
|
322
|
+
|
|
323
|
+
async function load(refresh) {
|
|
324
|
+
if (refresh) {
|
|
325
|
+
setRefreshing(true)
|
|
326
|
+
setRefreshError(false)
|
|
327
|
+
} else {
|
|
328
|
+
setStatus('loading')
|
|
329
|
+
}
|
|
330
|
+
try {
|
|
331
|
+
const data = await readCatalog(refresh)
|
|
332
|
+
setCatalog(data)
|
|
333
|
+
setStatus('ready')
|
|
334
|
+
} catch {
|
|
335
|
+
if (refresh) setRefreshError(true)
|
|
336
|
+
else setStatus('failed')
|
|
337
|
+
} finally {
|
|
338
|
+
if (refresh) setRefreshing(false)
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
useEffect(() => { void load(false) }, [])
|
|
343
|
+
useEffect(() => {
|
|
344
|
+
const timer = setTimeout(() => { setQuery(text) }, 150)
|
|
345
|
+
return () => { clearTimeout(timer) }
|
|
346
|
+
}, [text])
|
|
347
|
+
|
|
348
|
+
const entries = useMemo(() => prepare(catalog?.plugins ?? []), [catalog])
|
|
349
|
+
const tokens = useMemo(() => tokenize(query), [query])
|
|
350
|
+
const results = useMemo(() => searchEntries(entries, tokens), [entries, tokens])
|
|
351
|
+
useEffect(() => { setLimit(PAGE_SIZE) }, [query, entries])
|
|
352
|
+
|
|
353
|
+
const shown = results.slice(0, limit)
|
|
354
|
+
const language = currentLanguage()
|
|
355
|
+
|
|
356
|
+
return h('div', { className: 'pf-root' },
|
|
357
|
+
h('style', null, CSS),
|
|
358
|
+
h('div', { className: 'pf-toolbar' },
|
|
359
|
+
h('label', { className: 'pf-search' },
|
|
360
|
+
h(SearchIcon),
|
|
361
|
+
h('input', {
|
|
362
|
+
className: 'pf-input', type: 'text', value: text, spellCheck: false, autoComplete: 'off',
|
|
363
|
+
placeholder: t('placeholder'), 'aria-label': t('placeholder'),
|
|
364
|
+
onChange: event => { setText(event.target.value) },
|
|
365
|
+
}),
|
|
366
|
+
text === '' ? null : h('button', {
|
|
367
|
+
type: 'button', className: 'pf-clear', 'aria-label': t('clear'),
|
|
368
|
+
onClick: () => { setText('') },
|
|
369
|
+
}, '×')),
|
|
370
|
+
h('button', {
|
|
371
|
+
type: 'button', className: 'pf-refresh', disabled: refreshing || status === 'loading',
|
|
372
|
+
onClick: () => { void load(true) },
|
|
373
|
+
}, refreshing ? t('refreshing') : t('refresh'))),
|
|
374
|
+
h('div', { className: 'pf-summary' },
|
|
375
|
+
h('span', null, status === 'ready' ? t('count', { count: results.length }) : ''),
|
|
376
|
+
refreshError ? h('span', { className: 'pf-warn' }, t('refreshFailed')) : null),
|
|
377
|
+
status === 'loading'
|
|
378
|
+
? h('div', { className: 'pf-state', role: 'status' }, t('loading'))
|
|
379
|
+
: status === 'failed'
|
|
380
|
+
? h('div', { className: 'pf-state', role: 'alert' },
|
|
381
|
+
t('failed'),
|
|
382
|
+
h('button', { type: 'button', className: 'pf-link', onClick: () => { void load(false) } }, t('retry')))
|
|
383
|
+
: results.length === 0
|
|
384
|
+
? h('div', { className: 'pf-state' }, t('empty'))
|
|
385
|
+
: h('div', { className: 'pf-list' },
|
|
386
|
+
shown.map(entry => h(FinderRow, {
|
|
387
|
+
key: entry.name, entry, install, language, t,
|
|
388
|
+
}))),
|
|
389
|
+
results.length > shown.length
|
|
390
|
+
? h('button', { type: 'button', className: 'pf-more', onClick: () => { setLimit(limit + PAGE_SIZE) } },
|
|
391
|
+
`${t('more')} (${results.length - shown.length})`)
|
|
392
|
+
: null,
|
|
393
|
+
h('div', { className: 'pf-note' }, t('note')))
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return {
|
|
397
|
+
/** Internal exports used by the package's Node-side checks. */
|
|
398
|
+
__test: { prepare, tokenize, searchEntries, FinderTab, FinderRow },
|
|
399
|
+
inject: ['slots', 'locale'],
|
|
400
|
+
apply(ctx) {
|
|
401
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'plugin-finder: dictionaries')
|
|
402
|
+
const t = ctx.locale.bind(NS)
|
|
403
|
+
ctx.slots.inject('plugins.tab', () => ctx.slots.register({
|
|
404
|
+
name: 'plugins.tab',
|
|
405
|
+
id: 'finder',
|
|
406
|
+
order: 10,
|
|
407
|
+
label: () => t('title'),
|
|
408
|
+
locale: NS,
|
|
409
|
+
inject: () => ({ t }),
|
|
410
|
+
}, FinderTab))
|
|
411
|
+
},
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
})
|
package/cordis.patch.yml
ADDED