@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,107 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { t } from "../i18n/index.js";
|
|
3
|
+
const DEFAULT_HEARTBEAT = 30_000;
|
|
4
|
+
function headers() {
|
|
5
|
+
const token = typeof localStorage === 'undefined' ? null : localStorage.getItem('token');
|
|
6
|
+
return { 'Content-Type': 'application/json', ...(token ? { Authorization: `Bearer ${token}` } : {}) };
|
|
7
|
+
}
|
|
8
|
+
async function call(path, method, body) {
|
|
9
|
+
try {
|
|
10
|
+
const res = await fetch(path, { method, headers: headers(), body: body === undefined ? undefined : JSON.stringify(body) });
|
|
11
|
+
const data = await res.json().catch(() => ({}));
|
|
12
|
+
return { status: res.status, lock: data?.lock ?? null };
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return { status: 0, lock: null };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function usePostLock(postId, enabled) {
|
|
19
|
+
const [status, setStatus] = useState(enabled && postId ? 'pending' : 'idle');
|
|
20
|
+
const [holder, setHolder] = useState(null);
|
|
21
|
+
// Set when we had the lock and someone took it, so the banner can say that
|
|
22
|
+
// rather than "is editing", which would read as if we never had it.
|
|
23
|
+
const [lostIt, setLostIt] = useState(false);
|
|
24
|
+
const statusRef = useRef(status);
|
|
25
|
+
statusRef.current = status;
|
|
26
|
+
const heartbeat = useRef(DEFAULT_HEARTBEAT);
|
|
27
|
+
const path = postId ? `/api/posts/${postId}/lock` : '';
|
|
28
|
+
const apply = useCallback((code, lock) => {
|
|
29
|
+
if (lock?.heartbeat_ms)
|
|
30
|
+
heartbeat.current = lock.heartbeat_ms;
|
|
31
|
+
if (code === 200 && lock?.mine) {
|
|
32
|
+
setStatus('held');
|
|
33
|
+
setHolder(null);
|
|
34
|
+
setLostIt(false);
|
|
35
|
+
}
|
|
36
|
+
else if (code === 409 && lock) {
|
|
37
|
+
if (statusRef.current === 'held')
|
|
38
|
+
setLostIt(true);
|
|
39
|
+
setStatus('blocked');
|
|
40
|
+
setHolder(lock.user_name || t('Someone else'));
|
|
41
|
+
}
|
|
42
|
+
else if (code === 0 || code >= 500) {
|
|
43
|
+
// A dropped request is not a lost lock: keep whatever we had and try
|
|
44
|
+
// again on the next beat. The lock outlives four missed beats.
|
|
45
|
+
if (statusRef.current === 'pending')
|
|
46
|
+
setStatus('error');
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
setStatus('error');
|
|
50
|
+
}
|
|
51
|
+
}, []);
|
|
52
|
+
const acquire = useCallback(async (takeOver = false) => {
|
|
53
|
+
if (!path)
|
|
54
|
+
return;
|
|
55
|
+
const { status: code, lock } = await call(path, 'POST', takeOver ? { take_over: true } : {});
|
|
56
|
+
apply(code, lock);
|
|
57
|
+
}, [path, apply]);
|
|
58
|
+
// Take it on open, keep it while open. While blocked, keep looking: when
|
|
59
|
+
// the other editor leaves, say so — but do not grab it silently, because the
|
|
60
|
+
// text on screen is from before their save and has to be reloaded first.
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (!enabled || !path)
|
|
63
|
+
return;
|
|
64
|
+
void acquire();
|
|
65
|
+
const timer = setInterval(async () => {
|
|
66
|
+
if (statusRef.current === 'held' || statusRef.current === 'error') {
|
|
67
|
+
await acquire();
|
|
68
|
+
}
|
|
69
|
+
else if (statusRef.current === 'blocked') {
|
|
70
|
+
const { status: code, lock } = await call(path, 'GET');
|
|
71
|
+
if (code === 200 && lock && (!lock.locked || lock.mine))
|
|
72
|
+
setStatus('free');
|
|
73
|
+
else if (code === 200 && lock?.user_name)
|
|
74
|
+
setHolder(lock.user_name);
|
|
75
|
+
}
|
|
76
|
+
}, heartbeat.current);
|
|
77
|
+
// Let go on the way out. `keepalive` lets the request outlive the page,
|
|
78
|
+
// which a beacon would too — but a beacon cannot send the Authorization
|
|
79
|
+
// header, and this API has no cookie to fall back on.
|
|
80
|
+
const release = () => {
|
|
81
|
+
if (statusRef.current !== 'held')
|
|
82
|
+
return;
|
|
83
|
+
try {
|
|
84
|
+
void fetch(path, { method: 'DELETE', headers: headers(), keepalive: true });
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// Nothing to do on the way out; the lock expires on its own.
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
window.addEventListener('pagehide', release);
|
|
91
|
+
return () => {
|
|
92
|
+
clearInterval(timer);
|
|
93
|
+
window.removeEventListener('pagehide', release);
|
|
94
|
+
release();
|
|
95
|
+
};
|
|
96
|
+
}, [enabled, path, acquire]);
|
|
97
|
+
return {
|
|
98
|
+
status,
|
|
99
|
+
holder,
|
|
100
|
+
lostIt,
|
|
101
|
+
/** Whether this editor may save — true when the lock is ours, or there is no lock to have. */
|
|
102
|
+
canSave: !enabled || status === 'held' || status === 'idle' || status === 'error',
|
|
103
|
+
takeOver: () => acquire(true),
|
|
104
|
+
/** Try again without taking over — after a reload, or after a save was refused. */
|
|
105
|
+
retry: () => acquire(false)
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The admin half of the feature host (src/host is the server half).
|
|
3
|
+
*
|
|
4
|
+
* A feature's `admin.tsx` registers its pages, slot fills and translations
|
|
5
|
+
* here. Its menu entries come from its manifest, which the server reads too,
|
|
6
|
+
* so the server's menu and this one cannot disagree.
|
|
7
|
+
*
|
|
8
|
+
* Internal API: it may change in any release.
|
|
9
|
+
*/
|
|
10
|
+
import { type ComponentType, type ReactNode } from 'react';
|
|
11
|
+
import { type Dictionary } from '../i18n/index.ts';
|
|
12
|
+
import type { FeatureManifest } from '../../host/manifest.ts';
|
|
13
|
+
export interface AdminFeature {
|
|
14
|
+
name: string;
|
|
15
|
+
register(admin: AdminHost): void;
|
|
16
|
+
}
|
|
17
|
+
/** Named places in core screens that features may add to. */
|
|
18
|
+
export type SlotName = 'post.editor.sidebar' | 'settings.reading';
|
|
19
|
+
/**
|
|
20
|
+
* What the post editor gives a `post.editor.sidebar` fill.
|
|
21
|
+
*
|
|
22
|
+
* `values` holds the post's `visibility` and whatever fields fills have set
|
|
23
|
+
* this session; `onChange` sets them, and the editor sends them with the next
|
|
24
|
+
* save (posts only). Core does not know what they mean: the server-side half
|
|
25
|
+
* of the feature does, through the `post.creating` / `post.updating` filters.
|
|
26
|
+
*/
|
|
27
|
+
export interface PostEditorSidebarProps {
|
|
28
|
+
kind: 'post' | 'page';
|
|
29
|
+
/** Null until the post is first saved. */
|
|
30
|
+
postId: number | null;
|
|
31
|
+
/** The post as loaded, or null for a new one. */
|
|
32
|
+
record: Record<string, unknown> | null;
|
|
33
|
+
values: Record<string, unknown>;
|
|
34
|
+
disabled: boolean;
|
|
35
|
+
onChange(changes: Record<string, unknown>): void;
|
|
36
|
+
}
|
|
37
|
+
export interface AdminHost {
|
|
38
|
+
/** The screen for a page the feature's manifest declares. */
|
|
39
|
+
page(path: string, component: ComponentType<any>): void;
|
|
40
|
+
/** Add a component to a named slot in a core screen. */
|
|
41
|
+
fill(slot: SlotName, component: ComponentType<any>): void;
|
|
42
|
+
/** The feature's translations, loaded with the admin's own. */
|
|
43
|
+
dictionaries(loaders: Record<string, () => Promise<{
|
|
44
|
+
default: Dictionary;
|
|
45
|
+
}>>): void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Register the site's enabled features: their admin halves, and the manifests
|
|
49
|
+
* of every enabled feature (one without an admin half still has menu facts).
|
|
50
|
+
* Called once by src/main.tsx, before the route table and the menu are built.
|
|
51
|
+
*/
|
|
52
|
+
export declare function registerAdminFeatures(features: AdminFeature[], manifests: FeatureManifest[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* What the Settings page gives a `settings.reading` fill, rendered after the
|
|
55
|
+
* Reading card. `values` is every stored setting plus what fills have changed;
|
|
56
|
+
* `onChange` changes them, and the page saves them with its own. Only keys a
|
|
57
|
+
* feature defined (host.settings.define) are accepted by the server.
|
|
58
|
+
*/
|
|
59
|
+
export interface SettingsSectionProps {
|
|
60
|
+
values: Record<string, string>;
|
|
61
|
+
onChange(changes: Record<string, string>): void;
|
|
62
|
+
}
|
|
63
|
+
/** Whether any feature fills a slot. */
|
|
64
|
+
export declare function hasFills(name: SlotName): boolean;
|
|
65
|
+
/** The manifests of the features this site enables, in list order. */
|
|
66
|
+
export declare function enabledManifests(): FeatureManifest[];
|
|
67
|
+
export declare function featurePages(): Array<[string, ComponentType<any>]>;
|
|
68
|
+
/** Render every fill for a slot, with the props the core screen passes. */
|
|
69
|
+
export declare function Slot({ name, ...props }: {
|
|
70
|
+
name: SlotName;
|
|
71
|
+
} & Record<string, unknown>): ReactNode;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The admin half of the feature host (src/host is the server half).
|
|
3
|
+
*
|
|
4
|
+
* A feature's `admin.tsx` registers its pages, slot fills and translations
|
|
5
|
+
* here. Its menu entries come from its manifest, which the server reads too,
|
|
6
|
+
* so the server's menu and this one cannot disagree.
|
|
7
|
+
*
|
|
8
|
+
* Internal API: it may change in any release.
|
|
9
|
+
*/
|
|
10
|
+
import { createElement, Fragment } from 'react';
|
|
11
|
+
import { addDictionaries } from "../i18n/index.js";
|
|
12
|
+
const pages = new Map();
|
|
13
|
+
const fills = new Map();
|
|
14
|
+
let enabled = [];
|
|
15
|
+
/**
|
|
16
|
+
* Register the site's enabled features: their admin halves, and the manifests
|
|
17
|
+
* of every enabled feature (one without an admin half still has menu facts).
|
|
18
|
+
* Called once by src/main.tsx, before the route table and the menu are built.
|
|
19
|
+
*/
|
|
20
|
+
export function registerAdminFeatures(features, manifests) {
|
|
21
|
+
enabled = [...manifests];
|
|
22
|
+
for (const feature of features) {
|
|
23
|
+
const declared = new Set((manifests.find((m) => m.name === feature.name)?.pages ?? []).map((p) => p.path));
|
|
24
|
+
feature.register({
|
|
25
|
+
page(path, component) {
|
|
26
|
+
// A page with no manifest entry would be a screen with no menu item
|
|
27
|
+
// and no server-side knowledge of it; refuse it while developing.
|
|
28
|
+
if (!declared.has(path))
|
|
29
|
+
throw new Error(`${feature.name}: page ${path} is not declared in its manifest`);
|
|
30
|
+
pages.set(path, component);
|
|
31
|
+
},
|
|
32
|
+
fill(slot, component) {
|
|
33
|
+
fills.set(slot, [...(fills.get(slot) ?? []), component]);
|
|
34
|
+
},
|
|
35
|
+
dictionaries(loaders) {
|
|
36
|
+
addDictionaries(loaders);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Whether any feature fills a slot. */
|
|
42
|
+
export function hasFills(name) {
|
|
43
|
+
return (fills.get(name)?.length ?? 0) > 0;
|
|
44
|
+
}
|
|
45
|
+
/** The manifests of the features this site enables, in list order. */
|
|
46
|
+
export function enabledManifests() {
|
|
47
|
+
return enabled;
|
|
48
|
+
}
|
|
49
|
+
export function featurePages() {
|
|
50
|
+
return [...pages.entries()];
|
|
51
|
+
}
|
|
52
|
+
/** Render every fill for a slot, with the props the core screen passes. */
|
|
53
|
+
export function Slot({ name, ...props }) {
|
|
54
|
+
const list = fills.get(name) ?? [];
|
|
55
|
+
if (!list.length)
|
|
56
|
+
return null;
|
|
57
|
+
return createElement(Fragment, null, ...list.map((Component, index) => createElement(Component, { key: index, ...props })));
|
|
58
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin translations.
|
|
3
|
+
*
|
|
4
|
+
* Keyed on the English text itself, gettext-style: `t('Save changes')`. The
|
|
5
|
+
* English string is the fallback, so a missing translation shows English
|
|
6
|
+
* rather than a key like `posts.save_button`, and a component reads the same
|
|
7
|
+
* as it did before it was translated. `tests/admin-i18n.test.js` reads every
|
|
8
|
+
* `t()`/`tn()` literal in the admin and fails when a shipped locale lacks one.
|
|
9
|
+
*
|
|
10
|
+
* ## Which language
|
|
11
|
+
*
|
|
12
|
+
* 1. This browser's choice (Profile → Admin language), kept in localStorage.
|
|
13
|
+
* 2. The site's `admin_locale` setting, which `/api/admin/menu` reports.
|
|
14
|
+
* 3. English.
|
|
15
|
+
*
|
|
16
|
+
* A locale is matched on its full tag and then on its language alone, so
|
|
17
|
+
* `es-MX` gets the `es` dictionary. Dictionaries are loaded on demand: an
|
|
18
|
+
* English admin downloads none of them.
|
|
19
|
+
*
|
|
20
|
+
* ## Interpolation and plurals
|
|
21
|
+
*
|
|
22
|
+
* `t('Deleted {name}', { name })` — values are inserted as text; React
|
|
23
|
+
* escapes them like any other string, so there is no markup channel here.
|
|
24
|
+
* `tn('{count} post', '{count} posts', n)` picks the form with
|
|
25
|
+
* `Intl.PluralRules`, so languages with more than two forms can supply them.
|
|
26
|
+
*/
|
|
27
|
+
import { type ReactNode } from 'react';
|
|
28
|
+
export type PluralForms = Partial<Record<Intl.LDMLPluralRule, string>> & {
|
|
29
|
+
other: string;
|
|
30
|
+
};
|
|
31
|
+
export type Dictionary = Record<string, string | PluralForms>;
|
|
32
|
+
type Vars = Record<string, string | number>;
|
|
33
|
+
/** Locales with a dictionary, and the name each calls itself in the picker. */
|
|
34
|
+
export declare const ADMIN_LOCALES: Array<{
|
|
35
|
+
code: string;
|
|
36
|
+
name: string;
|
|
37
|
+
}>;
|
|
38
|
+
/** The full tag, then the language alone, among the shipped locales. */
|
|
39
|
+
export declare function resolveLocale(requested: string | null | undefined): string;
|
|
40
|
+
export declare function currentLocale(): string;
|
|
41
|
+
/** This browser's choice, or null to follow the site. */
|
|
42
|
+
export declare function localeOverride(): string | null;
|
|
43
|
+
export declare function setLocale(requested: string | null | undefined): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* A feature's translations. If the admin is already showing that language,
|
|
46
|
+
* they are loaded and applied now, so registration order does not matter.
|
|
47
|
+
*/
|
|
48
|
+
export declare function addDictionaries(map: Record<string, () => Promise<{
|
|
49
|
+
default: Dictionary;
|
|
50
|
+
}>>): void;
|
|
51
|
+
/** Remember (or with null, forget) this browser's choice, and apply it. */
|
|
52
|
+
export declare function chooseLocale(code: string | null, siteLocale?: string | null): Promise<void>;
|
|
53
|
+
/** Called with the site's setting once it is known. The browser's choice wins. */
|
|
54
|
+
export declare function applySiteLocale(siteLocale: string | null | undefined): Promise<void>;
|
|
55
|
+
/** Translate a fixed English string. */
|
|
56
|
+
export declare function t(source: string, vars?: Vars): string;
|
|
57
|
+
/** Translate a count. `{count}` is filled in for you. */
|
|
58
|
+
export declare function tn(one: string, other: string, count: number, vars?: Vars): string;
|
|
59
|
+
/**
|
|
60
|
+
* A translated sentence with elements in its `{name}` slots:
|
|
61
|
+
* `slots(t('Entries live at {code}.'), { code: <code>/recipes</code> })`.
|
|
62
|
+
*
|
|
63
|
+
* For markup inside a sentence. The sentence stays one string, so a
|
|
64
|
+
* translation can move the element to wherever its grammar puts it. A slot
|
|
65
|
+
* with no element is left as written, so a typo shows rather than vanishing.
|
|
66
|
+
*/
|
|
67
|
+
export declare function slots(text: string, parts: Record<string, ReactNode>): ReactNode[];
|
|
68
|
+
/** How a plural pair is keyed in a dictionary. */
|
|
69
|
+
export declare function pluralKey(one: string, other: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* `t` and `tn`, re-rendering the component when the language changes.
|
|
72
|
+
* Components use this; plain helpers call `t` directly.
|
|
73
|
+
*/
|
|
74
|
+
export declare function useT(): {
|
|
75
|
+
t: typeof t;
|
|
76
|
+
tn: typeof tn;
|
|
77
|
+
locale: string;
|
|
78
|
+
};
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin translations.
|
|
3
|
+
*
|
|
4
|
+
* Keyed on the English text itself, gettext-style: `t('Save changes')`. The
|
|
5
|
+
* English string is the fallback, so a missing translation shows English
|
|
6
|
+
* rather than a key like `posts.save_button`, and a component reads the same
|
|
7
|
+
* as it did before it was translated. `tests/admin-i18n.test.js` reads every
|
|
8
|
+
* `t()`/`tn()` literal in the admin and fails when a shipped locale lacks one.
|
|
9
|
+
*
|
|
10
|
+
* ## Which language
|
|
11
|
+
*
|
|
12
|
+
* 1. This browser's choice (Profile → Admin language), kept in localStorage.
|
|
13
|
+
* 2. The site's `admin_locale` setting, which `/api/admin/menu` reports.
|
|
14
|
+
* 3. English.
|
|
15
|
+
*
|
|
16
|
+
* A locale is matched on its full tag and then on its language alone, so
|
|
17
|
+
* `es-MX` gets the `es` dictionary. Dictionaries are loaded on demand: an
|
|
18
|
+
* English admin downloads none of them.
|
|
19
|
+
*
|
|
20
|
+
* ## Interpolation and plurals
|
|
21
|
+
*
|
|
22
|
+
* `t('Deleted {name}', { name })` — values are inserted as text; React
|
|
23
|
+
* escapes them like any other string, so there is no markup channel here.
|
|
24
|
+
* `tn('{count} post', '{count} posts', n)` picks the form with
|
|
25
|
+
* `Intl.PluralRules`, so languages with more than two forms can supply them.
|
|
26
|
+
*/
|
|
27
|
+
import { createElement, Fragment, useSyncExternalStore } from 'react';
|
|
28
|
+
/** Locales with a dictionary, and the name each calls itself in the picker. */
|
|
29
|
+
export const ADMIN_LOCALES = [
|
|
30
|
+
{ code: 'en', name: 'English' },
|
|
31
|
+
{ code: 'es', name: 'Español' }
|
|
32
|
+
];
|
|
33
|
+
const OVERRIDE_KEY = 'basicben.admin_locale';
|
|
34
|
+
// Vite turns this into one lazily loaded chunk per locale. `.ts` matches the
|
|
35
|
+
// source here; `.js` matches the compiled copy in lib/, which tsc does not
|
|
36
|
+
// rewrite inside a string. `index.d.ts` matches neither.
|
|
37
|
+
const loaders = import.meta.glob('./locales/*/index.{ts,js}');
|
|
38
|
+
// Features' dictionaries (src/client/host), per locale, merged over core's.
|
|
39
|
+
const featureLoaders = {};
|
|
40
|
+
let locale = 'en';
|
|
41
|
+
let dictionary = {};
|
|
42
|
+
let version = 0;
|
|
43
|
+
const listeners = new Set();
|
|
44
|
+
function notify() {
|
|
45
|
+
version++;
|
|
46
|
+
for (const listener of listeners)
|
|
47
|
+
listener();
|
|
48
|
+
}
|
|
49
|
+
/** The full tag, then the language alone, among the shipped locales. */
|
|
50
|
+
export function resolveLocale(requested) {
|
|
51
|
+
if (!requested)
|
|
52
|
+
return 'en';
|
|
53
|
+
const codes = ADMIN_LOCALES.map((entry) => entry.code);
|
|
54
|
+
if (codes.includes(requested))
|
|
55
|
+
return requested;
|
|
56
|
+
const language = requested.split('-')[0].toLowerCase();
|
|
57
|
+
return codes.includes(language) ? language : 'en';
|
|
58
|
+
}
|
|
59
|
+
export function currentLocale() {
|
|
60
|
+
return locale;
|
|
61
|
+
}
|
|
62
|
+
/** This browser's choice, or null to follow the site. */
|
|
63
|
+
export function localeOverride() {
|
|
64
|
+
if (typeof localStorage === 'undefined')
|
|
65
|
+
return null;
|
|
66
|
+
return localStorage.getItem(OVERRIDE_KEY);
|
|
67
|
+
}
|
|
68
|
+
export async function setLocale(requested) {
|
|
69
|
+
const next = resolveLocale(requested);
|
|
70
|
+
if (next === locale && (next === 'en' || Object.keys(dictionary).length))
|
|
71
|
+
return;
|
|
72
|
+
if (next === 'en') {
|
|
73
|
+
dictionary = {};
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const load = loaders[`./locales/${next}/index.ts`] ?? loaders[`./locales/${next}/index.js`];
|
|
77
|
+
if (!load)
|
|
78
|
+
return;
|
|
79
|
+
try {
|
|
80
|
+
const core = await load();
|
|
81
|
+
// Read after the await: features register while core's chunk loads, and
|
|
82
|
+
// one registered by then must not be missed.
|
|
83
|
+
const extra = await Promise.all((featureLoaders[next] ?? []).map((loader) => loader()));
|
|
84
|
+
dictionary = Object.assign({}, core.default, ...extra.map((module) => module.default));
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// A chunk that fails to load leaves the admin in English, not blank.
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
locale = next;
|
|
92
|
+
if (typeof document !== 'undefined')
|
|
93
|
+
document.documentElement.lang = next;
|
|
94
|
+
notify();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A feature's translations. If the admin is already showing that language,
|
|
98
|
+
* they are loaded and applied now, so registration order does not matter.
|
|
99
|
+
*/
|
|
100
|
+
export function addDictionaries(map) {
|
|
101
|
+
for (const [code, loader] of Object.entries(map)) {
|
|
102
|
+
featureLoaders[code] = [...(featureLoaders[code] ?? []), loader];
|
|
103
|
+
if (code === locale) {
|
|
104
|
+
loader()
|
|
105
|
+
.then((module) => {
|
|
106
|
+
dictionary = { ...dictionary, ...module.default };
|
|
107
|
+
notify();
|
|
108
|
+
})
|
|
109
|
+
.catch(() => { });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** Remember (or with null, forget) this browser's choice, and apply it. */
|
|
114
|
+
export async function chooseLocale(code, siteLocale) {
|
|
115
|
+
if (typeof localStorage !== 'undefined') {
|
|
116
|
+
if (code)
|
|
117
|
+
localStorage.setItem(OVERRIDE_KEY, code);
|
|
118
|
+
else
|
|
119
|
+
localStorage.removeItem(OVERRIDE_KEY);
|
|
120
|
+
}
|
|
121
|
+
await setLocale(code ?? siteLocale ?? 'en');
|
|
122
|
+
}
|
|
123
|
+
/** Called with the site's setting once it is known. The browser's choice wins. */
|
|
124
|
+
export function applySiteLocale(siteLocale) {
|
|
125
|
+
return setLocale(localeOverride() ?? siteLocale ?? 'en');
|
|
126
|
+
}
|
|
127
|
+
function fill(text, vars) {
|
|
128
|
+
if (!vars)
|
|
129
|
+
return text;
|
|
130
|
+
return text.replace(/\{(\w+)\}/g, (match, name) => Object.prototype.hasOwnProperty.call(vars, name) ? String(vars[name]) : match);
|
|
131
|
+
}
|
|
132
|
+
/** Translate a fixed English string. */
|
|
133
|
+
export function t(source, vars) {
|
|
134
|
+
const entry = dictionary[source];
|
|
135
|
+
return fill(typeof entry === 'string' && entry ? entry : source, vars);
|
|
136
|
+
}
|
|
137
|
+
/** Translate a count. `{count}` is filled in for you. */
|
|
138
|
+
export function tn(one, other, count, vars) {
|
|
139
|
+
const all = { count: count.toLocaleString(locale), ...vars };
|
|
140
|
+
const entry = dictionary[pluralKey(one, other)];
|
|
141
|
+
if (entry && typeof entry === 'object') {
|
|
142
|
+
const form = new Intl.PluralRules(locale).select(count);
|
|
143
|
+
return fill(entry[form] ?? entry.other, all);
|
|
144
|
+
}
|
|
145
|
+
return fill(count === 1 ? one : other, all);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* A translated sentence with elements in its `{name}` slots:
|
|
149
|
+
* `slots(t('Entries live at {code}.'), { code: <code>/recipes</code> })`.
|
|
150
|
+
*
|
|
151
|
+
* For markup inside a sentence. The sentence stays one string, so a
|
|
152
|
+
* translation can move the element to wherever its grammar puts it. A slot
|
|
153
|
+
* with no element is left as written, so a typo shows rather than vanishing.
|
|
154
|
+
*/
|
|
155
|
+
export function slots(text, parts) {
|
|
156
|
+
return text.split(/\{(\w+)\}/g).map((piece, index) => index % 2 ? createElement(Fragment, { key: index }, parts[piece] ?? `{${piece}}`) : piece);
|
|
157
|
+
}
|
|
158
|
+
/** How a plural pair is keyed in a dictionary. */
|
|
159
|
+
export function pluralKey(one, other) {
|
|
160
|
+
return `${one}|${other}`;
|
|
161
|
+
}
|
|
162
|
+
function subscribe(listener) {
|
|
163
|
+
listeners.add(listener);
|
|
164
|
+
return () => listeners.delete(listener);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* `t` and `tn`, re-rendering the component when the language changes.
|
|
168
|
+
* Components use this; plain helpers call `t` directly.
|
|
169
|
+
*/
|
|
170
|
+
export function useT() {
|
|
171
|
+
useSyncExternalStore(subscribe, () => version, () => version);
|
|
172
|
+
return { t, tn, locale };
|
|
173
|
+
}
|
|
174
|
+
// Start loading the browser's own choice at once rather than after the menu
|
|
175
|
+
// request, so the English frame before it is as short as it can be.
|
|
176
|
+
if (typeof window !== 'undefined')
|
|
177
|
+
void setLocale(localeOverride());
|