@scalar/nuxt 0.4.34 → 0.5.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/dist/module.json +2 -2
- package/dist/module.mjs +18 -4
- package/dist/runtime/components/ScalarApiReference.vue +98 -78
- package/dist/runtime/components/ScalarApiReference.vue.d.ts +15 -0
- package/dist/runtime/pages/ScalarPage.vue +9 -19
- package/dist/runtime/pages/ScalarPage.vue.d.ts +2 -0
- package/dist/types.d.mts +1 -1
- package/package.json +19 -19
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -29
- package/dist/runtime/plugins/hydrateClient.d.ts +0 -2
- package/dist/runtime/plugins/hydrateClient.js +0 -13
- package/dist/types.d.ts +0 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addComponent, extendPages
|
|
1
|
+
import { defineNuxtModule, createResolver, addComponent, extendPages } from '@nuxt/kit';
|
|
2
2
|
|
|
3
3
|
const module = defineNuxtModule({
|
|
4
4
|
meta: {
|
|
@@ -26,6 +26,7 @@ const module = defineNuxtModule({
|
|
|
26
26
|
_nuxt.options.imports.transform ||= {};
|
|
27
27
|
_nuxt.options.imports.transform.exclude ||= [];
|
|
28
28
|
_nuxt.options.imports.transform.exclude.push(/scalar/);
|
|
29
|
+
_nuxt.options.vite ||= {};
|
|
29
30
|
_nuxt.options.vite.optimizeDeps ||= {};
|
|
30
31
|
_nuxt.options.vite.optimizeDeps.include ||= [];
|
|
31
32
|
_nuxt.options.vite.optimizeDeps.include.push(
|
|
@@ -34,9 +35,23 @@ const module = defineNuxtModule({
|
|
|
34
35
|
"@scalar/nuxt > ajv-draft-04",
|
|
35
36
|
"@scalar/nuxt > ajv-formats",
|
|
36
37
|
"@scalar/nuxt > ajv",
|
|
37
|
-
"@scalar/nuxt >
|
|
38
|
-
"@scalar/nuxt >
|
|
38
|
+
"@scalar/nuxt > ajv-draft-04 > ajv",
|
|
39
|
+
"@scalar/nuxt > ajv-formats > ajv",
|
|
40
|
+
"@scalar/nuxt > whatwg-mimetype"
|
|
39
41
|
);
|
|
42
|
+
_nuxt.options.vite.ssr ||= {};
|
|
43
|
+
if (Array.isArray(_nuxt.options.vite.ssr.noExternal)) {
|
|
44
|
+
_nuxt.options.vite.ssr.noExternal.push("ajv-draft-04", "ajv-formats", "ajv", "jsonpointer", "whatwg-mimetype");
|
|
45
|
+
} else {
|
|
46
|
+
_nuxt.options.vite.ssr.noExternal = [
|
|
47
|
+
...Array.isArray(_nuxt.options.vite.ssr.noExternal) ? _nuxt.options.vite.ssr.noExternal : [],
|
|
48
|
+
"ajv-draft-04",
|
|
49
|
+
"ajv-formats",
|
|
50
|
+
"ajv",
|
|
51
|
+
"jsonpointer",
|
|
52
|
+
"whatwg-mimetype"
|
|
53
|
+
];
|
|
54
|
+
}
|
|
40
55
|
_nuxt.hook("nitro:config", (config) => {
|
|
41
56
|
if (config.experimental?.openAPI) {
|
|
42
57
|
isOpenApiEnabled = true;
|
|
@@ -92,7 +107,6 @@ const module = defineNuxtModule({
|
|
|
92
107
|
});
|
|
93
108
|
});
|
|
94
109
|
}
|
|
95
|
-
addPlugin(resolver.resolve("./runtime/plugins/hydrateClient"));
|
|
96
110
|
}
|
|
97
111
|
});
|
|
98
112
|
|
|
@@ -1,104 +1,124 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ApiReferenceWorkspace } from "@scalar/api-reference";
|
|
3
|
+
import { useColorMode } from "@scalar/use-hooks/useColorMode";
|
|
4
|
+
import { createWorkspaceStore } from "@scalar/workspace-store/client";
|
|
5
|
+
import {
|
|
6
|
+
useAsyncData,
|
|
7
|
+
useFetch,
|
|
8
|
+
useHead,
|
|
9
|
+
useRequestURL,
|
|
10
|
+
useRoute,
|
|
11
|
+
useSeoMeta,
|
|
12
|
+
useState
|
|
13
|
+
} from "#imports";
|
|
14
|
+
import { onMounted, ref, toRaw, watch } from "vue";
|
|
15
|
+
const props = defineProps({
|
|
16
|
+
configuration: { type: Object, required: true }
|
|
17
|
+
});
|
|
18
|
+
const isDark = ref(props.configuration.darkMode);
|
|
19
|
+
const forcedMode = props.configuration.forceDarkModeState;
|
|
16
20
|
const { colorMode, toggleColorMode } = useColorMode({
|
|
17
|
-
initialColorMode: props.configuration.darkMode ?
|
|
18
|
-
overrideColorMode: props.configuration.forceDarkModeState
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
21
|
+
initialColorMode: props.configuration.darkMode ? "dark" : "light",
|
|
22
|
+
overrideColorMode: props.configuration.forceDarkModeState
|
|
23
|
+
});
|
|
24
|
+
const content = props.configuration.spec?.content ?? props.configuration.content;
|
|
25
|
+
const url = props.configuration.spec?.url ?? props.configuration.url;
|
|
26
|
+
const currentRoute = useRoute();
|
|
27
|
+
const meta = currentRoute.meta;
|
|
28
|
+
const document = useState("document", () => null);
|
|
29
|
+
if (!document.value) {
|
|
30
|
+
if (typeof content === "function") {
|
|
31
|
+
document.value = content();
|
|
32
|
+
} else if (content) {
|
|
33
|
+
document.value = content;
|
|
34
|
+
} else if (url) {
|
|
35
|
+
try {
|
|
36
|
+
const response = await useFetch(url, { responseType: "text" });
|
|
37
|
+
document.value = response.data.value || null;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error("Failed to fetch spec from URL:", error);
|
|
40
|
+
}
|
|
41
|
+
} else if (meta.isOpenApiEnabled) {
|
|
42
|
+
try {
|
|
43
|
+
const { data } = await useAsyncData("openapi-spec", async () => {
|
|
44
|
+
const response = await $fetch("/_openapi.json", {
|
|
45
|
+
responseType: "text"
|
|
46
|
+
});
|
|
47
|
+
return response;
|
|
48
|
+
});
|
|
49
|
+
document.value = data.value || null;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error("Failed to fetch OpenAPI spec from /_openapi.json:", error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
props.configuration.content = document.value;
|
|
41
56
|
if (!document) {
|
|
42
|
-
throw new Error(
|
|
57
|
+
throw new Error(
|
|
58
|
+
"You must provide a document for Scalar API References. Either provide a spec URL/content, or enable experimental openAPI in the Nitro config."
|
|
59
|
+
);
|
|
43
60
|
}
|
|
44
|
-
|
|
45
|
-
const parsedSpec = reactive(await parse(document))
|
|
46
|
-
const rawSpec = JSON.stringify(document)
|
|
47
|
-
|
|
48
|
-
// Load up the metadata
|
|
49
61
|
if (props.configuration?.metaData) {
|
|
50
|
-
useSeoMeta(props.configuration.metaData)
|
|
62
|
+
useSeoMeta(props.configuration.metaData);
|
|
51
63
|
}
|
|
52
|
-
|
|
53
64
|
useHead({
|
|
54
65
|
script: [
|
|
55
66
|
{
|
|
56
67
|
// Inject dark / light detection that runs before loading Nuxt to avoid flicker
|
|
57
68
|
// This is a bit of a hack inspired by @nuxtjs/color-mode, but it works
|
|
58
|
-
id:
|
|
59
|
-
tagPosition:
|
|
69
|
+
id: "scalar-color-mode-script",
|
|
70
|
+
tagPosition: "bodyClose",
|
|
60
71
|
innerHTML: `((isDark, forced) => {
|
|
61
72
|
try {
|
|
62
73
|
const stored = window.localStorage.getItem('colorMode');
|
|
63
74
|
const useDark = forced === 'dark' || !forced && (stored === 'dark' || !stored && isDark);
|
|
64
75
|
window.document.body.classList.add(useDark ? 'dark-mode' : 'light-mode');
|
|
65
76
|
} catch {}
|
|
66
|
-
})(${isDark.value}, ${JSON.stringify(forcedMode)})
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
],
|
|
71
|
-
})
|
|
72
|
-
|
|
77
|
+
})(${isDark.value}, ${JSON.stringify(forcedMode)});`.replace(/[\n\r]/g, "").replace(/ +/g, " ")
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
});
|
|
73
81
|
watch(colorMode, () => {
|
|
74
|
-
isDark.value = colorMode.value ===
|
|
75
|
-
})
|
|
76
|
-
|
|
82
|
+
isDark.value = colorMode.value === "dark";
|
|
83
|
+
});
|
|
77
84
|
onMounted(() => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// Add baseServerURL and _integration
|
|
85
|
-
const { origin } = useRequestURL()
|
|
86
|
-
|
|
87
|
-
const config: Partial<ApiReferenceConfiguration> = {
|
|
85
|
+
isDark.value = window.document.body.classList.contains("dark-mode");
|
|
86
|
+
window.document.getElementById("scalar-color-mode-script")?.remove();
|
|
87
|
+
});
|
|
88
|
+
const { origin } = useRequestURL();
|
|
89
|
+
const config = {
|
|
88
90
|
baseServerURL: origin,
|
|
89
|
-
_integration:
|
|
90
|
-
layout:
|
|
91
|
-
...props.configuration
|
|
91
|
+
_integration: "nuxt",
|
|
92
|
+
layout: "modern",
|
|
93
|
+
...props.configuration
|
|
94
|
+
};
|
|
95
|
+
const route = useRoute();
|
|
96
|
+
const store = createWorkspaceStore();
|
|
97
|
+
let parsedDocument;
|
|
98
|
+
if (typeof document.value === "string") {
|
|
99
|
+
try {
|
|
100
|
+
parsedDocument = JSON.parse(document.value);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error("Failed to parse OpenAPI document:", error);
|
|
103
|
+
throw new Error("Invalid OpenAPI document format");
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
if (document.value && typeof document.value === "object") {
|
|
107
|
+
parsedDocument = document.value;
|
|
108
|
+
} else {
|
|
109
|
+
throw new Error("Document must be a valid OpenAPI object");
|
|
110
|
+
}
|
|
92
111
|
}
|
|
112
|
+
store.addDocument({
|
|
113
|
+
name: route.name,
|
|
114
|
+
document: parsedDocument
|
|
115
|
+
});
|
|
93
116
|
</script>
|
|
94
117
|
|
|
95
118
|
<template>
|
|
96
|
-
<
|
|
97
|
-
:
|
|
98
|
-
:
|
|
99
|
-
:parsedSpec="parsedSpec"
|
|
100
|
-
:rawSpec="rawSpec"
|
|
101
|
-
@toggleDarkMode="() => toggleColorMode()" />
|
|
119
|
+
<ApiReferenceWorkspace
|
|
120
|
+
:store
|
|
121
|
+
:configuration="config" />
|
|
102
122
|
</template>
|
|
103
123
|
|
|
104
124
|
<style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Configuration } from '../../types.js';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
configuration: Configuration;
|
|
4
|
+
};
|
|
5
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<__VLS_Props>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<__VLS_Props>>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
6
|
+
export default _default;
|
|
7
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
8
|
+
type __VLS_TypePropsToOption<T> = {
|
|
9
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
10
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
11
|
+
} : {
|
|
12
|
+
type: import('vue').PropType<T[K]>;
|
|
13
|
+
required: true;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import { useRoute } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// Ensure we have a spec
|
|
9
|
-
if (
|
|
10
|
-
!meta.isOpenApiEnabled &&
|
|
11
|
-
!meta.configuration?.url &&
|
|
12
|
-
!meta.configuration?.content &&
|
|
13
|
-
// @ts-expect-error support the old syntax for a bit
|
|
14
|
-
!meta.configuration?.spec?.url &&
|
|
15
|
-
// @ts-expect-error support the old syntax for a bit
|
|
16
|
-
!meta.configuration?.spec?.content
|
|
17
|
-
) {
|
|
1
|
+
<script setup>
|
|
2
|
+
import { useRoute } from "#imports";
|
|
3
|
+
const route = useRoute();
|
|
4
|
+
const meta = route.meta;
|
|
5
|
+
if (!meta.isOpenApiEnabled && !meta.configuration?.url && !meta.configuration?.content && // @ts-expect-error support the old syntax for a bit
|
|
6
|
+
!meta.configuration?.spec?.url && // @ts-expect-error support the old syntax for a bit
|
|
7
|
+
!meta.configuration?.spec?.content) {
|
|
18
8
|
throw new Error(
|
|
19
|
-
|
|
20
|
-
)
|
|
9
|
+
"You must either provide a spec to scalar, or enable experimental openApi in the Nitro config."
|
|
10
|
+
);
|
|
21
11
|
}
|
|
22
12
|
</script>
|
|
23
13
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
export default _default;
|
package/dist/types.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { type ModuleOptions, default } from './module.
|
|
1
|
+
export { type ModuleOptions, default } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -20,42 +20,42 @@
|
|
|
20
20
|
"testing",
|
|
21
21
|
"vue"
|
|
22
22
|
],
|
|
23
|
-
"version": "0.
|
|
23
|
+
"version": "0.5.0",
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=20"
|
|
26
26
|
},
|
|
27
27
|
"type": "module",
|
|
28
|
-
"main": "./dist/module.
|
|
29
|
-
"types": "./dist/types.d.
|
|
28
|
+
"main": "./dist/module.mjs",
|
|
29
|
+
"types": "./dist/types.d.mts",
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
|
-
"types": "./dist/types.d.
|
|
33
|
-
"import": "./dist/module.mjs"
|
|
34
|
-
"require": "./dist/module.cjs"
|
|
32
|
+
"types": "./dist/types.d.mts",
|
|
33
|
+
"import": "./dist/module.mjs"
|
|
35
34
|
}
|
|
36
35
|
},
|
|
37
36
|
"files": [
|
|
38
37
|
"dist"
|
|
39
38
|
],
|
|
40
39
|
"dependencies": {
|
|
41
|
-
"@nuxt/kit": "^
|
|
42
|
-
"
|
|
43
|
-
"@scalar/api-
|
|
40
|
+
"@nuxt/kit": "^4.0.0",
|
|
41
|
+
"vue": "^3.5.17",
|
|
42
|
+
"@scalar/api-reference": "1.34.0",
|
|
43
|
+
"@scalar/types": "0.2.11",
|
|
44
|
+
"@scalar/api-client": "2.5.21",
|
|
44
45
|
"@scalar/use-hooks": "0.2.4",
|
|
45
|
-
"@scalar/
|
|
46
|
+
"@scalar/workspace-store": "0.12.0"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"@nuxt/devtools": "^
|
|
49
|
+
"@nuxt/devtools": "^2.6.2",
|
|
49
50
|
"@nuxt/eslint-config": "^0.7.3",
|
|
50
|
-
"@nuxt/module-builder": "^0.
|
|
51
|
-
"@nuxt/schema": "^
|
|
52
|
-
"@nuxt/test-utils": "^3.
|
|
51
|
+
"@nuxt/module-builder": "^1.0.1",
|
|
52
|
+
"@nuxt/schema": "^4.0.0",
|
|
53
|
+
"@nuxt/test-utils": "^3.19.2",
|
|
53
54
|
"@types/node": "^22.9.0",
|
|
54
|
-
"changelogen": "^0.5.5",
|
|
55
55
|
"cross-env": "^7.0.3",
|
|
56
|
-
"nuxt": "^
|
|
57
|
-
"vite": "
|
|
58
|
-
"vitest": "^
|
|
56
|
+
"nuxt": "^4.0.0",
|
|
57
|
+
"vite": "6.1.6",
|
|
58
|
+
"vitest": "^3.2.4"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "cross-env NUXT_TELEMETRY_DISABLED=false pnpm dev:prepare && nuxt-module-build build",
|
|
@@ -67,6 +67,6 @@
|
|
|
67
67
|
"lint:check": "scalar-lint-check",
|
|
68
68
|
"lint:fix": "scalar-lint-fix",
|
|
69
69
|
"test:watch": "vitest watch",
|
|
70
|
-
"types:check": "nuxi typecheck"
|
|
70
|
+
"types:check": "NUXT_TELEMETRY_DISABLED=true nuxi typecheck"
|
|
71
71
|
}
|
|
72
72
|
}
|
package/dist/module.cjs
DELETED
package/dist/module.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import { ApiReferenceConfiguration } from '@scalar/types/api-reference';
|
|
3
|
-
|
|
4
|
-
type Configuration = Omit<Partial<ApiReferenceConfiguration>, 'layout' | 'isEditable' | 'onSpecUpdate' | 'theme'> & {
|
|
5
|
-
/**
|
|
6
|
-
* Whether to show scalar in Nuxt DevTools
|
|
7
|
-
*
|
|
8
|
-
* @default true
|
|
9
|
-
*/
|
|
10
|
-
devtools: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* The theme to use for the reference
|
|
13
|
-
*
|
|
14
|
-
* @default undefined (nuxt theme)
|
|
15
|
-
*/
|
|
16
|
-
theme?: ApiReferenceConfiguration['theme'];
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
type ModuleOptions = {
|
|
20
|
-
/**
|
|
21
|
-
* For multiple references, pass an array of config objects into
|
|
22
|
-
* configurations. These configurations will extend over the base config
|
|
23
|
-
*/
|
|
24
|
-
configurations: Omit<Configuration, 'devtools'>[];
|
|
25
|
-
layout: string | false;
|
|
26
|
-
} & Configuration;
|
|
27
|
-
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
28
|
-
|
|
29
|
-
export { type ModuleOptions, _default as default };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { defineNuxtPlugin } from "#app";
|
|
2
|
-
import { useHead } from "#imports";
|
|
3
|
-
export default defineNuxtPlugin((_nuxtApp) => {
|
|
4
|
-
_nuxtApp.hook("app:rendered", ({ ssrContext }) => {
|
|
5
|
-
useHead({
|
|
6
|
-
script: [
|
|
7
|
-
{
|
|
8
|
-
children: `window.__SCALAR__ = ${JSON.stringify(ssrContext?.payload?.data ?? {})}`
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
});
|
package/dist/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { type ModuleOptions, default } from './module'
|