@ckeditor/ckeditor5-engine 34.2.0 → 35.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/CHANGELOG.md +823 -0
  2. package/LICENSE.md +4 -0
  3. package/package.json +32 -25
  4. package/src/controller/datacontroller.js +467 -561
  5. package/src/controller/editingcontroller.js +168 -204
  6. package/src/conversion/conversion.js +541 -565
  7. package/src/conversion/conversionhelpers.js +24 -28
  8. package/src/conversion/downcastdispatcher.js +457 -686
  9. package/src/conversion/downcasthelpers.js +1583 -1965
  10. package/src/conversion/mapper.js +518 -707
  11. package/src/conversion/modelconsumable.js +240 -283
  12. package/src/conversion/upcastdispatcher.js +372 -718
  13. package/src/conversion/upcasthelpers.js +707 -818
  14. package/src/conversion/viewconsumable.js +524 -581
  15. package/src/dataprocessor/basichtmlwriter.js +12 -16
  16. package/src/dataprocessor/dataprocessor.js +5 -0
  17. package/src/dataprocessor/htmldataprocessor.js +101 -117
  18. package/src/dataprocessor/htmlwriter.js +1 -18
  19. package/src/dataprocessor/xmldataprocessor.js +117 -138
  20. package/src/dev-utils/model.js +260 -352
  21. package/src/dev-utils/operationreplayer.js +106 -126
  22. package/src/dev-utils/utils.js +34 -51
  23. package/src/dev-utils/view.js +632 -753
  24. package/src/index.js +0 -11
  25. package/src/model/batch.js +111 -127
  26. package/src/model/differ.js +988 -1233
  27. package/src/model/document.js +340 -449
  28. package/src/model/documentfragment.js +327 -364
  29. package/src/model/documentselection.js +996 -1189
  30. package/src/model/element.js +306 -410
  31. package/src/model/history.js +224 -262
  32. package/src/model/item.js +5 -0
  33. package/src/model/liveposition.js +84 -145
  34. package/src/model/liverange.js +108 -185
  35. package/src/model/markercollection.js +379 -480
  36. package/src/model/model.js +883 -1034
  37. package/src/model/node.js +419 -463
  38. package/src/model/nodelist.js +175 -201
  39. package/src/model/operation/attributeoperation.js +153 -182
  40. package/src/model/operation/detachoperation.js +64 -83
  41. package/src/model/operation/insertoperation.js +135 -166
  42. package/src/model/operation/markeroperation.js +114 -140
  43. package/src/model/operation/mergeoperation.js +163 -191
  44. package/src/model/operation/moveoperation.js +157 -187
  45. package/src/model/operation/nooperation.js +28 -38
  46. package/src/model/operation/operation.js +106 -125
  47. package/src/model/operation/operationfactory.js +30 -34
  48. package/src/model/operation/renameoperation.js +109 -135
  49. package/src/model/operation/rootattributeoperation.js +155 -188
  50. package/src/model/operation/splitoperation.js +196 -232
  51. package/src/model/operation/transform.js +1833 -2204
  52. package/src/model/operation/utils.js +140 -204
  53. package/src/model/position.js +899 -1053
  54. package/src/model/range.js +910 -1028
  55. package/src/model/rootelement.js +77 -97
  56. package/src/model/schema.js +1189 -1835
  57. package/src/model/selection.js +745 -862
  58. package/src/model/text.js +90 -114
  59. package/src/model/textproxy.js +204 -240
  60. package/src/model/treewalker.js +316 -397
  61. package/src/model/typecheckable.js +16 -0
  62. package/src/model/utils/autoparagraphing.js +32 -44
  63. package/src/model/utils/deletecontent.js +334 -418
  64. package/src/model/utils/findoptimalinsertionrange.js +25 -36
  65. package/src/model/utils/getselectedcontent.js +96 -118
  66. package/src/model/utils/insertcontent.js +654 -773
  67. package/src/model/utils/insertobject.js +96 -119
  68. package/src/model/utils/modifyselection.js +120 -158
  69. package/src/model/utils/selection-post-fixer.js +153 -201
  70. package/src/model/writer.js +1305 -1474
  71. package/src/view/attributeelement.js +189 -225
  72. package/src/view/containerelement.js +75 -85
  73. package/src/view/document.js +172 -215
  74. package/src/view/documentfragment.js +200 -249
  75. package/src/view/documentselection.js +338 -367
  76. package/src/view/domconverter.js +1371 -1613
  77. package/src/view/downcastwriter.js +1747 -2076
  78. package/src/view/editableelement.js +81 -97
  79. package/src/view/element.js +739 -890
  80. package/src/view/elementdefinition.js +5 -0
  81. package/src/view/emptyelement.js +82 -92
  82. package/src/view/filler.js +35 -50
  83. package/src/view/item.js +5 -0
  84. package/src/view/matcher.js +260 -559
  85. package/src/view/node.js +274 -360
  86. package/src/view/observer/arrowkeysobserver.js +19 -28
  87. package/src/view/observer/bubblingemittermixin.js +120 -263
  88. package/src/view/observer/bubblingeventinfo.js +47 -55
  89. package/src/view/observer/clickobserver.js +7 -13
  90. package/src/view/observer/compositionobserver.js +14 -24
  91. package/src/view/observer/domeventdata.js +57 -67
  92. package/src/view/observer/domeventobserver.js +40 -64
  93. package/src/view/observer/fakeselectionobserver.js +81 -96
  94. package/src/view/observer/focusobserver.js +45 -61
  95. package/src/view/observer/inputobserver.js +7 -13
  96. package/src/view/observer/keyobserver.js +17 -27
  97. package/src/view/observer/mouseobserver.js +7 -14
  98. package/src/view/observer/mutationobserver.js +220 -315
  99. package/src/view/observer/observer.js +81 -102
  100. package/src/view/observer/selectionobserver.js +191 -246
  101. package/src/view/observer/tabobserver.js +23 -36
  102. package/src/view/placeholder.js +128 -173
  103. package/src/view/position.js +350 -401
  104. package/src/view/range.js +453 -513
  105. package/src/view/rawelement.js +85 -112
  106. package/src/view/renderer.js +874 -1014
  107. package/src/view/rooteditableelement.js +80 -90
  108. package/src/view/selection.js +608 -689
  109. package/src/view/styles/background.js +43 -44
  110. package/src/view/styles/border.js +220 -276
  111. package/src/view/styles/margin.js +8 -17
  112. package/src/view/styles/padding.js +8 -16
  113. package/src/view/styles/utils.js +127 -160
  114. package/src/view/stylesmap.js +728 -905
  115. package/src/view/text.js +102 -126
  116. package/src/view/textproxy.js +144 -170
  117. package/src/view/treewalker.js +383 -479
  118. package/src/view/typecheckable.js +19 -0
  119. package/src/view/uielement.js +166 -187
  120. package/src/view/upcastwriter.js +395 -449
  121. package/src/view/view.js +569 -664
  122. package/src/dataprocessor/dataprocessor.jsdoc +0 -64
  123. package/src/model/item.jsdoc +0 -14
  124. package/src/view/elementdefinition.jsdoc +0 -59
  125. package/src/view/item.jsdoc +0 -14
