@plitzi/sdk-authoring 0.37.8 → 0.37.10
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 +817 -0
- package/dist/index.d.ts +2769 -266
- package/dist/index.js +14203 -7441
- package/package.json +9 -8
- package/skills/plitzi-authoring/CHEATSHEET.md +135 -0
- package/skills/plitzi-authoring/SKILL.md +77 -74
- package/skills/plitzi-authoring/recipes/carousel.ts +114 -0
- package/skills/plitzi-authoring/recipes/detail-page.ts +70 -0
- package/skills/plitzi-authoring/recipes/embed-and-svg.ts +48 -0
- package/skills/plitzi-authoring/recipes/every-few-seconds.ts +119 -0
- package/skills/plitzi-authoring/recipes/feature-flag.ts +24 -0
- package/skills/plitzi-authoring/recipes/filter-a-list.ts +63 -0
- package/skills/plitzi-authoring/recipes/forms-and-modals.ts +64 -0
- package/skills/plitzi-authoring/recipes/from-tailwind.ts +52 -0
- package/skills/plitzi-authoring/recipes/link-to-a-section.ts +35 -0
- package/skills/plitzi-authoring/recipes/link-with-data.ts +40 -0
- package/skills/plitzi-authoring/recipes/marquee.ts +57 -0
- package/skills/plitzi-authoring/recipes/plugin.ts +53 -0
- package/skills/plitzi-authoring/recipes/scroll-a-row.ts +79 -0
- package/skills/plitzi-authoring/recipes/show-data.ts +73 -0
- package/skills/plitzi-authoring/recipes/style-a-page.ts +45 -0
- package/skills/plitzi-authoring/recipes/typed-data.ts +64 -0
- package/skills/plitzi-authoring/recipes/usable-without-sight.ts +39 -0
- package/skills/plitzi-authoring/reference/accessibility.md +2 -2
- package/skills/plitzi-authoring/reference/authoring-errors.md +195 -53
- package/skills/plitzi-authoring/reference/colours-and-motion.md +63 -0
- package/skills/plitzi-authoring/reference/components.md +83 -0
- package/skills/plitzi-authoring/reference/data-and-visibility.md +29 -29
- package/skills/plitzi-authoring/reference/efficiency.md +53 -0
- package/skills/plitzi-authoring/reference/elements-and-styles.md +39 -24
- package/skills/plitzi-authoring/reference/feature-flags.md +78 -0
- package/skills/plitzi-authoring/reference/flows.md +26 -37
- package/skills/plitzi-authoring/reference/kept-state.md +28 -0
- package/skills/plitzi-authoring/reference/layouts.md +20 -3
- package/skills/plitzi-authoring/reference/lists.md +45 -16
- package/skills/plitzi-authoring/reference/plugins.md +27 -0
- package/skills/plitzi-authoring/reference/realtime.md +35 -0
- package/skills/plitzi-authoring/reference/review-checklist.md +8 -3
- package/skills/plitzi-authoring/reference/{templates-and-export.md → snippets-and-export.md} +15 -8
- package/skills/plitzi-authoring/reference/structure.md +29 -20
- package/skills/plitzi-authoring/reference/tailwind.md +19 -0
- package/skills/plitzi-authoring/reference/templates.md +6 -5
- package/skills/plitzi-authoring/reference/testing.md +11 -0
- package/skills/plitzi-authoring/reference/typed-sources.md +20 -0
- package/skills/plitzi-authoring/reference/validation.md +6 -2
|
@@ -7,36 +7,44 @@ its children once as a plain `<ul>` and never looks at `items`, so a list with i
|
|
|
7
7
|
list bound to its records (see the provider in data-and-visibility).
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
list({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class: gameGrid,
|
|
14
|
-
bind: { items: 'catalog.data.games' }, // an array from the provider around it
|
|
15
|
-
children: [gameCard()] // rendered once per game
|
|
16
|
-
})
|
|
10
|
+
list({ id: 'games', class: gameGrid, items: 'catalog.data.games', row: 'game-card' }) // a component per game
|
|
11
|
+
list({ id: 'games', items: 'catalog.data.games', row: r => text({ from: `${r.item}.title` }) }) // or a tree of its own
|
|
12
|
+
list({ id: 'plans', items: ['Free', 'Pro'], children: [text({ from: 'plans.item' })] }) // fixed items
|
|
17
13
|
```
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
`items` makes a list controlled: an array of its own, or the source its rows come from. `row` is what it renders once
|
|
16
|
+
per item — a component's id (placed with the row bound to its `item` prop, or its only prop), or a function handed the
|
|
17
|
+
row's names: `r.item` and `r.index` for a binding or `from`, `r.inTemplate.item` for a template
|
|
18
|
+
(`` `/games/{{ ${r.inTemplate.item}.slug }}` ``). A function needs the list's `id`, which names those sources. With
|
|
19
|
+
`items` a typed source's path (`items: site.data.games`, see typed-sources.md), the row is typed too:
|
|
20
|
+
`row: g => text({ from: g.item.title })`, and a field the sample's games lack is a type error.
|
|
21
|
+
|
|
22
|
+
- Each row publishes **`list_<id>.item`** (the row) and **`list_<id>.index`** (its position, a number from 0 —
|
|
23
|
+
`index + 1` counts, and `==` compares it with text or a number alike). Inside the row,
|
|
20
24
|
bindings read the short form (`'games.item.title'`), templates and attribute tokens the full one
|
|
21
25
|
(`{{ list_games.item.slug }}`).
|
|
22
26
|
- A **nested list** sees the outer row: inside `list_features`, `list_games.item` is still the game.
|
|
23
27
|
- The list is a `<ul>` and its `class` styles that root; each child is rendered straight into it, with no wrapper.
|
|
24
28
|
A card grid needs `{ margin: '0px', padding: '0px', 'list-style-type': 'none' }` in its class.
|
|
25
|
-
- Fixed data is `items: [ … ]` on the list itself — no provider needed.
|
|
29
|
+
- Fixed data is `items: [ … ]` on the list itself — no provider needed. Worth it when the rows ARE data — written from
|
|
30
|
+
an array, or rows that come and go (`repeated-shape` points at sibling copies). Three cards a person rewords on the
|
|
31
|
+
canvas are easier to edit as three cards than as a JSON array.
|
|
26
32
|
- Everything inside a row is `repeated` in the handles: a test addresses one copy with `.first()` / `.nth()`.
|
|
33
|
+
- **A row is its item's by its `id`** when every item has a different one, else by its position: filtered or
|
|
34
|
+
reordered, a row's state (an open detail, a field's text) follows its item. Items named by another field say so —
|
|
35
|
+
`itemKey: 'slug'` (`list-item-key-missing` warns when fixed items lack it). A row whose item changes mounts again,
|
|
36
|
+
so a one-row list showing "the current slide" replays the slide's entrance animation.
|
|
27
37
|
|
|
28
38
|
## Filtering and sorting
|
|
29
39
|
|
|
30
|
-
|
|
40
|
+
Feed the list through a template — `from` with `as` hands a list its template's **value**:
|
|
31
41
|
|
|
32
42
|
```ts
|
|
33
43
|
list({
|
|
34
44
|
id: 'shown',
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
{ returns: 'value' })],
|
|
39
|
-
children: [gameCard()]
|
|
45
|
+
from: 'catalog.data.games',
|
|
46
|
+
as: "{{ source|filter(g => (state.genre ?? '') == '' or g.genre == state.genre)|sort((a, b) => b.score - a.score) }}",
|
|
47
|
+
row: 'game-card'
|
|
40
48
|
})
|
|
41
49
|
```
|
|
42
50
|
|
|
@@ -71,4 +79,25 @@ apiContainer({ id: 'catalog', query: '/data/games.json', cache: true, children:
|
|
|
71
79
|
```
|
|
72
80
|
|
|
73
81
|
A link to it from a card is an attribute token read inside the card's row:
|
|
74
|
-
`link({
|
|
82
|
+
`link({ href: '/games/{{ list_games.item.slug }}' })`.
|
|
83
|
+
|
|
84
|
+
## Carousels
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
carousel({ id: 'hero', label: 'Featured', items: 'site.data.slides', autoplay: 5000, row: 'slide-card', children: [
|
|
88
|
+
button({ content: '›', title: 'Next slide', flows: [[onClick(), carouselNext('hero')]] })
|
|
89
|
+
] })
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
A `carousel` takes `items` and a `row` as a list does, and writes the row into a `carouselTrack`; its other children are
|
|
93
|
+
its controls, which read `carousel_hero.index`, `.count`, `.item` and `.items` (`list({ id: 'dots', items: 'hero.items',
|
|
94
|
+
… })` for dots, `activeWhen(dot, '{{ list_dots.index == carousel_hero.index }}')` for the current one). Steps:
|
|
95
|
+
`carouselNext`, `carouselPrevious`, `carouselGoTo(id, index)`, `carouselPlay`, `carouselPause`; it fires `onChange`.
|
|
96
|
+
|
|
97
|
+
- `mode: 'slide'` (one at a time, `transition` `slide`/`fade`/`none`, back enters from the left), `'marquee'` (`speed` px/s,
|
|
98
|
+
no seam), `'scroll'` (a row that snaps and swipes; next moves a slide). Several slides at once: the carousel's class
|
|
99
|
+
sets `--plitzi-carousel-slide-width` and `--plitzi-carousel-gap`.
|
|
100
|
+
- Autoplay holds still under the pointer (`pauseOnHover`), with keyboard focus inside, in a hidden tab and for reduced
|
|
101
|
+
motion. In the builder it stands on its first slide. `label` names it for a screen reader.
|
|
102
|
+
|
|
103
|
+
See recipes/carousel.ts.
|
|
@@ -92,6 +92,21 @@ Take the topic as a prop (`bindTemplate('roomTopic', 'board.id', 'room:{{ source
|
|
|
92
92
|
channels, and trust a message you act on only when `message.from === 'server'`. The page has one connection and is one
|
|
93
93
|
member per topic, however many elements and plugins listen.
|
|
94
94
|
|
|
95
|
+
## Feature flags
|
|
96
|
+
|
|
97
|
+
A plugin that ships a feature behind one of the space's [feature flags](feature-flags.md) asks with `useFlag` — the
|
|
98
|
+
answer every layer gave (the space's rules, the server, the SDK, a tester forcing it), and it renders again when it
|
|
99
|
+
changes:
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
import { useFlag } from '@plitzi/plitzi-sdk';
|
|
103
|
+
|
|
104
|
+
const newChart = useFlag('newChart'); // false for a flag the space does not declare
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Gating the whole plugin needs no code: give its element `flag: 'newChart'`. `useFlag` is for a plugin that changes
|
|
108
|
+
inside — a new mode, an extra panel.
|
|
109
|
+
|
|
95
110
|
## Registering
|
|
96
111
|
|
|
97
112
|
A project `plitzi create` wrote registers every folder of `src/plugins` by itself, under the folder's name in
|
|
@@ -134,6 +149,18 @@ A plugin says what HAPPENED through its events (`onPick`, with the seat in the p
|
|
|
134
149
|
decide what that means — write `state`, open a modal, call a server action. Prefer that to writing `state` from inside
|
|
135
150
|
the component: the flow is visible in the space, the builder shows it, and the same act can come from a button too.
|
|
136
151
|
|
|
152
|
+
## Behaving in the builder
|
|
153
|
+
|
|
154
|
+
The builder draws the element on its canvas while somebody edits the page: a click selects it, a drag moves it, a key
|
|
155
|
+
belongs to the editor.
|
|
156
|
+
|
|
157
|
+
- **Outside preview, do nothing on your own.** `usePlitziServiceContext().settings.previewMode` is `false` while the
|
|
158
|
+
page is edited. Declared interactions are already held back then; your own click handlers, timers, global listeners,
|
|
159
|
+
permission prompts and map gestures are not — gate them on `previewMode`, and still render something to select.
|
|
160
|
+
- **Never the global `window` or `document`.** The canvas is a frame of its own and the code runs in the builder's
|
|
161
|
+
window: listen, measure and go full screen through the node's own page (`ref.current.ownerDocument`, its
|
|
162
|
+
`defaultView`) or `usePlitziServiceContext().utils.getWindow()`. An `instanceof` check takes its class from there too.
|
|
163
|
+
|
|
137
164
|
## Components that draw into DOM they do not render
|
|
138
165
|
|
|
139
166
|
A map, a chart library, anything that positions its own markers or popups: its roots are the library's to place. Never
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Realtime channels
|
|
2
|
+
|
|
3
|
+
Pages that see each other — cursors, presence, a shared board — need a channel. Declare its topic pattern on the space,
|
|
4
|
+
then subscribe with a `channel` element; a topic no pattern matches is refused, naming the patterns:
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
channels: {
|
|
8
|
+
'board:{id}': { access: { mode: 'public' }, publish: 'server' }, // only `realtime.publish` speaks
|
|
9
|
+
'room:{id}': { access: { mode: 'public' }, presence: true } // pages speak directly
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
channel({ id: 'room', topic: 'room:{{ id }}', keep: 0, bind: { presence: 'computed.me' }, children: [...] })
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Its descendants bind `room.members`, `room.connected`, `room.last`; flows use `on('onMessage')` (`type`, `data`,
|
|
16
|
+
`from`), `onJoin`/`onLeave` (`from`, `user` and the `state` the member announced — `onJoin` only for who came after
|
|
17
|
+
this page), `publishOn('room', 'reaction', data)` and `announceOn('room', state)`. State everyone must
|
|
18
|
+
agree on goes through a server action whose last step is `realtime.publish` — validated and saved first, announced
|
|
19
|
+
after.
|
|
20
|
+
|
|
21
|
+
A topic only some visitors may hear — a room behind a password, a customer's order — goes on a channel declared
|
|
22
|
+
`grant: true`. The action that decides they may be there ends with `realtime.grant` and answers the grant; the
|
|
23
|
+
element binds it, or the server refuses the topic every time (`channel-grant`). `realtime.revoke { topic, grant }`
|
|
24
|
+
takes one back — or every grant for the topic, naming none — and lets go whoever is on it with it:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
channels: { 'order:{id}': { access: { mode: 'session' }, grant: true } }
|
|
28
|
+
|
|
29
|
+
// steps: [ …decide…, { id: 'let', task: 'realtime.grant', params: { topic: 'order:{{ input.order }}' } } ]
|
|
30
|
+
channel({ id: 'order', topic: 'order:{{ id }}', bind: { grant: 'state.follow.grant' }, children: [...] })
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Two people writing the same thing at once: `kv.setIf` writes only if the value is still the one the flow read (empty
|
|
34
|
+
`expected` = only if nothing is there yet — claim a seat, a username), `list.put`/`list.range` keep an ordered list
|
|
35
|
+
(latest first, a leaderboard), and `flow.rateLimit` first in a public action that writes.
|
|
@@ -6,6 +6,8 @@ of it; each line is something that has shipped broken before.
|
|
|
6
6
|
## It renders, and says so
|
|
7
7
|
|
|
8
8
|
- [ ] `authorSpace` returns **zero warnings**. Each one is written code that will not do what it says.
|
|
9
|
+
- [ ] Every **suggestion** is taken, or left for a reason you can say (the copies are about to diverge; three cards a
|
|
10
|
+
person rewords on the canvas). The ones your change opened up first — [efficiency.md](efficiency.md).
|
|
9
11
|
- [ ] No console errors on any page you touched.
|
|
10
12
|
|
|
11
13
|
## Nothing flashes, nothing jumps
|
|
@@ -15,6 +17,8 @@ of it; each line is something that has shipped broken before.
|
|
|
15
17
|
- [ ] Nothing that is on screen by default disappears because a flag has not been set yet (a sidebar until it is
|
|
16
18
|
folded). Checked on a fresh visit, with no state kept from before.
|
|
17
19
|
- [ ] Empty states show only when the answer arrived and is empty — never while loading.
|
|
20
|
+
- [ ] A feature still being built is gated by a [feature flag](feature-flags.md) (`flag: 'x'` / `'!x'`), not hidden
|
|
21
|
+
with `visible` — and checked with the flag on AND off. A flag whose feature shipped is removed, gate and all.
|
|
18
22
|
- [ ] No hidden element leaves a hole: the element itself is hidden, not a wrapper around it.
|
|
19
23
|
- [ ] Nothing shifts when the data lands: a loading area keeps its size, numbers use tabular figures.
|
|
20
24
|
|
|
@@ -23,7 +27,8 @@ of it; each line is something that has shipped broken before.
|
|
|
23
27
|
- [ ] Desktop, tablet and mobile — and nothing scrolls sideways on a phone. A rule for tablets and phones alike is
|
|
24
28
|
written under `compact`.
|
|
25
29
|
- [ ] Light AND dark. Every colour is a token with both values; no theme-following text on a fixed background.
|
|
26
|
-
- [ ] Focus is visible on everything clickable (`focus-visible`)
|
|
30
|
+
- [ ] Focus is visible on everything clickable (`focus-visible`). Animations and transitions stop by themselves for
|
|
31
|
+
`prefers-reduced-motion`; a hover that moves something is turned off there too (`transform: none`).
|
|
27
32
|
|
|
28
33
|
## Usable without sight
|
|
29
34
|
|
|
@@ -44,8 +49,8 @@ Screen readers and browser agents (Claude in Chrome) work a page through its acc
|
|
|
44
49
|
- [ ] Chrome shared by pages is a layout; the current menu entry comes from `activeOn`, not per-page styling.
|
|
45
50
|
- [ ] 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
|
|
46
51
|
plans is ONE array everything reads.
|
|
47
|
-
- [ ] No positional ids (`container-45`) in what you wrote; every referenced element is named,
|
|
48
|
-
|
|
52
|
+
- [ ] No positional ids (`container-45`) in what you wrote; every referenced element is named, and a helper that
|
|
53
|
+
runs more than once builds inside `scope()`.
|
|
49
54
|
|
|
50
55
|
## True, and in the right place
|
|
51
56
|
|
package/skills/plitzi-authoring/reference/{templates-and-export.md → snippets-and-export.md}
RENAMED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Snippets, exports, and what authoring refuses
|
|
2
2
|
|
|
3
|
-
## Publishing a
|
|
3
|
+
## Publishing a snippet
|
|
4
4
|
|
|
5
|
-
A
|
|
6
|
-
will never see.
|
|
5
|
+
A snippet is ONE subtree, the style that dresses it and a name, published as a JSON someone drags onto a canvas you
|
|
6
|
+
will never see. What lands is a copy, the page's own from then on — for a block that stays linked to every place it
|
|
7
|
+
renders, write a component instead ([components.md](components.md)).
|
|
7
8
|
|
|
8
9
|
```ts
|
|
9
|
-
import {
|
|
10
|
+
import { authorSnippet } from '@plitzi/sdk-authoring';
|
|
10
11
|
|
|
11
|
-
const {
|
|
12
|
+
const { snippet, warnings } = authorSnippet({
|
|
12
13
|
name: 'Pricing card',
|
|
13
14
|
description: 'A price, a list of features and a call to action.',
|
|
14
15
|
classes: { card: { padding: '24px', 'border-radius': '12px', 'background-color': 'var(--surface)' } },
|
|
@@ -17,8 +18,8 @@ const { template, warnings } = authorTemplate({
|
|
|
17
18
|
```
|
|
18
19
|
|
|
19
20
|
- **Everything it names, it carries.** A class declared in the space it was cut from does not travel: declare every
|
|
20
|
-
rule the subtree names (`
|
|
21
|
-
- **A binding may not point outside the subtree.** Bring the provider into the
|
|
21
|
+
rule the subtree names (`validateSnippet` warns about one it does not carry).
|
|
22
|
+
- **A binding may not point outside the subtree.** Bring the provider into the snippet, or bind to a global.
|
|
22
23
|
|
|
23
24
|
## From an exported JSON
|
|
24
25
|
|
|
@@ -27,6 +28,12 @@ Never rewrite an exported space by hand. `specFromSpace({ schema, style })` read
|
|
|
27
28
|
`compareSpaces(original, authorSpace(spec))` must list nothing but what `corrections` explains. The builder's
|
|
28
29
|
**Export** does all three. Edit the code from then on — and tidy it as you go ([structure.md](structure.md)).
|
|
29
30
|
|
|
31
|
+
A server action reads back the same way: `actionSpecFromEntry({ id, document })` gives the `defineAction` spec that writes
|
|
32
|
+
it — only when that spec writes the very same document, otherwise `reason` says why and it stays JSON — and
|
|
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>` (and `plitzi pull` later) rather than exporting
|
|
35
|
+
the parts by hand.
|
|
36
|
+
|
|
30
37
|
For a document you did not author — an export, a JSON edited by hand — run the gate before serving it:
|
|
31
38
|
`validateSpace({ schema, style })`.
|
|
32
39
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# Structuring a space that grows
|
|
2
2
|
|
|
3
|
-
A one-screen space fits in `src/space.ts`. Past a few pages, split it by what changes together —
|
|
4
|
-
repeated thing in exactly one place.
|
|
3
|
+
A one-screen space fits in `src/space.ts`. Past a few pages, split it by what changes together — a file per part, short
|
|
4
|
+
enough to read whole — and keep every repeated thing in exactly one place. `npx @plitzi/cli create shop --template
|
|
5
|
+
catalog` writes a complete small site in this shape (tokens, a layout, a card component, typed data, a page per file)
|
|
6
|
+
to read before writing one.
|
|
5
7
|
|
|
6
8
|
```text
|
|
7
9
|
src/space/
|
|
@@ -20,29 +22,36 @@ src/space/
|
|
|
20
22
|
|
|
21
23
|
## Components are functions
|
|
22
24
|
|
|
23
|
-
The same block in two places is a function with parameters.
|
|
24
|
-
|
|
25
|
+
The same block in two places is a function with parameters. Ids are one namespace for the whole space, so the
|
|
26
|
+
function builds inside `scope()`: every `id` given in it is prefixed by the scope's name, and `ref()` names one of them
|
|
27
|
+
in full for a binding, a step's target or a template:
|
|
25
28
|
|
|
26
29
|
```ts
|
|
27
30
|
export const panel = (params: { id: string; title: string; sub?: string; link?: { href: string; label: string }; children: ElementSpec[] }): ElementSpec =>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
scope(params.id, () =>
|
|
32
|
+
container({
|
|
33
|
+
id: 'panel',
|
|
34
|
+
class: panelCard,
|
|
35
|
+
children: [
|
|
36
|
+
container({
|
|
37
|
+
id: 'head',
|
|
38
|
+
class: panelHead,
|
|
39
|
+
children: [
|
|
40
|
+
heading(params.title, { id: 'title', subType: 'h3', class: panelTitle }),
|
|
41
|
+
...(params.sub ? [text(params.sub, { id: 'sub', class: panelSub })] : []),
|
|
42
|
+
...(params.link ? [link({ id: 'link', href: params.link.href, class: panelLink, children: [text(params.link.label)] })] : [])
|
|
43
|
+
]
|
|
44
|
+
}),
|
|
45
|
+
...params.children
|
|
46
|
+
]
|
|
47
|
+
})
|
|
48
|
+
);
|
|
44
49
|
```
|
|
45
50
|
|
|
51
|
+
`panel({ id: 'hm-traffic', … })` writes `hm-traffic-panel`, `hm-traffic-title`… Whatever names one of them from inside
|
|
52
|
+
takes it from the function's argument — `scope(params.id, ref => …)`, then `scrollBy(ref('row'), …)` or
|
|
53
|
+
`` `{{ list_${ref('row')}.index }}` ``. Scopes nest; a list's `row` already reads its list by its full name.
|
|
54
|
+
|
|
46
55
|
A page then reads as what it shows: `panel({ id: 'hm-traffic', title: 'Traffic', link: { href: 'analytics', label:
|
|
47
56
|
'Open analytics →' }, children: [chart] })`.
|
|
48
57
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# From Tailwind classes
|
|
2
|
+
|
|
3
|
+
`tw()` turns Tailwind classes into the rules `styles()` takes, when the space is written — nothing of Tailwind runs in
|
|
4
|
+
the page, and the class is an ordinary one the builder edits:
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
const pill = styles('nav-pill', tw('inline-flex items-center gap-2 px-5 py-2 rounded-full bg-slate-950/90 hover:scale-105 md:text-sm'));
|
|
8
|
+
const t = createTw({ colors: tokens(variables) }); // bg-surface → var(--surface), text-ink/60 → a tint of it
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- Tailwind v4's scales and palette, its arbitrary values (`w-[220px]`, `shadow-[0_0_20px_rgb(6_182_212/0.35)]`), CSS
|
|
12
|
+
variables (`bg-(--accent)`) and any property (`[mask-type:luminance]`).
|
|
13
|
+
- Breakpoints become Plitzi's ranges: `md:` is tablet and desktop, `lg:` desktop, `max-md:` mobile, `max-lg:` tablet and
|
|
14
|
+
mobile. A property only a wider range sets is `revert` below it.
|
|
15
|
+
- `hover:`, `focus-visible:`, `active:`… are the class's states; `group-hover/card:` is how it looks inside an
|
|
16
|
+
ancestor wearing the class `card`.
|
|
17
|
+
- What has no exact equivalent is refused with what to write instead (`tw-no-equivalent`): `sm:`/`xl:`, `dark:` (a
|
|
18
|
+
token with both values), `space-x-*` (`gap`), `animate-*` (keyframes in `customCss`). An unknown class is
|
|
19
|
+
`tw-unknown-class` with the closest one; two classes that tie on a property are `tw-class-conflict`.
|
|
@@ -16,7 +16,7 @@ An attribute holding a condition — `href: "/x/{{ on ? 'a' : 'b' }}"` — is us
|
|
|
16
16
|
`template-never-resolved`). Move the expression into a binding with `bindTemplate`:
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
|
-
link({ href: '/',
|
|
19
|
+
link({ href: '/', bind: [bindTemplate('href', 'state.workspace.id', "{{ source ? '/workspace/' ~ source : '/' }}")] })
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
A value that came from a BINDING is data, never a template: a comment reading `{{ auth.accessToken }}` prints those
|
|
@@ -39,8 +39,8 @@ A text template feeding `items` is refused: the list would receive the array wri
|
|
|
39
39
|
## Naming sources inside a template
|
|
40
40
|
|
|
41
41
|
Always the full name — the element's kind, an underscore, its id: `apiContainer_stats`, `list_rows`,
|
|
42
|
-
`modalContainer_credits`. The globals (`state`, `auth`, `navigation`, `variables`, `host`, `theme`, `computed`) are
|
|
43
|
-
as themselves. In a flow, an earlier step is read by the name given with `named('quote', …)`: `{{ quote.output.total }}`.
|
|
42
|
+
`modalContainer_credits`. The globals (`state`, `auth`, `navigation`, `variables`, `host`, `theme`, `flags`, `computed`) are
|
|
43
|
+
named as themselves — `{{ flags.newCheckout }}` is `true` or `false`, see [feature flags](feature-flags.md). In a flow, an earlier step is read by the name given with `named('quote', …)`: `{{ quote.output.total }}`.
|
|
44
44
|
|
|
45
45
|
An id with a hyphen is one name inside a template — `{{ apiContainer_tn-data.data.total }}` reads that provider. So
|
|
46
46
|
subtraction is written with spaces: `{{ total - used }}`, never `total-used`.
|
|
@@ -69,7 +69,7 @@ outside the element that publishes it — each with the name it should have been
|
|
|
69
69
|
interpreter would read past, rather than letting a template render a value nobody wrote.
|
|
70
70
|
|
|
71
71
|
Filters: `default upper lower trim capitalize title camelize kebab snake ltrim rtrim pad padRight replace slice split
|
|
72
|
-
join reverse length first last contains startswith endswith number number_format round abs format sort batch chunk map
|
|
72
|
+
join reverse length first last contains startswith endswith number number_format currency percent round abs format sort batch chunk map
|
|
73
73
|
reduce merge keys values filter column find pluck unique flatten sum without only index_by group_by url_encode nl2br
|
|
74
74
|
striptags spaceless json_encode to_json object_as_json raw date base64_encode base64_decode md5 random`.
|
|
75
75
|
|
|
@@ -93,7 +93,8 @@ A lookup across two sources — a row joined to the stats around it:
|
|
|
93
93
|
step's params and an action's output, `"{{ text }}"` in quotes is safe too — a value inside a string literal of a
|
|
94
94
|
param written as a JSON document is escaped for it. Anywhere else (an attribute, a binding's template) it is not:
|
|
95
95
|
encode.
|
|
96
|
-
- **Numbers**: `number_format(decimals, point, thousands)`; `round(precision)
|
|
96
|
+
- **Numbers**: `number_format(decimals, point, thousands)`; `round(precision)`; `currency('USD', 'en', { trimZeros: true })`
|
|
97
|
+
(`$2,040.57`, `$440`); `percent(1)` (`0.256` → `25.6%`). Locale `en` unless named, so server and browser agree.
|
|
97
98
|
- **A step param that is one `{{ expression }}` is that value, with its type**: a number stays a number, and a
|
|
98
99
|
string stays a string however it looks — a password typed `1234` arrives as `"1234"`. Nothing is guessed from the
|
|
99
100
|
text: to convert, declare the type where the value lands (`setState`'s `type`, the action's input field). Text around
|
|
@@ -57,6 +57,13 @@ for it; over `max`, `problems` says so. It reads the SDK's render tracing, which
|
|
|
57
57
|
the space with it (the e2e harness: `renderSpace(page, space, { debugMode: true })`). What to do with the answer is in
|
|
58
58
|
[performance](performance.md).
|
|
59
59
|
|
|
60
|
+
## Asking the page what it holds
|
|
61
|
+
|
|
62
|
+
`plitzi check` lists every flow that failed while the page loaded; `--state` adds the state and every source by its
|
|
63
|
+
full name, `--element <id>` one element — what it reads, its own state, whether it is on screen. They come from the
|
|
64
|
+
page's dev tools (debug mode, any development server). In a test, `readDevTools(page, { state: true })` from
|
|
65
|
+
`@plitzi/sdk-authoring` answers the same.
|
|
66
|
+
|
|
60
67
|
## Spaces written for a test
|
|
61
68
|
|
|
62
69
|
Author them like any space — never as JSON: the validator is what tells a fixture that tests something from one that
|
|
@@ -112,6 +119,10 @@ expect(await page.evaluate(() => (window as unknown as { __painted: string[] }).
|
|
|
112
119
|
|
|
113
120
|
## Screenshots and scrolling
|
|
114
121
|
|
|
122
|
+
A browser holds back CSS animations and transitions in a tab that is not in view, and `onInterval` stops ticking there:
|
|
123
|
+
check motion with `getComputedStyle(element).animationName` (and `animationPlayState`), or two screenshots taken
|
|
124
|
+
apart, in a page that is in front — not a background tab.
|
|
125
|
+
|
|
115
126
|
The page scrolls the document in development exactly as in production while the dev-tools panel is folded away (the
|
|
116
127
|
badge). With the panel OPEN, the page shares the window with it and scrolls inside its own pane — close the panel, or
|
|
117
128
|
run with `debugMode: false`, before a `fullPage` screenshot or a scroll measurement. For a screenshot at a width and a
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Data typed by a sample
|
|
2
|
+
|
|
3
|
+
`source('site', home)` names a provider's source from a sample of its answer — the JSON file it reads, imported
|
|
4
|
+
(`import home from '../../public/data/home.json' with { type: 'json' }`). Every path is then completed by the editor
|
|
5
|
+
and checked: `site.data.hero.titel` is a type error, and refused `source-field-unknown` if it gets past the types.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const site = source('site', home);
|
|
9
|
+
apiContainer({ id: site.id, query: '/data/home.json', children: [
|
|
10
|
+
heading({ from: site.data.hero.title }),
|
|
11
|
+
text({ content: twig`{{ ${site.data.products}|length }} products` }),
|
|
12
|
+
list({ id: 'products', items: site.data.products, row: p => text({ from: p.item.title }) })
|
|
13
|
+
] })
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- A path is the source's full name (`apiContainer_site.data.hero.title`), so it goes in `from`, `items`, `bind` and
|
|
17
|
+
`visible` as it is, and into a template through `twig` (a plain template literal writes the same text, but a
|
|
18
|
+
type-checked lint refuses an object in one).
|
|
19
|
+
- A list fed by a path hands its `row` the item typed: every field any item of the sample has.
|
|
20
|
+
- An item of a list is read by position: `site.data.sections[1]`.
|
|
@@ -36,15 +36,19 @@ bar.
|
|
|
36
36
|
import { space } from './src/space.ts';
|
|
37
37
|
|
|
38
38
|
try {
|
|
39
|
-
const { schema, warnings } = authorSpace(space, { plugins: [] /* your declarations */ });
|
|
39
|
+
const { schema, warnings, suggestions } = authorSpace(space, { plugins: [] /* your declarations */ });
|
|
40
40
|
console.log(`${Object.keys(schema.flat).length} elements, ${warnings.length} warnings`);
|
|
41
41
|
warnings.forEach(warning => console.log(`[${warning.code}] ${warning.message}`));
|
|
42
|
+
suggestions.forEach(({ code, message, saves }) => console.log(`[suggest] ${code} (saves ${saves}): ${message}`));
|
|
42
43
|
} catch (error) {
|
|
43
44
|
console.log((error as Error).message);
|
|
44
45
|
}
|
|
45
46
|
```
|
|
46
47
|
|
|
47
|
-
2. **Fix, re-run, until it prints zero warnings.**
|
|
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
|
|
50
|
+
fix gone and nothing new — a fix it cannot place, or that would add a problem, is said with the reason. Then
|
|
51
|
+
typecheck the project.
|
|
48
52
|
3. **Look at it** — in a browser, at desktop and phone width, in both themes (see [testing](testing.md)). Stage 3 is
|
|
49
53
|
thorough about MEANING and blind to what follows.
|
|
50
54
|
|