Skip to content

[Grida Canvas] RC (daily) #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2025
Merged

[Grida Canvas] RC (daily) #374

merged 1 commit into from
May 31, 2025

Conversation

softmarshmallow
Copy link
Member

@softmarshmallow softmarshmallow commented May 31, 2025

  • Fix Value change on commit (side controls)

Summary by CodeRabbit

  • New Features
    • Introduced a new numeric input component with enhanced keyboard support, value commit handling, and special "mixed" state display.
  • Refactor
    • Updated all relevant controls to use the new numeric input component, improving consistency and input handling across the UI.
    • Standardized event callbacks to use onValueCommit instead of onValueChange for numeric inputs.
  • Bug Fixes
    • Improved reliability of numeric input handling, including better support for keyboard interactions and value validation.
  • Chores
    • Removed deprecated numeric input components and related code.

Copy link

codesandbox bot commented May 31, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

vercel bot commented May 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
grida ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2025 7:38am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
code ⬜️ Ignored (Inspect) May 31, 2025 7:38am
legacy ⬜️ Ignored (Inspect) May 31, 2025 7:38am
backgrounds ⬜️ Skipped (Inspect) May 31, 2025 7:38am
blog ⬜️ Skipped (Inspect) May 31, 2025 7:38am
docs ⬜️ Skipped (Inspect) May 31, 2025 7:38am
viewer ⬜️ Skipped (Inspect) May 31, 2025 7:38am

Copy link

coderabbitai bot commented May 31, 2025

Walkthrough

This update replaces all usages of the PropertyNumber numeric input component with a new, more specialized InputPropertyNumber component throughout the codebase. Numeric property controls now use commit-based value handling (onValueCommit) instead of immediate change events (onValueChange). Several component signatures and event handler props are updated accordingly, and a new PropertyInputContainer is introduced for consistent UI styling.

Changes

File(s) Change Summary
editor/scaffolds/sidecontrol/controls/box-shadow.tsx
.../font-size.tsx
.../letter-spacing.tsx
.../line-height.tsx
.../rotate.tsx
.../stroke-width.tsx
.../opacity.tsx
Replaced PropertyNumber with InputPropertyNumber; updated event handlers to use onValueCommit and added mode props.
editor/scaffolds/sidecontrol/controls/corner-radius.tsx Refactored to use InputPropertyNumber with mode="fixed"; updated callback prop to onValueCommit; adjusted subcomponent logic and signatures.
editor/scaffolds/sidecontrol/controls/gap.tsx
.../maxlength.tsx
.../padding.tsx
Switched to InputPropertyNumber with mode="fixed"; replaced onValueChange with onValueCommit.
editor/scaffolds/sidecontrol/controls/gradient.tsx Replaced PropertyNumber with InputPropertyNumber for angle input; updated handler to onValueCommit.
editor/scaffolds/sidecontrol/controls/length-percentage.tsx Refactored input logic into new __Input component; switched to InputPropertyNumber; unified onCommit handling.
editor/scaffolds/sidecontrol/controls/positioning.tsx Replaced all Input usages with InputPropertyNumber for numeric constraints; removed manual parsing logic.
editor/scaffolds/sidecontrol/sidecontrol-node-selection.tsx Updated all numeric control handlers from onValueChange to onValueCommit.
editor/scaffolds/sidecontrol/ui/index.tsx Removed PropertyNumber and related types; added new PropertyInputContainer component for input styling.
editor/scaffolds/sidecontrol/ui/number.tsx Added new InputPropertyNumber component with advanced numeric input features and commit/change distinction.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant InputPropertyNumber
    participant ParentComponent

    User->>InputPropertyNumber: Types or changes number
    InputPropertyNumber->>ParentComponent: onValueChange (immediate, if in auto mode)
    User->>InputPropertyNumber: Presses Enter/Arrow or blurs input
    InputPropertyNumber->>ParentComponent: onValueCommit (committed value)
Loading

Poem

A hop, a skip, a leap ahead,
Our numbers now commit instead!
With inputs neat and handlers new,
The codebase shines in streamlined hue.
No more parsing, no more fuss—
Just tap and type, commit with us!
🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@softmarshmallow softmarshmallow changed the title [Grida Canvas] RC [Grida Canvas] RC (daily) May 31, 2025
@softmarshmallow softmarshmallow marked this pull request as ready for review May 31, 2025 08:00
Copy link

@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

🧹 Nitpick comments (2)
editor/scaffolds/sidecontrol/ui/number.tsx (1)

162-162: Type assertions are necessary but consider defensive checks.

While the discriminated union makes these type assertions safe, consider adding runtime checks for extra safety in development mode.

