dsh-featured 0.1.2 → 0.1.4
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/lib/client.js +99 -18
- package/lib/index.js +1 -1
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -2
package/lib/client.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// 正式 DSH bundle:向官方插件页 plugins.tab 槽注册「精选插件」tab,
|
|
4
4
|
// 带搜索栏、标签筛选、申请收录入口与 README 详情弹窗。
|
|
5
5
|
//
|
|
6
|
-
//
|
|
7
|
-
// - 两者用同一个 slot id
|
|
6
|
+
// 与内联欢迎页(历史集成自带)的关系:
|
|
7
|
+
// - 两者用同一个 slot id(兼容常量,见 apply),页面只显示一个 tab;
|
|
8
8
|
// - 本插件启动时若发现内联版已注册,先调它的 disposer 注销(GitHub 上挂
|
|
9
9
|
// window.__DSH_FEATURED_ENTRY__),再注册完整版 —— 干净替换,不靠 priority 遮蔽。
|
|
10
10
|
// - 内联版保持原样不动(已发布,有人下载);本插件装上后自动接管。
|
|
@@ -199,6 +199,10 @@ window.__ModuleLoader__.load({
|
|
|
199
199
|
},
|
|
200
200
|
// ── 自建详情弹窗(README 从 npm 包 jsdelivr 读取) ──
|
|
201
201
|
overlay: { position: 'fixed', inset: 0, zIndex: 1000, background: 'rgba(0,0,0,0.4)', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 24 },
|
|
202
|
+
viewer: { position: 'fixed', inset: 0, zIndex: 1100, background: 'rgba(0,0,0,0.72)', display: 'flex', alignItems: 'center', justifyContent: 'center' },
|
|
203
|
+
viewerImg: { maxWidth: '82vw', maxHeight: '82vh', borderRadius: 10, boxShadow: '0 12px 48px rgba(0,0,0,0.5)', background: 'var(--dsw-alias-bg-layer-1)' },
|
|
204
|
+
viewerBtn: { position: 'absolute', width: 34, height: 34, borderRadius: '50%', border: 'none', background: 'rgba(0,0,0,0.55)', color: '#fff', fontSize: 16, lineHeight: 1, cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center' },
|
|
205
|
+
viewerCount: { position: 'absolute', bottom: 18, left: '50%', transform: 'translateX(-50%)', color: 'rgba(255,255,255,0.85)', fontSize: 12 },
|
|
202
206
|
panel: {
|
|
203
207
|
width: 'min(860px, 92vw)', maxHeight: '84vh', display: 'flex', flexDirection: 'column',
|
|
204
208
|
background: 'var(--dsw-alias-bg-layer-2)', border: '1px solid var(--dsw-alias-border-l1)',
|
|
@@ -269,18 +273,93 @@ window.__ModuleLoader__.load({
|
|
|
269
273
|
meta ? h('span', { style: S.meta }, meta) : null)
|
|
270
274
|
}
|
|
271
275
|
|
|
272
|
-
//
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
+
// 截图来源:不依赖目录 screenshots 字段(可能指向别的仓库),直接读
|
|
277
|
+
// 插件自己 npm 包里的 README,提取其中的图片作为截图。
|
|
278
|
+
function readmeBase(entry) {
|
|
279
|
+
return `https://cdn.jsdelivr.net/npm/${entry.package}${entry.version ? '@' + entry.version : ''}/`
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function extractReadmeImages(txt, base) {
|
|
283
|
+
const out = []
|
|
284
|
+
const push = (u) => {
|
|
285
|
+
const a = mdAbsUrl(u, base)
|
|
286
|
+
if (out.indexOf(a) < 0) out.push(a)
|
|
287
|
+
}
|
|
288
|
+
const s = String(txt)
|
|
289
|
+
s.replace(/!\[[^\]]*\]\(([^)\s]+)(?:\s+"[^"]*")?\)/g, (m0, u) => { push(u); return m0 })
|
|
290
|
+
s.replace(/<img[^>]*\ssrc=["']([^"']+)["']/gi, (m0, u) => { push(u); return m0 })
|
|
291
|
+
// 过滤徽章类小图:svg / shields / badge / CI 字样
|
|
292
|
+
return out.filter((u) => !/\.svg(?:[?#]|$)|shields\.io|badge|travis|circleci|codecov/i.test(u)).slice(0, 8)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// 尺寸过滤阈值:加载后 宽<240 或 高<160 视为太小(徽章/图标),不进截图区。
|
|
296
|
+
const SHOT_MIN_W = 240
|
|
297
|
+
const SHOT_MIN_H = 160
|
|
298
|
+
|
|
299
|
+
function ReadmeShots(props) {
|
|
300
|
+
const entry = props.entry
|
|
301
|
+
const onOpen = props.onOpen
|
|
302
|
+
const pair = React.useState({ status: 'loading', urls: [] })
|
|
303
|
+
const state = pair[0], setState = pair[1]
|
|
304
|
+
const dropPair = React.useState({})
|
|
305
|
+
const drop = dropPair[0], setDrop = dropPair[1]
|
|
306
|
+
|
|
307
|
+
React.useEffect(() => {
|
|
308
|
+
let alive = true
|
|
309
|
+
const base = readmeBase(entry)
|
|
310
|
+
fetchText(base + 'README.md', 10000).then((txt) => {
|
|
311
|
+
if (alive) setState({ status: 'ready', urls: extractReadmeImages(txt, base) })
|
|
312
|
+
}).catch(() => {
|
|
313
|
+
const gh = entry.homepage && /^https?:\/\/github\.com\/([^/]+)\/([^/]+)/i.exec(entry.homepage)
|
|
314
|
+
if (!gh) { if (alive) setState({ status: 'error', urls: [] }); return }
|
|
315
|
+
const ghBase = `https://cdn.jsdelivr.net/gh/${gh[1]}/${gh[2]}@main/`
|
|
316
|
+
fetchText(ghBase + 'README.md', 10000).then((txt) => {
|
|
317
|
+
if (alive) setState({ status: 'ready', urls: extractReadmeImages(txt, ghBase) })
|
|
318
|
+
}).catch(() => { if (alive) setState({ status: 'error', urls: [] }) })
|
|
319
|
+
})
|
|
320
|
+
return () => { alive = false }
|
|
321
|
+
}, [entry.package])
|
|
322
|
+
|
|
323
|
+
const visible = state.urls.filter((u) => !drop[u]).slice(0, 2)
|
|
324
|
+
if (!visible.length) return null
|
|
325
|
+
return h('div', { style: S.shots }, visible.map((url, i) =>
|
|
326
|
+
h('img', {
|
|
327
|
+
key: url, src: url, alt: '', style: S.shot, loading: 'lazy',
|
|
328
|
+
onLoad: (ev) => {
|
|
329
|
+
const im = ev.target || {}
|
|
330
|
+
if (im.naturalWidth && (im.naturalWidth < SHOT_MIN_W || im.naturalHeight < SHOT_MIN_H)) {
|
|
331
|
+
setDrop(Object.assign({}, drop, { [url]: true }))
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
onError: () => setDrop(Object.assign({}, drop, { [url]: true })),
|
|
335
|
+
onClick: () => onOpen && onOpen(visible, i),
|
|
336
|
+
})))
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// 截图灯箱:点击缩略图弹出大图,左右按钮切换,Esc/←/→ 键盘可用。
|
|
340
|
+
function ShotViewer(props) {
|
|
341
|
+
const list = props.list
|
|
342
|
+
const onClose = props.onClose
|
|
343
|
+
const pair = React.useState(props.index || 0)
|
|
276
344
|
const idx = pair[0], setIdx = pair[1]
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
345
|
+
React.useEffect(() => {
|
|
346
|
+
const onKey = (ev) => {
|
|
347
|
+
if (ev.key === 'Escape') onClose()
|
|
348
|
+
else if (ev.key === 'ArrowLeft') setIdx((i) => (i + list.length - 1) % list.length)
|
|
349
|
+
else if (ev.key === 'ArrowRight') setIdx((i) => (i + 1) % list.length)
|
|
350
|
+
}
|
|
351
|
+
window.addEventListener('keydown', onKey)
|
|
352
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
353
|
+
}, [onClose, list.length])
|
|
354
|
+
if (!list.length) return null
|
|
355
|
+
const i = Math.min(idx, list.length - 1)
|
|
356
|
+
const go = (d) => setIdx((i + d + list.length) % list.length)
|
|
357
|
+
return h('div', { style: S.viewer, onClick: (ev) => { if (ev.target === ev.currentTarget) onClose() } },
|
|
358
|
+
h('img', { src: list[i], alt: '', style: S.viewerImg }),
|
|
359
|
+
h('button', { type: 'button', style: Object.assign({}, S.viewerBtn, { top: 16, right: 16 }), onClick: onClose }, '✕'),
|
|
360
|
+
list.length > 1 ? h('button', { type: 'button', style: Object.assign({}, S.viewerBtn, { top: '50%', left: 16, marginTop: -16 }), onClick: () => go(-1) }, '‹') : null,
|
|
361
|
+
list.length > 1 ? h('button', { type: 'button', style: Object.assign({}, S.viewerBtn, { top: '50%', right: 16, marginTop: -16 }), onClick: () => go(1) }, '›') : null,
|
|
362
|
+
list.length > 1 ? h('div', { style: S.viewerCount }, (i + 1) + ' / ' + list.length) : null)
|
|
284
363
|
}
|
|
285
364
|
|
|
286
365
|
// 卡片布局对齐官方 Discover:
|
|
@@ -301,6 +380,7 @@ window.__ModuleLoader__.load({
|
|
|
301
380
|
const t = props.t
|
|
302
381
|
const install = props.install
|
|
303
382
|
const onDetail = props.onDetail // 打开自建详情弹窗
|
|
383
|
+
const onShots = props.onShots // 打开截图灯箱(list, idx)
|
|
304
384
|
const installed = !!props.installed // 宿主侧 pluginManager.listBundles 判定
|
|
305
385
|
const pair = React.useState(false) // busy
|
|
306
386
|
const busy = pair[0], setBusy = pair[1]
|
|
@@ -340,9 +420,7 @@ window.__ModuleLoader__.load({
|
|
|
340
420
|
}, btnLabel)),
|
|
341
421
|
h(FeaturedAuthor, { pkg: e.package, meta: metaText, onDetail }),
|
|
342
422
|
e.description ? h('p', { style: S.desc, onClick: onDetail }, e.description) : null,
|
|
343
|
-
e
|
|
344
|
-
? h('div', { style: S.shots }, e.screenshots.map((url) => h(FeaturedShot, { key: url, url })))
|
|
345
|
-
: null,
|
|
423
|
+
h(ReadmeShots, { entry: e, onOpen: onShots }),
|
|
346
424
|
h('div', { style: S.foot },
|
|
347
425
|
h('div', { style: S.chips },
|
|
348
426
|
chips.map((c) => h('span', { key: c, style: S.chip, title: c }, c)),
|
|
@@ -598,6 +676,8 @@ window.__ModuleLoader__.load({
|
|
|
598
676
|
const query = queryPair[0], setQuery = queryPair[1]
|
|
599
677
|
const tagPair = React.useState('')
|
|
600
678
|
const activeTag = tagPair[0], setActiveTag = tagPair[1]
|
|
679
|
+
const viewerPair = React.useState(null)
|
|
680
|
+
const viewer = viewerPair[0], setViewer = viewerPair[1]
|
|
601
681
|
|
|
602
682
|
React.useEffect(() => {
|
|
603
683
|
let alive = true
|
|
@@ -673,7 +753,7 @@ window.__ModuleLoader__.load({
|
|
|
673
753
|
}
|
|
674
754
|
if (visible.length) {
|
|
675
755
|
kids.push(h('ul', { key: 'grid', style: S.grid }, visible.map((e) => (
|
|
676
|
-
h(FeaturedCard, { key: e.package, entry: e, t, install, onDetail: () => setDetail(e), installed: !!state.installed[e.package] })
|
|
756
|
+
h(FeaturedCard, { key: e.package, entry: e, t, install, onDetail: () => setDetail(e), onShots: (list, idx) => setViewer({ list, idx }), installed: !!state.installed[e.package] })
|
|
677
757
|
))))
|
|
678
758
|
} else {
|
|
679
759
|
kids.push(h('p', { key: 'nomatch', style: S.note }, t('noMatch')))
|
|
@@ -682,7 +762,8 @@ window.__ModuleLoader__.load({
|
|
|
682
762
|
|
|
683
763
|
return h('div', { style: S.wrap }, kids,
|
|
684
764
|
detail ? h(FeaturedModal, { key: 'detail-' + detail.package, entry: detail, t, onClose: () => setDetail(null) }) : null,
|
|
685
|
-
applyOpen ? h(ApplyModal, { key: 'apply', t, onClose: () => setApplyOpen(false) }) : null
|
|
765
|
+
applyOpen ? h(ApplyModal, { key: 'apply', t, onClose: () => setApplyOpen(false) }) : null,
|
|
766
|
+
viewer ? h(ShotViewer, { key: 'viewer', list: viewer.list, index: viewer.idx, onClose: () => setViewer(null) }) : null)
|
|
686
767
|
}
|
|
687
768
|
|
|
688
769
|
// 独立插件是唯一「官方完整版」:
|
package/lib/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// 按 updated 取最新),5 分钟内存缓存 —— 浏览器侧零外部请求、无缓存/跨域问题。
|
|
6
6
|
// 2. 已安装表:轮询 pluginManager.listBundles(),给卡片「已安装」徽标。
|
|
7
7
|
// 3. 聚合路由 GET /dsh-featured/featured:返回 { entries, installed, sources }。
|
|
8
|
-
// 4.
|
|
8
|
+
// 4. 内联版让位通道:如果某个接入插件内联了极简欢迎页,
|
|
9
9
|
// 它的 client 会在 window 上挂 __DSH_FEATURED_ENTRY__ = { dispose }。
|
|
10
10
|
// 本插件 client 启动时先调它注销内联版,再用同一个 slot id 注册完整版,
|
|
11
11
|
// 因此页面上永远只有一个「精选插件」tab(多插件同时集成也只会有内联一份)。
|
package/locale/en.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"noMatch": "No plugins match \"{q}\"",
|
|
11
11
|
"apply": "Submit",
|
|
12
12
|
"applyTitle": "Submit your plugin",
|
|
13
|
-
"applyStep1": "Fork the dsh-plugins
|
|
13
|
+
"applyStep1": "Fork the skillpie/dsh-plugins repo and add your plugin to entries in the root plugins.json, following the existing entry format (package, title, description, version, tags…).",
|
|
14
14
|
"applyStep2": "Open a Pull Request. Once merged, your plugin appears in every client that integrates Featured Plugins, with version and icon resolved automatically.",
|
|
15
15
|
"applyStep3": "You can also file an Issue with the package name and a short description, and a maintainer will add it for you.",
|
|
16
16
|
"applyExample": "Entry example (copy and edit):",
|
package/locale/zh.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"noMatch": "没有匹配「{q}」的插件",
|
|
11
11
|
"apply": "申请收录",
|
|
12
12
|
"applyTitle": "申请收录插件",
|
|
13
|
-
"applyStep1": "Fork 仓库 dsh-plugins
|
|
13
|
+
"applyStep1": "Fork 仓库 skillpie/dsh-plugins,在根目录的 plugins.json 的 entries 里按现有条目格式补充你的插件(包名、标题、简介、版本、标签等)。",
|
|
14
14
|
"applyStep2": "提交 Pull Request。合并后插件会出现在所有接入「精选插件」的客户端,并自动带上版本与图标。",
|
|
15
15
|
"applyStep3": "也可以直接在 Issue 里留下包名和简介,由维护者代为收录。",
|
|
16
16
|
"applyExample": "条目示例(可直接复制修改):",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-featured",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "精选插件:官方插件页的精选板块。带搜索栏、标签筛选、申请收录入口,数据来自 GitHub 集中维护的 plugins.json;已接入内联欢迎页的插件会自动让位给本插件,界面更新只需发这一个包。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|