mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 11:07:52 +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 {ThemeInstance} from './theme';
|
||||||
import {Action, Api, Payload, Schema} from './types';
|
import {Action, Api, Payload, Schema} from './types';
|
||||||
import hoistNonReactStatic from 'hoist-non-react-statics';
|
import hoistNonReactStatic from 'hoist-non-react-statics';
|
||||||
|
import {IScopedContext} from './Scoped';
|
||||||
|
import {RendererEvent} from './utils/renderer-event';
|
||||||
|
|
||||||
export interface RendererEnv {
|
export interface RendererEnv {
|
||||||
fetcher: (api: Api, data?: any, options?: object) => Promise<Payload>;
|
fetcher: (api: Api, data?: any, options?: object) => Promise<Payload>;
|
||||||
@ -67,6 +69,23 @@ export interface RendererEnv {
|
|||||||
* 过滤 html 标签,可用来添加 xss 保护逻辑
|
* 过滤 html 标签,可用来添加 xss 保护逻辑
|
||||||
*/
|
*/
|
||||||
filterHtml: (input: string) => string;
|
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;
|
[propName: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,6 +120,14 @@ export async function dispatchEvent(
|
|||||||
let unbindEvent = null;
|
let unbindEvent = null;
|
||||||
const eventName = typeof e === 'string' ? e : e.type;
|
const eventName = typeof e === 'string' ? e : e.type;
|
||||||
|
|
||||||
|
renderer?.props?.env?.beforeDispatchEvent?.(
|
||||||
|
e,
|
||||||
|
renderer,
|
||||||
|
scoped,
|
||||||
|
data,
|
||||||
|
broadcast
|
||||||
|
);
|
||||||
|
|
||||||
if (!broadcast) {
|
if (!broadcast) {
|
||||||
const eventConfig = renderer?.props?.onEvent?.[eventName];
|
const eventConfig = renderer?.props?.onEvent?.[eventName];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user