@berenjena/react-dev-panel 1.0.4 → 2.1.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 (139) hide show
  1. package/README.md +75 -52
  2. package/dist/assets/index.css +1 -1
  3. package/dist/assets/index10.css +1 -0
  4. package/dist/assets/index11.css +1 -0
  5. package/dist/assets/index12.css +1 -0
  6. package/dist/assets/index13.css +1 -0
  7. package/dist/assets/index2.css +1 -1
  8. package/dist/assets/index3.css +1 -0
  9. package/dist/assets/index4.css +1 -0
  10. package/dist/assets/index5.css +1 -0
  11. package/dist/assets/index6.css +1 -0
  12. package/dist/assets/index7.css +1 -0
  13. package/dist/assets/index8.css +1 -0
  14. package/dist/assets/index9.css +1 -0
  15. package/dist/components/ControlRenderer/controls/BooleanControl/index.d.ts +32 -1
  16. package/dist/components/ControlRenderer/controls/BooleanControl/index.js +24 -2
  17. package/dist/components/ControlRenderer/controls/ButtonControl/index.d.ts +33 -1
  18. package/dist/components/ControlRenderer/controls/ButtonControl/index.js +8 -2
  19. package/dist/components/ControlRenderer/controls/ButtonGroupControl/index.d.ts +37 -1
  20. package/dist/components/ControlRenderer/controls/ButtonGroupControl/index.js +20 -2
  21. package/dist/components/ControlRenderer/controls/ColorControl/index.d.ts +23 -1
  22. package/dist/components/ControlRenderer/controls/ColorControl/index.js +67 -2
  23. package/dist/components/ControlRenderer/controls/ColorControl/types.d.ts +14 -0
  24. package/dist/components/ControlRenderer/controls/DateControl/index.d.ts +41 -1
  25. package/dist/components/ControlRenderer/controls/DateControl/index.js +29 -2
  26. package/dist/components/ControlRenderer/controls/MultiSelectControl/index.d.ts +28 -0
  27. package/dist/components/ControlRenderer/controls/MultiSelectControl/index.js +18 -0
  28. package/dist/components/ControlRenderer/controls/MultiSelectControl/types.d.ts +11 -0
  29. package/dist/components/ControlRenderer/controls/NumberControl/index.d.ts +45 -1
  30. package/dist/components/ControlRenderer/controls/NumberControl/index.js +30 -2
  31. package/dist/components/ControlRenderer/controls/RangeControl/index.d.ts +46 -1
  32. package/dist/components/ControlRenderer/controls/RangeControl/index.js +38 -2
  33. package/dist/components/ControlRenderer/controls/SelectControl/index.d.ts +39 -1
  34. package/dist/components/ControlRenderer/controls/SelectControl/index.js +6 -2
  35. package/dist/components/ControlRenderer/controls/SeparatorControl/index.d.ts +39 -1
  36. package/dist/components/ControlRenderer/controls/SeparatorControl/index.js +12 -2
  37. package/dist/components/ControlRenderer/controls/TextControl/index.d.ts +40 -1
  38. package/dist/components/ControlRenderer/controls/TextControl/index.js +28 -2
  39. package/dist/components/ControlRenderer/controls/index.d.ts +2 -0
  40. package/dist/components/ControlRenderer/controls/index.js +1 -0
  41. package/dist/components/ControlRenderer/controls/types.d.ts +2 -0
  42. package/dist/components/ControlRenderer/index.d.ts +6 -1
  43. package/dist/components/ControlRenderer/index.js +50 -2
  44. package/dist/components/DevPanel/index.d.ts +11 -1
  45. package/dist/components/DevPanel/index.js +69 -2
  46. package/dist/components/DevPanel/types.d.ts +36 -5
  47. package/dist/components/DevPanelPortal/index.d.ts +9 -0
  48. package/dist/components/DevPanelPortal/index.js +17 -0
  49. package/dist/components/EmptyContent/index.d.ts +1 -1
  50. package/dist/components/EmptyContent/index.js +17 -2
  51. package/dist/components/Icon/index.d.ts +16 -0
  52. package/dist/components/Icon/index.js +31 -0
  53. package/dist/components/Input/index.d.ts +1 -1
  54. package/dist/components/Input/index.js +8 -2
  55. package/dist/components/Section/index.d.ts +7 -1
  56. package/dist/components/Section/index.js +23 -2
  57. package/dist/components/Select/index.d.ts +15 -1
  58. package/dist/components/Select/index.js +176 -2
  59. package/dist/components/index.d.ts +3 -2
  60. package/dist/components/index.js +8 -6
  61. package/dist/hooks/useDebounceCallback/index.d.ts +8 -1
  62. package/dist/hooks/useDebounceCallback/index.js +15 -2
  63. package/dist/hooks/useDevPanel/index.d.ts +29 -1
  64. package/dist/hooks/useDevPanel/index.js +22 -2
  65. package/dist/hooks/useDragAndDrop/index.d.ts +20 -1
  66. package/dist/hooks/useDragAndDrop/index.js +53 -2
  67. package/dist/hooks/{useHotkeys/useHotkey.d.ts → useHotKey/index.d.ts} +1 -1
  68. package/dist/hooks/{useHotkeys/useHotkey.js → useHotKey/index.js} +1 -1
  69. package/dist/hooks/useHotkeys/index.d.ts +37 -2
  70. package/dist/hooks/useHotkeys/index.js +29 -4
  71. package/dist/index.d.ts +0 -1
  72. package/dist/index.js +2 -8
  73. package/dist/managers/DevPanelManager.d.ts +85 -0
  74. package/dist/managers/DevPanelManager.js +119 -0
  75. package/dist/store/SectionsStore.js +112 -5
  76. package/dist/store/UIStore.d.ts +78 -2
  77. package/dist/store/UIStore.js +176 -9
  78. package/dist/utils/getPositionAdjustment/getPositionAdjustment.d.ts +3 -2
  79. package/dist/utils/getPositionAdjustment/getPositionAdjustment.js +1 -4
  80. package/package.json +53 -30
  81. package/dist/UIStore-CQdr4U-2.js +0 -227
  82. package/dist/assets/BooleanControl.css +0 -1
  83. package/dist/assets/ButtonControl.css +0 -1
  84. package/dist/assets/ButtonGroupControl.css +0 -1
  85. package/dist/assets/ColorControl.css +0 -1
  86. package/dist/assets/ControlRenderer.css +0 -1
  87. package/dist/assets/DevPanel.css +0 -1
  88. package/dist/assets/EmptyContent.css +0 -1
  89. package/dist/assets/Input.css +0 -1
  90. package/dist/assets/RangeControl.css +0 -1
  91. package/dist/assets/Section.css +0 -1
  92. package/dist/assets/Select.css +0 -1
  93. package/dist/assets/SeparatorControl.css +0 -1
  94. package/dist/components/ControlRenderer/ControlRenderer.d.ts +0 -6
  95. package/dist/components/ControlRenderer/ControlRenderer.js +0 -32
  96. package/dist/components/ControlRenderer/controls/BooleanControl/BooleanControl.d.ts +0 -16
  97. package/dist/components/ControlRenderer/controls/BooleanControl/BooleanControl.js +0 -24
  98. package/dist/components/ControlRenderer/controls/ButtonControl/ButtonControl.d.ts +0 -16
  99. package/dist/components/ControlRenderer/controls/ButtonControl/ButtonControl.js +0 -10
  100. package/dist/components/ControlRenderer/controls/ButtonGroupControl/ButtonGroupControl.d.ts +0 -2
  101. package/dist/components/ControlRenderer/controls/ButtonGroupControl/ButtonGroupControl.js +0 -22
  102. package/dist/components/ControlRenderer/controls/ColorControl/ColorControl.d.ts +0 -16
  103. package/dist/components/ControlRenderer/controls/ColorControl/ColorControl.js +0 -27
  104. package/dist/components/ControlRenderer/controls/DateControl/DateControl.d.ts +0 -29
  105. package/dist/components/ControlRenderer/controls/DateControl/DateControl.js +0 -31
  106. package/dist/components/ControlRenderer/controls/NumberControl/NumberControl.d.ts +0 -30
  107. package/dist/components/ControlRenderer/controls/NumberControl/NumberControl.js +0 -32
  108. package/dist/components/ControlRenderer/controls/RangeControl/RangeControl.d.ts +0 -30
  109. package/dist/components/ControlRenderer/controls/RangeControl/RangeControl.js +0 -40
  110. package/dist/components/ControlRenderer/controls/SelectControl/SelectControl.d.ts +0 -15
  111. package/dist/components/ControlRenderer/controls/SelectControl/SelectControl.js +0 -11
  112. package/dist/components/ControlRenderer/controls/SeparatorControl/SeparatorControl.d.ts +0 -30
  113. package/dist/components/ControlRenderer/controls/SeparatorControl/SeparatorControl.js +0 -14
  114. package/dist/components/ControlRenderer/controls/TextControl/TextControl.d.ts +0 -29
  115. package/dist/components/ControlRenderer/controls/TextControl/TextControl.js +0 -30
  116. package/dist/components/DevPanel/DevPanel.d.ts +0 -11
  117. package/dist/components/DevPanel/DevPanel.js +0 -67
  118. package/dist/components/EmptyContent/EmptyContent.d.ts +0 -1
  119. package/dist/components/EmptyContent/EmptyContent.js +0 -18
  120. package/dist/components/Input/Input.d.ts +0 -1
  121. package/dist/components/Input/Input.js +0 -10
  122. package/dist/components/Logger/index.d.ts +0 -20
  123. package/dist/components/Logger/index.js +0 -85
  124. package/dist/components/Section/Section.d.ts +0 -7
  125. package/dist/components/Section/Section.js +0 -24
  126. package/dist/components/Select/Select.d.ts +0 -1
  127. package/dist/components/Select/Select.js +0 -10
  128. package/dist/hooks/useDebounceCallback/useDebounceCallback.d.ts +0 -8
  129. package/dist/hooks/useDebounceCallback/useDebounceCallback.js +0 -17
  130. package/dist/hooks/useDevPanel/useDevPanel.d.ts +0 -24
  131. package/dist/hooks/useDevPanel/useDevPanel.js +0 -15
  132. package/dist/hooks/useDragAndDrop/useDragAndDrop.d.ts +0 -16
  133. package/dist/hooks/useDragAndDrop/useDragAndDrop.js +0 -55
  134. package/dist/hooks/useHotkeys/useHotkeys.d.ts +0 -37
  135. package/dist/hooks/useHotkeys/useHotkeys.js +0 -31
  136. package/dist/store/index.d.ts +0 -3
  137. package/dist/store/index.js +0 -13
  138. package/dist/utils/index.d.ts +0 -9
  139. package/dist/utils/index.js +0 -20
@@ -1,8 +1,10 @@
1
- import { controls as e } from "./ControlRenderer/controls/index.js";
2
- import { DevPanel as n } from "./DevPanel/DevPanel.js";
3
- import { ControlRenderer as l } from "./ControlRenderer/ControlRenderer.js";
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
+ import { controls as p } from "./ControlRenderer/controls/index.js";
4
5
  export {
5
- l as ControlRenderer,
6
- n as DevPanel,
7
- e as controls
6
+ f as ControlRenderer,
7
+ e as DevPanel,
8
+ l as DevPanelPortal,
9
+ p as controls
8
10
  };
@@ -1 +1,8 @@
1
- export * from './useDebounceCallback';
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 { useDebouncedCallback as a } from "./useDebounceCallback.js";
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
- a as useDebouncedCallback
16
+ f as useDebouncedCallback
4
17
  };
@@ -1 +1,29 @@
1
- export * from './useDevPanel';
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 { useDevPanel as r } from "./useDevPanel.js";
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
- r as useDevPanel
23
+ y as useDevPanel
4
24
  };
@@ -1 +1,20 @@
1
- export * from './useDragAndDrop';
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 { useDragAndDrop as e } from "./useDragAndDrop.js";
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
- e as useDragAndDrop
54
+ R as useDragAndDrop
4
55
  };
@@ -1,4 +1,4 @@
1
- import { HotkeyConfig, UseHotkeysOptions } from './types';
1
+ import { HotkeyConfig, UseHotkeysOptions } from '../useHotkeys/types';
2
2
  /**
3
3
  * Hook for handling a single hotkey combination
4
4
  *
@@ -1,4 +1,4 @@
1
- import { useHotkeys as t } from "./useHotkeys.js";
1
+ import { useHotkeys as t } from "../useHotkeys/index.js";
2
2
  function s(o, e = {}) {
3
3
  t([o], e);
4
4
  }
@@ -1,2 +1,37 @@
1
- export * from './useHotkey';
2
- export * from './useHotkeys';
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 { useHotkey as r } from "./useHotkey.js";
2
- import { useHotkeys as s } from "./useHotkeys.js";
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
- r as useHotkey,
5
- s as useHotkeys
30
+ M as useHotkeys
6
31
  };
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/index.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
+ };
@@ -1,7 +1,114 @@
1
- import "react";
2
- import "./BaseStoreService.js";
3
- import { a, u as i } from "../UIStore-CQdr4U-2.js";
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
- a as useDevPanelSectionActions,
6
- i as useDevPanelSections
112
+ d as useDevPanelSectionActions,
113
+ p as useDevPanelSections
7
114
  };