Socket
Socket
Sign inDemoInstall

yallajs

Package Overview
Dependencies
0
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-beta.31 to 2.0.0-beta.32

21

lib/yalla.js

@@ -388,3 +388,3 @@ "use strict";

var newValues = nextHtmlTemplate.values;
var context = nextHtmlTemplate.context;
if (!nodeValueIndexArray) {

@@ -440,3 +440,3 @@ return;

var value = newValues[valueIndexes];
Outlet.from(node).setContent(value);
Outlet.from(node).setContent(value, context);
}

@@ -502,5 +502,2 @@ nodeValueIndex.values = newActualValues;

var _ref = new Context(),
html = _ref.html;
var Outlet = function () {

@@ -551,3 +548,3 @@ function Outlet(commentNode) {

key: "setContent",
value: function setContent(template) {
value: function setContent(template, context) {
var _this5 = this;

@@ -558,6 +555,8 @@

var id = uuidv4();
this.setHtmlTemplateContent(html(_templateObject, id));
this.setHtmlTemplateContent(context.html(_templateObject, id));
template.then(function (result) {
// we needd to change instead calling document.getElementById we should use context.root.getElementById !!
var templateContent = document.getElementById(id);
if (!templateContent) {
templateContent = context.root.getElementsByTagName("*")[id];
}
if (templateContent) {

@@ -709,2 +708,3 @@ var newCommentNode = templateContent.nextSibling;

var context = newHtmlTemplateCollection.context;
if (this.instance === null) {

@@ -716,3 +716,3 @@ this.instance = {};

outletPointer.parentNode.insertBefore(childPlaceholder.commentNode, outletPointer);
Outlet.from(childPlaceholder.commentNode).setContent(template);
Outlet.from(childPlaceholder.commentNode).setContent(template, context);
outletPointer = childPlaceholder.firstChildNode();

@@ -756,3 +756,3 @@ _this7.instance[key] = childPlaceholder.commentNode;

_outletPointer.parentNode.insertBefore(childPlaceholder.commentNode, _outletPointer);
Outlet.from(childPlaceholder.commentNode).setContent(template);
Outlet.from(childPlaceholder.commentNode).setContent(template, context);
_outletPointer = childPlaceholder.firstChildNode();

@@ -934,2 +934,3 @@ _this7.instance[key] = childPlaceholder.commentNode;

var setContent = function setContent() {
templateValue.context.root = templateValue.context.root || node;
Outlet.from(node).setContent(templateValue);

@@ -936,0 +937,0 @@ if (!node.$synced) {

@@ -1,1 +0,1 @@

"use strict";function _taggedTemplateLiteral(e,t){return Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_templateObject=_taggedTemplateLiteral(['<span id="','" style="display: none" data-async-outlet>outlet</span>'],['<span id="','" style="display: none" data-async-outlet>outlet</span>']);!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"===("undefined"==typeof module?"undefined":_typeof(module))&&module.exports?module.exports=t():(e.yalla=t(),e.Context=e.Context||e.yalla.Context,e.render=e.render||e.yalla.render,e.plug=e.plug||e.yalla.plug,e.uuidv4=e.uuidv4||e.yalla.uuidv4)}("undefined"!=typeof self?self:eval("this"),function(){var e="chrome"in window&&"webstore"in window.chrome,t=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})},n=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"destroy",value:function(){throw new Error("Please implement template.destroy ")}}]),e}(),o={INPUT:["VALUE"]},i={col:"colgroup",td:"tr",area:"map",tbody:"table",tfoot:"table",th:"tr",thead:"table",tr:"tbody",caption:"table",colgroup:"table",li:"ul",g:"svg",circle:"svg",rect:"svg",polygon:"svg",eclipse:"svg",text:"svg"},r=function(e,t,n){var o=e,i=t.map(function(e){return n[e]});return t.forEach(function(e,t){o=o.replace("\x3c!--"+e+"--\x3e",i[t])}),o},a=function(e){function t(e,n,o,i){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r.items=e,r.keyFn="string"==typeof n?function(e){return e[n]}:n,r.templateFn=o,r.context=i,r.keys=[],r.templates={},r.initialzed=!1,r}return _inherits(t,n),_createClass(t,[{key:"iterateRight",value:function(e){if(this.initialzed)for(var t=this.keys.length-1;t>=0;){var n=this.items[t],o=this.keys[t],i=this.templates[o];e&&e.apply(null,[n,o,i,t]),t--}else{for(var r=this.items.length-1;r>=0;){var a=this.items[r],l=this.keyFn.apply(this,[a,r]),s=this.templateFn.apply(this,[a,r]);e&&e.apply(null,[a,l,s,r]),r--,this.keys.push(l),this.templates[l]=s}this.initialzed=!0,this.keys.reverse()}}}]),t}(),l=function(){function e(t){_classCallCheck(this,e),this.node=t,this.attributes={}}return _createClass(e,null,[{key:"from",value:function(t){var n=t;return t.nodeType===Node.ATTRIBUTE_NODE&&(n=t.ownerElement),n.$data=n.$data||new e(n),n.$data}}]),e}(),s=function(e){function t(e,n,o){_classCallCheck(this,t);var i=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return i.strings=e,i.values=n,i.context=o,i.key=i.strings.join("").trim(),i.nodeValueIndexArray=null,i.documentFragment=null,i}return _inherits(t,n),_createClass(t,[{key:"buildTemplate",value:function(e){this.documentFragment=t.getProperTemplateTag(e),this.nodeValueIndexArray=this.buildNodeValueIndex(this.documentFragment,this.documentFragment.nodeName),t.applyValues(this,this.nodeValueIndexArray)}},{key:"buildNodeValueIndex",value:function(e,n){var o=[],i=e.childNodes[0];if(void 0===i)return o;do{if(i.nodeType===Node.ELEMENT_NODE){for(var r=i.attributes,a=r.length,l=0;l<a;l++){var s=r[l].nodeValue,c=t.lookNodeValueArray(s).map(function(e){return e.match(/[\w\.]+/)[0]}).map(function(e){return parseInt(e)});c&&c.length>0&&o.push({node:r[l],valueIndexes:c,nodeValue:s})}o=o.concat(this.buildNodeValueIndex(i,i.nodeName))}if(i.nodeType===Node.TEXT_NODE&&"STYLE"===n.toUpperCase()){var u=i.nodeValue,d=t.lookNodeValueArray(u).map(function(e){return e.match(/[\w\.]+/)[0]}).map(function(e){return parseInt(e)});d&&d.length>0&&o.push({node:i,valueIndexes:d,nodeValue:u})}if(i.nodeType===Node.COMMENT_NODE){var h=i.nodeValue;i.nodeValue="outlet",o.push({node:i,valueIndexes:parseInt(h)})}i=i.nextSibling}while(i);return o}},{key:"constructTemplate",value:function(){if(!this.context.hasCache(this.key)){var e=this.buildStringSequence();return this.buildTemplate(e),this.context.cache(this.key,this)}for(var t=this.context.cache(this.key),n=t.documentFragment.querySelectorAll("span[data-async-outlet]"),o=n.length;o--;){var i=n[o];if(i.nextSibling){d.from(i.nextSibling).clearContent()}}return t}},{key:"buildStringSequence",value:function(){return this.strings.reduce(function(e,t,n){return 0===n?t:e+"\x3c!--"+(n-1)+"--\x3e"+t},"").trim()}}],[{key:"lookNodeValueArray",value:function(e){for(var t=[],n=e.indexOf("\x3c!--"),o=e.indexOf("--\x3e",n);o<e.length&&o>=0&&n>=0;)t.push(e.substring(n+4,o)),n=e.indexOf("\x3c!--",o+3),o=e.indexOf("--\x3e",n);return t}},{key:"getProperTemplateTag",value:function(e){var t=e.substring(1,e.indexOf(">"));t=(t.indexOf(" ")>0?t.substring(0,t.indexOf(" ")):t).toLowerCase();var n=i[t];n=n||"div";var o=document.createElement(n);return o.innerHTML=e,o}},{key:"applyValues",value:function(e,t){var n=e.values;t&&t.forEach(function(e){var t=e.node,i=e.valueIndexes,a=e.values,s=Array.isArray(i)?i.map(function(e){return n[e]}):n[i],c=t.nodeName,u=t.nodeType===Node.ATTRIBUTE_NODE&&0===c.indexOf("on");if(!(function(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)&&e.length===t.length){for(var n=!0,o=0;o<t.length;o++)if(!(n=n&&e[o]===t[o]))return!1;return!0}return!1}(s,a)||u&&s[0].name)){if(t.nodeType===Node.ATTRIBUTE_NODE){var h=l.from(t),f=e.nodeValue;if(u){var m=i[0];t.ownerElement[c]=n[m],h.attributes[c]=n[m]}else{var p=r(f,i,n);if(!function(e){return["checked","compact","declare","defer","disabled","ismap","noresize","noshade","nowrap","selected"].indexOf(e.nodeName)>=0}(t)?(t.ownerElement.setAttribute(c,p),function(e,t){return e=e.toUpperCase(),t=t.toUpperCase(),!!o[t]&&o[t].indexOf(e)>=0}(c,t.ownerElement.nodeName)&&(t.ownerElement[c]=p)):(t.ownerElement[c]="true"===p.trim(),t.ownerElement.setAttribute(c,"")),c.indexOf(".bind")>=0){var y=c.substring(0,c.indexOf(".bind"));t.ownerElement.setAttribute(y,p)}h.attributes[c]=p}}if(t.nodeType===Node.TEXT_NODE&&(t.nodeValue=r(e.nodeValue,i,n)),t.nodeType===Node.COMMENT_NODE){var v=n[i];d.from(t).setContent(v)}e.values=s}})}}]),t}(),c=function(){function e(){var t=this;_classCallCheck(this,e),this.cacheInstance={},this.syncCallbackStack=[],this.html=function(e){for(var n=arguments.length,o=Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return new s(e,o,t)},this.htmlCollection=function(e,n,o){return new a(e,n,o,t)}}return _createClass(e,[{key:"hasCache",value:function(e){return e in this.cacheInstance}},{key:"cache",value:function(e,t){return this.hasCache(e)||(this.cacheInstance[e]=t),this.cacheInstance[e]}},{key:"addSyncCallback",value:function(e){this.syncCallbackStack.push(e)}},{key:"clearSyncCallbacks",value:function(){this.syncCallbackStack.forEach(function(e){return e.apply()}),this.syncCallbackStack=[]}}]),e}(),u=(new c).html,d=function(){function e(t){_classCallCheck(this,e),this.commentNode=t,this.content=null}return _createClass(e,[{key:"constructTextContent",value:function(){this.content=this.commentNode.previousSibling}},{key:"constructHtmlTemplateCollectionContent",value:function(e){var t=this;this.content=new h(e,this),this.content.instance={};var n=this.commentNode;e.iterateRight(function(e,o){do{n=n.previousSibling}while(n.nodeType!==Node.COMMENT_NODE&&"outlet-child"!==n.nodeValue);t.content.instance[o]=n})}},{key:"constructHtmlTemplateContent",value:function(e){if(void 0!==e){var t=e.context.cache(e.key).documentFragment.childNodes.length;this.content=new f(e,this);for(var n=this.commentNode;t--;)n=n.previousSibling,this.content.instance.push(n);this.content.instance.reverse()}}},{key:"setContent",value:function(n){var o=this;if(function(e){return"object"===(void 0===e?"undefined":_typeof(e))&&"constructor"in e&&"Promise"===e.constructor.name}(n))if(null===this.content){var i=t();this.setHtmlTemplateContent(u(_templateObject,i)),n.then(function(t){var n=document.getElementById(i);if(n){var o=n.nextSibling;n.remove(),e.from(o).setContent(t),p(t,o)}})}else n.then(function(e){o.setContent(e)});else n instanceof y?n.factory.apply(null,[this]):n instanceof s?this.setHtmlTemplateContent(n):n instanceof a?this.setHtmlTemplateCollectionContent(n):this.setTextContent(n)}},{key:"setTextContent",value:function(e){this.content instanceof Text?this.content.nodeValue=e:(this.clearContent(),this.content=document.createTextNode(e),this.commentNode.parentNode.insertBefore(this.content,this.commentNode))}},{key:"setHtmlTemplateCollectionContent",value:function(e){var t=!1;!this.content||this.content instanceof h||(t=!0,this.clearContent()),this.content=this.content||new h(e,this),this.content.applyValues(e),t&&p(e,this.commentNode)}},{key:"setHtmlTemplateContent",value:function(e){var t=!1,n=!!(this.content&&this.content instanceof f)&&this.content.template.key===e.key;if(null===this.content||n||(this.clearContent(),t=!0),!this.content){var o=e.constructTemplate();this.content=new f(o,this)}this.content.applyValues(e),t&&p(e,this.commentNode)}},{key:"clearContent",value:function(){null!==this.content&&(this.content instanceof n?this.content.destroy():this.content.remove(),this.content=null)}},{key:"firstChildNode",value:function(){if(this.content instanceof f)return this.content.instance[0];if(this.content instanceof h){var t=this.content.template.keys[0];return e.from(this.content.instance[t]).firstChildNode()}return this.content}},{key:"validateInstancePosition",value:function(){this.content instanceof f?this.content.instance.reduceRight(function(e,t){return e.previousSibling!==t&&e.parentNode.insertBefore(t,e),t},this.commentNode):this.content instanceof h||this.commentNode.previousSibling!==this.content&&this.commentNode.parentNode.insertBefore(this.content,this.commentNode)}}],[{key:"from",value:function(t){return t instanceof Comment?(t.$data=t.$data||new e(t),t.$data):(t.$outlet||(t.$outlet=document.createComment("outlet"),t.appendChild(t.$outlet)),e.from(t.$outlet))}}]),e}(),h=function(e){function t(e,n){_classCallCheck(this,t);var o=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return o.template=e,o.outlet=n,o.instance=null,o}return _inherits(t,n),_createClass(t,[{key:"applyValues",value:function(e){var t=this;if(null===this.instance){this.instance={};var n=this.outlet.commentNode;e.iterateRight(function(e,o,i){var r=d.from(document.createComment("outlet-child"));n.parentNode.insertBefore(r.commentNode,n),d.from(r.commentNode).setContent(i),n=r.firstChildNode(),t.instance[o]=r.commentNode})}else{if(e.iterateRight(),0===e.items.length){if(this.outlet.commentNode.parentNode.$htmlCollectionInstanceChild&&1===this.outlet.commentNode.parentNode.$htmlCollectionInstanceChild.length){var o=this.outlet.commentNode.parentNode;o.innerText="",o.appendChild(this.outlet.commentNode),this.instance={}}}else{this.template.keys.forEach(function(n){if(e.keys.indexOf(n)<0){var o=t.instance[n];d.from(o).clearContent(),o.remove(),delete t.instance[n]}})}var i=this.outlet.commentNode;e.iterateRight(function(e,n,o){var r=t.instance[n];if(r){var a=d.from(r);a.setContent(o),i.previousSibling!==r&&(i.parentNode.insertBefore(r,i),a.validateInstancePosition()),i=a.firstChildNode()}else{var l=d.from(document.createComment("outlet-child"));i.parentNode.insertBefore(l.commentNode,i),d.from(l.commentNode).setContent(o),i=l.firstChildNode(),t.instance[n]=l.commentNode,t.template.context.addSyncCallback(function(){return p(o,l.commentNode)})}}),this.template=e}}},{key:"destroy",value:function(){var e=this;this.template.keys.forEach(function(t){var n=e.instance[t];d.from(n).clearContent(),n.remove(),delete e.instance[t]}),this.outlet=null,this.instance=null,this.template=null}}]),t}(),f=function(t){function o(e,t){_classCallCheck(this,o);var n=_possibleConstructorReturn(this,(o.__proto__||Object.getPrototypeOf(o)).call(this));return n.template=e,n.outlet=t,n.instance=[],n.nodeValueIndexArray=null,n}return _inherits(o,n),_createClass(o,[{key:"applyValues",value:function(t){if(null===this.instance||0===this.instance.length){s.applyValues(t,this.template.nodeValueIndexArray);var n=function t(n){if(e)return n.cloneNode(!0);for(var o=3===n.nodeType?document.createTextNode(n.nodeValue):n.cloneNode(!1),i=n.firstChild;i;)o.appendChild(t(i)),i=i.nextSibling;return o}(this.template.documentFragment),o=this.outlet.commentNode,i=n.childNodes[0],r=null;do{this.instance.push(i),r=i.nextSibling,o.parentNode.insertBefore(i,o),i=r}while(i)}else this.nodeValueIndexArray&&s.applyValues(t,this.nodeValueIndexArray)}},{key:"destroy",value:function(){this.instance.forEach(function(e){return e.remove()}),this.nodeValueIndexArray=null,this.outlet=null,this.template=null}}]),o}(),m=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],o=e.nodeValue,i=e.valueIndexes,c=function(e,t){return e.reduce(function(e,t){return"number"==typeof t?e.childNodes[t]:e.attributes[t.name]},t)}(function e(t){if(t.nodeType===Node.ATTRIBUTE_NODE)return e(t.ownerElement).concat([{name:t.nodeName}]);for(var n=0,o=t;null!==(o=o.previousSibling);)n++;var i=[];return i.push(n),t.parentNode&&t.parentNode.parentNode?e(t.parentNode).concat(i):i}(e.node),t),u=Array.isArray(i)?i.map(function(e){return n[e]}):n[i];return c.parentNode&&"STYLE"===c.parentNode.nodeName.toUpperCase()?{node:c,valueIndexes:i,nodeValue:o,values:u}:c.nodeType===Node.ATTRIBUTE_NODE?(function(e,t,n,o){var i=l.from(e),a=e.nodeName;if(0===a.indexOf("on")){var s=t[0];i.attributes[a]=n[s],e.ownerElement.setAttribute(a,"return false;"),e.ownerElement[a]=n[s]}else i.attributes[a]=r(o,t,n)}(c,i,n,o),{node:c,valueIndexes:i,nodeValue:o,values:u}):(function(e,t,n){var o=d.from(e),i=t[n];i instanceof s?(o.constructHtmlTemplateContent(i),p(i,o.commentNode)):i instanceof a?(o.constructHtmlTemplateCollectionContent(i),p(i,o.commentNode)):o.constructTextContent()}(c,n,i),{node:c,valueIndexes:i,values:u})},p=function e(t,n){var o=d.from(n);if(o.content&&o.content instanceof f){var i=o.content,r=i.template,a=t.values,l={childNodes:i.instance};if(null===r.nodeValueIndexArray){var c=r.context.cache(r.key);l={childNodes:o.content.instance},i.nodeValueIndexArray=c.nodeValueIndexArray.map(function(e){return m(e,l,a)})}else i.nodeValueIndexArray=r.nodeValueIndexArray.map(function(e){return m(e,l,a)})}if(o.content&&o.content instanceof h){var u=o.content,p=u.template.templates,y=u.template.keys;o.commentNode.parentNode.$htmlCollectionInstanceChild=o.commentNode.parentNode.$htmlCollectionInstanceChild||[],o.commentNode.parentNode.$htmlCollectionInstanceChild.push(o.commentNode),y.forEach(function(t){var n=p[t],o=u.instance[t],i=d.from(o);null===i.content?n instanceof s&&(i.constructHtmlTemplateContent(n.context.cache(n.key)),e(n,o)):i.content instanceof f&&e(n,o)})}},y=function e(t){_classCallCheck(this,e),this.factory=t};return{Context:c,render:function(e,t){var n=function(){d.from(t).setContent(e),t.$synced||(p(e,t),t.$synced=!0)};if(requestAnimationFrame in window?requestAnimationFrame(n):n(),window.Promise)return new Promise(function(t){setTimeout(function(){e.context.clearSyncCallbacks(),t()},300)});setTimeout(e.context.clearSyncCallbacks,300)},plug:function(e){return new y(e)},uuidv4:t}});
"use strict";function _taggedTemplateLiteral(e,t){return Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_templateObject=_taggedTemplateLiteral(['<span id="','" style="display: none" data-async-outlet>outlet</span>'],['<span id="','" style="display: none" data-async-outlet>outlet</span>']);!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"===("undefined"==typeof module?"undefined":_typeof(module))&&module.exports?module.exports=t():(e.yalla=t(),e.Context=e.Context||e.yalla.Context,e.render=e.render||e.yalla.render,e.plug=e.plug||e.yalla.plug,e.uuidv4=e.uuidv4||e.yalla.uuidv4)}("undefined"!=typeof self?self:eval("this"),function(){var e="chrome"in window&&"webstore"in window.chrome,t=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})},n=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"destroy",value:function(){throw new Error("Please implement template.destroy ")}}]),e}(),o={INPUT:["VALUE"]},i={col:"colgroup",td:"tr",area:"map",tbody:"table",tfoot:"table",th:"tr",thead:"table",tr:"tbody",caption:"table",colgroup:"table",li:"ul",g:"svg",circle:"svg",rect:"svg",polygon:"svg",eclipse:"svg",text:"svg"},r=function(e,t,n){var o=e,i=t.map(function(e){return n[e]});return t.forEach(function(e,t){o=o.replace("\x3c!--"+e+"--\x3e",i[t])}),o},a=function(e){function t(e,n,o,i){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r.items=e,r.keyFn="string"==typeof n?function(e){return e[n]}:n,r.templateFn=o,r.context=i,r.keys=[],r.templates={},r.initialzed=!1,r}return _inherits(t,n),_createClass(t,[{key:"iterateRight",value:function(e){if(this.initialzed)for(var t=this.keys.length-1;t>=0;){var n=this.items[t],o=this.keys[t],i=this.templates[o];e&&e.apply(null,[n,o,i,t]),t--}else{for(var r=this.items.length-1;r>=0;){var a=this.items[r],l=this.keyFn.apply(this,[a,r]),s=this.templateFn.apply(this,[a,r]);e&&e.apply(null,[a,l,s,r]),r--,this.keys.push(l),this.templates[l]=s}this.initialzed=!0,this.keys.reverse()}}}]),t}(),l=function(){function e(t){_classCallCheck(this,e),this.node=t,this.attributes={}}return _createClass(e,null,[{key:"from",value:function(t){var n=t;return t.nodeType===Node.ATTRIBUTE_NODE&&(n=t.ownerElement),n.$data=n.$data||new e(n),n.$data}}]),e}(),s=function(e){function t(e,n,o){_classCallCheck(this,t);var i=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return i.strings=e,i.values=n,i.context=o,i.key=i.strings.join("").trim(),i.nodeValueIndexArray=null,i.documentFragment=null,i}return _inherits(t,n),_createClass(t,[{key:"buildTemplate",value:function(e){this.documentFragment=t.getProperTemplateTag(e),this.nodeValueIndexArray=this.buildNodeValueIndex(this.documentFragment,this.documentFragment.nodeName),t.applyValues(this,this.nodeValueIndexArray)}},{key:"buildNodeValueIndex",value:function(e,n){var o=[],i=e.childNodes[0];if(void 0===i)return o;do{if(i.nodeType===Node.ELEMENT_NODE){for(var r=i.attributes,a=r.length,l=0;l<a;l++){var s=r[l].nodeValue,c=t.lookNodeValueArray(s).map(function(e){return e.match(/[\w\.]+/)[0]}).map(function(e){return parseInt(e)});c&&c.length>0&&o.push({node:r[l],valueIndexes:c,nodeValue:s})}o=o.concat(this.buildNodeValueIndex(i,i.nodeName))}if(i.nodeType===Node.TEXT_NODE&&"STYLE"===n.toUpperCase()){var u=i.nodeValue,d=t.lookNodeValueArray(u).map(function(e){return e.match(/[\w\.]+/)[0]}).map(function(e){return parseInt(e)});d&&d.length>0&&o.push({node:i,valueIndexes:d,nodeValue:u})}if(i.nodeType===Node.COMMENT_NODE){var h=i.nodeValue;i.nodeValue="outlet",o.push({node:i,valueIndexes:parseInt(h)})}i=i.nextSibling}while(i);return o}},{key:"constructTemplate",value:function(){if(!this.context.hasCache(this.key)){var e=this.buildStringSequence();return this.buildTemplate(e),this.context.cache(this.key,this)}for(var t=this.context.cache(this.key),n=t.documentFragment.querySelectorAll("span[data-async-outlet]"),o=n.length;o--;){var i=n[o];if(i.nextSibling){u.from(i.nextSibling).clearContent()}}return t}},{key:"buildStringSequence",value:function(){return this.strings.reduce(function(e,t,n){return 0===n?t:e+"\x3c!--"+(n-1)+"--\x3e"+t},"").trim()}}],[{key:"lookNodeValueArray",value:function(e){for(var t=[],n=e.indexOf("\x3c!--"),o=e.indexOf("--\x3e",n);o<e.length&&o>=0&&n>=0;)t.push(e.substring(n+4,o)),n=e.indexOf("\x3c!--",o+3),o=e.indexOf("--\x3e",n);return t}},{key:"getProperTemplateTag",value:function(e){var t=e.substring(1,e.indexOf(">"));t=(t.indexOf(" ")>0?t.substring(0,t.indexOf(" ")):t).toLowerCase();var n=i[t];n=n||"div";var o=document.createElement(n);return o.innerHTML=e,o}},{key:"applyValues",value:function(e,t){var n=e.values,i=e.context;t&&t.forEach(function(e){var t=e.node,a=e.valueIndexes,s=e.values,c=Array.isArray(a)?a.map(function(e){return n[e]}):n[a],d=t.nodeName,h=t.nodeType===Node.ATTRIBUTE_NODE&&0===d.indexOf("on");if(!(function(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)&&e.length===t.length){for(var n=!0,o=0;o<t.length;o++)if(!(n=n&&e[o]===t[o]))return!1;return!0}return!1}(c,s)||h&&c[0].name)){if(t.nodeType===Node.ATTRIBUTE_NODE){var f=l.from(t),m=e.nodeValue;if(h){var p=a[0];t.ownerElement[d]=n[p],f.attributes[d]=n[p]}else{var y=r(m,a,n);if(!function(e){return["checked","compact","declare","defer","disabled","ismap","noresize","noshade","nowrap","selected"].indexOf(e.nodeName)>=0}(t)?(t.ownerElement.setAttribute(d,y),function(e,t){return e=e.toUpperCase(),t=t.toUpperCase(),!!o[t]&&o[t].indexOf(e)>=0}(d,t.ownerElement.nodeName)&&(t.ownerElement[d]=y)):(t.ownerElement[d]="true"===y.trim(),t.ownerElement.setAttribute(d,"")),d.indexOf(".bind")>=0){var v=d.substring(0,d.indexOf(".bind"));t.ownerElement.setAttribute(v,y)}f.attributes[d]=y}}if(t.nodeType===Node.TEXT_NODE&&(t.nodeValue=r(e.nodeValue,a,n)),t.nodeType===Node.COMMENT_NODE){var C=n[a];u.from(t).setContent(C,i)}e.values=c}})}}]),t}(),c=function(){function e(){var t=this;_classCallCheck(this,e),this.cacheInstance={},this.syncCallbackStack=[],this.html=function(e){for(var n=arguments.length,o=Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return new s(e,o,t)},this.htmlCollection=function(e,n,o){return new a(e,n,o,t)}}return _createClass(e,[{key:"hasCache",value:function(e){return e in this.cacheInstance}},{key:"cache",value:function(e,t){return this.hasCache(e)||(this.cacheInstance[e]=t),this.cacheInstance[e]}},{key:"addSyncCallback",value:function(e){this.syncCallbackStack.push(e)}},{key:"clearSyncCallbacks",value:function(){this.syncCallbackStack.forEach(function(e){return e.apply()}),this.syncCallbackStack=[]}}]),e}(),u=function(){function e(t){_classCallCheck(this,e),this.commentNode=t,this.content=null}return _createClass(e,[{key:"constructTextContent",value:function(){this.content=this.commentNode.previousSibling}},{key:"constructHtmlTemplateCollectionContent",value:function(e){var t=this;this.content=new d(e,this),this.content.instance={};var n=this.commentNode;e.iterateRight(function(e,o){do{n=n.previousSibling}while(n.nodeType!==Node.COMMENT_NODE&&"outlet-child"!==n.nodeValue);t.content.instance[o]=n})}},{key:"constructHtmlTemplateContent",value:function(e){if(void 0!==e){var t=e.context.cache(e.key).documentFragment.childNodes.length;this.content=new h(e,this);for(var n=this.commentNode;t--;)n=n.previousSibling,this.content.instance.push(n);this.content.instance.reverse()}}},{key:"setContent",value:function(n,o){var i=this;if(function(e){return"object"===(void 0===e?"undefined":_typeof(e))&&"constructor"in e&&"Promise"===e.constructor.name}(n))if(null===this.content){var r=t();this.setHtmlTemplateContent(o.html(_templateObject,r)),n.then(function(t){var n=document.getElementById(r);if(n||(n=o.root.getElementsByTagName("*")[r]),n){var i=n.nextSibling;n.remove(),e.from(i).setContent(t),m(t,i)}})}else n.then(function(e){i.setContent(e)});else n instanceof p?n.factory.apply(null,[this]):n instanceof s?this.setHtmlTemplateContent(n):n instanceof a?this.setHtmlTemplateCollectionContent(n):this.setTextContent(n)}},{key:"setTextContent",value:function(e){this.content instanceof Text?this.content.nodeValue=e:(this.clearContent(),this.content=document.createTextNode(e),this.commentNode.parentNode.insertBefore(this.content,this.commentNode))}},{key:"setHtmlTemplateCollectionContent",value:function(e){var t=!1;!this.content||this.content instanceof d||(t=!0,this.clearContent()),this.content=this.content||new d(e,this),this.content.applyValues(e),t&&m(e,this.commentNode)}},{key:"setHtmlTemplateContent",value:function(e){var t=!1,n=!!(this.content&&this.content instanceof h)&&this.content.template.key===e.key;if(null===this.content||n||(this.clearContent(),t=!0),!this.content){var o=e.constructTemplate();this.content=new h(o,this)}this.content.applyValues(e),t&&m(e,this.commentNode)}},{key:"clearContent",value:function(){null!==this.content&&(this.content instanceof n?this.content.destroy():this.content.remove(),this.content=null)}},{key:"firstChildNode",value:function(){if(this.content instanceof h)return this.content.instance[0];if(this.content instanceof d){var t=this.content.template.keys[0];return e.from(this.content.instance[t]).firstChildNode()}return this.content}},{key:"validateInstancePosition",value:function(){this.content instanceof h?this.content.instance.reduceRight(function(e,t){return e.previousSibling!==t&&e.parentNode.insertBefore(t,e),t},this.commentNode):this.content instanceof d||this.commentNode.previousSibling!==this.content&&this.commentNode.parentNode.insertBefore(this.content,this.commentNode)}}],[{key:"from",value:function(t){return t instanceof Comment?(t.$data=t.$data||new e(t),t.$data):(t.$outlet||(t.$outlet=document.createComment("outlet"),t.appendChild(t.$outlet)),e.from(t.$outlet))}}]),e}(),d=function(e){function t(e,n){_classCallCheck(this,t);var o=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return o.template=e,o.outlet=n,o.instance=null,o}return _inherits(t,n),_createClass(t,[{key:"applyValues",value:function(e){var t=this,n=e.context;if(null===this.instance){this.instance={};var o=this.outlet.commentNode;e.iterateRight(function(e,i,r){var a=u.from(document.createComment("outlet-child"));o.parentNode.insertBefore(a.commentNode,o),u.from(a.commentNode).setContent(r,n),o=a.firstChildNode(),t.instance[i]=a.commentNode})}else{if(e.iterateRight(),0===e.items.length){if(this.outlet.commentNode.parentNode.$htmlCollectionInstanceChild&&1===this.outlet.commentNode.parentNode.$htmlCollectionInstanceChild.length){var i=this.outlet.commentNode.parentNode;i.innerText="",i.appendChild(this.outlet.commentNode),this.instance={}}}else{this.template.keys.forEach(function(n){if(e.keys.indexOf(n)<0){var o=t.instance[n];u.from(o).clearContent(),o.remove(),delete t.instance[n]}})}var r=this.outlet.commentNode;e.iterateRight(function(e,o,i){var a=t.instance[o];if(a){var l=u.from(a);l.setContent(i),r.previousSibling!==a&&(r.parentNode.insertBefore(a,r),l.validateInstancePosition()),r=l.firstChildNode()}else{var s=u.from(document.createComment("outlet-child"));r.parentNode.insertBefore(s.commentNode,r),u.from(s.commentNode).setContent(i,n),r=s.firstChildNode(),t.instance[o]=s.commentNode,t.template.context.addSyncCallback(function(){return m(i,s.commentNode)})}}),this.template=e}}},{key:"destroy",value:function(){var e=this;this.template.keys.forEach(function(t){var n=e.instance[t];u.from(n).clearContent(),n.remove(),delete e.instance[t]}),this.outlet=null,this.instance=null,this.template=null}}]),t}(),h=function(t){function o(e,t){_classCallCheck(this,o);var n=_possibleConstructorReturn(this,(o.__proto__||Object.getPrototypeOf(o)).call(this));return n.template=e,n.outlet=t,n.instance=[],n.nodeValueIndexArray=null,n}return _inherits(o,n),_createClass(o,[{key:"applyValues",value:function(t){if(null===this.instance||0===this.instance.length){s.applyValues(t,this.template.nodeValueIndexArray);var n=function t(n){if(e)return n.cloneNode(!0);for(var o=3===n.nodeType?document.createTextNode(n.nodeValue):n.cloneNode(!1),i=n.firstChild;i;)o.appendChild(t(i)),i=i.nextSibling;return o}(this.template.documentFragment),o=this.outlet.commentNode,i=n.childNodes[0],r=null;do{this.instance.push(i),r=i.nextSibling,o.parentNode.insertBefore(i,o),i=r}while(i)}else this.nodeValueIndexArray&&s.applyValues(t,this.nodeValueIndexArray)}},{key:"destroy",value:function(){this.instance.forEach(function(e){return e.remove()}),this.nodeValueIndexArray=null,this.outlet=null,this.template=null}}]),o}(),f=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],o=e.nodeValue,i=e.valueIndexes,c=function(e,t){return e.reduce(function(e,t){return"number"==typeof t?e.childNodes[t]:e.attributes[t.name]},t)}(function e(t){if(t.nodeType===Node.ATTRIBUTE_NODE)return e(t.ownerElement).concat([{name:t.nodeName}]);for(var n=0,o=t;null!==(o=o.previousSibling);)n++;var i=[];return i.push(n),t.parentNode&&t.parentNode.parentNode?e(t.parentNode).concat(i):i}(e.node),t),d=Array.isArray(i)?i.map(function(e){return n[e]}):n[i];return c.parentNode&&"STYLE"===c.parentNode.nodeName.toUpperCase()?{node:c,valueIndexes:i,nodeValue:o,values:d}:c.nodeType===Node.ATTRIBUTE_NODE?(function(e,t,n,o){var i=l.from(e),a=e.nodeName;if(0===a.indexOf("on")){var s=t[0];i.attributes[a]=n[s],e.ownerElement.setAttribute(a,"return false;"),e.ownerElement[a]=n[s]}else i.attributes[a]=r(o,t,n)}(c,i,n,o),{node:c,valueIndexes:i,nodeValue:o,values:d}):(function(e,t,n){var o=u.from(e),i=t[n];i instanceof s?(o.constructHtmlTemplateContent(i),m(i,o.commentNode)):i instanceof a?(o.constructHtmlTemplateCollectionContent(i),m(i,o.commentNode)):o.constructTextContent()}(c,n,i),{node:c,valueIndexes:i,values:d})},m=function e(t,n){var o=u.from(n);if(o.content&&o.content instanceof h){var i=o.content,r=i.template,a=t.values,l={childNodes:i.instance};if(null===r.nodeValueIndexArray){var c=r.context.cache(r.key);l={childNodes:o.content.instance},i.nodeValueIndexArray=c.nodeValueIndexArray.map(function(e){return f(e,l,a)})}else i.nodeValueIndexArray=r.nodeValueIndexArray.map(function(e){return f(e,l,a)})}if(o.content&&o.content instanceof d){var m=o.content,p=m.template.templates,y=m.template.keys;o.commentNode.parentNode.$htmlCollectionInstanceChild=o.commentNode.parentNode.$htmlCollectionInstanceChild||[],o.commentNode.parentNode.$htmlCollectionInstanceChild.push(o.commentNode),y.forEach(function(t){var n=p[t],o=m.instance[t],i=u.from(o);null===i.content?n instanceof s&&(i.constructHtmlTemplateContent(n.context.cache(n.key)),e(n,o)):i.content instanceof h&&e(n,o)})}},p=function e(t){_classCallCheck(this,e),this.factory=t};return{Context:c,render:function(e,t){var n=function(){e.context.root=e.context.root||t,u.from(t).setContent(e),t.$synced||(m(e,t),t.$synced=!0)};if(requestAnimationFrame in window?requestAnimationFrame(n):n(),window.Promise)return new Promise(function(t){setTimeout(function(){e.context.clearSyncCallbacks(),t()},300)});setTimeout(e.context.clearSyncCallbacks,300)},plug:function(e){return new p(e)},uuidv4:t}});
{
"name": "yallajs",
"version": "2.0.0-beta.31",
"version": "2.0.0-beta.32",
"description": "Web Application with zero boiler plate",

@@ -5,0 +5,0 @@ "scripts": {

@@ -256,3 +256,3 @@ (function (root, factory) {

let newValues = nextHtmlTemplate.values;
let context = nextHtmlTemplate.context;
if (!nodeValueIndexArray) {

@@ -303,3 +303,3 @@ return;

let value = newValues[valueIndexes];
Outlet.from(node).setContent(value);
Outlet.from(node).setContent(value,context);
}

@@ -410,4 +410,2 @@ nodeValueIndex.values = newActualValues;

const {html} = new Context();
class Outlet {

@@ -463,10 +461,12 @@ constructor(commentNode) {

setContent(template) {
setContent(template,context) {
if (isPromise(template)) {
if (this.content === null) {
let id = uuidv4();
this.setHtmlTemplateContent(html`<span id="${id}" style="display: none" data-async-outlet>outlet</span>`);
this.setHtmlTemplateContent(context.html`<span id="${id}" style="display: none" data-async-outlet>outlet</span>`);
template.then((result) => {
// we needd to change instead calling document.getElementById we should use context.root.getElementById !!
let templateContent = document.getElementById(id);
if(!templateContent){
templateContent = context.root.getElementsByTagName("*")[id];
}
if(templateContent){

@@ -585,2 +585,3 @@ let newCommentNode = templateContent.nextSibling;

applyValues(newHtmlTemplateCollection) {
let context = newHtmlTemplateCollection.context;
if (this.instance === null) {

@@ -592,3 +593,3 @@ this.instance = {};

outletPointer.parentNode.insertBefore(childPlaceholder.commentNode, outletPointer);
Outlet.from(childPlaceholder.commentNode).setContent(template);
Outlet.from(childPlaceholder.commentNode).setContent(template,context);
outletPointer = childPlaceholder.firstChildNode();

@@ -632,3 +633,3 @@ this.instance[key] = childPlaceholder.commentNode;

outletPointer.parentNode.insertBefore(childPlaceholder.commentNode, outletPointer);
Outlet.from(childPlaceholder.commentNode).setContent(template);
Outlet.from(childPlaceholder.commentNode).setContent(template,context);
outletPointer = childPlaceholder.firstChildNode();

@@ -781,2 +782,3 @@ this.instance[key] = childPlaceholder.commentNode;

let setContent = () => {
templateValue.context.root = templateValue.context.root || node;
Outlet.from(node).setContent(templateValue);

@@ -783,0 +785,0 @@ if (!node.$synced) {

@@ -346,6 +346,8 @@ /**

describe("Promise and async",function(){
it('Should render HtmlTemplate',function(done){
it('Should render html in async',function(done){
let {html,htmlCollection} = new Context();
let dom = document.createElement('div');
render(html`<div> ${new Promise(function (resolve){resolve(html`Hello World`)})} </div>`,dom).then(function(){
expect(true).to.equal(dom.innerHTML.toString().indexOf('<span')>0);
expect(dom.innerHTML).to.equal(`<div> Hello World<!--outlet--> </div><!--outlet-->`);
done();

@@ -356,14 +358,71 @@ });

it('Should render text in async',function(done){
let {html,htmlCollection} = new Context();
let dom = document.createElement('div');
render(html`<div> ${new Promise(function (resolve){resolve(html`Hello World`)})} </div>`,dom).then(function(){
//expect(true).to.equal(dom.innerHTML.toString().indexOf('<span')>0);
render(html`<div> ${new Promise(function (resolve){resolve(`Hello World`)})} </div>`,dom).then(function(){
expect(dom.innerHTML).to.equal(`<div> Hello World<!--outlet--> </div><!--outlet-->`);
done();
});
});
setTimeout(function(){
console.log('Hello we got update', dom.innerHTML);
it('Should render text in async',function(done){
let {html,htmlCollection} = new Context();
let dom = document.createElement('div');
render(html`<div> ${new Promise(function (resolve){resolve(html`<div>Hello World</div>`)})} </div>`,dom).then(function(){
expect(dom.innerHTML).to.equal(`<div> <div>Hello World</div><!--outlet--> </div><!--outlet-->`);
done();
},1000);
});
});
it('Should render collection in async',function(done){
let {html,htmlCollection} = new Context();
let dom = document.createElement('div');
const asyncList = () =>{
return htmlCollection([{id:uuidv4(),label:'One'},{id:uuidv4(),label:'Two'},{id:uuidv4(),label:'Three'}],'id',data => {
return new Promise(resolve => {
resolve(html`<li>${data.label}</li>`)
});
})
}
render(html`<ul> ${asyncList()} </ul>`,dom).then(function(){
expect(dom.innerHTML).to.equal(`<ul> <li>One<!--outlet--></li><!--outlet-child--><li>Two<!--outlet--></li><!--outlet-child--><li>Three<!--outlet--></li><!--outlet-child--><!--outlet--> </ul><!--outlet-->`);
done();
});
});
it('Should render collection in async',function(done){
let {html,htmlCollection} = new Context();
let dom = document.createElement('div');
const asyncList = () =>{
return htmlCollection([{id:uuidv4(),label:'One'},{id:uuidv4(),label:'Two'},{id:uuidv4(),label:'Three'}],'id',data => {
return html`<li>${new Promise(resolve => resolve(data.label))}</li>`
})
}
render(html`<ul> ${asyncList()} </ul>`,dom).then(function(){
expect(dom.innerHTML).to.equal(`<ul> <li>One<!--outlet--></li><!--outlet-child--><li>Two<!--outlet--></li><!--outlet-child--><li>Three<!--outlet--></li><!--outlet-child--><!--outlet--> </ul><!--outlet-->`);
done();
});
});
it('Should render collection in async and removal',function(done){
let {html,htmlCollection} = new Context();
let dom = document.createElement('div');
let items = [{id:uuidv4(),label:'One'},{id:uuidv4(),label:'Two'},{id:uuidv4(),label:'Three'}];
const asyncList = () =>{
return htmlCollection(items,'id',data => {
return html`<li>${new Promise(resolve => resolve(data.label))}</li>`
})
}
render(html`<ul> ${asyncList()} </ul>`,dom).then(function(){
expect(dom.innerHTML).to.equal(`<ul> <li>One<!--outlet--></li><!--outlet-child--><li>Two<!--outlet--></li><!--outlet-child--><li>Three<!--outlet--></li><!--outlet-child--><!--outlet--> </ul><!--outlet-->`);
items = [];
render(html`<ul> ${asyncList()} </ul>`,dom).then(function(){
expect(dom.innerHTML).to.equal(`<ul><!--outlet--></ul><!--outlet-->`);
done();
});
});
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc