jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.42k stars 714 forks source link

Cannot read properties of null (reading 'version') #784

Closed charleshetier closed 7 months ago

charleshetier commented 7 months ago

Here is my minimalist try:

import Drawflow from "drawflow";
import "drawflow/dist/drawflow.min.css";

var id = document.getElementById("drawflow");
const editor = new Drawflow(id);

const html = `<div><input type="text" df-name></div>`;
const data = { name: "" };

editor.addNode("github", 0, 1, 150, 300, "github", data, html, "type1");

editor.start();

as far as I understand the documentation, there might be possible to run drawflow without vue (can I ?...) image

This example raises the followind error: Cannot read properties of null (reading 'version')

It's happening here, on addNode function: image

Am I missing something ?

(I am using typescript and vite)

Thank you !

jerosoler commented 7 months ago

Yes, run without vue!

editor.start() before addNode.

addNode without last parameter.

example with simple html:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.css" />
  <script src="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.js"></script>
  <style>
    #drawflow {
      position: relative;
      width: 100%;
      height: 800px;
      border: 1px solid red;
    }
  </style>
</head>
<body>
  <div>
    <div id="drawflow"></div>
  </div>
  <script>
    var id = document.getElementById("drawflow");
    const editor = new Drawflow(id);
    editor.start();
    const html = `<div><input type="text" df-name></div>`;
    const data = { name: "" };
    editor.addNode("github", 0, 1, 150, 300, "github", data, html);
  </script>
</body>
</html>
jerosoler commented 7 months ago

This is the demo wihtou vue: https://jerosoler.github.io/Drawflow/

Example in repo: https://github.com/jerosoler/Drawflow/blob/master/docs/index.html

charleshetier commented 7 months ago

It works like a charm, thank you very much ! However, there is just a little issue with the @types, le last parameter is mandatory in type definition

/**
     * @param name Name of module
     * @param inputs Number of inputs
     * @param outputs Number of outputs
     * @param posx Position on start node left
     * @param posy Position on start node top
     * @param className Added classname to de node
     * @param data Data passed to node
     * @param html HTML drawn on node or name of register node.
     * @param typenode Default false, true for Object HTML, vue for vue
     */
    addNode(
        name: string,
        inputs: number,
        outputs: number,
        posx: number,
        posy: number,
        className: string,
        data: any,
        html: string,
        typenode: boolean | string,
    ): number | string;

I guess it should be then:

/**
     * @param name Name of module
     * @param inputs Number of inputs
     * @param outputs Number of outputs
     * @param posx Position on start node left
     * @param posy Position on start node top
     * @param className Added classname to de node
     * @param data Data passed to node
     * @param html HTML drawn on node or name of register node.
     * @param typenode Default false, true for Object HTML, vue for vue
     */
    addNode(
        name: string,
        inputs: number,
        outputs: number,
        posx: number,
        posy: number,
        className: string,
        data: any,
        html: string,
        typenode?: boolean | string,
    ): number | string;

Thank you very much, the lib sounds very nice

jerosoler commented 7 months ago

Types is an external package to drawflow. Try setting false. In parameter.

charleshetier commented 7 months ago

It works fine. Again, thank you !