@dlightjs/components
Advanced tools
Comparing version 1.0.0-alpha.16 to 1.0.0-alpha.17
@@ -20,2 +20,3 @@ import { Typed, ContentProp } from '@dlightjs/types'; | ||
onPathUpdate?: (path: string) => void; | ||
fallback?: (View: any) => void; | ||
} | ||
@@ -22,0 +23,0 @@ declare const _default: Typed<RoutesProps, object>; |
@@ -1,2 +0,2 @@ | ||
var P=Object.defineProperty;var w=(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)=>(w(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(/^#/,""),l=a.split("/"),n=s.split("/").filter(u=>u),r=0;for(let u of l){if(![".",".."].includes(u))break;u===".."&&(n.length===0&&console.warn(`no ../ in ${a}`),n.pop()),r++}e="/"+[...n,...l.slice(r)].join("/")}return e}var i=class{mode;constructor(t="history"){this.mode=t}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 b,EnvNode as U,ExpNode as y,PropView as L}from"@dlightjs/dlight";import{View as M}from"@dlightjs/dlight";var v=null;var m=history.pushState,o=[],d=class extends M{constructor(t,e,s,l){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,l)}$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","watchPath","updateRoute"];get mode(){return this.$mode}set mode(t){this._$updateProp("mode",t)}$e$_$baseUrl;$_$baseUrl="";$$_$baseUrl=4;$s$_$baseUrl=["updateRoute"];get _$baseUrl(){return this.$_$baseUrl}set _$baseUrl(t){this._$updateProp("_$baseUrl",t)}$currUrl;$$currUrl=8;$s$currUrl=["watchPath","updateRoute"];get currUrl(){return this.$currUrl}set currUrl(t){this._$updateProp("currUrl",t)}get $f$currUrl(){return this.mode==="hash"?$():c()}$p$onPathUpdate;$onPathUpdate;$$onPathUpdate=16;$s$onPathUpdate=["watchPath"];get onPathUpdate(){return this.$onPathUpdate}set onPathUpdate(t){this._$updateProp("onPathUpdate",t)}$w$watchPath;watchPath(){this.onPathUpdate?.(this.currUrl)}$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 l=!1;if(d.regPathTest.test(e))l=new RegExp(e.replace(d.regPathTest,"$1")).test(t);else{let n=e.replace(/^(\.\/)+/,""),r=n==="."&&t==="",u=(t+"/").startsWith(n+"/");l=r||u||n==="*"}if(l){if(e===this.prevPathCondition)return;this.prevPathCondition=e,"propViewFunc"in s?this.currentRoute={view:s,type:"view"}:s().then(n=>{this.currentRoute={view:n.default,type:"lazy"}});return}}}historyChangeListen(){this.currUrl=c()}hashChangeListen(){this.currUrl=$()}willMount(){this.navigator.mode=this.mode}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 l=t.apply(e,s);return o.forEach(n=>n()),l}})}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 l=t.apply(e,s);return o.forEach(n=>n()),l}}):history.pushState=m}View(){let t=new U({_$baseUrl:`${this._$baseUrl}${this.prevPathCondition}/`,path:this.currUrl,navigator:this.navigator}),e=new b(s=>{if(this.currentRoute.type==="view"){if(s.cond===0)return s.didntChange=!0,[];let l=new y(()=>this.currentRoute.view);return l._$updateFunc=n=>{n&64&&l.update()},s.cond=0,[l]}else{if(s.cond===1)return s.didntChange=!0,[];let l=new L(()=>[new this.currentRoute.view(null,null,null,null)]),n=new y(()=>l);return n._$updateFunc=r=>{r&64&&n.update(),l.update(r)},s.cond=1,[n]}},64);return t.initNodes([e]),this._$update=s=>{s&10&&t.updateEnv("path",this.currUrl),s&36&&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 _=p;import{CondNode as x,ExpNode as C,PropView as T}from"@dlightjs/dlight";import{View as R}from"@dlightjs/dlight";function xt(a,t){class e extends R{constructor(l,n,r,u){super(),this.willMount=this.willMount.bind(this),this._$init(l,n,r,u)}_$forwardProps;_$forwardPropsSet=new Set;_$forwardPropsId=[];$v;$$v=8;get v(){return this.$v}set v(l){this._$updateProp("v",l)}willMount(){a().then(l=>{this.v=l.default})}View(){let l=new x(n=>{if(this.v){if(n.cond===0)return n.didntChange=!0,[];let r=new T(()=>[new this.v(null,null,null,this)]),u=new C(()=>r);return u._$updateFunc=h=>{h&8&&u.update(),r.update(h)},n.cond=0,[u]}else if(t){if(n.cond===1)return n.didntChange=!0,[];let r=new t(null,null,null,null);return n.cond=1,[r]}else return n.cond=-1,[]},8);return this._$update=n=>{n&8&&l.updateCond(),l.update(n)},[l]}}return e}export{i as Navigator,_ as Routes,xt as lazy}; | ||
var P=Object.defineProperty;var w=(s,t,e)=>t in s?P(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var g=(s,t,e)=>(w(s,typeof t!="symbol"?t+"":t,e),e);function $(){return location.hash.slice(2)}function c(){return location.pathname.slice(1)}function f(s,t){let e;if(s[0]==="/")e=s;else{s[0]!=="."&&(s="./"+s);let a=t==="history"?window.location.pathname:window.location.hash.replace(/^#/,""),n=s.split("/"),l=a.split("/").filter(u=>u),r=0;for(let u of n){if(![".",".."].includes(u))break;u===".."&&(l.length===0&&console.warn(`no ../ in ${s}`),l.pop()),r++}e="/"+[...l,...n.slice(r)].join("/")}return e}var i=class{mode;constructor(t="history"){this.mode=t}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 b,EnvNode as U,ExpNode as y,PropView as L}from"@dlightjs/dlight";import{View as M}from"@dlightjs/dlight";var v=null;var m=history.pushState,o=[],d=class extends M{constructor(t,e,a,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,a,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","watchPath","updateRoute"];get mode(){return this.$mode}set mode(t){this._$updateProp("mode",t)}$p$fallback;$fallback;$$fallback=4;$s$fallback=["updateRoute"];get fallback(){return this.$fallback}set fallback(t){this._$updateProp("fallback",t)}$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=["watchPath","updateRoute"];get currUrl(){return this.$currUrl}set currUrl(t){this._$updateProp("currUrl",t)}get $f$currUrl(){return this.mode==="hash"?$():c()}$p$onPathUpdate;$onPathUpdate;$$onPathUpdate=32;$s$onPathUpdate=["watchPath"];get onPathUpdate(){return this.$onPathUpdate}set onPathUpdate(t){this._$updateProp("onPathUpdate",t)}$w$watchPath;watchPath(){this.onPathUpdate?.(this.currUrl)}$prevPathCondition;$$prevPathCondition=64;get prevPathCondition(){return this.$prevPathCondition}set prevPathCondition(t){this._$updateProp("prevPathCondition",t)}$currentRoute={view:null,type:"view"};$$currentRoute=128;get currentRoute(){return this.$currentRoute}set currentRoute(t){this._$updateProp("currentRoute",t)}$navigator=new i;$$navigator=256;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,a]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 a?this.currentRoute={view:a,type:"view"}:(this.fallback&&(this.currentRoute={view:this.fallback,type:"view"}),a().then(l=>{this.currentRoute={view:l.default,type:"lazy"}}));return}}}historyChangeListen(){this.currUrl=c()}hashChangeListen(){this.currUrl=$()}willMount(){this.navigator.mode=this.mode}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,a){let n=t.apply(e,a);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,a){let n=t.apply(e,a);return o.forEach(l=>l()),n}}):history.pushState=m}View(){let t=new U({_$baseUrl:`${this._$baseUrl}${this.prevPathCondition}/`,path:this.currUrl,navigator:this.navigator}),e=new b(a=>{if(this.currentRoute.type==="view"){if(a.cond===0)return a.didntChange=!0,[];let n=new y(()=>this.currentRoute.view);return n._$updateFunc=l=>{l&128&&n.update()},a.cond=0,[n]}else{if(a.cond===1)return a.didntChange=!0,[];let n=new L(()=>[new this.currentRoute.view(null,null,null,null)]),l=new y(()=>n);return l._$updateFunc=r=>{r&128&&l.update(),n.update(r)},a.cond=1,[l]}},128);return t.initNodes([e]),this._$update=a=>{a&18&&t.updateEnv("path",this.currUrl),a&72&&t.updateEnv("_$baseUrl",`${this._$baseUrl}${this.prevPathCondition}/`),a&128&&e.updateCond(),a&256&&t.updateEnv("navigator",this.navigator),e.update(a)},[t]}},p=d;g(p,"regPathTest",/^\/\/(.+?)\/\/$/);var _=p;import{CondNode as x,ExpNode as R,PropView as C}from"@dlightjs/dlight";import{View as T}from"@dlightjs/dlight";function xt(s,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(){s().then(n=>{this.v=n.default})}View(){let n=new x(l=>{if(this.v){if(l.cond===0)return l.didntChange=!0,[];let r=new C(()=>[new this.v(null,null,null,this)]),u=new R(()=>r);return u._$updateFunc=h=>{h&8&&u.update(),r.update(h)},l.cond=0,[u]}else if(t){if(l.cond===1)return l.didntChange=!0,[];let r=new t(null,null,null,null);return l.cond=1,[r]}else return l.cond=-1,[]},8);return this._$update=l=>{l&8&&n.updateCond(),n.update(l)},[n]}}return e}export{i as Navigator,_ as Routes,xt as lazy}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@dlightjs/components", | ||
"version": "1.0.0-alpha.16", | ||
"version": "1.0.0-alpha.17", | ||
"description": "DLight components library", | ||
@@ -5,0 +5,0 @@ "author": { |
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
88288
80