reroute-js 0.5.0 → 0.7.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 (121) hide show
  1. package/README.md +142 -0
  2. package/_/basic/package.json +4 -4
  3. package/_/basic/src/client/index.html +1 -1
  4. package/_/basic/src/index.ts +1 -3
  5. package/_/blog/package.json +4 -4
  6. package/_/blog/src/client/App.tsx +1 -0
  7. package/_/blog/src/client/index.html +1 -1
  8. package/_/blog/src/client/routes/blog/content/1-hello-world.tsx +1 -1
  9. package/_/blog/src/client/routes/blog/content/3-markdown-with-syntax-highlighting.mdx +213 -0
  10. package/_/blog/src/client/routes/blog/content/4-content-in-markdown.md +143 -0
  11. package/_/blog/src/client/routes/blog/content/5-mdx-with-components.mdx +267 -0
  12. package/_/blog/src/client/routes/blog/index.tsx +59 -0
  13. package/_/blog/src/client/routes/client.tsx +564 -0
  14. package/_/blog/src/client/routes/docs.tsx +670 -0
  15. package/_/blog/src/client/routes/index.tsx +37 -0
  16. package/_/blog/src/client/routes/markdown-demo.md +169 -0
  17. package/_/blog/src/client/routes/markdown.tsx +160 -0
  18. package/_/blog/src/index.ts +5 -2
  19. package/_/store/package.json +4 -4
  20. package/_/store/src/client/index.html +1 -1
  21. package/_/store/src/index.ts +1 -1
  22. package/cli/bin.d.ts +1 -1
  23. package/cli/bin.js +1313 -74
  24. package/cli/bin.js.map +13 -7
  25. package/cli/index.d.ts +1 -1
  26. package/cli/index.js +428 -17
  27. package/cli/index.js.map +6 -3
  28. package/cli/src/cli.d.ts +1 -1
  29. package/cli/src/commands/boot.d.ts +1 -1
  30. package/cli/src/commands/build.d.ts +19 -0
  31. package/cli/src/commands/build.d.ts.map +1 -0
  32. package/cli/src/commands/dev.d.ts +18 -0
  33. package/cli/src/commands/dev.d.ts.map +1 -0
  34. package/cli/src/commands/gen.d.ts +1 -1
  35. package/cli/src/commands/gen.d.ts.map +1 -1
  36. package/cli/src/commands/init.d.ts +1 -1
  37. package/cli/src/commands/start.d.ts +19 -0
  38. package/cli/src/commands/start.d.ts.map +1 -0
  39. package/cli/src/libs/index.d.ts +4 -1
  40. package/cli/src/libs/index.d.ts.map +1 -1
  41. package/cli/src/libs/log.d.ts +46 -0
  42. package/cli/src/libs/log.d.ts.map +1 -0
  43. package/cli/src/libs/markdown-processor.d.ts +59 -0
  44. package/cli/src/libs/markdown-processor.d.ts.map +1 -0
  45. package/cli/src/libs/markdown.d.ts +33 -0
  46. package/cli/src/libs/markdown.d.ts.map +1 -0
  47. package/cli/src/libs/tailwind.d.ts +1 -1
  48. package/cli/src/libs/version.d.ts +1 -1
  49. package/core/index.d.ts +1 -1
  50. package/core/index.js +4 -4
  51. package/core/index.js.map +2 -2
  52. package/core/src/bundler/hash.d.ts +1 -1
  53. package/core/src/bundler/index.d.ts +1 -1
  54. package/core/src/bundler/transpile.d.ts +1 -1
  55. package/core/src/content/discovery.d.ts +1 -1
  56. package/core/src/content/index.d.ts +1 -1
  57. package/core/src/content/metadata.d.ts +1 -1
  58. package/core/src/content/registry.d.ts +1 -1
  59. package/core/src/index.d.ts +1 -1
  60. package/core/src/ssr/data.d.ts +1 -1
  61. package/core/src/ssr/index.d.ts +1 -1
  62. package/core/src/ssr/modules.d.ts +1 -1
  63. package/core/src/ssr/render.d.ts +1 -1
  64. package/core/src/ssr/seed.d.ts +1 -1
  65. package/core/src/template/html.d.ts +1 -1
  66. package/core/src/template/index.d.ts +1 -1
  67. package/core/src/types.d.ts +1 -1
  68. package/core/src/utils/cache.d.ts +1 -1
  69. package/core/src/utils/compression.d.ts +1 -1
  70. package/core/src/utils/index.d.ts +1 -1
  71. package/core/src/utils/mime.d.ts +1 -1
  72. package/core/src/utils/path.d.ts +1 -1
  73. package/elysia/index.d.ts +1 -1
  74. package/elysia/index.js +4 -4
  75. package/elysia/index.js.map +2 -2
  76. package/elysia/src/index.d.ts +1 -1
  77. package/elysia/src/libs/http.d.ts +1 -1
  78. package/elysia/src/libs/image.d.ts +1 -1
  79. package/elysia/src/plugin.d.ts +1 -1
  80. package/elysia/src/routes/artifacts.d.ts +1 -1
  81. package/elysia/src/routes/content.d.ts +1 -1
  82. package/elysia/src/routes/dev.d.ts +1 -1
  83. package/elysia/src/routes/image.d.ts +1 -1
  84. package/elysia/src/routes/ssr.d.ts +1 -1
  85. package/elysia/src/routes/static.d.ts +1 -1
  86. package/elysia/src/types.d.ts +1 -1
  87. package/package.json +22 -9
  88. package/react/index.d.ts +1 -1
  89. package/react/index.js +141 -36
  90. package/react/index.js.map +7 -6
  91. package/react/src/components/ClientOnly.d.ts +1 -1
  92. package/react/src/components/ContentRoute.d.ts +1 -1
  93. package/react/src/components/ContentRoute.d.ts.map +1 -1
  94. package/react/src/components/Image.d.ts +1 -1
  95. package/react/src/components/Link.d.ts +1 -1
  96. package/react/src/components/Link.d.ts.map +1 -1
  97. package/react/src/components/Markdown.d.ts +89 -0
  98. package/react/src/components/Markdown.d.ts.map +1 -0
  99. package/react/src/components/Outlet.d.ts +1 -1
  100. package/react/src/components/index.d.ts +2 -1
  101. package/react/src/components/index.d.ts.map +1 -1
  102. package/react/src/hooks/index.d.ts +1 -1
  103. package/react/src/hooks/useContent.d.ts +1 -1
  104. package/react/src/hooks/useData.d.ts +1 -1
  105. package/react/src/hooks/useNavigate.d.ts +1 -1
  106. package/react/src/hooks/useParams.d.ts +1 -1
  107. package/react/src/hooks/useRouter.d.ts +1 -1
  108. package/react/src/hooks/useSearchParams.d.ts +1 -1
  109. package/react/src/index.d.ts +1 -1
  110. package/react/src/providers/ContentProvider.d.ts +1 -1
  111. package/react/src/providers/RerouteProvider.d.ts +1 -1
  112. package/react/src/providers/RouterProvider.d.ts +1 -1
  113. package/react/src/providers/RouterProvider.d.ts.map +1 -1
  114. package/react/src/providers/index.d.ts +1 -1
  115. package/react/src/types/any.d.ts +1 -1
  116. package/react/src/types/index.d.ts +1 -1
  117. package/react/src/types/router.d.ts +1 -1
  118. package/react/src/utils/content.d.ts +1 -1
  119. package/react/src/utils/head.d.ts +1 -1
  120. package/react/src/utils/index.d.ts +1 -1
  121. package/_/blog/src/client/components/Counter.tsx +0 -14