+// Add development-time safety check
+if (process.env.NODE_ENV === 'development') {
+  if (mode === "auto" && typeof onValueCommit !== 'function') {
+    console.warn('onValueCommit should be provided in auto mode');
+  }
+}

Also applies to: 168-168, 231-231, 237-237, 286-286, 292-292

editor/scaffolds/sidecontrol/controls/opacity.tsx (1)

42-45: Consider event handling consistency between input and slider

The slider now only calls onValueCommit while the input field calls both onValueChange and onValueCommit. This might create inconsistent behavior if the parent component expects live updates (onValueChange) from both controls.

Consider whether the slider should also call onValueChange for consistency, or if the commit-only approach is intentionally different for slider interactions.

If both should behave consistently for live updates:

-            // use commit for slider
-            onValueCommit?.({ type: "set", value });
+            onValueChange?.({ type: "set", value });
+            onValueCommit?.({ type: "set", value });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f6b297c and 6601382.

📒 Files selected for processing (17)
  • editor/scaffolds/sidecontrol/controls/box-shadow.tsx (4 hunks)
  • editor/scaffolds/sidecontrol/controls/corner-radius.tsx (5 hunks)
  • editor/scaffolds/sidecontrol/controls/font-size.tsx (1 hunks)
  • editor/scaffolds/sidecontrol/controls/gap.tsx (1 hunks)
  • editor/scaffolds/sidecontrol/controls/gradient.tsx (2 hunks)
  • editor/scaffolds/sidecontrol/controls/length-percentage.tsx (4 hunks)
  • editor/scaffolds/sidecontrol/controls/letter-spacing.tsx (1 hunks)
  • editor/scaffolds/sidecontrol/controls/line-height.tsx (1 hunks)
  • editor/scaffolds/sidecontrol/controls/maxlength.tsx (1 hunks)
  • editor/scaffolds/sidecontrol/controls/opacity.tsx (3 hunks)
  • editor/scaffolds/sidecontrol/controls/padding.tsx (2 hunks)
  • editor/scaffolds/sidecontrol/controls/positioning.tsx (3 hunks)
  • editor/scaffolds/sidecontrol/controls/rotate.tsx (1 hunks)
  • editor/scaffolds/sidecontrol/controls/stroke-width.tsx (1 hunks)
  • editor/scaffolds/sidecontrol/sidecontrol-node-selection.tsx (13 hunks)
  • editor/scaffolds/sidecontrol/ui/index.tsx (2 hunks)
  • editor/scaffolds/sidecontrol/ui/number.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (6)
editor/scaffolds/sidecontrol/controls/letter-spacing.tsx (3)
editor/scaffolds/sidecontrol/controls/utils/types.ts (1)
  • TMixed (3-3)
editor/grida-canvas/index.ts (1)
  • NumberChange (1815-1815)
editor/scaffolds/sidecontrol/ui/number.tsx (1)
  • InputPropertyNumber (128-298)
editor/scaffolds/sidecontrol/controls/stroke-width.tsx (3)
editor/scaffolds/sidecontrol/controls/utils/types.ts (1)
  • TMixed (3-3)
editor/grida-canvas/index.ts (1)
  • NumberChange (1815-1815)
editor/scaffolds/sidecontrol/ui/number.tsx (1)
  • InputPropertyNumber (128-298)
editor/scaffolds/sidecontrol/controls/positioning.tsx (2)
editor/scaffolds/sidecontrol/ui/number.tsx (1)
  • InputPropertyNumber (128-298)
editor/components/lib/utils/index.ts (1)
  • cn (4-6)
editor/scaffolds/sidecontrol/controls/line-height.tsx (3)
editor/scaffolds/sidecontrol/controls/utils/types.ts (1)
  • TMixed (3-3)
editor/grida-canvas/index.ts (1)
  • NumberChange (1815-1815)
editor/scaffolds/sidecontrol/ui/number.tsx (1)
  • InputPropertyNumber (128-298)
editor/scaffolds/sidecontrol/ui/index.tsx (1)
editor/components/lib/utils/index.ts (1)
  • cn (4-6)
editor/scaffolds/sidecontrol/controls/corner-radius.tsx (4)
packages/grida-canvas-schema/grida.ts (1)
  • IRectangleCorner (1072-1074)
editor/scaffolds/sidecontrol/ui/number.tsx (1)
  • InputPropertyNumber (128-298)
packages/grida-canvas-cg/lib.ts (1)
  • CornerRadius4 (428-428)
editor/scaffolds/sidecontrol/ui/index.tsx (1)
  • PropertyInputContainer (50-66)
🔇 Additional comments (39)
editor/scaffolds/sidecontrol/controls/stroke-width.tsx (4)

3-3: LGTM! Clean refactor to new InputPropertyNumber component.

The changes correctly replace PropertyNumber with InputPropertyNumber and add the onValueCommit callback for commit-based value handling. The component interface and usage are consistent with the broader refactor pattern.

Also applies to: 8-8, 12-12, 15-15, 21-21


3-3: LGTM: Import updated correctly

The import has been properly updated to use the new InputPropertyNumber component.


8-8: LGTM: Props interface updated consistently

The addition of the optional onValueCommit prop maintains backward compatibility while enabling the new commit-based event handling pattern.

Also applies to: 12-12


15-22: LGTM: Component usage follows the new pattern

The component correctly uses InputPropertyNumber with both onValueChange and onValueCommit handlers. The default mode="auto" is appropriate for this stroke width control, providing both live updates and commit events.

editor/scaffolds/sidecontrol/controls/box-shadow.tsx (3)

19-19: LGTM! Consistent usage of InputPropertyNumber with fixed mode.

The refactor correctly uses mode="fixed" for all box shadow numeric inputs, which is appropriate since these components handle direct numeric values rather than change objects. The event handlers properly handle the numeric values with fallbacks.

Also applies to: 118-127, 131-140, 144-150, 154-160


18-19: LGTM: Imports updated correctly

The import statements have been properly updated to use the new InputPropertyNumber component.


118-127: LGTM: Consistent use of commit-only pattern for box shadow values

The use of mode="fixed" with only onValueCommit (no onValueChange) is appropriate for box shadow properties, as it prevents expensive live updates during typing and only commits final values. The callback signature correctly expects a number parameter in fixed mode.

Also applies to: 131-140, 144-150, 154-161

editor/scaffolds/sidecontrol/controls/font-size.tsx (4)

7-7: LGTM! Proper integration with auto mode for NumberChange handling.

The refactor correctly uses mode="auto" which is appropriate since this component expects NumberChange objects. Both onValueChange and onValueCommit are properly passed through, maintaining compatibility with the existing Select dropdown logic.

Also applies to: 16-16, 20-20, 24-32


7-7: LGTM: Import updated correctly

The import has been properly updated to use the new InputPropertyNumber component.


16-16: LGTM: Props interface updated consistently

The addition of the optional onValueCommit prop maintains backward compatibility while enabling commit-based event handling.

Also applies to: 20-20


24-33: LGTM: Component configuration is appropriate for font size control

The use of mode="auto" with type="integer" is perfect for font size input, providing both live preview updates (onValueChange) and committed changes (onValueCommit). The min/step constraints ensure valid font size values.

editor/scaffolds/sidecontrol/controls/opacity.tsx (4)

3-3: LGTM! Good use of commit semantics for slider interactions.

The refactor correctly uses mode="auto" and adds type="number" for opacity values. The change to use onValueCommit for slider interactions is logical since slider changes represent committed user actions, and the comment clearly explains this reasoning.

Also applies to: 11-11, 15-15, 25-34, 43-44


3-3: LGTM: Import updated correctly

The import has been properly updated to use the new InputPropertyNumber component.


11-11: LGTM: Props interface updated consistently

The addition of the optional onValueCommit prop maintains backward compatibility while enabling commit-based event handling.

Also applies to: 15-15


25-34: LGTM: InputPropertyNumber configuration is appropriate for opacity

The use of mode="auto" with type="number" is correct for opacity values (0-1 range with decimal precision). The min/max/step constraints ensure valid opacity values.

editor/scaffolds/sidecontrol/controls/letter-spacing.tsx (1)

3-3: LGTM! Clean refactor to commit-based input handling.

The changes correctly implement the new commit-based pattern:

  • Import updated to use the new InputPropertyNumber component
  • Added onValueCommit prop to handle committed value changes
  • Uses mode="auto" which is appropriate for the editor.api.NumberChange callback type
  • Maintains all existing functionality while adding enhanced keyboard interactions

Also applies to: 8-8, 12-12, 15-16, 23-23

editor/scaffolds/sidecontrol/controls/line-height.tsx (1)

3-3: LGTM! Consistent with the refactor pattern.

The implementation correctly follows the established pattern:

  • Updated import and component usage
  • Added onValueCommit callback for committed value changes
  • Uses mode="auto" consistently with other text-related controls
  • Preserves the minimum value constraint (min={1}) for line height validation

Also applies to: 8-8, 12-12, 15-16, 23-23

editor/scaffolds/sidecontrol/sidecontrol-node-selection.tsx (1)

