fix(amis-saas-2815): 优化addChild方法

Change-Id: If016b68cdf7f8d3b7e42170ac5af89b411d0266c
This commit is contained in:
wibetter 2023-01-05 10:42:27 +08:00
parent 4e67c09731
commit 45cf1ff60d
3 changed files with 26 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"name": "amis-editor-core",
"version": "5.2.3-beta.13",
"version": "5.2.3-beta.15",
"description": "amis 可视化编辑器",
"main": "lib/index.js",
"module": "esm/index.js",

View File

@ -43,6 +43,7 @@ import {
guid,
reactionWithOldValue,
reGenerateID,
JsonGenerateID,
isString,
isObject,
isLayoutPlugin,
@ -63,7 +64,7 @@ import {EditorDNDManager} from './dnd';
import {IScopedContext} from 'amis';
import {SchemaObject, SchemaCollection} from 'amis/lib/Schema';
import type {RendererConfig} from 'amis-core/lib/factory';
import {isPlainObject} from 'lodash';
import isPlainObject from 'lodash/isPlainObject';
export interface EditorManagerConfig
extends Omit<EditorProps, 'value' | 'onChange'> {}
@ -1370,11 +1371,8 @@ export class EditorManager {
let index: number = -1;
const commonContext = this.buildEventContext(id);
// 填充id有些脚手架生成了复杂的布局等这里都填充一下id
if (isPlainObject(json) && json.type && !json.id) {
json = {...json, id: 'u:' + guid()};
json = reGenerateID(json);
}
// 填充id有些脚手架生成了复杂的布局等自动填充一下id
JsonGenerateID(json);
if (beforeId) {
const arr = commonContext.schema[region];

View File

@ -556,6 +556,27 @@ export function reGenerateID(
return json;
}
// 遍历json每层元素自动生成uid。
export function JsonGenerateID(json: any) {
if (Array.isArray(json)) {
json.map((item: any) => JsonGenerateID(item));
}
if (!isObject(json) || isObservable(json)) {
return;
}
if (json.type && !json.id) {
json.id = generateNodeId();
}
Object.keys(json).forEach(key => {
let curElem = json[key];
if (isObject(curElem) || Array.isArray(curElem)) {
JsonGenerateID(curElem);
}
});
}
export function createElementFromHTML(htmlString: string): HTMLElement {
var div = document.createElement('div');
// bca-disable-next-line