UNPKG

@ckeditor/ckeditor5-export-word

Version:

Export to Word feature for CKEditor 5.

23 lines • 12.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 _0x5a1328,Plugin as _0x58b504}from'@ckeditor/ckeditor5-core/dist/index.js';import{ButtonView as _0x1ae9bc,MenuBarMenuListItemButtonView as _0x389b07,SpinnerView as _0x5ceca1,Notification as _0x28e40f}from'@ckeditor/ckeditor5-ui/dist/index.js';import{logWarning as _0x64193b,collectStylesheets as _0x8d27c9}from'@ckeditor/ckeditor5-utils/dist/index.js';function a(_0x5ef4ab,_0x3bcbc9={}){const _0x15f317=_0x5ef4ab['plugins']['has']('Users'),_0xea85c7=_0x5ef4ab['plugins']['has']('CommentsRepository'),_0x4adfa9=_0x5ef4ab['plugins']['has']('TrackChanges'),_0x313512=_0x3bcbc9;if(_0x15f317&&_0xea85c7){const _0x5439f1=function(_0x380473){const _0x2cc866={};if(!_0x380473['length'])return _0x2cc866;for(const _0x14324b of _0x380473)_0x14324b['comments']['map'](_0x2b802a=>{void 0x0===_0x2cc866[_0x14324b['id']]&&(_0x2cc866[_0x14324b['id']]=[]),_0x2cc866[_0x14324b['id']]['push']({'author':_0x2b802a['author']['name'],'content':_0x2b802a['content'],'created':_0x2b802a['createdAt'],'is_resolved':_0x14324b['isResolved']});});return _0x2cc866;}(_0x5ef4ab['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));Object['keys'](_0x5439f1)['length']&&(_0x313512['comments']=_0x5439f1);}if(_0x15f317&&_0x4adfa9){const _0x32d6d7=_0x5ef4ab['plugins']['get']('TrackChanges'),_0x2c036d=_0x5ef4ab['plugins']['get']('Users'),_0x13dc64=function(_0x10606b,_0x4ff63c){const _0x1e11cd={};if(!_0x10606b['length']||!_0x4ff63c['length'])return _0x1e11cd;for(const {id:_0x515f4e,createdAt:_0x482f8c,authorId:_0x4fc94d,attributes:_0x33745b}of _0x10606b){const _0x109108=_0x33745b&&_0x33745b['@external'],_0xae401e=_0x109108?_0x109108['authorName']:_0x4ff63c['get'](_0x4fc94d)['name'];_0x1e11cd[_0x515f4e]={'author':_0xae401e,'created':_0x482f8c};}return _0x1e11cd;}(_0x32d6d7['getSuggestions']({'toJSON':!0x0}),_0x2c036d['users']);Object['keys'](_0x13dc64)['length']&&(_0x313512['suggestions']=_0x13dc64);}return(_0x313512['suggestions']||_0x313512['comments'])&&(_0x313512['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone']),_0x313512;}function m(_0x27ff25,_0x25b83d={}){const _0x2ef968=_0x27ff25['plugins']['has']('Users'),_0xd1b651=_0x27ff25['plugins']['has']('CommentsRepository'),_0x266b8b=_0x27ff25['plugins']['has']('TrackChanges'),_0x50cbe2=_0x27ff25['plugins']['has']('MergeFields'),_0x4feb07=_0x27ff25['locale']['contentLanguage'],_0x76149d=_0x25b83d,_0xea6e6a={};if(_0x76149d['document']=_0x76149d['document']||{},_0x76149d['document']['language']=_0x76149d['document']['language']||_0x4feb07,_0x2ef968&&_0xd1b651){const _0x460913=function(_0x4c2a46){const _0x5f22d8=[];if(!_0x4c2a46['length'])return _0x5f22d8;for(const _0x2a5524 of _0x4c2a46){const _0x40b962=_0x2a5524['comments']['map'](_0x546d34=>({'author':_0x546d34['author']['name'],'content':_0x546d34['content'],'created_at':_0x546d34['createdAt']}));_0x5f22d8['push']({'thread_id':_0x2a5524['id'],'is_resolved':_0x2a5524['isResolved'],'comments':_0x40b962});}return _0x5f22d8;}(_0x27ff25['plugins']['get']('CommentsRepository')['getCommentThreads']({'skipNotAttached':!0x0,'skipEmpty':!0x0}));_0x460913['length']&&(_0xea6e6a['comment_threads']=_0x460913);}if(_0x2ef968&&_0x266b8b){const _0x3d75d0=_0x27ff25['plugins']['get']('TrackChanges'),_0x4b60c2=_0x27ff25['plugins']['get']('Users'),_0x577fa7=function(_0x5bceb6,_0x2486f1){if(!_0x5bceb6['length']||!_0x2486f1['length'])return[];return _0x5bceb6['map'](({id:_0x1c921f,createdAt:_0x311dae,authorId:_0x30dc7f,attributes:_0x32c7e7})=>{const _0x34a302=_0x32c7e7&&_0x32c7e7['@external'];return{'id':_0x1c921f,'author':_0x34a302?_0x34a302['authorName']:_0x2486f1['get'](_0x30dc7f)['name'],'created_at':_0x311dae};});}(_0x3d75d0['getSuggestions']({'toJSON':!0x0}),_0x4b60c2['users']);_0x577fa7['length']&&(_0xea6e6a['suggestions']=_0x577fa7);}if(_0x50cbe2){const _0x3718fa=_0x27ff25['plugins']['get']('MergeFieldsEditing'),_0x244f9b=_0x3718fa['previewMode'],{prefix:_0x3161bc,suffix:_0x1aadf5}=_0x27ff25['config']['get']('mergeFields');if(_0x76149d['merge_fields']={'prefix':_0x3161bc,'suffix':_0x1aadf5},'$labels'!==_0x244f9b){_0x76149d['merge_fields']['data']={};const _0x4b817f='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88B8AAuUB8e2ujYwAAAAASUVORK5CYII=',_0x41999b='$defaultValues'===_0x244f9b?_0x3718fa['getDefaultValues']():_0x3718fa['getDataSetValues'](_0x244f9b,!0x0);for(const _0x1ecc2f of Object['entries'](_0x41999b)){const [_0x563f29,_0x239bce]=_0x1ecc2f;'image'===_0x3718fa['getMergeFieldType'](_0x563f29)?_0x76149d['merge_fields']['data'][_0x563f29]=null!==_0x239bce?_0x239bce:_0x4b817f:_0x76149d['merge_fields']['data'][_0x563f29]=null!==_0x239bce?_0x239bce:_0x3718fa['getLabel'](_0x563f29)||_0x563f29;}}}return(_0xea6e6a['comment_threads']||_0xea6e6a['suggestions'])&&(_0x76149d['timezone']=new Intl['DateTimeFormat']()['resolvedOptions']()['timeZone'],_0x76149d['collaboration_features']=_0xea6e6a),_0x76149d;}function p(_0x321dab,_0xd9f252){const t=_0x321dab['t'];switch(_0xd9f252){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 _0xd9f252;}}const h=['orientation','margin_top','margin_right','margin_bottom','margin_left','format','header','footer','comments','suggestions'];class e extends _0x5a1328{constructor(_0x354249){super(_0x354249),this['set']('isBusy',!0x1),this['affectsData']=!0x1;}['refresh'](){this['isEnabled']=!this['isBusy'],this['value']=this['isBusy']?'pending':void 0x0;}['execute'](_0x4175ce={}){const _0x55cf28=this['editor'],_0x258418=_0x4175ce['version']||0x2,_0x1afb86=0x1===_0x258418,_0x485c5e=_0x4175ce['converterUrl']||(_0x1afb86?'https://docx-converter.cke-cs.com/v1/convert':'https://docx-converter.cke-cs.com/v2/convert/html-docx'),_0x189aa7=_0x4175ce['converterOptions']||{},_0x3f5bb5=_0x55cf28['plugins']['get']('ExportWord'),_0x3450bf=_0x4175ce['token']||_0x3f5bb5['_token'],_0x5c5e29=!0x0===_0x189aa7['auto_pagination'],_0x3ab5be=_0x4175ce['dataCallback']||(_0x1a6311=>_0x1a6311['data']['get']({'pagination':_0x5c5e29}));return 0x2===_0x258418&&function(_0x5a2818){for(const _0x3ba3e6 of h)if(void 0x0!==_0x5a2818[_0x3ba3e6])return!0x0;return!0x1;}(_0x189aa7)&&_0x64193b('export-word-v1-api-is-deprecated'),this['isBusy']=!0x0,this['refresh'](),_0x8d27c9(_0x4175ce['stylesheets']||['EDITOR_STYLES'])['then'](async _0xf403ef=>{_0x55cf28['ui']['ariaLiveAnnouncer']['announce'](p(_0x55cf28['locale'],'Word\x20document\x20export\x20started'));const _0xaff4e3=await _0x3ab5be(_0x55cf28),_0x2205ee={'html':'<div\x20class=\x22ck-content\x22\x20dir=\x22'+_0x55cf28['locale']['contentLanguageDirection']+'\x22>'+_0xaff4e3+'</div>','css':_0xf403ef,[_0x1afb86?'options':'config']:{..._0x189aa7,..._0x1afb86?a(_0x55cf28,_0x189aa7):m(_0x55cf28,_0x189aa7)}},_0x5f5930={'method':'POST','headers':{'Content-Type':'application/json','Accept':'application/docx',..._0x3450bf?{'Authorization':_0x3450bf['value']}:null},'body':JSON['stringify'](_0x2205ee)};return window['fetch'](_0x485c5e,_0x5f5930)['then'](_0x34afa1=>{if(0xc8!==_0x34afa1['status'])throw _0x34afa1;return _0x34afa1['blob']();})['then'](_0x25e017=>{_0x55cf28['ui']['ariaLiveAnnouncer']['announce'](p(_0x55cf28['locale'],'Word\x20document\x20export\x20successful'));const _0x4d49f4='function'==typeof _0x4175ce['fileName']?_0x4175ce['fileName']():_0x4175ce['fileName'];this['_downloadFile'](_0x25e017,_0x4d49f4||'document.docx');});})['catch'](_0x86de83=>{const _0x2290d3=_0x55cf28['plugins']['get']('Notification');throw _0x55cf28['ui']['ariaLiveAnnouncer']['announce'](p(_0x55cf28['locale'],'Word\x20document\x20export\x20failed'),{'politeness':'assertive'}),_0x2290d3['showWarning'](p(_0x55cf28['locale'],'An\x20error\x20occurred\x20while\x20generating\x20the\x20Word\x20file.')),_0x86de83;})['finally'](()=>{this['isBusy']=!0x1,this['refresh']();});}['_downloadFile'](_0x496ee1,_0x4a06b1){const _0x713c=document['createElement']('a');_0x713c['href']=window['URL']['createObjectURL'](_0x496ee1),_0x713c['download']=_0x4a06b1,_0x713c['click'](),_0x713c['remove']();}}class o extends _0x58b504{static get['pluginName'](){return'ExportWordUI';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}['init'](){const _0x3e8a4a=this['editor'];_0x3e8a4a['ui']['componentFactory']['add']('exportWord',()=>{const _0x37ff02=_0x3e8a4a['commands']['get']('exportWord'),_0x49e186=this['_createButton'](_0x1ae9bc);return _0x49e186['set']({'tooltip':!0x0}),_0x49e186['bind']('isOn')['to'](_0x37ff02,'isBusy'),_0x49e186;}),_0x3e8a4a['ui']['componentFactory']['add']('menuBar:exportWord',()=>this['_createButton'](_0x389b07));}['_createButton'](_0x34a8d0){const _0x67dd7f=this['editor'],_0x447fb4=_0x67dd7f['config']['get']('exportWord')||{},_0x29abdf=_0x67dd7f['commands']['get']('exportWord'),_0x200d6e=new _0x34a8d0(_0x67dd7f['locale']),_0x22bc6e=new _0x5ceca1();return _0x200d6e['children']['add'](_0x22bc6e),_0x22bc6e['bind']('isVisible')['to'](_0x29abdf,'isBusy'),_0x200d6e['iconView']['bind']('isVisible')['to'](_0x29abdf,'isBusy',_0x1e5b6c=>!_0x1e5b6c),_0x200d6e['set']({'icon':'<svg\x20viewBox=\x220\x200\x2020\x2020\x22\x20xmlns=\x22http://www.w3.org/2000/svg\x22><path\x20d=\x22M17.826\x2016.843a.75.75\x200\x200\x200-1.152-.96L15.5\x2017.29V12H14v5.29l-1.174-1.408a.75.75\x200\x200\x200-1.152.96l2.346\x202.816a.95.95\x200\x200\x200\x201.46\x200l2.346-2.815Z\x22/><path\x20d=\x22m14\x200\x205\x204.5v9.741a2.737\x202.737\x200\x200\x200-1.5-.617V6.5h-5v-5h-8v3H3V0h11Zm0\x202v3h3.3L14\x202Z\x22/><path\x20d=\x22M3\x2017.5h6.746c.1.22.23.429.391.623l.731.877H3v-1.5Z\x22/><path\x20d=\x22M8.5\x206a1.5\x201.5\x200\x200\x201\x201.493\x201.356L10\x207.5v7a1.5\x201.5\x200\x200\x201-1.356\x201.493L8.5\x2016h-7a1.5\x201.5\x200\x200\x201-1.493-1.356L0\x2014.5v-7a1.5\x201.5\x200\x200\x201\x201.356-1.493L1.5\x206h7ZM7.483\x208.795l-.042.088-.986\x202.534-.947-2.528-.043-.092a.601.601\x200\x200\x200-1.042.008l-.042.093-.883\x202.465-.937-2.475-.042-.089a.6.6\x200\x200\x200-1.107.42l.027.093\x201.514\x204\x20.044.092a.6.6\x200\x200\x200\x201.041-.01l.041-.092.88-2.458.925\x202.467.046.096a.6.6\x200\x200\x200\x201.032\x200l.043-.09\x201.554-4\x20.028-.093a.6.6\x200\x200\x200-1.104-.43v.001Z\x22/></svg>\x0a'}),_0x200d6e['bind']('isEnabled')['to'](_0x29abdf,'isEnabled'),_0x200d6e['bind']('label')['to'](_0x29abdf,'isBusy',_0x1c863f=>p(_0x67dd7f['locale'],_0x1c863f?'Exporting\x20Word\x20document':'Export\x20to\x20Word')),this['listenTo'](_0x200d6e,'execute',()=>{_0x67dd7f['execute']('exportWord',_0x447fb4),_0x67dd7f['editing']['view']['focus']();}),_0x200d6e;}}class s extends _0x58b504{['_token'];static get['pluginName'](){return'ExportWord';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}static get['requires'](){return['CloudServices',_0x28e40f,o];}['init'](){const _0x473f25=this['editor'],_0x2fe99f=_0x473f25['config']['get']('exportWord')||{};_0x473f25['commands']['add']('exportWord',new e(_0x473f25));const _0x1d0795=_0x473f25['plugins']['get']('CloudServices');!0x1===_0x2fe99f['tokenUrl']?this['_token']=null:_0x2fe99f['tokenUrl']?_0x1d0795['registerTokenUrl'](_0x2fe99f['tokenUrl'])['then'](_0x1a177b=>{this['_token']=_0x1a177b;}):this['_token']=_0x1d0795['token'];}}export{s as ExportWord};