added tree view

This commit is contained in:
paul
2025-03-09 11:07:08 +05:30
parent 0f7d9944a8
commit 0a2a8601c1
5 changed files with 298 additions and 209 deletions

View File

@@ -1,19 +1,23 @@
import React, { createContext, useContext, useState } from 'react';
import React, { createContext, useContext, useEffect, useRef, useState } from 'react'
const widgetContext = createContext()
export const WidgetContext = createContext()
export const useSelectedWidgetContext = () => useContext(widgetContext)
export const useWidgetContext = () => useContext(WidgetContext)
export const WidgetContextProvider = ({ children }) => {
const [widgets, setWidgets] = useState(null)
const [activeWidget, setActiveWidget] = useState(null)
const [widgets, setWidgets] = useState([]) // stores the mapping to widgetRefs, stores id and WidgetType, later used for rendering [{id: , widgetType: WidgetClass, children: [], parent: "", initialData: {}}]
// don't useState here because the refs are changing often
const widgetRefs = useRef({}) // stores the actual refs to the widgets inside the canvas {id: ref, id2, ref2...}
const [widgetRef, setWidgetRef] = useState({})
// const []
return (
<widgetContext.Provider value={{ widgets, setWidgets, widgetRef, setWidgetRef }}>
<WidgetContext.Provider value={{ widgets, setWidgets, widgetRefs,
activeWidget, setActiveWidget }}>
{children}
</widgetContext.Provider>
</WidgetContext.Provider>
)
}