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

Commit

Permalink
Improved major view classes docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Nov 8, 2018
1 parent b0aa93b commit f0d6d5d
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 83 deletions.
7 changes: 4 additions & 3 deletions src/dev-utils/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { isPlainObject } from 'lodash-es';
import toMap from '@ckeditor/ckeditor5-utils/src/tomap';

/**
* Writes the content of the {@link module:engine/model/document~Document document} to an HTML-like string.
* Writes the content of a model {@link module:engine/model/document~Document document} to an HTML-like string.
*
* **Note:** A {@link module:engine/model/text~Text text} node that contains attributes will be represented as:
*
Expand Down Expand Up @@ -72,9 +72,10 @@ export function getData( model, options = {} ) {
getData._stringify = stringify;

/**
* Sets the content of the {@link module:engine/model/document~Document document} provided as an HTML-like string.
* Sets the content of a model {@link module:engine/model/document~Document document} provided as an HTML-like string.
*
* **Note:** Remember to register elements in the {@link module:engine/model/model~Model#schema model's schema} before inserting them.
* **Note:** Remember to register elements in the {@link module:engine/model/model~Model#schema model's schema} before
* trying to use them.
*
* **Note:** To create a {@link module:engine/model/text~Text text} node that contains attributes use:
*
Expand Down
7 changes: 4 additions & 3 deletions src/dev-utils/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function getData( view, options = {} ) {
getData._stringify = stringify;

/**
* Sets the content of the {@link module:engine/view/document~Document document} provided as an HTML-like string.
* Sets the content of a view {@link module:engine/view/document~Document document} provided as an HTML-like string.
*
* @param {module:engine/view/view~View} view
* @param {String} data An HTML-like string to write into the document.
Expand Down Expand Up @@ -111,6 +111,7 @@ setData._parse = parse;

/**
* Converts view elements to HTML-like string representation.
*
* A root element can be provided as {@link module:engine/view/text~Text text}:
*
* const text = downcastWriter.createText( 'foobar' );
Expand All @@ -131,7 +132,7 @@ setData._parse = parse;
* stringify( fragment ); // '<p style="color:red;"></p><b name="test">foobar</b>'
*
* Additionally, a {@link module:engine/view/documentselection~DocumentSelection selection} instance can be provided.
* Ranges from the selection will then be included in output data.
* Ranges from the selection will then be included in the output data.
* If a range position is placed inside the element node, it will be represented with `[` and `]`:
*
* const text = downcastWriter.createText( 'foobar' );
Expand Down Expand Up @@ -251,7 +252,7 @@ export function stringify( node, selectionOrPositionOrRange = null, options = {}
}

/**
* Parses an HTML-like string and returns view tree nodes.
* Parses an HTML-like string and returns a view tree.
* A simple string will be converted to a {@link module:engine/view/text~Text text} node:
*
* parse( 'foobar' ); // Returns an instance of text.
Expand Down
14 changes: 7 additions & 7 deletions src/view/attributeelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
const DEFAULT_PRIORITY = 10;

/**
* Attributes are elements which define document presentation. They are mostly elements like `<b>` or `<span>`.
* Attributes can be broken and merged by the {@link module:engine/view/downcastwriter~DowncastWriter view downcast writer}.
* Attribute elements are used to represent formatting elements in the view (think – `<b>`, `<span style="font-size: 2em">`, etc.).
* Most often they are created when downcasting model text attributes.
*
* Editing engine does not define fixed HTML DTD. This is why the type of the {@link module:engine/view/element~Element} need to
* be defined by the feature developer. Creating an element you should use {@link module:engine/view/containerelement~ContainerElement}
* class or `AttributeElement`.
* Editing engine does not define a fixed HTML DTD. This is why a feature developer needs to choose between various
* types (container element, {@link module:engine/view/attributeelement~AttributeElement attribute element},
* {@link module:engine/view/emptyelement~EmptyElement empty element}, etc) when developing a feature.
*
* The constructor of this class shouldn't be used directly. To create new `AttributeElement` use the
* {@link module:engine/view/downcastwriter~DowncastWriter#createAttributeElement `downcastWriter#createAttributeElement()`} method.
* To create a new attribute element instance use the
* {@link module:engine/view/downcastwriter~DowncastWriter#createAttributeElement `DowncastWriter#createAttributeElement()`} method.
*
* @extends module:engine/view/element~Element
*/
Expand Down
41 changes: 12 additions & 29 deletions src/view/containerelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,22 @@ import Element from './element';

