@ckeditor/ckeditor5-ui 40.2.0 → 41.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/CHANGELOG.md +8 -8
  2. package/LICENSE.md +1 -1
  3. package/lang/contexts.json +3 -1
  4. package/lang/translations/ar.po +9 -1
  5. package/lang/translations/ast.po +9 -1
  6. package/lang/translations/az.po +9 -1
  7. package/lang/translations/bg.po +9 -1
  8. package/lang/translations/bn.po +9 -1
  9. package/lang/translations/ca.po +9 -1
  10. package/lang/translations/cs.po +9 -1
  11. package/lang/translations/da.po +9 -1
  12. package/lang/translations/de-ch.po +9 -1
  13. package/lang/translations/de.po +9 -1
  14. package/lang/translations/el.po +9 -1
  15. package/lang/translations/en-au.po +9 -1
  16. package/lang/translations/en-gb.po +9 -1
  17. package/lang/translations/en.po +9 -1
  18. package/lang/translations/eo.po +9 -1
  19. package/lang/translations/es.po +14 -6
  20. package/lang/translations/et.po +9 -1
  21. package/lang/translations/eu.po +9 -1
  22. package/lang/translations/fa.po +9 -1
  23. package/lang/translations/fi.po +9 -1
  24. package/lang/translations/fr.po +9 -1
  25. package/lang/translations/gl.po +9 -1
  26. package/lang/translations/he.po +9 -1
  27. package/lang/translations/hi.po +9 -1
  28. package/lang/translations/hr.po +9 -1
  29. package/lang/translations/hu.po +9 -1
  30. package/lang/translations/id.po +9 -1
  31. package/lang/translations/it.po +9 -1
  32. package/lang/translations/ja.po +9 -1
  33. package/lang/translations/km.po +9 -1
  34. package/lang/translations/kn.po +9 -1
  35. package/lang/translations/ko.po +9 -1
  36. package/lang/translations/ku.po +9 -1
  37. package/lang/translations/lt.po +9 -1
  38. package/lang/translations/lv.po +9 -1
  39. package/lang/translations/ms.po +9 -1
  40. package/lang/translations/nb.po +9 -1
  41. package/lang/translations/ne.po +9 -1
  42. package/lang/translations/nl.po +9 -1
  43. package/lang/translations/no.po +9 -1
  44. package/lang/translations/pl.po +9 -1
  45. package/lang/translations/pt-br.po +9 -1
  46. package/lang/translations/pt.po +9 -1
  47. package/lang/translations/ro.po +9 -1
  48. package/lang/translations/ru.po +9 -1
  49. package/lang/translations/sk.po +9 -1
  50. package/lang/translations/sl.po +9 -1
  51. package/lang/translations/sq.po +9 -1
  52. package/lang/translations/sr-latn.po +9 -1
  53. package/lang/translations/sr.po +9 -1
  54. package/lang/translations/sv.po +9 -1
  55. package/lang/translations/th.po +9 -1
  56. package/lang/translations/tk.po +9 -1
  57. package/lang/translations/tr.po +9 -1
  58. package/lang/translations/tt.po +9 -1
  59. package/lang/translations/ug.po +9 -1
  60. package/lang/translations/uk.po +9 -1
  61. package/lang/translations/ur.po +9 -1
  62. package/lang/translations/uz.po +9 -1
  63. package/lang/translations/vi.po +9 -1
  64. package/lang/translations/zh-cn.po +9 -1
  65. package/lang/translations/zh.po +9 -1
  66. package/package.json +4 -3
  67. package/src/arialiveannouncer.d.ts +14 -10
  68. package/src/arialiveannouncer.js +11 -8
  69. package/src/augmentation.d.ts +3 -2
  70. package/src/augmentation.js +1 -1
  71. package/src/autocomplete/autocompleteview.d.ts +4 -4
  72. package/src/autocomplete/autocompleteview.js +4 -3
  73. package/src/bindings/addkeyboardhandlingforgrid.d.ts +2 -2
  74. package/src/bindings/addkeyboardhandlingforgrid.js +1 -1
  75. package/src/bindings/clickoutsidehandler.d.ts +1 -1
  76. package/src/bindings/clickoutsidehandler.js +1 -1
  77. package/src/bindings/csstransitiondisablermixin.d.ts +2 -2
  78. package/src/bindings/csstransitiondisablermixin.js +1 -1
  79. package/src/bindings/draggableviewmixin.d.ts +46 -0
  80. package/src/bindings/draggableviewmixin.js +144 -0
  81. package/src/bindings/injectcsstransitiondisabler.d.ts +2 -2
  82. package/src/bindings/injectcsstransitiondisabler.js +1 -1
  83. package/src/bindings/preventdefault.d.ts +3 -3
  84. package/src/bindings/preventdefault.js +1 -1
  85. package/src/bindings/submithandler.d.ts +2 -2
  86. package/src/bindings/submithandler.js +1 -1
  87. package/src/button/button.d.ts +4 -1
  88. package/src/button/button.js +1 -1
  89. package/src/button/buttonlabel.d.ts +2 -2
  90. package/src/button/buttonlabel.js +1 -1
  91. package/src/button/buttonlabelview.d.ts +3 -3
  92. package/src/button/buttonlabelview.js +2 -2
  93. package/src/button/buttonview.d.ts +6 -6
  94. package/src/button/buttonview.js +4 -4
  95. package/src/button/switchbuttonview.d.ts +3 -3
  96. package/src/button/switchbuttonview.js +3 -3
  97. package/src/collapsible/collapsibleview.d.ts +7 -6
  98. package/src/collapsible/collapsibleview.js +3 -3
  99. package/src/colorgrid/colorgridview.d.ts +5 -5
  100. package/src/colorgrid/colorgridview.js +4 -4
  101. package/src/colorgrid/colortileview.d.ts +2 -2
  102. package/src/colorgrid/colortileview.js +2 -2
  103. package/src/colorgrid/utils.d.ts +1 -1
  104. package/src/colorgrid/utils.js +1 -1
  105. package/src/colorpicker/colorpickerview.d.ts +12 -7
  106. package/src/colorpicker/colorpickerview.js +12 -9
  107. package/src/colorpicker/utils.d.ts +6 -1
  108. package/src/colorpicker/utils.js +10 -1
  109. package/src/colorselector/colorgridsfragmentview.d.ts +9 -8
  110. package/src/colorselector/colorgridsfragmentview.js +10 -11
  111. package/src/colorselector/colorpickerfragmentview.d.ts +9 -8
  112. package/src/colorselector/colorpickerfragmentview.js +7 -8
  113. package/src/colorselector/colorselectorview.d.ts +9 -9
  114. package/src/colorselector/colorselectorview.js +6 -6
  115. package/src/colorselector/documentcolorcollection.d.ts +2 -2
  116. package/src/colorselector/documentcolorcollection.js +1 -1
  117. package/src/componentfactory.d.ts +2 -2
  118. package/src/componentfactory.js +1 -1
  119. package/src/dialog/dialog.d.ts +273 -0
  120. package/src/dialog/dialog.js +261 -0
  121. package/src/dialog/dialogactionsview.d.ts +69 -0
  122. package/src/dialog/dialogactionsview.js +98 -0
  123. package/src/dialog/dialogcontentview.d.ts +27 -0
  124. package/src/dialog/dialogcontentview.js +35 -0
  125. package/src/dialog/dialogview.d.ts +256 -0
  126. package/src/dialog/dialogview.js +466 -0
  127. package/src/dropdown/button/dropdownbutton.d.ts +3 -3
  128. package/src/dropdown/button/dropdownbutton.js +1 -1
  129. package/src/dropdown/button/dropdownbuttonview.d.ts +4 -4
  130. package/src/dropdown/button/dropdownbuttonview.js +3 -3
  131. package/src/dropdown/button/splitbuttonview.d.ts +7 -7
  132. package/src/dropdown/button/splitbuttonview.js +3 -3
  133. package/src/dropdown/dropdownpanelfocusable.d.ts +1 -1
  134. package/src/dropdown/dropdownpanelfocusable.js +1 -1
  135. package/src/dropdown/dropdownpanelview.d.ts +4 -4
  136. package/src/dropdown/dropdownpanelview.js +2 -2
  137. package/src/dropdown/dropdownview.d.ts +8 -8
  138. package/src/dropdown/dropdownview.js +5 -4
  139. package/src/dropdown/utils.d.ts +9 -9
  140. package/src/dropdown/utils.js +15 -15
  141. package/src/editableui/editableuiview.d.ts +3 -3
  142. package/src/editableui/editableuiview.js +2 -2
  143. package/src/editableui/inline/inlineeditableuiview.d.ts +4 -4
  144. package/src/editableui/inline/inlineeditableuiview.js +2 -2
  145. package/src/editorui/bodycollection.d.ts +3 -3
  146. package/src/editorui/bodycollection.js +3 -3
  147. package/src/editorui/boxed/boxededitoruiview.d.ts +3 -3
  148. package/src/editorui/boxed/boxededitoruiview.js +3 -3
  149. package/src/editorui/editorui.d.ts +7 -7
  150. package/src/editorui/editorui.js +5 -5
  151. package/src/editorui/editoruiview.d.ts +4 -4
  152. package/src/editorui/editoruiview.js +3 -3
  153. package/src/editorui/poweredby.d.ts +1 -1
  154. package/src/editorui/poweredby.js +4 -4
  155. package/src/focuscycler.d.ts +29 -10
  156. package/src/focuscycler.js +46 -17
  157. package/src/formheader/formheaderview.d.ts +4 -4
  158. package/src/formheader/formheaderview.js +3 -3
  159. package/src/highlightedtext/highlightedtextview.d.ts +2 -2
  160. package/src/highlightedtext/highlightedtextview.js +2 -2
  161. package/src/icon/iconview.d.ts +5 -2
  162. package/src/icon/iconview.js +4 -3
  163. package/src/iframe/iframeview.d.ts +2 -2
  164. package/src/iframe/iframeview.js +2 -2
  165. package/src/index.d.ts +67 -68
  166. package/src/index.js +63 -65
  167. package/src/input/inputbase.d.ts +2 -2
  168. package/src/input/inputbase.js +2 -2
  169. package/src/input/inputview.d.ts +2 -2
  170. package/src/input/inputview.js +2 -2
  171. package/src/inputnumber/inputnumberview.d.ts +2 -2
  172. package/src/inputnumber/inputnumberview.js +2 -2
  173. package/src/inputtext/inputtextview.d.ts +2 -2
  174. package/src/inputtext/inputtextview.js +2 -2
  175. package/src/label/labelview.d.ts +2 -2
  176. package/src/label/labelview.js +2 -2
  177. package/src/labeledfield/labeledfieldview.d.ts +5 -5
  178. package/src/labeledfield/labeledfieldview.js +3 -3
  179. package/src/labeledfield/utils.d.ts +14 -14
  180. package/src/labeledfield/utils.js +13 -13
  181. package/src/labeledinput/labeledinputview.d.ts +4 -4
  182. package/src/labeledinput/labeledinputview.js +3 -3
  183. package/src/list/listitemgroupview.d.ts +5 -5
  184. package/src/list/listitemgroupview.js +5 -5
  185. package/src/list/listitemview.d.ts +4 -4
  186. package/src/list/listitemview.js +2 -2
  187. package/src/list/listseparatorview.d.ts +2 -2
  188. package/src/list/listseparatorview.js +2 -2
  189. package/src/list/listview.d.ts +9 -8
  190. package/src/list/listview.js +7 -7
  191. package/src/model.d.ts +1 -1
  192. package/src/model.js +1 -1
  193. package/src/notification/notification.d.ts +1 -1
  194. package/src/notification/notification.js +1 -1
  195. package/src/panel/balloon/balloonpanelview.d.ts +4 -4
  196. package/src/panel/balloon/balloonpanelview.js +5 -4
  197. package/src/panel/balloon/contextualballoon.d.ts +5 -5
  198. package/src/panel/balloon/contextualballoon.js +7 -9
  199. package/src/panel/sticky/stickypanelview.d.ts +9 -9
  200. package/src/panel/sticky/stickypanelview.js +7 -7
  201. package/src/search/filteredview.d.ts +2 -2
  202. package/src/search/filteredview.js +1 -1
  203. package/src/search/searchinfoview.d.ts +3 -3
  204. package/src/search/searchinfoview.js +2 -2
  205. package/src/search/searchresultsview.d.ts +5 -5
  206. package/src/search/searchresultsview.js +3 -3
  207. package/src/search/text/searchtextqueryview.d.ts +5 -5
  208. package/src/search/text/searchtextqueryview.js +5 -5
  209. package/src/search/text/searchtextview.d.ts +12 -12
  210. package/src/search/text/searchtextview.js +6 -6
  211. package/src/spinner/spinnerview.d.ts +2 -2
  212. package/src/spinner/spinnerview.js +2 -2
  213. package/src/template.d.ts +3 -3
  214. package/src/template.js +3 -3
  215. package/src/textarea/textareaview.d.ts +18 -2
  216. package/src/textarea/textareaview.js +46 -6
  217. package/src/toolbar/balloon/balloontoolbar.d.ts +3 -3
  218. package/src/toolbar/balloon/balloontoolbar.js +5 -5
  219. package/src/toolbar/block/blockbuttonview.d.ts +2 -2
  220. package/src/toolbar/block/blockbuttonview.js +2 -2
  221. package/src/toolbar/block/blocktoolbar.d.ts +4 -4
  222. package/src/toolbar/block/blocktoolbar.js +6 -6
  223. package/src/toolbar/normalizetoolbarconfig.d.ts +1 -1
  224. package/src/toolbar/normalizetoolbarconfig.js +1 -1
  225. package/src/toolbar/toolbarlinebreakview.d.ts +2 -2
  226. package/src/toolbar/toolbarlinebreakview.js +2 -2
  227. package/src/toolbar/toolbarseparatorview.d.ts +2 -2
  228. package/src/toolbar/toolbarseparatorview.js +2 -2
  229. package/src/toolbar/toolbarview.d.ts +7 -6
  230. package/src/toolbar/toolbarview.js +17 -15
  231. package/src/tooltipmanager.d.ts +3 -3
  232. package/src/tooltipmanager.js +5 -4
  233. package/src/view.d.ts +3 -3
  234. package/src/view.js +3 -3
  235. package/src/viewcollection.d.ts +2 -2
  236. package/src/viewcollection.js +1 -1
  237. package/theme/components/arialiveannouncer/arialiveannouncer.css +1 -1
  238. package/theme/components/autocomplete/autocomplete.css +2 -2
  239. package/theme/components/button/button.css +1 -1
  240. package/theme/components/button/switchbutton.css +1 -1
  241. package/theme/components/collapsible/collapsible.css +1 -1
  242. package/theme/components/colorgrid/colorgrid.css +1 -1
  243. package/theme/components/colorpicker/colorpicker.css +1 -1
  244. package/theme/components/colorselector/colorselector.css +1 -1
  245. package/theme/components/dialog/dialog.css +39 -0
  246. package/theme/components/dialog/dialogactions.css +11 -0
  247. package/theme/components/dropdown/dropdown.css +3 -3
  248. package/theme/components/dropdown/listdropdown.css +1 -1
  249. package/theme/components/dropdown/splitbutton.css +1 -1
  250. package/theme/components/dropdown/toolbardropdown.css +1 -1
  251. package/theme/components/editorui/editorui.css +1 -1
  252. package/theme/components/formheader/formheader.css +1 -1
  253. package/theme/components/highlightedtext/highlightedtext.css +1 -1
  254. package/theme/components/icon/icon.css +1 -1
  255. package/theme/components/input/input.css +1 -1
  256. package/theme/components/label/label.css +1 -1
  257. package/theme/components/labeledfield/labeledfieldview.css +1 -1
  258. package/theme/components/labeledinput/labeledinput.css +1 -1
  259. package/theme/components/list/list.css +1 -1
  260. package/theme/components/panel/balloonpanel.css +2 -2
  261. package/theme/components/panel/balloonrotator.css +1 -1
  262. package/theme/components/panel/fakepanel.css +2 -2
  263. package/theme/components/panel/stickypanel.css +2 -2
  264. package/theme/components/responsive-form/responsiveform.css +1 -1
  265. package/theme/components/search/search.css +1 -1
  266. package/theme/components/spinner/spinner.css +1 -1
  267. package/theme/components/textarea/textarea.css +1 -1
  268. package/theme/components/toolbar/blocktoolbar.css +1 -1
  269. package/theme/components/toolbar/toolbar.css +1 -1
  270. package/theme/components/tooltip/tooltip.css +2 -2
  271. package/theme/globals/_hidden.css +1 -1
  272. package/theme/globals/_poweredby.css +2 -2
  273. package/theme/globals/_reset.css +1 -1
  274. package/theme/globals/_transition.css +1 -1
  275. package/theme/globals/_zindex.css +3 -2
  276. package/theme/globals/globals.css +1 -1
  277. package/theme/mixins/_dir.css +1 -1
  278. package/theme/mixins/_rwd.css +1 -1
  279. package/theme/mixins/_unselectable.css +1 -1
  280. package/theme/icons/color-palette.svg +0 -1
  281. package/theme/icons/next-arrow.svg +0 -1
  282. package/theme/icons/previous-arrow.svg +0 -1
