vitepress-openapi 0.2.14 → 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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitepress-openapi",
3
3
  "type": "module",
4
- "version": "0.2.14",
4
+ "version": "0.2.15",
5
5
  "engines": {
6
6
  "node": "^20.19.0 || ^22.13.0 || >=24.0.0"
7
7
  },
@@ -43,7 +43,7 @@
43
43
  ],
44
44
  "peerDependencies": {
45
45
  "vitepress": ">=1.0.0",
46
- "vue": "^3.0.0"
46
+ "vue": "^3.5.0"
47
47
  },
48
48
  "peerDependenciesMeta": {
49
49
  "vitepress": {
@@ -1,5 +1,7 @@
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'
3
5
  import OADocRoot from '../Common/OADocRoot.vue'
4
6
  import OAProvider from '../Context/OAProvider.vue'
5
7
  import OASpecContent from './OASpecContent.vue'
@@ -56,6 +58,14 @@ const props = defineProps({
56
58
  type: Boolean,
57
59
  default: undefined,
58
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
+ },
59
69
  })
60
70
 
61
71
  const emits = defineEmits([
@@ -65,6 +75,8 @@ const emits = defineEmits([
65
75
  const slots = defineSlots<{ [K in OperationSlot]?: (props: any) => any } & {
66
76
  'response-description'?: (props: ResponseDescriptionSlotProps) => any
67
77
  }>()
78
+
79
+ provide(LAZY_RENDERING_KEY, props.lazyRendering)
68
80
  </script>
69
81
 
70
82
  <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>
@@ -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
+ }