vitepress-openapi 0.2.13 → 0.2.14
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/{OAJSONEditor-Cxpub1dW.js → OAJSONEditor-BeZ8k8oU.js} +1 -1
- package/dist/{OAJSONEditor-B27HNYxA.cjs → OAJSONEditor-uRw8XH0g.cjs} +2 -2
- package/dist/{engine-javascript-C27eFBsG.cjs → engine-javascript-BuuII3Kr.cjs} +2 -2
- package/dist/{engine-javascript-Jp6ImdBF.js → engine-javascript-C0OBEbU1.js} +12 -12
- package/dist/standalone.css +1385 -0
- package/dist/types/src/client.d.ts +1 -12
- package/dist/types/src/components/Common/OADocRoot.vue.d.ts +15 -0
- package/dist/types/src/composables/useSidebar.d.ts +16 -3
- package/dist/types/src/lib/docRoot.d.ts +3 -0
- package/dist/types/src/lib/sidebar/cleanSidebarItems.d.ts +2 -3
- package/dist/types/src/lib/utils/copyCode.d.ts +1 -0
- package/dist/types/src/vue.d.ts +35 -0
- package/dist/vitepress-openapi.client.cjs.js +1 -6
- package/dist/vitepress-openapi.client.es.js +10 -17169
- package/dist/vitepress-openapi.css +1 -1
- package/dist/vitepress-openapi.vue.cjs.js +1 -0
- package/dist/vitepress-openapi.vue.es.js +3 -0
- package/dist/vue-2Bqkyliz.js +17260 -0
- package/dist/vue-ue8NZ9rA.cjs +6 -0
- package/package.json +15 -3
- package/src/client.ts +6 -39
- package/src/components/Common/OADocRoot.vue +18 -0
- package/src/components/Feature/OAInfo.vue +11 -5
- package/src/components/Feature/OAIntroduction.vue +12 -6
- package/src/components/Feature/OAOperation.vue +22 -19
- package/src/components/Feature/OAServers.vue +11 -5
- package/src/components/Feature/OASpec.vue +25 -22
- package/src/composables/useSidebar.ts +18 -4
- package/src/lib/docRoot.ts +4 -0
- package/src/lib/sidebar/cleanSidebarItems.ts +4 -5
- package/src/lib/utils/copyCode.ts +46 -0
- package/src/standalone.css +38 -0
- package/src/vue.ts +81 -0
- package/dist/classPrivateFieldGet2-B5R_onup.js +0 -22
- package/dist/classPrivateFieldGet2-Bglvjmhn.cjs +0 -1
- package/dist/lib-DtBHFGXA.cjs +0 -1
- package/dist/lib-DuAv3NcE.js +0 -27
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitepress-openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.14",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "^20.19.0 || ^22.13.0 || >=24.0.0"
|
|
7
7
|
},
|
|
@@ -27,7 +27,12 @@
|
|
|
27
27
|
"types": "./dist/types/src/client.d.ts",
|
|
28
28
|
"import": "./dist/vitepress-openapi.client.es.js"
|
|
29
29
|
},
|
|
30
|
-
"./
|
|
30
|
+
"./vue": {
|
|
31
|
+
"types": "./dist/types/src/vue.d.ts",
|
|
32
|
+
"import": "./dist/vitepress-openapi.vue.es.js"
|
|
33
|
+
},
|
|
34
|
+
"./dist/style.css": "./dist/vitepress-openapi.css",
|
|
35
|
+
"./dist/standalone.css": "./dist/standalone.css"
|
|
31
36
|
},
|
|
32
37
|
"main": "./dist/vitepress-openapi.node.es.js",
|
|
33
38
|
"module": "./dist/vitepress-openapi.node.es.js",
|
|
@@ -40,6 +45,11 @@
|
|
|
40
45
|
"vitepress": ">=1.0.0",
|
|
41
46
|
"vue": "^3.0.0"
|
|
42
47
|
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"vitepress": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
43
53
|
"dependencies": {
|
|
44
54
|
"@lucide/vue": "^1.39.0",
|
|
45
55
|
"@vueuse/core": "^14.4.0",
|
|
@@ -91,15 +101,17 @@
|
|
|
91
101
|
"scripts": {
|
|
92
102
|
"build": "vite build",
|
|
93
103
|
"build-watch": "vite build --watch",
|
|
94
|
-
"postbuild": "vue-tsc --emitDeclarationOnly",
|
|
104
|
+
"postbuild": "vue-tsc --emitDeclarationOnly && node scripts/build-standalone-css.mjs",
|
|
95
105
|
"lint": "eslint src .github/workflows",
|
|
96
106
|
"lint:fix": "eslint src .github/workflows --fix",
|
|
97
107
|
"dev": "cd docs && VITE_DEBUG=1 pnpm run dev",
|
|
108
|
+
"dev:standalone": "cd e2e/local/standalone && vite --mode source --port 4175",
|
|
98
109
|
"docs:build": "pnpm run build && cd docs && pnpm run build",
|
|
99
110
|
"test": "vitest",
|
|
100
111
|
"test:run": "vitest --run",
|
|
101
112
|
"typecheck": "vue-tsc --noEmit",
|
|
102
113
|
"e2e:local:dev": "cd e2e/local/dev && vitepress dev docs --port 4173",
|
|
114
|
+
"e2e:local:standalone": "cd e2e/local/standalone && vite --port 4174 --strictPort",
|
|
103
115
|
"e2e:local:test": "playwright test local",
|
|
104
116
|
"e2e:update-snapshots": "node scripts/update-snapshots.js",
|
|
105
117
|
"e2e:staging:test": "playwright test staging"
|
package/src/client.ts
CHANGED
|
@@ -2,11 +2,9 @@ import type { Awaitable } from 'vitepress'
|
|
|
2
2
|
import type { EnhanceAppContext, Theme } from 'vitepress/client'
|
|
3
3
|
import type { Component } from 'vue'
|
|
4
4
|
import type { OpenApiSpecInstance } from './lib/spec/createOpenApiSpec'
|
|
5
|
-
import { createI18n } from '@byjohann/vue-i18n'
|
|
6
5
|
import { useData } from 'vitepress'
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import { DEFAULT_OPERATION_SLOTS, setIsDarkSource, useTheme } from './composables/useTheme'
|
|
6
|
+
import { setIsDarkSource } from './composables/useTheme'
|
|
7
|
+
import { VOpenapi } from './vue'
|
|
10
8
|
|
|
11
9
|
interface OAEnhanceAppContext extends EnhanceAppContext {
|
|
12
10
|
openapi?: OpenApiSpecInstance | null
|
|
@@ -28,41 +26,10 @@ export const theme = {
|
|
|
28
26
|
// Not inside a VitePress app: keep the useDark fallback.
|
|
29
27
|
}
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const i18nConfig = themeConfig.getI18nConfig()
|
|
34
|
-
|
|
35
|
-
const i18n = createI18n({
|
|
36
|
-
defaultLocale: i18nConfig.locale?.value || 'en',
|
|
37
|
-
messages: i18nConfig.messages || {},
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
app.use(i18n)
|
|
41
|
-
|
|
42
|
-
watch(
|
|
43
|
-
() => themeConfig.getLocale(),
|
|
44
|
-
() => {
|
|
45
|
-
i18n.setLocale(themeConfig.getLocale())
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
immediate: true,
|
|
49
|
-
},
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
Object.entries(components).forEach(([key, component]) => {
|
|
53
|
-
app.component(key, component)
|
|
54
|
-
})
|
|
29
|
+
// VitePress already handles the copy buttons of code blocks, and its pages are already inside `.vp-doc`.
|
|
30
|
+
app.use(VOpenapi, { copyCode: false, vpDoc: false })
|
|
55
31
|
},
|
|
56
32
|
} as VPTheme
|
|
57
33
|
|
|
58
|
-
|
|
59
|
-
export
|
|
60
|
-
export { usePlayground } from './composables/usePlayground'
|
|
61
|
-
export { DEFAULT_OPERATION_SLOTS }
|
|
62
|
-
export { useShiki } from './composables/useShiki'
|
|
63
|
-
export { useTheme } from './composables/useTheme'
|
|
64
|
-
export { generateCodeSample } from './lib/codeSamples/generateCodeSample'
|
|
65
|
-
export { OARequest } from './lib/codeSamples/request'
|
|
66
|
-
export { createOpenApiSpec } from './lib/spec/createOpenApiSpec'
|
|
67
|
-
export { minifyHtml } from './lib/utils/minifyHtml'
|
|
68
|
-
export { locales } from './locales'
|
|
34
|
+
// Everything that does not depend on VitePress lives in `vitepress-openapi/vue`.
|
|
35
|
+
export * from './vue'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { inject } from 'vue'
|
|
3
|
+
import { DOC_ROOT_KEY } from '../../lib/docRoot'
|
|
4
|
+
|
|
5
|
+
// The entry components already forward their attrs to the content; keep this wrapper attr-free.
|
|
6
|
+
defineOptions({ inheritAttrs: false })
|
|
7
|
+
|
|
8
|
+
// Outside VitePress, the content needs a `.vp-doc` ancestor for standalone.css.
|
|
9
|
+
// Inside VitePress, pages already have one, so render the content as is.
|
|
10
|
+
const vpDoc = inject(DOC_ROOT_KEY, false)
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<div v-if="vpDoc" class="vp-doc">
|
|
15
|
+
<slot />
|
|
16
|
+
</div>
|
|
17
|
+
<slot v-else />
|
|
18
|
+
</template>
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
+
import OADocRoot from '../Common/OADocRoot.vue'
|
|
2
3
|
import OAProvider from '../Context/OAProvider.vue'
|
|
3
4
|
import OAInfoContent from './OAInfoContent.vue'
|
|
4
5
|
|
|
6
|
+
// Attrs (e.g. `spec-url`) go to OAProvider, not to the OADocRoot wrapper.
|
|
7
|
+
defineOptions({ inheritAttrs: false })
|
|
8
|
+
|
|
5
9
|
const props = defineProps({
|
|
6
10
|
spec: {
|
|
7
11
|
type: [Object, String],
|
|
@@ -11,9 +15,11 @@ const props = defineProps({
|
|
|
11
15
|
</script>
|
|
12
16
|
|
|
13
17
|
<template>
|
|
14
|
-
<
|
|
15
|
-
<
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
<OADocRoot>
|
|
19
|
+
<OAProvider v-bind="$attrs" :spec="props.spec">
|
|
20
|
+
<template #default="{ openapi }">
|
|
21
|
+
<OAInfoContent :openapi="openapi" />
|
|
22
|
+
</template>
|
|
23
|
+
</OAProvider>
|
|
24
|
+
</OADocRoot>
|
|
19
25
|
</template>
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
+
import OADocRoot from '../Common/OADocRoot.vue'
|
|
2
3
|
import OAProvider from '../Context/OAProvider.vue'
|
|
3
4
|
import OAInfoContent from './OAInfoContent.vue'
|
|
4
5
|
import OAServersContent from './OAServersContent.vue'
|
|
5
6
|
|
|
7
|
+
// Attrs (e.g. `spec-url`) go to OAProvider, not to the OADocRoot wrapper.
|
|
8
|
+
defineOptions({ inheritAttrs: false })
|
|
9
|
+
|
|
6
10
|
const props = defineProps({
|
|
7
11
|
spec: {
|
|
8
12
|
type: [Object, String],
|
|
@@ -12,10 +16,12 @@ const props = defineProps({
|
|
|
12
16
|
</script>
|
|
13
17
|
|
|
14
18
|
<template>
|
|
15
|
-
<
|
|
16
|
-
<
|
|
17
|
-
<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
<OADocRoot>
|
|
20
|
+
<OAProvider v-bind="$attrs" :spec="props.spec">
|
|
21
|
+
<template #default="{ openapi }">
|
|
22
|
+
<OAInfoContent :openapi="openapi" />
|
|
23
|
+
<OAServersContent :openapi="openapi" />
|
|
24
|
+
</template>
|
|
25
|
+
</OAProvider>
|
|
26
|
+
</OADocRoot>
|
|
21
27
|
</template>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { OperationSlot, ResponseDescriptionSlotProps } from '../../types'
|
|
3
|
+
import OADocRoot from '../Common/OADocRoot.vue'
|
|
3
4
|
import OAProvider from '../Context/OAProvider.vue'
|
|
4
5
|
import OAOperationContent from './OAOperationContent.vue'
|
|
5
6
|
|
|
@@ -55,23 +56,25 @@ const slots = defineSlots<{ [K in OperationSlot]?: (props: any) => any } & {
|
|
|
55
56
|
</script>
|
|
56
57
|
|
|
57
58
|
<template>
|
|
58
|
-
<
|
|
59
|
-
<
|
|
60
|
-
<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
59
|
+
<OADocRoot>
|
|
60
|
+
<OAProvider :spec="props.spec" :spec-url="props.specUrl" @update:spec="emits('update:spec', $event)">
|
|
61
|
+
<template #default="{ openapi }">
|
|
62
|
+
<OAOperationContent
|
|
63
|
+
v-bind="{
|
|
64
|
+
...$attrs,
|
|
65
|
+
operationId: props.operationId,
|
|
66
|
+
openapi,
|
|
67
|
+
prefixHeadings: props.prefixHeadings,
|
|
68
|
+
hideBranding: props.hideBranding,
|
|
69
|
+
hideDefaultFooter: props.hideDefaultFooter,
|
|
70
|
+
}"
|
|
71
|
+
>
|
|
72
|
+
<!-- Expose all slots upwards -->
|
|
73
|
+
<template v-for="(_, name) in slots" #[name]="slotProps">
|
|
74
|
+
<slot :name="name" v-bind="slotProps || {}" />
|
|
75
|
+
</template>
|
|
76
|
+
</OAOperationContent>
|
|
77
|
+
</template>
|
|
78
|
+
</OAProvider>
|
|
79
|
+
</OADocRoot>
|
|
77
80
|
</template>
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
+
import OADocRoot from '../Common/OADocRoot.vue'
|
|
2
3
|
import OAProvider from '../Context/OAProvider.vue'
|
|
3
4
|
import OAServersContent from './OAServersContent.vue'
|
|
4
5
|
|
|
6
|
+
// Attrs (e.g. `spec-url`) go to OAProvider, not to the OADocRoot wrapper.
|
|
7
|
+
defineOptions({ inheritAttrs: false })
|
|
8
|
+
|
|
5
9
|
const props = defineProps({
|
|
6
10
|
spec: {
|
|
7
11
|
type: [Object, String],
|
|
@@ -11,9 +15,11 @@ const props = defineProps({
|
|
|
11
15
|
</script>
|
|
12
16
|
|
|
13
17
|
<template>
|
|
14
|
-
<
|
|
15
|
-
<
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
<OADocRoot>
|
|
19
|
+
<OAProvider v-bind="$attrs" :spec="props.spec">
|
|
20
|
+
<template #default="{ openapi }">
|
|
21
|
+
<OAServersContent :openapi="openapi" />
|
|
22
|
+
</template>
|
|
23
|
+
</OAProvider>
|
|
24
|
+
</OADocRoot>
|
|
19
25
|
</template>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { OperationSlot, ResponseDescriptionSlotProps } from '../../types'
|
|
3
|
+
import OADocRoot from '../Common/OADocRoot.vue'
|
|
3
4
|
import OAProvider from '../Context/OAProvider.vue'
|
|
4
5
|
import OASpecContent from './OASpecContent.vue'
|
|
5
6
|
|
|
@@ -67,26 +68,28 @@ const slots = defineSlots<{ [K in OperationSlot]?: (props: any) => any } & {
|
|
|
67
68
|
</script>
|
|
68
69
|
|
|
69
70
|
<template>
|
|
70
|
-
<
|
|
71
|
-
<
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
<
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
71
|
+
<OADocRoot>
|
|
72
|
+
<OAProvider :spec="props.spec" :spec-url="props.specUrl" @update:spec="emits('update:spec', $event)">
|
|
73
|
+
<template #default="{ openapi }">
|
|
74
|
+
<OASpecContent
|
|
75
|
+
v-bind="{
|
|
76
|
+
...$attrs,
|
|
77
|
+
openapi,
|
|
78
|
+
hideInfo: props.hideInfo,
|
|
79
|
+
hideServers: props.hideServers,
|
|
80
|
+
groupByTags: props.groupByTags,
|
|
81
|
+
tags: props.tags,
|
|
82
|
+
hideDefaultFooter: props.hideDefaultFooter,
|
|
83
|
+
hideBranding: props.hideBranding,
|
|
84
|
+
hidePathsSummary: props.hidePathsSummary,
|
|
85
|
+
}"
|
|
86
|
+
>
|
|
87
|
+
<!-- Expose all slots upwards -->
|
|
88
|
+
<template v-for="(_, name) in slots" #[name]="slotProps">
|
|
89
|
+
<slot :name="name" v-bind="slotProps || {}" />
|
|
90
|
+
</template>
|
|
91
|
+
</OASpecContent>
|
|
92
|
+
</template>
|
|
93
|
+
</OAProvider>
|
|
94
|
+
</OADocRoot>
|
|
92
95
|
</template>
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from '@scalar/openapi-types'
|
|
2
|
-
import type { DefaultTheme } from 'vitepress'
|
|
3
2
|
import type { OpenAPIDocument } from '../types'
|
|
4
3
|
import { httpVerbs } from '../index'
|
|
5
4
|
import { parseOpenapi } from '../lib/parser/parseOpenapi'
|
|
@@ -60,7 +59,22 @@ export interface SidebarGroupsConfig {
|
|
|
60
59
|
sidebarGroupTemplate?: SidebarGroupTemplateFn
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Same shape as VitePress' `SidebarItem`, so it can be used as `themeConfig.sidebar`,
|
|
64
|
+
* without depending on VitePress types (e.g. in a plain Vue app).
|
|
65
|
+
*/
|
|
66
|
+
export interface SidebarItem {
|
|
67
|
+
text?: string
|
|
68
|
+
link?: string
|
|
69
|
+
items?: SidebarItem[]
|
|
70
|
+
collapsed?: boolean
|
|
71
|
+
base?: string
|
|
72
|
+
docFooterText?: string
|
|
73
|
+
rel?: string
|
|
74
|
+
target?: string
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface OASidebarItem extends SidebarItem {
|
|
64
78
|
path?: string
|
|
65
79
|
isOperation?: boolean
|
|
66
80
|
flattenedItems?: OASidebarItem[]
|
|
@@ -284,7 +298,7 @@ export function useSidebar({
|
|
|
284
298
|
linkPrefix?: string
|
|
285
299
|
sidebarItemTemplate?: SidebarItemTemplateFn
|
|
286
300
|
sidebarGroupTemplate?: SidebarGroupTemplateFn
|
|
287
|
-
} = {}):
|
|
301
|
+
} = {}): SidebarItem[] {
|
|
288
302
|
const paths = getOpenApi().getPaths()
|
|
289
303
|
|
|
290
304
|
const itemTemplateForMethodPath = ({
|
|
@@ -306,7 +320,7 @@ export function useSidebar({
|
|
|
306
320
|
sidebarGroupTemplate,
|
|
307
321
|
})
|
|
308
322
|
|
|
309
|
-
return cleanSidebarItems(sidebarItems) as
|
|
323
|
+
return cleanSidebarItems(sidebarItems) as SidebarItem[]
|
|
310
324
|
}
|
|
311
325
|
|
|
312
326
|
return {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { OASidebarItem } from '../../composables/useSidebar'
|
|
1
|
+
import type { OASidebarItem, SidebarItem } from '../../composables/useSidebar'
|
|
3
2
|
|
|
4
|
-
export function cleanSidebarItems(result: (OASidebarItem[] | OASidebarItem)):
|
|
3
|
+
export function cleanSidebarItems(result: (OASidebarItem[] | OASidebarItem)): SidebarItem[] | SidebarItem {
|
|
5
4
|
if (Array.isArray(result)) {
|
|
6
|
-
return result.map(cleanSidebarItems) as
|
|
5
|
+
return result.map(cleanSidebarItems) as SidebarItem[]
|
|
7
6
|
}
|
|
8
7
|
|
|
9
8
|
if (typeof result === 'object') {
|
|
@@ -12,7 +11,7 @@ export function cleanSidebarItems(result: (OASidebarItem[] | OASidebarItem)): De
|
|
|
12
11
|
...(result.collapsed === undefined ? {} : { collapsed: result.collapsed }),
|
|
13
12
|
...(result.link ? { link: result.link } : {}),
|
|
14
13
|
...(result.items ? { items: cleanSidebarItems(result.items) } : {}),
|
|
15
|
-
} as
|
|
14
|
+
} as SidebarItem
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
return result
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copy buttons in code blocks (`div[class*="language-"] > button.copy`), for apps without VitePress.
|
|
2
|
+
// Port of VitePress' useCopyCode (MIT, https://github.com/vuejs/vitepress).
|
|
3
|
+
|
|
4
|
+
const COPY_BUTTON_SELECTOR = 'div[class*="language-"] > button.copy'
|
|
5
|
+
const RE_SHELL_LANGUAGE = /language-(?:shellscript|shell|bash|sh|zsh)/
|
|
6
|
+
const RE_SHELL_PROMPT = /^ *[$>] /gm
|
|
7
|
+
const COPIED_MS = 2000
|
|
8
|
+
|
|
9
|
+
let isSetup = false
|
|
10
|
+
|
|
11
|
+
export function setupCopyCode() {
|
|
12
|
+
if (isSetup || typeof window === 'undefined') {
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
|
+
isSetup = true
|
|
16
|
+
|
|
17
|
+
const timeouts = new WeakMap<HTMLElement, ReturnType<typeof setTimeout>>()
|
|
18
|
+
|
|
19
|
+
window.addEventListener('click', (event) => {
|
|
20
|
+
const button = event.target as HTMLElement | null
|
|
21
|
+
if (!button?.matches?.(COPY_BUTTON_SELECTOR)) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Markup: button.copy, span.lang, then the code.
|
|
26
|
+
const code = button.nextElementSibling?.nextElementSibling
|
|
27
|
+
if (!code) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let text = code.textContent || ''
|
|
32
|
+
if (RE_SHELL_LANGUAGE.test(button.parentElement?.className ?? '')) {
|
|
33
|
+
text = text.replace(RE_SHELL_PROMPT, '').trim()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
navigator.clipboard?.writeText(text).then(() => {
|
|
37
|
+
button.classList.add('copied')
|
|
38
|
+
clearTimeout(timeouts.get(button))
|
|
39
|
+
timeouts.set(button, setTimeout(() => {
|
|
40
|
+
button.classList.remove('copied')
|
|
41
|
+
button.blur()
|
|
42
|
+
timeouts.delete(button)
|
|
43
|
+
}, COPIED_MS))
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Styles for using vitepress-openapi outside VitePress (e.g. with `vitepress-openapi/vue`).
|
|
3
|
+
*
|
|
4
|
+
* Inside VitePress, its default theme provides these styles. Do not load this file there.
|
|
5
|
+
*
|
|
6
|
+
* Usage: import it before `vitepress-openapi/dist/style.css` (the same order as in VitePress).
|
|
7
|
+
* The `VOpenapi` plugin wraps the components in a `.vp-doc` element, which these styles target.
|
|
8
|
+
* Override any `--vp-*` variable to match your design.
|
|
9
|
+
*
|
|
10
|
+
* The imports below are VitePress' own default theme styles (MIT, https://github.com/vuejs/vitepress).
|
|
11
|
+
* The build inlines them into dist/standalone.css, so VitePress is not needed at runtime.
|
|
12
|
+
*/
|
|
13
|
+
@import 'vitepress/dist/client/theme-default/styles/vars.css';
|
|
14
|
+
@import 'vitepress/dist/client/theme-default/styles/icons.css';
|
|
15
|
+
@import 'vitepress/dist/client/theme-default/styles/components/vp-doc.css';
|
|
16
|
+
@import 'vitepress/dist/client/theme-default/styles/components/vp-code-group.css';
|
|
17
|
+
|
|
18
|
+
/* Base text and page colors, like VitePress' base.css. Zero specificity: any app style on html/body wins. */
|
|
19
|
+
:where(html) {
|
|
20
|
+
color: var(--vp-c-text-1);
|
|
21
|
+
background-color: var(--vp-c-bg);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.vp-doc {
|
|
25
|
+
line-height: 24px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.vp-doc :is(pre, code, kbd, samp) {
|
|
29
|
+
font-family: var(--vp-font-family-mono);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Space between the operation columns (VitePress applies it through its .VPDoc layout). */
|
|
33
|
+
@media (min-width: 640px) {
|
|
34
|
+
.OAPathContentEnd {
|
|
35
|
+
padding-right: 24px;
|
|
36
|
+
padding-left: 24px;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/vue.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { App, Plugin } from 'vue'
|
|
2
|
+
import type { PartialUseThemeConfig } from './composables/useTheme'
|
|
3
|
+
import type { OpenAPIDocument } from './types'
|
|
4
|
+
import { createI18n } from '@byjohann/vue-i18n'
|
|
5
|
+
import { watch } from 'vue'
|
|
6
|
+
import * as components from './components'
|
|
7
|
+
import { useOpenapi } from './composables/useOpenapi'
|
|
8
|
+
import { DEFAULT_OPERATION_SLOTS, useTheme } from './composables/useTheme'
|
|
9
|
+
import { DOC_ROOT_KEY } from './lib/docRoot'
|
|
10
|
+
import { setupCopyCode } from './lib/utils/copyCode'
|
|
11
|
+
|
|
12
|
+
export interface VOpenapiOptions {
|
|
13
|
+
/** OpenAPI document (object, or a JSON/YAML string) used by components without their own `spec`. */
|
|
14
|
+
spec?: OpenAPIDocument | string
|
|
15
|
+
/** Theme configuration, the same as `useTheme(config)`. */
|
|
16
|
+
config?: PartialUseThemeConfig
|
|
17
|
+
/** Handle the copy buttons of code blocks. VitePress already does it, so its theme disables this. Default: true. */
|
|
18
|
+
copyCode?: boolean
|
|
19
|
+
/**
|
|
20
|
+
* Wrap the entry components (OAOperation, OASpec, OAIntroduction, OAInfo, OAServers) in a `.vp-doc`
|
|
21
|
+
* element, which `standalone.css` styles. VitePress pages are already inside `.vp-doc`, so its theme
|
|
22
|
+
* disables this. Default: true.
|
|
23
|
+
*/
|
|
24
|
+
vpDoc?: boolean
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Vue plugin to use the components in any Vue 3 app, without VitePress.
|
|
29
|
+
* It installs i18n and registers the components globally.
|
|
30
|
+
*/
|
|
31
|
+
export const VOpenapi: Plugin<[VOpenapiOptions?]> = {
|
|
32
|
+
install(app: App, options: VOpenapiOptions = {}) {
|
|
33
|
+
if (options.spec || options.config) {
|
|
34
|
+
useOpenapi(options)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (options.copyCode !== false) {
|
|
38
|
+
setupCopyCode()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
app.provide(DOC_ROOT_KEY, options.vpDoc !== false)
|
|
42
|
+
|
|
43
|
+
const themeConfig = useTheme()
|
|
44
|
+
|
|
45
|
+
const i18nConfig = themeConfig.getI18nConfig()
|
|
46
|
+
|
|
47
|
+
const i18n = createI18n({
|
|
48
|
+
defaultLocale: i18nConfig.locale?.value || 'en',
|
|
49
|
+
messages: i18nConfig.messages || {},
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
app.use(i18n)
|
|
53
|
+
|
|
54
|
+
watch(
|
|
55
|
+
() => themeConfig.getLocale(),
|
|
56
|
+
() => {
|
|
57
|
+
i18n.setLocale(themeConfig.getLocale())
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
immediate: true,
|
|
61
|
+
},
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
Object.entries(components).forEach(([key, component]) => {
|
|
65
|
+
app.component(key, component)
|
|
66
|
+
})
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export * from './components'
|
|
71
|
+
export { useOpenapi } from './composables/useOpenapi'
|
|
72
|
+
export { usePlayground } from './composables/usePlayground'
|
|
73
|
+
export { DEFAULT_OPERATION_SLOTS }
|
|
74
|
+
export { useShiki } from './composables/useShiki'
|
|
75
|
+
export { type SidebarItem, useSidebar } from './composables/useSidebar'
|
|
76
|
+
export { type PartialUseThemeConfig, useTheme } from './composables/useTheme'
|
|
77
|
+
export { generateCodeSample } from './lib/codeSamples/generateCodeSample'
|
|
78
|
+
export { OARequest } from './lib/codeSamples/request'
|
|
79
|
+
export { createOpenApiSpec } from './lib/spec/createOpenApiSpec'
|
|
80
|
+
export { minifyHtml } from './lib/utils/minifyHtml'
|
|
81
|
+
export { locales } from './locales'
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/checkPrivateRedeclaration.js
|
|
2
|
-
function e(e, t) {
|
|
3
|
-
if (t.has(e)) throw TypeError("Cannot initialize the same private elements twice on an object");
|
|
4
|
-
}
|
|
5
|
-
//#endregion
|
|
6
|
-
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/classPrivateFieldInitSpec.js
|
|
7
|
-
function t(t, n, r) {
|
|
8
|
-
e(t, n), n.set(t, r);
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
11
|
-
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/assertClassBrand.js
|
|
12
|
-
function n(e, t, n) {
|
|
13
|
-
if (typeof e == "function" ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
14
|
-
throw TypeError("Private element is not present on this object");
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/classPrivateFieldGet2.js
|
|
18
|
-
function r(e, t) {
|
|
19
|
-
return e.get(n(e, t));
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
export { e as i, n, t as r, r as t };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function e(e,t){if(t.has(e))throw TypeError(`Cannot initialize the same private elements twice on an object`)}function t(t,n,r){e(t,n),n.set(t,r)}function n(e,t,n){if(typeof e==`function`?e===t:e.has(t))return arguments.length<3?t:n;throw TypeError(`Private element is not present on this object`)}function r(e,t){return e.get(n(e,t))}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return r}});
|
package/dist/lib-DtBHFGXA.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require("./useOpenapi-D3rJQzeG.cjs");let t=require("vue"),n=e.nt(t,1);t=e.nt(t);var r=e.et({Vue:()=>n,Vue2:()=>void 0,del:()=>o,install:()=>i,isVue2:()=>!1,isVue3:()=>!0,set:()=>a});e.tt(r,require("vue"));function i(){}function a(e,t,n){return Array.isArray(e)?(e.length=Math.max(e.length,t),e.splice(t,1,n),n):(e[t]=n,n)}function o(e,t){if(Array.isArray(e)){e.splice(t,1);return}delete e[t]}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return r}});
|
package/dist/lib-DuAv3NcE.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { et as e, tt as t } from "./useOpenapi-DVLwqpMR.js";
|
|
2
|
-
import * as n from "vue";
|
|
3
|
-
//#region node_modules/.pnpm/vue-demi@0.14.10_vue@3.5.42_typescript@6.0.3_/node_modules/vue-demi/lib/index.mjs
|
|
4
|
-
var r = /* @__PURE__ */ e({
|
|
5
|
-
Vue: () => n,
|
|
6
|
-
Vue2: () => void 0,
|
|
7
|
-
del: () => s,
|
|
8
|
-
install: () => a,
|
|
9
|
-
isVue2: () => !1,
|
|
10
|
-
isVue3: () => !0,
|
|
11
|
-
set: () => o
|
|
12
|
-
});
|
|
13
|
-
import * as i from "vue";
|
|
14
|
-
t(r, i);
|
|
15
|
-
function a() {}
|
|
16
|
-
function o(e, t, n) {
|
|
17
|
-
return Array.isArray(e) ? (e.length = Math.max(e.length, t), e.splice(t, 1, n), n) : (e[t] = n, n);
|
|
18
|
-
}
|
|
19
|
-
function s(e, t) {
|
|
20
|
-
if (Array.isArray(e)) {
|
|
21
|
-
e.splice(t, 1);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
delete e[t];
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
export { r as t };
|