Skip to content

Centralize editor defaults#605

Merged
siddharthvaddem merged 5 commits into
siddharthvaddem:mainfrom
EtienneLescot:codex/editor-defaults-ssot
May 23, 2026
Merged

Centralize editor defaults#605
siddharthvaddem merged 5 commits into
siddharthvaddem:mainfrom
EtienneLescot:codex/editor-defaults-ssot

Conversation

@EtienneLescot
Copy link
Copy Markdown
Collaborator

@EtienneLescot EtienneLescot commented May 18, 2026

Summary

  • centralize editor default values in a dedicated editorDefaults module
  • route editor history, user preferences, project normalization, settings panel, preview, and export UI fallbacks through the same defaults
  • add anti-drift tests covering history defaults, persisted preference defaults, and project fallback normalization

Why

Several editor defaults were repeated across UI state, props fallbacks, user preferences, and project persistence. That makes small behavior changes easy to miss in one layer. This PR keeps the behavior the same while making the default source clearer and easier to validate.

Validation

  • npm run lint
  • npm test
  • npm run build-vite
  • npm test -- editorDefaults projectPersistence

Note: npm run i18n:check currently fails on main with pre-existing locale drift unrelated to this PR; this refactor does not touch translations.

Summary by CodeRabbit

  • Refactor

    • Centralized editor defaults for layout, export/GIF settings, webcam, and cursor; unified fallback source dimensions used across editor, preview, and export flows.
  • New Features

    • Cursor can be configured to clip to video bounds.
    • Default preferences are now exported for external use.
    • Webcam capture now uses a zero-dimension sentinel when initiating native capture.
  • Tests

    • Added tests to ensure defaults remain consistent across editor and export pipelines.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ee5471ad-9b1c-4d6c-a512-450ff7572060

📥 Commits

Reviewing files that changed from the base of the PR and between 84b523d and 9eaae72.

📒 Files selected for processing (1)
  • src/hooks/useScreenRecorder.ts

📝 Walkthrough

Walkthrough

this pr centralizes scattered editor defaults into editorDefaults.ts, adds a cursor clipToBounds field, updates consumers and normalization to use the new defaults, replaces hardcoded 1920×1080 fallbacks, and adds tests asserting consistency.

Changes

Editor Defaults Consolidation

Layer / File(s) Summary
Centralized defaults module and cursor bounds extension
src/components/video-editor/editorDefaults.ts, src/components/video-editor/types.ts
Introduces typed constant presets for source/GIF dimensions, editor appearance/layout, webcam, cursor visuals (adds clipToBounds), export settings, and GIF settings.
Initial editor state and user preferences from defaults
src/hooks/useEditorHistory.ts, src/lib/userPreferences.ts
INITIAL_EDITOR_STATE and DEFAULT_PREFS now derive wallpaper, appearance, layout, and webcam defaults from the centralized settings instead of hardcoded literals.
Project persistence and normalization defaults
src/components/video-editor/projectPersistence.ts
normalizeProjectEditor and normalization logic now fall back to centralized appearance/layout/webcam/export/GIF defaults.
Component consumption of consolidated defaults
src/components/video-editor/VideoEditor.tsx, src/components/video-editor/VideoPlayback.tsx, src/components/video-editor/SettingsPanel.tsx, src/components/video-editor/CropControl.tsx
Components now import and use centralized defaults (cursor, export/GIF, layout, source dimensions); all hardcoded 1920×1080 fallbacks replaced with DEFAULT_SOURCE_DIMENSIONS.
Defaults consistency verification
src/components/video-editor/editorDefaults.test.ts
Adds tests asserting strict alignment between editor defaults, initial editor state, DEFAULT_PREFS, and normalization fallbacks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • siddharthvaddem

Poem

