widgettoolbarrepository.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* global document */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import BalloonEditor from '@ckeditor/ckeditor5-editor-balloon/src/ballooneditor';
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  10. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
  11. import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
  12. import Widget from '../src/widget';
  13. import WidgetToolbarRepository from '../src/widgettoolbarrepository';
  14. import { isWidget, toWidget } from '../src/utils';
  15. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  16. import View from '@ckeditor/ckeditor5-ui/src/view';
  17. import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  18. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  19. import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  20. describe( 'WidgetToolbarRepository', () => {
  21. let editor, model, balloon, widgetToolbarRepository, editorElement;
  22. testUtils.createSinonSandbox();
  23. beforeEach( () => {
  24. editorElement = document.createElement( 'div' );
  25. document.body.appendChild( editorElement );
  26. return ClassicTestEditor
  27. .create( editorElement, {
  28. plugins: [ Paragraph, FakeButton, WidgetToolbarRepository, FakeWidget, FakeChildWidget, BlockQuote ],
  29. fake: {
  30. toolbar: [ 'fake_button' ]
  31. }
  32. } )
  33. .then( newEditor => {
  34. editor = newEditor;
  35. model = newEditor.model;
  36. widgetToolbarRepository = editor.plugins.get( WidgetToolbarRepository );
  37. balloon = editor.plugins.get( 'ContextualBalloon' );
  38. } );
  39. } );
  40. afterEach( () => {
  41. editorElement.remove();
  42. return editor.destroy();
  43. } );
  44. it( 'should be loaded', () => {
  45. expect( editor.plugins.get( WidgetToolbarRepository ) ).to.be.instanceOf( WidgetToolbarRepository );
  46. } );
  47. it( 'should work if balloon toolbar is not available', () => {
  48. editorElement.remove();
  49. editor.destroy();
  50. editorElement = document.createElement( 'div' );
  51. document.body.appendChild( editorElement );
  52. expect( editor.plugins.has( 'BalloonToolbar' ) ).to.be.false;
  53. expect( editor.plugins.has( WidgetToolbarRepository ) ).to.be.true;
  54. } );
  55. describe( 'register()', () => {
  56. it( 'should create a widget toolbar and add it to the collection', () => {
  57. widgetToolbarRepository.register( 'fake', {
  58. items: editor.config.get( 'fake.toolbar' ),
  59. getRelatedElement: () => null,
  60. } );
  61. expect( widgetToolbarRepository._toolbarDefinitions.size ).to.equal( 1 );
  62. expect( widgetToolbarRepository._toolbarDefinitions.get( 'fake' ) ).to.be.an( 'object' );
  63. } );
  64. it( 'should throw when adding two times widget with the same id', () => {
  65. widgetToolbarRepository.register( 'fake', {
  66. items: editor.config.get( 'fake.toolbar' ),
  67. getRelatedElement: () => null
  68. } );
  69. expectToThrowCKEditorError( () => {
  70. widgetToolbarRepository.register( 'fake', {
  71. items: editor.config.get( 'fake.toolbar' ),
  72. getRelatedElement: () => null
  73. } );
  74. }, /^widget-toolbar-duplicated/, editor );
  75. } );
  76. } );
  77. describe( 'integration tests', () => {
  78. beforeEach( () => {
  79. editor.ui.focusTracker.isFocused = true;
  80. } );
  81. it( 'toolbar should be visible when the `getRelatedElement` callback returns a selected widget element', () => {
  82. widgetToolbarRepository.register( 'fake', {
  83. items: editor.config.get( 'fake.toolbar' ),
  84. getRelatedElement: getSelectedFakeWidget
  85. } );
  86. setData( model, '<paragraph>foo</paragraph>[<fake-widget></fake-widget>]' );
  87. const fakeWidgetToolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake' ).view;
  88. expect( balloon.visibleView ).to.equal( fakeWidgetToolbarView );
  89. } );
  90. it( 'toolbar should be hidden when the `getRelatedElement` callback returns null', () => {
  91. widgetToolbarRepository.register( 'fake', {
  92. items: editor.config.get( 'fake.toolbar' ),
  93. getRelatedElement: getSelectedFakeWidget
  94. } );
  95. setData( model, '[<paragraph>foo</paragraph>]<fake-widget></fake-widget>' );
  96. expect( balloon.visibleView ).to.equal( null );
  97. } );
  98. it( 'toolbar should be hidden when the `getRelatedElement` callback returns null #2', () => {
  99. widgetToolbarRepository.register( 'fake', {
  100. items: editor.config.get( 'fake.toolbar' ),
  101. getRelatedElement: getSelectedFakeWidget
  102. } );
  103. setData( model, '<paragraph>foo</paragraph>[<fake-widget></fake-widget>]' );
  104. model.change( writer => {
  105. // Select the <paragraph>foo</paragraph>.
  106. writer.setSelection( model.document.getRoot().getChild( 0 ), 'in' );
  107. } );
  108. expect( balloon.visibleView ).to.equal( null );
  109. } );
  110. it( 'toolbar should be removed from not visible balloon stack when the `getRelatedElement` callback returns null', () => {
  111. balloon.add( {
  112. view: new View(),
  113. stackId: 'secondary',
  114. position: {
  115. target: {}
  116. }
  117. } );
  118. widgetToolbarRepository.register( 'fake', {
  119. items: editor.config.get( 'fake.toolbar' ),
  120. getRelatedElement: getSelectedFakeWidget
  121. } );
  122. setData( model, '<paragraph>foo</paragraph>[<fake-widget></fake-widget>]' );
  123. const fakeWidgetToolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake' ).view;
  124. expect( balloon.hasView( fakeWidgetToolbarView ) );
  125. expect( balloon.visibleView ).to.not.equal( fakeWidgetToolbarView );
  126. model.change( writer => {
  127. // Select the <paragraph>foo</paragraph>.
  128. writer.setSelection( model.document.getRoot().getChild( 0 ), 'in' );
  129. } );
  130. expect( balloon.hasView( fakeWidgetToolbarView ) ).to.equal( false );
  131. } );
  132. it( 'toolbar should be hidden when the editor ui lost focus', () => {
  133. widgetToolbarRepository.register( 'fake', {
  134. items: editor.config.get( 'fake.toolbar' ),
  135. getRelatedElement: getSelectedFakeWidget
  136. } );
  137. setData( model, '<paragraph>foo</paragraph>[<fake-widget></fake-widget>]' );
  138. editor.ui.focusTracker.isFocused = false;
  139. expect( balloon.visibleView ).to.equal( null );
  140. } );
  141. it( 'toolbar should do nothing with toolbar when the editor ui lost focus but toolbar is not a visible view', () => {
  142. balloon.add( {
  143. view: new View(),
  144. stackId: 'secondary',
  145. position: {
  146. target: {}
  147. }
  148. } );
  149. widgetToolbarRepository.register( 'fake', {
  150. items: editor.config.get( 'fake.toolbar' ),
  151. getRelatedElement: getSelectedFakeWidget
  152. } );
  153. setData( model, '<paragraph>foo</paragraph>[<fake-widget></fake-widget>]' );
  154. const fakeWidgetToolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake' ).view;
  155. editor.ui.focusTracker.isFocused = false;
  156. expect( balloon.hasView( fakeWidgetToolbarView ) ).to.equal( true );
  157. } );
  158. it( 'toolbar should update its position when other widget is selected', () => {
  159. widgetToolbarRepository.register( 'fake', {
  160. items: editor.config.get( 'fake.toolbar' ),
  161. getRelatedElement: getSelectedFakeWidget
  162. } );
  163. setData( model, '[<fake-widget></fake-widget>]<fake-widget></fake-widget>' );
  164. model.change( writer => {
  165. // Select the second widget.
  166. writer.setSelection( model.document.getRoot().getChild( 1 ), 'on' );
  167. } );
  168. const fakeWidgetToolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake' ).view;
  169. expect( balloon.visibleView ).to.equal( fakeWidgetToolbarView );
  170. } );
  171. it( 'it should be possible to create a widget toolbar for content inside the widget', () => {
  172. widgetToolbarRepository.register( 'fake', {
  173. items: editor.config.get( 'fake.toolbar' ),
  174. getRelatedElement: getSelectedFakeWidgetContent
  175. } );
  176. setData( model, '<fake-widget>[foo]</fake-widget>' );
  177. const fakeWidgetToolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake' ).view;
  178. expect( balloon.visibleView ).to.equal( fakeWidgetToolbarView );
  179. } );
  180. it( 'toolbar should not engage when is in the balloon yet invisible', () => {
  181. widgetToolbarRepository.register( 'fake', {
  182. items: editor.config.get( 'fake.toolbar' ),
  183. getRelatedElement: getSelectedFakeWidget
  184. } );
  185. const fakeWidgetToolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake' ).view;
  186. setData( model, '[<fake-widget></fake-widget>]' );
  187. expect( balloon.visibleView ).to.equal( fakeWidgetToolbarView );
  188. const lastView = new View();
  189. lastView.element = document.createElement( 'div' );
  190. balloon.add( {
  191. view: lastView,
  192. position: {
  193. target: document.body
  194. }
  195. } );
  196. expect( balloon.visibleView ).to.equal( lastView );
  197. editor.ui.fire( 'update' );
  198. expect( balloon.visibleView ).to.equal( lastView );
  199. } );
  200. // #60
  201. it( 'should show up only for the related element which is deepest in the view document', () => {
  202. // The point of this widget is to provide a getRelatedElement function that
  203. // returns a super–shallow related element which is ignored but satisfies code coverage.
  204. widgetToolbarRepository.register( 'dummy', {
  205. items: editor.config.get( 'fake.toolbar' ),
  206. getRelatedElement: () => editor.editing.view.document.getRoot()
  207. } );
  208. widgetToolbarRepository.register( 'fake', {
  209. items: editor.config.get( 'fake.toolbar' ),
  210. getRelatedElement: getSelectedFakeWidget
  211. } );
  212. widgetToolbarRepository.register( 'fake-child', {
  213. items: editor.config.get( 'fake.toolbar' ),
  214. getRelatedElement: getSelectedFakeChildWidget
  215. } );
  216. setData( model,
  217. '<paragraph>foo</paragraph>' +
  218. '<fake-widget>' +
  219. '<paragraph>foo</paragraph>' +
  220. '[<fake-child-widget></fake-child-widget>]' +
  221. '</fake-widget>' );
  222. const fakeChildWidgetToolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake-child' ).view;
  223. expect( balloon.visibleView ).to.equal( fakeChildWidgetToolbarView );
  224. } );
  225. // #60
  226. it( 'should attach to the new related view element upon selecting another widget', () => {
  227. const view = editor.editing.view;
  228. widgetToolbarRepository.register( 'fake', {
  229. items: editor.config.get( 'fake.toolbar' ),
  230. getRelatedElement: getSelectedFakeWidget
  231. } );
  232. widgetToolbarRepository.register( 'fake-child', {
  233. items: editor.config.get( 'fake.toolbar' ),
  234. getRelatedElement: getSelectedFakeChildWidget
  235. } );
  236. setData( model,
  237. '<paragraph>foo</paragraph>' +
  238. '[<fake-widget>' +
  239. '<paragraph>foo</paragraph>' +
  240. '<fake-child-widget></fake-child-widget>' +
  241. '</fake-widget>]' );
  242. const fakeWidgetToolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake' ).view;
  243. const fakeChildWidgetToolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake-child' ).view;
  244. expect( balloon.visibleView ).to.equal( fakeWidgetToolbarView );
  245. const fakeChildViewElement = view.document.getRoot().getChild( 1 ).getChild( 1 );
  246. const updatePositionSpy = sinon.spy( balloon, 'add' );
  247. view.change( writer => {
  248. // [<fake-child-widget></fake-child-widget>]
  249. writer.setSelection( fakeChildViewElement, 'on' );
  250. } );
  251. expect( balloon.visibleView ).to.equal( fakeChildWidgetToolbarView );
  252. expect( updatePositionSpy.firstCall.args[ 0 ].position.target ).to.equal(
  253. view.domConverter.viewToDom( fakeChildViewElement ) );
  254. } );
  255. it( 'should not update balloon position when toolbar is in not visible stack', () => {
  256. const customView = new View();
  257. sinon.spy( balloon.view, 'pin' );
  258. widgetToolbarRepository.register( 'fake', {
  259. items: editor.config.get( 'fake.toolbar' ),
  260. getRelatedElement: getSelectedFakeWidget
  261. } );
  262. setData( model,
  263. '<paragraph>foo</paragraph>' +
  264. '[<fake-widget></fake-widget>]'
  265. );
  266. balloon.add( {
  267. stackId: 'custom',
  268. view: customView,
  269. position: { target: {} }
  270. } );
  271. balloon.showStack( 'custom' );
  272. const fakeWidgetToolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake' ).view;
  273. expect( balloon.visibleView ).to.equal( customView );
  274. expect( balloon.hasView( fakeWidgetToolbarView ) ).to.equal( true );
  275. const spy = testUtils.sinon.spy( balloon, 'updatePosition' );
  276. editor.ui.fire( 'update' );
  277. sinon.assert.notCalled( spy );
  278. } );
  279. it( 'should update balloon position when stack with toolbar is switched in rotator to visible', () => {
  280. const view = editor.editing.view;
  281. const customView = new View();
  282. sinon.spy( balloon.view, 'pin' );
  283. widgetToolbarRepository.register( 'fake', {
  284. items: editor.config.get( 'fake.toolbar' ),
  285. getRelatedElement: getSelectedFakeWidget
  286. } );
  287. setData( model,
  288. '<paragraph>foo</paragraph>' +
  289. '[<fake-widget></fake-widget>]'
  290. );
  291. const fakeViewElement = view.document.getRoot().getChild( 1 );
  292. const fakeDomElement = editor.editing.view.domConverter.mapViewToDom( fakeViewElement );
  293. const fakeWidgetToolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake' ).view;
  294. expect( balloon.view.pin.lastCall.args[ 0 ].target ).to.equal( fakeDomElement );
  295. balloon.add( {
  296. stackId: 'custom',
  297. view: customView,
  298. position: { target: {} }
  299. } );
  300. balloon.showStack( 'custom' );
  301. expect( balloon.visibleView ).to.equal( customView );
  302. expect( balloon.hasView( fakeWidgetToolbarView ) ).to.equal( true );
  303. editor.execute( 'blockQuote' );
  304. balloon.showStack( 'main' );
  305. expect( balloon.visibleView ).to.equal( fakeWidgetToolbarView );
  306. expect( balloon.hasView( customView ) ).to.equal( true );
  307. expect( balloon.view.pin.lastCall.args[ 0 ].target ).to.not.equal( fakeDomElement );
  308. const newFakeViewElement = view.document.getRoot().getChild( 1 ).getChild( 0 );
  309. const newFakeDomElement = editor.editing.view.domConverter.mapViewToDom( newFakeViewElement );
  310. expect( balloon.view.pin.lastCall.args[ 0 ].target ).to.equal( newFakeDomElement );
  311. } );
  312. } );
  313. } );
  314. describe( 'WidgetToolbarRepository - integration with the BalloonToolbar', () => {
  315. let clock, editor, model, balloon, balloonToolbar, widgetToolbarRepository, editorElement;
  316. testUtils.createSinonSandbox();
  317. beforeEach( () => {
  318. editorElement = document.createElement( 'div' );
  319. document.body.appendChild( editorElement );
  320. clock = testUtils.sinon.useFakeTimers();
  321. return BalloonEditor
  322. .create( editorElement, {
  323. plugins: [ Paragraph, FakeButton, WidgetToolbarRepository, FakeWidget, Bold ],
  324. balloonToolbar: [ 'bold' ],
  325. fake: {
  326. toolbar: [ 'fake_button' ]
  327. }
  328. } )
  329. .then( newEditor => {
  330. editor = newEditor;
  331. model = newEditor.model;
  332. widgetToolbarRepository = editor.plugins.get( WidgetToolbarRepository );
  333. balloon = editor.plugins.get( 'ContextualBalloon' );
  334. balloonToolbar = editor.plugins.get( 'BalloonToolbar' );
  335. editor.ui.focusTracker.isFocused = true;
  336. } );
  337. } );
  338. afterEach( () => {
  339. editorElement.remove();
  340. return editor.destroy();
  341. } );
  342. it( 'balloon toolbar should be hidden when the widget is selected', () => {
  343. widgetToolbarRepository.register( 'fake', {
  344. items: editor.config.get( 'fake.toolbar' ),
  345. getRelatedElement: getSelectedFakeWidget,
  346. } );
  347. const fakeWidgetToolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake' ).view;
  348. editor.editing.view.document.isFocused = true;
  349. setData( model, '[<fake-widget></fake-widget>]<paragraph>foo</paragraph>' );
  350. clock.tick( 200 );
  351. expect( balloon.visibleView ).to.equal( fakeWidgetToolbarView );
  352. } );
  353. it( 'balloon toolbar should be visible when the widget is not selected', () => {
  354. widgetToolbarRepository.register( 'fake', {
  355. items: editor.config.get( 'fake.toolbar' ),
  356. getRelatedElement: getSelectedFakeWidget
  357. } );
  358. editor.editing.view.document.isFocused = true;
  359. setData( model, '<fake-widget></fake-widget><paragraph>[foo]</paragraph>' );
  360. clock.tick( 200 );
  361. expect( balloon.visibleView ).to.equal( balloonToolbar.toolbarView );
  362. } );
  363. } );
  364. function getSelectedFakeWidget( selection ) {
  365. const viewElement = selection.getSelectedElement();
  366. if ( viewElement && isWidget( viewElement ) && !!viewElement.getCustomProperty( 'fakeWidget' ) ) {
  367. return viewElement;
  368. }
  369. return null;
  370. }
  371. function getSelectedFakeChildWidget( selection ) {
  372. const viewElement = selection.getSelectedElement();
  373. if ( viewElement && isWidget( viewElement ) && !!viewElement.getCustomProperty( 'fakeChildWidget' ) ) {
  374. return viewElement;
  375. }
  376. return null;
  377. }
  378. function getSelectedFakeWidgetContent( selection ) {
  379. const pos = selection.getFirstPosition();
  380. let node = pos.parent;
  381. while ( node ) {
  382. if ( node.is( 'element' ) && isWidget( node ) && node.getCustomProperty( 'fakeWidget' ) ) {
  383. return node;
  384. }
  385. node = node.parent;
  386. }
  387. return null;
  388. }
  389. // Plugin that adds fake_button to editor's component factory.
  390. class FakeButton extends Plugin {
  391. init() {
  392. this.editor.ui.componentFactory.add( 'fake_button', locale => {
  393. const view = new ButtonView( locale );
  394. view.set( {
  395. label: 'fake button'
  396. } );
  397. return view;
  398. } );
  399. }
  400. }
  401. // Simple widget plugin
  402. // It registers `<fake-widget>` block in model and represents `div` in the view.
  403. // It allows having text inside self.
  404. class FakeWidget extends Plugin {
  405. static get requires() {
  406. return [ Widget ];
  407. }
  408. init() {
  409. const editor = this.editor;
  410. const schema = editor.model.schema;
  411. schema.register( 'fake-widget', {
  412. isObject: true,
  413. isBlock: true,
  414. allowWhere: '$block'
  415. } );
  416. schema.extend( '$text', { allowIn: 'fake-widget' } );
  417. schema.extend( 'paragraph', { allowIn: 'fake-widget' } );
  418. const conversion = editor.conversion;
  419. conversion.for( 'dataDowncast' ).elementToElement( {
  420. model: 'fake-widget',
  421. view: ( modelElement, viewWriter ) => {
  422. return viewWriter.createContainerElement( 'div' );
  423. }
  424. } );
  425. conversion.for( 'editingDowncast' ).elementToElement( {
  426. model: 'fake-widget',
  427. view: ( modelElement, viewWriter ) => {
  428. const fakeWidget = viewWriter.createContainerElement( 'div' );
  429. viewWriter.setCustomProperty( 'fakeWidget', true, fakeWidget );
  430. return toWidget( fakeWidget, viewWriter, { label: 'fake-widget' } );
  431. }
  432. } );
  433. conversion.for( 'upcast' ).elementToElement( {
  434. view: {
  435. name: 'div'
  436. },
  437. model: ( view, modelWriter ) => {
  438. return modelWriter.createElement( 'fake-widget' );
  439. }
  440. } );
  441. }
  442. }
  443. // A simple child widget plugin
  444. // It registers `<fake-child-widget>` block in model and represents `div` in the view.
  445. // It allows having text inside self.
  446. class FakeChildWidget extends Plugin {
  447. static get requires() {
  448. return [ Widget ];
  449. }
  450. init() {
  451. const editor = this.editor;
  452. const schema = editor.model.schema;
  453. schema.register( 'fake-child-widget', {
  454. isObject: true,
  455. isBlock: true,
  456. allowWhere: '$block',
  457. allowIn: 'fake-widget'
  458. } );
  459. schema.extend( '$text', { allowIn: 'fake-child-widget' } );
  460. schema.extend( 'paragraph', { allowIn: 'fake-child-widget' } );
  461. const conversion = editor.conversion;
  462. conversion.for( 'dataDowncast' ).elementToElement( {
  463. model: 'fake-child-widget',
  464. view: ( modelElement, viewWriter ) => {
  465. return viewWriter.createContainerElement( 'div' );
  466. }
  467. } );
  468. conversion.for( 'editingDowncast' ).elementToElement( {
  469. model: 'fake-child-widget',
  470. view: ( modelElement, viewWriter ) => {
  471. const fakeWidget = viewWriter.createContainerElement( 'div' );
  472. viewWriter.setCustomProperty( 'fakeChildWidget', true, fakeWidget );
  473. return toWidget( fakeWidget, viewWriter, { label: 'fake-child-widget' } );
  474. }
  475. } );
  476. conversion.for( 'upcast' ).elementToElement( {
  477. view: {
  478. name: 'div'
  479. },
  480. model: ( view, modelWriter ) => {
  481. return modelWriter.createElement( 'fake-child-widget' );
  482. }
  483. } );
  484. }
  485. }