@logimaxx/kviews.js 1.2.4 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -2
- package/README.md +2 -2
- package/dist/index.js +242 -32
- package/dist/index.js.map +2 -2
- package/dist/kviews.js +244 -34
- package/dist/kviews.js.map +2 -2
- package/dist/kviews.min.js +6 -6
- package/package.json +5 -4
package/dist/kviews.min.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* KViews - Class-based API data binding library
|
|
3
|
-
* Version: 1.
|
|
4
|
-
* Built: 2026-06-
|
|
3
|
+
* Version: 1.3.1
|
|
4
|
+
* Built: 2026-06-29T17:09:29.460Z
|
|
5
5
|
*/
|
|
6
6
|
/*!
|
|
7
7
|
* KViews - Class-based API data binding library
|
|
8
|
-
* Version: 1.
|
|
9
|
-
* Built: 2026-06-
|
|
10
|
-
*/var KViews=(()=>{var
|
|
11
|
-
`)},getResponseHeader:h=>s.headers.get(h)},a=await s.text();let o=a;try{o=JSON.parse(a)}catch{}if(l.responseText=a,l.responseJSON=typeof o=="object"?o:null,!s.ok){const h=new C(`HTTP ${s.status}: ${s.statusText}`,{status:s.status,statusText:s.statusText,responseText:a,responseJSON:typeof o=="object"?o:null,jqXHR:l,options:t,errorThrown:new Error(`HTTP ${s.status}: ${s.statusText}`)});throw h.textStatus="error",h}return{data:o,textStatus:"success",jqXHR:l}}).catch(s=>{if(s instanceof C||s instanceof D)throw s;const l={status:0,statusText:"error",responseText:null,responseJSON:null,getAllResponseHeaders:()=>"",getResponseHeader:()=>null},a=new C(s instanceof Error?s.message:String(s),{status:0,statusText:"error",responseText:null,responseJSON:null,jqXHR:l,options:t,errorThrown:s instanceof Error?s:new Error(String(s))});throw a.textStatus="error",a})}create(t,e,i,r){let n={context:t,url:e,method:"POST",data:r};return Object.assign(n,i),this.sync(n)}read(t,e,i){let r={context:t,url:e,method:"GET"};return Object.assign(r,i),this.sync(r)}delete(t,e,i){let r={context:t,url:e,method:"DELETE"};return Object.assign(r,i),this.sync(r)}update(t,e,i,r){let n={context:t,url:e,method:"PATCH",contentType:"application/vnd.api+json",data:r};return Object.assign(n,i),this.sync(n)}};function mt(t){if(!t||typeof t!="object")return[];const e=t.hasOwnProperty("included")?t.included:t.hasOwnProperty("includes")?t.includes:null;return e?Array.isArray(e)?e:[]:[]}function bt(t){const e=new Map;if(!t||typeof t!="object")return e;function i(n){if(!n||typeof n!="object"||!n.type||!n.id)return;const s=`${n.type}/${n.id}`;e.has(s)||e.set(s,n)}return t.data&&(Array.isArray(t.data)?t.data.forEach(i):typeof t.data=="object"&&i(t.data)),mt(t).forEach(i),e}function W(t,e,i){let r,n;if(typeof t=="object"&&t!==null?(r=t.type,n=t.id):(r=t,n=e),!r||!n)return null;const s=`${r}/${n}`;return i.get(s)||null}function I(t,e,i=new Set){if(!t||typeof t!="object"||!t.relationships)return t;const r=t.type&&t.id?`${t.type}/${t.id}`:null;return r&&i.has(r)||(r&&i.add(r),Object.keys(t.relationships).forEach(n=>{const s=t.relationships[n];if(s!==null)if(s.data!==void 0)if(s.data===null)t.relationships[n]=null;else if(Array.isArray(s.data))t.relationships[n]=s.data.map(l=>{const a=W(l,null,e);return a?I(a,e,new Set(i)):l}).filter(l=>l!==null);else if(typeof s.data=="object"&&s.data.type&&s.data.id){const l=W(s.data,null,e);l?t.relationships[n]=I(l,e,new Set(i)):t.relationships[n]=s.data}else t.relationships[n]=s.data;else t.relationships[n]=s})),t}function X(t){if(!t||typeof t!="object")throw new B("Invalid document: must be an object");const e=bt(t);if(!t.data)return null;const i=t.data;return Array.isArray(i)?(i.forEach(r=>I(r,e)),i):typeof i=="object"?I(i,e):i}function wt(t,e={}){let i,r=t;if(t&&typeof t=="object"&&t.type&&t.id&&!t.data?i=t:t&&t.data?(r=t,i=X(r)):i=t,!i||typeof i!="object")throw new B("Invalid item data: must be an object");return r&&r.links&&r.links.self&&!i.url&&(i.url=c(r.links.self)),i}function Ot(t){if(!t||typeof t!="object")return[];const e=X(t);return e?Array.isArray(e)?e:[e]:[]}function _(t){if(t===null)return null;if(typeof t!="object")throw new Error("Invalid item data: "+t);if(t.constructor===Array||t.hasOwnProperty("items")&&t.hasOwnProperty("length")){let i=[];return t.forEach(function(r){i.push(_(r))}),i}if(t.constructor!==Object)throw new Error("Invalid case");let e={};if(!t.hasOwnProperty("attributes")){let i={attributes:{}};t.hasOwnProperty("type")&&(i.type=t.type),Object.assign(i.attributes,t),t=i}return Object.getOwnPropertyNames(t.attributes).forEach(function(i){if(t.attributes[i]&&typeof t.attributes[i]=="object"){e.relationships||(e.relationships={}),e.relationships[i]={data:_(t.attributes[i])};return}e.attributes||(e.attributes={}),e.attributes[i]=t.attributes[i]}),e}var Q=class{name="jsonapi";isSingleItemResponse(t){return!!(t&&t.data&&typeof t.data=="object"&&!Array.isArray(t.data))}extractMetadata(t){const e={};return!t||!t.hasOwnProperty("meta")||typeof t.meta!="object"||(t.meta.hasOwnProperty("totalRecords")&&(e.totalRecords=t.meta.totalRecords*1),t.meta.hasOwnProperty("offset")&&(e.offset=t.meta.offset)),e}applyMetadata(t,e){e.totalRecords!==void 0&&(t.total=e.totalRecords),e.offset!==void 0&&(t.offset=e.offset)}parseItemResponse(t,e={}){return this.validateItemRemoteDoc(t,e),wt(t,e)}validateItemRemoteDoc(t){if(t?.data?.constructor===Array)throw new Error("Invalid configuration: resource type is item but server response is collection")}inferItemType(t){return t?.data?.type}parseCollectionResponse(t){const e=Ot(t),i=this.extractMetadata(t);return{items:e,meta:i}}applyListQuery(t,e){const{type:i,offset:r,pageSize:n}=e;typeof r<"u"&&r!==null&&i&&(t.parameters[`page[${i}][offset]`]=r),typeof n<"u"&&n!==null&&i&&(t.parameters[`page[${i}][limit]`]=n)}serializeForCreate(t,e={}){const i={data:_(t)};return e.type&&(i.type=e.type),{body:JSON.stringify(i),contentType:"application/vnd.api+json"}}serializeForUpdate(t){return{body:JSON.stringify({data:t}),contentType:"application/vnd.api+json"}}serializeRelationship(t){if(t===null)return{data:null};if(t&&typeof t=="object"&&!Array.isArray(t)){if(t.id){const e={data:{id:t.id}};return t.type&&(e.data.type=t.type),e}if(t.hasOwnProperty("toJSON")){const e=t.toJSON(),i={data:{id:e.id}};return e.type&&(i.data.type=e.type),i}return{data:null}}return Array.isArray(t)?{data:t.map(e=>{if(e&&typeof e=="object"){if(e.type&&e.id){const i={id:e.id};return e.type&&(i.type=e.type),i}if(e.hasOwnProperty("toJSON")){const i=e.toJSON(),r={id:i.id};return i.type&&(r.type=i.type),r}}return e}).filter(e=>e&&e.id)}:{data:null}}};function v(t,e){if(!(!t||!e||typeof e!="string"))return e.split(".").reduce((i,r)=>{if(!(i==null||typeof i!="object"))return i[r]},t)}function G(t,e){if(Array.isArray(t))return t;if(!t||typeof t!="object")return[];if(e){const i=v(t,e);return Array.isArray(i)?i:[]}return Array.isArray(t.data)?t.data:Array.isArray(t.items)?t.items:Array.isArray(t.results)?t.results:[]}function vt(t,e){if(!(!t||typeof t!="object")){if(e){const i=v(t,e);return i!=null?i*1:void 0}for(const i of["total","count","totalCount","meta.totalRecords"]){const r=v(t,i);if(r!=null)return r*1}}}function St(t,e){if(!(!t||typeof t!="object")){if(e){const i=v(t,e);return i??void 0}for(const i of["offset","meta.offset"]){const r=v(t,i);if(r!=null)return r}}}var Y=class{name="plain";constructor(t={}){this.itemsPath=t.itemsPath??null,this.itemPath=t.itemPath??null,this.totalPath=t.totalPath??null,this.offsetPath=t.offsetPath??null,this.idField=t.idField??"id",this.typeField=t.typeField??"type",this.paginationStyle=t.paginationStyle??"offset",this.offsetParam=t.offsetParam??"offset",this.limitParam=t.limitParam??"limit",this.pageParam=t.pageParam??"page",this.embedRelationships=t.embedRelationships??!1}isSingleItemResponse(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;if(this.itemPath){const i=v(t,this.itemPath);return Array.isArray(i)?!1:i&&typeof i=="object"?i[this.idField]!=null:!1}return G(t,this.itemsPath).length>0||t.data&&Array.isArray(t.data)?!1:t.data&&typeof t.data=="object"&&t.data[this.idField]!=null?!0:t[this.idField]!=null}extractMetadata(t){const e={},i=vt(t,this.totalPath);i!==void 0&&(e.totalRecords=i);const r=St(t,this.offsetPath);return r!==void 0&&(e.offset=r),e}applyMetadata(t,e){e.totalRecords!==void 0&&(t.total=e.totalRecords),e.offset!==void 0&&(t.offset=e.offset)}parseItemResponse(t,e={}){this.validateItemRemoteDoc(t,e);const i=this.extractRawItem(t),r=e.collection?.type??e.type;return this.normalize(i,r)}validateItemRemoteDoc(t){if(Array.isArray(t))throw new Error("Invalid configuration: resource type is item but server response is collection");if(this.itemPath){const e=v(t,this.itemPath);if(Array.isArray(e))throw new Error("Invalid configuration: resource type is item but server response is collection");return}if(t?.data&&Array.isArray(t.data))throw new Error("Invalid configuration: resource type is item but server response is collection")}inferItemType(t){const e=this.extractRawItem(t);if(!(!e||typeof e!="object"))return e[this.typeField]}parseCollectionResponse(t,e={}){const i=G(t,this.itemsPath),r=e.type,n=i.map(l=>this.normalize(l,r)),s=this.extractMetadata(t);return{items:n,meta:s}}applyListQuery(t,e){const{offset:i,pageSize:r}=e;if(!(typeof r>"u"||r===null)){if(this.paginationStyle==="page"){const s=Math.floor((typeof i>"u"||i===null?0:i)/r)+1;t.parameters[this.pageParam]=s,t.parameters[this.limitParam]=r;return}typeof i<"u"&&i!==null&&(t.parameters[this.offsetParam]=i),t.parameters[this.limitParam]=r}}serializeForCreate(t,e={}){const i=e.type;let r;return Array.isArray(t)?r=t.map(n=>this.flattenForWire(this.coerceToCanonical(n,i))):r=this.flattenForWire(this.coerceToCanonical(t,i)),{body:JSON.stringify(r),contentType:"application/json"}}serializeForUpdate(t){const e={};Object.entries(t.relationships||{}).forEach(([r,n])=>{e[r]=this.unwrapRelationship(n)});const i=this.flattenForWire({id:t.id,type:t.type,attributes:t.attributes,relationships:e});return{body:JSON.stringify(i),contentType:"application/json"}}serializeRelationship(t){return this.unwrapRelationship(t)}extractRawItem(t){return this.itemPath?v(t,this.itemPath):t?.data&&typeof t.data=="object"&&!Array.isArray(t.data)?t.data:t}normalize(t,e){if(!t||typeof t!="object"||Array.isArray(t))throw new Error("Invalid item data: must be an object");if(t.attributes&&typeof t.attributes=="object"){const a={};Object.entries(t.relationships||{}).forEach(([h,p])=>{p===null?a[h]=null:Array.isArray(p)?a[h]=p.map(d=>this.normalize(d,e)):a[h]=this.normalize(p,e)});const o={attributes:{...t.attributes},relationships:a};return t.id!=null&&(o.id=String(t.id)),(t.type??e)&&(o.type=t.type??e),o}const i={},r={};let n,s;Object.entries(t).forEach(([a,o])=>{if(a===this.idField){n=o;return}if(a===this.typeField){s=o;return}if(o==null){i[a]=o;return}if(Array.isArray(o)){o.length>0&&o.every(h=>this.isNestedResource(h))?r[a]=o.map(h=>this.normalize(h,e)):i[a]=o;return}if(this.isNestedResource(o)){r[a]=this.normalize(o,e);return}i[a]=o});const l={attributes:i,relationships:r};return n!=null&&(l.id=String(n)),(s??e)&&(l.type=s??e),l}isNestedResource(t){return t&&typeof t=="object"&&!Array.isArray(t)&&t[this.idField]!=null}coerceToCanonical(t,e){return!t||typeof t!="object"||t.attributes||t.relationships?t:this.normalize(t,e)}flattenForWire(t){if(!t||typeof t!="object")return t;const e={...t.attributes||{}};return t.id!=null&&(e[this.idField]=t.id),t.type!=null&&this.typeField&&(e[this.typeField]=t.type),Object.entries(t.relationships||{}).forEach(([i,r])=>{if(r===null){e[i]=null;return}if(Array.isArray(r)){e[i]=r.map(n=>this.relationshipToWire(n));return}e[i]=this.relationshipToWire(r)}),e}relationshipToWire(t){if(!t)return null;if(this.embedRelationships&&t.attributes)return this.flattenForWire(t);const e={[this.idField]:t.id??t[this.idField]};return(t.type??t[this.typeField])!=null&&(e[this.typeField]=t.type??t[this.typeField]),e}unwrapRelationship(t){return t==null?null:t.data!==void 0?t.data===null?null:Array.isArray(t.data)?t.data.map(e=>({...e})):{...t.data}:Array.isArray(t)?t.map(e=>this.unwrapRelationship(e)):typeof t=="object"?t.attributes?t:{...t}:t}},Z=new Map([["jsonapi",new Q],["plain",new Y]]),H="jsonapi";function N(t,e){if(!t||typeof t!="string")throw new Error("Adapter name must be a non-empty string");Z.set(t,e)}function tt(t){H=t}function et(){return H}function x(t){if(t&&typeof t=="object")return t;const e=typeof t=="string"?t:H;if(typeof e=="object")return e;const i=Z.get(e);if(!i)throw new Error(`Unknown data adapter: ${e}`);return i}var P=class{constructor(t){if(t&&t.isView)return t;if(this.type="ItemView",this.dataBindings=null,this.template=null,this.container=null,this.collectionView=null,this.item=null,this.el=null,this.id=q(),this.isView=!0,this.callbacks={},t&&(t.length||t.nodeName&&!t.jquery)){f("params is actually a jquery object or an html node",t);let e=$(t);if(e.data("view"))return e.data("view");let i=$("<div>").append(e.clone(!0)),r=i.html().replace(/<%/gi,"<%").replace(/</gi,"<").replace(/%>/gi,"%>").replace(/>/gi,">").replace(/&/gi,"&");t={template:E(r),el:e},e.attr("id")&&(t.id=e.attr("id")),i.remove()}try{t=w(t)}catch(e){throw new Error("Error on ItemView",this,e)}Object.assign(this,t),this.el!==null&&(this.dataBindings=k(this.el))}on(t,e){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(e),this}unbind(){this.item&&this.item.unbindView(this)}createElementFromTemplate(){if(this.template==null)return f("Warning: no template defined. Nothing to render"),null;if(!this.item)return f("Warning: no item bound to view. Cannot render template."),null;let t;try{const e=this.item.getRenderContext();console.log("renderContext",e);let i=this.template(e);t=$(i).attr("data-type","item").attr("id",this.id).data("view",this).data("instance",this.item)}catch(e){console.log("Error create view from template",e,this.item),t=$("<div>Could not render view: <strong>"+e.toString()+"</strong></div>")}return t}afterrender(){this.callbacks.afterrender&&(console.log("afterend of view",this),this.callbacks.afterrender.forEach(t=>t(this)))}render(t=!1,e=!1){u("ItemView.render called",this.item,this.el);let i=this.createElementFromTemplate();if(!i)return null;if(u("View item",this.item),this.item&&this.item.uievents&&(u("UI events",this.item.uievents),this.item.uievents.forEach(r=>{if(u("UI event",r,i),r.selector&&r.event&&r.callback){const n=$(i).find(r.selector);u("UI event els",r,i,n),n.on(r.event,s=>{s.preventDefault(),u("UIevent triggered",s,this.item,this),r.callback(s,this.item,this)})}})),t)return this.el=i,this.el;if(this.el){let r=this.el;return r.jquery||(r=$(r)),r.off(),this.el=$(i).insertBefore(r),r.remove(),this.afterrender(),this}return this.el=i,this.afterrender(),this.container?($(this.el).appendTo(this.container.el),this):this}renderEmpty(t){if(this.item&&this.item.emptyview&&this.el){let e=$(this.item.emptyview).clone(!0).css("display","block");$(this.el).replaceWith(e)}}remove(t){return new Promise(e=>{if(this.item&&this.item.collection&&this.item.collection._trigger("afterrender",this.item.collection),this.el){let i=this.el.jquery?this.el:$(this.el);i.fadeOut({complete:()=>{i.remove(),e()}})}else e()})}destroy(){if(this.el){const t=this.el.jquery?this.el:$(this.el);t.off(),t.removeData()}return this.callbacks={},this.item&&this.item.unbindView(this),this.item=null,this.container=null,this.collectionView=null,this.el=null,this.template=null,this.dataBindings=null,this}},V=class A{constructor(e={},i=null){this.id=null,this.type=null,this.attributes={},this.relationships={},this.views=[],this.collection=null,this.url=null,this.updateUrl=null,this.deleteUrl=null,this.strict=!1,this.shadow=null,this.syncOp=null,this.emptyview=null,this.uievents=[],this.callbacks={},this.adapter=null;try{Object.assign(this,w(e))}catch(n){throw new Error("Error on Item init",n)}this.adapter=x(e.adapter??(e.collection&&e.collection.adapter)),this.storage=e.storage||new L((()=>{const n=Object.assign({},e.ajaxOpts||{});return e.headers&&typeof e.headers=="object"&&(n.headers=Object.assign({},n.headers||{},e.headers)),n})());let r=!1;if(i){u("Loading data",i);try{this.loadFromData(i),r=!0}catch(n){console.error("Error loading data",n)}}this.url&&this.setUrl(this.url),this.deleteUrl&&(u("deleteUrl",this.deleteUrl),this.setUrl(this.deleteUrl,"delete")),this.updateUrl&&this.setUrl(this.updateUrl,"update"),this.insertUrl&&this.setUrl(this.insertUrl,"insert"),this.views.forEach(n=>{n.item=this}),e.itemListeners&&typeof e.itemListeners=="object"&&Object.getOwnPropertyNames(e.itemListeners).forEach(n=>{u("apply item listener",n,e.itemListeners[n]),this.on(n,e.itemListeners[n])}),r&&(u("Rendering data",i),this.render())}on(e,i){return typeof this.callbacks[e]>"u"&&(this.callbacks[e]=[]),this.callbacks[e].push(i),this}off(e,i){if(!e)return this.callbacks={},this;if(!this.callbacks[e])return this;if(i){const r=this.callbacks[e].indexOf(i);r>-1&&this.callbacks[e].splice(r,1),this.callbacks[e].length===0&&delete this.callbacks[e]}else delete this.callbacks[e];return this}once(e,i){const r=(...n)=>{i(...n),this.off(e,r)};return this.on(e,r)}hasListeners(e){return this.callbacks[e]&&Array.isArray(this.callbacks[e])&&this.callbacks[e].length>0}_trigger(e,...i){this.callbacks[e]&&Array.isArray(this.callbacks[e])&&this.callbacks[e].forEach(r=>{typeof r=="function"&&r(...i)})}emit(e,...i){return this._trigger(e,...i),this}setUrl(e,i){switch(i){case"delete":this.deleteUrl=c(e);break;case"update":this.updateUrl=c(e);break;case"insert":this.insertUrl=c(e);break;default:this.url=c(e),this.deleteUrl=typeof this.deleteUrl=="string"?c(this.deleteUrl):this.deleteUrl??c(this.url),this.updateUrl=typeof this.updateUrl=="string"?c(this.updateUrl):this.updateUrl??c(this.url);break}return this}loadFromRemote(){return this.loadFromDataSource()}load(e){return e?this.loadFromData(e):this.loadFromRemote()}loadFromDataSource(){let e=[];const i=z(this);return this.views.forEach(r=>{if(r.el){let n=$(r.el),s=i.clone();s.insertBefore(r.el).width(n.width()).height(n.height()),e.push(s)}}),new Promise((r,n)=>{if(!this.url){n(new Error("No valid URL provided"));return}this._trigger("beforeload",this);let s=this.url.toString?this.url.toString():this.url;this.storage.read(this,s,{}).then(l=>{let a=l.data;this.loadFromRemoteDoc(a).render(),this._trigger("load",this),e.forEach(o=>{o.remove()}),r(this)}).catch(l=>{f("fail to load item resource",this.url,l),l instanceof Error&&l.jqXHR?(this.fail(l.jqXHR,l.textStatus||"error",l.errorThrown||l),n(l)):l&&l.jqXHR?(this.fail(l.jqXHR,l.textStatus,l.errorThrown),n(l)):(this.fail(null,"error",l),n(l))})})}refresh(){return this.loadFromRemote()}reload(){return this.loadFromRemote()}load_from_data_source(){return this.loadFromDataSource()}unbindView(e){let i=!1;for(let r=0;r<this.views.length;r++)this.views[r]===e&&(i=r);i!==!1&&this.views.splice(i,1)}bindView(e,i){if($(e).length===0)throw new Error("Nothing to bind to: empty view element");e instanceof P||(e=new P(e));let n=!1;return this.views.forEach(s=>{f("bind to existing view",s.el),s===e&&(n=!0)}),n?i?e:this:(e.item=this,this.views.push(e),i?e:this)}loadFromRemoteDoc(e){if(f("Load from remote doc",e),this.collection&&!this.collection.type){const r=this.adapter.inferItemType(e);r&&(this.type=r)}this.adapter.validateItemRemoteDoc(e,{collection:this.collection});const i=this.adapter.parseItemResponse(e,{collection:this.collection});return Object.assign(this,i),this.url&&(this.url=c(this.url)),this}loadFromJSONAPIDoc(e){return this.loadFromRemoteDoc(e)}loadFromData(e,i=!1){if(e===null||typeof e!="object"||e.constructor!==Object)throw f("cannot load ",e," into ",this),new Error("Cannot load data into item");if(!e.hasOwnProperty("attributes")&&!e.hasOwnProperty("id")&&!e.hasOwnProperty("type")){f("need to normalize data",e);let r={},n={};Object.getOwnPropertyNames(e).forEach(s=>{if(e[s]&&e[s].constructor===Object){n[s]=new A().loadFromData(e[s]);return}if(e[s]&&e[s].constructor===Array){n[s]=e[s];return}r[s]=e[s]}),e={attributes:r},Object.getOwnPropertyNames(n).length&&(e.relationships=n)}return Object.assign(this,e),this._trigger("load",this),i&&this.render(),this}fail(e,i,r){f("item.fail",e,i,r),this.views.forEach(n=>{e&&e.status===404&&n.renderEmpty()})}getRenderContext(){function e(s,l=new WeakMap){if(s===null||typeof s!="object")return s;if(l.has(s))return l.get(s);if(Array.isArray(s)){const o=[];return l.set(s,o),s.forEach(h=>o.push(e(h,l))),o}const a={};return l.set(s,a),Object.keys(s).forEach(o=>{a[o]=e(s[o],l)}),a}function i(s){return s instanceof A||s.attributes!=null&&typeof s.attributes=="object"}function r(s){return!s||typeof s!="object"||Array.isArray(s)||i(s)||s.id==null?!1:Object.keys(s).every(l=>l==="id"||l==="type")}function n(s,l=new WeakMap){if(!s)return null;if(typeof s!="object")return s;if(l.has(s))return l.get(s);if(r(s)){const o={id:s.id};return l.set(s,o),o}if(!i(s)){if(s.id!=null){const h={id:s.id};return Object.keys(s).forEach(p=>{p==="id"||p==="type"||p==="relationships"||p==="attributes"||(h[p]=e(s[p]))}),l.set(s,h),h}const o=e(s);return l.set(s,o),o}const a={id:s.id};return l.set(s,a),Object.assign(a,e(s.attributes??{})),Object.keys(s.relationships??{}).forEach(o=>{Array.isArray(s.relationships[o])?a[o]=s.relationships[o].map(h=>n(h,l)):a[o]=n(s.relationships[o],l)}),a}return n(this)}toJSON(){let e={type:this.type,attributes:this.attributes||{}};if(this.id&&(e.id=this.id),this.relationships&&Object.keys(this.relationships).length>0){e.relationships={};for(let i in this.relationships){if(!this.relationships.hasOwnProperty(i))continue;const r=this.relationships[i];if(r===null){e.relationships[i]={data:null};continue}if(r&&typeof r=="object"&&!Array.isArray(r)){if(r.type&&r.id)e.relationships[i]={data:{type:r.type,id:r.id}};else if(r.hasOwnProperty("toJSON"))e.relationships[i]={data:r.toJSON()};else continue;continue}if(Array.isArray(r)){e.relationships[i]={data:r.map(n=>{if(n&&typeof n=="object"){if(n.type&&n.id)return{type:n.type,id:n.id};if(n.hasOwnProperty("toJSON"))return n.toJSON()}return n})};continue}}}return f("item.json",e),e}_serializeRelationshipToWireFormat(e){return this.adapter.serializeRelationship(e)}sync(){if(this.syncOp){let e=this.syncOp;return f("Syncing",this,e),this.syncOp=null,e()}else f("Nothing to sync on",this)}perform_update(e){let i={rerender:!0};return Object.assign(i,e),new Promise((r,n)=>{let s={id:this.id,attributes:{},relationships:{}};if(this.type&&(s.type=this.type),Object.getOwnPropertyNames(this.attributes).forEach(o=>{this.shadow&&this.shadow.attributes[o]!==this.attributes[o]&&(s.attributes[o]=this.attributes[o])}),Object.getOwnPropertyNames(this.relationships).forEach(o=>{if(this.shadow&&this.shadow.relationships[o]!==this.relationships[o]){const h=this.relationships[o];s.relationships[o]=this._serializeRelationshipToWireFormat(h)}}),!Object.getOwnPropertyNames(s.attributes).length&&!Object.getOwnPropertyNames(s.relationships).length){this.syncOp=null,r(this);return}const l=this.adapter.serializeForUpdate(s);if(e&&e.justSimulate){f(l.body),r(this);return}let a=this.updateUrl.toString?this.updateUrl.toString():this.updateUrl;this.storage.update(this,a,{contentType:l.contentType},l.body).then(o=>{let h=this.adapter.parseItemResponse(o.data);Object.assign(this,h),this.shadow=null,i.rerender&&this.views.forEach(p=>{p.render(),this._trigger("afterrender",this,p)}),this._trigger("update",this),this.collection&&this.collection.onupdate(),r(this)}).catch(o=>{f("Update NOK",this.updateUrl,l.body,o),o instanceof Error&&o.jqXHR||o.jqXHR?n(o):n(o instanceof Error?o:new Error(String(o)))})})}update(e,i){if(!e||e.constructor!==Object)return;let r={sync:!0,rerender:!0};i&&i.constructor===Object&&Object.assign(r,i),this.shadow||(this.shadow={attributes:{},relationships:{}},Object.assign(this.shadow.attributes,this.attributes),Object.assign(this.shadow.relationships,this.relationships));const n=(s,l)=>{if(f("update relation",s,l),l===null)return null;if(s&&Array.isArray(s))return Array.isArray(l)?l.map(a=>typeof a=="object"&&a!==null?new A().loadFromData(a):a):(f("to fix: array relationship update"),s);if(typeof l=="object"||l===null){f("Update 1:1 relation");let a=new A().loadFromData(l);return f("relation",a),a}if(typeof l=="string"||typeof l=="number"){if(f("Update 1:1 relation with id",l),s&&s.id&&(s.id===l||String(s.id)===String(l)))return s;const a={id:String(l)};return s&&s.type&&(a.type=s.type),a}return s};return Object.getOwnPropertyNames(this.relationships).forEach(s=>{if(e.hasOwnProperty(s)){if(e[s]===null){this.relationships[s]=null;return}this.relationships[s]=n(this.relationships[s],e[s]),delete e[s]}}),Object.getOwnPropertyNames(e).forEach(s=>{if(e[s]&&typeof e[s]=="object"){!this.strict&&typeof this.relationships[s]>"u"&&(this.relationships[s]=n(this.relationships[s],e[s]));return}if(!this.shadow.attributes.hasOwnProperty(s)){this.strict||(this.attributes[s]=e[s]);return}e[s]!==this.shadow.attributes[s]&&(this.attributes[s]=e[s])}),f("updateOptions",r),r.sync?this.perform_update(r):new Promise(s=>{this.syncOp=()=>this.perform_update(r),this.views.forEach(l=>{r.rerender&&l.render()}),s()})}remove(){return new Promise((e,i)=>{let r=[];for(let s=this.views.length-1;s>=0;s--)r.push(this.views[s].remove());let n=this.collection;n&&r.push(n.removeItem(this)),Promise.all(r).then(()=>{this._trigger("remove",this),n&&(console.log("removed"),n.onupdate())}).finally(()=>e())})}async delete(e){if(!this.deleteUrl)return this.remove();let i={sync:!0};e&&e.constructor===Object&&Object.assign(i,e);try{u("delete",this.deleteUrl.toString()),await this.storage.delete(this,this.deleteUrl.toString(),{}),await this.remove()}catch(r){throw f("Error deleting item",r),r}}render(e,i=!1){return f("Render from item",this),this.views.forEach(r=>{typeof e>"u"?(f("collectionView is undefined so render view"),r.render()):r.container===e&&(f("collectionView matches view container so render view"),r.render(!1,i)),f("trigger afterrender",this,r,r.el),this._trigger("afterrender",this,r)}),this}destroy(){return(this.views?[...this.views]:[]).forEach(i=>{i&&typeof i.destroy=="function"&&i.destroy()}),this.views=[],this.callbacks={},this.collection&&(this.collection=null),this.storage=null,this.url=null,this.updateUrl=null,this.deleteUrl=null,this.attributes={},this.relationships={},this.shadow=null,this.views=[],this}},it=class{constructor(t={}){this.el=null,this.type="CollectionView",this.container=null,this.collection=null,this.itemsContainer=null,this.allowempty=!0;try{Object.assign(this,w(t))}catch(e){throw new Error("Error on CollectionView init",e)}this.dataBindings=k(this.el)}reset(t){return(this.allowempty||t)&&this.el&&$(this.el).empty(),this}render(){return f("Render _collectionView",this.collection),this.collection&&this.collection.navtype==="page"&&this.reset(),this.collection&&this.collection.items.length===0?(this.renderEmpty(),this):(this.collection&&this.collection.items.forEach(t=>{t.render(this)}),this)}renderEmpty(){return!this.collection||!this.collection.emptyview?this:(this.reset(),$(this.el).append(this.collection.emptyview),this)}destroy(){if(this.el){const t=$(this.el);t.empty(),t.removeData()}return this.collection=null,this.el=null,this.container=null,this.itemsContainer=null,this.dataBindings=null,this}},rt=class{constructor(t,e){this.collection=e,this.el=$(t),this.collection.paging=this,this.iniOffset=(this.collection.offset?this.collection.offset:0)*1,this.defaultPageSize=20,this.pageSize=this.collection.pageSize,this.setupPageSizeInput(),this.setupOffsetInput(),this.buttons=this.extractButtons(),u("buttons",this.buttons),this.setupTotalCount(),this.render()}setupPageSizeInput(){let t=$(this.collection.pagesizeinp);t.length&&(this.collection.setPageSize(t.val()),t.off("change").on("change",()=>{this.collection.setPageSize(t.val())&&this.collection.loadFromRemote()}))}setupOffsetInput(){let t=$(this.collection.offsetinp);t.length&&(this.collection.setOffset(t.val()),t.off("change").on("change",()=>{this.collection.setOffset(t.val())&&this.collection.loadFromRemote()}))}extractButtons(){let t={};const e=$(this.el).find("[name=page]");e.length&&(t.page=e.clone(),e.remove());const i=$(this.el).find("[name=prev]");i.length&&(t.prev=i.clone(),i.remove());const r=$(this.el).find("[name=next]");r.length&&(t.next=r.clone(),r.remove());const n=$(this.el).find("[name=first]");n.length&&(t.first=n.clone(),n.remove());const s=$(this.el).find("[name=last]");return s.length&&(t.last=s.clone(),s.remove()),t}setupTotalCount(){this.$totalCount=$(this.collection.totalrecscount)}clearContainer(){$(this.el).empty(),$(this.el).find("[data-type=pages]").empty()}updateTotalCount(t){this.$totalCount&&this.$totalCount.length&&(this.$totalCount[0].tagName==="INPUT"?this.$totalCount.val(t):this.$totalCount.text(t))}appendButton(t,e,i){let r=t.clone();return i!==void 0&&r.attr("title",i),r.on("click",e),$(this.el).append(r),r}render(){const e=this.collection.total;if(u("Paging render",e,this.buttons),this.updateTotalCount(e),this.clearContainer(),this.iniOffset=this.collection.offset*1,this.collection.pageSize?this.pageSize=this.collection.pageSize:e-this.iniOffset-this.collection.items.length>0?this.pageSize=this.collection.items.length:this.pageSize=this.defaultPageSize,this.pageSize=this.pageSize*1,u("Paging obj",this,this.pageSize,e),this.pageSize>e)return;this.iniOffset>0&&(this.buttons.first&&this.appendButton(this.buttons.first,()=>{this.collection.setOffset(0),this.collection.loadFromRemote()},0),this.buttons.prev&&this.appendButton(this.buttons.prev,()=>{this.collection.setOffset(this.iniOffset-this.pageSize),this.collection.loadFromRemote()},this.iniOffset-this.pageSize));let i=Math.floor(this.iniOffset/this.pageSize)-Math.floor(5/2);i=i<0?0:i;let r=Math.floor(this.iniOffset/this.pageSize)+Math.ceil(5/2);r=r*this.pageSize<e?r:Math.ceil(e/this.pageSize);for(let l=i;l<r;l++){if(!this.buttons.page)continue;const a=l*this.pageSize,o=Math.floor(this.iniOffset/this.pageSize)===l;let h=this.buttons.page.clone();h.text(l+1).attr("title",a).on("click",()=>{this.collection.setOffset(a),this.collection.loadFromRemote()}),o&&h.addClass("active").off("click"),$(this.el).append(h)}const n=this.iniOffset+this.pageSize;if(this.iniOffset+this.pageSize<e&&(this.buttons.next&&this.appendButton(this.buttons.next,()=>{this.collection.setOffset(n),this.collection.loadFromRemote()},n),this.buttons.last)){const l=(Math.ceil(e/this.pageSize)-1)*this.pageSize;u("last button",e,l,this.pageSize,this.offset),l>this.iniOffset*1&&this.appendButton(this.buttons.last,()=>{this.collection.setOffset(l),this.collection.loadFromRemote()},l)}let s=$(this.collection.offsetinp);s.length&&s.val(this.iniOffset)}destroy(){if(this.collection&&this.collection.pagesizeinp&&$(this.collection.pagesizeinp).off("change"),this.collection&&this.collection.offsetinp&&$(this.collection.offsetinp).off("change"),this.el){const t=$(this.el);t.empty(),t.off(),t.removeData()}return this.collection=null,this.el=null,this.buttons=null,this.$totalCount=null,this}},st=class{constructor(t={}){this.url=null,this.deleteUrl=null,this.insertUrl=null,this.updateUrl=null,this.paging=null,this.view=null,this.offset=0,this.total=null,this.pageSize=10,this.template=null,this.navtype="page",this.type=null,this.emptyview=null,this.items=[],this.addontop=!1,this.uievents=[],this.setAttrAsId=null,this.itemListeners=null,this.adapter=null,this.callbacks={},this.iterator=-1,M("Collection init",t);try{t=w(t)}catch(i){throw new Error("Error on Collection init",i)}Object.defineProperty(this,"length",{get(){return this.items.length},enumerable:!0,configurable:!0});let e=Object.assign({},t);if(Object.assign(this,e),e.hasOwnProperty("paging")&&$(e.paging).length&&(this.paging=new rt($(e.paging)[0],this)),this.url&&this.setUrl(this.url),this.deleteUrl&&this.setUrl(this.deleteUrl,"delete"),this.updateUrl&&this.setUrl(this.updateUrl,"update"),this.insertUrl&&this.setUrl(this.insertUrl,"insert"),this.view&&(this.view.collection=this),this.total&&(this.total=this.total*1),["page","scroll"].indexOf(this.navtype)===-1)throw new Error("Invalid navigations type. Should be page or scroll");if(this.adapter=x(t.adapter),this.storage=t.hasOwnProperty("storage")?t.storage:new L((()=>{const i=Object.assign({},t.ajaxOpts||{});return t.headers&&typeof t.headers=="object"&&(i.headers=Object.assign({},i.headers||{},t.headers)),i})()),typeof t.listeners=="object")for(let i in t.listeners)this.on(i,t.listeners[i]);t.itemListeners&&typeof t.itemListeners=="object"?this.itemListeners=t.itemListeners:t.itemOn&&typeof t.itemOn=="object"&&(this.itemListeners=t.itemOn)}on(t,e){return typeof this.callbacks[t]>"u"&&(this.callbacks[t]=[]),this.callbacks[t].push(e),this}off(t,e){if(!t)return this.callbacks={},this;if(!this.callbacks[t])return this;if(e){const i=this.callbacks[t].indexOf(e);i>-1&&this.callbacks[t].splice(i,1),this.callbacks[t].length===0&&delete this.callbacks[t]}else delete this.callbacks[t];return this}once(t,e){const i=(...r)=>{e(...r),this.off(t,i)};return this.on(t,i)}hasListeners(t){return this.callbacks[t]&&Array.isArray(this.callbacks[t])&&this.callbacks[t].length>0}_trigger(t,...e){this.callbacks[t]&&Array.isArray(this.callbacks[t])&&this.callbacks[t].forEach(i=>{typeof i=="function"&&i(...e)})}emit(t,...e){return this._trigger(t,...e),this}showlisteners(){f(this.callbacks)}removeItem(t){const e=this.items.findIndex(i=>i===t||i.id&&t.id&&i.id===t.id);return e!==-1&&this.items.splice(e,1),Promise.resolve()}setPageSize(t){return/^\d+$/.test(t)?(this.pageSize=t,!0):!1}empty(){return this.clear()}setOffset(t){return/^\d+$/.test(t)?(this.offset=t,!0):!1}update(t){throw new Error("Not implemented... yet")}setUrl(t,e){if(!t)return this;switch(e){case"delete":this.deleteUrl=c(t);break;case"update":this.updateUrl=c(t);break;case"insert":this.insertUrl=c(t);break;default:u("setUrl",t),this.url=c(t),this.deleteUrl=typeof this.deleteUrl=="string"?c(this.deleteUrl):this.deleteUrl??c(this.url),this.updateUrl=typeof this.updateUrl=="string"?c(this.updateUrl):this.updateUrl??c(this.url),this.insertUrl=typeof this.insertUrl=="string"?c(this.insertUrl):this.insertUrl??c(this.url);break}return this}receiveRemoteData(t){if(f("Remote data received",t),this.adapter.isSingleItemResponse(t)){const r=this.adapter.parseItemResponse(t);this.adapter.applyMetadata(this,this.adapter.extractMetadata(t)),this.items.length===0&&this.view.reset(!0),f("Append single item to collection");let n=this.loadItem(r);return n.render(this.view,this.addontop),this._trigger("afterrender",this),n}const{items:e,meta:i}=this.adapter.parseCollectionResponse(t,{type:this.type});if(this.adapter.applyMetadata(this,i),e!=null&&e.constructor===Array){u("Append multiple items to collection"),this.items.length===0&&this.view.reset(!0);const r=[];return e.forEach(n=>{const s=this.loadItem(n);s&&r.push(s)}),this.render(),r}}extractMetadataAndData(t){return f("extract metadata and data",t),t.hasOwnProperty("data")?(this.adapter.applyMetadata(this,this.adapter.extractMetadata(t)),t.data):t}parse(t){return this.extractMetadataAndData(t)}loadFromData(t){return f("collection load from data",t),t===null||typeof t!="object"||t.constructor!==Array?(f("cannot load ",t," into collection ",this),this):(this.navtype==="page"&&(this.items=[]),t.forEach(e=>{this.loadItem(e)}),this.view?this.view.render():f("collection does not have a view ",this),this._trigger("load",this),this)}next(){this.offset=parseInt(this.offset)+parseInt(this.pageSize),this.loadFromRemote()}prev(){this.offset=parseInt(this.offset)-parseInt(this.pageSize),this.loadFromRemote()}clear(){return this.items=[],this.view&&this.view.render(),this._trigger("update",this),this}render(){return this.view&&this.view.render(),this._trigger("afterrender",this),this}loadFromRemote(){return this.loadFromDataSource()}load(t){return t?this.loadFromData(t):this.loadFromRemote()}loadFromDataSource(){const t=z(this);let e=null;return this.view&&this.view.el&&(e=$(t).clone().insertBefore(this.view.el).width($(this.view.el).width()).height($(this.view.el).height())),this._trigger("beforeload",this),new Promise((i,r)=>{if(!this.url){e.remove(),r(new Error("No valid URL provided"));return}this.adapter.applyListQuery(this.url,{type:this.type,offset:this.offset,pageSize:this.pageSize});let n=this.url.toString?this.url.toString():this.url;this.storage.read(this,n,{}).then(s=>{this.navtype==="page"&&(this.items=[]),this.receiveRemoteData(s.data),this._trigger("load",this),e&&$(e).remove(),this.paging&&this.paging.render(),i(this)}).catch(s=>{s instanceof Error&&s.jqXHR?(this.fail(s.jqXHR,s.textStatus||"error",s.errorThrown||s),e.remove(),r(s)):s&&s.jqXHR?(this.fail(s.jqXHR,s.textStatus,s.errorThrown),e.remove(),r(s)):(this.fail(null,"error",s),e.remove(),r(s))})})}fail(t,e,i){f("Fail to load collection",t,e,i,this)}onupdate(){return console.log("onupdate"),this._trigger("update",this),this}insert(t){if(Array.isArray(t))throw new Error("insert() expects a single item object. Use batchInsert() for multiple items.");const e=this.adapter.serializeForCreate(t,{type:this.type});return new Promise((i,r)=>{this.insertUrl||(this.insertUrl=this.url);let n=this.insertUrl.toString?this.insertUrl.toString():this.insertUrl;this.storage.create(this,n,{contentType:e.contentType},e.body).then(s=>{let l=s.data,a=this.receiveRemoteData(l);u("newItem",a),this.onupdate(),i(a)}).catch(s=>{f("fail to receive data",s),r(s)})})}batchInsert(t){if(!Array.isArray(t))throw new Error("batchInsert() expects an array of items. Use insert() for a single item.");if(t.length===0)return Promise.resolve([]);const e=this.adapter.serializeForCreate(t,{type:this.type});return new Promise((i,r)=>{this.insertUrl||(this.insertUrl=this.url);let n=this.insertUrl.toString?this.insertUrl.toString():this.insertUrl;this.storage.create(this,n,{contentType:e.contentType},e.body).then(s=>{let l=s.data;const a=this.receiveRemoteData(l),o=Array.isArray(a)?a:a?[a]:[];u("batchInsert newItems",o),this.onupdate(),i(o)}).catch(s=>{f("fail to receive batch data",s),r(s)})})}append(t){return Array.isArray(t)?this.batchInsert(t):this.insert(t)}createItem(t){return this.insert(t)}newItem(t){return this.insert(t)}loadItem(t){if(u("loadItem from collection",t),!t)return u("no item data",t),null;let e={type:this.type,collection:this,uievents:this.uievents,storage:this.storage,adapter:this.adapter};if(this.setAttrAsId&&t.id==null&&(u("set item id from attribute",this.setAttrAsId,t),t.id=t.attributes[this.setAttrAsId]),t.id&&this.url){let r;const n=c(this.url.toString());n.path+="/"+t.id,e.url=c(n.toString());const s=c(this.updateUrl.toString());s.path+="/"+t.id,e.updateUrl=c(s.toString());const l=c(this.deleteUrl.toString());l.path+="/"+t.id,e.deleteUrl=c(l.toString());const a=c(this.insertUrl.toString());a.path+="/"+t.id,e.insertUrl=c(a.toString())}this.itemListeners&&(e.itemListeners=this.itemListeners);let i=new V(e).bindView(new P({template:this.template,container:this.view})).loadFromData(t);return this.addontop?(f("Add on top"),this.items.unshift(i)):this.items.push(i),i}destroy(){return[...this.items].forEach(e=>{e&&typeof e.destroy=="function"&&e.destroy()}),this.items=[],this.view&&typeof this.view.destroy=="function"&&this.view.destroy(),this.view=null,this.filtering&&typeof this.filtering.destroy=="function"&&this.filtering.destroy(),this.filtering=null,this.paging&&typeof this.paging.destroy=="function"&&this.paging.destroy(),this.paging=null,this.callbacks={},this.storage=null,this.url=null,this.deleteUrl=null,this.insertUrl=null,this.updateUrl=null,this.items=[],this.total=null,this.offset=0,this}},nt=class{constructor(t,e){this.collection=e,this.el=t;let i=$(t);i.data("instance",e).on("submit",r=>{f("Filter form was submitted"),r.preventDefault(),this.handleSubmit(i[0])}).on("reset",()=>{delete this.collection.url.parameters.filter,this.collection.loadFromRemote(),f("filter form reset")})}handleSubmit(t){let e=[];for(let i=0;i<t.elements.length;i++){let r=t.elements[i],n=$(r),s=n.val(),l=n.data("operator");r.name&&s&&e.push(r.name+(l||"=")+s)}this.collection.offset=0,e.length?this.collection.url.parameters.filter=e.join(","):delete this.collection.url.parameters.filter,this.collection.loadFromRemote()}destroy(){if(this.el){const t=$(this.el);t.off("submit"),t.off("reset"),typeof t.removeData=="function"&&t.removeData("instance")}return this.collection=null,this.el=null,this}},lt=class{constructor(t,e){this.el=t,this.collection=e;const i=t.find("[data-sortfld]").data("instance",this.collection).on("click",this.sortNow.bind(this))}sortNow(t){let e=$(t.currentTarget),i=e.data("sortfld"),r=e.data("sortdir"),n=this.collection,s=n.url.parameters.hasOwnProperty("sort")?n.url.parameters.sort:"",l=[];switch(s.split(",").forEach(function(o){let h=/^(-*)([a-z0-9\-\_]+)$/.exec(o.trim());h&&h[2]!=i&&l.push(o)}),r){case"up":l.push("-"+i),e.data("sortdir","down"),e.find(".sort-up").hide(),e.find(".sort-down").show(),e.find(".sort-default").hide();break;case"down":e.data("sortdir",null),e.find(".sort-up").hide(),e.find(".sort-down").hide(),e.find(".sort-default").show();break;default:e.data("sortdir","up"),l.push(i),e.find(".sort-up").show(),e.find(".sort-down").hide(),e.find(".sort-default").hide()}let a=l.join(",");s!==a&&(n.url.parameters.sort=a,n.loadFromRemote())}destroy(){return this.el&&$(this.el).find("[data-sortfld]").each(function(t){$(this).off("click"),$(this).removeData("instance")}),this}},ot={fillForm:function(t,e){let i=$(t)[0];if($(t).prop("tagName")!=="FORM"||!e||!e.hasOwnProperty("attributes"))return null;Object.getOwnPropertyNames(e.attributes).forEach(r=>{if(!i.elements.hasOwnProperty(r))return;let n=e.attributes[r],s=i.elements[r],l=$(s);e.attributes[r]&&typeof e.attributes[r]=="object"&&e.attributes[r].hasOwnProperty("id")&&(n=e.attributes[r].id),l.attr("type")==="date"&&(n=n&&n.substr(0,10)),l.val(n)}),e.relationships&&Object.getOwnPropertyNames(e.relationships).forEach(r=>{if(!i.elements.hasOwnProperty(r))return;if(!e.relationships[r]){$(i.elements[r]).val(null);return}let n=e.relationships[r],s=i.elements[r];if(n.constructor===Array){let l=[];n.forEach(a=>{l.push(a.id)}),$(s).val(l)}else{if(f("set ",r,n),s.tagName==="SELECT"){let l=$(s).data("label"),a=n.hasOwnProperty("attributes")&&n.attributes[l]?n.attributes[l]:n.id;$("<option>").val(n.id).text(a).appendTo($(s))}$(s).val(n.id)}})},captureFormSubmit:function(t,e){let i=$(t);if(!(i.prop("tagName")!=="FORM"||typeof e!="function"))return i.off("submit").on("submit",r=>{r.preventDefault();let n=i[0];e(this.fetchFormData(n),r)}),i},fetchFormData:function(t){let e=$(t)[0],i={};return Object.getOwnPropertyNames(e.elements).forEach(r=>{let n=e.elements[r],s=$(n);if(!s.attr("name")||s.attr("name")===""||s.attr("type")==="checkbox"&&!s[0].checked)return;let l=s.attr("name"),a=s.val(),o=/(\w+)\[\]/.exec(l);if(o){let h=o[1];i[h]||(i[h]=[]),i[h].push(a)}else i[l]=a}),i},extractFormData:function(t){return this.fetchFormData(t)}},S=class O{static prepareOptions(e,i){if(!e)return f("Warning: no DOM element provided for apiator"),null;typeof i=="string"&&(i={url:i});let r={dataBindings:{},addontop:!1};r=Object.assign(r,$(e).data());try{Object.assign(r,w(i))}catch(n){throw new Error("Error on KViews init",n)}return r}static getOrUpdateInstance(e,i){let r=$(e).data("instance");if(r!==void 0){const n=["url","updateUrl","deleteUrl","insertUrl","template","type","pageSize","offset","emptyview","filter","paging","addontop","uievents","setAttrAsId","itemListeners","itemOn","headers","adapter"];i.url&&(r.setUrl(i.url),delete i.url);const s=w(i),l={};return n.forEach(a=>{s.hasOwnProperty(a)&&(l[a]=s[a])}),Object.assign(r,l),l.adapter&&(r.adapter=x(l.adapter)),l.headers&&r.storage&&r.storage.defaultOptions&&(r.storage.defaultOptions.headers=Object.assign({},r.storage.defaultOptions.headers||{},l.headers)),r}return null}static processEmptyView(e){e.hasOwnProperty("emptyview")&&(e.emptyview=$(e.emptyview).remove())}static finalizeInstance(e,i,r,n){return n&&Object.getOwnPropertyNames(n).forEach(s=>{i.on(s,n[s])}),$(e).data("instance",i),f("instance",i.url),i.url&&(typeof r.dontload>"u"||!r.dontload)&&(u("loadFromRemote now",r,i),i.loadFromRemote()),i}static createCollectionInstance(e,i){let r=O.prepareOptions(e,i);if(u("createCollectionInstance",r),!r)return null;let n=O.getOrUpdateInstance(e,r);if(n)return n;f("init apiator collection on ",e,r),O.processEmptyView(r);let s=r.on;delete r.on,f("Create collection instance",r);let l=$(e).length?$(e).html():null;if(r.template)if(r.template instanceof jQuery){f("template is jQuery object",r.template,e);let h=$(r.template).clone().removeAttr("id");l=$("<div>").append(h).html()}else typeof r.template=="string"&&(f("template is raw text: can be either a jQuery selector or raw HTML",r.template,e),l=$("<div>").append($(r.template).clone().removeAttr("id")).html());l!==null&&(l=l.replace(/</gi,"<").replace(/>/gi,">").replace(/'/gi,"'").replace(/"/gi,'"').replace(/ /gi," ").replace(/&/gi,"&"),r.template=E(l));let a={el:e,itemsContainer:r.hasOwnProperty("container")?$(r.container):e,allowempty:r.disableempty!==!0};r.view=new it(a),u("Collection constructor",r);let o=new st(r);if(r.hasOwnProperty("filter")){let h=$(r.filter);h.length&&h.prop("tagName")==="FORM"&&(o.filtering=new nt(h,o))}if(r.hasOwnProperty("sort")){u("setup sorting",r.sort);let h=$(r.sort);h.length&&(o.sorting=new lt(h,o))}return O.finalizeInstance(e,o,r,s),o}static createItemInstance(e,i,r=null){let n=O.prepareOptions(e,i);if(!n)return null;let s=O.getOrUpdateInstance(e,n);if(s)return s;f("init apiator item on ",e,n),O.processEmptyView(n);let l=n.on;delete n.on,n.template=null;let a=null;if($(e).length){var o=$(e)[0];a=o?o.outerHTML:null}a&&(a=a.replace(/</gi,"<").replace(/>/gi,">").replace(/'/gi,"'").replace(/"/gi,'"').replace(/ /gi," ").replace(/&/gi,"&"),n.template=E(a));let h=$(e).attr("id"),p=new V(n,r).bindView(new P({template:n.template,el:e,id:h||null}));return O.finalizeInstance(e,p,n,l),n.dontload&&p.attributes&&Object.keys(p.attributes).length>0&&p.render(),p}static helpers=ot;static get defaultAdapter(){return et()}static set defaultAdapter(e){tt(e)}static registerAdapter(e,i){N(e,i)}};Object.defineProperty(S,"baseUrl",{enumerable:!0,configurable:!0,get(){return y.baseUrl},set(t){y.baseUrl=t}}),Object.defineProperty(S,"basePath",{enumerable:!0,configurable:!0,get(){return y.basePath},set(t){y.basePath=t}}),Object.defineProperty(S,"defaultHeaders",{enumerable:!0,configurable:!0,get(){return y.defaultHeaders},set(t){t&&typeof t=="object"&&!Array.isArray(t)?y.defaultHeaders=t:y.defaultHeaders={}}});var at=S;return typeof window<"u"&&(window.KViews=S),typeof $<"u"&&$.fn&&($.fn.kviews=function(t){let e=this.length?this[0]:this,i="collection";if(t&&t.resourcetype)i=t.resourcetype;else{let r=$(e).data("resourcetype");r&&(i=r)}return i==="item"?S.createItemInstance(e,t):S.createCollectionInstance(e,t)},Object.defineProperty($.fn.kviews,"baseUrl",{enumerable:!0,configurable:!0,get(){return y.baseUrl},set(t){y.baseUrl=t}}),Object.defineProperty($.fn.kviews,"basePath",{enumerable:!0,configurable:!0,get(){return y.basePath},set(t){y.basePath=t}}),Object.defineProperty($.fn.kviews,"defaultHeaders",{enumerable:!0,configurable:!0,get(){return y.defaultHeaders},set(t){t&&typeof t=="object"&&!Array.isArray(t)?y.defaultHeaders=t:y.defaultHeaders={}}}),$.fn.kviewsCollection=function(t){let e={resourcetype:"collection"};return typeof t>"u"&&(t={}),typeof t=="string"&&(t={url:t}),t=Object.assign(t,e),this.kviews(t)},$.fn.kviewsItem=function(t){let e={resourcetype:"item"};return typeof t>"u"&&(t={}),typeof t=="string"&&(t={url:t}),t=Object.assign(t,e),this.kviews(t)}),at})();
|
|
8
|
+
* Version: 1.3.1
|
|
9
|
+
* Built: 2026-06-29T17:09:29.460Z
|
|
10
|
+
*/var KViews=(()=>{var k=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,ct=Object.getOwnPropertyNames,ut=Object.prototype.hasOwnProperty,pt=(t,e)=>{for(var i in e)k(t,i,{get:e[i],enumerable:!0})},dt=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ct(e))!ut.call(t,n)&&n!==i&&k(t,n,{get:()=>e[n],enumerable:!(r=ft(e,n))||r.enumerable});return t},Pt=t=>dt(k({},"__esModule",{value:!0}),t),yt={};pt(yt,{Collection:()=>nt,CollectionView:()=>rt,Filtering:()=>at,Item:()=>M,ItemView:()=>A,JsonApiAdapter:()=>G,KViews:()=>v,Paging:()=>st,PlainRestAdapter:()=>Z,Sorting:()=>lt,Storage:()=>_,URL:()=>W,createOverlay:()=>L,createURL:()=>c,dbg:()=>f,deepEqual:()=>U,deepmerge:()=>P,default:()=>ht,error:()=>gt,getBoundObjects:()=>T,getDefaultAdapter:()=>it,log:()=>u,parseOptions:()=>w,registerAdapter:()=>tt,resolveAdapter:()=>F,setDefaultAdapter:()=>et,template:()=>E,trace:()=>q,uid:()=>B,utilities:()=>ot});function f(){typeof kviewsLogLevel<"u"&&kviewsLogLevel>=3&&console.trace(...arguments)}function u(){typeof kviewsLogLevel<"u"&&kviewsLogLevel>=2&&console.log(...arguments)}function gt(){typeof kviewsLogLevel<"u"&&kviewsLogLevel>=1&&console.error(...arguments)}function q(){typeof kviewsLogLevel<"u"&&kviewsLogLevel>=4&&console.trace(...arguments)}function B(){return"uid_"+Math.random().toString(36).substr(2,9)}function w(t){if(typeof t>"u")return{};if(t.constructor===Object)return t;throw new Error("Invalid options",t)}function U(t,e){if(t===e)return!0;if(t===null||e===null||typeof t!="object"||typeof e!="object")return!1;if(Array.isArray(t)||Array.isArray(e)){if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!U(t[n],e[n]))return!1;return!0}const i=Object.keys(t),r=Object.keys(e);if(i.length!==r.length)return!1;for(const n of i)if(!Object.prototype.hasOwnProperty.call(e,n)||!U(t[n],e[n]))return!1;return!0}function P(t,e,i){function r(p,m,j){let b=p.slice();return m.forEach(function(g,z){typeof b[z]>"u"?b[z]=a(g,j):n(g)?b[z]=P(p[z],g,j):p.indexOf(g)===-1&&b.push(a(g,j))}),b}function n(p){var m=p&&typeof p=="object";return m&&Object.prototype.toString.call(p)!=="[object RegExp]"&&Object.prototype.toString.call(p)!=="[object Date]"}function s(p){return Array.isArray(p)?[]:{}}function a(p,m){return m&&m.clone===!0&&n(p)?P(s(p),p,m):p}function l(p,m,j){let b={};return n(p)&&Object.keys(p).forEach(function(g){b[g]=a(p[g],j)}),Object.keys(m).forEach(function(g){!n(m[g])||!p[g]?b[g]=a(m[g],j):b[g]=P(p[g],m[g],j)}),b}let o=Array.isArray(e),d=(i||{arrayMerge:r}).arrayMerge||r;return o?Array.isArray(t)?d(t,e,i):a(e,i):l(t,e,i)}P.all=function(e,i){if(!Array.isArray(e)||e.length<2)throw new Error("first argument should be an array with at least two elements");return e.reduce(function(r,n){return P(r,n,i)})};function T(t){let e={};if(!t||$(t).length===0)return e;let i=$(t).data();for(let r in i)typeof i[r]=="object"&&r!=="instance"&&(e[r]=i[r]);return e}function E(t){if(typeof Handlebars<"u")return Handlebars.compile(t);throw new Error("Handlebars is required for template compilation")}function L(t){return $(document.createElement("div")).text("Se incarca 123").addClass("komponent-overlay").data("asd",t).attr("style","background: linear-gradient(135deg,rgb(191, 225, 205),rgb(236, 234, 232) 70%, #fca); text-align: center; position:absolute; z-index:100000;")}var y={baseUrl:null,basePath:null,defaultHeaders:{}};function mt(t){if(t==null||t==="")return t;const e=typeof t=="string"?t:String(t);if(/^https?:\/\//i.test(e)||e.startsWith("//"))return e;const i=y.baseUrl||y.basePath||"";if(!i)return e;const r=i.replace(/\/+$/,""),n=e.replace(/^\/+/,"");return n?r+"/"+n:r+"/"}var I=class extends Error{constructor(t,e={}){super(t),this.name="KViewsError",this.options=e.options||{},this.context=e.context||null,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}},C=class extends I{constructor(t,e={}){super(t,e),this.name="KViewsHttpError",this.status=e.status||0,this.statusText=e.statusText||"error",this.responseText=e.responseText||null,this.responseJSON=e.responseJSON||null,this.jqXHR=e.jqXHR||null,this.textStatus=e.textStatus||"error",this.errorThrown=e.errorThrown||null}},D=class extends I{constructor(t,e={}){super(t,e),this.name="KViewsParseError",this.rawData=e.rawData||null,this.parseStep=e.parseStep||null}},J=class extends I{constructor(t,e={}){super(t,e),this.name="KViewsUrlError",this.url=e.url||null}},K=class extends I{constructor(t,e={}){super(t,e),this.name="KViewsNetworkError",this.originalError=e.originalError||null,this.url=e.url||null}},W=class{constructor(t){if(!t)throw new J("URL is not provided",{url:t});if(typeof t=="object"&&t.hasOwnProperty("protocol")){Object.assign(this,t),this.parameters&&!this.parameters.toString&&this._addParametersToString();return}if(t.constructor!==String)throw f("URL is not a string",t),new J("URL is not a string: "+t.toString(),{url:t});if(/^[a-z]+:\/\//i.test(t)&&typeof window<"u"&&window.URL)try{const i=new window.URL(t);this.protocol=i.protocol?i.protocol.replace(":",""):null,this.fqdn=i.hostname||null,this.port=i.port||null,this.path=i.pathname||null,this.fragment=i.hash?i.hash.replace("#",""):null,this.parameters={},i.search&&new URLSearchParams(i.search).forEach((n,s)=>{this.parameters[s]=n})}catch{this._parseRelativeUrl(t)}else this._parseRelativeUrl(t);this._addParametersToString()}_parseRelativeUrl(t){let i=/^((?:([a-z]+):)([\/]{2,3})([\w\.\-\_]+)(?::(\d+))?)?(?:(\/?[^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/i.exec(t);if(this.protocol=null,this.fqdn=null,this.port=null,this.path=null,this.parameters={},this.fragment=null,typeof i[2]<"u"&&(this.protocol=i[2]),typeof i[4]<"u"&&(this.fqdn=i[4]),typeof i[5]<"u"&&(this.port=i[5]),typeof i[6]<"u"&&(this.path=i[6]),typeof i[7]<"u")try{new URLSearchParams(i[7]).forEach((n,s)=>{this.parameters[s]=n})}catch{i[7].split("&").forEach(s=>{if(!s||s==="")return;let a=s.indexOf("=");a===-1?this.parameters[s]="":this.parameters[s.substr(0,a)]=decodeURIComponent(s.substr(a+1))})}typeof i[8]<"u"&&(this.fragment=i[8])}_addParametersToString(){if(!this.parameters.toString||this.parameters.toString===Object.prototype.toString){const t=this;this.parameters.toString=function(){if(typeof URLSearchParams<"u")try{const i=new URLSearchParams;for(let r in this)this.hasOwnProperty(r)&&r!=="toString"&&i.append(r,String(this[r]));return i.toString()}catch{}let e=[];for(let i in this)if(this.hasOwnProperty(i)&&i!=="toString"){const r=String(this[i]);e.push(encodeURIComponent(i)+"="+encodeURIComponent(r))}return e.join("&")}}}toString(){let t="";if(this.protocol&&this.fqdn){if(typeof window<"u"&&window.URL)try{const e=this.protocol+"://"+this.fqdn+(this.port?":"+this.port:""),i=new window.URL(this.path||"/",e);return this.parameters&&Object.keys(this.parameters).length>0&&Object.getOwnPropertyNames(this.parameters).forEach(r=>{r!=="toString"&&i.searchParams.set(r,this.parameters[r])}),this.fragment&&(i.hash=this.fragment),i.toString()}catch{}t+=this.protocol+"://"+this.fqdn,this.port&&(t+=":"+this.port)}return this.path&&(t+=this.path),this.parameters&&Object.keys(this.parameters).length>0&&(t+="?"+this.parameters.toString()),this.fragment&&(t+="#"+this.fragment),t}};function c(t){return new W(t)}var _=class{constructor(t={}){let e={url:null,method:"GET"};t=w(t),Object.assign(e,t),this.defaultOptions=e}sync(t){t.url&&typeof t.url=="object"&&t.url.toString&&(t.url=t.url.toString()),t.url=mt(t.url),t=Object.assign(Object.assign({},this.defaultOptions),w(t));const e=y.defaultHeaders&&typeof y.defaultHeaders=="object"?y.defaultHeaders:{},i=this.defaultOptions.headers&&typeof this.defaultOptions.headers=="object"?this.defaultOptions.headers:{},r=t.headers&&typeof t.headers=="object"?t.headers:{};if(t.headers=Object.assign({},e,i,r),!t.hasOwnProperty("url"))throw new Error("No URL provided");t.url&&typeof t.url=="object"&&t.url.toString&&(t.url=t.url.toString());const n={method:t.method||"GET",headers:{}};return t.headers&&Object.assign(n.headers,t.headers),t.contentType&&(n.headers["Content-Type"]=t.contentType),t.data&&["POST","PUT","PATCH"].includes(n.method)&&(n.body=t.data),fetch(t.url,n).catch(s=>{throw new K(s instanceof Error?s.message:String(s),{originalError:s instanceof Error?s:new Error(String(s)),url:t.url,options:t})}).then(async s=>{const a={status:s.status,statusText:s.statusText,responseText:null,responseJSON:null,getAllResponseHeaders:()=>{const h={};return s.headers.forEach((d,p)=>{h[p]=d}),Object.entries(h).map(([d,p])=>`${d}: ${p}`).join(`\r
|
|
11
|
+
`)},getResponseHeader:h=>s.headers.get(h)},l=await s.text();let o=l;try{o=JSON.parse(l)}catch{}if(a.responseText=l,a.responseJSON=typeof o=="object"?o:null,!s.ok){const h=new C(`HTTP ${s.status}: ${s.statusText}`,{status:s.status,statusText:s.statusText,responseText:l,responseJSON:typeof o=="object"?o:null,jqXHR:a,options:t,errorThrown:new Error(`HTTP ${s.status}: ${s.statusText}`)});throw h.textStatus="error",h}return{data:o,textStatus:"success",jqXHR:a}}).catch(s=>{if(s instanceof C||s instanceof K)throw s;const a={status:0,statusText:"error",responseText:null,responseJSON:null,getAllResponseHeaders:()=>"",getResponseHeader:()=>null},l=new C(s instanceof Error?s.message:String(s),{status:0,statusText:"error",responseText:null,responseJSON:null,jqXHR:a,options:t,errorThrown:s instanceof Error?s:new Error(String(s))});throw l.textStatus="error",l})}create(t,e,i,r){let n={context:t,url:e,method:"POST",data:r};return Object.assign(n,i),this.sync(n)}read(t,e,i){let r={context:t,url:e,method:"GET"};return Object.assign(r,i),this.sync(r)}delete(t,e,i){let r={context:t,url:e,method:"DELETE"};return Object.assign(r,i),this.sync(r)}update(t,e,i,r){let n={context:t,url:e,method:"PATCH",contentType:"application/vnd.api+json",data:r};return Object.assign(n,i),this.sync(n)}};function bt(t){if(!t||typeof t!="object")return[];const e=t.hasOwnProperty("included")?t.included:t.hasOwnProperty("includes")?t.includes:null;return e?Array.isArray(e)?e:[]:[]}function wt(t){const e=new Map;if(!t||typeof t!="object")return e;function i(n){if(!n||typeof n!="object"||!n.type||!n.id)return;const s=`${n.type}/${n.id}`;e.has(s)||e.set(s,n)}return t.data&&(Array.isArray(t.data)?t.data.forEach(i):typeof t.data=="object"&&i(t.data)),bt(t).forEach(i),e}function Q(t,e,i){let r,n;if(typeof t=="object"&&t!==null?(r=t.type,n=t.id):(r=t,n=e),!r||!n)return null;const s=`${r}/${n}`;return i.get(s)||null}function x(t,e,i=new Set){if(!t||typeof t!="object"||!t.relationships)return t;const r=t.type&&t.id?`${t.type}/${t.id}`:null;return r&&i.has(r)||(r&&i.add(r),Object.keys(t.relationships).forEach(n=>{const s=t.relationships[n];if(s!==null)if(s.data!==void 0)if(s.data===null)t.relationships[n]=null;else if(Array.isArray(s.data))t.relationships[n]=s.data.map(a=>{const l=Q(a,null,e);return l?x(l,e,new Set(i)):a}).filter(a=>a!==null);else if(typeof s.data=="object"&&s.data.type&&s.data.id){const a=Q(s.data,null,e);a?t.relationships[n]=x(a,e,new Set(i)):t.relationships[n]=s.data}else t.relationships[n]=s.data;else t.relationships[n]=s})),t}function X(t){if(!t||typeof t!="object")throw new D("Invalid document: must be an object");const e=wt(t);if(!t.data)return null;const i=t.data;return Array.isArray(i)?(i.forEach(r=>x(r,e)),i):typeof i=="object"?x(i,e):i}function Ot(t,e={}){let i,r=t;if(t&&typeof t=="object"&&t.type&&t.id&&!t.data?i=t:t&&t.data?(r=t,i=X(r)):i=t,!i||typeof i!="object")throw new D("Invalid item data: must be an object");return r&&r.links&&r.links.self&&!i.url&&(i.url=c(r.links.self)),i}function St(t){if(!t||typeof t!="object")return[];const e=X(t);return e?Array.isArray(e)?e:[e]:[]}function V(t){if(t===null)return null;if(typeof t!="object")throw new Error("Invalid item data: "+t);if(t.constructor===Array||t.hasOwnProperty("items")&&t.hasOwnProperty("length")){let i=[];return t.forEach(function(r){i.push(V(r))}),i}if(t.constructor!==Object)throw new Error("Invalid case");let e={};if(!t.hasOwnProperty("attributes")){let i={attributes:{}};t.hasOwnProperty("type")&&(i.type=t.type),Object.assign(i.attributes,t),t=i}return Object.getOwnPropertyNames(t.attributes).forEach(function(i){if(t.attributes[i]&&typeof t.attributes[i]=="object"){e.relationships||(e.relationships={}),e.relationships[i]={data:V(t.attributes[i])};return}e.attributes||(e.attributes={}),e.attributes[i]=t.attributes[i]}),e}var G=class{name="jsonapi";isSingleItemResponse(t){return!!(t&&t.data&&typeof t.data=="object"&&!Array.isArray(t.data))}extractMetadata(t){const e={};return!t||!t.hasOwnProperty("meta")||typeof t.meta!="object"||(t.meta.hasOwnProperty("totalRecords")&&(e.totalRecords=t.meta.totalRecords*1),t.meta.hasOwnProperty("offset")&&(e.offset=t.meta.offset)),e}applyMetadata(t,e){e.totalRecords!==void 0&&(t.total=e.totalRecords),e.offset!==void 0&&(t.offset=e.offset)}parseItemResponse(t,e={}){return this.validateItemRemoteDoc(t,e),Ot(t,e)}validateItemRemoteDoc(t){if(t?.data?.constructor===Array)throw new Error("Invalid configuration: resource type is item but server response is collection")}inferItemType(t){return t?.data?.type}parseCollectionResponse(t){const e=St(t),i=this.extractMetadata(t);return{items:e,meta:i}}applyListQuery(t,e){const{type:i,offset:r,pageSize:n}=e;typeof r<"u"&&r!==null&&i&&(t.parameters[`page[${i}][offset]`]=r),typeof n<"u"&&n!==null&&i&&(t.parameters[`page[${i}][limit]`]=n)}extractListQueryFromUrl(t,e={}){const{type:i}=e,r={};if(!t||!t.parameters||!i)return r;const n=`page[${i}][limit]`,s=`page[${i}][offset]`;return t.parameters.hasOwnProperty(n)&&(r.pageSize=t.parameters[n]),t.parameters.hasOwnProperty(s)&&(r.offset=t.parameters[s]),r}serializeForCreate(t,e={}){const i={data:V(t)};return e.type&&(i.type=e.type),{body:JSON.stringify(i),contentType:"application/vnd.api+json"}}serializeForUpdate(t){return{body:JSON.stringify({data:t}),contentType:"application/vnd.api+json"}}serializeRelationship(t){if(t===null)return{data:null};if(t&&typeof t=="object"&&!Array.isArray(t)){if(t.id){const e={data:{id:t.id}};return t.type&&(e.data.type=t.type),e}if(t.hasOwnProperty("toJSON")){const e=t.toJSON(),i={data:{id:e.id}};return e.type&&(i.data.type=e.type),i}return{data:null}}return Array.isArray(t)?{data:t.map(e=>{if(e&&typeof e=="object"){if(e.type&&e.id){const i={id:e.id};return e.type&&(i.type=e.type),i}if(e.hasOwnProperty("toJSON")){const i=e.toJSON(),r={id:i.id};return i.type&&(r.type=i.type),r}}return e}).filter(e=>e&&e.id)}:{data:null}}};function S(t,e){if(!(!t||!e||typeof e!="string"))return e.split(".").reduce((i,r)=>{if(!(i==null||typeof i!="object"))return i[r]},t)}function Y(t,e){if(Array.isArray(t))return t;if(!t||typeof t!="object")return[];if(e){const i=S(t,e);return Array.isArray(i)?i:[]}return Array.isArray(t.data)?t.data:Array.isArray(t.items)?t.items:Array.isArray(t.results)?t.results:[]}function vt(t,e){if(!(!t||typeof t!="object")){if(e){const i=S(t,e);return i!=null?i*1:void 0}for(const i of["total","count","totalCount","meta.totalRecords"]){const r=S(t,i);if(r!=null)return r*1}}}function jt(t,e){if(!(!t||typeof t!="object")){if(e){const i=S(t,e);return i??void 0}for(const i of["offset","meta.offset"]){const r=S(t,i);if(r!=null)return r}}}var Z=class{name="plain";constructor(t={}){this.itemsPath=t.itemsPath??null,this.itemPath=t.itemPath??null,this.totalPath=t.totalPath??null,this.offsetPath=t.offsetPath??null,this.idField=t.idField??"id",this.typeField=t.typeField??"type",this.paginationStyle=t.paginationStyle??"offset",this.offsetParam=t.offsetParam??"offset",this.limitParam=t.limitParam??"limit",this.pageParam=t.pageParam??"page",this.embedRelationships=t.embedRelationships??!1}isSingleItemResponse(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;if(this.itemPath){const i=S(t,this.itemPath);return Array.isArray(i)?!1:i&&typeof i=="object"?i[this.idField]!=null:!1}return Y(t,this.itemsPath).length>0||t.data&&Array.isArray(t.data)?!1:t.data&&typeof t.data=="object"&&t.data[this.idField]!=null?!0:t[this.idField]!=null}extractMetadata(t){const e={},i=vt(t,this.totalPath);i!==void 0&&(e.totalRecords=i);const r=jt(t,this.offsetPath);return r!==void 0&&(e.offset=r),e}applyMetadata(t,e){e.totalRecords!==void 0&&(t.total=e.totalRecords),e.offset!==void 0&&(t.offset=e.offset)}parseItemResponse(t,e={}){this.validateItemRemoteDoc(t,e);const i=this.extractRawItem(t),r=e.collection?.type??e.type;return this.normalize(i,r)}validateItemRemoteDoc(t){if(Array.isArray(t))throw new Error("Invalid configuration: resource type is item but server response is collection");if(this.itemPath){const e=S(t,this.itemPath);if(Array.isArray(e))throw new Error("Invalid configuration: resource type is item but server response is collection");return}if(t?.data&&Array.isArray(t.data))throw new Error("Invalid configuration: resource type is item but server response is collection")}inferItemType(t){const e=this.extractRawItem(t);if(!(!e||typeof e!="object"))return e[this.typeField]}parseCollectionResponse(t,e={}){const i=Y(t,this.itemsPath),r=e.type,n=i.map(a=>this.normalize(a,r)),s=this.extractMetadata(t);return{items:n,meta:s}}applyListQuery(t,e){const{offset:i,pageSize:r}=e;if(!(typeof r>"u"||r===null)){if(this.paginationStyle==="page"){const s=Math.floor((typeof i>"u"||i===null?0:i)/r)+1;t.parameters[this.pageParam]=s,t.parameters[this.limitParam]=r;return}typeof i<"u"&&i!==null&&(t.parameters[this.offsetParam]=i),t.parameters[this.limitParam]=r}}extractListQueryFromUrl(t){const e={};if(!t||!t.parameters)return e;if(t.parameters.hasOwnProperty(this.limitParam)?e.pageSize=t.parameters[this.limitParam]:t.parameters.hasOwnProperty("pageSize")&&(e.pageSize=t.parameters.pageSize),this.paginationStyle==="page"&&t.parameters.hasOwnProperty(this.pageParam)){const i=t.parameters[this.pageParam]*1,r=e.pageSize!=null?e.pageSize*1:null;r&&(e.offset=(i-1)*r)}else t.parameters.hasOwnProperty(this.offsetParam)&&(e.offset=t.parameters[this.offsetParam]);return e}serializeForCreate(t,e={}){const i=e.type;let r;return Array.isArray(t)?r=t.map(n=>this.flattenForWire(this.coerceToCanonical(n,i))):r=this.flattenForWire(this.coerceToCanonical(t,i)),{body:JSON.stringify(r),contentType:"application/json"}}serializeForUpdate(t){const e={};Object.entries(t.relationships||{}).forEach(([r,n])=>{e[r]=this.unwrapRelationship(n)});const i=this.flattenForWire({id:t.id,type:t.type,attributes:t.attributes,relationships:e});return{body:JSON.stringify(i),contentType:"application/json"}}serializeRelationship(t){return this.unwrapRelationship(t)}extractRawItem(t){return this.itemPath?S(t,this.itemPath):t?.data&&typeof t.data=="object"&&!Array.isArray(t.data)?t.data:t}normalize(t,e){if(!t||typeof t!="object"||Array.isArray(t))throw new Error("Invalid item data: must be an object");if(t.attributes&&typeof t.attributes=="object"){const l={};Object.entries(t.relationships||{}).forEach(([h,d])=>{d===null?l[h]=null:Array.isArray(d)?l[h]=d.map(p=>this.normalize(p,e)):l[h]=this.normalize(d,e)});const o={attributes:{...t.attributes},relationships:l};return t.id!=null&&(o.id=String(t.id)),(t.type??e)&&(o.type=t.type??e),o}const i={},r={};let n,s;Object.entries(t).forEach(([l,o])=>{if(l===this.idField){n=o;return}if(l===this.typeField){s=o;return}if(o==null){i[l]=o;return}if(Array.isArray(o)){o.length>0&&o.every(h=>this.isNestedResource(h))?r[l]=o.map(h=>this.normalize(h,e)):i[l]=o;return}if(this.isNestedResource(o)){r[l]=this.normalize(o,e);return}i[l]=o});const a={attributes:i,relationships:r};return n!=null&&(a.id=String(n)),(s??e)&&(a.type=s??e),a}isNestedResource(t){return t&&typeof t=="object"&&!Array.isArray(t)&&t[this.idField]!=null}coerceToCanonical(t,e){return!t||typeof t!="object"||t.attributes||t.relationships?t:this.normalize(t,e)}flattenForWire(t){if(!t||typeof t!="object")return t;const e={...t.attributes||{}};return t.id!=null&&(e[this.idField]=t.id),t.type!=null&&this.typeField&&(e[this.typeField]=t.type),Object.entries(t.relationships||{}).forEach(([i,r])=>{if(r===null){e[i]=null;return}if(Array.isArray(r)){e[i]=r.map(n=>this.relationshipToWire(n));return}e[i]=this.relationshipToWire(r)}),e}relationshipToWire(t){if(!t)return null;if(this.embedRelationships&&t.attributes)return this.flattenForWire(t);const e={[this.idField]:t.id??t[this.idField]};return(t.type??t[this.typeField])!=null&&(e[this.typeField]=t.type??t[this.typeField]),e}unwrapRelationship(t){return t==null?null:t.data!==void 0?t.data===null?null:Array.isArray(t.data)?t.data.map(e=>({...e})):{...t.data}:Array.isArray(t)?t.map(e=>this.unwrapRelationship(e)):typeof t=="object"?t.attributes?t:{...t}:t}},N=new Map([["jsonapi",new G],["plain",new Z]]),H="jsonapi";function tt(t,e){if(!t||typeof t!="string")throw new Error("Adapter name must be a non-empty string");N.set(t,e)}function et(t){H=t}function it(){return H}function F(t){if(t&&typeof t=="object")return t;const e=typeof t=="string"?t:H;if(typeof e=="object")return e;const i=N.get(e);if(!i)throw new Error(`Unknown data adapter: ${e}`);return i}var A=class{constructor(t){if(t&&t.isView)return t;if(this.type="ItemView",this.dataBindings=null,this.template=null,this.container=null,this.collectionView=null,this.item=null,this.el=null,this.id=B(),this.isView=!0,this.callbacks={},t&&(t.length||t.nodeName&&!t.jquery)){f("params is actually a jquery object or an html node",t);let e=$(t);if(e.data("view"))return e.data("view");let i=$("<div>").append(e.clone(!0)),r=i.html().replace(/<%/gi,"<%").replace(/</gi,"<").replace(/%>/gi,"%>").replace(/>/gi,">").replace(/&/gi,"&");t={template:E(r),el:e},e.attr("id")&&(t.id=e.attr("id")),i.remove()}try{t=w(t)}catch(e){throw new Error("Error on ItemView",this,e)}Object.assign(this,t),this.el!==null&&(this.dataBindings=T(this.el))}on(t,e){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(e),this}unbind(){this.item&&this.item.unbindView(this)}createElementFromTemplate(){if(this.template==null)return f("Warning: no template defined. Nothing to render"),null;if(!this.item)return f("Warning: no item bound to view. Cannot render template."),null;let t;try{const e=this.item.getRenderContext();console.log("renderContext",e);let i=this.template(e);t=$(i).attr("data-type","item").attr("id",this.id).data("view",this).data("instance",this.item)}catch(e){console.log("Error create view from template",e,this.item),t=$("<div>Could not render view: <strong>"+e.toString()+"</strong></div>")}return t}afterrender(){this.callbacks.afterrender&&(console.log("afterend of view",this),this.callbacks.afterrender.forEach(t=>t(this)))}render(t=!1,e=!1){u("ItemView.render called",this.item,this.el);let i=this.createElementFromTemplate();if(!i)return null;if(u("View item",this.item),this.item&&this.item.uievents&&(u("UI events",this.item.uievents),this.item.uievents.forEach(r=>{if(u("UI event",r,i),r.selector&&r.event&&r.callback){const n=$(i).find(r.selector);u("UI event els",r,i,n),n.on(r.event,s=>{s.preventDefault(),u("UIevent triggered",s,this.item,this),r.callback(s,this.item,this)})}})),t)return this.el=i,this.el;if(this.el){let r=this.el;return r.jquery||(r=$(r)),r.off(),this.el=$(i).insertBefore(r),r.remove(),this.afterrender(),this}return this.el=i,this.afterrender(),this.container?($(this.el).appendTo(this.container.el),this):this}renderEmpty(t){if(this.item&&this.item.emptyview&&this.el){let e=$(this.item.emptyview).clone(!0).css("display","block");$(this.el).replaceWith(e)}}remove(t){return new Promise(e=>{if(this.item&&this.item.collection&&this.item.collection._trigger("afterrender",this.item.collection),this.el){let i=this.el.jquery?this.el:$(this.el);i.fadeOut({complete:()=>{i.remove(),e()}})}else e()})}destroy(){if(this.el){const t=this.el.jquery?this.el:$(this.el);t.off(),t.removeData()}return this.callbacks={},this.item&&this.item.unbindView(this),this.item=null,this.container=null,this.collectionView=null,this.el=null,this.template=null,this.dataBindings=null,this}},M=class R{constructor(e={},i=null){this.id=null,this.type=null,this.attributes={},this.relationships={},this.views=[],this.collection=null,this.url=null,this.updateUrl=null,this.deleteUrl=null,this.strict=!1,this.shadow=null,this.syncOp=null,this.emptyview=null,this.uievents=[],this.callbacks={},this.adapter=null;try{Object.assign(this,w(e))}catch(n){throw new Error("Error on Item init",n)}this.adapter=F(e.adapter??(e.collection&&e.collection.adapter)),this.storage=e.storage||new _((()=>{const n=Object.assign({},e.ajaxOpts||{});return e.headers&&typeof e.headers=="object"&&(n.headers=Object.assign({},n.headers||{},e.headers)),n})());let r=!1;if(i){u("Loading data",i);try{this.loadFromData(i),r=!0}catch(n){console.error("Error loading data",n)}}this.url&&this.setUrl(this.url),this.deleteUrl&&(u("deleteUrl",this.deleteUrl),this.setUrl(this.deleteUrl,"delete")),this.updateUrl&&this.setUrl(this.updateUrl,"update"),this.insertUrl&&this.setUrl(this.insertUrl,"insert"),this.views.forEach(n=>{n.item=this}),e.itemListeners&&typeof e.itemListeners=="object"&&Object.getOwnPropertyNames(e.itemListeners).forEach(n=>{u("apply item listener",n,e.itemListeners[n]),this.on(n,e.itemListeners[n])}),r&&(u("Rendering data",i),this.render())}on(e,i){return typeof this.callbacks[e]>"u"&&(this.callbacks[e]=[]),this.callbacks[e].push(i),this}off(e,i){if(!e)return this.callbacks={},this;if(!this.callbacks[e])return this;if(i){const r=this.callbacks[e].indexOf(i);r>-1&&this.callbacks[e].splice(r,1),this.callbacks[e].length===0&&delete this.callbacks[e]}else delete this.callbacks[e];return this}once(e,i){const r=(...n)=>{i(...n),this.off(e,r)};return this.on(e,r)}hasListeners(e){return this.callbacks[e]&&Array.isArray(this.callbacks[e])&&this.callbacks[e].length>0}_trigger(e,...i){this.callbacks[e]&&Array.isArray(this.callbacks[e])&&this.callbacks[e].forEach(r=>{typeof r=="function"&&r(...i)})}emit(e,...i){return this._trigger(e,...i),this}setUrl(e,i){switch(i){case"delete":this.deleteUrl=c(e);break;case"update":this.updateUrl=c(e);break;case"insert":this.insertUrl=c(e);break;default:this.url=c(e),this.deleteUrl=typeof this.deleteUrl=="string"?c(this.deleteUrl):this.deleteUrl??c(this.url),this.updateUrl=typeof this.updateUrl=="string"?c(this.updateUrl):this.updateUrl??c(this.url);break}return this}loadFromRemote(){return this.loadFromDataSource()}load(e){return e?this.loadFromData(e):this.loadFromRemote()}loadFromDataSource(){let e=[];if(this.showLoader!==!1){const n=L(this);this.views.forEach(s=>{if(s.el){let a=$(s.el),l=n.clone();l.insertBefore(s.el).width(a.width()).height(a.height()),e.push(l)}})}const r=()=>{e.forEach(n=>{n.remove()})};return new Promise((n,s)=>{if(!this.url){r(),s(new Error("No valid URL provided"));return}this._trigger("beforeload",this);let a=this.url.toString?this.url.toString():this.url;this.storage.read(this,a,{}).then(l=>{let o=l.data;const h=this._parseRemoteDoc(o);this._remoteDataEquals(h)||(this._applyParsedRemoteData(h),this.render()),this._trigger("load",this),r(),n(this)}).catch(l=>{r(),f("fail to load item resource",this.url,l),l instanceof Error&&l.jqXHR?(this.fail(l.jqXHR,l.textStatus||"error",l.errorThrown||l),s(l)):l&&l.jqXHR?(this.fail(l.jqXHR,l.textStatus,l.errorThrown),s(l)):(this.fail(null,"error",l),s(l))})})}refresh(){return this.loadFromRemote()}reload(){return this.loadFromRemote()}load_from_data_source(){return this.loadFromDataSource()}unbindView(e){let i=!1;for(let r=0;r<this.views.length;r++)this.views[r]===e&&(i=r);i!==!1&&this.views.splice(i,1)}bindView(e,i){if($(e).length===0)throw new Error("Nothing to bind to: empty view element");e instanceof A||(e=new A(e));let n=!1;return this.views.forEach(s=>{f("bind to existing view",s.el),s===e&&(n=!0)}),n?i?e:this:(e.item=this,this.views.push(e),i?e:this)}_parseRemoteDoc(e){if(this.collection&&!this.collection.type){const i=this.adapter.inferItemType(e);i&&(this.type=i)}return this.adapter.validateItemRemoteDoc(e,{collection:this.collection}),this.adapter.parseItemResponse(e,{collection:this.collection})}_applyParsedRemoteData(e){Object.assign(this,e),this.url&&(this.url=c(this.url))}_remoteDataEquals(e){return this.id==null&&(!this.attributes||Object.keys(this.attributes).length===0)||String(this.id??"")!==String(e.id??"")||(this.type??null)!==(e.type??null)||!U(this.attributes??{},e.attributes??{})?!1:U(this._normalizeRelationshipsForCompare(this.relationships),this._normalizeRelationshipsForCompare(e.relationships))}_normalizeRelationshipsForCompare(e){if(!e||typeof e!="object")return{};const i={};return Object.keys(e).sort().forEach(r=>{i[r]=this._normalizeRelationshipValueForCompare(e[r])}),i}_normalizeRelationshipValueForCompare(e){if(e==null)return null;if(Array.isArray(e))return e.map(r=>this._normalizeRelationshipValueForCompare(r));if(typeof e!="object")return e;const i={id:e.id??null,type:e.type??null,attributes:e.attributes??{}};return e.relationships&&(i.relationships=this._normalizeRelationshipsForCompare(e.relationships)),i}loadFromRemoteDoc(e){f("Load from remote doc",e);const i=this._parseRemoteDoc(e);return this._remoteDataEquals(i)?this:(this._applyParsedRemoteData(i),this)}loadFromJSONAPIDoc(e){return this.loadFromRemoteDoc(e)}loadFromData(e,i=!1){if(e===null||typeof e!="object"||e.constructor!==Object)throw f("cannot load ",e," into ",this),new Error("Cannot load data into item");if(!e.hasOwnProperty("attributes")&&!e.hasOwnProperty("id")&&!e.hasOwnProperty("type")){f("need to normalize data",e);let r={},n={};Object.getOwnPropertyNames(e).forEach(s=>{if(e[s]&&e[s].constructor===Object){n[s]=new R().loadFromData(e[s]);return}if(e[s]&&e[s].constructor===Array){n[s]=e[s];return}r[s]=e[s]}),e={attributes:r},Object.getOwnPropertyNames(n).length&&(e.relationships=n)}return Object.assign(this,e),this._trigger("load",this),i&&this.render(),this}fail(e,i,r){f("item.fail",e,i,r),this.views.forEach(n=>{e&&e.status===404&&n.renderEmpty()})}getRenderContext(){function e(s,a=new WeakMap){if(s===null||typeof s!="object")return s;if(a.has(s))return a.get(s);if(Array.isArray(s)){const o=[];return a.set(s,o),s.forEach(h=>o.push(e(h,a))),o}const l={};return a.set(s,l),Object.keys(s).forEach(o=>{l[o]=e(s[o],a)}),l}function i(s){return s instanceof R||s.attributes!=null&&typeof s.attributes=="object"}function r(s){return!s||typeof s!="object"||Array.isArray(s)||i(s)||s.id==null?!1:Object.keys(s).every(a=>a==="id"||a==="type")}function n(s,a=new WeakMap){if(!s)return null;if(typeof s!="object")return s;if(a.has(s))return a.get(s);if(r(s)){const o={id:s.id};return a.set(s,o),o}if(!i(s)){if(s.id!=null){const h={id:s.id};return Object.keys(s).forEach(d=>{d==="id"||d==="type"||d==="relationships"||d==="attributes"||(h[d]=e(s[d]))}),a.set(s,h),h}const o=e(s);return a.set(s,o),o}const l={id:s.id};return a.set(s,l),Object.assign(l,e(s.attributes??{})),Object.keys(s.relationships??{}).forEach(o=>{Array.isArray(s.relationships[o])?l[o]=s.relationships[o].map(h=>n(h,a)):l[o]=n(s.relationships[o],a)}),l}return n(this)}toJSON(){let e={type:this.type,attributes:this.attributes||{}};if(this.id&&(e.id=this.id),this.relationships&&Object.keys(this.relationships).length>0){e.relationships={};for(let i in this.relationships){if(!this.relationships.hasOwnProperty(i))continue;const r=this.relationships[i];if(r===null){e.relationships[i]={data:null};continue}if(r&&typeof r=="object"&&!Array.isArray(r)){if(r.type&&r.id)e.relationships[i]={data:{type:r.type,id:r.id}};else if(r.hasOwnProperty("toJSON"))e.relationships[i]={data:r.toJSON()};else continue;continue}if(Array.isArray(r)){e.relationships[i]={data:r.map(n=>{if(n&&typeof n=="object"){if(n.type&&n.id)return{type:n.type,id:n.id};if(n.hasOwnProperty("toJSON"))return n.toJSON()}return n})};continue}}}return f("item.json",e),e}_serializeRelationshipToWireFormat(e){return this.adapter.serializeRelationship(e)}sync(){if(this.syncOp){let e=this.syncOp;return f("Syncing",this,e),this.syncOp=null,e()}else f("Nothing to sync on",this)}perform_update(e){let i={rerender:!0};return Object.assign(i,e),new Promise((r,n)=>{let s={id:this.id,attributes:{},relationships:{}};if(this.type&&(s.type=this.type),Object.getOwnPropertyNames(this.attributes).forEach(o=>{this.shadow&&this.shadow.attributes[o]!==this.attributes[o]&&(s.attributes[o]=this.attributes[o])}),Object.getOwnPropertyNames(this.relationships).forEach(o=>{if(this.shadow&&this.shadow.relationships[o]!==this.relationships[o]){const h=this.relationships[o];s.relationships[o]=this._serializeRelationshipToWireFormat(h)}}),!Object.getOwnPropertyNames(s.attributes).length&&!Object.getOwnPropertyNames(s.relationships).length){this.syncOp=null,r(this);return}const a=this.adapter.serializeForUpdate(s);if(e&&e.justSimulate){f(a.body),r(this);return}let l=this.updateUrl.toString?this.updateUrl.toString():this.updateUrl;this.storage.update(this,l,{contentType:a.contentType},a.body).then(o=>{let h=this.adapter.parseItemResponse(o.data);Object.assign(this,h),this.shadow=null,i.rerender&&this.views.forEach(d=>{d.render(),this._trigger("afterrender",this,d)}),this._trigger("update",this),this.collection&&this.collection.onupdate(),r(this)}).catch(o=>{f("Update NOK",this.updateUrl,a.body,o),o instanceof Error&&o.jqXHR||o.jqXHR?n(o):n(o instanceof Error?o:new Error(String(o)))})})}update(e,i){if(!e||e.constructor!==Object)return;let r={sync:!0,rerender:!0};i&&i.constructor===Object&&Object.assign(r,i),this.shadow||(this.shadow={attributes:{},relationships:{}},Object.assign(this.shadow.attributes,this.attributes),Object.assign(this.shadow.relationships,this.relationships));const n=(s,a)=>{if(f("update relation",s,a),a===null)return null;if(s&&Array.isArray(s))return Array.isArray(a)?a.map(l=>typeof l=="object"&&l!==null?new R().loadFromData(l):l):(f("to fix: array relationship update"),s);if(typeof a=="object"||a===null){f("Update 1:1 relation");let l=new R().loadFromData(a);return f("relation",l),l}if(typeof a=="string"||typeof a=="number"){if(f("Update 1:1 relation with id",a),s&&s.id&&(s.id===a||String(s.id)===String(a)))return s;const l={id:String(a)};return s&&s.type&&(l.type=s.type),l}return s};return Object.getOwnPropertyNames(this.relationships).forEach(s=>{if(e.hasOwnProperty(s)){if(e[s]===null){this.relationships[s]=null;return}this.relationships[s]=n(this.relationships[s],e[s]),delete e[s]}}),Object.getOwnPropertyNames(e).forEach(s=>{if(e[s]&&typeof e[s]=="object"){!this.strict&&typeof this.relationships[s]>"u"&&(this.relationships[s]=n(this.relationships[s],e[s]));return}if(!this.shadow.attributes.hasOwnProperty(s)){this.strict||(this.attributes[s]=e[s]);return}e[s]!==this.shadow.attributes[s]&&(this.attributes[s]=e[s])}),f("updateOptions",r),r.sync?this.perform_update(r):new Promise(s=>{this.syncOp=()=>this.perform_update(r),this.views.forEach(a=>{r.rerender&&a.render()}),s()})}remove(){return new Promise((e,i)=>{let r=[];for(let s=this.views.length-1;s>=0;s--)r.push(this.views[s].remove());let n=this.collection;n&&r.push(n.removeItem(this)),Promise.all(r).then(()=>{this._trigger("remove",this),n&&(console.log("removed"),n.onupdate())}).finally(()=>e())})}async delete(e){if(!this.deleteUrl)return this.remove();let i={sync:!0};e&&e.constructor===Object&&Object.assign(i,e);try{u("delete",this.deleteUrl.toString()),await this.storage.delete(this,this.deleteUrl.toString(),{}),await this.remove()}catch(r){throw f("Error deleting item",r),r}}render(e,i=!1){return f("Render from item",this),this.views.forEach(r=>{typeof e>"u"?(f("collectionView is undefined so render view"),r.render()):r.container===e&&(f("collectionView matches view container so render view"),r.render(!1,i)),f("trigger afterrender",this,r,r.el),this._trigger("afterrender",this,r)}),this}destroy(){return(this.views?[...this.views]:[]).forEach(i=>{i&&typeof i.destroy=="function"&&i.destroy()}),this.views=[],this.callbacks={},this.collection&&(this.collection=null),this.storage=null,this.url=null,this.updateUrl=null,this.deleteUrl=null,this.attributes={},this.relationships={},this.shadow=null,this.views=[],this}},rt=class{constructor(t={}){this.el=null,this.type="CollectionView",this.container=null,this.collection=null,this.itemsContainer=null,this.allowempty=!0;try{Object.assign(this,w(t))}catch(e){throw new Error("Error on CollectionView init",e)}this.dataBindings=T(this.el)}reset(t){return(this.allowempty||t)&&this.el&&$(this.el).empty(),this}_render(){return f("Render _collectionView",this.collection),this.collection&&this.collection.navtype==="page"&&this.reset(),this.collection&&this.collection.items.length===0?(this.renderEmpty(),this):(this.collection&&this.collection.items.forEach(t=>{t.render(this)}),this)}renderEmpty(){return!this.collection||!this.collection.emptyview?this:(this.reset(),$(this.el).append(this.collection.emptyview),this)}destroy(){if(this.el){const t=$(this.el);t.empty(),t.removeData()}return this.collection=null,this.el=null,this.container=null,this.itemsContainer=null,this.dataBindings=null,this}},st=class{constructor(t,e){this.collection=e,this.el=$(t),this.collection.paging=this,this.iniOffset=(this.collection.offset?this.collection.offset:0)*1,this.defaultPageSize=20,this.pageSize=this.collection.pageSize,this.setupPageSizeInput(),this.setupOffsetInput(),this.buttons=this.extractButtons(),u("buttons",this.buttons),this.setupTotalCount(),this.render()}setupPageSizeInput(){let t=$(this.collection.pagesizeinp);t.length&&(this.collection.setPageSize(t.val()),t.off("change").on("change",()=>{this.collection.setPageSize(t.val())&&this.collection.loadFromRemote()}))}setupOffsetInput(){let t=$(this.collection.offsetinp);t.length&&(this.collection.setOffset(t.val()),t.off("change").on("change",()=>{this.collection.setOffset(t.val())&&this.collection.loadFromRemote()}))}extractButtons(){let t={};const e=$(this.el).find("[name=page]");e.length&&(t.page=e.clone(),e.remove());const i=$(this.el).find("[name=prev]");i.length&&(t.prev=i.clone(),i.remove());const r=$(this.el).find("[name=next]");r.length&&(t.next=r.clone(),r.remove());const n=$(this.el).find("[name=first]");n.length&&(t.first=n.clone(),n.remove());const s=$(this.el).find("[name=last]");return s.length&&(t.last=s.clone(),s.remove()),t}setupTotalCount(){this.$totalCount=$(this.collection.totalrecscount)}clearContainer(){$(this.el).empty(),$(this.el).find("[data-type=pages]").empty()}updateTotalCount(t){this.$totalCount&&this.$totalCount.length&&(this.$totalCount[0].tagName==="INPUT"?this.$totalCount.val(t):this.$totalCount.text(t))}appendButton(t,e,i){let r=t.clone();return i!==void 0&&r.attr("title",i),r.on("click",e),$(this.el).append(r),r}render(){const e=this.collection.total;if(u("Paging render",e,this.buttons),this.updateTotalCount(e),this.clearContainer(),this.iniOffset=this.collection.offset*1,this.collection.pageSize?this.pageSize=this.collection.pageSize:e-this.iniOffset-this.collection.items.length>0?this.pageSize=this.collection.items.length:this.pageSize=this.defaultPageSize,this.pageSize=this.pageSize*1,u("Paging obj",this,this.pageSize,e),this.pageSize>e)return;this.iniOffset>0&&(this.buttons.first&&this.appendButton(this.buttons.first,()=>{this.collection.setOffset(0),this.collection.loadFromRemote()},0),this.buttons.prev&&this.appendButton(this.buttons.prev,()=>{this.collection.setOffset(this.iniOffset-this.pageSize),this.collection.loadFromRemote()},this.iniOffset-this.pageSize));let i=Math.floor(this.iniOffset/this.pageSize)-Math.floor(5/2);i=i<0?0:i;let r=Math.floor(this.iniOffset/this.pageSize)+Math.ceil(5/2);r=r*this.pageSize<e?r:Math.ceil(e/this.pageSize);for(let a=i;a<r;a++){if(!this.buttons.page)continue;const l=a*this.pageSize,o=Math.floor(this.iniOffset/this.pageSize)===a;let h=this.buttons.page.clone();h.text(a+1).attr("title",l).on("click",()=>{this.collection.setOffset(l),this.collection.loadFromRemote()}),o&&h.addClass("active").off("click"),$(this.el).append(h)}const n=this.iniOffset+this.pageSize;if(this.iniOffset+this.pageSize<e&&(this.buttons.next&&this.appendButton(this.buttons.next,()=>{this.collection.setOffset(n),this.collection.loadFromRemote()},n),this.buttons.last)){const a=(Math.ceil(e/this.pageSize)-1)*this.pageSize;u("last button",e,a,this.pageSize,this.offset),a>this.iniOffset*1&&this.appendButton(this.buttons.last,()=>{this.collection.setOffset(a),this.collection.loadFromRemote()},a)}let s=$(this.collection.offsetinp);s.length&&s.val(this.iniOffset)}destroy(){if(this.collection&&this.collection.pagesizeinp&&$(this.collection.pagesizeinp).off("change"),this.collection&&this.collection.offsetinp&&$(this.collection.offsetinp).off("change"),this.el){const t=$(this.el);t.empty(),t.off(),t.removeData()}return this.collection=null,this.el=null,this.buttons=null,this.$totalCount=null,this}},nt=class{constructor(t={}){this.url=null,this.deleteUrl=null,this.insertUrl=null,this.updateUrl=null,this.paging=null,this.view=null,this.offset=0,this.total=null,this.pageSize=10,this.template=null,this.navtype="page",this.type=null,this.emptyview=null,this.items=[],this.addontop=!1,this.uievents=[],this.setAttrAsId=null,this.itemListeners=null,this.adapter=null,this.callbacks={},this.iterator=-1,q("Collection init",t);try{t=w(t)}catch(r){throw new Error("Error on Collection init",r)}Object.defineProperty(this,"length",{get(){return this.items.length},enumerable:!0,configurable:!0});let e=Object.assign({},t);const i={pageSize:e.hasOwnProperty("pageSize"),offset:e.hasOwnProperty("offset")};if(Object.assign(this,e),e.hasOwnProperty("paging")&&$(e.paging).length&&(this.paging=new st($(e.paging)[0],this)),this.url&&this.setUrl(this.url),this.deleteUrl&&this.setUrl(this.deleteUrl,"delete"),this.updateUrl&&this.setUrl(this.updateUrl,"update"),this.insertUrl&&this.setUrl(this.insertUrl,"insert"),this.view&&(this.view.collection=this),this.total&&(this.total=this.total*1),["page","scroll"].indexOf(this.navtype)===-1)throw new Error("Invalid navigations type. Should be page or scroll");if(this.adapter=F(t.adapter),this.url&&this._syncListQueryFromUrl(this.url,i),this.storage=t.hasOwnProperty("storage")?t.storage:new _((()=>{const r=Object.assign({},t.ajaxOpts||{});return t.headers&&typeof t.headers=="object"&&(r.headers=Object.assign({},r.headers||{},t.headers)),r})()),typeof t.listeners=="object")for(let r in t.listeners)this.on(r,t.listeners[r]);t.itemListeners&&typeof t.itemListeners=="object"?this.itemListeners=t.itemListeners:t.itemOn&&typeof t.itemOn=="object"&&(this.itemListeners=t.itemOn)}on(t,e){return typeof this.callbacks[t]>"u"&&(this.callbacks[t]=[]),this.callbacks[t].push(e),this}off(t,e){if(!t)return this.callbacks={},this;if(!this.callbacks[t])return this;if(e){const i=this.callbacks[t].indexOf(e);i>-1&&this.callbacks[t].splice(i,1),this.callbacks[t].length===0&&delete this.callbacks[t]}else delete this.callbacks[t];return this}once(t,e){const i=(...r)=>{e(...r),this.off(t,i)};return this.on(t,i)}hasListeners(t){return this.callbacks[t]&&Array.isArray(this.callbacks[t])&&this.callbacks[t].length>0}_trigger(t,...e){this.callbacks[t]&&Array.isArray(this.callbacks[t])&&this.callbacks[t].forEach(i=>{typeof i=="function"&&i(...e)})}emit(t,...e){return this._trigger(t,...e),this}showlisteners(){f(this.callbacks)}removeItem(t){const e=this.items.findIndex(i=>i===t||i.id&&t.id&&i.id===t.id);return e!==-1&&this.items.splice(e,1),Promise.resolve()}setPageSize(t){return/^\d+$/.test(t)?(this.pageSize=t,!0):!1}empty(){return this.clear()}setOffset(t){return/^\d+$/.test(t)?(this.offset=t,!0):!1}update(t){throw new Error("Not implemented... yet")}setUrl(t,e){if(!t)return this;switch(e){case"delete":this.deleteUrl=c(t);break;case"update":this.updateUrl=c(t);break;case"insert":this.insertUrl=c(t);break;default:u("setUrl",t),this.url=c(t),this.deleteUrl=typeof this.deleteUrl=="string"?c(this.deleteUrl):this.deleteUrl??c(this.url),this.updateUrl=typeof this.updateUrl=="string"?c(this.updateUrl):this.updateUrl??c(this.url),this.insertUrl=typeof this.insertUrl=="string"?c(this.insertUrl):this.insertUrl??c(this.url),this.adapter&&this._syncListQueryFromUrl(this.url);break}return this}_syncListQueryFromUrl(t,e={}){if(!t||!this.adapter||typeof this.adapter.extractListQueryFromUrl!="function")return;const i=this.adapter.extractListQueryFromUrl(t,{type:this.type});i.pageSize!=null&&!e.pageSize&&this.setPageSize(i.pageSize),i.offset!=null&&!e.offset&&(this.offset=i.offset*1)}receiveRemoteData(t){if(f("Remote data received",t),this.adapter.isSingleItemResponse(t)){const r=this.adapter.parseItemResponse(t);this.adapter.applyMetadata(this,this.adapter.extractMetadata(t)),this.items.length===0&&this.view.reset(!0),f("Append single item to collection");let n=this.loadItem(r);return n.render(this.view,this.addontop),this._trigger("afterrender",this),n}const{items:e,meta:i}=this.adapter.parseCollectionResponse(t,{type:this.type});if(this.adapter.applyMetadata(this,i),e!=null&&e.constructor===Array){u("Append multiple items to collection"),this.items.length===0&&this.view.reset(!0);const r=[];return e.forEach(n=>{const s=this.loadItem(n);s&&r.push(s)}),this.render(),r}}extractMetadataAndData(t){return f("extract metadata and data",t),t.hasOwnProperty("data")?(this.adapter.applyMetadata(this,this.adapter.extractMetadata(t)),t.data):t}parse(t){return this.extractMetadataAndData(t)}loadFromData(t){return f("collection load from data",t),t===null||typeof t!="object"||t.constructor!==Array?(f("cannot load ",t," into collection ",this),this):(this.navtype==="page"&&(this.items=[]),t.forEach(e=>{this.loadItem(e)}),this.view?this.view._render():f("collection does not have a view ",this),this._trigger("load",this),this)}next(){this.offset=parseInt(this.offset)+parseInt(this.pageSize),this.loadFromRemote()}prev(){this.offset=parseInt(this.offset)-parseInt(this.pageSize),this.loadFromRemote()}clear(){return this.items=[],this.view&&this.view._render(),this._trigger("update",this),this}render(){return this.view&&this.view._render(),this._trigger("afterrender",this),this}loadFromRemote(){return this.loadFromDataSource()}load(t){return t?this.loadFromData(t):this.loadFromRemote()}loadFromDataSource(){let t=null;if(this.showLoader!==!1&&this.view&&this.view.el){const r=L(this);t=$(r).clone().insertBefore(this.view.el).width($(this.view.el).width()).height($(this.view.el).height())}const i=()=>{t&&$(t).remove()};return this._trigger("beforeload",this),new Promise((r,n)=>{if(!this.url){i(),n(new Error("No valid URL provided"));return}this.adapter.applyListQuery(this.url,{type:this.type,offset:this.offset,pageSize:this.pageSize});let s=this.url.toString?this.url.toString():this.url;this.storage.read(this,s,{}).then(a=>{this.navtype==="page"&&(this.items=[]),this.receiveRemoteData(a.data),this._trigger("load",this),i(),this.paging&&this.paging.render(),r(this)}).catch(a=>{a instanceof Error&&a.jqXHR?(this.fail(a.jqXHR,a.textStatus||"error",a.errorThrown||a),i(),n(a)):a&&a.jqXHR?(this.fail(a.jqXHR,a.textStatus,a.errorThrown),i(),n(a)):(this.fail(null,"error",a),i(),n(a))})})}fail(t,e,i){f("Fail to load collection",t,e,i,this)}onupdate(){return console.log("onupdate"),this._trigger("update",this),this}insert(t){if(Array.isArray(t))throw new Error("insert() expects a single item object. Use batchInsert() for multiple items.");const e=this.adapter.serializeForCreate(t,{type:this.type});return new Promise((i,r)=>{this.insertUrl||(this.insertUrl=this.url);let n=this.insertUrl.toString?this.insertUrl.toString():this.insertUrl;this.storage.create(this,n,{contentType:e.contentType},e.body).then(s=>{let a=s.data,l=this.receiveRemoteData(a);u("newItem",l),this.onupdate(),i(l)}).catch(s=>{f("fail to receive data",s),r(s)})})}batchInsert(t){if(!Array.isArray(t))throw new Error("batchInsert() expects an array of items. Use insert() for a single item.");if(t.length===0)return Promise.resolve([]);const e=this.adapter.serializeForCreate(t,{type:this.type});return new Promise((i,r)=>{this.insertUrl||(this.insertUrl=this.url);let n=this.insertUrl.toString?this.insertUrl.toString():this.insertUrl;this.storage.create(this,n,{contentType:e.contentType},e.body).then(s=>{let a=s.data;const l=this.receiveRemoteData(a),o=Array.isArray(l)?l:l?[l]:[];u("batchInsert newItems",o),this.onupdate(),i(o)}).catch(s=>{f("fail to receive batch data",s),r(s)})})}append(t){return Array.isArray(t)?this.batchInsert(t):this.insert(t)}createItem(t){return this.insert(t)}newItem(t){return this.insert(t)}loadItem(t){if(u("loadItem from collection",t),!t)return u("no item data",t),null;let e={type:this.type,collection:this,uievents:this.uievents,storage:this.storage,adapter:this.adapter};if(this.setAttrAsId&&t.id==null&&(u("set item id from attribute",this.setAttrAsId,t),t.id=t.attributes[this.setAttrAsId]),t.id&&this.url){let r;const n=c(this.url.toString());n.path+="/"+t.id,e.url=c(n.toString());const s=c(this.updateUrl.toString());s.path+="/"+t.id,e.updateUrl=c(s.toString());const a=c(this.deleteUrl.toString());a.path+="/"+t.id,e.deleteUrl=c(a.toString());const l=c(this.insertUrl.toString());l.path+="/"+t.id,e.insertUrl=c(l.toString())}this.itemListeners&&(e.itemListeners=this.itemListeners);let i=new M(e).bindView(new A({template:this.template,container:this.view})).loadFromData(t);return this.addontop?(f("Add on top"),this.items.unshift(i)):this.items.push(i),i}destroy(){return[...this.items].forEach(e=>{e&&typeof e.destroy=="function"&&e.destroy()}),this.items=[],this.view&&typeof this.view.destroy=="function"&&this.view.destroy(),this.view=null,this.filtering&&typeof this.filtering.destroy=="function"&&this.filtering.destroy(),this.filtering=null,this.paging&&typeof this.paging.destroy=="function"&&this.paging.destroy(),this.paging=null,this.callbacks={},this.storage=null,this.url=null,this.deleteUrl=null,this.insertUrl=null,this.updateUrl=null,this.items=[],this.total=null,this.offset=0,this}},at=class{constructor(t,e){this.collection=e,this.el=t;let i=$(t);i.data("instance",e).on("submit",r=>{f("Filter form was submitted"),r.preventDefault(),this.handleSubmit(i[0])}).on("reset",()=>{delete this.collection.url.parameters.filter,this.collection.loadFromRemote(),f("filter form reset")})}handleSubmit(t){let e=[];for(let i=0;i<t.elements.length;i++){let r=t.elements[i],n=$(r),s=n.val(),a=n.data("operator");r.name&&s&&e.push(r.name+(a||"=")+s)}this.collection.offset=0,e.length?this.collection.url.parameters.filter=e.join(","):delete this.collection.url.parameters.filter,this.collection.loadFromRemote()}destroy(){if(this.el){const t=$(this.el);t.off("submit"),t.off("reset"),typeof t.removeData=="function"&&t.removeData("instance")}return this.collection=null,this.el=null,this}},lt=class{constructor(t,e){this.el=t,this.collection=e;const i=t.find("[data-sortfld]").data("instance",this.collection).on("click",this.sortNow.bind(this))}sortNow(t){let e=$(t.currentTarget),i=e.data("sortfld"),r=e.data("sortdir"),n=this.collection,s=n.url.parameters.hasOwnProperty("sort")?n.url.parameters.sort:"",a=[];switch(s.split(",").forEach(function(o){let h=/^(-*)([a-z0-9\-\_]+)$/.exec(o.trim());h&&h[2]!=i&&a.push(o)}),r){case"up":a.push("-"+i),e.data("sortdir","down"),e.find(".sort-up").hide(),e.find(".sort-down").show(),e.find(".sort-default").hide();break;case"down":e.data("sortdir",null),e.find(".sort-up").hide(),e.find(".sort-down").hide(),e.find(".sort-default").show();break;default:e.data("sortdir","up"),a.push(i),e.find(".sort-up").show(),e.find(".sort-down").hide(),e.find(".sort-default").hide()}let l=a.join(",");s!==l&&(n.url.parameters.sort=l,n.loadFromRemote())}destroy(){return this.el&&$(this.el).find("[data-sortfld]").each(function(t){$(this).off("click"),$(this).removeData("instance")}),this}},ot={fillForm:function(t,e){let i=$(t)[0];if($(t).prop("tagName")!=="FORM"||!e||!e.hasOwnProperty("attributes"))return null;Object.getOwnPropertyNames(e.attributes).forEach(r=>{if(!i.elements.hasOwnProperty(r))return;let n=e.attributes[r],s=i.elements[r],a=$(s);e.attributes[r]&&typeof e.attributes[r]=="object"&&e.attributes[r].hasOwnProperty("id")&&(n=e.attributes[r].id),a.attr("type")==="date"&&(n=n&&n.substr(0,10)),a.val(n)}),e.relationships&&Object.getOwnPropertyNames(e.relationships).forEach(r=>{if(!i.elements.hasOwnProperty(r))return;if(!e.relationships[r]){$(i.elements[r]).val(null);return}let n=e.relationships[r],s=i.elements[r];if(n.constructor===Array){let a=[];n.forEach(l=>{a.push(l.id)}),$(s).val(a)}else{if(f("set ",r,n),s.tagName==="SELECT"){let a=$(s).data("label"),l=n.hasOwnProperty("attributes")&&n.attributes[a]?n.attributes[a]:n.id;$("<option>").val(n.id).text(l).appendTo($(s))}$(s).val(n.id)}})},captureFormSubmit:function(t,e){let i=$(t);if(!(i.prop("tagName")!=="FORM"||typeof e!="function"))return i.off("submit").on("submit",r=>{r.preventDefault();let n=i[0];e(this.fetchFormData(n),r)}),i},fetchFormData:function(t){let e=$(t)[0],i={};return Object.getOwnPropertyNames(e.elements).forEach(r=>{let n=e.elements[r],s=$(n);if(!s.attr("name")||s.attr("name")===""||s.attr("type")==="checkbox"&&!s[0].checked)return;let a=s.attr("name"),l=s.val(),o=/(\w+)\[\]/.exec(a);if(o){let h=o[1];i[h]||(i[h]=[]),i[h].push(l)}else i[a]=l}),i},extractFormData:function(t){return this.fetchFormData(t)}},v=class O{static prepareOptions(e,i){if(!e)return f("Warning: no DOM element provided for apiator"),null;typeof i=="string"&&(i={url:i});let r={dataBindings:{},addontop:!1};r=Object.assign(r,$(e).data());try{Object.assign(r,w(i))}catch(n){throw new Error("Error on KViews init",n)}return r}static getOrUpdateInstance(e,i){let r=$(e).data("instance");if(r!==void 0){const n=["url","updateUrl","deleteUrl","insertUrl","template","type","pageSize","offset","emptyview","filter","paging","addontop","uievents","setAttrAsId","itemListeners","itemOn","headers","adapter"];i.url&&(r.setUrl(i.url),delete i.url);const s=w(i),a={};return n.forEach(l=>{s.hasOwnProperty(l)&&(a[l]=s[l])}),Object.assign(r,a),a.adapter&&(r.adapter=F(a.adapter)),a.headers&&r.storage&&r.storage.defaultOptions&&(r.storage.defaultOptions.headers=Object.assign({},r.storage.defaultOptions.headers||{},a.headers)),r}return null}static processEmptyView(e){e.hasOwnProperty("emptyview")&&(e.emptyview=$(e.emptyview).remove())}static finalizeInstance(e,i,r,n){return n&&Object.getOwnPropertyNames(n).forEach(s=>{i.on(s,n[s])}),$(e).data("instance",i),f("instance",i.url),i.url&&(typeof r.dontload>"u"||!r.dontload)&&(u("loadFromRemote now",r,i),i.loadFromRemote()),i}static createCollectionInstance(e,i){let r=O.prepareOptions(e,i);if(u("createCollectionInstance",r),!r)return null;let n=O.getOrUpdateInstance(e,r);if(n)return n;f("init apiator collection on ",e,r),O.processEmptyView(r);let s=r.on;delete r.on,f("Create collection instance",r);let a=$(e).length?$(e).html():null;if(r.template)if(r.template instanceof jQuery){f("template is jQuery object",r.template,e);let h=$(r.template).clone().removeAttr("id");a=$("<div>").append(h).html()}else typeof r.template=="string"&&(f("template is raw text: can be either a jQuery selector or raw HTML",r.template,e),a=$("<div>").append($(r.template).clone().removeAttr("id")).html());a!==null&&(a=a.replace(/</gi,"<").replace(/>/gi,">").replace(/'/gi,"'").replace(/"/gi,'"').replace(/ /gi," ").replace(/&/gi,"&"),r.template=E(a));let l={el:e,itemsContainer:r.hasOwnProperty("container")?$(r.container):e,allowempty:r.disableempty!==!0};r.view=new rt(l),u("Collection constructor",r);let o=new nt(r);if(r.hasOwnProperty("filter")){let h=$(r.filter);h.length&&h.prop("tagName")==="FORM"&&(o.filtering=new at(h,o))}if(r.hasOwnProperty("sort")){u("setup sorting",r.sort);let h=$(r.sort);h.length&&(o.sorting=new lt(h,o))}return O.finalizeInstance(e,o,r,s),o}static createItemInstance(e,i,r=null){let n=O.prepareOptions(e,i);if(!n)return null;let s=O.getOrUpdateInstance(e,n);if(s)return s;f("init apiator item on ",e,n),O.processEmptyView(n);let a=n.on;delete n.on,n.template=null;let l=null;if($(e).length){var o=$(e)[0];l=o?o.outerHTML:null}l&&(l=l.replace(/</gi,"<").replace(/>/gi,">").replace(/'/gi,"'").replace(/"/gi,'"').replace(/ /gi," ").replace(/&/gi,"&"),n.template=E(l));let h=$(e).attr("id"),d=new M(n,r).bindView(new A({template:n.template,el:e,id:h||null}));return O.finalizeInstance(e,d,n,a),n.dontload&&d.attributes&&Object.keys(d.attributes).length>0&&d.render(),d}static helpers=ot;static get defaultAdapter(){return it()}static set defaultAdapter(e){et(e)}static registerAdapter(e,i){tt(e,i)}};Object.defineProperty(v,"baseUrl",{enumerable:!0,configurable:!0,get(){return y.baseUrl},set(t){y.baseUrl=t}}),Object.defineProperty(v,"basePath",{enumerable:!0,configurable:!0,get(){return y.basePath},set(t){y.basePath=t}}),Object.defineProperty(v,"defaultHeaders",{enumerable:!0,configurable:!0,get(){return y.defaultHeaders},set(t){t&&typeof t=="object"&&!Array.isArray(t)?y.defaultHeaders=t:y.defaultHeaders={}}});var ht=v;return typeof window<"u"&&(window.KViews=v),typeof $<"u"&&$.fn&&($.fn.kviews=function(t){let e=this.length?this[0]:this,i="collection";if(t&&t.resourcetype)i=t.resourcetype;else{let r=$(e).data("resourcetype");r&&(i=r)}return i==="item"?v.createItemInstance(e,t):v.createCollectionInstance(e,t)},Object.defineProperty($.fn.kviews,"baseUrl",{enumerable:!0,configurable:!0,get(){return y.baseUrl},set(t){y.baseUrl=t}}),Object.defineProperty($.fn.kviews,"basePath",{enumerable:!0,configurable:!0,get(){return y.basePath},set(t){y.basePath=t}}),Object.defineProperty($.fn.kviews,"defaultHeaders",{enumerable:!0,configurable:!0,get(){return y.defaultHeaders},set(t){t&&typeof t=="object"&&!Array.isArray(t)?y.defaultHeaders=t:y.defaultHeaders={}}}),$.fn.kviewsCollection=function(t){let e={resourcetype:"collection"};return typeof t>"u"&&(t={}),typeof t=="string"&&(t={url:t}),t=Object.assign(t,e),this.kviews(t)},$.fn.kviewsItem=function(t){let e={resourcetype:"item"};return typeof t>"u"&&(t={}),typeof t=="string"&&(t={url:t}),t=Object.assign(t,e),this.kviews(t)}),ht})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logimaxx/kviews.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Class-based JSON:API data binding for the DOM (jQuery, Handlebars, Fetch; collections and items)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -67,11 +67,12 @@
|
|
|
67
67
|
"license": "MIT",
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@playwright/test": "^1.40.0",
|
|
70
|
-
"@vitest/
|
|
71
|
-
"
|
|
70
|
+
"@vitest/coverage-v8": "^3.2.6",
|
|
71
|
+
"@vitest/ui": "^3.2.6",
|
|
72
|
+
"esbuild": "^0.28.1",
|
|
72
73
|
"jsdom": "^23.0.0",
|
|
73
74
|
"rollup": "^4.57.1",
|
|
74
|
-
"vitest": "^
|
|
75
|
+
"vitest": "^3.2.6"
|
|
75
76
|
},
|
|
76
77
|
"peerDependencies": {
|
|
77
78
|
"handlebars": "^4.0.0",
|