Compare commits
2 Commits
6a5d97677a
...
a9139c6cd3
Author | SHA1 | Date | |
---|---|---|---|
a9139c6cd3 | |||
55b5bd28ab |
@ -1,7 +1,7 @@
|
||||
import React from "react";
|
||||
import * as TW from "https://esm.sh/@twind/core@1.0.1";
|
||||
import TWPreTail from "https://esm.sh/@twind/preset-tailwind@1.0.1";
|
||||
import TWPreAuto from "https://esm.sh/@twind/preset-autoprefix@1.0.1";
|
||||
import * as TW from "https://esm.sh/v126/@twind/core@1.1.3/es2022/core.mjs";
|
||||
import TWPreTail from "https://esm.sh/v126/@twind/preset-tailwind@1.1.3/es2022/preset-tailwind.mjs";
|
||||
import TWPreAuto from "https://esm.sh/v126/@twind/preset-autoprefix@1.0.7/es2022/preset-autoprefix.mjs";
|
||||
|
||||
const Configure =
|
||||
{
|
||||
@ -24,42 +24,6 @@ export const Shadow =(inElement:HTMLElement, inConfig?:TW.TwindUserConfig)=>
|
||||
return ShadowDiv;
|
||||
};
|
||||
|
||||
let booted = false;
|
||||
export const Boot =async(inSettings:{App:()=>React.JSX.Element, CSS?:TW.TwindUserConfig, DOM?:string})=>
|
||||
{
|
||||
if(booted){return;}
|
||||
booted = true;
|
||||
|
||||
const settings = {CSS:{...Configure, ...inSettings.CSS||{} }, DOM:inSettings.DOM||"#app", App:inSettings.App};
|
||||
|
||||
console.log("Clinet boot called")
|
||||
|
||||
let dom = document.querySelector(settings.DOM);
|
||||
if(!dom)
|
||||
{
|
||||
console.log(`element "${settings.DOM}" not found.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
dom = Shadow(dom as HTMLElement, settings.CSS)
|
||||
|
||||
const app = React.createElement(()=> React.createElement(settings.App, null), null);
|
||||
if(React.render)
|
||||
{
|
||||
React.render(app, dom);
|
||||
return ()=>dom && React.unmountComponentAtNode(dom);
|
||||
}
|
||||
else
|
||||
{
|
||||
const reactDom = await import(`https://esm.sh/react-dom@${React.version}/client`);
|
||||
const root = reactDom.createRoot(dom);
|
||||
root.render(app);
|
||||
return root.unmount;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export default async(inSelector:string, inModulePath:string, inMemberApp="default", inMemberCSS="CSS"):Promise<(()=>void)|false>=>
|
||||
{
|
||||
let dom = document.querySelector(inSelector);
|
@ -1,4 +1,4 @@
|
||||
import "../serve.tsx";
|
||||
import "./run-serve.tsx";
|
||||
|
||||
Deno.args.forEach(arg=>
|
||||
{
|
||||
@ -11,5 +11,5 @@ Deno.args.forEach(arg=>
|
||||
|
||||
if(Deno.env.get("dev"))
|
||||
{
|
||||
await import("../local.tsx");
|
||||
await import("./run-local.tsx");
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
{
|
||||
"react":"https://esm.sh/preact@10.15.1/compat",
|
||||
"react-original":"https://esm.sh/preact@10.15.1/compat",
|
||||
"@able/": "./_lib_/"
|
||||
"@able/": "./"
|
||||
},
|
||||
"tasks":
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
import "@able/boot.tsx";
|
||||
import "@able/boot-server.tsx";
|
||||
import React from "react";
|
||||
|
||||
const CTXString = React.createContext("lol");
|
||||
|
@ -3,7 +3,7 @@
|
||||
"imports":
|
||||
{
|
||||
"react":"https://esm.sh/preact@10.15.1/compat",
|
||||
"@able/":"http://localhost:4507/_lib_/"
|
||||
"@able/":"http://localhost:4507/"
|
||||
},
|
||||
"tasks":
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { type StateCapture } from "./react.tsx";
|
||||
|
||||
import { type StateCapture } from "./hmr-react.tsx";
|
||||
|
||||
const FileListeners = new Map() as Map<string, Array<(module:unknown)=>void>>;
|
||||
export const FileListen =(inPath:string, inHandler:()=>void)=>
|
||||
@ -21,7 +20,6 @@ Socket.addEventListener('message', async(event:{data:string})=>
|
||||
Socket.addEventListener("error", ()=>{clearInterval(SocketTimer); console.log("HMR socket lost")})
|
||||
const SocketTimer = setInterval(()=>{Socket.send("ping")}, 5000);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Each custom component is secretly modified to have an extra state and id.
|
||||
@ -46,10 +44,8 @@ When there is an HMR update:
|
||||
- statesNew is moved into *statesOld*
|
||||
- statesNew is cleared.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
const HMR =
|
||||
{
|
||||
reloads:1,
|
@ -1,5 +1,5 @@
|
||||
import * as ReactParts from "react-original";
|
||||
import { HMR } from "./hmr.tsx";
|
||||
import { HMR } from "./hmr-listen.tsx";
|
||||
|
||||
export type StateType = boolean|number|string|Record<string, string>
|
||||
export type StateCapture = {state:StateType, set:ReactParts.StateUpdater<StateType>, reload:number};
|
@ -1,4 +1,4 @@
|
||||
import {Configure, Transpile, Extension} from "./serve.tsx";
|
||||
import {Configure, Transpile, Extension} from "./run-serve.tsx";
|
||||
|
||||
const SocketsLive:Set<WebSocket> = new Set();
|
||||
const SocketsSend =(inData:string)=>{ console.log(inData); for (const socket of SocketsLive){ socket.send(inData); } }
|
||||
@ -21,7 +21,7 @@ Configure({
|
||||
Remap: (inImports)=>
|
||||
{
|
||||
inImports["react-original"] = inImports["react"];
|
||||
inImports["react"] = "/_lib_/react.tsx";
|
||||
inImports["react"] = "/_lib_/hmr-react.tsx";
|
||||
return inImports;
|
||||
},
|
||||
async Serve(inReq, inURL, inExt, inMap, inProxy)
|
||||
@ -33,7 +33,7 @@ Configure({
|
||||
for( const key in imp ) { members.push(key); }
|
||||
|
||||
const code =`
|
||||
import {FileListen} from "/_lib_/hmr.tsx";
|
||||
import {FileListen} from "/_lib_/hmr-listen.tsx";
|
||||
import * as Import from "${inURL.pathname}?reload=0";
|
||||
${ members.map(m=>`let proxy_${m} = Import.${m}; export { proxy_${m} as ${m} };`).join("\n") }
|
||||
FileListen("${inURL.pathname}", (updatedModule)=>
|
@ -74,12 +74,14 @@ let Configuration:Configuration =
|
||||
`<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
<meta charset="utf-8"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="importmap">${JSON.stringify(inMap)}</script>
|
||||
<script type="module">
|
||||
import Mount from "/_lib_/mount.tsx";
|
||||
import Mount from "/_lib_/boot-browser.tsx";
|
||||
Mount("#app", "${parts[1]??"/app.tsx"}");
|
||||
</script>
|
||||
</body>
|
||||
@ -192,14 +194,17 @@ HTTP.serve(async(req: Request)=>
|
||||
let path;
|
||||
if(url.pathname.startsWith("/_lib_/"))
|
||||
{
|
||||
if(url.pathname.endsWith("boot.tsx"))
|
||||
const clipRoot = import.meta.url.substring(0, import.meta.url.lastIndexOf("/"));
|
||||
const clipPath = url.pathname.substring(url.pathname.indexOf("/", 1));
|
||||
if(clipPath.startsWith("/boot-"))
|
||||
{
|
||||
path = import.meta.url+"/../_lib_/mount.tsx";
|
||||
path = clipRoot+"/boot-browser.tsx";
|
||||
}
|
||||
else
|
||||
{
|
||||
path = import.meta.url+"/.."+url.pathname;
|
||||
path = clipRoot + clipPath;
|
||||
}
|
||||
console.log("transpiling", path);
|
||||
code = await Transpile.Fetch(path, url.pathname, true);
|
||||
}
|
||||
else
|
Loading…
Reference in New Issue
Block a user