|
|
@@ -9,17 +9,14 @@ import ViewText from './text.js';
|
|
|
import ViewElement from './element.js';
|
|
|
|
|
|
/**
|
|
|
- * Converter is a set of tools to do transformations between DOM nodes and view nodes. It also handle
|
|
|
+ * Converter is a set of tools to do transformations between DOM nodes and view nodes. It also handles
|
|
|
* {@link #bindElements binding} these nodes.
|
|
|
*
|
|
|
* Converter does not check which nodes should be rendered (use {@link treeView.Renderer}), does not keep a state of
|
|
|
- * a tree nor keep synchronization between tree view and DOM tree (use {@treeView.TreeView}).
|
|
|
+ * a tree nor keeps synchronization between tree view and DOM tree (use {@treeView.TreeView}).
|
|
|
*
|
|
|
- * Converter keep DOM elements - View element binding, so when the converter will be destroyed, the binding will be
|
|
|
- * lost. Two converters will use separate bindings, so one tree view can be binded with two DOM trees.
|
|
|
- *
|
|
|
- * In the future converter may take a configuration in the constructor (e.g. what should be inserted into an empty
|
|
|
- * elements).
|
|
|
+ * Converter keeps DOM elements to View element bindings, so when the converter will be destroyed, the binding will be
|
|
|
+ * lost. Two converters will keep separate binding maps, so one tree view can be bound with two DOM trees.
|
|
|
*
|
|
|
* @class treeView.Converter
|
|
|
*/
|
|
|
@@ -33,6 +30,8 @@ export default class Converter {
|
|
|
// Using WeakMap prevent memory leaks: when the converter will be destroyed all referenced between View and DOM
|
|
|
// will be removed. Also because it is a *Weak*Map when both view and DOM elements will be removed referenced
|
|
|
// will be also removed, isn't it brilliant?
|
|
|
+ //
|
|
|
+ // Yes, PJ. It is.
|
|
|
|
|
|
/**
|
|
|
* DOM to View mapping.
|
|
|
@@ -52,7 +51,7 @@ export default class Converter {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Bind DOM and View elements, so it will be possible to get corresponding elements using
|
|
|
+ * Binds DOM and View elements, so it will be possible to get corresponding elements using
|
|
|
* {@link treeView.Converter#getCorrespondingViewElement} and {@link treeView.Converter#getCorespondingDOMElement}.
|
|
|
*
|
|
|
* @param {HTMLElement} domElement DOM element to bind.
|
|
|
@@ -64,7 +63,7 @@ export default class Converter {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Compare DOM and View nodes. Elements are same when they are binded. Text nodes are same when they have the same
|
|
|
+ * Compares DOM and View nodes. Elements are same when they are bound. Text nodes are same when they have the same
|
|
|
* text data. Nodes need to have corresponding types. In all other cases nodes are different.
|
|
|
*
|
|
|
* @param {Node} domNode DOM node to compare.
|
|
|
@@ -86,13 +85,13 @@ export default class Converter {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Convert view to DOM. For all text nodes and not binded elements new elements will be created. For binded
|
|
|
+ * Converts view to DOM. For all text nodes and not bound elements new elements will be created. For bound
|
|
|
* elements function will return corresponding elements.
|
|
|
*
|
|
|
* @param {treeView.Node} viewNode View node to transform.
|
|
|
* @param {document} domDocument Document which will be used to create DOM nodes.
|
|
|
* @param {Object} [options] Conversion options.
|
|
|
- * @param {Boolean} [options.bind=false] Determines whether new elements will be binded.
|
|
|
+ * @param {Boolean} [options.bind=false] Determines whether new elements will be bound.
|
|
|
* @param {Boolean} [options.withChildren=true] If true node's children will be converter too.
|
|
|
* @returns {Node} Converted node.
|
|
|
*/
|
|
|
@@ -129,12 +128,12 @@ export default class Converter {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Convert DOM to view. For all text nodes and not binded elements new elements will be created. For binded
|
|
|
+ * Converts DOM to view. For all text nodes and not bound elements new elements will be created. For bound
|
|
|
* elements function will return corresponding elements.
|
|
|
*
|
|
|
* @param {Node} domNode DOM node to transform.
|
|
|
* @param {Object} [options] Conversion options.
|
|
|
- * @param {Boolean} [options.bind=false] Determines whether new elements will be binded.
|
|
|
+ * @param {Boolean} [options.bind=false] Determines whether new elements will be bound.
|
|
|
* @param {Boolean} [options.withChildren=true] It true node's children will be converter too.
|
|
|
* @returns {treeView.Node} Converted node.
|
|
|
*/
|
|
|
@@ -179,7 +178,7 @@ export default class Converter {
|
|
|
* {@link getCorrespondingViewText} for text nodes.
|
|
|
*
|
|
|
* @param {Node} domNode DOM node.
|
|
|
- * @returns {treeView.Node|Null} Corresponding node.
|
|
|
+ * @returns {treeView.Node|null} Corresponding node.
|
|
|
*/
|
|
|
getCorrespondingView( domNode ) {
|
|
|
if ( domNode instanceof HTMLElement ) {
|
|
|
@@ -190,30 +189,30 @@ export default class Converter {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Gets corresponding view element. Returns element if an view element was {@link #bindElements binded} to the given
|
|
|
+ * Gets corresponding view element. Returns element if an view element was {@link #bindElements bound} to the given
|
|
|
* DOM element or null otherwise.
|
|
|
*
|
|
|
* @param {HTMLElement} domElement DOM element.
|
|
|
- * @returns {treeView.Element|Null} Corresponding element or null if none element was binded.
|
|
|
+ * @returns {treeView.Element|null} Corresponding element or null if none element was bound.
|
|
|
*/
|
|
|
getCorrespondingViewElement( domElement ) {
|
|
|
return this._domToViewMapping.get( domElement );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Gets corresponding text node. Text nodes are not {@link #bindElements binded}, corresponding text node is
|
|
|
+ * Gets corresponding text node. Text nodes are not {@link #bindElements bound}, corresponding text node is
|
|
|
* returned based on the sibling or parent.
|
|
|
*
|
|
|
- * If the directly previous sibling is a {@link #bindElements binded} element, it is used to find the corresponding
|
|
|
+ * If the directly previous sibling is a {@link #bindElements bound} element, it is used to find the corresponding
|
|
|
* text node.
|
|
|
*
|
|
|
- * If this is a first child in the parent and the parent is a {@link #bindElements binded} element, it is used to
|
|
|
+ * If this is a first child in the parent and the parent is a {@link #bindElements bound} element, it is used to
|
|
|
* find the corresponding text node.
|
|
|
*
|
|
|
- * Otherwise null is returned.
|
|
|
+ * Otherwise `null` is returned.
|
|
|
*
|
|
|
* @param {Text} domText DOM text node.
|
|
|
- * @returns {treeView.Text|Null} Corresponding view text node or null, if it was not possible to find a
|
|
|
+ * @returns {treeView.Text|null} Corresponding view text node or null, if it was not possible to find a
|
|
|
* corresponding node.
|
|
|
*/
|
|
|
getCorrespondingViewText( domText ) {
|
|
|
@@ -249,7 +248,7 @@ export default class Converter {
|
|
|
* {@link #getCorrespondingDomText} for text nodes.
|
|
|
*
|
|
|
* @param {treeView.Node} viewNode View node.
|
|
|
- * @returns {Node|Null} Corresponding DOM node.
|
|
|
+ * @returns {Node|null} Corresponding DOM node.
|
|
|
*/
|
|
|
getCorrespondingDom( viewNode ) {
|
|
|
if ( viewNode instanceof ViewElement ) {
|
|
|
@@ -260,30 +259,30 @@ export default class Converter {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Gets corresponding DOM element. Returns element if an DOM element was {@link #bindElements binded} to the given
|
|
|
+ * Gets corresponding DOM element. Returns element if an DOM element was {@link #bindElements bound} to the given
|
|
|
* view element or null otherwise.
|
|
|
*
|
|
|
* @param {treeView.Element} viewElement View element.
|
|
|
- * @returns {HTMLElement|Null} Corresponding element or null if none element was binded.
|
|
|
+ * @returns {HTMLElement|null} Corresponding element or null if none element was bound.
|
|
|
*/
|
|
|
getCorrespondingDomElement( viewElement ) {
|
|
|
return this._viewToDomMapping.get( viewElement );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Gets corresponding text node. Text nodes are not {@link #bindElements binded}, corresponding text node is
|
|
|
+ * Gets corresponding text node. Text nodes are not {@link #bindElements bound}, corresponding text node is
|
|
|
* returned based on the sibling or parent.
|
|
|
*
|
|
|
- * If the directly previous sibling is a {@link #bindElements binded} element, it is used to find the corresponding
|
|
|
+ * If the directly previous sibling is a {@link #bindElements bound} element, it is used to find the corresponding
|
|
|
* text node.
|
|
|
*
|
|
|
- * If this is a first child in the parent and the parent is a {@link #bindElements binded} element, it is used to
|
|
|
+ * If this is a first child in the parent and the parent is a {@link #bindElements bound} element, it is used to
|
|
|
* find the corresponding text node.
|
|
|
*
|
|
|
* Otherwise null is returned.
|
|
|
*
|
|
|
* @param {treeView.Text} viewText View text node.
|
|
|
- * @returns {Text|Null} Corresponding DOM text node or null, if it was not possible to find a corresponding node.
|
|
|
+ * @returns {Text|null} Corresponding DOM text node or null, if it was not possible to find a corresponding node.
|
|
|
*/
|
|
|
getCorrespondingDomText( viewText ) {
|
|
|
const previousSibling = viewText.getPreviousSibling();
|
|
|
@@ -300,4 +299,4 @@ export default class Converter {
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
-}
|
|
|
+}
|