xanix 1.0.1 → 1.0.3

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 (120) hide show
  1. package/dist/BaseDocument.d.ts +1 -1
  2. package/dist/BaseDocument.js +3 -3
  3. package/dist/bin/bundler/buildCache.js +6 -23
  4. package/dist/bin/bundler/plugins/XanixReactRefresh.js +33 -33
  5. package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.js +5 -0
  6. package/dist/bin/bundler/plugins/XanixTsconfigAlias.d.ts +2 -0
  7. package/dist/bin/bundler/plugins/{xanixTsconfigAlias.js → XanixTsconfigAlias.js} +3 -5
  8. package/dist/bin/bundler/plugins/plugins.js +6 -0
  9. package/dist/bin/bundler/watchClient.js +7 -1
  10. package/dist/bin/cli/build.js +3 -1
  11. package/dist/bin/cli/dev.js +3 -0
  12. package/dist/bin/cli/start copy.d.ts +2 -0
  13. package/dist/bin/cli/start copy.js +34 -0
  14. package/dist/bin/index.js +0 -0
  15. package/dist/client/client-runtime.d.ts +10 -0
  16. package/dist/client/client-runtime.js +98 -0
  17. package/dist/client/index.d.ts +2 -2
  18. package/dist/client/index.js +2 -2
  19. package/dist/client/navigation.d.ts +3 -4
  20. package/dist/client/navigation.js +23 -10
  21. package/dist/client/runtime.d.ts +1 -1
  22. package/dist/components/Document/context.d.ts +4 -10
  23. package/dist/components/Document/context.js +6 -5
  24. package/dist/components/Document/index.d.ts +6 -5
  25. package/dist/components/Document/index.js +3 -7
  26. package/dist/components/Head.js +1 -1
  27. package/dist/document/Body.js +1 -2
  28. package/dist/document/Document.js +1 -2
  29. package/dist/document/DocumentContext.d.ts +1 -0
  30. package/dist/document/Head.js +4 -3
  31. package/dist/document/index.d.ts +1 -1
  32. package/dist/document/index.js +1 -1
  33. package/dist/document/useDocument.d.ts +1 -1
  34. package/dist/hooks/useCookie.d.ts +2 -0
  35. package/dist/hooks/useCookie.js +13 -0
  36. package/dist/hooks/useData.js +1 -3
  37. package/dist/hooks/useRequest copy.d.ts +2 -0
  38. package/dist/hooks/useRequest copy.js +8 -0
  39. package/dist/index.d.ts +0 -4
  40. package/dist/index.js +0 -4
  41. package/dist/navigation/navigate.js +6 -6
  42. package/dist/navigation/useLocation.js +1 -1
  43. package/dist/router/index.d.ts +3 -1
  44. package/dist/router/index.js +3 -1
  45. package/dist/router/useParams.d.ts +1 -9
  46. package/dist/router/useParams.js +3 -48
  47. package/dist/router/usePathname.d.ts +1 -0
  48. package/dist/router/usePathname.js +8 -0
  49. package/dist/router/useSearchParams.js +2 -8
  50. package/dist/runtime/createServer.d.ts +12 -0
  51. package/dist/runtime/createServer.js +40 -0
  52. package/dist/runtime/index.d.ts +12 -0
  53. package/dist/runtime/index.js +40 -0
  54. package/dist/runtime/readManifest.d.ts +14 -0
  55. package/dist/runtime/readManifest.js +8 -0
  56. package/dist/runtime/xanixPage.d.ts +9 -0
  57. package/dist/runtime/xanixPage.js +62 -0
  58. package/dist/server/createServer.d.ts +12 -0
  59. package/dist/server/createServer.js +40 -0
  60. package/dist/server/page.js +2 -0
  61. package/dist/server/runtime copy.d.ts +12 -0
  62. package/dist/server/runtime copy.js +40 -0
  63. package/dist/server/runtime.d.ts +12 -0
  64. package/dist/server/runtime.js +40 -0
  65. package/dist/server/xanixPage.d.ts +9 -0
  66. package/dist/server/xanixPage.js +62 -0
  67. package/dist/utils/index.d.ts +0 -9
  68. package/dist/utils/index.js +1 -27
  69. package/dist/xanix.js +12 -12
  70. package/package.json +73 -73
  71. package/xanix-env.d.ts +79 -79
  72. package/dist/Document.d.ts +0 -7
  73. package/dist/Document.js +0 -7
  74. package/dist/bin/bundler/plugins/XanixWatchChange copy.d.ts +0 -10
  75. package/dist/bin/bundler/plugins/XanixWatchChange copy.js +0 -30
  76. package/dist/bin/bundler/plugins/XanixWatchChange.d.ts +0 -9
  77. package/dist/bin/bundler/plugins/XanixWatchChange.js +0 -27
  78. package/dist/bin/bundler/plugins/XanixWatchChangeClient.d.ts +0 -7
  79. package/dist/bin/bundler/plugins/XanixWatchChangeClient.js +0 -15
  80. package/dist/bin/bundler/plugins/pathResolver.d.ts +0 -5
  81. package/dist/bin/bundler/plugins/pathResolver.js +0 -57
  82. package/dist/bin/bundler/plugins/xanixServerData.d.ts +0 -6
  83. package/dist/bin/bundler/plugins/xanixServerData.js +0 -224
  84. package/dist/bin/bundler/plugins/xanixTsconfigAlias.d.ts +0 -6
  85. package/dist/client/components/Body.d.ts +0 -5
  86. package/dist/client/components/Body.js +0 -10
  87. package/dist/client/components/Document/context.d.ts +0 -3
  88. package/dist/client/components/Document/context.js +0 -14
  89. package/dist/client/components/Document/index.d.ts +0 -8
  90. package/dist/client/components/Document/index.js +0 -6
  91. package/dist/client/components/Head copy.d.ts +0 -5
  92. package/dist/client/components/Head copy.js +0 -8
  93. package/dist/client/components/Head.d.ts +0 -5
  94. package/dist/client/components/Head.js +0 -10
  95. package/dist/client/components/Link.d.ts +0 -6
  96. package/dist/client/components/Link.js +0 -10
  97. package/dist/client/refresh.d.ts +0 -7
  98. package/dist/client/refresh.js +0 -15
  99. package/dist/components/Document/Document.d.ts +0 -16
  100. package/dist/components/Document/Document.js +0 -15
  101. package/dist/components/DocumentContext/DocumentContext.d.ts +0 -15
  102. package/dist/components/DocumentContext/DocumentContext.js +0 -18
  103. package/dist/components/DocumentContext/context.d.ts +0 -11
  104. package/dist/components/DocumentContext/context.js +0 -14
  105. package/dist/components/DocumentContext/index.d.ts +0 -15
  106. package/dist/components/DocumentContext/index.js +0 -18
  107. package/dist/components/DocumentProvider.d.ts +0 -13
  108. package/dist/components/DocumentProvider.js +0 -7
  109. package/dist/document/Document/Document.d.ts +0 -7
  110. package/dist/document/Document/Document.js +0 -10
  111. package/dist/document/Document/context.d.ts +0 -17
  112. package/dist/document/Document/context.js +0 -13
  113. package/dist/document/Document/index.d.ts +0 -7
  114. package/dist/document/Document/index.js +0 -10
  115. package/dist/document/context.d.ts +0 -17
  116. package/dist/document/context.js +0 -13
  117. package/dist/loader.d.ts +0 -11
  118. package/dist/loader.js +0 -16
  119. package/dist/router/useSearchParams .d.ts +0 -9
  120. package/dist/router/useSearchParams .js +0 -50
