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
@@ -1,3 +0,0 @@
1
- import type { Plugin } from "rollup";
2
- import { XanixClientEntry } from "../../types.js";
3
- export default function xanixHydrate(entries: XanixClientEntry[]): Plugin;
@@ -1,34 +0,0 @@
1
- export default function xanixHydrate(entries) {
2
- const entryNames = new Set(entries.map((entry) => entry.name));
3
- return {
4
- name: "xanix-hydrate",
5
- renderChunk(code, chunk) {
6
- // Only process the entries we explicitly provided.
7
- if (!chunk.isEntry || !entryNames.has(chunk.name)) {
8
- return null;
9
- }
10
- // Must have a default export.
11
- if (!chunk.exports.includes("default")) {
12
- return null;
13
- }
14
- // Find Rollup's generated default export variable.
15
- const match = code.match(/export\s*\{\s*([^,\s]+)\s+as\s+default\s*\}/);
16
- if (!match) {
17
- return null;
18
- }
19
- const component = match[1];
20
- const hydration = `\nwindow.xanix.hydrate(` +
21
- `${component}, ` +
22
- `window.PAGE_PROPS` +
23
- `);\n`;
24
- const exportIndex = code.lastIndexOf("export {");
25
- if (exportIndex === -1) {
26
- return null;
27
- }
28
- return {
29
- code: code.slice(0, exportIndex) + hydration + code.slice(exportIndex),
30
- map: null,
31
- };
32
- },
33
- };
34
- }
@@ -1,3 +0,0 @@
1
- import { RollupCommonJSOptions } from "@rollup/plugin-commonjs";
2
- declare const rollupCommonjs: (opt?: RollupCommonJSOptions) => import("rollup").Plugin<any>;
3
- export default rollupCommonjs;
@@ -1,10 +0,0 @@
1
- import commonjs from "@rollup/plugin-commonjs";
2
- const rollupCommonjs = (opt) => {
3
- return commonjs({
4
- include: /node_modules/,
5
- extensions: [".js", ".cjs"],
6
- transformMixedEsModules: true,
7
- ...opt,
8
- });
9
- };
10
- export default rollupCommonjs;
@@ -1,9 +0,0 @@
1
- import { Plugin } from "rollup";
2
- import { XanixClientEntry } from "../../types";
3
- export type XanixWatchChangeOptions = {
4
- onClientEntryChange?: (entry: string, entries: XanixClientEntry[]) => Promise<void>;
5
- onServerChange?: (entry: string, entries: XanixClientEntry[]) => Promise<void>;
6
- onChange?: (entry: string, event: "update" | "delete" | "create" | undefined) => void;
7
- };
8
- declare const XanixWatchChange: (entries: XanixClientEntry[], options: XanixWatchChangeOptions) => Plugin;
9
- export default XanixWatchChange;
@@ -1,27 +0,0 @@
1
- import path from "path";
2
- import { createManifest, readManifest } from "../../include/manifest.js";
3
- import generateClientEntries from "../generateClientEntries.js";
4
- import { entriesEqual } from "../../include/entry.js";
5
- const XanixWatchChange = (entries, options) => {
6
- return {
7
- name: "xanix-watch-server",
8
- async watchChange(id, change) {
9
- const entry = path.resolve(id).replaceAll("\\", "/");
10
- const manifest = await readManifest();
11
- if (!manifest)
12
- return;
13
- const isClientEntry = Array.from(manifest.entries.values()).find((e) => e.file === entry);
14
- if (!isClientEntry) {
15
- const entries = await generateClientEntries();
16
- const isEqual = await entriesEqual(entries);
17
- if (!isEqual) {
18
- await createManifest(entries);
19
- await options.onClientEntryChange?.(entry, entries);
20
- }
21
- await options.onServerChange?.(entry, entries);
22
- }
23
- options.onChange?.(entry, change?.event);
24
- },
25
- };
26
- };
27
- export default XanixWatchChange;
@@ -1,3 +0,0 @@
1
- import { RollupNodeResolveOptions } from "@rollup/plugin-node-resolve";
2
- declare const rollupNodeResolve: (browser?: boolean, options?: RollupNodeResolveOptions) => import("rollup").Plugin<any>;
3
- export default rollupNodeResolve;
@@ -1,10 +0,0 @@
1
- import nodeResolve from "@rollup/plugin-node-resolve";
2
- const rollupNodeResolve = (browser = true, options) => {
3
- return nodeResolve({
4
- extensions: [".mjs", ".js", ".json", ".node", ".ts", ".tsx", ".jsx"],
5
- browser: browser,
6
- preferBuiltins: !browser,
7
- ...options,
8
- });
9
- };
10
- export default rollupNodeResolve;
@@ -1,3 +0,0 @@
1
- import { Options } from "rollup-plugin-esbuild";
2
- declare const rollupEsbuild: (options?: Options) => import("rollup").Plugin<any>;
3
- export default rollupEsbuild;
@@ -1,14 +0,0 @@
1
- import esbuild from "rollup-plugin-esbuild";
2
- const rollupEsbuild = (options) => {
3
- return esbuild({
4
- target: "es2022",
5
- platform: "browser",
6
- format: "esm",
7
- jsx: "automatic",
8
- sourceMap: false,
9
- minify: false,
10
- include: /\.(mjs|js|cjs|ts|tsx|jsx)$/,
11
- ...options,
12
- });
13
- };
14
- export default rollupEsbuild;
@@ -1,2 +0,0 @@
1
- declare const build: (rootEntry: string) => Promise<void>;
2
- export default build;
@@ -1,34 +0,0 @@
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;
@@ -1,10 +0,0 @@
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 {};
@@ -1,98 +0,0 @@
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,8 +0,0 @@
1
- import React from "react";
2
- export declare const RouteContext: React.Context<string>;
3
- type RouteProviderProps = {
4
- children: React.ReactNode;
5
- value?: string;
6
- };
7
- export declare const RouteProvider: ({ children, value }: RouteProviderProps) => React.JSX.Element;
8
- export default RouteContext;
@@ -1,16 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { useMemo } from "react";
3
- export const RouteContext = React.createContext("");
4
- let dispach = null;
5
- export const RouteProvider = ({ children, value }) => {
6
- const [route, setRoute] = React.useState(value || window.location.pathname);
7
- useMemo(() => {
8
- if (value) {
9
- dispach = () => {
10
- setRoute(value);
11
- };
12
- }
13
- }, [value]);
14
- return (_jsx(RouteContext.Provider, { value: route, children: children }));
15
- };
16
- export default RouteContext;
@@ -1 +0,0 @@
1
- declare const usePageProps: () => void;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- const usePageProps = () => { };
@@ -1 +0,0 @@
1
- declare const useRoute: () => void;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- const useRoute = () => { };
@@ -1 +0,0 @@
1
- declare const useSearchParams: () => void;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- const useSearchParams = () => { };
@@ -1,2 +0,0 @@
1
- import { navigate, back, forward } from "./navigation.js";
2
- export { navigate, back, forward };
@@ -1,2 +0,0 @@
1
- import { navigate, back, forward } from "./navigation.js";
2
- export { navigate, back, forward };
@@ -1,3 +0,0 @@
1
- export declare const navigate: (path: string) => Promise<void>;
2
- export declare const back: () => Promise<void>;
3
- export declare const forward: () => Promise<void>;
@@ -1,27 +0,0 @@
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);
7
- };
8
- export const navigate = async (path) => {
9
- history = history.slice(0, currentIndex + 1);
10
- history.push(path);
11
- currentIndex++;
12
- fire(path);
13
- };
14
- export const back = async () => {
15
- if (currentIndex > 0) {
16
- currentIndex--;
17
- const path = history[currentIndex];
18
- fire(path);
19
- }
20
- };
21
- export const forward = async () => {
22
- if (currentIndex < history.length - 1) {
23
- currentIndex++;
24
- const path = history[currentIndex];
25
- fire(path);
26
- }
27
- };
@@ -1,10 +0,0 @@
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 {};
@@ -1,98 +0,0 @@
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,11 +0,0 @@
1
- export type XanixDocumentData = {
2
- pageId?: string;
3
- props: Record<string, any>;
4
- title: string;
5
- meta: Array<{
6
- name: string;
7
- content: string;
8
- }>;
9
- };
10
- export declare const DocumentContext: import("react").Context<XanixDocumentData>;
11
- export declare const useDocument: () => XanixDocumentData;
@@ -1,14 +0,0 @@
1
- import { createContext, useContext } from "react";
2
- export const DocumentContext = createContext({
3
- pageId: "",
4
- props: {},
5
- title: "",
6
- meta: [],
7
- });
8
- export const useDocument = () => {
9
- const context = useContext(DocumentContext);
10
- if (!context) {
11
- throw new Error("useDocument must be used within a DocumentProvider");
12
- }
13
- return context;
14
- };
@@ -1,8 +0,0 @@
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;
6
- };
7
- declare const Document: ({ document, children, ...props }: DocumentProps) => import("react").JSX.Element;
8
- export default Document;
@@ -1,6 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
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 }) }));
5
- };
6
- export default Document;
@@ -1,3 +0,0 @@
1
- import { DocumentProps } from "./Document.js";
2
- declare const BaseDocument: ({ document, children }: DocumentProps) => import("react").JSX.Element;
3
- export default BaseDocument;
@@ -1,8 +0,0 @@
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;
@@ -1,5 +0,0 @@
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;
@@ -1,8 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- const Body = ({ children }) => {
3
- if (__XANIX_CLIENT__) {
4
- return children;
5
- }
6
- return _jsx("body", { children: children });
7
- };
8
- export default Body;
@@ -1,7 +0,0 @@
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;
@@ -1,9 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { DocumentProvider } from "./DocumentContext.js";
3
- const Document = ({ children, document }) => {
4
- if (__XANIX_CLIENT__) {
5
- return _jsx(DocumentProvider, { value: document, children: children });
6
- }
7
- return (_jsx(DocumentProvider, { value: document, children: _jsx("html", { children: children }) }));
8
- };
9
- export default Document;
@@ -1,18 +0,0 @@
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
- params: Record<string, string>;
11
- request?: Request;
12
- };
13
- export declare const DocumentContext: import("react").Context<DocumentContextData | null>;
14
- export type DocumentProviderProps = {
15
- children: React.ReactNode;
16
- value: DocumentContextData;
17
- };
18
- export declare const DocumentProvider: ({ children, value, }: DocumentProviderProps) => import("react").JSX.Element;
@@ -1,6 +0,0 @@
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
- };
@@ -1,5 +0,0 @@
1
- type HeadProps = {
2
- children?: React.ReactNode;
3
- };
4
- declare const Head: ({ children }: HeadProps) => import("react").JSX.Element;
5
- export default Head;