Skip to content

Commit

Permalink
降级nanoid 为4.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
codebdy committed Sep 26, 2023
1 parent e3c49b3 commit 2c06cfb
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 51 deletions.
1 change: 1 addition & 0 deletions examples/app-designer-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@rxdrag/react-fieldy": "workspace:*",
"@rxdrag/react-antd-shell": "workspace:*",
"@rxdrag/react-locales": "workspace:*",
"@rxdrag/core": "workspace:*",
"@rxdrag/react-core": "workspace:*",
"@rxdrag/react-antd-materials": "workspace:*",
"@rxdrag/locales": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,77 @@
import { Tree } from "antd";
import { DataNode, DirectoryTreeProps } from "antd/es/tree";
import { memo } from "react"
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;

const treeData: DataNode[] = [
{
title: '字段1',
key: '0-0',
children: [
{
title: '列表',
key: '0-1',
children: [
{ title: 'leaf 1-0', key: '0-1-0', isLeaf: true },
{ title: 'leaf 1-1', key: '0-1-1', isLeaf: true },
],
},
],
},
{
title: '字段2',
key: 'vars',
}

];

export type ReactionableNode = {
node: ITreeNode<unknown, IControllerMeta>,
children?: ReactionableNode[]
}

export const ComponentTree = memo(() => {
const onSelect: DirectoryTreeProps['onSelect'] = (keys, info) => {
console.log('Trigger Select', keys, info);
};
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])

const onExpand: DirectoryTreeProps['onExpand'] = (keys, info) => {
console.log('Trigger Expand', keys, info);
};
return (
<TreeContainer>
<DirectoryTree
onSelect={onSelect}
onExpand={onExpand}
selectable={false}
treeData={treeData}
/>
</TreeContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { TabsProps } from "antd"
import styled from "styled-components"
import { FlowDesigner } from "../BottomConsole/FlowDesigner"
import { ScriptDesigner } from "../BottomConsole/ScriptDesigner"
import { ModuleContext } from "../contexts"

const Label = styled.div`
display: flex;
Expand Down Expand Up @@ -52,16 +53,20 @@ export const ModuleUiDesignerInner = memo(() => {
}, [])

return (
module
? <ZoomableEditor
toolbox={
Toolbox && <Toolbox />
}
schemas={module?.views}
bottomConsole={{
items
}}
/>
: <></>
<ModuleContext.Provider value={module}>
{
module
? <ZoomableEditor
toolbox={
Toolbox && <Toolbox />
}
schemas={module?.views}
bottomConsole={{
items
}}
/>
: <></>
}
</ModuleContext.Provider>
)
})
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)
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)
}
8 changes: 8 additions & 0 deletions examples/app-designer-example/src/data/mudules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ export const defaultModules: { [device: string]: IModule[] | undefined } = {
title: "用户管理",
views: [
{
id: "user-index",
title: "入口页",
schema: userList,
},
{
id: "user-edit",
title: "编辑对话框",
schema: rootNodeSchema,
}
Expand All @@ -111,10 +113,12 @@ export const defaultModules: { [device: string]: IModule[] | undefined } = {
title: "用户管理(h5)",
views: [
{
id: "h5-user-index",
title: "入口页(h5)",
schema: rootNodeSchema,
},
{
id: "h5-user-eidit",
title: "编辑对话框",
schema: rootNodeSchema,
}
Expand All @@ -135,10 +139,12 @@ export const defaultModules: { [device: string]: IModule[] | undefined } = {
title: "用户管理(门户)",
views: [
{
id: "website-user-index",
title: "入口页(门户)",
schema: rootNodeSchema,
},
{
id: "weibsite-user-edit",
title: "编辑对话框",
schema: rootNodeSchema,
}
Expand All @@ -159,10 +165,12 @@ export const defaultModules: { [device: string]: IModule[] | undefined } = {
title: "用户管理(大屏)",
views: [
{
id: "lg-user-index",
title: "入口页(大屏)",
schema: rootNodeSchema,
},
{
id: "lg-user-edit",
title: "编辑对话框",
schema: rootNodeSchema,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/minions/editor/controller-editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rxdrag/minions-controller-editor",
"version": "0.4.0",
"version": "0.4.1",
"type": "module",
"module": "index.ts",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/minions/editor/logicflow-editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rxdrag/minions-logicflow-editor",
"version": "0.4.0",
"version": "0.4.1",
"module": "index.ts",
"files": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion packages/minions/runtime/activities/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rxdrag/minions-activities",
"version": "0.4.0",
"version": "0.4.1",
"author": "Water.Li",
"module": "index.ts",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/minions/runtime/runtime-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rxdrag/minions-runtime",
"version": "0.4.0",
"version": "0.4.1",
"author": "Water.Li",
"module": "index.ts",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/minions/runtime/runtime-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rxdrag/minions-runtime-react",
"version": "0.4.0",
"version": "0.4.1",
"module": "index.ts",
"files": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion packages/rxdrag/schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export enum ViewType {
//一个document schema对应一个场景
export interface IViewSchema<Field = unknown, NodeController = unknown> {
schema: INodeSchema<Field, NodeController>,
id?: string,
id: string,
title?: string,
//视图类型,用于同一画布编辑多个document
viewType?: ViewType,
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rxdrag/shared",
"version": "0.4.0",
"version": "0.4.1",
"author": "Water.Li",
"module": "index.ts",
"files": [
Expand All @@ -24,6 +24,6 @@
},
"dependencies": {
"lodash": "^4.17.21",
"nanoid": "^5.0.1"
"nanoid": "4.0.2"
}
}

0 comments on commit 2c06cfb

Please sign in to comment.