@berenjena/react-dev-panel 1.0.3 → 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.
Files changed (87) hide show
  1. package/README.md +32 -171
  2. package/dist/assets/BooleanControl.css +1 -1
  3. package/dist/assets/ButtonControl.css +1 -1
  4. package/dist/assets/ButtonGroupControl.css +1 -1
  5. package/dist/assets/ColorControl.css +1 -1
  6. package/dist/assets/ControlRenderer.css +1 -1
  7. package/dist/assets/DevPanel.css +1 -1
  8. package/dist/assets/EmptyContent.css +1 -1
  9. package/dist/assets/Input.css +1 -1
  10. package/dist/assets/MultiSelectControl.css +1 -0
  11. package/dist/assets/RangeControl.css +1 -1
  12. package/dist/assets/Section.css +1 -1
  13. package/dist/assets/Select.css +1 -1
  14. package/dist/assets/SeparatorControl.css +1 -1
  15. package/dist/assets/index.css +1 -1
  16. package/dist/components/ControlRenderer/ControlRenderer.js +38 -18
  17. package/dist/components/ControlRenderer/controls/BooleanControl/BooleanControl.d.ts +20 -4
  18. package/dist/components/ControlRenderer/controls/BooleanControl/BooleanControl.js +16 -14
  19. package/dist/components/ControlRenderer/controls/ButtonControl/ButtonControl.d.ts +22 -5
  20. package/dist/components/ControlRenderer/controls/ButtonControl/ButtonControl.js +2 -2
  21. package/dist/components/ControlRenderer/controls/ButtonGroupControl/ButtonGroupControl.d.ts +35 -0
  22. package/dist/components/ControlRenderer/controls/ButtonGroupControl/ButtonGroupControl.js +2 -2
  23. package/dist/components/ControlRenderer/controls/ColorControl/ColorControl.d.ts +13 -6
  24. package/dist/components/ControlRenderer/controls/ColorControl/ColorControl.js +61 -15
  25. package/dist/components/ControlRenderer/controls/ColorControl/types.d.ts +14 -0
  26. package/dist/components/ControlRenderer/controls/DateControl/DateControl.d.ts +17 -5
  27. package/dist/components/ControlRenderer/controls/DateControl/DateControl.js +12 -12
  28. package/dist/components/ControlRenderer/controls/MultiSelectControl/MultiSelectControl.d.ts +28 -0
  29. package/dist/components/ControlRenderer/controls/MultiSelectControl/MultiSelectControl.js +131 -0
  30. package/dist/components/ControlRenderer/controls/MultiSelectControl/index.d.ts +1 -0
  31. package/dist/components/ControlRenderer/controls/MultiSelectControl/index.js +4 -0
  32. package/dist/components/ControlRenderer/controls/MultiSelectControl/types.d.ts +11 -0
  33. package/dist/components/ControlRenderer/controls/NumberControl/NumberControl.d.ts +26 -11
  34. package/dist/components/ControlRenderer/controls/NumberControl/NumberControl.js +14 -14
  35. package/dist/components/ControlRenderer/controls/RangeControl/RangeControl.d.ts +27 -11
  36. package/dist/components/ControlRenderer/controls/RangeControl/RangeControl.js +19 -19
  37. package/dist/components/ControlRenderer/controls/SelectControl/SelectControl.d.ts +29 -5
  38. package/dist/components/ControlRenderer/controls/SeparatorControl/SeparatorControl.d.ts +16 -7
  39. package/dist/components/ControlRenderer/controls/SeparatorControl/SeparatorControl.js +6 -6
  40. package/dist/components/ControlRenderer/controls/TextControl/TextControl.d.ts +24 -13
  41. package/dist/components/ControlRenderer/controls/TextControl/TextControl.js +15 -15
  42. package/dist/components/ControlRenderer/controls/index.d.ts +2 -0
  43. package/dist/components/ControlRenderer/controls/index.js +1 -0
  44. package/dist/components/ControlRenderer/controls/types.d.ts +2 -0
  45. package/dist/components/DevPanel/DevPanel.js +45 -40
  46. package/dist/components/DevPanel/types.d.ts +26 -0
  47. package/dist/components/DevPanelPortal/DevPanelPortal.d.ts +8 -0
  48. package/dist/components/DevPanelPortal/DevPanelPortal.js +17 -0
  49. package/dist/components/DevPanelPortal/index.d.ts +1 -0
  50. package/dist/components/DevPanelPortal/index.js +4 -0
  51. package/dist/components/EmptyContent/EmptyContent.js +5 -5
  52. package/dist/components/Icon/index.d.ts +16 -0
  53. package/dist/components/Icon/index.js +31 -0
  54. package/dist/components/Input/Input.js +4 -4
  55. package/dist/components/Section/Section.js +17 -16
  56. package/dist/components/Select/Select.js +1 -1
  57. package/dist/components/index.d.ts +3 -2
  58. package/dist/components/index.js +8 -6
  59. package/dist/hooks/useDebounceCallback/index.d.ts +1 -0
  60. package/dist/hooks/useDebounceCallback/index.js +4 -0
  61. package/dist/hooks/useDebounceCallback/useDebounceCallback.d.ts +8 -0
  62. package/dist/hooks/useDebounceCallback/useDebounceCallback.js +17 -0
  63. package/dist/hooks/useDevPanel/useDevPanel.d.ts +10 -5
  64. package/dist/hooks/useDevPanel/useDevPanel.js +25215 -12
  65. package/dist/hooks/useDragAndDrop/useDragAndDrop.d.ts +5 -1
  66. package/dist/hooks/useDragAndDrop/useDragAndDrop.js +24 -24
  67. package/dist/index.d.ts +0 -1
  68. package/dist/index.js +2 -8
  69. package/dist/managers/DevPanelManager.d.ts +85 -0
  70. package/dist/managers/DevPanelManager.js +119 -0
  71. package/dist/managers/index.d.ts +1 -0
  72. package/dist/managers/index.js +4 -0
  73. package/dist/store/BaseStoreService.d.ts +90 -0
  74. package/dist/store/BaseStoreService.js +90 -0
  75. package/dist/store/SectionsStore.d.ts +40 -0
  76. package/dist/store/SectionsStore.js +114 -0
  77. package/dist/store/ThemeStore.d.ts +68 -0
  78. package/dist/store/ThemeStore.js +102 -0
  79. package/dist/store/{store.d.ts → UIStore.d.ts} +17 -35
  80. package/dist/store/UIStore.js +117 -0
  81. package/dist/store/index.d.ts +4 -1
  82. package/dist/store/index.js +16 -7
  83. package/package.json +12 -3
  84. package/dist/assets/index2.css +0 -1
  85. package/dist/components/Logger/index.d.ts +0 -20
  86. package/dist/components/Logger/index.js +0 -85
  87. package/dist/store/store.js +0 -239
@@ -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
- handleMouseDown: (e: React.MouseEvent) => void;
17
+ handlePointerDown: (e: React.PointerEvent) => void;
14
18
  stopDragging: () => void;
15
19
  adjustPositionForResize: () => void;
16
20
  };
@@ -1,30 +1,30 @@
1
- import { useRef as p, useState as l, useCallback as c, useEffect as f } from "react";
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 z({ onPositionChange: i }) {
6
- const o = p(null), [t, a] = l(!1), [u, v] = l({ x: 0, y: 0 }), m = c(() => {
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: d } = L(e);
10
- d && i(n);
11
- }, [i]), s = c(
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 - u.x,
16
- y: e.clientY - u.y
17
- }, d = D(n, o.current);
18
- i(d);
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, u.x, u.y, i]
21
- ), r = c(() => {
20
+ [t, c.x, c.y, s]
21
+ ), r = u(() => {
22
22
  a(!1);
23
- }, []), g = c((e) => {
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 && v({
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("mousemove", s, e), document.addEventListener("mouseup", r, e), () => {
36
- document.removeEventListener("mousemove", s), document.removeEventListener("mouseup", r);
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, s, r]), f(() => {
39
- const e = E(m, 100);
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
- }, [m]), f(() => () => {
44
- t && (document.removeEventListener("mousemove", s), document.removeEventListener("mouseup", r));
45
- }, [t, s, r]), {
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
- handleMouseDown: g,
48
+ handlePointerDown: v,
49
49
  stopDragging: r,
50
- adjustPositionForResize: m
50
+ adjustPositionForResize: d
51
51
  };
52
52
  }
53
53
  export {
54
- z as useDragAndDrop
54
+ R as useDragAndDrop
55
55
  };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './components';
2
1
  export { useDevPanel } from './hooks/useDevPanel';
3
2
  export type { DevPanelProps } from './components/DevPanel/types';
4
3
  export type { ControlsGroup } from './components/ControlRenderer/controls/types';
package/dist/index.js CHANGED
@@ -1,10 +1,4 @@
1
- import { controls as r } from "./components/ControlRenderer/controls/index.js";
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
- l as ControlRenderer,
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';
@@ -0,0 +1,4 @@
1
+ import { DevPanelManager as r } from "./DevPanelManager.js";
2
+ export {
3
+ r as DevPanelManager
4
+ };
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Abstract base class for state management services using the useSyncExternalStore pattern.
3
+ * Provides common functionality for subscription management, state updates, and persistence.
4
+ *
5
+ * @template TState - The type of the state object
6
+ * @template TPersistedState - The type of the persisted state object (usually a subset of TState)
7
+ */
8
+ export declare abstract class BaseStoreService<TState, TPersistedState = TState> {
9
+ /** Set of listeners subscribed to state changes */
10
+ protected readonly listeners: Set<() => void>;
11
+ /** The localStorage key for persisting state */
12
+ protected readonly storageKey: string;
13
+ /** Whether this store should persist state to localStorage */
14
+ protected readonly shouldPersist: boolean;
15
+ /** The current state */
16
+ protected state: TState;
17
+ /**
18
+ * Creates a new BaseStoreService instance.
19
+ *
20
+ * @param storageKey - The localStorage key for persisting state (used only if shouldPersist is true)
21
+ * @param defaultState - The default state value
22
+ * @param shouldLoadOnInit - Whether to load persisted state on initialization (only works if shouldPersist is true)
23
+ * @param shouldPersist - Whether to persist state to localStorage (default: true)
24
+ */
25
+ constructor(storageKey: string, defaultState: TState, shouldLoadOnInit?: boolean, shouldPersist?: boolean);
26
+ /**
27
+ * Abstract method to transform current state to persistable format.
28
+ * Must be implemented by subclasses.
29
+ *
30
+ * @param state - The current state
31
+ * @returns The state in persistable format
32
+ */
33
+ protected abstract toPersistableState(state: TState): TPersistedState;
34
+ /**
35
+ * Abstract method to transform persisted state back to current state format.
36
+ * Must be implemented by subclasses.
37
+ *
38
+ * @param persistedState - The persisted state
39
+ * @param defaultState - The default state to fall back to
40
+ * @returns The state in current format
41
+ */
42
+ protected abstract fromPersistedState(persistedState: TPersistedState, defaultState: TState): TState;
43
+ /**
44
+ * Abstract method to get the service name for error messages.
45
+ * Must be implemented by subclasses.
46
+ *
47
+ * @returns The service name
48
+ */
49
+ protected abstract getServiceName(): string;
50
+ /**
51
+ * Saves the current state to localStorage.
52
+ *
53
+ * @protected
54
+ */
55
+ protected saveState(): void;
56
+ /**
57
+ * Loads previously persisted state from localStorage.
58
+ * If no state exists or loading fails, keeps the current state.
59
+ *
60
+ * @protected
61
+ */
62
+ protected loadState(): void;
63
+ /**
64
+ * Notifies all subscribed listeners about state changes.
65
+ *
66
+ * @protected
67
+ */
68
+ protected notifySubscribers(): void;
69
+ /**
70
+ * Updates the state using an updater function, persists the new state,
71
+ * and notifies all subscribers if the state changed.
72
+ *
73
+ * @param updater - Function that receives current state and returns new state
74
+ * @protected
75
+ */
76
+ protected setState(updater: (state: TState) => TState): void;
77
+ /**
78
+ * Returns the current state snapshot for useSyncExternalStore.
79
+ *
80
+ * @returns The current state
81
+ */
82
+ getSnapshot: () => TState;
83
+ /**
84
+ * Subscribes a listener to state changes for useSyncExternalStore.
85
+ *
86
+ * @param listener - Function to call when state changes
87
+ * @returns Unsubscribe function
88
+ */
89
+ subscribe: (listener: () => void) => (() => void);
90
+ }
@@ -0,0 +1,90 @@
1
+ class r {
2
+ /** Set of listeners subscribed to state changes */
3
+ listeners = /* @__PURE__ */ new Set();
4
+ /** The localStorage key for persisting state */
5
+ storageKey;
6
+ /** Whether this store should persist state to localStorage */
7
+ shouldPersist;
8
+ /** The current state */
9
+ state;
10
+ /**
11
+ * Creates a new BaseStoreService instance.
12
+ *
13
+ * @param storageKey - The localStorage key for persisting state (used only if shouldPersist is true)
14
+ * @param defaultState - The default state value
15
+ * @param shouldLoadOnInit - Whether to load persisted state on initialization (only works if shouldPersist is true)
16
+ * @param shouldPersist - Whether to persist state to localStorage (default: true)
17
+ */
18
+ constructor(t, e, a = !0, s = !0) {
19
+ this.storageKey = t, this.shouldPersist = s, this.state = e, a && s && this.loadState();
20
+ }
21
+ /**
22
+ * Saves the current state to localStorage.
23
+ *
24
+ * @protected
25
+ */
26
+ saveState() {
27
+ if (this.shouldPersist)
28
+ try {
29
+ const t = this.toPersistableState(this.state);
30
+ localStorage.setItem(this.storageKey, JSON.stringify(t));
31
+ } catch {
32
+ console.warn(`Failed to save ${this.getServiceName()} state to localStorage`);
33
+ }
34
+ }
35
+ /**
36
+ * Loads previously persisted state from localStorage.
37
+ * If no state exists or loading fails, keeps the current state.
38
+ *
39
+ * @protected
40
+ */
41
+ loadState() {
42
+ if (this.shouldPersist)
43
+ try {
44
+ const t = localStorage.getItem(this.storageKey);
45
+ if (t) {
46
+ const e = JSON.parse(t);
47
+ this.state = this.fromPersistedState(e, this.state);
48
+ }
49
+ } catch {
50
+ console.warn(`Failed to load persisted ${this.getServiceName()} state from localStorage`);
51
+ }
52
+ }
53
+ /**
54
+ * Notifies all subscribed listeners about state changes.
55
+ *
56
+ * @protected
57
+ */
58
+ notifySubscribers() {
59
+ this.listeners.forEach((t) => t());
60
+ }
61
+ /**
62
+ * Updates the state using an updater function, persists the new state,
63
+ * and notifies all subscribers if the state changed.
64
+ *
65
+ * @param updater - Function that receives current state and returns new state
66
+ * @protected
67
+ */
68
+ setState(t) {
69
+ const e = t(this.state);
70
+ JSON.stringify(e) !== JSON.stringify(this.state) && (this.state = e, this.saveState(), this.notifySubscribers());
71
+ }
72
+ /**
73
+ * Returns the current state snapshot for useSyncExternalStore.
74
+ *
75
+ * @returns The current state
76
+ */
77
+ getSnapshot = () => this.state;
78
+ /**
79
+ * Subscribes a listener to state changes for useSyncExternalStore.
80
+ *
81
+ * @param listener - Function to call when state changes
82
+ * @returns Unsubscribe function
83
+ */
84
+ subscribe = (t) => (this.listeners.add(t), () => {
85
+ this.listeners.delete(t);
86
+ });
87
+ }
88
+ export {
89
+ r as BaseStoreService
90
+ };
@@ -0,0 +1,40 @@
1
+ import { ControlsGroup } from '../components/ControlRenderer/controls/types';
2
+ import { DevPanelSection } from '../components/DevPanel/types';
3
+ type SectionsState = Record<string, DevPanelSection>;
4
+ /**
5
+ * React hook that subscribes only to the sections state of the dev panel.
6
+ * This hook will not re-render when UI state (position, visibility) changes.
7
+ *
8
+ * @returns Record of section names to section objects
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const sections = useDevPanelSections();
13
+ * const sectionNames = Object.keys(sections);
14
+ * ```
15
+ */
16
+ export declare function useDevPanelSections(): SectionsState;
17
+ /**
18
+ * React hook that provides access to section actions without subscribing to state.
19
+ * Ideal for components that only need to trigger section actions without rendering on changes.
20
+ *
21
+ * @returns Object containing all available section actions
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const { registerSection, toggleSectionCollapse } = useDevPanelSectionActions();
26
+ *
27
+ * // Add a new section
28
+ * registerSection('mySection', myControls);
29
+ *
30
+ * // Toggle section collapse
31
+ * toggleSectionCollapse('mySection');
32
+ * ```
33
+ */
34
+ export declare function useDevPanelSectionActions(): {
35
+ registerSection: (name: string, controls: ControlsGroup) => void;
36
+ unregisterSection: (name: string) => void;
37
+ toggleSectionCollapse: (name: string) => void;
38
+ reset: () => void;
39
+ };
40
+ export {};
@@ -0,0 +1,114 @@
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
+ }
111
+ export {
112
+ d as useDevPanelSectionActions,
113
+ p as useDevPanelSections
114
+ };