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 dynamic links to Text plugins and HTMLFields with CKEditor 5 #6

Merged
merged 15 commits into from
Dec 18, 2024

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented Dec 16, 2024

Summary by Sourcery

Add dynamic link support to CKEditor 5 by implementing a CmsLink plugin that handles custom CMS links with a 'cmsHref' attribute, supports autocomplete, and integrates with the CKEditor UI. Update the build configuration to reflect changes in static file paths.

New Features:

  • Introduce dynamic linking capabilities to CKEditor 5 by adding a custom 'cmsHref' attribute for CMS-based links, enabling model-to-view and view-to-model conversion, and integrating autocomplete functionality for these links.

Enhancements:

  • Refactor the CmsLink plugin to extend the default CKEditor Link Plugin, providing additional functionalities such as handling custom link attributes and managing the CKEditor UI.
  • Update the CKEditor configuration to include the CmsLink plugin and adjust toolbar settings for better integration with the new dynamic link features.

Build:

  • Modify the webpack configuration to update the output path for CKEditor 5 static files.

@fsbraun
Copy link
Member Author

fsbraun commented Dec 17, 2024

@sourcery-ai summary

@fsbraun
Copy link
Member Author

fsbraun commented Dec 18, 2024

@sourcery-ai review

Copy link
Contributor

sourcery-ai bot commented Dec 18, 2024

Reviewer's Guide by Sourcery

This PR implements dynamic link support in CKEditor 5 by refactoring the link handling system. The changes introduce a new CMS-specific link plugin that manages custom link attributes and provides autocomplete functionality for link selection. The implementation focuses on improving the user experience when adding and editing links while maintaining compatibility with the CMS backend.

Class diagram for CmsLink and LinkField

classDiagram
    class CmsLink {
        +init()
        +_defineConverters()
        +_handleExtraAttributeValues()
        +_enableLinkAutocomplete()
        +_handleExtraFormFieldSubmit()
        +_handleDataLoadingIntoExtraFormField()
        +_refreshExtraAttributeValues()
        +static get pluginName()
    }
    class LinkField {
        +constructor(element, options)
        +createInput()
        +populateField()
        +registerEvents()
        +handleInput(event)
        +showResults(response, page)
        +_addResult(result, currentSection)
        +handleSelection(event)
        +handleChange()
        +search(page)
        +updateSearch()
        +fetchData(searchText, page)
    }
    CmsLink --> LinkField : uses
    note for CmsLink "Handles custom CMS links in CKEditor 5"
    note for LinkField "Manages link field input and autocomplete functionality"
Loading

File-Level Changes

Change Details Files
Implemented a new CMS Link plugin for CKEditor 5
  • Created a new CmsLink plugin class that extends the base CKEditor Link plugin
  • Added support for custom 'cmsHref' attribute in the model schema
  • Implemented model-to-view and view-to-model converters for CMS links
  • Added handlers for link and unlink commands to manage CMS-specific attributes
private/js/ckeditor5_plugins/cms-link/src/cmsLink.js
Created a new LinkField component for link selection UI
  • Implemented autocomplete functionality for link selection
  • Added support for dynamic link preview
  • Created a custom dropdown UI for link suggestions
  • Added handling for link selection and value synchronization
private/js/ckeditor5_plugins/cms-link/src/cms.linkfield.js
djangocms_text_ckeditor5/static/djangocms_text_ckeditor5/css/cms.linkfield.css
Updated CKEditor configuration and integration
  • Added CmsLink plugin to the list of built-in plugins
  • Updated webpack configuration for proper static file handling
  • Modified CSS paths and added new stylesheets
  • Removed deprecated link suggestion editing code
private/js/cms.ckeditor5.js
webpack.config.js
djangocms_text_ckeditor5/__init__.py

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:

  • Consider adding error handling for fetch calls in the link preview and autocomplete functionality to gracefully handle API failures
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 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/ckeditor5_plugins/cms-link/src/cms.linkfield.js Outdated Show resolved Hide resolved
private/js/ckeditor5_plugins/cms-link/src/cmsLink.js Outdated Show resolved Hide resolved
private/js/cms.ckeditor5.js Outdated Show resolved Hide resolved
private/js/cms.ckeditor5.js Show resolved Hide resolved
private/js/cms.ckeditor5.js Outdated Show resolved Hide resolved
@fsbraun fsbraun marked this pull request as ready for review December 18, 2024 16:34
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.

We have skipped reviewing this pull request. It looks like we've already reviewed the commit ad2568f in this pull request.

@fsbraun fsbraun merged commit 89f4e7e into main Dec 18, 2024
4 checks passed
@fsbraun fsbraun deleted the feat/dynamic-html branch December 18, 2024 17:29
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