XiaoDaiGua-Ray 22dfe441e0
feat(layout): add a composable workspace designer
Add layout registration, visual editing, and source generation.

Preserve embedded pages and wait for asynchronous layout renderers.

Add workspace lint and formatting commands.
2026-12-01 17:34:27 +08:00

61 lines
2.1 KiB
TypeScript

import { useI18n } from '@/hooks'
import { useSettingActions, useSettingGetters } from '@/store'
import { getDefaultSettingConfig } from '@/store/modules/setting/constant'
import { LAYOUT_MODES, LayoutSettings } from '@ray-template/admin-shell'
import { layoutHostKey } from '../host-context'
import { useLayout } from '../useLayout'
export default defineComponent({
name: 'LayoutSettings',
props: { showDescription: Boolean },
setup(props) {
const { t } = useI18n('layout')
const { layouts, activeLayoutId, updateLayout } = useLayout()
const { getLayoutConfig, getLocaleLanguage } = useSettingGetters()
const { updateSettingState } = useSettingActions()
const host = inject(layoutHostKey, null)
return () => (
<LayoutSettings
showDescription={props.showDescription}
selectionNotice={
host?.deferredFromId.value ? t('deferredForEmbed') : void 0
}
selectedId={
host?.deferredFromId.value ??
(host?.draftRenderer.value ? '' : activeLayoutId.value)
}
onSelect={(id) => {
if (updateLayout(id) && host) host.draftRenderer.value = void 0
}}
choices={layouts.value.map((definition) => {
const mode = LAYOUT_MODES.find((id) => id === definition.id)
const label =
typeof definition.label === 'string'
? definition.label
: definition.label[
getLocaleLanguage.value === 'zh-CN' ? 'zh-CN' : 'en-US'
]
return {
id: definition.id,
label,
preview:
definition.preview ?? mode ?? definition.fallbackMode ?? 'side',
disabled: definition.selectable === false,
hint: mode ? t(`modeHint.${mode}`) : void 0,
}
})}
layout={getLayoutConfig.value}
defaults={getDefaultSettingConfig().layoutConfig}
translate={t}
update={(value) => {
updateSettingState('layoutConfig', value)
if (value.mode && host) host.draftRenderer.value = void 0
}}
/>
)
},
})