@wsxjs/wsx-router 0.0.6 → 0.0.8
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/LICENSE +21 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +525 -186
- package/package.json +61 -61
- package/src/WsxLink.wsx +0 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 WSX Framework Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("@wsxjs/wsx-core"),G=":host{display:block;width:100%;height:100%}.router-outlet{width:100%;height:100%}";var K=Object.create,$=Object.defineProperty,X=Object.getOwnPropertyDescriptor,P=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),W=e=>{throw TypeError(e)},I=(e,t,r)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Y=(e,t)=>$(e,"name",{value:t,configurable:!0}),Z=e=>[,,,K((e==null?void 0:e[P("metadata")])??null)],tt=["class","method","getter","setter","accessor","field","value","get","set"],O=e=>e!==void 0&&typeof e!="function"?W("Function expected"):e,et=(e,t,r,i,o)=>({kind:tt[e],name:t,metadata:i,addInitializer:n=>r._?W("Already initialized"):o.push(O(n||null))}),rt=(e,t)=>I(t,P("metadata"),e[3]),it=(e,t,r,i)=>{for(var o=0,n=e[t>>1],s=n&&n.length;o<s;o++)n[o].call(r);return i},ot=(e,t,r,i,o,n)=>{var s,l,c,a=t&7,d=!1,v=0,f=e[v]||(e[v]=[]),u=a&&(o=o.prototype,a<5&&(a>3||!d)&&X(o,r));Y(o,r);for(var p=i.length-1;p>=0;p--)c=et(a,r,l={},e[3],f),s=(0,i[p])(o,c),l._=1,O(s)&&(o=s);return rt(e,o),u&&$(o,r,u),d?a^4?n:u:o},b=(e,t,r)=>I(e,typeof t!="symbol"?t+"":t,r),j,E,N;const m=h.createLogger("WsxRouter");j=[h.autoRegister({tagName:"wsx-router"})];class y extends(N=h.LightComponent){constructor(){super({styles:G,styleName:"wsx-router"}),b(this,"views",new Map),b(this,"currentView",null),b(this,"handleRouteChange",()=>{const t=window.location.pathname;m.debug(`Route changed to: ${t}`),this.currentView&&(this.currentView.style.display="none",m.debug("Hiding previous view"));const r=this.matchRoute(t);if(r){r.style.display="block",this.currentView=r,m.debug(`Showing view for route: ${r.getAttribute("route")}`);const i=this.extractParams(r.getAttribute("route")||"/",t);i&&r.setAttribute("params",JSON.stringify(i))}else m.warn(`No view found for path: ${t}`);this.dispatchEvent(new CustomEvent("route-changed",{detail:{path:t,view:r},bubbles:!0,composed:!0}))}),b(this,"interceptLinks",t=>{const r=t.target.closest("a");if(!r)return;const i=r.getAttribute("href");!i||i.startsWith("http")||i.startsWith("#")||(t.preventDefault(),this.navigate(i))})}render(){return h.jsx("div",{class:"router-outlet"})}onConnected(){m.debug("WsxRouter connected to DOM"),this.collectViews(),m.debug("WsxRouter collected views:",this.views.size),window.addEventListener("popstate",this.handleRouteChange),this.addEventListener("click",this.interceptLinks),this.handleRouteChange()}onDisconnected(){window.removeEventListener("popstate",this.handleRouteChange)}collectViews(){const t=Array.from(this.children).filter(r=>r.tagName.toLowerCase()==="wsx-view");m.debug("WsxRouter found views:",t.length),t.forEach(r=>{const i=r.getAttribute("route")||"/";this.views.set(i,r),r.style.display="none",m.debug(`WsxRouter hiding view for route: ${i}`)})}matchRoute(t){if(this.views.has(t))return this.views.get(t);for(const[r,i]of this.views)if(r.includes(":")){const o=r.replace(/:[^/]+/g,"([^/]+)");if(new RegExp(`^${o}$`).test(t))return i}return this.views.get("*")||null}extractParams(t,r){var c;if(!t.includes(":"))return null;const i=((c=t.match(/:([^/]+)/g))==null?void 0:c.map(a=>a.slice(1)))||[],o=t.replace(/:[^/]+/g,"([^/]+)"),n=new RegExp(`^${o}$`),s=r.match(n);if(!s||!i.length)return null;const l={};return i.forEach((a,d)=>{l[a]=s[d+1]}),l}navigate(t){window.history.pushState(null,"",t),this.handleRouteChange()}}E=Z(N);y=ot(E,0,"WsxRouter",j,y);it(E,1,y);const nt=":host{display:block;width:100%;height:100%}.route-view{width:100%;height:100%;position:relative}:host([loading]) .route-view{opacity:.5;transition:opacity .3s ease}:host([error]) .route-view{border:1px solid var(--error-color, #ff0000);padding:1rem}.route-view.entering{animation:fadeIn .3s ease-out}.route-view.leaving{animation:fadeOut .3s ease-in}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}@keyframes fadeOut{0%{opacity:1}to{opacity:0}}";var at=Object.create,S=Object.defineProperty,st=Object.getOwnPropertyDescriptor,z=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),D=e=>{throw TypeError(e)},F=(e,t,r)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ct=(e,t)=>S(e,"name",{value:t,configurable:!0}),lt=e=>[,,,at((e==null?void 0:e[z("metadata")])??null)],ht=["class","method","getter","setter","accessor","field","value","get","set"],U=e=>e!==void 0&&typeof e!="function"?D("Function expected"):e,dt=(e,t,r,i,o)=>({kind:ht[e],name:t,metadata:i,addInitializer:n=>r._?D("Already initialized"):o.push(U(n||null))}),ut=(e,t)=>F(t,z("metadata"),e[3]),pt=(e,t,r,i)=>{for(var o=0,n=e[t>>1],s=n&&n.length;o<s;o++)n[o].call(r);return i},vt=(e,t,r,i,o,n)=>{var s,l,c,a=t&7,d=!1,v=0,f=e[v]||(e[v]=[]),u=a&&(o=o.prototype,a<5&&(a>3||!d)&&st(o,r));ct(o,r);for(var p=i.length-1;p>=0;p--)c=dt(a,r,l={},e[3],f),s=(0,i[p])(o,c),l._=1,U(s)&&(o=s);return ut(e,o),u&&S(o,r,u),d?a^4?n:u:o},x=(e,t,r)=>F(e,typeof t!="symbol"?t+"":t,r),M,R,V;const k=h.createLogger("WsxView");M=[h.autoRegister({tagName:"wsx-view"})];class g extends(V=h.LightComponent){constructor(){super({styles:nt,styleName:"wsx-view"}),x(this,"component",null),x(this,"params",{}),x(this,"componentInstance",null)}render(){return h.jsx("div",{class:"route-view"})}onConnected(){const t=this.getAttribute("component");t&&!this.componentInstance&&this.loadComponent(t)}onAttributeChanged(t,r,i){if(t==="component"&&i&&!this.componentInstance)this.loadComponent(i);else if(t==="params"&&this.componentInstance)try{this.params=JSON.parse(i),Object.entries(this.params).forEach(([o,n])=>{this.componentInstance.setAttribute(o,n)})}catch(o){k.error("Failed to parse params:",o)}}async loadComponent(t){if(this.componentInstance&&(this.componentInstance.remove(),this.componentInstance=null),!customElements.get(t)){k.warn(`Component ${t} not found in customElements registry`);return}this.componentInstance=document.createElement(t),Object.keys(this.params).length>0&&Object.entries(this.params).forEach(([o,n])=>{this.componentInstance.setAttribute(o,n)});const i=this.querySelector(".route-view");i?i.appendChild(this.componentInstance):k.error("Route view container not found")}onDisconnected(){this.componentInstance&&(this.componentInstance.remove(),this.componentInstance=null)}}R=lt(V);g=vt(R,0,"WsxView",M,g);x(g,"observedAttributes",["route","component","params"]);pt(R,1,g);const mt=':host{display:inline-block;min-width:fit-content;min-height:fit-content;width:auto;height:auto}.wsx-link{color:var(--link-color, #007bff);text-decoration:var(--link-decoration, underline);cursor:pointer;transition:color .2s ease;display:inline-block;min-height:1.2em;line-height:1.2}.wsx-link:hover{color:var(--link-hover-color, #0056b3);text-decoration:var(--link-hover-decoration, underline)}.wsx-link:focus{outline:2px solid var(--link-focus-color, #007bff);outline-offset:2px}.wsx-link.active{color:var(--link-active-color, #6c757d);font-weight:var(--link-active-weight, bold)}:host([disabled]) .wsx-link{color:var(--link-disabled-color, #6c757d);cursor:not-allowed;pointer-events:none}:host([external]) .wsx-link:after{content:"↗";font-size:.8em;margin-left:.2em;opacity:.7}:host([variant="button"]) .wsx-link{background-color:var(--button-bg, #007bff);color:var(--button-color, white);padding:.5rem 1rem;border-radius:.25rem;text-decoration:none;display:inline-block}:host([variant="button"]) .wsx-link:hover{background-color:var(--button-hover-bg, #0056b3);color:var(--button-hover-color, white)}:host([variant="tab"]) .wsx-link{padding:.5rem 1rem;border-bottom:2px solid transparent;text-decoration:none}:host([variant="tab"]) .wsx-link.active{border-bottom-color:var(--tab-active-border, #007bff)}';var wt=Object.create,C=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,q=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),T=e=>{throw TypeError(e)},Q=(e,t,r)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,gt=(e,t)=>C(e,"name",{value:t,configurable:!0}),_t=e=>[,,,wt((e==null?void 0:e[q("metadata")])??null)],bt=["class","method","getter","setter","accessor","field","value","get","set"],H=e=>e!==void 0&&typeof e!="function"?T("Function expected"):e,xt=(e,t,r,i,o)=>({kind:bt[e],name:t,metadata:i,addInitializer:n=>r._?T("Already initialized"):o.push(H(n||null))}),yt=(e,t)=>Q(t,q("metadata"),e[3]),kt=(e,t,r,i)=>{for(var o=0,n=e[t>>1],s=n&&n.length;o<s;o++)n[o].call(r);return i},$t=(e,t,r,i,o,n)=>{var s,l,c,a=t&7,d=!1,v=0,f=e[v]||(e[v]=[]),u=a&&(o=o.prototype,a<5&&(a>3||!d)&&ft(o,r));gt(o,r);for(var p=i.length-1;p>=0;p--)c=xt(a,r,l={},e[3],f),s=(0,i[p])(o,c),l._=1,H(s)&&(o=s);return yt(e,o),u&&C(o,r,u),d?a^4?n:u:o},w=(e,t,r)=>Q(e,typeof t!="symbol"?t+"":t,r),J,L,B;const A=h.createLogger("WsxLink");J=[h.autoRegister({tagName:"wsx-link"})];class _ extends(B=h.WebComponent){constructor(){super({styles:mt,styleName:"wsx-link"}),w(this,"to",""),w(this,"replace",!1),w(this,"activeClass","active"),w(this,"exact",!1),w(this,"handleClick",t=>{if(t.preventDefault(),!this.to){A.warn("No 'to' attribute specified");return}if(this.isExternalLink(this.to)){window.open(this.to,"_blank");return}this.replace?window.history.replaceState(null,"",this.to):window.history.pushState(null,"",this.to),window.dispatchEvent(new PopStateEvent("popstate")),A.debug(`Navigated to: ${this.to}`)}),w(this,"updateActiveState",()=>{var o;const t=window.location.pathname,r=this.exact?t===this.to:t.startsWith(this.to)&&this.to!=="/",i=(o=this.shadowRoot)==null?void 0:o.querySelector("a");i&&(r?(i.classList.add(this.activeClass),this.setAttribute("active","")):(i.classList.remove(this.activeClass),this.removeAttribute("active")))})}render(){return h.jsx("a",{href:this.to,class:"wsx-link",onClick:this.handleClick,part:"link"},h.jsx("slot",null))}onConnected(){this.to=this.getAttribute("to")||"",this.replace=this.hasAttribute("replace"),this.activeClass=this.getAttribute("active-class")||"active",this.exact=this.hasAttribute("exact");const t=this.shadowRoot.querySelector(".wsx-link");t&&(t.href=this.to),window.addEventListener("popstate",this.updateActiveState),document.addEventListener("route-changed",this.updateActiveState),this.updateActiveState()}onDisconnected(){window.removeEventListener("popstate",this.updateActiveState),document.removeEventListener("route-changed",this.updateActiveState)}onAttributeChanged(t,r,i){switch(t){case"to":this.to=i||"",this.rerender(),this.updateActiveState();break;case"replace":this.replace=i!==null&&i!=="false";break;case"active-class":this.activeClass=i||"active",this.updateActiveState();break;case"exact":this.exact=i!==null&&i!=="false",this.updateActiveState();break}}isExternalLink(t){return t.startsWith("http://")||t.startsWith("https://")||t.startsWith("mailto:")||t.startsWith("tel:")}navigate(){this.to&&this.handleClick(new MouseEvent("click",{bubbles:!0,cancelable:!0}))}}L=_t(B);_=$t(L,0,"WsxLink",J,_);w(_,"observedAttributes",["to","replace","active-class","exact"]);kt(L,1,_);const Et=h.createLogger("RouterUtils");class St{static navigate(t,r=!1){r?window.history.replaceState(null,"",t):window.history.pushState(null,"",t),window.dispatchEvent(new PopStateEvent("popstate")),Et.debug(`Navigated to: ${t} (replace: ${r})`)}static getCurrentRoute(){const t=new URL(window.location.href);return{path:t.pathname,params:{},query:Object.fromEntries(t.searchParams.entries()),hash:t.hash.slice(1)}}static parseRoute(t,r){var i;if(t===r)return{route:t,params:{},exact:!0};if(t==="*")return{route:t,params:{},exact:!1};if(t.includes(":")){const o=((i=t.match(/:([^/]+)/g))==null?void 0:i.map(c=>c.slice(1)))||[],n=t.replace(/:[^/]+/g,"([^/]+)"),s=new RegExp(`^${n}$`),l=r.match(s);if(l&&o.length>0){const c={};return o.forEach((a,d)=>{c[a]=l[d+1]}),{route:t,params:c,exact:!0}}}if(t.endsWith("/*")){const o=t.slice(0,-2);if(r.startsWith(o))return{route:t,params:{},exact:!1}}return null}static buildPath(t,r={}){let i=t;return Object.entries(r).forEach(([o,n])=>{i=i.replace(`:${o}`,encodeURIComponent(n))}),i}static isRouteActive(t,r=!1){const i=window.location.pathname;return r?i===t:t==="/"?i==="/":i.startsWith(t)}static getRouteDepth(t){return t.split("/").filter(r=>r.length>0).length}static getParentRoute(t){const r=t.split("/").filter(i=>i.length>0);return r.length<=1?"/":(r.pop(),"/"+r.join("/"))}static joinPaths(...t){return t.map(r=>r.replace(/^\/+|\/+$/g,"")).filter(r=>r.length>0).join("/").replace(/^/,"/")}static isExternalUrl(t){return/^https?:\/\//.test(t)||/^mailto:/.test(t)||/^tel:/.test(t)}static getQueryParam(t){return new URL(window.location.href).searchParams.get(t)}static setQueryParam(t,r,i=!1){const o=new URL(window.location.href);o.searchParams.set(t,r);const n=o.pathname+o.search+o.hash;this.navigate(n,i)}static removeQueryParam(t,r=!1){const i=new URL(window.location.href);i.searchParams.delete(t);const o=i.pathname+i.search+i.hash;this.navigate(o,r)}static goBack(){window.history.back()}static goForward(){window.history.forward()}static replace(t){this.navigate(t,!0)}static getHistoryLength(){return window.history.length}static onRouteChange(t){const r=()=>{const i=this.getCurrentRoute();t(i)};return window.addEventListener("popstate",r),document.addEventListener("route-changed",r),()=>{window.removeEventListener("popstate",r),document.removeEventListener("route-changed",r)}}}exports.RouterUtils=St;exports.WsxLink=_;exports.WsxRouter=y;exports.WsxView=g;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("@wsxjs/wsx-core"),nt=":host{display:block;width:100%;height:100%}.router-outlet{width:100%;height:100%}";var ft;let pt,vt;function Y(r,t,e){return(t=mt(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function xt(r,t,e,n,g,R){function C(i,c,u){return function(s,a){return u&&u(s),i[c].call(s,a)}}function O(i,c){for(var u=0;u<i.length;u++)i[u].call(c);return c}function b(i,c,u,s){if(typeof i!="function"&&(s||i!==void 0))throw new TypeError(c+" must "+(u||"be")+" a function"+(s?"":" or undefined"));return i}function T(i,c,u,s,a,$,L,j,N,y,m,f,p){function w(l){if(!p(l))throw new TypeError("Attempted to access private element on non-instance")}var h,x=c[0],k=c[3],_=!j;if(!_){u||Array.isArray(x)||(x=[x]);var o={},E=[],v=a===3?"get":a===4||f?"set":"value";y?(m||f?o={get:it(function(){return k(this)},s,"get"),set:function(l){c[4](this,l)}}:o[v]=k,m||it(o[v],s,a===2?"":v)):m||(o=Object.getOwnPropertyDescriptor(i,s))}for(var d=i,P=x.length-1;P>=0;P-=u?2:1){var H=x[P],K=u?x[P-1]:void 0,Q={},W={kind:["field","accessor","method","getter","setter","class"][a],name:s,metadata:$,addInitializer:(function(l,S){if(l.v)throw Error("attempted to call addInitializer after decoration was finished");b(S,"An initializer","be",!0),L.push(S)}).bind(null,Q)};try{if(_)(h=b(H.call(K,d,W),"class decorators","return"))&&(d=h);else{var A,z;W.static=N,W.private=y,y?a===2?A=function(l){return w(l),o.value}:(a<4&&(A=C(o,"get",w)),a!==3&&(z=C(o,"set",w))):(A=function(l){return l[s]},(a<2||a===4)&&(z=function(l,S){l[s]=S}));var J=W.access={has:y?p.bind():function(l){return s in l}};if(A&&(J.get=A),z&&(J.set=z),d=H.call(K,f?{get:o.get,set:o.set}:o[v],W),f){if(typeof d=="object"&&d)(h=b(d.get,"accessor.get"))&&(o.get=h),(h=b(d.set,"accessor.set"))&&(o.set=h),(h=b(d.init,"accessor.init"))&&E.push(h);else if(d!==void 0)throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0")}else b(d,(m?"field":"method")+" decorators","return")&&(m?E.push(d):o[v]=d)}}finally{Q.v=!0}}return(m||f)&&j.push(function(l,S){for(var V=E.length-1;V>=0;V--)S=E[V].call(l,S);return S}),m||_||(y?f?j.push(C(o,"get"),C(o,"set")):j.push(a===2?o[v]:C.call.bind(o[v])):Object.defineProperty(i,s,o)),d}function U(i,c){return Object.defineProperty(i,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:c})}if(arguments.length>=6)var q=R[Symbol.metadata||Symbol.for("Symbol.metadata")];var D=Object.create(q??null),X=function(i,c,u,s){var a,$,L=[],j=function(v){return Et(v)===i},N=new Map;function y(v){v&&L.push(O.bind(null,v))}for(var m=0;m<c.length;m++){var f=c[m];if(Array.isArray(f)){var p=f[1],w=f[2],h=f.length>3,x=16&p,k=!!(8&p),_=(p&=7)==0,o=w+"/"+k;if(!_&&!h){var E=N.get(o);if(E===!0||E===3&&p!==4||E===4&&p!==3)throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+w);N.set(o,!(p>2)||p)}T(k?i:i.prototype,f,x,h?"#"+w:mt(w),p,s,k?$=$||[]:a=a||[],L,k,h,_,p===1,k&&h?j:u)}}return y(a),y($),L}(r,t,g,D);return e.length||U(r,D),{e:X,get c(){var i=[];return e.length&&[U(T(r,[e],n,r.name,5,D,i),D),O.bind(null,i,r)]}}}function mt(r){var t=kt(r,"string");return typeof t=="symbol"?t:t+""}function kt(r,t){if(typeof r!="object"||!r)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var n=e.call(r,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(r)}function it(r,t,e){typeof t=="symbol"&&(t=(t=t.description)?"["+t+"]":"");try{Object.defineProperty(r,"name",{configurable:!0,value:e?e+" "+t:t})}catch{}return r}function Et(r){if(Object(r)!==r)throw TypeError("right-hand side of 'in' should be an object, got "+(r!==null?typeof r:"null"));return r}const B=I.createLogger("WsxRouter");vt=[I.autoRegister({tagName:"wsx-router"})];exports.WsxRouter=void 0;class St extends I.LightComponent{constructor(){super({styles:nt,styleName:"wsx-router"}),Y(this,"_autoStyles",nt),Y(this,"views",new Map),Y(this,"currentView",null),Y(this,"handleRouteChange",()=>{const t=window.location.pathname;B.debug(`Route changed to: ${t}`),this.currentView&&(this.currentView.style.display="none",B.debug("Hiding previous view"));const e=this.matchRoute(t);if(e){e.style.display="block",this.currentView=e,B.debug(`Showing view for route: ${e.getAttribute("route")}`);const n=this.extractParams(e.getAttribute("route")||"/",t);n&&e.setAttribute("params",JSON.stringify(n))}else B.warn(`No view found for path: ${t}`);this.dispatchEvent(new CustomEvent("route-changed",{detail:{path:t,view:e},bubbles:!0,composed:!0}))}),Y(this,"interceptLinks",t=>{const e=t.target.closest("a");if(!e)return;const n=e.getAttribute("href");!n||n.startsWith("http")||n.startsWith("#")||(t.preventDefault(),this.navigate(n))})}render(){return I.jsx("div",{class:"router-outlet"})}onConnected(){B.debug("WsxRouter connected to DOM"),this.collectViews(),B.debug("WsxRouter collected views:",this.views.size),window.addEventListener("popstate",this.handleRouteChange),this.addEventListener("click",this.interceptLinks),this.handleRouteChange()}onDisconnected(){window.removeEventListener("popstate",this.handleRouteChange)}collectViews(){const t=Array.from(this.children).filter(e=>e.tagName.toLowerCase()==="wsx-view");B.debug("WsxRouter found views:",t.length),t.forEach(e=>{const n=e.getAttribute("route")||"/";this.views.set(n,e),e.style.display="none",B.debug(`WsxRouter hiding view for route: ${n}`)})}matchRoute(t){if(this.views.has(t))return this.views.get(t);for(const[e,n]of this.views)if(e.includes(":")){const g=e.replace(/:[^/]+/g,"([^/]+)");if(new RegExp(`^${g}$`).test(t))return n}return this.views.get("*")||null}extractParams(t,e){var b;if(!t.includes(":"))return null;const n=((b=t.match(/:([^/]+)/g))==null?void 0:b.map(T=>T.slice(1)))||[],g=t.replace(/:[^/]+/g,"([^/]+)"),R=new RegExp(`^${g}$`),C=e.match(R);if(!C||!n.length)return null;const O={};return n.forEach((T,U)=>{O[T]=C[U+1]}),O}navigate(t){window.history.pushState(null,"",t),this.handleRouteChange()}}ft=St;[exports.WsxRouter,pt]=xt(ft,[],vt,0,void 0,I.LightComponent).c;pt();const ot=":host{display:block;width:100%;height:100%}.route-view{width:100%;height:100%;position:relative}:host([loading]) .route-view{opacity:.5;transition:opacity .3s ease}:host([error]) .route-view{border:1px solid var(--error-color, #ff0000);padding:1rem}.route-view.entering{animation:fadeIn .3s ease-out}.route-view.leaving{animation:fadeOut .3s ease-in}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}@keyframes fadeOut{0%{opacity:1}to{opacity:0}}";var Z,F;let st,gt,at;function G(r,t,e){return(t=bt(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function Ct(r,t,e,n,g,R){function C(i,c,u){return function(s,a){return u&&u(s),i[c].call(s,a)}}function O(i,c){for(var u=0;u<i.length;u++)i[u].call(c);return c}function b(i,c,u,s){if(typeof i!="function"&&(s||i!==void 0))throw new TypeError(c+" must "+(u||"be")+" a function"+(s?"":" or undefined"));return i}function T(i,c,u,s,a,$,L,j,N,y,m,f,p){function w(l){if(!p(l))throw new TypeError("Attempted to access private element on non-instance")}var h,x=c[0],k=c[3],_=!j;if(!_){u||Array.isArray(x)||(x=[x]);var o={},E=[],v=a===3?"get":a===4||f?"set":"value";y?(m||f?o={get:ct(function(){return k(this)},s,"get"),set:function(l){c[4](this,l)}}:o[v]=k,m||ct(o[v],s,a===2?"":v)):m||(o=Object.getOwnPropertyDescriptor(i,s))}for(var d=i,P=x.length-1;P>=0;P-=u?2:1){var H=x[P],K=u?x[P-1]:void 0,Q={},W={kind:["field","accessor","method","getter","setter","class"][a],name:s,metadata:$,addInitializer:(function(l,S){if(l.v)throw Error("attempted to call addInitializer after decoration was finished");b(S,"An initializer","be",!0),L.push(S)}).bind(null,Q)};try{if(_)(h=b(H.call(K,d,W),"class decorators","return"))&&(d=h);else{var A,z;W.static=N,W.private=y,y?a===2?A=function(l){return w(l),o.value}:(a<4&&(A=C(o,"get",w)),a!==3&&(z=C(o,"set",w))):(A=function(l){return l[s]},(a<2||a===4)&&(z=function(l,S){l[s]=S}));var J=W.access={has:y?p.bind():function(l){return s in l}};if(A&&(J.get=A),z&&(J.set=z),d=H.call(K,f?{get:o.get,set:o.set}:o[v],W),f){if(typeof d=="object"&&d)(h=b(d.get,"accessor.get"))&&(o.get=h),(h=b(d.set,"accessor.set"))&&(o.set=h),(h=b(d.init,"accessor.init"))&&E.push(h);else if(d!==void 0)throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0")}else b(d,(m?"field":"method")+" decorators","return")&&(m?E.push(d):o[v]=d)}}finally{Q.v=!0}}return(m||f)&&j.push(function(l,S){for(var V=E.length-1;V>=0;V--)S=E[V].call(l,S);return S}),m||_||(y?f?j.push(C(o,"get"),C(o,"set")):j.push(a===2?o[v]:C.call.bind(o[v])):Object.defineProperty(i,s,o)),d}function U(i,c){return Object.defineProperty(i,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:c})}if(arguments.length>=6)var q=R[Symbol.metadata||Symbol.for("Symbol.metadata")];var D=Object.create(q??null),X=function(i,c,u,s){var a,$,L=[],j=function(v){return jt(v)===i},N=new Map;function y(v){v&&L.push(O.bind(null,v))}for(var m=0;m<c.length;m++){var f=c[m];if(Array.isArray(f)){var p=f[1],w=f[2],h=f.length>3,x=16&p,k=!!(8&p),_=(p&=7)==0,o=w+"/"+k;if(!_&&!h){var E=N.get(o);if(E===!0||E===3&&p!==4||E===4&&p!==3)throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+w);N.set(o,!(p>2)||p)}T(k?i:i.prototype,f,x,h?"#"+w:bt(w),p,s,k?$=$||[]:a=a||[],L,k,h,_,p===1,k&&h?j:u)}}return y(a),y($),L}(r,t,g,D);return e.length||U(r,D),{e:X,get c(){var i=[];return e.length&&[U(T(r,[e],n,r.name,5,D,i),D),O.bind(null,i,r)]}}}function bt(r){var t=Rt(r,"string");return typeof t=="symbol"?t:t+""}function Rt(r,t){if(typeof r!="object"||!r)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var n=e.call(r,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(r)}function ct(r,t,e){typeof t=="symbol"&&(t=(t=t.description)?"["+t+"]":"");try{Object.defineProperty(r,"name",{configurable:!0,value:e?e+" "+t:t})}catch{}return r}function jt(r){if(Object(r)!==r)throw TypeError("right-hand side of 'in' should be an object, got "+(r!==null?typeof r:"null"));return r}function _t(r){return r}const tt=I.createLogger("WsxView");gt=[I.autoRegister({tagName:"wsx-view"})];exports.WsxView=void 0;new(at=(F=class extends I.LightComponent{constructor(){super({styles:ot,styleName:"wsx-view"}),G(this,"_autoStyles",ot),G(this,"component",null),G(this,"params",{}),G(this,"componentInstance",null)}render(){return I.jsx("div",{class:"route-view"})}onConnected(){const t=this.getAttribute("component");t&&!this.componentInstance&&this.loadComponent(t)}onAttributeChanged(t,e,n){if(t==="component"&&n&&!this.componentInstance)this.loadComponent(n);else if(t==="params"&&this.componentInstance)try{this.params=JSON.parse(n),Object.entries(this.params).forEach(([g,R])=>{this.componentInstance.setAttribute(g,R)})}catch(g){tt.error("Failed to parse params:",g)}}async loadComponent(t){if(this.componentInstance&&(this.componentInstance.remove(),this.componentInstance=null),!customElements.get(t)){tt.warn(`Component ${t} not found in customElements registry`);return}this.componentInstance=document.createElement(t),Object.keys(this.params).length>0&&Object.entries(this.params).forEach(([g,R])=>{this.componentInstance.setAttribute(g,R)});const n=this.querySelector(".route-view");n?n.appendChild(this.componentInstance):tt.error("Route view container not found")}onDisconnected(){this.componentInstance&&(this.componentInstance.remove(),this.componentInstance=null)}},[exports.WsxView,st]=Ct(F,[],gt,0,void 0,I.LightComponent).c,F),Z=class extends _t{constructor(){super(exports.WsxView),G(this,"observedAttributes",["route","component","params"]),st()}},G(Z,at,void 0),Z);const $t=':host{display:inline-block;min-width:fit-content;min-height:fit-content;width:auto;height:auto}.wsx-link{color:var(--link-color, #007bff);text-decoration:var(--link-decoration, underline);cursor:pointer;transition:color .2s ease;display:inline-block;min-height:1.2em;line-height:1.2}.wsx-link:hover{color:var(--link-hover-color, #0056b3);text-decoration:var(--link-hover-decoration, underline)}.wsx-link:focus{outline:2px solid var(--link-focus-color, #007bff);outline-offset:2px}.wsx-link.active{color:var(--link-active-color, #6c757d);font-weight:var(--link-active-weight, bold)}:host([disabled]) .wsx-link{color:var(--link-disabled-color, #6c757d);cursor:not-allowed;pointer-events:none}:host([external]) .wsx-link:after{content:"↗";font-size:.8em;margin-left:.2em;opacity:.7}:host([variant="button"]) .wsx-link{background-color:var(--button-bg, #007bff);color:var(--button-color, white);padding:.5rem 1rem;border-radius:.25rem;text-decoration:none;display:inline-block}:host([variant="button"]) .wsx-link:hover{background-color:var(--button-hover-bg, #0056b3);color:var(--button-hover-color, white)}:host([variant="tab"]) .wsx-link{padding:.5rem 1rem;border-bottom:2px solid transparent;text-decoration:none}:host([variant="tab"]) .wsx-link.active{border-bottom-color:var(--tab-active-border, #007bff)}';var et,rt;let lt,yt,ut;function M(r,t,e){return(t=wt(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function Lt(r,t,e,n,g,R){function C(i,c,u){return function(s,a){return u&&u(s),i[c].call(s,a)}}function O(i,c){for(var u=0;u<i.length;u++)i[u].call(c);return c}function b(i,c,u,s){if(typeof i!="function"&&(s||i!==void 0))throw new TypeError(c+" must "+(u||"be")+" a function"+(s?"":" or undefined"));return i}function T(i,c,u,s,a,$,L,j,N,y,m,f,p){function w(l){if(!p(l))throw new TypeError("Attempted to access private element on non-instance")}var h,x=c[0],k=c[3],_=!j;if(!_){u||Array.isArray(x)||(x=[x]);var o={},E=[],v=a===3?"get":a===4||f?"set":"value";y?(m||f?o={get:ht(function(){return k(this)},s,"get"),set:function(l){c[4](this,l)}}:o[v]=k,m||ht(o[v],s,a===2?"":v)):m||(o=Object.getOwnPropertyDescriptor(i,s))}for(var d=i,P=x.length-1;P>=0;P-=u?2:1){var H=x[P],K=u?x[P-1]:void 0,Q={},W={kind:["field","accessor","method","getter","setter","class"][a],name:s,metadata:$,addInitializer:(function(l,S){if(l.v)throw Error("attempted to call addInitializer after decoration was finished");b(S,"An initializer","be",!0),L.push(S)}).bind(null,Q)};try{if(_)(h=b(H.call(K,d,W),"class decorators","return"))&&(d=h);else{var A,z;W.static=N,W.private=y,y?a===2?A=function(l){return w(l),o.value}:(a<4&&(A=C(o,"get",w)),a!==3&&(z=C(o,"set",w))):(A=function(l){return l[s]},(a<2||a===4)&&(z=function(l,S){l[s]=S}));var J=W.access={has:y?p.bind():function(l){return s in l}};if(A&&(J.get=A),z&&(J.set=z),d=H.call(K,f?{get:o.get,set:o.set}:o[v],W),f){if(typeof d=="object"&&d)(h=b(d.get,"accessor.get"))&&(o.get=h),(h=b(d.set,"accessor.set"))&&(o.set=h),(h=b(d.init,"accessor.init"))&&E.push(h);else if(d!==void 0)throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0")}else b(d,(m?"field":"method")+" decorators","return")&&(m?E.push(d):o[v]=d)}}finally{Q.v=!0}}return(m||f)&&j.push(function(l,S){for(var V=E.length-1;V>=0;V--)S=E[V].call(l,S);return S}),m||_||(y?f?j.push(C(o,"get"),C(o,"set")):j.push(a===2?o[v]:C.call.bind(o[v])):Object.defineProperty(i,s,o)),d}function U(i,c){return Object.defineProperty(i,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:c})}if(arguments.length>=6)var q=R[Symbol.metadata||Symbol.for("Symbol.metadata")];var D=Object.create(q??null),X=function(i,c,u,s){var a,$,L=[],j=function(v){return At(v)===i},N=new Map;function y(v){v&&L.push(O.bind(null,v))}for(var m=0;m<c.length;m++){var f=c[m];if(Array.isArray(f)){var p=f[1],w=f[2],h=f.length>3,x=16&p,k=!!(8&p),_=(p&=7)==0,o=w+"/"+k;if(!_&&!h){var E=N.get(o);if(E===!0||E===3&&p!==4||E===4&&p!==3)throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+w);N.set(o,!(p>2)||p)}T(k?i:i.prototype,f,x,h?"#"+w:wt(w),p,s,k?$=$||[]:a=a||[],L,k,h,_,p===1,k&&h?j:u)}}return y(a),y($),L}(r,t,g,D);return e.length||U(r,D),{e:X,get c(){var i=[];return e.length&&[U(T(r,[e],n,r.name,5,D,i),D),O.bind(null,i,r)]}}}function wt(r){var t=Wt(r,"string");return typeof t=="symbol"?t:t+""}function Wt(r,t){if(typeof r!="object"||!r)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var n=e.call(r,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(r)}function ht(r,t,e){typeof t=="symbol"&&(t=(t=t.description)?"["+t+"]":"");try{Object.defineProperty(r,"name",{configurable:!0,value:e?e+" "+t:t})}catch{}return r}function At(r){if(Object(r)!==r)throw TypeError("right-hand side of 'in' should be an object, got "+(r!==null?typeof r:"null"));return r}function It(r){return r}const dt=I.createLogger("WsxLink");yt=[I.autoRegister({tagName:"wsx-link"})];exports.WsxLink=void 0;new(ut=(rt=class extends I.WebComponent{constructor(...t){super(...t),M(this,"_autoStyles",$t),M(this,"to",""),M(this,"replace",!1),M(this,"activeClass","active"),M(this,"exact",!1),M(this,"handleClick",e=>{if(e.preventDefault(),!this.to){dt.warn("No 'to' attribute specified");return}if(this.isExternalLink(this.to)){window.open(this.to,"_blank");return}this.replace?window.history.replaceState(null,"",this.to):window.history.pushState(null,"",this.to),window.dispatchEvent(new PopStateEvent("popstate")),dt.debug(`Navigated to: ${this.to}`)}),M(this,"updateActiveState",()=>{var R;const e=window.location.pathname,n=this.exact?e===this.to:e.startsWith(this.to)&&this.to!=="/",g=(R=this.shadowRoot)==null?void 0:R.querySelector("a");g&&(n?(g.classList.add(this.activeClass),this.setAttribute("active","")):(g.classList.remove(this.activeClass),this.removeAttribute("active")))})}render(){return I.jsx("a",{href:this.to,class:"wsx-link",onClick:this.handleClick,part:"link"},I.jsx("slot",null))}onConnected(){this.to=this.getAttribute("to")||"",this.replace=this.hasAttribute("replace"),this.activeClass=this.getAttribute("active-class")||"active",this.exact=this.hasAttribute("exact");const t=this.shadowRoot.querySelector(".wsx-link");t&&(t.href=this.to),window.addEventListener("popstate",this.updateActiveState),document.addEventListener("route-changed",this.updateActiveState),this.updateActiveState()}onDisconnected(){window.removeEventListener("popstate",this.updateActiveState),document.removeEventListener("route-changed",this.updateActiveState)}onAttributeChanged(t,e,n){switch(t){case"to":this.to=n||"",this.rerender(),this.updateActiveState();break;case"replace":this.replace=n!==null&&n!=="false";break;case"active-class":this.activeClass=n||"active",this.updateActiveState();break;case"exact":this.exact=n!==null&&n!=="false",this.updateActiveState();break}}isExternalLink(t){return t.startsWith("http://")||t.startsWith("https://")||t.startsWith("mailto:")||t.startsWith("tel:")}navigate(){this.to&&this.handleClick(new MouseEvent("click",{bubbles:!0,cancelable:!0}))}},[exports.WsxLink,lt]=Lt(rt,[],yt,0,void 0,I.WebComponent).c,rt),et=class extends It{constructor(){super(exports.WsxLink),M(this,"observedAttributes",["to","replace","active-class","exact"]),lt()}},M(et,ut,void 0),et);const Ot=I.createLogger("RouterUtils");class Tt{static navigate(t,e=!1){e?window.history.replaceState(null,"",t):window.history.pushState(null,"",t),window.dispatchEvent(new PopStateEvent("popstate")),Ot.debug(`Navigated to: ${t} (replace: ${e})`)}static getCurrentRoute(){const t=new URL(window.location.href);return{path:t.pathname,params:{},query:Object.fromEntries(t.searchParams.entries()),hash:t.hash.slice(1)}}static parseRoute(t,e){var n;if(t===e)return{route:t,params:{},exact:!0};if(t==="*")return{route:t,params:{},exact:!1};if(t.includes(":")){const g=((n=t.match(/:([^/]+)/g))==null?void 0:n.map(b=>b.slice(1)))||[],R=t.replace(/:[^/]+/g,"([^/]+)"),C=new RegExp(`^${R}$`),O=e.match(C);if(O&&g.length>0){const b={};return g.forEach((T,U)=>{b[T]=O[U+1]}),{route:t,params:b,exact:!0}}}if(t.endsWith("/*")){const g=t.slice(0,-2);if(e.startsWith(g))return{route:t,params:{},exact:!1}}return null}static buildPath(t,e={}){let n=t;return Object.entries(e).forEach(([g,R])=>{n=n.replace(`:${g}`,encodeURIComponent(R))}),n}static isRouteActive(t,e=!1){const n=window.location.pathname;return e?n===t:t==="/"?n==="/":n.startsWith(t)}static getRouteDepth(t){return t.split("/").filter(e=>e.length>0).length}static getParentRoute(t){const e=t.split("/").filter(n=>n.length>0);return e.length<=1?"/":(e.pop(),"/"+e.join("/"))}static joinPaths(...t){return t.map(e=>e.replace(/^\/+|\/+$/g,"")).filter(e=>e.length>0).join("/").replace(/^/,"/")}static isExternalUrl(t){return/^https?:\/\//.test(t)||/^mailto:/.test(t)||/^tel:/.test(t)}static getQueryParam(t){return new URL(window.location.href).searchParams.get(t)}static setQueryParam(t,e,n=!1){const g=new URL(window.location.href);g.searchParams.set(t,e);const R=g.pathname+g.search+g.hash;this.navigate(R,n)}static removeQueryParam(t,e=!1){const n=new URL(window.location.href);n.searchParams.delete(t);const g=n.pathname+n.search+n.hash;this.navigate(g,e)}static goBack(){window.history.back()}static goForward(){window.history.forward()}static replace(t){this.navigate(t,!0)}static getHistoryLength(){return window.history.length}static onRouteChange(t){const e=()=>{const n=this.getCurrentRoute();t(n)};return window.addEventListener("popstate",e),document.addEventListener("route-changed",e),()=>{window.removeEventListener("popstate",e),document.removeEventListener("route-changed",e)}}}exports.RouterUtils=Tt;
|
package/dist/index.js
CHANGED
|
@@ -1,86 +1,198 @@
|
|
|
1
|
-
import { createLogger as
|
|
2
|
-
const
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { createLogger as F, autoRegister as ot, LightComponent as Y, jsx as Z, WebComponent as st } from "@wsxjs/wsx-core";
|
|
2
|
+
const at = ":host{display:block;width:100%;height:100%}.router-outlet{width:100%;height:100%}";
|
|
3
|
+
var yt;
|
|
4
|
+
let wt, xt;
|
|
5
|
+
function X(r, t, e) {
|
|
6
|
+
return (t = kt(t)) in r ? Object.defineProperty(r, t, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = e, r;
|
|
7
|
+
}
|
|
8
|
+
function Ct(r, t, e, n, g, R) {
|
|
9
|
+
function _(i, c, u) {
|
|
10
|
+
return function(s, a) {
|
|
11
|
+
return u && u(s), i[c].call(s, a);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function I(i, c) {
|
|
15
|
+
for (var u = 0; u < i.length; u++) i[u].call(c);
|
|
16
|
+
return c;
|
|
17
|
+
}
|
|
18
|
+
function b(i, c, u, s) {
|
|
19
|
+
if (typeof i != "function" && (s || i !== void 0)) throw new TypeError(c + " must " + (u || "be") + " a function" + (s ? "" : " or undefined"));
|
|
20
|
+
return i;
|
|
21
|
+
}
|
|
22
|
+
function O(i, c, u, s, a, j, A, C, D, y, m, d, p) {
|
|
23
|
+
function w(l) {
|
|
24
|
+
if (!p(l)) throw new TypeError("Attempted to access private element on non-instance");
|
|
25
|
+
}
|
|
26
|
+
var h, x = c[0], k = c[3], $ = !C;
|
|
27
|
+
if (!$) {
|
|
28
|
+
u || Array.isArray(x) || (x = [x]);
|
|
29
|
+
var o = {}, E = [], v = a === 3 ? "get" : a === 4 || d ? "set" : "value";
|
|
30
|
+
y ? (m || d ? o = { get: ct(function() {
|
|
31
|
+
return k(this);
|
|
32
|
+
}, s, "get"), set: function(l) {
|
|
33
|
+
c[4](this, l);
|
|
34
|
+
} } : o[v] = k, m || ct(o[v], s, a === 2 ? "" : v)) : m || (o = Object.getOwnPropertyDescriptor(i, s));
|
|
35
|
+
}
|
|
36
|
+
for (var f = i, N = x.length - 1; N >= 0; N -= u ? 2 : 1) {
|
|
37
|
+
var H = x[N], q = u ? x[N - 1] : void 0, K = {}, W = { kind: ["field", "accessor", "method", "getter", "setter", "class"][a], name: s, metadata: j, addInitializer: (function(l, S) {
|
|
38
|
+
if (l.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
39
|
+
b(S, "An initializer", "be", !0), A.push(S);
|
|
40
|
+
}).bind(null, K) };
|
|
41
|
+
try {
|
|
42
|
+
if ($) (h = b(H.call(q, f, W), "class decorators", "return")) && (f = h);
|
|
43
|
+
else {
|
|
44
|
+
var L, P;
|
|
45
|
+
W.static = D, W.private = y, y ? a === 2 ? L = function(l) {
|
|
46
|
+
return w(l), o.value;
|
|
47
|
+
} : (a < 4 && (L = _(o, "get", w)), a !== 3 && (P = _(o, "set", w))) : (L = function(l) {
|
|
48
|
+
return l[s];
|
|
49
|
+
}, (a < 2 || a === 4) && (P = function(l, S) {
|
|
50
|
+
l[s] = S;
|
|
51
|
+
}));
|
|
52
|
+
var Q = W.access = { has: y ? p.bind() : function(l) {
|
|
53
|
+
return s in l;
|
|
54
|
+
} };
|
|
55
|
+
if (L && (Q.get = L), P && (Q.set = P), f = H.call(q, d ? { get: o.get, set: o.set } : o[v], W), d) {
|
|
56
|
+
if (typeof f == "object" && f) (h = b(f.get, "accessor.get")) && (o.get = h), (h = b(f.set, "accessor.set")) && (o.set = h), (h = b(f.init, "accessor.init")) && E.push(h);
|
|
57
|
+
else if (f !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
58
|
+
} else b(f, (m ? "field" : "method") + " decorators", "return") && (m ? E.push(f) : o[v] = f);
|
|
59
|
+
}
|
|
60
|
+
} finally {
|
|
61
|
+
K.v = !0;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return (m || d) && C.push(function(l, S) {
|
|
65
|
+
for (var U = E.length - 1; U >= 0; U--) S = E[U].call(l, S);
|
|
66
|
+
return S;
|
|
67
|
+
}), m || $ || (y ? d ? C.push(_(o, "get"), _(o, "set")) : C.push(a === 2 ? o[v] : _.call.bind(o[v])) : Object.defineProperty(i, s, o)), f;
|
|
68
|
+
}
|
|
69
|
+
function z(i, c) {
|
|
70
|
+
return Object.defineProperty(i, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
|
|
71
|
+
}
|
|
72
|
+
if (arguments.length >= 6) var M = R[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
73
|
+
var T = Object.create(M ?? null), G = function(i, c, u, s) {
|
|
74
|
+
var a, j, A = [], C = function(v) {
|
|
75
|
+
return jt(v) === i;
|
|
76
|
+
}, D = /* @__PURE__ */ new Map();
|
|
77
|
+
function y(v) {
|
|
78
|
+
v && A.push(I.bind(null, v));
|
|
79
|
+
}
|
|
80
|
+
for (var m = 0; m < c.length; m++) {
|
|
81
|
+
var d = c[m];
|
|
82
|
+
if (Array.isArray(d)) {
|
|
83
|
+
var p = d[1], w = d[2], h = d.length > 3, x = 16 & p, k = !!(8 & p), $ = (p &= 7) == 0, o = w + "/" + k;
|
|
84
|
+
if (!$ && !h) {
|
|
85
|
+
var E = D.get(o);
|
|
86
|
+
if (E === !0 || E === 3 && p !== 4 || E === 4 && p !== 3) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + w);
|
|
87
|
+
D.set(o, !(p > 2) || p);
|
|
88
|
+
}
|
|
89
|
+
O(k ? i : i.prototype, d, x, h ? "#" + w : kt(w), p, s, k ? j = j || [] : a = a || [], A, k, h, $, p === 1, k && h ? C : u);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return y(a), y(j), A;
|
|
93
|
+
}(r, t, g, T);
|
|
94
|
+
return e.length || z(r, T), { e: G, get c() {
|
|
95
|
+
var i = [];
|
|
96
|
+
return e.length && [z(O(r, [e], n, r.name, 5, T, i), T), I.bind(null, i, r)];
|
|
97
|
+
} };
|
|
98
|
+
}
|
|
99
|
+
function kt(r) {
|
|
100
|
+
var t = $t(r, "string");
|
|
101
|
+
return typeof t == "symbol" ? t : t + "";
|
|
102
|
+
}
|
|
103
|
+
function $t(r, t) {
|
|
104
|
+
if (typeof r != "object" || !r) return r;
|
|
105
|
+
var e = r[Symbol.toPrimitive];
|
|
106
|
+
if (e !== void 0) {
|
|
107
|
+
var n = e.call(r, t);
|
|
108
|
+
if (typeof n != "object") return n;
|
|
109
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
110
|
+
}
|
|
111
|
+
return String(r);
|
|
112
|
+
}
|
|
113
|
+
function ct(r, t, e) {
|
|
114
|
+
typeof t == "symbol" && (t = (t = t.description) ? "[" + t + "]" : "");
|
|
115
|
+
try {
|
|
116
|
+
Object.defineProperty(r, "name", { configurable: !0, value: e ? e + " " + t : t });
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
return r;
|
|
120
|
+
}
|
|
121
|
+
function jt(r) {
|
|
122
|
+
if (Object(r) !== r) throw TypeError("right-hand side of 'in' should be an object, got " + (r !== null ? typeof r : "null"));
|
|
123
|
+
return r;
|
|
124
|
+
}
|
|
125
|
+
const J = F("WsxRouter");
|
|
126
|
+
xt = [ot({
|
|
127
|
+
tagName: "wsx-router"
|
|
128
|
+
})];
|
|
129
|
+
let At;
|
|
130
|
+
class Wt extends Y {
|
|
18
131
|
constructor() {
|
|
19
132
|
super({
|
|
20
|
-
styles:
|
|
133
|
+
styles: at,
|
|
21
134
|
styleName: "wsx-router"
|
|
22
|
-
}),
|
|
135
|
+
}), X(this, "_autoStyles", at), X(this, "views", /* @__PURE__ */ new Map()), X(this, "currentView", null), X(this, "handleRouteChange", () => {
|
|
23
136
|
const t = window.location.pathname;
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
137
|
+
J.debug(`Route changed to: ${t}`), this.currentView && (this.currentView.style.display = "none", J.debug("Hiding previous view"));
|
|
138
|
+
const e = this.matchRoute(t);
|
|
139
|
+
if (e) {
|
|
140
|
+
e.style.display = "block", this.currentView = e, J.debug(`Showing view for route: ${e.getAttribute("route")}`);
|
|
141
|
+
const n = this.extractParams(e.getAttribute("route") || "/", t);
|
|
142
|
+
n && e.setAttribute("params", JSON.stringify(n));
|
|
30
143
|
} else
|
|
31
|
-
|
|
32
|
-
this.dispatchEvent(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
144
|
+
J.warn(`No view found for path: ${t}`);
|
|
145
|
+
this.dispatchEvent(new CustomEvent("route-changed", {
|
|
146
|
+
detail: {
|
|
147
|
+
path: t,
|
|
148
|
+
view: e
|
|
149
|
+
},
|
|
150
|
+
bubbles: !0,
|
|
151
|
+
composed: !0
|
|
152
|
+
}));
|
|
153
|
+
}), X(this, "interceptLinks", (t) => {
|
|
154
|
+
const e = t.target.closest("a");
|
|
155
|
+
if (!e) return;
|
|
156
|
+
const n = e.getAttribute("href");
|
|
157
|
+
!n || n.startsWith("http") || n.startsWith("#") || (t.preventDefault(), this.navigate(n));
|
|
44
158
|
});
|
|
45
159
|
}
|
|
46
160
|
render() {
|
|
47
|
-
return /* @__PURE__ */
|
|
161
|
+
return /* @__PURE__ */ Z("div", { class: "router-outlet" });
|
|
48
162
|
}
|
|
49
163
|
onConnected() {
|
|
50
|
-
|
|
164
|
+
J.debug("WsxRouter connected to DOM"), this.collectViews(), J.debug("WsxRouter collected views:", this.views.size), window.addEventListener("popstate", this.handleRouteChange), this.addEventListener("click", this.interceptLinks), this.handleRouteChange();
|
|
51
165
|
}
|
|
52
166
|
onDisconnected() {
|
|
53
167
|
window.removeEventListener("popstate", this.handleRouteChange);
|
|
54
168
|
}
|
|
55
169
|
collectViews() {
|
|
56
|
-
const t = Array.from(this.children).filter(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const i = r.getAttribute("route") || "/";
|
|
61
|
-
this.views.set(i, r), r.style.display = "none", v.debug(`WsxRouter hiding view for route: ${i}`);
|
|
170
|
+
const t = Array.from(this.children).filter((e) => e.tagName.toLowerCase() === "wsx-view");
|
|
171
|
+
J.debug("WsxRouter found views:", t.length), t.forEach((e) => {
|
|
172
|
+
const n = e.getAttribute("route") || "/";
|
|
173
|
+
this.views.set(n, e), e.style.display = "none", J.debug(`WsxRouter hiding view for route: ${n}`);
|
|
62
174
|
});
|
|
63
175
|
}
|
|
64
176
|
matchRoute(t) {
|
|
65
177
|
if (this.views.has(t))
|
|
66
178
|
return this.views.get(t);
|
|
67
|
-
for (const [
|
|
68
|
-
if (
|
|
69
|
-
const
|
|
70
|
-
if (new RegExp(`^${
|
|
71
|
-
return
|
|
179
|
+
for (const [e, n] of this.views)
|
|
180
|
+
if (e.includes(":")) {
|
|
181
|
+
const g = e.replace(/:[^/]+/g, "([^/]+)");
|
|
182
|
+
if (new RegExp(`^${g}$`).test(t))
|
|
183
|
+
return n;
|
|
72
184
|
}
|
|
73
185
|
return this.views.get("*") || null;
|
|
74
186
|
}
|
|
75
|
-
extractParams(t,
|
|
76
|
-
var
|
|
187
|
+
extractParams(t, e) {
|
|
188
|
+
var b;
|
|
77
189
|
if (!t.includes(":")) return null;
|
|
78
|
-
const
|
|
79
|
-
if (!
|
|
80
|
-
const
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
}),
|
|
190
|
+
const n = ((b = t.match(/:([^/]+)/g)) == null ? void 0 : b.map((O) => O.slice(1))) || [], g = t.replace(/:[^/]+/g, "([^/]+)"), R = new RegExp(`^${g}$`), _ = e.match(R);
|
|
191
|
+
if (!_ || !n.length) return null;
|
|
192
|
+
const I = {};
|
|
193
|
+
return n.forEach((O, z) => {
|
|
194
|
+
I[O] = _[z + 1];
|
|
195
|
+
}), I;
|
|
84
196
|
}
|
|
85
197
|
/**
|
|
86
198
|
* 编程式导航 - 使用原生 History API
|
|
@@ -89,107 +201,336 @@ class $ extends (F = I) {
|
|
|
89
201
|
window.history.pushState(null, "", t), this.handleRouteChange();
|
|
90
202
|
}
|
|
91
203
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
204
|
+
yt = Wt;
|
|
205
|
+
[At, wt] = Ct(yt, [], xt, 0, void 0, Y).c;
|
|
206
|
+
wt();
|
|
95
207
|
const lt = ":host{display:block;width:100%;height:100%}.route-view{width:100%;height:100%;position:relative}:host([loading]) .route-view{opacity:.5;transition:opacity .3s ease}:host([error]) .route-view{border:1px solid var(--error-color, #ff0000);padding:1rem}.route-view.entering{animation:fadeIn .3s ease-out}.route-view.leaving{animation:fadeOut .3s ease-in}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}@keyframes fadeOut{0%{opacity:1}to{opacity:0}}";
|
|
96
|
-
var
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
208
|
+
var tt, et;
|
|
209
|
+
let ut, Et, ht;
|
|
210
|
+
function B(r, t, e) {
|
|
211
|
+
return (t = St(t)) in r ? Object.defineProperty(r, t, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = e, r;
|
|
212
|
+
}
|
|
213
|
+
function Lt(r, t, e, n, g, R) {
|
|
214
|
+
function _(i, c, u) {
|
|
215
|
+
return function(s, a) {
|
|
216
|
+
return u && u(s), i[c].call(s, a);
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function I(i, c) {
|
|
220
|
+
for (var u = 0; u < i.length; u++) i[u].call(c);
|
|
221
|
+
return c;
|
|
222
|
+
}
|
|
223
|
+
function b(i, c, u, s) {
|
|
224
|
+
if (typeof i != "function" && (s || i !== void 0)) throw new TypeError(c + " must " + (u || "be") + " a function" + (s ? "" : " or undefined"));
|
|
225
|
+
return i;
|
|
226
|
+
}
|
|
227
|
+
function O(i, c, u, s, a, j, A, C, D, y, m, d, p) {
|
|
228
|
+
function w(l) {
|
|
229
|
+
if (!p(l)) throw new TypeError("Attempted to access private element on non-instance");
|
|
230
|
+
}
|
|
231
|
+
var h, x = c[0], k = c[3], $ = !C;
|
|
232
|
+
if (!$) {
|
|
233
|
+
u || Array.isArray(x) || (x = [x]);
|
|
234
|
+
var o = {}, E = [], v = a === 3 ? "get" : a === 4 || d ? "set" : "value";
|
|
235
|
+
y ? (m || d ? o = { get: ft(function() {
|
|
236
|
+
return k(this);
|
|
237
|
+
}, s, "get"), set: function(l) {
|
|
238
|
+
c[4](this, l);
|
|
239
|
+
} } : o[v] = k, m || ft(o[v], s, a === 2 ? "" : v)) : m || (o = Object.getOwnPropertyDescriptor(i, s));
|
|
240
|
+
}
|
|
241
|
+
for (var f = i, N = x.length - 1; N >= 0; N -= u ? 2 : 1) {
|
|
242
|
+
var H = x[N], q = u ? x[N - 1] : void 0, K = {}, W = { kind: ["field", "accessor", "method", "getter", "setter", "class"][a], name: s, metadata: j, addInitializer: (function(l, S) {
|
|
243
|
+
if (l.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
244
|
+
b(S, "An initializer", "be", !0), A.push(S);
|
|
245
|
+
}).bind(null, K) };
|
|
246
|
+
try {
|
|
247
|
+
if ($) (h = b(H.call(q, f, W), "class decorators", "return")) && (f = h);
|
|
248
|
+
else {
|
|
249
|
+
var L, P;
|
|
250
|
+
W.static = D, W.private = y, y ? a === 2 ? L = function(l) {
|
|
251
|
+
return w(l), o.value;
|
|
252
|
+
} : (a < 4 && (L = _(o, "get", w)), a !== 3 && (P = _(o, "set", w))) : (L = function(l) {
|
|
253
|
+
return l[s];
|
|
254
|
+
}, (a < 2 || a === 4) && (P = function(l, S) {
|
|
255
|
+
l[s] = S;
|
|
256
|
+
}));
|
|
257
|
+
var Q = W.access = { has: y ? p.bind() : function(l) {
|
|
258
|
+
return s in l;
|
|
259
|
+
} };
|
|
260
|
+
if (L && (Q.get = L), P && (Q.set = P), f = H.call(q, d ? { get: o.get, set: o.set } : o[v], W), d) {
|
|
261
|
+
if (typeof f == "object" && f) (h = b(f.get, "accessor.get")) && (o.get = h), (h = b(f.set, "accessor.set")) && (o.set = h), (h = b(f.init, "accessor.init")) && E.push(h);
|
|
262
|
+
else if (f !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
263
|
+
} else b(f, (m ? "field" : "method") + " decorators", "return") && (m ? E.push(f) : o[v] = f);
|
|
264
|
+
}
|
|
265
|
+
} finally {
|
|
266
|
+
K.v = !0;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return (m || d) && C.push(function(l, S) {
|
|
270
|
+
for (var U = E.length - 1; U >= 0; U--) S = E[U].call(l, S);
|
|
271
|
+
return S;
|
|
272
|
+
}), m || $ || (y ? d ? C.push(_(o, "get"), _(o, "set")) : C.push(a === 2 ? o[v] : _.call.bind(o[v])) : Object.defineProperty(i, s, o)), f;
|
|
273
|
+
}
|
|
274
|
+
function z(i, c) {
|
|
275
|
+
return Object.defineProperty(i, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
|
|
276
|
+
}
|
|
277
|
+
if (arguments.length >= 6) var M = R[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
278
|
+
var T = Object.create(M ?? null), G = function(i, c, u, s) {
|
|
279
|
+
var a, j, A = [], C = function(v) {
|
|
280
|
+
return Ot(v) === i;
|
|
281
|
+
}, D = /* @__PURE__ */ new Map();
|
|
282
|
+
function y(v) {
|
|
283
|
+
v && A.push(I.bind(null, v));
|
|
284
|
+
}
|
|
285
|
+
for (var m = 0; m < c.length; m++) {
|
|
286
|
+
var d = c[m];
|
|
287
|
+
if (Array.isArray(d)) {
|
|
288
|
+
var p = d[1], w = d[2], h = d.length > 3, x = 16 & p, k = !!(8 & p), $ = (p &= 7) == 0, o = w + "/" + k;
|
|
289
|
+
if (!$ && !h) {
|
|
290
|
+
var E = D.get(o);
|
|
291
|
+
if (E === !0 || E === 3 && p !== 4 || E === 4 && p !== 3) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + w);
|
|
292
|
+
D.set(o, !(p > 2) || p);
|
|
293
|
+
}
|
|
294
|
+
O(k ? i : i.prototype, d, x, h ? "#" + w : St(w), p, s, k ? j = j || [] : a = a || [], A, k, h, $, p === 1, k && h ? C : u);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return y(a), y(j), A;
|
|
298
|
+
}(r, t, g, T);
|
|
299
|
+
return e.length || z(r, T), { e: G, get c() {
|
|
300
|
+
var i = [];
|
|
301
|
+
return e.length && [z(O(r, [e], n, r.name, 5, T, i), T), I.bind(null, i, r)];
|
|
302
|
+
} };
|
|
303
|
+
}
|
|
304
|
+
function St(r) {
|
|
305
|
+
var t = It(r, "string");
|
|
306
|
+
return typeof t == "symbol" ? t : t + "";
|
|
307
|
+
}
|
|
308
|
+
function It(r, t) {
|
|
309
|
+
if (typeof r != "object" || !r) return r;
|
|
310
|
+
var e = r[Symbol.toPrimitive];
|
|
311
|
+
if (e !== void 0) {
|
|
312
|
+
var n = e.call(r, t);
|
|
313
|
+
if (typeof n != "object") return n;
|
|
314
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
315
|
+
}
|
|
316
|
+
return (t === "string" ? String : Number)(r);
|
|
317
|
+
}
|
|
318
|
+
function ft(r, t, e) {
|
|
319
|
+
typeof t == "symbol" && (t = (t = t.description) ? "[" + t + "]" : "");
|
|
320
|
+
try {
|
|
321
|
+
Object.defineProperty(r, "name", { configurable: !0, value: e ? e + " " + t : t });
|
|
322
|
+
} catch {
|
|
323
|
+
}
|
|
324
|
+
return r;
|
|
325
|
+
}
|
|
326
|
+
function Ot(r) {
|
|
327
|
+
if (Object(r) !== r) throw TypeError("right-hand side of 'in' should be an object, got " + (r !== null ? typeof r : "null"));
|
|
328
|
+
return r;
|
|
329
|
+
}
|
|
330
|
+
function Tt(r) {
|
|
331
|
+
return r;
|
|
332
|
+
}
|
|
333
|
+
const rt = F("WsxView");
|
|
334
|
+
Et = [ot({
|
|
335
|
+
tagName: "wsx-view"
|
|
336
|
+
})];
|
|
337
|
+
let dt;
|
|
338
|
+
new (ht = (et = class extends Y {
|
|
111
339
|
constructor() {
|
|
112
340
|
super({
|
|
113
341
|
styles: lt,
|
|
114
342
|
styleName: "wsx-view"
|
|
115
|
-
}),
|
|
343
|
+
}), B(this, "_autoStyles", lt), B(this, "component", null), B(this, "params", {}), B(this, "componentInstance", null);
|
|
116
344
|
}
|
|
117
345
|
render() {
|
|
118
|
-
return /* @__PURE__ */
|
|
346
|
+
return /* @__PURE__ */ Z("div", { class: "route-view" });
|
|
119
347
|
}
|
|
120
348
|
onConnected() {
|
|
121
349
|
const t = this.getAttribute("component");
|
|
122
350
|
t && !this.componentInstance && this.loadComponent(t);
|
|
123
351
|
}
|
|
124
|
-
onAttributeChanged(t,
|
|
125
|
-
if (t === "component" &&
|
|
126
|
-
this.loadComponent(
|
|
352
|
+
onAttributeChanged(t, e, n) {
|
|
353
|
+
if (t === "component" && n && !this.componentInstance)
|
|
354
|
+
this.loadComponent(n);
|
|
127
355
|
else if (t === "params" && this.componentInstance)
|
|
128
356
|
try {
|
|
129
|
-
this.params = JSON.parse(
|
|
130
|
-
this.componentInstance.setAttribute(
|
|
357
|
+
this.params = JSON.parse(n), Object.entries(this.params).forEach(([g, R]) => {
|
|
358
|
+
this.componentInstance.setAttribute(g, R);
|
|
131
359
|
});
|
|
132
|
-
} catch (
|
|
133
|
-
|
|
360
|
+
} catch (g) {
|
|
361
|
+
rt.error("Failed to parse params:", g);
|
|
134
362
|
}
|
|
135
363
|
}
|
|
136
364
|
async loadComponent(t) {
|
|
137
365
|
if (this.componentInstance && (this.componentInstance.remove(), this.componentInstance = null), !customElements.get(t)) {
|
|
138
|
-
|
|
366
|
+
rt.warn(`Component ${t} not found in customElements registry`);
|
|
139
367
|
return;
|
|
140
368
|
}
|
|
141
|
-
this.componentInstance = document.createElement(t), Object.keys(this.params).length > 0 && Object.entries(this.params).forEach(([
|
|
142
|
-
this.componentInstance.setAttribute(
|
|
369
|
+
this.componentInstance = document.createElement(t), Object.keys(this.params).length > 0 && Object.entries(this.params).forEach(([g, R]) => {
|
|
370
|
+
this.componentInstance.setAttribute(g, R);
|
|
143
371
|
});
|
|
144
|
-
const
|
|
145
|
-
|
|
372
|
+
const n = this.querySelector(".route-view");
|
|
373
|
+
n ? n.appendChild(this.componentInstance) : rt.error("Route view container not found");
|
|
146
374
|
}
|
|
147
375
|
onDisconnected() {
|
|
148
376
|
this.componentInstance && (this.componentInstance.remove(), this.componentInstance = null);
|
|
149
377
|
}
|
|
150
|
-
}
|
|
151
|
-
A = pt(T);
|
|
152
|
-
b = gt(A, 0, "WsxView", Q, b);
|
|
153
|
-
g(b, "observedAttributes", ["route", "component", "params"]);
|
|
154
|
-
ft(A, 1, b);
|
|
155
|
-
const _t = ':host{display:inline-block;min-width:fit-content;min-height:fit-content;width:auto;height:auto}.wsx-link{color:var(--link-color, #007bff);text-decoration:var(--link-decoration, underline);cursor:pointer;transition:color .2s ease;display:inline-block;min-height:1.2em;line-height:1.2}.wsx-link:hover{color:var(--link-hover-color, #0056b3);text-decoration:var(--link-hover-decoration, underline)}.wsx-link:focus{outline:2px solid var(--link-focus-color, #007bff);outline-offset:2px}.wsx-link.active{color:var(--link-active-color, #6c757d);font-weight:var(--link-active-weight, bold)}:host([disabled]) .wsx-link{color:var(--link-disabled-color, #6c757d);cursor:not-allowed;pointer-events:none}:host([external]) .wsx-link:after{content:"↗";font-size:.8em;margin-left:.2em;opacity:.7}:host([variant="button"]) .wsx-link{background-color:var(--button-bg, #007bff);color:var(--button-color, white);padding:.5rem 1rem;border-radius:.25rem;text-decoration:none;display:inline-block}:host([variant="button"]) .wsx-link:hover{background-color:var(--button-hover-bg, #0056b3);color:var(--button-hover-color, white)}:host([variant="tab"]) .wsx-link{padding:.5rem 1rem;border-bottom:2px solid transparent;text-decoration:none}:host([variant="tab"]) .wsx-link.active{border-bottom-color:var(--tab-active-border, #007bff)}';
|
|
156
|
-
var bt = Object.create, P = Object.defineProperty, xt = Object.getOwnPropertyDescriptor, H = (e, t) => (t = Symbol[e]) ? t : Symbol.for("Symbol." + e), J = (e) => {
|
|
157
|
-
throw TypeError(e);
|
|
158
|
-
}, B = (e, t, r) => t in e ? P(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, yt = (e, t) => P(e, "name", { value: t, configurable: !0 }), kt = (e) => [, , , bt((e == null ? void 0 : e[H("metadata")]) ?? null)], $t = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], G = (e) => e !== void 0 && typeof e != "function" ? J("Function expected") : e, Et = (e, t, r, i, o) => ({ kind: $t[e], name: t, metadata: i, addInitializer: (n) => r._ ? J("Already initialized") : o.push(G(n || null)) }), St = (e, t) => B(t, H("metadata"), e[3]), Ct = (e, t, r, i) => {
|
|
159
|
-
for (var o = 0, n = e[t >> 1], s = n && n.length; o < s; o++) n[o].call(r);
|
|
160
|
-
return i;
|
|
161
|
-
}, Rt = (e, t, r, i, o, n) => {
|
|
162
|
-
var s, l, c, a = t & 7, h = !1, p = 0, w = e[p] || (e[p] = []), d = a && (o = o.prototype, a < 5 && (a > 3 || !h) && xt(o, r));
|
|
163
|
-
yt(o, r);
|
|
164
|
-
for (var u = i.length - 1; u >= 0; u--)
|
|
165
|
-
c = Et(a, r, l = {}, e[3], w), s = (0, i[u])(o, c), l._ = 1, G(s) && (o = s);
|
|
166
|
-
return St(e, o), d && P(o, r, d), h ? a ^ 4 ? n : d : o;
|
|
167
|
-
}, m = (e, t, r) => B(e, typeof t != "symbol" ? t + "" : t, r), K, L, X;
|
|
168
|
-
const W = y("WsxLink");
|
|
169
|
-
K = [E({ tagName: "wsx-link" })];
|
|
170
|
-
class x extends (X = Y) {
|
|
378
|
+
}, [dt, ut] = Lt(et, [], Et, 0, void 0, Y).c, et), tt = class extends Tt {
|
|
171
379
|
constructor() {
|
|
172
|
-
super(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
380
|
+
super(dt), B(this, "observedAttributes", ["route", "component", "params"]), ut();
|
|
381
|
+
}
|
|
382
|
+
}, B(tt, ht, void 0), tt)();
|
|
383
|
+
const Dt = ':host{display:inline-block;min-width:fit-content;min-height:fit-content;width:auto;height:auto}.wsx-link{color:var(--link-color, #007bff);text-decoration:var(--link-decoration, underline);cursor:pointer;transition:color .2s ease;display:inline-block;min-height:1.2em;line-height:1.2}.wsx-link:hover{color:var(--link-hover-color, #0056b3);text-decoration:var(--link-hover-decoration, underline)}.wsx-link:focus{outline:2px solid var(--link-focus-color, #007bff);outline-offset:2px}.wsx-link.active{color:var(--link-active-color, #6c757d);font-weight:var(--link-active-weight, bold)}:host([disabled]) .wsx-link{color:var(--link-disabled-color, #6c757d);cursor:not-allowed;pointer-events:none}:host([external]) .wsx-link:after{content:"↗";font-size:.8em;margin-left:.2em;opacity:.7}:host([variant="button"]) .wsx-link{background-color:var(--button-bg, #007bff);color:var(--button-color, white);padding:.5rem 1rem;border-radius:.25rem;text-decoration:none;display:inline-block}:host([variant="button"]) .wsx-link:hover{background-color:var(--button-hover-bg, #0056b3);color:var(--button-hover-color, white)}:host([variant="tab"]) .wsx-link{padding:.5rem 1rem;border-bottom:2px solid transparent;text-decoration:none}:host([variant="tab"]) .wsx-link.active{border-bottom-color:var(--tab-active-border, #007bff)}';
|
|
384
|
+
var nt, it;
|
|
385
|
+
let pt, _t, vt;
|
|
386
|
+
function V(r, t, e) {
|
|
387
|
+
return (t = Rt(t)) in r ? Object.defineProperty(r, t, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = e, r;
|
|
388
|
+
}
|
|
389
|
+
function Nt(r, t, e, n, g, R) {
|
|
390
|
+
function _(i, c, u) {
|
|
391
|
+
return function(s, a) {
|
|
392
|
+
return u && u(s), i[c].call(s, a);
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function I(i, c) {
|
|
396
|
+
for (var u = 0; u < i.length; u++) i[u].call(c);
|
|
397
|
+
return c;
|
|
398
|
+
}
|
|
399
|
+
function b(i, c, u, s) {
|
|
400
|
+
if (typeof i != "function" && (s || i !== void 0)) throw new TypeError(c + " must " + (u || "be") + " a function" + (s ? "" : " or undefined"));
|
|
401
|
+
return i;
|
|
402
|
+
}
|
|
403
|
+
function O(i, c, u, s, a, j, A, C, D, y, m, d, p) {
|
|
404
|
+
function w(l) {
|
|
405
|
+
if (!p(l)) throw new TypeError("Attempted to access private element on non-instance");
|
|
406
|
+
}
|
|
407
|
+
var h, x = c[0], k = c[3], $ = !C;
|
|
408
|
+
if (!$) {
|
|
409
|
+
u || Array.isArray(x) || (x = [x]);
|
|
410
|
+
var o = {}, E = [], v = a === 3 ? "get" : a === 4 || d ? "set" : "value";
|
|
411
|
+
y ? (m || d ? o = { get: mt(function() {
|
|
412
|
+
return k(this);
|
|
413
|
+
}, s, "get"), set: function(l) {
|
|
414
|
+
c[4](this, l);
|
|
415
|
+
} } : o[v] = k, m || mt(o[v], s, a === 2 ? "" : v)) : m || (o = Object.getOwnPropertyDescriptor(i, s));
|
|
416
|
+
}
|
|
417
|
+
for (var f = i, N = x.length - 1; N >= 0; N -= u ? 2 : 1) {
|
|
418
|
+
var H = x[N], q = u ? x[N - 1] : void 0, K = {}, W = { kind: ["field", "accessor", "method", "getter", "setter", "class"][a], name: s, metadata: j, addInitializer: (function(l, S) {
|
|
419
|
+
if (l.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
420
|
+
b(S, "An initializer", "be", !0), A.push(S);
|
|
421
|
+
}).bind(null, K) };
|
|
422
|
+
try {
|
|
423
|
+
if ($) (h = b(H.call(q, f, W), "class decorators", "return")) && (f = h);
|
|
424
|
+
else {
|
|
425
|
+
var L, P;
|
|
426
|
+
W.static = D, W.private = y, y ? a === 2 ? L = function(l) {
|
|
427
|
+
return w(l), o.value;
|
|
428
|
+
} : (a < 4 && (L = _(o, "get", w)), a !== 3 && (P = _(o, "set", w))) : (L = function(l) {
|
|
429
|
+
return l[s];
|
|
430
|
+
}, (a < 2 || a === 4) && (P = function(l, S) {
|
|
431
|
+
l[s] = S;
|
|
432
|
+
}));
|
|
433
|
+
var Q = W.access = { has: y ? p.bind() : function(l) {
|
|
434
|
+
return s in l;
|
|
435
|
+
} };
|
|
436
|
+
if (L && (Q.get = L), P && (Q.set = P), f = H.call(q, d ? { get: o.get, set: o.set } : o[v], W), d) {
|
|
437
|
+
if (typeof f == "object" && f) (h = b(f.get, "accessor.get")) && (o.get = h), (h = b(f.set, "accessor.set")) && (o.set = h), (h = b(f.init, "accessor.init")) && E.push(h);
|
|
438
|
+
else if (f !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
439
|
+
} else b(f, (m ? "field" : "method") + " decorators", "return") && (m ? E.push(f) : o[v] = f);
|
|
440
|
+
}
|
|
441
|
+
} finally {
|
|
442
|
+
K.v = !0;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return (m || d) && C.push(function(l, S) {
|
|
446
|
+
for (var U = E.length - 1; U >= 0; U--) S = E[U].call(l, S);
|
|
447
|
+
return S;
|
|
448
|
+
}), m || $ || (y ? d ? C.push(_(o, "get"), _(o, "set")) : C.push(a === 2 ? o[v] : _.call.bind(o[v])) : Object.defineProperty(i, s, o)), f;
|
|
449
|
+
}
|
|
450
|
+
function z(i, c) {
|
|
451
|
+
return Object.defineProperty(i, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
|
|
452
|
+
}
|
|
453
|
+
if (arguments.length >= 6) var M = R[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
454
|
+
var T = Object.create(M ?? null), G = function(i, c, u, s) {
|
|
455
|
+
var a, j, A = [], C = function(v) {
|
|
456
|
+
return zt(v) === i;
|
|
457
|
+
}, D = /* @__PURE__ */ new Map();
|
|
458
|
+
function y(v) {
|
|
459
|
+
v && A.push(I.bind(null, v));
|
|
460
|
+
}
|
|
461
|
+
for (var m = 0; m < c.length; m++) {
|
|
462
|
+
var d = c[m];
|
|
463
|
+
if (Array.isArray(d)) {
|
|
464
|
+
var p = d[1], w = d[2], h = d.length > 3, x = 16 & p, k = !!(8 & p), $ = (p &= 7) == 0, o = w + "/" + k;
|
|
465
|
+
if (!$ && !h) {
|
|
466
|
+
var E = D.get(o);
|
|
467
|
+
if (E === !0 || E === 3 && p !== 4 || E === 4 && p !== 3) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + w);
|
|
468
|
+
D.set(o, !(p > 2) || p);
|
|
469
|
+
}
|
|
470
|
+
O(k ? i : i.prototype, d, x, h ? "#" + w : Rt(w), p, s, k ? j = j || [] : a = a || [], A, k, h, $, p === 1, k && h ? C : u);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return y(a), y(j), A;
|
|
474
|
+
}(r, t, g, T);
|
|
475
|
+
return e.length || z(r, T), { e: G, get c() {
|
|
476
|
+
var i = [];
|
|
477
|
+
return e.length && [z(O(r, [e], n, r.name, 5, T, i), T), I.bind(null, i, r)];
|
|
478
|
+
} };
|
|
479
|
+
}
|
|
480
|
+
function Rt(r) {
|
|
481
|
+
var t = Pt(r, "string");
|
|
482
|
+
return typeof t == "symbol" ? t : t + "";
|
|
483
|
+
}
|
|
484
|
+
function Pt(r, t) {
|
|
485
|
+
if (typeof r != "object" || !r) return r;
|
|
486
|
+
var e = r[Symbol.toPrimitive];
|
|
487
|
+
if (e !== void 0) {
|
|
488
|
+
var n = e.call(r, t);
|
|
489
|
+
if (typeof n != "object") return n;
|
|
490
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
491
|
+
}
|
|
492
|
+
return (t === "string" ? String : Number)(r);
|
|
493
|
+
}
|
|
494
|
+
function mt(r, t, e) {
|
|
495
|
+
typeof t == "symbol" && (t = (t = t.description) ? "[" + t + "]" : "");
|
|
496
|
+
try {
|
|
497
|
+
Object.defineProperty(r, "name", { configurable: !0, value: e ? e + " " + t : t });
|
|
498
|
+
} catch {
|
|
499
|
+
}
|
|
500
|
+
return r;
|
|
501
|
+
}
|
|
502
|
+
function zt(r) {
|
|
503
|
+
if (Object(r) !== r) throw TypeError("right-hand side of 'in' should be an object, got " + (r !== null ? typeof r : "null"));
|
|
504
|
+
return r;
|
|
505
|
+
}
|
|
506
|
+
function Ut(r) {
|
|
507
|
+
return r;
|
|
508
|
+
}
|
|
509
|
+
const gt = F("WsxLink");
|
|
510
|
+
_t = [ot({
|
|
511
|
+
tagName: "wsx-link"
|
|
512
|
+
})];
|
|
513
|
+
let bt;
|
|
514
|
+
new (vt = (it = class extends st {
|
|
515
|
+
constructor(...t) {
|
|
516
|
+
super(...t), V(this, "_autoStyles", Dt), V(this, "to", ""), V(this, "replace", !1), V(this, "activeClass", "active"), V(this, "exact", !1), V(this, "handleClick", (e) => {
|
|
517
|
+
if (e.preventDefault(), !this.to) {
|
|
518
|
+
gt.warn("No 'to' attribute specified");
|
|
178
519
|
return;
|
|
179
520
|
}
|
|
180
521
|
if (this.isExternalLink(this.to)) {
|
|
181
522
|
window.open(this.to, "_blank");
|
|
182
523
|
return;
|
|
183
524
|
}
|
|
184
|
-
this.replace ? window.history.replaceState(null, "", this.to) : window.history.pushState(null, "", this.to), window.dispatchEvent(new PopStateEvent("popstate")),
|
|
185
|
-
}),
|
|
186
|
-
var
|
|
187
|
-
const
|
|
188
|
-
|
|
525
|
+
this.replace ? window.history.replaceState(null, "", this.to) : window.history.pushState(null, "", this.to), window.dispatchEvent(new PopStateEvent("popstate")), gt.debug(`Navigated to: ${this.to}`);
|
|
526
|
+
}), V(this, "updateActiveState", () => {
|
|
527
|
+
var R;
|
|
528
|
+
const e = window.location.pathname, n = this.exact ? e === this.to : e.startsWith(this.to) && this.to !== "/", g = (R = this.shadowRoot) == null ? void 0 : R.querySelector("a");
|
|
529
|
+
g && (n ? (g.classList.add(this.activeClass), this.setAttribute("active", "")) : (g.classList.remove(this.activeClass), this.removeAttribute("active")));
|
|
189
530
|
});
|
|
190
531
|
}
|
|
191
532
|
render() {
|
|
192
|
-
return /* @__PURE__ */
|
|
533
|
+
return /* @__PURE__ */ Z("a", { href: this.to, class: "wsx-link", onClick: this.handleClick, part: "link" }, /* @__PURE__ */ Z("slot", null));
|
|
193
534
|
}
|
|
194
535
|
onConnected() {
|
|
195
536
|
this.to = this.getAttribute("to") || "", this.replace = this.hasAttribute("replace"), this.activeClass = this.getAttribute("active-class") || "active", this.exact = this.hasAttribute("exact");
|
|
@@ -199,19 +540,19 @@ class x extends (X = Y) {
|
|
|
199
540
|
onDisconnected() {
|
|
200
541
|
window.removeEventListener("popstate", this.updateActiveState), document.removeEventListener("route-changed", this.updateActiveState);
|
|
201
542
|
}
|
|
202
|
-
onAttributeChanged(t,
|
|
543
|
+
onAttributeChanged(t, e, n) {
|
|
203
544
|
switch (t) {
|
|
204
545
|
case "to":
|
|
205
|
-
this.to =
|
|
546
|
+
this.to = n || "", this.rerender(), this.updateActiveState();
|
|
206
547
|
break;
|
|
207
548
|
case "replace":
|
|
208
|
-
this.replace =
|
|
549
|
+
this.replace = n !== null && n !== "false";
|
|
209
550
|
break;
|
|
210
551
|
case "active-class":
|
|
211
|
-
this.activeClass =
|
|
552
|
+
this.activeClass = n || "active", this.updateActiveState();
|
|
212
553
|
break;
|
|
213
554
|
case "exact":
|
|
214
|
-
this.exact =
|
|
555
|
+
this.exact = n !== null && n !== "false", this.updateActiveState();
|
|
215
556
|
break;
|
|
216
557
|
}
|
|
217
558
|
}
|
|
@@ -222,25 +563,23 @@ class x extends (X = Y) {
|
|
|
222
563
|
* 编程式导航
|
|
223
564
|
*/
|
|
224
565
|
navigate() {
|
|
225
|
-
this.to && this.handleClick(
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
})
|
|
230
|
-
);
|
|
566
|
+
this.to && this.handleClick(new MouseEvent("click", {
|
|
567
|
+
bubbles: !0,
|
|
568
|
+
cancelable: !0
|
|
569
|
+
}));
|
|
231
570
|
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
class
|
|
571
|
+
}, [bt, pt] = Nt(it, [], _t, 0, void 0, st).c, it), nt = class extends Ut {
|
|
572
|
+
constructor() {
|
|
573
|
+
super(bt), V(this, "observedAttributes", ["to", "replace", "active-class", "exact"]), pt();
|
|
574
|
+
}
|
|
575
|
+
}, V(nt, vt, void 0), nt)();
|
|
576
|
+
const Vt = F("RouterUtils");
|
|
577
|
+
class Kt {
|
|
239
578
|
/**
|
|
240
579
|
* 编程式导航
|
|
241
580
|
*/
|
|
242
|
-
static navigate(t,
|
|
243
|
-
|
|
581
|
+
static navigate(t, e = !1) {
|
|
582
|
+
e ? window.history.replaceState(null, "", t) : window.history.pushState(null, "", t), window.dispatchEvent(new PopStateEvent("popstate")), Vt.debug(`Navigated to: ${t} (replace: ${e})`);
|
|
244
583
|
}
|
|
245
584
|
/**
|
|
246
585
|
* 获取当前路由信息
|
|
@@ -259,9 +598,9 @@ class Lt {
|
|
|
259
598
|
/**
|
|
260
599
|
* 解析路由路径,提取参数
|
|
261
600
|
*/
|
|
262
|
-
static parseRoute(t,
|
|
263
|
-
var
|
|
264
|
-
if (t ===
|
|
601
|
+
static parseRoute(t, e) {
|
|
602
|
+
var n;
|
|
603
|
+
if (t === e)
|
|
265
604
|
return {
|
|
266
605
|
route: t,
|
|
267
606
|
params: {},
|
|
@@ -274,21 +613,21 @@ class Lt {
|
|
|
274
613
|
exact: !1
|
|
275
614
|
};
|
|
276
615
|
if (t.includes(":")) {
|
|
277
|
-
const
|
|
278
|
-
if (
|
|
279
|
-
const
|
|
280
|
-
return
|
|
281
|
-
|
|
616
|
+
const g = ((n = t.match(/:([^/]+)/g)) == null ? void 0 : n.map((b) => b.slice(1))) || [], R = t.replace(/:[^/]+/g, "([^/]+)"), _ = new RegExp(`^${R}$`), I = e.match(_);
|
|
617
|
+
if (I && g.length > 0) {
|
|
618
|
+
const b = {};
|
|
619
|
+
return g.forEach((O, z) => {
|
|
620
|
+
b[O] = I[z + 1];
|
|
282
621
|
}), {
|
|
283
622
|
route: t,
|
|
284
|
-
params:
|
|
623
|
+
params: b,
|
|
285
624
|
exact: !0
|
|
286
625
|
};
|
|
287
626
|
}
|
|
288
627
|
}
|
|
289
628
|
if (t.endsWith("/*")) {
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
629
|
+
const g = t.slice(0, -2);
|
|
630
|
+
if (e.startsWith(g))
|
|
292
631
|
return {
|
|
293
632
|
route: t,
|
|
294
633
|
params: {},
|
|
@@ -300,37 +639,37 @@ class Lt {
|
|
|
300
639
|
/**
|
|
301
640
|
* 构建路由路径,替换参数
|
|
302
641
|
*/
|
|
303
|
-
static buildPath(t,
|
|
304
|
-
let
|
|
305
|
-
return Object.entries(
|
|
306
|
-
|
|
307
|
-
}),
|
|
642
|
+
static buildPath(t, e = {}) {
|
|
643
|
+
let n = t;
|
|
644
|
+
return Object.entries(e).forEach(([g, R]) => {
|
|
645
|
+
n = n.replace(`:${g}`, encodeURIComponent(R));
|
|
646
|
+
}), n;
|
|
308
647
|
}
|
|
309
648
|
/**
|
|
310
649
|
* 检查路由是否匹配当前路径
|
|
311
650
|
*/
|
|
312
|
-
static isRouteActive(t,
|
|
313
|
-
const
|
|
314
|
-
return
|
|
651
|
+
static isRouteActive(t, e = !1) {
|
|
652
|
+
const n = window.location.pathname;
|
|
653
|
+
return e ? n === t : t === "/" ? n === "/" : n.startsWith(t);
|
|
315
654
|
}
|
|
316
655
|
/**
|
|
317
656
|
* 获取路由层级
|
|
318
657
|
*/
|
|
319
658
|
static getRouteDepth(t) {
|
|
320
|
-
return t.split("/").filter((
|
|
659
|
+
return t.split("/").filter((e) => e.length > 0).length;
|
|
321
660
|
}
|
|
322
661
|
/**
|
|
323
662
|
* 获取父级路由
|
|
324
663
|
*/
|
|
325
664
|
static getParentRoute(t) {
|
|
326
|
-
const
|
|
327
|
-
return
|
|
665
|
+
const e = t.split("/").filter((n) => n.length > 0);
|
|
666
|
+
return e.length <= 1 ? "/" : (e.pop(), "/" + e.join("/"));
|
|
328
667
|
}
|
|
329
668
|
/**
|
|
330
669
|
* 合并路由路径
|
|
331
670
|
*/
|
|
332
671
|
static joinPaths(...t) {
|
|
333
|
-
return t.map((
|
|
672
|
+
return t.map((e) => e.replace(/^\/+|\/+$/g, "")).filter((e) => e.length > 0).join("/").replace(/^/, "/");
|
|
334
673
|
}
|
|
335
674
|
/**
|
|
336
675
|
* 检查是否为外部链接
|
|
@@ -347,20 +686,20 @@ class Lt {
|
|
|
347
686
|
/**
|
|
348
687
|
* 设置查询参数
|
|
349
688
|
*/
|
|
350
|
-
static setQueryParam(t,
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
this.navigate(
|
|
689
|
+
static setQueryParam(t, e, n = !1) {
|
|
690
|
+
const g = new URL(window.location.href);
|
|
691
|
+
g.searchParams.set(t, e);
|
|
692
|
+
const R = g.pathname + g.search + g.hash;
|
|
693
|
+
this.navigate(R, n);
|
|
355
694
|
}
|
|
356
695
|
/**
|
|
357
696
|
* 删除查询参数
|
|
358
697
|
*/
|
|
359
|
-
static removeQueryParam(t,
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
const
|
|
363
|
-
this.navigate(
|
|
698
|
+
static removeQueryParam(t, e = !1) {
|
|
699
|
+
const n = new URL(window.location.href);
|
|
700
|
+
n.searchParams.delete(t);
|
|
701
|
+
const g = n.pathname + n.search + n.hash;
|
|
702
|
+
this.navigate(g, e);
|
|
364
703
|
}
|
|
365
704
|
/**
|
|
366
705
|
* 返回上一页
|
|
@@ -390,18 +729,18 @@ class Lt {
|
|
|
390
729
|
* 监听路由变化
|
|
391
730
|
*/
|
|
392
731
|
static onRouteChange(t) {
|
|
393
|
-
const
|
|
394
|
-
const
|
|
395
|
-
t(
|
|
732
|
+
const e = () => {
|
|
733
|
+
const n = this.getCurrentRoute();
|
|
734
|
+
t(n);
|
|
396
735
|
};
|
|
397
|
-
return window.addEventListener("popstate",
|
|
398
|
-
window.removeEventListener("popstate",
|
|
736
|
+
return window.addEventListener("popstate", e), document.addEventListener("route-changed", e), () => {
|
|
737
|
+
window.removeEventListener("popstate", e), document.removeEventListener("route-changed", e);
|
|
399
738
|
};
|
|
400
739
|
}
|
|
401
740
|
}
|
|
402
741
|
export {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
742
|
+
Kt as RouterUtils,
|
|
743
|
+
bt as WsxLink,
|
|
744
|
+
At as WsxRouter,
|
|
745
|
+
dt as WsxView
|
|
407
746
|
};
|
package/package.json
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"dist",
|
|
16
|
-
"src",
|
|
17
|
-
"!**/__tests__",
|
|
18
|
-
"!**/test"
|
|
19
|
-
],
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "vite build",
|
|
22
|
-
"build:dev": "NODE_ENV=development vite build",
|
|
23
|
-
"dev": "NODE_ENV=development vite build --watch",
|
|
24
|
-
"clean": "rm -rf dist",
|
|
25
|
-
"test": "vitest",
|
|
26
|
-
"test:ui": "vitest --ui",
|
|
27
|
-
"test:coverage": "vitest --coverage",
|
|
28
|
-
"typecheck": "tsc --noEmit",
|
|
29
|
-
"lint": "eslint .",
|
|
30
|
-
"lint:fix": "eslint . --fix"
|
|
31
|
-
},
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"@wsxjs/wsx-core": "workspace:*"
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@wsxjs/eslint-plugin-wsx": "workspace:*",
|
|
37
|
-
"@wsxjs/wsx-vite-plugin": "workspace:*",
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "^8.37.0",
|
|
39
|
-
"@typescript-eslint/parser": "^8.37.0",
|
|
40
|
-
"@vitest/ui": "^2.1.8",
|
|
41
|
-
"@vitest/coverage-v8": "^2.1.8",
|
|
42
|
-
"eslint": "^9.31.0",
|
|
43
|
-
"jsdom": "^26.0.0",
|
|
44
|
-
"typescript": "^5.0.0",
|
|
45
|
-
"vite": "^5.4.19",
|
|
46
|
-
"vitest": "^2.1.8"
|
|
47
|
-
},
|
|
48
|
-
"keywords": [
|
|
49
|
-
"wsx",
|
|
50
|
-
"router",
|
|
51
|
-
"web-components",
|
|
52
|
-
"history-api",
|
|
53
|
-
"navigation",
|
|
54
|
-
"spa"
|
|
55
|
-
],
|
|
56
|
-
"author": "WSX Framework Team",
|
|
57
|
-
"license": "MIT",
|
|
58
|
-
"repository": {
|
|
59
|
-
"type": "git",
|
|
60
|
-
"url": "https://github.com/wsxjs/wsxjs.git",
|
|
61
|
-
"directory": "packages/wsx-router"
|
|
2
|
+
"name": "@wsxjs/wsx-router",
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"description": "WSX Router - Native History API-based routing for WSX Framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
62
12
|
}
|
|
63
|
-
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src",
|
|
17
|
+
"!**/__tests__",
|
|
18
|
+
"!**/test"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@wsxjs/wsx-core": "0.0.8"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^8.37.0",
|
|
25
|
+
"@typescript-eslint/parser": "^8.37.0",
|
|
26
|
+
"@vitest/ui": "^2.1.8",
|
|
27
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
28
|
+
"eslint": "^9.31.0",
|
|
29
|
+
"jsdom": "^26.0.0",
|
|
30
|
+
"typescript": "^5.0.0",
|
|
31
|
+
"vite": "^5.4.19",
|
|
32
|
+
"vitest": "^2.1.8",
|
|
33
|
+
"@wsxjs/wsx-vite-plugin": "0.0.8",
|
|
34
|
+
"@wsxjs/eslint-plugin-wsx": "0.0.8"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"wsx",
|
|
38
|
+
"router",
|
|
39
|
+
"web-components",
|
|
40
|
+
"history-api",
|
|
41
|
+
"navigation",
|
|
42
|
+
"spa"
|
|
43
|
+
],
|
|
44
|
+
"author": "WSX Framework Team",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/wsxjs/wsxjs.git",
|
|
49
|
+
"directory": "packages/wsx-router"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "vite build",
|
|
53
|
+
"build:dev": "NODE_ENV=development vite build",
|
|
54
|
+
"dev": "NODE_ENV=development vite build --watch",
|
|
55
|
+
"clean": "rm -rf dist",
|
|
56
|
+
"test": "vitest",
|
|
57
|
+
"test:ui": "vitest --ui",
|
|
58
|
+
"test:coverage": "vitest --coverage",
|
|
59
|
+
"typecheck": "tsc --noEmit",
|
|
60
|
+
"lint": "eslint .",
|
|
61
|
+
"lint:fix": "eslint . --fix"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/WsxLink.wsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/** @jsxImportSource @wsxjs/wsx-core */
|
|
2
2
|
import { WebComponent, autoRegister, createLogger } from "@wsxjs/wsx-core";
|
|
3
|
-
import styles from "./WsxLink.css?inline";
|
|
4
3
|
|
|
5
4
|
const logger = createLogger("WsxLink");
|
|
6
5
|
|
|
@@ -29,13 +28,6 @@ export default class WsxLink extends WebComponent {
|
|
|
29
28
|
private activeClass: string = "active";
|
|
30
29
|
private exact: boolean = false;
|
|
31
30
|
|
|
32
|
-
constructor() {
|
|
33
|
-
super({
|
|
34
|
-
styles,
|
|
35
|
-
styleName: "wsx-link",
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
31
|
render() {
|
|
40
32
|
return (
|
|
41
33
|
<a href={this.to} class="wsx-link" onClick={this.handleClick} part="link">
|