@ckeditor/ckeditor5-clipboard 47.1.0 → 47.2.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.
package/README.md CHANGED
@@ -2,7 +2,7 @@ CKEditor 5 clipboard feature
2
2
  ========================================
3
3
 
4
4
  [![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-clipboard.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-clipboard)
5
- [![Coverage Status](https://coveralls.io/repos/github/ckeditor/ckeditor5/badge.svg?branch=master)](https://coveralls.io/github/ckeditor/ckeditor5?branch=master)
5
+ [![codecov](https://codecov.io/gh/ckeditor/ckeditor5/branch/master/graph/badge.svg)](https://codecov.io/gh/ckeditor/ckeditor5)
6
6
  [![CircleCI](https://circleci.com/gh/ckeditor/ckeditor5.svg?style=shield)](https://app.circleci.com/pipelines/github/ckeditor/ckeditor5?branch=master)
7
7
 
8
8
  This package implements the clipboard (copy, cut, paste) support for CKEditor 5.
package/dist/index.js CHANGED
@@ -1092,18 +1092,26 @@ const toPx = /* #__PURE__ */ toUnit('px');
1092
1092
  /**
1093
1093
  * Finds the drop target range and updates the drop marker.
1094
1094
  *
1095
+ * @return The updated drop target range or null if no valid range was found.
1095
1096
  * @internal
1096
1097
  */ updateDropMarker(targetViewElement, targetViewRanges, clientX, clientY, blockMode, draggedRange) {
1097
1098
  this.removeDropMarkerDelayed.cancel();
1098
1099
  const targetRange = findDropTargetRange(this.editor, targetViewElement, targetViewRanges, clientX, clientY, blockMode, draggedRange);
1099
1100
  /* istanbul ignore next -- @preserve */ if (!targetRange) {
1100
- return;
1101
+ return null;
1101
1102
  }
1102
1103
  if (draggedRange && draggedRange.containsRange(targetRange)) {
1103
1104
  // Target range is inside the dragged range.
1104
- return this.removeDropMarker();
1105
+ this.removeDropMarker();
1106
+ return null;
1107
+ }
1108
+ if (targetRange && !this.editor.model.canEditAt(targetRange)) {
1109
+ // Do not show drop marker if target place is not editable.
1110
+ this.removeDropMarker();
1111
+ return null;
1105
1112
  }
1106
1113
  this._updateDropMarkerThrottled(targetRange);
1114
+ return targetRange;
1107
1115
  }
1108
1116
  /**
1109
1117
  * Finds the final drop target range.
@@ -1275,7 +1283,7 @@ const toPx = /* #__PURE__ */ toUnit('px');
1275
1283
  const targetModelPosition = mapper.toModelPosition(targetViewPosition);
1276
1284
  const canDropOnPosition = !draggedRange || Array.from(draggedRange.getItems({
1277
1285
  shallow: true
1278
- })).every((item)=>model.schema.checkChild(targetModelPosition, item));
1286
+ })).some((item)=>model.schema.checkChild(targetModelPosition, item));
1279
1287
  if (canDropOnPosition) {
1280
1288
  if (model.schema.checkChild(targetModelPosition, '$text')) {
1281
1289
  return model.createRange(targetModelPosition);
@@ -1675,7 +1683,8 @@ const toPx = /* #__PURE__ */ toUnit('px');
1675
1683
  return;
1676
1684
  }
1677
1685
  this._draggingUid = uid();
1678
- data.dataTransfer.effectAllowed = this.isEnabled ? 'copyMove' : 'copy';
1686
+ const canEditAtDraggedRange = this.isEnabled && editor.model.canEditAt(this._draggedRange);
1687
+ data.dataTransfer.effectAllowed = canEditAtDraggedRange ? 'copyMove' : 'copy';
1679
1688
  data.dataTransfer.setData('application/ckeditor5-dragging-uid', this._draggingUid);
1680
1689
  const draggedSelection = model.createSelection(this._draggedRange.toRange());
1681
1690
  const clipboardPipeline = this.editor.plugins.get('ClipboardPipeline');
@@ -1688,7 +1697,7 @@ const toPx = /* #__PURE__ */ toUnit('px');
1688
1697
  clientX
1689
1698
  });
1690
1699
  data.stopPropagation();
1691
- if (!this.isEnabled) {
1700
+ if (!canEditAtDraggedRange) {
1692
1701
  this._draggedRange.detach();
1693
1702
  this._draggedRange = null;
1694
1703
  this._draggingUid = '';
@@ -1730,7 +1739,12 @@ const toPx = /* #__PURE__ */ toUnit('px');
1730
1739
  return;
1731
1740
  }
1732
1741
  const { clientX, clientY } = data.domEvent;
1733
- dragDropTarget.updateDropMarker(data.target, data.targetRanges, clientX, clientY, this._blockMode, this._draggedRange);
1742
+ const targetRange = dragDropTarget.updateDropMarker(data.target, data.targetRanges, clientX, clientY, this._blockMode, this._draggedRange);
1743
+ // Do not allow dropping if there is no valid target range (e.g., dropping on non-editable place).
1744
+ if (!targetRange) {
1745
+ data.dataTransfer.dropEffect = 'none';
1746
+ return;
1747
+ }
1734
1748
  // If this is content being dragged from another editor, moving out of current editor instance
1735
1749
  // is not possible until 'dragend' event case will be fixed.
1736
1750
  if (!this._draggedRange) {