313-313: LGTM! Systematic prop updates align with the commit-based pattern.

All the numeric control components have been correctly updated to use onValueCommit instead of onValueChange. This ensures:

  • Values are committed when user finishes input (blur, Enter, arrow keys) rather than on every keystroke
  • Consistent behavior across all numeric inputs in the side panel
  • Better performance by reducing unnecessary intermediate updates

The commented-out line at 527-528 clearly shows the transition pattern being applied.

Also applies to: 330-330, 337-337, 401-401, 408-408, 415-415, 527-529, 535-535, 539-539, 608-608, 919-919, 926-926, 933-933, 957-957, 1029-1029, 1043-1043, 1058-1058, 1066-1066, 1108-1108, 1247-1247, 1272-1272, 1279-1279

editor/scaffolds/sidecontrol/controls/padding.tsx (1)

1-1: LGTM! Correct implementation with appropriate mode selection.

The changes properly replace the generic Input component with the specialized InputPropertyNumber:

  • Uses mode="fixed" which is appropriate since the callback expects raw Padding values rather than NumberChange objects
  • Preserves the existing value handling logic for both numeric and object padding values
  • Maintains styling and validation constraints (min={0}, step={1})

The different mode usage ("fixed" vs "auto" in other controls) is intentional based on the callback type requirements.

Also applies to: 9-9, 12-12, 15-16, 28-28

editor/scaffolds/sidecontrol/controls/gap.tsx (3)

1-1: LGTM: Clean import migration to new component.

The import correctly references the new InputPropertyNumber component.


5-10: LGTM: Proper interface update for commit-based handling.

The interface correctly updates from onValueChange to onValueCommit, aligning with the new commit-based input pattern. This change improves UX by only triggering updates when the user commits the value rather than on every keystroke.


13-22: LGTM: Proper component migration with appropriate constraints.

The migration to InputPropertyNumber is well-executed:

  • mode="fixed" is appropriate for gap values that should be explicit numbers
  • min={0} prevents negative gap values, which makes logical sense
  • onValueCommit correctly replaces the previous change handler
editor/scaffolds/sidecontrol/controls/gradient.tsx (2)

8-8: LGTM: Correct import for new numeric input component.

The import properly references the new specialized InputPropertyNumber component.


32-48: LGTM: Excellent migration with clear behavioral documentation.

The migration to InputPropertyNumber is well-implemented:

  • mode="fixed" is appropriate for angle values
  • The comment "change on commit" clearly documents the behavioral change
  • Commit-based handling improves UX by preventing excessive re-renders during angle adjustment
  • The transform calculation logic remains correctly unchanged
editor/scaffolds/sidecontrol/controls/maxlength.tsx (3)

2-2: LGTM: Proper import update.

Correctly imports the new InputPropertyNumber component.


7-12: LGTM: Interface properly updated for commit-based handling.

The prop signature correctly changes from onValueChange to onValueCommit, maintaining type safety and consistency with the new input pattern.


16-25: LGTM: Well-configured numeric input with appropriate constraints.

The InputPropertyNumber configuration is optimal:

  • mode="fixed" enforces explicit numeric values for maxlength
  • min={0} prevents negative values, which is logically correct
  • onValueCommit provides better UX by committing only final values
editor/scaffolds/sidecontrol/controls/rotate.tsx (3)

3-3: LGTM: Import updated correctly.

Properly imports the new InputPropertyNumber component.


8-12: LGTM: Dual-callback interface for enhanced UX.

The interface wisely maintains both onValueChange and onValueCommit callbacks, likely to support live preview during rotation (immediate feedback) while still providing commit semantics for final value persistence.


15-22: LGTM: Well-configured component with dual event handling.

The InputPropertyNumber configuration is appropriate:

  • mode="auto" likely supports mixed values or auto-completion for rotation
  • Both onValueChange and onValueCommit enable live preview with commit finalization
  • This provides optimal UX for rotation controls where users expect real-time visual feedback
editor/scaffolds/sidecontrol/controls/positioning.tsx (1)

2-2: Excellent systematic refactor to specialized numeric inputs!

The replacement of generic input components with InputPropertyNumber provides several improvements:

  • Enhanced keyboard navigation with arrow keys for increment/decrement
  • Commit-based value handling for better UX (values only update on blur/Enter)
  • Better handling of mixed/undefined states
  • Consistent mode="fixed" configuration appropriate for positioning values

The implementation is consistent across all four positioning controls (top, left, right, bottom) with proper callback handling.

Also applies to: 45-57, 60-72, 87-99, 102-114

editor/scaffolds/sidecontrol/ui/index.tsx (1)

15-15: Well-designed container component with comprehensive styling!

The new PropertyInputContainer provides excellent styling infrastructure:

  • Comprehensive state management (focus, hover, disabled, invalid)
  • Proper accessibility support with ARIA attributes
  • Consistent design system integration with Tailwind classes
  • Good separation of concerns between container styling and input logic

The type-only import optimization for TMixed is also a good practice.

Also applies to: 50-66

editor/scaffolds/sidecontrol/controls/length-percentage.tsx (1)

3-3: Clean architectural separation with conditional input rendering!

The refactor introduces excellent separation of concerns:

  • Main component focuses on mode logic and state management
  • New __Input component handles conditional rendering based on value type
  • Numeric values leverage InputPropertyNumber with commit-based handling
  • Non-numeric values (auto, mixed) use appropriately disabled text inputs
  • Proper mode-specific handling in commit callbacks (fixed vs percentage)

The transition from onValueChange to onValueCommit aligns with the commit-based UX pattern throughout the codebase.

Also applies to: 29-29, 32-32, 46-55, 59-59, 82-121

editor/scaffolds/sidecontrol/controls/corner-radius.tsx (1)

2-2: Comprehensive implementation with excellent UX improvements!

The corner radius controls demonstrate excellent application of the new component architecture:

  • Proper separation between unified and individual corner radius modes
  • Individual corner inputs wrapped in PropertyInputContainer with clear icon labeling
  • Consistent commit-based handling throughout both control variants
  • Logic for detecting identical corner values and collapsing to single value is preserved
  • All four corner controls maintain consistent patterns and styling

The icon placement within input containers significantly improves visual clarity and user experience.

Also applies to: 18-18, 23-23, 27-30, 42-51, 73-80, 88-88, 91-92, 95-100, 105-142

editor/scaffolds/sidecontrol/ui/number.tsx (5)

1-15: LGTM! Clean imports and solid helper function.

The imports are well-organized and the roundToStep helper function correctly handles floating-point precision by counting decimal places in the step value and rounding accordingly.


17-50: Excellent type design with discriminated unions.

The NumericPropertyControlProps type effectively uses discriminated unions to provide type safety for different operation modes. The separation between "auto" mode (with editor.api.NumberChange objects) and "fixed" mode (with direct numbers) is clean and well-structured.


52-127: Exceptional documentation quality.

The JSDoc documentation is comprehensive, providing clear usage examples and detailed behavioral specifications. This level of documentation significantly improves maintainability and developer experience.


281-281: Review the fallback behavior for empty input.

The || 0 fallback means empty strings become 0, which may not be the intended behavior for all use cases. Consider if this should be || NaN or handled explicitly.

Should empty input values default to 0 or remain as NaN? This could affect how the component behaves with optional numeric fields.


128-298: Excellent implementation of commit-based value handling.

The component successfully addresses the PR objective of fixing "value change on commit" for side controls. Key strengths:

  • Proper separation between onValueChange (during typing) and onValueCommit (on Enter/arrow keys)
  • Comprehensive keyboard interactions with shift modifiers
  • Elegant handling of mixed states for multi-selection scenarios
  • Auto-selection and focus management enhance UX
  • Proper constraint enforcement with min/max values

This implementation provides a solid foundation for replacing the previous PropertyNumber component throughout the codebase.

Comment on lines +214 to +216
: type === "integer"
? parseInt(internalValue as string)
: parseFloat(internalValue as string);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor duplicated parsing logic.

The same parsing logic is repeated in three places. Consider extracting this into a helper function to improve maintainability and reduce code duplication.

+const parseNumericValue = (value: string | number, type: "integer" | "number"): number => {
+  if (typeof value === "number") return value;
+  return type === "integer" ? parseInt(value) : parseFloat(value);
+};

// Then replace the duplicated logic:
-const currentValue =
-  typeof internalValue === "number"
-    ? internalValue
-    : type === "integer"
-      ? parseInt(internalValue as string)
-      : parseFloat(internalValue as string);
+const currentValue = parseNumericValue(internalValue, type);

Also applies to: 252-254, 267-269

🤖 Prompt for AI Agents
In editor/scaffolds/sidecontrol/ui/number.tsx around lines 214-216, 252-254, and
267-269, the parsing logic for converting internalValue to integer or float is
duplicated. Extract this logic into a single helper function that takes the type
and internalValue as parameters and returns the parsed number. Replace all
occurrences of the duplicated parsing code with calls to this new helper
function to improve maintainability and reduce code duplication.

@softmarshmallow softmarshmallow merged commit ab9066c into main May 31, 2025
10 checks passed
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