From 6176608ac745dbcff7d53143601316875eb2c351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Tue, 8 Jun 2021 13:49:20 +0800 Subject: [PATCH 01/12] =?UTF-8?q?refactor(props):=20=E5=B0=86=E5=BA=95?= =?UTF-8?q?=E5=B1=82=20prop=20=E7=9A=84=E5=B1=82=E7=BA=A7=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=88=90=E8=B7=9F=E5=85=83=E6=95=B0=E6=8D=AE=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0=E4=B8=80=E8=87=B4,=20=E6=94=AF=E6=8C=81=E9=80=9A?= =?UTF-8?q?=E8=BF=87=20API=20=E6=96=B9=E5=BC=8F=E8=AE=BE=E7=BD=AE=20prop?= =?UTF-8?q?=20=E5=88=86=E6=94=AF=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/designer/setting/setting-field.ts | 10 ++-- .../designer/src/document/node/props/prop.ts | 57 ++++++++++++++++++- .../designer/src/document/node/props/props.ts | 2 + .../src/components/object-setter/index.tsx | 22 ++++--- .../src/components/settings/main.ts | 14 ++--- 5 files changed, 82 insertions(+), 23 deletions(-) diff --git a/packages/designer/src/designer/setting/setting-field.ts b/packages/designer/src/designer/setting/setting-field.ts index 2267fcef9..0bedf77c3 100644 --- a/packages/designer/src/designer/setting/setting-field.ts +++ b/packages/designer/src/designer/setting/setting-field.ts @@ -6,13 +6,13 @@ import { computed, obx } from '@ali/lowcode-editor-core'; import { cloneDeep } from '@ali/lowcode-utils'; function getSettingFieldCollectorKey(parent: SettingEntry, config: FieldConfig) { - let top = parent; + let cur = parent; const path = [config.name]; - while (top !== parent.top) { - if (top instanceof SettingField && top.type !== 'group') { - path.unshift(top.name); + while (cur !== parent.top) { + if (cur instanceof SettingField && cur.type !== 'group') { + path.unshift(cur.name); } - top = top.parent; + cur = cur.parent; } return path.join('.'); } diff --git a/packages/designer/src/document/node/props/prop.ts b/packages/designer/src/document/node/props/prop.ts index 1622bcfac..148654962 100644 --- a/packages/designer/src/document/node/props/prop.ts +++ b/packages/designer/src/document/node/props/prop.ts @@ -1,11 +1,12 @@ import { untracked, computed, obx, engineConfig } from '@ali/lowcode-editor-core'; -import { CompositeValue, isJSExpression, isJSSlot, JSSlot, SlotSchema } from '@ali/lowcode-types'; +import { CompositeValue, FieldConfig, isJSExpression, isJSSlot, JSSlot, SlotSchema } from '@ali/lowcode-types'; import { uniqueId, isPlainObject, hasOwnProperty, compatStage } from '@ali/lowcode-utils'; import { PropStash } from './prop-stash'; import { valueToSource } from './value-to-source'; import { Props } from './props'; import { SlotNode, Node } from '../node'; import { TransformStage } from '../transform-stage'; +import { getFocusedElement } from 'medium-editor'; export const UNSET = Symbol.for('unset'); export type UNSET = typeof UNSET; @@ -14,10 +15,40 @@ export interface IPropParent { delete(prop: Prop): void; readonly props: Props; readonly owner: Node; + readonly path: string[]; } export type ValueTypes = 'unset' | 'literal' | 'map' | 'list' | 'expression' | 'slot'; +function hasItemsInMetadata(prop: Prop) { + const path = prop.path; + const { configure } = prop.getNode().componentMeta.getMetadata(); + if (!path || path.length === 0) return false; + let props = configure?.props; + while (path.length > 0) { + let name = path.shift(); + let matchedProp = getMatchedProp(props, name!); + if (!matchedProp) return false; + if (path.length === 0) return !!matchedProp?.items; + props = matchedProp.items; + } +} + +function getMatchedProp(props: FieldConfig[] | undefined, name: string): FieldConfig | null { + let found = null; + if (!props) return null; + for (const prop of props) { + if (prop.name === name) { + found = prop; + break; + } else if (prop.type === 'group' && prop.items) { + found = getMatchedProp(prop.items, name); + if (found) return found; + } + } + return found; +} + export class Prop implements IPropParent { readonly isProp = true; @@ -253,6 +284,21 @@ export class Prop implements IPropParent { }; } + this.dispose(); + + // 将父属性设置成一个对象,得同时把子属性都设值,同时清空其他子属性 + if (this._type === 'map' && isPlainObject(val)) { + this.items?.forEach((item) => { + // @ts-ignore + if ([item.key] in val) { + // @ts-ignore + item.setValue(val[item.key]); + } else { + this.clearPropValue(item.key!); + } + }); + } + if (oldValue !== this._value) { editor?.emit('node.innerProp.change', { node: this.owner, @@ -261,7 +307,6 @@ export class Prop implements IPropParent { newValue: this._value, }); } - this.dispose(); } @computed getValue(): CompositeValue { @@ -358,7 +403,13 @@ export class Prop implements IPropParent { @obx.val private _maps: Map | null = null; - @computed private get items(): Prop[] | null { + get path(): string[] { + return (this.parent.path || []).concat(this.key as string); + } + + private get items(): Prop[] | null { + // 不在元数据配置项中的,不产生 items + if (!hasItemsInMetadata(this)) return null; let _items: any; untracked(() => { _items = this._items; diff --git a/packages/designer/src/document/node/props/props.ts b/packages/designer/src/document/node/props/props.ts index 3c40d17fd..028d190a0 100644 --- a/packages/designer/src/document/node/props/props.ts +++ b/packages/designer/src/document/node/props/props.ts @@ -37,6 +37,8 @@ export class Props implements IPropParent { return maps; } + readonly path = []; + get props(): Props { return this; } diff --git a/packages/editor-skeleton/src/components/object-setter/index.tsx b/packages/editor-skeleton/src/components/object-setter/index.tsx index 1dcb7e25f..ec309ff2c 100644 --- a/packages/editor-skeleton/src/components/object-setter/index.tsx +++ b/packages/editor-skeleton/src/components/object-setter/index.tsx @@ -1,9 +1,9 @@ import { Component, Fragment } from 'react'; import { Icon, Button } from '@alifd/next'; -import { SetterType, FieldConfig } from '@ali/lowcode-types'; +import { SetterType, FieldConfig, CustomView } from '@ali/lowcode-types'; import { createSettingFieldView } from '../settings/settings-pane'; import { PopupContext, PopupPipe } from '../popup'; -import { SettingField } from '@ali/lowcode-designer'; +import { isSettingField, SettingField } from '@ali/lowcode-designer'; import './style.less'; import { Title } from '@ali/lowcode-editor-core'; @@ -165,11 +165,17 @@ class FormSetter extends Component { super(props); const { config, field } = props; const { extraProps } = field; - this.items = (config?.items || []).map((conf) => field.createField({ - ...conf, - setValue: extraProps?.setValue, - })); - + field.items.forEach((item: SettingField | CustomView) => { + if (isSettingField(item)) { + const originalSetValue = item.extraProps.setValue; + item.extraProps.setValue = (...args) => { + // 调用子字段本身的 setValue + originalSetValue?.apply(null, args); + // 调用父字段本身的 setValue + extraProps.setValue?.apply(null, args); + }; + } + }); // TODO: extraConfig for custom fields } @@ -181,7 +187,7 @@ class FormSetter extends Component { const { field } = this.props; return (
- {this.items.map((item, index) => createSettingFieldView(item, field, index))} + {field.items.map((item, index) => createSettingFieldView(item, field, index))}
); } diff --git a/packages/editor-skeleton/src/components/settings/main.ts b/packages/editor-skeleton/src/components/settings/main.ts index 60a20c2bf..66e78bc3d 100644 --- a/packages/editor-skeleton/src/components/settings/main.ts +++ b/packages/editor-skeleton/src/components/settings/main.ts @@ -69,13 +69,13 @@ export class SettingsMain { if (!this.designer) { this.designer = nodes[0].document.designer; } - - let lastSettings = this._settings; - // obx 的一些响应式计算会延迟到下一个时钟周期,导致 prop.parent 获取不到,这里也做一个延迟 - executePendingFn(() => { - lastSettings?.purge(); - }, 2000); - this._settings = this.designer.createSettingEntry(nodes); + // 当节点只有一个时,复用 node 上挂载的 settingEntry,不会产生平行的两个实例,这样在整个系统中对 + // 某个节点操作的 SettingTopEntry 只有一个实例,后续的 getProp() 也会拿到相同的 SettingField 实例 + if (nodes.length === 1) { + this._settings = nodes[0].settingEntry; + } else { + this._settings = this.designer.createSettingEntry(nodes); + } } purge() { From 1297e3c0e5f13a50bdd6e79ce5da37a8272e1ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Wed, 9 Jun 2021 14:57:52 +0800 Subject: [PATCH 02/12] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20valueChange?= =?UTF-8?q?=20=E4=B8=8D=E4=BC=9A=E5=9B=A0=E4=B8=BA=E5=AD=90=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=8F=98=E5=8C=96=E8=80=8C=E9=80=9A=E7=9F=A5=E7=88=B6?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E4=BA=8B=E4=BB=B6=E7=9B=91=E5=90=AC,=20?= =?UTF-8?q?=E8=80=83=E8=99=91=E5=88=B0=E5=90=8E=E7=BB=AD=E6=8E=A8=E8=8D=90?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A8=20setValue,=20=E4=B9=9F?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BA=86=20valueChange=20=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/designer/setting/setting-field.ts | 12 ++++++--- .../designer/setting/setting-prop-entry.ts | 25 ++++++++++--------- packages/designer/src/types/index.ts | 19 +++++++++++++- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/packages/designer/src/designer/setting/setting-field.ts b/packages/designer/src/designer/setting/setting-field.ts index 0bedf77c3..6f2a935d8 100644 --- a/packages/designer/src/designer/setting/setting-field.ts +++ b/packages/designer/src/designer/setting/setting-field.ts @@ -4,6 +4,7 @@ import { SettingPropEntry } from './setting-prop-entry'; import { SettingEntry } from './setting-entry'; import { computed, obx } from '@ali/lowcode-editor-core'; import { cloneDeep } from '@ali/lowcode-utils'; +import { ISetValueOptions } from '../../types'; function getSettingFieldCollectorKey(parent: SettingEntry, config: FieldConfig) { let cur = parent; @@ -140,7 +141,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry { private hotValue: any; - setValue(val: any, isHotValue?: boolean, force?: boolean, extraOptions?: any) { + setValue(val: any, isHotValue?: boolean, force?: boolean, extraOptions?: ISetValueOptions) { if (isHotValue) { this.setHotValue(val, extraOptions); return; @@ -172,9 +173,14 @@ export class SettingField extends SettingPropEntry implements SettingEntry { this.valueChange(); } - setHotValue(data: any, options?: any) { + setHotValue(data: any, options?: ISetValueOptions) { this.hotValue = data; const value = this.transducer.toNative(data); + if (options) { + options.fromSetHotValue = true; + } else { + options = { fromSetHotValue: true }; + } if (this.isUseVariable()) { const oldValue = this.getValue(); this.setValue({ @@ -191,7 +197,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry { return; } - this.valueChange(); + this.valueChange(options); } onEffect(action: () => void): () => void { diff --git a/packages/designer/src/designer/setting/setting-prop-entry.ts b/packages/designer/src/designer/setting/setting-prop-entry.ts index 3ec65bd4e..351af3cfe 100644 --- a/packages/designer/src/designer/setting/setting-prop-entry.ts +++ b/packages/designer/src/designer/setting/setting-prop-entry.ts @@ -6,6 +6,8 @@ import { Node } from '../../document'; import { ComponentMeta } from '../../component-meta'; import { Designer } from '../designer'; import { EventEmitter } from 'events'; +import { ISetValueOptions } from '../../types'; +import { isSettingField } from './setting-field'; export class SettingPropEntry implements SettingEntry { // === static properties === @@ -162,7 +164,7 @@ export class SettingPropEntry implements SettingEntry { /** * 设置当前属性值 */ - setValue(val: any, isHotValue?: boolean, force?: boolean, extraOptions?: any) { + setValue(val: any, isHotValue?: boolean, force?: boolean, extraOptions?: ISetValueOptions) { const oldValue = this.getValue(); if (this.type === 'field') { this.parent.setPropValue(this.name, val); @@ -178,6 +180,10 @@ export class SettingPropEntry implements SettingEntry { } } this.notifyValueChange(oldValue, val); + // 如果 fromSetHotValue,那么在 setHotValue 中已经调用过 valueChange 了 + if (!extraOptions?.fromSetHotValue) { + this.valueChange(extraOptions); + } } /** @@ -272,8 +278,12 @@ export class SettingPropEntry implements SettingEntry { /** * @deprecated */ - valueChange() { - this.emitter.emit('valuechange'); + valueChange(options: ISetValueOptions = {}) { + this.emitter.emit('valuechange', options); + + if (this.parent && isSettingField(this.parent)) { + this.parent.valueChange(options); + } } notifyValueChange(oldValue: any, newValue:any) { @@ -288,15 +298,6 @@ export class SettingPropEntry implements SettingEntry { return false; } - /* - getConfig(configName?: K): IPropConfig[K] | IPropConfig { - if (configName) { - return this.config[configName]; - } - - return this.config; - } - */ getVariableValue() { const v = this.getValue(); if (isJSExpression(v)) { diff --git a/packages/designer/src/types/index.ts b/packages/designer/src/types/index.ts index e079964b0..97cf60c6a 100644 --- a/packages/designer/src/types/index.ts +++ b/packages/designer/src/types/index.ts @@ -18,4 +18,21 @@ const utils = { compatibleLegaoSchema, getNodeSchemaById, }; -export type Utils = typeof utils; \ No newline at end of file +export type Utils = typeof utils; + +export enum PROP_VALUE_CHANGED_TYPE { + /** + * normal set value + */ + SET_VALUE = 'SET_VALUE', + /** + * value changed caused by sub-prop value change + */ + SUB_VALUE_CHANGE = 'SUB_VALUE_CHANGE', +} + +export interface ISetValueOptions { + disableMutator?: boolean; + type?: PROP_VALUE_CHANGED_TYPE; + fromSetHotValue?: boolean; +} \ No newline at end of file From 45cd088e607fc5101b43dd1a12e089768b68f0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Thu, 10 Jun 2021 15:43:15 +0800 Subject: [PATCH 03/12] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E5=A2=9E?= =?UTF-8?q?=E9=87=8F=E6=9B=B4=E6=96=B0=E6=9C=BA=E5=88=B6=E7=9A=84=E9=83=A8?= =?UTF-8?q?=E5=88=86=E9=99=90=E5=88=B6=E6=9D=A1=E4=BB=B6,=20=E5=B9=B6?= =?UTF-8?q?=E5=B0=86=E9=97=A8=E6=A7=9B=E8=B0=83=E6=95=B4=E5=88=B0=20200=20?= =?UTF-8?q?=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../react-simulator-renderer/src/renderer.ts | 6 ++--- .../src/utils/misc.ts | 23 +++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/react-simulator-renderer/src/renderer.ts b/packages/react-simulator-renderer/src/renderer.ts index 92b8ff08e..c70800190 100644 --- a/packages/react-simulator-renderer/src/renderer.ts +++ b/packages/react-simulator-renderer/src/renderer.ts @@ -48,8 +48,8 @@ export class DocumentInstance { this.disposeFunctions.push(host.onActivityEvent((data: ActivityData, ctx: any) => { if (host.mutedActivityEvent || (ctx && ctx.doc !== this.document)) return; - // 当节点数小数 300 个时,不走入增量更新逻辑,后面优化、细化逻辑后逐步放开限制 - if (this.document.nodesMap.size < 300) return; + // 当节点数小数 200 个时,不走入增量更新逻辑,后面优化、细化逻辑后逐步放开限制 + if (this.document.nodesMap.size < 200) return; if (tid) clearTimeout(tid); // 临时关闭全量计算 schema 的逻辑,在增量计算结束后,来一次全量计算 @@ -59,7 +59,7 @@ export class DocumentInstance { if (supportsQuickPropSetting(data, this)) { setInstancesProp(data, this); } else { - this._schema = applyActivities(this._schema!, data); + // this._schema = applyActivities(this._schema!, data); } } else if (data.type === ActivityType.ADDED) { // FIXME: 待补充 节点增加 逻辑 diff --git a/packages/react-simulator-renderer/src/utils/misc.ts b/packages/react-simulator-renderer/src/utils/misc.ts index 9777c4047..a4cd86848 100644 --- a/packages/react-simulator-renderer/src/utils/misc.ts +++ b/packages/react-simulator-renderer/src/utils/misc.ts @@ -1,6 +1,7 @@ import { ReactInstance } from 'react'; import { ActivityData, isJSSlot } from '@ali/lowcode-types'; import { DocumentInstance } from '../renderer'; +import { isReactClass } from '@ali/lowcode-utils'; interface UtilsMetadata { name: string; @@ -55,9 +56,9 @@ function haveForceUpdate(instances: any[]): boolean { export function supportsQuickPropSetting(data: ActivityData, doc: DocumentInstance) { const { payload } = data; const { schema, prop } = payload; - const nodeId = schema.id!; + const { componentName, id: nodeId } = schema; // const key = data.payload.prop.key; - const instances = doc.instancesMap.get(nodeId); + const instances = doc.instancesMap.get(nodeId!); const propKey = getUppermostPropKey(prop); let value = (schema.props as any)[propKey]; @@ -65,14 +66,28 @@ export function supportsQuickPropSetting(data: ActivityData, doc: DocumentInstan nodeId && Array.isArray(instances) && instances.length > 0 && - haveForceUpdate(instances) && propKey && // 不是 extraProp !propKey.startsWith('___') && - !isJSSlot(value) + !isJSSlot(value) && + // functional component 不支持 ref.props 直接设值,是 readonly 的 + isReactClass((doc.container?.components as any)[componentName]) && + haveForceUpdate(instances) && + // 黑名单组件通常会把 schema / children 魔改,导致直接设置 props 失效 + isAllowedComponent(componentName) ); } +// 不允许走快捷设置的组件黑名单 +const DISABLED__QUICK_SETTING_COMPONENT_NAMES = [ + 'Filter', // 查询组件 + 'Filter2', // 查询组件 + 'TableField', // 明细组件 +]; +function isAllowedComponent(name: string): boolean { + return !DISABLED__QUICK_SETTING_COMPONENT_NAMES.includes(name); +} + /** * 设置属性值 * @param data From 341f938f7fbf557b5b57965b711e369d75ec5e09 Mon Sep 17 00:00:00 2001 From: "wuyue.xht" Date: Thu, 10 Jun 2021 14:36:19 +0800 Subject: [PATCH 04/12] =?UTF-8?q?fix:=20=E4=BB=A5=E8=8A=82=E7=82=B9id?= =?UTF-8?q?=E4=BD=9C=E4=B8=BAkey=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=8B=96?= =?UTF-8?q?=E6=8B=BD=E3=80=81=E5=A2=9E=E5=88=A0=E6=97=B6=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=A2=91=E7=B9=81=E5=8D=B8=E8=BD=BD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/renderer-core/src/renderer/base.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/renderer-core/src/renderer/base.tsx b/packages/renderer-core/src/renderer/base.tsx index 1d81ac6d8..745e71796 100644 --- a/packages/renderer-core/src/renderer/base.tsx +++ b/packages/renderer-core/src/renderer/base.tsx @@ -372,7 +372,7 @@ export default function baseRenererFactory() { } if (Array.isArray(schema)) { if (schema.length === 1) return this.__createVirtualDom(schema[0], self, parentInfo); - return schema.map((item, idy) => this.__createVirtualDom(item, self, parentInfo, item?.__ctx?.lceKey ? '' : idy)); + return schema.map((item, idy) => this.__createVirtualDom(item, self, parentInfo, item?.__ctx?.lceKey ? '' : String(idy))); } // FIXME const _children = this.getSchemaChildren(schema); @@ -484,6 +484,7 @@ export default function baseRenererFactory() { } props.key = props.key || `${schema.__ctx.lceKey}_${schema.__ctx.idx || 0}_${idx !== undefined ? idx : ''}`; } else if (typeof idx === 'number' && !props.key) { + // 仅当循环场景走这里 props.key = idx; } From 4e5c7f57c1837c40cb4e8ec6b14af22c4b9ad4e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Thu, 10 Jun 2021 16:05:24 +0800 Subject: [PATCH 05/12] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=98=AF=E5=90=A6=E5=85=81=E8=AE=B8=E7=94=BB=E5=B8=83?= =?UTF-8?q?=E9=BC=A0=E6=A0=87=E4=BA=8B=E4=BB=B6=E7=9A=84=E5=86=92=E6=B3=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/designer/src/builtin-simulator/host.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/designer/src/builtin-simulator/host.ts b/packages/designer/src/builtin-simulator/host.ts index 0eb5c2429..4cb8199df 100644 --- a/packages/designer/src/builtin-simulator/host.ts +++ b/packages/designer/src/builtin-simulator/host.ts @@ -641,14 +641,16 @@ export class BuiltinSimulatorHost implements ISimulatorHost { if (!detecting.enable || this.designMode !== 'design') { return; } const nodeInst = this.getNodeInstanceFromElement(e.target as Element); detecting.capture(nodeInst?.node || null); - e.stopPropagation(); + if (!engineConfig.get('enableMouseEventPropagationInCanvas', false) || dragon.dragging) { + e.stopPropagation(); + } }; const leave = () => detecting.leave(this.project.currentDocument); @@ -659,7 +661,9 @@ export class BuiltinSimulatorHost implements ISimulatorHost { - e.stopPropagation(); + if (!engineConfig.get('enableMouseEventPropagationInCanvas', false) || dragon.dragging) { + e.stopPropagation(); + } }, true, ); From 144dd0801de3d497460670420a0cf2061f56bb6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Thu, 10 Jun 2021 20:55:33 +0800 Subject: [PATCH 06/12] =?UTF-8?q?chore(ut):=20=E4=BF=AE=E5=A4=8D=20prop=20?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=8F=98=E6=9B=B4=E5=90=8E=E7=9A=84=E5=8D=95?= =?UTF-8?q?=E6=B5=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 + packages/designer/jest.config.js | 2 +- .../tests/document/node/node.modify.test.ts | 66 +++++++++---------- .../props/{prop.test.ts => prop.test_wip.ts} | 0 .../{props.test.ts => props.test_wip.ts} | 0 5 files changed, 37 insertions(+), 34 deletions(-) rename packages/designer/tests/document/node/props/{prop.test.ts => prop.test_wip.ts} (100%) rename packages/designer/tests/document/node/props/{props.test.ts => props.test_wip.ts} (100%) diff --git a/package.json b/package.json index 401ceeccc..ad2023cce 100644 --- a/package.json +++ b/package.json @@ -48,5 +48,8 @@ "tnpm": { "mode": "yarn", "lockfile": "enable" + }, + "resolutions": { + "@builder/babel-preset-ice": "1.0.1" } } diff --git a/packages/designer/jest.config.js b/packages/designer/jest.config.js index 05a022b87..3703fedbe 100644 --- a/packages/designer/jest.config.js +++ b/packages/designer/jest.config.js @@ -6,7 +6,7 @@ module.exports = { // // '^.+\\.(ts|tsx)$': 'ts-jest', // // '^.+\\.(js|jsx)$': 'babel-jest', // }, - // testMatch: ['**/project.test.ts'], + // testMatch: ['**/node.modify.test.ts'], // testMatch: ['(/tests?/.*(test))\\.[jt]s$'], transformIgnorePatterns: [ `/node_modules/(?!${esModules})/`, diff --git a/packages/designer/tests/document/node/node.modify.test.ts b/packages/designer/tests/document/node/node.modify.test.ts index cd157868b..145610899 100644 --- a/packages/designer/tests/document/node/node.modify.test.ts +++ b/packages/designer/tests/document/node/node.modify.test.ts @@ -89,12 +89,12 @@ describe('schema 生成节点模型测试', () => { b: false, c: 'string', }); - const objAProp = formNode?.getProp('obj.a'); - const objBProp = formNode?.getProp('obj.b'); - const objCProp = formNode?.getProp('obj.c'); - expect(objAProp?.getValue()).toBe(1); - expect(objBProp?.getValue()).toBe(false); - expect(objCProp?.getValue()).toBe('string'); + // const objAProp = formNode?.getProp('obj.a'); + // const objBProp = formNode?.getProp('obj.b'); + // const objCProp = formNode?.getProp('obj.c'); + // expect(objAProp?.getValue()).toBe(1); + // expect(objBProp?.getValue()).toBe(false); + // expect(objCProp?.getValue()).toBe('string'); const idProp = formNode?.getExtraProp('extraPropA'); expect(idProp?.getValue()).toBe('extraPropA'); @@ -154,17 +154,17 @@ describe('schema 生成节点模型测试', () => { formNode?.setPropValue('obj.a', 3); formNode?.setPropValue('obj.b', false); formNode?.setPropValue('obj.c', 'string'); - const objAProp = formNode?.getProp('obj.a'); - const objBProp = formNode?.getProp('obj.b'); - const objCProp = formNode?.getProp('obj.c'); - expect(objAProp?.getValue()).toBe(3); - expect(objBProp?.getValue()).toBe(false); - expect(objCProp?.getValue()).toBe('string'); - expect(objProp?.getValue()).toEqual({ - a: 3, - b: false, - c: 'string', - }); + // const objAProp = formNode?.getProp('obj.a'); + // const objBProp = formNode?.getProp('obj.b'); + // const objCProp = formNode?.getProp('obj.c'); + // expect(objAProp?.getValue()).toBe(3); + // expect(objBProp?.getValue()).toBe(false); + // expect(objCProp?.getValue()).toBe('string'); + // expect(objProp?.getValue()).toEqual({ + // a: 3, + // b: false, + // c: 'string', + // }); }); it('修改普通属性,string | number | object,使用 Props 实例接口', () => { @@ -222,17 +222,17 @@ describe('schema 生成节点模型测试', () => { props?.setPropValue('obj.a', 3); props?.setPropValue('obj.b', false); props?.setPropValue('obj.c', 'string'); - const objAProp = formNode?.getProp('obj.a'); - const objBProp = formNode?.getProp('obj.b'); - const objCProp = formNode?.getProp('obj.c'); - expect(objAProp?.getValue()).toBe(3); - expect(objBProp?.getValue()).toBe(false); - expect(objCProp?.getValue()).toBe('string'); - expect(objProp?.getValue()).toEqual({ - a: 3, - b: false, - c: 'string', - }); + // const objAProp = formNode?.getProp('obj.a'); + // const objBProp = formNode?.getProp('obj.b'); + // const objCProp = formNode?.getProp('obj.c'); + // expect(objAProp?.getValue()).toBe(3); + // expect(objBProp?.getValue()).toBe(false); + // expect(objCProp?.getValue()).toBe('string'); + // expect(objProp?.getValue()).toEqual({ + // a: 3, + // b: false, + // c: 'string', + // }); }); it('修改普通属性,string | number | object,使用 Prop 实例接口', () => { @@ -296,11 +296,11 @@ describe('schema 生成节点模型测试', () => { expect(objAProp?.getValue()).toBe(3); expect(objBProp?.getValue()).toBe(false); expect(objCProp?.getValue()).toBe('string'); - expect(objProp?.getValue()).toEqual({ - a: 3, - b: false, - c: 'string', - }); + // expect(objProp?.getValue()).toEqual({ + // a: 3, + // b: false, + // c: 'string', + // }); }); }); diff --git a/packages/designer/tests/document/node/props/prop.test.ts b/packages/designer/tests/document/node/props/prop.test_wip.ts similarity index 100% rename from packages/designer/tests/document/node/props/prop.test.ts rename to packages/designer/tests/document/node/props/prop.test_wip.ts diff --git a/packages/designer/tests/document/node/props/props.test.ts b/packages/designer/tests/document/node/props/props.test_wip.ts similarity index 100% rename from packages/designer/tests/document/node/props/props.test.ts rename to packages/designer/tests/document/node/props/props.test_wip.ts From 4134dad92ed3ab1bed1487208d6a69555c7b4902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Tue, 15 Jun 2021 10:03:31 +0800 Subject: [PATCH 07/12] =?UTF-8?q?chore(test):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=90=84=E5=8C=85=E4=B8=AD=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84?= =?UTF-8?q?=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/designer/jest.config.js | 2 +- packages/editor-skeleton/package.json | 4 +--- packages/engine/package.json | 2 +- packages/plugin-designer/package.json | 4 +--- packages/plugin-outline-pane/package.json | 4 +--- packages/rax-renderer/package.json | 2 +- packages/rax-simulator-renderer/package.json | 6 ++---- .../react-renderer/tests/__snapshots__/index.test.tsx.snap | 4 ++-- packages/react-simulator-renderer/package.json | 2 -- packages/types/package.json | 4 +--- packages/utils/package.json | 4 +--- 11 files changed, 12 insertions(+), 26 deletions(-) diff --git a/packages/designer/jest.config.js b/packages/designer/jest.config.js index 3703fedbe..1a6063f1a 100644 --- a/packages/designer/jest.config.js +++ b/packages/designer/jest.config.js @@ -6,7 +6,7 @@ module.exports = { // // '^.+\\.(ts|tsx)$': 'ts-jest', // // '^.+\\.(js|jsx)$': 'babel-jest', // }, - // testMatch: ['**/node.modify.test.ts'], + // testMatch: ['**/node.add.test.ts'], // testMatch: ['(/tests?/.*(test))\\.[jt]s$'], transformIgnorePatterns: [ `/node_modules/(?!${esModules})/`, diff --git a/packages/editor-skeleton/package.json b/packages/editor-skeleton/package.json index 5b2715764..7362a1234 100644 --- a/packages/editor-skeleton/package.json +++ b/packages/editor-skeleton/package.json @@ -10,9 +10,7 @@ "es" ], "scripts": { - "build": "build-scripts build --skip-demo", - "test": "ava", - "test:snapshot": "ava --update-snapshots" + "build": "build-scripts build --skip-demo" }, "keywords": [ "lowcode", diff --git a/packages/engine/package.json b/packages/engine/package.json index 725982e2c..9f19f7488 100644 --- a/packages/engine/package.json +++ b/packages/engine/package.json @@ -14,7 +14,7 @@ "version:update": "node ./scripts/version.js", "build": "NODE_OPTIONS=--max_old_space_size=8192 build-scripts build --skip-demo", "cloud-build": "build-scripts build --config build.cloud.json && tnpm run version:update", - "test": "build-scripts test --config build.test.json" + "test": "build-scripts test --config build.test.json --jest-passWithNoTests" }, "license": "MIT", "dependencies": { diff --git a/packages/plugin-designer/package.json b/packages/plugin-designer/package.json index 4cebfc395..2e2bbe68b 100644 --- a/packages/plugin-designer/package.json +++ b/packages/plugin-designer/package.json @@ -10,9 +10,7 @@ "module": "es/index.js", "stylePath": "style.js", "scripts": { - "build": "build-scripts build --skip-demo", - "test": "ava", - "test:snapshot": "ava --update-snapshots" + "build": "build-scripts build --skip-demo" }, "keywords": [ "lowcode", diff --git a/packages/plugin-outline-pane/package.json b/packages/plugin-outline-pane/package.json index 3861e2f0d..973c33853 100644 --- a/packages/plugin-outline-pane/package.json +++ b/packages/plugin-outline-pane/package.json @@ -9,9 +9,7 @@ "main": "lib/index.js", "module": "es/index.js", "scripts": { - "build": "build-scripts build --skip-demo", - "test": "ava", - "test:snapshot": "ava --update-snapshots" + "build": "build-scripts build --skip-demo" }, "dependencies": { "@ali/lowcode-designer": "1.0.54", diff --git a/packages/rax-renderer/package.json b/packages/rax-renderer/package.json index 1a417311d..01e00ac59 100644 --- a/packages/rax-renderer/package.json +++ b/packages/rax-renderer/package.json @@ -3,7 +3,7 @@ "version": "1.0.54", "description": "Rax renderer for Ali lowCode engine", "main": "lib/index.js", - "module": "lib/index.js", + "module": "es/index.js", "miniappConfig": { "main": "lib/miniapp/index", "main:wechat": "lib/wechat-miniprogram/index" diff --git a/packages/rax-simulator-renderer/package.json b/packages/rax-simulator-renderer/package.json index 82cf500e3..48433fd76 100644 --- a/packages/rax-simulator-renderer/package.json +++ b/packages/rax-simulator-renderer/package.json @@ -8,9 +8,7 @@ "files": [], "scripts": { "build": "NODE_OPTIONS=--max_old_space_size=8192 build-scripts build", - "cloud-build": "build-scripts build --skip-demo", - "test": "ava", - "test:snapshot": "ava --update-snapshots" + "cloud-build": "build-scripts build --skip-demo" }, "dependencies": { "@ali/lowcode-designer": "1.0.54", @@ -57,6 +55,6 @@ "publishConfig": { "registry": "https://registry.npm.alibaba-inc.com" }, - "homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-rax-simulator-renderer@1.0.49/build/index.html", + "homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-rax-simulator-renderer@1.0.54/build/index.html", "gitHead": "3bfd7df92985ec6c9d2ccb8ba95d7b0829fa2b1d" } diff --git a/packages/react-renderer/tests/__snapshots__/index.test.tsx.snap b/packages/react-renderer/tests/__snapshots__/index.test.tsx.snap index 90d2f6a5d..7a4d4b365 100644 --- a/packages/react-renderer/tests/__snapshots__/index.test.tsx.snap +++ b/packages/react-renderer/tests/__snapshots__/index.test.tsx.snap @@ -2,7 +2,7 @@ exports[`React Renderer render basic case 1`] = `
diff --git a/packages/react-simulator-renderer/package.json b/packages/react-simulator-renderer/package.json index 277ba69f1..6cadb38cf 100644 --- a/packages/react-simulator-renderer/package.json +++ b/packages/react-simulator-renderer/package.json @@ -11,8 +11,6 @@ ], "scripts": { "cloud-build": "build-scripts build --skip-demo", - "test": "ava", - "test:snapshot": "ava --update-snapshots", "build": "NODE_OPTIONS=--max_old_space_size=8192 build-scripts build --skip-demo" }, "dependencies": { diff --git a/packages/types/package.json b/packages/types/package.json index a373448dc..88017f218 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -9,9 +9,7 @@ "main": "lib/index.js", "module": "es/index.js", "scripts": { - "build": "build-scripts build --skip-demo", - "test": "ava", - "test:snapshot": "ava --update-snapshots" + "build": "build-scripts build --skip-demo" }, "dependencies": { "@ali/lowcode-datasource-types": "^1.0.21", diff --git a/packages/utils/package.json b/packages/utils/package.json index ab53d2346..a2fa681bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -9,9 +9,7 @@ "main": "lib/index.js", "module": "es/index.js", "scripts": { - "build": "build-scripts build --skip-demo", - "test": "ava", - "test:snapshot": "ava --update-snapshots" + "build": "build-scripts build --skip-demo" }, "dependencies": { "@ali/lowcode-types": "1.0.54", From a187d0d2bf5b6aedf787aa38374f3c7e46f71085 Mon Sep 17 00:00:00 2001 From: "jianhui.fjh" Date: Wed, 16 Jun 2021 12:40:20 +0800 Subject: [PATCH 08/12] fix: deploy node version 14.17.0 --- scripts/deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index d9b026bbd..f5c862c8a 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -12,7 +12,7 @@ tnpm i -g n export N_NODE_MIRROR=https://npm.taobao.org/mirrors/node echo "Switch node version to 14" -n 14 +n 14.17.0 echo "Node Version" node -v From b4f8eed6295e358ba76a9c66319cba085cf1fdc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Wed, 16 Jun 2021 12:54:53 +0800 Subject: [PATCH 09/12] =?UTF-8?q?refactor(prop):=20=E6=AF=8F=E6=AC=A1=20pr?= =?UTF-8?q?op.dispose=20=E5=90=8E=E9=9C=80=E8=A6=81=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=20items,=20field.items=20=E6=9C=89=E5=88=99?= =?UTF-8?q?=E5=A4=8D=E7=94=A8,=20=E6=97=A0=E5=88=99=E6=96=B0=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/src/document/node/props/prop.ts | 52 +-------------- .../tests/document/node/node.modify.test.ts | 66 +++++++++---------- .../props/{prop.test_wip.ts => prop.test.ts} | 0 .../{props.test_wip.ts => props.test.ts} | 0 .../src/components/object-setter/index.tsx | 35 ++++++---- .../src/components/settings/settings-pane.tsx | 2 +- 6 files changed, 58 insertions(+), 97 deletions(-) rename packages/designer/tests/document/node/props/{prop.test_wip.ts => prop.test.ts} (100%) rename packages/designer/tests/document/node/props/{props.test_wip.ts => props.test.ts} (100%) diff --git a/packages/designer/src/document/node/props/prop.ts b/packages/designer/src/document/node/props/prop.ts index 148654962..79a3564f9 100644 --- a/packages/designer/src/document/node/props/prop.ts +++ b/packages/designer/src/document/node/props/prop.ts @@ -6,7 +6,6 @@ import { valueToSource } from './value-to-source'; import { Props } from './props'; import { SlotNode, Node } from '../node'; import { TransformStage } from '../transform-stage'; -import { getFocusedElement } from 'medium-editor'; export const UNSET = Symbol.for('unset'); export type UNSET = typeof UNSET; @@ -20,35 +19,6 @@ export interface IPropParent { export type ValueTypes = 'unset' | 'literal' | 'map' | 'list' | 'expression' | 'slot'; -function hasItemsInMetadata(prop: Prop) { - const path = prop.path; - const { configure } = prop.getNode().componentMeta.getMetadata(); - if (!path || path.length === 0) return false; - let props = configure?.props; - while (path.length > 0) { - let name = path.shift(); - let matchedProp = getMatchedProp(props, name!); - if (!matchedProp) return false; - if (path.length === 0) return !!matchedProp?.items; - props = matchedProp.items; - } -} - -function getMatchedProp(props: FieldConfig[] | undefined, name: string): FieldConfig | null { - let found = null; - if (!props) return null; - for (const prop of props) { - if (prop.name === name) { - found = prop; - break; - } else if (prop.type === 'group' && prop.items) { - found = getMatchedProp(prop.items, name); - if (found) return found; - } - } - return found; -} - export class Prop implements IPropParent { readonly isProp = true; @@ -286,19 +256,6 @@ export class Prop implements IPropParent { this.dispose(); - // 将父属性设置成一个对象,得同时把子属性都设值,同时清空其他子属性 - if (this._type === 'map' && isPlainObject(val)) { - this.items?.forEach((item) => { - // @ts-ignore - if ([item.key] in val) { - // @ts-ignore - item.setValue(val[item.key]); - } else { - this.clearPropValue(item.key!); - } - }); - } - if (oldValue !== this._value) { editor?.emit('node.innerProp.change', { node: this.owner, @@ -407,13 +364,8 @@ export class Prop implements IPropParent { return (this.parent.path || []).concat(this.key as string); } - private get items(): Prop[] | null { - // 不在元数据配置项中的,不产生 items - if (!hasItemsInMetadata(this)) return null; - let _items: any; - untracked(() => { - _items = this._items; - }); + @computed private get items(): Prop[] | null { + let _items: any = this._items; if (!_items) { if (this._type === 'list') { const data = this._value; diff --git a/packages/designer/tests/document/node/node.modify.test.ts b/packages/designer/tests/document/node/node.modify.test.ts index 145610899..cd157868b 100644 --- a/packages/designer/tests/document/node/node.modify.test.ts +++ b/packages/designer/tests/document/node/node.modify.test.ts @@ -89,12 +89,12 @@ describe('schema 生成节点模型测试', () => { b: false, c: 'string', }); - // const objAProp = formNode?.getProp('obj.a'); - // const objBProp = formNode?.getProp('obj.b'); - // const objCProp = formNode?.getProp('obj.c'); - // expect(objAProp?.getValue()).toBe(1); - // expect(objBProp?.getValue()).toBe(false); - // expect(objCProp?.getValue()).toBe('string'); + const objAProp = formNode?.getProp('obj.a'); + const objBProp = formNode?.getProp('obj.b'); + const objCProp = formNode?.getProp('obj.c'); + expect(objAProp?.getValue()).toBe(1); + expect(objBProp?.getValue()).toBe(false); + expect(objCProp?.getValue()).toBe('string'); const idProp = formNode?.getExtraProp('extraPropA'); expect(idProp?.getValue()).toBe('extraPropA'); @@ -154,17 +154,17 @@ describe('schema 生成节点模型测试', () => { formNode?.setPropValue('obj.a', 3); formNode?.setPropValue('obj.b', false); formNode?.setPropValue('obj.c', 'string'); - // const objAProp = formNode?.getProp('obj.a'); - // const objBProp = formNode?.getProp('obj.b'); - // const objCProp = formNode?.getProp('obj.c'); - // expect(objAProp?.getValue()).toBe(3); - // expect(objBProp?.getValue()).toBe(false); - // expect(objCProp?.getValue()).toBe('string'); - // expect(objProp?.getValue()).toEqual({ - // a: 3, - // b: false, - // c: 'string', - // }); + const objAProp = formNode?.getProp('obj.a'); + const objBProp = formNode?.getProp('obj.b'); + const objCProp = formNode?.getProp('obj.c'); + expect(objAProp?.getValue()).toBe(3); + expect(objBProp?.getValue()).toBe(false); + expect(objCProp?.getValue()).toBe('string'); + expect(objProp?.getValue()).toEqual({ + a: 3, + b: false, + c: 'string', + }); }); it('修改普通属性,string | number | object,使用 Props 实例接口', () => { @@ -222,17 +222,17 @@ describe('schema 生成节点模型测试', () => { props?.setPropValue('obj.a', 3); props?.setPropValue('obj.b', false); props?.setPropValue('obj.c', 'string'); - // const objAProp = formNode?.getProp('obj.a'); - // const objBProp = formNode?.getProp('obj.b'); - // const objCProp = formNode?.getProp('obj.c'); - // expect(objAProp?.getValue()).toBe(3); - // expect(objBProp?.getValue()).toBe(false); - // expect(objCProp?.getValue()).toBe('string'); - // expect(objProp?.getValue()).toEqual({ - // a: 3, - // b: false, - // c: 'string', - // }); + const objAProp = formNode?.getProp('obj.a'); + const objBProp = formNode?.getProp('obj.b'); + const objCProp = formNode?.getProp('obj.c'); + expect(objAProp?.getValue()).toBe(3); + expect(objBProp?.getValue()).toBe(false); + expect(objCProp?.getValue()).toBe('string'); + expect(objProp?.getValue()).toEqual({ + a: 3, + b: false, + c: 'string', + }); }); it('修改普通属性,string | number | object,使用 Prop 实例接口', () => { @@ -296,11 +296,11 @@ describe('schema 生成节点模型测试', () => { expect(objAProp?.getValue()).toBe(3); expect(objBProp?.getValue()).toBe(false); expect(objCProp?.getValue()).toBe('string'); - // expect(objProp?.getValue()).toEqual({ - // a: 3, - // b: false, - // c: 'string', - // }); + expect(objProp?.getValue()).toEqual({ + a: 3, + b: false, + c: 'string', + }); }); }); diff --git a/packages/designer/tests/document/node/props/prop.test_wip.ts b/packages/designer/tests/document/node/props/prop.test.ts similarity index 100% rename from packages/designer/tests/document/node/props/prop.test_wip.ts rename to packages/designer/tests/document/node/props/prop.test.ts diff --git a/packages/designer/tests/document/node/props/props.test_wip.ts b/packages/designer/tests/document/node/props/props.test.ts similarity index 100% rename from packages/designer/tests/document/node/props/props.test_wip.ts rename to packages/designer/tests/document/node/props/props.test.ts diff --git a/packages/editor-skeleton/src/components/object-setter/index.tsx b/packages/editor-skeleton/src/components/object-setter/index.tsx index ec309ff2c..eb0bd6058 100644 --- a/packages/editor-skeleton/src/components/object-setter/index.tsx +++ b/packages/editor-skeleton/src/components/object-setter/index.tsx @@ -159,23 +159,32 @@ interface FormSetterProps { config: ObjectSetterConfig; } class FormSetter extends Component { - private items: SettingField[]; + private items: (SettingField | CustomView)[]; constructor(props: RowSetterProps) { super(props); const { config, field } = props; const { extraProps } = field; - field.items.forEach((item: SettingField | CustomView) => { - if (isSettingField(item)) { - const originalSetValue = item.extraProps.setValue; - item.extraProps.setValue = (...args) => { - // 调用子字段本身的 setValue - originalSetValue?.apply(null, args); - // 调用父字段本身的 setValue - extraProps.setValue?.apply(null, args); - }; - } - }); + + if (Array.isArray(field.items) && field.items.length > 0) { + field.items.forEach((item: SettingField | CustomView) => { + if (isSettingField(item)) { + const originalSetValue = item.extraProps.setValue; + item.extraProps.setValue = (...args) => { + // 调用子字段本身的 setValue + originalSetValue?.apply(null, args); + // 调用父字段本身的 setValue + extraProps.setValue?.apply(null, args); + }; + } + }); + this.items = field.items; + } else { + this.items = (config?.items || []).map((conf) => field.createField({ + ...conf, + setValue: extraProps?.setValue, + })); + } // TODO: extraConfig for custom fields } @@ -187,7 +196,7 @@ class FormSetter extends Component { const { field } = this.props; return (
- {field.items.map((item, index) => createSettingFieldView(item, field, index))} + {this.items.map((item, index) => createSettingFieldView(item, field, index))}
); } diff --git a/packages/editor-skeleton/src/components/settings/settings-pane.tsx b/packages/editor-skeleton/src/components/settings/settings-pane.tsx index a003318b5..16f9ae138 100644 --- a/packages/editor-skeleton/src/components/settings/settings-pane.tsx +++ b/packages/editor-skeleton/src/components/settings/settings-pane.tsx @@ -24,7 +24,7 @@ class SettingFieldView extends Component<{ field: SettingField }> { const { field } = this.props; const { extraProps, componentMeta } = field; const { condition, defaultValue, display } = extraProps; - const { prototype } = componentMeta; + const { prototype } = componentMeta!; let visible; try { visible = typeof condition === 'function' ? condition(field) !== false : true; From cec923b8ff477eb5a419b09f30b0abdf1f211877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Thu, 17 Jun 2021 11:13:19 +0800 Subject: [PATCH 10/12] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=8C=BA=20stage=20=E5=9B=9E=E5=88=B0=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/editor-skeleton/src/components/stage-box/stage-box.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/editor-skeleton/src/components/stage-box/stage-box.tsx b/packages/editor-skeleton/src/components/stage-box/stage-box.tsx index 92e77db57..f1125d229 100644 --- a/packages/editor-skeleton/src/components/stage-box/stage-box.tsx +++ b/packages/editor-skeleton/src/components/stage-box/stage-box.tsx @@ -45,6 +45,7 @@ export default class StageBox extends Component { } else { const stateName = skeleton.createStage({ content: children, + isRoot: true, }); this.stageChain = new StageChain(skeleton.getStage(stateName as string) as StageWidget); } From 2ba28f928a095166c434639670b20c4988cf57fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Thu, 17 Jun 2021 11:14:03 +0800 Subject: [PATCH 11/12] =?UTF-8?q?fix(vision):=20=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E5=8E=9F=20vision=20proto=20transducers=20=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/src/document/node/props/props.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/designer/src/document/node/props/props.ts b/packages/designer/src/document/node/props/props.ts index 028d190a0..2d24e477d 100644 --- a/packages/designer/src/document/node/props/props.ts +++ b/packages/designer/src/document/node/props/props.ts @@ -107,6 +107,7 @@ export class Props implements IPropParent { if (this.items.length < 1) { return {}; } + let allProps = {} as any; let props: any = {}; const extras: any = {}; if (this.type === 'list') { @@ -139,6 +140,12 @@ export class Props implements IPropParent { if (value === UNSET) { value = undefined; } + allProps[name] = value; + }); + // compatible vision + const transformedProps = this.transformToStatic(allProps); + Object.keys(transformedProps).forEach((name) => { + const value = transformedProps[name]; if (typeof name === 'string' && name.startsWith(EXTRA_KEY_PREFIX)) { name = getOriginalExtraKey(name); extras[name] = value; @@ -151,6 +158,26 @@ export class Props implements IPropParent { return { props, extras }; } + /** + * @deprecated + */ + private transformToStatic(props: any) { + let transducers = this.owner.componentMeta.prototype?.options?.transducers; + if (!transducers) { + return props; + } + if (!Array.isArray(transducers)) { + transducers = [transducers]; + } + props = transducers.reduce((xprops: any, transducer: any) => { + if (transducer && typeof transducer.toStatic === 'function') { + return transducer.toStatic(xprops); + } + return xprops; + }, props); + return props; + } + /** * 根据 path 路径查询属性 * From 8319b13051405f7a62328320c88545f22de28901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Thu, 17 Jun 2021 11:14:36 +0800 Subject: [PATCH 12/12] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9=20icon=20?= =?UTF-8?q?=E4=B8=BA=20esmodule=20=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/utils/src/create-icon.tsx | 4 ++++ packages/utils/src/is-es-module.ts | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/utils/src/create-icon.tsx b/packages/utils/src/create-icon.tsx index a69a042ae..34c405147 100644 --- a/packages/utils/src/create-icon.tsx +++ b/packages/utils/src/create-icon.tsx @@ -2,6 +2,7 @@ import { isValidElement, ReactNode, createElement, cloneElement } from 'react'; import { Icon } from '@alifd/next'; import { IconType } from '@ali/lowcode-types'; import { isReactComponent } from './is-react'; +import { isESModule } from './is-es-module'; const URL_RE = /^(https?:)\/\//i; @@ -9,6 +10,9 @@ export function createIcon(icon?: IconType | null, props?: Record; diff --git a/packages/utils/src/is-es-module.ts b/packages/utils/src/is-es-module.ts index 32839a38b..6a9d0fa9e 100644 --- a/packages/utils/src/is-es-module.ts +++ b/packages/utils/src/is-es-module.ts @@ -1,3 +1,7 @@ -export function isESModule(obj: any): obj is { [key: string]: any } { +export type ESModule = { + __esModule: true; + default: any; +}; +export function isESModule(obj: any): obj is ESModule { return obj && obj.__esModule; }