dsh-brain/src-client/index.ts

53 lines
1.7 KiB
TypeScript

// dsh-brain client bundle entry — the __ModuleLoader__ module contract.
import * as React from 'react'
import { messageOf } from './api'
import { CardBoundary } from './components'
import { SettingsCard } from './SettingsCard'
import { SettingsSummaryCard } from './SettingsSummaryCard'
import { registerBrainPanel } from './panel/register'
const h = React.createElement
export const inject = ['slots']
export function apply(ctx: any): void {
const summaryCard = function () {
return h(CardBoundary as any, null, h(SettingsSummaryCard as any, { ctx }))
}
// The plugin bundle config page keeps the full settings card; the generic
// settings section is now only the status summary with a jump button.
const configCard = function () {
return h(CardBoundary as any, null, h(SettingsCard as any, null))
}
const register = function (seat: string, options: any, component: any) {
try {
ctx.slots.inject(seat, function () {
return ctx.slots.register(options, component)
})
} catch (failure) {
if (typeof console !== 'undefined') console.warn('[dsh-brain] slot ' + seat + ' unavailable: ' + messageOf(failure))
}
}
register('plugins.bundle.config', { name: 'plugins.bundle.config', key: 'dsh-brain' }, configCard)
register('settings.section', {
name: 'settings.section',
id: 'dsh-brain',
order: 100,
label: function () {
return '云端记忆'
},
}, summaryCard)
try {
if (typeof ctx.effect === 'function') ctx.effect(() => registerBrainPanel(ctx), 'dsh-brain: panel')
else registerBrainPanel(ctx)
} catch (failure) {
if (typeof console !== 'undefined') console.warn('[dsh-brain] panel registration failed: ' + messageOf(failure))
}
}
export const name = 'dsh-brain'