Socket
Socket
Sign inDemoInstall

morphdom

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

morphdom - npm Package Compare versions

Comparing version 0.1.14 to 1.0.0

.cache/lasso/default/198215032/read/01/bb6eb463cf44faa3a0d238172218c4

108

dist/morphdom-umd.js

@@ -104,10 +104,10 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.morphdom = f()}})(function(){var define,module,exports;module={exports:(exports={})};

*/
function moveChildren(from, to) {
var curChild = from.firstChild;
function moveChildren(fromEl, toEl) {
var curChild = fromEl.firstChild;
while(curChild) {
var nextChild = curChild.nextSibling;
to.appendChild(curChild);
toEl.appendChild(curChild);
curChild = nextChild;
}
return to;
return toEl;
}

@@ -130,2 +130,3 @@

var onBeforeNodeDiscarded = options.onBeforeNodeDiscarded || noop;
var childrenOnly = options.childrenOnly === true;

@@ -191,21 +192,23 @@ function removeNodeHelper(node, nestedInSavedEl) {

function morphEl(fromNode, toNode, alreadyVisited) {
if (toNode.id) {
function morphEl(fromEl, toEl, alreadyVisited, childrenOnly) {
if (toEl.id) {
// If an element with an ID is being morphed then it is will be in the final
// DOM so clear it out of the saved elements collection
delete savedEls[toNode.id];
delete savedEls[toEl.id];
}
if (onBeforeMorphEl(fromNode, toNode) === false) {
return;
}
if (!childrenOnly) {
if (onBeforeMorphEl(fromEl, toEl) === false) {
return;
}
morphAttrs(fromNode, toNode);
morphAttrs(fromEl, toEl);
if (onBeforeMorphElChildren(fromNode, toNode) === false) {
return;
if (onBeforeMorphElChildren(fromEl, toEl) === false) {
return;
}
}
var curToNodeChild = toNode.firstChild;
var curFromNodeChild = fromNode.firstChild;
var curToNodeChild = toEl.firstChild;
var curFromNodeChild = fromEl.firstChild;
var curToNodeId;

@@ -275,3 +278,3 @@

// to find a match in the original DOM
removeNode(curFromNodeChild, fromNode, alreadyVisited);
removeNode(curFromNodeChild, fromEl, alreadyVisited);
curFromNodeChild = fromNextSibling;

@@ -298,3 +301,3 @@ }

// append the current "to node" to the end
fromNode.appendChild(curToNodeChild);
fromEl.appendChild(curToNodeChild);

@@ -309,11 +312,11 @@ curToNodeChild = toNextSibling;

fromNextSibling = curFromNodeChild.nextSibling;
removeNode(curFromNodeChild, fromNode, alreadyVisited);
removeNode(curFromNodeChild, fromEl, alreadyVisited);
curFromNodeChild = fromNextSibling;
}
var specialElHandler = specialElHandlers[fromNode.tagName];
var specialElHandler = specialElHandlers[fromEl.tagName];
if (specialElHandler) {
specialElHandler(fromNode, toNode);
specialElHandler(fromEl, toEl);
}
}
} // END: morphEl(...)

@@ -324,38 +327,45 @@ var morphedNode = fromNode;

// Handle the case where we are given two DOM nodes that are not
// compatible (e.g. <div> --> <span> or <div> --> TEXT)
if (morphedNodeType === 1) {
if (toNodeType === 1) {
if (morphedNode.tagName !== toNode.tagName) {
onNodeDiscarded(fromNode);
morphedNode = moveChildren(morphedNode, document.createElement(toNode.tagName));
if (!childrenOnly) {
// Handle the case where we are given two DOM nodes that are not
// compatible (e.g. <div> --> <span> or <div> --> TEXT)
if (morphedNodeType === 1) {
if (toNodeType === 1) {
if (fromNode.tagName !== toNode.tagName) {
onNodeDiscarded(fromNode);
morphedNode = moveChildren(fromNode, document.createElement(toNode.tagName));
}
} else {
// Going from an element node to a text node
morphedNode = toNode;
}
} else {
// Going from an element node to a text node
return toNode;
} else if (morphedNodeType === 3) { // Text node
if (toNodeType === 3) {
morphedNode.nodeValue = toNode.nodeValue;
return morphedNode;
} else {
// Text node to something else
morphedNode = toNode;
}
}
} else if (morphedNodeType === 3) { // Text node
if (toNodeType === 3) {
morphedNode.nodeValue = toNode.nodeValue;
return morphedNode;
} else {
onNodeDiscarded(fromNode);
// Text node to something else
return toNode;
}
}
morphEl(morphedNode, toNode, false);
if (morphedNode === toNode) {
// The "to node" was not compatible with the "from node"
// so we had to toss out the "from node" and use the "to node"
onNodeDiscarded(fromNode);
} else {
morphEl(morphedNode, toNode, false, childrenOnly);
// Fire the "onNodeDiscarded" event for any saved elements
// that never found a new home in the morphed DOM
for (var savedElId in savedEls) {
if (savedEls.hasOwnProperty(savedElId)) {
var savedEl = savedEls[savedElId];
onNodeDiscarded(savedEl);
walkDiscardedChildNodes(savedEl);
// Fire the "onNodeDiscarded" event for any saved elements
// that never found a new home in the morphed DOM
for (var savedElId in savedEls) {
if (savedEls.hasOwnProperty(savedElId)) {
var savedEl = savedEls[savedElId];
onNodeDiscarded(savedEl);
walkDiscardedChildNodes(savedEl);
}
}
}
if (morphedNode !== fromNode && fromNode.parentNode) {
if (!childrenOnly && morphedNode !== fromNode && fromNode.parentNode) {
// If we had to swap out the from node with a new node because the old

@@ -362,0 +372,0 @@ // node was not compatible with the target node then we need to

@@ -103,10 +103,10 @@ // Create a range object for efficently rendering strings to elements.

*/
function moveChildren(from, to) {
var curChild = from.firstChild;
function moveChildren(fromEl, toEl) {
var curChild = fromEl.firstChild;
while(curChild) {
var nextChild = curChild.nextSibling;
to.appendChild(curChild);
toEl.appendChild(curChild);
curChild = nextChild;
}
return to;
return toEl;
}

@@ -129,2 +129,3 @@

var onBeforeNodeDiscarded = options.onBeforeNodeDiscarded || noop;
var childrenOnly = options.childrenOnly === true;

@@ -190,21 +191,23 @@ function removeNodeHelper(node, nestedInSavedEl) {

function morphEl(fromNode, toNode, alreadyVisited) {
if (toNode.id) {
function morphEl(fromEl, toEl, alreadyVisited, childrenOnly) {
if (toEl.id) {
// If an element with an ID is being morphed then it is will be in the final
// DOM so clear it out of the saved elements collection
delete savedEls[toNode.id];
delete savedEls[toEl.id];
}
if (onBeforeMorphEl(fromNode, toNode) === false) {
return;
}
if (!childrenOnly) {
if (onBeforeMorphEl(fromEl, toEl) === false) {
return;
}
morphAttrs(fromNode, toNode);
morphAttrs(fromEl, toEl);
if (onBeforeMorphElChildren(fromNode, toNode) === false) {
return;
if (onBeforeMorphElChildren(fromEl, toEl) === false) {
return;
}
}
var curToNodeChild = toNode.firstChild;
var curFromNodeChild = fromNode.firstChild;
var curToNodeChild = toEl.firstChild;
var curFromNodeChild = fromEl.firstChild;
var curToNodeId;

@@ -274,3 +277,3 @@

// to find a match in the original DOM
removeNode(curFromNodeChild, fromNode, alreadyVisited);
removeNode(curFromNodeChild, fromEl, alreadyVisited);
curFromNodeChild = fromNextSibling;

@@ -297,3 +300,3 @@ }

// append the current "to node" to the end
fromNode.appendChild(curToNodeChild);
fromEl.appendChild(curToNodeChild);

@@ -308,11 +311,11 @@ curToNodeChild = toNextSibling;

fromNextSibling = curFromNodeChild.nextSibling;
removeNode(curFromNodeChild, fromNode, alreadyVisited);
removeNode(curFromNodeChild, fromEl, alreadyVisited);
curFromNodeChild = fromNextSibling;
}
var specialElHandler = specialElHandlers[fromNode.tagName];
var specialElHandler = specialElHandlers[fromEl.tagName];
if (specialElHandler) {
specialElHandler(fromNode, toNode);
specialElHandler(fromEl, toEl);
}
}
} // END: morphEl(...)

@@ -323,38 +326,45 @@ var morphedNode = fromNode;

// Handle the case where we are given two DOM nodes that are not
// compatible (e.g. <div> --> <span> or <div> --> TEXT)
if (morphedNodeType === 1) {
if (toNodeType === 1) {
if (morphedNode.tagName !== toNode.tagName) {
onNodeDiscarded(fromNode);
morphedNode = moveChildren(morphedNode, document.createElement(toNode.tagName));
if (!childrenOnly) {
// Handle the case where we are given two DOM nodes that are not
// compatible (e.g. <div> --> <span> or <div> --> TEXT)
if (morphedNodeType === 1) {
if (toNodeType === 1) {
if (fromNode.tagName !== toNode.tagName) {
onNodeDiscarded(fromNode);
morphedNode = moveChildren(fromNode, document.createElement(toNode.tagName));
}
} else {
// Going from an element node to a text node
morphedNode = toNode;
}
} else {
// Going from an element node to a text node
return toNode;
} else if (morphedNodeType === 3) { // Text node
if (toNodeType === 3) {
morphedNode.nodeValue = toNode.nodeValue;
return morphedNode;
} else {
// Text node to something else
morphedNode = toNode;
}
}
} else if (morphedNodeType === 3) { // Text node
if (toNodeType === 3) {
morphedNode.nodeValue = toNode.nodeValue;
return morphedNode;
} else {
onNodeDiscarded(fromNode);
// Text node to something else
return toNode;
}
}
morphEl(morphedNode, toNode, false);
if (morphedNode === toNode) {
// The "to node" was not compatible with the "from node"
// so we had to toss out the "from node" and use the "to node"
onNodeDiscarded(fromNode);
} else {
morphEl(morphedNode, toNode, false, childrenOnly);
// Fire the "onNodeDiscarded" event for any saved elements
// that never found a new home in the morphed DOM
for (var savedElId in savedEls) {
if (savedEls.hasOwnProperty(savedElId)) {
var savedEl = savedEls[savedElId];
onNodeDiscarded(savedEl);
walkDiscardedChildNodes(savedEl);
// Fire the "onNodeDiscarded" event for any saved elements
// that never found a new home in the morphed DOM
for (var savedElId in savedEls) {
if (savedEls.hasOwnProperty(savedElId)) {
var savedEl = savedEls[savedElId];
onNodeDiscarded(savedEl);
walkDiscardedChildNodes(savedEl);
}
}
}
if (morphedNode !== fromNode && fromNode.parentNode) {
if (!childrenOnly && morphedNode !== fromNode && fromNode.parentNode) {
// If we had to swap out the from node with a new node because the old

@@ -361,0 +371,0 @@ // node was not compatible with the target node then we need to

@@ -38,3 +38,3 @@ {

"dependencies": {},
"version": "0.1.14"
"version": "1.0.0"
}

@@ -75,2 +75,3 @@ morphdom

- **onBeforeMorphElChildren** (`Function(fromEl, toEl)`) - A function that will called when the children of an `HTMLElement` in the `from` tree are about to be morphed. If the listener function returns `false` then the child nodes will be skipped.
- **childrenOnly** (`Boolean`) - If `true` then only the children of the `fromEl` and `toEl` nodes will be morphed (the containing element will be skipped). Defaults to `false`.

@@ -82,3 +83,3 @@ ```javascript

return true;
}
},
onNodeDiscarded: function(node) {

@@ -92,3 +93,4 @@

return true;
}
},
childrenOnly: false
});

@@ -95,0 +97,0 @@ ```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc