Compare commits

..

No commits in common. "6fe3ddbd3762541f0d26d5681ddad60da05dbef4" and "2af5d4f82341cca9f287d9961af1829cf2e13a94" have entirely different histories.

18 changed files with 66 additions and 91 deletions

View File

@ -1,14 +1,9 @@
{ {
"name": "@denreg-jsx", "name": "@denreg-jsx",
"version": "0.1.1", "version": "0.1.0",
"description": "Denreg JSX renderer", "description": "Denreg JSX renderer",
"author": "Fabian Stamm <dev@fabianstamm.de>", "author": "Fabian Stamm <dev@fabianstamm.de>",
"contributors": [], "contributors": [],
"deprecated": false, "deprecated": false,
"files": [ "files": ["**/*.ts", "**/*.js", "tsconfig.json", "README.md"]
"**/*.ts",
"**/*.js",
"tsconfig.json",
"README.md"
]
} }

View File

@ -83,6 +83,7 @@ async function renderHTML(element: Element) {
if (typeof element.component !== "string") if (typeof element.component !== "string")
throw new Error("Internal consistency error"); throw new Error("Internal consistency error");
console.log("Element:", element.component);
let props = ""; let props = "";
for (const key in element.props) { for (const key in element.props) {
@ -100,6 +101,7 @@ async function renderHTML(element: Element) {
inner = element.props["innerHTML"]; inner = element.props["innerHTML"];
} else { } else {
const children = cleanChildren(element.children); const children = cleanChildren(element.children);
if (tag == "body") console.log(element.children, children);
inner = ( inner = (
await Promise.all(children.map((child) => renderSSR(child))) await Promise.all(children.map((child) => renderSSR(child)))
).join(""); ).join("");
@ -112,6 +114,7 @@ async function renderCustom(element: Element) {
if (typeof element.component === "string") if (typeof element.component === "string")
throw new Error("Internal consistency error"); throw new Error("Internal consistency error");
console.log("Component:", element.component);
const res = await Promise.resolve( const res = await Promise.resolve(
element.component( element.component(
{ {

View File

@ -8,4 +8,4 @@ ADD public /app/public
RUN /usr/bin/deno cache --unstable src/registry.ts RUN /usr/bin/deno cache --unstable src/registry.ts
VOLUME [ "/app/data" ] VOLUME [ "/app/data" ]
ENTRYPOINT [ "/usr/bin/deno", "run", "-A", "--unstable", "--config", "tsconfig.json", "/app/src/registry.ts" ] ENTRYPOINT [ "/usr/bin/deno", "run", "-A", "--unstable", "/app/src/registry.ts" ]

View File

@ -15,7 +15,6 @@ const config =
if (!config.user) config.user = {}; if (!config.user) config.user = {};
if (!config.web) config.web = {}; if (!config.web) config.web = {};
if (!config.general) config.general = {};
const env = Deno.env.toObject(); const env = Deno.env.toObject();
@ -48,17 +47,11 @@ for (const key in env) {
case "WEB_TRACKING": case "WEB_TRACKING":
config.web.tracking = env[key]; config.web.tracking = env[key];
break; break;
case "GENERAL_DEV":
config.general.dev = env[key] === "true";
} }
} }
} }
} }
if (config.general.dev) {
console.warn("Dev mode active!!!");
}
console.log("Known users:", Object.keys(config.user)); console.log("Known users:", Object.keys(config.user));
export default config; export default config;

View File

@ -1,28 +1,40 @@
// @deno-types="./types/hotfix.d.ts" export * as S3 from "https://deno.land/x/s3@0.2.0/mod.ts";
export { S3Error } from "https://deno.land/x/s3@0.2.0/src/error.ts";
export * as S3 from "https://deno.land/x/s3@0.3.0/mod.ts"; export * as Ini from "https://deno.hibas123.de/raw/ini@0.0.1/mod.ts";
export { S3Error } from "https://deno.land/x/s3@0.3.0/src/error.ts";
export * as Ini from "https://deno.hibas123.de/raw/ini@0.0.3/mod.ts"; export * as ABC from "https://deno.land/x/abc@v1/mod.ts";
export * as CorsMW from "https://deno.land/x/abc@v1/middleware/cors.ts";
export * as LoggerMW from "https://deno.land/x/abc@v1/middleware/logger.ts";
export * as ABC from "https://deno.land/x/abc@v1.2.4/mod.ts"; export * as Path from "https://deno.land/std@0.74.0/path/mod.ts";
export * as CorsMW from "https://deno.land/x/abc@v1.2.4/middleware/cors.ts"; export * as FS from "https://deno.land/std@0.74.0/fs/mod.ts";
export * as LoggerMW from "https://deno.land/x/abc@v1.2.4/middleware/logger.ts"; export * as Base64 from "https://deno.land/std@0.74.0/encoding/base64.ts";
export * as Hash from "https://deno.land/std@0.74.0/hash/mod.ts";
export * as Path from "https://deno.land/std@0.83.0/path/mod.ts"; export * as Colors from "https://deno.land/std@0.74.0/fmt/colors.ts";
export * as FS from "https://deno.land/std@0.83.0/fs/mod.ts";
export * as Base64 from "https://deno.land/std@0.83.0/encoding/base64.ts";
export * as Hash from "https://deno.land/std@0.83.0/hash/mod.ts";
export * as Colors from "https://deno.land/std@0.83.0/fmt/colors.ts";
export * as Compress from "https://git.stamm.me/Deno/DenReg/raw/branch/master/tar/mod.ts"; export * as Compress from "https://git.stamm.me/Deno/DenReg/raw/branch/master/tar/mod.ts";
export { default as Prism } from "https://cdn.skypack.dev/prismjs"; export { default as Prism } from "https://cdn.skypack.dev/prismjs";
// export { Marked } from "https://deno.land/x/markdown/mod.ts";
// export { Marked } from "../../markdown/mod.ts";
export { Marked } from "https://deno.hibas123.de/raw/markdown/mod.ts"; export { Marked } from "https://deno.hibas123.de/raw/markdown/mod.ts";
import DS from "https://raw.githubusercontent.com/hibas123/dndb/master/mod.ts"; import DS from "https://raw.githubusercontent.com/hibas123/dndb/master/mod.ts";
export * as Pico from "../../jsx/mod.ts"; /// <reference path="./types/jsx.d.ts" />
export {
React,
jsx,
Fragment,
} from "https://deno.hibas123.de/raw/jsx-html/mod.ts";
// export {
// React,
// jsx,
// Fragment,
// } from "https://raw.githubusercontent.com/apiel/jsx-html/master/mod.ts";
export const Datastore = DS; export const Datastore = DS;

View File

@ -1,4 +1,4 @@
// /// <reference path="./types/jsx.d.ts" /> /// <reference path="./types/jsx.d.ts" />
import { ABC, CorsMW, LoggerMW, Path } from "./deps.ts"; import { ABC, CorsMW, LoggerMW, Path } from "./deps.ts";
import config from "./config.ts"; import config from "./config.ts";

View File

@ -1,12 +1,8 @@
/// <reference path="./types/jsx.d.ts" /> /// <reference path="./types/jsx.d.ts" />
import { Pico } from "./deps.ts"; import { React, jsx } from "./deps.ts";
import config from "./config.ts"; import config from "./config.ts";
const React = {
createElement: Pico.h.bind(Pico),
};
class StringReader implements Deno.Reader { class StringReader implements Deno.Reader {
private data: Uint8Array; private data: Uint8Array;
private offset = 0; private offset = 0;
@ -29,37 +25,15 @@ class StringReader implements Deno.Reader {
} }
} }
type ELM = any;
type Component = () => ELM;
const componentCache = new Map<string, Component>();
async function loadComponent(name: string) {
let mod = componentCache.get(name);
if (!mod || config.general.dev) {
mod = (await import(`./views/${name}.tsx`)).default;
if (!mod) throw new Error("Invalid component " + name);
componentCache.set(name, mod);
}
return mod;
}
const preLoad = ["index", "package", "browse_folder", "browse_file"];
preLoad.forEach((page) =>
loadComponent(page).catch((err) => console.error("Error preloading", page))
);
export default async function render( export default async function render(
name: string, name: string,
data: any data: any
): Promise<Deno.Reader> { ): Promise<Deno.Reader> {
const Component = await loadComponent(name); const component: {
default: () => JSX.IntrinsicElements | Promise<JSX.IntrinsicElements>;
} = await import(`./views/${name}.tsx`);
//@ts-ignore const res = await (<component.default {...data} />).render();
const res = await Pico.renderSSR(<Component {...data} />);
return new StringReader("<!DOCTYPE html>\n" + res); return new StringReader("<!DOCTYPE html>\n" + (res as string));
} }

View File

@ -1,4 +0,0 @@
// fixes an issue in std@0.80.0
interface ReadableStream<R> {
getIterator(): any;
}

5
registry/src/types/jsx.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
declare namespace JSX {
interface IntrinsicElements {
[elemName: string]: any;
}
}

View File

@ -1,4 +1,5 @@
import { Pico } from "../deps.ts"; /// <reference path="../types/jsx.d.ts" />
import { React } from "../deps.ts";
import config from "../config.ts"; import config from "../config.ts";
const styles = new TextDecoder().decode( const styles = new TextDecoder().decode(

View File

@ -1,4 +1,5 @@
import { Pico, Marked } from "../deps.ts"; /// <reference path="../types/jsx.d.ts" />
import { React, Marked } from "../deps.ts";
import type { IPackage } from "../db.ts"; import type { IPackage } from "../db.ts";
import { sortVersions } from "../utils.ts"; import { sortVersions } from "../utils.ts";

View File

@ -1,4 +1,5 @@
import { Pico } from "../deps.ts"; /// <reference path="../types/jsx.d.ts" />
import { React, Fragment } from "../deps.ts";
export function Main(a: any, children: any) { export function Main(a: any, children: any) {
return ( return (

View File

@ -1,5 +1,5 @@
// /// <reference path="../types/jsx.d.ts" /> /// <reference path="../types/jsx.d.ts" />
import { Pico, Marked } from "../deps.ts"; import { React, Fragment, Marked } from "../deps.ts";
import type { IPackage } from "../db.ts"; import type { IPackage } from "../db.ts";
export default async function index({ export default async function index({

View File

@ -1,4 +1,5 @@
import { Pico } from "../deps.ts"; /// <reference path="../types/jsx.d.ts" />
import { React } from "../deps.ts";
import Base from "./_base.tsx"; import Base from "./_base.tsx";
import type { IPackage } from "../db.ts"; import type { IPackage } from "../db.ts";

View File

@ -1,4 +1,5 @@
import { Pico } from "../deps.ts"; /// <reference path="../types/jsx.d.ts" />
import { React } from "../deps.ts";
import Base from "./_base.tsx"; import Base from "./_base.tsx";
import type { IPackage } from "../db.ts"; import type { IPackage } from "../db.ts";

View File

@ -1,4 +1,5 @@
import { Pico } from "../deps.ts"; /// <reference path="../types/jsx.d.ts" />
import { React, Fragment } from "../deps.ts";
import Base from "./_base.tsx"; import Base from "./_base.tsx";
import type { IPackage } from "../db.ts"; import type { IPackage } from "../db.ts";
import { sortVersions } from "../utils.ts"; import { sortVersions } from "../utils.ts";

View File

@ -1,4 +1,5 @@
import { Pico, Marked } from "../deps.ts"; /// <reference path="../types/jsx.d.ts" />
import { React, Fragment, Marked } from "../deps.ts";
import Base from "./_base.tsx"; import Base from "./_base.tsx";
import type { IPackage } from "../db.ts"; import type { IPackage } from "../db.ts";
import { sortVersions, getFile, getAbsolutePackageVersion } from "../utils.ts"; import { sortVersions, getFile, getAbsolutePackageVersion } from "../utils.ts";

View File

@ -1,10 +0,0 @@
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext", "deno.ns", "deno.unstable"],
"jsx": "react",
"jsxFactory": "Pico.h",
"jsxFragmentFactory": "Pico.Fragment",
"noImplicitAny": true,
"strictPropertyInitialization": false
}
}