@dlightjs/components
Advanced tools
Comparing version 1.0.0-alpha.7 to 1.0.0-alpha.8
@@ -1,2 +0,2 @@ | ||
var P=Object.defineProperty;var b=(a,t,e)=>t in a?P(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var g=(a,t,e)=>(b(a,typeof t!="symbol"?t+"":t,e),e);function $(){return location.hash.slice(2)}function c(){return location.pathname.slice(1)}function f(a,t){let e;if(a[0]==="/")e=a;else{a[0]!=="."&&(a="./"+a);let s=t==="history"?window.location.pathname:window.location.hash.replace(/^#/,""),n=a.split("/"),l=s.split("/").filter(u=>u),r=0;for(let u of n){if(![".",".."].includes(u))break;u===".."&&(l.length===0&&console.warn(`no ../ in ${a}`),l.pop()),r++}e="/"+[...l,...n.slice(r)].join("/")}return e}var i=class{mode="hash";hashTo(t){window.location.href="#"+f(t,this.mode)}historyTo(t){window.history.pushState({},"",f(t,this.mode))}to(t){if(this.mode==="hash"){this.hashTo(t);return}this.historyTo(t)}};import{EnvNode as L,ExpNode as y,PropView as M}from"@dlightjs/dlight";import{View as U}from"@dlightjs/dlight";var v=null;var m=history.pushState,o=[],d=class extends U{constructor(t,e,s,n){super(),this.historyChangeListen=this.historyChangeListen.bind(this),this.hashChangeListen=this.hashChangeListen.bind(this),this.willMount=this.willMount.bind(this),this.didMount=this.didMount.bind(this),this.willUnmount=this.willUnmount.bind(this),this._$init(t,e,s,n)}$p$routeMap;_$contentKey="routeMap";$routeMap=v;$$routeMap=1;$s$routeMap=["updateRoute"];get routeMap(){return this.$routeMap}set routeMap(t){this._$updateProp("routeMap",t)}$p$mode;$mode="history";$$mode=2;$s$mode=["currUrl","updateRoute"];get mode(){return this.$mode}set mode(t){this._$updateProp("mode",t)}$p$getNavigator;getNavigator;$e$_$baseUrl;$_$baseUrl="";$$_$baseUrl=8;$s$_$baseUrl=["updateRoute"];get _$baseUrl(){return this.$_$baseUrl}set _$baseUrl(t){this._$updateProp("_$baseUrl",t)}$currUrl;$$currUrl=16;$s$currUrl=["updateRoute"];get currUrl(){return this.$currUrl}set currUrl(t){this._$updateProp("currUrl",t)}get $f$currUrl(){return this.mode==="hash"?$():c()}$prevPathCondition;$$prevPathCondition=32;get prevPathCondition(){return this.$prevPathCondition}set prevPathCondition(t){this._$updateProp("prevPathCondition",t)}$currentRoute={view:null,type:"view"};$$currentRoute=64;get currentRoute(){return this.$currentRoute}set currentRoute(t){this._$updateProp("currentRoute",t)}$navigator=new i;$$navigator=128;get navigator(){return this.$navigator}set navigator(t){this._$updateProp("navigator",t)}isRoutes=!0;$w$updateRoute;updateRoute(){let t=this.currUrl.replace(new RegExp(`^${this._$baseUrl}`),"");for(let[e,s]of Object.entries(this.routeMap)){let n=!1;if(d.regPathTest.test(e))n=new RegExp(e.replace(d.regPathTest,"$1")).test(t);else{let l=e.replace(/^(\.\/)+/,""),r=l==="."&&t==="",u=(t+"/").startsWith(l+"/");n=r||u||l==="*"}if(n){if(e===this.prevPathCondition)return;this.prevPathCondition=e,"propViewFunc"in s?this.currentRoute={view:s,type:"view"}:s().then(l=>{this.currentRoute={view:l.default,type:"lazy"}});return}}}historyChangeListen(){this.currUrl=c()}hashChangeListen(){this.currUrl=$()}willMount(){this.updateRoute(),this.navigator.mode=this.mode,this.getNavigator?.(this.navigator)}didMount(){if(this.mode==="hash"){addEventListener("load",this.hashChangeListen),addEventListener("hashchange",this.hashChangeListen);return}addEventListener("load",this.historyChangeListen),addEventListener("popstate",this.historyChangeListen),o.push(this.historyChangeListen),history.pushState=new Proxy(m,{apply(t,e,s){let n=t.apply(e,s);return o.forEach(l=>l()),n}})}willUnmount(){if(this.mode==="hash"){removeEventListener("load",this.hashChangeListen),removeEventListener("hashchange",this.hashChangeListen);return}removeEventListener("load",this.historyChangeListen),removeEventListener("popstate",this.historyChangeListen),o=o.filter(t=>t!==this.historyChangeListen),o.length>0?history.pushState=new Proxy(m,{apply(t,e,s){let n=t.apply(e,s);return o.forEach(l=>l()),n}}):history.pushState=m}View(){let t=new L({_$baseUrl:`${this._$baseUrl}${this.prevPathCondition}/`,path:this.currUrl,navigator:this.navigator}),e=new CondNode(s=>{if(this.currentRoute.type==="view"){if(s.cond===0)return;let n=new y(()=>this.currentRoute.view);return n._$updateFunc=l=>{l&64&&n.update()},s.cond=0,[n]}else{if(s.cond===1)return;let n=new M(()=>[new this.currentRoute.view(null,null,null,null)]),l=new y(()=>n);return l._$updateFunc=r=>{r&64&&l.update(),n.update(r)},s.cond=1,[l]}});return t.initNodes([e]),this._$update=s=>{s&18&&t.updateEnv("path",this.currUrl),s&40&&t.updateEnv("_$baseUrl",`${this._$baseUrl}${this.prevPathCondition}/`),s&64&&e.updateCond(),s&128&&t.updateEnv("navigator",this.navigator),e.update(s)},[t]}},p=d;g(p,"regPathTest",/^\/\/(.+?)\/\/$/);var w=p;import{ExpNode as C,PropView as x}from"@dlightjs/dlight";import{View as T}from"@dlightjs/dlight";function Tt(a,t){class e extends T{constructor(n,l,r,u){super(),this.willMount=this.willMount.bind(this),this._$init(n,l,r,u)}_$forwardProps;_$forwardPropsSet=new Set;_$forwardPropsId=[];$v;$$v=8;get v(){return this.$v}set v(n){this._$updateProp("v",n)}willMount(){a().then(n=>{this.v=n.default})}View(){let n=new CondNode(l=>{if(this.v){if(l.cond===0)return;let r=new x(()=>[new this.v(null,null,null,this)]),u=new C(()=>r);return u._$updateFunc=h=>{h&8&&u.update(),r.update(h)},l.cond=0,[u]}else if(t){if(l.cond===1)return;let r=new t(null,null,null,null);return l.cond=1,[r]}else return l.cond=-1,[]});return this._$update=l=>{l&8&&n.updateCond(),n.update(l)},[n]}}return e}export{i as Navigator,w as Route,w as Routes,Tt as lazy}; | ||
var P=Object.defineProperty;var b=(a,t,s)=>t in a?P(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s;var g=(a,t,s)=>(b(a,typeof t!="symbol"?t+"":t,s),s);function $(){return location.hash.slice(2)}function c(){return location.pathname.slice(1)}function f(a,t){let s;if(a[0]==="/")s=a;else{a[0]!=="."&&(a="./"+a);let e=t==="history"?window.location.pathname:window.location.hash.replace(/^#/,""),n=a.split("/"),l=e.split("/").filter(u=>u),r=0;for(let u of n){if(![".",".."].includes(u))break;u===".."&&(l.length===0&&console.warn(`no ../ in ${a}`),l.pop()),r++}s="/"+[...l,...n.slice(r)].join("/")}return s}var i=class{mode="hash";hashTo(t){window.location.href="#"+f(t,this.mode)}historyTo(t){window.history.pushState({},"",f(t,this.mode))}to(t){if(this.mode==="hash"){this.hashTo(t);return}this.historyTo(t)}};import{CondNode as L,EnvNode as M,ExpNode as y,PropView as U}from"@dlightjs/dlight";import{View as x}from"@dlightjs/dlight";var v=null;var m=history.pushState,o=[],d=class extends x{constructor(t,s,e,n){super(),this.historyChangeListen=this.historyChangeListen.bind(this),this.hashChangeListen=this.hashChangeListen.bind(this),this.willMount=this.willMount.bind(this),this.didMount=this.didMount.bind(this),this.willUnmount=this.willUnmount.bind(this),this._$init(t,s,e,n)}$p$routeMap;_$contentKey="routeMap";$routeMap=v;$$routeMap=1;$s$routeMap=["updateRoute"];get routeMap(){return this.$routeMap}set routeMap(t){this._$updateProp("routeMap",t)}$p$mode;$mode="history";$$mode=2;$s$mode=["currUrl","updateRoute"];get mode(){return this.$mode}set mode(t){this._$updateProp("mode",t)}$p$getNavigator;getNavigator;$e$_$baseUrl;$_$baseUrl="";$$_$baseUrl=8;$s$_$baseUrl=["updateRoute"];get _$baseUrl(){return this.$_$baseUrl}set _$baseUrl(t){this._$updateProp("_$baseUrl",t)}$currUrl;$$currUrl=16;$s$currUrl=["updateRoute"];get currUrl(){return this.$currUrl}set currUrl(t){this._$updateProp("currUrl",t)}get $f$currUrl(){return this.mode==="hash"?$():c()}$prevPathCondition;$$prevPathCondition=32;get prevPathCondition(){return this.$prevPathCondition}set prevPathCondition(t){this._$updateProp("prevPathCondition",t)}$currentRoute={view:null,type:"view"};$$currentRoute=64;get currentRoute(){return this.$currentRoute}set currentRoute(t){this._$updateProp("currentRoute",t)}$navigator=new i;$$navigator=128;get navigator(){return this.$navigator}set navigator(t){this._$updateProp("navigator",t)}isRoutes=!0;$w$updateRoute;updateRoute(){let t=this.currUrl.replace(new RegExp(`^${this._$baseUrl}`),"");for(let[s,e]of Object.entries(this.routeMap)){let n=!1;if(d.regPathTest.test(s))n=new RegExp(s.replace(d.regPathTest,"$1")).test(t);else{let l=s.replace(/^(\.\/)+/,""),r=l==="."&&t==="",u=(t+"/").startsWith(l+"/");n=r||u||l==="*"}if(n){if(s===this.prevPathCondition)return;this.prevPathCondition=s,"propViewFunc"in e?this.currentRoute={view:e,type:"view"}:e().then(l=>{this.currentRoute={view:l.default,type:"lazy"}});return}}}historyChangeListen(){this.currUrl=c()}hashChangeListen(){this.currUrl=$()}willMount(){this.updateRoute(),this.navigator.mode=this.mode,this.getNavigator?.(this.navigator)}didMount(){if(this.mode==="hash"){addEventListener("load",this.hashChangeListen),addEventListener("hashchange",this.hashChangeListen);return}addEventListener("load",this.historyChangeListen),addEventListener("popstate",this.historyChangeListen),o.push(this.historyChangeListen),history.pushState=new Proxy(m,{apply(t,s,e){let n=t.apply(s,e);return o.forEach(l=>l()),n}})}willUnmount(){if(this.mode==="hash"){removeEventListener("load",this.hashChangeListen),removeEventListener("hashchange",this.hashChangeListen);return}removeEventListener("load",this.historyChangeListen),removeEventListener("popstate",this.historyChangeListen),o=o.filter(t=>t!==this.historyChangeListen),o.length>0?history.pushState=new Proxy(m,{apply(t,s,e){let n=t.apply(s,e);return o.forEach(l=>l()),n}}):history.pushState=m}View(){let t=new M({_$baseUrl:`${this._$baseUrl}${this.prevPathCondition}/`,path:this.currUrl,navigator:this.navigator}),s=new L(e=>{if(this.currentRoute.type==="view"){if(e.cond===0)return;let n=new y(()=>this.currentRoute.view);return n._$updateFunc=l=>{l&64&&n.update()},e.cond=0,[n]}else{if(e.cond===1)return;let n=new U(()=>[new this.currentRoute.view(null,null,null,null)]),l=new y(()=>n);return l._$updateFunc=r=>{r&64&&l.update(),n.update(r)},e.cond=1,[l]}});return t.initNodes([s]),this._$update=e=>{e&18&&t.updateEnv("path",this.currUrl),e&40&&t.updateEnv("_$baseUrl",`${this._$baseUrl}${this.prevPathCondition}/`),e&64&&s.updateCond(),e&128&&t.updateEnv("navigator",this.navigator),s.update(e)},[t]}},p=d;g(p,"regPathTest",/^\/\/(.+?)\/\/$/);var w=p;import{CondNode as C,ExpNode as T,PropView as _}from"@dlightjs/dlight";import{View as R}from"@dlightjs/dlight";function Tt(a,t){class s extends R{constructor(n,l,r,u){super(),this.willMount=this.willMount.bind(this),this._$init(n,l,r,u)}_$forwardProps;_$forwardPropsSet=new Set;_$forwardPropsId=[];$v;$$v=8;get v(){return this.$v}set v(n){this._$updateProp("v",n)}willMount(){a().then(n=>{this.v=n.default})}View(){let n=new C(l=>{if(this.v){if(l.cond===0)return;let r=new _(()=>[new this.v(null,null,null,this)]),u=new T(()=>r);return u._$updateFunc=h=>{h&8&&u.update(),r.update(h)},l.cond=0,[u]}else if(t){if(l.cond===1)return;let r=new t(null,null,null,null);return l.cond=1,[r]}else return l.cond=-1,[]});return this._$update=l=>{l&8&&n.updateCond(),n.update(l)},[n]}}return s}export{i as Navigator,w as Route,w as Routes,Tt as lazy}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@dlightjs/components", | ||
"version": "1.0.0-alpha.7", | ||
"version": "1.0.0-alpha.8", | ||
"description": "DLight components library", | ||
@@ -26,3 +26,3 @@ "author": { | ||
"@typescript-eslint/parser": "^6.16.0", | ||
"babel-preset-dlight": "1.0.0-alpha.12", | ||
"babel-preset-dlight": "1.0.0-alpha.13", | ||
"eslint": "^8.56.0", | ||
@@ -35,3 +35,3 @@ "eslint-config-prettier": "^9.1.0", | ||
"vite": "^4.5.1", | ||
"vite-plugin-dlight": "1.0.0-alpha.12" | ||
"vite-plugin-dlight": "1.0.0-alpha.13" | ||
}, | ||
@@ -38,0 +38,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
83924