@ckeditor/ckeditor5-paste-from-office 43.3.1 → 44.0.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.
@@ -6,7 +6,7 @@
6
6
  * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
7
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
8
  */
9
- import type { ViewDocument } from 'ckeditor5/src/engine.js';
9
+ import { type ViewDocument } from 'ckeditor5/src/engine.js';
10
10
  import type { Normalizer, NormalizerData } from '../normalizer.js';
11
11
  /**
12
12
  * Normalizer for the content pasted from Microsoft Word.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-paste-from-office",
3
- "version": "43.3.1",
3
+ "version": "44.0.0-alpha.1",
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": "43.3.1",
17
- "@ckeditor/ckeditor5-core": "43.3.1",
18
- "@ckeditor/ckeditor5-engine": "43.3.1",
19
- "ckeditor5": "43.3.1"
16
+ "@ckeditor/ckeditor5-clipboard": "44.0.0-alpha.1",
17
+ "@ckeditor/ckeditor5-core": "44.0.0-alpha.1",
18
+ "@ckeditor/ckeditor5-engine": "44.0.0-alpha.1",
19
+ "ckeditor5": "44.0.0-alpha.1"
20
20
  },
21
21
  "author": "CKSource (http://cksource.com/)",
22
22
  "license": "GPL-2.0-or-later",
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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 paste-from-office/filters/bookmark
7
+ */
8
+ import { type UpcastWriter, type ViewDocumentFragment } from 'ckeditor5/src/engine.js';
9
+ /**
10
+ * Transforms `<a>` elements which are bookmarks by moving their children after the element.
11
+ */
12
+ export default function transformBookmarks(documentFragment: ViewDocumentFragment, writer: UpcastWriter): void;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * Transforms `<a>` elements which are bookmarks by moving their children after the element.
7
+ */
8
+ export default function transformBookmarks(documentFragment, writer) {
9
+ const elementsToChange = [];
10
+ for (const value of writer.createRangeIn(documentFragment)) {
11
+ const element = value.item;
12
+ if (element.is('element', 'a') &&
13
+ !element.hasAttribute('href') &&
14
+ (element.hasAttribute('id') || element.hasAttribute('name'))) {
15
+ elementsToChange.push(element);
16
+ }
17
+ }
18
+ for (const element of elementsToChange) {
19
+ const index = element.parent.getChildIndex(element) + 1;
20
+ const children = element.getChildren();
21
+ writer.insertChild(index, children, element.parent);
22
+ }
23
+ }
@@ -2,7 +2,7 @@
2
2
  * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
- import type { ViewDocument } from 'ckeditor5/src/engine.js';
5
+ import { type ViewDocument } from 'ckeditor5/src/engine.js';
6
6
  import type { Normalizer, NormalizerData } from '../normalizer.js';
7
7
  /**
8
8
  * Normalizer for the content pasted from Microsoft Word.
@@ -5,9 +5,11 @@
5
5
  /**
6
6
  * @module paste-from-office/normalizers/mswordnormalizer
7
7
  */
8
+ import transformBookmarks from '../filters/bookmark.js';
8
9
  import { transformListItemLikeElementsIntoLists } from '../filters/list.js';
9
10
  import { replaceImagesSourceWithBase64 } from '../filters/image.js';
10
11
  import removeMSAttributes from '../filters/removemsattributes.js';
12
+ import { UpcastWriter } from 'ckeditor5/src/engine.js';
11
13
  const msWordMatch1 = /<meta\s*name="?generator"?\s*content="?microsoft\s*word\s*\d+"?\/?>/i;
12
14
  const msWordMatch2 = /xmlns:o="urn:schemas-microsoft-com/i;
13
15
  /**
@@ -33,7 +35,9 @@ export default class MSWordNormalizer {
33
35
  * @inheritDoc
34
36
  */
35
37
  execute(data) {
38
+ const writer = new UpcastWriter(this.document);
36
39
  const { body: documentFragment, stylesString } = data._parsedData;
40
+ transformBookmarks(documentFragment, writer);
37
41
  transformListItemLikeElementsIntoLists(documentFragment, stylesString, this.hasMultiLevelListPlugin);
38
42
  replaceImagesSourceWithBase64(documentFragment, data.dataTransfer.getData('text/rtf'));
39
43
  removeMSAttributes(documentFragment);