nuxt-loaders 1.0.1 → 1.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/README.md +20 -4
- package/dist/bin/loaders.mjs +0 -0
- package/dist/module.d.mts +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +2 -2
- package/dist/runtime/components/DefaultLoader.d.vue.ts +8 -0
- package/dist/runtime/components/DefaultLoader.vue +20 -0
- package/dist/runtime/components/DefaultLoader.vue.d.ts +8 -0
- package/dist/runtime/components/Loader.d.vue.ts +6 -1
- package/dist/runtime/components/Loader.vue +5 -2
- package/dist/runtime/components/Loader.vue.d.ts +6 -1
- package/dist/runtime/lib/utils/route-rules.d.ts +1 -1
- package/dist/runtime/lib/utils/route-rules.js +12 -6
- package/dist/runtime/tailwind.css +1 -1
- package/package.json +13 -15
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ export default defineNuxtConfig({
|
|
|
64
64
|
// Define rules for which loader to use on which route
|
|
65
65
|
routeRules: {
|
|
66
66
|
"/": "MyLoader",
|
|
67
|
-
"/admin
|
|
67
|
+
"/admin/*": "AdminLoader",
|
|
68
68
|
},
|
|
69
69
|
},
|
|
70
70
|
});
|
|
@@ -80,9 +80,25 @@ export default defineNuxtConfig({
|
|
|
80
80
|
|
|
81
81
|
## Usage
|
|
82
82
|
|
|
83
|
-
1.
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
1. **Add the Loader Component**:
|
|
84
|
+
Add the `<Loader />` component to your `app.vue` (or layout) and control its visibility using `useLoader`.
|
|
85
|
+
|
|
86
|
+
```vue
|
|
87
|
+
<script setup lang="ts">
|
|
88
|
+
const { isLoading } = useLoader();
|
|
89
|
+
</script>
|
|
90
|
+
|
|
91
|
+
<template>
|
|
92
|
+
<Loader v-if="isLoading" />
|
|
93
|
+
<NuxtPage />
|
|
94
|
+
</template>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
2. **Create your loader components**:
|
|
98
|
+
Place them in `app/components/loaders` (or your configured `loadersDir`).
|
|
99
|
+
|
|
100
|
+
3. **Configure Route Rules**:
|
|
101
|
+
Use `routeRules` in your `nuxt.config.ts` to specify which loader should be active for specific routes.
|
|
86
102
|
|
|
87
103
|
Example loader component (`app/components/loaders/MyLoader.vue`):
|
|
88
104
|
|
package/dist/bin/loaders.mjs
CHANGED
|
File without changes
|
package/dist/module.d.mts
CHANGED
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -14,7 +14,7 @@ const module$1 = defineNuxtModule({
|
|
|
14
14
|
defaults: {
|
|
15
15
|
autoSetup: true,
|
|
16
16
|
routeRules: {},
|
|
17
|
-
_defaultLoader: "",
|
|
17
|
+
_defaultLoader: "DefaultLoader",
|
|
18
18
|
_activeLoader: ""
|
|
19
19
|
},
|
|
20
20
|
async setup(options, nuxt) {
|
|
@@ -74,7 +74,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
74
74
|
if (options.routeRules && Object.keys(options.routeRules).length > 0) {
|
|
75
75
|
nuxt.options.runtimeConfig.public.loaders._activeLoader = getDefaultLoader(validatedLoaderRules) ?? "";
|
|
76
76
|
}
|
|
77
|
-
nuxt.options.runtimeConfig.public.loaders._defaultLoader = getDefaultLoader(validatedLoaderRules) ?? "";
|
|
77
|
+
nuxt.options.runtimeConfig.public.loaders._defaultLoader = getDefaultLoader(validatedLoaderRules) ?? "DefaultLoader";
|
|
78
78
|
addPlugin(resolver.resolve("./runtime/plugin"));
|
|
79
79
|
}
|
|
80
80
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
className?: string;
|
|
3
|
+
};
|
|
4
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
5
|
+
className: string;
|
|
6
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
|
+
declare const _default: typeof __VLS_export;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="['loader', className]">
|
|
3
|
+
<h1>Loading{{ dots }}</h1>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup>
|
|
8
|
+
import { onMounted, onUnmounted, ref } from "vue";
|
|
9
|
+
const dots = ref(".");
|
|
10
|
+
let interval;
|
|
11
|
+
onMounted(() => {
|
|
12
|
+
interval = setInterval(() => {
|
|
13
|
+
dots.value = dots.value.length >= 3 ? "." : dots.value + ".";
|
|
14
|
+
}, 500);
|
|
15
|
+
});
|
|
16
|
+
onUnmounted(() => clearInterval(interval));
|
|
17
|
+
defineProps({
|
|
18
|
+
className: { type: String, required: false, default: "" }
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
className?: string;
|
|
3
|
+
};
|
|
4
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
5
|
+
className: string;
|
|
6
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
|
+
declare const _default: typeof __VLS_export;
|
|
8
|
+
export default _default;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
className?: string;
|
|
3
|
+
};
|
|
4
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
5
|
+
className: string;
|
|
6
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
2
7
|
declare const _default: typeof __VLS_export;
|
|
3
8
|
export default _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<component :is="loaderName"
|
|
2
|
+
<div :class="[className, 'w-[100vw] h-[100svh] absolute top-0 left-0 z-50 grid place-items-center bg-white']">
|
|
3
|
+
<component :is="loaderName" />
|
|
4
4
|
</div>
|
|
5
5
|
</template>
|
|
6
6
|
|
|
@@ -17,4 +17,7 @@ const loaderName = computed(() => {
|
|
|
17
17
|
}
|
|
18
18
|
return name;
|
|
19
19
|
});
|
|
20
|
+
defineProps({
|
|
21
|
+
className: { type: String, required: false, default: "" }
|
|
22
|
+
});
|
|
20
23
|
</script>
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
className?: string;
|
|
3
|
+
};
|
|
4
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
5
|
+
className: string;
|
|
6
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
2
7
|
declare const _default: typeof __VLS_export;
|
|
3
8
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const validateLoaderRules: (routeRules: Record<string, string>) => Record<string, string>;
|
|
2
|
-
export declare const getDefaultLoader: (routeRules: Record<string, string
|
|
2
|
+
export declare const getDefaultLoader: (routeRules: Record<string, string>, defaultLoaderName?: string) => string | undefined;
|
|
3
3
|
export declare const getActiveLoader: (routeRules: Record<string, string>, path: string) => string | undefined;
|
|
@@ -13,11 +13,11 @@ const checkRoutePatternValidity = (route) => {
|
|
|
13
13
|
if (route === "*" || route === "/") {
|
|
14
14
|
return { valid: true };
|
|
15
15
|
}
|
|
16
|
-
const routePattern = /^\/[\w\-/]
|
|
16
|
+
const routePattern = /^\/[\w\-/]*(?:\/\*)?$/;
|
|
17
17
|
if (!routePattern.test(route)) {
|
|
18
18
|
return {
|
|
19
19
|
valid: false,
|
|
20
|
-
reason: "Route pattern is invalid. Must start with '/' and contain only alphanumeric characters, hyphens, underscores, or slashes."
|
|
20
|
+
reason: "Route pattern is invalid. Must start with '/' and contain only alphanumeric characters, hyphens, underscores, astrix or slashes."
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
return { valid: true };
|
|
@@ -62,22 +62,28 @@ export const validateLoaderRules = (routeRules) => {
|
|
|
62
62
|
});
|
|
63
63
|
return newRules;
|
|
64
64
|
};
|
|
65
|
-
export const getDefaultLoader = (routeRules) => {
|
|
65
|
+
export const getDefaultLoader = (routeRules, defaultLoaderName = "DefaultLoader") => {
|
|
66
66
|
const defaultLoader = Object.keys(routeRules).filter((key) => {
|
|
67
67
|
return key === "*" || key === "/";
|
|
68
68
|
});
|
|
69
69
|
if (defaultLoader.length <= 0) {
|
|
70
|
-
return
|
|
70
|
+
return defaultLoaderName;
|
|
71
71
|
}
|
|
72
72
|
if (defaultLoader.length > 1) {
|
|
73
73
|
return routeRules["*"];
|
|
74
74
|
}
|
|
75
|
-
return routeRules[defaultLoader[0]];
|
|
75
|
+
return routeRules[defaultLoader[0]] || defaultLoaderName;
|
|
76
76
|
};
|
|
77
77
|
export const getActiveLoader = (routeRules, path) => {
|
|
78
|
+
if (path.endsWith("/")) {
|
|
79
|
+
path = path.substring(0, -1);
|
|
80
|
+
}
|
|
78
81
|
const rules = Object.keys(routeRules).filter((rule2) => {
|
|
82
|
+
if (rule2.endsWith("/")) {
|
|
83
|
+
rule2 = rule2.substring(0, -1);
|
|
84
|
+
}
|
|
79
85
|
if (!path.startsWith(rule2)) return false;
|
|
80
|
-
if (!
|
|
86
|
+
if (!rule2.endsWith("/*") && path != rule2) return false;
|
|
81
87
|
return true;
|
|
82
88
|
});
|
|
83
89
|
if (rules.length <= 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
@import "tailwindcss";
|
|
1
|
+
@import "tailwindcss";@source "./**/*.{vue,js,ts,html}";@source "../components/**/*.{vue,js,ts}";@source "../pages/**/*.{vue,js,ts}";@source "../layouts/**/*.{vue,js,ts}";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-loaders",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Simple loading screen engine for Nuxt 4+",
|
|
5
5
|
"repository": "haileabt/nuxt-loaders",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,18 +25,6 @@
|
|
|
25
25
|
"bin": {
|
|
26
26
|
"loaders": "./dist/bin/loaders.mjs"
|
|
27
27
|
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"prepack": "nuxt-module-build build",
|
|
30
|
-
"dev": "npm run dev:prepare && nuxi dev playground",
|
|
31
|
-
"dev:build": "nuxi build playground",
|
|
32
|
-
"cli:build": "tsc",
|
|
33
|
-
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
34
|
-
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
35
|
-
"lint": "eslint .",
|
|
36
|
-
"test": "vitest run",
|
|
37
|
-
"test:watch": "vitest watch",
|
|
38
|
-
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
39
|
-
},
|
|
40
28
|
"dependencies": {
|
|
41
29
|
"@nuxt/kit": "^4.2.1",
|
|
42
30
|
"@tailwindcss/vite": "^4.1.18",
|
|
@@ -58,5 +46,15 @@
|
|
|
58
46
|
"vitest": "^3.2.0",
|
|
59
47
|
"vue-tsc": "^3.1.7"
|
|
60
48
|
},
|
|
61
|
-
"
|
|
62
|
-
|
|
49
|
+
"scripts": {
|
|
50
|
+
"dev": "npm run dev:prepare && nuxi dev playground",
|
|
51
|
+
"dev:build": "nuxi build playground",
|
|
52
|
+
"cli:build": "tsc",
|
|
53
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
54
|
+
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
55
|
+
"lint": "eslint .",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"test:watch": "vitest watch",
|
|
58
|
+
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
59
|
+
}
|
|
60
|
+
}
|