@btst/stack 1.0.1 → 1.1.1

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 (282) hide show
  1. package/README.md +156 -709
  2. package/dist/api/index.cjs +2 -1
  3. package/dist/api/index.d.cts +4 -3
  4. package/dist/api/index.d.mts +4 -3
  5. package/dist/api/index.d.ts +4 -3
  6. package/dist/api/index.mjs +1 -1
  7. package/dist/client/components/compose.cjs +68 -0
  8. package/dist/client/components/compose.mjs +65 -0
  9. package/dist/client/components/error-boundary.cjs +24 -0
  10. package/dist/client/components/error-boundary.mjs +22 -0
  11. package/dist/client/components/index.cjs +10 -0
  12. package/dist/client/components/index.d.cts +52 -0
  13. package/dist/client/components/index.d.mts +52 -0
  14. package/dist/client/components/index.d.ts +52 -0
  15. package/dist/client/components/index.mjs +2 -0
  16. package/dist/client/index.cjs +24 -5
  17. package/dist/client/index.d.cts +125 -8
  18. package/dist/client/index.d.mts +125 -8
  19. package/dist/client/index.d.ts +125 -8
  20. package/dist/client/index.mjs +21 -4
  21. package/dist/client/meta-utils.cjs +162 -0
  22. package/dist/client/meta-utils.mjs +160 -0
  23. package/dist/client/path-utils.cjs +15 -0
  24. package/dist/client/path-utils.mjs +13 -0
  25. package/dist/client/sitemap-utils.cjs +14 -0
  26. package/dist/client/sitemap-utils.mjs +12 -0
  27. package/dist/context/index.cjs +6 -63
  28. package/dist/context/index.d.cts +21 -24
  29. package/dist/context/index.d.mts +21 -24
  30. package/dist/context/index.d.ts +21 -24
  31. package/dist/context/index.mjs +1 -61
  32. package/dist/context/provider.cjs +51 -0
  33. package/dist/context/provider.mjs +46 -0
  34. package/dist/index.cjs +2 -3
  35. package/dist/index.d.cts +3 -2
  36. package/dist/index.d.mts +3 -2
  37. package/dist/index.d.ts +3 -2
  38. package/dist/index.mjs +1 -2
  39. package/dist/plugins/api/index.cjs +13 -0
  40. package/dist/plugins/api/index.d.cts +40 -0
  41. package/dist/plugins/api/index.d.mts +40 -0
  42. package/dist/plugins/api/index.d.ts +40 -0
  43. package/dist/plugins/api/index.mjs +8 -0
  44. package/dist/plugins/blog/api/index.cjs +11 -0
  45. package/dist/plugins/blog/api/index.d.cts +7 -0
  46. package/dist/plugins/blog/api/index.d.mts +7 -0
  47. package/dist/plugins/blog/api/index.d.ts +7 -0
  48. package/dist/plugins/blog/api/index.mjs +2 -0
  49. package/dist/plugins/blog/api/plugin.cjs +569 -0
  50. package/dist/plugins/blog/api/plugin.mjs +565 -0
  51. package/dist/plugins/blog/client/components/forms/image-field.cjs +133 -0
  52. package/dist/plugins/blog/client/components/forms/image-field.mjs +131 -0
  53. package/dist/plugins/blog/client/components/forms/markdown-editor-styles.css +30 -0
  54. package/dist/plugins/blog/client/components/forms/markdown-editor.cjs +106 -0
  55. package/dist/plugins/blog/client/components/forms/markdown-editor.mjs +104 -0
  56. package/dist/plugins/blog/client/components/forms/post-forms.cjs +401 -0
  57. package/dist/plugins/blog/client/components/forms/post-forms.mjs +398 -0
  58. package/dist/plugins/blog/client/components/forms/tags-multiselect.cjs +71 -0
  59. package/dist/plugins/blog/client/components/forms/tags-multiselect.mjs +65 -0
  60. package/dist/plugins/blog/client/components/index.cjs +17 -0
  61. package/dist/plugins/blog/client/components/index.d.cts +22 -0
  62. package/dist/plugins/blog/client/components/index.d.mts +22 -0
  63. package/dist/plugins/blog/client/components/index.d.ts +22 -0
  64. package/dist/plugins/blog/client/components/index.mjs +12 -0
  65. package/dist/plugins/blog/client/components/loading/form-page-skeleton.cjs +62 -0
  66. package/dist/plugins/blog/client/components/loading/form-page-skeleton.mjs +60 -0
  67. package/dist/plugins/blog/client/components/loading/index.cjs +20 -0
  68. package/dist/plugins/blog/client/components/loading/index.mjs +16 -0
  69. package/dist/plugins/blog/client/components/loading/list-page-skeleton.cjs +26 -0
  70. package/dist/plugins/blog/client/components/loading/list-page-skeleton.mjs +24 -0
  71. package/dist/plugins/blog/client/components/loading/page-header-skeleton.cjs +13 -0
  72. package/dist/plugins/blog/client/components/loading/page-header-skeleton.mjs +11 -0
  73. package/dist/plugins/blog/client/components/loading/post-card-skeleton.cjs +22 -0
  74. package/dist/plugins/blog/client/components/loading/post-card-skeleton.mjs +20 -0
  75. package/dist/plugins/blog/client/components/loading/post-page-skeleton.cjs +56 -0
  76. package/dist/plugins/blog/client/components/loading/post-page-skeleton.mjs +54 -0
  77. package/dist/plugins/blog/client/components/pages/404-page.cjs +19 -0
  78. package/dist/plugins/blog/client/components/pages/404-page.mjs +17 -0
  79. package/dist/plugins/blog/client/components/pages/edit-post-page.cjs +41 -0
  80. package/dist/plugins/blog/client/components/pages/edit-post-page.internal.cjs +57 -0
  81. package/dist/plugins/blog/client/components/pages/edit-post-page.internal.mjs +55 -0
  82. package/dist/plugins/blog/client/components/pages/edit-post-page.mjs +39 -0
  83. package/dist/plugins/blog/client/components/pages/home-page.cjs +41 -0
  84. package/dist/plugins/blog/client/components/pages/home-page.internal.cjs +61 -0
  85. package/dist/plugins/blog/client/components/pages/home-page.internal.mjs +59 -0
  86. package/dist/plugins/blog/client/components/pages/home-page.mjs +39 -0
  87. package/dist/plugins/blog/client/components/pages/new-post-page.cjs +37 -0
  88. package/dist/plugins/blog/client/components/pages/new-post-page.internal.cjs +53 -0
  89. package/dist/plugins/blog/client/components/pages/new-post-page.internal.mjs +51 -0
  90. package/dist/plugins/blog/client/components/pages/new-post-page.mjs +35 -0
  91. package/dist/plugins/blog/client/components/pages/post-page.cjs +39 -0
  92. package/dist/plugins/blog/client/components/pages/post-page.internal.cjs +101 -0
  93. package/dist/plugins/blog/client/components/pages/post-page.internal.mjs +99 -0
  94. package/dist/plugins/blog/client/components/pages/post-page.mjs +37 -0
  95. package/dist/plugins/blog/client/components/pages/tag-page.cjs +39 -0
  96. package/dist/plugins/blog/client/components/pages/tag-page.internal.cjs +61 -0
  97. package/dist/plugins/blog/client/components/pages/tag-page.internal.mjs +59 -0
  98. package/dist/plugins/blog/client/components/pages/tag-page.mjs +37 -0
  99. package/dist/plugins/blog/client/components/shared/better-blog-attribution.cjs +24 -0
  100. package/dist/plugins/blog/client/components/shared/better-blog-attribution.mjs +22 -0
  101. package/dist/plugins/blog/client/components/shared/default-error.cjs +18 -0
  102. package/dist/plugins/blog/client/components/shared/default-error.mjs +16 -0
  103. package/dist/plugins/blog/client/components/shared/defaults.cjs +13 -0
  104. package/dist/plugins/blog/client/components/shared/defaults.mjs +10 -0
  105. package/dist/plugins/blog/client/components/shared/empty-list.cjs +21 -0
  106. package/dist/plugins/blog/client/components/shared/empty-list.mjs +19 -0
  107. package/dist/plugins/blog/client/components/shared/error-placeholder.cjs +24 -0
  108. package/dist/plugins/blog/client/components/shared/error-placeholder.mjs +22 -0
  109. package/dist/plugins/blog/client/components/shared/highlight-text.cjs +53 -0
  110. package/dist/plugins/blog/client/components/shared/highlight-text.mjs +51 -0
  111. package/dist/plugins/blog/client/components/shared/markdown-content-styles.css +328 -0
  112. package/dist/plugins/blog/client/components/shared/markdown-content.cjs +324 -0
  113. package/dist/plugins/blog/client/components/shared/markdown-content.mjs +315 -0
  114. package/dist/plugins/blog/client/components/shared/on-this-page.cjs +161 -0
  115. package/dist/plugins/blog/client/components/shared/on-this-page.mjs +158 -0
  116. package/dist/plugins/blog/client/components/shared/page-header.cjs +40 -0
  117. package/dist/plugins/blog/client/components/shared/page-header.mjs +38 -0
  118. package/dist/plugins/blog/client/components/shared/page-layout.cjs +24 -0
  119. package/dist/plugins/blog/client/components/shared/page-layout.mjs +22 -0
  120. package/dist/plugins/blog/client/components/shared/page-wrapper.cjs +23 -0
  121. package/dist/plugins/blog/client/components/shared/page-wrapper.mjs +21 -0
  122. package/dist/plugins/blog/client/components/shared/post-card.cjs +279 -0
  123. package/dist/plugins/blog/client/components/shared/post-card.mjs +277 -0
  124. package/dist/plugins/blog/client/components/shared/post-navigation.cjs +74 -0
  125. package/dist/plugins/blog/client/components/shared/post-navigation.mjs +72 -0
  126. package/dist/plugins/blog/client/components/shared/posts-list.cjs +48 -0
  127. package/dist/plugins/blog/client/components/shared/posts-list.mjs +46 -0
  128. package/dist/plugins/blog/client/components/shared/recent-posts-carousel.cjs +59 -0
  129. package/dist/plugins/blog/client/components/shared/recent-posts-carousel.mjs +57 -0
  130. package/dist/plugins/blog/client/components/shared/search-input.cjs +136 -0
  131. package/dist/plugins/blog/client/components/shared/search-input.mjs +117 -0
  132. package/dist/plugins/blog/client/components/shared/search-modal.cjs +135 -0
  133. package/dist/plugins/blog/client/components/shared/search-modal.mjs +116 -0
  134. package/dist/plugins/blog/client/components/shared/tags-list.cjs +22 -0
  135. package/dist/plugins/blog/client/components/shared/tags-list.mjs +20 -0
  136. package/dist/plugins/blog/client/components/shared/use-route-lifecycle.cjs +50 -0
  137. package/dist/plugins/blog/client/components/shared/use-route-lifecycle.mjs +48 -0
  138. package/dist/plugins/blog/client/hooks/blog-hooks.cjs +380 -0
  139. package/dist/plugins/blog/client/hooks/blog-hooks.mjs +368 -0
  140. package/dist/plugins/blog/client/hooks/index.cjs +17 -0
  141. package/dist/plugins/blog/client/hooks/index.d.cts +150 -0
  142. package/dist/plugins/blog/client/hooks/index.d.mts +150 -0
  143. package/dist/plugins/blog/client/hooks/index.d.ts +150 -0
  144. package/dist/plugins/blog/client/hooks/index.mjs +1 -0
  145. package/dist/plugins/blog/client/hooks/use-debounce.cjs +16 -0
  146. package/dist/plugins/blog/client/hooks/use-debounce.mjs +14 -0
  147. package/dist/plugins/blog/client/index.cjs +7 -0
  148. package/dist/plugins/blog/client/index.d.cts +414 -0
  149. package/dist/plugins/blog/client/index.d.mts +414 -0
  150. package/dist/plugins/blog/client/index.d.ts +414 -0
  151. package/dist/plugins/blog/client/index.mjs +1 -0
  152. package/dist/plugins/blog/client/localization/blog-card.cjs +7 -0
  153. package/dist/plugins/blog/client/localization/blog-card.mjs +5 -0
  154. package/dist/plugins/blog/client/localization/blog-common.cjs +10 -0
  155. package/dist/plugins/blog/client/localization/blog-common.mjs +8 -0
  156. package/dist/plugins/blog/client/localization/blog-forms.cjs +40 -0
  157. package/dist/plugins/blog/client/localization/blog-forms.mjs +38 -0
  158. package/dist/plugins/blog/client/localization/blog-list.cjs +18 -0
  159. package/dist/plugins/blog/client/localization/blog-list.mjs +16 -0
  160. package/dist/plugins/blog/client/localization/blog-post.cjs +13 -0
  161. package/dist/plugins/blog/client/localization/blog-post.mjs +11 -0
  162. package/dist/plugins/blog/client/localization/index.cjs +17 -0
  163. package/dist/plugins/blog/client/localization/index.mjs +15 -0
  164. package/dist/plugins/blog/client/plugin.cjs +462 -0
  165. package/dist/plugins/blog/client/plugin.mjs +460 -0
  166. package/dist/plugins/blog/client.css +3 -0
  167. package/dist/plugins/blog/db.cjs +90 -0
  168. package/dist/plugins/blog/db.mjs +88 -0
  169. package/dist/plugins/blog/query-keys.cjs +181 -0
  170. package/dist/plugins/blog/query-keys.d.cts +530 -0
  171. package/dist/plugins/blog/query-keys.d.mts +530 -0
  172. package/dist/plugins/blog/query-keys.d.ts +530 -0
  173. package/dist/plugins/blog/query-keys.mjs +179 -0
  174. package/dist/plugins/blog/schemas.cjs +39 -0
  175. package/dist/plugins/blog/schemas.mjs +35 -0
  176. package/dist/plugins/blog/style.css +22 -0
  177. package/dist/plugins/blog/utils.cjs +97 -0
  178. package/dist/plugins/blog/utils.mjs +87 -0
  179. package/dist/plugins/client/index.cjs +15 -0
  180. package/dist/plugins/client/index.d.cts +57 -0
  181. package/dist/plugins/client/index.d.mts +57 -0
  182. package/dist/plugins/client/index.d.ts +57 -0
  183. package/dist/plugins/client/index.mjs +9 -0
  184. package/dist/{shared/stack.3OUyGp_E.mjs → plugins/utils.mjs} +1 -1
  185. package/dist/shared/{stack.DORw_1ps.d.cts → stack.ByOugz9d.d.cts} +17 -1
  186. package/dist/shared/{stack.DORw_1ps.d.mts → stack.ByOugz9d.d.mts} +17 -1
  187. package/dist/shared/{stack.DORw_1ps.d.ts → stack.ByOugz9d.d.ts} +17 -1
  188. package/dist/shared/stack.CoPoHVfV.d.cts +76 -0
  189. package/dist/shared/stack.CoPoHVfV.d.mts +76 -0
  190. package/dist/shared/stack.CoPoHVfV.d.ts +76 -0
  191. package/package.json +102 -14
  192. package/src/__tests__/plugins.test.tsx +539 -0
  193. package/src/__tests__/sitemap.test.ts +60 -0
  194. package/src/api/index.ts +75 -0
  195. package/src/client/components/compose.tsx +116 -0
  196. package/src/client/components/error-boundary.tsx +30 -0
  197. package/src/client/components/index.tsx +2 -0
  198. package/src/client/index.ts +109 -0
  199. package/src/client/meta-utils.ts +228 -0
  200. package/src/client/path-utils.ts +38 -0
  201. package/src/client/sitemap-utils.ts +46 -0
  202. package/src/context/index.ts +1 -0
  203. package/src/context/provider.tsx +157 -0
  204. package/src/index.ts +1 -0
  205. package/src/plugins/api/index.ts +50 -0
  206. package/src/plugins/blog/api/index.ts +2 -0
  207. package/src/plugins/blog/api/plugin.ts +759 -0
  208. package/src/plugins/blog/client/components/forms/image-field.tsx +165 -0
  209. package/src/plugins/blog/client/components/forms/markdown-editor-styles.css +30 -0
  210. package/src/plugins/blog/client/components/forms/markdown-editor.tsx +136 -0
  211. package/src/plugins/blog/client/components/forms/post-forms.tsx +531 -0
  212. package/src/plugins/blog/client/components/forms/tags-multiselect.tsx +79 -0
  213. package/src/plugins/blog/client/components/index.tsx +11 -0
  214. package/src/plugins/blog/client/components/loading/form-page-skeleton.tsx +75 -0
  215. package/src/plugins/blog/client/components/loading/index.tsx +27 -0
  216. package/src/plugins/blog/client/components/loading/list-page-skeleton.tsx +38 -0
  217. package/src/plugins/blog/client/components/loading/page-header-skeleton.tsx +10 -0
  218. package/src/plugins/blog/client/components/loading/post-card-skeleton.tsx +30 -0
  219. package/src/plugins/blog/client/components/loading/post-page-skeleton.tsx +75 -0
  220. package/src/plugins/blog/client/components/pages/404-page.tsx +23 -0
  221. package/src/plugins/blog/client/components/pages/edit-post-page.internal.tsx +60 -0
  222. package/src/plugins/blog/client/components/pages/edit-post-page.tsx +40 -0
  223. package/src/plugins/blog/client/components/pages/home-page.internal.tsx +71 -0
  224. package/src/plugins/blog/client/components/pages/home-page.tsx +42 -0
  225. package/src/plugins/blog/client/components/pages/new-post-page.internal.tsx +59 -0
  226. package/src/plugins/blog/client/components/pages/new-post-page.tsx +36 -0
  227. package/src/plugins/blog/client/components/pages/post-page.internal.tsx +142 -0
  228. package/src/plugins/blog/client/components/pages/post-page.tsx +38 -0
  229. package/src/plugins/blog/client/components/pages/tag-page.internal.tsx +74 -0
  230. package/src/plugins/blog/client/components/pages/tag-page.tsx +38 -0
  231. package/src/plugins/blog/client/components/shared/better-blog-attribution.tsx +19 -0
  232. package/src/plugins/blog/client/components/shared/default-error.tsx +20 -0
  233. package/src/plugins/blog/client/components/shared/defaults.tsx +9 -0
  234. package/src/plugins/blog/client/components/shared/empty-list.tsx +25 -0
  235. package/src/plugins/blog/client/components/shared/error-placeholder.tsx +20 -0
  236. package/src/plugins/blog/client/components/shared/highlight-text.tsx +80 -0
  237. package/src/plugins/blog/client/components/shared/markdown-content-styles.css +328 -0
  238. package/src/plugins/blog/client/components/shared/markdown-content.tsx +448 -0
  239. package/src/plugins/blog/client/components/shared/on-this-page.tsx +234 -0
  240. package/src/plugins/blog/client/components/shared/page-header.tsx +35 -0
  241. package/src/plugins/blog/client/components/shared/page-layout.tsx +23 -0
  242. package/src/plugins/blog/client/components/shared/page-wrapper.tsx +32 -0
  243. package/src/plugins/blog/client/components/shared/post-card.tsx +308 -0
  244. package/src/plugins/blog/client/components/shared/post-navigation.tsx +98 -0
  245. package/src/plugins/blog/client/components/shared/posts-list.tsx +67 -0
  246. package/src/plugins/blog/client/components/shared/recent-posts-carousel.tsx +79 -0
  247. package/src/plugins/blog/client/components/shared/search-input.tsx +146 -0
  248. package/src/plugins/blog/client/components/shared/search-modal.tsx +162 -0
  249. package/src/plugins/blog/client/components/shared/tags-list.tsx +34 -0
  250. package/src/plugins/blog/client/components/shared/use-route-lifecycle.tsx +68 -0
  251. package/src/plugins/blog/client/hooks/blog-hooks.tsx +623 -0
  252. package/src/plugins/blog/client/hooks/index.tsx +1 -0
  253. package/src/plugins/blog/client/hooks/use-debounce.ts +43 -0
  254. package/src/plugins/blog/client/index.ts +9 -0
  255. package/src/plugins/blog/client/localization/blog-card.ts +3 -0
  256. package/src/plugins/blog/client/localization/blog-common.ts +7 -0
  257. package/src/plugins/blog/client/localization/blog-forms.ts +45 -0
  258. package/src/plugins/blog/client/localization/blog-list.ts +14 -0
  259. package/src/plugins/blog/client/localization/blog-post.ts +9 -0
  260. package/src/plugins/blog/client/localization/index.ts +15 -0
  261. package/src/plugins/blog/client/overrides.ts +123 -0
  262. package/src/plugins/blog/client/plugin.tsx +672 -0
  263. package/src/plugins/blog/client.css +3 -0
  264. package/src/plugins/blog/db.ts +90 -0
  265. package/src/plugins/blog/query-keys.ts +267 -0
  266. package/src/plugins/blog/schemas.ts +39 -0
  267. package/src/plugins/blog/style.css +22 -0
  268. package/src/plugins/blog/types.ts +37 -0
  269. package/src/plugins/blog/utils.ts +144 -0
  270. package/src/plugins/client/index.ts +53 -0
  271. package/src/plugins/index.ts +0 -0
  272. package/src/plugins/utils.ts +35 -0
  273. package/src/types.ts +209 -0
  274. package/dist/plugins/index.cjs +0 -15
  275. package/dist/plugins/index.d.cts +0 -64
  276. package/dist/plugins/index.d.mts +0 -64
  277. package/dist/plugins/index.d.ts +0 -64
  278. package/dist/plugins/index.mjs +0 -11
  279. package/dist/shared/stack.DrUAVfIH.d.cts +0 -17
  280. package/dist/shared/stack.DrUAVfIH.d.mts +0 -17
  281. package/dist/shared/stack.DrUAVfIH.d.ts +0 -17
  282. /package/dist/{shared/stack.CktCg4PJ.cjs → plugins/utils.cjs} +0 -0
