@vixt/react 0.9.0 → 0.11.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/dist/client/client.d.ts +17 -0
- package/dist/client/entry.d.ts +2 -5
- package/dist/client/entry.js +2 -5
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2 -0
- package/dist/node/chunk-e9Ob2GDo.mjs +26 -0
- package/dist/node/components-DgaASyfT.mjs +10683 -0
- package/dist/node/detect-acorn-Du_gcr4-.mjs +370 -0
- package/dist/{index.mjs → node/dist-OcbwbyG4.mjs} +456 -2356
- package/dist/node/index.d.mts +9 -0
- package/dist/node/index.mjs +38 -0
- package/dist/node/lib-ByhivYXf.mjs +1930 -0
- package/dist/node/modules/components.d.mts +10 -0
- package/dist/node/modules/components.mjs +2 -0
- package/dist/node/modules/preset-react.d.mts +7 -0
- package/dist/node/modules/preset-react.mjs +2 -0
- package/dist/node/modules/route-block.d.mts +13 -0
- package/dist/node/modules/route-block.mjs +38 -0
- package/dist/node/modules/virtual-root-component.d.mts +7 -0
- package/dist/node/modules/virtual-root-component.mjs +51 -0
- package/dist/node/modules/virtual-setup-layouts.d.mts +6 -0
- package/dist/node/modules/virtual-setup-layouts.mjs +41 -0
- package/dist/node/node.d.mts +18 -0
- package/dist/node/preset-react-DWJpAlWQ.mjs +65 -0
- package/dist/types/index.d.ts +2 -2
- package/package.json +12 -13
- package/dist/index.d.mts +0 -7
- package/dist/types/client.d.ts +0 -12
- package/dist/types/node.d.ts +0 -20
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _$vite from "vite";
|
|
2
|
+
|
|
3
|
+
//#region src/node/modules/components.d.ts
|
|
4
|
+
interface ComponentResolverOptions {
|
|
5
|
+
dirs?: string[];
|
|
6
|
+
dts?: string | boolean;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: (options?: ComponentResolverOptions | undefined) => _$vite.PluginOption;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ComponentResolverOptions, _default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactRoute } from "vite-plugin-pages";
|
|
2
|
+
|
|
3
|
+
//#region src/node/modules/route-block.d.ts
|
|
4
|
+
declare function extendRoute(route: ReactRoute): {
|
|
5
|
+
children?: ReactRoute[];
|
|
6
|
+
rawRoute?: string | undefined;
|
|
7
|
+
path?: string | undefined;
|
|
8
|
+
caseSensitive?: boolean | undefined;
|
|
9
|
+
element?: string | undefined;
|
|
10
|
+
index?: boolean | undefined;
|
|
11
|
+
} | undefined;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { extendRoute };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { r as __toESM } from "../chunk-e9Ob2GDo.mjs";
|
|
2
|
+
import { t as require_lib } from "../lib-ByhivYXf.mjs";
|
|
3
|
+
import extractComments from "extract-comments";
|
|
4
|
+
import { parse } from "yaml";
|
|
5
|
+
//#region src/node/modules/route-block.ts
|
|
6
|
+
var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
7
|
+
const routeJSXReg = /^\s+(route)\s+/gm;
|
|
8
|
+
function parseJSX(code) {
|
|
9
|
+
return extractComments(code).slice(0, 1).filter((comment) => routeJSXReg.test(comment.value) && comment.value.includes(":") && comment.loc.start.line === 1);
|
|
10
|
+
}
|
|
11
|
+
function parseYamlComment(code, path) {
|
|
12
|
+
return code.reduce((memo, item) => {
|
|
13
|
+
const { value } = item;
|
|
14
|
+
const v = value.replace(routeJSXReg, "");
|
|
15
|
+
try {
|
|
16
|
+
const yamlResult = parse(v);
|
|
17
|
+
return {
|
|
18
|
+
...memo,
|
|
19
|
+
...yamlResult
|
|
20
|
+
};
|
|
21
|
+
} catch (err) {
|
|
22
|
+
throw new Error(`Invalid YAML format of comment in ${path}\n${err.message}`);
|
|
23
|
+
}
|
|
24
|
+
}, {});
|
|
25
|
+
}
|
|
26
|
+
function getRouteBlock(path) {
|
|
27
|
+
return parseYamlComment(parseJSX(import_lib.default.readFileSync(path, "utf-8")), path);
|
|
28
|
+
}
|
|
29
|
+
function extendRoute(route) {
|
|
30
|
+
if (!route.element) return;
|
|
31
|
+
const block = getRouteBlock(route.element.startsWith("/") ? route.element.slice(1) : route.element);
|
|
32
|
+
return {
|
|
33
|
+
...route,
|
|
34
|
+
...block
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { extendRoute };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _$_vixt_core0 from "@vixt/core";
|
|
2
|
+
|
|
3
|
+
//#region src/node/modules/virtual-root-component.d.ts
|
|
4
|
+
declare function isEmptyCode(code?: string): boolean;
|
|
5
|
+
declare const _default: _$_vixt_core0.VixtModule<_$_vixt_core0.ModuleOptions>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default as default, isEmptyCode };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { r as __toESM } from "../chunk-e9Ob2GDo.mjs";
|
|
2
|
+
import { t as require_lib } from "../lib-ByhivYXf.mjs";
|
|
3
|
+
import { c as resolvePathSync, l as posix } from "../dist-OcbwbyG4.mjs";
|
|
4
|
+
import { defineVixtModule } from "@vixt/core";
|
|
5
|
+
import { parseAst } from "vite";
|
|
6
|
+
//#region src/node/modules/virtual-root-component.ts
|
|
7
|
+
var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
8
|
+
function resolveRootComponent(vixt) {
|
|
9
|
+
for (const layer of vixt._layers) {
|
|
10
|
+
const layerRootComponentPath = posix.resolve(layer.config.srcDir, "App.tsx");
|
|
11
|
+
const layerRootComponentCode = import_lib.default.existsSync(layerRootComponentPath) && import_lib.default.readFileSync(layerRootComponentPath, "utf-8") || "";
|
|
12
|
+
if (!isEmptyCode(layerRootComponentCode)) return {
|
|
13
|
+
path: layerRootComponentPath,
|
|
14
|
+
code: layerRootComponentCode
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const defaultRootComponentPath = resolvePathSync("@vixt/react/client/App");
|
|
18
|
+
return {
|
|
19
|
+
path: defaultRootComponentPath,
|
|
20
|
+
code: import_lib.default.readFileSync(defaultRootComponentPath, "utf-8")
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function isEmptyCode(code) {
|
|
24
|
+
if (!code) return true;
|
|
25
|
+
try {
|
|
26
|
+
return !parseAst(code, { jsx: true }).body.length;
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const name = "virtual:vixt:root-component.tsx";
|
|
32
|
+
var virtual_root_component_default = defineVixtModule({
|
|
33
|
+
meta: { name },
|
|
34
|
+
setup(_, vixt) {
|
|
35
|
+
return {
|
|
36
|
+
name,
|
|
37
|
+
resolveId(id) {
|
|
38
|
+
if (id === name) return name;
|
|
39
|
+
},
|
|
40
|
+
load(id) {
|
|
41
|
+
if (id === name) {
|
|
42
|
+
const { path, code } = resolveRootComponent(vixt);
|
|
43
|
+
this.addWatchFile(path);
|
|
44
|
+
return code;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
//#endregion
|
|
51
|
+
export { virtual_root_component_default as default, isEmptyCode };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { defineVixtModule } from "@vixt/core";
|
|
2
|
+
//#region src/node/modules/virtual-setup-layouts.ts
|
|
3
|
+
const name = "virtual:vixt:setup-layouts";
|
|
4
|
+
const virtualModuleId = name;
|
|
5
|
+
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
6
|
+
var virtual_setup_layouts_default = defineVixtModule({
|
|
7
|
+
meta: { name },
|
|
8
|
+
setup(_, vixt) {
|
|
9
|
+
return {
|
|
10
|
+
name,
|
|
11
|
+
resolveId(id) {
|
|
12
|
+
if (id === virtualModuleId) return resolvedVirtualModuleId;
|
|
13
|
+
},
|
|
14
|
+
load(id) {
|
|
15
|
+
if (id === resolvedVirtualModuleId) {
|
|
16
|
+
const { defaultLayout = "default" } = vixt.options.layouts ?? {};
|
|
17
|
+
return `import { createElement } from 'react'
|
|
18
|
+
import { layouts } from 'virtual:generated-layouts'
|
|
19
|
+
|
|
20
|
+
export function setupLayouts(routes) {
|
|
21
|
+
return routes.map(route => {
|
|
22
|
+
if (route.children?.length > 0) {
|
|
23
|
+
route.children = setupLayouts(route.children)
|
|
24
|
+
}
|
|
25
|
+
if(route.element && route.meta?.layout !== false) {
|
|
26
|
+
return {
|
|
27
|
+
path: route.path,
|
|
28
|
+
element: createElement(layouts[route.meta?.layout ?? '${defaultLayout}']),
|
|
29
|
+
children: [{ ...route, path: '' }]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return route
|
|
33
|
+
});
|
|
34
|
+
}`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
//#endregion
|
|
41
|
+
export { virtual_setup_layouts_default as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ExtractPluginOptions } from "@vixt/core";
|
|
2
|
+
import React from "@vitejs/plugin-react";
|
|
3
|
+
import Pages from "vite-plugin-pages";
|
|
4
|
+
import Layouts from "vite-plugin-vue-layouts";
|
|
5
|
+
|
|
6
|
+
//#region src/node/node.d.ts
|
|
7
|
+
interface ReactVixtOptions {
|
|
8
|
+
react?: ExtractPluginOptions<typeof React>;
|
|
9
|
+
/** https://github.com/hannoeru/vite-plugin-pages */
|
|
10
|
+
pages?: ExtractPluginOptions<typeof Pages>;
|
|
11
|
+
/** https://github.com/JohnCampionJr/vite-plugin-vue-layouts */
|
|
12
|
+
layouts?: ExtractPluginOptions<typeof Layouts>;
|
|
13
|
+
}
|
|
14
|
+
declare module '@vixt/core' {
|
|
15
|
+
interface VixtOptions extends ReactVixtOptions {}
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ReactVixtOptions };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { t as components_default } from "./components-DgaASyfT.mjs";
|
|
2
|
+
import { extendRoute } from "./modules/route-block.mjs";
|
|
3
|
+
import { defineVixtModule, resolveLayersDirs } from "@vixt/core";
|
|
4
|
+
import React from "@vitejs/plugin-react";
|
|
5
|
+
import Pages from "vite-plugin-pages";
|
|
6
|
+
import Layouts from "vite-plugin-vue-layouts";
|
|
7
|
+
//#region ../../node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.mjs
|
|
8
|
+
function isPlainObject(value) {
|
|
9
|
+
if (value === null || typeof value !== "object") return false;
|
|
10
|
+
const prototype = Object.getPrototypeOf(value);
|
|
11
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
|
|
12
|
+
if (Symbol.iterator in value) return false;
|
|
13
|
+
if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
17
|
+
if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace, merger);
|
|
18
|
+
const object = { ...defaults };
|
|
19
|
+
for (const key of Object.keys(baseObject)) {
|
|
20
|
+
if (key === "__proto__" || key === "constructor") continue;
|
|
21
|
+
const value = baseObject[key];
|
|
22
|
+
if (value === null || value === void 0) continue;
|
|
23
|
+
if (merger && merger(object, key, value, namespace)) continue;
|
|
24
|
+
if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
|
|
25
|
+
else if (isPlainObject(value) && isPlainObject(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
|
|
26
|
+
else object[key] = value;
|
|
27
|
+
}
|
|
28
|
+
return object;
|
|
29
|
+
}
|
|
30
|
+
function createDefu(merger) {
|
|
31
|
+
return (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
|
|
32
|
+
}
|
|
33
|
+
const defu = createDefu();
|
|
34
|
+
var preset_react_default = defineVixtModule({
|
|
35
|
+
meta: { name: "vixt:preset-react" },
|
|
36
|
+
setup(_, vixt) {
|
|
37
|
+
const { components = [], layouts = [], pages = [] } = resolveLayersDirs([...vixt._layers].reverse());
|
|
38
|
+
const { buildTypesDir } = vixt.options;
|
|
39
|
+
const defaultOptions = {
|
|
40
|
+
react: {},
|
|
41
|
+
pages: {
|
|
42
|
+
dirs: pages,
|
|
43
|
+
extendRoute
|
|
44
|
+
},
|
|
45
|
+
layouts: {
|
|
46
|
+
layoutsDirs: layouts,
|
|
47
|
+
pagesDirs: pages,
|
|
48
|
+
extensions: ["jsx", "tsx"],
|
|
49
|
+
importMode: () => "sync"
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const options = vixt.options = defu(vixt.options, defaultOptions);
|
|
53
|
+
return [
|
|
54
|
+
React(options.react),
|
|
55
|
+
Pages(options.pages),
|
|
56
|
+
Layouts(options.layouts),
|
|
57
|
+
components_default({
|
|
58
|
+
dirs: components,
|
|
59
|
+
dts: `${buildTypesDir}/components.d.ts`
|
|
60
|
+
})
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
//#endregion
|
|
65
|
+
export { preset_react_default as t };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import '
|
|
1
|
+
import '../client/client.d'
|
|
2
|
+
import '../node/node.d'
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vixt/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"author": "SoulLyoko<https://github.com/SoulLyoko>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://soullyoko.github.io/vixt/",
|
|
@@ -12,33 +12,32 @@
|
|
|
12
12
|
"react"
|
|
13
13
|
],
|
|
14
14
|
"exports": {
|
|
15
|
-
".": "./dist/index.mjs",
|
|
15
|
+
".": "./dist/node/index.mjs",
|
|
16
16
|
"./client/App": "./src/client/App.tsx",
|
|
17
17
|
"./client/*": "./dist/client/*.js",
|
|
18
18
|
"./types": "./dist/types/index.d.ts",
|
|
19
19
|
"./package.json": "./package.json"
|
|
20
20
|
},
|
|
21
|
-
"main": "./dist/index.mjs",
|
|
21
|
+
"main": "./dist/node/index.mjs",
|
|
22
22
|
"types": "./dist/types/index.d.ts",
|
|
23
23
|
"files": [
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@types/react": "^19.2.
|
|
27
|
+
"@types/react": "^19.2.15",
|
|
28
28
|
"@types/react-dom": "^19.2.3",
|
|
29
|
-
"@vitejs/plugin-react": "^
|
|
30
|
-
"ahooks": "^3.9.
|
|
29
|
+
"@vitejs/plugin-react": "^6.0.2",
|
|
30
|
+
"ahooks": "^3.9.7",
|
|
31
31
|
"extract-comments": "^1.1.0",
|
|
32
32
|
"fast-glob": "^3.3.3",
|
|
33
|
-
"react": "^19.2.
|
|
34
|
-
"react-dom": "^19.2.
|
|
35
|
-
"react-router": "^7.
|
|
36
|
-
"unocss": "^66.
|
|
37
|
-
"unplugin-auto-import": "^21.0.0",
|
|
33
|
+
"react": "^19.2.6",
|
|
34
|
+
"react-dom": "^19.2.6",
|
|
35
|
+
"react-router": "^7.15.1",
|
|
36
|
+
"unocss": "^66.7.0",
|
|
38
37
|
"unplugin-vue-components": "28.0.0",
|
|
39
38
|
"vite-plugin-pages": "^0.33.3",
|
|
40
39
|
"vite-plugin-vue-layouts": "^0.11.0",
|
|
41
|
-
"yaml": "^2.
|
|
42
|
-
"@vixt/core": "0.
|
|
40
|
+
"yaml": "^2.9.0",
|
|
41
|
+
"@vixt/core": "0.11.0"
|
|
43
42
|
}
|
|
44
43
|
}
|
package/dist/index.d.mts
DELETED
package/dist/types/client.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Root } from 'react-dom/client'
|
|
2
|
-
import type { RouteObject } from 'react-router'
|
|
3
|
-
|
|
4
|
-
declare module '@vixt/core/client' {
|
|
5
|
-
interface VixtAppConfig { }
|
|
6
|
-
|
|
7
|
-
interface VixtApp {
|
|
8
|
-
app: Root
|
|
9
|
-
routes: RouteObject[]
|
|
10
|
-
appConfig: VixtAppConfig
|
|
11
|
-
}
|
|
12
|
-
}
|
package/dist/types/node.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type React from '@vitejs/plugin-react'
|
|
2
|
-
import type { ExtractPluginOptions } from '@vixt/core'
|
|
3
|
-
import type UnoCSS from 'unocss/vite'
|
|
4
|
-
import type AutoImport from 'unplugin-auto-import/vite'
|
|
5
|
-
import type Pages from 'vite-plugin-pages'
|
|
6
|
-
import type Layouts from 'vite-plugin-vue-layouts'
|
|
7
|
-
|
|
8
|
-
declare module '@vixt/core' {
|
|
9
|
-
interface VixtOptions {
|
|
10
|
-
react?: ExtractPluginOptions<typeof React>
|
|
11
|
-
/** https://github.com/hannoeru/vite-plugin-pages */
|
|
12
|
-
pages?: ExtractPluginOptions<typeof Pages>
|
|
13
|
-
/** https://github.com/JohnCampionJr/vite-plugin-vue-layouts */
|
|
14
|
-
layouts?: ExtractPluginOptions<typeof Layouts>
|
|
15
|
-
/** https://github.com/unplugin/unplugin-auto-import */
|
|
16
|
-
imports?: ExtractPluginOptions<typeof AutoImport>
|
|
17
|
-
/** https://github.com/unocss/unocss */
|
|
18
|
-
unocss?: ExtractPluginOptions<typeof UnoCSS>
|
|
19
|
-
}
|
|
20
|
-
}
|