@nemigo/helpers 0.8.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/html.d.ts CHANGED
@@ -29,15 +29,21 @@ export declare const enterKeyHook: <T extends KeyboardEvent = KeyboardEvent>(cal
29
29
  usePreventStop?: "enter" | unknown | ((e: T, isEnter: boolean) => unknown);
30
30
  condition?: ((e: T) => unknown) | unknown;
31
31
  }) => (e: T) => void;
32
- export type TargetEvent<E extends Event, N = HTMLDivElement> = E & {
32
+ export type TargetEvent<E extends Event, N extends HTMLElement = HTMLDivElement> = E & {
33
33
  currentTarget: EventTarget & N;
34
34
  };
35
- export type TargetKeyboardEvent<N = HTMLDivElement> = TargetEvent<KeyboardEvent, N>;
35
+ export type TargetKeyboardEvent<N extends HTMLElement = HTMLDivElement> = TargetEvent<KeyboardEvent, N>;
36
36
  export declare const isKeyboardEvent: (e: any) => e is KeyboardEvent;
37
- export declare const ctxMenuHook: (call: (position: {
37
+ export declare const ctxMenuHook: <N extends HTMLElement = HTMLDivElement>(call: (position: {
38
38
  left: number;
39
39
  top: number;
40
- }) => void) => (e: MouseEvent | TargetKeyboardEvent<HTMLDivElement>) => void;
40
+ }, meta: {
41
+ isKeyboardEvent: true;
42
+ event: TargetKeyboardEvent<N>;
43
+ } | {
44
+ isKeyboardEvent: false;
45
+ event: MouseEvent;
46
+ }) => void) => (e: TargetKeyboardEvent<N> | MouseEvent) => void;
41
47
  /**
42
48
  * Создаёт обработчик событий для указанного элемента или окна
43
49
  *
package/dist/html.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { useConditionGuard } from "./index.js";
2
- import { clamp, toRound } from "./phymath/index.js";
3
2
  /**
4
3
  * Проверка по глобальному `window`
5
4
  */
@@ -43,13 +42,13 @@ export const enterKeyHook = (call, { usePreventStop = "enter", condition = true,
43
42
  call?.(e);
44
43
  };
45
44
  export const isKeyboardEvent = (e) => !!e.code;
46
- export const ctxMenuHook = (call) => preventStopHook((e) => {
47
- if (isKeyboardEvent(e)) {
48
- const { x, y, width } = e.currentTarget.getBoundingClientRect();
49
- call({ left: toRound(x + clamp(5, width / 10, 25), 3), top: toRound(y) });
45
+ export const ctxMenuHook = (call) => preventStopHook((event) => {
46
+ if (isKeyboardEvent(event)) {
47
+ const { x, y } = event.currentTarget.getBoundingClientRect();
48
+ call({ left: x, top: y }, { isKeyboardEvent: true, event });
50
49
  }
51
50
  else {
52
- call({ left: toRound(e.clientX), top: toRound(e.clientY) });
51
+ call({ left: event.clientX, top: event.clientY }, { isKeyboardEvent: false, event });
53
52
  }
54
53
  });
55
54
  //...
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemigo/helpers",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "private": false,
5
5
  "author": {
6
6
  "name": "Vlad Logvin",