arcanajs 2.5.0 → 2.5.2
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/framework/cli/index.d.ts +1 -0
- package/framework/cli/index.js +204 -0
- package/framework/cli/templates.d.ts +6 -0
- package/framework/cli/templates.js +60 -0
- package/framework/cli/webpack.config.d.ts +3 -0
- package/framework/cli/webpack.config.js +310 -0
- package/framework/lib/client/index.d.ts +59 -0
- package/framework/lib/client/index.js +97 -0
- package/framework/lib/config/index.d.ts +46 -0
- package/framework/lib/config/index.js +115 -0
- package/framework/lib/global.d.ts +65 -0
- package/framework/lib/index.d.ts +19 -0
- package/framework/lib/index.js +59 -0
- package/framework/lib/server/ArcanaJSMiddleware.d.ts +24 -0
- package/framework/lib/server/ArcanaJSMiddleware.js +114 -0
- package/framework/lib/server/ArcanaJSServer.d.ts +55 -0
- package/framework/lib/server/ArcanaJSServer.js +441 -0
- package/framework/lib/server/ControllerBinder.d.ts +4 -0
- package/framework/lib/server/ControllerBinder.js +32 -0
- package/framework/lib/server/CsrfMiddleware.d.ts +2 -0
- package/framework/lib/server/CsrfMiddleware.js +34 -0
- package/framework/lib/server/DynamicRouter.d.ts +2 -0
- package/framework/lib/server/DynamicRouter.js +50 -0
- package/framework/lib/server/ResponseHandlerMiddleware.d.ts +27 -0
- package/framework/lib/server/ResponseHandlerMiddleware.js +30 -0
- package/framework/lib/server/Router.d.ts +94 -0
- package/framework/lib/server/Router.js +203 -0
- package/framework/lib/server/default-index.html +12 -0
- package/framework/lib/server.d.ts +33 -0
- package/framework/lib/server.js +69 -0
- package/framework/lib/shared/components/Body.d.ts +6 -0
- package/framework/lib/shared/components/Body.js +8 -0
- package/framework/lib/shared/components/Head.d.ts +4 -0
- package/framework/lib/shared/components/Head.js +125 -0
- package/framework/lib/shared/components/Link.d.ts +7 -0
- package/framework/lib/shared/components/Link.js +27 -0
- package/framework/lib/shared/components/NavLink.d.ts +9 -0
- package/framework/lib/shared/components/NavLink.js +13 -0
- package/framework/lib/shared/components/Page.d.ts +6 -0
- package/framework/lib/shared/components/Page.js +10 -0
- package/framework/lib/shared/context/HeadContext.d.ts +6 -0
- package/framework/lib/shared/context/HeadContext.js +5 -0
- package/framework/lib/shared/context/PageContext.d.ts +1 -0
- package/framework/lib/shared/context/PageContext.js +5 -0
- package/framework/lib/shared/context/RouterContext.d.ts +15 -0
- package/framework/lib/shared/context/RouterContext.js +10 -0
- package/framework/lib/shared/core/ArcanaJSApp.d.ts +14 -0
- package/framework/lib/shared/core/ArcanaJSApp.js +153 -0
- package/framework/lib/shared/hooks/useHead.d.ts +1 -0
- package/framework/lib/shared/hooks/useHead.js +7 -0
- package/framework/lib/shared/hooks/useLocation.d.ts +5 -0
- package/framework/lib/shared/hooks/useLocation.js +13 -0
- package/framework/lib/shared/hooks/usePage.d.ts +1 -0
- package/framework/lib/shared/hooks/usePage.js +7 -0
- package/framework/lib/shared/hooks/useParams.d.ts +1 -0
- package/framework/lib/shared/hooks/useParams.js +13 -0
- package/framework/lib/shared/hooks/useQuery.d.ts +1 -0
- package/framework/lib/shared/hooks/useQuery.js +9 -0
- package/framework/lib/shared/hooks/useRouter.d.ts +1 -0
- package/framework/lib/shared/hooks/useRouter.js +13 -0
- package/framework/lib/shared/utils/createSingletonContext.d.ts +11 -0
- package/framework/lib/shared/utils/createSingletonContext.js +21 -0
- package/framework/lib/shared/views/ErrorPage.d.ts +7 -0
- package/framework/lib/shared/views/ErrorPage.js +12 -0
- package/framework/lib/shared/views/NotFoundPage.d.ts +5 -0
- package/framework/lib/shared/views/NotFoundPage.js +11 -0
- package/framework/lib/types.d.ts +174 -0
- package/framework/lib/types.js +8 -0
- package/framework/templates/arcanajs.config.ts +44 -0
- package/framework/templates/package.json +15 -0
- package/framework/templates/postcss.config.js +6 -0
- package/framework/templates/public/arcanajs.png +0 -0
- package/framework/templates/public/arcanajs.svg +12 -0
- package/framework/templates/public/favicon.ico +0 -0
- package/framework/templates/src/arcanajs.d.ts +8 -0
- package/framework/templates/src/client/globals.css +199 -0
- package/framework/templates/src/client/index.tsx +7 -0
- package/framework/templates/src/db/mongo.ts +10 -0
- package/framework/templates/src/db/mongoose.ts +12 -0
- package/framework/templates/src/db/mysql.ts +15 -0
- package/framework/templates/src/db/postgres.ts +8 -0
- package/framework/templates/src/server/controllers/HomeController.ts +7 -0
- package/framework/templates/src/server/controllers/UsersController.ts +37 -0
- package/framework/templates/src/server/index.ts +35 -0
- package/framework/templates/src/server/routes/api.ts +6 -0
- package/framework/templates/src/server/routes/web.ts +7 -0
- package/framework/templates/src/views/ErrorPage.tsx +136 -0
- package/framework/templates/src/views/HomePage.tsx +344 -0
- package/framework/templates/src/views/NotFoundPage.tsx +108 -0
- package/framework/templates/tsconfig.json +27 -0
- package/package.json +1 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import express, { Router as ExpressRouter, RequestHandler } from "express";
|
|
2
|
+
/**
|
|
3
|
+
* Provides Routing syntax for defining routes with prefixes, middlewares, and groups
|
|
4
|
+
*/
|
|
5
|
+
export declare class Router {
|
|
6
|
+
private router;
|
|
7
|
+
private middlewareStack;
|
|
8
|
+
private prefixStack;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Create a new router instance
|
|
12
|
+
*/
|
|
13
|
+
static create(): Router;
|
|
14
|
+
/**
|
|
15
|
+
* Add middleware to the current stack
|
|
16
|
+
*/
|
|
17
|
+
middleware(...middleware: RequestHandler[]): Router;
|
|
18
|
+
/**
|
|
19
|
+
* Add prefix to the current stack
|
|
20
|
+
*/
|
|
21
|
+
prefix(prefix: string): Router;
|
|
22
|
+
/**
|
|
23
|
+
* Create a route group
|
|
24
|
+
*/
|
|
25
|
+
group(callback: (router: Router) => void): Router;
|
|
26
|
+
/**
|
|
27
|
+
* Define a GET route
|
|
28
|
+
*/
|
|
29
|
+
get(path: string, ...args: any[]): Router;
|
|
30
|
+
/**
|
|
31
|
+
* Define a POST route
|
|
32
|
+
*/
|
|
33
|
+
post(path: string, ...args: any[]): Router;
|
|
34
|
+
/**
|
|
35
|
+
* Define a PUT route
|
|
36
|
+
*/
|
|
37
|
+
put(path: string, ...args: any[]): Router;
|
|
38
|
+
/**
|
|
39
|
+
* Define a DELETE route
|
|
40
|
+
*/
|
|
41
|
+
delete(path: string, ...args: any[]): Router;
|
|
42
|
+
/**
|
|
43
|
+
* Define a PATCH route
|
|
44
|
+
*/
|
|
45
|
+
patch(path: string, ...args: any[]): Router;
|
|
46
|
+
/**
|
|
47
|
+
* Define an OPTIONS route
|
|
48
|
+
*/
|
|
49
|
+
options(path: string, ...args: any[]): Router;
|
|
50
|
+
/**
|
|
51
|
+
* Get the underlying Express router
|
|
52
|
+
*/
|
|
53
|
+
getRouter(): ExpressRouter;
|
|
54
|
+
/**
|
|
55
|
+
* Mount this router to an Express app or router
|
|
56
|
+
*/
|
|
57
|
+
mount(app: express.Application | ExpressRouter, basePath?: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* Clone the current router instance
|
|
60
|
+
*/
|
|
61
|
+
private _clone;
|
|
62
|
+
/**
|
|
63
|
+
* Add a route to the router
|
|
64
|
+
*/
|
|
65
|
+
private _addRoute;
|
|
66
|
+
/**
|
|
67
|
+
* Build the full path with prefixes
|
|
68
|
+
*/
|
|
69
|
+
private _buildPath;
|
|
70
|
+
/**
|
|
71
|
+
* Build the route handler
|
|
72
|
+
*/
|
|
73
|
+
private _buildHandler;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Static Route class for ArcanaJS Routing
|
|
77
|
+
*/
|
|
78
|
+
export declare class Route {
|
|
79
|
+
private static _router;
|
|
80
|
+
static create(): Router;
|
|
81
|
+
static middleware(...middleware: RequestHandler[]): Router;
|
|
82
|
+
static prefix(prefix: string): Router;
|
|
83
|
+
static group(callback: (router: Router) => void): Router;
|
|
84
|
+
static get(path: string, ...args: any[]): Router;
|
|
85
|
+
static post(path: string, ...args: any[]): Router;
|
|
86
|
+
static put(path: string, ...args: any[]): Router;
|
|
87
|
+
static delete(path: string, ...args: any[]): Router;
|
|
88
|
+
static patch(path: string, ...args: any[]): Router;
|
|
89
|
+
static options(path: string, ...args: any[]): Router;
|
|
90
|
+
static getRouter(): ExpressRouter;
|
|
91
|
+
static mount(app: express.Application, basePath?: string): void;
|
|
92
|
+
static reset(): void;
|
|
93
|
+
}
|
|
94
|
+
export default Route;
|
|
@@ -0,0 +1,203 @@
|
|
|
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;
|
|
@@ -0,0 +1,12 @@
|
|
|
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>
|
|
@@ -0,0 +1,33 @@
|
|
|
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;
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
|
@@ -0,0 +1,125 @@
|
|
|
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;
|
|
@@ -0,0 +1,27 @@
|
|
|
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 } = (0, useRouter_1.useRouter)();
|
|
8
|
+
const isExternal = /^https?:\/\//.test(href);
|
|
9
|
+
const handleClick = (e) => {
|
|
10
|
+
e.preventDefault();
|
|
11
|
+
if (!isExternal) {
|
|
12
|
+
navigateTo(href);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
// Open external links in a new tab
|
|
16
|
+
window.open(href, "_blank", "noopener,noreferrer");
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const handleMouseEnter = () => {
|
|
20
|
+
if (prefetch && !isExternal) {
|
|
21
|
+
// Prefetch using HEAD request to warm cache
|
|
22
|
+
fetch(href, { method: "HEAD" }).catch(() => { });
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
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 }));
|
|
26
|
+
};
|
|
27
|
+
exports.Link = Link;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface NavLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
3
|
+
href: string;
|
|
4
|
+
activeClassName?: string;
|
|
5
|
+
exact?: boolean;
|
|
6
|
+
prefetch?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const NavLink: React.FC<NavLinkProps>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
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;
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
@@ -0,0 +1,5 @@
|
|
|
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);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PageContext: import("react").Context<any>;
|
|
@@ -0,0 +1,5 @@
|
|
|
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);
|