tinyzoo 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +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 +98 -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 +393 -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/cmsTiming.ts +14 -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 +228 -0
- package/server/utils/cmsWebhooks.ts +104 -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,63 @@
|
|
|
1
|
+
// What the admin knows about a library file: its kind, a small copy to draw in a grid, and
|
|
2
|
+
// uploading several files in turns (the server takes a limited number a minute).
|
|
3
|
+
|
|
4
|
+
export type CmsMediaKind = 'image' | 'video' | 'audio' | 'pdf' | 'file'
|
|
5
|
+
|
|
6
|
+
export function cmsMediaKind(m: { mime?: string | null } | null | undefined): CmsMediaKind {
|
|
7
|
+
const mime = String(m?.mime ?? '')
|
|
8
|
+
if (mime.startsWith('image/')) return 'image'
|
|
9
|
+
if (mime.startsWith('video/')) return 'video'
|
|
10
|
+
if (mime.startsWith('audio/')) return 'audio'
|
|
11
|
+
if (mime === 'application/pdf') return 'pdf'
|
|
12
|
+
return 'file'
|
|
13
|
+
}
|
|
14
|
+
export const cmsMediaIcon = (m: { mime?: string | null } | null | undefined) => ({
|
|
15
|
+
image: 'i-lucide-image', video: 'i-lucide-film', audio: 'i-lucide-music', pdf: 'i-lucide-file-text', file: 'i-lucide-file',
|
|
16
|
+
})[cmsMediaKind(m)]
|
|
17
|
+
|
|
18
|
+
// The kinds the server makes smaller WebP copies of (server/utils/cmsImageSizes.ts); a GIF
|
|
19
|
+
// (it would stop moving) or an SVG has only its original.
|
|
20
|
+
const RESIZABLE = new Set(['image/jpeg', 'image/png', 'image/webp', 'image/avif'])
|
|
21
|
+
const WIDTHS = [320, 640, 960, 1280, 1920]
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* What to put in an `<img>` that shows the file small: the matching smaller copy
|
|
25
|
+
* (`/api/cms/_media/img/<id>/320.webp`, a few kB) when there is one, else the original —
|
|
26
|
+
* a picture already that small, or a kind with no copies. A grid of 24 tiles that loads the
|
|
27
|
+
* originals is 10 MB; this is a few hundred kB.
|
|
28
|
+
*/
|
|
29
|
+
export function cmsThumbUrl(m: { id?: string; url: string; mime?: string | null; width?: number | null } | null | undefined, width = 320): string {
|
|
30
|
+
if (!m) return ''
|
|
31
|
+
if (!m.id || !RESIZABLE.has(String(m.mime)) || !WIDTHS.includes(width)) return m.url
|
|
32
|
+
if (m.width && m.width <= width) return m.url
|
|
33
|
+
return `/api/cms/_media/img/${m.id}/${width}.webp`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `@error` of a thumbnail: if its smaller copy is not there (yet), show the original, once. */
|
|
37
|
+
export function cmsThumbFallback(e: Event, original: string) {
|
|
38
|
+
const img = e.target as HTMLImageElement
|
|
39
|
+
if (img.dataset.fallback) return
|
|
40
|
+
img.dataset.fallback = '1'
|
|
41
|
+
img.src = original
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Upload one file. When the server says "too many uploads" (429) it is not a failure of the
|
|
46
|
+
* file: wait the time the server names (Retry-After, else a few seconds) and try again, up to
|
|
47
|
+
* a couple of minutes. `onWait` says so once, so 60 files make one message, not 60 errors.
|
|
48
|
+
*/
|
|
49
|
+
export async function cmsUploadFile(form: FormData, { onWait, signal }: { onWait?: (seconds: number) => void; signal?: AbortSignal } = {}): Promise<any> {
|
|
50
|
+
for (let attempt = 0; ; attempt++) {
|
|
51
|
+
try {
|
|
52
|
+
return await $fetch('/api/cms/_media', { method: 'POST', body: form, signal })
|
|
53
|
+
}
|
|
54
|
+
catch (err: any) {
|
|
55
|
+
const status = err?.statusCode ?? err?.status ?? err?.response?.status
|
|
56
|
+
if (status !== 429 || attempt >= 12) throw err
|
|
57
|
+
const header = Number(err?.response?.headers?.get?.('retry-after'))
|
|
58
|
+
const seconds = Math.min(30, Math.max(3, Number.isFinite(header) && header > 0 ? header : 6 + attempt * 2))
|
|
59
|
+
onWait?.(seconds)
|
|
60
|
+
await new Promise((r) => setTimeout(r, seconds * 1000))
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// How an admin form is grouped, and which fields wait behind "+ Add …".
|
|
2
|
+
//
|
|
3
|
+
// A form reads as a few titled sections ("When?", "Where?") instead of one long
|
|
4
|
+
// column. The developer names them in `admin.sections`; without that, fields are
|
|
5
|
+
// grouped by kind once a form has enough of them to need it. Fields with `.group()`
|
|
6
|
+
// (e.g. "Search & sharing") fold away at the end.
|
|
7
|
+
|
|
8
|
+
export interface CmsFormFieldLike { key: string; type: string; optional?: boolean; meta?: Record<string, any> }
|
|
9
|
+
export interface CmsSectionConfig { label: unknown; icon?: string; description?: unknown; fields: string[]; columns?: 1 | 2 }
|
|
10
|
+
|
|
11
|
+
/** The kinds a field is grouped by when no sections are configured. */
|
|
12
|
+
export type CmsSectionKind = 'basics' | 'content' | 'when' | 'pictures' | 'links' | 'related'
|
|
13
|
+
const KIND_ORDER: CmsSectionKind[] = ['basics', 'content', 'when', 'pictures', 'links', 'related']
|
|
14
|
+
export const CMS_SECTION_ICONS: Record<CmsSectionKind, string> = {
|
|
15
|
+
basics: 'i-lucide-pencil-line',
|
|
16
|
+
content: 'i-lucide-align-left',
|
|
17
|
+
when: 'i-lucide-calendar',
|
|
18
|
+
pictures: 'i-lucide-image',
|
|
19
|
+
links: 'i-lucide-link',
|
|
20
|
+
related: 'i-lucide-layers',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CmsFormSectionView<F extends CmsFormFieldLike = CmsFormFieldLike> {
|
|
24
|
+
id: string
|
|
25
|
+
/** The configured heading; null with `kind` = a heading named after the kind; both null = no heading. */
|
|
26
|
+
label: unknown | null
|
|
27
|
+
kind: CmsSectionKind | null
|
|
28
|
+
icon: string | null
|
|
29
|
+
description: unknown | null
|
|
30
|
+
fields: F[]
|
|
31
|
+
columns: 1 | 2
|
|
32
|
+
/** A `.group()` of fields: folded away at the end of the form. */
|
|
33
|
+
folded: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function cmsSectionKind(f: CmsFormFieldLike): CmsSectionKind {
|
|
37
|
+
if (f.type === 'datetime') return 'when'
|
|
38
|
+
if (f.type === 'media' || f.type === 'gallery') return 'pictures'
|
|
39
|
+
if (f.type === 'relation') return 'related'
|
|
40
|
+
if (f.type === 'richtext' || f.type === 'blocks') return 'content'
|
|
41
|
+
if (f.type === 'text' && ['url', 'link', 'email'].includes(f.meta?.format)) return 'links'
|
|
42
|
+
return 'basics'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Below this many fields a form is short enough to need no headings. */
|
|
46
|
+
const AUTO_MIN_FIELDS = 6
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The sections of a form, in order: the configured ones (fields they list that are
|
|
50
|
+
* not in this form are skipped), then the rest grouped by kind, then the folded groups.
|
|
51
|
+
*/
|
|
52
|
+
export function cmsFormSections<F extends CmsFormFieldLike>(fields: F[], config?: CmsSectionConfig[] | null): CmsFormSectionView<F>[] {
|
|
53
|
+
const open = fields.filter((f) => !f.meta?.group)
|
|
54
|
+
const byKey = new Map(open.map((f) => [f.key, f]))
|
|
55
|
+
const out: CmsFormSectionView<F>[] = []
|
|
56
|
+
const placed = new Set<string>()
|
|
57
|
+
|
|
58
|
+
for (const [i, s] of (config ?? []).entries()) {
|
|
59
|
+
const own = s.fields.map((k) => byKey.get(k)).filter((f): f is F => !!f)
|
|
60
|
+
own.forEach((f) => placed.add(f.key))
|
|
61
|
+
if (!own.length) continue
|
|
62
|
+
out.push({
|
|
63
|
+
id: `s${i}`, label: s.label, kind: null, icon: s.icon ?? CMS_SECTION_ICONS[cmsSectionKind(own[0]!)],
|
|
64
|
+
description: s.description ?? null, fields: own, columns: s.columns ?? 1, folded: false,
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const rest = open.filter((f) => !placed.has(f.key))
|
|
69
|
+
if (rest.length) {
|
|
70
|
+
const titled = out.length > 0 || rest.length >= AUTO_MIN_FIELDS
|
|
71
|
+
const buckets = new Map<CmsSectionKind, F[]>()
|
|
72
|
+
for (const f of rest) {
|
|
73
|
+
const k = titled ? cmsSectionKind(f) : 'basics'
|
|
74
|
+
if (!buckets.has(k)) buckets.set(k, [])
|
|
75
|
+
buckets.get(k)!.push(f)
|
|
76
|
+
}
|
|
77
|
+
const kinds = KIND_ORDER.filter((k) => buckets.has(k))
|
|
78
|
+
const headed = titled && (out.length > 0 || kinds.length > 1)
|
|
79
|
+
for (const k of kinds) {
|
|
80
|
+
out.push({
|
|
81
|
+
id: `k-${k}`, label: null, kind: headed ? k : null, icon: headed ? CMS_SECTION_ICONS[k] : null,
|
|
82
|
+
description: null, fields: buckets.get(k)!, columns: 1, folded: false,
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const groups = new Map<string, F[]>()
|
|
88
|
+
for (const f of fields) {
|
|
89
|
+
if (!f.meta?.group) continue
|
|
90
|
+
const id = JSON.stringify(f.meta.group)
|
|
91
|
+
if (!groups.has(id)) groups.set(id, [])
|
|
92
|
+
groups.get(id)!.push(f)
|
|
93
|
+
}
|
|
94
|
+
let g = 0
|
|
95
|
+
for (const own of groups.values()) {
|
|
96
|
+
out.push({
|
|
97
|
+
id: `g${g++}`, label: own[0]!.meta!.group, kind: null, icon: 'i-lucide-sliders-horizontal',
|
|
98
|
+
description: null, fields: own, columns: 1, folded: true,
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
return out
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The sections are many enough for a section menu beside the form. */
|
|
105
|
+
export function cmsNeedsSectionMenu(sections: CmsFormSectionView[]): boolean {
|
|
106
|
+
const headed = sections.filter((s) => s.label != null || s.kind != null)
|
|
107
|
+
return headed.length >= 4 && sections.reduce((n, s) => n + s.fields.length, 0) >= 10
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const cmsIsEmpty = (v: unknown) => v === null || v === undefined || v === '' || (Array.isArray(v) && v.length === 0)
|
|
111
|
+
|
|
112
|
+
// Never put behind "+ Add": a switch always has a value, and text bodies are the content.
|
|
113
|
+
const ALWAYS_SHOWN = new Set(['boolean', 'richtext', 'blocks'])
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The fields of a section that wait behind "+ Add …": optional, still empty, never
|
|
117
|
+
* filled in this visit and without an error. A section always shows at least one field.
|
|
118
|
+
*/
|
|
119
|
+
export function cmsWaitingFields(
|
|
120
|
+
section: { fields: CmsFormFieldLike[] },
|
|
121
|
+
state: Record<string, unknown>,
|
|
122
|
+
seen: Set<string>,
|
|
123
|
+
errors: Record<string, unknown> = {},
|
|
124
|
+
): string[] {
|
|
125
|
+
const waiting = section.fields.filter((f) =>
|
|
126
|
+
f.optional && !ALWAYS_SHOWN.has(f.type) && cmsIsEmpty(state[f.key]) && !seen.has(f.key) && !errors[f.key])
|
|
127
|
+
if (waiting.length === section.fields.length) waiting.shift()
|
|
128
|
+
return waiting.map((f) => f.key)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** A field that fits half a row in a two-column section. */
|
|
132
|
+
export function cmsIsShortField(f: CmsFormFieldLike): boolean {
|
|
133
|
+
if (f.type === 'text') return !f.meta?.multiline
|
|
134
|
+
return f.type === 'number' || f.type === 'slug' || (f.type === 'relation' && f.meta?.kind !== 'many-to-many')
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The icon inside a field's control: the developer's, else one for the kind of value. */
|
|
138
|
+
export function cmsFieldIcon(f: CmsFormFieldLike): string | undefined {
|
|
139
|
+
if (f.meta?.icon) return f.meta.icon
|
|
140
|
+
if (f.type === 'datetime') return 'i-lucide-calendar'
|
|
141
|
+
if (f.type === 'relation') return 'i-lucide-search'
|
|
142
|
+
if (f.type === 'text') {
|
|
143
|
+
const format = f.meta?.format
|
|
144
|
+
if (format === 'email') return 'i-lucide-mail'
|
|
145
|
+
if (format === 'url' || format === 'link') return 'i-lucide-link'
|
|
146
|
+
if (format === 'path') return 'i-lucide-corner-down-right'
|
|
147
|
+
}
|
|
148
|
+
return undefined
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** A choice of a few options shows as buttons in the content column, a dropdown elsewhere. */
|
|
152
|
+
export function cmsSelectAsButtons(f: CmsFormFieldLike, placement: 'main' | 'sidebar' = 'main'): boolean {
|
|
153
|
+
return f.type === 'select' && placement === 'main' && ((f.meta?.options as unknown[] | undefined)?.length ?? 0) <= 5
|
|
154
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Wall-clock time in a named time zone <-> an instant. The admin shows and edits
|
|
2
|
+
// dates in its configured zone (cms.admin.timeZone), never the server's or the
|
|
3
|
+
// browser's, so "9:00" means 9:00 in Prague for every editor and every server.
|
|
4
|
+
|
|
5
|
+
function partsIn(ts: number, timeZone: string) {
|
|
6
|
+
const parts = new Intl.DateTimeFormat('en-US', {
|
|
7
|
+
timeZone, hourCycle: 'h23',
|
|
8
|
+
year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit',
|
|
9
|
+
}).formatToParts(new Date(ts))
|
|
10
|
+
const get = (type: string) => Number(parts.find((p) => p.type === type)?.value)
|
|
11
|
+
return { y: get('year'), mo: get('month'), d: get('day'), h: get('hour'), mi: get('minute'), s: get('second') }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** How far `timeZone` is ahead of UTC at instant `ts`, in ms (DST-aware). */
|
|
15
|
+
function offsetAt(ts: number, timeZone: string): number {
|
|
16
|
+
const p = partsIn(ts, timeZone)
|
|
17
|
+
return Date.UTC(p.y, p.mo - 1, p.d, p.h, p.mi, p.s) - Math.floor(ts / 1000) * 1000
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const pad = (n: number) => String(n).padStart(2, '0')
|
|
21
|
+
|
|
22
|
+
/** An instant → `YYYY-MM-DDTHH:mm` as the wall clock reads in `timeZone` (for <input type="datetime-local">). */
|
|
23
|
+
export function toZonedInput(value: string | number | Date | null | undefined, timeZone: string): string {
|
|
24
|
+
if (value === null || value === undefined || value === '') return ''
|
|
25
|
+
const ts = new Date(value).getTime()
|
|
26
|
+
if (Number.isNaN(ts)) return ''
|
|
27
|
+
const p = partsIn(ts, timeZone)
|
|
28
|
+
return `${p.y}-${pad(p.mo)}-${pad(p.d)}T${pad(p.h)}:${pad(p.mi)}`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** `YYYY-MM-DDTHH:mm` read as wall-clock time in `timeZone` → ISO instant (UTC). Empty → null. */
|
|
32
|
+
export function fromZonedInput(input: string | null | undefined, timeZone: string): string | null {
|
|
33
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(input ?? '')
|
|
34
|
+
if (!m) return null
|
|
35
|
+
const [, y, mo, d, h, mi] = m.map(Number) as unknown as [never, number, number, number, number, number]
|
|
36
|
+
const guess = Date.UTC(y, mo - 1, d, h, mi)
|
|
37
|
+
// Two passes settle the offset across a DST change.
|
|
38
|
+
let ts = guess - offsetAt(guess, timeZone)
|
|
39
|
+
ts = guess - offsetAt(ts, timeZone)
|
|
40
|
+
return new Date(ts).toISOString()
|
|
41
|
+
}
|