@ckeditor/ckeditor5-engine 36.0.1 → 37.0.0-alpha.1

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 (203) hide show
  1. package/README.md +1 -1
  2. package/package.json +25 -24
  3. package/src/controller/datacontroller.d.ts +331 -0
  4. package/src/controller/datacontroller.js +72 -116
  5. package/src/controller/editingcontroller.d.ts +98 -0
  6. package/src/controller/editingcontroller.js +22 -46
  7. package/src/conversion/conversion.d.ts +476 -0
  8. package/src/conversion/conversion.js +328 -347
  9. package/src/conversion/conversionhelpers.d.ts +26 -0
  10. package/src/conversion/conversionhelpers.js +1 -5
  11. package/src/conversion/downcastdispatcher.d.ts +547 -0
  12. package/src/conversion/downcastdispatcher.js +74 -152
  13. package/src/conversion/downcasthelpers.d.ts +1226 -0
  14. package/src/conversion/downcasthelpers.js +843 -762
  15. package/src/conversion/mapper.d.ts +503 -0
  16. package/src/conversion/mapper.js +84 -99
  17. package/src/conversion/modelconsumable.d.ts +201 -0
  18. package/src/conversion/modelconsumable.js +96 -99
  19. package/src/conversion/upcastdispatcher.d.ts +492 -0
  20. package/src/conversion/upcastdispatcher.js +73 -100
  21. package/src/conversion/upcasthelpers.d.ts +499 -0
  22. package/src/conversion/upcasthelpers.js +406 -373
  23. package/src/conversion/viewconsumable.d.ts +369 -0
  24. package/src/conversion/viewconsumable.js +139 -173
  25. package/src/dataprocessor/basichtmlwriter.d.ts +18 -0
  26. package/src/dataprocessor/basichtmlwriter.js +0 -9
  27. package/src/dataprocessor/dataprocessor.d.ts +61 -0
  28. package/src/dataprocessor/htmldataprocessor.d.ts +76 -0
  29. package/src/dataprocessor/htmldataprocessor.js +6 -28
  30. package/src/dataprocessor/htmlwriter.d.ts +16 -0
  31. package/src/dataprocessor/xmldataprocessor.d.ts +90 -0
  32. package/src/dataprocessor/xmldataprocessor.js +8 -40
  33. package/src/dev-utils/model.d.ts +124 -0
  34. package/src/dev-utils/model.js +41 -38
  35. package/src/dev-utils/operationreplayer.d.ts +51 -0
  36. package/src/dev-utils/operationreplayer.js +6 -14
  37. package/src/dev-utils/utils.d.ts +37 -0
  38. package/src/dev-utils/utils.js +5 -18
  39. package/src/dev-utils/view.d.ts +319 -0
  40. package/src/dev-utils/view.js +205 -226
  41. package/src/index.d.ts +108 -0
  42. package/src/index.js +4 -0
  43. package/src/model/batch.d.ts +106 -0
  44. package/src/model/differ.d.ts +329 -0
  45. package/src/model/document.d.ts +246 -0
  46. package/src/model/document.js +1 -1
  47. package/src/model/documentfragment.d.ts +196 -0
  48. package/src/model/documentfragment.js +2 -2
  49. package/src/model/documentselection.d.ts +420 -0
  50. package/src/model/element.d.ts +165 -0
  51. package/src/model/history.d.ts +114 -0
  52. package/src/model/item.d.ts +14 -0
  53. package/src/model/liveposition.d.ts +77 -0
  54. package/src/model/liverange.d.ts +102 -0
  55. package/src/model/markercollection.d.ts +335 -0
  56. package/src/model/model.d.ts +885 -0
  57. package/src/model/model.js +59 -81
  58. package/src/model/node.d.ts +256 -0
  59. package/src/model/nodelist.d.ts +91 -0
  60. package/src/model/operation/attributeoperation.d.ts +98 -0
  61. package/src/model/operation/detachoperation.d.ts +55 -0
  62. package/src/model/operation/insertoperation.d.ts +85 -0
  63. package/src/model/operation/markeroperation.d.ts +86 -0
  64. package/src/model/operation/mergeoperation.d.ts +95 -0
  65. package/src/model/operation/mergeoperation.js +1 -1
  66. package/src/model/operation/moveoperation.d.ts +91 -0
  67. package/src/model/operation/nooperation.d.ts +33 -0
  68. package/src/model/operation/operation.d.ts +89 -0
  69. package/src/model/operation/operationfactory.d.ts +18 -0
  70. package/src/model/operation/renameoperation.d.ts +78 -0
  71. package/src/model/operation/rootattributeoperation.d.ts +97 -0
  72. package/src/model/operation/rootattributeoperation.js +1 -1
  73. package/src/model/operation/splitoperation.d.ts +104 -0
  74. package/src/model/operation/splitoperation.js +1 -1
  75. package/src/model/operation/transform.d.ts +100 -0
  76. package/src/model/operation/utils.d.ts +71 -0
  77. package/src/model/operation/utils.js +1 -1
  78. package/src/model/position.d.ts +539 -0
  79. package/src/model/position.js +1 -1
  80. package/src/model/range.d.ts +458 -0
  81. package/src/model/range.js +1 -1
  82. package/src/model/rootelement.d.ts +40 -0
  83. package/src/model/schema.d.ts +1176 -0
  84. package/src/model/schema.js +19 -19
  85. package/src/model/selection.d.ts +472 -0
  86. package/src/model/text.d.ts +66 -0
  87. package/src/model/text.js +0 -2
  88. package/src/model/textproxy.d.ts +144 -0
  89. package/src/model/treewalker.d.ts +186 -0
  90. package/src/model/treewalker.js +19 -10
  91. package/src/model/typecheckable.d.ts +285 -0
  92. package/src/model/utils/autoparagraphing.d.ts +37 -0
  93. package/src/model/utils/deletecontent.d.ts +58 -0
  94. package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
  95. package/src/model/utils/getselectedcontent.d.ts +30 -0
  96. package/src/model/utils/insertcontent.d.ts +46 -0
  97. package/src/model/utils/insertcontent.js +2 -12
  98. package/src/model/utils/insertobject.d.ts +44 -0
  99. package/src/model/utils/insertobject.js +3 -14
  100. package/src/model/utils/modifyselection.d.ts +48 -0
  101. package/src/model/utils/selection-post-fixer.d.ts +65 -0
  102. package/src/model/writer.d.ts +823 -0
  103. package/src/model/writer.js +6 -61
  104. package/src/view/attributeelement.d.ts +108 -0
  105. package/src/view/attributeelement.js +25 -69
  106. package/src/view/containerelement.d.ts +49 -0
  107. package/src/view/containerelement.js +10 -43
  108. package/src/view/datatransfer.d.ts +75 -0
  109. package/src/view/document.d.ts +184 -0
  110. package/src/view/document.js +15 -84
  111. package/src/view/documentfragment.d.ts +149 -0
  112. package/src/view/documentfragment.js +39 -81
  113. package/src/view/documentselection.d.ts +306 -0
  114. package/src/view/documentselection.js +42 -143
  115. package/src/view/domconverter.d.ts +650 -0
  116. package/src/view/domconverter.js +157 -283
  117. package/src/view/downcastwriter.d.ts +996 -0
  118. package/src/view/downcastwriter.js +259 -426
  119. package/src/view/editableelement.d.ts +52 -0
  120. package/src/view/editableelement.js +9 -49
  121. package/src/view/element.d.ts +468 -0
  122. package/src/view/element.js +150 -222
  123. package/src/view/elementdefinition.d.ts +87 -0
  124. package/src/view/emptyelement.d.ts +41 -0
  125. package/src/view/emptyelement.js +11 -44
  126. package/src/view/filler.d.ts +111 -0
  127. package/src/view/filler.js +24 -21
  128. package/src/view/item.d.ts +14 -0
  129. package/src/view/matcher.d.ts +486 -0
  130. package/src/view/matcher.js +247 -218
  131. package/src/view/node.d.ts +163 -0
  132. package/src/view/node.js +26 -100
  133. package/src/view/observer/arrowkeysobserver.d.ts +41 -0
  134. package/src/view/observer/arrowkeysobserver.js +0 -13
  135. package/src/view/observer/bubblingemittermixin.d.ts +166 -0
  136. package/src/view/observer/bubblingemittermixin.js +36 -25
  137. package/src/view/observer/bubblingeventinfo.d.ts +47 -0
  138. package/src/view/observer/bubblingeventinfo.js +3 -29
  139. package/src/view/observer/clickobserver.d.ts +43 -0
  140. package/src/view/observer/clickobserver.js +9 -19
  141. package/src/view/observer/compositionobserver.d.ts +82 -0
  142. package/src/view/observer/compositionobserver.js +13 -42
  143. package/src/view/observer/domeventdata.d.ts +50 -0
  144. package/src/view/observer/domeventdata.js +5 -30
  145. package/src/view/observer/domeventobserver.d.ts +69 -0
  146. package/src/view/observer/domeventobserver.js +19 -21
  147. package/src/view/observer/fakeselectionobserver.d.ts +43 -0
  148. package/src/view/observer/fakeselectionobserver.js +0 -16
  149. package/src/view/observer/focusobserver.d.ts +82 -0
  150. package/src/view/observer/focusobserver.js +14 -40
  151. package/src/view/observer/inputobserver.d.ts +86 -0
  152. package/src/view/observer/inputobserver.js +18 -64
  153. package/src/view/observer/keyobserver.d.ts +66 -0
  154. package/src/view/observer/keyobserver.js +8 -42
  155. package/src/view/observer/mouseobserver.d.ts +89 -0
  156. package/src/view/observer/mouseobserver.js +8 -28
  157. package/src/view/observer/mutationobserver.d.ts +82 -0
  158. package/src/view/observer/mutationobserver.js +7 -37
  159. package/src/view/observer/observer.d.ts +84 -0
  160. package/src/view/observer/observer.js +12 -25
  161. package/src/view/observer/selectionobserver.d.ts +144 -0
  162. package/src/view/observer/selectionobserver.js +17 -107
  163. package/src/view/observer/tabobserver.d.ts +42 -0
  164. package/src/view/observer/tabobserver.js +0 -14
  165. package/src/view/placeholder.d.ts +85 -0
  166. package/src/view/placeholder.js +26 -43
  167. package/src/view/position.d.ts +189 -0
  168. package/src/view/position.js +36 -83
  169. package/src/view/range.d.ts +279 -0
  170. package/src/view/range.js +79 -122
  171. package/src/view/rawelement.d.ts +73 -0
  172. package/src/view/rawelement.js +34 -48
  173. package/src/view/renderer.d.ts +265 -0
  174. package/src/view/renderer.js +105 -193
  175. package/src/view/rooteditableelement.d.ts +41 -0
  176. package/src/view/rooteditableelement.js +12 -40
  177. package/src/view/selection.d.ts +375 -0
  178. package/src/view/selection.js +79 -153
  179. package/src/view/styles/background.d.ts +33 -0
  180. package/src/view/styles/background.js +14 -12
  181. package/src/view/styles/border.d.ts +43 -0
  182. package/src/view/styles/border.js +58 -48
  183. package/src/view/styles/margin.d.ts +29 -0
  184. package/src/view/styles/margin.js +13 -11
  185. package/src/view/styles/padding.d.ts +29 -0
  186. package/src/view/styles/padding.js +13 -11
  187. package/src/view/styles/utils.d.ts +93 -0
  188. package/src/view/styles/utils.js +22 -48
  189. package/src/view/stylesmap.d.ts +675 -0
  190. package/src/view/stylesmap.js +249 -244
  191. package/src/view/text.d.ts +74 -0
  192. package/src/view/text.js +16 -46
  193. package/src/view/textproxy.d.ts +97 -0
  194. package/src/view/textproxy.js +10 -59
  195. package/src/view/treewalker.d.ts +195 -0
  196. package/src/view/treewalker.js +43 -106
  197. package/src/view/typecheckable.d.ts +448 -0
  198. package/src/view/uielement.d.ts +96 -0
  199. package/src/view/uielement.js +29 -63
  200. package/src/view/upcastwriter.d.ts +417 -0
  201. package/src/view/upcastwriter.js +86 -157
  202. package/src/view/view.d.ts +417 -0
  203. package/src/view/view.js +47 -175
