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,46 @@
|
|
|
1
|
+
let global = typeof window === "undefined" ? globalThis : window;
|
|
2
|
+
global.$XANIXDT_INITIALED = new Map();
|
|
3
|
+
global.$XANIXDT = new Map();
|
|
4
|
+
global.$XANIXDT_PAGES = new Map();
|
|
5
|
+
const register = (xanixId, callback) => {
|
|
6
|
+
global.$XANIXDT.set(xanixId, { args: {}, callback });
|
|
7
|
+
return xanixId;
|
|
8
|
+
};
|
|
9
|
+
const registerPage = (pageId, xanixId, args) => {
|
|
10
|
+
if (!global.$XANIXDT_PAGES.has(pageId)) {
|
|
11
|
+
global.$XANIXDT_PAGES.set(pageId, []);
|
|
12
|
+
}
|
|
13
|
+
global.$XANIXDT_PAGES.get(pageId).push(xanixId);
|
|
14
|
+
global.$XANIXDT.get(xanixId).args = args;
|
|
15
|
+
return xanixId;
|
|
16
|
+
};
|
|
17
|
+
const results = async (pageId) => {
|
|
18
|
+
global.$XANIXDT_INITIALED.set(pageId, true);
|
|
19
|
+
const page = global.$XANIXDT_PAGES.get(pageId) || [];
|
|
20
|
+
const datas = {};
|
|
21
|
+
await Promise.all(page.map(async (xanixId) => {
|
|
22
|
+
const { callback, args } = global.$XANIXDT.get(xanixId);
|
|
23
|
+
const data = await callback(args);
|
|
24
|
+
datas[xanixId] = data;
|
|
25
|
+
}));
|
|
26
|
+
return datas;
|
|
27
|
+
};
|
|
28
|
+
const result = async (xanixId, args) => {
|
|
29
|
+
const item = global.$XANIXDT.get(xanixId);
|
|
30
|
+
if (item) {
|
|
31
|
+
const { callback, args: storedArgs } = item;
|
|
32
|
+
const data = await callback(args ?? storedArgs);
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const isInit = (pageId) => {
|
|
37
|
+
return global.$XANIXDT_INITIALED.get(pageId) ?? false;
|
|
38
|
+
};
|
|
39
|
+
const dataLoader = {
|
|
40
|
+
results,
|
|
41
|
+
result,
|
|
42
|
+
isInit,
|
|
43
|
+
register,
|
|
44
|
+
registerPage,
|
|
45
|
+
};
|
|
46
|
+
export default dataLoader;
|
|
@@ -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,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,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,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DocumentProvider } from "./DocumentContext.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,17 @@
|
|
|
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
|
+
request?: Request;
|
|
11
|
+
};
|
|
12
|
+
export declare const DocumentContext: import("react").Context<DocumentContextData | null>;
|
|
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,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,40 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import useDocument from "./useDocument.js";
|
|
4
|
+
const Head = ({ children }) => {
|
|
5
|
+
const { title, meta, pageId, props } = 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 (typeof window !== "undefined")
|
|
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
|
+
request: null,
|
|
36
|
+
})};
|
|
37
|
+
`,
|
|
38
|
+
} }), _jsx("script", { type: "module", src: "/.xanix/client/xanix-runtime.js" })] }));
|
|
39
|
+
};
|
|
40
|
+
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 "../navigation/navigate.js";
|
|
4
|
+
const Link = ({ children, preload, ...props }) => {
|
|
5
|
+
const ref = useRef(null);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const load = () => {
|
|
8
|
+
window.dispatchEvent(new CustomEvent("xanix:preload", { detail: { path: props.href } }));
|
|
9
|
+
};
|
|
10
|
+
if (preload && ref.current) {
|
|
11
|
+
ref.current.addEventListener("mouseenter", load);
|
|
12
|
+
}
|
|
13
|
+
return () => {
|
|
14
|
+
if (preload && ref.current) {
|
|
15
|
+
ref.current.removeEventListener("mouseenter", load);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}, []);
|
|
19
|
+
if (preload) {
|
|
20
|
+
props.onMouseEnter;
|
|
21
|
+
}
|
|
22
|
+
return (_jsx("a", { ref: ref, ...props, onClick: (e) => {
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
e.stopPropagation();
|
|
25
|
+
navigate(props.href);
|
|
26
|
+
}, children: children }));
|
|
27
|
+
};
|
|
28
|
+
export default Link;
|
|
@@ -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,8 @@
|
|
|
1
|
+
import Document, { DocumentProps } from "./Document.js";
|
|
2
|
+
import useDocument from "./useDocument.js";
|
|
3
|
+
import Head from "./Head.js";
|
|
4
|
+
import Body from "./Body.js";
|
|
5
|
+
import Link from "./Link.js";
|
|
6
|
+
import Script from "./Script.js";
|
|
7
|
+
export { Document, Head, Body, Link, Script, useDocument };
|
|
8
|
+
export type { DocumentProps };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Document from "./Document.js";
|
|
2
|
+
import useDocument from "./useDocument.js";
|
|
3
|
+
import Head from "./Head.js";
|
|
4
|
+
import Body from "./Body.js";
|
|
5
|
+
import Link from "./Link.js";
|
|
6
|
+
import Script from "./Script.js";
|
|
7
|
+
export { Document, Head, Body, Link, Script, useDocument };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DocumentContext } from "./DocumentContext";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
const useDocument = () => {
|
|
4
|
+
const context = useContext(DocumentContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error("useDocument must be used within a DocumentProvider");
|
|
7
|
+
}
|
|
8
|
+
return context;
|
|
9
|
+
};
|
|
10
|
+
export default useDocument;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import useHeaders from "./useHeaders.js";
|
|
2
|
+
const useCookies = () => {
|
|
3
|
+
const headers = useHeaders();
|
|
4
|
+
let cookies = __XANIX_SERVER__ ? headers?.cookie : document.cookie;
|
|
5
|
+
return cookies?.split(";").reduce((cookies, cookie) => {
|
|
6
|
+
const [name, value] = cookie.split("=");
|
|
7
|
+
cookies[name.trim()] = value;
|
|
8
|
+
return cookies;
|
|
9
|
+
}, {});
|
|
10
|
+
};
|
|
11
|
+
export default useCookies;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type Callback = (args: Record<string, any>) => Promise<any>;
|
|
2
|
+
declare const useData: {
|
|
3
|
+
(_callback: Callback, _args?: Record<string, any>): {
|
|
4
|
+
data: any;
|
|
5
|
+
loading: boolean;
|
|
6
|
+
reload: () => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
register(xanixId: string, callback: Callback): ((args?: Record<string, any>) => Promise<{
|
|
9
|
+
data: any;
|
|
10
|
+
loading: boolean;
|
|
11
|
+
reload: () => Promise<void>;
|
|
12
|
+
}>) | ((args?: Record<string, any>) => {
|
|
13
|
+
data: any;
|
|
14
|
+
loading: boolean;
|
|
15
|
+
reload: () => Promise<void>;
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export default useData;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import usePage from "./usePage.js";
|
|
2
|
+
import React, { useEffect, useRef } from "react";
|
|
3
|
+
import useDocument from "./useDocument.js";
|
|
4
|
+
import loader from "../dataLoader.js";
|
|
5
|
+
const useData = (_callback, _args) => {
|
|
6
|
+
return {};
|
|
7
|
+
};
|
|
8
|
+
useData.register = (xanixId, callback) => {
|
|
9
|
+
if (__XANIX_SERVER__) {
|
|
10
|
+
loader.register(xanixId, callback);
|
|
11
|
+
}
|
|
12
|
+
if (__XANIX_SERVER__) {
|
|
13
|
+
return async (args) => {
|
|
14
|
+
const page = usePage();
|
|
15
|
+
const doc = useDocument();
|
|
16
|
+
loader.registerPage(page.pageId, xanixId, args ?? {});
|
|
17
|
+
const pageData = doc.pageData || {};
|
|
18
|
+
const itemData = pageData[xanixId];
|
|
19
|
+
return {
|
|
20
|
+
data: itemData,
|
|
21
|
+
loading: false,
|
|
22
|
+
reload: async () => { },
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return (args) => {
|
|
28
|
+
const doc = useDocument();
|
|
29
|
+
const pageData = doc.pageData || {};
|
|
30
|
+
const itemData = pageData[xanixId];
|
|
31
|
+
const [loading, setLoading] = React.useState(!itemData);
|
|
32
|
+
const [data, setData] = React.useState(itemData);
|
|
33
|
+
const init = useRef(false);
|
|
34
|
+
const reload = async () => {
|
|
35
|
+
setLoading(true);
|
|
36
|
+
const res = await fetch(`/.xanix/__data__/${xanixId}`, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers: {
|
|
39
|
+
"Content-Type": "application/json",
|
|
40
|
+
},
|
|
41
|
+
body: JSON.stringify(args ?? {}),
|
|
42
|
+
});
|
|
43
|
+
try {
|
|
44
|
+
const result = await res.json();
|
|
45
|
+
setData(result.data);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error(error);
|
|
49
|
+
}
|
|
50
|
+
setLoading(false);
|
|
51
|
+
};
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (init.current) {
|
|
54
|
+
reload();
|
|
55
|
+
}
|
|
56
|
+
else if (!itemData) {
|
|
57
|
+
reload();
|
|
58
|
+
}
|
|
59
|
+
init.current = true;
|
|
60
|
+
}, [JSON.stringify(args)]);
|
|
61
|
+
return {
|
|
62
|
+
data,
|
|
63
|
+
loading,
|
|
64
|
+
reload,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
export default useData;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DocumentContext } from "../components/DocumentContext.js";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
const useDocument = () => {
|
|
4
|
+
const context = useContext(DocumentContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error("useDocument must be used within a DocumentProvider");
|
|
7
|
+
}
|
|
8
|
+
return context;
|
|
9
|
+
};
|
|
10
|
+
export default useDocument;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import useRequest from "./useRequest.js";
|
|
3
|
+
const useLocation = () => {
|
|
4
|
+
const req = useRequest();
|
|
5
|
+
let _url = __XANIX_SERVER__
|
|
6
|
+
? new URL(req.originalUrl, `${req.protocol}://${req.get("host")}`)
|
|
7
|
+
: new URL(window.location.href);
|
|
8
|
+
const [url, setUrl] = useState(_url);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const onNavigate = (e) => {
|
|
11
|
+
const path = e.detail.path;
|
|
12
|
+
const url = new URL(path, window.location.origin);
|
|
13
|
+
const newUrl = new URL(window.location.href);
|
|
14
|
+
if (url.href === newUrl.href)
|
|
15
|
+
return;
|
|
16
|
+
setUrl(newUrl);
|
|
17
|
+
};
|
|
18
|
+
window.addEventListener("xanix:navigate:end", onNavigate);
|
|
19
|
+
return () => {
|
|
20
|
+
window.removeEventListener("xanix:navigate:end", onNavigate);
|
|
21
|
+
};
|
|
22
|
+
}, []);
|
|
23
|
+
return url;
|
|
24
|
+
};
|
|
25
|
+
export default useLocation;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const useSearchParams: () => {
|
|
2
|
+
get: (key: string) => string | null;
|
|
3
|
+
getAll: () => any;
|
|
4
|
+
has: (key: string) => boolean;
|
|
5
|
+
set: (key: string, value: string | undefined) => 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
|
+
};
|
|
12
|
+
export default useSearchParams;
|