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.
Files changed (230) hide show
  1. package/dist/BaseDocument.d.ts +3 -0
  2. package/dist/BaseDocument.js +8 -0
  3. package/dist/Document.d.ts +7 -0
  4. package/dist/Document.js +7 -0
  5. package/dist/bin/bundler/buildCache.d.ts +11 -0
  6. package/dist/bin/bundler/buildCache.js +129 -0
  7. package/dist/bin/bundler/buildClient.d.ts +3 -0
  8. package/dist/bin/bundler/buildClient.js +41 -0
  9. package/dist/bin/bundler/buildServer.d.ts +7 -0
  10. package/dist/bin/bundler/buildServer.js +55 -0
  11. package/dist/bin/bundler/cacheNpmModules.d.ts +11 -0
  12. package/dist/bin/bundler/cacheNpmModules.js +157 -0
  13. package/dist/bin/bundler/config/output.d.ts +14 -0
  14. package/dist/bin/bundler/config/output.js +48 -0
  15. package/dist/bin/bundler/generateClientEntries.d.ts +3 -0
  16. package/dist/bin/bundler/generateClientEntries.js +59 -0
  17. package/dist/bin/bundler/plugins/XanixAssets/index.d.ts +4 -0
  18. package/dist/bin/bundler/plugins/XanixAssets/index.js +22 -0
  19. package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.d.ts +6 -0
  20. package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.js +350 -0
  21. package/dist/bin/bundler/plugins/XanixEntryFinder/finder.d.ts +11 -0
  22. package/dist/bin/bundler/plugins/XanixEntryFinder/finder.js +156 -0
  23. package/dist/bin/bundler/plugins/XanixEntryFinder/index.d.ts +6 -0
  24. package/dist/bin/bundler/plugins/XanixEntryFinder/index.js +36 -0
  25. package/dist/bin/bundler/plugins/XanixEnv.d.ts +15 -0
  26. package/dist/bin/bundler/plugins/XanixEnv.js +46 -0
  27. package/dist/bin/bundler/plugins/XanixHydrate.d.ts +3 -0
  28. package/dist/bin/bundler/plugins/XanixHydrate.js +34 -0
  29. package/dist/bin/bundler/plugins/XanixReactRefresh.d.ts +2 -0
  30. package/dist/bin/bundler/plugins/XanixReactRefresh.js +126 -0
  31. package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.d.ts +5 -0
  32. package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.js +22 -0
  33. package/dist/bin/bundler/plugins/XanixTransform/index.d.ts +5 -0
  34. package/dist/bin/bundler/plugins/XanixTransform/index.js +19 -0
  35. package/dist/bin/bundler/plugins/XanixTransform/transformer.d.ts +16 -0
  36. package/dist/bin/bundler/plugins/XanixTransform/transformer.js +631 -0
  37. package/dist/bin/bundler/plugins/XanixWatchChange copy.d.ts +10 -0
  38. package/dist/bin/bundler/plugins/XanixWatchChange copy.js +30 -0
  39. package/dist/bin/bundler/plugins/XanixWatchChange.d.ts +9 -0
  40. package/dist/bin/bundler/plugins/XanixWatchChange.js +27 -0
  41. package/dist/bin/bundler/plugins/XanixWatchChangeClient.d.ts +7 -0
  42. package/dist/bin/bundler/plugins/XanixWatchChangeClient.js +15 -0
  43. package/dist/bin/bundler/plugins/commonjs.d.ts +3 -0
  44. package/dist/bin/bundler/plugins/commonjs.js +10 -0
  45. package/dist/bin/bundler/plugins/dep-XanixWatchChange.d.ts +9 -0
  46. package/dist/bin/bundler/plugins/dep-XanixWatchChange.js +27 -0
  47. package/dist/bin/bundler/plugins/nodeResolve.d.ts +3 -0
  48. package/dist/bin/bundler/plugins/nodeResolve.js +10 -0
  49. package/dist/bin/bundler/plugins/pathResolver.d.ts +5 -0
  50. package/dist/bin/bundler/plugins/pathResolver.js +57 -0
  51. package/dist/bin/bundler/plugins/plugins.d.ts +8 -0
  52. package/dist/bin/bundler/plugins/plugins.js +75 -0
  53. package/dist/bin/bundler/plugins/rollupEsbuild.d.ts +3 -0
  54. package/dist/bin/bundler/plugins/rollupEsbuild.js +14 -0
  55. package/dist/bin/bundler/plugins/xanixServerData.d.ts +6 -0
  56. package/dist/bin/bundler/plugins/xanixServerData.js +224 -0
  57. package/dist/bin/bundler/plugins/xanixTsconfigAlias.d.ts +6 -0
  58. package/dist/bin/bundler/plugins/xanixTsconfigAlias.js +51 -0
  59. package/dist/bin/bundler/plugins/xanixUseDataId.d.ts +4 -0
  60. package/dist/bin/bundler/plugins/xanixUseDataId.js +93 -0
  61. package/dist/bin/bundler/watchClient.d.ts +8 -0
  62. package/dist/bin/bundler/watchClient.js +54 -0
  63. package/dist/bin/bundler/watchServer.d.ts +10 -0
  64. package/dist/bin/bundler/watchServer.js +84 -0
  65. package/dist/bin/cli/build.d.ts +2 -0
  66. package/dist/bin/cli/build.js +18 -0
  67. package/dist/bin/cli/dev.d.ts +2 -0
  68. package/dist/bin/cli/dev.js +103 -0
  69. package/dist/bin/cli/start.d.ts +2 -0
  70. package/dist/bin/cli/start.js +19 -0
  71. package/dist/bin/include/entry.d.ts +3 -0
  72. package/dist/bin/include/entry.js +28 -0
  73. package/dist/bin/include/logger.d.ts +10 -0
  74. package/dist/bin/include/logger.js +11 -0
  75. package/dist/bin/include/manifest.d.ts +3 -0
  76. package/dist/bin/include/manifest.js +13 -0
  77. package/dist/bin/include/utils.d.ts +2 -0
  78. package/dist/bin/include/utils.js +14 -0
  79. package/dist/bin/index.d.ts +2 -0
  80. package/dist/bin/index.js +26 -0
  81. package/dist/bin/types.d.ts +12 -0
  82. package/dist/bin/types.js +1 -0
  83. package/dist/client/components/Body.d.ts +5 -0
  84. package/dist/client/components/Body.js +10 -0
  85. package/dist/client/components/Document/context.d.ts +3 -0
  86. package/dist/client/components/Document/context.js +14 -0
  87. package/dist/client/components/Document/index.d.ts +8 -0
  88. package/dist/client/components/Document/index.js +6 -0
  89. package/dist/client/components/Head copy.d.ts +5 -0
  90. package/dist/client/components/Head copy.js +8 -0
  91. package/dist/client/components/Head.d.ts +5 -0
  92. package/dist/client/components/Head.js +10 -0
  93. package/dist/client/components/Link.d.ts +6 -0
  94. package/dist/client/components/Link.js +10 -0
  95. package/dist/client/context/RouteContext.d.ts +8 -0
  96. package/dist/client/context/RouteContext.js +16 -0
  97. package/dist/client/hooks/usePageProps.d.ts +1 -0
  98. package/dist/client/hooks/usePageProps.js +2 -0
  99. package/dist/client/hooks/useRoute.d.ts +1 -0
  100. package/dist/client/hooks/useRoute.js +2 -0
  101. package/dist/client/hooks/useSearchParams.d.ts +1 -0
  102. package/dist/client/hooks/useSearchParams.js +2 -0
  103. package/dist/client/index.d.ts +2 -0
  104. package/dist/client/index.js +2 -0
  105. package/dist/client/navigation.d.ts +4 -0
  106. package/dist/client/navigation.js +14 -0
  107. package/dist/client/refresh.d.ts +7 -0
  108. package/dist/client/refresh.js +15 -0
  109. package/dist/client/runtime.d.ts +10 -0
  110. package/dist/client/runtime.js +98 -0
  111. package/dist/client-runtime.d.ts +10 -0
  112. package/dist/client-runtime.js +113 -0
  113. package/dist/components/BaseDocument.d.ts +3 -0
  114. package/dist/components/BaseDocument.js +8 -0
  115. package/dist/components/Body.d.ts +5 -0
  116. package/dist/components/Body.js +8 -0
  117. package/dist/components/Document/Document.d.ts +16 -0
  118. package/dist/components/Document/Document.js +15 -0
  119. package/dist/components/Document/context.d.ts +17 -0
  120. package/dist/components/Document/context.js +13 -0
  121. package/dist/components/Document/index.d.ts +7 -0
  122. package/dist/components/Document/index.js +10 -0
  123. package/dist/components/Document.d.ts +7 -0
  124. package/dist/components/Document.js +9 -0
  125. package/dist/components/DocumentContext/DocumentContext.d.ts +15 -0
  126. package/dist/components/DocumentContext/DocumentContext.js +18 -0
  127. package/dist/components/DocumentContext/context.d.ts +11 -0
  128. package/dist/components/DocumentContext/context.js +14 -0
  129. package/dist/components/DocumentContext/index.d.ts +15 -0
  130. package/dist/components/DocumentContext/index.js +18 -0
  131. package/dist/components/DocumentContext.d.ts +19 -0
  132. package/dist/components/DocumentContext.js +6 -0
  133. package/dist/components/DocumentProvider.d.ts +13 -0
  134. package/dist/components/DocumentProvider.js +7 -0
  135. package/dist/components/Head.d.ts +5 -0
  136. package/dist/components/Head.js +42 -0
  137. package/dist/components/Link.d.ts +7 -0
  138. package/dist/components/Link.js +28 -0
  139. package/dist/components/Script.d.ts +3 -0
  140. package/dist/components/Script.js +5 -0
  141. package/dist/dataLoader.d.ts +11 -0
  142. package/dist/dataLoader.js +46 -0
  143. package/dist/document/BaseDocument.d.ts +3 -0
  144. package/dist/document/BaseDocument.js +8 -0
  145. package/dist/document/Body.d.ts +5 -0
  146. package/dist/document/Body.js +9 -0
  147. package/dist/document/Document/Document.d.ts +7 -0
  148. package/dist/document/Document/Document.js +10 -0
  149. package/dist/document/Document/context.d.ts +17 -0
  150. package/dist/document/Document/context.js +13 -0
  151. package/dist/document/Document/index.d.ts +7 -0
  152. package/dist/document/Document/index.js +10 -0
  153. package/dist/document/Document.d.ts +7 -0
  154. package/dist/document/Document.js +10 -0
  155. package/dist/document/DocumentContext.d.ts +17 -0
  156. package/dist/document/DocumentContext.js +6 -0
  157. package/dist/document/Head.d.ts +5 -0
  158. package/dist/document/Head.js +40 -0
  159. package/dist/document/Link.d.ts +7 -0
  160. package/dist/document/Link.js +28 -0
  161. package/dist/document/Script.d.ts +3 -0
  162. package/dist/document/Script.js +5 -0
  163. package/dist/document/context.d.ts +17 -0
  164. package/dist/document/context.js +13 -0
  165. package/dist/document/index.d.ts +8 -0
  166. package/dist/document/index.js +7 -0
  167. package/dist/document/useDocument.d.ts +2 -0
  168. package/dist/document/useDocument.js +10 -0
  169. package/dist/hooks/useCookies.d.ts +2 -0
  170. package/dist/hooks/useCookies.js +11 -0
  171. package/dist/hooks/useData.d.ts +18 -0
  172. package/dist/hooks/useData.js +69 -0
  173. package/dist/hooks/useDocument.d.ts +2 -0
  174. package/dist/hooks/useDocument.js +10 -0
  175. package/dist/hooks/useHeaders.d.ts +2 -0
  176. package/dist/hooks/useHeaders.js +9 -0
  177. package/dist/hooks/useLocation.d.ts +2 -0
  178. package/dist/hooks/useLocation.js +25 -0
  179. package/dist/hooks/usePage.d.ts +5 -0
  180. package/dist/hooks/usePage.js +9 -0
  181. package/dist/hooks/useParams.d.ts +2 -0
  182. package/dist/hooks/useParams.js +6 -0
  183. package/dist/hooks/usePathname.d.ts +2 -0
  184. package/dist/hooks/usePathname.js +9 -0
  185. package/dist/hooks/useRequest.d.ts +2 -0
  186. package/dist/hooks/useRequest.js +8 -0
  187. package/dist/hooks/useSearchParams.d.ts +12 -0
  188. package/dist/hooks/useSearchParams.js +66 -0
  189. package/dist/index.d.ts +23 -0
  190. package/dist/index.js +27 -0
  191. package/dist/loader.d.ts +11 -0
  192. package/dist/loader.js +16 -0
  193. package/dist/navigate.d.ts +7 -0
  194. package/dist/navigate.js +31 -0
  195. package/dist/navigation/index.d.ts +2 -0
  196. package/dist/navigation/index.js +2 -0
  197. package/dist/navigation/navigate.d.ts +7 -0
  198. package/dist/navigation/navigate.js +31 -0
  199. package/dist/navigation/useLocation.d.ts +1 -0
  200. package/dist/navigation/useLocation.js +22 -0
  201. package/dist/router/index.d.ts +1 -0
  202. package/dist/router/index.js +1 -0
  203. package/dist/router/useParams.d.ts +9 -0
  204. package/dist/router/useParams.js +50 -0
  205. package/dist/router/useSearchParams .d.ts +9 -0
  206. package/dist/router/useSearchParams .js +50 -0
  207. package/dist/router/useSearchParams.d.ts +11 -0
  208. package/dist/router/useSearchParams.js +80 -0
  209. package/dist/server/index.d.ts +0 -0
  210. package/dist/server/index.js +1 -0
  211. package/dist/server/page.d.ts +9 -0
  212. package/dist/server/page.js +60 -0
  213. package/dist/server/readManifest.d.ts +14 -0
  214. package/dist/server/readManifest.js +8 -0
  215. package/dist/server/runtime/createServer.d.ts +12 -0
  216. package/dist/server/runtime/createServer.js +48 -0
  217. package/dist/server/runtime/index.d.ts +3 -0
  218. package/dist/server/runtime/index.js +3 -0
  219. package/dist/server/runtime/readManifest.d.ts +14 -0
  220. package/dist/server/runtime/readManifest.js +8 -0
  221. package/dist/server/runtime/xanixPage.d.ts +9 -0
  222. package/dist/server/runtime/xanixPage.js +87 -0
  223. package/dist/types.d.ts +12 -0
  224. package/dist/types.js +7 -0
  225. package/dist/utils/index.d.ts +9 -0
  226. package/dist/utils/index.js +27 -0
  227. package/dist/xanix.d.ts +3 -0
  228. package/dist/xanix.js +40 -0
  229. package/package.json +73 -13
  230. 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,3 @@
1
+ import { DocumentProps } from "./Document.js";
2
+ declare const BaseDocument: ({ document, children }: DocumentProps) => import("react").JSX.Element;
3
+ export default BaseDocument;
@@ -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,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ const Body = ({ children }) => {
3
+ const isClient = typeof window !== "undefined";
4
+ if (isClient) {
5
+ return children;
6
+ }
7
+ return _jsx("body", { children: children });
8
+ };
9
+ 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,5 @@
1
+ type HeadProps = {
2
+ children?: React.ReactNode;
3
+ };
4
+ declare const Head: ({ children }: HeadProps) => import("react").JSX.Element;
5
+ export default Head;
@@ -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,3 @@
1
+ type ScriptProps = React.DetailedHTMLProps<React.ScriptHTMLAttributes<HTMLScriptElement>, HTMLScriptElement>;
2
+ declare const Script: ({ children, ...props }: ScriptProps) => import("react").JSX.Element;
3
+ export default Script;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ const Script = ({ children, ...props }) => {
3
+ return _jsx("script", { ...props, children: children });
4
+ };
5
+ export default Script;
@@ -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,2 @@
1
+ declare const useDocument: () => import("./DocumentContext").DocumentContextData;
2
+ export default 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,2 @@
1
+ declare const useCookies: () => Record<string, string> | undefined;
2
+ export default useCookies;
@@ -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,2 @@
1
+ declare const useDocument: () => import("../components/DocumentContext.js").DocumentContextData;
2
+ export default useDocument;
@@ -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,2 @@
1
+ declare const useHeaders: () => import("node:http").IncomingHttpHeaders | undefined;
2
+ export default useHeaders;
@@ -0,0 +1,9 @@
1
+ import useRequest from "./useRequest.js";
2
+ const useHeaders = () => {
3
+ const request = useRequest();
4
+ if (__XANIX_SERVER__) {
5
+ return request?.headers;
6
+ }
7
+ return {};
8
+ };
9
+ export default useHeaders;
@@ -0,0 +1,2 @@
1
+ declare const useLocation: () => URL;
2
+ export default useLocation;
@@ -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,5 @@
1
+ declare const usePage: () => {
2
+ pageId: any;
3
+ props: any;
4
+ };
5
+ export default usePage;
@@ -0,0 +1,9 @@
1
+ import useDocument from "./useDocument.js";
2
+ const usePage = () => {
3
+ const { pageId, props } = useDocument();
4
+ return {
5
+ pageId,
6
+ props,
7
+ };
8
+ };
9
+ export default usePage;
@@ -0,0 +1,2 @@
1
+ declare const useParams: () => Record<string, string>;
2
+ export default useParams;
@@ -0,0 +1,6 @@
1
+ import useDocument from "../hooks/useDocument.js";
2
+ const useParams = () => {
3
+ const { params } = useDocument();
4
+ return params;
5
+ };
6
+ export default useParams;
@@ -0,0 +1,2 @@
1
+ declare const usePathname: () => string | undefined;
2
+ export default usePathname;
@@ -0,0 +1,9 @@
1
+ import useRequest from "./useRequest.js";
2
+ const usePathname = () => {
3
+ if (__XANIX_CLIENT__) {
4
+ return window.location.pathname;
5
+ }
6
+ const request = useRequest();
7
+ return request?.path;
8
+ };
9
+ export default usePathname;
@@ -0,0 +1,2 @@
1
+ declare const useRequest: () => import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>> | undefined;
2
+ export default useRequest;
@@ -0,0 +1,8 @@
1
+ import useDocument from "./useDocument.js";
2
+ const useRequest = () => {
3
+ const { request } = useDocument();
4
+ if (__XANIX_SERVER__) {
5
+ return request;
6
+ }
7
+ };
8
+ export default useRequest;
@@ -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;