@nemigo/helpers 0.8.1 → 0.8.2

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,6 +29,15 @@ 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 & {
33
+ currentTarget: EventTarget & N;
34
+ };
35
+ export type TargetKeyboardEvent<N = HTMLDivElement> = TargetEvent<KeyboardEvent, N>;
36
+ export declare const isKeyboardEvent: (e: any) => e is KeyboardEvent;
37
+ export declare const ctxMenuHook: (call: (position: {
38
+ left: number;
39
+ top: number;
40
+ }) => void) => (e: MouseEvent | TargetKeyboardEvent<HTMLDivElement>) => void;
32
41
  /**
33
42
  * Создаёт обработчик событий для указанного элемента или окна
34
43
  *
package/dist/html.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { useConditionGuard } from "./index.js";
2
+ import { clamp, toRound } from "./phymath/index.js";
2
3
  /**
3
4
  * Проверка по глобальному `window`
4
5
  */
@@ -41,6 +42,16 @@ export const enterKeyHook = (call, { usePreventStop = "enter", condition = true,
41
42
  if (isEnter && useConditionGuard(condition))
42
43
  call?.(e);
43
44
  };
45
+ 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) });
50
+ }
51
+ else {
52
+ call({ left: toRound(e.clientX), top: toRound(e.clientY) });
53
+ }
54
+ });
44
55
  //...
45
56
  /**
46
57
  * Создаёт обработчик событий для указанного элемента или окна
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemigo/helpers",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "private": false,
5
5
  "author": {
6
6
  "name": "Vlad Logvin",
@@ -137,7 +137,7 @@
137
137
  }
138
138
  },
139
139
  "peerDependencies": {
140
- "zod": "^4.0.0"
140
+ "zod": ">=4.0.0"
141
141
  },
142
142
  "peerDependenciesMeta": {
143
143
  "zod": {