merge pre-release

Change-Id: Ie4c4024e2cbe75651845f51ac25129e69266ff6e
This commit is contained in:
allenve 2022-07-28 17:50:24 +08:00
commit fd9ffd4e0c
5 changed files with 68 additions and 57 deletions

View File

@ -129,11 +129,9 @@ export default class APIControl extends React.Component<
componentDidUpdate(prevProps: APIControlProps) { componentDidUpdate(prevProps: APIControlProps) {
const props = this.props; const props = this.props;
if (prevProps.value !== props.value) { if (prevProps.value !== props.value) {
this.setState({apiStr: this.transformApi2Str(props.value)}); this.setState({apiStr: this.transformApi2Str(props.value)});
} }
if (anyChanged(['enablePickerMode', 'pickerSchema'], prevProps, props)) { if (anyChanged(['enablePickerMode', 'pickerSchema'], prevProps, props)) {
this.setState({schema: props.pickerSchema}); this.setState({schema: props.pickerSchema});
} }
@ -198,7 +196,6 @@ export default class APIControl extends React.Component<
if (typeof value !== 'string' || typeof values !== 'string') { if (typeof value !== 'string' || typeof values !== 'string') {
api = merge({}, normalizeApi(values)); api = merge({}, normalizeApi(values));
} }
onChange?.(api); onChange?.(api);
} }

View File

