diff --git a/example/app.tsx b/example/app.tsx index d6bdc70..ea4529d 100644 --- a/example/app.tsx +++ b/example/app.tsx @@ -1,23 +1,25 @@ -import TWPreTail from "https://esm.sh/@twind/preset-tailwind@1.1.4"; -import TWPreAuto from "https://esm.sh/@twind/preset-autoprefix@1.0.7"; +import TWPreTail from "https://esm.sh/v115/@twind/preset-tailwind@1.1.4/es2022/preset-tailwind.mjs"; +import TWPreAuto from "https://esm.sh/v115/@twind/preset-autoprefix@1.0.7/es2022/preset-autoprefix.mjs"; import React from "react"; import Component from "./deep/component.tsx"; import * as Iso from "@eno/iso"; export default ()=> { - console.log(Iso.Meta); - const [countGet, countSet] = React.useState(1); return

Title!!

subtitle

- - About Us + + + About us! + sorry no page + lol/idk +

404!

; }; diff --git a/lib/iso.tsx b/lib/iso.tsx index fa6a91a..2b1789a 100644 --- a/lib/iso.tsx +++ b/lib/iso.tsx @@ -1,6 +1,5 @@ import React from "react"; - type Meta = {title:string, description:string, keywords:string, image:string, canonical:string } type MetaKeys = keyof Meta; export const Meta:Meta = { @@ -30,11 +29,14 @@ export const Metas =(props:{concatListed?:boolean; dropUnlisted?:boolean}&MetasI return null; } + +export type Children = string | number | React.JSX.Element | React.JSX.Element[]; + type RoutePath = Array; type RouteParams = Record; type RouteState = {URL:URL, Path:RoutePath, Params:RouteParams, Anchor:string}; type RouteContext = [Route:RouteState, Update:(inPath?:RoutePath, inParams?:RouteParams, inAnchor?:string)=>void]; -type RouteProps = {children:typeof React.Children, url?:URL }; +type RouteProps = {children:Children, url?:URL }; export const Router = { Parse(url:URL):RouteState { @@ -89,9 +91,7 @@ export const Router = { }) }, []); - return - {props.children} - ; + return {props.children}; }, Consumer() { @@ -101,54 +101,61 @@ export const Router = { type SwitchContext = {depth:number, keys:Record}; export const SwitchContext = React.createContext({depth:0, keys:{}} as SwitchContext); -export const Switch =({children}:{children:typeof React.Children})=> +export const Switch =({children}:{children:Children})=> { - const contextSelection = React.useContext(SwitchContext); - const [contextRoute] = Router.Consumer(); - const routeSegment = contextRoute.Path.slice(contextSelection.depth); - const checkChild =(inChild:{props:{value?:string}})=> + let fallback = null; + if(Array.isArray(children)) { - if(inChild?.props?.value) - { - const parts = inChild.props.value.split("/"); - if(parts.length > routeSegment.length) - { - return false; - } - - const output:SwitchContext = {depth:contextSelection.depth+parts.length, keys:{}}; - for(let i=0; i + { + if(inChild?.props?.value) + { + const parts = inChild.props.value.split("/"); + if(parts.length > routeSegment.length) { return false; } + + const output:SwitchContext = {depth:contextSelection.depth+parts.length, keys:{}}; + for(let i=0; i{childCaseChildren} + } + if(childCase?.props?.default && !fallback) + { + console.log(routeSegment); + fallback = childCaseChildren; + } + } } - for(let i=0; iRoute Rendred!{child} - } - } - return null; -}; -export const Case =({children, value}:{children:typeof React.Children, value?:string})=> -{ - return <>{children}; + return fallback; }; +export const Case =({children, value}:{children:Children, value?:string, default?:true})=>null; export const useRouteVars =()=> React.useContext(SwitchContext).keys; \ No newline at end of file diff --git a/server.tsx b/server.tsx index e6613ff..300d9c6 100644 --- a/server.tsx +++ b/server.tsx @@ -35,7 +35,7 @@ const Transpileable =(inFilePath:string):boolean=> }; const Transpile =async(inCode:string, inKey:string):Promise=> { - const transpile = await ESBuild.transform(inCode, { loader: "tsx", sourcemap: "inline", minify:false}); + const transpile = await ESBuild.transform(inCode, { loader: "tsx", minify:true}); Transpiled.set(inKey, transpile.code); return transpile.code; }; @@ -181,7 +181,7 @@ Deno.serve({ port: Deno.args[0]||3000 }, async(_req:Request) => const isLib = url.pathname.startsWith(`/${LibPath}/`); - if(Transpileable(pathLast)) + if(Transpileable(url.pathname)) { type = `application/javascript`; if(isLib) @@ -232,13 +232,12 @@ FileListen("${url.pathname}", reloadHandler);`; -
${results.html}