-
Notifications
You must be signed in to change notification settings - Fork 18
Introduced ContextualBalloon class for managing contextual balloons. #177
Conversation
@@ -0,0 +1,283 @@ | |||
/** |
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.
Code of this manual test is no pretty because a lot of various things happens there :)
This code should be reduced when ContextualToolbar will become a CKE5 plugin.
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.
See: #185
I see |
… -> Editor integration.
Hm... this is not a bug of |
src/contextualballoon.js
Outdated
/** | ||
* Balloon panel view. | ||
* | ||
* @member {module:ui:view~View} #view |
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.
@readonly
?
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.
Anyway, any practical reason why not creating the BalloonPanelView
instance directly at this point but assigning it like ctxBalloon.view = new BalloonPanelView()
later on instead?
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.
I moved it to the constructor.
src/contextualballoon.js
Outdated
* @param {module:ui/contextualballoon~Panel} panelData Configuration of the panel. | ||
*/ | ||
add( panelData ) { | ||
if ( this._stack.get( panelData.view ) ) { |
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.
Wouldn't this.isPanelInStack( panelData.view )
be cleaner?
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.
Yes. I added isPanelInstack()
after I wrote this code.
src/contextualballoon.js
Outdated
/** | ||
* Trying to add configuration of the same panel more than once. | ||
* | ||
* @error contextualballoon-add-item-exist |
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.
Error id in docs does not match error id in throw new CKEditorError()
.
* @private | ||
* @member {Map} #_stack | ||
*/ | ||
this._stack = new Map(); |
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.
@readonly
?
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.
Why not @private
?
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.
A good point :P
src/contextualballoon.js
Outdated
* Common contextual balloon of the Editor. | ||
* | ||
* This class reuses the same {module:ui/view~View} for each contextual balloon panel in the editor UI, makes | ||
* possible to add multiple panels to the same balloon (stored in the stack, last one in the stack is visible) |
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.
Why calling it "panels"? They're simply views, aren't they? It's a tool to use a single BalloonPanelView
with multiple child views. The word "panel" repeats many times in this PR.
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.
Renamed.
src/contextualballoon.js
Outdated
* @param {module:ui/view~View} view View of panel which will be removed from the balloon. | ||
*/ | ||
remove( view ) { | ||
if ( !this._stack.get( view ) ) { |
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.
this.isPanelInStack( view )
src/contextualballoon.js
Outdated
this._stack.delete( view ); | ||
|
||
// Next we need to check if there is other panel in stack to show. | ||
const lastPanel = Array.from( this._stack ).pop(); |
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.
Using this._stack.values()
would let us avoid lastPanel[ 1 ]
a couple of lines later.
src/contextualballoon.js
Outdated
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror'; | ||
|
||
/** | ||
* Common contextual balloon of the Editor. |
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.
How much work would it take to make it a generic utility? I suppose eventually we may end up with other UI components which should manage their children in a similar way. E.g. a dialog, where you edit some fields, then you go deeper to edit some details or internals, then you go back again, etc., without leaving the dialog. Each editing level would be a different child view of the same dialog. If this is a lot of thinking, designing and coding we may think about it as a follow–up, because it's not necessary to MVP.
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.
I created follow-up #186
@@ -0,0 +1,292 @@ | |||
/** |
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.
It would be great to see how to the focus behaves when navigating such structure.
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.
Focus behave is a matter of feature implementation. In this PR ckeditor/ckeditor5-link#92 balloon uses focus cycler and works fine.
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.
I created issue about simplifying/improving manual test. https://github.com/ckeditor/ckeditor5-ui/issues/185
src/contextualballoon.js
Outdated
/** | ||
* Returns `true` when given view is in the stack otherwise returns `false`. | ||
* | ||
* @param {module:ui:view~View} view |
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.
Invalid link.
src/contextualballoon.js
Outdated
} | ||
|
||
/** | ||
* Adds view to the stack and makes is visible. |
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.
s/is/it
I also experienced
when pressing Esc when just loaded http://localhost:8125/ckeditor5-ui/tests/manual/contextualballoon/contextualballoon.html. |
* This plugin allows reusing a single {module:ui/panel/balloon/balloonpanelview~BalloonPanelView} instance | ||
* to display multiple contextual balloon panels in the editor. | ||
* | ||
* Child views of such a panel are stored in the stack and the last one in the stack is visible. When the |
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.
An afterthought: Since _stack
is private we should not talk in the public docs about it. It is of no concern to the devs how the CB handles views.
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.
When I wrote about stack I wasn't thinking about var name but about the way how we store it.
src/contextualballoon.js
Outdated
* @param {module:ui/view~View} view | ||
* @returns {Boolean} | ||
*/ | ||
isViewInStack( view ) { |
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.
I would rename it to hasView()
. As in https://github.com/ckeditor/ckeditor5-ui/pull/177/files#r109897538, _stack
is private and it does not concern people in the public API.
src/contextualballoon.js
Outdated
* | ||
* @returns {module:ui/contextualballoon~ViewConfig|null} | ||
*/ | ||
get visible() { |
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.
Boolean properties and variables are always prefixed by an auxiliary verb:
https://github.com/ckeditor/ckeditor5-design/wiki/Code-Style-Naming-Guidelines
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.
This getter returns visible view. It's not checking if given view is visible.
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.
So get visibleView()
maybe? I'm trying to make it less ambiguous.
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.
Hm... this returns not only the view but the whole configuration { view, position }
https://github.com/ckeditor/ckeditor5-ui/pull/177/files#diff-93d63500d90d723217fc16438b6b32a4R193
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.
But maybe only the view should be returned.
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.
Hm... looks like there is no need to return the balloon position configuration because this position is used internally by ContextualBalloon.
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.
Done.
R+ but the master is locked so we're gonna postpone the merge. |
Suggested merge commit message (convention)
Feature: Introduced
ContextualBalloon
plugin for managing contextual balloons. Closes ckeditor/ckeditor5#5296.Follow-ups: