@plitzi/sdk-authoring 0.38.6 → 0.38.8

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 (29) hide show
  1. package/CHANGELOG.md +381 -0
  2. package/dist/index-src.js +26687 -0
  3. package/dist/index.d.ts +1174 -367
  4. package/dist/index.js +2 -24803
  5. package/dist/node.d.ts +2820 -0
  6. package/dist/node.js +610 -13
  7. package/package.json +7 -7
  8. package/skills/plitzi-authoring/CHEATSHEET.md +2 -2
  9. package/skills/plitzi-authoring/SKILL.md +34 -148
  10. package/skills/plitzi-authoring/recipes/plugin.ts +1 -1
  11. package/skills/plitzi-authoring/reference/accessibility.md +3 -4
  12. package/skills/plitzi-authoring/reference/auth.md +75 -0
  13. package/skills/plitzi-authoring/reference/authoring-errors.md +19 -4
  14. package/skills/plitzi-authoring/reference/colours-and-motion.md +3 -2
  15. package/skills/plitzi-authoring/reference/drawing.md +1 -1
  16. package/skills/plitzi-authoring/reference/efficiency.md +5 -2
  17. package/skills/plitzi-authoring/reference/elements-and-styles.md +23 -23
  18. package/skills/plitzi-authoring/reference/flows.md +15 -8
  19. package/skills/plitzi-authoring/reference/index.md +33 -0
  20. package/skills/plitzi-authoring/reference/layouts.md +15 -18
  21. package/skills/plitzi-authoring/reference/plugins.md +3 -3
  22. package/skills/plitzi-authoring/reference/recipes.md +25 -0
  23. package/skills/plitzi-authoring/reference/review-checklist.md +2 -1
  24. package/skills/plitzi-authoring/reference/rules.md +61 -0
  25. package/skills/plitzi-authoring/reference/snippets-and-export.md +2 -2
  26. package/skills/plitzi-authoring/reference/structure.md +4 -3
  27. package/skills/plitzi-authoring/reference/testing.md +1 -1
  28. package/skills/plitzi-authoring/reference/validation.md +1 -1
  29. package/dist/index-compactSvg.js +0 -16
@@ -18,7 +18,7 @@ container([hero, grid]) // an array is the children
18
18
  | `id` | the ONE name this element answers to — its key in the document, a binding's source, a step's target. Unique across the WHOLE space |
19
19
  | `class` | a shared class: a `styles()` declaration or a name from the space's `classes`; a list for several. Exclusive with `css` |
20
20
  | `css` | rules of this element's own: one set, or one per breakpoint (`{ desktop, tablet, mobile }`) |
21
- | `states` | `hover`, `focus-visible`, `current` (a link to the page shown), `hidden`… beside the element's own `css` |
21
+ | `states` | `hover`, `focus-visible`, `current` (the chosen link, toggle, tab), `expanded`, `first`/`last`/`odd`/`even`, `hidden`… |
22
22
  | `variant` | a variant of the class it wears (when the class declares it) or of its type |
23
23
  | `slots` | a class for one of the element's OTHER selectors — a form control's `input` |
24
24
  | `bind` | where a value comes from |
@@ -73,13 +73,9 @@ indented with space below it: `{ margin: '0px', padding: '0px' }` on its class t
73
73
  children sit in the parent's layout and a `class` on it styles nothing (`STYLE_WITHOUT_TAG`). Put the layout on the
74
74
  parent, or give it `attributes: { subType: 'div' }`.
75
75
 
76
- A type this SDK does not ship — a plugin — is authored the same way: `defineElement<Props>({ type, … })`,
77
- `element<Props>('type', props)`, or `elementsFromManifest(manifest)`. See [plugins](plugins.md).
76
+ A plugin's type is authored the same way: `defineElement<Props>({ type, … })` — see [plugins](plugins.md).
78
77
 
79
- **What a type takes, answered by the package** instead of the 7,000-line `.d.ts`: every catalogue is exported, keyed by
80
- type — `elementCatalog` (what it is for), `elementDefaultAttributes`, `elementAttributeNames`, `elementTriggers`,
81
- `elementCallbacks`, `elementSlots`, `elementSourceTypes`, `elementLeafTypes`, plus `BUILTIN_TRANSFORMERS` — and
82
- `npx @plitzi/cli explain formControl` prints them for one type.
78
+ **What a type takes:** `npx @plitzi/cli explain formControl`, or the exported catalogues ([validation.md](validation.md)).
83
79
 
84
80
  ## CSS
85
81
 
