New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dwightbcoder/action-ui

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dwightbcoder/action-ui - npm Package Compare versions

Comparing version 1.3.4 to 1.3.7

12

dist/action-ui.min.js

@@ -17,5 +17,5 @@ "use strict";function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}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';/**

// Initialize the action cache and top-level event listener (only once)
}],[{key:"init",value:function init(){document.addEventListener("click",function(b){var c=g(b.target,"[ui-action]");if(c&&"FORM"!=c.tagName){"INPUT"==c.tagName&&("checkbox"==c.type||"radio"==c.type)||b.preventDefault();var d=c.getAttribute("ui-action");// Don't run the action if it's already running
}],[{key:"init",value:function init(){document.addEventListener("click",function(b){var c=g(b.target,"[ui-action]");if(c&&"FORM"!=c.tagName&&!c.disabled&&!b.target.disabled){"INPUT"==c.tagName&&("checkbox"==c.type||"radio"==c.type)||b.preventDefault();var d=c.getAttribute("ui-action");// Don't run the action if it's already running
if(d in n)!1==n[d].running&&n[d].run(c);else if(o.autoCreate){// Auto create and run action
var e=a.createFromElement(c);a.cache(e),e.run(c)}else throw new Error("Action not found: "+d)}}),document.addEventListener("submit",function(b){if(b.target.matches("form[ui-action]")){b.preventDefault();var c=b.target.getAttribute("ui-action");// Don't run the action if it's already running
var e=a.createFromElement(c);a.cache(e),e.run(c)}else throw new Error("Action not found: "+d)}}),document.addEventListener("submit",function(b){if(b.target.matches("form[ui-action]")&&!b.target.disabled){b.preventDefault();var c=b.target.getAttribute("ui-action");// Don't run the action if it's already running
if(c in n)!1==n[c].running&&n[c].run(b.target);else if(o.autoCreate){// Auto create and run action

@@ -44,3 +44,3 @@ var d=a.createFromElement(b.target);a.cache(d),d.run(b.target)}else throw new Error("Action not found: "+c)}})}},{key:"create",value:function create(b){if(!1=="name"in b)throw"No action name specfied";return!1=="handler"in b&&(!0=="url"in b&&b.url?b.handler=new Request(b.url,b.request||{}):b.handler=null),new a(b.name,b.handler,b.model)}},{key:"createFromElement",value:function createFromElement(b){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return a.create(Object.assign({name:b.getAttribute("ui-action")||null,url:b.action||b.href||c.href||null,request:{method:b.method||c.method||"GET"}},c))}// Cache an action

if(d.type&&d.pageSize&&d.pageNumber){var e=this.pageKey(d.pageSize,d.query),f=this.data(a);if(Array.isArray(f)){var g,h=this.model(d.type),i=[],j=c({},d),l=_createForOfIteratorHelper(f);try{for(l.s();!(g=l.n()).done;){var m=g.value;i.push({id:m[this.options.keys.id],type:m[this.options.keys.type]})}}catch(a){l.e(a)}finally{l.f()}j.data=i,j.url=[b],h._paging||(h._paging=new k({current:null,type:d.type,pageNumber:d.pageNumber,pageSize:d.pageSize,pageKey:e},{model:h,property:"_paging"})),h._paging[e]||(h._paging[e]=new k({},{model:h._paging,property:e})),h._paging[e][d.pageNumber]||(h._paging[e][d.pageNumber]=new k({},{model:h._paging[e],property:d.pageNumber})),h._paging[e][d.pageNumber].sync(j)}return this.pageChange(d.type,d.pageNumber,d.pageSize,d.query)}}},{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];b.searchParams.sort();var e={};return b.searchParams.forEach(function(a,b){return e[b]=a}),{url:b,type:d,pageNumber:parseInt(b.searchParams.get(this.options.query["page[number]"])),pageSize:parseInt(b.searchParams.get(this.options.query["page[size]"])),query:e}}},{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,f.pageData.query),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,pageData:d,pageNumber:!!d&&d.pageNumber,pageSize:!!d&&d.pageSize}}},{key:"urlCacheClear",value:function urlCacheClear(a){var b=!!(1<arguments.length&&void 0!==arguments[1])&&arguments[1];if(!a)return void(this._urlCache={});for(var c,d=Object.keys(this._urlCache),e=0,f=d;e<f.length;e++)c=f[e],this._urlCache[c].type==a&&(!b||this._urlCache[c].pageNumber&&this._urlCache[c].pageSize)&&delete this._urlCache[c]}},{key:"pageData",value:function pageData(a){if(!a)return{type:null,pageNumber:!1,pageSize:!1};var b=this.urlParse(a),c=this._urlCache[a],d=b.pageSize||!!c&&c.pageSize,e=b.query||(c?c.query:{});return{type:b.type||(c?c.type:null),pageNumber:b.pageNumber||!!c&&c.pageNumber,pageSize:d,pageKey:this.pageKey(d,e),query:e,cached:!!c}}},{key:"paging",value:function paging(a){return this.model(a)._paging||{current:!1,pageNumber:!1,pageSize:!1,pageKey:!1}}},{key:"pagingReset",value:function(){var a=_asyncToGenerator(/*#__PURE__*/regeneratorRuntime.mark(function b(a){var c,d,e;return regeneratorRuntime.wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return this.urlCacheClear(a,!0),c=!1,d=!1,e=!1,this._model[a]._paging&&(this._model[a]._paging.current&&(c=this._model[a]._paging.current.pageNumber,d=this._model[a]._paging.current.pageSize,e=this._model[a]._paging.current.query,1>=this._model[a]._paging.current.data.length&&1<c&&--c),delete this._model[a]._paging),b.abrupt("return",c&&d?this.page(a,c,d,e):Promise.resolve());case 6:case"end":return b.stop();}},b,this)}));return function pagingReset(){return a.apply(this,arguments)}}()},{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){var d=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},e=this.pageKey(c,d);return!!(a&&this._model[a]._paging&&this._model[a]._paging[e][b])&&(this._model[a]._paging.pageNumber=b,this._model[a]._paging.pageSize=c,this._model[a]._paging.pageKey=e,delete this._model[a]._paging.current,this._model[a]._paging.current=this._model[a]._paging[e][b],this._model[a]._paging)}},{key:"pageKey",value:function pageKey(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};b[this.options.query["page[size]"]]=a,delete b[this.options.query["page[number]"]];var c=new URLSearchParams(b);return c.sort(),c.toString()}},{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}).then(function(){return c.pagingReset(a).catch(function(){})}).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",relationships:"relationships"},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=_defineProperty({},this.options.keys.data,a[this.options.keys.included]);this.sync(f,b,!0)}var e=_get(_getPrototypeOf(c.prototype),"sync",this).call(this,a,b,d);try{if(Array.isArray(e)||!(e[this.options.keys.type]&&e[this.options.keys.id]))for(var g in e)e[g].hasOwnProperty(this.options.keys.type)&&e[g].hasOwnProperty(this.options.keys.id)&&this.triggerChangesOnRelated(e[g][this.options.keys.type],e[g][this.options.keys.id]);else this.triggerChangesOnRelated(e[this.options.keys.type],e[this.options.keys.id])}catch(a){}return 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){if(!a||!b)return 0;var c=0;for(var d in this._model)for(var e in this._model[d])if(this._model[d][e].hasOwnProperty(this.options.keys.relationships))for(var f in this._model[d][e][this.options.keys.relationships])if(this._model[d][e][this.options.keys.relationships][f].hasOwnProperty(this.options.keys.data))if(Array.isArray(this._model[d][e][this.options.keys.relationships][f][this.options.keys.data]))for(var g in this._model[d][e][this.options.keys.relationships][f][this.options.keys.data])this._model[d][e][this.options.keys.relationships][f][this.options.keys.data]&&a==this._model[d][e][this.options.keys.relationships][f][this.options.keys.data][g][this.options.keys.type]&&b==this._model[d][e][this.options.keys.relationships][f][this.options.keys.data][g][this.options.keys.id]&&(++c,this._model[d][e].triggerChanges({relationships:{value:{type:a,id:b}}}));else this._model[d][e][this.options.keys.relationships][f][this.options.keys.data]&&a==this._model[d][e][this.options.keys.relationships][f][this.options.keys.data][this.options.keys.type]&&b==this._model[d][e][this.options.keys.relationships][f][this.options.keys.data][this.options.keys.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
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){var e;_classCallCheck(this,c);var f={keys:{data:"data",type:"type",id:"id",links:"links",meta:"meta",included:"included",relationships:"relationships"},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(f,a||{}),e=d.call(this,f),e._mapRelationships={},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=_defineProperty({},this.options.keys.data,a[this.options.keys.included]);this.sync(f,b,!0)}var e=_get(_getPrototypeOf(c.prototype),"sync",this).call(this,a,b,d);this.mapRelationships(e);try{if(Array.isArray(e)||!(e[this.options.keys.type]&&e[this.options.keys.id]))for(var g in e)e[g].hasOwnProperty(this.options.keys.type)&&e[g].hasOwnProperty(this.options.keys.id)&&this.triggerChangesOnRelated(e[g][this.options.keys.type],e[g][this.options.keys.id]);else this.triggerChangesOnRelated(e[this.options.keys.type],e[this.options.keys.id])}catch(a){}return 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:"mapRelationships",value:function mapRelationships(a){try{if(Array.isArray(a)||!(a[this.options.keys.type]&&a[this.options.keys.id]))for(var h in a)this.mapRelationships(a[h]);else if(a[this.options.keys.relationships]){var b=a[this.options.keys.type],c=a[this.options.keys.id];for(var i in a[this.options.keys.relationships])if(a[this.options.keys.relationships][i][this.options.keys.data])if(Array.isArray(a[this.options.keys.relationships][i][this.options.keys.data]))for(var j in a[this.options.keys.relationships][i][this.options.keys.data]){var d=a[this.options.keys.relationships][i][this.options.keys.data][j][this.options.keys.type],e=a[this.options.keys.relationships][i][this.options.keys.data][j][this.options.keys.id];this.mapRelationship(b,c,d,e)}else{var f=a[this.options.keys.relationships][i][this.options.keys.data][this.options.keys.type],g=a[this.options.keys.relationships][i][this.options.keys.data][this.options.keys.id];this.mapRelationship(b,c,f,g)}}}catch(a){console.error("MAP RELATIONSHIPS",a)}}},{key:"mapRelationship",value:function mapRelationship(a,b,c,d){this._mapRelationships[a]||(this._mapRelationships[a]={}),this._mapRelationships[a][b]||(this._mapRelationships[a][b]={}),this._mapRelationships[a][b][c]||(this._mapRelationships[a][b][c]=[]),-1==this._mapRelationships[a][b][c].indexOf(d)&&this._mapRelationships[a][b][c].push(d),this._mapRelationships[c]||(this._mapRelationships[c]={}),this._mapRelationships[c][d]||(this._mapRelationships[c][d]={}),this._mapRelationships[c][d][a]||(this._mapRelationships[c][d][a]=[]),-1==this._mapRelationships[c][d][a].indexOf(b)&&this._mapRelationships[c][d][a].push(b)}},{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){if(!a||!b)return 0;if(!this._mapRelationships[a]||!this._mapRelationships[a][b])return 0;var c=0;for(var f in this._mapRelationships[a][b]){var d,e=_createForOfIteratorHelper(this._mapRelationships[a][b][f]);try{for(e.s();!(d=e.n()).done;){var g=d.value;++c,this._model[f][g].triggerChanges({relationships:{value:{type:a,id:b}}})}}catch(a){e.e(a)}finally{e.f()}}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]