defaults once scattered, now corralled in a row,
no more 1920 ghosts stealing the show.
constants aligned, tests check the seams,
cursor now clipped for steadier dreams,
ship it quiet, tidy, lowkey clean.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main objective—centralizing editor defaults across the codebase.
Description check ✅ Passed The description covers all key sections: summary of changes, motivation/why, validation steps, and even notes on pre-existing issues. Well-structured and informative.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@EtienneLescot EtienneLescot changed the title [codex] Centralize editor defaults Centralize editor defaults May 18, 2026
@EtienneLescot EtienneLescot force-pushed the codex/editor-defaults-ssot branch from 165bbba to b36a32d Compare May 22, 2026 19:15
@EtienneLescot EtienneLescot marked this pull request as ready for review May 22, 2026 19:15
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
src/components/video-editor/editorDefaults.ts (1)

32-55: ⚡ Quick win

Make the shared default objects readonly too.

lowkey risky with SSOT constants: DEFAULT_EDITOR_APPEARANCE_SETTINGS, DEFAULT_EDITOR_LAYOUT_SETTINGS, DEFAULT_EXPORT_SETTINGS, and DEFAULT_GIF_SETTINGS are still mutable object literals. one accidental write in a consumer can mutate global defaults.

nit: cleaner + safer typing pattern
-export const DEFAULT_EDITOR_APPEARANCE_SETTINGS: {
-	shadowIntensity: number;
-	showBlur: boolean;
-	motionBlurAmount: number;
-	borderRadius: number;
-} = {
+export const DEFAULT_EDITOR_APPEARANCE_SETTINGS = {
 	shadowIntensity: 0,
 	showBlur: false,
 	motionBlurAmount: 0,
 	borderRadius: 0,
-};
+} as const satisfies {
+	shadowIntensity: number;
+	showBlur: boolean;
+	motionBlurAmount: number;
+	borderRadius: number;
+};
 
-export const DEFAULT_EDITOR_LAYOUT_SETTINGS: {
-	padding: number;
-	aspectRatio: AspectRatio;
-	cropRegion: typeof DEFAULT_CROP_REGION;
-	wallpaper: string;
-} = {
+export const DEFAULT_EDITOR_LAYOUT_SETTINGS = {
 	padding: 50,
 	aspectRatio: "16:9",
 	cropRegion: DEFAULT_CROP_REGION,
 	wallpaper: DEFAULT_WALLPAPER,
-};
+} as const satisfies {
+	padding: number;
+	aspectRatio: AspectRatio;
+	cropRegion: typeof DEFAULT_CROP_REGION;
+	wallpaper: string;
+};
 
-export const DEFAULT_EXPORT_SETTINGS: {
-	quality: ExportQuality;
-	format: ExportFormat;
-} = {
+export const DEFAULT_EXPORT_SETTINGS = {
 	quality: "good",
 	format: "mp4",
-};
+} as const satisfies {
+	quality: ExportQuality;
+	format: ExportFormat;
+};
 
-export const DEFAULT_GIF_SETTINGS: {
-	frameRate: GifFrameRate;
-	loop: boolean;
-	sizePreset: GifSizePreset;
-	outputDimensions: typeof DEFAULT_GIF_OUTPUT_DIMENSIONS;
-} = {
+export const DEFAULT_GIF_SETTINGS = {
 	frameRate: 15,
 	loop: true,
 	sizePreset: "medium",
 	outputDimensions: DEFAULT_GIF_OUTPUT_DIMENSIONS,
-};
+} as const satisfies {
+	frameRate: GifFrameRate;
+	loop: boolean;
+	sizePreset: GifSizePreset;
+	outputDimensions: typeof DEFAULT_GIF_OUTPUT_DIMENSIONS;
+};

Also applies to: 77-95

