vitepress-openapi 0.2.13 → 0.2.15

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.
Files changed (43) hide show
  1. package/dist/{OAJSONEditor-Cxpub1dW.js → OAJSONEditor-BPdzinnW.js} +1 -1
  2. package/dist/{OAJSONEditor-B27HNYxA.cjs → OAJSONEditor-cdYfH8pW.cjs} +2 -2
  3. package/dist/{engine-javascript-Jp6ImdBF.js → engine-javascript-DSMQf2z2.js} +12 -12
  4. package/dist/{engine-javascript-C27eFBsG.cjs → engine-javascript-DsJlQOsE.cjs} +2 -2
  5. package/dist/standalone.css +1385 -0
  6. package/dist/types/src/client.d.ts +1 -12
  7. package/dist/types/src/components/Common/OADocRoot.vue.d.ts +15 -0
  8. package/dist/types/src/components/Feature/OASpec.vue.d.ts +17 -0
  9. package/dist/types/src/composables/useSidebar.d.ts +16 -3
  10. package/dist/types/src/lib/docRoot.d.ts +3 -0
  11. package/dist/types/src/lib/sidebar/cleanSidebarItems.d.ts +2 -3
  12. package/dist/types/src/lib/spec/lazyRendering.d.ts +5 -0
  13. package/dist/types/src/lib/utils/copyCode.d.ts +1 -0
  14. package/dist/types/src/vue.d.ts +35 -0
  15. package/dist/vitepress-openapi.client.cjs.js +1 -6
  16. package/dist/vitepress-openapi.client.es.js +10 -17169
  17. package/dist/vitepress-openapi.css +1 -1
  18. package/dist/vitepress-openapi.vue.cjs.js +1 -0
  19. package/dist/vitepress-openapi.vue.es.js +3 -0
  20. package/dist/vue-Cdo23EVh.cjs +6 -0
  21. package/dist/vue-DpVGGK22.js +17272 -0
  22. package/package.json +16 -4
  23. package/src/client.ts +6 -39
  24. package/src/components/Common/OADocRoot.vue +18 -0
  25. package/src/components/Feature/OAInfo.vue +11 -5
  26. package/src/components/Feature/OAIntroduction.vue +12 -6
  27. package/src/components/Feature/OAOperation.vue +22 -19
  28. package/src/components/Feature/OAServers.vue +11 -5
  29. package/src/components/Feature/OASpec.vue +37 -22
  30. package/src/components/Path/OAPaths.vue +12 -5
  31. package/src/components/Path/OAPathsGroup.vue +2 -1
  32. package/src/components/Path/OAPathsGroups.vue +2 -3
  33. package/src/composables/useSidebar.ts +18 -4
  34. package/src/lib/docRoot.ts +4 -0
  35. package/src/lib/sidebar/cleanSidebarItems.ts +4 -5
  36. package/src/lib/spec/lazyRendering.ts +12 -0
  37. package/src/lib/utils/copyCode.ts +46 -0
  38. package/src/standalone.css +38 -0
  39. package/src/vue.ts +81 -0
  40. package/dist/classPrivateFieldGet2-B5R_onup.js +0 -22
  41. package/dist/classPrivateFieldGet2-Bglvjmhn.cjs +0 -1
  42. package/dist/lib-DtBHFGXA.cjs +0 -1
  43. 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.13",
4
+ "version": "0.2.15",
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
- "./dist/style.css": "./dist/vitepress-openapi.css"
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",
@@ -38,7 +43,12 @@
38
43
  ],
39
44
  "peerDependencies": {
40
45
  "vitepress": ">=1.0.0",
41
- "vue": "^3.0.0"
46
+ "vue": "^3.5.0"
47
+ },
48
+ "peerDependenciesMeta": {
49
+ "vitepress": {
50
+ "optional": true
51
+ }
42
52
  },
