@@ -24,7 +24,9 @@ import { useEditorStore } from "@/lib/ui-builder/store/editor-store";
2424import {
2525 ComponentRegistry ,
2626 ComponentLayer ,
27- Variable
27+ Variable ,
28+ LayerChangeHandler ,
29+ VariableChangeHandler
2830} from "@/components/ui/ui-builder/types" ;
2931import { TailwindThemePanel } from "@/components/ui/ui-builder/internal/tailwind-theme-panel" ;
3032import { ConfigPanel } from "@/components/ui/ui-builder/internal/config-panel" ;
@@ -52,14 +54,14 @@ interface PanelConfig {
5254}
5355
5456/**
55- * UIBuilderProps defines the props for the UIBuilder component.
57+ * UIBuilderProps defines the props for the UIBuilder component with enhanced type safety .
5658 */
57- interface UIBuilderProps {
59+ interface UIBuilderProps < TRegistry extends ComponentRegistry = ComponentRegistry > {
5860 initialLayers ?: ComponentLayer [ ] ;
59- onChange ?: ( pages : ComponentLayer [ ] ) => void ;
61+ onChange ?: LayerChangeHandler < TRegistry > ;
6062 initialVariables ?: Variable [ ] ;
61- onVariablesChange ?: ( variables : Variable [ ] ) => void ;
62- componentRegistry : ComponentRegistry ;
63+ onVariablesChange ?: VariableChangeHandler ;
64+ componentRegistry : TRegistry ;
6365 panelConfig ?: PanelConfig ;
6466 persistLayerStore ?: boolean ;
6567 allowVariableEditing ?: boolean ;
@@ -73,7 +75,7 @@ interface UIBuilderProps {
7375 * @param {UIBuilderProps } props - The props for the UIBuilder component.
7476 * @returns {JSX.Element } The UIBuilder component wrapped in a ThemeProvider.
7577 */
76- const UIBuilder = ( {
78+ const UIBuilder = < TRegistry extends ComponentRegistry = ComponentRegistry > ( {
7779 initialLayers,
7880 onChange,
7981 initialVariables,
@@ -84,7 +86,7 @@ const UIBuilder = ({
8486 allowVariableEditing = true ,
8587 allowPagesCreation = true ,
8688 allowPagesDeletion = true ,
87- } : UIBuilderProps ) => {
89+ } : UIBuilderProps < TRegistry > ) => {
8890 const layerStore = useStore ( useLayerStore , ( state ) => state ) ;
8991 const editorStore = useStore ( useEditorStore , ( state ) => state ) ;
9092
0 commit comments