Skip to content

Commit

Permalink
Review fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
niegowski committed Sep 26, 2023
1 parent f671e28 commit a39c9bc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ The output pipeline is the equivalent of the input pipeline but for the copy and
└────────────────┌────────────────┘
┌─────────────V────────────┐ Processes model.DocumentFragment
view.Document │ and converts it to
ClipboardPipeline │ and converts it to
│ outputTransformation │ view.DocumentFragment.
└──────────────────────────┘
Expand Down
46 changes: 22 additions & 24 deletions packages/ckeditor5-clipboard/src/clipboardpipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,38 +147,36 @@ export default class ClipboardPipeline extends Plugin {
return 'ClipboardPipeline' as const;
}

/**
* @inheritDoc
*/
public init(): void {
const editor = this.editor;
const view = editor.editing.view;

view.addObserver( ClipboardObserver );

this._setupPasteDrop();
this._setupCopyCut();
}

/**
* Fires Clipboard `'outputTransformation'` event for given parameters.
*
* @param dataTransfer
* @param selection
* @param method
* @internal
*/
public fireOutputTransformationEvent(
public _fireOutputTransformationEvent(
dataTransfer: DataTransfer,
selection: Selection | DocumentSelection,
method: 'copy' | 'cut' | 'dragstart'
): void {
const content = this.editor.model.getSelectedContent( selection );
const data = {

this.fire<ClipboardOutputTransformationEvent>( 'outputTransformation', {
dataTransfer,
content,
method
};
this.fire<ClipboardOutputTransformationEvent>( 'outputTransformation', data );
}

/**
* @inheritDoc
*/
public init(): void {
const editor = this.editor;
const view = editor.editing.view;

view.addObserver( ClipboardObserver );

this._setupPasteDrop();
this._setupCopyCut();
} );
}

/**
Expand Down Expand Up @@ -285,7 +283,7 @@ export default class ClipboardPipeline extends Plugin {

data.preventDefault();

this.fireOutputTransformationEvent( dataTransfer, modelDocument.selection, evt.name );
this._fireOutputTransformationEvent( dataTransfer, modelDocument.selection, evt.name );
};

this.listenTo<ViewDocumentCopyEvent>( viewDocument, 'copy', onCopyCut, { priority: 'low' } );
Expand Down Expand Up @@ -480,18 +478,18 @@ export interface ViewDocumentClipboardOutputEventData {
*
* It is a part of the {@glink framework/deep-dive/clipboard#output-pipeline clipboard output pipeline}.
*
* @eventName module:engine/view/document~Document#outputTransformation
* @eventName ~ClipboardPipeline##outputTransformation
* @param data The event data.
*/
export type ClipboardOutputTransformationEvent = {
name: 'outputTransformation';
args: [ data: ClipboardOutputTransformationEventData ];
args: [ data: ClipboardOutputTransformationData ];
};

/**
* The value of the 'outputTransformation' event.
*/
export interface ClipboardOutputTransformationEventData {
export interface ClipboardOutputTransformationData {

/**
* The data transfer instance.
Expand Down
11 changes: 3 additions & 8 deletions packages/ckeditor5-clipboard/src/dragdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ import {
} from '@ckeditor/ckeditor5-utils';

import ClipboardPipeline, {
type ClipboardContentInsertionEvent,
type ViewDocumentClipboardOutputEvent
type ClipboardContentInsertionEvent
} from './clipboardpipeline';

import ClipboardObserver, {
Expand Down Expand Up @@ -290,13 +289,9 @@ export default class DragDrop extends Plugin {
data.dataTransfer.setData( 'application/ckeditor5-dragging-uid', this._draggingUid );

const draggedSelection = model.createSelection( this._draggedRange.toRange() );
const content = editor.data.toView( model.getSelectedContent( draggedSelection ) );
const clipboardPipeline: ClipboardPipeline = this.editor.plugins.get( 'ClipboardPipeline' );

viewDocument.fire<ViewDocumentClipboardOutputEvent>( 'clipboardOutput', {
dataTransfer: data.dataTransfer,
content,
method: 'dragstart'
} );
clipboardPipeline._fireOutputTransformationEvent( data.dataTransfer, draggedSelection, 'dragstart' );

const { dataTransfer, domTarget, domEvent } = data;
const { clientX } = domEvent;
Expand Down
5 changes: 3 additions & 2 deletions packages/ckeditor5-clipboard/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export {
type ClipboardContentInsertionEvent,
type ClipboardInputTransformationEvent,
type ClipboardInputTransformationData,
type ViewDocumentClipboardOutputEvent,
type ClipboardOutputTransformationEvent
type ClipboardOutputTransformationEvent,
type ClipboardOutputTransformationData,
type ViewDocumentClipboardOutputEvent
} from './clipboardpipeline';

export type {
Expand Down
23 changes: 23 additions & 0 deletions packages/ckeditor5-clipboard/tests/clipboardpipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,29 @@ describe( 'ClipboardPipeline feature', () => {
} );

describe( 'clipboard copy/cut pipeline', () => {
it( 'fires the outputTransformation event on the clipboardPlugin', done => {
const dataTransferMock = createDataTransfer();
const preventDefaultSpy = sinon.spy();

setModelData( editor.model, '<paragraph>a[bc</paragraph><paragraph>de]f</paragraph>' );

clipboardPlugin.on( 'outputTransformation', ( evt, data ) => {
expect( preventDefaultSpy.calledOnce ).to.be.true;

expect( data.method ).to.equal( 'copy' );
expect( data.dataTransfer ).to.equal( dataTransferMock );
expect( data.content ).is.instanceOf( ModelDocumentFragment );
expect( stringifyModel( data.content ) ).to.equal( '<paragraph>bc</paragraph><paragraph>de</paragraph>' );

done();
} );

viewDocument.fire( 'copy', {
dataTransfer: dataTransferMock,
preventDefault: preventDefaultSpy
} );
} );

it( 'fires clipboardOutput for copy with the selected content and correct method', done => {
const dataTransferMock = createDataTransfer();
const preventDefaultSpy = sinon.spy();
Expand Down
10 changes: 3 additions & 7 deletions packages/ckeditor5-clipboard/tests/manual/dragdroplists.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* globals console, window, document, CKEditorInspector */
/* globals console, window, document */

import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import { Essentials } from '@ckeditor/ckeditor5-essentials';
Expand Down Expand Up @@ -53,8 +53,6 @@ import SourceEditing from '@ckeditor/ckeditor5-source-editing/src/sourceediting'
import Style from '@ckeditor/ckeditor5-style/src/style';
import GeneralHtmlSupport from '@ckeditor/ckeditor5-html-support/src/generalhtmlsupport';

import { DragDropExperimental } from '../../src';

import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';

ClassicEditor
Expand All @@ -66,7 +64,7 @@ ClassicEditor
CodeBlock, DocumentListProperties, TableProperties, TableCellProperties, TableCaption, TableColumnResize,
EasyImage, ImageResize, ImageInsert, LinkImage, AutoImage, HtmlEmbed,
AutoLink, Mention, TextTransformation, Alignment, IndentBlock, PageBreak, HorizontalLine,
CloudServices, TextPartLanguage, SourceEditing, Style, GeneralHtmlSupport, DragDropExperimental
CloudServices, TextPartLanguage, SourceEditing, Style, GeneralHtmlSupport
],
toolbar: [
'heading', 'style',
Expand Down Expand Up @@ -102,9 +100,7 @@ ClassicEditor
}
} )
.then( editor => {
window.editorClassicLists = editor;

CKEditorInspector.attach( { classicLists: editor } );
window.editor = editor;
} )
.catch( err => {
console.error( err.stack );
Expand Down

0 comments on commit a39c9bc

Please sign in to comment.