@plitzi/sdk-server 0.38.7 → 0.38.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +10 -5
  3. package/dist/core/createServer.notFound.test.d.ts +1 -0
  4. package/dist/core/oauth/consentPage.js +1 -9
  5. package/dist/core/unusedPort.d.ts +6 -0
  6. package/dist/core/unusedPort.js +20 -0
  7. package/dist/helpers/compress.js +1 -1
  8. package/dist/helpers/escapeHtml.d.ts +2 -0
  9. package/dist/helpers/escapeHtml.js +13 -0
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.js +2 -1
  12. package/dist/modules/actions/runtime/errors.d.ts +6 -0
  13. package/dist/modules/actions/runtime/errors.js +7 -1
  14. package/dist/modules/actions/runtime/projectData.js +1 -1
  15. package/dist/modules/actions/runtime/runAction.js +2 -2
  16. package/dist/modules/functions/routes.js +2 -2
  17. package/dist/modules/project/plugins.d.ts +1 -1
  18. package/dist/modules/project/plugins.js +2 -2
  19. package/dist/modules/project/serveProject.js +40 -12
  20. package/dist/modules/project/spaceFailure.d.ts +8 -0
  21. package/dist/modules/project/spaceFailure.js +76 -0
  22. package/dist/modules/runtime/bundle.d.ts +1 -1
  23. package/dist/modules/runtime/bundle.js +1 -1
  24. package/dist/modules/runtime/runner.d.ts +1 -0
  25. package/dist/modules/runtime/runner.js +2 -3
  26. package/dist/modules/ssr/applySSRResult.d.ts +11 -0
  27. package/dist/modules/ssr/applySSRResult.js +14 -1
  28. package/dist/modules/ssr/buildBody.js +2 -0
  29. package/dist/modules/ssr/handler.js +2 -2
  30. package/dist/modules/ssr/prepareRender.d.ts +2 -0
  31. package/dist/modules/ssr/prepareRender.js +9 -3
  32. package/dist/modules/ssr/streamBody.js +3 -2
  33. package/package.json +3 -3
  34. package/skills/plitzi-authoring/SKILL.md +34 -149
  35. package/skills/plitzi-authoring/recipes/detail-page.ts +4 -2
  36. package/skills/plitzi-authoring/recipes/plugin.ts +1 -1
  37. package/skills/plitzi-authoring/reference/accessibility.md +3 -2
  38. package/skills/plitzi-authoring/reference/authoring-errors.md +4 -0
  39. package/skills/plitzi-authoring/reference/drawing.md +1 -1
  40. package/skills/plitzi-authoring/reference/flows.md +6 -4
  41. package/skills/plitzi-authoring/reference/index.md +33 -0
  42. package/skills/plitzi-authoring/reference/layouts.md +18 -0
  43. package/skills/plitzi-authoring/reference/plugins.md +2 -2
  44. package/skills/plitzi-authoring/reference/recipes.md +25 -0
  45. package/skills/plitzi-authoring/reference/rules.md +61 -0
  46. package/skills/plitzi-authoring/reference/snippets-and-export.md +2 -2
  47. package/skills/plitzi-authoring/reference/structure.md +1 -1
  48. package/skills/plitzi-authoring/reference/testing.md +1 -1
  49. package/skills/plitzi-authoring/reference/validation.md +1 -1
@@ -1,6 +1,6 @@
1
1
  import { buildHtmlCacheKey } from "../../helpers/cache/keys.js";
2
2
  import { draftSessionCookie, takeDraftOverride } from "./preview.js";
3
- import { applySSRResult } from "./applySSRResult.js";
3
+ import { applySSRResult, isReusable } from "./applySSRResult.js";
4
4
  import { buildBody } from "./buildBody.js";
5
5
  import { streamBody } from "./streamBody.js";
6
6
  import { RequestMetrics } from "../../helpers/metrics.js";
@@ -63,7 +63,7 @@ var renderSSR = async (req, res, config, renderFn, pluginManager, caches) => {
63
63
  metrics.log(`${req.method} ${req.path}`);
64
64
  }
65
65
  if (applySSRResult(res, result)) return;
