UNPKG

@ckeditor/ckeditor5-export-word

Version:

Export to Word feature for CKEditor 5.

23 lines • 11.9 kB
/* * 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 _0x453227,Plugin as _0x5e39f0}from'@ckeditor/ckeditor5-core/dist/index.js';import{ButtonView as _0x1e7b35,MenuBarMenuListItemButtonView as _0x5793f3,SpinnerView as _0x96fc8,Notification as _0x2497b1}from'@ckeditor/ckeditor5-ui/dist/index.js';import{logWarning as _0x177c1e,collectStylesheets as _0x52a03}from'@ckeditor/ckeditor5-utils/dist/index.js';import{IconExportWord as _0x45fe21}from'@ckeditor/ckeditor5-icons/dist/index.js';function a(_0x3a6a40,_0x3c282b={}){const _0x13750f=_0x3a6a40['plugins']['has']('Users'),_0x59e0b7=_0x3a6a40['plugins']['has']('CommentsRepository'),_0x1dde42=_0x3a6a40['plugins']['has']('TrackChanges'),_0x350aad=_0x3c282b;if(_0x13750f&&_0x59e0b7){const _0x3b95b6=function(_0x2f5a7c){const _0x3e3c44={};if(!_0x2f5a7c['length'])return _0x3e3c44;for(const _0x4c0698 of _0x2f5a7c)_0x4c0698['comments']['map'](_0x370be7=>{void 0x0===_0x3e3c44[_0x4c0698['id']]&&(_0x3e3c44[_0x4c0698['id']]=[]),_0x3e3c44[_0x4c0698['id']]['push']({'author':_0x370be7['author']['name'],'content':_0x370be7['content'],'created':_0x370be7['createdAt'],'is_resolved':_0x4c0698['isResolved']});});return _0x3e3c44;}(_0x3a6a40['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));Object['keys'](_0x3b95b6)['length']&&(_0x350aad['comments']=_0x3b95b6);}if(_0x13750f&&_0x1dde42){const _0x408927=_0x3a6a40['plugins']['get']('TrackChanges'),_0x132c9b=_0x3a6a40['plugins']['get']('Users'),_0x123d27=function(_0x46070e,_0x528278){const _0x248315={};if(!_0x46070e['length']||!_0x528278['length'])return _0x248315;for(const {id:_0x302512,createdAt:_0x224a4e,authorId:_0x1a7799,attributes:_0x4055e6}of _0x46070e){const _0x4a4213=_0x4055e6&&_0x4055e6['@external'],_0x1b4a0f=_0x4a4213?_0x4a4213['authorName']:_0x528278['get'](_0x1a7799)['name'];_0x248315[_0x302512]={'author':_0x1b4a0f,'created':_0x224a4e};}return _0x248315;}(_0x408927['getSuggestions']({'toJSON':!0x0}),_0x132c9b['users']);Object['keys'](_0x123d27)['length']&&(_0x350aad['suggestions']=_0x123d27);}return(_0x350aad['suggestions']||_0x350aad['comments'])&&(_0x350aad['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone']),_0x350aad;}function m(_0x23ffe3,_0x1148ee={}){const _0x11dccc=_0x23ffe3['plugins']['has']('Users'),_0x2f3bb5=_0x23ffe3['plugins']['has']('CommentsRepository'),_0x4afeff=_0x23ffe3['plugins']['has']('TrackChanges'),_0x1899f9=_0x23ffe3['plugins']['has']('MergeFields'),_0x2c3828=_0x23ffe3['locale']['contentLanguage'],_0x474bc4=_0x1148ee,_0x466562={};if(_0x474bc4['document']=_0x474bc4['document']||{},_0x474bc4['document']['language']=_0x474bc4['document']['language']||_0x2c3828,_0x11dccc&&_0x2f3bb5){const _0x853144=function(_0x147f8e){const _0x33aa88=[];if(!_0x147f8e['length'])return _0x33aa88;for(const _0xa1c249 of _0x147f8e){const _0x29e28d=_0xa1c249['comments']['map'](_0x56aecb=>({'author':_0x56aecb['author']['name'],'content':_0x56aecb['content'],'created_at':_0x56aecb['createdAt']}));_0x33aa88['push']({'thread_id':_0xa1c249['id'],'is_resolved':_0xa1c249['isResolved'],'comments':_0x29e28d});}return _0x33aa88;}(_0x23ffe3['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));_0x853144['length']&&(_0x466562['comment_threads']=_0x853144);}if(_0x11dccc&&_0x4afeff){const _0x2ff269=_0x23ffe3['plugins']['get']('TrackChanges'),_0x16bd01=_0x23ffe3['plugins']['get']('Users'),_0xdba11c=function(_0x40f7b0,_0x2ac380){if(!_0x40f7b0['length']||!_0x2ac380['length'])return[];return _0x40f7b0['map'](({id:_0xc25f9c,createdAt:_0x169da6,authorId:_0x120c20,attributes:_0x25702a})=>{const _0x13753e=_0x25702a&&_0x25702a['@external'];return{'id':_0xc25f9c,'author':_0x13753e?_0x13753e['authorName']:_0x2ac380['get'](_0x120c20)['name'],'created_at':_0x169da6};});}(_0x2ff269['getSuggestions']({'toJSON':!0x0}),_0x16bd01['users']);_0xdba11c['length']&&(_0x466562['suggestions']=_0xdba11c);}if(_0x1899f9){const _0x2dfe27=_0x23ffe3['plugins']['get']('MergeFieldsEditing'),_0x1765e9=_0x2dfe27['previewMode'],{prefix:_0x433021,suffix:_0x2e67b0}=_0x23ffe3['config']['get']('mergeFields');if(_0x474bc4['merge_fields']={'prefix':_0x433021,'suffix':_0x2e67b0},'$labels'!==_0x1765e9){_0x474bc4['merge_fields']['data']={};const _0x23bf83='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88B8AAuUB8e2ujYwAAAAASUVORK5CYII=',_0xdcc58a='$defaultValues'===_0x1765e9?_0x2dfe27['getDefaultValues']():_0x2dfe27['getDataSetValues'](_0x1765e9,!0x0);for(const _0xa3c9fa of Object['entries'](_0xdcc58a)){const [_0x5d4932,_0x10a4b1]=_0xa3c9fa;'image'===_0x2dfe27['getMergeFieldType'](_0x5d4932)?_0x474bc4['merge_fields']['data'][_0x5d4932]=null!==_0x10a4b1?_0x10a4b1:_0x23bf83:_0x474bc4['merge_fields']['data'][_0x5d4932]=null!==_0x10a4b1?_0x10a4b1:_0x2dfe27['getLabel'](_0x5d4932)||_0x5d4932;}}}return(_0x466562['comment_threads']||_0x466562['suggestions'])&&(_0x474bc4['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone'],_0x474bc4['collaboration_features']=_0x466562),_0x474bc4;}function p(_0x36e8ed,_0x34c72c){const t=_0x36e8ed['t'];switch(_0x34c72c){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 _0x34c72c;}}const h=['orientation','margin_top','margin_right','margin_bottom','margin_left','format','header','footer','comments','suggestions'];class i extends _0x453227{constructor(_0x52b2df){super(_0x52b2df),this['set']('isBusy',!0x1),this['affectsData']=!0x1;}['refresh'](){this['isEnabled']=!this['isBusy'],this['value']=this['isBusy']?'pending':void 0x0;}['execute'](_0xbad0d={}){const _0x5292a3=this['editor'],_0x4a9f4f=_0xbad0d['version']||0x2,_0x247f11=0x1===_0x4a9f4f,_0x17dc73=_0xbad0d['converterUrl']||(_0x247f11?'https://docx-converter.cke-cs.com/v1/convert':'https://docx-converter.cke-cs.com/v2/convert/html-docx'),_0x565fb7=_0xbad0d['converterOptions']||{},_0x38baff=_0x5292a3['plugins']['get']('ExportWord'),_0x20c66c=_0xbad0d['token']||_0x38baff['_token'],_0x31f72b=!0x0===_0x565fb7['auto_pagination'],_0x4b19b3=_0xbad0d['dataCallback']||(_0x16e0b5=>_0x16e0b5['data']['get']({'pagination':_0x31f72b}));return 0x2===_0x4a9f4f&&function(_0x78c94f){for(const _0x51fedd of h)if(void 0x0!==_0x78c94f[_0x51fedd])return!0x0;return!0x1;}(_0x565fb7)&&_0x177c1e('export-word-v1-api-is-deprecated'),this['isBusy']=!0x0,this['refresh'](),_0x52a03(_0xbad0d['stylesheets']||['EDITOR_STYLES'])['then'](async _0x39f31d=>{_0x5292a3['ui']['ariaLiveAnnouncer']['announce'](p(_0x5292a3['locale'],'Word\x20document\x20export\x20started'));const _0x3e8856=await _0x4b19b3(_0x5292a3),_0x228f63={'html':'<div\x20class=\x22ck-content\x22\x20dir=\x22'+_0x5292a3['locale']['contentLanguageDirection']+'\x22>'+_0x3e8856+'</div>','css':_0x39f31d,[_0x247f11?'options':'config']:{..._0x565fb7,..._0x247f11?a(_0x5292a3,_0x565fb7):m(_0x5292a3,_0x565fb7)}},_0x1e0685={'method':'POST','headers':{'Content-Type':'application/json','Accept':'application/docx',..._0x20c66c?{'Authorization':_0x20c66c['value']}:null},'body':JSON['stringify'](_0x228f63)};return window['fetch'](_0x17dc73,_0x1e0685)['then'](_0x3d3bfd=>{if(0xc8!==_0x3d3bfd['status'])throw _0x3d3bfd;return _0x3d3bfd['blob']();})['then'](_0x30ab37=>{_0x5292a3['ui']['ariaLiveAnnouncer']['announce'](p(_0x5292a3['locale'],'Word\x20document\x20export\x20successful'));const _0x1ec245='function'==typeof _0xbad0d['fileName']?_0xbad0d['fileName']():_0xbad0d['fileName'];this['_downloadFile'](_0x30ab37,_0x1ec245||'document.docx');});})['catch'](_0x2aac5a=>{const _0x56cd07=_0x5292a3['plugins']['get']('Notification');throw _0x5292a3['ui']['ariaLiveAnnouncer']['announce'](p(_0x5292a3['locale'],'Word\x20document\x20export\x20failed'),{'politeness':'assertive'}),_0x56cd07['showWarning'](p(_0x5292a3['locale'],'An\x20error\x20occurred\x20while\x20generating\x20the\x20Word\x20file.')),_0x2aac5a;})['finally'](()=>{this['isBusy']=!0x1,this['refresh']();});}['_downloadFile'](_0x5a64d1,_0x45cb52){const _0x321eec=document['createElement']('a');_0x321eec['href']=window['URL']['createObjectURL'](_0x5a64d1),_0x321eec['download']=_0x45cb52,_0x321eec['click'](),_0x321eec['remove']();}}class o extends _0x5e39f0{static get['pluginName'](){return'ExportWordUI';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}['init'](){const _0x4b4f84=this['editor'];_0x4b4f84['ui']['componentFactory']['add']('exportWord',()=>{const _0x2ce607=_0x4b4f84['commands']['get']('exportWord'),_0x5b8343=this['_createButton'](_0x1e7b35);return _0x5b8343['set']({'tooltip':!0x0}),_0x5b8343['bind']('isOn')['to'](_0x2ce607,'isBusy'),_0x5b8343;}),_0x4b4f84['ui']['componentFactory']['add']('menuBar:exportWord',()=>this['_createButton'](_0x5793f3));}['_createButton'](_0x37cf13){const _0x4d947e=this['editor'],_0x585dac=_0x4d947e['config']['get']('exportWord')||{},_0x32177d=_0x4d947e['commands']['get']('exportWord'),_0x54d2c=new _0x37cf13(_0x4d947e['locale']),_0x4cd5c0=new _0x96fc8();return _0x54d2c['children']['add'](_0x4cd5c0),_0x4cd5c0['bind']('isVisible')['to'](_0x32177d,'isBusy'),_0x54d2c['iconView']['bind']('isVisible')['to'](_0x32177d,'isBusy',_0x271816=>!_0x271816),_0x54d2c['set']({'icon':_0x45fe21}),_0x54d2c['bind']('isEnabled')['to'](_0x32177d,'isEnabled'),_0x54d2c['bind']('label')['to'](_0x32177d,'isBusy',_0x5851c7=>p(_0x4d947e['locale'],_0x5851c7?'Exporting\x20Word\x20document':'Export\x20to\x20Word')),this['listenTo'](_0x54d2c,'execute',()=>{_0x4d947e['execute']('exportWord',_0x585dac),_0x4d947e['editing']['view']['focus']();}),_0x54d2c;}}class s extends _0x5e39f0{['_token'];static get['pluginName'](){return'ExportWord';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}static get['requires'](){return['CloudServices',_0x2497b1,o];}['init'](){const _0x317cd6=this['editor'],_0x5e1641=_0x317cd6['config']['get']('exportWord')||{};_0x317cd6['commands']['add']('exportWord',new i(_0x317cd6));const _0x3cc6ec=_0x317cd6['plugins']['get']('CloudServices');!0x1===_0x5e1641['tokenUrl']?this['_token']=null:_0x5e1641['tokenUrl']?_0x3cc6ec['registerTokenUrl'](_0x5e1641['tokenUrl'])['then'](_0x47a999=>{this['_token']=_0x47a999;}):this['_token']=_0x3cc6ec['token'];}}export{s as ExportWord};