@inzombieland/nuxt-common 1.16.27 → 1.16.29
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/module.json +1 -1
- package/dist/module.mjs +2 -2
- package/dist/runtime/api/user-actions.mjs +3 -2
- package/dist/runtime/composables/use-theme-mode.d.ts +3 -0
- package/dist/runtime/composables/use-theme-mode.mjs +3 -0
- package/dist/runtime/packages/api/AppProvider.vue +36 -0
- package/dist/runtime/packages/api/composables/use-theme-mode.d.ts +1 -0
- package/dist/runtime/packages/api/composables/use-theme-mode.mjs +14 -0
- package/dist/runtime/packages/api/index.d.ts +2 -0
- package/dist/runtime/packages/api/index.mjs +2 -0
- package/dist/runtime/packages/api/init-application.mjs +26 -20
- package/dist/runtime/packages/api/package.json +1 -1
- package/dist/runtime/plugin.mjs +14 -1
- package/dist/runtime/plugins/device.mjs +1 -1
- package/package.json +1 -1
- package/dist/runtime/AppProvider.vue +0 -75
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
2
2
|
import { defineNuxtModule, createResolver, addServerHandler, addImportsDir, addPlugin, addComponent } from '@nuxt/kit';
|
|
3
3
|
|
|
4
4
|
const name = "@inzombieland/nuxt-common";
|
|
5
|
-
const version = "1.16.
|
|
5
|
+
const version = "1.16.29";
|
|
6
6
|
|
|
7
7
|
const module = defineNuxtModule({
|
|
8
8
|
meta: {
|
|
@@ -54,7 +54,7 @@ const module = defineNuxtModule({
|
|
|
54
54
|
addPlugin(resolve(runtimeDir, "plugins/sanitize-url"));
|
|
55
55
|
addComponent({
|
|
56
56
|
name: "NuxtAppProvider",
|
|
57
|
-
filePath: resolve(runtimeDir, "AppProvider.vue")
|
|
57
|
+
filePath: resolve(runtimeDir, "packages/api/AppProvider.vue")
|
|
58
58
|
});
|
|
59
59
|
addComponent({
|
|
60
60
|
name: "NuxtLayerManager",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useLocalStorage } from "@vueuse/core";
|
|
2
2
|
import { useCookie, useRequestHeaders } from "#imports";
|
|
3
|
+
import { useThemeMode } from "../packages/api/index.mjs";
|
|
3
4
|
import { flush, setToken, updateUser } from "../packages/api/api-client.mjs";
|
|
4
5
|
import { fetch, getUser, userActions, useUser } from "./index.mjs";
|
|
5
6
|
export const signIn = userActions.signIn;
|
|
@@ -121,8 +122,8 @@ export const changeTheme = async (body) => {
|
|
|
121
122
|
updateUser(body);
|
|
122
123
|
}
|
|
123
124
|
if (typeof window !== "undefined") {
|
|
124
|
-
const theme =
|
|
125
|
-
theme.value =
|
|
125
|
+
const theme = useThemeMode();
|
|
126
|
+
theme.value = { value: body.theme };
|
|
126
127
|
}
|
|
127
128
|
};
|
|
128
129
|
export const changeLocale = async (body) => {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onMounted, ref } from "vue"
|
|
3
|
+
import bus from "./bus"
|
|
4
|
+
import { useThemeMode, useUser } from "./index"
|
|
5
|
+
import type { ConfigProviderTheme } from "vant"
|
|
6
|
+
import "@vant/touch-emulator"
|
|
7
|
+
|
|
8
|
+
const theme = useThemeMode()
|
|
9
|
+
const user = useUser()
|
|
10
|
+
const appLoading = ref(Boolean(user.value))
|
|
11
|
+
|
|
12
|
+
onMounted(() => {
|
|
13
|
+
appLoading.value = false
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
if (typeof window !== "undefined") {
|
|
17
|
+
bus.publish("app:beforeMount", true)
|
|
18
|
+
}
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<div
|
|
23
|
+
class="h-full"
|
|
24
|
+
:class="{ app: appLoading }"
|
|
25
|
+
>
|
|
26
|
+
<slot />
|
|
27
|
+
<van-config-provider
|
|
28
|
+
v-if="theme?.value"
|
|
29
|
+
:theme="theme?.value as ConfigProviderTheme"
|
|
30
|
+
/>
|
|
31
|
+
</div>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<style scoped>
|
|
35
|
+
.app{height:0;width:0}.app:after{background:#5a5a5a url(/images/loading.gif) no-repeat 50%;content:"";height:100%;left:0;position:absolute;top:0;transition:.5s;width:100%;z-index:10000}
|
|
36
|
+
</style>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useThemeMode: () => import("@vueuse/shared").RemovableRef<any>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useLocalStorage, usePreferredDark } from "@vueuse/core";
|
|
2
|
+
export const useThemeMode = () => {
|
|
3
|
+
const isDark = usePreferredDark();
|
|
4
|
+
return useLocalStorage(
|
|
5
|
+
"app-preferences-theme",
|
|
6
|
+
{ value: isDark.value ? "dark" : "light" },
|
|
7
|
+
{
|
|
8
|
+
serializer: {
|
|
9
|
+
read: (v) => v ? JSON.parse(v) : null,
|
|
10
|
+
write: (v) => JSON.stringify(v)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
);
|
|
14
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type Ref } from "vue";
|
|
2
2
|
import type { ActiveSession, Fetch, FetchConfig, User } from "./types";
|
|
3
3
|
export type { ActiveSession, Fetch, FetchConfig, User };
|
|
4
|
+
export { default as AppProvider } from "./AppProvider.vue";
|
|
4
5
|
export { useUser } from "./composables/use-user";
|
|
5
6
|
export { useSubscribe } from "./composables/use-subscribe";
|
|
6
7
|
export { useActiveSessions } from "./composables/use-active-sessions";
|
|
8
|
+
export { useThemeMode } from "./composables/use-theme-mode";
|
|
7
9
|
export { getVisitor, getVisitorId, type Visitor } from "./get-visitor";
|
|
8
10
|
export declare function initApiFetch($fetch: Fetch, config: FetchConfig): {
|
|
9
11
|
fetch: Fetch;
|
|
@@ -9,9 +9,11 @@ import { createApiGetVisitorIdentifier } from "./get-visitor.mjs";
|
|
|
9
9
|
import { createInitApplication } from "./init-application.mjs";
|
|
10
10
|
import { createApiRefreshToken } from "./refresh-token.mjs";
|
|
11
11
|
import { createApiUserActions } from "./user-actions.mjs";
|
|
12
|
+
export { default as AppProvider } from "./AppProvider.vue";
|
|
12
13
|
export { useUser } from "./composables/use-user.mjs";
|
|
13
14
|
export { useSubscribe } from "./composables/use-subscribe.mjs";
|
|
14
15
|
export { useActiveSessions } from "./composables/use-active-sessions.mjs";
|
|
16
|
+
export { useThemeMode } from "./composables/use-theme-mode.mjs";
|
|
15
17
|
export { getVisitor, getVisitorId } from "./get-visitor.mjs";
|
|
16
18
|
const apiActions = useApiActions();
|
|
17
19
|
let userActions;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Locale as VarletLocale } from "@varlet/ui";
|
|
1
|
+
import { StyleProvider, Themes, Locale as VarletLocale } from "@varlet/ui";
|
|
2
2
|
import { useLocalStorage } from "@vueuse/core";
|
|
3
3
|
import { setNotifyDefaultOptions, Locale as VantLocale } from "vant";
|
|
4
4
|
import enUS from "vant/es/locale/lang/en-US";
|
|
@@ -10,31 +10,37 @@ import { useActiveSessions } from "./composables/use-active-sessions.mjs";
|
|
|
10
10
|
import { useSubscribe } from "./composables/use-subscribe.mjs";
|
|
11
11
|
import { useUser } from "./composables/use-user.mjs";
|
|
12
12
|
import { once } from "./helpers/index.mjs";
|
|
13
|
-
import { getVisitorId, useUserActions } from "./index.mjs";
|
|
13
|
+
import { getVisitorId, useThemeMode, useUserActions } from "./index.mjs";
|
|
14
14
|
function initApplication() {
|
|
15
15
|
const router = useRouter();
|
|
16
16
|
const user = useUser();
|
|
17
|
-
const theme =
|
|
17
|
+
const theme = useThemeMode();
|
|
18
18
|
const locale = useLocalStorage("app-preferences-locale", JSON.stringify({ value: "en" }));
|
|
19
19
|
const i18n = useI18n();
|
|
20
|
-
watch(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
} catch (error) {
|
|
29
|
-
console.error(`Error parsing app preferences theme:`, error);
|
|
20
|
+
watch(user, (user2) => {
|
|
21
|
+
if (user2 && user2.theme !== theme.value?.value) {
|
|
22
|
+
theme.value = { value: user2.theme };
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const { value } = JSON.parse(locale.value);
|
|
26
|
+
if (user2 && user2.locale !== value) {
|
|
27
|
+
locale.value = JSON.stringify({ value: user2.locale });
|
|
30
28
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error(`Error parsing app preferences locale:`, error);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
watch(
|
|
34
|
+
theme,
|
|
35
|
+
(theme2) => {
|
|
36
|
+
if (theme2?.value === "dark") {
|
|
37
|
+
document.documentElement.classList.remove("light", "van-theme-light");
|
|
38
|
+
document.documentElement.classList.add("dark", "van-theme-dark");
|
|
39
|
+
StyleProvider(Themes.dark);
|
|
40
|
+
} else {
|
|
41
|
+
document.documentElement.classList.remove("dark", "van-theme-dark");
|
|
42
|
+
document.documentElement.classList.add("light", "van-theme-light");
|
|
43
|
+
StyleProvider(null);
|
|
38
44
|
}
|
|
39
45
|
},
|
|
40
46
|
{ immediate: true }
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { addRouteMiddleware, defineNuxtPlugin } from "#app";
|
|
2
|
-
import { useRequestHeaders, useRuntimeConfig, useState } from "#imports";
|
|
2
|
+
import { useNuxtApp, useRequestHeaders, useRuntimeConfig, useState } from "#imports";
|
|
3
|
+
import { watch } from "vue";
|
|
3
4
|
import { fetch, getUser } from "./api/index.mjs";
|
|
4
5
|
import { authMiddleware, guestMiddleware, localeMiddleware } from "./middleware/index.mjs";
|
|
6
|
+
import { useThemeMode } from "./packages/api/index.mjs";
|
|
5
7
|
import { flush, setToken, setUser } from "./packages/api/api-client.mjs";
|
|
6
8
|
const useAuth = () => {
|
|
7
9
|
return useState("auth", () => null);
|
|
@@ -9,6 +11,8 @@ const useAuth = () => {
|
|
|
9
11
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
10
12
|
const auth = useAuth();
|
|
11
13
|
const runtimeConfig = useRuntimeConfig();
|
|
14
|
+
const { $mobileApp } = useNuxtApp();
|
|
15
|
+
const theme = useThemeMode();
|
|
12
16
|
if (runtimeConfig.public.ssr && import.meta.server || !runtimeConfig.public.ssr) {
|
|
13
17
|
flush();
|
|
14
18
|
if (import.meta.server) {
|
|
@@ -26,6 +30,15 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
26
30
|
}
|
|
27
31
|
nuxtApp.hook("app:beforeMount", () => {
|
|
28
32
|
auth.value = null;
|
|
33
|
+
watch(
|
|
34
|
+
theme,
|
|
35
|
+
(theme2) => {
|
|
36
|
+
if ($mobileApp && "changeTheme" in $mobileApp && typeof $mobileApp.changeTheme === "function") {
|
|
37
|
+
$mobileApp.changeTheme({ theme: theme2?.value });
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
{ immediate: true }
|
|
41
|
+
);
|
|
29
42
|
});
|
|
30
43
|
addRouteMiddleware("auth", authMiddleware, { global: false });
|
|
31
44
|
addRouteMiddleware("guest", guestMiddleware, { global: false });
|
|
@@ -9,7 +9,7 @@ export default defineNuxtPlugin(() => {
|
|
|
9
9
|
...device,
|
|
10
10
|
getInfo: async () => {
|
|
11
11
|
const { $mobileApp } = useNuxtApp();
|
|
12
|
-
if (device.isMobileApp && $mobileApp && typeof $mobileApp.getInfo === "function") {
|
|
12
|
+
if (device.isMobileApp && $mobileApp && "getInfo" in $mobileApp && typeof $mobileApp.getInfo === "function") {
|
|
13
13
|
const device2 = await $mobileApp.getInfo();
|
|
14
14
|
return device2.name;
|
|
15
15
|
}
|
package/package.json
CHANGED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { StyleProvider, Themes } from "@varlet/ui"
|
|
3
|
-
import { useLocalStorage } from "@vueuse/core"
|
|
4
|
-
import { useNuxtApp } from "#imports"
|
|
5
|
-
import { onMounted, ref, watch } from "vue"
|
|
6
|
-
import { useUser } from "./packages/api"
|
|
7
|
-
import bus from "./packages/api/bus"
|
|
8
|
-
import type { ConfigProviderTheme } from "vant"
|
|
9
|
-
import "@vant/touch-emulator"
|
|
10
|
-
|
|
11
|
-
const theme = ref("")
|
|
12
|
-
const appPreferencesTheme = useLocalStorage("app-preferences-theme", JSON.stringify({ value: "" }))
|
|
13
|
-
const user = useUser()
|
|
14
|
-
const appLoading = ref(Boolean(user.value))
|
|
15
|
-
const { $mobileApp } = useNuxtApp()
|
|
16
|
-
|
|
17
|
-
onMounted(() => {
|
|
18
|
-
watch(
|
|
19
|
-
appPreferencesTheme,
|
|
20
|
-
newThemeValue => {
|
|
21
|
-
try {
|
|
22
|
-
if (newThemeValue) {
|
|
23
|
-
const { value } = JSON.parse(newThemeValue)
|
|
24
|
-
theme.value = value
|
|
25
|
-
}
|
|
26
|
-
} catch (error) {
|
|
27
|
-
console.error(`Error parsing app preferences theme:`, error)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!theme.value) {
|
|
31
|
-
theme.value = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
|
|
32
|
-
appPreferencesTheme.value = JSON.stringify({ value: theme.value })
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (theme.value === "dark") {
|
|
36
|
-
document.documentElement.classList.remove("light", "van-theme-light")
|
|
37
|
-
document.documentElement.classList.add("dark", "van-theme-dark")
|
|
38
|
-
StyleProvider(Themes.dark)
|
|
39
|
-
} else {
|
|
40
|
-
document.documentElement.classList.remove("dark", "van-theme-dark")
|
|
41
|
-
document.documentElement.classList.add("light", "van-theme-light")
|
|
42
|
-
StyleProvider(null)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if ($mobileApp?.changeTheme && typeof $mobileApp.changeTheme === "function") {
|
|
46
|
-
$mobileApp.changeTheme({ theme: theme.value })
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
{ immediate: true }
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
appLoading.value = false
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
if (typeof window !== "undefined") {
|
|
56
|
-
bus.publish("app:beforeMount", true)
|
|
57
|
-
}
|
|
58
|
-
</script>
|
|
59
|
-
|
|
60
|
-
<template>
|
|
61
|
-
<div
|
|
62
|
-
class="h-full"
|
|
63
|
-
:class="{ app: appLoading }"
|
|
64
|
-
>
|
|
65
|
-
<slot />
|
|
66
|
-
<van-config-provider
|
|
67
|
-
v-if="theme"
|
|
68
|
-
:theme="theme as ConfigProviderTheme"
|
|
69
|
-
/>
|
|
70
|
-
</div>
|
|
71
|
-
</template>
|
|
72
|
-
|
|
73
|
-
<style scoped>
|
|
74
|
-
.app{height:0;width:0}.app:after{background:#5a5a5a url(/images/loading.gif) no-repeat 50%;content:"";height:100%;left:0;position:absolute;top:0;transition:.5s;width:100%;z-index:10000}
|
|
75
|
-
</style>
|