mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-05-21 22:02:15 +08:00
fix(editor): 修复初始dsl无codeBlocks字段时无法新增的问题
This commit is contained in:
parent
caa47823be
commit
3bb8ecc975
@ -61,8 +61,8 @@ class App extends EventEmitter {
|
||||
super();
|
||||
|
||||
this.env = new Env(options.ua);
|
||||
// 代码块描述内容在dsl codeBlock字段
|
||||
this.codeDsl = options.config?.codeBlock;
|
||||
// 代码块描述内容在dsl codeBlocks字段
|
||||
this.codeDsl = options.config?.codeBlocks;
|
||||
options.platform && (this.platform = options.platform);
|
||||
options.jsEngine && (this.jsEngine = options.jsEngine);
|
||||
options.designWidth && (this.designWidth = options.designWidth);
|
||||
@ -141,7 +141,7 @@ class App extends EventEmitter {
|
||||
* @param curPage 当前页面id
|
||||
*/
|
||||
public setConfig(config: MApp, curPage?: Id) {
|
||||
this.codeDsl = config.codeBlock;
|
||||
this.codeDsl = config.codeBlocks;
|
||||
this.pages = new Map();
|
||||
config.items?.forEach((page) => {
|
||||
this.pages.set(
|
||||
|
@ -69,7 +69,7 @@ class CodeBlock extends BaseService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取活动的代码块dsl数据源(默认从dsl中的codeBlock字段读取)
|
||||
* 获取活动的代码块dsl数据源(默认从dsl中的codeBlocks字段读取)
|
||||
* @param {boolean} forceRefresh 是否强制从活动dsl拉取刷新
|
||||
* @returns {CodeBlockDSL | null}
|
||||
*/
|
||||
@ -100,7 +100,12 @@ class CodeBlock extends BaseService {
|
||||
*/
|
||||
public async setCodeDslById(id: string, codeConfig: CodeBlockContent): Promise<void> {
|
||||
let codeDsl = await this.getCodeDsl();
|
||||
if (!codeDsl) return;
|
||||
if (!codeDsl) {
|
||||
// dsl中无代码块字段
|
||||
codeDsl = {
|
||||
[id]: codeConfig,
|
||||
};
|
||||
} else {
|
||||
const existContent = codeDsl[id] || {};
|
||||
codeDsl = {
|
||||
...codeDsl,
|
||||
@ -109,6 +114,7 @@ class CodeBlock extends BaseService {
|
||||
...codeConfig,
|
||||
},
|
||||
};
|
||||
}
|
||||
await this.setCodeDsl(codeDsl);
|
||||
}
|
||||
|
||||
|
@ -767,23 +767,23 @@ class Editor extends BaseService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 从dsl中的codeBlock字段读取活动的代码块
|
||||
* 从dsl中的codeBlocks字段读取活动的代码块
|
||||
* @returns {CodeBlockDSL | null}
|
||||
*/
|
||||
public async getCodeDsl(): Promise<CodeBlockDSL | null> {
|
||||
const root = this.get<MApp | null>('root');
|
||||
if (!root) return null;
|
||||
return root.codeBlock || null;
|
||||
return root.codeBlocks || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置代码块到dsl的codeBlock字段
|
||||
* 设置代码块到dsl的codeBlocks字段
|
||||
* @param {CodeBlockDSL} codeDsl 代码DSL
|
||||
* @returns {void}
|
||||
*/
|
||||
public async setCodeDsl(codeDsl: CodeBlockDSL): Promise<void> {
|
||||
if (!this.state.root) return;
|
||||
this.state.root.codeBlock = codeDsl;
|
||||
this.state.root.codeBlocks = codeDsl;
|
||||
}
|
||||
|
||||
private addModifiedNodeId(id: Id) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user