From 63b19f17104c9c30a8e3babdac477777989268b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Tue, 4 Aug 2020 19:51:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20slot=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=88=9D=E5=A7=8B=E5=80=BC=E5=BC=82=E5=B8=B8=E7=9A=84?= =?UTF-8?q?=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/bundle/upgrade-metadata.ts | 43 ++++++++----------- packages/types/src/value-type.ts | 2 +- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/packages/editor-preset-vision/src/bundle/upgrade-metadata.ts b/packages/editor-preset-vision/src/bundle/upgrade-metadata.ts index 42ed2ad27..4af320f41 100644 --- a/packages/editor-preset-vision/src/bundle/upgrade-metadata.ts +++ b/packages/editor-preset-vision/src/bundle/upgrade-metadata.ts @@ -1,6 +1,6 @@ import { ComponentType, ReactElement, isValidElement, ComponentClass } from 'react'; import { isPlainObject, uniqueId } from '@ali/lowcode-utils'; -import { isI18nData, SettingTarget, InitialItem, FilterItem, isJSSlot, ProjectSchema, AutorunItem } from '@ali/lowcode-types'; +import { isI18nData, SettingTarget, InitialItem, FilterItem, isJSSlot, ProjectSchema, AutorunItem, isJSBlock } from '@ali/lowcode-types'; import { untracked } from '@ali/lowcode-editor-core'; import { editor, designer } from '../editor'; import { SettingField } from '@ali/lowcode-designer'; @@ -281,24 +281,19 @@ export function upgradePropConfig(config: OldPropConfig, collector: ConfigCollec } let initialFn = (slotName ? null : initial) || initialValue; - // 在 upgrade reducer 做了 JSBlock ——> JSSlot - // if (slotName && initialValue === true) { - // initialFn = (value: any, defaultValue: any) => { - // if (isJSSlot(value)) { - // return { - // title: slotTitle || title, - // name: slotName, - // ...value, - // }; - // } - // return { - // type: 'JSSlot', - // title: slotTitle || title, - // name: slotName, - // value: initialChildren, - // }; - // }; - // } + if (slotName && initialValue === true) { + initialFn = (value: any, defaultValue: any) => { + if (isJSBlock(value)) { + return value; + } + return { + type: 'JSSlot', + title: slotTitle || title, + name: slotName, + value: initialChildren, + }; + }; + } if (!slotName) { if (accessor) { @@ -347,22 +342,22 @@ export function upgradePropConfig(config: OldPropConfig, collector: ConfigCollec initial: (field: Field, currentValue: any) => { // FIXME! read from prototype.defaultProps const defaults = extraProps.defaultValue; - + if (typeof initialFn !== 'function') { initialFn = defaultInitial; } - + const v = initialFn.call(field, currentValue, defaults); - + if (setterInitial) { return setterInitial.call(field, v, defaults); } - + return v; }, }); } - + if (ignore != null || disabled != null) { collector.addFilter({ // FIXME! name should be "xxx.xxx" diff --git a/packages/types/src/value-type.ts b/packages/types/src/value-type.ts index 6e5083c0a..34f0c38c5 100644 --- a/packages/types/src/value-type.ts +++ b/packages/types/src/value-type.ts @@ -55,5 +55,5 @@ export function isJSSlot(data: any): data is JSSlot { } export function isJSBlock(data: any): data is JSBlock { - return data && data.type === 'JSBlock' + return data && data.type === 'JSBlock'; }