@ckeditor/ckeditor5-export-word
Version:
Export to Word feature for CKEditor 5.
23 lines • 11.9 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 _0x842054,Plugin as _0x1c788c}from'@ckeditor/ckeditor5-core';import{ButtonView as _0x186932,MenuBarMenuListItemButtonView as _0x576838,Notification as _0x455b9a,SpinnerView as _0x40457a}from'@ckeditor/ckeditor5-ui';import{CloudServices as _0x49f5ea}from'@ckeditor/ckeditor5-cloud-services';import{collectStylesheets as _0x33e860,logWarning as _0x183015}from'@ckeditor/ckeditor5-utils';import{IconExportWord as _0x59fe4b}from'@ckeditor/ckeditor5-icons';function p(_0x32c686,_0x1f38b8={}){const _0x541d3c=_0x32c686['plugins']['has']('Users'),_0x2c2f5f=_0x32c686['plugins']['has']('CommentsRepository'),_0x4ba03b=_0x32c686['plugins']['has']('TrackChanges'),_0x1f218e=_0x1f38b8;if(_0x541d3c&&_0x2c2f5f){const _0x196d5a=function(_0x3523bc){const _0x320dca={};if(!_0x3523bc['length'])return _0x320dca;for(const _0x3d0ac6 of _0x3523bc)_0x3d0ac6['comments']['map'](_0x59f38b=>{void 0x0===_0x320dca[_0x3d0ac6['id']]&&(_0x320dca[_0x3d0ac6['id']]=[]),_0x320dca[_0x3d0ac6['id']]['push']({'author':_0x59f38b['author']['name'],'content':_0x59f38b['content'],'created':_0x59f38b['createdAt'],'is_resolved':_0x3d0ac6['isResolved']});});return _0x320dca;}(_0x32c686['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));Object['keys'](_0x196d5a)['length']&&(_0x1f218e['comments']=_0x196d5a);}if(_0x541d3c&&_0x4ba03b){const _0x5864ba=_0x32c686['plugins']['get']('TrackChanges'),_0x2dca16=_0x32c686['plugins']['get']('Users'),_0x5df8de=function(_0x1cfe84,_0x1297c5){const _0x37c3a6={};if(!_0x1cfe84['length']||!_0x1297c5['length'])return _0x37c3a6;for(const {id:_0x28c800,createdAt:_0x1cdaf5,authorId:_0x276ded,attributes:_0x261721}of _0x1cfe84){const _0x558078=_0x261721&&_0x261721['@external'];_0x37c3a6[_0x28c800]={'author':_0x558078?_0x558078['authorName']:_0x1297c5['get'](_0x276ded)['name'],'created':_0x1cdaf5};}return _0x37c3a6;}(_0x5864ba['getSuggestions']({'toJSON':!0x0}),_0x2dca16['users']);Object['keys'](_0x5df8de)['length']&&(_0x1f218e['suggestions']=_0x5df8de);}return(_0x1f218e['suggestions']||_0x1f218e['comments'])&&(_0x1f218e['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone']),_0x1f218e;}function f(_0x5dc2f5,_0xf27025={}){const _0x3c6227=_0x5dc2f5['plugins']['has']('Users'),_0x4df478=_0x5dc2f5['plugins']['has']('CommentsRepository'),_0x3e2147=_0x5dc2f5['plugins']['has']('TrackChanges'),_0x26f3ca=_0x5dc2f5['plugins']['has']('MergeFields'),_0x338539=_0x5dc2f5['locale']['contentLanguage'],_0x2897ae=_0xf27025,_0x53c297={};if(_0x2897ae['document']=_0x2897ae['document']||{},_0x2897ae['document']['language']=_0x2897ae['document']['language']||_0x338539,_0x3c6227&&_0x4df478){const _0x50c611=function(_0x2f0a0e){const _0xa3e5b2=[];if(!_0x2f0a0e['length'])return _0xa3e5b2;for(const _0x24f38e of _0x2f0a0e){const _0x32722f=_0x24f38e['comments']['map'](_0x1e4c89=>({'author':_0x1e4c89['author']['name'],'content':_0x1e4c89['content'],'created_at':_0x1e4c89['createdAt']}));_0xa3e5b2['push']({'thread_id':_0x24f38e['id'],'is_resolved':_0x24f38e['isResolved'],'comments':_0x32722f});}return _0xa3e5b2;}(_0x5dc2f5['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));_0x50c611['length']&&(_0x53c297['comment_threads']=_0x50c611);}if(_0x3c6227&&_0x3e2147){const _0x22951f=_0x5dc2f5['plugins']['get']('TrackChanges'),_0x18901b=_0x5dc2f5['plugins']['get']('Users'),_0x166fa7=function(_0x1bbf02,_0x3afeee){return _0x1bbf02['length']&&_0x3afeee['length']?_0x1bbf02['map'](({id:_0x5aa5b1,createdAt:_0x1fb5d2,authorId:_0x2abc37,attributes:_0x4686ae})=>{const _0x2c890b=_0x4686ae&&_0x4686ae['@external'];return{'id':_0x5aa5b1,'author':_0x2c890b?_0x2c890b['authorName']:_0x3afeee['get'](_0x2abc37)['name'],'created_at':_0x1fb5d2};}):[];}(_0x22951f['getSuggestions']({'toJSON':!0x0}),_0x18901b['users']);_0x166fa7['length']&&(_0x53c297['suggestions']=_0x166fa7);}if(_0x26f3ca){const _0x30a1a9=_0x5dc2f5['plugins']['get']('MergeFieldsEditing'),_0x44032e=_0x30a1a9['previewMode'],{prefix:_0x521de5,suffix:_0xe165a6}=_0x5dc2f5['config']['get']('mergeFields');if(_0x2897ae['merge_fields']={'prefix':_0x521de5,'suffix':_0xe165a6},'$labels'!==_0x44032e){_0x2897ae['merge_fields']['data']={};const _0x10d93b='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88B8AAuUB8e2ujYwAAAAASUVORK5CYII=',_0x5e3181='$defaultValues'===_0x44032e?_0x30a1a9['getDefaultValues']():_0x30a1a9['getDataSetValues'](_0x44032e,!0x0);for(const _0x2369fc of Object['entries'](_0x5e3181)){const [_0x3a95d8,_0x23b373]=_0x2369fc;'image'===_0x30a1a9['getMergeFieldType'](_0x3a95d8)?_0x2897ae['merge_fields']['data'][_0x3a95d8]=null!==_0x23b373?_0x23b373:_0x10d93b:_0x2897ae['merge_fields']['data'][_0x3a95d8]=null!==_0x23b373?_0x23b373:_0x30a1a9['getLabel'](_0x3a95d8)||_0x3a95d8;}}}return(_0x53c297['comment_threads']||_0x53c297['suggestions'])&&(_0x2897ae['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone'],_0x2897ae['collaboration_features']=_0x53c297),_0x2897ae;}function l(_0x4c4a7f,_0x343bf1){const t=_0x4c4a7f['t'];switch(_0x343bf1){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 _0x343bf1;}}const m=['orientation','margin_top','margin_right','margin_bottom','margin_left','format','header','footer','comments','suggestions'];var h=class extends _0x842054{constructor(_0x3b07bc){super(_0x3b07bc),this['set']('isBusy',!0x1),this['affectsData']=!0x1;}['refresh'](){this['isEnabled']=!this['isBusy'],this['value']=this['isBusy']?'pending':void 0x0;}['execute'](_0x4caa0f={}){const _0x2f9eef=this['editor'],_0x3d6840=_0x4caa0f['version']||0x2,_0x166660=0x1===_0x3d6840,_0x3338ac=_0x4caa0f['converterUrl']||(_0x166660?'https://docx-converter.cke-cs.com/v1/convert':'https://docx-converter.cke-cs.com/v2/convert/html-docx'),_0x3d9e10=_0x4caa0f['converterOptions']||{},_0x39b34a=_0x2f9eef['plugins']['get']('ExportWord'),_0x578491=_0x4caa0f['token']||_0x39b34a['_token'],_0x51bac3=!0x0===_0x3d9e10['auto_pagination'],_0x46de3b=_0x4caa0f['dataCallback']||(_0x1c6501=>_0x1c6501['data']['get']({'pagination':_0x51bac3}));return 0x2===_0x3d6840&&function(_0x2c0e48){for(const _0x41a2ce of m)if(void 0x0!==_0x2c0e48[_0x41a2ce])return!0x0;return!0x1;}(_0x3d9e10)&&_0x183015('export-word-v1-api-is-deprecated'),this['isBusy']=!0x0,this['refresh'](),_0x33e860(_0x4caa0f['stylesheets']||['EDITOR_STYLES'])['then'](async _0x1c0589=>{_0x2f9eef['ui']['ariaLiveAnnouncer']['announce'](l(_0x2f9eef['locale'],'Word\x20document\x20export\x20started'));const _0xd5888b=await _0x46de3b(_0x2f9eef),_0x3472aa={'html':'<div\x20class=\x22ck-content\x22\x20dir=\x22'+_0x2f9eef['locale']['contentLanguageDirection']+'\x22>'+_0xd5888b+'</div>','css':_0x1c0589,[_0x166660?'options':'config']:{..._0x3d9e10,..._0x166660?p(_0x2f9eef,_0x3d9e10):f(_0x2f9eef,_0x3d9e10)}},_0x2a2180={'method':'POST','headers':{'Content-Type':'application/json','Accept':'application/docx',..._0x578491?{'Authorization':_0x578491['value']}:null},'body':JSON['stringify'](_0x3472aa)};return window['fetch'](_0x3338ac,_0x2a2180)['then'](_0x1843bc=>{if(0xc8!==_0x1843bc['status'])throw _0x1843bc;return _0x1843bc['blob']();})['then'](_0x51cde9=>{_0x2f9eef['ui']['ariaLiveAnnouncer']['announce'](l(_0x2f9eef['locale'],'Word\x20document\x20export\x20successful'));const _0x66a80='function'==typeof _0x4caa0f['fileName']?_0x4caa0f['fileName']():_0x4caa0f['fileName'];this['_downloadFile'](_0x51cde9,_0x66a80||'document.docx');});})['catch'](_0x24ae21=>{const _0x1da9d2=_0x2f9eef['plugins']['get']('Notification');throw _0x2f9eef['ui']['ariaLiveAnnouncer']['announce'](l(_0x2f9eef['locale'],'Word\x20document\x20export\x20failed'),{'politeness':'assertive'}),_0x1da9d2['showWarning'](l(_0x2f9eef['locale'],'An\x20error\x20occurred\x20while\x20generating\x20the\x20Word\x20file.')),_0x24ae21;})['finally'](()=>{this['isBusy']=!0x1,this['refresh']();});}['_downloadFile'](_0xc4649c,_0x28907d){const _0x22a53c=document['createElement']('a');_0x22a53c['href']=window['URL']['createObjectURL'](_0xc4649c),_0x22a53c['download']=_0x28907d,_0x22a53c['click'](),_0x22a53c['remove']();}},g=class extends _0x1c788c{static get['pluginName'](){return'ExportWordUI';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}['init'](){const _0x3cdf38=this['editor'];_0x3cdf38['ui']['componentFactory']['add']('exportWord',()=>{const _0x179052=_0x3cdf38['commands']['get']('exportWord'),_0xcd8cd1=this['_createButton'](_0x186932);return _0xcd8cd1['set']({'tooltip':!0x0}),_0xcd8cd1['bind']('isOn')['to'](_0x179052,'isBusy'),_0xcd8cd1;}),_0x3cdf38['ui']['componentFactory']['add']('menuBar:exportWord',()=>this['_createButton'](_0x576838));}['_createButton'](_0x125c79){const _0x36851f=this['editor'],_0x1a6119=_0x36851f['config']['get']('exportWord')||{},_0x1beb9c=_0x36851f['commands']['get']('exportWord'),_0x44e7a5=new _0x125c79(_0x36851f['locale']),_0x54d12b=new _0x40457a();return _0x44e7a5['children']['add'](_0x54d12b),_0x54d12b['bind']('isVisible')['to'](_0x1beb9c,'isBusy'),_0x44e7a5['iconView']['bind']('isVisible')['to'](_0x1beb9c,'isBusy',_0x192018=>!_0x192018),_0x44e7a5['set']({'icon':_0x59fe4b}),_0x44e7a5['bind']('isEnabled')['to'](_0x1beb9c,'isEnabled'),_0x44e7a5['bind']('label')['to'](_0x1beb9c,'isBusy',_0x4e0644=>l(_0x36851f['locale'],_0x4e0644?'Exporting\x20Word\x20document':'Export\x20to\x20Word')),this['listenTo'](_0x44e7a5,'execute',()=>{_0x36851f['execute']('exportWord',_0x1a6119),_0x36851f['editing']['view']['focus']();}),_0x44e7a5;}},x=class extends _0x1c788c{['_token'];static get['pluginName'](){return'ExportWord';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}static get['requires'](){return[_0x49f5ea,_0x455b9a,g];}['init'](){const _0x39af5e=this['editor'],_0x29f7a8=_0x39af5e['config']['get']('exportWord')||{};_0x39af5e['commands']['add']('exportWord',new h(_0x39af5e));const _0x384507=_0x39af5e['plugins']['get'](_0x49f5ea);!0x1===_0x29f7a8['tokenUrl']?this['_token']=null:_0x29f7a8['tokenUrl']?_0x384507['registerTokenUrl'](_0x29f7a8['tokenUrl'])['then'](_0x570a45=>{this['_token']=_0x570a45;}):this['_token']=_0x384507['token'];}};export{x as ExportWord,h as ExportWordCommand};