mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 02:58:05 +08:00
feat:添加beforeDispatchEvent (#4102)
This commit is contained in:
parent
a629615a4c
commit
e933ad1954
19
src/env.tsx
19
src/env.tsx
@ -6,6 +6,8 @@ import {RendererConfig} from './factory';
|
||||
import {ThemeInstance} from './theme';
|
||||
import {Action, Api, Payload, Schema} from './types';
|
||||
import hoistNonReactStatic from 'hoist-non-react-statics';
|
||||
import {IScopedContext} from './Scoped';
|
||||
import {RendererEvent} from './utils/renderer-event';
|
||||
|
||||
export interface RendererEnv {
|
||||
fetcher: (api: Api, data?: any, options?: object) => Promise<Payload>;
|
||||
@ -67,6 +69,23 @@ export interface RendererEnv {
|
||||
* 过滤 html 标签,可用来添加 xss 保护逻辑
|
||||
*/
|
||||
filterHtml: (input: string) => string;
|
||||
beforeDispatchEvent: (
|
||||
e:
|
||||
| string
|
||||
| React.ClipboardEvent<any>
|
||||
| React.DragEvent<any>
|
||||
| React.ChangeEvent<any>
|
||||
| React.KeyboardEvent<any>
|
||||
| React.TouchEvent<any>
|
||||
| React.WheelEvent<any>
|
||||
| React.AnimationEvent<any>
|
||||
| React.TransitionEvent<any>
|
||||
| React.MouseEvent<any>,
|
||||
context: any,
|
||||
scoped: IScopedContext,
|
||||
data: any,
|
||||
broadcast?: RendererEvent<any>
|
||||
) => void;
|
||||
[propName: string]: any;
|
||||
}
|
||||
|
||||
|
@ -120,6 +120,14 @@ export async function dispatchEvent(
|
||||
let unbindEvent = null;
|
||||
const eventName = typeof e === 'string' ? e : e.type;
|
||||
|
||||
renderer?.props?.env?.beforeDispatchEvent?.(
|
||||
e,
|
||||
renderer,
|
||||
scoped,
|
||||
data,
|
||||
broadcast
|
||||
);
|
||||
|
||||
if (!broadcast) {
|
||||
const eventConfig = renderer?.props?.onEvent?.[eventName];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user