@ckeditor/ckeditor5-engine 36.0.0 → 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 (201) 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/datatransfer.js +24 -27
  107. package/src/view/document.d.ts +184 -0
  108. package/src/view/document.js +15 -84
  109. package/src/view/documentfragment.d.ts +150 -0
  110. package/src/view/documentfragment.js +40 -81
  111. package/src/view/documentselection.d.ts +219 -0
  112. package/src/view/documentselection.js +75 -121
  113. package/src/view/domconverter.d.ts +620 -0
  114. package/src/view/domconverter.js +159 -276
  115. package/src/view/downcastwriter.d.ts +804 -0
  116. package/src/view/downcastwriter.js +336 -380
  117. package/src/view/editableelement.d.ts +52 -0
  118. package/src/view/editableelement.js +9 -49
  119. package/src/view/element.d.ts +466 -0
  120. package/src/view/element.js +150 -222
  121. package/src/view/elementdefinition.d.ts +87 -0
  122. package/src/view/emptyelement.d.ts +41 -0
  123. package/src/view/emptyelement.js +11 -44
  124. package/src/view/filler.d.ts +111 -0
  125. package/src/view/filler.js +24 -21
  126. package/src/view/item.d.ts +14 -0
  127. package/src/view/matcher.d.ts +486 -0
  128. package/src/view/matcher.js +247 -218
  129. package/src/view/node.d.ts +160 -0
  130. package/src/view/node.js +26 -100
  131. package/src/view/observer/arrowkeysobserver.d.ts +41 -0
  132. package/src/view/observer/arrowkeysobserver.js +0 -13
  133. package/src/view/observer/bubblingemittermixin.d.ts +166 -0
  134. package/src/view/observer/bubblingemittermixin.js +36 -25
  135. package/src/view/observer/bubblingeventinfo.d.ts +47 -0
  136. package/src/view/observer/bubblingeventinfo.js +3 -29
  137. package/src/view/observer/clickobserver.d.ts +43 -0
  138. package/src/view/observer/clickobserver.js +9 -19
  139. package/src/view/observer/compositionobserver.d.ts +82 -0
  140. package/src/view/observer/compositionobserver.js +13 -42
  141. package/src/view/observer/domeventdata.d.ts +50 -0
  142. package/src/view/observer/domeventdata.js +5 -30
  143. package/src/view/observer/domeventobserver.d.ts +69 -0
  144. package/src/view/observer/domeventobserver.js +19 -21
  145. package/src/view/observer/fakeselectionobserver.d.ts +46 -0
  146. package/src/view/observer/fakeselectionobserver.js +2 -15
  147. package/src/view/observer/focusobserver.d.ts +82 -0
  148. package/src/view/observer/focusobserver.js +14 -40
  149. package/src/view/observer/inputobserver.d.ts +86 -0
  150. package/src/view/observer/inputobserver.js +18 -64
  151. package/src/view/observer/keyobserver.d.ts +67 -0
  152. package/src/view/observer/keyobserver.js +8 -42
  153. package/src/view/observer/mouseobserver.d.ts +89 -0
  154. package/src/view/observer/mouseobserver.js +8 -28
  155. package/src/view/observer/mutationobserver.d.ts +82 -0
  156. package/src/view/observer/mutationobserver.js +7 -37
  157. package/src/view/observer/observer.d.ts +84 -0
  158. package/src/view/observer/observer.js +12 -25
  159. package/src/view/observer/selectionobserver.d.ts +143 -0
  160. package/src/view/observer/selectionobserver.js +9 -99
  161. package/src/view/observer/tabobserver.d.ts +42 -0
  162. package/src/view/observer/tabobserver.js +0 -14
  163. package/src/view/placeholder.d.ts +85 -0
  164. package/src/view/placeholder.js +26 -43
  165. package/src/view/position.d.ts +189 -0
  166. package/src/view/position.js +36 -83
  167. package/src/view/range.d.ts +279 -0
  168. package/src/view/range.js +79 -122
  169. package/src/view/rawelement.d.ts +73 -0
  170. package/src/view/rawelement.js +34 -48
  171. package/src/view/renderer.d.ts +265 -0
  172. package/src/view/renderer.js +105 -193
  173. package/src/view/rooteditableelement.d.ts +41 -0
  174. package/src/view/rooteditableelement.js +12 -40
  175. package/src/view/selection.d.ts +375 -0
  176. package/src/view/selection.js +79 -153
  177. package/src/view/styles/background.d.ts +33 -0
  178. package/src/view/styles/background.js +14 -12
  179. package/src/view/styles/border.d.ts +43 -0
  180. package/src/view/styles/border.js +58 -48
  181. package/src/view/styles/margin.d.ts +29 -0
  182. package/src/view/styles/margin.js +13 -11
  183. package/src/view/styles/padding.d.ts +29 -0
  184. package/src/view/styles/padding.js +13 -11
  185. package/src/view/styles/utils.d.ts +93 -0
  186. package/src/view/styles/utils.js +22 -48
  187. package/src/view/stylesmap.d.ts +675 -0
  188. package/src/view/stylesmap.js +249 -244
  189. package/src/view/text.d.ts +74 -0
  190. package/src/view/text.js +16 -46
  191. package/src/view/textproxy.d.ts +97 -0
  192. package/src/view/textproxy.js +10 -59
  193. package/src/view/treewalker.d.ts +195 -0
  194. package/src/view/treewalker.js +43 -106
  195. package/src/view/typecheckable.d.ts +401 -0
  196. package/src/view/uielement.d.ts +96 -0
  197. package/src/view/uielement.js +28 -62
  198. package/src/view/upcastwriter.d.ts +328 -0
  199. package/src/view/upcastwriter.js +124 -134
  200. package/src/view/view.d.ts +327 -0
  201. package/src/view/view.js +79 -150