/**
* Containers are elements which define document structure. They define boundaries for
* {@link module:engine/view/attributeelement~AttributeElement attributes}. They are mostly use for block elements like `<p>` or `<div>`.
* {@link module:engine/view/attributeelement~AttributeElement attributes}. They are mostly used for block elements like `<p>` or `<div>`.
*
* Editing engine does not define fixed HTML DTD. This is why the type of the {@link module:engine/view/element~Element} need to
* be defined by the feature developer.
* Editing engine does not define a fixed HTML DTD. This is why a feature developer needs to choose between various
* types (container element, {@link module:engine/view/attributeelement~AttributeElement attribute element},
* {@link module:engine/view/emptyelement~EmptyElement empty element}, etc) when developing a feature.
*
* To create new `ContainerElement`
* {@link module:engine/view/downcastwriter~DowncastWriter#createContainerElement `DowncastWriter#createContainerElement()`}
* method should be used.
*
* Creating an element you should use `ContainerElement` class or {@link module:engine/view/attributeelement~AttributeElement}. This is
* important to define the type of the element because of two reasons:
*
* Firstly, {@link module:engine/view/domconverter~DomConverter} needs the information what is an editable block to convert elements to
* DOM properly. {@link module:engine/view/domconverter~DomConverter} will ensure that `ContainerElement` is editable and it is possible
* to put caret inside it, even if the container is empty.
*
* Secondly, {@link module:engine/view/downcastwriter~DowncastWriter view downcast writer} uses this information.
* Nodes {@link module:engine/view/downcastwriter~DowncastWriter#breakAttributes breaking} and
* {@link module:engine/view/downcastwriter~DowncastWriter#mergeAttributes merging} is performed only in a bounds of a container nodes.
*
* For instance if `<p>` is an container and `<b>` is attribute:
* The container element should be your default choice when writing a converter, unless:
*
* <p><b>fo^o</b></p>
* * this element represents a model text attribute (then use {@link module:engine/view/attributeelement~AttributeElement}),
* * this is an empty element like `<img>` (then use {@link module:engine/view/emptyelement~EmptyElement}),
* * this is a root element,
* * this is a nested editable element (then use {@link module:engine/view/editableelement~EditableElement}).
*
* {@link module:engine/view/downcastwriter~DowncastWriter#breakAttributes breakAttributes} will create:
*
* <p><b>fo</b><b>o</b></p>
*
* There might be a need to mark `<span>` element as a container node, for example in situation when it will be a
* container of an inline widget:
*
* <span color="red">foobar</span> // attribute
* <span data-widget>foobar</span> // container
* To create a new container element instance use the
* {@link module:engine/view/downcastwriter~DowncastWriter#createContainerElement `DowncastWriter#createContainerElement()`}
* method.
*
* @extends module:engine/view/element~Element
*/
Expand Down
6 changes: 3 additions & 3 deletions src/view/documentfragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import isIterable from '@ckeditor/ckeditor5-utils/src/isiterable';
import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';

