Skip to content

feat(template-builder): Cake Equity fixes — lockMode, fieldColors, reactive mode (SD-1866, SD-883, SD-2406)#2727

Merged
caio-pizzol merged 15 commits intostablefrom
caio/cherry-pick-cake-equity-fixes-to-stable
Apr 6, 2026
Merged

feat(template-builder): Cake Equity fixes — lockMode, fieldColors, reactive mode (SD-1866, SD-883, SD-2406)#2727
caio-pizzol merged 15 commits intostablefrom
caio/cherry-pick-cake-equity-fixes-to-stable

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

Cherry-pick of #2721, #2724, #2726 to stable for release.

lockMode (SD-1866)

  • lockMode prop on field definitions + defaultLockMode on component
  • Lock mode selector in field creation form (simple "Locked" checkbox → contentLocked)
  • Lock badge in sidebar field list
  • areTemplateFieldsEqual includes lockMode

fieldColors (SD-883)

  • fieldColors prop generates scoped CSS for field type colors
  • Sidebar/menu badges match document colors dynamically
  • No manual CSS import needed — field-types.css still available as fallback
  • Correct block label selector, color-mix() for non-hex support

Reactive mode + refresh (SD-2406)

  • Mode changes (edit ↔ view) no longer destroy/recreate the editor
  • pendingModeRef queues mode changes during async init
  • refresh() method for re-discovering fields after async data delivery

Unblocks IT-754, IT-755, IT-758

SuperDoc core already enforces SDT lock modes (SD-1616), but Template
Builder never passed lockMode to the editor commands. This adds:

- LockMode type and lockMode prop on FieldDefinition / TemplateField
- defaultLockMode prop on SuperDocTemplateBuilderProps
- lockMode threading through insertFieldInternal, handleSelectExisting,
  and handleMenuSelect
- lockMode read-back in getTemplateFieldsFromEditor

Closes SD-1866
areTemplateFieldsEqual omitted lockMode, so lock-only changes were
silently dropped by discoverFields. Also tightens the lockMode spread
guard from truthiness to nullish check for consistency with the ??
resolution above.
Documents field locking in configuration guide and API reference.
Adds a dropdown to the default FieldMenu create form so users can
set a lock mode when creating new fields. Options: No lock, Unlocked,
Container locked, Content locked, Fully locked.
- deleteField no longer force-removes locked fields from state when
  the editor command is rejected by the lock plugin
- FieldList sidebar shows a lock icon for fields with active lock modes
- Revert lock guard in deleteField — template authors can always
  delete fields regardless of lock mode
- Replace 5-option lock dropdown with a simple "Locked" checkbox
  that maps to contentLocked
- Full LockMode type still available for programmatic use
Focus on contentLocked as the default, remove the 4-mode table,
clarify that locking only affects end users not template authors.
Consumers can now pass a `fieldColors` prop to color-code fields by
type in both the document and sidebar — no CSS import needed.

- Generates scoped CSS from fieldColors and injects into <head>
- Dynamic sidebar/menu badge colors via updated getFieldTypeStyle
- Removes need for manual field-types.css import (still available)
- Updates demo to use fieldColors instead of CSS variable overrides
- Documents fieldColors in configuration guide and API reference

Closes SD-883
- Fix block label selector: use .superdoc-structured-content__label
  (not __block__label) to match actual DOM
- Fix non-hex color support: use color-mix() instead of appending '1a'
- Fix partial fieldColors: only generate default rule when owner key
  exists, preventing unrelated fields from being recolored
- Simplify style injection: compute CSS in useMemo directly, remove
  JSON stringify/parse round-trip
- Extract buildColorRules helper to deduplicate CSS template
- Add 11 unit tests for getFieldTypeStyle and generateFieldColorCSS
- Remove document.mode from init effect deps so mode changes don't
  destroy and recreate the editor (no more scroll jump / content flash)
- Add separate useEffect that calls setDocumentMode() imperatively,
  following the same pattern as the React wrapper
- Add refresh() method to the imperative handle for re-discovering
  fields after async data delivery
- Document refresh() in API reference

Closes SD-2406
If document.mode changes while SuperDoc is still loading, the change
is queued and applied once handleReady fires. Follows the same
pendingModeRef pattern as the React wrapper.
- Remove redundant prevModeRef — useEffect dep array handles this
- Clear pendingModeRef in init cleanup to prevent stale mode on re-init
- Clear pendingModeRef when applying mode directly
- Extract applyDocumentMode helper to centralize the as-any cast
@caio-pizzol caio-pizzol self-assigned this Apr 6, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 17c4390a21

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

When the "Locked" checkbox is unchecked, emit lockMode: 'unlocked'
instead of omitting it, so it correctly overrides defaultLockMode.
@caio-pizzol caio-pizzol merged commit d2a012a into stable Apr 6, 2026
3 checks passed
@caio-pizzol caio-pizzol deleted the caio/cherry-pick-cake-equity-fixes-to-stable branch April 6, 2026 21:17
@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot bot commented Apr 6, 2026

🎉 This PR is included in template-builder v1.4.0

The release is available on GitHub release

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant