-
Notifications
You must be signed in to change notification settings - Fork 40
Create writer for non-semantic view manipulation #1503
Conversation
Also, I disagree that the writer has nothing to do with downcasting, because if it used a lot during downcasting. It is as important for downcasting as converters, doing a big part of creating view during downcasting. |
I'm fine with it, just one clarification - so the existing
That's true for the current |
Nope. The existing one ( |
That's true, but we could bend the definition a little for this case. How, upcasting is View -> Model, but it could be Data -> View -> Model (downcasting Model -> View -> Data). Then it will fit well. |
Yes, it makes sense and makes it easier to understand with upcasting/downcasting defined in such way 👍 |
@pjasiun I will update the naming and docs and ping you when it's ready. |
@pjasiun I have renamed So this PR is ready for R. |
src/view/upcastwriter.js
Outdated
* @param {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment} element Element | ||
* to which items will be appended. | ||
* @param {module:engine/view/item~Item|Iterable.<module:engine/view/item~Item>} items Items to be inserted. | ||
* @fires module:engine/view/node~Node#change |
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.
We (at least I ;)) usually write event:change
. Does the line above create proper docs?
BTW., those change events on view tree are so internal that I am not sure if it is worth documenting. @pjasiun ?
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.
From what I see, both produce the same link .../module_engine_view_node-Node.html#event:change
but I will update it to make it consistent.
However, I just discovered it doesn't work properly in our docs 😱 The generated links are e.g. ...api/module_engine_conversion_upcastdispatcher-UpcastDispatcher.html#event:element
, while to working one is ...api/module_engine_conversion_upcastdispatcher-UpcastDispatcher.html#event-element
(so -
instead of :
in event name). I will report it.
src/view/upcastwriter.js
Outdated
* @see module:engine/view/element~Element#_insertChild | ||
* @param {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment} element Element | ||
* to which items will be inserted. | ||
* @param {Number} index Position where nodes should be inserted. |
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.
Offset at which
?
src/view/upcastwriter.js
Outdated
* @see module:engine/view/element~Element#_removeChildren | ||
* @param {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment} element Element | ||
* from which children will be removed. | ||
* @param {Number} index Number of the first node to remove. |
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.
Offset from which
?
src/view/upcastwriter.js
Outdated
* @param {Number} index Number of the first node to remove. | ||
* @param {Number} [howMany=1] Number of nodes to remove. | ||
* @fires module:engine/view/node~Node#change | ||
* @returns {Array.<module:engine/view/node~Node>} The array of removed nodes. |
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.
containing
?
src/view/upcastwriter.js
Outdated
* Removes given element from the view structure. Will not have effect on detached elements. | ||
* | ||
* @param {module:engine/view/element~Element} element Element which will be removed. | ||
* @returns {Array.<module:engine/view/node~Node>} The array of removed nodes. |
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.
with removed nodes
?
src/view/upcastwriter.js
Outdated
*/ | ||
remove( element ) { | ||
const parent = element.parent; | ||
if ( parent ) { |
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.
New line please? :)
src/view/upcastwriter.js
Outdated
* Replaces given element with the new one in the view structure. Will not have effect on detached elements. | ||
* | ||
* @param {module:engine/view/element~Element} oldElement Element which will be replaced. | ||
* @param {module:engine/view/element~Element} newElement Element which will inserted in the place of the old 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.
will be
src/view/upcastwriter.js
Outdated
} | ||
|
||
/** | ||
* Adds or overwrite element's attribute with a specified key and value. |
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.
overwrites
(I see that this is a typo also at the place you copied from :P)
I have one overall issue: the parameters in methods in this class have a different order than the parameters in |
Note that |
Yes... The reason I did it that way is that in a former However, in the
So:
From my perspective it is a choice between keeping it internally consistent or trying to make it consistent with some Btw. |
I will propose a follow-up issue. 🤔 @pjasiun I don't see |
Wasn't |
Yep. DOM converter now is using protected elements API and it should use this writer instead. |
@f1ames Correct me if I am wrong, but AFAICS the methods that are not available in
So if we would change
|
Sorry, |
Makes sense. I will extract those changes to a separate issue to not block this PR for too long ;) |
As I applied all requested changes, it is ready another R. |
Suggested merge commit message (convention)
Internal: Introduced writer for manipulating non-semantic view. Closes ckeditor/ckeditor5#4399.
Additional information
I'm still not sure about naming, the name I used is
RawWriter
, but we have discussed alsoUpcast/Downcast
writer. Maybe looking at the code it will be easier to decide. I'm not in favor of any,upcast/downcast
doesn't fit that much as this writer has basically nothing to do with upcasting/downcasting (apart from the fact that it touches view instance which may get upcasted eventually - but lots of classes do). Andraw
is somehow descriptive, but still you need to know the context well.