@ckeditor/ckeditor5-engine 36.0.1 → 37.0.0-alpha.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 (200) hide show
  1. package/README.md +1 -1
  2. package/package.json +24 -23
  3. package/src/controller/datacontroller.d.ts +331 -0
  4. package/src/controller/datacontroller.js +62 -109
  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 +499 -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 +177 -0
  24. package/src/conversion/viewconsumable.js +157 -162
  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 +105 -0
  42. package/src/index.js +1 -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 +245 -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 +812 -0
  57. package/src/model/model.js +59 -30
  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/moveoperation.d.ts +91 -0
  66. package/src/model/operation/nooperation.d.ts +33 -0
  67. package/src/model/operation/operation.d.ts +89 -0
  68. package/src/model/operation/operationfactory.d.ts +18 -0
  69. package/src/model/operation/renameoperation.d.ts +78 -0
  70. package/src/model/operation/rootattributeoperation.d.ts +97 -0
  71. package/src/model/operation/rootattributeoperation.js +1 -1
  72. package/src/model/operation/splitoperation.d.ts +104 -0
  73. package/src/model/operation/transform.d.ts +100 -0
  74. package/src/model/operation/utils.d.ts +71 -0
  75. package/src/model/position.d.ts +539 -0
  76. package/src/model/position.js +1 -1
  77. package/src/model/range.d.ts +458 -0
  78. package/src/model/range.js +1 -1
  79. package/src/model/rootelement.d.ts +40 -0
  80. package/src/model/schema.d.ts +1176 -0
  81. package/src/model/schema.js +15 -15
  82. package/src/model/selection.d.ts +472 -0
  83. package/src/model/text.d.ts +66 -0
  84. package/src/model/text.js +0 -2
  85. package/src/model/textproxy.d.ts +144 -0
  86. package/src/model/treewalker.d.ts +186 -0
  87. package/src/model/treewalker.js +19 -10
  88. package/src/model/typecheckable.d.ts +255 -0
  89. package/src/model/utils/autoparagraphing.d.ts +37 -0
  90. package/src/model/utils/deletecontent.d.ts +58 -0
  91. package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
  92. package/src/model/utils/getselectedcontent.d.ts +30 -0
  93. package/src/model/utils/insertcontent.d.ts +46 -0
  94. package/src/model/utils/insertcontent.js +2 -12
  95. package/src/model/utils/insertobject.d.ts +44 -0
  96. package/src/model/utils/insertobject.js +3 -14
  97. package/src/model/utils/modifyselection.d.ts +48 -0
  98. package/src/model/utils/selection-post-fixer.d.ts +65 -0
  99. package/src/model/writer.d.ts +726 -0
  100. package/src/model/writer.js +6 -4
  101. package/src/view/attributeelement.d.ts +108 -0
  102. package/src/view/attributeelement.js +25 -69
  103. package/src/view/containerelement.d.ts +49 -0
  104. package/src/view/containerelement.js +10 -43
  105. package/src/view/datatransfer.d.ts +75 -0
  106. package/src/view/document.d.ts +184 -0
  107. package/src/view/document.js +15 -84
  108. package/src/view/documentfragment.d.ts +150 -0
  109. package/src/view/documentfragment.js +40 -81
  110. package/src/view/documentselection.d.ts +219 -0
  111. package/src/view/documentselection.js +75 -121
  112. package/src/view/domconverter.d.ts +620 -0
  113. package/src/view/domconverter.js +159 -276
  114. package/src/view/downcastwriter.d.ts +804 -0
  115. package/src/view/downcastwriter.js +336 -380
  116. package/src/view/editableelement.d.ts +52 -0
  117. package/src/view/editableelement.js +9 -49
  118. package/src/view/element.d.ts +466 -0
  119. package/src/view/element.js +150 -222
  120. package/src/view/elementdefinition.d.ts +87 -0
  121. package/src/view/emptyelement.d.ts +41 -0
  122. package/src/view/emptyelement.js +11 -44
  123. package/src/view/filler.d.ts +111 -0
  124. package/src/view/filler.js +24 -21
  125. package/src/view/item.d.ts +14 -0
  126. package/src/view/matcher.d.ts +486 -0
  127. package/src/view/matcher.js +247 -218
  128. package/src/view/node.d.ts +160 -0
  129. package/src/view/node.js +26 -100
  130. package/src/view/observer/arrowkeysobserver.d.ts +41 -0
  131. package/src/view/observer/arrowkeysobserver.js +0 -13
  132. package/src/view/observer/bubblingemittermixin.d.ts +166 -0
  133. package/src/view/observer/bubblingemittermixin.js +36 -25
  134. package/src/view/observer/bubblingeventinfo.d.ts +47 -0
  135. package/src/view/observer/bubblingeventinfo.js +3 -29
  136. package/src/view/observer/clickobserver.d.ts +43 -0
  137. package/src/view/observer/clickobserver.js +9 -19
  138. package/src/view/observer/compositionobserver.d.ts +82 -0
  139. package/src/view/observer/compositionobserver.js +13 -42
  140. package/src/view/observer/domeventdata.d.ts +50 -0
  141. package/src/view/observer/domeventdata.js +5 -30
  142. package/src/view/observer/domeventobserver.d.ts +69 -0
  143. package/src/view/observer/domeventobserver.js +19 -21
  144. package/src/view/observer/fakeselectionobserver.d.ts +46 -0
  145. package/src/view/observer/fakeselectionobserver.js +2 -15
  146. package/src/view/observer/focusobserver.d.ts +82 -0
  147. package/src/view/observer/focusobserver.js +14 -40
  148. package/src/view/observer/inputobserver.d.ts +86 -0
  149. package/src/view/observer/inputobserver.js +18 -64
  150. package/src/view/observer/keyobserver.d.ts +67 -0
  151. package/src/view/observer/keyobserver.js +8 -42
  152. package/src/view/observer/mouseobserver.d.ts +89 -0
  153. package/src/view/observer/mouseobserver.js +8 -28
  154. package/src/view/observer/mutationobserver.d.ts +82 -0
  155. package/src/view/observer/mutationobserver.js +7 -37
  156. package/src/view/observer/observer.d.ts +84 -0
  157. package/src/view/observer/observer.js +12 -25
  158. package/src/view/observer/selectionobserver.d.ts +143 -0
  159. package/src/view/observer/selectionobserver.js +9 -99
  160. package/src/view/observer/tabobserver.d.ts +42 -0
  161. package/src/view/observer/tabobserver.js +0 -14
  162. package/src/view/placeholder.d.ts +85 -0
  163. package/src/view/placeholder.js +26 -43
  164. package/src/view/position.d.ts +189 -0
  165. package/src/view/position.js +36 -83
  166. package/src/view/range.d.ts +279 -0
  167. package/src/view/range.js +79 -122
  168. package/src/view/rawelement.d.ts +73 -0
  169. package/src/view/rawelement.js +34 -48
  170. package/src/view/renderer.d.ts +265 -0
  171. package/src/view/renderer.js +105 -193
  172. package/src/view/rooteditableelement.d.ts +41 -0
  173. package/src/view/rooteditableelement.js +12 -40
  174. package/src/view/selection.d.ts +375 -0
  175. package/src/view/selection.js +79 -153
  176. package/src/view/styles/background.d.ts +33 -0
  177. package/src/view/styles/background.js +14 -12
  178. package/src/view/styles/border.d.ts +43 -0
  179. package/src/view/styles/border.js +58 -48
  180. package/src/view/styles/margin.d.ts +29 -0
  181. package/src/view/styles/margin.js +13 -11
  182. package/src/view/styles/padding.d.ts +29 -0
  183. package/src/view/styles/padding.js +13 -11
  184. package/src/view/styles/utils.d.ts +93 -0
  185. package/src/view/styles/utils.js +22 -48
  186. package/src/view/stylesmap.d.ts +675 -0
  187. package/src/view/stylesmap.js +249 -244
  188. package/src/view/text.d.ts +74 -0
  189. package/src/view/text.js +16 -46
  190. package/src/view/textproxy.d.ts +97 -0
  191. package/src/view/textproxy.js +10 -59
  192. package/src/view/treewalker.d.ts +195 -0
  193. package/src/view/treewalker.js +43 -106
  194. package/src/view/typecheckable.d.ts +401 -0
  195. package/src/view/uielement.d.ts +96 -0
  196. package/src/view/uielement.js +28 -62
  197. package/src/view/upcastwriter.d.ts +328 -0
  198. package/src/view/upcastwriter.js +124 -134
  199. package/src/view/view.d.ts +327 -0
  200. package/src/view/view.js +79 -150
@@ -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
@@ -192,9 +121,8 @@ export default class SelectionObserver extends Observer {
192
121
  * a selection changes and fires {@link module:engine/view/document~Document#event:selectionChange} event on every change
193
122
  * and {@link module:engine/view/document~Document#event:selectionChangeDone} when a selection stop changing.
194
123
  *
195
- * @private
196
- * @param {Event} domEvent DOM event.
197
- * @param {Document} domDocument DOM document.
124
+ * @param domEvent DOM event.
125
+ * @param domDocument DOM document.
198
126
  */
199
127
  _handleSelectionChange(domEvent, domDocument) {
200
128
  if (!this.isEnabled) {
@@ -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 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);
@@ -0,0 +1,189 @@
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/position
7
+ */
8
+ import TypeCheckable from './typecheckable';
9
+ import EditableElement from './editableelement';
10
+ import '@ckeditor/ckeditor5-utils/src/version';
11
+ import type DocumentFragment from './documentfragment';
12
+ import type Item from './item';
13
+ import type Node from './node';
14
+ import { default as TreeWalker, type TreeWalkerValue, type TreeWalkerOptions } from './treewalker';
15
+ /**
16
+ * Position in the view tree. Position is represented by its parent node and an offset in this parent.
17
+ *
18
+ * In order to create a new position instance use the `createPosition*()` factory methods available in:
19
+ *
20
+ * * {@link module:engine/view/view~View}
21
+ * * {@link module:engine/view/downcastwriter~DowncastWriter}
22
+ * * {@link module:engine/view/upcastwriter~UpcastWriter}
23
+ */
24
+ export default class Position extends TypeCheckable {
25
+ /**
26
+ * Position parent.
27
+ */
28
+ readonly parent: Node | DocumentFragment;
29
+ /**
30
+ * Position offset.
31
+ */
32
+ offset: number;
33
+ /**
34
+ * Creates a position.
35
+ *
36
+ * @param parent Position parent.
37
+ * @param offset Position offset.
38
+ */
39
+ constructor(parent: Node | DocumentFragment, offset: number);
40
+ /**
41
+ * Node directly after the position. Equals `null` when there is no node after position or position is located
42
+ * inside text node.
43
+ */
44
+ get nodeAfter(): Node | null;
45
+ /**
46
+ * Node directly before the position. Equals `null` when there is no node before position or position is located
47
+ * inside text node.
48
+ */
49
+ get nodeBefore(): Node | null;
50
+ /**
51
+ * Is `true` if position is at the beginning of its {@link module:engine/view/position~Position#parent parent}, `false` otherwise.
52
+ */
53
+ get isAtStart(): boolean;
54
+ /**
55
+ * Is `true` if position is at the end of its {@link module:engine/view/position~Position#parent parent}, `false` otherwise.
56
+ */
57
+ get isAtEnd(): boolean;
58
+ /**
59
+ * Position's root, that is the root of the position's parent element.
60
+ */
61
+ get root(): Node | DocumentFragment;
62
+ /**
63
+ * {@link module:engine/view/editableelement~EditableElement EditableElement} instance that contains this position, or `null` if
64
+ * position is not inside an editable element.
65
+ */
66
+ get editableElement(): EditableElement | null;
67
+ /**
68
+ * Returns a new instance of Position with offset incremented by `shift` value.
69
+ *
70
+ * @param shift How position offset should get changed. Accepts negative values.
71
+ * @returns Shifted position.
72
+ */
73
+ getShiftedBy(shift: number): Position;
74
+ /**
75
+ * Gets the farthest position which matches the callback using
76
+ * {@link module:engine/view/treewalker~TreeWalker TreeWalker}.
77
+ *
78
+ * For example:
79
+ *
80
+ * ```ts
81
+ * getLastMatchingPosition( value => value.type == 'text' ); // <p>{}foo</p> -> <p>foo[]</p>
82
+ * getLastMatchingPosition( value => value.type == 'text', { direction: 'backward' } ); // <p>foo[]</p> -> <p>{}foo</p>
83
+ * getLastMatchingPosition( value => false ); // Do not move the position.
84
+ * ```
85
+ *
86
+ * @param skip Callback function. Gets {@link module:engine/view/treewalker~type TreeWalkerValue} and should
87
+ * return `true` if the value should be skipped or `false` if not.
88
+ * @param options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}.
89
+ * @returns The position after the last item which matches the `skip` callback test.
90
+ */
91
+ getLastMatchingPosition(skip: (value: TreeWalkerValue) => boolean, options?: TreeWalkerOptions): Position;
92
+ /**
93
+ * Returns ancestors array of this position, that is this position's parent and it's ancestors.
94
+ *
95
+ * @returns Array with ancestors.
96
+ */
97
+ getAncestors(): Array<Node | DocumentFragment>;
98
+ /**
99
+ * Returns a {@link module:engine/view/node~Node} or {@link module:engine/view/documentfragment~DocumentFragment}
100
+ * which is a common ancestor of both positions.
101
+ */
102
+ getCommonAncestor(position: Position): Node | DocumentFragment | null;
103
+ /**
104
+ * Checks whether this position equals given position.
105
+ *
106
+ * @param otherPosition Position to compare with.
107
+ * @returns True if positions are same.
108
+ */
109
+ isEqual(otherPosition: Position): boolean;
110
+ /**
111
+ * Checks whether this position is located before given position. When method returns `false` it does not mean that
112
+ * this position is after give one. Two positions may be located inside separate roots and in that situation this
113
+ * method will still return `false`.
114
+ *
115
+ * @see module:engine/view/position~Position#isAfter
116
+ * @see module:engine/view/position~Position#compareWith
117
+ * @param otherPosition Position to compare with.
118
+ * @returns Returns `true` if this position is before given position.
119
+ */
120
+ isBefore(otherPosition: Position): boolean;
121
+ /**
122
+ * Checks whether this position is located after given position. When method returns `false` it does not mean that
123
+ * this position is before give one. Two positions may be located inside separate roots and in that situation this
124
+ * method will still return `false`.
125
+ *
126
+ * @see module:engine/view/position~Position#isBefore
127
+ * @see module:engine/view/position~Position#compareWith
128
+ * @param otherPosition Position to compare with.
129
+ * @returns Returns `true` if this position is after given position.
130
+ */
131
+ isAfter(otherPosition: Position): boolean;
132
+ /**
133
+ * Checks whether this position is before, after or in same position that other position. Two positions may be also
134
+ * different when they are located in separate roots.
135
+ *
136
+ * @param otherPosition Position to compare with.
137
+ */
138
+ compareWith(otherPosition: Position): PositionRelation;
139
+ /**
140
+ * Creates a {@link module:engine/view/treewalker~TreeWalker TreeWalker} instance with this positions as a start position.
141
+ *
142
+ * @param options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}
143
+ */
144
+ getWalker(options?: TreeWalkerOptions): TreeWalker;
145
+ /**
146
+ * Clones this position.
147
+ */
148
+ clone(): Position;
149
+ /**
150
+ * Creates position at the given location. The location can be specified as:
151
+ *
152
+ * * a {@link module:engine/view/position~Position position},
153
+ * * parent element and offset (offset defaults to `0`),
154
+ * * parent element and `'end'` (sets position at the end of that element),
155
+ * * {@link module:engine/view/item~Item view item} and `'before'` or `'after'` (sets position before or after given view item).
156
+ *
157
+ * This method is a shortcut to other constructors such as:
158
+ *
159
+ * * {@link module:engine/view/position~Position._createBefore},
160
+ * * {@link module:engine/view/position~Position._createAfter}.
161
+ *
162
+ * @internal
163
+ * @param offset Offset or one of the flags. Used only when first parameter is a {@link module:engine/view/item~Item view item}.
164
+ */
165
+ static _createAt(itemOrPosition: Item | Position, offset?: PositionOffset): Position;
166
+ /**
167
+ * Creates a new position after given view item.
168
+ *
169
+ * @internal
170
+ * @param item View item after which the position should be located.
171
+ */
172
+ static _createAfter(item: Item): Position;
173
+ /**
174
+ * Creates a new position before given view item.
175
+ *
176
+ * @internal
177
+ * @param item View item before which the position should be located.
178
+ */
179
+ static _createBefore(item: Item): Position;
180
+ }
181
+ /**
182
+ * A flag indicating whether this position is `'before'` or `'after'` or `'same'` as given position.
183
+ * If positions are in different roots `'different'` flag is returned.
184
+ */
185
+ export type PositionRelation = 'before' | 'after' | 'same' | 'different';
186
+ /**
187
+ * Offset or one of the flags.
188
+ */
189
+ export type PositionOffset = number | 'before' | 'after' | 'end';