@plitzi/sdk-authoring 0.37.9 → 0.38.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +601 -0
  2. package/dist/index.d.ts +2606 -248
  3. package/dist/index.js +15698 -9654
  4. package/package.json +13 -12
  5. package/skills/plitzi-authoring/CHEATSHEET.md +135 -0
  6. package/skills/plitzi-authoring/SKILL.md +71 -71
  7. package/skills/plitzi-authoring/recipes/carousel.ts +114 -0
  8. package/skills/plitzi-authoring/recipes/detail-page.ts +70 -0
  9. package/skills/plitzi-authoring/recipes/embed-and-svg.ts +48 -0
  10. package/skills/plitzi-authoring/recipes/every-few-seconds.ts +119 -0
  11. package/skills/plitzi-authoring/recipes/feature-flag.ts +24 -0
  12. package/skills/plitzi-authoring/recipes/filter-a-list.ts +63 -0
  13. package/skills/plitzi-authoring/recipes/forms-and-modals.ts +64 -0
  14. package/skills/plitzi-authoring/recipes/from-tailwind.ts +52 -0
  15. package/skills/plitzi-authoring/recipes/link-to-a-section.ts +35 -0
  16. package/skills/plitzi-authoring/recipes/link-with-data.ts +40 -0
  17. package/skills/plitzi-authoring/recipes/marquee.ts +57 -0
  18. package/skills/plitzi-authoring/recipes/plugin.ts +53 -0
  19. package/skills/plitzi-authoring/recipes/scroll-a-row.ts +79 -0
  20. package/skills/plitzi-authoring/recipes/show-data.ts +73 -0
  21. package/skills/plitzi-authoring/recipes/style-a-page.ts +45 -0
  22. package/skills/plitzi-authoring/recipes/typed-data.ts +64 -0
  23. package/skills/plitzi-authoring/recipes/usable-without-sight.ts +39 -0
  24. package/skills/plitzi-authoring/reference/accessibility.md +2 -2
  25. package/skills/plitzi-authoring/reference/authoring-errors.md +195 -53
  26. package/skills/plitzi-authoring/reference/colours-and-motion.md +63 -0
  27. package/skills/plitzi-authoring/reference/components.md +9 -1
  28. package/skills/plitzi-authoring/reference/data-and-visibility.md +29 -29
  29. package/skills/plitzi-authoring/reference/efficiency.md +53 -0
  30. package/skills/plitzi-authoring/reference/elements-and-styles.md +39 -24
  31. package/skills/plitzi-authoring/reference/feature-flags.md +78 -0
  32. package/skills/plitzi-authoring/reference/flows.md +25 -36
  33. package/skills/plitzi-authoring/reference/kept-state.md +28 -0
  34. package/skills/plitzi-authoring/reference/layouts.md +20 -3
  35. package/skills/plitzi-authoring/reference/lists.md +45 -16
  36. package/skills/plitzi-authoring/reference/plugins.md +15 -0
  37. package/skills/plitzi-authoring/reference/realtime.md +35 -0
  38. package/skills/plitzi-authoring/reference/review-checklist.md +8 -3
  39. package/skills/plitzi-authoring/reference/{templates-and-export.md → snippets-and-export.md} +9 -8
  40. package/skills/plitzi-authoring/reference/structure.md +29 -20
  41. package/skills/plitzi-authoring/reference/tailwind.md +19 -0
  42. package/skills/plitzi-authoring/reference/templates.md +6 -5
  43. package/skills/plitzi-authoring/reference/testing.md +11 -0
  44. package/skills/plitzi-authoring/reference/typed-sources.md +20 -0
  45. package/skills/plitzi-authoring/reference/validation.md +6 -2
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Something every few seconds — here a carousel that turns by itself: `onInterval` moves `state.slide` on, a hover
3
+ * pauses it, arrows and dots move it by hand, and each slide enters with an animation.
4
+ *
5
+ * Every slide is rendered and all but one hidden by `visible`. A hidden element is `display: none`, so its CSS
6
+ * animation runs again each time it is shown: that is the entrance. The clock ticks only while the tab is in view.
7
+ */
8
+ import {
9
+ button,
10
+ container,
11
+ cycleState,
12
+ heading,
13
+ list,
14
+ on,
15
+ onClick,
16
+ onInterval,
17
+ setState,
18
+ styles,
19
+ text,
20
+ activeWhen,
21
+ when
22
+ } from '@plitzi/sdk-authoring';
23
+
24
+ import type { SpaceSpec } from '@plitzi/sdk-authoring';
25
+
26
+ const SLIDES = [
27
+ { title: 'New in store', body: 'This week’s arrivals.' },
28
+ { title: 'Free delivery', body: 'On orders over 50 €.' },
29
+ { title: 'Trade in', body: 'Your old card, against a new one.' }
30
+ ];
31
+
32
+ // The slide after the last is the first: a cycle as long as the slides.
33
+ const next = cycleState({ key: 'slide', length: SLIDES.length });
34
+ const previous = cycleState({ key: 'slide', length: SLIDES.length, by: -1 });
35
+
36
+ const slide = styles('slide', { padding: '48px 24px', animation: 'slide-in 400ms ease-out' });
37
+
38
+ const dots = styles('dots', { display: 'flex', gap: '8px', margin: '0px', padding: '0px', 'list-style-type': 'none' });
39
+
40
+ const dot = styles('dot', {
41
+ css: {
42
+ width: '10px',
43
+ height: '10px',
44
+ padding: '0px',
45
+ 'border-radius': '999px',
46
+ border: '0px solid transparent',
47
+ 'background-color': 'var(--muted)'
48
+ },
49
+ variants: { active: { 'background-color': 'var(--primary)' } }
50
+ });
51
+
52
+ export const recipe: SpaceSpec = {
53
+ name: 'Carousel',
54
+ permanentUrl: 'carousel',
55
+ variables: {
56
+ color: {
57
+ muted: { light: '#c4c4cc', dark: '#3a3a44', default: '#c4c4cc' },
58
+ primary: { light: '#4f46e5', dark: '#818cf8', default: '#4f46e5' }
59
+ }
60
+ },
61
+ customCss:
62
+ '@keyframes slide-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }',
63
+ pages: [
64
+ {
65
+ id: 'home',
66
+ name: 'Home',
67
+ slug: '',
68
+ body: [
69
+ container({
70
+ id: 'carousel',
71
+ subType: 'section',
72
+ label: 'Offers',
73
+ flows: [
74
+ // Each tick turns it, unless the pointer is on it.
75
+ [onInterval(5000), when({ field: 'state.carouselPaused', operator: '!=', value: 'true' }, next)],
76
+ [on('onMouseEnter'), setState({ key: 'carouselPaused', type: 'boolean', value: true })],
77
+ [on('onMouseLeave'), setState({ key: 'carouselPaused', type: 'boolean', value: false })]
78
+ ],
79
+ children: [
80
+ list({
81
+ id: 'slides',
82
+ items: SLIDES,
83
+ children: [
84
+ container({
85
+ class: slide,
86
+ visible: { source: 'slides.index', template: '{{ source == (state.slide ?? 0) }}' },
87
+ children: [heading({ subType: 'h2', from: 'slides.item.title' }), text({ from: 'slides.item.body' })]
88
+ })
89
+ ]
90
+ }),
91
+ button({
92
+ content: 'Previous',
93
+ flows: [[onClick(), previous]]
94
+ }),
95
+ button({
96
+ content: 'Next',
97
+ flows: [[onClick(), next]]
98
+ }),
99
+ list({
100
+ id: 'dots',
101
+ class: dots,
102
+ items: SLIDES,
103
+ children: [
104
+ button({
105
+ content: '',
106
+ title: 'Show this offer',
107
+ class: dot,
108
+ bind: [activeWhen(dot, '{{ list_dots.index == (state.slide ?? 0) }}')],
109
+ flows: [[onClick(), setState({ key: 'slide', type: 'number', value: '{{ list_dots.index }}' })]]
110
+ })
111
+ ]
112
+ }),
113
+ text({ from: 'state.slide', as: '{{ (source ?? 0) + 1 }} of 3' })
114
+ ]
115
+ })
116
+ ]
117
+ }
118
+ ]
119
+ };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A feature behind a flag: declared once in the space, both versions gated — exactly one is ever rendered, and the
3
+ * flag is switched per environment without touching the space.
4
+ */
5
+ import { container, text } from '@plitzi/sdk-authoring';
6
+
7
+ import type { SpaceSpec } from '@plitzi/sdk-authoring';
8
+
9
+ export const recipe: SpaceSpec = {
10
+ name: 'Flags',
11
+ permanentUrl: 'flags',
12
+ flags: { newCheckout: { description: 'The one-step checkout', value: false, rules: [] } },
13
+ pages: [
14
+ {
15
+ id: 'home',
16
+ name: 'Home',
17
+ slug: '',
18
+ body: [
19
+ container({ id: 'checkout-new', flag: 'newCheckout', children: [text('One step')] }),
20
+ container({ id: 'checkout-old', flag: '!newCheckout', children: [text('Three steps')] })
21
+ ]
22
+ }
23
+ ]
24
+ };
@@ -0,0 +1,63 @@
1
+ /* eslint-disable quotes -- templates quote their own strings, and read best in the other quotes */
2
+ /**
3
+ * Filter and sort a list: a select writes the chosen category to `state`, and the list is bound through a template
4
+ * that hands over its VALUE — only the matching rows are rendered, with a count and an empty state over the same rows.
5
+ */
6
+ import { apiContainer, formControl, list, named, on, setState, text } from '@plitzi/sdk-authoring';
7
+
8
+ import type { SpaceSpec } from '@plitzi/sdk-authoring';
9
+
10
+ // One predicate, read three times: the rows, their count, and whether there are none.
11
+ const shown =
12
+ "source|filter(p => (state.category ?? 'all') == 'all' or p.category == state.category)|sort((a, b) => a.price - b.price)";
13
+
14
+ export const recipe: SpaceSpec = {
15
+ name: 'Filtered',
16
+ permanentUrl: 'filtered',
17
+ pages: [
18
+ {
19
+ id: 'home',
20
+ name: 'Home',
21
+ slug: '',
22
+ body: [
23
+ // A control outside a form keeps its own value and fires `onChange` with `{ value, name }`: no form needed.
24
+ formControl({
25
+ name: 'category',
26
+ label: 'Category',
27
+ subType: 'select',
28
+ options: [
29
+ { label: 'Everything', value: 'all' },
30
+ { label: 'Processors', value: 'cpu' },
31
+ { label: 'Graphics cards', value: 'gpu' }
32
+ ],
33
+ defaultValue: 'all',
34
+ // A filter always has an answer: the select is not a question that must be filled in.
35
+ required: false,
36
+ flows: [
37
+ [named('picked', on('onChange')), setState({ key: 'category', type: 'text', value: '{{ picked.value }}' })]
38
+ ]
39
+ }),
40
+ apiContainer({
41
+ id: 'catalog',
42
+ query: '/data/products.json',
43
+ cache: true,
44
+ children: [
45
+ text({ from: 'catalog.data.products', as: `{{ ${shown}|length }} shown` }),
46
+ list({
47
+ id: 'shown',
48
+ from: 'catalog.data.products',
49
+ as: `{{ ${shown} }}`,
50
+ children: [text({ from: 'shown.item.title' })]
51
+ }),
52
+ text('Nothing in that category.', {
53
+ visible: {
54
+ source: 'catalog.data.products',
55
+ template: `{{ source is defined and ${shown}|length == 0 }}`
56
+ }
57
+ })
58
+ ]
59
+ })
60
+ ]
61
+ }
62
+ ]
63
+ };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Do something on a click or a submit: a flow is `[trigger, steps…]`. A form manages its own submit and hands its
3
+ * values to the flow; a modal starts hidden and a step opens it.
4
+ */
5
+ import {
6
+ button,
7
+ closeModal,
8
+ fontAwesome,
9
+ form,
10
+ formControl,
11
+ modalContainer,
12
+ named,
13
+ onClick,
14
+ onSubmit,
15
+ openModal,
16
+ setState,
17
+ text,
18
+ toggleState
19
+ } from '@plitzi/sdk-authoring';
20
+
21
+ import type { SpaceSpec } from '@plitzi/sdk-authoring';
22
+
23
+ export const recipe: SpaceSpec = {
24
+ name: 'Flows',
25
+ permanentUrl: 'flows',
26
+ pages: [
27
+ {
28
+ id: 'home',
29
+ name: 'Home',
30
+ slug: '',
31
+ body: [
32
+ button({ content: 'Save', flows: [[onClick(), setState({ key: 'saved', type: 'boolean', value: true })]] }),
33
+ // A switch is named for how it leaves its default: shown until somebody hides it.
34
+ button({ content: 'Hide details', flows: [[onClick(), toggleState({ key: 'detailsHidden' })]] }),
35
+ form({
36
+ id: 'signup',
37
+ managedByInteractions: true,
38
+ flows: [
39
+ [named('sent', onSubmit()), setState({ key: 'email', type: 'text', value: '{{ sent.values.email }}' })]
40
+ ],
41
+ children: [
42
+ formControl({ name: 'email', label: 'Email', subType: 'email' }),
43
+ button({ content: 'Sign up', subType: 'submit' })
44
+ ]
45
+ }),
46
+ modalContainer({
47
+ id: 'details',
48
+ visible: false,
49
+ title: 'Details',
50
+ children: [
51
+ text('What the modal says.'),
52
+ button({
53
+ content: '',
54
+ title: 'Close',
55
+ children: [fontAwesome({ icon: 'fa-solid fa-xmark' })],
56
+ flows: [[onClick(), closeModal('details')]]
57
+ })
58
+ ]
59
+ }),
60
+ button({ content: 'Open', flows: [[onClick(), openModal('details')]] })
61
+ ]
62
+ }
63
+ ]
64
+ };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * A design written in Tailwind classes, kept as classes the builder edits: `tw()` turns them into rules when the space
3
+ * is written. The space's colours stay tokens with both themes — `createTw({ colors: tokens(variables) })` — and
4
+ * Tailwind's own palette is there for the rest.
5
+ */
6
+ import { container, createTw, heading, link, styles, text, tokens } from '@plitzi/sdk-authoring';
7
+
8
+ import type { SpaceSpec } from '@plitzi/sdk-authoring';
9
+
10
+ const variables = {
11
+ color: {
12
+ surface: { light: '#ffffff', dark: '#0f172a', default: '#ffffff' },
13
+ ink: { light: '#0f172a', dark: '#e2e8f0', default: '#0f172a' },
14
+ accent: { light: '#0891b2', dark: '#22d3ee', default: '#0891b2' }
15
+ }
16
+ } satisfies SpaceSpec['variables'];
17
+
18
+ const tw = createTw({ colors: tokens(variables) });
19
+
20
+ const grid = styles('feature-grid', tw('grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3'));
21
+ // The card's title moves with the card's hover: an ancestor named by its class.
22
+ const card = styles(
23
+ 'feature-card',
24
+ tw('rounded-xl border border-ink/10 bg-surface p-6 transition-shadow hover:shadow-lg')
25
+ );
26
+ const title = styles('feature-title', tw('text-lg font-semibold text-ink group-hover/feature-card:text-accent'));
27
+ const cta = styles(
28
+ 'feature-cta',
29
+ tw('inline-flex items-center gap-2 rounded-full bg-accent px-5 py-2 text-sm font-medium text-white hover:scale-105')
30
+ );
31
+
32
+ export const recipe: SpaceSpec = {
33
+ name: 'Features',
34
+ permanentUrl: 'features',
35
+ variables,
36
+ pages: [
37
+ {
38
+ id: 'home',
39
+ name: 'Home',
40
+ slug: '',
41
+ body: [
42
+ container({
43
+ class: grid,
44
+ children: ['Fast', 'Typed', 'Yours'].map(name =>
45
+ container({ class: card, children: [heading(name, { subType: 'h3', class: title }), text('…')] })
46
+ )
47
+ }),
48
+ link({ href: '/start', class: cta, children: [text('Get started')] })
49
+ ]
50
+ }
51
+ ]
52
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Link to a section: the section carries an `anchor` — its id in the page; an element's `id` is only its name in the
3
+ * space, `data-id` in the DOM — and a link's `hash` lands on it, from any page, even when the section renders late.
4
+ */
5
+ import { container, heading, link, text } from '@plitzi/sdk-authoring';
6
+
7
+ import type { SpaceSpec } from '@plitzi/sdk-authoring';
8
+
9
+ export const recipe: SpaceSpec = {
10
+ name: 'Sections',
11
+ permanentUrl: 'sections',
12
+ pages: [
13
+ {
14
+ id: 'home',
15
+ name: 'Home',
16
+ slug: '',
17
+ body: [
18
+ link({ href: 'home', hash: 'plans', children: [text('See the plans')] }),
19
+ container({
20
+ id: 'plans-section',
21
+ subType: 'section',
22
+ anchor: 'plans',
23
+ children: [heading('Plans', { subType: 'h2' }), text('Three of them.')]
24
+ })
25
+ ]
26
+ },
27
+ {
28
+ id: 'about',
29
+ name: 'About',
30
+ slug: 'about',
31
+ // → /#plans
32
+ body: [link({ href: 'home', hash: 'plans', children: [text('Plans')] })]
33
+ }
34
+ ]
35
+ };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * A link built from the row it is in — here "ask about this product" on WhatsApp, with the product's name in the
3
+ * message. An attribute resolves a name with filters, so the text is encoded with `url_encode`.
4
+ */
5
+ import { apiContainer, fontAwesome, link, list, text } from '@plitzi/sdk-authoring';
6
+
7
+ import type { SpaceSpec } from '@plitzi/sdk-authoring';
8
+
9
+ export const recipe: SpaceSpec = {
10
+ name: 'Contact',
11
+ permanentUrl: 'contact',
12
+ pages: [
13
+ {
14
+ id: 'home',
15
+ name: 'Home',
16
+ slug: '',
17
+ body: [
18
+ apiContainer({
19
+ id: 'catalog',
20
+ query: '/data/products.json',
21
+ cache: true,
22
+ children: [
23
+ list({
24
+ id: 'products',
25
+ items: 'catalog.data.products',
26
+ children: [
27
+ link({
28
+ target: 'blank',
29
+ href: 'https://wa.me/34600000000?text={{ list_products.item.title|url_encode }}',
30
+ children: [fontAwesome({ icon: 'fa-brands fa-whatsapp' }), text('Ask about it')]
31
+ }),
32
+ link({ href: 'mailto:shop@example.com', children: [text('Write to us')] })
33
+ ]
34
+ })
35
+ ]
36
+ })
37
+ ]
38
+ }
39
+ ]
40
+ };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * A marquee: a row of names that scrolls for ever and stops under the pointer. The items are rendered three times
3
+ * and the keyframe moves the track by a third, so the end meets the start with no jump.
4
+ */
5
+ import { apiContainer, container, list, styles, text } from '@plitzi/sdk-authoring';
6
+
7
+ import type { SpaceSpec } from '@plitzi/sdk-authoring';
8
+
9
+ const marquee = styles('marquee', { overflow: 'hidden' });
10
+
11
+ const track = styles('marquee-track', {
12
+ css: {
13
+ display: 'flex',
14
+ gap: '48px',
15
+ width: 'max-content',
16
+ margin: '0px',
17
+ padding: '0px',
18
+ 'list-style-type': 'none',
19
+ animation: 'marquee 30s linear infinite'
20
+ },
21
+ // An ancestor's state reaches inside it: hovering the band pauses the track.
22
+ ancestors: { [marquee.name]: { states: { hover: { 'animation-play-state': 'paused' } } } }
23
+ });
24
+
25
+ export const recipe: SpaceSpec = {
26
+ name: 'Marquee',
27
+ permanentUrl: 'marquee',
28
+ customCss: '@keyframes marquee { to { transform: translateX(calc(-100% / 3)); } }',
29
+ pages: [
30
+ {
31
+ id: 'home',
32
+ name: 'Home',
33
+ slug: '',
34
+ body: [
35
+ apiContainer({
36
+ id: 'catalog',
37
+ query: '/data/brands.json',
38
+ cache: true,
39
+ children: [
40
+ container({
41
+ class: marquee,
42
+ children: [
43
+ list({
44
+ id: 'brands',
45
+ class: track,
46
+ from: 'catalog.data.brands',
47
+ as: '{{ source|merge(source)|merge(source) }}',
48
+ children: [text({ from: 'brands.item' })]
49
+ })
50
+ ]
51
+ })
52
+ ]
53
+ })
54
+ ]
55
+ }
56
+ ]
57
+ };
@@ -0,0 +1,53 @@
1
+ /**
2
+ * An element of your own (a plugin): authored from its declaration — the one `plitzi add plugin` writes — so a flow on
3
+ * its events, a step to its actions and its attributes are all checked. Hand the declaration to `authorSpace` too.
4
+ */
5
+ import {
6
+ button,
7
+ declaredCallback,
8
+ declaredTrigger,
9
+ defineElement,
10
+ named,
11
+ onClick,
12
+ setState
13
+ } from '@plitzi/sdk-authoring';
14
+
15
+ import type { PluginDeclarationData, SpaceSpec } from '@plitzi/sdk-authoring';
16
+
17
+ // In a project: `import declaration from './plugins/seatPicker/declaration';`
18
+ const declaration = {
19
+ type: 'seatPicker',
20
+ triggers: { onPick: { action: 'onPick', title: 'On Pick', type: 'trigger', params: {}, preview: { seat: '' } } },
21
+ callbacks: { reset: { action: 'reset', title: 'Reset', type: 'callback', params: {} } },
22
+ content: { attributes: { rows: 10 }, definition: { label: 'Seat Picker' } }
23
+ } as const;
24
+
25
+ const seatPicker = defineElement<{ rows?: number }>(declaration);
26
+
27
+ // `authorSpace(recipe, { plugins })` — in a project, `src/plugins/declarations.ts` lists them all.
28
+ export const plugins: PluginDeclarationData[] = [declaration];
29
+
30
+ export const recipe: SpaceSpec = {
31
+ name: 'Seats',
32
+ permanentUrl: 'seats',
33
+ pages: [
34
+ {
35
+ id: 'home',
36
+ name: 'Home',
37
+ slug: '',
38
+ body: [
39
+ seatPicker({
40
+ id: 'seats',
41
+ rows: 12,
42
+ flows: [
43
+ [
44
+ named('picked', declaredTrigger(declaration, 'onPick')),
45
+ setState({ key: 'seat', type: 'text', value: '{{ picked.seat }}' })
46
+ ]
47
+ ]
48
+ }),
49
+ button({ content: 'Clear', flows: [[onClick(), declaredCallback(declaration, 'reset', { on: 'seats' })]] })
50
+ ]
51
+ }
52
+ ]
53
+ };
@@ -0,0 +1,79 @@
1
+ /**
2
+ * A row that scrolls sideways — swiped on a phone, moved by arrows elsewhere: the row's box scrolls
3
+ * (`overflow-x: auto`), the arrows move it by most of what it shows, and `onScroll` hides each arrow at its end.
4
+ */
5
+ import {
6
+ button,
7
+ container,
8
+ list,
9
+ named,
10
+ onClick,
11
+ onScroll,
12
+ scrollBy,
13
+ setState,
14
+ styles,
15
+ text
16
+ } from '@plitzi/sdk-authoring';
17
+
18
+ import type { SpaceSpec } from '@plitzi/sdk-authoring';
19
+
20
+ const row = styles('card-row', {
21
+ display: 'flex',
22
+ gap: '16px',
23
+ 'overflow-x': 'auto',
24
+ // Stops on a card, never between two.
25
+ 'scroll-snap-type': 'x mandatory',
26
+ margin: '0px',
27
+ padding: '0px',
28
+ 'list-style-type': 'none'
29
+ });
30
+
31
+ const card = styles('row-card', { 'flex-shrink': '0', width: '240px', padding: '16px', 'scroll-snap-align': 'start' });
32
+
33
+ const CATEGORIES = ['Processors', 'Graphics cards', 'Memory', 'Storage', 'Monitors', 'Keyboards', 'Mice', 'Cases'];
34
+
35
+ export const recipe: SpaceSpec = {
36
+ name: 'Row',
37
+ permanentUrl: 'row',
38
+ pages: [
39
+ {
40
+ id: 'home',
41
+ name: 'Home',
42
+ slug: '',
43
+ body: [
44
+ container({
45
+ children: [
46
+ // Shown until the row says it is at that end: the arrows are there before anybody scrolls.
47
+ button({
48
+ content: '',
49
+ title: 'Previous categories',
50
+ visible: '!state.rowAtStart',
51
+ children: [text('‹')],
52
+ flows: [[onClick(), scrollBy('categories', { x: '-80%' })]]
53
+ }),
54
+ list({
55
+ id: 'categories',
56
+ class: row,
57
+ items: CATEGORIES,
58
+ flows: [
59
+ [
60
+ named('moved', onScroll()),
61
+ setState({ key: 'rowAtStart', type: 'boolean', value: '{{ moved.atStart }}' }),
62
+ setState({ key: 'rowAtEnd', type: 'boolean', value: '{{ moved.atEnd }}' })
63
+ ]
64
+ ],
65
+ children: [text({ class: card, from: 'categories.item' })]
66
+ }),
67
+ button({
68
+ content: '',
69
+ title: 'More categories',
70
+ visible: '!state.rowAtEnd',
71
+ children: [text('›')],
72
+ flows: [[onClick(), scrollBy('categories', { x: '80%' })]]
73
+ })
74
+ ]
75
+ })
76
+ ]
77
+ }
78
+ ]
79
+ };
@@ -0,0 +1,73 @@
1
+ /* eslint-disable quotes -- templates quote their own strings, and read best in the other quotes */
2
+ /**
3
+ * Show data with no backend: a JSON file the project serves (`public/data/products.json`), read by a provider — one
4
+ * card per product, a skeleton while it loads, a count, a computed value, and an empty state that never flashes.
5
+ */
6
+ import { apiContainer, container, heading, list, styles, text } from '@plitzi/sdk-authoring';
7
+
8
+ import type { SpaceSpec } from '@plitzi/sdk-authoring';
9
+
10
+ // A list is a `<ul>`: a grid of cards takes the bullets and the indent off.
11
+ const grid = styles('product-grid', {
12
+ display: 'grid',
13
+ 'grid-template-columns': 'repeat(auto-fill, minmax(220px, 1fr))',
14
+ gap: '16px',
15
+ margin: '0px',
16
+ padding: '0px',
17
+ 'list-style-type': 'none'
18
+ });
19
+
20
+ const card = styles('product-card', { padding: '16px', 'border-radius': '12px', 'background-color': 'var(--card)' });
21
+
22
+ // The shape of what is coming, shown until the file answers.
23
+ const skeleton = styles('product-skeleton', {
24
+ height: '96px',
25
+ 'border-radius': '12px',
26
+ 'background-color': 'var(--card)'
27
+ });
28
+
29
+ export const recipe: SpaceSpec = {
30
+ name: 'Catalogue',
31
+ permanentUrl: 'catalogue',
32
+ variables: { color: { card: { light: '#ffffff', dark: '#16161d', default: '#ffffff' } } },
33
+ // Read anywhere as `computed.cartCount`, declared once.
34
+ computed: { cartCount: '{{ (state.cart ?? [])|length }}' },
35
+ // How a price is shown, said once: `text({ from: …, as: 'price' })` anywhere.
36
+ formats: { price: "{{ source|currency('USD', 'en', { trimZeros: true }) }}" },
37
+ pages: [
38
+ {
39
+ id: 'home',
40
+ name: 'Home',
41
+ slug: '',
42
+ body: [
43
+ text({ from: 'computed.cartCount', as: '{{ source }} in the cart' }),
44
+ apiContainer({
45
+ id: 'catalog',
46
+ query: '/data/products.json',
47
+ cache: true,
48
+ // Shown in place of the rest until the first answer, and gone after it.
49
+ loadingSlot: 'catalog-skeleton',
50
+ children: [
51
+ container({ id: 'catalog-skeleton', class: skeleton }),
52
+ // Inside a template a source is spelled in full; a binding's own source is `source`.
53
+ text({ from: 'catalog.data.products', as: '{{ source|length }} products' }),
54
+ list({
55
+ id: 'products',
56
+ class: grid,
57
+ items: 'catalog.data.products',
58
+ children: [
59
+ // Inside a row, a binding names the row short (`products.item`), a template in full (`list_products`).
60
+ heading({ subType: 'h3', class: card, from: 'products.item.title' }),
61
+ text({ from: 'products.item.price', as: 'price' })
62
+ ]
63
+ }),
64
+ // Revealed by the data, so it starts hidden: nothing flashes while the file loads.
65
+ text('No products yet.', {
66
+ visible: { source: 'catalog.data.products', template: '{{ source is defined and source|length == 0 }}' }
67
+ })
68
+ ]
69
+ })
70
+ ]
71
+ }
72
+ ]
73
+ };