UNPKG

3.94 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/tableproperties/tablepropertiesui
7 */
8import { type Editor, Plugin } from 'ckeditor5/src/core';
9import { ContextualBalloon } from 'ckeditor5/src/ui';
10import TablePropertiesView from './ui/tablepropertiesview';
11/**
12 * The table properties UI plugin. It introduces the `'tableProperties'` button
13 * that opens a form allowing to specify visual styling of an entire table.
14 *
15 * It uses the {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon plugin}.
16 */
17export default class TablePropertiesUI extends Plugin {
18 /**
19 * The default table properties.
20 */
21 private _defaultTableProperties;
22 /**
23 * The contextual balloon plugin instance.
24 */
25 private _balloon;
26 /**
27 * The properties form view displayed inside the balloon.
28 */
29 view: TablePropertiesView | 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(): 'TablePropertiesUI';
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/tableproperties/ui/tablepropertiesview~TablePropertiesView} instance.
62 *
63 * @returns The table 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 table 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, the new {@link #_undoStepBatch} is created that 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 is no longer selected.
89 */
90 protected _updateView(): void;
91 /**
92 * Returns `true` when the {@link #view} is the 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 {@link #view view's} property change
101 * executes a related editor command with the new property value.
102 *
103 * If new value will be set to the default value, the command will not be executed.
104 *
105 * @param commandName The command that will be executed.
106 */
107 private _getPropertyChangeCallback;
108 /**
109 * Creates a callback that when executed upon {@link #view view's} property change:
110 * * executes a related editor command with the new property value if the value is valid,
111 * * or sets the error text next to the invalid field, if the value did not pass the validation.
112 */
113 private _getValidatedPropertyChangeCallback;
114}