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

feat: Add configurable block and inline styles for Tiptap #51

Merged
merged 6 commits into from
Jan 6, 2025

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented Jan 6, 2025

Summary by Sourcery

Add support for configurable inline and block styles, replacing the hardcoded small, kbd, var, and samp styles.

New Features:

  • Introduce configurable inline and block styles in the editor.

Tests:

  • Update tests to reflect the changes in the available styles.

Copy link
Contributor

sourcery-ai bot commented Jan 6, 2025

Reviewer's Guide by Sourcery

This pull request introduces a flexible styling system for inline and block elements, replacing the fixed styles (Small, Var, Kbd, Samp) with configurable styles. The toolbar has been updated to support these changes.

Sequence diagram for style application

sequenceDiagram
    participant User
    participant Editor
    participant StyleSystem
    participant DOM

    User->>Editor: Clicks style button
    Editor->>StyleSystem: toggleStyle(id)
    StyleSystem->>StyleSystem: Check style exists
    alt Style exists
        StyleSystem->>StyleSystem: Check if style active
        alt Style is active
            StyleSystem->>DOM: Remove style
        else Style not active
            StyleSystem->>DOM: Apply style attributes
        end
    end
    DOM-->>User: Updated content display
Loading

Class diagram for the new style system

classDiagram
    class Style {
        +addOptions()
        +addAttributes()
        +parseHTML()
        +renderHTML()
    }

    class InlineStyle {
        +name: string
        +defaultTag: string
        +addOptions()
        +addCommands()
        -toggleInlineStyle(id)
        -activeInlineStyle(id)
    }

    class BlockStyle {
        +name: string
        +group: string
        +content: string
        +defaultTag: string
        +addCommands()
        -toggleBlockStyle(id)
        -activeBlockStyle(id)
    }

    Style <|-- InlineStyle
    Style <|-- BlockStyle

    note for Style "Base functionality for styling"
    note for InlineStyle "Handles inline text styling"
    note for BlockStyle "Handles block-level styling"
Loading

File-Level Changes

Change Details Files
Replaced fixed inline styles with configurable styles
  • Removed fixed inline style components (Small, Var, Kbd, Samp).
  • Added InlineStyle component to enable configurable inline styles.
  • Added logic to parse and render configurable inline styles based on editor options.
  • Added commands to toggle and check the active state of inline styles.
  • Updated style rendering to handle both element-based and attribute-based styles.
private/js/tiptap_plugins/cms.styles.js
Introduced configurable block styles
  • Added BlockStyle component to manage configurable block-level styles.
  • Implemented logic to parse and apply block styles from editor options.
  • Added commands for toggling and checking the status of block styles.
  • Updated style rendering to support configurable block elements and attributes.
private/js/tiptap_plugins/cms.styles.js
Updated toolbar to accommodate configurable styles
  • Added new toolbar buttons for inline and block styles.
  • Implemented rendering of style menus in the toolbar.
  • Updated toolbar configuration to include the new style buttons.
  • Added options for inline and block styles to the editor configuration.
  • Modified toolbar update logic to handle enabled and active states of style buttons.
private/js/tiptap_plugins/cms.styles.js
private/js/tiptap_plugins/cms.tiptap.toolbar.js
djangocms_text/editors.py
private/js/cms.tiptap.js
private/js/tiptap_plugins/cms.toolbar.js
Refactored color menu rendering
  • Moved color menu rendering logic from cms.tiptap.toolbar.js to cms.styles.js.
  • Simplified color menu rendering using array-based approach.
private/js/tiptap_plugins/cms.styles.js
private/js/tiptap_plugins/cms.tiptap.toolbar.js
Made CMS plugins draggable and atomic
  • Added atom: true and draggable: true properties to CMS plugin nodes.
private/js/tiptap_plugins/cms.plugin.js
Updated dynamic link handling
  • Removed unnecessary strict mode declaration from dynamic link code.
private/js/tiptap_plugins/cms.dynlink.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @fsbraun - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please remove the console.log statements before merging (in cms.styles.js)
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

private/js/tiptap_plugins/cms.toolbar.js Show resolved Hide resolved
private/js/tiptap_plugins/cms.styles.js Show resolved Hide resolved
Copy link

codecov bot commented Jan 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.22%. Comparing base (182fabf) to head (f2e7495).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #51   +/-   ##
=======================================
  Coverage   81.22%   81.22%           
=======================================
  Files          17       17           
  Lines         932      932           
  Branches      104      104           
=======================================
  Hits          757      757           
  Misses        132      132           
  Partials       43       43           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fsbraun
Copy link
Member Author

fsbraun commented Jan 6, 2025

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @fsbraun - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using a more efficient comparison method than JSON.stringify() for style matching. For deeply nested styles, this could impact performance.
  • The HTML string concatenation in generateColorMenu and renderStyleMenu functions could be vulnerable to XSS. Consider using DOM manipulation methods or a templating library instead.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

private/js/tiptap_plugins/cms.styles.js Outdated Show resolved Hide resolved
private/js/tiptap_plugins/cms.styles.js Outdated Show resolved Hide resolved
private/js/tiptap_plugins/cms.styles.js Show resolved Hide resolved
private/js/tiptap_plugins/cms.styles.js Outdated Show resolved Hide resolved
@fsbraun
Copy link
Member Author

fsbraun commented Jan 6, 2025

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @fsbraun - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

private/js/tiptap_plugins/cms.styles.js Show resolved Hide resolved
private/js/tiptap_plugins/cms.styles.js Show resolved Hide resolved
@fsbraun fsbraun changed the title feat: Add configurable styles feat: Add configurable block and inline styles for Tiptap Jan 6, 2025
@fsbraun fsbraun merged commit 25c019f into main Jan 6, 2025
31 checks passed
@fsbraun fsbraun deleted the feat/configurable-styles branch January 6, 2025 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant