@dbp-topics/dispatch
Version:
[GitHub Repository](https://github.com/digital-blueprint/dispatch-frontend) | [npmjs package](https://www.npmjs.com/package/@dbp-topics/dispatch) | [Unpkg CDN](https://unpkg.com/browse/@dbp-topics/dispatch/) | [Dispatch Bundle](https://github.com/digital-
228 lines (213 loc) • 18.5 kB
JavaScript
let t,e,i,l,a,n,s=t=>t;function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var l in i)Object.prototype.hasOwnProperty.call(i,l)&&(t[l]=i[l])}return t},o.apply(this,arguments)}
/*!
* 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/common: LGPL-2.1-or-later
* @dbp-toolkit/auth: LGPL-2.1-or-later
* event-target-shim: MIT
* @dbp-toolkit/notification: LGPL-2.1-or-later
* @dbp-toolkit/theme-switcher: LGPL-2.1-or-later
* path-to-regexp: MIT
* universal-router: MIT
* generateUrls: MIT
* @dbp-toolkit/matomo: LGPL-2.1-or-later
* @tugraz/web-components: LGPL-2.1-or-later
* @babel/runtime: MIT
* i18next: MIT
* @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
* @popperjs/core: MIT
* tippy.js: MIT
* @dbp-toolkit/tooltip: LGPL-2.1-or-later
* @dbp-toolkit/person-select: LGPL-2.1-or-later
* @dbp-toolkit/file-handling: LGPL-2.1-or-later
* file-saver: MIT
*/import{D as d,c,N as r,C as h,M as u,g as p}from"./dbp-file-handling-lit-element.c8c0eb51.es.js";import{S as b,I as f,M as g,K as v,N as m,s as x,y,o as k,i as w,g as $,b as S,f as T,t as D}from"./notification.431b7aff.es.js";import{c as _}from"./_commonjsHelpers.e3705ba7.es.js";var U,A={};U={get exports(){return A},set exports(t){A=t}},function(){function t(t,e){return void 0===e?e={autoBom:!1}:"object"!=typeof e&&(console.warn("Deprecated: Expected third argument to be a object"),e={autoBom:!e}),e.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(t.type)?new Blob(["\ufeff",t],{type:t.type}):t}function e(t,e,i){var l=new XMLHttpRequest;l.open("GET",t),l.responseType="blob",l.onload=function(){s(l.response,e,i)},l.onerror=function(){console.error("could not download file")},l.send()}function i(t){var e=new XMLHttpRequest;e.open("HEAD",t,!1);try{e.send()}catch(t){}return 200<=e.status&&299>=e.status}function l(t){try{t.dispatchEvent(new MouseEvent("click"))}catch(i){var e=document.createEvent("MouseEvents");e.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),t.dispatchEvent(e)}}var a="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof _&&_.global===_?_:void 0,n=a.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),s=a.saveAs||("object"!=typeof window||window!==a?function(){}:"download"in HTMLAnchorElement.prototype&&!n?function(t,n,s){var o=a.URL||a.webkitURL,d=document.createElement("a");n=n||t.name||"download",d.download=n,d.rel="noopener","string"==typeof t?(d.href=t,d.origin===location.origin?l(d):i(d.href)?e(t,n,s):l(d,d.target="_blank")):(d.href=o.createObjectURL(t),setTimeout((function(){o.revokeObjectURL(d.href)}),4e4),setTimeout((function(){l(d)}),0))}:"msSaveOrOpenBlob"in navigator?function(a,n,s){if(n=n||a.name||"download","string"!=typeof a)navigator.msSaveOrOpenBlob(t(a,s),n);else if(i(a))e(a,n,s);else{var o=document.createElement("a");o.href=a,o.target="_blank",setTimeout((function(){l(o)}))}}:function(t,i,l,s){if((s=s||open("","_blank"))&&(s.document.title=s.document.body.innerText="downloading..."),"string"==typeof t)return e(t,i,l);var o="application/octet-stream"===t.type,d=/constructor/i.test(a.HTMLElement)||a.safari,c=/CriOS\/[\d]+/.test(navigator.userAgent);if((c||o&&d||n)&&"undefined"!=typeof FileReader){var r=new FileReader;r.onloadend=function(){var t=r.result;t=c?t:t.replace(/^data:[^;]*;/,"data:attachment/file;"),s?s.location.href=t:location=t,s=null},r.readAsDataURL(t)}else{var h=a.URL||a.webkitURL,u=h.createObjectURL(t);s?s.location=u:location.href=u,s=null,setTimeout((function(){h.revokeObjectURL(u)}),4e4)}});a.saveAs=s.saveAs=s,U.exports=s}();class L extends(b(d)){constructor(){super(),this.context="",this._i18n=c(),this.lang=this._i18n.language,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.initialFileHandlingState={target:"",path:""}}static get scopedElements(){return{"dbp-icon":f,"dbp-mini-spinner":g,"dbp-nextcloud-file-picker":r,"dbp-clipboard":h}}static get properties(){return o({},super.properties,{context:{type:String,attribute:"context"},lang:{type:String},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"}})}connectedCallback(){super.connectedCallback(),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{const t=this._(".paddles");t&&t.classList.add("hidden")}}))}async downloadCompressedFiles(){let t=new(0,(await import("./jszip.16927ca7.es.js").then((function(t){return t.j}))).default),e=[];if(1===this.files.length)return A.saveAs(this.files[0],this.files[0].filename),void this.closeDialog();this.files.forEach((i=>{let l=i.name;-1!==e.indexOf(l)&&(l=v(l)+"-"+Math.random().toString(36).substring(7)+"."+m(l)),e.push(l),t.file(l,i)}));let i=await t.generateAsync({type:"blob"});A.saveAs(i,this.filename||"files.zip"),this.closeDialog()}update(t){t.forEach(((t,e)=>{switch(e){case"lang":this._i18n.changeLanguage(this.lang);break;case"enabledTargets":this.hasEnabledDestination(this.activeTargets)||(this.activeTargets=this.enabledTargets.split(",")[0]);break;case"files":if(0!==this.files.length&&(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)}})),super.update(t)}hasEnabledDestination(t){return this.enabledTargets.split(",").includes(t)}async uploadToNextcloud(t){const e=this._("#nextcloud-file-picker"),i=[...this.files];await e.uploadFiles(i,t)}finishedFileUpload(t){const e=this._i18n;this.sendDestination(),u.close(this._("#modal-picker")),t.detail>0&&x({summary:e.t("file-sink.upload-success-title"),body:e.t("file-sink.upload-success-body",{name:this.nextcloudName,count:t.detail}),type:"success",timeout:5})}sendDestination(){let t={};t="nextcloud"===this.activeTarget?{target:this.activeTarget,path:this._("#nextcloud-file-picker").directoryPath}:{target:this.activeTarget},this.sendSetPropertyEvent("initial-file-handling-state",t)}preventDefaults(t){t.preventDefault(),t.stopPropagation()}loadWebdavDirectory(){const t=this._("#nextcloud-file-picker");t&&t.checkLocalStorage().then((e=>{null!==t.webDavClient&&t.loadDirectory(t.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);const t=this._("#modal-picker");if(t&&u.show(t,{disableScroll:!0,onClose:t=>{this.isDialogOpen=!1}}),""!==this.initialFileHandlingState.target&&void 0!==this.initialFileHandlingState.target&&this.firstOpen){this.activeTarget=this.initialFileHandlingState.target,this.nextcloudPath=this.initialFileHandlingState.path;const t=this._("#nextcloud-file-picker");t&&null!==t.webDavClient&&t.loadDirectory(this.initialFileHandlingState.path),this.firstOpen=!1}this.isDialogOpen=!0}closeDialog(t){if(this.sendDestination(),this.enabledTargets.includes("clipboard")){const t=this._("#clipboard-file-picker");t&&t.tabulatorTable&&(t.tabulatorTable.deselectRow(),t.numberOfSelectedFiles=0,t._("#select_all")&&(t._("#select_all").checked=!1))}u.close(this._("#modal-picker")),this.isDialogOpen=!1}getClipboardHtml(){return this.enabledTargets.includes("clipboard")?y(t||(t=s`
<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,(t=>{this.closeDialog(t)})):y(e||(e=s``))}getNextcloudHtml(){const t=this._i18n;return this.enabledTargets.includes("nextcloud")&&""!==this.nextcloudWebDavUrl&&""!==this.nextcloudAuthUrl?y(i||(i=s`
<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>
`),k({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,(t=>{this.uploadToNextcloud(t.detail)}),(t=>{this.finishedFileUpload(t)})):y(l||(l=s``))}static get styles(){return w(a||(a=s`
${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;
}
}
`),$(),S(),T(),D(),p())}render(){const t=this._i18n;return y(n||(n=s`
<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>
`),k({"modal-container-full-size":this.fullsizeModal}),t.t("file-sink.nav-local"),(()=>{this.activeTarget="local"}),k({active:"local"===this.activeTarget,hidden:!this.hasEnabledDestination("local")}),t.t("file-source.nav-local"),this.nextcloudName,(()=>{this.activeTarget="nextcloud",this.loadWebdavDirectory()}),k({active:"nextcloud"===this.activeTarget,hidden:!this.hasEnabledDestination("nextcloud")||""===this.nextcloudWebDavUrl||""===this.nextcloudAuthUrl}),this.nextcloudName,t.t("file-sink.clipboard"),(()=>{this.activeTarget="clipboard"}),k({active:"clipboard"===this.activeTarget,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,k({hidden:"local"!==this.activeTarget}),t.t("file-sink.local-intro",{count:this.files.length}),this.disabled,(()=>{this.downloadCompressedFiles()}),t.t("file-sink.local-button",{count:this.files.length}),k({hidden:"nextcloud"!==this.activeTarget||""===this.nextcloudWebDavUrl||""===this.nextcloudAuthUrl}),this.getNextcloudHtml(),k({hidden:"clipboard"!==this.activeTarget}),this.getClipboardHtml())}}export{L as FileSink};
//# sourceMappingURL=file-sink.a4f3cd03.es.js.map