From bf2b359b44dc6aa331f424d6497a9597842f3c3c Mon Sep 17 00:00:00 2001 From: "lihao.ylh" Date: Fri, 26 Nov 2021 13:10:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BA=A7=E8=81=94?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=B1=9E=E6=80=A7=E6=97=B6,=20=E4=B8=AD?= =?UTF-8?q?=E9=97=B4=E5=B1=9E=E6=80=A7=E7=9A=84=E6=9E=84=E9=80=A0=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=80=BC=E4=B8=8D=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/src/document/node/props/prop.ts | 5 ++- .../designer/src/document/node/props/props.ts | 2 +- .../__snapshots__/document-model.test.ts.snap | 38 ++++--------------- .../tests/document/node/node-children.test.ts | 2 +- 4 files changed, 13 insertions(+), 34 deletions(-) diff --git a/packages/designer/src/document/node/props/prop.ts b/packages/designer/src/document/node/props/prop.ts index d6e86792d..5b533df67 100644 --- a/packages/designer/src/document/node/props/prop.ts +++ b/packages/designer/src/document/node/props/prop.ts @@ -234,7 +234,6 @@ export class Prop implements IPropParent { @action setValue(val: CompositeValue) { if (val === this._value) return; - this.dispose(); const editor = this.owner.document?.designer.editor; const oldValue = this._value; this._value = val; @@ -263,6 +262,8 @@ export class Prop implements IPropParent { }; } + this.dispose(); + if (oldValue !== this._value) { const propsInfo = { key: this.key, @@ -450,7 +451,7 @@ export class Prop implements IPropParent { } if (createIfNone) { - prop = new Prop(this, UNSET, entry); + prop = new Prop(this, nest ? {} : UNSET, entry); this.set(entry, prop, true); if (nest) { return prop.get(nest, true); diff --git a/packages/designer/src/document/node/props/props.ts b/packages/designer/src/document/node/props/props.ts index b0c7a082d..66c646217 100644 --- a/packages/designer/src/document/node/props/props.ts +++ b/packages/designer/src/document/node/props/props.ts @@ -202,7 +202,7 @@ export class Props implements IPropParent { let prop = this.maps.get(entry); if (!prop && createIfNone) { - prop = new Prop(this, UNSET, entry); + prop = new Prop(this, nest ? {} : UNSET, entry); this.items.push(prop); } diff --git a/packages/designer/tests/document/document-model/__snapshots__/document-model.test.ts.snap b/packages/designer/tests/document/document-model/__snapshots__/document-model.test.ts.snap index 2620c0a3f..a12a521f6 100644 --- a/packages/designer/tests/document/document-model/__snapshots__/document-model.test.ts.snap +++ b/packages/designer/tests/document/document-model/__snapshots__/document-model.test.ts.snap @@ -79,7 +79,6 @@ Object { "__slot__extraContent": false, "__slot__logo": false, "__slot__tab": false, - "__style__": Object {}, "action": "", "content": "", "crumb": "", @@ -95,7 +94,6 @@ Object { "condition": true, "id": "node_k1ow3cbf", "props": Object { - "__style__": Object {}, "behavior": "NORMAL", "content": Object { "en_US": "Title", @@ -144,7 +142,6 @@ Object { "isLocked": false, "props": Object { "__category__": "form", - "__style__": Object {}, "__useMediator": "value", "addonAfter": Object { "type": "i18n", @@ -177,7 +174,7 @@ Object { "labelTextAlign": "right", "labelTipsIcon": "", "labelTipsText": Object { - "en_US": null, + "en_US": "", "type": "i18n", "use": "zh_CN", "zh_CN": "", @@ -222,7 +219,6 @@ Object { "isLocked": false, "props": Object { "__category__": "form", - "__style__": Object {}, "__useMediator": "value", "addonAfter": Object { "type": "i18n", @@ -255,7 +251,7 @@ Object { "labelTextAlign": "right", "labelTipsIcon": "", "labelTipsText": Object { - "en_US": null, + "en_US": "", "type": "i18n", "use": "zh_CN", "zh_CN": "", @@ -296,7 +292,6 @@ Object { "isLocked": false, "props": Object { "__category__": "form", - "__style__": Object {}, "__useMediator": "value", "addonAfter": Object { "type": "i18n", @@ -329,7 +324,7 @@ Object { "labelTextAlign": "right", "labelTipsIcon": "", "labelTipsText": Object { - "en_US": null, + "en_US": "", "type": "i18n", "use": "zh_CN", "zh_CN": "", @@ -369,7 +364,6 @@ Object { "id": "node_k1ow3cbx", "isLocked": false, "props": Object { - "__style__": Object {}, "colSpan": "", "fieldId": "column_k1p1bnjm", }, @@ -386,7 +380,6 @@ Object { "isLocked": false, "props": Object { "__category__": "form", - "__style__": Object {}, "__useMediator": "value", "addonAfter": Object { "type": "i18n", @@ -419,7 +412,7 @@ Object { "labelTextAlign": "right", "labelTipsIcon": "", "labelTipsText": Object { - "en_US": null, + "en_US": "", "type": "i18n", "use": "zh_CN", "zh_CN": "", @@ -460,7 +453,6 @@ Object { "isLocked": false, "props": Object { "__category__": "form", - "__style__": Object {}, "__useMediator": "value", "autoWidth": true, "behavior": "NORMAL", @@ -509,7 +501,7 @@ Object { "labelTextAlign": "right", "labelTipsIcon": "", "labelTipsText": Object { - "en_US": null, + "en_US": "", "type": "i18n", "use": "zh_CN", "zh_CN": "", @@ -553,7 +545,6 @@ Object { "id": "node_k1ow3cby", "isLocked": false, "props": Object { - "__style__": Object {}, "colSpan": "", "fieldId": "column_k1p1bnjn", }, @@ -567,7 +558,6 @@ Object { "id": "node_k1ow3cbw", "isLocked": false, "props": Object { - "__style__": Object {}, "columnGap": "20", "fieldId": "columns_k1ow3h1v", "layout": "6:6", @@ -638,7 +628,6 @@ Object { "isLocked": false, "props": Object { "__category__": "form", - "__style__": Object {}, "__useMediator": "value", "addonAfter": Object { "type": "i18n", @@ -671,7 +660,7 @@ Object { "labelTextAlign": "right", "labelTipsIcon": "", "labelTipsText": Object { - "en_US": null, + "en_US": "", "type": "i18n", "use": "zh_CN", "zh_CN": "", @@ -716,7 +705,6 @@ Object { "isLocked": false, "props": Object { "__category__": "form", - "__style__": Object {}, "__useMediator": "value", "addonAfter": Object { "type": "i18n", @@ -749,7 +737,7 @@ Object { "labelTextAlign": "right", "labelTipsIcon": "", "labelTipsText": Object { - "en_US": null, + "en_US": "", "type": "i18n", "use": "zh_CN", "zh_CN": "", @@ -789,7 +777,6 @@ Object { "id": "node_k1ow3cc6", "isLocked": false, "props": Object { - "__style__": Object {}, "colSpan": "", "fieldId": "column_k1p1bnjo", }, @@ -806,7 +793,6 @@ Object { "isLocked": false, "props": Object { "__category__": "form", - "__style__": Object {}, "__useMediator": "value", "addonAfter": Object { "type": "i18n", @@ -839,7 +825,7 @@ Object { "labelTextAlign": "right", "labelTipsIcon": "", "labelTipsText": Object { - "en_US": null, + "en_US": "", "type": "i18n", "use": "zh_CN", "zh_CN": "", @@ -879,7 +865,6 @@ Object { "id": "node_k1ow3cc7", "isLocked": false, "props": Object { - "__style__": Object {}, "colSpan": "", "fieldId": "column_k1p1bnjp", }, @@ -893,7 +878,6 @@ Object { "id": "node_k1ow3cc5", "isLocked": false, "props": Object { - "__style__": Object {}, "columnGap": "20", "fieldId": "columns_k1ow3h22", "layout": "6:6", @@ -1022,7 +1006,6 @@ Object { "value": Array [ Object { "componentName": "Text", - "props": Object {}, }, ], }, @@ -1052,7 +1035,6 @@ Object { "behavior": "NORMAL", "className": "div_kgaqfbm9", "customClassName": "", - "events": Object {}, "fieldId": "div_k1ow3h1o", "useFieldIdAsDomId": false, }, @@ -1067,7 +1049,6 @@ Object { "id": "form", "isLocked": false, "props": Object { - "__style__": Object {}, "autoUnmount": true, "autoValidate": true, "behavior": "NORMAL", @@ -1076,7 +1057,6 @@ Object { "variable": "state.formData", }, "fieldId": "form", - "fieldOptions": Object {}, "labelAlign": "top", "obj": Object { "a": 1, @@ -1137,7 +1117,6 @@ Object { "globalConfig": Object { "fit": Object { "compiled": "", - "error": Object {}, "source": "", "type": "js", }, @@ -1196,7 +1175,6 @@ Object.keys(module.exports).forEach(function(item) { }, "props": Object { "className": "page_kgaqfbm4", - "containerStyle": Object {}, "extensions": Object { "启用页头": true, }, diff --git a/packages/designer/tests/document/node/node-children.test.ts b/packages/designer/tests/document/node/node-children.test.ts index 30fe1a1ee..96c2c4736 100644 --- a/packages/designer/tests/document/node/node-children.test.ts +++ b/packages/designer/tests/document/node/node-children.test.ts @@ -75,7 +75,7 @@ describe('NodeChildren 方法测试', () => { expect(children.size).toBe(1); expect(children.length).toBe(1); - children.splice(0, 0, { componentName: 'Button' }); + children.splice(0, 0, doc.createNode({ componentName: 'Button' })); expect(children.size).toBe(2); expect(children.length).toBe(2); });