This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Extracted nested editable styles and logic to widgets. #74
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b0b4bc7
Extracted nested editable styles and logic to widgets.
szymonkups a80dff3
Renamed utils functions: widgetize to toWidget and createNestedEditab…
szymonkups 7ef4895
CSS classes name refactoring in widgets.
szymonkups a426d5a
Widget util function toWidgetEditable now accepts element to have sim…
szymonkups 3be8718
Fixed widget and caption styles.
szymonkups aeb276b
Added ck-editor__editable prefix to content styles.
szymonkups c025e49
Fixed indentation in theme file.
szymonkups d797993
Use data classes to style the content. Removed invalid comment.
Reinmar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ export function isWidget( element ) { | |
} | ||
|
||
/** | ||
* "Widgetizes" given {@link module:engine/view/element~Element}: | ||
* Converts given {@link module:engine/view/element~Element} to widget in following way: | ||
* * sets `contenteditable` attribute to `true`, | ||
* * adds custom `getFillerOffset` method returning `null`, | ||
* * adds `ck-widget` CSS class, | ||
|
@@ -47,7 +47,7 @@ export function isWidget( element ) { | |
* a plain string or a function returning a string. | ||
* @returns {module:engine/view/element~Element} Returns same element. | ||
*/ | ||
export function widgetize( element, options ) { | ||
export function toWidget( element, options ) { | ||
options = options || {}; | ||
element.setAttribute( 'contenteditable', false ); | ||
element.getFillerOffset = getFillerOffset; | ||
|
@@ -89,6 +89,30 @@ export function getLabel( element ) { | |
return typeof labelCreator == 'function' ? labelCreator() : labelCreator; | ||
} | ||
|
||
/** | ||
* Adds functionality to provided {module:engine/view/editableelement~EditableElement} to act as a widget's editable: | ||
* * sets `contenteditable` attribute to `true`, | ||
* * adds `ck-editable` CSS class, | ||
* * adds `ck-editable_focused` CSS class when editable is focused and removes it when it's blurred. | ||
* | ||
* @param {module:engine/view/editableelement~EditableElement} editable | ||
* @returns {module:engine/view/editableelement~EditableElement} Returns same element that was provided in `editable` param. | ||
*/ | ||
export function toWidgetEditable( editable ) { | ||
editable.setAttribute( 'contenteditable', 'true' ); | ||
editable.addClass( 'ck-editable' ); | ||
|
||
editable.on( 'change:isFocused', ( evt, property, is ) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new Template( {
attributes: {
contenteditable: true,
class: [
'ck-editable',
bind.if( editable, 'isFocused', 'ck-editable_focused' )
]
}
} ).apply( editable ); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above – nope. This is not a native element. |
||
if ( is ) { | ||
editable.addClass( 'ck-editable_focused' ); | ||
} else { | ||
editable.removeClass( 'ck-editable_focused' ); | ||
} | ||
} ); | ||
|
||
return editable; | ||
} | ||
|
||
// Default filler offset function applied to all widget elements. | ||
// | ||
// @returns {null} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think this and the following line should be done via
Template.apply()
. One of the reasons we decided to have aTemplate
class was that DOM attrs should be touched via unified API.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.
That's not true. This isn't UI. This is the engine and the element here isn't a native DOM element. We've been talking about unifying the APIs, but that never happened and I guess won't happen anytime soon.
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.
Nice catch! I didn't notice that this isn't DOM. You're right, ofc ;-)