@inzombieland/nuxt-common 1.16.23 → 1.16.24

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.23",
3
+ "version": "1.16.24",
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.23";
5
+ const version = "1.16.24";
6
6
 
7
7
  const module = defineNuxtModule({
8
8
  meta: {
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { StyleProvider, Themes } from "@varlet/ui"
3
3
  import { useLocalStorage } from "@vueuse/core"
4
- import { useI18n, useLocalePath } from "#i18n"
4
+ import { useLocalePath } from "#i18n"
5
5
  import { useNuxtApp } from "#imports"
6
6
  import { onMounted, ref, watch } from "vue"
7
7
  import { useRouter } from "vue-router"
@@ -15,15 +15,12 @@ import "@vant/touch-emulator"
15
15
 
16
16
  const theme = ref("")
17
17
  const appPreferencesTheme = useLocalStorage("app-preferences-theme", JSON.stringify({ value: "" }))
18
- const locale = useLocalStorage("app-preferences-locale", JSON.stringify({ value: "en" }))
19
18
  const user = useUser()
20
19
  const activeSessions = useActiveSessions()
21
20
  const { fetchActiveSessions, logout } = useUserActions()
22
21
  const localePath = useLocalePath()
23
22
  const router = useRouter()
24
23
  const appLoading = ref(Boolean(user.value))
25
- // @ts-ignore
26
- const { setLocale } = useI18n()
27
24
  const { $mobileApp } = useNuxtApp()
28
25
 
29
26
  useSubscribe("WS.SessionsUpdated", async (session: { status?: string; visitorId?: string; sessionId?: string }) => {
@@ -82,20 +79,6 @@ onMounted(() => {
82
79
  { immediate: true }
83
80
  )
84
81
 
85
- watch(
86
- locale,
87
- locale => {
88
- try {
89
- const { value } = JSON.parse(locale)
90
- setLocale(value)
91
- } catch (error) {
92
- console.error(`Error parsing app preferences locale:`, error)
93
- setLocale("en")
94
- }
95
- },
96
- { immediate: true }
97
- )
98
-
99
82
  appLoading.value = false
100
83
  })
101
84
 
@@ -1,15 +1,11 @@
1
- import { Locale as VarletLocale } from "@varlet/ui";
2
1
  import { useLocalStorage } from "@vueuse/core";
3
- import { setNotifyDefaultOptions, Locale as VantLocale } from "vant";
4
- import enUS from "vant/es/locale/lang/en-US";
5
- import ruRU from "vant/es/locale/lang/ru-RU";
6
- import { watch } from "vue";
7
2
  import { createApiFetch } from "./api-client.mjs";
8
3
  import bus from "./bus.mjs";
9
4
  import { newCometClient } from "./comet-client.mjs";
10
5
  import { useApiActions } from "./composables/use-api-actions.mjs";
11
6
  import { createApiGetUser } from "./get-user.mjs";
12
7
  import { createApiGetVisitorIdentifier } from "./get-visitor.mjs";
8
+ import { createInitApplication } from "./init-application.mjs";
13
9
  import { createApiRefreshToken } from "./refresh-token.mjs";
14
10
  import { createApiUserActions } from "./user-actions.mjs";
15
11
  export { useUser } from "./composables/use-user.mjs";
@@ -20,8 +16,8 @@ export function initApiFetch($fetch, config) {
20
16
  const fetch = createApiFetch($fetch, config);
21
17
  const getUser = createApiGetUser(fetch, config);
22
18
  const getVisitorIdentifier = createApiGetVisitorIdentifier(config);
19
+ const initApplication = createInitApplication();
23
20
  const refreshToken = createApiRefreshToken(fetch, config);
24
- const useApiFetch = () => fetch;
25
21
  const userActions = createApiUserActions(fetch, config, getUser);
26
22
  apiActions.value = {
27
23
  initialized: true,
@@ -30,8 +26,6 @@ export function initApiFetch($fetch, config) {
30
26
  };
31
27
  if (typeof window !== "undefined") {
32
28
  const loggedIn = useLocalStorage("lin", "no");
33
- const theme = useLocalStorage("app-preferences-theme", JSON.stringify({ value: "" }));
34
- const locale = useLocalStorage("app-preferences-locale", JSON.stringify({ value: "en" }));
35
29
  const cometServerURL = config.cometServerURL;
36
30
  let cometClient;
37
31
  bus.subscribe("user:onUpdated", (user) => {
@@ -46,48 +40,12 @@ export function initApiFetch($fetch, config) {
46
40
  cometClient.isStarted = false;
47
41
  }
48
42
  loggedIn.value = user ? "yes" : "no";
49
- try {
50
- const { value } = JSON.parse(theme.value);
51
- if (user && user.theme !== value) {
52
- theme.value = JSON.stringify({ value: user.theme });
53
- }
54
- } catch (error) {
55
- console.error(`Error parsing app preferences theme:`, error);
56
- }
57
- try {
58
- const { value } = JSON.parse(locale.value);
59
- if (user && user.locale !== value) {
60
- locale.value = JSON.stringify({ value: user.locale });
61
- }
62
- } catch (error) {
63
- console.error(`Error parsing app preferences locale:`, error);
64
- }
65
43
  });
66
- watch(
67
- locale,
68
- (locale2) => {
69
- try {
70
- const { value } = JSON.parse(locale2);
71
- if (value === "en") {
72
- VantLocale.use(locale2, enUS);
73
- VarletLocale.add("en-US", VarletLocale.enUS);
74
- }
75
- if (value === "ru") {
76
- VantLocale.use(locale2, ruRU);
77
- VarletLocale.add("en-US", VarletLocale.enUS);
78
- }
79
- } catch (error) {
80
- console.error(`Error parsing app preferences locale:`, error);
81
- VantLocale.use(locale2, enUS);
82
- VarletLocale.add("en-US", VarletLocale.enUS);
83
- }
84
- },
85
- { immediate: true }
86
- );
87
- setNotifyDefaultOptions({ position: "bottom" });
88
44
  bus.subscribe("app:beforeMount", () => {
89
45
  getVisitorIdentifier();
46
+ initApplication();
90
47
  });
91
48
  }
49
+ const useApiFetch = () => fetch;
92
50
  return { fetch, getUser, useApiFetch, userActions };
93
51
  }
@@ -0,0 +1 @@
1
+ export declare const createInitApplication: () => () => void;
@@ -0,0 +1,63 @@
1
+ import { Locale as VarletLocale } from "@varlet/ui";
2
+ import { useLocalStorage } from "@vueuse/core";
3
+ import { setNotifyDefaultOptions, Locale as VantLocale } from "vant";
4
+ import enUS from "vant/es/locale/lang/en-US";
5
+ import ruRU from "vant/es/locale/lang/ru-RU";
6
+ import { watch } from "vue";
7
+ import { useI18n } from "vue-i18n";
8
+ import { useUser } from "./composables/use-user.mjs";
9
+ import { once } from "./helpers/index.mjs";
10
+ function initApplication() {
11
+ const user = useUser();
12
+ const theme = useLocalStorage("app-preferences-theme", JSON.stringify({ value: "" }));
13
+ const locale = useLocalStorage("app-preferences-locale", JSON.stringify({ value: "en" }));
14
+ const i18n = useI18n();
15
+ watch(
16
+ user,
17
+ (user2) => {
18
+ try {
19
+ const { value } = JSON.parse(theme.value);
20
+ if (user2 && user2.theme !== value) {
21
+ theme.value = JSON.stringify({ value: user2.theme });
22
+ }
23
+ } catch (error) {
24
+ console.error(`Error parsing app preferences theme:`, error);
25
+ }
26
+ try {
27
+ const { value } = JSON.parse(locale.value);
28
+ if (user2 && user2.locale !== value) {
29
+ locale.value = JSON.stringify({ value: user2.locale });
30
+ }
31
+ } catch (error) {
32
+ console.error(`Error parsing app preferences locale:`, error);
33
+ }
34
+ },
35
+ { immediate: true }
36
+ );
37
+ watch(
38
+ locale,
39
+ (locale2) => {
40
+ try {
41
+ const { value } = JSON.parse(locale2);
42
+ if ("setLocale" in i18n && typeof i18n.setLocale === "function") {
43
+ i18n.setLocale(value);
44
+ }
45
+ if (value === "en") {
46
+ VantLocale.use(locale2, enUS);
47
+ VarletLocale.add("en-US", VarletLocale.enUS);
48
+ }
49
+ if (value === "ru") {
50
+ VantLocale.use(locale2, ruRU);
51
+ VarletLocale.add("en-US", VarletLocale.enUS);
52
+ }
53
+ } catch (error) {
54
+ console.error(`Error parsing app preferences locale:`, error);
55
+ }
56
+ },
57
+ { immediate: true }
58
+ );
59
+ setNotifyDefaultOptions({ position: "bottom" });
60
+ }
61
+ export const createInitApplication = once(() => {
62
+ return () => initApplication();
63
+ });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/api",
3
- "version": "1.16.23",
3
+ "version": "1.16.24",
4
4
  "type": "module",
5
5
  "license": "ISC",
6
6
  "main": "./index.mjs",
@@ -17,7 +17,6 @@
17
17
  "ofetch": "^1.4.1",
18
18
  "rxjs": "^7.8.2",
19
19
  "vant": "^4.9.19",
20
- "vue": "^3.5.13",
21
20
  "zod": "^3.24.2"
22
21
  }
23
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/nuxt-common",
3
- "version": "1.16.23",
3
+ "version": "1.16.24",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "exports": {