feat: update plugin type

This commit is contained in:
chenshenhai 2021-11-21 17:45:23 +08:00
parent 3ddd6a2e22
commit 88620b5f3a
2 changed files with 71 additions and 33 deletions

View file

@ -1,7 +1,47 @@
import { InterfacePlugin } from '@idraw/types';
import {
InterfaceHelperPlugin, TypeHelperPluginEventDetail,
TypeHelperPluginEventResult,
} from '@idraw/types';
import util from '@idraw/util';
export class HelperPlugin implements Required<InterfaceHelperPlugin> {
readonly name: string = 'helper-plugin';
readonly uuid: string;
export class HelperPlugin implements InterfacePlugin {
constructor() {
// TODO
this.uuid = util.uuid.createUUID();
}
onHover(detail: TypeHelperPluginEventDetail): void | TypeHelperPluginEventResult {
if (detail.controller === null) {
}
}
onPoint(detail: TypeHelperPluginEventDetail): void | TypeHelperPluginEventResult {
}
onClick(detail: TypeHelperPluginEventDetail): void | TypeHelperPluginEventResult {
}
onMoveStart(detail: TypeHelperPluginEventDetail): void | TypeHelperPluginEventResult {
}
onMove(detail: TypeHelperPluginEventDetail): void | TypeHelperPluginEventResult {
}
onMoveEnd(detail: TypeHelperPluginEventDetail): void | TypeHelperPluginEventResult {
}
}

View file

@ -3,36 +3,34 @@ import { TypeElemDesc, TypeElement } from './element';
import { TypeContext } from './context';
import { TypePoint, TypePointCursor } from './board';
export type TypeHelperPluginEventDetail = {
controller: string | null,
point: TypePoint,
selectedElement: TypeElement<keyof TypeElemDesc> | null,
data: TypeData,
helperCtx:TypeContext,
}
export interface InterfacePlugin {
onHover?: (detail: {
point: TypePoint,
selectedElement: TypeElement<keyof TypeElemDesc> | null,
data: TypeData,
helperCtx:TypeContext,
}) => void | { cursor?: TypePointCursor };
onClick?: (detail: {
point: TypePoint,
selectedElement: TypeElement<keyof TypeElemDesc> | null,
data: TypeData,
helperCtx:TypeContext
}) => void;
onMoveStart?: (detail: {
point: TypePoint,
selectedElement: TypeElement<keyof TypeElemDesc> | null,
data: TypeData,
helperCtx:TypeContext
}) => void;
onMove?: (detail: {
point: TypePoint,
selectedElement: TypeElement<keyof TypeElemDesc> | null,
data: TypeData,
helperCtx:TypeContext
}) => void;
onMoveEnd?: (detail: {
point: TypePoint,
selectedElement?: TypeElement<keyof TypeElemDesc> | null,
data: TypeData,
helperCtx:TypeContext
}) => void;
export type TypeHelperPluginEventResult = {
cursor?: TypePointCursor,
beController?: boolean;
}
export interface InterfaceHelperPlugin {
readonly name?: string;
readonly uuid?: string;
onHover?: (detail: TypeHelperPluginEventDetail) => void | TypeHelperPluginEventResult;
onPoint?: (detail: TypeHelperPluginEventDetail) => void | TypeHelperPluginEventResult;
onClick?: (detail: TypeHelperPluginEventDetail) => void | TypeHelperPluginEventResult;
onMoveStart?: (detail: TypeHelperPluginEventDetail) => void | TypeHelperPluginEventResult;
onMove?: (detail: TypeHelperPluginEventDetail) => void | TypeHelperPluginEventResult;
onMoveEnd?: (detail: TypeHelperPluginEventDetail) => void | TypeHelperPluginEventResult;
}