Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: let the target be passed into dragStart #1050

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/moveable/src/MoveableManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ class MoveableManager extends EventEmitter<MoveableEventsParameters> {
public forceUpdate(callback?: () => any) {
this.innerMoveable!.forceUpdate(callback);
}
public dragStart(e: MouseEvent | TouchEvent) {
public dragStart(e: MouseEvent | TouchEvent, target: EventTarget | null = e.target) {
const innerMoveable = this.innerMoveable;
if ((innerMoveable as any).$_timer) {
this.forceUpdate();
}
this.getMoveable().dragStart(e);
this.getMoveable().dragStart(e, target);
}
public destroy() {
const selfElement = this.selfElement!;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-moveable/src/InitialMoveable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class InitialMoveable<T = {}>
* @example
* document.querySelector(".target").addEventListener("mousedown", e => {
* moveable.waitToChangeTarget().then(() => {
* moveable.dragStart(e.currentTarget);
* moveable.dragStart(e, e.currentTarget);
* });
* moveable.target = e.currentTarget;
* });
Expand Down
6 changes: 3 additions & 3 deletions packages/react-moveable/src/MoveableIndividualGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class MoveableIndividualGroup extends MoveableManager<GroupableProps & Individua
};
return requestInstant ? requester.request(param).requestEnd() : requester;
}
public dragStart(e: MouseEvent | TouchEvent) {
const inputTarget = e.target as HTMLElement;
public dragStart(e: MouseEvent | TouchEvent, target: EventTarget | null = e.target) {
const inputTarget = target as HTMLElement;
const childMoveable = find(this.moveables, child => {
const target = child.getTargets()[0];
const controlBoxElement = child.getControlBoxElement();
Expand All @@ -104,7 +104,7 @@ class MoveableIndividualGroup extends MoveableManager<GroupableProps & Individua
});

if (childMoveable) {
childMoveable.dragStart(e);
childMoveable.dragStart(e, target);
}
return this;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/react-moveable/src/MoveableManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,15 @@ export default class MoveableManager<T = {}>
* }
* });
*/
public dragStart(e: MouseEvent | TouchEvent) {
public dragStart(e: MouseEvent | TouchEvent, target: EventTarget | null = e.target) {
const targetGesto = this.targetGesto;
const controlGesto = this.controlGesto;

if (targetGesto && checkMoveableTarget(this)({ inputEvent: e })) {
if (targetGesto && checkMoveableTarget(this)({ inputEvent: e }, target)) {
if (!targetGesto.isFlag()) {
targetGesto.triggerDragStart(e);
}
} else if (controlGesto && this.isMoveableElement(e.target as Element)) {
} else if (controlGesto && this.isMoveableElement(target as Element)) {
if (!controlGesto.isFlag()) {
controlGesto.triggerDragStart(e);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-moveable/src/gesto/getAbleGesto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ export function triggerAble(
}

export function checkMoveableTarget(moveable: MoveableManagerInterface) {
return (e: { inputEvent: Event }) => {
const eventTarget = e.inputEvent.target as Element;
return (e: { inputEvent: Event }, target: EventTarget | null = e.inputEvent.target) => {
const eventTarget = target as Element;
const areaElement = moveable.areaElement;
const dragTargetElement = (moveable as any)._dragTarget;

Expand Down
2 changes: 1 addition & 1 deletion packages/react-moveable/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3435,7 +3435,7 @@ export interface MoveableInterface {
*/
getDragElement(): HTMLElement | SVGElement | null | undefined;
destroy(): void;
dragStart(e: MouseEvent | TouchEvent): void;
dragStart(e: MouseEvent | TouchEvent, target?: EventTarget | null): void;
isInside(clientX: number, clientY: number): boolean;
isDragging(ableName?: string): boolean;
hitTest(el: Element | HitRect): number;
Expand Down