-
Notifications
You must be signed in to change notification settings - Fork 3
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: Improve tiptop-integration of toolbars for better UX #43
base: main
Are you sure you want to change the base?
Conversation
Reviewer's Guide by SourceryThis PR refactors the toolbar system to improve UX by moving the toolbars into the editable div, changing the block toolbar from a dialog to a div, and refactoring the toolbar code into its own module. Sequence diagram for toolbar interaction flowsequenceDiagram
actor User
participant Editor
participant Toolbar
participant ProseMirror
User->>Editor: Click in editable area
Editor->>ProseMirror: Focus event
ProseMirror->>Toolbar: Show toolbar decorations
User->>Toolbar: Click toolbar button
Toolbar->>ProseMirror: Execute command
ProseMirror->>Editor: Update content
Editor->>Toolbar: Update button states
Class diagram for the new toolbar systemclassDiagram
class CmsToolbarPlugin {
+addProseMirrorPlugins()
}
class ToolbarPlugin {
+props
+state
-handleDOMEvents
-createToolbar()
-updateToolbar()
}
class TiptapToolbar {
+action()
+enabled()
+active()
+type: string
}
CmsToolbarPlugin --> ToolbarPlugin
ToolbarPlugin --> TiptapToolbar
note for CmsToolbarPlugin "Extension that adds toolbar functionality"
note for ToolbarPlugin "ProseMirror plugin for toolbar management"
note for TiptapToolbar "Toolbar button definitions and handlers"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #43 +/- ##
=======================================
Coverage 81.16% 81.16%
=======================================
Files 17 17
Lines 929 929
Branches 104 104
=======================================
Hits 754 754
Misses 132 132
Partials 43 43 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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 found some issues that need to be addressed.
Blocking issues:
- Fix typo in mousedowxn event handler name (link)
Overall Comments:
- Consider moving the SVG icon definitions to separate asset files to improve code readability and maintainability
Here's what I looked at during the review
- 🔴 General issues: 1 blocking issue
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
…t into feat/pm-widgets # Conflicts: # private/js/tiptap_plugins/cms.toolbar.js
@sourcery-ai review |
There was a problem hiding this 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: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@@ -0,0 +1,563 @@ | |||
/* eslint-env es11 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider refactoring the toolbar creation and event handling to be more modular and reduce duplication.
The toolbar implementation has unnecessary complexity that can be reduced in two key areas:
- Break down the monolithic
_populateToolbar
function into focused component builders:
function _createToolbarButton(editor, item, filter) {
// Existing button creation logic
}
function _createDropdown(editor, item, filter) {
const dropdown = typeof item.items === 'function'
? item.items(editor, items => _populateToolbar(editor, items, filter))
: _populateToolbar(editor, item.items, filter);
return `<span title='${item.title}' class="dropdown" role="button">
${item.icon}<div class="dropdown-content ${item.class || ''}">${dropdown}</div>
</span>`;
}
function _populateToolbar(editor, array, filter) {
return array.map(item => {
if (Array.isArray(item)) return _handleGroup(editor, item, filter);
if (item.constructor === Object) return _createDropdown(editor, item, filter);
if (item === '|') return editor.options.separator_markup;
return _createToolbarButton(editor, item, filter);
}).join('');
}
- Consolidate duplicated event handling between block and top toolbar:
const sharedToolbarHandlers = {
handleClick(view, event, editor) {
if (this.containsTarget(event.target)) {
_handleToolbarClick(event, editor);
return true;
}
_closeAllDropdowns(event, editor);
return false;
},
containsTarget(target) {
return this.toolbar?.contains(target);
}
};
function createToolbarPlugin(editor, type) {
return new Plugin({
props: {
handleDOMEvents: {
click(view, event) {
return sharedToolbarHandlers.handleClick(view, event, editor);
}
}
}
// ... rest of plugin config
});
}
These changes maintain all functionality while making the code more maintainable and easier to understand.
UX improvements
This PR introduces a new toolbar system for improved user experience.
div
as Prosemirror decorations. This avoids problems with timeouts when the editablediv
blurs.dialog
tag to adiv
tag to leverage the different focus concepts.Summary by Sourcery
New Features: