nuxt-users 1.41.0 → 1.41.1

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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { M as ModuleOptions } from './shared/nuxt-users.XW6DYM7t.mjs';
2
+ import { M as ModuleOptions } from './shared/nuxt-users.DUmdxjpk.mjs';
3
3
  export * from '../dist/runtime/server/internal/index.js';
4
4
 
5
5
  declare const defaultOptions: ModuleOptions;
package/dist/module.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { M as ModuleOptions } from './shared/nuxt-users.XW6DYM7t.js';
2
+ import { M as ModuleOptions } from './shared/nuxt-users.DUmdxjpk.js';
3
3
  export * from '../dist/runtime/server/internal/index.js';
4
4
 
5
5
  declare const defaultOptions: ModuleOptions;
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "1.41.0",
7
+ "version": "1.41.1",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -56,8 +56,11 @@ const defaultOptions = {
56
56
  fallbackLocale: "en",
57
57
  texts: {}
58
58
  },
59
- tokenCleanupSchedule: "0 2 * * *"
59
+ tokenCleanupSchedule: "0 2 * * *",
60
60
  // Daily at 2 AM
61
+ theme: {
62
+ enabled: true
63
+ }
61
64
  };
62
65
  const module$1 = defineNuxtModule({
63
66
  meta: {
@@ -122,6 +125,7 @@ const module$1 = defineNuxtModule({
122
125
  nuxt.options.runtimeConfig.public.nuxtUsers = {
123
126
  passwordValidation: runtimeConfigOptions.passwordValidation,
124
127
  locale: runtimeConfigOptions.locale,
128
+ theme: runtimeConfigOptions.theme,
125
129
  auth: {
126
130
  whitelist: (() => {
127
131
  const combinedWhitelist = [...defaultOptions.auth?.whitelist || [], ...runtimeConfigOptions.auth?.whitelist || []];
@@ -0,0 +1,40 @@
1
+ import type { Ref } from 'vue';
2
+ export type ThemeMode = 'light' | 'dark' | 'system';
3
+ export interface UseThemeReturn {
4
+ /**
5
+ * Current theme mode
6
+ */
7
+ theme: Ref<ThemeMode>;
8
+ /**
9
+ * Current resolved theme (system resolved to actual light/dark)
10
+ */
11
+ resolvedTheme: Ref<'light' | 'dark'>;
12
+ /**
13
+ * Set the theme mode
14
+ */
15
+ setTheme: (mode: ThemeMode) => void;
16
+ /**
17
+ * Toggle between light and dark themes
18
+ */
19
+ toggleTheme: () => void;
20
+ }
21
+ /**
22
+ * Composable for managing theme state in nuxt-users module
23
+ *
24
+ * This composable provides a reactive theme state that can be shared
25
+ * between the module and consumer applications.
26
+ *
27
+ * @example
28
+ * ```vue
29
+ * <script setup>
30
+ * const { theme, setTheme, toggleTheme } = useTheme()
31
+ * </script>
32
+ *
33
+ * <template>
34
+ * <button @click="toggleTheme">
35
+ * Current: {{ theme }}
36
+ * </button>
37
+ * </template>
38
+ * ```
39
+ */
40
+ export declare const useTheme: () => UseThemeReturn;
@@ -0,0 +1,47 @@
1
+ import { useState } from "#app";
2
+ export const useTheme = () => {
3
+ const theme = useState("nuxt-users-theme", () => "system");
4
+ const resolvedTheme = useState("nuxt-users-resolved-theme", () => "light");
5
+ const resolveTheme = () => {
6
+ if (theme.value === "system") {
7
+ if (typeof window === "undefined") {
8
+ return "light";
9
+ }
10
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
11
+ }
12
+ return theme.value;
13
+ };
14
+ const applyTheme = (resolved) => {
15
+ if (typeof document === "undefined") {
16
+ return;
17
+ }
18
+ if (resolved === "dark") {
19
+ document.documentElement.classList.add("dark");
20
+ }
21
+ if (resolved === "light") {
22
+ document.documentElement.classList.remove("dark");
23
+ }
24
+ resolvedTheme.value = resolved;
25
+ };
26
+ const setTheme = (mode) => {
27
+ theme.value = mode;
28
+ const resolved = resolveTheme();
29
+ applyTheme(resolved);
30
+ if (typeof window !== "undefined") {
31
+ window.dispatchEvent(new CustomEvent("nuxt-users:theme-change", {
32
+ detail: { mode, resolved }
33
+ }));
34
+ }
35
+ };
36
+ const toggleTheme = () => {
37
+ const current = resolveTheme();
38
+ const newMode = current === "dark" ? "light" : "dark";
39
+ setTheme(newMode);
40
+ };
41
+ return {
42
+ theme,
43
+ resolvedTheme,
44
+ setTheme,
45
+ toggleTheme
46
+ };
47
+ };
@@ -1,8 +1,21 @@
1
1
  /**
2
- * Theme detection plugin
2
+ * Theme detection plugin with hybrid detection support
3
3
  *
4
- * Automatically applies dark theme class based on system preferences.
5
- * Listens for changes to system theme and updates accordingly.
4
+ * This plugin provides flexible theme management that works seamlessly
5
+ * with consumer applications that have their own theme systems.
6
+ *
7
+ * Detection methods:
8
+ * 1. System preference changes (prefers-color-scheme)
9
+ * 2. DOM class changes via MutationObserver (consumer app control)
10
+ * 3. Custom events (consumer app notification)
11
+ * 4. Shared state via useTheme composable
12
+ *
13
+ * The plugin respects consumer app theme changes and won't conflict
14
+ * with external theme management systems.
6
15
  */
7
- declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
16
+ declare const _default: import("#app").Plugin<{
17
+ nuxtUsersTheme: import("./composables/useTheme.js").UseThemeReturn;
18
+ }> & import("#app").ObjectPlugin<{
19
+ nuxtUsersTheme: import("./composables/useTheme.js").UseThemeReturn;
20
+ }>;
8
21
  export default _default;
@@ -1,27 +1,92 @@
1
- import { defineNuxtPlugin } from "#app";
1
+ import { defineNuxtPlugin, useRuntimeConfig } from "#app";
2
+ import { useTheme } from "./composables/useTheme.js";
2
3
  export default defineNuxtPlugin(() => {
3
4
  if (import.meta.server) {
4
5
  return;
5
6
  }
6
- const applyTheme = () => {
7
- if (typeof window === "undefined" || typeof document === "undefined") {
7
+ const config = useRuntimeConfig();
8
+ const themeConfig = config.public?.nuxtUsers?.theme;
9
+ if (themeConfig?.enabled === false) {
10
+ return;
11
+ }
12
+ const { setTheme, theme } = useTheme();
13
+ let isInternalChange = false;
14
+ const syncThemeFromDOM = () => {
15
+ if (isInternalChange) {
16
+ return;
17
+ }
18
+ if (typeof document === "undefined") {
8
19
  return;
9
20
  }
10
- const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
11
- if (prefersDark) {
12
- document.documentElement.classList.add("dark");
21
+ const isDark = document.documentElement.classList.contains("dark");
22
+ const currentResolved = window.matchMedia("(prefers-color-scheme: dark)").matches;
23
+ if (isDark) {
24
+ theme.value = "dark";
13
25
  }
14
- if (!prefersDark) {
15
- document.documentElement.classList.remove("dark");
26
+ if (!isDark && !currentResolved) {
27
+ theme.value = "light";
28
+ }
29
+ if (!isDark && currentResolved) {
30
+ theme.value = "light";
31
+ }
32
+ };
33
+ const handleSystemThemeChange = () => {
34
+ if (theme.value === "system") {
35
+ isInternalChange = true;
36
+ setTheme("system");
37
+ isInternalChange = false;
16
38
  }
17
39
  };
18
- applyTheme();
19
40
  if (typeof window !== "undefined" && window.matchMedia) {
20
41
  const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
21
42
  if (mediaQuery.addEventListener) {
22
- mediaQuery.addEventListener("change", applyTheme);
23
- } else if (mediaQuery.addListener) {
24
- mediaQuery.addListener(applyTheme);
43
+ mediaQuery.addEventListener("change", handleSystemThemeChange);
44
+ }
45
+ if (mediaQuery.addListener) {
46
+ mediaQuery.addListener(handleSystemThemeChange);
25
47
  }
26
48
  }
49
+ if (typeof window !== "undefined" && typeof MutationObserver !== "undefined") {
50
+ const observer = new MutationObserver(() => {
51
+ syncThemeFromDOM();
52
+ });
53
+ observer.observe(document.documentElement, {
54
+ attributes: true,
55
+ attributeFilter: ["class"]
56
+ });
57
+ }
58
+ if (typeof window !== "undefined") {
59
+ window.addEventListener("theme-change", (event) => {
60
+ const customEvent = event;
61
+ const newTheme = customEvent.detail?.theme;
62
+ if (newTheme === "light" || newTheme === "dark") {
63
+ isInternalChange = true;
64
+ setTheme(newTheme);
65
+ isInternalChange = false;
66
+ }
67
+ });
68
+ window.addEventListener("color-scheme-change", (event) => {
69
+ const customEvent = event;
70
+ const newTheme = customEvent.detail?.colorScheme || customEvent.detail?.theme;
71
+ if (newTheme === "light" || newTheme === "dark") {
72
+ isInternalChange = true;
73
+ setTheme(newTheme);
74
+ isInternalChange = false;
75
+ }
76
+ });
77
+ }
78
+ if (typeof document !== "undefined") {
79
+ const hasExistingDarkClass = document.documentElement.classList.contains("dark");
80
+ if (hasExistingDarkClass) {
81
+ theme.value = "dark";
82
+ }
83
+ if (!hasExistingDarkClass) {
84
+ setTheme("system");
85
+ }
86
+ }
87
+ return {
88
+ provide: {
89
+ nuxtUsersTheme: useTheme()
90
+ }
91
+ };
27
92
  });
@@ -192,6 +192,18 @@ interface RuntimeModuleOptions {
192
192
  * Locale configuration for component labels and messages
193
193
  */
194
194
  locale?: LocaleOptions;
195
+ /**
196
+ * Theme configuration for color scheme management
197
+ */
198
+ theme?: {
199
+ /**
200
+ * Enable the automatic theme plugin
201
+ * When disabled, the module won't manage themes automatically,
202
+ * allowing consumer apps full control over theme management
203
+ * @default true
204
+ */
205
+ enabled?: boolean;
206
+ };
195
207
  }
196
208
  interface ModuleOptions {
197
209
  connector: {
@@ -235,6 +247,18 @@ interface ModuleOptions {
235
247
  * Default: '0 2 * * *' (daily at 2 AM)
236
248
  */
237
249
  tokenCleanupSchedule?: string | false | null;
250
+ /**
251
+ * Theme configuration for color scheme management
252
+ */
253
+ theme?: {
254
+ /**
255
+ * Enable the automatic theme plugin
256
+ * When disabled, the module won't manage themes automatically,
257
+ * allowing consumer apps full control over theme management
258
+ * @default true
259
+ */
260
+ enabled?: boolean;
261
+ };
238
262
  }
239
263
  interface MailerOptions {
240
264
  host: string;
@@ -192,6 +192,18 @@ interface RuntimeModuleOptions {
192
192
  * Locale configuration for component labels and messages
193
193
  */
194
194
  locale?: LocaleOptions;
195
+ /**
196
+ * Theme configuration for color scheme management
197
+ */
198
+ theme?: {
199
+ /**
200
+ * Enable the automatic theme plugin
201
+ * When disabled, the module won't manage themes automatically,
202
+ * allowing consumer apps full control over theme management
203
+ * @default true
204
+ */
205
+ enabled?: boolean;
206
+ };
195
207
  }
196
208
  interface ModuleOptions {
197
209
  connector: {
@@ -235,6 +247,18 @@ interface ModuleOptions {
235
247
  * Default: '0 2 * * *' (daily at 2 AM)
236
248
  */
237
249
  tokenCleanupSchedule?: string | false | null;
250
+ /**
251
+ * Theme configuration for color scheme management
252
+ */
253
+ theme?: {
254
+ /**
255
+ * Enable the automatic theme plugin
256
+ * When disabled, the module won't manage themes automatically,
257
+ * allowing consumer apps full control over theme management
258
+ * @default true
259
+ */
260
+ enabled?: boolean;
261
+ };
238
262
  }
239
263
  interface MailerOptions {
240
264
  host: string;
package/dist/utils.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { defaultLocaleMessages, en, hu, huFormal } from '../dist/runtime/locales/index.js';
2
2
  export { getNestedValue, getTranslation } from '../dist/runtime/utils/locale.js';
3
3
  export { deepMerge } from '../dist/runtime/utils/deep-merge.js';
4
- export { g as DatabaseConfig, f as DatabaseType, D as DisplayFieldsProps, G as GoogleOAuthOptions, i as LocaleMessages, h as LocaleOptions, L as LoginFormData, c as LoginFormProps, M as ModuleOptions, b as PasswordResetToken, e as Permission, P as PersonalAccessToken, d as ResetPasswordFormProps, R as RuntimeModuleOptions, U as User, a as UserWithoutPassword, j as defaultDisplayFields, k as defaultFieldLabels } from './shared/nuxt-users.XW6DYM7t.mjs';
4
+ export { g as DatabaseConfig, f as DatabaseType, D as DisplayFieldsProps, G as GoogleOAuthOptions, i as LocaleMessages, h as LocaleOptions, L as LoginFormData, c as LoginFormProps, M as ModuleOptions, b as PasswordResetToken, e as Permission, P as PersonalAccessToken, d as ResetPasswordFormProps, R as RuntimeModuleOptions, U as User, a as UserWithoutPassword, j as defaultDisplayFields, k as defaultFieldLabels } from './shared/nuxt-users.DUmdxjpk.mjs';
5
5
 
6
6
  interface PasswordValidationResult {
7
7
  isValid: boolean;
package/dist/utils.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { defaultLocaleMessages, en, hu, huFormal } from '../dist/runtime/locales/index.js';
2
2
  export { getNestedValue, getTranslation } from '../dist/runtime/utils/locale.js';
3
3
  export { deepMerge } from '../dist/runtime/utils/deep-merge.js';
4
- export { g as DatabaseConfig, f as DatabaseType, D as DisplayFieldsProps, G as GoogleOAuthOptions, i as LocaleMessages, h as LocaleOptions, L as LoginFormData, c as LoginFormProps, M as ModuleOptions, b as PasswordResetToken, e as Permission, P as PersonalAccessToken, d as ResetPasswordFormProps, R as RuntimeModuleOptions, U as User, a as UserWithoutPassword, j as defaultDisplayFields, k as defaultFieldLabels } from './shared/nuxt-users.XW6DYM7t.js';
4
+ export { g as DatabaseConfig, f as DatabaseType, D as DisplayFieldsProps, G as GoogleOAuthOptions, i as LocaleMessages, h as LocaleOptions, L as LoginFormData, c as LoginFormProps, M as ModuleOptions, b as PasswordResetToken, e as Permission, P as PersonalAccessToken, d as ResetPasswordFormProps, R as RuntimeModuleOptions, U as User, a as UserWithoutPassword, j as defaultDisplayFields, k as defaultFieldLabels } from './shared/nuxt-users.DUmdxjpk.js';
5
5
 
6
6
  interface PasswordValidationResult {
7
7
  isValid: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-users",
3
- "version": "1.41.0",
3
+ "version": "1.41.1",
4
4
  "description": "A comprehensive user management module for Nuxt 3 and Nuxt 4 applications with authentication, authorization, database support, and CLI tools",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -66,7 +66,7 @@
66
66
  "check:locale-consistency": "tsx scripts/check-locale-consistency.ts",
67
67
  "check:npm_token": "dotenv -- sh -c 'if [ -z \"$NPM_TOKEN\" ]; then echo \"❌ NPM_TOKEN environment variable is not set in .env file. Please set it to your npm token.\"; exit 1; fi'",
68
68
  "prerelease": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for deployment' && exit 1)",
69
- "release": "yarn check:npm_token && yarn lint && yarn check:translations && yarn check:locale-consistency && yarn test && yarn prepack && dotenv -- changelogen --release && dotenv -- npm publish --registry https://registry.npmjs.org/ && git push --follow-tags",
69
+ "release": "yarn check:npm_token && yarn lint && yarn check:translations && yarn check:locale-consistency && yarn test && yarn prepack && dotenv -- changelogen --release && dotenv -- sh -c 'npm publish --//registry.npmjs.org/:_authToken=$NPM_TOKEN --registry https://registry.npmjs.org/' && git push --follow-tags",
70
70
  "lint": "eslint .",
71
71
  "lint:fix": "eslint . --fix",
72
72
  "pretest": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for testing' && exit 1)",