| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /**
- * @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/tableclipboard
- */
- import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
- import TableSelection from './tableselection';
- /**
- * This plugin adds support for copying/cutting/pasting fragments of tables.
- * It is loaded automatically by the {@link module:table/table~Table} plugin.
- *
- * @extends module:core/plugin~Plugin
- */
- export default class TableClipboard extends Plugin {
- /**
- * @inheritDoc
- */
- static get pluginName() {
- return 'TableClipboard';
- }
- /**
- * @inheritDoc
- */
- static get requires() {
- return [ TableSelection ];
- }
- /**
- * @inheritDoc
- */
- init() {
- const editor = this.editor;
- const viewDocument = editor.editing.view.document;
- this.listenTo( viewDocument, 'copy', ( evt, data ) => this._onCopyCut( evt, data ) );
- this.listenTo( viewDocument, 'cut', ( evt, data ) => this._onCopyCut( evt, data ) );
- }
- /**
- * Copies table content to a clipboard on "copy" & "cut" events.
- *
- * @private
- * @param {module:utils/eventinfo~EventInfo} evt An object containing information about the handled event.
- * @param {Object} data Clipboard event data.
- */
- _onCopyCut( evt, data ) {
- const tableSelection = this.editor.plugins.get( 'TableSelection' );
- if ( !tableSelection.getSelectedTableCells() ) {
- return;
- }
- if ( evt.name == 'cut' && this.editor.isReadOnly ) {
- return;
- }
- data.preventDefault();
- evt.stop();
- const dataController = this.editor.data;
- const viewDocument = this.editor.editing.view.document;
- const content = dataController.toView( tableSelection.getSelectionAsFragment() );
- viewDocument.fire( 'clipboardOutput', {
- dataTransfer: data.dataTransfer,
- content,
- method: evt.name
- } );
- }
- }
|