Skip to content
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

[PULSE-42] feat: text alignment for all editors #5847

Open
wants to merge 5 commits into
base: preview
Choose a base branch
from

Conversation

aaryan610
Copy link
Collaborator

@aaryan610 aaryan610 commented Oct 16, 2024

Users can now use Left, Center and Right text alignments on pages, issue descriptions and comments.

Ways to align text-

  1. Using the toolbar.
  2. Using shortcuts- Cmd + Shift + L/E/R for left, center and right respectively.

Media:

Screen.Recording.2024-10-16.at.18.51.18.mov

Summary by CodeRabbit

  • New Features

    • Introduced a TextAlignmentSelector component for selecting text alignment (left, center, right) in the text editor.
    • Added support for text alignment through a new CustomTextAlignExtension.
  • Enhancements

    • Updated color selection commands for improved functionality.
    • Enhanced the structure of toolbar menu items, including new alignment options.
    • Improved command handling for more flexible execution in the editor.
    • Adjusted styling for better visual consistency in the editor.
    • Introduced new function types for better type inference in menu items.
  • Bug Fixes

    • Minor adjustments to the AddComment component's placeholder text for clarity.
  • Documentation

    • Updated type definitions and method signatures for better clarity and type safety.

Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The pull request introduces a new dependency, @tiptap/extension-text-align, to the @plane/editor package and adds a new React component, TextAlignmentSelector, for selecting text alignment options. Additionally, several existing components are modified for improved type safety and functionality, including updates to command handling and the integration of the new text alignment feature. The changes also include enhancements to type definitions and styling adjustments in the editor.

Changes

File Path Change Summary
packages/editor/package.json Added dependency: "@tiptap/extension-text-align": "^2.8.0"
packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx Introduced TextAlignmentSelector component for text alignment options.
packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx Updated color command invocation method.
packages/editor/src/core/components/menus/bubble-menu/node-selector.tsx Enhanced type safety for items array.
packages/editor/src/core/components/menus/bubble-menu/root.tsx Added TextAlignmentSelector and renamed items to basicFormattingOptions.
packages/editor/src/core/components/menus/menu-items.ts Enhanced EditorMenuItem type and added TextAlignItem.
packages/editor/src/core/extensions/core-without-props.ts Added CustomTextAlignExtension to core editor extensions.
packages/editor/src/core/extensions/extensions.tsx Added CustomTextAlignExtension to core editor extensions.
packages/editor/src/core/extensions/index.ts Modified exports to include text-align and remove slash-commands.
packages/editor/src/core/extensions/read-only-extensions.tsx Added CustomTextAlignExtension to read-only editor extensions.
packages/editor/src/core/extensions/text-align.ts Introduced text-align.ts with CustomTextAlignExtension for alignment options.
packages/editor/src/core/helpers/editor-commands.ts Added setTextAlign function for setting text alignment.
packages/editor/src/core/hooks/use-editor.ts Updated command handling in useEditor hook.
packages/editor/src/core/types/editor.ts Redefined TEditorCommands type and introduced new command property types.
packages/editor/src/core/types/slash-commands-suggestion.ts Removed local TEditorCommands type, now imported from a different module.
packages/editor/src/styles/editor.css Adjusted styling for .tippy-box and task list appearance.
space/core/components/editor/lite-text-editor.tsx Updated executeCommand method and removed unused import.
space/core/components/editor/toolbar.tsx Updated type definitions and logic for command handling.
space/core/components/issues/peek-overview/comment/add-comment.tsx Minor modification to AddComment component's placeholder text.
space/core/constants/editor.ts Enhanced structure and typing of toolbar menu items, added new alignment items.
web/core/components/editor/lite-text-editor/lite-text-editor.tsx Updated executeCommand function and removed unused import.
web/core/components/editor/lite-text-editor/toolbar.tsx Updated type definitions and command handling logic.
web/core/components/pages/editor/header/color-dropdown.tsx Updated type definitions for color selection props.
web/core/components/pages/editor/header/toolbar.tsx Updated handling of toolbar items and associated keys.

Possibly related PRs

Suggested reviewers

  • sriramveeraghanta
  • SatishGandham

🐇 In the editor, we align with glee,
New features added, oh what a spree!
Texts left, right, or center they’ll sway,
With colors and styles, come join the play!
A hop and a skip, let’s code away! 🌈✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b05f407 and e4cb32e.

📒 Files selected for processing (1)
  • packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.

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

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: 15

🧹 Outside diff range and nitpick comments (19)
packages/editor/src/core/extensions/text-align.ts (1)

1-6: LGTM! Consider enhancing code readability.

The implementation of the CustomTextAlignExtension looks good and aligns well with the PR objectives. It correctly configures the TextAlign extension with the required alignment options (left, center, right) and applies them to both heading and paragraph content types.

To improve code readability and maintainability, consider using constants for the alignment options and content types. Here's a suggested refactor:

 import TextAlign from "@tiptap/extension-text-align";

+const ALIGNMENT_OPTIONS = ["left", "center", "right"] as const;
+const CONTENT_TYPES = ["heading", "paragraph"] as const;
+
 export const CustomTextAlignExtension = TextAlign.configure({
-  alignments: ["left", "center", "right"],
-  types: ["heading", "paragraph"],
+  alignments: ALIGNMENT_OPTIONS,
+  types: CONTENT_TYPES,
 });

This change would make it easier to maintain and update the supported alignments and content types in the future if needed.

packages/editor/src/core/extensions/index.ts (1)

Line range hint 1-26: Consider sorting exports alphabetically

To improve readability and maintainability, consider sorting the exports alphabetically. This will make it easier to locate specific exports in the future.

Here's a script to sort the exports:

#!/bin/bash
# Description: Sort exports alphabetically

# Test: Sort exports and display the result
sort -o sorted_exports.tmp packages/editor/src/core/extensions/index.ts
cat sorted_exports.tmp
rm sorted_exports.tmp
packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx (2)

19-65: LGTM: Text alignment options are well-defined.

The textAlignmentOptions array is structured appropriately, covering left, center, and right alignments as specified in the PR objectives. Each option includes the necessary properties for rendering and handling user interactions.

Consider extracting the alignment options ("left", "center", "right") into a constant array or enum to improve maintainability. This would allow for easier addition or modification of alignment options in the future. Here's a suggested implementation:

const ALIGNMENT_OPTIONS = ["left", "center", "right"] as const;
type AlignmentOption = typeof ALIGNMENT_OPTIONS[number];

const textAlignmentOptions = ALIGNMENT_OPTIONS.map((alignment) => ({
  itemKey: "text-align" as const,
  renderKey: `text-align-${alignment}`,
  icon: alignmentIcons[alignment],
  command: () => menuItem.command({ alignment }),
  isActive: () => menuItem.isActive({ alignment }),
}));

// Define alignmentIcons separately
const alignmentIcons: Record<AlignmentOption, LucideIcon> = {
  left: AlignLeft,
  center: AlignCenter,
  right: AlignRight,
};

This refactoring would make the code more DRY and easier to maintain.


67-88: LGTM: Render method is well-implemented with a suggestion for improvement.

The component's render method effectively creates buttons for each alignment option, applying appropriate styling and event handlers. The use of the cn helper function for conditional class names is a good practice.

To improve accessibility, consider adding aria-label attributes to the buttons. This will provide more context for screen reader users. Here's a suggested modification:

 <button
   key={item.renderKey}
   type="button"
+  aria-label={`Align text ${item.renderKey.split('-').pop()}`}
   onClick={(e) => {
     item.command();
     e.stopPropagation();
   }}
   className={cn(
     "size-7 grid place-items-center rounded text-custom-text-300 hover:bg-custom-background-80 active:bg-custom-background-80 transition-colors",
     {
       "bg-custom-background-80 text-custom-text-100": item.isActive(),
     }
   )}
 >
   <item.icon className="size-4" />
 </button>

This change will make the component more accessible to users relying on screen readers.

space/core/components/editor/lite-text-editor.tsx (2)

36-38: LGTM! Consider using useMemo for isEmpty.

The changes improve code readability and simplify the editorRef derivation. Good job!

Consider using useMemo for isEmpty to optimize performance, especially if props.initialValue is complex or isCommentEmpty is computationally expensive:

const isEmpty = useMemo(() => isCommentEmpty(props.initialValue), [props.initialValue]);

Line range hint 1-77: Overall improvements with some follow-up tasks.

The changes to the LiteTextEditor component and IssueCommentToolbar improve code structure and flexibility. However, there are a few follow-up tasks to consider:

  1. Complete the toolbar homogenization mentioned in the TODO comment.
  2. Update type definitions to remove the need for type assertions.
  3. Consider adding unit tests for the new executeCommand logic to ensure it works as expected with different types of items.
  4. Review the @plane/editor package to ensure all exported types and components are up-to-date with these changes.

These changes seem to be part of a larger refactoring effort. Ensure that all related components and files are updated consistently to maintain the overall architecture integrity.

packages/editor/src/core/components/menus/bubble-menu/node-selector.tsx (1)

23-23: Summary: Improved type safety for editor commands

These changes enhance the type safety of the BubbleMenuNodeSelector component, particularly for editor commands. This aligns well with the PR's objective of introducing text alignment features, as it provides a more robust foundation for implementing new editor functionalities.

Suggestions for follow-up:

  1. Ensure that the TEditorCommands type includes the new text alignment commands.
  2. Consider applying similar type improvements to other components in the editor package for consistency.
  3. Update the component's documentation to reflect the enhanced type safety, if applicable.

Also applies to: 34-34

packages/editor/src/core/extensions/extensions.tsx (1)

Line range hint 1-163: Overall assessment: Changes look good

The changes to this file are minimal and focused, correctly implementing the addition of the CustomTextAlignExtension. This aligns well with the PR objectives of introducing text alignment features. The implementation follows existing patterns in the codebase, which is good for consistency and maintainability.

However, to ensure a comprehensive review:

  1. Please confirm that the CustomTextAlignExtension has been properly implemented and tested in its own file.
  2. Verify that the new text alignment features (Left, Center, Right) work as expected in the editor, both through the toolbar and the specified keyboard shortcuts (Cmd + Shift + L, Cmd + Shift + E, Cmd + Shift + R).
  3. Check if any updates to documentation or user guides are needed to reflect these new text alignment capabilities.

Consider adding a comment in the CoreEditorExtensions function to briefly explain the purpose of CustomTextAlignExtension for future maintainers.

web/core/components/pages/editor/header/toolbar.tsx (1)

Action Required: Resolve @ts-expect-error and TODO Comments

The verification reveals that there are still two @ts-expect-error comments and two TODO comments in web/core/components/pages/editor/header/toolbar.tsx. Please address these to ensure type safety and complete the planned refactoring.

  • Resolve Type Mismatches: Investigate and fix the type issues causing the @ts-expect-error comments.
  • Address TODOs: Create and reference tickets for the TODO items to track their completion.
  • Clean Up Code: Remove any unnecessary debugging statements or commented-out code if applicable.

Once these actions are completed, the codebase will be more robust and maintainable.

🔗 Analysis chain

Line range hint 1-163: Summary of changes and recommendations

The changes in this file generally improve consistency in how toolbar items are handled and referenced. The use of itemKey, renderKey, and extraProps has been standardized across the component, which is a positive change.

However, there are a few items that need attention:

  1. Resolve type mismatches: There are two instances of @ts-expect-error in the file. These should be investigated and resolved to ensure proper type safety.
  2. Address TODO comments: Create tickets for the TODO items and reference them in the code comments.
  3. Clean up debugging code: Remove commented-out console.log statements if they're no longer needed.

Overall, once these issues are addressed, the code will be more robust and maintainable.

To ensure all instances of @ts-expect-error and TODO comments are addressed, run the following script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for remaining @ts-expect-error comments and TODOs in the file

echo "Checking for @ts-expect-error comments:"
rg "@ts-expect-error" web/core/components/pages/editor/header/toolbar.tsx

echo "\nChecking for TODO comments:"
rg "TODO:" web/core/components/pages/editor/header/toolbar.tsx

Length of output: 508

packages/editor/src/core/components/menus/bubble-menu/root.tsx (1)

30-32: Approved: Improved basicFormattingOptions logic

The renaming of items to basicFormattingOptions enhances code readability. The conditional logic for including CodeItem is a good practice, ensuring that appropriate formatting options are displayed based on the editor's state.

Consider extracting the condition props.editor.isActive("code") into a descriptive variable for improved readability:

const isCodeModeActive = props.editor.isActive("code");
const basicFormattingOptions = isCodeModeActive
  ? [CodeItem(props.editor)]
  : [BoldItem(props.editor), ItalicItem(props.editor), UnderLineItem(props.editor), StrikeThroughItem(props.editor)];

This minor refactoring would make the code even more self-explanatory.

packages/editor/src/core/hooks/use-editor.ts (1)

155-155: Simplified active state check: Approved with suggestion

This change simplifies the isMenuItemActive method by passing the entire props object to the isActive function. This refactoring aligns with the changes made to executeMenuItemCommand, providing consistency and improving maintainability.

For even better consistency, consider renaming the props parameter in both methods to something more specific, like menuItemProps. This would make it clearer that these are properties related to menu items.

Here's a suggested change for both methods:

