UNPKG

shark-mvc

Version:

Shark-MVC is a small MVC framework born to make our small JS apps easier to build.

1 lines 80.8 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("jquery"),require("mustache"),require("moment"),require("preact"),require("preact-html-converter")):"function"==typeof define&&define.amd?define(["jquery","mustache","moment","preact","preact-html-converter"],t):"object"==typeof exports?exports["shark-mvc"]=t(require("jquery"),require("mustache"),require("moment"),require("preact"),require("preact-html-converter")):e["shark-mvc"]=t(e.$,e.Mustache,e.Moment,e.preact,e["preact-html-converter"])}(this,(e,t,r,a,o)=>(()=>{"use strict";var n={274(t){t.exports=e},230(e){e.exports=r},410(e){e.exports=t},524(e){e.exports=a},906(e){e.exports=o}},s={};function i(e){var t=s[e];if(void 0!==t)return t.exports;var r=s[e]={exports:{}};return n[e](r,r.exports,i),r.exports}i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var l={};i.r(l),i.d(l,{Component:()=>H,Controller:()=>I,Jaw:()=>m,ModelRenderer:()=>w,PageTemplate:()=>j,PreactRenderer:()=>F,RenderableJaw:()=>V,Shark:()=>k,SmartModel:()=>b,SwimRoute:()=>M,SwimWay:()=>N,Utils:()=>u,View:()=>U});var c=i(274),d=i.n(c);class p{constructor(){this.__id="Utils"}static parseQueryValue(e){return""===e||isNaN(e)?e:Number(e)}static betterRandom(e,t){let r=parseFloat(e),a=Math.random();return!(t=parseFloat(t))&&e&&(r=0,t=parseFloat(e)),r||(r=0),t||(t=1),a*=t-r,a+=r,a}static betterRandomInt(e,t){return Math.round(p.betterRandom(e,t))}static camelToDashed(e){let t="";return e.split("").forEach((e,r)=>{e.toLowerCase()!==e&&(r>0&&(t+="-"),e=e.toLowerCase()),t+=e}),t}static computeHash(e){return(p.safeStringify(e)||"").split("").reduce(function(e,t){return(e=(e<<5)-e+t.charCodeAt(0))&e},0)}static dashedToCamel(e){let t=e,r=0;for(;r>-1;)r=t.indexOf("-"),r>-1&&(t=t.substr(0,r)+t.substr(r+1,1).toUpperCase()+t.substr(r+2));return t}static decodeHtmlEntities(e){const t={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&apos;":"'","&nbsp;":" "};return e.replace(/&[\w#]+;/g,e=>t[e]??e)}static deepMerge(...e){if(0===e.length)return{};const t={};return e.forEach(e=>{for(let r in e)null!==e[r]&&void 0!==e[r]&&"object"==typeof e[r]?t[r]=p.deepMerge(t[r],e[r]):t[r]=e[r]}),t}static extractDifferentProperties(e,t){const r={};for(let a in e)e[a]&&t[a]&&e[a]!==t[a]&&(r[a]=t[a]);return r}static extractPropertiesFromHTMLString(e){const t=/([\w-]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s>]*)))?(?=\s|>|$)/g,r=e.match(/^<[\w-]+\s+([\s\S]*?)(?:\/>|>)/);if(!r)return{};const a=r[1],o={};let n;for(;null!==(n=t.exec(a));){const e=n[1],t=n[2]??n[3]??n[4]??!0,r=!0===t||p.decodeHtmlEntities(t),a=!0===r||isNaN(r)||""===r?r:Number(r);if(e.startsWith("data-")){const t=e.slice(5).replace(/-([a-z])/g,(e,t)=>t.toUpperCase());o.dataset=o.dataset??{},o.dataset[t]=a}else if(e.startsWith("prop-")){const t=e.slice(5).replace(/-([a-z])/g,(e,t)=>t.toUpperCase());o.props=o.props??{},o.props[t]=a}else o[e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())]=a}return o}static extractSharkComponentTags(e){const t=[],r=/<(shark-[\w-]+)(\s[^>]*)?>/g;let a;for(;null!==(a=r.exec(e));){const o=a[1];if(a[0].trimEnd().endsWith("/>")){t.push(a[0]);continue}const n=`</${o}>`,s=`<${o}`;let i=1,l=a.index+a[0].length;for(;i>0&&l<e.length;){const o=e.indexOf(s,l),c=e.indexOf(n,l);if(-1===c)break;if(-1!==o&&o<c)i++,l=o+s.length;else if(i--,0===i){const o=c+n.length;t.push(e.slice(a.index,o)),r.lastIndex=o}else l=c+n.length}}return t}static flatten(e){const t={};for(var r in e)"function"!=typeof e[r]&&("object"==typeof e[r]?t[r]=p.flatten(e[r]):t[r]=e[r]);return t}static generateGUID(e="",t=""){return e+"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}).toUpperCase()+t}static getDeepProperty(e,t){if(e){const n=t.split(".");for(var r=0;r<n.length-1;r++){var a=-1;if((o=n[r].indexOf("["))>-1&&(a=parseInt(n[r].substring(o+1,n[r].indexOf("]"))),n[r]=n[r].substr(0,o)),-1===a){if(!e[n[r]])break;e=e[n[r]]}else{if(!e[n[r]][a])break;e=e[n[r]][a]}}var o;return a=-1,(o=n[r].indexOf("["))>-1&&(a=parseInt(n[r].substring(o+1,n[r].indexOf("]"))),n[r]=n[r].substr(0,o)),-1===a?e[n[r]]:e[n[r]][a]}}static matchLists(e=[],t={},r={}){e.forEach(e=>{for(const r in e)if("Guid"===r.substr(-2)){const a=r.substr(0,r.length-2),o=t[a];o&&(e[`__${a}`]=p.safp(o,"guid",e[r]))}})}static matchProperties(e,t,r){let a={createMissingProperties:!1,exclude:[],matchEmptyParameters:!0,matchUndefinedParameters:!1};Object.assign(a,r),Array.isArray(a.exclude)||(a.exclude=[]);for(let o in t)(Object.prototype.hasOwnProperty.call(e,o)&&Object.getOwnPropertyDescriptor(e,o).writable||!Object.prototype.hasOwnProperty.call(e,o)&&a.createMissingProperties)&&(0!==a.exclude.length&&-1!==a.exclude.indexOf(o)||void 0===e[o]&&!a.createMissingProperties||!(t[o]&&""!==t[o]||a.matchEmptyParameters)||void 0===t[o]&&!a.matchUndefinedParameters||(Array.isArray(t[o])?e[o]=[...t[o]]:"object"!=typeof t[o]&&"object"!=typeof e[o]||null===t[o]||null===e[o]?e[o]=t[o]:e[o]&&"Object"===e[o].constructor.name&&"Object"===t[o].constructor.name&&Object.keys(e[o]).length>0?p.matchProperties(e[o],t[o],r):e[o]&&"Object"===e[o].constructor.name&&"string"==typeof t[o]?e[o]=d().extend(!0,e[o],p.parseJSON(t[o],"object")):e[o]&&"Array"===e[o].constructor.name&&"string"==typeof t[o]?e[o]=p.parseJSON(t[o],"array"):e[o]=d().extend(!0,{},t[o])))}static mergeAttributes(e,t){const r=p.extractPropertiesFromHTMLString(t);return e.replace(/^(\s*<[\w-]+)((?:\s[^>]*)?)>/,(e,t,a)=>{const o={...p.extractPropertiesFromHTMLString(`${t.trimStart()}${a}>`)};for(const[e,t]of Object.entries(r))"style"===e?o[e]=p.mergeStyle(o[e]||"",t):"class"===e?o[e]=`${o[e]||""} ${t}`.trim():"dataset"===e?o.dataset={...o.dataset,...t}:"props"===e||(o[e]=t);return`${t} ${Object.entries(o).map(([e,t])=>"dataset"===e?Object.entries(t).map(([e,t])=>{const r=e.replace(/([A-Z])/g,(e,t)=>`-${t.toLowerCase()}`);return!0===t?`data-${r}`:`data-${r}="${t}"`}).join(" "):!0===t?e:`${e}="${t}"`).join(" ")}>`})}static mergeStyle(e,t){const r=e=>Object.fromEntries(e.split(";").map(e=>e.trim()).filter(Boolean).map(e=>e.split(":").map(e=>e.trim()))),a={...r(e),...r(t)};return Object.entries(a).map(([e,t])=>`${e}: ${t}`).join("; ")+";"}static moveCaretToEnd(e){setTimeout(function(){if("number"==typeof e.selectionStart)e.selectionStart=e.selectionEnd=e.value.length;else if(void 0!==e.createTextRange){e.focus();var t=e.createTextRange();t.collapse(!1),t.select()}},10)}static objectToFlatMap(e,t=""){return t=""===t?t:t+".",(null!=e?Object.getOwnPropertyNames(e):[]).filter(e=>"__"!==e.slice(0,2)).map(r=>"object"==typeof e[r]?this.objectToFlatMap(e[r],t+r):t+r).flat()}static parseJSON(e,t){if("string"==typeof e&&"array"===e.toLowerCase())return[];if(""===e||'""'===e)return"array"===t?[]:{};if("string"!=typeof e)return void 0===e?"array"===t?[]:{}:e;{let r;try{r=JSON.parse(e)}catch(a){console.error("Utisl.parseJSON",{error:a,data:e,expectedType:t}),r=null}if(null!==r&&""!==r)return"array"===t?"function"==typeof r.splice?r:[]:r;switch(t){case"array":return[];case"object":return{};default:return r}}}static reindexList(e){e.forEach((e,t)=>{e._index=t,e._displayIndex=t+1})}static replaceNullValue(e,t){if(Array.isArray(e))e.forEach(e=>p.replaceNullValue(e,t));else for(let r in e)void 0!==e[r]&&null!==e[r]||(e[r]=t)}static resolveComponentSlots(e,t){const r=/<slot\s+name="[^"]+"/.test(e),a=/\{\{props\./.test(e);if(!r&&!a)return e;const o=t.match(/^<shark-[\w-]+(?:\s[^>]*)?>([\s\S]*)<\/shark-[\w-]+>$/),n=o&&o[1].trim()?o[1]:"",s={};if(n&&n.replace(/<slot\s+name="([^"]+)"\s*>([\s\S]*?)<\/slot>/g,(e,t,r)=>{s[t]=r}),0===Object.keys(s).length&&!a)return e;let i=e.replace(/<slot\s+name="([^"]+)"\s*(?:\/|><\/slot)>/g,(e,t)=>s[t]??e);const l=p.extractPropertiesFromHTMLString(t);return l.props&&Object.keys(l.props).length>0&&(i=i.replace(/\{\{props\.([\w]+)\}\}/g,(e,t)=>l.props[t]??e)),i}static safeStringify(e){return JSON.stringify(e,(e,t)=>(t instanceof Map&&(t=Array.from(t)),"handlerHolder"===e&&(t=null),"__shguid"!==e&&"__"===e.slice(0,2)?void 0:t))}static safp(e,t,r,a){return p.searchArrayForProperty(e,t,r,a)}static searchArrayForProperty(e,t,r,a){if(e){switch(typeof a){case"undefined":a="first";break;case"boolean":a=a?"first":"all"}for(var o,n=[],s=(o=t.indexOf(".")>-1?t.split("."):[t]).length,i=e.length,l=0;l<i;l++){var c=e[l][o[0]];if(c)for(var d=1;d<s&&c[o[d]];d++)c=c[o[d]];if(c===r)switch(a){case"all":n.push(e[l]);break;case"first":return e[l];case"index":return l}}return n.length>0?n:null}console.warn("Error, cant search on a null list.")}static setDeepProperty(e,t,r,a=0){const o=t.split(".");return e[o[a]]||(e[o[a]]={}),a<o.length-1?p.setDeepProperty(e[o[a]],t,r,a+1):e[o[a]]=r,e}static trace(e){try{AppData.consoleDebugActive&&console.debug(e)}catch(t){alert(e)}}static toCamelCase(e){return e.slice(0,1).toLowerCase()+e.slice(1)}static toTitleCase(e,t=!0){return e.slice(0,1).toUpperCase()+(t?e.slice(1).toLowerCase():e.substr(1))}static zeroFill(e,t){let r=e.toString();return r.length<t?r.padStart(t,"0"):r}}const u=p;class h extends EventTarget{#e=[];get activeComponents(){return this.#e}constructor(e,t){if(super(),t&&console.error("Yous must not pass jawDefinition, it's no more supported and it does not have any effect."),"string"!=typeof e)throw new Error("Jaw id must be passed");Object.defineProperty(this,"className",{configurable:!1,enumerable:!0,value:e,writable:!1}),Object.defineProperty(this,"id",{configurable:!1,enumerable:!0,value:e,writable:!1}),Object.defineProperty(this,"addComponents",{configurable:!1,value:this.addComponents,writable:!1}),this.__renderFields=[],this.isInitialized=!1,this.currentOpenOptions={},this.route=null,this.$store={},this.__store={getLabel:function(){return function(e,t){return e.indexOf("{{")>-1&&(e=t(e)),t(k.labels.labels[e])}}},this.__activeComponents=[],this.__autoBoundProperties=[],this.__childTemplates={},this.__dynamicDataBindings={},this.__listeners={},this.__methods={},this.__viewBinds={},this.__viewBinds2={},this.__storeHashMap=new Map}addComponent(e){if(void 0===e)throw new Error("Jaw.addComponent: You can't pass this type of data (must be a component)");if("string"==typeof e&&(console.error("You should avoid to use string to add component. The right way is to pass the Component instance."),e=k.__components[e]),k?.settings?.enableExperimentalComponentProps){if(!this.#e.find(t=>t.id===e.id)){const t=new e.constructor;this.#e.push(t)}}else this.#e.find(t=>t.id===e.id)||this.#e.push(e);return this.#e}addComponents(e){if(!Array.isArray(e))throw new Error("Jaw.addComponents: You can't pass this type of data (must be an Array)");return e.forEach(e=>{this.addComponent(e)}),this.#e}get(e){if(arguments.length>1&&console.warn("WARNING!! The jaw.get() method has deprecated the 'forcedType' parameter, and now works only on jaw-local data"),void 0===e)return this.__store;if(Array.isArray(e)){const t=[];return e.forEach(e=>{const r=this.__store[e];t.push(r)}),t}return this.__store[e]}init(){this.trace("The init method for '"+this.className+"' Jaw has not been implemented. (I'm just setting this as Initialized)","info"),this.isInitialized=!0}_extractComponentsValidMethodList(e,t,r){const a=[];return e.forEach(e=>{-1===t.indexOf(e.id)?(a.push(...this._extractValidMethodList(e)),t.push(e.id)):r.push("= NO "+e.id),e.activeComponents.length>0&&a.push(...this._extractComponentsValidMethodList(e.activeComponents,t,r))}),a}_extractValidMethodList(e){const t=[];for(var r in e)"function"==typeof e[r]&&"Handler"===r.slice(-7)&&(t.find(e=>e.handlerName===r)||t.push({handlerName:r,handlerHolder:e,_from:"_extractValidMethodList-targetObject"}));if(e.__proto__ instanceof h){const r=e.__proto__;Object.getOwnPropertyNames(e.__proto__).forEach(a=>{"function"==typeof r[a]&&"constructor"!==a&&"Handler"===a.slice(-7)&&(t.find(e=>e.handlerName===a)||t.push({handlerName:a,handlerHolder:e,_from:"_extractValidMethodList-referenceObject"}))}),t.push(...this._extractValidMethodList(e.__proto__))}return t}_initComponents(e=null,t=[]){null===e&&(e=this.#e),e.forEach(function(e){this.#e.find(t=>t.id===e.id)||this.#e.push(e),t.includes(e.id)||("function"==typeof e.jawInit&&e.jawInit.call(e,{jaw:currJaw}),"function"!=typeof e.init||e.isInitialized||(e.init.call(e),e.isInitialized=!0),t.push(e.id),e.activeComponents.length>0&&this._initComponents(e.activeComponents,t))},this)}set(e,t){arguments.length>2&&console.error("WARNING!! The Jaw.set() method has been called with more than 2 parameters.");let r=0;if(Array.isArray(e))for(var a=e.length,o=0;o<a;o++){var n=e[o];if(""===n.name)throw new Error("Can't pass an empty 'name' for a property");r+=this.__singleSet(n.name,n.value)}else if("object"==typeof e)for(let t in e)r+=this.__singleSet(t,e[t]);else if("string"==typeof e){if(""===e)throw new Error("Can't pass an empty 'name' for a property");r+=this.__singleSet(e,t)}else console.error("Jaw.set: This kind of data could not be used.");k.trace({__store:this.__store,nameOrItems:e,value:t,type:typeof e},k.TRACE_LOG),k.settings.enableJawStoreAutoRender&&r>0&&(k.trace(`%c SharkMVC: AUTORENDER TRIGGERED by JAW (${r})`,"background-color: red; color: white; font-weight: bold;",{nameOrItems:e,value:t},k.TRACE_INFO),k.render(),k.trace("%c SharkMVC: AUTORENDER COMPLETED by JAW","background-color: red; color: white; font-weight: bold;",k.TRACE_INFO))}__singleSet(e,t){this.__store[e]=t;const r=this;this.$store.hasOwnProperty(e)||Object.defineProperty(this.$store,e,{configurable:!0,enumerable:!0,get:()=>r.__store[e],set(t){const a=r.__store[e];r.__store[e]=t,k.settings.enableJawStoreAutoRender&&u.computeHash(t)!==u.computeHash(a)&&k.render()}});let a=this.__store[e],o=a,n="",s=o!==n;if(void 0!==a)try{o=u.computeHash(a)}catch(e){o=a}if(void 0!==t)try{n=u.computeHash(t)}catch(e){n=t}return s=this.__storeHashMap.has(e)?this.__storeHashMap.get(e)!==n:o!==n,this.__storeHashMap.set(e,n),this.__store[e]=t,s}}h.prototype.emit=function(e,t){return d()(this).trigger(e,t)},h.prototype.off=function(e,t){return d()(this).off(e,t)},h.prototype.on=function(e,t){return d()(this).on(e,t)},h.__getNodeDepth=function(e){let t=0;for(;"BODY"!=e.nodeName;)e=e.parentNode,t++;return t},h.prototype.smartListen2=function(e,t){const r=[];for(let e in this)"function"==typeof this[e]&&e.indexOf("Handler")>-1&&r.push({handlerName:e,handlerHolder:this});this.activeComponents.forEach(e=>{for(let t in e)"function"==typeof e[t]&&t.indexOf("Handler")>-1&&r.push({handlerName:t,handlerHolder:e})}),r.forEach(e=>{let t,r=e.handlerName;t=r.lastIndexOf("_")>-1?r.substr(0,r.lastIndexOf("_")):r;let a=t,o="#"+a,n=!0,s=document.querySelector(o),i="singleNode";if(!s)if(o="."+a,s=document.querySelectorAll(o),0===s.length)k.__controllers[t]?i="manager":n=!1;else{i="multiNode";const t=[];s.forEach(e=>{t.push(h.__getNodeDepth(e))});const r=Math.min(...t);e.depthList=t,e.minDepth=r}if(e.targetType=i,n){let r=!1;"manager"===i&&(e.handlerHolder.__listeners[t]?e.handlerHolder.__listeners[t][eventName]?"component"===e.handlerHolder.type&&(r=!0):r=!0:(r=!0,e.handlerHolder.__listeners[t]={}),r&&(this.trace("Auto-listener assigned to the '"+k.__controllers[t].className+"' Controller for the '"+eventName+"' event.","log"),e.handlerHolder.__listeners[t][eventName]={handler:currHandler,target:"controller",type:"autoListener"},"component"===e.handlerHolder.type&&d()(k.__controllers[t]).off(eventName,e.handlerHolder[currHandler]),d()(k.__controllers[t]).on(eventName,e.handlerHolder[currHandler])))}},this),this.trace("Jaw.prototype.smartListen2: validMethodList",r,"log")},h.prototype.smartListen=function(e,t){void 0===t&&(t=!1);var r=this._extractValidMethodList(this);this.trace("smartListen",{__validMethodList:this.__validMethodList,jaw:this},"log");const a=[],o=[];r.push(...this._extractComponentsValidMethodList(this.activeComponents,a,o)),this.trace("Jaw.prototype.smartListen: data",{processedComponentList:a,__activeComponents:this.activeComponents,notProcessedComponentList:o,validMethodList:r},"log"),this.trace("Jaw.prototype.smartListen: validMethodList",r,"log"),this.__validMethodList=r,r.forEach(function(r){var a,o=r.handlerName,n=!0;a=o.indexOf("_")>-1?o.substr(0,o.indexOf("_")):o;var s=r.handlerHolder.className+"_"+a,i="#"+s,l=o.substring(o.indexOf("_")+1,o.indexOf("Handler")),c=d()(i);if(e){var p=d()(e);t&&"#"+a===e?(this.trace(c,p,"log"),c=p):(0===(c=p.find(i)).length&&(i="#"+a,c=p.find(i)),0===c.length&&(i="."+s,c=p.find(i)),0===c.length&&(i="."+a,c=p.find(i)),c.selector!==p.selector&&0===c.closest(p).length&&(n=!1))}else 0===c.length&&(i="#"+a,c=d()(i)),0===c.length&&(i="."+s,c=d()(i)),0===c.length&&(i="."+a,c=d()(i));if(n){var u=!1;if(c.length>0){if(r.handlerHolder.__listeners||(r.handlerHolder.__listeners={}),r.handlerHolder.__listeners[i]?r.handlerHolder.__listeners[i][l]?"component"===r.handlerHolder.type&&(u=!0):u=!0:(u=!0,r.handlerHolder.__listeners[i]={}),u){this.trace("Auto-listener assigned to '"+i+"' item of the '"+r.handlerHolder.className+"' "+r.handlerHolder.type+" for the '"+l+"' event.","log");var h=function(e){e.data.handler.call(r.handlerHolder,e,this.dataset)};"component"===r.handlerHolder.type&&r.handlerHolder.__listeners[i][l]&&r.handlerHolder.__listeners[i][l].handler&&c.off(l,r.handlerHolder.__listeners[i][l].handler),r.handlerHolder.__listeners[i][l]={context:"jaw",handler:h,originalHandler:o,target:"DOM",type:"autoListener"},c.on(l,{handler:r.handlerHolder[o],handlerHolder:r.handlerHolder},h),r.handlerHolder.__methods||(r.handlerHolder.__methods={}),r.handlerHolder.__methods[o]&&r.handlerHolder.__methods[o].settings&&void 0!==r.handlerHolder.__methods[o].settings.smartUnlisten&&(r.handlerHolder.__listeners[i][l].smartUnlisten=r.handlerHolder.__methods[o].settings.smartUnlisten)}}else k.__controllers[a]?(r.handlerHolder.__listeners[a]?r.handlerHolder.__listeners[a][l]?"component"===r.handlerHolder.type&&(u=!0):u=!0:(u=!0,r.handlerHolder.__listeners[a]={}),u&&(this.trace("Auto-listener assigned to the '"+k.__controllers[a].className+"' Controller for the '"+l+"' event.","log"),r.handlerHolder.__listeners[a][l]={handler:o,target:"controller",type:"autoListener"},"component"===r.handlerHolder.type&&d()(k.__controllers[a]).off(l,r.handlerHolder[o]),d()(k.__controllers[a]).on(l,r.handlerHolder[o]))):k.__components[a]&&(r.handlerHolder.__listeners[a]?r.handlerHolder.__listeners[a][l]?"component"===r.handlerHolder.type&&(u=!0):u=!0:(u=!0,r.handlerHolder.__listeners[a]={}),u&&(this.trace("Auto-listener assigned to the '"+k.__components[a].className+"' Component for the '"+l+"' event.","log"),r.handlerHolder.__listeners[a][l]={handler:o,target:"component",type:"autoListener"},r.handlerHolder[o]=r.handlerHolder[o].bind(r.handlerHolder),d()(k.__components[a]).off(l,r.handlerHolder[o]),d()(k.__components[a]).on(l,r.handlerHolder[o])))}else this.trace("Auto-listener not assigned for the '"+l+"' event because of the container selector. The target: ",c,"log")},this)},h.prototype.smartUnlisten=function(e){this.trace("smartUnlisten",{__validMethodList:this.__validMethodList},"log"),this.__validMethodList&&this.__validMethodList.forEach(e=>{for(var t in e.handlerHolder.__listeners){var r=e.handlerHolder.__listeners[t];for(var a in r){var o=r[a];if(!0===o.smartUnlisten||void 0===o.smartUnlisten){switch(o.target){case"DOM":d()(t).off(a,e.handlerHolder[o.handler]);break;case"component":d()(k.__components[t]).off(a,e.handlerHolder[o.handler]);break;case"controller":d()(k.__components[t]).off(a,e.handlerHolder[o.handler]),d()(k.__controllers[t]).off(a,e.handlerHolder[o.handler])}delete e.handlerHolder.__listeners[t][a]}}delete e.handlerHolder.__listeners[t]}})},h.prototype.trace=function(e,t){k&&k.trace&&k.trace(e,t)},h.prototype.updateDisplay=function(e,t){throw k.get(e,"appData"),console.warn("UPDATE DISPLAY!!!!!!"),new Error("UPDATE DISPLAY!!!!!!")};const m=h;var f=i(410),_=i.n(f),g=i(230),y=i.n(g);const w=class{#t=new Set;#r="";constructor(e){this.model=e,this.parseModelValues()}cssClasses(){return this.#r}addClasses(...e){console.log({classes:e,arguments}),Array.isArray(e)||(e=[e]),e.forEach(e=>this.#t.add(e)),this.#a()}removeClasses(...e){Array.isArray(e)||(e=[e]),e.forEach(e=>this.#t.delete(e)),this.#a()}#a(){this.#r=[...this.#t].map(e=>e+" ").join("")}#o(){for(let e in this.model)"function"!=typeof this.model[e]&&(this[e]=this.model[e])}parseModelValues(e){return this.#o(e)}setModel(e){this.model=e}};class v extends EventTarget{#n={};#s={};__modelName="";constructor(e,t,r){super(),Object.defineProperties(this,{__shguid:{value:u.generateGUID(),writable:!1}}),r&&u.matchProperties(this,r,{createMissingProperties:!0,matchEmptyParameters:!0}),Object.defineProperties(this,{__clean:{value:e=>(this.__dirtyProperties=e?this.__dirtyProperties.filter(t=>-1===e.indexOf(t.property)):[],this.__isDirty=this.__dirtyProperties.length>0,this.__dirtyProperties),writable:!1},__export:{value:e=>{const t={};if(e&&e.hasOwnProperty("fields"))e.fields.forEach(e=>{this.hasOwnProperty(e)&&(t[e]=this[e])});else for(let e in this)"function"!=typeof this[e]&&"__"!==e.slice(0,2)&&"jQuery"!==e.slice(0,6)&&(t[e]=this[e]);return t},writable:!1},__import:{value:(e,t)=>{const r=Object.assign({createMissingProperties:!1,matchEmptyParameters:!0},t);return u.matchProperties(this,e,r)},writable:!1},__restore:{value:e=>{e||([...this.__dirtyProperties].forEach(e=>{this.set(e.property,e.originalValue)}),this.__dirtyProperties=[],this.__isDirty=!1)},writable:!1},__setPropertyDirtiness:{value:(e,t)=>{const r=this.__dirtyProperties.findIndex(t=>t.property===e);if(-1===r)this.__dirtyProperties.push({property:e,originalValue:t.oldValue});else if(t.newValue===this.__dirtyProperties[r].originalValue)this.__dirtyProperties.splice(r,1);else if(Array.isArray(t.newValue)&&Array.isArray(this.__dirtyProperties[r].originalValue))try{u.computeHash(t.newValue)===u.computeHash(this.__dirtyProperties[r].originalValue)&&this.__dirtyProperties.splice(r,1)}catch(e){console.error(e)}},writable:!1},__toJSON:{value:e=>{"boolean"==typeof e||(e=!1);var t={};for(var r in this)"function"==typeof this[r]||this[r]instanceof Element||"__"===r.slice(0,2)&&"__shguid"!==r&&!e||"jQuery"===r.slice(0,6)||(t[r]=this[r]);return t},writable:!1}}),Object.defineProperties(this,{__dirtyProperties:{value:[],writable:!0}}),this.__boundProperties=[],this.__isDirty=!1,this.__modelStructure=r,this.__renderer=new w(this)}addRenderer(e){this.__renderer=this.__=e,this.__renderer.setModel(this)}clean(e){return this.__clean(e)}emit(e,t){return d()(this).trigger(e,t)}export(e){return this.__export(e)}exportArrayField(e,t="JSON"){return this.__exportArrayField(e,t)}__exportArrayField(e,t="JSON"){const r=u.getDeepProperty(this,e);let a;return"JSON"===t&&(a=JSON.stringify(r)),a}exportBooleanField(e,t="number"){return this.__exportBooleanField(e,t)}__exportBooleanField(e,t="number"){const r=u.getDeepProperty(this,e);let a;switch(t){case"number":a=!0===r?1:0;break;case"string":a=r.toString()}return a}exportDateField(e,t="ISO",r=!0){return this.__exportDateField(e,t,r)}__exportDateField(e,t="ISO",r=!0){const a=u.getDeepProperty(this,e);let o;const n=y()(a);return o=n.isValid()?r?n.utc().format("YYYY-MM-DD HH:mm:ss"):n.format("YYYY-MM-DD HH:mm:ss"):"0000-00-00 00:00:00",o}exportNumberField(e,t){return this.__exportNumberField(e,t)}__exportNumberField(e,t){const r=u.getDeepProperty(this,e);let a;return"number"==typeof r?a=r:"string"==typeof r&&(a=parseFloat(r)),a}exportObjectField(e,t="JSON"){return this.__exportObjectField(e,t)}__exportObjectField(e,t="JSON"){const r=u.getDeepProperty(this,e);let a;return"JSON"===t&&(a=JSON.stringify(r)),a}import(e,t){return this.__import(e,t)}importBooleanField(e,t){return this.__importBooleanField(e,t)}__importBooleanField(e,t){if(void 0===t||null==t)return!1;let r,a=!1;return"number"==typeof t?(r=1===t,a=!0):"string"==typeof t?(r="false"!==t.toLowerCase()&&(1===parseInt(t)||"true"===t.toLowerCase()),a=!0):"boolean"==typeof t&&(r=t,a=!0),a&&u.setDeepProperty(this,e,r),a}importDateField(e,t,r=!0){return this.__importDateField(e,t,r)}__importDateField(e,t,r){if(void 0===t||null==t)return!1;let a;return a=r?y().utc(t).local():y()(t),u.setDeepProperty(this,e,a),a.isValid()}importNumberField(e,t,r){return this.__importNumberField(e,t,r)}__importNumberField(e,t,r){if(void 0===t||null==t)return!1;let a;return"number"==typeof t?a=t:"string"==typeof t&&(a=parseFloat(t)),isNaN(a)?void 0!==r&&"number"==typeof r&&(u.setDeepProperty(this,e,r),!0):(u.setDeepProperty(this,e,a),!0)}importField(e,t,r){if(r=Object.assign({acceptUndefined:!1,dataType:"auto",defaultValue:void 0,useUTC:!0},r),(void 0===t||null==t)&&!r.acceptUndefined)return!1;switch(r.dataType){case"auto":break;case"boolean":return this.importBooleanField(e,t);case"date":return this.importDateField(e,t,r.useUTC);case"number":return this.importNumberField(e,t,r.defaultValue)}return!0}static inferTypes(){const e=new this,t={};console.log("Inferring types for",this.name);for(let r in e)if("__"!==r.slice(0,2)&&"_"!==r.slice(0,1))switch(console.log(r,e[r]),e[r]){case 0:case-1:t[r]="number";break;case"0000-00-00 00:00:00":case"0000-00-00":t[r]="datetime";break;case!0:case!1:t[r]="boolean";break;case"":t[r]="string";break;default:Array.isArray(e[r])?t[r]="array":e[r].constructor===Object?t[r]="object":e[r].prototype instanceof v&&(t[r]=e[r])}this.inferTypes=t,console.log("Inferred types",t,this)}isDirty(e=null,t="any"){return null==e?this.__isDirty:(Array.isArray(e)||(e=[e]),"any"===t?this.__dirtyProperties.filter(t=>e.includes(t.property)).length>0:"all"===t?this.__dirtyProperties.filter(t=>e.includes(t.property)).length===e.length:void 0)}off(e,t){return delete this.#s[e],d()(this).off(e,t)}on(e,t){return d()(this).on(e,t)}registerBoundProperty(e,t){this.#n[e]||(this.#n[e]=new Set),this.#n[e].add(t)}restore(e){this.__restore(e)}__singleSet(e,t,r){let a=u.getDeepProperty(this,e);const o=u.computeHash(a);let n=!0;switch(typeof a){case"number":k.trace("%cChiamato il metodo set e la propietà è di tipo "+typeof a,"font-size: 16px; color: red;",k.TRACE_LOG),t=parseFloat(t);break;case"object":if(Array.isArray(a)&&!Array.isArray(t)){let e=Array.from(a),r=e.indexOf(t);if(r>-1)e.splice(r,1);else{let r=e.indexOf(parseFloat(t));r>-1?e.splice(r,1):e.push(t)}t=e,k.trace(`%cChiamato il metodo set e la propietà è di tipo ${typeof e} ed è un array`,"font-size: 16px; color: red;",k.TRACE_LOG)}else k.activeFeatures.moment&&(a._isAMomentObject||a instanceof y())?(k.trace(`%cChiamato il metodo set e la propietà è di tipo ${typeof a} ed è un moment`,"font-size: 16px; color: red;",k.TRACE_LOG),t=y()(t)):k.trace("%cChiamato il metodo set e la propietà è di tipo "+typeof a,"font-size: 16px; color: red;",k.TRACE_LOG);if(Array.isArray(a)&&Array.isArray(t))try{n=o!==u.computeHash(t)}catch(e){console.error(e)}break;case"string":k.trace("%cChiamato il metodo set e la propietà è di tipo "+typeof a,"font-size: 16px; color: red;",k.TRACE_LOG),void 0!==t?"function"==typeof t.toString&&(t=t.toString()):t=""}var s={modelName:this.__modelName,newValue:t,oldValue:u.getDeepProperty(this,e),property:e};if(u.setDeepProperty(this,e,t),s.oldValue!==s.newValue&&n){this.__setPropertyDirtiness(e,s),this.__isDirty=this.__dirtyProperties.length>0,k.settings.enableSmartModelSetUpdatesView&&this.updateScreenWithModelValue(e,r,t,s),"function"==typeof this.onDataChanged&&this.onDataChanged.call(this,s);const a=u.toTitleCase(e,!1).replace(/\./g,"_");return"Data"!==a&&a!==e&&"function"==typeof this["on"+a+"Changed"]&&this["on"+a+"Changed"].call(this,s),this.emit("dataChanged",s),"data"!==e&&this.emit(e+"Changed",s),this.#n?.[e]?.has[k.activePage.id]}return!1}set(e,t,r){let a=0;if(Array.isArray(e))e.forEach(e=>{a+=this.__singleSet(e.name,e.value,r)});else if("object"==typeof e)for(let t in e)a+=this.__singleSet(t,e[t],r);else"string"==typeof e?a+=this.__singleSet(e,t,r):console.error("Shark.set: This kind of data could not be used.");this.__renderer&&"function"==typeof this.__renderer.parseModelValues&&this.__renderer.parseModelValues({name:e,value:t}),k.settings.enableSmartModelSetUpdatesView&&a>0&&(console.log("%cAvrei renderizzato per SmartModel","background-color: red; color: white; font-weight: bold;",this,e,t),k.trace(`%c SharkMVC: AUTORENDER TRIGGERED by SmartModel (${a})`,"background-color: red; color: white; font-weight: bold;",{name:e,value:t},k.TRACE_INFO),k.trace("%c SharkMVC: AUTORENDER COMPLETED by SmartModel","background-color: red; color: white; font-weight: bold;",k.TRACE_INFO))}toJSON(e){return this.__toJSON(e)}toString(e){return JSON.stringify(this.toJSON(e))}updateScreenWithModelValue(e,t,r,a){document.querySelectorAll(`[data-sh-prop="${e}"]`).forEach(e=>{if(e!==t){const t=e.closest("[data-shguid]");let o=t?t.dataset.shguid:"";if(""===o||o===this.__shguid){let t=!1,o=!1;switch(e.nodeName.toUpperCase()){case"INPUT":switch(e.type.toUpperCase()){case"CHECKBOX":case"RADIO":break;default:t=!0}break;case"SELECT":case"TEXTAREA":t=!0;break;default:o=!0}t?e.value=r:o?e.innerHTML=r:k.trace("Non aggiorno il valore",{eventData:a},k.TRACE_LOG)}}})}updateScreenWithModelValues(){for(let e in this)k.trace("updateScreenWithModelValues",{currProp:e,value:this[e]},k.TRACE_LOG),this.updateScreenWithModelValue(e,null,this[e],"no event")}}const b=v;var R,P=function(){if(void 0===_())throw new Error("Mustache is needed to use MustacheRenderer!")};P.prototype.render=function(e,t){if(console.time("MustacheRenderer.render"),k.trace("MustacheRenderer.render: ",e,t,k.TRACE_INFO),t=d().extend({renderOnScreen:!0},t),!e.__templateParsed){for(var r=e.templateContent,a=0,o=r.match(/{{>[\w\.]+\}\}/g);o&&a<100;)o.forEach(function(e){var t=e.replace("{{>","").replace("}}","");t?r=r.replace(e,k.getTemplate(t)):k.trace("MustacheRenderer.render > Missing SubTemplate: "+t,k.TRACE_ERROR)}),o=r.match(/{{>[\w\.]+\}\}/g),a++;for(var n=r.match(/{{=>[\w\.]+\}\}/g);n;)n.forEach(function(e){let t=!0,a=e.replace("{{=>","").replace("}}","");a.indexOf(".")>-1&&(a=a.substr(0,a.indexOf(".")),t=!1);let o=k.__components[a];if(o){if(t&&(r=r.replace(e,o.templateContent)),o.__templates)for(let e in o.__templates)r=r.replace(`{{=>${a}.${e}}}`,o.__templates[e])}else k.trace("MustacheRenderer.render > Missing component: "+a,k.TRACE_ERROR),r=r.replace(e,e.replace("{{=>","{{>"))}),n=r.match(/{{=>[\w\.]+\}\}/g);let t=new RegExp(/<shark-[\w]+.+\/*>/g),s=r.match(t);for(;s;)s.forEach(function(e){let t=e,a="";t.indexOf("></shark-")>-1&&(t=t.substr(0,t.indexOf("></shark-"))),t.indexOf("/>")>-1&&(t=t.substr(0,t.indexOf("/>"))),t.indexOf(">")>-1&&(t=t.substr(0,t.indexOf(">"))),t.indexOf(" ")>-1&&(t=t.substr(0,t.indexOf(" "))),t=t.replace("<shark-",""),t.indexOf("-")>-1&&(t=u.dashedToCamel(t));let o=e.indexOf('template="');o>-1&&(a=e.substring(o+10,e.indexOf('"',o+11)),"default"===a&&(a=""));let n=k.__components[t];n?""===a?r=r.replace(e,n.templateContent):n.__templates&&n.__templates[a]&&(r=r.replace(e,n.__templates[a])):(k.trace("MustacheRenderer.render > Missing component: "+t+", removing from template.",k.TRACE_ERROR),r=r.replace(e,""))}),s=r.match(t);r=r.replace(/data-sh-model=\"(.\S+)\"/g,'$& data-shguid="{{$1.__shguid}}"'),e.__autoBoundListSection=[];const i=r.match(/{{\[\>[\w\.]+\}\}/g);i&&(i.forEach(t=>{const a=t.replace("{{[>","").replace("}}","");let o=new RegExp("{{\\[\\>"+a+"\\}\\}([\\s\\S]*){{"+a+"\\<\\]\\}\\}","g").exec(r)[1];const n=o.indexOf(">");o=o.substr(0,n)+' data-shguid="{{__shguid}}"'+o.substr(n),console.log({listSection:t}),e.__autoBoundListSection.push({propertyName:a,template:o});const s=new RegExp("{{\\[\\>("+a+")\\}\\}","g"),i=new RegExp("{{("+a+")\\<\\]\\}\\}","g");r=(r=r.replace(s,'<shark-list property="'+a+'">{{#$1}}')).replace(i,"{{/$1}}</shark-list>")}),console.log({__autoBoundListSection:e.__autoBoundListSection})),console.time("autoBind"),k.trace({renderField:r.match(/{{[\w\.]+\}\}/g),renderListOrPresence:r.match(/{{#[\w\.]+\}\}/g),renderAbsence:r.match(/{{\^[\w\.]+\}\}/g)},k.TRACE_LOG),k.trace({renderField:[...new Set(r.match(/{{[\w\.]+\}\}/g))].map(e=>e.replace("{{","").replace("}}","")),renderListOrPresence:[...new Set(r.match(/{{#[\w\.]+\}\}/g))].map(e=>e.replace("{{#","").replace("}}","")),renderAbsence:[...new Set(r.match(/{{\^[\w\.]+\}\}/g))].map(e=>e.replace("{{^","").replace("}}",""))},k.TRACE_LOG);const l=[...[...new Set(r.match(/{{[\w\.]+\}\}/g))].map(e=>e.replace("{{","").replace("}}","")),...[...new Set(r.match(/{{#[\w\.]+\}\}/g))].map(e=>e.replace("{{#","").replace("}}","")),...[...new Set(r.match(/{{\^[\w\.]+\}\}/g))].map(e=>e.replace("{{^","").replace("}}",""))];k.__autoBoundProperties=[];for(const t in k.__store)l.indexOf(t)>-1&&(k.__autoBoundProperties.push(t),e.__autoBoundProperties.push(t));k.trace({renderField:l,SharkAutoBoundProperties:k.__autoBoundProperties,JawAutoBoundProperties:e.__autoBoundProperties}),console.timeEnd("autoBind");for(const e in k.__store)k.__store[e]instanceof b&&(k.__store[e].__boundProperties=[]);const c=r.match(/{{[\w\.]+\}\}/g);c&&c.length>0&&c.forEach(e=>{const t=e.replace("{{","").replace("}}","").split("."),r=k.get(t[0]);r&&r instanceof b&&-1===r.__boundProperties.indexOf(t[1])&&(r.__boundProperties.push(t[1]),k.trace("dynamicFields",r,"log"))}),k.__dynamicSections={};const d=r.match(/\<shark-section(.*?)\>/g);d&&d.length>0&&(d.forEach(e=>{const t=e,a="</shark-section>",o={closeTag:a,openTag:t,rGuid:k.__generateGUID("rid_"),storeReference:/model=\"(.*?)\"/g.exec(e)[1]};var n=new RegExp(t+"(.*?)"+a.replace("/","/"),"gs");o.templateContent=n.exec(r)[1],r=window.customElements?r.replace(e,`<shark-section data-sh-rguid='${o.rGuid}'>${t}`).replace(a,`${a}</shark-section>`):r.replace(e,`<span data-sh-rguid='${o.rGuid}'>${t}`).replace(a,`${a}</span>`),k.__dynamicSections[o.storeReference]?k.__dynamicSections[o.storeReference].push(o):k.__dynamicSections[o.storeReference]=[o]}),k.trace("dynamicSections",k.__dynamicSections,"log")),r=r.replace(/\[\[([\w\.]+)\]\]/g,"{{{__renderer.$1}}}"),e.__parsedTemplate=r,e.__templateParsed=!0}const s={},i=[];e.activeComponents.forEach(e=>{-1===i.indexOf(e.id)&&Object.assign(s,e.__store),e.activeComponents.forEach(e=>{-1===i.indexOf(e.id)&&Object.assign(s,e.__store)})});const l=d().extend({},k.__templateMap,e.__childTemplates),c=Object.assign({},k.__store,s,e.__store),p=_().render(e.__parsedTemplate,c,l);if(!t.renderOnScreen)return console.timeEnd("MustacheRenderer.render"),p;d()(t.container).html(p),console.timeEnd("MustacheRenderer.render")},P.prototype.renderItem=function(e){if(!e.templateSource)throw new Error("MustacheRenderer.renderItem: To render an item you must specify the template parameter");var t={append:!1,childTemplates:{},containerSelector:"",renderItems:{},replace:!1,templateSource:null};if(d().extend(!0,t,e),k.trace("MustacheRenderer.renderItem",t,k.TRACE_INFO),e.replace&&""===e.containerSelector)throw new Error("Could not use replace parameter without setting a containerSelector!");var r=d().extend({},k.__templateMap,t.childTemplates),a=_().render(t.templateSource,t.renderItems,r);if(""===e.containerSelector||!e.containerSelector)return a;e.append?d()(e.containerSelector).append(a):e.replace?d()(e.containerSelector).replaceWith(a):d()(e.containerSelector).html(a)};var C=new Uint8Array(16);function O(){if(!R&&!(R="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return R(C)}const T=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var E=[],S=0;S<256;++S)E.push((S+256).toString(16).substr(1));const x=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(E[e[t+0]]+E[e[t+1]]+E[e[t+2]]+E[e[t+3]]+"-"+E[e[t+4]]+E[e[t+5]]+"-"+E[e[t+6]]+E[e[t+7]]+"-"+E[e[t+8]]+E[e[t+9]]+"-"+E[e[t+10]]+E[e[t+11]]+E[e[t+12]]+E[e[t+13]]+E[e[t+14]]+E[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&T.test(e)}(r))throw TypeError("Stringified UUID is invalid");return r},A=function(e,t,r){var a=(e=e||{}).random||(e.rng||O)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,t){r=r||0;for(var o=0;o<16;++o)t[r+o]=a[o];return t}return x(a)},M=class{#i={};#l={};route="";url="";view=null;get params(){return this.#i}get queryParams(){return this.#l}constructor(e){this.route=e.route,this.view=e.view}extractRouteParams(e){e||(e=this.url);const t=this.route.replace(/\/$/,"").split("?")[0],r=e.replace(/\/$/,"").split("?")[0],a=t.split("/").filter(Boolean),o=r.split("/").filter(Boolean);if(a.length!==o.length)return;const n={};for(let e=0;e<a.length;e++){const t=a[e],r=o[e];if(t.startsWith(":"))n[t.slice(1)]=r;else if(t!==r)return}this.#i=n}extractQueryParams(e=document.location.search){const t={};for(const[r,a]of new URLSearchParams(e))t[r]=u.parseQueryValue(a);this.#l=t}},N=class{#c=null;#d=[];get currentRoute(){return this.#c}constructor(e="pathname"){this.routingMethod=e}addRoute(e){return this.#d.push(e instanceof M?e:new M(e)),this.#d.length}addRoutes(e){return this.#d.push(...e.map(e=>e instanceof M?e:new M(e))),this.#d.length}getQueryParam(e){return this.getQueryParams().get(e)}getQueryParams(){return new URLSearchParams(document.location.search)}get queryParams(){const e={};for(const[t,r]of new URLSearchParams(document.location.search))e[t]=u.parseQueryValue(r);return e}getRequestedViewFromLocation({includeRootSlash:e}={includeRootSlash:!1}){let t=["url","pathname"].includes(this.routingMethod)?document.location.pathname:document.location.hash;return""===t||e||(t=t.slice(1)),t}getRoute(){return this.#c?.extractRouteParams(document.location.pathname),this.#c?.extractQueryParams(),this.#c}navigateTo(e){if("string"==typeof e){const t=this.#c?.url,r=this.findCurrentRoute(e);if(r){const e={route:{...r}};delete e.route.view,this.#c===r&&t===r.url||(this.#c=r,k.openPage(r.view,e))}else{const t=this.#d.find(t=>t.route===e||t.name===e);if(t){this.#c=t;const e={route:{...t}};delete e.route.view,k.openPage(t.view,e)}else this.#c=null,k.openPage(e)}return!0}if(e instanceof m)return this.#c=null,k.openPage(e),!0;if(e instanceof M)return this.#c=this.findCurrentRoute(),k.navigateToRoute(e),!0;if("object"==typeof e){this.#c=null;let t=e.route,r={};const a={route:{...e}};return delete a.route.view,"string"==typeof t&&(r=this.#d.find(e=>e.route===t||e.name===t)||{},this.#c=r),k.openPage(e.view||r.view||t,a),!0}return!1}setQueryParams(e){const t=new URL(window.location);if(null===e)t.searchParams.forEach((e,r)=>t.searchParams.delete(r));else if("object"==typeof e)for(let r in e)t.searchParams.set(r,e[r]);if("function"==typeof history.replaceState){const r={queryParams:e};history.replaceState(r,"",t)}}setURLSearchParams(e=null){const t={urlSearchParams:e},r=new URL(window.location);if(null===e)r.searchParams.forEach((e,t)=>r.searchParams.delete(t));else if("string"==typeof e&&""!==e)e.split("&").forEach(e=>{const t=e.split("=");r.searchParams.set(t[0],t[1])});else if("object"==typeof e)for(let t in e)r.searchParams.set(t,e[t]);"function"==typeof history.replaceState&&(["url","pathname"].includes(this.routingMethod)?r.pathname=r.pathname.slice(0,r.pathname.lastIndexOf("/"))+"/"+destinationViewURL:r.hash=destinationViewURL,history.replaceState(t,"",r))}findMatchingRoute(e){const t=e.replace(/\/$/,"").split("?")[0];for(const e of this.#d){const r=e.route.replace(/\/$/,"").split("?")[0].split("/").filter(Boolean),a=t.split("/").filter(Boolean);if(r.length!==a.length)continue;let o=!0;for(let e=0;e<r.length;e++){const t=r[e],n=a[e];if(!t.startsWith(":")&&t!==n){o=!1;break}}if(o)return e}return null}findCurrentRoute(e){e||(e=this.getRequestedViewFromLocation({includeRootSlash:!0}));const t=this.findMatchingRoute(e);return t&&(t.url=e,t.extractRouteParams(e),t.extractQueryParams()),t}initLinkInterception(e={}){const{preventDefault:t=!0,onRouteNotFound:r=null}=e;document.addEventListener("click",e=>{const a=e.target.closest("a");if(!a)return;const o=a.getAttribute("href");if(!o)return;if(!o.startsWith("/")||o.startsWith("//"))return;if(a.hasAttribute("data-no-route")||"_blank"===a.getAttribute("target"))return;const n=this.findMatchingRoute(o);n?(t&&e.preventDefault(),this.navigateTo(n),"function"==typeof history.pushState&&history.pushState({route:o},"",o)):r&&(e.preventDefault(),r(o,e))}),window.addEventListener("popstate",e=>{const t=this.getRequestedViewFromLocation({includeRootSlash:!0}),r=this.findMatchingRoute(t);r&&this.navigateTo(r)})}disableLinkInterception(){console.warn("disableLinkInterception not fully implemented - requires storing handler references")}};class L{static TRACE_ERROR="error";static TRACE_INFO="info";static TRACE_LOG="log";static TRACE_NONE="none";static TRACE_WARN="warn";static __store={};static __stores=[];static __views={};static#p=new Map;static requestedView="";static activeFeatures={moment:!1};static activePage={id:""};static appData={};static appDataItems={};static history={content:[],currentPos:-1};static isInitialized=!1;static labels={};static languagesPath="";static models={};static pageTemplates={};static requiredPage="";static templates={};static traceLevel=L.TRACE_WARN;static __appDataMap=[];static __autoBoundProperties=[];static __components={};static __controllers={};static __globalListeners=[];static __listeners={viewToModelBinds:{},viewToModelBinds2:{}};static#u=new Set;static __models={};static __templateMap={};constructor(){console.warn("Shark constructor is deprecated, use Shark.init() method.")}static init(e,t){if(console.log("Initializing Shark v0.7.49-alpha.113"),Object.defineProperty(this,"$store",{configurable:!1,enumerable:!0,value:{},writable:!1}),e.templates&&console.warn("WARNING!!!! You are using 'templates' option that has been removed and it's been ignored."),e.commonEndPointsBase&&console.warn("WARNING!!!! You are using 'commonEndPointsBase' option that has been removed and it's been ignored."),e.dataManager&&console.warn("WARNING!!!! You are using 'dataManager' option that has been removed and it's been ignored."),L.trace("Shark.init, Shark.isInitialized: "+L.isInitialized+", forceReinit: "+t,L.TRACE_INFO),!L.isInitialized||t){let t={enableMainStoreAutoRender:!1,enableJawStoreAutoRender:!1,enableSmartModelSetUpdatesView:!1,enableSmartModelTypeInfer:!1,enableJawsCompatibilityMode:!1,enableExperimentalComponentProps:!1,enableExperimentalJawTemplates:!1,labels:[],preventDeepLinking:!1,remoteCallTimeOutDuration:15e3,routingMethod:"hash",templateRenderer:void 0!==P?new P:null};Object.assign(t,e),L.activeFeatures.moment="undefined"!=typeof moment,L.settings=t,L.labels=t.labels,L.templateRenderer=t.templateRenderer,L.settings.enableSmartModelTypeInfer&&Object.values(L.__models).forEach(e=>{e.inferTypes()}),Object.values(L.__components).forEach(e=>{L.trace("Calling appInit on Component "+e.id,L.TRACE_LOG),"function"==typeof e.appInit&&e.appInit.call(e)}),Object.values(L.__controllers).forEach(e=>{L.trace("Calling appInit on Controller "+e.id,L.TRACE_LOG),"function"==typeof e.appInit&&e.appInit.call(e)}),Object.values(L.__views).forEach(e=>{L.trace("Calling appInit on View "+e.id,L.TRACE_LOG),"function"==typeof e.appInit&&e.appInit.call(e)}),Object.values(L.pageTemplates).forEach(e=>{L.trace("Calling appInit on PageTemplate "+e.id,L.TRACE_LOG),"function"==typeof e.appInit&&e.appInit.call(e)}),L.isInitialized=!0}L.settings.preventDeepLinking||(L.parseRequestedViewFromLocation(),L.__pageOpening||L.trace("Page requested from URL",L.requestedView,L.TRACE_INFO),window.addEventListener("popstate",e=>{console.log(`%cSi è verificato l'evento ${e.type}, dovrei gestirlo.`,"border: 1px solid orange; color: violet; padding: 5px;",{event:e}),L.trace("event: popstate, location: "+document.location+", state: "+JSON.stringify(e.state),e,L.TRACE_LOG),e.state&&!L.__pageOpening&&(e.state.route&&e.state.url?(L.trace("Page requested from route (routing: url)",e.state.route,L.TRACE_INFO),L.$store.router?L.$store.router.navigateTo(e.state.url):console.warn("Sharo router not set.")):(L.requestedView=e.state.jawId,L.requestedView!==L.activePage.className&&(L.trace("Page requested from URL (routing: url)",L.requestedView,L.TRACE_INFO),L.openPage(L.requestedView,{isAutoOpen:!0}))))}),window.addEventListener("pushState",e=>{console.log(`%cSi è verificato l'evento ${e.type}, dovrei gestirlo.`,"border: 1px solid orange; color: violet; padding: 5px;",{event:e})}),window.addEventListener("replaceState",e=>{console.log(`%cSi è verificato l'evento ${e.type}, dovrei gestirlo.`,"border: 1px solid orange; color: violet; padding: 5px;",{event:e})}),"hash"!==L.settings.routingMethod&&"function"==typeof history.pushState||window.addEventListener("hashchange",function(){L.trace("event: hashchange, location: "+document.location+", state: "+JSON.stringify(event.state),event,L.TRACE_LOG),document.location.hash.length>1&&!L.__pageOpening&&(L.parseRequestedViewFromLocation(),L.requestedView!==L.activePage.className&&(L.trace("Page requested from URL (routing: hash)",L.requestedView,L.TRACE_INFO),L.openPage(L.requestedView,{isAutoOpen:!0})))}))}static navigateToRoute(e){L.__pageOpening=!0,""!==L.activePage.id&&(L.activePage.activeComponents.forEach(e=>{"function"==typeof e.beforeUnload&&e.beforeUnload.call(e,options)}),"function"==typeof L.activePage.beforeUnload&&L.activePage.beforeUnload.call(L.activePage),L.activePage.smartUnlisten(),L.activePage.currentOpenOptions=null);const t=e.view;if(!t)return!1;let r={dataType:"",delayRender:!1,renderOptions:{forceCleanRender:!0},route:e,saveInHistory:!0,urlSearchParams:""};if(r=u.deepMerge(r,e.options),t.currentOpenOptions=r,L.activePage=t,"function"!=typeof t.init||t.isInitialized||(t.init.call(t,r),t.isInitialized=!0,t._initComponents()),"function"==typeof t.beforeAutoOpen&&r.isAutoOpen){var a=t.beforeAutoOpen.call(t,r);a&&(r=a)}return L.setURLSearchParams(r.urlSearchParams,!1,e),t.activeComponents.forEach(e=>{"function"==typeof e.beforePageLoad&&e.beforePageLoad.call(e,r)}),"function"==typeof t.beforeLoad&&t.beforeLoad.call(t,r),t.activeComponents.forEach(e=>{"function"==typeof e.beforeLoad&&e.beforeLoad.call(e,r)}),L.render(t,r),t.currentOpenOptions.renderOptions.forceCleanRender=!1,L.__pageOpening=!1,"function"==typeof t.afterLoad&&t.afterLoad.call(t,r),t.activeComponents.forEach(e=>{"function"==typeof e.afterLoad&&e.afterLoad.call(e,r)}),!0}static __singleSet(e,t){L.trace("%csingleSet","background-color: #dddddd; boder: 2px solid lime; color: purple; padding: 5px 10px;",e,t,L.#p,L.TRACE_INFO),L.$store.hasOwnProperty(e)||(L.trace("%cCreo la property '%s'","background-color: #dddddd; boder: 2px solid lime; color: purple; padding: 5px 10px;",e,L.TRACE_INFO),Object.defineProperty(L.$store,e,{configurable:!0,enumerable:!0,get:()=>L.__store[e],set(t){const r=L.__store[e],a=u.computeHash(t);let o=a!==u.computeHash(r);L.#p.has(e)&&(o=L.#p.get(e)!==a,console.log(`%cHo un vecchio hash (sul set)!!!${L.#p.get(e)}, ${a}`,`background-color: ${o?"yellow":"green"}; color: ${o?"red":"white"}; font-weight: bold; padding: 3px 6px;`)),L.#p.set(e,a),L.__store[e]=t,L.settings.enableMainStoreAutoRender&&o&&(L.trace("%c SharkMVC: AUTORENDER TRIGGERED from single property","background-color: red; color: white; font-weight: bold;",{name:e,value:t},L.TRACE_INFO),L.render(),L.trace("%c SharkMVC: AUTORENDER COMPLETED from single property","background-color: red; color: white; font-weight: bold;",L.TRACE_INFO)),L.trace("%c scrivo la property valueChanged: "+o,"background-color: #ff99dd; boder: 2px solid lime; color: purple; padding: 5px 10px;",e,t,L.TRACE_INFO)}}));let r=L.__store[e],a=r,o="",n=a!==o;if(void 0!==r)try{a=u.computeHash(r)}catch(e){a=r}if(void 0!==t)try{o=u.computeHash(t)}catch(e){o=t}return L.#p.has(e)?(n=L.#p.get(e)!==o,L.trace(`%cHo un vecchio hash (sul set)!!!${L.#p.get(e)}, ${o}`,`background-color: ${n?"yellow":"green"}; color: ${n?"red":"white"}; font-weight: bold; padding: 3px 6px;`,L.TRACE_INFO)):n=a!==o,L.#p.set(e,o),L.__store[e]=t,L.trace("%cValueChanged","background-color: #dddddd; boder: 2px solid lime; color: purple; padding: 5px 10px;",n,{newValueHash:o},L.TRACE_INFO),n}static parseRequestedViewFromLocation(){const e=["url","pathname"].includes(L.settings.routingMethod)?document.location.pathname:document.location.hash;L.requestedView=""!==e?e.slice(1):""}static render(e,t){if(L.__renderRunning)L.trace("Autorender should be triggered but there is another render running.",L.TRACE_INFO),L.__renderPending=!0;else{L.__renderRunning=!0;const o=Math.random();L.trace("Start render: "+o,L.TRACE_LOG);let n=!0;if(void 0===e){var r=u.deepMerge(L.activePage.currentOpenOptions,t);t=r,e=L.activePage}let s=e.$documentTitle||(e?.get?e?.get("__htmlTitle"):null)||L.get("__htmlTitle")||L.$defaultDocumentTile;"string"==typeof s&&""!==s&&(document.title=s);var a=t.renderOptions;L.activePage&&"function"==typeof L.activePage.smartUnlisten&&L.activePage.smartUnlisten(),"function"==typeof L.beforeRenderEachPage&&L.beforeRenderEachPage(e,t),e&&"function"==typeof e.beforeRender&&e.beforeRender.call(e,t),e.activeComponents&&e.activeComponents.forEach(e=>{"function"==typeof e.beforeRender&&e.beforeRender.call(e,t)}),e&&"function"==typeof e.afterComponentsPreRender&&e.afterComponentsPreRender.call(e,t);let i={};if(i=u.deepMerge(i,a),document.querySelector(i.container)||(i.container="body"),e&&""!==e.id&&null!==L.templateRenderer&&(L.templateRenderer.render(e,i),document.querySelector("body").dataset.pageId=e.id,document.querySelector(i.container).dataset.pageId=e.id),L.__evaluateReferenceValues(),n&&L.bindViewToModel(),e&&"function"==typeof e.afterRender&&e.afterRender.call(e,t),e.activeCom