@shiqianjiang/ceru-plugin-cli 0.3.2 → 0.3.3
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 +2 -0
- package/assets/playground.js +35 -2
- package/assets/sandbox.js +12 -12
- package/assets/style.css +11 -0
- package/package.json +3 -3
- package/schemas/config.schema.json +8 -1
- package/templates/connected-library/js/package.json +2 -2
- package/templates/connected-library/ts/package.json +2 -2
- package/templates/guest-adapter/js/package.json +2 -2
- package/templates/guest-adapter/ts/package.json +2 -2
- package/templates/importer/js/package.json +2 -2
- package/templates/importer/ts/package.json +2 -2
- package/templates/react/js/package.json +2 -2
- package/templates/react/ts/package.json +2 -2
- package/templates/snapshot.json +1 -1
- package/templates/source/js/package.json +2 -2
- package/templates/source/ts/package.json +2 -2
- package/templates/vue/js/package.json +2 -2
- package/templates/vue/ts/package.json +2 -2
- package/templates/vue-tsx/js/package.json +2 -2
- package/templates/vue-tsx/ts/package.json +2 -2
- package/templates/web-dist/js/package.json +2 -2
- package/templates/web-dist/ts/package.json +2 -2
- package/templates/web-surface/js/package.json +2 -2
- package/templates/web-surface/ts/package.json +2 -2
package/README.md
CHANGED
package/assets/playground.js
CHANGED
|
@@ -17,12 +17,14 @@ let state,
|
|
|
17
17
|
currentInvocation
|
|
18
18
|
let viewSession
|
|
19
19
|
let nativePreview
|
|
20
|
+
let viewMountInfo
|
|
20
21
|
let viewTransition = Promise.resolve()
|
|
21
22
|
const frames = new Map(),
|
|
22
23
|
calls = new Map(),
|
|
23
24
|
registrations = new Map(),
|
|
24
25
|
surfaceStates = new Map()
|
|
25
26
|
const accountButtons = new Map()
|
|
27
|
+
const accountLogoutButtons = new Map()
|
|
26
28
|
const api = async (path, data) => {
|
|
27
29
|
const response = await fetch('/api/' + path, {
|
|
28
30
|
method: data === undefined ? 'GET' : 'POST',
|
|
@@ -352,6 +354,13 @@ function showView(id, mountInfo = { kind: 'page' }) {
|
|
|
352
354
|
viewTransition = viewTransition.catch(() => {}).then(async () => {
|
|
353
355
|
await closeView()
|
|
354
356
|
if (stopped) return
|
|
357
|
+
viewMountInfo = mountInfo
|
|
358
|
+
const logicEntry = state.manifest.modules.logic?.entry
|
|
359
|
+
if (logicEntry && !frames.get(logicEntry)?.active) {
|
|
360
|
+
viewId = id
|
|
361
|
+
$('preview').textContent = '正在启动插件…'
|
|
362
|
+
return
|
|
363
|
+
}
|
|
355
364
|
mountView(id, mountInfo)
|
|
356
365
|
})
|
|
357
366
|
return viewTransition.catch(error => log('error', error.message))
|
|
@@ -411,13 +420,31 @@ function drawStatic() {
|
|
|
411
420
|
state.manifest.id + ' · v' + state.manifest.version + ' · revision ' + revision
|
|
412
421
|
$('views').replaceChildren()
|
|
413
422
|
accountButtons.clear()
|
|
423
|
+
accountLogoutButtons.clear()
|
|
414
424
|
for (const account of state.manifest.contributes?.accountItems ?? []) {
|
|
425
|
+
const item = document.createElement('div')
|
|
426
|
+
item.className = 'account-item'
|
|
415
427
|
const button = document.createElement('button')
|
|
416
428
|
button.textContent = '账号 · ' + account.title
|
|
417
429
|
button.onclick = () => showView(account.view)
|
|
418
430
|
button.disabled = true
|
|
419
431
|
accountButtons.set(account.id, button)
|
|
420
|
-
|
|
432
|
+
item.append(button)
|
|
433
|
+
if (account.logoutAction) {
|
|
434
|
+
const logout = document.createElement('button')
|
|
435
|
+
logout.textContent = '退出登录'
|
|
436
|
+
logout.className = 'account-logout'
|
|
437
|
+
logout.hidden = true
|
|
438
|
+
logout.onclick = async () => {
|
|
439
|
+
logout.disabled = true
|
|
440
|
+
try { await runAction(account.logoutAction); await refreshAccountItems(account.view) }
|
|
441
|
+
catch (error) { log('error', error.message) }
|
|
442
|
+
finally { logout.disabled = false }
|
|
443
|
+
}
|
|
444
|
+
accountLogoutButtons.set(account.id, logout)
|
|
445
|
+
item.append(logout)
|
|
446
|
+
}
|
|
447
|
+
$('views').append(item)
|
|
421
448
|
}
|
|
422
449
|
for (const view of [
|
|
423
450
|
...(state.manifest.modules.surfaces || []),
|
|
@@ -550,6 +577,8 @@ async function refreshAccountItems(surfaceId) {
|
|
|
550
577
|
assertAccountSummary(summary)
|
|
551
578
|
button.textContent = '账号 · ' + summary.displayName + (summary.badge ? ' · ' + summary.badge : '')
|
|
552
579
|
button.disabled = false
|
|
580
|
+
const logout = accountLogoutButtons.get(account.id)
|
|
581
|
+
if (logout) logout.hidden = !summary.signedIn
|
|
553
582
|
} catch (error) {
|
|
554
583
|
button.textContent = '账号 · ' + account.title
|
|
555
584
|
button.disabled = false
|
|
@@ -585,7 +614,7 @@ window.addEventListener('message', async (event) => {
|
|
|
585
614
|
void frame.session.open().catch(error => log('error', error.message))
|
|
586
615
|
} else if (frame.kind === 'logic') {
|
|
587
616
|
void refreshAccountItems()
|
|
588
|
-
if (viewId) void showView(viewId)
|
|
617
|
+
if (viewId) void showView(viewId, viewMountInfo)
|
|
589
618
|
}
|
|
590
619
|
}
|
|
591
620
|
if (message.type === 'failed') {
|
|
@@ -601,6 +630,10 @@ window.addEventListener('message', async (event) => {
|
|
|
601
630
|
if (message.type === 'log') log(data.level, data.values)
|
|
602
631
|
if (message.type === 'notify') log(data.level, data.message)
|
|
603
632
|
if (message.type === 'open-view' && frame.kind === 'logic') void showView(data.surfaceId)
|
|
633
|
+
if (message.type === 'close-view' &&
|
|
634
|
+
((frame.kind === 'logic' && data.surfaceId === viewId) ||
|
|
635
|
+
(frame.kind === 'web' && frame.surfaceId === viewId)))
|
|
636
|
+
void closeView().catch(error => log('error', error.message))
|
|
604
637
|
if (message.type === 'register') {
|
|
605
638
|
if (frame.kind !== 'logic') return
|
|
606
639
|
const valid =
|