refactor: 兼容 type: group 为 i18n 时的场景, 比如 CascadeDateField

fix: 乐高回滚异常
This commit is contained in:
力皓 2020-10-20 17:55:52 +08:00
parent a5a5407a9f
commit 9775087310
5 changed files with 13 additions and 6 deletions

View File

@ -274,7 +274,7 @@ export class DocumentModel {
if (!node) { if (!node) {
return; return;
} }
this.internalRemoveAndPurgeNode(node); this.internalRemoveAndPurgeNode(node, true);
} }
/** /**

View File

@ -110,6 +110,7 @@ export class Project {
return; return;
} }
this.documents.splice(index, 1); this.documents.splice(index, 1);
this.documentsMap.delete(doc.id);
} }
/** /**
@ -159,8 +160,10 @@ export class Project {
private documentsMap = new Map<string, DocumentModel>(); private documentsMap = new Map<string, DocumentModel>();
getDocument(id: string): DocumentModel | null { getDocument(id: string): DocumentModel | null {
return this.documentsMap.get(id) || null; // 此处不能使用 this.documentsMap.get(id),因为在乐高 rollback 场景document.id 会被改成其他值
return this.documents.find(doc => doc.id === id) || null;
} }
createDocument(data?: RootSchema): DocumentModel { createDocument(data?: RootSchema): DocumentModel {

View File

@ -1,5 +1,5 @@
import { isJSBlock, isJSExpression, isJSSlot } from '@ali/lowcode-types'; import { isJSBlock, isJSExpression, isJSSlot } from '@ali/lowcode-types';
import { isPlainObject, hasOwnProperty, cloneDeep, isI18NObject, isUseI18NSetter, convertToI18NObject } from '@ali/lowcode-utils'; import { isPlainObject, hasOwnProperty, cloneDeep, isI18NObject, isUseI18NSetter, convertToI18NObject, isString } from '@ali/lowcode-utils';
import { globalContext, Editor } from '@ali/lowcode-editor-core'; import { globalContext, Editor } from '@ali/lowcode-editor-core';
import { Designer, LiveEditing, TransformStage, Node, getConvertedExtraKey } from '@ali/lowcode-designer'; import { Designer, LiveEditing, TransformStage, Node, getConvertedExtraKey } from '@ali/lowcode-designer';
import Outline, { OutlineBackupPane, getTreeMaster } from '@ali/lowcode-plugin-outline-pane'; import Outline, { OutlineBackupPane, getTreeMaster } from '@ali/lowcode-plugin-outline-pane';
@ -126,7 +126,8 @@ designer.addPropsReducer((props, node) => {
!isJSExpression(ov) && !isJSExpression(ov) &&
!isJSBlock(ov) && !isJSBlock(ov) &&
!isJSSlot(ov) && !isJSSlot(ov) &&
!isVariable(ov)) { !isVariable(ov) &&
isString(v)) {
newProps[item.name] = convertToI18NObject(v); newProps[item.name] = convertToI18NObject(v);
} }
} catch (e) { } catch (e) {

View File

@ -53,6 +53,5 @@
}, },
"publishConfig": { "publishConfig": {
"registry": "http://registry.npm.alibaba-inc.com" "registry": "http://registry.npm.alibaba-inc.com"
}, }
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@0.13.1-2/build/index.html"
} }

View File

@ -15,3 +15,7 @@ export function convertToI18NObject(v: string | object, locale: string = 'zh_CN'
if (isI18NObject(v)) return v; if (isI18NObject(v)) return v;
return { type: 'i18n', use: locale, [locale]: v }; return { type: 'i18n', use: locale, [locale]: v };
} }
export function isString(v: any): v is string {
return typeof v === 'string';
}