@scalar/nuxt 0.2.39 → 0.2.40
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.d.mts +22 -0
- package/dist/module.d.ts +22 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +79 -9
- package/dist/runtime/components/ScalarApiReference.vue +53 -0
- package/dist/runtime/components/nuxt-theme.css +1 -0
- package/dist/runtime/pages/ScalarPage.vue +21 -0
- package/dist/runtime/plugins/hydrateClient.d.mts +2 -0
- package/dist/runtime/plugins/hydrateClient.d.ts +2 -0
- package/dist/runtime/plugins/hydrateClient.js +13 -0
- package/dist/types.d.mts +1 -19
- package/dist/types.d.ts +1 -19
- package/package.json +6 -6
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { ReferenceConfiguration } from '@scalar/api-reference';
|
|
3
|
+
|
|
4
|
+
type Configuration = Omit<ReferenceConfiguration, 'layout' | 'isEditable' | 'onSpecUpdate'> & {
|
|
5
|
+
/**
|
|
6
|
+
* Whether to show scalar in Nuxt DevTools
|
|
7
|
+
*
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
devtools: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type ModuleOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* For multiple references, pass an array of config objects into
|
|
16
|
+
* configurations. These configurations will extend over the base config
|
|
17
|
+
*/
|
|
18
|
+
configurations: Omit<Configuration, 'devtools'>[];
|
|
19
|
+
} & Configuration;
|
|
20
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
21
|
+
|
|
22
|
+
export { type ModuleOptions, _default as default };
|
package/dist/module.d.ts
CHANGED
|
@@ -1,2 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { ReferenceConfiguration } from '@scalar/api-reference';
|
|
3
|
+
|
|
4
|
+
type Configuration = Omit<ReferenceConfiguration, 'layout' | 'isEditable' | 'onSpecUpdate'> & {
|
|
5
|
+
/**
|
|
6
|
+
* Whether to show scalar in Nuxt DevTools
|
|
7
|
+
*
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
devtools: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type ModuleOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* For multiple references, pass an array of config objects into
|
|
16
|
+
* configurations. These configurations will extend over the base config
|
|
17
|
+
*/
|
|
18
|
+
configurations: Omit<Configuration, 'devtools'>[];
|
|
19
|
+
} & Configuration;
|
|
20
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
21
|
+
|
|
22
|
+
export { type ModuleOptions, _default as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,12 +1,82 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { defineNuxtModule, createResolver, addComponent, extendPages, addPlugin } from '@nuxt/kit';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
const module = defineNuxtModule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "@scalar/nuxt",
|
|
6
|
+
configKey: "scalar"
|
|
7
|
+
},
|
|
8
|
+
// Default configuration options of the Nuxt module
|
|
9
|
+
defaults: {
|
|
10
|
+
darkMode: true,
|
|
11
|
+
metaData: {
|
|
12
|
+
title: "API Documentation by Scalar"
|
|
13
|
+
},
|
|
14
|
+
pathRouting: {
|
|
15
|
+
basePath: "/docs"
|
|
16
|
+
},
|
|
17
|
+
showSidebar: true,
|
|
18
|
+
devtools: true,
|
|
19
|
+
configurations: []
|
|
20
|
+
},
|
|
21
|
+
setup(_options, _nuxt) {
|
|
22
|
+
const resolver = createResolver(import.meta.url);
|
|
23
|
+
let isOpenApiEnabled = false;
|
|
24
|
+
_nuxt.options.build.transpile.push("yaml");
|
|
25
|
+
_nuxt.options.imports.transform ||= {};
|
|
26
|
+
_nuxt.options.imports.transform.exclude ||= [];
|
|
27
|
+
_nuxt.options.imports.transform.exclude.push(/scalar/);
|
|
28
|
+
_nuxt.hook("nitro:config", (config) => {
|
|
29
|
+
if (config.experimental?.openAPI)
|
|
30
|
+
isOpenApiEnabled = true;
|
|
31
|
+
});
|
|
32
|
+
addComponent({
|
|
33
|
+
name: "ScalarApiReference",
|
|
34
|
+
export: "default",
|
|
35
|
+
filePath: resolver.resolve("./runtime/components/ScalarApiReference.vue")
|
|
36
|
+
});
|
|
37
|
+
extendPages((pages) => {
|
|
38
|
+
if (_options.configurations.length) {
|
|
39
|
+
const { configurations, ...baseConfig } = _options;
|
|
40
|
+
configurations.forEach((_config, index) => {
|
|
41
|
+
const configuration = { ...baseConfig, ..._config };
|
|
42
|
+
pages.push({
|
|
43
|
+
name: "scalar-" + index,
|
|
44
|
+
path: configuration.pathRouting?.basePath + ":pathMatch(.*)*",
|
|
45
|
+
meta: {
|
|
46
|
+
configuration,
|
|
47
|
+
isOpenApiEnabled
|
|
48
|
+
},
|
|
49
|
+
file: resolver.resolve("./runtime/pages/ScalarPage.vue")
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
pages.push({
|
|
54
|
+
name: "scalar",
|
|
55
|
+
path: _options.pathRouting?.basePath + ":pathMatch(.*)*",
|
|
56
|
+
meta: {
|
|
57
|
+
configuration: _options,
|
|
58
|
+
isOpenApiEnabled
|
|
59
|
+
},
|
|
60
|
+
file: resolver.resolve("./runtime/pages/ScalarPage.vue")
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (_nuxt.options.dev && _options.devtools) {
|
|
65
|
+
_nuxt.hook("devtools:customTabs", (tabs) => {
|
|
66
|
+
tabs.push({
|
|
67
|
+
name: "scalar",
|
|
68
|
+
title: "Scalar",
|
|
69
|
+
icon: "https://gist.githubusercontent.com/cameronrohani/0fa020f6dcf957266bff49e7b6b7c05e/raw/17fce1ef37bbb036dca36b778c8b422056ad6fdf/scalar-logo-nuxt-color.svg",
|
|
70
|
+
category: "server",
|
|
71
|
+
view: {
|
|
72
|
+
type: "iframe",
|
|
73
|
+
src: _options.pathRouting?.basePath ?? "/docs"
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
addPlugin(resolver.resolve("./runtime/plugins/hydrateClient"));
|
|
9
79
|
}
|
|
10
|
-
})
|
|
80
|
+
});
|
|
11
81
|
|
|
12
|
-
export default
|
|
82
|
+
export { module as default };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { useHead, useRequestURL, useSeoMeta } from '#imports'
|
|
3
|
+
import { ModernLayout, parse } from '@scalar/api-reference'
|
|
4
|
+
import { reactive, ref, toRaw } from 'vue'
|
|
5
|
+
import type { Configuration } from '~/src/types'
|
|
6
|
+
|
|
7
|
+
import './nuxt-theme.css'
|
|
8
|
+
|
|
9
|
+
const props = defineProps<{
|
|
10
|
+
configuration: Configuration
|
|
11
|
+
}>()
|
|
12
|
+
|
|
13
|
+
const isDark = ref(props.configuration.darkMode)
|
|
14
|
+
|
|
15
|
+
// Grab spec if we can
|
|
16
|
+
const content: unknown = props.configuration.spec?.content
|
|
17
|
+
? toRaw(props.configuration.spec.content)
|
|
18
|
+
: props.configuration.spec?.url
|
|
19
|
+
? await $fetch(props.configuration.spec?.url)
|
|
20
|
+
: await $fetch('/_nitro/openapi.json')
|
|
21
|
+
|
|
22
|
+
// Check for empty spec
|
|
23
|
+
if (!content)
|
|
24
|
+
throw new Error('You must provide a spec for Scalar API References')
|
|
25
|
+
|
|
26
|
+
const parsedSpec = reactive(await parse(content))
|
|
27
|
+
const rawSpec = JSON.stringify(content)
|
|
28
|
+
|
|
29
|
+
// Load up the metadata
|
|
30
|
+
if (props.configuration?.metaData) useSeoMeta(props.configuration.metaData)
|
|
31
|
+
|
|
32
|
+
useHead({
|
|
33
|
+
bodyAttrs: {
|
|
34
|
+
class: () => (isDark.value ? 'dark-mode' : 'light-mode'),
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// Add baseServerURL
|
|
39
|
+
const { origin } = useRequestURL()
|
|
40
|
+
const config = {
|
|
41
|
+
baseServerURL: origin,
|
|
42
|
+
...props.configuration,
|
|
43
|
+
}
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<template>
|
|
47
|
+
<ModernLayout
|
|
48
|
+
:configuration="config"
|
|
49
|
+
:isDark="isDark"
|
|
50
|
+
:parsedSpec="parsedSpec"
|
|
51
|
+
:rawSpec="rawSpec"
|
|
52
|
+
@toggleDarkMode="isDark = !isDark" />
|
|
53
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@scalar/api-client/style.css";@import "@scalar/api-reference/style.css";.light-mode{--scalar-background-1:#fff;--scalar-background-2:#f8fafc;--scalar-background-3:#e7e7e7;--scalar-background-accent:#8ab4f81f;--scalar-color-1:#000;--scalar-color-2:#6b7280;--scalar-color-3:#9ca3af;--scalar-color-accent:#00c16a;--scalar-border-color:#e5e7eb;--scalar-color-green:#069061;--scalar-color-red:#ef4444;--scalar-color-yellow:#f59e0b;--scalar-color-blue:#1d4ed8;--scalar-color-orange:#fb892c;--scalar-color-purple:#6d28d9;--scalar-button-1:#000;--scalar-button-1-hover:rgba(0,0,0,.9);--scalar-button-1-color:#fff}.dark-mode{--scalar-background-1:#020420;--scalar-background-2:#121a31;--scalar-background-3:#1e293b;--scalar-background-accent:#8ab4f81f;--scalar-color-1:#fff;--scalar-color-2:#cbd5e1;--scalar-color-3:#94a3b8;--scalar-color-accent:#00dc82;--scalar-border-color:#1e293b;--scalar-color-green:#069061;--scalar-color-red:#f87171;--scalar-color-yellow:#fde68a;--scalar-color-blue:#60a5fa;--scalar-color-orange:#fb892c;--scalar-color-purple:#ddd6fe;--scalar-button-1:hsla(0,0%,100%,.9);--scalar-button-1-hover:hsla(0,0%,100%,.8);--scalar-button-1-color:#000}.dark-mode .t-doc__sidebar,.light-mode .t-doc__sidebar{--scalar-sidebar-background-1:var(--scalar-background-1);--scalar-sidebar-color-1:var(--scalar-color-1);--scalar-sidebar-color-2:var(--scalar-color-3);--scalar-sidebar-border-color:var(--scalar-border-color);--scalar-sidebar-item-hover-background:transparent;--scalar-sidebar-item-hover-color:var(--scalar-color-1);--scalar-sidebar-item-active-background:transparent;--scalar-sidebar-color-active:var(--scalar-color-accent);--scalar-sidebar-search-background:transparent;--scalar-sidebar-search-color:var(--scalar-color-3);--scalar-sidebar-search-border-color:var(--scalar-border-color);--scalar-sidebar-indent-border:var(--scalar-border-color);--scalar-sidebar-indent-border-hover:var(--scalar-color-1);--scalar-sidebar-indent-border-active:var(--scalar-color-accent)}.scalar-card .request-card-footer{--scalar-background-3:var(--scalar-background-2);--scalar-button-1:#0f172a;--scalar-button-1-hover:rgba(30,41,59,.5);--scalar-button-1-color:#fff}.scalar-card .show-api-client-button{border:1px solid #334155!important}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { useRoute } from '#imports'
|
|
3
|
+
import type { Meta } from '~/src/types'
|
|
4
|
+
|
|
5
|
+
const route = useRoute()
|
|
6
|
+
const meta = route.meta as Meta
|
|
7
|
+
|
|
8
|
+
// Ensure we have a spec
|
|
9
|
+
if (
|
|
10
|
+
!meta.isOpenApiEnabled &&
|
|
11
|
+
!meta.configuration?.spec?.url &&
|
|
12
|
+
!meta.configuration?.spec?.content
|
|
13
|
+
)
|
|
14
|
+
throw new Error(
|
|
15
|
+
'You must either provide a spec to scalar, or enable experimental openApi in the Nitro config.',
|
|
16
|
+
)
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<ScalarApiReference :configuration="meta.configuration" />
|
|
21
|
+
</template>
|
|
@@ -0,0 +1,13 @@
|
|
|
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.mts
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare module '#app' {
|
|
4
|
-
interface RuntimeNuxtHooks extends ModuleRuntimeHooks {}
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
declare module '@nuxt/schema' {
|
|
8
|
-
interface NuxtHooks extends ModuleHooks {}
|
|
9
|
-
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
10
|
-
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
declare module 'nuxt/schema' {
|
|
14
|
-
interface NuxtHooks extends ModuleHooks {}
|
|
15
|
-
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
16
|
-
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export * from "./module.js"
|
|
1
|
+
export { type ModuleOptions, default } from './module.js'
|
package/dist/types.d.ts
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare module '#app' {
|
|
4
|
-
interface RuntimeNuxtHooks extends ModuleRuntimeHooks {}
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
declare module '@nuxt/schema' {
|
|
8
|
-
interface NuxtHooks extends ModuleHooks {}
|
|
9
|
-
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
10
|
-
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
declare module 'nuxt/schema' {
|
|
14
|
-
interface NuxtHooks extends ModuleHooks {}
|
|
15
|
-
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
16
|
-
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export * from "./module"
|
|
1
|
+
export { type ModuleOptions, default } from './module'
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"testing",
|
|
21
21
|
"vue"
|
|
22
22
|
],
|
|
23
|
-
"version": "0.2.
|
|
23
|
+
"version": "0.2.40",
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=18"
|
|
26
26
|
},
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@nuxt/kit": "^3.12.3",
|
|
42
|
-
"@scalar/api-
|
|
43
|
-
"@scalar/api-
|
|
42
|
+
"@scalar/api-reference": "1.24.41",
|
|
43
|
+
"@scalar/api-client": "2.0.17"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@nuxt/devtools": "^1.3.9",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"@nuxt/module-builder": "^0.8.1",
|
|
49
49
|
"@nuxt/schema": "^3.12.3",
|
|
50
50
|
"@nuxt/test-utils": "^3.13.1",
|
|
51
|
-
"@types/node": "^20.
|
|
51
|
+
"@types/node": "^20.14.10",
|
|
52
52
|
"changelogen": "^0.5.5",
|
|
53
|
-
"eslint": "^8.
|
|
53
|
+
"eslint": "^8.57.0",
|
|
54
54
|
"nuxt": "^3.12.3",
|
|
55
55
|
"vitest": "^1.6.0"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
|
-
"build": "pnpm dev:prepare nuxt-module-build build",
|
|
58
|
+
"build": "pnpm dev:prepare && nuxt-module-build build",
|
|
59
59
|
"dev": "pnpm dev:prepare && nuxi dev playground",
|
|
60
60
|
"dev:build": "nuxi build playground",
|
|
61
61
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|