8
0
Pārlūkot izejas kodu

Move widget utility functions to utils/ui/widget.js.

Maciej Gołaszewski 5 gadi atpakaļ
vecāks
revīzija
0dea407ee9

+ 1 - 1
packages/ckeditor5-table/src/tablecellproperties/tablecellpropertiesui.js

@@ -9,7 +9,6 @@
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
-import { getTableWidgetAncestor } from '../utils/common';
 import clickOutsideHandler from '@ckeditor/ckeditor5-ui/src/bindings/clickoutsidehandler';
 import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
 import TableCellPropertiesView from './ui/tablecellpropertiesview';
@@ -29,6 +28,7 @@ import {
 	normalizeColorOptions
 } from '@ckeditor/ckeditor5-ui/src/colorgrid/utils';
 import { debounce } from 'lodash-es';
+import { getTableWidgetAncestor } from '../utils/ui/widget';
 
 const ERROR_TEXT_TIMEOUT = 500;
 

+ 1 - 1
packages/ckeditor5-table/src/tableproperties/tablepropertiesui.js

@@ -9,7 +9,6 @@
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
-import { getTableWidgetAncestor } from '../utils/common';
 import clickOutsideHandler from '@ckeditor/ckeditor5-ui/src/bindings/clickoutsidehandler';
 import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
 import TablePropertiesView from './ui/tablepropertiesview';
@@ -29,6 +28,7 @@ import {
 	normalizeColorOptions
 } from '@ckeditor/ckeditor5-ui/src/colorgrid/utils';
 import { debounce } from 'lodash-es';
+import { getTableWidgetAncestor } from '../utils/ui/widget';
 
 const ERROR_TEXT_TIMEOUT = 500;
 

+ 1 - 1
packages/ckeditor5-table/src/tabletoolbar.js

@@ -8,8 +8,8 @@
  */
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import { getSelectedTableWidget, getTableWidgetAncestor } from './utils/common';
 import WidgetToolbarRepository from '@ckeditor/ckeditor5-widget/src/widgettoolbarrepository';
+import { getSelectedTableWidget, getTableWidgetAncestor } from './utils/ui/widget';
 
 /**
  * The table toolbar class. It creates toolbars for the table feature and its content (for now only for the table cell content).

+ 1 - 1
packages/ckeditor5-table/src/ui/utils.js

@@ -13,10 +13,10 @@ import Collection from '@ckeditor/ckeditor5-utils/src/collection';
 import Model from '@ckeditor/ckeditor5-ui/src/model';
 import ColorInputView from './colorinputview';
 import { isColor, isLength, isPercentage } from '@ckeditor/ckeditor5-engine/src/view/styles/utils';
-import { getTableWidgetAncestor } from '../utils/common';
 import { findAncestor } from '../commands/utils';
 import Rect from '@ckeditor/ckeditor5-utils/src/dom/rect';
 import { centeredBalloonPositionForLongWidgets } from '@ckeditor/ckeditor5-widget/src/utils';
+import { getTableWidgetAncestor } from '../utils/ui/widget';
 
 const DEFAULT_BALLOON_POSITIONS = BalloonPanelView.defaultPositions;
 const BALLOON_POSITIONS = [

+ 1 - 42
packages/ckeditor5-table/src/utils/common.js

@@ -7,50 +7,9 @@
  * @module table/utils/common
  */
 
-import { isWidget } from '@ckeditor/ckeditor5-widget/src/utils';
-import { createEmptyTableCell, findAncestor, updateNumericAttribute } from '../commands/utils';
+import { createEmptyTableCell, updateNumericAttribute } from '../commands/utils';
 import TableWalker from '../tablewalker';
 
-// Checks if a given view element is a table widget.
-//
-// @param {module:engine/view/element~Element} viewElement
-// @returns {Boolean}
-function isTableWidget( viewElement ) {
-	return !!viewElement.getCustomProperty( 'table' ) && isWidget( viewElement );
-}
-
-/**
- * Returns a table widget editing view element if one is selected.
- *
- * @param {module:engine/view/selection~Selection|module:engine/view/documentselection~DocumentSelection} selection
- * @returns {module:engine/view/element~Element|null}
- */
-export function getSelectedTableWidget( selection ) {
-	const viewElement = selection.getSelectedElement();
-
-	if ( viewElement && isTableWidget( viewElement ) ) {
-		return viewElement;
-	}
-
-	return null;
-}
-
-/**
- * Returns a table widget editing view element if one is among the selection's ancestors.
- *
- * @param {module:engine/view/selection~Selection|module:engine/view/documentselection~DocumentSelection} selection
- * @returns {module:engine/view/element~Element|null}
- */
-export function getTableWidgetAncestor( selection ) {
-	const parentTable = findAncestor( 'table', selection.getFirstPosition() );
-
-	if ( parentTable && isTableWidget( parentTable.parent ) ) {
-		return parentTable.parent;
-	}
-
-	return null;
-}
-
 /**
  * Returns slot info of cells that starts above and overlaps a given row.
  *

+ 51 - 0
packages/ckeditor5-table/src/utils/ui/widget.js

@@ -0,0 +1,51 @@
+/**
+ * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+/**
+ * @module table/utils/ui/widget
+ */
+
+import { findAncestor } from '../../commands/utils';
+import { isWidget } from '@ckeditor/ckeditor5-widget/src/utils';
+
+/**
+ * Returns a table widget editing view element if one is selected.
+ *
+ * @param {module:engine/view/selection~Selection|module:engine/view/documentselection~DocumentSelection} selection
+ * @returns {module:engine/view/element~Element|null}
+ */
+export function getSelectedTableWidget( selection ) {
+	const viewElement = selection.getSelectedElement();
+
+	if ( viewElement && isTableWidget( viewElement ) ) {
+		return viewElement;
+	}
+
+	return null;
+}
+
+/**
+ * Returns a table widget editing view element if one is among the selection's ancestors.
+ *
+ * @param {module:engine/view/selection~Selection|module:engine/view/documentselection~DocumentSelection} selection
+ * @returns {module:engine/view/element~Element|null}
+ */
+export function getTableWidgetAncestor( selection ) {
+	const parentTable = findAncestor( 'table', selection.getFirstPosition() );
+
+	if ( parentTable && isTableWidget( parentTable.parent ) ) {
+		return parentTable.parent;
+	}
+
+	return null;
+}
+
+// Checks if a given view element is a table widget.
+//
+// @param {module:engine/view/element~Element} viewElement
+// @returns {Boolean}
+function isTableWidget( viewElement ) {
+	return !!viewElement.getCustomProperty( 'table' ) && isWidget( viewElement );
+}