valaxy 1.1.0 → 1.2.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/client/components/ValaxyCopyright.vue +2 -1
- package/client/composables/collections.ts +13 -9
- package/client/composables/decrypt.ts +8 -1
- package/client/composables/outline/anchor.ts +20 -8
- package/client/index.d.ts +0 -1
- package/client/layouts/README.md +1 -1
- package/client/main.ts +35 -20
- package/client/modules/valaxy.ts +14 -5
- package/client/shims.d.ts +20 -0
- package/client/utils/layouts.ts +359 -0
- package/client/utils/path.ts +30 -0
- package/dist/node/cli/index.mjs +4 -11
- package/dist/node/index.d.mts +68 -45
- package/dist/node/index.mjs +4 -11
- package/dist/shared/{valaxy.BU27Owzs.mjs → valaxy.DvkRJomf.mjs} +627 -1886
- package/dist/shared/{valaxy.I4MpBkZO.d.mts → valaxy.EzGcrVef.d.mts} +90 -1
- package/dist/types/index.d.mts +2 -2
- package/package.json +11 -18
- package/types/config.ts +83 -0
- package/types/vue-router.d.ts +8 -0
- package/vendor/README.md +8 -8
- package/vendor/sources.json +0 -31
- package/vendor/i18n/LICENSE +0 -20
- package/vendor/i18n/index.d.mts +0 -7
- package/vendor/i18n/index.mjs +0 -1389
- package/vendor/i18n/types.d.ts +0 -48
- package/vendor/layouts/LICENSE +0 -21
- package/vendor/layouts/client.d.ts +0 -11
- package/vendor/layouts/index.d.mts +0 -86
- package/vendor/layouts/index.mjs +0 -235
- package/vendor/layouts/layoutName-DVkP7Qpo.mjs +0 -82
- package/vendor/layouts/runtime.d.mts +0 -72
- package/vendor/layouts/runtime.mjs +0 -284
package/vendor/i18n/types.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
type SFCLangFormat = 'json' | 'json5' | 'yml' | 'yaml';
|
|
2
|
-
type VueI18nModule = 'vue-i18n' | 'petite-vue-i18n';
|
|
3
|
-
interface TreeShakingOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Message key patterns to always keep (never tree-shake).
|
|
6
|
-
* Supports glob-like patterns (e.g., `'errors.*'`, `'validation.**'`).
|
|
7
|
-
*/
|
|
8
|
-
safelist?: string[];
|
|
9
|
-
/**
|
|
10
|
-
* Strategy when dynamic key usage (e.g., `t(variable)`) is detected.
|
|
11
|
-
* - `'keep-all'`: Disable tree-shaking and keep all keys (safe default).
|
|
12
|
-
* - `'ignore'`: Continue tree-shaking despite dynamic keys (risky, use with `safelist`).
|
|
13
|
-
* @default 'keep-all'
|
|
14
|
-
*/
|
|
15
|
-
dynamicKeyStrategy?: 'keep-all' | 'ignore';
|
|
16
|
-
/**
|
|
17
|
-
* Glob patterns for source files to scan for used message keys.
|
|
18
|
-
* Defaults to `${projectRoot}/src/**\/*.{vue,ts,js,tsx,jsx}` when not specified.
|
|
19
|
-
*/
|
|
20
|
-
scanPatterns?: string[];
|
|
21
|
-
}
|
|
22
|
-
interface PluginOptions {
|
|
23
|
-
include?: string | string[];
|
|
24
|
-
exclude?: string | string[];
|
|
25
|
-
onlyLocales?: string | string[];
|
|
26
|
-
allowDynamic?: boolean;
|
|
27
|
-
module?: VueI18nModule;
|
|
28
|
-
dropMessageCompiler?: boolean;
|
|
29
|
-
runtimeOnly?: boolean;
|
|
30
|
-
compositionOnly?: boolean;
|
|
31
|
-
ssr?: boolean;
|
|
32
|
-
fullInstall?: boolean;
|
|
33
|
-
forceStringify?: boolean;
|
|
34
|
-
defaultSFCLang?: SFCLangFormat;
|
|
35
|
-
globalSFCScope?: boolean;
|
|
36
|
-
strictMessage?: boolean;
|
|
37
|
-
escapeHtml?: boolean;
|
|
38
|
-
optimizeTranslationDirective?: boolean | string | string[];
|
|
39
|
-
transformI18nBlock?: (src: string | Buffer) => string;
|
|
40
|
-
/**
|
|
41
|
-
* Enable message key tree-shaking to remove unused locale message keys.
|
|
42
|
-
* Only effective in production builds.
|
|
43
|
-
* @default false
|
|
44
|
-
*/
|
|
45
|
-
treeShaking?: boolean | TreeShakingOptions;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export type { PluginOptions, SFCLangFormat, TreeShakingOptions, VueI18nModule };
|
package/vendor/layouts/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 loicduong
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
declare module 'virtual:generated-layouts' {
|
|
2
|
-
import type { LayoutMap, LayoutName, LayoutProps } from 'valaxy/vendor/layouts/runtime.mjs'
|
|
3
|
-
import type { Router, RouteRecordRaw } from 'vue-router'
|
|
4
|
-
|
|
5
|
-
export const layouts: LayoutMap
|
|
6
|
-
/** need any here due to different types for vue-router versions */
|
|
7
|
-
export function createGetRoutes(router: Router | any, withLayout?: boolean): () => RouteRecordRaw[]
|
|
8
|
-
export function setupLayouts(routes: readonly RouteRecordRaw[]): RouteRecordRaw[]
|
|
9
|
-
export function setPageLayout(name: LayoutName, props?: LayoutProps): void
|
|
10
|
-
export function useLayout(): import('vue').ComputedRef<LayoutName>
|
|
11
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "vite";
|
|
2
|
-
//#region src/types.d.ts
|
|
3
|
-
interface Options {
|
|
4
|
-
/**
|
|
5
|
-
* Relative path to the directory to search for layout components.
|
|
6
|
-
* @default 'src/layouts'
|
|
7
|
-
*/
|
|
8
|
-
layoutsDirs: string | string[];
|
|
9
|
-
/**
|
|
10
|
-
* Valid file extensions for layout components.
|
|
11
|
-
* @default ['vue']
|
|
12
|
-
*/
|
|
13
|
-
extensions: string[];
|
|
14
|
-
/**
|
|
15
|
-
* List of path globs to exclude when resolving layouts.
|
|
16
|
-
*/
|
|
17
|
-
exclude: string[];
|
|
18
|
-
/**
|
|
19
|
-
* Normalized layout name/key to use as the default layout
|
|
20
|
-
* (for example, myDefault.vue -> my-default)
|
|
21
|
-
* @default 'default'
|
|
22
|
-
*/
|
|
23
|
-
defaultLayout: string;
|
|
24
|
-
/**
|
|
25
|
-
* Layout name/key to render when a page asks for a layout that does not exist.
|
|
26
|
-
* Defaults to `defaultLayout`.
|
|
27
|
-
*/
|
|
28
|
-
fallbackLayout?: string;
|
|
29
|
-
/**
|
|
30
|
-
* `sync` bundles a layout into the main chunk, `async` lazy-loads it.
|
|
31
|
-
* Defaults to `sync` for `default` (and for every layout under `VITE_SSG`), `async` otherwise.
|
|
32
|
-
*/
|
|
33
|
-
importMode: (name: string) => 'sync' | 'async';
|
|
34
|
-
/**
|
|
35
|
-
* Whether nested routes should inherit the default layout from parent routes.
|
|
36
|
-
* When false, if a child route has its own layout, the parent route won't use the default layout.
|
|
37
|
-
* @default true
|
|
38
|
-
*/
|
|
39
|
-
inheritDefaultLayout: boolean;
|
|
40
|
-
}
|
|
41
|
-
export interface FileContainer {
|
|
42
|
-
path: string;
|
|
43
|
-
files: string[];
|
|
44
|
-
}
|
|
45
|
-
export type UserOptions = Partial<Options>;
|
|
46
|
-
export interface ResolvedOptions extends Options {}
|
|
47
|
-
export interface clientSideOptions {
|
|
48
|
-
/**
|
|
49
|
-
* Relative path to the directory to search for layout components.
|
|
50
|
-
* Same name as the default plugin's option, but a single directory: no array, no glob.
|
|
51
|
-
* @default "src/layouts"
|
|
52
|
-
*/
|
|
53
|
-
layoutsDirs?: string;
|
|
54
|
-
/**
|
|
55
|
-
* @deprecated Use `layoutsDirs` instead. Ignored when `layoutsDirs` is set.
|
|
56
|
-
*/
|
|
57
|
-
layoutDir?: string;
|
|
58
|
-
/**
|
|
59
|
-
* normalized layout name/key to use as the default layout
|
|
60
|
-
* (for example, myDefault.vue -> my-default)
|
|
61
|
-
* @default "default"
|
|
62
|
-
*/
|
|
63
|
-
defaultLayout?: string;
|
|
64
|
-
/**
|
|
65
|
-
* Layout name/key to render when a page asks for a layout that does not exist.
|
|
66
|
-
* Defaults to `defaultLayout`.
|
|
67
|
-
*/
|
|
68
|
-
fallbackLayout?: string;
|
|
69
|
-
/**
|
|
70
|
-
* `sync` bundles every layout into the main chunk, `async` lazy-loads them.
|
|
71
|
-
* Defaults to `sync` under `VITE_SSG`, `async` otherwise.
|
|
72
|
-
*/
|
|
73
|
-
importMode?: 'sync' | 'async';
|
|
74
|
-
/**
|
|
75
|
-
* Whether nested routes should inherit the default layout from parent routes.
|
|
76
|
-
* When false, if a child route has its own layout, the parent route won't use the default layout.
|
|
77
|
-
* @default true
|
|
78
|
-
*/
|
|
79
|
-
inheritDefaultLayout?: boolean;
|
|
80
|
-
}
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/index.d.ts
|
|
83
|
-
export declare function defaultImportMode(name: string): "sync" | "async";
|
|
84
|
-
export default function Layout(userOptions?: UserOptions): Plugin;
|
|
85
|
-
export declare function ClientSideLayout(options?: clientSideOptions): Plugin;
|
|
86
|
-
//#endregion
|
package/vendor/layouts/index.mjs
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { t as normalizeLayoutName } from "./layoutName-DVkP7Qpo.mjs";
|
|
2
|
-
import { posix, resolve } from "node:path";
|
|
3
|
-
import process from "node:process";
|
|
4
|
-
import { glob, globSync } from "tinyglobby";
|
|
5
|
-
import Debug from "debug";
|
|
6
|
-
//#region src/RouteLayout.ts
|
|
7
|
-
const RUNTIME_ID = "valaxy/vendor/layouts/runtime.mjs";
|
|
8
|
-
function getClientCode(importCode, options) {
|
|
9
|
-
const inheritDefaultLayout = options.inheritDefaultLayout ?? true;
|
|
10
|
-
const fallbackArg = options.fallbackLayout ? `, '${options.fallbackLayout}'` : "";
|
|
11
|
-
return `
|
|
12
|
-
import { createGetRoutes, createLayoutWrapper, createSetupLayouts, lazyLayout, setPageLayout, useLayout } from '${RUNTIME_ID}'
|
|
13
|
-
export { createGetRoutes, setPageLayout, useLayout }
|
|
14
|
-
${importCode}
|
|
15
|
-
const LayoutWrapper = createLayoutWrapper(layouts, '${options.defaultLayout}'${fallbackArg})
|
|
16
|
-
export const setupLayouts = createSetupLayouts(LayoutWrapper, { inheritDefaultLayout: ${inheritDefaultLayout} })
|
|
17
|
-
`;
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/clientSide.ts
|
|
21
|
-
function normalizePath$1(path) {
|
|
22
|
-
path = path.startsWith("/") ? path : `/${path}`;
|
|
23
|
-
return posix.normalize(path);
|
|
24
|
-
}
|
|
25
|
-
async function createVirtualModuleCode(options) {
|
|
26
|
-
const { layoutDir, defaultLayout, fallbackLayout, importMode, inheritDefaultLayout = true } = options;
|
|
27
|
-
const normalizedTarget = normalizePath$1(layoutDir);
|
|
28
|
-
const isSync = importMode === "sync";
|
|
29
|
-
const fallbackArg = fallbackLayout ? `, '${fallbackLayout}'` : "";
|
|
30
|
-
return `
|
|
31
|
-
import { createGetRoutes, createLayoutWrapper, createSetupLayouts, lazyLayout, normalizeLayoutName, setPageLayout, useLayout } from '${RUNTIME_ID}'
|
|
32
|
-
export { createGetRoutes, setPageLayout, useLayout }
|
|
33
|
-
|
|
34
|
-
const modules = import.meta.glob("${normalizedTarget}/**/*.vue", { eager: ${isSync} })
|
|
35
|
-
|
|
36
|
-
export const layouts = {}
|
|
37
|
-
Object.entries(modules).forEach(([name, module]) => {
|
|
38
|
-
const key = normalizeLayoutName(name.replace("${normalizedTarget}/", ''))
|
|
39
|
-
layouts[key] = ${isSync ? "module.default" : "lazyLayout(module)"}
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
const LayoutWrapper = createLayoutWrapper(layouts, '${defaultLayout}'${fallbackArg})
|
|
43
|
-
export const setupLayouts = createSetupLayouts(LayoutWrapper, { inheritDefaultLayout: ${inheritDefaultLayout} })
|
|
44
|
-
`;
|
|
45
|
-
}
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region src/utils.ts
|
|
48
|
-
const REGEX_BACKSLASH = /\\/g;
|
|
49
|
-
function extensionsToGlob(extensions) {
|
|
50
|
-
return extensions.length > 1 ? `{${extensions.join(",")}}` : extensions[0] || "";
|
|
51
|
-
}
|
|
52
|
-
function normalizePath(str) {
|
|
53
|
-
return str.replace(REGEX_BACKSLASH, "/");
|
|
54
|
-
}
|
|
55
|
-
const debug = Debug("vite-plugin-layouts-next");
|
|
56
|
-
function resolveDirs(dirs, root) {
|
|
57
|
-
if (dirs === null) return [];
|
|
58
|
-
const dirsArray = Array.isArray(dirs) ? dirs : [dirs];
|
|
59
|
-
const dirsResolved = [];
|
|
60
|
-
for (const dir of dirsArray) if (dir.includes("**")) {
|
|
61
|
-
const matches = globSync(dir, { cwd: root, onlyDirectories: true });
|
|
62
|
-
for (const match of matches) dirsResolved.push(normalizePath(resolve(root, match)));
|
|
63
|
-
} else dirsResolved.push(normalizePath(resolve(root, dir)));
|
|
64
|
-
return dirsResolved;
|
|
65
|
-
}
|
|
66
|
-
//#endregion
|
|
67
|
-
//#region src/files.ts
|
|
68
|
-
async function getFilesFromPath(path, options) {
|
|
69
|
-
const { exclude, extensions } = options;
|
|
70
|
-
const ext = extensionsToGlob(extensions);
|
|
71
|
-
debug(extensions);
|
|
72
|
-
return await glob(`**/*.${ext}`, {
|
|
73
|
-
ignore: [
|
|
74
|
-
"node_modules",
|
|
75
|
-
".git",
|
|
76
|
-
"**/__*__/*",
|
|
77
|
-
...exclude
|
|
78
|
-
],
|
|
79
|
-
onlyFiles: true,
|
|
80
|
-
cwd: path
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region src/importCode.ts
|
|
85
|
-
function getImportCode(files, options) {
|
|
86
|
-
const imports = [];
|
|
87
|
-
const head = [];
|
|
88
|
-
let id = 0;
|
|
89
|
-
for (const __ of files) for (const file of __.files) {
|
|
90
|
-
const path = __.path.startsWith("/") ? `${__.path}/${file}` : `/${__.path}/${file}`;
|
|
91
|
-
const name = normalizeLayoutName(file);
|
|
92
|
-
if (options.importMode(name) === "sync") {
|
|
93
|
-
const variable = `__layout_${id}`;
|
|
94
|
-
head.push(`import ${variable} from '${path}'`);
|
|
95
|
-
imports.push(`'${name}': ${variable},`);
|
|
96
|
-
id += 1;
|
|
97
|
-
} else imports.push(`'${name}': lazyLayout(() => import('${path}')),`);
|
|
98
|
-
}
|
|
99
|
-
return `
|
|
100
|
-
${head.join("\n")}
|
|
101
|
-
export const layouts = {
|
|
102
|
-
${imports.join("\n")}
|
|
103
|
-
}`;
|
|
104
|
-
}
|
|
105
|
-
//#endregion
|
|
106
|
-
//#region src/index.ts
|
|
107
|
-
const MODULE_ID = "virtual:generated-layouts";
|
|
108
|
-
const MODULE_ID_VIRTUAL = "/@vite-plugin-vue-layouts-next/generated-layouts";
|
|
109
|
-
function defaultImportMode(name) {
|
|
110
|
-
if (process.env.VITE_SSG) return "sync";
|
|
111
|
-
return name === "default" ? "sync" : "async";
|
|
112
|
-
}
|
|
113
|
-
function resolveOptions(userOptions) {
|
|
114
|
-
return {
|
|
115
|
-
defaultLayout: "default",
|
|
116
|
-
layoutsDirs: "src/layouts",
|
|
117
|
-
extensions: ["vue"],
|
|
118
|
-
exclude: [],
|
|
119
|
-
importMode: defaultImportMode,
|
|
120
|
-
inheritDefaultLayout: true,
|
|
121
|
-
...userOptions
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
function Layout(userOptions = {}) {
|
|
125
|
-
if (canEnableClientLayout(userOptions)) return ClientSideLayout({
|
|
126
|
-
defaultLayout: userOptions.defaultLayout,
|
|
127
|
-
fallbackLayout: userOptions.fallbackLayout,
|
|
128
|
-
layoutsDirs: userOptions.layoutsDirs,
|
|
129
|
-
inheritDefaultLayout: userOptions.inheritDefaultLayout
|
|
130
|
-
});
|
|
131
|
-
let config;
|
|
132
|
-
const options = resolveOptions(userOptions);
|
|
133
|
-
let layoutsDirs;
|
|
134
|
-
return {
|
|
135
|
-
name: "vite-plugin-vue-layouts-next",
|
|
136
|
-
enforce: "pre",
|
|
137
|
-
config() {
|
|
138
|
-
return { optimizeDeps: { include: [RUNTIME_ID] } };
|
|
139
|
-
},
|
|
140
|
-
configResolved(_config) {
|
|
141
|
-
config = _config;
|
|
142
|
-
layoutsDirs = resolveDirs(options.layoutsDirs, config.root);
|
|
143
|
-
},
|
|
144
|
-
configureServer({ moduleGraph, watcher, ws }) {
|
|
145
|
-
watcher.add(options.layoutsDirs);
|
|
146
|
-
const reloadModule = (module, path = "*") => {
|
|
147
|
-
if (module) {
|
|
148
|
-
moduleGraph.invalidateModule(module);
|
|
149
|
-
if (ws) ws.send({
|
|
150
|
-
path,
|
|
151
|
-
type: "full-reload"
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
const updateVirtualModule = (path) => {
|
|
156
|
-
path = normalizePath(path);
|
|
157
|
-
if (layoutsDirs.some((dir) => path.startsWith(dir))) {
|
|
158
|
-
debug("reload", path);
|
|
159
|
-
const module = moduleGraph.getModuleById(MODULE_ID_VIRTUAL);
|
|
160
|
-
reloadModule(module);
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
watcher.on("add", (path) => {
|
|
164
|
-
updateVirtualModule(path);
|
|
165
|
-
});
|
|
166
|
-
watcher.on("unlink", (path) => {
|
|
167
|
-
updateVirtualModule(path);
|
|
168
|
-
});
|
|
169
|
-
watcher.on("change", async (path) => {
|
|
170
|
-
updateVirtualModule(path);
|
|
171
|
-
});
|
|
172
|
-
},
|
|
173
|
-
resolveId(id) {
|
|
174
|
-
return id === MODULE_ID || id.startsWith(MODULE_ID) ? MODULE_ID_VIRTUAL : null;
|
|
175
|
-
},
|
|
176
|
-
async load(id) {
|
|
177
|
-
if (id === MODULE_ID_VIRTUAL) {
|
|
178
|
-
const container = [];
|
|
179
|
-
for (const dir of layoutsDirs) {
|
|
180
|
-
const layoutsDirPath = dir.startsWith("/") ? normalizePath(dir) : normalizePath(resolve(config.root, dir));
|
|
181
|
-
debug("Loading Layout Dir: %O", layoutsDirPath);
|
|
182
|
-
const _f = await getFilesFromPath(layoutsDirPath, options);
|
|
183
|
-
container.push({
|
|
184
|
-
path: layoutsDirPath,
|
|
185
|
-
files: _f
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
const clientCode = getClientCode(getImportCode(container, options), options);
|
|
189
|
-
debug("Client code: %O", clientCode);
|
|
190
|
-
return {
|
|
191
|
-
code: clientCode,
|
|
192
|
-
moduleType: "js"
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function ClientSideLayout(options) {
|
|
199
|
-
const { layoutsDirs, layoutDir: legacyLayoutDir, defaultLayout = "default", fallbackLayout, importMode = process.env.VITE_SSG ? "sync" : "async", inheritDefaultLayout = true } = options || {};
|
|
200
|
-
const layoutDir = layoutsDirs ?? legacyLayoutDir ?? "src/layouts";
|
|
201
|
-
return {
|
|
202
|
-
name: "vite-plugin-vue-layouts-next",
|
|
203
|
-
config() {
|
|
204
|
-
return { optimizeDeps: { include: [RUNTIME_ID] } };
|
|
205
|
-
},
|
|
206
|
-
resolveId(id) {
|
|
207
|
-
if (id === MODULE_ID) return `\0${MODULE_ID}`;
|
|
208
|
-
},
|
|
209
|
-
async load(id) {
|
|
210
|
-
if (id === `\0${MODULE_ID}`) return {
|
|
211
|
-
code: await createVirtualModuleCode({
|
|
212
|
-
layoutDir,
|
|
213
|
-
importMode,
|
|
214
|
-
defaultLayout,
|
|
215
|
-
fallbackLayout,
|
|
216
|
-
inheritDefaultLayout
|
|
217
|
-
}),
|
|
218
|
-
moduleType: "js"
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
function canEnableClientLayout(options) {
|
|
224
|
-
const keys = Object.keys(options);
|
|
225
|
-
if (keys.length > 4 || keys.some((key) => ![
|
|
226
|
-
"layoutsDirs",
|
|
227
|
-
"defaultLayout",
|
|
228
|
-
"fallbackLayout",
|
|
229
|
-
"inheritDefaultLayout"
|
|
230
|
-
].includes(key))) return false;
|
|
231
|
-
if (options.layoutsDirs && (Array.isArray(options.layoutsDirs) || options.layoutsDirs.includes("*"))) return false;
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
//#endregion
|
|
235
|
-
export { ClientSideLayout, Layout as default, defaultImportMode };
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
//#region src/layoutName.ts
|
|
2
|
-
const REGEX_BACKSLASH = /\\/g;
|
|
3
|
-
const REGEX_SEPARATORS = /[-_/.\s]+/g;
|
|
4
|
-
const REGEX_NON_ALPHANUMERIC = /[^a-z0-9-]+/gi;
|
|
5
|
-
const REGEX_REPEATED_DASH = /-+/g;
|
|
6
|
-
const REGEX_EDGE_DASH = /^-|-$/g;
|
|
7
|
-
const REGEX_NUMBER = /\d/;
|
|
8
|
-
function isUppercase(char = "") {
|
|
9
|
-
if (REGEX_NUMBER.test(char)) return void 0;
|
|
10
|
-
return char !== char.toLowerCase();
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Where a word boundary falls when `char` follows `buffer` with no separator:
|
|
14
|
-
* `before` for `aB`, `after` for `ABc` (the last upper starts the next word).
|
|
15
|
-
*/
|
|
16
|
-
function caseBoundary(previousUpper, isUpper, buffer) {
|
|
17
|
-
if (previousUpper === false && isUpper === true) return "before";
|
|
18
|
-
if (previousUpper === true && isUpper === false && buffer.length > 1) return "after";
|
|
19
|
-
}
|
|
20
|
-
function splitByCase(value) {
|
|
21
|
-
const parts = [];
|
|
22
|
-
let buffer = "";
|
|
23
|
-
let previousUpper;
|
|
24
|
-
let previousSplitter;
|
|
25
|
-
const flush = () => {
|
|
26
|
-
if (buffer) parts.push(buffer);
|
|
27
|
-
};
|
|
28
|
-
for (const char of value) {
|
|
29
|
-
const isSplitter = REGEX_SEPARATORS.test(char);
|
|
30
|
-
REGEX_SEPARATORS.lastIndex = 0;
|
|
31
|
-
if (isSplitter) {
|
|
32
|
-
flush();
|
|
33
|
-
buffer = "";
|
|
34
|
-
previousUpper = void 0;
|
|
35
|
-
previousSplitter = true;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
const isUpper = isUppercase(char);
|
|
39
|
-
const boundary = previousSplitter === false ? caseBoundary(previousUpper, isUpper, buffer) : void 0;
|
|
40
|
-
if (boundary === "before") {
|
|
41
|
-
flush();
|
|
42
|
-
buffer = char;
|
|
43
|
-
} else if (boundary === "after") {
|
|
44
|
-
parts.push(buffer.slice(0, -1));
|
|
45
|
-
buffer = buffer.at(-1) + char;
|
|
46
|
-
} else buffer += char;
|
|
47
|
-
previousUpper = isUpper;
|
|
48
|
-
previousSplitter = false;
|
|
49
|
-
}
|
|
50
|
-
flush();
|
|
51
|
-
return parts;
|
|
52
|
-
}
|
|
53
|
-
function kebabCaseSegments(segments) {
|
|
54
|
-
return segments.map((segment) => segment.toLowerCase()).join("-").replace(REGEX_NON_ALPHANUMERIC, "-").replace(REGEX_REPEATED_DASH, "-").replace(REGEX_EDGE_DASH, "");
|
|
55
|
-
}
|
|
56
|
-
function resolveLayoutNameSegments(fileName, prefixParts) {
|
|
57
|
-
const fileNameParts = splitByCase(fileName);
|
|
58
|
-
const fileNamePartsContent = fileNameParts.join("/").toLowerCase();
|
|
59
|
-
const layoutNameParts = prefixParts.flatMap((part) => splitByCase(part));
|
|
60
|
-
const matchedSuffix = [];
|
|
61
|
-
let index = prefixParts.length - 1;
|
|
62
|
-
while (index >= 0) {
|
|
63
|
-
const prefixPart = prefixParts[index];
|
|
64
|
-
matchedSuffix.unshift(...splitByCase(prefixPart).map((part) => part.toLowerCase()));
|
|
65
|
-
const matchedSuffixContent = matchedSuffix.join("/");
|
|
66
|
-
if (fileNamePartsContent === matchedSuffixContent || fileNamePartsContent.startsWith(`${matchedSuffixContent}/`) || prefixPart.toLowerCase() === fileNamePartsContent && prefixParts[index + 1] && prefixParts[index] === prefixParts[index + 1]) layoutNameParts.length = index;
|
|
67
|
-
index -= 1;
|
|
68
|
-
}
|
|
69
|
-
return [...layoutNameParts, ...fileNameParts];
|
|
70
|
-
}
|
|
71
|
-
function normalizeLayoutName(file) {
|
|
72
|
-
const normalizedFile = file.replace(REGEX_BACKSLASH, "/");
|
|
73
|
-
const slashIndex = normalizedFile.lastIndexOf("/");
|
|
74
|
-
const dir = slashIndex === -1 ? "" : normalizedFile.slice(0, slashIndex);
|
|
75
|
-
const basename = slashIndex === -1 ? normalizedFile : normalizedFile.slice(slashIndex + 1);
|
|
76
|
-
const dotIndex = basename.lastIndexOf(".");
|
|
77
|
-
const name = dotIndex <= 0 ? basename : basename.slice(0, dotIndex);
|
|
78
|
-
const prefixParts = splitByCase(dir);
|
|
79
|
-
return kebabCaseSegments(resolveLayoutNameSegments(dir && name.toLowerCase() === "index" ? "" : name, prefixParts).filter(Boolean));
|
|
80
|
-
}
|
|
81
|
-
//#endregion
|
|
82
|
-
export { normalizeLayoutName as t };
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Component, ComputedRef } from "vue";
|
|
2
|
-
import { RouteRecordRaw, Router } from "vue-router";
|
|
3
|
-
//#region src/runtime/layoutMeta.d.ts
|
|
4
|
-
type LayoutName = string | false;
|
|
5
|
-
type LayoutProps = Record<string, unknown>;
|
|
6
|
-
/** Object form of `meta.layout`. */
|
|
7
|
-
interface LayoutOptions {
|
|
8
|
-
/** Layout name, `false` for no layout, or omitted for the default layout. */
|
|
9
|
-
name?: LayoutName;
|
|
10
|
-
props?: LayoutProps;
|
|
11
|
-
}
|
|
12
|
-
type LayoutMeta = LayoutName | LayoutOptions;
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/layoutName.d.ts
|
|
15
|
-
export declare function normalizeLayoutName(file: string): string;
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/runtime/setupLayouts.d.ts
|
|
18
|
-
interface SetupLayoutsOptions {
|
|
19
|
-
inheritDefaultLayout: boolean;
|
|
20
|
-
}
|
|
21
|
-
/** Without `withLayout`, the returned getter hides the generated layout routes. */
|
|
22
|
-
export declare function createGetRoutes(router: Router, withLayout: true): RouteRecordRaw[];
|
|
23
|
-
export declare function createGetRoutes(router: Router, withLayout?: false): () => RouteRecordRaw[];
|
|
24
|
-
export declare function createSetupLayouts(wrapper: Component, options: SetupLayoutsOptions): (routes: readonly RouteRecordRaw[]) => RouteRecordRaw[];
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/runtime/wrapper.d.ts
|
|
27
|
-
declare const LAZY: unique symbol;
|
|
28
|
-
type LazyLayout = (() => Promise<{
|
|
29
|
-
default: Component;
|
|
30
|
-
} | Component>) & {
|
|
31
|
-
[LAZY]: true;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Both virtual-module generators wrap their async imports with this, so a lazy entry
|
|
35
|
-
* is always identified explicitly rather than guessed from its shape - unlike Vue
|
|
36
|
-
* Router's route components, a bare functional component (e.g. an arrow-function
|
|
37
|
-
* default export from a `.tsx` layout) is a perfectly valid, non-lazy layout here.
|
|
38
|
-
*/
|
|
39
|
-
export declare function lazyLayout(loader: () => Promise<{
|
|
40
|
-
default: Component;
|
|
41
|
-
} | Component>): LazyLayout;
|
|
42
|
-
type LayoutMap = Record<string, Component | LazyLayout>;
|
|
43
|
-
/**
|
|
44
|
-
* Change the layout of the current page without navigating, optionally passing props
|
|
45
|
-
* to the layout component. The override lasts until the router navigates to a different `path`.
|
|
46
|
-
*/
|
|
47
|
-
export declare function setPageLayout(name: LayoutName, props?: LayoutProps): void;
|
|
48
|
-
/**
|
|
49
|
-
* Reactive name of the layout resolved for the current route.
|
|
50
|
-
* `false` when no wrapper is rendered around it (a static `layout: false` route, or
|
|
51
|
-
* one deliberately left unwrapped because `inheritDefaultLayout` is `false`).
|
|
52
|
-
*/
|
|
53
|
-
export declare function useLayout(): ComputedRef<LayoutName>;
|
|
54
|
-
/** `fallbackLayout` is rendered when the requested layout is not in `layouts`; if it is missing too, the page renders without a layout. */
|
|
55
|
-
export declare function createLayoutWrapper(layouts: LayoutMap, defaultLayout: string, fallbackLayout?: string): Component;
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/runtime/index.d.ts
|
|
58
|
-
declare module 'vue-router' {
|
|
59
|
-
interface RouteMeta {
|
|
60
|
-
/**
|
|
61
|
-
* Layout name for this page, `false` to render without a layout, or
|
|
62
|
-
* `{ name, props }` to also pass props to the layout component.
|
|
63
|
-
*/
|
|
64
|
-
layout?: LayoutMeta;
|
|
65
|
-
/** Props for the layout component; `layout.props` in the object form wins over this. */
|
|
66
|
-
layoutProps?: LayoutProps;
|
|
67
|
-
/** Set on the generated parent routes created by `setupLayouts`. */
|
|
68
|
-
isLayout?: boolean;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
|
-
export type { LayoutMap, LayoutMeta, LayoutName, LayoutOptions, LayoutProps, LazyLayout, SetupLayoutsOptions };
|