tinyzoo 0.0.0-stage → 0.2.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 +10 -0
- package/README.md +46 -2
- package/app/app.config.ts +35 -0
- package/app/assets/brand/characters/bright/bird.svg +1 -0
- package/app/assets/brand/characters/bright/bunny.svg +1 -0
- package/app/assets/brand/characters/bright/elephant.svg +1 -0
- package/app/assets/brand/characters/bright/fox.svg +1 -0
- package/app/assets/brand/characters/bright/frog.svg +1 -0
- package/app/assets/brand/characters/bright/octopus.svg +1 -0
- package/app/assets/brand/characters/muted/bee.svg +1 -0
- package/app/assets/brand/characters/muted/bird.svg +1 -0
- package/app/assets/brand/characters/muted/butterfly.svg +1 -0
- package/app/assets/brand/characters/muted/chick.svg +1 -0
- package/app/assets/brand/characters/muted/cow.svg +1 -0
- package/app/assets/brand/characters/muted/deer.svg +1 -0
- package/app/assets/brand/characters/muted/duck.svg +1 -0
- package/app/assets/brand/characters/muted/elephant.svg +1 -0
- package/app/assets/brand/characters/muted/fox.svg +1 -0
- package/app/assets/brand/characters/muted/hedgehog.svg +1 -0
- package/app/assets/brand/characters/muted/koala.svg +1 -0
- package/app/assets/brand/characters/muted/ladybug.svg +1 -0
- package/app/assets/brand/characters/muted/lion.svg +1 -0
- package/app/assets/brand/characters/muted/mouse.svg +1 -0
- package/app/assets/brand/characters/muted/octopus.svg +1 -0
- package/app/assets/brand/characters/muted/owl.svg +1 -0
- package/app/assets/brand/characters/muted/panda.svg +1 -0
- package/app/assets/brand/characters/muted/penguin.svg +1 -0
- package/app/assets/brand/characters/muted/pig.svg +1 -0
- package/app/assets/brand/characters/muted/poodle.svg +1 -0
- package/app/assets/brand/characters/muted/raccoon.svg +1 -0
- package/app/assets/brand/characters/muted/seal.svg +1 -0
- package/app/assets/brand/characters/muted/sheep.svg +1 -0
- package/app/assets/brand/characters/muted/snail.svg +1 -0
- package/app/assets/brand/characters/muted/turtle.svg +1 -0
- package/app/assets/brand/characters/muted/whale.svg +1 -0
- package/app/assets/brand/logo/favicon.svg +1 -0
- package/app/assets/brand/logo/logo-primary-reversed.svg +1 -0
- package/app/assets/brand/logo/logo-primary.svg +1 -0
- package/app/assets/brand/logo/mascot-reversed.svg +1 -0
- package/app/assets/brand/logo/mascot.svg +1 -0
- package/app/assets/brand/logo/wordmark-reversed.svg +1 -0
- package/app/assets/brand/logo/wordmark.svg +1 -0
- package/app/assets/css/cms-admin.css +607 -0
- package/app/components/CmsBlocks.vue +30 -0
- package/app/components/CmsCell.vue +16 -0
- package/app/components/CmsCellBadge.vue +18 -0
- package/app/components/CmsCellBlocks.vue +9 -0
- package/app/components/CmsCellBoolean.vue +12 -0
- package/app/components/CmsCellCode.vue +7 -0
- package/app/components/CmsCellColor.vue +13 -0
- package/app/components/CmsCellDate.vue +10 -0
- package/app/components/CmsCellExcerpt.vue +21 -0
- package/app/components/CmsCellGallery.vue +10 -0
- package/app/components/CmsCellGroup.vue +23 -0
- package/app/components/CmsCellNumber.vue +7 -0
- package/app/components/CmsCellRelation.vue +8 -0
- package/app/components/CmsCellText.vue +12 -0
- package/app/components/CmsCellThumb.vue +18 -0
- package/app/components/CmsConfirmDialog.vue +55 -0
- package/app/components/CmsContent.vue +103 -0
- package/app/components/CmsDayPicker.vue +44 -0
- package/app/components/CmsEmptyState.vue +35 -0
- package/app/components/CmsField.vue +111 -0
- package/app/components/CmsFieldBlocks.vue +353 -0
- package/app/components/CmsFieldBoolean.vue +8 -0
- package/app/components/CmsFieldColor.vue +42 -0
- package/app/components/CmsFieldDate.vue +131 -0
- package/app/components/CmsFieldGallery.vue +114 -0
- package/app/components/CmsFieldGroup.vue +53 -0
- package/app/components/CmsFieldMedia.vue +219 -0
- package/app/components/CmsFieldNumber.vue +11 -0
- package/app/components/CmsFieldRelationMany.vue +54 -0
- package/app/components/CmsFieldRelationOne.vue +47 -0
- package/app/components/CmsFieldRichText.vue +45 -0
- package/app/components/CmsFieldSelect.vue +41 -0
- package/app/components/CmsFieldSlug.vue +46 -0
- package/app/components/CmsFieldText.vue +75 -0
- package/app/components/CmsFormSections.vue +150 -0
- package/app/components/CmsHighlight.vue +22 -0
- package/app/components/CmsImage.vue +39 -0
- package/app/components/CmsLinkPicker.vue +122 -0
- package/app/components/CmsLinkTarget.vue +35 -0
- package/app/components/CmsListFilters.vue +107 -0
- package/app/components/CmsLiveNotice.vue +64 -0
- package/app/components/CmsLoadError.vue +24 -0
- package/app/components/CmsMascot.vue +10 -0
- package/app/components/CmsMediaLibrary.vue +114 -0
- package/app/components/CmsMediaPreview.vue +34 -0
- package/app/components/CmsMediaThumb.vue +22 -0
- package/app/components/CmsMoment.vue +42 -0
- package/app/components/CmsNav.vue +39 -0
- package/app/components/CmsPage.vue +86 -0
- package/app/components/CmsPasswordInput.vue +22 -0
- package/app/components/CmsPresence.vue +29 -0
- package/app/components/CmsPreviewPanel.vue +131 -0
- package/app/components/CmsPublishReview.vue +102 -0
- package/app/components/CmsRevisions.vue +195 -0
- package/app/components/CmsRichTextEditor.vue +290 -0
- package/app/components/CmsSearch.vue +99 -0
- package/app/components/CmsSection.vue +20 -0
- package/app/components/CmsSingletonForm.vue +283 -0
- package/app/components/CmsStatusBadge.vue +21 -0
- package/app/components/CmsTime.vue +16 -0
- package/app/components/CmsTranslationRef.vue +27 -0
- package/app/components/CmsTreeList.vue +453 -0
- package/app/components/CmsUnsavedText.vue +34 -0
- package/app/components/CmsWordmark.vue +10 -0
- package/app/composables/useCmsAdminHead.ts +18 -0
- package/app/composables/useCmsCollab.ts +165 -0
- package/app/composables/useCmsConfirm.ts +39 -0
- package/app/composables/useCmsEntryActions.ts +75 -0
- package/app/composables/useCmsFocus.ts +13 -0
- package/app/composables/useCmsForm.ts +273 -0
- package/app/composables/useCmsI18n.ts +185 -0
- package/app/composables/useCmsLinkTargets.ts +84 -0
- package/app/composables/useCmsLive.ts +199 -0
- package/app/composables/useCmsSearch.ts +62 -0
- package/app/composables/useCmsSeo.ts +99 -0
- package/app/composables/useCmsSignedIn.ts +24 -0
- package/app/composables/useCmsUiLocale.ts +24 -0
- package/app/i18n/cs.ts +781 -0
- package/app/i18n/de.ts +781 -0
- package/app/i18n/en.ts +782 -0
- package/app/i18n/types.ts +22 -0
- package/app/layouts/admin.vue +224 -0
- package/app/layouts/cms-auth.vue +37 -0
- package/app/middleware/cms-api-not-a-page.global.ts +10 -0
- package/app/middleware/cms-auth.global.ts +16 -0
- package/app/pages/admin/[entity]/[id].vue +1109 -0
- package/app/pages/admin/[entity]/index.vue +733 -0
- package/app/pages/admin/account.vue +117 -0
- package/app/pages/admin/forgot.vue +50 -0
- package/app/pages/admin/index.vue +184 -0
- package/app/pages/admin/invite/[token].vue +73 -0
- package/app/pages/admin/login.vue +84 -0
- package/app/pages/admin/media.vue +494 -0
- package/app/pages/admin/privacy.vue +193 -0
- package/app/pages/admin/reset/[token].vue +52 -0
- package/app/pages/admin/setup.vue +87 -0
- package/app/pages/admin/styleguide.vue +261 -0
- package/app/pages/admin/team.vue +258 -0
- package/app/plugins/cmsLivePreview.client.ts +20 -0
- package/app/plugins/cmsSignedOut.client.ts +31 -0
- package/app/utils/cmsBlockType.ts +11 -0
- package/app/utils/cmsBrand.ts +38 -0
- package/app/utils/cmsDiff.ts +83 -0
- package/app/utils/cmsFetch.ts +7 -0
- package/app/utils/cmsFocusInvalid.ts +22 -0
- package/app/utils/cmsIssues.ts +128 -0
- package/app/utils/cmsJson.ts +28 -0
- package/app/utils/cmsMedia.ts +63 -0
- package/app/utils/cmsSections.ts +154 -0
- package/app/utils/cmsTime.ts +41 -0
- package/cli/backup.ts +713 -0
- package/cli/breaking.ts +174 -0
- package/cli/content-migrate.ts +239 -0
- package/cli/db.ts +86 -0
- package/cli/export.ts +336 -0
- package/cli/generate.ts +146 -0
- package/cli/import.ts +643 -0
- package/cli/index.ts +140 -0
- package/cli/links-convert.ts +291 -0
- package/cli/seed-engine.ts +705 -0
- package/cli/seed.ts +339 -0
- package/cli/status.ts +49 -0
- package/cli/tar.ts +304 -0
- package/cli/transfer.ts +677 -0
- package/cli/up.ts +27 -0
- package/cli/upgrade.ts +60 -0
- package/cli/versions.ts +60 -0
- package/forms/components/CmsForm.vue +186 -0
- package/forms/index.ts +203 -0
- package/forms/messages.ts +104 -0
- package/forms/retention.ts +48 -0
- package/forms/server/form.get.ts +12 -0
- package/forms/server/form.post.ts +109 -0
- package/forms/server/formSettings.ts +12 -0
- package/forms/server/forms.ts +127 -0
- package/module.ts +373 -0
- package/nuxt.config.ts +43 -0
- package/package.json +99 -3
- package/server/api/cms/[entity]/[id]/revisions/[rev].get.ts +19 -0
- package/server/api/cms/[entity]/[id]/revisions/index.get.ts +14 -0
- package/server/api/cms/[entity]/[id].delete.ts +52 -0
- package/server/api/cms/[entity]/[id].get.ts +21 -0
- package/server/api/cms/[entity]/[id].patch.ts +116 -0
- package/server/api/cms/[entity]/_export.get.ts +69 -0
- package/server/api/cms/[entity]/_move.post.ts +81 -0
- package/server/api/cms/[entity]/_order.post.ts +49 -0
- package/server/api/cms/[entity]/_tree.get.ts +41 -0
- package/server/api/cms/[entity]/index.get.ts +62 -0
- package/server/api/cms/[entity]/index.post.ts +38 -0
- package/server/api/cms/[entity]/options.get.ts +55 -0
- package/server/api/cms/_auth/accept.post.ts +33 -0
- package/server/api/cms/_auth/forgot.post.ts +39 -0
- package/server/api/cms/_auth/invite/[token].get.ts +18 -0
- package/server/api/cms/_auth/login.post.ts +42 -0
- package/server/api/cms/_auth/logout.post.ts +7 -0
- package/server/api/cms/_auth/me.get.ts +5 -0
- package/server/api/cms/_auth/me.patch.ts +32 -0
- package/server/api/cms/_auth/password.post.ts +29 -0
- package/server/api/cms/_auth/reset.post.ts +34 -0
- package/server/api/cms/_auth/setup.post.ts +46 -0
- package/server/api/cms/_auth/status.get.ts +18 -0
- package/server/api/cms/_collab/session.get.ts +30 -0
- package/server/api/cms/_collab/socket.ts +51 -0
- package/server/api/cms/_collab/unsaved.delete.ts +16 -0
- package/server/api/cms/_graph.get.ts +20 -0
- package/server/api/cms/_links/resolve.post.ts +17 -0
- package/server/api/cms/_links.get.ts +81 -0
- package/server/api/cms/_live.ts +30 -0
- package/server/api/cms/_media/[id]/usage.get.ts +14 -0
- package/server/api/cms/_media/[id].delete.ts +29 -0
- package/server/api/cms/_media/[id].get.ts +13 -0
- package/server/api/cms/_media/[id].patch.ts +64 -0
- package/server/api/cms/_media/exists.post.ts +15 -0
- package/server/api/cms/_media/img/[id]/[file].get.ts +42 -0
- package/server/api/cms/_media/index.get.ts +44 -0
- package/server/api/cms/_media/index.post.ts +147 -0
- package/server/api/cms/_media/raw/[...key].get.ts +85 -0
- package/server/api/cms/_media/raw/[...key].head.ts +2 -0
- package/server/api/cms/_overview.get.ts +87 -0
- package/server/api/cms/_preview.post.ts +17 -0
- package/server/api/cms/_privacy/delete.post.ts +14 -0
- package/server/api/cms/_privacy/export.post.ts +25 -0
- package/server/api/cms/_privacy/lookup.post.ts +27 -0
- package/server/api/cms/_search.get.ts +17 -0
- package/server/api/cms/_singleton/[name].get.ts +19 -0
- package/server/api/cms/_singleton/[name].put.ts +76 -0
- package/server/api/cms/_users/[id]/resend.post.ts +25 -0
- package/server/api/cms/_users/[id].delete.ts +21 -0
- package/server/api/cms/_users/[id].patch.ts +45 -0
- package/server/api/cms/_users/index.get.ts +28 -0
- package/server/api/cms/_users/index.post.ts +39 -0
- package/server/api/content/[entity]/[slug].get.ts +74 -0
- package/server/api/content/[entity]/index.get.ts +100 -0
- package/server/api/content/_global/[name].get.ts +23 -0
- package/server/api/content/_search.get.ts +28 -0
- package/server/api/content/_sitemap.get.ts +8 -0
- package/server/api/content/_tree/[entity].get.ts +31 -0
- package/server/api/content-types.ts.get.ts +17 -0
- package/server/api/health/live.get.ts +10 -0
- package/server/api/health/ready.get.ts +21 -0
- package/server/api/openapi.get.ts +48 -0
- package/server/api/openapi.json.get.ts +32 -0
- package/server/db/driver.ts +8 -0
- package/server/mail/mailer.ts +43 -0
- package/server/middleware/cms-0-headers.ts +37 -0
- package/server/middleware/cms-0-migrate-gate.ts +14 -0
- package/server/middleware/cms-csrf.ts +28 -0
- package/server/middleware/cms-limits.ts +20 -0
- package/server/middleware/cms-redirects.ts +21 -0
- package/server/middleware/cms-session.ts +41 -0
- package/server/middleware/cms-z-plugin-access.ts +15 -0
- package/server/plugins/cms-0-config-check.ts +35 -0
- package/server/plugins/cms-changes.ts +53 -0
- package/server/plugins/cms-content-etag.ts +21 -0
- package/server/plugins/cms-errors.ts +45 -0
- package/server/plugins/cms-migrate.ts +5 -0
- package/server/plugins/cms-plugins.ts +17 -0
- package/server/plugins/cms-search.ts +12 -0
- package/server/plugins/cms-setup-code.ts +15 -0
- package/server/routes/sitemap.xml.get.ts +25 -0
- package/server/store/redis.ts +95 -0
- package/server/store/types.ts +21 -0
- package/server/tasks/cms/retention.ts +10 -0
- package/server/tasks/cms/scheduled.ts +10 -0
- package/server/tasks/cms/search-reindex.ts +12 -0
- package/server/utils/cmsAudit.ts +29 -0
- package/server/utils/cmsAuth.ts +143 -0
- package/server/utils/cmsBlocks.ts +47 -0
- package/server/utils/cmsChanges.ts +222 -0
- package/server/utils/cmsCollab.ts +286 -0
- package/server/utils/cmsCollabServer.ts +451 -0
- package/server/utils/cmsCollate.ts +27 -0
- package/server/utils/cmsContent.ts +376 -0
- package/server/utils/cmsCrud.ts +361 -0
- package/server/utils/cmsCsv.ts +24 -0
- package/server/utils/cmsDb.ts +23 -0
- package/server/utils/cmsDemo.ts +36 -0
- package/server/utils/cmsEmails.ts +125 -0
- package/server/utils/cmsErrors.ts +40 -0
- package/server/utils/cmsFold.ts +17 -0
- package/server/utils/cmsImageSizes.ts +51 -0
- package/server/utils/cmsJson.ts +6 -0
- package/server/utils/cmsLinkAddress.ts +50 -0
- package/server/utils/cmsLinks.ts +248 -0
- package/server/utils/cmsListQuery.ts +93 -0
- package/server/utils/cmsLive.ts +392 -0
- package/server/utils/cmsLocales.ts +96 -0
- package/server/utils/cmsMail.ts +28 -0
- package/server/utils/cmsMediaGc.ts +188 -0
- package/server/utils/cmsMediaKeys.ts +62 -0
- package/server/utils/cmsMigrate.ts +86 -0
- package/server/utils/cmsPreviewDraft.ts +72 -0
- package/server/utils/cmsPrivacy.ts +176 -0
- package/server/utils/cmsPublished.ts +57 -0
- package/server/utils/cmsRange.ts +38 -0
- package/server/utils/cmsRateLimit.ts +82 -0
- package/server/utils/cmsRedirects.ts +160 -0
- package/server/utils/cmsRetention.ts +61 -0
- package/server/utils/cmsRevisions.ts +103 -0
- package/server/utils/cmsScheduler.ts +45 -0
- package/server/utils/cmsScrub.ts +107 -0
- package/server/utils/cmsSearch.ts +354 -0
- package/server/utils/cmsSession.ts +102 -0
- package/server/utils/cmsSetupCode.ts +97 -0
- package/server/utils/cmsSitemap.ts +176 -0
- package/server/utils/cmsStorage.ts +580 -0
- package/server/utils/cmsStore.ts +109 -0
- package/server/utils/cmsTooMany.ts +9 -0
- package/server/utils/cmsTranslationWrite.ts +186 -0
- package/server/utils/cmsTree.ts +251 -0
- package/server/utils/cmsTreeAddress.ts +65 -0
- package/server/utils/cmsUpload.ts +197 -0
- package/server/utils/cmsWebhooks.ts +101 -0
- package/shared/json.ts +11 -0
- package/shared/richtext-editor.ts +56 -0
- package/shared/richtext-normalize.ts +33 -0
- package/shared/richtext-paste.ts +151 -0
- package/shared/storage-delivery.ts +53 -0
- package/src/blocks.ts +624 -0
- package/src/changes.ts +54 -0
- package/src/content-shape.ts +340 -0
- package/src/deprecate.ts +64 -0
- package/src/descriptor.ts +149 -0
- package/src/docs.ts +27 -0
- package/src/emitter.ts +94 -0
- package/src/entity.ts +624 -0
- package/src/errorReport.ts +41 -0
- package/src/fields.ts +465 -0
- package/src/i18n.ts +26 -0
- package/src/index.ts +54 -0
- package/src/linkref.ts +31 -0
- package/src/links.ts +179 -0
- package/src/locales.ts +39 -0
- package/src/media.ts +48 -0
- package/src/migrate.ts +236 -0
- package/src/openapi.ts +377 -0
- package/src/paths.ts +88 -0
- package/src/plugin.ts +505 -0
- package/src/presets.ts +230 -0
- package/src/richtext.ts +88 -0
- package/src/sdk.ts +181 -0
- package/src/search.ts +312 -0
- package/src/seed.ts +225 -0
- package/src/setupCode.ts +30 -0
- package/src/system.ts +219 -0
- package/src/tree.ts +421 -0
- package/src/upgrades.ts +137 -0
- package/starter/.env.example +10 -0
- package/starter/README.md +65 -0
- package/starter/app/app.config.ts +10 -0
- package/starter/app/app.vue +12 -0
- package/starter/app/assets/css/main.css +15 -0
- package/starter/app/components/global/BlockContact.vue +15 -0
- package/starter/app/components/global/BlockCta.vue +15 -0
- package/starter/app/components/global/BlockHero.vue +23 -0
- package/starter/app/components/global/BlockImage.vue +13 -0
- package/starter/app/components/global/BlockText.vue +12 -0
- package/starter/app/composables/useSite.ts +77 -0
- package/starter/app/error.vue +28 -0
- package/starter/app/layouts/default.vue +106 -0
- package/starter/app/lib/cms-content.ts +152 -0
- package/starter/app/pages/[...slug].vue +66 -0
- package/starter/app/pages/hledat.vue +59 -0
- package/starter/app/pages/index.vue +20 -0
- package/starter/cms.config.ts +137 -0
- package/starter/compose.yaml +15 -0
- package/starter/drizzle.config.ts +8 -0
- package/starter/gitignore.txt +8 -0
- package/starter/nuxt.config.ts +13 -0
- package/starter/package.json +38 -0
- package/starter/scripts/typecheck.mjs +38 -0
- package/starter/seed/index.ts +297 -0
- package/starter/seed/media/about.jpg +0 -0
- package/starter/seed/media/hero.jpg +0 -0
- package/starter/seed/media/logo.png +0 -0
- package/starter/seed/media/news-bread.jpg +0 -0
- package/starter/seed/media/news-morning.jpg +0 -0
- package/starter/server/db/migrations/0000_init.sql +269 -0
- package/starter/server/db/migrations/0001_page_tree.sql +5 -0
- package/starter/server/db/migrations/0002_opening_hours_per_language.sql +1 -0
- package/starter/server/db/migrations/meta/0000_snapshot.json +1890 -0
- package/starter/server/db/migrations/meta/0001_snapshot.json +1887 -0
- package/starter/server/db/migrations/meta/0002_snapshot.json +1893 -0
- package/starter/server/db/migrations/meta/_journal.json +27 -0
- package/starter/server/db/schema.ts +253 -0
- package/starter/server/plugins/sitemap.ts +11 -0
- package/starter/server/routes/robots.txt.get.ts +12 -0
- package/starter/tsconfig.json +9 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// The history of an entry (or one translation): every save, newest first, and for
|
|
3
|
+
// the one picked, the fields that differ from what is in the form now, with the
|
|
4
|
+
// words that changed highlighted. "Restore this version" puts it into the form —
|
|
5
|
+
// nothing is saved until the editor saves.
|
|
6
|
+
const props = defineProps<{ entity: string; id: string; locale: string | null; fields: any[]; current: Record<string, any> }>()
|
|
7
|
+
const open = defineModel<boolean>('open', { default: false })
|
|
8
|
+
const emit = defineEmits<{ restore: [data: Record<string, any>] }>()
|
|
9
|
+
const { t, fieldLabel, formatDate, formatRelative } = useCmsI18n()
|
|
10
|
+
|
|
11
|
+
const query = computed(() => (props.locale ? `?locale=${props.locale}` : ''))
|
|
12
|
+
const { data: list, status, refresh } = useFetch<{ revisions: any[] }>(() => `/api/cms/${props.entity}/${props.id}/revisions${query.value}`, { immediate: false, server: false })
|
|
13
|
+
watch(open, (o) => { if (o) refresh() })
|
|
14
|
+
const revisions = computed(() => list.value?.revisions ?? [])
|
|
15
|
+
|
|
16
|
+
const selectedId = ref<string | null>(null)
|
|
17
|
+
const selected = ref<any>(null)
|
|
18
|
+
const loading = ref(false)
|
|
19
|
+
watch(revisions, (rs) => { if (rs.length && !rs.some((r) => r.id === selectedId.value)) pick(rs[0].id) })
|
|
20
|
+
async function pick(rev: string) {
|
|
21
|
+
selectedId.value = rev
|
|
22
|
+
loading.value = true
|
|
23
|
+
try {
|
|
24
|
+
const found = (await cmsFetch<{ revision: any }>(`/api/cms/${props.entity}/${props.id}/revisions/${rev}`)).revision
|
|
25
|
+
// Clicked another one meanwhile: that answer wins, not this one.
|
|
26
|
+
if (selectedId.value === rev) selected.value = found
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
if (selectedId.value === rev) loading.value = false
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const byKey = computed(() => new Map(props.fields.map((f: any) => [f.key, f])))
|
|
34
|
+
|
|
35
|
+
// ── files and related entries: shown by name (and a thumbnail), never by id ──
|
|
36
|
+
type Ref = { label: string; thumb: string | null } | null
|
|
37
|
+
const names = ref<Record<string, Ref>>({})
|
|
38
|
+
const isRefField = (f: any) => f?.type === 'media' || f?.type === 'gallery' || f?.relation?.kind === 'many-to-one' || f?.relation?.kind === 'many-to-many'
|
|
39
|
+
const refKey = (f: any, id: string) => (f.type === 'media' || f.type === 'gallery' ? `media:${id}` : `${f.relation.to}:${id}`)
|
|
40
|
+
function refIds(f: any, v: any): string[] {
|
|
41
|
+
if (v === null || v === undefined || v === '') return []
|
|
42
|
+
if (f.type === 'media') return typeof v === 'string' ? [v] : []
|
|
43
|
+
if (f.type === 'gallery') return Array.isArray(v) ? v.map((x: any) => x?.mediaId).filter(Boolean) : []
|
|
44
|
+
if (f.relation?.kind === 'many-to-one') return typeof v === 'string' ? [v] : []
|
|
45
|
+
return Array.isArray(v) ? v.filter((x: any) => typeof x === 'string') : []
|
|
46
|
+
}
|
|
47
|
+
const mediaRef = (m: any): Ref => (m ? { label: String(m.name || m.alt || String(m.key ?? '').split('/').pop() || ''), thumb: String(m.mime ?? '').startsWith('image/') ? m.url ?? null : null } : null)
|
|
48
|
+
/** Look up the names of every file and related entry in the picked version and in the form. */
|
|
49
|
+
async function resolveNames() {
|
|
50
|
+
const wanted = new Map<string, { f: any; id: string }>()
|
|
51
|
+
const sources = [selected.value?.data, props.current]
|
|
52
|
+
for (const f of props.fields) {
|
|
53
|
+
if (!isRefField(f)) continue
|
|
54
|
+
for (const src of sources) {
|
|
55
|
+
if (!src) continue
|
|
56
|
+
for (const id of refIds(f, src[f.key])) {
|
|
57
|
+
const k = refKey(f, id)
|
|
58
|
+
if (k in names.value) continue
|
|
59
|
+
// The record that came with the version, when it is the one.
|
|
60
|
+
const known = f.type === 'media' && src[`${f.key}__media`]?.id === id ? mediaRef(src[`${f.key}__media`]) : undefined
|
|
61
|
+
if (known) names.value = { ...names.value, [k]: known }
|
|
62
|
+
else wanted.set(k, { f, id })
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!wanted.size) return
|
|
67
|
+
const next: Record<string, Ref> = {}
|
|
68
|
+
const byEntity = new Map<string, string[]>()
|
|
69
|
+
await Promise.all([...wanted].map(async ([k, { f, id }]) => {
|
|
70
|
+
if (f.type === 'media' || f.type === 'gallery') {
|
|
71
|
+
next[k] = mediaRef(await cmsFetch(`/api/cms/_media/${id}`).catch(() => null))
|
|
72
|
+
}
|
|
73
|
+
else byEntity.set(f.relation.to, [...(byEntity.get(f.relation.to) ?? []), id])
|
|
74
|
+
}))
|
|
75
|
+
await Promise.all([...byEntity].map(async ([to, ids]) => {
|
|
76
|
+
const found = await cmsFetch<{ id: string; label: string }[]>(`/api/cms/${to}/options`, { query: { selected: ids.join(',') } }).catch(() => [])
|
|
77
|
+
for (const id of ids) {
|
|
78
|
+
const hit = found.find((x) => x.id === id)
|
|
79
|
+
next[`${to}:${id}`] = hit ? { label: String(hit.label ?? ''), thumb: null } : null
|
|
80
|
+
}
|
|
81
|
+
}))
|
|
82
|
+
names.value = { ...names.value, ...next }
|
|
83
|
+
}
|
|
84
|
+
watch([selected, () => open.value], () => { if (open.value && selected.value) void resolveNames() })
|
|
85
|
+
const refParts = (f: any, v: any) => refIds(f, v).map((id) => names.value[refKey(f, id)] ?? undefined).map((r) => (r === undefined ? { label: '…', thumb: null } : r ?? { label: t('revisions.gone'), thumb: null }))
|
|
86
|
+
const textOf = (f: any, v: any): string => {
|
|
87
|
+
if (v === null || v === undefined || v === '') return ''
|
|
88
|
+
if (f?.type === 'richtext') return richTextToPlain(v)
|
|
89
|
+
if (f?.type === 'boolean') return v ? t('fields.yes') : t('fields.no')
|
|
90
|
+
if (f?.type === 'datetime') return formatDate(v)
|
|
91
|
+
if (isRefField(f)) return refParts(f, v).map((p) => p.label).join(', ')
|
|
92
|
+
if (Array.isArray(v)) return t('revisions.items', { count: v.length })
|
|
93
|
+
if (typeof v === 'object') return JSON.stringify(v)
|
|
94
|
+
return String(v)
|
|
95
|
+
}
|
|
96
|
+
/** The fields where this version differs from the form now. */
|
|
97
|
+
const differences = computed(() => {
|
|
98
|
+
const data = selected.value?.data ?? {}
|
|
99
|
+
return Object.keys(data)
|
|
100
|
+
.filter((k) => !k.endsWith('__media') && byKey.value.has(k) && cmsFormJson(data[k]) !== cmsFormJson(props.current[k]))
|
|
101
|
+
.map((k) => {
|
|
102
|
+
const f = byKey.value.get(k)
|
|
103
|
+
const then = textOf(f, data[k])
|
|
104
|
+
const now = textOf(f, props.current[k])
|
|
105
|
+
const textual = ['text', 'slug', 'richtext', 'number', 'select'].includes(f?.type)
|
|
106
|
+
const refs = isRefField(f) ? { then: refParts(f, data[k]), now: refParts(f, props.current[k]) } : null
|
|
107
|
+
return { key: k, label: fieldLabel(f), then, now, refs, parts: textual ? wordDiff(now, then) : null }
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
const actionLabel = (r: any) => {
|
|
112
|
+
const names = (r.changed ?? []).map((k: string) => fieldLabel(byKey.value.get(k))).filter(Boolean)
|
|
113
|
+
switch (r.action) {
|
|
114
|
+
case 'entry.created': return t('revisions.created')
|
|
115
|
+
case 'entry.published': return t('revisions.published')
|
|
116
|
+
case 'entry.unpublished': return t('revisions.unpublished')
|
|
117
|
+
default: return names.length ? t('revisions.edited', { fields: names.slice(0, 3).join(', ') + (names.length > 3 ? '…' : '') }) : t('revisions.saved')
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function restore() {
|
|
122
|
+
if (!selected.value) return
|
|
123
|
+
emit('restore', selected.value.data)
|
|
124
|
+
open.value = false
|
|
125
|
+
}
|
|
126
|
+
</script>
|
|
127
|
+
|
|
128
|
+
<template>
|
|
129
|
+
<USlideover v-model:open="open" :title="t('revisions.title')" :description="t('revisions.description')" :ui="{ content: 'max-w-4xl' }">
|
|
130
|
+
<template #body>
|
|
131
|
+
<div class="grid gap-6 md:grid-cols-[minmax(0,1fr)_16rem]">
|
|
132
|
+
<section class="min-w-0 space-y-4" :aria-label="t('revisions.compare')">
|
|
133
|
+
<p v-if="!selected && status !== 'pending'" class="text-sm text-muted">{{ t('revisions.empty') }}</p>
|
|
134
|
+
<template v-else-if="selected">
|
|
135
|
+
<p class="text-sm text-muted">
|
|
136
|
+
{{ t('revisions.versionOf', { date: formatDate(selected.createdAt) }) }}
|
|
137
|
+
</p>
|
|
138
|
+
<p v-if="!differences.length" class="text-sm text-muted">{{ t('revisions.same') }}</p>
|
|
139
|
+
<!-- what the marks in the text mean (they are the only thing that tells added from removed) -->
|
|
140
|
+
<p v-else-if="differences.some((d: any) => d.parts)" class="text-xs text-muted">
|
|
141
|
+
<ins class="no-underline rounded-sm bg-success/15 px-0.5 text-highlighted">{{ t('revisions.legendAddedMark') }}</ins> {{ t('revisions.legendAdded') }}
|
|
142
|
+
· <del class="rounded-sm bg-error/10 px-0.5 text-muted">{{ t('revisions.legendRemovedMark') }}</del> {{ t('revisions.legendRemoved') }}
|
|
143
|
+
</p>
|
|
144
|
+
<div v-for="d in differences" :key="d.key" class="rounded-lg border border-default p-3 space-y-1.5">
|
|
145
|
+
<p class="text-xs font-medium text-muted">{{ d.label }}</p>
|
|
146
|
+
<p v-if="d.parts" class="text-sm whitespace-pre-wrap leading-relaxed">
|
|
147
|
+
<template v-for="(p, i) in d.parts" :key="i">
|
|
148
|
+
<span v-if="p.kind === 'same'">{{ p.text }}</span>
|
|
149
|
+
<ins v-else-if="p.kind === 'added'" class="no-underline rounded-sm bg-success/15 text-highlighted">{{ p.text }}</ins>
|
|
150
|
+
<del v-else class="rounded-sm bg-error/10 text-muted">{{ p.text }}</del>
|
|
151
|
+
</template>
|
|
152
|
+
</p>
|
|
153
|
+
<div v-else-if="d.refs" class="grid grid-cols-2 gap-3 text-sm">
|
|
154
|
+
<div v-for="side in (['then', 'now'] as const)" :key="side" class="min-w-0">
|
|
155
|
+
<span class="block text-xs text-dimmed">{{ t(`revisions.${side}`) }}</span>
|
|
156
|
+
<span v-if="!d.refs[side].length">—</span>
|
|
157
|
+
<ul v-else class="space-y-1.5">
|
|
158
|
+
<li v-for="(r, i) in d.refs[side]" :key="i" class="flex items-center gap-2 min-w-0">
|
|
159
|
+
<img v-if="r.thumb" :src="r.thumb" alt="" class="size-9 shrink-0 rounded object-cover border border-default" loading="lazy">
|
|
160
|
+
<span class="truncate">{{ r.label }}</span>
|
|
161
|
+
</li>
|
|
162
|
+
</ul>
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
<div v-else class="grid grid-cols-2 gap-3 text-sm">
|
|
166
|
+
<div><span class="block text-xs text-dimmed">{{ t('revisions.then') }}</span>{{ d.then || '—' }}</div>
|
|
167
|
+
<div><span class="block text-xs text-dimmed">{{ t('revisions.now') }}</span>{{ d.now || '—' }}</div>
|
|
168
|
+
</div>
|
|
169
|
+
</div>
|
|
170
|
+
</template>
|
|
171
|
+
</section>
|
|
172
|
+
|
|
173
|
+
<nav class="md:border-l md:border-default md:pl-4" :aria-label="t('revisions.list')">
|
|
174
|
+
<ol class="space-y-1">
|
|
175
|
+
<li v-for="r in revisions" :key="r.id">
|
|
176
|
+
<button
|
|
177
|
+
type="button" class="w-full rounded-md px-2 py-1.5 text-left hover:bg-elevated/60"
|
|
178
|
+
:class="r.id === selectedId ? 'bg-elevated' : ''" :aria-current="r.id === selectedId ? 'true' : undefined" @click="pick(r.id)"
|
|
179
|
+
>
|
|
180
|
+
<span class="block text-sm text-highlighted">{{ formatRelative(r.createdAt) }}</span>
|
|
181
|
+
<span class="block truncate text-xs text-muted">{{ r.byName || t('revisions.someone') }} · {{ actionLabel(r) }}</span>
|
|
182
|
+
</button>
|
|
183
|
+
</li>
|
|
184
|
+
</ol>
|
|
185
|
+
</nav>
|
|
186
|
+
</div>
|
|
187
|
+
</template>
|
|
188
|
+
<template #footer>
|
|
189
|
+
<div class="flex w-full items-center justify-end gap-2">
|
|
190
|
+
<UButton color="neutral" variant="ghost" @click="open = false">{{ t('common.close') }}</UButton>
|
|
191
|
+
<UButton :disabled="!selected || !differences.length" :loading="loading" icon="i-lucide-history" @click="restore">{{ t('revisions.restore') }}</UButton>
|
|
192
|
+
</div>
|
|
193
|
+
</template>
|
|
194
|
+
</USlideover>
|
|
195
|
+
</template>
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { Ref } from 'vue'
|
|
3
|
+
import { EditorContent, useEditor } from '@tiptap/vue-3'
|
|
4
|
+
import Collaboration from '@tiptap/extension-collaboration'
|
|
5
|
+
import CollaborationCaret from '@tiptap/extension-collaboration-caret'
|
|
6
|
+
import { ySyncPluginKey } from '@tiptap/y-tiptap'
|
|
7
|
+
import { richTextExtensions } from '../../shared/richtext-editor'
|
|
8
|
+
import { isLinkRef } from '../../src/linkref'
|
|
9
|
+
import { cleanPastedHtml } from '../../shared/richtext-paste'
|
|
10
|
+
import type { CmsCollab } from '../composables/useCmsCollab'
|
|
11
|
+
|
|
12
|
+
// The rich-text editor itself (TipTap). The model IS the ProseMirror/TipTap JSON doc
|
|
13
|
+
// stored in the jsonb column — no conversion. Used by CmsFieldRichText, which picks
|
|
14
|
+
// the mode:
|
|
15
|
+
// - alone: the editor holds the text, and the form's value fills it;
|
|
16
|
+
// - shared (`collab` given): the text lives in the shared Yjs document that
|
|
17
|
+
// everyone types into, with their cursors; the form's value only follows it.
|
|
18
|
+
const props = defineProps<{
|
|
19
|
+
collab?: { doc: any; provider: any; field: string; user: { name: string; color: string }; readOnly: boolean } | null
|
|
20
|
+
/** The field's name, for screen readers (the text area is a labelled textbox). */
|
|
21
|
+
label?: string
|
|
22
|
+
/** Or the id of the element that shows it. */
|
|
23
|
+
labelledby?: string
|
|
24
|
+
}>()
|
|
25
|
+
const model = defineModel<any>()
|
|
26
|
+
const libraryOpen = ref(false)
|
|
27
|
+
const { t } = useCmsI18n()
|
|
28
|
+
const toast = useToast()
|
|
29
|
+
const form = inject<{ quiet?: (fn: () => void) => void } | null>('cmsForm', null)
|
|
30
|
+
const shared = props.collab ? inject<CmsCollab | null>('cmsCollab', null) : null
|
|
31
|
+
// A page that opens read-only (the person may not save here) says so; typing is off.
|
|
32
|
+
const readOnly = inject<Ref<boolean> | null>('cmsReadOnly', null)
|
|
33
|
+
const canType = () => !props.collab?.readOnly && !readOnly?.value
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Is this the same text as that? The editor fills in attribute defaults and adds an
|
|
37
|
+
* empty paragraph after a last heading or list; text written elsewhere (an API client,
|
|
38
|
+
* an older version) lacks both. That alone is no change — the form must not turn
|
|
39
|
+
* "unsaved" just because the editor looked at the text.
|
|
40
|
+
*/
|
|
41
|
+
function sameDoc(ed: { schema: any }, a: unknown, b: unknown): boolean {
|
|
42
|
+
const canon = (v: any) => {
|
|
43
|
+
if (!v || typeof v !== 'object') return v
|
|
44
|
+
try {
|
|
45
|
+
return ed.schema.nodeFromJSON(v).toJSON()
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return v
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return sameRichText(canon(a), canon(b))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const editor = useEditor({
|
|
55
|
+
// Shared: the content comes from the shared document, never from here.
|
|
56
|
+
content: props.collab ? undefined : (model.value || { type: 'doc', content: [] }),
|
|
57
|
+
editable: canType(),
|
|
58
|
+
editorProps: {
|
|
59
|
+
attributes: {
|
|
60
|
+
role: 'textbox', 'aria-multiline': 'true',
|
|
61
|
+
...(props.labelledby ? { 'aria-labelledby': props.labelledby } : props.label ? { 'aria-label': props.label } : {}),
|
|
62
|
+
},
|
|
63
|
+
// Word's lists, tables and pictures on its owner's disk: made into what was meant
|
|
64
|
+
// (real lists, a line per table row), pictures that cannot be shown left out — and said.
|
|
65
|
+
transformPastedHTML: (html: string) => {
|
|
66
|
+
const pasted = cleanPastedHtml(html)
|
|
67
|
+
if (pasted.droppedImages) {
|
|
68
|
+
toast.add({ title: t('fields.pasteImagesDropped'), description: t('fields.pasteImagesDroppedBody'), icon: 'i-lucide-image-off', color: 'warning' })
|
|
69
|
+
}
|
|
70
|
+
return pasted.html
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
extensions: [
|
|
74
|
+
...richTextExtensions({ collaborative: !!props.collab }),
|
|
75
|
+
...(props.collab
|
|
76
|
+
? [
|
|
77
|
+
Collaboration.configure({ document: props.collab.doc, field: props.collab.field }),
|
|
78
|
+
CollaborationCaret.configure({ provider: props.collab.provider, user: props.collab.user }),
|
|
79
|
+
]
|
|
80
|
+
: []),
|
|
81
|
+
],
|
|
82
|
+
onUpdate: ({ editor, transaction }) => {
|
|
83
|
+
const next = editor.getJSON()
|
|
84
|
+
// Only real changes reach the form (an identical value would still mark it
|
|
85
|
+
// dirty; empty text stays "no value", so a translation keeps falling back).
|
|
86
|
+
if (sameDoc(editor, next, model.value)) return
|
|
87
|
+
const value = isEmptyRichText(next) && (model.value === null || model.value === undefined) ? model.value : next
|
|
88
|
+
// Someone else typing: the form follows, but it is not unsaved work of this tab.
|
|
89
|
+
const remote = !!(transaction.getMeta(ySyncPluginKey) as any)?.isChangeOrigin
|
|
90
|
+
if (remote && form?.quiet) form.quiet(() => { model.value = value })
|
|
91
|
+
else model.value = value
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
watch(() => readOnly?.value, () => editor.value?.setEditable(canType()))
|
|
96
|
+
|
|
97
|
+
watch(model, (val) => {
|
|
98
|
+
const ed = editor.value
|
|
99
|
+
if (!ed) return
|
|
100
|
+
if (props.collab) {
|
|
101
|
+
// The shared document is the truth: when the form loads another value (a newer
|
|
102
|
+
// version, a merge), the form takes the shared text back instead of overwriting
|
|
103
|
+
// what everyone is typing. Replacing it is an explicit choice (collab.set).
|
|
104
|
+
if (!sameDoc(ed, val, ed.getJSON())) model.value = ed.getJSON()
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
const next = val || { type: 'doc', content: [] }
|
|
108
|
+
if (!sameDoc(ed, ed.getJSON(), next)) ed.commands.setContent(next, { emitUpdate: false })
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
// Shared: once the editor shows the shared text, the form takes it (it may hold
|
|
112
|
+
// changes not saved yet, typed by anyone).
|
|
113
|
+
if (props.collab) {
|
|
114
|
+
const key = props.collab.field
|
|
115
|
+
watch(editor, (ed) => {
|
|
116
|
+
if (!ed) return
|
|
117
|
+
const v = ed.getJSON()
|
|
118
|
+
if (!sameDoc(ed, v, model.value)) model.value = v
|
|
119
|
+
// This field is now shared on the page: merges leave it to the shared text, and
|
|
120
|
+
// an explicit load or copy goes through here, to everyone.
|
|
121
|
+
if (shared) {
|
|
122
|
+
shared.setters.set(key, (value) => ed.commands.setContent(value || { type: 'doc', content: [] }))
|
|
123
|
+
shared.mounted.value = new Set([...shared.mounted.value, key])
|
|
124
|
+
}
|
|
125
|
+
}, { once: true })
|
|
126
|
+
onBeforeUnmount(() => {
|
|
127
|
+
if (!shared) return
|
|
128
|
+
shared.setters.delete(key)
|
|
129
|
+
const next = new Set(shared.mounted.value)
|
|
130
|
+
next.delete(key)
|
|
131
|
+
shared.mounted.value = next
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
onBeforeUnmount(() => editor.value?.destroy())
|
|
136
|
+
|
|
137
|
+
// Links: an in-app popover (a page of the site, or an address), never the browser's
|
|
138
|
+
// prompt. With no text selected, the picked page's title becomes the link text.
|
|
139
|
+
const linkOpen = ref(false)
|
|
140
|
+
const linkHref = ref<string | null>(null)
|
|
141
|
+
watch(linkOpen, (v) => {
|
|
142
|
+
if (v) linkHref.value = (editor.value?.getAttributes('link').href as string | undefined) ?? null
|
|
143
|
+
})
|
|
144
|
+
function applyLink(href: string, title?: string) {
|
|
145
|
+
const ed = editor.value
|
|
146
|
+
linkOpen.value = false
|
|
147
|
+
if (!ed) return
|
|
148
|
+
const { empty } = ed.state.selection
|
|
149
|
+
if (empty && !ed.isActive('link')) {
|
|
150
|
+
ed.chain().focus().insertContent({ type: 'text', text: title || href, marks: [{ type: 'link', attrs: { href } }] }).run()
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
ed.chain().focus().extendMarkRange('link').setLink({ href }).run()
|
|
154
|
+
}
|
|
155
|
+
function removeLink() {
|
|
156
|
+
linkOpen.value = false
|
|
157
|
+
editor.value?.chain().focus().extendMarkRange('link').unsetLink().run()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Images go in after the selection (never over the selected text), and carry a
|
|
161
|
+
// description: the file's own, or one the editor writes now.
|
|
162
|
+
const altOpen = ref(false)
|
|
163
|
+
const altText = ref('')
|
|
164
|
+
let pending: { kind: 'insert'; media: any } | { kind: 'edit' } | null = null
|
|
165
|
+
const pendingIsInsert = ref(false)
|
|
166
|
+
function onImageSelect(m: any) {
|
|
167
|
+
const alt = typeof m.alt === 'string' ? m.alt.trim() : ''
|
|
168
|
+
if (alt) return insertImage(m, alt)
|
|
169
|
+
pending = { kind: 'insert', media: m }
|
|
170
|
+
pendingIsInsert.value = true
|
|
171
|
+
altText.value = ''
|
|
172
|
+
altOpen.value = true
|
|
173
|
+
}
|
|
174
|
+
function insertImage(m: any, alt: string) {
|
|
175
|
+
const ed = editor.value
|
|
176
|
+
if (!ed) return
|
|
177
|
+
ed.chain().focus().setTextSelection(ed.state.selection.to).setImage({ src: m.url, alt, mediaId: m.id } as any).run()
|
|
178
|
+
}
|
|
179
|
+
// Closing the question (Esc, ×) still inserts the picked image, without a description.
|
|
180
|
+
watch(altOpen, (v) => { if (!v && pending) confirmAlt(true) })
|
|
181
|
+
function editAlt() {
|
|
182
|
+
pending = { kind: 'edit' }
|
|
183
|
+
pendingIsInsert.value = false
|
|
184
|
+
altText.value = String(editor.value?.getAttributes('image').alt ?? '')
|
|
185
|
+
altOpen.value = true
|
|
186
|
+
}
|
|
187
|
+
function confirmAlt(skip = false) {
|
|
188
|
+
const alt = skip ? '' : altText.value.trim()
|
|
189
|
+
const p = pending
|
|
190
|
+
pending = null
|
|
191
|
+
altOpen.value = false
|
|
192
|
+
if (!p) return
|
|
193
|
+
if (p.kind === 'insert') insertImage(p.media, alt)
|
|
194
|
+
else editor.value?.chain().focus().updateAttributes('image', { alt }).run()
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
type Tool = { icon: string, label: string, run: () => void, active: () => boolean }
|
|
198
|
+
const tools = computed<Tool[]>(() => {
|
|
199
|
+
const ed = editor.value
|
|
200
|
+
if (!ed) return []
|
|
201
|
+
const chain = () => ed.chain().focus()
|
|
202
|
+
return [
|
|
203
|
+
{ icon: 'i-lucide-bold', label: t('fields.toolbar.bold'), run: () => chain().toggleBold().run(), active: () => ed.isActive('bold') },
|
|
204
|
+
{ icon: 'i-lucide-italic', label: t('fields.toolbar.italic'), run: () => chain().toggleItalic().run(), active: () => ed.isActive('italic') },
|
|
205
|
+
{ icon: 'i-lucide-strikethrough', label: t('fields.toolbar.strike'), run: () => chain().toggleStrike().run(), active: () => ed.isActive('strike') },
|
|
206
|
+
{ icon: 'i-lucide-heading-2', label: t('fields.toolbar.h2'), run: () => chain().toggleHeading({ level: 2 }).run(), active: () => ed.isActive('heading', { level: 2 }) },
|
|
207
|
+
{ icon: 'i-lucide-heading-3', label: t('fields.toolbar.h3'), run: () => chain().toggleHeading({ level: 3 }).run(), active: () => ed.isActive('heading', { level: 3 }) },
|
|
208
|
+
{ icon: 'i-lucide-list', label: t('fields.toolbar.bulletList'), run: () => chain().toggleBulletList().run(), active: () => ed.isActive('bulletList') },
|
|
209
|
+
{ icon: 'i-lucide-list-ordered', label: t('fields.toolbar.orderedList'), run: () => chain().toggleOrderedList().run(), active: () => ed.isActive('orderedList') },
|
|
210
|
+
{ icon: 'i-lucide-quote', label: t('fields.toolbar.quote'), run: () => chain().toggleBlockquote().run(), active: () => ed.isActive('blockquote') },
|
|
211
|
+
{ icon: 'i-lucide-code', label: t('fields.toolbar.code'), run: () => chain().toggleCode().run(), active: () => ed.isActive('code') },
|
|
212
|
+
]
|
|
213
|
+
})
|
|
214
|
+
</script>
|
|
215
|
+
|
|
216
|
+
<template>
|
|
217
|
+
<div class="cms-rte w-full overflow-hidden rounded-lg border border-default bg-default">
|
|
218
|
+
<CmsMediaLibrary v-model:open="libraryOpen" accept="image/*" @select="onImageSelect" />
|
|
219
|
+
<UModal v-model:open="altOpen" :title="t('link.imageAlt')" :description="t('link.imageAltHint')">
|
|
220
|
+
<template #body>
|
|
221
|
+
<form class="space-y-4" @submit.prevent="confirmAlt()">
|
|
222
|
+
<UInput v-model="altText" :placeholder="t('link.imageAltPlaceholder')" class="w-full" autofocus :aria-label="t('link.imageAlt')" />
|
|
223
|
+
<div class="flex justify-end gap-2">
|
|
224
|
+
<UButton color="neutral" variant="ghost" @click="confirmAlt(true)">{{ t('link.skip') }}</UButton>
|
|
225
|
+
<UButton type="submit">{{ pendingIsInsert ? t('link.insert') : t('link.save') }}</UButton>
|
|
226
|
+
</div>
|
|
227
|
+
</form>
|
|
228
|
+
</template>
|
|
229
|
+
</UModal>
|
|
230
|
+
<ClientOnly>
|
|
231
|
+
<div v-if="editor && canType()" class="cms-rte__toolbar flex flex-wrap items-center gap-0.5 border-b border-default bg-elevated/30 p-1">
|
|
232
|
+
<UButton
|
|
233
|
+
v-for="tool in tools" :key="tool.icon"
|
|
234
|
+
:icon="tool.icon" size="xs" variant="ghost"
|
|
235
|
+
:color="tool.active() ? 'primary' : 'neutral'"
|
|
236
|
+
:aria-label="tool.label" :aria-pressed="tool.active()" @click="tool.run()"
|
|
237
|
+
/>
|
|
238
|
+
<UPopover v-model:open="linkOpen" :content="{ align: 'start' }">
|
|
239
|
+
<UButton
|
|
240
|
+
icon="i-lucide-link" size="xs" variant="ghost" :color="editor.isActive('link') ? 'primary' : 'neutral'"
|
|
241
|
+
:aria-label="t('fields.toolbar.link')" :aria-pressed="editor.isActive('link')"
|
|
242
|
+
/>
|
|
243
|
+
<template #content>
|
|
244
|
+
<div v-if="linkHref" class="flex items-center gap-2 border-b border-default px-3 py-2">
|
|
245
|
+
<CmsLinkTarget v-if="isLinkRef(linkHref)" :value="linkHref" class="flex-1" />
|
|
246
|
+
<span v-else class="min-w-0 flex-1 truncate font-mono text-xs text-muted">{{ linkHref }}</span>
|
|
247
|
+
<UButton size="xs" color="neutral" variant="ghost" icon="i-lucide-unlink" @click="removeLink">{{ t('link.remove') }}</UButton>
|
|
248
|
+
</div>
|
|
249
|
+
<CmsLinkPicker :initial="linkHref" @pick="applyLink" />
|
|
250
|
+
</template>
|
|
251
|
+
</UPopover>
|
|
252
|
+
<UButton
|
|
253
|
+
icon="i-lucide-image" size="xs" variant="ghost" color="neutral"
|
|
254
|
+
:aria-label="t('fields.toolbar.image')" @click="libraryOpen = true"
|
|
255
|
+
/>
|
|
256
|
+
<UButton
|
|
257
|
+
v-if="editor.isActive('image')" icon="i-lucide-text-quote" size="xs" variant="ghost" color="neutral"
|
|
258
|
+
:aria-label="t('fields.toolbar.imageAlt')" @click="editAlt"
|
|
259
|
+
>{{ t('fields.toolbar.imageAlt') }}</UButton>
|
|
260
|
+
<div class="ml-auto flex gap-0.5">
|
|
261
|
+
<UButton icon="i-lucide-undo-2" size="xs" variant="ghost" color="neutral" :aria-label="t('fields.toolbar.undo')" @click="editor.chain().focus().undo().run()" />
|
|
262
|
+
<UButton icon="i-lucide-redo-2" size="xs" variant="ghost" color="neutral" :aria-label="t('fields.toolbar.redo')" @click="editor.chain().focus().redo().run()" />
|
|
263
|
+
</div>
|
|
264
|
+
</div>
|
|
265
|
+
<EditorContent :editor="editor" class="cms-prose" />
|
|
266
|
+
<template #fallback>
|
|
267
|
+
<div class="min-h-32 px-3 py-2 text-sm text-muted">{{ t('fields.loadingEditor') }}</div>
|
|
268
|
+
</template>
|
|
269
|
+
</ClientOnly>
|
|
270
|
+
</div>
|
|
271
|
+
</template>
|
|
272
|
+
|
|
273
|
+
<style scoped>
|
|
274
|
+
:deep(.ProseMirror) { min-height: 10rem; padding: 0.75rem 1rem; outline: none; }
|
|
275
|
+
:deep(.ProseMirror > * + *) { margin-top: 0.5rem; }
|
|
276
|
+
:deep(.ProseMirror h2) { font-size: 1.25rem; font-weight: 600; line-height: 1.3; letter-spacing: -0.01em; margin-top: 1rem; }
|
|
277
|
+
:deep(.ProseMirror h3) { font-size: 1.0625rem; font-weight: 600; line-height: 1.35; margin-top: 0.75rem; }
|
|
278
|
+
:deep(.ProseMirror ul) { list-style: disc; padding-left: 1.5rem; }
|
|
279
|
+
:deep(.ProseMirror ol) { list-style: decimal; padding-left: 1.5rem; }
|
|
280
|
+
:deep(.ProseMirror blockquote) { border-left: 3px solid currentColor; opacity: 0.85; padding-left: 0.75rem; }
|
|
281
|
+
:deep(.ProseMirror code) { font-family: ui-monospace, monospace; background: rgb(127 127 127 / 0.15); padding: 0.1em 0.3em; border-radius: 0.25rem; font-size: 0.9em; }
|
|
282
|
+
:deep(.ProseMirror pre) { background: rgb(127 127 127 / 0.12); padding: 0.5rem 0.75rem; border-radius: 0.375rem; overflow-x: auto; }
|
|
283
|
+
:deep(.ProseMirror pre code) { background: none; padding: 0; }
|
|
284
|
+
:deep(.ProseMirror a) { color: var(--ui-primary, currentColor); text-decoration: underline; }
|
|
285
|
+
:deep(.ProseMirror img) { max-width: 100%; height: auto; border-radius: 0.375rem; }
|
|
286
|
+
:deep(.ProseMirror img.ProseMirror-selectednode) { outline: 2px solid var(--ui-primary, currentColor); }
|
|
287
|
+
/* Other people's cursors in shared text: a thin line in their colour, their name above. */
|
|
288
|
+
:deep(.collaboration-carets__caret) { position: relative; margin-left: -1px; margin-right: -1px; border-left: 1px solid; border-right: 1px solid; word-break: normal; pointer-events: none; }
|
|
289
|
+
:deep(.collaboration-carets__label) { position: absolute; top: -1.4em; left: -1px; padding: 0.05rem 0.3rem; border-radius: 0.25rem 0.25rem 0.25rem 0; font-size: 0.6875rem; font-weight: 500; line-height: 1.3; color: #fff; white-space: nowrap; user-select: none; }
|
|
290
|
+
</style>
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// The admin's search (⌘K, or the Search button in the sidebar): entries of every
|
|
3
|
+
// collection this person may read, found by any word in them (title, text, blocks,
|
|
4
|
+
// any language), and the admin's own places (collections, settings, media).
|
|
5
|
+
import type { CommandPaletteGroup, CommandPaletteItem } from '@nuxt/ui'
|
|
6
|
+
|
|
7
|
+
const props = defineProps<{ graph: any[]; places: CommandPaletteItem[] }>()
|
|
8
|
+
const { t, entitySingular } = useCmsI18n()
|
|
9
|
+
|
|
10
|
+
interface Hit { entity: string; id: string; title: string; excerpt: string; status: string | null }
|
|
11
|
+
|
|
12
|
+
const term = ref('')
|
|
13
|
+
const hits = ref<Hit[]>([])
|
|
14
|
+
const searched = ref('')
|
|
15
|
+
const loading = ref(false)
|
|
16
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
17
|
+
let seq = 0
|
|
18
|
+
|
|
19
|
+
// Ask the server once typing settles; a slower, older answer never replaces a newer one.
|
|
20
|
+
watch(term, (value) => {
|
|
21
|
+
clearTimeout(timer)
|
|
22
|
+
const q = value.trim()
|
|
23
|
+
if (q.length < 2) {
|
|
24
|
+
seq++
|
|
25
|
+
hits.value = []
|
|
26
|
+
searched.value = ''
|
|
27
|
+
loading.value = false
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
loading.value = true
|
|
31
|
+
timer = setTimeout(async () => {
|
|
32
|
+
const mine = ++seq
|
|
33
|
+
try {
|
|
34
|
+
const res = await $fetch<{ items: Hit[] }>('/api/cms/_search', { query: { q } })
|
|
35
|
+
if (mine !== seq) return
|
|
36
|
+
hits.value = res.items
|
|
37
|
+
searched.value = q
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
if (mine === seq) hits.value = []
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
if (mine === seq) loading.value = false
|
|
44
|
+
}
|
|
45
|
+
}, 180)
|
|
46
|
+
})
|
|
47
|
+
onBeforeUnmount(() => clearTimeout(timer))
|
|
48
|
+
|
|
49
|
+
const byName = computed(() => new Map(props.graph.map((e) => [e.name, e])))
|
|
50
|
+
const statusLabel = (s: string | null) => (s === 'draft' ? t('editor.draft') : s === 'scheduled' ? t('editor.scheduled') : '')
|
|
51
|
+
|
|
52
|
+
const groups = computed<CommandPaletteGroup<CommandPaletteItem>[]>(() => {
|
|
53
|
+
const out: CommandPaletteGroup<CommandPaletteItem>[] = []
|
|
54
|
+
if (hits.value.length) {
|
|
55
|
+
out.push({
|
|
56
|
+
id: 'entries',
|
|
57
|
+
label: t('search.entries'),
|
|
58
|
+
// Already matched (and ranked) by the server: shown as they come.
|
|
59
|
+
ignoreFilter: true,
|
|
60
|
+
items: hits.value.map((h, i) => {
|
|
61
|
+
const e = byName.value.get(h.entity)
|
|
62
|
+
// A snippet that only repeats the title, or one an earlier result already showed, says nothing new.
|
|
63
|
+
const excerpt = h.excerpt && h.excerpt.trim() !== h.title.trim() && !hits.value.slice(0, i).some((o) => o.excerpt === h.excerpt) ? h.excerpt : ''
|
|
64
|
+
const kind = e ? entitySingular(e) : h.entity
|
|
65
|
+
return {
|
|
66
|
+
id: `${h.entity}:${h.id}`,
|
|
67
|
+
label: h.title || t('search.untitled'),
|
|
68
|
+
description: excerpt || undefined,
|
|
69
|
+
suffix: [kind, statusLabel(h.status)].filter(Boolean).join(' · '),
|
|
70
|
+
icon: e?.icon ?? 'i-lucide-file',
|
|
71
|
+
to: `/admin/${h.entity}/${h.id}`,
|
|
72
|
+
}
|
|
73
|
+
}),
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
out.push({ id: 'places', label: t('search.places'), items: props.places })
|
|
77
|
+
return out
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const empty = computed(() => (loading.value || term.value.trim().length < 2 ? t('search.typeMore') : t('search.nothing', { query: searched.value || term.value.trim() })))
|
|
81
|
+
</script>
|
|
82
|
+
|
|
83
|
+
<template>
|
|
84
|
+
<UDashboardSearch
|
|
85
|
+
v-model:search-term="term"
|
|
86
|
+
:groups="groups"
|
|
87
|
+
:loading="loading"
|
|
88
|
+
:color-mode="false"
|
|
89
|
+
:title="t('search.title')"
|
|
90
|
+
:description="t('search.description')"
|
|
91
|
+
:placeholder="t('search.placeholder')"
|
|
92
|
+
:fuse="{ resultLimit: 20, fuseOptions: { keys: ['label'] } }"
|
|
93
|
+
:ui="{ itemDescription: 'line-clamp-2 whitespace-normal' }"
|
|
94
|
+
>
|
|
95
|
+
<template #empty>
|
|
96
|
+
<p class="py-6 text-center text-sm text-muted">{{ empty }}</p>
|
|
97
|
+
</template>
|
|
98
|
+
</UDashboardSearch>
|
|
99
|
+
</template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A titled card on the page background — the unit that groups related fields or
|
|
3
|
+
// lists. One frame per group; sections are never nested.
|
|
4
|
+
defineProps<{ title?: string; description?: string; flush?: boolean }>()
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<template>
|
|
8
|
+
<section class="cms-card overflow-hidden">
|
|
9
|
+
<header v-if="title || $slots.actions" class="flex items-start justify-between gap-4 px-4 pt-3" :class="flush ? 'pb-3 border-b border-default' : ''">
|
|
10
|
+
<div class="min-w-0">
|
|
11
|
+
<h2 v-if="title" class="text-sm font-semibold text-highlighted">{{ title }}</h2>
|
|
12
|
+
<p v-if="description" class="mt-0.5 text-sm text-muted">{{ description }}</p>
|
|
13
|
+
</div>
|
|
14
|
+
<slot name="actions" />
|
|
15
|
+
</header>
|
|
16
|
+
<div :class="flush ? '' : 'p-4'">
|
|
17
|
+
<slot />
|
|
18
|
+
</div>
|
|
19
|
+
</section>
|
|
20
|
+
</template>
|