boltdocs 2.5.5 → 2.6.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.
Files changed (166) hide show
  1. package/bin/boltdocs.js +2 -2
  2. package/dist/client/index.cjs +6 -0
  3. package/dist/client/index.d.cts +1560 -0
  4. package/dist/client/index.d.ts +1219 -922
  5. package/dist/client/index.js +6 -1
  6. package/dist/client/theme/neutral.css +428 -0
  7. package/dist/node/cli-entry.cjs +8 -0
  8. package/dist/node/cli-entry.d.cts +2 -0
  9. package/dist/node/cli-entry.d.mts +2 -1
  10. package/dist/node/cli-entry.mjs +7 -5
  11. package/dist/node/index.cjs +6 -0
  12. package/dist/node/index.d.cts +519 -0
  13. package/dist/node/index.d.mts +374 -422
  14. package/dist/node/index.mjs +6 -1
  15. package/dist/node-BgvNl2Ay.mjs +89 -0
  16. package/dist/node-vkbb0MK7.cjs +89 -0
  17. package/dist/package-CR0HF9x3.mjs +6 -0
  18. package/dist/package-Dgmsc_l5.cjs +6 -0
  19. package/dist/search-dialog-3lvKsbVG.js +6 -0
  20. package/dist/search-dialog-DMK5OpgH.cjs +6 -0
  21. package/dist/use-search-C9bxCqfF.js +6 -0
  22. package/dist/use-search-DcfZSunO.cjs +6 -0
  23. package/package.json +26 -25
  24. package/src/client/app/config-context.tsx +38 -5
  25. package/src/client/app/doc-page.tsx +34 -0
  26. package/src/client/app/mdx-component.tsx +2 -3
  27. package/src/client/app/mdx-components-context.tsx +27 -2
  28. package/src/client/app/routes-context.tsx +34 -0
  29. package/src/client/app/scroll-handler.tsx +7 -4
  30. package/src/client/app/theme-context.tsx +71 -67
  31. package/src/client/components/default-layout.tsx +34 -33
  32. package/src/client/components/docs-layout.tsx +1 -2
  33. package/src/client/components/icons-dev.tsx +36 -5
  34. package/src/client/components/mdx/admonition.tsx +11 -27
  35. package/src/client/components/mdx/badge.tsx +1 -1
  36. package/src/client/components/mdx/button.tsx +3 -3
  37. package/src/client/components/mdx/card.tsx +1 -1
  38. package/src/client/components/mdx/code-block.tsx +90 -80
  39. package/src/client/components/mdx/component-preview.tsx +1 -5
  40. package/src/client/components/mdx/component-props.tsx +1 -1
  41. package/src/client/components/mdx/field.tsx +4 -5
  42. package/src/client/components/mdx/file-tree.tsx +6 -3
  43. package/src/client/components/mdx/hooks/use-code-block.ts +2 -2
  44. package/src/client/components/mdx/image.tsx +1 -1
  45. package/src/client/components/mdx/link.tsx +2 -2
  46. package/src/client/components/mdx/list.tsx +1 -1
  47. package/src/client/components/mdx/table.tsx +1 -1
  48. package/src/client/components/mdx/tabs.tsx +1 -1
  49. package/src/client/components/primitives/breadcrumbs.tsx +1 -7
  50. package/src/client/components/primitives/button-group.tsx +1 -1
  51. package/src/client/components/primitives/button.tsx +1 -1
  52. package/src/client/components/primitives/code-block.tsx +113 -0
  53. package/src/client/components/primitives/link.tsx +23 -41
  54. package/src/client/components/primitives/menu.tsx +5 -6
  55. package/src/client/components/primitives/navbar.tsx +6 -18
  56. package/src/client/components/primitives/navigation-menu.tsx +4 -4
  57. package/src/client/components/primitives/on-this-page.tsx +6 -10
  58. package/src/client/components/primitives/page-nav.tsx +4 -9
  59. package/src/client/components/primitives/popover.tsx +1 -1
  60. package/src/client/components/primitives/search-dialog.tsx +3 -6
  61. package/src/client/components/primitives/sidebar.tsx +80 -22
  62. package/src/client/components/primitives/skeleton.tsx +1 -1
  63. package/src/client/components/primitives/tabs.tsx +4 -11
  64. package/src/client/components/primitives/tooltip.tsx +3 -3
  65. package/src/client/components/ui-base/breadcrumbs.tsx +4 -6
  66. package/src/client/components/ui-base/copy-markdown.tsx +2 -7
  67. package/src/client/components/ui-base/github-stars.tsx +2 -2
  68. package/src/client/components/ui-base/head.tsx +58 -51
  69. package/src/client/components/ui-base/loading.tsx +2 -2
  70. package/src/client/components/ui-base/navbar.tsx +12 -14
  71. package/src/client/components/ui-base/not-found.tsx +1 -1
  72. package/src/client/components/ui-base/on-this-page.tsx +6 -6
  73. package/src/client/components/ui-base/page-nav.tsx +4 -8
  74. package/src/client/components/ui-base/search-dialog.tsx +10 -8
  75. package/src/client/components/ui-base/sidebar.tsx +76 -23
  76. package/src/client/components/ui-base/tabs.tsx +9 -8
  77. package/src/client/components/ui-base/theme-toggle.tsx +2 -2
  78. package/src/client/hooks/use-i18n.ts +3 -3
  79. package/src/client/hooks/use-localized-to.ts +1 -1
  80. package/src/client/hooks/use-navbar.ts +8 -6
  81. package/src/client/hooks/use-routes.ts +19 -11
  82. package/src/client/hooks/use-search.ts +1 -1
  83. package/src/client/hooks/use-sidebar.ts +48 -2
  84. package/src/client/hooks/use-tabs.ts +6 -2
  85. package/src/client/hooks/use-version.ts +3 -3
  86. package/src/client/index.ts +22 -22
  87. package/src/client/ssg/boltdocs-shell.tsx +127 -0
  88. package/src/client/ssg/create-routes.tsx +179 -0
  89. package/src/client/ssg/index.ts +3 -0
  90. package/src/client/ssg/mdx-page.tsx +37 -0
  91. package/src/client/store/boltdocs-context.tsx +66 -0
  92. package/src/client/theme/neutral.css +90 -50
  93. package/src/client/types.ts +5 -33
  94. package/src/client/utils/react-to-text.ts +34 -0
  95. package/CHANGELOG.md +0 -98
  96. package/dist/cache-3FOEPC2P.mjs +0 -1
  97. package/dist/chunk-5B5NKOW6.mjs +0 -77
  98. package/dist/chunk-J2PTDWZM.mjs +0 -1
  99. package/dist/chunk-TP5KMRD3.mjs +0 -1
  100. package/dist/chunk-Y4RE5KI7.mjs +0 -1
  101. package/dist/client/index.d.mts +0 -1263
  102. package/dist/client/index.mjs +0 -1
  103. package/dist/client/ssr.d.mts +0 -78
  104. package/dist/client/ssr.d.ts +0 -78
  105. package/dist/client/ssr.js +0 -1
  106. package/dist/client/ssr.mjs +0 -1
  107. package/dist/node/cli-entry.d.ts +0 -1
  108. package/dist/node/cli-entry.js +0 -82
  109. package/dist/node/index.d.ts +0 -567
  110. package/dist/node/index.js +0 -77
  111. package/dist/package-QFIAETHR.mjs +0 -1
  112. package/dist/search-dialog-O6VLVSOA.mjs +0 -1
  113. package/src/client/app/index.tsx +0 -345
  114. package/src/client/app/mdx-page.tsx +0 -15
  115. package/src/client/app/preload.tsx +0 -66
  116. package/src/client/app/router.tsx +0 -30
  117. package/src/client/integrations/codesandbox.ts +0 -179
  118. package/src/client/integrations/index.ts +0 -1
  119. package/src/client/ssr.tsx +0 -65
  120. package/src/client/store/use-boltdocs-store.ts +0 -44
  121. package/src/node/cache.ts +0 -408
  122. package/src/node/cli/build.ts +0 -53
  123. package/src/node/cli/dev.ts +0 -22
  124. package/src/node/cli/doctor.ts +0 -243
  125. package/src/node/cli/index.ts +0 -9
  126. package/src/node/cli/ui.ts +0 -54
  127. package/src/node/cli-entry.ts +0 -24
  128. package/src/node/config.ts +0 -382
  129. package/src/node/errors.ts +0 -44
  130. package/src/node/index.ts +0 -84
  131. package/src/node/mdx/cache.ts +0 -12
  132. package/src/node/mdx/highlighter.ts +0 -47
  133. package/src/node/mdx/index.ts +0 -122
  134. package/src/node/mdx/rehype-shiki.ts +0 -62
  135. package/src/node/mdx/remark-code-meta.ts +0 -35
  136. package/src/node/mdx/remark-shiki.ts +0 -61
  137. package/src/node/plugin/entry.ts +0 -87
  138. package/src/node/plugin/html.ts +0 -99
  139. package/src/node/plugin/index.ts +0 -478
  140. package/src/node/plugin/types.ts +0 -9
  141. package/src/node/plugins/index.ts +0 -17
  142. package/src/node/plugins/plugin-errors.ts +0 -62
  143. package/src/node/plugins/plugin-lifecycle.ts +0 -117
  144. package/src/node/plugins/plugin-sandbox.ts +0 -59
  145. package/src/node/plugins/plugin-store.ts +0 -54
  146. package/src/node/plugins/plugin-types.ts +0 -107
  147. package/src/node/plugins/plugin-validator.ts +0 -105
  148. package/src/node/routes/cache.ts +0 -28
  149. package/src/node/routes/index.ts +0 -293
  150. package/src/node/routes/parser.ts +0 -262
  151. package/src/node/routes/sorter.ts +0 -42
  152. package/src/node/routes/types.ts +0 -61
  153. package/src/node/schema/config.ts +0 -195
  154. package/src/node/schema/frontmatter.ts +0 -17
  155. package/src/node/search/index.ts +0 -55
  156. package/src/node/security/constants/index.ts +0 -10
  157. package/src/node/security/csp.ts +0 -31
  158. package/src/node/security/headers.ts +0 -27
  159. package/src/node/ssg/index.ts +0 -205
  160. package/src/node/ssg/meta.ts +0 -33
  161. package/src/node/ssg/options.ts +0 -15
  162. package/src/node/ssg/robots.ts +0 -53
  163. package/src/node/ssg/sitemap.ts +0 -55
  164. package/src/node/utils.ts +0 -349
  165. package/tsconfig.json +0 -26
  166. package/tsup.config.ts +0 -56
