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();
|
super();
|
||||||
|
|
||||||
this.env = new Env(options.ua);
|
this.env = new Env(options.ua);
|
||||||
// 代码块描述内容在dsl codeBlock字段
|
// 代码块描述内容在dsl codeBlocks字段
|
||||||
this.codeDsl = options.config?.codeBlock;
|
this.codeDsl = options.config?.codeBlocks;
|
||||||
options.platform && (this.platform = options.platform);
|
options.platform && (this.platform = options.platform);
|
||||||
options.jsEngine && (this.jsEngine = options.jsEngine);
|
options.jsEngine && (this.jsEngine = options.jsEngine);
|
||||||
options.designWidth && (this.designWidth = options.designWidth);
|
options.designWidth && (this.designWidth = options.designWidth);
|
||||||
@ -141,7 +141,7 @@ class App extends EventEmitter {
|
|||||||
* @param curPage 当前页面id
|
* @param curPage 当前页面id
|
||||||
*/
|
*/
|
||||||
public setConfig(config: MApp, curPage?: Id) {
|
public setConfig(config: MApp, curPage?: Id) {
|
||||||
this.codeDsl = config.codeBlock;
|
this.codeDsl = config.codeBlocks;
|
||||||
this.pages = new Map();
|
this.pages = new Map();
|
||||||
config.items?.forEach((page) => {
|
config.items?.forEach((page) => {
|
||||||
this.pages.set(
|
this.pages.set(
|
||||||
|
@ -69,7 +69,7 @@ class CodeBlock extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取活动的代码块dsl数据源(默认从dsl中的codeBlock字段读取)
|
* 获取活动的代码块dsl数据源(默认从dsl中的codeBlocks字段读取)
|
||||||
* @param {boolean} forceRefresh 是否强制从活动dsl拉取刷新
|
* @param {boolean} forceRefresh 是否强制从活动dsl拉取刷新
|
||||||
* @returns {CodeBlockDSL | null}
|
* @returns {CodeBlockDSL | null}
|
||||||
*/
|
*/
|
||||||
@ -100,15 +100,21 @@ class CodeBlock extends BaseService {
|
|||||||
*/
|
*/
|
||||||
public async setCodeDslById(id: string, codeConfig: CodeBlockContent): Promise<void> {
|
public async setCodeDslById(id: string, codeConfig: CodeBlockContent): Promise<void> {
|
||||||
let codeDsl = await this.getCodeDsl();
|
let codeDsl = await this.getCodeDsl();
|
||||||
if (!codeDsl) return;
|
if (!codeDsl) {
|
||||||
const existContent = codeDsl[id] || {};
|
// dsl中无代码块字段
|
||||||
codeDsl = {
|
codeDsl = {
|
||||||
...codeDsl,
|
[id]: codeConfig,
|
||||||
[id]: {
|
};
|
||||||
...existContent,
|
} else {
|
||||||
...codeConfig,
|
const existContent = codeDsl[id] || {};
|
||||||
},
|
codeDsl = {
|
||||||
};
|
...codeDsl,
|
||||||
|
[id]: {
|
||||||
|
...existContent,
|
||||||
|
...codeConfig,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
await this.setCodeDsl(codeDsl);
|
await this.setCodeDsl(codeDsl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -767,23 +767,23 @@ class Editor extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从dsl中的codeBlock字段读取活动的代码块
|
* 从dsl中的codeBlocks字段读取活动的代码块
|
||||||
* @returns {CodeBlockDSL | null}
|
* @returns {CodeBlockDSL | null}
|
||||||
*/
|
*/
|
||||||
public async getCodeDsl(): Promise<CodeBlockDSL | null> {
|
public async getCodeDsl(): Promise<CodeBlockDSL | null> {
|
||||||
const root = this.get<MApp | null>('root');
|
const root = this.get<MApp | null>('root');
|
||||||
if (!root) return null;
|
if (!root) return null;
|
||||||
return root.codeBlock || null;
|
return root.codeBlocks || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置代码块到dsl的codeBlock字段
|
* 设置代码块到dsl的codeBlocks字段
|
||||||
* @param {CodeBlockDSL} codeDsl 代码DSL
|
* @param {CodeBlockDSL} codeDsl 代码DSL
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
public async setCodeDsl(codeDsl: CodeBlockDSL): Promise<void> {
|
public async setCodeDsl(codeDsl: CodeBlockDSL): Promise<void> {
|
||||||
if (!this.state.root) return;
|
if (!this.state.root) return;
|
||||||
this.state.root.codeBlock = codeDsl;
|
this.state.root.codeBlocks = codeDsl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private addModifiedNodeId(id: Id) {
|
private addModifiedNodeId(id: Id) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user