xanix 0.0.0 → 1.0.0
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/BaseDocument.d.ts +3 -0
- package/dist/BaseDocument.js +8 -0
- package/dist/Document.d.ts +7 -0
- package/dist/Document.js +7 -0
- package/dist/bin/bundler/buildCache.d.ts +11 -0
- package/dist/bin/bundler/buildCache.js +129 -0
- package/dist/bin/bundler/buildClient.d.ts +3 -0
- package/dist/bin/bundler/buildClient.js +41 -0
- package/dist/bin/bundler/buildServer.d.ts +7 -0
- package/dist/bin/bundler/buildServer.js +55 -0
- package/dist/bin/bundler/cacheNpmModules.d.ts +11 -0
- package/dist/bin/bundler/cacheNpmModules.js +157 -0
- package/dist/bin/bundler/config/output.d.ts +14 -0
- package/dist/bin/bundler/config/output.js +48 -0
- package/dist/bin/bundler/generateClientEntries.d.ts +3 -0
- package/dist/bin/bundler/generateClientEntries.js +59 -0
- package/dist/bin/bundler/plugins/XanixAssets/index.d.ts +4 -0
- package/dist/bin/bundler/plugins/XanixAssets/index.js +22 -0
- package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.d.ts +6 -0
- package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.js +350 -0
- package/dist/bin/bundler/plugins/XanixEntryFinder/finder.d.ts +11 -0
- package/dist/bin/bundler/plugins/XanixEntryFinder/finder.js +156 -0
- package/dist/bin/bundler/plugins/XanixEntryFinder/index.d.ts +6 -0
- package/dist/bin/bundler/plugins/XanixEntryFinder/index.js +36 -0
- package/dist/bin/bundler/plugins/XanixEnv.d.ts +15 -0
- package/dist/bin/bundler/plugins/XanixEnv.js +46 -0
- package/dist/bin/bundler/plugins/XanixHydrate.d.ts +3 -0
- package/dist/bin/bundler/plugins/XanixHydrate.js +34 -0
- package/dist/bin/bundler/plugins/XanixReactRefresh.d.ts +2 -0
- package/dist/bin/bundler/plugins/XanixReactRefresh.js +126 -0
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.d.ts +5 -0
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.js +22 -0
- package/dist/bin/bundler/plugins/XanixTransform/index.d.ts +5 -0
- package/dist/bin/bundler/plugins/XanixTransform/index.js +19 -0
- package/dist/bin/bundler/plugins/XanixTransform/transformer.d.ts +16 -0
- package/dist/bin/bundler/plugins/XanixTransform/transformer.js +631 -0
- package/dist/bin/bundler/plugins/XanixWatchChange copy.d.ts +10 -0
- package/dist/bin/bundler/plugins/XanixWatchChange copy.js +30 -0
- package/dist/bin/bundler/plugins/XanixWatchChange.d.ts +9 -0
- package/dist/bin/bundler/plugins/XanixWatchChange.js +27 -0
- package/dist/bin/bundler/plugins/XanixWatchChangeClient.d.ts +7 -0
- package/dist/bin/bundler/plugins/XanixWatchChangeClient.js +15 -0
- package/dist/bin/bundler/plugins/commonjs.d.ts +3 -0
- package/dist/bin/bundler/plugins/commonjs.js +10 -0
- package/dist/bin/bundler/plugins/dep-XanixWatchChange.d.ts +9 -0
- package/dist/bin/bundler/plugins/dep-XanixWatchChange.js +27 -0
- package/dist/bin/bundler/plugins/nodeResolve.d.ts +3 -0
- package/dist/bin/bundler/plugins/nodeResolve.js +10 -0
- package/dist/bin/bundler/plugins/pathResolver.d.ts +5 -0
- package/dist/bin/bundler/plugins/pathResolver.js +57 -0
- package/dist/bin/bundler/plugins/plugins.d.ts +8 -0
- package/dist/bin/bundler/plugins/plugins.js +75 -0
- package/dist/bin/bundler/plugins/rollupEsbuild.d.ts +3 -0
- package/dist/bin/bundler/plugins/rollupEsbuild.js +14 -0
- package/dist/bin/bundler/plugins/xanixServerData.d.ts +6 -0
- package/dist/bin/bundler/plugins/xanixServerData.js +224 -0
- package/dist/bin/bundler/plugins/xanixTsconfigAlias.d.ts +6 -0
- package/dist/bin/bundler/plugins/xanixTsconfigAlias.js +51 -0
- package/dist/bin/bundler/plugins/xanixUseDataId.d.ts +4 -0
- package/dist/bin/bundler/plugins/xanixUseDataId.js +93 -0
- package/dist/bin/bundler/watchClient.d.ts +8 -0
- package/dist/bin/bundler/watchClient.js +54 -0
- package/dist/bin/bundler/watchServer.d.ts +10 -0
- package/dist/bin/bundler/watchServer.js +84 -0
- package/dist/bin/cli/build.d.ts +2 -0
- package/dist/bin/cli/build.js +18 -0
- package/dist/bin/cli/dev.d.ts +2 -0
- package/dist/bin/cli/dev.js +103 -0
- package/dist/bin/cli/start.d.ts +2 -0
- package/dist/bin/cli/start.js +19 -0
- package/dist/bin/include/entry.d.ts +3 -0
- package/dist/bin/include/entry.js +28 -0
- package/dist/bin/include/logger.d.ts +10 -0
- package/dist/bin/include/logger.js +11 -0
- package/dist/bin/include/manifest.d.ts +3 -0
- package/dist/bin/include/manifest.js +13 -0
- package/dist/bin/include/utils.d.ts +2 -0
- package/dist/bin/include/utils.js +14 -0
- package/dist/bin/index.d.ts +2 -0
- package/dist/bin/index.js +26 -0
- package/dist/bin/types.d.ts +12 -0
- package/dist/bin/types.js +1 -0
- package/dist/client/components/Body.d.ts +5 -0
- package/dist/client/components/Body.js +10 -0
- package/dist/client/components/Document/context.d.ts +3 -0
- package/dist/client/components/Document/context.js +14 -0
- package/dist/client/components/Document/index.d.ts +8 -0
- package/dist/client/components/Document/index.js +6 -0
- package/dist/client/components/Head copy.d.ts +5 -0
- package/dist/client/components/Head copy.js +8 -0
- package/dist/client/components/Head.d.ts +5 -0
- package/dist/client/components/Head.js +10 -0
- package/dist/client/components/Link.d.ts +6 -0
- package/dist/client/components/Link.js +10 -0
- package/dist/client/context/RouteContext.d.ts +8 -0
- package/dist/client/context/RouteContext.js +16 -0
- package/dist/client/hooks/usePageProps.d.ts +1 -0
- package/dist/client/hooks/usePageProps.js +2 -0
- package/dist/client/hooks/useRoute.d.ts +1 -0
- package/dist/client/hooks/useRoute.js +2 -0
- package/dist/client/hooks/useSearchParams.d.ts +1 -0
- package/dist/client/hooks/useSearchParams.js +2 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2 -0
- package/dist/client/navigation.d.ts +4 -0
- package/dist/client/navigation.js +14 -0
- package/dist/client/refresh.d.ts +7 -0
- package/dist/client/refresh.js +15 -0
- package/dist/client/runtime.d.ts +10 -0
- package/dist/client/runtime.js +98 -0
- package/dist/client-runtime.d.ts +10 -0
- package/dist/client-runtime.js +113 -0
- package/dist/components/BaseDocument.d.ts +3 -0
- package/dist/components/BaseDocument.js +8 -0
- package/dist/components/Body.d.ts +5 -0
- package/dist/components/Body.js +8 -0
- package/dist/components/Document/Document.d.ts +16 -0
- package/dist/components/Document/Document.js +15 -0
- package/dist/components/Document/context.d.ts +17 -0
- package/dist/components/Document/context.js +13 -0
- package/dist/components/Document/index.d.ts +7 -0
- package/dist/components/Document/index.js +10 -0
- package/dist/components/Document.d.ts +7 -0
- package/dist/components/Document.js +9 -0
- package/dist/components/DocumentContext/DocumentContext.d.ts +15 -0
- package/dist/components/DocumentContext/DocumentContext.js +18 -0
- package/dist/components/DocumentContext/context.d.ts +11 -0
- package/dist/components/DocumentContext/context.js +14 -0
- package/dist/components/DocumentContext/index.d.ts +15 -0
- package/dist/components/DocumentContext/index.js +18 -0
- package/dist/components/DocumentContext.d.ts +19 -0
- package/dist/components/DocumentContext.js +6 -0
- package/dist/components/DocumentProvider.d.ts +13 -0
- package/dist/components/DocumentProvider.js +7 -0
- package/dist/components/Head.d.ts +5 -0
- package/dist/components/Head.js +42 -0
- package/dist/components/Link.d.ts +7 -0
- package/dist/components/Link.js +28 -0
- package/dist/components/Script.d.ts +3 -0
- package/dist/components/Script.js +5 -0
- package/dist/dataLoader.d.ts +11 -0
- package/dist/dataLoader.js +46 -0
- package/dist/document/BaseDocument.d.ts +3 -0
- package/dist/document/BaseDocument.js +8 -0
- package/dist/document/Body.d.ts +5 -0
- package/dist/document/Body.js +9 -0
- package/dist/document/Document/Document.d.ts +7 -0
- package/dist/document/Document/Document.js +10 -0
- package/dist/document/Document/context.d.ts +17 -0
- package/dist/document/Document/context.js +13 -0
- package/dist/document/Document/index.d.ts +7 -0
- package/dist/document/Document/index.js +10 -0
- package/dist/document/Document.d.ts +7 -0
- package/dist/document/Document.js +10 -0
- package/dist/document/DocumentContext.d.ts +17 -0
- package/dist/document/DocumentContext.js +6 -0
- package/dist/document/Head.d.ts +5 -0
- package/dist/document/Head.js +40 -0
- package/dist/document/Link.d.ts +7 -0
- package/dist/document/Link.js +28 -0
- package/dist/document/Script.d.ts +3 -0
- package/dist/document/Script.js +5 -0
- package/dist/document/context.d.ts +17 -0
- package/dist/document/context.js +13 -0
- package/dist/document/index.d.ts +8 -0
- package/dist/document/index.js +7 -0
- package/dist/document/useDocument.d.ts +2 -0
- package/dist/document/useDocument.js +10 -0
- package/dist/hooks/useCookies.d.ts +2 -0
- package/dist/hooks/useCookies.js +11 -0
- package/dist/hooks/useData.d.ts +18 -0
- package/dist/hooks/useData.js +69 -0
- package/dist/hooks/useDocument.d.ts +2 -0
- package/dist/hooks/useDocument.js +10 -0
- package/dist/hooks/useHeaders.d.ts +2 -0
- package/dist/hooks/useHeaders.js +9 -0
- package/dist/hooks/useLocation.d.ts +2 -0
- package/dist/hooks/useLocation.js +25 -0
- package/dist/hooks/usePage.d.ts +5 -0
- package/dist/hooks/usePage.js +9 -0
- package/dist/hooks/useParams.d.ts +2 -0
- package/dist/hooks/useParams.js +6 -0
- package/dist/hooks/usePathname.d.ts +2 -0
- package/dist/hooks/usePathname.js +9 -0
- package/dist/hooks/useRequest.d.ts +2 -0
- package/dist/hooks/useRequest.js +8 -0
- package/dist/hooks/useSearchParams.d.ts +12 -0
- package/dist/hooks/useSearchParams.js +66 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +27 -0
- package/dist/loader.d.ts +11 -0
- package/dist/loader.js +16 -0
- package/dist/navigate.d.ts +7 -0
- package/dist/navigate.js +31 -0
- package/dist/navigation/index.d.ts +2 -0
- package/dist/navigation/index.js +2 -0
- package/dist/navigation/navigate.d.ts +7 -0
- package/dist/navigation/navigate.js +31 -0
- package/dist/navigation/useLocation.d.ts +1 -0
- package/dist/navigation/useLocation.js +22 -0
- package/dist/router/index.d.ts +1 -0
- package/dist/router/index.js +1 -0
- package/dist/router/useParams.d.ts +9 -0
- package/dist/router/useParams.js +50 -0
- package/dist/router/useSearchParams .d.ts +9 -0
- package/dist/router/useSearchParams .js +50 -0
- package/dist/router/useSearchParams.d.ts +11 -0
- package/dist/router/useSearchParams.js +80 -0
- package/dist/server/index.d.ts +0 -0
- package/dist/server/index.js +1 -0
- package/dist/server/page.d.ts +9 -0
- package/dist/server/page.js +60 -0
- package/dist/server/readManifest.d.ts +14 -0
- package/dist/server/readManifest.js +8 -0
- package/dist/server/runtime/createServer.d.ts +12 -0
- package/dist/server/runtime/createServer.js +48 -0
- package/dist/server/runtime/index.d.ts +3 -0
- package/dist/server/runtime/index.js +3 -0
- package/dist/server/runtime/readManifest.d.ts +14 -0
- package/dist/server/runtime/readManifest.js +8 -0
- package/dist/server/runtime/xanixPage.d.ts +9 -0
- package/dist/server/runtime/xanixPage.js +87 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +7 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.js +27 -0
- package/dist/xanix.d.ts +3 -0
- package/dist/xanix.js +40 -0
- package/package.json +73 -13
- package/src/xanix-env.d.ts +79 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// refresh/index.ts
|
|
2
|
+
import RefreshRuntime from "react-refresh";
|
|
3
|
+
const runtime = RefreshRuntime;
|
|
4
|
+
// if (typeof window !== "undefined") {
|
|
5
|
+
// RefreshRuntime.injectIntoGlobalHook(window);
|
|
6
|
+
// const win = window as any;
|
|
7
|
+
// win.$RefreshReg$ = () => {};
|
|
8
|
+
// win.$RefreshSig$ = () => (type: any) => type;
|
|
9
|
+
// }
|
|
10
|
+
export function register(component, id) {
|
|
11
|
+
runtime.register(component, id);
|
|
12
|
+
}
|
|
13
|
+
export function performRefresh() {
|
|
14
|
+
runtime.performReactRefresh();
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DocumentContextData } from "../document/DocumentContext";
|
|
2
|
+
import type { ComponentType } from "react";
|
|
3
|
+
type DocumentInfo = DocumentContextData & {
|
|
4
|
+
component: ComponentType<any>;
|
|
5
|
+
};
|
|
6
|
+
export declare const getPath: () => string;
|
|
7
|
+
export declare const getImportUrl: (pageId: string) => string;
|
|
8
|
+
export declare const getPage: (path: string) => Promise<any>;
|
|
9
|
+
export declare function mount(path: string, Component: ComponentType<any>, doc: DocumentInfo): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
const pages = new Map();
|
|
4
|
+
const ROOT_KEY = "__xanix_root__";
|
|
5
|
+
export const getPath = () => {
|
|
6
|
+
const { pathname, search } = window.location;
|
|
7
|
+
return search ? `${pathname}${search}` : pathname;
|
|
8
|
+
};
|
|
9
|
+
export const getImportUrl = (pageId) => `/.xanix/client/${pageId}.js`;
|
|
10
|
+
function getRoot() {
|
|
11
|
+
let ele = document.body;
|
|
12
|
+
if (!ele) {
|
|
13
|
+
throw new Error("Root element not found");
|
|
14
|
+
}
|
|
15
|
+
ele[ROOT_KEY] = ele[ROOT_KEY] ?? createRoot(ele);
|
|
16
|
+
return ele[ROOT_KEY];
|
|
17
|
+
}
|
|
18
|
+
export const getPage = async (path) => {
|
|
19
|
+
let page = pages.get(path);
|
|
20
|
+
if (page)
|
|
21
|
+
return page;
|
|
22
|
+
const response = await fetch(path, {
|
|
23
|
+
headers: {
|
|
24
|
+
"X-Navigation": "true",
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return await response.json();
|
|
31
|
+
};
|
|
32
|
+
export async function mount(path, Component, doc) {
|
|
33
|
+
const root = getRoot();
|
|
34
|
+
pages.set(path, doc);
|
|
35
|
+
const Document = (await import(getImportUrl("xanix-document"))).default;
|
|
36
|
+
root.render(_jsx(Document, { document: doc, children: _jsx(Component, { ...doc.props }) }));
|
|
37
|
+
}
|
|
38
|
+
if (typeof window !== "undefined") {
|
|
39
|
+
const dispatch = (name, path) => {
|
|
40
|
+
window.dispatchEvent(new CustomEvent(`xanix:${name}`, { detail: { path } }));
|
|
41
|
+
};
|
|
42
|
+
window.addEventListener("load", async () => {
|
|
43
|
+
const path = getPath();
|
|
44
|
+
dispatch("navigate:start", path);
|
|
45
|
+
const doc = window.XANIX_DOCUMENT;
|
|
46
|
+
const mod = await import(getImportUrl(doc.pageId));
|
|
47
|
+
mount(path, mod.default, doc);
|
|
48
|
+
const scriptTag = document.getElementById(doc.pageId);
|
|
49
|
+
if (scriptTag) {
|
|
50
|
+
scriptTag.remove();
|
|
51
|
+
}
|
|
52
|
+
dispatch("navigate:end", path);
|
|
53
|
+
});
|
|
54
|
+
window.addEventListener("xanix:navigate", async (event) => {
|
|
55
|
+
const path = event.detail.path;
|
|
56
|
+
const replace = event.detail.replace;
|
|
57
|
+
dispatch("navigate:start", path);
|
|
58
|
+
let page = await getPage(path);
|
|
59
|
+
if (!page)
|
|
60
|
+
return;
|
|
61
|
+
const mod = await import(getImportUrl(page.pageId));
|
|
62
|
+
mount(path, mod.default, page);
|
|
63
|
+
if (replace) {
|
|
64
|
+
history.replaceState(null, "", path);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
history.pushState(null, "", path);
|
|
68
|
+
}
|
|
69
|
+
dispatch("navigate:end", path);
|
|
70
|
+
});
|
|
71
|
+
window.addEventListener("xanix:preload", async (event) => {
|
|
72
|
+
const path = event.detail.path;
|
|
73
|
+
if (!path)
|
|
74
|
+
return;
|
|
75
|
+
dispatch("preload:start", path);
|
|
76
|
+
const page = await getPage(path);
|
|
77
|
+
if (!page)
|
|
78
|
+
return;
|
|
79
|
+
await import(getImportUrl(page.pageId));
|
|
80
|
+
pages.set(path, page);
|
|
81
|
+
dispatch("preload:end", path);
|
|
82
|
+
});
|
|
83
|
+
window.addEventListener("xanix:reload", async (event) => {
|
|
84
|
+
const path = getPath();
|
|
85
|
+
dispatch("navigate:start", path);
|
|
86
|
+
let page = await getPage(path);
|
|
87
|
+
if (!page)
|
|
88
|
+
return;
|
|
89
|
+
const mod = await import(getImportUrl(page.pageId) + "?t=" + Date.now());
|
|
90
|
+
mount(path, mod.default, page);
|
|
91
|
+
history.pushState(null, "", path);
|
|
92
|
+
dispatch("navigate:end", path);
|
|
93
|
+
});
|
|
94
|
+
window.addEventListener("popstate", async () => {
|
|
95
|
+
const path = getPath();
|
|
96
|
+
dispatch("navigate", path);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DocumentContextData } from "./components/DocumentContext.js";
|
|
2
|
+
import type { ComponentType } from "react";
|
|
3
|
+
type DocumentInfo = DocumentContextData & {
|
|
4
|
+
component: ComponentType<any>;
|
|
5
|
+
};
|
|
6
|
+
export declare const getPath: () => string;
|
|
7
|
+
export declare const getImportUrl: (pageId: string) => string;
|
|
8
|
+
export declare const getPage: (path: string) => Promise<any>;
|
|
9
|
+
export declare function mount(path: string, Component: ComponentType<any>, doc: DocumentInfo): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
const pages = new Map();
|
|
4
|
+
const ROOT_KEY = "__xanix_root__";
|
|
5
|
+
export const getPath = () => {
|
|
6
|
+
const { pathname, search } = window.location;
|
|
7
|
+
return search ? `${pathname}${search}` : pathname;
|
|
8
|
+
};
|
|
9
|
+
export const getImportUrl = (pageId) => `/.xanix/client/${pageId}.js`;
|
|
10
|
+
function getRoot() {
|
|
11
|
+
let ele = document.body;
|
|
12
|
+
if (!ele) {
|
|
13
|
+
throw new Error("Root element not found");
|
|
14
|
+
}
|
|
15
|
+
ele[ROOT_KEY] = ele[ROOT_KEY] ?? createRoot(ele);
|
|
16
|
+
return ele[ROOT_KEY];
|
|
17
|
+
}
|
|
18
|
+
export const getPage = async (path) => {
|
|
19
|
+
let page = pages.get(path);
|
|
20
|
+
if (page)
|
|
21
|
+
return page;
|
|
22
|
+
const response = await fetch(path, {
|
|
23
|
+
headers: {
|
|
24
|
+
"X-Navigation": "true",
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
const page = await response.json();
|
|
29
|
+
if (!page)
|
|
30
|
+
return null;
|
|
31
|
+
if (page.pageId && page.props && page.meta && page.params) {
|
|
32
|
+
return page;
|
|
33
|
+
}
|
|
34
|
+
throw new Error("Invalid page structure");
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error("Failed to fetch page:", error);
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
41
|
+
export async function mount(path, Component, doc) {
|
|
42
|
+
const root = getRoot();
|
|
43
|
+
pages.set(path, doc);
|
|
44
|
+
const Document = (await import(getImportUrl("xanix-document"))).default;
|
|
45
|
+
root.render(_jsx(Document, { document: doc, children: _jsx(Component, { ...doc.props }) }));
|
|
46
|
+
}
|
|
47
|
+
if (typeof window !== "undefined") {
|
|
48
|
+
const dispatch = (name, path) => {
|
|
49
|
+
window.dispatchEvent(new CustomEvent(`xanix:${name}`, { detail: { path } }));
|
|
50
|
+
};
|
|
51
|
+
window.addEventListener("load", async () => {
|
|
52
|
+
const path = getPath();
|
|
53
|
+
dispatch("navigate:start", path);
|
|
54
|
+
const doc = window.XANIX_DOCUMENT;
|
|
55
|
+
const mod = await import(getImportUrl(doc.pageId));
|
|
56
|
+
mount(path, mod.default, doc);
|
|
57
|
+
const scriptTag = document.getElementById(doc.pageId);
|
|
58
|
+
if (scriptTag) {
|
|
59
|
+
scriptTag.remove();
|
|
60
|
+
}
|
|
61
|
+
dispatch("navigate:end", path);
|
|
62
|
+
});
|
|
63
|
+
window.addEventListener("popstate", async () => {
|
|
64
|
+
dispatch("navigate", getPath());
|
|
65
|
+
});
|
|
66
|
+
window.addEventListener("xanix:navigate", async (event) => {
|
|
67
|
+
const { path, replace } = event.detail;
|
|
68
|
+
const currentPath = getPath();
|
|
69
|
+
if (path === currentPath)
|
|
70
|
+
return;
|
|
71
|
+
const url = new URL(path, window.location.origin);
|
|
72
|
+
const prevUrl = new URL(currentPath, window.location.origin);
|
|
73
|
+
const isSamePath = url.pathname === prevUrl.pathname;
|
|
74
|
+
dispatch("navigate:start", path);
|
|
75
|
+
let page = await getPage(path);
|
|
76
|
+
if (!page)
|
|
77
|
+
return;
|
|
78
|
+
if (!isSamePath) {
|
|
79
|
+
const mod = await import(getImportUrl(page.pageId));
|
|
80
|
+
mount(path, mod.default, page);
|
|
81
|
+
}
|
|
82
|
+
dispatch("navigate:end", path);
|
|
83
|
+
if (replace) {
|
|
84
|
+
history.replaceState(null, "", path);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
history.pushState(null, "", path);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
window.addEventListener("xanix:preload", async (event) => {
|
|
91
|
+
const path = event.detail.path;
|
|
92
|
+
if (!path)
|
|
93
|
+
return;
|
|
94
|
+
dispatch("preload:start", path);
|
|
95
|
+
const page = await getPage(path);
|
|
96
|
+
if (!page)
|
|
97
|
+
return;
|
|
98
|
+
await import(getImportUrl(page.pageId));
|
|
99
|
+
pages.set(path, page);
|
|
100
|
+
dispatch("preload:end", path);
|
|
101
|
+
});
|
|
102
|
+
window.addEventListener("xanix:reload", async (event) => {
|
|
103
|
+
const path = getPath();
|
|
104
|
+
dispatch("navigate:start", path);
|
|
105
|
+
let page = await getPage(path);
|
|
106
|
+
if (!page)
|
|
107
|
+
return;
|
|
108
|
+
const mod = await import(getImportUrl(page.pageId) + "?t=" + Date.now());
|
|
109
|
+
mount(path, mod.default, page);
|
|
110
|
+
history.pushState(null, "", path);
|
|
111
|
+
dispatch("navigate:end", path);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Head from "./Head.js";
|
|
3
|
+
import Body from "./Body.js";
|
|
4
|
+
import Document from "./Document.js";
|
|
5
|
+
const BaseDocument = ({ document, children }) => {
|
|
6
|
+
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
|
+
};
|
|
8
|
+
export default BaseDocument;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type BodyProps = {
|
|
2
|
+
children?: React.ReactNode;
|
|
3
|
+
};
|
|
4
|
+
declare const Body: ({ children }: BodyProps) => string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;
|
|
5
|
+
export default Body;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type DocumentContextData = {
|
|
2
|
+
pageId?: string;
|
|
3
|
+
props: Record<string, any>;
|
|
4
|
+
title: string;
|
|
5
|
+
meta: Array<{
|
|
6
|
+
name: string;
|
|
7
|
+
content: string;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
export declare const useDocument: () => DocumentContextData | null;
|
|
11
|
+
export type DocumentProps = {
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
document: DocumentContextData;
|
|
14
|
+
};
|
|
15
|
+
declare const Document: ({ children, document }: DocumentProps) => import("react").JSX.Element;
|
|
16
|
+
export default Document;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
const DocumentContext = createContext(null);
|
|
4
|
+
export const useDocument = () => {
|
|
5
|
+
return useContext(DocumentContext);
|
|
6
|
+
};
|
|
7
|
+
const DocumentProvider = DocumentContext.Provider;
|
|
8
|
+
const Document = ({ children, document }) => {
|
|
9
|
+
const isClient = typeof window !== "undefined";
|
|
10
|
+
if (isClient) {
|
|
11
|
+
return _jsx(DocumentProvider, { value: document, children: children });
|
|
12
|
+
}
|
|
13
|
+
return (_jsx(DocumentProvider, { value: document, children: _jsx("html", { children: children }) }));
|
|
14
|
+
};
|
|
15
|
+
export default Document;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type DocumentContextData = {
|
|
2
|
+
pageId: string;
|
|
3
|
+
props: Record<string, any>;
|
|
4
|
+
title: string;
|
|
5
|
+
meta: Array<{
|
|
6
|
+
name: string;
|
|
7
|
+
content: string;
|
|
8
|
+
}>;
|
|
9
|
+
request?: Express.Request;
|
|
10
|
+
};
|
|
11
|
+
export declare const DocumentContext: import("react").Context<DocumentContextData | null>;
|
|
12
|
+
export declare const useDocument: () => DocumentContextData;
|
|
13
|
+
export type DocumentProviderProps = {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
value: DocumentContextData;
|
|
16
|
+
};
|
|
17
|
+
export declare const DocumentProvider: ({ children, value, }: DocumentProviderProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
export const DocumentContext = createContext(null);
|
|
4
|
+
export const useDocument = () => {
|
|
5
|
+
const context = useContext(DocumentContext);
|
|
6
|
+
if (!context) {
|
|
7
|
+
throw new Error("useDocument must be used within a DocumentProvider");
|
|
8
|
+
}
|
|
9
|
+
return context;
|
|
10
|
+
};
|
|
11
|
+
export const DocumentProvider = ({ children, value, }) => {
|
|
12
|
+
return (_jsx(DocumentContext.Provider, { value: value, children: children }));
|
|
13
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DocumentContextData } from "./context.js";
|
|
2
|
+
export type DocumentProps = {
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
document: DocumentContextData;
|
|
5
|
+
};
|
|
6
|
+
declare const Document: ({ children, document }: DocumentProps) => import("react").JSX.Element;
|
|
7
|
+
export default Document;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DocumentProvider } from "./context.js";
|
|
3
|
+
const Document = ({ children, document }) => {
|
|
4
|
+
const isClient = typeof window !== "undefined";
|
|
5
|
+
if (isClient) {
|
|
6
|
+
return _jsx(DocumentProvider, { value: document, children: children });
|
|
7
|
+
}
|
|
8
|
+
return (_jsx(DocumentProvider, { value: document, children: _jsx("html", { children: children }) }));
|
|
9
|
+
};
|
|
10
|
+
export default Document;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DocumentContextData } from "./DocumentContext.js";
|
|
2
|
+
export type DocumentProps = {
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
document: DocumentContextData;
|
|
5
|
+
};
|
|
6
|
+
declare const Document: ({ children, document }: DocumentProps) => import("react").JSX.Element;
|
|
7
|
+
export default Document;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DocumentProvider } from "./DocumentContext.js";
|
|
3
|
+
const Document = ({ children, document }) => {
|
|
4
|
+
if (__XANIX_CLIENT__) {
|
|
5
|
+
return _jsx(DocumentProvider, { value: document, children: children });
|
|
6
|
+
}
|
|
7
|
+
return (_jsx(DocumentProvider, { value: document, children: _jsx("html", { children: children }) }));
|
|
8
|
+
};
|
|
9
|
+
export default Document;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type XanixDocumentData = {
|
|
2
|
+
pageId?: string;
|
|
3
|
+
props: Record<string, any>;
|
|
4
|
+
title: string;
|
|
5
|
+
meta: Array<{
|
|
6
|
+
name: string;
|
|
7
|
+
content: string;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
export declare const DocumentContext: import("react").Context<XanixDocumentData>;
|
|
11
|
+
export declare const useDocument: () => XanixDocumentData;
|
|
12
|
+
export declare const DocumentProvider: ({ children, value, }: {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
value: XanixDocumentData;
|
|
15
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
export const DocumentContext = createContext({
|
|
4
|
+
pageId: "",
|
|
5
|
+
title: "",
|
|
6
|
+
props: {},
|
|
7
|
+
meta: [],
|
|
8
|
+
});
|
|
9
|
+
export const useDocument = () => {
|
|
10
|
+
const context = useContext(DocumentContext);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error("useDocument must be used within a DocumentProvider");
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
};
|
|
16
|
+
export const DocumentProvider = ({ children, value, }) => {
|
|
17
|
+
return (_jsx(DocumentContext.Provider, { value: value, children: children }));
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type XanixDocumentData = {
|
|
2
|
+
pageId?: string;
|
|
3
|
+
props: Record<string, any>;
|
|
4
|
+
title: string;
|
|
5
|
+
meta: Array<{
|
|
6
|
+
name: string;
|
|
7
|
+
content: string;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
export declare const DocumentContext: import("react").Context<XanixDocumentData>;
|
|
11
|
+
export declare const useDocument: () => XanixDocumentData;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
export const DocumentContext = createContext({
|
|
3
|
+
pageId: "",
|
|
4
|
+
title: "",
|
|
5
|
+
props: {},
|
|
6
|
+
meta: [],
|
|
7
|
+
});
|
|
8
|
+
export const useDocument = () => {
|
|
9
|
+
const context = useContext(DocumentContext);
|
|
10
|
+
if (!context) {
|
|
11
|
+
throw new Error("useDocument must be used within a DocumentProvider");
|
|
12
|
+
}
|
|
13
|
+
return context;
|
|
14
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type XanixDocumentData = {
|
|
2
|
+
pageId?: string;
|
|
3
|
+
props: Record<string, any>;
|
|
4
|
+
title: string;
|
|
5
|
+
meta: Array<{
|
|
6
|
+
name: string;
|
|
7
|
+
content: string;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
export declare const DocumentContext: import("react").Context<XanixDocumentData>;
|
|
11
|
+
export declare const useDocument: () => XanixDocumentData;
|
|
12
|
+
export declare const DocumentProvider: ({ children, value, }: {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
value: XanixDocumentData;
|
|
15
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
export const DocumentContext = createContext({
|
|
4
|
+
pageId: "",
|
|
5
|
+
title: "",
|
|
6
|
+
props: {},
|
|
7
|
+
meta: [],
|
|
8
|
+
});
|
|
9
|
+
export const useDocument = () => {
|
|
10
|
+
const context = useContext(DocumentContext);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error("useDocument must be used within a DocumentProvider");
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
};
|
|
16
|
+
export const DocumentProvider = ({ children, value, }) => {
|
|
17
|
+
return (_jsx(DocumentContext.Provider, { value: value, children: children }));
|
|
18
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Request } from "express";
|
|
2
|
+
export type DocumentContextData = {
|
|
3
|
+
pageId: string;
|
|
4
|
+
props: Record<string, any>;
|
|
5
|
+
title: string;
|
|
6
|
+
meta: Array<{
|
|
7
|
+
name: string;
|
|
8
|
+
content: string;
|
|
9
|
+
}>;
|
|
10
|
+
params: Record<string, string>;
|
|
11
|
+
request?: Request;
|
|
12
|
+
pageData: Record<string, any>;
|
|
13
|
+
};
|
|
14
|
+
export declare const DocumentContext: import("react").Context<DocumentContextData | null>;
|
|
15
|
+
export type DocumentProviderProps = {
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
value: DocumentContextData;
|
|
18
|
+
};
|
|
19
|
+
export declare const DocumentProvider: ({ children, value, }: DocumentProviderProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext } from "react";
|
|
3
|
+
export const DocumentContext = createContext(null);
|
|
4
|
+
export const DocumentProvider = ({ children, value, }) => {
|
|
5
|
+
return (_jsx(DocumentContext.Provider, { value: value, children: children }));
|
|
6
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type DocumentContextData = {
|
|
2
|
+
pageId?: string;
|
|
3
|
+
props: Record<string, any>;
|
|
4
|
+
title: string;
|
|
5
|
+
meta: Array<{
|
|
6
|
+
name: string;
|
|
7
|
+
content: string;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
export declare const DocumentContext: import("react").Context<DocumentContextData | null>;
|
|
11
|
+
export declare const useDocument: () => DocumentContextData | null;
|
|
12
|
+
declare const DocumentProvider: import("react").Provider<DocumentContextData | null>;
|
|
13
|
+
export default DocumentProvider;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
export const DocumentContext = createContext(null);
|
|
3
|
+
export const useDocument = () => {
|
|
4
|
+
return useContext(DocumentContext);
|
|
5
|
+
};
|
|
6
|
+
const DocumentProvider = DocumentContext.Provider;
|
|
7
|
+
export default DocumentProvider;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import useDocument from "../hooks/useDocument.js";
|
|
4
|
+
const Head = ({ children }) => {
|
|
5
|
+
const { title, meta, pageId, props, params, pageData } = 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
|
+
pageData,
|
|
37
|
+
request: null,
|
|
38
|
+
})};
|
|
39
|
+
`,
|
|
40
|
+
} }), _jsx("script", { type: "module", src: `/.xanix/client/xanix-runtime.js` })] }));
|
|
41
|
+
};
|
|
42
|
+
export default Head;
|
|
@@ -0,0 +1,7 @@
|
|
|
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;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { navigate } from "../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;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type PageId = string;
|
|
2
|
+
type Callback = (args: Record<string, any>) => Promise<any>;
|
|
3
|
+
type XanixId = string;
|
|
4
|
+
declare const dataLoader: {
|
|
5
|
+
results: (pageId: PageId) => Promise<Record<string, any>>;
|
|
6
|
+
result: (xanixId: XanixId, args?: Record<string, any>) => Promise<any>;
|
|
7
|
+
isInit: (pageId: PageId) => any;
|
|
8
|
+
register: (xanixId: XanixId, callback: Callback) => string;
|
|
9
|
+
registerPage: (pageId: PageId, xanixId: XanixId, args: Record<string, any>) => string;
|
|
10
|
+
};
|
|
11
|
+
export default dataLoader;
|