@basicbenframework/cms 0.0.0-stage → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (590) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +206 -2
  3. package/db/migrations/001_create_users.js +15 -0
  4. package/db/migrations/002_create_posts.js +18 -0
  5. package/db/migrations/003_create_categories.js +19 -0
  6. package/db/migrations/004_create_tags.js +16 -0
  7. package/db/migrations/005_create_post_tags.js +16 -0
  8. package/db/migrations/006_create_pages.js +26 -0
  9. package/db/migrations/007_create_comments.js +24 -0
  10. package/db/migrations/008_create_media.js +22 -0
  11. package/db/migrations/009_update_posts_blogging.js +27 -0
  12. package/db/migrations/010_create_settings.js +29 -0
  13. package/db/migrations/011_add_user_roles.js +23 -0
  14. package/db/migrations/012_create_auth_tokens.js +30 -0
  15. package/db/migrations/013_add_email_verified.js +24 -0
  16. package/db/migrations/014_create_user_two_factor.js +30 -0
  17. package/db/migrations/015_create_user_credentials.js +35 -0
  18. package/db/migrations/016_create_rate_limits.js +31 -0
  19. package/db/migrations/017_add_content_html.js +38 -0
  20. package/db/migrations/018_create_api_tokens.js +34 -0
  21. package/db/migrations/019_create_post_categories.js +40 -0
  22. package/db/migrations/020_add_author_profiles.js +60 -0
  23. package/db/migrations/021_add_page_featured_image.js +23 -0
  24. package/db/migrations/022_backfill_post_slugs_and_excerpts.js +57 -0
  25. package/db/migrations/023_add_user_session_controls.js +25 -0
  26. package/db/migrations/024_add_post_status_and_trash.js +45 -0
  27. package/db/migrations/025_add_social_and_indexing_fields.js +40 -0
  28. package/db/migrations/026_create_post_revisions.js +29 -0
  29. package/db/migrations/027_add_media_dimensions.js +19 -0
  30. package/db/migrations/028_create_navigation_menus.js +65 -0
  31. package/db/migrations/029_create_redirects.js +40 -0
  32. package/db/migrations/030_add_comment_status_and_notifications.js +53 -0
  33. package/db/migrations/031_create_post_locks.js +38 -0
  34. package/db/migrations/032_create_snippets.js +31 -0
  35. package/db/migrations/033_create_members.js +70 -0
  36. package/db/migrations/034_add_post_visibility.js +28 -0
  37. package/db/migrations/035_create_newsletters.js +72 -0
  38. package/db/migrations/036_create_analytics.js +89 -0
  39. package/db/migrations/037_create_ops_heartbeats.js +30 -0
  40. package/db/migrations/038_create_content_types.js +84 -0
  41. package/db/migrations/039_create_content_type_fields.js +47 -0
  42. package/db/migrations/040_create_taxonomies.js +80 -0
  43. package/db/migrations/041_add_newsletter_handoff.js +28 -0
  44. package/db/migrations/042_create_mysendbox_contacts.js +63 -0
  45. package/lib/cli/backup.d.mts +2 -0
  46. package/lib/cli/backup.mjs +124 -0
  47. package/lib/cli/export.d.mts +2 -0
  48. package/lib/cli/export.mjs +54 -0
  49. package/lib/cli/import-ghost.d.mts +2 -0
  50. package/lib/cli/import-ghost.mjs +50 -0
  51. package/lib/cli/import-json.d.mts +2 -0
  52. package/lib/cli/import-json.mjs +61 -0
  53. package/lib/cli/import-wordpress.d.mts +2 -0
  54. package/lib/cli/import-wordpress.mjs +169 -0
  55. package/lib/cli/import-wxr.d.mts +2 -0
  56. package/lib/cli/import-wxr.mjs +55 -0
  57. package/lib/cli/index.d.mts +2 -0
  58. package/lib/cli/index.mjs +53 -0
  59. package/lib/cli/lib/backup.d.mts +112 -0
  60. package/lib/cli/lib/backup.mjs +297 -0
  61. package/lib/cli/lib/ghost.d.mts +30 -0
  62. package/lib/cli/lib/ghost.mjs +201 -0
  63. package/lib/cli/lib/html-to-markdown.d.mts +61 -0
  64. package/lib/cli/lib/html-to-markdown.mjs +523 -0
  65. package/lib/cli/lib/import-common.d.mts +100 -0
  66. package/lib/cli/lib/import-common.mjs +252 -0
  67. package/lib/cli/lib/json-import.d.mts +22 -0
  68. package/lib/cli/lib/json-import.mjs +422 -0
  69. package/lib/cli/lib/site-import.d.mts +32 -0
  70. package/lib/cli/lib/site-import.mjs +456 -0
  71. package/lib/cli/lib/wordpress-rest.d.mts +25 -0
  72. package/lib/cli/lib/wordpress-rest.mjs +177 -0
  73. package/lib/cli/lib/wxr.d.mts +18 -0
  74. package/lib/cli/lib/wxr.mjs +307 -0
  75. package/lib/cli/lib/xml.d.mts +33 -0
  76. package/lib/cli/lib/xml.mjs +186 -0
  77. package/lib/cli/restore.d.mts +2 -0
  78. package/lib/cli/restore.mjs +98 -0
  79. package/lib/client/components/Alert.d.ts +7 -0
  80. package/lib/client/components/Alert.js +8 -0
  81. package/lib/client/components/Avatar.d.ts +15 -0
  82. package/lib/client/components/Avatar.js +10 -0
  83. package/lib/client/components/BackLink.d.ts +7 -0
  84. package/lib/client/components/BackLink.js +6 -0
  85. package/lib/client/components/Button.d.ts +7 -0
  86. package/lib/client/components/Button.js +12 -0
  87. package/lib/client/components/Card.d.ts +7 -0
  88. package/lib/client/components/Card.js +6 -0
  89. package/lib/client/components/CommentThread.d.ts +15 -0
  90. package/lib/client/components/CommentThread.js +101 -0
  91. package/lib/client/components/Empty.d.ts +6 -0
  92. package/lib/client/components/Empty.js +6 -0
  93. package/lib/client/components/Input.d.ts +6 -0
  94. package/lib/client/components/Input.js +6 -0
  95. package/lib/client/components/Link.d.ts +31 -0
  96. package/lib/client/components/Link.js +49 -0
  97. package/lib/client/components/Loading.d.ts +1 -0
  98. package/lib/client/components/Loading.js +6 -0
  99. package/lib/client/components/Logo.d.ts +5 -0
  100. package/lib/client/components/Logo.js +4 -0
  101. package/lib/client/components/MarkdownEditor.d.ts +41 -0
  102. package/lib/client/components/MarkdownEditor.js +156 -0
  103. package/lib/client/components/Nav/DarkModeToggle.d.ts +6 -0
  104. package/lib/client/components/Nav/DarkModeToggle.js +6 -0
  105. package/lib/client/components/Nav/DesktopNav.d.ts +8 -0
  106. package/lib/client/components/Nav/DesktopNav.js +9 -0
  107. package/lib/client/components/Nav/MobileNav.d.ts +9 -0
  108. package/lib/client/components/Nav/MobileNav.js +15 -0
  109. package/lib/client/components/NavLink.d.ts +8 -0
  110. package/lib/client/components/NavLink.js +6 -0
  111. package/lib/client/components/PageHeader.d.ts +8 -0
  112. package/lib/client/components/PageHeader.js +6 -0
  113. package/lib/client/components/PostCard.d.ts +8 -0
  114. package/lib/client/components/PostCard.js +7 -0
  115. package/lib/client/components/Textarea.d.ts +6 -0
  116. package/lib/client/components/Textarea.js +6 -0
  117. package/lib/client/components/ThemeContext.d.ts +18 -0
  118. package/lib/client/components/ThemeContext.js +8 -0
  119. package/lib/client/components/admin/AdminIcons.d.ts +13 -0
  120. package/lib/client/components/admin/AdminIcons.js +66 -0
  121. package/lib/client/components/admin/ContentModelPanels.d.ts +22 -0
  122. package/lib/client/components/admin/ContentModelPanels.js +93 -0
  123. package/lib/client/components/admin/FeaturedImageBox.d.ts +21 -0
  124. package/lib/client/components/admin/FeaturedImageBox.js +24 -0
  125. package/lib/client/components/admin/MediaGrid.d.ts +23 -0
  126. package/lib/client/components/admin/MediaGrid.js +69 -0
  127. package/lib/client/components/admin/MediaPicker.d.ts +17 -0
  128. package/lib/client/components/admin/MediaPicker.js +61 -0
  129. package/lib/client/components/admin/Pagination.d.ts +27 -0
  130. package/lib/client/components/admin/Pagination.js +29 -0
  131. package/lib/client/components/admin/SnippetPicker.d.ts +27 -0
  132. package/lib/client/components/admin/SnippetPicker.js +65 -0
  133. package/lib/client/components/admin/TermPicker.d.ts +52 -0
  134. package/lib/client/components/admin/TermPicker.js +58 -0
  135. package/lib/client/contexts/ToastContext.d.ts +12 -0
  136. package/lib/client/contexts/ToastContext.js +49 -0
  137. package/lib/client/features.d.ts +11 -0
  138. package/lib/client/features.js +7 -0
  139. package/lib/client/hooks/useContentTypes.d.ts +48 -0
  140. package/lib/client/hooks/useContentTypes.js +48 -0
  141. package/lib/client/hooks/useMediaLibrary.d.ts +46 -0
  142. package/lib/client/hooks/useMediaLibrary.js +189 -0
  143. package/lib/client/hooks/usePostLock.d.ts +32 -0
  144. package/lib/client/hooks/usePostLock.js +107 -0
  145. package/lib/client/host/index.d.ts +71 -0
  146. package/lib/client/host/index.js +58 -0
  147. package/lib/client/i18n/index.d.ts +79 -0
  148. package/lib/client/i18n/index.js +177 -0
  149. package/lib/client/i18n/locales/es/content.d.ts +4 -0
  150. package/lib/client/i18n/locales/es/content.js +220 -0
  151. package/lib/client/i18n/locales/es/editor.d.ts +9 -0
  152. package/lib/client/i18n/locales/es/editor.js +144 -0
  153. package/lib/client/i18n/locales/es/index.d.ts +8 -0
  154. package/lib/client/i18n/locales/es/index.js +7 -0
  155. package/lib/client/i18n/locales/es/layout.d.ts +4 -0
  156. package/lib/client/i18n/locales/es/layout.js +35 -0
  157. package/lib/client/i18n/locales/es/people.d.ts +4 -0
  158. package/lib/client/i18n/locales/es/people.js +187 -0
  159. package/lib/client/i18n/locales/es/site.d.ts +4 -0
  160. package/lib/client/i18n/locales/es/site.js +208 -0
  161. package/lib/client/layouts/AdminLayout.d.ts +7 -0
  162. package/lib/client/layouts/AdminLayout.js +1046 -0
  163. package/lib/client/layouts/AppLayout.d.ts +6 -0
  164. package/lib/client/layouts/AppLayout.js +19 -0
  165. package/lib/client/layouts/AuthLayout.d.ts +6 -0
  166. package/lib/client/layouts/AuthLayout.js +14 -0
  167. package/lib/client/layouts/DocsLayout.d.ts +6 -0
  168. package/lib/client/layouts/DocsLayout.js +28 -0
  169. package/lib/client/layouts/RootLayout.d.ts +6 -0
  170. package/lib/client/layouts/RootLayout.js +11 -0
  171. package/lib/client/pages/AcceptInvite.d.ts +8 -0
  172. package/lib/client/pages/AcceptInvite.js +60 -0
  173. package/lib/client/pages/Auth.d.ts +1 -0
  174. package/lib/client/pages/Auth.js +40 -0
  175. package/lib/client/pages/Authentication.d.ts +1 -0
  176. package/lib/client/pages/Authentication.js +230 -0
  177. package/lib/client/pages/Content.d.ts +1 -0
  178. package/lib/client/pages/Content.js +21 -0
  179. package/lib/client/pages/Database.d.ts +1 -0
  180. package/lib/client/pages/Database.js +264 -0
  181. package/lib/client/pages/Extending.d.ts +1 -0
  182. package/lib/client/pages/Extending.js +28 -0
  183. package/lib/client/pages/Feed.d.ts +1 -0
  184. package/lib/client/pages/Feed.js +19 -0
  185. package/lib/client/pages/FeedPost.d.ts +1 -0
  186. package/lib/client/pages/FeedPost.js +31 -0
  187. package/lib/client/pages/ForgotPassword.d.ts +8 -0
  188. package/lib/client/pages/ForgotPassword.js +38 -0
  189. package/lib/client/pages/GettingStarted.d.ts +1 -0
  190. package/lib/client/pages/GettingStarted.js +84 -0
  191. package/lib/client/pages/Headless.d.ts +1 -0
  192. package/lib/client/pages/Headless.js +49 -0
  193. package/lib/client/pages/Home.d.ts +1 -0
  194. package/lib/client/pages/Home.js +67 -0
  195. package/lib/client/pages/PostForm.d.ts +1 -0
  196. package/lib/client/pages/PostForm.js +55 -0
  197. package/lib/client/pages/Posts.d.ts +1 -0
  198. package/lib/client/pages/Posts.js +35 -0
  199. package/lib/client/pages/Profile.d.ts +1 -0
  200. package/lib/client/pages/Profile.js +153 -0
  201. package/lib/client/pages/ResetPassword.d.ts +8 -0
  202. package/lib/client/pages/ResetPassword.js +52 -0
  203. package/lib/client/pages/Routing.d.ts +1 -0
  204. package/lib/client/pages/Routing.js +192 -0
  205. package/lib/client/pages/Storage.d.ts +1 -0
  206. package/lib/client/pages/Storage.js +54 -0
  207. package/lib/client/pages/Testing.d.ts +1 -0
  208. package/lib/client/pages/Testing.js +141 -0
  209. package/lib/client/pages/Validation.d.ts +1 -0
  210. package/lib/client/pages/Validation.js +123 -0
  211. package/lib/client/pages/admin/Categories.d.ts +2 -0
  212. package/lib/client/pages/admin/Categories.js +75 -0
  213. package/lib/client/pages/admin/Comments.d.ts +11 -0
  214. package/lib/client/pages/admin/Comments.js +247 -0
  215. package/lib/client/pages/admin/ContentTypes.d.ts +2 -0
  216. package/lib/client/pages/admin/ContentTypes.js +163 -0
  217. package/lib/client/pages/admin/Dashboard.d.ts +2 -0
  218. package/lib/client/pages/admin/Dashboard.js +66 -0
  219. package/lib/client/pages/admin/Health.d.ts +12 -0
  220. package/lib/client/pages/admin/Health.js +148 -0
  221. package/lib/client/pages/admin/Media.d.ts +2 -0
  222. package/lib/client/pages/admin/Media.js +101 -0
  223. package/lib/client/pages/admin/Navigation.d.ts +9 -0
  224. package/lib/client/pages/admin/Navigation.js +230 -0
  225. package/lib/client/pages/admin/Pages.d.ts +2 -0
  226. package/lib/client/pages/admin/Pages.js +53 -0
  227. package/lib/client/pages/admin/PostEditor.d.ts +17 -0
  228. package/lib/client/pages/admin/PostEditor.js +532 -0
  229. package/lib/client/pages/admin/Posts.d.ts +2 -0
  230. package/lib/client/pages/admin/Posts.js +152 -0
  231. package/lib/client/pages/admin/Redirects.d.ts +10 -0
  232. package/lib/client/pages/admin/Redirects.js +87 -0
  233. package/lib/client/pages/admin/Settings.d.ts +2 -0
  234. package/lib/client/pages/admin/Settings.js +111 -0
  235. package/lib/client/pages/admin/Snippets.d.ts +14 -0
  236. package/lib/client/pages/admin/Snippets.js +85 -0
  237. package/lib/client/pages/admin/Tags.d.ts +2 -0
  238. package/lib/client/pages/admin/Tags.js +74 -0
  239. package/lib/client/pages/admin/Taxonomies.d.ts +2 -0
  240. package/lib/client/pages/admin/Taxonomies.js +130 -0
  241. package/lib/client/pages/admin/Tokens.d.ts +9 -0
  242. package/lib/client/pages/admin/Tokens.js +260 -0
  243. package/lib/client/pages/admin/Tools.d.ts +12 -0
  244. package/lib/client/pages/admin/Tools.js +111 -0
  245. package/lib/client/pages/admin/Users.d.ts +13 -0
  246. package/lib/client/pages/admin/Users.js +313 -0
  247. package/lib/client/pages/api-reference.d.ts +33 -0
  248. package/lib/client/pages/api-reference.js +198 -0
  249. package/lib/client/styles.css +37 -0
  250. package/lib/config.d.ts +24 -0
  251. package/lib/config.js +39 -0
  252. package/lib/controllers/AdminController.d.ts +46 -0
  253. package/lib/controllers/AdminController.js +134 -0
  254. package/lib/controllers/AuthController.d.ts +15 -0
  255. package/lib/controllers/AuthController.js +194 -0
  256. package/lib/controllers/AuthorController.d.ts +17 -0
  257. package/lib/controllers/AuthorController.js +19 -0
  258. package/lib/controllers/CategoryController.d.ts +10 -0
  259. package/lib/controllers/CategoryController.js +88 -0
  260. package/lib/controllers/CommentController.d.ts +68 -0
  261. package/lib/controllers/CommentController.js +438 -0
  262. package/lib/controllers/ContentTypeController.d.ts +24 -0
  263. package/lib/controllers/ContentTypeController.js +91 -0
  264. package/lib/controllers/EmailVerificationController.d.ts +33 -0
  265. package/lib/controllers/EmailVerificationController.js +116 -0
  266. package/lib/controllers/ExportController.d.ts +15 -0
  267. package/lib/controllers/ExportController.js +41 -0
  268. package/lib/controllers/FeedController.d.ts +14 -0
  269. package/lib/controllers/FeedController.js +246 -0
  270. package/lib/controllers/HealthController.d.ts +21 -0
  271. package/lib/controllers/HealthController.js +176 -0
  272. package/lib/controllers/HomeController.d.ts +12 -0
  273. package/lib/controllers/HomeController.js +16 -0
  274. package/lib/controllers/MediaController.d.ts +24 -0
  275. package/lib/controllers/MediaController.js +189 -0
  276. package/lib/controllers/NavigationController.d.ts +22 -0
  277. package/lib/controllers/NavigationController.js +176 -0
  278. package/lib/controllers/PageController.d.ts +13 -0
  279. package/lib/controllers/PageController.js +172 -0
  280. package/lib/controllers/PasskeyController.d.ts +36 -0
  281. package/lib/controllers/PasskeyController.js +201 -0
  282. package/lib/controllers/PasswordResetController.d.ts +44 -0
  283. package/lib/controllers/PasswordResetController.js +160 -0
  284. package/lib/controllers/PostController.d.ts +51 -0
  285. package/lib/controllers/PostController.js +538 -0
  286. package/lib/controllers/PostLockController.d.ts +62 -0
  287. package/lib/controllers/PostLockController.js +101 -0
  288. package/lib/controllers/ProfileController.d.ts +13 -0
  289. package/lib/controllers/ProfileController.js +160 -0
  290. package/lib/controllers/PublicApiController.d.ts +23 -0
  291. package/lib/controllers/PublicApiController.js +100 -0
  292. package/lib/controllers/RedirectController.d.ts +32 -0
  293. package/lib/controllers/RedirectController.js +95 -0
  294. package/lib/controllers/SettingsController.d.ts +28 -0
  295. package/lib/controllers/SettingsController.js +105 -0
  296. package/lib/controllers/SnippetController.d.ts +27 -0
  297. package/lib/controllers/SnippetController.js +123 -0
  298. package/lib/controllers/TagController.d.ts +9 -0
  299. package/lib/controllers/TagController.js +70 -0
  300. package/lib/controllers/TaxonomyController.d.ts +24 -0
  301. package/lib/controllers/TaxonomyController.js +149 -0
  302. package/lib/controllers/TokenController.d.ts +27 -0
  303. package/lib/controllers/TokenController.js +83 -0
  304. package/lib/controllers/TwoFactorController.d.ts +31 -0
  305. package/lib/controllers/TwoFactorController.js +213 -0
  306. package/lib/controllers/UserController.d.ts +110 -0
  307. package/lib/controllers/UserController.js +504 -0
  308. package/lib/features/analytics/AnalyticsPage.d.ts +11 -0
  309. package/lib/features/analytics/AnalyticsPage.js +123 -0
  310. package/lib/features/analytics/admin.d.ts +3 -0
  311. package/lib/features/analytics/admin.js +9 -0
  312. package/lib/features/analytics/controller.d.ts +19 -0
  313. package/lib/features/analytics/controller.js +79 -0
  314. package/lib/features/analytics/helpers.d.ts +84 -0
  315. package/lib/features/analytics/helpers.js +181 -0
  316. package/lib/features/analytics/i18n/es.d.ts +4 -0
  317. package/lib/features/analytics/i18n/es.js +31 -0
  318. package/lib/features/analytics/index.d.ts +28 -0
  319. package/lib/features/analytics/index.js +91 -0
  320. package/lib/features/analytics/manifest.d.ts +8 -0
  321. package/lib/features/analytics/manifest.js +18 -0
  322. package/lib/features/analytics/model.d.ts +130 -0
  323. package/lib/features/analytics/model.js +206 -0
  324. package/lib/features/members/Member.d.ts +93 -0
  325. package/lib/features/members/Member.js +194 -0
  326. package/lib/features/members/MemberAdminController.d.ts +60 -0
  327. package/lib/features/members/MemberAdminController.js +262 -0
  328. package/lib/features/members/MemberController.d.ts +88 -0
  329. package/lib/features/members/MemberController.js +250 -0
  330. package/lib/features/members/MembersPage.d.ts +10 -0
  331. package/lib/features/members/MembersPage.js +216 -0
  332. package/lib/features/members/PostAccessBox.d.ts +15 -0
  333. package/lib/features/members/PostAccessBox.js +70 -0
  334. package/lib/features/members/admin.d.ts +3 -0
  335. package/lib/features/members/admin.js +12 -0
  336. package/lib/features/members/csv.d.ts +21 -0
  337. package/lib/features/members/csv.js +74 -0
  338. package/lib/features/members/events.d.ts +34 -0
  339. package/lib/features/members/events.js +34 -0
  340. package/lib/features/members/i18n/es.d.ts +4 -0
  341. package/lib/features/members/i18n/es.js +106 -0
  342. package/lib/features/members/index.d.ts +44 -0
  343. package/lib/features/members/index.js +106 -0
  344. package/lib/features/members/manifest.d.ts +8 -0
  345. package/lib/features/members/manifest.js +18 -0
  346. package/lib/features/members/middleware.d.ts +42 -0
  347. package/lib/features/members/middleware.js +74 -0
  348. package/lib/features/members/newsletter.d.ts +177 -0
  349. package/lib/features/members/newsletter.js +439 -0
  350. package/lib/features/members/rate-limits.d.ts +34 -0
  351. package/lib/features/members/rate-limits.js +50 -0
  352. package/lib/features/members/request.d.ts +13 -0
  353. package/lib/features/members/request.js +6 -0
  354. package/lib/features/members/routes.d.ts +15 -0
  355. package/lib/features/members/routes.js +59 -0
  356. package/lib/features/members/session.d.ts +102 -0
  357. package/lib/features/members/session.js +158 -0
  358. package/lib/features/members/settings.d.ts +14 -0
  359. package/lib/features/members/settings.js +23 -0
  360. package/lib/features/mysendbox/MySendboxSettingsCard.d.ts +7 -0
  361. package/lib/features/mysendbox/MySendboxSettingsCard.js +48 -0
  362. package/lib/features/mysendbox/admin.d.ts +3 -0
  363. package/lib/features/mysendbox/admin.js +9 -0
  364. package/lib/features/mysendbox/broadcasts.d.ts +61 -0
  365. package/lib/features/mysendbox/broadcasts.js +124 -0
  366. package/lib/features/mysendbox/client.d.ts +95 -0
  367. package/lib/features/mysendbox/client.js +61 -0
  368. package/lib/features/mysendbox/config.d.ts +27 -0
  369. package/lib/features/mysendbox/config.js +74 -0
  370. package/lib/features/mysendbox/contacts.d.ts +121 -0
  371. package/lib/features/mysendbox/contacts.js +378 -0
  372. package/lib/features/mysendbox/controller.d.ts +11 -0
  373. package/lib/features/mysendbox/controller.js +47 -0
  374. package/lib/features/mysendbox/i18n/es.d.ts +4 -0
  375. package/lib/features/mysendbox/i18n/es.js +28 -0
  376. package/lib/features/mysendbox/index.d.ts +18 -0
  377. package/lib/features/mysendbox/index.js +71 -0
  378. package/lib/features/mysendbox/manifest.d.ts +7 -0
  379. package/lib/features/mysendbox/manifest.js +6 -0
  380. package/lib/features/mysendbox/routes.d.ts +6 -0
  381. package/lib/features/mysendbox/routes.js +14 -0
  382. package/lib/features/mysendbox/webhook.d.ts +23 -0
  383. package/lib/features/mysendbox/webhook.js +104 -0
  384. package/lib/features/theme/OEmbedController.d.ts +31 -0
  385. package/lib/features/theme/OEmbedController.js +128 -0
  386. package/lib/features/theme/ThemeController.d.ts +20 -0
  387. package/lib/features/theme/ThemeController.js +256 -0
  388. package/lib/features/theme/ThemeSettingsCard.d.ts +7 -0
  389. package/lib/features/theme/ThemeSettingsCard.js +12 -0
  390. package/lib/features/theme/admin.d.ts +3 -0
  391. package/lib/features/theme/admin.js +9 -0
  392. package/lib/features/theme/html.d.ts +48 -0
  393. package/lib/features/theme/html.js +97 -0
  394. package/lib/features/theme/i18n/es.d.ts +4 -0
  395. package/lib/features/theme/i18n/es.js +9 -0
  396. package/lib/features/theme/index.d.ts +11 -0
  397. package/lib/features/theme/index.js +23 -0
  398. package/lib/features/theme/manifest.d.ts +7 -0
  399. package/lib/features/theme/manifest.js +6 -0
  400. package/lib/features/theme/oembed.d.ts +36 -0
  401. package/lib/features/theme/oembed.js +58 -0
  402. package/lib/features/theme/routes.d.ts +17 -0
  403. package/lib/features/theme/routes.js +54 -0
  404. package/lib/features/theme/templates.d.ts +103 -0
  405. package/lib/features/theme/templates.js +283 -0
  406. package/lib/features.d.ts +15 -0
  407. package/lib/features.js +6 -0
  408. package/lib/features.manifest.d.ts +10 -0
  409. package/lib/features.manifest.js +6 -0
  410. package/lib/helpers/access.d.ts +62 -0
  411. package/lib/helpers/access.js +92 -0
  412. package/lib/helpers/api.d.ts +20 -0
  413. package/lib/helpers/api.js +44 -0
  414. package/lib/helpers/comment-guard.d.ts +145 -0
  415. package/lib/helpers/comment-guard.js +253 -0
  416. package/lib/helpers/comment-mail.d.ts +53 -0
  417. package/lib/helpers/comment-mail.js +188 -0
  418. package/lib/helpers/content-model.d.ts +50 -0
  419. package/lib/helpers/content-model.js +84 -0
  420. package/lib/helpers/content-paths.d.ts +107 -0
  421. package/lib/helpers/content-paths.js +200 -0
  422. package/lib/helpers/export-data.d.ts +85 -0
  423. package/lib/helpers/export-data.js +229 -0
  424. package/lib/helpers/gating.d.ts +53 -0
  425. package/lib/helpers/gating.js +83 -0
  426. package/lib/helpers/health.d.ts +91 -0
  427. package/lib/helpers/health.js +279 -0
  428. package/lib/helpers/heartbeat.d.ts +35 -0
  429. package/lib/helpers/heartbeat.js +55 -0
  430. package/lib/helpers/image-size.d.ts +18 -0
  431. package/lib/helpers/image-size.js +83 -0
  432. package/lib/helpers/images.d.ts +29 -0
  433. package/lib/helpers/images.js +41 -0
  434. package/lib/helpers/mail-templates.d.ts +11 -0
  435. package/lib/helpers/mail-templates.js +42 -0
  436. package/lib/helpers/publish-due.d.ts +28 -0
  437. package/lib/helpers/publish-due.js +67 -0
  438. package/lib/helpers/redirects.d.ts +43 -0
  439. package/lib/helpers/redirects.js +80 -0
  440. package/lib/helpers/seo-fields.d.ts +13 -0
  441. package/lib/helpers/seo-fields.js +52 -0
  442. package/lib/helpers/session.d.ts +30 -0
  443. package/lib/helpers/session.js +27 -0
  444. package/lib/helpers/site-settings.d.ts +98 -0
  445. package/lib/helpers/site-settings.js +232 -0
  446. package/lib/helpers/site.d.ts +14 -0
  447. package/lib/helpers/site.js +23 -0
  448. package/lib/helpers/write-hooks.d.ts +33 -0
  449. package/lib/helpers/write-hooks.js +37 -0
  450. package/lib/hooks.d.ts +17 -0
  451. package/lib/hooks.js +101 -0
  452. package/lib/host/core-tasks.d.ts +4 -0
  453. package/lib/host/core-tasks.js +26 -0
  454. package/lib/host/cron.d.ts +39 -0
  455. package/lib/host/cron.js +85 -0
  456. package/lib/host/enabled.d.ts +4 -0
  457. package/lib/host/enabled.js +40 -0
  458. package/lib/host/index.d.ts +81 -0
  459. package/lib/host/index.js +87 -0
  460. package/lib/host/manifest.d.ts +34 -0
  461. package/lib/host/manifest.js +7 -0
  462. package/lib/host/menu.d.ts +18 -0
  463. package/lib/host/menu.js +15 -0
  464. package/lib/main.d.ts +1 -0
  465. package/lib/main.js +24 -0
  466. package/lib/middleware/api-auth.d.ts +59 -0
  467. package/lib/middleware/api-auth.js +164 -0
  468. package/lib/middleware/auth.d.ts +49 -0
  469. package/lib/middleware/auth.js +112 -0
  470. package/lib/middleware/cache.d.ts +17 -0
  471. package/lib/middleware/cache.js +52 -0
  472. package/lib/middleware/rate-limits.d.ts +199 -0
  473. package/lib/middleware/rate-limits.js +276 -0
  474. package/lib/middleware/viewer.d.ts +13 -0
  475. package/lib/middleware/viewer.js +16 -0
  476. package/lib/models/Category.d.ts +24 -0
  477. package/lib/models/Category.js +102 -0
  478. package/lib/models/Comment.d.ts +120 -0
  479. package/lib/models/Comment.js +283 -0
  480. package/lib/models/ContentType.d.ts +142 -0
  481. package/lib/models/ContentType.js +462 -0
  482. package/lib/models/Credential.d.ts +21 -0
  483. package/lib/models/Credential.js +31 -0
  484. package/lib/models/Media.d.ts +53 -0
  485. package/lib/models/Media.js +132 -0
  486. package/lib/models/Menu.d.ts +131 -0
  487. package/lib/models/Menu.js +312 -0
  488. package/lib/models/Page.d.ts +55 -0
  489. package/lib/models/Page.js +218 -0
  490. package/lib/models/Post.d.ts +136 -0
  491. package/lib/models/Post.js +406 -0
  492. package/lib/models/PostLock.d.ts +67 -0
  493. package/lib/models/PostLock.js +112 -0
  494. package/lib/models/PostRevision.d.ts +45 -0
  495. package/lib/models/PostRevision.js +82 -0
  496. package/lib/models/PublicContent.d.ts +283 -0
  497. package/lib/models/PublicContent.js +577 -0
  498. package/lib/models/Redirect.d.ts +123 -0
  499. package/lib/models/Redirect.js +225 -0
  500. package/lib/models/Settings.d.ts +61 -0
  501. package/lib/models/Settings.js +128 -0
  502. package/lib/models/Snippet.d.ts +36 -0
  503. package/lib/models/Snippet.js +64 -0
  504. package/lib/models/Tag.d.ts +23 -0
  505. package/lib/models/Tag.js +117 -0
  506. package/lib/models/Taxonomy.d.ts +127 -0
  507. package/lib/models/Taxonomy.js +321 -0
  508. package/lib/models/TwoFactor.d.ts +26 -0
  509. package/lib/models/TwoFactor.js +60 -0
  510. package/lib/models/User.d.ts +49 -0
  511. package/lib/models/User.js +128 -0
  512. package/lib/models/derive.d.ts +69 -0
  513. package/lib/models/derive.js +81 -0
  514. package/lib/models/pagination.d.ts +30 -0
  515. package/lib/models/pagination.js +36 -0
  516. package/lib/models/visibility.d.ts +31 -0
  517. package/lib/models/visibility.js +47 -0
  518. package/lib/routes/App.d.ts +2 -0
  519. package/lib/routes/App.js +146 -0
  520. package/lib/routes/api/admin.d.ts +6 -0
  521. package/lib/routes/api/admin.js +11 -0
  522. package/lib/routes/api/auth.d.ts +6 -0
  523. package/lib/routes/api/auth.js +24 -0
  524. package/lib/routes/api/authors.d.ts +5 -0
  525. package/lib/routes/api/authors.js +8 -0
  526. package/lib/routes/api/categories.d.ts +8 -0
  527. package/lib/routes/api/categories.js +15 -0
  528. package/lib/routes/api/comments.d.ts +8 -0
  529. package/lib/routes/api/comments.js +35 -0
  530. package/lib/routes/api/content-model.d.ts +17 -0
  531. package/lib/routes/api/content-model.js +67 -0
  532. package/lib/routes/api/cron.d.ts +6 -0
  533. package/lib/routes/api/cron.js +9 -0
  534. package/lib/routes/api/export.d.ts +5 -0
  535. package/lib/routes/api/export.js +11 -0
  536. package/lib/routes/api/feed.d.ts +5 -0
  537. package/lib/routes/api/feed.js +16 -0
  538. package/lib/routes/api/media.d.ts +8 -0
  539. package/lib/routes/api/media.js +25 -0
  540. package/lib/routes/api/navigation.d.ts +12 -0
  541. package/lib/routes/api/navigation.js +17 -0
  542. package/lib/routes/api/ops.d.ts +9 -0
  543. package/lib/routes/api/ops.js +19 -0
  544. package/lib/routes/api/pages.d.ts +8 -0
  545. package/lib/routes/api/pages.js +21 -0
  546. package/lib/routes/api/passkeys.d.ts +7 -0
  547. package/lib/routes/api/passkeys.js +13 -0
  548. package/lib/routes/api/posts.d.ts +8 -0
  549. package/lib/routes/api/posts.js +39 -0
  550. package/lib/routes/api/profile.d.ts +6 -0
  551. package/lib/routes/api/profile.js +8 -0
  552. package/lib/routes/api/redirects.d.ts +12 -0
  553. package/lib/routes/api/redirects.js +13 -0
  554. package/lib/routes/api/settings.d.ts +8 -0
  555. package/lib/routes/api/settings.js +15 -0
  556. package/lib/routes/api/snippets.d.ts +15 -0
  557. package/lib/routes/api/snippets.js +16 -0
  558. package/lib/routes/api/tags.d.ts +8 -0
  559. package/lib/routes/api/tags.js +14 -0
  560. package/lib/routes/api/tokens.d.ts +7 -0
  561. package/lib/routes/api/tokens.js +15 -0
  562. package/lib/routes/api/two-factor.d.ts +7 -0
  563. package/lib/routes/api/two-factor.js +15 -0
  564. package/lib/routes/api/users.d.ts +8 -0
  565. package/lib/routes/api/users.js +25 -0
  566. package/lib/routes/api/v1.d.ts +12 -0
  567. package/lib/routes/api/v1.js +55 -0
  568. package/lib/routes/api/verification.d.ts +6 -0
  569. package/lib/routes/api/verification.js +11 -0
  570. package/lib/server/index.d.ts +24 -0
  571. package/lib/server/index.js +110 -0
  572. package/lib/types/index.d.ts +298 -0
  573. package/lib/types/index.js +1 -0
  574. package/lib/vite.d.ts +2 -0
  575. package/lib/vite.js +101 -0
  576. package/mail/comment-moderation.html +27 -0
  577. package/mail/comment-moderation.txt +13 -0
  578. package/mail/comment-reply.html +28 -0
  579. package/mail/comment-reply.txt +14 -0
  580. package/mail/invitation.html +25 -0
  581. package/mail/invitation.txt +11 -0
  582. package/mail/member-magic-link.html +23 -0
  583. package/mail/member-magic-link.txt +10 -0
  584. package/mail/newsletter.html +26 -0
  585. package/mail/newsletter.txt +13 -0
  586. package/mail/password-reset.html +26 -0
  587. package/mail/password-reset.txt +10 -0
  588. package/mail/verify-email.html +25 -0
  589. package/mail/verify-email.txt +8 -0
  590. package/package.json +85 -4
