feat: 支持用户修改 builtinComponentActions

This commit is contained in:
力皓 2020-12-15 15:50:04 +08:00
parent 5d98fddcee
commit bc183d1605
2 changed files with 47 additions and 11 deletions

View File

@ -178,10 +178,10 @@ export class ComponentMeta {
this._title = this._title =
typeof title === 'string' typeof title === 'string'
? { ? {
type: 'i18n', type: 'i18n',
'en-US': this.componentName, 'en-US': this.componentName,
'zh-CN': title, 'zh-CN': title,
} }
: title; : title;
} }
@ -243,14 +243,22 @@ export class ComponentMeta {
} }
isRootComponent(includeBlock = true) { isRootComponent(includeBlock = true) {
return this.componentName === 'Page' || this.componentName === 'Component' || (includeBlock && this.componentName === 'Block'); return (
this.componentName === 'Page' ||
this.componentName === 'Component' ||
(includeBlock && this.componentName === 'Block')
);
} }
@computed get availableActions() { @computed get availableActions() {
// eslint-disable-next-line prefer-const // eslint-disable-next-line prefer-const
let { disableBehaviors, actions } = this._transformedMetadata?.configure.component || {}; let { disableBehaviors, actions } = this._transformedMetadata?.configure.component || {};
const disabled = ensureAList(disableBehaviors) || (this.isRootComponent(false) ? ['copy', 'remove'] : null); const disabled =
actions = builtinComponentActions.concat(this.designer.getGlobalComponentActions() || [], actions || []); ensureAList(disableBehaviors) || (this.isRootComponent(false) ? ['copy', 'remove'] : null);
actions = builtinComponentActions.concat(
this.designer.getGlobalComponentActions() || [],
actions || [],
);
if (disabled) { if (disabled) {
if (disabled.includes('*')) { if (disabled.includes('*')) {
@ -331,7 +339,11 @@ export interface MetadataTransducer {
} }
const metadataTransducers: MetadataTransducer[] = []; const metadataTransducers: MetadataTransducer[] = [];
export function registerMetadataTransducer(transducer: MetadataTransducer, level = 100, id?: string) { export function registerMetadataTransducer(
transducer: MetadataTransducer,
level = 100,
id?: string,
) {
transducer.level = level; transducer.level = level;
transducer.id = id; transducer.id = id;
const i = metadataTransducers.findIndex((item) => item.level != null && item.level > level); const i = metadataTransducers.findIndex((item) => item.level != null && item.level > level);
@ -360,14 +372,14 @@ registerMetadataTransducer((metadata) => {
childWhitelist: [`${m[1]}`], childWhitelist: [`${m[1]}`],
}; };
} }
// eslint-disable-next-line no-cond-assign // eslint-disable-next-line no-cond-assign
} else if ((m = /^(.+)\.Node$/.exec(componentName))) { } else if ((m = /^(.+)\.Node$/.exec(componentName))) {
// uri match xx.Node set selfControlled: false, parentWhiteList // uri match xx.Node set selfControlled: false, parentWhiteList
// component.selfControlled = false; // component.selfControlled = false;
component.nestingRule = { component.nestingRule = {
parentWhitelist: [`${m[1]}`, componentName], parentWhitelist: [`${m[1]}`, componentName],
}; };
// eslint-disable-next-line no-cond-assign // eslint-disable-next-line no-cond-assign
} else if ((m = /^(.+)\.(Item|Node|Option)$/.exec(componentName))) { } else if ((m = /^(.+)\.(Item|Node|Option)$/.exec(componentName))) {
// uri match .Item .Node .Option set parentWhiteList // uri match .Item .Node .Option set parentWhiteList
component.nestingRule = { component.nestingRule = {
@ -440,3 +452,13 @@ export function removeBuiltinComponentAction(name: string) {
export function addBuiltinComponentAction(action: ComponentAction) { export function addBuiltinComponentAction(action: ComponentAction) {
builtinComponentActions.push(action); builtinComponentActions.push(action);
} }
export function modifyBuiltinComponentAction(
actionName,
handle: (action: ComponentAction) => void,
) {
const builtinAction = builtinComponentActions.find((action) => action.name === actionName);
if (builtinAction) {
handle(builtinAction);
}
}

View File

@ -5,7 +5,12 @@ import logger from '@ali/vu-logger';
import { render } from 'react-dom'; import { render } from 'react-dom';
import I18nUtil from './i18n-util'; import I18nUtil from './i18n-util';
import { hotkey as Hotkey, monitor } from '@ali/lowcode-editor-core'; import { hotkey as Hotkey, monitor } from '@ali/lowcode-editor-core';
import { registerMetadataTransducer } from '@ali/lowcode-designer'; import {
registerMetadataTransducer,
addBuiltinComponentAction,
removeBuiltinComponentAction,
modifyBuiltinComponentAction,
} from '@ali/lowcode-designer';
import { createElement } from 'react'; import { createElement } from 'react';
import { VE_EVENTS as EVENTS, VE_HOOKS as HOOKS, VERSION as Version } from './base/const'; import { VE_EVENTS as EVENTS, VE_HOOKS as HOOKS, VERSION as Version } from './base/const';
import Bus from './bus'; import Bus from './bus';
@ -68,8 +73,16 @@ const modules = {
Prop, Prop,
}; };
const designerHelper = {
registerMetadataTransducer,
addBuiltinComponentAction,
removeBuiltinComponentAction,
modifyBuiltinComponentAction,
};
const VisualEngine = { const VisualEngine = {
designer, designer,
designerHelper,
editor, editor,
skeleton, skeleton,
/** /**
@ -121,6 +134,7 @@ export default VisualEngine;
export { export {
designer, designer,
designerHelper,
editor, editor,
skeleton, skeleton,
/** /**