@vueuse/nuxt 7.0.0-alpha.3 → 7.2.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/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/@vueuse/nuxt?color=a1b858)](https://www.npmjs.com/package/@vueuse/nuxt)
4
4
 
5
- > This is an add-on of [VueUse](https://github.com/vueuse/vueuse), provides Nuxt specific composables and auto-import capabilities.
6
-
7
- > Experimental. **Will NOT follow semvar**.
5
+ > This is an add-on of [VueUse](https://github.com/vueuse/vueuse), which provides better Nuxt integration auto-import capabilities.
8
6
 
9
7
  ## Install
10
8
 
@@ -17,22 +15,11 @@ npm i <b>@vueuse/nuxt</b>
17
15
 
18
16
  export function defineNuxtConfig({
19
17
  buildModules: [
20
- '@vueuse/nuxt/module'
18
+ '@vueuse/nuxt'
21
19
  ]
22
20
  })
23
21
  ```
24
22
 
25
- ## Functions
26
-
27
- `@vueuse/nuxt` provides the following functions
28
-
29
- <!--GENERATED LIST, DO NOT MODIFY MANUALLY-->
30
- <!--FUNCTIONS_LIST_STARTS-->
31
- - [`useNuxtDark`](https://vueuse.org/nuxt/useNuxtDark/) — reactive dark mode with auto data persistence for Nuxt
32
-
33
-
34
- <!--FUNCTIONS_LIST_ENDS-->
35
-
36
23
  ## License
37
24
 
38
25
  [MIT License](https://github.com/vueuse/vueuse/blob/master/LICENSE) © 2021-PRESENT [Anthony Fu](https://github.com/antfu)
package/index.cjs CHANGED
@@ -1,46 +1,6 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var core = require('@vueuse/core');
6
- var vueDemi = require('vue-demi');
7
- var _app = require('#app');
8
-
9
- function useNuxtDark(options = {}) {
10
- const {
11
- attribute = "class",
12
- valueDark = "dark",
13
- valueLight = "light",
14
- window = core.defaultWindow,
15
- cookieKey = "vueuse-color-schema"
16
- } = options;
17
- const preferredDark = core.usePreferredDark({ window });
18
- const store = _app.useCookie(cookieKey);
19
- if (store.value == null)
20
- store.value = "auto";
21
- const isDark = vueDemi.computed({
22
- get() {
23
- return store.value === "auto" ? preferredDark.value : store.value === "dark";
24
- },
25
- set(v) {
26
- if (v === preferredDark.value)
27
- store.value = "auto";
28
- else
29
- store.value = v ? "dark" : "light";
30
- }
31
- });
32
- _app.useMeta(vueDemi.computed(() => ({
33
- htmlAttrs: {
34
- [attribute]: isDark.value ? valueDark : valueLight
35
- }
36
- })));
37
- return isDark;
1
+ // CommonJS proxy to bypass jiti transforms from nuxt 2 and using native ESM
2
+ module.exports = function(...args) {
3
+ return import('./index.ts').then(m => m.default.call(this, ...args))
38
4
  }
39
5
 
40
- exports.useNuxtDark = useNuxtDark;
41
- Object.keys(core).forEach(function (k) {
42
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
43
- enumerable: true,
44
- get: function () { return core[k]; }
45
- });
46
- });
6
+ module.exports.meta = require('./package.json')
package/index.d.ts CHANGED
@@ -1,48 +1 @@
1
- import * as vue_demi from 'vue-demi';
2
- import { ConfigurableWindow } from '@vueuse/core';
3
- export * from '@vueuse/core';
4
-
5
- interface UseNuxtDarkOptions extends ConfigurableWindow {
6
- /**
7
- * HTML attribute applying the target element
8
- *
9
- * @default 'class'
10
- */
11
- attribute?: string;
12
- /**
13
- * Value applying to the target element when isDark=true
14
- *
15
- * @default 'dark'
16
- */
17
- valueDark?: string;
18
- /**
19
- * Value applying to the target element when isDark=false
20
- *
21
- * @default 'light'
22
- */
23
- valueLight?: string;
24
- /**
25
- * A custom handler for handle the updates.
26
- * When specified, the default behavior will be overridded.
27
- *
28
- * @default undefined
29
- */
30
- onChanged?: (isDark: boolean) => void;
31
- /**
32
- * Key to persist the data into Nuxt's useCookie.
33
- *
34
- * Pass `null` to disable persistence
35
- *
36
- * @default 'vueuse-color-schema'
37
- */
38
- cookieKey?: string;
39
- }
40
- /**
41
- * Reactive dark mode with auto data persistence for Nuxt.
42
- *
43
- * @see https://vueuse.org/useNuxtDark
44
- * @param options
45
- */
46
- declare function useNuxtDark(options?: UseNuxtDarkOptions): vue_demi.WritableComputedRef<boolean>;
47
-
48
- export { UseNuxtDarkOptions, useNuxtDark };
1
+ export default function(): void
package/index.mjs CHANGED
@@ -1,37 +1,68 @@
1
- import { usePreferredDark, defaultWindow } from '@vueuse/core';
2
- export * from '@vueuse/core';
3
- import { computed } from 'vue-demi';
4
- import { useCookie, useMeta } from '#app';
1
+ import fs from 'fs';
2
+ import { dirname, resolve } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { isPackageExists } from 'local-pkg';
5
5
 
6
- function useNuxtDark(options = {}) {
7
- const {
8
- attribute = "class",
9
- valueDark = "dark",
10
- valueLight = "light",
11
- window = defaultWindow,
12
- cookieKey = "vueuse-color-schema"
13
- } = options;
14
- const preferredDark = usePreferredDark({ window });
15
- const store = useCookie(cookieKey);
16
- if (store.value == null)
17
- store.value = "auto";
18
- const isDark = computed({
19
- get() {
20
- return store.value === "auto" ? preferredDark.value : store.value === "dark";
21
- },
22
- set(v) {
23
- if (v === preferredDark.value)
24
- store.value = "auto";
25
- else
26
- store.value = v ? "dark" : "light";
27
- }
6
+ const _dirname = typeof __dirname === "undefined" ? dirname(fileURLToPath(import.meta.url)) : __dirname;
7
+ const disabledFunctions = [
8
+ "useFetch",
9
+ "toRefs",
10
+ "useCookie"
11
+ ];
12
+ const packages = [
13
+ "core",
14
+ "shared",
15
+ "nuxt",
16
+ "integrations",
17
+ "components",
18
+ "motion",
19
+ "firebase",
20
+ "rxjs",
21
+ "sound",
22
+ "head"
23
+ ];
24
+ const fullPackages = packages.map((p) => `@vueuse/${p}`);
25
+ function VueUseModule() {
26
+ const { nuxt } = this;
27
+ nuxt.hook("vite:extend", ({ config }) => {
28
+ config.optimizeDeps = config.optimizeDeps || {};
29
+ config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
30
+ config.optimizeDeps.exclude.push(...fullPackages);
28
31
  });
29
- useMeta(computed(() => ({
30
- htmlAttrs: {
31
- [attribute]: isDark.value ? valueDark : valueLight
32
+ nuxt.options.build = nuxt.options.build || {};
33
+ nuxt.options.build.transpile = nuxt.options.build.transpile || [];
34
+ nuxt.options.build.transpile.push("@vueuse/nuxt");
35
+ let indexes;
36
+ nuxt.hook("autoImports:sources", (sources) => {
37
+ if (sources.find((i) => fullPackages.includes(i.from)))
38
+ return;
39
+ if (!indexes) {
40
+ try {
41
+ indexes = JSON.parse(fs.readFileSync(resolve(_dirname, "./indexes.json"), "utf-8"));
42
+ indexes == null ? void 0 : indexes.functions.forEach((i) => {
43
+ if (i.package === "shared")
44
+ i.package = "core";
45
+ });
46
+ } catch (e) {
47
+ throw new Error("[@vueuse/nuxt] Failed to load indexes.json");
48
+ }
49
+ }
50
+ if (!indexes)
51
+ return;
52
+ for (const pkg of packages) {
53
+ if (pkg === "core")
54
+ continue;
55
+ if (!isPackageExists(`@vueuse/${pkg}`))
56
+ continue;
57
+ const functions = indexes.functions.filter((i) => (i.package === "core" || i.package === "shared") && !i.internal);
58
+ if (functions.length) {
59
+ sources.push({
60
+ from: `@vueuse/${pkg}`,
61
+ names: indexes.functions.filter((i) => i.package === pkg && !i.internal).map((i) => i.name).filter((i) => i.length >= 4 && !disabledFunctions.includes(i))
62
+ });
63
+ }
32
64
  }
33
- })));
34
- return isDark;
65
+ });
35
66
  }
36
67
 
37
- export { useNuxtDark };
68
+ export { VueUseModule as default };
package/indexes.json CHANGED
@@ -26,13 +26,16 @@
26
26
  "name": "nuxt",
27
27
  "display": "Nuxt",
28
28
  "description": "VueUse Nuxt Module",
29
+ "manualImport": true,
29
30
  "addon": true,
30
31
  "iife": false,
32
+ "cjs": false,
33
+ "dts": false,
34
+ "target": "node14",
31
35
  "external": [
32
36
  "@vueuse/core",
33
37
  "@vueuse/shared",
34
- "nuxt3",
35
- "#app"
38
+ "local-pkg"
36
39
  ],
37
40
  "dir": "packages/nuxt",
38
41
  "docs": "https://vueuse.org/nuxt/README.html"
@@ -134,7 +137,6 @@
134
137
  "@Electron",
135
138
  "@Firebase",
136
139
  "@Integrations",
137
- "@Nuxt",
138
140
  "@Router",
139
141
  "@RxJS",
140
142
  "Animation",
@@ -792,6 +794,13 @@
792
794
  "category": "Sensors",
793
795
  "description": "reactive utility to track or set the focus state of a DOM element"
794
796
  },
797
+ {
798
+ "name": "useFocusWithin",
799
+ "package": "core",
800
+ "docs": "https://vueuse.org/core/useFocusWithin/",
801
+ "category": "Sensors",
802
+ "description": "reactive utility to track if an element or one of its decendants has focus"
803
+ },
795
804
  {
796
805
  "name": "useFps",
797
806
  "package": "core",
@@ -1217,13 +1226,6 @@
1217
1226
  "category": "Sensors",
1218
1227
  "description": "reactive window size"
1219
1228
  },
1220
- {
1221
- "name": "useNuxtDark",
1222
- "package": "nuxt",
1223
- "docs": "https://vueuse.org/nuxt/useNuxtDark/",
1224
- "category": "@Nuxt",
1225
- "description": "reactive dark mode with auto data persistence for Nuxt"
1226
- },
1227
1229
  {
1228
1230
  "name": "useRouteHash",
1229
1231
  "package": "router",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vueuse/nuxt",
3
- "version": "7.0.0-alpha.3",
3
+ "version": "7.2.1",
4
4
  "description": "VueUse Nuxt Module",
5
5
  "keywords": [
6
6
  "vue",
@@ -23,12 +23,7 @@
23
23
  "require": "./index.cjs",
24
24
  "types": "./index.d.ts"
25
25
  },
26
- "./*": "./*",
27
- "./module": {
28
- "import": "./module.mjs",
29
- "require": "./module.cjs",
30
- "types": "./module.d.ts"
31
- }
26
+ "./*": "./*"
32
27
  },
33
28
  "main": "./index.cjs",
34
29
  "types": "./index.d.ts",
@@ -39,10 +34,8 @@
39
34
  },
40
35
  "homepage": "https://github.com/vueuse/vueuse/tree/main/packages/nuxt#readme",
41
36
  "dependencies": {
42
- "@vueuse/core": "7.1.1",
37
+ "@vueuse/core": "7.2.1",
38
+ "local-pkg": "^0.4.0",
43
39
  "vue-demi": "*"
44
- },
45
- "devDependencies": {
46
- "nuxt3": "latest"
47
40
  }
48
41
  }
package/module.cjs DELETED
@@ -1,6 +0,0 @@
1
- // CommonJS proxy to bypass jiti transforms from nuxt 2 and using native ESM
2
- module.exports = function(...args) {
3
- return import('./module.mjs').then(m => m.default.call(this, ...args))
4
- }
5
-
6
- module.exports.meta = require('./package.json')
package/module.d.ts DELETED
@@ -1 +0,0 @@
1
- export default function(): void
package/module.mjs DELETED
@@ -1,73 +0,0 @@
1
- import fs from 'fs'
2
- import { dirname, resolve } from 'path'
3
- import { fileURLToPath } from 'url'
4
-
5
- const __dirname = dirname(fileURLToPath(import.meta.url))
6
-
7
- const disabled = [
8
- 'useFetch',
9
- 'toRefs',
10
- 'useCookie',
11
- ]
12
-
13
- /**
14
- * Auto import for VueUse in Nuxt
15
- * Usage:
16
- *
17
- * ```ts
18
- * // nuxt.config.js
19
- * export deafult {
20
- * buildModules: [
21
- * '@vueuse/nuxt'
22
- * ]
23
- * }
24
- * ```
25
- */
26
- export default function() {
27
- const { nuxt } = this
28
-
29
- // opt-out Vite deps optimization for VueUse
30
- nuxt.hook('vite:extend', ({ config }) => {
31
- config.optimizeDeps = config.optimizeDeps || {}
32
- config.optimizeDeps.exclude = config.optimizeDeps.exclude || []
33
- config.optimizeDeps.exclude.push(
34
- '@vueuse/core',
35
- '@vueuse/shared',
36
- '@vueuse/nuxt',
37
- '@vueuse/integrations',
38
- '@vueuse/components',
39
- '@vueuse/motion',
40
- '@vueuse/firebase',
41
- '@vueuse/rxjs',
42
- '@vueuse/sound',
43
- '@vueuse/head',
44
- )
45
- })
46
-
47
- // add @vueuse/nuxt to transpile target for alias resolution
48
- nuxt.options.build = nuxt.options.build || {}
49
- nuxt.options.build.transpile = nuxt.options.build.transpile || []
50
- nuxt.options.build.transpile.push('@vueuse/nuxt')
51
-
52
- // auto Import
53
- nuxt.hook('autoImports:sources', (sources) => {
54
- if (sources.find(i => i.from === '@vueuse/core' || i.from === '@vueuse/nuxt'))
55
- return
56
- const indexes = JSON.parse(fs.readFileSync(resolve(__dirname, './indexes.json'), 'utf-8'))
57
- sources.push({
58
- from: '@vueuse/core',
59
- names: indexes
60
- .functions
61
- .filter(i => (i.package === 'core' || i.package === 'shared') && !i.internal)
62
- .map(i => i.name)
63
- .filter(i => i.length >= 4 && !disabled.includes(i)),
64
- })
65
- sources.push({
66
- from: '@vueuse/nuxt',
67
- names: indexes
68
- .functions
69
- .filter(i => i.package === 'nuxt' && !i.internal)
70
- .map(i => i.name),
71
- })
72
- })
73
- }