@digital-blueprint/dispatch-app
Version:
[GitHub Repository](https://github.com/digital-blueprint/dispatch-app) | [npmjs package](https://www.npmjs.com/package/@digital-blueprint/dispatch-app) | [Unpkg CDN](https://unpkg.com/browse/@digital-blueprint/dispatch-app/) | [Dispatch Bundle](https://gi
248 lines (234 loc) • 21.3 kB
JavaScript
let e=e=>e,t,n,r,i,a,o;function s(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function c(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?s(Object(n),!0).forEach(function(t){l(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function l(e,t,n){return(t=u(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e){var t=d(e,`string`);return typeof t==`symbol`?t:t+``}function d(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@ must return a primitive value.`)}return(t===`string`?String:Number)(e)}
/*!
* License: LGPL-2.1-or-later
* Dependencies:
*
* @webcomponents/scoped-custom-element-registry: BSD-3-Clause
* @dbp-toolkit/app-shell: LGPL-2.1-or-later
* @dbp-toolkit/language-select: LGPL-2.1-or-later
* @dbp-toolkit/auth: LGPL-2.1-or-later
* lit-html: BSD-3-Clause
* @dbp-toolkit/notification: LGPL-2.1-or-later
* @dbp-toolkit/theme-switcher: LGPL-2.1-or-later
* universal-router: MIT
* @dbp-toolkit/matomo: LGPL-2.1-or-later
* @digital-blueprint/esign-app: LGPL-2.1-or-later
* exceljs: MIT
* fabric: MIT
* jspdf-autotable: MIT
* keycloak-js: Apache-2.0
* jszip: (MIT OR GPL-3.0-or-later)
* pdfjs-dist: Apache-2.0
* path2d: MIT
* fflate: MIT
* @babel/runtime: MIT
* iobuffer: MIT
* pako: (MIT AND Zlib)
* fast-png: MIT
* jspdf: MIT
* core-js: MIT
* performance-now: MIT
* raf: MIT
* rgbcolor: MIT OR SEE LICENSE IN FEEL-FREE.md
* svg-pathdata: MIT
* stackblur-canvas: MIT
* canvg: MIT
* dompurify: (MPL-2.0 OR Apache-2.0)
* html2canvas: MIT
* i18next: MIT
* @dbp-toolkit/common: LGPL-2.1-or-later
* @lit/reactive-element: BSD-3-Clause
* lit-element: BSD-3-Clause
* @open-wc/dedupe-mixin: MIT
* @open-wc/scoped-elements: MIT
* dialog-polyfill: BSD
* @dbp-toolkit/person-select: LGPL-2.1-or-later
* @dbp-toolkit/file-handling: LGPL-2.1-or-later
* @dbp-toolkit/tabulator-table: LGPL-2.1-or-later
* webdav: MIT
* tabulator-tables: MIT
* jose: MIT
* file-saver: MIT
*/
import{i as f,r as p,t as m}from"./chunk.Cdv43ikU.js";import{$ as h,C as g,D as _,F as v,G as y,I as b,N as x,P as S,Q as C,T as w,U as T,W as E,c as D,p as O,t as k}from"./dbp-lit-element.BfjLvJVI.js";import{a as A,i as j,l as M,n as N,o as P,r as F,t as I}from"./dbp-file-handling-lit-element.CduMSkeZ.js";var L=f(m((e,t)=>{(function(t,n){typeof define==`function`&&define.amd?define([],n):e===void 0?(n(),t.FileSaver={exports:{}}.exports):n()})(e,function(){function e(e,t){return t===void 0?t={autoBom:!1}:typeof t!=`object`&&(console.warn(`Deprecated: Expected third argument to be a object`),t={autoBom:!t}),t.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob([``,e],{type:e.type}):e}function n(e,t,n){var r=new XMLHttpRequest;r.open(`GET`,e),r.responseType=`blob`,r.onload=function(){s(r.response,t,n)},r.onerror=function(){console.error(`could not download file`)},r.send()}function r(e){var t=new XMLHttpRequest;t.open(`HEAD`,e,!1);try{t.send()}catch{}return 200<=t.status&&299>=t.status}function i(e){try{e.dispatchEvent(new MouseEvent(`click`))}catch{var t=document.createEvent(`MouseEvents`);t.initMouseEvent(`click`,!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),e.dispatchEvent(t)}}var a=typeof window==`object`&&window.window===window?window:typeof self==`object`&&self.self===self?self:typeof global==`object`&&global.global===global?global:void 0,o=a.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),s=a.saveAs||(typeof window!=`object`||window!==a?function(){}:`download`in HTMLAnchorElement.prototype&&!o?function(e,t,o){var s=a.URL||a.webkitURL,c=document.createElement(`a`);t=t||e.name||`download`,c.download=t,c.rel=`noopener`,typeof e==`string`?(c.href=e,c.origin===location.origin?i(c):r(c.href)?n(e,t,o):i(c,c.target=`_blank`)):(c.href=s.createObjectURL(e),setTimeout(function(){s.revokeObjectURL(c.href)},4e4),setTimeout(function(){i(c)},0))}:`msSaveOrOpenBlob`in navigator?function(t,a,o){if(a=a||t.name||`download`,typeof t!=`string`)navigator.msSaveOrOpenBlob(e(t,o),a);else if(r(t))n(t,a,o);else{var s=document.createElement(`a`);s.href=t,s.target=`_blank`,setTimeout(function(){i(s)})}}:function(e,t,r,i){if(i||=open(``,`_blank`),i&&(i.document.title=i.document.body.innerText=`downloading...`),typeof e==`string`)return n(e,t,r);var s=e.type===`application/octet-stream`,c=/constructor/i.test(a.HTMLElement)||a.safari,l=/CriOS\/[\d]+/.test(navigator.userAgent);if((l||s&&c||o)&&typeof FileReader<`u`){var u=new FileReader;u.onloadend=function(){var e=u.result;e=l?e:e.replace(/^data:[^;]*;/,`data:attachment/file;`),i?i.location.href=e:location=e,i=null},u.readAsDataURL(e)}else{var d=a.URL||a.webkitURL,f=d.createObjectURL(e);i?i.location=f:location.href=f,i=null,setTimeout(function(){d.revokeObjectURL(f)},4e4)}});a.saveAs=s.saveAs=s,t!==void 0&&(t.exports=s)})})(),1),R=class extends D(S(I),M){constructor(){super(),this.auth={},this.context=``,this.nextcloudAuthUrl=``,this.nextcloudWebDavUrl=``,this.nextcloudName=`Nextcloud`,this.nextcloudPath=``,this.nextcloudFileURL=``,this.nextcloudStoreSession=!1,this.buttonLabel=``,this.filename=`files.zip`,this.files=[],this.activeTarget=`local`,this.isDialogOpen=!1,this.enabledTargets=`local`,this.firstOpen=!0,this.fullsizeModal=!1,this.nextcloudAuthInfo=``,this.streamed=!1,this.sumContentLengths=-1,this.initialFileHandlingState={target:``,path:``}}static get scopedElements(){return{"dbp-icon":b,"dbp-mini-spinner":v,"dbp-nextcloud-file-picker":F,"dbp-clipboard":N}}static get properties(){return c(c({},super.properties),{},{context:{type:String,attribute:`context`},filename:{type:String},files:{type:Array,attribute:!1},enabledTargets:{type:String,attribute:`enabled-targets`},nextcloudAuthUrl:{type:String,attribute:`nextcloud-auth-url`},nextcloudWebDavUrl:{type:String,attribute:`nextcloud-web-dav-url`},nextcloudName:{type:String,attribute:`nextcloud-name`},nextcloudFileURL:{type:String,attribute:`nextcloud-file-url`},nextcloudAuthInfo:{type:String,attribute:`nextcloud-auth-info`},nextcloudStoreSession:{type:Boolean,attribute:`nextcloud-store-session`},buttonLabel:{type:String,attribute:`button-label`},isDialogOpen:{type:Boolean,attribute:!1},activeTarget:{type:String,attribute:`active-target`},firstOpen:{type:Boolean,attribute:!1},nextcloudPath:{type:String,attribute:!1},fullsizeModal:{type:Boolean,attribute:`fullsize-modal`},initialFileHandlingState:{type:Object,attribute:`initial-file-handling-state`},streamed:{type:Boolean,attribute:`streamed`},sumContentLengths:{type:Number,attribute:`content-length`},auth:{type:Object}})}connectedCallback(){if(super.connectedCallback(),this.streamed){let e=T(A,`stream-sw.js`);navigator.serviceWorker.register(e).then(e=>{window.navigator.userAgent.includes(`Firefox`)&&setInterval(function(){e.active.postMessage(`keep-alive`)},3e3)})}this.updateComplete.then(()=>{if(this._(`nav.modal-nav`).addEventListener(`scroll`,this.handleScroll.bind(this)),this.enabledTargets.split(`,`)>1)this._(`.right-paddle`).addEventListener(`click`,this.handleScrollRight.bind(this,this._(`nav.modal-nav`))),this._(`.left-paddle`).addEventListener(`click`,this.handleScrollLeft.bind(this,this._(`nav.modal-nav`)));else{let e=this._(`.paddles`);e&&e.classList.add(`hidden`)}})}handleStreamedDownload(){let e=document.createElement(`form`);e.style.display=`none`,e.action=T(A,`downloadZip/files.zip`),e.method=`POST`;let t=!1;if(this.sumContentLengths>=0){let t=document.createElement(`input`);t.name=`sumContentLengths`,t.value=this.sumContentLengths,e.appendChild(t)}if(this.auth!=null&&this.auth.token!=null){let t=document.createElement(`input`);t.name=`authorization`,t.value=`Bearer `+this.auth.token,e.appendChild(t)}if(this.files.forEach(n=>{if(!Object.hasOwn(n,`name`)||!Object.hasOwn(n,`url`)||n instanceof File){console.error(`Given object cannot be streamed!`),t=!0;return}let r=new URL(n.url),i=document.createElement(`input`);i.type=`url`,e.querySelector(`input[name="${n.name}"]`)!==null&&(n.name=E(n.name)+`-`+Math.random().toString(36).substring(7)+`.`+y(n.name)),i.name=n.name,i.value=r.toString(),e.appendChild(i)}),!t){for(this.appendChild(e),e.submit();e.hasChildNodes();)e.removeChild(e.firstChild);this.removeChild(e)}}async downloadCompressedFiles(){let e=(await import(`./jszip.Cxpk0N-m.js`).then(p(1))).default,t=new e,n=[];if(this.files.length===1){if(this.streamed)this.handleStreamedDownload();else{if(!(this.files[0]instanceof File)){console.error(`Given object cannot be saved!`);return}L.default.saveAs(this.files[0],this.files[0].filename)}this.closeDialog();return}if(this.streamed)this.handleStreamedDownload();else{let e=!1;if(this.files.forEach(r=>{if(!(r instanceof File)){console.error(`Given object cannot be saved!`),e=!0;return}let i=r.name;n.indexOf(i)!==-1&&(i=E(i)+`-`+Math.random().toString(36).substring(7)+`.`+y(i)),n.push(i),t.file(i,r)}),e)return;let r=await t.generateAsync({type:`blob`});L.default.saveAs(r,this.filename||`files.zip`)}this.closeDialog()}update(e){e.forEach((e,t)=>{switch(t){case`enabledTargets`:this.hasEnabledDestination(this.activeTargets)||(this.activeTargets=this.enabledTargets.split(`,`)[0]);break;case`files`:this.files.length!==0&&(this.openDialog(),this.enabledTargets.includes(`clipboard`)&&this._(`#clipboard-file-picker`)&&(this._(`#clipboard-file-picker`).filesToSave=[...this.files]));break;case`initialFileHandlingState`:this.firstOpen&&(this.nextcloudPath=this.initialFileHandlingState.path);break}}),super.update(e)}hasEnabledDestination(e){return this.enabledTargets.split(`,`).includes(e)}async uploadToNextcloud(e){let t=this._(`#nextcloud-file-picker`),n=[...this.files];await t.uploadFiles(n,e)}finishedFileUpload(e){let t=this._i18n;this.sendDestination(),P.close(this._(`#modal-picker`)),e.detail>0&&k({summary:t.t(`file-sink.upload-success-title`),body:t.t(`file-sink.upload-success-body`,{name:this.nextcloudName,count:e.detail}),type:`success`,timeout:5})}sendDestination(){let e={};e=this.activeTarget===`nextcloud`?{target:this.activeTarget,path:this._(`#nextcloud-file-picker`).directoryPath}:{target:this.activeTarget},this.sendSetPropertyEvent(`initial-file-handling-state`,e)}preventDefaults(e){e.preventDefault(),e.stopPropagation()}loadWebdavDirectory(){let e=this._(`#nextcloud-file-picker`);e&&e.checkLocalStorage().then(t=>{e.webDavClient!==null&&e.loadDirectory(e.directoryPath)})}openDialog(){this.enabledTargets.includes(`nextcloud`)&&this.loadWebdavDirectory(),this.enabledTargets.includes(`clipboard`)&&this._(`#clipboard-file-picker`)._(`#select_all`)&&(this._(`#clipboard-file-picker`)._(`#select_all`).checked=!1);let e=this._(`#modal-picker`);if(e&&P.show(e,{disableScroll:!0,onClose:e=>{this.isDialogOpen=!1;let t=new CustomEvent(`dbp-file-sink-dialog-closed`,{detail:{},bubbles:!0,composed:!0});this.dispatchEvent(t)}}),this.initialFileHandlingState.target!==``&&this.initialFileHandlingState.target!==void 0&&this.firstOpen){this.activeTarget=this.initialFileHandlingState.target,this.nextcloudPath=this.initialFileHandlingState.path;let e=this._(`#nextcloud-file-picker`);e&&e.webDavClient!==null&&e.loadDirectory(this.initialFileHandlingState.path),this.firstOpen=!1}this.isDialogOpen=!0}closeDialog(e){if(this.sendDestination(),this.enabledTargets.includes(`clipboard`)){let e=this._(`#clipboard-file-picker`);e&&e.tabulatorTable&&(e.tabulatorTable.deselectRow(),e.numberOfSelectedFiles=0,e._(`#select_all`)&&(e._(`#select_all`).checked=!1))}P.close(this._(`#modal-picker`)),this.isDialogOpen=!1}getClipboardHtml(){return this.enabledTargets.includes(`clipboard`)?C(t||=e`
<dbp-clipboard
id="clipboard-file-picker"
subscribe="clipboard-files:clipboard-files"
show-additional-buttons
mode="file-sink"
lang="${0}"
auth-url="${0}"
enabled-targets="${0}"
nextcloud-auth-url="${0}"
nextcloud-web-dav-url="${0}"
nextcloud-name="${0}"
nextcloud-file-url="${0}"
-clipboard-file-picker-file-uploaded="${0}"></dbp-clipboard>
`,this.lang,this.nextcloudAuthUrl,this.enabledTargets,this.nextcloudAuthUrl,this.nextcloudWebDavUrl,this.nextcloudName,this.nextcloudFileURL,e=>{this.closeDialog(e)}):C(n||=e``)}getNextcloudHtml(){let t=this._i18n;return this.enabledTargets.includes(`nextcloud`)&&this.nextcloudWebDavUrl!==``&&this.nextcloudAuthUrl!==``?C(r||=e`
<dbp-nextcloud-file-picker
id="nextcloud-file-picker"
class="${0}"
directories-only
max-selected-items="1"
select-button-text="${0}"
?disabled="${0}"
lang="${0}"
subscribe="html-overrides,auth"
auth-url="${0}"
web-dav-url="${0}"
nextcloud-name="${0}"
auth-info="${0}"
directory-path="${0}"
nextcloud-file-url="${0}"
?store-nextcloud-session="${0}"
-nextcloud-file-picker-file-uploaded="${0}"
-nextcloud-file-picker-file-uploaded-finished="${0}"></dbp-nextcloud-file-picker>
`,O({hidden:this.nextcloudWebDavUrl===``||this.nextcloudAuthUrl===``}),t.t(`file-sink.select-directory`),this.disabled,this.lang,this.nextcloudAuthUrl,this.nextcloudWebDavUrl,this.nextcloudName,this.nextcloudAuthInfo,this.nextcloudPath,this.nextcloudFileURL,this.nextcloudStoreSession,e=>{this.uploadToNextcloud(e.detail)},e=>{this.finishedFileUpload(e)}):C(i||=e``)}static get styles(){return h(a||=e`
${0}
${0}
${0}
${0}
${0}
.modal-container-full-size {
min-width: 100%;
min-height: 100%;
}
#zip-download-block {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.block {
margin-bottom: 10px;
}
#clipboard-file-sink {
width: 100%;
height: 100%;
}
.paddle {
position: absolute;
top: 0px;
padding: 0px 5px;
box-sizing: content-box;
height: 100%;
}
.paddle::before {
background-color: var(--dbp-background);
opacity: 0.8;
content: '';
width: 100%;
height: 100%;
position: absolute;
left: 0;
}
.right-paddle {
right: 0px;
}
.left-paddle {
left: 0px;
}
.nav-wrapper {
position: relative;
display: block;
overflow-x: auto;
border: none;
}
.paddles {
display: none;
}
.modal-nav {
height: 100%;
}
only screen and (orientation: portrait) and (max-width: 768px) {
.paddles {
display: inherit;
}
}
`,x(),w(),g(),_(),j())}render(){let t=this._i18n;return C(o||=e`
<div class="modal micromodal-slide" id="modal-picker" aria-hidden="true">
<div class="modal-overlay" tabindex="-1">
<div
class="modal-container ${0}"
role="dialog"
aria-modal="true"
aria-labelledby="modal-picker-title">
<div class="nav-wrapper modal-nav">
<nav class="modal-nav">
<div
title="${0}"
="${0}"
class="${0}">
<dbp-icon class="nav-icon" name="laptop"></dbp-icon>
<p>${0}</p>
</div>
<div
title="${0}"
="${0}"
class="${0}">
<dbp-icon class="nav-icon" name="cloud"></dbp-icon>
<p>${0}</p>
</div>
<div
title="${0}"
="${0}"
class="${0}">
<dbp-icon class="nav-icon" name="clipboard"></dbp-icon>
<p>${0}</p>
</div>
</nav>
<div class="paddles">
<dbp-icon
class="left-paddle paddle hidden"
name="chevron-left"
class="close-icon"></dbp-icon>
<dbp-icon
class="right-paddle paddle"
name="chevron-right"
class="close-icon"></dbp-icon>
</div>
</div>
<div class="modal-header">
<button
title="${0}"
class="modal-close"
aria-label="Close modal"
="${0}">
<dbp-icon
title="${0}"
name="close"
class="close-icon"></dbp-icon>
</button>
<p class="modal-context">${0}</p>
</div>
<main class="modal-content" id="modal-picker-content">
<div
class="source-main ${0}">
<div id="zip-download-block">
<div class="block">
${0}
</div>
<button
class="button is-primary"
?disabled="${0}"
="${0}">
${0}
</button>
</div>
</div>
<div
class="source-main ${0}">
${0}
</div>
<div
class="source-main ${0}">
${0}
</div>
</main>
</div>
</div>
</div>
`,O({"modal-container-full-size":this.fullsizeModal}),t.t(`file-sink.nav-local`),()=>{this.activeTarget=`local`},O({active:this.activeTarget===`local`,hidden:!this.hasEnabledDestination(`local`)}),t.t(`file-source.nav-local`),this.nextcloudName,()=>{this.activeTarget=`nextcloud`,this.loadWebdavDirectory()},O({active:this.activeTarget===`nextcloud`,hidden:!this.hasEnabledDestination(`nextcloud`)||this.nextcloudWebDavUrl===``||this.nextcloudAuthUrl===``}),this.nextcloudName,t.t(`file-sink.clipboard`),()=>{this.activeTarget=`clipboard`},O({active:this.activeTarget===`clipboard`,hidden:!this.hasEnabledDestination(`clipboard`)}),t.t(`file-sink.clipboard`),t.t(`file-sink.modal-close`),()=>{this.closeDialog()},t.t(`file-sink.modal-close`),this.context,O({hidden:this.activeTarget!==`local`}),t.t(`file-sink.local-intro`,{count:this.files.length}),this.disabled,()=>{this.downloadCompressedFiles()},t.t(`file-sink.local-button`,{count:this.files.length}),O({hidden:this.activeTarget!==`nextcloud`||this.nextcloudWebDavUrl===``||this.nextcloudAuthUrl===``}),this.getNextcloudHtml(),O({hidden:this.activeTarget!==`clipboard`}),this.getClipboardHtml())}};export{R as t};
//# sourceMappingURL=file-sink.CHWfTL87.js.map