widgetresize.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals document, Event */
  6. import WidgetResize from '../src/widgetresize';
  7. // ClassicTestEditor can't be used, as it doesn't handle the focus, which is needed to test resizer visual cues.
  8. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  9. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  10. import { toWidget } from '../src/utils';
  11. import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  12. import { resizerMouseSimulator, focusEditor, getHandleCenterPoint, getWidgetDomParts } from './widgetresize/_utils/utils';
  13. describe( 'WidgetResize', () => {
  14. let editor, editorElement, widget, mouseListenerSpies, commitStub;
  15. const INITIAL_WIDGET_WIDTH = '25%';
  16. beforeEach( async () => {
  17. editorElement = createEditorElement();
  18. editor = await createEditor( editorElement );
  19. setModelData( editor.model, '[<widget></widget>]' );
  20. focusEditor( editor );
  21. widget = editor.editing.view.document.getRoot().getChild( 0 );
  22. // It's crucial to have a precisely defined editor size for this test suite.
  23. editor.editing.view.change( writer => {
  24. const viewEditableRoot = editor.editing.view.document.getRoot();
  25. writer.setAttribute( 'style', 'width: 400px; padding: 0px; overflow: hidden', viewEditableRoot );
  26. } );
  27. commitStub = sinon.stub();
  28. mouseListenerSpies = {
  29. down: sinon.spy( WidgetResize.prototype, '_mouseDownListener' ),
  30. move: sinon.spy( WidgetResize.prototype, '_mouseMoveListener' ),
  31. up: sinon.spy( WidgetResize.prototype, '_mouseUpListener' )
  32. };
  33. } );
  34. afterEach( () => {
  35. editorElement.remove();
  36. for ( const stub of Object.values( mouseListenerSpies ) ) {
  37. stub.restore();
  38. }
  39. if ( editor ) {
  40. return editor.destroy();
  41. }
  42. } );
  43. describe( 'plugin', () => {
  44. it( 'is loaded', () => {
  45. expect( editor.plugins.get( WidgetResize ) ).to.be.instanceOf( WidgetResize );
  46. } );
  47. } );
  48. describe( 'mouse listeners', () => {
  49. beforeEach( () => {
  50. createResizer();
  51. } );
  52. it( 'don\'t break when called with unexpected element', () => {
  53. const unrelatedElement = document.createElement( 'div' );
  54. editor.plugins.get( WidgetResize )._mouseDownListener( {}, {
  55. target: unrelatedElement
  56. } );
  57. } );
  58. it( 'passes new width to the options.onCommit()', () => {
  59. const usedResizer = 'top-right';
  60. const domParts = getWidgetDomParts( editor, widget, usedResizer );
  61. const initialPointerPosition = getHandleCenterPoint( domParts.widget, usedResizer );
  62. const finalPointerPosition = initialPointerPosition.clone().moveBy( 20, 0 );
  63. resizerMouseSimulator.dragTo( editor, domParts.resizeHandle, finalPointerPosition );
  64. expect( commitStub.callCount ).to.equal( 1 );
  65. sinon.assert.calledWithExactly( commitStub, '120px' );
  66. } );
  67. it( 'are detached when plugin is destroyed', async () => {
  68. await editor.destroy();
  69. const plugin = editor.plugins.get( WidgetResize );
  70. editor = null;
  71. const event = new Event( 'mousedown', { bubbles: true } );
  72. document.body.dispatchEvent( event );
  73. // Ensure nothing got called.
  74. expect( plugin._mouseDownListener.callCount ).to.equal( 0 );
  75. } );
  76. it( 'nothing bad happens if activeResizer got unset', () => {
  77. createResizer( {
  78. isCentered: () => true
  79. } );
  80. const usedResizer = 'top-right';
  81. const domParts = getWidgetDomParts( editor, widget, usedResizer );
  82. const initialPointerPosition = getHandleCenterPoint( domParts.widget, usedResizer );
  83. editor.plugins.get( WidgetResize )._getResizerByHandle = sinon.stub().returns( null );
  84. resizerMouseSimulator.dragTo( editor, domParts.resizeHandle, initialPointerPosition );
  85. // No exception should be thrown.
  86. } );
  87. } );
  88. describe( 'visibility', () => {
  89. beforeEach( () => {
  90. createResizer();
  91. } );
  92. it( 'it\'s hidden when no widget is focused', () => {
  93. // This particular test needs a paragraph, so that widget is no longer focused.
  94. setModelData( editor.model, '<widget></widget><paragraph>[]</paragraph>' );
  95. const allResizers = editor.ui.getEditableElement().querySelectorAll( '.ck-widget__resizer__handle' );
  96. for ( const resizer of allResizers ) {
  97. expect( isVisible( resizer ) ).to.be.false;
  98. }
  99. } );
  100. it( 'it\'s visible once the widget is focused', () => {
  101. // Widget is focused by default.
  102. const allResizers = editor.ui.getEditableElement().querySelectorAll( '.ck-widget__resizer__handle' );
  103. for ( const resizer of allResizers ) {
  104. expect( isVisible( resizer ) ).to.be.true;
  105. }
  106. } );
  107. function isVisible( element ) {
  108. // Checks if the DOM element is visible to the end user.
  109. return element.offsetParent !== null && !element.classList.contains( 'ck-hidden' );
  110. }
  111. } );
  112. describe( 'integration (pixels)', () => {
  113. describe( 'aligned widget', () => {
  114. beforeEach( () => {
  115. createResizer();
  116. } );
  117. it( 'properly sets the state for subsequent resizes', () => {
  118. const usedResizer = 'top-right';
  119. const domParts = getWidgetDomParts( editor, widget, usedResizer );
  120. const initialPointerPosition = getHandleCenterPoint( domParts.widget, usedResizer );
  121. const intermediatePointerPosition = initialPointerPosition.clone().moveBy( 50, 0 );
  122. resizerMouseSimulator.dragTo( editor, domParts.resizeHandle, intermediatePointerPosition );
  123. sinon.assert.calledWithExactly( commitStub.firstCall, '150px' );
  124. const finalPointerPosition = intermediatePointerPosition.clone().moveBy( 50, 0 );
  125. resizerMouseSimulator.dragTo( editor, domParts.resizeHandle, finalPointerPosition );
  126. sinon.assert.calledWithExactly( commitStub.secondCall, '200px' );
  127. expect( commitStub.callCount ).to.equal( 2 );
  128. } );
  129. it( 'shrinks correctly with left-bottom handler', generateResizeTest( {
  130. usedHandle: 'bottom-left',
  131. movePointerBy: { x: 20, y: -10 },
  132. expectedWidth: '80px'
  133. } ) );
  134. it( 'shrinks correctly with right-bottom handler', generateResizeTest( {
  135. usedHandle: 'bottom-right',
  136. movePointerBy: { x: -20, y: -10 },
  137. expectedWidth: '80px'
  138. } ) );
  139. it( 'shrinks correctly with left-top handler', generateResizeTest( {
  140. usedHandle: 'top-left',
  141. movePointerBy: { x: 20, y: 10 },
  142. expectedWidth: '80px'
  143. } ) );
  144. it( 'shrinks correctly with right-top handler', generateResizeTest( {
  145. usedHandle: 'top-right',
  146. movePointerBy: { x: -20, y: 10 },
  147. expectedWidth: '80px'
  148. } ) );
  149. it( 'enlarges correctly with left-bottom handler', generateResizeTest( {
  150. usedHandle: 'bottom-left',
  151. movePointerBy: { x: -10, y: 10 },
  152. expectedWidth: '120px'
  153. } ) );
  154. it( 'enlarges correctly with right-bottom handler', generateResizeTest( {
  155. usedHandle: 'bottom-right',
  156. movePointerBy: { x: 10, y: 10 },
  157. expectedWidth: '120px'
  158. } ) );
  159. it( 'enlarges correctly with right-bottom handler, y axis only', generateResizeTest( {
  160. usedHandle: 'bottom-right',
  161. movePointerBy: { x: 0, y: 20 },
  162. expectedWidth: '140px'
  163. } ) );
  164. it( 'enlarges correctly with right-bottom handler, x axis only', generateResizeTest( {
  165. usedHandle: 'bottom-right',
  166. movePointerBy: { x: 40, y: 0 },
  167. expectedWidth: '140px'
  168. } ) );
  169. it( 'enlarges correctly with left-top handler', generateResizeTest( {
  170. usedHandle: 'top-left',
  171. movePointerBy: { x: -20, y: -10 },
  172. expectedWidth: '120px'
  173. } ) );
  174. it( 'enlarges correctly with right-top handler', generateResizeTest( {
  175. usedHandle: 'top-right',
  176. movePointerBy: { x: 20, y: 10 },
  177. expectedWidth: '120px'
  178. } ) );
  179. } );
  180. describe( 'centered widget', () => {
  181. beforeEach( () => {
  182. createResizer( {
  183. isCentered: () => true
  184. } );
  185. } );
  186. it( 'shrinks correctly with left-bottom handler', generateResizeTest( {
  187. usedHandle: 'bottom-left',
  188. movePointerBy: { x: 10, y: -10 },
  189. expectedWidth: '80px'
  190. } ) );
  191. it( 'shrinks correctly with right-bottom handler', generateResizeTest( {
  192. usedHandle: 'bottom-right',
  193. movePointerBy: { x: -10, y: -10 },
  194. expectedWidth: '80px'
  195. } ) );
  196. it( 'enlarges correctly with right-bottom handler, x axis only', generateResizeTest( {
  197. usedHandle: 'bottom-right',
  198. movePointerBy: { x: 10, y: 0 },
  199. expectedWidth: '120px'
  200. } ) );
  201. it( 'enlarges correctly with right-bottom handler, y axis only', generateResizeTest( {
  202. usedHandle: 'bottom-right',
  203. movePointerBy: { x: 0, y: 10 },
  204. expectedWidth: '120px'
  205. } ) );
  206. it( 'enlarges correctly with left-bottom handler, x axis only', generateResizeTest( {
  207. usedHandle: 'bottom-left',
  208. movePointerBy: { x: -10, y: 0 },
  209. expectedWidth: '120px'
  210. } ) );
  211. it( 'enlarges correctly with left-bottom handler, y axis only', generateResizeTest( {
  212. usedHandle: 'bottom-left',
  213. movePointerBy: { x: 0, y: 10 },
  214. expectedWidth: '120px'
  215. } ) );
  216. // --- top handlers ---
  217. it( 'enlarges correctly with left-top handler', generateResizeTest( {
  218. usedHandle: 'top-left',
  219. movePointerBy: { x: -10, y: -10 },
  220. expectedWidth: '120px'
  221. } ) );
  222. it( 'enlarges correctly with left-top handler, y axis only', generateResizeTest( {
  223. usedHandle: 'top-left',
  224. movePointerBy: { x: 0, y: -10 },
  225. expectedWidth: '120px'
  226. } ) );
  227. it( 'enlarges correctly with right-top handler', generateResizeTest( {
  228. usedHandle: 'top-right',
  229. movePointerBy: { x: 10, y: -10 },
  230. expectedWidth: '120px'
  231. } ) );
  232. it( 'enlarges correctly with right-top handler, y axis only', generateResizeTest( {
  233. usedHandle: 'top-right',
  234. movePointerBy: { x: 0, y: -10 },
  235. expectedWidth: '120px'
  236. } ) );
  237. } );
  238. } );
  239. describe( 'integration (percents)', () => {
  240. describe( 'side aligned widget', () => {
  241. beforeEach( () => {
  242. createResizer( {
  243. unit: undefined
  244. } );
  245. } );
  246. it( 'properly sets the state for subsequent resizes', () => {
  247. const usedResizer = 'top-right';
  248. const domParts = getWidgetDomParts( editor, widget, usedResizer );
  249. const initialPointerPosition = getHandleCenterPoint( domParts.widget, usedResizer );
  250. const intermediatePointerPosition = initialPointerPosition.clone().moveBy( 100, 0 );
  251. resizerMouseSimulator.dragTo( editor, domParts.resizeHandle, intermediatePointerPosition );
  252. sinon.assert.calledWithExactly( commitStub.firstCall, '50%' );
  253. const finalPointerPosition = intermediatePointerPosition.clone().moveBy( 100, 0 );
  254. resizerMouseSimulator.dragTo( editor, domParts.resizeHandle, finalPointerPosition );
  255. sinon.assert.calledWithExactly( commitStub.secondCall, '75%' );
  256. expect( commitStub.callCount ).to.equal( 2 );
  257. } );
  258. it( 'shrinks correctly with bottom-left handler', generateResizeTest( {
  259. usedHandle: 'bottom-left',
  260. movePointerBy: { x: 10, y: -10 },
  261. expectedWidth: '22.5%'
  262. } ) );
  263. } );
  264. describe( 'centered widget', () => {
  265. beforeEach( () => {
  266. createResizer( {
  267. isCentered: () => true,
  268. unit: undefined
  269. } );
  270. } );
  271. it( 'shrinks correctly with bottom-left handler', generateResizeTest( {
  272. usedHandle: 'bottom-left',
  273. movePointerBy: { x: 10, y: -10 },
  274. expectedWidth: '20%'
  275. } ) );
  276. it( 'enlarges correctly with bottom-right handler', generateResizeTest( {
  277. usedHandle: 'bottom-right',
  278. movePointerBy: { x: 0, y: 5 },
  279. expectedWidth: '27.5%'
  280. } ) );
  281. it( 'enlarges correctly an image with unsupported width unit', () => {
  282. editor.editing.view.change( writer => {
  283. writer.setStyle( 'width', '100pt', widget );
  284. } );
  285. generateResizeTest( {
  286. usedHandle: 'bottom-right',
  287. movePointerBy: { x: 0, y: 5 },
  288. expectedWidth: '36.67%'
  289. } )();
  290. } );
  291. } );
  292. it( 'doesn\'t call options.onCommit() in case of no change', () => {
  293. const commitStub = sinon.stub();
  294. createResizer( {
  295. onCommit: commitStub
  296. } );
  297. const domParts = getWidgetDomParts( editor, widget, 'top-left' );
  298. resizerMouseSimulator.down( editor, domParts.resizeHandle );
  299. resizerMouseSimulator.up( editor );
  300. expect( commitStub.callCount, 'call count' ).to.be.eql( 0 );
  301. } );
  302. // Note that ultimately width should be changed, but through a model converter, not with direct view changes (#6060).
  303. it( 'restores the original view width after resize is done', () => {
  304. createResizer();
  305. const usedHandle = 'bottom-right';
  306. const domParts = getWidgetDomParts( editor, widget, usedHandle );
  307. const finalPointerPosition = getHandleCenterPoint( domParts.widget, usedHandle ).moveBy( 40, 40 );
  308. resizerMouseSimulator.dragTo( editor, domParts.resizeHandle, finalPointerPosition );
  309. expect( widget.getStyle( 'width' ) ).to.equal( INITIAL_WIDGET_WIDTH );
  310. } );
  311. // Verify render count https://github.com/ckeditor/ckeditor5-widget/pull/122#issuecomment-617012777.
  312. it( 'renders the final result in one step', () => {
  313. const renderListener = sinon.stub();
  314. const resizer = createResizer();
  315. const usedHandle = 'bottom-right';
  316. const domParts = getWidgetDomParts( editor, widget, usedHandle );
  317. const finalPointerPosition = getHandleCenterPoint( domParts.widget, usedHandle ).moveBy( 40, 40 );
  318. // Start listening on render at the last stage, to exclude rendering caused by moving the mouse.
  319. // Commit is triggered by mouse up and that's what interests us.
  320. resizer.on( 'commit', () => {
  321. editor.editing.view.on( 'render', renderListener );
  322. }, { priority: 'highest' } );
  323. resizerMouseSimulator.dragTo( editor, domParts.resizeHandle, finalPointerPosition );
  324. expect( renderListener.callCount ).to.equal( 1 );
  325. } );
  326. it( 'returns proper value when resize host is different from widget wrapper', () => {
  327. createResizer( {
  328. unit: undefined,
  329. getHandleHost( domWidgetElement ) {
  330. return domWidgetElement.querySelector( '.sub-div' );
  331. }
  332. } );
  333. const usedHandle = 'bottom-right';
  334. const pointerDifference = { x: -10, y: -10 };
  335. const expectedWidth = '20%';
  336. const domParts = getWidgetDomParts( editor, widget, usedHandle );
  337. const resizeHost = domParts.widget.querySelector( '.sub-div' );
  338. const initialPointerPosition = getHandleCenterPoint( resizeHost, usedHandle );
  339. const finalPointerPosition = initialPointerPosition.moveBy( pointerDifference.x, pointerDifference.y );
  340. resizerMouseSimulator.dragTo( editor, domParts.resizeHandle, finalPointerPosition );
  341. expect( commitStub.callCount, 'call count' ).to.be.eql( 1 );
  342. expect( commitStub.args[ 0 ][ 0 ], 'width' ).to.equal( expectedWidth );
  343. sinon.assert.calledOnce( commitStub );
  344. } );
  345. it( 'doesn\'t break if the widget wrapper was removed from DOM', () => {
  346. const resizer = createResizer( {
  347. unit: undefined
  348. } );
  349. const domParts = getWidgetDomParts( editor, widget, 'bottom-right' );
  350. domParts.resizeWrapper.remove();
  351. resizer.redraw();
  352. } );
  353. } );
  354. describe( 'attachTo()', () => {
  355. it( 'works without WidgetToolbarRepository plugin', async () => {
  356. const localEditorElement = createEditorElement();
  357. const localEditor = await ClassicEditor.create( localEditorElement, {
  358. plugins: [
  359. WidgetResize, simpleWidgetPlugin
  360. ]
  361. } );
  362. setModelData( localEditor.model, '[<widget></widget>]' );
  363. const resizerOptions = {
  364. modelElement: localEditor.model.document.getRoot().getChild( 0 ),
  365. viewElement: localEditor.editing.view.document.getRoot().getChild( 0 ),
  366. editor: localEditor,
  367. isCentered: () => false,
  368. getHandleHost( domWidgetElement ) {
  369. return domWidgetElement;
  370. },
  371. getResizeHost( domWidgetElement ) {
  372. return domWidgetElement;
  373. },
  374. onCommit: commitStub
  375. };
  376. localEditor.plugins.get( WidgetResize ).attachTo( resizerOptions );
  377. // Nothing should be thrown.
  378. // And clean up.
  379. localEditorElement.remove();
  380. return localEditor.destroy();
  381. } );
  382. } );
  383. describe( 'init()', () => {
  384. it( 'adds listener to redraw resizer on visible resizer change', async () => {
  385. setModelData( editor.model, '<widget></widget><paragraph>[]</paragraph>' );
  386. widget = editor.editing.view.document.getRoot().getChild( 0 );
  387. const resizer = createResizer();
  388. const redrawSpy = sinon.spy( resizer, 'redraw' );
  389. focusEditor( editor );
  390. editor.model.change( writer => {
  391. const widgetModel = editor.model.document.getRoot().getChild( 0 );
  392. writer.setSelection( widgetModel, 'on' );
  393. } );
  394. expect( redrawSpy.callCount ).to.equal( 1 );
  395. } );
  396. } );
  397. describe( 'cancel()', () => {
  398. it( 'restores original view width', () => {
  399. const resizer = createResizer();
  400. const usedHandle = 'bottom-right';
  401. const domParts = getWidgetDomParts( editor, widget, usedHandle );
  402. const startingPosition = getHandleCenterPoint( domParts.widget, usedHandle ).moveBy( 100, 0 );
  403. const domTarget = domParts.resizeHandle;
  404. resizerMouseSimulator.down( editor, domTarget );
  405. resizerMouseSimulator.move( editor, domTarget, {
  406. pageX: startingPosition.x,
  407. pageY: startingPosition.y
  408. } );
  409. resizer.cancel();
  410. // Value should be restored to the initial value (#6060).
  411. expect( widget.getStyle( 'width' ) ).to.equal( INITIAL_WIDGET_WIDTH );
  412. } );
  413. } );
  414. describe( '_getResizerByHandle()', () => {
  415. it( 'returns properly in case of invalid handle element', () => {
  416. const randomElement = document.createElement( 'span' );
  417. const plugin = editor.plugins.get( WidgetResize );
  418. createResizer();
  419. expect( plugin._getResizerByHandle( randomElement ) ).to.be.undefined;
  420. } );
  421. } );
  422. /**
  423. * @param {Object} options
  424. * @param {String} options.usedHandle Handle that should be used for resize, e.g. 'bottom-right'.
  425. * @param {Object} options.movePointerBy How much should the pointer move during the drag compared to the initial position.
  426. * @param {String} options.expectedWidth
  427. */
  428. function generateResizeTest( options ) {
  429. return () => {
  430. options = options || {};
  431. const usedHandle = options.usedHandle;
  432. const domParts = getWidgetDomParts( editor, widget, usedHandle );
  433. const initialPointerPosition = getHandleCenterPoint( domParts.widget, usedHandle );
  434. const pointerDifference = options.movePointerBy;
  435. const finalPointerPosition = initialPointerPosition.moveBy( pointerDifference.x, pointerDifference.y );
  436. resizerMouseSimulator.dragTo( editor, domParts.resizeHandle, finalPointerPosition );
  437. expect( commitStub.callCount, 'call count' ).to.be.eql( 1 );
  438. expect( commitStub.args[ 0 ][ 0 ], 'width' ).to.equal( options.expectedWidth );
  439. sinon.assert.calledOnce( commitStub );
  440. };
  441. }
  442. function createEditor( element ) {
  443. return ClassicEditor
  444. .create( element, {
  445. plugins: [
  446. ArticlePluginSet, WidgetResize, simpleWidgetPlugin
  447. ]
  448. } );
  449. }
  450. function simpleWidgetPlugin( editor ) {
  451. editor.model.schema.register( 'widget', {
  452. inheritAllFrom: '$block',
  453. isObject: true
  454. } );
  455. editor.conversion.for( 'downcast' )
  456. .elementToElement( {
  457. model: 'widget',
  458. view: ( modelItem, viewWriter ) => {
  459. const parentDiv = viewWriter.createContainerElement( 'div' );
  460. viewWriter.setStyle( 'height', '50px', parentDiv );
  461. viewWriter.setStyle( 'width', '25%', parentDiv ); // It evaluates to 100px.
  462. const subDiv = viewWriter.createContainerElement( 'div' );
  463. viewWriter.insert( viewWriter.createPositionAt( subDiv, 'start' ), viewWriter.createText( 'foo' ) );
  464. viewWriter.addClass( 'sub-div', subDiv );
  465. viewWriter.setStyle( 'height', '20px', subDiv );
  466. viewWriter.setStyle( 'width', '50px', subDiv );
  467. viewWriter.insert( viewWriter.createPositionAt( parentDiv, 'start' ), subDiv );
  468. return toWidget( parentDiv, viewWriter, {
  469. label: 'element label'
  470. } );
  471. }
  472. } );
  473. }
  474. function createEditorElement() {
  475. const element = document.createElement( 'div' );
  476. document.body.appendChild( element );
  477. return element;
  478. }
  479. function createResizer( resizerOptions ) {
  480. const widgetModel = editor.model.document.getRoot().getChild( 0 );
  481. const defaultOptions = {
  482. unit: 'px',
  483. modelElement: widgetModel,
  484. viewElement: widget,
  485. editor,
  486. isCentered: () => false,
  487. getHandleHost( domWidgetElement ) {
  488. return domWidgetElement;
  489. },
  490. getResizeHost( domWidgetElement ) {
  491. return domWidgetElement;
  492. },
  493. onCommit: commitStub
  494. };
  495. return editor.plugins.get( WidgetResize ).attachTo( Object.assign( defaultOptions, resizerOptions ) );
  496. }
  497. } );