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,494 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// The media library: every uploaded file in a grid, by folder, searchable. Drop files
|
|
3
|
+
// anywhere on the page to upload them (into the open folder).
|
|
4
|
+
//
|
|
5
|
+
// A file opens in a panel docked on the right (?file=… in the address), never over
|
|
6
|
+
// the page: the grid stays usable, and clicking another file switches the panel (its
|
|
7
|
+
// unsaved changes are saved first). On phones the panel is a page of its own. It holds
|
|
8
|
+
// the descriptions (per content language), folder, focal point — click the image where
|
|
9
|
+
// it must stay in view when the site crops it — and where the file is used.
|
|
10
|
+
definePageMeta({ layout: 'admin' })
|
|
11
|
+
const { t, tl, formatNumber, formatDate } = useCmsI18n()
|
|
12
|
+
const route = useRoute()
|
|
13
|
+
const router = useRouter()
|
|
14
|
+
const toast = useToast()
|
|
15
|
+
useHead({ title: () => t('media.libraryTitle') })
|
|
16
|
+
|
|
17
|
+
const { data: graph } = await useFetch<any[]>('/api/cms/_graph', { key: 'cms-graph' })
|
|
18
|
+
// Content languages (from any translatable collection): descriptions per language.
|
|
19
|
+
const locales = computed(() => (graph.value ?? []).find((e: any) => e.locales)?.locales as { default: string; all: string[]; labels: Record<string, any> } | undefined)
|
|
20
|
+
const otherLangs = computed(() => (locales.value?.all ?? []).filter((l) => l !== locales.value?.default))
|
|
21
|
+
const langLabel = (code: string) => tl(locales.value?.labels?.[code], code.toUpperCase())
|
|
22
|
+
|
|
23
|
+
const q = ref('')
|
|
24
|
+
const folder = ref<string>('all')
|
|
25
|
+
const kind = ref<'all' | 'image/*' | 'video/*' | 'audio/*' | 'application/pdf'>('all')
|
|
26
|
+
const limit = 48
|
|
27
|
+
const page = ref(1)
|
|
28
|
+
const items = ref<any[]>([])
|
|
29
|
+
const total = ref(0)
|
|
30
|
+
const folders = ref<string[]>([])
|
|
31
|
+
const loading = ref(false)
|
|
32
|
+
// The empty state only once the first answer is in (never on the page's first paint).
|
|
33
|
+
const loaded = ref(false)
|
|
34
|
+
async function load(reset = true) {
|
|
35
|
+
loading.value = true
|
|
36
|
+
if (reset) page.value = 1
|
|
37
|
+
try {
|
|
38
|
+
const res: any = await $fetch('/api/cms/_media', { query: { q: q.value || undefined, folder: folder.value === 'all' ? undefined : folder.value, accept: kind.value === 'all' ? undefined : kind.value, page: page.value, limit } })
|
|
39
|
+
items.value = reset ? res.items : [...items.value, ...res.items]
|
|
40
|
+
total.value = res.total
|
|
41
|
+
folders.value = res.folders ?? []
|
|
42
|
+
}
|
|
43
|
+
catch (err: any) {
|
|
44
|
+
toast.add({ title: t('media.loadFailed'), description: cmsRequestError(err, t as any), color: 'error', icon: 'i-lucide-x' })
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
loading.value = false
|
|
48
|
+
loaded.value = true
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
onMounted(() => load())
|
|
52
|
+
let debounce: ReturnType<typeof setTimeout> | undefined
|
|
53
|
+
watch(q, () => { clearTimeout(debounce); debounce = setTimeout(() => load(), 250) })
|
|
54
|
+
watch([folder, kind], () => load())
|
|
55
|
+
const folderTabs = computed(() => [
|
|
56
|
+
{ value: 'all', label: t('media.allFiles') },
|
|
57
|
+
{ value: 'none', label: t('media.noFolder') },
|
|
58
|
+
...folders.value.map((f) => ({ value: f, label: f })),
|
|
59
|
+
])
|
|
60
|
+
|
|
61
|
+
const isImage = (m: any) => cmsMediaKind(m) === 'image'
|
|
62
|
+
// A phone has no mouse to drag files with: its empty library says "Upload", not "Drag".
|
|
63
|
+
const coarse = ref(false)
|
|
64
|
+
onMounted(() => { coarse.value = window.matchMedia('(pointer: coarse)').matches })
|
|
65
|
+
const sizeLabel = (bytes: number) => (bytes >= 1024 * 1024 ? `${formatNumber(Math.round(bytes / 104857.6) / 10)} MB` : `${formatNumber(Math.max(1, Math.round(bytes / 1024)))} kB`)
|
|
66
|
+
|
|
67
|
+
// ── upload: the button, or files dropped on the page ──
|
|
68
|
+
const fileInput = ref<HTMLInputElement | null>(null)
|
|
69
|
+
const uploading = ref(0)
|
|
70
|
+
const dragging = ref(false)
|
|
71
|
+
async function upload(files: FileList | File[]) {
|
|
72
|
+
const list = [...files]
|
|
73
|
+
if (!list.length) return
|
|
74
|
+
uploading.value = list.length
|
|
75
|
+
const failures: string[] = []
|
|
76
|
+
let waited = false
|
|
77
|
+
for (const file of list) {
|
|
78
|
+
const form = new FormData()
|
|
79
|
+
form.append('file', file)
|
|
80
|
+
form.append('library', '1')
|
|
81
|
+
if (folder.value !== 'all' && folder.value !== 'none') form.append('folder', folder.value)
|
|
82
|
+
try {
|
|
83
|
+
// Files go one after another; when the server asks for a pause the rest wait for it
|
|
84
|
+
// (one message, not one error per file).
|
|
85
|
+
await cmsUploadFile(form, {
|
|
86
|
+
onWait: () => {
|
|
87
|
+
if (waited) return
|
|
88
|
+
waited = true
|
|
89
|
+
toast.add({ id: 'cms-upload-wait', title: t('media.uploadWaiting'), icon: 'i-lucide-clock', color: 'neutral' })
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
catch (err: any) {
|
|
94
|
+
failures.push(`${file.name}: ${cmsRequestError(err, t as any)}`)
|
|
95
|
+
}
|
|
96
|
+
uploading.value--
|
|
97
|
+
}
|
|
98
|
+
// One summary for every file that did not make it (60 wrong files are one message).
|
|
99
|
+
if (failures.length) {
|
|
100
|
+
const shown = failures.slice(0, 3).join('\n')
|
|
101
|
+
toast.add({
|
|
102
|
+
title: failures.length === list.length && list.length === 1 ? t('media.uploadFailed') : t('media.uploadSomeFailed', { count: failures.length }),
|
|
103
|
+
description: failures.length > 3 ? `${shown}\n${t('list.andMore', { count: failures.length - 3 })}` : shown,
|
|
104
|
+
color: 'error', icon: 'i-lucide-x', duration: 10000,
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
if (list.length - failures.length) toast.add({ title: t('media.uploaded', { count: list.length - failures.length }), color: 'success', icon: 'i-lucide-check' })
|
|
108
|
+
load()
|
|
109
|
+
}
|
|
110
|
+
function onDrop(e: DragEvent) {
|
|
111
|
+
dragging.value = false
|
|
112
|
+
if (e.dataTransfer?.files?.length) upload(e.dataTransfer.files)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ── a file's panel ──
|
|
116
|
+
const current = ref<any | null>(null)
|
|
117
|
+
const draft = reactive<{ alt: string; altLocales: Record<string, string>; folder: string; focal: { x: number; y: number } | null }>({ alt: '', altLocales: {}, folder: '', focal: null })
|
|
118
|
+
const usage = ref<any[] | null>(null)
|
|
119
|
+
const saving = ref(false)
|
|
120
|
+
const deleting = ref(false)
|
|
121
|
+
const dirty = computed(() => !!current.value && (
|
|
122
|
+
draft.alt !== (current.value.alt ?? '')
|
|
123
|
+
|| draft.folder !== (current.value.folder ?? '')
|
|
124
|
+
|| JSON.stringify(draft.focal) !== JSON.stringify(current.value.focalX != null ? { x: current.value.focalX, y: current.value.focalY } : null)
|
|
125
|
+
|| Object.entries(draft.altLocales).some(([k, v]) => (v ?? '') !== (current.value.altLocales?.[k] ?? ''))
|
|
126
|
+
))
|
|
127
|
+
/** Open a file in the panel (saving the one open now, when it has changes). */
|
|
128
|
+
async function open(m: any) {
|
|
129
|
+
if (current.value?.id === m.id) return
|
|
130
|
+
if (dirty.value) await save(true)
|
|
131
|
+
show(m)
|
|
132
|
+
router.replace({ query: { ...route.query, file: m.id } })
|
|
133
|
+
}
|
|
134
|
+
function close() {
|
|
135
|
+
if (dirty.value) save(true)
|
|
136
|
+
current.value = null
|
|
137
|
+
const { file: _file, ...rest } = route.query
|
|
138
|
+
router.replace({ query: rest })
|
|
139
|
+
}
|
|
140
|
+
async function show(m: any) {
|
|
141
|
+
current.value = m
|
|
142
|
+
draft.alt = m.alt ?? ''
|
|
143
|
+
draft.altLocales = { ...(m.altLocales ?? {}) }
|
|
144
|
+
draft.folder = m.folder ?? ''
|
|
145
|
+
draft.focal = m.focalX != null ? { x: m.focalX, y: m.focalY } : null
|
|
146
|
+
usage.value = null
|
|
147
|
+
const found = (await cmsFetch<{ usage: any[] }>(`/api/cms/_media/${m.id}/usage`).catch(() => ({ usage: [] }))).usage
|
|
148
|
+
// Opened another file meanwhile: its usage, not this one's.
|
|
149
|
+
if (current.value?.id === m.id) usage.value = found
|
|
150
|
+
}
|
|
151
|
+
// A file named in the address opens on arrival (a shared link, a reload).
|
|
152
|
+
onMounted(async () => {
|
|
153
|
+
const id = route.query.file
|
|
154
|
+
if (typeof id !== 'string' || !id) return
|
|
155
|
+
const m = await cmsFetch<any>(`/api/cms/_media/${id}`).catch(() => null)
|
|
156
|
+
if (m) show(m)
|
|
157
|
+
})
|
|
158
|
+
// While a question is open, Esc belongs to the dialog: the shortcut steps aside (it
|
|
159
|
+
// would otherwise take the key first and the dialog would never close).
|
|
160
|
+
const asking = useCmsConfirmQuestion()
|
|
161
|
+
const confirm = useCmsConfirm()
|
|
162
|
+
defineShortcuts(computed(() => (asking.value ? {} : { escape: { usingInput: false, handler: () => { if (current.value) close() } } })))
|
|
163
|
+
|
|
164
|
+
// The panel's width: drag its edge (or use the arrow keys on it); remembered.
|
|
165
|
+
const PEEK_MIN = 320
|
|
166
|
+
// The library keeps room for a few columns of files and its filters.
|
|
167
|
+
const LIST_MIN = 560
|
|
168
|
+
const editorEl = ref<HTMLElement | null>(null)
|
|
169
|
+
const peekMax = () => Math.max(PEEK_MIN, Math.min(Math.round(window.innerWidth * 0.6), (editorEl.value?.clientWidth ?? window.innerWidth) - LIST_MIN))
|
|
170
|
+
const peekMaxNow = ref(720)
|
|
171
|
+
const peekWidth = ref(416)
|
|
172
|
+
onMounted(() => {
|
|
173
|
+
try {
|
|
174
|
+
const saved = Number(localStorage.getItem('cms-peek-width'))
|
|
175
|
+
if (saved) peekWidth.value = Math.min(Math.max(saved, PEEK_MIN), peekMax())
|
|
176
|
+
}
|
|
177
|
+
catch { /* storage blocked: the default width */ }
|
|
178
|
+
peekMaxNow.value = peekMax()
|
|
179
|
+
// A narrower window: the panel gives way (without forgetting the width chosen).
|
|
180
|
+
window.addEventListener('resize', fitPeek)
|
|
181
|
+
})
|
|
182
|
+
onBeforeUnmount(() => window.removeEventListener('resize', fitPeek))
|
|
183
|
+
function fitPeek() {
|
|
184
|
+
peekMaxNow.value = peekMax()
|
|
185
|
+
if (peekWidth.value > peekMaxNow.value) peekWidth.value = peekMaxNow.value
|
|
186
|
+
}
|
|
187
|
+
function setPeekWidth(px: number) {
|
|
188
|
+
peekMaxNow.value = peekMax()
|
|
189
|
+
peekWidth.value = Math.round(Math.min(Math.max(px, PEEK_MIN), peekMaxNow.value))
|
|
190
|
+
try {
|
|
191
|
+
localStorage.setItem('cms-peek-width', String(peekWidth.value))
|
|
192
|
+
}
|
|
193
|
+
catch { /* storage blocked: for this visit only */ }
|
|
194
|
+
}
|
|
195
|
+
function startResize(e: PointerEvent) {
|
|
196
|
+
const startX = e.clientX
|
|
197
|
+
const startW = peekWidth.value
|
|
198
|
+
const el = e.currentTarget as HTMLElement
|
|
199
|
+
el.setPointerCapture(e.pointerId)
|
|
200
|
+
document.documentElement.classList.add('cms-resizing')
|
|
201
|
+
const move = (ev: PointerEvent) => setPeekWidth(startW + (startX - ev.clientX))
|
|
202
|
+
const up = () => {
|
|
203
|
+
el.removeEventListener('pointermove', move)
|
|
204
|
+
el.removeEventListener('pointerup', up)
|
|
205
|
+
document.documentElement.classList.remove('cms-resizing')
|
|
206
|
+
}
|
|
207
|
+
el.addEventListener('pointermove', move)
|
|
208
|
+
el.addEventListener('pointerup', up)
|
|
209
|
+
}
|
|
210
|
+
function resizeByKey(e: KeyboardEvent) {
|
|
211
|
+
if (e.key === 'ArrowLeft') setPeekWidth(peekWidth.value + 32)
|
|
212
|
+
else if (e.key === 'ArrowRight') setPeekWidth(peekWidth.value - 32)
|
|
213
|
+
else return
|
|
214
|
+
e.preventDefault()
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Where a file is used, named as the sidebar names the collections.
|
|
218
|
+
const collectionLabel = (name: string) => {
|
|
219
|
+
const e = (graph.value ?? []).find((x: any) => x.name === name)
|
|
220
|
+
return e ? (tl(e.labelSingular) || tl(e.label) || name) : name
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Phones: the panel replaces the grid (a page of its own); wide screens: side by side.
|
|
224
|
+
const wide = ref(true)
|
|
225
|
+
onMounted(() => {
|
|
226
|
+
const mq = window.matchMedia('(min-width: 1024px)')
|
|
227
|
+
wide.value = mq.matches
|
|
228
|
+
mq.addEventListener('change', (e) => { wide.value = e.matches })
|
|
229
|
+
})
|
|
230
|
+
// Messages ("Saved", "Link copied") appear bottom right — where the panel's buttons
|
|
231
|
+
// are. While it is open they move beside it (wide) or above its buttons (phones).
|
|
232
|
+
watchEffect(() => {
|
|
233
|
+
if (import.meta.server) return
|
|
234
|
+
const root = document.documentElement.style
|
|
235
|
+
if (current.value) root.setProperty('--cms-toast-right', wide.value ? `${peekWidth.value + 16}px` : '1rem')
|
|
236
|
+
else root.removeProperty('--cms-toast-right')
|
|
237
|
+
})
|
|
238
|
+
onBeforeUnmount(() => document.documentElement.style.removeProperty('--cms-toast-right'))
|
|
239
|
+
/** Arrow keys move the focal point (5 %, with Shift 1 %); Enter or Space puts it in the middle; Backspace clears it. */
|
|
240
|
+
function focalKey(e: KeyboardEvent) {
|
|
241
|
+
const step = e.shiftKey ? 1 : 5
|
|
242
|
+
const at = draft.focal ?? { x: 50, y: 50 }
|
|
243
|
+
const clamp = (n: number) => Math.min(100, Math.max(0, n))
|
|
244
|
+
if (e.key === 'ArrowLeft') draft.focal = { x: clamp(at.x - step), y: at.y }
|
|
245
|
+
else if (e.key === 'ArrowRight') draft.focal = { x: clamp(at.x + step), y: at.y }
|
|
246
|
+
else if (e.key === 'ArrowUp') draft.focal = { x: at.x, y: clamp(at.y - step) }
|
|
247
|
+
else if (e.key === 'ArrowDown') draft.focal = { x: at.x, y: clamp(at.y + step) }
|
|
248
|
+
else if ((e.key === 'Enter' || e.key === ' ') && !draft.focal) draft.focal = { x: 50, y: 50 }
|
|
249
|
+
else if (e.key === 'Backspace' || e.key === 'Delete') draft.focal = null
|
|
250
|
+
else return
|
|
251
|
+
e.preventDefault()
|
|
252
|
+
}
|
|
253
|
+
function setFocal(e: MouseEvent) {
|
|
254
|
+
const box = (e.currentTarget as HTMLElement).getBoundingClientRect()
|
|
255
|
+
draft.focal = { x: Math.round(((e.clientX - box.left) / box.width) * 100), y: Math.round(((e.clientY - box.top) / box.height) * 100) }
|
|
256
|
+
}
|
|
257
|
+
async function save(quiet = false) {
|
|
258
|
+
if (!current.value) return
|
|
259
|
+
saving.value = true
|
|
260
|
+
try {
|
|
261
|
+
const url: string = `/api/cms/_media/${current.value.id}`
|
|
262
|
+
const updated = await $fetch<any>(url, {
|
|
263
|
+
method: 'PATCH', body: { alt: draft.alt, altLocales: draft.altLocales, folder: draft.folder, focal: draft.focal, keep: true },
|
|
264
|
+
})
|
|
265
|
+
items.value = items.value.map((m) => (m.id === updated.id ? updated : m))
|
|
266
|
+
if (current.value?.id === updated.id) current.value = updated
|
|
267
|
+
// A new folder gets its tab right away.
|
|
268
|
+
if (updated.folder && !folders.value.includes(updated.folder)) folders.value = [...folders.value, updated.folder].sort((a, b) => a.localeCompare(b))
|
|
269
|
+
// Switching files saves the one left behind: say so, by name, so it is never a surprise.
|
|
270
|
+
toast.add({
|
|
271
|
+
title: quiet ? t('media.autoSaved', { name: updated.name || updated.key?.split('/').pop() || '' }) : t('editor.saved'),
|
|
272
|
+
color: 'success', icon: 'i-lucide-check',
|
|
273
|
+
})
|
|
274
|
+
}
|
|
275
|
+
catch (err: any) {
|
|
276
|
+
toast.add({ title: t('editor.saveFailed'), description: cmsRequestError(err, t as any), color: 'error', icon: 'i-lucide-x' })
|
|
277
|
+
}
|
|
278
|
+
finally {
|
|
279
|
+
saving.value = false
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async function remove() {
|
|
283
|
+
if (!current.value) return
|
|
284
|
+
const ok = await confirm({
|
|
285
|
+
title: t('media.deleteTitle', { name: current.value.name || current.value.key.split('/').pop() }), description: t('media.deleteConfirm'),
|
|
286
|
+
confirmLabel: t('common.delete'), color: 'error',
|
|
287
|
+
})
|
|
288
|
+
if (!ok || !current.value) return
|
|
289
|
+
deleting.value = true
|
|
290
|
+
try {
|
|
291
|
+
const url: string = `/api/cms/_media/${current.value.id}`
|
|
292
|
+
await $fetch(url, { method: 'DELETE' })
|
|
293
|
+
toast.add({ title: t('list.deleted'), color: 'success', icon: 'i-lucide-check' })
|
|
294
|
+
current.value = null
|
|
295
|
+
const { file: _file, ...rest } = route.query
|
|
296
|
+
router.replace({ query: rest })
|
|
297
|
+
load()
|
|
298
|
+
}
|
|
299
|
+
catch (err: any) {
|
|
300
|
+
// Still used somewhere (it may have been put on a page since this panel loaded): say where.
|
|
301
|
+
if (err?.statusCode === 409) {
|
|
302
|
+
const found = (await cmsFetch<{ usage: any[] }>(`/api/cms/_media/${current.value!.id}/usage`).catch(() => ({ usage: [] }))).usage
|
|
303
|
+
usage.value = found
|
|
304
|
+
toast.add({ ...cmsDeleteFailure({ data: { data: { code: 'in_use', usedBy: found } } }, t as any), color: 'error', icon: 'i-lucide-x' })
|
|
305
|
+
}
|
|
306
|
+
else toast.add({ title: t('list.deleteFailed'), description: cmsRequestError(err, t as any), color: 'error', icon: 'i-lucide-x' })
|
|
307
|
+
}
|
|
308
|
+
finally {
|
|
309
|
+
deleting.value = false
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
async function copyUrl() {
|
|
313
|
+
try {
|
|
314
|
+
await navigator.clipboard.writeText(new URL(current.value.url, location.origin).toString())
|
|
315
|
+
toast.add({ title: t('media.urlCopied'), color: 'success', icon: 'i-lucide-check' })
|
|
316
|
+
}
|
|
317
|
+
catch { /* clipboard blocked */ }
|
|
318
|
+
}
|
|
319
|
+
</script>
|
|
320
|
+
|
|
321
|
+
<template>
|
|
322
|
+
<CmsPage flush :breadcrumbs="[{ label: t('nav.home'), to: '/admin' }, { label: t('media.libraryTitle') }]">
|
|
323
|
+
<template #actions>
|
|
324
|
+
<input ref="fileInput" type="file" multiple class="hidden" accept="image/*,video/*,audio/*,application/pdf" @change="(e: any) => { upload(e.target.files); e.target.value = '' }">
|
|
325
|
+
<UButton icon="i-lucide-upload" :loading="uploading > 0" @click="fileInput?.click()">{{ t('media.upload') }}</UButton>
|
|
326
|
+
</template>
|
|
327
|
+
|
|
328
|
+
<div ref="editorEl" class="cms-editor" :class="current ? 'cms-editor--peek' : 'cms-editor--no-aside'" :style="{ '--cms-peek-w': `${peekWidth}px` }">
|
|
329
|
+
<!-- the library: stays usable while a file is open beside it -->
|
|
330
|
+
<div
|
|
331
|
+
v-show="!(current && !wide)" class="cms-editor__main relative"
|
|
332
|
+
@dragenter.prevent="dragging = true" @dragover.prevent="dragging = true"
|
|
333
|
+
@dragleave.self="dragging = false" @drop.prevent="onDrop"
|
|
334
|
+
>
|
|
335
|
+
<header class="mb-6 flex items-baseline gap-3">
|
|
336
|
+
<h1 class="cms-display text-[1.75rem] leading-tight text-highlighted">{{ t('media.libraryTitle') }}</h1>
|
|
337
|
+
<span v-if="total" class="text-2xl font-semibold text-dimmed tabular-nums">{{ formatNumber(total) }}</span>
|
|
338
|
+
</header>
|
|
339
|
+
<div class="flex flex-wrap items-center justify-between gap-3 mb-4">
|
|
340
|
+
<UTabs v-model="folder" :items="folderTabs" :content="false" variant="link" size="sm" :ui="{ list: 'border-0 gap-4 flex-wrap', trigger: 'px-0' }" />
|
|
341
|
+
<div class="flex items-center gap-2 w-full sm:w-auto">
|
|
342
|
+
<USelect
|
|
343
|
+
v-model="kind" size="sm" variant="ghost" class="w-36"
|
|
344
|
+
:items="[{ label: t('media.kindAll'), value: 'all' }, { label: t('media.kindImages'), value: 'image/*' }, { label: t('media.kindVideo'), value: 'video/*' }, { label: t('media.kindAudio'), value: 'audio/*' }, { label: t('media.kindPdf'), value: 'application/pdf' }]"
|
|
345
|
+
:aria-label="t('media.kindAll')"
|
|
346
|
+
/>
|
|
347
|
+
<UInput v-model="q" icon="i-lucide-search" size="sm" variant="ghost" class="w-full sm:w-56" :placeholder="t('media.searchPlaceholder')" :aria-label="t('media.searchPlaceholder')" />
|
|
348
|
+
</div>
|
|
349
|
+
</div>
|
|
350
|
+
|
|
351
|
+
<div
|
|
352
|
+
v-if="dragging" class="absolute inset-0 z-20 grid place-items-center rounded-(--ui-radius) border-2 border-dashed border-primary bg-default/85"
|
|
353
|
+
aria-hidden="true"
|
|
354
|
+
>
|
|
355
|
+
<p class="text-sm font-medium text-highlighted">{{ t('media.dropHere') }}</p>
|
|
356
|
+
</div>
|
|
357
|
+
|
|
358
|
+
<ul v-if="!loaded" class="cms-media-grid" aria-busy="true">
|
|
359
|
+
<li v-for="n in 8" :key="n"><USkeleton class="aspect-square w-full rounded-(--ui-radius)" /></li>
|
|
360
|
+
</ul>
|
|
361
|
+
<CmsEmptyState
|
|
362
|
+
v-else-if="!items.length && !loading" icon="i-lucide-images" character="media"
|
|
363
|
+
:variant="q || folder !== 'all' || kind !== 'all' ? 'no-results' : 'first-use'"
|
|
364
|
+
:title="q || folder !== 'all' || kind !== 'all' ? t('media.noMatches') : t('media.empty')"
|
|
365
|
+
:description="q || folder !== 'all' || kind !== 'all' ? t('media.noMatchesHint') : coarse ? t('media.dropTouchHint') : t('media.dropHint')"
|
|
366
|
+
>
|
|
367
|
+
<template v-if="q || folder !== 'all' || kind !== 'all'" #actions>
|
|
368
|
+
<UButton color="neutral" variant="outline" icon="i-lucide-x" @click="q = ''; folder = 'all'; kind = 'all'">{{ t('media.clearFilters') }}</UButton>
|
|
369
|
+
</template>
|
|
370
|
+
</CmsEmptyState>
|
|
371
|
+
<ul v-else class="cms-media-grid">
|
|
372
|
+
<li v-for="m in items" :key="m.id">
|
|
373
|
+
<button
|
|
374
|
+
type="button" class="group block w-full text-left" :aria-label="t('media.openFile', { name: m.name || m.key })"
|
|
375
|
+
:aria-current="current?.id === m.id ? 'true' : undefined" @click="open(m)"
|
|
376
|
+
>
|
|
377
|
+
<span
|
|
378
|
+
class="block aspect-square overflow-hidden rounded-(--ui-radius) border bg-elevated transition-shadow"
|
|
379
|
+
:class="current?.id === m.id ? 'border-transparent ring-2 ring-(--ui-primary) ring-offset-2 ring-offset-(--ui-bg)' : 'border-default'"
|
|
380
|
+
>
|
|
381
|
+
<CmsMediaThumb :media="m" class="transition-transform group-hover:scale-[1.02]" />
|
|
382
|
+
</span>
|
|
383
|
+
<span class="mt-1.5 block truncate text-xs" :class="current?.id === m.id ? 'text-highlighted font-medium' : 'text-default'">{{ m.name || m.key.split('/').pop() }}</span>
|
|
384
|
+
<span class="block truncate text-xs text-dimmed">{{ m.folder || '' }}<template v-if="m.folder && !m.alt"> · </template><template v-if="!m.alt && isImage(m)">{{ t('media.noAlt') }}</template></span>
|
|
385
|
+
</button>
|
|
386
|
+
</li>
|
|
387
|
+
</ul>
|
|
388
|
+
<div v-if="items.length < total" class="mt-6 flex justify-center">
|
|
389
|
+
<UButton color="neutral" variant="outline" :loading="loading" @click="page++; load(false)">{{ t('media.loadMore') }}</UButton>
|
|
390
|
+
</div>
|
|
391
|
+
</div>
|
|
392
|
+
|
|
393
|
+
<!-- the open file: docked beside the library, a page of its own on phones -->
|
|
394
|
+
<aside v-if="current" class="cms-editor__aside cms-peek" :aria-label="current.name || t('media.file')">
|
|
395
|
+
<!-- drag to resize; arrow keys too; a double-click resets -->
|
|
396
|
+
<div
|
|
397
|
+
v-if="wide" class="cms-peek__resize" role="separator" aria-orientation="vertical" tabindex="0"
|
|
398
|
+
:aria-label="t('media.resizePanel')" :aria-valuenow="peekWidth" :aria-valuemin="PEEK_MIN" :aria-valuemax="peekMaxNow"
|
|
399
|
+
@pointerdown.prevent="startResize" @keydown="resizeByKey" @dblclick="setPeekWidth(416)"
|
|
400
|
+
/>
|
|
401
|
+
<div class="cms-peek__inner">
|
|
402
|
+
<header class="cms-peek__head">
|
|
403
|
+
<UButton
|
|
404
|
+
v-if="!wide" color="neutral" variant="ghost" icon="i-lucide-chevron-left" class="-ml-2" @click="close"
|
|
405
|
+
>{{ t('media.libraryTitle') }}</UButton>
|
|
406
|
+
<h2 v-else class="min-w-0 truncate text-sm font-medium text-highlighted">{{ current.name || t('media.file') }}</h2>
|
|
407
|
+
<div class="flex items-center gap-1 shrink-0">
|
|
408
|
+
<UTooltip :text="t('media.copyUrl')">
|
|
409
|
+
<UButton color="neutral" variant="ghost" icon="i-lucide-link" :aria-label="t('media.copyUrl')" @click="copyUrl" />
|
|
410
|
+
</UTooltip>
|
|
411
|
+
<UTooltip :text="t('media.openOriginal')">
|
|
412
|
+
<UButton :to="current.url" target="_blank" rel="noopener" color="neutral" variant="ghost" icon="i-lucide-arrow-up-right" :aria-label="t('media.openOriginal')" />
|
|
413
|
+
</UTooltip>
|
|
414
|
+
<UTooltip v-if="wide" :text="t('common.close')" :kbds="['esc']">
|
|
415
|
+
<UButton color="neutral" variant="ghost" icon="i-lucide-x" :aria-label="t('common.close')" @click="close" />
|
|
416
|
+
</UTooltip>
|
|
417
|
+
</div>
|
|
418
|
+
</header>
|
|
419
|
+
|
|
420
|
+
<div class="cms-peek__body space-y-6">
|
|
421
|
+
<h2 v-if="!wide" class="cms-display text-xl text-highlighted break-words">{{ current.name || t('media.file') }}</h2>
|
|
422
|
+
<div v-if="isImage(current)" class="space-y-1.5">
|
|
423
|
+
<!-- the focal point: click or tap the picture, or focus it and use the arrow keys -->
|
|
424
|
+
<div
|
|
425
|
+
class="relative cursor-crosshair overflow-hidden rounded-(--ui-radius) border border-default bg-elevated focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--ui-primary)"
|
|
426
|
+
role="group" tabindex="0" :aria-label="t('media.focalLabel')" aria-describedby="cms-focal-help"
|
|
427
|
+
@click="setFocal" @keydown="focalKey"
|
|
428
|
+
>
|
|
429
|
+
<img :src="cmsThumbUrl(current, 960)" :alt="current.alt ?? ''" class="block w-full max-h-[22rem] object-contain mx-auto" @error="(e: Event) => cmsThumbFallback(e, current.url)">
|
|
430
|
+
<span
|
|
431
|
+
v-if="draft.focal" class="pointer-events-none absolute size-6 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow ring-2 ring-black/40"
|
|
432
|
+
:style="{ left: `${draft.focal.x}%`, top: `${draft.focal.y}%` }" aria-hidden="true"
|
|
433
|
+
/>
|
|
434
|
+
</div>
|
|
435
|
+
<p id="cms-focal-help" class="text-xs text-muted" aria-live="polite">
|
|
436
|
+
{{ draft.focal ? t('media.focalSet', { x: draft.focal.x, y: draft.focal.y }) : t('media.focalHint') }}
|
|
437
|
+
<span class="max-sm:hidden"> {{ t('media.focalKeys') }}</span>
|
|
438
|
+
<UButton v-if="draft.focal" color="neutral" variant="link" size="xs" class="px-1" @click="draft.focal = null">{{ t('media.focalClear') }}</UButton>
|
|
439
|
+
</p>
|
|
440
|
+
</div>
|
|
441
|
+
<!-- a video or a sound: played right here -->
|
|
442
|
+
<div v-else class="overflow-hidden rounded-(--ui-radius) border border-default bg-elevated">
|
|
443
|
+
<CmsMediaPreview :media="current" />
|
|
444
|
+
</div>
|
|
445
|
+
|
|
446
|
+
<section v-if="isImage(current)" class="space-y-4">
|
|
447
|
+
<UFormField :label="locales ? `${t('media.altLabel')} (${langLabel(locales.default)})` : t('media.altLabel')" :help="t('media.altPlaceholder')">
|
|
448
|
+
<UTextarea v-model="draft.alt" :rows="2" autoresize class="w-full" />
|
|
449
|
+
</UFormField>
|
|
450
|
+
<UFormField v-for="code in otherLangs" :key="code" :label="`${t('media.altLabel')} (${langLabel(code)})`">
|
|
451
|
+
<UTextarea v-model="draft.altLocales[code]" :rows="2" autoresize class="w-full" :placeholder="draft.alt" />
|
|
452
|
+
</UFormField>
|
|
453
|
+
</section>
|
|
454
|
+
<UFormField :label="t('media.folder')" :help="t('media.folderHint')">
|
|
455
|
+
<UInput v-model="draft.folder" list="cms-media-folders" icon="i-lucide-folder" class="w-full" />
|
|
456
|
+
<datalist id="cms-media-folders"><option v-for="f in folders" :key="f" :value="f" /></datalist>
|
|
457
|
+
</UFormField>
|
|
458
|
+
|
|
459
|
+
<dl class="space-y-2 text-sm border-t border-default pt-5">
|
|
460
|
+
<div class="flex gap-3"><dt class="w-24 shrink-0 text-muted">{{ t('media.type') }}</dt><dd class="min-w-0 truncate">{{ current.mime }}</dd></div>
|
|
461
|
+
<div class="flex gap-3"><dt class="w-24 shrink-0 text-muted">{{ t('media.size') }}</dt><dd class="tabular-nums">{{ sizeLabel(current.size) }}<template v-if="current.width"> · {{ current.width }} × {{ current.height }}</template></dd></div>
|
|
462
|
+
<div class="flex gap-3"><dt class="w-24 shrink-0 text-muted">{{ t('media.uploadedAt') }}</dt><dd>{{ formatDate(current.createdAt) }}</dd></div>
|
|
463
|
+
</dl>
|
|
464
|
+
|
|
465
|
+
<section class="border-t border-default pt-5">
|
|
466
|
+
<h3 class="text-sm font-medium text-highlighted mb-2">{{ t('media.usedIn') }}</h3>
|
|
467
|
+
<p v-if="usage === null" class="text-sm text-muted">…</p>
|
|
468
|
+
<p v-else-if="!usage.length" class="text-sm text-muted">{{ t('media.unused') }}</p>
|
|
469
|
+
<ul v-else class="-mx-2">
|
|
470
|
+
<li v-for="u in usage" :key="`${u.entity}:${u.id}:${u.locale ?? ''}`">
|
|
471
|
+
<NuxtLink :to="`/admin/${u.entity}/${u.id}${u.locale ? `?locale=${u.locale}` : ''}`" class="flex items-center justify-between gap-3 rounded-md px-2 py-1.5 text-sm hover:bg-elevated/60">
|
|
472
|
+
<span class="truncate text-highlighted">{{ u.title || t('common.untitled') }}</span>
|
|
473
|
+
<span class="shrink-0 text-xs text-muted">{{ collectionLabel(u.entity) }}<template v-if="u.locale"> · {{ u.locale.toUpperCase() }}</template></span>
|
|
474
|
+
</NuxtLink>
|
|
475
|
+
</li>
|
|
476
|
+
</ul>
|
|
477
|
+
</section>
|
|
478
|
+
</div>
|
|
479
|
+
|
|
480
|
+
<footer class="cms-peek__foot">
|
|
481
|
+
<UButton
|
|
482
|
+
color="error" variant="ghost" icon="i-lucide-trash-2" :loading="deleting" :disabled="!!usage?.length"
|
|
483
|
+
:title="usage?.length ? t('media.inUse') : undefined" @click="remove"
|
|
484
|
+
>{{ t('common.delete') }}</UButton>
|
|
485
|
+
<div class="flex items-center gap-3">
|
|
486
|
+
<span v-if="dirty" class="text-xs cms-unsaved">{{ t('editor.unsaved') }}</span>
|
|
487
|
+
<UButton :loading="saving" :disabled="!dirty" @click="save()">{{ t('common.save') }}</UButton>
|
|
488
|
+
</div>
|
|
489
|
+
</footer>
|
|
490
|
+
</div>
|
|
491
|
+
</aside>
|
|
492
|
+
</div>
|
|
493
|
+
</CmsPage>
|
|
494
|
+
</template>
|