@ckeditor/ckeditor5-paste-from-office 45.0.0 → 45.1.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/build/paste-from-office.js +1 -1
- package/dist/index.js +19 -9
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/filters/image.js +19 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-paste-from-office",
|
|
3
|
-
"version": "45.0.0",
|
|
3
|
+
"version": "45.1.0-alpha.0",
|
|
4
4
|
"description": "Paste from Office feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"main": "src/index.js",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@ckeditor/ckeditor5-clipboard": "45.0.0",
|
|
17
|
-
"@ckeditor/ckeditor5-core": "45.0.0",
|
|
18
|
-
"@ckeditor/ckeditor5-engine": "45.0.0",
|
|
19
|
-
"ckeditor5": "45.0.0"
|
|
16
|
+
"@ckeditor/ckeditor5-clipboard": "45.1.0-alpha.0",
|
|
17
|
+
"@ckeditor/ckeditor5-core": "45.1.0-alpha.0",
|
|
18
|
+
"@ckeditor/ckeditor5-engine": "45.1.0-alpha.0",
|
|
19
|
+
"ckeditor5": "45.1.0-alpha.0"
|
|
20
20
|
},
|
|
21
21
|
"author": "CKSource (http://cksource.com/)",
|
|
22
22
|
"license": "SEE LICENSE IN LICENSE.md",
|
package/src/filters/image.js
CHANGED
|
@@ -180,9 +180,11 @@ function insertMissingImgs(shapeIds, documentFragment, writer) {
|
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
182
|
* Finds all `<img>` elements in a given document fragment which have source pointing to local `file://` resource.
|
|
183
|
+
* This function also tracks the index position of each image in the document, which is essential for
|
|
184
|
+
* precise matching with hexadecimal representations in RTF data.
|
|
183
185
|
*
|
|
184
186
|
* @param documentFragment Document fragment in which to look for `<img>` elements.
|
|
185
|
-
* @returns
|
|
187
|
+
* @returns Array of found images along with their position index in the document.
|
|
186
188
|
*/
|
|
187
189
|
function findAllImageElementsWithLocalSource(documentFragment, writer) {
|
|
188
190
|
const range = writer.createRangeIn(documentFragment);
|
|
@@ -190,11 +192,16 @@ function findAllImageElementsWithLocalSource(documentFragment, writer) {
|
|
|
190
192
|
name: 'img'
|
|
191
193
|
});
|
|
192
194
|
const imgs = [];
|
|
195
|
+
let currentImageIndex = 0;
|
|
193
196
|
for (const value of range) {
|
|
194
197
|
if (value.item.is('element') && imageElementsMatcher.match(value.item)) {
|
|
195
198
|
if (value.item.getAttribute('src').startsWith('file://')) {
|
|
196
|
-
imgs.push(
|
|
199
|
+
imgs.push({
|
|
200
|
+
element: value.item,
|
|
201
|
+
imageIndex: currentImageIndex
|
|
202
|
+
});
|
|
197
203
|
}
|
|
204
|
+
currentImageIndex++;
|
|
198
205
|
}
|
|
199
206
|
}
|
|
200
207
|
return imgs;
|
|
@@ -237,17 +244,20 @@ function extractImageDataFromRtf(rtfData) {
|
|
|
237
244
|
}
|
|
238
245
|
/**
|
|
239
246
|
* Replaces `src` attribute value of all given images with the corresponding base64 image representation.
|
|
247
|
+
* Uses the image index to precisely match with the correct hexadecimal representation from RTF data.
|
|
240
248
|
*
|
|
241
|
-
* @param imageElements Array of image elements which will have
|
|
249
|
+
* @param imageElements Array of image elements along with their indices which will have their sources replaced.
|
|
242
250
|
* @param imagesHexSources Array of images hex sources (usually the result of `extractImageDataFromRtf()` function).
|
|
243
|
-
*
|
|
251
|
+
* Contains hexadecimal representations of ALL images in the document, not just those with `file://` URLs.
|
|
252
|
+
* In XML documents, the same image might be defined both as base64 in HTML and as hexadecimal in RTF data.
|
|
244
253
|
*/
|
|
245
254
|
function replaceImagesFileSourceWithInlineRepresentation(imageElements, imagesHexSources, writer) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
255
|
+
for (let i = 0; i < imageElements.length; i++) {
|
|
256
|
+
const { element, imageIndex } = imageElements[i];
|
|
257
|
+
const rtfHexSource = imagesHexSources[imageIndex];
|
|
258
|
+
if (rtfHexSource) {
|
|
259
|
+
const newSrc = `data:${rtfHexSource.type};base64,${_convertHexToBase64(rtfHexSource.hex)}`;
|
|
260
|
+
writer.setAttribute('src', newSrc, element);
|
|
251
261
|
}
|
|
252
262
|
}
|
|
253
263
|
}
|