roymondchen 94fae10ae0 feat(editor): 新增 SDK 层并将核心服务迁移至 sdk 目录
- 新增 packages/editor/src/sdk,通过 sdk.ts 对外导出
- 将 services 下的核心服务迁移至 sdk/services
- 工具函数拆分至 sdk/utils,校验逻辑迁移至 sdk/validate,新增 sdk/wiring
- services/sdk-instance.ts 负责在编辑器中实例化 SDK
- 补充 SDK 相关单元测试,新增 docs/api/editor/sdk.md 文档
2026-10-08 19:58:03 +08:00

41 lines
1.0 KiB
TypeScript

import type { MApp } from '@tmagic/core';
import type { SdkOptions } from '@editor/sdk';
import { createDslSdk } from '@editor/sdk';
export const createDsl = (): MApp =>
({
id: 'app_1',
type: 'app',
items: [
{
id: 'page_1',
type: 'page',
name: 'page',
items: [
{ id: 'text_1', type: 'text', text: '${ds_1.name}' },
{ id: 'container_1', type: 'container', items: [{ id: 'button_1', type: 'button', text: 'btn' }] },
],
},
],
dataSources: [{ id: 'ds_1', type: 'base', title: 'ds', fields: [{ name: 'name' }], methods: [], events: [] }],
codeBlocks: { code_1: { name: 'code', content: '() => {}', params: [] } },
}) as any;
export const COMPONENT_GROUP_LIST = [
{
title: '基础',
items: [
{ text: '文本', type: 'text' },
{ text: '按钮', type: 'button' },
],
},
];
export const createSdk = (options: SdkOptions = {}) =>
createDslSdk({
dsl: createDsl(),
componentGroupList: COMPONENT_GROUP_LIST,
...options,
});