@plitzi/sdk-authoring 0.37.7 → 0.37.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-authoring",
3
- "version": "0.37.7",
3
+ "version": "0.37.9",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist/index.js",
@@ -44,12 +44,12 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@microsoft/api-extractor": "^7.59.2",
47
- "@plitzi/plitzi-ui": "^1.6.24",
48
- "@plitzi/sdk-elements": "0.37.7",
49
- "@plitzi/sdk-interactions": "0.37.7",
50
- "@plitzi/sdk-schema": "0.37.7",
51
- "@plitzi/sdk-shared": "0.37.7",
52
- "@plitzi/sdk-style": "0.37.7",
47
+ "@plitzi/plitzi-ui": "^1.6.26",
48
+ "@plitzi/sdk-elements": "0.37.9",
49
+ "@plitzi/sdk-interactions": "0.37.9",
50
+ "@plitzi/sdk-schema": "0.37.9",
51
+ "@plitzi/sdk-shared": "0.37.9",
52
+ "@plitzi/sdk-style": "0.37.9",
53
53
  "@types/react": "^19.3.0",
54
54
  "eslint": "^9.39.5",
55
55
  "typescript": "^6.0.3",
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  name: plitzi-authoring
3
3
  description: >-
4
- Write or change a Plitzi space or template in TypeScript with @plitzi/sdk-authoring — pages, layouts, elements,
5
- CSS classes, data bindings, providers and flows — instead of hand-writing schema JSON. Use whenever the task is to
4
+ Write or change a Plitzi space or template in TypeScript with @plitzi/sdk-authoring — pages, layouts, components,
5
+ elements, CSS classes, data bindings, providers and flows — instead of hand-writing schema JSON. Use whenever the task is to
6
6
  create, extend, restyle or fix a space: adding a page or a section, sharing a header across pages, binding an
7
7
  element to data, showing or hiding something, wiring what happens on click, or turning an exported JSON into code.
8
8
  ---