🤖 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 `@src/components/video-editor/editorDefaults.ts` around lines 32 - 55, The
default settings objects (DEFAULT_EDITOR_APPEARANCE_SETTINGS,
DEFAULT_EDITOR_LAYOUT_SETTINGS, DEFAULT_EXPORT_SETTINGS, DEFAULT_GIF_SETTINGS)
are mutable and should be made readonly so consumers can't accidentally mutate
global defaults; update their declarations to use an immutable type (e.g.,
Readonly<...> or the equivalent readonly property types) and produce immutable
runtime values (use Object.freeze(...) or the TypeScript "as const" pattern) and
ensure related defaults referenced inside them (like DEFAULT_CROP_REGION,
DEFAULT_WALLPAPER) are also readonly/frozen so the entire object graph is
immutable.
src/components/video-editor/projectPersistence.ts (1)

487-490: ⚡ Quick win

Normalize export enums independently from current default values.

kinda subtle but lowkey risky: these checks currently preserve only a subset and rely on defaults to recover the rest. explicit full whitelists keep behavior stable even if defaults change later.

safer normalization (future-proof)
 		exportQuality:
-			editor.exportQuality === "medium" || editor.exportQuality === "source"
+			editor.exportQuality === "medium" ||
+			editor.exportQuality === "good" ||
+			editor.exportQuality === "source"
 				? editor.exportQuality
 				: DEFAULT_EXPORT_SETTINGS.quality,
-		exportFormat: editor.exportFormat === "gif" ? "gif" : DEFAULT_EXPORT_SETTINGS.format,
+		exportFormat:
+			editor.exportFormat === "gif" || editor.exportFormat === "mp4"
+				? editor.exportFormat
+				: DEFAULT_EXPORT_SETTINGS.format,
🤖 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 `@src/components/video-editor/projectPersistence.ts` around lines 487 - 490,
The current ternary normalization for exportQuality and exportFormat relies on
DEFAULT_EXPORT_SETTINGS to recover invalid values; instead implement explicit
whitelists so valid enums are normalized independently of defaults. Replace the
exportQuality ternary that checks only "medium" and "source" with a whitelist
check against an allowedQualities array (e.g., allowedQualities =
['low','medium','high','source']) and fall back to
DEFAULT_EXPORT_SETTINGS.quality only if the value is not in the whitelist; do
the same for exportFormat using an allowedFormats whitelist (e.g.,
['mp4','gif','webm']) and reference editor.exportQuality, editor.exportFormat
and DEFAULT_EXPORT_SETTINGS in the implementation to ensure future default
changes won’t alter allowed values.
src/hooks/useEditorHistory.ts (1)

18-18: ⚡ Quick win

Route cropRegion through the centralized layout defaults too.

right now this is the one remaining direct default in this initializer, so drift can sneak in later if layout defaults evolve.

small consistency fix
-import { DEFAULT_CROP_REGION } from "`@/components/video-editor/types`";
@@
-	cropRegion: DEFAULT_CROP_REGION,
+	cropRegion: DEFAULT_EDITOR_LAYOUT_SETTINGS.cropRegion,

Also applies to: 47-47

🤖 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 `@src/hooks/useEditorHistory.ts` at line 18, The hook useEditorHistory
currently imports and uses DEFAULT_CROP_REGION directly; change it to obtain
cropRegion from the centralized layout defaults instead so defaults don't drift.
In the initializer inside useEditorHistory replace the direct use/import of
DEFAULT_CROP_REGION with the value from the shared layout defaults API (e.g.,
call or import that provides the default layout object and read its cropRegion)
so the hook uses the centralized default consistently (update any references to
DEFAULT_CROP_REGION in useEditorHistory to use the layoutDefaults.cropRegion).
🤖 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 `@src/components/video-editor/editorDefaults.ts`:
- Around line 32-55: The default settings objects
(DEFAULT_EDITOR_APPEARANCE_SETTINGS, DEFAULT_EDITOR_LAYOUT_SETTINGS,
DEFAULT_EXPORT_SETTINGS, DEFAULT_GIF_SETTINGS) are mutable and should be made
readonly so consumers can't accidentally mutate global defaults; update their
declarations to use an immutable type (e.g., Readonly<...> or the equivalent
readonly property types) and produce immutable runtime values (use
Object.freeze(...) or the TypeScript "as const" pattern) and ensure related
defaults referenced inside them (like DEFAULT_CROP_REGION, DEFAULT_WALLPAPER)
are also readonly/frozen so the entire object graph is immutable.

