@gyoll/adapter-react-router-dom 0.1.0
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/build-output/index.cjs +91 -0
- package/build-output/index.d.ts +17 -0
- package/build-output/index.js +61 -0
- package/package.json +50 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// code/index.js
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
reactRouterAdapter: () => reactRouterAdapter
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
var import_react = __toESM(require("react"), 1);
|
|
36
|
+
var import_react_router_dom = require("react-router-dom");
|
|
37
|
+
function transformRoutes(routes) {
|
|
38
|
+
return routes.map((route) => {
|
|
39
|
+
const routeObj = {
|
|
40
|
+
path: route.path
|
|
41
|
+
};
|
|
42
|
+
if (route.component || route.layout || route.error) {
|
|
43
|
+
routeObj.lazy = async () => {
|
|
44
|
+
const result = {};
|
|
45
|
+
const [componentMod, layoutMod, errorMod] = await Promise.all([
|
|
46
|
+
route.component ? route.component() : null,
|
|
47
|
+
route.layout ? route.layout() : null,
|
|
48
|
+
route.error ? route.error() : null
|
|
49
|
+
]);
|
|
50
|
+
if (componentMod || layoutMod) {
|
|
51
|
+
const ComponentInner = componentMod && componentMod.default;
|
|
52
|
+
const LayoutOuter = layoutMod && layoutMod.default;
|
|
53
|
+
if (ComponentInner && LayoutOuter) {
|
|
54
|
+
result.Component = () => import_react.default.createElement(
|
|
55
|
+
LayoutOuter,
|
|
56
|
+
null,
|
|
57
|
+
import_react.default.createElement(ComponentInner)
|
|
58
|
+
);
|
|
59
|
+
} else {
|
|
60
|
+
result.Component = LayoutOuter || ComponentInner;
|
|
61
|
+
}
|
|
62
|
+
if (componentMod?.loader) result.loader = componentMod.loader;
|
|
63
|
+
if (componentMod?.action) result.action = componentMod.action;
|
|
64
|
+
}
|
|
65
|
+
if (errorMod) {
|
|
66
|
+
result.ErrorBoundary = errorMod.default;
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (route.children && route.children.length > 0) {
|
|
72
|
+
routeObj.children = transformRoutes(route.children);
|
|
73
|
+
}
|
|
74
|
+
return routeObj;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
var reactRouterAdapter = {
|
|
78
|
+
/**
|
|
79
|
+
* Creates a React Router instance
|
|
80
|
+
* @param {Array} routes - Transformed routes
|
|
81
|
+
* @param {object} options - Router options
|
|
82
|
+
* @returns {object} Router instance
|
|
83
|
+
*/
|
|
84
|
+
createRouter(routes, options = {}) {
|
|
85
|
+
return (0, import_react_router_dom.createBrowserRouter)(routes, options);
|
|
86
|
+
},
|
|
87
|
+
/**
|
|
88
|
+
* Transforms routes to React Router format
|
|
89
|
+
*/
|
|
90
|
+
transformRoutes
|
|
91
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export namespace reactRouterAdapter {
|
|
2
|
+
/**
|
|
3
|
+
* Creates a React Router instance
|
|
4
|
+
* @param {Array} routes - Transformed routes
|
|
5
|
+
* @param {object} options - Router options
|
|
6
|
+
* @returns {object} Router instance
|
|
7
|
+
*/
|
|
8
|
+
export function createRouter(routes: any[], options?: object): object;
|
|
9
|
+
export { transformRoutes };
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Transforms file-routes format to React Router format
|
|
13
|
+
* @param {Array} routes - Routes from manifest
|
|
14
|
+
* @returns {Array} React Router route objects
|
|
15
|
+
*/
|
|
16
|
+
declare function transformRoutes(routes: any[]): any[];
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// code/index.js
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { createBrowserRouter } from "react-router-dom";
|
|
4
|
+
function transformRoutes(routes) {
|
|
5
|
+
return routes.map((route) => {
|
|
6
|
+
const routeObj = {
|
|
7
|
+
path: route.path
|
|
8
|
+
};
|
|
9
|
+
if (route.component || route.layout || route.error) {
|
|
10
|
+
routeObj.lazy = async () => {
|
|
11
|
+
const result = {};
|
|
12
|
+
const [componentMod, layoutMod, errorMod] = await Promise.all([
|
|
13
|
+
route.component ? route.component() : null,
|
|
14
|
+
route.layout ? route.layout() : null,
|
|
15
|
+
route.error ? route.error() : null
|
|
16
|
+
]);
|
|
17
|
+
if (componentMod || layoutMod) {
|
|
18
|
+
const ComponentInner = componentMod && componentMod.default;
|
|
19
|
+
const LayoutOuter = layoutMod && layoutMod.default;
|
|
20
|
+
if (ComponentInner && LayoutOuter) {
|
|
21
|
+
result.Component = () => React.createElement(
|
|
22
|
+
LayoutOuter,
|
|
23
|
+
null,
|
|
24
|
+
React.createElement(ComponentInner)
|
|
25
|
+
);
|
|
26
|
+
} else {
|
|
27
|
+
result.Component = LayoutOuter || ComponentInner;
|
|
28
|
+
}
|
|
29
|
+
if (componentMod?.loader) result.loader = componentMod.loader;
|
|
30
|
+
if (componentMod?.action) result.action = componentMod.action;
|
|
31
|
+
}
|
|
32
|
+
if (errorMod) {
|
|
33
|
+
result.ErrorBoundary = errorMod.default;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (route.children && route.children.length > 0) {
|
|
39
|
+
routeObj.children = transformRoutes(route.children);
|
|
40
|
+
}
|
|
41
|
+
return routeObj;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
var reactRouterAdapter = {
|
|
45
|
+
/**
|
|
46
|
+
* Creates a React Router instance
|
|
47
|
+
* @param {Array} routes - Transformed routes
|
|
48
|
+
* @param {object} options - Router options
|
|
49
|
+
* @returns {object} Router instance
|
|
50
|
+
*/
|
|
51
|
+
createRouter(routes, options = {}) {
|
|
52
|
+
return createBrowserRouter(routes, options);
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* Transforms routes to React Router format
|
|
56
|
+
*/
|
|
57
|
+
transformRoutes
|
|
58
|
+
};
|
|
59
|
+
export {
|
|
60
|
+
reactRouterAdapter
|
|
61
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gyoll/adapter-react-router-dom",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "React Router DOM adapter for Gyoll file-based routing",
|
|
6
|
+
"main": "./build-output/index.cjs",
|
|
7
|
+
"module": "./build-output/index.js",
|
|
8
|
+
"types": "./build-output/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./build-output/index.d.ts",
|
|
12
|
+
"import": "./build-output/index.js",
|
|
13
|
+
"require": "./build-output/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"build-output/",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"routing",
|
|
23
|
+
"react-router",
|
|
24
|
+
"react",
|
|
25
|
+
"adapter",
|
|
26
|
+
"gyoll"
|
|
27
|
+
],
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/your-org/gyoll.git",
|
|
31
|
+
"directory": "adapters-react-router-dom"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@gyoll/runtime": "^0.1.0",
|
|
35
|
+
"react": "^18.0.0",
|
|
36
|
+
"react-router-dom": "^6.0.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"typescript": "^5.9.3"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "node build.js",
|
|
46
|
+
"types": "tsc --declaration --emitDeclarationOnly --outDir build-output",
|
|
47
|
+
"test:unit": "vitest run --dir tests/unit",
|
|
48
|
+
"test:integration": "vitest run --dir tests/integration"
|
|
49
|
+
}
|
|
50
|
+
}
|