UNPKG

2.52 kBTypeScriptView Raw
1/**
2 * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4 */
5import { Plugin } from 'ckeditor5/src/core';
6import type { DocumentFragment, Element, Item, Model, Position, Writer } from 'ckeditor5/src/engine';
7import TableSelection from './tableselection';
8import { type TableSlot } from './tablewalker';
9import TableUtils from './tableutils';
10/**
11 * This plugin adds support for copying/cutting/pasting fragments of tables.
12 * It is loaded automatically by the {@link module:table/table~Table} plugin.
13 */
14export default class TableClipboard extends Plugin {
15 /**
16 * @inheritDoc
17 */
18 static get pluginName(): 'TableClipboard';
19 /**
20 * @inheritDoc
21 */
22 static get requires(): readonly [typeof TableSelection, typeof TableUtils];
23 /**
24 * @inheritDoc
25 */
26 init(): void;
27 /**
28 * Copies table content to a clipboard on "copy" & "cut" events.
29 *
30 * @param evt An object containing information about the handled event.
31 * @param data Clipboard event data.
32 */
33 private _onCopyCut;
34 /**
35 * Overrides default {@link module:engine/model/model~Model#insertContent `model.insertContent()`} method to handle pasting table inside
36 * selected table fragment.
37 *
38 * Depending on selected table fragment:
39 * - If a selected table fragment is smaller than paste table it will crop pasted table to match dimensions.
40 * - If dimensions are equal it will replace selected table fragment with a pasted table contents.
41 *
42 * @param content The content to insert.
43 * @param selectable The selection into which the content should be inserted.
44 * If not provided the current model document selection will be used.
45 */
46 private _onInsertContent;
47 /**
48 * Replaces the part of selectedTable with pastedTable.
49 */
50 private _replaceSelectedCellsWithPasted;
51 /**
52 * Replaces a single table slot.
53 *
54 * @returns Inserted table cell or null if slot should remain empty.
55 * @private
56 */
57 _replaceTableSlotCell(tableSlot: TableSlot, cellToInsert: Element | null, insertPosition: Position, writer: Writer): Element | null;
58 /**
59 * Extracts the table for pasting into a table.
60 *
61 * @param content The content to insert.
62 * @param model The editor model.
63 */
64 getTableIfOnlyTableInContent(content: DocumentFragment | Item, model: Model): Element | null;
65}