@@ -52,10 +52,12 @@ type, the exported catalogues answer faster (`elementDefaultAttributes`, `elemen
52
52
  1. **Name what is referred to.** Give an `id` to every element a binding, a flow or a test addresses. Ids are ONE
53
53
  namespace for the whole space — layouts and every page share it — so an element built by a helper that runs more
54
54
  than once gets its id prefixed by what it is for: `` `${pageId}-foot` ``.
55
- 2. **Share with classes and layouts, never with copies.** A look used twice is a `styles()` class. Chrome shown on
56
- several pages — a header, a sidebar, a footer — is a **layout** the pages name, written once. A menu, a card grid,
57
- a list of steps is DATA mapped to elements (`entries.map(entry => link(…))`), not a block pasted per item. See
58
- [layouts and duplication](reference/layouts.md).
55
+ 2. **Share with classes, layouts and components, never with copies.** A look used twice is a `styles()` class.
56
+ Chrome shown on several pages — a header, a sidebar, a footer — is a **layout** the pages name, written once. A block
57
+ placed many times with different content — a product card, a testimonial — is a **component** placed with
58
+ `component(id, { props })`. A menu, a card grid, a list of steps is DATA mapped to elements
59
+ (`entries.map(entry => link(…))`), not a block pasted per item. See [layouts and duplication](reference/layouts.md)
60
+ and [components](reference/components.md).
59
61
  3. **One element, one base selector.** An element takes a shared `class` OR its own `css`, never both — authoring
60
62
  refuses the pair. A look that never changes is its own class.
61
63
  4. **Visible by default; decide which way the logic flips.** An element is on screen unless something hides it. When
@@ -158,16 +160,17 @@ link({ href: 'about' }); link({ href: '/games/nebula', mode: 'internal' }); link
158
160
  | --- | --- |
159
161
  | [elements-and-styles.md](reference/elements-and-styles.md) | Any element or CSS: factories, fields, classes, states, variants, tokens, fonts, lists, links |
160
162
  | [layouts.md](reference/layouts.md) | Anything shown on more than one page; menus; reducing duplication of elements and styles |
163
+ | [components.md](reference/components.md) | One block placed many times — a card, a tier, a testimonial: props, slots, binding a row into one, why it is closed |
161
164
  | [data-and-visibility.md](reference/data-and-visibility.md) | Bindings, providers, offline data, loading/empty/error states, live data, caching, showing and hiding, kept state |
162
165
  | [lists.md](reference/lists.md) | Rendering rows, filtering and sorting them, a detail page for one record |
163
166
  | [validation.md](reference/validation.md) | How `authorSpace` checks, the loop that wastes no attempts, and what it cannot see |
164
167
  | [authoring-errors.md](reference/authoring-errors.md) | What `authorSpace` refuses or warns about, and what to write instead |
165
168
  | [templates.md](reference/templates.md) | Any `{{ … }}` or `{% … %}`: where it runs, naming sources, filters, tests, dates |
166
169
  | [flows.md](reference/flows.md) | Clicks, submits, page loads, server actions, realtime channels, modals, state |
167
- | [plugins.md](reference/plugins.md) | A component of your own: props, binding them, writing state, channels, registering |
170
+ | [plugins.md](reference/plugins.md) | A component of your own: props, binding them, writing state, channels, registering, behaving in the builder |
168
171
  | [structure.md](reference/structure.md) | A space bigger than one screen: files, helpers, naming, keeping it short |
169
172
  | [testing.md](reference/testing.md) | Any test: `inspectPage` (one call, every problem), handles, fixtures, catching a flash from the first frame, shortcuts, counting renders |
170
173
  | [performance.md](reference/performance.md) | A page with many elements, a busy flow, something that feels slow: what renders, what it costs, how to measure it |
171
- | [templates-and-export.md](reference/templates-and-export.md) | Publishing a template; turning an exported JSON into code |
174
+ | [templates-and-export.md](reference/templates-and-export.md) | Publishing a template; turning an exported JSON — or a server action — into code |
172
175
  | [accessibility.md](reference/accessibility.md) | Icon buttons, fields, images, clickable cards, toggles, headings, landmarks, a canvas — anything a screen reader or a browser agent has to use |
173
176
  | [review-checklist.md](reference/review-checklist.md) | Before you say it is done |
@@ -0,0 +1,75 @@
1
+ # Components: a block written once, placed anywhere
2
+
3
+ A product card, a pricing tier, a testimonial: the same block on several pages, or several times on one, differing
4
+ only in what it says. A helper function that returns `ElementSpec` writes a COPY of the block wherever it is called —
5
+ the document holds every copy, and a person who later edits one in the builder edits that one. A **component** is the
6
+ block written ONCE: the document holds one tree, every placement is an instance of it, and an edit to it is an edit to
7
+ all of them, in code and in the builder alike.
8
+
9
+ ```ts
10
+ import { component, container, heading, text } from '@plitzi/sdk-authoring';
11
+
12
+ import type { ComponentSpec } from '@plitzi/sdk-authoring';
13
+
14
+ export const productCard: ComponentSpec = {
15
+ id: 'product-card',
16
+ label: 'Product card',
17
+ props: {
18
+ title: { type: 'text', description: 'The product name', required: true },
19
+ price: { type: 'number', description: 'In euros' },
20
+ featured: { type: 'boolean', description: 'Wears the accent border', default: false }
21
+ },
22
+ slots: ['product-card-actions'],
23
+ root: container({
24
+ id: 'product-card-root',
25
+ class: card,
26
+ children: [
27
+ heading({ id: 'product-card-title', bind: { content: 'props.title' } }),
28
+ text({ id: 'product-card-price', content: '{{ props.price }} €' }),
29
+ container({ id: 'product-card-actions' })
30
+ ]
31
+ })
32
+ };
33
+
34
+ // in the space
35
+ components: [productCard],
36
+ pages: [{ name: 'Shop', slug: 'shop', body: [
37
+ component('product-card', { props: { title: 'Lamp', price: 40 }, children: { 'product-card-actions': [button('Buy')] } })
38
+ ] }]
39
+ ```
40
+
41
+ - **Props are attributes of the instance**, declared like a step's params (`type`, `description`, `required`,
42
+ `default`, `options`) and read inside as `{{ props.<name> }}` — in a binding's `source`, a template or an attribute.
43
+ A prop name is letters, digits and `_`, never one an instance already has (`referenceId`, `slot`, `className`…).
44
+ A prop an instance leaves out, with no `default`, is `null`: `{{ props.blurb }}` prints nothing and
45
+ `visible: 'props.featured'` keeps the element hidden.
46
+ - **A prop can be bound** like any attribute: `component('product-card', { bind: [{ to: 'title', source: 'list_products.item.name' }] })`.
47
+ That is how a list row hands its record to a card — bind the record, not each field, if the card reads several:
48
+ a `json` prop `item`, read as `{{ props.item.name }}`.
49
+ - **Slots** are elements of the component's tree that an instance fills. `children: [ … ]` fills a component with one
50
+ slot; `children: { '<slot>': [ … ] }` names the slot for each. What fills a slot is the instance's, not the
51
+ component's: it is authored on the page and sees the page's sources.
52
+ - **Closed.** Inside, nothing but `props` and the globals (`state`, `auth`, `navigation`, `theme`, `variables`,
53
+ `computed`). A binding inside a component onto a provider of the page is refused — "nothing in this component answers
54
+ to …" — because the component would render differently wherever it was placed. Put the provider inside the component,
55
+ or hand the value in as a prop.
56
+ - **Ids are shared** with the whole space, like a layout's: name a component's elements after it (`product-card-title`).
57
+ The same ids render once per instance, each with state of its own.
58
+ - **State of its own per instance.** A flow inside a component that names one of its elements —
59
+ `toggleElement({ category: 'state', key: 'visibility' }, 'product-card-details')` — acts on THAT instance's copy.
60
+ Global state is shared: `toggleInState({ key: 'favourites', value: '{{ props.product.id }}' })` from any card.
61
+ - **Components nest**: a component may place another. One that places itself, directly or through another, is refused.
62
+ - **Checked when written**: a component the space does not declare, a prop it does not declare, a required one left out,
63
+ a value of the wrong kind (`featured: 'true'` for a boolean) and a child for a slot it does not have each throw, by name.
64
+
65
+ ## Component, layout or helper?
66
+
67
+ | You have | Write |
68
+ | --- | --- |
69
+ | Chrome a page renders INSIDE — top bar, sidebar, footer | a **layout** ([layouts.md](layouts.md)) |
70
+ | One block placed many times, differing in its content | a **component** |
71
+ | Many blocks of DIFFERENT structure built by the same logic | a **helper** returning `ElementSpec` |
72
+ | A list of the same block over data | a **list** whose row is the block — or places the component ([lists.md](lists.md)) |
73
+
74
+ A component is also what a person editing the space in the builder will find in its Components panel, open and edit
75
+ once; a helper's output is, to them, a pile of copies.
@@ -39,7 +39,7 @@ never a nested tree. Use the step builders — they fill in where a step runs an
39
39
 
40
40
  ## What a trigger hands the flow
41
41
 
42
- Name the trigger (`named('changed', onChange())`) and read its payload as `{{ changed.<field> }}`:
42
+ Name the trigger (`named('changed', on('onChange'))`) and read its payload as `{{ changed.<field> }}`:
43
43
 
44
44
  | Trigger | Payload |
45
45
  | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------- |
@@ -134,6 +134,18 @@ A plugin says what HAPPENED through its events (`onPick`, with the seat in the p
134
134
  decide what that means — write `state`, open a modal, call a server action. Prefer that to writing `state` from inside
135
135
  the component: the flow is visible in the space, the builder shows it, and the same act can come from a button too.
136
136
 
137
+ ## Behaving in the builder
138
+
139
+ The builder draws the element on its canvas while somebody edits the page: a click selects it, a drag moves it, a key
140
+ belongs to the editor.
141
+
142
+ - **Outside preview, do nothing on your own.** `usePlitziServiceContext().settings.previewMode` is `false` while the
143
+ page is edited. Declared interactions are already held back then; your own click handlers, timers, global listeners,
144
+ permission prompts and map gestures are not — gate them on `previewMode`, and still render something to select.
145
+ - **Never the global `window` or `document`.** The canvas is a frame of its own and the code runs in the builder's
146
+ window: listen, measure and go full screen through the node's own page (`ref.current.ownerDocument`, its
147
+ `defaultView`) or `usePlitziServiceContext().utils.getWindow()`. An `instanceof` check takes its class from there too.
148
+
137
149
  ## Components that draw into DOM they do not render
138
150
 
139
151
  A map, a chart library, anything that positions its own markers or popups: its roots are the library's to place. Never
@@ -27,6 +27,12 @@ Never rewrite an exported space by hand. `specFromSpace({ schema, style })` read
27
27
  `compareSpaces(original, authorSpace(spec))` must list nothing but what `corrections` explains. The builder's
28
28
  **Export** does all three. Edit the code from then on — and tidy it as you go ([structure.md](structure.md)).
29
29
 
30
+ A server action reads back the same way: `actionSpecFromEntry({ id, document })` gives the `defineAction` spec that writes
31
+ it — only when that spec writes the very same document, otherwise `reason` says why and it stays JSON — and
32
+ `actionToSource(spec)` writes the module. For the whole space as a project — pages, actions, functions, the source of
33
+ its plugins and runtime, its files — use `plitzi create --from <space>` (and `plitzi pull` later) rather than exporting
34
+ the parts by hand.
35
+
30
36
  For a document you did not author — an export, a JSON edited by hand — run the gate before serving it:
31
37
  `validateSpace({ schema, style })`.
32
38