web-mojo 2.4.4 → 2.4.6
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 +43 -0
- package/dist/admin-models.cjs.js +1 -1
- package/dist/admin-models.cjs.js.map +1 -1
- package/dist/admin-models.es.js +1 -1
- package/dist/admin-models.es.js.map +1 -1
- package/dist/admin.cjs.js +1 -1
- package/dist/admin.css +258 -6
- package/dist/admin.es.js +1 -1
- package/dist/auth.cjs.js +1 -1
- package/dist/auth.es.js +1 -1
- package/dist/charts.cjs.js +1 -1
- package/dist/charts.es.js +1 -1
- package/dist/chat.css +5 -0
- package/dist/chunks/AssistantPanelView-CkQEcaFk.js +2 -0
- package/dist/chunks/AssistantPanelView-CkQEcaFk.js.map +1 -0
- package/dist/chunks/AssistantPanelView-D1wEbgtM.js +2 -0
- package/dist/chunks/AssistantPanelView-D1wEbgtM.js.map +1 -0
- package/dist/chunks/ChatView-D2WOSxPu.js +2 -0
- package/dist/chunks/ChatView-D2WOSxPu.js.map +1 -0
- package/dist/chunks/ChatView-kWguc444.js +2 -0
- package/dist/chunks/ChatView-kWguc444.js.map +1 -0
- package/dist/chunks/{Collection-7F3lsq4z.js → Collection-C0pHSKDH.js} +2 -2
- package/dist/chunks/{Collection-7F3lsq4z.js.map → Collection-C0pHSKDH.js.map} +1 -1
- package/dist/chunks/{Collection-Cgxbmj8G.js → Collection-DNmr743A.js} +2 -2
- package/dist/chunks/{Collection-Cgxbmj8G.js.map → Collection-DNmr743A.js.map} +1 -1
- package/dist/chunks/{ContextMenu-afYD0lFk.js → ContextMenu-BeveGkJr.js} +2 -2
- package/dist/chunks/{ContextMenu-afYD0lFk.js.map → ContextMenu-BeveGkJr.js.map} +1 -1
- package/dist/chunks/{ContextMenu-Ba4fjHxg.js → ContextMenu-T3yDdsIe.js} +2 -2
- package/dist/chunks/{ContextMenu-Ba4fjHxg.js.map → ContextMenu-T3yDdsIe.js.map} +1 -1
- package/dist/chunks/{DataView-DFGIE3wK.js → DataView-VZIXSsZa.js} +2 -2
- package/dist/chunks/{DataView-DFGIE3wK.js.map → DataView-VZIXSsZa.js.map} +1 -1
- package/dist/chunks/{DataView-fA6qQbvN.js → DataView-z2rxXk4L.js} +2 -2
- package/dist/chunks/{DataView-fA6qQbvN.js.map → DataView-z2rxXk4L.js.map} +1 -1
- package/dist/chunks/{FormView-CgnaTPkQ.js → FormView-COIPtbrd.js} +2 -2
- package/dist/chunks/{FormView-CgnaTPkQ.js.map → FormView-COIPtbrd.js.map} +1 -1
- package/dist/chunks/{FormView-LRb8scDI.js → FormView-DUXQruUZ.js} +2 -2
- package/dist/chunks/{FormView-LRb8scDI.js.map → FormView-DUXQruUZ.js.map} +1 -1
- package/dist/chunks/{ListView-Dsezts8J.js → ListView-BjsNHuZ1.js} +2 -2
- package/dist/chunks/{ListView-Dsezts8J.js.map → ListView-BjsNHuZ1.js.map} +1 -1
- package/dist/chunks/{ListView-Cu6iQ0aG.js → ListView-BxcxIwC3.js} +2 -2
- package/dist/chunks/{ListView-Cu6iQ0aG.js.map → ListView-BxcxIwC3.js.map} +1 -1
- package/dist/chunks/{MetricsCountryMapView-BsJoEsUE.js → MetricsCountryMapView-Bp3qoVHp.js} +2 -2
- package/dist/chunks/{MetricsCountryMapView-BsJoEsUE.js.map → MetricsCountryMapView-Bp3qoVHp.js.map} +1 -1
- package/dist/chunks/{MetricsCountryMapView-BkLDonK4.js → MetricsCountryMapView-CWjIEBJB.js} +2 -2
- package/dist/chunks/{MetricsCountryMapView-BkLDonK4.js.map → MetricsCountryMapView-CWjIEBJB.js.map} +1 -1
- package/dist/chunks/Modal-Bm1OQ8Ou.js +3 -0
- package/dist/chunks/{Modal-BRKy85bz.js.map → Modal-Bm1OQ8Ou.js.map} +1 -1
- package/dist/chunks/Modal-KnJhNZ1E.js +3 -0
- package/dist/chunks/{Modal-DKjxtaZI.js.map → Modal-KnJhNZ1E.js.map} +1 -1
- package/dist/chunks/Passkeys-B1-Z4-16.js +2 -0
- package/dist/chunks/Passkeys-B1-Z4-16.js.map +1 -0
- package/dist/chunks/Passkeys-BlHx11-5.js +2 -0
- package/dist/chunks/Passkeys-BlHx11-5.js.map +1 -0
- package/dist/chunks/TicketPanelView-DVePzWyJ.js +2 -0
- package/dist/chunks/TicketPanelView-DVePzWyJ.js.map +1 -0
- package/dist/chunks/TicketPanelView-TYh5iZiR.js +2 -0
- package/dist/chunks/TicketPanelView-TYh5iZiR.js.map +1 -0
- package/dist/chunks/{TokenManager-CWRL33UM.js → TokenManager-6atX9uKB.js} +2 -2
- package/dist/chunks/TokenManager-6atX9uKB.js.map +1 -0
- package/dist/chunks/{TokenManager-CVR3ENIS.js → TokenManager-CiNtJclo.js} +2 -2
- package/dist/chunks/TokenManager-CiNtJclo.js.map +1 -0
- package/dist/chunks/User-9qvKV7G6.js +2 -0
- package/dist/chunks/User-9qvKV7G6.js.map +1 -0
- package/dist/chunks/{User-BmS8zImI.js → User-BM76Ughk.js} +2 -2
- package/dist/chunks/User-BM76Ughk.js.map +1 -0
- package/dist/chunks/{UserProfileView-CrmACQjJ.js → UserProfileView-DDflzpTa.js} +2 -2
- package/dist/chunks/{UserProfileView-CrmACQjJ.js.map → UserProfileView-DDflzpTa.js.map} +1 -1
- package/dist/chunks/{UserProfileView-B56WeGL1.js → UserProfileView-cUF8ED9n.js} +2 -2
- package/dist/chunks/{UserProfileView-B56WeGL1.js.map → UserProfileView-cUF8ED9n.js.map} +1 -1
- package/dist/chunks/{View-gAghvPMN.js → View-BxlKR1IW.js} +2 -2
- package/dist/chunks/{View-gAghvPMN.js.map → View-BxlKR1IW.js.map} +1 -1
- package/dist/chunks/{View-IgBQlwd0.js → View-CPWwS19u.js} +2 -2
- package/dist/chunks/{View-IgBQlwd0.js.map → View-CPWwS19u.js.map} +1 -1
- package/dist/chunks/{WebApp-B6wrmIaj.js → WebApp-BdxhRnnT.js} +2 -2
- package/dist/chunks/WebApp-BdxhRnnT.js.map +1 -0
- package/dist/chunks/WebApp-Bo_egO0c.js +2 -0
- package/dist/chunks/WebApp-Bo_egO0c.js.map +1 -0
- package/dist/chunks/admin-CHPo4iDn.js +2 -0
- package/dist/chunks/admin-CHPo4iDn.js.map +1 -0
- package/dist/chunks/admin-CucHFXfD.js +2 -0
- package/dist/chunks/admin-CucHFXfD.js.map +1 -0
- package/dist/chunks/admin-models-CkHjtMHf.js +2 -0
- package/dist/chunks/admin-models-CkHjtMHf.js.map +1 -0
- package/dist/chunks/admin-models-DLtFboxy.js +2 -0
- package/dist/chunks/admin-models-DLtFboxy.js.map +1 -0
- package/dist/chunks/{exportChart-CmfLeCi8.js → exportChart-BTrEOM9j.js} +2 -2
- package/dist/chunks/{exportChart-CmfLeCi8.js.map → exportChart-BTrEOM9j.js.map} +1 -1
- package/dist/chunks/{exportChart-Ue-zU0_c.js → exportChart-BfzZUb1j.js} +2 -2
- package/dist/chunks/{exportChart-Ue-zU0_c.js.map → exportChart-BfzZUb1j.js.map} +1 -1
- package/dist/chunks/{index-DTXotoXw.js → index-Cxffar1o.js} +2 -2
- package/dist/chunks/{index-DTXotoXw.js.map → index-Cxffar1o.js.map} +1 -1
- package/dist/chunks/{index-NXnA6T-5.js → index-DsID1QpB.js} +2 -2
- package/dist/chunks/{index-NXnA6T-5.js.map → index-DsID1QpB.js.map} +1 -1
- package/dist/chunks/{version-CpR8sTVV.js → version-BYy2UAT0.js} +2 -2
- package/dist/chunks/{version-CpR8sTVV.js.map → version-BYy2UAT0.js.map} +1 -1
- package/dist/chunks/{version-CsLH6aiB.js → version-BxLEknar.js} +2 -2
- package/dist/chunks/{version-CsLH6aiB.js.map → version-BxLEknar.js.map} +1 -1
- package/dist/css/web-mojo.css +1 -1
- package/dist/docit.cjs.js +1 -1
- package/dist/docit.es.js +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/lightbox.cjs.js +1 -1
- package/dist/lightbox.es.js +1 -1
- package/dist/map.cjs.js +1 -1
- package/dist/map.es.js +1 -1
- package/dist/timeline.cjs.js +1 -1
- package/dist/timeline.es.js +1 -1
- package/dist/user-profile.cjs.js +1 -1
- package/dist/user-profile.es.js +1 -1
- package/dist/web-mojo.lite.iife.js +33 -4
- package/dist/web-mojo.lite.iife.js.map +1 -1
- package/dist/web-mojo.lite.iife.min.js +45 -45
- package/dist/web-mojo.lite.iife.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/AssistantPanelView-B3orPoag.js +0 -2
- package/dist/chunks/AssistantPanelView-B3orPoag.js.map +0 -1
- package/dist/chunks/AssistantPanelView-GeIHDvyN.js +0 -2
- package/dist/chunks/AssistantPanelView-GeIHDvyN.js.map +0 -1
- package/dist/chunks/ChatView-B0xHv7Nq.js +0 -2
- package/dist/chunks/ChatView-B0xHv7Nq.js.map +0 -1
- package/dist/chunks/ChatView-CUmRTKna.js +0 -2
- package/dist/chunks/ChatView-CUmRTKna.js.map +0 -1
- package/dist/chunks/Modal-BRKy85bz.js +0 -3
- package/dist/chunks/Modal-DKjxtaZI.js +0 -3
- package/dist/chunks/Passkeys-CMh9iSax.js +0 -2
- package/dist/chunks/Passkeys-CMh9iSax.js.map +0 -1
- package/dist/chunks/Passkeys-DF7mRGYj.js +0 -2
- package/dist/chunks/Passkeys-DF7mRGYj.js.map +0 -1
- package/dist/chunks/TokenManager-CVR3ENIS.js.map +0 -1
- package/dist/chunks/TokenManager-CWRL33UM.js.map +0 -1
- package/dist/chunks/User-BmS8zImI.js.map +0 -1
- package/dist/chunks/User-CayBjzMG.js +0 -2
- package/dist/chunks/User-CayBjzMG.js.map +0 -1
- package/dist/chunks/WebApp-B6wrmIaj.js.map +0 -1
- package/dist/chunks/WebApp-DeHPnmbD.js +0 -2
- package/dist/chunks/WebApp-DeHPnmbD.js.map +0 -1
- package/dist/chunks/admin-FvzwR-f7.js +0 -2
- package/dist/chunks/admin-FvzwR-f7.js.map +0 -1
- package/dist/chunks/admin-yjCkhxvU.js +0 -2
- package/dist/chunks/admin-yjCkhxvU.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const t=require("./Collection-7F3lsq4z.js"),e=Object.prototype.toString,n=Array.isArray||function(t){return"[object Array]"===e.call(t)},i=function(t){return"function"==typeof t},s=function(t){return null!==t&&"object"==typeof t},r=function(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};return String(t).replace(/[&<>"'`=\/]/g,function(t){return e[t]})};class Scanner{constructor(t){this.string=t,this.tail=t,this.pos=0}eos(){return""===this.tail}scan(t){const e=this.tail.match(t);if(!e||0!==e.index)return"";const n=e[0];return this.tail=this.tail.substring(n.length),this.pos+=n.length,n}scanUntil(t){const e=this.tail.search(t);let n;switch(e){case-1:n=this.tail,this.tail="";break;case 0:n="";break;default:n=this.tail.substring(0,e),this.tail=this.tail.substring(e)}return this.pos+=n.length,n}}class Context{constructor(t,e){this.view=t,this.cache={".":this.view},this.parent=e,this.view?._cacheId||this.view&&"object"==typeof this.view&&(this.view._cacheId=Math.random().toString(36).substring(2))}push(t){return new Context(t,this)}lookup(t){if(this.renderCache&&this.view?._cacheId){const e=`${this.view._cacheId}:${t}`;if(this.renderCache.has(e))return this.renderCache.get(e)}if("."===t)return this.view;if(t&&t.startsWith(".")){let e=t.substring(1),r=!1,o=null;const a=e.indexOf("|");if(-1!==a&&(o=e.substring(a+1).trim(),e=e.substring(0,a).trim()),e.endsWith("|iter")&&(e=e.substring(0,e.length-5),r=!0),this.view&&"object"==typeof this.view){let t;if("function"==typeof this.view.getContextValue)try{t=this.view.getContextValue(e),void 0!==t&&i(t)&&(t=t.call(this.view))}catch(h){t=void 0}if(void 0===t&&e in this.view&&(t=this.view[e],i(t)&&(t=t.call(this.view))),o&&void 0!==t)try{const e="undefined"==typeof window?null:window.MOJO?.dataFormatter?window.MOJO.dataFormatter:window.dataFormatter?window.dataFormatter:null;e&&"function"==typeof e.pipe&&(t=e.pipe(t,o,this))}catch(h){}return n(t)?r?t:t.length>0:s(t)?r?Object.entries(t).map(([t,e])=>({key:t,value:e})):Object.keys(t).length>0:t}return}const e=this.cache;let r;if(e.hasOwnProperty(t))r=e[t];else{let n,i,s,l=this,c=!1;for(;l;){if(l.view&&"function"==typeof l.view.getContextValue)try{n=l.view.getContextValue(t),void 0!==n&&(c=!0)}catch(h){c=!1}if(!c)if(t.indexOf(".")>0)for(n=l.view,i=t.split("."),s=0;null!=n&&s<i.length;)if(n&&"function"==typeof n.getContextValue&&s<i.length)try{const t=i.slice(s).join(".");n=n.getContextValue(t),s=i.length,void 0!==n&&(c=!0)}catch(h){s===i.length-1&&(c=o(n,i[s])||a(n,i[s])),n=n[i[s++]]}else s===i.length-1&&(c=o(n,i[s])||a(n,i[s])),n=n[i[s++]];else n=l.view[t],c=o(l.view,t);if(c){r=n;break}l=l.parent}e[t]=r}if(i(r)&&(r=r.call(this.view)),this.renderCache&&this.view?._cacheId){const e=`${this.view._cacheId}:${t}`;this.renderCache.set(e,r)}return r}}function o(t,e){return null!=t&&"object"==typeof t&&e in t}function a(t,e){return null!=t&&"object"!=typeof t&&t.hasOwnProperty&&t.hasOwnProperty(e)}class Writer{constructor(){this.templateCache=/* @__PURE__ */new Map}clearCache(){this.templateCache.clear()}parse(t,e){const n=t+":"+(e=e||["{{","}}"]).join(":");let i=this.templateCache.get(n);return null==i&&(i=this.parseTemplate(t,e),this.templateCache.set(n,i)),i}parseTemplate(t,e){if(!t)return[];const n=e[0],i=e[1],s=new Scanner(t),r=[];let o,a,l,c,d;const u=new RegExp(h(n)+"\\s*"),p=new RegExp("\\s*"+h(i)),f=new RegExp("\\s*"+h("}"+i));for(;!s.eos();){if(o=s.pos,l=s.scanUntil(u),l)for(let t=0;t<l.length;++t)c=l.charAt(t),r.push(["text",c]);if(!s.scan(u))break;if(a=s.scan(/[#^\/>{&=!]/),a||(a="name"),s.scan(/\s*/),"="===a?(l=s.scanUntil(/\s*=/),s.scan(/\s*=/),s.scanUntil(p)):"{"===a?(l=s.scanUntil(f),s.scan(f),a="&"):l=s.scanUntil(p),s.scan(p),"#"===a||"^"===a)d=[a,l,o,s.pos],r.push(d);else if("/"===a){let t;for(let e=r.length-1;e>=0;--e)if(("#"===r[e][0]||"^"===r[e][0])&&r[e][1]===l){t=r[e];break}t&&4===t.length&&t.push(s.pos),r.push([a,l,o,s.pos])}else r.push([a,l,o,s.pos])}return this.nestSections(this.squashTokens(r))}squashTokens(t){const e=[];let n,i;for(let s=0;s<t.length;++s)n=t[s],n&&("text"===n[0]&&i&&"text"===i[0]?(i[1]+=n[1],i[3]=n[3]):(e.push(n),i=n));return e}nestSections(t){const e=[];let n=e;const i=[];for(let s=0;s<t.length;++s){const r=t[s];switch(r[0]){case"#":case"^":const t=[r[0],r[1],r[2],r[3],[],r[4]||null];n.push(t),i.push(t),n=t[4];break;case"/":const s=i.pop();s&&(s[5]=r[2],n=i.length>0?i[i.length-1][4]:e);break;default:n.push(r)}}return e}render(t,e,n,i){const s=this.getConfigTags(i)||["{{","}}"],r=this.parse(t,s),o=/* @__PURE__ */new Map;return this.renderTokens(r,new Context(e),n,t,i,o)}renderTokens(t,e,s,o,a,h){h&&!e.renderCache&&(e.renderCache=h);let l="";for(let c=0;c<t.length;++c){const d=t[c];let u;switch(d[0]){case"#":if(u=e.lookup(d[1]),!u)continue;const t=d[4];if(!t||!n(t)){console.warn(`MUSTACHE WARNING - Section ${d[1]} has no child tokens:`,d);continue}if(n(u))for(let n=0;n<u.length;++n){const i=e.push(u[n]);e.renderCache&&(i.renderCache=e.renderCache),l+=this.renderTokens(t,i,s,o,a,h)}else if("object"==typeof u||"string"==typeof u||"number"==typeof u){const n=e.push(u);e.renderCache&&(n.renderCache=e.renderCache),l+=this.renderTokens(t,n,s,o,a,h)}else if(i(u)){const t=null==o?null:o.slice(d[3],d[5]);u=u.call(e.view,t,t=>this.render(t,e.view,s,a)),null!=u&&(l+=u)}else u&&(l+=this.renderTokens(t,e,s,o,a,h));break;case"^":if(u=e.lookup(d[1]),!u||n(u)&&0===u.length){const t=d[4];t&&n(t)&&(l+=this.renderTokens(t,e,s,o,a,h))}break;case">":if(!s)continue;u=i(s)?s(d[1]):s[d[1]],null!=u&&(l+=this.render(u,e.view,s,a));break;case"&":u=e.lookup(d[1]),null!=u&&(l+=u);break;case"name":u=e.lookup(d[1]),null!=u&&(l+=r(u));break;case"text":l+=d[1]}}return l}getConfigTags(t){return s(t)&&n(t.tags)?t.tags:null}}function h(t){return t.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}const l=new Writer,c={name:"MOJO Mustache",version:"1.0.0",tags:["{{","}}"],Scanner:Scanner,Context:Context,Writer:Writer,escape:r,clearCache:()=>l.clearCache(),parse:(t,e)=>l.parse(t,e),render(e,n,i,s){if("string"!=typeof e)throw new TypeError('Invalid template! Template should be a "string"');return n&&"object"==typeof n&&!n.getContextValue&&"function"!=typeof n.toJSON&&(n=t.MOJOUtils.wrapData(n)),l.render(e,n,i,s)}};class EventDelegate{constructor(t){this.view=t,this.domListeners=[],this.debounceTimers=/* @__PURE__ */new Map}bind(t){if(this.unbind(),!t)return;const e=async t=>{const e=t.target.closest("[data-action]");if(e&&this.shouldHandle(e,t)){const n=e.getAttribute("data-action");if("A"===e.tagName&&t.preventDefault(),this.hideTooltip(e),await this.dispatch(n,t,e))return t.preventDefault(),t.stopPropagation(),void(t.handledByChild=!0)}const n=t.target.closest("a[href], [data-page]");if(n&&!n.hasAttribute("data-action")&&this.shouldHandle(n,t)){if(t.ctrlKey||t.metaKey||t.shiftKey||1===t.button)return;if("A"===n.tagName){const t=n.getAttribute("href");if(t&&"#"!==t&&!t.startsWith("#")&&(this.view.isExternalLink(t)||n.hasAttribute("data-external")))return}this.hideTooltip(n),t.preventDefault(),t.stopPropagation(),t.handledByChild=!0,n.hasAttribute("data-page")?await this.view.handlePageNavigation(n):await this.view.handleHrefNavigation(n)}},n=t=>{const e=t.target.closest("[data-change-action]");if(e&&this.shouldHandle(e,t)){const n=e.getAttribute("data-change-action");return void this.dispatchChange(n,t,e).then(e=>{e&&(t.stopPropagation(),t.handledByChild=!0)})}const n=t.target.closest("[data-action]");if(n&&this.isFormControl(n)&&this.shouldHandle(n,t)){const e=n.getAttribute("data-action");this.dispatch(e,t,n).then(e=>{e&&(t.stopPropagation(),t.handledByChild=!0)})}},i=t=>{const e=t.target.closest("[data-change-action]");if(e&&this.shouldHandle(e,t)&&t.target.matches('[data-filter="live-search"]')){const n=e.getAttribute("data-change-action"),i=parseInt(e.getAttribute("data-filter-debounce"))||300,s=`change-${n}-${e.getAttribute("data-container")||"default"}`;this.debounceTimers.has(s)&&clearTimeout(this.debounceTimers.get(s));const r=setTimeout(()=>{this.debounceTimers.delete(s),this.dispatchChange(n,t,e).then(e=>{e&&(t.stopPropagation(),t.handledByChild=!0)})},i);return void this.debounceTimers.set(s,r)}const n=t.target.closest("[data-action]");if(!n||!this.isFormControl(n))return;if(n.hasAttribute("data-change-action"))return;if(!this.shouldHandle(n,t))return;const i=n.getAttribute("data-action"),s=n.getAttribute("data-action-debounce"),r=null!=s&&parseInt(s)||0;if(r>0){const e=`action-${i}-${n.getAttribute("data-container")||"default"}`;this.debounceTimers.has(e)&&clearTimeout(this.debounceTimers.get(e));const s=setTimeout(()=>{this.debounceTimers.delete(e),this.dispatch(i,t,n).then(e=>{e&&(t.stopPropagation(),t.handledByChild=!0)})},r);return void this.debounceTimers.set(e,s)}this.dispatch(i,t,n).then(e=>{e&&(t.stopPropagation(),t.handledByChild=!0)})},s=t=>{if(t.target.matches('[data-filter="search"]'))return;const e=t.target.closest("[data-keydown-action]")||t.target.closest("[data-change-action]");if(!e||!this.shouldHandle(e,t))return;let n=["Enter"];if(e.getAttribute("data-change-keys")&&(n=e.getAttribute("data-change-keys").split(",").map(t=>t.trim())),n.includes("*")||n.includes(t.key)){const n=e.getAttribute("data-keydown-action")||e.getAttribute("data-change-action");this.dispatch(n,t,e).then(e=>{e&&(t.preventDefault(),t.stopPropagation(),t.handledByChild=!0)})}},r=t=>{const e=t.target.closest("form[data-action]");if(!e||!this.shouldHandle(e,t))return;t.preventDefault();const n=e.getAttribute("data-action");this.dispatch(n,t,e)};t.addEventListener("click",e),t.addEventListener("change",n),t.addEventListener("input",i),t.addEventListener("keydown",s),t.addEventListener("submit",r),this.domListeners.push({el:t,type:"click",fn:e},{el:t,type:"change",fn:n},{el:t,type:"input",fn:i},{el:t,type:"keydown",fn:s},{el:t,type:"submit",fn:r})}unbind(){for(const{el:t,type:e,fn:n}of this.domListeners)t.removeEventListener(e,n);this.domListeners=[];for(const t of this.debounceTimers.values())clearTimeout(t);this.debounceTimers.clear()}hideDropdown(t){const e=t.closest(".dropdown-menu").closest(".dropdown");if(!e)return;const n=e.querySelector('[data-bs-toggle="dropdown"]');if(n&&window.bootstrap?.Dropdown){const t=window.bootstrap.Dropdown.getInstance(n);t?.hide()}}hideTooltip(t){if(t&&window.bootstrap?.Tooltip){const e=window.bootstrap.Tooltip.getInstance(t);e&&e.dispose()}}hideAllTooltips(){window.bootstrap?.Tooltip&&document.querySelectorAll('[data-bs-toggle="tooltip"]').forEach(t=>{const e=window.bootstrap.Tooltip.getInstance(t);e&&e.hide()})}async dispatch(t,e,n){const i=this.view,s=t=>t.includes("-")?t.split("-").map(t=>t[0].toUpperCase()+t.slice(1)).join(""):t[0].toUpperCase()+t.slice(1),r=`handleAction${s(t)}`;if("function"==typeof i[r])try{return e.preventDefault(),await i[r](e,n),!0}catch(h){return console.error(`Error in action ${t}:`,h),i.handleActionError(t,h,e,n),!0}const o=`onAction${s(t)}`;if("function"==typeof i[o])try{return!!(await i[o](e,n))&&(!!n.closest(".dropdown-menu")&&this.hideDropdown(n),e.preventDefault(),e.stopPropagation(),!0)}catch(h){return console.error(`Error in action ${t}:`,h),i.handleActionError(t,h,e,n),!0}const a=`onPassThruAction${s(t)}`;if("function"==typeof i[a])try{return await i[a](e,n),!1}catch(h){return console.error(`Error in action ${t}:`,h),i.handleActionError(t,h,e,n),!0}if("function"==typeof i.onActionDefault)try{return await i.onActionDefault(t,e,n)}catch(h){return console.error(`Error in default action handler for ${t}:`,h),i.handleActionError(t,h,e,n),!0}return i.emit?.(`action:${t}`,{action:t,event:e,element:n}),!1}async dispatchChange(t,e,n){const i=this.view,s=`onChange${r=t,r.includes("-")?r.split("-").map(t=>t[0].toUpperCase()+t.slice(1)).join(""):r[0].toUpperCase()+r.slice(1)}`;var r;if("function"==typeof i[s])try{return await i[s](e,n),!0}catch(o){return console.error(`Error in onChange ${t}:`,o),i.handleActionError?.(t,o,e,n),!0}return await this.dispatch(t,e,n)}isFormControl(t){if(!t||!t.tagName)return!1;const e=t.tagName;return"INPUT"===e||"TEXTAREA"===e||"SELECT"===e}shouldHandle(t,e){return!!this.owns(t)||!(!this.contains(t)||e.handledByChild)}owns(t){const e=this.view.element;if(!e||!e.contains(t))return!1;for(const n of Object.values(this.view.children))if(n.element&&n.element.contains(t))return!1;return!0}contains(t){return!!this.view.element&&this.view.element.contains(t)}}"undefined"!=typeof window&&(window.Mustache=c);class View{constructor(t={}){this.tagName=t.tagName??"div",this.className=t.className??"mojo-view",this.style=t.style??null,this.id=t.id??View._genId(),this.containerId=t.containerId??null,this.container=t.container??null,"string"==typeof this.container&&(this.containerId=this.container,this.container=null),this.parent=t.parent??null,this.children=t.children??{},this.template=t.template||t.templateUrl||"",this.data=t.data??{},this.isRendering=!1,this.lastRenderTime=0,this.mounted=!1,this.debug=t.debug??!1,this.app=t.app??null,this.cacheTemplate=t.cacheTemplate??!0,this.enableTooltips=t.enableTooltips??!1,this.options={...t},this.element=this._ensureElement(),this.events=new EventDelegate(this),t.model&&this.setModel(t.model)}async onInit(){}async onInitView(){this.initialized||(this.initialized=!0,await this.onInit())}async onBeforeRender(){}async onAfterRender(){}async onBeforeMount(){}async onAfterMount(){}async onBeforeUnmount(){}async onAfterUnmount(){}async onBeforeDestroy(){}async onAfterDestroy(){}setModel(t={}){let e=t!==this.model;if(!e)return this;this.model&&this.model.off&&this.model.off("change",this._onModelChange,this),this.model=t,this.model&&this.model.on&&this.model.on("change",this._onModelChange,this);for(const n in this.children){const e=this.children[n];e&&"function"==typeof e.setModel&&e.setModel(t)}return e&&this._onModelChange(),this}_onModelChange(){this.isMounted()&&this.render()}setTemplate(t){return this.template=t??"",this}addChild(t,e){try{if(!t||"object"!=typeof t)return this;e&&((e.containerId||e.container)&&(t.containerId=e.containerId||e.container),e.id&&(t.id=e.id),!0===e.lazyMount&&(t._lazyMount=!0)),t.parent=this,this.getApp()&&(t.app=this.app),this.children[t.id]=t}catch(n){View._warn("addChild error",n)}return t}removeChild(t){try{const e="string"==typeof t?t:t&&t.id;if(!e)return this;const n=this.children[e];n&&(Promise.resolve(n.destroy()).catch(t=>View._warn("removeChild destroy error",t)),delete this.children[e])}catch(e){View._warn("removeChild error",e)}return this}getChild(t){return this.children[t]}async updateData(t,e=!1){return Object.assign(this.data,t),e&&this.isMounted()&&await this.render(),this}toggleClass(t,e){return void 0===e&&(e=!this.element.classList.contains(t)),this.element.classList.toggle(t,e),this}addClass(t){return this.element.classList.add(t),this}setClass(t){return this.element.className=t,this}removeClass(t){return this.element.classList.remove(t),this}canRender(){if(this.isRendering)return!1;const t=Date.now();if(this.options.renderCooldown>0&&t-this.lastRenderTime<this.options.renderCooldown)return View._warn(`View ${this.id}: Render called too quickly, cooldown active`),!1;if(this.options.noAppend&&this.parent){if(!this.parent.contains(this.containerId||this.container))return!1;if(this.containerId&&!document.getElementById(this.containerId))return!1;if(this.container&&!document.contains(this.container))return!1}return!0}async render(t=!0,e=null){const n=Date.now();if(!this.canRender())return this;this.isRendering=!0,this.lastRenderTime=n;try{this.initialized||await this.onInitView(),this.unbindEvents(),await this.onBeforeRender(),this.getViewData&&(this.data=await this.getViewData());const n=await this.renderTemplate();this.element.innerHTML=n,t&&!this.isMounted()&&await this.mount(e),await this._renderChildren(),await this.onAfterRender(),this.bindEvents()}catch(i){View._warn(`Render error in ${this.id}`,i)}finally{this.isRendering=!1}return this}async _renderChildren(){const t=[];for(const e in this.children){const n=this.children[e];n&&(n.parent=this,!n._lazyMount||n._lazyTriggered?await Promise.resolve(n.render()).catch(t=>View._warn(`Child render error (${e})`,t)):t.push(n))}t.length&&this._setupLazyMountObserver(t)}_setupLazyMountObserver(t){if("undefined"!=typeof IntersectionObserver){this._lazyObserver||(this._lazyObserver=new IntersectionObserver((t,e)=>{for(const n of t){if(!n.isIntersecting)continue;const t=n.target.__mojoLazyChild;e.unobserve(n.target),t&&!t._lazyTriggered&&(t._lazyTriggered=!0,Promise.resolve(t.render()).catch(e=>View._warn(`Lazy child render error (${t.id})`,e)))}},{rootMargin:"120px 0px",threshold:.01}));for(const e of t){const t=this.getChildElement(e.containerId);t&&(t.__mojoLazyChild=e,t.style.minHeight||(t.classList.add("mojo-lazy-placeholder"),t.style.minHeight="1px"),this._lazyObserver.observe(t),requestAnimationFrame(()=>{if(e._lazyTriggered)return;const n=t.getBoundingClientRect(),i="undefined"!=typeof window?window.innerHeight:0,s="undefined"!=typeof window?window.innerWidth:0;n.top<i+120&&n.bottom>-120&&n.left<s&&n.right>0&&(e._lazyTriggered=!0,this._lazyObserver?.unobserve(t),Promise.resolve(e.render()).catch(t=>View._warn(`Lazy child render error (${e.id})`,t)))}))}}else t.forEach(t=>{t._lazyTriggered=!0,Promise.resolve(t.render()).catch(e=>View._warn(`Lazy child render error (${t.id})`,e))})}async _unmountChildren(){for(const t in this.children){const e=this.children[t];e&&e.unbindEvents()}}isMounted(){return this.element?.isConnected}getChildElementById(t,e=null){const n=t.startsWith("#")?t.substring(1):t;return e?e.querySelector(`#${n}`):this.element.querySelector(`#${n}`)}getChildElement(t){if(t.startsWith("#"))return this.getChildElementById(t);let e=this.element?.querySelector(`[data-container="${t}"]`);return e||this.getChildElementById(t)}getContainer(){return this.replaceById?this.parent?this.parent.getChildElementById(this.id):null:this.containerId?this.parent?this.parent.getChildElement(this.containerId):this.getChildElementById(this.containerId,document.body):null}async mount(t=null){await this.onBeforeMount(),t||(t=this.getContainer()),!this.containerId||t?(t&&this.replaceById?t.replaceWith(this.element):t?t.replaceChildren(this.element):!this.containerId&&this.parent?this.parent.element.appendChild(this.element):this.containerId||this.parent||!this.options.allowAppendToBody?console.error(`Container not found for ${this.containerId}`):document.body.appendChild(this.element),await this.onAfterMount(),this.mounted=!0):console.error(`Container not found for ${this.containerId}`)}async unmount(){this.element&&this.element.parentNode&&(await this.onBeforeUnmount(),await this._unmountChildren(),this.element.parentNode&&this.element.parentNode.removeChild(this.element),this.events.unbind(),await this.onAfterUnmount(),this.mounted=!1)}async destroy(){try{this.events.unbind(),this._lazyObserver&&(this._lazyObserver.disconnect(),this._lazyObserver=null);for(const t in this.children){const e=this.children[t];e&&await Promise.resolve(e.destroy()).catch(e=>View._warn(`Child destroy error (${t})`,e))}this.mounted=!1,this.element&&this.element.parentNode&&(await this.onBeforeDestroy(),this.element.parentNode&&this.element.parentNode.removeChild(this.element),await this.onAfterDestroy())}catch(t){View._warn(`Destroy error in ${this.id}`,t)}}_ensureElement(){try{if(this.element&&this.element.tagName?.toLowerCase()===this.tagName)return this._syncAttrs(),this.element;const t=document.createElement(this.tagName);return this.element=t,this.el=t,this._syncAttrs(),t}catch(t){View._warn("ensureElement error",t);const e=document.createElement("div");return e.id=this.id||View._genId(),e}}_syncAttrs(){try{if(!this.element)return;this.id&&(this.element.id=this.id),this.element.className=this.className||"",null==this.style?this.element.removeAttribute("style"):this.element.style.cssText=String(this.style)}catch(t){View._warn("_syncAttrs error",t)}}bindEvents(){this.events.bind(this.element),this.enableTooltips&&this.initializeTooltips()}unbindEvents(){this.events.unbind(),this.enableTooltips&&this.disposeTooltips()}async renderTemplate(){const t=await this.getTemplate();if(!t)return"";const e=this.getPartials();return c.render(t,this,e)}renderTemplateString(t,e,n){return c.render(t,e,n)}getPartials(){return{}}async getTemplate(){if(this._templateCache&&this.cacheTemplate)return this._templateCache;const t=this.template||this.templateUrl;if(!t)throw new Error("Template not found");let e="";if("string"==typeof t)if(t.includes("<")||t.includes("{"))e=t;else try{let n=t;this.app||(this.app=this.getApp()),!this.app||!this.app.basePath||n.startsWith("/")||n.startsWith("http://")||n.startsWith("https://")||(n=`${this.app.basePath.endsWith("/")?this.app.basePath.slice(0,-1):this.app.basePath}/${n}`);const i=await fetch(n);if(!i.ok)throw new Error(`HTTP ${i.status}: ${i.statusText}`);e=await i.text()}catch(n){View._warn(`Failed to load template from ${t}: ${n}`),this.showError?.(`Failed to load template from ${t}: ${n.message}`)}else"function"==typeof t&&(e=await this.template(this.data,this.state));return this.cacheTemplate&&e&&(this._templateCache=e),e}getContextValue(e){const n=t.MOJOUtils.getContextData(this,e);return e&&e.startsWith("data.")&&n&&"object"==typeof n?t.MOJOUtils.wrapData(n,this):e&&e.startsWith("model.")&&"model"!==e&&n&&"object"==typeof n&&"function"!=typeof n.getContextValue?t.MOJOUtils.wrapData(n,null):n}async handlePageNavigation(t){const e=t.getAttribute("data-page"),n=t.getAttribute("data-params");let i={};if(n)try{i=JSON.parse(n)}catch(o){console.warn("Invalid JSON in data-params:",n)}const s=this.getApp();if(s)return void s.showPage(e,i);const r=this.findRouter();r&&"function"==typeof r.navigateToPage?await r.navigateToPage(e,i):console.error(`No router found for page navigation to '${e}'`)}async handleHrefNavigation(t){const e=t.getAttribute("href");if(this.isExternalLink(e)||t.hasAttribute("data-external"))return;const n=this.findRouter();if(n){if(n.options&&"param"===n.options.mode&&e.startsWith("?")){const t="/"+e;return void(await n.navigate(t))}if(n.options&&"hash"===n.options.mode&&e.startsWith("#"))return void(await n.navigate(e));const t=this.hrefToRoutePath(e);await n.navigate(t)}else console.warn("No router found for navigation, using default behavior"),window.location.href=e}isExternalLink(t){return!t||(t.startsWith("/")&&this.getApp()?!t.startsWith(this.findRouter().basePath):t.startsWith("#")||t.startsWith("mailto:")||t.startsWith("tel:")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//"))}hrefToRoutePath(t){if(t.startsWith("/")){const e=this.findRouter();if(e&&e.options&&e.options.base){const n=e.options.base;if(t.startsWith(n))return t.substring(n.length)||"/"}return t}return t.startsWith("./")?t.substring(2):t}findRouter(){return this.getApp(),this.app?.router||null}getApp(){if(this.app)return this.app;const t=[window.__app__,window.MOJO?.app,window.APP,window.app,window.WebApp,window.matchUUID?window[window.matchUUID]():window[window.matchUUID]];return this.app=t.find(t=>t&&"function"==typeof t.showPage)||null,this.app}handleActionError(t,e,n,i){this.showError(`Action '${t}' failed: ${e}`,n,i)}escapeHtml(t){if("string"!=typeof t)return t;const e=document.createElement("div");return e.textContent=t,e.innerHTML}contains(t){if("string"==typeof t){if(!this.element)return!1;t=document.getElementById(t)}return!!t&&this.element.contains(t)}initializeTooltips(){this.element&&window.bootstrap?.Tooltip&&(this.disposeTooltips(),[...this.element.querySelectorAll('[data-bs-toggle="tooltip"]')].map(t=>{const e=t.getAttribute("data-tooltip-theme"),n=t.getAttribute("data-tooltip-size");let i="";e&&(i+=`tooltip-${e} `),n&&(i+=`tooltip-${n}`);const s={},r=i.trim();return r&&(s.customClass=r),new window.bootstrap.Tooltip(t,s)}))}disposeTooltips(){this.element&&window.bootstrap?.Tooltip&&this.element.querySelectorAll('[data-bs-toggle="tooltip"]').forEach(t=>{const e=window.bootstrap.Tooltip.getInstance(t);e&&e.dispose()})}async showError(t){console.error(`View ${this.id} error:`,t);const e=this.getApp?this.getApp():this.app||null;e&&"function"==typeof e.showError?await e.showError(t):alert(`Error: ${t}`)}async showSuccess(t){this.debug&&this.id;const e=this.getApp?this.getApp():this.app||null;e&&"function"==typeof e.showSuccess?await e.showSuccess(t):alert(`Success: ${t}`)}async showInfo(t){this.id;const e=this.getApp?this.getApp():this.app||null;e&&"function"==typeof e.showInfo?await e.showInfo(t):alert(`Info: ${t}`)}async showWarning(t){console.warn(`View ${this.id} warning:`,t);const e=this.getApp?this.getApp():this.app||null;e&&"function"==typeof e.showWarning?await e.showWarning(t):alert(`Warning: ${t}`)}async onActionCopyToClipboard(t,e){try{const t=e?.closest("[data-clipboard]")||e,n=t?.getAttribute("data-clipboard")||"";if(!n)return!0;if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(n);else{const t=document.createElement("textarea");t.value=n,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}const i=e.querySelector("i"),s=i&&i.className;return i&&(i.className="bi bi-check",setTimeout(()=>{i.className=s},1e3)),!0}catch(n){return console.warn("Copy to clipboard failed:",n),!0}}static _genId(){return`view_${Math.random().toString(36).substr(2,9)}`}static _warn(t,e){try{e?console.warn(`[View] ${t}:`,e):console.warn(`[View] ${t}`)}catch{}}}Object.assign(View.prototype,t.EventEmitter),exports.EventDelegate=EventDelegate,exports.Mustache=c,exports.View=View;
|
|
2
|
-
//# sourceMappingURL=View-
|
|
1
|
+
"use strict";const t=require("./Collection-C0pHSKDH.js"),e=Object.prototype.toString,n=Array.isArray||function(t){return"[object Array]"===e.call(t)},i=function(t){return"function"==typeof t},s=function(t){return null!==t&&"object"==typeof t},r=function(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};return String(t).replace(/[&<>"'`=\/]/g,function(t){return e[t]})};class Scanner{constructor(t){this.string=t,this.tail=t,this.pos=0}eos(){return""===this.tail}scan(t){const e=this.tail.match(t);if(!e||0!==e.index)return"";const n=e[0];return this.tail=this.tail.substring(n.length),this.pos+=n.length,n}scanUntil(t){const e=this.tail.search(t);let n;switch(e){case-1:n=this.tail,this.tail="";break;case 0:n="";break;default:n=this.tail.substring(0,e),this.tail=this.tail.substring(e)}return this.pos+=n.length,n}}class Context{constructor(t,e){this.view=t,this.cache={".":this.view},this.parent=e,this.view?._cacheId||this.view&&"object"==typeof this.view&&(this.view._cacheId=Math.random().toString(36).substring(2))}push(t){return new Context(t,this)}lookup(t){if(this.renderCache&&this.view?._cacheId){const e=`${this.view._cacheId}:${t}`;if(this.renderCache.has(e))return this.renderCache.get(e)}if("."===t)return this.view;if(t&&t.startsWith(".")){let e=t.substring(1),r=!1,o=null;const a=e.indexOf("|");if(-1!==a&&(o=e.substring(a+1).trim(),e=e.substring(0,a).trim()),e.endsWith("|iter")&&(e=e.substring(0,e.length-5),r=!0),this.view&&"object"==typeof this.view){let t;if("function"==typeof this.view.getContextValue)try{t=this.view.getContextValue(e),void 0!==t&&i(t)&&(t=t.call(this.view))}catch(h){t=void 0}if(void 0===t&&e in this.view&&(t=this.view[e],i(t)&&(t=t.call(this.view))),o&&void 0!==t)try{const e="undefined"==typeof window?null:window.MOJO?.dataFormatter?window.MOJO.dataFormatter:window.dataFormatter?window.dataFormatter:null;e&&"function"==typeof e.pipe&&(t=e.pipe(t,o,this))}catch(h){}return n(t)?r?t:t.length>0:s(t)?r?Object.entries(t).map(([t,e])=>({key:t,value:e})):Object.keys(t).length>0:t}return}const e=this.cache;let r;if(e.hasOwnProperty(t))r=e[t];else{let n,i,s,l=this,c=!1;for(;l;){if(l.view&&"function"==typeof l.view.getContextValue)try{n=l.view.getContextValue(t),void 0!==n&&(c=!0)}catch(h){c=!1}if(!c)if(t.indexOf(".")>0)for(n=l.view,i=t.split("."),s=0;null!=n&&s<i.length;)if(n&&"function"==typeof n.getContextValue&&s<i.length)try{const t=i.slice(s).join(".");n=n.getContextValue(t),s=i.length,void 0!==n&&(c=!0)}catch(h){s===i.length-1&&(c=o(n,i[s])||a(n,i[s])),n=n[i[s++]]}else s===i.length-1&&(c=o(n,i[s])||a(n,i[s])),n=n[i[s++]];else n=l.view[t],c=o(l.view,t);if(c){r=n;break}l=l.parent}e[t]=r}if(i(r)&&(r=r.call(this.view)),this.renderCache&&this.view?._cacheId){const e=`${this.view._cacheId}:${t}`;this.renderCache.set(e,r)}return r}}function o(t,e){return null!=t&&"object"==typeof t&&e in t}function a(t,e){return null!=t&&"object"!=typeof t&&t.hasOwnProperty&&t.hasOwnProperty(e)}class Writer{constructor(){this.templateCache=/* @__PURE__ */new Map}clearCache(){this.templateCache.clear()}parse(t,e){const n=t+":"+(e=e||["{{","}}"]).join(":");let i=this.templateCache.get(n);return null==i&&(i=this.parseTemplate(t,e),this.templateCache.set(n,i)),i}parseTemplate(t,e){if(!t)return[];const n=e[0],i=e[1],s=new Scanner(t),r=[];let o,a,l,c,d;const u=new RegExp(h(n)+"\\s*"),p=new RegExp("\\s*"+h(i)),f=new RegExp("\\s*"+h("}"+i));for(;!s.eos();){if(o=s.pos,l=s.scanUntil(u),l)for(let t=0;t<l.length;++t)c=l.charAt(t),r.push(["text",c]);if(!s.scan(u))break;if(a=s.scan(/[#^\/>{&=!]/),a||(a="name"),s.scan(/\s*/),"="===a?(l=s.scanUntil(/\s*=/),s.scan(/\s*=/),s.scanUntil(p)):"{"===a?(l=s.scanUntil(f),s.scan(f),a="&"):l=s.scanUntil(p),s.scan(p),"#"===a||"^"===a)d=[a,l,o,s.pos],r.push(d);else if("/"===a){let t;for(let e=r.length-1;e>=0;--e)if(("#"===r[e][0]||"^"===r[e][0])&&r[e][1]===l){t=r[e];break}t&&4===t.length&&t.push(s.pos),r.push([a,l,o,s.pos])}else r.push([a,l,o,s.pos])}return this.nestSections(this.squashTokens(r))}squashTokens(t){const e=[];let n,i;for(let s=0;s<t.length;++s)n=t[s],n&&("text"===n[0]&&i&&"text"===i[0]?(i[1]+=n[1],i[3]=n[3]):(e.push(n),i=n));return e}nestSections(t){const e=[];let n=e;const i=[];for(let s=0;s<t.length;++s){const r=t[s];switch(r[0]){case"#":case"^":const t=[r[0],r[1],r[2],r[3],[],r[4]||null];n.push(t),i.push(t),n=t[4];break;case"/":const s=i.pop();s&&(s[5]=r[2],n=i.length>0?i[i.length-1][4]:e);break;default:n.push(r)}}return e}render(t,e,n,i){const s=this.getConfigTags(i)||["{{","}}"],r=this.parse(t,s),o=/* @__PURE__ */new Map;return this.renderTokens(r,new Context(e),n,t,i,o)}renderTokens(t,e,s,o,a,h){h&&!e.renderCache&&(e.renderCache=h);let l="";for(let c=0;c<t.length;++c){const d=t[c];let u;switch(d[0]){case"#":if(u=e.lookup(d[1]),!u)continue;const t=d[4];if(!t||!n(t)){console.warn(`MUSTACHE WARNING - Section ${d[1]} has no child tokens:`,d);continue}if(n(u))for(let n=0;n<u.length;++n){const i=e.push(u[n]);e.renderCache&&(i.renderCache=e.renderCache),l+=this.renderTokens(t,i,s,o,a,h)}else if("object"==typeof u||"string"==typeof u||"number"==typeof u){const n=e.push(u);e.renderCache&&(n.renderCache=e.renderCache),l+=this.renderTokens(t,n,s,o,a,h)}else if(i(u)){const t=null==o?null:o.slice(d[3],d[5]);u=u.call(e.view,t,t=>this.render(t,e.view,s,a)),null!=u&&(l+=u)}else u&&(l+=this.renderTokens(t,e,s,o,a,h));break;case"^":if(u=e.lookup(d[1]),!u||n(u)&&0===u.length){const t=d[4];t&&n(t)&&(l+=this.renderTokens(t,e,s,o,a,h))}break;case">":if(!s)continue;u=i(s)?s(d[1]):s[d[1]],null!=u&&(l+=this.render(u,e.view,s,a));break;case"&":u=e.lookup(d[1]),null!=u&&(l+=u);break;case"name":u=e.lookup(d[1]),null!=u&&(l+=r(u));break;case"text":l+=d[1]}}return l}getConfigTags(t){return s(t)&&n(t.tags)?t.tags:null}}function h(t){return t.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}const l=new Writer,c={name:"MOJO Mustache",version:"1.0.0",tags:["{{","}}"],Scanner:Scanner,Context:Context,Writer:Writer,escape:r,clearCache:()=>l.clearCache(),parse:(t,e)=>l.parse(t,e),render(e,n,i,s){if("string"!=typeof e)throw new TypeError('Invalid template! Template should be a "string"');return n&&"object"==typeof n&&!n.getContextValue&&"function"!=typeof n.toJSON&&(n=t.MOJOUtils.wrapData(n)),l.render(e,n,i,s)}};class EventDelegate{constructor(t){this.view=t,this.domListeners=[],this.debounceTimers=/* @__PURE__ */new Map}bind(t){if(this.unbind(),!t)return;const e=async t=>{const e=t.target.closest("[data-action]");if(e&&this.shouldHandle(e,t)){const n=e.getAttribute("data-action");if("A"===e.tagName&&t.preventDefault(),this.hideTooltip(e),await this.dispatch(n,t,e))return t.preventDefault(),t.stopPropagation(),void(t.handledByChild=!0)}const n=t.target.closest("a[href], [data-page]");if(n&&!n.hasAttribute("data-action")&&this.shouldHandle(n,t)){if(t.ctrlKey||t.metaKey||t.shiftKey||1===t.button)return;if("A"===n.tagName){const t=n.getAttribute("href");if(t&&"#"!==t&&!t.startsWith("#")&&(this.view.isExternalLink(t)||n.hasAttribute("data-external")))return}this.hideTooltip(n),t.preventDefault(),t.stopPropagation(),t.handledByChild=!0,n.hasAttribute("data-page")?await this.view.handlePageNavigation(n):await this.view.handleHrefNavigation(n)}},n=t=>{const e=t.target.closest("[data-change-action]");if(e&&this.shouldHandle(e,t)){const n=e.getAttribute("data-change-action");return void this.dispatchChange(n,t,e).then(e=>{e&&(t.stopPropagation(),t.handledByChild=!0)})}const n=t.target.closest("[data-action]");if(n&&this.isFormControl(n)&&this.shouldHandle(n,t)){const e=n.getAttribute("data-action");this.dispatch(e,t,n).then(e=>{e&&(t.stopPropagation(),t.handledByChild=!0)})}},i=t=>{const e=t.target.closest("[data-change-action]");if(e&&this.shouldHandle(e,t)&&t.target.matches('[data-filter="live-search"]')){const n=e.getAttribute("data-change-action"),i=parseInt(e.getAttribute("data-filter-debounce"))||300,s=`change-${n}-${e.getAttribute("data-container")||"default"}`;this.debounceTimers.has(s)&&clearTimeout(this.debounceTimers.get(s));const r=setTimeout(()=>{this.debounceTimers.delete(s),this.dispatchChange(n,t,e).then(e=>{e&&(t.stopPropagation(),t.handledByChild=!0)})},i);return void this.debounceTimers.set(s,r)}const n=t.target.closest("[data-action]");if(!n||!this.isFormControl(n))return;if(n.hasAttribute("data-change-action"))return;if(!this.shouldHandle(n,t))return;const i=n.getAttribute("data-action"),s=n.getAttribute("data-action-debounce"),r=null!=s&&parseInt(s)||0;if(r>0){const e=`action-${i}-${n.getAttribute("data-container")||"default"}`;this.debounceTimers.has(e)&&clearTimeout(this.debounceTimers.get(e));const s=setTimeout(()=>{this.debounceTimers.delete(e),this.dispatch(i,t,n).then(e=>{e&&(t.stopPropagation(),t.handledByChild=!0)})},r);return void this.debounceTimers.set(e,s)}this.dispatch(i,t,n).then(e=>{e&&(t.stopPropagation(),t.handledByChild=!0)})},s=t=>{if(t.target.matches('[data-filter="search"]'))return;const e=t.target.closest("[data-keydown-action]")||t.target.closest("[data-change-action]");if(!e||!this.shouldHandle(e,t))return;let n=["Enter"];if(e.getAttribute("data-change-keys")&&(n=e.getAttribute("data-change-keys").split(",").map(t=>t.trim())),n.includes("*")||n.includes(t.key)){const n=e.getAttribute("data-keydown-action")||e.getAttribute("data-change-action");this.dispatch(n,t,e).then(e=>{e&&(t.preventDefault(),t.stopPropagation(),t.handledByChild=!0)})}},r=t=>{const e=t.target.closest("form[data-action]");if(!e||!this.shouldHandle(e,t))return;t.preventDefault();const n=e.getAttribute("data-action");this.dispatch(n,t,e)};t.addEventListener("click",e),t.addEventListener("change",n),t.addEventListener("input",i),t.addEventListener("keydown",s),t.addEventListener("submit",r),this.domListeners.push({el:t,type:"click",fn:e},{el:t,type:"change",fn:n},{el:t,type:"input",fn:i},{el:t,type:"keydown",fn:s},{el:t,type:"submit",fn:r})}unbind(){for(const{el:t,type:e,fn:n}of this.domListeners)t.removeEventListener(e,n);this.domListeners=[];for(const t of this.debounceTimers.values())clearTimeout(t);this.debounceTimers.clear()}hideDropdown(t){const e=t.closest(".dropdown-menu").closest(".dropdown");if(!e)return;const n=e.querySelector('[data-bs-toggle="dropdown"]');if(n&&window.bootstrap?.Dropdown){const t=window.bootstrap.Dropdown.getInstance(n);t?.hide()}}hideTooltip(t){if(t&&window.bootstrap?.Tooltip){const e=window.bootstrap.Tooltip.getInstance(t);e&&e.dispose()}}hideAllTooltips(){window.bootstrap?.Tooltip&&document.querySelectorAll('[data-bs-toggle="tooltip"]').forEach(t=>{const e=window.bootstrap.Tooltip.getInstance(t);e&&e.hide()})}async dispatch(t,e,n){const i=this.view,s=t=>t.includes("-")?t.split("-").map(t=>t[0].toUpperCase()+t.slice(1)).join(""):t[0].toUpperCase()+t.slice(1),r=`handleAction${s(t)}`;if("function"==typeof i[r])try{return e.preventDefault(),await i[r](e,n),!0}catch(h){return console.error(`Error in action ${t}:`,h),i.handleActionError(t,h,e,n),!0}const o=`onAction${s(t)}`;if("function"==typeof i[o])try{return!!(await i[o](e,n))&&(!!n.closest(".dropdown-menu")&&this.hideDropdown(n),e.preventDefault(),e.stopPropagation(),!0)}catch(h){return console.error(`Error in action ${t}:`,h),i.handleActionError(t,h,e,n),!0}const a=`onPassThruAction${s(t)}`;if("function"==typeof i[a])try{return await i[a](e,n),!1}catch(h){return console.error(`Error in action ${t}:`,h),i.handleActionError(t,h,e,n),!0}if("function"==typeof i.onActionDefault)try{return await i.onActionDefault(t,e,n)}catch(h){return console.error(`Error in default action handler for ${t}:`,h),i.handleActionError(t,h,e,n),!0}return i.emit?.(`action:${t}`,{action:t,event:e,element:n}),!1}async dispatchChange(t,e,n){const i=this.view,s=`onChange${r=t,r.includes("-")?r.split("-").map(t=>t[0].toUpperCase()+t.slice(1)).join(""):r[0].toUpperCase()+r.slice(1)}`;var r;if("function"==typeof i[s])try{return await i[s](e,n),!0}catch(o){return console.error(`Error in onChange ${t}:`,o),i.handleActionError?.(t,o,e,n),!0}return await this.dispatch(t,e,n)}isFormControl(t){if(!t||!t.tagName)return!1;const e=t.tagName;return"INPUT"===e||"TEXTAREA"===e||"SELECT"===e}shouldHandle(t,e){return!!this.owns(t)||!(!this.contains(t)||e.handledByChild)}owns(t){const e=this.view.element;if(!e||!e.contains(t))return!1;for(const n of Object.values(this.view.children))if(n.element&&n.element.contains(t))return!1;return!0}contains(t){return!!this.view.element&&this.view.element.contains(t)}}"undefined"!=typeof window&&(window.Mustache=c);class View{constructor(t={}){this.tagName=t.tagName??"div",this.className=t.className??"mojo-view",this.style=t.style??null,this.id=t.id??View._genId(),this.containerId=t.containerId??null,this.container=t.container??null,"string"==typeof this.container&&(this.containerId=this.container,this.container=null),this.parent=t.parent??null,this.children=t.children??{},this.template=t.template||t.templateUrl||"",this.data=t.data??{},this.isRendering=!1,this.lastRenderTime=0,this.mounted=!1,this.debug=t.debug??!1,this.app=t.app??null,this.cacheTemplate=t.cacheTemplate??!0,this.enableTooltips=t.enableTooltips??!1,this.options={...t},this.element=this._ensureElement(),this.events=new EventDelegate(this),t.model&&this.setModel(t.model)}async onInit(){}async onInitView(){this.initialized||(this.initialized=!0,await this.onInit())}async onBeforeRender(){}async onAfterRender(){}async onBeforeMount(){}async onAfterMount(){}async onBeforeUnmount(){}async onAfterUnmount(){}async onBeforeDestroy(){}async onAfterDestroy(){}setModel(t={}){let e=t!==this.model;if(!e)return this;this.model&&this.model.off&&this.model.off("change",this._onModelChange,this),this.model=t,this.model&&this.model.on&&this.model.on("change",this._onModelChange,this);for(const n in this.children){const e=this.children[n];e&&"function"==typeof e.setModel&&e.setModel(t)}return e&&this._onModelChange(),this}_onModelChange(){this.isMounted()&&this.render()}setTemplate(t){return this.template=t??"",this}addChild(t,e){try{if(!t||"object"!=typeof t)return this;e&&((e.containerId||e.container)&&(t.containerId=e.containerId||e.container),e.id&&(t.id=e.id),!0===e.lazyMount&&(t._lazyMount=!0)),t.parent=this,this.getApp()&&(t.app=this.app),this.children[t.id]=t}catch(n){View._warn("addChild error",n)}return t}removeChild(t){try{const e="string"==typeof t?t:t&&t.id;if(!e)return this;const n=this.children[e];n&&(Promise.resolve(n.destroy()).catch(t=>View._warn("removeChild destroy error",t)),delete this.children[e])}catch(e){View._warn("removeChild error",e)}return this}getChild(t){return this.children[t]}async updateData(t,e=!1){return Object.assign(this.data,t),e&&this.isMounted()&&await this.render(),this}toggleClass(t,e){return void 0===e&&(e=!this.element.classList.contains(t)),this.element.classList.toggle(t,e),this}addClass(t){return this.element.classList.add(t),this}setClass(t){return this.element.className=t,this}removeClass(t){return this.element.classList.remove(t),this}canRender(){if(this.isRendering)return!1;const t=Date.now();if(this.options.renderCooldown>0&&t-this.lastRenderTime<this.options.renderCooldown)return View._warn(`View ${this.id}: Render called too quickly, cooldown active`),!1;if(this.options.noAppend&&this.parent){if(!this.parent.contains(this.containerId||this.container))return!1;if(this.containerId&&!document.getElementById(this.containerId))return!1;if(this.container&&!document.contains(this.container))return!1}return!0}async render(t=!0,e=null){const n=Date.now();if(!this.canRender())return this;this.isRendering=!0,this.lastRenderTime=n;try{this.initialized||await this.onInitView(),this.unbindEvents(),await this.onBeforeRender(),this.getViewData&&(this.data=await this.getViewData());const n=await this.renderTemplate();this.element.innerHTML=n,t&&!this.isMounted()&&await this.mount(e),await this._renderChildren(),await this.onAfterRender(),this.bindEvents()}catch(i){View._warn(`Render error in ${this.id}`,i)}finally{this.isRendering=!1}return this}async _renderChildren(){const t=[];for(const e in this.children){const n=this.children[e];n&&(n.parent=this,!n._lazyMount||n._lazyTriggered?await Promise.resolve(n.render()).catch(t=>View._warn(`Child render error (${e})`,t)):t.push(n))}t.length&&this._setupLazyMountObserver(t)}_setupLazyMountObserver(t){if("undefined"!=typeof IntersectionObserver){this._lazyObserver||(this._lazyObserver=new IntersectionObserver((t,e)=>{for(const n of t){if(!n.isIntersecting)continue;const t=n.target.__mojoLazyChild;e.unobserve(n.target),t&&!t._lazyTriggered&&(t._lazyTriggered=!0,Promise.resolve(t.render()).catch(e=>View._warn(`Lazy child render error (${t.id})`,e)))}},{rootMargin:"120px 0px",threshold:.01}));for(const e of t){const t=this.getChildElement(e.containerId);t&&(t.__mojoLazyChild=e,t.style.minHeight||(t.classList.add("mojo-lazy-placeholder"),t.style.minHeight="1px"),this._lazyObserver.observe(t),requestAnimationFrame(()=>{if(e._lazyTriggered)return;const n=t.getBoundingClientRect(),i="undefined"!=typeof window?window.innerHeight:0,s="undefined"!=typeof window?window.innerWidth:0;n.top<i+120&&n.bottom>-120&&n.left<s&&n.right>0&&(e._lazyTriggered=!0,this._lazyObserver?.unobserve(t),Promise.resolve(e.render()).catch(t=>View._warn(`Lazy child render error (${e.id})`,t)))}))}}else t.forEach(t=>{t._lazyTriggered=!0,Promise.resolve(t.render()).catch(e=>View._warn(`Lazy child render error (${t.id})`,e))})}async _unmountChildren(){for(const t in this.children){const e=this.children[t];e&&e.unbindEvents()}}isMounted(){return this.element?.isConnected}getChildElementById(t,e=null){const n=t.startsWith("#")?t.substring(1):t;return e?e.querySelector(`#${n}`):this.element.querySelector(`#${n}`)}getChildElement(t){if(t.startsWith("#"))return this.getChildElementById(t);let e=this.element?.querySelector(`[data-container="${t}"]`);return e||this.getChildElementById(t)}getContainer(){return this.replaceById?this.parent?this.parent.getChildElementById(this.id):null:this.containerId?this.parent?this.parent.getChildElement(this.containerId):this.getChildElementById(this.containerId,document.body):null}async mount(t=null){await this.onBeforeMount(),t||(t=this.getContainer()),!this.containerId||t?(t&&this.replaceById?t.replaceWith(this.element):t?t.replaceChildren(this.element):!this.containerId&&this.parent?this.parent.element.appendChild(this.element):this.containerId||this.parent||!this.options.allowAppendToBody?console.error(`Container not found for ${this.containerId}`):document.body.appendChild(this.element),await this.onAfterMount(),this.mounted=!0):console.error(`Container not found for ${this.containerId}`)}async unmount(){this.element&&this.element.parentNode&&(await this.onBeforeUnmount(),await this._unmountChildren(),this.element.parentNode&&this.element.parentNode.removeChild(this.element),this.events.unbind(),await this.onAfterUnmount(),this.mounted=!1)}async destroy(){try{this.events.unbind(),this._lazyObserver&&(this._lazyObserver.disconnect(),this._lazyObserver=null);for(const t in this.children){const e=this.children[t];e&&await Promise.resolve(e.destroy()).catch(e=>View._warn(`Child destroy error (${t})`,e))}this.mounted=!1,this.element&&this.element.parentNode&&(await this.onBeforeDestroy(),this.element.parentNode&&this.element.parentNode.removeChild(this.element),await this.onAfterDestroy())}catch(t){View._warn(`Destroy error in ${this.id}`,t)}}_ensureElement(){try{if(this.element&&this.element.tagName?.toLowerCase()===this.tagName)return this._syncAttrs(),this.element;const t=document.createElement(this.tagName);return this.element=t,this.el=t,this._syncAttrs(),t}catch(t){View._warn("ensureElement error",t);const e=document.createElement("div");return e.id=this.id||View._genId(),e}}_syncAttrs(){try{if(!this.element)return;this.id&&(this.element.id=this.id),this.element.className=this.className||"",null==this.style?this.element.removeAttribute("style"):this.element.style.cssText=String(this.style)}catch(t){View._warn("_syncAttrs error",t)}}bindEvents(){this.events.bind(this.element),this.enableTooltips&&this.initializeTooltips()}unbindEvents(){this.events.unbind(),this.enableTooltips&&this.disposeTooltips()}async renderTemplate(){const t=await this.getTemplate();if(!t)return"";const e=this.getPartials();return c.render(t,this,e)}renderTemplateString(t,e,n){return c.render(t,e,n)}getPartials(){return{}}async getTemplate(){if(this._templateCache&&this.cacheTemplate)return this._templateCache;const t=this.template||this.templateUrl;if(!t)throw new Error("Template not found");let e="";if("string"==typeof t)if(t.includes("<")||t.includes("{"))e=t;else try{let n=t;this.app||(this.app=this.getApp()),!this.app||!this.app.basePath||n.startsWith("/")||n.startsWith("http://")||n.startsWith("https://")||(n=`${this.app.basePath.endsWith("/")?this.app.basePath.slice(0,-1):this.app.basePath}/${n}`);const i=await fetch(n);if(!i.ok)throw new Error(`HTTP ${i.status}: ${i.statusText}`);e=await i.text()}catch(n){View._warn(`Failed to load template from ${t}: ${n}`),this.showError?.(`Failed to load template from ${t}: ${n.message}`)}else"function"==typeof t&&(e=await this.template(this.data,this.state));return this.cacheTemplate&&e&&(this._templateCache=e),e}getContextValue(e){const n=t.MOJOUtils.getContextData(this,e);return e&&e.startsWith("data.")&&n&&"object"==typeof n?t.MOJOUtils.wrapData(n,this):e&&e.startsWith("model.")&&"model"!==e&&n&&"object"==typeof n&&"function"!=typeof n.getContextValue?t.MOJOUtils.wrapData(n,null):n}async handlePageNavigation(t){const e=t.getAttribute("data-page"),n=t.getAttribute("data-params");let i={};if(n)try{i=JSON.parse(n)}catch(o){console.warn("Invalid JSON in data-params:",n)}const s=this.getApp();if(s)return void s.showPage(e,i);const r=this.findRouter();r&&"function"==typeof r.navigateToPage?await r.navigateToPage(e,i):console.error(`No router found for page navigation to '${e}'`)}async handleHrefNavigation(t){const e=t.getAttribute("href");if(this.isExternalLink(e)||t.hasAttribute("data-external"))return;const n=this.findRouter();if(n){if(n.options&&"param"===n.options.mode&&e.startsWith("?")){const t="/"+e;return void(await n.navigate(t))}if(n.options&&"hash"===n.options.mode&&e.startsWith("#"))return void(await n.navigate(e));const t=this.hrefToRoutePath(e);await n.navigate(t)}else console.warn("No router found for navigation, using default behavior"),window.location.href=e}isExternalLink(t){return!t||(t.startsWith("/")&&this.getApp()?!t.startsWith(this.findRouter().basePath):t.startsWith("#")||t.startsWith("mailto:")||t.startsWith("tel:")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//"))}hrefToRoutePath(t){if(t.startsWith("/")){const e=this.findRouter();if(e&&e.options&&e.options.base){const n=e.options.base;if(t.startsWith(n))return t.substring(n.length)||"/"}return t}return t.startsWith("./")?t.substring(2):t}findRouter(){return this.getApp(),this.app?.router||null}getApp(){if(this.app)return this.app;const t=[window.__app__,window.MOJO?.app,window.APP,window.app,window.WebApp,window.matchUUID?window[window.matchUUID]():window[window.matchUUID]];return this.app=t.find(t=>t&&"function"==typeof t.showPage)||null,this.app}handleActionError(t,e,n,i){this.showError(`Action '${t}' failed: ${e}`,n,i)}escapeHtml(t){if("string"!=typeof t)return t;const e=document.createElement("div");return e.textContent=t,e.innerHTML}contains(t){if("string"==typeof t){if(!this.element)return!1;t=document.getElementById(t)}return!!t&&this.element.contains(t)}initializeTooltips(){this.element&&window.bootstrap?.Tooltip&&(this.disposeTooltips(),[...this.element.querySelectorAll('[data-bs-toggle="tooltip"]')].map(t=>{const e=t.getAttribute("data-tooltip-theme"),n=t.getAttribute("data-tooltip-size");let i="";e&&(i+=`tooltip-${e} `),n&&(i+=`tooltip-${n}`);const s={},r=i.trim();return r&&(s.customClass=r),new window.bootstrap.Tooltip(t,s)}))}disposeTooltips(){this.element&&window.bootstrap?.Tooltip&&this.element.querySelectorAll('[data-bs-toggle="tooltip"]').forEach(t=>{const e=window.bootstrap.Tooltip.getInstance(t);e&&e.dispose()})}async showError(t){console.error(`View ${this.id} error:`,t);const e=this.getApp?this.getApp():this.app||null;e&&"function"==typeof e.showError?await e.showError(t):alert(`Error: ${t}`)}async showSuccess(t){this.debug&&this.id;const e=this.getApp?this.getApp():this.app||null;e&&"function"==typeof e.showSuccess?await e.showSuccess(t):alert(`Success: ${t}`)}async showInfo(t){this.id;const e=this.getApp?this.getApp():this.app||null;e&&"function"==typeof e.showInfo?await e.showInfo(t):alert(`Info: ${t}`)}async showWarning(t){console.warn(`View ${this.id} warning:`,t);const e=this.getApp?this.getApp():this.app||null;e&&"function"==typeof e.showWarning?await e.showWarning(t):alert(`Warning: ${t}`)}async onActionCopyToClipboard(t,e){try{const t=e?.closest("[data-clipboard]")||e,n=t?.getAttribute("data-clipboard")||"";if(!n)return!0;if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(n);else{const t=document.createElement("textarea");t.value=n,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}const i=e.querySelector("i"),s=i&&i.className;return i&&(i.className="bi bi-check",setTimeout(()=>{i.className=s},1e3)),!0}catch(n){return console.warn("Copy to clipboard failed:",n),!0}}static _genId(){return`view_${Math.random().toString(36).substr(2,9)}`}static _warn(t,e){try{e?console.warn(`[View] ${t}:`,e):console.warn(`[View] ${t}`)}catch{}}}Object.assign(View.prototype,t.EventEmitter),exports.EventDelegate=EventDelegate,exports.Mustache=c,exports.View=View;
|
|
2
|
+
//# sourceMappingURL=View-CPWwS19u.js.map
|