claude-artifact-framework 0.8.0 → 0.8.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/README.md +56 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ mirrors npm packages automatically.
|
|
|
20
20
|
### As a global script (`<script>` tag)
|
|
21
21
|
|
|
22
22
|
```html
|
|
23
|
-
<script src="https://cdn.jsdelivr.net/npm/claude-artifact-framework@0.8.
|
|
23
|
+
<script src="https://cdn.jsdelivr.net/npm/claude-artifact-framework@0.8.1/dist/index.global.js"></script>
|
|
24
24
|
<script>
|
|
25
25
|
ArtifactKit.useReact(React); // hand over the page's React once
|
|
26
26
|
const App = ArtifactKit.createApp({ title: "Mi app", blocks: [ /* ... */ ] });
|
|
@@ -38,11 +38,11 @@ mirrors npm packages automatically.
|
|
|
38
38
|
createStore,
|
|
39
39
|
createPersistedStore,
|
|
40
40
|
createSharedStore,
|
|
41
|
-
} from "https://cdn.jsdelivr.net/npm/claude-artifact-framework@0.8.
|
|
41
|
+
} from "https://cdn.jsdelivr.net/npm/claude-artifact-framework@0.8.1/dist/index.esm.js";
|
|
42
42
|
</script>
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
Pin a version (`@0.8.
|
|
45
|
+
Pin a version (`@0.8.1`) for reproducible artifacts, or drop the version
|
|
46
46
|
(`claude-artifact-framework/dist/...`) to always get the latest release.
|
|
47
47
|
|
|
48
48
|
### Inside a React artifact
|
|
@@ -436,6 +436,59 @@ records: {
|
|
|
436
436
|
}
|
|
437
437
|
```
|
|
438
438
|
|
|
439
|
+
### Writing `custom` blocks that work
|
|
440
|
+
|
|
441
|
+
`custom: (ctx) => ...` runs **during React render**. The rules below come
|
|
442
|
+
from measured failures — each one is a way a model has actually broken a
|
|
443
|
+
custom block:
|
|
444
|
+
|
|
445
|
+
- **Return a string or a React element — never a DOM element.**
|
|
446
|
+
`document.createElement(...)` as a return value is not renderable (React
|
|
447
|
+
error #31, contained in the block). To use a library that *writes into*
|
|
448
|
+
an element (QRCode, pdf.js, chart libs), give it a ref:
|
|
449
|
+
|
|
450
|
+
```js
|
|
451
|
+
custom: (ctx) => {
|
|
452
|
+
const ref = React.useRef(null);
|
|
453
|
+
React.useEffect(() => {
|
|
454
|
+
if (!ref.current || !ctx.data.texto) return;
|
|
455
|
+
ref.current.innerHTML = "";
|
|
456
|
+
new QRCode(ref.current, { text: ctx.data.texto, width: 220, height: 220 });
|
|
457
|
+
}, [ctx.data.texto]);
|
|
458
|
+
return React.createElement("div", { ref });
|
|
459
|
+
}
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
- **React hooks are allowed** inside custom (`React.useState`,
|
|
463
|
+
`React.useEffect`, `React.useRef`) — it runs in a component's render, and
|
|
464
|
+
`React` is available as a global.
|
|
465
|
+
- **State has exactly two homes.** Persistent or visible to other blocks →
|
|
466
|
+
`ctx.update((d) => { d.x = ... })` (the whole app re-renders and it's
|
|
467
|
+
saved). Ephemeral UI state → `React.useState`. **Never `createStore` for
|
|
468
|
+
UI state** — stores do not re-render the app; a parse result stored there
|
|
469
|
+
will compute correctly and never appear on screen.
|
|
470
|
+
- **Async work over an uploaded file**: an effect keyed on the file, local
|
|
471
|
+
state for the result:
|
|
472
|
+
|
|
473
|
+
```js
|
|
474
|
+
custom: (ctx) => {
|
|
475
|
+
const file = ctx.files.archivo;
|
|
476
|
+
const [rows, setRows] = React.useState(null);
|
|
477
|
+
React.useEffect(() => {
|
|
478
|
+
if (!file) { setRows(null); return; }
|
|
479
|
+
file.text().then((t) => setRows(t.trim().split("\n").map((l) => l.split(","))));
|
|
480
|
+
}, [file]);
|
|
481
|
+
if (!file) return "Subí un archivo para analizarlo.";
|
|
482
|
+
if (!rows) return "Analizando…";
|
|
483
|
+
return React.createElement(/* tu tabla */);
|
|
484
|
+
}
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
- Custom re-renders whenever `data` or `view` change; it receives the full
|
|
488
|
+
`ctx` (`data`, `update`, `view`, `files`, `viewerId`, `colors`, `go`,
|
|
489
|
+
`back`) and lives inside the block error boundary — a bug in your custom
|
|
490
|
+
code shows a named error in its slot, never a blank app.
|
|
491
|
+
|
|
439
492
|
## API reference
|
|
440
493
|
|
|
441
494
|
Everything an app can declare, in one place.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-artifact-framework",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Utilities for building apps inside Claude Artifacts: platform storage, chat tool-calling loops, and other primitives verified against the real runtime.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.esm.js",
|