/**
* DocumentFragment class.
* Document fragment.
*
* The constructor of this class shouldn't be used directly. To create new DocumentFragment instance use the
* To create a new document fragment instance use the
* {@link module:engine/view/upcastwriter~UpcastWriter#createDocumentFragment `UpcastWriter#createDocumentFragment()`}
* method instead.
* method.
*/
export default class DocumentFragment {
/**
Expand Down
5 changes: 3 additions & 2 deletions src/view/downcastwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ import { isPlainObject } from 'lodash-es';
* It provides a set of methods used to manipulate view nodes.
*
* The `DowncastWriter` is designed to work with semantic views which are the views that were/are being downcasted from the model.
* To work with ordinary views (e.g. parsed from a string) use the {@link module:engine/view/upcastwriter~UpcastWriter upcast writer}.
* To work with ordinary views (e.g. parsed from a pasted content) use the
* {@link module:engine/view/upcastwriter~UpcastWriter upcast writer}.
*
* Do not create an instance of this writer manually. To modify a view structure, use
* the {@link module:engine/view/view~View#change View#change()) block.
* the {@link module:engine/view/view~View#change `View#change()`) block.
*/
export default class DowncastWriter {
constructor( document ) {
Expand Down
4 changes: 2 additions & 2 deletions src/view/emptyelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import Node from './node';

/**
* EmptyElement class. It is used to represent elements that cannot contain any child nodes (for example `<img>` elements).
* Empty element class. It is used to represent elements that cannot contain any child nodes (for example `<img>` elements).
*
* The constructor of this class shouldn't be used directly. To create new `EmptyElement` use the
* To create a new empty element use the
* {@link module:engine/view/downcastwriter~DowncastWriter#createEmptyElement `downcastWriter#createEmptyElement()`} method.
*/
export default class EmptyElement extends Element {
Expand Down
8 changes: 7 additions & 1 deletion src/view/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import EditableElement from './editableelement';

/**
* Position in the tree. Position is always located before or after a node.
* Position in the view tree. Position is represented by its parent node and an offset in this parent.
*
* In order to create a new position instance use the `createPosition*()` factory methods available in:
*
* * {@module:engine/view/view~View}
* * {@module:engine/view/downcastwriter~DowncastWriter}
* * {@module:engine/view/upcastwriter~UpcastWriter}
*/
export default class Position {
/**
Expand Down
42 changes: 28 additions & 14 deletions src/view/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import Position from './position';
import TreeWalker from './treewalker';

/**
* Tree view range.
* Range in the view tree. A range is represented by its start and end {@link module:engine/view/position~Position positions}.
*
* In order to create a new position instance use the `createPosition*()` factory methods available in:
*
* * {@module:engine/view/view~View}
* * {@module:engine/view/downcastwriter~DowncastWriter}
* * {@module:engine/view/upcastwriter~UpcastWriter}
*/
export default class Range {
/**
Expand All @@ -20,7 +26,7 @@ export default class Range {
* **Note:** Constructor creates it's own {@link module:engine/view/position~Position} instances basing on passed values.
*
* @param {module:engine/view/position~Position} start Start position.
* @param {module:engine/view/position~Position} [end] End position. If not set, range will be collapsed at `start` position.
* @param {module:engine/view/position~Position} [end] End position. If not set, range will be collapsed at the `start` position.
*/
constructor( start, end = null ) {
/**
Expand Down Expand Up @@ -91,13 +97,14 @@ export default class Range {
*
* For example:
*
* <p>Foo</p><p><b>{Bar}</b></p> -> <p>Foo</p>[<p><b>Bar</b>]</p>
* <p><b>foo</b>{bar}<span></span></p> -> <p><b>foo[</b>bar<span></span>]</p>
* <p>Foo</p><p><b>{Bar}</b></p> -> <p>Foo</p>[<p><b>Bar</b>]</p>
* <p><b>foo</b>{bar}<span></span></p> -> <p><b>foo[</b>bar<span></span>]</p>
*
* Note that in the sample above:
* - `<p>` have type of {@link module:engine/view/containerelement~ContainerElement},
* - `<b>` have type of {@link module:engine/view/attributeelement~AttributeElement},
* - `<span>` have type of {@link module:engine/view/uielement~UIElement}.
*
* - `<p>` have type of {@link module:engine/view/containerelement~ContainerElement},
* - `<b>` have type of {@link module:engine/view/attributeelement~AttributeElement},
* - `<span>` have type of {@link module:engine/view/uielement~UIElement}.
*
* @returns {module:engine/view/range~Range} Enlarged range.
*/
Expand All @@ -123,13 +130,14 @@ export default class Range {
*
* For example:
*
* <p>Foo</p>[<p><b>Bar</b>]</p> -> <p>Foo</p><p><b>{Bar}</b></p>
* <p><b>foo[</b>bar<span></span>]</p> -> <p><b>foo</b>{bar}<span></span></p>
* <p>Foo</p>[<p><b>Bar</b>]</p> -> <p>Foo</p><p><b>{Bar}</b></p>
* <p><b>foo[</b>bar<span></span>]</p> -> <p><b>foo</b>{bar}<span></span></p>
*
* Note that in the sample above:
* - `<p>` have type of {@link module:engine/view/containerelement~ContainerElement},
* - `<b>` have type of {@link module:engine/view/attributeelement~AttributeElement},
* - `<span>` have type of {@link module:engine/view/uielement~UIElement}.
*
* - `<p>` have type of {@link module:engine/view/containerelement~ContainerElement},
* - `<b>` have type of {@link module:engine/view/attributeelement~AttributeElement},
* - `<span>` have type of {@link module:engine/view/uielement~UIElement}.
*
* @returns {module:engine/view/range~Range} Shrink range.
*/
Expand Down Expand Up @@ -309,6 +317,7 @@ export default class Range {
* @param {Boolean} [options.singleCharacters=false]
* @param {Boolean} [options.shallow=false]
* @param {Boolean} [options.ignoreElementEnd=false]
* @returns {module:engine/view/treewalker~TreeWalker}
*/
getWalker( options = {} ) {
options.boundaries = this;
Expand All @@ -326,6 +335,11 @@ export default class Range {
return this.start.getCommonAncestor( this.end );
}

/**
* Clones this range.
*
* @returns {module:engine/view/range~Range}
*/
clone() {
return new Range( this.start, this.end );
}
Expand Down Expand Up @@ -381,7 +395,7 @@ export default class Range {
}

/**
* Checks and returns whether this range intersects with given range.
* Checks and returns whether this range intersects with the given range.
*
* @param {module:engine/view/range~Range} otherRange Range to compare with.
* @returns {Boolean} True if ranges intersect.
Expand All @@ -391,7 +405,7 @@ export default class Range {
}

/**
* Creates a range from given parents and offsets.
* Creates a range from the given parents and offsets.
*
* @protected
* @param {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment} startElement Start position
Expand Down
17 changes: 14 additions & 3 deletions src/view/uielement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@ import Node from './node';
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';

/**
* UIElement class. It is used to represent UI not a content of the document.
* This element can't be split and selection can't be placed inside this element.
* UI element class. It should be used to represent editing UI which needs to be injected into the editing view
* If possible, you should keep your UI outside the editing view. However, if that is not possible,
* UI elements can be used.
*
* The constructor of this class shouldn't be used directly. To create new `UIElement` use the
* How a UI element is rendered is in your control (you pass a callback to
* {@link module:engine/view/downcastwriter~DowncastWriter#createUIElement `downcastWriter#createUIElement()`}).
* The editor will ignore your UI element – the selection cannot be placed in it, it is skipped (invisible) when
* the user modifies the selection by using arrow keys and the editor does not listen to any mutations which
* happen inside your UI elements.
*
* The limitation is that you cannot convert a model element to a UI element. UI elements need to be
* created for {@link module:engine/model/markercollection~Marker markers} or as additinal elements
* inside normal {@link module:engine/view/containerelement~ContainerElement container elements}.
*
* To create a new UI element use the
* {@link module:engine/view/downcastwriter~DowncastWriter#createUIElement `downcastWriter#createUIElement()`} method.
*/
export default class UIElement extends Element {
Expand Down
Loading

0 comments on commit f0d6d5d

Please sign in to comment.