UNPKG

@ckeditor/ckeditor5-export-word

Version:

Export to Word feature for CKEditor 5.

23 lines • 12.1 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 _0x23acb0,Plugin as _0x1510d8}from'@ckeditor/ckeditor5-core/dist/index.js';import{ButtonView as _0x565c65,MenuBarMenuListItemButtonView as _0x1187e6,SpinnerView as _0x62e106,Notification as _0x14c3ec}from'@ckeditor/ckeditor5-ui/dist/index.js';import{logWarning as _0x480be7,collectStylesheets as _0x5e1197}from'@ckeditor/ckeditor5-utils/dist/index.js';import{IconExportWord as _0x27b1cb}from'@ckeditor/ckeditor5-icons/dist/index.js';function d(_0x14e907,_0x2edd7a={}){const _0x1b5ab8=_0x14e907['plugins']['has']('Users'),_0x1ff4ca=_0x14e907['plugins']['has']('CommentsRepository'),_0x477a10=_0x14e907['plugins']['has']('TrackChanges'),_0x4d45fa=_0x2edd7a;if(_0x1b5ab8&&_0x1ff4ca){const _0x27625a=f(_0x14e907['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));Object['keys'](_0x27625a)['length']&&(_0x4d45fa['comments']=_0x27625a);}if(_0x1b5ab8&&_0x477a10){const _0x3812e4=_0x14e907['plugins']['get']('TrackChanges'),_0x279135=_0x14e907['plugins']['get']('Users'),_0x6b21ad=g(_0x3812e4['getSuggestions']({'toJSON':!0x0}),_0x279135['users']);Object['keys'](_0x6b21ad)['length']&&(_0x4d45fa['suggestions']=_0x6b21ad);}return(_0x4d45fa['suggestions']||_0x4d45fa['comments'])&&(_0x4d45fa['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone']),_0x4d45fa;}function f(_0x334bb8){const _0x3e8ac1={};if(!_0x334bb8['length'])return _0x3e8ac1;for(const _0x522b1f of _0x334bb8)_0x522b1f['comments']['map'](_0x5592fb=>{void 0x0===_0x3e8ac1[_0x522b1f['id']]&&(_0x3e8ac1[_0x522b1f['id']]=[]),_0x3e8ac1[_0x522b1f['id']]['push']({'author':_0x5592fb['author']['name'],'content':_0x5592fb['content'],'created':_0x5592fb['createdAt'],'is_resolved':_0x522b1f['isResolved']});});return _0x3e8ac1;}function g(_0x31eb47,_0x488f58){const _0x2b9066={};if(!_0x31eb47['length']||!_0x488f58['length'])return _0x2b9066;for(const {id:_0x41ab55,createdAt:_0x107ecc,authorId:_0x6ea3dd,attributes:_0x435627}of _0x31eb47){const _0x5c6498=_0x435627&&_0x435627['@external'],_0x34d515=_0x5c6498?_0x5c6498['authorName']:_0x488f58['get'](_0x6ea3dd)['name'];_0x2b9066[_0x41ab55]={'author':_0x34d515,'created':_0x107ecc};}return _0x2b9066;}function a(_0x49e0ee,_0x1fd1e9={}){const _0x49bef8=_0x49e0ee['plugins']['has']('Users'),_0x18518d=_0x49e0ee['plugins']['has']('CommentsRepository'),_0x397f18=_0x49e0ee['plugins']['has']('TrackChanges'),_0x256ef8=_0x49e0ee['plugins']['has']('MergeFields'),_0x3cf454=_0x49e0ee['locale']['contentLanguage'],_0x40c343=_0x1fd1e9,_0x4e9b4d={};if(_0x40c343['document']=_0x40c343['document']||{},_0x40c343['document']['language']=_0x40c343['document']['language']||_0x3cf454,_0x49bef8&&_0x18518d){const _0x4beacb=h(_0x49e0ee['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));_0x4beacb['length']&&(_0x4e9b4d['comment_threads']=_0x4beacb);}if(_0x49bef8&&_0x397f18){const _0x1e8689=_0x49e0ee['plugins']['get']('TrackChanges'),_0x55af93=_0x49e0ee['plugins']['get']('Users'),_0x3fdd58=A(_0x1e8689['getSuggestions']({'toJSON':!0x0}),_0x55af93['users']);_0x3fdd58['length']&&(_0x4e9b4d['suggestions']=_0x3fdd58);}if(_0x256ef8){const _0xaa7873=_0x49e0ee['plugins']['get']('MergeFieldsEditing'),_0x63b545=_0xaa7873['previewMode'],{prefix:_0x4d4ba1,suffix:_0x4040b2}=_0x49e0ee['config']['get']('mergeFields');if(_0x40c343['merge_fields']={'prefix':_0x4d4ba1,'suffix':_0x4040b2},'$labels'!==_0x63b545){_0x40c343['merge_fields']['data']={};const _0xea6179='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88B8AAuUB8e2ujYwAAAAASUVORK5CYII=',_0x59a788='$defaultValues'===_0x63b545?_0xaa7873['getDefaultValues']():_0xaa7873['getDataSetValues'](_0x63b545,!0x0);for(const _0x59c3af of Object['entries'](_0x59a788)){const [_0x5e0072,_0x2dd060]=_0x59c3af;'image'===_0xaa7873['getMergeFieldType'](_0x5e0072)?_0x40c343['merge_fields']['data'][_0x5e0072]=null!==_0x2dd060?_0x2dd060:_0xea6179:_0x40c343['merge_fields']['data'][_0x5e0072]=null!==_0x2dd060?_0x2dd060:_0xaa7873['getLabel'](_0x5e0072)||_0x5e0072;}}}return(_0x4e9b4d['comment_threads']||_0x4e9b4d['suggestions'])&&(_0x40c343['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone'],_0x40c343['collaboration_features']=_0x4e9b4d),_0x40c343;}function h(_0x30605a){const _0x537ce2=[];if(!_0x30605a['length'])return _0x537ce2;for(const _0x23a818 of _0x30605a){const _0x2f8490=_0x23a818['comments']['map'](_0x50152f=>({'author':_0x50152f['author']['name'],'content':_0x50152f['content'],'created_at':_0x50152f['createdAt']}));_0x537ce2['push']({'thread_id':_0x23a818['id'],'is_resolved':_0x23a818['isResolved'],'comments':_0x2f8490});}return _0x537ce2;}function A(_0xb98ecb,_0x5aeb38){return _0xb98ecb['length']&&_0x5aeb38['length']?_0xb98ecb['map'](({id:_0x2d5127,createdAt:_0x57b33d,authorId:_0x7addfd,attributes:_0x2f10b7})=>{const _0x266a6c=_0x2f10b7&&_0x2f10b7['@external'];return{'id':_0x2d5127,'author':_0x266a6c?_0x266a6c['authorName']:_0x5aeb38['get'](_0x7addfd)['name'],'created_at':_0x57b33d};}):[];}function m(_0x39c047,_0xc98db1){const t=_0x39c047['t'];switch(_0xc98db1){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 _0xc98db1;}}const p=['orientation','margin_top','margin_right','margin_bottom','margin_left','format','header','footer','comments','suggestions'];class i extends _0x23acb0{constructor(_0x4c4de1){super(_0x4c4de1),this['set']('isBusy',!0x1),this['affectsData']=!0x1;}['refresh'](){this['isEnabled']=!this['isBusy'],this['value']=this['isBusy']?'pending':void 0x0;}['execute'](_0x444995={}){const _0x3a3370=this['editor'],_0x4dfe1f=_0x444995['version']||0x2,_0x1941c3=0x1===_0x4dfe1f,_0x443b06=_0x444995['converterUrl']||(_0x1941c3?'https://docx-converter.cke-cs.com/v1/convert':'https://docx-converter.cke-cs.com/v2/convert/html-docx'),_0x54faed=_0x444995['converterOptions']||{},_0x2034e2=_0x3a3370['plugins']['get']('ExportWord'),_0x108ebc=_0x444995['token']||_0x2034e2['_token'],_0x10d735=!0x0===_0x54faed['auto_pagination'],_0x5c7de9=_0x444995['dataCallback']||(_0x5160e2=>_0x5160e2['data']['get']({'pagination':_0x10d735}));return 0x2===_0x4dfe1f&&function(_0x3ffa97){for(const _0x10ebb1 of p)if(void 0x0!==_0x3ffa97[_0x10ebb1])return!0x0;return!0x1;}(_0x54faed)&&_0x480be7('export-word-v1-api-is-deprecated'),this['isBusy']=!0x0,this['refresh'](),_0x5e1197(_0x444995['stylesheets']||['EDITOR_STYLES'])['then'](async _0x36c6d3=>{_0x3a3370['ui']['ariaLiveAnnouncer']['announce'](m(_0x3a3370['locale'],'Word\x20document\x20export\x20started'));const _0x4ba291=await _0x5c7de9(_0x3a3370),_0x74a643={'html':'<div\x20class=\x22ck-content\x22\x20dir=\x22'+_0x3a3370['locale']['contentLanguageDirection']+'\x22>'+_0x4ba291+'</div>','css':_0x36c6d3,[_0x1941c3?'options':'config']:{..._0x54faed,..._0x1941c3?d(_0x3a3370,_0x54faed):a(_0x3a3370,_0x54faed)}},_0x197d05={'method':'POST','headers':{'Content-Type':'application/json','Accept':'application/docx',..._0x108ebc?{'Authorization':_0x108ebc['value']}:null},'body':JSON['stringify'](_0x74a643)};return window['fetch'](_0x443b06,_0x197d05)['then'](_0x214ddc=>{if(0xc8!==_0x214ddc['status'])throw _0x214ddc;return _0x214ddc['blob']();})['then'](_0x1cc04a=>{_0x3a3370['ui']['ariaLiveAnnouncer']['announce'](m(_0x3a3370['locale'],'Word\x20document\x20export\x20successful'));const _0x1abd01='function'==typeof _0x444995['fileName']?_0x444995['fileName']():_0x444995['fileName'];this['_downloadFile'](_0x1cc04a,_0x1abd01||'document.docx');});})['catch'](_0x2278fd=>{const _0x11ba20=_0x3a3370['plugins']['get']('Notification');throw _0x3a3370['ui']['ariaLiveAnnouncer']['announce'](m(_0x3a3370['locale'],'Word\x20document\x20export\x20failed'),{'politeness':'assertive'}),_0x11ba20['showWarning'](m(_0x3a3370['locale'],'An\x20error\x20occurred\x20while\x20generating\x20the\x20Word\x20file.')),_0x2278fd;})['finally'](()=>{this['isBusy']=!0x1,this['refresh']();});}['_downloadFile'](_0x2842c3,_0x350eea){const _0x3a686d=document['createElement']('a');_0x3a686d['href']=window['URL']['createObjectURL'](_0x2842c3),_0x3a686d['download']=_0x350eea,_0x3a686d['click'](),_0x3a686d['remove']();}}class e extends _0x1510d8{static get['pluginName'](){return'ExportWordUI';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}['init'](){const _0x1ffec7=this['editor'];_0x1ffec7['ui']['componentFactory']['add']('exportWord',()=>{const _0x426fc1=_0x1ffec7['commands']['get']('exportWord'),_0x19ce01=this['_createButton'](_0x565c65);return _0x19ce01['set']({'tooltip':!0x0}),_0x19ce01['bind']('isOn')['to'](_0x426fc1,'isBusy'),_0x19ce01;}),_0x1ffec7['ui']['componentFactory']['add']('menuBar:exportWord',()=>this['_createButton'](_0x1187e6));}['_createButton'](_0x2accad){const _0x15d257=this['editor'],_0x6a4bc1=_0x15d257['config']['get']('exportWord')||{},_0x5eb030=_0x15d257['commands']['get']('exportWord'),_0x4f66f5=new _0x2accad(_0x15d257['locale']),_0x182239=new _0x62e106();return _0x4f66f5['children']['add'](_0x182239),_0x182239['bind']('isVisible')['to'](_0x5eb030,'isBusy'),_0x4f66f5['iconView']['bind']('isVisible')['to'](_0x5eb030,'isBusy',_0x1b24e5=>!_0x1b24e5),_0x4f66f5['set']({'icon':_0x27b1cb}),_0x4f66f5['bind']('isEnabled')['to'](_0x5eb030,'isEnabled'),_0x4f66f5['bind']('label')['to'](_0x5eb030,'isBusy',_0x1c8259=>m(_0x15d257['locale'],_0x1c8259?'Exporting\x20Word\x20document':'Export\x20to\x20Word')),this['listenTo'](_0x4f66f5,'execute',()=>{_0x15d257['execute']('exportWord',_0x6a4bc1),_0x15d257['editing']['view']['focus']();}),_0x4f66f5;}}class E extends _0x1510d8{['_token'];static get['pluginName'](){return'ExportWord';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}static get['requires'](){return['CloudServices',_0x14c3ec,e];}['init'](){const _0x28cb23=this['editor'],_0x498593=_0x28cb23['config']['get']('exportWord')||{};_0x28cb23['commands']['add']('exportWord',new i(_0x28cb23));const _0x44715d=_0x28cb23['plugins']['get']('CloudServices');!0x1===_0x498593['tokenUrl']?this['_token']=null:_0x498593['tokenUrl']?_0x44715d['registerTokenUrl'](_0x498593['tokenUrl'])['then'](_0x4845b7=>{this['_token']=_0x4845b7;}):this['_token']=_0x44715d['token'];}}export{E as ExportWord,i as ExportWordCommand,f as _getExportWordComments,h as _getExportWordCommentsV2,d as _getExportWordConverterOptionsV1,a as _getExportWordConverterOptionsV2,g as _getExportWordSuggestions,A as _getExportWordSuggestionsV2};