@@ -1,3 +1,3 @@
1
- import { DocumentProps } from "./document/Document.js";
1
+ import { DocumentProps } from "./components/Document/index.js";
2
2
  declare const BaseDocument: ({ document, children }: DocumentProps) => import("react").JSX.Element;
3
3
  export default BaseDocument;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import Head from "./document/Head.js";
3
- import Body from "./document/Body.js";
4
- import Document from "./document/Document.js";
2
+ import Head from "./components/Head.js";
3
+ import Body from "./components/Body.js";
4
+ import Document from "./components/Document/index.js";
5
5
  const BaseDocument = ({ document, children }) => {
6
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
7
  };
@@ -2,9 +2,9 @@ import path from "node:path";
2
2
  import { rollup } from "rollup";
3
3
  import { build } from "esbuild";
4
4
  import { createRequire } from "node:module";
5
+ import xanixAssets from "./plugins/XanixAssets/index.js";
6
+ import rollupEsbuild from "./plugins/rollupEsbuild.js";
5
7
  import { getDocumentFile } from "../include/utils.js";
6
- import esbuild from "rollup-plugin-esbuild";
7
- import url from "@rollup/plugin-url";
8
8
  const require = createRequire(import.meta.url);
9
9
  const GenerateGraph = async (entries) => {
10
10
  const collector = new Map();
@@ -17,28 +17,11 @@ const GenerateGraph = async (entries) => {
17
17
  const bundle = await rollup({
18
18
  input,
19
19
  plugins: [
20
- url({
21
- include: [
22
- "**/*.jpg",
23
- "**/*.jpeg",
24
- "**/*.png",
25
- "**/*.gif",
26
- "**/*.webp",
27
- "**/*.svg",
28
- "**/*.ico",
29
- "**/*.woff",
30
- "**/*.woff2",
31
- "**/*.ttf",
32
- "**/*.eot",
33
- ],
34
- limit: 0,
35
- fileName: "assets/[name]-[hash][extname]",
36
- emitFiles: true,
20
+ xanixAssets({
21
+ external: true,
37
22
  }),
38
- esbuild({
39
- target: "es2022",
40
- jsx: "automatic",
41
- tsconfig: false,
23
+ rollupEsbuild({
24
+ sourceMap: true,
42
25
  }),
43
26
  ],
44
27
  external(id) {
@@ -16,39 +16,39 @@ export default function xanixReactRefresh() {
16
16
  return null;
17
17
  }
18
18
  const code = fs.readFileSync(id, "utf8");
19
- const refreshCode = `
20
- import * as RefreshRuntime from "react-refresh/runtime";
21
-
22
- ${code}
23
-
24
- if (typeof window !== "undefined") {
25
- RefreshRuntime.injectIntoGlobalHook(window);
26
-
27
- window.$RefreshReg$ = RefreshRuntime.register;
28
- window.$RefreshSig$ = () => (type) => type;
29
-
30
- const ws = new WebSocket("ws://localhost:8080");
31
-
32
- ws.onmessage = async (event) => {
33
- const files = JSON.parse(event.data);
34
-
35
- for (const file of files) {
36
- if (!file.endsWith(".js")) {
37
- continue;
38
- }
39
-
40
- const url =
41
- getImportUrl(file.replace(/\\.js$/, "")) +
42
- "?t=" +
43
- Date.now();
44
-
45
- await import(url);
46
- }
47
-
48
- RefreshRuntime.performReactRefresh();
49
- ws.send("reload")
50
- };
51
- }
19
+ const refreshCode = `
20
+ import * as RefreshRuntime from "react-refresh/runtime";
21
+
22
+ ${code}
23
+
24
+ if (typeof window !== "undefined") {
25
+ RefreshRuntime.injectIntoGlobalHook(window);
26
+
27
+ window.$RefreshReg$ = RefreshRuntime.register;
28
+ window.$RefreshSig$ = () => (type) => type;
29
+
30
+ const ws = new WebSocket("ws://localhost:8080");
31
+
32
+ ws.onmessage = async (event) => {
33
+ const files = JSON.parse(event.data);
34
+
35
+ for (const file of files) {
36
+ if (!file.endsWith(".js")) {
37
+ continue;
38
+ }
39
+
40
+ const url =
41
+ getImportUrl(file.replace(/\\.js$/, "")) +
42
+ "?t=" +
43
+ Date.now();
44
+
45
+ await import(url);
46
+ }
47
+
48
+ RefreshRuntime.performReactRefresh();
49
+ ws.send("reload")
50
+ };
51
+ }
52
52
  `;
53
53
  return {
54
54
  code: refreshCode,
@@ -1,6 +1,11 @@
1
1
  import path from "node:path";
2
2
  import BuildCache from "../../cacheNpmModules.js";
3
3
  function XanixResolveCacheDeps(metadata, entries) {
4
+ if (!entries.length) {
5
+ return {
6
+ name: "xanix:cached-deps",
7
+ };
8
+ }
4
9
  return {
5
10
  name: "xanix:cached-deps",
6
11
  async resolveId(source) {
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from "rollup";
2
+ export default function xanixTsconfigAlias(): Plugin;
@@ -2,11 +2,9 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import ts from "typescript";
4
4
  import alias from "@rollup/plugin-alias";
5
- export default function xanixTsconfigAlias(options = {}) {
6
- const root = options.root ?? process.cwd();
7
- const tsconfigPath = options.tsconfigPath
8
- ? path.resolve(root, options.tsconfigPath)
9
- : path.resolve(root, "tsconfig.json");
5
+ export default function xanixTsconfigAlias() {
6
+ const root = process.cwd();
7
+ const tsconfigPath = path.resolve(root, "tsconfig.json");
10
8
  if (!fs.existsSync(tsconfigPath)) {
11
9
  return {
12
10
  name: "xanix-tsconfig-alias",
@@ -70,6 +70,12 @@ export function xanixDefaultPlugins(options = {}) {
70
70
  jsx: "automatic",
71
71
  tsconfig: false,
72
72
  minify: !development,
73
+ define: {
74
+ __XANIX_CLIENT__: JSON.stringify(isClient),
75
+ __XANIX_SERVER__: JSON.stringify(isServer),
76
+ __XANIX_DEV__: JSON.stringify(development),
77
+ __XANIX_PROD__: JSON.stringify(!development),
78
+ },
73
79
  }),
74
80
  ];
75
81
  }
@@ -19,7 +19,13 @@ const WatchClient = async (entries, options) => {
19
19
  fs.mkdirSync(outDir.client, {
20
20
  recursive: true,
21
21
  });
22
- const buildCache = await BuildCache(entries);
22
+ let buildCache;
23
+ if (entries.length > 0) {
24
+ buildCache = await BuildCache(entries);
25
+ }
26
+ else {
27
+ buildCache = new Map();
28
+ }
23
29
  const watcher = watch({
24
30
  input,
25
31
  treeshake: true,
@@ -10,7 +10,9 @@ const build = async (rootEntry) => {
10
10
  onBuildEnd: async (entries) => {
11
11
  logger.info(pc.green("Building client..."), "client");
12
12
  const duration = Date.now() - st;
13
- await buildClient(entries);
13
+ if (entries.length) {
14
+ await buildClient(entries);
15
+ }
14
16
  logger.info(pc.green(`Build completed in ${duration}ms`), "complete");
15
17
  },
16
18
  });
@@ -45,6 +45,9 @@ const dev = async (rootEntry) => {
45
45
  let firstBuild = true;
46
46
  let _clientWatcher = null;
47
47
  const clientWatcher = async (entries) => {
48
+ if (!entries.length) {
49
+ return;
50
+ }
48
51
  let changedFiles = new Set();
49
52
  _clientWatcher?.close();
50
53
  _clientWatcher = await watchClient(entries, {
@@ -0,0 +1,2 @@
1
+ declare const build: (rootEntry: string) => Promise<void>;
2
+ export default build;
@@ -0,0 +1,34 @@
1
+ import buildServer from "../bundler/buildServer.js";
2
+ import buildClient from "../bundler/buildClient.js";
3
+ import pc from "picocolors";
4
+ import path from "node:path";
5
+ import logger from "../include/logger.js";
6
+ import { spawn } from "child_process";
7
+ import { outDir } from "../bundler/config/output.js";
8
+ let child;
9
+ const build = async (rootEntry) => {
10
+ logger.info(pc.green("Building server..."), "server");
11
+ const st = Date.now();
12
+ await buildServer({
13
+ rootEntry,
14
+ onBuildEnd: async (entries) => {
15
+ logger.info(pc.green("Building client..."), "client");
16
+ const duration = Date.now() - st;
17
+ await buildClient(entries);
18
+ logger.info(pc.green(`Build completed in ${duration}ms`), "complete");
19
+ },
20
+ });
21
+ const filePath = path.join(outDir.server, "index.js");
22
+ child = spawn(process.execPath, [filePath], {
23
+ stdio: "inherit",
24
+ });
25
+ process.on("SIGINT", () => {
26
+ child?.kill();
27
+ process.exit(0);
28
+ });
29
+ process.on("SIGTERM", () => {
30
+ child?.kill();
31
+ process.exit(0);
32
+ });
33
+ };
34
+ export default build;
package/dist/bin/index.js CHANGED
File without changes
@@ -0,0 +1,10 @@
1
+ import type { DocumentContextData } from "../components/DocumentContext.js";
2
+ import type { ComponentType } from "react";
3
+ type DocumentInfo = DocumentContextData & {
4
+ component: ComponentType<any>;
5
+ };
6
+ export declare const getPath: () => string;
7
+ export declare const getImportUrl: (pageId: string) => string;
8
+ export declare const getPage: (path: string) => Promise<any>;
9
+ export declare function mount(path: string, Component: ComponentType<any>, doc: DocumentInfo): Promise<void>;
10
+ export {};
@@ -0,0 +1,98 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createRoot } from "react-dom/client";
3
+ const pages = new Map();
4
+ const ROOT_KEY = "__xanix_root__";
5
+ export const getPath = () => {
6
+ const { pathname, search } = window.location;
7
+ return search ? `${pathname}${search}` : pathname;
8
+ };
9
+ export const getImportUrl = (pageId) => `/.xanix/client/${pageId}.js`;
10
+ function getRoot() {
11
+ let ele = document.body;
12
+ if (!ele) {
13
+ throw new Error("Root element not found");
14
+ }
15
+ ele[ROOT_KEY] = ele[ROOT_KEY] ?? createRoot(ele);
16
+ return ele[ROOT_KEY];
17
+ }
18
+ export const getPage = async (path) => {
19
+ let page = pages.get(path);
20
+ if (page)
21
+ return page;
22
+ const response = await fetch(path, {
23
+ headers: {
24
+ "X-Navigation": "true",
25
+ },
26
+ });
27
+ if (!response.ok) {
28
+ return null;
29
+ }
30
+ return await response.json();
31
+ };
32
+ export async function mount(path, Component, doc) {
33
+ const root = getRoot();
34
+ pages.set(path, doc);
35
+ const Document = (await import(getImportUrl("xanix-document"))).default;
36
+ root.render(_jsx(Document, { document: doc, children: _jsx(Component, { ...doc.props }) }));
37
+ }
38
+ if (typeof window !== "undefined") {
39
+ const dispatch = (name, path) => {
40
+ window.dispatchEvent(new CustomEvent(`xanix:${name}`, { detail: { path } }));
41
+ };
42
+ window.addEventListener("load", async () => {
43
+ const path = getPath();
44
+ dispatch("navigate:start", path);
45
+ const doc = window.XANIX_DOCUMENT;
46
+ const mod = await import(getImportUrl(doc.pageId));
47
+ mount(path, mod.default, doc);
48
+ const scriptTag = document.getElementById(doc.pageId);
49
+ if (scriptTag) {
50
+ scriptTag.remove();
51
+ }
52
+ dispatch("navigate:end", path);
53
+ });
54
+ window.addEventListener("xanix:navigate", async (event) => {
55
+ const path = event.detail.path;
56
+ const replace = event.detail.replace;
57
+ dispatch("navigate:start", path);
58
+ let page = await getPage(path);
59
+ if (!page)
60
+ return;
61
+ const mod = await import(getImportUrl(page.pageId));
62
+ mount(path, mod.default, page);
63
+ if (replace) {
64
+ history.replaceState(null, "", path);
65
+ }
66
+ else {
67
+ history.pushState(null, "", path);
68
+ }
69
+ dispatch("navigate:end", path);
70
+ });
71
+ window.addEventListener("xanix:preload", async (event) => {
72
+ const path = event.detail.path;
73
+ if (!path)
74
+ return;
75
+ dispatch("preload:start", path);
76
+ const page = await getPage(path);
77
+ if (!page)
78
+ return;
79
+ await import(getImportUrl(page.pageId));
80
+ pages.set(path, page);
81
+ dispatch("preload:end", path);
82
+ });
83
+ window.addEventListener("xanix:reload", async (event) => {
84
+ const path = getPath();
85
+ dispatch("navigate:start", path);
86
+ let page = await getPage(path);
87
+ if (!page)
88
+ return;
89
+ const mod = await import(getImportUrl(page.pageId) + "?t=" + Date.now());
90
+ mount(path, mod.default, page);
91
+ history.pushState(null, "", path);
92
+ dispatch("navigate:end", path);
93
+ });
94
+ window.addEventListener("popstate", async () => {
95
+ const path = getPath();
96
+ dispatch("navigate", path);
97
+ });
98
+ }
@@ -1,2 +1,2 @@
1
- import { navigate, back, forward, preload } from "../navigation/navigation.js";
2
- export { navigate, back, forward, preload };
1
+ import { navigate, back, forward } from "./navigation.js";
2
+ export { navigate, back, forward };
@@ -1,2 +1,2 @@
1
- import { navigate, back, forward, preload } from "../navigation/navigation.js";
2
- export { navigate, back, forward, preload };
1
+ import { navigate, back, forward } from "./navigation.js";
2
+ export { navigate, back, forward };
@@ -1,4 +1,3 @@
1
- export declare const navigate: (path: string) => void;
2
- export declare const back: () => void;
3
- export declare const forward: () => void;
4
- export declare const preload: (path: string) => Promise<void>;
1
+ export declare const navigate: (path: string) => Promise<void>;
2
+ export declare const back: () => Promise<void>;
3
+ export declare const forward: () => Promise<void>;
@@ -1,14 +1,27 @@
1
- export const navigate = (path) => {
2
- window.dispatchEvent(new CustomEvent("xanix:navigate", {
3
- detail: { path },
4
- }));
1
+ let history = [];
2
+ let currentIndex = -1;
3
+ const fire = (path) => {
4
+ window.history.pushState({}, "", path);
5
+ const popStateEvent = new PopStateEvent("popstate", { state: {} });
6
+ dispatchEvent(popStateEvent);
5
7
  };
6
- export const back = () => {
7
- window.history.back();
8
+ export const navigate = async (path) => {
9
+ history = history.slice(0, currentIndex + 1);
10
+ history.push(path);
11
+ currentIndex++;
12
+ fire(path);
8
13
  };
9
- export const forward = () => {
10
- window.history.forward();
14
+ export const back = async () => {
15
+ if (currentIndex > 0) {
16
+ currentIndex--;
17
+ const path = history[currentIndex];
18
+ fire(path);
19
+ }
11
20
  };
12
- export const preload = async (path) => {
13
- window.dispatchEvent(new CustomEvent("xanix:preload", { detail: { path } }));
21
+ export const forward = async () => {
22
+ if (currentIndex < history.length - 1) {
23
+ currentIndex++;
24
+ const path = history[currentIndex];
25
+ fire(path);
26
+ }
14
27
  };
@@ -1,4 +1,4 @@
1
- import { DocumentContextData } from "../document/DocumentContext";
1
+ import type { DocumentContextData } from "../components/DocumentContext.js";
2
2
  import type { ComponentType } from "react";
3
3
  type DocumentInfo = DocumentContextData & {
4
4
  component: ComponentType<any>;
@@ -1,17 +1,11 @@
1
- export type DocumentContextData = {
2
- pageId: string;
1
+ export type XanixDocumentData = {
2
+ pageId?: string;
3
3
  props: Record<string, any>;
4
4
  title: string;
5
5
  meta: Array<{
6
6
  name: string;
7
7
  content: string;
8
8
  }>;
9
- request?: Express.Request;
10
9
  };
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;
10
+ export declare const DocumentContext: import("react").Context<XanixDocumentData>;
11
+ export declare const useDocument: () => XanixDocumentData;
@@ -1,6 +1,10 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
1
  import { createContext, useContext } from "react";
3
- export const DocumentContext = createContext(null);
2
+ export const DocumentContext = createContext({
3
+ pageId: "",
4
+ props: {},
5
+ title: "",
6
+ meta: [],
7
+ });
4
8
  export const useDocument = () => {
5
9
  const context = useContext(DocumentContext);
6
10
  if (!context) {
@@ -8,6 +12,3 @@ export const useDocument = () => {
8
12
  }
9
13
  return context;
10
14
  };
11
- export const DocumentProvider = ({ children, value, }) => {
12
- return (_jsx(DocumentContext.Provider, { value: value, children: children }));
13
- };
@@ -1,7 +1,8 @@
1
- import { DocumentContextData } from "./context.js";
2
- export type DocumentProps = {
3
- children?: React.ReactNode;
4
- document: DocumentContextData;
1
+ import { type XanixDocumentData } from "./context.js";
2
+ import { HTMLProps } from "react";
3
+ export type DocumentProps = HTMLProps<HTMLHtmlElement> & {
4
+ document: XanixDocumentData;
5
+ children: React.ReactNode;
5
6
  };
6
- declare const Document: ({ children, document }: DocumentProps) => import("react").JSX.Element;
7
+ declare const Document: ({ document, children, ...props }: DocumentProps) => import("react").JSX.Element;
7
8
  export default Document;
@@ -1,10 +1,6 @@
1
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 }) }));
2
+ import { DocumentContext } from "./context.js";
3
+ const Document = ({ document, children, ...props }) => {
4
+ return (_jsx(DocumentContext.Provider, { value: document, children: _jsx("html", { ...props, children: children }) }));
9
5
  };
10
6
  export default Document;
@@ -35,7 +35,7 @@ const Head = ({ children }) => {
35
35
  params,
36
36
  pageData,
37
37
  request: null,
38
- })};
38
+ })};
39
39
  `,
40
40
  } }), _jsx("script", { type: "module", src: `/.xanix/client/xanix-runtime.js` })] }));
41
41
  };
@@ -1,7 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  const Body = ({ children }) => {
3
- const isClient = typeof window !== "undefined";
4
- if (isClient) {
3
+ if (__XANIX_CLIENT__) {
5
4
  return children;
6
5
  }
7
6
  return _jsx("body", { children: children });
@@ -1,8 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { DocumentProvider } from "./DocumentContext.js";
3
3
  const Document = ({ children, document }) => {
4
- const isClient = typeof window !== "undefined";
5
- if (isClient) {
4
+ if (__XANIX_CLIENT__) {
6
5
  return _jsx(DocumentProvider, { value: document, children: children });
7
6
  }
8
7
  return (_jsx(DocumentProvider, { value: document, children: _jsx("html", { children: children }) }));
@@ -7,6 +7,7 @@ export type DocumentContextData = {
7
7
  name: string;
8
8
  content: string;
9
9
  }>;
10
+ params: Record<string, string>;
10
11
  request?: Request;
11
12
  };
12
13
  export declare const DocumentContext: import("react").Context<DocumentContextData | null>;
@@ -2,7 +2,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
2
2
  import { useEffect } from "react";
3
3
  import useDocument from "./useDocument.js";
4
4
  const Head = ({ children }) => {
5
- const { title, meta, pageId, props } = useDocument();
5
+ const { title, meta, pageId, props, params } = useDocument();
6
6
  useEffect(() => {
7
7
  document.title = title || "";
8
8
  meta?.forEach(({ name, content }) => {
@@ -24,7 +24,7 @@ const Head = ({ children }) => {
24
24
  });
25
25
  }
26
26
  }, [children]);
27
- if (typeof window !== "undefined")
27
+ if (__XANIX_CLIENT__)
28
28
  return _jsx(_Fragment, {});
29
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
30
  __html: `window.XANIX_DOCUMENT = ${JSON.stringify({
@@ -32,8 +32,9 @@ const Head = ({ children }) => {
32
32
  props,
33
33
  meta,
34
34
  title,
35
+ params,
35
36
  request: null,
36
- })};
37
+ })};
37
38
  `,
38
39
  } }), _jsx("script", { type: "module", src: "/.xanix/client/xanix-runtime.js" })] }));
39
40
  };
@@ -1,5 +1,5 @@
1
1
  import Document, { DocumentProps } from "./Document.js";
2
- import useDocument from "./useDocument.js";
2
+ import useDocument from "../hooks/useDocument.js";
3
3
  import Head from "./Head.js";
4
4
  import Body from "./Body.js";
5
5
  import Link from "./Link.js";
@@ -1,5 +1,5 @@
1
1
  import Document from "./Document.js";
2
- import useDocument from "./useDocument.js";
2
+ import useDocument from "../hooks/useDocument.js";
3
3
  import Head from "./Head.js";
4
4
  import Body from "./Body.js";
5
5
  import Link from "./Link.js";
@@ -1,2 +1,2 @@
1
- declare const useDocument: () => import("./DocumentContext").DocumentContextData;
1
+ declare const useDocument: () => {};
2
2
  export default useDocument;
@@ -0,0 +1,2 @@
1
+ declare const useCookie: () => any;
2
+ export default useCookie;
@@ -0,0 +1,13 @@
1
+ import useRequest from "./useRequest";
2
+ const useCookie = () => {
3
+ const request = useRequest();
4
+ if (__XANIX_SERVER__) {
5
+ return request?.cookies;
6
+ }
7
+ return document.cookie.split(";").reduce((cookies, cookie) => {
8
+ const [name, value] = cookie.split("=");
9
+ cookies[name.trim()] = value;
10
+ return cookies;
11
+ }, {});
12
+ };
13
+ export default useCookie;
@@ -6,10 +6,8 @@ const useData = (_callback, _args) => {
6
6
  return {};
7
7
  };
8
8
  useData.register = (xanixId, callback) => {
9
- if (__XANIX_SERVER__) {
9
+ if (typeof __XANIX_SERVER__ !== "undefined" && __XANIX_SERVER__) {
10
10
  loader.register(xanixId, callback);
11
- }
12
- if (__XANIX_SERVER__) {
13
11
  return async (args) => {
14
12
  const page = usePage();
15
13
  const doc = useDocument();
@@ -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;