@ckeditor/ckeditor5-clipboard 39.0.2 → 40.0.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.
@@ -1,47 +1,47 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module clipboard/dragdropblocktoolbar
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- /**
10
- * Integration of an experimental block Drag and drop support with the block toolbar.
11
- *
12
- * @internal
13
- */
14
- export default class DragDropBlockToolbar extends Plugin {
15
- /**
16
- * Whether current dragging is started by block toolbar button dragging.
17
- */
18
- private _isBlockDragging;
19
- /**
20
- * DOM Emitter.
21
- */
22
- private _domEmitter;
23
- /**
24
- * @inheritDoc
25
- */
26
- static get pluginName(): "DragDropBlockToolbar";
27
- /**
28
- * @inheritDoc
29
- */
30
- init(): void;
31
- /**
32
- * @inheritDoc
33
- */
34
- destroy(): void;
35
- /**
36
- * The `dragstart` event handler.
37
- */
38
- private _handleBlockDragStart;
39
- /**
40
- * The `dragover` and `drop` event handler.
41
- */
42
- private _handleBlockDragging;
43
- /**
44
- * The `dragend` event handler.
45
- */
46
- private _handleBlockDragEnd;
47
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module clipboard/dragdropblocktoolbar
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ /**
10
+ * Integration of a block Drag and Drop support with the block toolbar.
11
+ *
12
+ * @internal
13
+ */
14
+ export default class DragDropBlockToolbar extends Plugin {
15
+ /**
16
+ * Whether current dragging is started by block toolbar button dragging.
17
+ */
18
+ private _isBlockDragging;
19
+ /**
20
+ * DOM Emitter.
21
+ */
22
+ private _domEmitter;
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ static get pluginName(): "DragDropBlockToolbar";
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ init(): void;
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ destroy(): void;
35
+ /**
36
+ * The `dragstart` event handler.
37
+ */
38
+ private _handleBlockDragStart;
39
+ /**
40
+ * The `dragover` and `drop` event handler.
41
+ */
42
+ private _handleBlockDragging;
43
+ /**
44
+ * The `dragend` event handler.
45
+ */
46
+ private _handleBlockDragEnd;
47
+ }
@@ -1,114 +1,121 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module clipboard/dragdropblocktoolbar
7
- */
8
- /* istanbul ignore file -- @preserve */
9
- import { Plugin } from '@ckeditor/ckeditor5-core';
10
- import { env, global, DomEmitterMixin } from '@ckeditor/ckeditor5-utils';
11
- import ClipboardObserver from './clipboardobserver';
12
- /**
13
- * Integration of an experimental block Drag and drop support with the block toolbar.
14
- *
15
- * @internal
16
- */
17
- export default class DragDropBlockToolbar extends Plugin {
18
- constructor() {
19
- super(...arguments);
20
- /**
21
- * Whether current dragging is started by block toolbar button dragging.
22
- */
23
- this._isBlockDragging = false;
24
- /**
25
- * DOM Emitter.
26
- */
27
- this._domEmitter = new (DomEmitterMixin())();
28
- }
29
- /**
30
- * @inheritDoc
31
- */
32
- static get pluginName() {
33
- return 'DragDropBlockToolbar';
34
- }
35
- /**
36
- * @inheritDoc
37
- */
38
- init() {
39
- const editor = this.editor;
40
- this.listenTo(editor, 'change:isReadOnly', (evt, name, isReadOnly) => {
41
- if (isReadOnly) {
42
- this.forceDisabled('readOnlyMode');
43
- this._isBlockDragging = false;
44
- }
45
- else {
46
- this.clearForceDisabled('readOnlyMode');
47
- }
48
- });
49
- if (env.isAndroid) {
50
- this.forceDisabled('noAndroidSupport');
51
- }
52
- if (editor.plugins.has('BlockToolbar')) {
53
- const blockToolbar = editor.plugins.get('BlockToolbar');
54
- const element = blockToolbar.buttonView.element;
55
- element.setAttribute('draggable', 'true');
56
- this._domEmitter.listenTo(element, 'dragstart', (evt, data) => this._handleBlockDragStart(data));
57
- this._domEmitter.listenTo(global.document, 'dragover', (evt, data) => this._handleBlockDragging(data));
58
- this._domEmitter.listenTo(global.document, 'drop', (evt, data) => this._handleBlockDragging(data));
59
- this._domEmitter.listenTo(global.document, 'dragend', () => this._handleBlockDragEnd(), { useCapture: true });
60
- }
61
- }
62
- /**
63
- * @inheritDoc
64
- */
65
- destroy() {
66
- this._domEmitter.stopListening();
67
- return super.destroy();
68
- }
69
- /**
70
- * The `dragstart` event handler.
71
- */
72
- _handleBlockDragStart(domEvent) {
73
- if (!this.isEnabled) {
74
- return;
75
- }
76
- const model = this.editor.model;
77
- const selection = model.document.selection;
78
- const blocks = Array.from(selection.getSelectedBlocks());
79
- const draggedRange = model.createRange(model.createPositionBefore(blocks[0]), model.createPositionAfter(blocks[blocks.length - 1]));
80
- model.change(writer => writer.setSelection(draggedRange));
81
- this._isBlockDragging = true;
82
- this.editor.editing.view.getObserver(ClipboardObserver).onDomEvent(domEvent);
83
- }
84
- /**
85
- * The `dragover` and `drop` event handler.
86
- */
87
- _handleBlockDragging(domEvent) {
88
- if (!this.isEnabled || !this._isBlockDragging) {
89
- return;
90
- }
91
- const clientX = domEvent.clientX + 100;
92
- const clientY = domEvent.clientY;
93
- const target = document.elementFromPoint(clientX, clientY);
94
- if (!target || !target.closest('.ck-editor__editable')) {
95
- return;
96
- }
97
- this.editor.editing.view.getObserver(ClipboardObserver).onDomEvent({
98
- ...domEvent,
99
- type: domEvent.type,
100
- dataTransfer: domEvent.dataTransfer,
101
- target,
102
- clientX,
103
- clientY,
104
- preventDefault: () => domEvent.preventDefault(),
105
- stopPropagation: () => domEvent.stopPropagation()
106
- });
107
- }
108
- /**
109
- * The `dragend` event handler.
110
- */
111
- _handleBlockDragEnd() {
112
- this._isBlockDragging = false;
113
- }
114
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module clipboard/dragdropblocktoolbar
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ import { env, global, DomEmitterMixin } from '@ckeditor/ckeditor5-utils';
10
+ import ClipboardObserver from './clipboardobserver';
11
+ /**
12
+ * Integration of a block Drag and Drop support with the block toolbar.
13
+ *
14
+ * @internal
15
+ */
16
+ export default class DragDropBlockToolbar extends Plugin {
17
+ constructor() {
18
+ super(...arguments);
19
+ /**
20
+ * Whether current dragging is started by block toolbar button dragging.
21
+ */
22
+ this._isBlockDragging = false;
23
+ /**
24
+ * DOM Emitter.
25
+ */
26
+ this._domEmitter = new (DomEmitterMixin())();
27
+ }
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ static get pluginName() {
32
+ return 'DragDropBlockToolbar';
33
+ }
34
+ /**
35
+ * @inheritDoc
36
+ */
37
+ init() {
38
+ const editor = this.editor;
39
+ this.listenTo(editor, 'change:isReadOnly', (evt, name, isReadOnly) => {
40
+ if (isReadOnly) {
41
+ this.forceDisabled('readOnlyMode');
42
+ this._isBlockDragging = false;
43
+ }
44
+ else {
45
+ this.clearForceDisabled('readOnlyMode');
46
+ }
47
+ });
48
+ if (env.isAndroid) {
49
+ this.forceDisabled('noAndroidSupport');
50
+ }
51
+ if (editor.plugins.has('BlockToolbar')) {
52
+ const blockToolbar = editor.plugins.get('BlockToolbar');
53
+ const element = blockToolbar.buttonView.element;
54
+ this._domEmitter.listenTo(element, 'dragstart', (evt, data) => this._handleBlockDragStart(data));
55
+ this._domEmitter.listenTo(global.document, 'dragover', (evt, data) => this._handleBlockDragging(data));
56
+ this._domEmitter.listenTo(global.document, 'drop', (evt, data) => this._handleBlockDragging(data));
57
+ this._domEmitter.listenTo(global.document, 'dragend', () => this._handleBlockDragEnd(), { useCapture: true });
58
+ if (this.isEnabled) {
59
+ element.setAttribute('draggable', 'true');
60
+ }
61
+ this.on('change:isEnabled', (evt, name, isEnabled) => {
62
+ element.setAttribute('draggable', isEnabled ? 'true' : 'false');
63
+ });
64
+ }
65
+ }
66
+ /**
67
+ * @inheritDoc
68
+ */
69
+ destroy() {
70
+ this._domEmitter.stopListening();
71
+ return super.destroy();
72
+ }
73
+ /**
74
+ * The `dragstart` event handler.
75
+ */
76
+ _handleBlockDragStart(domEvent) {
77
+ if (!this.isEnabled) {
78
+ return;
79
+ }
80
+ const model = this.editor.model;
81
+ const selection = model.document.selection;
82
+ const view = this.editor.editing.view;
83
+ const blocks = Array.from(selection.getSelectedBlocks());
84
+ const draggedRange = model.createRange(model.createPositionBefore(blocks[0]), model.createPositionAfter(blocks[blocks.length - 1]));
85
+ model.change(writer => writer.setSelection(draggedRange));
86
+ this._isBlockDragging = true;
87
+ view.focus();
88
+ view.getObserver(ClipboardObserver).onDomEvent(domEvent);
89
+ }
90
+ /**
91
+ * The `dragover` and `drop` event handler.
92
+ */
93
+ _handleBlockDragging(domEvent) {
94
+ if (!this.isEnabled || !this._isBlockDragging) {
95
+ return;
96
+ }
97
+ const clientX = domEvent.clientX + (this.editor.locale.contentLanguageDirection == 'ltr' ? 100 : -100);
98
+ const clientY = domEvent.clientY;
99
+ const target = document.elementFromPoint(clientX, clientY);
100
+ const view = this.editor.editing.view;
101
+ if (!target || !target.closest('.ck-editor__editable')) {
102
+ return;
103
+ }
104
+ view.getObserver(ClipboardObserver).onDomEvent({
105
+ ...domEvent,
106
+ type: domEvent.type,
107
+ dataTransfer: domEvent.dataTransfer,
108
+ target,
109
+ clientX,
110
+ clientY,
111
+ preventDefault: () => domEvent.preventDefault(),
112
+ stopPropagation: () => domEvent.stopPropagation()
113
+ });
114
+ }
115
+ /**
116
+ * The `dragend` event handler.
117
+ */
118
+ _handleBlockDragEnd() {
119
+ this._isBlockDragging = false;
120
+ }
121
+ }
@@ -1,94 +1,94 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module clipboard/dragdroptarget
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- import { type Range, type ViewElement, type ViewRange } from '@ckeditor/ckeditor5-engine';
10
- /**
11
- * Part of the Drag and Drop handling. Responsible for finding and displaying the drop target.
12
- *
13
- * @internal
14
- */
15
- export default class DragDropTarget extends Plugin {
16
- /**
17
- * A delayed callback removing the drop marker.
18
- *
19
- * @internal
20
- */
21
- readonly removeDropMarkerDelayed: import("@ckeditor/ckeditor5-utils").DelayedFunc<() => void>;
22
- /**
23
- * A throttled callback updating the drop marker.
24
- */
25
- private readonly _updateDropMarkerThrottled;
26
- /**
27
- * A throttled callback reconverting the drop parker.
28
- */
29
- private readonly _reconvertMarkerThrottled;
30
- /**
31
- * The horizontal drop target line view.
32
- */
33
- private _dropTargetLineView;
34
- /**
35
- * DOM Emitter.
36
- */
37
- private _domEmitter;
38
- /**
39
- * Map of document scrollable elements.
40
- */
41
- private _scrollables;
42
- /**
43
- * @inheritDoc
44
- */
45
- static get pluginName(): "DragDropTarget";
46
- /**
47
- * @inheritDoc
48
- */
49
- init(): void;
50
- /**
51
- * @inheritDoc
52
- */
53
- destroy(): void;
54
- /**
55
- * Finds the drop target range and updates the drop marker.
56
- *
57
- * @internal
58
- */
59
- updateDropMarker(targetViewElement: ViewElement, targetViewRanges: Array<ViewRange> | null, clientX: number, clientY: number, blockMode: boolean): void;
60
- /**
61
- * Finds the final drop target range.
62
- *
63
- * @internal
64
- */
65
- getFinalDropRange(targetViewElement: ViewElement, targetViewRanges: Array<ViewRange> | null, clientX: number, clientY: number, blockMode: boolean): Range | null;
66
- /**
67
- * Removes the drop target marker.
68
- *
69
- * @internal
70
- */
71
- removeDropMarker(): void;
72
- /**
73
- * Creates downcast conversion for the drop target marker.
74
- */
75
- private _setupDropMarker;
76
- /**
77
- * Updates the drop target marker to the provided range.
78
- *
79
- * @param targetRange The range to set the marker to.
80
- */
81
- private _updateDropMarker;
82
- /**
83
- * Creates the UI element for vertical (in-line) drop target.
84
- */
85
- private _createDropTargetPosition;
86
- /**
87
- * Updates the horizontal drop target line.
88
- */
89
- private _updateDropTargetLine;
90
- /**
91
- * Finds the closest scrollable element rect for the given view element.
92
- */
93
- private _getScrollableRect;
94
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module clipboard/dragdroptarget
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ import { type Range, type ViewElement, type ViewRange } from '@ckeditor/ckeditor5-engine';
10
+ /**
11
+ * Part of the Drag and Drop handling. Responsible for finding and displaying the drop target.
12
+ *
13
+ * @internal
14
+ */
15
+ export default class DragDropTarget extends Plugin {
16
+ /**
17
+ * A delayed callback removing the drop marker.
18
+ *
19
+ * @internal
20
+ */
21
+ readonly removeDropMarkerDelayed: import("@ckeditor/ckeditor5-utils").DelayedFunc<() => void>;
22
+ /**
23
+ * A throttled callback updating the drop marker.
24
+ */
25
+ private readonly _updateDropMarkerThrottled;
26
+ /**
27
+ * A throttled callback reconverting the drop parker.
28
+ */
29
+ private readonly _reconvertMarkerThrottled;
30
+ /**
31
+ * The horizontal drop target line view.
32
+ */
33
+ private _dropTargetLineView;
34
+ /**
35
+ * DOM Emitter.
36
+ */
37
+ private _domEmitter;
38
+ /**
39
+ * Map of document scrollable elements.
40
+ */
41
+ private _scrollables;
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ static get pluginName(): "DragDropTarget";
46
+ /**
47
+ * @inheritDoc
48
+ */
49
+ init(): void;
50
+ /**
51
+ * @inheritDoc
52
+ */
53
+ destroy(): void;
54
+ /**
55
+ * Finds the drop target range and updates the drop marker.
56
+ *
57
+ * @internal
58
+ */
59
+ updateDropMarker(targetViewElement: ViewElement, targetViewRanges: Array<ViewRange> | null, clientX: number, clientY: number, blockMode: boolean): void;
60
+ /**
61
+ * Finds the final drop target range.
62
+ *
63
+ * @internal
64
+ */
65
+ getFinalDropRange(targetViewElement: ViewElement, targetViewRanges: Array<ViewRange> | null, clientX: number, clientY: number, blockMode: boolean): Range | null;
66
+ /**
67
+ * Removes the drop target marker.
68
+ *
69
+ * @internal
70
+ */
71
+ removeDropMarker(): void;
72
+ /**
73
+ * Creates downcast conversion for the drop target marker.
74
+ */
75
+ private _setupDropMarker;
76
+ /**
77
+ * Updates the drop target marker to the provided range.
78
+ *
79
+ * @param targetRange The range to set the marker to.
80
+ */
81
+ private _updateDropMarker;
82
+ /**
83
+ * Creates the UI element for vertical (in-line) drop target.
84
+ */
85
+ private _createDropTargetPosition;
86
+ /**
87
+ * Updates the horizontal drop target line.
88
+ */
89
+ private _updateDropTargetLine;
90
+ /**
91
+ * Finds the closest scrollable element rect for the given view element.
92
+ */
93
+ private _getScrollableRect;
94
+ }