ckeditor5-1.0.x-dev/js/drupal/src/drupalMedia/src/ui/utils.js

js/drupal/src/drupalMedia/src/ui/utils.js
import { getSelectedDrupalMediaWidget } from "../utils";
import { BalloonPanelView } from 'ckeditor5/src/ui';

/**
 * A helper utility that positions the contextual balloon instance with respect
 * to the image in the editor content, if one is selected.
 *
 * @param editor {Editor} The editor instance.
 */
export function repositionContextualBalloon(editor) {
  const balloon = editor.plugins.get('ContextualBalloon');

  if (getSelectedDrupalMediaWidget(editor.editing.view.document.selection)) {
    const position = getBalloonPositionData(editor);

    balloon.updatePosition(position);
  }
}

/**
 * Returns the positioning options that control the geometry of the contextual
 * balloon with respect to the selected element in the editor content.
 *
 * @param editor {Editor} The editor instance.
 * @returns {Options}
 */
export function getBalloonPositionData(editor) {
  const editingView = editor.editing.view;
  const defaultPositions = BalloonPanelView.defaultPositions;

  return {
    target: editingView.domConverter.viewToDom(
      editingView.document.selection.getSelectedElement(),
    ),
    positions: [
      defaultPositions.northArrowSouth,
      defaultPositions.northArrowSouthWest,
      defaultPositions.northArrowSouthEast,
      defaultPositions.southArrowNorth,
      defaultPositions.southArrowNorthWest,
      defaultPositions.southArrowNorthEast,
    ],
  };
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc