57 lines
2.0 KiB
TypeScript
57 lines
2.0 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 { registerBrainPanel } from './panel/register'
|
|
import { mountBrainSidebarTab } from './sidebar/register'
|
|
import { MnemonBundleSettings, mountMnemonWorkbench } from './mnemon-workbench'
|
|
|
|
const h = React.createElement
|
|
|
|
export const inject = ['slots']
|
|
|
|
export function apply(ctx: any): void {
|
|
const configCard = function (props?: { view?: string }) {
|
|
return h(CardBoundary as any, null, h(SettingsCard as any, null),
|
|
props?.view === 'page' ? h(MnemonBundleSettings, { ctx }) : 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 '云端记忆'
|
|
},
|
|
}, configCard)
|
|
|
|
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))
|
|
}
|
|
try {
|
|
if (typeof ctx.effect === 'function') ctx.effect(() => mountBrainSidebarTab(ctx), 'dsh-brain: project memory sidebar')
|
|
else mountBrainSidebarTab(ctx)
|
|
} catch (failure) {
|
|
if (typeof console !== 'undefined') console.warn('[dsh-brain] project memory sidebar registration failed: ' + messageOf(failure))
|
|
}
|
|
mountMnemonWorkbench(ctx)
|
|
}
|
|
|
|
export const name = 'dsh-brain'
|