@@ -0,0 +1,273 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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 ui/dialog/dialog
7
+ */
8
+ import type View from '../view.js';
9
+ import { type Editor, Plugin } from '@ckeditor/ckeditor5-core';
10
+ import DialogView, { DialogViewPosition } from './dialogview.js';
11
+ import type { DialogActionButtonDefinition } from './dialogactionsview.js';
12
+ /**
13
+ * The dialog controller class. It is used to show and hide the {@link module:ui/dialog/dialogview~DialogView}.
14
+ */
15
+ export default class Dialog extends Plugin {
16
+ /**
17
+ * The name of the currently visible dialog view instance.
18
+ *
19
+ * @observable
20
+ */
21
+ id: string | null;
22
+ /**
23
+ * The currently visible dialog view instance.
24
+ */
25
+ view?: DialogView;
26
+ /**
27
+ * The `Dialog` plugin instance which most recently showed the dialog.
28
+ *
29
+ * Only one dialog can be visible at once, even if there are many editor instances on the page.
30
+ * If an editor wants to show a dialog, it should first hide the dialog that is already opened.
31
+ * But only the `Dialog` instance that showed the dialog is able able to properly hide it.
32
+ * This is why we need to store it in a globally available space (static property).
33
+ * This way every `Dialog` plugin in every editor is able to correctly close any open dialog window.
34
+ */
35
+ private static _visibleDialogPlugin;
36
+ /**
37
+ * A flag indicating whether the dialog is currently visible.
38
+ *
39
+ * @observable
40
+ */
41
+ isOpen: boolean;
42
+ /**
43
+ * A configurable callback called when the dialog is hidden.
44
+ */
45
+ private _onHide;
46
+ /**
47
+ * @inheritDoc
48
+ */
49
+ static get pluginName(): "Dialog";
50
+ /**
51
+ * @inheritDoc
52
+ */
53
+ constructor(editor: Editor);
54
+ /**
55
+ * Initiates listeners for the `show` and `hide` events emitted by this plugin.
56
+ *
57
+ * We could not simply decorate the {@link #show} and {@link #hide} methods to fire events,
58
+ * because they would be fired in the wrong order – first would be `show` and then `hide`
59
+ * (because showing the dialog actually starts with hiding the previously visible one).
60
+ * Hence, we added private methods {@link #_show} and {@link #_hide} which are called on events
61
+ * in the desired sequence.
62
+ */
63
+ private _initShowHideListeners;
64
+ /**
65
+ * Initiates keystroke handler for toggling the focus between the editor and the dialog view.
66
+ */
67
+ private _initFocusToggler;
68
+ /**
69
+ * Provides an integration between the root attaching and detaching and positioning of the view.
70
+ */
71
+ private _initMultiRootIntegration;
72
+ /**
73
+ * Displays a dialog window.
74
+ *
75
+ * This method requires a {@link ~DialogDefinition} that defines the dialog's content, title, icon, action buttons, etc.
76
+ *
77
+ * For example, the following definition will create a dialog with:
78
+ * * A header consisting of an icon, a title, and a "Close" button (it is added by default).
79
+ * * A content consisting of a view with a single paragraph.
80
+ * * A footer consisting of two buttons: "Yes" and "No".
81
+ *
82
+ * ```js
83
+ * // Create the view that will be used as the dialog's content.
84
+ * const textView = new View( locale );
85
+ *
86
+ * textView.setTemplate( {
87
+ * tag: 'div',
88
+ * attributes: {
89
+ * style: {
90
+ * padding: 'var(--ck-spacing-large)',
91
+ * whiteSpace: 'initial',
92
+ * width: '100%',
93
+ * maxWidth: '500px'
94
+ * },
95
+ * tabindex: -1
96
+ * },
97
+ * children: [
98
+ * 'Lorem ipsum dolor sit amet...'
99
+ * ]
100
+ * } );
101
+ *
102
+ * // Show the dialog.
103
+ * editor.plugins.get( 'Dialog' ).show( {
104
+ * id: 'myDialog',
105
+ * icon: 'myIcon', // This should be an SVG string.
106
+ * title: 'My dialog',
107
+ * content: textView,
108
+ * actionButtons: [
109
+ * {
110
+ * label: t( 'Yes' ),
111
+ * class: 'ck-button-action',
112
+ * withText: true,
113
+ * onExecute: () => dialog.hide()
114
+ * },
115
+ * {
116
+ * label: t( 'No' ),
117
+ * withText: true,
118
+ * onExecute: () => dialog.hide()
119
+ * }
120
+ * ]
121
+ * } );
122
+ * ```
123
+ *
124
+ * By specifying the {@link ~DialogDefinition#onShow} and {@link ~DialogDefinition#onHide} callbacks
125
+ * it is also possible to add callbacks that will be called when the dialog is shown or hidden.
126
+ *
127
+ * For example, the callbacks in the following definition:
128
+ * * Disable the default behavior of the <kbd>Esc</kbd> key.
129
+ * * Fire a custom event when the dialog gets hidden.
130
+ *
131
+ * ```js
132
+ * editor.plugins.get( 'Dialog' ).show( {
133
+ * // ...
134
+ * onShow: dialog => {
135
+ * dialog.view.on( 'close', ( evt, data ) => {
136
+ * // Only prevent the event from the "Esc" key - do not affect the other ways of closing the dialog.
137
+ * if ( data.source === 'escKeyPress' ) {
138
+ * evt.stop();
139
+ * }
140
+ * } );
141
+ * },
142
+ * onHide: dialog => {
143
+ * dialog.fire( 'dialogDestroyed' );
144
+ * }
145
+ * } );
146
+ * ```
147
+ *
148
+ * Internally, calling this method:
149
+ * 1. Hides the currently visible dialog (if any) calling the {@link #hide} method
150
+ * (fires the {@link ~DialogHideEvent hide event}).
151
+ * 2. Fires the {@link ~DialogShowEvent show event} which allows for adding callbacks that customize the
152
+ * behavior of the dialog.
153
+ * 3. Shows the dialog.
154
+ */
155
+ show(dialogDefinition: DialogDefinition): void;
156
+ /**
157
+ * Handles creating the {@link module:ui/dialog/dialogview~DialogView} instance and making it visible.
158
+ */
159
+ private _show;
160
+ /**
161
+ * Hides the dialog. This method is decorated to enable interacting on the {@link ~DialogHideEvent hide event}.
162
+ *
163
+ * See {@link #show}.
164
+ */
165
+ hide(): void;
166
+ /**
167
+ * Destroys the {@link module:ui/dialog/dialogview~DialogView} and cleans up the stored dialog state.
168
+ */
169
+ private _hide;
170
+ }
171
+ /**
172
+ * The definition that describes a dialog window and its content. Passed to the {@link module:ui/dialog/dialog~Dialog#show} method.
173
+ */
174
+ export interface DialogDefinition {
175
+ /**
176
+ * A unique identifier of the dialog. It allows for distinguishing between different dialogs and their visibility.
177
+ * For instance, when open, the ID of the currently visible dialog is stored in {@link module:ui/dialog/dialog~Dialog#id}.
178
+ *
179
+ * The `id` is also passed along the {@link module:ui/dialog/dialog~DialogShowEvent} and {@link module:ui/dialog/dialog~DialogHideEvent}
180
+ * events.
181
+ */
182
+ id: string;
183
+ /**
184
+ * The SVG string of an icon displayed in dialogs's header. Used only when {@link #title} is also set
185
+ * and the header is displayed.
186
+ *
187
+ * See more in {@link module:ui/icon/iconview~IconView#content}.
188
+ */
189
+ icon?: string;
190
+ /**
191
+ * A title displayed in the dialogs's header. It also works as an accessible name of the dialog used by assistive technologies.
192
+ *
193
+ * When not set, the header is not displayed. Affects {@link #icon} and {@link #hasCloseButton}.
194
+ */
195
+ title?: string;
196
+ /**
197
+ * A flag indicating whether the dialog should have a close button in the header.
198
+ * `true` by default. Works when {@link #title} is also set and the header is displayed.
199
+ *
200
+ * **Note**: If you hide the close button, make sure that the dialog can be closed in another way.
201
+ */
202
+ hasCloseButton?: boolean;
203
+ /**
204
+ * The content of the dialog. It can be a single {@link module:ui/view~View} or an array of views.
205
+ */
206
+ content?: View | Array<View>;
207
+ /**
208
+ * The action buttons displayed in the dialog's footer.
209
+ */
210
+ actionButtons?: Array<DialogActionButtonDefinition>;
211
+ /**
212
+ * An additional CSS class set on the outermost (`.ck.ck-dialog`) container element allowing for visual customization.
213
+ */
214
+ className?: string;
215
+ /**
216
+ * When set to `true`, the dialog will become a modal, that is, it will block the UI until it is closed.
217
+ */
218
+ isModal?: boolean;
219
+ /**
220
+ * Available dialog positions. By default `DialogViewPosition.EDITOR_CENTER` is used for {@link #isModal non-modals}
221
+ * and `DialogViewPosition.SCREEN_CENTER` for modals.
222
+ *
223
+ * {@link module:ui/dialog/dialogview#DialogViewPosition Learn more} about available positions.
224
+ */
225
+ position?: typeof DialogViewPosition[keyof typeof DialogViewPosition];
226
+ /**
227
+ * A callback called when the dialog shows up with a `low` priority. It allows for setting up the dialog's {@link #content}.
228
+ */
229
+ onShow?: (dialog: Dialog) => void;
230
+ /**
231
+ * A callback called when the dialog hides with a `low` priority.
232
+ * It allows for cleaning up (for example, resetting) the dialog's {@link #content}.
233
+ */
234
+ onHide?: (dialog: Dialog) => void;
235
+ }
236
+ /**
237
+ * An event fired after {@link module:ui/dialog/dialog~Dialog#show} is called. You can use it to customize the behavior
238
+ * of any dialog.
239
+ *
240
+ * ```js
241
+ * import { DialogViewPosition } from 'ckeditor5/src/ui.js';
242
+ *
243
+ * // ...
244
+ *
245
+ * // Changes the position of the "Find and Replace" dialog.
246
+ * editor.plugins.get( 'Dialog' ).on( 'show:findAndReplace', ( evt, data ) => {
247
+ * Object.assign( data, { position: DialogViewPosition.EDITOR_BOTTOM_CENTER } );
248
+ * }, { priority: 'high' } );
249
+ * ```
250
+ *
251
+ * @eventName ~Dialog#show
252
+ */
253
+ export type DialogShowEvent = {
254
+ name: 'show' | `show:${string}`;
255
+ args: [dialogDefinition: DialogDefinition];
256
+ };
257
+ /**
258
+ * An event fired after {@link module:ui/dialog/dialog~Dialog#hide} is called. You can use it to customize the behavior
259
+ * of any dialog.
260
+ *
261
+ * ```js
262
+ * // Logs after the "Find and Replace" dialog gets hidden
263
+ * editor.plugins.get( 'Dialog' ).on( 'hide:findAndReplace', () => {
264
+ * console.log( 'The "Find and Replace" dialog was hidden.' );
265
+ * } );
266
+ * ```
267
+ *
268
+ * @eventName ~Dialog#hide
269
+ */
270
+ export type DialogHideEvent = {
271
+ name: 'hide' | `hide:${string}`;
272
+ args: [];
273
+ };
@@ -0,0 +1,261 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ import { Plugin } from '@ckeditor/ckeditor5-core';
6
+ import DialogView, { DialogViewPosition } from './dialogview.js';
7
+ /**
8
+ * The dialog controller class. It is used to show and hide the {@link module:ui/dialog/dialogview~DialogView}.
9
+ */
10
+ export default class Dialog extends Plugin {
11
+ /**
12
+ * @inheritDoc
13
+ */
14
+ static get pluginName() {
15
+ return 'Dialog';
16
+ }
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ constructor(editor) {
21
+ super(editor);
22
+ this._initShowHideListeners();
23
+ this._initFocusToggler();
24
+ this._initMultiRootIntegration();
25
+ this.set('id', null);
26
+ }
27
+ /**
28
+ * Initiates listeners for the `show` and `hide` events emitted by this plugin.
29
+ *
30
+ * We could not simply decorate the {@link #show} and {@link #hide} methods to fire events,
31
+ * because they would be fired in the wrong order &ndash; first would be `show` and then `hide`
32
+ * (because showing the dialog actually starts with hiding the previously visible one).
33
+ * Hence, we added private methods {@link #_show} and {@link #_hide} which are called on events
34
+ * in the desired sequence.
35
+ */
36
+ _initShowHideListeners() {
37
+ this.on('show', (evt, args) => {
38
+ this._show(args);
39
+ });
40
+ // 'low' priority allows to add custom callback between `_show()` and `onShow()`.
41
+ this.on('show', (evt, args) => {
42
+ if (args.onShow) {
43
+ args.onShow(this);
44
+ }
45
+ }, { priority: 'low' });
46
+ this.on('hide', () => {
47
+ if (Dialog._visibleDialogPlugin) {
48
+ Dialog._visibleDialogPlugin._hide();
49
+ }
50
+ });
51
+ // 'low' priority allows to add custom callback between `_hide()` and `onHide()`.
52
+ this.on('hide', () => {
53
+ if (this._onHide) {
54
+ this._onHide(this);
55
+ this._onHide = undefined;
56
+ }
57
+ }, { priority: 'low' });
58
+ }
59
+ /**
60
+ * Initiates keystroke handler for toggling the focus between the editor and the dialog view.
61
+ */
62
+ _initFocusToggler() {
63
+ const editor = this.editor;
64
+ editor.keystrokes.set('Ctrl+F6', (data, cancel) => {
65
+ if (!this.isOpen || this.view.isModal) {
66
+ return;
67
+ }
68
+ if (this.view.focusTracker.isFocused) {
69
+ editor.editing.view.focus();
70
+ }
71
+ else {
72
+ this.view.focus();
73
+ }
74
+ cancel();
75
+ });
76
+ }
77
+ /**
78
+ * Provides an integration between the root attaching and detaching and positioning of the view.
79
+ */
80
+ _initMultiRootIntegration() {
81
+ const model = this.editor.model;
82
+ model.document.on('change:data', () => {
83
+ if (!this.view) {
84
+ return;
85
+ }
86
+ const changedRoots = model.document.differ.getChangedRoots();
87
+ for (const changes of changedRoots) {
88
+ if (changes.state) {
89
+ this.view.updatePosition();
90
+ }
91
+ }
92
+ });
93
+ }
94
+ /**
95
+ * Displays a dialog window.
96
+ *
97
+ * This method requires a {@link ~DialogDefinition} that defines the dialog's content, title, icon, action buttons, etc.
98
+ *
99
+ * For example, the following definition will create a dialog with:
100
+ * * A header consisting of an icon, a title, and a "Close" button (it is added by default).
101
+ * * A content consisting of a view with a single paragraph.
102
+ * * A footer consisting of two buttons: "Yes" and "No".
103
+ *
104
+ * ```js
105
+ * // Create the view that will be used as the dialog's content.
106
+ * const textView = new View( locale );
107
+ *
108
+ * textView.setTemplate( {
109
+ * tag: 'div',
110
+ * attributes: {
111
+ * style: {
112
+ * padding: 'var(--ck-spacing-large)',
113
+ * whiteSpace: 'initial',
114
+ * width: '100%',
115
+ * maxWidth: '500px'
116
+ * },
117
+ * tabindex: -1
118
+ * },
119
+ * children: [
120
+ * 'Lorem ipsum dolor sit amet...'
121
+ * ]
122
+ * } );
123
+ *
124
+ * // Show the dialog.
125
+ * editor.plugins.get( 'Dialog' ).show( {
126
+ * id: 'myDialog',
127
+ * icon: 'myIcon', // This should be an SVG string.
128
+ * title: 'My dialog',
129
+ * content: textView,
130
+ * actionButtons: [
131
+ * {
132
+ * label: t( 'Yes' ),
133
+ * class: 'ck-button-action',
134
+ * withText: true,
135
+ * onExecute: () => dialog.hide()
136
+ * },
137
+ * {
138
+ * label: t( 'No' ),
139
+ * withText: true,
140
+ * onExecute: () => dialog.hide()
141
+ * }
142
+ * ]
143
+ * } );
144
+ * ```
145
+ *
146
+ * By specifying the {@link ~DialogDefinition#onShow} and {@link ~DialogDefinition#onHide} callbacks
147
+ * it is also possible to add callbacks that will be called when the dialog is shown or hidden.
148
+ *
149
+ * For example, the callbacks in the following definition:
150
+ * * Disable the default behavior of the <kbd>Esc</kbd> key.
151
+ * * Fire a custom event when the dialog gets hidden.
152
+ *
153
+ * ```js
154
+ * editor.plugins.get( 'Dialog' ).show( {
155
+ * // ...
156
+ * onShow: dialog => {
157
+ * dialog.view.on( 'close', ( evt, data ) => {
158
+ * // Only prevent the event from the "Esc" key - do not affect the other ways of closing the dialog.
159
+ * if ( data.source === 'escKeyPress' ) {
160
+ * evt.stop();
161
+ * }
162
+ * } );
163
+ * },
164
+ * onHide: dialog => {
165
+ * dialog.fire( 'dialogDestroyed' );
166
+ * }
167
+ * } );
168
+ * ```
169
+ *
170
+ * Internally, calling this method:
171
+ * 1. Hides the currently visible dialog (if any) calling the {@link #hide} method
172
+ * (fires the {@link ~DialogHideEvent hide event}).
173
+ * 2. Fires the {@link ~DialogShowEvent show event} which allows for adding callbacks that customize the
174
+ * behavior of the dialog.
175
+ * 3. Shows the dialog.
176
+ */
177
+ show(dialogDefinition) {
178
+ this.hide();
179
+ this.fire(`show:${dialogDefinition.id}`, dialogDefinition);
180
+ }
181
+ /**
182
+ * Handles creating the {@link module:ui/dialog/dialogview~DialogView} instance and making it visible.
183
+ */
184
+ _show({ id, icon, title, hasCloseButton = true, content, actionButtons, className, isModal, position, onHide }) {
185
+ const editor = this.editor;
186
+ this.view = new DialogView(editor.locale, {
187
+ getCurrentDomRoot: () => {
188
+ return editor.editing.view.getDomRoot(editor.model.document.selection.anchor.root.rootName);
189
+ },
190
+ getViewportOffset: () => {
191
+ return editor.ui.viewportOffset;
192
+ }
193
+ });
194
+ const view = this.view;
195
+ view.on('close', () => {
196
+ this.hide();
197
+ });
198
+ editor.ui.view.body.add(view);
199
+ editor.ui.focusTracker.add(view.element);
200
+ editor.keystrokes.listenTo(view.element);
201
+ // Unless the user specified a position, modals should always be centered on the screen.
202
+ // Otherwise, let's keep dialogs centered in the editing root by default.
203
+ if (!position) {
204
+ position = isModal ? DialogViewPosition.SCREEN_CENTER : DialogViewPosition.EDITOR_CENTER;
205
+ }
206
+ view.set({
207
+ position,
208
+ _isVisible: true,
209
+ className,
210
+ isModal
211
+ });
212
+ view.setupParts({
213
+ icon,
214
+ title,
215
+ hasCloseButton,
216
+ content,
217
+ actionButtons
218
+ });
219
+ this.id = id;
220
+ if (onHide) {
221
+ this._onHide = onHide;
222
+ }
223
+ this.isOpen = true;
224
+ Dialog._visibleDialogPlugin = this;
225
+ }
226
+ /**
227
+ * Hides the dialog. This method is decorated to enable interacting on the {@link ~DialogHideEvent hide event}.
228
+ *
229
+ * See {@link #show}.
230
+ */
231
+ hide() {
232
+ if (Dialog._visibleDialogPlugin) {
233
+ Dialog._visibleDialogPlugin.fire(`hide:${Dialog._visibleDialogPlugin.id}`);
234
+ }
235
+ }
236
+ /**
237
+ * Destroys the {@link module:ui/dialog/dialogview~DialogView} and cleans up the stored dialog state.
238
+ */
239
+ _hide() {
240
+ if (!this.view) {
241
+ return;
242
+ }
243
+ const editor = this.editor;
244
+ const view = this.view;
245
+ // Reset the content view to prevent its children from being destroyed in the standard
246
+ // View#destroy() (and collections) chain. If the content children were left in there,
247
+ // they would have to be re-created by the feature using the dialog every time the dialog
248
+ // shows up.
249
+ if (view.contentView) {
250
+ view.contentView.reset();
251
+ }
252
+ editor.ui.view.body.remove(view);
253
+ editor.ui.focusTracker.remove(view.element);
254
+ editor.keystrokes.stopListening(view.element);
255
+ view.destroy();
256
+ editor.editing.view.focus();
257
+ this.id = null;
258
+ this.isOpen = false;
259
+ Dialog._visibleDialogPlugin = null;
260
+ }
261
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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 ui/dialog/dialogactionsview
7
+ */
8
+ import { KeystrokeHandler, type Locale } from '@ckeditor/ckeditor5-utils';
9
+ import type { default as Button } from '../button/button.js';
10
+ import ButtonView from '../button/buttonview.js';
11
+ import View from '../view.js';
12
+ import ViewCollection from '../viewcollection.js';
13
+ import FocusCycler, { type FocusableView } from '../focuscycler.js';
14
+ import '../../theme/components/dialog/dialogactions.css';
15
+ /**
16
+ * A dialog actions view class. It contains button views which are used to execute dialog actions.
17
+ */
18
+ export default class DialogActionsView extends View {
19
+ /**
20
+ * A collection of button views.
21
+ */
22
+ readonly children: ViewCollection<FocusableView>;
23
+ /**
24
+ * A keystroke handler instance.
25
+ */
26
+ readonly keystrokes: KeystrokeHandler;
27
+ /**
28
+ * A focus cycler instance.
29
+ */
30
+ readonly focusCycler: FocusCycler;
31
+ /**
32
+ * A focus tracker instance.
33
+ */
34
+ private readonly _focusTracker;
35
+ /**
36
+ * A collection of focusable views.
37
+ */
38
+ private readonly _focusables;
39
+ /**
40
+ * @inheritDoc
41
+ */
42
+ constructor(locale?: Locale);
43
+ /**
44
+ * @inheritDoc
45
+ */
46
+ render(): void;
47
+ /**
48
+ * Creates the button views based on the given definitions.
49
+ * Then adds them to the {@link #children} collection and to the focus cycler.
50
+ */
51
+ setButtons(definitions: Array<DialogActionButtonDefinition>): void;
52
+ /**
53
+ * @inheritDoc
54
+ */
55
+ focus(direction?: 1 | -1): void;
56
+ /**
57
+ * Adds all elements from the {@link #children} collection to the {@link #_focusables} collection
58
+ * and to the {@link #_focusTracker} instance.
59
+ */
60
+ private _updateFocusCyclableItems;
61
+ }
62
+ /**
63
+ * A dialog action button definition. It is a slightly modified version
64
+ * of the {@link module:ui/button/button~Button} definition.
65
+ */
66
+ export type DialogActionButtonDefinition = Pick<Button, 'label'> & Partial<Pick<Button, 'withText' | 'class' | 'icon'>> & {
67
+ onExecute: Function;
68
+ onCreate?: (button: ButtonView) => void;
69
+ };
@@ -0,0 +1,98 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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 ui/dialog/dialogactionsview
7
+ */
8
+ import { FocusTracker, KeystrokeHandler } from '@ckeditor/ckeditor5-utils';
9
+ import ButtonView from '../button/buttonview.js';
10
+ import View from '../view.js';
11
+ import ViewCollection from '../viewcollection.js';
12
+ import FocusCycler from '../focuscycler.js';
13
+ import '../../theme/components/dialog/dialogactions.css';
14
+ /**
15
+ * A dialog actions view class. It contains button views which are used to execute dialog actions.
16
+ */
17
+ export default class DialogActionsView extends View {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ constructor(locale) {
22
+ super(locale);
23
+ this.children = this.createCollection();
24
+ this.keystrokes = new KeystrokeHandler();
25
+ this._focusTracker = new FocusTracker();
26
+ this._focusables = new ViewCollection();
27
+ this.focusCycler = new FocusCycler({
28
+ focusables: this._focusables,
29
+ focusTracker: this._focusTracker,
30
+ keystrokeHandler: this.keystrokes,
31
+ actions: {
32
+ // Navigate form fields backwards using the Shift + Tab keystroke.
33
+ focusPrevious: 'shift + tab',
34
+ // Navigate form fields forwards using the Tab key.
35
+ focusNext: 'tab'
36
+ }
37
+ });
38
+ this.setTemplate({
39
+ tag: 'div',
40
+ attributes: {
41
+ class: [
42
+ 'ck',
43
+ 'ck-dialog__actions'
44
+ ]
45
+ },
46
+ children: this.children
47
+ });
48
+ }
49
+ /**
50
+ * @inheritDoc
51
+ */
52
+ render() {
53
+ super.render();
54
+ this.keystrokes.listenTo(this.element);
55
+ }
56
+ /**
57
+ * Creates the button views based on the given definitions.
58
+ * Then adds them to the {@link #children} collection and to the focus cycler.
59
+ */
60
+ setButtons(definitions) {
61
+ for (const definition of definitions) {
62
+ const button = new ButtonView(this.locale);
63
+ let property;
64
+ button.on('execute', () => definition.onExecute());
65
+ if (definition.onCreate) {
66
+ definition.onCreate(button);
67
+ }
68
+ for (property in definition) {
69
+ if (property != 'onExecute' && property != 'onCreate') {
70
+ button.set(property, definition[property]);
71
+ }
72
+ }
73
+ this.children.add(button);
74
+ }
75
+ this._updateFocusCyclableItems();
76
+ }
77
+ /**
78
+ * @inheritDoc
79
+ */
80
+ focus(direction) {
81
+ if (direction === -1) {
82
+ this.focusCycler.focusLast();
83
+ }
84
+ else {
85
+ this.focusCycler.focusFirst();
86
+ }
87
+ }
88
+ /**
89
+ * Adds all elements from the {@link #children} collection to the {@link #_focusables} collection
90
+ * and to the {@link #_focusTracker} instance.
91
+ */
92
+ _updateFocusCyclableItems() {
93
+ Array.from(this.children).forEach(v => {
94
+ this._focusables.add(v);
95
+ this._focusTracker.add(v.element);
96
+ });
97
+ }
98
+ }