8
0

utils.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module table/ui/utils
  7. */
  8. import BalloonPanelView from '@ckeditor/ckeditor5-ui/src/panel/balloon/balloonpanelview';
  9. import { getParentTable } from '../commands/utils';
  10. /**
  11. * A helper utility that positions the
  12. * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} instance
  13. * with respect to the table in the editor content, if one is selected.
  14. *
  15. * @param {module:core/editor/editor~Editor} editor The editor instance.
  16. */
  17. export function repositionContextualBalloon( editor ) {
  18. const balloon = editor.plugins.get( 'ContextualBalloon' );
  19. balloon.updatePosition( getBalloonPositionData( editor ) );
  20. }
  21. /**
  22. * Returns the positioning options that control the geometry of the
  23. * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
  24. * to the selected element in the editor content.
  25. *
  26. * @param {module:core/editor/editor~Editor} editor The editor instance.
  27. * @returns {module:utils/dom/position~Options}
  28. */
  29. export function getBalloonPositionData( editor ) {
  30. const editingView = editor.editing.view;
  31. const defaultPositions = BalloonPanelView.defaultPositions;
  32. const viewSelection = editingView.document.selection;
  33. const parentTable = getParentTable( viewSelection.getFirstPosition() );
  34. return {
  35. target: editingView.domConverter.viewToDom( parentTable ),
  36. positions: [
  37. defaultPositions.northArrowSouth,
  38. defaultPositions.northArrowSouthWest,
  39. defaultPositions.northArrowSouthEast,
  40. defaultPositions.southArrowNorth,
  41. defaultPositions.southArrowNorthWest,
  42. defaultPositions.southArrowNorthEast
  43. ]
  44. };
  45. }