Skip to content

feat(root-cms): add array item defaults via itemDefault#946

Open
stevenle wants to merge 1 commit intomainfrom
codex/add-default-value-option-for-array-fields
Open

feat(root-cms): add array item defaults via itemDefault#946
stevenle wants to merge 1 commit intomainfrom
codex/add-default-value-option-for-array-fields

Conversation

@stevenle
Copy link
Member

@stevenle stevenle commented Mar 3, 2026

Motivation

  • Provide schema authors a way to initialize newly added array items with a configured default object so CMS users get sensible starting values.
  • Ensure new array items are independent objects (cloned) to avoid shared references.

Description

  • Add a new itemDefault?: Record<string, any> option to ArrayField in packages/root-cms/core/schema.ts so schema.array() can accept an item default.
  • Update the DocEditor array logic in packages/root-cms/ui/components/DocEditor/DocEditor.tsx to accept and propagate a defaultValue for array actions and to apply structuredClone(action.defaultValue || {}) when inserting new items for add, insertBefore, and insertAfter so each item receives its own cloned default object.
  • Extend the TypeScript action interfaces (ArrayAdd, ArrayInsertBefore, ArrayInsertAfter) to carry the defaultValue and pass field.itemDefault || {} when dispatching those actions.
  • Add a changeset for @blinkk/root-cms describing the feature.

Testing

  • No automated tests were executed for this change (tests were intentionally not run per instructions).

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant