mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-02-28 21:20:28 +00:00
feat: 支持用户修改 builtinComponentActions
This commit is contained in:
parent
5d98fddcee
commit
bc183d1605
@ -178,10 +178,10 @@ export class ComponentMeta {
|
||||
this._title =
|
||||
typeof title === 'string'
|
||||
? {
|
||||
type: 'i18n',
|
||||
'en-US': this.componentName,
|
||||
'zh-CN': title,
|
||||
}
|
||||
type: 'i18n',
|
||||
'en-US': this.componentName,
|
||||
'zh-CN': title,
|
||||
}
|
||||
: title;
|
||||
}
|
||||
|
||||
@ -243,14 +243,22 @@ export class ComponentMeta {
|
||||
}
|
||||
|
||||
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() {
|
||||
// eslint-disable-next-line prefer-const
|
||||
let { disableBehaviors, actions } = this._transformedMetadata?.configure.component || {};
|
||||
const disabled = ensureAList(disableBehaviors) || (this.isRootComponent(false) ? ['copy', 'remove'] : null);
|
||||
actions = builtinComponentActions.concat(this.designer.getGlobalComponentActions() || [], actions || []);
|
||||
const disabled =
|
||||
ensureAList(disableBehaviors) || (this.isRootComponent(false) ? ['copy', 'remove'] : null);
|
||||
actions = builtinComponentActions.concat(
|
||||
this.designer.getGlobalComponentActions() || [],
|
||||
actions || [],
|
||||
);
|
||||
|
||||
if (disabled) {
|
||||
if (disabled.includes('*')) {
|
||||
@ -331,7 +339,11 @@ export interface 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.id = id;
|
||||
const i = metadataTransducers.findIndex((item) => item.level != null && item.level > level);
|
||||
@ -360,14 +372,14 @@ registerMetadataTransducer((metadata) => {
|
||||
childWhitelist: [`${m[1]}`],
|
||||
};
|
||||
}
|
||||
// eslint-disable-next-line no-cond-assign
|
||||
// eslint-disable-next-line no-cond-assign
|
||||
} else if ((m = /^(.+)\.Node$/.exec(componentName))) {
|
||||
// uri match xx.Node set selfControlled: false, parentWhiteList
|
||||
// component.selfControlled = false;
|
||||
component.nestingRule = {
|
||||
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))) {
|
||||
// uri match .Item .Node .Option set parentWhiteList
|
||||
component.nestingRule = {
|
||||
@ -440,3 +452,13 @@ export function removeBuiltinComponentAction(name: string) {
|
||||
export function addBuiltinComponentAction(action: ComponentAction) {
|
||||
builtinComponentActions.push(action);
|
||||
}
|
||||
|
||||
export function modifyBuiltinComponentAction(
|
||||
actionName,
|
||||
handle: (action: ComponentAction) => void,
|
||||
) {
|
||||
const builtinAction = builtinComponentActions.find((action) => action.name === actionName);
|
||||
if (builtinAction) {
|
||||
handle(builtinAction);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,12 @@ import logger from '@ali/vu-logger';
|
||||
import { render } from 'react-dom';
|
||||
import I18nUtil from './i18n-util';
|
||||
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 { VE_EVENTS as EVENTS, VE_HOOKS as HOOKS, VERSION as Version } from './base/const';
|
||||
import Bus from './bus';
|
||||
@ -68,8 +73,16 @@ const modules = {
|
||||
Prop,
|
||||
};
|
||||
|
||||
const designerHelper = {
|
||||
registerMetadataTransducer,
|
||||
addBuiltinComponentAction,
|
||||
removeBuiltinComponentAction,
|
||||
modifyBuiltinComponentAction,
|
||||
};
|
||||
|
||||
const VisualEngine = {
|
||||
designer,
|
||||
designerHelper,
|
||||
editor,
|
||||
skeleton,
|
||||
/**
|
||||
@ -121,6 +134,7 @@ export default VisualEngine;
|
||||
|
||||
export {
|
||||
designer,
|
||||
designerHelper,
|
||||
editor,
|
||||
skeleton,
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user