Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Introduced util for checking whether the editor wasn't initialized on the same element more than once #176

Merged
merged 10 commits into from
Jul 23, 2019

Conversation

pomek
Copy link
Member

@pomek pomek commented Jun 4, 2019

Suggested merge commit message (convention)

Feature: Introduced a secureSourceElement() utility that makes sure source DOM elements are not shared between editor instances. See ckeditor/ckeditor5#746.

…ified sourceElement was used more than once.
@coveralls
Copy link

coveralls commented Jul 16, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling b8656e4 on t/ckeditor5/746 into cba2fd6 on master.

Copy link
Contributor

@jodator jodator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some updates to docs are needed - the PR is OK :) I have only one question to @Reinmar about naming the error.

src/editor/utils/securesourceelement.js Outdated Show resolved Hide resolved

if ( sourceElement.hasAttribute( SECURE_ATTRIBUTE ) ) {
/**
* An element passed to the editor creator has been passed more than once. The element can be used only once.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* An element passed to the editor creator has been passed more than once. The element can be used only once.
* Another editor instance was already initialized on this element. You cannot create more then one editor on the same element.

Or something similar - I get the feeling that the error description should reflect how someone could use our API. So it is rather creating two or more instances of the ediotr on some element then passing something.

src/editor/utils/securesourceelement.js Outdated Show resolved Hide resolved
tests/editor/utils/securesourceelement.js Outdated Show resolved Hide resolved
src/editor/utils/securesourceelement.js Outdated Show resolved Hide resolved
@oleq
Copy link
Member

oleq commented Jul 19, 2019

Why not a part of ElementApiMixin?

@jodator
Copy link
Contributor

jodator commented Jul 19, 2019

Why not a part of ElementApiMixin?

I think that probably for the same reason as #173 (comment)

I think that not every editor build is initialized over an element.

Edit: I was wrong - @oleq this looks like a place for this util.

@oleq
Copy link
Member

oleq commented Jul 19, 2019

I moved the method and updated other PRs.

But don't merge it please, because I figured we can go further and have ElementDataMixin#setSourceElement(), that will handle these

if ( isElement( sourceElementOrData ) ) {
	this.sourceElement = sourceElementOrData;
	this.secureSourceElement();
}

in editor constructors as

if ( isElement( sourceElementOrData ) ) {
	this.setSourceElement( sourceElementOrData );
}

with backwards compatibility (setting this.sourceElement directly will warn about this way being obsolete like we did with EditorUI.editableElements).

Gonna create it ASAP.

oleq added 2 commits July 22, 2019 10:43
…e it does not make sense in the mixin because the mixin is used wrongly in the first place :P
@oleq
Copy link
Member

oleq commented Jul 22, 2019

I reverted some of the changes I made because it turned out the ElementApi interface does not make sense the way we use it (RFC). Securing the editor element should remain a helper. The code is ready for review.

@oleq
Copy link
Member

oleq commented Jul 22, 2019

Self–review: maybe instead of using data- attributes we should simply use DOM element properties? Less clutter in the view/DOM.

@jodator
Copy link
Contributor

jodator commented Jul 22, 2019

Self–review: maybe instead of using data- attributes we should simply use DOM element properties? Less clutter in the view/DOM.

Sounds cool :)

@Reinmar
Copy link
Member

Reinmar commented Jul 22, 2019

Self–review: maybe instead of using data- attributes we should simply use DOM element properties? Less clutter in the view/DOM.

Just like editableElement.ckeditorInstance? In fact, we could assign ckeditorInstance there for the same reasons why we marked editable elements with it :)

@oleq
Copy link
Member

oleq commented Jul 22, 2019

In fact... we could use #ckeditorInstance that we recently implemented.

@oleq
Copy link
Member

oleq commented Jul 22, 2019

Perfect timing.

@oleq
Copy link
Member

oleq commented Jul 22, 2019

Ready for another round of review.

Copy link
Contributor

@jodator jodator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I've fixed only one docs as I couldn't parse it :)

@jodator jodator merged commit 6a59058 into master Jul 23, 2019
@jodator jodator deleted the t/ckeditor5/746 branch July 23, 2019 10:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants