@ckeditor/ckeditor5-clipboard
Advanced tools
Comparing version 0.0.0-nightly-20250110.0 to 0.0.0-nightly-20250111.0
{ | ||
"name": "@ckeditor/ckeditor5-clipboard", | ||
"version": "0.0.0-nightly-20250110.0", | ||
"version": "0.0.0-nightly-20250111.0", | ||
"description": "Clipboard integration feature for CKEditor 5.", | ||
@@ -16,7 +16,7 @@ "keywords": [ | ||
"dependencies": { | ||
"@ckeditor/ckeditor5-core": "0.0.0-nightly-20250110.0", | ||
"@ckeditor/ckeditor5-engine": "0.0.0-nightly-20250110.0", | ||
"@ckeditor/ckeditor5-ui": "0.0.0-nightly-20250110.0", | ||
"@ckeditor/ckeditor5-utils": "0.0.0-nightly-20250110.0", | ||
"@ckeditor/ckeditor5-widget": "0.0.0-nightly-20250110.0", | ||
"@ckeditor/ckeditor5-core": "0.0.0-nightly-20250111.0", | ||
"@ckeditor/ckeditor5-engine": "0.0.0-nightly-20250111.0", | ||
"@ckeditor/ckeditor5-ui": "0.0.0-nightly-20250111.0", | ||
"@ckeditor/ckeditor5-utils": "0.0.0-nightly-20250111.0", | ||
"@ckeditor/ckeditor5-widget": "0.0.0-nightly-20250111.0", | ||
"lodash-es": "4.17.21" | ||
@@ -23,0 +23,0 @@ }, |
@@ -266,3 +266,3 @@ /** | ||
this.listenTo(this, 'outputTransformation', (evt, data) => { | ||
const content = editor.data.toView(data.content); | ||
const content = editor.data.toView(data.content, { isClipboardPipeline: true }); | ||
viewDocument.fire('clipboardOutput', { | ||
@@ -277,3 +277,3 @@ dataTransfer: data.dataTransfer, | ||
data.dataTransfer.setData('text/html', this.editor.data.htmlProcessor.toData(data.content)); | ||
data.dataTransfer.setData('text/plain', viewToPlainText(data.content)); | ||
data.dataTransfer.setData('text/plain', viewToPlainText(editor.data.htmlProcessor.domConverter, data.content)); | ||
} | ||
@@ -280,0 +280,0 @@ if (data.method == 'cut') { |
@@ -8,9 +8,10 @@ /** | ||
*/ | ||
import type { ViewDocumentFragment, ViewItem } from '@ckeditor/ckeditor5-engine'; | ||
import type { DomConverter, ViewDocumentFragment, ViewItem } from '@ckeditor/ckeditor5-engine'; | ||
/** | ||
* Converts {@link module:engine/view/item~Item view item} and all of its children to plain text. | ||
* | ||
* @param converter The converter instance. | ||
* @param viewItem View item to convert. | ||
* @returns Plain text representation of `viewItem`. | ||
*/ | ||
export default function viewToPlainText(viewItem: ViewItem | ViewDocumentFragment): string; | ||
export default function viewToPlainText(converter: DomConverter, viewItem: ViewItem | ViewDocumentFragment): string; |
@@ -13,6 +13,7 @@ /** | ||
* | ||
* @param converter The converter instance. | ||
* @param viewItem View item to convert. | ||
* @returns Plain text representation of `viewItem`. | ||
*/ | ||
export default function viewToPlainText(viewItem) { | ||
export default function viewToPlainText(converter, viewItem) { | ||
if (viewItem.is('$text') || viewItem.is('$textProxy')) { | ||
@@ -34,8 +35,30 @@ return viewItem.data; | ||
for (const child of viewItem.getChildren()) { | ||
text += newLinePadding(child, prev) + viewToPlainText(child); | ||
text += newLinePadding(child, prev) + viewToPlainText(converter, child); | ||
prev = child; | ||
} | ||
// If item is a raw element, the only way to get its content is to render it and read the text directly from DOM. | ||
if (viewItem.is('rawElement')) { | ||
const tempElement = document.createElement('div'); | ||
viewItem.render(tempElement, converter); | ||
text += domElementToPlainText(tempElement); | ||
} | ||
return text; | ||
} | ||
/** | ||
* Recursively converts DOM element and all of its children to plain text. | ||
*/ | ||
function domElementToPlainText(element) { | ||
let text = ''; | ||
if (element.nodeType === Node.TEXT_NODE) { | ||
return element.textContent; | ||
} | ||
else if (element.tagName === 'BR') { | ||
return '\n'; | ||
} | ||
for (const child of element.childNodes) { | ||
text += domElementToPlainText(child); | ||
} | ||
return text; | ||
} | ||
/** | ||
* Returns new line padding to prefix the given elements with. | ||
@@ -42,0 +65,0 @@ */ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
927703
7409
+ Added@ckeditor/ckeditor5-core@0.0.0-nightly-20250111.0(transitive)
+ Added@ckeditor/ckeditor5-engine@0.0.0-nightly-20250111.0(transitive)
+ Added@ckeditor/ckeditor5-enter@0.0.0-nightly-20250111.0(transitive)
+ Added@ckeditor/ckeditor5-typing@0.0.0-nightly-20250111.0(transitive)
+ Added@ckeditor/ckeditor5-ui@0.0.0-nightly-20250111.0(transitive)
+ Added@ckeditor/ckeditor5-utils@0.0.0-nightly-20250111.0(transitive)
+ Added@ckeditor/ckeditor5-watchdog@0.0.0-nightly-20250111.0(transitive)
+ Added@ckeditor/ckeditor5-widget@0.0.0-nightly-20250111.0(transitive)
- Removed@ckeditor/ckeditor5-core@0.0.0-nightly-20250110.0(transitive)
- Removed@ckeditor/ckeditor5-engine@0.0.0-nightly-20250110.0(transitive)
- Removed@ckeditor/ckeditor5-enter@0.0.0-nightly-20250110.0(transitive)
- Removed@ckeditor/ckeditor5-typing@0.0.0-nightly-20250110.0(transitive)
- Removed@ckeditor/ckeditor5-ui@0.0.0-nightly-20250110.0(transitive)
- Removed@ckeditor/ckeditor5-utils@0.0.0-nightly-20250110.0(transitive)
- Removed@ckeditor/ckeditor5-watchdog@0.0.0-nightly-20250110.0(transitive)
- Removed@ckeditor/ckeditor5-widget@0.0.0-nightly-20250110.0(transitive)