- executeMenuItemCommand: (props) => {
-   const { itemKey } = props;
+ executeMenuItemCommand: (menuItemProps) => {
+   const { itemKey } = menuItemProps;
  // ... rest of the method
-   item.command(props);
+   item.command(menuItemProps);

- isMenuItemActive: (props) => {
-   const { itemKey } = props;
+ isMenuItemActive: (menuItemProps) => {
+   const { itemKey } = menuItemProps;
  // ... rest of the method
-   return item.isActive(props);
+   return item.isActive(menuItemProps);
space/core/components/editor/toolbar.tsx (1)

36-36: Address the TODO comment regarding toolbar homogenization

There's a TODO comment indicating that this code needs updating during the toolbar homogenization process. To prevent this from being overlooked, ensure that this task is prioritized and tracked appropriately.

Do you want me to create a GitHub issue to track this task or assist with the homogenization?

space/core/constants/editor.ts (2)

46-46: Consider using a more intuitive icon for 'Text'

The CaseSensitive icon may not effectively represent the "Text" formatting option to users. Consider choosing an icon that more clearly symbolizes "Text" to enhance user experience.


61-61: Ensure alignment shortcuts do not conflict with existing shortcuts

Please verify that the new alignment shortcuts (Cmd + Shift + L, Cmd + Shift + E, Cmd + Shift + R) do not conflict with existing editor or system shortcuts to ensure a smooth user experience.

Also applies to: 72-72, 83-83

web/core/components/editor/lite-text-editor/toolbar.tsx (1)

71-71: Address the TODO: Update during toolbar homogenization

There's a TODO comment indicating that this code should be updated as part of the toolbar homogenization process.

Would you like assistance in updating this code segment for toolbar homogenization? I can help refactor the code to align with the homogenization goals or open a GitHub issue to track this task.

packages/editor/src/core/components/menus/menu-items.ts (1)

Line range hint 231-255: Reorder Menu Items for Improved User Experience

The TextAlignItem is currently added at the end of the menu items array. To enhance the user experience, consider positioning it alongside other text formatting options like BoldItem, ItalicItem, and UnderlineItem.

Apply this diff to reposition TextAlignItem:

      UnderLineItem(editor),
+     TextAlignItem(editor),
      StrikeThroughItem(editor),
      BulletListItem(editor),
web/core/constants/editor.ts (3)

40-47: Enhance Documentation for ToolbarMenuItem

The ToolbarMenuItem type now includes a generic parameter <T extends TEditorCommands> and an optional extraProps. Consider updating any associated documentation or comments to reflect these changes for better clarity for future developers.


122-123: Fix Indentation for Consistency

There is an indentation issue at line 122 and 123. Consistent indentation improves code readability.

Apply this diff to fix the indentation:

     {
-    itemKey: "strikethrough",
-    renderKey: "strikethrough",
+      itemKey: "strikethrough",
+      renderKey: "strikethrough",

66-119: Consider Internationalization for Keyboard Shortcuts

While defining keyboard shortcuts, consider that some users might have different keyboard layouts or internationalization settings. It's important to ensure that the shortcuts are accessible and do not conflict with existing shortcuts in various locales.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7d36d63 and e2bcf25.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (25)
  • packages/editor/package.json (1 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx (1 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx (2 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/node-selector.tsx (2 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/root.tsx (4 hunks)
  • packages/editor/src/core/components/menus/menu-items.ts (3 hunks)
  • packages/editor/src/core/extensions/core-without-props.ts (2 hunks)
  • packages/editor/src/core/extensions/extensions.tsx (2 hunks)
  • packages/editor/src/core/extensions/index.ts (1 hunks)
  • packages/editor/src/core/extensions/read-only-extensions.tsx (2 hunks)
  • packages/editor/src/core/extensions/text-align.ts (1 hunks)
  • packages/editor/src/core/helpers/editor-commands.ts (1 hunks)
  • packages/editor/src/core/hooks/use-editor.ts (2 hunks)
  • packages/editor/src/core/types/editor.ts (2 hunks)
  • packages/editor/src/core/types/slash-commands-suggestion.ts (1 hunks)
  • packages/editor/src/styles/editor.css (1 hunks)
  • space/core/components/editor/lite-text-editor.tsx (3 hunks)
  • space/core/components/editor/toolbar.tsx (3 hunks)
  • space/core/components/issues/peek-overview/comment/add-comment.tsx (1 hunks)
  • space/core/constants/editor.ts (3 hunks)
  • web/core/components/editor/lite-text-editor/lite-text-editor.tsx (3 hunks)
  • web/core/components/editor/lite-text-editor/toolbar.tsx (3 hunks)
  • web/core/components/pages/editor/header/color-dropdown.tsx (1 hunks)
  • web/core/components/pages/editor/header/toolbar.tsx (6 hunks)
  • web/core/constants/editor.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • space/core/components/issues/peek-overview/comment/add-comment.tsx
🧰 Additional context used
🪛 Biome
packages/editor/src/core/types/editor.ts

[error] 60-60: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

🔇 Additional comments (58)
packages/editor/src/core/extensions/text-align.ts (2)

1-6: Overall assessment: Good implementation with room for minor enhancements

The CustomTextAlignExtension implementation successfully introduces the required text alignment functionality, aligning well with the PR objectives. It provides a solid foundation for text alignment in various editor contexts.

Key points:

  1. The implementation is correct and focused.
  2. It supports the required alignment options (left, center, right) for both headings and paragraphs.
  3. The code is clean and concise.

Suggested enhancements:

  1. Improve readability by using constants for alignment options and content types.
  2. Enhance extensibility by creating a function to generate the configured extension.
  3. Verify integration in different editor contexts to ensure comprehensive implementation.

These suggestions are minor improvements to an already solid implementation. Great job on introducing this feature!


1-6: Verify integration in different editor contexts

The CustomTextAlignExtension implementation looks good and provides the required text alignment functionality. To ensure it fully meets the PR objectives, we should verify its integration in various editor contexts.

Please run the following script to check if the CustomTextAlignExtension is being used in the relevant editor configurations for pages, issue descriptions, and comments:

This will help ensure that the text alignment feature is properly integrated across all required editor instances.

packages/editor/src/core/types/slash-commands-suggestion.ts (3)

Line range hint 1-22: Summary: Centralization of types improves maintainability, but requires careful verification.

The changes in this file are part of a larger refactoring effort to centralize type definitions, which can improve maintainability. However, to ensure a smooth transition, please:

  1. Verify that the new TEditorCommands definition in "@/types" includes all necessary command types.
  2. Check for any usage of the removed TColorEditorCommands and TNonColorEditorCommands types in the codebase and update them accordingly.
  3. Ensure that all parts of the codebase using TEditorCommands are compatible with its new definition.

These steps will help maintain backward compatibility and prevent potential runtime errors.


Line range hint 6-22: Verify backward compatibility and usage of removed types.

While CommandProps and ISlashCommandItem remain unchanged, which is good for compatibility, we need to ensure:

  1. The new TEditorCommands definition includes all previously available command types.
  2. There are no usages of the removed TColorEditorCommands and TNonColorEditorCommands types in the codebase.

Please run the following script to check for potential issues:

#!/bin/bash
# Description: Verify backward compatibility and usage of removed types

# Test 1: Check for usage of removed types
echo "Checking for usage of removed types:"
rg --type typescript "TColorEditorCommands|TNonColorEditorCommands"

# Test 2: Compare old and new TEditorCommands definitions
echo "Comparing old and new TEditorCommands definitions:"
git show HEAD:packages/editor/src/core/types/slash-commands-suggestion.ts | rg "export type TEditorCommands" -A 10
echo "---"
rg --type typescript "export type TEditorCommands" -A 10

If the script finds any usage of removed types or discrepancies in the TEditorCommands definition, please update the affected areas to maintain compatibility.


3-4: Approve centralization of TEditorCommands, but verify its new definition.

The centralization of TEditorCommands by importing it from "@/types" can improve maintainability. However, ensure that the new definition in "@/types" includes all necessary command types previously defined in this file.

Please run the following script to verify the new TEditorCommands definition:

✅ Verification successful

Verification Successful: TEditorCommands Centralized and Removed Unused Types

The centralization of TEditorCommands by importing it from @/types has been successfully verified. Additionally, TColorEditorCommands and TNonColorEditorCommands have been completely removed from the codebase, ensuring no deprecated or unused types remain.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new TEditorCommands definition and its usage

# Test 1: Check the new TEditorCommands definition
echo "Checking TEditorCommands definition:"
rg --type typescript "export type TEditorCommands" -A 10

# Test 2: Verify usage of TEditorCommands in the codebase
echo "Checking TEditorCommands usage:"
rg --type typescript "TEditorCommands"

Length of output: 524


Script:

#!/bin/bash
# Description: Verify the new TEditorCommands definition and its usage by searching .ts and .tsx files

# Test 1: Check the new TEditorCommands definition
echo "Checking TEditorCommands definition in .ts and .tsx files:"
rg "export type TEditorCommands" --glob "*.ts" --glob "*.tsx" -A 10

# Test 2: Verify usage of TEditorCommands in the codebase
echo "Checking TEditorCommands usage in .ts and .tsx files:"
rg "TEditorCommands" --glob "*.ts" --glob "*.tsx"

Length of output: 4530


Script:

#!/bin/bash
# Description: Verify the removal of TColorEditorCommands and TNonColorEditorCommands

# Test 1: Check for any remaining TColorEditorCommands definitions or usages
echo "Checking for any occurrences of TColorEditorCommands in .ts and .tsx files:"
rg "TColorEditorCommands" --glob "*.ts" --glob "*.tsx"

# Test 2: Check for any remaining TNonColorEditorCommands definitions or usages
echo "Checking for any occurrences of TNonColorEditorCommands in .ts and .tsx files:"
rg "TNonColorEditorCommands" --glob "*.ts" --glob "*.tsx"

Length of output: 440

packages/editor/src/core/extensions/index.ts (2)

19-19: LGTM: Addition of headers export

The addition of the ./headers export aligns with the PR objectives of enhancing text editing capabilities.


25-25: LGTM: Addition of text-align export

The addition of the ./text-align export is consistent with the PR objectives of introducing text alignment features for various editors.

packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx (3)

1-12: LGTM: Imports and type definition are appropriate.

The imports cover all necessary dependencies for the component, including the Tiptap Editor, icons from lucide-react, and custom components/helpers. The Props type is correctly defined with the editor prop of type Editor.


1-89: LGTM: Overall implementation meets PR objectives.

The TextAlignmentSelector component successfully implements the text alignment functionality as specified in the PR objectives. It provides a user-friendly interface for selecting text alignment options (left, center, right) and integrates well with the Tiptap editor.

To ensure full compliance with the PR objectives, please verify the implementation of the keyboard shortcuts mentioned (Cmd + Shift + L for left, Cmd + Shift + E for center, and Cmd + Shift + R for right alignment). Run the following script to check for the keyboard shortcut implementations:

If the keyboard shortcuts are not found in the current file, they might be implemented in a parent component or a separate keyboard handler. Please ensure these shortcuts are properly implemented and connected to the alignment functions.


14-17: LGTM: Component definition and initial setup look good.

The TextAlignmentSelector is correctly defined as a functional component with proper prop typing. The editor prop is properly destructured for use within the component.

Please verify the implementation of the TextAlignItem function to ensure it returns the expected structure for the menuItem. Run the following script to check its implementation:

✅ Verification successful

Action Required: Verify the TextAlignItem function implementation using ast-grep.

Please run the following script to locate the TextAlignItem function definition:

[/run_scripts]


Action Required: Further verify the TextAlignItem function implementation using an updated search pattern.

Please run the following script to locate the TextAlignItem function definition with alternative declaration styles:

[/run_scripts]


Verified: The TextAlignItem function is correctly implemented and located in menu-items.ts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of TextAlignItem function

# Test: Search for the TextAlignItem function definition
rg --type typescript -A 10 'function TextAlignItem'

Length of output: 256


Script:

#!/bin/bash
# Description: Locate the TextAlignItem function definition using ast-grep

ast-grep --lang typescript --pattern 'function TextAlignItem($_) { $$$ }'

Length of output: 75


Script:

#!/bin/bash
# Description: Locate the TextAlignItem function definition using ast-grep with alternative patterns

# Pattern 1: Function expression
ast-grep --lang typescript --pattern 'const TextAlignItem = ($_): $_ => { $$$ }'

# Pattern 2: Arrow function
ast-grep --lang typescript --pattern 'const TextAlignItem = ($_): $_ => ($$$)'

Length of output: 870

space/core/components/editor/lite-text-editor.tsx (2)

70-70: LGTM! Simplified prop passing.

The direct passing of editorRef improves code readability and maintainability. Good job!


3-3: LGTM! Consider verifying unused imports.

The import statement has been updated correctly. The removal of TNonColorEditorCommands suggests it's no longer used in this file.

To ensure all imports are being used and no unnecessary imports remain, run the following script:

packages/editor/package.json (1)

51-51: LGTM! Verify compatibility with existing dependencies.

The addition of "@tiptap/extension-text-align" is appropriate for implementing the text alignment features described in the PR objectives. The version "^2.8.0" allows for compatible updates, which is a good practice.

To ensure compatibility, please run the following script:

packages/editor/src/core/extensions/core-without-props.ts (3)

21-21: LGTM: New import statement for text alignment extension.

The import statement for CustomTextAlignExtension is correctly added and follows the existing pattern in the file. The naming convention is consistent with other custom extensions.


21-21: Overall assessment: Changes align well with PR objectives.

The addition of the CustomTextAlignExtension import and its inclusion in the CoreEditorExtensionsWithoutProps array effectively implements the text alignment feature as described in the PR objectives. These changes are minimal and focused, maintaining the existing structure of the file while enhancing the editor's capabilities.

The implementation supports the goal of introducing text alignment features (Left, Center, Right) for various editors within the application. To fully meet the PR objectives, ensure that:

  1. The toolbar in the editor interface includes options for text alignment.
  2. Keyboard shortcuts (Cmd + Shift + L, Cmd + Shift + E, Cmd + Shift + R) are properly implemented for text alignment.

These aspects might be handled in other files not included in this review.

Also applies to: 91-91


91-91: LGTM: Text alignment extension added successfully.

The CustomTextAlignExtension is correctly added to the CoreEditorExtensionsWithoutProps array. This addition aligns with the PR objectives to introduce text alignment features for various editors.

Could you confirm if any configuration options are needed for the CustomTextAlignExtension? If not, that's fine, but it's worth verifying to ensure we're not missing any important settings.

✅ Verification successful

Action Required: Update Shell Script with Correct Type for ripgrep

The initial script failed because typescript is not a recognized file type for rg. Please update the script to use the correct type identifier, such as ts, and rerun it to verify if the CustomTextAlignExtension has any configuration options.


Verified: Configuration options found for CustomTextAlignExtension.

The CustomTextAlignExtension includes configuration options for alignments and types, ensuring that it functions as intended and aligns with the PR objectives to introduce text alignment features.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if CustomTextAlignExtension has any configuration options

# Test: Search for the CustomTextAlignExtension definition
rg --type typescript -A 10 'export const CustomTextAlignExtension'

Length of output: 103


Script:

#!/bin/bash
# Description: Check if CustomTextAlignExtension has any configuration options

# Test: Search for the CustomTextAlignExtension definition using the correct file type
rg --type ts -A 10 'export const CustomTextAlignExtension'

Length of output: 404

packages/editor/src/core/components/menus/bubble-menu/node-selector.tsx (2)

23-23: LGTM: New type import enhances type safety.

The addition of TEditorCommands import from @/types is a good practice for improving type safety and code organization.


34-34: Approve: Enhanced type safety for editor menu items.

The updated type signature EditorMenuItem<TEditorCommands>[] for items improves type safety by specifying the command types associated with each menu item. This change aligns well with the new TEditorCommands import and likely contributes to a more robust typing system for the editor.

To ensure consistency across the codebase, please run the following script to check for other occurrences of EditorMenuItem that might need similar updates:

This will help identify any inconsistencies in the usage of EditorMenuItem across the project.

✅ Verification successful

Approve: Enhanced type safety for editor menu items.

The updated type signature EditorMenuItem<TEditorCommands>[] for items improves type safety by specifying the command types associated with each menu item. This change aligns well with the new TEditorCommands import and contributes to a more robust typing system for the editor. Verified that all EditorMenuItem usages are consistent with the updated generic type parameter.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other occurrences of EditorMenuItem that might need updating

# Search for EditorMenuItem usage without generic type parameter
echo "Searching for EditorMenuItem usage without generic type parameter:"
rg --type typescript "EditorMenuItem(\s*\[|[^<])" -g '!node_modules'

# Search for EditorMenuItem usage with generic type parameter
echo "Searching for EditorMenuItem usage with generic type parameter:"
rg --type typescript "EditorMenuItem\s*<" -g '!node_modules'

Length of output: 483


Script:

#!/bin/bash
# Description: Check for other occurrences of EditorMenuItem that might need updating

# Search for EditorMenuItem usage without generic type parameter
echo "Searching for EditorMenuItem usage without generic type parameter:"
rg --type ts "EditorMenuItem(\s*\[|[^<])" -g '!node_modules'

# Search for EditorMenuItem usage with generic type parameter
echo "Searching for EditorMenuItem usage with generic type parameter:"
rg --type ts "EditorMenuItem\s*<" -g '!node_modules'

Length of output: 4686

packages/editor/src/core/extensions/read-only-extensions.tsx (2)

130-130: LGTM: CustomTextAlignExtension successfully added

The addition of CustomTextAlignExtension to the CoreReadOnlyEditorExtensions array is correct and aligns with the PR objectives of introducing text alignment features for various editors. The import and placement of the extension are appropriate.


Line range hint 1-131: Verify completeness of text alignment implementation

The addition of CustomTextAlignExtension is a good start for implementing text alignment features. However, to ensure full functionality:

  1. Verify that CustomTextAlignExtension is properly configured to handle left, center, and right alignments.
  2. Check if any UI components (e.g., toolbar buttons) need to be added or modified to utilize this extension.
  3. Ensure that keyboard shortcuts (Cmd + Shift + L, Cmd + Shift + E, Cmd + Shift + R) are properly set up to work with this extension.
  4. Consider adding unit tests to verify the behavior of the new text alignment features.

To check for any related changes, run the following script:

web/core/components/editor/lite-text-editor/lite-text-editor.tsx (4)

67-68: LGTM! Verify impact of variable relocation.

The isEmpty variable has been moved within the component. While this doesn't change its functionality, it's important to ensure that this relocation doesn't affect any other part of the component that might have depended on its previous scope.

To verify the impact of this change, run the following script:

#!/bin/bash
# Description: Check usage of isEmpty variable in the component

# Test: Look for uses of isEmpty variable
rg --type typescript -A 5 '\bisEmpty\b' web/core/components/editor/lite-text-editor/lite-text-editor.tsx

69-69: LGTM! Ensure consistent usage of editorRef.

The introduction of editorRef simplifies access to the editor's ref throughout the component. This is a good refactoring that improves code readability and type safety.

To ensure editorRef is used consistently, run the following script:

#!/bin/bash
# Description: Check usage of editorRef variable in the component

# Test: Look for uses of editorRef and ref variables
rg --type typescript -A 5 '\b(editorRef|ref)\b' web/core/components/editor/lite-text-editor/lite-text-editor.tsx

92-98: LGTM with suggestions. Address TODO and type assertion.

The refactoring of executeCommand simplifies the command execution logic and aligns with the earlier introduction of editorRef. However, there are two points that need attention:

  1. There's a TODO comment on line 93 about toolbar homogenization. This should be addressed or tracked as a separate issue.
  2. There's a type assertion (@ts-expect-error) on line 94. It's generally better to avoid type assertions if possible. Consider investigating why this type mismatch occurs and if it can be resolved without the assertion.

To investigate the type mismatch, run the following script:

#!/bin/bash
# Description: Investigate type mismatch in executeCommand

# Test: Look for the definition of executeMenuItemCommand
ast-grep --lang typescript --pattern 'executeMenuItemCommand($$$)' web/core/components/editor/lite-text-editor/lite-text-editor.tsx

# Test: Look for the type definition of EditorRefApi
rg --type typescript -A 10 'type EditorRefApi' web/core/components/editor/lite-text-editor/lite-text-editor.tsx

Would you like assistance in resolving the type mismatch or creating an issue to track the TODO?


3-3: LGTM! Consider verifying unused imports.

The import statement has been updated to include necessary types and components. This change aligns with the refactoring of editor-related entities.

To ensure all imports are being used and no unnecessary imports remain, run the following script:

packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx (3)

Line range hint 1-108: Summary of changes: Improved color selection implementation

The changes in this file enhance the color selection functionality for both text and background colors. The new implementation uses a more structured approach to pass color parameters, which improves type safety and code clarity. These modifications align well with the PR objectives and contribute to the overall enhancement of the editor's features.

Key points:

  1. Consistent parameter passing for both text and background color selection.
  2. Improved type safety and API design.
  3. Changes are localized and don't introduce any breaking changes to the component's interface.

67-67: Approve the structured parameter passing for text color.

The change to pass the color key as a named property in an object ({ color: color.key }) improves type safety and clarity. This is a good practice for API design.

To ensure consistency, let's verify the TextColorItem implementation:

✅ Verification successful

Re-running the search using TypeScript file extensions.

To locate the TextColorItem implementation, let's search specifically within .ts and .tsx files.


Verification Successful: TextColorItem Supports Structured Parameter

The TextColorItem implementation correctly accepts an object with a color property, ensuring that the recent change enhances type safety and clarity without causing inconsistencies.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the TextColorItem implementation accepts the new parameter structure.

# Test: Search for the TextColorItem definition
rg --type typescript -A 10 'export const TextColorItem'

Length of output: 98


Script:

#!/bin/bash
# Description: Verify the TextColorItem implementation accepts the new parameter structure.

# Test: Search for the TextColorItem definition using TypeScript file extensions.
rg --glob '*.ts' --glob '*.tsx' -A 10 'export const TextColorItem'

Length of output: 1111


90-90: Approve the consistent parameter passing for background color.

The change to pass the color key as a named property in an object ({ color: color.key }) for background color selection maintains consistency with the text color implementation. This unified approach improves the overall code quality and maintainability.

To ensure consistency, let's verify the BackgroundColorItem implementation:

✅ Verification successful

To accurately locate the BackgroundColorItem implementation, let's run a corrected search:


To successfully locate the BackgroundColorItem implementation, let's use file globs to target .ts and .tsx files:


Approve the consistent parameter passing for background color.

The command function in BackgroundColorItem correctly accepts an object with a color property. Passing { color: color.key } aligns with the expected parameter structure, ensuring consistency and maintainability.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the BackgroundColorItem implementation accepts the new parameter structure.

# Test: Search for the BackgroundColorItem definition
rg --type typescript -A 10 'export const BackgroundColorItem'

Length of output: 98


Script:

#!/bin/bash
# Description: Correctly search for the BackgroundColorItem definition in TypeScript files.

# Test: Search for the BackgroundColorItem definition using the correct TypeScript file types.
rg --type ts,tsx -A 10 'export const BackgroundColorItem'

Length of output: 90


Script:

#!/bin/bash
# Description: Search for the BackgroundColorItem definition in .ts and .tsx files.

# Test: Search for the BackgroundColorItem definition using file globs.
rg 'export const BackgroundColorItem' --glob '*.ts' --glob '*.tsx' -A 10

Length of output: 1138

packages/editor/src/core/extensions/extensions.tsx (1)

21-21: LGTM: Import of CustomTextAlignExtension

The addition of CustomTextAlignExtension to the import statement is correct and follows the existing naming convention for custom extensions. This change aligns with the PR objective of introducing text alignment features.

web/core/components/pages/editor/header/color-dropdown.tsx (2)

12-19: Great improvement in type safety!

The update to the Props type definition enhances type safety by restricting the key parameter in both handleColorSelect and isColorActive to only "text-color" and "background-color". This change:

  1. Ensures that only specific command types can be passed as arguments.
  2. Aligns with the updated import statement.
  3. Maintains backwards compatibility as the function signatures remain unchanged.

This refinement contributes to a more robust and maintainable codebase.


7-7: LGTM! Verify the updated import usage.

The change from TColorEditorCommands to TEditorCommands aligns with the type updates in the Props interface and suggests a refactoring to use a more generic type for editor commands. This is consistent with the PR objectives of enhancing text alignment features.

To ensure the change is applied consistently, run the following script:

✅ Verification successful

Action Required: Update Verification Script to Correct Type Definitions

The previous verification script failed due to an unrecognized file type typescript in rg. Please use the following updated script to accurately search TypeScript files:


Verified: Import Replacement Successful

All instances of TColorEditorCommands have been successfully replaced with TEditorCommands across the codebase. The import change is consistent and aligns with the PR objectives.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of TEditorCommands across the codebase

# Test: Search for any remaining usage of TColorEditorCommands
rg --type typescript 'TColorEditorCommands'

# Test: Confirm the usage of TEditorCommands in relevant files
rg --type typescript 'TEditorCommands'

Length of output: 152


Script:

#!/bin/bash
# Description: Verify the usage of TEditorCommands across the codebase

# Test: Search for any remaining usage of TColorEditorCommands in .ts and .tsx files
rg --glob '*.ts' --glob '*.tsx' 'TColorEditorCommands'

# Test: Confirm the usage of TEditorCommands in relevant .ts and .tsx files
rg --glob '*.ts' --glob '*.tsx' 'TEditorCommands'

Length of output: 3685

web/core/components/pages/editor/header/toolbar.tsx (6)

6-6: LGTM: Explicit import of EditorRefApi

The addition of this import improves type safety and makes the dependencies of this component more explicit.


95-96: LGTM: Consistent use of itemKey and extraProps

The update to isMenuItemActive is consistent with the changes made elsewhere in the file. This improves the overall consistency of how toolbar items are handled.


116-116: LGTM: Consistent use of renderKey for React key prop

The update to use item.renderKey as the key for CustomMenu.MenuItem is a good change. It ensures consistency with other parts of the component and follows React best practices for list rendering.


120-121: LGTM: Consistent use of itemKey and extraProps

The update to executeMenuItemCommand is consistent with the changes made elsewhere in the file. This improves the overall consistency of how toolbar items are handled and executed.


129-131: LGTM: Consistent use of itemKey for active item check

The update to use activeTypography?.itemKey for checking the active item is consistent with the changes made elsewhere in the file. This improves the overall consistency of how active toolbar items are identified.


153-155: LGTM: Consistent use of renderKey for React key prop and active state tracking

The updates to use item.renderKey as the key for ToolbarButton and for tracking active states are good changes. They ensure consistency with other parts of the component and follow React best practices for list rendering and state management.

packages/editor/src/core/components/menus/bubble-menu/root.tsx (4)

18-19: LGTM: Import of TextAlignmentSelector

The import of TextAlignmentSelector aligns with the PR objectives of adding text alignment features. The import statement follows correct syntax and naming conventions.


Line range hint 136-153: LGTM: Updated rendering logic for formatting buttons

The rendering logic for formatting buttons has been successfully updated to use basicFormattingOptions. This change is consistent with the earlier variable renaming and maintains the existing functionality. The conditional rendering based on the isActive state ensures proper visual feedback for active formatting options.


Line range hint 1-159: Summary: Successful integration of text alignment features

The changes to EditorBubbleMenu successfully integrate text alignment functionality into the editor. Key improvements include:

  1. Addition of the TextAlignmentSelector component.
  2. Refactoring of formatting options logic for better code organization.
  3. Consistent updates to the rendering logic.

These changes align well with the PR objectives and enhance the editor's capabilities. The implementation follows React best practices and maintains good code readability.

To ensure complete functionality:

  1. Verify the TextAlignmentSelector implementation in alignment-selector.tsx.
  2. Confirm that all specified alignment options (Left, Center, Right) are available.
  3. Test the keyboard shortcuts (Cmd + Shift + L/E/R) for alignment.

Overall, this is a solid enhancement to the editor's functionality.


155-155: Approved: Addition of TextAlignmentSelector

The inclusion of the TextAlignmentSelector component aligns with the PR objectives of introducing text alignment features. It's correctly placed within the EditorBubbleMenu structure and receives the necessary editor prop.

To ensure full functionality:

  1. Verify that the TextAlignmentSelector component is correctly implemented in the alignment-selector.tsx file.
  2. Confirm that it handles the text alignment options (Left, Center, Right) as specified in the PR objectives.
  3. Check if the component implements the keyboard shortcuts (Cmd + Shift + L/E/R) for alignment.
packages/editor/src/core/hooks/use-editor.ts (2)

142-142: Simplified command execution logic: Approved

This change simplifies the executeMenuItemCommand method by passing the entire props object to the command function. This refactoring improves code maintainability and flexibility, making it easier to add new menu item types in the future without modifying this method. It also reduces the risk of errors that could occur with type-specific conditional checks.


Line range hint 142-155: Overall assessment: Improved menu item handling

The changes in this file significantly improve the handling of menu items in the editor. By simplifying both the executeMenuItemCommand and isMenuItemActive methods, the code becomes more maintainable and flexible. This refactoring aligns well with the PR objectives of introducing text alignment features, as it makes it easier to add new menu items without modifying the core logic.

These changes contribute to a more robust and extensible editor implementation, which will facilitate the integration of the new text alignment features and potential future enhancements.

packages/editor/src/styles/editor.css (1)

195-195: LGTM! Consider verifying responsive behavior.

The increase in max-width for .tippy-box from 400px to 600px is a good improvement that allows for more content in tooltips or popovers. This change aligns well with the PR objectives of enhancing text alignment features.

To ensure this change doesn't cause layout issues on smaller screens, please run the following verification script:

space/core/components/editor/toolbar.tsx (2)

65-97: Code logic and rendering appear correct

The rendering logic for toolbar items and the management of active states are implemented correctly. The use of activeStates and conditional classes ensures the toolbar reflects the current editor state accurately.


14-14: Verify prop type changes in dependent components

The prop types for executeCommand and editorRef have been updated. Ensure that all components using IssueCommentToolbar are passing the correct types for these props to prevent any type-related issues.

Run the following script to find usages of IssueCommentToolbar and check prop types:

Also applies to: 19-19

packages/editor/src/core/types/editor.ts (1)

88-89: Enhanced type safety in method signatures

The updated method signatures for executeMenuItemCommand and isMenuItemActive now utilize generic type parameters with TCommandWithPropsWithItemKey<T>. This improvement enhances type safety and ensures that the methods are used correctly with the appropriate command props.

web/core/constants/editor.ts (12)

36-38: Correct Implementation of ExtraPropsForCommand Utility Type

The ExtraPropsForCommand type is correctly defined using conditional types to ensure that extraProps are properly typed based on the command. This enhances type safety and code maintainability.


50-57: Improved Type Safety for TYPOGRAPHY_ITEMS

By specifying the generic type ToolbarMenuItem<"text" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6">, you enhance type safety for the TYPOGRAPHY_ITEMS array, restricting itemKey to the specified commands. This is a good practice to prevent unintended errors.


60-94: Addition of TEXT_ALIGNMENT_ITEMS

The introduction of TEXT_ALIGNMENT_ITEMS correctly extends the toolbar functionality to include text alignment options, aligning with the PR objective to add text alignment features. The integration appears consistent with existing patterns.


66-67: Ensure Consistency of Keyboard Shortcuts Across Platforms

The shortcuts ["Cmd", "Shift", "L"], ["Cmd", "Shift", "E"], and ["Cmd", "Shift", "R"] are specified for text alignment. Please ensure that these shortcuts are mapped appropriately for non-Mac platforms (e.g., using Ctrl instead of Cmd) to provide a consistent user experience.


69-92: Confirm Proper Handling of extraProps in Command Execution

The extraProps field is used to pass the alignment property to the command handler. Verify that the command execution logic for "text-align" correctly utilizes extraProps.alignment to apply the desired text alignment.


96-120: Consistent Type Annotations in BASIC_MARK_ITEMS

The BASIC_MARK_ITEMS array now includes a generic type parameter, enhancing type safety. The items correctly specify the editors array to indicate where they are applicable.


131-150: Enhanced Type Safety in LIST_ITEMS

The type annotations for LIST_ITEMS are updated to specify the exact command keys. This improves type checking and reduces potential runtime errors.


158-160: Validation of USER_ACTION_ITEMS Configuration

The USER_ACTION_ITEMS array is correctly updated with the generic type parameter and maintains consistency with other toolbar item definitions.


163-165: Proper Configuration of COMPLEX_ITEMS

The COMPLEX_ITEMS array now includes proper type annotations and integrates the extraProps where necessary.


170-182: Integration of TEXT_ALIGNMENT_ITEMS into TOOLBAR_ITEMS

The TOOLBAR_ITEMS object includes the new alignment category for both lite and document editors. Filtering based on the editor type is correctly implemented.


175-182: Verify Filtering Logic in TOOLBAR_ITEMS

Ensure that the .filter method accurately filters toolbar items based on the editors array. This is crucial to display the correct toolbar options for each editor type.


3-5: Verify Usage of Imported Icons

The icons AlignCenter, AlignLeft, and AlignRight are newly imported. Please ensure these icons are utilized within the codebase to avoid unnecessary imports.

Run the following script to check if the imported icons are used:

✅ Verification successful

Imported icons are properly utilized across the codebase.

All imported icons (AlignCenter, AlignLeft, and AlignRight) are actively used within the codebase, ensuring there are no unnecessary imports.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the imported icons are used in the file.

# Test: Search for usages of the imported icons.
for icon in "AlignCenter" "AlignLeft" "AlignRight"; do
  usage_count=$(rg -c "$icon" web/core/constants/editor.ts)
  if [ "$usage_count" -le 1 ]; then
    echo "Icon $icon might be unused."
  fi
done

Length of output: 407


Script:

#!/bin/bash
# Description: Verify that the imported icons are used across the entire codebase.

# Test: Search for usages of the imported icons in all files except the constants file.
for icon in "AlignCenter" "AlignLeft" "AlignRight"; do
  usage_count=$(rg -c "$icon" --glob '!web/core/constants/editor.ts' .)
  if [ "$usage_count" -eq 0 ]; then
    echo "Icon $icon might be unused across the codebase."
  fi
done

Length of output: 2222


Script:

#!/bin/bash
# Description: Verify that the imported icons are used across the entire codebase.

# Test: Search for total usages of the imported icons in all files except the constants file.
for icon in "AlignCenter" "AlignLeft" "AlignRight"; do
  usage_count=$(rg "$icon" --glob '!web/core/constants/editor.ts' -o | wc -l)
  if [ "$usage_count" -eq 0 ]; then
    echo "Icon $icon might be unused across the codebase."
  fi
done

Length of output: 464

packages/editor/src/core/components/menus/menu-items.ts Outdated Show resolved Hide resolved
packages/editor/src/core/components/menus/menu-items.ts Outdated Show resolved Hide resolved
packages/editor/src/core/components/menus/menu-items.ts Outdated Show resolved Hide resolved
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: 12

🧹 Outside diff range and nitpick comments (17)
packages/editor/src/core/extensions/text-align.ts (1)

1-6: Consider adding documentation to improve code maintainability.

To enhance code readability and maintainability, consider adding comments or documentation to explain the purpose of this file and how to use the CustomTextAlignExtension. This will be helpful for other developers who might work on this code in the future.

Here's a suggestion for documentation:

/**
 * Custom Text Alignment Extension
 * 
 * This file configures and exports a custom text alignment extension for the editor.
 * It uses the TextAlign extension from @tiptap/extension-text-align and configures
 * it with specific alignment options and content types.
 * 
 * Usage:
 * Import this extension and add it to your Tiptap editor's extension array.
 */

import TextAlign from "@tiptap/extension-text-align";

export const CustomTextAlignExtension = TextAlign.configure({
  alignments: ["left", "center", "right"],
  types: ["heading", "paragraph"],
});
packages/editor/src/core/types/slash-commands-suggestion.ts (1)

Line range hint 6-21: LGTM with a minor suggestion for consistency

The changes to the ISlashCommandItem interface, specifically the commandKey property, correctly reference the newly imported TEditorCommands type. The rest of the type definitions remain unchanged, which helps maintain compatibility with existing code.

For consistency with the new import style, consider using the full import path for the React types as well. This change is optional but could improve consistency across the codebase:

-import { CSSProperties } from "react";
+import type { CSSProperties } from "react";

This change emphasizes that we're importing a type and matches the style used for TEditorCommands.

packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx (2)

14-17: LGTM: Component declaration and setup look good.

The TextAlignmentSelector component is correctly declared as a React functional component with proper prop typing. The use of TextAlignItem suggests good integration with existing functionality.

Consider using object destructuring in the function parameters for cleaner code:

-export const TextAlignmentSelector: React.FC<Props> = (props) => {
-  const { editor } = props;
+export const TextAlignmentSelector: React.FC<Props> = ({ editor }) => {

67-88: LGTM: Rendering logic is clean and efficient.

The component's rendering logic is well-implemented, using React's mapping function to generate buttons for each alignment option. The use of Tailwind CSS classes and the cn helper function provides flexible and conditional styling.

To improve accessibility, consider adding an aria-label to each button to describe its function:

 <button
   key={item.renderKey}
   type="button"
+  aria-label={`Align text ${item.renderKey.split('-').pop()}`}
   onClick={(e) => {
     item.command();
     e.stopPropagation();
   }}
   className={cn(
     // ... (existing classes)
   )}
 >
   <item.icon className="size-4" />
 </button>
space/core/components/editor/lite-text-editor.tsx (1)

70-70: LGTM. Consider moving editorRef derivation.

The simplification of passing editorRef directly to IssueCommentToolbar is a good change. It removes unnecessary conditional logic and makes the code more readable.

To further improve code readability and maintainability, consider moving the editorRef derivation closer to where it's used. This would make the connection between the derivation and its usage more apparent. For example:

const editorRef = isMutableRefObject<EditorRefApi>(ref) ? ref.current : null;

return (
  <div className="border border-custom-border-200 rounded p-3 space-y-3">
    <LiteTextEditorWithRef
      // ... other props ...
    />
    <IssueCommentToolbar
      // ... other props ...
      editorRef={editorRef}
    />
  </div>
);

This change would group related logic together and make the component's structure easier to understand at a glance.

packages/editor/src/core/extensions/core-without-props.ts (1)

21-21: Consider additional improvements for text alignment feature

The addition of CustomTextAlignExtension successfully introduces text alignment functionality to the editor. However, consider the following improvements:

  1. If not implemented elsewhere, add configuration options to CustomTextAlignExtension to allow for customization of alignment options or default behavior.
  2. Ensure that the new extension doesn't conflict with existing extensions, especially those that might affect text positioning or layout.
  3. If keyboard shortcuts are not implemented in this extension, make sure they are properly set up in the appropriate part of the codebase to fulfill the PR objectives.

Would you like assistance in implementing any of these suggestions?

Also applies to: 91-91

packages/editor/src/core/extensions/read-only-extensions.tsx (1)

Line range hint 1-132: Summary of changes and recommendations

The changes to this file are minimal and focused on adding the CustomTextAlignExtension. The implementation follows existing patterns and is technically correct. However, there's a potential logical inconsistency:

  1. The function is named CoreReadOnlyEditorExtensions, implying these extensions are for a read-only editor.
  2. Adding a text alignment feature to a read-only editor seems counterintuitive, as users typically can't modify text in a read-only context.

Recommendations:

  1. Clarify the intended behavior of CustomTextAlignExtension in a read-only context.
  2. If it's meant to display aligned text rather than allow alignment changes, consider adding a comment explaining this.
  3. If it's not meant for read-only use, consider creating a separate function for editable editor extensions or renaming this function to reflect its actual purpose.

These clarifications will improve code maintainability and prevent confusion for future developers working on this codebase.

web/core/components/editor/lite-text-editor/lite-text-editor.tsx (1)

69-69: LGTM! Consider using optional chaining for clarity.

The addition of the editorRef variable improves the code by simplifying the ref handling. To further enhance readability, consider using optional chaining:

const editorRef = isMutableRefObject(ref) ? ref.current : null;

This change would make it clear that ref.current is only accessed if ref is a mutable ref object.

packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx (1)

90-90: Consistent improvement for background color selection

The modification to pass an object { color: color.key } instead of just color.key to the BackgroundColorItem(editor).command() function is consistent with the text color change. This enhances type safety and improves API clarity.

Consider refactoring the color selection logic to reduce duplication between text and background color handling. For example:

const handleColorSelection = (ColorItem: typeof TextColorItem | typeof BackgroundColorItem, color: string | undefined) => {
  ColorItem(editor).command(color ? { color } : undefined);
};

// Usage
onClick={() => handleColorSelection(TextColorItem, color.key)}
onClick={() => handleColorSelection(BackgroundColorItem, color.key)}

This refactoring would centralize the color selection logic and make future changes easier to manage.

web/core/components/pages/editor/header/color-dropdown.tsx (1)

12-19: LGTM! Consider extracting the type for improved readability.

The type definitions for handleColorSelect and isColorActive have been updated to use Extract<TEditorCommands, "text-color" | "background-color"> instead of TColorEditorCommands. This change improves type safety by restricting the allowed values to "text-color" and "background-color".

To improve readability, consider extracting the new type into a separate type alias:

type ColorEditorCommands = Extract<TEditorCommands, "text-color" | "background-color">;

type Props = {
  handleColorSelect: (key: ColorEditorCommands, color: string | undefined) => void;
  isColorActive: (key: ColorEditorCommands, color: string | undefined) => boolean;
};

This extraction would make the Props type more concise and easier to understand at a glance.

web/core/components/pages/editor/header/toolbar.tsx (2)

116-131: LGTM: Improved TYPOGRAPHY_ITEMS handling with a minor suggestion

The updates to the TYPOGRAPHY_ITEMS mapping are well-implemented and consistent with the changes made elsewhere in the file. The use of renderKey for the React key and itemKey for functionality improves the separation of concerns.

These changes align well with the PR objectives of introducing text alignment features.

Consider extracting the onClick handler into a separate function for improved readability:

const handleTypographyItemClick = (item: TypographyItem) => {
  editorRef.executeMenuItemCommand({
    itemKey: item.itemKey,
    ...item.extraProps,
  });
};

// Then in the JSX:
onClick={() => handleTypographyItemClick(item)}

This would make the JSX more concise and easier to read.


Line range hint 1-163: Overall improvements with some follow-up tasks

The changes in this file significantly improve the consistency and type safety of the toolbar implementation. The introduction of renderKey and itemKey effectively separates React-specific concerns from functionality, which is a good practice. These modifications lay a solid foundation for implementing the text alignment features described in the PR objectives.

However, there are a few items that need attention:

  1. Address the TODOs related to toolbar homogenization.
  2. Resolve the type mismatches currently marked with @ts-expect-error.
  3. Remove any remaining commented-out debug code (e.g., console.log statements).

To ensure a smooth integration of the text alignment features:

  1. Verify that the TOOLBAR_ITEMS constant includes the new text alignment options.
  2. Ensure that the EditorRefApi includes methods for applying and checking text alignment.
  3. Consider adding unit tests for the new text alignment functionality in the toolbar.

Would you like assistance in creating tasks for these follow-up items?

packages/editor/src/core/helpers/editor-commands.ts (1)

184-186: Approve with suggestions: Enhance robustness and consistency of setTextAlign

The setTextAlign function successfully implements the text alignment feature, which aligns with the PR objectives. However, consider the following improvements:

  1. Add error handling for invalid alignments to prevent potential runtime errors.
  2. Include a range parameter for consistency with other functions in this file.
  3. Consider implementing a toggle functionality for better user experience.

Here's a suggested implementation incorporating these improvements:

export const setTextAlign = (alignment: 'left' | 'center' | 'right' | 'justify', editor: Editor, range?: Range) => {
  if (range) {
    editor.chain().focus().deleteRange(range).setTextAlign(alignment).run();
  } else if (editor.isActive({ textAlign: alignment })) {
    editor.chain().focus().unsetTextAlign().run();
  } else {
    editor.chain().focus().setTextAlign(alignment).run();
  }
};

This implementation:

  • Uses a union type for alignment to prevent invalid inputs.
  • Includes an optional range parameter for consistency.
  • Implements a toggle functionality by unsetting the alignment if it's already active.
packages/editor/src/core/hooks/use-editor.ts (3)

142-142: Approve change with suggestion for improved type safety

The modification to pass the entire props object to the command function simplifies the logic and increases flexibility, which aligns well with the PR objective of introducing text alignment features. This change allows for easier addition of new commands without modifying this method.

However, to maintain type safety and prevent passing unnecessary data to commands, consider using a generic type parameter:

executeMenuItemCommand: <T extends { itemKey: TEditorCommands }>(props: T) => {
  const { itemKey } = props;
  const editorItems = getEditorMenuItems(editorRef.current);
  const getEditorMenuItem = (itemKey: TEditorCommands) => editorItems.find((item) => item.key === itemKey);
  const item = getEditorMenuItem(itemKey);
  if (item) {
    (item.command as (props: T) => void)(props);
  } else {
    console.warn(`No command found for item: ${itemKey}`);
  }
},

This approach ensures that only the necessary properties are passed to each command while maintaining flexibility.


155-155: Approve change with suggestion for improved type safety

The modification to pass the entire props object to the isActive function is consistent with the change in executeMenuItemCommand. This change increases flexibility and supports the PR objective by allowing for easier implementation of new active state checks, such as for text alignment features.

To maintain type safety and consistency with the previous suggestion, consider using a generic type parameter here as well:

isMenuItemActive: <T extends { itemKey: TEditorCommands }>(props: T) => {
  const { itemKey } = props;
  const editorItems = getEditorMenuItems(editorRef.current);
  const getEditorMenuItem = (itemKey: TEditorCommands) => editorItems.find((item) => item.key === itemKey);
  const item = getEditorMenuItem(itemKey);
  if (!item) return false;
  return (item.isActive as (props: T) => boolean)(props);
},

This approach ensures type safety while maintaining the flexibility introduced by the change.


Line range hint 1-285: Summary: Changes support PR objectives with room for type safety improvements

The modifications to executeMenuItemCommand and isMenuItemActive methods effectively support the PR objective of introducing text alignment features. By passing the entire props object, the changes increase the flexibility and extensibility of the editor's command system, allowing for easy addition of new features without modifying these core methods.

The changes align well with the implementation of text alignment features, as they can now be easily integrated into the existing command structure. This approach will facilitate the addition of toolbar buttons and keyboard shortcuts for left, center, and right alignment as specified in the PR objectives.

To further improve the implementation:

  1. Consider the suggested type safety enhancements to maintain robustness while preserving flexibility.
  2. Ensure that the new text alignment commands (Cmd + Shift + L, Cmd + Shift + E, Cmd + Shift + R) are properly integrated into the editor's command system.
  3. Verify that the toolbar for text alignment options is correctly implemented and interacts with these modified methods as expected.

As you proceed with the implementation of text alignment features, consider the following architectural advice:

  1. Implement a consistent approach for adding new commands and active state checks across the codebase.
  2. Document the new command structure and how to extend it for future developers.
  3. Consider creating unit tests for the new text alignment functionality to ensure reliability and prevent regressions.
web/core/components/editor/lite-text-editor/toolbar.tsx (1)

71-71: Address the TODO comment regarding toolbar homogenization

There's a TODO comment indicating a pending update during toolbar homogenization. It's important to resolve this to maintain consistency across toolbars.

Would you like assistance in updating this code segment to complete the toolbar homogenization?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7d36d63 and e2bcf25.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (25)
  • packages/editor/package.json (1 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx (1 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx (2 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/node-selector.tsx (2 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/root.tsx (4 hunks)
  • packages/editor/src/core/components/menus/menu-items.ts (3 hunks)
  • packages/editor/src/core/extensions/core-without-props.ts (2 hunks)
  • packages/editor/src/core/extensions/extensions.tsx (2 hunks)
  • packages/editor/src/core/extensions/index.ts (1 hunks)
  • packages/editor/src/core/extensions/read-only-extensions.tsx (2 hunks)
  • packages/editor/src/core/extensions/text-align.ts (1 hunks)
  • packages/editor/src/core/helpers/editor-commands.ts (1 hunks)
  • packages/editor/src/core/hooks/use-editor.ts (2 hunks)
  • packages/editor/src/core/types/editor.ts (2 hunks)
  • packages/editor/src/core/types/slash-commands-suggestion.ts (1 hunks)
  • packages/editor/src/styles/editor.css (1 hunks)
  • space/core/components/editor/lite-text-editor.tsx (3 hunks)
  • space/core/components/editor/toolbar.tsx (3 hunks)
  • space/core/components/issues/peek-overview/comment/add-comment.tsx (1 hunks)
  • space/core/constants/editor.ts (3 hunks)
  • web/core/components/editor/lite-text-editor/lite-text-editor.tsx (3 hunks)
  • web/core/components/editor/lite-text-editor/toolbar.tsx (3 hunks)
  • web/core/components/pages/editor/header/color-dropdown.tsx (1 hunks)
  • web/core/components/pages/editor/header/toolbar.tsx (6 hunks)
  • web/core/constants/editor.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • space/core/components/issues/peek-overview/comment/add-comment.tsx
🧰 Additional context used
🪛 Biome
packages/editor/src/core/types/editor.ts

[error] 60-60: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

🔇 Additional comments (69)
packages/editor/src/core/extensions/text-align.ts (3)

1-6: LGTM! The text alignment extension is correctly implemented.

The CustomTextAlignExtension is properly configured with the required alignment options ("left", "center", "right") and applicable content types ("heading", "paragraph"). This implementation aligns well with the PR objectives for introducing text alignment features.


1-6: Verify the integration of this extension with the editor.

While this file correctly exports the CustomTextAlignExtension, it's important to ensure that it's properly integrated with the editor and works with the TextAlignmentSelector component mentioned in the AI summary.

Let's verify the usage of this extension:

#!/bin/bash
# Description: Verify the integration of CustomTextAlignExtension with the editor

# Search for imports of CustomTextAlignExtension
rg --type typescript --type javascript "import.*CustomTextAlignExtension"

# Search for usage of CustomTextAlignExtension in editor configuration
rg --type typescript --type javascript "CustomTextAlignExtension" -C 5

Please ensure that the CustomTextAlignExtension is properly added to the editor's extension array and that it interacts correctly with the TextAlignmentSelector component.


1-6: Clarify the implementation of keyboard shortcuts.

The PR objectives mention keyboard shortcuts for text alignment (Cmd + Shift + L, Cmd + Shift + E, Cmd + Shift + R), but these are not visible in this implementation. Could you clarify where and how these shortcuts are being handled?

To verify the implementation of keyboard shortcuts, we can search for their usage in the codebase:

If the keyboard shortcuts are not yet implemented, would you like assistance in adding them to the appropriate component or handler?

packages/editor/src/core/types/slash-commands-suggestion.ts (1)

3-4: Verify the impact of centralizing TEditorCommands

The TEditorCommands type is now imported from a central location (@/types) instead of being defined in this file. While this change can improve maintainability, it's important to ensure that all other parts of the codebase that may have been importing TEditorCommands from this file have been updated accordingly.

Additionally, the removal of TColorEditorCommands and TNonColorEditorCommands types suggests a change in how editor commands are categorized or used. Please confirm that this removal doesn't negatively impact any existing functionality.

To ensure all usages have been updated, run the following script:

If these searches return results, those locations may need to be updated to reflect the new import location or to remove usage of the deleted types.

✅ Verification successful

Reattempting search with corrected file type for TypeScript

The previous search attempts failed because typescript is not a recognized file type in rg. Let's retry the searches using the correct file type or by specifying the file extensions directly.


Reattempting search using file extension patterns for TypeScript

The previous search attempts failed due to incorrect file type specifications. Let's retry the searches by directly specifying the .ts and .tsx file extensions to ensure accurate results.


Verification Successful: No residual imports or usages found

The searches for any remaining imports of TEditorCommands from slash-commands-suggestion.ts and usages of TColorEditorCommands or TNonColorEditorCommands returned no results. This indicates that the centralization and removal of these types have been properly handled across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining imports of TEditorCommands from this file

# Test: Search for imports of TEditorCommands from slash-commands-suggestion
rg --type typescript "import.*TEditorCommands.*from.*slash-commands-suggestion"

# Test: Search for uses of TColorEditorCommands and TNonColorEditorCommands
rg --type typescript "TColorEditorCommands|TNonColorEditorCommands"

Length of output: 221


Script:

#!/bin/bash
# Description: Check for any remaining imports of TEditorCommands from this file using the correct file type

# Test: Search for imports of TEditorCommands from slash-commands-suggestion
rg --type ts "import.*TEditorCommands.*from.*slash-commands-suggestion"

# Test: Search for uses of TColorEditorCommands and TNonColorEditorCommands
rg --type ts "TColorEditorCommands|TNonColorEditorCommands"

Length of output: 135


Script:

#!/bin/bash
# Description: Check for any remaining imports of TEditorCommands from slash-commands-suggestion using file extension patterns

# Test: Search for imports of TEditorCommands from slash-commands-suggestion in .ts and .tsx files
rg "import.*TEditorCommands.*from.*slash-commands-suggestion" --glob "*.ts" --glob "*.tsx"

# Test: Search for uses of TColorEditorCommands and TNonColorEditorCommands in .ts and .tsx files
rg "TColorEditorCommands|TNonColorEditorCommands" --glob "*.ts" --glob "*.tsx"

Length of output: 173

packages/editor/src/core/extensions/index.ts (3)

19-19: LGTM: Addition of headers export

The addition of export * from "./headers" aligns with the PR objective of introducing text alignment features. Headers are often used in text editors and may be related to text alignment functionality.


25-25: LGTM: Addition of text-align export

The addition of export * from "./text-align" directly relates to the PR objective of adding text alignment features. This module likely contains the core functionality for text alignment, which is a key component of this PR.


Line range hint 1-26: Verify discrepancies with AI summary

The AI-generated summary mentions the removal of exports for "./slash-commands" and "./headers", but these changes are not visible in the provided code. This could be due to limitations in the diff view or multiple commits in the PR.

To verify these discrepancies, please run the following script:

This script will help us understand if the mentioned removals actually occurred and if there were any intermediate changes not reflected in the final diff.

packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx (3)

1-12: LGTM: Imports and type definition are appropriate.

The imports cover all necessary dependencies for the component, including the Tiptap Editor, icon components, and custom helpers. The Props type is correctly defined with the editor prop of type Editor.


1-89: Great implementation of text alignment feature.

The TextAlignmentSelector component successfully implements the text alignment feature as described in the PR objectives. It provides options for left, center, and right alignment, which can be accessed through the editor's toolbar.

Key points:

  1. The component integrates well with the Tiptap editor, ensuring compatibility with keyboard shortcuts.
  2. The implementation is clean, efficient, and follows React best practices.
  3. The use of Tailwind CSS provides flexible and maintainable styling.

To ensure full compatibility with the PR objectives, please confirm that the keyboard shortcuts (Cmd + Shift + L, Cmd + Shift + E, Cmd + Shift + R) are properly set up in the Tiptap editor configuration. You can verify this by running the following script:

If the shortcuts are not found, consider adding them to the Tiptap editor configuration to fully meet the PR objectives.


19-65: LGTM: Text alignment options are well-defined.

The textAlignmentOptions array is structured correctly, covering left, center, and right alignments. Each option includes the necessary properties for rendering and functionality.

Could you clarify the purpose of the itemKey and renderKey properties? They seem potentially redundant, as itemKey is always "text-align" and renderKey appears to be a unique identifier. If they're used elsewhere in the application, please provide context. Otherwise, consider simplifying the option structure.

To verify the usage of these properties, you can run the following script:

space/core/components/editor/lite-text-editor.tsx (3)

36-37: LGTM. Good use of derived state.

The addition of the isEmpty variable is a good practice. It improves code readability by giving a clear name to the condition and allows for easy reuse of this derived state.

This change enhances the maintainability of the component by making the empty state check more explicit and easier to understand.


Line range hint 1-77: Overall assessment: Changes align with PR objectives, with minor improvements needed.

The modifications to the LiteTextEditor component align well with the PR objectives of introducing text alignment features across various editors. The changes to the editor commands and toolbar suggest progress towards implementing the text alignment functionality.

Key points:

  1. The updated import statements and command execution logic support the new text alignment feature.
  2. The simplification of editorRef handling improves code readability.
  3. The addition of the isEmpty variable enhances maintainability.

To fully meet the PR objectives, ensure that:

  1. The text alignment options (Left, Center, Right) are properly implemented in the IssueCommentToolbar.
  2. The keyboard shortcuts (Cmd + Shift + L/E/R) for text alignment are correctly set up.
  3. The text alignment feature works across all specified editors (pages, issue descriptions, and comments).

To verify the implementation of text alignment features, please run the following script:

#!/bin/bash
# Description: Check for text alignment implementation

# Test 1: Search for text alignment related imports
echo "Checking for text alignment imports:"
rg --type-add 'ts:*.{ts,tsx}' --type-add 'js:*.{js,jsx}' --type ts --type js '@tiptap/extension-text-align'

# Test 2: Search for text alignment command handlers
echo "Checking for text alignment command handlers:"
rg --type-add 'ts:*.{ts,tsx}' --type-add 'js:*.{js,jsx}' --type ts --type js 'textAlign|alignLeft|alignCenter|alignRight'

# Test 3: Search for keyboard shortcut definitions
echo "Checking for text alignment keyboard shortcuts:"
rg --type-add 'ts:*.{ts,tsx}' --type-add 'js:*.{js,jsx}' --type ts --type js 'Cmd \+ Shift \+ [LER]|Command \+ Shift \+ [LER]'

This script will help verify that the text alignment feature is properly implemented across the codebase.


3-3: LGTM. Verify impact on editor commands.

The import statement has been updated to include necessary types and components. The removal of TNonColorEditorCommands suggests a change in how editor commands are handled.

To ensure this change doesn't introduce any issues, please run the following script to check for any remaining usage of TNonColorEditorCommands:

packages/editor/package.json (1)

51-51: LGTM! Verify usage and version.

The addition of "@tiptap/extension-text-align": "^2.8.0" aligns with the PR objectives of introducing text alignment features. This is a positive change that will enable the implementation of text alignment functionality.

To ensure this dependency is properly utilized, please run the following verification script:

This script will help confirm that the new dependency is being used in the codebase and whether the specified version (^2.8.0) is the latest stable version. If the usage is not found or if there's a newer stable version available, consider updating accordingly.

packages/editor/src/core/extensions/core-without-props.ts (3)

21-21: LGTM: Import statement for CustomTextAlignExtension

The import statement for CustomTextAlignExtension is correctly added and follows the existing pattern in the file. This aligns with the PR objective of introducing text alignment features.


91-91: LGTM: Addition of CustomTextAlignExtension

The CustomTextAlignExtension is correctly added to the CoreEditorExtensionsWithoutProps array. Its placement at the end of the array is appropriate and doesn't interfere with existing extensions.


91-91: Verify implementation of keyboard shortcuts

The PR objectives mention keyboard shortcuts for text alignment (Cmd + Shift + L, Cmd + Shift + E, Cmd + Shift + R), but there's no visible implementation of these shortcuts in this file. Please ensure that these shortcuts are implemented elsewhere in the codebase.

packages/editor/src/core/components/menus/bubble-menu/node-selector.tsx (4)

22-23: LGTM: Import of TEditorCommands type

The addition of the TEditorCommands type import enhances type safety, which aligns with good TypeScript practices and the PR's objectives.


34-34: LGTM: Enhanced type safety for items array

The update to EditorMenuItem<TEditorCommands>[] improves type safety by ensuring that the commands associated with each menu item are explicitly typed. This change aligns well with TypeScript best practices and the PR's objectives.


Line range hint 1-99: Summary: Type safety improvements implemented, but text alignment features not found in this file

The changes in this file enhance type safety, which is a positive improvement. However, the main objectives of the PR, specifically the text alignment features (Left, Center, Right) and their corresponding keyboard shortcuts, are not implemented in this file.

Could you please clarify:

  1. In which file(s) are the text alignment features implemented?
  2. How do these changes in the BubbleMenuNodeSelector component relate to the text alignment functionality?
  3. Are there any plans to add text alignment options to this menu, or is it intentionally separate?

To help locate the text alignment implementations, I've provided a script in a previous comment. Running this script should help identify where these features are implemented across the codebase.


Line range hint 34-46: Verify implementation of text alignment options

The PR objectives mention adding text alignment features (Left, Center, Right) to various editors. However, I don't see these options in the items array. Could you please verify if the text alignment options are implemented elsewhere or if they need to be added to this component?

To check for text alignment implementations, we can run the following script:

packages/editor/src/core/extensions/read-only-extensions.tsx (2)

26-26: LGTM: Import statement for CustomTextAlignExtension

The import statement for CustomTextAlignExtension is correctly added and follows the existing pattern for importing custom extensions.


130-130: Verify the necessity of CustomTextAlignExtension in a read-only context

The CustomTextAlignExtension has been correctly added to the array of extensions. However, I have a concern:

This function is named CoreReadOnlyEditorExtensions, which implies these extensions are for a read-only editor. Adding a text alignment feature to a read-only editor seems counterintuitive, as users typically can't modify text in a read-only context.

Could you please clarify the intended behavior? If this extension is meant to display aligned text in read-only mode (rather than allow users to change alignment), it might be worth adding a comment explaining this to prevent confusion for future developers.

To verify the intended behavior, we can check if there's a read-only version of the CustomTextAlignExtension:

web/core/components/editor/lite-text-editor/lite-text-editor.tsx (2)

67-68: LGTM! Improved variable positioning.

The isEmpty variable has been correctly moved inside the component function. This ensures that it's recalculated on each render, which is appropriate for a derived value based on props.


3-3: LGTM! Consider verifying unused imports.

The import statement has been updated to include EditorRefApi and remove TNonColorEditorCommands. This change aligns with the modifications in the component.

To ensure all imports are being used and no unnecessary imports remain, run the following command:

✅ Verification successful

LGTM! Unused imports verified.

All imports in web/core/components/editor/lite-text-editor/lite-text-editor.tsx are used. No unnecessary imports found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for unused imports in the file

# Test: Look for imports that are not used in the file
rg --type typescript -e '^import.*from' web/core/components/editor/lite-text-editor/lite-text-editor.tsx | while read -r line; do
  import=$(echo "$line" | sed -E 's/^import \{([^}]*)\}.*/\1/' | tr ',' '\n' | sed 's/^ *//; s/ *$//')
  echo "$import" | while read -r item; do
    if ! rg -q "\b$item\b" web/core/components/editor/lite-text-editor/lite-text-editor.tsx; then
      echo "Potentially unused import: $item"
    fi
  done
done

Length of output: 156


Script:

#!/bin/bash
# Description: Check for unused imports in the file

# Test: Look for import statements and verify their usage
rg -e '^import\s+\{[^}]+\}\s+from' web/core/components/editor/lite-text-editor/lite-text-editor.tsx | while read -r line; do
  # Extract imported items
  imports=$(echo "$line" | sed -E 's/^import\s+\{([^}]+)\}\s+from.*/\1/' | tr ',' '\n' | sed 's/^ *//; s/ *$//')
  
  for import in $imports; do
    # Check if the import is used elsewhere in the file
    if ! rg -q "\\b$import\\b" web/core/components/editor/lite-text-editor/lite-text-editor.tsx; then
      echo "Potentially unused import: $import"
    fi
  done
done

Length of output: 3510

packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx (2)

67-67: Improved type safety for text color selection

The modification to pass an object { color: color.key } instead of just color.key to the TextColorItem(editor).command() function enhances type safety and makes the API more explicit. This change aligns well with the PR objectives and improves the overall code quality.


Line range hint 1-106: Overall implementation looks good

The changes to the BubbleMenuColorSelector component improve type safety and align well with the PR objectives for implementing text alignment features. The modifications are consistent between text and background color handling.

To ensure the changes are working as expected, please verify the following:

  1. Test the text and background color selection functionality in the editor.
  2. Confirm that the color changes are applied correctly when selected.
  3. Check if the color selection integrates well with the new text alignment features.

This script will help identify any potential integration points between color selection and text alignment features.

✅ Verification successful

Verification Successful

The TextColorItem and BackgroundColorItem are correctly integrated with the text alignment features within the codebase. The BubbleMenuColorSelector component interacts seamlessly with the alignment functionalities, aligning with the PR objectives.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the integration of color selection with text alignment

# Search for usage of TextColorItem and BackgroundColorItem
echo "Searching for TextColorItem and BackgroundColorItem usage:"
rg --type typescript "TextColorItem|BackgroundColorItem"

# Search for text alignment related code
echo "\nSearching for text alignment related code:"
rg --type typescript "textAlign|alignLeft|alignCenter|alignRight"

Length of output: 422


Script:

#!/bin/bash
# Verify the integration of color selection with text alignment

# Search for usage of TextColorItem and BackgroundColorItem
echo "Searching for TextColorItem and BackgroundColorItem usage:"
rg "TextColorItem|BackgroundColorItem" --type-add 'ts=*.ts' --type-add 'tsx=*.tsx' -t ts -t tsx

# Search for text alignment related code
echo "\nSearching for text alignment related code:"
rg "textAlign|alignLeft|alignCenter|alignRight" --type-add 'ts=*.ts' --type-add 'tsx=*.tsx' -t ts -t tsx

Length of output: 550


Script:

#!/bin/bash
# Verify the integration of color selection with text alignment

# Search for usage of TextColorItem and BackgroundColorItem
echo "Searching for TextColorItem and BackgroundColorItem usage:"
rg "TextColorItem|BackgroundColorItem" -g "*.ts" -g "*.tsx"

# Search for text alignment related code
echo "\nSearching for text alignment related code:"
rg "textAlign|alignLeft|alignCenter|alignRight" -g "*.ts" -g "*.tsx"

Length of output: 1941


Script:

#!/bin/bash
# Verify the integration of color selection with text alignment

# Search for usage of TextColorItem and BackgroundColorItem in .ts and .tsx files
echo "Searching for TextColorItem and BackgroundColorItem usage:"
rg "TextColorItem|BackgroundColorItem" -g "*.ts*"

# Search for text alignment related code in .ts and .tsx files
echo "\nSearching for text alignment related code:"
rg "textAlign|alignLeft|alignCenter|alignRight" -g "*.ts*"

Length of output: 1921

packages/editor/src/core/extensions/extensions.tsx (3)

21-21: LGTM: Import of CustomTextAlignExtension

The addition of CustomTextAlignExtension to the import statement is consistent with the existing code structure and aligns with the PR objective of introducing text alignment features.


21-21: Verify toolbar and keyboard shortcut implementation

The changes in this file successfully introduce the text alignment extension. However, the PR objectives mention a toolbar and keyboard shortcuts for text alignment, which are not directly addressed here.

Please ensure that the toolbar and keyboard shortcuts for text alignment (Cmd + Shift + L for left, Cmd + Shift + E for center, and Cmd + Shift + R for right) are implemented in the appropriate components. You can verify this with the following script:

#!/bin/bash
# Description: Verify toolbar and keyboard shortcut implementation for text alignment

# Test: Check for toolbar implementation
rg --type typescript 'TextAlignmentSelector|alignLeft|alignCenter|alignRight' -A 5 -B 5

# Test: Check for keyboard shortcut implementation
rg --type typescript 'Cmd \+ Shift \+ [LER]|CommandShift[LER]' -A 5 -B 5

Also applies to: 161-161


161-161: LGTM: Integration of CustomTextAlignExtension

The addition of CustomTextAlignExtension to the array returned by CoreEditorExtensions is correct and aligns with the PR objective of introducing text alignment features.

To ensure proper integration, let's verify the implementation of CustomTextAlignExtension:

✅ Verification successful

LGTM: Integration of CustomTextAlignExtension

The implementation of CustomTextAlignExtension in text-align.ts correctly includes the alignment options ["left", "center", "right"], ensuring the desired text alignment functionality is available in the editor.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of CustomTextAlignExtension

# Test: Check if CustomTextAlignExtension is properly implemented
ast-grep --lang typescript --pattern 'export const CustomTextAlignExtension = $_'

# Test: Verify if the extension includes left, center, and right alignment options
rg --type typescript 'alignLeft|alignCenter|alignRight' -A 5 -B 5

Length of output: 328


Script:

#!/bin/bash
# Description: Verify the implementation of CustomTextAlignExtension

# Test: Check if CustomTextAlignExtension is properly implemented
ast-grep --lang typescript --pattern 'export const CustomTextAlignExtension = $_'

# Test: Verify if the extension includes left, center, and right alignment options
rg --type ts 'alignLeft|alignCenter|alignRight' -A 5 -B 5
rg --type tsx 'alignLeft|alignCenter|alignRight' -A 5 -B 5

Length of output: 584


Script:

#!/bin/bash
# Description: Verify the implementation of CustomTextAlignExtension by searching alignment options in .ts and .tsx files

# Test: Check if CustomTextAlignExtension is properly implemented
ast-grep --lang typescript --pattern 'export const CustomTextAlignExtension = $_'

# Test: Verify if the extension includes left, center, and right alignment options in .ts files
rg 'alignLeft|alignCenter|alignRight' -A 5 -B 5 -g "*.ts"

# Test: Verify if the extension includes left, center, and right alignment options in .tsx files
rg 'alignLeft|alignCenter|alignRight' -A 5 -B 5 -g "*.tsx"

Length of output: 556

web/core/components/pages/editor/header/color-dropdown.tsx (2)

Line range hint 1-138: Overall assessment: Changes improve type safety and align with PR objectives.

The modifications to this file focus on enhancing type safety and consistency in the ColorDropdown component. The changes align well with the PR objectives by refining the type definitions related to text color and background color. These improvements contribute to the overall goal of enhancing the editor's functionality and type safety.

Key points:

  1. The import statement has been updated to use a more generic TEditorCommands type.
  2. The Props type definition now uses a more specific type for color-related commands.
  3. No functional changes were made to the component's behavior, maintaining its existing functionality.

These changes are part of the larger effort to implement text alignment features across various editors, as mentioned in the PR objectives.


7-7: LGTM! Verify the impact of the import change.

The import statement has been updated to use TEditorCommands instead of TColorEditorCommands. This change aligns with the modifications in the Props type and suggests a move towards using a more generic type.

To ensure this change doesn't have unintended consequences, please run the following script:

If the script returns any results, those occurrences might need to be updated as well.

✅ Verification successful

Import Change Verified: No remaining usage of TColorEditorCommands found.

The update to use TEditorCommands is safe and does not affect other parts of the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usage of TColorEditorCommands in the codebase

# Test: Search for TColorEditorCommands usage
rg --type typescript 'TColorEditorCommands'

Length of output: 78


Script:

#!/bin/bash
# Description: Check for any remaining usage of TColorEditorCommands in TypeScript files

# Test: Search for TColorEditorCommands usage in .ts and .tsx files
rg 'TColorEditorCommands' --type ts --type tsx

Length of output: 74


Script:

#!/bin/bash
# Description: Check for any remaining usage of TColorEditorCommands in .ts and .tsx files

# Test: Search for TColorEditorCommands usage in .ts and .tsx files using glob patterns
rg 'TColorEditorCommands' --glob '*.ts' --glob '*.tsx'

Length of output: 54

web/core/components/pages/editor/header/toolbar.tsx (4)

6-6: LGTM: Improved type safety with EditorRefApi import

The addition of the EditorRefApi import from "@plane/editor" enhances type safety for editor-related operations. This change aligns well with the goal of improving overall type safety in the codebase.


95-96: LGTM: Consistent usage of itemKey and extraProps

The update to the activeTypography variable, now using item.itemKey and extraProps, aligns well with the changes made elsewhere in the file. This improves consistency in how toolbar items are handled throughout the component.


153-155: LGTM: Consistent ToolbarButton rendering

The updates to the ToolbarButton rendering are well-implemented and consistent with the changes made elsewhere in the file. The use of item.renderKey as the key and in activeStates improves overall consistency in how toolbar items are handled.


71-84: ⚠️ Potential issue

Clean up updateActiveStates function

The changes to updateActiveStates function improve consistency with the ToolbarButton component. However, there are several issues that need attention:

  1. The TODO comment suggests that further updates are needed for toolbar homogenization. This aligns with the previous TODO comment.

  2. The use of @ts-expect-error indicates a type mismatch that should be resolved.

  3. Commented out console.log statements should be removed to keep the code clean.

To address these issues:

  1. Ensure that the follow-up task for toolbar homogenization includes this function.
  2. Investigate and fix the type mismatch, removing the need for @ts-expect-error.
  3. Remove the commented out console.log statements.

Run the following script to check for any remaining console.log statements:

✅ Verification successful

Remove Commented-Out console.log Statements

The toolbar.tsx file still contains commented-out console.log statements:

  • Lines 71-84:
    // console.log("Updating status");
    // console.log("newActiveStates", newActiveStates);

These should be removed to maintain clean and readable code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for console.log statements in the file
rg 'console\.log' web/core/components/pages/editor/header/toolbar.tsx

Length of output: 166

packages/editor/src/core/components/menus/bubble-menu/root.tsx (5)

18-19: LGTM: TextAlignmentSelector import added.

The import of the new TextAlignmentSelector component is correctly placed and aligns with the PR objective of adding text alignment features to the editor.


Line range hint 136-153: LGTM: Rendering logic updated consistently.

The rendering logic has been updated to use 'basicFormattingOptions' instead of 'items', which is consistent with the earlier variable renaming. The mapping logic remains unchanged, preserving the existing functionality.


Line range hint 1-160: Summary: Text alignment feature successfully integrated.

The changes in this file successfully integrate the text alignment feature into the editor's bubble menu. The code modifications, including the import of TextAlignmentSelector, variable renaming, and rendering logic updates, are well-implemented and align with the PR objectives.

Some points to consider:

  1. Verify that the renaming of 'items' to 'basicFormattingOptions' doesn't affect other parts of the codebase.
  2. Ensure that the TextAlignmentSelector component correctly implements the Left, Center, and Right alignment options as specified in the PR objectives.

Overall, the changes enhance the editor's functionality while maintaining code quality and readability.


155-155: LGTM: TextAlignmentSelector added as per PR objective.

The TextAlignmentSelector component has been added, which aligns with the PR objective of introducing text alignment features. Its placement after the formatting buttons is logical.

To ensure the TextAlignmentSelector is implemented correctly, please run the following script:

#!/bin/bash
# Description: Verify the implementation of TextAlignmentSelector

# Test: Check the implementation of TextAlignmentSelector
cat packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx

# Test: Verify if the component handles the alignment options (Left, Center, Right) as mentioned in the PR objectives
rg --type typescript --type tsx -i '(left|center|right)\s*alignment' packages/editor

30-32: Approve renaming and conditional logic, but verify usage.

The renaming of 'items' to 'basicFormattingOptions' improves code readability. The added conditional logic for including CodeItem is a good practice. However, ensure that this change doesn't break any existing functionality that might have been using the 'items' variable.

Run the following script to verify the variable usage across the codebase:

✅ Verification successful

Correct the file type in the search script and rerun the verification.

The previous script failed because typescript is not a recognized file type in rg. Please use ts and tsx instead to search for any remaining usage of the items variable.


Adjust the search to use file patterns instead of types and rerun the verification.

The previous script failed because rg does not recognize tsx as a valid file type. Please modify the search to use file patterns *.ts and *.tsx instead of the --type flag.


Renaming and conditional logic verified; no remaining 'items' usage found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usage of 'items' variable in editor-related files

# Test: Search for 'items' usage in editor-related files
rg --type typescript --type tsx 'items\s*=' packages/editor

Length of output: 2366


Script:

#!/bin/bash
# Description: Check for any remaining usage of 'items' variable in editor-related files

# Test: Search for 'items' usage in TypeScript and TSX files within packages/editor
rg --type ts --type tsx 'items\s*=' packages/editor

Length of output: 81


Script:

#!/bin/bash
# Description: Check for any remaining usage of 'items' variable in TypeScript and TSX files within packages/editor

# Test: Search for 'items' usage in .ts and .tsx files within packages/editor
rg 'items\s*=' packages/editor -g '*.ts' -g '*.tsx'

Length of output: 53

packages/editor/src/core/helpers/editor-commands.ts (1)

183-186: Integration of setTextAlign is consistent with existing code

The placement and structure of the new setTextAlign function at the end of the file are consistent with the existing code patterns. It doesn't introduce any conflicts or issues with the existing functions.

packages/editor/src/styles/editor.css (1)

195-195: LGTM! Consider verifying layout on smaller screens.

The increase in max-width for .tippy-box from 400px to 600px allows for more spacious tooltips or popovers, which can enhance the display of text alignment options and other editor features. This change aligns well with the PR objectives.

To ensure this change doesn't cause any layout issues, especially on smaller screens, please run the following verification script:

This script will help identify any potential conflicts or areas that might need adjustment due to the increased width.

packages/editor/src/core/types/editor.ts (3)

17-40: Addition of 'text-align' command is appropriate

The inclusion of "text-align" in TEditorCommands aligns with the PR objectives to introduce text alignment features across editors.


42-55: 'text-align' extra properties are correctly defined

Defining extra properties for "text-align" in TCommandExtraProps with an alignment parameter is appropriate for handling text alignment commands.


88-89: Verify compatibility of updated method signatures with existing implementations

The methods executeMenuItemCommand and isMenuItemActive now use the generic type parameters with TCommandWithPropsWithItemKey<T>. Ensure all implementations of the EditorRefApi interface are updated to match these new method signatures to prevent type errors.

Run the following script to find usages of EditorRefApi and verify method implementations:

✅ Verification successful

Adjusting search commands to include .ts and .tsx files correctly. Initiating re-verification.


Method signatures are compatible across all implementations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all implementations of EditorRefApi have updated method signatures.

# Search for implementations of EditorRefApi
rg --type ts --type tsx 'implements\s+EditorRefApi'

# Search for definitions or overrides of executeMenuItemCommand
rg --type ts --type tsx 'executeMenuItemCommand\s*[:(]'

# Search for definitions or overrides of isMenuItemActive
rg --type ts --type tsx 'isMenuItemActive\s*[:(]'

Length of output: 247


Script:

#!/bin/bash
# Description: Verify that all implementations of EditorRefApi have updated method signatures.

# Search for implementations of EditorRefApi in .ts and .tsx files
rg 'implements\s+EditorRefApi' -g '*.ts' -g '*.tsx'

# Search for definitions or overrides of executeMenuItemCommand in .ts and .tsx files
rg 'executeMenuItemCommand\s*[:(]' -g '*.ts' -g '*.tsx'

# Search for definitions or overrides of isMenuItemActive in .ts and .tsx files
rg 'isMenuItemActive\s*[:(]' -g '*.ts' -g '*.tsx'

Length of output: 1561

space/core/constants/editor.ts (2)

35-42: Type definitions updated appropriately.

The ToolbarMenuItem type has been enhanced with a generic parameter, allowing for extra properties specific to commands. This increases flexibility and type safety.


55-89: Text alignment items are well-defined.

The TEXT_ALIGNMENT_ITEMS constant is correctly introduced with appropriate properties, including itemKey, renderKey, name, icon, shortcut, editors, and extraProps. The implementation aligns with the intended functionality.

web/core/components/editor/lite-text-editor/toolbar.tsx (6)

6-6: Importing EditorRefApi

The import of EditorRefApi from @plane/editor aligns with the updated usage of editorRef.


10-10: Importing ToolbarMenuItem

Including ToolbarMenuItem in the imports is appropriate for handling toolbar items with improved type safety.


17-17: Update executeCommand to accept ToolbarMenuItem

Changing the executeCommand function to accept a ToolbarMenuItem enhances flexibility and aligns with how toolbar commands are executed.


24-24: Simplify editorRef type

Updating editorRef to be of type EditorRefApi | null simplifies the reference and removes unnecessary indirection.


83-84: Ensure proper subscription to editor state changes

The updated null check for editorRef and the direct use of editorRef.onStateChange improve readability and ensure that the component correctly subscribes to editor state changes.


127-158: Enhance toolbar item rendering and active state management

Updating the rendering logic to use item.renderKey and passing the entire item to executeCommand improves type safety and consistency. The use of activeStates[item.renderKey] accurately reflects the active state of each toolbar item.

packages/editor/src/core/components/menus/menu-items.ts (4)

23-30: New Imports for Text Alignment Feature

The addition of AlignCenter and setTextAlign imports correctly integrates the text alignment functionality into the editor.


52-61: Enhanced Type Safety with Generic Functions

Excellent work introducing the generic types isActiveFunction and commandFunction and updating EditorMenuItem accordingly. This improves type safety and code maintainability.


199-205: Consistent Parameter Usage in ImageItem

Updating ImageItem to accept parameters in the command function increases consistency across menu items and accommodates necessary parameters.


255-255: TextAlignItem Added to Editor Menu Items

Including TextAlignItem in getEditorMenuItems ensures that text alignment options are available to users.

web/core/constants/editor.ts (11)

3-5: Imports for text alignment icons are correctly added

The imports of AlignCenter, AlignLeft, and AlignRight from lucide-react are appropriate for the new text alignment feature.


35-38: Utility type ExtraPropsForCommand is well-defined

The ExtraPropsForCommand type correctly ensures that extraProps are enforced or made optional based on the command's requirements. This improves type safety when extending commands with additional properties.


40-47: Enhanced ToolbarMenuItem type with a generic parameter

Introducing a generic parameter T extends TEditorCommands in the ToolbarMenuItem type increases flexibility and type safety. It allows for specifying extra properties based on the command type.


50-57: Updated TYPOGRAPHY_ITEMS to utilize the generic ToolbarMenuItem type

The TYPOGRAPHY_ITEMS array now correctly uses the updated ToolbarMenuItem type with specific itemKey and renderKey properties. This change enhances type safety and aligns with the new structure.


60-94: Addition of TEXT_ALIGNMENT_ITEMS for text alignment commands

The new TEXT_ALIGNMENT_ITEMS array introduces items for left, center, and right text alignment. Each item includes appropriate properties such as itemKey, renderKey, name, icon, shortcut, editors, and extraProps with the alignment value.


95-120: Consistent use of renderKey in BASIC_MARK_ITEMS

The BASIC_MARK_ITEMS array now includes the renderKey property for each item, ensuring consistency with other toolbar item definitions.


131-150: Updated LIST_ITEMS with specific itemKey and renderKey properties

The LIST_ITEMS array correctly utilizes the updated ToolbarMenuItem type, enhancing type safety and consistency across the toolbar configurations.


158-160: Updated USER_ACTION_ITEMS to use the new ToolbarMenuItem type

The USER_ACTION_ITEMS array has been updated to align with the new ToolbarMenuItem type definition, promoting consistency and improved type enforcement.


163-165: Updated COMPLEX_ITEMS with enhanced type definitions

The COMPLEX_ITEMS array reflects the updated type definitions, correctly specifying itemKey, renderKey, and other properties in line with the new structure.


170-182: Adjusted TOOLBAR_ITEMS to accommodate new type definitions

The TOOLBAR_ITEMS export has been updated to use the enhanced ToolbarMenuItem type. The filtering logic based on editor types remains intact, and the inclusion of the new alignment items is correctly handled.


60-94: Verify that TCommandExtraProps includes the text-align command with alignment property

To ensure type safety for the extraProps in TEXT_ALIGNMENT_ITEMS, please confirm that the TCommandExtraProps type includes an entry for the text-align command specifying the alignment property.

You can run the following script to verify:

This script searches for the TCommandExtraProps type definition and checks if it includes a definition for 'text-align' with the appropriate properties.

space/core/components/editor/toolbar.tsx Show resolved Hide resolved
packages/editor/src/core/types/editor.ts Outdated Show resolved Hide resolved
space/core/constants/editor.ts Show resolved Hide resolved
space/core/constants/editor.ts Show resolved Hide resolved
packages/editor/src/core/components/menus/menu-items.ts Outdated Show resolved Hide resolved
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: 1

🧹 Outside diff range and nitpick comments (6)
packages/editor/src/core/extensions/custom-image/components/image-node.tsx (1)

Line range hint 7-14: LGTM: Type definition enhanced for better type safety.

The update to CustomImageNodeViewProps is a good improvement:

  1. It now extends NodeViewProps, incorporating all relevant properties from Tiptap's node view.
  2. The additional properties are correctly typed and consistent with the component's usage.
  3. This change supports potential new features, aligning with the PR objectives.

Consider adding a comment explaining the purpose of extending NodeViewProps and any specific properties it brings that are crucial for this component. This would improve code maintainability.

packages/editor/src/core/extensions/slash-commands/root.tsx (1)

58-58: LGTM: Enhanced type specificity for ReactRenderer

The update to use SlashCommandsMenuProps in the ReactRenderer type improves type checking and consistency. This change is beneficial for maintaining code quality and catching potential issues early.

Consider adding a type annotation to the renderItems function for even better type safety:

-const renderItems = () => {
+const renderItems = (): {
+  onStart: (props: { editor: Editor; clientRect?: (() => DOMRect | null) | null }) => void;
+  onUpdate: (props: { editor: Editor; clientRect?: (() => DOMRect | null) | null }) => void;
+  onKeyDown: (props: { event: KeyboardEvent }) => boolean;
+  onExit: () => void;
+} => {
packages/editor/src/core/extensions/slash-commands/command-menu.tsx (1)

6-9: Approve type definition with a suggestion for improvement

The new SlashCommandsMenuProps type enhances the component's type safety and aligns with the PR objectives. However, consider improving the type safety of the command property.

Instead of using any for the command property, consider defining a more specific type. For example:

command: (item: { key: string; [key: string]: any }) => void;

This assumes that the command function takes an item with at least a key property. Adjust the type according to the actual structure of the items if different.

packages/editor/src/core/types/editor.ts (1)

18-41: LGTM: Comprehensive TEditorCommands type

The new TEditorCommands type provides a clear and exhaustive list of editor commands, including the new "text-align" command. This enhances type safety and aligns with the PR objectives.

Consider using a union of string literals instead of separate lines for better readability:

export type TEditorCommands =
  | "text" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6"
  | "bold" | "italic" | "underline" | "strikethrough"
  | "bulleted-list" | "numbered-list" | "to-do-list"
  | "quote" | "code" | "table" | "image" | "divider"
  | "issue-embed" | "text-color" | "background-color"
  | "text-align";

This format is more compact and easier to maintain.

packages/editor/src/core/components/menus/menu-items.ts (2)

208-220: Consider adding explicit typing for color parameter

While the TextColorItem and BackgroundColorItem now use the new generic types, the color parameter in the isActive and command functions could benefit from explicit typing. This would further enhance type safety and prevent potential runtime errors.

Consider updating the functions as follows:

isActive: ({ color }: { color: string }) => editor.getAttributes("textStyle").color === color,
command: ({ color }: { color: string }) => toggleTextColor(color, editor),

Apply similar changes to the BackgroundColorItem as well.


224-230: New TextAlignItem and updated getEditorMenuItems

The new TextAlignItem successfully implements the text alignment feature, and the getEditorMenuItems function has been updated to maintain type consistency. These changes align well with the PR objectives.

Consider adding explicit typing for the alignment parameter in TextAlignItem to further enhance type safety:

isActive: ({ alignment }: { alignment: 'left' | 'center' | 'right' | 'justify' }) => editor.isActive({ textAlign: alignment }),
command: ({ alignment }: { alignment: 'left' | 'center' | 'right' | 'justify' }) => setTextAlign(alignment, editor),

This change would help prevent potential errors from invalid alignment values.

Also applies to: 232-232, 256-256

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e2bcf25 and 7d7cbff.

📒 Files selected for processing (9)
  • packages/editor/src/core/components/menus/bubble-menu/node-selector.tsx (3 hunks)
  • packages/editor/src/core/components/menus/menu-items.ts (3 hunks)
  • packages/editor/src/core/extensions/custom-image/components/image-node.tsx (1 hunks)
  • packages/editor/src/core/extensions/slash-commands/command-menu.tsx (1 hunks)
  • packages/editor/src/core/extensions/slash-commands/root.tsx (2 hunks)
  • packages/editor/src/core/extensions/text-align.ts (1 hunks)
  • packages/editor/src/core/hooks/use-editor.ts (3 hunks)
  • packages/editor/src/core/types/editor.ts (2 hunks)
  • space/core/constants/editor.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/editor/src/core/components/menus/bubble-menu/node-selector.tsx
  • packages/editor/src/core/extensions/text-align.ts
  • packages/editor/src/core/hooks/use-editor.ts
🧰 Additional context used
🔇 Additional comments (23)
packages/editor/src/core/extensions/custom-image/components/image-node.tsx (2)

3-3: LGTM: Import statement updated correctly.

The addition of NodeViewProps to the import statement is appropriate and necessary for the type definition update that follows. This change enhances type safety in the component.


Line range hint 1-91: Overall assessment: Changes improve type safety without altering functionality.

The updates to this file enhance type safety and prepare the component for potential new features related to text alignment. The changes are minimal but impactful, focusing on improving the type definition without altering the existing component logic. This approach maintains current functionality while setting the stage for future enhancements.

To ensure these changes don't introduce any unintended side effects, please run the following verification script:

packages/editor/src/core/extensions/slash-commands/root.tsx (3)

9-9: LGTM: Improved type safety for SlashCommandsMenu

The addition of SlashCommandsMenuProps to the import statement enhances type safety for the SlashCommandsMenu component. This change aligns well with the PR objectives and is a step towards more robust code.


Line range hint 1-114: Overall assessment: Improved type safety with minimal impact

The changes in this file enhance type safety for the SlashCommandsMenu component without altering the core functionality. These improvements align well with the PR objectives of enhancing the editor's functionality. The suggestions provided are minor and aimed at further improving type safety and code clarity.


9-9: Verify SlashCommandsMenu implementation

The changes to import SlashCommandsMenuProps and use it in the ReactRenderer type are good improvements. To ensure full compatibility, please verify that the SlashCommandsMenu component is correctly implemented with the expected props as defined in SlashCommandsMenuProps.

Run the following script to check the SlashCommandsMenu implementation:

Also applies to: 58-58

packages/editor/src/core/extensions/slash-commands/command-menu.tsx (2)

11-11: Approve component signature update

The updated SlashCommandsMenu component signature correctly uses the new SlashCommandsMenuProps type, improving type safety and consistency. This change aligns well with the PR objectives and maintains consistency with the rest of the codebase.


Line range hint 1-124: Verify implementation of text alignment features

While the type and signature changes in this file improve code quality, they don't directly implement the text alignment features mentioned in the PR objectives. Please ensure that the text alignment functionality (Left, Center, Right) and keyboard shortcuts (Cmd + Shift + L/E/R) are implemented in the relevant files.

To verify the implementation of text alignment features, you can run the following script:

This script will help locate the files where text alignment and keyboard shortcuts are implemented.

packages/editor/src/core/types/editor.ts (4)

16-16: LGTM: New import for text alignment

The addition of the TTextAlign import aligns with the PR objective of introducing text alignment features across various editors.


43-56: LGTM: TCommandExtraProps type with text alignment

The TCommandExtraProps type effectively defines additional properties for specific commands, including the new text alignment feature. This enhances type safety and aligns with the PR objectives.

Regarding the past review comment about the alignment property:

"text-align": {
  alignment: TTextAlign;
}

This implementation already addresses the suggestion to restrict the alignment property to specific allowed options by using the TTextAlign type. Good job on implementing this improvement!


63-65: LGTM: TCommandWithPropsWithItemKey type

The TCommandWithPropsWithItemKey type is a well-designed extension of TCommandWithProps that includes an itemKey property. This addition enhances type safety and provides a clear structure for commands with associated properties and keys.


89-90: LGTM: Improved type safety in EditorRefApi

The updates to executeMenuItemCommand and isMenuItemActive methods in the EditorRefApi interface significantly improve type safety:

executeMenuItemCommand: <T extends TEditorCommands>(props: TCommandWithPropsWithItemKey<T>) => void;
isMenuItemActive: <T extends TEditorCommands>(props: TCommandWithPropsWithItemKey<T>) => boolean;

These changes ensure that the methods can handle a wide range of command types with their associated properties, aligning well with the new type system introduced earlier in the file.

space/core/constants/editor.ts (9)

2-6: Reconsider the use of the CaseSensitive icon

The CaseSensitive icon is imported and later used for the "Text" item in the toolbar. As mentioned in a previous review, this icon might not intuitively represent the "Text" formatting option. Consider using a more appropriate icon like Text or Type to improve user understanding.


30-42: Improved type safety and extensibility

The new ExtraPropsForCommand<T> utility type and the updated ToolbarMenuItem<T> type with a generic parameter enhance type safety and extensibility. These changes allow for command-specific properties, which is a good improvement.


45-53: Approve renaming and suggest icon change

The renaming of BASIC_MARK_ITEMS to TYPOGRAPHY_ITEMS is more descriptive and appropriate. However, as mentioned earlier, reconsider using the CaseSensitive icon for the "Text" item. A more intuitive icon would improve user understanding.


55-89: Text alignment features implemented correctly

The TEXT_ALIGNMENT_ITEMS constant correctly implements the text alignment features as described in the PR objectives. It includes left, center, and right alignment options with the specified keyboard shortcuts (Cmd + Shift + L/E/R). This implementation enhances the editor's functionality as intended.


91-124: BASIC_MARK_ITEMS updated correctly

The BASIC_MARK_ITEMS constant has been correctly updated to use the new ToolbarMenuItem type with appropriate generic parameters. The functionality of the items remains unchanged, which is good for maintaining consistency.


126-150: LIST_ITEMS updated correctly

The LIST_ITEMS constant has been properly updated to use the new ToolbarMenuItem type with appropriate generic parameters. The functionality of the list items remains consistent, which is good for maintaining the existing behavior.


153-161: USER_ACTION_ITEMS and COMPLEX_ITEMS updated correctly

Both USER_ACTION_ITEMS and COMPLEX_ITEMS constants have been correctly updated to use the new ToolbarMenuItem type with appropriate generic parameters. The functionality of these items remains unchanged, maintaining consistency in the editor's behavior.


170-177: Text alignment added to all editors correctly

The TOOLBAR_ITEMS constant has been updated to include the new text alignment options for both "lite" and "document" editors. This change aligns with the PR objectives to add text alignment features across all editors. The previous issue with incorrect filtering for the document editor has been resolved.


Line range hint 1-182: Summary of changes and their impact

The changes in this file successfully implement the text alignment features as described in the PR objectives. Key improvements include:

  1. Addition of text alignment options (left, center, right) with correct keyboard shortcuts.
  2. Enhanced type safety and extensibility through new type definitions.
  3. Consistent updates across all relevant constants to support the new features.

These changes will allow users to align text in various editors as intended. The implementation is solid, with only minor suggestions for icon usage improvement.

packages/editor/src/core/components/menus/menu-items.ts (3)

23-23: Improved type safety and new text alignment feature

The changes introduce new imports and type definitions to support text alignment functionality. The use of generic types for isActiveFunction, commandFunction, and EditorMenuItem significantly enhances type safety across the menu items.

Also applies to: 30-30, 52-61


63-63: Consistent type improvements across menu items

All existing menu item definitions have been updated with specific generic type parameters (e.g., EditorMenuItem<"text">, EditorMenuItem<"h1">, etc.). This change enhances type safety and maintains consistency across all menu items.

Also applies to: 71-71, 79-79, 87-87, 95-95, 103-103, 111-111, 119-119, 127-127, 135-135, 143-143, 151-151, 159-159, 167-167, 175-175, 183-183, 191-191


199-206: Improved ImageItem implementation

The ImageItem has been updated to use the new generic type EditorMenuItem<"image">. The command function now properly handles cases where savedSelection might be undefined by providing a fallback position. This addresses the concern raised in a previous review comment about validating savedSelection.

Comment on lines +58 to +61
// Create a utility type that maps a command to its extra props or an empty object if none are defined
export type TCommandWithProps<T extends TEditorCommands> = T extends keyof TCommandExtraProps
? TCommandExtraProps[T] // If the command has extra props, include them
: object; // Otherwise, just return the command type with no extra props
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

Improve type safety in TCommandWithProps

The TCommandWithProps utility type is a good addition for mapping commands to their extra props. However, there's an opportunity to improve type safety:

export type TCommandWithProps<T extends TEditorCommands> = T extends keyof TCommandExtraProps
  ? TCommandExtraProps[T] // If the command has extra props, include them
-  : object; // Otherwise, just return the command type with no extra props
+  : Record<string, never>; // Use an explicit empty object type

This change addresses the past review comment about avoiding {} as a type and uses Record<string, never> for better type safety when representing an empty object.

📝 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
// Create a utility type that maps a command to its extra props or an empty object if none are defined
export type TCommandWithProps<T extends TEditorCommands> = T extends keyof TCommandExtraProps
? TCommandExtraProps[T] // If the command has extra props, include them
: object; // Otherwise, just return the command type with no extra props
// Create a utility type that maps a command to its extra props or an empty object if none are defined
export type TCommandWithProps<T extends TEditorCommands> = T extends keyof TCommandExtraProps
? TCommandExtraProps[T] // If the command has extra props, include them
: Record<string, never>; // Use an explicit empty object type

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: 0

🧹 Outside diff range and nitpick comments (1)
packages/editor/src/core/components/menus/menu-items.ts (1)

224-230: New TextAlignItem successfully implements text alignment feature

The addition of TextAlignItem successfully implements the text alignment feature mentioned in the PR objectives:

  1. It correctly uses the EditorMenuItem<"text-align"> type.
  2. The implementation is consistent with other menu items.
  3. The isActive and command functions use an alignment parameter to determine the current state and set the alignment.

To further improve type safety, consider defining a specific type for the alignment options:

type TextAlignment = 'left' | 'center' | 'right' | 'justify';

export const TextAlignItem = (editor: Editor): EditorMenuItem<"text-align"> => ({
  // ...
  isActive: ({ alignment }: { alignment: TextAlignment }) => editor.isActive({ textAlign: alignment }),
  command: ({ alignment }: { alignment: TextAlignment }) => setTextAlign(alignment, editor),
  // ...
});

This change would prevent potential errors from invalid alignment values.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7d7cbff and b05f407.

📒 Files selected for processing (6)
  • packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx (2 hunks)
  • packages/editor/src/core/components/menus/menu-items.ts (3 hunks)
  • packages/editor/src/core/extensions/core-without-props.ts (2 hunks)
  • packages/editor/src/core/extensions/extensions.tsx (2 hunks)
  • packages/editor/src/core/extensions/index.ts (1 hunks)
  • packages/editor/src/core/extensions/read-only-extensions.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx
  • packages/editor/src/core/extensions/core-without-props.ts
  • packages/editor/src/core/extensions/extensions.tsx
  • packages/editor/src/core/extensions/index.ts
  • packages/editor/src/core/extensions/read-only-extensions.tsx
🧰 Additional context used
🔇 Additional comments (4)
packages/editor/src/core/components/menus/menu-items.ts (4)

23-23: Excellent improvements in type safety and new text alignment feature!

The changes in this section significantly enhance the type safety of the codebase:

  1. New imports for AlignCenter and setTextAlign support the text alignment feature.
  2. The introduction of isActiveFunction and commandFunction types provides better type checking for these crucial functions.
  3. The updated EditorMenuItem type now uses generics, allowing for more precise type inference based on the specific editor command.

These changes will lead to better code completion, fewer runtime errors, and improved maintainability.

Also applies to: 30-30, 52-61


63-222: Consistent type improvements across all menu items

The updates to all existing menu item definitions (TextItem, HeadingOneItem, etc.) show a systematic approach to improving type safety:

  1. Each item now uses the generic EditorMenuItem<T> type, where T is the specific command type (e.g., "text", "h1", "bold").
  2. This change ensures that the key, isActive, and command properties for each item are correctly typed according to their specific functionality.
  3. The consistency in these changes across all items reduces the likelihood of type-related errors and improves code maintainability.

Great job on implementing these improvements consistently throughout the file!


199-206: Improved robustness in ImageItem implementation

The changes to the ImageItem definition enhance both type safety and functionality:

  1. The use of EditorMenuItem<"image"> aligns with the new type system.
  2. The command function now uses object destructuring for savedSelection, improving code readability.
  3. A fallback is provided for the position when savedSelection is undefined, preventing potential runtime errors.
command: ({ savedSelection }) =>
  insertImage({ editor, event: "insert", pos: savedSelection?.from ?? editor.state.selection.from }),

This fallback mechanism ensures that the image insertion will work correctly even if there's no saved selection, improving the robustness of the feature.


232-232: Successful integration of TextAlignItem in getEditorMenuItems

The changes to the getEditorMenuItems function effectively integrate the new text alignment feature:

  1. The return type EditorMenuItem<TEditorCommands>[] aligns with the new generic EditorMenuItem type, ensuring type safety across all menu items.
  2. The addition of TextAlignItem(editor) to the returned array makes the new text alignment feature available in the editor.

These changes complete the implementation of the text alignment feature, making it accessible alongside other editor functionalities.

Also applies to: 256-256

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant