Skip to content

Conversation

@zhravan
Copy link
Owner

@zhravan zhravan commented May 2, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a full-featured Markdown text editor mode with persistent, multi-tab support, tab renaming, drag-and-drop reordering, and autosave functionality.
    • Added keyboard shortcut (Ctrl/Cmd + Shift + S) to save editor content.
    • Enhanced UI feedback with SweetAlert2 modals for clipboard actions and tab close confirmations.
  • Improvements

    • Unified and improved UI styling, theming consistency, and accessibility across all components, including comprehensive dark mode support.
    • Refined tab management and mode switching for a smoother user experience.
    • Enhanced tree view, markdown preview, and modal interfaces for better usability and interactivity.

@coderabbitai
Copy link

coderabbitai bot commented May 2, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces a comprehensive refactor and expansion of the application's UI and functionality. The CSS was overhauled for unified layout, theming, and accessibility, with significant improvements to dark mode and component interactivity. The HTML structure was reorganized to support new features, notably a fully-featured Markdown Editor mode with tab management. The JavaScript adds SweetAlert2-based dialogs, refactors mode switching, and implements the Markdown Editor with persistent, draggable tabs, autosave, and keyboard shortcuts. No changes were made to exported or public entity declarations in the HTML or CSS, but several new and updated functions were introduced in the JavaScript.

Changes

Files / Areas Change Summary
index.css Refactored and enhanced for unified layout, spacing, and theming. Improved dark mode, standardized component styles, added drag-and-drop tab reordering, enhanced tree view with transitions, tooltips, keyboard accessibility, and color-coded node types. Markdown preview, modals, Toast UI Editor, and utility containers received consistent styling and dark mode support.
index.html Reorganized structure with new UI sections for six modes, including a new Markdown Editor. Added external dependencies for Toast UI Editor and SweetAlert2. Enhanced tab containers, content areas, and expanded sections for mock data generation and conversion. Improved markup grouping, indentation, and added new containers and buttons for expanded features and better structure.
index.js Replaced native dialogs with SweetAlert2 modals. Refactored mode switching to support new editor mode. Implemented Markdown Editor with tab management (add, switch, rename, save, delete, reorder), persistent storage, autosave, and keyboard shortcuts. Updated tab close functions to async for modal dialogs. Added functions for editor state management, tab reordering, and dark mode adaptation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI (HTML/CSS)
    participant JS Logic
    participant LocalStorage
    participant ToastUIEditor
    participant SweetAlert2

    User->>UI (HTML/CSS): Clicks "Markdown Editor" mode
    UI (HTML/CSS)->>JS Logic: Triggers mode switch
    JS Logic->>UI (HTML/CSS): Shows editor section, hides others
    JS Logic->>LocalStorage: Loads editor global state (tabs, active tab)
    JS Logic->>ToastUIEditor: Initializes editor for active tab
    User->>UI (HTML/CSS): Adds/Renames/Deletes/Reorders tabs
    UI (HTML/CSS)->>JS Logic: Handles tab action
    JS Logic->>LocalStorage: Updates/saves editor state
    JS Logic->>SweetAlert2: Shows modal for confirm/notify actions
    User->>UI (HTML/CSS): Edits content or saves (Ctrl/Cmd+Shift+S)
    UI (HTML/CSS)->>JS Logic: Triggers saveEditorContent
    JS Logic->>LocalStorage: Persists tab content
    JS Logic->>SweetAlert2: Shows save notification
Loading

Possibly related PRs

  • fix: CSS inconsistencies #45: Extensively modifies CSS for layout, theming, and UI components, overlapping with this PR's styling improvements and refinements.
  • feat: implement tab reordering feature #37: Implements drag-and-drop tab reordering for formatter, compare, and codegen tabs, similar to this PR's tab management and reordering in the new editor mode.

Poem

In a garden of code where the editors bloom,
New tabs pop up and markdown finds room.
With SweetAlert’s sparkle and dark mode’s embrace,
The UI hops forward, a unified space.
Tabs dance and reorder, content autosaves—
A rabbit’s delight in the features it paves!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8275cd4 and 12cc6d6.

📒 Files selected for processing (1)
  • index.js (9 hunks)
✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

@zhravan zhravan changed the title Improv feat: add text editor and move to SWAL2 May 2, 2025
@zhravan zhravan merged commit 07b1e14 into main May 2, 2025
@zhravan zhravan deleted the improv branch May 2, 2025 15:38
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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 3

🔭 Outside diff range comments (3)
index.js (3)

2-6: 🛠️ Refactor suggestion

getActiveMode() ignores three new modes

Only formatter, compare, and codegen are detected, so when the UI is in convert, mockgen, or editor modes, the persisted activeMode is always recorded as "formatter".
Restoring the session will therefore open the wrong section.

 function getActiveMode() {
-    if (document.getElementById("formatter-section").style.display !== "none") return "formatter";
-    if (document.getElementById("compare-section").style.display !== "none") return "compare";
-    if (document.getElementById("codegen-section").style.display !== "none") return "codegen";
-    return "formatter";
+    const modes = ["formatter","compare","codegen","convert","mockgen","editor"];
+    for (const m of modes) {
+        if (document.getElementById(`${m}-section`).style.display !== "none") {
+            return m;
+        }
+    }
+    return "formatter";  // sensible fallback
 }

240-258: ⚠️ Potential issue

Duplicate “raw-preview” IDs will break DOM queries

#${tabId}-raw-preview is rendered twice: once at lines 240-243 and again at 250-253.
Duplicate IDs are invalid HTML, and querySelector("#id") will only hit the first instance, confusing copy/preview logic.

-             <div id="${tabId}-raw-preview" class="preview-section active">
-                    <button class="copy-button" onclick="copyRawJSON('${tabId}')">Copy</button>
-                    <pre class="raw-json"></pre>
-                </div>
-                <div id="${tabId}-tree-preview" class="preview-section">
-                    <button class="copy-button" onclick="copyRawJSON('${tabId}')">Copy JSON</button>
-                    <div class="tree-view"></div>
-                </div>
+             <!-- second block removed – first one already contains copy btn & pre -->

1073-1100: ⚠️ Potential issue

Null-dereference in convert()

Because of the missing convert-output element (see HTML comment), output can be null, and the following lines attempt output.textContent = ….
Guard or fail loudly:

-const output = document.getElementById("convert-output");
+const output = document.getElementById("convert-output");
+if (!output) {
+    console.error("convert-output element not found");
+    return;
+}

(But preferred fix is adding the element in HTML, see earlier comment.)

🧹 Nitpick comments (1)
.gitignore (1)

19-20: Duplicate .qodo pattern – keep only one entry

.qodo/ is already ignored on line 19, yet a second (slightly different) entry .qodo is appended at line 139.
Keeping both:

  • clutters the ignore-list,
  • might confuse future contributors about the canonical spelling (with or without trailing slash).
-CHANGELOG.*
-.qodo
+CHANGELOG.*

If the directory form (.qodo/) is correct, the extra line should be removed; if individual files inside .qodo also need ignoring, keep the former and use /.qodo* (or similar) instead.

Also applies to: 138-139

🛑 Comments failed to post (3)
index.css (1)

345-435: 🛠️ Refactor suggestion

Large block of duplicated rules inflates bundle & invites drift

Selectors such as .tree-children, .tree-key, body.dark-mode .tree-key[title]:hover::after, etc. are repeated almost verbatim (first block lines 345-435, second block 491-575).

Besides ~230 extra lines, duplication causes:

• heavier CSS payload,
• maintenance headaches (one copy updated, the other forgotten),
• potential specificity battles.

Please keep one canonical definition and delete the clone.

-.tree-children {
-  /* second duplicate block… */
-}
-
-
-.tree-key.shift-toggle {
-  background-color: rgba(0,123,255,.08);
-}
+/* duplicate block removed – original rules above remain */

Also applies to: 491-575

🤖 Prompt for AI Agents (early access)
In index.css between lines 345-435 and 491-575, there is a large block of duplicated CSS rules for selectors like .tree-children, .tree-key, and body.dark-mode .tree-key[title]:hover::after. This duplication increases the CSS bundle size and risks maintenance issues. To fix this, remove the duplicated block from lines 491-575 and keep only one canonical definition of these styles in lines 345-435, ensuring all necessary styles remain intact in the single retained block.
index.html (1)

110-116: ⚠️ Potential issue

convert() will fail – missing id="convert-output"

index.js expects document.getElementById("convert-output") (see lines 1073-1076) but the <pre> added here lacks that id.
convert() now dereferences null, throwing TypeError: Cannot set property 'textContent' of null.

-<pre class="code-output" style="margin-top: 10px; overflow: auto"></pre>
+<pre id="convert-output"
+     class="code-output"
+     style="margin-top:10px;overflow:auto"></pre>
📝 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.

      <textarea id="convert-input" class="json-input" placeholder="Paste here..."></textarea>
      <button onclick="convert()">Convert</button>
      <button class="copy-button" onclick="copyConvertOutput()">
        Copy Output
      </button>
      <pre id="convert-output"
           class="code-output"
           style="margin-top:10px;overflow:auto"></pre>
    </div>
🤖 Prompt for AI Agents (early access)
In index.html around lines 110 to 116, the <pre> element used for output is missing the id "convert-output" which is required by the convert() function in index.js. Add id="convert-output" to the <pre> tag so that document.getElementById("convert-output") correctly references this element and prevents the TypeError when setting textContent.
index.js (1)

1493-1523: 🛠️ Refactor suggestion

Function redeclared — pick one implementation

openTabRenameTooltip is defined earlier (lines 909-944) for JSON tabs (signature (tabId, mode)) and re-defined here for editor tabs (signature (tabId)), silently overwriting the first.
Side-effects:

• Formatter/Compare/Codegen now call the new version with two args – ignored but confusing.
• Static analysis already warns (noRedeclare).

Rename the editor-specific one (e.g., openEditorTabRenameTooltip) or merge both behaviours into a single, generic implementation.

-function openTabRenameTooltip(tabId) {
+function openEditorTabRenameTooltip(tabId) {
@@
 }

Update calls in addEditorTab() and elsewhere accordingly.

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

function openEditorTabRenameTooltip(tabId) {
    const btn = document.querySelector(`#editor-tabs-container .tab-button[data-tab="${tabId}"]`);
    const existing = document.querySelector(".tab-rename-tooltip");
    if (existing) existing.remove();
    const tooltip = document.createElement("div");
    tooltip.className = "tab-rename-tooltip";
    const rect = btn.getBoundingClientRect();
    tooltip.style.left = rect.left + "px";
    tooltip.style.top = rect.bottom + window.scrollY + 5 + "px";
    const input = document.createElement("input");
    input.type = "text";
    input.value = btn.querySelector(".tab-name").textContent;
    input.style.width = "150px";
    input.addEventListener("keydown", (e) => {
        if (e.key === "Enter") finalizeRename();
        else if (e.key === "Escape") tooltip.remove();
    });
    input.addEventListener("blur", finalizeRename);
    tooltip.appendChild(input);
    document.body.appendChild(tooltip);
    input.focus();

    function finalizeRename() {
        const newName = input.value.trim();
        if (newName) {
            btn.querySelector(".tab-name").textContent = newName;
        }
        tooltip.remove();
        updateEditorGlobalState();
    }
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 1493-1494: Shouldn't redeclare 'openTabRenameTooltip'. Consider to delete it or rename it.

'openTabRenameTooltip' is defined here:

(lint/suspicious/noRedeclare)

🤖 Prompt for AI Agents (early access)
In index.js around lines 1493 to 1523, the function openTabRenameTooltip is redeclared, overwriting the earlier version defined around lines 909 to 944, causing confusion and static analysis warnings. Rename this second function to openEditorTabRenameTooltip to distinguish it from the JSON tabs version, and update all calls to this function in addEditorTab() and other places to use the new name. This avoids silent overwrites and clarifies which function is used for editor tabs.

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