-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #246 from codebdy/add-zoomable-editor
Add zoomable editor
- Loading branch information
Showing
62 changed files
with
395 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...es/app-designer-example/src/FrontendDesigner/BottomConsole/FlowDesigner/ComponentTree.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Tree } from "antd"; | ||
import { DataNode } from "antd/es/tree"; | ||
import { memo, useCallback, useMemo } from "react" | ||
import { TreeContainer } from "../common/TreeContainer"; | ||
import { useModule } from "../../hooks/useModule"; | ||
import { useDesignerEngine, useGetNode } from "@rxdrag/react-core"; | ||
import { ITreeNode } from "@rxdrag/core" | ||
import { IControllerMeta } from "@rxdrag/minions-runtime-react"; | ||
|
||
const { DirectoryTree } = Tree; | ||
|
||
export type ReactionableNode = { | ||
node: ITreeNode<unknown, IControllerMeta>, | ||
children?: ReactionableNode[] | ||
} | ||
|
||
export const ComponentTree = memo(() => { | ||
const module = useModule() | ||
const engine = useDesignerEngine() | ||
const docs = engine?.getAllDocuments() | ||
const getNode = useGetNode() | ||
console.log("===>ComponentTree", module, docs) | ||
|
||
const getReactionableSchemas = useCallback((node: ITreeNode<unknown, IControllerMeta>) => { | ||
const nodes: ReactionableNode[] = [] | ||
let activeNodes = nodes | ||
if (node.meta["x-controller"]?.id) { | ||
const rNode: ReactionableNode = { | ||
node: node, | ||
children: [] | ||
} | ||
nodes.push(rNode) | ||
activeNodes = rNode.children || [] | ||
} | ||
|
||
for (const childId of node.children) { | ||
const child = getNode(childId) | ||
if (child) { | ||
const children = getReactionableSchemas(child as ITreeNode<unknown, IControllerMeta>) | ||
activeNodes.push(...children) | ||
} | ||
} | ||
return nodes | ||
}, [getNode]) | ||
|
||
const getSchemaTreeOfView = useCallback((id: string) => { | ||
const doc = docs?.find(doc => doc.id === id) | ||
const rootNode = doc?.getRootNode() | ||
if (rootNode) { | ||
return getReactionableSchemas(rootNode as ITreeNode<unknown, IControllerMeta>) | ||
} | ||
|
||
}, [docs, getReactionableSchemas]) | ||
|
||
const getOneNode = useCallback((rNode: ReactionableNode): DataNode => { | ||
return { | ||
key: rNode.node.id, | ||
title: rNode.node.meta?.["x-controller"]?.name || rNode.node.title, | ||
children: rNode.children?.map(child => getOneNode(child)) | ||
} | ||
}, []) | ||
|
||
const treeData: DataNode[] = useMemo(() => { | ||
return module?.views?.map(view => ({ | ||
key: view.id, | ||
title: view.title, | ||
children: getSchemaTreeOfView(view.id)?.map(schema => getOneNode(schema)), | ||
})) || [] | ||
}, [getOneNode, getSchemaTreeOfView, module?.views]) | ||
|
||
return ( | ||
<TreeContainer> | ||
<DirectoryTree | ||
selectable={false} | ||
treeData={treeData} | ||
/> | ||
</TreeContainer> | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
examples/app-designer-example/src/FrontendDesigner/contexts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createContext } from "react"; | ||
import { IModule } from "../interfaces/module"; | ||
|
||
export const ModuleContext = createContext<IModule | undefined>(undefined) |
6 changes: 6 additions & 0 deletions
6
examples/app-designer-example/src/FrontendDesigner/hooks/useModule.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useContext } from "react"; | ||
import { ModuleContext } from "../contexts"; | ||
|
||
export function useModule() { | ||
return useContext(ModuleContext) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export class Mock { | ||
|
||
} | ||
|
||
export const globalMock = new Mock() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.