@ckeditor/ckeditor5-export-word
Version:
Export to Word feature for CKEditor 5.
23 lines • 11.9 kB
JavaScript
/*
* Copyright (c) 2003-2025, 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 _0x2a3c59,Plugin as _0x45b22f}from'@ckeditor/ckeditor5-core/dist/index.js';import{ButtonView as _0x45e749,MenuBarMenuListItemButtonView as _0x588ff2,SpinnerView as _0x322666,Notification as _0x36816c}from'@ckeditor/ckeditor5-ui/dist/index.js';import{logWarning as _0x575507,collectStylesheets as _0x15e06c}from'@ckeditor/ckeditor5-utils/dist/index.js';import{IconExportWord as _0x2bc53f}from'@ckeditor/ckeditor5-icons/dist/index.js';function a(_0x2f0082,_0x42becd={}){const _0x59e47d=_0x2f0082['plugins']['has']('Users'),_0x22dd6c=_0x2f0082['plugins']['has']('CommentsRepository'),_0x11a31b=_0x2f0082['plugins']['has']('TrackChanges'),_0x29c5f3=_0x42becd;if(_0x59e47d&&_0x22dd6c){const _0x1603ef=function(_0x5c1bfa){const _0x5ec989={};if(!_0x5c1bfa['length'])return _0x5ec989;for(const _0x503078 of _0x5c1bfa)_0x503078['comments']['map'](_0x17a93e=>{void 0x0===_0x5ec989[_0x503078['id']]&&(_0x5ec989[_0x503078['id']]=[]),_0x5ec989[_0x503078['id']]['push']({'author':_0x17a93e['author']['name'],'content':_0x17a93e['content'],'created':_0x17a93e['createdAt'],'is_resolved':_0x503078['isResolved']});});return _0x5ec989;}(_0x2f0082['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));Object['keys'](_0x1603ef)['length']&&(_0x29c5f3['comments']=_0x1603ef);}if(_0x59e47d&&_0x11a31b){const _0x233b3c=_0x2f0082['plugins']['get']('TrackChanges'),_0xb6452a=_0x2f0082['plugins']['get']('Users'),_0x15f04e=function(_0x222c70,_0xd2555f){const _0xd2959f={};if(!_0x222c70['length']||!_0xd2555f['length'])return _0xd2959f;for(const {id:_0x4d7095,createdAt:_0x2931cd,authorId:_0x19682a,attributes:_0x2e3c36}of _0x222c70){const _0x23d138=_0x2e3c36&&_0x2e3c36['@external'],_0xdec7f=_0x23d138?_0x23d138['authorName']:_0xd2555f['get'](_0x19682a)['name'];_0xd2959f[_0x4d7095]={'author':_0xdec7f,'created':_0x2931cd};}return _0xd2959f;}(_0x233b3c['getSuggestions']({'toJSON':!0x0}),_0xb6452a['users']);Object['keys'](_0x15f04e)['length']&&(_0x29c5f3['suggestions']=_0x15f04e);}return(_0x29c5f3['suggestions']||_0x29c5f3['comments'])&&(_0x29c5f3['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone']),_0x29c5f3;}function m(_0x518b5e,_0x519944={}){const _0x6067e0=_0x518b5e['plugins']['has']('Users'),_0x4de625=_0x518b5e['plugins']['has']('CommentsRepository'),_0x2f5256=_0x518b5e['plugins']['has']('TrackChanges'),_0x10776a=_0x518b5e['plugins']['has']('MergeFields'),_0x20fdfe=_0x518b5e['locale']['contentLanguage'],_0x5b4e24=_0x519944,_0x5e8a69={};if(_0x5b4e24['document']=_0x5b4e24['document']||{},_0x5b4e24['document']['language']=_0x5b4e24['document']['language']||_0x20fdfe,_0x6067e0&&_0x4de625){const _0x586cd9=function(_0x3e985e){const _0x5d0876=[];if(!_0x3e985e['length'])return _0x5d0876;for(const _0x13ee1f of _0x3e985e){const _0x5eaf61=_0x13ee1f['comments']['map'](_0x47eee8=>({'author':_0x47eee8['author']['name'],'content':_0x47eee8['content'],'created_at':_0x47eee8['createdAt']}));_0x5d0876['push']({'thread_id':_0x13ee1f['id'],'is_resolved':_0x13ee1f['isResolved'],'comments':_0x5eaf61});}return _0x5d0876;}(_0x518b5e['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));_0x586cd9['length']&&(_0x5e8a69['comment_threads']=_0x586cd9);}if(_0x6067e0&&_0x2f5256){const _0x85f061=_0x518b5e['plugins']['get']('TrackChanges'),_0x495d82=_0x518b5e['plugins']['get']('Users'),_0x7d6cb4=function(_0x302b90,_0x4fee1c){if(!_0x302b90['length']||!_0x4fee1c['length'])return[];return _0x302b90['map'](({id:_0x1cf897,createdAt:_0x2c9531,authorId:_0x47b64a,attributes:_0x47a9f2})=>{const _0x36b292=_0x47a9f2&&_0x47a9f2['@external'];return{'id':_0x1cf897,'author':_0x36b292?_0x36b292['authorName']:_0x4fee1c['get'](_0x47b64a)['name'],'created_at':_0x2c9531};});}(_0x85f061['getSuggestions']({'toJSON':!0x0}),_0x495d82['users']);_0x7d6cb4['length']&&(_0x5e8a69['suggestions']=_0x7d6cb4);}if(_0x10776a){const _0x688201=_0x518b5e['plugins']['get']('MergeFieldsEditing'),_0x3e0770=_0x688201['previewMode'],{prefix:_0x4e7410,suffix:_0x30f525}=_0x518b5e['config']['get']('mergeFields');if(_0x5b4e24['merge_fields']={'prefix':_0x4e7410,'suffix':_0x30f525},'$labels'!==_0x3e0770){_0x5b4e24['merge_fields']['data']={};const _0x23936a='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88B8AAuUB8e2ujYwAAAAASUVORK5CYII=',_0xcc2f22='$defaultValues'===_0x3e0770?_0x688201['getDefaultValues']():_0x688201['getDataSetValues'](_0x3e0770,!0x0);for(const _0x1a9a4b of Object['entries'](_0xcc2f22)){const [_0x21efc2,_0x521e46]=_0x1a9a4b;'image'===_0x688201['getMergeFieldType'](_0x21efc2)?_0x5b4e24['merge_fields']['data'][_0x21efc2]=null!==_0x521e46?_0x521e46:_0x23936a:_0x5b4e24['merge_fields']['data'][_0x21efc2]=null!==_0x521e46?_0x521e46:_0x688201['getLabel'](_0x21efc2)||_0x21efc2;}}}return(_0x5e8a69['comment_threads']||_0x5e8a69['suggestions'])&&(_0x5b4e24['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone'],_0x5b4e24['collaboration_features']=_0x5e8a69),_0x5b4e24;}function p(_0x25378b,_0x1eff60){const t=_0x25378b['t'];switch(_0x1eff60){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 _0x1eff60;}}const h=['orientation','margin_top','margin_right','margin_bottom','margin_left','format','header','footer','comments','suggestions'];class i extends _0x2a3c59{constructor(_0x22c18a){super(_0x22c18a),this['set']('isBusy',!0x1),this['affectsData']=!0x1;}['refresh'](){this['isEnabled']=!this['isBusy'],this['value']=this['isBusy']?'pending':void 0x0;}['execute'](_0x34da60={}){const _0x12a5ac=this['editor'],_0x348483=_0x34da60['version']||0x2,_0x374196=0x1===_0x348483,_0x35c6ff=_0x34da60['converterUrl']||(_0x374196?'https://docx-converter.cke-cs.com/v1/convert':'https://docx-converter.cke-cs.com/v2/convert/html-docx'),_0xbbfeb7=_0x34da60['converterOptions']||{},_0x55fd30=_0x12a5ac['plugins']['get']('ExportWord'),_0x932017=_0x34da60['token']||_0x55fd30['_token'],_0x20007f=!0x0===_0xbbfeb7['auto_pagination'],_0x23caea=_0x34da60['dataCallback']||(_0x2a08f2=>_0x2a08f2['data']['get']({'pagination':_0x20007f}));return 0x2===_0x348483&&function(_0x574e83){for(const _0x7b6ace of h)if(void 0x0!==_0x574e83[_0x7b6ace])return!0x0;return!0x1;}(_0xbbfeb7)&&_0x575507('export-word-v1-api-is-deprecated'),this['isBusy']=!0x0,this['refresh'](),_0x15e06c(_0x34da60['stylesheets']||['EDITOR_STYLES'])['then'](async _0x304237=>{_0x12a5ac['ui']['ariaLiveAnnouncer']['announce'](p(_0x12a5ac['locale'],'Word\x20document\x20export\x20started'));const _0x4b85b8=await _0x23caea(_0x12a5ac),_0x3a9bdc={'html':'<div\x20class=\x22ck-content\x22\x20dir=\x22'+_0x12a5ac['locale']['contentLanguageDirection']+'\x22>'+_0x4b85b8+'</div>','css':_0x304237,[_0x374196?'options':'config']:{..._0xbbfeb7,..._0x374196?a(_0x12a5ac,_0xbbfeb7):m(_0x12a5ac,_0xbbfeb7)}},_0x172058={'method':'POST','headers':{'Content-Type':'application/json','Accept':'application/docx',..._0x932017?{'Authorization':_0x932017['value']}:null},'body':JSON['stringify'](_0x3a9bdc)};return window['fetch'](_0x35c6ff,_0x172058)['then'](_0x2ccb30=>{if(0xc8!==_0x2ccb30['status'])throw _0x2ccb30;return _0x2ccb30['blob']();})['then'](_0x11f652=>{_0x12a5ac['ui']['ariaLiveAnnouncer']['announce'](p(_0x12a5ac['locale'],'Word\x20document\x20export\x20successful'));const _0x5b5616='function'==typeof _0x34da60['fileName']?_0x34da60['fileName']():_0x34da60['fileName'];this['_downloadFile'](_0x11f652,_0x5b5616||'document.docx');});})['catch'](_0x14d063=>{const _0x54925c=_0x12a5ac['plugins']['get']('Notification');throw _0x12a5ac['ui']['ariaLiveAnnouncer']['announce'](p(_0x12a5ac['locale'],'Word\x20document\x20export\x20failed'),{'politeness':'assertive'}),_0x54925c['showWarning'](p(_0x12a5ac['locale'],'An\x20error\x20occurred\x20while\x20generating\x20the\x20Word\x20file.')),_0x14d063;})['finally'](()=>{this['isBusy']=!0x1,this['refresh']();});}['_downloadFile'](_0x275207,_0x3b7561){const _0x2a0b1d=document['createElement']('a');_0x2a0b1d['href']=window['URL']['createObjectURL'](_0x275207),_0x2a0b1d['download']=_0x3b7561,_0x2a0b1d['click'](),_0x2a0b1d['remove']();}}class o extends _0x45b22f{static get['pluginName'](){return'ExportWordUI';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}['init'](){const _0x41f104=this['editor'];_0x41f104['ui']['componentFactory']['add']('exportWord',()=>{const _0x3387ea=_0x41f104['commands']['get']('exportWord'),_0xd1941a=this['_createButton'](_0x45e749);return _0xd1941a['set']({'tooltip':!0x0}),_0xd1941a['bind']('isOn')['to'](_0x3387ea,'isBusy'),_0xd1941a;}),_0x41f104['ui']['componentFactory']['add']('menuBar:exportWord',()=>this['_createButton'](_0x588ff2));}['_createButton'](_0x458f1d){const _0x428d8a=this['editor'],_0x470d36=_0x428d8a['config']['get']('exportWord')||{},_0x1f2764=_0x428d8a['commands']['get']('exportWord'),_0x2b9f4d=new _0x458f1d(_0x428d8a['locale']),_0x25bbe5=new _0x322666();return _0x2b9f4d['children']['add'](_0x25bbe5),_0x25bbe5['bind']('isVisible')['to'](_0x1f2764,'isBusy'),_0x2b9f4d['iconView']['bind']('isVisible')['to'](_0x1f2764,'isBusy',_0x27c00b=>!_0x27c00b),_0x2b9f4d['set']({'icon':_0x2bc53f}),_0x2b9f4d['bind']('isEnabled')['to'](_0x1f2764,'isEnabled'),_0x2b9f4d['bind']('label')['to'](_0x1f2764,'isBusy',_0x1e22fa=>p(_0x428d8a['locale'],_0x1e22fa?'Exporting\x20Word\x20document':'Export\x20to\x20Word')),this['listenTo'](_0x2b9f4d,'execute',()=>{_0x428d8a['execute']('exportWord',_0x470d36),_0x428d8a['editing']['view']['focus']();}),_0x2b9f4d;}}class s extends _0x45b22f{['_token'];static get['pluginName'](){return'ExportWord';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}static get['requires'](){return['CloudServices',_0x36816c,o];}['init'](){const _0x3b4784=this['editor'],_0x200df2=_0x3b4784['config']['get']('exportWord')||{};_0x3b4784['commands']['add']('exportWord',new i(_0x3b4784));const _0x18f727=_0x3b4784['plugins']['get']('CloudServices');!0x1===_0x200df2['tokenUrl']?this['_token']=null:_0x200df2['tokenUrl']?_0x18f727['registerTokenUrl'](_0x200df2['tokenUrl'])['then'](_0x16c8f0=>{this['_token']=_0x16c8f0;}):this['_token']=_0x18f727['token'];}}export{s as ExportWord};