@berenjena/react-dev-panel 2.0.0 → 2.2.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/README.md +75 -52
- package/dist/assets/index.css +1 -1
- package/dist/assets/{RangeControl.css → index10.css} +1 -1
- package/dist/assets/index11.css +1 -0
- package/dist/assets/index13.css +1 -0
- package/dist/assets/index14.css +1 -0
- package/dist/assets/index15.css +1 -0
- package/dist/assets/index2.css +1 -0
- package/dist/assets/index6.css +1 -0
- package/dist/assets/index7.css +1 -0
- package/dist/assets/index8.css +1 -0
- package/dist/components/ControlRenderer/controls/BooleanControl/index.d.ts +32 -1
- package/dist/components/ControlRenderer/controls/BooleanControl/index.js +24 -2
- package/dist/components/ControlRenderer/controls/ButtonControl/index.d.ts +33 -1
- package/dist/components/ControlRenderer/controls/ButtonControl/index.js +8 -2
- package/dist/components/ControlRenderer/controls/ButtonGroupControl/index.d.ts +37 -1
- package/dist/components/ControlRenderer/controls/ButtonGroupControl/index.js +20 -2
- package/dist/components/ControlRenderer/controls/ColorControl/index.d.ts +23 -1
- package/dist/components/ControlRenderer/controls/ColorControl/index.js +67 -2
- package/dist/components/ControlRenderer/controls/DateControl/index.d.ts +41 -1
- package/dist/components/ControlRenderer/controls/DateControl/index.js +29 -2
- package/dist/components/ControlRenderer/controls/DragAndDropControl/index.d.ts +2 -0
- package/dist/components/ControlRenderer/controls/DragAndDropControl/index.js +117 -0
- package/dist/components/ControlRenderer/controls/DragAndDropControl/types.d.ts +20 -0
- package/dist/components/ControlRenderer/controls/MultiSelectControl/index.d.ts +28 -1
- package/dist/components/ControlRenderer/controls/MultiSelectControl/index.js +16 -2
- package/dist/components/ControlRenderer/controls/NumberControl/index.d.ts +45 -1
- package/dist/components/ControlRenderer/controls/NumberControl/index.js +30 -2
- package/dist/components/ControlRenderer/controls/RangeControl/index.d.ts +46 -1
- package/dist/components/ControlRenderer/controls/RangeControl/index.js +38 -2
- package/dist/components/ControlRenderer/controls/SelectControl/index.d.ts +39 -1
- package/dist/components/ControlRenderer/controls/SelectControl/index.js +6 -2
- package/dist/components/ControlRenderer/controls/SeparatorControl/index.d.ts +39 -1
- package/dist/components/ControlRenderer/controls/SeparatorControl/index.js +12 -2
- package/dist/components/ControlRenderer/controls/TextControl/index.d.ts +40 -1
- package/dist/components/ControlRenderer/controls/TextControl/index.js +28 -2
- package/dist/components/ControlRenderer/controls/TextControl/types.d.ts +1 -0
- package/dist/components/ControlRenderer/controls/index.d.ts +1 -0
- package/dist/components/ControlRenderer/controls/index.js +2 -1
- package/dist/components/ControlRenderer/controls/types.d.ts +2 -0
- package/dist/components/ControlRenderer/index.d.ts +6 -1
- package/dist/components/ControlRenderer/index.js +50 -2
- package/dist/components/DevPanel/index.d.ts +11 -1
- package/dist/components/DevPanel/index.js +67 -2
- package/dist/components/DevPanel/types.d.ts +13 -6
- package/dist/components/DevPanelPortal/index.d.ts +9 -1
- package/dist/components/DevPanelPortal/index.js +15 -2
- package/dist/components/EmptyContent/index.d.ts +1 -1
- package/dist/components/EmptyContent/index.js +17 -2
- package/dist/components/Icon/index.d.ts +3 -3
- package/dist/components/Input/index.d.ts +1 -1
- package/dist/components/Input/index.js +8 -2
- package/dist/components/Section/index.d.ts +7 -1
- package/dist/components/Section/index.js +23 -2
- package/dist/components/Select/index.d.ts +15 -1
- package/dist/components/Select/index.js +176 -2
- package/dist/components/Textarea/index.d.ts +5 -0
- package/dist/components/Textarea/index.js +18 -0
- package/dist/components/index.js +3 -3
- package/dist/hooks/useDebounceCallback/index.d.ts +8 -1
- package/dist/hooks/useDebounceCallback/index.js +15 -2
- package/dist/hooks/useDevPanel/index.d.ts +29 -1
- package/dist/hooks/useDevPanel/index.js +22 -2
- package/dist/hooks/useDragAndDrop/index.d.ts +20 -1
- package/dist/hooks/useDragAndDrop/index.js +53 -2
- package/dist/hooks/{useHotkeys/useHotkey.d.ts → useHotKey/index.d.ts} +1 -1
- package/dist/hooks/{useHotkeys/useHotkey.js → useHotKey/index.js} +1 -1
- package/dist/hooks/useHotkeys/index.d.ts +37 -2
- package/dist/hooks/useHotkeys/index.js +29 -4
- package/dist/index.js +1 -1
- package/dist/store/UIStore.d.ts +78 -2
- package/dist/store/UIStore.js +95 -34
- package/dist/utils/getPositionAdjustment/getPositionAdjustment.d.ts +3 -2
- package/dist/utils/getPositionAdjustment/getPositionAdjustment.js +1 -4
- package/package.json +43 -29
- package/dist/assets/BooleanControl.css +0 -1
- package/dist/assets/ButtonControl.css +0 -1
- package/dist/assets/ButtonGroupControl.css +0 -1
- package/dist/assets/DevPanel.css +0 -1
- package/dist/assets/Input.css +0 -1
- package/dist/assets/MultiSelectControl.css +0 -1
- package/dist/assets/Select.css +0 -1
- package/dist/components/ControlRenderer/ControlRenderer.d.ts +0 -6
- package/dist/components/ControlRenderer/ControlRenderer.js +0 -52
- package/dist/components/ControlRenderer/controls/BooleanControl/BooleanControl.d.ts +0 -32
- package/dist/components/ControlRenderer/controls/BooleanControl/BooleanControl.js +0 -26
- package/dist/components/ControlRenderer/controls/ButtonControl/ButtonControl.d.ts +0 -33
- package/dist/components/ControlRenderer/controls/ButtonControl/ButtonControl.js +0 -10
- package/dist/components/ControlRenderer/controls/ButtonGroupControl/ButtonGroupControl.d.ts +0 -37
- package/dist/components/ControlRenderer/controls/ButtonGroupControl/ButtonGroupControl.js +0 -22
- package/dist/components/ControlRenderer/controls/ColorControl/ColorControl.d.ts +0 -23
- package/dist/components/ControlRenderer/controls/ColorControl/ColorControl.js +0 -69
- package/dist/components/ControlRenderer/controls/DateControl/DateControl.d.ts +0 -41
- package/dist/components/ControlRenderer/controls/DateControl/DateControl.js +0 -31
- package/dist/components/ControlRenderer/controls/MultiSelectControl/MultiSelectControl.d.ts +0 -28
- package/dist/components/ControlRenderer/controls/MultiSelectControl/MultiSelectControl.js +0 -131
- package/dist/components/ControlRenderer/controls/NumberControl/NumberControl.d.ts +0 -45
- package/dist/components/ControlRenderer/controls/NumberControl/NumberControl.js +0 -32
- package/dist/components/ControlRenderer/controls/RangeControl/RangeControl.d.ts +0 -46
- package/dist/components/ControlRenderer/controls/RangeControl/RangeControl.js +0 -40
- package/dist/components/ControlRenderer/controls/SelectControl/SelectControl.d.ts +0 -39
- package/dist/components/ControlRenderer/controls/SelectControl/SelectControl.js +0 -11
- package/dist/components/ControlRenderer/controls/SeparatorControl/SeparatorControl.d.ts +0 -39
- package/dist/components/ControlRenderer/controls/SeparatorControl/SeparatorControl.js +0 -14
- package/dist/components/ControlRenderer/controls/TextControl/TextControl.d.ts +0 -40
- package/dist/components/ControlRenderer/controls/TextControl/TextControl.js +0 -30
- package/dist/components/DevPanel/DevPanel.d.ts +0 -11
- package/dist/components/DevPanel/DevPanel.js +0 -72
- package/dist/components/DevPanelPortal/DevPanelPortal.d.ts +0 -8
- package/dist/components/DevPanelPortal/DevPanelPortal.js +0 -17
- package/dist/components/EmptyContent/EmptyContent.d.ts +0 -1
- package/dist/components/EmptyContent/EmptyContent.js +0 -18
- package/dist/components/Input/Input.d.ts +0 -1
- package/dist/components/Input/Input.js +0 -10
- package/dist/components/Section/Section.d.ts +0 -7
- package/dist/components/Section/Section.js +0 -25
- package/dist/components/Select/Select.d.ts +0 -1
- package/dist/components/Select/Select.js +0 -10
- package/dist/hooks/useDebounceCallback/useDebounceCallback.d.ts +0 -8
- package/dist/hooks/useDebounceCallback/useDebounceCallback.js +0 -17
- package/dist/hooks/useDevPanel/useDevPanel.d.ts +0 -29
- package/dist/hooks/useDevPanel/useDevPanel.js +0 -25218
- package/dist/hooks/useDragAndDrop/useDragAndDrop.d.ts +0 -20
- package/dist/hooks/useDragAndDrop/useDragAndDrop.js +0 -55
- package/dist/hooks/useHotkeys/useHotkeys.d.ts +0 -37
- package/dist/hooks/useHotkeys/useHotkeys.js +0 -31
- package/dist/managers/index.d.ts +0 -1
- package/dist/managers/index.js +0 -4
- package/dist/store/ThemeStore.d.ts +0 -68
- package/dist/store/ThemeStore.js +0 -102
- package/dist/store/index.d.ts +0 -4
- package/dist/store/index.js +0 -18
- package/dist/utils/index.d.ts +0 -9
- package/dist/utils/index.js +0 -20
- /package/dist/assets/{ColorControl.css → index12.css} +0 -0
- /package/dist/assets/{EmptyContent.css → index3.css} +0 -0
- /package/dist/assets/{Section.css → index4.css} +0 -0
- /package/dist/assets/{ControlRenderer.css → index5.css} +0 -0
- /package/dist/assets/{SeparatorControl.css → index9.css} +0 -0
|
@@ -1 +1,15 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface SelectProps {
|
|
2
|
+
value?: string | string[];
|
|
3
|
+
options: string[] | {
|
|
4
|
+
label: string;
|
|
5
|
+
value: string;
|
|
6
|
+
}[];
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
multiple?: boolean;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
onChange: (value: string | string[]) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Unified Select component that can handle both single and multiple selection
|
|
14
|
+
*/
|
|
15
|
+
export declare function Select({ value, options, onChange, disabled, multiple, placeholder }: SelectProps): React.ReactNode;
|
|
@@ -1,4 +1,178 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs as y, Fragment as M, jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as x, useState as H, useCallback as q, useEffect as P } from "react";
|
|
3
|
+
import { createPortal as T } from "react-dom";
|
|
4
|
+
import { Icon as j } from "../Icon/index.js";
|
|
5
|
+
import { useDevPanelPosition as B } from "../../store/UIStore.js";
|
|
6
|
+
import { className as F } from "../../utils/className/className.js";
|
|
7
|
+
import '../../assets/index7.css';const W = "_select_1hbiz_217", U = "_trigger_1hbiz_222", G = "_open_1hbiz_271", J = "_value_1hbiz_275", K = "_placeholder_1hbiz_284", Q = "_arrow_1hbiz_288", X = "_dropdownPortal_1hbiz_303", Y = "_dropdown_1hbiz_303", Z = "_option_1hbiz_342", ee = "_selected_1hbiz_360", te = "_checkbox_1hbiz_369", ne = "_label_1hbiz_390", r = {
|
|
8
|
+
select: W,
|
|
9
|
+
trigger: U,
|
|
10
|
+
open: G,
|
|
11
|
+
value: J,
|
|
12
|
+
placeholder: K,
|
|
13
|
+
arrow: Q,
|
|
14
|
+
dropdownPortal: X,
|
|
15
|
+
dropdown: Y,
|
|
16
|
+
option: Z,
|
|
17
|
+
selected: ee,
|
|
18
|
+
checkbox: te,
|
|
19
|
+
label: ne
|
|
20
|
+
};
|
|
21
|
+
function ae({ value: p, options: _, onChange: z, disabled: f = !1, multiple: u = !1, placeholder: L = "Select..." }) {
|
|
22
|
+
const w = B(), g = x(null), h = x(null), k = x(null), [c, m] = H(!1), [b, E] = H({
|
|
23
|
+
top: 0,
|
|
24
|
+
left: 0,
|
|
25
|
+
width: 0,
|
|
26
|
+
maxHeight: 200
|
|
27
|
+
}), d = u ? Array.isArray(p) ? p : [] : typeof p == "string" ? p : "", C = S(), D = u ? d.length === 0 : !d, s = q(() => {
|
|
28
|
+
c && E(N());
|
|
29
|
+
}, [c]);
|
|
30
|
+
function N() {
|
|
31
|
+
if (!h.current)
|
|
32
|
+
return {
|
|
33
|
+
top: 0,
|
|
34
|
+
left: 0,
|
|
35
|
+
width: 0,
|
|
36
|
+
maxHeight: 200
|
|
37
|
+
};
|
|
38
|
+
const e = h.current.getBoundingClientRect(), t = window.innerHeight, n = window.innerWidth, o = 200, l = 4, i = t - e.bottom - l, v = e.top - l, R = i < o && v > i, V = R ? e.top - Math.min(o, v) : e.bottom + l, $ = Math.max(8, Math.min(e.left, n - e.width - 8)), I = R ? Math.min(o, v) : Math.min(o, i);
|
|
39
|
+
return {
|
|
40
|
+
top: V,
|
|
41
|
+
left: $,
|
|
42
|
+
width: e.width,
|
|
43
|
+
maxHeight: I
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function O(e) {
|
|
47
|
+
if (u) {
|
|
48
|
+
const t = d, n = t.includes(e) ? t.filter((o) => o !== e) : [...t, e];
|
|
49
|
+
z(n);
|
|
50
|
+
} else
|
|
51
|
+
z(e), m(!1);
|
|
52
|
+
}
|
|
53
|
+
function S() {
|
|
54
|
+
if (u) {
|
|
55
|
+
const e = d;
|
|
56
|
+
if (e.length === 0)
|
|
57
|
+
return L;
|
|
58
|
+
if (e.length === 1) {
|
|
59
|
+
const t = _.find((o) => (typeof o == "string" ? o : o.value) === e[0]);
|
|
60
|
+
return (typeof t == "string" ? t : t?.label) || e[0];
|
|
61
|
+
}
|
|
62
|
+
return `${e.length} selected`;
|
|
63
|
+
} else {
|
|
64
|
+
const e = d;
|
|
65
|
+
if (!e)
|
|
66
|
+
return L;
|
|
67
|
+
const t = _.find((o) => (typeof o == "string" ? o : o.value) === e);
|
|
68
|
+
return (typeof t == "string" ? t : t?.label) || e;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function A() {
|
|
72
|
+
f || (c ? m(!1) : (E(N()), m(!0)));
|
|
73
|
+
}
|
|
74
|
+
return P(() => {
|
|
75
|
+
if (!c) return;
|
|
76
|
+
s(), window.addEventListener("resize", s), window.addEventListener("scroll", s, !0);
|
|
77
|
+
const e = g.current?.closest("[data-dev-panel]") || document.querySelector("[data-dev-panel]");
|
|
78
|
+
e && e.addEventListener("scroll", s, !0);
|
|
79
|
+
let t = null;
|
|
80
|
+
if (h.current && "IntersectionObserver" in window) {
|
|
81
|
+
const n = {
|
|
82
|
+
top: 0,
|
|
83
|
+
left: 0,
|
|
84
|
+
width: 0,
|
|
85
|
+
height: 0
|
|
86
|
+
};
|
|
87
|
+
t = new IntersectionObserver(
|
|
88
|
+
(o) => {
|
|
89
|
+
const l = o[0];
|
|
90
|
+
if (l && l.target === h.current) {
|
|
91
|
+
const i = l.boundingClientRect;
|
|
92
|
+
(i.top !== n.top || i.left !== n.left || i.width !== n.width || i.height !== n.height) && (n.top = i.top, n.left = i.left, n.width = i.width, n.height = i.height, s());
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
threshold: [0, 0.1, 0.5, 1]
|
|
97
|
+
}
|
|
98
|
+
), t.observe(h.current);
|
|
99
|
+
}
|
|
100
|
+
return () => {
|
|
101
|
+
window.removeEventListener("resize", s), window.removeEventListener("scroll", s, !0), e && e.removeEventListener("scroll", s, !0), t && t.disconnect();
|
|
102
|
+
};
|
|
103
|
+
}, [c, s]), P(() => {
|
|
104
|
+
const e = k.current;
|
|
105
|
+
(!e || e.x !== w.x || e.y !== w.y) && (k.current = w, c && requestAnimationFrame(s));
|
|
106
|
+
}, [c, w, s]), P(() => {
|
|
107
|
+
function e(t) {
|
|
108
|
+
if (g.current && !g.current.contains(t.target)) {
|
|
109
|
+
const n = document.querySelector(`.${r.dropdownPortal}`);
|
|
110
|
+
if (n && n.contains(t.target))
|
|
111
|
+
return;
|
|
112
|
+
m(!1);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return document.addEventListener("mousedown", e), () => {
|
|
116
|
+
document.removeEventListener("mousedown", e);
|
|
117
|
+
};
|
|
118
|
+
}, []), /* @__PURE__ */ y(M, { children: [
|
|
119
|
+
/* @__PURE__ */ a(
|
|
120
|
+
"div",
|
|
121
|
+
{
|
|
122
|
+
ref: g,
|
|
123
|
+
...F(r.select, {
|
|
124
|
+
[r.disabled]: f,
|
|
125
|
+
[r.open]: c
|
|
126
|
+
}),
|
|
127
|
+
children: /* @__PURE__ */ y("button", { ref: h, type: "button", className: r.trigger, onClick: A, disabled: f, children: [
|
|
128
|
+
/* @__PURE__ */ a("span", { className: `${r.value} ${D ? r.placeholder : ""}`, children: C }),
|
|
129
|
+
/* @__PURE__ */ a(j, { name: "ArrowDown", className: r.arrow })
|
|
130
|
+
] })
|
|
131
|
+
}
|
|
132
|
+
),
|
|
133
|
+
typeof window < "u" && T(
|
|
134
|
+
c && !f && /* @__PURE__ */ a(
|
|
135
|
+
"div",
|
|
136
|
+
{
|
|
137
|
+
className: r.dropdownPortal,
|
|
138
|
+
style: {
|
|
139
|
+
position: "fixed",
|
|
140
|
+
top: b.top,
|
|
141
|
+
left: b.left,
|
|
142
|
+
width: b.width,
|
|
143
|
+
maxHeight: b.maxHeight,
|
|
144
|
+
zIndex: 9999
|
|
145
|
+
},
|
|
146
|
+
children: /* @__PURE__ */ a("div", { className: r.dropdown, children: _.map((e) => {
|
|
147
|
+
const t = typeof e == "string" ? e : e.value, n = typeof e == "string" ? e : e.label, o = u ? d.includes(t) : d === t;
|
|
148
|
+
return u ? /* @__PURE__ */ y("label", { className: r.option, children: [
|
|
149
|
+
/* @__PURE__ */ a(
|
|
150
|
+
"input",
|
|
151
|
+
{
|
|
152
|
+
type: "checkbox",
|
|
153
|
+
checked: o,
|
|
154
|
+
onChange: () => O(t),
|
|
155
|
+
className: r.checkbox
|
|
156
|
+
}
|
|
157
|
+
),
|
|
158
|
+
/* @__PURE__ */ a("span", { className: r.label, children: n })
|
|
159
|
+
] }, t) : /* @__PURE__ */ a(
|
|
160
|
+
"button",
|
|
161
|
+
{
|
|
162
|
+
type: "button",
|
|
163
|
+
className: `${r.option} ${o ? r.selected : ""}`,
|
|
164
|
+
onClick: () => O(t),
|
|
165
|
+
children: n
|
|
166
|
+
},
|
|
167
|
+
t
|
|
168
|
+
);
|
|
169
|
+
}) })
|
|
170
|
+
}
|
|
171
|
+
),
|
|
172
|
+
document.body
|
|
173
|
+
)
|
|
174
|
+
] });
|
|
175
|
+
}
|
|
2
176
|
export {
|
|
3
|
-
|
|
177
|
+
ae as Select
|
|
4
178
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as c } from "react/jsx-runtime";
|
|
2
|
+
import '../../assets/index6.css';const h = "_textarea_83ckv_217", x = {
|
|
3
|
+
textarea: h
|
|
4
|
+
}, a = 240;
|
|
5
|
+
function g(r) {
|
|
6
|
+
const { disableAutoExpand: o, onChange: n, ...s } = r;
|
|
7
|
+
function l(e) {
|
|
8
|
+
if (!o && e.currentTarget) {
|
|
9
|
+
const t = e.currentTarget;
|
|
10
|
+
t.style.height = "auto", t.style.height = `${t.scrollHeight}px`, t.scrollHeight > a ? t.style.overflowY = "auto" : t.style.overflowY = "hidden";
|
|
11
|
+
}
|
|
12
|
+
n?.(e);
|
|
13
|
+
}
|
|
14
|
+
return /* @__PURE__ */ c("textarea", { ...s, className: x.textarea, onChange: l, style: { maxHeight: `${a}px` } });
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
g as Textarea
|
|
18
|
+
};
|
package/dist/components/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DevPanel as e } from "./DevPanel/
|
|
2
|
-
import { DevPanelPortal as l } from "./DevPanelPortal/
|
|
3
|
-
import { ControlRenderer as f } from "./ControlRenderer/
|
|
1
|
+
import { DevPanel as e } from "./DevPanel/index.js";
|
|
2
|
+
import { DevPanelPortal as l } from "./DevPanelPortal/index.js";
|
|
3
|
+
import { ControlRenderer as f } from "./ControlRenderer/index.js";
|
|
4
4
|
import { controls as p } from "./ControlRenderer/controls/index.js";
|
|
5
5
|
export {
|
|
6
6
|
f as ControlRenderer,
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Creates a debounced version of a callback.
|
|
3
|
+
*
|
|
4
|
+
* @param callback - Function to debounce
|
|
5
|
+
* @param delay - Delay in ms before calling the callback
|
|
6
|
+
* @returns A debounced version of the callback
|
|
7
|
+
*/
|
|
8
|
+
export declare function useDebouncedCallback<T extends (...args: Parameters<T>) => void>(callback: T, delay: number): (...args: Parameters<T>) => void;
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useRef as n, useEffect as c, useCallback as o } from "react";
|
|
2
|
+
function f(r, t) {
|
|
3
|
+
const e = n(null);
|
|
4
|
+
return c(() => () => {
|
|
5
|
+
e.current && clearTimeout(e.current);
|
|
6
|
+
}, []), o(
|
|
7
|
+
(...u) => {
|
|
8
|
+
e.current && clearTimeout(e.current), e.current = window.setTimeout(() => {
|
|
9
|
+
r(...u);
|
|
10
|
+
}, t);
|
|
11
|
+
},
|
|
12
|
+
[r, t]
|
|
13
|
+
);
|
|
14
|
+
}
|
|
2
15
|
export {
|
|
3
|
-
|
|
16
|
+
f as useDebouncedCallback
|
|
4
17
|
};
|
|
@@ -1 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import { ControlsGroup } from '../../components/ControlRenderer/controls/types';
|
|
2
|
+
import { DevPanelProps } from '../../components/DevPanel/types';
|
|
3
|
+
/**
|
|
4
|
+
* Hook to register controls in the dev panel with auto-mounting
|
|
5
|
+
* @param sectionName - Section name (e.g: 'Global', 'HomePage')
|
|
6
|
+
* @param controls - Controls configuration object
|
|
7
|
+
* @param devPanelProps - Optional DevPanel configuration (title, hotkey, theme)
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* useDevPanel('Global', {
|
|
12
|
+
* theme: {
|
|
13
|
+
* type: 'select',
|
|
14
|
+
* value: 'light',
|
|
15
|
+
* options: ['light', 'dark'],
|
|
16
|
+
* onChange: setTheme
|
|
17
|
+
* },
|
|
18
|
+
* debugMode: {
|
|
19
|
+
* type: 'boolean',
|
|
20
|
+
* value: false,
|
|
21
|
+
* onChange: setDebugMode
|
|
22
|
+
* }
|
|
23
|
+
* }, {
|
|
24
|
+
* panelTitle: 'My App Controls',
|
|
25
|
+
* theme: 'dark'
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function useDevPanel(sectionName: string, controls: ControlsGroup, devPanelProps?: DevPanelProps): void;
|
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useRef as f, useEffect as i, createElement as l } from "react";
|
|
2
|
+
import { createRoot as m } from "react-dom/client";
|
|
3
|
+
import { DevPanelPortal as p } from "../../components/DevPanelPortal/index.js";
|
|
4
|
+
import { DevPanelManager as v } from "../../managers/DevPanelManager.js";
|
|
5
|
+
import { useDevPanelSections as g, useDevPanelSectionActions as S } from "../../store/SectionsStore.js";
|
|
6
|
+
import { hasControlsChanged as D } from "../../utils/hasControlChanged/hasControlChanged.js";
|
|
7
|
+
function y(t, n, r) {
|
|
8
|
+
const c = g(), { registerSection: u, unregisterSection: a } = S(), s = f(void 0), o = f(null);
|
|
9
|
+
o.current || (o.current = v.getInstance()), i(() => {
|
|
10
|
+
const e = o.current, d = c[t] !== void 0;
|
|
11
|
+
D(n, s.current) || !d ? (u(t, n), s.current = n, e.addSection(t, r)) : r && e.updateProps(r);
|
|
12
|
+
}, [t, n, r, c, u]), i(() => () => {
|
|
13
|
+
const e = o.current;
|
|
14
|
+
a(t), e.removeSection(t);
|
|
15
|
+
}, [t, a]), i(() => {
|
|
16
|
+
if (window.__devPanelAutoMounted) return;
|
|
17
|
+
window.__devPanelAutoMounted = !0;
|
|
18
|
+
const e = document.createElement("div");
|
|
19
|
+
e.id = "dev-panel-portal-container", e.style.display = "none", document.body.appendChild(e), m(e).render(l(p));
|
|
20
|
+
}, []);
|
|
21
|
+
}
|
|
2
22
|
export {
|
|
3
|
-
|
|
23
|
+
y as useDevPanel
|
|
4
24
|
};
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { Position } from '../../components/DevPanel/types';
|
|
2
|
+
export interface UseDragAndDropProps {
|
|
3
|
+
/**
|
|
4
|
+
* Callback function to handle position changes during dragging
|
|
5
|
+
* @param position - The new position of the draggable element
|
|
6
|
+
*/
|
|
7
|
+
onPositionChange: (position: Position) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Custom hook to handle drag and drop functionality
|
|
11
|
+
* Separates the drag logic from the main component
|
|
12
|
+
* Includes boundary constraints and window resize handling
|
|
13
|
+
*/
|
|
14
|
+
export declare function useDragAndDrop({ onPositionChange }: UseDragAndDropProps): {
|
|
15
|
+
elementRef: React.RefObject<HTMLDivElement | null>;
|
|
16
|
+
isDragging: boolean;
|
|
17
|
+
handlePointerDown: (e: React.PointerEvent) => void;
|
|
18
|
+
stopDragging: () => void;
|
|
19
|
+
adjustPositionForResize: () => void;
|
|
20
|
+
};
|
|
@@ -1,4 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useRef as g, useState as p, useCallback as u, 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 R({ onPositionChange: s }) {
|
|
6
|
+
const o = g(null), [t, a] = p(!1), [c, l] = p({ x: 0, y: 0 }), d = u(() => {
|
|
7
|
+
const e = o.current;
|
|
8
|
+
if (!e) return;
|
|
9
|
+
const { constrainedPosition: n, needsAdjustment: m } = L(e);
|
|
10
|
+
m && s(n);
|
|
11
|
+
}, [s]), i = u(
|
|
12
|
+
(e) => {
|
|
13
|
+
if (!t || !o.current) return;
|
|
14
|
+
const n = {
|
|
15
|
+
x: e.clientX - c.x,
|
|
16
|
+
y: e.clientY - c.y
|
|
17
|
+
}, m = D(n, o.current);
|
|
18
|
+
s(m);
|
|
19
|
+
},
|
|
20
|
+
[t, c.x, c.y, s]
|
|
21
|
+
), r = u(() => {
|
|
22
|
+
a(!1);
|
|
23
|
+
}, []), v = u((e) => {
|
|
24
|
+
if (e.target !== e.currentTarget) return;
|
|
25
|
+
e.preventDefault(), a(!0);
|
|
26
|
+
const n = o.current?.getBoundingClientRect();
|
|
27
|
+
n && l({
|
|
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("pointermove", i, e), document.addEventListener("pointerup", r, e), () => {
|
|
36
|
+
document.removeEventListener("pointermove", i), document.removeEventListener("pointerup", r);
|
|
37
|
+
};
|
|
38
|
+
}, [t, i, r]), f(() => {
|
|
39
|
+
const e = E(d, 100);
|
|
40
|
+
return window.addEventListener("resize", e), () => {
|
|
41
|
+
window.removeEventListener("resize", e);
|
|
42
|
+
};
|
|
43
|
+
}, [d]), f(() => () => {
|
|
44
|
+
t && (document.removeEventListener("pointermove", i), document.removeEventListener("pointerup", r));
|
|
45
|
+
}, [t, i, r]), {
|
|
46
|
+
isDragging: t,
|
|
47
|
+
elementRef: o,
|
|
48
|
+
handlePointerDown: v,
|
|
49
|
+
stopDragging: r,
|
|
50
|
+
adjustPositionForResize: d
|
|
51
|
+
};
|
|
52
|
+
}
|
|
2
53
|
export {
|
|
3
|
-
|
|
54
|
+
R as useDragAndDrop
|
|
4
55
|
};
|
|
@@ -1,2 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { HotkeyConfig, UseHotkeysOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for handling keyboard shortcuts (hotkeys) with support for modifier keys
|
|
4
|
+
* and multiple key combinations.
|
|
5
|
+
*
|
|
6
|
+
* @param hotkeys - Array of hotkey configurations
|
|
7
|
+
* @param options - Global options for all hotkeys
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // Basic usage
|
|
11
|
+
* useHotkeys([
|
|
12
|
+
* { key: 'Enter', action: handleSubmit },
|
|
13
|
+
* { key: 'Escape', action: handleCancel }
|
|
14
|
+
* ]);
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // With modifier keys
|
|
18
|
+
* useHotkeys([
|
|
19
|
+
* { key: 's', ctrlKey: true, action: handleSave, description: 'Save' },
|
|
20
|
+
* { key: 'k', metaKey: true, action: handleSearch, description: 'Search' },
|
|
21
|
+
* { key: 'z', ctrlKey: true, action: handleUndo, description: 'Undo' },
|
|
22
|
+
* { key: 'z', ctrlKey: true, shiftKey: true, action: handleRedo, description: 'Redo' }
|
|
23
|
+
* ]);
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // With individual configuration
|
|
27
|
+
* useHotkeys([
|
|
28
|
+
* {
|
|
29
|
+
* key: 'Delete',
|
|
30
|
+
* action: handleDelete,
|
|
31
|
+
* preventDefault: true,
|
|
32
|
+
* enabled: canDelete,
|
|
33
|
+
* description: 'Delete item'
|
|
34
|
+
* }
|
|
35
|
+
* ]);
|
|
36
|
+
*/
|
|
37
|
+
export declare function useHotkeys(hotkeys: HotkeyConfig[], options?: UseHotkeysOptions): void;
|
|
@@ -1,6 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
+
}
|
|
3
29
|
export {
|
|
4
|
-
|
|
5
|
-
s as useHotkeys
|
|
30
|
+
M as useHotkeys
|
|
6
31
|
};
|
package/dist/index.js
CHANGED
package/dist/store/UIStore.d.ts
CHANGED
|
@@ -11,8 +11,10 @@ import { DevPanelUIState, Position } from '../components/DevPanel/types';
|
|
|
11
11
|
* const {
|
|
12
12
|
* isVisible,
|
|
13
13
|
* position,
|
|
14
|
+
* currentTheme,
|
|
14
15
|
* setVisible,
|
|
15
|
-
* setPosition
|
|
16
|
+
* setPosition,
|
|
17
|
+
* setTheme
|
|
16
18
|
* } = useDevPanelUI();
|
|
17
19
|
* ```
|
|
18
20
|
*/
|
|
@@ -20,6 +22,9 @@ export declare function useDevPanelUI(): DevPanelUIState & {
|
|
|
20
22
|
setVisible: (visible: boolean) => void;
|
|
21
23
|
setCollapsed: (collapsed: boolean) => void;
|
|
22
24
|
setPosition: (position: Position) => void;
|
|
25
|
+
setTheme: (theme: string) => void;
|
|
26
|
+
resetTheme: () => void;
|
|
27
|
+
getCurrentTheme: () => string;
|
|
23
28
|
reset: () => void;
|
|
24
29
|
};
|
|
25
30
|
/**
|
|
@@ -59,6 +64,46 @@ export declare function useDevPanelCollapsed(): boolean;
|
|
|
59
64
|
* ```
|
|
60
65
|
*/
|
|
61
66
|
export declare function useDevPanelPosition(): Position;
|
|
67
|
+
/**
|
|
68
|
+
* React hook that subscribes only to the current theme state.
|
|
69
|
+
* Optimized for components that only need to know the current theme.
|
|
70
|
+
*
|
|
71
|
+
* @returns String indicating the current theme name
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const currentTheme = useCurrentTheme();
|
|
76
|
+
* console.log(`Current theme is: ${currentTheme}`);
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function useCurrentTheme(): string;
|
|
80
|
+
/**
|
|
81
|
+
* React hook that provides access to the complete dev panel theme state and actions.
|
|
82
|
+
* Uses useSyncExternalStore for optimal performance and React 18 compatibility.
|
|
83
|
+
*
|
|
84
|
+
* @returns Object containing the current theme state and all available theme actions
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const {
|
|
89
|
+
* currentTheme,
|
|
90
|
+
* setTheme,
|
|
91
|
+
* resetTheme
|
|
92
|
+
* } = useDevPanelTheme();
|
|
93
|
+
*
|
|
94
|
+
* // Set a specific theme
|
|
95
|
+
* setTheme("dark");
|
|
96
|
+
*
|
|
97
|
+
* // Reset to auto theme
|
|
98
|
+
* resetTheme();
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function useDevPanelTheme(): {
|
|
102
|
+
currentTheme: string;
|
|
103
|
+
setTheme: (theme: string) => void;
|
|
104
|
+
resetTheme: () => void;
|
|
105
|
+
getCurrentTheme: () => string;
|
|
106
|
+
};
|
|
62
107
|
/**
|
|
63
108
|
* React hook that provides access to all dev panel UI actions without subscribing to state.
|
|
64
109
|
* Ideal for components that only need to trigger UI actions without rendering on state changes.
|
|
@@ -67,7 +112,7 @@ export declare function useDevPanelPosition(): Position;
|
|
|
67
112
|
*
|
|
68
113
|
* @example
|
|
69
114
|
* ```typescript
|
|
70
|
-
* const { setVisible, setPosition, reset } = useDevPanelUIActions();
|
|
115
|
+
* const { setVisible, setPosition, setTheme, reset } = useDevPanelUIActions();
|
|
71
116
|
*
|
|
72
117
|
* // Toggle panel visibility
|
|
73
118
|
* setVisible(true);
|
|
@@ -75,6 +120,9 @@ export declare function useDevPanelPosition(): Position;
|
|
|
75
120
|
* // Update position
|
|
76
121
|
* setPosition({ x: 100, y: 100 });
|
|
77
122
|
*
|
|
123
|
+
* // Set theme
|
|
124
|
+
* setTheme("dark");
|
|
125
|
+
*
|
|
78
126
|
* // Reset UI state
|
|
79
127
|
* reset();
|
|
80
128
|
* ```
|
|
@@ -83,6 +131,34 @@ export declare function useDevPanelUIActions(): {
|
|
|
83
131
|
setVisible: (visible: boolean) => void;
|
|
84
132
|
setCollapsed: (collapsed: boolean) => void;
|
|
85
133
|
setPosition: (position: Position) => void;
|
|
134
|
+
setTheme: (theme: string) => void;
|
|
135
|
+
resetTheme: () => void;
|
|
136
|
+
getCurrentTheme: () => string;
|
|
86
137
|
reset: () => void;
|
|
87
138
|
};
|
|
139
|
+
/**
|
|
140
|
+
* React hook that provides access to all dev panel theme actions without subscribing to state.
|
|
141
|
+
* Ideal for components that only need to trigger theme actions without rendering on state changes.
|
|
142
|
+
*
|
|
143
|
+
* @returns Object containing all available theme actions
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const { setTheme, resetTheme } = useDevPanelThemeActions();
|
|
148
|
+
*
|
|
149
|
+
* // Switch to dark theme
|
|
150
|
+
* setTheme("dark");
|
|
151
|
+
*
|
|
152
|
+
* // Switch to neon theme
|
|
153
|
+
* setTheme("neon");
|
|
154
|
+
*
|
|
155
|
+
* // Reset to auto theme
|
|
156
|
+
* resetTheme();
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
export declare function useDevPanelThemeActions(): {
|
|
160
|
+
setTheme: (theme: string) => void;
|
|
161
|
+
resetTheme: () => void;
|
|
162
|
+
getCurrentTheme: () => string;
|
|
163
|
+
};
|
|
88
164
|
export declare const useDevPanelStore: typeof useDevPanelUI;
|