@inzombieland/nuxt-common 1.16.28 → 1.17.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/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/nuxt-common",
3
- "version": "1.16.28",
3
+ "version": "1.17.0",
4
4
  "configKey": "nuxt-common",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.6.0",
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.28";
5
+ const version = "1.17.0";
6
6
 
7
7
  const module = defineNuxtModule({
8
8
  meta: {
@@ -1,5 +1,5 @@
1
- import { useLocalStorage } from "@vueuse/core";
2
1
  import { useCookie, useRequestHeaders } from "#imports";
2
+ import { useAppLocale, useThemeMode } from "../packages/api/index.mjs";
3
3
  import { flush, setToken, updateUser } from "../packages/api/api-client.mjs";
4
4
  import { fetch, getUser, userActions, useUser } from "./index.mjs";
5
5
  export const signIn = userActions.signIn;
@@ -121,8 +121,8 @@ export const changeTheme = async (body) => {
121
121
  updateUser(body);
122
122
  }
123
123
  if (typeof window !== "undefined") {
124
- const theme = useLocalStorage("app-preferences-theme", "");
125
- theme.value = JSON.stringify({ value: body.theme });
124
+ const theme = useThemeMode();
125
+ theme.value = { value: body.theme };
126
126
  }
127
127
  };
128
128
  export const changeLocale = async (body) => {
@@ -134,8 +134,8 @@ export const changeLocale = async (body) => {
134
134
  if (typeof window !== "undefined") {
135
135
  const localeCookie = useCookie("locale", { maxAge: 60 * 60 * 24 * 365 });
136
136
  localeCookie.value = body.locale;
137
- const locale = useLocalStorage("app-preferences-locale", JSON.stringify({ value: "" }));
138
- locale.value = JSON.stringify({ value: body.locale });
137
+ const locale = useAppLocale();
138
+ locale.value = { value: body.locale };
139
139
  }
140
140
  };
141
141
  export const changeAvatar = async (body) => {
@@ -0,0 +1,3 @@
1
+ import { useAppLocale } from "../packages/api";
2
+ export { useAppLocale };
3
+ export default useAppLocale;
@@ -0,0 +1,3 @@
1
+ import { useAppLocale } from "../packages/api/index.mjs";
2
+ export { useAppLocale };
3
+ export default useAppLocale;
@@ -0,0 +1,3 @@
1
+ import { useThemeMode } from "../packages/api";
2
+ export { useThemeMode };
3
+ export default useThemeMode;
@@ -0,0 +1,3 @@
1
+ import { useThemeMode } from "../packages/api/index.mjs";
2
+ export { useThemeMode };
3
+ export default useThemeMode;
@@ -1,48 +1,15 @@
1
1
  <script setup lang="ts">
2
- import { StyleProvider, Themes } from "@varlet/ui"
3
- import { useLocalStorage } from "@vueuse/core"
4
- import { onMounted, ref, watch } from "vue"
2
+ import { onMounted, ref } from "vue"
5
3
  import bus from "./bus"
6
- import { useUser } from "./index"
4
+ import { useThemeMode, useUser } from "./index"
7
5
  import type { ConfigProviderTheme } from "vant"
8
6
  import "@vant/touch-emulator"
9
7
 
10
- const theme = ref("")
11
- const appPreferencesTheme = useLocalStorage("app-preferences-theme", "")
8
+ const theme = useThemeMode()
12
9
  const user = useUser()
13
10
  const appLoading = ref(Boolean(user.value))
14
11
 
15
12
  onMounted(() => {
16
- watch(
17
- appPreferencesTheme,
18
- newThemeValue => {
19
- try {
20
- if (newThemeValue) {
21
- const { value } = JSON.parse(newThemeValue)
22
- theme.value = value
23
- }
24
- } catch (error) {
25
- console.error(`Error parsing app preferences theme:`, error)
26
- }
27
-
28
- if (!theme.value) {
29
- theme.value = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
30
- appPreferencesTheme.value = JSON.stringify({ value: theme.value })
31
- }
32
-
33
- if (theme.value === "dark") {
34
- document.documentElement.classList.remove("light", "van-theme-light")
35
- document.documentElement.classList.add("dark", "van-theme-dark")
36
- StyleProvider(Themes.dark)
37
- } else {
38
- document.documentElement.classList.remove("dark", "van-theme-dark")
39
- document.documentElement.classList.add("light", "van-theme-light")
40
- StyleProvider(null)
41
- }
42
- },
43
- { immediate: true }
44
- )
45
-
46
13
  appLoading.value = false
47
14
  })
48
15
 
@@ -58,8 +25,8 @@ if (typeof window !== "undefined") {
58
25
  >
59
26
  <slot />
60
27
  <van-config-provider
61
- v-if="theme"
62
- :theme="theme as ConfigProviderTheme"
28
+ v-if="theme?.value"
29
+ :theme="theme?.value as ConfigProviderTheme"
63
30
  />
64
31
  </div>
65
32
  </template>
@@ -0,0 +1 @@
1
+ export declare const useAppLocale: () => import("@vueuse/shared").RemovableRef<any>;
@@ -0,0 +1,13 @@
1
+ import { useLocalStorage } from "@vueuse/core";
2
+ export const useAppLocale = () => {
3
+ return useLocalStorage(
4
+ "app-preferences-locale",
5
+ { value: "en" },
6
+ {
7
+ serializer: {
8
+ read: (v) => v ? JSON.parse(v) : null,
9
+ write: (v) => JSON.stringify(v)
10
+ }
11
+ }
12
+ );
13
+ };
@@ -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
+ };
@@ -5,6 +5,8 @@ export { default as AppProvider } from "./AppProvider.vue";
5
5
  export { useUser } from "./composables/use-user";
6
6
  export { useSubscribe } from "./composables/use-subscribe";
7
7
  export { useActiveSessions } from "./composables/use-active-sessions";
8
+ export { useThemeMode } from "./composables/use-theme-mode";
9
+ export { useAppLocale } from "./composables/use-app-locale";
8
10
  export { getVisitor, getVisitorId, type Visitor } from "./get-visitor";
9
11
  export declare function initApiFetch($fetch: Fetch, config: FetchConfig): {
10
12
  fetch: Fetch;
@@ -13,6 +13,8 @@ export { default as AppProvider } from "./AppProvider.vue";
13
13
  export { useUser } from "./composables/use-user.mjs";
14
14
  export { useSubscribe } from "./composables/use-subscribe.mjs";
15
15
  export { useActiveSessions } from "./composables/use-active-sessions.mjs";
16
+ export { useThemeMode } from "./composables/use-theme-mode.mjs";
17
+ export { useAppLocale } from "./composables/use-app-locale.mjs";
16
18
  export { getVisitor, getVisitorId } from "./get-visitor.mjs";
17
19
  const apiActions = useApiActions();
18
20
  let userActions;
@@ -1,5 +1,4 @@
1
- import { Locale as VarletLocale } from "@varlet/ui";
2
- import { useLocalStorage } from "@vueuse/core";
1
+ import { StyleProvider, Themes, Locale as VarletLocale } from "@varlet/ui";
3
2
  import { setNotifyDefaultOptions, Locale as VantLocale } from "vant";
4
3
  import enUS from "vant/es/locale/lang/en-US";
5
4
  import ruRU from "vant/es/locale/lang/ru-RU";
@@ -10,33 +9,32 @@ import { useActiveSessions } from "./composables/use-active-sessions.mjs";
10
9
  import { useSubscribe } from "./composables/use-subscribe.mjs";
11
10
  import { useUser } from "./composables/use-user.mjs";
12
11
  import { once } from "./helpers/index.mjs";
13
- import { getVisitorId, useUserActions } from "./index.mjs";
12
+ import { getVisitorId, useAppLocale, useThemeMode, useUserActions } from "./index.mjs";
14
13
  function initApplication() {
15
14
  const router = useRouter();
16
15
  const user = useUser();
17
- const theme = useLocalStorage("app-preferences-theme", "");
18
- const locale = useLocalStorage("app-preferences-locale", JSON.stringify({ value: "en" }));
16
+ const theme = useThemeMode();
17
+ const locale = useAppLocale();
19
18
  const i18n = useI18n();
19
+ watch(user, (user2) => {
20
+ if (user2 && user2.theme !== theme.value?.value) {
21
+ theme.value = { value: user2.theme };
22
+ }
23
+ if (user2 && user2.locale !== locale.value?.value) {
24
+ locale.value = { value: user2.locale };
25
+ }
26
+ });
20
27
  watch(
21
- user,
22
- (user2) => {
23
- try {
24
- if (theme.value) {
25
- const { value } = JSON.parse(theme.value);
26
- if (user2 && user2.theme !== value) {
27
- theme.value = JSON.stringify({ value: user2.theme });
28
- }
29
- }
30
- } catch (error) {
31
- console.error(`Error parsing app preferences theme:`, error);
32
- }
33
- try {
34
- const { value } = JSON.parse(locale.value);
35
- if (user2 && user2.locale !== value) {
36
- locale.value = JSON.stringify({ value: user2.locale });
37
- }
38
- } catch (error) {
39
- console.error(`Error parsing app preferences locale:`, error);
28
+ theme,
29
+ (theme2) => {
30
+ if (theme2?.value === "dark") {
31
+ document.documentElement.classList.remove("light", "van-theme-light");
32
+ document.documentElement.classList.add("dark", "van-theme-dark");
33
+ StyleProvider(Themes.dark);
34
+ } else {
35
+ document.documentElement.classList.remove("dark", "van-theme-dark");
36
+ document.documentElement.classList.add("light", "van-theme-light");
37
+ StyleProvider(null);
40
38
  }
41
39
  },
42
40
  { immediate: true }
@@ -44,21 +42,16 @@ function initApplication() {
44
42
  watch(
45
43
  locale,
46
44
  (locale2) => {
47
- try {
48
- const { value } = JSON.parse(locale2);
49
- if ("setLocale" in i18n && typeof i18n.setLocale === "function") {
50
- i18n.setLocale(value);
51
- }
52
- if (value === "en") {
53
- VantLocale.use(locale2, enUS);
54
- VarletLocale.add("en-US", VarletLocale.enUS);
55
- }
56
- if (value === "ru") {
57
- VantLocale.use(locale2, ruRU);
58
- VarletLocale.add("en-US", VarletLocale.enUS);
59
- }
60
- } catch (error) {
61
- console.error(`Error parsing app preferences locale:`, error);
45
+ if ("setLocale" in i18n && typeof i18n.setLocale === "function") {
46
+ i18n.setLocale(locale2?.value);
47
+ }
48
+ if (locale2?.value === "en") {
49
+ VantLocale.use(locale2, enUS);
50
+ VarletLocale.add("en-US", VarletLocale.enUS);
51
+ }
52
+ if (locale2?.value === "ru") {
53
+ VantLocale.use(locale2, ruRU);
54
+ VarletLocale.add("en-US", VarletLocale.enUS);
62
55
  }
63
56
  },
64
57
  { immediate: true }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/api",
3
- "version": "1.16.28",
3
+ "version": "1.17.0",
4
4
  "type": "module",
5
5
  "license": "ISC",
6
6
  "main": "./index.mjs",
@@ -1,9 +1,9 @@
1
- import { useLocalStorage } from "@vueuse/core";
2
1
  import { addRouteMiddleware, defineNuxtPlugin } from "#app";
3
2
  import { useNuxtApp, useRequestHeaders, useRuntimeConfig, useState } from "#imports";
4
3
  import { watch } from "vue";
5
4
  import { fetch, getUser } from "./api/index.mjs";
6
5
  import { authMiddleware, guestMiddleware, localeMiddleware } from "./middleware/index.mjs";
6
+ import { useThemeMode } from "./packages/api/index.mjs";
7
7
  import { flush, setToken, setUser } from "./packages/api/api-client.mjs";
8
8
  const useAuth = () => {
9
9
  return useState("auth", () => null);
@@ -12,7 +12,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
12
12
  const auth = useAuth();
13
13
  const runtimeConfig = useRuntimeConfig();
14
14
  const { $mobileApp } = useNuxtApp();
15
- const theme = useLocalStorage("app-preferences-theme", "");
15
+ const theme = useThemeMode();
16
16
  if (runtimeConfig.public.ssr && import.meta.server || !runtimeConfig.public.ssr) {
17
17
  flush();
18
18
  if (import.meta.server) {
@@ -33,15 +33,8 @@ export default defineNuxtPlugin(async (nuxtApp) => {
33
33
  watch(
34
34
  theme,
35
35
  (theme2) => {
36
- try {
37
- if (theme2) {
38
- const { value } = JSON.parse(theme2);
39
- if ($mobileApp && "changeTheme" in $mobileApp && typeof $mobileApp.changeTheme === "function") {
40
- $mobileApp.changeTheme({ theme: value });
41
- }
42
- }
43
- } catch (error) {
44
- console.error(`Error parsing app preferences theme:`, error);
36
+ if ($mobileApp && "changeTheme" in $mobileApp && typeof $mobileApp.changeTheme === "function") {
37
+ $mobileApp.changeTheme({ theme: theme2?.value });
45
38
  }
46
39
  },
47
40
  { immediate: true }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/nuxt-common",
3
- "version": "1.16.28",
3
+ "version": "1.17.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "exports": {