@vueuse/nuxt 7.3.0 → 7.4.3

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/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { dirname, resolve } from 'path';
3
3
  import { fileURLToPath } from 'url';
4
4
  import { isPackageExists } from 'local-pkg';
5
5
 
6
- const _dirname = typeof __dirname === "undefined" ? dirname(fileURLToPath(import.meta.url)) : __dirname;
6
+ const _dirname = dirname(fileURLToPath(import.meta.url));
7
7
  const disabledFunctions = [
8
8
  "useFetch",
9
9
  "toRefs",
@@ -24,6 +24,7 @@ const packages = [
24
24
  const fullPackages = packages.map((p) => `@vueuse/${p}`);
25
25
  function VueUseModule() {
26
26
  const { nuxt } = this;
27
+ const options = nuxt.options.vueuse || {};
27
28
  nuxt.hook("vite:extend", ({ config }) => {
28
29
  config.optimizeDeps = config.optimizeDeps || {};
29
30
  config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
@@ -31,38 +32,45 @@ function VueUseModule() {
31
32
  });
32
33
  nuxt.options.build = nuxt.options.build || {};
33
34
  nuxt.options.build.transpile = nuxt.options.build.transpile || [];
34
- nuxt.options.build.transpile.push("@vueuse/nuxt");
35
+ nuxt.options.build.transpile.push("@vueuse/nuxt", "@vueuse/core", "@vueuse/shared");
35
36
  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");
37
+ if (options.ssrHandlers) {
38
+ const pluginPath = resolve(_dirname, "./ssr-plugin.mjs");
39
+ nuxt.options.plugins = nuxt.options.plugins || [];
40
+ nuxt.options.plugins.push(pluginPath);
41
+ }
42
+ if (options.autoImports !== false) {
43
+ nuxt.hook("autoImports:sources", (sources) => {
44
+ if (sources.find((i) => fullPackages.includes(i.from)))
45
+ return;
46
+ if (!indexes) {
47
+ try {
48
+ indexes = JSON.parse(fs.readFileSync(resolve(_dirname, "./indexes.json"), "utf-8"));
49
+ indexes == null ? void 0 : indexes.functions.forEach((i) => {
50
+ if (i.package === "shared")
51
+ i.package = "core";
52
+ });
53
+ } catch (e) {
54
+ throw new Error("[@vueuse/nuxt] Failed to load indexes.json");
55
+ }
48
56
  }
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
- });
57
+ if (!indexes)
58
+ return;
59
+ for (const pkg of packages) {
60
+ if (pkg === "shared")
61
+ continue;
62
+ if (!isPackageExists(`@vueuse/${pkg}`))
63
+ continue;
64
+ const functions = indexes.functions.filter((i) => (i.package === "core" || i.package === "shared") && !i.internal);
65
+ if (functions.length) {
66
+ sources.push({
67
+ from: `@vueuse/${pkg}`,
68
+ names: indexes.functions.filter((i) => i.package === pkg && !i.internal).map((i) => i.name).filter((i) => i.length >= 4 && !disabledFunctions.includes(i))
69
+ });
70
+ }
63
71
  }
64
- }
65
- });
72
+ });
73
+ }
66
74
  }
67
75
 
68
76
  export { VueUseModule as default };
package/indexes.json CHANGED
@@ -35,7 +35,10 @@
35
35
  "external": [
36
36
  "@vueuse/core",
37
37
  "@vueuse/shared",
38
- "local-pkg"
38
+ "local-pkg",
39
+ "fs",
40
+ "path",
41
+ "url"
39
42
  ],
40
43
  "dir": "packages/nuxt",
41
44
  "docs": "https://vueuse.org/nuxt/README.html"
@@ -629,6 +632,14 @@
629
632
  "category": "Browser",
630
633
  "description": "reactive [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API)"
631
634
  },
635
+ {
636
+ "name": "useColorMode",
637
+ "package": "core",
638
+ "component": true,
639
+ "docs": "https://vueuse.org/core/useColorMode/",
640
+ "category": "Browser",
641
+ "description": "reactive color mode (dark / light / customs) with auto data persistence"
642
+ },
632
643
  {
633
644
  "name": "useConfirmDialog",
634
645
  "package": "core",
@@ -643,6 +654,13 @@
643
654
  "category": "Browser",
644
655
  "description": "manipulate CSS variables"
645
656
  },
657
+ {
658
+ "name": "useCycleList",
659
+ "package": "core",
660
+ "docs": "https://vueuse.org/core/useCycleList/",
661
+ "category": "Utilities",
662
+ "description": "cycle through a list of items"
663
+ },
646
664
  {
647
665
  "name": "useDark",
648
666
  "package": "core",
@@ -933,6 +951,13 @@
933
951
  "category": "Sensors",
934
952
  "description": "watch for changes being made to the DOM tree"
935
953
  },
954
+ {
955
+ "name": "useNavigatorLanguage",
956
+ "package": "core",
957
+ "docs": "https://vueuse.org/core/useNavigatorLanguage/",
958
+ "category": "Sensors",
959
+ "description": "watch for changes being made to the navigator language preference by the user"
960
+ },
936
961
  {
937
962
  "name": "useNetwork",
938
963
  "package": "core",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vueuse/nuxt",
3
- "version": "7.3.0",
3
+ "version": "7.4.3",
4
4
  "description": "VueUse Nuxt Module",
5
5
  "keywords": [
6
6
  "vue",
@@ -9,6 +9,10 @@
9
9
  "nuxt3",
10
10
  "nuxt-module"
11
11
  ],
12
+ "homepage": "https://github.com/vueuse/vueuse/tree/main/packages/nuxt#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/vueuse/vueuse/issues"
15
+ },
12
16
  "license": "MIT",
13
17
  "repository": {
14
18
  "type": "git",
@@ -17,6 +21,7 @@
17
21
  },
18
22
  "funding": "https://github.com/sponsors/antfu",
19
23
  "author": "Anthony Fu <https://github.com/antfu>",
24
+ "sideEffects": false,
20
25
  "exports": {
21
26
  ".": {
22
27
  "import": "./index.mjs",
@@ -26,15 +31,10 @@
26
31
  "./*": "./*"
27
32
  },
28
33
  "main": "./index.cjs",
29
- "types": "./index.d.ts",
30
34
  "module": "./index.mjs",
31
- "sideEffects": false,
32
- "bugs": {
33
- "url": "https://github.com/vueuse/vueuse/issues"
34
- },
35
- "homepage": "https://github.com/vueuse/vueuse/tree/main/packages/nuxt#readme",
35
+ "types": "./index.d.ts",
36
36
  "dependencies": {
37
- "@vueuse/core": "7.3.0",
37
+ "@vueuse/core": "7.4.3",
38
38
  "local-pkg": "^0.4.0",
39
39
  "vue-demi": "*"
40
40
  }
package/ssr-plugin.mjs ADDED
@@ -0,0 +1,41 @@
1
+ import { setSSRHandler } from '@vueuse/core'
2
+ import { useMeta } from '#meta'
3
+ import { useCookie } from '#app'
4
+
5
+ setSSRHandler('getDefaultStorage', () => {
6
+ const cookieMap = new Map()
7
+ const get = (key) => {
8
+ if (!cookieMap.get(key))
9
+ cookieMap.set(key, useCookie(key, { maxAge: 2147483646 }))
10
+ return cookieMap.get(key)
11
+ }
12
+ return {
13
+ getItem: (key) => get(key).value,
14
+ setItem: (key, value) => get(key).value = value,
15
+ removeItem: (key) => get(key).value = undefined
16
+ }
17
+ })
18
+
19
+ if (process.server) {
20
+ setSSRHandler('updateHTMLAttrs', (selector, attr, value) => {
21
+ if (selector === 'html') {
22
+ useMeta({
23
+ htmlAttrs: {
24
+ [attr]: value,
25
+ },
26
+ })
27
+ }
28
+ else if (selector === 'body') {
29
+ useMeta({
30
+ bodyAttrs: {
31
+ [attr]: value,
32
+ },
33
+ })
34
+ }
35
+ else {
36
+ throw new Error(`Unsupported meta selector "${selector}" in SSR`)
37
+ }
38
+ })
39
+ }
40
+
41
+ export default () => { }