@berenjena/react-dev-panel 1.0.4 → 2.0.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/assets/BooleanControl.css +1 -1
- package/dist/assets/ButtonControl.css +1 -1
- package/dist/assets/ButtonGroupControl.css +1 -1
- package/dist/assets/ColorControl.css +1 -1
- package/dist/assets/ControlRenderer.css +1 -1
- package/dist/assets/DevPanel.css +1 -1
- package/dist/assets/EmptyContent.css +1 -1
- package/dist/assets/Input.css +1 -1
- package/dist/assets/MultiSelectControl.css +1 -0
- package/dist/assets/RangeControl.css +1 -1
- package/dist/assets/Section.css +1 -1
- package/dist/assets/Select.css +1 -1
- package/dist/assets/SeparatorControl.css +1 -1
- package/dist/assets/index.css +1 -1
- package/dist/components/ControlRenderer/ControlRenderer.js +38 -18
- package/dist/components/ControlRenderer/controls/BooleanControl/BooleanControl.d.ts +20 -4
- package/dist/components/ControlRenderer/controls/BooleanControl/BooleanControl.js +16 -14
- package/dist/components/ControlRenderer/controls/ButtonControl/ButtonControl.d.ts +22 -5
- package/dist/components/ControlRenderer/controls/ButtonControl/ButtonControl.js +2 -2
- package/dist/components/ControlRenderer/controls/ButtonGroupControl/ButtonGroupControl.d.ts +35 -0
- package/dist/components/ControlRenderer/controls/ButtonGroupControl/ButtonGroupControl.js +2 -2
- package/dist/components/ControlRenderer/controls/ColorControl/ColorControl.d.ts +13 -6
- package/dist/components/ControlRenderer/controls/ColorControl/ColorControl.js +61 -19
- package/dist/components/ControlRenderer/controls/ColorControl/types.d.ts +14 -0
- package/dist/components/ControlRenderer/controls/DateControl/DateControl.d.ts +17 -5
- package/dist/components/ControlRenderer/controls/DateControl/DateControl.js +12 -12
- package/dist/components/ControlRenderer/controls/MultiSelectControl/MultiSelectControl.d.ts +28 -0
- package/dist/components/ControlRenderer/controls/MultiSelectControl/MultiSelectControl.js +131 -0
- package/dist/components/ControlRenderer/controls/MultiSelectControl/index.d.ts +1 -0
- package/dist/components/ControlRenderer/controls/MultiSelectControl/index.js +4 -0
- package/dist/components/ControlRenderer/controls/MultiSelectControl/types.d.ts +11 -0
- package/dist/components/ControlRenderer/controls/NumberControl/NumberControl.d.ts +26 -11
- package/dist/components/ControlRenderer/controls/NumberControl/NumberControl.js +14 -14
- package/dist/components/ControlRenderer/controls/RangeControl/RangeControl.d.ts +27 -11
- package/dist/components/ControlRenderer/controls/RangeControl/RangeControl.js +19 -19
- package/dist/components/ControlRenderer/controls/SelectControl/SelectControl.d.ts +29 -5
- package/dist/components/ControlRenderer/controls/SeparatorControl/SeparatorControl.d.ts +16 -7
- package/dist/components/ControlRenderer/controls/SeparatorControl/SeparatorControl.js +6 -6
- package/dist/components/ControlRenderer/controls/TextControl/TextControl.d.ts +24 -13
- package/dist/components/ControlRenderer/controls/TextControl/TextControl.js +15 -15
- package/dist/components/ControlRenderer/controls/index.d.ts +2 -0
- package/dist/components/ControlRenderer/controls/index.js +1 -0
- package/dist/components/ControlRenderer/controls/types.d.ts +2 -0
- package/dist/components/DevPanel/DevPanel.js +46 -41
- package/dist/components/DevPanel/types.d.ts +24 -0
- package/dist/components/DevPanelPortal/DevPanelPortal.d.ts +8 -0
- package/dist/components/DevPanelPortal/DevPanelPortal.js +17 -0
- package/dist/components/DevPanelPortal/index.d.ts +1 -0
- package/dist/components/DevPanelPortal/index.js +4 -0
- package/dist/components/EmptyContent/EmptyContent.js +5 -5
- package/dist/components/Icon/index.d.ts +16 -0
- package/dist/components/Icon/index.js +31 -0
- package/dist/components/Input/Input.js +4 -4
- package/dist/components/Section/Section.js +16 -15
- package/dist/components/Select/Select.js +1 -1
- package/dist/components/index.d.ts +3 -2
- package/dist/components/index.js +8 -6
- package/dist/hooks/useDevPanel/useDevPanel.d.ts +10 -5
- package/dist/hooks/useDevPanel/useDevPanel.js +25215 -12
- package/dist/hooks/useDragAndDrop/useDragAndDrop.d.ts +5 -1
- package/dist/hooks/useDragAndDrop/useDragAndDrop.js +24 -24
- package/dist/index.d.ts +0 -1
- package/dist/index.js +2 -8
- package/dist/managers/DevPanelManager.d.ts +85 -0
- package/dist/managers/DevPanelManager.js +119 -0
- package/dist/managers/index.d.ts +1 -0
- package/dist/managers/index.js +4 -0
- package/dist/store/SectionsStore.js +112 -5
- package/dist/store/ThemeStore.d.ts +68 -0
- package/dist/store/ThemeStore.js +102 -0
- package/dist/store/UIStore.js +115 -9
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.js +16 -11
- package/package.json +12 -3
- package/dist/UIStore-CQdr4U-2.js +0 -227
- package/dist/assets/index2.css +0 -1
- package/dist/components/Logger/index.d.ts +0 -20
- package/dist/components/Logger/index.js +0 -85
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Position } from '../../components/DevPanel/types';
|
|
2
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
|
+
*/
|
|
3
7
|
onPositionChange: (position: Position) => void;
|
|
4
8
|
}
|
|
5
9
|
/**
|
|
@@ -10,7 +14,7 @@ export interface UseDragAndDropProps {
|
|
|
10
14
|
export declare function useDragAndDrop({ onPositionChange }: UseDragAndDropProps): {
|
|
11
15
|
isDragging: boolean;
|
|
12
16
|
elementRef: import('react').RefObject<HTMLDivElement | null>;
|
|
13
|
-
|
|
17
|
+
handlePointerDown: (e: React.PointerEvent) => void;
|
|
14
18
|
stopDragging: () => void;
|
|
15
19
|
adjustPositionForResize: () => void;
|
|
16
20
|
};
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { useRef as
|
|
1
|
+
import { useRef as g, useState as p, useCallback as u, useEffect as f } from "react";
|
|
2
2
|
import { debounce as E } from "../../utils/debounce/debounce.js";
|
|
3
3
|
import { getConstrainedPosition as D } from "../../utils/getConstrainedPosition/getConstrainedPosition.js";
|
|
4
4
|
import { getPositionAdjustment as L } from "../../utils/getPositionAdjustment/getPositionAdjustment.js";
|
|
5
|
-
function
|
|
6
|
-
const o =
|
|
5
|
+
function R({ onPositionChange: s }) {
|
|
6
|
+
const o = g(null), [t, a] = p(!1), [c, l] = p({ x: 0, y: 0 }), d = u(() => {
|
|
7
7
|
const e = o.current;
|
|
8
8
|
if (!e) return;
|
|
9
|
-
const { constrainedPosition: n, needsAdjustment:
|
|
10
|
-
|
|
11
|
-
}, [
|
|
9
|
+
const { constrainedPosition: n, needsAdjustment: m } = L(e);
|
|
10
|
+
m && s(n);
|
|
11
|
+
}, [s]), i = u(
|
|
12
12
|
(e) => {
|
|
13
13
|
if (!t || !o.current) return;
|
|
14
14
|
const n = {
|
|
15
|
-
x: e.clientX -
|
|
16
|
-
y: e.clientY -
|
|
17
|
-
},
|
|
18
|
-
|
|
15
|
+
x: e.clientX - c.x,
|
|
16
|
+
y: e.clientY - c.y
|
|
17
|
+
}, m = D(n, o.current);
|
|
18
|
+
s(m);
|
|
19
19
|
},
|
|
20
|
-
[t,
|
|
21
|
-
), r =
|
|
20
|
+
[t, c.x, c.y, s]
|
|
21
|
+
), r = u(() => {
|
|
22
22
|
a(!1);
|
|
23
|
-
}, []),
|
|
23
|
+
}, []), v = u((e) => {
|
|
24
24
|
if (e.target !== e.currentTarget) return;
|
|
25
25
|
e.preventDefault(), a(!0);
|
|
26
26
|
const n = o.current?.getBoundingClientRect();
|
|
27
|
-
n &&
|
|
27
|
+
n && l({
|
|
28
28
|
x: e.clientX - n.left,
|
|
29
29
|
y: e.clientY - n.top
|
|
30
30
|
});
|
|
@@ -32,24 +32,24 @@ function z({ onPositionChange: i }) {
|
|
|
32
32
|
return f(() => {
|
|
33
33
|
if (!t) return;
|
|
34
34
|
const e = { passive: !0 };
|
|
35
|
-
return document.addEventListener("
|
|
36
|
-
document.removeEventListener("
|
|
35
|
+
return document.addEventListener("pointermove", i, e), document.addEventListener("pointerup", r, e), () => {
|
|
36
|
+
document.removeEventListener("pointermove", i), document.removeEventListener("pointerup", r);
|
|
37
37
|
};
|
|
38
|
-
}, [t,
|
|
39
|
-
const e = E(
|
|
38
|
+
}, [t, i, r]), f(() => {
|
|
39
|
+
const e = E(d, 100);
|
|
40
40
|
return window.addEventListener("resize", e), () => {
|
|
41
41
|
window.removeEventListener("resize", e);
|
|
42
42
|
};
|
|
43
|
-
}, [
|
|
44
|
-
t && (document.removeEventListener("
|
|
45
|
-
}, [t,
|
|
43
|
+
}, [d]), f(() => () => {
|
|
44
|
+
t && (document.removeEventListener("pointermove", i), document.removeEventListener("pointerup", r));
|
|
45
|
+
}, [t, i, r]), {
|
|
46
46
|
isDragging: t,
|
|
47
47
|
elementRef: o,
|
|
48
|
-
|
|
48
|
+
handlePointerDown: v,
|
|
49
49
|
stopDragging: r,
|
|
50
|
-
adjustPositionForResize:
|
|
50
|
+
adjustPositionForResize: d
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
export {
|
|
54
|
-
|
|
54
|
+
R as useDragAndDrop
|
|
55
55
|
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DevPanel as n } from "./components/DevPanel/DevPanel.js";
|
|
3
|
-
import { ControlRenderer as l } from "./components/ControlRenderer/ControlRenderer.js";
|
|
4
|
-
import { useDevPanel as p } from "./hooks/useDevPanel/useDevPanel.js";
|
|
1
|
+
import { useDevPanel as r } from "./hooks/useDevPanel/useDevPanel.js";
|
|
5
2
|
import './assets/index.css';export {
|
|
6
|
-
|
|
7
|
-
n as DevPanel,
|
|
8
|
-
r as controls,
|
|
9
|
-
p as useDevPanel
|
|
3
|
+
r as useDevPanel
|
|
10
4
|
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { DevPanelProps } from '../components/DevPanel/types';
|
|
2
|
+
/**
|
|
3
|
+
* Simplified singleton that manages DevPanel state and props merging
|
|
4
|
+
* Works with createPortal for rendering instead of manual DOM management
|
|
5
|
+
*/
|
|
6
|
+
export declare class DevPanelManager {
|
|
7
|
+
private static instance;
|
|
8
|
+
private currentProps;
|
|
9
|
+
private mountedSections;
|
|
10
|
+
private updateCallback;
|
|
11
|
+
private propsChangeCallback;
|
|
12
|
+
private cleanupTimeoutId;
|
|
13
|
+
private constructor();
|
|
14
|
+
static getInstance(): DevPanelManager;
|
|
15
|
+
/**
|
|
16
|
+
* Sets callback to trigger re-render when state changes
|
|
17
|
+
*
|
|
18
|
+
* @param callback - Function to call when state changes
|
|
19
|
+
*/
|
|
20
|
+
setUpdateCallback(callback: () => void): void;
|
|
21
|
+
/**
|
|
22
|
+
* Updates DevPanel props using merge strategy
|
|
23
|
+
*
|
|
24
|
+
* @param newProps - New props to merge with existing props
|
|
25
|
+
*/
|
|
26
|
+
updateProps(newProps: DevPanelProps): void;
|
|
27
|
+
/**
|
|
28
|
+
* Registers section and updates props
|
|
29
|
+
*
|
|
30
|
+
* @param sectionName - Unique identifier for the section
|
|
31
|
+
* @param props - Optional DevPanel props to merge
|
|
32
|
+
*/
|
|
33
|
+
addSection(sectionName: string, props?: DevPanelProps): void;
|
|
34
|
+
/**
|
|
35
|
+
* Removes section and schedules cleanup if no sections remain
|
|
36
|
+
*
|
|
37
|
+
* @param sectionName - Unique identifier for the section to remove
|
|
38
|
+
*/
|
|
39
|
+
removeSection(sectionName: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if DevPanel should be rendered
|
|
42
|
+
*
|
|
43
|
+
* @returns True if there are mounted sections, false otherwise
|
|
44
|
+
*/
|
|
45
|
+
shouldRender(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Gets current merged props
|
|
48
|
+
*
|
|
49
|
+
* @returns Copy of the current merged DevPanel props
|
|
50
|
+
*/
|
|
51
|
+
getAllProps(): DevPanelProps;
|
|
52
|
+
/**
|
|
53
|
+
* Subscribe to props changes
|
|
54
|
+
*
|
|
55
|
+
* @param callback - Function to call when props change
|
|
56
|
+
* @returns Unsubscribe function to remove the callback
|
|
57
|
+
*/
|
|
58
|
+
onPropsChange(callback: (props: DevPanelProps) => void): () => void;
|
|
59
|
+
/**
|
|
60
|
+
* Gets active sections for debugging
|
|
61
|
+
*
|
|
62
|
+
* @returns Array of active section names
|
|
63
|
+
*/
|
|
64
|
+
getActiveSections(): string[];
|
|
65
|
+
/**
|
|
66
|
+
* Schedules cleanup with 1s grace period for quick re-mounting
|
|
67
|
+
*/
|
|
68
|
+
private scheduleCleanup;
|
|
69
|
+
/**
|
|
70
|
+
* Notifies subscribers about state changes
|
|
71
|
+
*/
|
|
72
|
+
private notifyUpdate;
|
|
73
|
+
/**
|
|
74
|
+
* Cleans up state and notifies update
|
|
75
|
+
*/
|
|
76
|
+
private cleanup;
|
|
77
|
+
/**
|
|
78
|
+
* Force cleanup - useful for testing
|
|
79
|
+
*/
|
|
80
|
+
forceCleanup(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Reset singleton instance - useful for HMR
|
|
83
|
+
*/
|
|
84
|
+
static resetInstance(): void;
|
|
85
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
class e {
|
|
2
|
+
static instance = null;
|
|
3
|
+
currentProps = {};
|
|
4
|
+
mountedSections = /* @__PURE__ */ new Set();
|
|
5
|
+
updateCallback = null;
|
|
6
|
+
propsChangeCallback = null;
|
|
7
|
+
cleanupTimeoutId = null;
|
|
8
|
+
constructor() {
|
|
9
|
+
}
|
|
10
|
+
static getInstance() {
|
|
11
|
+
return e.instance || (e.instance = new e()), e.instance;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Sets callback to trigger re-render when state changes
|
|
15
|
+
*
|
|
16
|
+
* @param callback - Function to call when state changes
|
|
17
|
+
*/
|
|
18
|
+
setUpdateCallback(t) {
|
|
19
|
+
this.updateCallback = t;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Updates DevPanel props using merge strategy
|
|
23
|
+
*
|
|
24
|
+
* @param newProps - New props to merge with existing props
|
|
25
|
+
*/
|
|
26
|
+
updateProps(t) {
|
|
27
|
+
this.currentProps = {
|
|
28
|
+
...this.currentProps,
|
|
29
|
+
...t
|
|
30
|
+
}, this.notifyUpdate();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Registers section and updates props
|
|
34
|
+
*
|
|
35
|
+
* @param sectionName - Unique identifier for the section
|
|
36
|
+
* @param props - Optional DevPanel props to merge
|
|
37
|
+
*/
|
|
38
|
+
addSection(t, i = {}) {
|
|
39
|
+
this.cleanupTimeoutId && (clearTimeout(this.cleanupTimeoutId), this.cleanupTimeoutId = null), this.mountedSections.add(t), Object.keys(i).length > 0 ? this.updateProps(i) : this.notifyUpdate();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Removes section and schedules cleanup if no sections remain
|
|
43
|
+
*
|
|
44
|
+
* @param sectionName - Unique identifier for the section to remove
|
|
45
|
+
*/
|
|
46
|
+
removeSection(t) {
|
|
47
|
+
this.mountedSections.delete(t), this.mountedSections.size === 0 ? this.scheduleCleanup() : this.notifyUpdate();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Checks if DevPanel should be rendered
|
|
51
|
+
*
|
|
52
|
+
* @returns True if there are mounted sections, false otherwise
|
|
53
|
+
*/
|
|
54
|
+
shouldRender() {
|
|
55
|
+
return this.mountedSections.size > 0;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Gets current merged props
|
|
59
|
+
*
|
|
60
|
+
* @returns Copy of the current merged DevPanel props
|
|
61
|
+
*/
|
|
62
|
+
getAllProps() {
|
|
63
|
+
return { ...this.currentProps };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Subscribe to props changes
|
|
67
|
+
*
|
|
68
|
+
* @param callback - Function to call when props change
|
|
69
|
+
* @returns Unsubscribe function to remove the callback
|
|
70
|
+
*/
|
|
71
|
+
onPropsChange(t) {
|
|
72
|
+
return this.propsChangeCallback = t, () => {
|
|
73
|
+
this.propsChangeCallback = null;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Gets active sections for debugging
|
|
78
|
+
*
|
|
79
|
+
* @returns Array of active section names
|
|
80
|
+
*/
|
|
81
|
+
getActiveSections() {
|
|
82
|
+
return Array.from(this.mountedSections);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Schedules cleanup with 1s grace period for quick re-mounting
|
|
86
|
+
*/
|
|
87
|
+
scheduleCleanup() {
|
|
88
|
+
this.cleanupTimeoutId = setTimeout(() => {
|
|
89
|
+
this.mountedSections.size === 0 && this.cleanup();
|
|
90
|
+
}, 1e3);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Notifies subscribers about state changes
|
|
94
|
+
*/
|
|
95
|
+
notifyUpdate() {
|
|
96
|
+
this.updateCallback?.(), this.propsChangeCallback?.(this.getAllProps());
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Cleans up state and notifies update
|
|
100
|
+
*/
|
|
101
|
+
cleanup() {
|
|
102
|
+
this.currentProps = {}, this.mountedSections.clear(), this.notifyUpdate(), this.cleanupTimeoutId && (clearTimeout(this.cleanupTimeoutId), this.cleanupTimeoutId = null);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Force cleanup - useful for testing
|
|
106
|
+
*/
|
|
107
|
+
forceCleanup() {
|
|
108
|
+
this.cleanupTimeoutId && (clearTimeout(this.cleanupTimeoutId), this.cleanupTimeoutId = null), this.cleanup();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Reset singleton instance - useful for HMR
|
|
112
|
+
*/
|
|
113
|
+
static resetInstance() {
|
|
114
|
+
e.instance && (e.instance.forceCleanup(), e.instance = null);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
e as DevPanelManager
|
|
119
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DevPanelManager } from './DevPanelManager';
|
|
@@ -1,7 +1,114 @@
|
|
|
1
|
-
import "react";
|
|
2
|
-
import "./BaseStoreService.js";
|
|
3
|
-
|
|
1
|
+
import { useSyncExternalStore as n } from "react";
|
|
2
|
+
import { BaseStoreService as c } from "./BaseStoreService.js";
|
|
3
|
+
const S = "dev-panel-sections-storage";
|
|
4
|
+
class a extends c {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new DevPanelSectionsService instance.
|
|
7
|
+
*/
|
|
8
|
+
constructor() {
|
|
9
|
+
super(S, {}, !1, !1);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Transforms current sections state to persistable format.
|
|
13
|
+
* Since this store doesn't persist, this method returns a dummy value.
|
|
14
|
+
*
|
|
15
|
+
* @param _state - The current sections state (unused)
|
|
16
|
+
* @returns Empty persistable state
|
|
17
|
+
* @protected
|
|
18
|
+
*/
|
|
19
|
+
toPersistableState(e) {
|
|
20
|
+
return { sectionCollapseState: {} };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Transforms persisted state back to current state format.
|
|
24
|
+
* Since this store doesn't persist, this method returns the default state.
|
|
25
|
+
*
|
|
26
|
+
* @param _persistedState - The persisted sections state (unused)
|
|
27
|
+
* @param defaultState - The default state to fall back to
|
|
28
|
+
* @returns The default state
|
|
29
|
+
* @protected
|
|
30
|
+
*/
|
|
31
|
+
fromPersistedState(e, t) {
|
|
32
|
+
return t;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Gets the service name for error messages.
|
|
36
|
+
*
|
|
37
|
+
* @returns The service name
|
|
38
|
+
* @protected
|
|
39
|
+
*/
|
|
40
|
+
getServiceName() {
|
|
41
|
+
return "sections";
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Registers a new section with the dev panel.
|
|
45
|
+
* If a section with the same name already exists, it preserves the existing collapse state.
|
|
46
|
+
* New sections start in expanded state (isCollapsed: false).
|
|
47
|
+
*
|
|
48
|
+
* @param name - Unique name for the section
|
|
49
|
+
* @param controls - Array of control configurations for the section
|
|
50
|
+
*/
|
|
51
|
+
registerSection = (e, t) => {
|
|
52
|
+
this.setState((s) => {
|
|
53
|
+
const i = s[e]?.isCollapsed ?? !1;
|
|
54
|
+
return {
|
|
55
|
+
...s,
|
|
56
|
+
[e]: {
|
|
57
|
+
name: e,
|
|
58
|
+
controls: t,
|
|
59
|
+
isCollapsed: i
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Removes a section from the dev panel.
|
|
66
|
+
*
|
|
67
|
+
* @param name - Name of the section to remove
|
|
68
|
+
*/
|
|
69
|
+
unregisterSection = (e) => {
|
|
70
|
+
this.setState((t) => {
|
|
71
|
+
const { [e]: s, ...o } = t;
|
|
72
|
+
return o;
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Toggles the collapsed state of a specific section.
|
|
77
|
+
*
|
|
78
|
+
* @param name - Name of the section to toggle
|
|
79
|
+
*/
|
|
80
|
+
toggleSectionCollapse = (e) => {
|
|
81
|
+
this.setState((t) => {
|
|
82
|
+
const s = t[e];
|
|
83
|
+
return s ? {
|
|
84
|
+
...t,
|
|
85
|
+
[e]: {
|
|
86
|
+
...s,
|
|
87
|
+
isCollapsed: !s.isCollapsed
|
|
88
|
+
}
|
|
89
|
+
} : t;
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Clears all sections.
|
|
94
|
+
*/
|
|
95
|
+
reset = () => {
|
|
96
|
+
this.setState(() => ({}));
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const r = new a();
|
|
100
|
+
function p() {
|
|
101
|
+
return n(r.subscribe, r.getSnapshot);
|
|
102
|
+
}
|
|
103
|
+
function d() {
|
|
104
|
+
return {
|
|
105
|
+
registerSection: r.registerSection,
|
|
106
|
+
unregisterSection: r.unregisterSection,
|
|
107
|
+
toggleSectionCollapse: r.toggleSectionCollapse,
|
|
108
|
+
reset: r.reset
|
|
109
|
+
};
|
|
110
|
+
}
|
|
4
111
|
export {
|
|
5
|
-
|
|
6
|
-
|
|
112
|
+
d as useDevPanelSectionActions,
|
|
113
|
+
p as useDevPanelSections
|
|
7
114
|
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
interface ThemeState {
|
|
2
|
+
currentTheme: string;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* React hook that provides access to the complete dev panel theme state and actions.
|
|
6
|
+
* Uses useSyncExternalStore for optimal performance and React 18 compatibility.
|
|
7
|
+
*
|
|
8
|
+
* @returns Object containing the current theme state and all available theme actions
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const {
|
|
13
|
+
* currentTheme,
|
|
14
|
+
* setTheme,
|
|
15
|
+
* resetTheme
|
|
16
|
+
* } = useDevPanelTheme();
|
|
17
|
+
*
|
|
18
|
+
* // Set a specific theme
|
|
19
|
+
* setTheme("dark");
|
|
20
|
+
*
|
|
21
|
+
* // Reset to auto theme
|
|
22
|
+
* resetTheme();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function useDevPanelTheme(): ThemeState & {
|
|
26
|
+
setTheme: (theme: string) => void;
|
|
27
|
+
resetTheme: () => void;
|
|
28
|
+
getCurrentTheme: () => string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* React hook that subscribes only to the current theme state.
|
|
32
|
+
* Optimized for components that only need to know the current theme.
|
|
33
|
+
*
|
|
34
|
+
* @returns String indicating the current theme name
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const currentTheme = useCurrentTheme();
|
|
39
|
+
* console.log(`Current theme is: ${currentTheme}`);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function useCurrentTheme(): string;
|
|
43
|
+
/**
|
|
44
|
+
* React hook that provides access to all dev panel theme actions without subscribing to state.
|
|
45
|
+
* Ideal for components that only need to trigger theme actions without rendering on state changes.
|
|
46
|
+
*
|
|
47
|
+
* @returns Object containing all available theme actions
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const { setTheme, resetTheme } = useDevPanelThemeActions();
|
|
52
|
+
*
|
|
53
|
+
* // Switch to dark theme
|
|
54
|
+
* setTheme("dark");
|
|
55
|
+
*
|
|
56
|
+
* // Switch to neon theme
|
|
57
|
+
* setTheme("neon");
|
|
58
|
+
*
|
|
59
|
+
* // Reset to auto theme
|
|
60
|
+
* resetTheme();
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function useDevPanelThemeActions(): {
|
|
64
|
+
setTheme: (theme: string) => void;
|
|
65
|
+
resetTheme: () => void;
|
|
66
|
+
getCurrentTheme: () => string;
|
|
67
|
+
};
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { useSyncExternalStore as n } from "react";
|
|
2
|
+
import { BaseStoreService as h } from "./BaseStoreService.js";
|
|
3
|
+
const m = "dev-panel-theme-storage", u = {
|
|
4
|
+
currentTheme: "auto"
|
|
5
|
+
};
|
|
6
|
+
class o extends h {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new DevPanelThemeService instance and loads persisted theme from localStorage.
|
|
9
|
+
*/
|
|
10
|
+
constructor() {
|
|
11
|
+
super(m, u, !0, !0), this.applyTheme(this.getSnapshot().currentTheme);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Transforms current state to persistable format.
|
|
15
|
+
*
|
|
16
|
+
* @param state - The current theme state
|
|
17
|
+
* @returns The state in persistable format
|
|
18
|
+
* @protected
|
|
19
|
+
*/
|
|
20
|
+
toPersistableState(e) {
|
|
21
|
+
return {
|
|
22
|
+
currentTheme: e.currentTheme
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Transforms persisted state back to current state format.
|
|
27
|
+
*
|
|
28
|
+
* @param persistedState - The persisted theme state
|
|
29
|
+
* @param defaultState - The default state to fall back to
|
|
30
|
+
* @returns The state in current format
|
|
31
|
+
* @protected
|
|
32
|
+
*/
|
|
33
|
+
fromPersistedState(e, r) {
|
|
34
|
+
return {
|
|
35
|
+
...r,
|
|
36
|
+
currentTheme: e.currentTheme || r.currentTheme
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Gets the service name for error messages.
|
|
41
|
+
*
|
|
42
|
+
* @returns The service name
|
|
43
|
+
* @protected
|
|
44
|
+
*/
|
|
45
|
+
getServiceName() {
|
|
46
|
+
return "theme";
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Applies the theme to the document root element using data attributes.
|
|
50
|
+
*
|
|
51
|
+
* @param theme - Theme name to apply
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
applyTheme(e) {
|
|
55
|
+
const r = document.documentElement;
|
|
56
|
+
e === "auto" || e === "" ? r.removeAttribute("data-dev-panel-theme") : r.setAttribute("data-dev-panel-theme", e);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Sets the current theme and applies it to the document.
|
|
60
|
+
*
|
|
61
|
+
* @param theme - Theme name to set
|
|
62
|
+
*/
|
|
63
|
+
setTheme = (e) => {
|
|
64
|
+
this.setState((r) => ({ ...r, currentTheme: e })), this.applyTheme(e);
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Resets the theme to the default "auto" theme.
|
|
68
|
+
*/
|
|
69
|
+
resetTheme = () => {
|
|
70
|
+
this.setTheme("auto");
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Gets the current theme name.
|
|
74
|
+
*
|
|
75
|
+
* @returns The current theme name
|
|
76
|
+
*/
|
|
77
|
+
getCurrentTheme = () => this.getSnapshot().currentTheme;
|
|
78
|
+
}
|
|
79
|
+
const t = new o();
|
|
80
|
+
function c() {
|
|
81
|
+
return {
|
|
82
|
+
...n(t.subscribe, t.getSnapshot),
|
|
83
|
+
setTheme: t.setTheme,
|
|
84
|
+
resetTheme: t.resetTheme,
|
|
85
|
+
getCurrentTheme: t.getCurrentTheme
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function i() {
|
|
89
|
+
return n(t.subscribe, () => t.getSnapshot().currentTheme);
|
|
90
|
+
}
|
|
91
|
+
function p() {
|
|
92
|
+
return {
|
|
93
|
+
setTheme: t.setTheme,
|
|
94
|
+
resetTheme: t.resetTheme,
|
|
95
|
+
getCurrentTheme: t.getCurrentTheme
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export {
|
|
99
|
+
i as useCurrentTheme,
|
|
100
|
+
c as useDevPanelTheme,
|
|
101
|
+
p as useDevPanelThemeActions
|
|
102
|
+
};
|