-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a builtin Position, Range and Selection factories #4427
Comments
We've been planning this for a long time but I realised that it will significantly affect some of the documentation. This is currently one of the biggest blockers to write plugins without dependency on the engine. |
Wow, that's huge :/ However, I agree that this is important. |
I actually don't think that it's so big. It may even turn out that we'll simply move the static factory methods to some other place and implement a simple pass-through method for constructors. We've got most of the code and tests. I hope it's mostly about moving it around. |
I also think that is just that. Maybe huge in terms of lines changed but doable right now. |
That might be true. I was checking the API and realized that we have also
(https://github.com/ckeditor/ckeditor5-media-embed/blob/7e75a681aa070ebdd4f5fddf04bdf8e1887903e2/src/automediaembed.js#L117)
Also, I was checking how often do we use I think that we need to simply count the number of usage of all constructors and static methods of |
@pjasiun with pleasure ;) Already on it. Some conclusion are already there, like |
Current usage of model importsImports:
As you can see it's not much (probably test would have hundreds...) - also there are some minimal usages of other things like Position
Range
Live Range & Live Position
Selection
Element
|
New model API proposalWhere to expose new APIInitially I thought that it should go on
So I'm for Position
doc.createPosition( [ 0, 1, 2 ] ); // creates position in default root
doc.createPosition( [ 0, 1, 2 ], '$graveyard' );
doc.createPosition( [ 0, 1 ], doc.getRoot() ); Summary: const doc = editor.model.document;
const positionAfter = doc.createPositionAt( node, 'after' );
const positionBefore = doc.createPositionAt( node, 'before' );
const positionAt = doc.createPositionAt( node, 7 );
const positionAtEnd = doc.createPositionAt( node, 'end' );
const cloned = positionAt.clone();
const positionInTest = doc.createPosition( [ 0, 2, 3 ], '$graveyard' ); Range
Summary: const doc = editor.model.document;
const range = doc.createRange( position, position.getShiftedBy( 7 ) );
const cloned = range.clone();
const rangeOnNode = doc.createRangeOn( node );
const rangeInsideNode = doc.createRangeIn( tableCell ); SelectionThe selection factory to be exposed: const selection = doc.createSelection( doc.createRange( start, end ) );
doc.selection.setSelection( selection ) Other APIs (might be follow ups):
const liveRange = doc.createLiveRange( range );
// or:
doc.createLiveRange( start, end ); // or both
const livePostion = doc.createLivePosition( position );
|
Great research. Can't wait to see the new API in action. Some notes from me.
That's not true. You can have a position on the detached document fragment which is not a document.
I'm for it. Especially if we will hide
See https://github.com/ckeditor/ckeditor5-engine/issues/1086.
I am for |
So we agreed that:
|
I just found this: const endPos = LivePosition.createFromPosition( selRange.end );
endPos.stickiness = 'toNext'; Perhaps worth considering while taking care of |
Other: Moved `Position`, `Range` and `Selection` factories from those classes to the model/view writers and `Model`/`View` instances. Previously, those factories were available as static methods of the `Position`, `Range` and `Selection` classes which meant that you needed to import those classes to your plugin's code to create new instances. That required your package to depend on `@ckeditor/ckeditor5-engine` and was not very useful in general. After this change, you can create instances of those classes without importing anything. See the "Breaking changes" section for more details. Closes #1555. BREAKING CHANGE: The model `Position.createAt()` method was removed from the public API. Use `writer.createPositionAt()` instead. This method is also available on the `Model` instance. BREAKING CHANGE: The model `Position.createAfter()` method was removed from the public API. Use `writer.createPositionAfter()` instead. This method is also available on the `Model` instance. BREAKING CHANGE: The model `Position.createBefore()` method was removed from the public API. Use `writer.createPositionBefore()` instead. This method is also available on the `Model` instance. BREAKING CHANGE: The model `Position.createFromPosition()` method was removed. Use `writer.createPositionAt( position )` to create a new position instance. This method is also available on the `Model` instance. BREAKING CHANGE: The model `Position.createFromParentAndOffset()` method was removed. Use `writer.createPositionAt( parent, offset )` instead. This method is also available on the `Model` instance. BREAKING CHANGE: The model `Range.createIn()` method was removed from the public API. Use `writer.createRangeIn()` instead. This method is also available on the `Model` instance. BREAKING CHANGE: The model `Range.createOn()` method was removed from the public API. Use `writer.createRangeOn()` instead. This method is also available on the `Model` instance. BREAKING CHANGE: The model `Range.createFromRange()` method was removed from the public API. BREAKING CHANGE: The model `Range.createFromParentsAndOffsets()` method was removed from the public API. BREAKING CHANGE: The model `Range.createFromPositionAndShift()` method was removed from the public API. BREAKING CHANGE: The model `Range.createCollapsedAt()` method removed method was removed. Use `writer.createRange( position )` to create collapsed range. This method is also available on the `Model` instance. BREAKING CHANGE: The model `Range.createFromRanges()` method was removed from the public API. BREAKING CHANGE: The view `Position.createAt()` method was removed from the public API. Use `writer.createPositionAt()` instead. This method is also available on the `View` instance. BREAKING CHANGE: The view `Position.createAfter()` method was removed from the public API. Use `writer.createPositionAfter()` instead. This method is also available on the `View` instance. BREAKING CHANGE: The view `Position.createBefore()` method was removed from the public API. Use `writer.createPositionBefore()` instead. This method is also available on the `View` instance. BREAKING CHANGE: The view `Position.createFromPosition()` method was removed. Use `writer.createPositionAt( position )` to create a new position instance. This method is also available on the `View` instance. BREAKING CHANGE: The view `Range.createIn()` method was removed from the public API. Use `writer.createRangeIn()` instead. This method is also available on the `View` instance. BREAKING CHANGE: The view `Range.createOn()` method was removed from the public API. Use `writer.createRangeOn()` instead. This method is also available on the `View` instance. BREAKING CHANGE: The view `Range.createFromRange()` method was removed from the public API. BREAKING CHANGE: The view `Range.createFromPositionAndShift()` method was removed from the public API. BREAKING CHANGE: The view `Range.createFromParentsAndOffsets()` method was removed from the public API. BREAKING CHANGE: The view `Range.createCollapsedAt()` method removed method was removed. Use `writer.createRange( position )` to create a collapsed range. This method is also available on the `View` instance.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Strongly related to #667.
@ckeditor/ckeditor5-engine/src
in plugins (source, not tests). I used this regexpimport [\w, {},_]+ from '@ckeditor/ckeditor5-engine/src
. From my quick check, 90% of that arePosition
,Range
andSelection
from the model and the view. There are also some converters fromsrc/conversion/downcast-converters
andsrc/conversion/upcast-converters
, but one thing at a time (https://github.com/ckeditor/ckeditor5-engine/issues/1556).createRange()
,createRangeOn()
, etc.Range
andPosition
may be removed since the factories will be created.Document
classes or onView
&Model
?@ckeditor/ckeditor5-engine
can be removed in a couple of plugins.cc @jodator @pjasiun
Edit (by @jodator):
The text was updated successfully, but these errors were encountered: