@vueuse/nuxt 7.0.0-alpha.1 → 7.3.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/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
- > Expiremental. **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.mjs').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 === "shared")
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",
@@ -719,6 +721,13 @@
719
721
  "category": "Sensors",
720
722
  "description": "reactive [bounding box](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect) of an HTML element"
721
723
  },
724
+ {
725
+ "name": "useElementByPoint",
726
+ "package": "core",
727
+ "docs": "https://vueuse.org/core/useElementByPoint/",
728
+ "category": "Sensors",
729
+ "description": "reactive element by point"
730
+ },
722
731
  {
723
732
  "name": "useElementHover",
724
733
  "package": "core",
@@ -792,6 +801,13 @@
792
801
  "category": "Sensors",
793
802
  "description": "reactive utility to track or set the focus state of a DOM element"
794
803
  },
804
+ {
805
+ "name": "useFocusWithin",
806
+ "package": "core",
807
+ "docs": "https://vueuse.org/core/useFocusWithin/",
808
+ "category": "Sensors",
809
+ "description": "reactive utility to track if an element or one of its decendants has focus"
810
+ },
795
811
  {
796
812
  "name": "useFps",
797
813
  "package": "core",
@@ -1023,6 +1039,14 @@
1023
1039
  "category": "Sensors",
1024
1040
  "description": "reports changes to the dimensions of an Element's content or the border-box"
1025
1041
  },
1042
+ {
1043
+ "name": "useScreenSafeArea",
1044
+ "package": "core",
1045
+ "component": true,
1046
+ "docs": "https://vueuse.org/core/useScreenSafeArea/",
1047
+ "category": "Browser",
1048
+ "description": "reactive `env(safe-area-inset-*)`"
1049
+ },
1026
1050
  {
1027
1051
  "name": "useScriptTag",
1028
1052
  "package": "core",
@@ -1079,6 +1103,13 @@
1079
1103
  "category": "State",
1080
1104
  "description": "reactive [LocalStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)/[SessionStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage)"
1081
1105
  },
1106
+ {
1107
+ "name": "useStorageAsync",
1108
+ "package": "core",
1109
+ "docs": "https://vueuse.org/core/useStorageAsync/",
1110
+ "category": "State",
1111
+ "description": "reactive Storage in with async support"
1112
+ },
1082
1113
  {
1083
1114
  "name": "useSwipe",
1084
1115
  "package": "core",
@@ -1093,6 +1124,13 @@
1093
1124
  "category": "Component",
1094
1125
  "description": "shorthand for binding refs to template elements and components inside `v-for`"
1095
1126
  },
1127
+ {
1128
+ "name": "useTextSelection",
1129
+ "package": "core",
1130
+ "docs": "https://vueuse.org/core/useTextSelection/",
1131
+ "category": "Sensors",
1132
+ "description": "reactively track user text selection based on [`Window.getSelection`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection)"
1133
+ },
1096
1134
  {
1097
1135
  "name": "useThrottledRefHistory",
1098
1136
  "package": "core",
@@ -1217,13 +1255,6 @@
1217
1255
  "category": "Sensors",
1218
1256
  "description": "reactive window size"
1219
1257
  },
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
1258
  {
1228
1259
  "name": "useRouteHash",
1229
1260
  "package": "router",
@@ -1316,6 +1347,13 @@
1316
1347
  "category": "@RxJS",
1317
1348
  "description": "use an Observable"
1318
1349
  },
1350
+ {
1351
+ "name": "useSubject",
1352
+ "package": "rxjs",
1353
+ "docs": "https://vueuse.org/rxjs/useSubject/",
1354
+ "category": "@RxJS",
1355
+ "description": "bind Subject to ref and propagate value changes both ways"
1356
+ },
1319
1357
  {
1320
1358
  "name": "useSubscription",
1321
1359
  "package": "rxjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vueuse/nuxt",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.3.0",
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.0",
37
+ "@vueuse/core": "7.3.0",
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,67 +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/core/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
- nuxt.hook('autoImports:sources', (sources) => {
48
- if (sources.find(i => i.from === '@vueuse/core' || i.from === '@vueuse/nuxt'))
49
- return
50
- const indexes = JSON.parse(fs.readFileSync(resolve(__dirname, './indexes.json'), 'utf-8'))
51
- sources.push({
52
- from: '@vueuse/core',
53
- names: indexes
54
- .functions
55
- .filter(i => (i.package === 'core' || i.package === 'shared') && !i.internal)
56
- .map(i => i.name)
57
- .filter(i => i.length >= 4 && !disabled.includes(i)),
58
- })
59
- sources.push({
60
- from: '@vueuse/nuxt',
61
- names: indexes
62
- .functions
63
- .filter(i => i.package === 'nuxt' && !i.internal)
64
- .map(i => i.name),
65
- })
66
- })
67
- }