UNPKG

3.92 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 */
5/**
6 * @module table/tablecellproperties/tablecellpropertiesui
7 */
8import { Plugin, type Editor } from 'ckeditor5/src/core';
9import { ContextualBalloon } from 'ckeditor5/src/ui';
10import TableCellPropertiesView from './ui/tablecellpropertiesview';
11/**
12 * The table cell properties UI plugin. It introduces the `'tableCellProperties'` button
13 * that opens a form allowing to specify the visual styling of a table cell.
14 *
15 * It uses the {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon plugin}.
16 */
17export default class TableCellPropertiesUI extends Plugin {
18 /**
19 * The default table cell properties.
20 */
21 private _defaultTableCellProperties;
22 /**
23 * The contextual balloon plugin instance.
24 */
25 private _balloon?;
26 /**
27 * The cell properties form view displayed inside the balloon.
28 */
29 view?: TableCellPropertiesView | null;
30 /**
31 * The batch used to undo all changes made by the form (which are live, as the user types)
32 * when "Cancel" was pressed. Each time the view is shown, a new batch is created.
33 */
34 private _undoStepBatch?;
35 /**
36 * Flag used to indicate whether view is ready to execute update commands
37 * (it finished loading initial data).
38 */
39 private _isReady?;
40 /**
41 * @inheritDoc
42 */
43 static get requires(): readonly [typeof ContextualBalloon];
44 /**
45 * @inheritDoc
46 */
47 static get pluginName(): 'TableCellPropertiesUI';
48 /**
49 * @inheritDoc
50 */
51 constructor(editor: Editor);
52 /**
53 * @inheritDoc
54 */
55 init(): void;
56 /**
57 * @inheritDoc
58 */
59 destroy(): void;
60 /**
61 * Creates the {@link module:table/tablecellproperties/ui/tablecellpropertiesview~TableCellPropertiesView} instance.
62 *
63 * @returns The cell properties form view instance.
64 */
65 private _createPropertiesView;
66 /**
67 * In this method the "editor data -> UI" binding is happening.
68 *
69 * When executed, this method obtains selected cell property values from various table commands
70 * and passes them to the {@link #view}.
71 *
72 * This way, the UI stays up–to–date with the editor data.
73 */
74 private _fillViewFormFromCommandValues;
75 /**
76 * Shows the {@link #view} in the {@link #_balloon}.
77 *
78 * **Note**: Each time a view is shown, a new {@link #_undoStepBatch} is created. It contains
79 * all changes made to the document when the view is visible, allowing a single undo step
80 * for all of them.
81 */
82 protected _showView(): void;
83 /**
84 * Removes the {@link #view} from the {@link #_balloon}.
85 */
86 protected _hideView(): void;
87 /**
88 * Repositions the {@link #_balloon} or hides the {@link #view} if a table cell is no longer selected.
89 */
90 protected _updateView(): void;
91 /**
92 * Returns `true` when the {@link #view} is visible in the {@link #_balloon}.
93 */
94 private get _isViewVisible();
95 /**
96 * Returns `true` when the {@link #view} is in the {@link #_balloon}.
97 */
98 private get _isViewInBalloon();
99 /**
100 * Creates a callback that when executed upon the {@link #view view's} property change
101 * executes a related editor command with the new property value.
102 *
103 * @param defaultValue The default value of the command.
104 */
105 private _getPropertyChangeCallback;
106 /**
107 * Creates a callback that when executed upon the {@link #view view's} property change:
108 * * Executes a related editor command with the new property value if the value is valid,
109 * * Or sets the error text next to the invalid field, if the value did not pass the validation.
110 */
111 private _getValidatedPropertyChangeCallback;
112}