@ckeditor/ckeditor5-engine 41.1.0 → 41.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-engine",
3
- "version": "41.1.0",
3
+ "version": "41.2.1",
4
4
  "description": "The editing engine of CKEditor 5 – the best browser-based rich text editor.",
5
5
  "keywords": [
6
6
  "wysiwyg",
@@ -24,7 +24,7 @@
24
24
  "type": "module",
25
25
  "main": "src/index.js",
26
26
  "dependencies": {
27
- "@ckeditor/ckeditor5-utils": "41.1.0",
27
+ "@ckeditor/ckeditor5-utils": "41.2.1",
28
28
  "lodash-es": "4.17.21"
29
29
  },
30
30
  "author": "CKSource (http://cksource.com/)",
@@ -5,8 +5,7 @@
5
5
  /**
6
6
  * @module engine/conversion/viewconsumable
7
7
  */
8
- import { CKEditorError } from '@ckeditor/ckeditor5-utils';
9
- import { isArray } from 'lodash-es';
8
+ import { CKEditorError, toArray } from '@ckeditor/ckeditor5-utils';
10
9
  /**
11
10
  * Class used for handling consumption of view {@link module:engine/view/element~Element elements},
12
11
  * {@link module:engine/view/text~Text text nodes} and {@link module:engine/view/documentfragment~DocumentFragment document fragments}.
@@ -420,7 +419,7 @@ export class ViewElementConsumables {
420
419
  * @param item Consumable item or array of items.
421
420
  */
422
421
  _add(type, item) {
423
- const items = isArray(item) ? item : [item];
422
+ const items = toArray(item);
424
423
  const consumables = this._consumables[type];
425
424
  for (const name of items) {
426
425
  if (type === 'attributes' && (name === 'class' || name === 'style')) {
@@ -461,7 +460,7 @@ export class ViewElementConsumables {
461
460
  * consumed and `false` when one of the items is already consumed.
462
461
  */
463
462
  _test(type, item) {
464
- const items = isArray(item) ? item : [item];
463
+ const items = toArray(item);
465
464
  const consumables = this._consumables[type];
466
465
  for (const name of items) {
467
466
  if (type === 'attributes' && (name === 'class' || name === 'style')) {
@@ -492,7 +491,7 @@ export class ViewElementConsumables {
492
491
  * @param item Consumable item or array of items.
493
492
  */
494
493
  _consume(type, item) {
495
- const items = isArray(item) ? item : [item];
494
+ const items = toArray(item);
496
495
  const consumables = this._consumables[type];
497
496
  for (const name of items) {
498
497
  if (type === 'attributes' && (name === 'class' || name === 'style')) {
@@ -517,7 +516,7 @@ export class ViewElementConsumables {
517
516
  * @param item Consumable item or array of items.
518
517
  */
519
518
  _revert(type, item) {
520
- const items = isArray(item) ? item : [item];
519
+ const items = toArray(item);
521
520
  const consumables = this._consumables[type];
522
521
  for (const name of items) {
523
522
  if (type === 'attributes' && (name === 'class' || name === 'style')) {
package/src/index.d.ts CHANGED
@@ -105,7 +105,7 @@ export type { ViewDocumentTabEvent } from './view/observer/tabobserver.js';
105
105
  export type { ViewDocumentClickEvent } from './view/observer/clickobserver.js';
106
106
  export type { ViewDocumentSelectionChangeEvent } from './view/observer/selectionobserver.js';
107
107
  export type { ViewRenderEvent, ViewScrollToTheSelectionEvent } from './view/view.js';
108
- export { StylesProcessor, type BoxSides } from './view/stylesmap.js';
108
+ export { default as StylesMap, StylesProcessor, type BoxSides } from './view/stylesmap.js';
109
109
  export * from './view/styles/background.js';
110
110
  export * from './view/styles/border.js';
111
111
  export * from './view/styles/margin.js';
package/src/index.js CHANGED
@@ -69,7 +69,7 @@ export { default as Matcher } from './view/matcher.js';
69
69
  export { default as BubblingEventInfo } from './view/observer/bubblingeventinfo.js';
70
70
  export { default as DomEventData } from './view/observer/domeventdata.js';
71
71
  // View / Styles.
72
- export { StylesProcessor } from './view/stylesmap.js';
72
+ export { default as StylesMap, StylesProcessor } from './view/stylesmap.js';
73
73
  export * from './view/styles/background.js';
74
74
  export * from './view/styles/border.js';
75
75
  export * from './view/styles/margin.js';
@@ -460,6 +460,14 @@ class ContextFactory {
460
460
  this._setRelation(opA, opB, 'splitAtSource');
461
461
  }
462
462
  }
463
+ else if (opB instanceof MoveOperation && opB.howMany > 0) {
464
+ if (opA.sourcePosition.isEqual(opB.sourcePosition.getShiftedBy(opB.howMany))) {
465
+ this._setRelation(opA, opB, 'mergeSourceAffected');
466
+ }
467
+ if (opA.targetPosition.isEqual(opB.sourcePosition)) {
468
+ this._setRelation(opA, opB, 'mergeTargetWasBefore');
469
+ }
470
+ }
463
471
  }
464
472
  else if (opA instanceof MarkerOperation) {
465
473
  const markerRange = opA.newRange;
@@ -1103,16 +1111,68 @@ setTransformation(MergeOperation, MoveOperation, (a, b, context) => {
1103
1111
  return [new NoOperation(0)];
1104
1112
  }
1105
1113
  }
1106
- // The default case.
1114
+ // In most cases we want `sourcePosition` to stick to previous and `targetPosition` to stick to next.
1115
+ // Usually, `sourcePosition` is at the beginning of the merged element and `targetPosition` is at the end of the merge-target element.
1107
1116
  //
1108
- if (a.sourcePosition.hasSameParentAs(b.targetPosition)) {
1109
- a.howMany += b.howMany;
1117
+ // However, `sourcePosition` and `targetPosition` may end up in the middle of an element due to some OT magic that happens during undo.
1118
+ // It is expected and used in `MergeOperation` x `SplitOperation` transformation.
1119
+ //
1120
+ // But when these positions are in the middle, it messes up the regular `MergeOperation` x `MoveOperation` transformation because
1121
+ // these positions may "follow" some moved elements. And we want them stick in the original elements.
1122
+ //
1123
+ // This is why we add two extra cases: (1) and (2).
1124
+ //
1125
+ // But after this `MergeOperation` is transformed by "this" move (which is undone), we also need to define extra cases for
1126
+ // the operation undoing previous move. These are (3) and (4).
1127
+ //
1128
+ // (1). Note that this case is also added to `updateRelations()` and sets `mergeSourceAffected` relation.
1129
+ //
1130
+ // [] is move operation, } is merge source position (sticks to previous by default):
1131
+ // <p>A[b]}c</p> -> <p>A}c</p>
1132
+ //
1133
+ if (b.sourcePosition.getShiftedBy(b.howMany).isEqual(a.sourcePosition)) {
1134
+ a.sourcePosition.stickiness = 'toNone';
1135
+ }
1136
+ // (3). This is the transformation for undoing operation of the above case.
1137
+ //
1138
+ // [] is move operation, } is merge source position (sticks to previous by default):
1139
+ // <p>A}c</p> -> <p>A[b]}c</p> (instead of <p>A}[b]c</p>)
1140
+ //
1141
+ else if (b.targetPosition.isEqual(a.sourcePosition) && context.abRelation == 'mergeSourceAffected') {
1142
+ a.sourcePosition.stickiness = 'toNext';
1110
1143
  }
1111
- if (a.sourcePosition.hasSameParentAs(b.sourcePosition)) {
1144
+ // (2). Note that this case is also added to `updateRelations()` and sets `mergeTargetWasBefore` relation.
1145
+ //
1146
+ // [] is move operation, { is merge target position (sticks to next by default):
1147
+ // <p>A{[b]c</p> -> <p>A{c</p>
1148
+ //
1149
+ else if (b.sourcePosition.isEqual(a.targetPosition)) {
1150
+ a.targetPosition.stickiness = 'toNone';
1112
1151
  a.howMany -= b.howMany;
1113
1152
  }
1153
+ // (4). This is the transformation for undoing operation of the above case.
1154
+ //
1155
+ // [] is move operation, { is merge target position (sticks to next by default):
1156
+ // <p>A{c</p> -> <p>A{[b]c</p> (instead of <p>A[b]{c</p>)
1157
+ //
1158
+ else if (b.targetPosition.isEqual(a.targetPosition) && context.abRelation == 'mergeTargetWasBefore') {
1159
+ a.targetPosition.stickiness = 'toPrevious';
1160
+ a.howMany += b.howMany;
1161
+ }
1162
+ // The default case.
1163
+ else {
1164
+ if (a.sourcePosition.hasSameParentAs(b.targetPosition)) {
1165
+ a.howMany += b.howMany;
1166
+ }
1167
+ if (a.sourcePosition.hasSameParentAs(b.sourcePosition)) {
1168
+ a.howMany -= b.howMany;
1169
+ }
1170
+ }
1114
1171
  a.sourcePosition = a.sourcePosition._getTransformedByMoveOperation(b);
1115
1172
  a.targetPosition = a.targetPosition._getTransformedByMoveOperation(b);
1173
+ // After transformations are done, make sure to revert stickiness in case if (1) - (4) scenario happened.
1174
+ a.sourcePosition.stickiness = 'toPrevious';
1175
+ a.targetPosition.stickiness = 'toNext';
1116
1176
  // `MergeOperation` graveyard position is like `MoveOperation` target position. It is a position where element(s) will
1117
1177
  // be moved. Like in other similar cases, we need to consider the scenario when those positions are same.
1118
1178
  // Here, we will treat `MergeOperation` like it is always strong (see `InsertOperation` x `InsertOperation` for comparison).
@@ -149,7 +149,7 @@ export default function insertContent(model, content, selectable) {
149
149
  for (const [name, [start, end]] of Object.entries(markersData)) {
150
150
  // For now, we ignore markers if they are included in the filtered-out content.
151
151
  // In the future implementation we will improve that case to create markers that are not filtered out completely.
152
- if (start && end && start.root === end.root) {
152
+ if (start && end && start.root === end.root && start.root.document) {
153
153
  writer.addMarker(name, {
154
154
  usingOperation: true,
155
155
  affectsData: true,
@@ -519,7 +519,7 @@ export default class Writer {
519
519
  *
520
520
  * The `options.affectsData` parameter, which defaults to `false`, allows you to define if a marker affects the data. It should be
521
521
  * `true` when the marker change changes the data returned by the
522
- * {@link module:core/editor/utils/dataapimixin~DataApi#getData `editor.getData()`} method.
522
+ * {@link module:core/editor/editor~Editor#getData `editor.getData()`} method.
523
523
  * When set to `true` it fires the {@link module:engine/model/document~Document#event:change:data `change:data`} event.
524
524
  * When set to `false` it fires the {@link module:engine/model/document~Document#event:change `change`} event.
525
525
  *
@@ -573,7 +573,7 @@ export default class Writer {
573
573
  *
574
574
  * The `options.affectsData` parameter, which defaults to `false`, allows you to define if a marker affects the data. It should be
575
575
  * `true` when the marker change changes the data returned by
576
- * the {@link module:core/editor/utils/dataapimixin~DataApi#getData `editor.getData()`} method.
576
+ * the {@link module:core/editor/editor~Editor#getData `editor.getData()`} method.
577
577
  * When set to `true` it fires the {@link module:engine/model/document~Document#event:change:data `change:data`} event.
578
578
  * When set to `false` it fires the {@link module:engine/model/document~Document#event:change `change`} event.
579
579
  *
@@ -705,7 +705,7 @@ export default class Writer {
705
705
  *
706
706
  * The `options.affectsData` parameter, which defaults to `false`, allows you to define if a marker affects the data. It should be
707
707
  * `true` when the marker change changes the data returned by the
708
- * {@link module:core/editor/utils/dataapimixin~DataApi#getData `editor.getData()`} method.
708
+ * {@link module:core/editor/editor~Editor#getData `editor.getData()`} method.
709
709
  * When set to `true` it fires the {@link module:engine/model/document~Document#event:change:data `change:data`} event.
710
710
  * When set to `false` it fires the {@link module:engine/model/document~Document#event:change `change`} event.
711
711
  *
@@ -789,7 +789,7 @@ export default class Writer {
789
789
  *
790
790
  * The `options.affectsData` parameter, which defaults to `false`, allows you to define if a marker affects the data. It should be
791
791
  * `true` when the marker change changes the data returned by
792
- * the {@link module:core/editor/utils/dataapimixin~DataApi#getData `editor.getData()`} method.
792
+ * the {@link module:core/editor/editor~Editor#getData `editor.getData()`} method.
793
793
  * When set to `true` it fires the {@link module:engine/model/document~Document#event:change:data `change:data`} event.
794
794
  * When set to `false` it fires the {@link module:engine/model/document~Document#event:change `change`} event.
795
795
  *
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import type { StylesProcessor } from '../stylesmap.js';
9
9
  /**
10
- * Adds a margin CSS styles processing rules.
10
+ * Adds a padding CSS styles processing rules.
11
11
  *
12
12
  * ```ts
13
13
  * editor.data.addStyleProcessorRules( addPaddingRules );
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { getPositionShorthandNormalizer, getBoxSidesValueReducer } from './utils.js';
6
6
  /**
7
- * Adds a margin CSS styles processing rules.
7
+ * Adds a padding CSS styles processing rules.
8
8
  *
9
9
  * ```ts
10
10
  * editor.data.addStyleProcessorRules( addPaddingRules );
@@ -4,8 +4,6 @@
4
4
  */
5
5
  /**
6
6
  * Styles map. Allows handling (adding, removing, retrieving) a set of style rules (usually, of an element).
7
- *
8
- * The styles map is capable of normalizing style names so e.g. the following operations are possible:
9
7
  */
10
8
  export default class StylesMap {
11
9
  /**
@@ -8,8 +8,6 @@
8
8
  import { get, isObject, merge, set, unset } from 'lodash-es';
9
9
  /**
10
10
  * Styles map. Allows handling (adding, removing, retrieving) a set of style rules (usually, of an element).
11
- *
12
- * The styles map is capable of normalizing style names so e.g. the following operations are possible:
13
11
  */
14
12
  export default class StylesMap {
15
13
  /**