@ -116,7 +116,6 @@ export default class ActionDialog extends React.Component<ActionDialogProp> {
} }
const actionNode = findActionNode(actionTree, value); const actionNode = findActionNode(actionTree, value);
form.setValues({ form.setValues({
...removeKeys, ...removeKeys,
__keywords: form.data.__keywords, __keywords: form.data.__keywords,
@ -158,7 +157,6 @@ export default class ActionDialog extends React.Component<ActionDialogProp> {
commonActions, commonActions,
onClose onClose
} = this.props; } = this.props;
return amisRender( return amisRender(
{ {
type: 'dialog', type: 'dialog',

View File

@ -192,6 +192,7 @@ const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
manager.openSubEditor({ manager.openSubEditor({
title: '配置弹框内容', title: '配置弹框内容',
value: {type: 'dialog', ...value}, value: {type: 'dialog', ...value},
data,
onChange: (value: any) => onChange(value) onChange: (value: any) => onChange(value)
}) })
} }

View File

@ -23,6 +23,7 @@ import {
import CmptActionSelect from './comp-action-select'; import CmptActionSelect from './comp-action-select';
import {Button} from 'amis'; import {Button} from 'amis';
import ACTION_TYPE_TREE from './actions'; import ACTION_TYPE_TREE from './actions';
import { stores } from 'amis-core/lib/factory';
// 数据容器范围 // 数据容器范围
export const DATA_CONTAINER = [ export const DATA_CONTAINER = [
@ -957,6 +958,7 @@ export const getEventControlConfig = (
manager: EditorManager, manager: EditorManager,
context: BaseEventContext context: BaseEventContext
) => { ) => {
const isSubEditor = manager.store.isSubEditor;
// 通用动作配置 // 通用动作配置
const commonActions = const commonActions =
manager?.config.actionOptions?.customActionGetter?.(manager); manager?.config.actionOptions?.customActionGetter?.(manager);
@ -964,7 +966,49 @@ export const getEventControlConfig = (
const actionTree = manager?.config.actionOptions?.actionTreeGetter const actionTree = manager?.config.actionOptions?.actionTreeGetter
? manager?.config.actionOptions?.actionTreeGetter(ACTION_TYPE_TREE(manager)) ? manager?.config.actionOptions?.actionTreeGetter(ACTION_TYPE_TREE(manager))
: ACTION_TYPE_TREE(manager); : ACTION_TYPE_TREE(manager);
const allComponents = mapTree(
manager?.store?.outline ?? [],
(item: any) => {
const schema = manager?.store?.getSchema(item.id);
return {
id: item.id,
label: item.label,
value: schema?.id ?? item.id,
type: schema?.type ?? item.type,
schema,
disabled: !!item.region,
children: item?.children
};
},
1,
true
);
const checkComponent = (node: any, action: RendererPluginAction) => {
const actionType = action.actionType;
const actions = manager?.pluginActions[node.type];
const haveChild = !!node.children?.length;
let isSupport = false;
if (typeof action.supportComponents === 'string') {
isSupport =
action.supportComponents === '*' ||
action.supportComponents === node.type;
} else if (Array.isArray(action.supportComponents)) {
isSupport = action.supportComponents.includes(node.type);
}
if (['reload', 'setValue'].includes(actionType)) {
isSupport = hasActionType(actionType, actions);
}
if (actionType === 'component' && !actions?.length) {
node.disabled = true;
}
if (isSupport) {
return true;
} else if (haveChild) {
node.disabled = true;
return true;
}
return false;
}
return { return {
showOldEntry: showOldEntry:
!!context.schema.actionType || !!context.schema.actionType ||
@ -976,6 +1020,7 @@ export const getEventControlConfig = (
owner: '', owner: '',
addBroadcast: manager?.addBroadcast, addBroadcast: manager?.addBroadcast,
removeBroadcast: manager?.removeBroadcast, removeBroadcast: manager?.removeBroadcast,
allComponents: allComponents,
getContextSchemas: async (id?: string, withoutSuper?: boolean) => { getContextSchemas: async (id?: string, withoutSuper?: boolean) => {
const dataSchema = await manager.getContextSchemas( const dataSchema = await manager.getContextSchemas(
id ?? context!.id, id ?? context!.id,
@ -988,56 +1033,23 @@ export const getEventControlConfig = (
return manager.dataSchema; return manager.dataSchema;
}, },
getComponents: (action: RendererPluginAction) => { getComponents: (action: RendererPluginAction) => {
const actionType = action.actionType!; let components = allComponents;
const components = filterTree( if (isSubEditor) {
mapTree( let superTree = manager.store.getSuperEditorData;
manager?.store?.outline ?? [], while(superTree) {
(item: any) => { if (superTree.__superCmptTreeSource) {
const schema = manager?.store?.getSchema(item.id); components = components.concat(superTree.__superCmptTreeSource);
return {
id: item.id,
label: item.label,
value: schema?.id ?? item.id,
type: schema?.type ?? item.type,
schema,
disabled: !!item.region,
children: item?.children
};
},
1,
true
),
node => {
const actions = manager?.pluginActions[node.type];
let isSupport = false;
if (typeof action.supportComponents === 'string') {
isSupport =
action.supportComponents === '*' ||
action.supportComponents === node.type;
} else if (Array.isArray(action.supportComponents)) {
isSupport = action.supportComponents.includes(node.type);
} }
if (['reload', 'setValue'].includes(actionType)) { superTree = superTree.__super;
isSupport = hasActionType(actionType, actions); }
} }
const result = filterTree(
if (actionType === 'component' && !actions?.length) { components,
node.disabled = true; (node) => checkComponent(node, action),
}
if (isSupport) {
return true;
} else if (!isSupport && !!node.children?.length) {
node.disabled = true;
return true;
}
return false;
},
1, 1,
true true
); );
return result;
return components;
}, },
actionConfigInitFormatter: (action: ActionConfig) => { actionConfigInitFormatter: (action: ActionConfig) => {
let config = {...action}; let config = {...action};

View File

@ -73,6 +73,7 @@ interface EventControlState {
groupType?: string; groupType?: string;
__actionDesc?: string; __actionDesc?: string;
__cmptTreeSource?: ComponentInfo[]; __cmptTreeSource?: ComponentInfo[];
__superCmptTreeSource?: ComponentInfo[];
__actionSchema?: any; __actionSchema?: any;
__subActions?: SubRendererPluginAction[]; __subActions?: SubRendererPluginAction[];
__setValueDs?: any[]; __setValueDs?: any[];
@ -492,13 +493,13 @@ export class EventControl extends React.Component<
getContextSchemas, getContextSchemas,
actionConfigInitFormatter, actionConfigInitFormatter,
getComponents, getComponents,
actionTree actionTree,
allComponents
} = this.props; } = this.props;
const {rawVariables} = this.state; const {rawVariables} = this.state;
// 收集事件变量 // 收集事件变量
const eventVariables = this.getEventVariables(data); const eventVariables = this.getEventVariables(data);
const variables = [...eventVariables, ...rawVariables]; const variables = [...eventVariables, ...rawVariables];
// 编辑操作,需要格式化动作配置 // 编辑操作,需要格式化动作配置
if (data.type === 'update') { if (data.type === 'update') {
const action = data.actionData!.action!; const action = data.actionData!.action!;
@ -521,7 +522,7 @@ export class EventControl extends React.Component<
item => item.value !== '$$id' item => item.value !== '$$id'
); );
} }
} };
data.actionData = { data.actionData = {
eventKey: data.actionData!.eventKey, eventKey: data.actionData!.eventKey,
actionIndex: data.actionData!.actionIndex, actionIndex: data.actionData!.actionIndex,
@ -537,6 +538,8 @@ export class EventControl extends React.Component<
__cmptTreeSource: actionConfig?.componentId __cmptTreeSource: actionConfig?.componentId
? getComponents?.(actionNode!) ?? [] ? getComponents?.(actionNode!) ?? []
: [], : [],
__superCmptTreeSource: allComponents,
// __supersCmptTreeSource: '',
__setValueDs: setValueDs __setValueDs: setValueDs
// broadcastId: action.actionType === 'broadcast' ? action.eventName : '' // broadcastId: action.actionType === 'broadcast' ? action.eventName : ''
}; };
@ -554,10 +557,10 @@ export class EventControl extends React.Component<
variables, variables,
pluginActions, pluginActions,
getContextSchemas, getContextSchemas,
rawVariables rawVariables,
__superCmptTreeSource: allComponents
}; };
} }
this.setState(data); this.setState(data);
} }