@basicbenframework/cms 0.0.0-stage → 0.6.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.
- package/LICENSE +9 -0
- package/README.md +206 -2
- package/db/migrations/001_create_users.js +15 -0
- package/db/migrations/002_create_posts.js +18 -0
- package/db/migrations/003_create_categories.js +19 -0
- package/db/migrations/004_create_tags.js +16 -0
- package/db/migrations/005_create_post_tags.js +16 -0
- package/db/migrations/006_create_pages.js +26 -0
- package/db/migrations/007_create_comments.js +24 -0
- package/db/migrations/008_create_media.js +22 -0
- package/db/migrations/009_update_posts_blogging.js +27 -0
- package/db/migrations/010_create_settings.js +29 -0
- package/db/migrations/011_add_user_roles.js +23 -0
- package/db/migrations/012_create_auth_tokens.js +30 -0
- package/db/migrations/013_add_email_verified.js +24 -0
- package/db/migrations/014_create_user_two_factor.js +30 -0
- package/db/migrations/015_create_user_credentials.js +35 -0
- package/db/migrations/016_create_rate_limits.js +31 -0
- package/db/migrations/017_add_content_html.js +38 -0
- package/db/migrations/018_create_api_tokens.js +34 -0
- package/db/migrations/019_create_post_categories.js +40 -0
- package/db/migrations/020_add_author_profiles.js +60 -0
- package/db/migrations/021_add_page_featured_image.js +23 -0
- package/db/migrations/022_backfill_post_slugs_and_excerpts.js +57 -0
- package/db/migrations/023_add_user_session_controls.js +25 -0
- package/db/migrations/024_add_post_status_and_trash.js +45 -0
- package/db/migrations/025_add_social_and_indexing_fields.js +40 -0
- package/db/migrations/026_create_post_revisions.js +29 -0
- package/db/migrations/027_add_media_dimensions.js +19 -0
- package/db/migrations/028_create_navigation_menus.js +65 -0
- package/db/migrations/029_create_redirects.js +40 -0
- package/db/migrations/030_add_comment_status_and_notifications.js +53 -0
- package/db/migrations/031_create_post_locks.js +38 -0
- package/db/migrations/032_create_snippets.js +31 -0
- package/db/migrations/033_create_members.js +70 -0
- package/db/migrations/034_add_post_visibility.js +28 -0
- package/db/migrations/035_create_newsletters.js +72 -0
- package/db/migrations/036_create_analytics.js +89 -0
- package/db/migrations/037_create_ops_heartbeats.js +30 -0
- package/db/migrations/038_create_content_types.js +84 -0
- package/db/migrations/039_create_content_type_fields.js +47 -0
- package/db/migrations/040_create_taxonomies.js +80 -0
- package/db/migrations/041_add_newsletter_handoff.js +28 -0
- package/db/migrations/042_create_mysendbox_contacts.js +63 -0
- package/lib/cli/backup.d.mts +2 -0
- package/lib/cli/backup.mjs +124 -0
- package/lib/cli/export.d.mts +2 -0
- package/lib/cli/export.mjs +54 -0
- package/lib/cli/import-ghost.d.mts +2 -0
- package/lib/cli/import-ghost.mjs +50 -0
- package/lib/cli/import-json.d.mts +2 -0
- package/lib/cli/import-json.mjs +61 -0
- package/lib/cli/import-wordpress.d.mts +2 -0
- package/lib/cli/import-wordpress.mjs +169 -0
- package/lib/cli/import-wxr.d.mts +2 -0
- package/lib/cli/import-wxr.mjs +55 -0
- package/lib/cli/index.d.mts +2 -0
- package/lib/cli/index.mjs +53 -0
- package/lib/cli/lib/backup.d.mts +112 -0
- package/lib/cli/lib/backup.mjs +297 -0
- package/lib/cli/lib/ghost.d.mts +30 -0
- package/lib/cli/lib/ghost.mjs +201 -0
- package/lib/cli/lib/html-to-markdown.d.mts +61 -0
- package/lib/cli/lib/html-to-markdown.mjs +523 -0
- package/lib/cli/lib/import-common.d.mts +100 -0
- package/lib/cli/lib/import-common.mjs +252 -0
- package/lib/cli/lib/json-import.d.mts +22 -0
- package/lib/cli/lib/json-import.mjs +422 -0
- package/lib/cli/lib/site-import.d.mts +32 -0
- package/lib/cli/lib/site-import.mjs +456 -0
- package/lib/cli/lib/wordpress-rest.d.mts +25 -0
- package/lib/cli/lib/wordpress-rest.mjs +177 -0
- package/lib/cli/lib/wxr.d.mts +18 -0
- package/lib/cli/lib/wxr.mjs +307 -0
- package/lib/cli/lib/xml.d.mts +33 -0
- package/lib/cli/lib/xml.mjs +186 -0
- package/lib/cli/restore.d.mts +2 -0
- package/lib/cli/restore.mjs +98 -0
- package/lib/client/components/Alert.d.ts +7 -0
- package/lib/client/components/Alert.js +8 -0
- package/lib/client/components/Avatar.d.ts +15 -0
- package/lib/client/components/Avatar.js +10 -0
- package/lib/client/components/BackLink.d.ts +7 -0
- package/lib/client/components/BackLink.js +6 -0
- package/lib/client/components/Button.d.ts +7 -0
- package/lib/client/components/Button.js +12 -0
- package/lib/client/components/Card.d.ts +7 -0
- package/lib/client/components/Card.js +6 -0
- package/lib/client/components/CommentThread.d.ts +15 -0
- package/lib/client/components/CommentThread.js +101 -0
- package/lib/client/components/Empty.d.ts +6 -0
- package/lib/client/components/Empty.js +6 -0
- package/lib/client/components/Input.d.ts +6 -0
- package/lib/client/components/Input.js +6 -0
- package/lib/client/components/Link.d.ts +31 -0
- package/lib/client/components/Link.js +49 -0
- package/lib/client/components/Loading.d.ts +1 -0
- package/lib/client/components/Loading.js +6 -0
- package/lib/client/components/Logo.d.ts +5 -0
- package/lib/client/components/Logo.js +4 -0
- package/lib/client/components/MarkdownEditor.d.ts +41 -0
- package/lib/client/components/MarkdownEditor.js +156 -0
- package/lib/client/components/Nav/DarkModeToggle.d.ts +6 -0
- package/lib/client/components/Nav/DarkModeToggle.js +6 -0
- package/lib/client/components/Nav/DesktopNav.d.ts +8 -0
- package/lib/client/components/Nav/DesktopNav.js +9 -0
- package/lib/client/components/Nav/MobileNav.d.ts +9 -0
- package/lib/client/components/Nav/MobileNav.js +15 -0
- package/lib/client/components/NavLink.d.ts +8 -0
- package/lib/client/components/NavLink.js +6 -0
- package/lib/client/components/PageHeader.d.ts +8 -0
- package/lib/client/components/PageHeader.js +6 -0
- package/lib/client/components/PostCard.d.ts +8 -0
- package/lib/client/components/PostCard.js +7 -0
- package/lib/client/components/Textarea.d.ts +6 -0
- package/lib/client/components/Textarea.js +6 -0
- package/lib/client/components/ThemeContext.d.ts +18 -0
- package/lib/client/components/ThemeContext.js +8 -0
- package/lib/client/components/admin/AdminIcons.d.ts +13 -0
- package/lib/client/components/admin/AdminIcons.js +66 -0
- package/lib/client/components/admin/ContentModelPanels.d.ts +22 -0
- package/lib/client/components/admin/ContentModelPanels.js +93 -0
- package/lib/client/components/admin/FeaturedImageBox.d.ts +21 -0
- package/lib/client/components/admin/FeaturedImageBox.js +24 -0
- package/lib/client/components/admin/MediaGrid.d.ts +23 -0
- package/lib/client/components/admin/MediaGrid.js +69 -0
- package/lib/client/components/admin/MediaPicker.d.ts +17 -0
- package/lib/client/components/admin/MediaPicker.js +61 -0
- package/lib/client/components/admin/Pagination.d.ts +27 -0
- package/lib/client/components/admin/Pagination.js +29 -0
- package/lib/client/components/admin/SnippetPicker.d.ts +27 -0
- package/lib/client/components/admin/SnippetPicker.js +65 -0
- package/lib/client/components/admin/TermPicker.d.ts +52 -0
- package/lib/client/components/admin/TermPicker.js +58 -0
- package/lib/client/contexts/ToastContext.d.ts +12 -0
- package/lib/client/contexts/ToastContext.js +49 -0
- package/lib/client/features.d.ts +11 -0
- package/lib/client/features.js +7 -0
- package/lib/client/hooks/useContentTypes.d.ts +48 -0
- package/lib/client/hooks/useContentTypes.js +48 -0
- package/lib/client/hooks/useMediaLibrary.d.ts +46 -0
- package/lib/client/hooks/useMediaLibrary.js +189 -0
- package/lib/client/hooks/usePostLock.d.ts +32 -0
- package/lib/client/hooks/usePostLock.js +107 -0
- package/lib/client/host/index.d.ts +71 -0
- package/lib/client/host/index.js +58 -0
- package/lib/client/i18n/index.d.ts +79 -0
- package/lib/client/i18n/index.js +177 -0
- package/lib/client/i18n/locales/es/content.d.ts +4 -0
- package/lib/client/i18n/locales/es/content.js +220 -0
- package/lib/client/i18n/locales/es/editor.d.ts +9 -0
- package/lib/client/i18n/locales/es/editor.js +144 -0
- package/lib/client/i18n/locales/es/index.d.ts +8 -0
- package/lib/client/i18n/locales/es/index.js +7 -0
- package/lib/client/i18n/locales/es/layout.d.ts +4 -0
- package/lib/client/i18n/locales/es/layout.js +35 -0
- package/lib/client/i18n/locales/es/people.d.ts +4 -0
- package/lib/client/i18n/locales/es/people.js +187 -0
- package/lib/client/i18n/locales/es/site.d.ts +4 -0
- package/lib/client/i18n/locales/es/site.js +208 -0
- package/lib/client/layouts/AdminLayout.d.ts +7 -0
- package/lib/client/layouts/AdminLayout.js +1046 -0
- package/lib/client/layouts/AppLayout.d.ts +6 -0
- package/lib/client/layouts/AppLayout.js +19 -0
- package/lib/client/layouts/AuthLayout.d.ts +6 -0
- package/lib/client/layouts/AuthLayout.js +14 -0
- package/lib/client/layouts/DocsLayout.d.ts +6 -0
- package/lib/client/layouts/DocsLayout.js +28 -0
- package/lib/client/layouts/RootLayout.d.ts +6 -0
- package/lib/client/layouts/RootLayout.js +11 -0
- package/lib/client/pages/AcceptInvite.d.ts +8 -0
- package/lib/client/pages/AcceptInvite.js +60 -0
- package/lib/client/pages/Auth.d.ts +1 -0
- package/lib/client/pages/Auth.js +40 -0
- package/lib/client/pages/Authentication.d.ts +1 -0
- package/lib/client/pages/Authentication.js +230 -0
- package/lib/client/pages/Content.d.ts +1 -0
- package/lib/client/pages/Content.js +21 -0
- package/lib/client/pages/Database.d.ts +1 -0
- package/lib/client/pages/Database.js +264 -0
- package/lib/client/pages/Extending.d.ts +1 -0
- package/lib/client/pages/Extending.js +28 -0
- package/lib/client/pages/Feed.d.ts +1 -0
- package/lib/client/pages/Feed.js +19 -0
- package/lib/client/pages/FeedPost.d.ts +1 -0
- package/lib/client/pages/FeedPost.js +31 -0
- package/lib/client/pages/ForgotPassword.d.ts +8 -0
- package/lib/client/pages/ForgotPassword.js +38 -0
- package/lib/client/pages/GettingStarted.d.ts +1 -0
- package/lib/client/pages/GettingStarted.js +84 -0
- package/lib/client/pages/Headless.d.ts +1 -0
- package/lib/client/pages/Headless.js +49 -0
- package/lib/client/pages/Home.d.ts +1 -0
- package/lib/client/pages/Home.js +67 -0
- package/lib/client/pages/PostForm.d.ts +1 -0
- package/lib/client/pages/PostForm.js +55 -0
- package/lib/client/pages/Posts.d.ts +1 -0
- package/lib/client/pages/Posts.js +35 -0
- package/lib/client/pages/Profile.d.ts +1 -0
- package/lib/client/pages/Profile.js +153 -0
- package/lib/client/pages/ResetPassword.d.ts +8 -0
- package/lib/client/pages/ResetPassword.js +52 -0
- package/lib/client/pages/Routing.d.ts +1 -0
- package/lib/client/pages/Routing.js +192 -0
- package/lib/client/pages/Storage.d.ts +1 -0
- package/lib/client/pages/Storage.js +54 -0
- package/lib/client/pages/Testing.d.ts +1 -0
- package/lib/client/pages/Testing.js +141 -0
- package/lib/client/pages/Validation.d.ts +1 -0
- package/lib/client/pages/Validation.js +123 -0
- package/lib/client/pages/admin/Categories.d.ts +2 -0
- package/lib/client/pages/admin/Categories.js +75 -0
- package/lib/client/pages/admin/Comments.d.ts +11 -0
- package/lib/client/pages/admin/Comments.js +247 -0
- package/lib/client/pages/admin/ContentTypes.d.ts +2 -0
- package/lib/client/pages/admin/ContentTypes.js +163 -0
- package/lib/client/pages/admin/Dashboard.d.ts +2 -0
- package/lib/client/pages/admin/Dashboard.js +66 -0
- package/lib/client/pages/admin/Health.d.ts +12 -0
- package/lib/client/pages/admin/Health.js +148 -0
- package/lib/client/pages/admin/Media.d.ts +2 -0
- package/lib/client/pages/admin/Media.js +101 -0
- package/lib/client/pages/admin/Navigation.d.ts +9 -0
- package/lib/client/pages/admin/Navigation.js +230 -0
- package/lib/client/pages/admin/Pages.d.ts +2 -0
- package/lib/client/pages/admin/Pages.js +53 -0
- package/lib/client/pages/admin/PostEditor.d.ts +17 -0
- package/lib/client/pages/admin/PostEditor.js +532 -0
- package/lib/client/pages/admin/Posts.d.ts +2 -0
- package/lib/client/pages/admin/Posts.js +152 -0
- package/lib/client/pages/admin/Redirects.d.ts +10 -0
- package/lib/client/pages/admin/Redirects.js +87 -0
- package/lib/client/pages/admin/Settings.d.ts +2 -0
- package/lib/client/pages/admin/Settings.js +111 -0
- package/lib/client/pages/admin/Snippets.d.ts +14 -0
- package/lib/client/pages/admin/Snippets.js +85 -0
- package/lib/client/pages/admin/Tags.d.ts +2 -0
- package/lib/client/pages/admin/Tags.js +74 -0
- package/lib/client/pages/admin/Taxonomies.d.ts +2 -0
- package/lib/client/pages/admin/Taxonomies.js +130 -0
- package/lib/client/pages/admin/Tokens.d.ts +9 -0
- package/lib/client/pages/admin/Tokens.js +260 -0
- package/lib/client/pages/admin/Tools.d.ts +12 -0
- package/lib/client/pages/admin/Tools.js +111 -0
- package/lib/client/pages/admin/Users.d.ts +13 -0
- package/lib/client/pages/admin/Users.js +313 -0
- package/lib/client/pages/api-reference.d.ts +33 -0
- package/lib/client/pages/api-reference.js +198 -0
- package/lib/client/styles.css +37 -0
- package/lib/config.d.ts +24 -0
- package/lib/config.js +39 -0
- package/lib/controllers/AdminController.d.ts +46 -0
- package/lib/controllers/AdminController.js +134 -0
- package/lib/controllers/AuthController.d.ts +15 -0
- package/lib/controllers/AuthController.js +194 -0
- package/lib/controllers/AuthorController.d.ts +17 -0
- package/lib/controllers/AuthorController.js +19 -0
- package/lib/controllers/CategoryController.d.ts +10 -0
- package/lib/controllers/CategoryController.js +88 -0
- package/lib/controllers/CommentController.d.ts +68 -0
- package/lib/controllers/CommentController.js +438 -0
- package/lib/controllers/ContentTypeController.d.ts +24 -0
- package/lib/controllers/ContentTypeController.js +91 -0
- package/lib/controllers/EmailVerificationController.d.ts +33 -0
- package/lib/controllers/EmailVerificationController.js +116 -0
- package/lib/controllers/ExportController.d.ts +15 -0
- package/lib/controllers/ExportController.js +41 -0
- package/lib/controllers/FeedController.d.ts +14 -0
- package/lib/controllers/FeedController.js +246 -0
- package/lib/controllers/HealthController.d.ts +21 -0
- package/lib/controllers/HealthController.js +176 -0
- package/lib/controllers/HomeController.d.ts +12 -0
- package/lib/controllers/HomeController.js +16 -0
- package/lib/controllers/MediaController.d.ts +24 -0
- package/lib/controllers/MediaController.js +189 -0
- package/lib/controllers/NavigationController.d.ts +22 -0
- package/lib/controllers/NavigationController.js +176 -0
- package/lib/controllers/PageController.d.ts +13 -0
- package/lib/controllers/PageController.js +172 -0
- package/lib/controllers/PasskeyController.d.ts +36 -0
- package/lib/controllers/PasskeyController.js +201 -0
- package/lib/controllers/PasswordResetController.d.ts +44 -0
- package/lib/controllers/PasswordResetController.js +160 -0
- package/lib/controllers/PostController.d.ts +51 -0
- package/lib/controllers/PostController.js +538 -0
- package/lib/controllers/PostLockController.d.ts +62 -0
- package/lib/controllers/PostLockController.js +101 -0
- package/lib/controllers/ProfileController.d.ts +13 -0
- package/lib/controllers/ProfileController.js +160 -0
- package/lib/controllers/PublicApiController.d.ts +23 -0
- package/lib/controllers/PublicApiController.js +100 -0
- package/lib/controllers/RedirectController.d.ts +32 -0
- package/lib/controllers/RedirectController.js +95 -0
- package/lib/controllers/SettingsController.d.ts +28 -0
- package/lib/controllers/SettingsController.js +105 -0
- package/lib/controllers/SnippetController.d.ts +27 -0
- package/lib/controllers/SnippetController.js +123 -0
- package/lib/controllers/TagController.d.ts +9 -0
- package/lib/controllers/TagController.js +70 -0
- package/lib/controllers/TaxonomyController.d.ts +24 -0
- package/lib/controllers/TaxonomyController.js +149 -0
- package/lib/controllers/TokenController.d.ts +27 -0
- package/lib/controllers/TokenController.js +83 -0
- package/lib/controllers/TwoFactorController.d.ts +31 -0
- package/lib/controllers/TwoFactorController.js +213 -0
- package/lib/controllers/UserController.d.ts +110 -0
- package/lib/controllers/UserController.js +504 -0
- package/lib/features/analytics/AnalyticsPage.d.ts +11 -0
- package/lib/features/analytics/AnalyticsPage.js +123 -0
- package/lib/features/analytics/admin.d.ts +3 -0
- package/lib/features/analytics/admin.js +9 -0
- package/lib/features/analytics/controller.d.ts +19 -0
- package/lib/features/analytics/controller.js +79 -0
- package/lib/features/analytics/helpers.d.ts +84 -0
- package/lib/features/analytics/helpers.js +181 -0
- package/lib/features/analytics/i18n/es.d.ts +4 -0
- package/lib/features/analytics/i18n/es.js +31 -0
- package/lib/features/analytics/index.d.ts +28 -0
- package/lib/features/analytics/index.js +91 -0
- package/lib/features/analytics/manifest.d.ts +8 -0
- package/lib/features/analytics/manifest.js +18 -0
- package/lib/features/analytics/model.d.ts +130 -0
- package/lib/features/analytics/model.js +206 -0
- package/lib/features/members/Member.d.ts +93 -0
- package/lib/features/members/Member.js +194 -0
- package/lib/features/members/MemberAdminController.d.ts +60 -0
- package/lib/features/members/MemberAdminController.js +262 -0
- package/lib/features/members/MemberController.d.ts +88 -0
- package/lib/features/members/MemberController.js +250 -0
- package/lib/features/members/MembersPage.d.ts +10 -0
- package/lib/features/members/MembersPage.js +216 -0
- package/lib/features/members/PostAccessBox.d.ts +15 -0
- package/lib/features/members/PostAccessBox.js +70 -0
- package/lib/features/members/admin.d.ts +3 -0
- package/lib/features/members/admin.js +12 -0
- package/lib/features/members/csv.d.ts +21 -0
- package/lib/features/members/csv.js +74 -0
- package/lib/features/members/events.d.ts +34 -0
- package/lib/features/members/events.js +34 -0
- package/lib/features/members/i18n/es.d.ts +4 -0
- package/lib/features/members/i18n/es.js +106 -0
- package/lib/features/members/index.d.ts +44 -0
- package/lib/features/members/index.js +106 -0
- package/lib/features/members/manifest.d.ts +8 -0
- package/lib/features/members/manifest.js +18 -0
- package/lib/features/members/middleware.d.ts +42 -0
- package/lib/features/members/middleware.js +74 -0
- package/lib/features/members/newsletter.d.ts +177 -0
- package/lib/features/members/newsletter.js +439 -0
- package/lib/features/members/rate-limits.d.ts +34 -0
- package/lib/features/members/rate-limits.js +50 -0
- package/lib/features/members/request.d.ts +13 -0
- package/lib/features/members/request.js +6 -0
- package/lib/features/members/routes.d.ts +15 -0
- package/lib/features/members/routes.js +59 -0
- package/lib/features/members/session.d.ts +102 -0
- package/lib/features/members/session.js +158 -0
- package/lib/features/members/settings.d.ts +14 -0
- package/lib/features/members/settings.js +23 -0
- package/lib/features/mysendbox/MySendboxSettingsCard.d.ts +7 -0
- package/lib/features/mysendbox/MySendboxSettingsCard.js +48 -0
- package/lib/features/mysendbox/admin.d.ts +3 -0
- package/lib/features/mysendbox/admin.js +9 -0
- package/lib/features/mysendbox/broadcasts.d.ts +61 -0
- package/lib/features/mysendbox/broadcasts.js +124 -0
- package/lib/features/mysendbox/client.d.ts +95 -0
- package/lib/features/mysendbox/client.js +61 -0
- package/lib/features/mysendbox/config.d.ts +27 -0
- package/lib/features/mysendbox/config.js +74 -0
- package/lib/features/mysendbox/contacts.d.ts +121 -0
- package/lib/features/mysendbox/contacts.js +378 -0
- package/lib/features/mysendbox/controller.d.ts +11 -0
- package/lib/features/mysendbox/controller.js +47 -0
- package/lib/features/mysendbox/i18n/es.d.ts +4 -0
- package/lib/features/mysendbox/i18n/es.js +28 -0
- package/lib/features/mysendbox/index.d.ts +18 -0
- package/lib/features/mysendbox/index.js +71 -0
- package/lib/features/mysendbox/manifest.d.ts +7 -0
- package/lib/features/mysendbox/manifest.js +6 -0
- package/lib/features/mysendbox/routes.d.ts +6 -0
- package/lib/features/mysendbox/routes.js +14 -0
- package/lib/features/mysendbox/webhook.d.ts +23 -0
- package/lib/features/mysendbox/webhook.js +104 -0
- package/lib/features/theme/OEmbedController.d.ts +31 -0
- package/lib/features/theme/OEmbedController.js +128 -0
- package/lib/features/theme/ThemeController.d.ts +20 -0
- package/lib/features/theme/ThemeController.js +256 -0
- package/lib/features/theme/ThemeSettingsCard.d.ts +7 -0
- package/lib/features/theme/ThemeSettingsCard.js +12 -0
- package/lib/features/theme/admin.d.ts +3 -0
- package/lib/features/theme/admin.js +9 -0
- package/lib/features/theme/html.d.ts +48 -0
- package/lib/features/theme/html.js +97 -0
- package/lib/features/theme/i18n/es.d.ts +4 -0
- package/lib/features/theme/i18n/es.js +9 -0
- package/lib/features/theme/index.d.ts +11 -0
- package/lib/features/theme/index.js +23 -0
- package/lib/features/theme/manifest.d.ts +7 -0
- package/lib/features/theme/manifest.js +6 -0
- package/lib/features/theme/oembed.d.ts +36 -0
- package/lib/features/theme/oembed.js +58 -0
- package/lib/features/theme/routes.d.ts +17 -0
- package/lib/features/theme/routes.js +54 -0
- package/lib/features/theme/templates.d.ts +103 -0
- package/lib/features/theme/templates.js +283 -0
- package/lib/features.d.ts +15 -0
- package/lib/features.js +6 -0
- package/lib/features.manifest.d.ts +10 -0
- package/lib/features.manifest.js +6 -0
- package/lib/helpers/access.d.ts +62 -0
- package/lib/helpers/access.js +92 -0
- package/lib/helpers/api.d.ts +20 -0
- package/lib/helpers/api.js +44 -0
- package/lib/helpers/comment-guard.d.ts +145 -0
- package/lib/helpers/comment-guard.js +253 -0
- package/lib/helpers/comment-mail.d.ts +53 -0
- package/lib/helpers/comment-mail.js +188 -0
- package/lib/helpers/content-model.d.ts +50 -0
- package/lib/helpers/content-model.js +84 -0
- package/lib/helpers/content-paths.d.ts +107 -0
- package/lib/helpers/content-paths.js +200 -0
- package/lib/helpers/export-data.d.ts +85 -0
- package/lib/helpers/export-data.js +229 -0
- package/lib/helpers/gating.d.ts +53 -0
- package/lib/helpers/gating.js +83 -0
- package/lib/helpers/health.d.ts +91 -0
- package/lib/helpers/health.js +279 -0
- package/lib/helpers/heartbeat.d.ts +35 -0
- package/lib/helpers/heartbeat.js +55 -0
- package/lib/helpers/image-size.d.ts +18 -0
- package/lib/helpers/image-size.js +83 -0
- package/lib/helpers/images.d.ts +29 -0
- package/lib/helpers/images.js +41 -0
- package/lib/helpers/mail-templates.d.ts +11 -0
- package/lib/helpers/mail-templates.js +42 -0
- package/lib/helpers/publish-due.d.ts +28 -0
- package/lib/helpers/publish-due.js +67 -0
- package/lib/helpers/redirects.d.ts +43 -0
- package/lib/helpers/redirects.js +80 -0
- package/lib/helpers/seo-fields.d.ts +13 -0
- package/lib/helpers/seo-fields.js +52 -0
- package/lib/helpers/session.d.ts +30 -0
- package/lib/helpers/session.js +27 -0
- package/lib/helpers/site-settings.d.ts +98 -0
- package/lib/helpers/site-settings.js +232 -0
- package/lib/helpers/site.d.ts +14 -0
- package/lib/helpers/site.js +23 -0
- package/lib/helpers/write-hooks.d.ts +33 -0
- package/lib/helpers/write-hooks.js +37 -0
- package/lib/hooks.d.ts +17 -0
- package/lib/hooks.js +101 -0
- package/lib/host/core-tasks.d.ts +4 -0
- package/lib/host/core-tasks.js +26 -0
- package/lib/host/cron.d.ts +39 -0
- package/lib/host/cron.js +85 -0
- package/lib/host/enabled.d.ts +4 -0
- package/lib/host/enabled.js +40 -0
- package/lib/host/index.d.ts +81 -0
- package/lib/host/index.js +87 -0
- package/lib/host/manifest.d.ts +34 -0
- package/lib/host/manifest.js +7 -0
- package/lib/host/menu.d.ts +18 -0
- package/lib/host/menu.js +15 -0
- package/lib/main.d.ts +1 -0
- package/lib/main.js +24 -0
- package/lib/middleware/api-auth.d.ts +59 -0
- package/lib/middleware/api-auth.js +164 -0
- package/lib/middleware/auth.d.ts +49 -0
- package/lib/middleware/auth.js +112 -0
- package/lib/middleware/cache.d.ts +17 -0
- package/lib/middleware/cache.js +52 -0
- package/lib/middleware/rate-limits.d.ts +199 -0
- package/lib/middleware/rate-limits.js +276 -0
- package/lib/middleware/viewer.d.ts +13 -0
- package/lib/middleware/viewer.js +16 -0
- package/lib/models/Category.d.ts +24 -0
- package/lib/models/Category.js +102 -0
- package/lib/models/Comment.d.ts +120 -0
- package/lib/models/Comment.js +283 -0
- package/lib/models/ContentType.d.ts +142 -0
- package/lib/models/ContentType.js +462 -0
- package/lib/models/Credential.d.ts +21 -0
- package/lib/models/Credential.js +31 -0
- package/lib/models/Media.d.ts +53 -0
- package/lib/models/Media.js +132 -0
- package/lib/models/Menu.d.ts +131 -0
- package/lib/models/Menu.js +312 -0
- package/lib/models/Page.d.ts +55 -0
- package/lib/models/Page.js +218 -0
- package/lib/models/Post.d.ts +136 -0
- package/lib/models/Post.js +406 -0
- package/lib/models/PostLock.d.ts +67 -0
- package/lib/models/PostLock.js +112 -0
- package/lib/models/PostRevision.d.ts +45 -0
- package/lib/models/PostRevision.js +82 -0
- package/lib/models/PublicContent.d.ts +283 -0
- package/lib/models/PublicContent.js +577 -0
- package/lib/models/Redirect.d.ts +123 -0
- package/lib/models/Redirect.js +225 -0
- package/lib/models/Settings.d.ts +61 -0
- package/lib/models/Settings.js +128 -0
- package/lib/models/Snippet.d.ts +36 -0
- package/lib/models/Snippet.js +64 -0
- package/lib/models/Tag.d.ts +23 -0
- package/lib/models/Tag.js +117 -0
- package/lib/models/Taxonomy.d.ts +127 -0
- package/lib/models/Taxonomy.js +321 -0
- package/lib/models/TwoFactor.d.ts +26 -0
- package/lib/models/TwoFactor.js +60 -0
- package/lib/models/User.d.ts +49 -0
- package/lib/models/User.js +128 -0
- package/lib/models/derive.d.ts +69 -0
- package/lib/models/derive.js +81 -0
- package/lib/models/pagination.d.ts +30 -0
- package/lib/models/pagination.js +36 -0
- package/lib/models/visibility.d.ts +31 -0
- package/lib/models/visibility.js +47 -0
- package/lib/routes/App.d.ts +2 -0
- package/lib/routes/App.js +146 -0
- package/lib/routes/api/admin.d.ts +6 -0
- package/lib/routes/api/admin.js +11 -0
- package/lib/routes/api/auth.d.ts +6 -0
- package/lib/routes/api/auth.js +24 -0
- package/lib/routes/api/authors.d.ts +5 -0
- package/lib/routes/api/authors.js +8 -0
- package/lib/routes/api/categories.d.ts +8 -0
- package/lib/routes/api/categories.js +15 -0
- package/lib/routes/api/comments.d.ts +8 -0
- package/lib/routes/api/comments.js +35 -0
- package/lib/routes/api/content-model.d.ts +17 -0
- package/lib/routes/api/content-model.js +67 -0
- package/lib/routes/api/cron.d.ts +6 -0
- package/lib/routes/api/cron.js +9 -0
- package/lib/routes/api/export.d.ts +5 -0
- package/lib/routes/api/export.js +11 -0
- package/lib/routes/api/feed.d.ts +5 -0
- package/lib/routes/api/feed.js +16 -0
- package/lib/routes/api/media.d.ts +8 -0
- package/lib/routes/api/media.js +25 -0
- package/lib/routes/api/navigation.d.ts +12 -0
- package/lib/routes/api/navigation.js +17 -0
- package/lib/routes/api/ops.d.ts +9 -0
- package/lib/routes/api/ops.js +19 -0
- package/lib/routes/api/pages.d.ts +8 -0
- package/lib/routes/api/pages.js +21 -0
- package/lib/routes/api/passkeys.d.ts +7 -0
- package/lib/routes/api/passkeys.js +13 -0
- package/lib/routes/api/posts.d.ts +8 -0
- package/lib/routes/api/posts.js +39 -0
- package/lib/routes/api/profile.d.ts +6 -0
- package/lib/routes/api/profile.js +8 -0
- package/lib/routes/api/redirects.d.ts +12 -0
- package/lib/routes/api/redirects.js +13 -0
- package/lib/routes/api/settings.d.ts +8 -0
- package/lib/routes/api/settings.js +15 -0
- package/lib/routes/api/snippets.d.ts +15 -0
- package/lib/routes/api/snippets.js +16 -0
- package/lib/routes/api/tags.d.ts +8 -0
- package/lib/routes/api/tags.js +14 -0
- package/lib/routes/api/tokens.d.ts +7 -0
- package/lib/routes/api/tokens.js +15 -0
- package/lib/routes/api/two-factor.d.ts +7 -0
- package/lib/routes/api/two-factor.js +15 -0
- package/lib/routes/api/users.d.ts +8 -0
- package/lib/routes/api/users.js +25 -0
- package/lib/routes/api/v1.d.ts +12 -0
- package/lib/routes/api/v1.js +55 -0
- package/lib/routes/api/verification.d.ts +6 -0
- package/lib/routes/api/verification.js +11 -0
- package/lib/server/index.d.ts +24 -0
- package/lib/server/index.js +110 -0
- package/lib/types/index.d.ts +298 -0
- package/lib/types/index.js +1 -0
- package/lib/vite.d.ts +2 -0
- package/lib/vite.js +101 -0
- package/mail/comment-moderation.html +27 -0
- package/mail/comment-moderation.txt +13 -0
- package/mail/comment-reply.html +28 -0
- package/mail/comment-reply.txt +14 -0
- package/mail/invitation.html +25 -0
- package/mail/invitation.txt +11 -0
- package/mail/member-magic-link.html +23 -0
- package/mail/member-magic-link.txt +10 -0
- package/mail/newsletter.html +26 -0
- package/mail/newsletter.txt +13 -0
- package/mail/password-reset.html +26 -0
- package/mail/password-reset.txt +10 -0
- package/mail/verify-email.html +25 -0
- package/mail/verify-email.txt +8 -0
- package/package.json +85 -4
|
@@ -0,0 +1,75 @@
|
|
|
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 AdminCategories() {
|
|
7
|
+
const { t } = useT();
|
|
8
|
+
const [categories, setCategories] = useState([]);
|
|
9
|
+
const [loading, setLoading] = useState(true);
|
|
10
|
+
const [showForm, setShowForm] = useState(false);
|
|
11
|
+
const [editingId, setEditingId] = useState(null);
|
|
12
|
+
const [formData, setFormData] = useState({ name: '', slug: '', description: '' });
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
loadCategories();
|
|
15
|
+
}, []);
|
|
16
|
+
const loadCategories = async () => {
|
|
17
|
+
try {
|
|
18
|
+
const res = await api.get('/api/categories');
|
|
19
|
+
setCategories(res?.categories || []);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error('Failed to load categories:', error);
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
setLoading(false);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const handleSubmit = async (e) => {
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
try {
|
|
31
|
+
if (editingId) {
|
|
32
|
+
await api.put(`/api/categories/${editingId}`, formData);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
await api.post('/api/categories', formData);
|
|
36
|
+
}
|
|
37
|
+
setFormData({ name: '', slug: '', description: '' });
|
|
38
|
+
setShowForm(false);
|
|
39
|
+
setEditingId(null);
|
|
40
|
+
loadCategories();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
alert(error.message || t('Failed to save category'));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const handleEdit = (category) => {
|
|
47
|
+
setFormData({
|
|
48
|
+
name: category.name,
|
|
49
|
+
slug: category.slug,
|
|
50
|
+
description: category.description || ''
|
|
51
|
+
});
|
|
52
|
+
setEditingId(category.id);
|
|
53
|
+
setShowForm(true);
|
|
54
|
+
};
|
|
55
|
+
const handleDelete = async (id) => {
|
|
56
|
+
if (!confirm(t('Are you sure you want to delete this category?')))
|
|
57
|
+
return;
|
|
58
|
+
try {
|
|
59
|
+
await api.delete(`/api/categories/${id}`);
|
|
60
|
+
setCategories(categories.filter(c => c.id !== id));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
alert(t('Failed to delete category'));
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const handleCancel = () => {
|
|
67
|
+
setFormData({ name: '', slug: '', description: '' });
|
|
68
|
+
setShowForm(false);
|
|
69
|
+
setEditingId(null);
|
|
70
|
+
};
|
|
71
|
+
if (loading) {
|
|
72
|
+
return (_jsx(AdminLayout, { title: t('Categories'), children: _jsx("div", { className: "admin-loading", children: t('Loading...') }) }));
|
|
73
|
+
}
|
|
74
|
+
return (_jsx(AdminLayout, { title: t('Categories'), 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 Category') : t('Add New Category') }), _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('Category 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('category-slug (auto-generated if empty)') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", children: t('Description') }), _jsx("textarea", { value: formData.description, onChange: e => setFormData({ ...formData, description: e.target.value }), className: "admin-textarea", style: { minHeight: '80px' }, placeholder: t('Category description') })] }), _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 Category') }), 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 Categories') }), categories.length === 0 ? (_jsx("p", { style: { color: 'var(--fg-muted)' }, children: t('No categories yet.') })) : (_jsxs("table", { className: "admin-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: t('Name') }), _jsx("th", { children: t('Slug') }), _jsx("th", { children: t('Posts') }), _jsx("th", { children: t('Actions') })] }) }), _jsx("tbody", { children: categories.map(cat => (_jsxs("tr", { children: [_jsx("td", { children: cat.name }), _jsx("td", { children: _jsx("code", { children: cat.slug }) }), _jsx("td", { children: cat.post_count || 0 }), _jsx("td", { children: _jsxs("div", { style: { display: 'flex', gap: '0.5rem' }, children: [_jsx("button", { onClick: () => handleEdit(cat), className: "admin-btn admin-btn-secondary", children: t('Edit') }), _jsx("button", { onClick: () => handleDelete(cat.id), className: "admin-btn admin-btn-danger", children: t('Delete') })] }) })] }, cat.id))) })] }))] })] }) }));
|
|
75
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The comment moderation screen.
|
|
4
|
+
*
|
|
5
|
+
* A tab per status with the count behind it, bulk actions over a checked
|
|
6
|
+
* page, and each comment's thread a click away — a reply makes no sense to
|
|
7
|
+
* judge without what it answers. The settings that decide what lands in each
|
|
8
|
+
* tab (the blocklist, the link limit, who is emailed) live here too, beside
|
|
9
|
+
* the results they produce.
|
|
10
|
+
*/
|
|
11
|
+
export default function AdminComments(): React.JSX.Element;
|
|
@@ -0,0 +1,247 @@
|
|
|
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 { Pagination } from "../../components/admin/Pagination.js";
|
|
6
|
+
import { useT, t, slots } from "../../i18n/index.js";
|
|
7
|
+
const TABS = [
|
|
8
|
+
{ key: 'all' },
|
|
9
|
+
{ key: 'pending' },
|
|
10
|
+
{ key: 'approved' },
|
|
11
|
+
{ key: 'spam' },
|
|
12
|
+
{ key: 'trash' }
|
|
13
|
+
];
|
|
14
|
+
/** A tab's name. Called while rendering, so it follows the admin's language. */
|
|
15
|
+
function tabLabel(tab) {
|
|
16
|
+
switch (tab) {
|
|
17
|
+
case 'all': return t('All');
|
|
18
|
+
case 'pending': return t('Pending');
|
|
19
|
+
case 'approved': return t('Approved');
|
|
20
|
+
case 'spam': return t('Spam');
|
|
21
|
+
case 'trash': return t('Trash');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** A comment's status, as its badge shows it. */
|
|
25
|
+
function statusLabel(status) {
|
|
26
|
+
switch (status) {
|
|
27
|
+
case 'pending': return t('pending');
|
|
28
|
+
case 'approved': return t('approved');
|
|
29
|
+
case 'spam': return t('spam');
|
|
30
|
+
case 'trash': return t('trash');
|
|
31
|
+
default: return status;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const BADGES = {
|
|
35
|
+
pending: 'admin-badge-warning',
|
|
36
|
+
approved: 'admin-badge-success',
|
|
37
|
+
spam: 'admin-badge-danger',
|
|
38
|
+
trash: 'admin-badge-info'
|
|
39
|
+
};
|
|
40
|
+
/** The tab a link asked for — the moderation email links to `?status=pending`. */
|
|
41
|
+
function initialTab() {
|
|
42
|
+
const asked = new URLSearchParams(window.location.search).get('status');
|
|
43
|
+
return TABS.some(tab => tab.key === asked) ? asked : 'all';
|
|
44
|
+
}
|
|
45
|
+
const excerpt = (text = '', length = 80) => (text.length > length ? `${text.slice(0, length)}…` : text);
|
|
46
|
+
/**
|
|
47
|
+
* The comment moderation screen.
|
|
48
|
+
*
|
|
49
|
+
* A tab per status with the count behind it, bulk actions over a checked
|
|
50
|
+
* page, and each comment's thread a click away — a reply makes no sense to
|
|
51
|
+
* judge without what it answers. The settings that decide what lands in each
|
|
52
|
+
* tab (the blocklist, the link limit, who is emailed) live here too, beside
|
|
53
|
+
* the results they produce.
|
|
54
|
+
*/
|
|
55
|
+
export default function AdminComments() {
|
|
56
|
+
const { t, tn, locale } = useT();
|
|
57
|
+
const [tab, setTab] = useState(initialTab);
|
|
58
|
+
const [page, setPage] = useState(1);
|
|
59
|
+
const [comments, setComments] = useState([]);
|
|
60
|
+
const [counts, setCounts] = useState(null);
|
|
61
|
+
const [meta, setMeta] = useState(null);
|
|
62
|
+
const [selected, setSelected] = useState(new Set());
|
|
63
|
+
const [loading, setLoading] = useState(true);
|
|
64
|
+
const [threadFor, setThreadFor] = useState(null);
|
|
65
|
+
const [showSettings, setShowSettings] = useState(false);
|
|
66
|
+
const load = async () => {
|
|
67
|
+
setLoading(true);
|
|
68
|
+
try {
|
|
69
|
+
const res = await api.get(`/api/comments?status=${tab}&page=${page}`);
|
|
70
|
+
setComments(res?.comments || []);
|
|
71
|
+
setCounts(res?.counts || null);
|
|
72
|
+
setMeta(res?.meta || null);
|
|
73
|
+
setSelected(new Set());
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.error('Failed to load comments:', error);
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
setLoading(false);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
useEffect(() => { load(); }, [tab, page]);
|
|
83
|
+
const switchTab = (next) => {
|
|
84
|
+
setTab(next);
|
|
85
|
+
setPage(1);
|
|
86
|
+
setThreadFor(null);
|
|
87
|
+
};
|
|
88
|
+
const setStatus = async (id, status) => {
|
|
89
|
+
try {
|
|
90
|
+
await api.put(`/api/comments/${id}/status`, { status });
|
|
91
|
+
await load();
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
alert(error.message || t('Failed to update comment'));
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const deleteForever = async (id) => {
|
|
98
|
+
if (!confirm(t('Delete this comment permanently? Its replies stay, moved up a level. This cannot be undone.')))
|
|
99
|
+
return;
|
|
100
|
+
try {
|
|
101
|
+
await api.delete(`/api/comments/${id}?force=true`);
|
|
102
|
+
await load();
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
alert(error.message || t('Failed to delete comment'));
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const bulk = async (action) => {
|
|
109
|
+
if (!selected.size)
|
|
110
|
+
return;
|
|
111
|
+
if (action === 'delete' && !confirm(tn('Delete {count} comment permanently? This cannot be undone.', 'Delete {count} comments permanently? This cannot be undone.', selected.size)))
|
|
112
|
+
return;
|
|
113
|
+
try {
|
|
114
|
+
await api.post('/api/comments/bulk', { ids: [...selected], action });
|
|
115
|
+
await load();
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
alert(error.message || t('Bulk action failed'));
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const empty = async (status) => {
|
|
122
|
+
const n = counts?.[status] ?? 0;
|
|
123
|
+
const question = status === 'spam'
|
|
124
|
+
? tn('Permanently delete the {count} comment in spam? This cannot be undone.', 'Permanently delete all {count} comments in spam? This cannot be undone.', n)
|
|
125
|
+
: tn('Permanently delete the {count} comment in the trash? This cannot be undone.', 'Permanently delete all {count} comments in the trash? This cannot be undone.', n);
|
|
126
|
+
if (!confirm(question))
|
|
127
|
+
return;
|
|
128
|
+
try {
|
|
129
|
+
await api.post('/api/comments/empty', { status });
|
|
130
|
+
await load();
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
alert(error.message || (status === 'spam' ? t('Failed to empty spam') : t('Failed to empty the trash')));
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const toggle = (id) => {
|
|
137
|
+
const next = new Set(selected);
|
|
138
|
+
if (next.has(id))
|
|
139
|
+
next.delete(id);
|
|
140
|
+
else
|
|
141
|
+
next.add(id);
|
|
142
|
+
setSelected(next);
|
|
143
|
+
};
|
|
144
|
+
const allChecked = comments.length > 0 && comments.every(c => selected.has(c.id));
|
|
145
|
+
return (_jsx(AdminLayout, { title: t('Comments'), children: _jsxs("div", { className: "admin-card", children: [_jsxs("div", { className: "admin-card-header", style: { flexWrap: 'wrap', gap: '0.5rem' }, children: [_jsx("h2", { className: "admin-card-title", children: t('Comments') }), _jsxs("div", { style: { display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }, children: [TABS.map(({ key }) => (_jsxs("button", { onClick: () => switchTab(key), className: `admin-btn ${tab === key ? 'admin-btn-primary' : 'admin-btn-secondary'}`, children: [tabLabel(key), counts ? ` (${counts[key]})` : ''] }, key))), _jsx("button", { onClick: () => setShowSettings(!showSettings), className: "admin-btn admin-btn-secondary", children: showSettings ? t('Hide settings') : t('Spam settings') })] })] }), showSettings && _jsx(SettingsPanel, {}), _jsxs("div", { style: { display: 'flex', gap: '0.5rem', flexWrap: 'wrap', alignItems: 'center', padding: '0.75rem 1rem', borderBottom: '1px solid var(--border)' }, children: [_jsxs("label", { style: { display: 'flex', gap: '0.5rem', alignItems: 'center' }, children: [_jsx("input", { type: "checkbox", checked: allChecked, onChange: () => setSelected(allChecked ? new Set() : new Set(comments.map(c => c.id))), "aria-label": t('Select all on this page') }), _jsx("span", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem' }, children: tn('{count} selected', '{count} selected', selected.size) })] }), tab !== 'approved' && tab !== 'trash' && _jsx(BulkButton, { label: t('Approve'), onClick: () => bulk('approve'), disabled: !selected.size }), (tab === 'all' || tab === 'approved') && _jsx(BulkButton, { label: t('Unapprove'), onClick: () => bulk('pending'), disabled: !selected.size }), tab !== 'spam' && _jsx(BulkButton, { label: t('Mark spam'), onClick: () => bulk('spam'), disabled: !selected.size }), tab === 'spam' && _jsx(BulkButton, { label: t('Not spam'), onClick: () => bulk('pending'), disabled: !selected.size }), tab === 'trash' && _jsx(BulkButton, { label: t('Restore'), onClick: () => bulk('pending'), disabled: !selected.size }), tab !== 'trash' && tab !== 'spam' && _jsx(BulkButton, { label: t('Trash'), onClick: () => bulk('trash'), disabled: !selected.size }), (tab === 'trash' || tab === 'spam') && _jsx(BulkButton, { label: t('Delete permanently'), danger: true, onClick: () => bulk('delete'), disabled: !selected.size }), (tab === 'spam' || tab === 'trash') && (counts?.[tab] ?? 0) > 0 && (_jsx("button", { onClick: () => empty(tab), className: "admin-btn admin-btn-danger", style: { marginLeft: 'auto' }, children: tab === 'spam' ? t('Empty spam') : t('Empty trash') }))] }), loading ? (_jsx("div", { className: "admin-loading", children: t('Loading...') })) : comments.length === 0 ? (_jsx("p", { style: { color: 'var(--fg-muted)', textAlign: 'center', padding: '2rem' }, children: {
|
|
146
|
+
all: t('No comments.'),
|
|
147
|
+
pending: t('No pending comments.'),
|
|
148
|
+
approved: t('No approved comments.'),
|
|
149
|
+
spam: t('No spam comments.'),
|
|
150
|
+
trash: t('No trash comments.')
|
|
151
|
+
}[tab] })) : (_jsx("div", { children: comments.map(comment => (_jsx("div", { style: {
|
|
152
|
+
padding: '1rem',
|
|
153
|
+
borderBottom: '1px solid var(--border)',
|
|
154
|
+
backgroundColor: comment.status === 'pending' ? 'var(--tint-warning)' : 'var(--surface)'
|
|
155
|
+
}, children: _jsxs("div", { style: { display: 'flex', gap: '0.75rem' }, children: [_jsx("input", { type: "checkbox", checked: selected.has(comment.id), onChange: () => toggle(comment.id), "aria-label": t('Select comment'), style: { marginTop: '0.25rem' } }), _jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [_jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', gap: '0.5rem', flexWrap: 'wrap', marginBottom: '0.25rem' }, children: [_jsxs("div", { children: [_jsx("strong", { children: comment.user_name || comment.author_name || t('Anonymous') }), comment.post_title && (_jsxs("span", { style: { color: 'var(--fg-muted)' }, children: [" ", t('on {title}', { title: comment.post_title })] }))] }), _jsx("span", { style: { color: 'var(--fg-muted)', fontSize: '0.875rem' }, children: new Date(comment.created_at).toLocaleString(locale) })] }), _jsxs("div", { style: { color: 'var(--fg-muted)', fontSize: '0.8125rem', wordBreak: 'break-all' }, children: [comment.user_email || comment.author_email, comment.author_ip && _jsxs(_Fragment, { children: [" \u00B7 ", comment.author_ip] })] }), comment.parent_id && (_jsxs("div", { style: { color: 'var(--fg-muted)', fontSize: '0.8125rem', marginTop: '0.25rem' }, children: ["\u21B3 ", slots(t('In reply to {name}'), { name: _jsx("strong", { children: comment.parent_author_name || t('a comment') }) }), comment.parent_content && _jsxs(_Fragment, { children: [": \u201C", excerpt(comment.parent_content), "\u201D"] })] })), _jsx("p", { style: { margin: '0.5rem 0', color: 'var(--fg)', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' }, children: comment.content }), _jsxs("div", { style: { display: 'flex', gap: '0.5rem', alignItems: 'center', flexWrap: 'wrap' }, children: [_jsx("span", { className: `admin-badge ${BADGES[comment.status]}`, children: statusLabel(comment.status) }), comment.held_reason && (_jsx("span", { style: { color: 'var(--fg-muted)', fontSize: '0.8125rem' }, title: t('Why a check held this comment'), children: comment.held_reason })), _jsxs("div", { style: { marginLeft: 'auto', display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }, children: [_jsx("button", { onClick: () => setThreadFor(threadFor?.id === comment.id ? null : comment), className: "admin-btn admin-btn-secondary", children: threadFor?.id === comment.id ? t('Hide thread') : t('Thread') }), _jsx(RowActions, { comment: comment, setStatus: setStatus, deleteForever: deleteForever })] })] }), threadFor?.id === comment.id && (_jsx(ThreadView, { postId: comment.post_id, highlight: comment.id, onChange: load }))] })] }) }, comment.id))) })), meta && _jsx(Pagination, { meta: meta, onChange: setPage, noun: t('comments') })] }) }));
|
|
156
|
+
}
|
|
157
|
+
function BulkButton({ label, onClick, disabled, danger }) {
|
|
158
|
+
return (_jsx("button", { onClick: onClick, disabled: disabled, className: `admin-btn ${danger ? 'admin-btn-danger' : 'admin-btn-secondary'}`, children: label }));
|
|
159
|
+
}
|
|
160
|
+
function RowActions({ comment, setStatus, deleteForever }) {
|
|
161
|
+
const { t } = useT();
|
|
162
|
+
const button = (label, onClick, kind = 'admin-btn-secondary') => (_jsx("button", { onClick: onClick, className: `admin-btn ${kind}`, children: label }, label));
|
|
163
|
+
switch (comment.status) {
|
|
164
|
+
case 'pending':
|
|
165
|
+
return (_jsxs(_Fragment, { children: [button(t('Approve'), () => setStatus(comment.id, 'approved'), 'admin-btn-primary'), button(t('Spam'), () => setStatus(comment.id, 'spam')), button(t('Trash'), () => setStatus(comment.id, 'trash'), 'admin-btn-danger')] }));
|
|
166
|
+
case 'approved':
|
|
167
|
+
return (_jsxs(_Fragment, { children: [button(t('Unapprove'), () => setStatus(comment.id, 'pending')), button(t('Spam'), () => setStatus(comment.id, 'spam')), button(t('Trash'), () => setStatus(comment.id, 'trash'), 'admin-btn-danger')] }));
|
|
168
|
+
case 'spam':
|
|
169
|
+
// Back to the queue rather than straight to approved: "not spam" is
|
|
170
|
+
// not the same judgement as "worth publishing".
|
|
171
|
+
return (_jsxs(_Fragment, { children: [button(t('Not spam'), () => setStatus(comment.id, 'pending')), button(t('Delete permanently'), () => deleteForever(comment.id), 'admin-btn-danger')] }));
|
|
172
|
+
case 'trash':
|
|
173
|
+
return (_jsxs(_Fragment, { children: [button(t('Restore'), () => setStatus(comment.id, 'pending')), button(t('Delete permanently'), () => deleteForever(comment.id), 'admin-btn-danger')] }));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* A post's whole thread, every status, nested as readers would see it.
|
|
178
|
+
*
|
|
179
|
+
* Moderators can reply in place; the reply posts as them, and is approved
|
|
180
|
+
* like any moderator's comment. Replies hang only off approved comments —
|
|
181
|
+
* the server refuses the rest, since readers could not see what they answer.
|
|
182
|
+
*/
|
|
183
|
+
function ThreadView({ postId, highlight, onChange }) {
|
|
184
|
+
const [thread, setThread] = useState(null);
|
|
185
|
+
const [replyTo, setReplyTo] = useState(null);
|
|
186
|
+
const [text, setText] = useState('');
|
|
187
|
+
const { t, locale } = useT();
|
|
188
|
+
const load = () => (api.get(`/api/posts/${postId}/comments?all=true`)
|
|
189
|
+
.then(res => setThread(res?.comments || []))
|
|
190
|
+
.catch(() => setThread([])));
|
|
191
|
+
useEffect(() => { load(); }, [postId]);
|
|
192
|
+
const reply = async (parentId) => {
|
|
193
|
+
try {
|
|
194
|
+
await api.post(`/api/posts/${postId}/comments`, { content: text, parent_id: parentId });
|
|
195
|
+
setText('');
|
|
196
|
+
setReplyTo(null);
|
|
197
|
+
await load();
|
|
198
|
+
onChange();
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
alert(error.message || t('Failed to post reply'));
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
const render = (nodes) => (_jsx("ul", { style: { listStyle: 'none', margin: 0, paddingLeft: '1rem', borderLeft: '2px solid var(--border)' }, children: nodes.map(node => (_jsxs("li", { style: { margin: '0.5rem 0' }, children: [_jsxs("div", { style: {
|
|
205
|
+
padding: '0.5rem',
|
|
206
|
+
borderRadius: 6,
|
|
207
|
+
outline: node.id === highlight ? '2px solid var(--accent, var(--border))' : undefined
|
|
208
|
+
}, children: [_jsxs("div", { style: { fontSize: '0.8125rem' }, children: [_jsx("strong", { children: node.user_name || node.author_name || t('Anonymous') }), ' ', _jsx("span", { className: `admin-badge ${BADGES[node.status]}`, children: statusLabel(node.status) }), ' ', _jsx("span", { style: { color: 'var(--fg-muted)' }, children: new Date(node.created_at).toLocaleString(locale) })] }), _jsx("p", { style: { margin: '0.25rem 0', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' }, children: node.content }), node.status === 'approved' && (_jsx("button", { className: "admin-btn admin-btn-secondary", onClick: () => setReplyTo(replyTo === node.id ? null : node.id), children: replyTo === node.id ? t('Cancel') : t('Reply') })), replyTo === node.id && (_jsxs("div", { style: { marginTop: '0.5rem' }, children: [_jsx("textarea", { className: "admin-textarea", rows: 3, value: text, onChange: e => setText(e.target.value), "aria-label": t('Reply') }), _jsx("button", { className: "admin-btn admin-btn-primary", style: { marginTop: '0.5rem' }, onClick: () => reply(node.id), disabled: text.trim().length < 3, children: t('Post reply') })] }))] }), node.replies && node.replies.length > 0 && render(node.replies)] }, node.id))) }));
|
|
209
|
+
return (_jsx("div", { style: { marginTop: '0.75rem' }, children: thread === null ? _jsx("div", { className: "admin-loading", children: t('Loading thread...') }) : render(thread) }));
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* What decides which tab a new comment lands in.
|
|
213
|
+
*
|
|
214
|
+
* Kept on this page rather than the general settings: these are tuned by
|
|
215
|
+
* looking at what got caught, and the spam tab is right here.
|
|
216
|
+
*/
|
|
217
|
+
function SettingsPanel() {
|
|
218
|
+
const [settings, setSettings] = useState(null);
|
|
219
|
+
const [canManage, setCanManage] = useState(false);
|
|
220
|
+
const [saved, setSaved] = useState(false);
|
|
221
|
+
const { t } = useT();
|
|
222
|
+
useEffect(() => {
|
|
223
|
+
api.get('/api/comments/settings')
|
|
224
|
+
.then(res => {
|
|
225
|
+
setSettings(res.settings);
|
|
226
|
+
setCanManage(res.can_manage);
|
|
227
|
+
})
|
|
228
|
+
.catch(() => setSettings(null));
|
|
229
|
+
}, []);
|
|
230
|
+
if (!settings)
|
|
231
|
+
return _jsx("div", { className: "admin-loading", children: t('Loading settings...') });
|
|
232
|
+
const save = async (e) => {
|
|
233
|
+
e.preventDefault();
|
|
234
|
+
try {
|
|
235
|
+
const res = await api.put('/api/comments/settings', settings);
|
|
236
|
+
setSettings(res.settings);
|
|
237
|
+
setSaved(true);
|
|
238
|
+
setTimeout(() => setSaved(false), 2000);
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
alert(error.message || t('Failed to save settings'));
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
return (_jsxs("form", { onSubmit: save, style: { padding: '1rem', borderBottom: '1px solid var(--border)' }, children: [_jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: "comment-blocklist", children: t('Blocklist') }), _jsx("textarea", { id: "comment-blocklist", className: "admin-textarea", rows: 6, value: settings.comment_blocklist, disabled: !canManage, onChange: e => setSettings({ ...settings, comment_blocklist: e.target.value }), placeholder: `${t('One per line:')}\n${t('cheap pills')}\nspammer@example.com\n@spam-domain.example\n203.0.113.7\n198.51.100.0/24` }), _jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.8125rem' }, children: slots(t('Words or phrases, email addresses, {domains}, and IP addresses or ranges. A comment that matches goes straight to spam. IPv6 entries cover their whole /64. Lines starting with # are ignored.'), {
|
|
245
|
+
domains: _jsx("code", { children: t('@domains') })
|
|
246
|
+
}) })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: "comment-max-links", children: t('Hold comments with more than this many links') }), _jsx("input", { id: "comment-max-links", className: "admin-input", type: "number", min: 0, max: 100, value: settings.comment_max_links, disabled: !canManage, onChange: e => setSettings({ ...settings, comment_max_links: Number(e.target.value) }) })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: "comment-notify", children: t('Email about comments awaiting moderation') }), _jsxs("select", { id: "comment-notify", className: "admin-select", value: settings.comment_notify, disabled: !canManage, onChange: e => setSettings({ ...settings, comment_notify: e.target.value }), children: [_jsx("option", { value: "author", children: t('The post\'s author') }), _jsx("option", { value: "moderators", children: t('Everyone who can moderate') }), _jsx("option", { value: "both", children: t('The author and everyone who can moderate') }), _jsx("option", { value: "none", children: t('Nobody') })] })] }), canManage ? (_jsx("button", { type: "submit", className: "admin-btn admin-btn-primary", children: saved ? t('Saved') : t('Save settings') })) : (_jsx("p", { style: { color: 'var(--fg-muted)', fontSize: '0.8125rem' }, children: t('Only administrators can change these.') }))] }));
|
|
247
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
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, slots } from "../../i18n/index.js";
|
|
6
|
+
const FIELD_TYPES = ['text', 'textarea', 'number', 'url', 'date', 'boolean', 'select'];
|
|
7
|
+
const SUPPORT_KEYS = ['excerpt', 'featured_image', 'comments', 'categories', 'tags', 'custom_fields'];
|
|
8
|
+
const ALL_SUPPORTS = { excerpt: true, featured_image: true, comments: true, categories: true, tags: true, custom_fields: true };
|
|
9
|
+
const EMPTY = {
|
|
10
|
+
key: '',
|
|
11
|
+
singular_label: '',
|
|
12
|
+
plural_label: '',
|
|
13
|
+
description: '',
|
|
14
|
+
route_base: '',
|
|
15
|
+
public: true,
|
|
16
|
+
supports: ALL_SUPPORTS,
|
|
17
|
+
fields: []
|
|
18
|
+
};
|
|
19
|
+
function toForm(type) {
|
|
20
|
+
return {
|
|
21
|
+
key: type.key,
|
|
22
|
+
singular_label: type.singular_label,
|
|
23
|
+
plural_label: type.plural_label,
|
|
24
|
+
description: type.description ?? '',
|
|
25
|
+
route_base: type.route_base,
|
|
26
|
+
public: type.public,
|
|
27
|
+
supports: { ...type.supports },
|
|
28
|
+
fields: type.fields.map(field => ({ ...field, optionsText: field.options.join('\n') }))
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export default function AdminContentTypes() {
|
|
32
|
+
const { t } = useT();
|
|
33
|
+
const fieldTypeLabels = {
|
|
34
|
+
text: t('Text'),
|
|
35
|
+
textarea: t('Long text'),
|
|
36
|
+
number: t('Number'),
|
|
37
|
+
url: 'URL',
|
|
38
|
+
date: t('Date'),
|
|
39
|
+
boolean: t('Yes / no'),
|
|
40
|
+
select: t('Choice')
|
|
41
|
+
};
|
|
42
|
+
const supportLabels = {
|
|
43
|
+
excerpt: t('Excerpt'),
|
|
44
|
+
featured_image: t('Featured image'),
|
|
45
|
+
comments: t('Comments'),
|
|
46
|
+
categories: t('Categories'),
|
|
47
|
+
tags: t('Tags'),
|
|
48
|
+
custom_fields: t('Custom fields')
|
|
49
|
+
};
|
|
50
|
+
const [types, setTypes] = useState([]);
|
|
51
|
+
const [loading, setLoading] = useState(true);
|
|
52
|
+
const [editing, setEditing] = useState(null);
|
|
53
|
+
const [form, setForm] = useState(EMPTY);
|
|
54
|
+
const [showForm, setShowForm] = useState(false);
|
|
55
|
+
const [saving, setSaving] = useState(false);
|
|
56
|
+
const [message, setMessage] = useState('');
|
|
57
|
+
useEffect(() => { load(); }, []);
|
|
58
|
+
const load = async () => {
|
|
59
|
+
try {
|
|
60
|
+
const res = await api.get('/api/content-types');
|
|
61
|
+
setTypes(res?.content_types || []);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error('Failed to load content types:', error);
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
setLoading(false);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const startNew = () => {
|
|
71
|
+
setEditing(null);
|
|
72
|
+
setForm(EMPTY);
|
|
73
|
+
setShowForm(true);
|
|
74
|
+
setMessage('');
|
|
75
|
+
};
|
|
76
|
+
const startEdit = (type) => {
|
|
77
|
+
setEditing(type);
|
|
78
|
+
setForm(toForm(type));
|
|
79
|
+
setShowForm(true);
|
|
80
|
+
setMessage('');
|
|
81
|
+
};
|
|
82
|
+
const cancel = () => {
|
|
83
|
+
setShowForm(false);
|
|
84
|
+
setEditing(null);
|
|
85
|
+
};
|
|
86
|
+
const save = async (event) => {
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
if (editing && !editing.builtin && form.route_base !== editing.route_base &&
|
|
89
|
+
!confirm(t('Every {name} will move from {from} to {to}. Old links will break unless you add a redirect. Continue?', { name: editing.singular_label.toLowerCase(), from: editing.route_base, to: form.route_base }))) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
setSaving(true);
|
|
93
|
+
try {
|
|
94
|
+
const payload = {
|
|
95
|
+
...(editing ? {} : { key: form.key }),
|
|
96
|
+
singular_label: form.singular_label,
|
|
97
|
+
plural_label: form.plural_label,
|
|
98
|
+
description: form.description,
|
|
99
|
+
...(editing?.builtin ? {} : { route_base: form.route_base, public: form.public }),
|
|
100
|
+
supports: form.supports,
|
|
101
|
+
fields: form.fields.map(({ optionsText, ...field }) => ({
|
|
102
|
+
...field,
|
|
103
|
+
options: field.type === 'select' ? optionsText.split('\n').map(o => o.trim()).filter(Boolean) : []
|
|
104
|
+
}))
|
|
105
|
+
};
|
|
106
|
+
const res = editing
|
|
107
|
+
? await api.put(`/api/content-types/${editing.id}`, payload)
|
|
108
|
+
: await api.post('/api/content-types', payload);
|
|
109
|
+
setMessage(res?.notice || t('Saved.'));
|
|
110
|
+
setShowForm(false);
|
|
111
|
+
setEditing(null);
|
|
112
|
+
await load();
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
alert(error.message || t('Could not save the content type'));
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
setSaving(false);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const remove = async (type) => {
|
|
122
|
+
if (!confirm(t('Delete the {name} type? This only works when no entries use it.', { name: type.plural_label })))
|
|
123
|
+
return;
|
|
124
|
+
try {
|
|
125
|
+
await api.delete(`/api/content-types/${type.id}`);
|
|
126
|
+
await load();
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
alert(error.message || t('Could not delete the content type'));
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const updateField = (index, change) => {
|
|
133
|
+
setForm(prev => ({ ...prev, fields: prev.fields.map((field, i) => (i === index ? { ...field, ...change } : field)) }));
|
|
134
|
+
};
|
|
135
|
+
const moveField = (index, by) => {
|
|
136
|
+
setForm(prev => {
|
|
137
|
+
const fields = [...prev.fields];
|
|
138
|
+
const target = index + by;
|
|
139
|
+
if (target < 0 || target >= fields.length)
|
|
140
|
+
return prev;
|
|
141
|
+
[fields[index], fields[target]] = [fields[target], fields[index]];
|
|
142
|
+
return { ...prev, fields };
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
const addField = () => {
|
|
146
|
+
setForm(prev => ({
|
|
147
|
+
...prev,
|
|
148
|
+
fields: [...prev.fields, { key: '', label: '', type: 'text', options: [], optionsText: '', required: false, help_text: null }]
|
|
149
|
+
}));
|
|
150
|
+
};
|
|
151
|
+
if (loading) {
|
|
152
|
+
return (_jsx(AdminLayout, { title: t('Content types'), children: _jsx("div", { className: "admin-loading", children: t('Loading...') }) }));
|
|
153
|
+
}
|
|
154
|
+
return (_jsxs(AdminLayout, { title: t('Content types'), children: [message && _jsx("div", { className: "admin-card", role: "status", children: message }), _jsxs("div", { className: "admin-card", children: [_jsxs("div", { className: "admin-card-header", children: [_jsx("h2", { className: "admin-card-title", children: t('Content types') }), _jsx("button", { type: "button", className: "admin-btn admin-btn-primary", onClick: startNew, children: t('+ New type') })] }), _jsxs("p", { style: { color: 'var(--fg-muted)', marginTop: 0 }, children: [t('Each type is written in the same editor as posts and gets its own address on the public site.'), ' ', slots(t('Types listed here appear in the content API as {code}.'), { code: _jsx("code", { children: "/api/v1/posts?type=key" }) })] }), _jsxs("table", { className: "admin-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: t('Name') }), _jsx("th", { children: t('Key') }), _jsx("th", { children: t('Lives at') }), _jsx("th", { children: t('Fields') }), _jsx("th", { children: t('Actions') })] }) }), _jsx("tbody", { children: types.map(type => (_jsxs("tr", { children: [_jsxs("td", { children: [type.plural_label, type.builtin && _jsx("span", { className: "admin-badge admin-badge-info", style: { marginLeft: '0.5rem' }, children: t('Built in') }), !type.public && _jsx("span", { className: "admin-badge admin-badge-warning", style: { marginLeft: '0.5rem' }, children: t('Private') })] }), _jsx("td", { children: _jsx("code", { children: type.key }) }), _jsx("td", { children: _jsxs("code", { children: [type.route_base, "/\u2026"] }) }), _jsx("td", { children: type.supports.custom_fields ? type.fields.length : '—' }), _jsx("td", { children: _jsxs("div", { style: { display: 'flex', gap: '0.5rem' }, children: [_jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: () => startEdit(type), children: t('Edit') }), !type.builtin && (_jsx("button", { type: "button", className: "admin-btn admin-btn-danger", onClick: () => remove(type), children: t('Delete') }))] }) })] }, type.id))) })] })] }), showForm && (_jsxs("form", { className: "admin-card", onSubmit: save, children: [_jsx("h3", { className: "admin-card-title", children: editing ? t('Edit {name}', { name: editing.plural_label }) : t('New content type') }), _jsxs("div", { className: "admin-grid admin-grid-2", children: [_jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: "ct-singular", children: t('Singular label') }), _jsx("input", { id: "ct-singular", className: "admin-input", required: true, value: form.singular_label, onChange: e => setForm({ ...form, singular_label: e.target.value }), placeholder: t('Recipe') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: "ct-plural", children: t('Plural label') }), _jsx("input", { id: "ct-plural", className: "admin-input", required: true, value: form.plural_label, onChange: e => setForm({ ...form, plural_label: e.target.value }), placeholder: t('Recipes') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: "ct-key", children: t('Key') }), _jsx("input", { id: "ct-key", className: "admin-input", required: true, disabled: Boolean(editing), value: form.key, onChange: e => setForm({ ...form, key: e.target.value.toLowerCase().replace(/[^a-z0-9_]/g, '_') }), placeholder: t('recipe') }), _jsx("small", { style: { color: 'var(--fg-muted)' }, children: t('What the API calls it. Fixed once created.') })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: "ct-route", children: t('Route base') }), _jsx("input", { id: "ct-route", className: "admin-input", disabled: Boolean(editing?.builtin), value: form.route_base, onChange: e => setForm({ ...form, route_base: e.target.value }), placeholder: `/${form.key.replace(/_/g, '-') || t('recipes')}` }), _jsx("small", { style: { color: 'var(--fg-muted)' }, children: slots(t('Entries live at {code}.'), { code: _jsxs("code", { children: [form.route_base || `/${form.key.replace(/_/g, '-')}`, "/slug"] }) }) })] })] }), _jsxs("div", { className: "admin-form-group", children: [_jsx("label", { className: "admin-label", htmlFor: "ct-description", children: t('Description') }), _jsx("textarea", { id: "ct-description", className: "admin-textarea", value: form.description, onChange: e => setForm({ ...form, description: e.target.value }), style: { minHeight: '60px' } })] }), !editing?.builtin && (_jsx("div", { className: "admin-form-group", children: _jsxs("label", { style: { display: 'flex', gap: '0.5rem', alignItems: 'center' }, children: [_jsx("input", { type: "checkbox", checked: form.public, onChange: e => setForm({ ...form, public: e.target.checked }) }), t('Public — listed in the content API, the sitemap and the public site')] }) })), _jsxs("fieldset", { className: "admin-form-group", style: { border: 'none', padding: 0 }, children: [_jsx("legend", { className: "admin-label", children: t('Editor panels') }), _jsx("div", { style: { display: 'flex', flexWrap: 'wrap', gap: '1rem' }, children: SUPPORT_KEYS.map(key => (_jsxs("label", { style: { display: 'flex', gap: '0.4rem', alignItems: 'center' }, children: [_jsx("input", { type: "checkbox", checked: form.supports[key], onChange: e => setForm({ ...form, supports: { ...form.supports, [key]: e.target.checked } }) }), supportLabels[key]] }, key))) })] }), form.supports.custom_fields && (_jsxs("div", { className: "admin-form-group", children: [_jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' }, children: [_jsx("span", { className: "admin-label", children: t('Custom fields') }), _jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: addField, children: t('+ Add field') })] }), form.fields.length === 0 && _jsx("p", { style: { color: 'var(--fg-muted)' }, children: t('No custom fields yet.') }), form.fields.map((field, index) => (_jsxs("div", { style: { border: '1px solid var(--border)', borderRadius: '0.5rem', padding: '0.75rem', marginTop: '0.5rem' }, children: [_jsxs("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(10rem, 1fr))', gap: '0.5rem' }, children: [_jsx("input", { className: "admin-input", "aria-label": t('Field label'), placeholder: t('Label'), value: field.label, required: true, onChange: e => updateField(index, {
|
|
155
|
+
label: e.target.value,
|
|
156
|
+
// A new field takes its key from its label until the
|
|
157
|
+
// key is typed into directly.
|
|
158
|
+
...(field.key === '' || field.key === slugKey(field.label) ? { key: slugKey(e.target.value) } : {})
|
|
159
|
+
}) }), _jsx("input", { className: "admin-input", "aria-label": t('Field key'), placeholder: t('key'), value: field.key, required: true, onChange: e => updateField(index, { key: e.target.value.toLowerCase().replace(/[^a-z0-9_]/g, '_') }) }), _jsx("select", { className: "admin-input", "aria-label": t('Field type'), value: field.type, onChange: e => updateField(index, { type: e.target.value }), children: FIELD_TYPES.map(type => _jsx("option", { value: type, children: fieldTypeLabels[type] }, type)) })] }), field.type === 'select' && (_jsx("textarea", { className: "admin-textarea", "aria-label": t('Choices, one per line'), placeholder: t('One choice per line'), value: field.optionsText, onChange: e => updateField(index, { optionsText: e.target.value }), style: { minHeight: '70px', marginTop: '0.5rem' } })), _jsx("input", { className: "admin-input", "aria-label": t('Help text'), placeholder: t('Help text (optional)'), value: field.help_text ?? '', onChange: e => updateField(index, { help_text: e.target.value || null }), style: { marginTop: '0.5rem' } }), _jsxs("div", { style: { display: 'flex', gap: '0.5rem', alignItems: 'center', marginTop: '0.5rem' }, children: [_jsxs("label", { style: { display: 'flex', gap: '0.4rem', alignItems: 'center', marginRight: 'auto' }, children: [_jsx("input", { type: "checkbox", checked: field.required, onChange: e => updateField(index, { required: e.target.checked }) }), t('Required')] }), _jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: () => moveField(index, -1), "aria-label": t('Move up'), children: "\u2191" }), _jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: () => moveField(index, 1), "aria-label": t('Move down'), children: "\u2193" }), _jsx("button", { type: "button", className: "admin-btn admin-btn-danger", onClick: () => setForm(prev => ({ ...prev, fields: prev.fields.filter((_, i) => i !== index) })), children: t('Remove') })] })] }, index)))] })), _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…') : t('Save') }), _jsx("button", { type: "button", className: "admin-btn admin-btn-secondary", onClick: cancel, children: t('Cancel') })] })] }))] }));
|
|
160
|
+
}
|
|
161
|
+
function slugKey(label) {
|
|
162
|
+
return label.toLowerCase().trim().replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/g, '').replace(/^(\d)/, 'f_$1').slice(0, 50);
|
|
163
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 { Link } from "../../components/Link.js";
|
|
6
|
+
import { useT } from "../../i18n/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* A request whose refusal is an answer rather than a failure.
|
|
9
|
+
*
|
|
10
|
+
* The four went out as one `Promise.all`, so a single 403 rejected the lot: an
|
|
11
|
+
* author holds neither `page.edit` nor `comment.moderate`, and those two
|
|
12
|
+
* refusals left the whole dashboard — the post count included — reading zero.
|
|
13
|
+
*/
|
|
14
|
+
const settle = (request) => request.catch(() => null);
|
|
15
|
+
export default function AdminDashboard() {
|
|
16
|
+
const { t, locale } = useT();
|
|
17
|
+
const [stats, setStats] = useState(null);
|
|
18
|
+
const [recentPosts, setRecentPosts] = useState([]);
|
|
19
|
+
const [loading, setLoading] = useState(true);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
loadDashboardData();
|
|
22
|
+
}, []);
|
|
23
|
+
/**
|
|
24
|
+
* The counts, and the five most recent posts.
|
|
25
|
+
*
|
|
26
|
+
* `/api/posts` and `/api/pages` are paginated, so the rows they return are
|
|
27
|
+
* one page of rows. Counting that array reported the page size rather than
|
|
28
|
+
* the total, and any site past its twentieth post sat at "20" for ever.
|
|
29
|
+
* `meta.total` is the count the database did, which is what a stat card is
|
|
30
|
+
* asking for.
|
|
31
|
+
*
|
|
32
|
+
* Five rows are shown, so five are asked for: this was fetching twenty posts
|
|
33
|
+
* and twenty pages, bodies and all, to render two numbers and a short table.
|
|
34
|
+
*/
|
|
35
|
+
const loadDashboardData = async () => {
|
|
36
|
+
const [postsRes, pagesRes, commentsRes, mediaRes] = await Promise.all([
|
|
37
|
+
settle(api.get('/api/posts?per_page=5')),
|
|
38
|
+
settle(api.get('/api/pages?per_page=1')),
|
|
39
|
+
settle(api.get('/api/comments/pending')),
|
|
40
|
+
settle(api.get('/api/media/stats'))
|
|
41
|
+
]);
|
|
42
|
+
setStats({
|
|
43
|
+
posts: postsRes?.meta?.total ?? null,
|
|
44
|
+
pages: pagesRes?.meta?.total ?? null,
|
|
45
|
+
pendingComments: commentsRes?.count ?? null,
|
|
46
|
+
media: mediaRes?.stats?.total ?? null
|
|
47
|
+
});
|
|
48
|
+
setRecentPosts(postsRes?.posts ?? []);
|
|
49
|
+
setLoading(false);
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* One card per stat that came back. A refused one is left out rather than
|
|
53
|
+
* shown as zero — "0 Pending Comments" to somebody who may not moderate them
|
|
54
|
+
* is a number the dashboard has no way to know.
|
|
55
|
+
*/
|
|
56
|
+
const cards = [
|
|
57
|
+
{ label: t('Posts'), value: stats?.posts },
|
|
58
|
+
{ label: t('Pages'), value: stats?.pages },
|
|
59
|
+
{ label: t('Pending Comments'), value: stats?.pendingComments },
|
|
60
|
+
{ label: t('Media Files'), value: stats?.media }
|
|
61
|
+
].filter((card) => typeof card.value === 'number');
|
|
62
|
+
if (loading) {
|
|
63
|
+
return (_jsx(AdminLayout, { title: t('Dashboard'), children: _jsx("div", { className: "admin-loading", children: t('Loading...') }) }));
|
|
64
|
+
}
|
|
65
|
+
return (_jsxs(AdminLayout, { title: t('Dashboard'), children: [cards.length > 0 && (_jsx("div", { className: `admin-grid admin-grid-${Math.min(4, Math.max(2, cards.length))}`, children: cards.map(card => (_jsxs("div", { className: "admin-stat-card", children: [_jsx("div", { className: "admin-stat-value", children: card.value }), _jsx("div", { className: "admin-stat-label", children: card.label })] }, card.label))) })), _jsxs("div", { className: "admin-card", children: [_jsxs("div", { className: "admin-card-header", children: [_jsx("h2", { className: "admin-card-title", children: t('Recent Posts') }), _jsx(Link, { href: "/admin/posts/new", className: "admin-btn admin-btn-primary", children: t('New Post') })] }), recentPosts.length === 0 ? (_jsx("p", { style: { color: 'var(--fg-muted)' }, children: t('No posts yet. Create your first post!') })) : (_jsxs("table", { className: "admin-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: t('Title') }), _jsx("th", { children: t('Status') }), _jsx("th", { children: t('Date') }), _jsx("th", { children: t('Actions') })] }) }), _jsx("tbody", { children: recentPosts.map(post => (_jsxs("tr", { children: [_jsx("td", { children: post.title }), _jsx("td", { children: _jsx("span", { className: `admin-badge ${post.published ? 'admin-badge-success' : 'admin-badge-warning'}`, children: post.published ? t('Published') : t('Draft') }) }), _jsx("td", { children: new Date(post.created_at).toLocaleDateString(locale) }), _jsx("td", { children: _jsx(Link, { href: `/admin/posts/${post.id}/edit`, className: "admin-btn admin-btn-secondary", children: t('Edit') }) })] }, post.id))) })] }))] }), _jsxs("div", { className: "admin-grid admin-grid-3", children: [_jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Content') }), _jsxs("div", { className: "admin-stack", children: [_jsx(Link, { href: "/admin/posts/new", className: "admin-btn admin-btn-secondary", children: t('New Post') }), _jsx(Link, { href: "/admin/pages/new", className: "admin-btn admin-btn-secondary", children: t('New Page') }), _jsx(Link, { href: "/admin/media", className: "admin-btn admin-btn-secondary", children: t('Upload Media') })] })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Extend') }), _jsx("div", { className: "admin-stack", children: _jsx(Link, { href: "/admin/settings", className: "admin-btn admin-btn-secondary", children: t('Settings') }) })] }), _jsxs("div", { className: "admin-card", children: [_jsx("h3", { className: "admin-card-title", children: t('Help') }), _jsxs("div", { className: "admin-stack", children: [_jsx(Link, { href: "https://basicben.com/docs", target: "_blank", rel: "noopener noreferrer", className: "admin-btn admin-btn-secondary", children: t('Documentation') }), _jsx(Link, { href: "/", className: "admin-btn admin-btn-secondary", children: t('View Site') })] })] })] })] }));
|
|
66
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Site health: what this deployment is configured to do, and what it should
|
|
4
|
+
* fix before people rely on it.
|
|
5
|
+
*
|
|
6
|
+
* Every check is computed on the server (helpers/health.ts) — the browser
|
|
7
|
+
* cannot see the environment, and should not: the server reports whether a
|
|
8
|
+
* secret is set and how long it is, never what it is. The two actions that
|
|
9
|
+
* touch the outside world, the storage probe and the test email, are buttons
|
|
10
|
+
* rather than part of the page load, because each one writes something.
|
|
11
|
+
*/
|
|
12
|
+
export default function AdminHealth(): React.JSX.Element;
|