UNPKG

5.05 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, type Editor } from 'ckeditor5/src/core';
6import type { Element } from 'ckeditor5/src/engine';
7import TableEditing from '../tableediting';
8import TableUtils from '../tableutils';
9/**
10 * The table column resize editing plugin.
11 */
12export default class TableColumnResizeEditing extends Plugin {
13 /**
14 * A flag indicating if the column resizing is in progress.
15 */
16 private _isResizingActive;
17 /**
18 * A flag indicating if the column resizing is allowed. It is not allowed if the editor is in read-only
19 * or comments-only mode or the `TableColumnResize` plugin is disabled.
20 *
21 * @observable
22 * @internal
23 */
24 _isResizingAllowed: boolean;
25 /**
26 * A temporary storage for the required data needed to correctly calculate the widths of the resized columns. This storage is
27 * initialized when column resizing begins, and is purged upon completion.
28 */
29 private _resizingData;
30 /**
31 * DOM emitter.
32 */
33 private _domEmitter;
34 /**
35 * A local reference to the {@link module:table/tableutils~TableUtils} plugin.
36 */
37 private _tableUtilsPlugin;
38 /**
39 * @inheritDoc
40 */
41 static get requires(): readonly [typeof TableEditing, typeof TableUtils];
42 /**
43 * @inheritDoc
44 */
45 static get pluginName(): 'TableColumnResizeEditing';
46 /**
47 * @inheritDoc
48 */
49 constructor(editor: Editor);
50 /**
51 * @inheritDoc
52 */
53 init(): void;
54 /**
55 * @inheritDoc
56 */
57 destroy(): void;
58 /**
59 * Returns a 'tableColumnGroup' element from the 'table'.
60 *
61 * @param element A 'table' or 'tableColumnGroup' element.
62 * @returns A 'tableColumnGroup' element.
63 */
64 getColumnGroupElement(element: Element): Element | undefined;
65 /**
66 * Returns an array of 'tableColumn' elements.
67 *
68 * @param element A 'table' or 'tableColumnGroup' element.
69 * @returns An array of 'tableColumn' elements.
70 */
71 getTableColumnElements(element: Element): Array<Element>;
72 /**
73 * Returns an array of table column widths.
74 *
75 * @param element A 'table' or 'tableColumnGroup' element.
76 * @returns An array of table column widths.
77 */
78 getTableColumnsWidths(element: Element): Array<string>;
79 /**
80 * Registers new attributes for a table model element.
81 */
82 private _extendSchema;
83 /**
84 * Registers table column resize post-fixer.
85 *
86 * It checks if the change from the differ concerns a table-related element or attribute. For detected changes it:
87 * * Adjusts the `columnWidths` attribute to guarantee that the sum of the widths from all columns is 100%.
88 * * Checks if the `columnWidths` attribute gets updated accordingly after columns have been added or removed.
89 */
90 private _registerPostFixer;
91 /**
92 * Registers table column resize converters.
93 */
94 private _registerConverters;
95 /**
96 * Registers listeners to handle resizing process.
97 */
98 private _registerResizingListeners;
99 /**
100 * Handles the `mousedown` event on column resizer element:
101 * * calculates the initial column pixel widths,
102 * * inserts the `<colgroup>` element if it is not present in the `<table>`,
103 * * puts the necessary data in the temporary storage,
104 * * applies the attributes to the `<table>` view element.
105 *
106 * @param eventInfo An object containing information about the fired event.
107 * @param domEventData The data related to the DOM event.
108 */
109 private _onMouseDownHandler;
110 /**
111 * Handles the `mousemove` event.
112 * * If resizing process is not in progress, it does nothing.
113 * * If resizing is active but not allowed, it stops the resizing process instantly calling the `mousedown` event handler.
114 * * Otherwise it dynamically updates the widths of the resized columns.
115 *
116 * @param eventInfo An object containing information about the fired event.
117 * @param mouseEventData The native DOM event.
118 */
119 private _onMouseMoveHandler;
120 /**
121 * Handles the `mouseup` event.
122 * * If resizing process is not in progress, it does nothing.
123 * * If resizing is active but not allowed, it cancels the resizing process restoring the original widths.
124 * * Otherwise it propagates the changes from view to the model by executing the adequate commands.
125 */
126 private _onMouseUpHandler;
127 /**
128 * Retrieves and returns required data needed for the resizing process.
129 *
130 * @param domEventData The data of the `mousedown` event.
131 * @param columnWidths The current widths of the columns.
132 * @returns The data needed for the resizing process.
133 */
134 private _getResizingData;
135 /**
136 * Registers a listener ensuring that each resizable cell have a resizer handle.
137 */
138 private _registerResizerInserter;
139}