xanix 1.0.4 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/bundler/buildClient.js +3 -3
- package/dist/bin/bundler/buildServer.js +4 -4
- package/dist/bin/bundler/cacheNpmModules.js +8 -2
- package/dist/bin/bundler/config/output.d.ts +1 -1
- package/dist/bin/bundler/config/output.js +11 -3
- package/dist/bin/bundler/plugins/XanixDocument/index.d.ts +2 -0
- package/dist/bin/bundler/plugins/XanixDocument/index.js +35 -0
- package/dist/bin/bundler/plugins/XanixEnv.js +13 -3
- package/dist/bin/bundler/plugins/XanixReactRefresh.js +33 -33
- package/dist/bin/bundler/plugins/XanixTransform/transformer copy.d.ts +16 -0
- package/dist/bin/bundler/plugins/XanixTransform/transformer copy.js +631 -0
- package/dist/bin/bundler/plugins/plugins.js +3 -1
- package/dist/bin/bundler/watchClient.js +3 -3
- package/dist/bin/bundler/watchServer.js +8 -5
- package/dist/bin/cli/dev.js +2 -2
- package/dist/bin/include/utils.d.ts +3 -0
- package/dist/bin/include/utils.js +17 -0
- package/dist/bin/index.js +0 -0
- package/dist/client-runtime.js +17 -15
- package/dist/components/BaseDocument.d.ts +1 -1
- package/dist/components/BaseDocument.js +1 -3
- package/dist/components/Body.js +3 -1
- package/dist/components/Document.js +3 -1
- package/dist/components/Head.d.ts +1 -1
- package/dist/components/Head.js +37 -34
- package/dist/components/Link.d.ts +1 -1
- package/dist/components/Link.js +23 -18
- package/dist/dataLoader.d.ts +1 -1
- package/dist/dataLoader.js +14 -5
- package/dist/hooks/useData.d.ts +2 -6
- package/dist/hooks/useData.js +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/navigate.js +11 -8
- package/dist/server/runtime/xanixPage.js +1 -4
- package/dist/types/assets.d.ts +34 -0
- package/dist/types/express.d.ts +12 -0
- package/dist/types/globals.d.ts +27 -0
- package/dist/types/xanix-virtual.d.ts +26 -0
- package/package.json +75 -73
- package/dist/BaseDocument.d.ts +0 -3
- package/dist/BaseDocument.js +0 -8
- package/dist/bin/bundler/buildCache.d.ts +0 -11
- package/dist/bin/bundler/buildCache.js +0 -112
- package/dist/bin/bundler/plugins/XanixAssets/index.d.ts +0 -4
- package/dist/bin/bundler/plugins/XanixAssets/index.js +0 -22
- package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.d.ts +0 -6
- package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.js +0 -350
- package/dist/bin/bundler/plugins/XanixHydrate.d.ts +0 -3
- package/dist/bin/bundler/plugins/XanixHydrate.js +0 -34
- package/dist/bin/bundler/plugins/commonjs.d.ts +0 -3
- package/dist/bin/bundler/plugins/commonjs.js +0 -10
- package/dist/bin/bundler/plugins/dep-XanixWatchChange.d.ts +0 -9
- package/dist/bin/bundler/plugins/dep-XanixWatchChange.js +0 -27
- package/dist/bin/bundler/plugins/nodeResolve.d.ts +0 -3
- package/dist/bin/bundler/plugins/nodeResolve.js +0 -10
- package/dist/bin/bundler/plugins/rollupEsbuild.d.ts +0 -3
- package/dist/bin/bundler/plugins/rollupEsbuild.js +0 -14
- package/dist/bin/cli/start copy.d.ts +0 -2
- package/dist/bin/cli/start copy.js +0 -34
- package/dist/client/client-runtime.d.ts +0 -10
- package/dist/client/client-runtime.js +0 -98
- package/dist/client/context/RouteContext.d.ts +0 -8
- package/dist/client/context/RouteContext.js +0 -16
- package/dist/client/hooks/usePageProps.d.ts +0 -1
- package/dist/client/hooks/usePageProps.js +0 -2
- package/dist/client/hooks/useRoute.d.ts +0 -1
- package/dist/client/hooks/useRoute.js +0 -2
- package/dist/client/hooks/useSearchParams.d.ts +0 -1
- package/dist/client/hooks/useSearchParams.js +0 -2
- package/dist/client/index.d.ts +0 -2
- package/dist/client/index.js +0 -2
- package/dist/client/navigation.d.ts +0 -3
- package/dist/client/navigation.js +0 -27
- package/dist/client/runtime.d.ts +0 -10
- package/dist/client/runtime.js +0 -98
- package/dist/components/Document/context.d.ts +0 -11
- package/dist/components/Document/context.js +0 -14
- package/dist/components/Document/index.d.ts +0 -8
- package/dist/components/Document/index.js +0 -6
- package/dist/document/BaseDocument.d.ts +0 -3
- package/dist/document/BaseDocument.js +0 -8
- package/dist/document/Body.d.ts +0 -5
- package/dist/document/Body.js +0 -8
- package/dist/document/Document.d.ts +0 -7
- package/dist/document/Document.js +0 -9
- package/dist/document/DocumentContext.d.ts +0 -18
- package/dist/document/DocumentContext.js +0 -6
- package/dist/document/Head.d.ts +0 -5
- package/dist/document/Head.js +0 -41
- package/dist/document/Link.d.ts +0 -7
- package/dist/document/Link.js +0 -28
- package/dist/document/Script.d.ts +0 -3
- package/dist/document/Script.js +0 -5
- package/dist/document/index.d.ts +0 -8
- package/dist/document/index.js +0 -7
- package/dist/document/useDocument.d.ts +0 -2
- package/dist/document/useDocument.js +0 -10
- package/dist/hooks/useCookie.d.ts +0 -2
- package/dist/hooks/useCookie.js +0 -13
- package/dist/hooks/useRequest copy.d.ts +0 -2
- package/dist/hooks/useRequest copy.js +0 -8
- package/dist/navigation/index.d.ts +0 -2
- package/dist/navigation/index.js +0 -2
- package/dist/navigation/navigate.d.ts +0 -7
- package/dist/navigation/navigate.js +0 -31
- package/dist/navigation/useLocation.d.ts +0 -1
- package/dist/navigation/useLocation.js +0 -22
- package/dist/router/index.d.ts +0 -3
- package/dist/router/index.js +0 -3
- package/dist/router/useParams.d.ts +0 -1
- package/dist/router/useParams.js +0 -5
- package/dist/router/usePathname.d.ts +0 -1
- package/dist/router/usePathname.js +0 -8
- package/dist/router/useSearchParams.d.ts +0 -11
- package/dist/router/useSearchParams.js +0 -74
- package/dist/runtime/createServer.d.ts +0 -12
- package/dist/runtime/createServer.js +0 -40
- package/dist/runtime/index.d.ts +0 -12
- package/dist/runtime/index.js +0 -40
- package/dist/runtime/readManifest.d.ts +0 -14
- package/dist/runtime/readManifest.js +0 -8
- package/dist/runtime/xanixPage.d.ts +0 -9
- package/dist/runtime/xanixPage.js +0 -62
- package/dist/server/createServer.d.ts +0 -12
- package/dist/server/createServer.js +0 -40
- package/dist/server/page.d.ts +0 -9
- package/dist/server/page.js +0 -62
- package/dist/server/readManifest.d.ts +0 -14
- package/dist/server/readManifest.js +0 -8
- package/dist/server/runtime copy.d.ts +0 -12
- package/dist/server/runtime copy.js +0 -40
- package/dist/server/runtime.d.ts +0 -12
- package/dist/server/runtime.js +0 -40
- package/dist/server/xanixPage.d.ts +0 -9
- package/dist/server/xanixPage.js +0 -62
- package/dist/types.d.ts +0 -12
- package/dist/types.js +0 -7
- package/dist/utils/index.d.ts +0 -0
- package/dist/utils/index.js +0 -1
- package/dist/xanix.d.ts +0 -3
- package/dist/xanix.js +0 -40
- package/xanix-env.d.ts +0 -79
package/dist/document/Head.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import useDocument from "./useDocument.js";
|
|
4
|
-
const Head = ({ children }) => {
|
|
5
|
-
const { title, meta, pageId, props, params } = useDocument();
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
document.title = title || "";
|
|
8
|
-
meta?.forEach(({ name, content }) => {
|
|
9
|
-
let element = document.querySelector(`meta[name="${name}"]`);
|
|
10
|
-
if (!element) {
|
|
11
|
-
element = document.createElement("meta");
|
|
12
|
-
element.setAttribute("name", name);
|
|
13
|
-
document.head.appendChild(element);
|
|
14
|
-
}
|
|
15
|
-
element.setAttribute("content", content);
|
|
16
|
-
});
|
|
17
|
-
// add children
|
|
18
|
-
const head = document.head;
|
|
19
|
-
if (children) {
|
|
20
|
-
const container = document.createElement("div");
|
|
21
|
-
container.innerHTML = children;
|
|
22
|
-
Array.from(container.children).forEach((child) => {
|
|
23
|
-
head.appendChild(child);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}, [children]);
|
|
27
|
-
if (__XANIX_CLIENT__)
|
|
28
|
-
return _jsx(_Fragment, {});
|
|
29
|
-
return (_jsxs("head", { children: [_jsx("title", { children: title }), meta?.map(({ name, content }) => (_jsx("meta", { name: name, content: content }, name))), children, _jsx("script", { id: pageId, dangerouslySetInnerHTML: {
|
|
30
|
-
__html: `window.XANIX_DOCUMENT = ${JSON.stringify({
|
|
31
|
-
pageId,
|
|
32
|
-
props,
|
|
33
|
-
meta,
|
|
34
|
-
title,
|
|
35
|
-
params,
|
|
36
|
-
request: null,
|
|
37
|
-
})};
|
|
38
|
-
`,
|
|
39
|
-
} }), _jsx("script", { type: "module", src: "/.xanix/client/xanix-runtime.js" })] }));
|
|
40
|
-
};
|
|
41
|
-
export default Head;
|
package/dist/document/Link.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { HTMLProps } from "react";
|
|
2
|
-
export type LinkProps = Omit<HTMLProps<HTMLAnchorElement>, "href" | "preload"> & {
|
|
3
|
-
preload?: boolean;
|
|
4
|
-
href: string;
|
|
5
|
-
};
|
|
6
|
-
declare const Link: ({ children, preload, ...props }: LinkProps) => import("react").JSX.Element;
|
|
7
|
-
export default Link;
|
package/dist/document/Link.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef } from "react";
|
|
3
|
-
import { navigate } from "../navigation/navigate.js";
|
|
4
|
-
const Link = ({ children, preload, ...props }) => {
|
|
5
|
-
const ref = useRef(null);
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
const load = () => {
|
|
8
|
-
window.dispatchEvent(new CustomEvent("xanix:preload", { detail: { path: props.href } }));
|
|
9
|
-
};
|
|
10
|
-
if (preload && ref.current) {
|
|
11
|
-
ref.current.addEventListener("mouseenter", load);
|
|
12
|
-
}
|
|
13
|
-
return () => {
|
|
14
|
-
if (preload && ref.current) {
|
|
15
|
-
ref.current.removeEventListener("mouseenter", load);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}, []);
|
|
19
|
-
if (preload) {
|
|
20
|
-
props.onMouseEnter;
|
|
21
|
-
}
|
|
22
|
-
return (_jsx("a", { ref: ref, ...props, onClick: (e) => {
|
|
23
|
-
e.preventDefault();
|
|
24
|
-
e.stopPropagation();
|
|
25
|
-
navigate(props.href);
|
|
26
|
-
}, children: children }));
|
|
27
|
-
};
|
|
28
|
-
export default Link;
|
package/dist/document/Script.js
DELETED
package/dist/document/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import Document, { DocumentProps } from "./Document.js";
|
|
2
|
-
import useDocument from "../hooks/useDocument.js";
|
|
3
|
-
import Head from "./Head.js";
|
|
4
|
-
import Body from "./Body.js";
|
|
5
|
-
import Link from "./Link.js";
|
|
6
|
-
import Script from "./Script.js";
|
|
7
|
-
export { Document, Head, Body, Link, Script, useDocument };
|
|
8
|
-
export type { DocumentProps };
|
package/dist/document/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import Document from "./Document.js";
|
|
2
|
-
import useDocument from "../hooks/useDocument.js";
|
|
3
|
-
import Head from "./Head.js";
|
|
4
|
-
import Body from "./Body.js";
|
|
5
|
-
import Link from "./Link.js";
|
|
6
|
-
import Script from "./Script.js";
|
|
7
|
-
export { Document, Head, Body, Link, Script, useDocument };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { DocumentContext } from "./DocumentContext";
|
|
2
|
-
import { useContext } from "react";
|
|
3
|
-
const useDocument = () => {
|
|
4
|
-
const context = useContext(DocumentContext);
|
|
5
|
-
if (!context) {
|
|
6
|
-
throw new Error("useDocument must be used within a DocumentProvider");
|
|
7
|
-
}
|
|
8
|
-
return context;
|
|
9
|
-
};
|
|
10
|
-
export default useDocument;
|
package/dist/hooks/useCookie.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import useRequest from "./useRequest";
|
|
2
|
-
const useCookie = () => {
|
|
3
|
-
const request = useRequest();
|
|
4
|
-
if (__XANIX_SERVER__) {
|
|
5
|
-
return request?.cookies;
|
|
6
|
-
}
|
|
7
|
-
return document.cookie.split(";").reduce((cookies, cookie) => {
|
|
8
|
-
const [name, value] = cookie.split("=");
|
|
9
|
-
cookies[name.trim()] = value;
|
|
10
|
-
return cookies;
|
|
11
|
-
}, {});
|
|
12
|
-
};
|
|
13
|
-
export default useCookie;
|
package/dist/navigation/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const navigate: (path: string, replace?: boolean) => void;
|
|
2
|
-
export declare const back: () => void;
|
|
3
|
-
export declare const forward: () => void;
|
|
4
|
-
export declare const preload: (path: string) => Promise<void>;
|
|
5
|
-
export declare const reload: (hard?: boolean) => void;
|
|
6
|
-
export declare const onNavigateStart: (callback: () => void) => void;
|
|
7
|
-
export declare const onNavigateEnd: (callback: () => void) => void;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export const navigate = (path, replace = false) => {
|
|
2
|
-
window.dispatchEvent(new CustomEvent("xanix:navigate", {
|
|
3
|
-
detail: { path, replace },
|
|
4
|
-
}));
|
|
5
|
-
};
|
|
6
|
-
export const back = () => {
|
|
7
|
-
window.history.back();
|
|
8
|
-
};
|
|
9
|
-
export const forward = () => {
|
|
10
|
-
window.history.forward();
|
|
11
|
-
};
|
|
12
|
-
export const preload = async (path) => {
|
|
13
|
-
window.dispatchEvent(new CustomEvent("xanix:preload", { detail: { path } }));
|
|
14
|
-
};
|
|
15
|
-
export const reload = (hard = false) => {
|
|
16
|
-
if (hard) {
|
|
17
|
-
window.location.reload();
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
window.dispatchEvent(new CustomEvent("xanix:reload"));
|
|
21
|
-
};
|
|
22
|
-
export const onNavigateStart = (callback) => {
|
|
23
|
-
if (__XANIX_CLIENT__) {
|
|
24
|
-
window.addEventListener("xanix:navigate:start", callback);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
export const onNavigateEnd = (callback) => {
|
|
28
|
-
if (__XANIX_CLIENT__) {
|
|
29
|
-
window.addEventListener("xanix:navigate:end", callback);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useLocation: () => URL;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { useDocument } from "../document/index.js";
|
|
2
|
-
import { useState, useEffect } from "react";
|
|
3
|
-
export const useLocation = () => {
|
|
4
|
-
const _document = useDocument();
|
|
5
|
-
const req = _document?.request;
|
|
6
|
-
let _url;
|
|
7
|
-
if (__XANIX_SERVER__) {
|
|
8
|
-
_url = new URL(req.originalUrl, `${req.protocol}://${req.get("host")}`);
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
_url = new URL(window.location.href);
|
|
12
|
-
}
|
|
13
|
-
const [url, setUrl] = useState(_url);
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
const onNavigate = () => setUrl(new URL(window.location.href));
|
|
16
|
-
window.addEventListener("xanix:navigate:end", onNavigate);
|
|
17
|
-
return () => {
|
|
18
|
-
window.removeEventListener("xanix:navigate:end", onNavigate);
|
|
19
|
-
};
|
|
20
|
-
}, []);
|
|
21
|
-
return url;
|
|
22
|
-
};
|
package/dist/router/index.d.ts
DELETED
package/dist/router/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useParams: () => any;
|
package/dist/router/useParams.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const usePathname: () => any;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const useSearchParams: () => {
|
|
2
|
-
get: (key: string) => string | null;
|
|
3
|
-
getAll: () => any;
|
|
4
|
-
has: (key: string) => boolean;
|
|
5
|
-
set: (key: string, value: string) => void;
|
|
6
|
-
sets: (entries: Record<string, string>) => void;
|
|
7
|
-
delete: (key: string) => void;
|
|
8
|
-
deletes: (keys: string[]) => void;
|
|
9
|
-
clear: () => void;
|
|
10
|
-
toString: () => string;
|
|
11
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { navigate } from "../navigation/navigate.js";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
import useDocument from "../hooks/useDocument.js";
|
|
4
|
-
const getParams = () => {
|
|
5
|
-
return new URLSearchParams(window.location.search);
|
|
6
|
-
};
|
|
7
|
-
const buildUrl = (params) => {
|
|
8
|
-
const search = params.toString();
|
|
9
|
-
return (window.location.pathname +
|
|
10
|
-
(search ? `?${search}` : "") +
|
|
11
|
-
window.location.hash);
|
|
12
|
-
};
|
|
13
|
-
export const useSearchParams = () => {
|
|
14
|
-
const { request } = useDocument();
|
|
15
|
-
let _params = new URLSearchParams(__XANIX_SERVER__ ? request.url.split("?")[1] || "" : window.location.search);
|
|
16
|
-
const [params, setParams] = useState(_params);
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
const onNavigate = () => {
|
|
19
|
-
setParams(getParams());
|
|
20
|
-
};
|
|
21
|
-
window.addEventListener("xanix:navigate:end", onNavigate);
|
|
22
|
-
window.addEventListener("popstate", onNavigate);
|
|
23
|
-
return () => {
|
|
24
|
-
window.removeEventListener("xanix:navigate:end", onNavigate);
|
|
25
|
-
window.removeEventListener("popstate", onNavigate);
|
|
26
|
-
};
|
|
27
|
-
}, []);
|
|
28
|
-
const update = (newParams) => {
|
|
29
|
-
setParams(newParams);
|
|
30
|
-
navigate(buildUrl(newParams));
|
|
31
|
-
};
|
|
32
|
-
return {
|
|
33
|
-
get: (key) => params.get(key),
|
|
34
|
-
getAll: () => {
|
|
35
|
-
const p = {};
|
|
36
|
-
for (const [key, value] of params.entries()) {
|
|
37
|
-
if (!p[key]) {
|
|
38
|
-
p[key] = [];
|
|
39
|
-
}
|
|
40
|
-
p[key].push(value);
|
|
41
|
-
}
|
|
42
|
-
return p;
|
|
43
|
-
},
|
|
44
|
-
has: (key) => params.has(key),
|
|
45
|
-
set: (key, value) => {
|
|
46
|
-
const newParams = new URLSearchParams(params);
|
|
47
|
-
newParams.set(key, value);
|
|
48
|
-
update(newParams);
|
|
49
|
-
},
|
|
50
|
-
sets: (entries) => {
|
|
51
|
-
const newParams = new URLSearchParams(params);
|
|
52
|
-
for (const [key, value] of Object.entries(entries)) {
|
|
53
|
-
newParams.set(key, value);
|
|
54
|
-
}
|
|
55
|
-
update(newParams);
|
|
56
|
-
},
|
|
57
|
-
delete: (key) => {
|
|
58
|
-
const newParams = new URLSearchParams(params);
|
|
59
|
-
newParams.delete(key);
|
|
60
|
-
update(newParams);
|
|
61
|
-
},
|
|
62
|
-
deletes: (keys) => {
|
|
63
|
-
const newParams = new URLSearchParams(params);
|
|
64
|
-
for (const key of keys) {
|
|
65
|
-
newParams.delete(key);
|
|
66
|
-
}
|
|
67
|
-
update(newParams);
|
|
68
|
-
},
|
|
69
|
-
clear: () => {
|
|
70
|
-
update(new URLSearchParams());
|
|
71
|
-
},
|
|
72
|
-
toString: () => params.toString(),
|
|
73
|
-
};
|
|
74
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
export interface XanixProps {
|
|
3
|
-
clientId: string;
|
|
4
|
-
req: any;
|
|
5
|
-
res: any;
|
|
6
|
-
component: React.ReactElement;
|
|
7
|
-
}
|
|
8
|
-
type Options = {
|
|
9
|
-
mode: "watch" | "start";
|
|
10
|
-
};
|
|
11
|
-
export declare function createXanixServer({ mode }: Options): express.Express;
|
|
12
|
-
export {};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
export function createXanixServer({ mode }) {
|
|
3
|
-
const app = express();
|
|
4
|
-
if (mode === "watch") {
|
|
5
|
-
app.use("/.xanix/client", express.static(".xanix/client"));
|
|
6
|
-
app.use("/assets", express.static(".xanix/assets"));
|
|
7
|
-
app.use("/.xanix/cache", express.static(".xanix/cache"));
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
app.use("/.xanix/client", express.static(".xanix/client", {
|
|
11
|
-
maxAge: "1y",
|
|
12
|
-
immutable: true,
|
|
13
|
-
etag: true,
|
|
14
|
-
}));
|
|
15
|
-
app.use("/assets", express.static(".xanix/assets", {
|
|
16
|
-
maxAge: "1y",
|
|
17
|
-
immutable: true,
|
|
18
|
-
etag: true,
|
|
19
|
-
}));
|
|
20
|
-
}
|
|
21
|
-
app.use((req, res, next) => {
|
|
22
|
-
let data = {
|
|
23
|
-
title: null,
|
|
24
|
-
meta: [],
|
|
25
|
-
};
|
|
26
|
-
if (!req.page) {
|
|
27
|
-
req.page = {
|
|
28
|
-
setTitle(title) {
|
|
29
|
-
data.title = title;
|
|
30
|
-
},
|
|
31
|
-
setMeta(name, content) {
|
|
32
|
-
data.meta.push({ name, content });
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
req.XanixPageData = data;
|
|
36
|
-
}
|
|
37
|
-
next();
|
|
38
|
-
});
|
|
39
|
-
return app;
|
|
40
|
-
}
|
package/dist/runtime/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
export interface XanixProps {
|
|
3
|
-
clientId: string;
|
|
4
|
-
req: any;
|
|
5
|
-
res: any;
|
|
6
|
-
component: React.ReactElement;
|
|
7
|
-
}
|
|
8
|
-
type Options = {
|
|
9
|
-
mode: "watch" | "start";
|
|
10
|
-
};
|
|
11
|
-
export declare function createXanixServer({ mode }: Options): express.Express;
|
|
12
|
-
export {};
|
package/dist/runtime/index.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
export function createXanixServer({ mode }) {
|
|
3
|
-
const app = express();
|
|
4
|
-
if (mode === "watch") {
|
|
5
|
-
app.use("/.xanix/client", express.static(".xanix/client"));
|
|
6
|
-
app.use("/assets", express.static(".xanix/assets"));
|
|
7
|
-
app.use("/.xanix/cache", express.static(".xanix/cache"));
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
app.use("/.xanix/client", express.static(".xanix/client", {
|
|
11
|
-
maxAge: "1y",
|
|
12
|
-
immutable: true,
|
|
13
|
-
etag: true,
|
|
14
|
-
}));
|
|
15
|
-
app.use("/assets", express.static(".xanix/assets", {
|
|
16
|
-
maxAge: "1y",
|
|
17
|
-
immutable: true,
|
|
18
|
-
etag: true,
|
|
19
|
-
}));
|
|
20
|
-
}
|
|
21
|
-
app.use((req, res, next) => {
|
|
22
|
-
let data = {
|
|
23
|
-
title: null,
|
|
24
|
-
meta: [],
|
|
25
|
-
};
|
|
26
|
-
if (!req.page) {
|
|
27
|
-
req.page = {
|
|
28
|
-
setTitle(title) {
|
|
29
|
-
data.title = title;
|
|
30
|
-
},
|
|
31
|
-
setMeta(name, content) {
|
|
32
|
-
data.meta.push({ name, content });
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
req.XanixPageData = data;
|
|
36
|
-
}
|
|
37
|
-
next();
|
|
38
|
-
});
|
|
39
|
-
return app;
|
|
40
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
interface XanixManifestEntry {
|
|
2
|
-
id: string;
|
|
3
|
-
name: string;
|
|
4
|
-
file: string;
|
|
5
|
-
path: string;
|
|
6
|
-
build: string;
|
|
7
|
-
export: string;
|
|
8
|
-
}
|
|
9
|
-
interface XanixManifest {
|
|
10
|
-
version: number;
|
|
11
|
-
entries: XanixManifestEntry[];
|
|
12
|
-
}
|
|
13
|
-
declare function readManifest(): Promise<XanixManifest>;
|
|
14
|
-
export default readManifest;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
async function readManifest() {
|
|
4
|
-
const manifestPath = path.resolve(process.cwd(), ".xanix", "client-manifest.json");
|
|
5
|
-
const source = await fs.readFile(manifestPath, "utf8");
|
|
6
|
-
return JSON.parse(source);
|
|
7
|
-
}
|
|
8
|
-
export default readManifest;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
interface XanixPageProps {
|
|
2
|
-
pageId: string;
|
|
3
|
-
req: any;
|
|
4
|
-
res: any;
|
|
5
|
-
Component: (props: Record<string, any>) => React.ReactElement;
|
|
6
|
-
props: Record<string, any>;
|
|
7
|
-
}
|
|
8
|
-
export default function xanix_page({ pageId, req, res, Component, props, }: XanixPageProps): Promise<string | undefined>;
|
|
9
|
-
export {};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { renderToPipeableStream } from "react-dom/server";
|
|
3
|
-
import readManifest from "./readManifest.js";
|
|
4
|
-
import { PassThrough } from "node:stream";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { pathToFileURL } from "node:url";
|
|
7
|
-
function renderPage(element) {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
let html = "";
|
|
10
|
-
const stream = new PassThrough();
|
|
11
|
-
stream.on("data", (chunk) => {
|
|
12
|
-
html += chunk.toString();
|
|
13
|
-
});
|
|
14
|
-
stream.on("end", () => {
|
|
15
|
-
resolve(html);
|
|
16
|
-
});
|
|
17
|
-
stream.on("error", reject);
|
|
18
|
-
const { pipe } = renderToPipeableStream(element, {
|
|
19
|
-
onAllReady() {
|
|
20
|
-
pipe(stream);
|
|
21
|
-
},
|
|
22
|
-
onError(error) {
|
|
23
|
-
console.error("SSR error:", error);
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
export default async function xanix_page({ pageId, req, res, Component, props, }) {
|
|
29
|
-
const manifest = await readManifest();
|
|
30
|
-
const { title, meta } = req.XanixPageData;
|
|
31
|
-
const entry = manifest.entries.find((item) => item.id === pageId);
|
|
32
|
-
const method = req.method.toUpperCase();
|
|
33
|
-
if (method !== "GET") {
|
|
34
|
-
res.status(405).send("Method Not Allowed");
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (!entry) {
|
|
38
|
-
throw new Error(`Xanix client entry "${pageId}" was not found in the manifest.`);
|
|
39
|
-
}
|
|
40
|
-
if ("x-navigation" in req.headers) {
|
|
41
|
-
res.setHeader("Content-Type", "application/json");
|
|
42
|
-
return JSON.stringify({
|
|
43
|
-
pageId,
|
|
44
|
-
props,
|
|
45
|
-
title: title ?? entry.name.replaceAll("-", " "),
|
|
46
|
-
meta,
|
|
47
|
-
params: req.params,
|
|
48
|
-
request: null,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
const Document = (await import(pathToFileURL(path.join(process.cwd(), ".xanix", "xanix-document.js"))
|
|
52
|
-
.href)).default;
|
|
53
|
-
const html = await renderPage(_jsx(Document, { document: {
|
|
54
|
-
pageId,
|
|
55
|
-
props,
|
|
56
|
-
title: title ?? entry.name.replaceAll("-", " "),
|
|
57
|
-
meta,
|
|
58
|
-
params: req.params,
|
|
59
|
-
request: req,
|
|
60
|
-
}, children: _jsx(Component, { ...props }) }));
|
|
61
|
-
return `<!DOCTYPE html>${html}`;
|
|
62
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
export interface XanixProps {
|
|
3
|
-
clientId: string;
|
|
4
|
-
req: any;
|
|
5
|
-
res: any;
|
|
6
|
-
component: React.ReactElement;
|
|
7
|
-
}
|
|
8
|
-
type Options = {
|
|
9
|
-
mode: "watch" | "start";
|
|
10
|
-
};
|
|
11
|
-
export declare function createXanixServer({ mode }: Options): express.Express;
|
|
12
|
-
export {};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
export function createXanixServer({ mode }) {
|
|
3
|
-
const app = express();
|
|
4
|
-
if (mode === "watch") {
|
|
5
|
-
app.use("/.xanix/client", express.static(".xanix/client"));
|
|
6
|
-
app.use("/assets", express.static(".xanix/assets"));
|
|
7
|
-
app.use("/.xanix/cache", express.static(".xanix/cache"));
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
app.use("/.xanix/client", express.static(".xanix/client", {
|
|
11
|
-
maxAge: "1y",
|
|
12
|
-
immutable: true,
|
|
13
|
-
etag: true,
|
|
14
|
-
}));
|
|
15
|
-
app.use("/assets", express.static(".xanix/assets", {
|
|
16
|
-
maxAge: "1y",
|
|
17
|
-
immutable: true,
|
|
18
|
-
etag: true,
|
|
19
|
-
}));
|
|
20
|
-
}
|
|
21
|
-
app.use((req, res, next) => {
|
|
22
|
-
let data = {
|
|
23
|
-
title: null,
|
|
24
|
-
meta: [],
|
|
25
|
-
};
|
|
26
|
-
if (!req.page) {
|
|
27
|
-
req.page = {
|
|
28
|
-
setTitle(title) {
|
|
29
|
-
data.title = title;
|
|
30
|
-
},
|
|
31
|
-
setMeta(name, content) {
|
|
32
|
-
data.meta.push({ name, content });
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
req.XanixPageData = data;
|
|
36
|
-
}
|
|
37
|
-
next();
|
|
38
|
-
});
|
|
39
|
-
return app;
|
|
40
|
-
}
|
package/dist/server/page.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
interface XanixPageProps {
|
|
2
|
-
pageId: string;
|
|
3
|
-
req: any;
|
|
4
|
-
res: any;
|
|
5
|
-
Component: (props: Record<string, any>) => React.ReactElement;
|
|
6
|
-
props: Record<string, any>;
|
|
7
|
-
}
|
|
8
|
-
export default function xanix_page({ pageId, req, res, Component, props, }: XanixPageProps): Promise<string | undefined>;
|
|
9
|
-
export {};
|