@@ -50,3 +50,3 @@ /**

* @returns Promise
*/},{key:"render",value:function render(){var a=this;return this.constructor.options.verbose&&console.info(this.constructor.name+".render()",this.name,{view:this}),Object.assign(this.constructor.options.eventRender.detail,{name:this.model.view,view:this}),document.querySelectorAll("[ui-view=\""+this._name+"\"]").forEach(function(b){b.innerHTML=a.html,b.dispatchEvent(a.constructor.options.eventRender),a.renderSubviews(b)}),Promise.resolve()}},{key:"renderSubviews",value:function renderSubviews(a){var b=this;this.constructor.options.verbose&&console.info(this.constructor.name+".renderSubviews()",this.name,{view:this,parent:a}),a.querySelectorAll("[ui-view]").forEach(function(a){var c=a.getAttribute("ui-view"),d=b.constructor.cache(c);d&&d.render()})}},{key:"name",get:function get(){return this._name}},{key:"html",get:function get(){return this._html instanceof Function?this._html(this._model):this._html},set:function set(a){this._html=a}},{key:"model",get:function get(){return this._model}// #region Static methods
*/},{key:"render",value:function render(){var a=this;this.constructor.options.verbose&&console.info(this.constructor.name+".render()",this.name,{view:this});var b=new CustomEvent(this.constructor.options.eventRender.type,this.constructor.options.eventRender);return Object.assign(b.detail,{name:this.model.view,view:this}),document.querySelectorAll("[ui-view=\""+this._name+"\"]").forEach(function(c){var d=!c.dispatchEvent(b);d||(c.innerHTML=b.detail.view.html,a.renderSubviews(c))}),Promise.resolve()}},{key:"renderSubviews",value:function renderSubviews(a){var b=this;this.constructor.options.verbose&&console.info(this.constructor.name+".renderSubviews()",this.name,{view:this,parent:a}),a.querySelectorAll("[ui-view]").forEach(function(a){var c=a.getAttribute("ui-view"),d=b.constructor.cache(c);d&&d.render()})}},{key:"name",get:function get(){return this._name}},{key:"html",get:function get(){return this._html instanceof Function?this._html(this._model):this._html},set:function set(a){this._html=a}},{key:"model",get:function get(){return this._model}// #region Static methods
// View factory

@@ -57,6 +57,6 @@ }],[{key:"create",value:function create(a){return this.options.verbose&&console.info(this.name+":create()",{options:a}),new this(a.name,a.html,a.model)}// Cache a view

}]),a}(),w={},x={verbose:!1,autoCache:!0,// Automatically cache views when created
eventRender:new CustomEvent("view.render",{bubbles:!0,detail:{type:"render",name:null,view:null}})},y=/*#__PURE__*/function(a){function c(a,b,e){var f;return _classCallCheck(this,c),2==arguments.length&&(e=b,b=void 0),b||(b=a),f=d.call(this,a,null,e),f.file=b,f}_inherits(c,a);var d=_createSuper(c);return _createClass(c,[{key:"clear",value:function clear(){return this.html=null,_get(_getPrototypeOf(c.prototype),"clear",this).call(this)}},{key:"render",value:function render(){var a=this;this.constructor.options.verbose&&console.info(this.constructor.name+".render()",this.name,{view:this});var b=null==this._html?this.fetch():Promise.resolve();return b.then(function(){return _get(_getPrototypeOf(c.prototype),"render",a).call(a)})}},{key:"fetch",value:function(a){function b(){return a.apply(this,arguments)}return b.toString=function(){return a.toString()},b}(function(){var a=this;return this.constructor.options.verbose&&console.info(this.constructor.name+".fetch()",this.name,{view:this}),this.fetchBefore(),fetch(this.fullPath).then(function(a){if(a.ok)return a.text();throw new Error(a.statusText)}).then(function(b){return a._html=b,a.fetchAfter(!0),a._html}).catch(function(){throw a.fetchAfter(!1),new Error("File not found: "+a.fileName)})})},{key:"fetchBefore",value:function fetchBefore(){var a=this;this.constructor.options.verbose&&console.info(this.constructor.name+".fetchBefore()",this.name,{view:this}),document.querySelectorAll("[ui-view=\""+this._name+"\"]").forEach(function(b){a.constructor.setCssClass(b,z.cssClass.loading)}),this.constructor.options.eventFetch&&(Object.assign(this.constructor.options.eventFetch.detail,{view:this,success:null}),document.dispatchEvent(this.constructor.options.eventFetch))}},{key:"fetchAfter",value:function fetchAfter(a){var b=this;this.constructor.options.verbose&&console.info(this.constructor.name+".fetchAfter()",this.name,{view:this}),document.querySelectorAll("[ui-view=\""+this._name+"\"]").forEach(function(c){b.constructor.setCssClass(c,a?z.cssClass.success:z.cssClass.fail)}),this.constructor.options.eventFetch&&(Object.assign(this.constructor.options.eventFetch.detail,{view:this,success:a}),document.dispatchEvent(this.constructor.options.eventFetch))}},{key:"fileName",get:function get(){return this.file+"."+this.constructor.options.extension}},{key:"fullPath",get:function get(){return this.constructor.options.basePath+this.fileName}},{key:"file",get:function get(){return this._file},set:function set(a){a!=this._file&&(this._html=null),this._file=a}// #region Static methods
eventRender:new CustomEvent("view.render",{bubbles:!0,cancelable:!0,detail:{type:"render",name:null,view:null}})},y=/*#__PURE__*/function(a){function c(a,b,e){var f;return _classCallCheck(this,c),2==arguments.length&&(e=b,b=void 0),b||(b=a),f=d.call(this,a,null,e),f.file=b,f}_inherits(c,a);var d=_createSuper(c);return _createClass(c,[{key:"clear",value:function clear(){return this.html=null,_get(_getPrototypeOf(c.prototype),"clear",this).call(this)}},{key:"render",value:function render(){var a=this;this.constructor.options.verbose&&console.info(this.constructor.name+".render()",this.name,{view:this});var b=null==this._html?this.fetch():Promise.resolve();return b.then(function(){return _get(_getPrototypeOf(c.prototype),"render",a).call(a)})}},{key:"fetch",value:function(a){function b(){return a.apply(this,arguments)}return b.toString=function(){return a.toString()},b}(function(){var a=this;return this.constructor.options.verbose&&console.info(this.constructor.name+".fetch()",this.name,{view:this}),this.fetchBefore(),fetch(this.fullPath).then(function(a){if(a.ok)return a.text();throw new Error(a.statusText)}).then(function(b){return a._html=b,a.fetchAfter(!0),a._html}).catch(function(){throw a.fetchAfter(!1),new Error("File not found: "+a.fileName)})})},{key:"fetchBefore",value:function fetchBefore(){var a=this;this.constructor.options.verbose&&console.info(this.constructor.name+".fetchBefore()",this.name,{view:this}),document.querySelectorAll("[ui-view=\""+this._name+"\"]").forEach(function(b){a.constructor.setCssClass(b,z.cssClass.loading)}),this.constructor.options.eventFetch&&(Object.assign(this.constructor.options.eventFetch.detail,{view:this,success:null}),document.dispatchEvent(this.constructor.options.eventFetch))}},{key:"fetchAfter",value:function fetchAfter(a){var b=this;this.constructor.options.verbose&&console.info(this.constructor.name+".fetchAfter()",this.name,{view:this}),document.querySelectorAll("[ui-view=\""+this._name+"\"]").forEach(function(c){b.constructor.setCssClass(c,a?z.cssClass.success:z.cssClass.fail)}),this.constructor.options.eventFetch&&(Object.assign(this.constructor.options.eventFetch.detail,{view:this,success:a}),document.dispatchEvent(this.constructor.options.eventFetch))}},{key:"fileName",get:function get(){return this.file+"."+this.constructor.options.extension}},{key:"fullPath",get:function get(){return this.constructor.options.basePath+this.fileName}},{key:"file",get:function get(){return this._file},set:function set(a){a!=this._file&&(this._html=null),this._file=a}// #region Static methods
// View factory
}],[{key:"create",value:function create(a){return this.options.verbose&&console.info(this.name+":create()",{options:a}),a.file&&(a.file=a.name),new this(a.name,a.file,a.model)}},{key:"setCssClass",value:function setCssClass(a,b){for(var c in z.cssClass)a.classList.remove(z.cssClass[c]);a.classList.add(b)}},{key:"options",get:function get(){return z},set:function set(a){b(z,a)}// #endregion
}]),c}(v),z={basePath:"view/",extension:"html",cssClass:{loading:"loading",success:"success",fail:"fail"},eventFetch:new CustomEvent("view.fetch",{bubbles:!0,detail:{type:"fetch",view:null,success:null}}),eventRender:new CustomEvent("view.render",{bubbles:!0,detail:{type:"render",view:null}})};/**
}]),c}(v),z={basePath:"view/",extension:"html",cssClass:{loading:"loading",success:"success",fail:"fail"},eventFetch:new CustomEvent("view.fetch",{bubbles:!0,detail:{type:"fetch",view:null,success:null}}),eventRender:new CustomEvent("view.render",{bubbles:!0,cancelable:!0,detail:{type:"render",view:null}})};/**
* JsonApi

@@ -63,0 +63,0 @@ * @description Json API data store

@@ -164,3 +164,3 @@ import * as Util from './util.js'

if (target && target.tagName != 'FORM')
if (target && target.tagName != 'FORM' && !target.disabled && !e.target.disabled)
{

@@ -196,3 +196,3 @@ if (!(target.tagName == 'INPUT' && (target.type == 'checkbox' || target.type == 'radio')))

{
if (e.target.matches('form[ui-action]'))
if (e.target.matches('form[ui-action]') && !e.target.disabled)
{

@@ -199,0 +199,0 @@ e.preventDefault()

@@ -33,2 +33,3 @@ import { Store } from './store.js'

super(_options)
this._mapRelationships = {}
}

@@ -45,2 +46,3 @@

let model = super.sync(json, url, skipPaging)
this.mapRelationships(model)

@@ -80,2 +82,72 @@ try

mapRelationships(model)
{
try
{
if (Array.isArray(model) || !(model[this.options.keys.type] && model[this.options.keys.id]))
{
for (const i in model)
{
this.mapRelationships(model[i])
}
}
else if (model[this.options.keys.relationships])
{
const type = model[this.options.keys.type]
const id = model[this.options.keys.id]
for (const i in model[this.options.keys.relationships])
{
if (model[this.options.keys.relationships][i][this.options.keys.data])
{
if (Array.isArray(model[this.options.keys.relationships][i][this.options.keys.data]))
{
for (const ii in model[this.options.keys.relationships][i][this.options.keys.data])
{
const relationType = model[this.options.keys.relationships][i][this.options.keys.data][ii][this.options.keys.type]
const relationId = model[this.options.keys.relationships][i][this.options.keys.data][ii][this.options.keys.id]
this.mapRelationship(type, id, relationType, relationId)
}
}
else
{
const relationType = model[this.options.keys.relationships][i][this.options.keys.data][this.options.keys.type]
const relationId = model[this.options.keys.relationships][i][this.options.keys.data][this.options.keys.id]
this.mapRelationship(type, id, relationType, relationId)
}
}
}
}
}
catch (e) { console.error('MAP RELATIONSHIPS', e) }
}
mapRelationship(type, id, relationType, relationId)
{
if (!this._mapRelationships[type])
this._mapRelationships[type] = {}
if (!this._mapRelationships[type][id])
this._mapRelationships[type][id] = {}
if (!this._mapRelationships[type][id][relationType])
this._mapRelationships[type][id][relationType] = []
if (this._mapRelationships[type][id][relationType].indexOf(relationId) == -1)
this._mapRelationships[type][id][relationType].push(relationId)
// Reverse map
if (!this._mapRelationships[relationType])
this._mapRelationships[relationType] = {}
if (!this._mapRelationships[relationType][relationId])
this._mapRelationships[relationType][relationId] = {}
if (!this._mapRelationships[relationType][relationId][type])
this._mapRelationships[relationType][relationId][type] = []
if (this._mapRelationships[relationType][relationId][type].indexOf(id) == -1)
this._mapRelationships[relationType][relationId][type].push(id)
}
body(type, data)

@@ -113,43 +185,12 @@ {

if (!type || !id) return 0
if (!this._mapRelationships[type] || !this._mapRelationships[type][id]) return 0
let count = 0
for (const _type in this._model)
for (const relationType in this._mapRelationships[type][id])
{
for (const _id in this._model[_type])
for (const relationId of this._mapRelationships[type][id][relationType])
{
if (this._model[_type][_id].hasOwnProperty(this.options.keys.relationships))
{
for (const _name in this._model[_type][_id][this.options.keys.relationships])
{
if (this._model[_type][_id][this.options.keys.relationships][_name].hasOwnProperty(this.options.keys.data))
{
if (Array.isArray(this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data]))
{
for (const i in this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data])
{
if (this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data]
&& type == this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data][i][this.options.keys.type]
&& id == this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data][i][this.options.keys.id]
)
{
++count
this._model[_type][_id].triggerChanges({ relationships: { value: { type: type, id: id } } })
}
}
}
else
{
if (this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data]
&& type == this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data][this.options.keys.type]
&& id == this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data][this.options.keys.id]
)
{
++count
this._model[_type][_id].triggerChanges({ relationships: { value: { type: type, id: id } } })
}
}
}
}
}
++count
this._model[relationType][relationId].triggerChanges({ relationships: { value: { type: type, id: id } } })
}

@@ -156,0 +197,0 @@ }

@@ -153,3 +153,3 @@ import { View } from './view.js'

eventFetch: new CustomEvent('view.fetch', { bubbles: true, detail: { type: 'fetch', view: null, success: null } }),
eventRender: new CustomEvent('view.render', { bubbles: true, detail: { type: 'render', view: null } })
eventRender: new CustomEvent('view.render', { bubbles: true, cancelable: true, detail: { type: 'render', view: null } })
}

@@ -156,0 +156,0 @@ ViewFile.options = View.options

@@ -59,3 +59,6 @@ import { deepAssign } from './util.js'

Object.assign(this.constructor.options.eventRender.detail, {
let eventRender = new CustomEvent(this.constructor.options.eventRender.type, this.constructor.options.eventRender)
Object.assign(eventRender.detail,
{
name: this.model.view,

@@ -69,5 +72,8 @@ view: this

{
_target.innerHTML = this.html
_target.dispatchEvent(this.constructor.options.eventRender)
this.renderSubviews(_target)
let canceled = !_target.dispatchEvent(eventRender)
if (!canceled)
{
_target.innerHTML = eventRender.detail.view.html
this.renderSubviews(_target)
}
})

@@ -143,5 +149,5 @@

autoCache: true, // Automatically cache views when created
eventRender: new CustomEvent('view.render', { bubbles: true, detail: { type: 'render', name: null, view: null } })
eventRender: new CustomEvent('view.render', { bubbles: true, cancelable: true, detail: { type: 'render', name: null, view: null } })
}
export { View }
{
"name": "@dwightbcoder/action-ui",
"version": "1.3.4",
"version": "1.3.7",
"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",

@@ -164,3 +164,3 @@ import * as Util from './util.js'

if (target && target.tagName != 'FORM')
if (target && target.tagName != 'FORM' && !target.disabled && !e.target.disabled)
{

@@ -196,3 +196,3 @@ if (!(target.tagName == 'INPUT' && (target.type == 'checkbox' || target.type == 'radio')))

{
if (e.target.matches('form[ui-action]'))
if (e.target.matches('form[ui-action]') && !e.target.disabled)
{

@@ -199,0 +199,0 @@ e.preventDefault()

@@ -33,2 +33,3 @@ import { Store } from './store.js'

super(_options)
this._mapRelationships = {}
}

@@ -45,2 +46,3 @@

let model = super.sync(json, url, skipPaging)
this.mapRelationships(model)

@@ -80,2 +82,72 @@ try

mapRelationships(model)
{
try
{
if (Array.isArray(model) || !(model[this.options.keys.type] && model[this.options.keys.id]))
{
for (const i in model)
{
this.mapRelationships(model[i])
}
}
else if (model[this.options.keys.relationships])
{
const type = model[this.options.keys.type]
const id = model[this.options.keys.id]
for (const i in model[this.options.keys.relationships])
{
if (model[this.options.keys.relationships][i][this.options.keys.data])
{
if (Array.isArray(model[this.options.keys.relationships][i][this.options.keys.data]))
{
for (const ii in model[this.options.keys.relationships][i][this.options.keys.data])
{
const relationType = model[this.options.keys.relationships][i][this.options.keys.data][ii][this.options.keys.type]
const relationId = model[this.options.keys.relationships][i][this.options.keys.data][ii][this.options.keys.id]
this.mapRelationship(type, id, relationType, relationId)
}
}
else
{
const relationType = model[this.options.keys.relationships][i][this.options.keys.data][this.options.keys.type]
const relationId = model[this.options.keys.relationships][i][this.options.keys.data][this.options.keys.id]
this.mapRelationship(type, id, relationType, relationId)
}
}
}
}
}
catch (e) { console.error('MAP RELATIONSHIPS', e) }
}
mapRelationship(type, id, relationType, relationId)
{
if (!this._mapRelationships[type])
this._mapRelationships[type] = {}
if (!this._mapRelationships[type][id])
this._mapRelationships[type][id] = {}
if (!this._mapRelationships[type][id][relationType])
this._mapRelationships[type][id][relationType] = []
if (this._mapRelationships[type][id][relationType].indexOf(relationId) == -1)
this._mapRelationships[type][id][relationType].push(relationId)
// Reverse map
if (!this._mapRelationships[relationType])
this._mapRelationships[relationType] = {}
if (!this._mapRelationships[relationType][relationId])
this._mapRelationships[relationType][relationId] = {}
if (!this._mapRelationships[relationType][relationId][type])
this._mapRelationships[relationType][relationId][type] = []
if (this._mapRelationships[relationType][relationId][type].indexOf(id) == -1)
this._mapRelationships[relationType][relationId][type].push(id)
}
body(type, data)

@@ -113,43 +185,12 @@ {

if (!type || !id) return 0
if (!this._mapRelationships[type] || !this._mapRelationships[type][id]) return 0
let count = 0
for (const _type in this._model)
for (const relationType in this._mapRelationships[type][id])
{
for (const _id in this._model[_type])
for (const relationId of this._mapRelationships[type][id][relationType])
{
if (this._model[_type][_id].hasOwnProperty(this.options.keys.relationships))
{
for (const _name in this._model[_type][_id][this.options.keys.relationships])
{
if (this._model[_type][_id][this.options.keys.relationships][_name].hasOwnProperty(this.options.keys.data))
{
if (Array.isArray(this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data]))
{
for (const i in this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data])
{
if (this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data]
&& type == this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data][i][this.options.keys.type]
&& id == this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data][i][this.options.keys.id]
)
{
++count
this._model[_type][_id].triggerChanges({ relationships: { value: { type: type, id: id } } })
}
}
}
else
{
if (this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data]
&& type == this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data][this.options.keys.type]
&& id == this._model[_type][_id][this.options.keys.relationships][_name][this.options.keys.data][this.options.keys.id]
)
{
++count
this._model[_type][_id].triggerChanges({ relationships: { value: { type: type, id: id } } })
}
}
}
}
}
++count
this._model[relationType][relationId].triggerChanges({ relationships: { value: { type: type, id: id } } })
}

@@ -156,0 +197,0 @@ }

@@ -153,3 +153,3 @@ import { View } from './view.js'

eventFetch: new CustomEvent('view.fetch', { bubbles: true, detail: { type: 'fetch', view: null, success: null } }),
eventRender: new CustomEvent('view.render', { bubbles: true, detail: { type: 'render', view: null } })
eventRender: new CustomEvent('view.render', { bubbles: true, cancelable: true, detail: { type: 'render', view: null } })
}

@@ -156,0 +156,0 @@ ViewFile.options = View.options

@@ -59,3 +59,6 @@ import { deepAssign } from './util.js'

Object.assign(this.constructor.options.eventRender.detail, {
let eventRender = new CustomEvent(this.constructor.options.eventRender.type, this.constructor.options.eventRender)
Object.assign(eventRender.detail,
{
name: this.model.view,

@@ -69,5 +72,8 @@ view: this

{
_target.innerHTML = this.html
_target.dispatchEvent(this.constructor.options.eventRender)
this.renderSubviews(_target)
let canceled = !_target.dispatchEvent(eventRender)
if (!canceled)
{
_target.innerHTML = eventRender.detail.view.html
this.renderSubviews(_target)
}
})

@@ -143,5 +149,5 @@

autoCache: true, // Automatically cache views when created
eventRender: new CustomEvent('view.render', { bubbles: true, detail: { type: 'render', name: null, view: null } })
eventRender: new CustomEvent('view.render', { bubbles: true, cancelable: true, detail: { type: 'render', name: null, view: null } })
}
export { View }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc