@ckeditor/ckeditor5-paste-from-office 45.1.0-alpha.7 → 45.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-paste-from-office",
3
- "version": "45.1.0-alpha.7",
3
+ "version": "45.2.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.1.0-alpha.7",
17
- "@ckeditor/ckeditor5-core": "45.1.0-alpha.7",
18
- "@ckeditor/ckeditor5-engine": "45.1.0-alpha.7",
19
- "ckeditor5": "45.1.0-alpha.7"
16
+ "@ckeditor/ckeditor5-clipboard": "45.2.0-alpha.0",
17
+ "@ckeditor/ckeditor5-core": "45.2.0-alpha.0",
18
+ "@ckeditor/ckeditor5-engine": "45.2.0-alpha.0",
19
+ "ckeditor5": "45.2.0-alpha.0"
20
20
  },
21
21
  "author": "CKSource (http://cksource.com/)",
22
22
  "license": "SEE LICENSE IN LICENSE.md",
@@ -5,7 +5,6 @@
5
5
  /**
6
6
  * @module paste-from-office/filters/image
7
7
  */
8
- /* globals btoa */
9
8
  import { Matcher, UpcastWriter } from 'ckeditor5/src/engine.js';
10
9
  /**
11
10
  * Replaces source attribute of all `<img>` elements representing regular
@@ -5,7 +5,6 @@
5
5
  /**
6
6
  * @module paste-from-office/filters/parse
7
7
  */
8
- /* globals DOMParser */
9
8
  import { DomConverter, ViewDocument } from 'ckeditor5/src/engine.js';
10
9
  import { normalizeSpacing, normalizeSpacerunSpans } from './space.js';
11
10
  /**
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
+ */
5
+ /**
6
+ * @module paste-from-office/filters/table
7
+ */
8
+ import { type UpcastWriter, type ViewDocumentFragment } from 'ckeditor5/src/engine.js';
9
+ /**
10
+ * Applies border none for table and cells without a border specified.
11
+ * Normalizes style length units to px.
12
+ */
13
+ export default function transformTables(documentFragment: ViewDocumentFragment, writer: UpcastWriter): void;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
+ */
5
+ import { convertCssLengthToPx } from './utils.js';
6
+ /**
7
+ * Applies border none for table and cells without a border specified.
8
+ * Normalizes style length units to px.
9
+ */
10
+ export default function transformTables(documentFragment, writer) {
11
+ for (const item of writer.createRangeIn(documentFragment).getItems()) {
12
+ if (!item.is('element', 'table') &&
13
+ !item.is('element', 'td') &&
14
+ !item.is('element', 'th')) {
15
+ continue;
16
+ }
17
+ const sides = ['left', 'top', 'right', 'bottom'];
18
+ // As this is a pasted table, we do not want default table styles to apply here
19
+ // so we set border node for sides that does not have any border style.
20
+ // It is enough to verify border style as border color and border width properties have default values in DOM.
21
+ if (sides.every(side => !item.hasStyle(`border-${side}-style`))) {
22
+ writer.setStyle('border-style', 'none', item);
23
+ }
24
+ else {
25
+ for (const side of sides) {
26
+ if (!item.hasStyle(`border-${side}-style`)) {
27
+ writer.setStyle(`border-${side}-style`, 'none', item);
28
+ }
29
+ }
30
+ }
31
+ // Translate style length units to px.
32
+ const props = [
33
+ 'width',
34
+ 'height',
35
+ ...sides.map(side => `border-${side}-width`),
36
+ ...sides.map(side => `padding-${side}`)
37
+ ];
38
+ for (const prop of props) {
39
+ if (item.hasStyle(prop)) {
40
+ writer.setStyle(prop, convertCssLengthToPx(item.getStyle(prop)), item);
41
+ }
42
+ }
43
+ }
44
+ }
@@ -48,5 +48,5 @@ export function isPx(value) {
48
48
  * @internal
49
49
  */
50
50
  export function toPx(value) {
51
- return value.toFixed(2).replace(/\.?0+$/, '') + 'px';
51
+ return Math.round(value) + 'px';
52
52
  }
@@ -9,6 +9,7 @@ import transformBookmarks from '../filters/bookmark.js';
9
9
  import { transformListItemLikeElementsIntoLists } from '../filters/list.js';
10
10
  import { replaceImagesSourceWithBase64 } from '../filters/image.js';
11
11
  import removeMSAttributes from '../filters/removemsattributes.js';
12
+ import transformTables from '../filters/table.js';
12
13
  import { UpcastWriter } from 'ckeditor5/src/engine.js';
13
14
  const msWordMatch1 = /<meta\s*name="?generator"?\s*content="?microsoft\s*word\s*\d+"?\/?>/i;
14
15
  const msWordMatch2 = /xmlns:o="urn:schemas-microsoft-com/i;
@@ -42,6 +43,7 @@ export default class MSWordNormalizer {
42
43
  transformBookmarks(documentFragment, writer);
43
44
  transformListItemLikeElementsIntoLists(documentFragment, stylesString, this.hasMultiLevelListPlugin);
44
45
  replaceImagesSourceWithBase64(documentFragment, data.dataTransfer.getData('text/rtf'));
46
+ transformTables(documentFragment, writer);
45
47
  removeMSAttributes(documentFragment);
46
48
  data.content = documentFragment;
47
49
  }