Skip to content

Conversation

@JayantRautela
Copy link

@JayantRautela JayantRautela commented Jan 29, 2026

Part of #661

Describe the changes you have made in this PR -

changed listeners.js to listeners.ts as a part of javascript to typescript conversion


Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • No, I wrote all the code myself
  • Yes, I used AI assistance (continue below)

If you used AI assistance:

  • I have reviewed every single line of the AI-generated code
  • I can explain the purpose and logic of each function/component I added
  • I have tested edge cases and understand how the code handles them
  • I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:


Checklist before requesting a review

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
  • If it is a core feature, I have added thorough tests
  • My code follows the project's style guidelines and conventions

Note: Please check Allow edits from maintainers if you would like us to assist in the PR.

Summary by CodeRabbit

  • Refactor
    • Improved event handling system for more stable mouse and touch interactions.
    • Enhanced clipboard operations for more reliable copy/paste functionality.
    • Strengthened type safety across interaction components to reduce runtime errors.

✏️ Tip: You can customize this high-level summary in your review settings.

@netlify
Copy link

netlify bot commented Jan 29, 2026

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit 00991ec
🔍 Latest deploy log https://app.netlify.com/projects/circuitverse/deploys/697eff0111d4f30008baa8ed
😎 Deploy Preview https://deploy-preview-883--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 49 (🟢 up 1 from production)
Accessibility: 73 (no change from production)
Best Practices: 92 (no change from production)
SEO: 82 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 29, 2026

Walkthrough

This pull request makes type safety improvements and extends mouse tracking capabilities across the simulator. The SimulationArea interface adds raw and floating-point mouse coordinate properties and narrows the copyList type. The listeners.ts file undergoes significant type-related changes, including new type definitions (Coordinate, Direction, PointerEvent), updated function signatures with stricter event typing, addition of type guards and safer DOM access patterns, import path adjustments, and refinements to zoom and clipboard handling logic. The logixFunction.newProject call is also updated to pass a boolean argument.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: converting listeners.js to listeners.ts as part of a JavaScript to TypeScript migration.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/simulator/src/listeners.ts (1)

598-611: Duplicate deltaY variable declaration.

Line 601 and 603 contain identical declarations of deltaY. The second one is redundant and should be removed.

