fix(editor): 移除 removeStyleDisplayConfig 并取消属性 tab 懒加载

对比/只读表单直接返回 getPropsConfig 结果,样式/事件/高级 tab 不再使用 lazy 懒加载。
This commit is contained in:
roymondchen 2026-08-10 20:13:06 +08:00
parent 44cd3d480f
commit 8550e6f854
4 changed files with 15 additions and 89 deletions

View File

@ -23,7 +23,6 @@ import { type FormConfig, type FormState, type FormValue, MForm } from '@tmagic/
import type { CompareFormBaseProps } from '@editor/type';
import { getCodeBlockFormConfig } from '@editor/utils/code-block';
import { removeStyleDisplayConfig } from '@editor/utils/props';
export interface UseCompareFormReturn {
config: Ref<FormConfig>;
@ -107,9 +106,7 @@ export const useCompareForm = (props: CompareFormBaseProps): UseCompareFormRetur
if (!props.type) {
return [];
}
return removeStyleDisplayConfig(
await props.services.propsService.getPropsConfig(props.type, { node: props.value as unknown as MNode }),
);
return props.services.propsService.getPropsConfig(props.type, { node: props.value as unknown as MNode });
}
case 'data-source': {
const config = props.services.dataSourceService.getFormConfig(props.type || 'base');

View File

@ -73,7 +73,6 @@ export const getCondOpOptionsByFieldType = (type: string) => {
export const styleTabConfig: TabPaneConfig = {
title: '样式',
lazy: true,
display: ({ services }: any) => !(services?.uiService?.get('showStylePanel') ?? true),
items: [
{
@ -146,7 +145,6 @@ export const styleTabConfig: TabPaneConfig = {
export const eventTabConfig: TabPaneConfig = {
title: '事件',
lazy: true,
items: [
{
name: 'events',
@ -160,7 +158,6 @@ export const eventTabConfig: TabPaneConfig = {
export const advancedTabConfig: TabPaneConfig = {
title: '高级',
lazy: true,
items: [
{
name: NODE_DISABLE_CODE_BLOCK_KEY,
@ -360,32 +357,3 @@ export const fillConfig = (
return [tabConfig];
};
/**
* tab-pane `display` `true`
*
* `propsService.getPropsConfig` tab
* `display: ({ services }) => !(services?.uiService?.get('showStylePanel') ?? true)`
* / CompareForm / ViewForm uiService
* tab
*
* @param formConfig
* @returns
*/
export const removeStyleDisplayConfig = (formConfig: FormConfig): FormConfig =>
formConfig.map((item) => {
if (!('type' in item)) return item;
if (item?.type !== 'tab' || !Array.isArray(item.items)) return item;
return {
...item,
items: item.items.map((tabPane) => {
if (tabPane?.title !== '样式' || !Array.isArray(tabPane.items)) return tabPane;
return {
...tabPane,
display: true,
};
}),
};
});

View File

@ -81,14 +81,18 @@ describe('useCompareForm', () => {
expect(captured.config.value).toEqual([]);
});
test('node 类别加载 props 配置并把「样式」tab display 置为 true', async () => {
test('node 类别加载 props 配置并原样返回 getPropsConfig 结果', async () => {
const { captured } = mountHook({ category: 'node', type: 'text', value: { id: 'n1' }, services });
await nextTick();
await nextTick();
expect(propsService.getPropsConfig).toHaveBeenCalledWith('text', { node: { id: 'n1' } });
const tab = captured.config.value.find((i: any) => i.type === 'tab');
const stylePane = tab.items.find((p: any) => p.title === '样式');
expect(stylePane.display).toBe(true);
expect(captured.config.value).toEqual([
{
type: 'tab',
items: [{ title: '样式', items: [{ type: 'text', name: 'color', display: false }] }],
},
{ type: 'text', name: 'name' },
]);
});
test('node 类别缺少 type 时返回空配置', async () => {

View File

@ -17,7 +17,6 @@ import {
fillConfig,
getCondOpOptionsByFieldType,
numberOptions,
removeStyleDisplayConfig,
styleTabConfig,
} from '@editor/utils/props';
@ -66,6 +65,12 @@ describe('props 选项常量', () => {
expect(displayTabConfig.title).toBe('显示条件');
});
test('styleTabConfig / eventTabConfig / advancedTabConfig 不使用 lazy 懒加载', () => {
expect(styleTabConfig.lazy).toBeUndefined();
expect(eventTabConfig.lazy).toBeUndefined();
expect(advancedTabConfig.lazy).toBeUndefined();
});
test('advancedTabConfig 中包含 created/mounted/display', () => {
const names = (advancedTabConfig.items as any[]).map((i) => i.name);
expect(names).toEqual(expect.arrayContaining(['created', 'mounted', 'display']));
@ -169,51 +174,3 @@ describe('fillConfig', () => {
});
});
});
describe('removeStyleDisplayConfig', () => {
test('将 tab 内「样式」pane 的 display 置为 true', () => {
const config = [
{
type: 'tab',
items: [
{ title: '属性', items: [{ name: 'a' }] },
{ title: '样式', display: false, items: [{ name: 'color' }] },
],
},
] as any;
const result = removeStyleDisplayConfig(config) as any;
const stylePane = result[0].items.find((i: any) => i.title === '样式');
expect(stylePane.display).toBe(true);
// 非样式 pane 保持不变
expect(result[0].items.find((i: any) => i.title === '属性').display).toBeUndefined();
});
test('不修改入参,返回浅拷贝', () => {
const stylePane = { title: '样式', display: false, items: [{ name: 'color' }] };
const config = [{ type: 'tab', items: [stylePane] }] as any;
const result = removeStyleDisplayConfig(config) as any;
expect(result).not.toBe(config);
expect(result[0]).not.toBe(config[0]);
expect(stylePane.display).toBe(false);
});
test('非 tab 项 / 无 items 的项原样返回', () => {
const plain = { name: 'x', type: 'text' };
const tabWithoutItems = { type: 'tab' };
const noType = { foo: 'bar' };
const config = [plain, tabWithoutItems, noType] as any;
const result = removeStyleDisplayConfig(config) as any;
expect(result[0]).toBe(plain);
expect(result[1]).toBe(tabWithoutItems);
expect(result[2]).toBe(noType);
});
test('样式 pane 无 items 数组时不处理', () => {
const config = [{ type: 'tab', items: [{ title: '样式' }] }] as any;
const result = removeStyleDisplayConfig(config) as any;
expect(result[0].items[0].display).toBeUndefined();
});
});