66
- if (htmlCache && cacheKey && body !== void 0 && cacheable) {
66
+ if (htmlCache && cacheKey && body !== void 0 && cacheable && isReusable(result)) {
67
67
  const page = {
68
68
  html: body,
69
69
  compressed: {}
@@ -11,5 +11,7 @@ export type RenderPrep = {
11
11
  };
12
12
  /** False for a render that must not be served to anybody else from a cache: it carries this request's own runs. */
13
13
  cacheable: boolean;
14
+ /** A server provider of the page said its address shows nothing (`notFound`): sent with status 404. */
15
+ notFound: boolean;
14
16
  };
15
17
  export declare const prepareRender: (req: SSRRequest, config: SSRPageServerConfig, spaceId: number, environment: Environment, revision: number, pluginManager: PluginManager, offlineDataCache?: TtlCache<string>, metrics?: RequestMetrics, offlineDataOverride?: OfflineDataRaw) => Promise<RenderPrep>;
@@ -20,7 +20,7 @@ import { sdkAssetVersion } from "../../core/sdkAssets.js";
20
20
  import { buildServerInfo } from "../../helpers/buildServerInfo.js";
21
21
  import { resolveDebugMode } from "../../helpers/resolveDebugMode.js";
22
22
  import { flagUserFromSSR, flagValues, resolveFlags } from "@plitzi/sdk-shared/flags";
23
- import { hasServerElements } from "@plitzi/sdk-shared/schema/serverElements";
23
+ import { collectServerElements, notFoundProvider } from "@plitzi/sdk-shared/schema/serverElements";
24
24
  import { debugCookieName } from "@plitzi/sdk-shared/devTools";
25
25
  import { themeFromCookies } from "@plitzi/sdk-shared/theme";
26
26
  import { paintedKeys, paintedStateFor } from "@plitzi/sdk-shared/state/paintedState";
@@ -74,7 +74,8 @@ var prepareRender = async (req, config, spaceId, environment, revision, pluginMa
74
74
  queryParams: req.query,
75
75
  user: flagUserFromSSR(req.ctx.user)
76
76
  }, flagOverrides)) : void 0;
