path-rush 1.3.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/LICENSE +21 -0
- package/README.md +195 -0
- package/dist/chunk-VBEFTPIV.mjs +517 -0
- package/dist/chunk-VBEFTPIV.mjs.map +1 -0
- package/dist/core.d.cts +2 -0
- package/dist/core.d.ts +2 -0
- package/dist/core.js +553 -0
- package/dist/core.js.map +1 -0
- package/dist/core.mjs +7 -0
- package/dist/core.mjs.map +1 -0
- package/dist/plugin.d.cts +106 -0
- package/dist/plugin.d.ts +106 -0
- package/dist/plugin.js +551 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugin.mjs +7 -0
- package/dist/plugin.mjs.map +1 -0
- package/dist/react.d.cts +35 -0
- package/dist/react.d.ts +35 -0
- package/dist/react.js +111 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +74 -0
- package/dist/react.mjs.map +1 -0
- package/package.json +104 -0
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
type RouterProviderProps = {
|
|
5
|
+
/**
|
|
6
|
+
* ⏳ Кастомный индикатор загрузки
|
|
7
|
+
*
|
|
8
|
+
* ▸ Компонент который показывается во время загрузки
|
|
9
|
+
*
|
|
10
|
+
* ▸ Если не указан - используется стандартный прелоадер
|
|
11
|
+
*
|
|
12
|
+
* @default
|
|
13
|
+
* <div>Loading...</div>
|
|
14
|
+
*/
|
|
15
|
+
preloader?: React.ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* 📍 Базовый путь для маршрутизации
|
|
18
|
+
*
|
|
19
|
+
* ▸ Используется для работы нескольких фронтендов на одном домене
|
|
20
|
+
*
|
|
21
|
+
* ▸ Переопределяет basePath из конфигурации плагина
|
|
22
|
+
*
|
|
23
|
+
* @example '/' - основной сайт
|
|
24
|
+
* @example '/admin' - админка на /admin/*
|
|
25
|
+
* @example '/app' - приложение на /app/*
|
|
26
|
+
*
|
|
27
|
+
* @default '/'
|
|
28
|
+
*/
|
|
29
|
+
basePath?: string;
|
|
30
|
+
children?: React.ReactNode;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
declare function RouterProvider({ children, preloader, basePath, }: Readonly<RouterProviderProps>): react_jsx_runtime.JSX.Element;
|
|
34
|
+
|
|
35
|
+
export { RouterProvider, type RouterProviderProps };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/react.ts
|
|
31
|
+
var react_exports = {};
|
|
32
|
+
__export(react_exports, {
|
|
33
|
+
RouterProvider: () => RouterProvider
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(react_exports);
|
|
36
|
+
|
|
37
|
+
// src/components/router-provider.tsx
|
|
38
|
+
var import_virtual_routes = require("virtual:routes");
|
|
39
|
+
|
|
40
|
+
// src/components/router-layout.tsx
|
|
41
|
+
var import_react2 = __toESM(require("react"), 1);
|
|
42
|
+
var import_react_router_dom2 = require("react-router-dom");
|
|
43
|
+
|
|
44
|
+
// src/components/router-utils.tsx
|
|
45
|
+
var import_react = __toESM(require("react"), 1);
|
|
46
|
+
var import_react_router_dom = require("react-router-dom");
|
|
47
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
48
|
+
function wrapLayouts(layouts, pageEl) {
|
|
49
|
+
if (!layouts || layouts.length === 0) return pageEl;
|
|
50
|
+
return layouts.reduceRight((child, loader) => {
|
|
51
|
+
const Layout = import_react.default.lazy(async () => {
|
|
52
|
+
const module2 = await loader();
|
|
53
|
+
return "default" in module2 ? module2 : { default: module2.Layout };
|
|
54
|
+
});
|
|
55
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Layout, { children: child });
|
|
56
|
+
}, pageEl);
|
|
57
|
+
}
|
|
58
|
+
var renderManifestAsRoutes = (manifest2) => {
|
|
59
|
+
return manifest2.map((n) => {
|
|
60
|
+
const Page = import_react.default.lazy(async () => {
|
|
61
|
+
const module2 = await n.loader();
|
|
62
|
+
if (module2 && typeof module2 === "object" && "default" in module2 && module2.default) {
|
|
63
|
+
return module2;
|
|
64
|
+
}
|
|
65
|
+
if (module2 && typeof module2 === "object") {
|
|
66
|
+
const namedExports = Object.keys(module2).filter(
|
|
67
|
+
(key) => key !== "default"
|
|
68
|
+
);
|
|
69
|
+
for (const key of namedExports) {
|
|
70
|
+
const exportValue = module2[key];
|
|
71
|
+
if (typeof exportValue === "function" || typeof exportValue === "object" && exportValue !== null) {
|
|
72
|
+
return {
|
|
73
|
+
default: exportValue
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const availableExports = module2 && typeof module2 === "object" ? Object.keys(module2).join(", ") : "unknown";
|
|
79
|
+
throw new Error(
|
|
80
|
+
`No valid export found in module for route ${n.path}. Available exports: ${availableExports}`
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
const element = wrapLayouts(n.layouts, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Page, {}));
|
|
84
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, { path: n.path, element }, n.id);
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// src/components/router-layout.tsx
|
|
89
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
90
|
+
var RouterLayout = ({
|
|
91
|
+
manifest: manifest2,
|
|
92
|
+
children,
|
|
93
|
+
preloader,
|
|
94
|
+
basePath = "/"
|
|
95
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_router_dom2.BrowserRouter, { basename: basePath, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react2.default.Suspense, { fallback: children || preloader || /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: "Loading..." }), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_router_dom2.Routes, { children: renderManifestAsRoutes(manifest2) }) }) });
|
|
96
|
+
|
|
97
|
+
// src/components/router-provider.tsx
|
|
98
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
99
|
+
function RouterProvider({
|
|
100
|
+
children,
|
|
101
|
+
preloader,
|
|
102
|
+
basePath
|
|
103
|
+
}) {
|
|
104
|
+
const finalBasePath = basePath ?? import_virtual_routes.basePath ?? "/";
|
|
105
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(RouterLayout, { manifest: import_virtual_routes.manifest, preloader, basePath: finalBasePath, children });
|
|
106
|
+
}
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
RouterProvider
|
|
110
|
+
});
|
|
111
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.ts","../src/components/router-provider.tsx","../src/components/router-layout.tsx","../src/components/router-utils.tsx"],"sourcesContent":["export { default as RouterProvider } from './components/router-provider'\r\nexport type { RouterProviderProps } from './components/types/types'\r\n","import { manifest, basePath as configBasePath } from 'virtual:routes'\r\nimport { RouterLayout } from './router-layout'\r\nimport type { RouterProviderProps } from './types/types'\r\n\r\nexport default function RouterProvider({\r\n\tchildren,\r\n\tpreloader,\r\n\tbasePath,\r\n}: Readonly<RouterProviderProps>) {\r\n\t// Используем basePath из пропсов, если указан, иначе из конфигурации\r\n\tconst finalBasePath = basePath ?? configBasePath ?? '/'\r\n\t\r\n\treturn (\r\n\t\t<RouterLayout manifest={manifest} preloader={preloader} basePath={finalBasePath}>\r\n\t\t\t{children}\r\n\t\t</RouterLayout>\r\n\t)\r\n}\r\n","import React from 'react'\r\nimport { BrowserRouter, Routes } from 'react-router-dom'\r\nimport { renderManifestAsRoutes } from './router-utils'\r\nimport type { RouterLayoutProps } from './types/types'\r\n\r\nexport const RouterLayout = ({\r\n\tmanifest,\r\n\tchildren,\r\n\tpreloader,\r\n\tbasePath = '/',\r\n}: RouterLayoutProps) => (\r\n\t<BrowserRouter basename={basePath}>\r\n\t\t<React.Suspense fallback={children || preloader || <div>Loading...</div>}>\r\n\t\t\t<Routes>{renderManifestAsRoutes(manifest)}</Routes>\r\n\t\t</React.Suspense>\r\n\t</BrowserRouter>\r\n)\r\n","import React from 'react'\r\nimport { Route } from 'react-router-dom'\r\nimport type { Node } from './types/types'\r\n\r\nfunction wrapLayouts(\r\n\tlayouts: Node['layouts'] | undefined,\r\n\tpageEl: React.ReactNode\r\n) {\r\n\tif (!layouts || layouts.length === 0) return pageEl\r\n\r\n\treturn layouts.reduceRight((child, loader) => {\r\n\t\tconst Layout = React.lazy(async () => {\r\n\t\t\tconst module = await loader()\r\n\t\t\t// Поддерживаем как default, так и именованный экспорт Layout\r\n\t\t\treturn 'default' in module ? module : { default: module.Layout }\r\n\t\t})\r\n\t\treturn <Layout>{child}</Layout>\r\n\t}, pageEl as React.ReactElement)\r\n}\r\n\r\nexport const renderManifestAsRoutes = (manifest: Node[]) => {\r\n\treturn manifest.map(n => {\r\n\t\tconst Page = React.lazy(async () => {\r\n\t\t\tconst module = await n.loader()\r\n\r\n\t\t\t// Если есть default экспорт, используем его\r\n\t\t\tif (\r\n\t\t\t\tmodule &&\r\n\t\t\t\ttypeof module === 'object' &&\r\n\t\t\t\t'default' in module &&\r\n\t\t\t\tmodule.default\r\n\t\t\t) {\r\n\t\t\t\treturn module as { default: React.ComponentType }\r\n\t\t\t}\r\n\r\n\t\t\t// Ищем любой именованный экспорт, который является функцией или компонентом\r\n\t\t\tif (module && typeof module === 'object') {\r\n\t\t\t\tconst namedExports = Object.keys(module).filter(\r\n\t\t\t\t\tkey => key !== 'default'\r\n\t\t\t\t)\r\n\t\t\t\tfor (const key of namedExports) {\r\n\t\t\t\t\tconst exportValue = module[key]\r\n\t\t\t\t\tif (\r\n\t\t\t\t\t\ttypeof exportValue === 'function' ||\r\n\t\t\t\t\t\t(typeof exportValue === 'object' && exportValue !== null)\r\n\t\t\t\t\t) {\r\n\t\t\t\t\t\treturn {\r\n\t\t\t\t\t\t\tdefault: exportValue as React.ComponentType,\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// Если ничего не найдено, возвращаем ошибку\r\n\t\t\tconst availableExports =\r\n\t\t\t\tmodule && typeof module === 'object'\r\n\t\t\t\t\t? Object.keys(module).join(', ')\r\n\t\t\t\t\t: 'unknown'\r\n\t\t\tthrow new Error(\r\n\t\t\t\t`No valid export found in module for route ${n.path}. Available exports: ${availableExports}`\r\n\t\t\t)\r\n\t\t})\r\n\r\n\t\tconst element = wrapLayouts(n.layouts, <Page />)\r\n\t\treturn <Route key={n.id} path={n.path} element={element} />\r\n\t})\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,4BAAqD;;;ACArD,IAAAA,gBAAkB;AAClB,IAAAC,2BAAsC;;;ACDtC,mBAAkB;AAClB,8BAAsB;AAeb;AAZT,SAAS,YACR,SACA,QACC;AACD,MAAI,CAAC,WAAW,QAAQ,WAAW,EAAG,QAAO;AAE7C,SAAO,QAAQ,YAAY,CAAC,OAAO,WAAW;AAC7C,UAAM,SAAS,aAAAC,QAAM,KAAK,YAAY;AACrC,YAAMC,UAAS,MAAM,OAAO;AAE5B,aAAO,aAAaA,UAASA,UAAS,EAAE,SAASA,QAAO,OAAO;AAAA,IAChE,CAAC;AACD,WAAO,4CAAC,UAAQ,iBAAM;AAAA,EACvB,GAAG,MAA4B;AAChC;AAEO,IAAM,yBAAyB,CAACC,cAAqB;AAC3D,SAAOA,UAAS,IAAI,OAAK;AACxB,UAAM,OAAO,aAAAF,QAAM,KAAK,YAAY;AACnC,YAAMC,UAAS,MAAM,EAAE,OAAO;AAG9B,UACCA,WACA,OAAOA,YAAW,YAClB,aAAaA,WACbA,QAAO,SACN;AACD,eAAOA;AAAA,MACR;AAGA,UAAIA,WAAU,OAAOA,YAAW,UAAU;AACzC,cAAM,eAAe,OAAO,KAAKA,OAAM,EAAE;AAAA,UACxC,SAAO,QAAQ;AAAA,QAChB;AACA,mBAAW,OAAO,cAAc;AAC/B,gBAAM,cAAcA,QAAO,GAAG;AAC9B,cACC,OAAO,gBAAgB,cACtB,OAAO,gBAAgB,YAAY,gBAAgB,MACnD;AACD,mBAAO;AAAA,cACN,SAAS;AAAA,YACV;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAGA,YAAM,mBACLA,WAAU,OAAOA,YAAW,WACzB,OAAO,KAAKA,OAAM,EAAE,KAAK,IAAI,IAC7B;AACJ,YAAM,IAAI;AAAA,QACT,6CAA6C,EAAE,IAAI,wBAAwB,gBAAgB;AAAA,MAC5F;AAAA,IACD,CAAC;AAED,UAAM,UAAU,YAAY,EAAE,SAAS,4CAAC,QAAK,CAAE;AAC/C,WAAO,4CAAC,iCAAiB,MAAM,EAAE,MAAM,WAApB,EAAE,EAAoC;AAAA,EAC1D,CAAC;AACF;;;ADtDqD,IAAAE,sBAAA;AAP9C,IAAM,eAAe,CAAC;AAAA,EAC5B,UAAAC;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AACZ,MACC,6CAAC,0CAAc,UAAU,UACxB,uDAAC,cAAAC,QAAM,UAAN,EAAe,UAAU,YAAY,aAAa,6CAAC,SAAI,wBAAU,GACjE,uDAAC,mCAAQ,iCAAuBD,SAAQ,GAAE,GAC3C,GACD;;;ADFC,IAAAE,sBAAA;AATa,SAAR,eAAgC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AACD,GAAkC;AAEjC,QAAM,gBAAgB,YAAY,sBAAAC,YAAkB;AAEpD,SACC,6CAAC,gBAAa,UAAU,gCAAU,WAAsB,UAAU,eAChE,UACF;AAEF;","names":["import_react","import_react_router_dom","React","module","manifest","import_jsx_runtime","manifest","React","import_jsx_runtime","configBasePath"]}
|
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/components/router-provider.tsx
|
|
2
|
+
import { manifest, basePath as configBasePath } from "virtual:routes";
|
|
3
|
+
|
|
4
|
+
// src/components/router-layout.tsx
|
|
5
|
+
import React2 from "react";
|
|
6
|
+
import { BrowserRouter, Routes } from "react-router-dom";
|
|
7
|
+
|
|
8
|
+
// src/components/router-utils.tsx
|
|
9
|
+
import React from "react";
|
|
10
|
+
import { Route } from "react-router-dom";
|
|
11
|
+
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
function wrapLayouts(layouts, pageEl) {
|
|
13
|
+
if (!layouts || layouts.length === 0) return pageEl;
|
|
14
|
+
return layouts.reduceRight((child, loader) => {
|
|
15
|
+
const Layout = React.lazy(async () => {
|
|
16
|
+
const module = await loader();
|
|
17
|
+
return "default" in module ? module : { default: module.Layout };
|
|
18
|
+
});
|
|
19
|
+
return /* @__PURE__ */ jsx(Layout, { children: child });
|
|
20
|
+
}, pageEl);
|
|
21
|
+
}
|
|
22
|
+
var renderManifestAsRoutes = (manifest2) => {
|
|
23
|
+
return manifest2.map((n) => {
|
|
24
|
+
const Page = React.lazy(async () => {
|
|
25
|
+
const module = await n.loader();
|
|
26
|
+
if (module && typeof module === "object" && "default" in module && module.default) {
|
|
27
|
+
return module;
|
|
28
|
+
}
|
|
29
|
+
if (module && typeof module === "object") {
|
|
30
|
+
const namedExports = Object.keys(module).filter(
|
|
31
|
+
(key) => key !== "default"
|
|
32
|
+
);
|
|
33
|
+
for (const key of namedExports) {
|
|
34
|
+
const exportValue = module[key];
|
|
35
|
+
if (typeof exportValue === "function" || typeof exportValue === "object" && exportValue !== null) {
|
|
36
|
+
return {
|
|
37
|
+
default: exportValue
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const availableExports = module && typeof module === "object" ? Object.keys(module).join(", ") : "unknown";
|
|
43
|
+
throw new Error(
|
|
44
|
+
`No valid export found in module for route ${n.path}. Available exports: ${availableExports}`
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
const element = wrapLayouts(n.layouts, /* @__PURE__ */ jsx(Page, {}));
|
|
48
|
+
return /* @__PURE__ */ jsx(Route, { path: n.path, element }, n.id);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// src/components/router-layout.tsx
|
|
53
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
54
|
+
var RouterLayout = ({
|
|
55
|
+
manifest: manifest2,
|
|
56
|
+
children,
|
|
57
|
+
preloader,
|
|
58
|
+
basePath = "/"
|
|
59
|
+
}) => /* @__PURE__ */ jsx2(BrowserRouter, { basename: basePath, children: /* @__PURE__ */ jsx2(React2.Suspense, { fallback: children || preloader || /* @__PURE__ */ jsx2("div", { children: "Loading..." }), children: /* @__PURE__ */ jsx2(Routes, { children: renderManifestAsRoutes(manifest2) }) }) });
|
|
60
|
+
|
|
61
|
+
// src/components/router-provider.tsx
|
|
62
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
63
|
+
function RouterProvider({
|
|
64
|
+
children,
|
|
65
|
+
preloader,
|
|
66
|
+
basePath
|
|
67
|
+
}) {
|
|
68
|
+
const finalBasePath = basePath ?? configBasePath ?? "/";
|
|
69
|
+
return /* @__PURE__ */ jsx3(RouterLayout, { manifest, preloader, basePath: finalBasePath, children });
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
RouterProvider
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=react.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/router-provider.tsx","../src/components/router-layout.tsx","../src/components/router-utils.tsx"],"sourcesContent":["import { manifest, basePath as configBasePath } from 'virtual:routes'\r\nimport { RouterLayout } from './router-layout'\r\nimport type { RouterProviderProps } from './types/types'\r\n\r\nexport default function RouterProvider({\r\n\tchildren,\r\n\tpreloader,\r\n\tbasePath,\r\n}: Readonly<RouterProviderProps>) {\r\n\t// Используем basePath из пропсов, если указан, иначе из конфигурации\r\n\tconst finalBasePath = basePath ?? configBasePath ?? '/'\r\n\t\r\n\treturn (\r\n\t\t<RouterLayout manifest={manifest} preloader={preloader} basePath={finalBasePath}>\r\n\t\t\t{children}\r\n\t\t</RouterLayout>\r\n\t)\r\n}\r\n","import React from 'react'\r\nimport { BrowserRouter, Routes } from 'react-router-dom'\r\nimport { renderManifestAsRoutes } from './router-utils'\r\nimport type { RouterLayoutProps } from './types/types'\r\n\r\nexport const RouterLayout = ({\r\n\tmanifest,\r\n\tchildren,\r\n\tpreloader,\r\n\tbasePath = '/',\r\n}: RouterLayoutProps) => (\r\n\t<BrowserRouter basename={basePath}>\r\n\t\t<React.Suspense fallback={children || preloader || <div>Loading...</div>}>\r\n\t\t\t<Routes>{renderManifestAsRoutes(manifest)}</Routes>\r\n\t\t</React.Suspense>\r\n\t</BrowserRouter>\r\n)\r\n","import React from 'react'\r\nimport { Route } from 'react-router-dom'\r\nimport type { Node } from './types/types'\r\n\r\nfunction wrapLayouts(\r\n\tlayouts: Node['layouts'] | undefined,\r\n\tpageEl: React.ReactNode\r\n) {\r\n\tif (!layouts || layouts.length === 0) return pageEl\r\n\r\n\treturn layouts.reduceRight((child, loader) => {\r\n\t\tconst Layout = React.lazy(async () => {\r\n\t\t\tconst module = await loader()\r\n\t\t\t// Поддерживаем как default, так и именованный экспорт Layout\r\n\t\t\treturn 'default' in module ? module : { default: module.Layout }\r\n\t\t})\r\n\t\treturn <Layout>{child}</Layout>\r\n\t}, pageEl as React.ReactElement)\r\n}\r\n\r\nexport const renderManifestAsRoutes = (manifest: Node[]) => {\r\n\treturn manifest.map(n => {\r\n\t\tconst Page = React.lazy(async () => {\r\n\t\t\tconst module = await n.loader()\r\n\r\n\t\t\t// Если есть default экспорт, используем его\r\n\t\t\tif (\r\n\t\t\t\tmodule &&\r\n\t\t\t\ttypeof module === 'object' &&\r\n\t\t\t\t'default' in module &&\r\n\t\t\t\tmodule.default\r\n\t\t\t) {\r\n\t\t\t\treturn module as { default: React.ComponentType }\r\n\t\t\t}\r\n\r\n\t\t\t// Ищем любой именованный экспорт, который является функцией или компонентом\r\n\t\t\tif (module && typeof module === 'object') {\r\n\t\t\t\tconst namedExports = Object.keys(module).filter(\r\n\t\t\t\t\tkey => key !== 'default'\r\n\t\t\t\t)\r\n\t\t\t\tfor (const key of namedExports) {\r\n\t\t\t\t\tconst exportValue = module[key]\r\n\t\t\t\t\tif (\r\n\t\t\t\t\t\ttypeof exportValue === 'function' ||\r\n\t\t\t\t\t\t(typeof exportValue === 'object' && exportValue !== null)\r\n\t\t\t\t\t) {\r\n\t\t\t\t\t\treturn {\r\n\t\t\t\t\t\t\tdefault: exportValue as React.ComponentType,\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// Если ничего не найдено, возвращаем ошибку\r\n\t\t\tconst availableExports =\r\n\t\t\t\tmodule && typeof module === 'object'\r\n\t\t\t\t\t? Object.keys(module).join(', ')\r\n\t\t\t\t\t: 'unknown'\r\n\t\t\tthrow new Error(\r\n\t\t\t\t`No valid export found in module for route ${n.path}. Available exports: ${availableExports}`\r\n\t\t\t)\r\n\t\t})\r\n\r\n\t\tconst element = wrapLayouts(n.layouts, <Page />)\r\n\t\treturn <Route key={n.id} path={n.path} element={element} />\r\n\t})\r\n}\r\n"],"mappings":";AAAA,SAAS,UAAU,YAAY,sBAAsB;;;ACArD,OAAOA,YAAW;AAClB,SAAS,eAAe,cAAc;;;ACDtC,OAAO,WAAW;AAClB,SAAS,aAAa;AAeb;AAZT,SAAS,YACR,SACA,QACC;AACD,MAAI,CAAC,WAAW,QAAQ,WAAW,EAAG,QAAO;AAE7C,SAAO,QAAQ,YAAY,CAAC,OAAO,WAAW;AAC7C,UAAM,SAAS,MAAM,KAAK,YAAY;AACrC,YAAM,SAAS,MAAM,OAAO;AAE5B,aAAO,aAAa,SAAS,SAAS,EAAE,SAAS,OAAO,OAAO;AAAA,IAChE,CAAC;AACD,WAAO,oBAAC,UAAQ,iBAAM;AAAA,EACvB,GAAG,MAA4B;AAChC;AAEO,IAAM,yBAAyB,CAACC,cAAqB;AAC3D,SAAOA,UAAS,IAAI,OAAK;AACxB,UAAM,OAAO,MAAM,KAAK,YAAY;AACnC,YAAM,SAAS,MAAM,EAAE,OAAO;AAG9B,UACC,UACA,OAAO,WAAW,YAClB,aAAa,UACb,OAAO,SACN;AACD,eAAO;AAAA,MACR;AAGA,UAAI,UAAU,OAAO,WAAW,UAAU;AACzC,cAAM,eAAe,OAAO,KAAK,MAAM,EAAE;AAAA,UACxC,SAAO,QAAQ;AAAA,QAChB;AACA,mBAAW,OAAO,cAAc;AAC/B,gBAAM,cAAc,OAAO,GAAG;AAC9B,cACC,OAAO,gBAAgB,cACtB,OAAO,gBAAgB,YAAY,gBAAgB,MACnD;AACD,mBAAO;AAAA,cACN,SAAS;AAAA,YACV;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAGA,YAAM,mBACL,UAAU,OAAO,WAAW,WACzB,OAAO,KAAK,MAAM,EAAE,KAAK,IAAI,IAC7B;AACJ,YAAM,IAAI;AAAA,QACT,6CAA6C,EAAE,IAAI,wBAAwB,gBAAgB;AAAA,MAC5F;AAAA,IACD,CAAC;AAED,UAAM,UAAU,YAAY,EAAE,SAAS,oBAAC,QAAK,CAAE;AAC/C,WAAO,oBAAC,SAAiB,MAAM,EAAE,MAAM,WAApB,EAAE,EAAoC;AAAA,EAC1D,CAAC;AACF;;;ADtDqD,gBAAAC,YAAA;AAP9C,IAAM,eAAe,CAAC;AAAA,EAC5B,UAAAC;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AACZ,MACC,gBAAAD,KAAC,iBAAc,UAAU,UACxB,0BAAAA,KAACE,OAAM,UAAN,EAAe,UAAU,YAAY,aAAa,gBAAAF,KAAC,SAAI,wBAAU,GACjE,0BAAAA,KAAC,UAAQ,iCAAuBC,SAAQ,GAAE,GAC3C,GACD;;;ADFC,gBAAAE,YAAA;AATa,SAAR,eAAgC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AACD,GAAkC;AAEjC,QAAM,gBAAgB,YAAY,kBAAkB;AAEpD,SACC,gBAAAA,KAAC,gBAAa,UAAoB,WAAsB,UAAU,eAChE,UACF;AAEF;","names":["React","manifest","jsx","manifest","React","jsx"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "path-rush",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "A simple and powerful plugin for Vite with file-based routing",
|
|
5
|
+
"main": "dist/plugin.js",
|
|
6
|
+
"module": "dist/plugin.mjs",
|
|
7
|
+
"types": "dist/plugin.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsup",
|
|
16
|
+
"dev": "tsup --watch",
|
|
17
|
+
"prepublishOnly": "npm run build",
|
|
18
|
+
"type-check": "tsc --noEmit"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"vite",
|
|
22
|
+
"plugin",
|
|
23
|
+
"file-based-routing",
|
|
24
|
+
"react",
|
|
25
|
+
"router",
|
|
26
|
+
"typescript",
|
|
27
|
+
"seo",
|
|
28
|
+
"hmr",
|
|
29
|
+
"spa",
|
|
30
|
+
"routing",
|
|
31
|
+
"file-system",
|
|
32
|
+
"automatic-routes"
|
|
33
|
+
],
|
|
34
|
+
"author": {
|
|
35
|
+
"name": "da-b1rmuda",
|
|
36
|
+
"url": "https://github.com/da-b1rmuda"
|
|
37
|
+
},
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"homepage": "https://github.com/da-b1rmuda/path-rush#readme",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/da-b1rmuda/path-rush.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/da-b1rmuda/path-rush/issues"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"fast-glob": "^3.3.2"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
55
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
56
|
+
"react-router-dom": "^6.0.0 || ^7.0.0",
|
|
57
|
+
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"react": {
|
|
61
|
+
"optional": false
|
|
62
|
+
},
|
|
63
|
+
"react-dom": {
|
|
64
|
+
"optional": false
|
|
65
|
+
},
|
|
66
|
+
"react-router-dom": {
|
|
67
|
+
"optional": false
|
|
68
|
+
},
|
|
69
|
+
"vite": {
|
|
70
|
+
"optional": false
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@types/node": "^20.10.0",
|
|
75
|
+
"@types/react": "^19.2.2",
|
|
76
|
+
"@types/react-dom": "^19.2.2",
|
|
77
|
+
"react": "^19.1.1",
|
|
78
|
+
"react-dom": "^19.1.1",
|
|
79
|
+
"tsup": "^8.0.0",
|
|
80
|
+
"typescript": "^5.4.0",
|
|
81
|
+
"vite": "^5.2.0"
|
|
82
|
+
},
|
|
83
|
+
"exports": {
|
|
84
|
+
".": {
|
|
85
|
+
"types": "./dist/plugin.d.ts",
|
|
86
|
+
"import": "./dist/plugin.mjs",
|
|
87
|
+
"require": "./dist/plugin.js"
|
|
88
|
+
},
|
|
89
|
+
"./react": {
|
|
90
|
+
"types": "./dist/react.d.ts",
|
|
91
|
+
"import": "./dist/react.mjs",
|
|
92
|
+
"require": "./dist/react.js"
|
|
93
|
+
},
|
|
94
|
+
"./core": {
|
|
95
|
+
"types": "./dist/core.d.ts",
|
|
96
|
+
"import": "./dist/core.mjs",
|
|
97
|
+
"require": "./dist/core.js"
|
|
98
|
+
},
|
|
99
|
+
"./package.json": "./package.json"
|
|
100
|
+
},
|
|
101
|
+
"publishConfig": {
|
|
102
|
+
"access": "public"
|
|
103
|
+
}
|
|
104
|
+
}
|