EXTRA_KEY_PREFIX 逻辑调整和收敛

This commit is contained in:
mario.gk 2020-05-28 18:08:17 +08:00
parent 9278ab202e
commit 0c73fe40dc
3 changed files with 25 additions and 11 deletions

View File

@ -13,7 +13,7 @@ import {
ComponentSchema, ComponentSchema,
NodeStatus, NodeStatus,
} from '@ali/lowcode-types'; } from '@ali/lowcode-types';
import { Props, EXTRA_KEY_PREFIX } from './props/props'; import { Props, getConvertedExtraKey } from './props/props';
import { DocumentModel } from '../document-model'; import { DocumentModel } from '../document-model';
import { NodeChildren } from './node-children'; import { NodeChildren } from './node-children';
import { Prop } from './props/prop'; import { Prop } from './props/prop';
@ -378,7 +378,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
} }
getExtraProp(key: string, stash = true): Prop | null { getExtraProp(key: string, stash = true): Prop | null {
return this.props.get(EXTRA_KEY_PREFIX + key, stash) || null; return this.props.get(getConvertedExtraKey(key), stash) || null;
} }
/** /**

View File

@ -7,6 +7,19 @@ import { Node } from '../node';
import { TransformStage } from '../transform-stage'; import { TransformStage } from '../transform-stage';
export const EXTRA_KEY_PREFIX = '___'; export const EXTRA_KEY_PREFIX = '___';
export function getConvertedExtraKey(key: string): string {
if (!key) {
return '';
}
let _key = key;
if (key.indexOf('.') > 0) {
_key = key.split('.')[0];
}
return EXTRA_KEY_PREFIX + _key + EXTRA_KEY_PREFIX + key.substr(_key.length);
}
export function getOriginalExtraKey(key: string): string {
return key.replace(new RegExp(`${EXTRA_KEY_PREFIX}`, 'g'), '');
}
export class Props implements IPropParent { export class Props implements IPropParent {
readonly id = uniqueId('props'); readonly id = uniqueId('props');
@ -50,7 +63,7 @@ export class Props implements IPropParent {
} }
if (extras) { if (extras) {
Object.keys(extras).forEach(key => { Object.keys(extras).forEach(key => {
this.items.push(new Prop(this, (extras as any)[key], EXTRA_KEY_PREFIX + key)); this.items.push(new Prop(this, (extras as any)[key], getConvertedExtraKey(key)));
}); });
} }
} }
@ -70,7 +83,7 @@ export class Props implements IPropParent {
} }
if (extras) { if (extras) {
Object.keys(extras).forEach(key => { Object.keys(extras).forEach(key => {
this.items.push(new Prop(this, (extras as any)[key], EXTRA_KEY_PREFIX + key)); this.items.push(new Prop(this, (extras as any)[key], getConvertedExtraKey(key)));
}); });
} }
originItems.forEach(item => item.purge()); originItems.forEach(item => item.purge());
@ -97,7 +110,7 @@ export class Props implements IPropParent {
} }
let name = item.key as string; let name = item.key as string;
if (name && typeof name === 'string' && name.startsWith(EXTRA_KEY_PREFIX)) { if (name && typeof name === 'string' && name.startsWith(EXTRA_KEY_PREFIX)) {
name = name.substr(EXTRA_KEY_PREFIX.length); name = getOriginalExtraKey(name);
extras[name] = value; extras[name] = value;
} else { } else {
props.push({ props.push({
@ -119,7 +132,7 @@ export class Props implements IPropParent {
value = null; value = null;
} }
if (typeof name === 'string' && name.startsWith(EXTRA_KEY_PREFIX)) { if (typeof name === 'string' && name.startsWith(EXTRA_KEY_PREFIX)) {
name = name.substr(EXTRA_KEY_PREFIX.length); name = getOriginalExtraKey(name);
extras[name] = value; extras[name] = value;
} else { } else {
props[name] = value; props[name] = value;

View File

@ -1,5 +1,6 @@
import { TransformedComponentMetadata, FieldConfig, SettingTarget } from '@ali/lowcode-types'; import { TransformedComponentMetadata, FieldConfig, SettingTarget } from '@ali/lowcode-types';
import { IconSlot } from '../icons/slot'; import { IconSlot } from '../icons/slot';
import { getConvertedExtraKey } from '@ali/lowcode-designer';
export default function(metadata: TransformedComponentMetadata): TransformedComponentMetadata { export default function(metadata: TransformedComponentMetadata): TransformedComponentMetadata {
const { componentName, configure = {} } = metadata; const { componentName, configure = {} } = metadata;
@ -86,7 +87,7 @@ export default function(metadata: TransformedComponentMetadata): TransformedComp
if (componentName === 'Slot') { if (componentName === 'Slot') {
basicInfo.icon = IconSlot; basicInfo.icon = IconSlot;
propsGroup = [{ propsGroup = [{
name: '___title', name: getConvertedExtraKey('title'),
title: { title: {
type: 'i18n', type: 'i18n',
'en-US': 'Slot Title', 'en-US': 'Slot Title',
@ -203,7 +204,7 @@ export default function(metadata: TransformedComponentMetadata): TransformedComp
if (!isRoot) { if (!isRoot) {
if (supports.condition !== false) { if (supports.condition !== false) {
advanceGroup.push({ advanceGroup.push({
name: '___condition', name: getConvertedExtraKey('condition'),
title: { type: 'i18n', 'zh-CN': '是否渲染', 'en-US': 'Condition' }, title: { type: 'i18n', 'zh-CN': '是否渲染', 'en-US': 'Condition' },
defaultValue: true, defaultValue: true,
setter: [{ setter: [{
@ -219,7 +220,7 @@ export default function(metadata: TransformedComponentMetadata): TransformedComp
title: { type: 'i18n', 'zh-CN': '循环', 'en-US': 'Loop' }, title: { type: 'i18n', 'zh-CN': '循环', 'en-US': 'Loop' },
items: [ items: [
{ {
name: '___loop', name: getConvertedExtraKey('loop'),
title: { type: 'i18n', 'zh-CN': '循环数据', 'en-US': 'Loop Data' }, title: { type: 'i18n', 'zh-CN': '循环数据', 'en-US': 'Loop Data' },
defaultValue: [], defaultValue: [],
setter: [{ setter: [{
@ -232,7 +233,7 @@ export default function(metadata: TransformedComponentMetadata): TransformedComp
}], }],
}, },
{ {
name: '___loopArgs.0', name: getConvertedExtraKey('loopArgs.0'),
title: { type: 'i18n', 'zh-CN': '迭代变量名', 'en-US': 'Loop Item' }, title: { type: 'i18n', 'zh-CN': '迭代变量名', 'en-US': 'Loop Item' },
setter: { setter: {
componentName: 'StringSetter', componentName: 'StringSetter',
@ -242,7 +243,7 @@ export default function(metadata: TransformedComponentMetadata): TransformedComp
}, },
}, },
{ {
name: '___loopArgs.1', name: getConvertedExtraKey('loopArgs.1'),
title: { type: 'i18n', 'zh-CN': '索引变量名', 'en-US': 'Loop Index' }, title: { type: 'i18n', 'zh-CN': '索引变量名', 'en-US': 'Loop Index' },
setter: { setter: {
componentName: 'StringSetter', componentName: 'StringSetter',