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,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Boltdocs - https://boltdocs.vercel.app
|
|
3
|
-
* Copyright (c) 2026 Jesus Alcala
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let l=require(`react`);l=c(l);let u=require(`react-router-dom`),d=require(`lucide-react`),f=require(`react-aria-components`);f=c(f);let p=require(`react/jsx-runtime`),m=require(`clsx`),ee=require(`tailwind-merge`),h=require(`flexsearch`),g=require(`virtual:boltdocs-search`);g=c(g);const _=(0,l.createContext)(null);function v(){let e=(0,l.use)(_);if(!e)throw Error(`useConfig must be used within a ConfigProvider`);return e}const y=(0,l.createContext)({preload:()=>{},routes:[]});function b(){return(0,l.use)(y)}function x({routes:e,modules:t,children:n}){let r=(0,l.useRef)(null),i=(0,l.useCallback)(n=>{r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{let r=n.split(`#`)[0].split(`?`)[0],i=e.find(e=>e.path===r||r===`/`&&e.path===``);if(i?.filePath){let e=Object.keys(t).find(e=>e.endsWith(`/`+i.filePath));e&&t[e]().catch(e=>{console.error(`[boltdocs] Failed to preload route ${n}:`,e)})}},100)},[e,t]);return(0,p.jsx)(y.Provider,{value:{preload:i,routes:e},children:n})}const S=(0,l.createContext)(void 0),C=`boltdocs-storage`;function te(){try{let e=localStorage.getItem(C);if(e){let t=JSON.parse(e);return t?.state||t}}catch{}return{}}function w({children:e}){let t=te(),[n,r]=(0,l.useState)(t.currentLocale),[i,a]=(0,l.useState)(t.currentVersion),[o,s]=(0,l.useState)(!1);(0,l.useEffect)(()=>{s(!0)},[]),(0,l.useEffect)(()=>{if(o){let e={currentLocale:n,currentVersion:i};try{localStorage.setItem(C,JSON.stringify({state:e}))}catch{}}},[n,i,o]);let c={currentLocale:n,currentVersion:i,hasHydrated:o,setLocale:(0,l.useCallback)(e=>{r(e)},[]),setVersion:(0,l.useCallback)(e=>{a(e)},[]),setHasHydrated:(0,l.useCallback)(e=>{s(e)},[])};return(0,p.jsx)(S.Provider,{value:c,children:e})}function T(){let e=(0,l.useContext)(S);if(!e)throw Error(`useBoltdocsContext must be used within a BoltdocsProvider`);return e}function E(e){return e(T())}function D(){let{routes:e}=b(),t=v(),n=(0,u.useLocation)(),r=E(e=>e.currentLocale),i=E(e=>e.currentVersion),a=E(e=>e.hasHydrated),o=e.find(e=>e.path===n.pathname),s=t.i18n?o?.locale||(a?r:void 0)||t.i18n.defaultLocale:void 0,c=t.versions?o?.version||(a?i:void 0)||t.versions.defaultVersion:void 0,l=e.filter(n=>{let r=t.i18n?(n.locale||t.i18n.defaultLocale)===s:!0,i=t.versions?(n.version||t.versions.defaultVersion)===c:!0;if(!(r&&i))return!1;let a=t.i18n;if(a){let t=!!o?.locale,r=!!n.locale;if(e.some(e=>e!==n&&e.filePath===n.filePath&&e.version===n.version&&(e.locale||a.defaultLocale)===(n.locale||a.defaultLocale))&&t!==r)return!1}return!0}),d=t.i18n?.localeConfigs?.[s]?.label||t.i18n?.locales[s]||s,f=t.versions?.versions.find(e=>e.path===c)?.label||c;return{routes:l,allRoutes:e,currentRoute:o,currentLocale:s,currentLocaleLabel:d,availableLocales:t.i18n?Object.entries(t.i18n.locales).map(([e,n])=>({key:e,label:t.i18n?.localeConfigs?.[e]?.label||n,isCurrent:e===s})):[],currentVersion:c,currentVersionLabel:f,availableVersions:t.versions?t.versions.versions.map(e=>({key:e.path,label:e.label,isCurrent:e.path===c})):[],config:t}}function O(e){let t=v(),{currentLocale:n,currentVersion:r}=D();if(!t||typeof e!=`string`||e.startsWith(`http`)||e.startsWith(`//`))return e;let i=t.i18n,a=t.versions;if(!i&&!a)return e;let o=e.startsWith(`/docs`),s=e.split(`/`).filter(Boolean),c=0;s[c]===`docs`&&c++,a&&s.length>c&&a.versions.find(e=>e.path===s[c])&&c++,i&&s.length>c&&i.locales[s[c]]&&c++;let l=s.slice(c),u=[];o&&(u.push(`docs`),a&&r&&u.push(r)),i&&n&&n!==i.defaultLocale&&u.push(n),u.push(...l);let d=`/${u.join(`/`)}`;return d.length>1&&d.endsWith(`/`)?d.slice(0,-1):d||`/`}function k(...e){return(0,ee.twMerge)((0,m.clsx)(e))}const A=l.default.forwardRef((e,t)=>{let{href:n,prefetch:r=`hover`,onMouseEnter:i,onFocus:a,...o}=e,s=O(n??``),{preload:c}=b(),l=e=>{i?.(e),r===`hover`&&typeof s==`string`&&s.startsWith(`/`)&&c(s)},u=e=>{a?.(e),r===`hover`&&typeof s==`string`&&s.startsWith(`/`)&&c(s)};return(0,p.jsx)(f.Link,{...o,ref:t,href:s,onMouseEnter:l,onFocus:u})});A.displayName=`Link`;const j=l.default.forwardRef((e,t)=>{let{href:n,end:r=!1,className:i,children:a,...o}=e,s=(0,u.useLocation)(),c=O(n??``),l=r?s.pathname===c:s.pathname.startsWith(c),d=typeof i==`function`?i({isActive:l}):k(i,l&&`active`),f=typeof a==`function`?a({isActive:l}):a;return(0,p.jsx)(A,{...o,ref:t,href:n,className:d,children:f})});j.displayName=`NavLink`;function M(e){let{size:t=20,...n}=e;return{...n,width:t,height:t}}const N=e=>(0,p.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`currentColor`,...M(e),children:[(0,p.jsx)(`title`,{children:`GitHub`}),(0,p.jsx)(`path`,{d:`M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12`})]}),P=e=>(0,p.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`currentColor`,...M(e),children:[(0,p.jsx)(`title`,{children:`Discord`}),(0,p.jsx)(`path`,{d:`M20.317 4.37a19.791 19.791 0 0 0-4.885-1.515.074.074 0 0 0-.079.037c-.21.375-.444.864-.608 1.25a18.27 18.27 0 0 0-5.487 0 12.64 12.64 0 0 0-.617-1.25.077.077 0 0 0-.079-.037A19.736 19.736 0 0 0 3.677 4.37a.07.07 0 0 0-.032.027C.533 9.046-.32 13.58.099 18.057a.082.082 0 0 0 .031.057 19.9 19.9 0 0 0 5.993 3.03.078.078 0 0 0 .084-.028c.462-.63.874-1.295 1.226-1.994a.076.076 0 0 0-.041-.106 13.107 13.107 0 0 1-1.872-.892.077.077 0 0 1-.008-.128 10.2 10.2 0 0 0 .372-.292.074.074 0 0 1 .077-.01c3.928 1.793 8.18 1.793 12.062 0a.074.074 0 0 1 .078.01c.12.098.246.198.373.292a.077.077 0 0 1-.006.127 12.299 12.299 0 0 1-1.873.892.077.077 0 0 0-.041.107c.36.698.772 1.362 1.225 1.993a.076.076 0 0 0 .084.028 19.839 19.839 0 0 0 6.002-3.03.077.077 0 0 0 .032-.054c.5-5.177-.838-9.674-3.549-13.66a.061.061 0 0 0-.031-.03zM8.02 15.33c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.956-2.419 2.157-2.419 1.21 0 2.176 1.096 2.157 2.42 0 1.333-.956 2.418-2.157 2.418zm7.975 0c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.955-2.419 2.157-2.419 1.21 0 2.176 1.096 2.157 2.42 0 1.333-.946 2.418-2.157 2.418Z`})]}),F=e=>(0,p.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`currentColor`,...M(e),children:[(0,p.jsx)(`title`,{children:`X`}),(0,p.jsx)(`path`,{d:`M14.234 10.162 22.977 0h-2.072l-7.591 8.824L7.251 0H.258l9.168 13.343L.258 24H2.33l8.016-9.318L16.749 24h6.993zm-2.837 3.299-.929-1.329L3.076 1.56h3.182l5.965 8.532.929 1.329 7.754 11.09h-3.182z`})]}),I=e=>(0,p.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`currentColor`,...M(e),children:[(0,p.jsx)(`title`,{children:`Bluesky`}),(0,p.jsx)(`path`,{d:`M5.202 2.857C7.954 4.922 10.913 9.11 12 11.358c1.087-2.247 4.046-6.436 6.798-8.501C20.783 1.366 24 .213 24 3.883c0 .732-.42 6.156-.667 7.037-.856 3.061-3.978 3.842-6.755 3.37 4.854.826 6.089 3.562 3.422 6.299-5.065 5.196-7.28-1.304-7.847-2.97-.104-.305-.152-.448-.153-.327 0-.121-.05.022-.153.327-.568 1.666-2.782 8.166-7.847 2.97-2.667-2.737-1.432-5.473 3.422-6.3-2.777.473-5.899-.308-6.755-3.369C.42 10.04 0 4.615 0 3.883c0-3.67 3.217-2.517 5.202-1.026`})]}),L=e=>(0,p.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,...M(e),children:[(0,p.jsx)(`title`,{children:`TypeScript`}),(0,p.jsx)(`path`,{fill:`#2563EB`,d:`M3.234 9.093V7.318h8.363v1.775H8.479V17.5H6.352V9.093H3.234zm15.263 1.153c-.04-.4-.21-.712-.512-.934-.301-.222-.71-.333-1.228-.333-.351 0-.648.05-.89.149-.242.096-.427.23-.557.403a.969.969 0 0 0-.189.586.838.838 0 0 0 .115.477c.086.136.204.254.353.353.149.097.321.181.517.254.195.07.404.13.626.179l.915.219c.444.1.852.232 1.223.397.371.166.693.37.965.612.271.242.482.527.631.855.152.328.23.704.234 1.129-.004.623-.163 1.163-.478 1.62-.311.454-.762.807-1.352 1.06-.587.248-1.294.372-2.123.372-.822 0-1.538-.126-2.147-.378-.607-.252-1.081-.624-1.422-1.118-.338-.497-.516-1.112-.532-1.845h2.083c.023.342.12.627.293.855.176.226.41.397.701.513a2.8 2.8 0 0 0 1 .168c.364 0 .68-.053.949-.159a1.45 1.45 0 0 0 .631-.442c.15-.189.224-.406.224-.651a.846.846 0 0 0-.204-.577c-.132-.156-.328-.288-.586-.398a5.964 5.964 0 0 0-.94-.298l-1.109-.278c-.858-.21-1.536-.536-2.033-.98-.497-.444-.744-1.042-.74-1.795-.004-.616.16-1.155.491-1.615.335-.461.794-.82 1.377-1.08.584-.258 1.247-.387 1.99-.387.755 0 1.414.13 1.978.388.567.258 1.007.618 1.322 1.079.315.46.477.994.488 1.6h-2.064z`})]}),R=e=>(0,p.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,...M(e),children:[(0,p.jsx)(`title`,{children:`JavaScript`}),(0,p.jsx)(`path`,{fill:`#F59E0B`,d:`M8.383 7.318h2.127v7.1c0 .656-.147 1.226-.442 1.71a2.924 2.924 0 01-1.218 1.118c-.52.262-1.125.393-1.815.393-.613 0-1.17-.107-1.67-.323a2.67 2.67 0 01-1.183-.994c-.292-.448-.436-1.01-.433-1.686h2.143c.006.269.061.5.164.691.106.19.25.335.432.438.186.1.405.15.657.15.265 0 .488-.057.67-.17.186-.116.327-.285.423-.507.096-.222.145-.496.145-.82v-7.1zm9.43 2.928c-.04-.4-.21-.712-.511-.934-.302-.222-.711-.333-1.228-.333-.352 0-.648.05-.89.149-.242.096-.428.23-.557.403a.969.969 0 00-.19.586.838.838 0 00.115.477c.087.136.204.254.353.353.15.097.322.181.517.254.196.07.405.13.627.179l.915.219c.444.1.851.232 1.223.397.37.166.692.37.964.612s.482.527.631.855a2.7 2.7 0 01.234 1.129c-.003.623-.162 1.163-.477 1.62-.312.454-.763.807-1.353 1.06-.586.248-1.294.372-2.122.372-.822 0-1.538-.126-2.148-.378-.607-.252-1.08-.624-1.422-1.118-.338-.497-.515-1.112-.532-1.845h2.083c.023.342.121.627.293.855.176.226.41.397.702.513.295.112.628.168.999.168.364 0 .68-.053.95-.159.271-.106.482-.253.63-.442.15-.189.224-.406.224-.651a.846.846 0 00-.203-.577c-.133-.156-.329-.288-.587-.398a5.964 5.964 0 00-.94-.298l-1.108-.278c-.859-.21-1.537-.536-2.034-.98-.497-.444-.744-1.042-.74-1.795-.004-.616.16-1.155.492-1.615.334-.461.793-.82 1.377-1.08.583-.258 1.246-.387 1.989-.387.755 0 1.415.13 1.978.388.567.258 1.008.618 1.323 1.079.314.46.477.994.487 1.6h-2.063z`})]}),z=e=>(0,p.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,...M(e),children:[(0,p.jsx)(`title`,{children:`JSON`}),(0,p.jsx)(`path`,{fill:`#F59E0B`,d:`M4.778 6.667A2.667 2.667 0 017.444 4a.889.889 0 010 1.778.889.889 0 00-.888.889v3.5c0 .701-.273 1.35-.73 1.833.457.483.73 1.132.73 1.832v3.501c0 .491.398.89.888.89a.889.889 0 010 1.777 2.667 2.667 0 01-2.666-2.667v-3.5a.889.889 0 00-.674-.863l-.43-.108a.889.889 0 010-1.724l.43-.108a.889.889 0 00.674-.862V6.667zm14.222 0A2.667 2.667 0 0016.333 4a.889.889 0 000 1.778c.491 0 .89.398.89.889v3.5c0 .701.272 1.35.729 1.833a2.664 2.664 0 00-.73 1.832v3.501a.889.889 0 01-.889.89.889.889 0 000 1.777A2.667 2.667 0 0019 17.333v-3.5c0-.408.278-.764.673-.863l.431-.108a.889.889 0 000-1.724l-.43-.108a.889.889 0 01-.674-.862V6.667z`})]}),B=e=>(0,p.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,...M(e),children:[(0,p.jsx)(`title`,{children:`CSS`}),(0,p.jsx)(`path`,{fill:`#0EA5E9`,d:`M4.778 6.667A2.667 2.667 0 017.444 4a.889.889 0 010 1.778.889.889 0 00-.888.889v3.5c0 .701-.273 1.35-.73 1.833.457.483.73 1.132.73 1.832v3.501c0 .491.398.89.888.89a.889.889 0 010 1.777 2.667 2.667 0 01-2.666-2.667v-3.5a.889.889 0 00-.674-.863l-.43-.108a.889.889 0 010-1.724l.43-.108a.889.889 0 00.674-.862V6.667zm14.222 0A2.667 2.667 0 0016.333 4a.889.889 0 000 1.778c.491 0 .89.398.89.889v3.5c0 .701.272 1.35.729 1.833a2.664 2.664 0 00-.73 1.832v3.501a.889.889 0 01-.889.89.889.889 0 000 1.777A2.667 2.667 0 0019 17.333v-3.5c0-.408.278-.764.673-.863l.431-.108a.889.889 0 000-1.724l-.43-.108a.889.889 0 01-.674-.862V6.667z`})]}),V=e=>(0,p.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,...M(e),children:[(0,p.jsx)(`title`,{children:`HTML`}),(0,p.jsx)(`path`,{fill:`#EA580C`,d:`M4.778 6.667A2.667 2.667 0 017.444 4a.889.889 0 010 1.778.889.889 0 00-.888.889v3.5c0 .701-.273 1.35-.73 1.833.457.483.73 1.132.73 1.832v3.501c0 .491.398.89.888.89a.889.889 0 010 1.777 2.667 2.667 0 01-2.666-2.667v-3.5a.889.889 0 00-.674-.863l-.43-.108a.889.889 0 010-1.724l.43-.108a.889.889 0 00.674-.862V6.667zm14.222 0A2.667 2.667 0 0016.333 4a.889.889 0 000 1.778c.491 0 .89.398.89.889v3.5c0 .701.272 1.35.729 1.833a2.664 2.664 0 00-.73 1.832v3.501a.889.889 0 01-.889.89.889.889 0 000 1.777A2.667 2.667 0 0019 17.333v-3.5c0-.408.278-.764.673-.863l.431-.108a.889.889 0 000-1.724l-.43-.108a.889.889 0 01-.674-.862V6.667z`})]}),H=e=>(0,p.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,...M(e),children:[(0,p.jsx)(`title`,{children:`React`}),(0,p.jsx)(`path`,{fill:`#0E8ADC`,d:`M12 13.677a1.677 1.677 0 100-3.354 1.677 1.677 0 000 3.354z`}),(0,p.jsx)(`path`,{stroke:`#0E8ADC`,d:`M12 15.436c4.97 0 9-1.538 9-3.436s-4.03-3.436-9-3.436S3 10.102 3 12s4.03 3.436 9 3.436z`}),(0,p.jsx)(`path`,{stroke:`#0E8ADC`,d:`M9.024 13.718c2.485 4.305 5.832 7.025 7.476 6.076 1.644-.949.961-5.208-1.524-9.512C12.491 5.977 9.144 3.257 7.5 4.206c-1.644.949-.961 5.208 1.524 9.512z`}),(0,p.jsx)(`path`,{stroke:`#0E8ADC`,d:`M9.024 10.282c-2.485 4.304-3.168 8.563-1.524 9.512 1.644.95 4.99-1.771 7.476-6.076 2.485-4.304 3.168-8.563 1.524-9.512-1.644-.95-4.99 1.771-7.476 6.076z`})]}),U=e=>(0,p.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,...M(e),children:[(0,p.jsx)(`title`,{children:`Markdown`}),(0,p.jsx)(`path`,{fill:`#60A5FA`,d:`M3 15.714V8h2.323l2.322 2.836L9.968 8h2.322v7.714H9.968V11.29l-2.323 2.836-2.322-2.836v4.424H3zm14.516 0l-3.484-3.743h2.323V8h2.322v3.97H21l-3.484 3.744z`})]}),W=e=>(0,p.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 25 24`,...M(e),children:[(0,p.jsx)(`title`,{children:`Shell`}),(0,p.jsx)(`path`,{stroke:`#14B8A6`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M4.336 17l6-6-6-6M12.336 19h8`})]}),G=e=>(0,p.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,...M(e),children:[(0,p.jsx)(`title`,{children:`YAML`}),(0,p.jsx)(`path`,{fill:`#A78BFA`,d:`M6.533 5.864h2.755l2.654 5.011h.113l2.654-5.011h2.756l-4.245 7.522V17.5h-2.443v-4.114L6.533 5.864z`})]}),K=({children:e,className:t,...n})=>(0,p.jsx)(`header`,{className:k(`boltdocs-navbar sticky top-0 z-50 w-full border-b border-border-subtle bg-bg-main/80 backdrop-blur-md`,t),...n,children:e}),q=({children:e,className:t})=>(0,p.jsx)(`div`,{className:k(`mx-auto flex lg:h-navbar max-w-(--breakpoint-3xl) items-center justify-between px-4 md:px-6`,t),children:e}),J=({children:e,className:t})=>(0,p.jsx)(`div`,{className:k(`flex flex-1 items-center justify-start gap-4 min-w-0`,t),children:e}),Y=({children:e,className:t})=>(0,p.jsx)(`div`,{className:k(`flex flex-1 items-center justify-end gap-2 md:gap-4 min-w-0`,t),children:e}),X=({children:e,className:t})=>(0,p.jsx)(`div`,{className:k(`hidden lg:flex flex-1 justify-center items-center gap-4 px-4 min-w-0 w-full`,t),children:e}),Z=({src:e,alt:t,width:n=24,height:r=24,className:i})=>(0,p.jsx)(A,{href:`/`,className:k(`flex items-center gap-2 shrink-0 outline-none`,i),children:e?(0,p.jsx)(`img`,{src:e,alt:t,width:n,height:r,className:`h-6 w-6 object-contain`}):null}),ne=({children:e,className:t})=>(0,p.jsx)(A,{href:`/`,children:(0,p.jsx)(`span`,{className:k(`text-lg font-bold tracking-tight hidden sm:inline-block`,t),children:e})}),Q=({children:e,className:t})=>(0,p.jsx)(`nav`,{className:k(`hidden md:flex items-center gap-6 text-sm font-medium`,t),children:e}),re=({label:e,href:t,active:n,to:r,className:i})=>(0,p.jsxs)(A,{href:t,target:r===`external`?`_blank`:void 0,className:k(`transition-colors outline-none font-medium focus-visible:ring-2 focus-visible:ring-primary-500/30 rounded-sm`,{"text-primary-500":n,"text-text-muted hover:text-text-main":!n},i),children:[e,r===`external`&&(0,p.jsx)(`span`,{className:`ml-1 inline-block`,children:(0,p.jsx)(d.ExternalLink,{size:12})})]}),ie=({className:e,onPress:t})=>{let[n,r]=(0,l.useState)(!1),i=n&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);return(0,l.useEffect)(()=>{r(!0)},[]),(0,p.jsxs)(f.Button,{onPress:t,className:k(`flex items-center gap-2 rounded-full border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-muted outline-none cursor-pointer`,`transition-all duration-200 hover:border-border-strong hover:text-text-main hover:bg-bg-muted hover:shadow-sm active:scale-[0.98]`,`focus-visible:ring-2 focus-visible:ring-primary-500/30`,`w-full max-w-[720px] justify-between`,e),children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(d.Search,{size:16}),(0,p.jsx)(`span`,{className:`hidden sm:inline-block`,children:`Search docs...`})]}),(0,p.jsxs)(`div`,{className:`hidden sm:flex items-center gap-1 pointer-events-none select-none`,children:[(0,p.jsx)(`kbd`,{className:`flex h-5 items-center justify-center rounded border border-border-subtle bg-bg-main px-1.5 font-mono text-[10px] font-medium`,children:i?`⌘`:`Ctrl`}),(0,p.jsx)(`kbd`,{className:`flex h-5 w-5 items-center justify-center rounded border border-border-subtle bg-bg-main font-mono text-[10px] font-medium`,children:`K`})]})]})},ae=({className:e,theme:t,onThemeChange:n})=>(0,p.jsx)(f.ToggleButton,{isSelected:t===`dark`,onChange:n,className:k(`rounded-md p-2 text-text-muted outline-none cursor-pointer`,`transition-all duration-300 hover:bg-bg-surface hover:text-text-main hover:rotate-12 active:scale-90`,`focus-visible:ring-2 focus-visible:ring-primary-500/30`,e),"aria-label":`Toggle theme`,children:t===`dark`?(0,p.jsx)(d.Sun,{size:20}):(0,p.jsx)(d.Moon,{size:20})}),oe=({name:e})=>{if(e===`github`)return(0,p.jsx)(N,{});if(e===`discord`)return(0,p.jsx)(P,{});if(e===`x`)return(0,p.jsx)(F,{});if(e===`bluesky`)return(0,p.jsx)(I,{})};K.Root=K,K.Left=J,K.Right=Y,K.Center=X,K.Logo=Z,K.Title=ne,K.Links=Q,K.Link=re,K.SearchTrigger=ie,K.Theme=ae,K.Socials=({icon:e,link:t,className:n})=>(0,p.jsx)(A,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:k(`rounded-md p-2 text-text-muted outline-none transition-colors`,`hover:bg-bg-surface hover:text-text-main`,`focus-visible:ring-2 focus-visible:ring-primary-500/30`,n),children:(0,p.jsx)(oe,{name:e})}),K.Split=({className:e})=>(0,p.jsx)(f.Separator,{orientation:`vertical`,className:k(`h-6 w-px bg-border-subtle mx-1`,e)}),K.Content=q;const $=({children:e,isOpen:t,onOpenChange:n,className:r})=>(0,p.jsx)(f.ModalOverlay,{isOpen:t,onOpenChange:n,isDismissable:!0,className:k(`fixed inset-0 z-100 bg-black/40 backdrop-blur-sm px-4 py-4 sm:py-20`,`entering:animate-in entering:fade-in exiting:animate-out exiting:fade-out`),children:(0,p.jsx)(f.Modal,{className:k(`mx-auto w-full max-w-2xl overflow-hidden rounded-xl border border-border-subtle bg-bg-surface shadow-2xl ring-1 ring-black/5 outline-none`,`entering:animate-in entering:fade-in entering:zoom-in-95 exiting:animate-out exiting:fade-out exiting:zoom-out-95`,r),children:(0,p.jsx)(f.Dialog,{className:`flex flex-col max-h-[70vh] focus:outline-none`,children:e})})});$.Root=$,$.Autocomplete=({children:e,className:t,onSelectionChange:n,...r})=>{let i=f.Autocomplete;return(0,p.jsx)(`div`,{className:t,children:(0,p.jsx)(i,{...r,onSelectionChange:n,className:`flex flex-col min-h-0`,children:e})})},$.Input=({className:e,...t})=>(0,p.jsxs)(f.SearchField,{className:`flex items-center gap-3 border-b border-border-subtle px-4 py-4`,autoFocus:!0,children:[(0,p.jsx)(d.Search,{className:`h-5 w-5 text-text-muted`}),(0,p.jsx)(f.Input,{...t,className:k(`w-full bg-transparent text-lg text-text-main placeholder-text-muted outline-none`,e),placeholder:`Search documentation...`}),(0,p.jsx)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border-subtle bg-bg-main px-1.5 py-1 text-[10px] font-medium text-text-muted`,children:(0,p.jsx)(`kbd`,{className:`font-sans`,children:`ESC`})})]}),$.List=({children:e,className:t,...n})=>(0,p.jsx)(f.ListBox,{...n,className:k(`flex-1 overflow-y-auto p-2 outline-none`,t),children:e}),$.Item=Object.assign(({children:e,className:t,...n})=>(0,p.jsx)(f.ListBoxItem,{...n,className:k(`group flex items-center gap-3 rounded-lg p-3 text-left outline-none cursor-pointer transition-colors`,`text-text-muted hover:bg-bg-main hover:text-text-main focus:bg-primary-500 focus:text-white selected:bg-primary-500 selected:text-white`,t),children:t=>(0,p.jsxs)(p.Fragment,{children:[e,(t.isFocused||t.isSelected)&&(0,p.jsxs)(`div`,{className:`ml-auto opacity-50 flex items-center gap-1`,children:[(0,p.jsx)(`span`,{className:`text-[10px]`,children:`Select`}),(0,p.jsx)(d.CornerDownLeft,{size:10})]})]})}),{Icon:({isHeading:e,className:t})=>(0,p.jsx)(`div`,{className:k(`shrink-0`,t),children:e?(0,p.jsx)(d.Hash,{size:18}):(0,p.jsx)(d.FileText,{size:18})}),Title:({children:e,className:t})=>(0,p.jsx)(`span`,{className:k(`block font-medium truncate flex-1 text-sm`,t),children:e}),Bio:({children:e,className:t})=>(0,p.jsx)(`span`,{className:k(`ml-2 text-xs opacity-70 truncate hidden sm:inline group-focus:opacity-100`,t),children:e})});function se(e){let{currentLocale:t,currentVersion:n}=D(),[r,i]=(0,l.useState)(!1),[a,o]=(0,l.useState)(``),[s,c]=(0,l.useState)(null);return(0,l.useEffect)(()=>{if(!r||s)return;let e=new h.Index({preset:`match`,tokenize:`full`,resolution:9,cache:!0});for(let t of g.default)e.add(t.id,`${t.title} ${t.content}`);c(e)},[r,s]),{isOpen:r,setIsOpen:i,query:a,setQuery:o,list:(0,l.useMemo)(()=>{if(!a)return e.filter(e=>{let r=!t||e.locale===t,i=!n||e.version===n;return r&&i}).slice(0,10).map(e=>({id:e.path,title:e.title,path:e.path,bio:e.description||``,groupTitle:e.groupTitle}));if(!s)return[];let r=s.search(a,{limit:20,suggest:!0}),i=[],o=new Set;for(let e of r){let r=g.default.find(t=>t.id===e);if(!r)continue;let a=!t||r.locale===t,s=!n||r.version===n;!a||!s||o.has(r.url)||(o.add(r.url),i.push({id:r.url,title:r.title,path:r.url,bio:r.display,groupTitle:r.display.split(` > `)[0],isHeading:r.url.includes(`#`)}))}return i.slice(0,10)},[a,s,t,n,e]),input:{value:a,onChange:e=>o(e.target.value)}}}Object.defineProperty(exports,`C`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`S`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`T`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return se}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`w`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return w}});
|
package/src/client/app/index.tsx
DELETED
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState, useMemo } from 'react'
|
|
2
|
-
import { createRoot } from 'react-dom/client'
|
|
3
|
-
import { BrowserRouter, Routes, Route } from 'react-router-dom'
|
|
4
|
-
import { NotFound } from '@components/ui-base/not-found'
|
|
5
|
-
import { ThemeProvider } from './theme-context'
|
|
6
|
-
import type { ComponentRoute, CreateBoltdocsAppOptions } from '../types'
|
|
7
|
-
import type { BoltdocsConfig } from '@node/config'
|
|
8
|
-
|
|
9
|
-
import UserLayout from 'virtual:boltdocs-layout'
|
|
10
|
-
|
|
11
|
-
import { PreloadProvider } from './preload'
|
|
12
|
-
import { BoltdocsRouterProvider } from './router'
|
|
13
|
-
import { ConfigContext } from './config-context'
|
|
14
|
-
import { ScrollHandler } from './scroll-handler'
|
|
15
|
-
import { DocsLayout } from './docs-layout'
|
|
16
|
-
import { MdxPage } from './mdx-page'
|
|
17
|
-
import { MdxComponentsProvider } from './mdx-components-context'
|
|
18
|
-
import { mdxComponentsDefault } from './mdx-component'
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
import virtualCustomComponents from 'virtual:boltdocs-mdx-components'
|
|
21
|
-
import { useRoutes } from '../hooks/use-routes'
|
|
22
|
-
import { useLocation } from 'react-router-dom'
|
|
23
|
-
import { useBoltdocsStore } from '../store/boltdocs-context'
|
|
24
|
-
import { BoltdocsProvider } from '../store/boltdocs-context'
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Updates the HTML lang and dir attributes based on the current locale configuration.
|
|
28
|
-
*/
|
|
29
|
-
function I18nUpdater() {
|
|
30
|
-
const { currentLocale, config } = useRoutes()
|
|
31
|
-
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
if (!config.i18n) return
|
|
34
|
-
const localeConfig = config.i18n.localeConfigs?.[currentLocale as string]
|
|
35
|
-
document.documentElement.lang =
|
|
36
|
-
localeConfig?.htmlLang || currentLocale || 'en'
|
|
37
|
-
document.documentElement.dir = localeConfig?.direction || 'ltr'
|
|
38
|
-
}, [currentLocale, config.i18n])
|
|
39
|
-
|
|
40
|
-
return null
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Synchronizes the Zustand store with the current URL pathname.
|
|
45
|
-
*/
|
|
46
|
-
function StoreSync() {
|
|
47
|
-
const location = useLocation()
|
|
48
|
-
const { config } = useRoutes()
|
|
49
|
-
const setLocale = useBoltdocsStore((s) => s.setLocale)
|
|
50
|
-
const setVersion = useBoltdocsStore((s) => s.setVersion)
|
|
51
|
-
const currentLocaleStore = useBoltdocsStore((s) => s.currentLocale)
|
|
52
|
-
const currentVersionStore = useBoltdocsStore((s) => s.currentVersion)
|
|
53
|
-
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
const parts = location.pathname.split('/').filter(Boolean)
|
|
56
|
-
let cIdx = 0
|
|
57
|
-
let detectedVersion = config.versions?.defaultVersion
|
|
58
|
-
let detectedLocale = config.i18n?.defaultLocale
|
|
59
|
-
|
|
60
|
-
// 0. Skip docs prefix if present
|
|
61
|
-
if (parts[cIdx] === 'docs') cIdx++
|
|
62
|
-
|
|
63
|
-
// 1. Version detection
|
|
64
|
-
if (config.versions && parts.length > cIdx) {
|
|
65
|
-
const versionMatch = config.versions.versions.find(
|
|
66
|
-
(v) => v.path === parts[cIdx],
|
|
67
|
-
)
|
|
68
|
-
if (versionMatch) {
|
|
69
|
-
detectedVersion = versionMatch.path
|
|
70
|
-
cIdx++
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// 2. Locale detection
|
|
75
|
-
if (
|
|
76
|
-
config.i18n &&
|
|
77
|
-
parts.length > cIdx &&
|
|
78
|
-
config.i18n.locales[parts[cIdx]]
|
|
79
|
-
) {
|
|
80
|
-
detectedLocale = parts[cIdx]
|
|
81
|
-
} else if (config.i18n && parts.length === 0) {
|
|
82
|
-
// On root, use the stored preference if it exists, otherwise default
|
|
83
|
-
detectedLocale = currentLocaleStore || config.i18n.defaultLocale
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Only update if changed to avoid loops
|
|
87
|
-
if (detectedLocale !== currentLocaleStore) setLocale(detectedLocale)
|
|
88
|
-
if (detectedVersion !== currentVersionStore) setVersion(detectedVersion)
|
|
89
|
-
}, [
|
|
90
|
-
location.pathname,
|
|
91
|
-
config,
|
|
92
|
-
setLocale,
|
|
93
|
-
setVersion,
|
|
94
|
-
currentLocaleStore,
|
|
95
|
-
currentVersionStore,
|
|
96
|
-
])
|
|
97
|
-
|
|
98
|
-
return null
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function AppShell({
|
|
102
|
-
initialRoutes,
|
|
103
|
-
initialConfig,
|
|
104
|
-
docsDirName,
|
|
105
|
-
modules,
|
|
106
|
-
hot,
|
|
107
|
-
homePage: HomePage,
|
|
108
|
-
externalPages,
|
|
109
|
-
externalLayout: ExternalLayout,
|
|
110
|
-
components: customComponents = {},
|
|
111
|
-
}: {
|
|
112
|
-
initialRoutes: ComponentRoute[]
|
|
113
|
-
initialConfig: BoltdocsConfig
|
|
114
|
-
docsDirName: string
|
|
115
|
-
modules: Record<
|
|
116
|
-
string,
|
|
117
|
-
() => Promise<{ default: React.ComponentType<unknown> }>
|
|
118
|
-
>
|
|
119
|
-
hot?: CreateBoltdocsAppOptions['hot']
|
|
120
|
-
homePage?: React.ComponentType
|
|
121
|
-
externalPages?: Record<string, React.ComponentType>
|
|
122
|
-
externalLayout?: React.ComponentType<{ children: React.ReactNode }>
|
|
123
|
-
components?: Record<string, React.ComponentType>
|
|
124
|
-
}) {
|
|
125
|
-
const [routesInfo, setRoutesInfo] = useState<ComponentRoute[]>(initialRoutes)
|
|
126
|
-
const [config, setConfig] = useState(initialConfig)
|
|
127
|
-
const computedExternalPages = externalPages || {}
|
|
128
|
-
const EffectiveExternalLayout = ExternalLayout || UserLayout
|
|
129
|
-
|
|
130
|
-
const resolvedRoutes = useMemo(() => {
|
|
131
|
-
return routesInfo
|
|
132
|
-
.filter(
|
|
133
|
-
(route) =>
|
|
134
|
-
!(HomePage && (route.path === '/' || route.path === '')) &&
|
|
135
|
-
!computedExternalPages[route.path === '' ? '/' : route.path],
|
|
136
|
-
)
|
|
137
|
-
.map((route) => {
|
|
138
|
-
const loaderKey = Object.keys(modules).find(
|
|
139
|
-
(k) =>
|
|
140
|
-
k === `/${docsDirName}/${route.filePath}` || // Vite dev/build relative path
|
|
141
|
-
k.endsWith(`/${docsDirName}/${route.filePath}`) || // SSG absolute path fallback
|
|
142
|
-
k.endsWith(
|
|
143
|
-
`/${docsDirName}\\${route.filePath.replace(/\\/g, '/')}`,
|
|
144
|
-
), // Windows fallback
|
|
145
|
-
)
|
|
146
|
-
const loader = loaderKey ? modules[loaderKey] : null
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
...route,
|
|
150
|
-
Component: React.lazy<React.ComponentType<unknown>>(async () => {
|
|
151
|
-
if (!loader)
|
|
152
|
-
return { default: NotFound as React.ComponentType<unknown> }
|
|
153
|
-
const mod = await loader()
|
|
154
|
-
return mod as { default: React.ComponentType<unknown> }
|
|
155
|
-
}),
|
|
156
|
-
}
|
|
157
|
-
})
|
|
158
|
-
}, [routesInfo, modules, docsDirName, HomePage, computedExternalPages])
|
|
159
|
-
|
|
160
|
-
// Subscribe to HMR events
|
|
161
|
-
useEffect(() => {
|
|
162
|
-
if (hot) {
|
|
163
|
-
hot.on('boltdocs:routes-update', (newRoutes: ComponentRoute[]) => {
|
|
164
|
-
setRoutesInfo(newRoutes)
|
|
165
|
-
})
|
|
166
|
-
hot.on('boltdocs:config-update', (newConfig: BoltdocsConfig) => {
|
|
167
|
-
setConfig(newConfig)
|
|
168
|
-
})
|
|
169
|
-
}
|
|
170
|
-
}, [hot])
|
|
171
|
-
|
|
172
|
-
const allComponents = useMemo(
|
|
173
|
-
() => ({
|
|
174
|
-
...mdxComponentsDefault,
|
|
175
|
-
...virtualCustomComponents,
|
|
176
|
-
...customComponents,
|
|
177
|
-
}),
|
|
178
|
-
[customComponents],
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
const LoadingFallback = allComponents.Loading as React.ComponentType
|
|
182
|
-
|
|
183
|
-
return (
|
|
184
|
-
<BoltdocsProvider>
|
|
185
|
-
<ThemeProvider>
|
|
186
|
-
<MdxComponentsProvider components={allComponents}>
|
|
187
|
-
<ConfigContext.Provider value={config}>
|
|
188
|
-
<BoltdocsRouterProvider>
|
|
189
|
-
<PreloadProvider routes={routesInfo} modules={modules}>
|
|
190
|
-
<ScrollHandler />
|
|
191
|
-
<StoreSync />
|
|
192
|
-
<I18nUpdater />
|
|
193
|
-
<Routes>
|
|
194
|
-
<Route key="docs-layout" element={<DocsLayout />}>
|
|
195
|
-
{resolvedRoutes.map((route) => (
|
|
196
|
-
<Route
|
|
197
|
-
key={route.path}
|
|
198
|
-
path={route.path === '' ? '/' : route.path}
|
|
199
|
-
element={
|
|
200
|
-
<React.Suspense fallback={<LoadingFallback />}>
|
|
201
|
-
<MdxPage Component={route.Component} />
|
|
202
|
-
</React.Suspense>
|
|
203
|
-
}
|
|
204
|
-
/>
|
|
205
|
-
))}
|
|
206
|
-
</Route>
|
|
207
|
-
|
|
208
|
-
{/* Custom home page with user layout */}
|
|
209
|
-
{HomePage && (
|
|
210
|
-
<>
|
|
211
|
-
<Route
|
|
212
|
-
path="/"
|
|
213
|
-
element={
|
|
214
|
-
<EffectiveExternalLayout>
|
|
215
|
-
<HomePage />
|
|
216
|
-
</EffectiveExternalLayout>
|
|
217
|
-
}
|
|
218
|
-
/>
|
|
219
|
-
{config.i18n &&
|
|
220
|
-
Object.keys(config.i18n.locales).map((locale) => (
|
|
221
|
-
<Route
|
|
222
|
-
key={`home-${locale}`}
|
|
223
|
-
path={`/${locale}`}
|
|
224
|
-
element={
|
|
225
|
-
<EffectiveExternalLayout>
|
|
226
|
-
<HomePage />
|
|
227
|
-
</EffectiveExternalLayout>
|
|
228
|
-
}
|
|
229
|
-
/>
|
|
230
|
-
))}
|
|
231
|
-
</>
|
|
232
|
-
)}
|
|
233
|
-
|
|
234
|
-
{/* Custom External Pages with user layout */}
|
|
235
|
-
{Object.entries(computedExternalPages).map(
|
|
236
|
-
([extPath, ExtComponent]) => {
|
|
237
|
-
const cleanPath = extPath === '/' ? '' : extPath
|
|
238
|
-
return (
|
|
239
|
-
<React.Fragment key={extPath}>
|
|
240
|
-
<Route
|
|
241
|
-
path={extPath}
|
|
242
|
-
element={
|
|
243
|
-
<EffectiveExternalLayout>
|
|
244
|
-
<ExtComponent />
|
|
245
|
-
</EffectiveExternalLayout>
|
|
246
|
-
}
|
|
247
|
-
/>
|
|
248
|
-
{config.i18n &&
|
|
249
|
-
Object.keys(config.i18n.locales).map((locale) => (
|
|
250
|
-
<Route
|
|
251
|
-
key={`${extPath}-${locale}`}
|
|
252
|
-
path={`/${locale}${cleanPath}`}
|
|
253
|
-
element={
|
|
254
|
-
<EffectiveExternalLayout>
|
|
255
|
-
<ExtComponent />
|
|
256
|
-
</EffectiveExternalLayout>
|
|
257
|
-
}
|
|
258
|
-
/>
|
|
259
|
-
))}
|
|
260
|
-
</React.Fragment>
|
|
261
|
-
)
|
|
262
|
-
},
|
|
263
|
-
)}
|
|
264
|
-
|
|
265
|
-
<Route
|
|
266
|
-
path="*"
|
|
267
|
-
element={
|
|
268
|
-
<UserLayout>
|
|
269
|
-
<NotFound />
|
|
270
|
-
</UserLayout>
|
|
271
|
-
}
|
|
272
|
-
/>
|
|
273
|
-
</Routes>
|
|
274
|
-
</PreloadProvider>
|
|
275
|
-
</BoltdocsRouterProvider>
|
|
276
|
-
</ConfigContext.Provider>
|
|
277
|
-
</MdxComponentsProvider>
|
|
278
|
-
</ThemeProvider>
|
|
279
|
-
</BoltdocsProvider>
|
|
280
|
-
)
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Creates and mounts the Boltdocs documentation app.
|
|
285
|
-
*
|
|
286
|
-
* Usage:
|
|
287
|
-
* ```tsx
|
|
288
|
-
* import { createBoltdocsApp } from 'boltdocs/client'
|
|
289
|
-
* import routes from 'virtual:boltdocs-routes'
|
|
290
|
-
* import config from 'virtual:boltdocs-config'
|
|
291
|
-
* import 'boltdocs/style.css'
|
|
292
|
-
* import HomePage from './HomePage'
|
|
293
|
-
*
|
|
294
|
-
* createBoltdocsApp({
|
|
295
|
-
* target: '#root',
|
|
296
|
-
* routes,
|
|
297
|
-
* config,
|
|
298
|
-
* modules: import.meta.glob('/docs/**\/*.{md,mdx}'),
|
|
299
|
-
* hot: import.meta.hot,
|
|
300
|
-
* homePage: HomePage,
|
|
301
|
-
* })
|
|
302
|
-
* ```
|
|
303
|
-
*/
|
|
304
|
-
export function createBoltdocsApp(options: CreateBoltdocsAppOptions) {
|
|
305
|
-
const {
|
|
306
|
-
target,
|
|
307
|
-
routes,
|
|
308
|
-
docsDirName,
|
|
309
|
-
config,
|
|
310
|
-
modules,
|
|
311
|
-
hot,
|
|
312
|
-
homePage,
|
|
313
|
-
externalPages,
|
|
314
|
-
externalLayout,
|
|
315
|
-
components,
|
|
316
|
-
} = options
|
|
317
|
-
const container = document.querySelector(target)
|
|
318
|
-
if (!container) {
|
|
319
|
-
throw new Error(
|
|
320
|
-
`[boltdocs] Mount target "${target}" not found in document.`,
|
|
321
|
-
)
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
const app = (
|
|
325
|
-
<React.StrictMode>
|
|
326
|
-
<BrowserRouter>
|
|
327
|
-
<AppShell
|
|
328
|
-
initialRoutes={routes}
|
|
329
|
-
initialConfig={config}
|
|
330
|
-
docsDirName={docsDirName}
|
|
331
|
-
modules={modules}
|
|
332
|
-
hot={hot}
|
|
333
|
-
homePage={homePage}
|
|
334
|
-
externalPages={externalPages}
|
|
335
|
-
externalLayout={externalLayout}
|
|
336
|
-
components={components}
|
|
337
|
-
/>
|
|
338
|
-
</BrowserRouter>
|
|
339
|
-
</React.StrictMode>
|
|
340
|
-
)
|
|
341
|
-
|
|
342
|
-
// SSG pre-renders a shell with mock components for SEO crawlers.
|
|
343
|
-
// We always use createRoot because the SSG output doesn't match the
|
|
344
|
-
// real client-side component tree (components are lazy/dynamic).
|
|
345
|
-
// Clear any SSG placeholder content before mounting.
|
|
346
|
-
container.innerHTML = ''
|
|
347
|
-
createRoot(container as HTMLElement).render(app)
|
|
348
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useMdxComponents } from './mdx-components-context'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Renders an MDX page securely, injecting required custom components.
|
|
5
|
-
* This overrides the default HTML tags emitted by MDX with stylized components.
|
|
6
|
-
*/
|
|
7
|
-
export function MdxPage({
|
|
8
|
-
Component,
|
|
9
|
-
}: {
|
|
10
|
-
Component: React.ComponentType<any>
|
|
11
|
-
}) {
|
|
12
|
-
const allComponents = useMdxComponents()
|
|
13
|
-
|
|
14
|
-
return <Component components={allComponents as any} />
|
|
15
|
-
}
|
|
@@ -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
|
-
}
|