77
- const rscData = rscEnabled && pageMatch !== void 0 && hasServerElements(schema, pageMatch.pageId, pageFlags) && config.adapters.getRscData ? await m("rsc", () => config.adapters.getRscData?.({
77
+ const serverElements = rscEnabled && pageMatch !== void 0 ? collectServerElements(schema, pageMatch.pageId, void 0, pageFlags) : [];
78
+ const rscData = serverElements.length > 0 && config.adapters.getRscData ? await m("rsc", () => config.adapters.getRscData?.({
78
79
  req,
79
80
  spaceId: req.ctx.spaceDeployment?.spaceId ?? spaceId,
80
81
  environment: req.ctx.spaceDeployment?.environment ?? environment,
@@ -84,6 +85,10 @@ var prepareRender = async (req, config, spaceId, environment, revision, pluginMa
84
85
  flagOverrides
85
86
  })) : rscPath ? { serverData: {} } : void 0;
86
87
  const pageSeo = resolvePageSeo(schema, pageMatch?.pageId);
88
+ const notFound = pageMatch !== void 0 && rscData?.serverData !== void 0 ? notFoundProvider(serverElements, rscData.serverData, {
89
+ routeParams: pageMatch.routeParams,
90
+ queryParams: req.query
91
+ }) !== void 0 : false;
87
92
  const server = buildServerInfo(req, config, {
88
93
  rscPath,
89
94
  rscData,
@@ -281,7 +286,8 @@ var prepareRender = async (req, config, spaceId, environment, revision, pluginMa
281
286
  devReload: config.devReload === true,
282
287
  offlineData: offlineDataStr
283
288
  },
284
- cacheable: actionRuns === void 0 && forcedFlags === void 0
289
+ cacheable: actionRuns === void 0 && forcedFlags === void 0,
290
+ notFound
285
291
  };
286
292
  };
287
293
  //#endregion
@@ -1,4 +1,4 @@
1
- import { applySSRResult } from "./applySSRResult.js";
1
+ import { applySSRResult, isReusable, withNotFound } from "./applySSRResult.js";
2
2
  import Component from "./Component.js";
3
3
  import { prepareRender } from "./prepareRender.js";
4
4
  import { renderToPipeableStream } from "react-dom/server";
@@ -30,7 +30,7 @@ var streamBody = async (req, res, config, spaceId, environment, revision, render
30
30
  const tailBuf = Buffer.from(tail, "utf-8");
31
31
  res.write(tailBuf);
32
32
  res.end();
33
- if (chunks && cacheKey && htmlCache) htmlCache.set(cacheKey, {
33
+ if (chunks && cacheKey && htmlCache && isReusable(result)) htmlCache.set(cacheKey, {
34
34
  html: head + Buffer.concat(chunks).toString("utf-8") + tail,
35
35
  compressed: {}
36
36
  });
@@ -49,6 +49,7 @@ var streamBody = async (req, res, config, spaceId, environment, revision, render
49
49
  res.setHeader("Server-Timing", metrics.toServerTimingHeader());
50
50
  metrics.log(`${req.method} ${req.path}`);
51
51
  }
52
+ withNotFound(result, prep.notFound);
52
53
  if (applySSRResult(res, result)) {
53
54
  abort();
54
55
  resolve();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-server",
3
- "version": "0.38.7",
3
+ "version": "0.38.9",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist",
@@ -96,8 +96,8 @@
96
96
  "./dist/env.js"
97
97
  ],
98
98
  "dependencies": {
99
- "@plitzi/plitzi-sdk": "0.38.7",
100
- "@plitzi/sdk-shared": "0.38.7",
99
+ "@plitzi/plitzi-sdk": "0.38.9",
100
+ "@plitzi/sdk-shared": "0.38.9",
101
101
  "ejs": "^6.0.1",
102
102
  "esbuild": "^0.28.2",
103
103
  "jsonwebtoken": "^9.0.3",
@@ -9,174 +9,59 @@ description: >-
9
9
 
10
10
  # Authoring Plitzi spaces
11
11
 
12
- A space is two JSON documents — a schema and a style — full of cross-referenced ids. **Never write them by hand.**
13
- `@plitzi/sdk-authoring` derives every id, class name, parent link, breakpoint map and flow chain from a small
14
- declaration, and refuses a declaration that would not render.
12
+ A space is two JSON documents full of cross-referenced ids — **never write them by hand**. `@plitzi/sdk-authoring`
13
+ derives them from a small declaration, and refuses one that would not render.
15
14
 
16
15
  ```ts
17
- import { authorSpace, container, heading, styles, text } from '@plitzi/sdk-authoring';
16
+ import { heading, styles, text } from '@plitzi/sdk-authoring';
18
17
 
19
- const page = styles('page', { display: 'flex', 'flex-direction': 'column', padding: '96px 24px', gap: '16px' });
18
+ const page = styles('page', { display: 'flex', 'flex-direction': 'column', gap: '16px' });
20
19
 
21
20
  export const space = {
22
21
  name: 'My space',
23
22
  permanentUrl: 'my-space',
24
23
  pages: [{ name: 'Home', slug: '', class: page, body: [heading('Hello', { subType: 'h1' }), text('A paragraph.')] }]
25
24
  };
26
-
27
- const { schema, style, warnings } = authorSpace(space);
28
25
  ```
29
26
 
30
- **Start with [the cheatsheet](CHEATSHEET.md)** — the factories, fields, steps and the problems met most, on one page —
31
- and open a reference below only when the task names its subject. What an element takes, a step's params, what a
32
- trigger hands its flow: `npx @plitzi/cli explain <name>` answers in a few lines (over MCP, `plitzi://explain/<name>`).
33
- The published `.d.ts` documents the rest — search it by name, never read it whole.
34
-
35
- This skill writes a space that lives in code. One that lives on Plitzi — edited in the builder, published from there —
36
- is edited through the Plitzi MCP server instead, never both on one space; `plitzi create --from <space>` turns the
37
- second into the first. If the MCP asks for a sign-in nobody can give, a project in code needs no account.
27
+ A space on Plitzi — edited in the builder — is edited through the Plitzi MCP server instead, never both on one space.
38
28
 
39
29
  ## How to work
40
30
 
41
- 1. **Read before you write.** Open `src/space/index.ts` (and whatever it imports) and find the layout, the classes and the
42
- helpers already there. Extend them; do not add a second way of doing something the space already does.
43
- 2. **Change the declaration, then author it.** `npm run author` (or a restart) runs `authorSpace` — not `doctor`, which
44
- is the project's. It checks every field, value, template, name, param and page link, and a refusal says what to
45
- write instead: do exactly that. Never work around a check, cast past it, or move the logic into a plugin to escape
46
- it. The linter's problems come as ONE list — fix every line before running again. How it checks, and what it
47
- cannot see: [validation](reference/validation.md).
48
- 3. **Read every warning, then every suggestion.** A warning names something written that will not do what it says —
49
- zero warnings is the bar. A suggestion (`[suggest]`) names a shorter way to the same page — a layout, a component,
50
- a `list`, a button's own `content` — or what nothing uses. Take them, the ones that save the most first
51
- ([efficiency](reference/efficiency.md)). Then `npm run lint:space`: how the source is written — long files, rows of
52
- data inline, colours that are not tokens — at file:line. Leave both clean.
53
- 4. **Look at it.** `npm run check -- /about --width 1440,390` says in text whether the page is whole — every element on
54
- screen, nothing overflowing, a clean console; `npm run shot -- /about --width 390 --scheme dark` is the picture
55
- (`--frames 4` shows what moves); `npm run visual` runs the checks. Look at desktop, tablet and mobile, light and dark, and the page while its data is still loading.
56
- 5. **Go through the [review checklist](reference/review-checklist.md) before saying it is done.** It is the feedback a
57
- reviewer gives on every change, written down so you do not need to hear it.
31
+ 1. **Find, then write.** `npx plitzi element where <id|class|words>` answers the file, the line and the call: edit there, and
32
+ extend what the space already has. People move files — never keep a note of where something is.
33
+ 2. **Author.** `npm run author`. A refusal says what to write instead: do exactly that. Every problem comes at once —
34
+ fix them all before running again. Zero warnings; take the suggestions, the biggest first.
35
+ 3. **Look.** `npm run check -- /path --width 1440,390` says in text whether the page is whole; `npm run shot` only
36
+ when the text is not enough.
37
+ 4. **Before saying done:** `npm run lint:space` clean, and the [review checklist](reference/review-checklist.md).
58
38
 
59
- ## The rules that matter most
39
+ What a name means — an element, a step, a trigger, a code, any export (`pageFamily`, `SpaceSpec`): `npx plitzi explain
40
+ <name>`, in a few lines. Never read the `.d.ts`.
60
41
 
61
- 1. **Name what is referred to.** Give an `id` to every element a binding, a flow or a test addresses. Ids are ONE
62
- namespace for the whole space — layouts and every page share it — so a helper that runs more than once builds inside
63
- `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
64
- space (`data-plitzi-el` in the page); the DOM id a URL's `#fragment` lands on is its `anchor`.
65
- 2. **Share with classes, layouts and components, never with copies.** A look used twice is a `styles()` class.
66
- Chrome shown on several pages — a header, a sidebar, a footer — is a **layout** the pages name, written once. A block
67
- placed many times with different content — a product card, a testimonial — is a **component** placed with
68
- `component(id, { props })`. A menu, a card grid, a list of steps is DATA, never a block pasted per item: a short
69
- menu mapped in code is fine; rows — cards, dishes, tiles — are one `list` (`items: [ … ]`) whose row is written
70
- once. A link or a button says its words as
71
- its own `content`, not through a `text` inside it. Pages of one shape are one `pageFamily` over data. See
72
- [layouts](reference/layouts.md), [components](reference/components.md), [structure](reference/structure.md) and
73
- [efficiency](reference/efficiency.md).
74
- 3. **One element, one base selector.** An element takes a shared `class` OR its own `css`, never both — authoring
75
- refuses the pair. "This class plus one thing" is the class with rules on top, last in the list:
76
- `class: [cover, { opacity: '0.25' }]` (needs the element's `id`; it becomes the class `<id>--own`). A look that
77
- never changes is its own class.
78
- 4. **Visible by default; decide which way the logic flips.** An element is on screen unless something hides it. When
79
- the logic REVEALS it (hidden → shown: an empty state, a "get started" card, an admin-only panel), it starts hidden —
80
- `visible: 'source'`, or `visible: false` plus a binding for a computed condition — so it never flashes while data
81
- loads (`condition-starts-visible` warns). When a flag HIDES it (shown → hidden: a sidebar label until the sidebar
82
- is folded), it keeps the default and an absent flag must leave it shown. See
83
- [data and visibility](reference/data-and-visibility.md). What a PERSON switches on — a feature in beta, a rollout —
84
- is a feature flag, not a visibility: gated off, it is not rendered at all. See [feature flags](reference/feature-flags.md).
85
- 5. **Know where a template is evaluated.** A binding's template (`bindTemplate`) and a step's params evaluate full
86
- Twig. An ATTRIBUTE resolves a name with filters (`{{ list_games.item.slug }}`, `{{ post.slug|url_encode }}`) against
87
- the sources around the element; a condition there is used as written. Inside any template a source is spelled in
88
- full — `apiContainer_stats`, `list_rows` — and a query param is `navigation.queryParams.x`. A template that feeds a
89
- list its `items` hands over its value (`returns: 'value'`). `authorSpace` refuses a template it cannot read and a
90
- name nothing answers to. See [templates](reference/templates.md).
91
- 6. **Tokens, not colours.** Every colour is a variable of the space with a `light` and a `dark` value; both themes are
92
- checked from the first commit.
93
- 7. **Times in UTC, and say so.** Format with an explicit zone (`|date('j M · H:i', 'UTC')`) and print "UTC" beside it:
94
- a page rendered on a server and hydrated in a browser in another zone must agree on the hour.
95
- 8. **Breakpoints are ranges.** `tablet` (48–64rem) and `mobile` (up to 48rem) each inherit only from `desktop`; a rule
96
- meant for both is written under `compact`.
97
- 9. **Never invent data.** Numbers, names and states on screen come from a source. A panel with nothing true to say is
98
- an empty state, not a placeholder figure. With no backend, the data is JSON read by an `apiContainer`: a server
99
- project's `src/data/*.json`, read on the server and never served; with no server, `public/data/*.json`, which is
100
- public — see [data and visibility](reference/data-and-visibility.md).
101
- 10. **Never hand-write** `flat`, derived ids, `styleSelectors`, `beforeNode`/`afterNode`/`flowId`, or a
102
- `styleVariant` binding's key — use the factories, `variantFrom` and `activeOn`.
103
- 11. **A switch is named for how it leaves its default.** `toggleState` turns a key nobody has set yet ON, so a key
104
- named for the default (`showPlates`, on by default) takes a first click to do nothing: name it `platesOff`, and read
105
- every switch through `computed` (`plates: '{{ state.platesOff ? false : true }}'`) so its default shows before
106
- anybody touches it.
107
- 12. **Hand plugins over as their declarations**: `authorSpace(space, { plugins: [declaration] })` holds a plugin —
108
- its own type, or a `custom({ renderType })` host — to the events, actions and attributes it declares. See
109
- [plugins](reference/plugins.md).
110
- 13. **Usable without sight.** Screen readers and browser agents (Claude in Chrome) find a page's controls in its
111
- accessibility tree: every button and link has words (an icon-only button a `title`), every field a `label`
112
- (`hideLabel: true` hides it and keeps the name), every image an `alt` or `decorative: true`. Clicks go on a
113
- `button` — it holds children, so a whole card can be one — or a `link`, never on a container. See
114
- [accessibility](reference/accessibility.md).
115
- 14. **Motion that stays smooth.** Animate `opacity` and `transform` only; no animated blur, shadow or size. See
116
- [motion](reference/colours-and-motion.md).
42
+ ## Five rules authoring cannot check for you
117
43
 
118
- ## Recipes
44
+ 1. **Name what is referred to.** An `id` for every element a binding, a flow or a test addresses; ids are one namespace,
45
+ so a helper that runs twice builds inside `scope('promos', ref => …)`.
46
+ 2. **Share, never copy.** A look used twice is a class; chrome on several pages a layout; a block placed again with
47
+ other content a component; rows of data one `list`.
48
+ 3. **What is revealed starts hidden** (`visible: 'source'`), so it never flashes while its data loads.
49
+ 4. **Know where a template runs.** A binding and a step's params are full Twig; an attribute resolves a name with
50
+ filters. A source is spelled in full: `apiContainer_stats`.
51
+ 5. **Tokens, not colours** — a variable with a `light` and a `dark` value.
119
52
 
120
- Each is a whole file that authors with no warning — CI holds it to that. Copy the one that fits, then change the names.
53
+ The rest, and why: [rules](reference/rules.md).
121
54
 
122
- | To… | Open |
123
- | --- | --- |
124
- | 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) |
125
- | Data typed by a sample of it: completed and checked paths, typed rows | [recipes/typed-data.ts](recipes/typed-data.ts) |
126
- | Data read by the page server (`--mode server`) | [recipes/server-data.ts](recipes/server-data.ts) |
127
- | An accordion, one answer open at a time | [recipes/accordion.ts](recipes/accordion.ts) |
128
- | Filter and sort a list from a select | [recipes/filter-a-list.ts](recipes/filter-a-list.ts) |
129
- | A page per record (`/products/:slug`), and "not found" | [recipes/detail-page.ts](recipes/detail-page.ts) |
130
- | Link to a section of a page (`/#plans`) | [recipes/link-to-a-section.ts](recipes/link-to-a-section.ts) |
131
- | A carousel: slides with arrows, dots and autoplay; a marquee; a row that swipes | [recipes/carousel.ts](recipes/carousel.ts) |
132
- | Do something every few seconds — a ticker, a poll, a slideshow by hand | [recipes/every-few-seconds.ts](recipes/every-few-seconds.ts) |
133
- | A marquee that scrolls for ever and stops under the pointer | [recipes/marquee.ts](recipes/marquee.ts) |
134
- | A row that scrolls sideways, with arrows that hide at its ends | [recipes/scroll-a-row.ts](recipes/scroll-a-row.ts) |
135
- | A link built from a row: WhatsApp with the product's name, `mailto:` | [recipes/link-with-data.ts](recipes/link-with-data.ts) |
136
- | React to a click or a submit; a modal; a switch | [recipes/forms-and-modals.ts](recipes/forms-and-modals.ts) |
137
- | A feature behind a flag | [recipes/feature-flag.ts](recipes/feature-flag.ts) |
138
- | An element of your own (a plugin), checked | [recipes/plugin.ts](recipes/plugin.ts) |
139
- | Controls a screen reader and a browser agent can use | [recipes/usable-without-sight.ts](recipes/usable-without-sight.ts) |
140
- | Tokens, a shared class, "the class plus one thing", tablet and phone at once | [recipes/style-a-page.ts](recipes/style-a-page.ts) |
141
- | A design in Tailwind classes, kept as classes the builder edits | [recipes/from-tailwind.ts](recipes/from-tailwind.ts) |
142
- | 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) |
55
+ ## What to read
143
56
 
144
- ## References
57
+ Start with [the cheatsheet](CHEATSHEET.md), then only what the task names:
145
58
 
146
- | Read | When |
59
+ | The task | Read |
147
60
  | --- | --- |
148
- | [elements-and-styles.md](reference/elements-and-styles.md) | Any element or CSS: factories, fields, classes, states, variants, tokens, fonts, lists, links |
149
- | [colours-and-motion.md](reference/colours-and-motion.md) | Colours for both themes, tokens, keyframes, and motion that stays smooth (good practices) |
150
- | [tailwind.md](reference/tailwind.md) | A design written in Tailwind classes: `tw()`, its breakpoints and states, what it refuses |
151
- | [layouts.md](reference/layouts.md) | Anything shown on more than one page; menus; reducing duplication of elements and styles |
152
- | [efficiency.md](reference/efficiency.md) | The same page with fewer elements: the suggestions `authorSpace` makes, and the short way for each long one |
153
- | [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 |
154
- | [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 |
155
- | [kept-state.md](reference/kept-state.md) | State that outlives a reload: `keepState`, transient and painted keys |
156
- | [auth.md](reference/auth.md) | Signing people in: providers, `authLogin`, `auth.*`, visitor roles |
157
- | [feature-flags.md](reference/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 |
158
- | [lists.md](reference/lists.md) | Rendering rows, filtering and sorting them, a detail page for one record, carousels |
159
- | [typed-sources.md](reference/typed-sources.md) | Data typed by a sample of it: `source()`, typed rows, `twig` for templates |
160
- | [validation.md](reference/validation.md) | How `authorSpace` checks, the loop that wastes no attempts, and what it cannot see |
161
- | [authoring-errors.md](reference/authoring-errors.md) | What `authorSpace` refuses or warns about, and what to write instead |
162
- | [templates.md](reference/templates.md) | Any `{{ … }}` or `{% … %}`: where it runs, naming sources, filters, tests, dates |
163
- | [flows.md](reference/flows.md) | Clicks, submits, page loads, every few seconds, server actions, modals, state |
164
- | [realtime.md](reference/realtime.md) | Pages that see each other: channels, presence, cursors, a shared board, who may hear a topic |
165
- | [plugins.md](reference/plugins.md) | A component of your own: props, binding them, writing state, channels, registering, behaving in the builder |
166
- | [drawing.md](reference/drawing.md) | A plugin that draws or animates: a canvas sized to the device, WebGL, a loop that stops when unseen |
167
- | [structure.md](reference/structure.md) | A space bigger than one screen: files, helpers, naming, keeping it short |
168
- | [testing.md](reference/testing.md) | Any test: `inspectPage`, handles, fixtures, catching a flash from the first frame, shortcuts, counting renders |
169
- | [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 |
170
- | [snippets-and-export.md](reference/snippets-and-export.md) | Publishing a snippet; turning an exported JSON — or a server action — into code |
171
- | [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 |
172
- | [review-checklist.md](reference/review-checklist.md) | Before you say it is done |
173
-
174
- **What to read for a kind of task** — the cheatsheet, then only these:
175
-
176
- - A site — landing, catalogue, blog: elements-and-styles, layouts, components, lists.
177
- - An app with state and actions: data-and-visibility, templates, flows — realtime when pages see each other.
178
- - A component of your own: plugins.
179
- - A refusal or a warning: search authoring-errors.md for its code — never read it whole.
180
- - Tests: testing.
181
-
182
- Nothing else needs reading up front.
61
+ | A site — landing, catalogue, blog | [elements-and-styles](reference/elements-and-styles.md), [layouts](reference/layouts.md), [components](reference/components.md), [lists](reference/lists.md) |
62
+ | An app with state and actions | [data-and-visibility](reference/data-and-visibility.md), [templates](reference/templates.md), [flows](reference/flows.md) |
63
+ | A component of your own | [plugins](reference/plugins.md) |
64
+ | A whole working file to copy | [recipes](reference/recipes.md) |
65
+ | A refusal or a warning | `npx plitzi explain <code>` |
66
+ | Tests | [testing](reference/testing.md) |
67
+ | Anything else | [the index](reference/index.md): every reference, and when |
@@ -1,7 +1,8 @@
1
1
  /* eslint-disable quotes -- templates quote their own strings, and read best in the other quotes */
2
2
  /**
3
3
  * A page per record: a card links to `/products/<slug>`, and the detail page narrows the same file to the product its
4
- * address names — with a message, not an empty page, when no product has that name.
4
+ * address names — with a message, not an empty page, when no product has that name, and status 404: the provider is
5
+ * resolved on the server, and `notFound` says when its answer holds nothing for this address.
5
6
  */
6
7
  import { apiContainer, heading, link, list, text, listItem } from '@plitzi/sdk-authoring';
7
8
 
@@ -48,7 +49,8 @@ export const recipe: SpaceSpec = {
48
49
  apiContainer({
49
50
  id: 'catalog-one',
50
51
  query: '/data/products.json',
51
- cache: true,
52
+ runtime: 'server',
53
+ notFound: "{{ not (source.data.products|find('slug', navigation.routeParams.slug)) }}",
52
54
  children: [
53
55
  list({
54
56
  id: 'this-product',
@@ -1,5 +1,5 @@
1
1
  /**
2
- * An element of your own (a plugin): authored from its declaration — the one `plitzi add plugin` writes — so a flow on
2
+ * An element of your own (a plugin): authored from its declaration — the one `plitzi plugin add` writes — so a flow on
3
3
  * its events, a step to its actions and its attributes are all checked. Hand the declaration to `authorSpace` too.
4
4
  */
5
5
  import {
@@ -38,6 +38,8 @@ image({ src: '/grain.png', decorative: true }) // an orname
38
38
  image({ decorative: true, bind: { src: 'post.record.cover' } }) // a cover under its own headline adds nothing
39
39
  image({ bind: { src: 'row.item.cover', alt: 'row.item.title' } }) // …unless it is alone in a link: then it names it
40
40
  fontAwesome({ icon: 'fa-solid fa-triangle-exclamation', label: 'Overdue' }) // an icon that says something alone
41
+ text('福', { decorative: true }) // a seal or a mark drawn for the look alone
42
+ list({ label: 'Kinds of capsule', … }) // a group of options is named, as a group
41
43
  ```
42
44
 
43
45
  ## Clicks go on controls
@@ -111,5 +113,4 @@ can't click something that only appears on focus.
111
113
  - `authorSpace` warnings: zero, as always.
112
114
  - In a test, `page.getByRole('button', { name: 'Close' })` fails when the name is missing.
113
115
  `expect(locator).toMatchAriaSnapshot(…)` pins the whole outline.
114
- - Through MCP, `plitzi_screenshot` with `view: "accessibility"` returns the page's tree and lists everything that has
115
- no name.
116
+ - Through MCP, `plitzi_look` returns the page's tree (its default view) and lists everything that has no name.
@@ -101,6 +101,8 @@ The space is not written until these are fixed.
101
101
  | `motion-invalid` | a `motion` with a preset, a trigger or a timing the page cannot play | `motion: { enter: 'fade-up', on: 'view' }` — the message lists the presets |
102
102
  | `motion-no-tag` | a `motion` on an element with no tag of its own — nothing to move | the motion on what it wraps, or a `subType` on it |
103
103
  | `no-pages` | a space with no pages | `pages: [{ id: 'home', name: 'Home', slug: '', body: [] }]` |
104
+ | `not-found-in-browser` | `notFound` on a provider asked from the browser — its answer arrives after the page was sent with its status | `runtime: 'server'` on the provider, or `visible` on the page's "not found" part instead |
105
+ | `not-found-not-a-template` | `notFound` that is not one `{{ expression }}` against the answer — never `true`, so never a 404 | `notFound: '{{ source.found == false }}'` |
104
106
  | `notifications-shape` | `notifications` with a field it does not have, or a value that is not one CSS value | the field it suggests, or one it lists; one CSS value, like 'var(--card)', '12px' or '500' |
105
107
  | `outside-ancestor` | an element that reads the state of an element it is not inside | nest it in the element the message names |
106
108
  | `page-access-level` | an `accessLevel` that is not one the router reads | one of the values the message lists |
@@ -112,6 +114,7 @@ The space is not written until these are fixed.
112
114
  | `part-missing` | a compound element — a carousel, a tab container, a dropdown — without a part it renders through | the part the message names, inside it (`carousel()` writes its own track) |
113
115
  | `prop-missing` | an instance without a prop its component requires | `component('card', { props: { name: … } })`, or bind it |
114
116
  | `prop-name` | a prop whose name a template cannot read as `props.x` | letters, digits and `_` |
117
+ | `prop-type-unknown` | a prop declared with a type no editor offers and nothing checks a value against | one of text, textarea, select, boolean, number, scalar, json, elementIds — words are `text` |
115
118
  | `prop-unknown` | a prop the component does not declare, handed in or read | the prop it suggests, or declare it: `props: { name: { type: 'text' } }` |
116
119
  | `prop-value` | a prop handed in with a value its declaration does not take | a value of the declared type, or one of its options |
117
120
  | `props-outside-component` | `props.x` read outside a component | read the source it would have come from |
@@ -228,6 +231,7 @@ Nothing is wrong: the page renders as written. Each is a shorter way to the same
228
231
  | `custom-css-slot` | a part of a built-in element dressed in `customCss` by the SDK's markup — a form control's `<input>`, a pager's buttons, a heading inside a markdown | a class on the slot of that part — `slots: { field: input }`, `elements.<type>.slots` — with its states |
229
232
  | `heavy-animation` | keyframes animating what the browser repaints or lays out again on every frame — a size, a position, a blur, a shadow, or a colour in a loop — which stutters whenever the page is busy, most of all while it loads | `opacity` and `transform`: a size or a position is `translate`/`scale`, a blur or a shadow is the `opacity` of a layer carrying it; a loop that must animate anything else starts `paused` and runs under `[data-hydrated]` |
230
233
  | `literal-colour` | a colour written out in a class where the space has a token of that value — it stays put in the dark scheme | `var(--token)` when it should follow the scheme; a token of one value of its own when it must stay the same in both |
234
+ | `not-found-page` | a space with no page of its own for an address no other page answers — a plain one was added, in the home page’s layout, sent with status 404 | a page whose slug is `'*'`: `{ id: 'not-found', name: 'Not found', slug: '*', layout: …, body: [...] }` |
231
235
  | `repeated-on-pages` | the same block — a header, a footer, a side panel — written into several pages | a layout holding it once (`layouts`, and `layout: { id, slot }` on each page) — a component when only some pages of a layout carry it; a link marks its own page with the `current` state |
232
236
  | `repeated-shape` | the same structure written again and again with different words — cards, rows, tiles | a component with props (`components`, `component(id, { props })`), or one `list` when they are rows of data side by side — a few cards a person rewords on the canvas can stay cards |
233
237
  | `unused-class` | a class declared in `classes` that no element, binding, flow or other class names | remove it from `classes` — or wear it where it was meant to go |
@@ -17,7 +17,7 @@ It sizes the canvas to the device (at most 2× — `maxPixelRatio`), follows its
17
17
  can see it move: on a live page (in the builder it draws one still frame), for a visitor who did not ask for less
18
18
  motion, with the tab in front and the canvas on screen; `paused` holds it (bind it to a hover). A shader that does not
19
19
  compile — GLSL ES 1.0 wants `196.0`, not `196` — throws a `ShaderError` with the driver's log, printed as
20
- `[plugin <type> "<id>"] fragment shader failed: …` (`plitzi check` lists it under the console) and `error` says it;
20
+ `[plugin <type> "<id>"] fragment shader failed: …` (`plitzi page check` lists it under the console) and `error` says it;
21
21
  show the still image meanwhile, as above. `useAnimationFrame(onFrame, { target })` is the same loop for motion that
22
22
  is not a canvas.
23
23
 
@@ -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' },
@@ -131,8 +131,8 @@ form({
131
131
  });
132
132
  ```
133
133
 
134
- A `formControl` is `required` by default: an optional field says `required: false`, or an empty one stops the submit
135
- without a word.
134
+ A `formControl` is optional unless it says `required: true`, as an HTML field is. A required field that is empty stops
135
+ the submit, and the browser says which.
136
136
 
137
137
  ## Notifications
138
138
 
@@ -144,6 +144,8 @@ without a word.
144
144
  The toast carries no class of the space's, so this — not a `.Toastify__*` rule in `customCss` — is where it is
145
145
  dressed.
146
146
 
147
+ Copy link: `copyToClipboard('{{ navigation.href }}')`, then the toast — it fails with no clipboard.
148
+
147
149
  ## Modals, dropdowns, tabs
148
150
 
149
151
  - A modal or dialog is declared `visible: false` and driven with `openModal('credits')` / `closeModal('credits')`
@@ -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 |
@@ -124,6 +124,24 @@ pages: pageFamily(
124
124
 
125
125
  Every page is now its content and nothing else, and every page is guaranteed the same structure.
126
126
 
127
+ ## The page for an address nothing answers
128
+
129
+ ```ts
130
+ { id: 'not-found', name: 'Not found', slug: '*', layout: { id: 'site', slot: 'site-main' }, body: [ … ] }
131
+ ```
132
+
133
+ - **`slug: '*'`** is the page of every address no other page answers — a mistyped link, a page taken down — sent with
134
+ status 404, in the layout you give it, so the visitor is still on the site with a way back. Its own address answers
135
+ 404 too.
136
+ - **One per folder, if a section wants its own.** In a folder (`folder: 'docs'`) it answers that folder's unknown
137
+ addresses; the deepest folder's wins, the space's takes the rest. A page whose `flag` is off shows it too.
138
+ - **A space with none is given a plain one** — a title and a link home, in the home page's layout — and `author`
139
+ suggests writing your own (`not-found-page`): say it in the space's words.
140
+ - **A page that exists but finds nothing** — `/products/:slug` for a slug no product has — is sent with 404 too when
141
+ its server provider says so: `notFound: "{{ not (source.data.products|find('slug', navigation.routeParams.slug)) }}"`,
142
+ one expression against its answer, on a `runtime: 'server'` provider of the page (not of its layout, which every
143
+ page shares). The page renders as written: show its "not found" part with `visible`.
144
+
127
145
  ## Styles follow the same rule
128
146
 
129
147
  - A role used on several pages is ONE class (`panelCard`, `pageTitle`), declared in the module that owns the area and
@@ -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
@@ -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" sent with 404 | [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) |