In `@src/components/video-editor/projectPersistence.ts`:
- Around line 487-490: The current ternary normalization for exportQuality and
exportFormat relies on DEFAULT_EXPORT_SETTINGS to recover invalid values;
instead implement explicit whitelists so valid enums are normalized
independently of defaults. Replace the exportQuality ternary that checks only
"medium" and "source" with a whitelist check against an allowedQualities array
(e.g., allowedQualities = ['low','medium','high','source']) and fall back to
DEFAULT_EXPORT_SETTINGS.quality only if the value is not in the whitelist; do
the same for exportFormat using an allowedFormats whitelist (e.g.,
['mp4','gif','webm']) and reference editor.exportQuality, editor.exportFormat
and DEFAULT_EXPORT_SETTINGS in the implementation to ensure future default
changes won’t alter allowed values.

In `@src/hooks/useEditorHistory.ts`:
- Line 18: The hook useEditorHistory currently imports and uses
DEFAULT_CROP_REGION directly; change it to obtain cropRegion from the
centralized layout defaults instead so defaults don't drift. In the initializer
inside useEditorHistory replace the direct use/import of DEFAULT_CROP_REGION
with the value from the shared layout defaults API (e.g., call or import that
provides the default layout object and read its cropRegion) so the hook uses the
centralized default consistently (update any references to DEFAULT_CROP_REGION
in useEditorHistory to use the layoutDefaults.cropRegion).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c14c159d-b24b-4e51-ab3c-168c8e30cdf0

📥 Commits

Reviewing files that changed from the base of the PR and between 9f7f498 and b36a32d.

📒 Files selected for processing (10)
  • src/components/video-editor/CropControl.tsx
  • src/components/video-editor/SettingsPanel.tsx
  • src/components/video-editor/VideoEditor.tsx
  • src/components/video-editor/VideoPlayback.tsx
  • src/components/video-editor/editorDefaults.test.ts
  • src/components/video-editor/editorDefaults.ts
  • src/components/video-editor/projectPersistence.ts
  • src/components/video-editor/types.ts
  • src/hooks/useEditorHistory.ts
  • src/lib/userPreferences.ts

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@src/components/video-editor/SettingsPanel.tsx`:
- Around line 82-84: Remove the unused DEFAULT_WEBCAM_SIZE_PRESET symbol from
the import/destructuring in SettingsPanel (the list containing
MAX_PLAYBACK_SPEED, DEFAULT_WEBCAM_SIZE_PRESET, MAX_ZOOM_SCALE) so the file no
longer imports or references DEFAULT_WEBCAM_SIZE_PRESET; leave
MAX_PLAYBACK_SPEED and MAX_ZOOM_SCALE intact and ensure there are no other
references to DEFAULT_WEBCAM_SIZE_PRESET elsewhere in this file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 78aa6c6b-57fd-44df-92a1-672201571586

📥 Commits

Reviewing files that changed from the base of the PR and between b36a32d and b8e78cc.

📒 Files selected for processing (1)
  • src/components/video-editor/SettingsPanel.tsx

Comment thread src/components/video-editor/SettingsPanel.tsx Outdated
Removes MAX_PLAYBACK_SPEED and DEFAULT_WEBCAM_SIZE_PRESET (TS6133) and
runs biome's organize-imports to satisfy the Lint check.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
siddharthvaddem and others added 2 commits May 22, 2026 20:00
PR siddharthvaddem#600 (now on main) removed WEBCAM_TARGET_WIDTH/HEIGHT and switched
this call site to width/height: 0 so the native helper picks the
camera's native dimensions. Align this branch with that so CI's
fresh PR-merge stops erroring on the undeclared identifiers.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@siddharthvaddem siddharthvaddem merged commit dfd9613 into siddharthvaddem:main May 23, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants