},
+ {
+ name: "Tree view",
+ icon: ,
+ content:
+ },
{
name: "Uploads",
icon: ,
@@ -162,6 +169,7 @@ function App() {
const handleWidgetAddedToCanvas = (widgets) => {
setCanvasWidgets(widgets)
+ console.log("widget added: ", widgets)
}
const handleCodeGen = () => {
@@ -208,16 +216,19 @@ function App() {
Are you sure you want to change the framework? This will clear the canvas.
*/}
-
-
-
-
- {/* */}
- */}
-
- {/* dragOverlay (dnd-kit) helps move items from one container to another */}
-
+
+
+
+
+
+ {/* */}
+ */}
+
+ {/* dragOverlay (dnd-kit) helps move items from one container to another */}
+
+
)
}
diff --git a/src/canvas/canvas.js b/src/canvas/canvas.js
index c5ecd9e..8ed7dcf 100644
--- a/src/canvas/canvas.js
+++ b/src/canvas/canvas.js
@@ -798,32 +798,32 @@ class Canvas extends React.Component {
__checkClosestShiftElement = ({ event, parentWidgetId, dragElementID }) => {
// NOTE: work on this more maybe even check all four corners
- const parentWidget = this.findWidgetFromListById(parentWidgetId);
- if (!parentWidget) return;
+ const parentWidget = this.findWidgetFromListById(parentWidgetId)
+ if (!parentWidget) return
- const dropX = event.clientX;
- const dropY = event.clientY;
+ const dropX = event.clientX
+ const dropY = event.clientY
- let closestChild = null;
- let closestIndex = parentWidget.children.length;
- let minDistance = Infinity;
+ let closestChild = null
+ let closestIndex = parentWidget.children.length
+ let minDistance = Infinity
// Only check the first level of children
parentWidget.children.forEach((child, index) => {
if (child.id !== dragElementID) {
const childElement = this.widgetRefs[child.id]
- if (!childElement) return;
+ if (!childElement) return
const rect = childElement.current.getBoundingRect()
const childTopRightX = rect.right
const childTopRightY = rect.top
// Compute Euclidean distance from drop position
- const distance = Math.hypot(childTopRightX - dropX, childTopRightY - dropY);
+ const distance = Math.hypot(childTopRightX - dropX, childTopRightY - dropY)
if (distance < minDistance) {
- minDistance = distance;
- closestChild = child;
+ minDistance = distance
+ closestChild = child
closestIndex = index + 1
}
}
@@ -836,7 +836,7 @@ class Canvas extends React.Component {
const rect = childElement.current.getBoundingRect()
// Closest is first child, check if dropped before or after
- closestIndex = dropX < rect.left ? 0 : 1;
+ closestIndex = dropX < rect.left ? 0 : 1
}
return {closestChild, closestIndex}
diff --git a/src/canvas/context/widgetContext.js b/src/canvas/context/widgetContext.js
index c640dd0..e66e0c7 100644
--- a/src/canvas/context/widgetContext.js
+++ b/src/canvas/context/widgetContext.js
@@ -1,35 +1,19 @@
-import React, { createContext, Component } from 'react'
+import React, { createContext, useContext, useState } from 'react';
-const WidgetContext = createContext()
+const widgetContext = createContext()
-// NOTE: Don't use this context provider
+export const useSelectedWidgetContext = () => useContext(widgetContext)
-class WidgetProvider extends Component {
- state = {
- activeWidget: null, // Keeps track of the active widget's data
- widgetMethods: null, // Function to update active widget's state
- }
- setActiveWidget = (widgetData, widgetMethods) => {
- this.setState({
- activeWidget: widgetData,
- widgetMethods: widgetMethods, // Store the update function of the active widget
- })
- }
+export const WidgetContextProvider = ({ children }) => {
+ const [widgets, setWidgets] = useState(null)
- render() {
- return (
-
- {this.props.children}
-
- )
- }
+ const [widgetRef, setWidgetRef] = useState({})
+ // const []
+
+ return (
+
+ {children}
+
+ )
}
-
-export { WidgetContext, WidgetProvider }
diff --git a/src/components/cards.js b/src/components/cards.js
index bc22736..9b84004 100644
--- a/src/components/cards.js
+++ b/src/components/cards.js
@@ -1,13 +1,15 @@
import { useEffect, useMemo, useRef } from "react"
import Draggable from "./utils/draggableDnd"
+import { Button } from "antd"
import { GithubOutlined, GitlabOutlined, LinkOutlined,
AudioOutlined, FileTextOutlined,
DeleteFilled,
DeleteOutlined,
- GlobalOutlined} from "@ant-design/icons"
+ GlobalOutlined,
+ EyeOutlined} from "@ant-design/icons"
+
import DraggableWrapper from "./draggable/draggable"
-import { Button } from "antd"
export function SidebarWidgetCard({ name, img, url, license, widgetClass, innerRef}){
@@ -148,4 +150,22 @@ export function DraggableAssetCard({file, onDelete}){
)
+}
+
+
+export function TreeViewCard({widgetId, onDelete, title}){
+
+ return (
+
+
+ {title}
+
+
+
+ }>
+ }>
+
+
+ )
}
\ No newline at end of file
diff --git a/src/sidebar/treeviewContainer.js b/src/sidebar/treeviewContainer.js
new file mode 100644
index 0000000..7ff67ac
--- /dev/null
+++ b/src/sidebar/treeviewContainer.js
@@ -0,0 +1,89 @@
+import { useEffect, useMemo, useState } from "react"
+
+import { CloseCircleFilled, SearchOutlined } from "@ant-design/icons"
+
+import { SidebarWidgetCard, TreeViewCard } from "../components/cards"
+
+import ButtonWidget from "../assets/widgets/button.png"
+
+import { filterObjectListStartingWith } from "../utils/filter"
+import Widget from "../canvas/widgets/base"
+import { SearchComponent } from "../components/inputs"
+import { Tree } from "antd"
+import { TreeNode } from "antd/es/tree-select"
+
+
+/**
+ *
+ * @param {function} onWidgetsUpdate - this is a callback that will be called once the sidebar is populated with widgets
+ * @returns
+ */
+function TreeviewContainer({ sidebarContent, onWidgetsUpdate }) {
+
+
+ const [searchValue, setSearchValue] = useState("")
+ const [widgetData, setWidgetData] = useState(sidebarContent)
+
+
+ const treeData = [
+ {
+ title: 'Parent',
+ key: '0-0',
+ children: [
+ { title: 'Child 1', key: '0-0-1' },
+ { title: 'Child 2', key: '0-0-2' },
+ ],
+ },
+ ];
+
+ useEffect(() => {
+
+ setWidgetData(sidebarContent)
+ // if (onWidgetsUpdate){
+ // onWidgetsUpdate(widgets)
+ // }
+
+ }, [sidebarContent])
+
+
+
+ // useEffect(() => {
+
+ // if (searchValue.length > 0) {
+ // const searchData = filterObjectListStartingWith(sidebarContent, "name", searchValue)
+ // setWidgetData(searchData)
+ // } else {
+ // setWidgetData(sidebarContent)
+ // }
+
+ // }, [searchValue])
+
+ function onSearch(event) {
+
+ setSearchValue(event.target.value)
+
+ }
+
+ return (
+
+
+ {/*
setSearchValue("")} /> */}
+
+
+
+
+ }
+ >
+
+
+
+
+
+ )
+
+}
+
+
+export default TreeviewContainer
\ No newline at end of file