vuetify-nuxt-module 0.5.0 → 0.5.2

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
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "0.5.0"
7
+ "version": "0.5.2"
8
8
  }
package/dist/module.mjs CHANGED
@@ -10,7 +10,7 @@ import { resolveVuetifyBase, normalizePath, writeStyles, cacheDir } from '@vueti
10
10
  import { isAbsolute, join, relative } from 'pathe';
11
11
  import { normalizePath as normalizePath$1 } from 'vite';
12
12
 
13
- const version = "0.5.0";
13
+ const version = "0.5.2";
14
14
 
15
15
  const VIRTUAL_VUETIFY_CONFIGURATION = "virtual:vuetify-configuration";
16
16
  const RESOLVED_VIRTUAL_VUETIFY_CONFIGURATION = `/@nuxt-vuetify-configuration/${VIRTUAL_VUETIFY_CONFIGURATION.slice("virtual:".length)}`;
@@ -79,18 +79,16 @@ async function mergeVuetifyModules(options, nuxt) {
79
79
  if (nuxt.options._layers.length > 1) {
80
80
  for (let i = 1; i < nuxt.options._layers.length; i++) {
81
81
  const layer = nuxt.options._layers[i];
82
- if (layer.config.vuetify) {
83
- const resolvedOptions2 = await loadVuetifyConfiguration(
84
- layer.config.rootDir,
85
- layer.config.vuetify.vuetifyOptions
86
- );
87
- if (resolvedOptions2.sources.length)
88
- resolvedOptions2.sources.forEach((s) => vuetifyConfigurationFilesToWatch.add(s.replace(/\\/g, "/")));
89
- moduleOptions.push({
90
- moduleOptions: layer.config.vuetify.moduleOptions,
91
- vuetifyOptions: resolvedOptions2.config
92
- });
93
- }
82
+ const resolvedOptions2 = await loadVuetifyConfiguration(
83
+ layer.config.rootDir,
84
+ layer.config.vuetify?.vuetifyOptions
85
+ );
86
+ if (resolvedOptions2.sources.length)
87
+ resolvedOptions2.sources.forEach((s) => vuetifyConfigurationFilesToWatch.add(s.replace(/\\/g, "/")));
88
+ moduleOptions.push({
89
+ moduleOptions: layer.config.vuetify?.moduleOptions,
90
+ vuetifyOptions: resolvedOptions2.config
91
+ });
94
92
  }
95
93
  }
96
94
  const resolvedOptions = await loadVuetifyConfiguration(
@@ -612,6 +610,7 @@ function vuetifyConfigurationPlugin(ctx) {
612
610
  icons: _icons,
613
611
  localeMessages: _localeMessages,
614
612
  components: _components,
613
+ labComponents: _labComponents,
615
614
  ssr,
616
615
  aliases: _aliases,
617
616
  ...newVuetifyOptions
@@ -1,12 +1,4 @@
1
- import {
2
- getCurrentInstance as _getCurrentInstance,
3
- computed,
4
- effectScope,
5
- onScopeDispose,
6
- ref,
7
- toRaw,
8
- watch
9
- } from "vue";
1
+ import { ref, watch } from "vue";
10
2
  import { useI18n } from "vue-i18n";
11
3
  import { useNuxtApp } from "#app";
12
4
  export function createAdapter(vuetifyOptions) {
@@ -16,120 +8,55 @@ export function createAdapter(vuetifyOptions) {
16
8
  const current = i18n.locale;
17
9
  const fallback = i18n.fallbackLocale;
18
10
  const messages = i18n.messages;
11
+ const currentLocale = ref(current.value);
19
12
  vuetifyOptions.locale.rtl = i18n.locales.value.reduce((acc, locale) => {
20
13
  acc[locale.code] = locale.dir === "rtl";
21
14
  return acc;
22
15
  }, {});
16
+ watch(currentLocale, (val, oldVal) => {
17
+ if (oldVal)
18
+ i18n.setLocale(val);
19
+ }, { immediate: true, flush: "post" });
20
+ if (process.client) {
21
+ nuxtApp.hook("i18n:localeSwitched", ({ newLocale }) => {
22
+ currentLocale.value = newLocale;
23
+ });
24
+ }
23
25
  vuetifyOptions.locale.adapter = {
24
26
  name: "nuxt-vue-i18n",
25
- current,
27
+ current: currentLocale,
26
28
  fallback,
27
29
  messages,
28
30
  t: (key, ...params) => i18n.t(key, params),
29
31
  n: i18n.n,
30
- provide: createProvideFunction({ current, fallback, messages })
32
+ provide: createProvideFunction({ current: currentLocale, fallback, messages })
31
33
  };
32
34
  }
33
- function getCurrentInstance(name, message) {
34
- const vm = _getCurrentInstance();
35
- if (!vm)
36
- throw new Error(`[Vuetify] ${name} ${message || "must be called from inside a setup function"}`);
37
- return vm;
38
- }
39
- function useToggleScope(source, fn) {
40
- let scope;
41
- function start() {
42
- scope = effectScope();
43
- scope.run(
44
- () => fn.length ? fn(() => {
45
- scope?.stop();
46
- start();
47
- }) : fn()
48
- );
49
- }
50
- watch(source, (active) => {
51
- if (active && !scope) {
52
- start();
53
- } else if (!active) {
54
- scope?.stop();
55
- scope = void 0;
56
- }
57
- }, { immediate: true });
58
- onScopeDispose(() => {
59
- scope?.stop();
60
- });
61
- }
62
- function toKebabCase(str = "") {
63
- return str.replace(/[^a-z]/gi, "-").replace(/\B([A-Z])/g, "-$1").toLowerCase();
64
- }
65
- function useProxiedModel(props, prop, defaultValue, transformIn = (v) => v, transformOut = (v) => v) {
66
- const vm = getCurrentInstance("useProxiedModel");
67
- const internal = ref(props[prop] !== void 0 ? props[prop] : defaultValue);
68
- const kebabProp = toKebabCase(prop);
69
- const checkKebab = kebabProp !== prop;
70
- const isControlled = checkKebab ? computed(() => {
71
- void props[prop];
72
- return !!((vm.vnode.props?.hasOwnProperty(prop) || vm.vnode.props?.hasOwnProperty(kebabProp)) && (vm.vnode.props?.hasOwnProperty(`onUpdate:${prop}`) || vm.vnode.props?.hasOwnProperty(`onUpdate:${kebabProp}`)));
73
- }) : computed(() => {
74
- void props[prop];
75
- return !!(vm.vnode.props?.hasOwnProperty(prop) && vm.vnode.props?.hasOwnProperty(`onUpdate:${prop}`));
76
- });
77
- useToggleScope(() => !isControlled.value, () => {
78
- watch(() => props[prop], (val) => {
79
- internal.value = val;
80
- });
81
- });
82
- const model = computed({
83
- get() {
84
- const externalValue = props[prop];
85
- return transformIn(isControlled.value ? externalValue : internal.value);
86
- },
87
- set(internalValue) {
88
- const newValue = transformOut(internalValue);
89
- const value = toRaw(isControlled.value ? props[prop] : internal.value);
90
- if (value === newValue || transformIn(value) === internalValue)
91
- return;
92
- internal.value = newValue;
93
- vm?.emit(`update:${prop}`, newValue);
94
- }
95
- });
96
- Object.defineProperty(model, "externalValue", {
97
- get: () => isControlled.value ? props[prop] : internal.value
98
- });
99
- return model;
100
- }
101
- function useProvided(props, prop, provided) {
102
- const internal = useProxiedModel(props, prop);
103
- internal.value = props[prop] ?? provided.value;
104
- watch(provided, (v) => {
105
- if (props[prop] == null)
106
- internal.value = v;
107
- });
108
- return internal;
109
- }
110
35
  function createProvideFunction(data) {
111
36
  return (props) => {
112
- const current = useProvided(props, "locale", data.current);
113
- const fallback = useProvided(props, "fallback", data.fallback);
114
- const messages = useProvided(props, "messages", data.messages);
37
+ const currentLocale = ref(props.locale ?? data.current.value);
115
38
  const i18n = useI18n({
116
- locale: current.value,
117
- fallbackLocale: fallback.value,
118
- messages: messages.value,
39
+ locale: currentLocale.value,
40
+ fallbackLocale: data.fallback.value,
41
+ messages: data.messages.value,
119
42
  useScope: "local",
120
43
  legacy: false,
121
44
  inheritLocale: false
122
45
  });
46
+ watch(currentLocale, (val, oldVal) => {
47
+ if (oldVal)
48
+ i18n.setLocale(val);
49
+ }, { immediate: true, flush: "post" });
123
50
  return {
124
51
  name: "nuxt-vue-i18n",
125
- current,
126
- fallback,
127
- messages,
52
+ current: currentLocale,
53
+ fallback: data.fallback,
54
+ messages: data.messages,
128
55
  // todo: fix this, we should check the options
129
56
  // @ts-expect-error Type instantiation is excessively deep and possibly infinite.ts(2589)
130
57
  t: (key, ...params) => i18n.t(key, params),
131
58
  n: i18n.n,
132
- provide: createProvideFunction({ current, fallback, messages })
59
+ provide: createProvideFunction({ current: currentLocale, fallback: data.fallback, messages: data.messages })
133
60
  };
134
61
  };
135
62
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vuetify-nuxt-module",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.5.2",
5
5
  "packageManager": "pnpm@8.6.9",
6
6
  "description": "Zero-Config Nuxt Module for Vuetify",
7
7
  "author": "userquin <userquin@gmail.com>",
@@ -138,4 +138,4 @@
138
138
  "installDependencies": false,
139
139
  "startCommand": "node .stackblitz.js && pnpm install && pnpm run dev"
140
140
  }
141
- }
141
+ }