feat(template-builder): Cake Equity fixes — lockMode, fieldColors, reactive mode (SD-1866, SD-883, SD-2406)#2727
Merged
caio-pizzol merged 15 commits intostablefrom Apr 6, 2026
Conversation
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
There was a problem hiding this comment.
💡 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.
Contributor
|
🎉 This PR is included in template-builder v1.4.0 The release is available on GitHub release |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Cherry-pick of #2721, #2724, #2726 to stable for release.
lockMode (SD-1866)
lockModeprop on field definitions +defaultLockModeon componentcontentLocked)areTemplateFieldsEqualincludeslockModefieldColors (SD-883)
fieldColorsprop generates scoped CSS for field type colorsfield-types.cssstill available as fallbackcolor-mix()for non-hex supportReactive mode + refresh (SD-2406)
pendingModeRefqueues mode changes during async initrefresh()method for re-discovering fields after async data deliveryUnblocks IT-754, IT-755, IT-758