feat: add theme editor to local-editor#1212
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThis PR introduces an editor mode selection system (layout vs. theme) in the local editor, refactors theme style tag management to ensure tag creation before modification, adds themeEntityId computation for template metadata, and improves localStorage resilience. The mode selection is driven by a URL query parameter and controls whether the editor displays layout or theme editing capabilities. Theme application now uses a helper to guarantee the style tag exists before updating both the main document and iframe, addressing potential issues with style injection timing. Template metadata generation derives a stable themeEntityId from themeScopeKey, enabling consistent theme entity identification across template types. Suggested labels
Suggested reviewers
Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
benlife5
left a comment
There was a problem hiding this comment.
I'm good with this if this is more correct/more extensible, but it might be possible to just put applyTheme(document, relativePrefixToRoot, defaultThemeConfig), in the local-editor getHeadConfig if we only care about the defaults for now
jwartofsky-yext
left a comment
There was a problem hiding this comment.
nitpicks, but otherwise lgtm
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/visual-editor/src/internal/types/templateMetadata.test.ts (1)
39-51: ⚡ Quick winConsider adding test cases for edge scenarios.
The current test validates the core behavior (same scope key → same ID), but could be more comprehensive. Consider adding tests for:
themeScopeKey: undefined→themeEntityId: undefined- Different scope keys produce different IDs
- Empty string handling
🧪 Proposed additional test cases
}); + + it("returns undefined themeEntityId when themeScopeKey is not provided", () => { + const metadata = generateTemplateMetadata(undefined, { + templateId: "directory", + }); + + expect(metadata.themeEntityId).toBeUndefined(); + }); + + it("produces different themeEntityId for different scope keys", () => { + const metadata1 = generateTemplateMetadata(undefined, { + templateId: "directory", + themeScopeKey: "scope-a", + }); + const metadata2 = generateTemplateMetadata(undefined, { + templateId: "directory", + themeScopeKey: "scope-b", + }); + + expect(metadata1.themeEntityId).toBeDefined(); + expect(metadata2.themeEntityId).toBeDefined(); + expect(metadata1.themeEntityId).not.toBe(metadata2.themeEntityId); + }); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/visual-editor/src/internal/types/templateMetadata.test.ts` around lines 39 - 51, Add unit tests covering edge cases for generateTemplateMetadata: (1) verify that when themeScopeKey is undefined the returned themeEntityId is undefined (use generateTemplateMetadata with templateId like "directory" and no themeScopeKey), (2) verify different themeScopeKey values produce different themeEntityId values (call generateTemplateMetadata twice with different themeScopeKey strings and assert IDs differ), and (3) verify handling of empty string themeScopeKey (pass themeScopeKey: "" and assert the resulting themeEntityId behavior—either undefined if intended or a stable ID if implementation treats "" as a valid scope). Ensure each case asserts on the themeEntityId property.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/visual-editor/src/internal/types/templateMetadata.test.ts`:
- Around line 39-51: Add unit tests covering edge cases for
generateTemplateMetadata: (1) verify that when themeScopeKey is undefined the
returned themeEntityId is undefined (use generateTemplateMetadata with
templateId like "directory" and no themeScopeKey), (2) verify different
themeScopeKey values produce different themeEntityId values (call
generateTemplateMetadata twice with different themeScopeKey strings and assert
IDs differ), and (3) verify handling of empty string themeScopeKey (pass
themeScopeKey: "" and assert the resulting themeEntityId behavior—either
undefined if intended or a stable ID if implementation treats "" as a valid
scope). Ensure each case asserts on the themeEntityId property.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 3dbc5711-9c52-477e-8076-abd471ed957b
📒 Files selected for processing (10)
packages/visual-editor/src/editor/types.tspackages/visual-editor/src/internal/hooks/useMessageReceivers.test.tspackages/visual-editor/src/internal/types/templateMetadata.test.tspackages/visual-editor/src/internal/types/templateMetadata.tspackages/visual-editor/src/local-editor/LocalEditorControls.tsxpackages/visual-editor/src/local-editor/LocalEditorShell.tsxpackages/visual-editor/src/local-editor/selection.tspackages/visual-editor/src/local-editor/types.tspackages/visual-editor/src/utils/applyTheme.test.tspackages/visual-editor/src/vite-plugin/registry/registryTemplateGenerator.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- packages/visual-editor/src/vite-plugin/registry/registryTemplateGenerator.test.ts
- packages/visual-editor/src/internal/hooks/useMessageReceivers.test.ts
- packages/visual-editor/src/editor/types.ts
- packages/visual-editor/src/utils/applyTheme.test.ts
auto-screenshot-update: true
…visual-editor into local-editor-default-theme
auto-screenshot-update: true
Updated so now the whole theme editor is accessible in the local editor. |
…visual-editor into local-editor-default-theme
auto-screenshot-update: true
10ca4e0
into
2026-custom-components-templates
This adds the full theme editor within local-editor, allowing developers to customize theme variables and more easily test newly generated built-in templates that use brand styles rather than hardcoded values.
There is now a button to the right of the template selector that toggles between the layout editor and theme editor.