Proposed fix
 function MouseScroll(event: WheelEvent & { wheelDelta?: number; detail?: number }) {
     updateCanvasSet(true)
     event.preventDefault()
     var deltaY = event.wheelDelta ? event.wheelDelta : -event.detail
-    event.preventDefault()
-    var deltaY = event.wheelDelta ? event.wheelDelta : -event.detail
     const direction = deltaY > 0 ? 1 : -1
     handleZoom(direction)
🤖 Fix all issues with AI agents
In `@src/simulator/src/listeners.ts`:
- Around line 634-644: The code parses the JSON string returned by
copy(simulationArea.copyList, true) into an object (textToPutOnClipboard) but
then passes it to localStorage.setItem and clipboardData.setData which expect
strings; remove the JSON.parse and keep the string returned by copy(), e.g., set
textToPutOnClipboard = copy(simulationArea.copyList, true), validate it (if
undefined/null return early), then call localStorage.setItem('clipboardData',
textToPutOnClipboard) and clipboard APIs (window.clipboardData.setData /
e.clipboardData.setData) with that string; adjust references in the surrounding
block including updateRestrictedElementsInScope(), the isIe branch, and the
undefined check to reflect the string variable.
- Around line 665-675: The handler uses
JSON.parse(copy(simulationArea.copyList)) which produces an object but clipboard
and localStorage expect a string; remove the JSON.parse and use the raw string
returned by copy(simulationArea.copyList) (or JSON.stringify(...) if copy
returns an object) so that textToPutOnClipboard is a string, then call
localStorage.setItem('clipboardData', textToPutOnClipboard) and
e.clipboardData.setData('text/plain', textToPutOnClipboard) accordingly;
updateRestrictedElementsInScope and references to isIe and
(window).clipboardData remain unchanged.
🧹 Nitpick comments (2)
src/simulator/src/listeners.ts (2)

53-58: Custom PointerEvent type shadows the native DOM PointerEvent interface.

The native DOM already has a PointerEvent interface that extends UIEvent. Using the same name for a custom union type can cause confusion and potential type conflicts if native PointerEvent is needed elsewhere.

Suggested rename to avoid shadowing
 type Coordinate = { 
     x: number; 
     y: number 
 };
 type Direction = 1 | -1;
-type PointerEvent = MouseEvent | TouchEvent;
+type InputEvent = MouseEvent | TouchEvent;

Then update all function signatures accordingly (e.g., onDoubleClickorTap(e: InputEvent)).


43-51: Consider moving global declarations to a TypeScript declaration file.

These inline declare statements work but could be consolidated with other global declarations. Based on learnings from this repository, globalScope should be declared on the window object using TypeScript declaration files (.d.ts) rather than inline declarations, as it's initialized on the window object.

Comment on lines +634 to +644
const textToPutOnClipboard = JSON.parse(copy(simulationArea.copyList, true))

// Updated restricted elements
updateRestrictedElementsInScope()
localStorage.setItem('clipboardData', textToPutOnClipboard)
e.preventDefault()
if (textToPutOnClipboard == undefined) return
if (isIe) {
window.clipboardData.setData('Text', textToPutOnClipboard)
(window as any).clipboardData.setData('Text', textToPutOnClipboard)
} else {
e.clipboardData.setData('text/plain', textToPutOnClipboard)
e?.clipboardData?.setData('text/plain', textToPutOnClipboard)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

JSON.parse() returns an object, but setData() and localStorage.setItem() expect strings.

The copy() function returns a JSON string. Calling JSON.parse() on it produces an object. This object is then passed to clipboardData.setData('text/plain', ...) and localStorage.setItem(), both of which expect string arguments. This will result in "[object Object]" being stored instead of the actual circuit data.

🐛 Proposed fix: remove JSON.parse
-            const textToPutOnClipboard = JSON.parse(copy(simulationArea.copyList, true))
+            const textToPutOnClipboard = copy(simulationArea.copyList, true)

             // Updated restricted elements
             updateRestrictedElementsInScope()
             localStorage.setItem('clipboardData', textToPutOnClipboard)
             e.preventDefault()
             if (textToPutOnClipboard == undefined) return
             if (isIe) {
                 (window as any).clipboardData.setData('Text', textToPutOnClipboard)
             } else {
                 e?.clipboardData?.setData('text/plain', textToPutOnClipboard)
             }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const textToPutOnClipboard = JSON.parse(copy(simulationArea.copyList, true))
// Updated restricted elements
updateRestrictedElementsInScope()
localStorage.setItem('clipboardData', textToPutOnClipboard)
e.preventDefault()
if (textToPutOnClipboard == undefined) return
if (isIe) {
window.clipboardData.setData('Text', textToPutOnClipboard)
(window as any).clipboardData.setData('Text', textToPutOnClipboard)
} else {
e.clipboardData.setData('text/plain', textToPutOnClipboard)
e?.clipboardData?.setData('text/plain', textToPutOnClipboard)
const textToPutOnClipboard = copy(simulationArea.copyList, true)
// Updated restricted elements
updateRestrictedElementsInScope()
localStorage.setItem('clipboardData', textToPutOnClipboard)
e.preventDefault()
if (textToPutOnClipboard == undefined) return
if (isIe) {
(window as any).clipboardData.setData('Text', textToPutOnClipboard)
} else {
e?.clipboardData?.setData('text/plain', textToPutOnClipboard)
}
🤖 Prompt for AI Agents
In `@src/simulator/src/listeners.ts` around lines 634 - 644, The code parses the
JSON string returned by copy(simulationArea.copyList, true) into an object
(textToPutOnClipboard) but then passes it to localStorage.setItem and
clipboardData.setData which expect strings; remove the JSON.parse and keep the
string returned by copy(), e.g., set textToPutOnClipboard =
copy(simulationArea.copyList, true), validate it (if undefined/null return
early), then call localStorage.setItem('clipboardData', textToPutOnClipboard)
and clipboard APIs (window.clipboardData.setData / e.clipboardData.setData) with
that string; adjust references in the surrounding block including
updateRestrictedElementsInScope(), the isIe branch, and the undefined check to
reflect the string variable.

Comment on lines +665 to +675
const textToPutOnClipboard = JSON.parse(copy(simulationArea.copyList))

// Updated restricted elements
updateRestrictedElementsInScope()
localStorage.setItem('clipboardData', textToPutOnClipboard)
e.preventDefault()
if (textToPutOnClipboard == undefined) return
if (isIe) {
window.clipboardData.setData('Text', textToPutOnClipboard)
(window as any).clipboardData.setData('Text', textToPutOnClipboard)
} else {
e.clipboardData.setData('text/plain', textToPutOnClipboard)
e?.clipboardData?.setData('text/plain', textToPutOnClipboard)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Same JSON.parse() issue in the copy handler.

This has the same problem as the cut handler - JSON.parse() returns an object but string is expected.

🐛 Proposed fix: remove JSON.parse
-            const textToPutOnClipboard = JSON.parse(copy(simulationArea.copyList))
+            const textToPutOnClipboard = copy(simulationArea.copyList)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const textToPutOnClipboard = JSON.parse(copy(simulationArea.copyList))
// Updated restricted elements
updateRestrictedElementsInScope()
localStorage.setItem('clipboardData', textToPutOnClipboard)
e.preventDefault()
if (textToPutOnClipboard == undefined) return
if (isIe) {
window.clipboardData.setData('Text', textToPutOnClipboard)
(window as any).clipboardData.setData('Text', textToPutOnClipboard)
} else {
e.clipboardData.setData('text/plain', textToPutOnClipboard)
e?.clipboardData?.setData('text/plain', textToPutOnClipboard)
const textToPutOnClipboard = copy(simulationArea.copyList)
// Updated restricted elements
updateRestrictedElementsInScope()
localStorage.setItem('clipboardData', textToPutOnClipboard)
e.preventDefault()
if (textToPutOnClipboard == undefined) return
if (isIe) {
(window as any).clipboardData.setData('Text', textToPutOnClipboard)
} else {
e?.clipboardData?.setData('text/plain', textToPutOnClipboard)
🤖 Prompt for AI Agents
In `@src/simulator/src/listeners.ts` around lines 665 - 675, The handler uses
JSON.parse(copy(simulationArea.copyList)) which produces an object but clipboard
and localStorage expect a string; remove the JSON.parse and use the raw string
returned by copy(simulationArea.copyList) (or JSON.stringify(...) if copy
returns an object) so that textToPutOnClipboard is a string, then call
localStorage.setItem('clipboardData', textToPutOnClipboard) and
e.clipboardData.setData('text/plain', textToPutOnClipboard) accordingly;
updateRestrictedElementsInScope and references to isIe and
(window).clipboardData remain unchanged.

@JayantRautela JayantRautela marked this pull request as draft January 29, 2026 13:31
@JayantRautela JayantRautela marked this pull request as ready for review January 29, 2026 13:46
@JayantRautela
Copy link
Author

Hey @Nihal4777, can you please review the changes.

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.

1 participant