arcanajs 2.6.0 → 3.0.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/README.md +7 -22
- package/bin/arcanajs.js +1 -1
- package/dist/arcanajs.client.js +2 -0
- package/dist/arcanajs.client.js.map +1 -0
- package/dist/arcanajs.js +2 -0
- package/dist/arcanajs.js.map +1 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -0
- package/{framework → dist}/lib/client/index.d.ts +6 -26
- package/{framework → dist}/lib/global.d.ts +6 -10
- package/dist/lib/index.client.d.ts +11 -0
- package/dist/lib/index.d.ts +38 -0
- package/{framework → dist}/lib/server/ArcanaJSServer.d.ts +4 -4
- package/dist/lib/server/DefaultTemplate.d.ts +1 -0
- package/{framework → dist}/lib/shared/components/Body.d.ts +2 -2
- package/{framework → dist}/lib/shared/components/Head.d.ts +2 -1
- package/{framework → dist}/lib/shared/components/Link.d.ts +2 -2
- package/{framework → dist}/lib/shared/components/NavLink.d.ts +2 -2
- package/{framework → dist}/lib/shared/components/Page.d.ts +2 -1
- package/{framework → dist}/lib/shared/hooks/useLocation.d.ts +2 -1
- package/dist/lib/shared/hooks/usePage.d.ts +2 -0
- package/dist/lib/shared/hooks/useParams.d.ts +2 -0
- package/dist/lib/shared/hooks/useQuery.d.ts +2 -0
- package/dist/lib/shared/hooks/useRouter.d.ts +2 -0
- package/package.json +26 -23
- package/framework/cli/index.js +0 -204
- package/framework/cli/templates.d.ts +0 -6
- package/framework/cli/templates.js +0 -62
- package/framework/cli/webpack.config.js +0 -310
- package/framework/lib/client/index.js +0 -97
- package/framework/lib/config/index.d.ts +0 -46
- package/framework/lib/config/index.js +0 -115
- package/framework/lib/index.d.ts +0 -19
- package/framework/lib/index.js +0 -59
- package/framework/lib/server/ArcanaJSMiddleware.js +0 -114
- package/framework/lib/server/ArcanaJSServer.js +0 -441
- package/framework/lib/server/ControllerBinder.js +0 -32
- package/framework/lib/server/CsrfMiddleware.js +0 -34
- package/framework/lib/server/DynamicRouter.js +0 -50
- package/framework/lib/server/ResponseHandlerMiddleware.js +0 -30
- package/framework/lib/server/Router.js +0 -203
- package/framework/lib/server/default-index.html +0 -12
- package/framework/lib/server.d.ts +0 -33
- package/framework/lib/server.js +0 -69
- package/framework/lib/shared/components/Body.js +0 -8
- package/framework/lib/shared/components/Head.js +0 -125
- package/framework/lib/shared/components/Link.js +0 -30
- package/framework/lib/shared/components/NavLink.js +0 -13
- package/framework/lib/shared/components/Page.js +0 -10
- package/framework/lib/shared/context/HeadContext.js +0 -5
- package/framework/lib/shared/context/PageContext.js +0 -6
- package/framework/lib/shared/context/RouterContext.js +0 -10
- package/framework/lib/shared/core/ArcanaJSApp.js +0 -194
- package/framework/lib/shared/hooks/useHead.js +0 -7
- 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.js +0 -21
- package/framework/lib/shared/views/ErrorPage.js +0 -12
- package/framework/lib/shared/views/NotFoundPage.js +0 -11
- package/framework/lib/types.d.ts +0 -174
- package/framework/lib/types.js +0 -8
- package/framework/templates/arcanajs.config.ts +0 -44
- package/framework/templates/package.json +0 -15
- package/framework/templates/postcss.config.js +0 -6
- package/framework/templates/public/arcanajs.png +0 -0
- package/framework/templates/public/arcanajs.svg +0 -12
- package/framework/templates/public/favicon.ico +0 -0
- package/framework/templates/src/arcanajs.d.ts +0 -8
- package/framework/templates/src/client/globals.css +0 -199
- package/framework/templates/src/client/index.tsx +0 -7
- package/framework/templates/src/db/mongo.ts +0 -10
- package/framework/templates/src/db/mongoose.ts +0 -12
- package/framework/templates/src/db/mysql.ts +0 -15
- package/framework/templates/src/db/postgres.ts +0 -8
- package/framework/templates/src/server/controllers/HomeController.ts +0 -19
- package/framework/templates/src/server/controllers/UsersController.ts +0 -37
- package/framework/templates/src/server/index.ts +0 -38
- package/framework/templates/src/server/routes/api.ts +0 -6
- package/framework/templates/src/server/routes/web.ts +0 -7
- package/framework/templates/src/types/HomePageData.ts +0 -11
- package/framework/templates/src/views/ErrorPage.tsx +0 -136
- package/framework/templates/src/views/HomePage.tsx +0 -369
- package/framework/templates/src/views/NotFoundPage.tsx +0 -108
- package/framework/templates/tsconfig.json +0 -27
- /package/{framework → dist}/cli/index.d.ts +0 -0
- /package/{framework → dist}/cli/webpack.config.d.ts +0 -0
- /package/{framework → dist}/lib/server/ArcanaJSMiddleware.d.ts +0 -0
- /package/{framework → dist}/lib/server/ControllerBinder.d.ts +0 -0
- /package/{framework → dist}/lib/server/CsrfMiddleware.d.ts +0 -0
- /package/{framework → dist}/lib/server/DynamicRouter.d.ts +0 -0
- /package/{framework → dist}/lib/server/ResponseHandlerMiddleware.d.ts +0 -0
- /package/{framework → dist}/lib/server/Router.d.ts +0 -0
- /package/{framework → dist}/lib/shared/context/HeadContext.d.ts +0 -0
- /package/{framework → dist}/lib/shared/context/PageContext.d.ts +0 -0
- /package/{framework → dist}/lib/shared/context/RouterContext.d.ts +0 -0
- /package/{framework → dist}/lib/shared/core/ArcanaJSApp.d.ts +0 -0
- /package/{framework → dist}/lib/shared/hooks/useHead.d.ts +0 -0
- /package/{framework → dist}/lib/shared/utils/createSingletonContext.d.ts +0 -0
- /package/{framework → dist}/lib/shared/views/ErrorPage.d.ts +0 -0
- /package/{framework → dist}/lib/shared/views/NotFoundPage.d.ts +0 -0
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDynamicRouter = void 0;
|
|
4
|
-
const createDynamicRouter = (views) => {
|
|
5
|
-
return (req, res, next) => {
|
|
6
|
-
// Remove leading slash
|
|
7
|
-
let path = req.path.substring(1);
|
|
8
|
-
// Handle root path mapping to "index" if not handled elsewhere
|
|
9
|
-
if (path === "") {
|
|
10
|
-
path = "index";
|
|
11
|
-
}
|
|
12
|
-
// 1. Exact match
|
|
13
|
-
if (views[path]) {
|
|
14
|
-
return res.renderPage(path, {});
|
|
15
|
-
}
|
|
16
|
-
// 2. Dynamic match
|
|
17
|
-
for (const viewName of Object.keys(views)) {
|
|
18
|
-
if (!viewName.includes("["))
|
|
19
|
-
continue;
|
|
20
|
-
// Convert view path to regex
|
|
21
|
-
// e.g., "users/[id]" -> "^users/([^/]+)$"
|
|
22
|
-
// We need to escape special regex characters first, but keep [ and ] for our logic
|
|
23
|
-
// Actually, simpler: split by '/' and match segments
|
|
24
|
-
const pageParts = viewName.split("/");
|
|
25
|
-
const pathParts = path.split("/");
|
|
26
|
-
if (pageParts.length !== pathParts.length)
|
|
27
|
-
continue;
|
|
28
|
-
let match = true;
|
|
29
|
-
const params = {};
|
|
30
|
-
for (let i = 0; i < pageParts.length; i++) {
|
|
31
|
-
const pagePart = pageParts[i];
|
|
32
|
-
const pathPart = pathParts[i];
|
|
33
|
-
if (pagePart.startsWith("[") && pagePart.endsWith("]")) {
|
|
34
|
-
const paramName = pagePart.slice(1, -1);
|
|
35
|
-
params[paramName] = pathPart;
|
|
36
|
-
}
|
|
37
|
-
else if (pagePart !== pathPart) {
|
|
38
|
-
match = false;
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (match) {
|
|
43
|
-
return res.renderPage(viewName, {}, params);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// If not found, pass to the next middleware (usually 404 handler)
|
|
47
|
-
next();
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
exports.createDynamicRouter = createDynamicRouter;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.responseHandler = void 0;
|
|
4
|
-
const responseHandler = (req, res, next) => {
|
|
5
|
-
res.success = (data = {}, message = "Success", status = 200) => {
|
|
6
|
-
return res.status(status).json({
|
|
7
|
-
success: true,
|
|
8
|
-
message,
|
|
9
|
-
data,
|
|
10
|
-
error: null,
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
res.error = (message = "Error", status = 500, error = null, data = null) => {
|
|
14
|
-
const errorResponse = error
|
|
15
|
-
? typeof error === "object" && error !== null
|
|
16
|
-
? error instanceof Error
|
|
17
|
-
? error.toString()
|
|
18
|
-
: error
|
|
19
|
-
: error.toString()
|
|
20
|
-
: null;
|
|
21
|
-
return res.status(status).json({
|
|
22
|
-
success: false,
|
|
23
|
-
message,
|
|
24
|
-
data,
|
|
25
|
-
error: errorResponse,
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
next();
|
|
29
|
-
};
|
|
30
|
-
exports.responseHandler = responseHandler;
|
|
@@ -1,203 +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.Route = exports.Router = void 0;
|
|
7
|
-
const express_1 = __importDefault(require("express"));
|
|
8
|
-
const ControllerBinder_1 = __importDefault(require("./ControllerBinder"));
|
|
9
|
-
/**
|
|
10
|
-
* Provides Routing syntax for defining routes with prefixes, middlewares, and groups
|
|
11
|
-
*/
|
|
12
|
-
class Router {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.router = express_1.default.Router();
|
|
15
|
-
this.middlewareStack = [];
|
|
16
|
-
this.prefixStack = [];
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Create a new router instance
|
|
20
|
-
*/
|
|
21
|
-
static create() {
|
|
22
|
-
return new Router();
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Add middleware to the current stack
|
|
26
|
-
*/
|
|
27
|
-
middleware(...middleware) {
|
|
28
|
-
const newRouter = this._clone();
|
|
29
|
-
newRouter.middlewareStack = [...this.middlewareStack, ...middleware];
|
|
30
|
-
return newRouter;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Add prefix to the current stack
|
|
34
|
-
*/
|
|
35
|
-
prefix(prefix) {
|
|
36
|
-
const newRouter = this._clone();
|
|
37
|
-
newRouter.prefixStack = [
|
|
38
|
-
...this.prefixStack,
|
|
39
|
-
prefix.replace(/^\/|\/$/g, ""),
|
|
40
|
-
];
|
|
41
|
-
return newRouter;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Create a route group
|
|
45
|
-
*/
|
|
46
|
-
group(callback) {
|
|
47
|
-
callback(this);
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Define a GET route
|
|
52
|
-
*/
|
|
53
|
-
get(path, ...args) {
|
|
54
|
-
const action = args.pop();
|
|
55
|
-
const middlewares = args;
|
|
56
|
-
return this._addRoute("get", path, action, middlewares);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Define a POST route
|
|
60
|
-
*/
|
|
61
|
-
post(path, ...args) {
|
|
62
|
-
const action = args.pop();
|
|
63
|
-
const middlewares = args;
|
|
64
|
-
return this._addRoute("post", path, action, middlewares);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Define a PUT route
|
|
68
|
-
*/
|
|
69
|
-
put(path, ...args) {
|
|
70
|
-
const action = args.pop();
|
|
71
|
-
const middlewares = args;
|
|
72
|
-
return this._addRoute("put", path, action, middlewares);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Define a DELETE route
|
|
76
|
-
*/
|
|
77
|
-
delete(path, ...args) {
|
|
78
|
-
const action = args.pop();
|
|
79
|
-
const middlewares = args;
|
|
80
|
-
return this._addRoute("delete", path, action, middlewares);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Define a PATCH route
|
|
84
|
-
*/
|
|
85
|
-
patch(path, ...args) {
|
|
86
|
-
const action = args.pop();
|
|
87
|
-
const middlewares = args;
|
|
88
|
-
return this._addRoute("patch", path, action, middlewares);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Define an OPTIONS route
|
|
92
|
-
*/
|
|
93
|
-
options(path, ...args) {
|
|
94
|
-
const action = args.pop();
|
|
95
|
-
const middlewares = args;
|
|
96
|
-
return this._addRoute("options", path, action, middlewares);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Get the underlying Express router
|
|
100
|
-
*/
|
|
101
|
-
getRouter() {
|
|
102
|
-
return this.router;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Mount this router to an Express app or router
|
|
106
|
-
*/
|
|
107
|
-
mount(app, basePath = "/") {
|
|
108
|
-
app.use(basePath, this.router);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Clone the current router instance
|
|
112
|
-
*/
|
|
113
|
-
_clone() {
|
|
114
|
-
const newRouter = new Router();
|
|
115
|
-
newRouter.router = this.router;
|
|
116
|
-
newRouter.middlewareStack = [...this.middlewareStack];
|
|
117
|
-
newRouter.prefixStack = [...this.prefixStack];
|
|
118
|
-
return newRouter;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Add a route to the router
|
|
122
|
-
*/
|
|
123
|
-
_addRoute(method, path, action, routeMiddlewares = []) {
|
|
124
|
-
const fullPath = this._buildPath(path);
|
|
125
|
-
const handler = this._buildHandler(action);
|
|
126
|
-
const flatMiddlewares = routeMiddlewares.flat(Infinity);
|
|
127
|
-
const middlewares = [...this.middlewareStack, ...flatMiddlewares, handler];
|
|
128
|
-
this.router[method](fullPath, ...middlewares);
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Build the full path with prefixes
|
|
133
|
-
*/
|
|
134
|
-
_buildPath(path) {
|
|
135
|
-
const cleanPath = path.replace(/^\//, "");
|
|
136
|
-
const prefixes = this.prefixStack.filter((p) => p !== "");
|
|
137
|
-
if (prefixes.length === 0) {
|
|
138
|
-
return `/${cleanPath}`;
|
|
139
|
-
}
|
|
140
|
-
return `/${prefixes.join("/")}/${cleanPath}`.replace(/\/+/g, "/");
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Build the route handler
|
|
144
|
-
*/
|
|
145
|
-
_buildHandler(action) {
|
|
146
|
-
if (typeof action === "function") {
|
|
147
|
-
return action;
|
|
148
|
-
}
|
|
149
|
-
if (Array.isArray(action) && action.length === 2) {
|
|
150
|
-
const [controller, method] = action;
|
|
151
|
-
return ControllerBinder_1.default.handle(controller, method);
|
|
152
|
-
}
|
|
153
|
-
throw new Error('Action must be a function or array [Controller, "method"]');
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
exports.Router = Router;
|
|
157
|
-
/**
|
|
158
|
-
* Static Route class for ArcanaJS Routing
|
|
159
|
-
*/
|
|
160
|
-
class Route {
|
|
161
|
-
static create() {
|
|
162
|
-
return Router.create();
|
|
163
|
-
}
|
|
164
|
-
static middleware(...middleware) {
|
|
165
|
-
return this._router.middleware(...middleware);
|
|
166
|
-
}
|
|
167
|
-
static prefix(prefix) {
|
|
168
|
-
return this._router.prefix(prefix);
|
|
169
|
-
}
|
|
170
|
-
static group(callback) {
|
|
171
|
-
return this._router.group(callback);
|
|
172
|
-
}
|
|
173
|
-
static get(path, ...args) {
|
|
174
|
-
return this._router.get(path, ...args);
|
|
175
|
-
}
|
|
176
|
-
static post(path, ...args) {
|
|
177
|
-
return this._router.post(path, ...args);
|
|
178
|
-
}
|
|
179
|
-
static put(path, ...args) {
|
|
180
|
-
return this._router.put(path, ...args);
|
|
181
|
-
}
|
|
182
|
-
static delete(path, ...args) {
|
|
183
|
-
return this._router.delete(path, ...args);
|
|
184
|
-
}
|
|
185
|
-
static patch(path, ...args) {
|
|
186
|
-
return this._router.patch(path, ...args);
|
|
187
|
-
}
|
|
188
|
-
static options(path, ...args) {
|
|
189
|
-
return this._router.options(path, ...args);
|
|
190
|
-
}
|
|
191
|
-
static getRouter() {
|
|
192
|
-
return this._router.getRouter();
|
|
193
|
-
}
|
|
194
|
-
static mount(app, basePath = "/") {
|
|
195
|
-
return this._router.mount(app, basePath);
|
|
196
|
-
}
|
|
197
|
-
static reset() {
|
|
198
|
-
this._router = new Router();
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
exports.Route = Route;
|
|
202
|
-
Route._router = new Router();
|
|
203
|
-
exports.default = Route;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<!--HEAD_CONTENT-->
|
|
7
|
-
</head>
|
|
8
|
-
<body>
|
|
9
|
-
<div id="root"><!--APP_CONTENT--></div>
|
|
10
|
-
<!--ARCANAJS_DATA_SCRIPT-->
|
|
11
|
-
</body>
|
|
12
|
-
</html>
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Express } from "express";
|
|
2
|
-
import { ArcanaJSConfig, ArcanaJSServer } from "./server/ArcanaJSServer";
|
|
3
|
-
export type { NextFunction, Request, RequestHandler, Response } from "express";
|
|
4
|
-
export * from "./server/ArcanaJSMiddleware";
|
|
5
|
-
export * from "./server/ArcanaJSServer";
|
|
6
|
-
export { default as ControllerBinder } from "./server/ControllerBinder";
|
|
7
|
-
export * from "./server/DynamicRouter";
|
|
8
|
-
export * from "./server/Router";
|
|
9
|
-
export { default as Route } from "./server/Router";
|
|
10
|
-
export * from "./server/CsrfMiddleware";
|
|
11
|
-
export * from "./server/ResponseHandlerMiddleware";
|
|
12
|
-
/**
|
|
13
|
-
* Create an ArcanaJS server with the given Express app
|
|
14
|
-
*
|
|
15
|
-
* @param app - Express application instance
|
|
16
|
-
* @param config - Optional ArcanaJS configuration
|
|
17
|
-
* @returns ArcanaJSServer instance
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import express from 'express';
|
|
22
|
-
* import { createArcanaServer } from 'arcanajs/server';
|
|
23
|
-
*
|
|
24
|
-
* const app = express();
|
|
25
|
-
* const server = createArcanaServer(app, {
|
|
26
|
-
* port: 3000,
|
|
27
|
-
* viewsDir: 'src/views',
|
|
28
|
-
* });
|
|
29
|
-
*
|
|
30
|
-
* server.start();
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare function createArcanaServer(app: Express, config?: Partial<ArcanaJSConfig>): ArcanaJSServer;
|
package/framework/lib/server.js
DELETED
|
@@ -1,69 +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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.Route = exports.ControllerBinder = void 0;
|
|
21
|
-
exports.createArcanaServer = createArcanaServer;
|
|
22
|
-
const ArcanaJSServer_1 = require("./server/ArcanaJSServer");
|
|
23
|
-
// ============================================================================
|
|
24
|
-
// Server Core Exports
|
|
25
|
-
// ============================================================================
|
|
26
|
-
__exportStar(require("./server/ArcanaJSMiddleware"), exports);
|
|
27
|
-
__exportStar(require("./server/ArcanaJSServer"), exports);
|
|
28
|
-
var ControllerBinder_1 = require("./server/ControllerBinder");
|
|
29
|
-
Object.defineProperty(exports, "ControllerBinder", { enumerable: true, get: function () { return __importDefault(ControllerBinder_1).default; } });
|
|
30
|
-
// ============================================================================
|
|
31
|
-
// Routing Exports
|
|
32
|
-
// ============================================================================
|
|
33
|
-
__exportStar(require("./server/DynamicRouter"), exports);
|
|
34
|
-
__exportStar(require("./server/Router"), exports);
|
|
35
|
-
var Router_1 = require("./server/Router");
|
|
36
|
-
Object.defineProperty(exports, "Route", { enumerable: true, get: function () { return __importDefault(Router_1).default; } });
|
|
37
|
-
// ============================================================================
|
|
38
|
-
// Middleware Exports
|
|
39
|
-
// ============================================================================
|
|
40
|
-
__exportStar(require("./server/CsrfMiddleware"), exports);
|
|
41
|
-
__exportStar(require("./server/ResponseHandlerMiddleware"), exports);
|
|
42
|
-
// ============================================================================
|
|
43
|
-
// Server Factory Function
|
|
44
|
-
// ============================================================================
|
|
45
|
-
/**
|
|
46
|
-
* Create an ArcanaJS server with the given Express app
|
|
47
|
-
*
|
|
48
|
-
* @param app - Express application instance
|
|
49
|
-
* @param config - Optional ArcanaJS configuration
|
|
50
|
-
* @returns ArcanaJSServer instance
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```typescript
|
|
54
|
-
* import express from 'express';
|
|
55
|
-
* import { createArcanaServer } from 'arcanajs/server';
|
|
56
|
-
*
|
|
57
|
-
* const app = express();
|
|
58
|
-
* const server = createArcanaServer(app, {
|
|
59
|
-
* port: 3000,
|
|
60
|
-
* viewsDir: 'src/views',
|
|
61
|
-
* });
|
|
62
|
-
*
|
|
63
|
-
* server.start();
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
function createArcanaServer(app, config) {
|
|
67
|
-
const server = new ArcanaJSServer_1.ArcanaJSServer({ ...config });
|
|
68
|
-
return server;
|
|
69
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Body = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const Body = ({ children }) => {
|
|
6
|
-
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
7
|
-
};
|
|
8
|
-
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,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Link = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const useRouter_1 = require("../hooks/useRouter");
|
|
6
|
-
const Link = ({ href, children, prefetch = false, ...props }) => {
|
|
7
|
-
const { navigateTo, navigateToAsync } = (0, useRouter_1.useRouter)();
|
|
8
|
-
const isExternal = /^https?:\/\//.test(href);
|
|
9
|
-
const handleClick = async (e) => {
|
|
10
|
-
e.preventDefault();
|
|
11
|
-
if (isExternal) {
|
|
12
|
-
// Open external links in a new tab
|
|
13
|
-
window.open(href, "_blank", "noopener,noreferrer");
|
|
14
|
-
}
|
|
15
|
-
else if (navigateToAsync) {
|
|
16
|
-
await navigateToAsync(href);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
navigateTo(href);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const handleMouseEnter = () => {
|
|
23
|
-
if (prefetch && !isExternal) {
|
|
24
|
-
// Prefetch using HEAD request to warm cache
|
|
25
|
-
fetch(href, { method: "HEAD" }).catch(() => { });
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
return ((0, jsx_runtime_1.jsx)("a", { href: href, onClick: handleClick, onMouseEnter: handleMouseEnter, target: isExternal ? "_blank" : undefined, rel: isExternal ? "noopener noreferrer" : undefined, ...props, children: children }));
|
|
29
|
-
};
|
|
30
|
-
exports.Link = Link;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NavLink = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const useRouter_1 = require("../hooks/useRouter");
|
|
6
|
-
const Link_1 = require("./Link");
|
|
7
|
-
const NavLink = ({ href, activeClassName = "active", className = "", exact = false, prefetch = false, children, ...props }) => {
|
|
8
|
-
const { currentUrl } = (0, useRouter_1.useRouter)();
|
|
9
|
-
const isActive = exact ? currentUrl === href : currentUrl.startsWith(href);
|
|
10
|
-
const combinedClassName = `${className} ${isActive ? activeClassName : ""}`.trim();
|
|
11
|
-
return ((0, jsx_runtime_1.jsx)(Link_1.Link, { href: href, className: combinedClassName, prefetch: prefetch, ...props, children: children }));
|
|
12
|
-
};
|
|
13
|
-
exports.NavLink = NavLink;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Page = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const PageContext_1 = require("../context/PageContext");
|
|
6
|
-
const Head_1 = require("./Head");
|
|
7
|
-
const Page = ({ data, title, children, }) => {
|
|
8
|
-
return ((0, jsx_runtime_1.jsxs)(PageContext_1.PageContext.Provider, { value: data, children: [title && ((0, jsx_runtime_1.jsx)(Head_1.Head, { children: (0, jsx_runtime_1.jsx)("title", { children: title }) })), children] }));
|
|
9
|
-
};
|
|
10
|
-
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,6 +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
|
-
// PageContext holds the page data (may be null before hydration).
|
|
6
|
-
exports.PageContext = (0, createSingletonContext_1.createSingletonContext)("PageContext", null);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RouterProvider = exports.RouterContext = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const createSingletonContext_1 = require("../utils/createSingletonContext");
|
|
6
|
-
exports.RouterContext = (0, createSingletonContext_1.createSingletonContext)("RouterContext", null);
|
|
7
|
-
const RouterProvider = ({ value, children }) => {
|
|
8
|
-
return ((0, jsx_runtime_1.jsx)(exports.RouterContext.Provider, { value: value, children: children }));
|
|
9
|
-
};
|
|
10
|
-
exports.RouterProvider = RouterProvider;
|