@dwightbcoder/action-ui
Advanced tools
Comparing version 1.2.7 to 1.3.0
@@ -9,7 +9,6 @@ "use strict";function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(a,b,c){var d=_superPropBase(a,b);if(d){var e=Object.getOwnPropertyDescriptor(d,b);return e.get?e.get.call(3>arguments.length?a:c):e.value}},_get.apply(this,arguments)}function _superPropBase(a,b){for(;!Object.prototype.hasOwnProperty.call(a,b)&&(a=_getPrototypeOf(a),null!==a););return a}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _createForOfIteratorHelper(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(!c){if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0,e=function(){};return{s:e,n:function n(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function e(a){throw a},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,g=!0,h=!1;return{s:function s(){c=c.call(a)},n:function n(){var a=c.next();return g=a.done,a},e:function e(a){h=!0,f=a},f:function f(){try{g||null==c.return||c.return()}finally{if(h)throw f}}}}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _possibleConstructorReturn(a,b){if(b&&("object"===_typeof(b)||"function"==typeof b))return b;if(void 0!==b)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _wrapNativeSuper(a){var b="function"==typeof Map?new Map:void 0;return _wrapNativeSuper=function(a){function c(){return _construct(a,arguments,_getPrototypeOf(this).constructor)}if(null===a||!_isNativeFunction(a))return a;if("function"!=typeof a)throw new TypeError("Super expression must either be null or a function");if("undefined"!=typeof b){if(b.has(a))return b.get(a);b.set(a,c)}return c.prototype=Object.create(a.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(c,a)},_wrapNativeSuper(a)}function _construct(){return _construct=_isNativeReflectConstruct()?Reflect.construct:function(b,c,d){var e=[null];e.push.apply(e,c);var a=Function.bind.apply(b,e),f=new a;return d&&_setPrototypeOf(f,d.prototype),f},_construct.apply(null,arguments)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}function _isNativeFunction(a){return-1!==Function.toString.call(a).indexOf("[native code]")}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}var ActionUI=function(a){'use strict';/** | ||
},{key:"sync",value:function sync(a){return a=b({},a,!0),b(this,a),this}// Add watcher callback | ||
},{key:"watch",value:function watch(a){return this._watchers.push(a),this}},{key:"clearChanges",value:function clearChanges(){return this._changes={},this}},{key:"triggerChanges",value:function triggerChanges(){return this._trigger(!0)}// @deprecated | ||
},{key:"watch",value:function watch(a){return this._watchers.push(a),this}},{key:"clearChanges",value:function clearChanges(){return this._changes={},this}},{key:"triggerChanges",value:function triggerChanges(a){return a&&b(this._changes,a),this._trigger(!0)}// @deprecated | ||
},{key:"_privatize",value:function _privatize(){for(var a in this)"_"==a[0]&&Object.defineProperty(this,a,{enumerable:!1})}// Trigger all watcher callbacks | ||
},{key:"_trigger",value:function _trigger(){var a=!!(0<arguments.length&&void 0!==arguments[0])&&arguments[0];if(window.clearTimeout(this._timer),this._timer=null,a||0<Object.keys(this._changes).length){var b=this._watchers;for(var c in b)b[c].call(this,this._changes);// Clear change list | ||
this._changes={}}}// Log property change | ||
},{key:"_change",value:function _change(a,c,d){var e=this;if(this._changes[a]={value:c,originalValue:d},this._timer||(this._timer=window.setTimeout(function(){return e._trigger()},this._options.triggerDelay)),null!=this._parent){var f={};f=b({},this,!0),f[a]=d,this._parent.model._change(this._parent.property,this,f)}}}],[{key:"_proxySet",value:function _proxySet(b,c,d){var e=b[c];if(b[c]&&b[c]instanceof a)b[c].sync(d);else if(window.Reflect&&window.Reflect.set)!(d instanceof Object)||Array.isArray(d)||d instanceof a||"_"==c[0]||(d=new a(d,{model:b,property:c})),Reflect.set(b,c,d);else throw"Missing Model dependency: Reflect.set()";return"_"==c[0]?(Object.defineProperty(b,c,{enumerable:!1}),!0):(b._change(c,d,e),!0)}},{key:"_proxyDelete",value:function _proxyDelete(a,b){if(b in a){var c=a[b];delete a[b],a._change(b,void 0,c)}return!0}}]),a}(),l=/*#__PURE__*/function(){function a(b,c,d){_classCallCheck(this,a),this.name=b,this.handler=c||function(a,b,c){return a(c)},this.model=d?d:new k,this.running=!1,o.autoCache&&a.cache(this)}// trigger before event and run the handler as a promise | ||
},{key:"_trigger",value:function _trigger(){var a=!!(0<arguments.length&&void 0!==arguments[0])&&arguments[0];if(window.clearTimeout(this._timer),this._timer=null,a||0<Object.keys(this._changes).length){var b=this._watchers;for(var c in b)b[c].call(this,this._changes);null!=this._parent&&this._parent.model.triggerChanges({child:this,changes:this._changes}),this._changes={}}}// Log property change | ||
},{key:"_change",value:function _change(a,b,c){var d=this;this._changes[a]={value:b,originalValue:c},this._timer||(this._timer=window.setTimeout(function(){return d._trigger()},this._options.triggerDelay))}}],[{key:"_proxySet",value:function _proxySet(b,c,d){var e=b[c];if(b[c]&&b[c]instanceof a)b[c].sync(d);else if(window.Reflect&&window.Reflect.set)!(d instanceof Object)||Array.isArray(d)||d instanceof a||"_"==c[0]||(d=new a(d,{model:b,property:c})),Reflect.set(b,c,d);else throw"Missing Model dependency: Reflect.set()";return"_"==c[0]?(Object.defineProperty(b,c,{enumerable:!1}),!0):(b._change(c,d,e),!0)}},{key:"_proxyDelete",value:function _proxyDelete(a,b){if(b in a){var c=a[b];delete a[b],a._change(b,void 0,c)}return!0}}]),a}(),l=/*#__PURE__*/function(){function a(b,c,d){_classCallCheck(this,a),this.name=b,this.handler=c||function(a,b,c){return a(c)},this.model=d?d:new k,this.running=!1,o.autoCache&&a.cache(this)}// trigger before event and run the handler as a promise | ||
return _createClass(a,[{key:"run",value:function run(b){var c=this,d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};o.verbose&&console.info("Action.run()",this.name,{action:this,target:b,data:d}),this.running=!0,b=b||document.body,d=Object.assign(d,a.data(b));var e=!this.before(b,d),f=null;if(e)f=Promise.reject(new m("Canceled"));else if(this.handler instanceof Function)f=new Promise(function(a,b){return c.handler(a,b,d)});else if(this.handler instanceof Request){// If there is data to send, recreate the request with the data | ||
@@ -45,3 +44,3 @@ if(0<Object.keys(d).length){var g={};for(var h in this.handler)g[h]=this.handler[h];if("POST"!=g.method)"GET"==g.method&&(// Append query string to URL with ?/& first as needed | ||
if(d.type&&d.pageSize&&d.pageNumber){var j=this.data(a);if(Array.isArray(j)){var e,f=this.model(d.type),g=[],h=c({},d),i=_createForOfIteratorHelper(j);try{for(i.s();!(e=i.n()).done;){var l=e.value;g.push({id:l[this.options.keys.id],type:l[this.options.keys.type]})}}catch(a){i.e(a)}finally{i.f()}h.data=g,h.url=[b],f._paging||(f._paging=new k({current:null,type:d.type,pageNumber:d.pageNumber,pageSize:d.pageSize},{model:f,property:"_paging"})),f._paging[d.pageSize]||(f._paging[d.pageSize]=new k({},{model:f._paging,property:d.pageSize})),f._paging[d.pageSize][d.pageNumber]||(f._paging[d.pageSize][d.pageNumber]=new k({},{model:f._paging[d.pageSize],property:d.pageNumber})),f._paging[d.pageSize][d.pageNumber].sync(h)}return this.pageChange(d.type,d.pageNumber,d.pageSize)}}},{key:"url",value:function(a){var b=this.options.types[a.type]||a.type,c=this.options.baseUrl+"/"+b+"/"+(a.id?a.id+"/":""),d=new URLSearchParams;for(var f in a)f in this.options.query?d.set(this.options.query[f],a[f]):"type"!=f&&"id"!=f&&d.set(f,a[f]);d.sort();var e=d.toString();return e&&(c+="?"+e),c}},{key:"urlParse",value:function urlParse(a){if(!a)return{url:null,type:null,pageNumber:!1,pageSize:!1};-1==a.indexOf("://")&&(0<a.indexOf("/")&&(a="/"+a),a=location.origin+a);var b=new URL(a),c=b.pathname.replace(this.options.baseUrl,"").split("/"),d=c[0]||c[1];return b.searchParams.sort(),{url:b,type:d,pageNumber:parseInt(b.searchParams.get(this.options.query["page[number]"])),pageSize:parseInt(b.searchParams.get(this.options.query["page[size]"]))}}},{key:"search",value:function search(a){var b=new k;for(var e in this._model)if(!(0==e.indexOf("_")||a.type&&this.type({type:a.type})!=e))for(var f in this._model[e]){var c=!1,d=this._model[e][f];for(var g in a)c=this.propertyValueExists(d,g,a[g],this.options.searchDepth);c&&(b[f]=d)}return b}},{key:"propertyValueExists",value:function propertyValueExists(a,b,c){var d=3<arguments.length&&void 0!==arguments[3]?arguments[3]:1,e=Object.keys(a);if(-1<e.indexOf(b))return a[b]==c;if(1>=d)return!1;for(var f,g=0,h=e;g<h.length;g++)if(f=h[g],"object"==_typeof(a[f]))return this.propertyValueExists(a[f],b,c,d-1)}},{key:"fetch",value:function(){var a=_asyncToGenerator(/*#__PURE__*/regeneratorRuntime.mark(function c(a,b){var d,e,f=arguments;return regeneratorRuntime.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return d=2<f.length&&void 0!==f[2]?f[2]:{},a=this.type({type:a}),d=d||{},b=b||void 0,"object"==_typeof(b)&&(d=b,b=d.id),e=this.url(Object.assign({},d,{type:a,id:b})),this.options.verbose&&console.info("Store.fetch()",a,b,{type:a,id:b,query:d,store:this,url:e,options:this.options.fetch}),c.abrupt("return",this.fetchUrl(e,a,d));case 8:case"end":return c.stop();}},c,this)}));return function fetch(){return a.apply(this,arguments)}}()},{key:"fetchUrl",value:function(){var a=_asyncToGenerator(/*#__PURE__*/regeneratorRuntime.mark(function c(a,b){var d,e,f,g,h,i,j=arguments;return regeneratorRuntime.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(d=2<j.length&&void 0!==j[2]?j[2]:{},a){c.next=3;break}return c.abrupt("return",Promise.reject());case 3:if(c.prev=3,d=d||{},d.type=b,e=this.urlParse(a).url.toString(),f=this.urlCache(e),b=d.type||(f?f.type:null)||e.type||null,!f){c.next=12;break}return this.pageChange(f.type,f.pageNumber,f.pageSize),c.abrupt("return",Promise.resolve(f.model));case 12:return this.before(b,this.options.fetch,d),c.next=15,fetch(a,this.options.fetch);case 15:return g=c.sent,this.after(b,this.options.fetch,d,!!g&&g.ok,g),c.next=19,g.json();case 19:if(h=c.sent,g.ok){c.next=23;break}return b&&this.options.triggerChangesOnError&&this._model[b]&&this.model(b).triggerChanges(),c.abrupt("return",Promise.reject(h));case 23:return c.prev=23,i=this.sync(h,a),this.urlCache(e,i,h),c.abrupt("return",i);case 29:return c.prev=29,c.t0=c["catch"](23),b&&this.options.triggerChangesOnError&&this._model[b]&&this.model(b).triggerChanges(),c.abrupt("return",Promise.reject(h));case 33:c.next=41;break;case 35:return c.prev=35,c.t1=c["catch"](3),b&&this.options.triggerChangesOnError&&this._model[b]&&this.model(b).triggerChanges(),c.next=40,Promise.reject(c.t1);case 40:return c.abrupt("return",c.sent);case 41:case"end":return c.stop();}},c,this,[[3,35],[23,29]])}));return function fetchUrl(){return a.apply(this,arguments)}}()},{key:"urlCache",value:function urlCache(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null;if(a=decodeURIComponent(a),!b&&!c)return this._urlCache[a];var d=this.pageData(a),e=b[this.options.keys.type]||b._type||(d?d.type:null);if(c){var f,g=_createForOfIteratorHelper(this.options.keysExcludeFromCache);try{for(g.s();!(f=g.n()).done;){var h=f.value;delete c[h]}}catch(a){g.e(a)}finally{g.f()}}return this._urlCache[a]={url:a,type:e,model:b,json:c,pageNumber:!!d&&d.pageNumber,pageSize:!!d&&d.pageSize}}},{key:"pageData",value:function pageData(a){if(!a)return{type:null,pageNumber:!1,pageSize:!1};var b=this.urlParse(a),c=this._urlCache[a];return{type:b.type||(c?c.type:null),pageNumber:b.pageNumber||!!c&&c.pageNumber,pageSize:b.pageSize||!!c&&c.pageSize}}},{key:"paging",value:function paging(a){return this.model(a)._paging||{current:!1,pageNumber:!1,pageSize:!1}}},{key:"page",value:function(){var a=_asyncToGenerator(/*#__PURE__*/regeneratorRuntime.mark(function b(a){var c,d,e,f=arguments;return regeneratorRuntime.wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return c=1<f.length&&void 0!==f[1]?f[1]:1,d=2<f.length&&void 0!==f[2]?f[2]:0,e=3<f.length&&void 0!==f[3]?f[3]:{},e=e||{},d=parseInt(d)||this.options.per_page,c=parseInt(c)||1,e.type=a,e[this.options.query["page[number]"]]=c,e[this.options.query["page[size]"]]=d,b.next=11,this.fetch(a,0,e);case 11:return b.abrupt("return",b.sent);case 12:case"end":return b.stop();}},b,this)}));return function page(){return a.apply(this,arguments)}}()},{key:"pageChange",value:function pageChange(a,b,c){return!!(a&&this._model[a]._paging&&this._model[a]._paging[c][b])&&(this._model[a]._paging.pageNumber=b,this._model[a]._paging.pageSize=c,delete this._model[a]._paging.current,this._model[a]._paging.current=this._model[a]._paging[c][b],this._model[a]._paging)}},{key:"post",value:function post(a,b){var c=this;a=a||this.type(b);var d=this.url({type:a,id:this.id(b)}),e=Object.create(this.options.fetch);return e.method="POST",e.body=this.body(a,b),this.options.verbose&&console.info("Store.post()",a,{type:a,data:b,store:this,url:d,options:e}),fetch(d,e).then(function(a){return a.json().then(function(b){return a.ok?b:Promise.reject(b)})}).then(function(a){return c.sync(a,d)}).catch(function(b){return c.options.triggerChangesOnError&&c.model(a).triggerChanges(),Promise.reject(b)})}},{key:"patch",value:function patch(a,b){var d=this;a=a||this.type(b);var e=this.url({type:a,id:this.id(b)}),f={};return c(f,this.options.fetch),f.method="PATCH",f.body=this.body(a,b),this.options.verbose&&console.info("Store.patch()",a,{type:a,data:b,store:this,url:e,options:f}),fetch(e,f).then(function(a){return a.json().then(function(b){return a.ok?b:Promise.reject(b)})}).then(function(a){return d.sync(a,e)}).catch(function(b){return d.options.triggerChangesOnError&&d.model(a).triggerChanges(),Promise.reject(b)})}},{key:"delete",value:function _delete(a,b){var c=this,d=Object.create(this.options.fetch);d.method="DELETE";var e=this.url({type:a,id:b});return this.options.verbose&&console.info("Store.delete()",a,b,{type:a,id:b,store:this,url:e,options:d}),fetch(e,d).then(function(a){return a.json().then(function(b){return a.ok?b:Promise.reject(b)})}).then(function(d){return delete c._model[a][b],d}).catch(function(b){return c.options.triggerChangesOnError&&c.model(a).triggerChanges(),Promise.reject(b)})}},{key:"loading",value:function loading(a,b){this._model[a]||this.modelCreate(a);var c=this.model(a);return 1==arguments.length?c._loading:void(c._loading=!!b)}},{key:"before",value:function before(a,b,c){var d=this,e=this.options.baseUrl+"/"+a,f=null;this.loading(a,!0),this.options.viewClass&&this.options.viewMap.hasOwnProperty(a)&&(f=this.options.viewClass.cache(this.options.viewMap[a])),this.options.verbose&&console.info("Store.before()",e,{store:this,type:a,fetch:b,data:c,view:f,model:this.model(a)}),f&&document.querySelectorAll("[ui-view=\""+f.name+"\"]").forEach(function(a){d.options.viewClass.setCssClass(a,d.options.viewClass.options.cssClass.loading)});var g=new CustomEvent(this.options.eventBefore.type,this.options.eventBefore);return Object.assign(g.detail,{name:e,fetch:b,store:this,data:c,model:this.model(a),view:f}),document.dispatchEvent(g)}},{key:"after",value:function after(a,b,c,d,e){var f=this,g=this.options.baseUrl+"/"+a,h=null;this.loading(a,!1),this.options.viewClass&&this.options.viewMap.hasOwnProperty(a)&&(h=this.options.viewClass.cache(this.options.viewMap[a])),this.options.verbose&&console.info("Store.after()",g,{store:this,type:a,fetch:b,data:c,view:h,model:this.model(a),success:d,response:e}),h&&document.querySelectorAll("[ui-view=\""+h.name+"\"]").forEach(function(a){f.options.viewClass.setCssClass(a,d?f.options.viewClass.options.cssClass.success:f.options.viewClass.options.cssClass.fail)});var i=new CustomEvent(this.options.eventAfter.type,this.options.eventAfter);return Object.assign(i.detail,{name:g,success:d,fetch:b,store:this,data:c,model:this.model(a),view:h,response:e}),document.dispatchEvent(i)}}],[{key:"cache",value:function cache(a){if(null==a)return s;if("string"==typeof a){if(a=a.toLowerCase(),null!=s[a])return s[a];// Find a store that starts with the requested url to match ('/api/v1/entity' with a '/api/v1' store) | ||
for(var b in s)if(b.startsWith(a))return s[b];return}var c=a.options.baseUrl.toLowerCase();return c in s?this:(s[c]=a,this)}}]),a}(),s={},t=/*#__PURE__*/function(a){function c(a){_classCallCheck(this,c);var e={keys:{data:"data",type:"type",id:"id",links:"links",meta:"meta",included:"included"},keysExcludeFromCache:["data","included"],query:{"page[number]":"page[number]","page[size]":"page[size]"},per_page:0,fetch:{headers:{"Content-Type":"application/vnd.api+json"}},searchDepth:2};return b(e,a||{}),d.call(this,e)}_inherits(c,a);var d=_createSuper(c);return _createClass(c,[{key:"sync",value:function sync(a,b){var d=!!(2<arguments.length&&void 0!==arguments[2])&&arguments[2];if(a[this.options.keys.included]){var e=this.options.keys.data;this.options.keys.data=this.options.keys.included,_get(_getPrototypeOf(c.prototype),"sync",this).call(this,a,b,!0),this.options.keys.data=e}return _get(_getPrototypeOf(c.prototype),"sync",this).call(this,a,b,d)}},{key:"syncPaging",value:function syncPaging(a,b){var d=_get(_getPrototypeOf(c.prototype),"syncPaging",this).call(this,a,b);return d&&d.current&&(d.current[this.options.keys.links]=a[this.options.keys.links],d.current[this.options.keys.meta]=a[this.options.keys.meta]),d}},{key:"body",value:function body(a,d){var e=d.id?d.id:this.id(d),f={};return f[this.options.keys.data]={},f[this.options.keys.data][this.options.keys.type]=a,f[this.options.keys.data].attributes={},e&&(f[this.options.keys.data][this.options.keys.id]=e),d[this.options.keys.data]?b(f[this.options.keys.data],d[this.options.keys.data]):d.attributes?b(f[this.options.keys.data],d):b(f[this.options.keys.data].attributes,d),f[this.options.keys.data].attributes[this.options.keys.type]&&delete f[this.options.keys.data].attributes[this.options.keys.type],f[this.options.keys.data].attributes[this.options.keys.id]&&delete f[this.options.keys.data].attributes[this.options.keys.id],_get(_getPrototypeOf(c.prototype),"body",this).call(this,a,f)}}]),c}(r),u=/*#__PURE__*/function(a){function c(a){_classCallCheck(this,c);var e={baseUrl:"/wp-json/wp/v2",types:{page:"pages",post:"posts",category:"categories",tag:"tags",comment:"comments"},keys:{data:null,type:"type",id:"id"},query:{"page[number]":"page","page[size]":"per_page"},per_page:10};return b(e,a||{}),d.call(this,e)}_inherits(c,a);var d=_createSuper(c);return _createClass(c,[{key:"fetch",value:function fetch(a,b){var d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return"string"==typeof b&&(d.slug=b,b=void 0),_get(_getPrototypeOf(c.prototype),"fetch",this).call(this,a,b,d)}}]),c}(r),v=/*#__PURE__*/function(){function a(b,c,d){var e=this;_classCallCheck(this,a),d instanceof k||(d=new k(d||{controller:null,data:{},dev:!1,error:null,method:null,path:null,view:null})),this._name=b,this._html=c,this._model=d,d.watch(function(a){return e.update(a)}),this.constructor.options.autoCache&&a.cache(this)}return _createClass(a,[{key:"clear",value:function clear(){return document.querySelectorAll("[ui-view=\""+this._name+"\"]").forEach(function(a){a.innerHTML=""}),this}// When the model updates | ||
for(var b in s)if(b.startsWith(a))return s[b];return}var c=a.options.baseUrl.toLowerCase();return c in s?this:(s[c]=a,this)}}]),a}(),s={},t=/*#__PURE__*/function(a){function c(a){_classCallCheck(this,c);var e={keys:{data:"data",type:"type",id:"id",links:"links",meta:"meta",included:"included"},keysExcludeFromCache:["data","included"],query:{"page[number]":"page[number]","page[size]":"page[size]"},per_page:0,fetch:{headers:{"Content-Type":"application/vnd.api+json"}},searchDepth:2};return b(e,a||{}),d.call(this,e)}_inherits(c,a);var d=_createSuper(c);return _createClass(c,[{key:"sync",value:function sync(a,b){var d=!!(2<arguments.length&&void 0!==arguments[2])&&arguments[2];if(a[this.options.keys.included]){var f=this.options.keys.data;this.options.keys.data=this.options.keys.included,_get(_getPrototypeOf(c.prototype),"sync",this).call(this,a,b,!0),this.options.keys.data=f}var e=_get(_getPrototypeOf(c.prototype),"sync",this).call(this,a,b,d);return this.triggerChangesOnRelated(e.type,e.id),e}},{key:"syncPaging",value:function syncPaging(a,b){var d=_get(_getPrototypeOf(c.prototype),"syncPaging",this).call(this,a,b);return d&&d.current&&(d.current[this.options.keys.links]=a[this.options.keys.links],d.current[this.options.keys.meta]=a[this.options.keys.meta]),d}},{key:"body",value:function body(a,d){var e=d.id?d.id:this.id(d),f={};return f[this.options.keys.data]={},f[this.options.keys.data][this.options.keys.type]=a,f[this.options.keys.data].attributes={},e&&(f[this.options.keys.data][this.options.keys.id]=e),d[this.options.keys.data]?b(f[this.options.keys.data],d[this.options.keys.data]):d.attributes?b(f[this.options.keys.data],d):b(f[this.options.keys.data].attributes,d),f[this.options.keys.data].attributes[this.options.keys.type]&&delete f[this.options.keys.data].attributes[this.options.keys.type],f[this.options.keys.data].attributes[this.options.keys.id]&&delete f[this.options.keys.data].attributes[this.options.keys.id],_get(_getPrototypeOf(c.prototype),"body",this).call(this,a,f)}},{key:"triggerChangesOnRelated",value:function triggerChangesOnRelated(a,b){var c=0;for(var d in this._model)for(var e in this._model[d])if(this._model[d][e].relationships)for(var f in this._model[d][e].relationships)this._model[d][e].relationships[f].data&&a==this._model[d][e].relationships[f].data.type&&b==this._model[d][e].relationships[f].data.id&&(++c,this._model[d][e].triggerChanges({relationships:{value:{type:a,id:b}}}));return c}}]),c}(r),u=/*#__PURE__*/function(a){function c(a){_classCallCheck(this,c);var e={baseUrl:"/wp-json/wp/v2",types:{page:"pages",post:"posts",category:"categories",tag:"tags",comment:"comments"},keys:{data:null,type:"type",id:"id"},query:{"page[number]":"page","page[size]":"per_page"},per_page:10};return b(e,a||{}),d.call(this,e)}_inherits(c,a);var d=_createSuper(c);return _createClass(c,[{key:"fetch",value:function fetch(a,b){var d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return"string"==typeof b&&(d.slug=b,b=void 0),_get(_getPrototypeOf(c.prototype),"fetch",this).call(this,a,b,d)}}]),c}(r),v=/*#__PURE__*/function(){function a(b,c,d){var e=this;_classCallCheck(this,a),d instanceof k||(d=new k(d||{controller:null,data:{},dev:!1,error:null,method:null,path:null,view:null})),this._name=b,this._html=c,this._model=d,d.watch(function(a){return e.update(a)}),this.constructor.options.autoCache&&a.cache(this)}return _createClass(a,[{key:"clear",value:function clear(){return document.querySelectorAll("[ui-view=\""+this._name+"\"]").forEach(function(a){a.innerHTML=""}),this}// When the model updates | ||
},{key:"update",value:function update(a){this.constructor.options.verbose&&console.info(this.constructor.name+".update()",this.name,{view:this,changes:a}),this.render()}// Render the model data into the view template for all elements with [ui-view=this.name] | ||
@@ -48,0 +47,0 @@ /** |
@@ -228,4 +228,5 @@ var ActionUI = (function (exports) { | ||
triggerChanges() | ||
triggerChanges(changes) | ||
{ | ||
if (changes) deepAssign(this._changes, changes); | ||
return this._trigger(true) | ||
@@ -259,2 +260,7 @@ } | ||
} | ||
if (this._parent != null) | ||
{ | ||
this._parent.model.triggerChanges({ child: this, changes: this._changes}); | ||
} | ||
@@ -275,11 +281,2 @@ // Clear change list | ||
} | ||
if (this._parent != null) | ||
{ | ||
let thisCopy = {}; | ||
thisCopy = deepAssign({}, this, true); | ||
thisCopy[prop] = originalValue; | ||
this._parent.model._change(this._parent.property, this, thisCopy); | ||
} | ||
} | ||
@@ -1537,3 +1534,7 @@ | ||
return super.sync(json, url, skipPaging) | ||
let model = super.sync(json, url, skipPaging); | ||
this.triggerChangesOnRelated(model.type, model.id); | ||
return model | ||
} | ||
@@ -1582,2 +1583,30 @@ | ||
} | ||
triggerChangesOnRelated(type, id) | ||
{ | ||
let count = 0; | ||
for (const _type in this._model) | ||
{ | ||
for (const _id in this._model[_type]) | ||
{ | ||
if (this._model[_type][_id].relationships) | ||
{ | ||
for (const _name in this._model[_type][_id].relationships) | ||
{ | ||
if (this._model[_type][_id].relationships[_name].data | ||
&& type == this._model[_type][_id].relationships[_name].data.type | ||
&& id == this._model[_type][_id].relationships[_name].data.id | ||
) | ||
{ | ||
++count; | ||
this._model[_type][_id].triggerChanges({ relationships: { value: {type: type, id: id}}}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return count | ||
} | ||
} | ||
@@ -1584,0 +1613,0 @@ |
@@ -79,4 +79,5 @@ import * as Util from "./util.js"; | ||
triggerChanges() | ||
triggerChanges(changes) | ||
{ | ||
if (changes) Util.deepAssign(this._changes, changes) | ||
return this._trigger(true) | ||
@@ -110,2 +111,7 @@ } | ||
} | ||
if (this._parent != null) | ||
{ | ||
this._parent.model.triggerChanges({ child: this, changes: this._changes}) | ||
} | ||
@@ -126,11 +132,2 @@ // Clear change list | ||
} | ||
if (this._parent != null) | ||
{ | ||
let thisCopy = {} | ||
thisCopy = Util.deepAssign({}, this, true) | ||
thisCopy[prop] = originalValue | ||
this._parent.model._change(this._parent.property, this, thisCopy) | ||
} | ||
} | ||
@@ -137,0 +134,0 @@ |
@@ -44,3 +44,7 @@ import { Store } from './store.js' | ||
return super.sync(json, url, skipPaging) | ||
let model = super.sync(json, url, skipPaging) | ||
this.triggerChangesOnRelated(model.type, model.id) | ||
return model | ||
} | ||
@@ -89,4 +93,32 @@ | ||
} | ||
triggerChangesOnRelated(type, id) | ||
{ | ||
let count = 0 | ||
for (const _type in this._model) | ||
{ | ||
for (const _id in this._model[_type]) | ||
{ | ||
if (this._model[_type][_id].relationships) | ||
{ | ||
for (const _name in this._model[_type][_id].relationships) | ||
{ | ||
if (this._model[_type][_id].relationships[_name].data | ||
&& type == this._model[_type][_id].relationships[_name].data.type | ||
&& id == this._model[_type][_id].relationships[_name].data.id | ||
) | ||
{ | ||
++count | ||
this._model[_type][_id].triggerChanges({ relationships: { value: {type: type, id: id}}}) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return count | ||
} | ||
} | ||
export { StoreJsonApi } |
{ | ||
"name": "@dwightbcoder/action-ui", | ||
"version": "1.2.7", | ||
"version": "1.3.0", | ||
"description": "Action UI is a Javascript framework to simplify connecting actions to user interface elements", | ||
@@ -5,0 +5,0 @@ "main": "dist/action-ui.min.js", |
@@ -228,4 +228,5 @@ var ActionUI = (function (exports) { | ||
triggerChanges() | ||
triggerChanges(changes) | ||
{ | ||
if (changes) deepAssign(this._changes, changes); | ||
return this._trigger(true) | ||
@@ -259,2 +260,7 @@ } | ||
} | ||
if (this._parent != null) | ||
{ | ||
this._parent.model.triggerChanges({ child: this, changes: this._changes}); | ||
} | ||
@@ -275,11 +281,2 @@ // Clear change list | ||
} | ||
if (this._parent != null) | ||
{ | ||
let thisCopy = {}; | ||
thisCopy = deepAssign({}, this, true); | ||
thisCopy[prop] = originalValue; | ||
this._parent.model._change(this._parent.property, this, thisCopy); | ||
} | ||
} | ||
@@ -1537,3 +1534,7 @@ | ||
return super.sync(json, url, skipPaging) | ||
let model = super.sync(json, url, skipPaging); | ||
this.triggerChangesOnRelated(model.type, model.id); | ||
return model | ||
} | ||
@@ -1582,2 +1583,30 @@ | ||
} | ||
triggerChangesOnRelated(type, id) | ||
{ | ||
let count = 0; | ||
for (const _type in this._model) | ||
{ | ||
for (const _id in this._model[_type]) | ||
{ | ||
if (this._model[_type][_id].relationships) | ||
{ | ||
for (const _name in this._model[_type][_id].relationships) | ||
{ | ||
if (this._model[_type][_id].relationships[_name].data | ||
&& type == this._model[_type][_id].relationships[_name].data.type | ||
&& id == this._model[_type][_id].relationships[_name].data.id | ||
) | ||
{ | ||
++count; | ||
this._model[_type][_id].triggerChanges({ relationships: { value: {type: type, id: id}}}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return count | ||
} | ||
} | ||
@@ -1584,0 +1613,0 @@ |
@@ -79,4 +79,5 @@ import * as Util from "./util.js"; | ||
triggerChanges() | ||
triggerChanges(changes) | ||
{ | ||
if (changes) Util.deepAssign(this._changes, changes) | ||
return this._trigger(true) | ||
@@ -110,2 +111,7 @@ } | ||
} | ||
if (this._parent != null) | ||
{ | ||
this._parent.model.triggerChanges({ child: this, changes: this._changes}) | ||
} | ||
@@ -126,11 +132,2 @@ // Clear change list | ||
} | ||
if (this._parent != null) | ||
{ | ||
let thisCopy = {} | ||
thisCopy = Util.deepAssign({}, this, true) | ||
thisCopy[prop] = originalValue | ||
this._parent.model._change(this._parent.property, this, thisCopy) | ||
} | ||
} | ||
@@ -137,0 +134,0 @@ |
@@ -44,3 +44,7 @@ import { Store } from './store.js' | ||
return super.sync(json, url, skipPaging) | ||
let model = super.sync(json, url, skipPaging) | ||
this.triggerChangesOnRelated(model.type, model.id) | ||
return model | ||
} | ||
@@ -89,4 +93,32 @@ | ||
} | ||
triggerChangesOnRelated(type, id) | ||
{ | ||
let count = 0 | ||
for (const _type in this._model) | ||
{ | ||
for (const _id in this._model[_type]) | ||
{ | ||
if (this._model[_type][_id].relationships) | ||
{ | ||
for (const _name in this._model[_type][_id].relationships) | ||
{ | ||
if (this._model[_type][_id].relationships[_name].data | ||
&& type == this._model[_type][_id].relationships[_name].data.type | ||
&& id == this._model[_type][_id].relationships[_name].data.id | ||
) | ||
{ | ||
++count | ||
this._model[_type][_id].triggerChanges({ relationships: { value: {type: type, id: id}}}) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return count | ||
} | ||
} | ||
export { StoreJsonApi } |
Sorry, the diff of this file is too big to display
422989
10722