瀏覽代碼

improve types

AykutSarac 2 年之前
父節點
當前提交
897ceabfe0
共有 2 個文件被更改,包括 9 次插入3 次删除
  1. 2 2
      src/components/CustomNode/index.tsx
  2. 7 1
      src/types.d.ts

+ 2 - 2
src/components/CustomNode/index.tsx

@@ -24,7 +24,7 @@ export const CustomNode = (nodeProps: NodeProps) => {
   return (
   return (
     <Node {...nodeProps} label={<Label style={baseLabelStyle} />}>
     <Node {...nodeProps} label={<Label style={baseLabelStyle} />}>
       {({ width, height, x, y, node }) => {
       {({ width, height, x, y, node }) => {
-        if (properties.text instanceof Object) {
+        if (Array.isArray(properties.text)) {
           return (
           return (
             <ObjectNode
             <ObjectNode
               value={properties.text}
               value={properties.text}
@@ -38,7 +38,7 @@ export const CustomNode = (nodeProps: NodeProps) => {
 
 
         return (
         return (
           <TextNode
           <TextNode
-            node={node}
+            node={node as NodeData}
             isParent={properties.data.isParent}
             isParent={properties.data.isParent}
             value={properties.text}
             value={properties.text}
             width={width}
             width={width}

+ 7 - 1
src/types.d.ts

@@ -1,4 +1,10 @@
-type CanvasDirection = "LEFT" | "RIGHT" | "DOWN" | "UP"
+type CanvasDirection = "LEFT" | "RIGHT" | "DOWN" | "UP";
+
+interface CustomNodeData {
+  isParent: true;
+  hasChild: !!children.length;
+  children;
+}
 
 
 interface NodeData<T = any> {
 interface NodeData<T = any> {
   id: string;
   id: string;