@@ -0,0 +1,267 @@
1
+ ---
2
+ title: MDX with React Components
3
+ description: Learn how to use React components directly in your markdown content with MDX
4
+ date: 2025-11-06
5
+ excerpt: MDX lets you import and use React components inside markdown - true component composition!
6
+ ---
7
+
8
+ # MDX with React Component
9
+
10
+ This page is written in **MDX** - which means we can use React components directly in our markdown! 🎉
11
+
12
+ ## What is MDX?
13
+
14
+ MDX is markdown with JSX. It lets you:
15
+ - Import React components
16
+ - Use them inline with your content
17
+ - Create interactive documentation
18
+ - Build component-driven content
19
+
20
+ ## Custom Components Example
21
+
22
+ Here's a custom React component embedded in this markdown:
23
+
24
+ export function Highlight({ children, color = '#667eea' }) {
25
+ return (
26
+ <span style={{
27
+ background: `linear-gradient(135deg, ${color} 0%, ${color}dd 100%)`,
28
+ color: 'white',
29
+ padding: '0.25rem 0.75rem',
30
+ borderRadius: '6px',
31
+ fontWeight: '600',
32
+ display: 'inline-block'
33
+ }}>
34
+ {children}
35
+ </span>
36
+ );
37
+ }
38
+
39
+ You can use custom components inline: <Highlight>This is highlighted!</Highlight> or with different colors: <Highlight color="#22c55e">Green highlight</Highlight>
40
+
41
+ Pretty cool, right? These components are defined right in this MDX file and work with SSR!
42
+
43
+ ## Using Standard HTML
44
+
45
+ You can use standard HTML elements in your MDX. Links work as regular anchor tags:
46
+
47
+ <div style={{
48
+ padding: '1rem',
49
+ background: '#f0f9ff',
50
+ borderRadius: '8px',
51
+ border: '2px solid #bfdbfe'
52
+ }}>
53
+ {/* Use a div instead of p to avoid nested paragraphs */}
54
+ <div style={{ margin: '0 0 0.5rem 0', fontWeight: '600', color: '#1e40af' }}>
55
+ Quick Navigation:
56
+ </div>
57
+ <div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }}>
58
+ <a
59
+ href="/"
60
+ style={{
61
+ padding: '0.5rem 1rem',
62
+ background: '#3b82f6',
63
+ color: 'white',
64
+ borderRadius: '6px',
65
+ textDecoration: 'none',
66
+ fontSize: '0.9rem'
67
+ }}
68
+ >
69
+ <span>Home</span>
70
+ </a>
71
+ <a
72
+ href="/blog"
73
+ style={{
74
+ padding: '0.5rem 1rem',
75
+ background: '#3b82f6',
76
+ color: 'white',
77
+ borderRadius: '6px',
78
+ textDecoration: 'none',
79
+ fontSize: '0.9rem'
80
+ }}
81
+ >
82
+ <span>Blog</span>
83
+ </a>
84
+ <a
85
+ href="/markdown-demo"
86
+ style={{
87
+ padding: '0.5rem 1rem',
88
+ background: '#3b82f6',
89
+ color: 'white',
90
+ borderRadius: '6px',
91
+ textDecoration: 'none',
92
+ fontSize: '0.9rem'
93
+ }}
94
+ >
95
+ <span>Markdown Demo</span>
96
+ </a>
97
+ </div>
98
+ </div>
99
+
100
+ ## Alert Component
101
+
102
+ Let's create a reusable alert component inline:
103
+
104
+ export function Alert({ type = 'info', children }) {
105
+ const colors = {
106
+ info: { bg: '#dbeafe', border: '#3b82f6', text: '#1e40af' },
107
+ success: { bg: '#dcfce7', border: '#22c55e', text: '#166534' },
108
+ warning: { bg: '#fef3c7', border: '#f59e0b', text: '#92400e' },
109
+ error: { bg: '#fee2e2', border: '#ef4444', text: '#991b1b' }
110
+ };
111
+ const style = colors[type] || colors.info;
112
+ return (
113
+ <div style={{
114
+ padding: '1rem 1.25rem',
115
+ background: style.bg,
116
+ border: `2px solid ${style.border}`,
117
+ borderRadius: '8px',
118
+ color: style.text,
119
+ margin: '1rem 0'
120
+ }}>
121
+ {children}
122
+ </div>
123
+ );
124
+ }
125
+
126
+ Now we can use it throughout our content:
127
+
128
+ <Alert type="info">
129
+ 💡 **Tip:** MDX files require the `@mdx-js/mdx` package. Install it with: `bun add @mdx-js/mdx`
130
+ </Alert>
131
+
132
+ <Alert type="success">
133
+ ✅ **Success:** You're now using real React components in markdown!
134
+ </Alert>
135
+
136
+ <Alert type="warning">
137
+ ⚠️ **Warning:** MDX files are compiled at build time, so changes require running `reroute gen`.
138
+ </Alert>
139
+
140
+ <Alert type="error">
141
+ 🚫 **Error Example:** This is what error messages might look like.
142
+ </Alert>
143
+
144
+ ## Code Examples Still Work
145
+
146
+ You can still use regular markdown features like code blocks:
147
+
148
+ ```typescript
149
+ // MDX compiles to JSX at build time
150
+ import { MyComponent } from './components/MyComponent';
151
+
152
+ export default function BlogPost() {
153
+ return (
154
+ <div>
155
+ <h1>Hello from TSX!</h1>
156
+ <MyComponent />
157
+ </div>
158
+ );
159
+ }
160
+ ```
161
+
162
+ And even mix JSX with markdown syntax!
163
+
164
+ ## Data Visualization
165
+
166
+ Let's create a simple bar chart component:
167
+
168
+ export function BarChart({ data }) {
169
+ const max = Math.max(...data.map(d => d.value));
170
+ return (
171
+ <div style={{ margin: '2rem 0' }}>
172
+ {data.map((item, i) => (
173
+ <div key={i} style={{ marginBottom: '0.75rem' }}>
174
+ <div style={{
175
+ display: 'flex',
176
+ alignItems: 'center',
177
+ gap: '1rem'
178
+ }}>
179
+ <span style={{
180
+ minWidth: '100px',
181
+ fontWeight: '600',
182
+ fontSize: '0.9rem'
183
+ }}>
184
+ {item.label}
185
+ </span>
186
+ <div style={{
187
+ flex: 1,
188
+ background: '#e5e7eb',
189
+ borderRadius: '4px',
190
+ overflow: 'hidden'
191
+ }}>
192
+ <div style={{
193
+ width: `${(item.value / max) * 100}%`,
194
+ background: 'linear-gradient(90deg, #3b82f6, #8b5cf6)',
195
+ padding: '0.5rem',
196
+ color: 'white',
197
+ fontSize: '0.85rem',
198
+ fontWeight: '600',
199
+ textAlign: 'right',
200
+ minWidth: '40px'
201
+ }}>
202
+ {item.value}
203
+ </div>
204
+ </div>
205
+ </div>
206
+ </div>
207
+ ))}
208
+ </div>
209
+ );
210
+ }
211
+
212
+ <BarChart data={[
213
+ { label: 'React', value: 95 },
214
+ { label: 'TypeScript', value: 88 },
215
+ { label: 'Bun', value: 92 },
216
+ { label: 'Elysia', value: 85 },
217
+ { label: 'MDX', value: 90 }
218
+ ]} />
219
+
220
+ ## When to Use MDX
221
+
222
+ **Use MDX when you need:**
223
+ - ✅ Custom styled components in documentation
224
+ - ✅ Data visualizations in blog posts (use static data)
225
+ - ✅ Custom UI elements mixed with content
226
+ - ✅ Reusable component patterns
227
+ - ✅ Rich formatted content
228
+
229
+ **Use regular Markdown when:**
230
+ - 📝 Simple content without interactivity
231
+ - 📝 Faster build times (no JSX compilation)
232
+ - 📝 Content-only pages
233
+ - 📝 Working with non-technical writers
234
+
235
+ ## Installation & Setup
236
+
237
+ To use MDX in your Reroute project:
238
+
239
+ ```bash
240
+ # Required for MDX support
241
+ bun add @mdx-js/mdx
242
+
243
+ # Already required for markdown
244
+ bun add react-markdown
245
+
246
+ # Optional: Enhanced markdown features
247
+ bun add remark-gfm
248
+
249
+ # Optional: Syntax highlighting
250
+ bun add -d @shikijs/rehype
251
+ ```
252
+
253
+ Then just create `.mdx` files in your routes or content directories!
254
+
255
+ ## Conclusion
256
+
257
+ MDX gives you the best of both worlds: the simplicity of markdown with the power of React components. Perfect for creating rich, beautifully formatted documentation and content-driven applications.
258
+
259
+ **Note:** Content in MDX files is rendered in isolation during SSR. For interactive components with hooks or components that need React context (like `<Link>`), use plain HTML or import from client-side files wrapped with `<ClientOnly>`.
260
+
261
+ <Alert type="success">
262
+ 🎉 **That's it!** You now know how to use MDX with Reroute. Go build something amazing!
263
+ </Alert>
264
+
265
+ ---
266
+
267
+ *This entire page was written in MDX and includes live React components!* ✨
@@ -62,6 +62,65 @@ function BlogIndex() {
62
62
  </article>
63
63
  ))}
