-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.min.js
2 lines (2 loc) · 21.1 KB
/
index.min.js
1
2
/** Data Context functions for Browser and node.js. @preserve Copyright (c) 2020 Manuel Lõhmus.*/
(function(n,t){typeof exports=="object"&&typeof module!="undefined"?module.exports=t(exports):(n=typeof globalThis!="undefined"?globalThis:n||self,n.DC=t(n.DC={}))})(this,function(n){function u(n){var i,t,u;if(r||typeof n!="string")return!1;for(i="",t=n.split(".");t.length;)if(i+=i===""?t.shift():"."+t.shift(),u=eval(i),!u||!(typeof u=="function"||t.length))return!1;return!0}var r,i,t;return n&&n.name==="DC"?n:(n.name="DC",r=typeof exports!="undefined",n.IsDebuger=!1,n.IsAutoProperty=!1,r||(String.prototype.startsWith||Object.defineProperty(String.prototype,"startsWith",{value:function(n,t){var i=t>0?t|0:0;return typeof n=="string"&&this.substring(i,i+n.length)===n}}),String.prototype.endsWith||Object.defineProperty(String.prototype,"endsWith",{value:function(n,t){return t=t===undefined||t>this.length?this.length:t,typeof n=="string"&&this.substring(t-n.length,t)===n}}),String.prototype.trimStart||Object.defineProperty(String.prototype,"trimStart",{value:function(n){return this.startsWith(n)?this.substring(n.length):this.replace(/^[\s\uFEFF\xA0]+/g,"")}}),String.prototype.trimEnd||Object.defineProperty(String.prototype,"trimEnd",{value:function(n){return this.endsWith(n)?this.substring(0,this.length-n.length):this.replace(/[\s\uFEFF\xA0]+$/g,"")}}),String.prototype.includes||Object.defineProperty(String.prototype,"includes",{value:function(n){return this.indexOf(n)>-1}}),Math.cbrt||Object.defineProperty(Math,"cbrt",{value:function(n){return n<0?-Math.pow(-n,1/3):Math.pow(n,1/3)}})),n.Item=function(){function u(u,f){var e={},a,o,s,c,l,h;return e["-type"]="DC.Item",a=0,o={},Object.defineProperty(e,"-binds",{get:function(){return o}}),s={},Object.defineProperty(e,"-values",{get:function(){return s}}),Object.defineProperty(e,"isItem",{get:function(){return!0}}),c=null,Object.defineProperty(e,"parent",{get:function(){return c},set:function(n){c=n}}),l=null,Object.defineProperty(e,"parentPropertyName",{get:function(){return l},set:function(n){l=n}}),h=[],Object.defineProperty(e,"propertyNames",{get:function(){return h}}),Object.defineProperty(e,"isEmpty",{get:function(){return!e.propertyNames.length}}),Object.defineProperty(e,"isModified",{value:!0,writable:!0,configurable:!0}),Object.defineProperty(e,"isOverwriting",{value:!1,writable:!0,configurable:!0}),e.bindInvoke=function(n,t,i,r,u){var h=0,f=u?u:o,s,c,l,a;if(f=n?f[n]:f,f)for(s in f)typeof f[s]=="function"?f[s]&&(!f[s].element||f[s].element&&f[s].element.isConnected!==undefined&&f[s].element.isConnected||f[s].element&&(f[s].element.parentElement||f[s].element.parentNode))?(f[s]({newValue:t,oldValue:i,propertyPath:r}),h++):(f[s].element&&typeof f[s].element.removeBinding=="function"&&f[s].element.removeBinding(),delete f[s]):(c=e.bindInvoke(n,t,i,r,f[s]),c===0?delete f[s]:h+=c);if(n&&o&&o[""])for(l in o[""])typeof o[""][l]=="function"&&o[""][l]({newValue:t,oldValue:i,propertyPath:r});if(n&&o&&o["."])for(a in o["."])typeof o["."][a]=="function"&&r&&(r[0]==="value"||t&&(t.action==="add"||t.action==="remove"||t.action==="modified"))&&(t!==i||t&&i&&t.toString()!==i.toString())&&o["."][a]({newValue:t,oldValue:i,propertyPath:r});return n&&e.parent&&typeof e.parent.bindInvoke=="function"&&(r||(r=Array()),r.push(e.parentPropertyName),e.parent.bindInvoke("parent",t,i,r)),h},e.addBind=function(t,i,r){var f,u,s,h;if(typeof t=="string"&&typeof i=="function")return t&&t!=="."&&!e[t]&&e.defineProperty(t,null),r||(r={parentElement:{}}),f=function(n){(e[t]||n)&&i(e[t],r,n)},u=a++,o[t]?Object.keys(o[t]).forEach(function(n){(o[t][n]&&!o[t][n].element||o[t][n]&&o[t][n].element&&o[t][n].element.isConnected!==undefined&&!o[t][n].element.isConnected||o[t][n]&&o[t][n].element&&!(o[t][n].element.parentElement||o[t][n].element.parentNode))&&(o[t][n]&&o[t][n].element&&typeof o[t][n].element.removeBinding=="function"&&o[t][n].element.removeBinding(),delete o[t][n])}):o[t]={},o[t][u]=f,o[t][u].element=r,s=function(){delete o[t][u]},r.removeBinding=s,f(),h=Object.keys(o[t]).length,h>500&&(typeof n.GetPathByItem=="function"?console.warn("binds count: > 500 => datacontext"+n.GetPathByItem(e[t])+"="+e[t]):console.warn("binds count: > 500 => "+t+"="+e[t])),s},e.defineProperty=function(r,u,f,o){return u&&u.hasOwnProperty("value")&&(u=u.value),r&&r!=="parent"?(h.indexOf(r)>-1&&e.deleteProperty(r),e[r]&&delete e[r],h.push(r),Object.defineProperty(e,r,{configurable:!0,get:function(){return typeof o=="function"?o(s[r]):s[r]},set:function(u){var o=i(s[r])&&(r==="value"||s[r].propertyNames.length===0)?s[r].value:s[r],h;typeof f=="function"&&r==="value"&&(u=f(u));u===o||(u&&u.value||o&&o.value)&&(!(u&&u.value||o&&o.value)||u+""==o+"")||(!i(s[r])||i(u)||t(u)?r==="value"||s.hasOwnProperty(r)||i(u)||t(u)?r==="value"||i(u)||t(u)?s[r]=u:(s[r]=n.Item(),s[r].defineProperty("value",o,f),setTimeout(function(){s[r].value=u})):typeof u=="object"?(typeof f=="function"&&(u=f(u)),s[r]=Array.isArray(u)?n.Collection():n.Item(),e.isOverwriting?s[r].overwrite(u):s[r].init(u)):(h=n.Item(),h.defineProperty("value",u,f),u=h,s[r]=u):s[r].init(u),s[r]&&s[r].hasOwnProperty("parent")&&(s[r].parent=e),s[r]&&s[r].hasOwnProperty("parentPropertyName")&&(s[r].parentPropertyName=r),e[r]&&e[r].hasOwnProperty("isModified")?e[r].isModified=!0:r==="value"&&(e.isModified=!0),r==="value"&&e.parent&&e.parentPropertyName&&setTimeout(function(){e.parent.bindInvoke(e.parentPropertyName,s[r],o,Array(r,e.parentPropertyName))},50))}}),u!==undefined&&(e[r]=u),e[r]&&e[r].hasOwnProperty("parent")&&(e[r].parent=e),e[r]&&e[r].hasOwnProperty("parentPropertyName")&&(e[r].parentPropertyName=r),e[r]):void 0},e.setValue=function(t,i,u){return t&&((u||n.IsAutoProperty||t==="value")&&h.indexOf(t)<0&&e[t]===undefined?(i=e.defineProperty(t,i),r||u||t==="value"||console.info("AutoProperty!","propertyName:'"+t+"'","value:'"+i+"'")):e[t]&&typeof e[t].init=="function"?e[t].init(i):t==="value"&&i===null?e.defineProperty("value",i):e[t]=i),e[t]},e.deleteProperty=function(n){s[n]&&s[n].parent===e&&(s[n].parent=null);delete s[n];delete e[n];h.indexOf(n)>-1&&h.splice(h.indexOf(n),1)},e.clear=function(){for(var t=n.CreateByType(e["-type"]);e.propertyNames.length;)e.deleteProperty(e.propertyNames[0]);e.isModified=!0;t&&t.propertyNames&&t.propertyNames.length&&e.init(t);e.bindInvoke(undefined,e)},e.overwrite=function(n,t){var i=e.isOverwriting;e.isOverwriting=!0;e.init(n,t);t?e.isModified=!0:typeof t=="boolean"&&(e.isModified=!1);e.isOverwriting=i},e.init=function(r,u){var f,o,s;if(Array.isArray(r)||t(r))e.setValue("value",n.Collection(),!0),e.isOverwriting?e.value.overwrite(r,u):e.value.init(r,u);else if(typeof r=="object"&&r!==null){if(r["-isEmpty"]){e.clear();u?e.isModified=!0:typeof u=="boolean"&&(e.isModified=!1);return}f=i(r)?r.propertyNames:Object.keys(r);o=f.filter(function(n){return n[0]!=="-"});n.IsAutoProperty||f.length>1&&f.indexOf("value")>-1&&(f=f.filter(function(n){return n!=="value"}));f.forEach(function(f){if(o=o.filter(function(n){return n!==f}),f[0]==="-")(f!=="-type"||e["-type"]==="DC.Item")&&(e[f]=r[f]);else{if(typeof r[f]=="string"&&r[f].trim()==="-deleted"){e.deleteProperty(f);e.isModified=!0;typeof u=="boolean"&&(e.isModified=!1);return}if(i(e[f])||t(e[f]))e.isOverwriting?e[f].overwrite(r[f],u):e[f].init(r[f],u),u?e[f].isModified=!0:typeof u=="boolean"&&(e[f].isModified=!1);else{var s=r[f];Array.isArray(r[f])||t(r[f])?(s=n.CreateByType(r[f]["-type"],r[f]),s||(s=n.Collection()),e.isOverwriting?s.overwrite(r[f],u):s.init(r[f],u)):typeof r[f]=="object"&&r[f]!==null&&(s=n.CreateByType(r[f]["-type"],r[f]),s||(s=n.Item()),e.isOverwriting?s.overwrite(r[f],u):s.init(r[f],u));e.setValue(f,s,!0);e[f]&&e[f].hasOwnProperty("isModified")&&(u?e[f].isModified=!0:typeof u=="boolean"&&(e[f].isModified=!1))}}});n.IsAutoProperty||e.isOverwriting||o.forEach(function(n){e.deleteProperty(n)});u?e.isModified=!0:typeof u=="boolean"&&(e.isModified=!1)}else if(r===undefined)e.value&&(e.clear(),u?e.isModified=!0:typeof u=="boolean"&&(e.isModified=!1));else{if(n.IsAutoProperty||e.isOverwriting||(s=e.propertyNames.slice(0),s.forEach(function(n){n!=="value"&&e.deleteProperty(n)})),typeof r=="string"&&r.trim()==="-deleted"){e.parent&&(e.parent.isModified=!0,typeof u=="boolean"&&(e.parent.isModified=!1),e.parent.deleteProperty(e.parentPropertyName));return}e.setValue("value",r,!0);u?e.isModified=!0:typeof u=="boolean"&&(e.isModified=!1)}},e.toJSON=function(n){function s(n,t){if(e[n]!==undefined){var i=o(e[n],t);i&&(r.push('"'),r.push(n),r.push('"'),r.push(":"),r.push(i),r.push(","))}}function o(n,r){return t(n)||i(n)?n.toJSON(r):n===undefined?"null":JSON.stringify(n)}var f,r,u;return(n=typeof n=="function"?n:function(){return!0},f="",h.length!==1||h[0]!=="value"||t(e.parent)?(r=["{"],typeof e["-type"]=="string"&&(r.push('"-type":"'),r.push(e["-type"]),r.push('"'),r.push(",")),t(e.parent)&&(r.push('"-id":"'),r.push(e.parentPropertyName),r.push('"'),r.push(",")),e.isEmpty&&(r.push('"-isEmpty":"'),r.push("true"),r.push('"'),r.push(",")),h.forEach(function(t){s(t,n)}),r[r.length-1]===","&&r.pop(),r.push("}"),f=r.join("")):f=o(e.value,n),u={key:e.parentPropertyName,value:e,json:f,predict:n},n.call(u,u.key,u.value))?u.json:""},e.toPrettyJSON=function(n){var t=e.toJSON(n);return t?JSON.stringify(JSON.parse(t),null,2):t},e.toString=function(){return e.propertyNames.length===1&&e.propertyNames[0]==="value"?e.value+"":n.IsDebuger?"typeOf "+e["-type"]+" properties["+h+"]":""},e.toObject=function(){return JSON.parse(e.toJSON())},u!==undefined&&e.init(u,f),e}return u}(),i=function(n){return n&&n.isItem?!0:!1},n.IsItem=i,n.Collection=function(){function f(f,e,o){function k(r,u){var e,f;return v<u&&(v=u),e="id_"+v++,r&&r.hasOwnProperty("parent")&&(r.parent=s),r&&r.hasOwnProperty("parentPropertyName")&&(r.parentPropertyName=e),r["-id"]=e,c[e]=r,l.push(e),Object.defineProperty(s,e,{configurable:!0,get:function(){return c[e]},set:function(r){if(r!==c[e]){var u=c[e];c[e]=!c[e]||typeof c[e].setValue!="function"||i(r)||t(r)?r:n.Item(r);c[e]&&c[e].hasOwnProperty("parent")&&(c[e].parent=s);c[e]&&c[e].hasOwnProperty("parentPropertyName")&&(c[e].parentPropertyName=e);s.isOverwriting||s.bindInvoke(e,c[e],u,Array(e))}}}),f=l.length-1,Object.defineProperty(s,f,{configurable:!0,get:function(){return l[f]&&c[l[f]]?c[l[f]]:undefined},set:function(r){if(l[f]&&r!==c[l[f]]){var u=c[l[f]];!c[l[f]]||typeof c[l[f]].setValue!="function"||i(r)||t(r)?(c[l[f]]=r,c[l[f]]["-id"]=l[f]):c[l[f]]=n.Item(r);c[l[f]]&&c[l[f]].hasOwnProperty("parent")&&(c[l[f]].parent=s);c[l[f]]&&c[l[f]].hasOwnProperty("parentPropertyName")&&(c[l[f]].parentPropertyName=l[f]);s.isOverwriting||s.bindInvoke(f,c[l[f]],u,[f])}}}),l.length}function d(n,t){var i=[],r=l.splice(n,t);return r.forEach(function(n){a.push(n);c[n].parent=null;i.push(c[n]);delete c[n];delete s[n];s.hasOwnProperty(l.length)&&delete s[l.length]}),i}function g(f,e){var o;return(i(f)||t(f))&&!s.itemType?o=f:typeof eval(s.itemType)=="function"?(o=eval(s.itemType)(),typeof o.overwrite=="function"&&typeof o.init=="function"?s.isOverwriting?o.overwrite(f,e):o.init(f,e):o=eval(s.itemType)(f)):!r&&u(f["-type"])?(o=eval(f["-type"])(),typeof o.overwrite=="function"&&typeof o.init=="function"?s.isOverwriting?o.overwrite(f,e):o.init(f,e):o=eval(f["-type"])(f)):t(f)||i(f)?(o=f,s.isOverwriting?o.overwrite(f,e):o.init(f,e)):typeof f=="object"&&f!==null?Array.isArray(f)?(o=n.Collection(),s.isOverwriting?o.overwrite(f,e):o.init(f,e)):(o=n.Item(),s.isOverwriting?o.overwrite(f,e):o.init(f,e)):(o=n.Item(),s.isOverwriting?o.overwrite(f,e):o.init(f,e)),o.hasOwnProperty("isModified")&&(e?o.isModified=!0:typeof e=="boolean"&&(o.isModified=!1)),o}var s={},p,h,v,c,l,w,b,a,y;return s["-type"]="DC.Collection",p=0,h={},Object.defineProperty(s,"-binds",{get:function(){return h}}),v=0,c={},Object.defineProperty(s,"-values",{get:function(){return c}}),s.itemType=e,Object.defineProperty(s,"isCollection",{get:function(){return!0}}),l=[],Object.defineProperty(s,"propertyNames",{get:function(){return l}}),Object.defineProperty(s,"length",{get:function(){return l.length}}),w=null,Object.defineProperty(s,"parent",{get:function(){return w},set:function(n){w=n}}),b=null,Object.defineProperty(s,"parentPropertyName",{get:function(){return b},set:function(n){b=n}}),a=[],Object.defineProperty(s,"removedIDs",{get:function(){return a}}),Object.defineProperty(s,"isEmpty",{get:function(){return!s.length&&!s.removedIDs.length}}),y=!0,Object.defineProperty(s,"isModified",{get:function(){return y?y:s.filter(function(n){return n.isModified}).length>0},set:function(n){y=n},configurable:!0}),Object.defineProperty(s,"isOverwriting",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(s,"firstItem",{get:function(){return c[l[0]]}}),Object.defineProperty(s,"lastItem",{get:function(){return c[l[l.length-1]]}}),s["-values"].push=k,s["-values"].splice=d,s.bindInvokeCollection=function(n){var u=0,t,i,r;for(t in h)t!=="parent"&&t!=="values"&&(!h[t].element||h[t].element&&h[t].element.parentElement?typeof h[t]=="function"&&(h[t](n),u++):delete h[t]);if(n&&h&&h[""])for(i in h[""])typeof h[""][i]=="function"&&h[""][i]({newValue:n,oldValue:null,propertyPath:Array(s.parentPropertyName)});if(n&&h&&h["."])for(r in h["."])typeof h["."][r]=="function"&&n&&(n.action==="add"||n.action==="remove"||n.action==="modified")&&h["."][r]({newValue:n,oldValue:null,propertyPath:Array(s.parentPropertyName)});return n&&s.parent&&typeof s.parent.bindInvoke=="function"&&s.parent.bindInvoke("parent",n,null,Array(s.parentPropertyName)),u},s.addBindCollection=function(t,i){var r,u,f;if(typeof t=="function")return r=p++,i||(i={parentElement:{}}),h[r]=function(n){t(n,i)},h[r].element=i,u=function(){delete h[r]},i.removeBinding=u,h[r]({action:"addBind",items:s.toArray(!0),parent:s.parent,source:s,toString:function(){return"action:'addBind', actionItems.length:"+s.length+" source:"+s.toString()}}),f=Object.keys(h).length,f>500&&(typeof n.GetPathByItem=="function"?console.warn("binds count: > 500 => datacontext"+n.GetPathByItem(s)+"="+s.toString()):console.warn("binds count: > 500 => "+s.toString())),u},s.bindInvoke=function(n,t,i,r,u){var o=0,f=c[n]?c[n].binds:null,e,l,a,v;if(f||(f=u?u:function(){var t=[];return s.toArray(!0).forEach(function(i){i&&(!n&&i.binds?t.push(i.binds):i["-binds"]&&i["-binds"][n]&&t.push(i["-binds"][n]))}),t}()),f)for(e in f)typeof f[e]=="function"?!f[e].element||f[e].element&&f[e].element.parentElement?(f[e]({newValue:t,oldValue:i,propertyPath:r}),o++):delete f[e]:f[e]?(l=s.bindInvoke(n,t,i,r,f[e]),l===0?delete f[e]:o+=l):delete f[e];if(h&&h[""])for(a in h[""])typeof h[""][a]=="function"&&h[""][a]({newValue:t,oldValue:i,propertyPath:r});if(h&&h["."])for(v in h["."])typeof h["."][v]=="function"&&r&&(r[0]==="value"||t&&(t.action==="add"||t.action==="remove"||t.action==="modified"))&&(t!==i||t.toString()!==i.toString())&&h["."][v]({newValue:t,oldValue:i,propertyPath:r});return s.parent&&typeof s.parent.bindInvoke=="function"&&(r||(r=Array()),r.push(s.parentPropertyName),s.parent.bindInvoke("parent",t,i,r)),o},s.addBind=function(t,i,r){var f,u,e,o;if(typeof t=="string"&&typeof i=="function")return r||(r={parentElement:{}}),f=function(n){i(s[t],r,n)},u=p++,h[t]?Object.keys(h[t]).forEach(function(n){(h[t][n]&&!h[t][n].element||h[t][n]&&h[t][n].element&&h[t][n].element.isConnected!==undefined&&!h[t][n].element.isConnected||h[t][n]&&h[t][n].element&&!(h[t][n].element.parentElement||h[t][n].element.parentNode))&&(h[t][n]&&h[t][n].element&&typeof h[t][n].element.removeBinding=="function"&&h[t][n].element.removeBinding(),delete h[t][n])}):h[t]={},h[t][u]=f,h[t][u].element=r,e=function(){delete h[t][u]},r.removeBinding=e,f(),o=Object.keys(h[t]).length,o>500&&(typeof n.GetPathByItem=="function"?console.warn("binds count: > 500 => datacontext"+n.GetPathByItem(s[t])+"="+s[t]):console.warn("binds count: > 500 => "+t+"="+s[t])),e},s.add=function(n,t){var u=n&&n["-id"]?parseInt((n["-id"]+"").substr(3)):0,i=g(n,t),r;k(i,u);r={action:"add",items:[i],parent:s.parent,source:s,toString:function(){return"action:'add', actionItems.length:1 source:"+s.toString()}};s.bindInvokeCollection(r)},s.addRange=function(n,i){var r,u,o,e,h;if(arguments.length>1&&(n=Array.prototype.slice.call(arguments)),Array.isArray(n)||t(n)){for(r=[],u=0;u<n.length;u++)o=f&&f["-id"]?parseInt(f["-id"].substr(3)):0,e=g(n[u],i),r.push(e),k(e,o);h={action:"add",items:r,parent:s.parent,source:s,toString:function(){return"action:'add', actionItems.length:"+r.length+" source:"+s.toString()}};s.bindInvokeCollection(h)}else s.add(n)},s.clear=function(){s.length&&s.removeAll(function(){return!0});a=[];v=0},s.remove=function(n){var t,i,r;if(n)for(t=0;t<s.length;t++)if(s[t]!==undefined&&n(s[t]))return i=d(t,1),s.isModified=!0,r={action:"remove",items:i,parent:s.parent,source:s,toString:function(){return"action:'remove', actionItems.length:"+i.length+" source:"+s.toString()}},s.bindInvokeCollection(r),i},s.removeAll=function(n){var t=[],i,r;if(n){for(i=s.length-1;i>-1;i--)n(s[i])&&(t=t.concat(d(i,1)));s.isModified=!0;r={action:"remove",items:t,parent:s.parent,source:s,toString:function(){return"action:'remove', actionItems.length:"+t.length+" source:"+s.toString()}};s.bindInvokeCollection(r)}return t},s.moveItemTo=function(n,t,i){var r,u;n>=-1&&t>-1&&(r=s[n],s[n]=s[t],s[t]=r,s.isModified=!0,s[n].isModified=!0,s[t].isModified=!0,i||(u={action:"modified",items:[s[n],s[t]],parent:s.parent,source:s,toString:function(){return"action:'modified', actionItems.length:"+items.length+" source:"+s.toString()}},s.bindInvokeCollection(u)))},s.indexOf=function(n,t){return n?l.indexOf(n.parentPropertyName,t):-1},s.overwrite=function(n,t){var i=s.isOverwriting;s.isOverwriting=!0;s.init(n,t);t?s.isModified=!0:typeof t=="boolean"&&(s.isModified=!1);s.isOverwriting=i},s.init=function(n,i){function r(n){return n?parseInt(n.substr(3)):-1}function u(n){if(n["-deleted"]){s[n["-deleted"]]&&s.remove(function(t){return t.parentPropertyName===n["-deleted"]});a.indexOf(n["-deleted"])<0&&a.push(n["-deleted"]);var t=r(n["-deleted"]);t++;v<t&&(v=t)}else s[n["-id"]]?typeof s.overwrite=="function"&&typeof s.init=="function"?s.isOverwriting?s[n["-id"]].overwrite(n,i):s[n["-id"]].init(n,i):(i&&n&&n.hasOwnProperty("isModified")&&(n.isModified=!0),s[n["-id"]]=n):s.add(n,i)}if(s.isOverwriting||s.clear(),Array.isArray(n)||t(n)){if(n.length>0){if(!s.isOverwriting&&n.hasOwnProperty("isEmpty")&&n.isEmpty||typeof n.filter=="function"&&n.filter(function(n){return n==="-isEmpty"}).length){s.clear();return}t(n)&&(n=n.toArray(!0));n.sort(function(n,t){if(n=n["-id"]?n["-id"]:n["-deleted"],t=t["-id"]?t["-id"]:t["-deleted"],n=r(n),t=r(t),n>-1&&t>-1){if(n<t)return-1;if(n>t)return 1}else{if(n>t)return-1;if(n<t)return 1}return 0});n.forEach(function(n){u(n)})}}else n!==undefined&&n!==null?u(n):n===null&&s.clear();i?s.isModified=!0:typeof i=="boolean"&&(s.isModified=!1)},s.toJSON=function(n){function f(n,r){if(t(n)||i(n)){var u=n.toJSON(r);return u==="null"?"":u}return n===undefined?"":JSON.stringify(n)}var r,u;return(n=typeof n=="function"?n:function(){return!0},r=["["],s.isEmpty?r.push('"-isEmpty"'):(a.forEach(function(n){r.push('{"-deleted":"'+n+'"}');r.push(",")}),s.forEach(function(t){if(t!==undefined){var i={key:t.parentPropertyName,value:t,json:f(t,n),predict:n};i.json&&(r.push(i.json),r.push(","))}})),r[r.length-1]===","&&r.pop(),r.push("]"),u={key:s.parentPropertyName,value:s,json:r.join(""),predict:n},n.call(u,u.key,u.value))?u.json:""},s.toPrettyJSON=function(n){var t=s.toJSON(n);if(t)try{t=JSON.stringify(JSON.parse(t),null,2)}catch(i){console.error(i)}return t},s.toString=function(){return n.IsDebuger?"typeOf '"+s["-type"]+"<"+s.itemType+">' length = "+s.length:""},s.forEach=function(n){typeof n=="function"&&l.forEach(function(t,i){n(s[i],i,s)})},s.filter=function(n){var t=[];return typeof n=="function"&&l.forEach(function(i,r){n(s[r],r,s)&&t.push(s[r])}),t},s.find=function(n){if(typeof n=="function")for(var t=0;t<l.length;t++)if(n(s[t],t,s))return s[t]},s.sort=function(n,t){function f(n,t){n!==t&&s.moveItemTo(n,t,!0)}function e(t,i){for(var e=s[Math.floor((i+t)/2)],r=t,u=i;r<=u;){while(n(s[r],e)<0)r++;while(n(s[u],e)>0)u--;r<=u&&(f(r,u),r++,u--)}return r}function r(n,t){var i;s.length>1&&(i=e(n,t),n<i-1&&r(n,i-1),i<t&&r(i,t))}var i,u;r(0,s.length-1);t||(i=[],s.forEach(function(n){i.push(n)}),u={action:"modified",items:i,parent:s.parent,source:s,toString:function(){return"action:'modified', actionItems.length:"+i.length+" source:"+s.toString()}},s.bindInvokeCollection(u))},s.toArray=function(n){return(n?a.concat(l):l).map(function(n){return a.indexOf(n)>-1?{"-deleted":n}:c[n]?c[n]:undefined})},s.toObject=function(){return JSON.parse(s.toJSON())},f&&s.init(f,o),s}return f}(),t=function(n){return n&&n.isCollection?!0:!1},n.IsCollection=t,n.IsModifiedPredict=function(t,i,r,u){var f,e;if(!r||typeof r=="function"&&r(t,i)){if(n.IsItem(i))i.isModified?(this.json=i.toJSON(r),u||(i.isModified=!1)):i&&i.propertyNames&&i.propertyNames.length===1&&i.propertyNames[0]==="value"?this.json="":this.json!==""&&this.json!==undefined&&(f=JSON.parse(this.json),delete f["-type"],delete f["-id"],delete f["-isEmpty"],delete f.value,typeof f=="object"&&Object.keys(f).length||(this.json=""));else if(n.IsCollection(i))i.isModified?(this.json===""&&(this.json=i.toJSON(r)),u||(i.isModified=!1)):this.json!==""&&(e=JSON.parse(this.json),Array.isArray(e)&&(e=e.filter(function(n){return n!=="-isEmpty"&&Object.keys(n).indexOf("-deleted")<0})),Array.isArray(e)&&e.length||(this.json=""));else return!1;return this.json.length}return!1},n.CreateByType=function(n,t){return u(n)?eval(n)(t):null},n)});