@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 _0x3d0a38,Plugin as _0x4d3a04}from'@ckeditor/ckeditor5-core/dist/index.js';import{ButtonView as _0x3002a5,MenuBarMenuListItemButtonView as _0x1b6c72,SpinnerView as _0x1bdcab,Notification as _0x3245ff}from'@ckeditor/ckeditor5-ui/dist/index.js';import{logWarning as _0x32a9d9,collectStylesheets as _0x42c18c}from'@ckeditor/ckeditor5-utils/dist/index.js';import{IconExportWord as _0x16d45c}from'@ckeditor/ckeditor5-icons/dist/index.js';function d(_0x22caab,_0x4e167e={}){const _0x28018f=_0x22caab['plugins']['has']('Users'),_0xa5eb2c=_0x22caab['plugins']['has']('CommentsRepository'),_0x570a2f=_0x22caab['plugins']['has']('TrackChanges'),_0x519486=_0x4e167e;if(_0x28018f&&_0xa5eb2c){const _0x48ba5d=function(_0x1e608d){const _0xfb5e90={};if(!_0x1e608d['length'])return _0xfb5e90;for(const _0x5544ee of _0x1e608d)_0x5544ee['comments']['map'](_0x554143=>{void 0x0===_0xfb5e90[_0x5544ee['id']]&&(_0xfb5e90[_0x5544ee['id']]=[]),_0xfb5e90[_0x5544ee['id']]['push']({'author':_0x554143['author']['name'],'content':_0x554143['content'],'created':_0x554143['createdAt'],'is_resolved':_0x5544ee['isResolved']});});return _0xfb5e90;}(_0x22caab['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));Object['keys'](_0x48ba5d)['length']&&(_0x519486['comments']=_0x48ba5d);}if(_0x28018f&&_0x570a2f){const _0x1a5eec=_0x22caab['plugins']['get']('TrackChanges'),_0x43c92a=_0x22caab['plugins']['get']('Users'),_0x18dac7=function(_0x3a8d1a,_0xec3324){const _0x48a668={};if(!_0x3a8d1a['length']||!_0xec3324['length'])return _0x48a668;for(const {id:_0x57c86e,createdAt:_0x38a946,authorId:_0xf48023,attributes:_0x21b0fa}of _0x3a8d1a){const _0x3b9299=_0x21b0fa&&_0x21b0fa['@external'],_0x363525=_0x3b9299?_0x3b9299['authorName']:_0xec3324['get'](_0xf48023)['name'];_0x48a668[_0x57c86e]={'author':_0x363525,'created':_0x38a946};}return _0x48a668;}(_0x1a5eec['getSuggestions']({'toJSON':!0x0}),_0x43c92a['users']);Object['keys'](_0x18dac7)['length']&&(_0x519486['suggestions']=_0x18dac7);}return(_0x519486['suggestions']||_0x519486['comments'])&&(_0x519486['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone']),_0x519486;}function a(_0x14a1e5,_0x521ed7={}){const _0x111a0a=_0x14a1e5['plugins']['has']('Users'),_0x5f5499=_0x14a1e5['plugins']['has']('CommentsRepository'),_0x32c19f=_0x14a1e5['plugins']['has']('TrackChanges'),_0x34f11a=_0x14a1e5['plugins']['has']('MergeFields'),_0x2f5b14=_0x14a1e5['locale']['contentLanguage'],_0x3b724e=_0x521ed7,_0x7c1ee={};if(_0x3b724e['document']=_0x3b724e['document']||{},_0x3b724e['document']['language']=_0x3b724e['document']['language']||_0x2f5b14,_0x111a0a&&_0x5f5499){const _0x1e0e00=function(_0x3e6fc9){const _0x25b41d=[];if(!_0x3e6fc9['length'])return _0x25b41d;for(const _0x4fbc84 of _0x3e6fc9){const _0x33a8ef=_0x4fbc84['comments']['map'](_0x40bed0=>({'author':_0x40bed0['author']['name'],'content':_0x40bed0['content'],'created_at':_0x40bed0['createdAt']}));_0x25b41d['push']({'thread_id':_0x4fbc84['id'],'is_resolved':_0x4fbc84['isResolved'],'comments':_0x33a8ef});}return _0x25b41d;}(_0x14a1e5['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));_0x1e0e00['length']&&(_0x7c1ee['comment_threads']=_0x1e0e00);}if(_0x111a0a&&_0x32c19f){const _0x44e7c8=_0x14a1e5['plugins']['get']('TrackChanges'),_0x50ba6c=_0x14a1e5['plugins']['get']('Users'),_0x8e8aca=function(_0x54a72d,_0x118373){if(!_0x54a72d['length']||!_0x118373['length'])return[];return _0x54a72d['map'](({id:_0x33ff01,createdAt:_0x3a8b07,authorId:_0x560b27,attributes:_0xd3c34})=>{const _0x220d34=_0xd3c34&&_0xd3c34['@external'];return{'id':_0x33ff01,'author':_0x220d34?_0x220d34['authorName']:_0x118373['get'](_0x560b27)['name'],'created_at':_0x3a8b07};});}(_0x44e7c8['getSuggestions']({'toJSON':!0x0}),_0x50ba6c['users']);_0x8e8aca['length']&&(_0x7c1ee['suggestions']=_0x8e8aca);}if(_0x34f11a){const _0x5069da=_0x14a1e5['plugins']['get']('MergeFieldsEditing'),_0x134613=_0x5069da['previewMode'],{prefix:_0x36c957,suffix:_0x3d64e4}=_0x14a1e5['config']['get']('mergeFields');if(_0x3b724e['merge_fields']={'prefix':_0x36c957,'suffix':_0x3d64e4},'$labels'!==_0x134613){_0x3b724e['merge_fields']['data']={};const _0x17c891='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88B8AAuUB8e2ujYwAAAAASUVORK5CYII=',_0x55a37a='$defaultValues'===_0x134613?_0x5069da['getDefaultValues']():_0x5069da['getDataSetValues'](_0x134613,!0x0);for(const _0x2d63f4 of Object['entries'](_0x55a37a)){const [_0x4bfd33,_0x34085d]=_0x2d63f4;'image'===_0x5069da['getMergeFieldType'](_0x4bfd33)?_0x3b724e['merge_fields']['data'][_0x4bfd33]=null!==_0x34085d?_0x34085d:_0x17c891:_0x3b724e['merge_fields']['data'][_0x4bfd33]=null!==_0x34085d?_0x34085d:_0x5069da['getLabel'](_0x4bfd33)||_0x4bfd33;}}}return(_0x7c1ee['comment_threads']||_0x7c1ee['suggestions'])&&(_0x3b724e['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone'],_0x3b724e['collaboration_features']=_0x7c1ee),_0x3b724e;}function m(_0x13322c,_0x5e8144){const t=_0x13322c['t'];switch(_0x5e8144){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 _0x5e8144;}}const p=['orientation','margin_top','margin_right','margin_bottom','margin_left','format','header','footer','comments','suggestions'];class i extends _0x3d0a38{constructor(_0x4d0fc3){super(_0x4d0fc3),this['set']('isBusy',!0x1),this['affectsData']=!0x1;}['refresh'](){this['isEnabled']=!this['isBusy'],this['value']=this['isBusy']?'pending':void 0x0;}['execute'](_0x222867={}){const _0x1c0db5=this['editor'],_0x694a9c=_0x222867['version']||0x2,_0x3cbbed=0x1===_0x694a9c,_0x4ed788=_0x222867['converterUrl']||(_0x3cbbed?'https://docx-converter.cke-cs.com/v1/convert':'https://docx-converter.cke-cs.com/v2/convert/html-docx'),_0x559e48=_0x222867['converterOptions']||{},_0x5a8ccc=_0x1c0db5['plugins']['get']('ExportWord'),_0x26b15b=_0x222867['token']||_0x5a8ccc['_token'],_0x2cbcc8=!0x0===_0x559e48['auto_pagination'],_0x43c464=_0x222867['dataCallback']||(_0x5e2a62=>_0x5e2a62['data']['get']({'pagination':_0x2cbcc8}));return 0x2===_0x694a9c&&function(_0x226e0a){for(const _0x271e00 of p)if(void 0x0!==_0x226e0a[_0x271e00])return!0x0;return!0x1;}(_0x559e48)&&_0x32a9d9('export-word-v1-api-is-deprecated'),this['isBusy']=!0x0,this['refresh'](),_0x42c18c(_0x222867['stylesheets']||['EDITOR_STYLES'])['then'](async _0x1d9728=>{_0x1c0db5['ui']['ariaLiveAnnouncer']['announce'](m(_0x1c0db5['locale'],'Word\x20document\x20export\x20started'));const _0x6e2ada=await _0x43c464(_0x1c0db5),_0x244960={'html':'<div\x20class=\x22ck-content\x22\x20dir=\x22'+_0x1c0db5['locale']['contentLanguageDirection']+'\x22>'+_0x6e2ada+'</div>','css':_0x1d9728,[_0x3cbbed?'options':'config']:{..._0x559e48,..._0x3cbbed?d(_0x1c0db5,_0x559e48):a(_0x1c0db5,_0x559e48)}},_0x25023d={'method':'POST','headers':{'Content-Type':'application/json','Accept':'application/docx',..._0x26b15b?{'Authorization':_0x26b15b['value']}:null},'body':JSON['stringify'](_0x244960)};return window['fetch'](_0x4ed788,_0x25023d)['then'](_0x1e498f=>{if(0xc8!==_0x1e498f['status'])throw _0x1e498f;return _0x1e498f['blob']();})['then'](_0x57a117=>{_0x1c0db5['ui']['ariaLiveAnnouncer']['announce'](m(_0x1c0db5['locale'],'Word\x20document\x20export\x20successful'));const _0x247ee1='function'==typeof _0x222867['fileName']?_0x222867['fileName']():_0x222867['fileName'];this['_downloadFile'](_0x57a117,_0x247ee1||'document.docx');});})['catch'](_0xbf8998=>{const _0x25995a=_0x1c0db5['plugins']['get']('Notification');throw _0x1c0db5['ui']['ariaLiveAnnouncer']['announce'](m(_0x1c0db5['locale'],'Word\x20document\x20export\x20failed'),{'politeness':'assertive'}),_0x25995a['showWarning'](m(_0x1c0db5['locale'],'An\x20error\x20occurred\x20while\x20generating\x20the\x20Word\x20file.')),_0xbf8998;})['finally'](()=>{this['isBusy']=!0x1,this['refresh']();});}['_downloadFile'](_0x3dac52,_0x225c54){const _0x3eeb80=document['createElement']('a');_0x3eeb80['href']=window['URL']['createObjectURL'](_0x3dac52),_0x3eeb80['download']=_0x225c54,_0x3eeb80['click'](),_0x3eeb80['remove']();}}class e extends _0x4d3a04{static get['pluginName'](){return'ExportWordUI';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}['init'](){const _0x4cac1c=this['editor'];_0x4cac1c['ui']['componentFactory']['add']('exportWord',()=>{const _0x5b3f16=_0x4cac1c['commands']['get']('exportWord'),_0x19bdbe=this['_createButton'](_0x3002a5);return _0x19bdbe['set']({'tooltip':!0x0}),_0x19bdbe['bind']('isOn')['to'](_0x5b3f16,'isBusy'),_0x19bdbe;}),_0x4cac1c['ui']['componentFactory']['add']('menuBar:exportWord',()=>this['_createButton'](_0x1b6c72));}['_createButton'](_0x128ee8){const _0x16c939=this['editor'],_0x17e36d=_0x16c939['config']['get']('exportWord')||{},_0x1c0e1a=_0x16c939['commands']['get']('exportWord'),_0x171b10=new _0x128ee8(_0x16c939['locale']),_0x56aaa5=new _0x1bdcab();return _0x171b10['children']['add'](_0x56aaa5),_0x56aaa5['bind']('isVisible')['to'](_0x1c0e1a,'isBusy'),_0x171b10['iconView']['bind']('isVisible')['to'](_0x1c0e1a,'isBusy',_0x4a0b66=>!_0x4a0b66),_0x171b10['set']({'icon':_0x16d45c}),_0x171b10['bind']('isEnabled')['to'](_0x1c0e1a,'isEnabled'),_0x171b10['bind']('label')['to'](_0x1c0e1a,'isBusy',_0x22688a=>m(_0x16c939['locale'],_0x22688a?'Exporting\x20Word\x20document':'Export\x20to\x20Word')),this['listenTo'](_0x171b10,'execute',()=>{_0x16c939['execute']('exportWord',_0x17e36d),_0x16c939['editing']['view']['focus']();}),_0x171b10;}}class f extends _0x4d3a04{['_token'];static get['pluginName'](){return'ExportWord';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}static get['requires'](){return['CloudServices',_0x3245ff,e];}['init'](){const _0xe14317=this['editor'],_0xda8dc5=_0xe14317['config']['get']('exportWord')||{};_0xe14317['commands']['add']('exportWord',new i(_0xe14317));const _0x28cb83=_0xe14317['plugins']['get']('CloudServices');!0x1===_0xda8dc5['tokenUrl']?this['_token']=null:_0xda8dc5['tokenUrl']?_0x28cb83['registerTokenUrl'](_0xda8dc5['tokenUrl'])['then'](_0x567bfb=>{this['_token']=_0x567bfb;}):this['_token']=_0x28cb83['token'];}}export{f as ExportWord,i as ExportWordCommand};