@noya-app/noya-designsystem 0.1.2 → 0.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noya-app/noya-designsystem",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "@dnd-kit/core": "3.1.1",
14
14
  "@dnd-kit/modifiers": "3.0.0",
15
15
  "@dnd-kit/sortable": "4.0.0",
16
- "@noya-app/noya-colorpicker": "0.1.1",
16
+ "@noya-app/noya-colorpicker": "0.1.2",
17
17
  "@noya-app/noya-utils": "0.1.0",
18
18
  "@noya-app/noya-geometry": "0.1.0",
19
19
  "@noya-app/noya-icons": "0.1.0",
@@ -36,7 +36,6 @@
36
36
  "@radix-ui/react-utils": "^0.0.5",
37
37
  "immer": "9.0.5",
38
38
  "kiwi.js": "^1.1.3",
39
- "react-use-gesture": "9.1.3",
40
39
  "react-virtualized": "^9.22.3",
41
40
  "react-window": "^1.8.8",
42
41
  "styled-components": "5.3.0",
@@ -24,7 +24,6 @@ import { ListChildComponentProps, VariableSizeList } from "react-window";
24
24
  import styled from "styled-components";
25
25
  import { mergeEventHandlers } from "../hooks/mergeEventHandlers";
26
26
  import { useHover } from "../hooks/useHover";
27
- import { isLeftButtonClicked } from "../utils/mouseEvent";
28
27
  import { ContextMenu } from "./ContextMenu";
29
28
  import { InputField } from "./InputField";
30
29
  import { MenuItem } from "./internal/Menu";
@@ -386,7 +385,8 @@ const ListViewRow = forwardRef(function ListViewRow<
386
385
  // won't close (onPointerDownOutside won't fire).
387
386
  event.preventDefault();
388
387
 
389
- if (!isLeftButtonClicked(event)) return;
388
+ // We only want to handle left clicks
389
+ if (event.button !== 0) return;
390
390
 
391
391
  onPress?.(event);
392
392
  },
@@ -1,9 +1,15 @@
1
1
  import { expect, test } from "bun:test";
2
- import { ReactEventHandlers } from "react-use-gesture/dist/types";
3
- import { mergeEventHandlers } from "../..";
2
+ import { mergeEventHandlers } from "../mergeEventHandlers";
4
3
 
5
4
  const event = { defaultPrevented: false };
6
5
 
6
+ type ReactEventHandlers = {
7
+ onClick?: React.MouseEventHandler;
8
+ onMouseDown?: React.MouseEventHandler;
9
+ onMouseMove?: React.MouseEventHandler;
10
+ onMouseUp?: React.MouseEventHandler;
11
+ };
12
+
7
13
  test("merges handlers", () => {
8
14
  const out: [number, any][] = [];
9
15
 
@@ -1,46 +1,19 @@
1
- import { KeyMap } from '@noya-app/noya-keymap';
2
- import { unique } from '@noya-app/noya-utils';
3
- import { composeEventHandlers } from '@radix-ui/primitive';
4
- import { useGesture } from 'react-use-gesture';
5
- import { RegularMenuItem } from '../components/internal/Menu';
6
- import { Optional } from '../utils/createSectionedMenu';
1
+ import { unique } from "@noya-app/noya-utils";
2
+ import { composeEventHandlers } from "@radix-ui/primitive";
7
3
 
8
4
  function composeAllEventHandlers<E>(...handlers: ((e: E) => void)[]) {
9
5
  const [first, ...rest] = handlers;
10
6
 
11
7
  return rest.reduce(
12
8
  (result, handler) => composeEventHandlers(result, handler),
13
- first,
9
+ first
14
10
  );
15
11
  }
16
12
 
17
- export type ReactDOMEventHandlers = ReturnType<
18
- ReturnType<typeof useGesture>
19
- > & {
20
- onKeyDown?: (e: React.KeyboardEvent) => void;
21
- onKeyDownCapture?: (e: React.KeyboardEvent) => void;
22
- onKeyUp?: (e: React.KeyboardEvent) => void;
23
- onKeyUpCapture?: (e: React.KeyboardEvent) => void;
24
- onKeyPress?: (e: React.KeyboardEvent) => void;
25
- onKeyPressCapture?: (e: React.KeyboardEvent) => void;
26
-
27
- // Special
28
- onBeforeInput?: (e: InputEvent) => void;
29
- };
30
-
31
- export type ReactEventHandlers<MenuItemType extends string = string> =
32
- ReactDOMEventHandlers & {
33
- onContributeMenuItems?: () => Optional<RegularMenuItem<MenuItemType>>[];
34
- keyboardShortcuts?: KeyMap;
35
- onSelectMenuItem?: (id: string) => void;
36
- };
37
-
38
- export type EventName = keyof ReactEventHandlers;
39
-
40
- export function mergeEventHandlers(
41
- ...handlerMaps: ReactEventHandlers[]
42
- ): ReactEventHandlers {
43
- const eventNames = unique(handlerMaps.map(Object.keys).flat() as EventName[]);
13
+ export function mergeEventHandlers<
14
+ H extends Record<string, (...args: any[]) => any>,
15
+ >(...handlerMaps: H[]): H {
16
+ const eventNames = unique(handlerMaps.map(Object.keys).flat() as (keyof H)[]);
44
17
 
45
18
  return Object.fromEntries(
46
19
  eventNames.map((eventName) => {
@@ -49,7 +22,7 @@ export function mergeEventHandlers(
49
22
  return value ? [value] : [];
50
23
  });
51
24
 
52
- return [eventName, composeAllEventHandlers(...handlers)];
53
- }),
54
- );
25
+ return [eventName, composeAllEventHandlers(...handlers)] as const;
26
+ })
27
+ ) as H;
55
28
  }
package/src/index.tsx CHANGED
@@ -61,7 +61,6 @@ export * from "./contexts/ImageDataContext";
61
61
  // Contexts
62
62
  export * from "./contexts/GlobalInputBlurContext";
63
63
  // Hooks
64
- export * from "./hooks/mergeEventHandlers";
65
64
  export * from "./hooks/useHover";
66
65
  export * from "./hooks/usePlatform";
67
66
  export * from "./mediaQuery";
@@ -70,7 +69,6 @@ export * as darkTheme from "./theme/dark";
70
69
  export * as lightTheme from "./theme/light";
71
70
  export * from "./utils/createSectionedMenu";
72
71
  export * from "./utils/getGradientBackground";
73
- export * from "./utils/mouseEvent";
74
72
  // Utils
75
73
  export * from "./utils/completions";
76
74
  export * from "./utils/fuzzyScorer";
@@ -1,7 +0,0 @@
1
- export function isLeftButtonClicked(event: React.MouseEvent) {
2
- return event.button === 0;
3
- }
4
-
5
- export function isRightButtonClicked(event: React.MouseEvent) {
6
- return event.button === 2;
7
- }