@ckeditor/ckeditor5-paste-from-office 45.2.1 → 46.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.
- package/build/paste-from-office.js +1 -1
- package/dist/index.js +48 -23
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/filters/bookmark.d.ts +4 -2
- package/src/filters/bookmark.js +3 -1
- package/src/filters/br.d.ts +3 -2
- package/src/filters/br.js +4 -3
- package/src/filters/image.d.ts +1 -0
- package/src/filters/image.js +3 -2
- package/src/filters/list.d.ts +5 -2
- package/src/filters/list.js +10 -4
- package/src/filters/parse.d.ts +3 -3
- package/src/filters/parse.js +4 -4
- package/src/filters/removeboldwrapper.d.ts +3 -2
- package/src/filters/removeboldwrapper.js +2 -1
- package/src/filters/removegooglesheetstag.d.ts +3 -2
- package/src/filters/removegooglesheetstag.js +2 -1
- package/src/filters/removeinvalidtablewidth.d.ts +3 -2
- package/src/filters/removeinvalidtablewidth.js +2 -1
- package/src/filters/removemsattributes.d.ts +2 -1
- package/src/filters/removemsattributes.js +4 -3
- package/src/filters/removestyleblock.d.ts +3 -2
- package/src/filters/removestyleblock.js +2 -1
- package/src/filters/removexmlns.d.ts +3 -2
- package/src/filters/removexmlns.js +2 -1
- package/src/filters/space.d.ts +4 -2
- package/src/filters/space.js +6 -3
- package/src/filters/table.d.ts +4 -2
- package/src/filters/table.js +3 -1
- package/src/index.d.ts +19 -4
- package/src/index.js +18 -3
- package/src/normalizer.d.ts +5 -5
- package/src/normalizers/googledocsnormalizer.d.ts +5 -3
- package/src/normalizers/googledocsnormalizer.js +7 -5
- package/src/normalizers/googlesheetsnormalizer.d.ts +5 -3
- package/src/normalizers/googlesheetsnormalizer.js +9 -7
- package/src/normalizers/mswordnormalizer.d.ts +4 -4
- package/src/normalizers/mswordnormalizer.js +7 -7
- package/src/pastefromoffice.d.ts +3 -3
- package/src/pastefromoffice.js +9 -9
|
@@ -5,15 +5,17 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/normalizers/googledocsnormalizer
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
import removeBoldWrapper from '../filters/removeboldwrapper.js';
|
|
10
|
-
import transformBlockBrsToParagraphs from '../filters/br.js';
|
|
8
|
+
import { ViewUpcastWriter } from 'ckeditor5/src/engine.js';
|
|
9
|
+
import { removeBoldWrapper } from '../filters/removeboldwrapper.js';
|
|
10
|
+
import { transformBlockBrsToParagraphs } from '../filters/br.js';
|
|
11
11
|
import { unwrapParagraphInListItem } from '../filters/list.js';
|
|
12
12
|
const googleDocsMatch = /id=("|')docs-internal-guid-[-0-9a-f]+("|')/i;
|
|
13
13
|
/**
|
|
14
14
|
* Normalizer for the content pasted from Google Docs.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
15
17
|
*/
|
|
16
|
-
export
|
|
18
|
+
export class GoogleDocsNormalizer {
|
|
17
19
|
document;
|
|
18
20
|
/**
|
|
19
21
|
* Creates a new `GoogleDocsNormalizer` instance.
|
|
@@ -33,7 +35,7 @@ export default class GoogleDocsNormalizer {
|
|
|
33
35
|
* @inheritDoc
|
|
34
36
|
*/
|
|
35
37
|
execute(data) {
|
|
36
|
-
const writer = new
|
|
38
|
+
const writer = new ViewUpcastWriter(this.document);
|
|
37
39
|
const { body: documentFragment } = data._parsedData;
|
|
38
40
|
removeBoldWrapper(documentFragment, writer);
|
|
39
41
|
unwrapParagraphInListItem(documentFragment, writer);
|
|
@@ -6,11 +6,13 @@
|
|
|
6
6
|
* @module paste-from-office/normalizers/googlesheetsnormalizer
|
|
7
7
|
*/
|
|
8
8
|
import { type ViewDocument } from 'ckeditor5/src/engine.js';
|
|
9
|
-
import type {
|
|
9
|
+
import type { PasteFromOfficeNormalizer, PasteFromOfficeNormalizerData } from '../normalizer.js';
|
|
10
10
|
/**
|
|
11
11
|
* Normalizer for the content pasted from Google Sheets.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
12
14
|
*/
|
|
13
|
-
export
|
|
15
|
+
export declare class GoogleSheetsNormalizer implements PasteFromOfficeNormalizer {
|
|
14
16
|
readonly document: ViewDocument;
|
|
15
17
|
/**
|
|
16
18
|
* Creates a new `GoogleSheetsNormalizer` instance.
|
|
@@ -25,5 +27,5 @@ export default class GoogleSheetsNormalizer implements Normalizer {
|
|
|
25
27
|
/**
|
|
26
28
|
* @inheritDoc
|
|
27
29
|
*/
|
|
28
|
-
execute(data:
|
|
30
|
+
execute(data: PasteFromOfficeNormalizerData): void;
|
|
29
31
|
}
|
|
@@ -5,16 +5,18 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/normalizers/googlesheetsnormalizer
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
import removeXmlns from '../filters/removexmlns.js';
|
|
10
|
-
import removeGoogleSheetsTag from '../filters/removegooglesheetstag.js';
|
|
11
|
-
import removeInvalidTableWidth from '../filters/removeinvalidtablewidth.js';
|
|
12
|
-
import removeStyleBlock from '../filters/removestyleblock.js';
|
|
8
|
+
import { ViewUpcastWriter } from 'ckeditor5/src/engine.js';
|
|
9
|
+
import { removeXmlns } from '../filters/removexmlns.js';
|
|
10
|
+
import { removeGoogleSheetsTag } from '../filters/removegooglesheetstag.js';
|
|
11
|
+
import { removeInvalidTableWidth } from '../filters/removeinvalidtablewidth.js';
|
|
12
|
+
import { removeStyleBlock } from '../filters/removestyleblock.js';
|
|
13
13
|
const googleSheetsMatch = /<google-sheets-html-origin/i;
|
|
14
14
|
/**
|
|
15
15
|
* Normalizer for the content pasted from Google Sheets.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
16
18
|
*/
|
|
17
|
-
export
|
|
19
|
+
export class GoogleSheetsNormalizer {
|
|
18
20
|
document;
|
|
19
21
|
/**
|
|
20
22
|
* Creates a new `GoogleSheetsNormalizer` instance.
|
|
@@ -34,7 +36,7 @@ export default class GoogleSheetsNormalizer {
|
|
|
34
36
|
* @inheritDoc
|
|
35
37
|
*/
|
|
36
38
|
execute(data) {
|
|
37
|
-
const writer = new
|
|
39
|
+
const writer = new ViewUpcastWriter(this.document);
|
|
38
40
|
const { body: documentFragment } = data._parsedData;
|
|
39
41
|
removeGoogleSheetsTag(documentFragment, writer);
|
|
40
42
|
removeXmlns(documentFragment, writer);
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
4
|
*/
|
|
5
5
|
import { type ViewDocument } from 'ckeditor5/src/engine.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { PasteFromOfficeNormalizer, PasteFromOfficeNormalizerData } from '../normalizer.js';
|
|
7
7
|
/**
|
|
8
8
|
* Normalizer for the content pasted from Microsoft Word.
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export declare class PasteFromOfficeMSWordNormalizer implements PasteFromOfficeNormalizer {
|
|
11
11
|
readonly document: ViewDocument;
|
|
12
12
|
readonly hasMultiLevelListPlugin: boolean;
|
|
13
13
|
/**
|
|
14
|
-
* Creates a new `
|
|
14
|
+
* Creates a new `PasteFromOfficeMSWordNormalizer` instance.
|
|
15
15
|
*
|
|
16
16
|
* @param document View document.
|
|
17
17
|
*/
|
|
@@ -23,5 +23,5 @@ export default class MSWordNormalizer implements Normalizer {
|
|
|
23
23
|
/**
|
|
24
24
|
* @inheritDoc
|
|
25
25
|
*/
|
|
26
|
-
execute(data:
|
|
26
|
+
execute(data: PasteFromOfficeNormalizerData): void;
|
|
27
27
|
}
|
|
@@ -5,22 +5,22 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/normalizers/mswordnormalizer
|
|
7
7
|
*/
|
|
8
|
-
import transformBookmarks from '../filters/bookmark.js';
|
|
8
|
+
import { transformBookmarks } from '../filters/bookmark.js';
|
|
9
9
|
import { transformListItemLikeElementsIntoLists } from '../filters/list.js';
|
|
10
10
|
import { replaceImagesSourceWithBase64 } from '../filters/image.js';
|
|
11
|
-
import removeMSAttributes from '../filters/removemsattributes.js';
|
|
12
|
-
import transformTables from '../filters/table.js';
|
|
13
|
-
import {
|
|
11
|
+
import { removeMSAttributes } from '../filters/removemsattributes.js';
|
|
12
|
+
import { transformTables } from '../filters/table.js';
|
|
13
|
+
import { ViewUpcastWriter } from 'ckeditor5/src/engine.js';
|
|
14
14
|
const msWordMatch1 = /<meta\s*name="?generator"?\s*content="?microsoft\s*word\s*\d+"?\/?>/i;
|
|
15
15
|
const msWordMatch2 = /xmlns:o="urn:schemas-microsoft-com/i;
|
|
16
16
|
/**
|
|
17
17
|
* Normalizer for the content pasted from Microsoft Word.
|
|
18
18
|
*/
|
|
19
|
-
export
|
|
19
|
+
export class PasteFromOfficeMSWordNormalizer {
|
|
20
20
|
document;
|
|
21
21
|
hasMultiLevelListPlugin;
|
|
22
22
|
/**
|
|
23
|
-
* Creates a new `
|
|
23
|
+
* Creates a new `PasteFromOfficeMSWordNormalizer` instance.
|
|
24
24
|
*
|
|
25
25
|
* @param document View document.
|
|
26
26
|
*/
|
|
@@ -38,7 +38,7 @@ export default class MSWordNormalizer {
|
|
|
38
38
|
* @inheritDoc
|
|
39
39
|
*/
|
|
40
40
|
execute(data) {
|
|
41
|
-
const writer = new
|
|
41
|
+
const writer = new ViewUpcastWriter(this.document);
|
|
42
42
|
const { body: documentFragment, stylesString } = data._parsedData;
|
|
43
43
|
transformBookmarks(documentFragment, writer);
|
|
44
44
|
transformListItemLikeElementsIntoLists(documentFragment, stylesString, this.hasMultiLevelListPlugin);
|
package/src/pastefromoffice.d.ts
CHANGED
|
@@ -13,14 +13,14 @@ import { ClipboardPipeline } from 'ckeditor5/src/clipboard.js';
|
|
|
13
13
|
* This plugin handles content pasted from Office apps and transforms it (if necessary)
|
|
14
14
|
* to a valid structure which can then be understood by the editor features.
|
|
15
15
|
*
|
|
16
|
-
* Transformation is made by a set of predefined {@link module:paste-from-office/normalizer~
|
|
16
|
+
* Transformation is made by a set of predefined {@link module:paste-from-office/normalizer~PasteFromOfficeNormalizer normalizers}.
|
|
17
17
|
* This plugin includes following normalizers:
|
|
18
|
-
* * {@link module:paste-from-office/normalizers/mswordnormalizer~
|
|
18
|
+
* * {@link module:paste-from-office/normalizers/mswordnormalizer~PasteFromOfficeMSWordNormalizer Microsoft Word normalizer}
|
|
19
19
|
* * {@link module:paste-from-office/normalizers/googledocsnormalizer~GoogleDocsNormalizer Google Docs normalizer}
|
|
20
20
|
*
|
|
21
21
|
* For more information about this feature check the {@glink api/paste-from-office package page}.
|
|
22
22
|
*/
|
|
23
|
-
export
|
|
23
|
+
export declare class PasteFromOffice extends Plugin {
|
|
24
24
|
/**
|
|
25
25
|
* @inheritDoc
|
|
26
26
|
*/
|
package/src/pastefromoffice.js
CHANGED
|
@@ -7,24 +7,24 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
9
|
import { ClipboardPipeline } from 'ckeditor5/src/clipboard.js';
|
|
10
|
-
import
|
|
11
|
-
import GoogleDocsNormalizer from './normalizers/googledocsnormalizer.js';
|
|
12
|
-
import GoogleSheetsNormalizer from './normalizers/googlesheetsnormalizer.js';
|
|
13
|
-
import {
|
|
10
|
+
import { PasteFromOfficeMSWordNormalizer } from './normalizers/mswordnormalizer.js';
|
|
11
|
+
import { GoogleDocsNormalizer } from './normalizers/googledocsnormalizer.js';
|
|
12
|
+
import { GoogleSheetsNormalizer } from './normalizers/googlesheetsnormalizer.js';
|
|
13
|
+
import { parsePasteOfficeHtml } from './filters/parse.js';
|
|
14
14
|
/**
|
|
15
15
|
* The Paste from Office plugin.
|
|
16
16
|
*
|
|
17
17
|
* This plugin handles content pasted from Office apps and transforms it (if necessary)
|
|
18
18
|
* to a valid structure which can then be understood by the editor features.
|
|
19
19
|
*
|
|
20
|
-
* Transformation is made by a set of predefined {@link module:paste-from-office/normalizer~
|
|
20
|
+
* Transformation is made by a set of predefined {@link module:paste-from-office/normalizer~PasteFromOfficeNormalizer normalizers}.
|
|
21
21
|
* This plugin includes following normalizers:
|
|
22
|
-
* * {@link module:paste-from-office/normalizers/mswordnormalizer~
|
|
22
|
+
* * {@link module:paste-from-office/normalizers/mswordnormalizer~PasteFromOfficeMSWordNormalizer Microsoft Word normalizer}
|
|
23
23
|
* * {@link module:paste-from-office/normalizers/googledocsnormalizer~GoogleDocsNormalizer Google Docs normalizer}
|
|
24
24
|
*
|
|
25
25
|
* For more information about this feature check the {@glink api/paste-from-office package page}.
|
|
26
26
|
*/
|
|
27
|
-
export
|
|
27
|
+
export class PasteFromOffice extends Plugin {
|
|
28
28
|
/**
|
|
29
29
|
* @inheritDoc
|
|
30
30
|
*/
|
|
@@ -52,7 +52,7 @@ export default class PasteFromOffice extends Plugin {
|
|
|
52
52
|
const viewDocument = editor.editing.view.document;
|
|
53
53
|
const normalizers = [];
|
|
54
54
|
const hasMultiLevelListPlugin = this.editor.plugins.has('MultiLevelList');
|
|
55
|
-
normalizers.push(new
|
|
55
|
+
normalizers.push(new PasteFromOfficeMSWordNormalizer(viewDocument, hasMultiLevelListPlugin));
|
|
56
56
|
normalizers.push(new GoogleDocsNormalizer(viewDocument));
|
|
57
57
|
normalizers.push(new GoogleSheetsNormalizer(viewDocument));
|
|
58
58
|
clipboardPipeline.on('inputTransformation', (evt, data) => {
|
|
@@ -67,7 +67,7 @@ export default class PasteFromOffice extends Plugin {
|
|
|
67
67
|
const activeNormalizer = normalizers.find(normalizer => normalizer.isActive(htmlString));
|
|
68
68
|
if (activeNormalizer) {
|
|
69
69
|
if (!data._parsedData) {
|
|
70
|
-
data._parsedData =
|
|
70
|
+
data._parsedData = parsePasteOfficeHtml(htmlString, viewDocument.stylesProcessor);
|
|
71
71
|
}
|
|
72
72
|
activeNormalizer.execute(data);
|
|
73
73
|
data._isTransformedWithPasteFromOffice = true;
|