@@ -0,0 +1,152 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useState, useEffect } from 'react';
3
+ import { api } from "../../../helpers/api.js";
4
+ import AdminLayout from "../../layouts/AdminLayout.js";
5
+ import { Link } from "../../components/Link.js";
6
+ import { Pagination } from "../../components/admin/Pagination.js";
7
+ import { useNavigate, useParams } from '@basicbenframework/core/client';
8
+ import { useContentTypes, typeFromQuery, navigateWithType } from "../../hooks/useContentTypes.js";
9
+ import { t, useT } from "../../i18n/index.js";
10
+ const TABS = ['all', 'published', 'scheduled', 'pending', 'draft', 'trash'];
11
+ /** Read a stored timestamp as UTC, whether or not the driver kept the zone. */
12
+ function parseUtc(value) {
13
+ if (!value)
14
+ return null;
15
+ const date = new Date(/Z|[+-]\d\d:?\d\d$/.test(value) ? value : value.replace(' ', 'T') + 'Z');
16
+ return Number.isNaN(date.getTime()) ? null : date;
17
+ }
18
+ /** The badge a row shows: its status, with "scheduled" told apart from live. */
19
+ function badgeFor(post) {
20
+ if (post.deleted_at)
21
+ return { label: t('Trashed'), tone: 'admin-badge-danger' };
22
+ const at = parseUtc(post.publish_at);
23
+ if (Number(post.published) && at && at.getTime() > Date.now()) {
24
+ return { label: t('Scheduled {date}', { date: at.toLocaleString() }), tone: 'admin-badge-info' };
25
+ }
26
+ if (Number(post.published))
27
+ return { label: t('Published'), tone: 'admin-badge-success' };
28
+ if (post.status === 'pending')
29
+ return { label: t('Pending review'), tone: 'admin-badge-warning' };
30
+ return { label: t('Draft'), tone: 'admin-badge-warning' };
31
+ }
32
+ export default function AdminPosts() {
33
+ const { t, tn } = useT();
34
+ const tabLabels = {
35
+ all: t('All'),
36
+ published: t('Published'),
37
+ scheduled: t('Scheduled'),
38
+ pending: t('Pending review'),
39
+ draft: t('Drafts'),
40
+ trash: t('Trash')
41
+ };
42
+ const [posts, setPosts] = useState([]);
43
+ const [meta, setMeta] = useState(null);
44
+ const [counts, setCounts] = useState({});
45
+ const [page, setPage] = useState(1);
46
+ const [filter, setFilter] = useState('all');
47
+ const [search, setSearch] = useState('');
48
+ const [query, setQuery] = useState('');
49
+ const [selected, setSelected] = useState([]);
50
+ const [loading, setLoading] = useState(true);
51
+ // Which content type this screen lists. `/admin/content/:type` names it in
52
+ // the path; `/admin/posts?type=` in the query; otherwise it is Posts.
53
+ const navigate = useNavigate();
54
+ const params = useParams();
55
+ const { types } = useContentTypes();
56
+ const [type, setType] = useState(params.type || typeFromQuery() || 'post');
57
+ useEffect(() => { if (params.type)
58
+ setType(params.type); }, [params.type]);
59
+ const current = types.find(ct => ct.key === type);
60
+ const plural = current?.plural_label ?? t('Posts');
61
+ const changeType = (next) => {
62
+ setType(next);
63
+ setPage(1);
64
+ // Kept in the address bar so a reload stays on the same type.
65
+ window.history.replaceState({}, '', next === 'post' ? '/admin/posts' : `/admin/posts?type=${encodeURIComponent(next)}`);
66
+ };
67
+ useEffect(() => {
68
+ loadPosts();
69
+ }, [page, filter, query, type]);
70
+ const loadPosts = async () => {
71
+ setLoading(true);
72
+ setSelected([]);
73
+ try {
74
+ const params = new URLSearchParams({ page: String(page), status: filter, type });
75
+ if (query)
76
+ params.set('search', query);
77
+ const res = await api.get(`/api/posts?${params}`);
78
+ setPosts(res?.posts || []);
79
+ setMeta(res?.meta || null);
80
+ setCounts(res?.counts || {});
81
+ }
82
+ catch (error) {
83
+ console.error('Failed to load posts:', error);
84
+ }
85
+ finally {
86
+ setLoading(false);
87
+ }
88
+ };
89
+ const changeFilter = (next) => {
90
+ setFilter(next);
91
+ setPage(1);
92
+ };
93
+ const submitSearch = (event) => {
94
+ event.preventDefault();
95
+ setPage(1);
96
+ setQuery(search.trim());
97
+ };
98
+ /**
99
+ * Reload after a change rather than splicing rows out. The page is a window
100
+ * on the server's ordering, so removing a row locally leaves it one short and
101
+ * silently hides whatever should have moved up into it. Stepping back a page
102
+ * when the last rows on it go keeps the table from showing empty.
103
+ */
104
+ const refreshAfter = (removed) => {
105
+ if (removed >= posts.length && page > 1)
106
+ setPage(page - 1);
107
+ else
108
+ loadPosts();
109
+ };
110
+ const runBulk = async (action, ids) => {
111
+ if (ids.length === 0)
112
+ return;
113
+ if (action === 'delete' && !confirm(tn('Delete {count} post permanently? This cannot be undone.', 'Delete {count} posts permanently? This cannot be undone.', ids.length)))
114
+ return;
115
+ try {
116
+ const res = await api.post('/api/posts/bulk', { action, ids });
117
+ if (res?.failed?.length) {
118
+ alert(tn('{count} could not be changed:', '{count} could not be changed:', res.failed.length) + '\n' + res.failed.map(f => `#${f.id}: ${f.error}`).join('\n'));
119
+ }
120
+ const leavesView = action === 'trash' || action === 'restore' || action === 'delete' || filter !== 'all';
121
+ refreshAfter(leavesView ? (res?.done?.length ?? 0) : 0);
122
+ }
123
+ catch (error) {
124
+ alert(error.message || t('That action failed'));
125
+ }
126
+ };
127
+ const trash = async (id) => {
128
+ try {
129
+ await api.delete(`/api/posts/${id}`);
130
+ refreshAfter(1);
131
+ }
132
+ catch (error) {
133
+ alert(error.message || t('Failed to move the post to the trash'));
134
+ }
135
+ };
136
+ const toggle = (id) => setSelected(prev => (prev.includes(id) ? prev.filter(x => x !== id) : [...prev, id]));
137
+ const allSelected = posts.length > 0 && selected.length === posts.length;
138
+ const inTrash = filter === 'trash';
139
+ return (_jsx(AdminLayout, { title: plural, children: _jsxs("div", { className: "admin-card", children: [_jsxs("div", { className: "admin-card-header", children: [_jsx("h2", { className: "admin-card-title", children: plural }), type === 'post' ? (_jsx(Link, { href: "/admin/posts/new", className: "admin-btn admin-btn-primary", children: t('+ New Post') })) : (_jsx("button", { type: "button", className: "admin-btn admin-btn-primary", onClick: () => navigateWithType(navigate, '/admin/posts/new', type), children: current?.singular_label ? t('+ New {name}', { name: current.singular_label }) : t('+ New entry') }))] }), types.length > 1 && (_jsx("nav", { "aria-label": t('Content type'), style: { display: 'flex', flexWrap: 'wrap', gap: '0.25rem', marginBottom: '0.75rem' }, children: types.map(ct => (_jsx("button", { type: "button", onClick: () => changeType(ct.key), "aria-pressed": type === ct.key, className: `admin-btn ${type === ct.key ? 'admin-btn-primary' : 'admin-btn-secondary'}`, children: ct.plural_label }, ct.key))) })), _jsxs("div", { style: { display: 'flex', flexWrap: 'wrap', gap: '0.5rem', alignItems: 'center', justifyContent: 'space-between', marginBottom: '1rem' }, children: [_jsx("nav", { "aria-label": t('Filter posts by status'), style: { display: 'flex', flexWrap: 'wrap', gap: '0.25rem' }, children: TABS.map(tab => (_jsxs("button", { type: "button", onClick: () => changeFilter(tab), className: `admin-btn ${filter === tab ? 'admin-btn-primary' : 'admin-btn-secondary'}`, "aria-pressed": filter === tab, children: [tabLabels[tab], counts[tab] !== undefined ? ` (${counts[tab]})` : ''] }, tab))) }), _jsxs("form", { onSubmit: submitSearch, role: "search", style: { display: 'flex', gap: '0.25rem' }, children: [_jsx("input", { type: "search", value: search, onChange: e => setSearch(e.target.value), placeholder: t('Search posts'), className: "admin-input", "aria-label": t('Search posts') }), _jsx("button", { type: "submit", className: "admin-btn admin-btn-secondary", children: t('Search') })] })] }), selected.length > 0 && (_jsxs("div", { style: { display: 'flex', gap: '0.5rem', alignItems: 'center', marginBottom: '0.75rem' }, children: [_jsx("span", { children: tn('{count} selected', '{count} selected', selected.length) }), inTrash ? (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: () => runBulk('restore', selected), children: t('Restore') }), _jsx("button", { type: "button", className: "admin-btn admin-btn-danger", onClick: () => runBulk('delete', selected), children: t('Delete permanently') })] })) : (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: () => runBulk('publish', selected), children: t('Publish') }), _jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: () => runBulk('draft', selected), children: t('Unpublish') }), _jsx("button", { type: "button", className: "admin-btn admin-btn-danger", onClick: () => runBulk('trash', selected), children: t('Move to trash') })] }))] })), loading ? (_jsx("div", { className: "admin-loading", children: t('Loading...') })) : posts.length === 0 ? (_jsx("p", { style: { color: 'var(--fg-muted)', textAlign: 'center', padding: '2rem' }, children: query
140
+ ? t('No posts match “{query}”.', { query })
141
+ : inTrash
142
+ ? t('The trash is empty.')
143
+ : filter === 'all'
144
+ ? t('No posts yet. Create your first post!')
145
+ : t('Nothing here.') })) : (_jsxs("table", { className: "admin-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { style: { width: '2rem' }, children: _jsx("input", { type: "checkbox", "aria-label": t('Select all posts on this page'), checked: allSelected, onChange: () => setSelected(allSelected ? [] : posts.map(p => p.id)) }) }), _jsx("th", { children: t('Title') }), _jsx("th", { children: t('Author') }), _jsx("th", { children: t('Categories') }), _jsx("th", { children: t('Status') }), _jsx("th", { children: t('Date') }), _jsx("th", { children: t('Actions') })] }) }), _jsx("tbody", { children: posts.map(post => {
146
+ const badge = badgeFor(post);
147
+ const date = parseUtc(post.publish_at) ?? parseUtc(post.created_at);
148
+ return (_jsxs("tr", { children: [_jsx("td", { children: _jsx("input", { type: "checkbox", "aria-label": t('Select {name}', { name: post.title }), checked: selected.includes(post.id), onChange: () => toggle(post.id) }) }), _jsx("td", { children: inTrash ? (_jsx("span", { style: { fontWeight: 500 }, children: post.title })) : (_jsx(Link, { href: `/admin/posts/${post.id}/edit`, style: { color: 'var(--accent)', fontWeight: 500 }, children: post.title })) }), _jsx("td", { children: post.author_name || '—' }), _jsx("td", { children: post.categories?.length
149
+ ? post.categories.map(c => c.name).join(', ')
150
+ : '—' }), _jsx("td", { children: _jsx("span", { className: `admin-badge ${badge.tone}`, children: badge.label }) }), _jsx("td", { children: date ? date.toLocaleDateString() : '—' }), _jsx("td", { children: _jsx("div", { style: { display: 'flex', gap: '0.5rem' }, children: inTrash ? (_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => runBulk('restore', [post.id]), className: "admin-btn admin-btn-secondary", children: t('Restore') }), _jsx("button", { onClick: () => runBulk('delete', [post.id]), className: "admin-btn admin-btn-danger", children: t('Delete permanently') })] })) : (_jsxs(_Fragment, { children: [_jsx(Link, { href: `/admin/posts/${post.id}/edit`, className: "admin-btn admin-btn-secondary", children: t('Edit') }), _jsx("button", { onClick: () => trash(post.id), className: "admin-btn admin-btn-danger", children: t('Trash') })] })) }) })] }, post.id));
151
+ }) })] })), meta && _jsx(Pagination, { meta: meta, onChange: setPage, noun: t('posts') })] }) }));
152
+ }
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ /**
3
+ * Redirects the front end applies.
4
+ *
5
+ * The CMS is headless, so nothing here answers a visitor's request itself:
6
+ * the list is served at /api/v1/redirects for the front end to apply. Rows
7
+ * marked "post" or "page" were recorded automatically when a published post
8
+ * or page changed its slug.
9
+ */
10
+ export default function AdminRedirects(): React.JSX.Element;
@@ -0,0 +1,87 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect } from 'react';
3
+ import { api } from "../../../helpers/api.js";
4
+ import AdminLayout from "../../layouts/AdminLayout.js";
5
+ import { Pagination } from "../../components/admin/Pagination.js";
6
+ import { useT, slots } from "../../i18n/index.js";
7
+ const EMPTY = { from_path: '', to_path: '', status: '301' };
8
+ /**
9
+ * Redirects the front end applies.
10
+ *
11
+ * The CMS is headless, so nothing here answers a visitor's request itself:
12
+ * the list is served at /api/v1/redirects for the front end to apply. Rows
13
+ * marked "post" or "page" were recorded automatically when a published post
14
+ * or page changed its slug.
15
+ */
16
+ export default function AdminRedirects() {
17
+ const { t } = useT();
18
+ const [redirects, setRedirects] = useState([]);
19
+ const [meta, setMeta] = useState(null);
20
+ const [page, setPage] = useState(1);
21
+ const [search, setSearch] = useState('');
22
+ const [loading, setLoading] = useState(true);
23
+ const [form, setForm] = useState(EMPTY);
24
+ const [editingId, setEditingId] = useState(null);
25
+ const [error, setError] = useState('');
26
+ useEffect(() => {
27
+ load(page, search);
28
+ }, [page]);
29
+ const load = async (which, term) => {
30
+ try {
31
+ const params = new URLSearchParams({ page: String(which) });
32
+ if (term.trim())
33
+ params.set('search', term.trim());
34
+ const res = await api.get(`/api/redirects?${params}`);
35
+ setRedirects(res?.redirects || []);
36
+ setMeta(res?.meta || null);
37
+ }
38
+ catch (err) {
39
+ console.error('Failed to load redirects:', err);
40
+ }
41
+ finally {
42
+ setLoading(false);
43
+ }
44
+ };
45
+ const handleSubmit = async (e) => {
46
+ e.preventDefault();
47
+ setError('');
48
+ const body = { ...form, status: Number(form.status) };
49
+ try {
50
+ if (editingId)
51
+ await api.put(`/api/redirects/${editingId}`, body);
52
+ else
53
+ await api.post('/api/redirects', body);
54
+ setForm(EMPTY);
55
+ setEditingId(null);
56
+ load(page, search);
57
+ }
58
+ catch (err) {
59
+ setError(err.message || t('Failed to save redirect'));
60
+ }
61
+ };
62
+ const handleEdit = (redirect) => {
63
+ setForm({ from_path: redirect.from_path, to_path: redirect.to_path, status: String(redirect.status) });
64
+ setEditingId(redirect.id);
65
+ setError('');
66
+ };
67
+ const handleDelete = async (id) => {
68
+ if (!confirm(t('Delete this redirect? Visitors to the old path will get a 404.')))
69
+ return;
70
+ try {
71
+ await api.delete(`/api/redirects/${id}`);
72
+ setRedirects(redirects.filter(r => r.id !== id));
73
+ }
74
+ catch {
75
+ alert(t('Failed to delete redirect'));
76
+ }
77
+ };
78
+ const handleSearch = (e) => {
79
+ e.preventDefault();
80
+ setPage(1);
81
+ load(1, search);
82
+ };
83
+ if (loading) {
84
+ return (_jsx(AdminLayout, { title: t('Redirects'), children: _jsx("div", { className: "admin-loading", children: t('Loading...') }) }));
85
+ }
86
+ return (_jsxs(AdminLayout, { title: t('Redirects'), children: [_jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: editingId ? t('Edit Redirect') : t('Add Redirect') }), _jsxs("form", { onSubmit: handleSubmit, children: [_jsxs("div", { className: "admin-grid admin-grid-2", children: [_jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('From path') }), _jsx("input", { type: "text", value: form.from_path, onChange: e => setForm({ ...form, from_path: e.target.value }), className: "admin-input", placeholder: t('/old-page'), required: true })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('To') }), _jsx("input", { type: "text", value: form.to_path, onChange: e => setForm({ ...form, to_path: e.target.value }), className: "admin-input", placeholder: t('/new-page or https://example.com/page'), required: true })] })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Type') }), _jsxs("select", { value: form.status, onChange: e => setForm({ ...form, status: e.target.value }), className: "admin-select", children: [_jsx("option", { value: "301", children: t('301 - Moved permanently') }), _jsx("option", { value: "302", children: t('302 - Temporary') })] })] }), error && _jsx("p", { style: { color: 'var(--danger)', marginBottom: '0.75rem' }, children: error }), _jsxs("div", { style: { display: 'flex', gap: '0.5rem' }, children: [_jsx("button", { type: "submit", className: "admin-btn admin-btn-primary", children: editingId ? t('Update') : t('Add Redirect') }), editingId && (_jsx("button", { type: "button", onClick: () => { setForm(EMPTY); setEditingId(null); setError(''); }, className: "admin-btn admin-btn-secondary", children: t('Cancel') }))] })] }), _jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.75rem' }, children: slots(t('Your front end applies these: it reads {path} at build time or from edge middleware. Changing the slug of a published post or page adds a 301 here automatically.'), { path: _jsx("code", { children: '/api/v1/redirects' }) }) })] }), _jsxs("div", { className: "admin-card", children: [_jsxs("div", { className: "admin-card-header", children: [_jsx("h3", { className: "admin-card-title", children: t('All Redirects') }), _jsxs("form", { onSubmit: handleSearch, style: { display: 'flex', gap: '0.5rem' }, children: [_jsx("input", { type: "search", value: search, onChange: e => setSearch(e.target.value), className: "admin-input", placeholder: t('Search paths') }), _jsx("button", { type: "submit", className: "admin-btn admin-btn-secondary", children: t('Search') })] })] }), redirects.length === 0 ? (_jsx("p", { style: { color: 'var(--fg-muted)', textAlign: 'center', padding: '2rem' }, children: t('No redirects.') })) : (_jsxs("table", { className: "admin-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: t('From') }), _jsx("th", { children: t('To') }), _jsx("th", { children: t('Type') }), _jsx("th", { children: t('Source') }), _jsx("th", { children: t('Hits') }), _jsx("th", { children: t('Actions') })] }) }), _jsx("tbody", { children: redirects.map(redirect => (_jsxs("tr", { children: [_jsx("td", { children: _jsx("code", { children: redirect.from_path }) }), _jsx("td", { children: _jsx("code", { children: redirect.to_path }) }), _jsx("td", { children: redirect.status }), _jsx("td", { children: _jsx("span", { className: `admin-badge ${redirect.source === 'manual' ? 'admin-badge-warning' : 'admin-badge-success'}`, children: redirect.source === 'manual' ? t('Manual') : redirect.source === 'post' ? t('Automatic (post)') : t('Automatic (page)') }) }), _jsx("td", { children: redirect.hits }), _jsx("td", { children: _jsxs("div", { style: { display: 'flex', gap: '0.5rem' }, children: [_jsx("button", { onClick: () => handleEdit(redirect), className: "admin-btn admin-btn-secondary", children: t('Edit') }), _jsx("button", { onClick: () => handleDelete(redirect.id), className: "admin-btn admin-btn-danger", children: t('Delete') })] }) })] }, redirect.id))) })] })), meta && _jsx(Pagination, { meta: meta, onChange: setPage, noun: t('redirects') })] })] }));
87
+ }
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export default function AdminSettings(): React.JSX.Element;
@@ -0,0 +1,111 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect } from 'react';
3
+ import { api } from "../../../helpers/api.js";
4
+ import AdminLayout from "../../layouts/AdminLayout.js";
5
+ import { useT, ADMIN_LOCALES, applySiteLocale, slots } from "../../i18n/index.js";
6
+ import { Slot } from "../../host/index.js";
7
+ const DEFAULTS = {
8
+ site_name: '',
9
+ site_description: '',
10
+ posts_per_page: '10',
11
+ allow_comments: 'true',
12
+ moderate_comments: 'true',
13
+ public_api: 'false',
14
+ webhook_urls: '',
15
+ robots_txt: '',
16
+ site_logo: '',
17
+ site_icon: '',
18
+ default_social_image: '',
19
+ timezone: 'UTC',
20
+ locale: 'en',
21
+ admin_locale: '',
22
+ code_injection_head: '',
23
+ code_injection_foot: ''
24
+ };
25
+ // The zones the runtime knows, for the picker. The server validates against
26
+ // the same Intl data, so anything offered here is accepted there.
27
+ const TIME_ZONES = (() => {
28
+ try {
29
+ return ['UTC', ...Intl.supportedValuesOf('timeZone').filter((z) => z !== 'UTC')];
30
+ }
31
+ catch {
32
+ return ['UTC'];
33
+ }
34
+ })();
35
+ const mono = { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: '13px' };
36
+ const hint = { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' };
37
+ export default function AdminSettings() {
38
+ const { t } = useT();
39
+ const [settings, setSettings] = useState(DEFAULTS);
40
+ const [siteUrl, setSiteUrl] = useState('');
41
+ const [loading, setLoading] = useState(true);
42
+ const [saving, setSaving] = useState(false);
43
+ const [message, setMessage] = useState('');
44
+ const [failed, setFailed] = useState(false);
45
+ // Every stored setting, for features' sections, and what they changed.
46
+ const [stored, setStored] = useState({});
47
+ const [extra, setExtra] = useState({});
48
+ useEffect(() => {
49
+ loadSettings();
50
+ }, []);
51
+ const loadSettings = async () => {
52
+ try {
53
+ const res = await api.get('/api/settings');
54
+ if (res?.settings) {
55
+ // Only the known keys, each falling back to its default: the response
56
+ // can also carry legacy rows the form has no field for, and sending
57
+ // those back would be refused as unknown settings.
58
+ const loaded = { ...DEFAULTS };
59
+ for (const key of Object.keys(DEFAULTS)) {
60
+ if (res.settings[key])
61
+ loaded[key] = res.settings[key];
62
+ }
63
+ setSettings(loaded);
64
+ setStored(Object.fromEntries(Object.entries(res.settings).map(([key, value]) => [key, String(value ?? '')])));
65
+ }
66
+ setSiteUrl(res?.site_url || '');
67
+ }
68
+ catch (error) {
69
+ console.error('Failed to load settings:', error);
70
+ }
71
+ finally {
72
+ setLoading(false);
73
+ }
74
+ };
75
+ const handleSubmit = async (e) => {
76
+ e.preventDefault();
77
+ setSaving(true);
78
+ setMessage('');
79
+ setFailed(false);
80
+ try {
81
+ await api.put('/api/settings', { settings: { ...settings, ...extra } });
82
+ // The admin's own language may have just changed; show it now.
83
+ await applySiteLocale(settings.admin_locale);
84
+ setMessage(t('Settings saved successfully!'));
85
+ }
86
+ catch (error) {
87
+ // The server names the setting it refused; say which.
88
+ setFailed(true);
89
+ setMessage(t('Failed to save settings: {error}', { error: error?.message || t('unknown error') }));
90
+ }
91
+ finally {
92
+ setSaving(false);
93
+ }
94
+ };
95
+ const handleChange = (e) => {
96
+ const { name, value } = e.target;
97
+ setSettings(prev => ({ ...prev, [name]: value }));
98
+ };
99
+ if (loading) {
100
+ return (_jsx(AdminLayout, { title: t('Settings'), children: _jsx("div", { className: "admin-loading", children: t('Loading...') }) }));
101
+ }
102
+ return (_jsx(AdminLayout, { title: t('Settings'), children: _jsxs("form", { onSubmit: handleSubmit, children: [_jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('General') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site Name') }), _jsx("input", { type: "text", name: "site_name", value: settings.site_name, onChange: handleChange, className: "admin-input", placeholder: t('My Blog') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site Description') }), _jsx("textarea", { name: "site_description", value: settings.site_description, onChange: handleChange, className: "admin-textarea", style: { minHeight: '80px' }, placeholder: t('A brief description of your site') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Site Identity') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site URL') }), _jsx("input", { type: "text", value: siteUrl, className: "admin-input", readOnly: true, disabled: true }), _jsx("p", { style: hint, children: slots(t('Set by {variable} in the environment, not here. Feeds, the sitemap and {path} link to it.'), { variable: _jsx("code", { children: 'SITE_URL' }), path: _jsx("code", { children: '/api/v1/site' }) }) })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Logo URL') }), _jsx("input", { type: "text", name: "site_logo", value: settings.site_logo, onChange: handleChange, className: "admin-input", placeholder: t('/uploads/logo.svg or https://…') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Icon URL') }), _jsx("input", { type: "text", name: "site_icon", value: settings.site_icon, onChange: handleChange, className: "admin-input", placeholder: t('/uploads/icon.png — favicon and app icon') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Default Social Image URL') }), _jsx("input", { type: "text", name: "default_social_image", value: settings.default_social_image, onChange: handleChange, className: "admin-input", placeholder: t('Used on share cards when a post or page has no image') }), _jsx("p", { style: hint, children: t('Paste a URL from the media library, or a path starting with /.') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Language & Time') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Time Zone') }), _jsxs("select", { name: "timezone", value: settings.timezone, onChange: handleChange, className: "admin-select", children: [!TIME_ZONES.includes(settings.timezone) && _jsx("option", { value: settings.timezone, children: settings.timezone }), TIME_ZONES.map(zone => _jsx("option", { value: zone, children: zone }, zone))] }), _jsx("p", { style: hint, children: t('Dates are stored in UTC; this is the zone the front end shows them in.') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Locale') }), _jsx("input", { type: "text", name: "locale", value: settings.locale, onChange: handleChange, className: "admin-input", placeholder: t('en, en-GB, fr-CA') }), _jsx("p", { style: hint, children: slots(t('A BCP 47 language tag, for {tag} and date formatting.'), { tag: _jsx("code", { children: '<html lang>' }) }) })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: "admin_locale", children: t('Admin language') }), _jsx("select", { id: "admin_locale", name: "admin_locale", value: settings.admin_locale || 'en', onChange: handleChange, className: "admin-select", children: ADMIN_LOCALES.map(option => _jsx("option", { value: option.code, children: option.name }, option.code)) }), _jsx("p", { style: hint, children: t('The admin\'s language for everyone who has not chosen one in their profile.') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Reading') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Posts Per Page') }), _jsx("input", { type: "number", name: "posts_per_page", value: settings.posts_per_page, onChange: handleChange, className: "admin-input", min: "1", max: "100" })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: 'robots.txt' }), _jsx("textarea", { name: "robots_txt", value: settings.robots_txt, onChange: handleChange, className: "admin-textarea", rows: 5, placeholder: t('Blank uses the default:') + '\nUser-agent: *\nDisallow: /admin\nDisallow: /api/\nAllow: /api/v1/\nSitemap: …/sitemap.xml', style: { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: '13px' } })] })] }), _jsx(Slot, { name: "settings.reading", values: { ...stored, ...extra }, onChange: (changes) => setExtra(prev => ({ ...prev, ...changes })) }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Discussion') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Allow Comments') }), _jsxs("select", { name: "allow_comments", value: settings.allow_comments, onChange: handleChange, className: "admin-select", children: [_jsx("option", { value: "true", children: t('Yes') }), _jsx("option", { value: "false", children: t('No') })] })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Moderate Comments') }), _jsxs("select", { name: "moderate_comments", value: settings.moderate_comments, onChange: handleChange, className: "admin-select", children: [_jsx("option", { value: "true", children: t('Yes - Require approval') }), _jsx("option", { value: "false", children: t('No - Auto-approve all') })] }), _jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' }, children: t('If enabled, comments from guests will require approval before appearing.') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Headless API') }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Public reads') }), _jsxs("select", { name: "public_api", value: settings.public_api, onChange: handleChange, className: "admin-select", children: [_jsx("option", { value: "false", children: t('No - /api/v1 requires a token') }), _jsx("option", { value: "true", children: t('Yes - serve content to anyone') })] }), _jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' }, children: slots(t('Turning this on serves published content at {path} with no credential. Appropriate for a site whose content is public anyway, and for a browser-side consumer that cannot be trusted with a token.'), { path: _jsx("code", { children: '/api/v1' }) }) })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Webhook URLs') }), _jsx("textarea", { name: "webhook_urls", value: settings.webhook_urls, onChange: handleChange, className: "admin-input", rows: 4, placeholder: 'https://example.com/rebuild\nhttps://another.example.com/hook', style: { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: '13px' } }), _jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' }, children: slots(t('One per line. Each gets a POST when a post, page or media item is created, updated or deleted — which is what stops a consumer polling. Every request carries {signature}, an HMAC of {timestamp} and the exact body, keyed with your {secret} (set in the environment; nothing is sent without it); verify it over the {raw} body, since a parsed and re-serialised one will not match.'), {
103
+ signature: _jsx("code", { children: 'X-BasicBen-Signature' }),
104
+ timestamp: _jsx("code", { children: 'X-BasicBen-Timestamp' }),
105
+ secret: _jsx("code", { children: 'WEBHOOK_SECRET' }),
106
+ raw: _jsx("em", { children: t('raw') })
107
+ }) }), _jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem', marginTop: '0.25rem' }, children: t('Delivery is at-most-once: a failure is logged and dropped, with no retry queue. A consumer that cannot miss an event should poll as a backstop.') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Code Injection') }), _jsx("p", { style: { ...hint, marginTop: 0, marginBottom: '1rem' }, children: slots(t('HTML your front end inserts verbatim on every page — analytics, verification tags, a font stylesheet. It is {warning}: anything here runs on your site for every visitor. Served to the front end at {path}.'), {
108
+ warning: _jsx("strong", { children: t('not sanitised') }),
109
+ path: _jsx("code", { children: '/api/v1/site' })
110
+ }) }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site header (inside {tag})', { tag: '<head>' }) }), _jsx("textarea", { name: "code_injection_head", value: settings.code_injection_head, onChange: handleChange, className: "admin-textarea", rows: 6, style: mono })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Site footer (before {tag})', { tag: '</body>' }) }), _jsx("textarea", { name: "code_injection_foot", value: settings.code_injection_foot, onChange: handleChange, className: "admin-textarea", rows: 6, style: mono })] })] }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '1rem' }, children: [_jsx("button", { type: "submit", className: "admin-btn admin-btn-primary", disabled: saving, children: saving ? t('Saving...') : t('Save Settings') }), message && (_jsx("span", { style: { color: failed ? 'var(--danger)' : 'var(--success)' }, children: message }))] })] }) }));
111
+ }
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ /**
3
+ * The snippet library: reusable Markdown for the editor's "Insert snippet".
4
+ *
5
+ * One shared list for the whole site — the point is that the disclosure
6
+ * paragraph is written once. Anyone who writes (authors and up) may add
7
+ * snippets and change their own; an editor may change anyone's. The server
8
+ * decides that per row and says so in `can_edit`, so this page only has to
9
+ * hide the buttons it would refuse.
10
+ *
11
+ * Editing a snippet does not touch posts that already used it: insertion
12
+ * copies the text.
13
+ */
14
+ export default function AdminSnippets(): React.JSX.Element;
@@ -0,0 +1,85 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useState } from 'react';
3
+ import { api } from "../../../helpers/api.js";
4
+ import AdminLayout from "../../layouts/AdminLayout.js";
5
+ import MarkdownEditor from "../../components/MarkdownEditor.js";
6
+ import { useT } from "../../i18n/index.js";
7
+ const EMPTY = { id: null, name: '', content: '' };
8
+ /**
9
+ * The snippet library: reusable Markdown for the editor's "Insert snippet".
10
+ *
11
+ * One shared list for the whole site — the point is that the disclosure
12
+ * paragraph is written once. Anyone who writes (authors and up) may add
13
+ * snippets and change their own; an editor may change anyone's. The server
14
+ * decides that per row and says so in `can_edit`, so this page only has to
15
+ * hide the buttons it would refuse.
16
+ *
17
+ * Editing a snippet does not touch posts that already used it: insertion
18
+ * copies the text.
19
+ */
20
+ export default function AdminSnippets() {
21
+ const { t } = useT();
22
+ const [snippets, setSnippets] = useState([]);
23
+ const [loading, setLoading] = useState(true);
24
+ const [saving, setSaving] = useState(false);
25
+ const [draft, setDraft] = useState(EMPTY);
26
+ const [notice, setNotice] = useState(null);
27
+ useEffect(() => {
28
+ load();
29
+ }, []);
30
+ const load = async () => {
31
+ try {
32
+ const res = await api.get('/api/snippets');
33
+ setSnippets(res?.snippets || []);
34
+ }
35
+ catch (error) {
36
+ setNotice({
37
+ tone: 'error',
38
+ text: error.message === 'Forbidden'
39
+ ? t('Snippets are available to authors and editors.')
40
+ : t('Could not load snippets.')
41
+ });
42
+ }
43
+ finally {
44
+ setLoading(false);
45
+ }
46
+ };
47
+ const handleSave = async (event) => {
48
+ event.preventDefault();
49
+ setSaving(true);
50
+ setNotice(null);
51
+ try {
52
+ const body = { name: draft.name, content: draft.content };
53
+ if (draft.id)
54
+ await api.put(`/api/snippets/${draft.id}`, body);
55
+ else
56
+ await api.post('/api/snippets', body);
57
+ setNotice({ tone: 'ok', text: draft.id ? t('"{name}" updated.', { name: draft.name }) : t('"{name}" added.', { name: draft.name }) });
58
+ setDraft(EMPTY);
59
+ await load();
60
+ }
61
+ catch (error) {
62
+ setNotice({ tone: 'error', text: error.message || t('Could not save the snippet.') });
63
+ }
64
+ finally {
65
+ setSaving(false);
66
+ }
67
+ };
68
+ const handleDelete = async (snippet) => {
69
+ if (!confirm(t('Delete "{name}"? Posts that already use it keep their copy.', { name: snippet.name })))
70
+ return;
71
+ try {
72
+ await api.delete(`/api/snippets/${snippet.id}`);
73
+ setSnippets(current => current.filter(s => s.id !== snippet.id));
74
+ if (draft.id === snippet.id)
75
+ setDraft(EMPTY);
76
+ }
77
+ catch (error) {
78
+ setNotice({ tone: 'error', text: error.message || t('Could not delete the snippet.') });
79
+ }
80
+ };
81
+ if (loading) {
82
+ return (_jsx(AdminLayout, { title: t('Snippets'), children: _jsx("div", { className: "admin-loading", children: t('Loading…') }) }));
83
+ }
84
+ return (_jsxs(AdminLayout, { title: t('Snippets'), children: [notice && (_jsx("div", { className: "admin-card", role: notice.tone === 'error' ? 'alert' : 'status', style: { color: notice.tone === 'error' ? 'var(--danger)' : 'var(--success)' }, children: notice.text })), _jsxs("div", { className: "admin-card", children: [_jsx("h2", { className: "admin-card-title", children: draft.id ? t('Edit snippet') : t('New snippet') }), _jsxs("form", { onSubmit: handleSave, children: [_jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: "snippet-name", children: t('Name') }), _jsx("input", { id: "snippet-name", className: "admin-input", value: draft.name, maxLength: 100, onChange: e => setDraft(d => ({ ...d, name: e.target.value })), placeholder: t('Affiliate disclosure'), required: true })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Content') }), _jsx(MarkdownEditor, { name: "content", value: draft.content, onChange: e => setDraft(d => ({ ...d, content: e.target.value })), minHeight: "180px", placeholder: t('The Markdown that gets inserted.'), required: true })] }), _jsxs("div", { style: { display: 'flex', gap: '0.5rem' }, children: [_jsx("button", { type: "submit", className: "admin-btn admin-btn-primary", disabled: saving, children: saving ? t('Saving…') : draft.id ? t('Update snippet') : t('Add snippet') }), draft.id && (_jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: () => setDraft(EMPTY), children: t('Cancel') }))] })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h2", { className: "admin-card-title", children: t('Library') }), snippets.length === 0 ? (_jsx("p", { style: { color: 'var(--fg-muted)' }, children: t('No snippets yet. Add one above, then use "Insert snippet" in the post editor\'s toolbar.') })) : (_jsxs("table", { className: "admin-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: t('Name') }), _jsx("th", { children: t('Preview') }), _jsx("th", { children: t('Added by') }), _jsx("th", {})] }) }), _jsx("tbody", { children: snippets.map(snippet => (_jsxs("tr", { children: [_jsx("td", { children: _jsx("strong", { children: snippet.name }) }), _jsx("td", { style: { color: 'var(--fg-muted)', fontSize: '13px' }, children: snippet.content.length > 100 ? `${snippet.content.slice(0, 100)}…` : snippet.content }), _jsx("td", { style: { color: 'var(--fg-muted)', fontSize: '13px' }, children: snippet.author_name ?? '—' }), _jsx("td", { style: { whiteSpace: 'nowrap' }, children: snippet.can_edit && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: () => setDraft({ id: snippet.id, name: snippet.name, content: snippet.content }), children: t('Edit') }), ' ', _jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: () => handleDelete(snippet), children: t('Delete') })] })) })] }, snippet.id))) })] }))] })] }));
85
+ }
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export default function AdminTags(): React.JSX.Element;
@@ -0,0 +1,74 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect } from 'react';
3
+ import { api } from "../../../helpers/api.js";
4
+ import AdminLayout from "../../layouts/AdminLayout.js";
5
+ import { useT } from "../../i18n/index.js";
6
+ export default function AdminTags() {
7
+ const { t } = useT();
8
+ const [tags, setTags] = useState([]);
9
+ const [loading, setLoading] = useState(true);
10
+ const [editingId, setEditingId] = useState(null);
11
+ const [formData, setFormData] = useState({ name: '', slug: '' });
12
+ useEffect(() => {
13
+ loadTags();
14
+ }, []);
15
+ const loadTags = async () => {
16
+ try {
17
+ const res = await api.get('/api/tags');
18
+ setTags(res?.tags || []);
19
+ }
20
+ catch (error) {
21
+ console.error('Failed to load tags:', error);
22
+ }
23
+ finally {
24
+ setLoading(false);
25
+ }
26
+ };
27
+ const handleSubmit = async (e) => {
28
+ e.preventDefault();
29
+ try {
30
+ if (editingId) {
31
+ await api.put(`/api/tags/${editingId}`, formData);
32
+ }
33
+ else {
34
+ await api.post('/api/tags', formData);
35
+ }
36
+ setFormData({ name: '', slug: '' });
37
+ setEditingId(null);
38
+ loadTags();
39
+ }
40
+ catch (error) {
41
+ alert(error.message || t('Failed to save tag'));
42
+ }
43
+ };
44
+ const handleEdit = (tag) => {
45
+ setFormData({ name: tag.name, slug: tag.slug });
46
+ setEditingId(tag.id);
47
+ };
48
+ const handleDelete = async (id) => {
49
+ if (!confirm(t('Are you sure you want to delete this tag?')))
50
+ return;
51
+ try {
52
+ await api.delete(`/api/tags/${id}`);
53
+ setTags(tags.filter(tag => tag.id !== id));
54
+ }
55
+ catch (error) {
56
+ alert(t('Failed to delete tag'));
57
+ }
58
+ };
59
+ const handleCancel = () => {
60
+ setFormData({ name: '', slug: '' });
61
+ setEditingId(null);
62
+ };
63
+ if (loading) {
64
+ return (_jsx(AdminLayout, { title: t('Tags'), children: _jsx("div", { className: "admin-loading", children: t('Loading...') }) }));
65
+ }
66
+ return (_jsx(AdminLayout, { title: t('Tags'), children: _jsxs("div", { className: "admin-grid admin-grid-2", children: [_jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: editingId ? t('Edit Tag') : t('Add New Tag') }), _jsxs("form", { onSubmit: handleSubmit, children: [_jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Name') }), _jsx("input", { type: "text", value: formData.name, onChange: e => setFormData({ ...formData, name: e.target.value }), className: "admin-input", placeholder: t('Tag name'), required: true })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Slug') }), _jsx("input", { type: "text", value: formData.slug, onChange: e => setFormData({ ...formData, slug: e.target.value }), className: "admin-input", placeholder: t('tag-slug (auto-generated if empty)') })] }), _jsxs("div", { style: { display: 'flex', gap: '0.5rem' }, children: [_jsx("button", { type: "submit", className: "admin-btn admin-btn-primary", children: editingId ? t('Update') : t('Add Tag') }), editingId && (_jsx("button", { type: "button", onClick: handleCancel, className: "admin-btn admin-btn-secondary", children: t('Cancel') }))] })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('All Tags') }), tags.length === 0 ? (_jsx("p", { style: { color: 'var(--fg-muted)' }, children: t('No tags yet.') })) : (_jsx("div", { style: { display: 'flex', flexWrap: 'wrap', gap: '0.5rem' }, children: tags.map(tag => (_jsxs("div", { style: {
67
+ display: 'flex',
68
+ alignItems: 'center',
69
+ gap: '0.5rem',
70
+ padding: '0.5rem 1rem',
71
+ backgroundColor: 'var(--surface-hover)',
72
+ borderRadius: '0.375rem'
73
+ }, children: [_jsx("span", { children: tag.name }), _jsxs("span", { style: { color: 'var(--fg-muted)', fontSize: '0.75rem' }, children: ["(", tag.post_count || 0, ")"] }), _jsx("button", { onClick: () => handleEdit(tag), style: { background: 'none', border: 'none', cursor: 'pointer', padding: '0.25rem' }, children: "\u270F\uFE0F" }), _jsx("button", { onClick: () => handleDelete(tag.id), style: { background: 'none', border: 'none', cursor: 'pointer', padding: '0.25rem' }, children: "\uD83D\uDDD1\uFE0F" })] }, tag.id))) }))] })] }) }));
74
+ }
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export default function AdminTaxonomies(): React.JSX.Element;