From 8ba26ee8805121d72caa95cd84d3f326aa66b718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Tue, 22 Sep 2020 11:09:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BF=AE=E6=94=B9=20?= =?UTF-8?q?=E5=8B=BE=E9=80=89=E6=A1=86=E3=80=81=E5=AF=8C=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8=E3=80=81=E4=B8=8B=E6=8B=89=E9=80=89?= =?UTF-8?q?=E6=8B=A9=20=E7=AD=89=E7=BB=84=E4=BB=B6=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E6=8A=A5=E9=94=99=20fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E7=BB=84=E4=BB=B6=E6=97=A0=E6=B3=95=E9=80=89?= =?UTF-8?q?=E4=B8=AD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bem-tools/border-detecting.tsx | 5 ++--- packages/designer/src/builtin-simulator/host.ts | 8 ++++---- packages/editor-preset-vision/src/editor.ts | 8 ++++++-- packages/utils/src/index.ts | 1 + packages/utils/src/misc.ts | 15 +++++++++++++++ 5 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 packages/utils/src/misc.ts diff --git a/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx b/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx index 565078a66..1f1735801 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx @@ -58,13 +58,12 @@ export class BorderDetecting extends Component<{ host: BuiltinSimulatorHost }> { @computed get current() { const { host } = this.props; const doc = host.currentDocument; - console.info(doc); if (!doc) { return null; } const { selection } = doc; - const { current } = host.designer.detecting; - + const { current } = host.designer.detecting; + if (!current || current.document !== doc || selection.has(current.id)) { return null; } diff --git a/packages/designer/src/builtin-simulator/host.ts b/packages/designer/src/builtin-simulator/host.ts index 50daf3d3d..d61a4bed0 100644 --- a/packages/designer/src/builtin-simulator/host.ts +++ b/packages/designer/src/builtin-simulator/host.ts @@ -327,10 +327,10 @@ export class BuiltinSimulatorHost implements ISimulatorHost { doc.removeEventListener('mouseup', checkSelect, true); diff --git a/packages/editor-preset-vision/src/editor.ts b/packages/editor-preset-vision/src/editor.ts index f63a8fc0e..1ed7b3757 100644 --- a/packages/editor-preset-vision/src/editor.ts +++ b/packages/editor-preset-vision/src/editor.ts @@ -1,5 +1,5 @@ -import { isJSBlock, isJSExpression, isJSSlot, isI18nData } from '@ali/lowcode-types'; -import { isPlainObject, hasOwnProperty, cloneDeep } from '@ali/lowcode-utils'; +import { isJSBlock, isJSExpression, isJSSlot } from '@ali/lowcode-types'; +import { isPlainObject, hasOwnProperty, cloneDeep, isI18NObject, isUseI18NSetter, convertToI18NObject } from '@ali/lowcode-utils'; import { globalContext, Editor } from '@ali/lowcode-editor-core'; import { Designer, LiveEditing, TransformStage, Node, getConvertedExtraKey } from '@ali/lowcode-designer'; import Outline, { OutlineBackupPane, getTreeMaster } from '@ali/lowcode-plugin-outline-pane'; @@ -123,6 +123,10 @@ designer.addPropsReducer((props, node) => { if (ov === undefined && v !== undefined) { newProps[item.name] = v; } + // 兼容 props 中的属性为 i18n 类型,但是仅提供了一个值 + if (isUseI18NSetter(node.componentMeta.prototype, item.name) && !isI18NObject(ov)) { + newProps[item.name] = v; + } } catch (e) { if (hasOwnProperty(props, item.name)) { newProps[item.name] = props[item.name]; diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 0f9fcad2a..e5dd40da3 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -20,3 +20,4 @@ export * from './svg-icon'; export * from './unique-id'; export * from './build-components'; export * from './appHelper'; +export * from './misc'; \ No newline at end of file diff --git a/packages/utils/src/misc.ts b/packages/utils/src/misc.ts new file mode 100644 index 000000000..574def94a --- /dev/null +++ b/packages/utils/src/misc.ts @@ -0,0 +1,15 @@ + + +export function isUseI18NSetter(prototype: any, propName: string) { + const configure = prototype?.options?.configure; + if (Array.isArray(configure)) { + return configure.some(c => { + return c.name === propName && c?.setter?.type?.displayName === 'I18nSetter'; + }); + } + return false; +} + +export function convertToI18NObject(v: string, locale: string = 'zh_CN') { + return { type: 'i18n', use: locale, [locale]: v }; +}