boltdocs 2.5.6 → 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.
- package/bin/boltdocs.js +2 -2
- package/dist/client/index.cjs +6 -0
- package/dist/client/{index.d.mts → index.d.cts} +134 -252
- package/dist/client/index.d.ts +135 -253
- package/dist/client/index.js +1 -1
- package/dist/client/theme/neutral.css +90 -50
- package/dist/node/cli-entry.cjs +2 -2
- package/dist/node/cli-entry.mjs +2 -2
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.d.cts +150 -205
- package/dist/node/index.d.mts +150 -205
- package/dist/node/index.mjs +1 -1
- package/dist/node-BgvNl2Ay.mjs +89 -0
- package/dist/node-vkbb0MK7.cjs +89 -0
- package/dist/{package-OFZf0s2j.mjs → package-CR0HF9x3.mjs} +1 -1
- package/dist/{package-BY8Jd2j4.cjs → package-Dgmsc_l5.cjs} +1 -1
- package/dist/search-dialog-3lvKsbVG.js +6 -0
- package/dist/search-dialog-DMK5OpgH.cjs +6 -0
- package/dist/use-search-C9bxCqfF.js +6 -0
- package/dist/use-search-DcfZSunO.cjs +6 -0
- package/package.json +19 -22
- package/src/client/app/config-context.tsx +38 -5
- package/src/client/app/doc-page.tsx +34 -0
- package/src/client/app/mdx-component.tsx +2 -3
- package/src/client/app/mdx-components-context.tsx +27 -2
- package/src/client/app/routes-context.tsx +34 -0
- package/src/client/app/scroll-handler.tsx +7 -4
- package/src/client/app/theme-context.tsx +71 -67
- package/src/client/components/default-layout.tsx +13 -14
- package/src/client/components/docs-layout.tsx +1 -2
- package/src/client/components/icons-dev.tsx +36 -5
- package/src/client/components/mdx/admonition.tsx +11 -27
- package/src/client/components/mdx/badge.tsx +1 -1
- package/src/client/components/mdx/button.tsx +3 -3
- package/src/client/components/mdx/card.tsx +1 -1
- package/src/client/components/mdx/code-block.tsx +90 -80
- package/src/client/components/mdx/component-preview.tsx +1 -5
- package/src/client/components/mdx/component-props.tsx +1 -1
- package/src/client/components/mdx/field.tsx +4 -5
- package/src/client/components/mdx/file-tree.tsx +6 -3
- package/src/client/components/mdx/hooks/use-code-block.ts +2 -2
- package/src/client/components/mdx/image.tsx +1 -1
- package/src/client/components/mdx/link.tsx +2 -2
- package/src/client/components/mdx/list.tsx +1 -1
- package/src/client/components/mdx/table.tsx +1 -1
- package/src/client/components/mdx/tabs.tsx +1 -1
- package/src/client/components/primitives/breadcrumbs.tsx +1 -7
- package/src/client/components/primitives/button-group.tsx +1 -1
- package/src/client/components/primitives/button.tsx +1 -1
- package/src/client/components/primitives/code-block.tsx +113 -0
- package/src/client/components/primitives/link.tsx +23 -41
- package/src/client/components/primitives/menu.tsx +5 -6
- package/src/client/components/primitives/navbar.tsx +6 -18
- package/src/client/components/primitives/navigation-menu.tsx +4 -4
- package/src/client/components/primitives/on-this-page.tsx +6 -10
- package/src/client/components/primitives/page-nav.tsx +4 -9
- package/src/client/components/primitives/popover.tsx +1 -1
- package/src/client/components/primitives/search-dialog.tsx +3 -6
- package/src/client/components/primitives/sidebar.tsx +80 -22
- package/src/client/components/primitives/skeleton.tsx +1 -1
- package/src/client/components/primitives/tabs.tsx +4 -11
- package/src/client/components/primitives/tooltip.tsx +3 -3
- package/src/client/components/ui-base/breadcrumbs.tsx +4 -6
- package/src/client/components/ui-base/copy-markdown.tsx +2 -7
- package/src/client/components/ui-base/github-stars.tsx +2 -2
- package/src/client/components/ui-base/head.tsx +58 -51
- package/src/client/components/ui-base/loading.tsx +2 -2
- package/src/client/components/ui-base/navbar.tsx +12 -14
- package/src/client/components/ui-base/not-found.tsx +1 -1
- package/src/client/components/ui-base/on-this-page.tsx +6 -6
- package/src/client/components/ui-base/page-nav.tsx +4 -8
- package/src/client/components/ui-base/search-dialog.tsx +10 -8
- package/src/client/components/ui-base/sidebar.tsx +76 -23
- package/src/client/components/ui-base/tabs.tsx +9 -8
- package/src/client/components/ui-base/theme-toggle.tsx +2 -2
- package/src/client/hooks/use-i18n.ts +3 -3
- package/src/client/hooks/use-localized-to.ts +1 -1
- package/src/client/hooks/use-navbar.ts +8 -6
- package/src/client/hooks/use-routes.ts +19 -11
- package/src/client/hooks/use-search.ts +1 -1
- package/src/client/hooks/use-sidebar.ts +48 -2
- package/src/client/hooks/use-tabs.ts +6 -2
- package/src/client/hooks/use-version.ts +3 -3
- package/src/client/index.ts +22 -22
- package/src/client/ssg/boltdocs-shell.tsx +127 -0
- package/src/client/ssg/create-routes.tsx +179 -0
- package/src/client/ssg/index.ts +3 -0
- package/src/client/ssg/mdx-page.tsx +37 -0
- package/src/client/store/boltdocs-context.tsx +46 -99
- package/src/client/theme/neutral.css +90 -50
- package/src/client/types.ts +5 -33
- package/src/client/utils/react-to-text.ts +34 -0
- package/dist/cache-Cr8W2zgZ.cjs +0 -6
- package/dist/cache-DFdakSmR.mjs +0 -6
- package/dist/client/index.mjs +0 -6
- package/dist/client/ssr.cjs +0 -6
- package/dist/client/ssr.d.cts +0 -80
- package/dist/client/ssr.d.mts +0 -80
- package/dist/client/ssr.mjs +0 -6
- package/dist/node-CWXme96p.mjs +0 -73
- package/dist/node-VYfhzGrh.cjs +0 -73
- package/dist/search-dialog-BeNyI_KQ.mjs +0 -6
- package/dist/search-dialog-dYsCAk5S.js +0 -6
- package/dist/use-search-D25n0PrV.mjs +0 -6
- package/dist/use-search-WuzdH1cJ.js +0 -6
- package/src/client/app/index.tsx +0 -348
- package/src/client/app/mdx-page.tsx +0 -15
- package/src/client/app/preload.tsx +0 -66
- package/src/client/app/router.tsx +0 -30
- package/src/client/integrations/codesandbox.ts +0 -179
- package/src/client/integrations/index.ts +0 -1
- package/src/client/ssr.tsx +0 -65
|
@@ -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'
|
package/src/client/ssr.tsx
DELETED
|
@@ -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
|
-
}
|