arcanajs 2.1.0 → 2.1.1
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.
- package/package.json +2 -2
- package/framework/cli/index.d.ts +0 -1
- package/framework/cli/index.js +0 -107
- package/framework/cli/webpack.config.d.ts +0 -3
- package/framework/cli/webpack.config.js +0 -198
- package/framework/lib/client/index.d.ts +0 -2
- package/framework/lib/client/index.js +0 -40
- package/framework/lib/index.d.ts +0 -17
- package/framework/lib/index.js +0 -33
- package/framework/lib/server/ArcanaJSMiddleware.d.ts +0 -16
- package/framework/lib/server/ArcanaJSMiddleware.js +0 -99
- package/framework/lib/server/ArcanaJSServer.d.ts +0 -21
- package/framework/lib/server/ArcanaJSServer.js +0 -140
- package/framework/lib/server/ControllerBinder.d.ts +0 -4
- package/framework/lib/server/ControllerBinder.js +0 -32
- package/framework/lib/server/CsrfMiddleware.d.ts +0 -2
- package/framework/lib/server/CsrfMiddleware.js +0 -34
- package/framework/lib/server/DynamicRouter.d.ts +0 -2
- package/framework/lib/server/DynamicRouter.js +0 -50
- package/framework/lib/server/ResponseHandlerMiddleware.d.ts +0 -27
- package/framework/lib/server/ResponseHandlerMiddleware.js +0 -30
- package/framework/lib/server/Router.d.ts +0 -94
- package/framework/lib/server/Router.js +0 -203
- package/framework/lib/server.d.ts +0 -6
- package/framework/lib/server.js +0 -28
- package/framework/lib/shared/ArcanaJSApp.d.ts +0 -11
- package/framework/lib/shared/ArcanaJSApp.js +0 -79
- package/framework/lib/shared/components/Body.d.ts +0 -6
- package/framework/lib/shared/components/Body.js +0 -11
- package/framework/lib/shared/components/Head.d.ts +0 -4
- package/framework/lib/shared/components/Head.js +0 -125
- package/framework/lib/shared/components/Link.d.ts +0 -6
- package/framework/lib/shared/components/Link.js +0 -17
- package/framework/lib/shared/components/NavLink.d.ts +0 -8
- package/framework/lib/shared/components/NavLink.js +0 -16
- package/framework/lib/shared/components/Page.d.ts +0 -6
- package/framework/lib/shared/components/Page.js +0 -16
- package/framework/lib/shared/context/HeadContext.d.ts +0 -6
- package/framework/lib/shared/context/HeadContext.js +0 -5
- package/framework/lib/shared/context/PageContext.d.ts +0 -1
- package/framework/lib/shared/context/PageContext.js +0 -5
- package/framework/lib/shared/context/RouterContext.d.ts +0 -13
- package/framework/lib/shared/context/RouterContext.js +0 -13
- package/framework/lib/shared/core/ArcanaJSApp.d.ts +0 -13
- package/framework/lib/shared/core/ArcanaJSApp.js +0 -98
- package/framework/lib/shared/hooks/useDynamicComponents.d.ts +0 -1
- package/framework/lib/shared/hooks/useDynamicComponents.js +0 -20
- package/framework/lib/shared/hooks/useHead.d.ts +0 -1
- package/framework/lib/shared/hooks/useHead.js +0 -7
- package/framework/lib/shared/hooks/useLocation.d.ts +0 -5
- package/framework/lib/shared/hooks/useLocation.js +0 -13
- package/framework/lib/shared/hooks/usePage.d.ts +0 -1
- package/framework/lib/shared/hooks/usePage.js +0 -7
- package/framework/lib/shared/hooks/useParams.d.ts +0 -1
- package/framework/lib/shared/hooks/useParams.js +0 -13
- package/framework/lib/shared/hooks/useQuery.d.ts +0 -1
- package/framework/lib/shared/hooks/useQuery.js +0 -9
- package/framework/lib/shared/hooks/useRouter.d.ts +0 -1
- package/framework/lib/shared/hooks/useRouter.js +0 -13
- package/framework/lib/shared/utils/createSingletonContext.d.ts +0 -11
- package/framework/lib/shared/utils/createSingletonContext.js +0 -21
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ArcanaJSApp = void 0;
|
|
37
|
-
const react_1 = __importStar(require("react"));
|
|
38
|
-
const Page_1 = require("./components/Page");
|
|
39
|
-
const RouterContext_1 = require("./context/RouterContext");
|
|
40
|
-
const ArcanaJSApp = ({ initialPage, initialData, initialUrl, views, layout: Layout, }) => {
|
|
41
|
-
const [page, setPage] = (0, react_1.useState)(initialPage);
|
|
42
|
-
const [data, setData] = (0, react_1.useState)(initialData);
|
|
43
|
-
const [url, setUrl] = (0, react_1.useState)(initialUrl ||
|
|
44
|
-
(typeof window !== "undefined" ? window.location.pathname : "/"));
|
|
45
|
-
(0, react_1.useEffect)(() => {
|
|
46
|
-
const handlePopState = (event) => {
|
|
47
|
-
if (event.state) {
|
|
48
|
-
setPage(event.state.page);
|
|
49
|
-
setData(event.state.data);
|
|
50
|
-
setUrl(window.location.pathname);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
window.addEventListener("popstate", handlePopState);
|
|
54
|
-
return () => window.removeEventListener("popstate", handlePopState);
|
|
55
|
-
}, []);
|
|
56
|
-
const navigateTo = async (newUrl) => {
|
|
57
|
-
try {
|
|
58
|
-
const response = await fetch(newUrl, {
|
|
59
|
-
headers: { "x-arcanajs-request": "true" },
|
|
60
|
-
});
|
|
61
|
-
const json = await response.json();
|
|
62
|
-
setPage(json.page);
|
|
63
|
-
setData(json.data);
|
|
64
|
-
setUrl(newUrl);
|
|
65
|
-
window.history.pushState({ page: json.page, data: json.data }, "", newUrl);
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
console.error("Navigation failed", error);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
const renderPage = () => {
|
|
72
|
-
const Component = views[page] || views["NotFoundPage"] || (() => react_1.default.createElement("div", null, "404 Not Found"));
|
|
73
|
-
return (react_1.default.createElement(Page_1.Page, { data: data },
|
|
74
|
-
react_1.default.createElement(Component, { data: data, navigateTo: navigateTo })));
|
|
75
|
-
};
|
|
76
|
-
const content = renderPage();
|
|
77
|
-
return (react_1.default.createElement(RouterContext_1.RouterProvider, { value: { navigateTo, currentPage: page, currentUrl: url, params: {} } }, Layout ? react_1.default.createElement(Layout, null, content) : react_1.default.createElement(react_1.default.Fragment, null, content)));
|
|
78
|
-
};
|
|
79
|
-
exports.ArcanaJSApp = ArcanaJSApp;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Body = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const Body = ({ children }) => {
|
|
9
|
-
return react_1.default.createElement(react_1.default.Fragment, null, children);
|
|
10
|
-
};
|
|
11
|
-
exports.Body = Body;
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.Head = void 0;
|
|
37
|
-
const react_1 = __importStar(require("react"));
|
|
38
|
-
const useHead_1 = require("../hooks/useHead");
|
|
39
|
-
const Head = ({ children }) => {
|
|
40
|
-
const headManager = (0, useHead_1.useHead)();
|
|
41
|
-
// Server-side: Push tags to context
|
|
42
|
-
if (typeof window === "undefined" && headManager) {
|
|
43
|
-
react_1.default.Children.forEach(children, (child) => {
|
|
44
|
-
if (react_1.default.isValidElement(child)) {
|
|
45
|
-
headManager.push(react_1.default.cloneElement(child, {
|
|
46
|
-
"data-arcanajs-head": "true",
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
// Client-side: Update DOM
|
|
52
|
-
(0, react_1.useEffect)(() => {
|
|
53
|
-
const managedElements = [];
|
|
54
|
-
react_1.default.Children.forEach(children, (child) => {
|
|
55
|
-
if (react_1.default.isValidElement(child)) {
|
|
56
|
-
const reactElement = child;
|
|
57
|
-
if (reactElement.type === "title") {
|
|
58
|
-
document.title = reactElement.props.children;
|
|
59
|
-
}
|
|
60
|
-
else if (reactElement.type === "meta") {
|
|
61
|
-
const props = reactElement.props;
|
|
62
|
-
// Try to find existing meta tag
|
|
63
|
-
let selector = "meta";
|
|
64
|
-
if (props.name)
|
|
65
|
-
selector += `[name="${props.name}"]`;
|
|
66
|
-
if (props.property)
|
|
67
|
-
selector += `[property="${props.property}"]`;
|
|
68
|
-
// Only select if we have a specific identifier
|
|
69
|
-
if (props.name || props.property) {
|
|
70
|
-
let element = document.querySelector(selector + '[data-arcanajs-head="true"]') || document.querySelector(selector);
|
|
71
|
-
if (element) {
|
|
72
|
-
// Update existing
|
|
73
|
-
element.setAttribute("content", props.content);
|
|
74
|
-
element.setAttribute("data-arcanajs-head", "true");
|
|
75
|
-
managedElements.push(element);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
// Create new
|
|
79
|
-
const newMeta = document.createElement("meta");
|
|
80
|
-
Object.keys(props).forEach((key) => {
|
|
81
|
-
newMeta.setAttribute(key, props[key]);
|
|
82
|
-
});
|
|
83
|
-
newMeta.setAttribute("data-arcanajs-head", "true");
|
|
84
|
-
document.head.appendChild(newMeta);
|
|
85
|
-
managedElements.push(newMeta);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else if (reactElement.type === "link") {
|
|
90
|
-
const props = reactElement.props;
|
|
91
|
-
let selector = "link";
|
|
92
|
-
if (props.rel)
|
|
93
|
-
selector += `[rel="${props.rel}"]`;
|
|
94
|
-
if (props.href)
|
|
95
|
-
selector += `[href="${props.href}"]`;
|
|
96
|
-
let element = document.querySelector(selector + '[data-arcanajs-head="true"]') ||
|
|
97
|
-
document.querySelector(selector);
|
|
98
|
-
if (element) {
|
|
99
|
-
element.setAttribute("data-arcanajs-head", "true");
|
|
100
|
-
managedElements.push(element);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
const newLink = document.createElement("link");
|
|
104
|
-
Object.keys(props).forEach((key) => {
|
|
105
|
-
newLink.setAttribute(key, props[key]);
|
|
106
|
-
});
|
|
107
|
-
newLink.setAttribute("data-arcanajs-head", "true");
|
|
108
|
-
document.head.appendChild(newLink);
|
|
109
|
-
managedElements.push(newLink);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
return () => {
|
|
115
|
-
// Cleanup managed elements
|
|
116
|
-
managedElements.forEach((el) => {
|
|
117
|
-
// We remove the element to ensure clean state for the next page
|
|
118
|
-
// Note: This might cause a momentary flicker if the next page re-adds it immediately
|
|
119
|
-
el.remove();
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
}, [children]);
|
|
123
|
-
return null;
|
|
124
|
-
};
|
|
125
|
-
exports.Head = Head;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Link = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const useRouter_1 = require("../hooks/useRouter");
|
|
9
|
-
const Link = ({ href, children, ...props }) => {
|
|
10
|
-
const { navigateTo } = (0, useRouter_1.useRouter)();
|
|
11
|
-
const handleClick = (e) => {
|
|
12
|
-
e.preventDefault();
|
|
13
|
-
navigateTo(href);
|
|
14
|
-
};
|
|
15
|
-
return (react_1.default.createElement("a", { href: href, onClick: handleClick, ...props }, children));
|
|
16
|
-
};
|
|
17
|
-
exports.Link = Link;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.NavLink = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const Link_1 = require("./Link");
|
|
9
|
-
const useRouter_1 = require("../hooks/useRouter");
|
|
10
|
-
const NavLink = ({ href, activeClassName = "active", className = "", exact = false, children, ...props }) => {
|
|
11
|
-
const { currentUrl } = (0, useRouter_1.useRouter)();
|
|
12
|
-
const isActive = exact ? currentUrl === href : currentUrl.startsWith(href);
|
|
13
|
-
const combinedClassName = `${className} ${isActive ? activeClassName : ""}`.trim();
|
|
14
|
-
return (react_1.default.createElement(Link_1.Link, { href: href, className: combinedClassName, ...props }, children));
|
|
15
|
-
};
|
|
16
|
-
exports.NavLink = NavLink;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Page = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const PageContext_1 = require("../context/PageContext");
|
|
9
|
-
const Head_1 = require("./Head");
|
|
10
|
-
const Page = ({ data, title, children }) => {
|
|
11
|
-
return (react_1.default.createElement(PageContext_1.PageContext.Provider, { value: data },
|
|
12
|
-
title && (react_1.default.createElement(Head_1.Head, null,
|
|
13
|
-
react_1.default.createElement("title", null, title))),
|
|
14
|
-
children));
|
|
15
|
-
};
|
|
16
|
-
exports.Page = Page;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HeadContext = void 0;
|
|
4
|
-
const createSingletonContext_1 = require("../utils/createSingletonContext");
|
|
5
|
-
exports.HeadContext = (0, createSingletonContext_1.createSingletonContext)("HeadContext", null);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const PageContext: import("react").Context<any>;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PageContext = void 0;
|
|
4
|
-
const createSingletonContext_1 = require("../utils/createSingletonContext");
|
|
5
|
-
exports.PageContext = (0, createSingletonContext_1.createSingletonContext)("PageContext", null);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
export interface RouterContextType {
|
|
3
|
-
navigateTo: (url: string) => void;
|
|
4
|
-
currentPage: string;
|
|
5
|
-
currentUrl: string;
|
|
6
|
-
params: Record<string, string>;
|
|
7
|
-
csrfToken?: string;
|
|
8
|
-
}
|
|
9
|
-
export declare const RouterContext: React.Context<RouterContextType | null>;
|
|
10
|
-
export declare const RouterProvider: React.FC<{
|
|
11
|
-
value: RouterContextType;
|
|
12
|
-
children: React.ReactNode;
|
|
13
|
-
}>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.RouterProvider = exports.RouterContext = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const createSingletonContext_1 = require("../utils/createSingletonContext");
|
|
9
|
-
exports.RouterContext = (0, createSingletonContext_1.createSingletonContext)("RouterContext", null);
|
|
10
|
-
const RouterProvider = ({ value, children }) => {
|
|
11
|
-
return (react_1.default.createElement(exports.RouterContext.Provider, { value: value }, children));
|
|
12
|
-
};
|
|
13
|
-
exports.RouterProvider = RouterProvider;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
export interface ArcanaJSAppProps {
|
|
3
|
-
initialPage: string;
|
|
4
|
-
initialData: any;
|
|
5
|
-
initialParams?: Record<string, string>;
|
|
6
|
-
initialUrl?: string;
|
|
7
|
-
csrfToken?: string;
|
|
8
|
-
views: Record<string, React.FC<any>>;
|
|
9
|
-
layout?: React.FC<{
|
|
10
|
-
children: React.ReactNode;
|
|
11
|
-
}>;
|
|
12
|
-
}
|
|
13
|
-
export declare const ArcanaJSApp: React.FC<ArcanaJSAppProps>;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ArcanaJSApp = void 0;
|
|
37
|
-
const react_1 = __importStar(require("react"));
|
|
38
|
-
const Page_1 = require("../components/Page");
|
|
39
|
-
const RouterContext_1 = require("../context/RouterContext");
|
|
40
|
-
const ArcanaJSApp = ({ initialPage, initialData, initialParams = {}, initialUrl, csrfToken, views, layout: Layout, }) => {
|
|
41
|
-
const [page, setPage] = (0, react_1.useState)(initialPage);
|
|
42
|
-
const [data, setData] = (0, react_1.useState)(initialData);
|
|
43
|
-
const [params, setParams] = (0, react_1.useState)(initialParams);
|
|
44
|
-
const [url, setUrl] = (0, react_1.useState)(initialUrl ||
|
|
45
|
-
(typeof window !== "undefined" ? window.location.pathname : "/"));
|
|
46
|
-
(0, react_1.useEffect)(() => {
|
|
47
|
-
const handlePopState = (event) => {
|
|
48
|
-
if (event.state) {
|
|
49
|
-
setPage(event.state.page);
|
|
50
|
-
setData(event.state.data);
|
|
51
|
-
setParams(event.state.params || {});
|
|
52
|
-
setUrl(window.location.pathname);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
window.addEventListener("popstate", handlePopState);
|
|
56
|
-
return () => window.removeEventListener("popstate", handlePopState);
|
|
57
|
-
}, []);
|
|
58
|
-
const navigateTo = async (newUrl) => {
|
|
59
|
-
try {
|
|
60
|
-
const response = await fetch(newUrl, {
|
|
61
|
-
headers: { "x-arcanajs-request": "true" },
|
|
62
|
-
});
|
|
63
|
-
if (!response.ok) {
|
|
64
|
-
if (response.status === 404) {
|
|
65
|
-
setPage("NotFoundPage");
|
|
66
|
-
setUrl(newUrl);
|
|
67
|
-
window.history.pushState({ page: "NotFoundPage", data: {} }, "", newUrl);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
throw new Error(`Navigation failed: ${response.status} ${response.statusText}`);
|
|
71
|
-
}
|
|
72
|
-
const json = await response.json();
|
|
73
|
-
window.history.pushState({ page: json.page, data: json.data, params: json.params }, "", newUrl);
|
|
74
|
-
setPage(json.page);
|
|
75
|
-
setData(json.data);
|
|
76
|
-
setParams(json.params || {});
|
|
77
|
-
setUrl(newUrl);
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
console.error("Navigation failed", error);
|
|
81
|
-
// Optionally set an error state here to show a UI toast or error page
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const renderPage = () => {
|
|
85
|
-
const Component = views[page] || views["NotFoundPage"] || (() => react_1.default.createElement("div", null, "404 Not Found"));
|
|
86
|
-
return (react_1.default.createElement(Page_1.Page, { data: data },
|
|
87
|
-
react_1.default.createElement(Component, { data: data, navigateTo: navigateTo, params: params })));
|
|
88
|
-
};
|
|
89
|
-
const content = renderPage();
|
|
90
|
-
return (react_1.default.createElement(RouterContext_1.RouterProvider, { value: {
|
|
91
|
-
navigateTo,
|
|
92
|
-
currentPage: page,
|
|
93
|
-
currentUrl: url,
|
|
94
|
-
params,
|
|
95
|
-
csrfToken,
|
|
96
|
-
} }, Layout ? react_1.default.createElement(Layout, null, content) : react_1.default.createElement(react_1.default.Fragment, null, content)));
|
|
97
|
-
};
|
|
98
|
-
exports.ArcanaJSApp = ArcanaJSApp;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useDynamicComponents: (loader: () => Promise<any>) => any;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useDynamicComponents = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const useDynamicComponents = (loader) => {
|
|
6
|
-
const [component, setComponent] = (0, react_1.useState)(null);
|
|
7
|
-
(0, react_1.useEffect)(() => {
|
|
8
|
-
let mounted = true;
|
|
9
|
-
loader().then((mod) => {
|
|
10
|
-
if (mounted) {
|
|
11
|
-
setComponent(mod.default || mod);
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
return () => {
|
|
15
|
-
mounted = false;
|
|
16
|
-
};
|
|
17
|
-
}, []); // loader dependency omitted to avoid loops if loader is inline
|
|
18
|
-
return component;
|
|
19
|
-
};
|
|
20
|
-
exports.useDynamicComponents = useDynamicComponents;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useHead: () => import("../context/HeadContext").HeadManager | null;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useHead = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const HeadContext_1 = require("../context/HeadContext");
|
|
6
|
-
const useHead = () => (0, react_1.useContext)(HeadContext_1.HeadContext);
|
|
7
|
-
exports.useHead = useHead;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useLocation = void 0;
|
|
4
|
-
const useRouter_1 = require("./useRouter");
|
|
5
|
-
const useLocation = () => {
|
|
6
|
-
const { currentUrl } = (0, useRouter_1.useRouter)();
|
|
7
|
-
return {
|
|
8
|
-
pathname: currentUrl,
|
|
9
|
-
search: typeof window !== "undefined" ? window.location.search : "",
|
|
10
|
-
hash: typeof window !== "undefined" ? window.location.hash : "",
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
exports.useLocation = useLocation;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const usePage: <T = any>() => T;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usePage = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const PageContext_1 = require("../context/PageContext");
|
|
6
|
-
const usePage = () => (0, react_1.useContext)(PageContext_1.PageContext);
|
|
7
|
-
exports.usePage = usePage;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useParams: () => Record<string, string>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useParams = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const RouterContext_1 = require("../context/RouterContext");
|
|
6
|
-
const useParams = () => {
|
|
7
|
-
const context = (0, react_1.useContext)(RouterContext_1.RouterContext);
|
|
8
|
-
if (!context) {
|
|
9
|
-
throw new Error("useParams must be used within an ArcanaJSApp");
|
|
10
|
-
}
|
|
11
|
-
return context.params;
|
|
12
|
-
};
|
|
13
|
-
exports.useParams = useParams;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useQuery: () => URLSearchParams;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useQuery = void 0;
|
|
4
|
-
const useLocation_1 = require("./useLocation");
|
|
5
|
-
const useQuery = () => {
|
|
6
|
-
const { search } = (0, useLocation_1.useLocation)();
|
|
7
|
-
return new URLSearchParams(search);
|
|
8
|
-
};
|
|
9
|
-
exports.useQuery = useQuery;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useRouter: () => import("../context/RouterContext").RouterContextType;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useRouter = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const RouterContext_1 = require("../context/RouterContext");
|
|
6
|
-
const useRouter = () => {
|
|
7
|
-
const context = (0, react_1.useContext)(RouterContext_1.RouterContext);
|
|
8
|
-
if (!context) {
|
|
9
|
-
throw new Error("useRouter must be used within an ArcanaJSApp");
|
|
10
|
-
}
|
|
11
|
-
return context;
|
|
12
|
-
};
|
|
13
|
-
exports.useRouter = useRouter;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
/**
|
|
3
|
-
* Creates a React Context that persists across multiple module loads (Webpack bundles vs Node require).
|
|
4
|
-
* This is essential for SSR applications where the server bundle and dynamically loaded views
|
|
5
|
-
* might reference different instances of the "same" context module.
|
|
6
|
-
*
|
|
7
|
-
* @param key A unique string key to identify this context globally
|
|
8
|
-
* @param defaultValue The default value for the context
|
|
9
|
-
* @returns A React Context instance (singleton)
|
|
10
|
-
*/
|
|
11
|
-
export declare function createSingletonContext<T>(key: string, defaultValue: T): React.Context<T>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSingletonContext = createSingletonContext;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
/**
|
|
6
|
-
* Creates a React Context that persists across multiple module loads (Webpack bundles vs Node require).
|
|
7
|
-
* This is essential for SSR applications where the server bundle and dynamically loaded views
|
|
8
|
-
* might reference different instances of the "same" context module.
|
|
9
|
-
*
|
|
10
|
-
* @param key A unique string key to identify this context globally
|
|
11
|
-
* @param defaultValue The default value for the context
|
|
12
|
-
* @returns A React Context instance (singleton)
|
|
13
|
-
*/
|
|
14
|
-
function createSingletonContext(key, defaultValue) {
|
|
15
|
-
const globalAny = global;
|
|
16
|
-
const symbolKey = Symbol.for(`ARCANAJS_CONTEXT_${key}`);
|
|
17
|
-
if (!globalAny[symbolKey]) {
|
|
18
|
-
globalAny[symbolKey] = (0, react_1.createContext)(defaultValue);
|
|
19
|
-
}
|
|
20
|
-
return globalAny[symbolKey];
|
|
21
|
-
}
|