xanix 1.0.5 → 1.0.8
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 +2 -3
- package/dist/bin/bundler/{buildCache.js → cacheNpmModules copy.js } +71 -21
- package/dist/bin/bundler/cacheNpmModules.js +9 -5
- package/dist/bin/bundler/config/output.js +9 -1
- 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 +10 -3
- package/dist/bin/bundler/plugins/XanixReactRefresh.js +29 -36
- 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 +2 -3
- package/dist/bin/include/utils.d.ts +2 -1
- package/dist/bin/include/utils.js +9 -6
- package/dist/bin/index.js +0 -0
- package/dist/client-runtime.js +15 -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 +11 -5
- package/dist/hooks/useData.d.ts +2 -6
- package/dist/hooks/useData.js +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -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 +26 -0
- package/dist/types/xanix-virtual.d.ts +26 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +4 -0
- package/package.json +79 -73
- package/dist/BaseDocument.d.ts +0 -3
- package/dist/BaseDocument.js +0 -8
- 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/bin/bundler/{buildCache.d.ts → cacheNpmModules copy.d.ts} +0 -0
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
+
import crypto from "node:crypto";
|
|
4
4
|
const __dirname = fileURLToPath(import.meta.url);
|
|
5
|
+
export function uid(value, length) {
|
|
6
|
+
const hash = crypto.createHash("sha256").update(value).digest("hex");
|
|
7
|
+
return length ? hash.slice(0, length) : hash;
|
|
8
|
+
}
|
|
5
9
|
export const getClientRuntimeFile = () => {
|
|
6
10
|
return path.join(__dirname, "../../../client-runtime.js");
|
|
7
11
|
};
|
|
8
|
-
export const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return documentEntry;
|
|
12
|
+
export const getClientRuntimeFileName = (mode) => {
|
|
13
|
+
if (mode === "development") {
|
|
14
|
+
return "xanix-runtime";
|
|
12
15
|
}
|
|
13
|
-
return
|
|
16
|
+
return uid("xanix-runtime", 32);
|
|
14
17
|
};
|
package/dist/bin/index.js
CHANGED
|
File without changes
|
package/dist/client-runtime.js
CHANGED
|
@@ -41,16 +41,16 @@ export const getPage = async (path) => {
|
|
|
41
41
|
export async function mount(path, Component, doc) {
|
|
42
42
|
const root = getRoot();
|
|
43
43
|
pages.set(path, doc);
|
|
44
|
-
const Document = (await import(
|
|
44
|
+
const Document = (await import("virtual:xanix-document")).default;
|
|
45
45
|
root.render(_jsx(Document, { document: doc, children: _jsx(Component, { ...doc.props }) }));
|
|
46
46
|
}
|
|
47
|
-
if (
|
|
47
|
+
if (__XANIX_CLIENT__) {
|
|
48
48
|
const dispatch = (name, path) => {
|
|
49
|
-
window.dispatchEvent(new CustomEvent(
|
|
49
|
+
window.dispatchEvent(new CustomEvent(name, { detail: { path } }));
|
|
50
50
|
};
|
|
51
51
|
window.addEventListener("load", async () => {
|
|
52
52
|
const path = getPath();
|
|
53
|
-
dispatch(
|
|
53
|
+
dispatch(XANIX_NAVIGATE_START, path);
|
|
54
54
|
const doc = window.XANIX_DOCUMENT;
|
|
55
55
|
const mod = await import(getImportUrl(doc.pageId));
|
|
56
56
|
mount(path, mod.default, doc);
|
|
@@ -58,12 +58,12 @@ if (typeof window !== "undefined") {
|
|
|
58
58
|
if (scriptTag) {
|
|
59
59
|
scriptTag.remove();
|
|
60
60
|
}
|
|
61
|
-
dispatch(
|
|
61
|
+
dispatch(XANIX_NAVIGATE_END, path);
|
|
62
62
|
});
|
|
63
63
|
window.addEventListener("popstate", async () => {
|
|
64
|
-
dispatch(
|
|
64
|
+
dispatch(XANIX_NAVIGATE, getPath());
|
|
65
65
|
});
|
|
66
|
-
window.addEventListener(
|
|
66
|
+
window.addEventListener(XANIX_NAVIGATE, async (event) => {
|
|
67
67
|
const { path, replace } = event.detail;
|
|
68
68
|
const currentPath = getPath();
|
|
69
69
|
if (path === currentPath)
|
|
@@ -71,7 +71,7 @@ if (typeof window !== "undefined") {
|
|
|
71
71
|
const url = new URL(path, window.location.origin);
|
|
72
72
|
const prevUrl = new URL(currentPath, window.location.origin);
|
|
73
73
|
const isSamePath = url.pathname === prevUrl.pathname;
|
|
74
|
-
dispatch(
|
|
74
|
+
dispatch(XANIX_NAVIGATE_START, path);
|
|
75
75
|
let page = await getPage(path);
|
|
76
76
|
if (!page)
|
|
77
77
|
return;
|
|
@@ -79,7 +79,7 @@ if (typeof window !== "undefined") {
|
|
|
79
79
|
const mod = await import(getImportUrl(page.pageId));
|
|
80
80
|
mount(path, mod.default, page);
|
|
81
81
|
}
|
|
82
|
-
dispatch(
|
|
82
|
+
dispatch(XANIX_NAVIGATE_END, path);
|
|
83
83
|
if (replace) {
|
|
84
84
|
history.replaceState(null, "", path);
|
|
85
85
|
}
|
|
@@ -87,27 +87,27 @@ if (typeof window !== "undefined") {
|
|
|
87
87
|
history.pushState(null, "", path);
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
|
-
window.addEventListener(
|
|
90
|
+
window.addEventListener(XANIX_PRELOAD, async (event) => {
|
|
91
91
|
const path = event.detail.path;
|
|
92
92
|
if (!path)
|
|
93
93
|
return;
|
|
94
|
-
dispatch(
|
|
94
|
+
dispatch(XANIX_PRELOAD_START, path);
|
|
95
95
|
const page = await getPage(path);
|
|
96
96
|
if (!page)
|
|
97
97
|
return;
|
|
98
98
|
await import(getImportUrl(page.pageId));
|
|
99
99
|
pages.set(path, page);
|
|
100
|
-
dispatch(
|
|
100
|
+
dispatch(XANIX_PRELOAD_END, path);
|
|
101
101
|
});
|
|
102
|
-
window.addEventListener(
|
|
102
|
+
window.addEventListener(XANIX_NAVIGATE_RELOAD, async (event) => {
|
|
103
103
|
const path = getPath();
|
|
104
|
-
dispatch(
|
|
104
|
+
dispatch(XANIX_NAVIGATE_START, path);
|
|
105
105
|
let page = await getPage(path);
|
|
106
106
|
if (!page)
|
|
107
107
|
return;
|
|
108
108
|
const mod = await import(getImportUrl(page.pageId) + "?t=" + Date.now());
|
|
109
109
|
mount(path, mod.default, page);
|
|
110
110
|
history.pushState(null, "", path);
|
|
111
|
-
dispatch(
|
|
111
|
+
dispatch(XANIX_NAVIGATE_END, path);
|
|
112
112
|
});
|
|
113
113
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import Head from "
|
|
3
|
-
import Body from "./Body.js";
|
|
4
|
-
import Document from "./Document.js";
|
|
2
|
+
import { Head, Body, Document } from "xanix";
|
|
5
3
|
const BaseDocument = ({ document, children }) => {
|
|
6
4
|
return (_jsxs(Document, { document: document, children: [_jsxs(Head, { children: [_jsx("meta", { charSet: "UTF-8" }), _jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1.0" })] }), _jsx(Body, { children: children })] }));
|
|
7
5
|
};
|
package/dist/components/Body.js
CHANGED
|
@@ -4,6 +4,8 @@ const Document = ({ children, document }) => {
|
|
|
4
4
|
if (__XANIX_CLIENT__) {
|
|
5
5
|
return _jsx(DocumentProvider, { value: document, children: children });
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
else {
|
|
8
|
+
return (_jsx(DocumentProvider, { value: document, children: _jsx("html", { children: children }) }));
|
|
9
|
+
}
|
|
8
10
|
};
|
|
9
11
|
export default Document;
|
package/dist/components/Head.js
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
3
|
import useDocument from "../hooks/useDocument.js";
|
|
4
4
|
const Head = ({ children }) => {
|
|
5
5
|
const { title, meta, pageId, props, params, pageData } = useDocument();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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);
|
|
6
|
+
if (__XANIX_CLIENT__) {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
document.title = title || "";
|
|
9
|
+
meta?.forEach(({ name, content }) => {
|
|
10
|
+
let element = document.querySelector(`meta[name="${name}"]`);
|
|
11
|
+
if (!element) {
|
|
12
|
+
element = document.createElement("meta");
|
|
13
|
+
element.setAttribute("name", name);
|
|
14
|
+
document.head.appendChild(element);
|
|
15
|
+
}
|
|
16
|
+
element.setAttribute("content", content);
|
|
24
17
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
18
|
+
// add children
|
|
19
|
+
const head = document.head;
|
|
20
|
+
if (children) {
|
|
21
|
+
const container = document.createElement("div");
|
|
22
|
+
container.innerHTML = children;
|
|
23
|
+
Array.from(container.children).forEach((child) => {
|
|
24
|
+
head.appendChild(child);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}, [children]);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (__XANIX_SERVER__) {
|
|
31
|
+
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: {
|
|
32
|
+
__html: `window.XANIX_DOCUMENT = ${JSON.stringify({
|
|
33
|
+
pageId,
|
|
34
|
+
props,
|
|
35
|
+
meta,
|
|
36
|
+
title,
|
|
37
|
+
params,
|
|
38
|
+
pageData,
|
|
39
|
+
request: null,
|
|
40
|
+
})};
|
|
39
41
|
`,
|
|
40
|
-
|
|
42
|
+
} }), _jsx("script", { type: "module", src: `/.xanix/client/${__XANIX_CLIENT_RUNTIME_FILE_NAME__}.js` })] }));
|
|
43
|
+
}
|
|
41
44
|
};
|
|
42
45
|
export default Head;
|
|
@@ -3,5 +3,5 @@ export type LinkProps = Omit<HTMLProps<HTMLAnchorElement>, "href" | "preload"> &
|
|
|
3
3
|
preload?: boolean;
|
|
4
4
|
href: string;
|
|
5
5
|
};
|
|
6
|
-
declare const Link: ({ children, preload, ...props }: LinkProps) => import("react").JSX.Element;
|
|
6
|
+
declare const Link: ({ children, preload, ...props }: LinkProps) => import("react").JSX.Element | undefined;
|
|
7
7
|
export default Link;
|
package/dist/components/Link.js
CHANGED
|
@@ -3,26 +3,31 @@ import { useEffect, useRef } from "react";
|
|
|
3
3
|
import { navigate } from "../navigate.js";
|
|
4
4
|
const Link = ({ children, preload, ...props }) => {
|
|
5
5
|
const ref = useRef(null);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
ref.current.addEventListener("mouseenter", load);
|
|
12
|
-
}
|
|
13
|
-
return () => {
|
|
6
|
+
if (__XANIX_CLIENT__) {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const load = () => {
|
|
9
|
+
window.dispatchEvent(new CustomEvent("xanix:preload", { detail: { path: props.href } }));
|
|
10
|
+
};
|
|
14
11
|
if (preload && ref.current) {
|
|
15
|
-
ref.current.
|
|
12
|
+
ref.current.addEventListener("mouseenter", load);
|
|
16
13
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
return () => {
|
|
15
|
+
if (preload && ref.current) {
|
|
16
|
+
ref.current.removeEventListener("mouseenter", load);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}, []);
|
|
20
|
+
if (preload) {
|
|
21
|
+
props.onMouseEnter;
|
|
22
|
+
}
|
|
23
|
+
return (_jsx("a", { ref: ref, ...props, onClick: (e) => {
|
|
24
|
+
e.preventDefault();
|
|
25
|
+
e.stopPropagation();
|
|
26
|
+
navigate(props.href);
|
|
27
|
+
}, children: children }));
|
|
28
|
+
}
|
|
29
|
+
if (__XANIX_SERVER__) {
|
|
30
|
+
return _jsx("a", { ...props, children: children });
|
|
21
31
|
}
|
|
22
|
-
return (_jsx("a", { ref: ref, ...props, onClick: (e) => {
|
|
23
|
-
e.preventDefault();
|
|
24
|
-
e.stopPropagation();
|
|
25
|
-
navigate(props.href);
|
|
26
|
-
}, children: children }));
|
|
27
32
|
};
|
|
28
33
|
export default Link;
|
package/dist/dataLoader.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ type PageId = string;
|
|
|
2
2
|
type Callback = (args: Record<string, any>) => Promise<any>;
|
|
3
3
|
type XanixId = string;
|
|
4
4
|
declare const dataLoader: {
|
|
5
|
-
results: (pageId: PageId) => Promise<
|
|
5
|
+
results: (pageId: PageId) => Promise<any>;
|
|
6
6
|
result: (xanixId: XanixId, args?: Record<string, any>) => Promise<any>;
|
|
7
7
|
isInit: (pageId: PageId) => any;
|
|
8
8
|
register: (xanixId: XanixId, callback: Callback) => string;
|
package/dist/dataLoader.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { IS_SERVER } from "./utils.js";
|
|
2
|
+
let global = IS_SERVER ? globalThis : {};
|
|
2
3
|
global.$XANIXDT_INITIALED = new Map();
|
|
3
4
|
global.$XANIXDT = new Map();
|
|
4
5
|
global.$XANIXDT_PAGES = new Map();
|
|
@@ -15,14 +16,19 @@ const registerPage = (pageId, xanixId, args) => {
|
|
|
15
16
|
return xanixId;
|
|
16
17
|
};
|
|
17
18
|
const results = async (pageId) => {
|
|
18
|
-
global.$XANIXDT_INITIALED.
|
|
19
|
+
if (global.$XANIXDT_INITIALED.has(pageId)) {
|
|
20
|
+
return global.$XANIXDT_INITIALED.get(pageId);
|
|
21
|
+
}
|
|
19
22
|
const page = global.$XANIXDT_PAGES.get(pageId) || [];
|
|
20
23
|
const datas = {};
|
|
21
24
|
await Promise.all(page.map(async (xanixId) => {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
const item = global.$XANIXDT.get(xanixId);
|
|
26
|
+
if (!item)
|
|
27
|
+
return;
|
|
28
|
+
const { callback, args } = item;
|
|
29
|
+
datas[xanixId] = await callback(args);
|
|
25
30
|
}));
|
|
31
|
+
global.$XANIXDT_INITIALED.set(pageId, datas);
|
|
26
32
|
return datas;
|
|
27
33
|
};
|
|
28
34
|
const result = async (xanixId, args) => {
|
package/dist/hooks/useData.d.ts
CHANGED
|
@@ -5,14 +5,10 @@ declare const useData: {
|
|
|
5
5
|
loading: boolean;
|
|
6
6
|
reload: () => Promise<void>;
|
|
7
7
|
};
|
|
8
|
-
register(xanixId: string, callback: Callback): (
|
|
8
|
+
register(xanixId: string, callback: Callback): (args?: Record<string, any>) => {
|
|
9
9
|
data: any;
|
|
10
10
|
loading: boolean;
|
|
11
11
|
reload: () => Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
data: any;
|
|
14
|
-
loading: boolean;
|
|
15
|
-
reload: () => Promise<void>;
|
|
16
|
-
});
|
|
12
|
+
};
|
|
17
13
|
};
|
|
18
14
|
export default useData;
|
package/dist/hooks/useData.js
CHANGED
|
@@ -8,7 +8,7 @@ const useData = (_callback, _args) => {
|
|
|
8
8
|
useData.register = (xanixId, callback) => {
|
|
9
9
|
if (typeof __XANIX_SERVER__ !== "undefined" && __XANIX_SERVER__) {
|
|
10
10
|
loader.register(xanixId, callback);
|
|
11
|
-
return
|
|
11
|
+
return (args) => {
|
|
12
12
|
const page = usePage();
|
|
13
13
|
const doc = useDocument();
|
|
14
14
|
loader.registerPage(page.pageId, xanixId, args ?? {});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/// <reference path="./types/globals.d.ts" />
|
|
2
|
+
/// <reference path="./types/express.d.ts" />
|
|
3
|
+
/// <reference path="./types/assets.d.ts" />
|
|
4
|
+
|
|
1
5
|
import Link from "./components/Link.js";
|
|
2
6
|
import Document, { DocumentProps } from "./components/Document.js";
|
|
3
7
|
import Head from "./components/Head.js";
|
|
@@ -13,6 +17,7 @@ import useRequest from "./hooks/useRequest.js";
|
|
|
13
17
|
import useHeaders from "./hooks/useHeaders.js";
|
|
14
18
|
import useCookies from "./hooks/useCookies.js";
|
|
15
19
|
import useData from "./hooks/useData.js";
|
|
20
|
+
export * from "./utils.js";
|
|
16
21
|
import { navigate, back, forward, preload, onNavigateStart, onNavigateEnd, reload } from "./navigate.js";
|
|
17
22
|
export { Link, Document, Head, Body, Script, useDocument, useLocation, useParams, usePathname, useSearchParams, usePage, useRequest, useHeaders, useCookies, useData, navigate, back, forward, preload, onNavigateStart, onNavigateEnd, reload, };
|
|
18
23
|
export type { DocumentProps };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/// <reference path="./types/globals.d.ts" />
|
|
2
|
+
/// <reference path="./types/express.d.ts" />
|
|
3
|
+
/// <reference path="./types/assets.d.ts" />
|
|
1
4
|
import Link from "./components/Link.js";
|
|
2
5
|
import Document from "./components/Document.js";
|
|
3
6
|
import Head from "./components/Head.js";
|
|
@@ -14,6 +17,7 @@ import useRequest from "./hooks/useRequest.js";
|
|
|
14
17
|
import useHeaders from "./hooks/useHeaders.js";
|
|
15
18
|
import useCookies from "./hooks/useCookies.js";
|
|
16
19
|
import useData from "./hooks/useData.js";
|
|
20
|
+
export * from "./utils.js";
|
|
17
21
|
// navigate
|
|
18
22
|
import { navigate, back, forward, preload, onNavigateStart, onNavigateEnd, reload, } from "./navigate.js";
|
|
19
23
|
export { Link, Document, Head, Body, Script,
|
package/dist/navigate.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const navigate = (path, replace = false) => {
|
|
2
|
-
window.dispatchEvent(new CustomEvent(
|
|
2
|
+
window.dispatchEvent(new CustomEvent(XANIX_NAVIGATE, {
|
|
3
3
|
detail: { path, replace },
|
|
4
4
|
}));
|
|
5
5
|
};
|
|
@@ -10,22 +10,25 @@ export const forward = () => {
|
|
|
10
10
|
window.history.forward();
|
|
11
11
|
};
|
|
12
12
|
export const preload = async (path) => {
|
|
13
|
-
window.dispatchEvent(new CustomEvent(
|
|
13
|
+
window.dispatchEvent(new CustomEvent(XANIX_PRELOAD, { detail: { path } }));
|
|
14
14
|
};
|
|
15
15
|
export const reload = (hard = false) => {
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if (__XANIX_CLIENT__) {
|
|
17
|
+
if (hard) {
|
|
18
|
+
window.location.reload();
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
window.dispatchEvent(new CustomEvent(XANIX_NAVIGATE_RELOAD));
|
|
22
|
+
}
|
|
19
23
|
}
|
|
20
|
-
window.dispatchEvent(new CustomEvent("xanix:reload"));
|
|
21
24
|
};
|
|
22
25
|
export const onNavigateStart = (callback) => {
|
|
23
26
|
if (__XANIX_CLIENT__) {
|
|
24
|
-
window.addEventListener(
|
|
27
|
+
window.addEventListener(XANIX_NAVIGATE_START, callback);
|
|
25
28
|
}
|
|
26
29
|
};
|
|
27
30
|
export const onNavigateEnd = (callback) => {
|
|
28
31
|
if (__XANIX_CLIENT__) {
|
|
29
|
-
window.addEventListener(
|
|
32
|
+
window.addEventListener(XANIX_NAVIGATE_END, callback);
|
|
30
33
|
}
|
|
31
34
|
};
|
|
@@ -2,8 +2,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { renderToPipeableStream, renderToString } from "react-dom/server";
|
|
3
3
|
import readManifest from "./readManifest.js";
|
|
4
4
|
import { PassThrough } from "node:stream";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { pathToFileURL } from "node:url";
|
|
7
5
|
import dataLoader from "../../dataLoader.js";
|
|
8
6
|
function renderPage(element) {
|
|
9
7
|
return new Promise((resolve, reject) => {
|
|
@@ -48,8 +46,7 @@ export default async function xanixPage({ pageId, req, res, Component, props, })
|
|
|
48
46
|
res.status(404).send("Page Not Found");
|
|
49
47
|
return;
|
|
50
48
|
}
|
|
51
|
-
const Document = (await import(
|
|
52
|
-
.href)).default;
|
|
49
|
+
const Document = (await import("virtual:xanix-document")).default;
|
|
53
50
|
if (!dataLoader.isInit(pageId)) {
|
|
54
51
|
renderToString(_jsx(Document, { document: {
|
|
55
52
|
pageId,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
declare module "*.png" {
|
|
2
|
+
const src: string;
|
|
3
|
+
export default src;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module "*.jpg" {
|
|
7
|
+
const src: string;
|
|
8
|
+
export default src;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module "*.jpeg" {
|
|
12
|
+
const src: string;
|
|
13
|
+
export default src;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module "*.gif" {
|
|
17
|
+
const src: string;
|
|
18
|
+
export default src;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module "*.webp" {
|
|
22
|
+
const src: string;
|
|
23
|
+
export default src;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare module "*.svg" {
|
|
27
|
+
const src: string;
|
|
28
|
+
export default src;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare module "*.css" {
|
|
32
|
+
const src: string;
|
|
33
|
+
export default src;
|
|
34
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
const __XANIX_CLIENT_RUNTIME_FILE_NAME__: string;
|
|
3
|
+
const __XANIX_CLIENT__: boolean;
|
|
4
|
+
const __XANIX_SERVER__: boolean;
|
|
5
|
+
const __XANIX_DEV__: boolean;
|
|
6
|
+
const __XANIX_PROD__: boolean;
|
|
7
|
+
|
|
8
|
+
// XANIX Data
|
|
9
|
+
const XANIXDT: {
|
|
10
|
+
handlers: Record<string, () => Promise<any>>;
|
|
11
|
+
pages: Record<string, string[]>;
|
|
12
|
+
initialed: Record<string, boolean>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// navigation events
|
|
16
|
+
const XANIX_NAVIGATE: string;
|
|
17
|
+
const XANIX_NAVIGATE_START: string;
|
|
18
|
+
const XANIX_NAVIGATE_END: string;
|
|
19
|
+
const XANIX_PRELOAD: string;
|
|
20
|
+
const XANIX_PRELOAD_START: string;
|
|
21
|
+
const XANIX_PRELOAD_END: string;
|
|
22
|
+
|
|
23
|
+
const XANIX_NAVIGATE_RELOAD: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare module "virtual:xanix-document" {
|
|
2
|
+
import type { ComponentType, ReactNode } from "react";
|
|
3
|
+
import type { Request } from "express";
|
|
4
|
+
|
|
5
|
+
export type XanixDocumentData = {
|
|
6
|
+
pageId: string;
|
|
7
|
+
props: Record<string, any>;
|
|
8
|
+
title: string;
|
|
9
|
+
meta: Array<{
|
|
10
|
+
name: string;
|
|
11
|
+
content: string;
|
|
12
|
+
}>;
|
|
13
|
+
params: Record<string, string>;
|
|
14
|
+
request?: Request;
|
|
15
|
+
pageData: Record<string, any>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type XanixDocumentProps = {
|
|
19
|
+
document: XanixDocumentData;
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const Document: ComponentType<XanixDocumentProps>;
|
|
24
|
+
|
|
25
|
+
export default Document;
|
|
26
|
+
}
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export const IS_SERVER = typeof __XANIX_SERVER__ !== "undefined" && __XANIX_SERVER__;
|
|
2
|
+
export const IS_CLIENT = !IS_SERVER;
|
|
3
|
+
export const IS_DEVELOPMENT = typeof __XANIX_DEV__ !== "undefined" && __XANIX_DEV__;
|
|
4
|
+
export const IS_PRODUCTION = typeof __XANIX_PROD__ !== "undefined" && __XANIX_PROD__;
|