@ckeditor/ckeditor5-clipboard 47.1.0 → 47.2.0-alpha.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-clipboard",
3
- "version": "47.1.0",
3
+ "version": "47.2.0-alpha.1",
4
4
  "description": "Clipboard integration feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -13,11 +13,11 @@
13
13
  "type": "module",
14
14
  "main": "src/index.js",
15
15
  "dependencies": {
16
- "@ckeditor/ckeditor5-core": "47.1.0",
17
- "@ckeditor/ckeditor5-engine": "47.1.0",
18
- "@ckeditor/ckeditor5-ui": "47.1.0",
19
- "@ckeditor/ckeditor5-utils": "47.1.0",
20
- "@ckeditor/ckeditor5-widget": "47.1.0",
16
+ "@ckeditor/ckeditor5-core": "47.2.0-alpha.1",
17
+ "@ckeditor/ckeditor5-engine": "47.2.0-alpha.1",
18
+ "@ckeditor/ckeditor5-ui": "47.2.0-alpha.1",
19
+ "@ckeditor/ckeditor5-utils": "47.2.0-alpha.1",
20
+ "@ckeditor/ckeditor5-widget": "47.2.0-alpha.1",
21
21
  "es-toolkit": "1.39.5"
22
22
  },
23
23
  "author": "CKSource (http://cksource.com/)",
package/src/dragdrop.js CHANGED
@@ -218,7 +218,8 @@ export class DragDrop extends Plugin {
218
218
  return;
219
219
  }
220
220
  this._draggingUid = uid();
221
- data.dataTransfer.effectAllowed = this.isEnabled ? 'copyMove' : 'copy';
221
+ const canEditAtDraggedRange = this.isEnabled && editor.model.canEditAt(this._draggedRange);
222
+ data.dataTransfer.effectAllowed = canEditAtDraggedRange ? 'copyMove' : 'copy';
222
223
  data.dataTransfer.setData('application/ckeditor5-dragging-uid', this._draggingUid);
223
224
  const draggedSelection = model.createSelection(this._draggedRange.toRange());
224
225
  const clipboardPipeline = this.editor.plugins.get('ClipboardPipeline');
@@ -227,7 +228,7 @@ export class DragDrop extends Plugin {
227
228
  const { clientX } = domEvent;
228
229
  this._updatePreview({ dataTransfer, domTarget, clientX });
229
230
  data.stopPropagation();
230
- if (!this.isEnabled) {
231
+ if (!canEditAtDraggedRange) {
231
232
  this._draggedRange.detach();
232
233
  this._draggedRange = null;
233
234
  this._draggingUid = '';
@@ -263,7 +264,12 @@ export class DragDrop extends Plugin {
263
264
  return;
264
265
  }
265
266
  const { clientX, clientY } = data.domEvent;
266
- dragDropTarget.updateDropMarker(data.target, data.targetRanges, clientX, clientY, this._blockMode, this._draggedRange);
267
+ const targetRange = dragDropTarget.updateDropMarker(data.target, data.targetRanges, clientX, clientY, this._blockMode, this._draggedRange);
268
+ // Do not allow dropping if there is no valid target range (e.g., dropping on non-editable place).
269
+ if (!targetRange) {
270
+ data.dataTransfer.dropEffect = 'none';
271
+ return;
272
+ }
267
273
  // If this is content being dragged from another editor, moving out of current editor instance
268
274
  // is not possible until 'dragend' event case will be fixed.
269
275
  if (!this._draggedRange) {
@@ -58,9 +58,10 @@ export declare class DragDropTarget extends Plugin {
58
58
  /**
59
59
  * Finds the drop target range and updates the drop marker.
60
60
  *
61
+ * @return The updated drop target range or null if no valid range was found.
61
62
  * @internal
62
63
  */
63
- updateDropMarker(targetViewElement: ViewElement, targetViewRanges: Array<ViewRange> | null, clientX: number, clientY: number, blockMode: boolean, draggedRange: ModelLiveRange | null): void;
64
+ updateDropMarker(targetViewElement: ViewElement, targetViewRanges: Array<ViewRange> | null, clientX: number, clientY: number, blockMode: boolean, draggedRange: ModelLiveRange | null): ModelRange | null;
64
65
  /**
65
66
  * Finds the final drop target range.
66
67
  *
@@ -79,6 +79,7 @@ export class DragDropTarget extends Plugin {
79
79
  /**
80
80
  * Finds the drop target range and updates the drop marker.
81
81
  *
82
+ * @return The updated drop target range or null if no valid range was found.
82
83
  * @internal
83
84
  */
84
85
  updateDropMarker(targetViewElement, targetViewRanges, clientX, clientY, blockMode, draggedRange) {
@@ -86,13 +87,20 @@ export class DragDropTarget extends Plugin {
86
87
  const targetRange = findDropTargetRange(this.editor, targetViewElement, targetViewRanges, clientX, clientY, blockMode, draggedRange);
87
88
  /* istanbul ignore next -- @preserve */
88
89
  if (!targetRange) {
89
- return;
90
+ return null;
90
91
  }
91
92
  if (draggedRange && draggedRange.containsRange(targetRange)) {
92
93
  // Target range is inside the dragged range.
93
- return this.removeDropMarker();
94
+ this.removeDropMarker();
95
+ return null;
96
+ }
97
+ if (targetRange && !this.editor.model.canEditAt(targetRange)) {
98
+ // Do not show drop marker if target place is not editable.
99
+ this.removeDropMarker();
100
+ return null;
94
101
  }
95
102
  this._updateDropMarkerThrottled(targetRange);
103
+ return targetRange;
96
104
  }
97
105
  /**
98
106
  * Finds the final drop target range.
@@ -270,7 +278,7 @@ function findDropTargetRange(editor, targetViewElement, targetViewRanges, client
270
278
  const targetModelPosition = mapper.toModelPosition(targetViewPosition);
271
279
  const canDropOnPosition = !draggedRange || Array
272
280
  .from(draggedRange.getItems({ shallow: true }))
273
- .every(item => model.schema.checkChild(targetModelPosition, item));
281
+ .some(item => model.schema.checkChild(targetModelPosition, item));
274
282
  if (canDropOnPosition) {
275
283
  if (model.schema.checkChild(targetModelPosition, '$text')) {
276
284
  return model.createRange(targetModelPosition);