@vueuse/nuxt 7.0.0-alpha.0 → 7.2.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/README.md +2 -15
- package/index.cjs +4 -44
- package/index.d.ts +1 -48
- package/index.mjs +63 -32
- package/indexes.json +1385 -0
- package/package.json +4 -11
- package/module.cjs +0 -6
- package/module.d.ts +0 -1
- package/module.mjs +0 -67
package/README.md
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@vueuse/nuxt)
|
|
4
4
|
|
|
5
|
-
> This is an add-on of [VueUse](https://github.com/vueuse/vueuse), provides Nuxt
|
|
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
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 {
|
|
68
|
+
export { VueUseModule as default };
|