caspian-utils 0.0.4 → 0.0.5
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/dist/docs/pulsepoint.md +125 -44
- package/package.json +1 -1
package/dist/docs/pulsepoint.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: PulsePoint Runtime Guide
|
|
3
|
-
description: Learn how AI agents should
|
|
3
|
+
description: Learn how AI agents should author PulsePoint against the shipped browser runtime in `public/js/pp-reactive-v2.js` and the Caspian render pipeline that injects runtime attributes automatically.
|
|
4
4
|
related:
|
|
5
5
|
title: Related docs
|
|
6
6
|
description: Read the components, routing, data-fetching, and project-structure docs alongside the PulsePoint runtime contract.
|
|
@@ -14,16 +14,31 @@ related:
|
|
|
14
14
|
|
|
15
15
|
## Purpose
|
|
16
16
|
|
|
17
|
-
This file documents the PulsePoint
|
|
17
|
+
This file documents the current PulsePoint contract for this workspace. Treat it as the AI-facing source of truth when generating or reviewing interactive Caspian UI.
|
|
18
18
|
|
|
19
19
|
If a task involves `pp.state`, `pp.effect`, `pp.layoutEffect`, `pp-ref`, `pp-spread`, `pp-for`, context, portals, SPA navigation, or component boundary behavior, read this page first and keep generated code aligned with the runtime implemented in this repo.
|
|
20
20
|
|
|
21
|
-
Use `components.md` for authoring Python `@component` files and same-name HTML templates. Use this page for the browser-side
|
|
21
|
+
Use `components.md` for authoring Python `@component` files and same-name HTML templates. Use this page for the browser-side PulsePoint contract, the authoring rules that feed it, and the React-style mental model used by the current runtime.
|
|
22
22
|
|
|
23
|
-
PulsePoint is the default reactive frontend layer for Caspian.
|
|
23
|
+
PulsePoint is the default reactive frontend layer for Caspian. In this workspace it follows a React-like component pattern, but it is HTML-first rather than JSX-first.
|
|
24
24
|
|
|
25
25
|
Do not assume React, Vue, Svelte, JSX, Alpine, HTMX, or older PulsePoint docs unless the task explicitly asks for a different frontend contract.
|
|
26
26
|
|
|
27
|
+
## Source Of Truth
|
|
28
|
+
|
|
29
|
+
For the current workspace, follow this order when documenting or generating PulsePoint code:
|
|
30
|
+
|
|
31
|
+
- `public/js/pp-reactive-v2.js` is the shipped browser runtime contract AI should follow.
|
|
32
|
+
- `main.py` is the render-pipeline source of truth for how Caspian injects runtime attributes and rewrites scripts before the browser sees the HTML.
|
|
33
|
+
- If you are working inside PulsePoint or Caspian runtime development code and there is an authoring source tree behind the shipped files, use it only as an implementation detail. Do not assume that source tree exists in generated apps or shipped framework output.
|
|
34
|
+
|
|
35
|
+
Important current facts:
|
|
36
|
+
|
|
37
|
+
- `public/js/pp-reactive-v2.js` exposes the global `pp` runtime and auto-mounts on DOM ready.
|
|
38
|
+
- `main.py` renders the final HTML, runs `transform_components(...)`, then runs `transform_scripts(...)` before returning the response.
|
|
39
|
+
|
|
40
|
+
If docs, generated examples, or older notes disagree with `public/js/pp-reactive-v2.js` plus `main.py`, follow the code that actually runs.
|
|
41
|
+
|
|
27
42
|
## Default Frontend Rule
|
|
28
43
|
|
|
29
44
|
When a Caspian page needs reactive browser behavior, use PulsePoint.
|
|
@@ -32,14 +47,46 @@ When a Caspian page needs reactive browser behavior, use PulsePoint.
|
|
|
32
47
|
- Keep server-rendered HTML plus PulsePoint enhancement as the baseline architecture.
|
|
33
48
|
- Only introduce another frontend runtime when the user explicitly asks for it or the project already depends on one.
|
|
34
49
|
|
|
35
|
-
##
|
|
50
|
+
## Authoring Model
|
|
51
|
+
|
|
52
|
+
PulsePoint authoring in this repo is split into two layers:
|
|
53
|
+
|
|
54
|
+
- The authored layer: route, layout, and component templates under `src/` with plain HTML plus a plain `<script>`.
|
|
55
|
+
- The runtime layer: the browser sees `pp-component` roots and `script[type="text/pp"]` after Caspian transforms the HTML.
|
|
56
|
+
|
|
57
|
+
For authored Caspian templates:
|
|
58
|
+
|
|
59
|
+
- Keep exactly one top-level lowercase HTML root element.
|
|
60
|
+
- Put the component logic inside a plain `<script>` inside that same root.
|
|
61
|
+
- Do not handwrite `pp-component="..."`.
|
|
62
|
+
- Do not handwrite `type="text/pp"`.
|
|
63
|
+
|
|
64
|
+
Caspian already handles those details for you during render.
|
|
65
|
+
|
|
66
|
+
That means AI-generated examples should default to authored template source, not raw runtime HTML.
|
|
67
|
+
|
|
68
|
+
Authored example:
|
|
36
69
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
70
|
+
```html
|
|
71
|
+
<section>
|
|
72
|
+
<h2>{title}</h2>
|
|
73
|
+
<p>Count: {count}</p>
|
|
74
|
+
|
|
75
|
+
<button onclick="setCount(count + 1)">Increment</button>
|
|
76
|
+
<button onclick="reset()">Reset</button>
|
|
77
|
+
|
|
78
|
+
<script>
|
|
79
|
+
const { title = "Counter" } = pp.props;
|
|
80
|
+
const [count, setCount] = pp.state(0);
|
|
81
|
+
|
|
82
|
+
function reset() {
|
|
83
|
+
setCount(0);
|
|
84
|
+
}
|
|
85
|
+
</script>
|
|
86
|
+
</section>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
When that template reaches the browser, Caspian will already have injected the component id and rewritten the owned script to `type="text/pp"`. Those runtime attributes are for the rendered output, not for authored source examples.
|
|
43
90
|
|
|
44
91
|
## Runtime shape
|
|
45
92
|
|
|
@@ -57,17 +104,16 @@ Important:
|
|
|
57
104
|
|
|
58
105
|
## Component roots and scripts
|
|
59
106
|
|
|
60
|
-
- Each runtime component root should have at most one
|
|
61
|
-
-
|
|
107
|
+
- Each runtime component root should have at most one owned script.
|
|
108
|
+
- At runtime, the owned script is `script[type="text/pp"]`.
|
|
62
109
|
- The script lookup walks the current root and skips nested `pp-component` boundaries, so a parent does not consume a child component's script.
|
|
63
|
-
- If multiple matching scripts exist in the same root, the first matching owned script wins. Generate one script per root.
|
|
64
|
-
- Authored
|
|
65
|
-
- In authored Caspian templates, write plain `<script>` inside the single root and let the render pipeline rewrite it before mount.
|
|
110
|
+
- If multiple matching runtime scripts exist in the same root, the first matching owned script wins. Generate one script per root.
|
|
111
|
+
- Authored route, layout, and component templates still need one top-level lowercase HTML root so Caspian can inject the component boundary correctly.
|
|
66
112
|
- A scriptless component root still mounts and can receive props, refs, events, and nested children, but it has no local runtime scope beyond its props.
|
|
67
113
|
- Component scripts are plain JavaScript executed with `new Function(...)`. Do not use `import`, `export`, or top-level `await` inside them.
|
|
68
114
|
- The runtime auto-returns supported top-level bindings from the script. Do not rely on manual `return { ... }` objects.
|
|
69
115
|
- `pp.props` contains the current prop bag for the component.
|
|
70
|
-
- `pp.props.children` contains the root's initial inner HTML before the
|
|
116
|
+
- `pp.props.children` contains the root's initial inner HTML before the owned script is removed from the render template.
|
|
71
117
|
|
|
72
118
|
Bindings exported to the template:
|
|
73
119
|
|
|
@@ -85,12 +131,12 @@ Bindings that should not be assumed:
|
|
|
85
131
|
Example:
|
|
86
132
|
|
|
87
133
|
```html
|
|
88
|
-
<div
|
|
134
|
+
<div>
|
|
89
135
|
<h2>{title}</h2>
|
|
90
136
|
<p>Count: {count}</p>
|
|
91
137
|
<button onclick="setCount(count + 1)">Increment</button>
|
|
92
138
|
|
|
93
|
-
<script
|
|
139
|
+
<script>
|
|
94
140
|
const { title } = pp.props;
|
|
95
141
|
const [count, setCount] = pp.state(0);
|
|
96
142
|
|
|
@@ -101,10 +147,12 @@ Example:
|
|
|
101
147
|
</div>
|
|
102
148
|
```
|
|
103
149
|
|
|
104
|
-
That
|
|
150
|
+
That is the authored form. In browser-inspected runtime HTML, Caspian will already have added the component id and the owned script type.
|
|
105
151
|
|
|
106
152
|
## Hooks and runtime API
|
|
107
153
|
|
|
154
|
+
PulsePoint uses a React-style mental model inside each component script: stateful render scope, dependency-based effects, refs, reducer-style updates, context consumption, and portals.
|
|
155
|
+
|
|
108
156
|
Hooks exposed inside component scripts through `pp`:
|
|
109
157
|
|
|
110
158
|
- `pp.state(initial)` returns `[value, setValue]`.
|
|
@@ -115,11 +163,10 @@ Hooks exposed inside component scripts through `pp`:
|
|
|
115
163
|
- `pp.callback(callback, deps)` memoizes a function.
|
|
116
164
|
- `pp.reducer(reducer, initialState)` returns `[state, dispatch]`.
|
|
117
165
|
- `pp.context(token)` resolves a provided context value from ancestor components.
|
|
118
|
-
- `pp.provideContext(token, value)` provides a context value to descendant components.
|
|
119
166
|
- `pp.portal(ref, target?)` registers a ref-managed element for portal rendering and returns an object that includes `sourceParent`.
|
|
120
167
|
- `pp.props` exposes the current props.
|
|
121
168
|
|
|
122
|
-
Global helpers exposed
|
|
169
|
+
Global helpers exposed through the `pp` singleton and also merged into the component runtime:
|
|
123
170
|
|
|
124
171
|
- `pp.createContext(defaultValue)` creates a context token.
|
|
125
172
|
- `pp.mount()` bootstraps the runtime. It is idempotent.
|
|
@@ -132,21 +179,22 @@ Global helpers exposed on the `pp` singleton:
|
|
|
132
179
|
|
|
133
180
|
Notes:
|
|
134
181
|
|
|
135
|
-
- The global `pp` singleton auto-mounts once
|
|
182
|
+
- The global `pp` singleton auto-mounts once the runtime is loaded and the DOM is ready. Manual `pp.mount()` is still safe because it short-circuits after the first mount.
|
|
136
183
|
- `pp.state` setters accept either a value or an updater function.
|
|
137
184
|
- `pp.effect` and `pp.layoutEffect` are cleanup-style hooks. Returned promises are not awaited.
|
|
138
185
|
- `pp.portal(ref)` defaults to `document.body` when no target is provided.
|
|
139
186
|
- Older docs may call the RPC helper `pp.fetchFunction()`. In the current bundled runtime the implemented global API is `pp.rpc()`.
|
|
140
187
|
- Keep template-facing bindings at the top level so the AST-based exporter can see them.
|
|
188
|
+
- For predictable code generation, prefer passing an explicit dependency array to `pp.effect`, `pp.layoutEffect`, `pp.memo`, and `pp.callback`.
|
|
141
189
|
|
|
142
190
|
## Context
|
|
143
191
|
|
|
144
|
-
Context is implemented in the current runtime.
|
|
192
|
+
Context is implemented in the current runtime, but the current API follows a React-style `Context.Provider` pattern rather than a legacy `pp.provideContext(...)` helper.
|
|
145
193
|
|
|
146
194
|
How it works:
|
|
147
195
|
|
|
148
196
|
- Create a token with `pp.createContext(defaultValue)`.
|
|
149
|
-
- Provide a value
|
|
197
|
+
- Provide a value with `Context.Provider`.
|
|
150
198
|
- Read it in a descendant component with `pp.context(token)`.
|
|
151
199
|
- Resolution walks the logical component parent chain stored in the registry, not the live DOM.
|
|
152
200
|
- Portaled descendants still resolve providers through component ancestry.
|
|
@@ -159,30 +207,39 @@ Important:
|
|
|
159
207
|
- The same token object must be shared between provider and consumer.
|
|
160
208
|
- Context is component-level, not directive-based. There is no `pp-context` attribute.
|
|
161
209
|
- `pp.context(token)` resolves from ancestors. A component does not consume the value it provides in the same render.
|
|
162
|
-
- If provider and consumer live in different component script scopes, pass the token through props or store it in shared
|
|
210
|
+
- If provider and consumer live in different component script scopes, pass the token through props or store it in shared outer or global state.
|
|
211
|
+
- The preferred authoring style is a provider tag in the template. The runtime also supports imperative `ThemeContext.Provider({ value })` calls during render, but the tag form is clearer for AI-generated authored templates.
|
|
212
|
+
- Do not invent or document `pp.provideContext`. The current runtime explicitly does not expose it.
|
|
163
213
|
|
|
164
|
-
|
|
214
|
+
Provider example:
|
|
165
215
|
|
|
166
216
|
```html
|
|
167
|
-
<section
|
|
168
|
-
<div pp-component="theme-label-1" theme-token="{ThemeContext}">
|
|
169
|
-
<p>{theme}</p>
|
|
170
|
-
|
|
171
|
-
<script>
|
|
172
|
-
const { themeToken } = pp.props;
|
|
173
|
-
const theme = pp.context(themeToken);
|
|
174
|
-
</script>
|
|
175
|
-
</div>
|
|
176
|
-
|
|
217
|
+
<section>
|
|
177
218
|
<script>
|
|
178
219
|
const ThemeContext = pp.createContext("light");
|
|
179
220
|
const [theme] = pp.state("dark");
|
|
180
|
-
|
|
181
|
-
pp.provideContext(ThemeContext, theme);
|
|
182
221
|
</script>
|
|
222
|
+
|
|
223
|
+
<ThemeContext.Provider value="{theme}">
|
|
224
|
+
<p>This subtree receives the provided theme.</p>
|
|
225
|
+
</ThemeContext.Provider>
|
|
183
226
|
</section>
|
|
184
227
|
```
|
|
185
228
|
|
|
229
|
+
Consumer example for a child component that receives the token through props:
|
|
230
|
+
|
|
231
|
+
```html
|
|
232
|
+
<div>
|
|
233
|
+
<p>{theme}</p>
|
|
234
|
+
|
|
235
|
+
<script>
|
|
236
|
+
const theme = pp.context(pp.props.themeToken);
|
|
237
|
+
</script>
|
|
238
|
+
</div>
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
When a child component needs the same token object, pass it from the provider scope as a prop such as `theme-token="{ThemeContext}"`.
|
|
242
|
+
|
|
186
243
|
## Props and nested components
|
|
187
244
|
|
|
188
245
|
- Child component props are derived from DOM attributes.
|
|
@@ -217,7 +274,7 @@ Nested components:
|
|
|
217
274
|
Example:
|
|
218
275
|
|
|
219
276
|
```html
|
|
220
|
-
<div
|
|
277
|
+
<div>
|
|
221
278
|
<button pp-spread="{...buttonAttrs}" hidden="{isLoading}">Save</button>
|
|
222
279
|
|
|
223
280
|
<script>
|
|
@@ -246,7 +303,7 @@ Example:
|
|
|
246
303
|
Example:
|
|
247
304
|
|
|
248
305
|
```html
|
|
249
|
-
<div
|
|
306
|
+
<div>
|
|
250
307
|
<input pp-ref="nameInput" />
|
|
251
308
|
<button onclick="nameInput.current?.focus()">Focus</button>
|
|
252
309
|
|
|
@@ -270,7 +327,7 @@ Example:
|
|
|
270
327
|
Example:
|
|
271
328
|
|
|
272
329
|
```html
|
|
273
|
-
<div
|
|
330
|
+
<div>
|
|
274
331
|
<ul>
|
|
275
332
|
<template pp-for="(todo, index) in todos">
|
|
276
333
|
<li key="{todo.id}">
|
|
@@ -328,23 +385,43 @@ Notes:
|
|
|
328
385
|
- Root-layout mismatches during SPA navigation trigger a hard reload.
|
|
329
386
|
- `pp.mount()` bootstraps every `[pp-component]` it finds, so generated code should call it only through the global runtime if you are manually mounting at all.
|
|
330
387
|
|
|
388
|
+
## Runtime Output And Debugging
|
|
389
|
+
|
|
390
|
+
When you inspect rendered HTML in the browser, you should expect to see runtime-managed attributes and elements that are not part of authored source.
|
|
391
|
+
|
|
392
|
+
Normal runtime output includes:
|
|
393
|
+
|
|
394
|
+
- `pp-component="..."` on mounted roots.
|
|
395
|
+
- `script[type="text/pp"]` for owned component scripts.
|
|
396
|
+
- internal attributes such as captured ref tokens and event-owner bookkeeping.
|
|
397
|
+
|
|
398
|
+
These are runtime details.
|
|
399
|
+
|
|
400
|
+
- Mention them in docs when explaining how the browser runtime works.
|
|
401
|
+
- Do not use them as the default form in authored examples.
|
|
402
|
+
- Do not tell AI to handwrite them in route, layout, or component templates unless the task is explicitly about raw runtime HTML or runtime internals.
|
|
403
|
+
|
|
331
404
|
## AI rules
|
|
332
405
|
|
|
333
406
|
Use these rules when generating or editing PulsePoint runtime code:
|
|
334
407
|
|
|
335
408
|
- Treat PulsePoint as the default reactive frontend for Caspian app code.
|
|
336
|
-
- Use
|
|
409
|
+
- Use `public/js/pp-reactive-v2.js` as the shipped runtime contract AI should follow.
|
|
410
|
+
- Keep `main.py` in view because it injects the runtime-facing attributes and rewrites authored scripts before the browser sees them.
|
|
411
|
+
- If a development-only source tree exists behind the shipped runtime, treat it as optional implementation detail rather than something generated apps are guaranteed to contain.
|
|
337
412
|
- In authored Caspian templates, do not handwrite `pp-component` or `type="text/pp"`; let the render pipeline inject them.
|
|
338
413
|
- If you are explicitly editing raw runtime HTML or internals, keep `pp-component` unique per live instance.
|
|
339
414
|
- In authored templates, use a plain `<script>` inside the root. In runtime HTML, the owned script appears as `script[type="text/pp"]`.
|
|
340
415
|
- Keep template-facing variables at top level.
|
|
341
|
-
-
|
|
416
|
+
- Follow the React-style context pattern: `pp.createContext(...)`, `<Context.Provider value="{...}">`, and `pp.context(token)`.
|
|
417
|
+
- Do not invent `pp.provideContext`, `pp-context`, or other legacy context helpers.
|
|
342
418
|
- Keep `pp-for` on `<template>` and use plain `key`.
|
|
343
419
|
- Use native `on*` attributes, not framework-specific event syntax.
|
|
344
420
|
- Use refs and portals only through the implemented `pp` APIs.
|
|
345
421
|
- Use `pp.rpc()` for the bundled runtime API instead of older `pp.fetchFunction()` wording.
|
|
346
422
|
- Avoid generating internal runtime attributes.
|
|
347
423
|
- Avoid scriptless nested components when the child template contains its own bindings.
|
|
424
|
+
- Prefer authored-template examples over runtime-inspected HTML examples unless the doc is specifically explaining runtime internals.
|
|
348
425
|
|
|
349
426
|
## What to avoid
|
|
350
427
|
|
|
@@ -354,6 +431,7 @@ Do not generate these unless the current source explicitly adds support:
|
|
|
354
431
|
- `pp-context`
|
|
355
432
|
- `pp-key`
|
|
356
433
|
- `data-pp-ref`
|
|
434
|
+
- `pp-context-provider`
|
|
357
435
|
- `pp-owner`
|
|
358
436
|
- `pp-event-owner`
|
|
359
437
|
- `pp-dynamic-script`
|
|
@@ -368,10 +446,13 @@ Do not generate these unless the current source explicitly adds support:
|
|
|
368
446
|
These are current runtime caveats that matter for authors and AI tools:
|
|
369
447
|
|
|
370
448
|
- `pp-component` is the registry key for instances, state, parent tracking, and templates. Treat it as unique per mounted root.
|
|
449
|
+
- `public/js/pp-reactive-v2.js` is the runtime surface that ships and should be assumed to exist.
|
|
450
|
+
- Caspian already injects `pp-component` and rewrites owned scripts to `type="text/pp"` during render.
|
|
371
451
|
- Nested roots without their own `script[type="text/pp"]` block are not fully isolated during parent template compilation.
|
|
372
452
|
- The global `pp` singleton auto-mounts on DOM ready, and `pp.mount()` is idempotent.
|
|
373
453
|
- `pp.effect` and `pp.layoutEffect` are cleanup-style hooks. Their callbacks are not promise-aware.
|
|
374
454
|
- `pp.context()` resolves through ancestor components, not the current component's own pending providers.
|
|
455
|
+
- `pp.provideContext` is not part of the current runtime API. Use `Context.Provider`.
|
|
375
456
|
- `pp.portal()` preserves logical ancestry through the registry, so context and prop refresh behavior continue to work through portaled descendants.
|
|
376
457
|
|
|
377
458
|
## Final reminder
|