@commonpub/layer 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/app.vue +7 -0
- package/components/AnnouncementBand.vue +117 -0
- package/components/AppToast.vue +108 -0
- package/components/AuthorCard.vue +119 -0
- package/components/AuthorRow.vue +81 -0
- package/components/CommentSection.vue +330 -0
- package/components/ContentCard.vue +340 -0
- package/components/ContentPicker.vue +240 -0
- package/components/ContentStarterForm.vue +214 -0
- package/components/ContentTypeBadge.vue +46 -0
- package/components/CountdownTimer.vue +68 -0
- package/components/CpubEditor.vue +87 -0
- package/components/DiscussionItem.vue +191 -0
- package/components/EditorPropertiesPanel.vue +393 -0
- package/components/EngagementBar.vue +131 -0
- package/components/FederatedContentCard.vue +291 -0
- package/components/FeedItem.vue +283 -0
- package/components/FilterChip.vue +21 -0
- package/components/HeatmapGrid.vue +92 -0
- package/components/ImageUpload.vue +219 -0
- package/components/MemberCard.vue +163 -0
- package/components/MessageThread.vue +120 -0
- package/components/NotificationItem.vue +103 -0
- package/components/ProgressTracker.vue +41 -0
- package/components/PublishErrorsModal.vue +116 -0
- package/components/RemoteActorCard.vue +206 -0
- package/components/RemoteUserSearch.vue +117 -0
- package/components/SearchFilters.vue +188 -0
- package/components/SearchSidebar.vue +181 -0
- package/components/SectionHeader.vue +17 -0
- package/components/ShareToHubModal.vue +189 -0
- package/components/SiteLogo.vue +21 -0
- package/components/SkillBar.vue +57 -0
- package/components/SortSelect.vue +30 -0
- package/components/StatBar.vue +14 -0
- package/components/TOCNav.vue +69 -0
- package/components/TimelineItem.vue +82 -0
- package/components/VideoCard.vue +106 -0
- package/components/blocks/BlockBuildStepView.vue +92 -0
- package/components/blocks/BlockCalloutView.vue +82 -0
- package/components/blocks/BlockCheckpointView.vue +50 -0
- package/components/blocks/BlockCodeView.vue +212 -0
- package/components/blocks/BlockContentRenderer.vue +143 -0
- package/components/blocks/BlockDividerView.vue +11 -0
- package/components/blocks/BlockDownloadsView.vue +126 -0
- package/components/blocks/BlockEmbedView.vue +61 -0
- package/components/blocks/BlockGalleryView.vue +57 -0
- package/components/blocks/BlockHeadingView.vue +29 -0
- package/components/blocks/BlockImageView.vue +34 -0
- package/components/blocks/BlockMarkdownView.vue +118 -0
- package/components/blocks/BlockMathView.vue +45 -0
- package/components/blocks/BlockPartsListView.vue +104 -0
- package/components/blocks/BlockQuizView.vue +239 -0
- package/components/blocks/BlockQuoteView.vue +41 -0
- package/components/blocks/BlockSectionHeaderView.vue +58 -0
- package/components/blocks/BlockSliderView.vue +236 -0
- package/components/blocks/BlockTextView.vue +41 -0
- package/components/blocks/BlockToolListView.vue +87 -0
- package/components/blocks/BlockVideoView.vue +89 -0
- package/components/editors/ArticleEditor.vue +545 -0
- package/components/editors/BlockCanvas.vue +487 -0
- package/components/editors/BlockInsertZone.vue +84 -0
- package/components/editors/BlockPicker.vue +285 -0
- package/components/editors/BlockWrapper.vue +192 -0
- package/components/editors/BlogEditor.vue +567 -0
- package/components/editors/EditorBlocks.vue +248 -0
- package/components/editors/EditorSection.vue +81 -0
- package/components/editors/EditorShell.vue +168 -0
- package/components/editors/EditorTagInput.vue +114 -0
- package/components/editors/EditorVisibility.vue +110 -0
- package/components/editors/ExplainerEditor.vue +503 -0
- package/components/editors/MarkdownImportDialog.vue +249 -0
- package/components/editors/ProjectEditor.vue +446 -0
- package/components/editors/blocks/BuildStepBlock.vue +102 -0
- package/components/editors/blocks/CalloutBlock.vue +122 -0
- package/components/editors/blocks/CheckpointBlock.vue +27 -0
- package/components/editors/blocks/CodeBlock.vue +177 -0
- package/components/editors/blocks/DividerBlock.vue +22 -0
- package/components/editors/blocks/DownloadsBlock.vue +41 -0
- package/components/editors/blocks/EmbedBlock.vue +20 -0
- package/components/editors/blocks/GalleryBlock.vue +236 -0
- package/components/editors/blocks/HeadingBlock.vue +96 -0
- package/components/editors/blocks/ImageBlock.vue +271 -0
- package/components/editors/blocks/MarkdownBlock.vue +258 -0
- package/components/editors/blocks/MathBlock.vue +37 -0
- package/components/editors/blocks/PartsListBlock.vue +358 -0
- package/components/editors/blocks/QuizBlock.vue +47 -0
- package/components/editors/blocks/QuoteBlock.vue +101 -0
- package/components/editors/blocks/SectionHeaderBlock.vue +130 -0
- package/components/editors/blocks/SliderBlock.vue +318 -0
- package/components/editors/blocks/TextBlock.vue +201 -0
- package/components/editors/blocks/ToolListBlock.vue +70 -0
- package/components/editors/blocks/VideoBlock.vue +22 -0
- package/components/hub/HubDiscussions.vue +47 -0
- package/components/hub/HubFeed.vue +199 -0
- package/components/hub/HubHero.vue +185 -0
- package/components/hub/HubLayout.vue +103 -0
- package/components/hub/HubMembers.vue +40 -0
- package/components/hub/HubProducts.vue +93 -0
- package/components/hub/HubProjects.vue +207 -0
- package/components/hub/HubSidebar.vue +12 -0
- package/components/hub/HubSidebarCard.vue +35 -0
- package/components/views/ArticleView.vue +771 -0
- package/components/views/BlogView.vue +667 -0
- package/components/views/ExplainerView.vue +688 -0
- package/components/views/ProjectView.vue +1500 -0
- package/composables/useApiError.ts +39 -0
- package/composables/useAuth.ts +87 -0
- package/composables/useBlockEditor.ts +187 -0
- package/composables/useContentSave.ts +253 -0
- package/composables/useContentTypes.ts +37 -0
- package/composables/useEngagement.ts +196 -0
- package/composables/useFeatures.ts +33 -0
- package/composables/useFederation.ts +72 -0
- package/composables/useJsonLd.ts +183 -0
- package/composables/useMarkdownImport.ts +77 -0
- package/composables/useMirrorContent.ts +105 -0
- package/composables/useNotifications.ts +73 -0
- package/composables/usePublishValidation.ts +65 -0
- package/composables/useSanitize.ts +34 -0
- package/composables/useSiteName.ts +4 -0
- package/composables/useTheme.ts +34 -0
- package/composables/useToast.ts +35 -0
- package/error.vue +129 -0
- package/layouts/admin.vue +213 -0
- package/layouts/auth.vue +63 -0
- package/layouts/default.vue +269 -0
- package/layouts/editor.vue +129 -0
- package/middleware/auth.ts +6 -0
- package/nuxt.config.ts +83 -0
- package/package.json +59 -0
- package/pages/[type]/[slug]/edit.vue +676 -0
- package/pages/[type]/[slug]/index.vue +313 -0
- package/pages/[type]/index.vue +118 -0
- package/pages/about.vue +100 -0
- package/pages/admin/audit.vue +66 -0
- package/pages/admin/content.vue +116 -0
- package/pages/admin/federation.vue +446 -0
- package/pages/admin/index.vue +62 -0
- package/pages/admin/reports.vue +88 -0
- package/pages/admin/settings.vue +167 -0
- package/pages/admin/users.vue +145 -0
- package/pages/auth/forgot-password.vue +103 -0
- package/pages/auth/login.vue +216 -0
- package/pages/auth/oauth/authorize.vue +178 -0
- package/pages/auth/register.vue +246 -0
- package/pages/auth/reset-password.vue +124 -0
- package/pages/auth/verify-email.vue +80 -0
- package/pages/cert/[code].vue +154 -0
- package/pages/contests/[slug]/edit.vue +153 -0
- package/pages/contests/[slug]/index.vue +556 -0
- package/pages/contests/[slug]/judge.vue +160 -0
- package/pages/contests/create.vue +192 -0
- package/pages/contests/index.vue +69 -0
- package/pages/create.vue +219 -0
- package/pages/dashboard.vue +521 -0
- package/pages/docs/[siteSlug]/[...pagePath].vue +704 -0
- package/pages/docs/[siteSlug]/edit.vue +480 -0
- package/pages/docs/[siteSlug]/index.vue +380 -0
- package/pages/docs/create.vue +60 -0
- package/pages/docs/index.vue +181 -0
- package/pages/explore.vue +422 -0
- package/pages/federated-hubs/[id]/index.vue +385 -0
- package/pages/federated-hubs/[id]/posts/[postId].vue +309 -0
- package/pages/federation/index.vue +157 -0
- package/pages/federation/search.vue +43 -0
- package/pages/federation/users/[handle].vue +221 -0
- package/pages/feed.vue +135 -0
- package/pages/hubs/[slug]/index.vue +513 -0
- package/pages/hubs/[slug]/members.vue +134 -0
- package/pages/hubs/[slug]/posts/[postId].vue +352 -0
- package/pages/hubs/[slug]/settings.vue +254 -0
- package/pages/hubs/create.vue +201 -0
- package/pages/hubs/index.vue +207 -0
- package/pages/index.vue +1005 -0
- package/pages/learn/[slug]/[lessonSlug]/edit.vue +413 -0
- package/pages/learn/[slug]/[lessonSlug]/index.vue +438 -0
- package/pages/learn/[slug]/edit.vue +414 -0
- package/pages/learn/[slug]/index.vue +341 -0
- package/pages/learn/create.vue +71 -0
- package/pages/learn/index.vue +360 -0
- package/pages/messages/[conversationId].vue +113 -0
- package/pages/messages/index.vue +303 -0
- package/pages/mirror/[id].vue +115 -0
- package/pages/notifications.vue +91 -0
- package/pages/products/[slug].vue +128 -0
- package/pages/products/index.vue +122 -0
- package/pages/search.vue +692 -0
- package/pages/settings/account.vue +170 -0
- package/pages/settings/appearance.vue +80 -0
- package/pages/settings/index.vue +81 -0
- package/pages/settings/notifications.vue +68 -0
- package/pages/settings/profile.vue +838 -0
- package/pages/tags/[slug].vue +111 -0
- package/pages/tags/index.vue +73 -0
- package/pages/u/[username]/followers.vue +86 -0
- package/pages/u/[username]/following.vue +94 -0
- package/pages/u/[username]/index.vue +837 -0
- package/pages/videos/[id].vue +212 -0
- package/pages/videos/index.vue +327 -0
- package/pages/videos/submit.vue +112 -0
- package/plugins/auth.ts +23 -0
- package/server/api/admin/audit.get.ts +17 -0
- package/server/api/admin/content/[id].delete.ts +15 -0
- package/server/api/admin/content/[id].patch.ts +37 -0
- package/server/api/admin/federation/activity.get.ts +31 -0
- package/server/api/admin/federation/clients.get.ts +9 -0
- package/server/api/admin/federation/clients.post.ts +16 -0
- package/server/api/admin/federation/hub-mirrors/index.get.ts +10 -0
- package/server/api/admin/federation/hub-mirrors/index.post.ts +42 -0
- package/server/api/admin/federation/mirrors/[id]/backfill.post.ts +39 -0
- package/server/api/admin/federation/mirrors/[id].delete.ts +11 -0
- package/server/api/admin/federation/mirrors/[id].get.ts +15 -0
- package/server/api/admin/federation/mirrors/[id].put.ts +22 -0
- package/server/api/admin/federation/mirrors/index.get.ts +9 -0
- package/server/api/admin/federation/mirrors/index.post.ts +30 -0
- package/server/api/admin/federation/pending.get.ts +22 -0
- package/server/api/admin/federation/refederate.post.ts +92 -0
- package/server/api/admin/federation/repair-types.post.ts +57 -0
- package/server/api/admin/federation/retry.post.ts +41 -0
- package/server/api/admin/federation/stats.get.ts +26 -0
- package/server/api/admin/reports/[id]/resolve.post.ts +12 -0
- package/server/api/admin/reports.get.ts +17 -0
- package/server/api/admin/settings.get.ts +22 -0
- package/server/api/admin/settings.put.ts +11 -0
- package/server/api/admin/stats.get.ts +9 -0
- package/server/api/admin/users/[id]/role.put.ts +12 -0
- package/server/api/admin/users/[id]/status.put.ts +12 -0
- package/server/api/admin/users/[id].delete.ts +10 -0
- package/server/api/admin/users.get.ts +18 -0
- package/server/api/auth/federated/callback.get.ts +67 -0
- package/server/api/auth/federated/login.post.ts +60 -0
- package/server/api/auth/oauth2/authorize.get.ts +30 -0
- package/server/api/auth/oauth2/authorize.post.ts +51 -0
- package/server/api/auth/oauth2/register.post.ts +41 -0
- package/server/api/auth/oauth2/token.post.ts +48 -0
- package/server/api/cert/[code].get.ts +13 -0
- package/server/api/content/[id]/build.post.ts +9 -0
- package/server/api/content/[id]/fork.post.ts +10 -0
- package/server/api/content/[id]/index.delete.ts +18 -0
- package/server/api/content/[id]/index.get.ts +15 -0
- package/server/api/content/[id]/index.put.ts +23 -0
- package/server/api/content/[id]/products/[productId].delete.ts +28 -0
- package/server/api/content/[id]/products-sync.post.ts +29 -0
- package/server/api/content/[id]/products.get.ts +9 -0
- package/server/api/content/[id]/products.post.ts +31 -0
- package/server/api/content/[id]/publish.post.ts +17 -0
- package/server/api/content/[id]/report.post.ts +17 -0
- package/server/api/content/[id]/versions.get.ts +9 -0
- package/server/api/content/[id]/view.post.ts +34 -0
- package/server/api/content/index.get.ts +23 -0
- package/server/api/content/index.post.ts +11 -0
- package/server/api/contests/[slug]/entries.get.ts +18 -0
- package/server/api/contests/[slug]/entries.post.ts +23 -0
- package/server/api/contests/[slug]/index.delete.ts +21 -0
- package/server/api/contests/[slug]/index.get.ts +11 -0
- package/server/api/contests/[slug]/index.put.ts +15 -0
- package/server/api/contests/[slug]/judge.post.ts +12 -0
- package/server/api/contests/[slug]/transition.post.ts +24 -0
- package/server/api/contests/index.get.ts +10 -0
- package/server/api/contests/index.post.ts +28 -0
- package/server/api/docs/[siteSlug]/index.delete.ts +14 -0
- package/server/api/docs/[siteSlug]/index.get.ts +17 -0
- package/server/api/docs/[siteSlug]/index.put.ts +20 -0
- package/server/api/docs/[siteSlug]/nav.get.ts +26 -0
- package/server/api/docs/[siteSlug]/pages/[pageId].delete.ts +14 -0
- package/server/api/docs/[siteSlug]/pages/[pageId].get.ts +31 -0
- package/server/api/docs/[siteSlug]/pages/[pageId].put.ts +15 -0
- package/server/api/docs/[siteSlug]/pages/index.get.ts +34 -0
- package/server/api/docs/[siteSlug]/pages/index.post.ts +28 -0
- package/server/api/docs/[siteSlug]/pages/reorder.post.ts +26 -0
- package/server/api/docs/[siteSlug]/search.get.ts +20 -0
- package/server/api/docs/[siteSlug]/versions.post.ts +11 -0
- package/server/api/docs/index.get.ts +6 -0
- package/server/api/docs/index.post.ts +10 -0
- package/server/api/federated-hubs/[id]/posts/[postId].get.ts +16 -0
- package/server/api/federated-hubs/[id]/posts.get.ts +15 -0
- package/server/api/federated-hubs/[id].get.ts +16 -0
- package/server/api/federation/boost.post.ts +21 -0
- package/server/api/federation/content/[id].get.ts +15 -0
- package/server/api/federation/follow.post.ts +16 -0
- package/server/api/federation/health.get.ts +56 -0
- package/server/api/federation/hub-follow.post.ts +27 -0
- package/server/api/federation/hub-post-like.post.ts +115 -0
- package/server/api/federation/hub-post-likes.get.ts +24 -0
- package/server/api/federation/hub-post-reply.post.ts +42 -0
- package/server/api/federation/hub-post.post.ts +33 -0
- package/server/api/federation/like.post.ts +21 -0
- package/server/api/federation/remote-actor.get.ts +22 -0
- package/server/api/federation/reply.post.ts +22 -0
- package/server/api/federation/search.post.ts +17 -0
- package/server/api/federation/timeline.get.ts +22 -0
- package/server/api/federation/unfollow.post.ts +17 -0
- package/server/api/files/[id].delete.ts +35 -0
- package/server/api/files/mine.get.ts +31 -0
- package/server/api/files/upload-from-url.post.ts +68 -0
- package/server/api/files/upload.post.ts +105 -0
- package/server/api/health.get.ts +4 -0
- package/server/api/hubs/[slug]/bans/[userId].delete.ts +13 -0
- package/server/api/hubs/[slug]/bans.get.ts +20 -0
- package/server/api/hubs/[slug]/bans.post.ts +23 -0
- package/server/api/hubs/[slug]/feed.xml.get.ts +60 -0
- package/server/api/hubs/[slug]/gallery.get.ts +21 -0
- package/server/api/hubs/[slug]/index.delete.ts +18 -0
- package/server/api/hubs/[slug]/index.get.ts +14 -0
- package/server/api/hubs/[slug]/index.put.ts +22 -0
- package/server/api/hubs/[slug]/invites.get.ts +20 -0
- package/server/api/hubs/[slug]/invites.post.ts +27 -0
- package/server/api/hubs/[slug]/join.post.ts +17 -0
- package/server/api/hubs/[slug]/leave.post.ts +13 -0
- package/server/api/hubs/[slug]/members/[userId].delete.ts +13 -0
- package/server/api/hubs/[slug]/members/[userId].put.ts +16 -0
- package/server/api/hubs/[slug]/members.get.ts +20 -0
- package/server/api/hubs/[slug]/posts/[postId]/like.post.ts +21 -0
- package/server/api/hubs/[slug]/posts/[postId]/lock.post.ts +17 -0
- package/server/api/hubs/[slug]/posts/[postId]/pin.post.ts +17 -0
- package/server/api/hubs/[slug]/posts/[postId]/replies.get.ts +16 -0
- package/server/api/hubs/[slug]/posts/[postId]/replies.post.ts +21 -0
- package/server/api/hubs/[slug]/posts/[postId].delete.ts +23 -0
- package/server/api/hubs/[slug]/posts/[postId].get.ts +16 -0
- package/server/api/hubs/[slug]/posts/index.get.ts +16 -0
- package/server/api/hubs/[slug]/posts/index.post.ts +36 -0
- package/server/api/hubs/[slug]/products.get.ts +26 -0
- package/server/api/hubs/[slug]/products.post.ts +18 -0
- package/server/api/hubs/[slug]/share.post.ts +39 -0
- package/server/api/hubs/index.get.ts +15 -0
- package/server/api/hubs/index.post.ts +11 -0
- package/server/api/image-proxy.get.ts +91 -0
- package/server/api/learn/[slug]/[lessonSlug]/complete.post.ts +13 -0
- package/server/api/learn/[slug]/[lessonSlug]/index.get.ts +68 -0
- package/server/api/learn/[slug]/enroll.post.ts +12 -0
- package/server/api/learn/[slug]/index.delete.ts +12 -0
- package/server/api/learn/[slug]/index.get.ts +14 -0
- package/server/api/learn/[slug]/index.put.ts +19 -0
- package/server/api/learn/[slug]/lessons/[lessonId].delete.ts +14 -0
- package/server/api/learn/[slug]/lessons/[lessonId].put.ts +24 -0
- package/server/api/learn/[slug]/lessons.post.ts +10 -0
- package/server/api/learn/[slug]/modules/[moduleId].delete.ts +14 -0
- package/server/api/learn/[slug]/modules/[moduleId].put.ts +15 -0
- package/server/api/learn/[slug]/modules.post.ts +14 -0
- package/server/api/learn/[slug]/publish.post.ts +13 -0
- package/server/api/learn/[slug]/unenroll.post.ts +12 -0
- package/server/api/learn/certificates.get.ts +9 -0
- package/server/api/learn/enrollments.get.ts +9 -0
- package/server/api/learn/index.get.ts +17 -0
- package/server/api/learn/index.post.ts +11 -0
- package/server/api/me.get.ts +13 -0
- package/server/api/messages/[conversationId]/info.get.ts +43 -0
- package/server/api/messages/[conversationId]/stream.get.ts +73 -0
- package/server/api/messages/[conversationId].get.ts +13 -0
- package/server/api/messages/[conversationId].post.ts +12 -0
- package/server/api/messages/index.get.ts +39 -0
- package/server/api/messages/index.post.ts +58 -0
- package/server/api/notifications/[id].delete.ts +11 -0
- package/server/api/notifications/count.get.ts +10 -0
- package/server/api/notifications/index.get.ts +24 -0
- package/server/api/notifications/read.post.ts +15 -0
- package/server/api/notifications/stream.get.ts +59 -0
- package/server/api/openapi.get.ts +5 -0
- package/server/api/products/[id].delete.ts +15 -0
- package/server/api/products/[id].put.ts +18 -0
- package/server/api/products/[slug]/content.get.ts +21 -0
- package/server/api/products/[slug].get.ts +16 -0
- package/server/api/products/index.get.ts +28 -0
- package/server/api/profile.get.ts +15 -0
- package/server/api/profile.put.ts +24 -0
- package/server/api/resolve-identity.post.ts +34 -0
- package/server/api/search/index.get.ts +24 -0
- package/server/api/search/trending.get.ts +22 -0
- package/server/api/social/bookmark.get.ts +16 -0
- package/server/api/social/bookmark.post.ts +15 -0
- package/server/api/social/bookmarks.get.ts +16 -0
- package/server/api/social/comments/[id].delete.ts +13 -0
- package/server/api/social/comments.get.ts +18 -0
- package/server/api/social/comments.post.ts +11 -0
- package/server/api/social/like.get.ts +17 -0
- package/server/api/social/like.post.ts +35 -0
- package/server/api/stats.get.ts +8 -0
- package/server/api/user/hubs.get.ts +22 -0
- package/server/api/users/[username]/content.get.ts +21 -0
- package/server/api/users/[username]/feed.xml.get.ts +65 -0
- package/server/api/users/[username]/follow.delete.ts +15 -0
- package/server/api/users/[username]/follow.post.ts +15 -0
- package/server/api/users/[username]/followers.get.ts +22 -0
- package/server/api/users/[username]/following.get.ts +22 -0
- package/server/api/users/[username]/learning.get.ts +18 -0
- package/server/api/users/[username].get.ts +25 -0
- package/server/api/users/index.get.ts +78 -0
- package/server/api/videos/[id].get.ts +18 -0
- package/server/api/videos/categories/[id].delete.ts +15 -0
- package/server/api/videos/categories/[id].put.ts +17 -0
- package/server/api/videos/categories.get.ts +7 -0
- package/server/api/videos/categories.post.ts +11 -0
- package/server/api/videos/index.get.ts +20 -0
- package/server/api/videos/index.post.ts +11 -0
- package/server/middleware/auth.ts +180 -0
- package/server/middleware/features.ts +31 -0
- package/server/middleware/security.ts +54 -0
- package/server/plugins/auto-admin.ts +69 -0
- package/server/plugins/federation-delivery.ts +74 -0
- package/server/routes/.well-known/nodeinfo.ts +15 -0
- package/server/routes/.well-known/webfinger.ts +86 -0
- package/server/routes/actor/followers.ts +34 -0
- package/server/routes/actor/following.ts +34 -0
- package/server/routes/actor/outbox.ts +31 -0
- package/server/routes/actor.ts +30 -0
- package/server/routes/feed.xml.ts +59 -0
- package/server/routes/hubs/[slug]/followers.ts +39 -0
- package/server/routes/hubs/[slug]/inbox.ts +35 -0
- package/server/routes/hubs/[slug]/outbox.ts +43 -0
- package/server/routes/hubs/[slug]/posts/[postId].ts +63 -0
- package/server/routes/hubs/[slug].ts +29 -0
- package/server/routes/inbox.ts +34 -0
- package/server/routes/nodeinfo/2.1.ts +27 -0
- package/server/routes/robots.txt.ts +19 -0
- package/server/routes/sitemap.xml.ts +105 -0
- package/server/routes/users/[username]/followers.ts +33 -0
- package/server/routes/users/[username]/following.ts +33 -0
- package/server/routes/users/[username]/inbox.ts +34 -0
- package/server/routes/users/[username]/outbox.ts +35 -0
- package/server/routes/users/[username].ts +62 -0
- package/server/utils/auth.ts +36 -0
- package/server/utils/db.ts +34 -0
- package/server/utils/errors.ts +24 -0
- package/server/utils/inbox.ts +122 -0
- package/server/utils/validate.ts +82 -0
- package/theme/base.css +283 -0
- package/theme/components.css +322 -0
- package/theme/dark.css +87 -0
- package/theme/editor-panels.css +63 -0
- package/theme/forms.css +216 -0
- package/theme/generics.css +68 -0
- package/theme/layouts.css +415 -0
- package/theme/prose.css +342 -0
- package/types/hub.ts +61 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Consistent client-side error extraction from API responses
|
|
2
|
+
|
|
3
|
+
export function useApiError() {
|
|
4
|
+
function extract(err: unknown): string {
|
|
5
|
+
const e = err as {
|
|
6
|
+
data?: {
|
|
7
|
+
statusMessage?: string;
|
|
8
|
+
message?: string;
|
|
9
|
+
errors?: Record<string, string[]>;
|
|
10
|
+
};
|
|
11
|
+
statusCode?: number;
|
|
12
|
+
message?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Zod validation errors
|
|
16
|
+
if (e?.data?.errors) {
|
|
17
|
+
return Object.entries(e.data.errors)
|
|
18
|
+
.map(([field, msgs]) => `${field}: ${(msgs as string[]).join(', ')}`)
|
|
19
|
+
.join('; ');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Server error messages
|
|
23
|
+
if (e?.data?.statusMessage) return e.data.statusMessage;
|
|
24
|
+
if (e?.data?.message) return e.data.message;
|
|
25
|
+
|
|
26
|
+
// Status code hints
|
|
27
|
+
if (e?.statusCode === 401) return 'Not authenticated. Please log in again.';
|
|
28
|
+
if (e?.statusCode === 403) return 'Permission denied.';
|
|
29
|
+
if (e?.statusCode === 404) return 'Not found.';
|
|
30
|
+
if (e?.statusCode === 429) return 'Too many requests. Please wait.';
|
|
31
|
+
if (e?.statusCode === 500) return 'Server error. Please try again.';
|
|
32
|
+
|
|
33
|
+
// Fallback
|
|
34
|
+
if (e?.message) return e.message;
|
|
35
|
+
return 'Something went wrong. Please try again.';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { extract };
|
|
39
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Auth composable — reactive auth state + methods
|
|
2
|
+
|
|
3
|
+
/** Client-side auth user shape, matching what Better Auth returns */
|
|
4
|
+
export interface ClientAuthUser {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string | null;
|
|
7
|
+
username: string;
|
|
8
|
+
email: string;
|
|
9
|
+
role: string;
|
|
10
|
+
image: string | null;
|
|
11
|
+
emailVerified: boolean;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ClientAuthSession {
|
|
17
|
+
id: string;
|
|
18
|
+
userId: string;
|
|
19
|
+
token: string;
|
|
20
|
+
expiresAt: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function useAuth() {
|
|
24
|
+
const user = useState<ClientAuthUser | null>('auth-user', () => null);
|
|
25
|
+
const session = useState<ClientAuthSession | null>('auth-session', () => null);
|
|
26
|
+
|
|
27
|
+
const isAuthenticated = computed(() => !!user.value);
|
|
28
|
+
const isAdmin = computed(() => user.value?.role === 'admin');
|
|
29
|
+
|
|
30
|
+
async function signIn(email: string, password: string): Promise<void> {
|
|
31
|
+
const data = await $fetch<{ user: ClientAuthUser | null; session: ClientAuthSession | null }>('/api/auth/sign-in/email', {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
body: { email, password },
|
|
34
|
+
credentials: 'include',
|
|
35
|
+
});
|
|
36
|
+
user.value = data?.user ?? null;
|
|
37
|
+
session.value = data?.session ?? null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function signUp(email: string, password: string, username: string): Promise<void> {
|
|
41
|
+
const data = await $fetch<{ user: ClientAuthUser | null; session: ClientAuthSession | null }>('/api/auth/sign-up/email', {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
body: { email, password, username, name: username },
|
|
44
|
+
credentials: 'include',
|
|
45
|
+
});
|
|
46
|
+
user.value = data?.user ?? null;
|
|
47
|
+
session.value = data?.session ?? null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function signOut(): Promise<void> {
|
|
51
|
+
await $fetch('/api/auth/sign-out', { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json' }, body: {} });
|
|
52
|
+
user.value = null;
|
|
53
|
+
session.value = null;
|
|
54
|
+
await navigateTo('/');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Refresh the session from the server.
|
|
59
|
+
* Call on app mount to detect expired sessions and sync SSR-hydrated state.
|
|
60
|
+
*/
|
|
61
|
+
async function refreshSession(): Promise<void> {
|
|
62
|
+
if (import.meta.server) return;
|
|
63
|
+
try {
|
|
64
|
+
const data = await $fetch<{ user: ClientAuthUser | null; session: ClientAuthSession | null }>(
|
|
65
|
+
'/api/me',
|
|
66
|
+
{ credentials: 'include' },
|
|
67
|
+
);
|
|
68
|
+
user.value = data?.user ?? null;
|
|
69
|
+
session.value = data?.session ?? null;
|
|
70
|
+
} catch {
|
|
71
|
+
// Session invalid or server unreachable — clear client state
|
|
72
|
+
user.value = null;
|
|
73
|
+
session.value = null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
user: readonly(user),
|
|
79
|
+
session: readonly(session),
|
|
80
|
+
isAuthenticated,
|
|
81
|
+
isAdmin,
|
|
82
|
+
signIn,
|
|
83
|
+
signUp,
|
|
84
|
+
signOut,
|
|
85
|
+
refreshSession,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block editor composable — manages an array of content blocks with full CRUD operations.
|
|
3
|
+
* Blocks are stored as { id, type, content } and serialized to/from BlockTuple format for persistence.
|
|
4
|
+
*/
|
|
5
|
+
import type { BlockTuple } from '@commonpub/editor';
|
|
6
|
+
|
|
7
|
+
export interface EditorBlock {
|
|
8
|
+
id: string;
|
|
9
|
+
type: string;
|
|
10
|
+
content: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Default content values when creating a new block of each type */
|
|
14
|
+
const BLOCK_DEFAULTS: Record<string, () => Record<string, unknown>> = {
|
|
15
|
+
paragraph: () => ({ html: '' }),
|
|
16
|
+
heading: () => ({ text: '', level: 2 }),
|
|
17
|
+
code_block: () => ({ code: '', language: '', filename: '' }),
|
|
18
|
+
image: () => ({ src: '', alt: '', caption: '' }),
|
|
19
|
+
blockquote: () => ({ html: '', attribution: '' }),
|
|
20
|
+
callout: () => ({ html: '', variant: 'info' }),
|
|
21
|
+
gallery: () => ({ images: [] }),
|
|
22
|
+
video: () => ({ url: '', platform: 'youtube', caption: '' }),
|
|
23
|
+
embed: () => ({ url: '', type: 'generic', html: '' }),
|
|
24
|
+
horizontal_rule: () => ({}),
|
|
25
|
+
partsList: () => ({ parts: [] }),
|
|
26
|
+
buildStep: () => ({ stepNumber: 1, instructions: '', image: '', time: '' }),
|
|
27
|
+
toolList: () => ({ tools: [] }),
|
|
28
|
+
downloads: () => ({ files: [] }),
|
|
29
|
+
quiz: () => ({ question: '', options: [], feedback: '' }),
|
|
30
|
+
interactiveSlider: () => ({ label: '', min: 0, max: 100, step: 1, defaultValue: 50, states: [] }),
|
|
31
|
+
checkpoint: () => ({ message: '' }),
|
|
32
|
+
mathNotation: () => ({ expression: '', display: false }),
|
|
33
|
+
bulletList: () => ({ html: '' }),
|
|
34
|
+
orderedList: () => ({ html: '' }),
|
|
35
|
+
sectionHeader: () => ({ tag: '', title: '', body: '' }),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function generateId(): string {
|
|
39
|
+
return `blk-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function useBlockEditor(initialBlocks?: BlockTuple[]) {
|
|
43
|
+
const blocks = ref<EditorBlock[]>([]);
|
|
44
|
+
const selectedBlockId = ref<string | null>(null);
|
|
45
|
+
|
|
46
|
+
// --- Init from BlockTuples ---
|
|
47
|
+
function fromBlockTuples(tuples: BlockTuple[]): void {
|
|
48
|
+
blocks.value = tuples.map(([type, content]) => ({
|
|
49
|
+
id: generateId(),
|
|
50
|
+
type,
|
|
51
|
+
content: { ...content },
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (initialBlocks && initialBlocks.length > 0) {
|
|
56
|
+
fromBlockTuples(initialBlocks);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// --- Serialize back to BlockTuples ---
|
|
60
|
+
function toBlockTuples(): BlockTuple[] {
|
|
61
|
+
return blocks.value.map((b) => [b.type, { ...b.content }]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// --- Mutations ---
|
|
65
|
+
|
|
66
|
+
function addBlock(type: string, attrs?: Record<string, unknown>, atIndex?: number): string {
|
|
67
|
+
const defaults = BLOCK_DEFAULTS[type]?.() ?? {};
|
|
68
|
+
const block: EditorBlock = {
|
|
69
|
+
id: generateId(),
|
|
70
|
+
type,
|
|
71
|
+
content: { ...defaults, ...attrs },
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
if (atIndex !== undefined && atIndex >= 0 && atIndex <= blocks.value.length) {
|
|
75
|
+
blocks.value.splice(atIndex, 0, block);
|
|
76
|
+
} else {
|
|
77
|
+
blocks.value.push(block);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
selectedBlockId.value = block.id;
|
|
81
|
+
return block.id;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Replace a block with a new block type (used by slash command) */
|
|
85
|
+
function replaceBlock(id: string, newType: string, attrs?: Record<string, unknown>): string {
|
|
86
|
+
const idx = blocks.value.findIndex((b) => b.id === id);
|
|
87
|
+
if (idx === -1) return addBlock(newType, attrs);
|
|
88
|
+
|
|
89
|
+
const defaults = BLOCK_DEFAULTS[newType]?.() ?? {};
|
|
90
|
+
const newBlock: EditorBlock = {
|
|
91
|
+
id: generateId(),
|
|
92
|
+
type: newType,
|
|
93
|
+
content: { ...defaults, ...attrs },
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
blocks.value.splice(idx, 1, newBlock);
|
|
97
|
+
selectedBlockId.value = newBlock.id;
|
|
98
|
+
return newBlock.id;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function removeBlock(id: string): void {
|
|
102
|
+
const idx = blocks.value.findIndex((b) => b.id === id);
|
|
103
|
+
if (idx === -1) return;
|
|
104
|
+
blocks.value.splice(idx, 1);
|
|
105
|
+
if (selectedBlockId.value === id) {
|
|
106
|
+
selectedBlockId.value = null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function clearBlocks(): void {
|
|
111
|
+
blocks.value.splice(0, blocks.value.length);
|
|
112
|
+
selectedBlockId.value = null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function updateBlock(id: string, content: Record<string, unknown>): void {
|
|
116
|
+
const block = blocks.value.find((b) => b.id === id);
|
|
117
|
+
if (block) {
|
|
118
|
+
block.content = { ...block.content, ...content };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function moveBlock(fromIndex: number, toIndex: number): void {
|
|
123
|
+
if (fromIndex < 0 || fromIndex >= blocks.value.length) return;
|
|
124
|
+
if (toIndex < 0 || toIndex >= blocks.value.length) return;
|
|
125
|
+
const [moved] = blocks.value.splice(fromIndex, 1);
|
|
126
|
+
blocks.value.splice(toIndex, 0, moved!);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function moveBlockUp(id: string): void {
|
|
130
|
+
const idx = blocks.value.findIndex((b) => b.id === id);
|
|
131
|
+
if (idx > 0) moveBlock(idx, idx - 1);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function moveBlockDown(id: string): void {
|
|
135
|
+
const idx = blocks.value.findIndex((b) => b.id === id);
|
|
136
|
+
if (idx < blocks.value.length - 1) moveBlock(idx, idx + 1);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function duplicateBlock(id: string): void {
|
|
140
|
+
const idx = blocks.value.findIndex((b) => b.id === id);
|
|
141
|
+
if (idx === -1) return;
|
|
142
|
+
const original = blocks.value[idx]!;
|
|
143
|
+
const clone: EditorBlock = {
|
|
144
|
+
id: generateId(),
|
|
145
|
+
type: original.type,
|
|
146
|
+
content: JSON.parse(JSON.stringify(original.content)),
|
|
147
|
+
};
|
|
148
|
+
blocks.value.splice(idx + 1, 0, clone);
|
|
149
|
+
selectedBlockId.value = clone.id;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function selectBlock(id: string | null): void {
|
|
153
|
+
selectedBlockId.value = id;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function getBlockIndex(id: string): number {
|
|
157
|
+
return blocks.value.findIndex((b) => b.id === id);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const isEmpty = computed(() => blocks.value.length === 0);
|
|
161
|
+
|
|
162
|
+
const selectedBlock = computed(() =>
|
|
163
|
+
blocks.value.find((b) => b.id === selectedBlockId.value) ?? null,
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
blocks: readonly(blocks) as Readonly<Ref<EditorBlock[]>>,
|
|
168
|
+
selectedBlockId: readonly(selectedBlockId),
|
|
169
|
+
selectedBlock,
|
|
170
|
+
isEmpty,
|
|
171
|
+
addBlock,
|
|
172
|
+
removeBlock,
|
|
173
|
+
clearBlocks,
|
|
174
|
+
updateBlock,
|
|
175
|
+
moveBlock,
|
|
176
|
+
moveBlockUp,
|
|
177
|
+
moveBlockDown,
|
|
178
|
+
duplicateBlock,
|
|
179
|
+
replaceBlock,
|
|
180
|
+
selectBlock,
|
|
181
|
+
getBlockIndex,
|
|
182
|
+
toBlockTuples,
|
|
183
|
+
fromBlockTuples,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export type BlockEditor = ReturnType<typeof useBlockEditor>;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content save composable — manages draft creation, updates, autosave, and publishing.
|
|
3
|
+
* Extracted from edit.vue to keep the page component thin.
|
|
4
|
+
*/
|
|
5
|
+
import type { BlockTuple } from '@commonpub/editor';
|
|
6
|
+
import type { WatchSource } from 'vue';
|
|
7
|
+
|
|
8
|
+
export interface ContentSaveOptions {
|
|
9
|
+
contentType: Ref<string>;
|
|
10
|
+
title: Ref<string>;
|
|
11
|
+
metadata: Ref<Record<string, unknown>>;
|
|
12
|
+
isNew: Ref<boolean>;
|
|
13
|
+
contentId: Ref<string | null>;
|
|
14
|
+
isDirty: Ref<boolean>;
|
|
15
|
+
getBlockTuples: () => BlockTuple[];
|
|
16
|
+
extractError: (err: unknown) => string;
|
|
17
|
+
/** Called after every save to sync product links from partsList blocks */
|
|
18
|
+
onAfterSave?: (id: string) => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ContentSaveReturn {
|
|
22
|
+
saving: Ref<boolean>;
|
|
23
|
+
error: Ref<string>;
|
|
24
|
+
autoSaveStatus: Ref<'idle' | 'saving' | 'saved' | 'error'>;
|
|
25
|
+
/** Save without navigating — used by Save Draft, autosave, Ctrl+S */
|
|
26
|
+
silentSave: () => Promise<void>;
|
|
27
|
+
/** Save and navigate to the content view page */
|
|
28
|
+
handleSave: () => Promise<void>;
|
|
29
|
+
/** Validate, save, publish, and navigate */
|
|
30
|
+
handlePublish: (validate?: () => string[]) => Promise<string[]>;
|
|
31
|
+
/** Build a clean save body from current state */
|
|
32
|
+
buildSaveBody: () => Record<string, unknown>;
|
|
33
|
+
/** Schedule an autosave after the debounce delay */
|
|
34
|
+
scheduleAutoSave: () => void;
|
|
35
|
+
/** Cancel any pending autosave timer */
|
|
36
|
+
cancelAutoSave: () => void;
|
|
37
|
+
/** Set up autosave watchers — call in onMounted or setup */
|
|
38
|
+
initAutoSave: (watches: WatchSource[]) => void;
|
|
39
|
+
/** Clean up timers — call in onUnmounted */
|
|
40
|
+
cleanup: () => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function slugify(text: string): string {
|
|
44
|
+
return text
|
|
45
|
+
.toLowerCase()
|
|
46
|
+
.replace(/[^\w\s-]/g, '')
|
|
47
|
+
.replace(/\s+/g, '-')
|
|
48
|
+
.replace(/-+/g, '-')
|
|
49
|
+
.replace(/^-|-$/g, '')
|
|
50
|
+
.slice(0, 128);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const AUTO_SAVE_DELAY = 30_000;
|
|
54
|
+
|
|
55
|
+
export function useContentSave(opts: ContentSaveOptions): ContentSaveReturn {
|
|
56
|
+
const saving = ref(false);
|
|
57
|
+
const error = ref('');
|
|
58
|
+
const autoSaveStatus = ref<'idle' | 'saving' | 'saved' | 'error'>('idle');
|
|
59
|
+
let autoSaveTimer: ReturnType<typeof setTimeout> | null = null;
|
|
60
|
+
|
|
61
|
+
function buildSaveBody(): Record<string, unknown> {
|
|
62
|
+
const body: Record<string, unknown> = {
|
|
63
|
+
type: opts.contentType.value,
|
|
64
|
+
title: opts.title.value,
|
|
65
|
+
content: opts.getBlockTuples(),
|
|
66
|
+
...opts.metadata.value,
|
|
67
|
+
};
|
|
68
|
+
if (!body.slug) delete body.slug;
|
|
69
|
+
for (const key of Object.keys(body)) {
|
|
70
|
+
if (body[key] === '') body[key] = undefined;
|
|
71
|
+
}
|
|
72
|
+
return body;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function createDraft(body: Record<string, unknown>): Promise<{ id: string; slug: string }> {
|
|
76
|
+
try {
|
|
77
|
+
return await $fetch<{ id: string; slug: string }>('/api/content', { method: 'POST', body });
|
|
78
|
+
} catch (err: unknown) {
|
|
79
|
+
const msg = (err as { data?: { message?: string } })?.data?.message ?? '';
|
|
80
|
+
if (msg.toLowerCase().includes('slug') || msg.toLowerCase().includes('duplicate') || msg.toLowerCase().includes('unique')) {
|
|
81
|
+
body.slug = `${body.slug || slugify(opts.title.value)}-${Date.now().toString(36).slice(-4)}`;
|
|
82
|
+
return await $fetch<{ id: string; slug: string }>('/api/content', { method: 'POST', body });
|
|
83
|
+
}
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function silentSave(): Promise<void> {
|
|
89
|
+
if (saving.value) return;
|
|
90
|
+
if (!opts.title.value) {
|
|
91
|
+
error.value = 'Please enter a title before saving.';
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!opts.isNew.value && !opts.contentId.value) {
|
|
95
|
+
opts.isNew.value = true;
|
|
96
|
+
}
|
|
97
|
+
saving.value = true;
|
|
98
|
+
autoSaveStatus.value = 'saving';
|
|
99
|
+
error.value = '';
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const body = buildSaveBody();
|
|
103
|
+
|
|
104
|
+
if (opts.isNew.value) {
|
|
105
|
+
const result = await createDraft(body);
|
|
106
|
+
opts.contentId.value = result.id;
|
|
107
|
+
opts.isNew.value = false;
|
|
108
|
+
opts.isDirty.value = false;
|
|
109
|
+
autoSaveStatus.value = 'saved';
|
|
110
|
+
if (opts.onAfterSave) await opts.onAfterSave(result.id);
|
|
111
|
+
history.replaceState({}, '', `/${opts.contentType.value}/${result.slug}/edit`);
|
|
112
|
+
} else {
|
|
113
|
+
const updated = await $fetch<{ slug: string }>(`/api/content/${opts.contentId.value}`, { method: 'PUT', body });
|
|
114
|
+
opts.isDirty.value = false;
|
|
115
|
+
autoSaveStatus.value = 'saved';
|
|
116
|
+
if (opts.onAfterSave) await opts.onAfterSave(opts.contentId.value!);
|
|
117
|
+
if (updated?.slug) {
|
|
118
|
+
history.replaceState({}, '', `/${opts.contentType.value}/${updated.slug}/edit`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
setTimeout(() => {
|
|
123
|
+
if (autoSaveStatus.value === 'saved') autoSaveStatus.value = 'idle';
|
|
124
|
+
}, 3000);
|
|
125
|
+
} catch (err: unknown) {
|
|
126
|
+
error.value = opts.extractError(err);
|
|
127
|
+
autoSaveStatus.value = 'error';
|
|
128
|
+
} finally {
|
|
129
|
+
saving.value = false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function handleSave(): Promise<void> {
|
|
134
|
+
if (saving.value || !opts.title.value) return;
|
|
135
|
+
cancelAutoSave();
|
|
136
|
+
if (!opts.isNew.value && !opts.contentId.value) opts.isNew.value = true;
|
|
137
|
+
saving.value = true;
|
|
138
|
+
error.value = '';
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
const body = buildSaveBody();
|
|
142
|
+
if (opts.isNew.value) {
|
|
143
|
+
const result = await createDraft(body);
|
|
144
|
+
opts.contentId.value = result.id;
|
|
145
|
+
opts.isNew.value = false;
|
|
146
|
+
opts.isDirty.value = false;
|
|
147
|
+
if (opts.onAfterSave) await opts.onAfterSave(result.id);
|
|
148
|
+
await navigateTo(`/${opts.contentType.value}/${result.slug}`);
|
|
149
|
+
} else {
|
|
150
|
+
const updated = await $fetch<{ slug?: string }>(`/api/content/${opts.contentId.value}`, { method: 'PUT', body });
|
|
151
|
+
opts.isDirty.value = false;
|
|
152
|
+
if (opts.onAfterSave) await opts.onAfterSave(opts.contentId.value!);
|
|
153
|
+
const currentSlug = updated?.slug || useRoute().params.slug as string;
|
|
154
|
+
await navigateTo(`/${opts.contentType.value}/${currentSlug}`);
|
|
155
|
+
}
|
|
156
|
+
} catch (err: unknown) {
|
|
157
|
+
error.value = opts.extractError(err);
|
|
158
|
+
} finally {
|
|
159
|
+
saving.value = false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function handlePublish(validate?: () => string[]): Promise<string[]> {
|
|
164
|
+
if (saving.value || !opts.title.value) return ['Title is required'];
|
|
165
|
+
if (validate) {
|
|
166
|
+
const errs = validate();
|
|
167
|
+
if (errs.length > 0) return errs;
|
|
168
|
+
}
|
|
169
|
+
cancelAutoSave();
|
|
170
|
+
saving.value = true;
|
|
171
|
+
error.value = '';
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
const body = buildSaveBody();
|
|
175
|
+
let resultSlug = useRoute().params.slug as string;
|
|
176
|
+
|
|
177
|
+
if (opts.isNew.value || !opts.contentId.value) {
|
|
178
|
+
const result = await createDraft(body);
|
|
179
|
+
opts.contentId.value = result.id;
|
|
180
|
+
opts.isNew.value = false;
|
|
181
|
+
resultSlug = result.slug;
|
|
182
|
+
if (opts.onAfterSave) await opts.onAfterSave(result.id);
|
|
183
|
+
} else {
|
|
184
|
+
const updated = await $fetch<{ slug: string }>(`/api/content/${opts.contentId.value}`, { method: 'PUT', body });
|
|
185
|
+
if (updated?.slug) resultSlug = updated.slug;
|
|
186
|
+
if (opts.onAfterSave) await opts.onAfterSave(opts.contentId.value!);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
await $fetch(`/api/content/${opts.contentId.value}/publish`, { method: 'POST' });
|
|
190
|
+
|
|
191
|
+
// Share to hub if one is selected in metadata
|
|
192
|
+
const hubSlug = opts.metadata.value?.hubSlug as string | undefined;
|
|
193
|
+
if (hubSlug && opts.contentId.value) {
|
|
194
|
+
try {
|
|
195
|
+
await $fetch(`/api/hubs/${hubSlug}/share`, {
|
|
196
|
+
method: 'POST',
|
|
197
|
+
body: { contentId: opts.contentId.value },
|
|
198
|
+
});
|
|
199
|
+
} catch {
|
|
200
|
+
// Non-fatal: content is published even if hub share fails
|
|
201
|
+
console.warn(`[publish] Failed to share to hub ${hubSlug}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
opts.isDirty.value = false;
|
|
206
|
+
await navigateTo(`/${opts.contentType.value}/${resultSlug}`);
|
|
207
|
+
return [];
|
|
208
|
+
} catch (err: unknown) {
|
|
209
|
+
error.value = opts.extractError(err);
|
|
210
|
+
return [];
|
|
211
|
+
} finally {
|
|
212
|
+
saving.value = false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function scheduleAutoSave(): void {
|
|
217
|
+
if (autoSaveTimer) clearTimeout(autoSaveTimer);
|
|
218
|
+
autoSaveTimer = setTimeout(async () => {
|
|
219
|
+
if (!opts.isDirty.value || saving.value || opts.isNew.value || !opts.contentId.value || !opts.title.value) return;
|
|
220
|
+
await silentSave();
|
|
221
|
+
}, AUTO_SAVE_DELAY);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function cancelAutoSave(): void {
|
|
225
|
+
if (autoSaveTimer) { clearTimeout(autoSaveTimer); autoSaveTimer = null; }
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function initAutoSave(watches: WatchSource[]): void {
|
|
229
|
+
watch(watches, () => {
|
|
230
|
+
if (!opts.isNew.value && opts.contentId.value) {
|
|
231
|
+
scheduleAutoSave();
|
|
232
|
+
}
|
|
233
|
+
}, { deep: true });
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function cleanup(): void {
|
|
237
|
+
cancelAutoSave();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
saving,
|
|
242
|
+
error,
|
|
243
|
+
autoSaveStatus,
|
|
244
|
+
silentSave,
|
|
245
|
+
handleSave,
|
|
246
|
+
handlePublish,
|
|
247
|
+
buildSaveBody,
|
|
248
|
+
scheduleAutoSave,
|
|
249
|
+
cancelAutoSave,
|
|
250
|
+
initAutoSave,
|
|
251
|
+
cleanup,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Content type composable — reactive access to enabled content types
|
|
2
|
+
|
|
3
|
+
export type ContentType = 'project' | 'article' | 'blog' | 'explainer';
|
|
4
|
+
|
|
5
|
+
const CONTENT_TYPE_META: Record<ContentType, { label: string; plural: string; icon: string; route: string }> = {
|
|
6
|
+
project: { label: 'Project', plural: 'Projects', icon: 'fa-solid fa-microchip', route: '/project' },
|
|
7
|
+
article: { label: 'Article', plural: 'Articles', icon: 'fa-solid fa-file-lines', route: '/article' },
|
|
8
|
+
blog: { label: 'Blog', plural: 'Blogs', icon: 'fa-solid fa-pen-nib', route: '/blog' },
|
|
9
|
+
explainer: { label: 'Explainer', plural: 'Explainers', icon: 'fa-solid fa-lightbulb', route: '/explainer' },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function useContentTypes() {
|
|
13
|
+
const config = useRuntimeConfig();
|
|
14
|
+
|
|
15
|
+
const enabledTypes = computed<ContentType[]>(() => {
|
|
16
|
+
const raw = config.public.contentTypes as string;
|
|
17
|
+
if (!raw) return ['project', 'article', 'blog', 'explainer'];
|
|
18
|
+
return raw.split(',').map(s => s.trim()).filter(Boolean) as ContentType[];
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const isTypeEnabled = (type: ContentType): boolean => {
|
|
22
|
+
return enabledTypes.value.includes(type);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const enabledTypeMeta = computed(() => {
|
|
26
|
+
return enabledTypes.value
|
|
27
|
+
.filter(t => t in CONTENT_TYPE_META)
|
|
28
|
+
.map(t => ({ type: t, ...CONTENT_TYPE_META[t] }));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
enabledTypes,
|
|
33
|
+
isTypeEnabled,
|
|
34
|
+
enabledTypeMeta,
|
|
35
|
+
CONTENT_TYPE_META,
|
|
36
|
+
};
|
|
37
|
+
}
|