xanix 1.0.5 → 1.0.8

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 +2 -3
  3. package/dist/bin/bundler/{buildCache.js → cacheNpmModules copy.js } +71 -21
  4. package/dist/bin/bundler/cacheNpmModules.js +9 -5
  5. package/dist/bin/bundler/config/output.js +9 -1
  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 +10 -3
  9. package/dist/bin/bundler/plugins/XanixReactRefresh.js +29 -36
  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 +2 -3
  15. package/dist/bin/include/utils.d.ts +2 -1
  16. package/dist/bin/include/utils.js +9 -6
  17. package/dist/bin/index.js +0 -0
  18. package/dist/client-runtime.js +15 -15
  19. package/dist/components/BaseDocument.d.ts +1 -1
  20. package/dist/components/BaseDocument.js +1 -3
  21. package/dist/components/Body.js +3 -1
  22. package/dist/components/Document.js +3 -1
  23. package/dist/components/Head.d.ts +1 -1
  24. package/dist/components/Head.js +37 -34
  25. package/dist/components/Link.d.ts +1 -1
  26. package/dist/components/Link.js +23 -18
  27. package/dist/dataLoader.d.ts +1 -1
  28. package/dist/dataLoader.js +11 -5
  29. package/dist/hooks/useData.d.ts +2 -6
  30. package/dist/hooks/useData.js +1 -1
  31. package/dist/index.d.ts +5 -0
  32. package/dist/index.js +4 -0
  33. package/dist/navigate.js +11 -8
  34. package/dist/server/runtime/xanixPage.js +1 -4
  35. package/dist/types/assets.d.ts +34 -0
  36. package/dist/types/express.d.ts +12 -0
  37. package/dist/types/globals.d.ts +26 -0
  38. package/dist/types/xanix-virtual.d.ts +26 -0
  39. package/dist/utils.d.ts +4 -0
  40. package/dist/utils.js +4 -0
  41. package/package.json +79 -73
  42. package/dist/BaseDocument.d.ts +0 -3
  43. package/dist/BaseDocument.js +0 -8
  44. package/dist/bin/bundler/plugins/XanixAssets/index.d.ts +0 -4
  45. package/dist/bin/bundler/plugins/XanixAssets/index.js +0 -22
  46. package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.d.ts +0 -6
  47. package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.js +0 -350
  48. package/dist/bin/bundler/plugins/XanixHydrate.d.ts +0 -3
  49. package/dist/bin/bundler/plugins/XanixHydrate.js +0 -34
  50. package/dist/bin/bundler/plugins/commonjs.d.ts +0 -3
  51. package/dist/bin/bundler/plugins/commonjs.js +0 -10
  52. package/dist/bin/bundler/plugins/dep-XanixWatchChange.d.ts +0 -9
  53. package/dist/bin/bundler/plugins/dep-XanixWatchChange.js +0 -27
  54. package/dist/bin/bundler/plugins/nodeResolve.d.ts +0 -3
  55. package/dist/bin/bundler/plugins/nodeResolve.js +0 -10
  56. package/dist/bin/bundler/plugins/rollupEsbuild.d.ts +0 -3
  57. package/dist/bin/bundler/plugins/rollupEsbuild.js +0 -14
  58. package/dist/bin/cli/start copy.d.ts +0 -2
  59. package/dist/bin/cli/start copy.js +0 -34
  60. package/dist/client/client-runtime.d.ts +0 -10
  61. package/dist/client/client-runtime.js +0 -98
  62. package/dist/client/context/RouteContext.d.ts +0 -8
  63. package/dist/client/context/RouteContext.js +0 -16
  64. package/dist/client/hooks/usePageProps.d.ts +0 -1
  65. package/dist/client/hooks/usePageProps.js +0 -2
  66. package/dist/client/hooks/useRoute.d.ts +0 -1
  67. package/dist/client/hooks/useRoute.js +0 -2
  68. package/dist/client/hooks/useSearchParams.d.ts +0 -1
  69. package/dist/client/hooks/useSearchParams.js +0 -2
  70. package/dist/client/index.d.ts +0 -2
  71. package/dist/client/index.js +0 -2
  72. package/dist/client/navigation.d.ts +0 -3
  73. package/dist/client/navigation.js +0 -27
  74. package/dist/client/runtime.d.ts +0 -10
  75. package/dist/client/runtime.js +0 -98
  76. package/dist/components/Document/context.d.ts +0 -11
  77. package/dist/components/Document/context.js +0 -14
  78. package/dist/components/Document/index.d.ts +0 -8
  79. package/dist/components/Document/index.js +0 -6
  80. package/dist/document/BaseDocument.d.ts +0 -3
  81. package/dist/document/BaseDocument.js +0 -8
  82. package/dist/document/Body.d.ts +0 -5
  83. package/dist/document/Body.js +0 -8
  84. package/dist/document/Document.d.ts +0 -7
  85. package/dist/document/Document.js +0 -9
  86. package/dist/document/DocumentContext.d.ts +0 -18
  87. package/dist/document/DocumentContext.js +0 -6
  88. package/dist/document/Head.d.ts +0 -5
  89. package/dist/document/Head.js +0 -41
  90. package/dist/document/Link.d.ts +0 -7
  91. package/dist/document/Link.js +0 -28
  92. package/dist/document/Script.d.ts +0 -3
  93. package/dist/document/Script.js +0 -5
  94. package/dist/document/index.d.ts +0 -8
  95. package/dist/document/index.js +0 -7
  96. package/dist/document/useDocument.d.ts +0 -2
  97. package/dist/document/useDocument.js +0 -10
  98. package/dist/hooks/useCookie.d.ts +0 -2
  99. package/dist/hooks/useCookie.js +0 -13
  100. package/dist/hooks/useRequest copy.d.ts +0 -2
  101. package/dist/hooks/useRequest copy.js +0 -8
  102. package/dist/navigation/index.d.ts +0 -2
  103. package/dist/navigation/index.js +0 -2
  104. package/dist/navigation/navigate.d.ts +0 -7
  105. package/dist/navigation/navigate.js +0 -31
  106. package/dist/navigation/useLocation.d.ts +0 -1
  107. package/dist/navigation/useLocation.js +0 -22
  108. package/dist/router/index.d.ts +0 -3
  109. package/dist/router/index.js +0 -3
  110. package/dist/router/useParams.d.ts +0 -1
  111. package/dist/router/useParams.js +0 -5
  112. package/dist/router/usePathname.d.ts +0 -1
  113. package/dist/router/usePathname.js +0 -8
  114. package/dist/router/useSearchParams.d.ts +0 -11
  115. package/dist/router/useSearchParams.js +0 -74
  116. package/dist/runtime/createServer.d.ts +0 -12
  117. package/dist/runtime/createServer.js +0 -40
  118. package/dist/runtime/index.d.ts +0 -12
  119. package/dist/runtime/index.js +0 -40
  120. package/dist/runtime/readManifest.d.ts +0 -14
  121. package/dist/runtime/readManifest.js +0 -8
  122. package/dist/runtime/xanixPage.d.ts +0 -9
  123. package/dist/runtime/xanixPage.js +0 -62
  124. package/dist/server/createServer.d.ts +0 -12
  125. package/dist/server/createServer.js +0 -40
  126. package/dist/server/page.d.ts +0 -9
  127. package/dist/server/page.js +0 -62
  128. package/dist/server/readManifest.d.ts +0 -14
  129. package/dist/server/readManifest.js +0 -8
  130. package/dist/server/runtime copy.d.ts +0 -12
  131. package/dist/server/runtime copy.js +0 -40
  132. package/dist/server/runtime.d.ts +0 -12
  133. package/dist/server/runtime.js +0 -40
  134. package/dist/server/xanixPage.d.ts +0 -9
  135. package/dist/server/xanixPage.js +0 -62
  136. package/dist/types.d.ts +0 -12
  137. package/dist/types.js +0 -7
  138. package/dist/utils/index.d.ts +0 -0
  139. package/dist/utils/index.js +0 -1
  140. package/dist/xanix.d.ts +0 -3
  141. package/dist/xanix.js +0 -40
  142. package/xanix-env.d.ts +0 -79
  143. /package/dist/bin/bundler/{buildCache.d.ts → cacheNpmModules copy.d.ts} +0 -0
@@ -1,14 +1,17 @@
1
- import fs from "node:fs";
2
1
  import path from "node:path";
3
2
  import { fileURLToPath } from "node:url";
3
+ import crypto from "node:crypto";
4
4
  const __dirname = fileURLToPath(import.meta.url);
5
+ export function uid(value, length) {
6
+ const hash = crypto.createHash("sha256").update(value).digest("hex");
7
+ return length ? hash.slice(0, length) : hash;
8
+ }
5
9
  export const getClientRuntimeFile = () => {
6
10
  return path.join(__dirname, "../../../client-runtime.js");
7
11
  };
8
- export const getDocumentFile = async () => {
9
- const documentEntry = path.join(process.cwd(), "Document.tsx");
10
- if (fs.existsSync(documentEntry)) {
11
- return documentEntry;
12
+ export const getClientRuntimeFileName = (mode) => {
13
+ if (mode === "development") {
14
+ return "xanix-runtime";
12
15
  }
13
- return path.join(__dirname, "../../../components/BaseDocument.js");
16
+ return uid("xanix-runtime", 32);
14
17
  };
package/dist/bin/index.js CHANGED
File without changes
@@ -41,16 +41,16 @@ export const getPage = async (path) => {
41
41
  export async function mount(path, Component, doc) {
42
42
  const root = getRoot();
43
43
  pages.set(path, doc);
44
- const Document = (await import(getImportUrl("xanix-document"))).default;
44
+ const Document = (await import("virtual:xanix-document")).default;
45
45
  root.render(_jsx(Document, { document: doc, children: _jsx(Component, { ...doc.props }) }));
46
46
  }
47
- if (typeof window !== "undefined") {
47
+ if (__XANIX_CLIENT__) {
48
48
  const dispatch = (name, path) => {
49
- window.dispatchEvent(new CustomEvent(`xanix:${name}`, { detail: { path } }));
49
+ window.dispatchEvent(new CustomEvent(name, { detail: { path } }));
50
50
  };
51
51
  window.addEventListener("load", async () => {
52
52
  const path = getPath();
53
- dispatch("navigate:start", path);
53
+ dispatch(XANIX_NAVIGATE_START, path);
54
54
  const doc = window.XANIX_DOCUMENT;
55
55
  const mod = await import(getImportUrl(doc.pageId));
56
56
  mount(path, mod.default, doc);
@@ -58,12 +58,12 @@ if (typeof window !== "undefined") {
58
58
  if (scriptTag) {
59
59
  scriptTag.remove();
60
60
  }
61
- dispatch("navigate:end", path);
61
+ dispatch(XANIX_NAVIGATE_END, path);
62
62
  });
63
63
  window.addEventListener("popstate", async () => {
64
- dispatch("navigate", getPath());
64
+ dispatch(XANIX_NAVIGATE, getPath());
65
65
  });
66
- window.addEventListener("xanix:navigate", async (event) => {
66
+ window.addEventListener(XANIX_NAVIGATE, async (event) => {
67
67
  const { path, replace } = event.detail;
68
68
  const currentPath = getPath();
69
69
  if (path === currentPath)
@@ -71,7 +71,7 @@ if (typeof window !== "undefined") {
71
71
  const url = new URL(path, window.location.origin);
72
72
  const prevUrl = new URL(currentPath, window.location.origin);
73
73
  const isSamePath = url.pathname === prevUrl.pathname;
74
- dispatch("navigate:start", path);
74
+ dispatch(XANIX_NAVIGATE_START, path);
75
75
  let page = await getPage(path);
76
76
  if (!page)
77
77
  return;
@@ -79,7 +79,7 @@ if (typeof window !== "undefined") {
79
79
  const mod = await import(getImportUrl(page.pageId));
80
80
  mount(path, mod.default, page);
81
81
  }
82
- dispatch("navigate:end", path);
82
+ dispatch(XANIX_NAVIGATE_END, path);
83
83
  if (replace) {
84
84
  history.replaceState(null, "", path);
85
85
  }
@@ -87,27 +87,27 @@ if (typeof window !== "undefined") {
87
87
  history.pushState(null, "", path);
88
88
  }
89
89
  });
90
- window.addEventListener("xanix:preload", async (event) => {
90
+ window.addEventListener(XANIX_PRELOAD, async (event) => {
91
91
  const path = event.detail.path;
92
92
  if (!path)
93
93
  return;
94
- dispatch("preload:start", path);
94
+ dispatch(XANIX_PRELOAD_START, path);
95
95
  const page = await getPage(path);
96
96
  if (!page)
97
97
  return;
98
98
  await import(getImportUrl(page.pageId));
99
99
  pages.set(path, page);
100
- dispatch("preload:end", path);
100
+ dispatch(XANIX_PRELOAD_END, path);
101
101
  });
102
- window.addEventListener("xanix:reload", async (event) => {
102
+ window.addEventListener(XANIX_NAVIGATE_RELOAD, async (event) => {
103
103
  const path = getPath();
104
- dispatch("navigate:start", path);
104
+ dispatch(XANIX_NAVIGATE_START, path);
105
105
  let page = await getPage(path);
106
106
  if (!page)
107
107
  return;
108
108
  const mod = await import(getImportUrl(page.pageId) + "?t=" + Date.now());
109
109
  mount(path, mod.default, page);
110
110
  history.pushState(null, "", path);
111
- dispatch("navigate:end", path);
111
+ dispatch(XANIX_NAVIGATE_END, path);
112
112
  });
113
113
  }
@@ -1,3 +1,3 @@
1
- import { DocumentProps } from "./Document.js";
1
+ import { type DocumentProps } from "xanix";
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 "xanix";
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,5 @@
1
- let global = typeof window === "undefined" ? globalThis : window;
1
+ import { IS_SERVER } from "./utils.js";
2
+ let global = IS_SERVER ? globalThis : {};
2
3
  global.$XANIXDT_INITIALED = new Map();
3
4
  global.$XANIXDT = new Map();
4
5
  global.$XANIXDT_PAGES = new Map();
@@ -15,14 +16,19 @@ const registerPage = (pageId, xanixId, args) => {
15
16
  return xanixId;
16
17
  };
17
18
  const results = async (pageId) => {
18
- global.$XANIXDT_INITIALED.set(pageId, true);
19
+ if (global.$XANIXDT_INITIALED.has(pageId)) {
20
+ return global.$XANIXDT_INITIALED.get(pageId);
21
+ }
19
22
  const page = global.$XANIXDT_PAGES.get(pageId) || [];
20
23
  const datas = {};
21
24
  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
+ const item = global.$XANIXDT.get(xanixId);
26
+ if (!item)
27
+ return;
28
+ const { callback, args } = item;
29
+ datas[xanixId] = await callback(args);
25
30
  }));
31
+ global.$XANIXDT_INITIALED.set(pageId, datas);
26
32
  return datas;
27
33
  };
28
34
  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";
@@ -13,6 +17,7 @@ import useRequest from "./hooks/useRequest.js";
13
17
  import useHeaders from "./hooks/useHeaders.js";
14
18
  import useCookies from "./hooks/useCookies.js";
15
19
  import useData from "./hooks/useData.js";
20
+ export * from "./utils.js";
16
21
  import { navigate, back, forward, preload, onNavigateStart, onNavigateEnd, reload } from "./navigate.js";
17
22
  export { Link, Document, Head, Body, Script, useDocument, useLocation, useParams, usePathname, useSearchParams, usePage, useRequest, useHeaders, useCookies, useData, navigate, back, forward, preload, onNavigateStart, onNavigateEnd, reload, };
18
23
  export type { DocumentProps };
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";
@@ -14,6 +17,7 @@ import useRequest from "./hooks/useRequest.js";
14
17
  import useHeaders from "./hooks/useHeaders.js";
15
18
  import useCookies from "./hooks/useCookies.js";
16
19
  import useData from "./hooks/useData.js";
20
+ export * from "./utils.js";
17
21
  // navigate
18
22
  import { navigate, back, forward, preload, onNavigateStart, onNavigateEnd, reload, } from "./navigate.js";
19
23
  export { Link, Document, Head, Body, Script,
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,8 +2,6 @@ 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";
8
6
  function renderPage(element) {
9
7
  return new Promise((resolve, reject) => {
@@ -48,8 +46,7 @@ export default async function xanixPage({ pageId, req, res, Component, props, })
48
46
  res.status(404).send("Page Not Found");
49
47
  return;
50
48
  }
51
- const Document = (await import(pathToFileURL(path.join(process.cwd(), ".xanix", "xanix-document.js"))
52
- .href)).default;
49
+ const Document = (await import("virtual:xanix-document")).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,26 @@
1
+ declare global {
2
+ const __XANIX_CLIENT_RUNTIME_FILE_NAME__: string;
3
+ const __XANIX_CLIENT__: boolean;
4
+ const __XANIX_SERVER__: boolean;
5
+ const __XANIX_DEV__: boolean;
6
+ const __XANIX_PROD__: boolean;
7
+
8
+ // XANIX Data
9
+ const XANIXDT: {
10
+ handlers: Record<string, () => Promise<any>>;
11
+ pages: Record<string, string[]>;
12
+ initialed: Record<string, boolean>;
13
+ };
14
+
15
+ // navigation events
16
+ const XANIX_NAVIGATE: string;
17
+ const XANIX_NAVIGATE_START: string;
18
+ const XANIX_NAVIGATE_END: string;
19
+ const XANIX_PRELOAD: string;
20
+ const XANIX_PRELOAD_START: string;
21
+ const XANIX_PRELOAD_END: string;
22
+
23
+ const XANIX_NAVIGATE_RELOAD: string;
24
+ }
25
+
26
+ 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
+ }
@@ -0,0 +1,4 @@
1
+ export declare const IS_SERVER: boolean;
2
+ export declare const IS_CLIENT: boolean;
3
+ export declare const IS_DEVELOPMENT: boolean;
4
+ export declare const IS_PRODUCTION: boolean;
package/dist/utils.js ADDED
@@ -0,0 +1,4 @@
1
+ export const IS_SERVER = typeof __XANIX_SERVER__ !== "undefined" && __XANIX_SERVER__;
2
+ export const IS_CLIENT = !IS_SERVER;
3
+ export const IS_DEVELOPMENT = typeof __XANIX_DEV__ !== "undefined" && __XANIX_DEV__;
4
+ export const IS_PRODUCTION = typeof __XANIX_PROD__ !== "undefined" && __XANIX_PROD__;