@digital-blueprint/esign-app
Version:
[GitHub Repository](https://github.com/digital-blueprint/esign-app) | [npmjs package](https://www.npmjs.com/package/@digital-blueprint/esign-app) | [Unpkg CDN](https://unpkg.com/browse/@digital-blueprint/esign-app/) | [Esign Bundle](https://gitlab.tugraz.
254 lines (240 loc) • 20.2 kB
JavaScript
/*!
* 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
* @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
* @tugraz/web-components: 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-html: BSD-3-Clause
* lit-element: BSD-3-Clause
* @open-wc/dedupe-mixin: MIT
* @open-wc/scoped-elements: MIT
* dialog-polyfill: BSD
* @digital-blueprint/annotpdf: MIT
* @dbp-toolkit/pdf-viewer: LGPL-2.1-or-later
* @popperjs/core: MIT
* tippy.js: MIT
* @dbp-toolkit/tooltip: LGPL-2.1-or-later
* jquery: MIT
* select2: MIT
* @dbp-toolkit/resource-select: LGPL-2.1-or-later
* @dbp-toolkit/tabulator-table: LGPL-2.1-or-later
* @dbp-toolkit/file-handling: LGPL-2.1-or-later
* webdav: MIT
* tabulator-tables: MIT
* jose: MIT
* file-saver: MIT
*/
import{i as e,r as t,t as n}from"./chunk.RTniY5sO.js";import{A as r,B as i,C as a,J as o,M as s,V as c,Y as l,b as u,c as d,d as f,j as p,k as m,x as h,z as g}from"./dbp-lit-element.D0c52m5A.js";import{t as _}from"./notification.DW4NLT-r.js";import{a as v,i as y,l as b,n as x,o as S,r as C,t as w}from"./dbp-file-handling-lit-element.JMERQ6PV.js";var T=e(n((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),E=class extends d(r(w),b){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":s,"dbp-mini-spinner":p,"dbp-nextcloud-file-picker":C,"dbp-clipboard":x}}static get properties(){return{...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=g(v,`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=g(v,`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`,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.mYM3xYd_.js`).then(t(1))).default,n=new e,r=[];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}T.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(t=>{if(!(t instanceof File)){console.error(`Given object cannot be saved!`),e=!0;return}let a=t.name;r.indexOf(a)!==-1&&(a=i(a)+`-`+Math.random().toString(36).substring(7)+`.`+c(a)),r.push(a),n.file(a,t)}),e)return;let t=await n.generateAsync({type:`blob`});T.default.saveAs(t,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(),S.close(this._(`#modal-picker`)),e.detail>0&&_({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&&S.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))}S.close(this._(`#modal-picker`)),this.isDialogOpen=!1}getClipboardHtml(){return this.enabledTargets.includes(`clipboard`)?o`
<dbp-clipboard
id="clipboard-file-picker"
subscribe="clipboard-files:clipboard-files"
show-additional-buttons
mode="file-sink"
lang="${this.lang}"
auth-url="${this.nextcloudAuthUrl}"
enabled-targets="${this.enabledTargets}"
nextcloud-auth-url="${this.nextcloudAuthUrl}"
nextcloud-web-dav-url="${this.nextcloudWebDavUrl}"
nextcloud-name="${this.nextcloudName}"
nextcloud-file-url="${this.nextcloudFileURL}"
@dbp-clipboard-file-picker-file-uploaded="${e=>{this.closeDialog(e)}}"></dbp-clipboard>
`:o``}getNextcloudHtml(){let e=this._i18n;return this.enabledTargets.includes(`nextcloud`)&&this.nextcloudWebDavUrl!==``&&this.nextcloudAuthUrl!==``?o`
<dbp-nextcloud-file-picker
id="nextcloud-file-picker"
class="${f({hidden:this.nextcloudWebDavUrl===``||this.nextcloudAuthUrl===``})}"
directories-only
max-selected-items="1"
select-button-text="${e.t(`file-sink.select-directory`)}"
?disabled="${this.disabled}"
lang="${this.lang}"
subscribe="html-overrides,auth"
auth-url="${this.nextcloudAuthUrl}"
web-dav-url="${this.nextcloudWebDavUrl}"
nextcloud-name="${this.nextcloudName}"
auth-info="${this.nextcloudAuthInfo}"
directory-path="${this.nextcloudPath}"
nextcloud-file-url="${this.nextcloudFileURL}"
?store-nextcloud-session="${this.nextcloudStoreSession}"
@dbp-nextcloud-file-picker-file-uploaded="${e=>{this.uploadToNextcloud(e.detail)}}"
@dbp-nextcloud-file-picker-file-uploaded-finished="${e=>{this.finishedFileUpload(e)}}"></dbp-nextcloud-file-picker>
`:o``}static get styles(){return l`
${m()}
${h()}
${u()}
${a()}
${y()}
.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%;
}
@media only screen and (orientation: portrait) and (max-width: 768px) {
.paddles {
display: inherit;
}
}
`}render(){let e=this._i18n;return o`
<div class="modal micromodal-slide" id="modal-picker" aria-hidden="true">
<div class="modal-overlay" tabindex="-1">
<div
class="modal-container ${f({"modal-container-full-size":this.fullsizeModal})}"
role="dialog"
aria-modal="true"
aria-labelledby="modal-picker-title">
<div class="nav-wrapper modal-nav">
<nav class="modal-nav">
<div
title="${e.t(`file-sink.nav-local`)}"
@click="${()=>{this.activeTarget=`local`}}"
class="${f({active:this.activeTarget===`local`,hidden:!this.hasEnabledDestination(`local`)})}">
<dbp-icon class="nav-icon" name="laptop"></dbp-icon>
<p>${e.t(`file-source.nav-local`)}</p>
</div>
<div
title="${this.nextcloudName}"
@click="${()=>{this.activeTarget=`nextcloud`,this.loadWebdavDirectory()}}"
class="${f({active:this.activeTarget===`nextcloud`,hidden:!this.hasEnabledDestination(`nextcloud`)||this.nextcloudWebDavUrl===``||this.nextcloudAuthUrl===``})}">
<dbp-icon class="nav-icon" name="cloud"></dbp-icon>
<p>${this.nextcloudName}</p>
</div>
<div
title="${e.t(`file-sink.clipboard`)}"
@click="${()=>{this.activeTarget=`clipboard`}}"
class="${f({active:this.activeTarget===`clipboard`,hidden:!this.hasEnabledDestination(`clipboard`)})}">
<dbp-icon class="nav-icon" name="clipboard"></dbp-icon>
<p>${e.t(`file-sink.clipboard`)}</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="${e.t(`file-sink.modal-close`)}"
class="modal-close"
aria-label="Close modal"
@click="${()=>{this.closeDialog()}}">
<dbp-icon
title="${e.t(`file-sink.modal-close`)}"
name="close"
class="close-icon"></dbp-icon>
</button>
<p class="modal-context">${this.context}</p>
</div>
<main class="modal-content" id="modal-picker-content">
<div
class="source-main ${f({hidden:this.activeTarget!==`local`})}">
<div id="zip-download-block">
<div class="block">
${e.t(`file-sink.local-intro`,{count:this.files.length})}
</div>
<button
class="button is-primary"
?disabled="${this.disabled}"
@click="${()=>{this.downloadCompressedFiles()}}">
${e.t(`file-sink.local-button`,{count:this.files.length})}
</button>
</div>
</div>
<div
class="source-main ${f({hidden:this.activeTarget!==`nextcloud`||this.nextcloudWebDavUrl===``||this.nextcloudAuthUrl===``})}">
${this.getNextcloudHtml()}
</div>
<div
class="source-main ${f({hidden:this.activeTarget!==`clipboard`})}">
${this.getClipboardHtml()}
</div>
</main>
</div>
</div>
</div>
`}};export{E as t};
//# sourceMappingURL=file-sink.B_LBilwm.js.map