jerosoler / Drawflow

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

How can I update the rendered HTML for a node, I don't care about export #172

Closed ptrthomas closed 3 years ago

ptrthomas commented 3 years ago

this is what I tried:

    var id = '1';
    var node = editor.drawflow.drawflow.Home.data[id];
    node.html = '<div>HELLO WORLD</div>';
    editor.updateNodeDataFromId(id, {});

I was hoping to update the HTML visible, but it doesn't work. This is read-only HTML and no input or textarea is involved, so df-name won't work. I know how to update the data, but here I want the HTML to "update".

my use case is there is a separate edit popup, and after closing that, I want the respective node to "redraw".

is there a way to get the HTML DOM reference of a node ? I can then set the innerHTML directly

any suggestions would be appreciated !

SamuraiDante commented 3 years ago

If I understand you correctly then this would be one way I think: var t = document.querySelector(".drawflow-node[id='node-1'] .drawflow_content_node");

jerosoler commented 3 years ago

That you comment @SamuraiDante is correct.

ptrthomas commented 3 years ago

@SamuraiDante thank you, that helps !

in case this helps anyone else, I found that editor.import(editor.export()) will also do what I wanted, which is to "apply" any changes made to the node html property.

let me know if that is an ok approach @jerosoler - and thank you very much for this awesome library !

shubhambattoo commented 3 years ago

@jerosoler I tried the following code to update the html inside the node, but when I try editor.export() I am getting the old HTML only, as I am using this with React so assuming library is ignoring this change? Or is this expected?

const el = document.querySelector(
  `.drawflow-node[id='node-1'] .drawflow_content_node`
);
el.innerHTML = `<div id="my-id" class="box"> New Inner Text </div>`;
jerosoler commented 3 years ago

Hello @shubhambattoo

You have to update the json as well.

editor.drawflow.drawflow.Home.data[5].html = "...."

View: https://github.com/jerosoler/Drawflow/issues/40

shubhambattoo commented 3 years ago

@jerosoler Yeah that worked. Thanks.