eleva 1.0.0-rc.6 → 1.0.0-rc.7
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/README.md +133 -4
- package/dist/eleva-plugins.cjs.js +645 -43
- package/dist/eleva-plugins.cjs.js.map +1 -1
- package/dist/eleva-plugins.esm.js +645 -44
- package/dist/eleva-plugins.esm.js.map +1 -1
- package/dist/eleva-plugins.umd.js +645 -43
- package/dist/eleva-plugins.umd.js.map +1 -1
- package/dist/eleva-plugins.umd.min.js +2 -2
- package/dist/eleva-plugins.umd.min.js.map +1 -1
- package/dist/eleva.cjs.js +31 -25
- package/dist/eleva.cjs.js.map +1 -1
- package/dist/eleva.esm.js +31 -25
- package/dist/eleva.esm.js.map +1 -1
- package/dist/eleva.umd.js +31 -25
- package/dist/eleva.umd.js.map +1 -1
- package/dist/eleva.umd.min.js +2 -2
- package/dist/eleva.umd.min.js.map +1 -1
- package/dist/plugins/attr.umd.js +2 -2
- package/dist/plugins/attr.umd.js.map +1 -1
- package/dist/plugins/attr.umd.min.js +1 -1
- package/dist/plugins/attr.umd.min.js.map +1 -1
- package/dist/plugins/props.umd.js +18 -15
- package/dist/plugins/props.umd.js.map +1 -1
- package/dist/plugins/props.umd.min.js +1 -1
- package/dist/plugins/props.umd.min.js.map +1 -1
- package/dist/plugins/router.umd.js +22 -25
- package/dist/plugins/router.umd.js.map +1 -1
- package/dist/plugins/router.umd.min.js +1 -1
- package/dist/plugins/router.umd.min.js.map +1 -1
- package/dist/plugins/store.umd.js +632 -0
- package/dist/plugins/store.umd.js.map +1 -0
- package/dist/plugins/store.umd.min.js +3 -0
- package/dist/plugins/store.umd.min.js.map +1 -0
- package/package.json +4 -4
- package/src/plugins/Store.js +741 -0
- package/src/plugins/index.js +6 -1
- package/types/plugins/Store.d.ts +86 -0
- package/types/plugins/Store.d.ts.map +1 -0
- package/types/plugins/index.d.ts +1 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! Eleva Plugins v1.0.0-rc.
|
|
2
|
-
var e,t;e=this,t=function(e){"use strict";const t=/-([a-z])/g,r={name:"attr",version:"1.0.0-rc.1",description:"Advanced attribute handling for Eleva components",install(e,r={}){const{enableAria:n=!0,enableData:o=!0,enableBoolean:a=!0,enableDynamic:i=!0}=r,s=(e,r)=>{const s=e.attributes,u=r.attributes;for(let r=0;r<u.length;r++){const{name:s,value:l}=u[r];if(!s.startsWith("@")&&e.getAttribute(s)!==l)if(n&&s.startsWith("aria-"))e["aria"+s.slice(5).replace(t,(e,t)=>t.toUpperCase())]=l,e.setAttribute(s,l);else if(o&&s.startsWith("data-"))e.dataset[s.slice(5)]=l,e.setAttribute(s,l);else{let r=s.replace(t,(e,t)=>t.toUpperCase());if(i&&!(r in e)&&!Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e),r)){const t=Object.getOwnPropertyNames(Object.getPrototypeOf(e)).find(e=>e.toLowerCase()===s.toLowerCase()||e.toLowerCase().includes(s.toLowerCase())||s.toLowerCase().includes(e.toLowerCase()));t&&(r=t)}const n=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e),r);if(r in e||n)if(a)if("boolean"==typeof e[r]||n?.get&&"boolean"==typeof n.get.call(e)){const t="false"!==l&&(""===l||l===r||"true"===l);e[r]=t,t?e.setAttribute(s,""):e.removeAttribute(s)}else e[r]=l,e.setAttribute(s,l);else e[r]=l,e.setAttribute(s,l);else e.setAttribute(s,l)}}for(let t=s.length-1;t>=0;t--){const n=s[t].name;r.hasAttribute(n)||e.removeAttribute(n)}};e.renderer&&(e.renderer.updateAttributes=s,e.renderer._originalPatchNode=e.renderer._patchNode,e.renderer._patchNode=function(e,t){e?._eleva_instance||(this._isSameNode(e,t)?e.nodeType===Node.ELEMENT_NODE?(s(e,t),this._diff(e,t)):e.nodeType===Node.TEXT_NODE&&e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue):e.replaceWith(t.cloneNode(!0)))}),e.plugins||(e.plugins=new Map),e.plugins.set(this.name,{name:this.name,version:this.version,description:this.description,options:r}),e.updateElementAttributes=s},uninstall(e){e.renderer&&e.renderer._originalPatchNode&&(e.renderer._patchNode=e.renderer._originalPatchNode,delete e.renderer._originalPatchNode),e.plugins&&e.plugins.delete(this.name),delete e.updateElementAttributes}},n={handle(e,t,r={}){const n=new Error(`[ElevaRouter] ${t}: ${e.message}`);throw n.originalError=e,n.context=t,n.details=r,n},warn(e,t={}){},log(e,t,r={}){}};class o{constructor(e,t={}){this.eleva=e,this.options={mode:"hash",queryParam:"view",viewSelector:"root",...t},this.routes=this._processRoutes(t.routes||[]),this.emitter=this.eleva.emitter,this.isStarted=!1,this._isNavigating=!1,this.eventListeners=[],this.currentRoute=new this.eleva.signal(null),this.previousRoute=new this.eleva.signal(null),this.currentParams=new this.eleva.signal({}),this.currentQuery=new this.eleva.signal({}),this.currentLayout=new this.eleva.signal(null),this.currentView=new this.eleva.signal(null),this.plugins=new Map,this.errorHandler=n,this._validateOptions()}_validateOptions(){["hash","query","history"].includes(this.options.mode)||this.errorHandler.handle(new Error(`Invalid routing mode: ${this.options.mode}. Must be "hash", "query", or "history".`),"Configuration validation failed")}_processRoutes(e){const t=[];for(const r of e)try{t.push({...r,segments:this._parsePathIntoSegments(r.path)})}catch(e){this.errorHandler.warn(`Invalid path in route definition "${r.path||"undefined"}": ${e.message}`,{route:r,error:e})}return t}_parsePathIntoSegments(e){e&&"string"==typeof e||this.errorHandler.handle(new Error("Route path must be a non-empty string"),"Path parsing failed",{path:e});const t=e.replace(/\/+/g,"/").replace(/\/$/,"")||"/";return"/"===t?[]:t.split("/").filter(Boolean).map(t=>{if(t.startsWith(":")){const r=t.substring(1);return r||this.errorHandler.handle(new Error(`Invalid parameter segment: ${t}`),"Path parsing failed",{segment:t,path:e}),{type:"param",name:r}}return{type:"static",value:t}})}_findViewElement(e){const t=this.options.viewSelector;return e.querySelector(`#${t}`)||e.querySelector(`.${t}`)||e.querySelector(`[data-${t}]`)||e.querySelector(t)||e}async start(){if(this.isStarted)return void this.errorHandler.warn("Router is already started");if("undefined"==typeof window)return void this.errorHandler.warn("Router start skipped: `window` object not available (SSR environment)");if("undefined"!=typeof document&&!document.querySelector(this.options.mount))return void this.errorHandler.warn(`Mount element "${this.options.mount}" was not found in the DOM. The router will not start.`,{mountSelector:this.options.mount});const e=()=>this._handleRouteChange();"hash"===this.options.mode?(window.addEventListener("hashchange",e),this.eventListeners.push(()=>window.removeEventListener("hashchange",e))):(window.addEventListener("popstate",e),this.eventListeners.push(()=>window.removeEventListener("popstate",e))),this.isStarted=!0,await this._handleRouteChange()}async destroy(){if(this.isStarted){for(const e of this.plugins.values())if("function"==typeof e.destroy)try{await e.destroy(this)}catch(t){this.errorHandler.log(`Plugin ${e.name} destroy failed`,t)}this.eventListeners.forEach(e=>e()),this.eventListeners=[],this.currentLayout.value&&await this.currentLayout.value.unmount(),this.isStarted=!1}}async navigate(e,t={}){try{const r="string"==typeof e?{path:e,params:t}:e;let n=this._buildPath(r.path,r.params||{});const o=r.query||{};if(Object.keys(o).length>0){const e=new URLSearchParams(o).toString();e&&(n+=`?${e}`)}if(this._isSameRoute(n,r.params,o))return;if(await this._proceedWithNavigation(n)){this._isNavigating=!0;const e=r.state||{},t=r.replace||!1,o=t?"replaceState":"pushState";if("hash"===this.options.mode)if(t){const t=`${window.location.pathname}${window.location.search}#${n}`;window.history.replaceState(e,"",t)}else window.location.hash=n;else{const t="query"===this.options.mode?this._buildQueryUrl(n):n;history[o](e,"",t)}queueMicrotask(()=>{this._isNavigating=!1})}}catch(e){this.errorHandler.log("Navigation failed",e),await this.emitter.emit("router:onError",e)}}_buildQueryUrl(e){const t=new URLSearchParams(window.location.search);return t.set(this.options.queryParam,e.split("?")[0]),`${window.location.pathname}?${t.toString()}`}_isSameRoute(e,t,r){const n=this.currentRoute.value;if(!n)return!1;const[o,a]=e.split("?"),i=r||this._parseQuery(a||"");return n.path===o&&JSON.stringify(n.params)===JSON.stringify(t||{})&&JSON.stringify(n.query)===JSON.stringify(i)}_buildPath(e,t){let r=e;for(const[e,n]of Object.entries(t)){const t=encodeURIComponent(String(n));r=r.replace(new RegExp(`:${e}\\b`,"g"),t)}return r}async _handleRouteChange(){if(this._isNavigating)return;const e=this.currentRoute.value,t=this._getCurrentLocation();!await this._proceedWithNavigation(t.fullUrl)&&e&&this.navigate({path:e.path,query:e.query,replace:!0})}async _proceedWithNavigation(e){const t=this.currentRoute.value,[r,n]=(e||"/").split("?"),o={path:r.startsWith("/")?r:`/${r}`,query:this._parseQuery(n),fullUrl:e};let a=this._matchRoute(o.path);if(!a){const e=this.routes.find(e=>"*"===e.path);if(!e)return await this.emitter.emit("router:onError",new Error(`Route not found: ${o.path}`),o,t),!1;a={route:e,params:{pathMatch:o.path.substring(1)}}}const i={...o,params:a.params,meta:a.route.meta||{},name:a.route.name,matched:a.route};try{if(!await this._runGuards(i,t,a.route))return!1;const{layoutComponent:e,pageComponent:r}=await this._resolveComponents(a.route);if(t){const e=async e=>{if(e)try{await e.unmount()}catch(t){this.errorHandler.warn("Error during component unmount",{error:t,instance:e})}};(a.route.layout||this.options.globalLayout)!==(t.matched.layout||this.options.globalLayout)?(await e(this.currentLayout.value),this.currentLayout.value=null):(await e(this.currentView.value),this.currentView.value=null),t.matched.afterLeave&&(await t.matched.afterLeave(i,t),await this.emitter.emit("router:afterLeave",i,t))}return this.previousRoute.value=t,this.currentRoute.value=i,this.currentParams.value=i.params||{},this.currentQuery.value=i.query||{},await this._render(e,r,i),a.route.afterEnter&&(await a.route.afterEnter(i,t),await this.emitter.emit("router:afterEnter",i,t)),await this.emitter.emit("router:afterEach",i,t),!0}catch(e){return this.errorHandler.log("Error during navigation",e,{to:i,from:t}),await this.emitter.emit("router:onError",e,i,t),!1}}async _runGuards(e,t,r){const n=[...this.options.onBeforeEach?[this.options.onBeforeEach]:[],...t&&t.matched.beforeLeave?[t.matched.beforeLeave]:[],...r.beforeEnter?[r.beforeEnter]:[]];for(const r of n){const n=await r(e,t);if(!1===n)return!1;if("string"==typeof n||"object"==typeof n)return this.navigate(n),!1}return!0}_resolveStringComponent(e){const t=this.eleva._components.get(e);return t||this.errorHandler.handle(new Error(`Component "${e}" not registered.`),"Component resolution failed",{componentName:e,availableComponents:Array.from(this.eleva._components.keys())}),t}async _resolveFunctionComponent(e){try{const t=e.toString(),r=t.includes("import(")||t.startsWith("() =>"),n=await e();return r&&n.default||n}catch(t){this.errorHandler.handle(new Error(`Failed to load async component: ${t.message}`),"Component resolution failed",{function:e.toString(),error:t})}}_validateComponentDefinition(e){return e&&"object"==typeof e||this.errorHandler.handle(new Error("Invalid component definition: "+typeof e),"Component validation failed",{definition:e}),"function"!=typeof e.template&&"string"!=typeof e.template&&this.errorHandler.handle(new Error("Component missing template property"),"Component validation failed",{definition:e}),e}async _resolveComponent(e){return null==e?null:"string"==typeof e?this._resolveStringComponent(e):"function"==typeof e?await this._resolveFunctionComponent(e):e&&"object"==typeof e?this._validateComponentDefinition(e):void this.errorHandler.handle(new Error("Invalid component definition: "+typeof e),"Component resolution failed",{definition:e})}async _resolveComponents(e){const t=e.layout||this.options.globalLayout;try{const[r,n]=await Promise.all([this._resolveComponent(t),this._resolveComponent(e.component)]);return n||this.errorHandler.handle(new Error(`Page component is null or undefined for route: ${e.path}`),"Component resolution failed",{route:e.path}),{layoutComponent:r,pageComponent:n}}catch(t){throw this.errorHandler.log(`Error resolving components for route ${e.path}`,t,{route:e.path}),t}}async _render(e,t){const r=document.querySelector(this.options.mount);if(r||this.errorHandler.handle(new Error(`Mount element "${this.options.mount}" not found.`),{mountSelector:this.options.mount}),e){const n=await this.eleva.mount(r,this._wrapComponentWithChildren(e));this.currentLayout.value=n;const o=this._findViewElement(n.container),a=await this.eleva.mount(o,this._wrapComponentWithChildren(t));this.currentView.value=a}else{const e=await this.eleva.mount(r,this._wrapComponentWithChildren(t));this.currentView.value=e,this.currentLayout.value=null}}_createRouteGetter(e,t){return()=>this.currentRoute.value?.[e]??t}_wrapComponent(e){const t=e.setup,r=this;return{...e,setup:async e=>(e.router={navigate:r.navigate.bind(r),current:r.currentRoute,previous:r.previousRoute,get params(){return r._createRouteGetter("params",{})()},get query(){return r._createRouteGetter("query",{})()},get path(){return r._createRouteGetter("path","/")()},get fullUrl(){return r._createRouteGetter("fullUrl",window.location.href)()},get meta(){return r._createRouteGetter("meta",{})()}},t?await t(e):{})}}_wrapComponentWithChildren(e){const t=this._wrapComponent(e);if(t.children&&"object"==typeof t.children){const e={};for(const[r,n]of Object.entries(t.children))e[r]=this._wrapComponentWithChildren(n);t.children=e}return t}_getCurrentLocation(){if("undefined"==typeof window)return{path:"/",query:{},fullUrl:""};let e,t,r;switch(this.options.mode){case"hash":r=window.location.hash.slice(1)||"/",[e,t]=r.split("?");break;case"query":e=new URLSearchParams(window.location.search).get(this.options.queryParam)||"/",t=window.location.search.slice(1),r=e;break;default:e=window.location.pathname||"/",t=window.location.search.slice(1),r=`${e}${t?"?"+t:""}`}return{path:e.startsWith("/")?e:`/${e}`,query:this._parseQuery(t),fullUrl:r}}_parseQuery(e){const t={};return e&&new URLSearchParams(e).forEach((e,r)=>{t[r]=e}),t}_matchRoute(e){const t=e.split("/").filter(Boolean);for(const e of this.routes){if("/"===e.path){if(0===t.length)return{route:e,params:{}};continue}if(e.segments.length!==t.length)continue;const r={};let n=!0;for(let o=0;o<e.segments.length;o++){const a=e.segments[o],i=t[o];if("param"===a.type)r[a.name]=decodeURIComponent(i);else if(a.value!==i){n=!1;break}}if(n)return{route:e,params:r}}return null}onBeforeEach(e){this.options.onBeforeEach=e}onAfterEnter(e){this.emitter.on("router:afterEnter",e)}onAfterLeave(e){this.emitter.on("router:afterLeave",e)}onAfterEach(e){this.emitter.on("router:afterEach",e)}onError(e){this.emitter.on("router:onError",e)}use(e,t={}){"function"!=typeof e.install&&this.errorHandler.handle(new Error("Plugin must have an install method"),"Plugin registration failed",{plugin:e}),this.plugins.has(e.name)?this.errorHandler.warn(`Plugin "${e.name}" is already registered`,{existingPlugin:this.plugins.get(e.name)}):(this.plugins.set(e.name,e),e.install(this,t))}getPlugins(){return Array.from(this.plugins.values())}getPlugin(e){return this.plugins.get(e)}removePlugin(e){const t=this.plugins.get(e);if(!t)return!1;if("function"==typeof t.destroy)try{t.destroy(this)}catch(t){this.errorHandler.log(`Plugin ${e} destroy failed`,t)}return this.plugins.delete(e)}setErrorHandler(e){e&&"function"==typeof e.handle&&"function"==typeof e.warn&&"function"==typeof e.log&&(this.errorHandler=e)}}const a={name:"router",version:"1.0.0-rc.1",description:"Client-side routing for Eleva applications",install(e,t={}){if(!t.mount)throw new Error("[RouterPlugin] 'mount' option is required");if(!t.routes||!Array.isArray(t.routes))throw new Error("[RouterPlugin] 'routes' option must be an array");const r=(t,r)=>{if(!t)return null;if("object"==typeof t&&null!==t&&!t.name){const n=`Eleva${r}Component_${Math.random().toString(36).slice(2,11)}`;try{return e.component(n,t),n}catch(e){throw new Error(`[RouterPlugin] Failed to register ${r} component: ${e.message}`)}}return t};t.globalLayout&&(t.globalLayout=r(t.globalLayout,"GlobalLayout")),(t.routes||[]).forEach(e=>{e.component=r(e.component,"Route"),e.layout&&(e.layout=r(e.layout,"RouteLayout"))});const n=new o(e,t);return e.router=n,!1!==t.autoStart&&queueMicrotask(()=>n.start()),e.plugins||(e.plugins=new Map),e.plugins.set(this.name,{name:this.name,version:this.version,description:this.description,options:t}),e.navigate=n.navigate.bind(n),e.getCurrentRoute=()=>n.currentRoute.value,e.getRouteParams=()=>n.currentParams.value,e.getRouteQuery=()=>n.currentQuery.value,n},async uninstall(e){e.router&&(await e.router.destroy(),delete e.router),e.plugins&&e.plugins.delete(this.name),delete e.navigate,delete e.getCurrentRoute,delete e.getRouteParams,delete e.getRouteQuery}};class i{static expressionPattern=/\{\{\s*(.*?)\s*\}\}/g;static parse(e,t){return"string"!=typeof e?e:e.replace(this.expressionPattern,(e,r)=>this.evaluate(r,t))}static evaluate(e,t){if("string"!=typeof e)return e;try{return new Function("data",`with(data) { return ${e}; }`)(t)}catch{return""}}}const s={name:"props",version:"1.0.0-rc.2",description:"Advanced props data handling for complex data structures with automatic type detection and reactivity",install(e,t={}){const{enableAutoParsing:r=!0,enableReactivity:n=!0,onError:o=null}=t,a=e=>{try{if("string"!=typeof e)return e;if("true"===e)return!0;if("false"===e)return!1;if("null"===e)return null;if("undefined"===e)return;if(e.startsWith("{")||e.startsWith("["))try{return JSON.parse(e)}catch(t){throw new Error(`Invalid JSON: ${e}`)}if("1"===e)return!0;if("0"===e)return!1;if(""===e)return!0;if(!isNaN(e)&&""!==e&&!isNaN(parseFloat(e)))return Number(e);if(e.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/)){const t=new Date(e);if(!isNaN(t.getTime()))return t}return e}catch(t){return o&&o(t,e),e}},s=t=>{const r={};return Object.entries(t).forEach(([t,n])=>{r[t]=n&&"object"==typeof n&&"value"in n&&"watch"in n?n:new e.signal(n)}),r};e._extractProps=e=>{const t={},n=e.attributes;for(let o=n.length-1;o>=0;o--){const i=n[o];if(i.name.startsWith(":")){const n=i.name.slice(1),o=r?a(i.value):i.value;t[n]=o,e.removeAttribute(i.name)}}return t};const u=e.mount;e.mount=async(t,r,o={})=>{const a=n?s(o):o;return await u.call(e,t,r,a)};const l=e._mountComponents,c=new WeakMap,h=new Set;e._mountComponents=async(t,r,o)=>{for(const[a,i]of Object.entries(r))if(a)for(const r of t.querySelectorAll(a)){if(!(r instanceof HTMLElement))continue;const a=e._extractProps(r);let u=a,l=c.get(t);if(!l){let e=t;for(;e&&!l;){if(e._eleva_instance&&e._eleva_instance.data){l=e._eleva_instance.data,c.set(t,l);break}e=e.parentElement}}if(n&&l){const t={};Object.keys(a).forEach(r=>{l[r]&&l[r]instanceof e.signal&&(t[r]=l[r])}),u={...a,...t}}let p=u;if(n){const e={};Object.entries(u).forEach(([t,r])=>{r&&"object"==typeof r&&"value"in r&&"watch"in r||(e[t]=r)}),p={...s(e),...u}}const d=await e.mount(r,i,p);d&&!o.includes(d)&&(o.push(d),n&&Object.keys(a).length>0&&!l&&h.add({instance:d,extractedProps:a,container:t,component:i}))}if(n&&h.size>0)for(const t of h){const{instance:r,extractedProps:n,container:o,component:a}=t;let s=c.get(o);if(!s){let e=o;for(;e&&!s;){if(e._eleva_instance&&e._eleva_instance.data){s=e._eleva_instance.data,c.set(o,s);break}e=e.parentElement}}if(s){const o={};if(Object.keys(n).forEach(t=>{s[t]&&s[t]instanceof e.signal&&(o[t]=s[t])}),Object.keys(o).length>0){Object.assign(r.data,o),Object.keys(o).forEach(t=>{const n=o[t];n&&"function"==typeof n.watch&&n.watch(()=>{const t=e._components.get(a)||a;if(t&&t.template){const n="function"==typeof t.template?t.template(r.data):t.template,o=i.parse(n,r.data);e.renderer.patchDOM(r.container,o)}})});const t=e._components.get(a)||a;if(t&&t.template){const n="function"==typeof t.template?t.template(r.data):t.template,o=i.parse(n,r.data);e.renderer.patchDOM(r.container,o)}}h.delete(t)}}},e.props={parse:e=>r?a(e):e,detectType:e=>null===e?"null":void 0===e?"undefined":"boolean"==typeof e?"boolean":"number"==typeof e?"number":"string"==typeof e?"string":"function"==typeof e?"function":e instanceof Date?"date":e instanceof Map?"map":e instanceof Set?"set":Array.isArray(e)?"array":"object"==typeof e?"object":"unknown"},e._originalExtractProps=e._extractProps,e._originalMount=u,e._originalMountComponents=l},uninstall(e){e._originalExtractProps&&(e._extractProps=e._originalExtractProps,delete e._originalExtractProps),e._originalMount&&(e.mount=e._originalMount,delete e._originalMount),e._originalMountComponents&&(e._mountComponents=e._originalMountComponents,delete e._originalMountComponents),e.props&&delete e.props}};e.Attr=r,e.Props=s,e.Router=a},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ElevaPlugins={});
|
|
1
|
+
/*! Eleva Plugins v1.0.0-rc.7 | MIT License | https://elevajs.com */
|
|
2
|
+
var t,e;t=this,e=function(t){"use strict";const e=/-([a-z])/g,n={name:"attr",version:"1.0.0-rc.1",description:"Advanced attribute handling for Eleva components",install(t,n={}){const{enableAria:r=!0,enableData:o=!0,enableBoolean:i=!0,enableDynamic:s=!0}=n,a=(t,n)=>{const a=t.attributes,l=n.attributes;for(let n=0;n<l.length;n++){const{name:a,value:u}=l[n];if(!a.startsWith("@")&&t.getAttribute(a)!==u)if(r&&a.startsWith("aria-"))t["aria"+a.slice(5).replace(e,(t,e)=>e.toUpperCase())]=u,t.setAttribute(a,u);else if(o&&a.startsWith("data-"))t.dataset[a.slice(5)]=u,t.setAttribute(a,u);else{let n=a.replace(e,(t,e)=>e.toUpperCase());if(s&&!(n in t)&&!Object.getOwnPropertyDescriptor(Object.getPrototypeOf(t),n)){const e=Object.getOwnPropertyNames(Object.getPrototypeOf(t)).find(t=>t.toLowerCase()===a.toLowerCase()||t.toLowerCase().includes(a.toLowerCase())||a.toLowerCase().includes(t.toLowerCase()));e&&(n=e)}const r=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(t),n);if(n in t||r)if(i)if("boolean"==typeof t[n]||(null==r?void 0:r.get)&&"boolean"==typeof r.get.call(t)){const e="false"!==u&&(""===u||u===n||"true"===u);t[n]=e,e?t.setAttribute(a,""):t.removeAttribute(a)}else t[n]=u,t.setAttribute(a,u);else t[n]=u,t.setAttribute(a,u);else t.setAttribute(a,u)}}for(let e=a.length-1;e>=0;e--){const r=a[e].name;n.hasAttribute(r)||t.removeAttribute(r)}};t.renderer&&(t.renderer.updateAttributes=a,t.renderer._originalPatchNode=t.renderer._patchNode,t.renderer._patchNode=function(t,e){null!=t&&t._eleva_instance||(this._isSameNode(t,e)?t.nodeType===Node.ELEMENT_NODE?(a(t,e),this._diff(t,e)):t.nodeType===Node.TEXT_NODE&&t.nodeValue!==e.nodeValue&&(t.nodeValue=e.nodeValue):t.replaceWith(e.cloneNode(!0)))}),t.plugins||(t.plugins=new Map),t.plugins.set(this.name,{name:this.name,version:this.version,description:this.description,options:n}),t.updateElementAttributes=a},uninstall(t){t.renderer&&t.renderer._originalPatchNode&&(t.renderer._patchNode=t.renderer._originalPatchNode,delete t.renderer._originalPatchNode),t.plugins&&t.plugins.delete(this.name),delete t.updateElementAttributes}};function r(){return r=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},r.apply(null,arguments)}const o={handle(t,e,n={}){const r=new Error(`[ElevaRouter] ${e}: ${t.message}`);throw r.originalError=t,r.context=e,r.details=n,r},warn(t,e={}){},log(t,e,n={}){}};class i{constructor(t,e={}){this.eleva=t,this.options=r({mode:"hash",queryParam:"view",viewSelector:"root"},e),this.routes=this._processRoutes(e.routes||[]),this.emitter=this.eleva.emitter,this.isStarted=!1,this._isNavigating=!1,this.eventListeners=[],this.currentRoute=new this.eleva.signal(null),this.previousRoute=new this.eleva.signal(null),this.currentParams=new this.eleva.signal({}),this.currentQuery=new this.eleva.signal({}),this.currentLayout=new this.eleva.signal(null),this.currentView=new this.eleva.signal(null),this.plugins=new Map,this.errorHandler=o,this._validateOptions()}_validateOptions(){["hash","query","history"].includes(this.options.mode)||this.errorHandler.handle(new Error(`Invalid routing mode: ${this.options.mode}. Must be "hash", "query", or "history".`),"Configuration validation failed")}_processRoutes(t){const e=[];for(const n of t)try{e.push(r({},n,{segments:this._parsePathIntoSegments(n.path)}))}catch(t){this.errorHandler.warn(`Invalid path in route definition "${n.path||"undefined"}": ${t.message}`,{route:n,error:t})}return e}_parsePathIntoSegments(t){t&&"string"==typeof t||this.errorHandler.handle(new Error("Route path must be a non-empty string"),"Path parsing failed",{path:t});const e=t.replace(/\/+/g,"/").replace(/\/$/,"")||"/";return"/"===e?[]:e.split("/").filter(Boolean).map(e=>{if(e.startsWith(":")){const n=e.substring(1);return n||this.errorHandler.handle(new Error(`Invalid parameter segment: ${e}`),"Path parsing failed",{segment:e,path:t}),{type:"param",name:n}}return{type:"static",value:e}})}_findViewElement(t){const e=this.options.viewSelector;return t.querySelector(`#${e}`)||t.querySelector(`.${e}`)||t.querySelector(`[data-${e}]`)||t.querySelector(e)||t}async start(){if(this.isStarted)return void this.errorHandler.warn("Router is already started");if("undefined"==typeof window)return void this.errorHandler.warn("Router start skipped: `window` object not available (SSR environment)");if("undefined"!=typeof document&&!document.querySelector(this.options.mount))return void this.errorHandler.warn(`Mount element "${this.options.mount}" was not found in the DOM. The router will not start.`,{mountSelector:this.options.mount});const t=()=>this._handleRouteChange();"hash"===this.options.mode?(window.addEventListener("hashchange",t),this.eventListeners.push(()=>window.removeEventListener("hashchange",t))):(window.addEventListener("popstate",t),this.eventListeners.push(()=>window.removeEventListener("popstate",t))),this.isStarted=!0,await this._handleRouteChange()}async destroy(){if(this.isStarted){for(const t of this.plugins.values())if("function"==typeof t.destroy)try{await t.destroy(this)}catch(e){this.errorHandler.log(`Plugin ${t.name} destroy failed`,e)}this.eventListeners.forEach(t=>t()),this.eventListeners=[],this.currentLayout.value&&await this.currentLayout.value.unmount(),this.isStarted=!1}}async navigate(t,e={}){try{const n="string"==typeof t?{path:t,params:e}:t;let r=this._buildPath(n.path,n.params||{});const o=n.query||{};if(Object.keys(o).length>0){const t=new URLSearchParams(o).toString();t&&(r+=`?${t}`)}if(this._isSameRoute(r,n.params,o))return;if(await this._proceedWithNavigation(r)){this._isNavigating=!0;const t=n.state||{},e=n.replace||!1,o=e?"replaceState":"pushState";if("hash"===this.options.mode)if(e){const e=`${window.location.pathname}${window.location.search}#${r}`;window.history.replaceState(t,"",e)}else window.location.hash=r;else{const e="query"===this.options.mode?this._buildQueryUrl(r):r;history[o](t,"",e)}queueMicrotask(()=>{this._isNavigating=!1})}}catch(t){this.errorHandler.log("Navigation failed",t),await this.emitter.emit("router:onError",t)}}_buildQueryUrl(t){const e=new URLSearchParams(window.location.search);return e.set(this.options.queryParam,t.split("?")[0]),`${window.location.pathname}?${e.toString()}`}_isSameRoute(t,e,n){const r=this.currentRoute.value;if(!r)return!1;const[o,i]=t.split("?"),s=n||this._parseQuery(i||"");return r.path===o&&JSON.stringify(r.params)===JSON.stringify(e||{})&&JSON.stringify(r.query)===JSON.stringify(s)}_buildPath(t,e){let n=t;for(const[t,r]of Object.entries(e)){const e=encodeURIComponent(String(r));n=n.replace(new RegExp(`:${t}\\b`,"g"),e)}return n}async _handleRouteChange(){if(this._isNavigating)return;const t=this.currentRoute.value,e=this._getCurrentLocation();!await this._proceedWithNavigation(e.fullUrl)&&t&&this.navigate({path:t.path,query:t.query,replace:!0})}async _proceedWithNavigation(t){const e=this.currentRoute.value,[n,o]=(t||"/").split("?"),i={path:n.startsWith("/")?n:`/${n}`,query:this._parseQuery(o),fullUrl:t};let s=this._matchRoute(i.path);if(!s){const t=this.routes.find(t=>"*"===t.path);if(!t)return await this.emitter.emit("router:onError",new Error(`Route not found: ${i.path}`),i,e),!1;s={route:t,params:{pathMatch:i.path.substring(1)}}}const a=r({},i,{params:s.params,meta:s.route.meta||{},name:s.route.name,matched:s.route});try{if(!await this._runGuards(a,e,s.route))return!1;const{layoutComponent:t,pageComponent:n}=await this._resolveComponents(s.route);if(e){const t=async t=>{if(t)try{await t.unmount()}catch(e){this.errorHandler.warn("Error during component unmount",{error:e,instance:t})}};(s.route.layout||this.options.globalLayout)!==(e.matched.layout||this.options.globalLayout)?(await t(this.currentLayout.value),this.currentLayout.value=null):(await t(this.currentView.value),this.currentView.value=null),e.matched.afterLeave&&(await e.matched.afterLeave(a,e),await this.emitter.emit("router:afterLeave",a,e))}return this.previousRoute.value=e,this.currentRoute.value=a,this.currentParams.value=a.params||{},this.currentQuery.value=a.query||{},await this._render(t,n,a),s.route.afterEnter&&(await s.route.afterEnter(a,e),await this.emitter.emit("router:afterEnter",a,e)),await this.emitter.emit("router:afterEach",a,e),!0}catch(t){return this.errorHandler.log("Error during navigation",t,{to:a,from:e}),await this.emitter.emit("router:onError",t,a,e),!1}}async _runGuards(t,e,n){const r=[...this.options.onBeforeEach?[this.options.onBeforeEach]:[],...e&&e.matched.beforeLeave?[e.matched.beforeLeave]:[],...n.beforeEnter?[n.beforeEnter]:[]];for(const n of r){const r=await n(t,e);if(!1===r)return!1;if("string"==typeof r||"object"==typeof r)return this.navigate(r),!1}return!0}_resolveStringComponent(t){const e=this.eleva._components.get(t);return e||this.errorHandler.handle(new Error(`Component "${t}" not registered.`),"Component resolution failed",{componentName:t,availableComponents:Array.from(this.eleva._components.keys())}),e}async _resolveFunctionComponent(t){try{const e=t.toString(),n=e.includes("import(")||e.startsWith("() =>"),r=await t();return n&&r.default||r}catch(e){this.errorHandler.handle(new Error(`Failed to load async component: ${e.message}`),"Component resolution failed",{function:t.toString(),error:e})}}_validateComponentDefinition(t){return t&&"object"==typeof t||this.errorHandler.handle(new Error("Invalid component definition: "+typeof t),"Component validation failed",{definition:t}),"function"!=typeof t.template&&"string"!=typeof t.template&&this.errorHandler.handle(new Error("Component missing template property"),"Component validation failed",{definition:t}),t}async _resolveComponent(t){return null==t?null:"string"==typeof t?this._resolveStringComponent(t):"function"==typeof t?await this._resolveFunctionComponent(t):t&&"object"==typeof t?this._validateComponentDefinition(t):void this.errorHandler.handle(new Error("Invalid component definition: "+typeof t),"Component resolution failed",{definition:t})}async _resolveComponents(t){const e=t.layout||this.options.globalLayout;try{const[n,r]=await Promise.all([this._resolveComponent(e),this._resolveComponent(t.component)]);return r||this.errorHandler.handle(new Error(`Page component is null or undefined for route: ${t.path}`),"Component resolution failed",{route:t.path}),{layoutComponent:n,pageComponent:r}}catch(e){throw this.errorHandler.log(`Error resolving components for route ${t.path}`,e,{route:t.path}),e}}async _render(t,e){const n=document.querySelector(this.options.mount);if(n||this.errorHandler.handle(new Error(`Mount element "${this.options.mount}" not found.`),{mountSelector:this.options.mount}),t){const r=await this.eleva.mount(n,this._wrapComponentWithChildren(t));this.currentLayout.value=r;const o=this._findViewElement(r.container),i=await this.eleva.mount(o,this._wrapComponentWithChildren(e));this.currentView.value=i}else{const t=await this.eleva.mount(n,this._wrapComponentWithChildren(e));this.currentView.value=t,this.currentLayout.value=null}}_createRouteGetter(t,e){return()=>{var n,r;return null!=(n=null==(r=this.currentRoute.value)?void 0:r[t])?n:e}}_wrapComponent(t){const e=t.setup,n=this;return r({},t,{setup:async t=>(t.router={navigate:n.navigate.bind(n),current:n.currentRoute,previous:n.previousRoute,get params(){return n._createRouteGetter("params",{})()},get query(){return n._createRouteGetter("query",{})()},get path(){return n._createRouteGetter("path","/")()},get fullUrl(){return n._createRouteGetter("fullUrl",window.location.href)()},get meta(){return n._createRouteGetter("meta",{})()}},e?await e(t):{})})}_wrapComponentWithChildren(t){const e=this._wrapComponent(t);if(e.children&&"object"==typeof e.children){const t={};for(const[n,r]of Object.entries(e.children))t[n]=this._wrapComponentWithChildren(r);e.children=t}return e}_getCurrentLocation(){if("undefined"==typeof window)return{path:"/",query:{},fullUrl:""};let t,e,n;switch(this.options.mode){case"hash":n=window.location.hash.slice(1)||"/",[t,e]=n.split("?");break;case"query":t=new URLSearchParams(window.location.search).get(this.options.queryParam)||"/",e=window.location.search.slice(1),n=t;break;default:t=window.location.pathname||"/",e=window.location.search.slice(1),n=`${t}${e?"?"+e:""}`}return{path:t.startsWith("/")?t:`/${t}`,query:this._parseQuery(e),fullUrl:n}}_parseQuery(t){const e={};return t&&new URLSearchParams(t).forEach((t,n)=>{e[n]=t}),e}_matchRoute(t){const e=t.split("/").filter(Boolean);for(const t of this.routes){if("/"===t.path){if(0===e.length)return{route:t,params:{}};continue}if(t.segments.length!==e.length)continue;const n={};let r=!0;for(let o=0;o<t.segments.length;o++){const i=t.segments[o],s=e[o];if("param"===i.type)n[i.name]=decodeURIComponent(s);else if(i.value!==s){r=!1;break}}if(r)return{route:t,params:n}}return null}onBeforeEach(t){this.options.onBeforeEach=t}onAfterEnter(t){this.emitter.on("router:afterEnter",t)}onAfterLeave(t){this.emitter.on("router:afterLeave",t)}onAfterEach(t){this.emitter.on("router:afterEach",t)}onError(t){this.emitter.on("router:onError",t)}use(t,e={}){"function"!=typeof t.install&&this.errorHandler.handle(new Error("Plugin must have an install method"),"Plugin registration failed",{plugin:t}),this.plugins.has(t.name)?this.errorHandler.warn(`Plugin "${t.name}" is already registered`,{existingPlugin:this.plugins.get(t.name)}):(this.plugins.set(t.name,t),t.install(this,e))}getPlugins(){return Array.from(this.plugins.values())}getPlugin(t){return this.plugins.get(t)}removePlugin(t){const e=this.plugins.get(t);if(!e)return!1;if("function"==typeof e.destroy)try{e.destroy(this)}catch(e){this.errorHandler.log(`Plugin ${t} destroy failed`,e)}return this.plugins.delete(t)}setErrorHandler(t){t&&"function"==typeof t.handle&&"function"==typeof t.warn&&"function"==typeof t.log&&(this.errorHandler=t)}}const s={name:"router",version:"1.0.0-rc.1",description:"Client-side routing for Eleva applications",install(t,e={}){if(!e.mount)throw new Error("[RouterPlugin] 'mount' option is required");if(!e.routes||!Array.isArray(e.routes))throw new Error("[RouterPlugin] 'routes' option must be an array");const n=(e,n)=>{if(!e)return null;if("object"==typeof e&&null!==e&&!e.name){const r=`Eleva${n}Component_${Math.random().toString(36).slice(2,11)}`;try{return t.component(r,e),r}catch(t){throw new Error(`[RouterPlugin] Failed to register ${n} component: ${t.message}`)}}return e};e.globalLayout&&(e.globalLayout=n(e.globalLayout,"GlobalLayout")),(e.routes||[]).forEach(t=>{t.component=n(t.component,"Route"),t.layout&&(t.layout=n(t.layout,"RouteLayout"))});const r=new i(t,e);return t.router=r,!1!==e.autoStart&&queueMicrotask(()=>r.start()),t.plugins||(t.plugins=new Map),t.plugins.set(this.name,{name:this.name,version:this.version,description:this.description,options:e}),t.navigate=r.navigate.bind(r),t.getCurrentRoute=()=>r.currentRoute.value,t.getRouteParams=()=>r.currentParams.value,t.getRouteQuery=()=>r.currentQuery.value,r},async uninstall(t){t.router&&(await t.router.destroy(),delete t.router),t.plugins&&t.plugins.delete(this.name),delete t.navigate,delete t.getCurrentRoute,delete t.getRouteParams,delete t.getRouteQuery}};class a{static parse(t,e){return"string"!=typeof t?t:t.replace(this.expressionPattern,(t,n)=>this.evaluate(n,e))}static evaluate(t,e){if("string"!=typeof t)return t;try{return new Function("data",`with(data) { return ${t}; }`)(e)}catch(t){return""}}}a.expressionPattern=/\{\{\s*(.*?)\s*\}\}/g;const l={name:"props",version:"1.0.0-rc.2",description:"Advanced props data handling for complex data structures with automatic type detection and reactivity",install(t,e={}){const{enableAutoParsing:n=!0,enableReactivity:o=!0,onError:i=null}=e,s=t=>{try{if("string"!=typeof t)return t;if("true"===t)return!0;if("false"===t)return!1;if("null"===t)return null;if("undefined"===t)return;if(t.startsWith("{")||t.startsWith("["))try{return JSON.parse(t)}catch(e){throw new Error(`Invalid JSON: ${t}`)}if("1"===t)return!0;if("0"===t)return!1;if(""===t)return!0;if(!isNaN(t)&&""!==t&&!isNaN(parseFloat(t)))return Number(t);if(t.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/)){const e=new Date(t);if(!isNaN(e.getTime()))return e}return t}catch(e){return i&&i(e,t),t}},l=e=>{const n={};return Object.entries(e).forEach(([e,r])=>{n[e]=r&&"object"==typeof r&&"value"in r&&"watch"in r?r:new t.signal(r)}),n};t._extractProps=t=>{const e={},r=t.attributes;for(let o=r.length-1;o>=0;o--){const i=r[o];if(i.name.startsWith(":")){const r=i.name.slice(1),o=n?s(i.value):i.value;e[r]=o,t.removeAttribute(i.name)}}return e};const u=t.mount;t.mount=async(e,n,r={})=>{const i=o?l(r):r;return await u.call(t,e,n,i)};const c=t._mountComponents,h=new WeakMap,p=new Set;t._mountComponents=async(e,n,i)=>{for(const[s,a]of Object.entries(n))if(s)for(const n of e.querySelectorAll(s)){if(!(n instanceof HTMLElement))continue;const s=t._extractProps(n);let u=s,c=h.get(e);if(!c){let t=e;for(;t&&!c;){if(t._eleva_instance&&t._eleva_instance.data){c=t._eleva_instance.data,h.set(e,c);break}t=t.parentElement}}if(o&&c){const e={};Object.keys(s).forEach(n=>{c[n]&&c[n]instanceof t.signal&&(e[n]=c[n])}),u=r({},s,e)}let d=u;if(o){const t={};Object.entries(u).forEach(([e,n])=>{n&&"object"==typeof n&&"value"in n&&"watch"in n||(t[e]=n)}),d=r({},l(t),u)}const f=await t.mount(n,a,d);f&&!i.includes(f)&&(i.push(f),o&&Object.keys(s).length>0&&!c&&p.add({instance:f,extractedProps:s,container:e,component:a}))}if(o&&p.size>0)for(const e of p){const{instance:n,extractedProps:r,container:o,component:i}=e;let s=h.get(o);if(!s){let t=o;for(;t&&!s;){if(t._eleva_instance&&t._eleva_instance.data){s=t._eleva_instance.data,h.set(o,s);break}t=t.parentElement}}if(s){const o={};if(Object.keys(r).forEach(e=>{s[e]&&s[e]instanceof t.signal&&(o[e]=s[e])}),Object.keys(o).length>0){Object.assign(n.data,o),Object.keys(o).forEach(e=>{const r=o[e];r&&"function"==typeof r.watch&&r.watch(()=>{const e=t._components.get(i)||i;if(e&&e.template){const r="function"==typeof e.template?e.template(n.data):e.template,o=a.parse(r,n.data);t.renderer.patchDOM(n.container,o)}})});const e=t._components.get(i)||i;if(e&&e.template){const r="function"==typeof e.template?e.template(n.data):e.template,o=a.parse(r,n.data);t.renderer.patchDOM(n.container,o)}}p.delete(e)}}},t.props={parse:t=>n?s(t):t,detectType:t=>null===t?"null":void 0===t?"undefined":"boolean"==typeof t?"boolean":"number"==typeof t?"number":"string"==typeof t?"string":"function"==typeof t?"function":t instanceof Date?"date":t instanceof Map?"map":t instanceof Set?"set":Array.isArray(t)?"array":"object"==typeof t?"object":"unknown"},t._originalExtractProps=t._extractProps,t._originalMount=u,t._originalMountComponents=c},uninstall(t){t._originalExtractProps&&(t._extractProps=t._originalExtractProps,delete t._originalExtractProps),t._originalMount&&(t.mount=t._originalMount,delete t._originalMount),t._originalMountComponents&&(t._mountComponents=t._originalMountComponents,delete t._originalMountComponents),t.props&&delete t.props}},u={name:"store",version:"1.0.0-rc.1",description:"Reactive state management for sharing data across the entire Eleva application",install(t,e={}){const{state:n={},actions:o={},namespaces:i={},persistence:s={},devTools:a=!1,onError:l=null}=e,u=new class{constructor(){this.state={},this.actions={},this.subscribers=new Set,this.mutations=[],this.persistence=r({enabled:!1,key:"eleva-store",storage:"localStorage",include:null,exclude:null},s),this.devTools=a,this.onError=l,this._initializeState(n,o),this._initializeNamespaces(i),this._loadPersistedState(),this._setupDevTools()}_initializeState(e,n){Object.entries(e).forEach(([e,n])=>{this.state[e]=new t.signal(n)}),this.actions=r({},n)}_initializeNamespaces(e){Object.entries(e).forEach(([e,n])=>{const{state:o={},actions:i={}}=n;this.state[e]||(this.state[e]={}),this.actions[e]||(this.actions[e]={}),Object.entries(o).forEach(([n,r])=>{this.state[e][n]=new t.signal(r)}),this.actions[e]=r({},i)})}_loadPersistedState(){if(this.persistence.enabled&&"undefined"!=typeof window)try{const t=window[this.persistence.storage].getItem(this.persistence.key);if(t){const e=JSON.parse(t);this._applyPersistedData(e)}}catch(t){this.onError&&this.onError(t,"Failed to load persisted state")}}_applyPersistedData(t,e=this.state,n=""){Object.entries(t).forEach(([t,r])=>{const o=n?`${n}.${t}`:t;this._shouldPersist(o)&&(e[t]&&"object"==typeof e[t]&&"value"in e[t]?e[t].value=r:"object"==typeof r&&null!==r&&e[t]&&this._applyPersistedData(r,e[t],o))})}_shouldPersist(t){const{include:e,exclude:n}=this.persistence;return e&&e.length>0?e.some(e=>t.startsWith(e)):!(n&&n.length>0&&n.some(e=>t.startsWith(e)))}_saveState(){if(this.persistence.enabled&&"undefined"!=typeof window)try{const t=window[this.persistence.storage],e=this._extractPersistedData();t.setItem(this.persistence.key,JSON.stringify(e))}catch(t){this.onError&&this.onError(t,"Failed to save state")}}_extractPersistedData(t=this.state,e=""){const n={};return Object.entries(t).forEach(([t,r])=>{const o=e?`${e}.${t}`:t;if(this._shouldPersist(o))if(r&&"object"==typeof r&&"value"in r)n[t]=r.value;else if("object"==typeof r&&null!==r){const e=this._extractPersistedData(r,o);Object.keys(e).length>0&&(n[t]=e)}}),n}_setupDevTools(){this.devTools&&"undefined"!=typeof window&&window.__ELEVA_DEVTOOLS__&&window.__ELEVA_DEVTOOLS__.registerStore(this)}async dispatch(t,e){try{const n=this._getAction(t);if(!n){const e=new Error(`Action "${t}" not found`);throw this.onError&&this.onError(e,t),e}const r={type:t,payload:e,timestamp:Date.now()};this.mutations.push(r),this.mutations.length>100&&this.mutations.shift();const o=await n.call(null,this.state,e);return this._saveState(),this.subscribers.forEach(t=>{try{t(r,this.state)}catch(t){this.onError&&this.onError(t,"Subscriber callback failed")}}),this.devTools&&"undefined"!=typeof window&&window.__ELEVA_DEVTOOLS__&&window.__ELEVA_DEVTOOLS__.notifyMutation(r,this.state),o}catch(e){throw this.onError&&this.onError(e,`Action dispatch failed: ${t}`),e}}_getAction(t){const e=t.split(".");let n=this.actions;for(const t of e){if(void 0===n[t])return null;n=n[t]}return"function"==typeof n?n:null}subscribe(t){if("function"!=typeof t)throw new Error("Subscribe callback must be a function");return this.subscribers.add(t),()=>{this.subscribers.delete(t)}}getState(){return this._extractPersistedData()}replaceState(t){this._applyPersistedData(t),this._saveState()}clearPersistedState(){if(this.persistence.enabled&&"undefined"!=typeof window)try{window[this.persistence.storage].removeItem(this.persistence.key)}catch(t){this.onError&&this.onError(t,"Failed to clear persisted state")}}registerModule(t,e){this.state[t]||this.actions[t]||(this.state[t]={},this.actions[t]={},this._initializeNamespaces({[t]:e}),this._saveState())}unregisterModule(t){(this.state[t]||this.actions[t])&&(delete this.state[t],delete this.actions[t],this._saveState())}createState(e,n){return this.state[e]||(this.state[e]=new t.signal(n),this._saveState()),this.state[e]}createAction(t,e){if("function"!=typeof e)throw new Error("Action must be a function");this.actions[t]=e}},c=t.mount;t.mount=async(e,n,o={})=>{const i="string"==typeof n&&t._components.get(n)||n;if(!i)return await c.call(t,e,n,o);const s=r({},i,{async setup(e){e.store={state:u.state,dispatch:u.dispatch.bind(u),subscribe:u.subscribe.bind(u),getState:u.getState.bind(u),registerModule:u.registerModule.bind(u),unregisterModule:u.unregisterModule.bind(u),createState:u.createState.bind(u),createAction:u.createAction.bind(u),signal:t.signal};const n=i.setup;return n?await n(e):{}}});return await c.call(t,e,s,o)};const h=t._mountComponents;t._mountComponents=async(e,n,o)=>{const i={};for(const[e,o]of Object.entries(n)){const n="string"==typeof o&&t._components.get(o)||o;i[e]=n&&"object"==typeof n?r({},n,{async setup(e){e.store={state:u.state,dispatch:u.dispatch.bind(u),subscribe:u.subscribe.bind(u),getState:u.getState.bind(u),registerModule:u.registerModule.bind(u),unregisterModule:u.unregisterModule.bind(u),createState:u.createState.bind(u),createAction:u.createAction.bind(u),signal:t.signal};const r=n.setup;return r?await r(e):{}}}):o}return await h.call(t,e,i,o)},t.store=u,t.createAction=(t,e)=>{u.actions[t]=e},t.dispatch=(t,e)=>u.dispatch(t,e),t.getState=()=>u.getState(),t.subscribe=t=>u.subscribe(t),t._originalMount=c,t._originalMountComponents=h},uninstall(t){t._originalMount&&(t.mount=t._originalMount,delete t._originalMount),t._originalMountComponents&&(t._mountComponents=t._originalMountComponents,delete t._originalMountComponents),t.store&&delete t.store,t.createAction&&delete t.createAction,t.dispatch&&delete t.dispatch,t.getState&&delete t.getState,t.subscribe&&delete t.subscribe}};t.Attr=n,t.Props=l,t.Router=s,t.Store=u},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ElevaPlugins={});
|
|
3
3
|
//# sourceMappingURL=eleva-plugins.umd.min.js.map
|