mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 10:08:34 +00:00
Revert "refactor: refactor watcher event type"
This reverts commit 6f0a575239.
This commit is contained in:
parent
8e46b4abb0
commit
20f1df47a3
6 changed files with 32 additions and 79 deletions
|
|
@ -1,27 +1,15 @@
|
|||
import { TypePoint } from '@idraw/types';
|
||||
|
||||
interface TypeBoardEventBaseData {
|
||||
currentPoint: TypePoint,
|
||||
}
|
||||
|
||||
interface TypeBoardEventData extends TypeBoardEventBaseData {
|
||||
startPoint: TypePoint | null,
|
||||
}
|
||||
|
||||
interface TypeBoardWheelEventData {
|
||||
current: number,
|
||||
}
|
||||
|
||||
export interface TypeBoardEventArgMap {
|
||||
'doubleClick': TypeBoardEventBaseData;
|
||||
'hover': TypeBoardEventBaseData;
|
||||
'leave': TypeBoardEventBaseData;
|
||||
'point': TypeBoardEventBaseData;
|
||||
'move': TypeBoardEventData;
|
||||
'moveStart': TypeBoardEventData;
|
||||
'moveEnd': TypeBoardEventData;
|
||||
'wheelX': TypeBoardWheelEventData;
|
||||
'wheelY': TypeBoardWheelEventData;
|
||||
'doubleClick': TypePoint;
|
||||
'hover': TypePoint;
|
||||
'leave': void;
|
||||
'point': TypePoint;
|
||||
'move': TypePoint;
|
||||
'moveStart': TypePoint;
|
||||
'moveEnd': TypePoint;
|
||||
'wheelX': number;
|
||||
'wheelY': number;
|
||||
}
|
||||
|
||||
export interface TypeBoardEvent {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
import { TypePoint } from '@idraw/types';
|
||||
import { deepClone } from '@idraw/util';
|
||||
import { TypePoint } from '@idraw/types'
|
||||
|
||||
type TempDataDesc = {
|
||||
moveStartPoint: TypePoint & { t?: number } | null,
|
||||
prevClickPoint: TypePoint & { t?: number } | null,
|
||||
prevClickPoint: TypePoint & { t: number } | null,
|
||||
isHoverCanvas: boolean;
|
||||
isDragCanvas: boolean;
|
||||
statusMap: {
|
||||
|
|
@ -16,7 +14,6 @@ type TempDataDesc = {
|
|||
|
||||
function createTempData() {
|
||||
return {
|
||||
moveStartPoint: null,
|
||||
prevClickPoint: null,
|
||||
isHoverCanvas: false,
|
||||
isDragCanvas: false,
|
||||
|
|
@ -41,10 +38,7 @@ export class TempData {
|
|||
this._temp[name] = value;
|
||||
}
|
||||
|
||||
get<T extends keyof TempDataDesc >(name: T, opts?: { clone: boolean }): TempDataDesc[T] {
|
||||
if (opts?.clone === true) {
|
||||
return deepClone(this._temp[name]);
|
||||
}
|
||||
get<T extends keyof TempDataDesc >(name: T): TempDataDesc[T] {
|
||||
return this._temp[name];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ export class Watcher {
|
|||
const p = this._getPosition(e);
|
||||
if (this._isVaildPoint(p)) {
|
||||
if (this._event.has('hover')) {
|
||||
this._event.trigger('hover', { currentPoint: p });
|
||||
this._event.trigger('hover', p);
|
||||
}
|
||||
}
|
||||
this._isMoving = true;
|
||||
|
|
@ -57,8 +57,7 @@ export class Watcher {
|
|||
_listenLeave(e: MouseEvent|TouchEvent): void {
|
||||
e.preventDefault();
|
||||
if (this._event.has('leave')) {
|
||||
const p = this._getPosition(e);
|
||||
this._event.trigger('leave', { currentPoint: p });
|
||||
this._event.trigger('leave', undefined);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -66,15 +65,11 @@ export class Watcher {
|
|||
e.preventDefault();
|
||||
const p = this._getPosition(e);
|
||||
if (this._isVaildPoint(p)) {
|
||||
this._temp.set('moveStartPoint', p);
|
||||
if (this._event.has('point')) {
|
||||
this._event.trigger('point', { currentPoint: p });
|
||||
this._event.trigger('point', p);
|
||||
}
|
||||
if (this._event.has('moveStart')) {
|
||||
this._event.trigger('moveStart', {
|
||||
startPoint: this._temp.get('moveStartPoint', { clone: true }),
|
||||
currentPoint: p,
|
||||
});
|
||||
this._event.trigger('moveStart', p);
|
||||
}
|
||||
}
|
||||
this._isMoving = true;
|
||||
|
|
@ -86,10 +81,7 @@ export class Watcher {
|
|||
if (this._event.has('move') && this._isMoving === true) {
|
||||
const p = this._getPosition(e);
|
||||
if (this._isVaildPoint(p)) {
|
||||
this._event.trigger('move', {
|
||||
startPoint: this._temp.get('moveStartPoint', { clone: true }),
|
||||
currentPoint: p,
|
||||
});
|
||||
this._event.trigger('move', p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -99,23 +91,19 @@ export class Watcher {
|
|||
if (this._event.has('moveEnd')) {
|
||||
const p = this._getPosition(e);
|
||||
if (this._isVaildPoint(p)) {
|
||||
this._event.trigger('moveEnd', {
|
||||
startPoint: this._temp.get('moveStartPoint', { clone: true }),
|
||||
currentPoint: p,
|
||||
});
|
||||
this._event.trigger('moveEnd', p);
|
||||
}
|
||||
}
|
||||
this._isMoving = false;
|
||||
this._temp.set('moveStartPoint', null);
|
||||
}
|
||||
|
||||
_listenWheel(e: WheelEvent) {
|
||||
e.preventDefault();
|
||||
if (this._event.has('wheelX') && (e.deltaX > 0 || e.deltaX < 0)) {
|
||||
this._event.trigger('wheelX', { current: e.deltaX });
|
||||
this._event.trigger('wheelX', e.deltaX);
|
||||
}
|
||||
if (this._event.has('wheelY') && (e.deltaY > 0 || e.deltaY < 0)) {
|
||||
this._event.trigger('wheelY', { current: e.deltaY });
|
||||
this._event.trigger('wheelY', e.deltaY);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,12 +115,12 @@ export class Watcher {
|
|||
if (this._isVaildPoint(p)) {
|
||||
const preClickPoint = this._temp.get('prevClickPoint');
|
||||
if (
|
||||
preClickPoint && preClickPoint.t && (t - preClickPoint.t <= maxLimitTime)
|
||||
preClickPoint && (t - preClickPoint.t <= maxLimitTime)
|
||||
&& Math.abs(preClickPoint.x - p.x) <= 5
|
||||
&& Math.abs(preClickPoint.y - p.y) <= 5
|
||||
) {
|
||||
if (this._event.has('doubleClick')) {
|
||||
this._event.trigger('doubleClick', { currentPoint: { x: p.x, y: p.y } });
|
||||
this._event.trigger('doubleClick', { x: p.x, y: p.y });
|
||||
}
|
||||
} else {
|
||||
this._temp.set('prevClickPoint', {x: p.x, y: p.y, t, })
|
||||
|
|
|
|||
|
|
@ -58,24 +58,6 @@ const data = {
|
|||
],
|
||||
};
|
||||
|
||||
|
||||
const data2 = {
|
||||
bgColor: "#00000015",
|
||||
elements: [
|
||||
{
|
||||
name: "rect-001",
|
||||
x: 100,
|
||||
y: 80,
|
||||
w: 160,
|
||||
h: 80,
|
||||
angle: 30,
|
||||
type: "image",
|
||||
desc: {
|
||||
src: './images/computer.png',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
export function getData() {
|
||||
return data2;
|
||||
return data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
import { Core } from './../src/index';
|
||||
import { getData } from './data.js';
|
||||
|
||||
console.log('Core =', Core)
|
||||
|
||||
var opts = {
|
||||
width: 600,
|
||||
height: 300,
|
||||
contextWidth: 400,
|
||||
contextHeight: 240,
|
||||
width: 300,
|
||||
height: 200,
|
||||
contextWidth: 300,
|
||||
contextHeight: 200,
|
||||
devicePixelRatio: 4,
|
||||
}
|
||||
// var config = {
|
||||
|
|
@ -19,8 +21,8 @@ const data = getData();
|
|||
const core = new Core(
|
||||
mount,
|
||||
Object.assign({}, opts, {
|
||||
// contextWidth: 800,
|
||||
// contextHeight: 600,
|
||||
contextWidth: 500,
|
||||
contextHeight: 400,
|
||||
}),
|
||||
{
|
||||
scrollWrapper: {
|
||||
|
|
@ -29,5 +31,3 @@ const core = new Core(
|
|||
}
|
||||
);
|
||||
core.setData(data);
|
||||
const currentData = core.getData();
|
||||
core.selectElement(currentData.elements[0].uuid)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import { diffElementResourceChange } from './../lib/diff';
|
|||
import { Core } from './../index';
|
||||
import { Mode } from './../constant/static';
|
||||
|
||||
|
||||
|
||||
export function getSelectedElements(core: Core): TypeElement<keyof TypeElemDesc>[] {
|
||||
const elems: TypeElement<keyof TypeElemDesc>[] = [];
|
||||
|
|
|
|||
Loading…
Reference in a new issue