@sinnstack/ui 0.2.0 → 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 +74 -0
- package/README.md +6 -4
- package/docs/blocks.md +373 -364
- package/docs/data.md +128 -128
- package/docs/finishes.md +165 -0
- package/docs/primitives.md +4 -4
- package/docs/seo.md +191 -187
- package/package.json +15 -24
- package/src/blocks/BlockRenderer.astro +13 -7
- package/src/blocks/CTABanner.astro +8 -8
- package/src/blocks/CTAPair.astro +9 -9
- package/src/blocks/CardGrid.astro +7 -7
- package/src/blocks/ConsentEmbed.astro +1 -1
- package/src/blocks/ConsentManager.astro +1 -1
- package/src/blocks/ContactCard.astro +14 -14
- package/src/blocks/ContactForm.astro +4 -4
- package/src/blocks/ErrorPage.astro +1 -1
- package/src/blocks/FAQ.astro +9 -9
- package/src/blocks/FeatureGrid.astro +7 -7
- package/src/blocks/Hero.astro +11 -11
- package/src/blocks/HeroCarousel.astro +11 -11
- package/src/blocks/HighlightCards.astro +10 -10
- package/src/blocks/LocationHours.astro +14 -14
- package/src/blocks/LogoCloud.astro +7 -7
- package/src/blocks/MaintenancePage.astro +8 -3
- package/src/blocks/MediaText.astro +12 -12
- package/src/blocks/PageHeader.astro +9 -9
- package/src/blocks/ProseSection.astro +8 -8
- package/src/blocks/Reviews.astro +11 -11
- package/src/blocks/RichText.astro +58 -57
- package/src/blocks/StatsBand.astro +117 -117
- package/src/blocks/Steps.astro +9 -9
- package/src/blocks/Testimonials.astro +13 -13
- package/src/blocks/cms/card-grid.ts +48 -80
- package/src/blocks/cms/consent.ts +1 -30
- package/src/blocks/cms/contact-card.ts +4 -46
- package/src/blocks/cms/contact-form.ts +2 -20
- package/src/blocks/cms/cta-banner.ts +2 -23
- package/src/blocks/cms/cta-pair.ts +4 -37
- package/src/blocks/cms/data-base.ts +2 -4
- package/src/blocks/cms/data.ts +19 -19
- package/src/blocks/cms/faq.ts +4 -36
- package/src/blocks/cms/feature-grid.ts +47 -80
- package/src/blocks/cms/fixtures.ts +591 -599
- package/src/blocks/cms/hero-carousel.ts +4 -48
- package/src/blocks/cms/hero.ts +2 -46
- package/src/blocks/cms/highlight-cards.ts +4 -39
- package/src/blocks/cms/images.ts +1 -2
- package/src/blocks/cms/index.ts +59 -87
- package/src/blocks/cms/location-hours.ts +3 -85
- package/src/blocks/cms/logo-cloud.ts +36 -62
- package/src/blocks/cms/media-text.ts +2 -20
- package/src/blocks/cms/page-header.ts +27 -49
- package/src/blocks/cms/pages.ts +35 -81
- package/src/blocks/cms/prose-section.ts +2 -22
- package/src/blocks/cms/reviews.ts +5 -56
- package/src/blocks/cms/schema-dsl.ts +134 -0
- package/src/blocks/cms/schema.ts +794 -0
- package/src/blocks/cms/shared.ts +63 -115
- package/src/blocks/cms/stats-band.ts +35 -61
- package/src/blocks/cms/steps.ts +4 -31
- package/src/blocks/cms/testimonials.ts +4 -38
- package/src/blocks/cms/topbar.ts +4 -41
- package/src/blocks/cms/types.ts +1 -37
- package/src/blocks/consent.ts +2 -2
- package/src/blocks/index.ts +2 -2
- package/src/blocks/internal/Actions.astro +11 -5
- package/src/blocks/internal/BlockHeader.astro +7 -7
- package/src/blocks/internal/Placeholder.astro +3 -3
- package/src/blocks/internal/fields.ts +18 -0
- package/src/blocks/internal/registry-contract.ts +67 -0
- package/src/blocks/internal/util.ts +4 -4
- package/src/blocks/lib/contact.ts +10 -4
- package/src/blocks/lib/faq.ts +1 -1
- package/src/blocks/lib/markdown.ts +350 -0
- package/src/blocks/lib/rich-text.ts +132 -143
- package/src/blocks/scripts/consent-manager.ts +1 -1
- package/src/blocks/scripts/consent-store.ts +1 -1
- package/src/blocks/scripts/hours.ts +3 -2
- package/src/blocks/types.ts +33 -23
- package/src/data/ChartContainer.astro +2 -1
- package/src/data/cms.ts +130 -190
- package/src/data/lib/chart.ts +13 -4
- package/src/data/schema.ts +65 -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/primitives/Divider.astro +1 -1
- package/src/primitives/FocusRing.astro +1 -1
- package/src/primitives/FormField.astro +2 -2
- package/src/primitives/Image.astro +3 -3
- package/src/primitives/Input.astro +4 -2
- package/src/primitives/MetricCard.astro +3 -1
- package/src/primitives/Picture.astro +3 -3
- package/src/primitives/Prose.astro +1 -1
- package/src/primitives/Select.astro +4 -2
- package/src/primitives/Slider.astro +1 -1
- package/src/primitives/Table.astro +1 -1
- package/src/primitives/Textarea.astro +4 -2
- package/src/primitives/Thumbnail.astro +2 -2
- package/src/primitives/index.ts +4 -4
- package/src/primitives/internal/ChoiceField.astro +4 -2
- package/src/primitives/scripts/slider.ts +1 -1
- package/src/primitives/scripts/table-sort.ts +2 -2
- package/src/seo/cms.ts +59 -80
- package/src/seo/index.ts +1 -1
- package/src/seo/integration.ts +40 -3
- package/src/seo/lib/jsonld.ts +10 -2
- package/src/seo/lib/meta.ts +2 -2
- package/src/seo/lib/redirects.ts +14 -4
- package/src/seo/lib/rss.ts +1 -1
- package/src/seo/lib/sitemap.ts +1 -1
- package/src/seo/schema.ts +43 -0
- package/src/blocks/internal/tina.ts +0 -19
- /package/src/blocks/{lib → internal}/consent.ts +0 -0
- /package/src/blocks/{lib → internal}/reviews.ts +0 -0
- /package/src/blocks/{lib → internal}/slug.ts +0 -0
- /package/src/data/{lib → internal}/scale.ts +0 -0
- /package/src/primitives/{lib → internal}/image-plan.ts +0 -0
- /package/src/primitives/{lib → internal}/image.ts +0 -0
- /package/src/primitives/{lib → internal}/slider.ts +0 -0
- /package/src/seo/{lib → internal}/url.ts +0 -0
package/src/blocks/cms/shared.ts
CHANGED
|
@@ -1,115 +1,63 @@
|
|
|
1
|
-
/**
|
|
2
|
-
import type { ActionItem, BlockProps, ImageSource } from '../types';
|
|
3
|
-
import type { CmsAction, CmsSettings, MapContext
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
ui: { component: 'textarea' },
|
|
65
|
-
...extra,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
/** Plain text only: CMS strings are rendered as text (escaped), never as HTML. */
|
|
69
|
-
export function clean(value: unknown): string | undefined {
|
|
70
|
-
if (typeof value !== 'string') return undefined;
|
|
71
|
-
const v = value.trim();
|
|
72
|
-
return v.length ? v : undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function mapSettings(settings: CmsSettings | null | undefined): Partial<BlockProps> {
|
|
76
|
-
const s = settings ?? {};
|
|
77
|
-
return {
|
|
78
|
-
anchor: clean(s.anchor),
|
|
79
|
-
background: s.background,
|
|
80
|
-
tone: s.tone,
|
|
81
|
-
spacing: s.spacing,
|
|
82
|
-
align: s.align,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function mapActions(actions: CmsAction[] | undefined): ActionItem[] {
|
|
87
|
-
return (actions ?? [])
|
|
88
|
-
.filter((a) => clean(a?.label) && clean(a?.href))
|
|
89
|
-
.map((a, i) => ({ label: clean(a.label)!, href: clean(a.href)!, variant: a.style ?? (i === 0 ? 'solid' : 'outline'), ...(a.arrow ? { arrow: true } : {}) }));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function mapImage(src: unknown, alt: unknown, ctx: MapContext): ImageSource | undefined {
|
|
93
|
-
const path = clean(src);
|
|
94
|
-
if (!path) return undefined;
|
|
95
|
-
const resolved = ctx.resolveImage(path);
|
|
96
|
-
if (!resolved) {
|
|
97
|
-
if (import.meta.env?.DEV) console.warn(`[blocks] Image "${path}" couldn't be resolved; skipped. Pass resolveImage to BlockRenderer.`);
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
return 'format' in resolved ? { src: resolved, alt: clean(alt) ?? '' } : { src: resolved.src, width: resolved.width, height: resolved.height, alt: clean(alt) ?? '' };
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Map a value stored by an older schema to the current vocabulary. Content keeps working
|
|
105
|
-
* without a migration; the schema offers only current values, so the next save stores those.
|
|
106
|
-
*/
|
|
107
|
-
export function upgrade<T extends string>(value: T | undefined | null, renames: Readonly<Record<string, string>>): T | undefined {
|
|
108
|
-
if (value == null) return undefined;
|
|
109
|
-
return (Object.prototype.hasOwnProperty.call(renames, value) ? renames[value] : value) as T;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** Drops undefined values so component defaults apply. */
|
|
113
|
-
export function compact<T extends Record<string, unknown>>(obj: T): Partial<T> {
|
|
114
|
-
return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined)) as Partial<T>;
|
|
115
|
-
}
|
|
1
|
+
/** Mapping helpers shared by every block's CMS module. */
|
|
2
|
+
import type { ActionItem, BlockProps, ImageSource } from '../types';
|
|
3
|
+
import type { CmsAction, CmsSettings, MapContext } from './types';
|
|
4
|
+
import { safeHref } from '../lib/contact';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Tags each list item with its stored path (`items.3`) before the mapper filters the list, so the
|
|
8
|
+
* `data-sinn-field` annotations point at the right item even when empty ones are skipped.
|
|
9
|
+
* Null entries are dropped.
|
|
10
|
+
*/
|
|
11
|
+
export function withFields<T extends object>(list: ReadonlyArray<T | null | undefined> | null | undefined, key: string): Array<T & { _field: string }> {
|
|
12
|
+
return (list ?? []).flatMap((item, n) => (item ? [{ ...item, _field: `${key}.${n}` }] : []));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Plain text only: CMS strings are rendered as text (escaped), never as HTML. */
|
|
16
|
+
export function clean(value: unknown): string | undefined {
|
|
17
|
+
if (typeof value !== 'string') return undefined;
|
|
18
|
+
const v = value.trim();
|
|
19
|
+
return v.length ? v : undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function mapSettings(settings: CmsSettings | null | undefined): Partial<BlockProps> {
|
|
23
|
+
const s = settings ?? {};
|
|
24
|
+
return {
|
|
25
|
+
anchor: clean(s.anchor),
|
|
26
|
+
background: s.background,
|
|
27
|
+
tone: s.tone,
|
|
28
|
+
spacing: s.spacing,
|
|
29
|
+
align: s.align,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function mapActions(actions: CmsAction[] | undefined): ActionItem[] {
|
|
34
|
+
return withFields(actions, 'actions')
|
|
35
|
+
.map((a) => ({ ...a, href: safeHref(a.href) }))
|
|
36
|
+
.filter((a) => clean(a.label) && a.href)
|
|
37
|
+
.map((a, i) => ({ label: clean(a.label)!, href: a.href!, variant: a.style ?? (i === 0 ? 'solid' : 'outline'), ...(a.arrow ? { arrow: true } : {}), field: a._field }));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function mapImage(src: unknown, alt: unknown, ctx: MapContext): ImageSource | undefined {
|
|
41
|
+
const path = clean(src);
|
|
42
|
+
if (!path) return undefined;
|
|
43
|
+
const resolved = ctx.resolveImage(path);
|
|
44
|
+
if (!resolved) {
|
|
45
|
+
if (import.meta.env?.DEV) console.warn(`[blocks] Image "${path}" couldn't be resolved; skipped. Pass resolveImage to BlockRenderer.`);
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return 'format' in resolved ? { src: resolved, alt: clean(alt) ?? '' } : { src: resolved.src, width: resolved.width, height: resolved.height, alt: clean(alt) ?? '' };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Map a value stored by an older schema to the current vocabulary. Content keeps working
|
|
53
|
+
* without a migration; the schema offers only current values, so the next save stores those.
|
|
54
|
+
*/
|
|
55
|
+
export function upgrade<T extends string>(value: T | undefined | null, renames: Readonly<Record<string, string>>): T | undefined {
|
|
56
|
+
if (value == null) return undefined;
|
|
57
|
+
return (Object.prototype.hasOwnProperty.call(renames, value) ? renames[value] : value) as T;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Drops undefined values so component defaults apply. */
|
|
61
|
+
export function compact<T extends Record<string, unknown>>(obj: T): Partial<T> {
|
|
62
|
+
return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined)) as Partial<T>;
|
|
63
|
+
}
|
|
@@ -1,61 +1,35 @@
|
|
|
1
|
-
import type { StatItem } from '../types';
|
|
2
|
-
import type { StatsBandData } from './data';
|
|
3
|
-
import type { MapContext
|
|
4
|
-
import { blockIconNames } from '../icons';
|
|
5
|
-
import { clean, compact, mapImage, mapSettings,
|
|
6
|
-
|
|
7
|
-
export const statsBandDefaults: StatsBandData = {
|
|
8
|
-
_template: 'statsBand',
|
|
9
|
-
label: 'At a glance',
|
|
10
|
-
items: [
|
|
11
|
-
{ value: '24', label: 'Hours a day' },
|
|
12
|
-
{ value: '7', label: 'Days a week' },
|
|
13
|
-
{ value: '15', label: 'Counties served' },
|
|
14
|
-
],
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
{ type: 'image', name: 'image', label: 'Background photo (optional)', description: 'Decorative: it sits under the band color.' },
|
|
38
|
-
{ type: 'string', name: 'tone', label: 'Color', options: [{ value: 'accent', label: 'Brand' }, { value: 'neutral', label: 'Neutral' }] },
|
|
39
|
-
settingsField({ background: false }),
|
|
40
|
-
],
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export function statsBandToProps(d: StatsBandData, ctx: MapContext) {
|
|
44
|
-
const items = (d.items ?? [])
|
|
45
|
-
.filter((i) => clean(i?.value) && clean(i?.label))
|
|
46
|
-
.slice(0, 6)
|
|
47
|
-
.map((i) => compact({ value: clean(i.value)!, label: clean(i.label)!, icon: clean(i.icon), tina: i as never }) as StatItem);
|
|
48
|
-
const { anchor, align, spacing } = mapSettings(d.settings);
|
|
49
|
-
return compact({
|
|
50
|
-
anchor,
|
|
51
|
-
align,
|
|
52
|
-
spacing,
|
|
53
|
-
heading: clean(d.heading),
|
|
54
|
-
label: clean(d.label),
|
|
55
|
-
items,
|
|
56
|
-
image: mapImage(d.image, '', ctx),
|
|
57
|
-
tone: d.tone,
|
|
58
|
-
headingLevel: ctx.headingLevel === 1 ? (2 as const) : ctx.headingLevel,
|
|
59
|
-
placeholder: ctx.placeholder,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
1
|
+
import type { StatItem } from '../types';
|
|
2
|
+
import type { StatsBandData } from './data';
|
|
3
|
+
import type { MapContext } from './types';
|
|
4
|
+
import { blockIconNames } from '../icons';
|
|
5
|
+
import { clean, compact, mapImage, mapSettings, withFields } from './shared';
|
|
6
|
+
|
|
7
|
+
export const statsBandDefaults: StatsBandData = {
|
|
8
|
+
_template: 'statsBand',
|
|
9
|
+
label: 'At a glance',
|
|
10
|
+
items: [
|
|
11
|
+
{ value: '24', label: 'Hours a day' },
|
|
12
|
+
{ value: '7', label: 'Days a week' },
|
|
13
|
+
{ value: '15', label: 'Counties served' },
|
|
14
|
+
],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function statsBandToProps(d: StatsBandData, ctx: MapContext) {
|
|
18
|
+
const items = withFields(d.items, 'items')
|
|
19
|
+
.filter((i) => clean(i?.value) && clean(i?.label))
|
|
20
|
+
.slice(0, 6)
|
|
21
|
+
.map((i) => compact({ value: clean(i.value)!, label: clean(i.label)!, icon: i.icon && (blockIconNames as string[]).includes(i.icon) ? i.icon : undefined, field: i._field }) as StatItem);
|
|
22
|
+
const { anchor, align, spacing } = mapSettings(d.settings);
|
|
23
|
+
return compact({
|
|
24
|
+
anchor,
|
|
25
|
+
align,
|
|
26
|
+
spacing,
|
|
27
|
+
heading: clean(d.heading),
|
|
28
|
+
label: clean(d.label),
|
|
29
|
+
items,
|
|
30
|
+
image: mapImage(d.image, '', ctx),
|
|
31
|
+
tone: d.tone,
|
|
32
|
+
headingLevel: ctx.headingLevel === 1 ? (2 as const) : ctx.headingLevel,
|
|
33
|
+
placeholder: ctx.placeholder,
|
|
34
|
+
});
|
|
35
|
+
}
|
package/src/blocks/cms/steps.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { blockIconNames } from '../icons';
|
|
2
2
|
import type { StepItem } from '../types';
|
|
3
3
|
import type { StepsData } from './data';
|
|
4
|
-
import type { MapContext
|
|
5
|
-
import { clean, compact,
|
|
4
|
+
import type { MapContext } from './types';
|
|
5
|
+
import { clean, compact, mapSettings, upgrade, withFields } from './shared';
|
|
6
6
|
|
|
7
7
|
export const stepsDefaults: StepsData = {
|
|
8
8
|
_template: 'steps',
|
|
@@ -14,42 +14,15 @@ export const stepsDefaults: StepsData = {
|
|
|
14
14
|
],
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export const stepsTemplate: TinaTemplate = {
|
|
18
|
-
name: 'steps',
|
|
19
|
-
label: 'Steps',
|
|
20
|
-
ui: { defaultItem: stepsDefaults, itemProps: (item: StepsData) => ({ label: `Steps: ${item?.heading ?? ''}` }) },
|
|
21
|
-
fields: [
|
|
22
|
-
textField('eyebrow', 'Eyebrow'),
|
|
23
|
-
textField('heading', 'Heading'),
|
|
24
|
-
longTextField('description', 'Intro text'),
|
|
25
|
-
{
|
|
26
|
-
type: 'object',
|
|
27
|
-
name: 'items',
|
|
28
|
-
label: 'Steps',
|
|
29
|
-
list: true,
|
|
30
|
-
ui: { itemProps: (item: { title?: string }) => ({ label: item?.title || 'Step' }), defaultItem: { title: 'New step' } },
|
|
31
|
-
fields: [
|
|
32
|
-
textField('title', 'Title', { required: true }),
|
|
33
|
-
longTextField('description', 'Description'),
|
|
34
|
-
{ type: 'string', name: 'icon', label: 'Icon (when markers are icons)', options: blockIconNames },
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
{ type: 'string', name: 'marker', label: 'Marker', options: [{ value: 'number', label: 'Numbers' }, { value: 'icon', label: 'Icons' }, { value: 'none', label: 'None' }] },
|
|
38
|
-
{ type: 'string', name: 'layout', label: 'Layout', options: [{ value: 'row', label: 'Side by side' }, { value: 'list', label: 'Vertical list' }] },
|
|
39
|
-
{ type: 'string', name: 'variant', label: 'Style', options: [{ value: 'plain', label: 'Plain' }, { value: 'card', label: 'Cards' }] },
|
|
40
|
-
settingsField(),
|
|
41
|
-
],
|
|
42
|
-
};
|
|
43
|
-
|
|
44
17
|
export function stepsToProps(d: StepsData, ctx: MapContext) {
|
|
45
|
-
const items = (d.items
|
|
18
|
+
const items = withFields(d.items, 'items')
|
|
46
19
|
.filter((i) => clean(i?.title))
|
|
47
20
|
.map((i) =>
|
|
48
21
|
compact({
|
|
49
22
|
title: clean(i.title)!,
|
|
50
23
|
description: clean(i.description),
|
|
51
24
|
icon: i.icon && (blockIconNames as string[]).includes(i.icon) ? i.icon : undefined,
|
|
52
|
-
|
|
25
|
+
field: i._field,
|
|
53
26
|
}) as StepItem,
|
|
54
27
|
);
|
|
55
28
|
return compact({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TestimonialItem } from '../types';
|
|
2
2
|
import type { TestimonialsData } from './data';
|
|
3
|
-
import type { MapContext
|
|
4
|
-
import {
|
|
3
|
+
import type { MapContext } from './types';
|
|
4
|
+
import { clean, compact, mapActions, mapImage, mapSettings, withFields } from './shared';
|
|
5
5
|
import { safeHref } from '../lib/contact';
|
|
6
6
|
|
|
7
7
|
export const testimonialsDefaults: TestimonialsData = {
|
|
@@ -13,42 +13,8 @@ export const testimonialsDefaults: TestimonialsData = {
|
|
|
13
13
|
],
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export const testimonialsTemplate: TinaTemplate = {
|
|
17
|
-
name: 'testimonials',
|
|
18
|
-
label: 'Testimonials',
|
|
19
|
-
ui: { defaultItem: testimonialsDefaults, itemProps: (item: TestimonialsData) => ({ label: `Testimonials: ${item?.heading ?? ''}` }) },
|
|
20
|
-
fields: [
|
|
21
|
-
textField('eyebrow', 'Eyebrow'),
|
|
22
|
-
textField('heading', 'Heading'),
|
|
23
|
-
longTextField('description', 'Intro text'),
|
|
24
|
-
{
|
|
25
|
-
type: 'object',
|
|
26
|
-
name: 'items',
|
|
27
|
-
label: 'Quotes',
|
|
28
|
-
list: true,
|
|
29
|
-
description: 'Real quotes only, word for word, used with the person’s permission.',
|
|
30
|
-
ui: { itemProps: (item: { name?: string }) => ({ label: item?.name || 'Quote' }), defaultItem: { quote: 'What they said.', name: 'Their name' } },
|
|
31
|
-
fields: [
|
|
32
|
-
longTextField('quote', 'Quote', { required: true }),
|
|
33
|
-
textField('name', 'Name', { required: true }),
|
|
34
|
-
textField('role', 'Role (optional)'),
|
|
35
|
-
textField('organization', 'Company (optional)'),
|
|
36
|
-
{ type: 'image', name: 'image', label: 'Photo (optional)', description: 'A square portrait works best.' },
|
|
37
|
-
{ type: 'number', name: 'rating', label: 'Star rating (optional, 1–5)', ui: { validate: (v: unknown) => (v != null && v !== '' && !(Number(v) >= 1 && Number(v) <= 5) ? 'Use a number from 1 to 5.' : undefined) } },
|
|
38
|
-
textField('sourceLabel', 'Published on (optional)', { description: 'e.g. Google, Clutch, LinkedIn.' }),
|
|
39
|
-
textField('sourceHref', 'Link to the original (optional)'),
|
|
40
|
-
],
|
|
41
|
-
},
|
|
42
|
-
{ type: 'string', name: 'layout', label: 'Layout', options: [{ value: 'grid', label: 'Grid of quotes' }, { value: 'single', label: 'One large quote' }] },
|
|
43
|
-
{ type: 'string', name: 'variant', label: 'Style', options: [{ value: 'card', label: 'Boxes' }, { value: 'plain', label: 'Plain' }] },
|
|
44
|
-
{ type: 'string', name: 'columns', label: 'Columns (at most)', options: ['1', '2', '3'] },
|
|
45
|
-
actionsField(2),
|
|
46
|
-
settingsField(),
|
|
47
|
-
],
|
|
48
|
-
};
|
|
49
|
-
|
|
50
16
|
export function testimonialsToProps(d: TestimonialsData, ctx: MapContext) {
|
|
51
|
-
const items = (d.items
|
|
17
|
+
const items = withFields(d.items, 'items')
|
|
52
18
|
.filter((i) => clean(i?.quote) && clean(i?.name))
|
|
53
19
|
.map((i) => {
|
|
54
20
|
const rating = typeof i.rating === 'number' && i.rating >= 1 && i.rating <= 5 ? i.rating : undefined;
|
|
@@ -61,7 +27,7 @@ export function testimonialsToProps(d: TestimonialsData, ctx: MapContext) {
|
|
|
61
27
|
image: mapImage(i.image, '', ctx),
|
|
62
28
|
rating,
|
|
63
29
|
source: label ? compact({ label, href: safeHref(clean(i.sourceHref)) }) : undefined,
|
|
64
|
-
|
|
30
|
+
field: i._field,
|
|
65
31
|
}) as TestimonialItem;
|
|
66
32
|
});
|
|
67
33
|
return compact({
|
package/src/blocks/cms/topbar.ts
CHANGED
|
@@ -1,53 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Topbar is site chrome, not a page block: its content lives in site settings
|
|
3
|
-
*
|
|
4
|
-
* pass `topbarProps(settings.topbar)` to <Topbar> in the layout.
|
|
2
|
+
* Topbar is site chrome, not a page block: its content lives in site settings, like the error and
|
|
3
|
+
* maintenance pages. Pass `topbarProps(settings.topbar)` to <Topbar> in the layout.
|
|
5
4
|
*/
|
|
6
5
|
import type { ContactItem } from '../types';
|
|
7
6
|
import type { TopbarData } from './data';
|
|
8
|
-
import
|
|
9
|
-
import { clean, compact, textField } from './shared';
|
|
7
|
+
import { clean, compact } from './shared';
|
|
10
8
|
import { mapContactItems } from './contact-card';
|
|
11
9
|
import { safeHref } from '../lib/contact';
|
|
12
10
|
|
|
13
|
-
export function topbarField(): TinaField {
|
|
14
|
-
return {
|
|
15
|
-
type: 'object',
|
|
16
|
-
name: 'topbar',
|
|
17
|
-
label: 'Top bar (above the menu)',
|
|
18
|
-
fields: [
|
|
19
|
-
textField('message', 'Message', { description: 'One short line, e.g. “Now booking new projects”.' }),
|
|
20
|
-
{
|
|
21
|
-
type: 'object',
|
|
22
|
-
name: 'items',
|
|
23
|
-
label: 'Contact details',
|
|
24
|
-
list: true,
|
|
25
|
-
description: 'On phones only phone numbers stay visible.',
|
|
26
|
-
ui: { max: 4, itemProps: (item: { type?: string; value?: string }) => ({ label: [item?.type, item?.value].filter(Boolean).join(': ') || 'Detail' }) },
|
|
27
|
-
fields: [
|
|
28
|
-
{ type: 'string', name: 'type', label: 'Type', required: true, options: ['phone', 'email', 'address', 'fax', 'hours', 'link'] },
|
|
29
|
-
textField('value', 'Value', { required: true }),
|
|
30
|
-
textField('href', 'Link (links only)'),
|
|
31
|
-
],
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
type: 'object',
|
|
35
|
-
name: 'links',
|
|
36
|
-
label: 'Links (end side)',
|
|
37
|
-
list: true,
|
|
38
|
-
description: 'Social profiles or quick links. Name the network (“Facebook”).',
|
|
39
|
-
ui: { max: 5, itemProps: (item: { label?: string }) => ({ label: item?.label || 'Link' }) },
|
|
40
|
-
fields: [textField('label', 'Label', { required: true }), textField('href', 'Link', { required: true }), { type: 'boolean', name: 'newTab', label: 'Open in a new tab' }],
|
|
41
|
-
},
|
|
42
|
-
{ type: 'string', name: 'background', label: 'Background', options: [{ value: 'strong', label: 'Solid color' }, { value: 'tinted', label: 'Tinted' }, { value: 'subtle', label: 'Light gray' }] },
|
|
43
|
-
{ type: 'string', name: 'tone', label: 'Color', description: 'For solid and tinted backgrounds.', options: [{ value: 'neutral', label: 'Dark / neutral' }, { value: 'accent', label: 'Brand' }] },
|
|
44
|
-
],
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
11
|
export function topbarProps(d: TopbarData | null | undefined) {
|
|
49
12
|
const data = d ?? {};
|
|
50
|
-
const items: ContactItem[] = mapContactItems(data.items as never).map(({
|
|
13
|
+
const items: ContactItem[] = mapContactItems(data.items as never).map(({ field: _f, ...rest }) => rest);
|
|
51
14
|
const links = (data.links ?? [])
|
|
52
15
|
.map((l) => ({ label: clean(l?.label), href: safeHref(clean(l?.href)), newTab: l?.newTab ?? undefined }))
|
|
53
16
|
.filter((l): l is { label: string; href: string; newTab: boolean | undefined } => Boolean(l.label && l.href))
|
package/src/blocks/cms/types.ts
CHANGED
|
@@ -1,40 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Structural types for Tina schema fragments, so this package doesn't depend on tinacms.
|
|
3
|
-
* They match the shape of tinacms's `Template` / `TinaField` (v2). The real `defineConfig`
|
|
4
|
-
* accepts these objects as-is.
|
|
5
|
-
*/
|
|
6
|
-
export type TinaOption = string | { value: string; label: string };
|
|
7
|
-
|
|
8
|
-
export interface TinaField {
|
|
9
|
-
type: 'string' | 'number' | 'boolean' | 'image' | 'object' | 'datetime' | 'rich-text' | 'reference';
|
|
10
|
-
name: string;
|
|
11
|
-
label?: string;
|
|
12
|
-
description?: string;
|
|
13
|
-
required?: boolean;
|
|
14
|
-
list?: boolean;
|
|
15
|
-
options?: TinaOption[];
|
|
16
|
-
fields?: TinaField[];
|
|
17
|
-
ui?: {
|
|
18
|
-
component?: string;
|
|
19
|
-
validate?: (value: any) => string | undefined | void;
|
|
20
|
-
itemProps?: (item: any) => { label?: string };
|
|
21
|
-
defaultItem?: object | (() => object);
|
|
22
|
-
max?: number;
|
|
23
|
-
min?: number;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface TinaTemplate {
|
|
28
|
-
name: string;
|
|
29
|
-
label: string;
|
|
30
|
-
ui?: {
|
|
31
|
-
defaultItem?: object;
|
|
32
|
-
previewSrc?: string;
|
|
33
|
-
itemProps?: (item: any) => { label?: string };
|
|
34
|
-
};
|
|
35
|
-
fields: TinaField[];
|
|
36
|
-
}
|
|
37
|
-
|
|
1
|
+
/** Types shared by the CMS data → props mappers. */
|
|
38
2
|
/** What a CMS image string resolves to: an imported asset, or a URL with its size. */
|
|
39
3
|
export type ResolvedImage = import('astro').ImageMetadata | { src: string; width: number; height: number };
|
|
40
4
|
export type ImageResolver = (src: string) => ResolvedImage | undefined;
|
package/src/blocks/consent.ts
CHANGED
|
@@ -10,5 +10,5 @@
|
|
|
10
10
|
*/
|
|
11
11
|
export { hasConsent, setConsent, onConsentChange, openConsentSettings, getConsentRecord } from './scripts/consent-store';
|
|
12
12
|
export type { ConsentChangeDetail } from './scripts/consent-store';
|
|
13
|
-
export { consentCategoryPresets, CONSENT_EVENT, CONSENT_KEY } from './
|
|
14
|
-
export type { ConsentCategory, ConsentChoices, ConsentRecord } from './
|
|
13
|
+
export { consentCategoryPresets, CONSENT_EVENT, CONSENT_KEY } from './internal/consent';
|
|
14
|
+
export type { ConsentCategory, ConsentChoices, ConsentRecord } from './internal/consent';
|
package/src/blocks/index.ts
CHANGED
|
@@ -34,8 +34,8 @@ export { faqStructuredData } from './lib/faq';
|
|
|
34
34
|
export { locationStructuredData, directionsHref, mapEmbedSrc, mapSearchHref } from './lib/hours';
|
|
35
35
|
export { richTextPlain, isRichTextEmpty } from './lib/rich-text';
|
|
36
36
|
export type { RichTextValue, RichTextNode, RichTextRoot } from './lib/rich-text';
|
|
37
|
-
export { consentCategoryPresets } from './
|
|
38
|
-
export type { ConsentCategory } from './
|
|
37
|
+
export { consentCategoryPresets } from './internal/consent';
|
|
38
|
+
export type { ConsentCategory } from './internal/consent';
|
|
39
39
|
export type { SinnSlideChangeDetail } from './scripts/carousel';
|
|
40
40
|
export { blockIcons, blockIconNames } from './icons';
|
|
41
41
|
export type { BlockIconName } from './icons';
|
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
/** @internal Renders `actions` data as LinkButtons, then any `actions` slot content. */
|
|
3
3
|
import LinkButton from '../../primitives/LinkButton.astro';
|
|
4
4
|
import VisuallyHidden from '../../primitives/VisuallyHidden.astro';
|
|
5
|
-
import type { ActionItem
|
|
5
|
+
import type { ActionItem } from '../types';
|
|
6
6
|
import { actionVariant } from './util';
|
|
7
|
-
import {
|
|
7
|
+
import { sf } from './fields';
|
|
8
8
|
|
|
9
|
-
type Props = {
|
|
10
|
-
|
|
9
|
+
type Props = {
|
|
10
|
+
actions?: ActionItem[];
|
|
11
|
+
size?: 's' | 'm' | 'l';
|
|
12
|
+
class: string;
|
|
13
|
+
/** Path of the block (or item) that holds `actions`, for `data-sinn-field`. */
|
|
14
|
+
fieldPath?: string;
|
|
15
|
+
};
|
|
16
|
+
const { actions = [], size = 'l', class: className, fieldPath } = Astro.props;
|
|
11
17
|
const hasSlot = Astro.slots.has('default');
|
|
12
18
|
---
|
|
13
19
|
|
|
@@ -15,7 +21,7 @@ const hasSlot = Astro.slots.has('default');
|
|
|
15
21
|
(actions.length > 0 || hasSlot) && (
|
|
16
22
|
<div class={className}>
|
|
17
23
|
{actions.map((action, i) => (
|
|
18
|
-
<LinkButton href={action.href} size={size} variant={actionVariant(action, i)} newTab={action.newTab} {...
|
|
24
|
+
<LinkButton href={action.href} size={size} variant={actionVariant(action, i)} newTab={action.newTab} {...sf(fieldPath, action.field)}>
|
|
19
25
|
{action.label}
|
|
20
26
|
{action.srLabel && <VisuallyHidden> {action.srLabel}</VisuallyHidden>}
|
|
21
27
|
{action.arrow && (
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import Heading from '../../primitives/Heading.astro';
|
|
4
4
|
import Text from '../../primitives/Text.astro';
|
|
5
5
|
import type { TextSize } from '../../primitives/types';
|
|
6
|
-
import type { HeadingLevelNumber
|
|
7
|
-
import {
|
|
6
|
+
import type { HeadingLevelNumber } from '../types';
|
|
7
|
+
import { sf } from './fields';
|
|
8
8
|
|
|
9
9
|
type Props = {
|
|
10
10
|
eyebrow?: string;
|
|
@@ -15,17 +15,17 @@ type Props = {
|
|
|
15
15
|
/** Small muted heading ("Trusted by…"). Still a real heading. */
|
|
16
16
|
compact?: boolean;
|
|
17
17
|
description?: string;
|
|
18
|
-
|
|
18
|
+
fieldPath?: string;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
const { eyebrow, heading, headingId, headingLevel = 2, headingSize = '2xl', compact = false, description,
|
|
21
|
+
const { eyebrow, heading, headingId, headingLevel = 2, headingSize = '2xl', compact = false, description, fieldPath } = Astro.props;
|
|
22
22
|
const hasContent = Boolean(eyebrow || heading || description);
|
|
23
23
|
---
|
|
24
24
|
|
|
25
25
|
{
|
|
26
26
|
hasContent && (
|
|
27
27
|
<header class="sinn-block__header" data-compact={compact ? '' : undefined}>
|
|
28
|
-
{eyebrow && <p class="sinn-block__eyebrow" {...
|
|
28
|
+
{eyebrow && <p class="sinn-block__eyebrow" {...sf(fieldPath, 'eyebrow')}>{eyebrow}</p>}
|
|
29
29
|
{heading && (
|
|
30
30
|
<Heading
|
|
31
31
|
level={headingLevel}
|
|
@@ -34,12 +34,12 @@ const hasContent = Boolean(eyebrow || heading || description);
|
|
|
34
34
|
weight={compact ? 'semibold' : 'bold'}
|
|
35
35
|
id={headingId}
|
|
36
36
|
class="sinn-block__title"
|
|
37
|
-
{...
|
|
37
|
+
{...sf(fieldPath, 'heading')}
|
|
38
38
|
>
|
|
39
39
|
{heading}
|
|
40
40
|
</Heading>
|
|
41
41
|
)}
|
|
42
|
-
{description && <Text size="l" tone="muted" class="sinn-block__description" {...
|
|
42
|
+
{description && <Text size="l" tone="muted" class="sinn-block__description" {...sf(fieldPath, 'description')}>{description}</Text>}
|
|
43
43
|
</header>
|
|
44
44
|
)
|
|
45
45
|
}
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* @internal Shown in place of a block whose required content is missing, when placeholders
|
|
4
4
|
* are on (dev and CMS preview). Never rendered in production builds by default.
|
|
5
5
|
*/
|
|
6
|
-
type Props = { label: string; hint: string;
|
|
7
|
-
const { label, hint,
|
|
6
|
+
type Props = { label: string; hint: string; field?: string };
|
|
7
|
+
const { label, hint, field } = Astro.props;
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
-
<div class="sinn-block-placeholder" role="note" data-
|
|
10
|
+
<div class="sinn-block-placeholder" role="note" data-sinn-field={field}>
|
|
11
11
|
<strong>{label}</strong>
|
|
12
12
|
<span>{hint}</span>
|
|
13
13
|
</div>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal `data-sinn-field` annotations for SinnStackCMS visual editing (click a part of the
|
|
3
|
+
* preview to edit that field). Values are dotted paths into the content entry, e.g.
|
|
4
|
+
* `blocks.2.items.0.title`. BlockRenderer passes each block its path (`blocks.2`) when it is
|
|
5
|
+
* given `fieldPath`; without one, nothing is annotated and the HTML stays clean.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Joins path segments. Undefined when any segment is missing, so partial paths are never emitted. */
|
|
9
|
+
export function joinField(...segments: Array<string | number | null | undefined>): string | undefined {
|
|
10
|
+
if (!segments.length || segments.some((s) => s === undefined || s === null || s === '')) return undefined;
|
|
11
|
+
return segments.join('.');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Spread helper: {...sf(fieldPath, 'heading')} → { 'data-sinn-field': 'blocks.2.heading' } or {}. */
|
|
15
|
+
export function sf(...segments: Array<string | number | null | undefined>): Record<string, string> {
|
|
16
|
+
const value = joinField(...segments);
|
|
17
|
+
return value ? { 'data-sinn-field': value } : {};
|
|
18
|
+
}
|