utils.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module list/utils
  7. */
  8. import { getFillerOffset } from '@ckeditor/ckeditor5-engine/src/view/containerelement';
  9. /**
  10. * Creates list item {@link module:engine/view/containerelement~ContainerElement}.
  11. *
  12. * @param {module:engine/view/downcastwriter~DowncastWriter} writer The writer instance.
  13. * @returns {module:engine/view/containerelement~ContainerElement}
  14. */
  15. export function createViewListItemElement( writer ) {
  16. const viewItem = writer.createContainerElement( 'li' );
  17. viewItem.getFillerOffset = getListItemFillerOffset;
  18. return viewItem;
  19. }
  20. // Implementation of getFillerOffset for view list item element.
  21. //
  22. // @returns {Number|null} Block filler offset or `null` if block filler is not needed.
  23. function getListItemFillerOffset() {
  24. const hasOnlyLists = !this.isEmpty && ( this.getChild( 0 ).name == 'ul' || this.getChild( 0 ).name == 'ol' );
  25. if ( this.isEmpty || hasOnlyLists ) {
  26. return 0;
  27. }
  28. return getFillerOffset.call( this );
  29. }