solely 0.4.4 → 0.4.5

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.
@@ -1 +1 @@
1
- "use strict";var t=Object.defineProperty,e=(e,r,o)=>((e,r,o)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o)(e,"symbol"!=typeof r?r+"":r,o);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("./core.cjs"),o=require("../runtime/component/base-element.cjs"),s=require("../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;const n=new Map;exports.default=class extends o.default{constructor(){super(...arguments),e(this,"unsubscribe"),e(this,"level",0),e(this,"currentElement",null),e(this,"currentTagName",null),e(this,"routerAttrs",new Set),e(this,"prevPropKeys",new Set),e(this,"scheduled",!1),e(this,"latestLoadId",0),e(this,"abortController",null),e(this,"router",null)}async mounted(){this.detectLevel(),this.router=await r.routerReady,this.unsubscribe=this.router.listen(()=>{this.scheduleLoad()}),this.loadRoute(this.router.getCurrentRoute())}unmounted(){var t;null==(t=this.unsubscribe)||t.call(this)}scheduleLoad(){if(!this.router)return;const t=this.router;this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.loadRoute(t.getCurrentRoute())}))}detectLevel(){let t=0,e=this.parentElement;for(;e;){const r=e.closest("router-view");if(r){if(t++,e=r.parentElement,!e){const t=r.getRootNode();e=t instanceof ShadowRoot?t.host:null}}else{const t=e.getRootNode();e=t instanceof ShadowRoot?t.host:null}}this.level=t}async loadRoute(t){var e,r;this.abortController&&(this.abortController.abort(),this.abortController=null);const o=++this.latestLoadId,s=null==t?void 0:t.matched[this.level];if(!s)return void this.handleEmptyRoute();const{config:n}=s;let i=n.tagName;if(!i&&"function"==typeof n.component){this.clear(),this.renderLoading(),this.abortController=new AbortController;const s=this.abortController.signal;try{let l;const a=null==(r=null==(e=this.router)?void 0:e.getComponentFromCache)?void 0:r.call(e,null==t?void 0:t.fullPath);if(l=a?await a:await n.component(),s.aborted||o!==this.latestLoadId)return;i="string"==typeof l?l:l.tagName}catch(a){if(s.aborted||o!==this.latestLoadId)return;return this.renderError(`Load Error: ${a}`),this.currentElement=null,void(this.currentTagName=null)}finally{this.abortController&&!s.aborted&&(this.abortController=null)}}if(o!==this.latestLoadId)return;if(!i)return void this.clear();if(!n.forceReload&&this.currentElement&&this.currentTagName===i.toLowerCase())return void this.syncState(this.currentElement,null==t?void 0:t.params,(null==t?void 0:t.query)||{},n.props);this.clear();const l=this.getOrCreateComponent(i,n);this.syncState(l,null==t?void 0:t.params,(null==t?void 0:t.query)||{},n.props),this.appendChild(l),this.currentElement=l,this.currentTagName=i.toLowerCase()}getOrCreateComponent(t,e){const r=`${this.level}-${t.toLowerCase()}`;if(e.keepAlive&&n.has(r)){const t=n.get(r);if(t)return t}const o=document.createElement(t);return e.keepAlive&&n.set(r,o),o}syncState(t,e,r,o={}){const s=t=>t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),n=new Map;Object.entries(e).forEach(([t,e])=>n.set(s(t),String(e))),Object.entries(r).forEach(([t,e])=>n.set(`query-${s(t)}`,String(e))),this.routerAttrs.forEach(e=>{n.has(e)||(t.removeAttribute(e),this.routerAttrs.delete(e))}),n.forEach((e,r)=>{t.getAttribute(r)!==e&&t.setAttribute(r,e),this.routerAttrs.add(r)});const i=new Set(Object.keys(o));this.prevPropKeys.forEach(e=>{i.has(e)||(t[e]=void 0)}),Object.entries(o).forEach(([e,r])=>{t[e]!==r&&(t[e]=r)}),this.prevPropKeys=i}handleEmptyRoute(){this.clear(),0===this.level&&this.renderError("404 Not Found")}renderLoading(){this.textContent="";const t=document.createElement("div");t.style.cssText="padding:20px; color:#999;",t.textContent="Loading...",this.appendChild(t)}renderError(t){this.textContent="";const e=document.createElement("div");e.style.cssText="padding:20px; color:#ff4d4f;",e.textContent=String(t),this.appendChild(e)}clear(){this.currentElement&&this.contains(this.currentElement)&&this.removeChild(this.currentElement),this.innerHTML="",this.currentElement=null,this.currentTagName=null,this.routerAttrs.clear(),this.prevPropKeys.clear()}},exports.default=((t,e)=>{for(var r,o=e,s=t.length-1;s>=0;s--)(r=t[s])&&(o=r(o)||o);return o})([s.CustomElement({tagName:"router-view"})],exports.default);
1
+ "use strict";var t=Object.defineProperty,e=(e,r,o)=>((e,r,o)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o)(e,"symbol"!=typeof r?r+"":r,o);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("./core.cjs"),o=require("../runtime/component/base-element.cjs"),n=require("../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;const s=new Map;exports.default=class extends o.default{constructor(){super(...arguments),e(this,"unsubscribe"),e(this,"level",0),e(this,"currentElement",null),e(this,"currentTagName",null),e(this,"routerAttrs",new Set),e(this,"prevPropKeys",new Set),e(this,"scheduled",!1),e(this,"latestLoadId",0),e(this,"abortController",null),e(this,"router",null)}async mounted(){this.detectLevel(),this.router=await r.routerReady,this.unsubscribe=this.router.listen(()=>{this.scheduleLoad()}),this.loadRoute(this.router.getCurrentRoute())}unmounted(){var t;null==(t=this.unsubscribe)||t.call(this)}scheduleLoad(){if(!this.router)return;const t=this.router;this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.loadRoute(t.getCurrentRoute())}))}detectLevel(){let t=0,e=this.parentElement;for(;e;){const r=e.closest("router-view");if(r){if(t++,e=r.parentElement,!e){const t=r.getRootNode();e=t instanceof ShadowRoot?t.host:null}}else{const t=e.getRootNode();e=t instanceof ShadowRoot?t.host:null}}this.level=t}async loadRoute(t){var e,r;this.abortController&&(this.abortController.abort(),this.abortController=null);const o=++this.latestLoadId,n=null==t?void 0:t.matched[this.level];if(!n)return void this.handleEmptyRoute();const{config:s}=n;let i=s.tagName;if(!i&&"function"==typeof s.component){this.clear(),this.renderLoading(),this.abortController=new AbortController;const n=this.abortController.signal;try{let l;const a=null==(r=null==(e=this.router)?void 0:e.getComponentFromCache)?void 0:r.call(e,null==t?void 0:t.fullPath);if(l=a?await a:await s.component(),n.aborted||o!==this.latestLoadId)return;i="string"==typeof l?l:l.tagName}catch(a){if(n.aborted||o!==this.latestLoadId)return;return this.renderError(`Load Error: ${a}`),this.currentElement=null,void(this.currentTagName=null)}finally{this.abortController&&!n.aborted&&(this.abortController=null)}}if(o!==this.latestLoadId)return;if(!i)return void this.clear();if(!s.forceReload&&this.currentElement&&this.currentTagName===i.toLowerCase())return void this.syncState(this.currentElement,null==t?void 0:t.params,(null==t?void 0:t.query)||{},s.props);this.clear();const l=this.getOrCreateComponent(i,s);this.syncState(l,null==t?void 0:t.params,(null==t?void 0:t.query)||{},s.props),this.appendChild(l),this.currentElement=l,this.currentTagName=i.toLowerCase()}getOrCreateComponent(t,e){const r=`${this.level}-${t.toLowerCase()}`;if(e.keepAlive&&s.has(r)){const t=s.get(r);if(t)return t}const o=document.createElement(t);return e.keepAlive&&s.set(r,o),o}syncState(t,e,r,o={}){const n=t=>t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),s=new Map;Object.entries(e).forEach(([t,e])=>s.set(n(t),String(e))),Object.entries(r).forEach(([t,e])=>s.set(`query-${n(t)}`,String(e))),this.routerAttrs.forEach(e=>{s.has(e)||(t.removeAttribute(e),this.routerAttrs.delete(e))}),s.forEach((e,r)=>{t.getAttribute(r)!==e&&t.setAttribute(r,e),this.routerAttrs.add(r)});const i=new Set(Object.keys(o));this.prevPropKeys.forEach(e=>{i.has(e)||(t[e]=void 0)}),Object.entries(o).forEach(([e,r])=>{t[e]!==r&&(t[e]=r)}),this.prevPropKeys=i}handleEmptyRoute(){var t,e,r;if(this.clear(),0===this.level){const o=null==(t=this.router)?void 0:t.getCurrentRoute(),n=null==(e=null==o?void 0:o.matched)?void 0:e[0],s=null==(r=null==n?void 0:n.config)?void 0:r.notFoundComponent;if(s){const t=document.createElement(s);this.appendChild(t),this.currentElement=t,this.currentTagName=s.toLowerCase()}else if(this.$data.notFound){const t=document.createElement(this.$data.notFound);this.appendChild(t),this.currentElement=t,this.currentTagName=this.$data.notFound.toLowerCase()}else this.renderError("404 Not Found")}}renderLoading(){this.textContent="";const t=document.createElement("div");t.style.cssText="padding:20px; color:#999;",t.textContent="Loading...",this.appendChild(t)}renderError(t){this.textContent="";const e=document.createElement("div");e.style.cssText="padding:20px; color:#ff4d4f;",e.textContent=String(t),this.appendChild(e)}clear(){this.currentElement&&this.contains(this.currentElement)&&this.removeChild(this.currentElement),this.innerHTML="",this.currentElement=null,this.currentTagName=null,this.routerAttrs.clear(),this.prevPropKeys.clear()}},exports.default=((t,e)=>{for(var r,o=e,n=t.length-1;n>=0;n--)(r=t[n])&&(o=r(o)||o);return o})([n.CustomElement({tagName:"router-view",props:[{name:"notFound",type:"string",default:""}]})],exports.default);
@@ -1,6 +1,8 @@
1
1
  import { BaseElement } from '../runtime/component';
2
2
  import { RouteMatch } from './types';
3
- declare class RouterView extends BaseElement {
3
+ declare class RouterView extends BaseElement<{
4
+ notFound: string;
5
+ }> {
4
6
  private unsubscribe?;
5
7
  private level;
6
8
  private currentElement;
@@ -1 +1 @@
1
- var t=Object.defineProperty,e=(e,r,o)=>((e,r,o)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o)(e,"symbol"!=typeof r?r+"":r,o);import{routerReady as r}from"./core.js";import o from"../runtime/component/base-element.js";import{CustomElement as n}from"../runtime/component/decorators.js";Object.getOwnPropertyDescriptor;const s=new Map;let i=class extends o{constructor(){super(...arguments),e(this,"unsubscribe"),e(this,"level",0),e(this,"currentElement",null),e(this,"currentTagName",null),e(this,"routerAttrs",new Set),e(this,"prevPropKeys",new Set),e(this,"scheduled",!1),e(this,"latestLoadId",0),e(this,"abortController",null),e(this,"router",null)}async mounted(){this.detectLevel(),this.router=await r,this.unsubscribe=this.router.listen(()=>{this.scheduleLoad()}),this.loadRoute(this.router.getCurrentRoute())}unmounted(){var t;null==(t=this.unsubscribe)||t.call(this)}scheduleLoad(){if(!this.router)return;const t=this.router;this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.loadRoute(t.getCurrentRoute())}))}detectLevel(){let t=0,e=this.parentElement;for(;e;){const r=e.closest("router-view");if(r){if(t++,e=r.parentElement,!e){const t=r.getRootNode();e=t instanceof ShadowRoot?t.host:null}}else{const t=e.getRootNode();e=t instanceof ShadowRoot?t.host:null}}this.level=t}async loadRoute(t){var e,r;this.abortController&&(this.abortController.abort(),this.abortController=null);const o=++this.latestLoadId,n=null==t?void 0:t.matched[this.level];if(!n)return void this.handleEmptyRoute();const{config:s}=n;let i=s.tagName;if(!i&&"function"==typeof s.component){this.clear(),this.renderLoading(),this.abortController=new AbortController;const n=this.abortController.signal;try{let l;const a=null==(r=null==(e=this.router)?void 0:e.getComponentFromCache)?void 0:r.call(e,null==t?void 0:t.fullPath);if(l=a?await a:await s.component(),n.aborted||o!==this.latestLoadId)return;i="string"==typeof l?l:l.tagName}catch(a){if(n.aborted||o!==this.latestLoadId)return;return this.renderError(`Load Error: ${a}`),this.currentElement=null,void(this.currentTagName=null)}finally{this.abortController&&!n.aborted&&(this.abortController=null)}}if(o!==this.latestLoadId)return;if(!i)return void this.clear();if(!s.forceReload&&this.currentElement&&this.currentTagName===i.toLowerCase())return void this.syncState(this.currentElement,null==t?void 0:t.params,(null==t?void 0:t.query)||{},s.props);this.clear();const l=this.getOrCreateComponent(i,s);this.syncState(l,null==t?void 0:t.params,(null==t?void 0:t.query)||{},s.props),this.appendChild(l),this.currentElement=l,this.currentTagName=i.toLowerCase()}getOrCreateComponent(t,e){const r=`${this.level}-${t.toLowerCase()}`;if(e.keepAlive&&s.has(r)){const t=s.get(r);if(t)return t}const o=document.createElement(t);return e.keepAlive&&s.set(r,o),o}syncState(t,e,r,o={}){const n=t=>t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),s=new Map;Object.entries(e).forEach(([t,e])=>s.set(n(t),String(e))),Object.entries(r).forEach(([t,e])=>s.set(`query-${n(t)}`,String(e))),this.routerAttrs.forEach(e=>{s.has(e)||(t.removeAttribute(e),this.routerAttrs.delete(e))}),s.forEach((e,r)=>{t.getAttribute(r)!==e&&t.setAttribute(r,e),this.routerAttrs.add(r)});const i=new Set(Object.keys(o));this.prevPropKeys.forEach(e=>{i.has(e)||(t[e]=void 0)}),Object.entries(o).forEach(([e,r])=>{t[e]!==r&&(t[e]=r)}),this.prevPropKeys=i}handleEmptyRoute(){this.clear(),0===this.level&&this.renderError("404 Not Found")}renderLoading(){this.textContent="";const t=document.createElement("div");t.style.cssText="padding:20px; color:#999;",t.textContent="Loading...",this.appendChild(t)}renderError(t){this.textContent="";const e=document.createElement("div");e.style.cssText="padding:20px; color:#ff4d4f;",e.textContent=String(t),this.appendChild(e)}clear(){this.currentElement&&this.contains(this.currentElement)&&this.removeChild(this.currentElement),this.innerHTML="",this.currentElement=null,this.currentTagName=null,this.routerAttrs.clear(),this.prevPropKeys.clear()}};i=((t,e)=>{for(var r,o=e,n=t.length-1;n>=0;n--)(r=t[n])&&(o=r(o)||o);return o})([n({tagName:"router-view"})],i);export{i as default};
1
+ var t=Object.defineProperty,e=(e,r,o)=>((e,r,o)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o)(e,"symbol"!=typeof r?r+"":r,o);import{routerReady as r}from"./core.js";import o from"../runtime/component/base-element.js";import{CustomElement as n}from"../runtime/component/decorators.js";Object.getOwnPropertyDescriptor;const s=new Map;let i=class extends o{constructor(){super(...arguments),e(this,"unsubscribe"),e(this,"level",0),e(this,"currentElement",null),e(this,"currentTagName",null),e(this,"routerAttrs",new Set),e(this,"prevPropKeys",new Set),e(this,"scheduled",!1),e(this,"latestLoadId",0),e(this,"abortController",null),e(this,"router",null)}async mounted(){this.detectLevel(),this.router=await r,this.unsubscribe=this.router.listen(()=>{this.scheduleLoad()}),this.loadRoute(this.router.getCurrentRoute())}unmounted(){var t;null==(t=this.unsubscribe)||t.call(this)}scheduleLoad(){if(!this.router)return;const t=this.router;this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.loadRoute(t.getCurrentRoute())}))}detectLevel(){let t=0,e=this.parentElement;for(;e;){const r=e.closest("router-view");if(r){if(t++,e=r.parentElement,!e){const t=r.getRootNode();e=t instanceof ShadowRoot?t.host:null}}else{const t=e.getRootNode();e=t instanceof ShadowRoot?t.host:null}}this.level=t}async loadRoute(t){var e,r;this.abortController&&(this.abortController.abort(),this.abortController=null);const o=++this.latestLoadId,n=null==t?void 0:t.matched[this.level];if(!n)return void this.handleEmptyRoute();const{config:s}=n;let i=s.tagName;if(!i&&"function"==typeof s.component){this.clear(),this.renderLoading(),this.abortController=new AbortController;const n=this.abortController.signal;try{let l;const a=null==(r=null==(e=this.router)?void 0:e.getComponentFromCache)?void 0:r.call(e,null==t?void 0:t.fullPath);if(l=a?await a:await s.component(),n.aborted||o!==this.latestLoadId)return;i="string"==typeof l?l:l.tagName}catch(a){if(n.aborted||o!==this.latestLoadId)return;return this.renderError(`Load Error: ${a}`),this.currentElement=null,void(this.currentTagName=null)}finally{this.abortController&&!n.aborted&&(this.abortController=null)}}if(o!==this.latestLoadId)return;if(!i)return void this.clear();if(!s.forceReload&&this.currentElement&&this.currentTagName===i.toLowerCase())return void this.syncState(this.currentElement,null==t?void 0:t.params,(null==t?void 0:t.query)||{},s.props);this.clear();const l=this.getOrCreateComponent(i,s);this.syncState(l,null==t?void 0:t.params,(null==t?void 0:t.query)||{},s.props),this.appendChild(l),this.currentElement=l,this.currentTagName=i.toLowerCase()}getOrCreateComponent(t,e){const r=`${this.level}-${t.toLowerCase()}`;if(e.keepAlive&&s.has(r)){const t=s.get(r);if(t)return t}const o=document.createElement(t);return e.keepAlive&&s.set(r,o),o}syncState(t,e,r,o={}){const n=t=>t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),s=new Map;Object.entries(e).forEach(([t,e])=>s.set(n(t),String(e))),Object.entries(r).forEach(([t,e])=>s.set(`query-${n(t)}`,String(e))),this.routerAttrs.forEach(e=>{s.has(e)||(t.removeAttribute(e),this.routerAttrs.delete(e))}),s.forEach((e,r)=>{t.getAttribute(r)!==e&&t.setAttribute(r,e),this.routerAttrs.add(r)});const i=new Set(Object.keys(o));this.prevPropKeys.forEach(e=>{i.has(e)||(t[e]=void 0)}),Object.entries(o).forEach(([e,r])=>{t[e]!==r&&(t[e]=r)}),this.prevPropKeys=i}handleEmptyRoute(){var t,e,r;if(this.clear(),0===this.level){const o=null==(t=this.router)?void 0:t.getCurrentRoute(),n=null==(e=null==o?void 0:o.matched)?void 0:e[0],s=null==(r=null==n?void 0:n.config)?void 0:r.notFoundComponent;if(s){const t=document.createElement(s);this.appendChild(t),this.currentElement=t,this.currentTagName=s.toLowerCase()}else if(this.$data.notFound){const t=document.createElement(this.$data.notFound);this.appendChild(t),this.currentElement=t,this.currentTagName=this.$data.notFound.toLowerCase()}else this.renderError("404 Not Found")}}renderLoading(){this.textContent="";const t=document.createElement("div");t.style.cssText="padding:20px; color:#999;",t.textContent="Loading...",this.appendChild(t)}renderError(t){this.textContent="";const e=document.createElement("div");e.style.cssText="padding:20px; color:#ff4d4f;",e.textContent=String(t),this.appendChild(e)}clear(){this.currentElement&&this.contains(this.currentElement)&&this.removeChild(this.currentElement),this.innerHTML="",this.currentElement=null,this.currentTagName=null,this.routerAttrs.clear(),this.prevPropKeys.clear()}};i=((t,e)=>{for(var r,o=e,n=t.length-1;n>=0;n--)(r=t[n])&&(o=r(o)||o);return o})([n({tagName:"router-view",props:[{name:"notFound",type:"string",default:""}]})],i);export{i as default};
@@ -35,6 +35,10 @@ export interface RouteConfig {
35
35
  * 实际上通常可以通过判断 component 属性是否存在来推断。
36
36
  */
37
37
  async?: boolean;
38
+ /** * 404 页面组件标签名。
39
+ * 当没有匹配到路由时显示的组件,优先级高于 RouterView 的 not-found 属性。
40
+ */
41
+ notFoundComponent?: string;
38
42
  }
39
43
  export interface MatchedRoute {
40
44
  config: RouteConfig;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solely",
3
3
  "private": false,
4
- "version": "0.4.4",
4
+ "version": "0.4.5",
5
5
  "description": "A lightweight TypeScript framework for building web components with compile-time optimizations",
6
6
  "type": "module",
7
7
  "sideEffects": false,