@@ -2,139 +2,119 @@
2
2
  * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module engine/dev-utils/operationreplayer
8
7
  */
9
-
10
8
  /* global setTimeout */
11
-
12
9
  import OperationFactory from '../model/operation/operationfactory';
13
-
14
10
  /**
15
11
  * Operation replayer is a development tool created for easy replaying of operations on the document from stringified operations.
16
12
  */
17
13
  export default class OperationReplayer {
18
- /**
19
- * @param {module:engine/model/model~Model} model Data model.
20
- * @param {String} logSeparator Separator between operations.
21
- * @param {String} stringifiedOperations Operations to replay.
22
- */
23
- constructor( model, logSeparator, stringifiedOperations ) {
24
- this._model = model;
25
- this._logSeparator = logSeparator;
26
- this.setStringifiedOperations( stringifiedOperations );
27
- }
28
-
29
- /**
30
- * Parses the given string containing stringified operations and sets parsed operations as operations to replay.
31
- *
32
- * @param {String} stringifiedOperations Stringified operations to replay.
33
- */
34
- setStringifiedOperations( stringifiedOperations ) {
35
- if ( stringifiedOperations === '' ) {
36
- this._operationsToReplay = [];
37
-
38
- return;
39
- }
40
-
41
- this._operationsToReplay = stringifiedOperations
42
- .split( this._logSeparator )
43
- .map( stringifiedOperation => JSON.parse( stringifiedOperation ) );
44
- }
45
-
46
- /**
47
- * Returns operations to replay.
48
- *
49
- * @returns {Array.<module:engine/model/operation/operation~Operation>}
50
- */
51
- getOperationsToReplay() {
52
- return this._operationsToReplay;
53
- }
54
-
55
- /**
56
- * Applies all operations with a delay between actions.
57
- *
58
- * @param {Number} timeInterval Time between applying operations.
59
- * @returns {Promise}
60
- */
61
- play( timeInterval = 1000 ) {
62
- const operationReplayer = this; // eslint-disable-line consistent-this
63
-
64
- return new Promise( ( res, rej ) => {
65
- play();
66
-
67
- function play() {
68
- operationReplayer.applyNextOperation().then( isFinished => {
69
- if ( isFinished ) {
70
- return res();
71
- }
72
-
73
- setTimeout( play, timeInterval );
74
- } ).catch( err => {
75
- rej( err );
76
- } );
77
- }
78
- } );
79
- }
80
-
81
- /**
82
- * Applies `numberOfOperations` operations, beginning after the last applied operation (or first, if no operations were applied).
83
- *
84
- * @param {Number} numberOfOperations The number of operations to apply.
85
- * @returns {Promise}
86
- */
87
- applyOperations( numberOfOperations ) {
88
- if ( numberOfOperations <= 0 ) {
89
- return;
90
- }
91
-
92
- return this.applyNextOperation()
93
- .then( isFinished => {
94
- if ( !isFinished ) {
95
- return this.applyOperations( numberOfOperations - 1 );
96
- }
97
- } );
98
- }
99
-
100
- /**
101
- * Applies all operations to replay at once.
102
- *
103
- * @returns {Promise}
104
- */
105
- applyAllOperations() {
106
- return this.applyNextOperation()
107
- .then( isFinished => {
108
- if ( !isFinished ) {
109
- return this.applyAllOperations();
110
- }
111
- } );
112
- }
113
-
114
- /**
115
- * Applies the next operation to replay. Returns a promise with the `isFinished` parameter that is `true` if the last
116
- * operation in the replayer has been applied, `false` otherwise.
117
- *
118
- * @returns {Promise.<Boolean>}
119
- */
120
- applyNextOperation() {
121
- const model = this._model;
122
-
123
- return new Promise( res => {
124
- model.enqueueChange( writer => {
125
- const operationJson = this._operationsToReplay.shift();
126
-
127
- if ( !operationJson ) {
128
- return res( true );
129
- }
130
-
131
- const operation = OperationFactory.fromJSON( operationJson, model.document );
132
-
133
- writer.batch.addOperation( operation );
134
- model.applyOperation( operation );
135
-
136
- res( false );
137
- } );
138
- } );
139
- }
14
+ /**
15
+ * @param {module:engine/model/model~Model} model Data model.
16
+ * @param {String} logSeparator Separator between operations.
17
+ * @param {String} stringifiedOperations Operations to replay.
18
+ */
19
+ constructor(model, logSeparator, stringifiedOperations) {
20
+ this._model = model;
21
+ this._logSeparator = logSeparator;
22
+ this.setStringifiedOperations(stringifiedOperations);
23
+ }
24
+ /**
25
+ * Parses the given string containing stringified operations and sets parsed operations as operations to replay.
26
+ *
27
+ * @param {String} stringifiedOperations Stringified operations to replay.
28
+ */
29
+ setStringifiedOperations(stringifiedOperations) {
30
+ if (stringifiedOperations === '') {
31
+ this._operationsToReplay = [];
32
+ return;
33
+ }
34
+ this._operationsToReplay = stringifiedOperations
35
+ .split(this._logSeparator)
36
+ .map(stringifiedOperation => JSON.parse(stringifiedOperation));
37
+ }
38
+ /**
39
+ * Returns operations to replay.
40
+ *
41
+ * @returns {Array.<module:engine/model/operation/operation~Operation>}
42
+ */
43
+ getOperationsToReplay() {
44
+ return this._operationsToReplay;
45
+ }
46
+ /**
47
+ * Applies all operations with a delay between actions.
48
+ *
49
+ * @param {Number} timeInterval Time between applying operations.
50
+ * @returns {Promise}
51
+ */
52
+ play(timeInterval = 1000) {
53
+ // eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this
54
+ const operationReplayer = this;
55
+ return new Promise((res, rej) => {
56
+ play();
57
+ function play() {
58
+ operationReplayer.applyNextOperation().then(isFinished => {
59
+ if (isFinished) {
60
+ return res();
61
+ }
62
+ setTimeout(play, timeInterval);
63
+ }).catch(err => {
64
+ rej(err);
65
+ });
66
+ }
67
+ });
68
+ }
69
+ /**
70
+ * Applies `numberOfOperations` operations, beginning after the last applied operation (or first, if no operations were applied).
71
+ *
72
+ * @param {Number} numberOfOperations The number of operations to apply.
73
+ * @returns {Promise}
74
+ */
75
+ applyOperations(numberOfOperations) {
76
+ if (numberOfOperations <= 0) {
77
+ return;
78
+ }
79
+ return this.applyNextOperation()
80
+ .then(isFinished => {
81
+ if (!isFinished) {
82
+ return this.applyOperations(numberOfOperations - 1);
83
+ }
84
+ });
85
+ }
86
+ /**
87
+ * Applies all operations to replay at once.
88
+ *
89
+ * @returns {Promise}
90
+ */
91
+ applyAllOperations() {
92
+ return this.applyNextOperation()
93
+ .then(isFinished => {
94
+ if (!isFinished) {
95
+ return this.applyAllOperations();
96
+ }
97
+ });
98
+ }
99
+ /**
100
+ * Applies the next operation to replay. Returns a promise with the `isFinished` parameter that is `true` if the last
101
+ * operation in the replayer has been applied, `false` otherwise.
102
+ *
103
+ * @returns {Promise.<Boolean>}
104
+ */
105
+ applyNextOperation() {
106
+ const model = this._model;
107
+ return new Promise(res => {
108
+ model.enqueueChange(writer => {
109
+ const operationJson = this._operationsToReplay.shift();
110
+ if (!operationJson) {
111
+ return res(true);
112
+ }
113
+ const operation = OperationFactory.fromJSON(operationJson, model.document);
114
+ writer.batch.addOperation(operation);
115
+ model.applyOperation(operation);
116
+ res(false);
117
+ });
118
+ });
119
+ }
140
120
  }
@@ -2,7 +2,6 @@
2
2
  * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * Note: This package is used only internally for debugging purposes and should not be used
8
7
  * in other environments. It uses a few special methods not existing in the default
@@ -10,9 +9,7 @@
10
9
  *
11
10
  * @module engine/dev-utils/utils
12
11
  */
13
-
14
12
  /* globals console */
15
-
16
13
  /**
17
14
  * Helper function, converts a map to the 'key1="value1" key2="value1"' format.
18
15
  *
@@ -20,16 +17,13 @@
20
17
  * @param {Map} map Map to convert.
21
18
  * @returns {String} Converted map.
22
19
  */
23
- export function convertMapToTags( map ) {
24
- let string = '';
25
-
26
- for ( const entry of map ) {
27
- string += ` ${ entry[ 0 ] }=${ JSON.stringify( entry[ 1 ] ) }`;
28
- }
29
-
30
- return string;
20
+ export function convertMapToTags(map) {
21
+ let string = '';
22
+ for (const entry of map) {
23
+ string += ` ${entry[0]}=${JSON.stringify(entry[1])}`;
24
+ }
25
+ return string;
31
26
  }
32
-
33
27
  /**
34
28
  * Helper function, converts a map to the '{"key1":"value1","key2":"value2"}' format.
35
29
  *
@@ -37,19 +31,15 @@ export function convertMapToTags( map ) {
37
31
  * @param {Map} map Map to convert.
38
32
  * @returns {String} Converted map.
39
33
  */
40
- export function convertMapToStringifiedObject( map ) {
41
- const obj = {};
42
-
43
- for ( const entry of map ) {
44
- obj[ entry[ 0 ] ] = entry[ 1 ];
45
- }
46
-
47
- return JSON.stringify( obj );
34
+ export function convertMapToStringifiedObject(map) {
35
+ const obj = {};
36
+ for (const entry of map) {
37
+ obj[entry[0]] = entry[1];
38
+ }
39
+ return JSON.stringify(obj);
48
40
  }
49
-
50
- const treeDump = Symbol( '_treeDump' );
41
+ const treeDump = Symbol('_treeDump');
51
42
  const maxTreeDumpLength = 20;
52
-
53
43
  /**
54
44
  * Helper function that stores the `document` state for a given `version`.
55
45
  *
@@ -57,34 +47,27 @@ const maxTreeDumpLength = 20;
57
47
  * @param {*} document
58
48
  * @param {*} version
59
49
  */
60
- export function dumpTrees( document, version ) {
61
- console.log( document, version );
62
-
63
- let string = '';
64
-
65
- for ( const root of document.roots ) {
66
- string += root.printTree() + '\n';
67
- }
68
-
69
- document[ treeDump ][ version ] = string.substr( 0, string.length - 1 ); // Remove the last "\n".
70
-
71
- const overflow = document[ treeDump ].length - maxTreeDumpLength;
72
-
73
- if ( overflow > 0 ) {
74
- document[ treeDump ][ overflow - 1 ] = null;
75
- }
50
+ export function dumpTrees(document, version) {
51
+ console.log(document, version);
52
+ let string = '';
53
+ for (const root of document.roots) {
54
+ string += root.printTree() + '\n';
55
+ }
56
+ document[treeDump][version] = string.substr(0, string.length - 1); // Remove the last "\n".
57
+ const overflow = document[treeDump].length - maxTreeDumpLength;
58
+ if (overflow > 0) {
59
+ document[treeDump][overflow - 1] = null;
60
+ }
76
61
  }
77
-
78
62
  /**
79
63
  * Helper function that initializes document dumping.
80
64
  *
81
65
  * @private
82
66
  * @param {*} document
83
67
  */
84
- export function initDocumentDumping( document ) {
85
- document[ treeDump ] = [];
68
+ export function initDocumentDumping(document) {
69
+ document[treeDump] = [];
86
70
  }
87
-
88
71
  /**
89
72
  * Helper function that logs document for the given version.
90
73
  *
@@ -92,12 +75,12 @@ export function initDocumentDumping( document ) {
92
75
  * @param {*} document
93
76
  * @param {*} version
94
77
  */
95
- export function logDocument( document, version ) {
96
- console.log( '--------------------' );
97
-
98
- if ( document[ treeDump ][ version ] ) {
99
- console.log( document[ treeDump ][ version ] );
100
- } else {
101
- console.log( 'Tree log unavailable for given version: ' + version );
102
- }
78
+ export function logDocument(document, version) {
79
+ console.log('--------------------');
80
+ if (document[treeDump][version]) {
81
+ console.log(document[treeDump][version]);
82
+ }
83
+ else {
84
+ console.log('Tree log unavailable for given version: ' + version);
85
+ }
103
86
  }