@sinnstack/ui 0.0.0-stage → 0.3.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/CHANGELOG.md +89 -0
- package/LICENSE +373 -0
- package/README.md +188 -2
- package/docs/blocks.md +373 -0
- package/docs/data.md +128 -0
- package/docs/finishes.md +165 -0
- package/docs/motion.md +166 -0
- package/docs/primitives.md +510 -0
- package/docs/seo.md +191 -0
- package/docs/tokens.md +122 -0
- package/package.json +132 -3
- package/scripts/check-contrast.mjs +180 -0
- package/src/blocks/BlockRenderer.astro +60 -0
- package/src/blocks/CTABanner.astro +121 -0
- package/src/blocks/CTAPair.astro +110 -0
- package/src/blocks/CardGrid.astro +167 -0
- package/src/blocks/ConsentEmbed.astro +125 -0
- package/src/blocks/ConsentManager.astro +147 -0
- package/src/blocks/ConsentScript.astro +47 -0
- package/src/blocks/ContactCard.astro +164 -0
- package/src/blocks/ContactForm.astro +224 -0
- package/src/blocks/ErrorPage.astro +242 -0
- package/src/blocks/FAQ.astro +135 -0
- package/src/blocks/FeatureGrid.astro +148 -0
- package/src/blocks/Hero.astro +171 -0
- package/src/blocks/HeroCarousel.astro +220 -0
- package/src/blocks/HighlightCards.astro +107 -0
- package/src/blocks/LocationHours.astro +311 -0
- package/src/blocks/LogoCloud.astro +135 -0
- package/src/blocks/MaintenancePage.astro +173 -0
- package/src/blocks/MediaText.astro +177 -0
- package/src/blocks/PageHeader.astro +126 -0
- package/src/blocks/ProseSection.astro +98 -0
- package/src/blocks/Reviews.astro +194 -0
- package/src/blocks/RichText.astro +58 -0
- package/src/blocks/StatsBand.astro +117 -0
- package/src/blocks/Steps.astro +141 -0
- package/src/blocks/Testimonials.astro +144 -0
- package/src/blocks/Topbar.astro +158 -0
- package/src/blocks/cms/card-grid.ts +48 -0
- package/src/blocks/cms/consent.ts +16 -0
- package/src/blocks/cms/contact-card.ts +46 -0
- package/src/blocks/cms/contact-form.ts +37 -0
- package/src/blocks/cms/cta-banner.ts +27 -0
- package/src/blocks/cms/cta-pair.ts +30 -0
- package/src/blocks/cms/data-base.ts +5 -0
- package/src/blocks/cms/data.ts +257 -0
- package/src/blocks/cms/faq.ts +38 -0
- package/src/blocks/cms/feature-grid.ts +47 -0
- package/src/blocks/cms/fixtures.ts +591 -0
- package/src/blocks/cms/hero-carousel.ts +36 -0
- package/src/blocks/cms/hero.ts +33 -0
- package/src/blocks/cms/highlight-cards.ts +41 -0
- package/src/blocks/cms/images.ts +37 -0
- package/src/blocks/cms/index.ts +59 -0
- package/src/blocks/cms/location-hours.ts +67 -0
- package/src/blocks/cms/logo-cloud.ts +36 -0
- package/src/blocks/cms/media-text.ts +26 -0
- package/src/blocks/cms/page-header.ts +27 -0
- package/src/blocks/cms/pages.ts +35 -0
- package/src/blocks/cms/prose-section.ts +25 -0
- package/src/blocks/cms/reviews.ts +50 -0
- package/src/blocks/cms/schema-dsl.ts +134 -0
- package/src/blocks/cms/schema.ts +794 -0
- package/src/blocks/cms/shared.ts +63 -0
- package/src/blocks/cms/stats-band.ts +35 -0
- package/src/blocks/cms/steps.ts +40 -0
- package/src/blocks/cms/testimonials.ts +46 -0
- package/src/blocks/cms/topbar.ts +27 -0
- package/src/blocks/cms/types.ts +27 -0
- package/src/blocks/consent.ts +14 -0
- package/src/blocks/icons.ts +47 -0
- package/src/blocks/index.ts +42 -0
- package/src/blocks/internal/Actions.astro +35 -0
- package/src/blocks/internal/BlockHeader.astro +45 -0
- package/src/blocks/internal/BlockShell.astro +58 -0
- package/src/blocks/internal/CarouselScript.astro +7 -0
- package/src/blocks/internal/ConsentEmbedScript.astro +7 -0
- package/src/blocks/internal/ConsentManagerScript.astro +7 -0
- package/src/blocks/internal/HoursScript.astro +7 -0
- package/src/blocks/internal/Placeholder.astro +13 -0
- package/src/blocks/internal/RichTextNode.astro +133 -0
- package/src/blocks/internal/StandaloneDocument.astro +53 -0
- package/src/blocks/internal/consent.ts +96 -0
- package/src/blocks/internal/fields.ts +18 -0
- package/src/blocks/internal/registry-contract.ts +67 -0
- package/src/blocks/internal/reviews.ts +22 -0
- package/src/blocks/internal/slug.ts +12 -0
- package/src/blocks/internal/util.ts +23 -0
- package/src/blocks/lib/contact.ts +92 -0
- package/src/blocks/lib/error-pages.ts +119 -0
- package/src/blocks/lib/faq.ts +37 -0
- package/src/blocks/lib/hours.ts +201 -0
- package/src/blocks/lib/maintenance.ts +129 -0
- package/src/blocks/lib/markdown.ts +350 -0
- package/src/blocks/lib/rich-text.ts +132 -0
- package/src/blocks/registry.ts +79 -0
- package/src/blocks/scripts/carousel.ts +218 -0
- package/src/blocks/scripts/consent-embed.ts +105 -0
- package/src/blocks/scripts/consent-manager.ts +112 -0
- package/src/blocks/scripts/consent-store.ts +86 -0
- package/src/blocks/scripts/error-page.ts +71 -0
- package/src/blocks/scripts/hours.ts +107 -0
- package/src/blocks/scripts/maintenance.ts +109 -0
- package/src/blocks/styles/blocks.css +1320 -0
- package/src/blocks/styles/consent.css +102 -0
- package/src/blocks/styles/faq.css +28 -0
- package/src/blocks/styles/location.css +92 -0
- package/src/blocks/styles/prose-section.css +13 -0
- package/src/blocks/styles/quotes.css +123 -0
- package/src/blocks/styles/rich-text.css +14 -0
- package/src/blocks/types.ts +293 -0
- package/src/data/ChartAxis.astro +19 -0
- package/src/data/ChartContainer.astro +152 -0
- package/src/data/ChartLegend.astro +25 -0
- package/src/data/ChartSeries.astro +14 -0
- package/src/data/ChartTable.astro +17 -0
- package/src/data/ChartTooltip.astro +20 -0
- package/src/data/Sparkline.astro +55 -0
- package/src/data/cms.ts +130 -0
- package/src/data/index.ts +10 -0
- package/src/data/internal/scale.ts +107 -0
- package/src/data/lib/chart.ts +459 -0
- package/src/data/lib/render.ts +219 -0
- package/src/data/lib/sparkline.ts +117 -0
- package/src/data/schema.ts +65 -0
- package/src/data/scripts/chart.ts +324 -0
- package/src/data/styles/chart.css +392 -0
- package/src/finishes/aurora.css +75 -0
- package/src/finishes/autumn.css +87 -0
- package/src/finishes/blueprint.css +69 -0
- package/src/finishes/brutalist.css +55 -0
- package/src/finishes/clay.css +48 -0
- package/src/finishes/day-cycle.css +46 -0
- package/src/finishes/fog.css +71 -0
- package/src/finishes/glass.css +149 -0
- package/src/finishes/holographic.css +91 -0
- package/src/finishes/night.css +77 -0
- package/src/finishes/paper.css +58 -0
- package/src/finishes/polished-glass.css +159 -0
- package/src/finishes/rain.css +84 -0
- package/src/finishes/scripts/day-cycle.ts +30 -0
- package/src/finishes/scripts/holographic.ts +37 -0
- package/src/finishes/scripts/spotlight.ts +30 -0
- package/src/finishes/spotlight.css +41 -0
- package/src/finishes/spring.css +80 -0
- package/src/finishes/terminal.css +49 -0
- package/src/motion/Marquee.astro +90 -0
- package/src/motion/MotionProvider.astro +50 -0
- package/src/motion/PageTransitions.astro +61 -0
- package/src/motion/Parallax.astro +44 -0
- package/src/motion/ParallaxLayer.astro +31 -0
- package/src/motion/RevealOnScroll.astro +59 -0
- package/src/motion/SceneRegistry.astro +38 -0
- package/src/motion/ScrollScene.astro +81 -0
- package/src/motion/index.ts +12 -0
- package/src/motion/integration.ts +48 -0
- package/src/motion/runtime/page-transitions.ts +68 -0
- package/src/motion/runtime/runtime.ts +180 -0
- package/src/motion/runtime/scenes.ts +248 -0
- package/src/motion/runtime/types.ts +103 -0
- package/src/motion/styles/motion.css +332 -0
- package/src/motion/transitions.ts +74 -0
- package/src/motion/virtual.d.ts +4 -0
- package/src/primitives/Accordion.astro +129 -0
- package/src/primitives/Breadcrumbs.astro +50 -0
- package/src/primitives/BulletList.astro +69 -0
- package/src/primitives/Button.astro +73 -0
- package/src/primitives/ButtonGroup.astro +54 -0
- package/src/primitives/Callout.astro +137 -0
- package/src/primitives/Caption.astro +35 -0
- package/src/primitives/Card.astro +72 -0
- package/src/primitives/CardContent.astro +24 -0
- package/src/primitives/CardFooter.astro +36 -0
- package/src/primitives/CardHeader.astro +86 -0
- package/src/primitives/Checkbox.astro +38 -0
- package/src/primitives/ChoiceGroup.astro +23 -0
- package/src/primitives/Cluster.astro +49 -0
- package/src/primitives/Container.astro +44 -0
- package/src/primitives/DescriptionList.astro +83 -0
- package/src/primitives/Dialog.astro +38 -0
- package/src/primitives/Disclosure.astro +67 -0
- package/src/primitives/Divider.astro +93 -0
- package/src/primitives/Drawer.astro +33 -0
- package/src/primitives/Fieldset.astro +80 -0
- package/src/primitives/Flex.astro +64 -0
- package/src/primitives/FocusRing.astro +63 -0
- package/src/primitives/FocusTrap.astro +64 -0
- package/src/primitives/Footer.astro +155 -0
- package/src/primitives/Form.astro +68 -0
- package/src/primitives/FormDescription.astro +26 -0
- package/src/primitives/FormError.astro +106 -0
- package/src/primitives/FormField.astro +72 -0
- package/src/primitives/Grid.astro +64 -0
- package/src/primitives/Heading.astro +45 -0
- package/src/primitives/IconButton.astro +48 -0
- package/src/primitives/Image.astro +125 -0
- package/src/primitives/Input.astro +86 -0
- package/src/primitives/Label.astro +50 -0
- package/src/primitives/Link.astro +81 -0
- package/src/primitives/LinkButton.astro +66 -0
- package/src/primitives/List.astro +39 -0
- package/src/primitives/ListItem.astro +178 -0
- package/src/primitives/MediaObject.astro +66 -0
- package/src/primitives/MetricCard.astro +278 -0
- package/src/primitives/NavLink.astro +81 -0
- package/src/primitives/NavMenu.astro +109 -0
- package/src/primitives/Navbar.astro +197 -0
- package/src/primitives/Panel.astro +153 -0
- package/src/primitives/Picture.astro +167 -0
- package/src/primitives/Popover.astro +95 -0
- package/src/primitives/Prose.astro +45 -0
- package/src/primitives/Radio.astro +21 -0
- package/src/primitives/Rating.astro +135 -0
- package/src/primitives/ReducedMotion.astro +90 -0
- package/src/primitives/SegmentedControl.astro +132 -0
- package/src/primitives/Select.astro +109 -0
- package/src/primitives/Sheet.astro +45 -0
- package/src/primitives/SkipLink.astro +31 -0
- package/src/primitives/Slider.astro +186 -0
- package/src/primitives/Spacer.astro +35 -0
- package/src/primitives/Stack.astro +51 -0
- package/src/primitives/Surface.astro +70 -0
- package/src/primitives/Switch.astro +22 -0
- package/src/primitives/Table.astro +382 -0
- package/src/primitives/Tabs.astro +126 -0
- package/src/primitives/Text.astro +56 -0
- package/src/primitives/Textarea.astro +75 -0
- package/src/primitives/Thumbnail.astro +154 -0
- package/src/primitives/Toggle.astro +99 -0
- package/src/primitives/Tooltip.astro +50 -0
- package/src/primitives/VisuallyHidden.astro +29 -0
- package/src/primitives/index.ts +103 -0
- package/src/primitives/internal/AccordionScript.astro +7 -0
- package/src/primitives/internal/ChoiceField.astro +91 -0
- package/src/primitives/internal/FocusTrapScript.astro +8 -0
- package/src/primitives/internal/FormValidationScript.astro +10 -0
- package/src/primitives/internal/IndeterminateScript.astro +13 -0
- package/src/primitives/internal/ModalPanel.astro +114 -0
- package/src/primitives/internal/OverlayScript.astro +7 -0
- package/src/primitives/internal/ReducedMotionScript.astro +7 -0
- package/src/primitives/internal/SliderScript.astro +7 -0
- package/src/primitives/internal/SparklineScript.astro +7 -0
- package/src/primitives/internal/TableSortScript.astro +7 -0
- package/src/primitives/internal/TabsScript.astro +7 -0
- package/src/primitives/internal/TooltipScript.astro +7 -0
- package/src/primitives/internal/image-plan.ts +82 -0
- package/src/primitives/internal/image.ts +129 -0
- package/src/primitives/internal/slider.ts +170 -0
- package/src/primitives/lib/deprecate.ts +47 -0
- package/src/primitives/lib/focus-trap.ts +197 -0
- package/src/primitives/lib/focus.ts +60 -0
- package/src/primitives/lib/motion.ts +68 -0
- package/src/primitives/scripts/accordion.ts +123 -0
- package/src/primitives/scripts/form-validation.ts +225 -0
- package/src/primitives/scripts/overlay.ts +71 -0
- package/src/primitives/scripts/reduced-motion.ts +59 -0
- package/src/primitives/scripts/slider.ts +150 -0
- package/src/primitives/scripts/sparkline.ts +131 -0
- package/src/primitives/scripts/table-sort.ts +68 -0
- package/src/primitives/scripts/tabs.ts +151 -0
- package/src/primitives/scripts/tooltip.ts +28 -0
- package/src/primitives/styles/a11y.css +104 -0
- package/src/primitives/styles/accordion.css +53 -0
- package/src/primitives/styles/breadcrumbs.css +59 -0
- package/src/primitives/styles/bullet-list.css +89 -0
- package/src/primitives/styles/button.css +237 -0
- package/src/primitives/styles/choice.css +164 -0
- package/src/primitives/styles/cluster.css +24 -0
- package/src/primitives/styles/container.css +19 -0
- package/src/primitives/styles/data.css +849 -0
- package/src/primitives/styles/disclosure.css +140 -0
- package/src/primitives/styles/divider.css +50 -0
- package/src/primitives/styles/flex.css +42 -0
- package/src/primitives/styles/form.css +241 -0
- package/src/primitives/styles/grid.css +36 -0
- package/src/primitives/styles/media.css +247 -0
- package/src/primitives/styles/nav.css +792 -0
- package/src/primitives/styles/overlay.css +362 -0
- package/src/primitives/styles/prose.css +146 -0
- package/src/primitives/styles/scale.css +175 -0
- package/src/primitives/styles/segmented.css +165 -0
- package/src/primitives/styles/slider.css +170 -0
- package/src/primitives/styles/spacer.css +17 -0
- package/src/primitives/styles/stack.css +25 -0
- package/src/primitives/styles/surface.css +403 -0
- package/src/primitives/styles/tabs.css +223 -0
- package/src/primitives/styles/typography.css +144 -0
- package/src/primitives/styles/utilities.css +24 -0
- package/src/primitives/types.ts +385 -0
- package/src/primitives/utils.ts +254 -0
- package/src/seo/JSONLD.astro +35 -0
- package/src/seo/SEOHead.astro +47 -0
- package/src/seo/cms.ts +59 -0
- package/src/seo/index.ts +10 -0
- package/src/seo/integration.ts +268 -0
- package/src/seo/internal/url.ts +68 -0
- package/src/seo/lib/jsonld.ts +342 -0
- package/src/seo/lib/meta.ts +205 -0
- package/src/seo/lib/redirects.ts +293 -0
- package/src/seo/lib/robots.ts +33 -0
- package/src/seo/lib/rss.ts +98 -0
- package/src/seo/lib/sitemap.ts +105 -0
- package/src/seo/schema.ts +43 -0
- package/src/tokens/base.css +71 -0
- package/src/tokens/tokens.css +210 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { HighlightCardItem } from '../types';
|
|
2
|
+
import type { HighlightCardsData } from './data';
|
|
3
|
+
import type { MapContext } from './types';
|
|
4
|
+
import { clean, compact, mapActions, mapSettings, withFields } from './shared';
|
|
5
|
+
|
|
6
|
+
export const highlightCardsDefaults: HighlightCardsData = {
|
|
7
|
+
_template: 'highlightCards',
|
|
8
|
+
label: 'How can we help?',
|
|
9
|
+
items: [
|
|
10
|
+
{ heading: 'New projects', description: 'Tell us a little about your site and we’ll call you back.', actions: [{ label: 'Get started', href: '/contact', style: 'outline', arrow: true }] },
|
|
11
|
+
{ heading: 'Agency partners', description: 'Send a brief and we’ll respond within 24 hours.', actions: [{ label: 'Send a brief', href: '/partners', style: 'outline', arrow: true }] },
|
|
12
|
+
{ heading: 'Opening hours', points: ['24 hours a day', '7 days a week'], actions: [{ label: 'Contact us', href: '/contact', style: 'outline', arrow: true }] },
|
|
13
|
+
],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function highlightCardsToProps(d: HighlightCardsData, ctx: MapContext) {
|
|
17
|
+
const items = withFields(d.items, 'items')
|
|
18
|
+
.filter((i) => clean(i?.heading))
|
|
19
|
+
.slice(0, 4)
|
|
20
|
+
.map((i) =>
|
|
21
|
+
compact({
|
|
22
|
+
heading: clean(i.heading)!,
|
|
23
|
+
description: clean(i.description),
|
|
24
|
+
points: (i.points ?? []).map((p) => clean(p)).filter(Boolean) as string[],
|
|
25
|
+
actions: mapActions(i.actions),
|
|
26
|
+
tone: clean(i.tone),
|
|
27
|
+
field: i._field,
|
|
28
|
+
}) as HighlightCardItem,
|
|
29
|
+
);
|
|
30
|
+
const { anchor, align } = mapSettings(d.settings);
|
|
31
|
+
return compact({
|
|
32
|
+
anchor,
|
|
33
|
+
align,
|
|
34
|
+
label: clean(d.label),
|
|
35
|
+
items,
|
|
36
|
+
overlap: d.overlap ?? undefined,
|
|
37
|
+
gap: d.gap,
|
|
38
|
+
headingLevel: 2 as const,
|
|
39
|
+
placeholder: ctx.placeholder,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns CMS image paths into images astro:assets can optimize.
|
|
3
|
+
*
|
|
4
|
+
* const resolveImage = createImageResolver(import.meta.glob('/src/assets/**\/*.{jpg,jpeg,png,webp,avif,svg}', { eager: true }));
|
|
5
|
+
* <BlockRenderer blocks={page.blocks} resolveImage={resolveImage} />
|
|
6
|
+
*
|
|
7
|
+
* Paths are matched as given, with `/src` prepended (for CMSs that store paths relative to `src/`),
|
|
8
|
+
* and by filename-suffix as a last resort. Absolute URLs need `remote` sizes.
|
|
9
|
+
*/
|
|
10
|
+
import type { ImageResolver, ResolvedImage } from './types';
|
|
11
|
+
|
|
12
|
+
type GlobResult = Record<string, { default: import('astro').ImageMetadata } | import('astro').ImageMetadata>;
|
|
13
|
+
|
|
14
|
+
export function createImageResolver(
|
|
15
|
+
modules: GlobResult,
|
|
16
|
+
options: { remote?: Record<string, { width: number; height: number }> } = {},
|
|
17
|
+
): ImageResolver {
|
|
18
|
+
const byPath = new Map<string, import('astro').ImageMetadata>();
|
|
19
|
+
for (const [key, mod] of Object.entries(modules)) {
|
|
20
|
+
byPath.set(key, 'default' in mod ? mod.default : mod);
|
|
21
|
+
}
|
|
22
|
+
return (src: string): ResolvedImage | undefined => {
|
|
23
|
+
if (/^https?:\/\//.test(src)) {
|
|
24
|
+
const size = options.remote?.[src];
|
|
25
|
+
return size ? { src, ...size } : undefined;
|
|
26
|
+
}
|
|
27
|
+
const clean = src.split(/[?#]/)[0];
|
|
28
|
+
const path = clean.startsWith('/') ? clean : `/${clean}`;
|
|
29
|
+
const hit = byPath.get(path) ?? byPath.get(`/src${path}`);
|
|
30
|
+
if (hit) return hit;
|
|
31
|
+
for (const [key, value] of byPath) if (key.endsWith(path)) return value;
|
|
32
|
+
return undefined;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A resolver that resolves nothing (images are skipped, with a dev warning). */
|
|
37
|
+
export const noImages: ImageResolver = () => undefined;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CMS side of @sinnstack/ui/blocks: stored data shapes, defaults, fixtures and the data → props
|
|
3
|
+
* mappers that BlockRenderer uses. CMS-agnostic: any CMS that writes JSON/YAML/Markdown content
|
|
4
|
+
* with a `_template` key per block works. SinnStackCMS schemas for every block ship in
|
|
5
|
+
* `@sinnstack/ui/blocks/schema` (./schema.ts), typed against these data shapes.
|
|
6
|
+
*
|
|
7
|
+
* The data shapes are a contract: a field rename or removal is breaking, with a migration note.
|
|
8
|
+
*/
|
|
9
|
+
import { heroDefaults, heroToProps } from './hero';
|
|
10
|
+
import { ctaBannerDefaults, ctaBannerToProps } from './cta-banner';
|
|
11
|
+
import { featureGridDefaults, featureGridToProps } from './feature-grid';
|
|
12
|
+
import { cardGridDefaults, cardGridToProps } from './card-grid';
|
|
13
|
+
import { logoCloudDefaults, logoCloudToProps } from './logo-cloud';
|
|
14
|
+
import { heroCarouselDefaults, heroCarouselToProps } from './hero-carousel';
|
|
15
|
+
import { pageHeaderDefaults, pageHeaderToProps } from './page-header';
|
|
16
|
+
import { contactCardDefaults, contactCardToProps } from './contact-card';
|
|
17
|
+
import { stepsDefaults, stepsToProps } from './steps';
|
|
18
|
+
import { mediaTextDefaults, mediaTextToProps } from './media-text';
|
|
19
|
+
import { ctaPairDefaults, ctaPairToProps } from './cta-pair';
|
|
20
|
+
import { statsBandDefaults, statsBandToProps } from './stats-band';
|
|
21
|
+
import { highlightCardsDefaults, highlightCardsToProps } from './highlight-cards';
|
|
22
|
+
import { contactFormDefaults, contactFormToProps } from './contact-form';
|
|
23
|
+
import { proseSectionDefaults, proseSectionToProps } from './prose-section';
|
|
24
|
+
import { faqDefaults, faqToProps } from './faq';
|
|
25
|
+
import { testimonialsDefaults, testimonialsToProps } from './testimonials';
|
|
26
|
+
import { reviewsDefaults, reviewsToProps } from './reviews';
|
|
27
|
+
import { locationHoursDefaults, locationHoursToProps } from './location-hours';
|
|
28
|
+
|
|
29
|
+
export * from './types';
|
|
30
|
+
export * from './data';
|
|
31
|
+
export * from './fixtures';
|
|
32
|
+
export { createImageResolver, noImages } from './images';
|
|
33
|
+
export { errorPageProps, type ErrorPagesSettings } from './pages';
|
|
34
|
+
export { heroDefaults, heroToProps };
|
|
35
|
+
export { ctaBannerDefaults, ctaBannerToProps };
|
|
36
|
+
export { featureGridDefaults, featureGridToProps };
|
|
37
|
+
export { cardGridDefaults, cardGridToProps };
|
|
38
|
+
export { logoCloudDefaults, logoCloudToProps };
|
|
39
|
+
export { heroCarouselDefaults, heroCarouselToProps };
|
|
40
|
+
export { pageHeaderDefaults, pageHeaderToProps };
|
|
41
|
+
export { contactCardDefaults, contactCardToProps };
|
|
42
|
+
export { stepsDefaults, stepsToProps };
|
|
43
|
+
export { mediaTextDefaults, mediaTextToProps };
|
|
44
|
+
export { ctaPairDefaults, ctaPairToProps };
|
|
45
|
+
export { statsBandDefaults, statsBandToProps };
|
|
46
|
+
export { highlightCardsDefaults, highlightCardsToProps };
|
|
47
|
+
export { contactFormDefaults, contactFormToProps };
|
|
48
|
+
export { proseSectionDefaults, proseSectionToProps };
|
|
49
|
+
export { faqDefaults, faqToProps };
|
|
50
|
+
export { testimonialsDefaults, testimonialsToProps };
|
|
51
|
+
export { reviewsDefaults, reviewsToProps };
|
|
52
|
+
export { locationHoursDefaults, locationHoursToProps };
|
|
53
|
+
export { topbarProps } from './topbar';
|
|
54
|
+
export { consentProps } from './consent';
|
|
55
|
+
|
|
56
|
+
/** Template name of a stored block (its `_template` key). */
|
|
57
|
+
export function templateName(block: { _template?: unknown }): string | undefined {
|
|
58
|
+
return typeof block._template === 'string' && block._template ? block._template : undefined;
|
|
59
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { DayCode, HoursRow, PostalAddress, SpecialHours } from '../types';
|
|
2
|
+
import type { LocationHoursData } from './data';
|
|
3
|
+
import type { MapContext } from './types';
|
|
4
|
+
import { clean, compact, mapSettings } from './shared';
|
|
5
|
+
import { DAY_CODES, parseTime } from '../lib/hours';
|
|
6
|
+
|
|
7
|
+
/** Validates an IANA time zone name with the browser's own list. */
|
|
8
|
+
export function isTimeZone(value: string | undefined): boolean {
|
|
9
|
+
if (!value) return false;
|
|
10
|
+
try {
|
|
11
|
+
new Intl.DateTimeFormat('en-US', { timeZone: value });
|
|
12
|
+
return true;
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const locationHoursDefaults: LocationHoursData = {
|
|
19
|
+
_template: 'locationHours',
|
|
20
|
+
heading: 'Visit us',
|
|
21
|
+
name: 'Sinnstack',
|
|
22
|
+
address: { street: '500 Main St', street2: 'Suite 210', city: 'Fort Worth', region: 'TX', postalCode: '76102' },
|
|
23
|
+
phone: '(817) 555-0100',
|
|
24
|
+
email: 'hello@example.com',
|
|
25
|
+
timeZone: 'America/Chicago',
|
|
26
|
+
hours: [
|
|
27
|
+
{ days: ['Mo', 'Tu', 'We', 'Th', 'Fr'], opens: '09:00', closes: '17:00' },
|
|
28
|
+
{ days: ['Sa', 'Su'], closed: true },
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const days = (v: unknown): DayCode[] => (Array.isArray(v) ? (v.filter((d) => (DAY_CODES as readonly string[]).includes(d)) as DayCode[]) : []);
|
|
33
|
+
|
|
34
|
+
export function locationHoursToProps(d: LocationHoursData, ctx: MapContext) {
|
|
35
|
+
const a = d.address ?? {};
|
|
36
|
+
const address: PostalAddress | undefined =
|
|
37
|
+
clean(a.street) && clean(a.city)
|
|
38
|
+
? (compact({ street: clean(a.street)!, street2: clean(a.street2), city: clean(a.city)!, region: clean(a.region) ?? '', postalCode: clean(a.postalCode) ?? '', country: clean(a.country)?.toUpperCase() }) as PostalAddress)
|
|
39
|
+
: undefined;
|
|
40
|
+
const hours = (d.hours ?? [])
|
|
41
|
+
.map((r) => compact({ days: days(r?.days), opens: clean(r?.opens), closes: clean(r?.closes), closed: r?.closed === true ? true : undefined }) as HoursRow)
|
|
42
|
+
.filter((r) => r.days.length && (r.closed || (parseTime(r.opens) !== undefined && parseTime(r.closes) !== undefined)));
|
|
43
|
+
const special = (d.special ?? [])
|
|
44
|
+
.map((s) => compact({ date: clean(s?.date)?.slice(0, 10) ?? '', label: clean(s?.label), opens: clean(s?.opens), closes: clean(s?.closes), closed: s?.closed === true ? true : undefined }) as SpecialHours)
|
|
45
|
+
.filter((s) => /^\d{4}-\d{2}-\d{2}$/.test(s.date));
|
|
46
|
+
const tz = clean(d.timeZone);
|
|
47
|
+
const embed = clean(d.mapEmbedUrl);
|
|
48
|
+
return compact({
|
|
49
|
+
...mapSettings(d.settings),
|
|
50
|
+
eyebrow: clean(d.eyebrow),
|
|
51
|
+
heading: clean(d.heading),
|
|
52
|
+
description: clean(d.description),
|
|
53
|
+
name: clean(d.name),
|
|
54
|
+
address,
|
|
55
|
+
phone: clean(d.phone),
|
|
56
|
+
email: clean(d.email),
|
|
57
|
+
hours,
|
|
58
|
+
special: special.length ? special : undefined,
|
|
59
|
+
hoursNote: clean(d.hoursNote),
|
|
60
|
+
timeZone: tz && isTimeZone(tz) ? tz : undefined,
|
|
61
|
+
map: d.map,
|
|
62
|
+
mapEmbedUrl: embed && /^https:\/\//i.test(embed) ? embed : undefined,
|
|
63
|
+
layout: d.layout,
|
|
64
|
+
headingLevel: 2 as const,
|
|
65
|
+
placeholder: ctx.placeholder,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { LogoCloudData } from './data';
|
|
2
|
+
import type { LogoItem } from '../types';
|
|
3
|
+
import type { MapContext } from './types';
|
|
4
|
+
import { safeHref } from '../lib/contact';
|
|
5
|
+
import { clean, compact, mapImage, mapSettings, withFields } from './shared';
|
|
6
|
+
|
|
7
|
+
export const logoCloudDefaults: LogoCloudData = {
|
|
8
|
+
_template: 'logoCloud',
|
|
9
|
+
heading: 'Trusted by',
|
|
10
|
+
compact: true,
|
|
11
|
+
variant: 'strip',
|
|
12
|
+
logos: [],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function logoCloudToProps(d: LogoCloudData, ctx: MapContext) {
|
|
16
|
+
const logos = withFields(d.logos, 'logos').flatMap((l) => {
|
|
17
|
+
const name = clean(l?.name);
|
|
18
|
+
const image = name ? mapImage(l.image, name, ctx) : undefined;
|
|
19
|
+
if (!image) return [];
|
|
20
|
+
return [compact({ src: image.src, alt: name!, width: image.width, height: image.height, href: safeHref(l.href), field: l._field }) as LogoItem];
|
|
21
|
+
});
|
|
22
|
+
return compact({
|
|
23
|
+
...mapSettings(d.settings),
|
|
24
|
+
heading: clean(d.heading),
|
|
25
|
+
compact: d.compact ?? undefined,
|
|
26
|
+
logos,
|
|
27
|
+
// Stored as `variant` (no content migration); the component prop is `layout`.
|
|
28
|
+
layout: d.variant,
|
|
29
|
+
columns: d.columns ? (Number(d.columns) as 2 | 3 | 4 | 5 | 6) : undefined,
|
|
30
|
+
size: d.size,
|
|
31
|
+
mono: d.mono ?? undefined,
|
|
32
|
+
tile: d.tile ?? undefined,
|
|
33
|
+
headingLevel: 2 as const,
|
|
34
|
+
placeholder: ctx.placeholder,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { MediaTextData } from './data';
|
|
2
|
+
import type { MapContext } from './types';
|
|
3
|
+
import { clean, compact, mapActions, mapImage, mapSettings } from './shared';
|
|
4
|
+
|
|
5
|
+
export const mediaTextDefaults: MediaTextData = {
|
|
6
|
+
_template: 'mediaText',
|
|
7
|
+
heading: 'A heading about who you help',
|
|
8
|
+
description: 'One or two sentences of supporting text.',
|
|
9
|
+
points: ['A short reason to choose you', 'Another one'],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function mediaTextToProps(d: MediaTextData, ctx: MapContext) {
|
|
13
|
+
return compact({
|
|
14
|
+
...mapSettings(d.settings),
|
|
15
|
+
eyebrow: clean(d.eyebrow),
|
|
16
|
+
heading: clean(d.heading),
|
|
17
|
+
description: clean(d.description),
|
|
18
|
+
points: (d.points ?? []).map((p) => clean(p)).filter((p): p is string => Boolean(p)),
|
|
19
|
+
actions: mapActions(d.actions),
|
|
20
|
+
image: mapImage(d.image, d.imageAlt, ctx),
|
|
21
|
+
mediaPosition: d.mediaPosition,
|
|
22
|
+
mediaAspect: d.mediaAspect,
|
|
23
|
+
headingLevel: 2 as const,
|
|
24
|
+
placeholder: ctx.placeholder,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PageHeaderData } from './data';
|
|
2
|
+
import type { MapContext } from './types';
|
|
3
|
+
import { safeHref } from '../lib/contact';
|
|
4
|
+
import { clean, compact, mapActions, mapSettings } from './shared';
|
|
5
|
+
|
|
6
|
+
export const pageHeaderDefaults: PageHeaderData = {
|
|
7
|
+
_template: 'pageHeader',
|
|
8
|
+
heading: 'Page title',
|
|
9
|
+
breadcrumbs: [{ label: 'Home', href: '/' }],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function pageHeaderToProps(d: PageHeaderData, ctx: MapContext) {
|
|
13
|
+
const breadcrumbs = (d.breadcrumbs ?? [])
|
|
14
|
+
.filter((c) => clean(c?.label))
|
|
15
|
+
.map((c) => compact({ label: clean(c.label)!, href: safeHref(c.href) }) as { label: string; href?: string });
|
|
16
|
+
return compact({
|
|
17
|
+
...mapSettings(d.settings),
|
|
18
|
+
eyebrow: clean(d.eyebrow),
|
|
19
|
+
heading: clean(d.heading),
|
|
20
|
+
description: clean(d.description),
|
|
21
|
+
breadcrumbs,
|
|
22
|
+
breadcrumbPosition: d.breadcrumbPosition,
|
|
23
|
+
actions: mapActions(d.actions),
|
|
24
|
+
headingLevel: ctx.headingLevel,
|
|
25
|
+
placeholder: ctx.placeholder,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Site-wide page settings (not page-builder blocks): error-page copy and links, and maintenance
|
|
3
|
+
* mode. Store them in a "Site settings" singleton and map them with `errorPageProps`.
|
|
4
|
+
*
|
|
5
|
+
* Note: a static site needs a rebuild for maintenance changes to show; on SSR, read the setting in
|
|
6
|
+
* `createMaintenanceMiddleware({ enabled: async () => (await getSettings()).maintenance.enabled })`.
|
|
7
|
+
*/
|
|
8
|
+
import { blockIconNames } from '../icons';
|
|
9
|
+
import { safeHref } from '../lib/contact';
|
|
10
|
+
|
|
11
|
+
export interface ErrorPagesSettings {
|
|
12
|
+
notFoundHeading?: string;
|
|
13
|
+
notFoundDescription?: string;
|
|
14
|
+
serverErrorHeading?: string;
|
|
15
|
+
serverErrorDescription?: string;
|
|
16
|
+
links?: Array<{ label?: string; href?: string; description?: string; icon?: string }>;
|
|
17
|
+
contactText?: string;
|
|
18
|
+
contactLabel?: string;
|
|
19
|
+
contactHref?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Props for <ErrorPage> from the settings singleton (empty fields fall back to defaults). */
|
|
23
|
+
export function errorPageProps(settings: ErrorPagesSettings | null | undefined, status: number) {
|
|
24
|
+
const s = settings ?? {};
|
|
25
|
+
const t = (v?: string) => (v && v.trim() ? v.trim() : undefined);
|
|
26
|
+
const server = status >= 500;
|
|
27
|
+
const links = (s.links ?? []).filter((l) => t(l.label) && safeHref(l.href)).map((l) => ({ label: t(l.label)!, href: safeHref(l.href)!, description: t(l.description), icon: l.icon && (blockIconNames as string[]).includes(l.icon) ? l.icon : undefined }));
|
|
28
|
+
return {
|
|
29
|
+
status,
|
|
30
|
+
heading: t(server ? s.serverErrorHeading : s.notFoundHeading),
|
|
31
|
+
description: t(server ? s.serverErrorDescription : s.notFoundDescription),
|
|
32
|
+
links,
|
|
33
|
+
contact: t(s.contactLabel) && safeHref(s.contactHref) ? { text: t(s.contactText), label: t(s.contactLabel)!, href: safeHref(s.contactHref)! } : undefined,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ProseSectionData } from './data';
|
|
2
|
+
import type { MapContext } from './types';
|
|
3
|
+
import { clean, compact, mapActions, mapSettings } from './shared';
|
|
4
|
+
import { isRichTextEmpty } from '../lib/rich-text';
|
|
5
|
+
|
|
6
|
+
export const proseSectionDefaults: ProseSectionData = {
|
|
7
|
+
_template: 'proseSection',
|
|
8
|
+
heading: 'About the studio',
|
|
9
|
+
body: 'Sinnstack builds fast, accessible websites for small businesses.\n\nEvery project starts with a short discovery call, and every site ships with a CMS your team can edit.',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function proseSectionToProps(d: ProseSectionData, ctx: MapContext) {
|
|
13
|
+
return compact({
|
|
14
|
+
...mapSettings(d.settings),
|
|
15
|
+
eyebrow: clean(d.eyebrow),
|
|
16
|
+
heading: clean(d.heading),
|
|
17
|
+
body: isRichTextEmpty(d.body) ? undefined : d.body,
|
|
18
|
+
actions: mapActions(d.actions),
|
|
19
|
+
measure: d.measure === false ? false : undefined,
|
|
20
|
+
size: d.size,
|
|
21
|
+
resolveImage: ctx.resolveImage,
|
|
22
|
+
headingLevel: 2 as const,
|
|
23
|
+
placeholder: ctx.placeholder,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ReviewItem, ReviewSummary } from '../types';
|
|
2
|
+
import type { ReviewsData } from './data';
|
|
3
|
+
import type { MapContext } from './types';
|
|
4
|
+
import { clean, compact, mapSettings, withFields } from './shared';
|
|
5
|
+
import { safeHref } from '../lib/contact';
|
|
6
|
+
import { validReviews } from '../internal/reviews';
|
|
7
|
+
|
|
8
|
+
export const reviewsDefaults: ReviewsData = {
|
|
9
|
+
_template: 'reviews',
|
|
10
|
+
heading: 'Reviews',
|
|
11
|
+
summary: { rating: 4.9, count: 37, source: 'Google' },
|
|
12
|
+
items: [
|
|
13
|
+
{ text: 'Clear plan, fair price, and the site was live ahead of schedule.', author: 'Reviewer name', rating: 5, date: '2026-09-12', sourceLabel: 'Google' },
|
|
14
|
+
{ text: 'Quick replies and a site that loads fast on phones.', author: 'Reviewer name', rating: 5, date: '2026-08-03', sourceLabel: 'Google' },
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function reviewsToProps(d: ReviewsData, ctx: MapContext) {
|
|
19
|
+
const items = validReviews(
|
|
20
|
+
withFields(d.items, 'items').map((i) => {
|
|
21
|
+
const label = clean(i?.sourceLabel);
|
|
22
|
+
return compact({
|
|
23
|
+
text: clean(i?.text) ?? '',
|
|
24
|
+
author: clean(i?.author) ?? '',
|
|
25
|
+
rating: typeof i?.rating === 'number' ? i.rating : NaN,
|
|
26
|
+
date: clean(i?.date)?.slice(0, 10),
|
|
27
|
+
source: label ? compact({ label, href: safeHref(clean(i.sourceHref)) }) : undefined,
|
|
28
|
+
response: clean(i?.response),
|
|
29
|
+
field: i._field,
|
|
30
|
+
}) as ReviewItem;
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
const s = d.summary;
|
|
34
|
+
const summary: ReviewSummary | undefined =
|
|
35
|
+
s && typeof s.rating === 'number' && s.rating > 0 && typeof s.count === 'number' && s.count > 0
|
|
36
|
+
? (compact({ rating: Math.min(5, s.rating), count: Math.round(s.count), source: clean(s.source), href: safeHref(clean(s.href)), writeHref: safeHref(clean(s.writeHref)) }) as ReviewSummary)
|
|
37
|
+
: undefined;
|
|
38
|
+
return compact({
|
|
39
|
+
...mapSettings(d.settings),
|
|
40
|
+
eyebrow: clean(d.eyebrow),
|
|
41
|
+
heading: clean(d.heading),
|
|
42
|
+
description: clean(d.description),
|
|
43
|
+
items,
|
|
44
|
+
summary,
|
|
45
|
+
variant: d.variant,
|
|
46
|
+
columns: d.columns ? (Number(d.columns) as 1 | 2 | 3) : undefined,
|
|
47
|
+
headingLevel: 2 as const,
|
|
48
|
+
placeholder: ctx.placeholder,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The field-definition format SinnStackCMS reads (`fields.text()`, `fields.list()`…), written out
|
|
3
|
+
* as plain data so @sinnstack/ui can ship schemas without depending on the CMS. Every value here
|
|
4
|
+
* is JSON: the CMS sends schemas to its admin as-is.
|
|
5
|
+
*
|
|
6
|
+
* The types are tied to the stored data shapes: `FieldsFor<HeroData>` only accepts keys HeroData
|
|
7
|
+
* has, a field kind that fits the value (a select for a set of strings, a list for an array…) and
|
|
8
|
+
* select options the mapper accepts. So `astro check` fails when a schema and its data shape drift.
|
|
9
|
+
*/
|
|
10
|
+
import type { RichTextRoot } from '../lib/rich-text';
|
|
11
|
+
|
|
12
|
+
interface FieldBase {
|
|
13
|
+
/** Form label. Defaults to the field key, humanized. */
|
|
14
|
+
label?: string;
|
|
15
|
+
/** Short text shown under the label. */
|
|
16
|
+
description?: string;
|
|
17
|
+
/** Plain-language hint for non-technical editors. */
|
|
18
|
+
help?: string;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
/** Starting value for a newly added item. */
|
|
21
|
+
default?: unknown;
|
|
22
|
+
readOnly?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface TextField extends FieldBase {
|
|
25
|
+
type: 'text';
|
|
26
|
+
min?: number;
|
|
27
|
+
max?: number;
|
|
28
|
+
/** A regular expression the whole value must match. */
|
|
29
|
+
pattern?: string;
|
|
30
|
+
patternMessage?: string;
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface TextareaField extends FieldBase {
|
|
34
|
+
type: 'textarea';
|
|
35
|
+
min?: number;
|
|
36
|
+
max?: number;
|
|
37
|
+
rows?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface MarkdownField extends FieldBase {
|
|
40
|
+
type: 'markdown';
|
|
41
|
+
rows?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface NumberField extends FieldBase {
|
|
44
|
+
type: 'number';
|
|
45
|
+
min?: number;
|
|
46
|
+
max?: number;
|
|
47
|
+
step?: number;
|
|
48
|
+
integer?: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface BooleanField extends FieldBase {
|
|
51
|
+
type: 'boolean';
|
|
52
|
+
}
|
|
53
|
+
export type SelectOption<V extends string = string> = V | { value: V; label: string };
|
|
54
|
+
export interface SelectField<V extends string = string> extends FieldBase {
|
|
55
|
+
type: 'select';
|
|
56
|
+
options: Array<SelectOption<V>>;
|
|
57
|
+
}
|
|
58
|
+
export interface ImageField extends FieldBase {
|
|
59
|
+
type: 'image';
|
|
60
|
+
}
|
|
61
|
+
export interface LinkField extends FieldBase {
|
|
62
|
+
type: 'link';
|
|
63
|
+
placeholder?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface ListField<F = SchemaField> extends FieldBase {
|
|
66
|
+
type: 'list';
|
|
67
|
+
of: F;
|
|
68
|
+
min?: number;
|
|
69
|
+
max?: number;
|
|
70
|
+
/** For lists of objects: the key whose value names each item. */
|
|
71
|
+
itemLabel?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface ObjectField<F = Record<string, SchemaField>> extends FieldBase {
|
|
74
|
+
type: 'object';
|
|
75
|
+
fields: F;
|
|
76
|
+
}
|
|
77
|
+
export type SchemaField =
|
|
78
|
+
| TextField
|
|
79
|
+
| TextareaField
|
|
80
|
+
| MarkdownField
|
|
81
|
+
| NumberField
|
|
82
|
+
| BooleanField
|
|
83
|
+
| SelectField
|
|
84
|
+
| ImageField
|
|
85
|
+
| LinkField
|
|
86
|
+
| ListField
|
|
87
|
+
| ObjectField;
|
|
88
|
+
|
|
89
|
+
/** A block type for `fields.blocks({ types })`. Its key in `types` is the stored `_template`. */
|
|
90
|
+
export interface BlockSchema {
|
|
91
|
+
label: string;
|
|
92
|
+
/** Key whose value names the block in the admin's list. */
|
|
93
|
+
itemLabel?: string;
|
|
94
|
+
fields: Record<string, SchemaField>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// --- Data shape → allowed field ---------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
type Defined<V> = Exclude<V, null | undefined>;
|
|
100
|
+
/** Free text: any string field, or a select with options of your own. */
|
|
101
|
+
type StringField = TextField | TextareaField | LinkField | ImageField | SelectField;
|
|
102
|
+
|
|
103
|
+
/** The field kinds that can store a value of type V. */
|
|
104
|
+
export type FieldFor<V> = [Defined<V>] extends [never]
|
|
105
|
+
? never
|
|
106
|
+
: // Rich text is stored as Markdown (a textarea also works: plain text is valid Markdown).
|
|
107
|
+
[string, RichTextRoot] extends [Defined<V>, Defined<V>]
|
|
108
|
+
? TextareaField | MarkdownField
|
|
109
|
+
: [Defined<V>] extends [boolean]
|
|
110
|
+
? BooleanField
|
|
111
|
+
: [Defined<V>] extends [number]
|
|
112
|
+
? NumberField
|
|
113
|
+
: [Defined<V>] extends [string]
|
|
114
|
+
? string extends Defined<V>
|
|
115
|
+
? StringField
|
|
116
|
+
: SelectField<Defined<V> & string>
|
|
117
|
+
: [Defined<V>] extends [ReadonlyArray<infer E>]
|
|
118
|
+
? ListField<FieldFor<E>>
|
|
119
|
+
: [Defined<V>] extends [object]
|
|
120
|
+
? ObjectField<FieldsFor<Defined<V>>>
|
|
121
|
+
: never;
|
|
122
|
+
|
|
123
|
+
/** Fields for a data shape: any subset of its keys, each with a field kind that fits. */
|
|
124
|
+
export type FieldsFor<T> = { [K in Exclude<keyof T, '_template'>]?: FieldFor<T[K]> };
|
|
125
|
+
|
|
126
|
+
/** A block schema checked against its data shape. */
|
|
127
|
+
export function blockSchema<T>(schema: { label: string; itemLabel?: Extract<keyof T, string>; fields: FieldsFor<T> }): BlockSchema {
|
|
128
|
+
return schema as BlockSchema;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** An object field checked against a data shape (site settings, nested groups). */
|
|
132
|
+
export function objectSchema<T>(field: Omit<ObjectField, 'type' | 'fields'> & { fields: FieldsFor<T> }): ObjectField {
|
|
133
|
+
return { type: 'object', ...field } as ObjectField;
|
|
134
|
+
}
|