43
53
  "dependencies": {
44
54
  "@lucide/vue": "^1.39.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 { watch } from 'vue'
8
- import * as components from './components'
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
- const themeConfig = useTheme()
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
- export * from './components'
59
- export { useOpenapi } from './composables/useOpenapi'
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
- <OAProvider :spec="props.spec">
15
- <template #default="{ openapi }">
16
- <OAInfoContent :openapi="openapi" />
17
- </template>
18
- </OAProvider>
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
- <OAProvider :spec="props.spec">
16
- <template #default="{ openapi }">
17
- <OAInfoContent :openapi="openapi" />
18
- <OAServersContent :openapi="openapi" />
19
- </template>
20
- </OAProvider>
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
- <OAProvider :spec="props.spec" :spec-url="props.specUrl" @update:spec="emits('update:spec', $event)">
59
- <template #default="{ openapi }">
60
- <OAOperationContent
61
- v-bind="{
62
- ...$attrs,
63
- operationId: props.operationId,
64
- openapi,
65
- prefixHeadings: props.prefixHeadings,
66
- hideBranding: props.hideBranding,
67
- hideDefaultFooter: props.hideDefaultFooter,
68
- }"
69
- >
70
- <!-- Expose all slots upwards -->
71
- <template v-for="(_, name) in slots" #[name]="slotProps">
72
- <slot :name="name" v-bind="slotProps || {}" />
73
- </template>
74
- </OAOperationContent>
75
- </template>
76
- </OAProvider>
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
- <OAProvider :spec="props.spec">
15
- <template #default="{ openapi }">
16
- <OAServersContent :openapi="openapi" />
17
- </template>
18
- </OAProvider>
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,8 @@
1
1
  <script setup lang="ts">
2
2
  import type { OperationSlot, ResponseDescriptionSlotProps } from '../../types'
3
+ import { provide } from 'vue'
4
+ import { LAZY_RENDERING_KEY } from '../../lib/spec/lazyRendering'
5
+ import OADocRoot from '../Common/OADocRoot.vue'
3
6
  import OAProvider from '../Context/OAProvider.vue'
4
7
  import OASpecContent from './OASpecContent.vue'
5
8
 
@@ -55,6 +58,14 @@ const props = defineProps({
55
58
  type: Boolean,
56
59
  default: undefined,
57
60
  },
61
+ /**
62
+ * Render only the first operation, and the rest when the browser is idle. Overrides `spec.lazyRendering`
63
+ * of the theme config for this instance, also during SSR (where page-level theme config may not apply).
64
+ */
65
+ lazyRendering: {
66
+ type: Boolean,
67
+ default: undefined,
68
+ },
58
69
  })
59
70
 
