@ckeditor/ckeditor5-engine 48.5.2 → 48.5.3

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/dist/index.js CHANGED
@@ -859,8 +859,10 @@ var ViewConsumable = class ViewConsumable {
859
859
  */
860
860
  revert(element, consumables) {
861
861
  const elementConsumables = this._consumables.get(element);
862
- if (elementConsumables !== void 0) if (element.is("$text") || element.is("documentFragment")) this._consumables.set(element, true);
863
- else elementConsumables.revert(normalizeConsumables(consumables));
862
+ if (elementConsumables !== void 0) {
863
+ if (element.is("$text") || element.is("documentFragment")) this._consumables.set(element, true);
864
+ else elementConsumables.revert(normalizeConsumables(consumables));
865
+ }
864
866
  }
865
867
  /**
866
868
  * Creates {@link module:engine/conversion/viewconsumable~ViewConsumable ViewConsumable} instance from
@@ -2604,8 +2606,10 @@ var ViewElement = class ViewElement extends ViewNode {
2604
2606
  */
2605
2607
  hasAttribute(key, token) {
2606
2608
  if (!this._attrs.has(key)) return false;
2607
- if (token !== void 0) if (usesStylesMap(this.name, key) || usesTokenList(this.name, key)) return this._attrs.get(key).has(token);
2608
- else return this._attrs.get(key) === token;
2609
+ if (token !== void 0) {
2610
+ if (usesStylesMap(this.name, key) || usesTokenList(this.name, key)) return this._attrs.get(key).has(token);
2611
+ else return this._attrs.get(key) === token;
2612
+ }
2609
2613
  return true;
2610
2614
  }
2611
2615
  /**
@@ -2911,9 +2915,10 @@ var ViewElement = class ViewElement extends ViewNode {
2911
2915
  this._attrs.set(key, currentValue);
2912
2916
  }
2913
2917
  if (overwrite) currentValue.setTo(String(value));
2914
- else if (usesStylesMap(this.name, key)) if (Array.isArray(value)) currentValue.set(value[0], value[1]);
2915
- else currentValue.set(value);
2916
- else currentValue.set(typeof value == "string" ? value.split(/\s+/) : value);
2918
+ else if (usesStylesMap(this.name, key)) {
2919
+ if (Array.isArray(value)) currentValue.set(value[0], value[1]);
2920
+ else currentValue.set(value);
2921
+ } else currentValue.set(typeof value == "string" ? value.split(/\s+/) : value);
2917
2922
  } else this._attrs.set(key, String(value));
2918
2923
  }
2919
2924
  /**
@@ -3112,8 +3117,10 @@ var ViewElement = class ViewElement extends ViewNode {
3112
3117
  const attributes = [];
3113
3118
  if (key) {
3114
3119
  const value = this._attrs.get(key);
3115
- if (value !== void 0) if (typeof value == "string") attributes.push([key]);
3116
- else for (const prop of value._getConsumables(token)) attributes.push([key, prop]);
3120
+ if (value !== void 0) {
3121
+ if (typeof value == "string") attributes.push([key]);
3122
+ else for (const prop of value._getConsumables(token)) attributes.push([key, prop]);
3123
+ }
3117
3124
  } else for (const [key, value] of this._attrs) if (typeof value == "string") attributes.push([key]);
3118
3125
  else for (const prop of value._getConsumables()) attributes.push([key, prop]);
3119
3126
  return {
@@ -3770,14 +3777,18 @@ var ViewTreeWalker = class {
3770
3777
  */
3771
3778
  _formatReturnValue(type, item, previousPosition, nextPosition, length) {
3772
3779
  if (item.is("view:$textProxy")) {
3773
- if (item.offsetInText + item.data.length == item.textNode.data.length) if (this.direction == "forward" && !(this.boundaries && this.boundaries.end.isEqual(this.position))) {
3774
- nextPosition = ViewPosition._createAfter(item.textNode);
3775
- this._position = nextPosition;
3776
- } else previousPosition = ViewPosition._createAfter(item.textNode);
3777
- if (item.offsetInText === 0) if (this.direction == "backward" && !(this.boundaries && this.boundaries.start.isEqual(this.position))) {
3778
- nextPosition = ViewPosition._createBefore(item.textNode);
3779
- this._position = nextPosition;
3780
- } else previousPosition = ViewPosition._createBefore(item.textNode);
3780
+ if (item.offsetInText + item.data.length == item.textNode.data.length) {
3781
+ if (this.direction == "forward" && !(this.boundaries && this.boundaries.end.isEqual(this.position))) {
3782
+ nextPosition = ViewPosition._createAfter(item.textNode);
3783
+ this._position = nextPosition;
3784
+ } else previousPosition = ViewPosition._createAfter(item.textNode);
3785
+ }
3786
+ if (item.offsetInText === 0) {
3787
+ if (this.direction == "backward" && !(this.boundaries && this.boundaries.start.isEqual(this.position))) {
3788
+ nextPosition = ViewPosition._createBefore(item.textNode);
3789
+ this._position = nextPosition;
3790
+ } else previousPosition = ViewPosition._createBefore(item.textNode);
3791
+ }
3781
3792
  }
3782
3793
  return {
3783
3794
  done: false,
@@ -7891,12 +7902,14 @@ var ViewRenderer = class extends ViewRendererBase {
7891
7902
  for (const element of this.markedAttributes) this._updateAttrs(element);
7892
7903
  for (const element of this.markedChildren) this._updateChildren(element, { inlineFillerPosition });
7893
7904
  for (const node of this.markedTexts) if (!this.markedChildren.has(node.parent) && this.domConverter.mapViewToDom(node.parent)) this._updateText(node, { inlineFillerPosition });
7894
- if (isInlineFillerRenderingPossible) if (inlineFillerPosition) {
7895
- const fillerDomPosition = this.domConverter.viewPositionToDom(inlineFillerPosition);
7896
- const domDocument = fillerDomPosition.parent.ownerDocument;
7897
- if (!startsWithFiller(fillerDomPosition.parent)) this._inlineFiller = addInlineFiller(domDocument, fillerDomPosition.parent, fillerDomPosition.offset);
7898
- else this._inlineFiller = fillerDomPosition.parent;
7899
- } else this._inlineFiller = null;
7905
+ if (isInlineFillerRenderingPossible) {
7906
+ if (inlineFillerPosition) {
7907
+ const fillerDomPosition = this.domConverter.viewPositionToDom(inlineFillerPosition);
7908
+ const domDocument = fillerDomPosition.parent.ownerDocument;
7909
+ if (!startsWithFiller(fillerDomPosition.parent)) this._inlineFiller = addInlineFiller(domDocument, fillerDomPosition.parent, fillerDomPosition.offset);
7910
+ else this._inlineFiller = fillerDomPosition.parent;
7911
+ } else this._inlineFiller = null;
7912
+ }
7900
7913
  this._updateFocus();
7901
7914
  this._updateSelection();
7902
7915
  this.domConverter._clearTemporaryCustomProperties();
@@ -8682,8 +8695,10 @@ var ViewDomConverter = class {
8682
8695
  return this._domDocument.createTextNode(textData);
8683
8696
  } else {
8684
8697
  const viewElementOrFragment = viewNode;
8685
- if (this.mapViewToDom(viewElementOrFragment)) if (viewElementOrFragment.getCustomProperty("editingPipeline:doNotReuseOnce")) this._elementsWithTemporaryCustomProperties.add(viewElementOrFragment);
8686
- else return this.mapViewToDom(viewElementOrFragment);
8698
+ if (this.mapViewToDom(viewElementOrFragment)) {
8699
+ if (viewElementOrFragment.getCustomProperty("editingPipeline:doNotReuseOnce")) this._elementsWithTemporaryCustomProperties.add(viewElementOrFragment);
8700
+ else return this.mapViewToDom(viewElementOrFragment);
8701
+ }
8687
8702
  let domElement;
8688
8703
  if (viewElementOrFragment.is("documentFragment")) {
8689
8704
  domElement = this._domDocument.createDocumentFragment();
@@ -8773,12 +8788,13 @@ var ViewDomConverter = class {
8773
8788
  for (const childView of viewElement.getChildren()) {
8774
8789
  if (fillerPositionOffset === offset) yield this._getBlockFiller();
8775
8790
  const transparentRendering = childView.is("element") && !!childView.getCustomProperty("dataPipeline:transparentRendering") && !first(childView.getAttributes());
8776
- if (transparentRendering && this.renderingMode == "data") if (childView.is("rawElement")) {
8777
- const tempElement = this._domDocument.createElement(childView.name);
8778
- childView.render(tempElement, this);
8779
- yield* [...tempElement.childNodes];
8780
- } else yield* this.viewChildrenToDom(childView, options);
8781
- else {
8791
+ if (transparentRendering && this.renderingMode == "data") {
8792
+ if (childView.is("rawElement")) {
8793
+ const tempElement = this._domDocument.createElement(childView.name);
8794
+ childView.render(tempElement, this);
8795
+ yield* [...tempElement.childNodes];
8796
+ } else yield* this.viewChildrenToDom(childView, options);
8797
+ } else {
8782
8798
  if (transparentRendering)
8783
8799
  /**
8784
8800
  * The `dataPipeline:transparentRendering` flag is supported only in the data pipeline.
@@ -9263,15 +9279,16 @@ var ViewDomConverter = class {
9263
9279
  const hostElement = this.getHostViewElement(domNode);
9264
9280
  if (hostElement) return hostElement;
9265
9281
  if (isComment(domNode) && options.skipComments) return null;
9266
- if (isText(domNode)) if (isInlineFiller(domNode)) return null;
9267
- else {
9268
- const textData = domNode.data;
9269
- if (textData === "") return null;
9270
- const textNode = new ViewText(this.document, textData);
9271
- inlineNodes.push(textNode);
9272
- return textNode;
9273
- }
9274
- else {
9282
+ if (isText(domNode)) {
9283
+ if (isInlineFiller(domNode)) return null;
9284
+ else {
9285
+ const textData = domNode.data;
9286
+ if (textData === "") return null;
9287
+ const textNode = new ViewText(this.document, textData);
9288
+ inlineNodes.push(textNode);
9289
+ return textNode;
9290
+ }
9291
+ } else {
9275
9292
  let viewElement = this.mapDomToView(domNode);
9276
9293
  if (viewElement) {
9277
9294
  if (this._isInlineObjectElement(viewElement)) inlineNodes.push(viewElement);
@@ -12259,12 +12276,16 @@ var ModelPosition = class ModelPosition extends ModelTypeCheckable {
12259
12276
  const transformed = ModelPosition._createAt(this);
12260
12277
  if (this.root != deletePosition.root) return transformed;
12261
12278
  if (compareArrays(deletePosition.getParentPath(), this.getParentPath()) == "same") {
12262
- if (deletePosition.offset < this.offset) if (deletePosition.offset + howMany > this.offset) return null;
12263
- else transformed.offset -= howMany;
12279
+ if (deletePosition.offset < this.offset) {
12280
+ if (deletePosition.offset + howMany > this.offset) return null;
12281
+ else transformed.offset -= howMany;
12282
+ }
12264
12283
  } else if (compareArrays(deletePosition.getParentPath(), this.getParentPath()) == "prefix") {
12265
12284
  const i = deletePosition.path.length - 1;
12266
- if (deletePosition.offset <= this.path[i]) if (deletePosition.offset + howMany > this.path[i]) return null;
12267
- else transformed.path[i] -= howMany;
12285
+ if (deletePosition.offset <= this.path[i]) {
12286
+ if (deletePosition.offset + howMany > this.path[i]) return null;
12287
+ else transformed.path[i] -= howMany;
12288
+ }
12268
12289
  }
12269
12290
  return transformed;
12270
12291
  }
@@ -12816,8 +12837,10 @@ var ModelRange = class ModelRange extends ModelTypeCheckable {
12816
12837
  */
12817
12838
  getJoined(otherRange, loose = false) {
12818
12839
  let shouldJoin = this.isIntersecting(otherRange);
12819
- if (!shouldJoin) if (this.start.isBefore(otherRange.start)) shouldJoin = loose ? this.end.isTouching(otherRange.start) : this.end.isEqual(otherRange.start);
12820
- else shouldJoin = loose ? otherRange.end.isTouching(this.start) : otherRange.end.isEqual(this.start);
12840
+ if (!shouldJoin) {
12841
+ if (this.start.isBefore(otherRange.start)) shouldJoin = loose ? this.end.isTouching(otherRange.start) : this.end.isEqual(otherRange.start);
12842
+ else shouldJoin = loose ? otherRange.end.isTouching(this.start) : otherRange.end.isEqual(this.start);
12843
+ }
12821
12844
  if (!shouldJoin) return null;
12822
12845
  let startPosition = this.start;
12823
12846
  let endPosition = this.end;
@@ -13743,22 +13766,24 @@ var Mapper = class extends MapperBase {
13743
13766
  let lastLength = 0;
13744
13767
  while (traversedModelOffset < targetModelOffset) {
13745
13768
  viewNode = viewParent.getChild(viewOffset);
13746
- if (!viewNode) if (viewParent == viewContainer)
13769
+ if (!viewNode) {
13770
+ if (viewParent == viewContainer)
13747
13771
  /**
13748
- * A model position could not be mapped to the view because specified model offset was too big and could not be
13749
- * found inside the mapped view element or view document fragment.
13750
- *
13751
- * @error mapping-model-offset-not-found
13752
- */
13753
- throw new CKEditorError("mapping-model-offset-not-found", this, {
13754
- modelOffset: targetModelOffset,
13755
- viewContainer
13756
- });
13757
- else {
13758
- viewOffset = viewParent.parent.getChildIndex(viewParent) + 1;
13759
- viewParent = viewParent.parent;
13760
- if (useCache) this._cache.save(viewParent, viewOffset, viewContainer, traversedModelOffset);
13761
- continue;
13772
+ * A model position could not be mapped to the view because specified model offset was too big and could not be
13773
+ * found inside the mapped view element or view document fragment.
13774
+ *
13775
+ * @error mapping-model-offset-not-found
13776
+ */
13777
+ throw new CKEditorError("mapping-model-offset-not-found", this, {
13778
+ modelOffset: targetModelOffset,
13779
+ viewContainer
13780
+ });
13781
+ else {
13782
+ viewOffset = viewParent.parent.getChildIndex(viewParent) + 1;
13783
+ viewParent = viewParent.parent;
13784
+ if (useCache) this._cache.save(viewParent, viewOffset, viewContainer, traversedModelOffset);
13785
+ continue;
13786
+ }
13762
13787
  }
13763
13788
  if (useCache) lastLength = this._getModelLengthAndCache(viewNode, viewContainer, traversedModelOffset);
13764
13789
  else lastLength = this.getModelLength(viewNode);
@@ -13958,13 +13983,14 @@ var MapperCache = class extends MapperCacheBase {
13958
13983
  getClosest(viewContainer, modelOffset) {
13959
13984
  const cache = this._cachedMapping.get(viewContainer);
13960
13985
  let result;
13961
- if (cache) if (modelOffset > cache.maxModelOffset) result = cache.cacheList[cache.cacheList.length - 1];
13962
- else {
13963
- const cacheItem = cache.cacheMap.get(modelOffset);
13964
- if (cacheItem) result = cacheItem;
13965
- else result = this._findInCacheList(cache.cacheList, modelOffset);
13966
- }
13967
- else result = this.startTracking(viewContainer);
13986
+ if (cache) {
13987
+ if (modelOffset > cache.maxModelOffset) result = cache.cacheList[cache.cacheList.length - 1];
13988
+ else {
13989
+ const cacheItem = cache.cacheMap.get(modelOffset);
13990
+ if (cacheItem) result = cacheItem;
13991
+ else result = this._findInCacheList(cache.cacheList, modelOffset);
13992
+ }
13993
+ } else result = this.startTracking(viewContainer);
13968
13994
  return {
13969
13995
  modelOffset: result.modelOffset,
13970
13996
  viewPosition: result.viewPosition.clone()
@@ -14013,9 +14039,10 @@ var MapperCache = class extends MapperCacheBase {
14013
14039
  * will invalidate everything after `index`.
14014
14040
  */
14015
14041
  _clearCacheInsideParent(viewParent, index) {
14016
- if (index == 0) if (this._cachedMapping.has(viewParent)) this._clearCacheAll(viewParent);
14017
- else this._clearCacheInsideParent(viewParent.parent, viewParent.index);
14018
- else {
14042
+ if (index == 0) {
14043
+ if (this._cachedMapping.has(viewParent)) this._clearCacheAll(viewParent);
14044
+ else this._clearCacheInsideParent(viewParent.parent, viewParent.index);
14045
+ } else {
14019
14046
  const lastValidNode = viewParent.getChild(index - 1);
14020
14047
  this._clearCacheAfter(lastValidNode);
14021
14048
  }
@@ -16071,8 +16098,10 @@ function transform$2(operation) {
16071
16098
  const contentChanged = doesOperationChangeRangeContent(this, operation);
16072
16099
  let deletionPosition = null;
16073
16100
  if (boundariesChanged) {
16074
- if (result.root.rootName == "$graveyard") if (operation.type == "remove") deletionPosition = operation.sourcePosition;
16075
- else deletionPosition = operation.deletionPosition;
16101
+ if (result.root.rootName == "$graveyard") {
16102
+ if (operation.type == "remove") deletionPosition = operation.sourcePosition;
16103
+ else deletionPosition = operation.deletionPosition;
16104
+ }
16076
16105
  const oldRange = this.toRange();
16077
16106
  this.start = result.start;
16078
16107
  this.end = result.end;
@@ -18870,8 +18899,10 @@ function changeAttribute(attributeCreator) {
18870
18899
  throw new CKEditorError("conversion-attribute-to-attribute-on-text", conversionApi.dispatcher, data);
18871
18900
  if (data.attributeOldValue !== null && oldAttribute) {
18872
18901
  let value = oldAttribute.value;
18873
- if (oldAttribute.key == "style") if (typeof oldAttribute.value == "string") value = new StylesMap(viewWriter.document.stylesProcessor).setTo(oldAttribute.value).getStylesEntries().map(([key]) => key);
18874
- else value = Object.keys(oldAttribute.value);
18902
+ if (oldAttribute.key == "style") {
18903
+ if (typeof oldAttribute.value == "string") value = new StylesMap(viewWriter.document.stylesProcessor).setTo(oldAttribute.value).getStylesEntries().map(([key]) => key);
18904
+ else value = Object.keys(oldAttribute.value);
18905
+ }
18875
18906
  viewWriter.removeAttribute(oldAttribute.key, value, viewElement);
18876
18907
  }
18877
18908
  if (data.attributeNewValue !== null && newAttribute) {
@@ -19252,12 +19283,13 @@ function normalizeToAttributeConfig(view) {
19252
19283
  key: view,
19253
19284
  value: modelAttributeValue
19254
19285
  });
19255
- else if (typeof view == "object") if (view.value) return () => view;
19256
- else return (modelAttributeValue) => ({
19257
- key: view.key,
19258
- value: modelAttributeValue
19259
- });
19260
- else return view;
19286
+ else if (typeof view == "object") {
19287
+ if (view.value) return () => view;
19288
+ else return (modelAttributeValue) => ({
19289
+ key: view.key,
19290
+ value: modelAttributeValue
19291
+ });
19292
+ } else return view;
19261
19293
  }
19262
19294
  /**
19263
19295
  * Helper function for `highlight`. Prepares the actual descriptor object using value passed to the converter.
@@ -21304,10 +21336,12 @@ var ModelSchema = class extends ModelSchemaBase {
21304
21336
  let start = range.start;
21305
21337
  let end = range.start;
21306
21338
  for (const item of range.getItems({ shallow: true })) {
21307
- if (item.is("element")) if (options.includeEmptyRanges && item.isEmpty) {
21308
- const context = this.createContext(item);
21309
- if (this.checkChild(context, "$text") && this.checkAttribute(context.push("$text"), attribute)) yield ModelRange._createIn(item);
21310
- } else yield* this._getValidRangesForRange(ModelRange._createIn(item), attribute, options);
21339
+ if (item.is("element")) {
21340
+ if (options.includeEmptyRanges && item.isEmpty) {
21341
+ const context = this.createContext(item);
21342
+ if (this.checkChild(context, "$text") && this.checkAttribute(context.push("$text"), attribute)) yield ModelRange._createIn(item);
21343
+ } else yield* this._getValidRangesForRange(ModelRange._createIn(item), attribute, options);
21344
+ }
21311
21345
  if (!this.checkAttribute(item, attribute)) {
21312
21346
  if (!start.isEqual(end)) yield new ModelRange(start, end);
21313
21347
  start = ModelPosition._createAfter(item);
@@ -24305,8 +24339,10 @@ var MarkerOperation = class MarkerOperation extends Operation {
24305
24339
  get affectedSelectable() {
24306
24340
  const ranges = [];
24307
24341
  if (this.oldRange) ranges.push(this.oldRange.clone());
24308
- if (this.newRange) if (this.oldRange) ranges.push(...this.newRange.getDifference(this.oldRange));
24309
- else ranges.push(this.newRange.clone());
24342
+ if (this.newRange) {
24343
+ if (this.oldRange) ranges.push(...this.newRange.getDifference(this.oldRange));
24344
+ else ranges.push(this.newRange.clone());
24345
+ }
24310
24346
  return ranges;
24311
24347
  }
24312
24348
  /**
@@ -25208,21 +25244,25 @@ var ContextFactory = class {
25208
25244
  else if (opA.targetPosition.isAfter(opB.sourcePosition)) this._setRelation(opA, opB, "moveTargetAfter");
25209
25245
  else if (opA.howMany > 1 && opA.sourcePosition.isEqual(opB.deletionPosition)) this._setRelation(opA, opB, "firstToMoveMerged");
25210
25246
  else if (opA.howMany > 1 && opA.sourcePosition.getShiftedBy(opA.howMany - 1).isEqual(opB.deletionPosition)) this._setRelation(opA, opB, "lastToMoveMerged");
25211
- } else if (opB instanceof MoveOperation) if (opA.targetPosition.isEqual(opB.sourcePosition) || opA.targetPosition.isBefore(opB.sourcePosition)) this._setRelation(opA, opB, "insertBefore");
25212
- else this._setRelation(opA, opB, "insertAfter");
25247
+ } else if (opB instanceof MoveOperation) {
25248
+ if (opA.targetPosition.isEqual(opB.sourcePosition) || opA.targetPosition.isBefore(opB.sourcePosition)) this._setRelation(opA, opB, "insertBefore");
25249
+ else this._setRelation(opA, opB, "insertAfter");
25250
+ }
25213
25251
  } else if (opA instanceof SplitOperation) {
25214
25252
  if (opB instanceof MergeOperation) {
25215
25253
  if (opA.splitPosition.isBefore(opB.sourcePosition)) this._setRelation(opA, opB, "splitBefore");
25216
- } else if (opB instanceof MoveOperation) if (opA.splitPosition.isEqual(opB.sourcePosition) || opA.splitPosition.isBefore(opB.sourcePosition)) this._setRelation(opA, opB, "splitBefore");
25217
- else {
25218
- const range = ModelRange._createFromPositionAndShift(opB.sourcePosition, opB.howMany);
25219
- if (opA.splitPosition.hasSameParentAs(opB.sourcePosition) && range.containsPosition(opA.splitPosition)) {
25220
- const howMany = range.end.offset - opA.splitPosition.offset;
25221
- const offset = opA.splitPosition.offset - range.start.offset;
25222
- this._setRelation(opA, opB, {
25223
- howMany,
25224
- offset
25225
- });
25254
+ } else if (opB instanceof MoveOperation) {
25255
+ if (opA.splitPosition.isEqual(opB.sourcePosition) || opA.splitPosition.isBefore(opB.sourcePosition)) this._setRelation(opA, opB, "splitBefore");
25256
+ else {
25257
+ const range = ModelRange._createFromPositionAndShift(opB.sourcePosition, opB.howMany);
25258
+ if (opA.splitPosition.hasSameParentAs(opB.sourcePosition) && range.containsPosition(opA.splitPosition)) {
25259
+ const howMany = range.end.offset - opA.splitPosition.offset;
25260
+ const offset = opA.splitPosition.offset - range.start.offset;
25261
+ this._setRelation(opA, opB, {
25262
+ howMany,
25263
+ offset
25264
+ });
25265
+ }
25226
25266
  }
25227
25267
  }
25228
25268
  } else if (opA instanceof MergeOperation) {
@@ -25509,8 +25549,10 @@ setTransformation(MarkerOperation, InsertOperation, (a, b) => {
25509
25549
  return [a];
25510
25550
  });
25511
25551
  setTransformation(MarkerOperation, MarkerOperation, (a, b, context) => {
25512
- if (a.name == b.name) if (context.aIsStrong) a.oldRange = b.newRange ? b.newRange.clone() : null;
25513
- else return [new NoOperation(0)];
25552
+ if (a.name == b.name) {
25553
+ if (context.aIsStrong) a.oldRange = b.newRange ? b.newRange.clone() : null;
25554
+ else return [new NoOperation(0)];
25555
+ }
25514
25556
  return [a];
25515
25557
  });
25516
25558
  setTransformation(MarkerOperation, MergeOperation, (a, b) => {
@@ -25539,14 +25581,16 @@ setTransformation(MarkerOperation, SplitOperation, (a, b, context) => {
25539
25581
  if (a.newRange) {
25540
25582
  if (context.abRelation) {
25541
25583
  const aNewRange = a.newRange._getTransformedBySplitOperation(b);
25542
- if (a.newRange.start.isEqual(b.splitPosition)) if (context.abRelation.wasStartBeforeMergedElement) a.newRange.start = ModelPosition._createAt(b.insertionPosition);
25543
- else if (context.abRelation.wasInLeftElement) a.newRange.start = ModelPosition._createAt(a.newRange.start);
25544
- else a.newRange.start = ModelPosition._createAt(b.moveTargetPosition);
25545
- else a.newRange.start = aNewRange.start;
25546
- if (a.newRange.end.isEqual(b.splitPosition)) if (a.newRange.end.isEqual(b.splitPosition) && context.abRelation.wasEndBeforeMergedElement) a.newRange.end = ModelPosition._createAt(b.insertionPosition);
25547
- else if (context.abRelation.wasInRightElement) a.newRange.end = ModelPosition._createAt(b.moveTargetPosition);
25548
- else a.newRange.end = ModelPosition._createAt(a.newRange.end);
25549
- else a.newRange.end = aNewRange.end;
25584
+ if (a.newRange.start.isEqual(b.splitPosition)) {
25585
+ if (context.abRelation.wasStartBeforeMergedElement) a.newRange.start = ModelPosition._createAt(b.insertionPosition);
25586
+ else if (context.abRelation.wasInLeftElement) a.newRange.start = ModelPosition._createAt(a.newRange.start);
25587
+ else a.newRange.start = ModelPosition._createAt(b.moveTargetPosition);
25588
+ } else a.newRange.start = aNewRange.start;
25589
+ if (a.newRange.end.isEqual(b.splitPosition)) {
25590
+ if (a.newRange.end.isEqual(b.splitPosition) && context.abRelation.wasEndBeforeMergedElement) a.newRange.end = ModelPosition._createAt(b.insertionPosition);
25591
+ else if (context.abRelation.wasInRightElement) a.newRange.end = ModelPosition._createAt(b.moveTargetPosition);
25592
+ else a.newRange.end = ModelPosition._createAt(a.newRange.end);
25593
+ } else a.newRange.end = aNewRange.end;
25550
25594
  return [a];
25551
25595
  }
25552
25596
  a.newRange = a.newRange._getTransformedBySplitOperation(b);
@@ -25560,13 +25604,15 @@ setTransformation(MergeOperation, InsertOperation, (a, b) => {
25560
25604
  return [a];
25561
25605
  });
25562
25606
  setTransformation(MergeOperation, MergeOperation, (a, b, context) => {
25563
- if (a.sourcePosition.isEqual(b.sourcePosition) && a.targetPosition.isEqual(b.targetPosition)) if (!context.bWasUndone) return [new NoOperation(0)];
25564
- else {
25565
- const path = b.graveyardPosition.path.slice();
25566
- path.push(0);
25567
- a.sourcePosition = new ModelPosition(b.graveyardPosition.root, path);
25568
- a.howMany = 0;
25569
- return [a];
25607
+ if (a.sourcePosition.isEqual(b.sourcePosition) && a.targetPosition.isEqual(b.targetPosition)) {
25608
+ if (!context.bWasUndone) return [new NoOperation(0)];
25609
+ else {
25610
+ const path = b.graveyardPosition.path.slice();
25611
+ path.push(0);
25612
+ a.sourcePosition = new ModelPosition(b.graveyardPosition.root, path);
25613
+ a.howMany = 0;
25614
+ return [a];
25615
+ }
25570
25616
  }
25571
25617
  if (a.sourcePosition.isEqual(b.sourcePosition) && !a.targetPosition.isEqual(b.targetPosition) && !context.bWasUndone && context.abRelation != "splitAtSource") {
25572
25618
  const aToGraveyard = a.targetPosition.root.rootName == "$graveyard";
@@ -25685,9 +25731,10 @@ setTransformation(MoveOperation, MoveOperation, (a, b, context) => {
25685
25731
  common.start = common.start._getCombined(b.sourcePosition, b.getMovedRangeStart());
25686
25732
  common.end = common.end._getCombined(b.sourcePosition, b.getMovedRangeStart());
25687
25733
  if (ranges.length === 0) ranges.push(common);
25688
- else if (ranges.length == 1) if (rangeB.start.isBefore(rangeA.start) || rangeB.start.isEqual(rangeA.start)) ranges.unshift(common);
25689
- else ranges.push(common);
25690
- else ranges.splice(1, 0, common);
25734
+ else if (ranges.length == 1) {
25735
+ if (rangeB.start.isBefore(rangeA.start) || rangeB.start.isEqual(rangeA.start)) ranges.unshift(common);
25736
+ else ranges.push(common);
25737
+ } else ranges.splice(1, 0, common);
25691
25738
  }
25692
25739
  if (ranges.length === 0) return [new NoOperation(a.baseVersion)];
25693
25740
  return _makeMoveOperationsFromRanges(ranges, newTargetPosition);
@@ -25745,11 +25792,13 @@ setTransformation(MoveOperation, MergeOperation, (a, b, context) => {
25745
25792
  results.push(splitNodesMove);
25746
25793
  return results;
25747
25794
  }
25748
- } else if (a.howMany == 1) if (!context.bWasUndone) return [new NoOperation(0)];
25749
- else {
25750
- a.sourcePosition = b.graveyardPosition.clone();
25751
- a.targetPosition = a.targetPosition._getTransformedByMergeOperation(b);
25752
- return [a];
25795
+ } else if (a.howMany == 1) {
25796
+ if (!context.bWasUndone) return [new NoOperation(0)];
25797
+ else {
25798
+ a.sourcePosition = b.graveyardPosition.clone();
25799
+ a.targetPosition = a.targetPosition._getTransformedByMergeOperation(b);
25800
+ return [a];
25801
+ }
25753
25802
  }
25754
25803
  }
25755
25804
  const transformed = ModelRange._createFromPositionAndShift(a.sourcePosition, a.howMany)._getTransformedByMergeOperation(b);
@@ -25776,8 +25825,10 @@ setTransformation(RenameOperation, MoveOperation, (a, b) => {
25776
25825
  return [a];
25777
25826
  });
25778
25827
  setTransformation(RenameOperation, RenameOperation, (a, b, context) => {
25779
- if (a.position.isEqual(b.position)) if (context.aIsStrong) a.oldName = b.newName;
25780
- else return [new NoOperation(0)];
25828
+ if (a.position.isEqual(b.position)) {
25829
+ if (context.aIsStrong) a.oldName = b.newName;
25830
+ else return [new NoOperation(0)];
25831
+ }
25781
25832
  return [a];
25782
25833
  });
25783
25834
  setTransformation(RenameOperation, SplitOperation, (a, b) => {
@@ -25788,8 +25839,10 @@ setTransformation(RenameOperation, SplitOperation, (a, b) => {
25788
25839
  return [a];
25789
25840
  });
25790
25841
  setTransformation(RootAttributeOperation, RootAttributeOperation, (a, b, context) => {
25791
- if (a.root === b.root && a.key === b.key) if (!context.aIsStrong) return [new NoOperation(0)];
25792
- else a.oldValue = b.newValue;
25842
+ if (a.root === b.root && a.key === b.key) {
25843
+ if (!context.aIsStrong) return [new NoOperation(0)];
25844
+ else a.oldValue = b.newValue;
25845
+ }
25793
25846
  return [a];
25794
25847
  });
25795
25848
  setTransformation(RootOperation, RootOperation, (a, b) => {
@@ -26443,8 +26496,10 @@ var Differ = class Differ {
26443
26496
  * @returns Diff between the old and the new model tree state.
26444
26497
  */
26445
26498
  getChanges(options = {}) {
26446
- if (this._cachedChanges) if (options.includeChangesInGraveyard) return this._cachedChangesWithGraveyard.slice();
26447
- else return this._cachedChanges.slice();
26499
+ if (this._cachedChanges) {
26500
+ if (options.includeChangesInGraveyard) return this._cachedChangesWithGraveyard.slice();
26501
+ else return this._cachedChanges.slice();
26502
+ }
26448
26503
  let diffSet = [];
26449
26504
  for (const element of this._changesInElement.keys()) {
26450
26505
  const changes = this._changesInElement.get(element).sort((a, b) => {
@@ -26778,16 +26833,17 @@ var Differ = class Differ {
26778
26833
  if (inc.type == "remove") {
26779
26834
  if (old.type == "insert") {
26780
26835
  if (incEnd <= old.offset) old.offset -= inc.howMany;
26781
- else if (incEnd <= oldEnd) if (inc.offset < old.offset) {
26782
- const intersectionLength = incEnd - old.offset;
26783
- old.offset = inc.offset;
26784
- old.howMany -= intersectionLength;
26785
- inc.nodesToHandle -= intersectionLength;
26786
- } else {
26787
- old.howMany -= inc.nodesToHandle;
26788
- inc.nodesToHandle = 0;
26789
- }
26790
- else if (inc.offset <= old.offset) {
26836
+ else if (incEnd <= oldEnd) {
26837
+ if (inc.offset < old.offset) {
26838
+ const intersectionLength = incEnd - old.offset;
26839
+ old.offset = inc.offset;
26840
+ old.howMany -= intersectionLength;
26841
+ inc.nodesToHandle -= intersectionLength;
26842
+ } else {
26843
+ old.howMany -= inc.nodesToHandle;
26844
+ inc.nodesToHandle = 0;
26845
+ }
26846
+ } else if (inc.offset <= old.offset) {
26791
26847
  inc.nodesToHandle -= old.howMany;
26792
26848
  old.howMany = 0;
26793
26849
  } else if (inc.offset < oldEnd) {
@@ -26809,17 +26865,19 @@ var Differ = class Differ {
26809
26865
  const intersectionLength = incEnd - old.offset;
26810
26866
  old.offset = inc.offset;
26811
26867
  old.howMany -= intersectionLength;
26812
- } else if (inc.offset < oldEnd) if (incEnd <= oldEnd) {
26813
- const howMany = old.howMany;
26814
- old.howMany = inc.offset - old.offset;
26815
- const howManyAfter = howMany - old.howMany - inc.nodesToHandle;
26816
- changes.unshift({
26817
- type: "attribute",
26818
- offset: inc.offset,
26819
- howMany: howManyAfter,
26820
- count: this._changeCount++
26821
- });
26822
- } else old.howMany -= oldEnd - inc.offset;
26868
+ } else if (inc.offset < oldEnd) {
26869
+ if (incEnd <= oldEnd) {
26870
+ const howMany = old.howMany;
26871
+ old.howMany = inc.offset - old.offset;
26872
+ const howManyAfter = howMany - old.howMany - inc.nodesToHandle;
26873
+ changes.unshift({
26874
+ type: "attribute",
26875
+ offset: inc.offset,
26876
+ howMany: howManyAfter,
26877
+ count: this._changeCount++
26878
+ });
26879
+ } else old.howMany -= oldEnd - inc.offset;
26880
+ }
26823
26881
  }
26824
26882
  }
26825
26883
  if (inc.type == "attribute") {
@@ -26837,10 +26895,12 @@ var Differ = class Differ {
26837
26895
  }
26838
26896
  inc.nodesToHandle = old.offset - inc.offset;
26839
26897
  inc.howMany = inc.nodesToHandle;
26840
- } else if (inc.offset >= old.offset && inc.offset < oldEnd) if (incEnd > oldEnd) {
26841
- inc.nodesToHandle = incEnd - oldEnd;
26842
- inc.offset = oldEnd;
26843
- } else inc.nodesToHandle = 0;
26898
+ } else if (inc.offset >= old.offset && inc.offset < oldEnd) {
26899
+ if (incEnd > oldEnd) {
26900
+ inc.nodesToHandle = incEnd - oldEnd;
26901
+ inc.offset = oldEnd;
26902
+ } else inc.nodesToHandle = 0;
26903
+ }
26844
26904
  }
26845
26905
  if (old.type == "remove") {
26846
26906
  if (inc.offset < old.offset && incEnd > old.offset) {
@@ -28601,18 +28661,20 @@ var ModelWriter = class {
28601
28661
  this._assertWriterUsedCorrectly();
28602
28662
  if (item instanceof ModelText && item.data == "") return;
28603
28663
  const position = ModelPosition._createAt(itemOrPosition, offset);
28604
- if (item.parent) if (isSameTree(item.root, position.root)) {
28605
- this.move(ModelRange._createOn(item), position);
28606
- return;
28607
- } else if (item.root.document)
28664
+ if (item.parent) {
28665
+ if (isSameTree(item.root, position.root)) {
28666
+ this.move(ModelRange._createOn(item), position);
28667
+ return;
28668
+ } else if (item.root.document)
28608
28669
  /**
28609
- * Cannot move a node from a document to a different tree.
28610
- * It is forbidden to move a node that was already in a document outside of it.
28611
- *
28612
- * @error model-writer-insert-forbidden-move
28613
- */
28614
- throw new CKEditorError("model-writer-insert-forbidden-move", this);
28615
- else this.remove(item);
28670
+ * Cannot move a node from a document to a different tree.
28671
+ * It is forbidden to move a node that was already in a document outside of it.
28672
+ *
28673
+ * @error model-writer-insert-forbidden-move
28674
+ */
28675
+ throw new CKEditorError("model-writer-insert-forbidden-move", this);
28676
+ else this.remove(item);
28677
+ }
28616
28678
  const version = position.root.document ? position.root.document.version : null;
28617
28679
  const children = item instanceof ModelDocumentFragment ? item._removeChildren(0, item.childCount) : item;
28618
28680
  const insert = new InsertOperation(position, children, version);
@@ -30292,8 +30354,10 @@ function insertContent(model, content, selectable) {
30292
30354
  selectionLiveRange.detach();
30293
30355
  }
30294
30356
  }
30295
- if (newRange) if (selection instanceof ModelDocumentSelection) writer.setSelection(newRange);
30296
- else selection.setTo(newRange);
30357
+ if (newRange) {
30358
+ if (selection instanceof ModelDocumentSelection) writer.setSelection(newRange);
30359
+ else selection.setTo(newRange);
30360
+ }
30297
30361
  const affectedRange = insertion.getAffectedRange() || model.createRange(selection.anchor);
30298
30362
  insertion.destroy();
30299
30363
  return affectedRange;
@@ -31508,10 +31572,12 @@ var Model = class extends ModelBase {
31508
31572
  if (!ignoreMarkers) {
31509
31573
  for (const intersectingMarker of this.markers.getMarkersIntersectingRange(range)) if (intersectingMarker.affectsData) return true;
31510
31574
  }
31511
- for (const item of range.getItems()) if (this.schema.isContent(item)) if (item.is("$textProxy")) {
31512
- if (!ignoreWhitespaces) return true;
31513
- else if (item.data.search(/\S/) !== -1) return true;
31514
- } else return true;
31575
+ for (const item of range.getItems()) if (this.schema.isContent(item)) {
31576
+ if (item.is("$textProxy")) {
31577
+ if (!ignoreWhitespaces) return true;
31578
+ else if (item.data.search(/\S/) !== -1) return true;
31579
+ } else return true;
31580
+ }
31515
31581
  return false;
31516
31582
  }
31517
31583
  /**
@@ -31707,9 +31773,11 @@ var Model = class extends ModelBase {
31707
31773
  function normalizeSelectable(selectable, placeOrOffset) {
31708
31774
  if (!selectable) return;
31709
31775
  if (selectable instanceof ModelSelection || selectable instanceof ModelDocumentSelection) return selectable;
31710
- if (selectable instanceof ModelNode) if (placeOrOffset || placeOrOffset === 0) return new ModelSelection(selectable, placeOrOffset);
31711
- else if (selectable.is("rootElement")) return new ModelSelection(selectable, "in");
31712
- else return new ModelSelection(selectable, "on");
31776
+ if (selectable instanceof ModelNode) {
31777
+ if (placeOrOffset || placeOrOffset === 0) return new ModelSelection(selectable, placeOrOffset);
31778
+ else if (selectable.is("rootElement")) return new ModelSelection(selectable, "in");
31779
+ else return new ModelSelection(selectable, "on");
31780
+ }
31713
31781
  return new ModelSelection(selectable);
31714
31782
  }
31715
31783
 
@@ -32923,11 +32991,12 @@ function parseBackgroundLayer(layer) {
32923
32991
  background.position.push(part);
32924
32992
  if (i + 1 < parts.length && isPercentageStyleValue(part) && isPercentageStyleValue(parts[i + 1])) background.position.push(parts[++i]);
32925
32993
  } else if (isAttachmentStyleValue(part)) background.attachment = part;
32926
- else if (isClipStyleValue(part)) if (isOriginStyleValue(part) && !background.origin) {
32927
- background.origin = part;
32928
- background.clip = part;
32929
- } else background.clip = part;
32930
- else if (isColorStyleValue(part)) background.color = part;
32994
+ else if (isClipStyleValue(part)) {
32995
+ if (isOriginStyleValue(part) && !background.origin) {
32996
+ background.origin = part;
32997
+ background.clip = part;
32998
+ } else background.clip = part;
32999
+ } else if (isColorStyleValue(part)) background.color = part;
32931
33000
  }
32932
33001
  if (isEmpty(background)) return null;
32933
33002
  return {
@@ -33824,19 +33893,20 @@ var RangeParser = class {
33824
33893
  const index = node.index;
33825
33894
  const parent = node.parent;
33826
33895
  if (!text) node._remove();
33827
- for (const item of brackets) if (text) if (this.sameSelectionCharacters || !this.sameSelectionCharacters && (item.bracket == TEXT_RANGE_START_TOKEN || item.bracket == TEXT_RANGE_END_TOKEN)) this._positions.push({
33828
- bracket: item.bracket,
33829
- position: new ViewPosition(node, item.textOffset)
33830
- });
33831
- else {
33832
- if (!this.sameSelectionCharacters && item.textOffset !== 0 && item.textOffset !== text.length) throw new Error(`Parse error - range delimiter '${item.bracket}' is placed inside text node.`);
33833
- const offset = item.textOffset === 0 ? index : index + 1;
33834
- this._positions.push({
33896
+ for (const item of brackets) if (text) {
33897
+ if (this.sameSelectionCharacters || !this.sameSelectionCharacters && (item.bracket == TEXT_RANGE_START_TOKEN || item.bracket == TEXT_RANGE_END_TOKEN)) this._positions.push({
33835
33898
  bracket: item.bracket,
33836
- position: new ViewPosition(parent, offset)
33899
+ position: new ViewPosition(node, item.textOffset)
33837
33900
  });
33838
- }
33839
- else {
33901
+ else {
33902
+ if (!this.sameSelectionCharacters && item.textOffset !== 0 && item.textOffset !== text.length) throw new Error(`Parse error - range delimiter '${item.bracket}' is placed inside text node.`);
33903
+ const offset = item.textOffset === 0 ? index : index + 1;
33904
+ this._positions.push({
33905
+ bracket: item.bracket,
33906
+ position: new ViewPosition(parent, offset)
33907
+ });
33908
+ }
33909
+ } else {
33840
33910
  if (!this.sameSelectionCharacters && item.bracket == TEXT_RANGE_START_TOKEN || item.bracket == TEXT_RANGE_END_TOKEN) throw new Error(`Parse error - text range delimiter '${item.bracket}' is placed inside empty text node. `);
33841
33911
  this._positions.push({
33842
33912
  bracket: item.bracket,
@@ -33987,8 +34057,10 @@ var ViewStringify = class {
33987
34057
  let end = "";
33988
34058
  let collapsed = "";
33989
34059
  for (const range of this.ranges) {
33990
- if (range.start.parent == element && range.start.offset === offset) if (range.isCollapsed) collapsed += "[]";
33991
- else start += ELEMENT_RANGE_START_TOKEN;
34060
+ if (range.start.parent == element && range.start.offset === offset) {
34061
+ if (range.isCollapsed) collapsed += "[]";
34062
+ else start += ELEMENT_RANGE_START_TOKEN;
34063
+ }
33992
34064
  if (range.end.parent === element && range.end.offset === offset && !range.isCollapsed) end += ELEMENT_RANGE_END_TOKEN;
33993
34065
  }
33994
34066
  return end + collapsed + start;
@@ -34022,8 +34094,10 @@ var ViewStringify = class {
34022
34094
  for (const range of this.ranges) {
34023
34095
  const start = range.start;
34024
34096
  const end = range.end;
34025
- if (start.parent == node && start.offset >= 0 && start.offset <= length) if (range.isCollapsed) result[end.offset].collapsed += rangeStartToken + rangeEndToken;
34026
- else result[start.offset].start += rangeStartToken;
34097
+ if (start.parent == node && start.offset >= 0 && start.offset <= length) {
34098
+ if (range.isCollapsed) result[end.offset].collapsed += rangeStartToken + rangeEndToken;
34099
+ else result[start.offset].start += rangeStartToken;
34100
+ }
34027
34101
  if (end.parent == node && end.offset >= 0 && end.offset <= length && !range.isCollapsed) result[end.offset].end += rangeEndToken;
34028
34102
  }
34029
34103
  return result.map((item) => item.end + item.collapsed + item.start + item.letter).join("");