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,353 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { DropdownMenuItem } from '@nuxt/ui'
|
|
3
|
+
import { isLinkRef } from '../../src/linkref'
|
|
4
|
+
|
|
5
|
+
// Page builder: an ordered list of typed blocks. Each block is a collapsible card —
|
|
6
|
+
// its type, a one-line summary when collapsed, and a marker when something inside
|
|
7
|
+
// needs attention. Insert between blocks or at the end through a searchable picker;
|
|
8
|
+
// move, duplicate and remove from the block's "…" menu (keyboard- and touch-friendly),
|
|
9
|
+
// or drag a block by its handle. A removed block can be brought back from the toast.
|
|
10
|
+
// `f.list()` uses the same editor with one item type: items read as their own text
|
|
11
|
+
// ("Jana Nováková · Coach"), not as "Item", and a `sub` switch indents an item
|
|
12
|
+
// under the one above (menus). A block can hold a list (FAQ questions, feature
|
|
13
|
+
// cards): the same editor again, inside the open block, under its full path
|
|
14
|
+
// ("sections.2.items"), so a problem in item 3 marks both the item and the block.
|
|
15
|
+
const props = defineProps<{ field: any; entity: string }>()
|
|
16
|
+
// Text inside blocks is edited on its own (not shared), even on a shared entry.
|
|
17
|
+
provide('cmsCollab', null)
|
|
18
|
+
const model = defineModel<any[] | null>()
|
|
19
|
+
const { t, tl } = useCmsI18n()
|
|
20
|
+
const toast = useToast()
|
|
21
|
+
const confirm = useCmsConfirm()
|
|
22
|
+
const form = inject<{ issues?: Record<string, string> } | null>('cmsForm', null)
|
|
23
|
+
const list = computed<{ max: number | null; itemLabel: any } | null>(() => props.field.meta?.list ?? null)
|
|
24
|
+
const full = computed(() => !!list.value?.max && blocks.value.length >= list.value.max)
|
|
25
|
+
|
|
26
|
+
const defs = computed<Record<string, any>>(() => props.field.meta?.blocks ?? {})
|
|
27
|
+
const blocks = computed<any[]>(() => (Array.isArray(model.value) ? model.value : []))
|
|
28
|
+
const open = reactive<Record<string, boolean>>({})
|
|
29
|
+
// A link to a page is stored as a reference (`cms:page/<id>`): the collapsed row says which
|
|
30
|
+
// page it is (title and address), asked for in one batch like the expanded row does.
|
|
31
|
+
const { request: requestTargets, find: findTarget } = useCmsLinkTargets()
|
|
32
|
+
watchEffect(() => {
|
|
33
|
+
const refs: string[] = []
|
|
34
|
+
for (const b of blocks.value) for (const v of Object.values(b ?? {})) if (typeof v === 'string' && isLinkRef(v)) refs.push(v)
|
|
35
|
+
if (refs.length) requestTargets(refs)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const newId = () => (globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`).replace(/-/g, '').slice(0, 12)
|
|
39
|
+
|
|
40
|
+
function blank(type: string) {
|
|
41
|
+
const def = defs.value[type]
|
|
42
|
+
const b: Record<string, any> = { id: newId(), type }
|
|
43
|
+
for (const f of def?.fields ?? []) {
|
|
44
|
+
b[f.key] = f.type === 'boolean' ? false : f.type === 'richtext' ? { type: 'doc', content: [] } : null
|
|
45
|
+
}
|
|
46
|
+
return b
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function update(next: any[]) {
|
|
50
|
+
model.value = next
|
|
51
|
+
}
|
|
52
|
+
function insertAt(index: number, type: string) {
|
|
53
|
+
const b = blank(type)
|
|
54
|
+
const next = [...blocks.value]
|
|
55
|
+
next.splice(index, 0, b)
|
|
56
|
+
update(next)
|
|
57
|
+
// Only the new one opens: a page with many blocks stays readable.
|
|
58
|
+
for (const k of Object.keys(open)) open[k] = false
|
|
59
|
+
open[b.id] = true
|
|
60
|
+
pickerOpen.value = false
|
|
61
|
+
}
|
|
62
|
+
function move(index: number, by: number) {
|
|
63
|
+
const next = [...blocks.value]
|
|
64
|
+
const [b] = next.splice(index, 1)
|
|
65
|
+
next.splice(index + by, 0, b)
|
|
66
|
+
update(next)
|
|
67
|
+
}
|
|
68
|
+
function duplicate(index: number) {
|
|
69
|
+
const copy = { ...structuredClone(toRaw(blocks.value[index])), id: newId() }
|
|
70
|
+
const next = [...blocks.value]
|
|
71
|
+
next.splice(index + 1, 0, copy)
|
|
72
|
+
update(next)
|
|
73
|
+
open[copy.id] = true
|
|
74
|
+
}
|
|
75
|
+
function remove(index: number) {
|
|
76
|
+
const next = [...blocks.value]
|
|
77
|
+
const [gone] = next.splice(index, 1)
|
|
78
|
+
update(next)
|
|
79
|
+
if (!gone) return
|
|
80
|
+
toast.add({
|
|
81
|
+
title: t('blocks.removed', { label: shortName(gone, index) }),
|
|
82
|
+
icon: 'i-lucide-trash-2',
|
|
83
|
+
actions: [{ label: t('blocks.undo'), color: 'neutral', variant: 'outline', onClick: () => {
|
|
84
|
+
const back = [...blocks.value]
|
|
85
|
+
back.splice(Math.min(index, back.length), 0, gone)
|
|
86
|
+
update(back)
|
|
87
|
+
} }],
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
/** One short name for a block (its first text, else its kind): for messages. */
|
|
91
|
+
function shortName(b: any, index: number): string {
|
|
92
|
+
const first = summary(b).split(' · ')[0] ?? ''
|
|
93
|
+
const name = first || itemLabel(b, index)
|
|
94
|
+
return name.length > 40 ? `${name.slice(0, 39).trimEnd()}…` : name
|
|
95
|
+
}
|
|
96
|
+
/** A list item's name when it has no text yet: "Item 3". */
|
|
97
|
+
function itemLabel(b: any, index: number): string {
|
|
98
|
+
return list.value ? `${tl(list.value.itemLabel ?? defs.value[b.type]?.label, t('blocks.item'))} ${index + 1}` : tl(defs.value[b.type]?.label, b.type)
|
|
99
|
+
}
|
|
100
|
+
const indented = (b: any) => !!list.value && b?.sub === true
|
|
101
|
+
// A block of a type the site no longer has, or one whose old shape could not be
|
|
102
|
+
// upgraded: kept as stored, shown as a card of its own (not editable), removable.
|
|
103
|
+
const isGone = (b: any) => !defs.value[b?.type]
|
|
104
|
+
const isStale = (b: any) => !isGone(b) && b?.__upgradeFailed === true
|
|
105
|
+
const isLocked = (b: any) => isGone(b) || isStale(b)
|
|
106
|
+
/** What a locked card is called: its kind's label when the site still has it, else the stored type. */
|
|
107
|
+
const lockedName = (b: any) => tl(defs.value[b?.type]?.label, String(b?.type || t('blocks.item')))
|
|
108
|
+
/**
|
|
109
|
+
* What a locked block holds, so an editor can tell which one it is before removing it:
|
|
110
|
+
* its first few texts, whatever their field names are (the site no longer describes them).
|
|
111
|
+
*/
|
|
112
|
+
function storedText(b: any): string {
|
|
113
|
+
const parts: string[] = []
|
|
114
|
+
for (const [k, v] of Object.entries(b ?? {})) {
|
|
115
|
+
if (k === 'id' || k === 'type' || k === 'v' || k.startsWith('__')) continue
|
|
116
|
+
if (typeof v === 'string' && v.trim()) parts.push(v.trim())
|
|
117
|
+
else if (v && typeof v === 'object') {
|
|
118
|
+
const text = JSON.stringify(v).match(/"text":"([^"]{1,120})/)?.[1]
|
|
119
|
+
if (text) parts.push(text)
|
|
120
|
+
}
|
|
121
|
+
if (parts.length === 3) break
|
|
122
|
+
}
|
|
123
|
+
const joined = parts.join(' · ')
|
|
124
|
+
return joined.length > 120 ? `${joined.slice(0, 119).trimEnd()}…` : joined
|
|
125
|
+
}
|
|
126
|
+
/** A block the site no longer has cannot be added again: removing it asks first (the others have "Undo"). */
|
|
127
|
+
async function removeLocked(index: number) {
|
|
128
|
+
const b = blocks.value[index]
|
|
129
|
+
if (isGone(b) && !(await confirm({
|
|
130
|
+
title: t('blocks.removeGoneTitle', { type: b.type }), description: t('blocks.removeGoneBody'),
|
|
131
|
+
icon: 'i-lucide-trash-2', color: 'error', confirmLabel: t('blocks.removeGoneConfirm'), cancelLabel: t('common.cancel'),
|
|
132
|
+
}))) return
|
|
133
|
+
remove(blocks.value.indexOf(b))
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Drag by the handle (the rest of the card stays clickable and selectable).
|
|
137
|
+
const armed = ref<string | null>(null)
|
|
138
|
+
const dragFrom = ref<number | null>(null)
|
|
139
|
+
const dragOver = ref<number | null>(null)
|
|
140
|
+
function onDrop(to: number) {
|
|
141
|
+
const from = dragFrom.value
|
|
142
|
+
dragFrom.value = dragOver.value = null
|
|
143
|
+
armed.value = null
|
|
144
|
+
if (from === null || from === to) return
|
|
145
|
+
const next = [...blocks.value]
|
|
146
|
+
const [b] = next.splice(from, 1)
|
|
147
|
+
next.splice(from < to ? to - 1 : to, 0, b)
|
|
148
|
+
update(next)
|
|
149
|
+
}
|
|
150
|
+
/** A list inside block `index`, keyed by its full path (errors and ids find it). */
|
|
151
|
+
function nested(f: any, index: number) {
|
|
152
|
+
return { ...f, key: `${props.field.key}.${index}.${f.key}` }
|
|
153
|
+
}
|
|
154
|
+
function setField(index: number, key: string, value: unknown) {
|
|
155
|
+
const next = [...blocks.value]
|
|
156
|
+
next[index] = { ...next[index], [key]: value }
|
|
157
|
+
update(next)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** What the block says, for the collapsed header: its first few values, choices by their labels ("Plavání · Úterý · 18:00"). */
|
|
161
|
+
function summary(b: any): string {
|
|
162
|
+
const parts: string[] = []
|
|
163
|
+
for (const f of defs.value[b.type]?.fields ?? []) {
|
|
164
|
+
const v = b[f.key]
|
|
165
|
+
if (f.type === 'select' && typeof v === 'string' && v) parts.push(tl(f.meta?.labels?.[v], v))
|
|
166
|
+
else if (typeof v === 'string' && isLinkRef(v)) {
|
|
167
|
+
// Never the raw reference: the page's title and address once they are known.
|
|
168
|
+
const target = findTarget(v)
|
|
169
|
+
if (target) parts.push(target.state === 'missing' ? t('link.missingTitle') : [target.title, target.title && target.path ? `(${target.path})` : target.path].filter(Boolean).join(' '))
|
|
170
|
+
}
|
|
171
|
+
else if (typeof v === 'string' && v.trim() && f.type !== 'media') parts.push(v.trim())
|
|
172
|
+
else if (f.type === 'richtext' && v?.content) {
|
|
173
|
+
const text = JSON.stringify(v).match(/"text":"([^"]{1,120})/)?.[1]
|
|
174
|
+
if (text) parts.push(text)
|
|
175
|
+
}
|
|
176
|
+
if (parts.length === 3) break
|
|
177
|
+
}
|
|
178
|
+
return parts.join(' · ')
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* The server's refusal of the block as a whole ("saved by a newer version", "this type no
|
|
182
|
+
* longer exists", fields the website does not know), shown on the block itself: those
|
|
183
|
+
* issues have no field of their own, so they would otherwise only surface under the list.
|
|
184
|
+
*/
|
|
185
|
+
function blockIssue(index: number): string {
|
|
186
|
+
const prefix = `${props.field.key}.${index}`
|
|
187
|
+
const known = new Set<string>((defs.value[blocks.value[index]?.type]?.fields ?? []).map((f: any) => f.key))
|
|
188
|
+
for (const [key, message] of Object.entries(form?.issues ?? {})) {
|
|
189
|
+
if (key === prefix) return message
|
|
190
|
+
if (key.startsWith(`${prefix}.`) && !known.has(key.slice(prefix.length + 1).split('.')[0]!)) return message
|
|
191
|
+
}
|
|
192
|
+
return ''
|
|
193
|
+
}
|
|
194
|
+
const hasIssue = (index: number) => Object.keys(form?.issues ?? {}).some((k) => k.startsWith(`${props.field.key}.${index}.`) || k === `${props.field.key}.${index}`)
|
|
195
|
+
// A block with a problem opens itself.
|
|
196
|
+
watch(() => ({ ...(form?.issues ?? {}) }), () => {
|
|
197
|
+
blocks.value.forEach((b, i) => { if (hasIssue(i)) open[b.id] = true })
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
function menu(index: number): DropdownMenuItem[][] {
|
|
201
|
+
return [
|
|
202
|
+
[
|
|
203
|
+
{ label: t('blocks.moveUp'), icon: 'i-lucide-arrow-up', disabled: index === 0, onSelect: () => move(index, -1) },
|
|
204
|
+
{ label: t('blocks.moveDown'), icon: 'i-lucide-arrow-down', disabled: index === blocks.value.length - 1, onSelect: () => move(index, 1) },
|
|
205
|
+
...(isLocked(blocks.value[index]) ? [] : [{ label: t('blocks.duplicate'), icon: 'i-lucide-copy', onSelect: () => duplicate(index) }]),
|
|
206
|
+
],
|
|
207
|
+
[{ label: t('blocks.remove'), icon: 'i-lucide-trash-2', color: 'error' as const, onSelect: () => remove(index) }],
|
|
208
|
+
]
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ── picker ──
|
|
212
|
+
const pickerOpen = ref(false)
|
|
213
|
+
const pickerAt = ref(0)
|
|
214
|
+
const pickerQuery = ref('')
|
|
215
|
+
// One block type (e.g. menu links): no picker, the button names the type.
|
|
216
|
+
const onlyType = computed(() => {
|
|
217
|
+
const types = Object.keys(defs.value)
|
|
218
|
+
return types.length === 1 ? types[0]! : null
|
|
219
|
+
})
|
|
220
|
+
// A list says "Add item" (a label like "Opening hours" doesn't bend into a sentence).
|
|
221
|
+
const addLabel = computed(() => (list.value ? t('blocks.addItem') : onlyType.value ? t('blocks.addType', { label: tl(defs.value[onlyType.value]?.label, onlyType.value) }) : t('blocks.add')))
|
|
222
|
+
function openPicker(at: number) {
|
|
223
|
+
if (onlyType.value) return insertAt(at, onlyType.value)
|
|
224
|
+
pickerAt.value = at
|
|
225
|
+
pickerQuery.value = ''
|
|
226
|
+
pickerOpen.value = true
|
|
227
|
+
}
|
|
228
|
+
const choices = computed(() => {
|
|
229
|
+
const q = pickerQuery.value.trim().toLowerCase()
|
|
230
|
+
return Object.entries(defs.value)
|
|
231
|
+
.map(([type, d]) => ({ type, label: tl(d.label, type), description: tl(d.description), icon: d.icon }))
|
|
232
|
+
.filter((c) => !q || c.label.toLowerCase().includes(q) || c.description.toLowerCase().includes(q))
|
|
233
|
+
})
|
|
234
|
+
</script>
|
|
235
|
+
|
|
236
|
+
<template>
|
|
237
|
+
<div class="space-y-2">
|
|
238
|
+
<CmsEmptyState
|
|
239
|
+
v-if="!blocks.length && !onlyType" plain icon="i-lucide-layout-template" :title="t('blocks.emptyTitle')" :description="t('blocks.emptyDescription')"
|
|
240
|
+
class="rounded-(--ui-radius) border border-dashed border-accented !py-10"
|
|
241
|
+
>
|
|
242
|
+
<template #actions>
|
|
243
|
+
<UButton color="neutral" variant="outline" icon="i-lucide-plus" @click="openPicker(0)">{{ t('blocks.emptyAction') }}</UButton>
|
|
244
|
+
</template>
|
|
245
|
+
</CmsEmptyState>
|
|
246
|
+
<p v-else-if="!blocks.length" class="text-sm text-muted">{{ t('blocks.emptyGeneric') }}</p>
|
|
247
|
+
|
|
248
|
+
<template v-for="(b, i) in blocks" :key="b.id">
|
|
249
|
+
<!-- insertion point between blocks -->
|
|
250
|
+
<div v-if="i > 0" class="group relative h-2 -my-1 flex items-center justify-center">
|
|
251
|
+
<button
|
|
252
|
+
type="button" class="opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity size-5 rounded-full border border-default bg-default grid place-items-center text-muted hover:text-highlighted z-10"
|
|
253
|
+
:aria-label="t('blocks.insertHere')" @click="openPicker(i)"
|
|
254
|
+
>
|
|
255
|
+
<UIcon name="i-lucide-plus" class="size-3" />
|
|
256
|
+
</button>
|
|
257
|
+
<span class="absolute inset-x-0 top-1/2 h-px bg-transparent group-hover:bg-(--ui-border)" aria-hidden="true" />
|
|
258
|
+
</div>
|
|
259
|
+
|
|
260
|
+
<!-- a block the site no longer knows (or could not bring up to date): kept, not editable -->
|
|
261
|
+
<div
|
|
262
|
+
v-if="isLocked(b)" role="group" :aria-label="lockedName(b)" data-cms-block-locked
|
|
263
|
+
class="cms-card flex items-start gap-3 px-3 py-3" :class="[blockIssue(i) ? 'border-error' : 'border-warning/60', indented(b) ? 'ml-6' : '']"
|
|
264
|
+
>
|
|
265
|
+
<UIcon name="i-lucide-triangle-alert" class="size-4 text-warning shrink-0 mt-0.5" aria-hidden="true" />
|
|
266
|
+
<div class="min-w-0 flex-1 space-y-0.5">
|
|
267
|
+
<p class="text-sm font-medium text-highlighted">{{ t(isGone(b) ? 'blocks.gone' : 'blocks.stale', { type: lockedName(b) }) }}</p>
|
|
268
|
+
<p v-if="storedText(b)" class="line-clamp-2 break-words text-xs text-toned">{{ t('blocks.storedContent', { text: storedText(b) }) }}</p>
|
|
269
|
+
<p class="text-xs text-muted">{{ t(isGone(b) ? 'blocks.goneHelp' : 'blocks.staleHelp') }}</p>
|
|
270
|
+
<p v-if="blockIssue(i)" role="alert" class="pt-1 text-xs font-medium text-error">{{ blockIssue(i) }}</p>
|
|
271
|
+
</div>
|
|
272
|
+
<UButton
|
|
273
|
+
color="error" variant="ghost" size="sm" icon="i-lucide-trash-2" class="shrink-0 pointer-coarse:min-h-11"
|
|
274
|
+
:aria-label="t('blocks.removeNamed', { name: lockedName(b) })" @click="removeLocked(i)"
|
|
275
|
+
>{{ t('blocks.remove') }}</UButton>
|
|
276
|
+
</div>
|
|
277
|
+
<div
|
|
278
|
+
v-else class="cms-card transition-[margin,box-shadow]"
|
|
279
|
+
:class="[hasIssue(i) ? 'border-error' : '', indented(b) ? 'ml-6' : '', dragOver === i && dragFrom !== i ? 'ring-2 ring-(--ui-primary)/40' : '', dragFrom === i ? 'opacity-50' : '']"
|
|
280
|
+
:draggable="armed === b.id"
|
|
281
|
+
@dragstart.stop="(e: DragEvent) => { dragFrom = i; e.dataTransfer?.setData('text/plain', b.id) }"
|
|
282
|
+
@dragover.prevent.stop="dragFrom !== null && (dragOver = i)" @dragleave.stop="dragOver === i && (dragOver = null)"
|
|
283
|
+
@drop.prevent.stop="onDrop(dragOver !== null && dragFrom !== null && dragOver > dragFrom ? i + 1 : i)"
|
|
284
|
+
@dragend.stop="dragFrom = dragOver = null; armed = null"
|
|
285
|
+
>
|
|
286
|
+
<div class="flex items-center gap-2 pl-1.5 pr-1.5 py-2">
|
|
287
|
+
<span
|
|
288
|
+
v-if="blocks.length > 1" class="cursor-grab touch-none text-dimmed hover:text-muted shrink-0 p-1" :title="t('blocks.drag')" aria-hidden="true"
|
|
289
|
+
@pointerdown="armed = b.id" @pointerup="armed = null"
|
|
290
|
+
><UIcon name="i-lucide-grip-vertical" class="size-4" /></span>
|
|
291
|
+
<button
|
|
292
|
+
type="button" class="flex flex-1 min-w-0 items-center gap-2.5 text-left"
|
|
293
|
+
:aria-expanded="!!open[b.id]"
|
|
294
|
+
@click="open[b.id] = !open[b.id]"
|
|
295
|
+
>
|
|
296
|
+
<UIcon name="i-lucide-chevron-right" class="size-4 text-dimmed shrink-0 transition-transform" :class="open[b.id] ? 'rotate-90' : ''" />
|
|
297
|
+
<template v-if="list">
|
|
298
|
+
<UIcon v-if="indented(b)" name="i-lucide-corner-down-right" class="size-4 text-dimmed shrink-0" />
|
|
299
|
+
<span class="text-sm font-medium text-highlighted truncate">{{ summary(b) || itemLabel(b, i) }}</span>
|
|
300
|
+
</template>
|
|
301
|
+
<template v-else>
|
|
302
|
+
<UIcon :name="defs[b.type]?.icon ?? 'i-lucide-square'" class="size-4 text-muted shrink-0" />
|
|
303
|
+
<span class="text-sm font-medium text-highlighted shrink-0">{{ tl(defs[b.type]?.label, b.type) }}</span>
|
|
304
|
+
<span v-if="!open[b.id] && summary(b)" class="text-sm text-muted truncate">{{ summary(b) }}</span>
|
|
305
|
+
</template>
|
|
306
|
+
<span v-if="hasIssue(i)" class="ml-auto shrink-0 inline-flex items-center gap-1 text-xs text-error">
|
|
307
|
+
<span class="size-1.5 rounded-full bg-error" aria-hidden="true" />{{ t('blocks.hasErrors') }}
|
|
308
|
+
</span>
|
|
309
|
+
</button>
|
|
310
|
+
<UDropdownMenu :items="menu(i)" :content="{ align: 'end' }">
|
|
311
|
+
<UButton color="neutral" variant="ghost" size="sm" icon="i-lucide-ellipsis" class="pointer-coarse:size-11" :aria-label="t('blocks.actions')" />
|
|
312
|
+
</UDropdownMenu>
|
|
313
|
+
</div>
|
|
314
|
+
<div v-if="open[b.id]" class="border-t border-default px-4 py-4 space-y-5">
|
|
315
|
+
<p v-if="blockIssue(i)" role="alert" class="flex items-start gap-1.5 text-sm text-error">
|
|
316
|
+
<UIcon name="i-lucide-circle-alert" class="mt-0.5 size-4 shrink-0" aria-hidden="true" />{{ blockIssue(i) }}
|
|
317
|
+
</p>
|
|
318
|
+
<p v-if="!defs[b.type]" class="text-sm text-muted">{{ b.type }}</p>
|
|
319
|
+
<CmsField
|
|
320
|
+
v-for="f in (defs[b.type]?.fields ?? []).filter((x: any) => !(i === 0 && x.meta?.needsPrevious))" :key="f.key"
|
|
321
|
+
:model-value="b[f.key]" :field="f.type === 'blocks' || f.type === 'group' ? nested(f, i) : f" :entity="entity" :id-prefix="`${field.key}-${b.id}-`"
|
|
322
|
+
:error="form?.issues?.[`${field.key}.${i}.${f.key}`]"
|
|
323
|
+
@update:model-value="(v: unknown) => setField(i, f.key, v)"
|
|
324
|
+
/>
|
|
325
|
+
</div>
|
|
326
|
+
</div>
|
|
327
|
+
</template>
|
|
328
|
+
|
|
329
|
+
<UButton v-if="(blocks.length || onlyType) && !full" color="neutral" variant="ghost" icon="i-lucide-plus" size="sm" @click="openPicker(blocks.length)">
|
|
330
|
+
{{ addLabel }}
|
|
331
|
+
</UButton>
|
|
332
|
+
|
|
333
|
+
<UModal v-model:open="pickerOpen" :title="t('blocks.pickerTitle')">
|
|
334
|
+
<template #body>
|
|
335
|
+
<UInput v-model="pickerQuery" icon="i-lucide-search" :placeholder="t('blocks.search')" autofocus class="w-full mb-3" />
|
|
336
|
+
<ul class="-mx-2 space-y-0.5">
|
|
337
|
+
<li v-for="c in choices" :key="c.type">
|
|
338
|
+
<button type="button" class="w-full flex items-start gap-3 rounded-(--ui-radius) px-2 py-2 text-left hover:bg-elevated/70" @click="insertAt(pickerAt, c.type)">
|
|
339
|
+
<span class="size-8 shrink-0 rounded-md border border-default grid place-items-center text-muted">
|
|
340
|
+
<UIcon :name="c.icon" class="size-4" />
|
|
341
|
+
</span>
|
|
342
|
+
<span class="min-w-0">
|
|
343
|
+
<span class="block text-sm font-medium text-highlighted">{{ c.label }}</span>
|
|
344
|
+
<span v-if="c.description" class="block text-xs text-muted">{{ c.description }}</span>
|
|
345
|
+
</span>
|
|
346
|
+
</button>
|
|
347
|
+
</li>
|
|
348
|
+
</ul>
|
|
349
|
+
<p v-if="!choices.length" class="text-sm text-muted px-1 py-2">{{ t('blocks.noMatch') }}</p>
|
|
350
|
+
</template>
|
|
351
|
+
</UModal>
|
|
352
|
+
</div>
|
|
353
|
+
</template>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A colour (#rrggbb): the system colour picker next to the hex code, both editable.
|
|
3
|
+
const props = defineProps<{ field: any; entity?: string; id?: string }>()
|
|
4
|
+
const model = defineModel<string | null | undefined>()
|
|
5
|
+
const { t } = useCmsI18n()
|
|
6
|
+
const injected = inject<Ref<'outline' | 'ghost'> | null>('cmsFieldVariant', null)
|
|
7
|
+
const variant = computed(() => injected?.value ?? 'outline')
|
|
8
|
+
const valid = computed(() => typeof model.value === 'string' && /^#[0-9a-fA-F]{6}$/.test(model.value))
|
|
9
|
+
function onPick(e: Event) {
|
|
10
|
+
model.value = (e.target as HTMLInputElement).value
|
|
11
|
+
}
|
|
12
|
+
// Leaving the box tidies what was typed: "1f6feb" → "#1f6feb", "#1f6" → "#11ff66".
|
|
13
|
+
const touched = ref(false)
|
|
14
|
+
function normalize() {
|
|
15
|
+
touched.value = true
|
|
16
|
+
const typed = String(model.value ?? '').trim().toLowerCase()
|
|
17
|
+
if (!typed || typed === '#') { model.value = props.field.optional ? null : ''; return }
|
|
18
|
+
// Only hex digits get their "#" (never "red" → "#red").
|
|
19
|
+
if (!/^#?[0-9a-f]+$/.test(typed)) { model.value = typed; return }
|
|
20
|
+
const raw = typed.startsWith('#') ? typed : `#${typed}`
|
|
21
|
+
const short = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/.exec(raw)
|
|
22
|
+
model.value = short ? `#${short[1]}${short[1]}${short[2]}${short[2]}${short[3]}${short[3]}` : raw
|
|
23
|
+
}
|
|
24
|
+
const showHint = computed(() => touched.value && !!model.value && !valid.value)
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<div>
|
|
29
|
+
<div class="flex items-center gap-2">
|
|
30
|
+
<label class="relative size-8 shrink-0 cursor-pointer overflow-hidden rounded-md border border-default" :style="{ background: valid ? model! : 'transparent' }">
|
|
31
|
+
<span v-if="!valid" class="absolute inset-0 grid place-items-center text-dimmed"><UIcon name="i-lucide-palette" class="size-4" /></span>
|
|
32
|
+
<input type="color" class="absolute inset-0 size-full cursor-pointer opacity-0" :value="valid ? model! : '#000000'" :aria-label="t('fields.pickColor')" @input="onPick">
|
|
33
|
+
</label>
|
|
34
|
+
<UInput
|
|
35
|
+
:id="id" v-model="model" :variant="variant" placeholder="#1f6feb" class="w-32" maxlength="7"
|
|
36
|
+
:ui="{ base: 'font-mono text-[0.8125rem] uppercase' }" :aria-invalid="showHint" @blur="normalize"
|
|
37
|
+
/>
|
|
38
|
+
<UButton v-if="model && field.optional" color="neutral" variant="ghost" size="sm" icon="i-lucide-x" :aria-label="t('fields.clear')" @click="model = null" />
|
|
39
|
+
</div>
|
|
40
|
+
<p v-if="showHint" class="mt-1 text-sm text-error">{{ t('fields.colorHint') }}</p>
|
|
41
|
+
</div>
|
|
42
|
+
</template>
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Date & time, edited as wall-clock time in the admin's time zone (cms.admin.timeZone)
|
|
3
|
+
// and stored as an exact instant. The browser's own zone plays no part.
|
|
4
|
+
//
|
|
5
|
+
// The day is picked from a calendar ("Saturday 13 June 2026"), the time typed beside
|
|
6
|
+
// it. `f.datetime({ allDay: true })` adds "All day": the time goes away and the value
|
|
7
|
+
// is stored at 0:00.
|
|
8
|
+
import { CalendarDate } from '@internationalized/date'
|
|
9
|
+
|
|
10
|
+
const props = defineProps<{ field: any; entity?: string; id?: string }>()
|
|
11
|
+
// The field's own id belongs to the date button the label points at; the other controls inside
|
|
12
|
+
// would all take the form field's generated id (and each other's): one id on the page, once.
|
|
13
|
+
const timeId = computed(() => (props.id ? `${props.id}-time` : undefined))
|
|
14
|
+
const allDayId = computed(() => (props.id ? `${props.id}-allday` : undefined))
|
|
15
|
+
const clearId = computed(() => (props.id ? `${props.id}-clear` : undefined))
|
|
16
|
+
const model = defineModel<any>()
|
|
17
|
+
const config = useCmsAdminConfig()
|
|
18
|
+
const { t, locale, formatDateWith, fieldLabel } = useCmsI18n()
|
|
19
|
+
|
|
20
|
+
const tz = computed(() => config.value.timeZone)
|
|
21
|
+
const wall = computed(() => toZonedInput(model.value, tz.value)) // 'YYYY-MM-DDTHH:mm' or ''
|
|
22
|
+
const day = computed(() => wall.value.slice(0, 10))
|
|
23
|
+
const time = computed(() => wall.value.slice(11, 16))
|
|
24
|
+
|
|
25
|
+
const canAllDay = computed(() => !!props.field.meta?.allDay)
|
|
26
|
+
const allDay = ref(canAllDay.value && !!wall.value && time.value === '00:00')
|
|
27
|
+
// A time set elsewhere (a newer version loaded) ends "all day".
|
|
28
|
+
watch(time, (v) => { if (v && v !== '00:00') allDay.value = false })
|
|
29
|
+
|
|
30
|
+
const pad = (n: number) => String(n).padStart(2, '0')
|
|
31
|
+
function write(d: string, hm: string) {
|
|
32
|
+
model.value = d ? fromZonedInput(`${d}T${hm || '00:00'}`, tz.value) : null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const open = ref(false)
|
|
36
|
+
// The calendar's own words otherwise stay English ("Event date", "Previous month").
|
|
37
|
+
const calendarLabels = computed(() => ({
|
|
38
|
+
calendarLabel: fieldLabel(props.field),
|
|
39
|
+
prevMonth: { 'aria-label': t('fields.prevMonth') },
|
|
40
|
+
nextMonth: { 'aria-label': t('fields.nextMonth') },
|
|
41
|
+
}))
|
|
42
|
+
const calendarValue = computed({
|
|
43
|
+
get: () => {
|
|
44
|
+
if (!day.value) return undefined
|
|
45
|
+
const [y, m, d] = day.value.split('-').map(Number) as [number, number, number]
|
|
46
|
+
return new CalendarDate(y, m, d)
|
|
47
|
+
},
|
|
48
|
+
set: (v: any) => {
|
|
49
|
+
if (!v) return
|
|
50
|
+
// A first date with no time yet is an all-day one (it is stored at 0:00 and reads
|
|
51
|
+
// back as "All day"): say so now, not only after saving. Untick it to add a time.
|
|
52
|
+
if (!day.value && canAllDay.value) allDay.value = true
|
|
53
|
+
// A first date with a time starts at 9:00 (publishing at midnight surprises people).
|
|
54
|
+
write(`${v.year}-${pad(v.month)}-${pad(v.day)}`, allDay.value ? '00:00' : (time.value || '09:00'))
|
|
55
|
+
// The compact control keeps the calendar open: the time sits under it.
|
|
56
|
+
if (!compact.value) open.value = false
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
const timeValue = computed({
|
|
60
|
+
get: () => time.value,
|
|
61
|
+
set: (v: string) => { if (day.value && v) write(day.value, v) },
|
|
62
|
+
})
|
|
63
|
+
function setAllDay(on: boolean | 'indeterminate') {
|
|
64
|
+
allDay.value = on === true
|
|
65
|
+
if (allDay.value && day.value) write(day.value, '00:00')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const shown = computed(() => (model.value ? formatDateWith(model.value, { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }) : ''))
|
|
69
|
+
// In a details row: one quiet button ("5. 8. 2024, 10:00"); time and "All day" sit
|
|
70
|
+
// under the calendar.
|
|
71
|
+
const variant = inject<Ref<'outline' | 'ghost'> | null>('cmsFieldVariant', null)
|
|
72
|
+
const compact = computed(() => variant?.value === 'ghost')
|
|
73
|
+
const shortShown = computed(() => {
|
|
74
|
+
if (!model.value) return ''
|
|
75
|
+
return allDay.value
|
|
76
|
+
? formatDateWith(model.value, { day: 'numeric', month: 'numeric', year: 'numeric' })
|
|
77
|
+
: formatDateWith(model.value, { day: 'numeric', month: 'numeric', year: 'numeric', hour: 'numeric', minute: '2-digit' })
|
|
78
|
+
})
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<template>
|
|
82
|
+
<UPopover v-if="compact" v-model:open="open">
|
|
83
|
+
<UButton
|
|
84
|
+
:id="id" color="neutral" variant="ghost" class="w-full justify-start font-normal px-2.5"
|
|
85
|
+
:class="shortShown ? 'text-highlighted' : 'text-dimmed'" :title="tz"
|
|
86
|
+
>
|
|
87
|
+
<span class="truncate">{{ shortShown || t('fields.pickDate') }}</span>
|
|
88
|
+
</UButton>
|
|
89
|
+
<template #content>
|
|
90
|
+
<div class="p-2">
|
|
91
|
+
<UCalendar v-model="calendarValue" :locale="locale" :week-starts-on="1" weekday-format="short" :year-controls="false" :fixed-weeks="false" v-bind="calendarLabels" />
|
|
92
|
+
<div class="flex flex-wrap items-center gap-2 border-t border-default mt-2 pt-3 px-1">
|
|
93
|
+
<UInput
|
|
94
|
+
v-if="!allDay" :id="timeId" v-model="timeValue" type="time" icon="i-lucide-clock" size="sm" class="w-28" :ui="{ base: 'cms-time-input' }"
|
|
95
|
+
:disabled="!day" :aria-label="t('fields.time')"
|
|
96
|
+
/>
|
|
97
|
+
<UCheckbox v-if="canAllDay" :id="allDayId" :model-value="allDay" :label="t('fields.allDay')" @update:model-value="setAllDay" />
|
|
98
|
+
<UButton
|
|
99
|
+
v-if="model && field.optional" :id="clearId" class="ml-auto" size="sm" color="neutral" variant="ghost" icon="i-lucide-x"
|
|
100
|
+
@click="model = null; open = false"
|
|
101
|
+
>{{ t('fields.clear') }}</UButton>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
</template>
|
|
105
|
+
</UPopover>
|
|
106
|
+
<div v-else>
|
|
107
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
108
|
+
<UPopover v-model:open="open">
|
|
109
|
+
<UButton
|
|
110
|
+
:id="id" color="neutral" variant="outline" icon="i-lucide-calendar"
|
|
111
|
+
class="flex-1 min-w-48 justify-start font-normal bg-default"
|
|
112
|
+
:class="shown ? 'text-highlighted' : 'text-dimmed'" :title="tz"
|
|
113
|
+
>
|
|
114
|
+
<span class="truncate first-letter:uppercase">{{ shown || t('fields.pickDate') }}</span>
|
|
115
|
+
</UButton>
|
|
116
|
+
<template #content>
|
|
117
|
+
<UCalendar v-model="calendarValue" :locale="locale" :week-starts-on="1" weekday-format="short" :year-controls="false" :fixed-weeks="false" v-bind="calendarLabels" class="p-2" />
|
|
118
|
+
</template>
|
|
119
|
+
</UPopover>
|
|
120
|
+
<UInput
|
|
121
|
+
v-if="!allDay" :id="timeId" v-model="timeValue" type="time" icon="i-lucide-clock" class="w-32" :ui="{ base: 'cms-time-input' }"
|
|
122
|
+
:disabled="!day" :aria-label="t('fields.time')" :title="tz"
|
|
123
|
+
/>
|
|
124
|
+
<UButton
|
|
125
|
+
v-if="model && field.optional" :id="clearId" color="neutral" variant="ghost" icon="i-lucide-x" :aria-label="t('fields.clear')"
|
|
126
|
+
@click="model = null"
|
|
127
|
+
/>
|
|
128
|
+
</div>
|
|
129
|
+
<UCheckbox v-if="canAllDay" :id="allDayId" :model-value="allDay" :label="t('fields.allDay')" class="mt-2.5" @update:model-value="setAllDay" />
|
|
130
|
+
</div>
|
|
131
|
+
</template>
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Gallery field: several files in order, each with an optional caption. Add by
|
|
3
|
+
// uploading (several at once) or from the library; drag to reorder (or use the
|
|
4
|
+
// arrows); the caption sits under each picture.
|
|
5
|
+
const props = defineProps<{ field: any }>()
|
|
6
|
+
const model = defineModel<{ mediaId: string; caption?: string | null }[] | null>()
|
|
7
|
+
const { t } = useCmsI18n()
|
|
8
|
+
const toast = useToast()
|
|
9
|
+
|
|
10
|
+
const items = computed(() => model.value ?? [])
|
|
11
|
+
const media = reactive<Record<string, any>>({})
|
|
12
|
+
async function resolve(ids: string[]) {
|
|
13
|
+
const missing = ids.filter((id) => !media[id])
|
|
14
|
+
if (!missing.length) return
|
|
15
|
+
// The media list returns at most 60 at a time.
|
|
16
|
+
for (let i = 0; i < missing.length; i += 60) {
|
|
17
|
+
const ids = missing.slice(i, i + 60)
|
|
18
|
+
const res = await $fetch<{ items: any[] }>('/api/cms/_media', { query: { ids: ids.join(','), limit: 60 } }).catch(() => ({ items: [] }))
|
|
19
|
+
for (const m of res.items) media[m.id] = m
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
watch(() => items.value.map((i) => i.mediaId), (ids) => { void resolve(ids) }, { immediate: true })
|
|
23
|
+
|
|
24
|
+
const set = (next: { mediaId: string; caption?: string | null }[]) => { model.value = next }
|
|
25
|
+
function add(m: any) {
|
|
26
|
+
media[m.id] = m
|
|
27
|
+
if (items.value.some((i) => i.mediaId === m.id)) return
|
|
28
|
+
set([...items.value, { mediaId: m.id, caption: null }])
|
|
29
|
+
}
|
|
30
|
+
// Taking a photo out is one tap on a small target; "Undo" in the message puts it back where it was.
|
|
31
|
+
function remove(i: number) {
|
|
32
|
+
const before = items.value
|
|
33
|
+
const gone = before[i]
|
|
34
|
+
if (!gone) return
|
|
35
|
+
const name = media[gone.mediaId]?.name || media[gone.mediaId]?.alt || ''
|
|
36
|
+
set(before.filter((_, j) => j !== i))
|
|
37
|
+
toast.add({
|
|
38
|
+
title: t('fields.galleryRemoved', { name }), icon: 'i-lucide-trash-2', color: 'neutral',
|
|
39
|
+
actions: [{ label: t('blocks.undo'), color: 'neutral', variant: 'outline', onClick: () => set(before) }],
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
function move(i: number, d: number) {
|
|
43
|
+
const j = i + d
|
|
44
|
+
if (j < 0 || j >= items.value.length) return
|
|
45
|
+
const next = [...items.value]
|
|
46
|
+
;[next[i], next[j]] = [next[j]!, next[i]!]
|
|
47
|
+
set(next)
|
|
48
|
+
}
|
|
49
|
+
const setCaption = (i: number, caption: string) => set(items.value.map((it, j) => (j === i ? { ...it, caption: caption || null } : it)))
|
|
50
|
+
|
|
51
|
+
const dragFrom = ref<number | null>(null)
|
|
52
|
+
function onDragOver(i: number) {
|
|
53
|
+
const from = dragFrom.value
|
|
54
|
+
if (from === null || from === i) return
|
|
55
|
+
const next = [...items.value]
|
|
56
|
+
const [moved] = next.splice(from, 1)
|
|
57
|
+
next.splice(i, 0, moved!)
|
|
58
|
+
set(next)
|
|
59
|
+
dragFrom.value = i
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const libraryOpen = ref(false)
|
|
63
|
+
const fileInput = ref<HTMLInputElement | null>(null)
|
|
64
|
+
const uploading = ref(0)
|
|
65
|
+
async function upload(files: FileList | null) {
|
|
66
|
+
for (const file of [...(files ?? [])]) {
|
|
67
|
+
uploading.value++
|
|
68
|
+
try {
|
|
69
|
+
const form = new FormData()
|
|
70
|
+
form.append('file', file)
|
|
71
|
+
add(await cmsUploadFile(form))
|
|
72
|
+
}
|
|
73
|
+
catch (err: any) {
|
|
74
|
+
toast.add({ title: t('media.uploadFailed'), description: `${file.name}: ${cmsRequestError(err, t as any)}`, color: 'error', icon: 'i-lucide-x' })
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
uploading.value--
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
</script>
|
|
82
|
+
|
|
83
|
+
<template>
|
|
84
|
+
<div class="space-y-3">
|
|
85
|
+
<CmsMediaLibrary v-model:open="libraryOpen" :accept="field.meta?.accept" @select="add" />
|
|
86
|
+
<input ref="fileInput" type="file" multiple class="hidden" :accept="field.meta?.accept" @change="(e: any) => { upload(e.target.files); e.target.value = '' }">
|
|
87
|
+
<ol v-if="items.length" class="grid grid-cols-2 gap-3 sm:grid-cols-3">
|
|
88
|
+
<li
|
|
89
|
+
v-for="(it, i) in items" :key="it.mediaId" draggable="true" class="group space-y-1.5"
|
|
90
|
+
:class="dragFrom === i ? 'opacity-60' : ''"
|
|
91
|
+
@dragstart="dragFrom = i" @dragover.prevent="onDragOver(i)" @dragend="dragFrom = null" @drop.prevent="dragFrom = null"
|
|
92
|
+
>
|
|
93
|
+
<div class="relative aspect-[4/3] overflow-hidden rounded-(--ui-radius) border border-default bg-elevated cursor-grab">
|
|
94
|
+
<CmsMediaThumb v-if="media[it.mediaId]" :media="media[it.mediaId]" />
|
|
95
|
+
<!-- always there: a phone has no hover to show them (and a tap on an invisible x removed a photo) -->
|
|
96
|
+
<div class="absolute right-1 top-1 flex gap-0.5 rounded-md bg-default/90 p-0.5 shadow-sm ring-1 ring-(--ui-border)">
|
|
97
|
+
<UButton size="xs" color="neutral" variant="ghost" icon="i-lucide-arrow-left" :disabled="i === 0" :aria-label="t('fields.galleryEarlier')" @click="move(i, -1)" />
|
|
98
|
+
<UButton size="xs" color="neutral" variant="ghost" icon="i-lucide-arrow-right" :disabled="i === items.length - 1" :aria-label="t('fields.galleryLater')" @click="move(i, 1)" />
|
|
99
|
+
<UButton size="xs" color="error" variant="ghost" icon="i-lucide-x" :aria-label="t('media.remove')" @click="remove(i)" />
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
<UInput
|
|
103
|
+
:model-value="it.caption ?? ''" size="xs" variant="ghost" class="w-full" :placeholder="t('fields.galleryCaption')"
|
|
104
|
+
:aria-label="t('fields.galleryCaption')" @update:model-value="(v: any) => setCaption(i, String(v))"
|
|
105
|
+
/>
|
|
106
|
+
</li>
|
|
107
|
+
</ol>
|
|
108
|
+
<div class="flex flex-wrap gap-2">
|
|
109
|
+
<UButton size="sm" color="neutral" variant="outline" icon="i-lucide-upload" :loading="uploading > 0" @click="fileInput?.click()">{{ t('media.upload') }}</UButton>
|
|
110
|
+
<UButton size="sm" color="neutral" variant="ghost" icon="i-lucide-images" @click="libraryOpen = true">{{ t('media.browse') }}</UButton>
|
|
111
|
+
<span v-if="items.length" class="self-center text-xs text-muted">{{ t('fields.galleryCount', { count: items.length }) }}</span>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
</template>
|