@ckeditor/ckeditor5-paste-from-office 47.2.0 → 47.3.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/LICENSE.md CHANGED
@@ -11,10 +11,10 @@ Licensed under a dual-license model, this software is available under:
11
11
 
12
12
  For more information, see: [https://ckeditor.com/legal/ckeditor-licensing-options](https://ckeditor.com/legal/ckeditor-licensing-options).
13
13
 
14
- Sources of Intellectual Property Included in CKEditor
15
- -----------------------------------------------------
14
+ Sources of Intellectual Property Included in CKEditor 5
15
+ ------------------------------------------------------------
16
16
 
17
- Where not otherwise indicated, all CKEditor content is authored by CKSource engineers and consists of CKSource-owned intellectual property. In some specific instances, CKEditor will incorporate work done by developers outside of CKSource with their express permission.
17
+ Where not otherwise indicated, all CKEditor 5 content is authored by CKSource engineers and consists of CKSource-owned intellectual property. In some specific instances, CKEditor 5 will incorporate work done by developers outside of CKSource with their express permission.
18
18
 
19
19
  Trademarks
20
20
  ----------
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md.
4
- */(()=>{var e={237:e=>{"use strict";e.exports=CKEditor5.dll},331:(e,t,n)=>{e.exports=n(237)("./src/clipboard.js")},782:(e,t,n)=>{e.exports=n(237)("./src/core.js")},783:(e,t,n)=>{e.exports=n(237)("./src/engine.js")}},t={};function n(s){var i=t[s];if(void 0!==i)return i.exports;var r=t[s]={exports:{}};return e[s](r,r.exports,n),r.exports}n.d=(e,t)=>{for(var s in t)n.o(t,s)&&!n.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};(()=>{"use strict";n.r(s),n.d(s,{PasteFromOffice:()=>G,PasteFromOfficeGoogleDocsNormalizer:()=>j,PasteFromOfficeGoogleSheetsNormalizer:()=>N,PasteFromOfficeMSWordNormalizer:()=>L,_convertHexToBase64:()=>x,_convertPasteOfficeCssLengthToPx:()=>o,_isPasteOfficePxValue:()=>l,_normalizePasteOfficeSpaceRunSpans:()=>U,_normalizePasteOfficeSpacing:()=>z,_removePasteGoogleOfficeSheetsTag:()=>D,_removePasteMSOfficeAttributes:()=>w,_removePasteOfficeBoldWrapper:()=>_,_removePasteOfficeInvalidTableWidths:()=>C,_removePasteOfficeStyleBlock:()=>V,_removePasteOfficeXmlnsAttributes:()=>k,_replacePasteOfficeImagesSourceWithBase64:()=>v,_toPasteOfficePxValue:()=>a,_transformPasteOfficeBlockBrsToParagraphs:()=>$,_transformPasteOfficeBookmarks:()=>i,_transformPasteOfficeListItemLikeElementsIntoLists:()=>c,_transformPasteOfficeTables:()=>S,_unwrapPasteOfficeParagraphInListItem:()=>f,parsePasteOfficeHtml:()=>H});var e=n(782),t=n(331);function i(e,t){const n=[];for(const s of t.createRangeIn(e)){const e=s.item;e.is("element","a")&&!e.hasAttribute("href")&&(e.hasAttribute("id")||e.hasAttribute("name"))&&n.push(e)}for(const e of n){const n=e.parent.getChildIndex(e)+1,s=e.getChildren();t.insertChild(n,s,e.parent)}}var r=n(783);function o(e){const t=parseFloat(e);return e.endsWith("pt")?a(96*t/72):e.endsWith("pc")?a(12*t*96/72):e.endsWith("in")?a(96*t):e.endsWith("cm")?a(96*t/2.54):e.endsWith("mm")?a(t/10*96/2.54):e}function l(e){return void 0!==e&&e.endsWith("px")}function a(e){return Math.round(e)+"px"}function c(e,t,n){if(!e.childCount)return;const s=new r.ViewUpcastWriter(e.document),i=function(e,t){const n=t.createRangeIn(e),s=[],i=new Set;for(const e of n.getItems()){if(!e.is("element")||!e.name.match(/^(p|h\d+|li|div)$/))continue;let t=b(e);if(void 0===t||0!=parseFloat(t)||Array.from(e.getClassNames()).find(e=>e.startsWith("MsoList"))||(t=void 0),e.hasStyle("mso-list")&&"none"!==e.getStyle("mso-list")||void 0!==t&&i.has(t)){const n=h(e);s.push({element:e,id:n.id,order:n.order,indent:n.indent,marginLeft:t}),void 0!==t&&i.add(t)}else i.clear()}return s}(e,s);if(!i.length)return;const o={},c=[];for(const e of i)if(void 0!==e.indent){m(e)||(c.length=0);const i=`${e.id}:${e.indent}`,r=Math.min(e.indent-1,c.length);if(r<c.length&&c[r].id!==e.id&&(c.length=r),r<c.length-1)c.length=r+1;else{const f=d(e,t);if(r>c.length-1||c[r].listElement.name!=f.type){0==r&&"ol"==f.type&&void 0!==e.id&&o[i]&&(f.startIndex=o[i]);const t=g(f,s,n);if(l(e.marginLeft)&&(0==r||l(c[r-1].marginLeft))){let n=e.marginLeft;r>0&&(n=a(parseFloat(n)-parseFloat(c[r-1].marginLeft))),s.setStyle("padding-left",n,t)}if(0==c.length){const n=e.element.parent,i=n.getChildIndex(e.element)+1;s.insertChild(i,t,n)}else{const e=c[r-1].listItemElements;s.appendChild(t,e[e.length-1])}c[r]={...e,listElement:t,listItemElements:[]},0==r&&void 0!==e.id&&(o[i]=f.startIndex||1)}}const f="li"==e.element.name?e.element:s.createElement("li");s.appendChild(f,c[r].listElement),c[r].listItemElements.push(f),0==r&&void 0!==e.id&&o[i]++,e.element!=f&&s.appendChild(e.element,f),y(e.element,s),s.removeStyle("text-indent",e.element),s.removeStyle("margin-left",e.element)}else{const t=c.find(t=>t.marginLeft==e.marginLeft);if(t){const n=t.listItemElements;s.appendChild(e.element,n[n.length-1]),s.removeStyle("margin-left",e.element)}else c.length=0}}function f(e,t){for(const n of t.createRangeIn(e)){const e=n.item;if(e.is("element","li")){const n=e.getChild(0);n&&n.is("element","p")&&t.unwrapElement(n)}}}function m(e){const t=e.element.previousSibling;if(!t){const t=e.element.parent;return u(t)&&(!t.previousSibling||u(t.previousSibling))}return u(t)}function u(e){return e.is("element","ol")||e.is("element","ul")}function d(e,t){const n=new RegExp(`@list l${e.id}:level${e.indent}\\s*({[^}]*)`,"gi"),s=/mso-level-number-format:([^;]{0,100});/gi,i=/mso-level-start-at:\s{0,100}([0-9]{0,10})\s{0,100};/gi,r=new RegExp(`@list\\s+l${e.id}:level\\d\\s*{[^{]*mso-level-text:"%\\d\\\\.`,"gi"),o=new RegExp(`@list l${e.id}:level\\d\\s*{[^{]*mso-level-number-format:`,"gi"),l=r.exec(t),a=o.exec(t),c=l&&!a,f=n.exec(t);let m="decimal",u="ol",d=null;if(f&&f[1]){const t=s.exec(f[1]);if(t&&t[1]&&(m=t[1].trim(),u="bullet"!==m&&"image"!==m?"ol":"ul"),"bullet"===m){const t=function(e){if("li"==e.name&&"ul"==e.parent.name&&e.parent.hasAttribute("type"))return e.parent.getAttribute("type");const t=function(e){if(e.getChild(0).is("$text"))return null;for(const t of e.getChildren()){if(!t.is("element","span"))continue;const e=t.getChild(0);if(e)return e.is("$text")?e:e.getChild(0)}return null}(e);if(!t)return null;const n=t._data;if("o"===n)return"circle";if("·"===n)return"disc";if("§"===n)return"square";return null}(e.element);t&&(m=t)}else{const e=i.exec(f[1]);e&&e[1]&&(d=parseInt(e[1]))}c&&(u="ol")}return{type:u,startIndex:d,style:p(m),isLegalStyleList:c}}function p(e){if(e.startsWith("arabic-leading-zero"))return"decimal-leading-zero";switch(e){case"alpha-upper":return"upper-alpha";case"alpha-lower":return"lower-alpha";case"roman-upper":return"upper-roman";case"roman-lower":return"lower-roman";case"circle":case"disc":case"square":return e;default:return null}}function g(e,t,n){const s=t.createElement(e.type);return e.style&&t.setStyle("list-style-type",e.style,s),e.startIndex&&e.startIndex>1&&t.setAttribute("start",e.startIndex,s),e.isLegalStyleList&&n&&t.addClass("legal-list",s),s}function h(e){const t=e.getStyle("mso-list");if(void 0===t)return{};const n=t.match(/(^|\s{1,100})l(\d+)/i),s=t.match(/\s{0,100}lfo(\d+)/i),i=t.match(/\s{0,100}level(\d+)/i);return n&&s&&i?{id:n[2],order:s[1],indent:parseInt(i[1])}:{indent:1}}function y(e,t){const n=new r.Matcher({name:"span",styles:{"mso-list":"Ignore"}}),s=t.createRangeIn(e);for(const e of s)"elementStart"===e.type&&n.match(e.item)&&t.remove(e.item)}function b(e){const t=e.getStyle("margin-left");return void 0===t||t.endsWith("px")?t:o(t)}function v(e,t){if(!e.childCount)return;const n=new r.ViewUpcastWriter(e.document),s=function(e,t){const n=t.createRangeIn(e),s=new r.Matcher({name:/v:(.+)/}),i=[];for(const e of n){if("elementStart"!=e.type)continue;const t=e.item,n=t.previousSibling,r=n&&n.is("element")?n.name:null,o=["Chart"],l=s.match(t),a=t.getAttribute("o:gfxdata"),c="v:shapetype"===r,f=a&&o.some(e=>t.getAttribute("id").includes(e));l&&a&&!c&&!f&&i.push(e.item.getAttribute("id"))}return i}(e,n);!function(e,t,n){const s=n.createRangeIn(t),i=new r.Matcher({name:"img"}),o=[];for(const t of s)if(t.item.is("element")&&i.match(t.item)){const n=t.item,s=n.getAttribute("v:shapes")?n.getAttribute("v:shapes").split(" "):[];s.length&&s.every(t=>e.indexOf(t)>-1)?o.push(n):n.getAttribute("src")||o.push(n)}for(const e of o)n.remove(e)}(s,e,n),function(e,t,n){const s=n.createRangeIn(t),i=[];for(const t of s)if("elementStart"==t.type&&t.item.is("element","v:shape")){const n=t.item.getAttribute("id");if(e.includes(n))continue;r(t.item.parent.getChildren(),n)||i.push(t.item)}for(const e of i){const t={src:o(e)};e.hasAttribute("alt")&&(t.alt=e.getAttribute("alt"));const s=n.createElement("img",t);n.insertChild(e.index+1,s,e.parent)}function r(e,t){for(const n of e)if(n.is("element")){if("img"==n.name&&n.getAttribute("v:shapes")==t)return!0;if(r(n.getChildren(),t))return!0}return!1}function o(e){for(const t of e.getChildren())if(t.is("element")&&t.getAttribute("src"))return t.getAttribute("src")}}(s,e,n),function(e,t){const n=t.createRangeIn(e),s=new r.Matcher({name:/v:(.+)/}),i=[];for(const e of n)"elementStart"==e.type&&s.match(e.item)&&i.push(e.item);for(const e of i)t.remove(e)}(e,n);const i=function(e,t){const n=t.createRangeIn(e),s=new r.Matcher({name:"img"}),i=[];let o=0;for(const e of n)e.item.is("element")&&s.match(e.item)&&(e.item.getAttribute("src").startsWith("file://")&&i.push({element:e.item,imageIndex:o}),o++);return i}(e,n);i.length&&function(e,t,n){for(let s=0;s<e.length;s++){const{element:i,imageIndex:r}=e[s],o=t[r];if(o){const e=`data:${o.type};base64,${x(o.hex)}`;n.setAttribute("src",e,i)}}}(i,function(e){if(!e)return[];const t=/{\\pict[\s\S]+?\\bliptag-?\d+(\\blipupi-?\d+)?({\\\*\\blipuid\s?[\da-fA-F]+)?[\s}]*?/,n=new RegExp("(?:("+t.source+"))([\\da-fA-F\\s]+)\\}","g"),s=e.match(n),i=[];if(s)for(const e of s){let n=!1;e.includes("\\pngblip")?n="image/png":e.includes("\\jpegblip")&&(n="image/jpeg"),n&&i.push({hex:e.replace(t,"").replace(/[^\da-fA-F]/g,""),type:n})}return i}(t),n)}function x(e){return btoa(e.match(/\w{2}/g).map(e=>String.fromCharCode(parseInt(e,16))).join(""))}function w(e){const t=[],n=new r.ViewUpcastWriter(e.document);for(const{item:s}of n.createRangeIn(e))if(s.is("element")){for(const e of s.getClassNames())/\bmso/gi.exec(e)&&n.removeClass(e,s);for(const e of s.getStyleNames())/\bmso/gi.exec(e)&&n.removeStyle(e,s);(s.is("element","w:sdt")||s.is("element","w:sdtpr")&&s.isEmpty||s.is("element","o:p")&&s.isEmpty)&&t.push(s)}for(const e of t){const t=e.parent,s=t.getChildIndex(e);n.insertChild(s,e.getChildren(),t),n.remove(e)}}function S(e,t){for(const n of t.createRangeIn(e).getItems()){if(!n.is("element","table")&&!n.is("element","td")&&!n.is("element","th"))continue;const e=["left","top","right","bottom"];if(e.every(e=>!n.hasStyle(`border-${e}-style`)))t.setStyle("border-style","none",n);else for(const s of e)n.hasStyle(`border-${s}-style`)||t.setStyle(`border-${s}-style`,"none",n);const s=["width","height",...e.map(e=>`border-${e}-width`),...e.map(e=>`padding-${e}`)];for(const e of s)n.hasStyle(e)&&t.setStyle(e,o(n.getStyle(e)),n)}}function C(e,t){for(const n of t.createRangeIn(e).getItems())n.is("element","table")&&("0px"===n.getStyle("width")&&t.removeStyle("width",n),"0"===n.getAttribute("width")&&t.removeAttribute("width",n))}function I(e,t){const n=[],s=[];for(const{item:i}of e.createRangeIn(t))if(i.is("element")&&i.getStyle("mso-footnote-id")){n.unshift(i);const{nextSibling:e}=i;e?.is("$text")&&e.data.startsWith(" ")&&s.unshift(e)}for(const t of n)e.remove(t);for(const t of s){const n=t.data.substring(1);if(n.length>0){const s=t.parent,i=s.getChildIndex(t),r=e.createText(n);e.remove(t),e.insertChild(i,r,s)}else e.remove(t)}return t}function P(e,t){const n=e.createElement("sup",{class:"footnote"}),s=e.createElement("a",{id:`ref-${t}`,href:`#${t}`});return e.appendChild(s,n),n}function A(e,t){const n=e.createElement("li",{id:t,class:"footnote-definition"}),s=e.createElement("a",{href:`#ref-${t}`,class:"footnote-backlink"}),i=e.createElement("div",{class:"footnote-content"});return e.appendChild(e.createText("^"),s),e.appendChild(s,n),e.appendChild(i,n),{listItem:n,content:i}}const O=/<meta\s*name="?generator"?\s*content="?microsoft\s*word\s*\d+"?\/?>/i,E=/xmlns:o="urn:schemas-microsoft-com/i;class L{document;hasMultiLevelListPlugin;constructor(e,t=!1){this.document=e,this.hasMultiLevelListPlugin=t}isActive(e){return O.test(e)||E.test(e)}execute(e){const t=new r.ViewUpcastWriter(this.document),{body:n,stylesString:s}=e._parsedData;i(n,t),c(n,s,this.hasMultiLevelListPlugin),v(n,e.dataTransfer.getData("text/rtf")),S(n,t),C(n,t),function(e,t){const n=new Map,s=new Map;let i=null;for(const{item:r}of t.createRangeIn(e))if(r.is("element"))if("footnote-list"!==r.getStyle("mso-element")){if(r.hasStyle("mso-footnote-id")){const e=r.findAncestor("element",e=>"footnote"===e.getStyle("mso-element"));if(e){const t=e.getAttribute("id");s.set(t,e)}else{const e=r.getStyle("mso-footnote-id");n.set(e,r)}continue}}else i=r;if(!n.size||!i)return;const r=function(e){return e.createElement("ol",{class:"footnotes"})}(t);t.replace(i,r);for(const[e,i]of n){const n=s.get(e);if(!n)continue;t.replace(i,P(t,e));const o=A(t,e);I(t,n);for(const e of n.getChildren()){let n=e;e.is("element")&&(n=t.clone(e,!0)),t.appendChild(n,o.content)}t.appendChild(o.listItem,r)}}(n,t),w(n),e.content=n}}function _(e,t){for(const n of e.getChildren())if(n.is("element","b")&&"normal"===n.getStyle("font-weight")){const s=e.getChildIndex(n);t.remove(n),t.insertChild(s,n.getChildren(),e)}}function $(e,t){const n=new r.ViewDocument(t.document.stylesProcessor),s=new r.ViewDomConverter(n,{renderingMode:"data"}),i=s.blockElements,o=s.inlineObjectElements,l=[];for(const n of t.createRangeIn(e)){const e=n.item;if(e.is("element","br")){const n=M(e,"forward",t,{blockElements:i,inlineObjectElements:o}),s=M(e,"backward",t,{blockElements:i,inlineObjectElements:o}),r=T(n,i);(T(s,i)||r)&&l.push(e)}}for(const e of l)e.hasClass("Apple-interchange-newline")?t.remove(e):t.replace(e,t.createElement("p"))}function M(e,t,n,{blockElements:s,inlineObjectElements:i}){let r=n.createPositionAt(e,"forward"==t?"after":"before");return r=r.getLastMatchingPosition(({item:e})=>e.is("element")&&!s.includes(e.name)&&!i.includes(e.name),{direction:t}),"forward"==t?r.nodeAfter:r.nodeBefore}function T(e,t){return!!e&&e.is("element")&&t.includes(e.name)}function R(e){let t=e;for(;t;){if(t.is("element")){const e=t.getStyle?.("white-space");if("pre-wrap"===e)return!0}t=t.parent}return!1}function W(e,t,n){const{parent:s,data:i}=e,r=i.replaceAll("\t"," ".repeat(n)),o=s.getChildIndex(e);t.remove(e),t.insertChild(o,t.createText(r),s)}const F=/id=("|')docs-internal-guid-[-0-9a-f]+("|')/i;class j{document;constructor(e){this.document=e}isActive(e){return F.test(e)}execute(e){const t=new r.ViewUpcastWriter(this.document),{body:n}=e._parsedData;_(n,t),f(n,t),$(n,t),function(e,t,n){const s=new Set;for(const n of t.createRangeIn(e).getItems())n.is("view:$textProxy")&&n.data.includes("\t")&&R(n.parent)&&s.add(n.textNode);for(const e of s)W(e,t,n)}(n,t,8),e.content=n}}function k(e,t){for(const n of e.getChildren())n.is("element","table")&&n.hasAttribute("xmlns")&&t.removeAttribute("xmlns",n)}function D(e,t){for(const n of e.getChildren())if(n.is("element","google-sheets-html-origin")){const s=e.getChildIndex(n);t.remove(n),t.insertChild(s,n.getChildren(),e)}}function V(e,t){for(const n of Array.from(e.getChildren()))n.is("element","style")&&t.remove(n)}const B=/<google-sheets-html-origin/i;class N{document;constructor(e){this.document=e}isActive(e){return B.test(e)}execute(e){const t=new r.ViewUpcastWriter(this.document),{body:n}=e._parsedData;D(n,t),k(n,t),C(n,t),V(n,t),e.content=n}}function z(e){return q(q(e)).replace(/(<span\s+style=['"]mso-spacerun:yes['"]>[^\S\r\n]*?)[\r\n]+([^\S\r\n]*<\/span>)/g,"$1$2").replace(/<span\s+style=['"]mso-spacerun:yes['"]><\/span>/g,"").replace(/(<span\s+style=['"]letter-spacing:[^'"]+?['"]>)[\r\n]+(<\/span>)/g,"$1 $2").replace(/ <\//g," </").replace(/ <o:p><\/o:p>/g," <o:p></o:p>").replace(/<o:p>(&nbsp;|\u00A0)<\/o:p>/g,"").replace(/>([^\S\r\n]*[\r\n]\s*)</g,"><")}function U(e){e.querySelectorAll("span[style*=spacerun]").forEach(e=>{const t=e,n=t.innerText.length||0;t.innerText=Array(n+1).join("  ").substr(0,n)})}function q(e){return e.replace(/<span(?: class="Apple-converted-space"|)>(\s+)<\/span>/g,(e,t)=>1===t.length?" ":Array(t.length+1).join("  ").substr(0,t.length))}function H(e,t){const n=new DOMParser,s=z(function(e){const t="</body>",n="</html>",s=e.indexOf(t);if(s<0)return e;const i=e.indexOf(n,s+t.length);return e.substring(0,s+t.length)+(i>=0?e.substring(i):"")}(e=(e=e.replace(/<!--\[if gte vml 1]>/g,"")).replace(/<o:SmartTagType(?:\s+[^\s>=]+(?:="[^"]*")?)*\s*\/?>/gi,""))),i=n.parseFromString(s,"text/html");U(i);const o=i.body.innerHTML,l=function(e,t){const n=new r.ViewDocument(t),s=new r.ViewDomConverter(n,{renderingMode:"data"}),i=e.createDocumentFragment(),o=e.body.childNodes;for(;o.length>0;)i.appendChild(o[0]);return s.domToView(i,{skipComments:!0})}(i,t),a=function(e){const t=[],n=[],s=Array.from(e.getElementsByTagName("style"));for(const e of s)e.sheet&&e.sheet.cssRules&&e.sheet.cssRules.length&&(t.push(e.sheet),n.push(e.innerHTML));return{styles:t,stylesString:n.join(" ")}}(i);return{body:l,bodyString:o,styles:a.styles,stylesString:a.stylesString}}class G extends e.Plugin{static get pluginName(){return"PasteFromOffice"}static get licenseFeatureCode(){return"PFO"}static get isOfficialPlugin(){return!0}static get isPremiumPlugin(){return!0}static get requires(){return[t.ClipboardPipeline]}init(){const e=this.editor,t=e.plugins.get("ClipboardPipeline"),n=e.editing.view.document,s=[],i=this.editor.plugins.has("MultiLevelList");s.push(new L(n,i)),s.push(new j(n)),s.push(new N(n)),t.on("inputTransformation",(t,i)=>{if(i._isTransformedWithPasteFromOffice)return;if(e.model.document.selection.getFirstPosition().parent.is("element","codeBlock"))return;const r=i.dataTransfer.getData("text/html"),o=s.find(e=>e.isActive(r));o&&(i._parsedData||(i._parsedData=H(r,n.stylesProcessor)),o.execute(i),i._isTransformedWithPasteFromOffice=!0)},{priority:"high"})}}})(),(window.CKEditor5=window.CKEditor5||{}).pasteFromOffice=s})();
4
+ */(()=>{var e={237:e=>{"use strict";e.exports=CKEditor5.dll},331:(e,t,n)=>{e.exports=n(237)("./src/clipboard.js")},782:(e,t,n)=>{e.exports=n(237)("./src/core.js")},783:(e,t,n)=>{e.exports=n(237)("./src/engine.js")}},t={};function n(i){var s=t[i];if(void 0!==s)return s.exports;var r=t[i]={exports:{}};return e[i](r,r.exports,n),r.exports}n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};(()=>{"use strict";n.r(i),n.d(i,{PasteFromOffice:()=>G,PasteFromOfficeGoogleDocsNormalizer:()=>k,PasteFromOfficeGoogleSheetsNormalizer:()=>N,PasteFromOfficeMSWordNormalizer:()=>T,_convertHexToBase64:()=>x,_convertPasteOfficeCssLengthToPx:()=>o,_isPasteOfficePxValue:()=>l,_normalizePasteOfficeSpaceRunSpans:()=>U,_normalizePasteOfficeSpacing:()=>z,_removePasteGoogleOfficeSheetsTag:()=>B,_removePasteMSOfficeAttributes:()=>S,_removePasteOfficeBoldWrapper:()=>L,_removePasteOfficeInvalidTableWidths:()=>C,_removePasteOfficeStyleBlock:()=>D,_removePasteOfficeXmlnsAttributes:()=>j,_replacePasteOfficeImagesSourceWithBase64:()=>v,_toPasteOfficePxValue:()=>a,_transformPasteOfficeBlockBrsToParagraphs:()=>_,_transformPasteOfficeBookmarks:()=>s,_transformPasteOfficeListItemLikeElementsIntoLists:()=>c,_transformPasteOfficeTables:()=>w,_unwrapPasteOfficeParagraphInListItem:()=>f,parsePasteOfficeHtml:()=>H});var e=n(782),t=n(331);function s(e,t){const n=[];for(const i of t.createRangeIn(e)){const e=i.item;e.is("element","a")&&!e.hasAttribute("href")&&(e.hasAttribute("id")||e.hasAttribute("name"))&&n.push(e)}for(const e of n){const n=e.parent.getChildIndex(e)+1,i=e.getChildren();t.insertChild(n,i,e.parent)}}var r=n(783);function o(e){const t=parseFloat(e);return e.endsWith("pt")?a(96*t/72):e.endsWith("pc")?a(12*t*96/72):e.endsWith("in")?a(96*t):e.endsWith("cm")?a(96*t/2.54):e.endsWith("mm")?a(t/10*96/2.54):e}function l(e){return void 0!==e&&e.endsWith("px")}function a(e){return Math.round(e)+"px"}function c(e,t,n){if(!e.childCount)return;const i=new r.ViewUpcastWriter(e.document),s=function(e,t){const n=t.createRangeIn(e),i=[],s=new Set;for(const e of n.getItems()){if(!e.is("element")||!e.name.match(/^(p|h\d+|li|div)$/))continue;let t=y(e);if(void 0===t||0!=parseFloat(t)||Array.from(e.getClassNames()).find(e=>e.startsWith("MsoList"))||(t=void 0),e.hasStyle("mso-list")&&"none"!==e.getStyle("mso-list")||void 0!==t&&s.has(t)){const n=h(e);i.push({element:e,id:n.id,order:n.order,indent:n.indent,marginLeft:t}),void 0!==t&&s.add(t)}else s.clear()}return i}(e,i);if(!s.length)return;const o={},c=[];for(const e of s)if(void 0!==e.indent){m(e)||(c.length=0);const s=`${e.id}:${e.indent}`,r=Math.min(e.indent-1,c.length);if(r<c.length&&c[r].id!==e.id&&(c.length=r),r<c.length-1)c.length=r+1;else{const f=d(e,t);if(r>c.length-1||c[r].listElement.name!=f.type){0==r&&"ol"==f.type&&void 0!==e.id&&o[s]&&(f.startIndex=o[s]);const t=p(f,i,n);if(l(e.marginLeft)&&(0==r||l(c[r-1].marginLeft))){let n=e.marginLeft;r>0&&(n=a(parseFloat(n)-parseFloat(c[r-1].marginLeft))),i.setStyle("padding-left",n,t)}if(0==c.length){const n=e.element.parent,s=n.getChildIndex(e.element)+1;i.insertChild(s,t,n)}else{const e=c[r-1].listItemElements;i.appendChild(t,e[e.length-1])}c[r]={...e,listElement:t,listItemElements:[]},0==r&&void 0!==e.id&&(o[s]=f.startIndex||1)}}const f="li"==e.element.name?e.element:i.createElement("li");i.appendChild(f,c[r].listElement),c[r].listItemElements.push(f),0==r&&void 0!==e.id&&o[s]++,e.element!=f&&i.appendChild(e.element,f),b(e.element,i),i.removeStyle("text-indent",e.element),i.removeStyle("margin-left",e.element)}else{const t=c.find(t=>t.marginLeft==e.marginLeft);if(t){const n=t.listItemElements;i.appendChild(e.element,n[n.length-1]),i.removeStyle("margin-left",e.element)}else c.length=0}}function f(e,t){for(const n of t.createRangeIn(e)){const e=n.item;if(e.is("element","li")){const n=e.getChild(0);n&&n.is("element","p")&&t.unwrapElement(n)}}}function m(e){const t=e.element.previousSibling;if(!t){const t=e.element.parent;return u(t)&&(!t.previousSibling||u(t.previousSibling))}return u(t)}function u(e){return e.is("element","ol")||e.is("element","ul")}function d(e,t){const n=new RegExp(`@list l${e.id}:level${e.indent}\\s*({[^}]*)`,"gi"),i=/mso-level-number-format:([^;]{0,100});/gi,s=/mso-level-start-at:\s{0,100}([0-9]{0,10})\s{0,100};/gi,r=new RegExp(`@list\\s+l${e.id}:level\\d\\s*{[^{]*mso-level-text:"%\\d\\\\.`,"gi"),o=new RegExp(`@list l${e.id}:level\\d\\s*{[^{]*mso-level-number-format:`,"gi"),l=r.exec(t),a=o.exec(t),c=l&&!a,f=n.exec(t);let m="decimal",u="ol",d=null;if(f&&f[1]){const t=i.exec(f[1]);if(t&&t[1]&&(m=t[1].trim(),u="bullet"!==m&&"image"!==m?"ol":"ul"),"bullet"===m){const t=function(e){if("li"==e.name&&"ul"==e.parent.name&&e.parent.hasAttribute("type"))return e.parent.getAttribute("type");const t=function(e){if(e.getChild(0).is("$text"))return null;for(const t of e.getChildren()){if(!t.is("element","span"))continue;const e=t.getChild(0);if(e)return e.is("$text")?e:e.getChild(0)}return null}(e);if(!t)return null;const n=t._data;if("o"===n)return"circle";if("·"===n)return"disc";if("§"===n)return"square";return null}(e.element);t&&(m=t)}else{const e=s.exec(f[1]);e&&e[1]&&(d=parseInt(e[1]))}c&&(u="ol")}return{type:u,startIndex:d,style:g(m),isLegalStyleList:c}}function g(e){if(e.startsWith("arabic-leading-zero"))return"decimal-leading-zero";switch(e){case"alpha-upper":return"upper-alpha";case"alpha-lower":return"lower-alpha";case"roman-upper":return"upper-roman";case"roman-lower":return"lower-roman";case"circle":case"disc":case"square":return e;default:return null}}function p(e,t,n){const i=t.createElement(e.type);return e.style&&t.setStyle("list-style-type",e.style,i),e.startIndex&&e.startIndex>1&&t.setAttribute("start",e.startIndex,i),e.isLegalStyleList&&n&&t.addClass("legal-list",i),i}function h(e){const t=e.getStyle("mso-list");if(void 0===t)return{};const n=t.match(/(^|\s{1,100})l(\d+)/i),i=t.match(/\s{0,100}lfo(\d+)/i),s=t.match(/\s{0,100}level(\d+)/i);return n&&i&&s?{id:n[2],order:i[1],indent:parseInt(s[1])}:{indent:1}}function b(e,t){const n=new r.Matcher({name:"span",styles:{"mso-list":"Ignore"}}),i=t.createRangeIn(e);for(const e of i)"elementStart"===e.type&&n.match(e.item)&&t.remove(e.item)}function y(e){const t=e.getStyle("margin-left");return void 0===t||t.endsWith("px")?t:o(t)}function v(e,t){if(!e.childCount)return;const n=new r.ViewUpcastWriter(e.document),i=function(e,t){const n=t.createRangeIn(e),i=new r.Matcher({name:/v:(.+)/}),s=[];for(const e of n){if("elementStart"!=e.type)continue;const t=e.item,n=t.previousSibling,r=n&&n.is("element")?n.name:null,o=["Chart"],l=i.match(t),a=t.getAttribute("o:gfxdata"),c="v:shapetype"===r,f=a&&o.some(e=>t.getAttribute("id").includes(e));l&&a&&!c&&!f&&s.push(e.item.getAttribute("id"))}return s}(e,n);!function(e,t,n){const i=n.createRangeIn(t),s=new r.Matcher({name:"img"}),o=[];for(const t of i)if(t.item.is("element")&&s.match(t.item)){const n=t.item,i=n.getAttribute("v:shapes")?n.getAttribute("v:shapes").split(" "):[];i.length&&i.every(t=>e.indexOf(t)>-1)?o.push(n):n.getAttribute("src")||o.push(n)}for(const e of o)n.remove(e)}(i,e,n),function(e,t,n){const i=n.createRangeIn(t),s=[];for(const t of i)if("elementStart"==t.type&&t.item.is("element","v:shape")){const n=t.item.getAttribute("id");if(e.includes(n))continue;r(t.item.parent.getChildren(),n)||s.push(t.item)}for(const e of s){const t={src:o(e)};e.hasAttribute("alt")&&(t.alt=e.getAttribute("alt"));const i=n.createElement("img",t);n.insertChild(e.index+1,i,e.parent)}function r(e,t){for(const n of e)if(n.is("element")){if("img"==n.name&&n.getAttribute("v:shapes")==t)return!0;if(r(n.getChildren(),t))return!0}return!1}function o(e){for(const t of e.getChildren())if(t.is("element")&&t.getAttribute("src"))return t.getAttribute("src")}}(i,e,n),function(e,t){const n=t.createRangeIn(e),i=new r.Matcher({name:/v:(.+)/}),s=[];for(const e of n)"elementStart"==e.type&&i.match(e.item)&&s.push(e.item);for(const e of s)t.remove(e)}(e,n);const s=function(e,t){const n=t.createRangeIn(e),i=new r.Matcher({name:"img"}),s=[];let o=0;for(const e of n)e.item.is("element")&&i.match(e.item)&&(e.item.getAttribute("src").startsWith("file://")&&s.push({element:e.item,imageIndex:o}),o++);return s}(e,n);s.length&&function(e,t,n){for(let i=0;i<e.length;i++){const{element:s,imageIndex:r}=e[i],o=t[r];if(o){const e=`data:${o.type};base64,${x(o.hex)}`;n.setAttribute("src",e,s)}}}(s,function(e){if(!e)return[];const t=/{\\pict[\s\S]+?\\bliptag-?\d+(\\blipupi-?\d+)?({\\\*\\blipuid\s?[\da-fA-F]+)?[\s}]*?/,n=new RegExp("(?:("+t.source+"))([\\da-fA-F\\s]+)\\}","g"),i=e.match(n),s=[];if(i)for(const e of i){let n=!1;e.includes("\\pngblip")?n="image/png":e.includes("\\jpegblip")&&(n="image/jpeg"),n&&s.push({hex:e.replace(t,"").replace(/[^\da-fA-F]/g,""),type:n})}return s}(t),n)}function x(e){return btoa(e.match(/\w{2}/g).map(e=>String.fromCharCode(parseInt(e,16))).join(""))}function S(e){const t=[],n=new r.ViewUpcastWriter(e.document);for(const{item:i}of n.createRangeIn(e))if(i.is("element")){for(const e of i.getClassNames())/\bmso/gi.exec(e)&&n.removeClass(e,i);for(const e of i.getStyleNames())/\bmso/gi.exec(e)&&n.removeStyle(e,i);(i.is("element","w:sdt")||i.is("element","w:sdtpr")&&i.isEmpty||i.is("element","o:p")&&i.isEmpty)&&t.push(i)}for(const e of t){const t=e.parent,i=t.getChildIndex(e);n.insertChild(i,e.getChildren(),t),n.remove(e)}}function w(e,t,n=!1,i=!1){for(const s of t.createRangeIn(e).getItems()){if(!s.is("element","table")&&!s.is("element","td")&&!s.is("element","th"))continue;if(n&&i&&s.is("element","table")){const e=s.parent?.is("element","div")?s.parent:null,n=s.parent?.parent?.is("element","div")?s.parent.parent:null,i=e??n;i&&"center"===i.getAttribute("align")&&!s.getAttribute("align")?(t.setStyle("margin-left","auto",s),t.setStyle("margin-right","auto",s)):i&&"right"===i.getAttribute("align")&&!s.getAttribute("align")?(t.setStyle("margin-left","auto",s),t.setStyle("margin-right","0",s)):i||s.getAttribute("align")||(t.setStyle("margin-left","0",s),t.setStyle("margin-right","auto",s))}const e=["left","top","right","bottom"];if(e.every(e=>!s.hasStyle(`border-${e}-style`)))t.setStyle("border-style","none",s);else for(const n of e)s.hasStyle(`border-${n}-style`)||t.setStyle(`border-${n}-style`,"none",s);const r=["width","height",...e.map(e=>`border-${e}-width`),...e.map(e=>`padding-${e}`)];for(const e of r)s.hasStyle(e)&&t.setStyle(e,o(s.getStyle(e)),s)}}function C(e,t){for(const n of t.createRangeIn(e).getItems())n.is("element","table")&&("0px"===n.getStyle("width")&&t.removeStyle("width",n),"0"===n.getAttribute("width")&&t.removeAttribute("width",n))}function P(e,t){const n=[],i=[];for(const{item:s}of e.createRangeIn(t))if(s.is("element")&&s.getStyle("mso-footnote-id")){n.unshift(s);const{nextSibling:e}=s;e?.is("$text")&&e.data.startsWith(" ")&&i.unshift(e)}for(const t of n)e.remove(t);for(const t of i){const n=t.data.substring(1);if(n.length>0){const i=t.parent,s=i.getChildIndex(t),r=e.createText(n);e.remove(t),e.insertChild(s,r,i)}else e.remove(t)}return t}function A(e,t){const n=e.createElement("sup",{class:"footnote"}),i=e.createElement("a",{id:`ref-${t}`,href:`#${t}`});return e.appendChild(i,n),n}function I(e,t){const n=e.createElement("li",{id:t,class:"footnote-definition"}),i=e.createElement("a",{href:`#ref-${t}`,class:"footnote-backlink"}),s=e.createElement("div",{class:"footnote-content"});return e.appendChild(e.createText("^"),i),e.appendChild(i,n),e.appendChild(s,n),{listItem:n,content:s}}const E=/<meta\s*name="?generator"?\s*content="?microsoft\s*word\s*\d+"?\/?>/i,O=/xmlns:o="urn:schemas-microsoft-com/i;class T{document;hasMultiLevelListPlugin;hasTablePropertiesPlugin;hasExtendedTableBlockAlignment;constructor(e,t=!1,n=!1,i=!1){this.document=e,this.hasMultiLevelListPlugin=t,this.hasTablePropertiesPlugin=n,this.hasExtendedTableBlockAlignment=i}isActive(e){return E.test(e)||O.test(e)}execute(e){const t=new r.ViewUpcastWriter(this.document),{body:n,stylesString:i}=e._parsedData;s(n,t),c(n,i,this.hasMultiLevelListPlugin),v(n,e.dataTransfer.getData("text/rtf")),w(n,t,this.hasTablePropertiesPlugin,this.hasExtendedTableBlockAlignment),C(n,t),function(e,t){const n=new Map,i=new Map;let s=null;for(const{item:r}of t.createRangeIn(e))if(r.is("element"))if("footnote-list"!==r.getStyle("mso-element")){if(r.hasStyle("mso-footnote-id")){const e=r.findAncestor("element",e=>"footnote"===e.getStyle("mso-element"));if(e){const t=e.getAttribute("id");i.set(t,e)}else{const e=r.getStyle("mso-footnote-id");n.set(e,r)}continue}}else s=r;if(!n.size||!s)return;const r=function(e){return e.createElement("ol",{class:"footnotes"})}(t);t.replace(s,r);for(const[e,s]of n){const n=i.get(e);if(!n)continue;t.replace(s,A(t,e));const o=I(t,e);P(t,n);for(const e of n.getChildren()){let n=e;e.is("element")&&(n=t.clone(e,!0)),t.appendChild(n,o.content)}t.appendChild(o.listItem,r)}}(n,t),S(n),e.content=n}}function L(e,t){for(const n of e.getChildren())if(n.is("element","b")&&"normal"===n.getStyle("font-weight")){const i=e.getChildIndex(n);t.remove(n),t.insertChild(i,n.getChildren(),e)}}function _(e,t){const n=new r.ViewDocument(t.document.stylesProcessor),i=new r.ViewDomConverter(n,{renderingMode:"data"}),s=i.blockElements,o=i.inlineObjectElements,l=[];for(const n of t.createRangeIn(e)){const e=n.item;if(e.is("element","br")){const n=$(e,"forward",t,{blockElements:s,inlineObjectElements:o}),i=$(e,"backward",t,{blockElements:s,inlineObjectElements:o}),r=M(n,s);(M(i,s)||r)&&l.push(e)}}for(const e of l)e.hasClass("Apple-interchange-newline")?t.remove(e):t.replace(e,t.createElement("p"))}function $(e,t,n,{blockElements:i,inlineObjectElements:s}){let r=n.createPositionAt(e,"forward"==t?"after":"before");return r=r.getLastMatchingPosition(({item:e})=>e.is("element")&&!i.includes(e.name)&&!s.includes(e.name),{direction:t}),"forward"==t?r.nodeAfter:r.nodeBefore}function M(e,t){return!!e&&e.is("element")&&t.includes(e.name)}function R(e){let t=e;for(;t;){if(t.is("element")){const e=t.getStyle?.("white-space");if("pre-wrap"===e)return!0}t=t.parent}return!1}function W(e,t,n){const{parent:i,data:s}=e,r=s.replaceAll("\t"," ".repeat(n)),o=i.getChildIndex(e);t.remove(e),t.insertChild(o,t.createText(r),i)}const F=/id=("|')docs-internal-guid-[-0-9a-f]+("|')/i;class k{document;constructor(e){this.document=e}isActive(e){return F.test(e)}execute(e){const t=new r.ViewUpcastWriter(this.document),{body:n}=e._parsedData;L(n,t),f(n,t),_(n,t),function(e,t,n){const i=new Set;for(const n of t.createRangeIn(e).getItems())n.is("view:$textProxy")&&n.data.includes("\t")&&R(n.parent)&&i.add(n.textNode);for(const e of i)W(e,t,n)}(n,t,8),e.content=n}}function j(e,t){for(const n of e.getChildren())n.is("element","table")&&n.hasAttribute("xmlns")&&t.removeAttribute("xmlns",n)}function B(e,t){for(const n of e.getChildren())if(n.is("element","google-sheets-html-origin")){const i=e.getChildIndex(n);t.remove(n),t.insertChild(i,n.getChildren(),e)}}function D(e,t){for(const n of Array.from(e.getChildren()))n.is("element","style")&&t.remove(n)}const V=/<google-sheets-html-origin/i;class N{document;constructor(e){this.document=e}isActive(e){return V.test(e)}execute(e){const t=new r.ViewUpcastWriter(this.document),{body:n}=e._parsedData;B(n,t),j(n,t),C(n,t),D(n,t),e.content=n}}function z(e){return q(q(e)).replace(/(<span\s+style=['"]mso-spacerun:yes['"]>[^\S\r\n]*?)[\r\n]+([^\S\r\n]*<\/span>)/g,"$1$2").replace(/<span\s+style=['"]mso-spacerun:yes['"]><\/span>/g,"").replace(/(<span\s+style=['"]letter-spacing:[^'"]+?['"]>)[\r\n]+(<\/span>)/g,"$1 $2").replace(/ <\//g," </").replace(/ <o:p><\/o:p>/g," <o:p></o:p>").replace(/<o:p>(&nbsp;|\u00A0)<\/o:p>/g,"").replace(/>([^\S\r\n]*[\r\n]\s*)</g,"><")}function U(e){e.querySelectorAll("span[style*=spacerun]").forEach(e=>{const t=e,n=t.innerText.length||0;t.innerText=Array(n+1).join("  ").substr(0,n)})}function q(e){return e.replace(/<span(?: class="Apple-converted-space"|)>(\s+)<\/span>/g,(e,t)=>1===t.length?" ":Array(t.length+1).join("  ").substr(0,t.length))}function H(e,t){const n=new DOMParser,i=z(function(e){const t="</body>",n="</html>",i=e.indexOf(t);if(i<0)return e;const s=e.indexOf(n,i+t.length);return e.substring(0,i+t.length)+(s>=0?e.substring(s):"")}(e=(e=e.replace(/<!--\[if gte vml 1]>/g,"")).replace(/<o:SmartTagType(?:\s+[^\s>=]+(?:="[^"]*")?)*\s*\/?>/gi,""))),s=n.parseFromString(i,"text/html");U(s);const o=s.body.innerHTML,l=function(e,t){const n=new r.ViewDocument(t),i=new r.ViewDomConverter(n,{renderingMode:"data"}),s=e.createDocumentFragment(),o=e.body.childNodes;for(;o.length>0;)s.appendChild(o[0]);return i.domToView(s,{skipComments:!0})}(s,t),a=function(e){const t=[],n=[],i=Array.from(e.getElementsByTagName("style"));for(const e of i)e.sheet&&e.sheet.cssRules&&e.sheet.cssRules.length&&(t.push(e.sheet),n.push(e.innerHTML));return{styles:t,stylesString:n.join(" ")}}(s);return{body:l,bodyString:o,styles:a.styles,stylesString:a.stylesString}}class G extends e.Plugin{static get pluginName(){return"PasteFromOffice"}static get licenseFeatureCode(){return"PFO"}static get isOfficialPlugin(){return!0}static get isPremiumPlugin(){return!0}static get requires(){return[t.ClipboardPipeline]}init(){const e=this.editor,t=e.plugins.get("ClipboardPipeline"),n=e.editing.view.document,i=[],s=this.editor.plugins.has("MultiLevelList"),r=this.editor.plugins.has("TableProperties"),o=!!this.editor.config.get("experimentalFlags.useExtendedTableBlockAlignment");i.push(new T(n,s,r,o)),i.push(new k(n)),i.push(new N(n)),t.on("inputTransformation",(t,s)=>{if(s._isTransformedWithPasteFromOffice)return;if(e.model.document.selection.getFirstPosition().parent.is("element","codeBlock"))return;const r=s.dataTransfer.getData("text/html"),o=i.find(e=>e.isActive(r));o&&(s._parsedData||(s._parsedData=H(r,n.stylesProcessor)),o.execute(s),s._isTransformedWithPasteFromOffice=!0)},{priority:"high"})}}})(),(window.CKEditor5=window.CKEditor5||{}).pasteFromOffice=i})();
package/dist/index.js CHANGED
@@ -760,13 +760,40 @@ function isList(element) {
760
760
  /**
761
761
  * Applies border none for table and cells without a border specified.
762
762
  * Normalizes style length units to px.
763
+ * Handles left block table alignment.
763
764
  *
764
765
  * @internal
765
- */ function transformTables(documentFragment, writer) {
766
+ */ function transformTables(documentFragment, writer, hasTablePropertiesPlugin = false, hasExtendedTableBlockAlignment = false) {
766
767
  for (const item of writer.createRangeIn(documentFragment).getItems()){
767
768
  if (!item.is('element', 'table') && !item.is('element', 'td') && !item.is('element', 'th')) {
768
769
  continue;
769
770
  }
771
+ // In MS Word, left-aligned tables (default) have no align attribute on the `<table>` and are not wrapped in a `<div>`.
772
+ // In such cases, we need to set `margin-left: 0` and `margin-right: auto` to indicate to the editor that
773
+ // the table is block-aligned to the left.
774
+ //
775
+ // Center- and right-aligned tables in MS Word are wrapped in a `<div>` with the `align` attribute set to
776
+ // `center` or `right`, respectively with no align attribute on the `<table>` itself.
777
+ //
778
+ // Additionally, the structure may change when pasting content from MS Word.
779
+ // Some browsers (e.g., Safari) may insert extra elements around the table (e.g., a <span>),
780
+ // so the surrounding `<div>` with the `align` attribute may end up being the table's grandparent.
781
+ if (hasTablePropertiesPlugin && hasExtendedTableBlockAlignment && item.is('element', 'table')) {
782
+ const directParent = item.parent?.is('element', 'div') ? item.parent : null;
783
+ const grandParent = item.parent?.parent?.is('element', 'div') ? item.parent.parent : null;
784
+ const divParent = directParent ?? grandParent;
785
+ // Center block table alignment.
786
+ if (divParent && divParent.getAttribute('align') === 'center' && !item.getAttribute('align')) {
787
+ writer.setStyle('margin-left', 'auto', item);
788
+ writer.setStyle('margin-right', 'auto', item);
789
+ } else if (divParent && divParent.getAttribute('align') === 'right' && !item.getAttribute('align')) {
790
+ writer.setStyle('margin-left', 'auto', item);
791
+ writer.setStyle('margin-right', '0', item);
792
+ } else if (!divParent && !item.getAttribute('align')) {
793
+ writer.setStyle('margin-left', '0', item);
794
+ writer.setStyle('margin-right', 'auto', item);
795
+ }
796
+ }
770
797
  const sides = [
771
798
  'left',
772
799
  'top',
@@ -1040,13 +1067,17 @@ const msWordMatch2 = /xmlns:o="urn:schemas-microsoft-com/i;
1040
1067
  */ class PasteFromOfficeMSWordNormalizer {
1041
1068
  document;
1042
1069
  hasMultiLevelListPlugin;
1070
+ hasTablePropertiesPlugin;
1071
+ hasExtendedTableBlockAlignment;
1043
1072
  /**
1044
1073
  * Creates a new `PasteFromOfficeMSWordNormalizer` instance.
1045
1074
  *
1046
1075
  * @param document View document.
1047
- */ constructor(document, hasMultiLevelListPlugin = false){
1076
+ */ constructor(document, hasMultiLevelListPlugin = false, hasTablePropertiesPlugin = false, hasExtendedTableBlockAlignment = false){
1048
1077
  this.document = document;
1049
1078
  this.hasMultiLevelListPlugin = hasMultiLevelListPlugin;
1079
+ this.hasTablePropertiesPlugin = hasTablePropertiesPlugin;
1080
+ this.hasExtendedTableBlockAlignment = hasExtendedTableBlockAlignment;
1050
1081
  }
1051
1082
  /**
1052
1083
  * @inheritDoc
@@ -1061,7 +1092,7 @@ const msWordMatch2 = /xmlns:o="urn:schemas-microsoft-com/i;
1061
1092
  transformBookmarks(documentFragment, writer);
1062
1093
  transformListItemLikeElementsIntoLists(documentFragment, stylesString, this.hasMultiLevelListPlugin);
1063
1094
  replaceImagesSourceWithBase64(documentFragment, data.dataTransfer.getData('text/rtf'));
1064
- transformTables(documentFragment, writer);
1095
+ transformTables(documentFragment, writer, this.hasTablePropertiesPlugin, this.hasExtendedTableBlockAlignment);
1065
1096
  removeInvalidTableWidth(documentFragment, writer);
1066
1097
  replaceMSFootnotes(documentFragment, writer);
1067
1098
  removeMSAttributes(documentFragment);
@@ -1521,7 +1552,9 @@ const googleSheetsMatch = /<google-sheets-html-origin/i;
1521
1552
  const viewDocument = editor.editing.view.document;
1522
1553
  const normalizers = [];
1523
1554
  const hasMultiLevelListPlugin = this.editor.plugins.has('MultiLevelList');
1524
- normalizers.push(new PasteFromOfficeMSWordNormalizer(viewDocument, hasMultiLevelListPlugin));
1555
+ const hasTablePropertiesPlugin = this.editor.plugins.has('TableProperties');
1556
+ const hasExtendedTableBlockAlignment = !!this.editor.config.get('experimentalFlags.useExtendedTableBlockAlignment');
1557
+ normalizers.push(new PasteFromOfficeMSWordNormalizer(viewDocument, hasMultiLevelListPlugin, hasTablePropertiesPlugin, hasExtendedTableBlockAlignment));
1525
1558
  normalizers.push(new GoogleDocsNormalizer(viewDocument));
1526
1559
  normalizers.push(new GoogleSheetsNormalizer(viewDocument));
1527
1560
  clipboardPipeline.on('inputTransformation', (evt, data)=>{