@@ -0,0 +1,146 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { usePostSearch } from "../../hooks/blog-hooks";
5
+ import { stripHtml, stripMarkdown } from "../../../utils";
6
+ import { HighlightText } from "./highlight-text";
7
+ import { SearchModal, type SearchResult } from "./search-modal";
8
+ import type { BlogPluginOverrides } from "../../overrides";
9
+ import { useBasePath, usePluginOverrides } from "@btst/stack/context";
10
+
11
+ // Simplified blog post search result interface
12
+ interface BlogPostSearchResult extends SearchResult {
13
+ slug: string;
14
+ publishedAt?: string | null;
15
+ authorName?: string;
16
+ processedContent: string;
17
+ processedExcerpt?: string;
18
+ }
19
+
20
+ interface SearchInputProps {
21
+ className?: string;
22
+ triggerClassName?: string;
23
+ placeholder?: string;
24
+ buttonText?: string;
25
+ emptyMessage?: string;
26
+ }
27
+
28
+ const renderBlogResult = (
29
+ item: BlogPostSearchResult,
30
+ index: number,
31
+ query: string,
32
+ ): React.ReactNode => {
33
+ const q = (query || "").toLowerCase();
34
+ const excerptMatches = item.processedExcerpt
35
+ ? item.processedExcerpt.toLowerCase().includes(q)
36
+ : false;
37
+ const contentMatches = item.processedContent
38
+ ? item.processedContent.toLowerCase().includes(q)
39
+ : false;
40
+
41
+ return (
42
+ <button
43
+ data-testid="search-result"
44
+ type="button"
45
+ key={item.id}
46
+ className="flex w-full cursor-pointer flex-col gap-2 rounded-sm border-border border-b px-4 py-3 text-left transition-colors hover:bg-accent"
47
+ onClick={() => item.onClick?.()}
48
+ >
49
+ <div className="flex items-start justify-between gap-2">
50
+ <HighlightText
51
+ text={item.title}
52
+ searchQuery={query}
53
+ className="flex-1 font-medium text-sm leading-5"
54
+ />
55
+ {item.publishedAt && (
56
+ <span className="whitespace-nowrap text-muted-foreground text-xs">
57
+ {new Date(item.publishedAt).toLocaleDateString()}
58
+ </span>
59
+ )}
60
+ </div>
61
+
62
+ {excerptMatches && (
63
+ <HighlightText
64
+ text={item.processedExcerpt || ""}
65
+ searchQuery={query}
66
+ className="text-muted-foreground text-xs leading-4"
67
+ maxLength={120}
68
+ />
69
+ )}
70
+ {contentMatches && (
71
+ <HighlightText
72
+ text={item.processedContent}
73
+ searchQuery={query}
74
+ className="text-muted-foreground text-xs leading-4"
75
+ maxLength={120}
76
+ />
77
+ )}
78
+ {!excerptMatches && !contentMatches && (
79
+ <HighlightText
80
+ text={item.processedExcerpt || item.processedContent}
81
+ searchQuery={query}
82
+ className="text-muted-foreground text-xs leading-4"
83
+ maxLength={120}
84
+ />
85
+ )}
86
+ </button>
87
+ );
88
+ };
89
+
90
+ export function SearchInput({
91
+ className,
92
+ triggerClassName,
93
+ placeholder,
94
+ buttonText,
95
+ emptyMessage,
96
+ }: SearchInputProps) {
97
+ const { navigate } = usePluginOverrides<BlogPluginOverrides>("blog");
98
+ const basePath = useBasePath();
99
+ const [currentQuery, setCurrentQuery] = React.useState("");
100
+
101
+ const { data: searchResults = [], isLoading } = usePostSearch({
102
+ query: currentQuery,
103
+ enabled: currentQuery.trim().length > 0,
104
+ debounceMs: 300,
105
+ published: true,
106
+ });
107
+
108
+ const formattedResults: BlogPostSearchResult[] = React.useMemo(() => {
109
+ return searchResults.map((post) => ({
110
+ id: post.id,
111
+ title: post.title,
112
+ slug: post.slug,
113
+ publishedAt: post.publishedAt,
114
+ authorName: "",
115
+ processedContent: stripMarkdown(stripHtml(post.content || "")),
116
+ processedExcerpt: stripMarkdown(stripHtml(post.excerpt || "")),
117
+ onClick: () => navigate(`${basePath}/blog/${post.slug}`),
118
+ }));
119
+ }, [searchResults, navigate, basePath]);
120
+
121
+ // Search function that updates our query state
122
+ const handleSearch = React.useCallback(
123
+ (query: string): BlogPostSearchResult[] => {
124
+ setCurrentQuery(query);
125
+ return []; // Return empty since we use external async results
126
+ },
127
+ [],
128
+ );
129
+
130
+ return (
131
+ <SearchModal<BlogPostSearchResult>
132
+ placeholder={placeholder}
133
+ buttonText={buttonText}
134
+ emptyMessage={emptyMessage}
135
+ searchFn={handleSearch}
136
+ renderResult={renderBlogResult}
137
+ results={formattedResults}
138
+ isLoading={isLoading}
139
+ className={className}
140
+ triggerClassName={triggerClassName}
141
+ keyboardShortcut="⌘K"
142
+ />
143
+ );
144
+ }
145
+
146
+ export default SearchInput;
@@ -0,0 +1,162 @@
1
+ "use client";
2
+
3
+ import { SearchIcon } from "lucide-react";
4
+ import * as React from "react";
5
+ import { useDebounce } from "../../hooks/use-debounce";
6
+
7
+ import {
8
+ CommandDialog,
9
+ CommandEmpty,
10
+ CommandInput,
11
+ CommandList,
12
+ } from "@workspace/ui/components/command";
13
+
14
+ export interface SearchResult {
15
+ id: string;
16
+ title: string;
17
+ subtitle?: string;
18
+ content?: string;
19
+ onClick?: () => void;
20
+ }
21
+
22
+ export interface SearchModalProps<T = SearchResult> {
23
+ placeholder?: string;
24
+ emptyMessage?: string;
25
+ buttonText?: string;
26
+ keyboardShortcut?: string;
27
+ searchFn: (query: string) => T[];
28
+ renderResult: (item: T, index: number, query: string) => React.ReactNode;
29
+ results?: T[];
30
+ isLoading?: boolean;
31
+ groupTitle?: string;
32
+ className?: string;
33
+ triggerClassName?: string;
34
+ }
35
+
36
+ export function SearchModal<T extends SearchResult>({
37
+ placeholder = "Type to search...",
38
+ emptyMessage = "No results found.",
39
+ buttonText = "Search",
40
+ keyboardShortcut = "⌘K",
41
+ searchFn,
42
+ renderResult,
43
+ results: externalResults,
44
+ isLoading = false,
45
+ className,
46
+ triggerClassName,
47
+ }: SearchModalProps<T>) {
48
+ const [open, setOpen] = React.useState(false);
49
+ const [query, setQuery] = React.useState("");
50
+ const [results, setResults] = React.useState<T[]>([]);
51
+
52
+ // Only debounce if not using external results
53
+ const shouldDebounce = externalResults === undefined;
54
+ const debouncedQuery = useDebounce(query, shouldDebounce ? 300 : 0);
55
+
56
+ // Handle keyboard shortcut
57
+ React.useEffect(() => {
58
+ const down = (e: KeyboardEvent) => {
59
+ const cleanShortcut = keyboardShortcut
60
+ .replace("⌘", "")
61
+ .replace("⇧", "")
62
+ .toLowerCase();
63
+ if (e.key === cleanShortcut && (e.metaKey || e.ctrlKey)) {
64
+ e.preventDefault();
65
+
66
+ setOpen((open) => !open);
67
+ }
68
+ };
69
+
70
+ document.addEventListener("keydown", down);
71
+ return () => document.removeEventListener("keydown", down);
72
+ }, [keyboardShortcut]);
73
+
74
+ React.useEffect(() => {
75
+ if (!open) {
76
+ setQuery("");
77
+ setResults([]);
78
+ return;
79
+ }
80
+ }, [open]);
81
+
82
+ React.useEffect(() => {
83
+ if (!open) return;
84
+
85
+ // Always call searchFn to notify parent component of the search query
86
+ const searchResults = searchFn(debouncedQuery);
87
+
88
+ // If external results are provided, use them; otherwise use searchFn results
89
+ if (externalResults !== undefined) {
90
+ setResults(externalResults);
91
+ } else {
92
+ setResults(searchResults);
93
+ }
94
+ }, [debouncedQuery, open, searchFn, externalResults]);
95
+
96
+ // Base button classes for better readability
97
+ const buttonClasses = [
98
+ "border-input bg-background text-foreground",
99
+ "placeholder:text-muted-foreground",
100
+ "focus-visible:border-ring focus-visible:ring-ring/50",
101
+ "inline-flex h-9 w-fit rounded-md border px-3 py-2 text-sm",
102
+ "shadow-xs transition-[color,box-shadow] outline-none",
103
+ "focus-visible:ring-[3px]",
104
+ triggerClassName,
105
+ ]
106
+ .filter(Boolean)
107
+ .join(" ");
108
+
109
+ // Determine what to show based on state
110
+ const showEmpty = debouncedQuery && !isLoading && results.length === 0;
111
+ const currentEmptyMessage = isLoading ? "Searching..." : emptyMessage;
112
+
113
+ return (
114
+ <>
115
+ <button
116
+ data-testid="search-button"
117
+ type="button"
118
+ className={buttonClasses}
119
+ onClick={() => setOpen(true)}
120
+ >
121
+ <span className="flex grow items-center">
122
+ <SearchIcon
123
+ className="-ms-1 me-3 text-muted-foreground"
124
+ size={16}
125
+ aria-hidden="true"
126
+ />
127
+ <span className="font-normal text-muted-foreground">
128
+ {buttonText}
129
+ </span>
130
+ </span>
131
+ {keyboardShortcut && (
132
+ <kbd className="-me-1 ms-12 inline-flex h-5 max-h-full items-center rounded border bg-background px-1 font-[inherit] font-medium text-[0.625rem] text-muted-foreground">
133
+ {keyboardShortcut}
134
+ </kbd>
135
+ )}
136
+ </button>
137
+ <CommandDialog
138
+ data-testid="search-modal"
139
+ open={open}
140
+ onOpenChange={setOpen}
141
+ className={className}
142
+ >
143
+ <CommandInput
144
+ data-testid="search-input"
145
+ placeholder={placeholder}
146
+ value={query}
147
+ onValueChange={setQuery}
148
+ />
149
+ <CommandList className="max-h-[400px]">
150
+ {showEmpty && <CommandEmpty>{currentEmptyMessage}</CommandEmpty>}
151
+
152
+ {results.length > 0 &&
153
+ results.map((item, index) =>
154
+ renderResult(item, index, debouncedQuery),
155
+ )}
156
+ </CommandList>
157
+ </CommandDialog>
158
+ </>
159
+ );
160
+ }
161
+
162
+ export default SearchModal;
@@ -0,0 +1,34 @@
1
+ "use client";
2
+
3
+ import { usePluginOverrides, useBasePath } from "@btst/stack/context";
4
+ import type { BlogPluginOverrides } from "../../overrides";
5
+ import { DefaultLink } from "./defaults";
6
+ import { Badge } from "@workspace/ui/components/badge";
7
+ import { useSuspenseTags } from "../../hooks/blog-hooks";
8
+
9
+ export function TagsList() {
10
+ const { tags } = useSuspenseTags();
11
+ const { Link } = usePluginOverrides<
12
+ BlogPluginOverrides,
13
+ Partial<BlogPluginOverrides>
14
+ >("blog", {
15
+ Link: DefaultLink,
16
+ });
17
+ const basePath = useBasePath();
18
+
19
+ if (!tags || tags.length === 0) {
20
+ return null;
21
+ }
22
+
23
+ return (
24
+ <div className="flex flex-wrap gap-2 justify-center">
25
+ {tags.map((tag) => (
26
+ <Link key={tag.id} href={`${basePath}/blog/tag/${tag.slug}`}>
27
+ <Badge variant="secondary" className="text-xs">
28
+ {tag.name}
29
+ </Badge>
30
+ </Link>
31
+ ))}
32
+ </div>
33
+ );
34
+ }
@@ -0,0 +1,68 @@
1
+ "use client";
2
+
3
+ import { useEffect } from "react";
4
+ import { usePluginOverrides } from "@btst/stack/context";
5
+ import type { BlogPluginOverrides, RouteContext } from "../../overrides";
6
+
7
+ /**
8
+ * Hook to handle route lifecycle events
9
+ * - Calls authorization check before render
10
+ * - Calls onRouteRender on mount
11
+ * - Handles errors with onRouteError
12
+ */
13
+ export function useRouteLifecycle({
14
+ routeName,
15
+ context,
16
+ beforeRenderHook,
17
+ }: {
18
+ routeName: string;
19
+ context: RouteContext;
20
+ beforeRenderHook?: (
21
+ overrides: BlogPluginOverrides,
22
+ context: RouteContext,
23
+ ) => boolean;
24
+ }) {
25
+ const overrides = usePluginOverrides<BlogPluginOverrides>("blog");
26
+
27
+ // Authorization check - runs synchronously before render
28
+ if (beforeRenderHook) {
29
+ const canRender = beforeRenderHook(overrides, context);
30
+ if (!canRender) {
31
+ const error = new Error(`Unauthorized: Cannot render ${routeName}`);
32
+ // Call error hook synchronously
33
+ if (overrides.onRouteError) {
34
+ try {
35
+ const result = overrides.onRouteError(routeName, error, context);
36
+ if (result instanceof Promise) {
37
+ result.catch(() => {}); // Ignore promise rejection
38
+ }
39
+ } catch {
40
+ // Ignore errors in error hook
41
+ }
42
+ }
43
+ throw error;
44
+ }
45
+ }
46
+
47
+ // Lifecycle hook - runs on mount
48
+ useEffect(() => {
49
+ if (overrides.onRouteRender) {
50
+ try {
51
+ const result = overrides.onRouteRender(routeName, context);
52
+ if (result instanceof Promise) {
53
+ result.catch((error) => {
54
+ // If onRouteRender throws, call onRouteError
55
+ if (overrides.onRouteError) {
56
+ overrides.onRouteError(routeName, error, context);
57
+ }
58
+ });
59
+ }
60
+ } catch (error) {
61
+ // If onRouteRender throws, call onRouteError
62
+ if (overrides.onRouteError) {
63
+ overrides.onRouteError(routeName, error as Error, context);
64
+ }
65
+ }
66
+ }
67
+ }, [routeName, overrides, context]);
68
+ }