givanz / VvvebJs

Drag and drop page builder library written in vanilla javascript without dependencies or build tools.
https://www.vvveb.com/vvvebjs/editor.html
Apache License 2.0
7.31k stars 1.66k forks source link

Node gets inserted after body tag.. Fix #350

Open AbdisamadMoh opened 6 months ago

AbdisamadMoh commented 6 months ago

Node gets inserted after the body tag if you choose insert "AFTER"

image
function addSectionComponent(component, after = true) {
      let node = generateElements(component.html)[0];

      if (after) {
//start
        if (addSectionElement.tagName == "BODY") {
          addSectionElement.append(node);
        } else {
          addSectionElement.after(node);
        }
//end
      } else {
        addSectionElement.append(node);
      }

      if (component.afterDrop) {
        node = component.afterDrop(node);
      }

      node = node;
      self.selectNode(node);
      self.loadNodeComponent(node);
      Vvveb.TreeList.loadComponents();
      Vvveb.TreeList.selectComponent(node);

      Vvveb.Undo.addMutation({
        type: "childList",
        target: node.parentNode,
        addedNodes: [node],
        nextSibling: node.nextSibling,
      });
    }

If the selected node is body insert within the body.

givanz commented 5 months ago

Thanks for the bug report, it was fixed in https://github.com/givanz/VvvebJs/commit/d575326733efe933b7d55ce3818449f18c9b620a add component button is hidden for body.