@@ -20,91 +20,20 @@ import FocusObserver from './focusobserver';
20
20
  * This observer also manages the {@link module:engine/view/document~Document#isSelecting} property of the view document.
21
21
  *
22
22
  * Note that this observer is attached by the {@link module:engine/view/view~View} and is available by default.
23
- *
24
- * @extends module:engine/view/observer/observer~Observer
25
23
  */
26
24
  export default class SelectionObserver extends Observer {
27
25
  constructor(view) {
28
26
  super(view);
29
- /**
30
- * Instance of the mutation observer. Selection observer calls
31
- * {@link module:engine/view/observer/mutationobserver~MutationObserver#flush} to ensure that the mutations will be handled
32
- * before the {@link module:engine/view/document~Document#event:selectionChange} event is fired.
33
- *
34
- * @readonly
35
- * @member {module:engine/view/observer/mutationobserver~MutationObserver}
36
- * module:engine/view/observer/selectionobserver~SelectionObserver#mutationObserver
37
- */
38
27
  this.mutationObserver = view.getObserver(MutationObserver);
39
- /**
40
- * Instance of the focus observer. Selection observer calls
41
- * {@link module:engine/view/observer/focusobserver~FocusObserver#flush} to mark the latest focus change as complete.
42
- *
43
- * @readonly
44
- * @member {module:engine/view/observer/focusobserver~FocusObserver}
45
- * module:engine/view/observer/focusobserver~FocusObserver#focusObserver
46
- */
47
28
  this.focusObserver = view.getObserver(FocusObserver);
48
- /**
49
- * Reference to the view {@link module:engine/view/documentselection~DocumentSelection} object used to compare
50
- * new selection with it.
51
- *
52
- * @readonly
53
- * @member {module:engine/view/documentselection~DocumentSelection}
54
- * module:engine/view/observer/selectionobserver~SelectionObserver#selection
55
- */
56
29
  this.selection = this.document.selection;
57
- /* eslint-disable max-len */
58
- /**
59
- * Reference to the {@link module:engine/view/view~View#domConverter}.
60
- *
61
- * @readonly
62
- * @member {module:engine/view/domconverter~DomConverter} module:engine/view/observer/selectionobserver~SelectionObserver#domConverter
63
- */
64
- /* eslint-enable max-len */
65
30
  this.domConverter = view.domConverter;
66
- /**
67
- * A set of documents which have added `selectionchange` listener to avoid adding a listener twice to the same
68
- * document.
69
- *
70
- * @private
71
- * @member {WeakSet.<Document>} module:engine/view/observer/selectionobserver~SelectionObserver#_documents
72
- */
73
31
  this._documents = new WeakSet();
74
- /**
75
- * Fires debounced event `selectionChangeDone`. It uses `lodash#debounce` method to delay function call.
76
- *
77
- * @private
78
- * @param {Object} data Selection change data.
79
- * @method #_fireSelectionChangeDoneDebounced
80
- */
81
32
  this._fireSelectionChangeDoneDebounced = debounce(data => {
82
33
  this.document.fire('selectionChangeDone', data);
83
34
  }, 200);
84
- /**
85
- * When called, starts clearing the {@link #_loopbackCounter} counter in time intervals. When the number of selection
86
- * changes exceeds a certain limit within the interval of time, the observer will not fire `selectionChange` but warn about
87
- * possible infinite selection loop.
88
- *
89
- * @private
90
- * @member {Number} #_clearInfiniteLoopInterval
91
- */
92
35
  this._clearInfiniteLoopInterval = setInterval(() => this._clearInfiniteLoop(), 1000);
93
- /**
94
- * Unlocks the `isSelecting` state of the view document in case the selection observer did not record this fact
95
- * correctly (for whatever reason). It is a safeguard (paranoid check), that returns document to the normal state
96
- * after a certain period of time (debounced, postponed by each selectionchange event).
97
- *
98
- * @private
99
- * @method #_documentIsSelectingInactivityTimeoutDebounced
100
- */
101
36
  this._documentIsSelectingInactivityTimeoutDebounced = debounce(() => (this.document.isSelecting = false), 5000);
102
- /**
103
- * Private property to check if the code does not enter infinite loop.
104
- *
105
- * @private
106
- * @member {Number} module:engine/view/observer/selectionobserver~SelectionObserver#_loopbackCounter
107
- */
108
37
  this._loopbackCounter = 0;
109
38
  }
110
39
  /**
@@ -142,19 +71,19 @@ export default class SelectionObserver extends Observer {
142
71
  // handler would like to check it and update (for example table multi cell selection).
143
72
  this.listenTo(domDocument, 'mouseup', endDocumentIsSelecting, { priority: 'highest', useCapture: true });
144
73
  this.listenTo(domDocument, 'selectionchange', (evt, domEvent) => {
145
- // @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
146
- // @if CK_DEBUG_TYPING // const domSelection = domDocument.defaultView.getSelection();
74
+ // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
75
+ // @if CK_DEBUG_TYPING // const domSelection = domDocument.defaultView!.getSelection();
147
76
  // @if CK_DEBUG_TYPING // console.group( '%c[SelectionObserver]%c selectionchange', 'color:green', ''
148
77
  // @if CK_DEBUG_TYPING // );
149
78
  // @if CK_DEBUG_TYPING // console.info( '%c[SelectionObserver]%c DOM Selection:', 'font-weight:bold;color:green', '',
150
- // @if CK_DEBUG_TYPING // { node: domSelection.anchorNode, offset: domSelection.anchorOffset },
151
- // @if CK_DEBUG_TYPING // { node: domSelection.focusNode, offset: domSelection.focusOffset }
79
+ // @if CK_DEBUG_TYPING // { node: domSelection!.anchorNode, offset: domSelection!.anchorOffset },
80
+ // @if CK_DEBUG_TYPING // { node: domSelection!.focusNode, offset: domSelection!.focusOffset }
152
81
  // @if CK_DEBUG_TYPING // );
153
82
  // @if CK_DEBUG_TYPING // }
154
83
  // The Renderer is disabled while composing on non-android browsers, so we can't update the view selection
155
84
  // because the DOM and view tree drifted apart. Position mapping could fail because of it.
156
85
  if (this.document.isComposing && !env.isAndroid) {
157
- // @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
86
+ // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
158
87
  // @if CK_DEBUG_TYPING // console.info( '%c[SelectionObserver]%c Selection change ignored (isComposing)',
159
88
  // @if CK_DEBUG_TYPING // 'font-weight:bold;color:green', ''
160
89
  // @if CK_DEBUG_TYPING // );
@@ -163,7 +92,7 @@ export default class SelectionObserver extends Observer {
163
92
  return;
164
93
  }
165
94
  this._handleSelectionChange(domEvent, domDocument);
166
- // @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
95
+ // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
167
96
  // @if CK_DEBUG_TYPING // console.groupEnd();
168
97
  // @if CK_DEBUG_TYPING // }
169
98
  // Defer the safety timeout when the selection changes (e.g. the user keeps extending the selection
@@ -181,20 +110,20 @@ export default class SelectionObserver extends Observer {
181
110
  this._fireSelectionChangeDoneDebounced.cancel();
182
111
  this._documentIsSelectingInactivityTimeoutDebounced.cancel();
183
112
  }
184
- // @if CK_DEBUG // _reportInfiniteLoop() {
185
- // @if CK_DEBUG // throw new Error(
186
- // @if CK_DEBUG // 'Selection change observer detected an infinite rendering loop.\n\n' +
187
- // @if CK_DEBUG // '⚠️⚠️ Report this error on https://github.com/ckeditor/ckeditor5/issues/11658.'
188
- // @if CK_DEBUG // );
189
- // @if CK_DEBUG // }
113
+ /* istanbul ignore next */
114
+ _reportInfiniteLoop() {
115
+ // @if CK_DEBUG // throw new Error(
116
+ // @if CK_DEBUG // 'Selection change observer detected an infinite rendering loop.\n\n' +
117
+ // @if CK_DEBUG // '⚠️⚠️ Report this error on https://github.com/ckeditor/ckeditor5/issues/11658.'
118
+ // @if CK_DEBUG // );
119
+ }
190
120
  /**
191
121
  * Selection change listener. {@link module:engine/view/observer/mutationobserver~MutationObserver#flush Flush} mutations, check if
192
122
  * a selection changes and fires {@link module:engine/view/document~Document#event:selectionChange} event on every change
193
123
  * and {@link module:engine/view/document~Document#event:selectionChangeDone} when a selection stop changing.
194
124
  *
195
- * @private
196
- * @param {Event} domEvent DOM event.
197
- * @param {Document} domDocument DOM document.
125
+ * @param domEvent DOM event.
126
+ * @param domDocument DOM document.
198
127
  */
199
128
  _handleSelectionChange(domEvent, domDocument) {
200
129
  if (!this.isEnabled) {
@@ -227,8 +156,7 @@ export default class SelectionObserver extends Observer {
227
156
  // Most probably you try to put the selection in the position which is not allowed
228
157
  // by the browser and browser fixes it automatically what causes `selectionchange` event on
229
158
  // which a loopback through a model tries to re-render the wrong selection and again.
230
- //
231
- // @if CK_DEBUG // this._reportInfiniteLoop();
159
+ this._reportInfiniteLoop();
232
160
  return;
233
161
  }
234
162
  // Mark the latest focus change as complete (we got new selection after the focus so the selection is in the focused element).
@@ -244,7 +172,7 @@ export default class SelectionObserver extends Observer {
244
172
  newSelection: newViewSelection,
245
173
  domSelection
246
174
  };
247
- // @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
175
+ // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
248
176
  // @if CK_DEBUG_TYPING // console.info( '%c[SelectionObserver]%c Fire selection change:',
249
177
  // @if CK_DEBUG_TYPING // 'font-weight:bold;color:green', '',
250
178
  // @if CK_DEBUG_TYPING // newViewSelection.getFirstRange()
@@ -261,26 +189,8 @@ export default class SelectionObserver extends Observer {
261
189
  }
262
190
  /**
263
191
  * Clears `SelectionObserver` internal properties connected with preventing infinite loop.
264
- *
265
- * @protected
266
192
  */
267
193
  _clearInfiniteLoop() {
268
194
  this._loopbackCounter = 0;
269
195
  }
270
196
  }
271
- /**
272
- * Fired when selection stops changing.
273
- *
274
- * Introduced by {@link module:engine/view/observer/selectionobserver~SelectionObserver}.
275
- *
276
- * Note that because {@link module:engine/view/observer/selectionobserver~SelectionObserver} is attached by the
277
- * {@link module:engine/view/view~View} this event is available by default.
278
- *
279
- * @see module:engine/view/observer/selectionobserver~SelectionObserver
280
- * @event module:engine/view/document~Document#event:selectionChangeDone
281
- * @param {Object} data
282
- * @param {module:engine/view/documentselection~DocumentSelection} data.oldSelection Old View selection which is
283
- * {@link module:engine/view/document~Document#selection}.
284
- * @param {module:engine/view/selection~Selection} data.newSelection New View selection which is converted DOM selection.
285
- * @param {Selection} data.domSelection Native DOM selection.
286
- */
@@ -0,0 +1,42 @@
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 engine/view/observer/tabobserver
7
+ */
8
+ import type View from '../view';
9
+ import Observer from './observer';
10
+ import type { KeyEventData } from './keyobserver';
11
+ import type { BubblingEvent } from './bubblingemittermixin';
12
+ /**
13
+ * Tab observer introduces the {@link module:engine/view/document~Document#event:tab `Document#tab`} event.
14
+ *
15
+ * Note that because {@link module:engine/view/observer/tabobserver~TabObserver} is attached by the
16
+ * {@link module:engine/view/view~View}, this event is available by default.
17
+ */
18
+ export default class TabObserver extends Observer {
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ constructor(view: View);
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ observe(): void;
27
+ }
28
+ /**
29
+ * Event fired when the user presses a tab key.
30
+ *
31
+ * Introduced by {@link module:engine/view/observer/tabobserver~TabObserver}.
32
+ *
33
+ * Note that because {@link module:engine/view/observer/tabobserver~TabObserver} is attached by the
34
+ * {@link module:engine/view/view~View}, this event is available by default.
35
+ *
36
+ * @eventName module:engine/view/document~Document#tab
37
+ * @param data
38
+ */
39
+ export type ViewDocumentTabEvent = BubblingEvent<{
40
+ name: 'tab';
41
+ args: [data: KeyEventData];
42
+ }>;
@@ -10,8 +10,6 @@ import { keyCodes } from '@ckeditor/ckeditor5-utils';
10
10
  *
11
11
  * Note that because {@link module:engine/view/observer/tabobserver~TabObserver} is attached by the
12
12
  * {@link module:engine/view/view~View}, this event is available by default.
13
- *
14
- * @extends module:engine/view/observer/observer~Observer
15
13
  */
16
14
  export default class TabObserver extends Observer {
17
15
  /**
@@ -38,15 +36,3 @@ export default class TabObserver extends Observer {
38
36
  */
39
37
  observe() { }
40
38
  }
41
- /**
42
- * Event fired when the user presses a tab key.
43
- *
44
- * Introduced by {@link module:engine/view/observer/tabobserver~TabObserver}.
45
- *
46
- * Note that because {@link module:engine/view/observer/tabobserver~TabObserver} is attached by the
47
- * {@link module:engine/view/view~View}, this event is available by default.
48
- *
49
- * @event module:engine/view/document~Document#event:tab
50
- *
51
- * @param {module:engine/view/observer/domeventdata~DomEventData} data
52
- */
@@ -0,0 +1,85 @@
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 engine/view/placeholder
7
+ */
8
+ import '../../theme/placeholder.css';
9
+ import type DowncastWriter from './downcastwriter';
10
+ import type Element from './element';
11
+ import type View from './view';
12
+ /**
13
+ * A helper that enables a placeholder on the provided view element (also updates its visibility).
14
+ * The placeholder is a CSS pseudo–element (with a text content) attached to the element.
15
+ *
16
+ * To change the placeholder text, simply call this method again with new options.
17
+ *
18
+ * To disable the placeholder, use {@link module:engine/view/placeholder~disablePlaceholder `disablePlaceholder()`} helper.
19
+ *
20
+ * @param options Configuration options of the placeholder.
21
+ * @param options.view Editing view instance.
22
+ * @param options.element Element that will gain a placeholder. See `options.isDirectHost` to learn more.
23
+ * @param options.text Placeholder text.
24
+ * @param options.isDirectHost If set `false`, the placeholder will not be enabled directly
25
+ * in the passed `element` but in one of its children (selected automatically, i.e. a first empty child element).
26
+ * Useful when attaching placeholders to elements that can host other elements (not just text), for instance,
27
+ * editable root elements.
28
+ * @param options.keepOnFocus If set `true`, the placeholder stay visible when the host element is focused.
29
+ */
30
+ export declare function enablePlaceholder({ view, element, text, isDirectHost, keepOnFocus }: {
31
+ view: View;
32
+ element: Element;
33
+ text: string;
34
+ isDirectHost?: boolean;
35
+ keepOnFocus?: boolean;
36
+ }): void;
37
+ /**
38
+ * Disables the placeholder functionality from a given element.
39
+ *
40
+ * See {@link module:engine/view/placeholder~enablePlaceholder `enablePlaceholder()`} to learn more.
41
+ */
42
+ export declare function disablePlaceholder(view: View, element: Element): void;
43
+ /**
44
+ * Shows a placeholder in the provided element by changing related attributes and CSS classes.
45
+ *
46
+ * **Note**: This helper will not update the placeholder visibility nor manage the
47
+ * it in any way in the future. What it does is a one–time state change of an element. Use
48
+ * {@link module:engine/view/placeholder~enablePlaceholder `enablePlaceholder()`} and
49
+ * {@link module:engine/view/placeholder~disablePlaceholder `disablePlaceholder()`} for full
50
+ * placeholder functionality.
51
+ *
52
+ * **Note**: This helper will blindly show the placeholder directly in the root editable element if
53
+ * one is passed, which could result in a visual clash if the editable element has some children
54
+ * (for instance, an empty paragraph). Use {@link module:engine/view/placeholder~enablePlaceholder `enablePlaceholder()`}
55
+ * in that case or make sure the correct element is passed to the helper.
56
+ *
57
+ * @returns `true`, if any changes were made to the `element`.
58
+ */
59
+ export declare function showPlaceholder(writer: DowncastWriter, element: Element): boolean;
60
+ /**
61
+ * Hides a placeholder in the element by changing related attributes and CSS classes.
62
+ *
63
+ * **Note**: This helper will not update the placeholder visibility nor manage the
64
+ * it in any way in the future. What it does is a one–time state change of an element. Use
65
+ * {@link module:engine/view/placeholder~enablePlaceholder `enablePlaceholder()`} and
66
+ * {@link module:engine/view/placeholder~disablePlaceholder `disablePlaceholder()`} for full
67
+ * placeholder functionality.
68
+ *
69
+ * @returns `true`, if any changes were made to the `element`.
70
+ */
71
+ export declare function hidePlaceholder(writer: DowncastWriter, element: Element): boolean;
72
+ /**
73
+ * Checks if a placeholder should be displayed in the element.
74
+ *
75
+ * **Note**: This helper will blindly check the possibility of showing a placeholder directly in the
76
+ * root editable element if one is passed, which may not be the expected result. If an element can
77
+ * host other elements (not just text), most likely one of its children should be checked instead
78
+ * because it will be the final host for the placeholder. Use
79
+ * {@link module:engine/view/placeholder~enablePlaceholder `enablePlaceholder()`} in that case or make
80
+ * sure the correct element is passed to the helper.
81
+ *
82
+ * @param element Element that holds the placeholder.
83
+ * @param keepOnFocus Focusing the element will keep the placeholder visible.
84
+ */
85
+ export declare function needsPlaceholder(element: Element, keepOnFocus: boolean): boolean;
@@ -16,19 +16,17 @@ const documentPlaceholders = new WeakMap();
16
16
  *
17
17
  * To disable the placeholder, use {@link module:engine/view/placeholder~disablePlaceholder `disablePlaceholder()`} helper.
18
18
  *
19
- * @param {Object} [options] Configuration options of the placeholder.
20
- * @param {module:engine/view/view~View} options.view Editing view instance.
21
- * @param {module:engine/view/element~Element} options.element Element that will gain a placeholder.
22
- * See `options.isDirectHost` to learn more.
23
- * @param {String} options.text Placeholder text.
24
- * @param {Boolean} [options.isDirectHost=true] If set `false`, the placeholder will not be enabled directly
19
+ * @param options Configuration options of the placeholder.
20
+ * @param options.view Editing view instance.
21
+ * @param options.element Element that will gain a placeholder. See `options.isDirectHost` to learn more.
22
+ * @param options.text Placeholder text.
23
+ * @param options.isDirectHost If set `false`, the placeholder will not be enabled directly
25
24
  * in the passed `element` but in one of its children (selected automatically, i.e. a first empty child element).
26
25
  * Useful when attaching placeholders to elements that can host other elements (not just text), for instance,
27
26
  * editable root elements.
28
- * @param {Boolean} [options.keepOnFocus=false] If set `true`, the placeholder stay visible when the host element is focused.
27
+ * @param options.keepOnFocus If set `true`, the placeholder stay visible when the host element is focused.
29
28
  */
30
- export function enablePlaceholder(options) {
31
- const { view, element, text, isDirectHost = true, keepOnFocus = false } = options;
29
+ export function enablePlaceholder({ view, element, text, isDirectHost = true, keepOnFocus = false }) {
32
30
  const doc = view.document;
33
31
  // Use a single a single post fixer per—document to update all placeholders.
34
32
  if (!documentPlaceholders.has(doc)) {
@@ -55,9 +53,6 @@ export function enablePlaceholder(options) {
55
53
  * Disables the placeholder functionality from a given element.
56
54
  *
57
55
  * See {@link module:engine/view/placeholder~enablePlaceholder `enablePlaceholder()`} to learn more.
58
- *
59
- * @param {module:engine/view/view~View} view
60
- * @param {module:engine/view/element~Element} element
61
56
  */
62
57
  export function disablePlaceholder(view, element) {
63
58
  const doc = element.document;
@@ -86,9 +81,7 @@ export function disablePlaceholder(view, element) {
86
81
  * (for instance, an empty paragraph). Use {@link module:engine/view/placeholder~enablePlaceholder `enablePlaceholder()`}
87
82
  * in that case or make sure the correct element is passed to the helper.
88
83
  *
89
- * @param {module:engine/view/downcastwriter~DowncastWriter} writer
90
- * @param {module:engine/view/element~Element} element
91
- * @returns {Boolean} `true`, if any changes were made to the `element`.
84
+ * @returns `true`, if any changes were made to the `element`.
92
85
  */
93
86
  export function showPlaceholder(writer, element) {
94
87
  if (!element.hasClass('ck-placeholder')) {
@@ -106,9 +99,7 @@ export function showPlaceholder(writer, element) {
106
99
  * {@link module:engine/view/placeholder~disablePlaceholder `disablePlaceholder()`} for full
107
100
  * placeholder functionality.
108
101
  *
109
- * @param {module:engine/view/downcastwriter~DowncastWriter} writer
110
- * @param {module:engine/view/element~Element} element
111
- * @returns {Boolean} `true`, if any changes were made to the `element`.
102
+ * @returns `true`, if any changes were made to the `element`.
112
103
  */
113
104
  export function hidePlaceholder(writer, element) {
114
105
  if (element.hasClass('ck-placeholder')) {
@@ -127,9 +118,8 @@ export function hidePlaceholder(writer, element) {
127
118
  * {@link module:engine/view/placeholder~enablePlaceholder `enablePlaceholder()`} in that case or make
128
119
  * sure the correct element is passed to the helper.
129
120
  *
130
- * @param {module:engine/view/element~Element} element Element that holds the placeholder.
131
- * @param {Boolean} keepOnFocus Focusing the element will keep the placeholder visible.
132
- * @returns {Boolean}
121
+ * @param element Element that holds the placeholder.
122
+ * @param keepOnFocus Focusing the element will keep the placeholder visible.
133
123
  */
134
124
  export function needsPlaceholder(element, keepOnFocus) {
135
125
  if (!element.isAttached()) {
@@ -158,12 +148,11 @@ export function needsPlaceholder(element, keepOnFocus) {
158
148
  // If document is focused and the element is empty but the selection is not anchored inside it.
159
149
  return !!selectionAnchor && selectionAnchor.parent !== element;
160
150
  }
161
- // Updates all placeholders associated with a document in a post–fixer callback.
162
- //
163
- // @private
164
- // @param { module:engine/view/document~Document} doc
165
- // @param {module:engine/view/downcastwriter~DowncastWriter} writer
166
- // @returns {Boolean} True if any changes were made to the view document.
151
+ /**
152
+ * Updates all placeholders associated with a document in a post–fixer callback.
153
+ *
154
+ * @returns True if any changes were made to the view document.
155
+ */
167
156
  function updateDocumentPlaceholders(doc, writer) {
168
157
  const placeholders = documentPlaceholders.get(doc);
169
158
  const directHostElements = [];
@@ -200,15 +189,11 @@ function updateDocumentPlaceholders(doc, writer) {
200
189
  }
201
190
  return wasViewModified;
202
191
  }
203
- // Updates a single placeholder in a post–fixer callback.
204
- //
205
- // @private
206
- // @param {module:engine/view/downcastwriter~DowncastWriter} writer
207
- // @param {module:engine/view/element~Element} element
208
- // @param {Object} config Configuration of the placeholder
209
- // @param {String} config.text
210
- // @param {Boolean} config.isDirectHost
211
- // @returns {Boolean} True if any changes were made to the view document.
192
+ /**
193
+ * Updates a single placeholder in a post–fixer callback.
194
+ *
195
+ * @returns True if any changes were made to the view document.
196
+ */
212
197
  function updatePlaceholder(writer, element, config) {
213
198
  const { text, isDirectHost, hostElement } = config;
214
199
  let wasViewModified = false;
@@ -229,13 +214,11 @@ function updatePlaceholder(writer, element, config) {
229
214
  }
230
215
  return wasViewModified;
231
216
  }
232
- // Gets a child element capable of displaying a placeholder if a parent element can host more
233
- // than just text (for instance, when it is a root editable element). The child element
234
- // can then be used in other placeholder helpers as a substitute of its parent.
235
- //
236
- // @private
237
- // @param {module:engine/view/element~Element} parent
238
- // @returns {module:engine/view/element~Element|null}
217
+ /**
218
+ * Gets a child element capable of displaying a placeholder if a parent element can host more
219
+ * than just text (for instance, when it is a root editable element). The child element
220
+ * can then be used in other placeholder helpers as a substitute of its parent.
221
+ */
239
222
  function getChildPlaceholderHostSubstitute(parent) {
240
223
  if (parent.childCount) {
241
224
  const firstChild = parent.getChild(0);