64
64
  </div>
65
+
66
+ {/* Fragment Navigation Demo */}
67
+ <div
68
+ style={{
69
+ marginTop: '3rem',
70
+ padding: '1.5rem',
71
+ background: '#f0f8ff',
72
+ border: '2px solid #0066cc',
73
+ borderRadius: '8px',
74
+ }}
75
+ >
76
+ <h3 style={{ marginTop: 0 }}>🎯 New Feature: Fragment Navigation</h3>
77
+ <p style={{ marginBottom: '1rem' }}>
78
+ Check out our documentation to learn about the new{' '}
79
+ <code>fragment</code> prop for automatic scrolling to specific
80
+ sections!
81
+ </p>
82
+ <div style={{ display: 'flex', gap: '1rem', flexWrap: 'wrap' }}>
83
+ <Link
84
+ to='/docs'
85
+ fragment='installation'
86
+ style={{
87
+ padding: '0.5rem 1rem',
88
+ background: '#0066cc',
89
+ color: '#fff',
90
+ textDecoration: 'none',
91
+ borderRadius: '4px',
92
+ }}
93
+ >
94
+ Jump to Installation →
95
+ </Link>
96
+ <Link
97
+ to='/docs'
98
+ fragment='examples'
99
+ style={{
100
+ padding: '0.5rem 1rem',
101
+ background: '#28a745',
102
+ color: '#fff',
103
+ textDecoration: 'none',
104
+ borderRadius: '4px',
105
+ }}
106
+ >
107
+ View Examples →
108
+ </Link>
109
+ <Link
110
+ to='/docs'
111
+ fragment='api-reference'
112
+ style={{
113
+ padding: '0.5rem 1rem',
114
+ background: '#6c757d',
115
+ color: '#fff',
116
+ textDecoration: 'none',
117
+ borderRadius: '4px',
118
+ }}
119
+ >
120
+ API Reference →
121
+ </Link>
122
+ </div>
123
+ </div>
65
124
  </div>
66
125
  );
67
126
  }