@cascivo/render 1.3.1
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/LICENSE +21 -0
- package/README.md +103 -0
- package/dist/cascivo-view-7VMyIOGf.js +2 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.js +1 -0
- package/dist/validate-CLWUnuCw.js +1 -0
- package/dist/validate.d.ts +10 -0
- package/dist/validate.js +1 -0
- package/dist/view-text.d.ts +61 -0
- package/dist/view-text.js +1 -0
- package/package.json +88 -0
- package/readme.body.md +73 -0
- package/schema/view.v1.json +7976 -0
package/readme.body.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
A runtime that turns a plain **JSON config into live cascivo UI**. `CascivoView` takes a `ViewConfig` object and renders the real components — so AI agents (and no-code tooling) can emit data instead of writing TSX.
|
|
2
|
+
|
|
3
|
+
## Usage
|
|
4
|
+
|
|
5
|
+
A `ViewConfig` is named regions of component nodes; each node names a component (`component`), plus optional `props`, `children`, data bindings, and event wiring:
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { CascivoView, type ViewConfig } from '@cascivo/render'
|
|
9
|
+
|
|
10
|
+
const view: ViewConfig = {
|
|
11
|
+
view: {
|
|
12
|
+
regions: {
|
|
13
|
+
main: [
|
|
14
|
+
{
|
|
15
|
+
component: 'Card',
|
|
16
|
+
children: [
|
|
17
|
+
{
|
|
18
|
+
component: 'Badge',
|
|
19
|
+
props: { variant: 'secondary' },
|
|
20
|
+
bind: { children: '$data.count' },
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
component: 'Button',
|
|
24
|
+
props: { variant: 'primary' },
|
|
25
|
+
children: 'Invite',
|
|
26
|
+
events: { onClick: '$actions.invite' },
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function App() {
|
|
36
|
+
return (
|
|
37
|
+
<CascivoView
|
|
38
|
+
config={view}
|
|
39
|
+
data={{ count: 42 }}
|
|
40
|
+
actions={{ invite: () => console.log('invite') }}
|
|
41
|
+
/>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The JSON stays fully serializable: live values come from the host via `bind` (`"$data.users.active"` resolves a dot-path into the `data` prop) and handlers via `events` (`"$actions.invite"` looks up the `actions` prop) — never from the config itself. Strings can be i18n refs (`{ "$t": "catalog.key" }`), resolved through `@cascivo/i18n`. `config` also accepts a `Signal<ViewConfig>`, so a view can be swapped live.
|
|
47
|
+
|
|
48
|
+
Nodes resolve against a built-in component map of ~50 core cascivo components (Button, Card, Badge, Input, Select, Modal, Tabs, DataTable, Form, …) — see `component-map.ts` for the full list.
|
|
49
|
+
|
|
50
|
+
## Validation
|
|
51
|
+
|
|
52
|
+
Every render validates first. Invalid configs **throw** by default with exact paths; pass `onInvalid="render"` to show errors inline instead (playground mode). `validateView` is exported for validating before rendering:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { validateView } from '@cascivo/render'
|
|
56
|
+
|
|
57
|
+
const { valid, errors } = validateView(view) // errors: { path, message }[]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Unknown components (with a did-you-mean hint), malformed nodes, and prop values that don't match the generated per-component prop schemas are reported with exact paths, so generated views fail loudly rather than rendering garbage.
|
|
61
|
+
|
|
62
|
+
On a server, import it from `@cascivo/render/validate`. That entry has no React and no components, only the validator and the prop schemas it checks against, so it runs in a Cloudflare Worker, an edge function or a Node script:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { validateView } from '@cascivo/render/validate'
|
|
66
|
+
|
|
67
|
+
// In an AI tool: hand the errors back to the model, which fixes them and calls again.
|
|
68
|
+
const { valid, errors } = validateView(modelOutput)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`cascivo create --framework cloudflare --example agent` builds an assistant around exactly this: the Worker validates each view the model produces, and the page renders it with `<CascivoView>`.
|
|
72
|
+
|
|
73
|
+
Pair it with the MCP server's bound-vocabulary grammar (`get_view_grammar`) and `scaffold_view` for the full anti-hallucination loop: the model can only emit components and props that exist, and `validateView` is the enforcement backstop. `cascivo generate <config.json>` converts a validated `ViewConfig` into owned TSX when you want to graduate from JSON to source.
|