SPB Git

Repository Public License

COMPONENT_SDK.md 2.7 KB 44 lines markdown

1# Component SDK23A catalog component is three things that must agree: a **manifest** (the contract), a **view** (the implementation) and **tests**. A component without tests and a fixture counts as *planned*, not *working*.45## 1. Manifest (`packages/prism-component-catalog/Sources/Catalog.swift`)67```swift8ComponentManifest(9    type: "prism.badge", name: "Badge", category: "foundation",10    summary: "A small colored status label.",11    props: [PropSpec("text", .string, "Badge text.", required: true), toneProp],12    events: [], acceptsChildren: false, permissions: [],13    keywords: ["tag", "status", "pill", "chip"],14    accessibilityRole: "staticText", accessibilityLabelProp: "text",15    examples: [["id": "status", "type": "prism.badge", "props": ["text": "Over budget", "tone": "danger"]]],16    fixture: fixture("prism.badge", ["text": "Verified", "tone": "success"])17)18```1920- `PropSpec.kind`: `string`, `number`, `boolean`, `enum`, `list`, `object`, `query`, `any`.21- `dynamic: true` accepts `{"$expr": …}`; `binding: .required` demands `{"$bind": "stateKey"}` (inputs that write state).22- `fixture` is a self-contained preview (`root`, `objects`, optional `state` and `permissions`). It is rendered in the Library and in tests.23- `examples` are what the builder agent receives from `catalog.examples`; they must use only declared props and events.2425After changing any manifest run `scripts/update-catalog-lock.sh` and review the diff of `CatalogLock.swift`: the registry rejects a manifest whose content hash differs from the lock.2627## 2. View (`packages/prism-renderer/Sources/*Components.swift`)2829Add a case to `NodeView.content(_:)` and a SwiftUI view that takes the `PrismObject`.3031- Read props through the runtime: `runtime.string(o.props["text"])`, `runtime.bool(...)`, `runtime.rows(o.props["query"])`.32- Write state through `runtime.stateBinding(o)`; fire events with `runtime.fire("change", on: o.id, value: …)`.33- Never read files, the network or the clock directly; go through the runtime so permissions apply.34- A control with nothing to do must be disabled and say why (hard rule 2).35- Render children with `ChildrenView(ids: o.children)`.3637## 3. Tests3839Automatic for every manifest: strict decode round trip, fixture validates with zero errors, examples use declared props, the fixture renders off-screen without runtime errors (`RenderTests.everyComponentFixtureRenders`). Add behaviour tests in `RuntimeTests` when the component runs logic.4041## Validation rules a component gets for free4243Unknown or missing props, wrong literal types, enum values, expression syntax and names, undeclared state keys, query tables and columns, events and actions, permissions the app has not declared, and a missing accessibility label are all reported by `BlueprintValidator`.44
Files main
Menu

Theme