From a3771f20e57ae0cc772fba2d10d9aa408ea20bb0 Mon Sep 17 00:00:00 2001 From: Ian Silva Date: Fri, 15 Mar 2024 10:44:41 -0300 Subject: [PATCH] feat: add callbacks object in mouse props --- src/components/presence-mouse/canvas/index.ts | 8 ++++---- src/components/presence-mouse/html/index.test.ts | 2 +- src/components/presence-mouse/html/index.ts | 8 ++++---- src/components/presence-mouse/types.ts | 4 +++- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/presence-mouse/canvas/index.ts b/src/components/presence-mouse/canvas/index.ts index b0760c48..e239160f 100644 --- a/src/components/presence-mouse/canvas/index.ts +++ b/src/components/presence-mouse/canvas/index.ts @@ -11,7 +11,7 @@ export class PointersCanvas extends BaseComponent { private divWrapper: HTMLElement; private presences: Map; private animateFrame: number; - private goToMouseCallback: PresenceMouseProps['onGoToPresence']; + private goToMouseCallback: PresenceMouseProps['callbacks']['onGoToPresence']; private following: string; private isPrivate: boolean; private transformation: Transform = { translate: { x: 0, y: 0 }, scale: 1 }; @@ -32,7 +32,7 @@ export class PointersCanvas extends BaseComponent { this.divWrapper = this.renderDivWrapper(); this.animateFrame = requestAnimationFrame(this.animate); - this.goToMouseCallback = options?.onGoToPresence; + this.goToMouseCallback = options?.callbacks?.onGoToPresence; } private get textColorValues(): number[] { @@ -361,11 +361,11 @@ export class PointersCanvas extends BaseComponent { }; /** - * @function transformPointer + * @function transform * @description stores that information about which transformations should the pointers go through * @param {Transform} transformation Which transformations to apply */ - public transformPointer(transformation: Transform) { + public transform(transformation: Transform) { this.transformation = transformation; } } diff --git a/src/components/presence-mouse/html/index.test.ts b/src/components/presence-mouse/html/index.test.ts index 4fa003cc..cfaa4a81 100644 --- a/src/components/presence-mouse/html/index.test.ts +++ b/src/components/presence-mouse/html/index.test.ts @@ -413,7 +413,7 @@ describe('MousePointers on HTML', () => { 'updatePresenceMouse', ); - presenceMouseComponent['transformPointer']({ translate: { x: 10, y: 10 }, scale: 1 }); + presenceMouseComponent['transform']({ translate: { x: 10, y: 10 }, scale: 1 }); const event = { currentTarget: { diff --git a/src/components/presence-mouse/html/index.ts b/src/components/presence-mouse/html/index.ts index 55986811..c513210c 100644 --- a/src/components/presence-mouse/html/index.ts +++ b/src/components/presence-mouse/html/index.ts @@ -34,7 +34,7 @@ export class PointersHTML extends BaseComponent { private transformation: Transform = { translate: { x: 0, y: 0 }, scale: 1 }; // callbacks - private goToPresenceCallback: PresenceMouseProps['onGoToPresence']; + private goToPresenceCallback: PresenceMouseProps['callbacks']['onGoToPresence']; /** * @function constructor @@ -56,7 +56,7 @@ export class PointersHTML extends BaseComponent { this.name = ComponentNames.PRESENCE; this.containerTagname = this.container.tagName.toUpperCase(); - this.goToPresenceCallback = options?.onGoToPresence; + this.goToPresenceCallback = options?.callbacks?.onGoToPresence; } // ---------- SETUP ---------- @@ -475,11 +475,11 @@ export class PointersHTML extends BaseComponent { // ---------- REGULAR METHODS ---------- /** - * @function transformPointer + * @function transform * @description stores that information about which transformations should the pointers go through * @param {Transform} transformation Which transformations to apply */ - public transformPointer(transformation: Transform) { + public transform(transformation: Transform) { this.transformation = transformation; } diff --git a/src/components/presence-mouse/types.ts b/src/components/presence-mouse/types.ts index 7b74c38a..c4571fd1 100644 --- a/src/components/presence-mouse/types.ts +++ b/src/components/presence-mouse/types.ts @@ -16,7 +16,9 @@ export interface Transform { } export interface PresenceMouseProps { - onGoToPresence?: (position: { x: number; y: number }) => void; + callbacks: { + onGoToPresence?: (position: { x: number; y: number }) => void; + }; } export type Element = HTMLElement & SVGElement;