60
71
  const emits = defineEmits([
@@ -64,29 +75,33 @@ const emits = defineEmits([
64
75
  const slots = defineSlots<{ [K in OperationSlot]?: (props: any) => any } & {
65
76
  'response-description'?: (props: ResponseDescriptionSlotProps) => any
66
77
  }>()
78
+
79
+ provide(LAZY_RENDERING_KEY, props.lazyRendering)
67
80
  </script>
68
81
 
69
82
  <template>
70
- <OAProvider :spec="props.spec" :spec-url="props.specUrl" @update:spec="emits('update:spec', $event)">
71
- <template #default="{ openapi }">
72
- <OASpecContent
73
- v-bind="{
74
- ...$attrs,
75
- openapi,
76
- hideInfo: props.hideInfo,
77
- hideServers: props.hideServers,
78
- groupByTags: props.groupByTags,
79
- tags: props.tags,
80
- hideDefaultFooter: props.hideDefaultFooter,
81
- hideBranding: props.hideBranding,
82
- hidePathsSummary: props.hidePathsSummary,
83
- }"
84
- >
85
- <!-- Expose all slots upwards -->
86
- <template v-for="(_, name) in slots" #[name]="slotProps">
87
- <slot :name="name" v-bind="slotProps || {}" />
88
- </template>
89
- </OASpecContent>
90
- </template>
91
- </OAProvider>
83
+ <OADocRoot>
84
+ <OAProvider :spec="props.spec" :spec-url="props.specUrl" @update:spec="emits('update:spec', $event)">
85
+ <template #default="{ openapi }">
86
+ <OASpecContent
87
+ v-bind="{
88
+ ...$attrs,
89
+ openapi,
90
+ hideInfo: props.hideInfo,
91
+ hideServers: props.hideServers,
92
+ groupByTags: props.groupByTags,
93
+ tags: props.tags,
94
+ hideDefaultFooter: props.hideDefaultFooter,
95
+ hideBranding: props.hideBranding,
96
+ hidePathsSummary: props.hidePathsSummary,
97
+ }"
98
+ >
99
+ <!-- Expose all slots upwards -->
100
+ <template v-for="(_, name) in slots" #[name]="slotProps">
101
+ <slot :name="name" v-bind="slotProps || {}" />
102
+ </template>
103
+ </OASpecContent>
104
+ </template>
105
+ </OAProvider>
106
+ </OADocRoot>
92
107
  </template>
@@ -1,7 +1,8 @@
1
1
  <script setup lang="ts">
2
2
  import type { OperationNestedSlot, OperationSlot } from '../../types'
3
+ import { defineAsyncComponent, hydrateOnVisible } from 'vue'
3
4
  import { getGlobalOpenapi, injectOpenapi } from '../../composables/useOpenapi'
4
- import { useTheme } from '../../composables/useTheme'
5
+ import { useLazyRendering } from '../../lib/spec/lazyRendering'
5
6
  import OALazy from '../Common/Lazy/OALazy.vue'
6
7
  import OAOperationContent from '../Feature/OAOperationContent.vue'
7
8
 
@@ -14,7 +15,13 @@ const { paths } = defineProps({
14
15
 
15
16
  const slots = defineSlots<{ [K in OperationSlot | OperationNestedSlot]?: (props: any) => any }>()
16
17
 
17
- const themeConfig = useTheme()
18
+ // The server renders every operation (full HTML for SEO), but on the client each one hydrates only once it
19
+ // is near the viewport, so large specs do not run all their components on load. Client-side renders are
20
+ // not affected. The loader resolves immediately: this is about hydration, not code splitting.
21
+ const OAOperationContentOnVisible = defineAsyncComponent({
22
+ loader: () => Promise.resolve(OAOperationContent),
23
+ hydrate: hydrateOnVisible({ rootMargin: '400px' }),
24
+ })
18
25
 
19
26
  const operations = Object.entries(paths).reduce((acc: { operationId: string }[], [_, path]) => {
20
27
  return [
@@ -27,7 +34,7 @@ const operations = Object.entries(paths).reduce((acc: { operationId: string }[],
27
34
  ]
28
35
  }, [])
29
36
 
30
- const lazyRendering = themeConfig.getSpecConfig()?.lazyRendering?.value
37
+ const lazyRendering = useLazyRendering()
31
38
 
32
39
  const openapi = injectOpenapi() ?? getGlobalOpenapi()
33
40
  </script>
@@ -39,7 +46,7 @@ const openapi = injectOpenapi() ?? getGlobalOpenapi()
39
46
  :key="operation.operationId"
40
47
  :is-lazy="lazyRendering && operationIdx > 0"
41
48
  >
42
- <OAOperationContent
49
+ <OAOperationContentOnVisible
43
50
  :openapi="openapi"
44
51
  :operation-id="operation.operationId"
45
52
  prefix-headings
@@ -55,7 +62,7 @@ const openapi = injectOpenapi() ?? getGlobalOpenapi()
55
62
  v-bind="slotProps || {}"
56
63
  />
57
64
  </template>
58
- </OAOperationContent>
65
+ </OAOperationContentOnVisible>
59
66
 
60
67
  <hr>
61
68
  </OALazy>
@@ -4,6 +4,7 @@ import { useI18n } from '@byjohann/vue-i18n'
4
4
  import { computed, nextTick, ref } from 'vue'
5
5
  import { scrollToHash } from '@/lib/utils/utils'
6
6
  import { useTheme } from '../../composables/useTheme'
7
+ import { useLazyRendering } from '../../lib/spec/lazyRendering'
7
8
  import OAHeading from '../Common/OAHeading.vue'
8
9
  import OAMarkdown from '../Common/OAMarkdown.vue'
9
10
  import { Button } from '../ui/button'
@@ -24,7 +25,7 @@ const slots = defineSlots<{ [K in OperationSlot | OperationNestedSlot]?: (props:
24
25
  const themeConfig = useTheme()
25
26
  const { t } = useI18n()
26
27
 
27
- const lazyRendering = themeConfig.getSpecConfig()?.lazyRendering?.value
28
+ const lazyRendering = useLazyRendering()
28
29
 
29
30
  const showPathsSummary = computed(() =>
30
31
  props.hidePathsSummary === undefined
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import type { OperationNestedSlot, OperationSlot, PathsGroupView } from '../../types'
3
- import { useTheme } from '../../composables/useTheme'
3
+ import { useLazyRendering } from '../../lib/spec/lazyRendering'
4
4
  import OAPathsGroup from './OAPathsGroup.vue'
5
5
 
6
6
  const props = defineProps({
@@ -16,8 +16,7 @@ const props = defineProps({
16
16
 
17
17
  const slots = defineSlots<{ [K in OperationSlot | OperationNestedSlot]?: (props: any) => any }>()
18
18
 
19
- const themeConfig = useTheme()
20
- const lazyRendering = themeConfig.getSpecConfig()?.lazyRendering?.value
19
+ const lazyRendering = useLazyRendering()
21
20
  </script>
22
21
 
23
22
  <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
- export interface OASidebarItem extends DefaultTheme.SidebarItem {
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
- } = {}): DefaultTheme.SidebarItem[] {
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 DefaultTheme.SidebarItem[]
323
+ return cleanSidebarItems(sidebarItems) as SidebarItem[]
310
324
  }
311
325
 
312
326
  return {
@@ -0,0 +1,4 @@
1
+ import type { InjectionKey } from 'vue'
2
+
3
+ /** Provided by the VOpenapi plugin: wrap the entry components in a `.vp-doc` element. */
4
+ export const DOC_ROOT_KEY: InjectionKey<boolean> = Symbol('oa-doc-root')
@@ -1,9 +1,8 @@
1
- import type { DefaultTheme } from 'vitepress'
2
- import type { OASidebarItem } from '../../composables/useSidebar'
1
+ import type { OASidebarItem, SidebarItem } from '../../composables/useSidebar'
3
2
 
4
- export function cleanSidebarItems(result: (OASidebarItem[] | OASidebarItem)): DefaultTheme.SidebarItem[] | DefaultTheme.SidebarItem {
3
+ export function cleanSidebarItems(result: (OASidebarItem[] | OASidebarItem)): SidebarItem[] | SidebarItem {
5
4
  if (Array.isArray(result)) {
6
- return result.map(cleanSidebarItems) as DefaultTheme.SidebarItem[]
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 DefaultTheme.SidebarItem
14
+ } as SidebarItem
16
15
  }
17
16
 
18
17
  return result
@@ -0,0 +1,12 @@
1
+ import type { InjectionKey } from 'vue'
2
+ import { inject } from 'vue'
3
+ import { useTheme } from '../../composables/useTheme'
4
+
5
+ /** Provided by OASpec when it receives `lazy-rendering`, so it applies per instance, also during SSR. */
6
+ export const LAZY_RENDERING_KEY: InjectionKey<boolean | undefined> = Symbol('oa-lazy-rendering')
7
+
8
+ /** `lazy-rendering` of the closest OASpec, or `spec.lazyRendering` of the theme config. */
9
+ export function useLazyRendering(): boolean {
10
+ const fromSpec = inject(LAZY_RENDERING_KEY, undefined)
11
+ return fromSpec ?? useTheme().getSpecConfig()?.lazyRendering?.value ?? false
12
+ }
@@ -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
+ }