-
Notifications
You must be signed in to change notification settings - Fork 974
feat(plugins): add @emdash-cms/plugin-field-kit #702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "@emdash-cms/plugin-field-kit": minor | ||
| "emdash": patch | ||
| "@emdash-cms/admin": patch | ||
| --- | ||
|
|
||
| Adds `@emdash-cms/plugin-field-kit` — composable field widgets for `json` fields. Four widgets (`object-form`, `list`, `grid`, `tags`) are configured entirely through seed `options` so site builders don't need to write React to get a usable editing UI. Widgets store clean JSON (no nesting, no mutation of shape), so removing the plugin leaves valid data in the database. See discussion #571 for background. | ||
|
|
||
| Widens `FieldDescriptor.options` to `Array<{ value: string; label: string }> | Record<string, unknown>` so plugin widgets can accept arbitrary widget config (not only enum choices). The array shape for `select` / `multiSelect` continues to work unchanged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # @emdash-cms/plugin-field-kit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| { | ||
| "name": "@emdash-cms/plugin-field-kit", | ||
| "version": "0.0.0", | ||
| "description": "Composable field widgets for EmDash CMS — object forms, lists, grids, and tag inputs for json fields", | ||
| "type": "module", | ||
| "main": "src/index.ts", | ||
| "exports": { | ||
| ".": "./src/index.ts", | ||
| "./admin": "./src/admin.tsx" | ||
| }, | ||
| "files": [ | ||
| "src" | ||
| ], | ||
| "keywords": [ | ||
| "emdash", | ||
| "cms", | ||
| "plugin", | ||
| "field-widget", | ||
| "json" | ||
| ], | ||
| "author": "Filip Ilic", | ||
| "license": "MIT", | ||
| "peerDependencies": { | ||
| "@cloudflare/kumo": "^1.0.0", | ||
| "@phosphor-icons/react": "^2.1.10", | ||
| "emdash": "workspace:>=0.1.0", | ||
| "react": "^18.0.0 || ^19.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@testing-library/react": "^16.3.0", | ||
| "@types/react": "catalog:", | ||
| "@types/react-dom": "catalog:", | ||
| "@vitejs/plugin-react": "^4.6.0", | ||
| "jsdom": "^26.1.0", | ||
| "react": "catalog:", | ||
| "react-dom": "catalog:", | ||
| "vitest": "catalog:" | ||
| }, | ||
| "scripts": { | ||
| "test": "vitest run", | ||
| "typecheck": "tsgo --noEmit" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/emdash-cms/emdash.git", | ||
| "directory": "packages/plugins/field-kit" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { Grid } from "./widgets/grid"; | ||
| import { List } from "./widgets/list"; | ||
| import { ObjectForm } from "./widgets/object-form"; | ||
| import { Tags } from "./widgets/tags"; | ||
|
|
||
| export const fields = { | ||
| "object-form": ObjectForm, | ||
| list: List, | ||
| grid: Grid, | ||
| tags: Tags, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /** | ||
| * Field Kit Plugin for EmDash CMS | ||
| * | ||
| * Provides composable field widgets for `json` fields configured entirely | ||
| * through seed options — no React code required from site builders. | ||
| * | ||
| * Ships four widgets: | ||
| * - object-form — inline form for flat JSON objects | ||
| * - list — ordered array editor with add/remove/reorder | ||
| * - grid — rows × columns matrix with configurable cell type | ||
| * - tags — free-form tag/chip input for string arrays | ||
| * | ||
| * Usage in astro.config.mjs: | ||
| * import { fieldKitPlugin } from "@emdash-cms/plugin-field-kit"; | ||
| * emdash({ plugins: [fieldKitPlugin()] }); | ||
| * | ||
| * Usage in a seed field: | ||
| * { | ||
| * "slug": "ingredients", | ||
| * "type": "json", | ||
| * "widget": "field-kit:list", | ||
| * "options": { "fields": [...], "summary": "{{name}}" } | ||
| * } | ||
| */ | ||
|
|
||
| import type { PluginDescriptor } from "emdash"; | ||
| import { definePlugin } from "emdash"; | ||
|
|
||
| const PLUGIN_ID = "field-kit"; | ||
| const PLUGIN_VERSION = "0.0.0"; | ||
|
|
||
| /** | ||
| * Create the field-kit plugin instance. | ||
| * Called by the virtual module system at runtime. | ||
| */ | ||
| export function createPlugin() { | ||
| return definePlugin({ | ||
| id: PLUGIN_ID, | ||
| version: PLUGIN_VERSION, | ||
| admin: { | ||
| entry: "@emdash-cms/plugin-field-kit/admin", | ||
| fieldWidgets: [ | ||
| { name: "object-form", label: "Object form", fieldTypes: ["json"] }, | ||
| { name: "list", label: "List", fieldTypes: ["json"] }, | ||
| { name: "grid", label: "Grid", fieldTypes: ["json"] }, | ||
| { name: "tags", label: "Tags input", fieldTypes: ["json"] }, | ||
| ], | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| export default createPlugin; | ||
|
|
||
| /** | ||
| * Create a plugin descriptor for use in emdash config. | ||
| */ | ||
| export function fieldKitPlugin(): PluginDescriptor { | ||
| return { | ||
| id: PLUGIN_ID, | ||
| version: PLUGIN_VERSION, | ||
| entrypoint: "@emdash-cms/plugin-field-kit", | ||
| options: {}, | ||
| adminEntry: "@emdash-cms/plugin-field-kit/admin", | ||
| }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FieldDescriptor.optionsis widened here to allow plugin widgets to receive arbitrary config objects, but the admin-side manifest type (packages/admin/src/lib/api/client.ts→AdminManifest.collections[].fields[].options) is still typed as an enum array only. This creates a type mismatch and makes it easy for future code to accidentally treat plugin widget options asArrayeverywhere. Consider updating the shared manifest/client types to match this union so the admin consumes plugin widget config safely and consistently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Widened
AdminManifest.collections[].fields[].optionsinpackages/admin/src/lib/api/client.tsto match the union I landed inFieldDescriptor.options—Array<{ value: string; label: string }> | Record<string, unknown>. Good catch; I widened two of the three sites originally and this was the one I missed.