@@ -1,66 +0,0 @@
1
- import { createContext, use, useCallback, useRef } from 'react'
2
- import type { ComponentRoute } from '../types'
3
-
4
- interface PreloadContextType {
5
- preload: (path: string) => void
6
- routes: ComponentRoute[]
7
- }
8
-
9
- const PreloadContext = createContext<PreloadContextType>({
10
- preload: () => {},
11
- routes: [],
12
- })
13
-
14
- export function usePreload() {
15
- return use(PreloadContext)
16
- }
17
-
18
- export function PreloadProvider({
19
- routes,
20
- modules,
21
- children,
22
- }: {
23
- routes: ComponentRoute[]
24
- modules: Record<string, () => Promise<unknown>>
25
- children: React.ReactNode
26
- }) {
27
- const preloadTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
28
-
29
- const preload = useCallback(
30
- (path: string) => {
31
- if (preloadTimerRef.current) {
32
- clearTimeout(preloadTimerRef.current)
33
- }
34
-
35
- preloadTimerRef.current = setTimeout(() => {
36
- // Normalize path (remove hash and search)
37
- const cleanPath = path.split('#')[0].split('?')[0]
38
-
39
- // Support index routes matching "/"
40
- const route = routes.find(
41
- (r) => r.path === cleanPath || (cleanPath === '/' && r.path === ''),
42
- )
43
-
44
- if (route?.filePath) {
45
- const loaderKey = Object.keys(modules).find((k) =>
46
- k.endsWith('/' + route.filePath),
47
- )
48
-
49
- if (loaderKey) {
50
- // Trigger the dynamic import
51
- modules[loaderKey]().catch((err: unknown) => {
52
- console.error(`[boltdocs] Failed to preload route ${path}:`, err)
53
- })
54
- }
55
- }
56
- }, 100) // 100ms debounce
57
- },
58
- [routes, modules],
59
- )
60
-
61
- return (
62
- <PreloadContext.Provider value={{ preload, routes }}>
63
- {children}
64
- </PreloadContext.Provider>
65
- )
66
- }
@@ -1,30 +0,0 @@
1
- import type React from 'react'
2
- import { startTransition } from 'react'
3
- import { RouterProvider } from 'react-aria-components'
4
- import { useNavigate, useHref } from 'react-router-dom'
5
-
6
- /**
7
- * Connects React Aria Components (RAC) to React Router.
8
- * This ensures all RAC links and buttons use client-side navigation
9
- * instead of full page reloads.
10
- */
11
- export function BoltdocsRouterProvider({
12
- children,
13
- }: {
14
- children: React.ReactNode
15
- }) {
16
- const navigate = useNavigate()
17
-
18
- return (
19
- <RouterProvider
20
- navigate={(to, options) => {
21
- startTransition(() => {
22
- navigate(to, options)
23
- })
24
- }}
25
- useHref={useHref}
26
- >
27
- {children as any}
28
- </RouterProvider>
29
- )
30
- }
@@ -1,179 +0,0 @@
1
- import { getParameters } from 'codesandbox/lib/api/define.js'
2
- import { SandboxOptions } from '../types'
3
-
4
- /**
5
- * Build the files payload for the CodeSandbox Define API.
6
- * Ensures every file conforms to the `{ content, isBinary }` shape
7
- * required by the SDK, and auto-generates a `package.json` when one
8
- * isn't explicitly provided.
9
- */
10
- function buildSandboxFiles(options: SandboxOptions) {
11
- const files = options.files || {}
12
- const dependencies = options.dependencies || {}
13
- const devDependencies = options.devDependencies || {}
14
- const title = options.title || 'codesandbox-project'
15
- const description = options.description || 'Generic Sandbox'
16
-
17
- const finalFiles: Record<string, { content: string; isBinary: boolean }> = {}
18
-
19
- for (const [path, file] of Object.entries(files)) {
20
- const content =
21
- typeof file.content === 'object'
22
- ? JSON.stringify(file.content, null, 2)
23
- : file.content
24
- finalFiles[path] = { content, isBinary: file.isBinary ?? false }
25
- }
26
-
27
- if (!finalFiles['package.json']) {
28
- const isVite =
29
- options.template === 'vite' ||
30
- !!devDependencies.vite ||
31
- !!devDependencies['@vitejs/plugin-react']
32
-
33
- const defaultScripts = isVite
34
- ? {
35
- dev: 'vite',
36
- build: 'vite build',
37
- preview: 'vite preview',
38
- }
39
- : {
40
- start: 'node index.js',
41
- }
42
-
43
- finalFiles['package.json'] = {
44
- content: JSON.stringify(
45
- {
46
- private: true,
47
- name: title,
48
- description,
49
- type: 'module',
50
- version: '1.0.0',
51
- scripts: options.scripts || defaultScripts,
52
- dependencies,
53
- devDependencies,
54
- },
55
- null,
56
- 2,
57
- ),
58
- isBinary: false,
59
- }
60
- }
61
-
62
- return finalFiles
63
- }
64
-
65
- /**
66
- * Helper to define a sandbox and get a URL for the CodeSandbox Define API.
67
- * Uses the official SDK `getParameters` for proper LZ-string compression.
68
- */
69
- export function defineSandbox(options: SandboxOptions) {
70
- const finalFiles = buildSandboxFiles(options)
71
- const parameters = getParameters({ files: finalFiles })
72
-
73
- // FIX: Agregar query params que forzan comportamiento correcto
74
- const query = new URLSearchParams({
75
- parameters,
76
- // FIX: Forzar instalación de dependencias
77
- installDependencies: 'true',
78
- })
79
-
80
- // FIX: Agregar file query para que abra el entry correcto
81
- if (options.entry) {
82
- query.set('file', `/${options.entry}`)
83
- }
84
-
85
- return {
86
- parameters,
87
- url: `https://codesandbox.io/api/v1/sandboxes/define?${query.toString()}`,
88
- options,
89
- }
90
- }
91
-
92
- /**
93
- * CORE API: Open a CodeSandbox using a form POST to the Define API.
94
- *
95
- * Uses a hidden form + POST which avoids URL length limits and is the
96
- * recommended approach from CodeSandbox documentation. The SDK's
97
- * `getParameters` handles LZ-string compression internally.
98
- */
99
- export function openSandbox(options: SandboxOptions) {
100
- if (typeof window === 'undefined') return defineSandbox(options)
101
-
102
- const finalFiles = buildSandboxFiles(options)
103
- const parameters = getParameters({ files: finalFiles })
104
- const entry = options.entry || 'src/App.tsx'
105
-
106
- // Use form POST – the most reliable method for the Define API
107
- const form = document.createElement('form')
108
- form.method = 'POST'
109
- form.target = '_blank'
110
- form.action = 'https://codesandbox.io/api/v1/sandboxes/define'
111
- form.style.display = 'none'
112
-
113
- const addField = (name: string, value: string) => {
114
- const input = document.createElement('input')
115
- input.type = 'hidden'
116
- input.name = name
117
- input.value = value
118
- form.appendChild(input)
119
- }
120
-
121
- const queryParams = new URLSearchParams({
122
- file: `/${entry}`,
123
- // FIX: Forzar vista de preview (no solo editor)
124
- // FIX: Deshabilitar eslint que a veces bloquea
125
- eslint: '0',
126
- // FIX: Habilitar codemirror
127
- codemirror: '1',
128
- // FIX: Forzar instalación de deps
129
- installDependencies: 'true',
130
- })
131
-
132
- addField('query', queryParams.toString())
133
- addField('parameters', parameters)
134
-
135
- document.body.appendChild(form)
136
- form.submit()
137
- document.body.removeChild(form)
138
-
139
- return {
140
- parameters,
141
- url: `https://codesandbox.io/api/v1/sandboxes/define?parameters=${parameters}`,
142
- options,
143
- }
144
- }
145
-
146
- /**
147
- * Generate an embeddable iframe URL for a CodeSandbox.
148
- *
149
- * This gives you more control than `openSandbox` — you can embed the sandbox
150
- * inline on the page rather than opening a new tab. The returned URL can be
151
- * used as the `src` of an `<iframe>`.
152
- *
153
- * @example
154
- * ```tsx
155
- * const url = embedSandbox({
156
- * files: { "index.js": { content: "console.log('hello')" } },
157
- * embed: { view: "editor", theme: "dark" },
158
- * }).url;
159
- * // url → "https://codesandbox.io/api/v1/sandboxes/define?parameters=…&embed=1&view=editor&theme=dark"
160
- * ```
161
- */
162
- export function embedSandbox(options: SandboxOptions) {
163
- const finalFiles = buildSandboxFiles(options)
164
- const parameters = getParameters({ files: finalFiles })
165
- const embedOptions = options.embed || {}
166
-
167
- const query = new URLSearchParams({ parameters, embed: '1' })
168
-
169
- if (embedOptions.view) query.set('view', embedOptions.view)
170
- if (embedOptions.theme) query.set('theme', embedOptions.theme)
171
- if (embedOptions.hideNavigation) query.set('hidenavigation', '1')
172
- if (options.entry) query.set('file', `/${options.entry}`)
173
-
174
- return {
175
- parameters,
176
- url: `https://codesandbox.io/api/v1/sandboxes/define?${query.toString()}`,
177
- options,
178
- }
179
- }
@@ -1 +0,0 @@
1
- export * from './codesandbox'
@@ -1,65 +0,0 @@
1
- import React from 'react'
2
- import ReactDOMServer from 'react-dom/server'
3
- import { StaticRouter } from 'react-router-dom/server'
4
- import { AppShell } from './app'
5
- import type { ComponentRoute } from './types'
6
-
7
- /**
8
- * Options for rendering the Boltdocs application on the server (SSG).
9
- */
10
- export interface RenderOptions {
11
- /** The URL path currently being rendered */
12
- path: string
13
- /** Initial routes generated by the Vite plugin (`virtual:boltdocs-routes`) */
14
- routes: ComponentRoute[]
15
- /** Site configuration (`virtual:boltdocs-config`) */
16
- config: any
17
- /** The name of the documentation directory (e.g. 'docs') */
18
- docsDirName: string
19
- /** Optional custom React component to render when visiting the root path ('/') */
20
- homePage?: React.ComponentType
21
- /** Custom external pages mapped by their route path */
22
- externalPages?: Record<string, React.ComponentType<any>>
23
- /** Preloaded modules (since SSR cannot use dynamic imports easily) */
24
- modules: Record<string, any>
25
- }
26
-
27
- /**
28
- * Renders the full React application into an HTML string for a specific route.
29
- * This is called by the Node SSG script during the Vite build process.
30
- */
31
- export async function render(options: RenderOptions): Promise<string> {
32
- const {
33
- path,
34
- routes,
35
- config,
36
- modules,
37
- homePage,
38
- externalPages,
39
- docsDirName,
40
- } = options
41
-
42
- // For SSR, we must resolve modules synchronously. We create a mock 'loader'
43
- // that instantly returns the module since the SSG script already loaded it.
44
- const resolvedModules: Record<string, () => Promise<any>> = {}
45
- for (const [key, mod] of Object.entries(modules)) {
46
- resolvedModules[key] = () => Promise.resolve(mod)
47
- }
48
-
49
- const html = ReactDOMServer.renderToString(
50
- <React.StrictMode>
51
- <StaticRouter location={path}>
52
- <AppShell
53
- initialRoutes={routes}
54
- initialConfig={config}
55
- docsDirName={docsDirName}
56
- modules={resolvedModules}
57
- homePage={homePage}
58
- externalPages={externalPages}
59
- />
60
- </StaticRouter>
61
- </React.StrictMode>,
62
- )
63
-
64
- return html
65
- }
@@ -1,44 +0,0 @@
1
- import { create } from 'zustand'
2
- import { persist, createJSONStorage } from 'zustand/middleware'
3
-
4
- interface BoltdocsState {
5
- currentLocale: string | undefined
6
- currentVersion: string | undefined
7
- hasHydrated: boolean
8
-
9
- // Actions
10
- setLocale: (locale: string | undefined) => void
11
- setVersion: (version: string | undefined) => void
12
- setHasHydrated: (val: boolean) => void
13
- }
14
-
15
- /**
16
- * Global store for Boltdocs documentation state.
17
- * Uses localStorage persistence to remember user preferences across sessions.
18
- */
19
- export const useBoltdocsStore = create<BoltdocsState>()(
20
- persist(
21
- (set) => ({
22
- currentLocale: undefined,
23
- currentVersion: undefined,
24
- hasHydrated: false,
25
-
26
- setLocale: (locale: string | undefined) => set({ currentLocale: locale }),
27
- setVersion: (version: string | undefined) =>
28
- set({ currentVersion: version }),
29
- setHasHydrated: (val: boolean) => set({ hasHydrated: val }),
30
- }),
31
- {
32
- name: 'boltdocs-storage',
33
- storage: createJSONStorage(() => localStorage),
34
- // Only persist identifying state
35
- partialize: (state: BoltdocsState) => ({
36
- currentLocale: state.currentLocale,
37
- currentVersion: state.currentVersion,
38
- }),
39
- onRehydrateStorage: () => (state?: BoltdocsState) => {
40
- state?.setHasHydrated(true)
41
- },
42
- },
43
- ),
44
- )