@ckeditor/ckeditor5-export-word
Version:
Export to Word feature for CKEditor 5.
23 lines • 12 kB
JavaScript
/*
* Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
*
*
*
*
* +---------------------------------------------------------------------------------+
* | |
* | Hello stranger! |
* | |
* | |
* | What you're currently looking at is the source code of a legally protected, |
* | proprietary software. Any attempts to deobfuscate / disassemble this code |
* | are forbidden and will result in legal consequences. |
* | |
* | |
* +---------------------------------------------------------------------------------+
*
*
*
*
*/
import{Command as _0x11a5e3,Plugin as _0x133ffd}from'@ckeditor/ckeditor5-core/dist/index.js';import{ButtonView as _0x3e1e53,MenuBarMenuListItemButtonView as _0x2d9f42,SpinnerView as _0xe12daf,Notification as _0x554615}from'@ckeditor/ckeditor5-ui/dist/index.js';import{CloudServices as _0x2b7698}from'@ckeditor/ckeditor5-cloud-services/dist/index.js';import{logWarning as _0xc2c57a,collectStylesheets as _0x59fdf9}from'@ckeditor/ckeditor5-utils/dist/index.js';import{IconExportWord as _0x45fc55}from'@ckeditor/ckeditor5-icons/dist/index.js';function p(_0x44df72,_0x529f0e={}){const _0x5a8013=_0x44df72['plugins']['has']('Users'),_0x2822c4=_0x44df72['plugins']['has']('CommentsRepository'),_0x1cb610=_0x44df72['plugins']['has']('TrackChanges'),_0xd6ca41=_0x529f0e;if(_0x5a8013&&_0x2822c4){const _0x57735f=function(_0x5c43f2){const _0x2a1183={};if(!_0x5c43f2['length'])return _0x2a1183;for(const _0x25e305 of _0x5c43f2)_0x25e305['comments']['map'](_0x9483b9=>{void 0x0===_0x2a1183[_0x25e305['id']]&&(_0x2a1183[_0x25e305['id']]=[]),_0x2a1183[_0x25e305['id']]['push']({'author':_0x9483b9['author']['name'],'content':_0x9483b9['content'],'created':_0x9483b9['createdAt'],'is_resolved':_0x25e305['isResolved']});});return _0x2a1183;}(_0x44df72['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));Object['keys'](_0x57735f)['length']&&(_0xd6ca41['comments']=_0x57735f);}if(_0x5a8013&&_0x1cb610){const _0x5dba10=_0x44df72['plugins']['get']('TrackChanges'),_0x23e398=_0x44df72['plugins']['get']('Users'),_0x195c5d=function(_0x2fd624,_0x19c30e){const _0x699214={};if(!_0x2fd624['length']||!_0x19c30e['length'])return _0x699214;for(const {id:_0x5233e7,createdAt:_0x917fd2,authorId:_0x4b110f,attributes:_0x4d93b6}of _0x2fd624){const _0x313056=_0x4d93b6&&_0x4d93b6['@external'],_0x234a9d=_0x313056?_0x313056['authorName']:_0x19c30e['get'](_0x4b110f)['name'];_0x699214[_0x5233e7]={'author':_0x234a9d,'created':_0x917fd2};}return _0x699214;}(_0x5dba10['getSuggestions']({'toJSON':!0x0}),_0x23e398['users']);Object['keys'](_0x195c5d)['length']&&(_0xd6ca41['suggestions']=_0x195c5d);}return(_0xd6ca41['suggestions']||_0xd6ca41['comments'])&&(_0xd6ca41['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone']),_0xd6ca41;}function m(_0x59e000,_0x4ee560={}){const _0x1cf375=_0x59e000['plugins']['has']('Users'),_0x3c1c96=_0x59e000['plugins']['has']('CommentsRepository'),_0x237fea=_0x59e000['plugins']['has']('TrackChanges'),_0x249154=_0x59e000['plugins']['has']('MergeFields'),_0x2acd07=_0x59e000['locale']['contentLanguage'],_0x331915=_0x4ee560,_0x4c444={};if(_0x331915['document']=_0x331915['document']||{},_0x331915['document']['language']=_0x331915['document']['language']||_0x2acd07,_0x1cf375&&_0x3c1c96){const _0x502b8e=function(_0x4bd7b6){const _0x52f5e0=[];if(!_0x4bd7b6['length'])return _0x52f5e0;for(const _0x28374f of _0x4bd7b6){const _0x499a58=_0x28374f['comments']['map'](_0x4728e5=>({'author':_0x4728e5['author']['name'],'content':_0x4728e5['content'],'created_at':_0x4728e5['createdAt']}));_0x52f5e0['push']({'thread_id':_0x28374f['id'],'is_resolved':_0x28374f['isResolved'],'comments':_0x499a58});}return _0x52f5e0;}(_0x59e000['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));_0x502b8e['length']&&(_0x4c444['comment_threads']=_0x502b8e);}if(_0x1cf375&&_0x237fea){const _0x4c7225=_0x59e000['plugins']['get']('TrackChanges'),_0x4a07ef=_0x59e000['plugins']['get']('Users'),_0x39b11d=function(_0x405202,_0x4a1a22){if(!_0x405202['length']||!_0x4a1a22['length'])return[];return _0x405202['map'](({id:_0x2f33ca,createdAt:_0x530e20,authorId:_0x456c02,attributes:_0x56e9c5})=>{const _0x366a28=_0x56e9c5&&_0x56e9c5['@external'];return{'id':_0x2f33ca,'author':_0x366a28?_0x366a28['authorName']:_0x4a1a22['get'](_0x456c02)['name'],'created_at':_0x530e20};});}(_0x4c7225['getSuggestions']({'toJSON':!0x0}),_0x4a07ef['users']);_0x39b11d['length']&&(_0x4c444['suggestions']=_0x39b11d);}if(_0x249154){const _0x25cb15=_0x59e000['plugins']['get']('MergeFieldsEditing'),_0x4757bd=_0x25cb15['previewMode'],{prefix:_0x1589e7,suffix:_0x8aa326}=_0x59e000['config']['get']('mergeFields');if(_0x331915['merge_fields']={'prefix':_0x1589e7,'suffix':_0x8aa326},'$labels'!==_0x4757bd){_0x331915['merge_fields']['data']={};const _0x208a63='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88B8AAuUB8e2ujYwAAAAASUVORK5CYII=',_0x1203b0='$defaultValues'===_0x4757bd?_0x25cb15['getDefaultValues']():_0x25cb15['getDataSetValues'](_0x4757bd,!0x0);for(const _0x59103e of Object['entries'](_0x1203b0)){const [_0x2bb46f,_0x321096]=_0x59103e;'image'===_0x25cb15['getMergeFieldType'](_0x2bb46f)?_0x331915['merge_fields']['data'][_0x2bb46f]=null!==_0x321096?_0x321096:_0x208a63:_0x331915['merge_fields']['data'][_0x2bb46f]=null!==_0x321096?_0x321096:_0x25cb15['getLabel'](_0x2bb46f)||_0x2bb46f;}}}return(_0x4c444['comment_threads']||_0x4c444['suggestions'])&&(_0x331915['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone'],_0x331915['collaboration_features']=_0x4c444),_0x331915;}function f(_0x5d914a,_0x427cd7){const t=_0x5d914a['t'];switch(_0x427cd7){case'Export\x20to\x20Word':return t('Export\x20to\x20Word');case'An\x20error\x20occurred\x20while\x20generating\x20the\x20Word\x20file.':return t('An\x20error\x20occurred\x20while\x20generating\x20the\x20Word\x20file.');case'Word\x20document\x20export\x20started':return t('Word\x20document\x20export\x20started');case'Word\x20document\x20export\x20failed':return t('Word\x20document\x20export\x20failed');case'Word\x20document\x20export\x20successful':return t('Word\x20document\x20export\x20successful');case'Exporting\x20Word\x20document':return t('Exporting\x20Word\x20document');default:return _0x427cd7;}}const l=['orientation','margin_top','margin_right','margin_bottom','margin_left','format','header','footer','comments','suggestions'];class ExportWordCommand extends _0x11a5e3{constructor(_0x22d3e7){super(_0x22d3e7),this['set']('isBusy',!0x1),this['affectsData']=!0x1;}['refresh'](){this['isEnabled']=!this['isBusy'],this['value']=this['isBusy']?'pending':void 0x0;}['execute'](_0x5d75ed={}){const _0x46c03a=this['editor'],_0x2f7748=_0x5d75ed['version']||0x2,_0x37ca80=0x1===_0x2f7748,_0x2261bb=_0x5d75ed['converterUrl']||(_0x37ca80?'https://docx-converter.cke-cs.com/v1/convert':'https://docx-converter.cke-cs.com/v2/convert/html-docx'),_0x175fa8=_0x5d75ed['converterOptions']||{},_0x53950d=_0x46c03a['plugins']['get']('ExportWord'),_0x5f2837=_0x5d75ed['token']||_0x53950d['_token'],_0x31882a=!0x0===_0x175fa8['auto_pagination'],_0x2bd41d=_0x5d75ed['dataCallback']||(_0x234c79=>_0x234c79['data']['get']({'pagination':_0x31882a}));return 0x2===_0x2f7748&&function(_0x2983d6){for(const _0x1c77eb of l)if(void 0x0!==_0x2983d6[_0x1c77eb])return!0x0;return!0x1;}(_0x175fa8)&&_0xc2c57a('export-word-v1-api-is-deprecated'),this['isBusy']=!0x0,this['refresh'](),_0x59fdf9(_0x5d75ed['stylesheets']||['EDITOR_STYLES'])['then'](async _0x477ac7=>{_0x46c03a['ui']['ariaLiveAnnouncer']['announce'](f(_0x46c03a['locale'],'Word\x20document\x20export\x20started'));const _0x1eddeb=await _0x2bd41d(_0x46c03a),_0x4eb96e={'html':'<div\x20class=\x22ck-content\x22\x20dir=\x22'+_0x46c03a['locale']['contentLanguageDirection']+'\x22>'+_0x1eddeb+'</div>','css':_0x477ac7,[_0x37ca80?'options':'config']:{..._0x175fa8,..._0x37ca80?p(_0x46c03a,_0x175fa8):m(_0x46c03a,_0x175fa8)}},_0x54d508={'method':'POST','headers':{'Content-Type':'application/json','Accept':'application/docx',..._0x5f2837?{'Authorization':_0x5f2837['value']}:null},'body':JSON['stringify'](_0x4eb96e)};return window['fetch'](_0x2261bb,_0x54d508)['then'](_0x5a44f4=>{if(0xc8!==_0x5a44f4['status'])throw _0x5a44f4;return _0x5a44f4['blob']();})['then'](_0x30b194=>{_0x46c03a['ui']['ariaLiveAnnouncer']['announce'](f(_0x46c03a['locale'],'Word\x20document\x20export\x20successful'));const _0x49b5b5='function'==typeof _0x5d75ed['fileName']?_0x5d75ed['fileName']():_0x5d75ed['fileName'];this['_downloadFile'](_0x30b194,_0x49b5b5||'document.docx');});})['catch'](_0x1337fa=>{const _0x3e6752=_0x46c03a['plugins']['get']('Notification');throw _0x46c03a['ui']['ariaLiveAnnouncer']['announce'](f(_0x46c03a['locale'],'Word\x20document\x20export\x20failed'),{'politeness':'assertive'}),_0x3e6752['showWarning'](f(_0x46c03a['locale'],'An\x20error\x20occurred\x20while\x20generating\x20the\x20Word\x20file.')),_0x1337fa;})['finally'](()=>{this['isBusy']=!0x1,this['refresh']();});}['_downloadFile'](_0xf93360,_0x4625c6){const _0x4708c5=document['createElement']('a');_0x4708c5['href']=window['URL']['createObjectURL'](_0xf93360),_0x4708c5['download']=_0x4625c6,_0x4708c5['click'](),_0x4708c5['remove']();}}class ExportWordUI extends _0x133ffd{static get['pluginName'](){return'ExportWordUI';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}['init'](){const _0x3d0e3a=this['editor'];_0x3d0e3a['ui']['componentFactory']['add']('exportWord',()=>{const _0x2d802f=_0x3d0e3a['commands']['get']('exportWord'),_0x18d70a=this['_createButton'](_0x3e1e53);return _0x18d70a['set']({'tooltip':!0x0}),_0x18d70a['bind']('isOn')['to'](_0x2d802f,'isBusy'),_0x18d70a;}),_0x3d0e3a['ui']['componentFactory']['add']('menuBar:exportWord',()=>this['_createButton'](_0x2d9f42));}['_createButton'](_0x30d0c7){const _0x29e371=this['editor'],_0x252856=_0x29e371['config']['get']('exportWord')||{},_0xe884d1=_0x29e371['commands']['get']('exportWord'),_0x4c3e0d=new _0x30d0c7(_0x29e371['locale']),_0x41c4a7=new _0xe12daf();return _0x4c3e0d['children']['add'](_0x41c4a7),_0x41c4a7['bind']('isVisible')['to'](_0xe884d1,'isBusy'),_0x4c3e0d['iconView']['bind']('isVisible')['to'](_0xe884d1,'isBusy',_0x12c9d5=>!_0x12c9d5),_0x4c3e0d['set']({'icon':_0x45fc55}),_0x4c3e0d['bind']('isEnabled')['to'](_0xe884d1,'isEnabled'),_0x4c3e0d['bind']('label')['to'](_0xe884d1,'isBusy',_0x4c24a3=>f(_0x29e371['locale'],_0x4c24a3?'Exporting\x20Word\x20document':'Export\x20to\x20Word')),this['listenTo'](_0x4c3e0d,'execute',()=>{_0x29e371['execute']('exportWord',_0x252856),_0x29e371['editing']['view']['focus']();}),_0x4c3e0d;}}class ExportWord extends _0x133ffd{['_token'];static get['pluginName'](){return'ExportWord';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}static get['requires'](){return[_0x2b7698,_0x554615,ExportWordUI];}['init'](){const _0x891310=this['editor'],_0x464238=_0x891310['config']['get']('exportWord')||{};_0x891310['commands']['add']('exportWord',new ExportWordCommand(_0x891310));const _0x4b67aa=_0x891310['plugins']['get'](_0x2b7698);!0x1===_0x464238['tokenUrl']?this['_token']=null:_0x464238['tokenUrl']?_0x4b67aa['registerTokenUrl'](_0x464238['tokenUrl'])['then'](_0x48010f=>{this['_token']=_0x48010f;}):this['_token']=_0x4b67aa['token'];}}export{ExportWord,ExportWordCommand};