@plitzi/sdk-authoring 0.38.14 → 0.38.15
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 +102 -0
- package/dist/index-src.js +459 -407
- package/dist/index.d.ts +162 -19
- package/dist/index.js +3 -3
- package/dist/node.d.ts +77 -1
- package/dist/node.js +206 -2
- package/dist/plugin.d.ts +2 -1
- package/package.json +6 -6
- package/skills/plitzi-authoring/SKILL.md +1 -1
- package/skills/plitzi-authoring/reference/index.md +3 -2
- package/skills/plitzi-authoring/reference/plugin-reach.md +91 -0
- package/skills/plitzi-authoring/reference/plugins.md +15 -31
- package/skills/plitzi-authoring/reference/realtime.md +11 -0
- package/skills/plitzi-authoring/reference/testing.md +3 -1
package/dist/node.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ei as e, gn as e$1, l as validateSpace, n as authorSpace, p as compactSvg, yn as buildHandles } from "./index-src.js";
|
|
2
2
|
import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
3
3
|
import m from "node:path";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
5
6
|
var r = `plitzi/author.ts`;
|
|
6
7
|
var i$1 = "src/space";
|
|
7
8
|
var a$1 = `${i$1}/index.ts`;
|
|
@@ -473,6 +474,209 @@ var l = (n, r, i) => {
|
|
|
473
474
|
return m.join(n, o ? m.join(v$1, m.relative("src", r)).replace(/\.tsx?$/, ".js") : r);
|
|
474
475
|
};
|
|
475
476
|
//#endregion
|
|
477
|
+
//#region src/isolated.ts
|
|
478
|
+
/** The `node_modules` nearest the module that has `@plitzi/sdk-authoring` in it: where its imports resolve. */
|
|
479
|
+
var modulesOf = (dir) => {
|
|
480
|
+
for (let at = dir;; at = m.dirname(at)) {
|
|
481
|
+
if (existsSync(m.join(at, "node_modules", "@plitzi", "sdk-authoring"))) return m.join(at, "node_modules");
|
|
482
|
+
if (m.dirname(at) === at) return;
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
/**
|
|
486
|
+
* What the process may read: the module's folder, the packages it imports, and — where a package is linked in from
|
|
487
|
+
* elsewhere (a workspace) — the folder it really is in, which is the path Node reads it by.
|
|
488
|
+
*/
|
|
489
|
+
var readable = (dir, modules) => {
|
|
490
|
+
const linked = readdirSync(m.join(modules, "@plitzi")).map((name) => realpathSync(m.join(modules, "@plitzi", name)));
|
|
491
|
+
return [.../* @__PURE__ */ new Set([
|
|
492
|
+
dir,
|
|
493
|
+
modules,
|
|
494
|
+
realpathSync(modules),
|
|
495
|
+
...linked
|
|
496
|
+
])];
|
|
497
|
+
};
|
|
498
|
+
/**
|
|
499
|
+
* The module's process: imports it, authors its `space` with the copy of `@plitzi/sdk-authoring` the module itself
|
|
500
|
+
* imports — one copy, so the marks a factory leaves on what it makes are read by the code that made them — and sends
|
|
501
|
+
* back what it answered.
|
|
502
|
+
*/
|
|
503
|
+
var runner = (file) => `
|
|
504
|
+
const FILE = ${JSON.stringify(pathToFileURL(file).href)};
|
|
505
|
+
const NAME = ${JSON.stringify(m.basename(file))};
|
|
506
|
+
const send = message => new Promise(resolve => process.send(message, () => resolve()));
|
|
507
|
+
const firstLine = error => String(error instanceof Error ? error.message : error).split('\\n')[0];
|
|
508
|
+
const located = error => {
|
|
509
|
+
const frame = String(error instanceof Error ? error.stack ?? '' : '')
|
|
510
|
+
.split('\\n')
|
|
511
|
+
.map(line => /(file:\\/\\/[^\\s:()]+):(\\d+)/.exec(line))
|
|
512
|
+
.find(match => match && match[1] === FILE);
|
|
513
|
+
|
|
514
|
+
return frame ? NAME + ':' + frame[2] + ': ' + firstLine(error) : NAME + ': ' + firstLine(error);
|
|
515
|
+
};
|
|
516
|
+
try {
|
|
517
|
+
const { authorSpace } = await import('@plitzi/sdk-authoring');
|
|
518
|
+
let loaded;
|
|
519
|
+
try {
|
|
520
|
+
loaded = await import(FILE);
|
|
521
|
+
} catch (error) {
|
|
522
|
+
if (error instanceof Error && (error.name === 'AuthoringError' || error.name === 'SpaceRefusedError')) {
|
|
523
|
+
throw error;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
await send({ ok: false, reason: 'failed', message: located(error) });
|
|
527
|
+
process.exit(0);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const space = loaded && loaded.space;
|
|
531
|
+
if (!space || typeof space !== 'object') {
|
|
532
|
+
await send({
|
|
533
|
+
ok: false,
|
|
534
|
+
reason: 'failed',
|
|
535
|
+
message: NAME + ' exports no \`space\`: \`export const space: SpaceSpec = { name, permanentUrl, pages, … }\`'
|
|
536
|
+
});
|
|
537
|
+
process.exit(0);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const { schema, style, handles, warnings, suggestions } = authorSpace(space);
|
|
541
|
+
await send({ ok: true, space: { schema, style, handles, warnings, suggestions } });
|
|
542
|
+
} catch (error) {
|
|
543
|
+
await send(
|
|
544
|
+
error instanceof Error && error.name === 'SpaceRefusedError'
|
|
545
|
+
? { ok: false, reason: 'refused', message: error.message, refusals: error.refusals }
|
|
546
|
+
: { ok: false, reason: 'failed', message: located(error) }
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
process.exit(0);
|
|
550
|
+
`;
|
|
551
|
+
/** What the process answered, read for its shape and the space checked again: nothing it says is taken on trust. */
|
|
552
|
+
var readAnswer = (answer) => {
|
|
553
|
+
if (!e(answer) || typeof answer.ok !== "boolean") return;
|
|
554
|
+
if (!answer.ok) {
|
|
555
|
+
const message = typeof answer.message === "string" ? answer.message : "The module was not authored";
|
|
556
|
+
return answer.reason === "refused" && Array.isArray(answer.refusals) ? {
|
|
557
|
+
ok: false,
|
|
558
|
+
reason: "refused",
|
|
559
|
+
message,
|
|
560
|
+
refusals: answer.refusals.filter(isRefusal)
|
|
561
|
+
} : {
|
|
562
|
+
ok: false,
|
|
563
|
+
reason: "failed",
|
|
564
|
+
message
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
const space = answer.space;
|
|
568
|
+
if (!isWireAuthored(space)) return {
|
|
569
|
+
ok: false,
|
|
570
|
+
reason: "invalid",
|
|
571
|
+
message: "The module answered something that is not a space"
|
|
572
|
+
};
|
|
573
|
+
let checked;
|
|
574
|
+
try {
|
|
575
|
+
checked = validateSpace({
|
|
576
|
+
schema: space.schema,
|
|
577
|
+
style: space.style
|
|
578
|
+
});
|
|
579
|
+
} catch (error) {
|
|
580
|
+
return {
|
|
581
|
+
ok: false,
|
|
582
|
+
reason: "invalid",
|
|
583
|
+
message: `The space the module answered is not one: ${error instanceof Error ? error.message : String(error)}`
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
if (!checked.valid) return {
|
|
587
|
+
ok: false,
|
|
588
|
+
reason: "invalid",
|
|
589
|
+
message: `The space the module answered does not validate: ${checked.errors.map((error) => error.message).join("; ")}`
|
|
590
|
+
};
|
|
591
|
+
return {
|
|
592
|
+
ok: true,
|
|
593
|
+
space: {
|
|
594
|
+
...space,
|
|
595
|
+
handles: buildHandles(space.handles.pages, space.handles.layouts)
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
};
|
|
599
|
+
var isRefusal = (value) => e(value) && typeof value.message === "string" && typeof value.place === "string";
|
|
600
|
+
/**
|
|
601
|
+
* The shape of that answer. The documents are what `validateSpace` checks; the rest is what the author said about them,
|
|
602
|
+
* read by whoever asked.
|
|
603
|
+
*/
|
|
604
|
+
var isWireAuthored = (value) => e(value) && e(value.schema) && e(value.style) && e(value.handles) && e(value.handles.pages) && e(value.handles.layouts) && Array.isArray(value.warnings) && Array.isArray(value.suggestions);
|
|
605
|
+
var authorIsolated = (file, options = {}) => {
|
|
606
|
+
const { timeoutMs = 1e4, memoryMb = 512 } = options;
|
|
607
|
+
const module = m.resolve(file);
|
|
608
|
+
if (!existsSync(module)) return Promise.resolve({
|
|
609
|
+
ok: false,
|
|
610
|
+
reason: "failed",
|
|
611
|
+
message: `${file} does not exist`
|
|
612
|
+
});
|
|
613
|
+
const dir = m.dirname(module);
|
|
614
|
+
const modules = modulesOf(dir);
|
|
615
|
+
if (!modules) return Promise.resolve({
|
|
616
|
+
ok: false,
|
|
617
|
+
reason: "failed",
|
|
618
|
+
message: `No @plitzi/sdk-authoring is installed where ${file} is: put the module inside the project that installs it`
|
|
619
|
+
});
|
|
620
|
+
const reads = readable(realpathSync(dir), modules);
|
|
621
|
+
return new Promise((resolve) => {
|
|
622
|
+
const child = spawn(process.execPath, [
|
|
623
|
+
"--permission",
|
|
624
|
+
...reads.map((read) => `--allow-fs-read=${read}`),
|
|
625
|
+
`--max-old-space-size=${String(memoryMb)}`,
|
|
626
|
+
"--input-type=module",
|
|
627
|
+
"-e",
|
|
628
|
+
runner(realpathSync(module))
|
|
629
|
+
], {
|
|
630
|
+
cwd: dir,
|
|
631
|
+
env: {},
|
|
632
|
+
stdio: [
|
|
633
|
+
"ignore",
|
|
634
|
+
"ignore",
|
|
635
|
+
"pipe",
|
|
636
|
+
"ipc"
|
|
637
|
+
]
|
|
638
|
+
});
|
|
639
|
+
let answer;
|
|
640
|
+
let stderr = "";
|
|
641
|
+
let timedOut = false;
|
|
642
|
+
const timer = setTimeout(() => {
|
|
643
|
+
timedOut = true;
|
|
644
|
+
child.kill("SIGKILL");
|
|
645
|
+
}, timeoutMs);
|
|
646
|
+
child.on("message", (message) => {
|
|
647
|
+
answer = message;
|
|
648
|
+
});
|
|
649
|
+
child.stderr?.setEncoding("utf8");
|
|
650
|
+
child.stderr?.on("data", (chunk) => {
|
|
651
|
+
stderr = (stderr + chunk).slice(-2e3);
|
|
652
|
+
});
|
|
653
|
+
child.on("error", (error) => {
|
|
654
|
+
clearTimeout(timer);
|
|
655
|
+
resolve({
|
|
656
|
+
ok: false,
|
|
657
|
+
reason: "failed",
|
|
658
|
+
message: `The module's process did not start: ${error.message}`
|
|
659
|
+
});
|
|
660
|
+
});
|
|
661
|
+
child.on("close", (code) => {
|
|
662
|
+
clearTimeout(timer);
|
|
663
|
+
if (timedOut) {
|
|
664
|
+
resolve({
|
|
665
|
+
ok: false,
|
|
666
|
+
reason: "timeout",
|
|
667
|
+
message: `${file} took longer than ${String(timeoutMs)} ms to author`
|
|
668
|
+
});
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
resolve(readAnswer(answer) ?? {
|
|
672
|
+
ok: false,
|
|
673
|
+
reason: "failed",
|
|
674
|
+
message: `The module's process ended (${String(code)}) without an answer${stderr.trim() ? `: ${stderr.trim()}` : ""}`
|
|
675
|
+
});
|
|
676
|
+
});
|
|
677
|
+
});
|
|
678
|
+
};
|
|
679
|
+
//#endregion
|
|
476
680
|
//#region src/node.ts
|
|
477
681
|
/**
|
|
478
682
|
* What only an author running on Node can do: read the project's own files. A separate entry, so the package's main
|
|
@@ -699,4 +903,4 @@ var authorProjectSpace = async () => {
|
|
|
699
903
|
return authorSpace(space, authoring);
|
|
700
904
|
};
|
|
701
905
|
//#endregion
|
|
702
|
-
export { ProjectModuleError, ProjectSpaceError, authorProjectSpace, compactSvg, moduleProblem, pluginDeclarations, pluginFolders, projectAuthoring, projectAuthoringAt, projectData, projectSpace, projectSpaceAt, publicData, svgFile, svgFiles };
|
|
906
|
+
export { ProjectModuleError, ProjectSpaceError, authorIsolated, authorProjectSpace, compactSvg, moduleProblem, pluginDeclarations, pluginFolders, projectAuthoring, projectAuthoringAt, projectData, projectSpace, projectSpaceAt, publicData, svgFile, svgFiles };
|
package/dist/plugin.d.ts
CHANGED
|
@@ -153,7 +153,8 @@ export declare interface ElementDeclarationData {
|
|
|
153
153
|
/**
|
|
154
154
|
* Whether the element shows only some of the children put inside it, chosen as it runs — a dashboard showing the
|
|
155
155
|
* panels of the layout saved for this device, a wizard its current step. Read by the page checks, which then owe none
|
|
156
|
-
* of them on screen;
|
|
156
|
+
* of them on screen; the ones it draws are checked like the rest of the page — there, visible, and what is named
|
|
157
|
+
* inside them too.
|
|
157
158
|
*/
|
|
158
159
|
choosesChildren?: boolean;
|
|
159
160
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plitzi/sdk-authoring",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.15",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/index.js",
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@microsoft/api-extractor": "^7.59.3",
|
|
63
63
|
"@plitzi/plitzi-ui": "^1.6.33",
|
|
64
|
-
"@plitzi/sdk-elements": "0.38.
|
|
65
|
-
"@plitzi/sdk-interactions": "0.38.
|
|
66
|
-
"@plitzi/sdk-schema": "0.38.
|
|
67
|
-
"@plitzi/sdk-shared": "0.38.
|
|
68
|
-
"@plitzi/sdk-style": "0.38.
|
|
64
|
+
"@plitzi/sdk-elements": "0.38.15",
|
|
65
|
+
"@plitzi/sdk-interactions": "0.38.15",
|
|
66
|
+
"@plitzi/sdk-schema": "0.38.15",
|
|
67
|
+
"@plitzi/sdk-shared": "0.38.15",
|
|
68
|
+
"@plitzi/sdk-style": "0.38.15",
|
|
69
69
|
"@types/react": "^19.3.0",
|
|
70
70
|
"eslint": "^9.39.5",
|
|
71
71
|
"prettier": "^3.9.9",
|
|
@@ -36,7 +36,7 @@ A space on Plitzi — edited in the builder — is edited through the Plitzi MCP
|
|
|
36
36
|
when the text is not enough.
|
|
37
37
|
4. **Before saying done:** `npm run lint:space` clean, and the [review checklist](reference/review-checklist.md).
|
|
38
38
|
|
|
39
|
-
What a name means — an element, a step, a trigger, a code, any export (`pageFamily`, `
|
|
39
|
+
What a name means — an element, a step, a trigger, a code, any `@plitzi` export (`pageFamily`, `createServer`): `npx plitzi explain
|
|
40
40
|
<name>`, in a few lines. Never read the `.d.ts`.
|
|
41
41
|
|
|
42
42
|
## Five rules authoring cannot check for you
|
|
@@ -22,8 +22,9 @@ Read one only when the task names its subject.
|
|
|
22
22
|
| [authoring-errors.md](authoring-errors.md) | What `authorSpace` refuses or warns about, and what to write instead |
|
|
23
23
|
| [templates.md](templates.md) | Any `{{ … }}` or `{% … %}`: where it runs, naming sources, filters, tests, dates |
|
|
24
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,
|
|
25
|
+
| [realtime.md](realtime.md) | Pages that see each other: channels, presence, cursors, a shared board, state every screen shares, who may hear a topic |
|
|
26
|
+
| [plugins.md](plugins.md) | A component of your own: props, binding them, writing state, registering, behaving in the builder |
|
|
27
|
+
| [plugin-reach.md](plugin-reach.md) | What a plugin says and to whom: a notification, another element, a server action, shared state, other pages |
|
|
27
28
|
| [drawing.md](drawing.md) | A plugin that draws or animates: a canvas sized to the device, WebGL, a loop that stops when unseen |
|
|
28
29
|
| [structure.md](structure.md) | A space bigger than one screen: files, helpers, naming, keeping it short |
|
|
29
30
|
| [testing.md](testing.md) | Any test: `inspectPage`, handles, fixtures, catching a flash from the first frame, shortcuts, counting renders |
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# What a plugin says, and to whom
|
|
2
|
+
|
|
3
|
+
A plugin reaches the person, the space's other elements, the server and the other screens each one way. All of it is
|
|
4
|
+
imported from `@plitzi/plitzi-sdk` — the page's copy, which every plugin shares — never from `window` events or a
|
|
5
|
+
module of the project's (each plugin is a bundle of its own: a module two of them import is two).
|
|
6
|
+
|
|
7
|
+
## To the person: `useNotify`
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { useNotify } from '@plitzi/plitzi-sdk';
|
|
11
|
+
|
|
12
|
+
const notify = useNotify();
|
|
13
|
+
notify('Deleted 79 recordings'); // what an `addNotification` step shows
|
|
14
|
+
notify('Training failed', { appearance: 'danger', autoDismiss: false });
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The page's own toasts, in the space's theme and with the look its `notifications` give them. For what only the plugin
|
|
18
|
+
knows; what the PAGE decides to say stays a flow (`on(…)` → `addNotification`).
|
|
19
|
+
|
|
20
|
+
## To another element: an event, and the space's flow
|
|
21
|
+
|
|
22
|
+
A plugin never calls another one. It fires what happened, and the space's flow decides who acts — visible in the
|
|
23
|
+
space, and the same flow a button can start:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
// the assistant's declaration: triggers: { onOpenResult: { action: 'onOpenResult', preview: { index: 0 } } }
|
|
27
|
+
assistant({ id: 'jarvis', flows: [[
|
|
28
|
+
named('asked', declaredTrigger(assistantDeclaration, 'onOpenResult')),
|
|
29
|
+
declaredCallback(browserDeclaration, 'openResult', { on: 'browser', params: { index: '{{ asked.index }}' } })
|
|
30
|
+
]] })
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The receiver declares the action (`callbacks`) and registers it from its declaration; a name either side does not
|
|
34
|
+
declare is refused when the space is authored.
|
|
35
|
+
|
|
36
|
+
## To the server: `useServerAction`
|
|
37
|
+
|
|
38
|
+
One operation is one server action — `taskAction(tasks.done, …)` or `defineAction(…)` — whose input the server checks
|
|
39
|
+
before any code runs, never a `case` in one route. A plugin runs it awaited, typed by the action:
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
import { useServerAction } from '@plitzi/plitzi-sdk';
|
|
43
|
+
import type { habitDone } from '../../space/actions';
|
|
44
|
+
|
|
45
|
+
const done = useServerAction<typeof habitDone>('habits-done');
|
|
46
|
+
const result = await done({ id }); // the input its `call` way in declares
|
|
47
|
+
if (result.ok) { show(result.output.streak); } else { say(result.error ?? result.reason); }
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The same run a flow's `runServerAction` makes: its `access`, its refusals, its entry in the dev tools; a completed run
|
|
51
|
+
refreshes the page's cached requests (`{ invalidateQueries: 'none' }` for one that only reads).
|
|
52
|
+
|
|
53
|
+
## State every screen shares: a channel that retains
|
|
54
|
+
|
|
55
|
+
What the server keeps and every page shows — a dashboard's lists, a board's settings — is a channel declared
|
|
56
|
+
`retain: true` (with `publish: 'server'`): the server keeps the latest message of each type and hands them to every
|
|
57
|
+
page that joins.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
channels: { desk: { access: { mode: 'session' }, publish: 'server', retain: true } }
|
|
61
|
+
|
|
62
|
+
// the server, in a task, a route or a flow's `realtime.publish`: kept, and said to every page on it
|
|
63
|
+
await ctx.publish('desk', 'lists', lists);
|
|
64
|
+
await ctx.publish('desk', 'lists', null); // forgotten
|
|
65
|
+
|
|
66
|
+
channel({ id: 'desk', topic: 'desk', children: [lists({ id: 'lists', bind: { lists: 'desk.retained.lists' } })] })
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`useChannel('desk').retained.lists` is the same value in a plugin, re-rendering when it changes; what the page is
|
|
70
|
+
handed on joining reaches `onMessage` too, as if just said. A page changes it by
|
|
71
|
+
asking the server (an action), which keeps it and says it. A topic keeps at most 64 types and 512 KB.
|
|
72
|
+
|
|
73
|
+
## To other pages, at the speed of a cursor: `useChannel`
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
const room = useChannel(roomTopic, { onMessage: message => move(message.from, message.data) });
|
|
77
|
+
room.publish('pointer', { x, y }); // throttle it: ~20 a second, the latest position each time
|
|
78
|
+
room.publish('react', { emoji }, { echo: true }); // and heard here too
|
|
79
|
+
room.members; // who is here, with the state each announced
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Messages arrive through the callback and re-render nothing. Take the topic as a prop
|
|
83
|
+
(`bindTemplate('roomTopic', 'board.id', 'room:{{ source }}')`) so the space names its channels, and trust a message
|
|
84
|
+
you act on only when `message.from === 'server'`. The page has one connection and is one member per topic, however
|
|
85
|
+
many elements and plugins listen.
|
|
86
|
+
|
|
87
|
+
## Its own server code
|
|
88
|
+
|
|
89
|
+
`plitzi plugin add board --server` writes `functions/index.ts` in its folder. Its routes answer under
|
|
90
|
+
`/fn/plugins/board/`, named with `usePluginRoute('board')('/layout')` (`undefined` where no server runs code, as on the
|
|
91
|
+
canvas). Its `ctx.kv` is the plugin's own; the space's credentials, channels and data are not.
|
|
@@ -55,8 +55,14 @@ const NebulaRun = ({ shipColor = 'amber', best = 0, className }: NebulaRunProps)
|
|
|
55
55
|
|
|
56
56
|
- **Render `RootElement`**, not a `div`: it carries the element's id, classes and `data-plitzi-el`, so the CSS
|
|
57
57
|
authored on the element applies, the builder can select it and a test can find it.
|
|
58
|
-
- **Render the same thing on the server and on the first client pass
|
|
59
|
-
`window` belongs in an effect; a hydration mismatch discards the whole
|
|
58
|
+
- **Render the same thing on the server and on the first client pass** — a plugin is drawn on the server first. A
|
|
59
|
+
clock, a random number or anything read from `window` belongs in an effect; a hydration mismatch discards the whole
|
|
60
|
+
tree, not the plugin. A preference per device (a tab, muted) is never read from `localStorage` while rendering: write
|
|
61
|
+
it to `runtime.state` with `keepState` — and `paintedState` when it changes the first paint ([kept state](kept-state.md))
|
|
62
|
+
— and take it as a bound prop.
|
|
63
|
+
- **`@plitzi/plitzi-ui` is not the page's.** The build keeps out only React and the SDK: a plugin importing it carries
|
|
64
|
+
its own copy, whose contexts (its toasts) are not the page's and whose look is not the space's. Draw controls with the
|
|
65
|
+
space's tokens; tabs over the space's elements are a plugin that lays them out (below).
|
|
60
66
|
- **Borrow colours.** `currentColor` and the space's `var(--…)` tokens follow the theme; a hard-coded colour is
|
|
61
67
|
invisible in one of them. A canvas reads them with `getComputedStyle(element).getPropertyValue('--accent')` and
|
|
62
68
|
again when `theme.resolved` changes (bind it as a prop).
|
|
@@ -90,39 +96,17 @@ import { elementChildren } from '@plitzi/plitzi-sdk';
|
|
|
90
96
|
{elementChildren(children).map(({ id, node }) => <section key={id} style={placed[id]}>{node}</section>)}
|
|
91
97
|
```
|
|
92
98
|
|
|
93
|
-
|
|
99
|
+
One that shows only some of them — a dashboard's panels, a wizard's step — says `choosesChildren: true` in its
|
|
100
|
+
declaration: the page checks then owe none at rest, and check the ones it draws. Never write `style` onto an element
|
|
101
|
+
the plugin does not render: nothing promises to keep it. Its boxes share one
|
|
94
102
|
stacking context, the plugin's. `useDisplayMode()` names the breakpoint showing (`desktop`, `tablet`, `mobile`) at the
|
|
95
103
|
space's widths; `useElementSize(ref)`, its own box (`undefined` until measured).
|
|
96
104
|
|
|
97
|
-
##
|
|
105
|
+
## What it says, and to whom
|
|
98
106
|
|
|
99
|
-
`
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
```tsx
|
|
103
|
-
const route = usePluginRoute('board'); // from '@plitzi/plitzi-sdk'
|
|
104
|
-
const url = route('/layout'); // undefined where no server runs code (the canvas)
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
Its `ctx.kv` is the plugin's own; the space's credentials, channels and data are not.
|
|
108
|
-
|
|
109
|
-
## Talking to other pages
|
|
110
|
-
|
|
111
|
-
A plugin that moves at the speed of a cursor reads a realtime channel through `useChannel` rather than through flows —
|
|
112
|
-
messages arrive through a callback and re-render nothing:
|
|
113
|
-
|
|
114
|
-
```tsx
|
|
115
|
-
import { useChannel } from '@plitzi/plitzi-sdk';
|
|
116
|
-
|
|
117
|
-
const room = useChannel(roomTopic, { onMessage: message => move(message.from, message.data) });
|
|
118
|
-
room.publish('pointer', { x, y }); // throttle it: ~20 a second, the latest position each time
|
|
119
|
-
room.publish('react', { emoji }, { echo: true }); // and heard here too
|
|
120
|
-
room.members; // who is here, with the state each announced
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
Take the topic as a prop (`bindTemplate('roomTopic', 'board.id', 'room:{{ source }}')`) so the space names its
|
|
124
|
-
channels, and trust a message you act on only when `message.from === 'server'`. The page has one connection and is one
|
|
125
|
-
member per topic, however many elements and plugins listen.
|
|
107
|
+
The person (`useNotify`), another element (an event and the space's flow — never a `window` event), the server
|
|
108
|
+
(`useServerAction`, typed by the action), state every screen shares (a channel that retains), other pages
|
|
109
|
+
(`useChannel`) and its own server code: [plugin-reach](plugin-reach.md).
|
|
126
110
|
|
|
127
111
|
## Feature flags
|
|
128
112
|
|
|
@@ -33,6 +33,17 @@ channels: { 'order:{id}': { access: { mode: 'session' }, grant: true } }
|
|
|
33
33
|
channel({ id: 'order', topic: 'order:{{ id }}', bind: { grant: 'state.follow.grant' }, children: [...] })
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
State every screen shows and the server keeps — a dashboard's lists, a board's settings — goes on a channel declared
|
|
37
|
+
`retain: true` (and `publish: 'server'`): the server keeps the latest message of each type, sends it as it is said and
|
|
38
|
+
again to every page that joins — and to its `onMessage` flows, as if just said — which reads it as
|
|
39
|
+
`desk.retained.lists` (a plugin, `useChannel('desk').retained`).
|
|
40
|
+
Publishing `null` forgets the type; a topic keeps at most 64 types and 512 KB. No read of its own, no copy in `state`:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
channels: { desk: { access: { mode: 'session' }, publish: 'server', retain: true } }
|
|
44
|
+
// a flow: { task: 'realtime.publish', params: { topic: 'desk', type: 'lists', data: '{{ saved.lists }}' } }
|
|
45
|
+
```
|
|
46
|
+
|
|
36
47
|
Two people writing the same thing at once: `kv.setIf` writes only if the value is still the one the flow read (empty
|
|
37
48
|
`expected` = only if nothing is there yet — claim a seat, a username), `list.put`/`list.range` keep an ordered list
|
|
38
49
|
(latest first, a leaderboard), and `flow.rateLimit` first in a public action that writes.
|
|
@@ -44,7 +44,9 @@ the list `inspectPage` holds a page to.
|
|
|
44
44
|
Three flags say what a bare visit cannot promise, and `onScreen` leaves out:
|
|
45
45
|
|
|
46
46
|
- `conditional` — on screen only under a condition of its own or of an ancestor, or with every child conditional (a
|
|
47
|
-
list of flyouts at rest)
|
|
47
|
+
list of flyouts at rest). Under a plugin that chooses its children (`choosesChildren`), each child — and what is
|
|
48
|
+
inside it under no condition of its own — also carries `shownWith`, the child it comes with: once that child is
|
|
49
|
+
drawn it is owed like the rest (`onScreenIfChosen` lists them, and `inspectPage` checks them);
|
|
48
50
|
- `repeated` — inside a list row, so rendered once per row: several copies, or none while the list is empty. Address
|
|
49
51
|
one with `.first()` / `.nth(i)`, in a test that knows the data;
|
|
50
52
|
- `boxless` — a provider with no tag, which renders its children and no element of its own; or a plugin whose
|