@shapesos/clay 0.9.0 → 0.10.0
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/README.md +46 -1
- package/dist/blocks.cjs +650 -0
- package/dist/blocks.cjs.map +1 -0
- package/dist/blocks.d.cts +29 -0
- package/dist/blocks.d.ts +29 -0
- package/dist/blocks.js +21 -0
- package/dist/blocks.js.map +1 -0
- package/dist/chat.cjs +89 -47
- package/dist/chat.cjs.map +1 -1
- package/dist/chat.d.cts +7 -3
- package/dist/chat.d.ts +7 -3
- package/dist/chat.js +3 -2
- package/dist/chunk-OKPNST44.js +1 -0
- package/dist/chunk-OKPNST44.js.map +1 -0
- package/dist/chunk-R3BGPOAM.js +230 -0
- package/dist/chunk-R3BGPOAM.js.map +1 -0
- package/dist/{chunk-TDMJUF4A.js → chunk-WPQQVKWY.js} +4 -4
- package/dist/{chunk-A77BGJH4.js → chunk-WS4IPADR.js} +34 -201
- package/dist/chunk-WS4IPADR.js.map +1 -0
- package/dist/index.cjs +129 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +27 -12
- package/dist/text-area.js +2 -2
- package/dist/types-Q9aqd9nq.d.cts +34 -0
- package/dist/types-Q9aqd9nq.d.ts +34 -0
- package/package.json +6 -1
- package/dist/chunk-A77BGJH4.js.map +0 -1
- /package/dist/{chunk-TDMJUF4A.js.map → chunk-WPQQVKWY.js.map} +0 -0
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ Clay is tree-shakeable with multiple entry points — import only what you need.
|
|
|
32
32
|
| ------------------------- | ------------------------------------- | ------------------------ |
|
|
33
33
|
| `@shapesos/clay/tokens` | Colors, typography, font families | None (pure JS) |
|
|
34
34
|
| `@shapesos/clay/chat` | Chat compound components + types | React, styled-components |
|
|
35
|
+
| `@shapesos/clay/blocks` | Typed content blocks (Block, BlockServices, BlockContext) | React, styled-components |
|
|
35
36
|
| `@shapesos/clay/icon` | Icon, IconButton components + types | React, styled-components |
|
|
36
37
|
| `@shapesos/clay/lottie` | Lottie animation component + types | React, styled-components |
|
|
37
38
|
| `@shapesos/clay` | Everything (convenience re-export) | React, styled-components |
|
|
@@ -122,11 +123,55 @@ type MessageRole = "user" | "assistant";
|
|
|
122
123
|
interface ChatMessage {
|
|
123
124
|
id: string;
|
|
124
125
|
role: MessageRole;
|
|
125
|
-
|
|
126
|
+
blocks: BlockData[]; // ordered, type-discriminated content blocks (defined by @shapesos/clay/blocks)
|
|
127
|
+
fallbackText: string; // server-supplied plain-text version of the blocks; used for clipboard/accessibility
|
|
126
128
|
isHelpful?: boolean | null;
|
|
127
129
|
}
|
|
128
130
|
```
|
|
129
131
|
|
|
132
|
+
`BlockData`, `BlockType`, and `TextBlockData` live in [`@shapesos/clay/blocks`](#blocks). Chat doesn't own block rendering — it composes the `Block` component from the blocks package and bridges chat-specific concerns (like passing the message's `id` into `TableActions` callbacks). This means the same block infrastructure renders chat messages, vibe-view embeds, marketing-site responses, or any other surface that wants typed content blocks — without coupling to chat.
|
|
133
|
+
|
|
134
|
+
</details>
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Blocks
|
|
139
|
+
|
|
140
|
+
Typed content-block infrastructure: a `Block` dispatcher, a `BlockServices` registry of concrete renderers (currently `TextBlockService`), and a `BlockContext` for renderer-level concerns like table actions. Chat consumes this internally — non-chat surfaces import directly.
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
import { Block, BlockContext, type BlockData } from "@shapesos/clay/blocks";
|
|
144
|
+
|
|
145
|
+
const blocks: BlockData[] = [{ type: "TEXT", payload: { text: "**hello world**" } }];
|
|
146
|
+
|
|
147
|
+
function MyContent() {
|
|
148
|
+
return (
|
|
149
|
+
<BlockContext.Provider value={{ TableActions: ({ tableIndex }) => <ExportButton index={tableIndex} /> }}>
|
|
150
|
+
{blocks.map((block, i) => <Block key={i} block={block} />)}
|
|
151
|
+
</BlockContext.Provider>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The wire shape (`{ type, payload }`) matches `dreamteam-io-server` / `shapes-agent` 1:1, so blocks fetched from the API can be passed straight to `Block` with no translation. Unknown block types render as no-ops (forward-compat). Adding a new block type is a registration in `BlockServices` plus a concrete component — no changes to the dispatcher.
|
|
157
|
+
|
|
158
|
+
<details>
|
|
159
|
+
<summary><strong>Public API</strong></summary>
|
|
160
|
+
|
|
161
|
+
| Export | Kind | Description |
|
|
162
|
+
| --------------------- | --------- | -------------------------------------------------------------------------------------------- |
|
|
163
|
+
| `Block` | Component | Single-block dispatcher. Looks up the concrete renderer in `BlockServices` by `block.type`. |
|
|
164
|
+
| `BlockContext` | Context | Renderer-level concerns (today: `TableActions`). Optional — `Block` works without it. |
|
|
165
|
+
| `useBlockContext` | Hook | Reads the ambient `BlockContextValue`. Returns `{}` outside a provider. |
|
|
166
|
+
| `BlockServices` | Registry | `{ TEXT: TextBlockService }` today; additive over time. |
|
|
167
|
+
| `TextBlockService` | Service | Concrete renderer entry for `TEXT` blocks. |
|
|
168
|
+
| `BlockData` | Type | Discriminated union of all block shapes. |
|
|
169
|
+
| `TextBlockData` | Type | `{ type: "TEXT"; payload: { text: string } }`. |
|
|
170
|
+
| `BlockType` | Type | `"TEXT"` (literal union; widens as new types are added). |
|
|
171
|
+
| `BlockComponentProps` | Type | Props every concrete block component receives — `{ block }`. |
|
|
172
|
+
| `BlockService` | Type | Service registry entry contract — `{ type, Component }`. |
|
|
173
|
+
| `BlockContextValue` | Type | `{ TableActions?: ComponentType<{ tableIndex: number }> }`. |
|
|
174
|
+
|
|
130
175
|
</details>
|
|
131
176
|
|
|
132
177
|
---
|