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,66 @@
|
|
|
1
|
+
import { navigate } from "../navigate.js";
|
|
2
|
+
import useDocument from "./useDocument.js";
|
|
3
|
+
const getParams = (req) => {
|
|
4
|
+
return new URLSearchParams(__XANIX_SERVER__ ? req.url.split("?")[1] || "" : window.location.search);
|
|
5
|
+
};
|
|
6
|
+
const buildUrl = (params) => {
|
|
7
|
+
const search = params.toString();
|
|
8
|
+
return (window.location.pathname +
|
|
9
|
+
(search ? `?${search}` : "") +
|
|
10
|
+
window.location.hash);
|
|
11
|
+
};
|
|
12
|
+
const useSearchParams = () => {
|
|
13
|
+
const { request } = useDocument();
|
|
14
|
+
const update = (newParams) => {
|
|
15
|
+
navigate(buildUrl(newParams));
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
get: (key) => getParams(request).get(key),
|
|
19
|
+
getAll: () => {
|
|
20
|
+
const p = {};
|
|
21
|
+
for (const [key, value] of getParams(request).entries()) {
|
|
22
|
+
if (!p[key]) {
|
|
23
|
+
p[key] = [];
|
|
24
|
+
}
|
|
25
|
+
p[key].push(value);
|
|
26
|
+
}
|
|
27
|
+
return p;
|
|
28
|
+
},
|
|
29
|
+
has: (key) => getParams(request).has(key),
|
|
30
|
+
set: (key, value) => {
|
|
31
|
+
const newParams = new URLSearchParams(getParams(request));
|
|
32
|
+
if (!value) {
|
|
33
|
+
newParams.delete(key);
|
|
34
|
+
update(newParams);
|
|
35
|
+
}
|
|
36
|
+
else if (!newParams.has(key)) {
|
|
37
|
+
newParams.set(key, value);
|
|
38
|
+
update(newParams);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
sets: (entries) => {
|
|
42
|
+
const newParams = new URLSearchParams(getParams(request));
|
|
43
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
44
|
+
newParams.set(key, value);
|
|
45
|
+
}
|
|
46
|
+
update(newParams);
|
|
47
|
+
},
|
|
48
|
+
delete: (key) => {
|
|
49
|
+
const newParams = new URLSearchParams(getParams(request));
|
|
50
|
+
newParams.delete(key);
|
|
51
|
+
update(newParams);
|
|
52
|
+
},
|
|
53
|
+
deletes: (keys) => {
|
|
54
|
+
const newParams = new URLSearchParams(getParams(request));
|
|
55
|
+
for (const key of keys) {
|
|
56
|
+
newParams.delete(key);
|
|
57
|
+
}
|
|
58
|
+
update(newParams);
|
|
59
|
+
},
|
|
60
|
+
clear: () => {
|
|
61
|
+
update(new URLSearchParams());
|
|
62
|
+
},
|
|
63
|
+
toString: () => getParams(request).toString(),
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export default useSearchParams;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Link from "./components/Link.js";
|
|
2
|
+
import Document, { DocumentProps } from "./components/Document.js";
|
|
3
|
+
import Head from "./components/Head.js";
|
|
4
|
+
import Body from "./components/Body.js";
|
|
5
|
+
import Script from "./components/Script.js";
|
|
6
|
+
import useDocument from "./hooks/useDocument.js";
|
|
7
|
+
import useLocation from "./hooks/useLocation.js";
|
|
8
|
+
import useParams from "./hooks/useParams.js";
|
|
9
|
+
import usePathname from "./hooks/usePathname.js";
|
|
10
|
+
import useSearchParams from "./hooks/useSearchParams.js";
|
|
11
|
+
import usePage from "./hooks/usePage.js";
|
|
12
|
+
import useRequest from "./hooks/useRequest.js";
|
|
13
|
+
import useHeaders from "./hooks/useHeaders.js";
|
|
14
|
+
import useCookies from "./hooks/useCookies.js";
|
|
15
|
+
import useData from "./hooks/useData.js";
|
|
16
|
+
import { navigate, back, forward, preload, onNavigateStart, onNavigateEnd, reload } from "./navigate.js";
|
|
17
|
+
export declare const isClient: boolean;
|
|
18
|
+
export declare const isServer: boolean;
|
|
19
|
+
export declare const isDevelopment: boolean;
|
|
20
|
+
export declare const isProduction: boolean;
|
|
21
|
+
export { Link, Document, Head, Body, Script, useDocument, useLocation, useParams, usePathname, useSearchParams, usePage, useRequest, useHeaders, useCookies, useData, navigate, back, forward, preload, onNavigateStart, onNavigateEnd, reload, };
|
|
22
|
+
export type * from "./types";
|
|
23
|
+
export type { DocumentProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Link from "./components/Link.js";
|
|
2
|
+
import Document from "./components/Document.js";
|
|
3
|
+
import Head from "./components/Head.js";
|
|
4
|
+
import Body from "./components/Body.js";
|
|
5
|
+
import Script from "./components/Script.js";
|
|
6
|
+
// hooks
|
|
7
|
+
import useDocument from "./hooks/useDocument.js";
|
|
8
|
+
import useLocation from "./hooks/useLocation.js";
|
|
9
|
+
import useParams from "./hooks/useParams.js";
|
|
10
|
+
import usePathname from "./hooks/usePathname.js";
|
|
11
|
+
import useSearchParams from "./hooks/useSearchParams.js";
|
|
12
|
+
import usePage from "./hooks/usePage.js";
|
|
13
|
+
import useRequest from "./hooks/useRequest.js";
|
|
14
|
+
import useHeaders from "./hooks/useHeaders.js";
|
|
15
|
+
import useCookies from "./hooks/useCookies.js";
|
|
16
|
+
import useData from "./hooks/useData.js";
|
|
17
|
+
// navigate
|
|
18
|
+
import { navigate, back, forward, preload, onNavigateStart, onNavigateEnd, reload, } from "./navigate.js";
|
|
19
|
+
export const isClient = __XANIX_CLIENT__;
|
|
20
|
+
export const isServer = __XANIX_SERVER__;
|
|
21
|
+
export const isDevelopment = __XANIX_DEV__;
|
|
22
|
+
export const isProduction = __XANIX_PROD__;
|
|
23
|
+
export { Link, Document, Head, Body, Script,
|
|
24
|
+
// hooks
|
|
25
|
+
useDocument, useLocation, useParams, usePathname, useSearchParams, usePage, useRequest, useHeaders, useCookies, useData,
|
|
26
|
+
// navigate
|
|
27
|
+
navigate, back, forward, preload, onNavigateStart, onNavigateEnd, reload, };
|
package/dist/loader.d.ts
ADDED
package/dist/loader.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
let global = __XANIX_SERVER__ ? globalThis : window;
|
|
2
|
+
global.$XANIX_PAGE_LOADERS$ = new Map();
|
|
3
|
+
const _ = global.$XANIX_PAGE_LOADERS$;
|
|
4
|
+
const get = (pageId) => {
|
|
5
|
+
if (!_.has(pageId)) {
|
|
6
|
+
_.set(pageId, new Map());
|
|
7
|
+
}
|
|
8
|
+
return _.get(pageId);
|
|
9
|
+
};
|
|
10
|
+
const set = (pageId, entry) => {
|
|
11
|
+
const loader = get(pageId);
|
|
12
|
+
const uid = entry.callback.toString();
|
|
13
|
+
loader.set(uid, entry);
|
|
14
|
+
};
|
|
15
|
+
const loader = { get, set };
|
|
16
|
+
export default loader;
|
|
@@ -0,0 +1,7 @@
|
|
|
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;
|
package/dist/navigate.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
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;
|
|
@@ -0,0 +1,31 @@
|
|
|
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 (typeof window === "undefined")
|
|
24
|
+
return;
|
|
25
|
+
window.addEventListener("xanix:navigate:start", callback);
|
|
26
|
+
};
|
|
27
|
+
export const onNavigateEnd = (callback) => {
|
|
28
|
+
if (typeof window === "undefined")
|
|
29
|
+
return;
|
|
30
|
+
window.addEventListener("xanix:navigate:end", callback);
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useLocation: () => URL;
|
|
@@ -0,0 +1,22 @@
|
|
|
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 (req) {
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useSearchParams.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useSearchParams.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const useParams: () => {
|
|
2
|
+
get: (key: string) => string | null;
|
|
3
|
+
set: (key: string, value: string) => void;
|
|
4
|
+
sets: (entries: Record<string, string>) => void;
|
|
5
|
+
delete: (key: string) => void;
|
|
6
|
+
deletes: (keys: string[]) => void;
|
|
7
|
+
clear: () => void;
|
|
8
|
+
has: (key: string) => boolean;
|
|
9
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { navigate } from "../navigation/navigate.js";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
const getParams = () => {
|
|
4
|
+
return new URLSearchParams(window.location.search);
|
|
5
|
+
};
|
|
6
|
+
export const useParams = () => {
|
|
7
|
+
const [params, setParams] = useState(getParams());
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const onNavigate = () => setParams(getParams());
|
|
10
|
+
window.addEventListener("xanix:navigate:end", onNavigate);
|
|
11
|
+
return () => {
|
|
12
|
+
window.removeEventListener("xanix:navigate:end", onNavigate);
|
|
13
|
+
};
|
|
14
|
+
}, []);
|
|
15
|
+
return {
|
|
16
|
+
get: (key) => params.get(key),
|
|
17
|
+
set: (key, value) => {
|
|
18
|
+
const newParams = new URLSearchParams(params.toString());
|
|
19
|
+
newParams.set(key, value);
|
|
20
|
+
navigate(window.location.pathname + "?" + newParams.toString());
|
|
21
|
+
},
|
|
22
|
+
sets: (entries) => {
|
|
23
|
+
const newParams = new URLSearchParams(params.toString());
|
|
24
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
25
|
+
newParams.set(key, value);
|
|
26
|
+
}
|
|
27
|
+
navigate(window.location.pathname + "?" + newParams.toString());
|
|
28
|
+
},
|
|
29
|
+
delete: (key) => {
|
|
30
|
+
const newParams = new URLSearchParams(params.toString());
|
|
31
|
+
newParams.delete(key);
|
|
32
|
+
setParams(newParams);
|
|
33
|
+
navigate(window.location.pathname + "?" + newParams.toString());
|
|
34
|
+
},
|
|
35
|
+
deletes: (keys) => {
|
|
36
|
+
const newParams = new URLSearchParams(params.toString());
|
|
37
|
+
for (const key of keys) {
|
|
38
|
+
newParams.delete(key);
|
|
39
|
+
}
|
|
40
|
+
setParams(newParams);
|
|
41
|
+
navigate(window.location.pathname + "?" + newParams.toString());
|
|
42
|
+
},
|
|
43
|
+
clear: () => {
|
|
44
|
+
const newParams = new URLSearchParams();
|
|
45
|
+
setParams(newParams);
|
|
46
|
+
navigate(window.location.pathname + "?" + newParams.toString());
|
|
47
|
+
},
|
|
48
|
+
has: (key) => params.has(key),
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const useParams: () => {
|
|
2
|
+
get: (key: string) => string | null;
|
|
3
|
+
set: (key: string, value: string) => void;
|
|
4
|
+
sets: (entries: Record<string, string>) => void;
|
|
5
|
+
delete: (key: string) => void;
|
|
6
|
+
deletes: (keys: string[]) => void;
|
|
7
|
+
clear: () => void;
|
|
8
|
+
has: (key: string) => boolean;
|
|
9
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { navigate } from "../navigation/navigate.js";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
const getParams = () => {
|
|
4
|
+
return new URLSearchParams(window.location.search);
|
|
5
|
+
};
|
|
6
|
+
export const useParams = () => {
|
|
7
|
+
const [params, setParams] = useState(getParams());
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const onNavigate = () => setParams(getParams());
|
|
10
|
+
window.addEventListener("xanix:navigate:end", onNavigate);
|
|
11
|
+
return () => {
|
|
12
|
+
window.removeEventListener("xanix:navigate:end", onNavigate);
|
|
13
|
+
};
|
|
14
|
+
}, []);
|
|
15
|
+
return {
|
|
16
|
+
get: (key) => params.get(key),
|
|
17
|
+
set: (key, value) => {
|
|
18
|
+
const newParams = new URLSearchParams(params.toString());
|
|
19
|
+
newParams.set(key, value);
|
|
20
|
+
navigate(window.location.pathname + "?" + newParams.toString());
|
|
21
|
+
},
|
|
22
|
+
sets: (entries) => {
|
|
23
|
+
const newParams = new URLSearchParams(params.toString());
|
|
24
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
25
|
+
newParams.set(key, value);
|
|
26
|
+
}
|
|
27
|
+
navigate(window.location.pathname + "?" + newParams.toString());
|
|
28
|
+
},
|
|
29
|
+
delete: (key) => {
|
|
30
|
+
const newParams = new URLSearchParams(params.toString());
|
|
31
|
+
newParams.delete(key);
|
|
32
|
+
setParams(newParams);
|
|
33
|
+
navigate(window.location.pathname + "?" + newParams.toString());
|
|
34
|
+
},
|
|
35
|
+
deletes: (keys) => {
|
|
36
|
+
const newParams = new URLSearchParams(params.toString());
|
|
37
|
+
for (const key of keys) {
|
|
38
|
+
newParams.delete(key);
|
|
39
|
+
}
|
|
40
|
+
setParams(newParams);
|
|
41
|
+
navigate(window.location.pathname + "?" + newParams.toString());
|
|
42
|
+
},
|
|
43
|
+
clear: () => {
|
|
44
|
+
const newParams = new URLSearchParams();
|
|
45
|
+
setParams(newParams);
|
|
46
|
+
navigate(window.location.pathname + "?" + newParams.toString());
|
|
47
|
+
},
|
|
48
|
+
has: (key) => params.has(key),
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { navigate } from "../navigation/navigate.js";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import useDocument from "../document/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;
|
|
16
|
+
if (request) {
|
|
17
|
+
_params = new URLSearchParams(request.url.split("?")[1] || "");
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
_params = getParams();
|
|
21
|
+
}
|
|
22
|
+
const [params, setParams] = useState(_params);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const onNavigate = () => {
|
|
25
|
+
setParams(getParams());
|
|
26
|
+
};
|
|
27
|
+
window.addEventListener("xanix:navigate:end", onNavigate);
|
|
28
|
+
window.addEventListener("popstate", onNavigate);
|
|
29
|
+
return () => {
|
|
30
|
+
window.removeEventListener("xanix:navigate:end", onNavigate);
|
|
31
|
+
window.removeEventListener("popstate", onNavigate);
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
const update = (newParams) => {
|
|
35
|
+
setParams(newParams);
|
|
36
|
+
navigate(buildUrl(newParams));
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
get: (key) => params.get(key),
|
|
40
|
+
getAll: () => {
|
|
41
|
+
const p = {};
|
|
42
|
+
for (const [key, value] of params.entries()) {
|
|
43
|
+
if (!p[key]) {
|
|
44
|
+
p[key] = [];
|
|
45
|
+
}
|
|
46
|
+
p[key].push(value);
|
|
47
|
+
}
|
|
48
|
+
return p;
|
|
49
|
+
},
|
|
50
|
+
has: (key) => params.has(key),
|
|
51
|
+
set: (key, value) => {
|
|
52
|
+
const newParams = new URLSearchParams(params);
|
|
53
|
+
newParams.set(key, value);
|
|
54
|
+
update(newParams);
|
|
55
|
+
},
|
|
56
|
+
sets: (entries) => {
|
|
57
|
+
const newParams = new URLSearchParams(params);
|
|
58
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
59
|
+
newParams.set(key, value);
|
|
60
|
+
}
|
|
61
|
+
update(newParams);
|
|
62
|
+
},
|
|
63
|
+
delete: (key) => {
|
|
64
|
+
const newParams = new URLSearchParams(params);
|
|
65
|
+
newParams.delete(key);
|
|
66
|
+
update(newParams);
|
|
67
|
+
},
|
|
68
|
+
deletes: (keys) => {
|
|
69
|
+
const newParams = new URLSearchParams(params);
|
|
70
|
+
for (const key of keys) {
|
|
71
|
+
newParams.delete(key);
|
|
72
|
+
}
|
|
73
|
+
update(newParams);
|
|
74
|
+
},
|
|
75
|
+
clear: () => {
|
|
76
|
+
update(new URLSearchParams());
|
|
77
|
+
},
|
|
78
|
+
toString: () => params.toString(),
|
|
79
|
+
};
|
|
80
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,9 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
request: null,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const Document = (await import(pathToFileURL(path.join(process.cwd(), ".xanix", "xanix-document.js"))
|
|
51
|
+
.href)).default;
|
|
52
|
+
const html = await renderPage(_jsx(Document, { document: {
|
|
53
|
+
pageId,
|
|
54
|
+
props,
|
|
55
|
+
title: title ?? entry.name.replaceAll("-", " "),
|
|
56
|
+
meta,
|
|
57
|
+
request: req,
|
|
58
|
+
}, children: _jsx(Component, { ...props }) }));
|
|
59
|
+
return `<!DOCTYPE html>${html}`;
|
|
60
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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;
|
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
declare function createXanixServer({ mode }: Options): express.Express;
|
|
12
|
+
export default createXanixServer;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import dataLoader from "../../dataLoader.js";
|
|
3
|
+
function createXanixServer({ mode }) {
|
|
4
|
+
const app = express();
|
|
5
|
+
if (mode === "watch") {
|
|
6
|
+
app.use("/.xanix/client", express.static(".xanix/client"));
|
|
7
|
+
app.use("/assets", express.static(".xanix/assets"));
|
|
8
|
+
app.use("/.xanix/cache", express.static(".xanix/cache"));
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
app.use("/.xanix/client", express.static(".xanix/client", {
|
|
12
|
+
maxAge: "1y",
|
|
13
|
+
immutable: true,
|
|
14
|
+
etag: true,
|
|
15
|
+
}));
|
|
16
|
+
app.use("/assets", express.static(".xanix/assets", {
|
|
17
|
+
maxAge: "1y",
|
|
18
|
+
immutable: true,
|
|
19
|
+
etag: true,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
app.post("/.xanix/__data__/:xanixId", express.json(), async (req, res) => {
|
|
23
|
+
const { xanixId } = req.params;
|
|
24
|
+
const args = req.body;
|
|
25
|
+
const data = await dataLoader.result(xanixId, args);
|
|
26
|
+
res.json({ data });
|
|
27
|
+
});
|
|
28
|
+
app.use((req, res, next) => {
|
|
29
|
+
let data = {
|
|
30
|
+
title: null,
|
|
31
|
+
meta: [],
|
|
32
|
+
};
|
|
33
|
+
if (!req.page) {
|
|
34
|
+
req.page = {
|
|
35
|
+
setTitle(title) {
|
|
36
|
+
data.title = title;
|
|
37
|
+
},
|
|
38
|
+
setMeta(name, content) {
|
|
39
|
+
data.meta.push({ name, content });
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
req.XanixPageData = data;
|
|
43
|
+
}
|
|
44
|
+
next();
|
|
45
|
+
});
|
|
46
|
+
return app;
|
|
47
|
+
}
|
|
48
|
+
export default createXanixServer;
|