8
0

rootelement.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module engine/model/rootelement
  7. */
  8. import Element from './element';
  9. /**
  10. * Type of {@link module:engine/model/element~Element} that is a root of a model tree.
  11. * @extends module:engine/model/element~Element
  12. */
  13. export default class RootElement extends Element {
  14. /**
  15. * Creates root element.
  16. *
  17. * @param {module:engine/model/document~Document} doc Document that is an owner of this root.
  18. * @param {String} name Node name.
  19. * @param {String} [rootName='main'] Unique root name used to identify this root element by {@link module:engine/model/document~Document}.
  20. */
  21. constructor( doc, name, rootName = 'main' ) {
  22. super( name );
  23. /**
  24. * Document that is an owner of this root.
  25. *
  26. * @private
  27. * @member {module:engine/model/document~Document}
  28. */
  29. this._doc = doc;
  30. /**
  31. * Unique root name used to identify this root element by {@link module:engine/model/document~Document}.
  32. *
  33. * @readonly
  34. * @member {String}
  35. */
  36. this.rootName = rootName;
  37. }
  38. /**
  39. * {@link module:engine/model/document~Document Document} that owns this root element.
  40. *
  41. * In contrary, to {@link module:engine/model/node~Node node}, root element always have a `document`.
  42. *
  43. * @readonly
  44. * @type {module:engine/model/document~Document|null}
  45. */
  46. get document() {
  47. return this._doc;
  48. }
  49. /**
  50. * Converts `RootElement` instance to `String` containing it's name.
  51. *
  52. * @returns {String} `RootElement` instance converted to `String`.
  53. */
  54. toJSON() {
  55. return this.rootName;
  56. }
  57. }