@berenjena/react-dev-panel 0.0.1-beta.1

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.
Files changed (118) hide show
  1. package/README.md +1 -0
  2. package/dist/assets/BooleanControl.css +1 -0
  3. package/dist/assets/ButtonControl.css +1 -0
  4. package/dist/assets/ColorControl.css +1 -0
  5. package/dist/assets/DevPanel.css +1 -0
  6. package/dist/assets/EmptyContent.css +1 -0
  7. package/dist/assets/NumberControl.css +1 -0
  8. package/dist/assets/Section.css +1 -0
  9. package/dist/assets/SelectControl.css +1 -0
  10. package/dist/assets/TextControl.css +1 -0
  11. package/dist/assets/index.css +1 -0
  12. package/dist/components/ControlRenderer/ControlRenderer.d.ts +6 -0
  13. package/dist/components/ControlRenderer/ControlRenderer.js +8 -0
  14. package/dist/components/ControlRenderer/controls/BooleanControl/BooleanControl.d.ts +16 -0
  15. package/dist/components/ControlRenderer/controls/BooleanControl/BooleanControl.js +24 -0
  16. package/dist/components/ControlRenderer/controls/BooleanControl/index.d.ts +1 -0
  17. package/dist/components/ControlRenderer/controls/BooleanControl/index.js +4 -0
  18. package/dist/components/ControlRenderer/controls/ButtonControl/ButtonControl.d.ts +16 -0
  19. package/dist/components/ControlRenderer/controls/ButtonControl/ButtonControl.js +10 -0
  20. package/dist/components/ControlRenderer/controls/ButtonControl/index.d.ts +1 -0
  21. package/dist/components/ControlRenderer/controls/ButtonControl/index.js +4 -0
  22. package/dist/components/ControlRenderer/controls/ColorControl/ColorControl.d.ts +16 -0
  23. package/dist/components/ControlRenderer/controls/ColorControl/ColorControl.js +19 -0
  24. package/dist/components/ControlRenderer/controls/ColorControl/index.d.ts +1 -0
  25. package/dist/components/ControlRenderer/controls/ColorControl/index.js +4 -0
  26. package/dist/components/ControlRenderer/controls/NumberControl/NumberControl.d.ts +16 -0
  27. package/dist/components/ControlRenderer/controls/NumberControl/NumberControl.js +22 -0
  28. package/dist/components/ControlRenderer/controls/NumberControl/index.d.ts +1 -0
  29. package/dist/components/ControlRenderer/controls/NumberControl/index.js +4 -0
  30. package/dist/components/ControlRenderer/controls/SelectControl/SelectControl.d.ts +15 -0
  31. package/dist/components/ControlRenderer/controls/SelectControl/SelectControl.js +13 -0
  32. package/dist/components/ControlRenderer/controls/SelectControl/index.d.ts +1 -0
  33. package/dist/components/ControlRenderer/controls/SelectControl/index.js +4 -0
  34. package/dist/components/ControlRenderer/controls/TextControl/TextControl.d.ts +17 -0
  35. package/dist/components/ControlRenderer/controls/TextControl/TextControl.js +20 -0
  36. package/dist/components/ControlRenderer/controls/TextControl/index.d.ts +1 -0
  37. package/dist/components/ControlRenderer/controls/TextControl/index.js +4 -0
  38. package/dist/components/ControlRenderer/controls/index.d.ts +13 -0
  39. package/dist/components/ControlRenderer/controls/index.js +37 -0
  40. package/dist/components/ControlRenderer/index.d.ts +1 -0
  41. package/dist/components/ControlRenderer/index.js +4 -0
  42. package/dist/components/DevPanel/DevPanel.d.ts +11 -0
  43. package/dist/components/DevPanel/DevPanel.js +74 -0
  44. package/dist/components/DevPanel/index.d.ts +1 -0
  45. package/dist/components/DevPanel/index.js +4 -0
  46. package/dist/components/EmptyContent/EmptyContent.d.ts +1 -0
  47. package/dist/components/EmptyContent/EmptyContent.js +18 -0
  48. package/dist/components/EmptyContent/index.d.ts +1 -0
  49. package/dist/components/EmptyContent/index.js +4 -0
  50. package/dist/components/Section/Section.d.ts +7 -0
  51. package/dist/components/Section/Section.js +23 -0
  52. package/dist/components/Section/index.d.ts +1 -0
  53. package/dist/components/Section/index.js +4 -0
  54. package/dist/components/index.d.ts +2 -0
  55. package/dist/components/index.js +7 -0
  56. package/dist/components/logger.d.ts +5 -0
  57. package/dist/components/logger.js +7 -0
  58. package/dist/hooks/useDevPanel/index.d.ts +1 -0
  59. package/dist/hooks/useDevPanel/index.js +4 -0
  60. package/dist/hooks/useDevPanel/useDevPanel.d.ts +24 -0
  61. package/dist/hooks/useDevPanel/useDevPanel.js +15 -0
  62. package/dist/hooks/useDragAndDrop/index.d.ts +1 -0
  63. package/dist/hooks/useDragAndDrop/index.js +4 -0
  64. package/dist/hooks/useDragAndDrop/useDragAndDrop.d.ts +16 -0
  65. package/dist/hooks/useDragAndDrop/useDragAndDrop.js +55 -0
  66. package/dist/hooks/useHotkeys/example.d.ts +5 -0
  67. package/dist/hooks/useHotkeys/example.js +266 -0
  68. package/dist/hooks/useHotkeys/index.d.ts +2 -0
  69. package/dist/hooks/useHotkeys/index.js +6 -0
  70. package/dist/hooks/useHotkeys/useHotkey.d.ts +17 -0
  71. package/dist/hooks/useHotkeys/useHotkey.js +7 -0
  72. package/dist/hooks/useHotkeys/useHotkeys.d.ts +38 -0
  73. package/dist/hooks/useHotkeys/useHotkeys.js +31 -0
  74. package/dist/index.d.ts +1 -0
  75. package/dist/index.js +7 -0
  76. package/dist/utils/className/className.d.ts +14 -0
  77. package/dist/utils/className/className.js +15 -0
  78. package/dist/utils/className/index.d.ts +1 -0
  79. package/dist/utils/className/index.js +4 -0
  80. package/dist/utils/createHotkey/createHotkey.d.ts +19 -0
  81. package/dist/utils/createHotkey/createHotkey.js +14 -0
  82. package/dist/utils/createHotkey/index.d.ts +1 -0
  83. package/dist/utils/createHotkey/index.js +4 -0
  84. package/dist/utils/debounce/debounce.d.ts +7 -0
  85. package/dist/utils/debounce/debounce.js +9 -0
  86. package/dist/utils/debounce/index.d.ts +1 -0
  87. package/dist/utils/debounce/index.js +4 -0
  88. package/dist/utils/formatHotkey/formatHotkey.d.ts +12 -0
  89. package/dist/utils/formatHotkey/formatHotkey.js +8 -0
  90. package/dist/utils/formatHotkey/index.d.ts +1 -0
  91. package/dist/utils/formatHotkey/index.js +4 -0
  92. package/dist/utils/getConstrainedPosition/getConstrainedPosition.d.ts +8 -0
  93. package/dist/utils/getConstrainedPosition/getConstrainedPosition.js +10 -0
  94. package/dist/utils/getConstrainedPosition/index.d.ts +1 -0
  95. package/dist/utils/getConstrainedPosition/index.js +4 -0
  96. package/dist/utils/getCurrentElementPosition/getCurrentElementPosition.d.ts +7 -0
  97. package/dist/utils/getCurrentElementPosition/getCurrentElementPosition.js +10 -0
  98. package/dist/utils/getCurrentElementPosition/index.d.ts +1 -0
  99. package/dist/utils/getCurrentElementPosition/index.js +4 -0
  100. package/dist/utils/getPositionAdjustment/getPositionAdjustment.d.ts +10 -0
  101. package/dist/utils/getPositionAdjustment/getPositionAdjustment.js +16 -0
  102. package/dist/utils/getPositionAdjustment/index.d.ts +1 -0
  103. package/dist/utils/getPositionAdjustment/index.js +4 -0
  104. package/dist/utils/hasControlChanged/hasControlChanged.d.ts +5 -0
  105. package/dist/utils/hasControlChanged/hasControlChanged.js +14 -0
  106. package/dist/utils/hasControlChanged/index.d.ts +1 -0
  107. package/dist/utils/hasControlChanged/index.js +4 -0
  108. package/dist/utils/index.d.ts +10 -0
  109. package/dist/utils/index.js +27 -0
  110. package/dist/utils/isMacOS/index.d.ts +1 -0
  111. package/dist/utils/isMacOS/index.js +4 -0
  112. package/dist/utils/isMacOS/isMacOS.d.ts +5 -0
  113. package/dist/utils/isMacOS/isMacOS.js +6 -0
  114. package/dist/utils/store/index.d.ts +1 -0
  115. package/dist/utils/store/index.js +9 -0
  116. package/dist/utils/store/store.d.ts +40 -0
  117. package/dist/utils/store/store.js +103 -0
  118. package/package.json +97 -0