@@ -111,15 +107,20 @@ const card = styles('card', {
111
107
  container({ class: card, children: [ … ] });
112
108
  ```
113
109
 
114
- - A flat object is the base rules; `{ css, states, variants, ancestors }` when there is more. Each part may be written
110
+ - A flat object is the base rules; `{ css, states, variants, ancestors, pseudos, conditions }` when there is more. Each part may be written
115
111
  per breakpoint.
116
- - **Share a rule as a class, never as a spread.** Spreading a `const` into each element's `css` shares the source and
117
- duplicates the document: one selector per element, so restyling one card in the builder restyles one card.
112
+ - **Share a rule as a class, never as a spread** into each element's `css`: that is one selector per element, so
113
+ restyling one card in the builder restyles one card.
118
114
  - **Build a family from a plain object**, not by layering classes: `styles('button-primary', { ...buttonBase, … })`.
115
+ - Of two classes on an element, the one the stylesheet writes later wins (first met; a breakpoint's after the base),
116
+ not the list's last: write the longhands a class means (`class-overrides-class`).
119
117
  - One name declared twice with rules that disagree is refused. Declare a class once, in the module that owns it, and
120
118
  import it.
121
119
  - `ancestors: { [sidebar.name]: { variants: { collapsed: { display: 'none' } } } }` styles an element by the state or
122
- variant of an ancestor class — the way to react to a parent's hover or collapse without a flow.
120
+ variant of an ancestor class — the way to react to a parent's hover or collapse without a flow; `'>'` is the parent,
121
+ whatever it wears (a component's part: `{ '>': { states: { expanded: … } } }`).
122
+ - `pseudos: { after: { content: '"→"' } }` (`before`/`after` need a quoted `content`; also `selection`, `marker`,
123
+ `placeholder`, `first-letter`, `first-line`). `conditions: { 'motion-reduce': …, 'container (max-width: 30rem)': … }`.
123
124
  - **`hidden` is how an element looks while its `visible` says no** — where it goes as it hides, and where it comes
124
125
  from as it shows. Give the class a transition that includes `display` with `allow-discrete`, and a panel fades or
125
126
  slides instead of blinking; the transition on the base is the way in, the one in `hidden` the way out:
@@ -142,16 +143,15 @@ container({ class: card, children: [ … ] });
142
143
  What is inside follows its container with `ancestors: { [panel.name]: { states: { hidden: { … } } } }` — a
143
144
  different `transition-delay` per item staggers them. A container whose children mount only while it shows
144
145
  (`loadStrategy: 'visible'`) empties before it can leave: use `'lazy'` on one that animates out.
145
- - **The navigation of a site goes in a layout, once.** A link to the page being shown marks itself, and its class
146
- dresses it with `states: { current: { … } }` — never a class picked per page, which forces a copy of the header into
147
- every page.
148
- - **`:hover` is part of the selector, not a rule in `customCss`.** `customCss` is for what no class can say:
149
- keyframes, pseudo-elements, a rule across two unrelated elements, the inside of a third-party widget.
150
- - Per element TYPE defaults go in `elements: { heading: { base, states, variants, slots } }` — a whole type at once.
151
- - **Slots** are an element's other selectors: a `formControl`'s `input`, `label`, `error`; a `modalContainer`'s
152
- `backgroundContainer`, `rootContainer`, `headerContainer`, `headerTitle`, `headerCloseButton`, `bodyContainer`; a
153
- `dialogContainer`'s footer and buttons. `elementSlots` lists them all by type. Style one element's with `slots`, a
154
- whole type's with `elements.<type>.slots`.
146
+ - **The navigation goes in a layout, once:** a link to the page shown dresses itself with its class's
147
+ `states: { current: { … } }` — never a class picked per page, which copies the header into every page.
148
+ - **`:hover` is part of the selector, not a rule in `customCss`.** `customCss` is for what no class can say: a rule
149
+ across two unrelated elements, the inside of a third-party widget.
150
+ - Per element TYPE defaults go in `elements: { heading: { base, states, variants, pseudos, slots } }` — a whole type.
151
+ - **Slots** are an element's parts (not `customCss`): a `formControl`'s `input` (the box), `field` (its `<input>`),
152
+ `label`, `requiredMark`, `error`; a `markdown`'s or `richText`'s `heading`, `heading2`, `link`, `codeBlockFrame`…;
153
+ a `pagination`'s `page` (the one shown: its `current` state). `plitzi explain <type>` lists them. Style one
154
+ element's with `slots`, a type's with `elements.<type>.slots`.
155
155
  - A `modalContainer` / `dialogContainer` is fixed to the viewport, as tall as its content up to the screen, and 500px
156
156
  wide up to the screen; theme its look through its slots.
157
157
 
@@ -159,7 +159,7 @@ container({ class: card, children: [ … ] });
159
159
  already speak in variant names — `variantFrom(pill, 'runs.item.status', { template: "{{ source == 'completed' ?
160
160
  'ok' : 'failed' }}" })`. The binding's key names the CLASS; never write it by hand. A variant while a condition holds
161
161
  — the dot of the slide on screen — is `activeWhen(dot, '{{ list_dots.index == state.slide }}')` (`active`, else
162
- `idle`); for "the current page", `activeOn` in [layouts.md](layouts.md).
162
+ `idle`); for "the current page", `current` in [layouts.md](layouts.md).
163
163
 
164
164
  ## From Tailwind classes
165
165
 
@@ -169,4 +169,4 @@ A design written in Tailwind classes becomes classes the builder edits with `sty
169
169
  ## Colours, themes and motion
170
170
 
171
171
  Every colour is a token with a light and a dark value, read as `var(--name)` (or `tokens(variables)`); keyframes go in
172
- `customCss` — see [colours-and-motion.md](colours-and-motion.md).
172
+ the space's `keyframes` — see [colours-and-motion.md](colours-and-motion.md).
@@ -21,8 +21,8 @@ source — `when({ field: 'flags.newCheckout', operator: '=', value: true }, …
21
21
  same flags, decided on the server. Use the step builders — they fill in where a step runs and what it takes:
22
22
 
23
23
  - **Where it runs.** A global callback registers under its source MODULE (`state`, `auth`, `actions`), an element
24
- callback under an element's id, a utility under nothing. Naming either half wrong is a control that does nothing,
25
- with no error — which is why the builders exist.
24
+ callback under an element's id, a utility under nothing. Either half named wrong is a control that silently does
25
+ nothing.
26
26
  - **Which `setState`.** `setState({ key })` writes `runtime.state.<key>` and is read as `state.<key>`; never put
27
27
  `state.` in the key. `updateElement(…)` changes one element's own attribute or state.
28
28
  - **Flip in one step.** `toggleState({ key })` for app state, `toggleElement({ category: 'state', key: 'visibility' },
@@ -48,7 +48,7 @@ Name the trigger (`named('changed', on('onChange'))`) and read its payload as `{
48
48
 
49
49
  | Trigger | Payload |
50
50
  | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------- |
51
- | `onChange` (formControl) | `value` (a boolean for a checkbox), `name` |
51
+ | `onChange` (formControl) | `value` (a boolean for a checkbox or switch), `name` |
52
52
  | `onSubmit` (form) | `values` (by control `name`), `actionUrl`, `method` |
53
53
  | `onPageLoad` (page) | `pageId`, `routeParams`, `queryParams` |
54
54
  | `onApiSuccess` / `onApiError` (apiContainer) | `url`, `method`, `status`, `data` |
@@ -61,6 +61,10 @@ Name the trigger (`named('changed', on('onChange'))`) and read its payload as `{
61
61
  `named('quote', step)` is how a later step reads an earlier one: `{{ quote.output.total }}`. The trigger too:
62
62
  `named('submitted', onSubmit())` → `{{ submitted.values.email }}`. Unnamed steps get ids nothing can refer to.
63
63
 
64
+ `whenSucceeded` / `whenFailed` read a server action's `status` (`runServerAction` only); any other step is asked what
65
+ it publishes (`npx @plitzi/cli explain login` lists it) — after `named('signedIn', authLogin(…))`,
66
+ `when({ field: 'signedIn.ok', operator: '=', value: true }, …)`.
67
+
64
68
  A step's params are templates, evaluated in full (conditions, loops, filters). A source in them is named in full:
65
69
  a row's button posts `{ jobId: '{{ list_jobRows.item.id }}' }` — the row that was clicked; the short name is refused.
66
70
 
@@ -75,7 +79,7 @@ so `when({ field: 'sent.values.code', operator: '=', value: '' }, …)` never ho
75
79
  ## Writes and what they refresh
76
80
 
77
81
  `webHook` (not GET) refreshes every request to its own site when it succeeds; `runServerAction` refreshes
78
- everything. Say what it should refresh — `invalidateQueries: 'elements', invalidateElements: ['orders']` — or
82
+ everything, server-driven providers included. Say what it should refresh — `invalidateQueries: 'elements', invalidateElements: ['orders']` — or
79
83
  `'none'` for a step that only reads, or when a refresh would make the page act on the new answer mid-flow.
80
84
 
81
85
  ## Triggers belong to the element that fires them
@@ -134,10 +138,13 @@ without a word.
134
138
 
135
139
  `addNotification({ content: 'Saved', appearance: 'success' })` — `appearance` is `success`, `danger`, `warning` or
136
140
  `info`. They follow the page's theme; how they look is the space's `notifications` — colours (`background`, `text`,
137
- `success`, `danger`, `warning`, `info`) and shape (`radius`, `font`, `fontSize`, `border`, `shadow`, `padding`):
138
- `notifications: { background: 'var(--card)', text: 'var(--foreground)', success: 'var(--accent)', radius: '12px',
139
- font: 'var(--font-sans)', border: '1px solid var(--border)', shadow: 'var(--shadow-lg)' }`. The toast carries no class
140
- of the space's, so this — not a `.Toastify__toast` rule in `customCss` — is where it is dressed.
141
+ `success`, `danger`, `warning`, `info`), shape (`radius`, `font`, `fontSize`, `fontWeight`, `lineHeight`, `minHeight`,
142
+ `border`, `shadow`, `padding`) and the parts inside (`iconSize`, `iconGap`, `closeColor`, `closeOpacity`,
143
+ `progressHeight`), one CSS value each: `notifications: { background: 'var(--card)', radius: '12px', iconSize: '18px' }`.
144
+ The toast carries no class of the space's, so this — not a `.Toastify__*` rule in `customCss` — is where it is
145
+ dressed.
146
+
147
+ Copy link: `copyToClipboard('{{ navigation.href }}')`, then the toast — it fails with no clipboard.
141
148
 
142
149
  ## Modals, dropdowns, tabs
143
150
 
@@ -0,0 +1,33 @@
1
+ # Every reference, and when to read it
2
+
3
+ Read one only when the task names its subject.
4
+
5
+ | Read | When |
6
+ | --- | --- |
7
+ | [rules.md](rules.md) | Every rule of writing a space, with its why |
8
+ | [recipes.md](recipes.md) | A whole working file for a common task, to copy and rename |
9
+ | [elements-and-styles.md](elements-and-styles.md) | Any element or CSS: factories, fields, classes, states, variants, tokens, fonts, lists, links |
10
+ | [colours-and-motion.md](colours-and-motion.md) | Colours for both themes, tokens, keyframes, and motion that stays smooth (good practices) |
11
+ | [tailwind.md](tailwind.md) | A design written in Tailwind classes: `tw()`, its breakpoints and states, what it refuses |
12
+ | [layouts.md](layouts.md) | Anything shown on more than one page; menus; reducing duplication of elements and styles |
13
+ | [efficiency.md](efficiency.md) | The same page with fewer elements: the suggestions `authorSpace` makes, and the short way for each long one |
14
+ | [components.md](components.md) | One block placed many times — a card, a tier, a testimonial: props, slots, binding a row into one, why it is closed |
15
+ | [data-and-visibility.md](data-and-visibility.md) | Bindings, providers, offline data, loading/empty/error states, live data, caching, showing and hiding, kept state |
16
+ | [kept-state.md](kept-state.md) | State that outlives a reload: `keepState`, transient and painted keys |
17
+ | [auth.md](auth.md) | Signing people in: providers, `authLogin`, `auth.*`, visitor roles |
18
+ | [feature-flags.md](feature-flags.md) | Switching a part of the space on or off — a beta, a rollout, the old version kept until the new one ships |
19
+ | [lists.md](lists.md) | Rendering rows, filtering and sorting them, a detail page for one record, carousels |
20
+ | [typed-sources.md](typed-sources.md) | Data typed by a sample of it: `source()`, typed rows, `twig` for templates |
21
+ | [validation.md](validation.md) | How `authorSpace` checks, the loop that wastes no attempts, and what it cannot see |
22
+ | [authoring-errors.md](authoring-errors.md) | What `authorSpace` refuses or warns about, and what to write instead |
23
+ | [templates.md](templates.md) | Any `{{ … }}` or `{% … %}`: where it runs, naming sources, filters, tests, dates |
24
+ | [flows.md](flows.md) | Clicks, submits, page loads, every few seconds, server actions, modals, state |
25
+ | [realtime.md](realtime.md) | Pages that see each other: channels, presence, cursors, a shared board, who may hear a topic |
26
+ | [plugins.md](plugins.md) | A component of your own: props, binding them, writing state, channels, registering, behaving in the builder |
27
+ | [drawing.md](drawing.md) | A plugin that draws or animates: a canvas sized to the device, WebGL, a loop that stops when unseen |
28
+ | [structure.md](structure.md) | A space bigger than one screen: files, helpers, naming, keeping it short |
29
+ | [testing.md](testing.md) | Any test: `inspectPage`, handles, fixtures, catching a flash from the first frame, shortcuts, counting renders |
30
+ | [performance.md](performance.md) | A page with many elements, a busy flow, something that feels slow: what renders, what it costs, how to measure it |
31
+ | [snippets-and-export.md](snippets-and-export.md) | Publishing a snippet; turning an exported JSON — or a server action — into code |
32
+ | [accessibility.md](accessibility.md) | Icon buttons, fields, images, clickable cards, toggles, headings, landmarks, a canvas — anything a screen reader or a browser agent has to use |
33
+ | [review-checklist.md](review-checklist.md) | Before you say it is done |
@@ -74,7 +74,6 @@ const navGroup = (group: DocsGroup): ElementSpec =>
74
74
  id: `docs-nav-${entry.id}`,
75
75
  href: entry.id,
76
76
  class: navLink,
77
- bind: [activeOn(navLink, entry.id)],
78
77
  children: [text(entry.title, { id: `docs-nav-label-${entry.id}` })]
79
78
  })
80
79
  )
@@ -83,33 +82,31 @@ const navGroup = (group: DocsGroup): ElementSpec =>
83
82
 
84
83
  Adding a page is one entry in the list: the menu, the index and the neighbours' "next" follow.
85
84
 
86
- ## The current entry: `activeOn`
85
+ ## The current entry
87
86
 
88
- A menu in a layout is the same nodes on every page, so it cannot have the right entry styled by hand. It asks which
89
- page is showing:
87
+ A menu in a layout is the same nodes on every page, so it cannot have the right entry styled by hand — and does not
88
+ need to. A link to the page being shown marks itself: `aria-current="page"`, which a screen reader announces, and its
89
+ class's `current` state dresses it:
90
90
 
91
91
  ```ts
92
- const navLink = styles('nav-link', {
93
- css: { color: 'var(--muted)' },
94
- variants: { active: { color: 'var(--foreground)', 'font-weight': '600' } }
95
- });
92
+ const navLink = styles('nav-link', { css: { color: 'var(--muted)' }, states: { current: { color: 'var(--foreground)' } } });
96
93
 
97
- link({ href: 'spaces', class: navLink, bind: [activeOn(navLink, ['spaces', 'space-record'])] });
94
+ link({ href: '/pricing', mode: 'internal', class: navLink });
98
95
  ```
99
96
 
100
- A link to ONE page needs nothing of this: it marks itself — `aria-current="page"`, which a screen reader announces — and
101
- its class dresses it with the `current` state:
97
+ An entry lit for a SECTION — a journal and its articles, `/automations/runs` while on `/automations/runs/42` — says
98
+ `current: 'section'`: current on its page and on every page under its path, at a `/` (`/runs` holds `/runs/42`, not
99
+ `/runsx`), announced there as the current entry (`aria-current="true"`); the same `current` state dresses it. A link to
100
+ `/` holds every page, so authoring warns (`link-current-section`):
102
101
 
103
102
  ```ts
104
- const navLink = styles('nav-link', { css: { color: 'var(--muted)' }, states: { current: { color: 'var(--foreground)' } } });
105
-
106
- link({ href: '/pricing', mode: 'internal', class: navLink });
103
+ link({ href: 'runs', class: navLink, current: 'section' });
107
104
  ```
108
105
 
109
- `activeOn(class, pageIds, { variant?, slot? })` is for an entry lit on SEVERAL pages — a section and the pages under it,
110
- a journal and its articles: it binds the class's variant to `navigation.currentPageId`, the `active` variant on those
111
- pages and `idle` everywhere else. Do not write the binding by hand with a `when` rule per page; that is the long form
112
- this replaces.
106
+ `activeOn(class, pageIds, { variant?, slot? })` is for an entry lit on pages NOT under its path — `['spaces',
107
+ 'space-record']` when a record lives at `/s/:id`: it binds the class's variant to `navigation.currentPageId`, the
108
+ `active` variant on those pages and `idle` everywhere else. Do not write the binding by hand with a `when` rule per
109
+ page; that is the long form this replaces.
113
110
 
114
111
  ## Pages from a factory
115
112
 
@@ -9,7 +9,7 @@ custom({ id: 'arcade', renderType: 'nebulaRun', shipColor: 'amber', bind: { best
9
9
 
10
10
  ## Creating one
11
11
 
12
- The CLI writes it, in the shape Plitzi's own elements are written in: `npx @plitzi/cli add plugin seat-picker` (a
12
+ The CLI writes it, in the shape Plitzi's own elements are written in: `npx @plitzi/cli plugin add seat-picker` (a
13
13
  package of its own and packing it: the CLI skill).
14
14
 
15
15
  One folder, four files: `SeatPicker.tsx` (the component), `declaration.ts` (its `type`, the `triggers` it fires, the
@@ -88,7 +88,7 @@ the widths the space's styles use, instead of a width of the plugin's own.
88
88
 
89
89
  ## Its own server code
90
90
 
91
- `plitzi add plugin board --server` writes `functions/index.ts` in its folder (the CLI skill). Its routes answer
91
+ `plitzi plugin add board --server` writes `functions/index.ts` in its folder (the CLI skill). Its routes answer
92
92
  under `/fn/plugins/board/`; the component names them, with nothing for the space to wire:
93
93
 
94
94
  ```tsx
@@ -96,7 +96,7 @@ const route = usePluginRoute('board'); // from '@plitzi/plitzi-sdk'
96
96
  const url = route('/layout'); // undefined where no server runs code (the canvas)
97
97
  ```
98
98
 
99
- Its `ctx.kv` is the plugin's own; the space's credentials and channels are not.
99
+ Its `ctx.kv` is the plugin's own; the space's credentials, channels and data are not.
100
100
 
101
101
  ## Talking to other pages
102
102
 
@@ -0,0 +1,25 @@
1
+ # Recipes
2
+
3
+ Each is a whole file that authors with no warning — CI holds it to that. Copy the one that fits, then change the names.
4
+
5
+ | To… | Open |
6
+ | --- | --- |
7
+ | Show data with no backend: a JSON file, a card per row, a count, an empty state, a computed value | [recipes/show-data.ts](../recipes/show-data.ts) |
8
+ | Data typed by a sample of it: completed and checked paths, typed rows | [recipes/typed-data.ts](../recipes/typed-data.ts) |
9
+ | Data read by the page server (`--mode server`) | [recipes/server-data.ts](../recipes/server-data.ts) |
10
+ | An accordion, one answer open at a time | [recipes/accordion.ts](../recipes/accordion.ts) |
11
+ | Filter and sort a list from a select | [recipes/filter-a-list.ts](../recipes/filter-a-list.ts) |
12
+ | A page per record (`/products/:slug`), and "not found" | [recipes/detail-page.ts](../recipes/detail-page.ts) |
13
+ | Link to a section of a page (`/#plans`) | [recipes/link-to-a-section.ts](../recipes/link-to-a-section.ts) |
14
+ | A carousel: slides with arrows, dots and autoplay; a marquee; a row that swipes | [recipes/carousel.ts](../recipes/carousel.ts) |
15
+ | Do something every few seconds — a ticker, a poll, a slideshow by hand | [recipes/every-few-seconds.ts](../recipes/every-few-seconds.ts) |
16
+ | A marquee that scrolls for ever and stops under the pointer | [recipes/marquee.ts](../recipes/marquee.ts) |
17
+ | A row that scrolls sideways, with arrows that hide at its ends | [recipes/scroll-a-row.ts](../recipes/scroll-a-row.ts) |
18
+ | A link built from a row: WhatsApp with the product's name, `mailto:` | [recipes/link-with-data.ts](../recipes/link-with-data.ts) |
19
+ | React to a click or a submit; a modal; a switch | [recipes/forms-and-modals.ts](../recipes/forms-and-modals.ts) |
20
+ | A feature behind a flag | [recipes/feature-flag.ts](../recipes/feature-flag.ts) |
21
+ | An element of your own (a plugin), checked | [recipes/plugin.ts](../recipes/plugin.ts) |
22
+ | Controls a screen reader and a browser agent can use | [recipes/usable-without-sight.ts](../recipes/usable-without-sight.ts) |
23
+ | Tokens, a shared class, "the class plus one thing", tablet and phone at once | [recipes/style-a-page.ts](../recipes/style-a-page.ts) |
24
+ | A design in Tailwind classes, kept as classes the builder edits | [recipes/from-tailwind.ts](../recipes/from-tailwind.ts) |
25
+ | A page from elsewhere in a frame (`embed`: a map, a player) and a drawing of your own (`svg`) | [recipes/embed-and-svg.ts](../recipes/embed-and-svg.ts) |
@@ -50,7 +50,8 @@ Screen readers and browser agents (Claude in Chrome) work a page through its acc
50
50
 
51
51
  ## No copies
52
52
 
53
- - [ ] Chrome shared by pages is a layout; the current menu entry comes from `activeOn`, not per-page styling.
53
+ - [ ] Chrome shared by pages is a layout; the current menu entry marks itself (`current` state, `current: 'section'`),
54
+ not per-page styling.
54
55
  - [ ] A look used twice is a class; a tree used twice is a function or a `map` over data; a list of pages, links or
55
56
  plans is ONE array everything reads.
56
57
  - [ ] No positional ids (`container-45`) in what you wrote; every referenced element is named, and a helper that
@@ -0,0 +1,61 @@
1
+ # The rules of writing a space
2
+
3
+ Every rule, with its why. The skill's core keeps the five that go wrong most in a line each; the rest authoring
4
+ refuses or warns of, with the fix.
5
+
6
+ 1. **Name what is referred to.** Give an `id` to every element a binding, a flow or a test addresses. Ids are ONE
7
+ namespace for the whole space — layouts and every page share it — so a helper that runs more than once builds inside
8
+ `scope('promos', ref => …)`: every id in it is prefixed (`promos-panel`), and `ref('slides')` names one in full. An `id` is the element's name in the
9
+ space (`data-plitzi-el` in the page); the DOM id a URL's `#fragment` lands on is its `anchor`.
10
+ 2. **Share with classes, layouts and components, never with copies.** A look used twice is a `styles()` class.
11
+ Chrome shown on several pages — a header, a sidebar, a footer — is a **layout** the pages name, written once. A block
12
+ placed many times with different content — a product card, a testimonial — is a **component** placed with
13
+ `component(id, { props })`. A menu, a card grid, a list of steps is DATA, never a block pasted per item: a short
14
+ menu mapped in code is fine; rows — cards, dishes, tiles — are one `list` (`items: [ … ]`) whose row is written
15
+ once. A link or a button says its words as
16
+ its own `content`, not through a `text` inside it. Pages of one shape are one `pageFamily` over data. See
17
+ [layouts](layouts.md), [components](components.md), [structure](structure.md) and
18
+ [efficiency](efficiency.md).
19
+ 3. **One element, one base selector.** An element takes a shared `class` OR its own `css`, never both — authoring
20
+ refuses the pair. "This class plus one thing" is the class with rules on top, last in the list:
21
+ `class: [cover, { opacity: '0.25' }]` (needs the element's `id`; it becomes the class `<id>--own`). A look that
22
+ never changes is its own class.
23
+ 4. **Visible by default; decide which way the logic flips.** An element is on screen unless something hides it. When
24
+ the logic REVEALS it (hidden → shown: an empty state, a "get started" card, an admin-only panel), it starts hidden —
25
+ `visible: 'source'`, or `visible: false` plus a binding for a computed condition — so it never flashes while data
26
+ loads (`condition-starts-visible` warns). When a flag HIDES it (shown → hidden: a sidebar label until the sidebar
27
+ is folded), it keeps the default and an absent flag must leave it shown. See
28
+ [data and visibility](data-and-visibility.md). What a PERSON switches on — a feature in beta, a rollout —
29
+ is a feature flag, not a visibility: gated off, it is not rendered at all. See [feature flags](feature-flags.md).
30
+ 5. **Know where a template is evaluated.** A binding's template (`bindTemplate`) and a step's params evaluate full
31
+ Twig. An ATTRIBUTE resolves a name with filters (`{{ list_games.item.slug }}`, `{{ post.slug|url_encode }}`) against
32
+ the sources around the element; a condition there is used as written. Inside any template a source is spelled in
33
+ full — `apiContainer_stats`, `list_rows` — and a query param is `navigation.queryParams.x`. A template that feeds a
34
+ list its `items` hands over its value (`returns: 'value'`). `authorSpace` refuses a template it cannot read and a
35
+ name nothing answers to. See [templates](templates.md).
36
+ 6. **Tokens, not colours.** Every colour is a variable of the space with a `light` and a `dark` value; both themes are
37
+ checked from the first commit.
38
+ 7. **Times in UTC, and say so.** Format with an explicit zone (`|date('j M · H:i', 'UTC')`) and print "UTC" beside it:
39
+ a page rendered on a server and hydrated in a browser in another zone must agree on the hour.
40
+ 8. **Breakpoints are ranges.** `tablet` (48–64rem) and `mobile` (up to 48rem) each inherit only from `desktop`; a rule
41
+ meant for both is written under `compact`.
42
+ 9. **Never invent data.** Numbers, names and states on screen come from a source. A panel with nothing true to say is
43
+ an empty state, not a placeholder figure. With no backend, the data is JSON read by an `apiContainer`: a server
44
+ project's `src/data/*.json`, read on the server and never served; with no server, `public/data/*.json`, which is
45
+ public — see [data and visibility](data-and-visibility.md).
46
+ 10. **Never hand-write** `flat`, derived ids, `styleSelectors`, `beforeNode`/`afterNode`/`flowId`, or a
47
+ `styleVariant` binding's key — use the factories, `variantFrom` and `activeOn`.
48
+ 11. **A switch is named for how it leaves its default.** `toggleState` turns a key nobody has set yet ON, so a key
49
+ named for the default (`showPlates`, on by default) takes a first click to do nothing: name it `platesOff`, and read
50
+ every switch through `computed` (`plates: '{{ state.platesOff ? false : true }}'`) so its default shows before
51
+ anybody touches it.
52
+ 12. **Hand plugins over as their declarations**: `authorSpace(space, { plugins: [declaration] })` holds a plugin —
53
+ its own type, or a `custom({ renderType })` host — to the events, actions and attributes it declares. See
54
+ [plugins](plugins.md).
55
+ 13. **Usable without sight.** Screen readers and browser agents (Claude in Chrome) find a page's controls in its
56
+ accessibility tree: every button and link has words (an icon-only button a `title`), every field a `label`
57
+ (`hideLabel: true` hides it and keeps the name), every image an `alt` or `decorative: true`. Clicks go on a
58
+ `button` — it holds children, so a whole card can be one — or a `link`, never on a container. See
59
+ [accessibility](accessibility.md).
60
+ 14. **Motion that stays smooth.** Animate `opacity` and `transform` only; no animated blur, shadow or size. See
61
+ [motion](colours-and-motion.md).
@@ -31,8 +31,8 @@ Never rewrite an exported space by hand. `specFromSpace({ schema, style })` read
31
31
  A server action reads back the same way: `actionSpecFromEntry({ id, document })` gives the `defineAction` spec that writes
32
32
  it — only when that spec writes the very same document, otherwise `reason` says why and it stays JSON — and
33
33
  `actionToSource(spec)` writes the module. For the whole space as a project — pages, actions, functions, the source of
34
- its plugins and runtime, its files — use `plitzi create --from <space>` (then `plitzi pull` to bring the space's changes in, and
35
- `plitzi push` to put the project's back) rather than exporting the parts by hand.
34
+ its plugins and runtime, its files — use `plitzi create --from <space>` (then `plitzi space pull` to bring the space's changes in, and
35
+ `plitzi space push` to put the project's back) rather than exporting the parts by hand.
36
36
 
37
37
  For a document you did not author — an export, a JSON edited by hand — run the gate before serving it:
38
38
  `validateSpace({ schema, style })`.
@@ -108,7 +108,7 @@ the record is the answer instead: one page, as many addresses as records.
108
108
  per page. It renders; it is not maintainable. When you work on such a file, leave it better:
109
109
 
110
110
  - repeated `css` blocks → one class;
111
- - a nav with a hand-styled current entry per page → a layout and `activeOn`;
111
+ - a nav with a hand-styled current entry per page → a layout whose links mark themselves (`current: 'section'`);
112
112
  - the same tree pasted per item → a function and a `map`;
113
113
  - `container-45` → a name.
114
114
 
@@ -117,7 +117,8 @@ the rest.
117
117
 
118
118
  ## Checked for you
119
119
 
120
- `npm run lint:space` (`plitzi lint`) reads the source for what this page asks — a file past 400 lines, pages in one
120
+ `npm run lint:space` (`plitzi space lint`) reads the source for what this page asks — a file past 400 lines, pages in one
121
121
  file, rows of data inline, a colour that is not a token, CSS copied three times, a row singled out by its id inside a
122
122
  `map`, a minted id, a file nothing imports — at file:line, beside authoring's suggestions. Leave it clean; a departure
123
- on purpose says why where it is: `// plitzi-lint-disable-next-line <code> -- why`.
123
+ on purpose says why where it is: `// plitzi-lint-disable-next-line <code> -- why` for lint's own codes. A suggestion of
124
+ authoring's is quieted on its element instead — `quiet: ['repeated-shape']` — where the builder and the MCP read it.
@@ -71,7 +71,7 @@ the space with it (the e2e harness: `renderSpace(page, space, { debugMode: true
71
71
 
72
72
  ## Asking the page what it holds
73
73
 
74
- `plitzi check` lists every flow that failed while the page loaded; `--state` adds the state and every source by its
74
+ `plitzi page check` lists every flow that failed while the page loaded; `--state` adds the state and every source by its
75
75
  full name, `--element <id>` one element — what it reads, its own state, whether it is on screen. They come from the
76
76
  page's dev tools (debug mode, any development server). In a test, `readDevTools(page, { state: true })` from
77
77
  `@plitzi/sdk-authoring` answers the same.
@@ -46,7 +46,7 @@ bar.
46
46
  ```
47
47
 
48
48
  2. **Fix, re-run, until it prints zero warnings.** What has one fix (`author` says how many) is written for you: `npx
49
- plitzi fix` shows it as a diff of your source, `--write` writes it and keeps it only if the space authors with each
49
+ plitzi space fix` shows it as a diff of your source, `--write` writes it and keeps it only if the space authors with each
50
50
  fix gone and nothing new — a fix it cannot place, or that would add a problem, is said with the reason. A
51
51
  suggestion with one reading is written the same way (`content-attribute`: words and an icon held as children become
52
52
  the button's or link's own `content` and `icon`). Then typecheck the project.
@@ -1,16 +0,0 @@
1
- //#region ../sdk-shared/dist/server/rsc/projectData.mjs
2
- var e = "/data/";
3
- //#endregion
4
- //#region src/svg/compactSvg.ts
5
- /**
6
- * An SVG as it is worth carrying in a space: what a design tool wrote for itself taken out — the XML prolog and doctype,
7
- * comments, `<metadata>`, an editor's own elements and attributes (Inkscape, Sodipodi, Sketch, Figma's `data-name`) —
8
- * and the whitespace between tags. What draws, and its `<title>`, stay as they were.
9
- *
10
- * Every byte of an inline SVG is in the space's documents and in every page that shows it, so a logo exported from a
11
- * design tool with half its size in notes to itself is that much heavier for nothing. `svg()` checks and sanitises
12
- * what it is given; this only makes it smaller.
13
- */
14
- var compactSvg = (markup) => markup.replace(/<\?xml[\s\S]*?\?>/g, "").replace(/<!DOCTYPE[\s\S]*?>/gi, "").replace(/<!--[\s\S]*?-->/g, "").replace(/<metadata[\s\S]*?<\/metadata>/gi, "").replace(/<(sodipodi|inkscape|sketch):[\w-]+[^>]*\/>/g, "").replace(/<(sodipodi|inkscape|sketch):([\w-]+)[^>]*>[\s\S]*?<\/\1:\2>/g, "").replace(/\s(?:sodipodi|inkscape|sketch):[\w-]+="[^"]*"/g, "").replace(/\sxmlns:(?:sodipodi|inkscape|sketch|dc|cc|rdf)="[^"]*"/g, "").replace(/\sdata-name="[^"]*"/g, "").replace(/>\s+</g, "><").trim();
15
- //#endregion
16
- export { e as n, compactSvg as t };