@shiqianjiang/ceru-plugin-cli 0.3.15 → 3.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 +26 -7
- package/assets/compatibility.json +18 -0
- package/dist/compatibility.d.ts +24 -0
- package/dist/compatibility.js +119 -0
- package/dist/component.d.ts +6 -0
- package/dist/component.js +60 -0
- package/dist/dev-music.d.ts +19 -0
- package/dist/dev-music.js +81 -0
- package/dist/dev-plugin-services.d.ts +10 -0
- package/dist/dev-plugin-services.js +67 -0
- package/dist/dev.d.ts +1 -9
- package/dist/dev.js +53 -713
- package/dist/frameworks.d.ts +5 -2
- package/dist/frameworks.js +43 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +54 -23
- package/dist/init.js +3 -3
- package/dist/migrate.d.ts +3 -0
- package/dist/migrate.js +109 -0
- package/dist/project.d.ts +5 -2
- package/dist/project.js +131 -43
- package/dist/test-hooks.d.ts +1 -0
- package/dist/test-hooks.js +209 -0
- package/dist/test-services.d.ts +4 -0
- package/dist/test-services.js +54 -0
- package/dist/watch-vue-types.d.ts +17 -0
- package/dist/watch-vue-types.js +145 -0
- package/package.json +10 -6
- package/schemas/config.schema.json +954 -452
- package/templates/account-qrcode/js/.vscode/extensions.json +3 -0
- package/templates/account-qrcode/js/.vscode/launch.json +19 -0
- package/templates/account-qrcode/js/.vscode/settings.json +20 -0
- package/templates/account-qrcode/js/.vscode/tasks.json +43 -0
- package/templates/account-qrcode/js/README.md +15 -0
- package/templates/account-qrcode/js/_gitignore +6 -0
- package/templates/account-qrcode/js/ceru-plugin.code-workspace +8 -0
- package/templates/account-qrcode/js/ceru.plugin.json +62 -0
- package/templates/account-qrcode/js/package.json +24 -0
- package/templates/account-qrcode/js/src/Login.vue +25 -0
- package/templates/account-qrcode/js/src/index.js +25 -0
- package/templates/account-qrcode/js/src/login-html.js +23 -0
- package/templates/account-qrcode/js/tsconfig.json +17 -0
- package/templates/account-qrcode/ts/.vscode/extensions.json +3 -0
- package/templates/account-qrcode/ts/.vscode/launch.json +19 -0
- package/templates/account-qrcode/ts/.vscode/settings.json +20 -0
- package/templates/account-qrcode/ts/.vscode/tasks.json +43 -0
- package/templates/account-qrcode/ts/README.md +15 -0
- package/templates/account-qrcode/ts/_gitignore +6 -0
- package/templates/account-qrcode/ts/ceru-plugin.code-workspace +8 -0
- package/templates/account-qrcode/ts/ceru.plugin.json +62 -0
- package/templates/account-qrcode/ts/package.json +24 -0
- package/templates/account-qrcode/ts/src/Login.vue +25 -0
- package/templates/account-qrcode/ts/src/index.ts +25 -0
- package/templates/account-qrcode/ts/src/login-html.ts +23 -0
- package/templates/account-qrcode/ts/tsconfig.json +17 -0
- package/templates/connected-library/js/.vscode/launch.json +12 -29
- package/templates/connected-library/js/.vscode/tasks.json +2 -3
- package/templates/connected-library/js/README.md +26 -12
- package/templates/connected-library/js/ceru.plugin.json +122 -50
- package/templates/connected-library/js/package.json +5 -5
- package/templates/connected-library/js/src/index.js +46 -5
- package/templates/connected-library/js/src/settings.js +28 -0
- package/templates/connected-library/ts/.vscode/launch.json +12 -29
- package/templates/connected-library/ts/.vscode/tasks.json +2 -3
- package/templates/connected-library/ts/README.md +26 -12
- package/templates/connected-library/ts/ceru.plugin.json +122 -50
- package/templates/connected-library/ts/package.json +5 -5
- package/templates/connected-library/ts/src/index.ts +46 -5
- package/templates/connected-library/ts/src/settings.ts +28 -0
- package/templates/encrypted-source/README.md +86 -0
- package/templates/encrypted-source/js/.prettierrc.json +5 -0
- package/templates/encrypted-source/js/.vscode/ceru.code-snippets +55 -0
- package/templates/encrypted-source/js/.vscode/extensions.json +3 -0
- package/templates/encrypted-source/js/.vscode/launch.json +15 -0
- package/templates/encrypted-source/js/.vscode/settings.json +20 -0
- package/templates/encrypted-source/js/.vscode/tasks.json +40 -0
- package/templates/encrypted-source/js/DEMO.md +77 -0
- package/templates/encrypted-source/js/README.md +13 -0
- package/templates/encrypted-source/js/_gitignore +6 -0
- package/templates/encrypted-source/js/ceru-plugin.code-workspace +8 -0
- package/templates/encrypted-source/js/ceru.plugin.json +95 -0
- package/templates/encrypted-source/js/package.json +26 -0
- package/templates/encrypted-source/js/resources/xor-byte.wasm +0 -0
- package/templates/encrypted-source/js/resources/xor-byte.wat +5 -0
- package/templates/encrypted-source/js/src/demo.js +200 -0
- package/templates/encrypted-source/js/src/fixtures.js +118 -0
- package/templates/encrypted-source/js/src/index.js +4 -0
- package/templates/encrypted-source/js/tests/demo.test.mjs +357 -0
- package/templates/encrypted-source/js/tsconfig.json +16 -0
- package/templates/encrypted-source/ts/.prettierrc.json +5 -0
- package/templates/encrypted-source/ts/.vscode/ceru.code-snippets +55 -0
- package/templates/encrypted-source/ts/.vscode/extensions.json +3 -0
- package/templates/encrypted-source/ts/.vscode/launch.json +15 -0
- package/templates/encrypted-source/ts/.vscode/settings.json +20 -0
- package/templates/encrypted-source/ts/.vscode/tasks.json +40 -0
- package/templates/encrypted-source/ts/DEMO.md +77 -0
- package/templates/encrypted-source/ts/README.md +13 -0
- package/templates/encrypted-source/ts/_gitignore +6 -0
- package/templates/encrypted-source/ts/ceru-plugin.code-workspace +8 -0
- package/templates/encrypted-source/ts/ceru.plugin.json +95 -0
- package/templates/encrypted-source/ts/package.json +26 -0
- package/templates/encrypted-source/ts/resources/xor-byte.wasm +0 -0
- package/templates/encrypted-source/ts/resources/xor-byte.wat +5 -0
- package/templates/encrypted-source/ts/src/demo.ts +212 -0
- package/templates/encrypted-source/ts/src/fixtures.ts +125 -0
- package/templates/encrypted-source/ts/src/index.ts +4 -0
- package/templates/encrypted-source/ts/tests/demo.test.mjs +357 -0
- package/templates/encrypted-source/ts/tsconfig.json +17 -0
- package/templates/guest-adapter/js/.vscode/launch.json +12 -29
- package/templates/guest-adapter/js/.vscode/tasks.json +2 -3
- package/templates/guest-adapter/js/README.md +10 -10
- package/templates/guest-adapter/js/ceru.plugin.json +67 -62
- package/templates/guest-adapter/js/package.json +5 -5
- package/templates/guest-adapter/js/src/index.js +1 -1
- package/templates/guest-adapter/js/src/settings.js +8 -0
- package/templates/guest-adapter/ts/.vscode/launch.json +12 -29
- package/templates/guest-adapter/ts/.vscode/tasks.json +2 -3
- package/templates/guest-adapter/ts/README.md +10 -10
- package/templates/guest-adapter/ts/ceru.plugin.json +67 -62
- package/templates/guest-adapter/ts/package.json +5 -5
- package/templates/guest-adapter/ts/src/index.ts +1 -1
- package/templates/guest-adapter/ts/src/settings.ts +8 -0
- package/templates/importer/js/.vscode/launch.json +12 -29
- package/templates/importer/js/.vscode/tasks.json +2 -3
- package/templates/importer/js/README.md +10 -10
- package/templates/importer/js/ceru.plugin.json +23 -21
- package/templates/importer/js/package.json +5 -5
- package/templates/importer/ts/.vscode/launch.json +12 -29
- package/templates/importer/ts/.vscode/tasks.json +2 -3
- package/templates/importer/ts/README.md +10 -10
- package/templates/importer/ts/ceru.plugin.json +23 -21
- package/templates/importer/ts/package.json +5 -5
- package/templates/page-extension/js/.vscode/extensions.json +3 -0
- package/templates/page-extension/js/.vscode/launch.json +19 -0
- package/templates/page-extension/js/.vscode/settings.json +20 -0
- package/templates/page-extension/js/.vscode/tasks.json +43 -0
- package/templates/page-extension/js/README.md +9 -0
- package/templates/page-extension/js/_gitignore +6 -0
- package/templates/page-extension/js/ceru-plugin.code-workspace +8 -0
- package/templates/page-extension/js/ceru.plugin.json +94 -0
- package/templates/page-extension/js/package.json +24 -0
- package/templates/page-extension/js/src/Open.vue +6 -0
- package/templates/page-extension/js/src/Search.vue +62 -0
- package/templates/page-extension/js/src/index.js +54 -0
- package/templates/page-extension/js/tsconfig.json +17 -0
- package/templates/page-extension/ts/.vscode/extensions.json +3 -0
- package/templates/page-extension/ts/.vscode/launch.json +19 -0
- package/templates/page-extension/ts/.vscode/settings.json +20 -0
- package/templates/page-extension/ts/.vscode/tasks.json +43 -0
- package/templates/page-extension/ts/README.md +9 -0
- package/templates/page-extension/ts/_gitignore +6 -0
- package/templates/page-extension/ts/ceru-plugin.code-workspace +8 -0
- package/templates/page-extension/ts/ceru.plugin.json +94 -0
- package/templates/page-extension/ts/package.json +24 -0
- package/templates/page-extension/ts/src/Open.vue +6 -0
- package/templates/page-extension/ts/src/Search.vue +62 -0
- package/templates/page-extension/ts/src/index.ts +54 -0
- package/templates/page-extension/ts/tsconfig.json +17 -0
- package/templates/playback-hook/js/.prettierrc.json +5 -0
- package/templates/playback-hook/js/.vscode/extensions.json +3 -0
- package/templates/playback-hook/js/.vscode/launch.json +19 -0
- package/templates/playback-hook/js/.vscode/settings.json +20 -0
- package/templates/playback-hook/js/.vscode/tasks.json +50 -0
- package/templates/playback-hook/js/README.md +24 -0
- package/templates/playback-hook/js/_gitignore +6 -0
- package/templates/playback-hook/js/ceru-plugin.code-workspace +8 -0
- package/templates/playback-hook/js/ceru.plugin.json +36 -0
- package/templates/playback-hook/js/package.json +23 -0
- package/templates/playback-hook/js/src/index.js +25 -0
- package/templates/playback-hook/js/tests/hooks.json +316 -0
- package/templates/playback-hook/js/tsconfig.json +16 -0
- package/templates/playback-hook/ts/.prettierrc.json +5 -0
- package/templates/playback-hook/ts/.vscode/extensions.json +3 -0
- package/templates/playback-hook/ts/.vscode/launch.json +19 -0
- package/templates/playback-hook/ts/.vscode/settings.json +20 -0
- package/templates/playback-hook/ts/.vscode/tasks.json +50 -0
- package/templates/playback-hook/ts/README.md +24 -0
- package/templates/playback-hook/ts/_gitignore +6 -0
- package/templates/playback-hook/ts/ceru-plugin.code-workspace +8 -0
- package/templates/playback-hook/ts/ceru.plugin.json +36 -0
- package/templates/playback-hook/ts/package.json +23 -0
- package/templates/playback-hook/ts/src/index.ts +25 -0
- package/templates/playback-hook/ts/tests/hooks.json +316 -0
- package/templates/playback-hook/ts/tsconfig.json +16 -0
- package/templates/player-skin/js/.vscode/extensions.json +3 -0
- package/templates/player-skin/js/.vscode/launch.json +19 -0
- package/templates/player-skin/js/.vscode/settings.json +20 -0
- package/templates/player-skin/js/.vscode/tasks.json +43 -0
- package/templates/player-skin/js/README.md +11 -0
- package/templates/player-skin/js/_gitignore +6 -0
- package/templates/player-skin/js/assets/studio-preview.svg +15 -0
- package/templates/player-skin/js/ceru-plugin.code-workspace +8 -0
- package/templates/player-skin/js/ceru.plugin.json +77 -0
- package/templates/player-skin/js/package.json +24 -0
- package/templates/player-skin/js/src/Artwork.vue +9 -0
- package/templates/player-skin/js/src/Background.vue +15 -0
- package/templates/player-skin/js/src/BuiltinLyrics.vue +15 -0
- package/templates/player-skin/js/src/Lyrics.vue +28 -0
- package/templates/player-skin/js/tsconfig.json +17 -0
- package/templates/player-skin/ts/.vscode/extensions.json +3 -0
- package/templates/player-skin/ts/.vscode/launch.json +19 -0
- package/templates/player-skin/ts/.vscode/settings.json +20 -0
- package/templates/player-skin/ts/.vscode/tasks.json +43 -0
- package/templates/player-skin/ts/README.md +11 -0
- package/templates/player-skin/ts/_gitignore +6 -0
- package/templates/player-skin/ts/assets/studio-preview.svg +15 -0
- package/templates/player-skin/ts/ceru-plugin.code-workspace +8 -0
- package/templates/player-skin/ts/ceru.plugin.json +77 -0
- package/templates/player-skin/ts/package.json +24 -0
- package/templates/player-skin/ts/src/Artwork.vue +9 -0
- package/templates/player-skin/ts/src/Background.vue +15 -0
- package/templates/player-skin/ts/src/BuiltinLyrics.vue +15 -0
- package/templates/player-skin/ts/src/Lyrics.vue +28 -0
- package/templates/player-skin/ts/tsconfig.json +17 -0
- package/templates/react/js/.vscode/launch.json +12 -29
- package/templates/react/js/.vscode/tasks.json +2 -3
- package/templates/react/js/README.md +10 -10
- package/templates/react/js/ceru.plugin.json +27 -22
- package/templates/react/js/package.json +5 -5
- package/templates/react/js/src/index.js +1 -1
- package/templates/react/ts/.vscode/launch.json +12 -29
- package/templates/react/ts/.vscode/tasks.json +2 -3
- package/templates/react/ts/README.md +10 -10
- package/templates/react/ts/ceru.plugin.json +27 -22
- package/templates/react/ts/package.json +5 -5
- package/templates/react/ts/src/index.ts +1 -1
- package/templates/snapshot.json +152 -6
- package/templates/source/js/.vscode/launch.json +12 -29
- package/templates/source/js/.vscode/tasks.json +2 -3
- package/templates/source/js/README.md +12 -10
- package/templates/source/js/ceru.plugin.json +44 -26
- package/templates/source/js/package.json +5 -5
- package/templates/source/js/src/index.js +10 -8
- package/templates/source/ts/.vscode/launch.json +12 -29
- package/templates/source/ts/.vscode/tasks.json +2 -3
- package/templates/source/ts/README.md +12 -10
- package/templates/source/ts/ceru.plugin.json +44 -26
- package/templates/source/ts/package.json +5 -5
- package/templates/source/ts/src/index.ts +10 -8
- package/templates/vue/js/.vscode/launch.json +12 -29
- package/templates/vue/js/.vscode/tasks.json +2 -3
- package/templates/vue/js/README.md +10 -10
- package/templates/vue/js/ceru.plugin.json +27 -22
- package/templates/vue/js/package.json +5 -5
- package/templates/vue/js/src/index.js +1 -1
- package/templates/vue/ts/.vscode/launch.json +12 -29
- package/templates/vue/ts/.vscode/tasks.json +2 -3
- package/templates/vue/ts/README.md +10 -10
- package/templates/vue/ts/ceru.plugin.json +27 -22
- package/templates/vue/ts/package.json +5 -5
- package/templates/vue/ts/src/index.ts +1 -1
- package/templates/vue-tsx/js/.vscode/launch.json +12 -29
- package/templates/vue-tsx/js/.vscode/tasks.json +2 -3
- package/templates/vue-tsx/js/README.md +10 -10
- package/templates/vue-tsx/js/ceru.plugin.json +27 -22
- package/templates/vue-tsx/js/package.json +5 -5
- package/templates/vue-tsx/js/src/index.js +1 -1
- package/templates/vue-tsx/ts/.vscode/launch.json +12 -29
- package/templates/vue-tsx/ts/.vscode/tasks.json +2 -3
- package/templates/vue-tsx/ts/README.md +10 -10
- package/templates/vue-tsx/ts/ceru.plugin.json +27 -22
- package/templates/vue-tsx/ts/package.json +5 -5
- package/templates/vue-tsx/ts/src/index.ts +1 -1
- package/templates/web-dist/js/.vscode/launch.json +12 -29
- package/templates/web-dist/js/.vscode/tasks.json +2 -3
- package/templates/web-dist/js/README.md +10 -10
- package/templates/web-dist/js/ceru.plugin.json +27 -22
- package/templates/web-dist/js/package.json +5 -5
- package/templates/web-dist/js/src/index.js +1 -1
- package/templates/web-dist/ts/.vscode/launch.json +12 -29
- package/templates/web-dist/ts/.vscode/tasks.json +2 -3
- package/templates/web-dist/ts/README.md +10 -10
- package/templates/web-dist/ts/ceru.plugin.json +27 -22
- package/templates/web-dist/ts/package.json +5 -5
- package/templates/web-dist/ts/src/index.ts +1 -1
- package/templates/web-surface/js/.vscode/launch.json +12 -29
- package/templates/web-surface/js/.vscode/tasks.json +2 -3
- package/templates/web-surface/js/README.md +10 -10
- package/templates/web-surface/js/ceru.plugin.json +35 -35
- package/templates/web-surface/js/package.json +5 -5
- package/templates/web-surface/js/src/index.js +1 -1
- package/templates/web-surface/ts/.vscode/launch.json +12 -29
- package/templates/web-surface/ts/.vscode/tasks.json +2 -3
- package/templates/web-surface/ts/README.md +10 -10
- package/templates/web-surface/ts/ceru.plugin.json +35 -35
- package/templates/web-surface/ts/package.json +5 -5
- package/templates/web-surface/ts/src/index.ts +1 -1
- package/assets/core-contracts.js +0 -1
- package/assets/electron-app/main.cjs +0 -1
- package/assets/electron-app/package.json +0 -8
- package/assets/electron.cjs +0 -42
- package/assets/index.html +0 -94
- package/assets/native-view.js +0 -197
- package/assets/playground.js +0 -883
- package/assets/sandbox.js +0 -67
- package/assets/style.css +0 -337
- package/dist/socket-broker.d.ts +0 -23
- package/dist/socket-broker.js +0 -229
- package/templates/connected-library/js/ui/settings.json +0 -24
- package/templates/connected-library/ts/ui/settings.json +0 -24
- package/templates/guest-adapter/js/ui/settings.json +0 -14
- package/templates/guest-adapter/ts/ui/settings.json +0 -14
package/assets/native-view.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { assertNativeView, SurfaceSession } from './core-contracts.js'
|
|
2
|
-
|
|
3
|
-
/** Preview Host components, rendered in the Host DOM; plugin code remains in the logic sandbox. */
|
|
4
|
-
export class NativeSurfacePreview {
|
|
5
|
-
constructor(container, session, actions, onError = () => {}) {
|
|
6
|
-
this.container = container
|
|
7
|
-
this.session = session
|
|
8
|
-
this.actions = actions
|
|
9
|
-
this.onError = onError
|
|
10
|
-
this.closed = false
|
|
11
|
-
this.revision = 0
|
|
12
|
-
this.container.classList.add('native-preview')
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async open() {
|
|
16
|
-
try {
|
|
17
|
-
await this.session.open()
|
|
18
|
-
if (!this.closed) await this.refresh()
|
|
19
|
-
} catch (error) { this.fail(error) }
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
refresh() {
|
|
23
|
-
if (this.closed) return Promise.resolve()
|
|
24
|
-
this.revision++
|
|
25
|
-
if (this.rendering) return this.rendering
|
|
26
|
-
this.rendering = (async () => {
|
|
27
|
-
let rendered
|
|
28
|
-
do {
|
|
29
|
-
rendered = this.revision
|
|
30
|
-
const view = await this.session.invoke(this.session.surface.entry, {})
|
|
31
|
-
if (this.closed) return
|
|
32
|
-
assertNativeView(view, this.actions)
|
|
33
|
-
if (rendered === this.revision) this.render(view)
|
|
34
|
-
} while (!this.closed && rendered !== this.revision)
|
|
35
|
-
})().catch(error => this.fail(error)).finally(() => { this.rendering = undefined })
|
|
36
|
-
return this.rendering
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
dispose() {
|
|
40
|
-
this.closed = true
|
|
41
|
-
this.container.classList.remove('native-preview')
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
fail(error) {
|
|
45
|
-
if (this.closed) return
|
|
46
|
-
this.container.replaceChildren(this.element('p', error.message, 'error'))
|
|
47
|
-
this.onError(error)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
element(tag, text, className) {
|
|
51
|
-
const element = this.container.ownerDocument.createElement(tag)
|
|
52
|
-
if (text !== undefined) element.textContent = text
|
|
53
|
-
if (className) element.className = className
|
|
54
|
-
return element
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
button(label, action, input, primary = false) {
|
|
58
|
-
const button = this.element('button', label, primary ? 'primary' : '')
|
|
59
|
-
button.type = 'button'
|
|
60
|
-
button.onclick = async () => {
|
|
61
|
-
button.disabled = true
|
|
62
|
-
try {
|
|
63
|
-
await this.session.invoke(action, input)
|
|
64
|
-
if (!this.closed) await this.refresh()
|
|
65
|
-
} catch (error) { if (!this.closed) this.onError(error) }
|
|
66
|
-
finally { button.disabled = false }
|
|
67
|
-
}
|
|
68
|
-
return button
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
render(view) {
|
|
72
|
-
const page = this.element('div', undefined, 'native-page')
|
|
73
|
-
if (view.title) page.append(this.element('h2', view.title))
|
|
74
|
-
if (view.description) page.append(this.element('p', view.description, 'hint'))
|
|
75
|
-
const toolbar = this.element('div', undefined, 'native-actions')
|
|
76
|
-
for (const action of view.actions ?? [])
|
|
77
|
-
toolbar.append(this.button(action.label, action.action, action.input ?? {}, action.primary))
|
|
78
|
-
page.append(toolbar)
|
|
79
|
-
for (const section of view.sections) {
|
|
80
|
-
const group = this.element('div', undefined, 'native-section')
|
|
81
|
-
group.dataset.section = section.id
|
|
82
|
-
if (section.title) group.append(this.element('h3', section.title))
|
|
83
|
-
const items = this.element('div', undefined, 'native-' + section.layout)
|
|
84
|
-
const refs = section.items.map(item => item.ref)
|
|
85
|
-
for (const item of section.items) {
|
|
86
|
-
const card = this.element('div', undefined, 'native-item')
|
|
87
|
-
const content = this.element('div', undefined, 'native-item-content')
|
|
88
|
-
const artwork = item.playlist?.artworkUrl ?? item.metadata?.artworkUrl ?? item.chart?.artworkUrl
|
|
89
|
-
if (typeof artwork === 'string' && /^(https?:\/\/|data:image\/)/i.test(artwork)) {
|
|
90
|
-
const image = this.element('img', '', 'native-artwork')
|
|
91
|
-
image.src = artwork
|
|
92
|
-
image.alt = ''
|
|
93
|
-
image.loading = 'lazy'
|
|
94
|
-
image.referrerPolicy = 'no-referrer'
|
|
95
|
-
content.append(image)
|
|
96
|
-
}
|
|
97
|
-
const details = this.element('div', undefined, 'native-item-details')
|
|
98
|
-
const title = section.onOpen
|
|
99
|
-
? this.button(item.title, section.onOpen, { ref: item.ref })
|
|
100
|
-
: this.element('strong', item.title)
|
|
101
|
-
title.classList.add('native-item-title')
|
|
102
|
-
details.append(title)
|
|
103
|
-
const subtitle = item.subtitle ?? item.playlist?.description ?? item.metadata?.artists.join(' / ')
|
|
104
|
-
if (subtitle) details.append(this.element('p', subtitle, 'hint'))
|
|
105
|
-
if (item.playlist?.trackCount !== undefined)
|
|
106
|
-
details.append(this.element('small', item.playlist.trackCount + ' 首', 'hint'))
|
|
107
|
-
content.append(details)
|
|
108
|
-
card.append(content)
|
|
109
|
-
const buttons = this.element('div', undefined, 'native-actions')
|
|
110
|
-
if (section.onPlay) buttons.append(this.button('播放', section.onPlay, { ref: item.ref, refs }))
|
|
111
|
-
for (const action of section.itemActions ?? []) {
|
|
112
|
-
const input = action.input && typeof action.input === 'object' && !Array.isArray(action.input)
|
|
113
|
-
? action.input : {}
|
|
114
|
-
buttons.append(this.button(action.label, action.action, { ...input, ref: item.ref }, action.primary))
|
|
115
|
-
}
|
|
116
|
-
card.append(buttons)
|
|
117
|
-
items.append(card)
|
|
118
|
-
}
|
|
119
|
-
if (!section.items.length) items.append(this.element('p', '暂无内容', 'empty'))
|
|
120
|
-
group.append(items)
|
|
121
|
-
page.append(group)
|
|
122
|
-
}
|
|
123
|
-
this.container.replaceChildren(page)
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** Existing Host playlist page, with native plugin sections following local/cloud lists. */
|
|
128
|
-
export class PlaylistPagePreview {
|
|
129
|
-
constructor(container, manifest, dispatch, onError = () => {}) {
|
|
130
|
-
this.container = container
|
|
131
|
-
this.manifest = manifest
|
|
132
|
-
this.dispatch = dispatch
|
|
133
|
-
this.onError = onError
|
|
134
|
-
this.previews = new Map()
|
|
135
|
-
this.closed = false
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async open(sectionId) {
|
|
139
|
-
const doc = this.container.ownerDocument
|
|
140
|
-
const page = doc.createElement('div')
|
|
141
|
-
page.className = 'host-playlist-page'
|
|
142
|
-
const heading = doc.createElement('h2')
|
|
143
|
-
heading.textContent = '歌单'
|
|
144
|
-
page.append(heading)
|
|
145
|
-
for (const title of ['本地歌单', '云歌单']) {
|
|
146
|
-
const section = doc.createElement('section')
|
|
147
|
-
const label = doc.createElement('h3')
|
|
148
|
-
label.textContent = title
|
|
149
|
-
const empty = doc.createElement('p')
|
|
150
|
-
empty.className = 'hint'
|
|
151
|
-
empty.textContent = '独立开发 Host 暂无' + title
|
|
152
|
-
section.append(label, empty)
|
|
153
|
-
page.append(section)
|
|
154
|
-
}
|
|
155
|
-
const actions = new Set(this.manifest.contributes?.commands?.map(command => command.action))
|
|
156
|
-
const openings = []
|
|
157
|
-
let selected
|
|
158
|
-
for (const contribution of [...(this.manifest.contributes?.playlistSections ?? [])].sort((a, b) => (a.order ?? 0) - (b.order ?? 0))) {
|
|
159
|
-
const surface = this.manifest.modules.surfaces?.find(surface => surface.id === contribution.view)
|
|
160
|
-
if (surface?.kind !== 'native') throw new Error('Playlist section requires a native view')
|
|
161
|
-
const section = doc.createElement('section')
|
|
162
|
-
section.dataset.playlistSection = contribution.id
|
|
163
|
-
const title = doc.createElement('h3')
|
|
164
|
-
title.textContent = contribution.title
|
|
165
|
-
const content = doc.createElement('div')
|
|
166
|
-
section.append(title, content)
|
|
167
|
-
page.append(section)
|
|
168
|
-
const session = new SurfaceSession(surface, this.manifest, this.dispatch)
|
|
169
|
-
const preview = new NativeSurfacePreview(content, session, actions, this.onError)
|
|
170
|
-
this.previews.set(contribution.id, { surfaceId: surface.id, preview })
|
|
171
|
-
openings.push(preview.open())
|
|
172
|
-
if (contribution.id === sectionId) {
|
|
173
|
-
selected = section
|
|
174
|
-
section.classList.add('is-target')
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
this.container.replaceChildren(page)
|
|
178
|
-
await Promise.all(openings)
|
|
179
|
-
if (!this.closed) selected?.scrollIntoView({ block: 'start' })
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async refresh(surfaceId) {
|
|
183
|
-
if (this.closed) return
|
|
184
|
-
await Promise.all([...this.previews.values()]
|
|
185
|
-
.filter(item => item.surfaceId === surfaceId)
|
|
186
|
-
.map(item => item.preview.refresh()))
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
async close() {
|
|
190
|
-
if (this.closed) return
|
|
191
|
-
this.closed = true
|
|
192
|
-
const items = [...this.previews.values()]
|
|
193
|
-
this.previews.clear()
|
|
194
|
-
for (const { preview } of items) preview.dispose()
|
|
195
|
-
await Promise.all(items.map(({ preview }) => preview.session.close()))
|
|
196
|
-
}
|
|
197
|
-
}
|