@@ -0,0 +1,24 @@
1
+ import { ControlsGroup } from '../../components/ControlRenderer/controls/types';
2
+ /**
3
+ * Hook to register controls in the dev panel
4
+ * @param sectionName - Section name (e.g: 'Global', 'HomePage')
5
+ * @param controls - Controls configuration
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * useDevPanel('Global', {
10
+ * theme: {
11
+ * type: 'select',
12
+ * value: 'light',
13
+ * options: ['light', 'dark'],
14
+ * onChange: (value) => setTheme(value)
15
+ * },
16
+ * debugMode: {
17
+ * type: 'boolean',
18
+ * value: false,
19
+ * onChange: (value) => setDebugMode(value)
20
+ * }
21
+ * });
22
+ * ```
23
+ */
24
+ export declare function useDevPanel(sectionName: string, controls: ControlsGroup): void;
@@ -0,0 +1,15 @@
1
+ import { useRef as u, useEffect as s } from "react";
2
+ import { hasControlsChanged as f } from "../../utils/hasControlChanged/hasControlChanged.js";
3
+ import { useDevPanelActions as c, useDevPanelSections as v } from "../../utils/store/store.js";
4
+ function C(e, t) {
5
+ const r = c(), n = v(), o = u(void 0);
6
+ s(() => {
7
+ const i = n[e] !== void 0;
8
+ (f(t, o.current) || !i) && (r.registerSection(e, t), o.current = t);
9
+ }, [r, e, t, n]), s(() => () => {
10
+ r.unregisterSection(e);
11
+ }, [r, e]);
12
+ }
13
+ export {
14
+ C as useDevPanel
15
+ };
@@ -0,0 +1 @@
1
+ export * from './useDragAndDrop';
@@ -0,0 +1,4 @@
1
+ import { useDragAndDrop as e } from "./useDragAndDrop.js";
2
+ export {
3
+ e as useDragAndDrop
4
+ };
@@ -0,0 +1,16 @@
1
+ import { Position } from '../../types';
2
+ export interface UseDragAndDropProps {
3
+ onPositionChange: (position: Position) => void;
4
+ }
5
+ /**
6
+ * Custom hook to handle drag and drop functionality
7
+ * Separates the drag logic from the main component
8
+ * Includes boundary constraints and window resize handling
9
+ */
10
+ export declare function useDragAndDrop({ onPositionChange }: UseDragAndDropProps): {
11
+ isDragging: boolean;
12
+ elementRef: import('react').RefObject<HTMLDivElement | null>;
13
+ handleMouseDown: (e: React.MouseEvent) => void;
14
+ stopDragging: () => void;
15
+ adjustPositionForResize: () => void;
16
+ };
@@ -0,0 +1,55 @@
1
+ import { useRef as p, useState as l, useCallback as c, useEffect as f } from "react";
2
+ import { debounce as E } from "../../utils/debounce/debounce.js";
3
+ import { getConstrainedPosition as D } from "../../utils/getConstrainedPosition/getConstrainedPosition.js";
4
+ import { getPositionAdjustment as L } from "../../utils/getPositionAdjustment/getPositionAdjustment.js";
5
+ function z({ onPositionChange: i }) {
6
+ const o = p(null), [t, a] = l(!1), [u, v] = l({ x: 0, y: 0 }), m = c(() => {
7
+ const e = o.current;
8
+ if (!e) return;
9
+ const { constrainedPosition: n, needsAdjustment: d } = L(e);
10
+ d && i(n);
11
+ }, [i]), s = c(
12
+ (e) => {
13
+ if (!t || !o.current) return;
14
+ const n = {
15
+ x: e.clientX - u.x,
16
+ y: e.clientY - u.y
17
+ }, d = D(n, o.current);
18
+ i(d);
19
+ },
20
+ [t, u.x, u.y, i]
21
+ ), r = c(() => {
22
+ a(!1);
23
+ }, []), g = c((e) => {
24
+ if (e.target !== e.currentTarget) return;
25
+ e.preventDefault(), a(!0);
26
+ const n = o.current?.getBoundingClientRect();
27
+ n && v({
28
+ x: e.clientX - n.left,
29
+ y: e.clientY - n.top
30
+ });
31
+ }, []);
32
+ return f(() => {
33
+ if (!t) return;
34
+ const e = { passive: !0 };
35
+ return document.addEventListener("mousemove", s, e), document.addEventListener("mouseup", r, e), () => {
36
+ document.removeEventListener("mousemove", s), document.removeEventListener("mouseup", r);
37
+ };
38
+ }, [t, s, r]), f(() => {
39
+ const e = E(m, 100);
40
+ return window.addEventListener("resize", e), () => {
41
+ window.removeEventListener("resize", e);
42
+ };
43
+ }, [m]), f(() => () => {
44
+ t && (document.removeEventListener("mousemove", s), document.removeEventListener("mouseup", r));
45
+ }, [t, s, r]), {
46
+ isDragging: t,
47
+ elementRef: o,
48
+ handleMouseDown: g,
49
+ stopDragging: r,
50
+ adjustPositionForResize: m
51
+ };
52
+ }
53
+ export {
54
+ z as useDragAndDrop
55
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Ejemplo de uso del hook useHotkeys
3
+ * Este componente demuestra diferentes formas de usar el hook
4
+ */
5
+ export declare function HotkeysExample(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,266 @@
1
+ import { jsxs as i, jsx as e } from "react/jsx-runtime";
2
+ import { useState as p, useCallback as o } from "react";
3
+ import { createHotkey as y } from "../../utils/createHotkey/createHotkey.js";
4
+ import { useHotkeys as m } from "./useHotkeys.js";
5
+ function w() {
6
+ const [d, s] = p(""), [l, a] = p(!1), [r, f] = p([]), [n, u] = p(-1), g = o(() => {
7
+ if (d.trim()) {
8
+ const t = [...r, d];
9
+ f(t), u(t.length - 1), alert(`Guardado: "${d}"`);
10
+ }
11
+ }, [d, r]), h = o(() => {
12
+ s(""), a(!1);
13
+ }, []), x = o(() => {
14
+ if (n > 0) {
15
+ const t = n - 1;
16
+ s(r[t]), u(t);
17
+ }
18
+ }, [r, n]), k = o(() => {
19
+ if (n < r.length - 1) {
20
+ const t = n + 1;
21
+ s(r[t]), u(t);
22
+ }
23
+ }, [r, n]), b = o(() => {
24
+ l && a(!1);
25
+ }, [l]), E = o(() => {
26
+ a(!l);
27
+ }, [l]), K = o(() => {
28
+ const t = document.getElementById("example-input");
29
+ t && t.focus();
30
+ }, []);
31
+ m(
32
+ [
33
+ {
34
+ key: "s",
35
+ ctrlKey: !0,
36
+ action: g,
37
+ description: "Guardar",
38
+ preventDefault: !0
39
+ },
40
+ {
41
+ key: "z",
42
+ ctrlKey: !0,
43
+ action: x,
44
+ description: "Deshacer",
45
+ preventDefault: !0
46
+ },
47
+ {
48
+ key: "z",
49
+ ctrlKey: !0,
50
+ shiftKey: !0,
51
+ action: k,
52
+ description: "Rehacer",
53
+ preventDefault: !0
54
+ },
55
+ {
56
+ key: "Escape",
57
+ action: b,
58
+ description: "Cancelar edición"
59
+ },
60
+ {
61
+ key: "e",
62
+ ctrlKey: !0,
63
+ action: E,
64
+ description: "Alternar edición",
65
+ preventDefault: !0
66
+ },
67
+ {
68
+ key: "l",
69
+ ctrlKey: !0,
70
+ action: h,
71
+ description: "Limpiar",
72
+ preventDefault: !0
73
+ },
74
+ {
75
+ key: "f",
76
+ ctrlKey: !0,
77
+ action: K,
78
+ description: "Enfocar input",
79
+ preventDefault: !0
80
+ }
81
+ ],
82
+ {
83
+ enabled: !0,
84
+ target: window
85
+ }
86
+ );
87
+ const v = y(
88
+ "k",
89
+ () => {
90
+ alert("Función de búsqueda activada!");
91
+ },
92
+ { meta: !0 },
93
+ { description: "Buscar" }
94
+ ), C = y(
95
+ "Delete",
96
+ () => {
97
+ h();
98
+ },
99
+ {},
100
+ { description: "Eliminar todo", enabled: l }
101
+ );
102
+ m([v, C]);
103
+ const H = [
104
+ { key: "s", ctrlKey: !0, description: "Guardar" },
105
+ { key: "z", ctrlKey: !0, description: "Deshacer" },
106
+ { key: "z", ctrlKey: !0, shiftKey: !0, description: "Rehacer" },
107
+ { key: "e", ctrlKey: !0, description: "Alternar edición" },
108
+ { key: "l", ctrlKey: !0, description: "Limpiar" },
109
+ { key: "f", ctrlKey: !0, description: "Enfocar input" },
110
+ { key: "k", metaKey: !0, description: "Buscar" },
111
+ { key: "Delete", description: "Eliminar todo (solo en modo edición)" },
112
+ { key: "Escape", description: "Cancelar edición" }
113
+ ];
114
+ return /* @__PURE__ */ i("div", { style: { padding: "20px", maxWidth: "600px", margin: "0 auto" }, children: [
115
+ /* @__PURE__ */ e("h2", { children: "Ejemplo de useHotkeys Hook" }),
116
+ /* @__PURE__ */ i("div", { style: { marginBottom: "20px" }, children: [
117
+ /* @__PURE__ */ e("label", { htmlFor: "example-input", children: "Texto:" }),
118
+ /* @__PURE__ */ e(
119
+ "input",
120
+ {
121
+ id: "example-input",
122
+ type: "text",
123
+ value: d,
124
+ onChange: (t) => s(t.target.value),
125
+ onFocus: () => a(!0),
126
+ onBlur: () => a(!1),
127
+ style: {
128
+ width: "100%",
129
+ padding: "10px",
130
+ margin: "5px 0",
131
+ border: l ? "2px solid blue" : "1px solid gray",
132
+ borderRadius: "4px"
133
+ },
134
+ placeholder: "Escribe algo aquí..."
135
+ }
136
+ )
137
+ ] }),
138
+ /* @__PURE__ */ i("div", { style: { marginBottom: "20px" }, children: [
139
+ /* @__PURE__ */ i("p", { children: [
140
+ /* @__PURE__ */ e("strong", { children: "Estado:" }),
141
+ " ",
142
+ l ? "Editando" : "No editando"
143
+ ] }),
144
+ /* @__PURE__ */ i("p", { children: [
145
+ /* @__PURE__ */ e("strong", { children: "Historial:" }),
146
+ " ",
147
+ r.length,
148
+ " elementos"
149
+ ] }),
150
+ /* @__PURE__ */ i("p", { children: [
151
+ /* @__PURE__ */ e("strong", { children: "Posición en historial:" }),
152
+ " ",
153
+ n + 1,
154
+ " ",
155
+ "de ",
156
+ r.length
157
+ ] })
158
+ ] }),
159
+ /* @__PURE__ */ i("div", { style: { marginBottom: "20px" }, children: [
160
+ /* @__PURE__ */ e("h3", { children: "Hotkeys disponibles:" }),
161
+ /* @__PURE__ */ e("ul", { style: { listStyle: "none", padding: 0 }, children: H.map((t, c) => /* @__PURE__ */ i(
162
+ "li",
163
+ {
164
+ style: {
165
+ padding: "5px 0",
166
+ borderBottom: "1px solid #eee",
167
+ display: "flex",
168
+ justifyContent: "space-between"
169
+ },
170
+ children: [
171
+ /* @__PURE__ */ e("span", { children: t.description }),
172
+ /* @__PURE__ */ e(
173
+ "code",
174
+ {
175
+ style: {
176
+ backgroundColor: "#f5f5f5",
177
+ padding: "2px 6px",
178
+ borderRadius: "3px",
179
+ fontSize: "12px"
180
+ },
181
+ children: [
182
+ t.ctrlKey && "Ctrl",
183
+ t.altKey && "Alt",
184
+ t.shiftKey && "Shift",
185
+ t.metaKey && "⌘",
186
+ t.key.toUpperCase()
187
+ ].filter(Boolean).join("+")
188
+ }
189
+ )
190
+ ]
191
+ },
192
+ c
193
+ )) })
194
+ ] }),
195
+ /* @__PURE__ */ i("div", { style: { marginBottom: "20px" }, children: [
196
+ /* @__PURE__ */ e("h3", { children: "Historial:" }),
197
+ /* @__PURE__ */ e("ul", { children: r.map((t, c) => /* @__PURE__ */ e(
198
+ "li",
199
+ {
200
+ style: {
201
+ padding: "5px 0",
202
+ opacity: c === n ? 1 : 0.6,
203
+ fontWeight: c === n ? "bold" : "normal"
204
+ },
205
+ children: t
206
+ },
207
+ c
208
+ )) })
209
+ ] }),
210
+ /* @__PURE__ */ i(
211
+ "div",
212
+ {
213
+ style: {
214
+ backgroundColor: "#f9f9f9",
215
+ padding: "15px",
216
+ borderRadius: "5px",
217
+ fontSize: "14px"
218
+ },
219
+ children: [
220
+ /* @__PURE__ */ e("p", { children: /* @__PURE__ */ e("strong", { children: "Instrucciones:" }) }),
221
+ /* @__PURE__ */ i("ul", { children: [
222
+ /* @__PURE__ */ e("li", { children: "Escribe algo en el input" }),
223
+ /* @__PURE__ */ i("li", { children: [
224
+ "Usa ",
225
+ /* @__PURE__ */ e("code", { children: "Ctrl+S" }),
226
+ " para guardar"
227
+ ] }),
228
+ /* @__PURE__ */ i("li", { children: [
229
+ "Usa ",
230
+ /* @__PURE__ */ e("code", { children: "Ctrl+Z" }),
231
+ " para deshacer"
232
+ ] }),
233
+ /* @__PURE__ */ i("li", { children: [
234
+ "Usa ",
235
+ /* @__PURE__ */ e("code", { children: "Ctrl+Shift+Z" }),
236
+ " para rehacer"
237
+ ] }),
238
+ /* @__PURE__ */ i("li", { children: [
239
+ "Usa ",
240
+ /* @__PURE__ */ e("code", { children: "Ctrl+E" }),
241
+ " para alternar modo edición"
242
+ ] }),
243
+ /* @__PURE__ */ i("li", { children: [
244
+ "Usa ",
245
+ /* @__PURE__ */ e("code", { children: "Ctrl+L" }),
246
+ " para limpiar"
247
+ ] }),
248
+ /* @__PURE__ */ i("li", { children: [
249
+ "Usa ",
250
+ /* @__PURE__ */ e("code", { children: "Escape" }),
251
+ " para cancelar edición"
252
+ ] }),
253
+ /* @__PURE__ */ i("li", { children: [
254
+ "Usa ",
255
+ /* @__PURE__ */ e("code", { children: "Delete" }),
256
+ " para eliminar todo (solo en modo edición)"
257
+ ] })
258
+ ] })
259
+ ]
260
+ }
261
+ )
262
+ ] });
263
+ }
264
+ export {
265
+ w as HotkeysExample
266
+ };
@@ -0,0 +1,2 @@
1
+ export * from './useHotkey';
2
+ export * from './useHotkeys';
@@ -0,0 +1,6 @@
1
+ import { useHotkey as r } from "./useHotkey.js";
2
+ import { useHotkeys as s } from "./useHotkeys.js";
3
+ export {
4
+ r as useHotkey,
5
+ s as useHotkeys
6
+ };
@@ -0,0 +1,17 @@
1
+ import { HotkeyConfig } from '../../types';
2
+ import { UseHotkeysOptions } from './types';
3
+ /**
4
+ * Hook for handling a single hotkey combination
5
+ *
6
+ * @param config - Single hotkey configuration
7
+ * @param options - Options for the hotkey
8
+ *
9
+ * @example
10
+ * useHotkey({
11
+ * key: 's',
12
+ * ctrlKey: true,
13
+ * action: handleSave,
14
+ * description: 'Save document'
15
+ * });
16
+ */
17
+ export declare function useHotkey(config: HotkeyConfig, options?: UseHotkeysOptions): void;
@@ -0,0 +1,7 @@
1
+ import { useHotkeys as t } from "./useHotkeys.js";
2
+ function s(o, e = {}) {
3
+ t([o], e);
4
+ }
5
+ export {
6
+ s as useHotkey
7
+ };
@@ -0,0 +1,38 @@
1
+ import { HotkeyConfig } from '../../types';
2
+ import { UseHotkeysOptions } from './types';
3
+ /**
4
+ * Hook for handling keyboard shortcuts (hotkeys) with support for modifier keys
5
+ * and multiple key combinations.
6
+ *
7
+ * @param hotkeys - Array of hotkey configurations
8
+ * @param options - Global options for all hotkeys
9
+ *
10
+ * @example
11
+ * // Basic usage
12
+ * useHotkeys([
13
+ * { key: 'Enter', action: handleSubmit },
14
+ * { key: 'Escape', action: handleCancel }
15
+ * ]);
16
+ *
17
+ * @example
18
+ * // With modifier keys
19
+ * useHotkeys([
20
+ * { key: 's', ctrlKey: true, action: handleSave, description: 'Save' },
21
+ * { key: 'k', metaKey: true, action: handleSearch, description: 'Search' },
22
+ * { key: 'z', ctrlKey: true, action: handleUndo, description: 'Undo' },
23
+ * { key: 'z', ctrlKey: true, shiftKey: true, action: handleRedo, description: 'Redo' }
24
+ * ]);
25
+ *
26
+ * @example
27
+ * // With individual configuration
28
+ * useHotkeys([
29
+ * {
30
+ * key: 'Delete',
31
+ * action: handleDelete,
32
+ * preventDefault: true,
33
+ * enabled: canDelete,
34
+ * description: 'Delete item'
35
+ * }
36
+ * ]);
37
+ */
38
+ export declare function useHotkeys(hotkeys: HotkeyConfig[], options?: UseHotkeysOptions): void;
@@ -0,0 +1,31 @@
1
+ import { useRef as K, useCallback as y, useEffect as w } from "react";
2
+ function M(h, p = {}) {
3
+ const { enabled: a = !0, target: c = window, preventDefault: f = !1, stopPropagation: l = !1 } = p, u = K([]);
4
+ u.current = h;
5
+ const i = y((t, e) => {
6
+ const o = t.key.toLowerCase() === e.key.toLowerCase(), n = !!e.ctrlKey === t.ctrlKey, s = !!e.shiftKey === t.shiftKey, d = !!e.altKey === t.altKey, k = !!e.metaKey === t.metaKey;
7
+ return o && n && s && d && k;
8
+ }, []), r = y(
9
+ (t) => {
10
+ if (!a) return;
11
+ const e = t;
12
+ for (const o of u.current)
13
+ if (o.enabled !== !1 && i(e, o)) {
14
+ const n = o.preventDefault ?? f, s = o.stopPropagation ?? l;
15
+ n && t.preventDefault(), s && t.stopPropagation(), o.action(e);
16
+ break;
17
+ }
18
+ },
19
+ [a, f, l, i]
20
+ );
21
+ w(() => {
22
+ const t = c;
23
+ if (!(!t || !a))
24
+ return t.addEventListener("keydown", r), () => {
25
+ t.removeEventListener("keydown", r);
26
+ };
27
+ }, [c, a, r]);
28
+ }
29
+ export {
30
+ M as useHotkeys
31
+ };
@@ -0,0 +1 @@
1
+ export * from './components';
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import { ControlRenderer as e, controls as n } from "./components/ControlRenderer/controls/index.js";
2
+ import { DevPanel as l } from "./components/DevPanel/DevPanel.js";
3
+ export {
4
+ e as ControlRenderer,
5
+ l as DevPanel,
6
+ n as controls
7
+ };
@@ -0,0 +1,14 @@
1
+ type ClassValue = string | null | undefined | {
2
+ [key: string]: boolean;
3
+ };
4
+ /**
5
+ * A helper function to handle class name conditions easily.
6
+ * Receives an object containing strings or an object with the CSS class as key
7
+ * and a condition to add or remove it as value.
8
+ * @param classNames - The classnames object
9
+ * @returns The classes separated by a space
10
+ */
11
+ export declare function className(...classNames: ClassValue[]): {
12
+ className: string;
13
+ };
14
+ export {};
@@ -0,0 +1,15 @@
1
+ function f(...o) {
2
+ const s = [];
3
+ for (const e of o)
4
+ if (e) {
5
+ if (typeof e == "string")
6
+ s.push(e);
7
+ else if (typeof e == "object")
8
+ for (const [t, n] of Object.entries(e))
9
+ n && s.push(t);
10
+ }
11
+ return { className: s.join(" ") };
12
+ }
13
+ export {
14
+ f as className
15
+ };
@@ -0,0 +1 @@
1
+ export * from './className';
@@ -0,0 +1,4 @@
1
+ import { className as m } from "./className.js";
2
+ export {
3
+ m as className
4
+ };
@@ -0,0 +1,19 @@
1
+ import { HotkeyConfig } from '../../types';
2
+ /**
3
+ * Utility function to create a hotkey configuration object
4
+ *
5
+ * @param key - The key to listen for
6
+ * @param action - The action to execute
7
+ * @param modifiers - Optional modifier keys
8
+ * @param options - Additional options
9
+ *
10
+ * @example
11
+ * const saveHotkey = createHotkey('s', handleSave, { ctrl: true });
12
+ * const searchHotkey = createHotkey('k', handleSearch, { meta: true });
13
+ */
14
+ export declare function createHotkey(key: string, action: (event: KeyboardEvent) => void, modifiers?: {
15
+ ctrl?: boolean;
16
+ shift?: boolean;
17
+ alt?: boolean;
18
+ meta?: boolean;
19
+ }, options?: Partial<Omit<HotkeyConfig, "key" | "action">>): HotkeyConfig;
@@ -0,0 +1,14 @@
1
+ function c(e, a, t = {}, y = {}) {
2
+ return {
3
+ key: e,
4
+ action: a,
5
+ ctrlKey: t.ctrl,
6
+ shiftKey: t.shift,
7
+ altKey: t.alt,
8
+ metaKey: t.meta,
9
+ ...y
10
+ };
11
+ }
12
+ export {
13
+ c as createHotkey
14
+ };
@@ -0,0 +1 @@
1
+ export * from './createHotkey';
@@ -0,0 +1,4 @@
1
+ import { createHotkey as r } from "./createHotkey.js";
2
+ export {
3
+ r as createHotkey
4
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Creates a debounced function that delays invoking func until after wait milliseconds
3
+ * @param func - The function to debounce
4
+ * @param wait - The number of milliseconds to delay
5
+ * @returns The debounced function
6
+ */
7
+ export declare function debounce<T extends (...args: unknown[]) => void>(func: T, wait: number): (...args: Parameters<T>) => void;
@@ -0,0 +1,9 @@
1
+ function i(t, o) {
2
+ let e;
3
+ return (...u) => {
4
+ clearTimeout(e), e = setTimeout(() => t(...u), o);
5
+ };
6
+ }
7
+ export {
8
+ i as debounce
9
+ };
@@ -0,0 +1 @@
1
+ export * from './debounce';
@@ -0,0 +1,4 @@
1
+ import { debounce as r } from "./debounce.js";
2
+ export {
3
+ r as debounce
4
+ };
@@ -0,0 +1,12 @@
1
+ import { HotkeyConfig } from '../../types';
2
+ /**
3
+ * Utility function to format hotkey combination as a human-readable string
4
+ *
5
+ * @param config - Hotkey configuration
6
+ * @returns Human-readable string representation
7
+ *
8
+ * @example
9
+ * formatHotkey({ key: 's', ctrlKey: true }) // "Ctrl+S"
10
+ * formatHotkey({ key: 'k', metaKey: true }) // "⌘+K" (on Mac) or "Meta+K"
11
+ */
12
+ export declare function formatHotkey(config: HotkeyConfig): string;
@@ -0,0 +1,8 @@
1
+ import { isMacOS as p } from "../isMacOS/isMacOS.js";
2
+ function a(e) {
3
+ const t = [], s = p();
4
+ return e.ctrlKey && t.push(s ? "⌃" : "Ctrl"), e.altKey && t.push(s ? "⌥" : "Alt"), e.shiftKey && t.push(s ? "⇧" : "Shift"), e.metaKey && t.push(s ? "⌘" : "Meta"), t.push(e.key.toUpperCase()), t.join("+");
5
+ }
6
+ export {
7
+ a as formatHotkey
8
+ };
@@ -0,0 +1 @@
1
+ export * from './formatHotkey';
@@ -0,0 +1,4 @@
1
+ import { formatHotkey as t } from "./formatHotkey.js";
2
+ export {
3
+ t as formatHotkey
4
+ };