{"_id":"emdash-plugin-puck","_rev":"3-b83bfd8f93c417648c67a814f5b6fe34","name":"emdash-plugin-puck","dist-tags":{"latest":"0.3.0"},"versions":{"0.1.0":{"name":"emdash-plugin-puck","version":"0.1.0","keywords":["emdash","emdash-plugin","puck","puckeditor","page-builder","visual-editor","cms","astro"],"author":{"name":"Marko Stankovic"},"license":"MIT","_id":"emdash-plugin-puck@0.1.0","maintainers":[{"name":"markoinla","email":"m@marko.la"}],"homepage":"https://github.com/markoinla/emdash-plugin-puck#readme","bugs":{"url":"https://github.com/markoinla/emdash-plugin-puck/issues"},"dist":{"shasum":"d4656ce42ba51471cdf701d78b2d4cd42bd05d14","tarball":"https://registry.npmjs.org/emdash-plugin-puck/-/emdash-plugin-puck-0.1.0.tgz","fileCount":23,"integrity":"sha512-fD76H9MHVsGIUn9y9HYjjklp/LeBMXqI5xL95IWCsTBn5Lw9i0MDQZn0N1CQfN9yif4axnTvlUQzauBvlOTdzA==","signatures":[{"sig":"MEUCIQC8ZlT9Vmge5t2VpQhsg1IlaoctDi9bl5BahbfTLKTAXAIgCNDSglFy9yLBp7QSQAFFWJvSzKTn/AtjcJdSsQgUCv0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":125115},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=22.12.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./ai":{"types":"./dist/ai/index.d.ts","import":"./dist/ai/index.js"},"./admin":{"types":"./dist/admin.d.ts","import":"./dist/admin.js"},"./fields":{"types":"./dist/fields.d.ts","import":"./dist/fields.js"},"./render":{"types":"./dist/render/index.d.ts","import":"./dist/render/index.js"},"./theme.css":"./dist/theme.css","./ai/handler":{"types":"./dist/ai/handler.d.ts","import":"./dist/ai/handler.js"},"./package.json":"./package.json","./render/designed":{"types":"./dist/render/designed.d.ts","import":"./dist/render/designed.js"}},"gitHead":"8869d7f2480023855f37c31c32c2146ddd765b95","scripts":{"dev":"tsdown --watch","build":"tsdown && cp src/theme.css dist/theme.css","typecheck":"tsc --noEmit","prepublishOnly":"npm run typecheck && npm run build"},"_npmUser":{"name":"markoinla","email":"m@marko.la"},"repository":{"url":"git+https://github.com/markoinla/emdash-plugin-puck.git","type":"git"},"_npmVersion":"11.19.0","description":"The Puck visual editor as an EmDash field widget: edit any json field as a page layout, render it on the public site, pick images from the EmDash media library, and optionally wire up Puck AI.","directories":{},"sideEffects":["**/*.css"],"_nodeVersion":"26.7.0","_hasShrinkwrap":false,"devDependencies":{"astro":"^7.0.0","react":"^18.3.1","emdash":"^0.36.0","tsdown":"^0.23.0","react-dom":"^18.3.1","typescript":"^6.0.0","@types/node":"^22.0.0","@types/react":"^18.3.27","@puckeditor/core":"0.23.0","@types/react-dom":"^18.3.7","@puckeditor/plugin-ai":"^0.8.2","@puckeditor/cloud-client":"^0.8.2"},"peerDependencies":{"astro":"^5.0.0 || ^6.0.0 || ^7.0.0","react":"^18.0.0 || ^19.0.0","emdash":">=0.35.0 <0.37.0","react-dom":"^18.0.0 || ^19.0.0","@puckeditor/core":"^0.23.0","@puckeditor/plugin-ai":"^0.8.0","@puckeditor/cloud-client":"^0.8.0"},"peerDependenciesMeta":{"astro":{"optional":true},"@puckeditor/plugin-ai":{"optional":true},"@puckeditor/cloud-client":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/emdash-plugin-puck_0.1.0_1788553713749_0.3315788516186544","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"emdash-plugin-puck","version":"0.2.0","keywords":["emdash","emdash-plugin","puck","puckeditor","page-builder","visual-editor","cms","astro"],"author":{"name":"Marko Stankovic"},"license":"MIT","_id":"emdash-plugin-puck@0.2.0","maintainers":[{"name":"markoinla","email":"m@marko.la"}],"homepage":"https://github.com/markoinla/emdash-plugin-puck#readme","bugs":{"url":"https://github.com/markoinla/emdash-plugin-puck/issues"},"dist":{"shasum":"0ca61198c3948a92875911ff909281cd9ea6643f","tarball":"https://registry.npmjs.org/emdash-plugin-puck/-/emdash-plugin-puck-0.2.0.tgz","fileCount":27,"integrity":"sha512-kg9ivPI8nc5Q8eeMk4AT+5qxEJjd4w+Pa39JlH9p5dqbYG0Dl2OUHTu6M9dcgdwKsbL5vkJh5ObpwC+IwydNPQ==","signatures":[{"sig":"MEUCIG/kp5MZgkzdEjEO744IpwI1N16zxeA51LWJz4j+/dRZAiEArFxtBvoMwH38qVvvOTFFjTKACnm6DGha/ilPpPmL0p4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":212357},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=22.12.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./ai":{"types":"./dist/ai/index.d.ts","import":"./dist/ai/index.js"},"./admin":{"types":"./dist/admin.d.ts","import":"./dist/admin.js"},"./blocks":{"types":"./dist/blocks/index.d.ts","import":"./dist/blocks/index.js"},"./fields":{"types":"./dist/fields.d.ts","import":"./dist/fields.js"},"./render":{"types":"./dist/render/index.d.ts","import":"./dist/render/index.js"},"./theme.css":"./dist/theme.css","./ai/handler":{"types":"./dist/ai/handler.d.ts","import":"./dist/ai/handler.js"},"./blocks.css":"./dist/blocks.css","./package.json":"./package.json","./render/designed":{"types":"./dist/render/designed.d.ts","import":"./dist/render/designed.js"}},"gitHead":"a35adaa7c0d42dbbfa9df6587f2d3b6f87dcaf49","scripts":{"dev":"tsdown --watch","build":"tsdown && cp src/theme.css src/blocks.css dist/","typecheck":"tsc --noEmit","prepublishOnly":"npm run typecheck && npm run build"},"_npmUser":{"name":"markoinla","email":"m@marko.la"},"repository":{"url":"git+https://github.com/markoinla/emdash-plugin-puck.git","type":"git"},"_npmVersion":"11.19.0","description":"The Puck visual editor as an EmDash field widget: edit any json field as a page layout, render it on the public site, pick images from the EmDash media library, and optionally wire up Puck AI.","directories":{},"sideEffects":["**/*.css"],"_nodeVersion":"26.7.0","_hasShrinkwrap":false,"devDependencies":{"astro":"^7.0.0","react":"^18.3.1","emdash":"^0.36.0","tsdown":"^0.23.0","react-dom":"^18.3.1","typescript":"^6.0.0","@types/node":"^22.0.0","@types/react":"^18.3.27","@puckeditor/core":"0.23.0","@types/react-dom":"^18.3.7","@puckeditor/plugin-ai":"^0.8.2","@puckeditor/cloud-client":"^0.8.2"},"peerDependencies":{"astro":"^5.0.0 || ^6.0.0 || ^7.0.0","react":"^18.0.0 || ^19.0.0","emdash":">=0.35.0 <0.37.0","react-dom":"^18.0.0 || ^19.0.0","@puckeditor/core":"^0.23.0","@puckeditor/plugin-ai":"^0.8.0","@puckeditor/cloud-client":"^0.8.0"},"peerDependenciesMeta":{"astro":{"optional":true},"@puckeditor/plugin-ai":{"optional":true},"@puckeditor/cloud-client":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/emdash-plugin-puck_0.2.0_1788556351911_0.7973914033320177","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"_id":"emdash-plugin-puck@0.3.0","bugs":{"url":"https://github.com/markoinla/emdash-plugin-puck/issues"},"dist":{"shasum":"76bb6e53619d784cdb7376dd570ab4a48a46f13d","tarball":"https://registry.npmjs.org/emdash-plugin-puck/-/emdash-plugin-puck-0.3.0.tgz","fileCount":27,"integrity":"sha512-gx5mdIjx4J9Y7rVkjbz+VG7OloLG+fxjS2D3Brwp09W7Am+wcPeRQjrjCpges/weUVWo8Sm+fCjcR9bve/n+ag==","signatures":[{"sig":"MEUCIG+FWpG3X8JxNj8olfamrlgcZGsQn2chUoL5AhBug7b0AiEAjodXzhLYucjVG16t2QR6lZ64QrEV6QbMLSzHs6WTfnw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCv/bzyc5AXalWF8X79slWFAvXdONbAZzwjdLp4X+ZV2wIgPjuUyfkbOsI1TmN5Q0mDOLrmJ1O4m/uIdYyj0v3fqA4="}],"unpackedSize":211571},"main":"dist/index.js","name":"emdash-plugin-puck","type":"module","types":"./dist/index.d.ts","author":{"name":"Marko Stankovic"},"engines":{"node":">=22.12.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./ai":{"types":"./dist/ai/index.d.ts","import":"./dist/ai/index.js"},"./admin":{"types":"./dist/admin.d.ts","import":"./dist/admin.js"},"./blocks":{"types":"./dist/blocks/index.d.ts","import":"./dist/blocks/index.js"},"./fields":{"types":"./dist/fields.d.ts","import":"./dist/fields.js"},"./render":{"types":"./dist/render/index.d.ts","import":"./dist/render/index.js"},"./theme.css":"./dist/theme.css","./ai/handler":{"types":"./dist/ai/handler.d.ts","import":"./dist/ai/handler.js"},"./blocks.css":"./dist/blocks.css","./package.json":"./package.json","./render/designed":{"types":"./dist/render/designed.d.ts","import":"./dist/render/designed.js"}},"gitHead":"1cf1be7219ebd9e0f1dc58a328f9bd4a658dd935","license":"MIT","scripts":{"dev":"tsdown --watch","build":"tsdown && cp src/theme.css src/blocks.css dist/","typecheck":"tsc --noEmit","prepublishOnly":"npm run typecheck && npm run build"},"version":"0.3.0","_npmUser":{"name":"markoinla","email":"m@marko.la"},"homepage":"https://github.com/markoinla/emdash-plugin-puck#readme","keywords":["emdash","emdash-plugin","puck","puckeditor","page-builder","visual-editor","cms","astro"],"repository":{"url":"git+https://github.com/markoinla/emdash-plugin-puck.git","type":"git"},"_npmVersion":"11.14.1","description":"The Puck visual editor as an EmDash field widget: edit any json field as a page layout, render it on the public site, pick images from the EmDash media library, and optionally wire up Puck AI.","directories":{},"maintainers":[{"name":"markoinla","email":"m@marko.la"}],"sideEffects":["**/*.css"],"_nodeVersion":"22.22.0","_hasShrinkwrap":false,"devDependencies":{"astro":"^7.0.0","react":"^18.3.1","emdash":"^1.2.0","tsdown":"^0.23.0","react-dom":"^18.3.1","typescript":"^6.0.0","@types/node":"^22.0.0","@types/react":"^18.3.27","@puckeditor/core":"0.23.0","@types/react-dom":"^18.3.7","@puckeditor/plugin-ai":"^0.8.2","@puckeditor/cloud-client":"^0.8.2"},"peerDependencies":{"astro":"^5.0.0 || ^6.0.0 || ^7.0.0","react":"^18.0.0 || ^19.0.0","emdash":">=0.35.0 <2.0.0","react-dom":"^18.0.0 || ^19.0.0","@puckeditor/core":"^0.23.0","@puckeditor/plugin-ai":"^0.8.0","@puckeditor/cloud-client":"^0.8.0"},"peerDependenciesMeta":{"astro":{"optional":true},"@puckeditor/plugin-ai":{"optional":true},"@puckeditor/cloud-client":{"optional":true}},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/emdash-plugin-puck_0.3.0_1791509830603_0.7965846007827861"}}},"time":{"created":"2026-09-04T20:28:33.426Z","modified":"2026-10-09T01:37:10.914Z","0.1.0":"2026-09-04T20:28:33.896Z","0.2.0":"2026-09-04T21:12:32.072Z","0.3.0":"2026-10-09T01:37:10.734Z"},"bugs":{"url":"https://github.com/markoinla/emdash-plugin-puck/issues"},"author":{"name":"Marko Stankovic"},"license":"MIT","homepage":"https://github.com/markoinla/emdash-plugin-puck#readme","keywords":["emdash","emdash-plugin","puck","puckeditor","page-builder","visual-editor","cms","astro"],"repository":{"url":"git+https://github.com/markoinla/emdash-plugin-puck.git","type":"git"},"description":"The Puck visual editor as an EmDash field widget: edit any json field as a page layout, render it on the public site, pick images from the EmDash media library, and optionally wire up Puck AI.","maintainers":[{"name":"markoinla","email":"m@marko.la"}],"readme":"# emdash-plugin-puck\n\nThe [Puck](https://puckeditor.com/) visual editor as an [EmDash](https://github.com/emdash-cms/emdash) plugin.\n\nIt registers one field widget, `puck:canvas`, that takes over any `json` field and edits it with Puck instead of a raw JSON textarea. The stored value is Puck `Data` (`{ root, content, zones? }`), and the same package renders it on the public site.\n\n- Full-screen editor overlay with Cancel / Save layout and an unsaved-changes guard\n- A searchable block panel with live hover previews, rendered from each block's real `defaultProps`\n- Puck's chrome themed onto the EmDash admin's design tokens, so it follows the admin's light and dark mode\n- `mediaField()`: the EmDash media library (browse, search, upload) as a Puck field, for images or videos\n- A starter kit of ten composable blocks (Grid, Flex, Space, Heading, Text, Prose, Card, Stats, Logos, Button), ported from Puck's demo app\n- Public rendering with per-section error boundaries, so one broken block costs one section and not the page\n- Optional Puck AI: the chat panel in the editor, plus the authenticated Puck Cloud route behind it\n\n![The Puck editor inside the EmDash admin: block panel on the left, canvas in the middle, page fields on the right](docs/editor.webp)\n\n\n## Requirements\n\n| | |\n| --- | --- |\n| EmDash | `>=0.35 <2` (tested on 0.36 and 1.2) |\n| Puck | `@puckeditor/core` 0.23 |\n| React | 18 or 19 |\n| Astro | 5, 6 or 7 (the AI route is an Astro `APIRoute`) |\n\n```bash\nnpm install emdash-plugin-puck @puckeditor/core\n# for Puck AI:\nnpm install @puckeditor/plugin-ai @puckeditor/cloud-client\n```\n\n## Setup\n\nSix steps. The site owns three small files: the admin entry, the Puck config and the render island.\n\n**1. Install**\n\n```bash\nnpm install emdash-plugin-puck @puckeditor/core@0.23\nnpm install @puckeditor/plugin-ai @puckeditor/cloud-client   # only for Puck AI\n```\n\n**2. Register the plugin** in `astro.config.mjs`\n\n```js\nimport emdash from \"emdash/astro\";\nimport puck from \"emdash-plugin-puck\";\n\nexport default defineConfig({\n  integrations: [\n    emdash({\n      plugins: [\n        puck({ adminEntry: new URL(\"./src/puck/admin.tsx\", import.meta.url).href }),\n      ],\n    }),\n  ],\n  vite: {\n    optimizeDeps: {\n      // Required. Add \"@puckeditor/plugin-ai\" if used, and every bare\n      // dependency your blocks import. See \"optimizeDeps\" below.\n      include: [\"@puckeditor/core\"],\n    },\n  },\n});\n```\n\n`adminEntry` is your file (step 3), as an absolute URL string: EmDash inlines it into a generated virtual module that cannot resolve a relative path.\n\n**3. Write the admin entry** at `src/puck/admin.tsx`\n\n```tsx\nimport { createPuckAdmin } from \"emdash-plugin-puck/admin\";\nimport { config } from \"./config\";\n\nexport const { fields } = createPuckAdmin({ config });\n```\n\nIf your blocks depend on site CSS, add `canvas: { stylesheets: [href], css: \"...\", colorScheme: \"light\" }`; see [Styles in the canvas](#styles-in-the-canvas).\n\n**4. Write the Puck config** at `src/puck/config.tsx`. The quickest start is the bundled kit:\n\n```tsx\nimport type { Config } from \"@puckeditor/core\";\nimport { createBlocks } from \"emdash-plugin-puck/blocks\";\nimport \"emdash-plugin-puck/blocks.css\";\n\nconst kit = createBlocks();\n\nexport const config: Config = {\n  categories: { ...kit.categories },\n  components: { ...kit.components },\n};\n```\n\nAdd your own blocks beside them. Use `mediaField(\"Image\")` from `emdash-plugin-puck/fields` for image props, and `Editable` from `emdash-plugin-puck/render` for any prop with `contentEditable: true`. See [Starter blocks](#starter-blocks) and [Writing blocks](#writing-blocks).\n\n**5. Point a `json` field at the widget.** In a seed:\n\n```json\n{ \"slug\": \"layout\", \"type\": \"json\", \"widget\": \"puck:canvas\" }\n```\n\nOr on an existing field, over the REST API. `widget` is its own column, so it cannot be set through `options`, the `schema_create_field` MCP tool has no parameter for it, and `PATCH` 404s (`PUT` is the verb):\n\n```bash\ncurl -X PUT -H \"Authorization: Bearer $EMDASH_API_TOKEN\" -H \"X-EmDash-Request: 1\" \\\n  -H \"Content-Type: application/json\" -d '{\"widget\":\"puck:canvas\"}' \\\n  http://localhost:4321/_emdash/api/schema/collections/pages/fields/layout\n```\n\n`GET /_emdash/api/manifest` (authenticated) shows the widget the admin will use.\n\n**6. Render the page**\n\n```tsx\n// src/puck/PuckPage.tsx\nimport { createPuckPage } from \"emdash-plugin-puck/render\";\nimport { config } from \"./config\";\n\nexport default createPuckPage(config);\n```\n\n```astro\n---\n// src/pages/[...slug].astro\nimport { getEmDashEntry } from \"emdash\";\nimport { parseLayout } from \"emdash-plugin-puck/render\";\nimport PuckPage from \"../puck/PuckPage\";\n\nconst { entry, cacheHint } = await getEmDashEntry(\"pages\", Astro.params.slug!);\nif (!entry) return Astro.rewrite(\"/404\");\nif (cacheHint && Astro.cache?.enabled) Astro.cache.set(cacheHint);\n\nconst layout = parseLayout(entry.data.layout);\n---\n<Layout>\n  {layout && (\n    <div {...entry.edit.layout}>\n      <PuckPage client:load data={layout} />\n    </div>\n  )}\n</Layout>\n```\n\n`client:load` is required: the whole document is one island that server-renders first and then hydrates. The config cannot be an island prop (it holds React components), which is what `createPuckPage` is for. Any block module that touches `window` at module scope must use a dynamic `import()`.\n\n**Optional: Puck AI.** Add `puckAi()` to the admin entry, a route, and the key:\n\n```tsx\n// src/puck/admin.tsx\nimport { puckAi } from \"emdash-plugin-puck/ai\";\nconst ai = puckAi(); // module scope\nexport const { fields } = createPuckAdmin({ config, ...ai });\n```\n\n```ts\n// src/pages/api/puck/[...all].ts   (path fixed by Puck's client)\nimport { createPuckAiHandler } from \"emdash-plugin-puck/ai/handler\";\nconst handler = createPuckAiHandler({ context: \"You write pages for ...\" });\nexport const GET = handler;\nexport const POST = handler;\nexport const DELETE = handler;\n```\n\nSet `PUCK_API_KEY` in the environment. See [Puck AI](#puck-ai), including the second island needed for design mode.\n\n**Verify**\n\n1. `astro check` and `astro build` pass.\n2. Open the admin, edit an entry: the field shows \"Edit layout\", the overlay opens with your blocks listed, save writes `{ root, content }` to the field.\n3. The public route renders the page, and the browser console shows no `[puck]` boundary errors.\n4. If the admin sits on \"Loading EmDash…\", a dependency is missing from `optimizeDeps.include` (check the console for a failed `PluginRegistry` import).\n\n## Starter blocks\n\n`emdash-plugin-puck/blocks` ships ten composable blocks in two categories: **Layout** (Grid, Flex, Space) and **Content** (Heading, Text, Prose, Card, Stats, Logos, Button). Every block carries a parent-aware `layout` field (column span inside a Grid, grow inside a Flex, vertical padding elsewhere), inline-editable copy, closed token selects instead of free numbers, and Puck AI instructions.\n\n```tsx\nconst kit = createBlocks({\n  // Card icons: a closed vocabulary you supply. Without it the Card has no icon field.\n  icons: { options: [{ label: \"Globe\", value: \"globe\" }], render: (key) => <Icon name={key} /> },\n  // Rewrite author-typed hrefs (a base path, say). Default: identity.\n  resolveHref: withBase,\n  // Your own full-width sections, which must not be dropped inside a Grid or Flex cell.\n  disallow: [\"Hero\", \"Footer\"],\n  // Extra Button actions beside \"Go to a link\". Picking one hides the href field.\n  buttonActions: [{ value: \"contact\", label: \"Open contact form\", onClick: openDrawer }],\n  // Wear the site's own button classes instead of the package's `zk-btn`.\n  buttonClassName: (variant, size) => `btn btn-${variant}${size === \"large\" ? \" btn-lg\" : \"\"}`,\n  // Replace the spacing, gap or width scales.\n  options: { maxWidth: [{ label: \"Wide\", value: \"1200px\" }] },\n});\n```\n\n**The stylesheet loads in three places.** `import \"emdash-plugin-puck/blocks.css\"` from your config puts it on the public page and on the admin document, which Puck copies into the canvas. The block panel's preview iframe is a separate document, so also pass it raw in the admin entry:\n\n```tsx\nimport blocksCss from \"emdash-plugin-puck/blocks.css?raw\";\nexport const { fields } = createPuckAdmin({ config, blockPanel: { css: blocksCss } });\n```\n\n**Styling.** Every colour, size and radius in `blocks.css` reads a `--zk-*` variable, then a conventional site token (`--color-text`, `--color-brand`, `--font-size-lg`, `--site-radius`), then a literal. A site that already declares those tokens gets its own look with no configuration; any site can retune the blocks by declaring `--zk-*` on `:root`; a bare site is still presentable. The classes are plain (`zk-grid`, `zk-card`) rather than CSS modules because the preview iframe receives the sheet as raw text.\n\n**The registry keys must stay `Grid` and `Flex`.** The layout field narrows itself by the parent's registry name, so renaming either loses the span and grow controls.\n\n## Media\n\nReplace the plain URL text box on every image or video prop:\n\n```ts\nimport { mediaField } from \"emdash-plugin-puck/fields\";\n\nfields: {\n  image: mediaField(\"Image\"),\n  logo: mediaField(\"Logo\", \"Empty renders the name as a wordmark\"),\n  clip: mediaField(\"Video\", undefined, { kind: \"video\" }),\n}\n```\n\nIt stores exactly what a text field would store, a URL string, so nothing downstream changes. Values keep the proxy shape (`/_emdash/api/media/file/<key>`); if your public build rewrites them to a CDN, do that on the way out in `parseLayout`'s `transform`, not in the data.\n\nOne known blind spot: EmDash's media-usage extractor walks `image`, `file`, `repeater` and `portableText` fields only. A URL stored inside a `json` layout is invisible to it, so every asset used by a Puck page reads as used-nowhere in the media library. Nothing deletes those files, but \"where is this used\" under-reports.\n\n## Puck AI\n\nTwo halves, and both are opt-in.\n\n```tsx\n// src/puck/admin.tsx\nimport { createPuckAdmin } from \"emdash-plugin-puck/admin\";\nimport { puckAi } from \"emdash-plugin-puck/ai\";\nimport { config } from \"./config\";\n\nconst ai = puckAi(); // module scope, or the chat remounts on every render\n\nexport const { fields } = createPuckAdmin({ config, ...ai });\n```\n\n```ts\n// src/pages/api/puck/[...all].ts\nimport { createPuckAiHandler } from \"emdash-plugin-puck/ai/handler\";\n\nconst handler = createPuckAiHandler({\n  context: \"You write pages for ... (positioning, audience, voice, hard rules)\",\n  designMode: { allowed: true, instructions: \"Match the existing site surfaces ...\", scripts: false },\n});\n\nexport const GET = handler;\nexport const POST = handler;\nexport const DELETE = handler;\n```\n\n**The route path is fixed.** Puck's client calls `/api/puck/*` by convention and exposes only `host` (a different origin), so the file has to live exactly there.\n\n**That route spends money.** Every generation debits credit from the Puck Cloud account behind `PUCK_API_KEY`, billed to the account and not the caller. The handler refuses anything without an EmDash session (`locals.user`, which EmDash's auth middleware populates on public routes too, from the admin cookie that opened the editor) and anything missing the `X-EmDash-Request: 1` CSRF header the client attaches. A bearer token does not authenticate here. It also logs one line per generation with the user's email, because the Puck Cloud dashboard cannot see which EmDash user ran the prompt; pass `onFinish` to record it elsewhere.\n\n**Generation quality is config, not prompt.** `context` on the handler carries positioning and voice; component-level `ai.instructions` in your config encode placement, cardinality and cross-component references. `mediaField` is a `custom` field, which Puck AI cannot infer anything about, so it declares its own `ai.schema` and is told never to invent a media URL.\n\n### Design mode splits the public render path\n\nDesign mode invents new component types and stores them in the document at `root.props._dynamicConfig`. Rendering them needs `withDynamicConfig` from `@puckeditor/plugin-ai`, which is one bundle whose chat runtime does not tree-shake away from that one function: importing it into the ordinary island was measured at 608KB to 1.4MB on every public Puck page. So there are two islands, and the route picks per page:\n\n```tsx\n// src/puck/PuckPageDesigned.tsx\nimport { createPuckPageDesigned } from \"emdash-plugin-puck/render/designed\";\nimport { config } from \"./config\";\n\nexport default createPuckPageDesigned(config);\n```\n\n```astro\n---\nimport { hasDesignedComponents, parseLayout } from \"emdash-plugin-puck/render\";\nimport PuckPage from \"../puck/PuckPage\";\nimport PuckPageDesigned from \"../puck/PuckPageDesigned\";\nconst layout = parseLayout(entry.data.layout);\n---\n{hasDesignedComponents(layout)\n  ? <PuckPageDesigned client:load data={layout} />\n  : <PuckPage client:load data={layout} />}\n```\n\nWrite that choice as a ternary **in the markup**, never as a variable. Astro finds islands by statically matching `<Component client:* />`, so `const Island = cond ? A : B` with `<Island client:load />` type-checks, builds clean, and emits no client chunk for either. The page then server-renders correctly and silently never hydrates.\n\n## Theming\n\n`emdash-plugin-puck/theme.css` aliases Puck's global `--puck-*` tokens onto the EmDash admin's Kumo tokens, one declaration per token. Kumo's are `light-dark()` pairs keyed off the admin's `data-mode`, so the editor gets the admin's dark mode for free; Puck itself ships none. The sheet is unlayered on purpose: Puck declares its tokens inside `@layer puck-tokens`, and an unlayered rule beats a layered one at any specificity. That is the entire mechanism. Do not add an `@layer` or `!important` to it.\n\nIt is linked automatically, along with Puck's `no-external.css`, when the widget module loads. `no-external.css` rather than `puck.css` because the default sheet's first line is `@import \"https://rsms.me/inter/inter.css\"`, measured at 850-970ms of render blocking; the theme points `--puck-font-family` at the admin's own face anyway. Pass `adminStylesheets` to change the set.\n\nAll stylesheets are linked by URL at runtime rather than imported, on purpose. A static CSS import lands in the module graph of your admin entry, which imports your Puck config, which your public island imports too, and Astro emits a route's `<link>` tags from the whole reachable chunk graph. The editor's chrome ended up on every public page once. `?url` keeps the sheets out of every route's style graph, and they stay real document stylesheets, which is what `syncHostStyles` copies into the canvas.\n\n## optimizeDeps\n\nVite's dependency scanner crawls the server entry graph, but the Puck admin entry is only reachable through the virtual `emdash/admin-registry` module via an absolute `file://` URL, which the scanner cannot follow. A dependency discovered late gets optimised on a re-scan while the loaded admin chunk still asks for the old hash: Vite answers **504 Outdated Optimize Dep**, and the admin either hangs on \"Loading EmDash\" or shows \"Plugin widget error: Failed to fetch dynamically imported module\". It retries green and fails again on the next scan.\n\nPin `@puckeditor/core`, `@puckeditor/plugin-ai` if you use it, and **every bare dependency any of your blocks imports** in `vite.optimizeDeps.include`. Blocks have the same problem one level down: they are only reachable from your config, which the admin loads through that same unscannable entry.\n\n## Writing blocks\n\nThings the editor's iframe changes about ordinary React:\n\n- **`instanceof` is per-realm.** A library that validates DOM nodes with `container instanceof HTMLElement` (Mapbox does) sees an element owned by the iframe document while it was loaded in the parent window, and throws. Guard with `el.ownerDocument.defaultView !== window` and render a placeholder; that test also covers the block panel's preview iframe, and Puck 0.23 exposes no `isEditing` on render props.\n- **A Puck document is a flat list.** No block can open a wrapper that closes after a later block. Anything spanning sections (the `<main>` landmark, inter-section spacing, the page max-width) belongs in `root.render`. `<Render>` inserts an unclassed DropZone `<div>` between the root markup and the blocks, so child combinators do not reach them; use descendant selectors.\n- **Inline-editable copy is a React node in the editor.** Type such props `Editable` (exported from `emdash-plugin-puck/render`) and only ever render them. Never pass one to an attribute, test its truthiness, interpolate or compare it: `[object Object]` ships to the DOM, in the editor only, and survives a typecheck.\n- **The block panel renders your components bare.** Previews use `defaultProps` plus a stub `puck` prop, so a block that throws on missing data shows \"Preview unavailable\" rather than taking the panel down. Give every block sensible defaults.\n- **Props must be JSON-serialisable.** Icons are string keys resolved at render time, never components.\n\n## API\n\n| Export | From |\n| --- | --- |\n| `puckPlugin(options)` (default), `createPlugin` | `emdash-plugin-puck` |\n| `createPuckAdmin`, `createPuckCanvasField`, `createBlockPanel` | `emdash-plugin-puck/admin` |\n| `puckAi` | `emdash-plugin-puck/ai` |\n| `createPuckAiHandler` | `emdash-plugin-puck/ai/handler` |\n| `createPuckPage`, `parseLayout`, `hasDesignedComponents`, `isPuckData`, `EMPTY_DATA`, `withBoundaries`, `ErrorBoundary`, `BlockErrorBoundary`, `PageErrorBoundary`, `renderable`, `Editable` | `emdash-plugin-puck/render` |\n| `createPuckPageDesigned` | `emdash-plugin-puck/render/designed` |\n| `mediaField` | `emdash-plugin-puck/fields` |\n| `createBlocks`, `withLayout`, `Section`, the option lists and block prop types | `emdash-plugin-puck/blocks` |\n| the starter block styles | `emdash-plugin-puck/blocks.css` |\n| the admin theme | `emdash-plugin-puck/theme.css` |\n\n`createPuckAdmin` options: `config`, `emptyData`, `plugins`, `resolveConfig`, `canvas` (`stylesheets`, `css`, `colorScheme`, `unlockScroll`), `blockPanel` (preview styles, `previewWidth`, `previewScale`, or `false`), `adminStylesheets`, `overrides`, `labels`.\n\n## License\n\nMIT\n","readmeFilename":"README.md"}