-
Notifications
You must be signed in to change notification settings - Fork 37
Image captioning #48
Image captioning #48
Conversation
…nd of figure element.
Some issues to be resolved in the first place:
|
And tests fail after I merged master into this branch. |
@@ -57,6 +59,13 @@ export function viewToModelImage() { | |||
modelImage.setAttribute( 'alt', viewImg.getAttribute( 'alt' ) ); | |||
} | |||
|
|||
// Convert children of converted view element and append them to `modelImage`. |
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.
* | ||
* @extends module:core/plugin~Plugin | ||
*/ | ||
export default class ImageCaptioning extends 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.
Simply: ImageCaption
. We have ImageStyles
not ImageStyling
.
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.
Besides, since this plugin is empty now, you can merge the engine part into it. Unless... unless we see that adding the placeholder will require some strictly UI-related logic.
OTOH, by splitting the feature beforehand we stick to some pattern, so I'm not sure what would be better.
src/imagecaptioning/utils.js
Outdated
*/ | ||
export function captionEditableCreator( viewDocument ) { | ||
return () => { | ||
const editable = new ViewEditableElement( 'figcaption', { contenteditable: true } ) ; |
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.
Space before ;
.
src/imagecaptioning/utils.js
Outdated
* @param {module:engine/view/document~Document} viewDocument | ||
* @return {Function} | ||
*/ | ||
export function captionEditableCreator( viewDocument ) { |
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.
editableCaptionCreator()
src/imagecaptioning/utils.js
Outdated
const captionSymbol = Symbol( 'imageCaption' ); | ||
|
||
/** | ||
* Returns function that creates caption editable element for given {@link module:engine/view/document~Document}. |
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.
"Returns a function", "for the given"
src/imagecaptioning/utils.js
Outdated
* @param {module:engine/view/element~Element} viewElement | ||
* @return {Boolean} | ||
*/ | ||
export function isCaptionEditable( viewElement ) { |
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.
isEditableCaption
to pair with the other method. I'm also thinking about isCaption
and captionElementCreator
. That "editable" part is confusing. Or maybe captionEditableElementCreator
? I don't know... :D So maybe let's choose the shortest versions, WDYT?
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'll go with captionElementCreator
and isCaption
- sounds better and it's shorter too.
src/imagecaptioning/utils.js
Outdated
* @return {module:engine/model/element~Element|null} | ||
*/ | ||
export function getCaptionFromImage( imageModelElement ) { | ||
for ( let node of imageModelElement.getChildren() ) { |
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.
Could be like:
Array.from( imageModelElement.getChildren() ).find( node => node.is( 'caption' ) )
If we do https://github.com/ckeditor/ckeditor5-engine/issues/809.
src/widget/widget.js
Outdated
if ( !isWidget( widgetElement ) ) { | ||
widgetElement = widgetElement.findAncestor( element => isWidget( element ) ); | ||
widgetElement = widgetElement.findAncestor( element => { |
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.
widgetElement.findAncestor( isWidget );
src/widget/widgetengine.js
Outdated
const widget = editableElement.findAncestor( element => isWidget( element ) ); | ||
|
||
if ( widget ) { | ||
widget.addClass( WIDGET_SELECTED_CLASS_NAME ); |
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.
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 is complicated :P.
Instead of using stuff like:
const STICKS_TO_PREVIOUS = 0;
const STICKS_TO_NEXT = 1;
...
if ( this.stickiness == STICKS_TO_PREVIOUS ) { ... }
we decided to just use 'sticksToPrevious'
string. But this works only for closed list of constant values and was done to get rid of imports.
I don't know whether we decided anything about package-scope/configuration constants like this. If I wrote that code, I'd go with widgetSelectedClassName
but I can't say this is wrong either.
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 can see we use the ALL_CAPS notation in some cases. INLINE_FILLER_LENGTH
, BR_FILLER
, NBSP_FILLER
, DEFAULT_PRIORITY
. Also, all but one export const
use this notation. So let's stick to that.
Can't you, instead of |
Conversion builder does not allow to specify any information about attribute's element. I don't want to convert all |
Tests: CHecking if caption is added to limits set in schema.
Added caption to limits set in schema, test it further after closing ckeditor/ckeditor5-engine#825. |
Everything works brilliantly! |
I'm closing this PR despite the fact that the related tickets in engine and enter packages are still open. Let's not risk some conflicts. I've spotted two issues with the image caption implementation: #58 and #57. |
Adds captioning feature.
Currently there is no placeholder when caption's nested editable is empty.
There are other issues with nested editables, that will be reported in proper repositories and fixed (keyboard support etc.).
Fixes ckeditor/ckeditor5#5048.