xanix 1.0.4 → 1.0.7

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 (143) hide show
  1. package/dist/bin/bundler/buildClient.js +3 -3
  2. package/dist/bin/bundler/buildServer.js +4 -4
  3. package/dist/bin/bundler/cacheNpmModules.js +8 -2
  4. package/dist/bin/bundler/config/output.d.ts +1 -1
  5. package/dist/bin/bundler/config/output.js +11 -3
  6. package/dist/bin/bundler/plugins/XanixDocument/index.d.ts +2 -0
  7. package/dist/bin/bundler/plugins/XanixDocument/index.js +35 -0
  8. package/dist/bin/bundler/plugins/XanixEnv.js +13 -3
  9. package/dist/bin/bundler/plugins/XanixReactRefresh.js +33 -33
  10. package/dist/bin/bundler/plugins/XanixTransform/transformer copy.d.ts +16 -0
  11. package/dist/bin/bundler/plugins/XanixTransform/transformer copy.js +631 -0
  12. package/dist/bin/bundler/plugins/plugins.js +3 -1
  13. package/dist/bin/bundler/watchClient.js +3 -3
  14. package/dist/bin/bundler/watchServer.js +8 -5
  15. package/dist/bin/cli/dev.js +2 -2
  16. package/dist/bin/include/utils.d.ts +3 -0
  17. package/dist/bin/include/utils.js +17 -0
  18. package/dist/bin/index.js +0 -0
  19. package/dist/client-runtime.js +17 -15
  20. package/dist/components/BaseDocument.d.ts +1 -1
  21. package/dist/components/BaseDocument.js +1 -3
  22. package/dist/components/Body.js +3 -1
  23. package/dist/components/Document.js +3 -1
  24. package/dist/components/Head.d.ts +1 -1
  25. package/dist/components/Head.js +37 -34
  26. package/dist/components/Link.d.ts +1 -1
  27. package/dist/components/Link.js +23 -18
  28. package/dist/dataLoader.d.ts +1 -1
  29. package/dist/dataLoader.js +14 -5
  30. package/dist/hooks/useData.d.ts +2 -6
  31. package/dist/hooks/useData.js +1 -1
  32. package/dist/index.d.ts +4 -0
  33. package/dist/index.js +3 -0
  34. package/dist/navigate.js +11 -8
  35. package/dist/server/runtime/xanixPage.js +1 -4
  36. package/dist/types/assets.d.ts +34 -0
  37. package/dist/types/express.d.ts +12 -0
  38. package/dist/types/globals.d.ts +27 -0
  39. package/dist/types/xanix-virtual.d.ts +26 -0
  40. package/package.json +75 -73
  41. package/dist/BaseDocument.d.ts +0 -3
  42. package/dist/BaseDocument.js +0 -8
  43. package/dist/bin/bundler/buildCache.d.ts +0 -11
  44. package/dist/bin/bundler/buildCache.js +0 -112
  45. package/dist/bin/bundler/plugins/XanixAssets/index.d.ts +0 -4
  46. package/dist/bin/bundler/plugins/XanixAssets/index.js +0 -22
  47. package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.d.ts +0 -6
  48. package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.js +0 -350
  49. package/dist/bin/bundler/plugins/XanixHydrate.d.ts +0 -3
  50. package/dist/bin/bundler/plugins/XanixHydrate.js +0 -34
  51. package/dist/bin/bundler/plugins/commonjs.d.ts +0 -3
  52. package/dist/bin/bundler/plugins/commonjs.js +0 -10
  53. package/dist/bin/bundler/plugins/dep-XanixWatchChange.d.ts +0 -9
  54. package/dist/bin/bundler/plugins/dep-XanixWatchChange.js +0 -27
  55. package/dist/bin/bundler/plugins/nodeResolve.d.ts +0 -3
  56. package/dist/bin/bundler/plugins/nodeResolve.js +0 -10
  57. package/dist/bin/bundler/plugins/rollupEsbuild.d.ts +0 -3
  58. package/dist/bin/bundler/plugins/rollupEsbuild.js +0 -14
  59. package/dist/bin/cli/start copy.d.ts +0 -2
  60. package/dist/bin/cli/start copy.js +0 -34
  61. package/dist/client/client-runtime.d.ts +0 -10
  62. package/dist/client/client-runtime.js +0 -98
  63. package/dist/client/context/RouteContext.d.ts +0 -8
  64. package/dist/client/context/RouteContext.js +0 -16
  65. package/dist/client/hooks/usePageProps.d.ts +0 -1
  66. package/dist/client/hooks/usePageProps.js +0 -2
  67. package/dist/client/hooks/useRoute.d.ts +0 -1
  68. package/dist/client/hooks/useRoute.js +0 -2
  69. package/dist/client/hooks/useSearchParams.d.ts +0 -1
  70. package/dist/client/hooks/useSearchParams.js +0 -2
  71. package/dist/client/index.d.ts +0 -2
  72. package/dist/client/index.js +0 -2
  73. package/dist/client/navigation.d.ts +0 -3
  74. package/dist/client/navigation.js +0 -27
  75. package/dist/client/runtime.d.ts +0 -10
  76. package/dist/client/runtime.js +0 -98
  77. package/dist/components/Document/context.d.ts +0 -11
  78. package/dist/components/Document/context.js +0 -14
  79. package/dist/components/Document/index.d.ts +0 -8
  80. package/dist/components/Document/index.js +0 -6
  81. package/dist/document/BaseDocument.d.ts +0 -3
  82. package/dist/document/BaseDocument.js +0 -8
  83. package/dist/document/Body.d.ts +0 -5
  84. package/dist/document/Body.js +0 -8
  85. package/dist/document/Document.d.ts +0 -7
  86. package/dist/document/Document.js +0 -9
  87. package/dist/document/DocumentContext.d.ts +0 -18
  88. package/dist/document/DocumentContext.js +0 -6
  89. package/dist/document/Head.d.ts +0 -5
  90. package/dist/document/Head.js +0 -41
  91. package/dist/document/Link.d.ts +0 -7
  92. package/dist/document/Link.js +0 -28
  93. package/dist/document/Script.d.ts +0 -3
  94. package/dist/document/Script.js +0 -5
  95. package/dist/document/index.d.ts +0 -8
  96. package/dist/document/index.js +0 -7
  97. package/dist/document/useDocument.d.ts +0 -2
  98. package/dist/document/useDocument.js +0 -10
  99. package/dist/hooks/useCookie.d.ts +0 -2
  100. package/dist/hooks/useCookie.js +0 -13
  101. package/dist/hooks/useRequest copy.d.ts +0 -2
  102. package/dist/hooks/useRequest copy.js +0 -8
  103. package/dist/navigation/index.d.ts +0 -2
  104. package/dist/navigation/index.js +0 -2
  105. package/dist/navigation/navigate.d.ts +0 -7
  106. package/dist/navigation/navigate.js +0 -31
  107. package/dist/navigation/useLocation.d.ts +0 -1
  108. package/dist/navigation/useLocation.js +0 -22
  109. package/dist/router/index.d.ts +0 -3
  110. package/dist/router/index.js +0 -3
  111. package/dist/router/useParams.d.ts +0 -1
  112. package/dist/router/useParams.js +0 -5
  113. package/dist/router/usePathname.d.ts +0 -1
  114. package/dist/router/usePathname.js +0 -8
  115. package/dist/router/useSearchParams.d.ts +0 -11
  116. package/dist/router/useSearchParams.js +0 -74
  117. package/dist/runtime/createServer.d.ts +0 -12
  118. package/dist/runtime/createServer.js +0 -40
  119. package/dist/runtime/index.d.ts +0 -12
  120. package/dist/runtime/index.js +0 -40
  121. package/dist/runtime/readManifest.d.ts +0 -14
  122. package/dist/runtime/readManifest.js +0 -8
  123. package/dist/runtime/xanixPage.d.ts +0 -9
  124. package/dist/runtime/xanixPage.js +0 -62
  125. package/dist/server/createServer.d.ts +0 -12
  126. package/dist/server/createServer.js +0 -40
  127. package/dist/server/page.d.ts +0 -9
  128. package/dist/server/page.js +0 -62
  129. package/dist/server/readManifest.d.ts +0 -14
  130. package/dist/server/readManifest.js +0 -8
  131. package/dist/server/runtime copy.d.ts +0 -12
  132. package/dist/server/runtime copy.js +0 -40
  133. package/dist/server/runtime.d.ts +0 -12
  134. package/dist/server/runtime.js +0 -40
  135. package/dist/server/xanixPage.d.ts +0 -9
  136. package/dist/server/xanixPage.js +0 -62
  137. package/dist/types.d.ts +0 -12
  138. package/dist/types.js +0 -7
  139. package/dist/utils/index.d.ts +0 -0
  140. package/dist/utils/index.js +0 -1
  141. package/dist/xanix.d.ts +0 -3
  142. package/dist/xanix.js +0 -40
  143. package/xanix-env.d.ts +0 -79
@@ -11,7 +11,7 @@ const root = process.cwd();
11
11
  let child;
12
12
  function start() {
13
13
  child?.kill();
14
- return new Promise((resolve, reject) => {
14
+ return new Promise((resolve) => {
15
15
  const filePath = path.join(outDir.server, "index.js");
16
16
  child = spawn(process.execPath, [filePath], {
17
17
  stdio: !child ? "inherit" : "pipe",
@@ -78,7 +78,7 @@ const dev = async (rootEntry) => {
78
78
  async onClientEntryChange(_entry, entries) {
79
79
  await clientWatcher(entries);
80
80
  },
81
- onServerChange: async (entry, entries) => {
81
+ onServerChange: async (_entry, _entries) => {
82
82
  await start();
83
83
  },
84
84
  onBuildEnd: async () => {
@@ -1,2 +1,5 @@
1
+ export declare function uid(value: string, length?: number): string;
1
2
  export declare const getClientRuntimeFile: () => string;
3
+ export declare const getClientRuntimeFileName: (mode: "development" | "production") => string;
2
4
  export declare const getDocumentFile: () => Promise<string>;
5
+ export declare const getDocumentFileName: (mode: "development" | "production") => string;
@@ -1,10 +1,21 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
+ import crypto from "node:crypto";
4
5
  const __dirname = fileURLToPath(import.meta.url);
6
+ export function uid(value, length) {
7
+ const hash = crypto.createHash("sha256").update(value).digest("hex");
8
+ return length ? hash.slice(0, length) : hash;
9
+ }
5
10
  export const getClientRuntimeFile = () => {
6
11
  return path.join(__dirname, "../../../client-runtime.js");
7
12
  };
13
+ export const getClientRuntimeFileName = (mode) => {
14
+ if (mode === "development") {
15
+ return "xanix-runtime";
16
+ }
17
+ return uid("xanix-runtime", 32);
18
+ };
8
19
  export const getDocumentFile = async () => {
9
20
  const documentEntry = path.join(process.cwd(), "Document.tsx");
10
21
  if (fs.existsSync(documentEntry)) {
@@ -12,3 +23,9 @@ export const getDocumentFile = async () => {
12
23
  }
13
24
  return path.join(__dirname, "../../../components/BaseDocument.js");
14
25
  };
26
+ export const getDocumentFileName = (mode) => {
27
+ if (mode === "development") {
28
+ return "xanix-documents";
29
+ }
30
+ return uid("xanix-document", 32);
31
+ };
package/dist/bin/index.js CHANGED
File without changes
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createRoot } from "react-dom/client";
3
+ import Document from "virtual:xanix-document";
3
4
  const pages = new Map();
4
5
  const ROOT_KEY = "__xanix_root__";
5
6
  export const getPath = () => {
@@ -41,16 +42,17 @@ export const getPage = async (path) => {
41
42
  export async function mount(path, Component, doc) {
42
43
  const root = getRoot();
43
44
  pages.set(path, doc);
44
- const Document = (await import(getImportUrl("xanix-document"))).default;
45
+ // const Document = (await import(getImportUrl(__XANIX_DOCUMENT_FILE_NAME__)))
46
+ // .default;
45
47
  root.render(_jsx(Document, { document: doc, children: _jsx(Component, { ...doc.props }) }));
46
48
  }
47
- if (typeof window !== "undefined") {
49
+ if (__XANIX_CLIENT__) {
48
50
  const dispatch = (name, path) => {
49
- window.dispatchEvent(new CustomEvent(`xanix:${name}`, { detail: { path } }));
51
+ window.dispatchEvent(new CustomEvent(name, { detail: { path } }));
50
52
  };
51
53
  window.addEventListener("load", async () => {
52
54
  const path = getPath();
53
- dispatch("navigate:start", path);
55
+ dispatch(XANIX_NAVIGATE_START, path);
54
56
  const doc = window.XANIX_DOCUMENT;
55
57
  const mod = await import(getImportUrl(doc.pageId));
56
58
  mount(path, mod.default, doc);
@@ -58,12 +60,12 @@ if (typeof window !== "undefined") {
58
60
  if (scriptTag) {
59
61
  scriptTag.remove();
60
62
  }
61
- dispatch("navigate:end", path);
63
+ dispatch(XANIX_NAVIGATE_END, path);
62
64
  });
63
65
  window.addEventListener("popstate", async () => {
64
- dispatch("navigate", getPath());
66
+ dispatch(XANIX_NAVIGATE, getPath());
65
67
  });
66
- window.addEventListener("xanix:navigate", async (event) => {
68
+ window.addEventListener(XANIX_NAVIGATE, async (event) => {
67
69
  const { path, replace } = event.detail;
68
70
  const currentPath = getPath();
69
71
  if (path === currentPath)
@@ -71,7 +73,7 @@ if (typeof window !== "undefined") {
71
73
  const url = new URL(path, window.location.origin);
72
74
  const prevUrl = new URL(currentPath, window.location.origin);
73
75
  const isSamePath = url.pathname === prevUrl.pathname;
74
- dispatch("navigate:start", path);
76
+ dispatch(XANIX_NAVIGATE_START, path);
75
77
  let page = await getPage(path);
76
78
  if (!page)
77
79
  return;
@@ -79,7 +81,7 @@ if (typeof window !== "undefined") {
79
81
  const mod = await import(getImportUrl(page.pageId));
80
82
  mount(path, mod.default, page);
81
83
  }
82
- dispatch("navigate:end", path);
84
+ dispatch(XANIX_NAVIGATE_END, path);
83
85
  if (replace) {
84
86
  history.replaceState(null, "", path);
85
87
  }
@@ -87,27 +89,27 @@ if (typeof window !== "undefined") {
87
89
  history.pushState(null, "", path);
88
90
  }
89
91
  });
90
- window.addEventListener("xanix:preload", async (event) => {
92
+ window.addEventListener(XANIX_PRELOAD, async (event) => {
91
93
  const path = event.detail.path;
92
94
  if (!path)
93
95
  return;
94
- dispatch("preload:start", path);
96
+ dispatch(XANIX_PRELOAD_START, path);
95
97
  const page = await getPage(path);
96
98
  if (!page)
97
99
  return;
98
100
  await import(getImportUrl(page.pageId));
99
101
  pages.set(path, page);
100
- dispatch("preload:end", path);
102
+ dispatch(XANIX_PRELOAD_END, path);
101
103
  });
102
- window.addEventListener("xanix:reload", async (event) => {
104
+ window.addEventListener(XANIX_NAVIGATE_RELOAD, async (event) => {
103
105
  const path = getPath();
104
- dispatch("navigate:start", path);
106
+ dispatch(XANIX_NAVIGATE_START, path);
105
107
  let page = await getPage(path);
106
108
  if (!page)
107
109
  return;
108
110
  const mod = await import(getImportUrl(page.pageId) + "?t=" + Date.now());
109
111
  mount(path, mod.default, page);
110
112
  history.pushState(null, "", path);
111
- dispatch("navigate:end", path);
113
+ dispatch(XANIX_NAVIGATE_END, path);
112
114
  });
113
115
  }
@@ -1,3 +1,3 @@
1
- import { DocumentProps } from "./Document.js";
1
+ import { type DocumentProps } from "../index.js";
2
2
  declare const BaseDocument: ({ document, children }: DocumentProps) => import("react").JSX.Element;
3
3
  export default BaseDocument;
@@ -1,7 +1,5 @@
1
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";
2
+ import { Head, Body, Document } from "../index.js";
5
3
  const BaseDocument = ({ document, children }) => {
6
4
  return (_jsxs(Document, { document: document, children: [_jsxs(Head, { children: [_jsx("meta", { charSet: "UTF-8" }), _jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1.0" })] }), _jsx(Body, { children: children })] }));
7
5
  };
@@ -3,6 +3,8 @@ const Body = ({ children }) => {
3
3
  if (__XANIX_CLIENT__) {
4
4
  return children;
5
5
  }
6
- return _jsx("body", { children: children });
6
+ else {
7
+ return _jsx("body", { children: children });
8
+ }
7
9
  };
8
10
  export default Body;
@@ -4,6 +4,8 @@ const Document = ({ children, document }) => {
4
4
  if (__XANIX_CLIENT__) {
5
5
  return _jsx(DocumentProvider, { value: document, children: children });
6
6
  }
7
- return (_jsx(DocumentProvider, { value: document, children: _jsx("html", { children: children }) }));
7
+ else {
8
+ return (_jsx(DocumentProvider, { value: document, children: _jsx("html", { children: children }) }));
9
+ }
8
10
  };
9
11
  export default Document;
@@ -1,5 +1,5 @@
1
1
  type HeadProps = {
2
2
  children?: React.ReactNode;
3
3
  };
4
- declare const Head: ({ children }: HeadProps) => import("react").JSX.Element;
4
+ declare const Head: ({ children }: HeadProps) => import("react").JSX.Element | null | undefined;
5
5
  export default Head;
@@ -1,42 +1,45 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect } from "react";
3
3
  import useDocument from "../hooks/useDocument.js";
4
4
  const Head = ({ children }) => {
5
5
  const { title, meta, pageId, props, params, pageData } = useDocument();
6
- 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);
6
+ if (__XANIX_CLIENT__) {
7
+ useEffect(() => {
8
+ document.title = title || "";
9
+ meta?.forEach(({ name, content }) => {
10
+ let element = document.querySelector(`meta[name="${name}"]`);
11
+ if (!element) {
12
+ element = document.createElement("meta");
13
+ element.setAttribute("name", name);
14
+ document.head.appendChild(element);
15
+ }
16
+ element.setAttribute("content", content);
24
17
  });
25
- }
26
- }, [children]);
27
- if (__XANIX_CLIENT__)
28
- return _jsx(_Fragment, {});
29
- return (_jsxs("head", { children: [_jsx("title", { children: title }), meta?.map(({ name, content }) => (_jsx("meta", { name: name, content: content }, name))), children, _jsx("script", { id: pageId, dangerouslySetInnerHTML: {
30
- __html: `window.XANIX_DOCUMENT = ${JSON.stringify({
31
- pageId,
32
- props,
33
- meta,
34
- title,
35
- params,
36
- pageData,
37
- request: null,
38
- })};
18
+ // add children
19
+ const head = document.head;
20
+ if (children) {
21
+ const container = document.createElement("div");
22
+ container.innerHTML = children;
23
+ Array.from(container.children).forEach((child) => {
24
+ head.appendChild(child);
25
+ });
26
+ }
27
+ }, [children]);
28
+ return null;
29
+ }
30
+ if (__XANIX_SERVER__) {
31
+ return (_jsxs("head", { children: [_jsx("title", { children: title }), meta?.map(({ name, content }) => (_jsx("meta", { name: name, content: content }, name))), children, _jsx("script", { id: pageId, dangerouslySetInnerHTML: {
32
+ __html: `window.XANIX_DOCUMENT = ${JSON.stringify({
33
+ pageId,
34
+ props,
35
+ meta,
36
+ title,
37
+ params,
38
+ pageData,
39
+ request: null,
40
+ })};
39
41
  `,
40
- } }), _jsx("script", { type: "module", src: `/.xanix/client/xanix-runtime.js` })] }));
42
+ } }), _jsx("script", { type: "module", src: `/.xanix/client/${__XANIX_CLIENT_RUNTIME_FILE_NAME__}.js` })] }));
43
+ }
41
44
  };
42
45
  export default Head;
@@ -3,5 +3,5 @@ export type LinkProps = Omit<HTMLProps<HTMLAnchorElement>, "href" | "preload"> &
3
3
  preload?: boolean;
4
4
  href: string;
5
5
  };
6
- declare const Link: ({ children, preload, ...props }: LinkProps) => import("react").JSX.Element;
6
+ declare const Link: ({ children, preload, ...props }: LinkProps) => import("react").JSX.Element | undefined;
7
7
  export default Link;
@@ -3,26 +3,31 @@ import { useEffect, useRef } from "react";
3
3
  import { navigate } from "../navigate.js";
4
4
  const Link = ({ children, preload, ...props }) => {
5
5
  const ref = useRef(null);
6
- 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 () => {
6
+ if (__XANIX_CLIENT__) {
7
+ useEffect(() => {
8
+ const load = () => {
9
+ window.dispatchEvent(new CustomEvent("xanix:preload", { detail: { path: props.href } }));
10
+ };
14
11
  if (preload && ref.current) {
15
- ref.current.removeEventListener("mouseenter", load);
12
+ ref.current.addEventListener("mouseenter", load);
16
13
  }
17
- };
18
- }, []);
19
- if (preload) {
20
- props.onMouseEnter;
14
+ return () => {
15
+ if (preload && ref.current) {
16
+ ref.current.removeEventListener("mouseenter", load);
17
+ }
18
+ };
19
+ }, []);
20
+ if (preload) {
21
+ props.onMouseEnter;
22
+ }
23
+ return (_jsx("a", { ref: ref, ...props, onClick: (e) => {
24
+ e.preventDefault();
25
+ e.stopPropagation();
26
+ navigate(props.href);
27
+ }, children: children }));
28
+ }
29
+ if (__XANIX_SERVER__) {
30
+ return _jsx("a", { ...props, children: children });
21
31
  }
22
- return (_jsx("a", { ref: ref, ...props, onClick: (e) => {
23
- e.preventDefault();
24
- e.stopPropagation();
25
- navigate(props.href);
26
- }, children: children }));
27
32
  };
28
33
  export default Link;
@@ -2,7 +2,7 @@ type PageId = string;
2
2
  type Callback = (args: Record<string, any>) => Promise<any>;
3
3
  type XanixId = string;
4
4
  declare const dataLoader: {
5
- results: (pageId: PageId) => Promise<Record<string, any>>;
5
+ results: (pageId: PageId) => Promise<any>;
6
6
  result: (xanixId: XanixId, args?: Record<string, any>) => Promise<any>;
7
7
  isInit: (pageId: PageId) => any;
8
8
  register: (xanixId: XanixId, callback: Callback) => string;
@@ -1,4 +1,8 @@
1
- let global = typeof window === "undefined" ? globalThis : window;
1
+ let global = typeof __XANIX_SERVER__ !== "undefined" && __XANIX_SERVER__
2
+ ? globalThis
3
+ : typeof window !== "undefined"
4
+ ? window
5
+ : {};
2
6
  global.$XANIXDT_INITIALED = new Map();
3
7
  global.$XANIXDT = new Map();
4
8
  global.$XANIXDT_PAGES = new Map();
@@ -15,14 +19,19 @@ const registerPage = (pageId, xanixId, args) => {
15
19
  return xanixId;
16
20
  };
17
21
  const results = async (pageId) => {
18
- global.$XANIXDT_INITIALED.set(pageId, true);
22
+ if (global.$XANIXDT_INITIALED.has(pageId)) {
23
+ return global.$XANIXDT_INITIALED.get(pageId);
24
+ }
19
25
  const page = global.$XANIXDT_PAGES.get(pageId) || [];
20
26
  const datas = {};
21
27
  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;
28
+ const item = global.$XANIXDT.get(xanixId);
29
+ if (!item)
30
+ return;
31
+ const { callback, args } = item;
32
+ datas[xanixId] = await callback(args);
25
33
  }));
34
+ global.$XANIXDT_INITIALED.set(pageId, datas);
26
35
  return datas;
27
36
  };
28
37
  const result = async (xanixId, args) => {
@@ -5,14 +5,10 @@ declare const useData: {
5
5
  loading: boolean;
6
6
  reload: () => Promise<void>;
7
7
  };
8
- register(xanixId: string, callback: Callback): ((args?: Record<string, any>) => Promise<{
8
+ register(xanixId: string, callback: Callback): (args?: Record<string, any>) => {
9
9
  data: any;
10
10
  loading: boolean;
11
11
  reload: () => Promise<void>;
12
- }>) | ((args?: Record<string, any>) => {
13
- data: any;
14
- loading: boolean;
15
- reload: () => Promise<void>;
16
- });
12
+ };
17
13
  };
18
14
  export default useData;
@@ -8,7 +8,7 @@ const useData = (_callback, _args) => {
8
8
  useData.register = (xanixId, callback) => {
9
9
  if (typeof __XANIX_SERVER__ !== "undefined" && __XANIX_SERVER__) {
10
10
  loader.register(xanixId, callback);
11
- return async (args) => {
11
+ return (args) => {
12
12
  const page = usePage();
13
13
  const doc = useDocument();
14
14
  loader.registerPage(page.pageId, xanixId, args ?? {});
package/dist/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /// <reference path="./types/globals.d.ts" />
2
+ /// <reference path="./types/express.d.ts" />
3
+ /// <reference path="./types/assets.d.ts" />
4
+
1
5
  import Link from "./components/Link.js";
2
6
  import Document, { DocumentProps } from "./components/Document.js";
3
7
  import Head from "./components/Head.js";
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ /// <reference path="./types/globals.d.ts" />
2
+ /// <reference path="./types/express.d.ts" />
3
+ /// <reference path="./types/assets.d.ts" />
1
4
  import Link from "./components/Link.js";
2
5
  import Document from "./components/Document.js";
3
6
  import Head from "./components/Head.js";
package/dist/navigate.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export const navigate = (path, replace = false) => {
2
- window.dispatchEvent(new CustomEvent("xanix:navigate", {
2
+ window.dispatchEvent(new CustomEvent(XANIX_NAVIGATE, {
3
3
  detail: { path, replace },
4
4
  }));
5
5
  };
@@ -10,22 +10,25 @@ export const forward = () => {
10
10
  window.history.forward();
11
11
  };
12
12
  export const preload = async (path) => {
13
- window.dispatchEvent(new CustomEvent("xanix:preload", { detail: { path } }));
13
+ window.dispatchEvent(new CustomEvent(XANIX_PRELOAD, { detail: { path } }));
14
14
  };
15
15
  export const reload = (hard = false) => {
16
- if (hard) {
17
- window.location.reload();
18
- return;
16
+ if (__XANIX_CLIENT__) {
17
+ if (hard) {
18
+ window.location.reload();
19
+ }
20
+ else {
21
+ window.dispatchEvent(new CustomEvent(XANIX_NAVIGATE_RELOAD));
22
+ }
19
23
  }
20
- window.dispatchEvent(new CustomEvent("xanix:reload"));
21
24
  };
22
25
  export const onNavigateStart = (callback) => {
23
26
  if (__XANIX_CLIENT__) {
24
- window.addEventListener("xanix:navigate:start", callback);
27
+ window.addEventListener(XANIX_NAVIGATE_START, callback);
25
28
  }
26
29
  };
27
30
  export const onNavigateEnd = (callback) => {
28
31
  if (__XANIX_CLIENT__) {
29
- window.addEventListener("xanix:navigate:end", callback);
32
+ window.addEventListener(XANIX_NAVIGATE_END, callback);
30
33
  }
31
34
  };
@@ -2,9 +2,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { renderToPipeableStream, renderToString } from "react-dom/server";
3
3
  import readManifest from "./readManifest.js";
4
4
  import { PassThrough } from "node:stream";
5
- import path from "node:path";
6
- import { pathToFileURL } from "node:url";
7
5
  import dataLoader from "../../dataLoader.js";
6
+ import Document from "virtual:xanix-document";
8
7
  function renderPage(element) {
9
8
  return new Promise((resolve, reject) => {
10
9
  let html = "";
@@ -48,8 +47,6 @@ export default async function xanixPage({ pageId, req, res, Component, props, })
48
47
  res.status(404).send("Page Not Found");
49
48
  return;
50
49
  }
51
- const Document = (await import(pathToFileURL(path.join(process.cwd(), ".xanix", "xanix-document.js"))
52
- .href)).default;
53
50
  if (!dataLoader.isInit(pageId)) {
54
51
  renderToString(_jsx(Document, { document: {
55
52
  pageId,
@@ -0,0 +1,34 @@
1
+ declare module "*.png" {
2
+ const src: string;
3
+ export default src;
4
+ }
5
+
6
+ declare module "*.jpg" {
7
+ const src: string;
8
+ export default src;
9
+ }
10
+
11
+ declare module "*.jpeg" {
12
+ const src: string;
13
+ export default src;
14
+ }
15
+
16
+ declare module "*.gif" {
17
+ const src: string;
18
+ export default src;
19
+ }
20
+
21
+ declare module "*.webp" {
22
+ const src: string;
23
+ export default src;
24
+ }
25
+
26
+ declare module "*.svg" {
27
+ const src: string;
28
+ export default src;
29
+ }
30
+
31
+ declare module "*.css" {
32
+ const src: string;
33
+ export default src;
34
+ }
@@ -0,0 +1,12 @@
1
+ import "express-serve-static-core";
2
+
3
+ declare module "express-serve-static-core" {
4
+ interface Request {
5
+ page: {
6
+ setTitle(title: string): void;
7
+ setMeta(name: string, content: string): void;
8
+ };
9
+ }
10
+ }
11
+
12
+ export {};
@@ -0,0 +1,27 @@
1
+ declare global {
2
+ const __XANIX_CLIENT_RUNTIME_FILE_NAME__: string;
3
+ const __XANIX_DOCUMENT_FILE_NAME__: string;
4
+ const __XANIX_CLIENT__: boolean;
5
+ const __XANIX_SERVER__: boolean;
6
+ const __XANIX_DEV__: boolean;
7
+ const __XANIX_PROD__: boolean;
8
+
9
+ // XANIX Data
10
+ const XANIXDT: {
11
+ handlers: Record<string, () => Promise<any>>;
12
+ pages: Record<string, string[]>;
13
+ initialed: Record<string, boolean>;
14
+ };
15
+
16
+ // navigation events
17
+ const XANIX_NAVIGATE: string;
18
+ const XANIX_NAVIGATE_START: string;
19
+ const XANIX_NAVIGATE_END: string;
20
+ const XANIX_PRELOAD: string;
21
+ const XANIX_PRELOAD_START: string;
22
+ const XANIX_PRELOAD_END: string;
23
+
24
+ const XANIX_NAVIGATE_RELOAD: string;
25
+ }
26
+
27
+ export {};
@@ -0,0 +1,26 @@
1
+ declare module "virtual:xanix-document" {
2
+ import type { ComponentType, ReactNode } from "react";
3
+ import type { Request } from "express";
4
+
5
+ export type XanixDocumentData = {
6
+ pageId: string;
7
+ props: Record<string, any>;
8
+ title: string;
9
+ meta: Array<{
10
+ name: string;
11
+ content: string;
12
+ }>;
13
+ params: Record<string, string>;
14
+ request?: Request;
15
+ pageData: Record<string, any>;
16
+ };
17
+
18
+ export type XanixDocumentProps = {
19
+ document: XanixDocumentData;
20
+ children?: ReactNode;
21
+ };
22
+
23
+ const Document: ComponentType<XanixDocumentProps>;
24
+
25
+ export default Document;
26
+ }