@@ -0,0 +1,37 @@
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
+ import type Node from '../node';
6
+ import type Position from '../position';
7
+ import type Schema from '../schema';
8
+ import type Writer from '../writer';
9
+ /**
10
+ * @module engine/model/utils/autoparagraphing
11
+ */
12
+ /**
13
+ * Fixes all empty roots.
14
+ *
15
+ * @internal
16
+ * @param writer The model writer.
17
+ * @returns `true` if any change has been applied, `false` otherwise.
18
+ */
19
+ export declare function autoParagraphEmptyRoots(writer: Writer): boolean;
20
+ /**
21
+ * Checks if the given node wrapped with a paragraph would be accepted by the schema in the given position.
22
+ *
23
+ * @internal
24
+ * @param position The position at which to check.
25
+ * @param nodeOrType The child node or child type to check.
26
+ * @param schema A schema instance used for element validation.
27
+ */
28
+ export declare function isParagraphable(position: Position, nodeOrType: Node | string, schema: Schema): boolean;
29
+ /**
30
+ * Inserts a new paragraph at the given position and returns a position inside that paragraph.
31
+ *
32
+ * @internal
33
+ * @param position The position where a paragraph should be inserted.
34
+ * @param writer The model writer.
35
+ * @returns Position inside the created paragraph.
36
+ */
37
+ export declare function wrapInParagraph(position: Position, writer: Writer): Position;
@@ -0,0 +1,58 @@
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/model/utils/deletecontent
7
+ */
8
+ import DocumentSelection from '../documentselection';
9
+ import type Model from '../model';
10
+ import type Selection from '../selection';
11
+ /**
12
+ * Deletes content of the selection and merge siblings. The resulting selection is always collapsed.
13
+ *
14
+ * **Note:** Use {@link module:engine/model/model~Model#deleteContent} instead of this function.
15
+ * This function is only exposed to be reusable in algorithms
16
+ * which change the {@link module:engine/model/model~Model#deleteContent}
17
+ * method's behavior.
18
+ *
19
+ * @param model The model in context of which the insertion should be performed.
20
+ * @param selection Selection of which the content should be deleted.
21
+ * @param options.leaveUnmerged Whether to merge elements after removing the content of the selection.
22
+ *
23
+ * For example `<heading>x[x</heading><paragraph>y]y</paragraph>` will become:
24
+ *
25
+ * * `<heading>x^y</heading>` with the option disabled (`leaveUnmerged == false`)
26
+ * * `<heading>x^</heading><paragraph>y</paragraph>` with enabled (`leaveUnmerged == true`).
27
+ *
28
+ * Note: {@link module:engine/model/schema~Schema#isObject object} and {@link module:engine/model/schema~Schema#isLimit limit}
29
+ * elements will not be merged.
30
+ *
31
+ * @param options.doNotResetEntireContent Whether to skip replacing the entire content with a
32
+ * paragraph when the entire content was selected.
33
+ *
34
+ * For example `<heading>[x</heading><paragraph>y]</paragraph>` will become:
35
+ *
36
+ * * `<paragraph>^</paragraph>` with the option disabled (`doNotResetEntireContent == false`)
37
+ * * `<heading>^</heading>` with enabled (`doNotResetEntireContent == true`).
38
+ *
39
+ * @param options.doNotAutoparagraph Whether to create a paragraph if after content deletion selection is moved
40
+ * to a place where text cannot be inserted.
41
+ *
42
+ * For example `<paragraph>x</paragraph>[<imageBlock src="foo.jpg"></imageBlock>]` will become:
43
+ *
44
+ * * `<paragraph>x</paragraph><paragraph>[]</paragraph>` with the option disabled (`doNotAutoparagraph == false`)
45
+ * * `<paragraph>x</paragraph>[]` with the option enabled (`doNotAutoparagraph == true`).
46
+ *
47
+ * If you use this option you need to make sure to handle invalid selections yourself or leave
48
+ * them to the selection post-fixer (may not always work).
49
+ *
50
+ * **Note:** If there is no valid position for the selection, the paragraph will always be created:
51
+ *
52
+ * `[<imageBlock src="foo.jpg"></imageBlock>]` -> `<paragraph>[]</paragraph>`.
53
+ */
54
+ export default function deleteContent(model: Model, selection: Selection | DocumentSelection, options?: {
55
+ leaveUnmerged?: boolean;
56
+ doNotResetEntireContent?: boolean;
57
+ doNotAutoparagraph?: boolean;
58
+ }): void;
@@ -0,0 +1,32 @@
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
+ import type DocumentSelection from '../documentselection';
6
+ import type Model from '../model';
7
+ import type Range from '../range';
8
+ import type Selection from '../selection';
9
+ /**
10
+ * Returns a model range which is optimal (in terms of UX) for inserting a widget block.
11
+ *
12
+ * For instance, if a selection is in the middle of a paragraph, the collapsed range before this paragraph
13
+ * will be returned so that it is not split. If the selection is at the end of a paragraph,
14
+ * the collapsed range after this paragraph will be returned.
15
+ *
16
+ * Note: If the selection is placed in an empty block, the range in that block will be returned. If that range
17
+ * is then passed to {@link module:engine/model/model~Model#insertContent}, the block will be fully replaced
18
+ * by the inserted widget block.
19
+ *
20
+ * **Note:** Use {@link module:widget/utils#findOptimalInsertionRange} instead of this function outside engine.
21
+ * This function is only exposed to be used by {@link module:widget/utils#findOptimalInsertionRange findOptimalInsertionRange()}
22
+ * in the `widget` package and inside the `engine` package.
23
+ *
24
+ * @param selection The selection based on which the insertion position should be calculated.
25
+ * @param model Model instance.
26
+ * @param place The place where to look for optimal insertion range.
27
+ * The default `auto` value will determine itself the best position for insertion.
28
+ * The `before` value will try to find a position before selection.
29
+ * The `after` value will try to find a position after selection.
30
+ * @returns The optimal range.
31
+ */
32
+ export declare function findOptimalInsertionRange(selection: Selection | DocumentSelection, model: Model, place?: 'auto' | 'before' | 'after'): Range;
@@ -0,0 +1,30 @@
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
+ import type DocumentFragment from '../documentfragment';
6
+ import type DocumentSelection from '../documentselection';
7
+ import type Model from '../model';
8
+ import type Selection from '../selection';
9
+ /**
10
+ * @module engine/model/utils/getselectedcontent
11
+ */
12
+ /**
13
+ * Gets a clone of the selected content.
14
+ *
15
+ * For example, for the following selection:
16
+ *
17
+ * ```html
18
+ * <p>x</p><quote><p>y</p><h>fir[st</h></quote><p>se]cond</p><p>z</p>
19
+ * ```
20
+ *
21
+ * It will return a document fragment with such a content:
22
+ *
23
+ * ```html
24
+ * <quote><h>st</h></quote><p>se</p>
25
+ * ```
26
+ *
27
+ * @param model The model in context of which the selection modification should be performed.
28
+ * @param selection The selection of which content will be returned.
29
+ */
30
+ export default function getSelectedContent(model: Model, selection: Selection | DocumentSelection): DocumentFragment;
@@ -0,0 +1,46 @@
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/model/utils/insertcontent
7
+ */
8
+ import DocumentSelection from '../documentselection';
9
+ import Range from '../range';
10
+ import type DocumentFragment from '../documentfragment';
11
+ import type Item from '../item';
12
+ import type Model from '../model';
13
+ import type Selection from '../selection';
14
+ /**
15
+ * Inserts content into the editor (specified selection) as one would expect the paste functionality to work.
16
+ *
17
+ * It takes care of removing the selected content, splitting elements (if needed), inserting elements and merging elements appropriately.
18
+ *
19
+ * Some examples:
20
+ *
21
+ * ```html
22
+ * <p>x^</p> + <p>y</p> => <p>x</p><p>y</p> => <p>xy[]</p>
23
+ * <p>x^y</p> + <p>z</p> => <p>x</p>^<p>y</p> + <p>z</p> => <p>x</p><p>z</p><p>y</p> => <p>xz[]y</p>
24
+ * <p>x^y</p> + <img /> => <p>x</p>^<p>y</p> + <img /> => <p>x</p><img /><p>y</p>
25
+ * <p>x</p><p>^</p><p>z</p> + <p>y</p> => <p>x</p><p>y[]</p><p>z</p> (no merging)
26
+ * <p>x</p>[<img />]<p>z</p> + <p>y</p> => <p>x</p>^<p>z</p> + <p>y</p> => <p>x</p><p>y[]</p><p>z</p>
27
+ * ```
28
+ *
29
+ * If an instance of {@link module:engine/model/selection~Selection} is passed as `selectable` it will be modified
30
+ * to the insertion selection (equal to a range to be selected after insertion).
31
+ *
32
+ * If `selectable` is not passed, the content will be inserted using the current selection of the model document.
33
+ *
34
+ * **Note:** Use {@link module:engine/model/model~Model#insertContent} instead of this function.
35
+ * This function is only exposed to be reusable in algorithms which change the {@link module:engine/model/model~Model#insertContent}
36
+ * method's behavior.
37
+ *
38
+ * @param model The model in context of which the insertion should be performed.
39
+ * @param content The content to insert.
40
+ * @param selectable Selection into which the content should be inserted.
41
+ * @param placeOrOffset Sets place or offset of the selection.
42
+ * @returns Range which contains all the performed changes. This is a range that, if removed,
43
+ * would return the model to the state before the insertion. If no changes were preformed by `insertContent`, returns a range collapsed
44
+ * at the insertion position.
45
+ */
46
+ export default function insertContent(model: Model, content: Item | DocumentFragment, selectable?: Selection | DocumentSelection): Range;
@@ -11,7 +11,6 @@ import LivePosition from '../liveposition';
11
11
  import LiveRange from '../liverange';
12
12
  import Position from '../position';
13
13
  import Range from '../range';
14
- import Selection from '../selection';
15
14
  import { CKEditorError } from '@ckeditor/ckeditor5-utils';
16
15
  /**
17
16
  * Inserts content into the editor (specified selection) as one would expect the paste functionality to work.
@@ -45,18 +44,9 @@ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
45
44
  * would return the model to the state before the insertion. If no changes were preformed by `insertContent`, returns a range collapsed
46
45
  * at the insertion position.
47
46
  */
48
- export default function insertContent(model, content, selectable, placeOrOffset) {
47
+ export default function insertContent(model, content, selectable) {
49
48
  return model.change(writer => {
50
- let selection;
51
- if (!selectable) {
52
- selection = model.document.selection;
53
- }
54
- else if (selectable instanceof Selection || selectable instanceof DocumentSelection) {
55
- selection = selectable;
56
- }
57
- else {
58
- selection = writer.createSelection(selectable, placeOrOffset);
59
- }
49
+ const selection = selectable ? selectable : model.document.selection;
60
50
  if (!selection.isCollapsed) {
61
51
  model.deleteContent(selection, { doNotAutoparagraph: true });
62
52
  }
@@ -0,0 +1,44 @@
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
+ import type DocumentSelection from '../documentselection';
6
+ import type Selection from '../selection';
7
+ import type Element from '../element';
8
+ import type Model from '../model';
9
+ import type Range from '../range';
10
+ /**
11
+ * Inserts an {@glink framework/deep-dive/schema#object-elements object element} at a specific position in the editor content.
12
+ *
13
+ * **Note:** Use {@link module:engine/model/model~Model#insertObject} instead of this function.
14
+ * This function is only exposed to be reusable in algorithms which change the {@link module:engine/model/model~Model#insertObject}
15
+ * method's behavior.
16
+ *
17
+ * **Note**: For more documentation and examples, see {@link module:engine/model/model~Model#insertObject}.
18
+ *
19
+ * @param model The model in context of which the insertion should be performed.
20
+ * @param object An object to be inserted into the model document.
21
+ * @param selectable A selectable where the content should be inserted. If not specified, the current
22
+ * {@link module:engine/model/document~Document#selection document selection} will be used instead.
23
+ * @param placeOrOffset Specifies the exact place or offset for the insertion to take place, relative to `selectable`.
24
+ * @param options Additional options.
25
+ * @param options.findOptimalPosition An option that, when set, adjusts the insertion position (relative to
26
+ * `selectable` and `placeOrOffset`) so that the content of `selectable` is not split upon insertion (a.k.a. non-destructive insertion).
27
+ * * When `'auto'`, the algorithm will decide whether to insert the object before or after `selectable` to avoid content splitting.
28
+ * * When `'before'`, the closest position before `selectable` will be used that will not result in content splitting.
29
+ * * When `'after'`, the closest position after `selectable` will be used that will not result in content splitting.
30
+ *
31
+ * Note that this option works only for block objects. Inline objects are inserted into text and do not split blocks.
32
+ * @param options.setSelection An option that, when set, moves the
33
+ * {@link module:engine/model/document~Document#selection document selection} after inserting the object.
34
+ * * When `'on'`, the document selection will be set on the inserted object.
35
+ * * When `'after'`, the document selection will move to the closest text node after the inserted object. If there is no
36
+ * such text node, a paragraph will be created and the document selection will be moved inside it.
37
+ * @returns A range which contains all the performed changes. This is a range that, if removed,
38
+ * would return the model to the state before the insertion. If no changes were preformed by `insertObject()`, returns a range collapsed
39
+ * at the insertion position.
40
+ */
41
+ export default function insertObject(model: Model, object: Element, selectable?: Selection | DocumentSelection | null, options?: {
42
+ findOptimalPosition?: 'auto' | 'before' | 'after';
43
+ setSelection?: 'on' | 'after';
44
+ }): Range;
@@ -6,11 +6,9 @@
6
6
  * @module engine/model/utils/insertobject
7
7
  */
8
8
  import { findOptimalInsertionRange } from './findoptimalinsertionrange';
9
- import DocumentSelection from '../documentselection';
10
- import Selection from '../selection';
11
9
  import { CKEditorError, first } from '@ckeditor/ckeditor5-utils';
12
10
  /**
13
- * Inserts an {@glink framework/guides/deep-dive/schema#object-elements object element} at a specific position in the editor content.
11
+ * Inserts an {@glink framework/deep-dive/schema#object-elements object element} at a specific position in the editor content.
14
12
  *
15
13
  * **Note:** Use {@link module:engine/model/model~Model#insertObject} instead of this function.
16
14
  * This function is only exposed to be reusable in algorithms which change the {@link module:engine/model/model~Model#insertObject}
@@ -40,7 +38,7 @@ import { CKEditorError, first } from '@ckeditor/ckeditor5-utils';
40
38
  * would return the model to the state before the insertion. If no changes were preformed by `insertObject()`, returns a range collapsed
41
39
  * at the insertion position.
42
40
  */
43
- export default function insertObject(model, object, selectable, placeOrOffset, options = {}) {
41
+ export default function insertObject(model, object, selectable, options = {}) {
44
42
  if (!model.schema.isObject(object)) {
45
43
  /**
46
44
  * Tried to insert an element with {@link module:engine/model/utils/insertobject insertObject()} function
@@ -53,16 +51,7 @@ export default function insertObject(model, object, selectable, placeOrOffset, o
53
51
  throw new CKEditorError('insertobject-element-not-an-object', model, { object });
54
52
  }
55
53
  // Normalize selectable to a selection instance.
56
- let originalSelection;
57
- if (!selectable) {
58
- originalSelection = model.document.selection;
59
- }
60
- else if (selectable instanceof Selection || selectable instanceof DocumentSelection) {
61
- originalSelection = selectable;
62
- }
63
- else {
64
- originalSelection = model.createSelection(selectable, placeOrOffset);
65
- }
54
+ const originalSelection = selectable ? selectable : model.document.selection;
66
55
  // Adjust the insertion selection.
67
56
  let insertionSelection = originalSelection;
68
57
  if (options.findOptimalPosition && model.schema.isBlock(object)) {
@@ -0,0 +1,48 @@
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/model/utils/modifyselection
7
+ */
8
+ import DocumentSelection from '../documentselection';
9
+ import type Model from '../model';
10
+ import type Selection from '../selection';
11
+ /**
12
+ * Modifies the selection. Currently, the supported modifications are:
13
+ *
14
+ * * Extending. The selection focus is moved in the specified `options.direction` with a step specified in `options.unit`.
15
+ * Possible values for `unit` are:
16
+ * * `'character'` (default) - moves selection by one user-perceived character. In most cases this means moving by one
17
+ * character in `String` sense. However, unicode also defines "combing marks". These are special symbols, that combines
18
+ * with a symbol before it ("base character") to create one user-perceived character. For example, `q̣̇` is a normal
19
+ * letter `q` with two "combining marks": upper dot (`Ux0307`) and lower dot (`Ux0323`). For most actions, i.e. extending
20
+ * selection by one position, it is correct to include both "base character" and all of it's "combining marks". That is
21
+ * why `'character'` value is most natural and common method of modifying selection.
22
+ * * `'codePoint'` - moves selection by one unicode code point. In contrary to, `'character'` unit, this will insert
23
+ * selection between "base character" and "combining mark", because "combining marks" have their own unicode code points.
24
+ * However, for technical reasons, unicode code points with values above `UxFFFF` are represented in native `String` by
25
+ * two characters, called "surrogate pairs". Halves of "surrogate pairs" have a meaning only when placed next to each other.
26
+ * For example `𨭎` is represented in `String` by `\uD862\uDF4E`. Both `\uD862` and `\uDF4E` do not have any meaning
27
+ * outside the pair (are rendered as ? when alone). Position between them would be incorrect. In this case, selection
28
+ * extension will include whole "surrogate pair".
29
+ * * `'word'` - moves selection by a whole word.
30
+ *
31
+ * **Note:** if you extend a forward selection in a backward direction you will in fact shrink it.
32
+ *
33
+ * **Note:** Use {@link module:engine/model/model~Model#modifySelection} instead of this function.
34
+ * This function is only exposed to be reusable in algorithms
35
+ * which change the {@link module:engine/model/model~Model#modifySelection}
36
+ * method's behavior.
37
+ *
38
+ * @param model The model in context of which the selection modification should be performed.
39
+ * @param selection The selection to modify.
40
+ * @param options.direction The direction in which the selection should be modified. Default 'forward'.
41
+ * @param options.unit The unit by which selection should be modified. Default 'character'.
42
+ * @param options.treatEmojiAsSingleUnit Whether multi-characer emoji sequences should be handled as single unit.
43
+ */
44
+ export default function modifySelection(model: Model, selection: Selection | DocumentSelection, options?: {
45
+ direction?: 'forward' | 'backward';
46
+ unit?: 'character' | 'codePoint' | 'word';
47
+ treatEmojiAsSingleUnit?: boolean;
48
+ }): void;
@@ -0,0 +1,65 @@
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
+ import Range from '../range';
6
+ import type Model from '../model';
7
+ /**
8
+ * Injects selection post-fixer to the model.
9
+ *
10
+ * The role of the selection post-fixer is to ensure that the selection is in a correct place
11
+ * after a {@link module:engine/model/model~Model#change `change()`} block was executed.
12
+ *
13
+ * The correct position means that:
14
+ *
15
+ * * All collapsed selection ranges are in a place where the {@link module:engine/model/schema~Schema}
16
+ * allows a `$text`.
17
+ * * None of the selection's non-collapsed ranges crosses a {@link module:engine/model/schema~Schema#isLimit limit element}
18
+ * boundary (a range must be rooted within one limit element).
19
+ * * Only {@link module:engine/model/schema~Schema#isSelectable selectable elements} can be selected from the outside
20
+ * (e.g. `[<paragraph>foo</paragraph>]` is invalid). This rule applies independently to both selection ends, so this
21
+ * selection is correct: `<paragraph>f[oo</paragraph><imageBlock></imageBlock>]`.
22
+ *
23
+ * If the position is not correct, the post-fixer will automatically correct it.
24
+ *
25
+ * ## Fixing a non-collapsed selection
26
+ *
27
+ * See as an example a selection that starts in a P1 element and ends inside the text of a TD element
28
+ * (`[` and `]` are range boundaries and `(l)` denotes an element defined as `isLimit=true`):
29
+ *
30
+ * ```
31
+ * root
32
+ * |- element P1
33
+ * | |- "foo" root
34
+ * |- element TABLE (l) P1 TABLE P2
35
+ * | |- element TR (l) f o[o TR TR b a r
36
+ * | | |- element TD (l) TD TD
37
+ * | | |- "aaa" a]a a b b b
38
+ * | |- element TR (l)
39
+ * | | |- element TD (l) ||
40
+ * | | |- "bbb" ||
41
+ * |- element P2 VV
42
+ * | |- "bar"
43
+ * root
44
+ * P1 TABLE] P2
45
+ * f o[o TR TR b a r
46
+ * TD TD
47
+ * a a a b b b
48
+ * ```
49
+ *
50
+ * In the example above, the TABLE, TR and TD are defined as `isLimit=true` in the schema. The range which is not contained within
51
+ * a single limit element must be expanded to select the outermost limit element. The range end is inside the text node of the TD element.
52
+ * As the TD element is a child of the TR and TABLE elements, where both are defined as `isLimit=true` in the schema, the range must be
53
+ * expanded to select the whole TABLE element.
54
+ *
55
+ * **Note** If the selection contains multiple ranges, the method returns a minimal set of ranges that are not intersecting after expanding
56
+ * them to select `isLimit=true` elements.
57
+ */
58
+ export declare function injectSelectionPostFixer(model: Model): void;
59
+ /**
60
+ * Returns a minimal non-intersecting array of ranges without duplicates.
61
+ *
62
+ * @param ranges Ranges to merge.
63
+ * @returns Array of unique and non-intersecting ranges.
64
+ */
65
+ export declare function mergeIntersectingRanges(ranges: Array<Range>): Array<Range>;