UNPKG

@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-

269 lines (249 loc) 20.4 kB
let e,t,i,l,a,s,n,d,o,r=e=>e;function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var l in i)Object.prototype.hasOwnProperty.call(i,l)&&(e[l]=i[l])}return e},c.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 */import{D as h,c as p,N as u,C as b,M as g,g as m}from"./dbp-file-handling-lit-element.c8c0eb51.es.js";import{S as f,I as v,M as x,G as y,s as $,z as w,H as k,y as S,o as T,i as F,g as E,b as _,f as D,t as U,J as A}from"./notification.431b7aff.es.js";import"./_commonjsHelpers.e3705ba7.es.js";function z(e){let t={"application/pdf":[".pdf"],"application/zip":[".zip"]},i=[];return e.split(",").forEach((e=>{i.push(e),e.trim()in t&&(i=i.concat(t[e.trim()]))})),i.join(",")}class L extends(f(h)){constructor(){super(),this.context="",this._i18n=p(),this.lang=this._i18n.language,this.nextcloudAuthUrl="",this.nextcloudName="Nextcloud",this.nextcloudWebDavUrl="",this.nextcloudPath="",this.nextcloudFileURL="",this.nextcloudStoreSession=!1,this.dropArea=null,this.allowedMimeTypes="",this.enabledTargets="local",this.buttonLabel="",this.disabled=!1,this.decompressZip=!1,this._queueKey=0,this.activeTarget="local",this.isDialogOpen=!1,this.firstOpen=!0,this.nextcloudAuthInfo="",this.maxFileSize="",this.multipleFiles=Number.MAX_VALUE,this.initialFileHandlingState={target:"",path:""}}static get scopedElements(){return{"dbp-icon":v,"dbp-mini-spinner":x,"dbp-nextcloud-file-picker":u,"dbp-clipboard":b}}static get properties(){return c({},super.properties,{context:{type:String,attribute:"context"},lang:{type:String},allowedMimeTypes:{type:String,attribute:"allowed-mime-types"},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"},disabled:{type:Boolean},decompressZip:{type:Boolean,attribute:"decompress-zip"},activeTarget:{type:String,attribute:"active-target"},isDialogOpen:{type:Boolean,attribute:"dialog-open"},maxFileSize:{type:Number,attribute:"max-file-size"},multipleFiles:{type:Number,attribute:"number-of-files"},initialFileHandlingState:{type:Object,attribute:"initial-file-handling-state"}})}update(e){e.forEach(((e,t)=>{switch(t){case"lang":this._i18n.changeLanguage(this.lang);break;case"enabledTargets":this.hasEnabledSource(this.activeTarget)||(this.activeTarget=this.enabledTargets.split(",")[0]);break;case"isDialogOpen":this.isDialogOpen?this.openDialog():this.removeAttribute("dialog-open");break;case"initialFileHandlingState":this.firstOpen&&(this.nextcloudPath=this.initialFileHandlingState.path);break;case"activeTarget":"nextcloud"===this.activeTarget&&this.loadWebdavDirectory()}})),super.update(e)}connectedCallback(){super.connectedCallback(),this.updateComplete.then((()=>{if(this.dropArea=this._("#dropArea"),["dragenter","dragover","dragleave","drop"].forEach((e=>{this.dropArea.addEventListener(e,this.preventDefaults,!1)})),["dragenter","dragover"].forEach((e=>{this.dropArea.addEventListener(e,this.highlight.bind(this),!1)})),["dragleave","drop"].forEach((e=>{this.dropArea.addEventListener(e,this.unhighlight.bind(this),!1)})),this.dropArea.addEventListener("drop",this.handleDrop.bind(this),!1),this._("#fileElem").addEventListener("change",this.handleChange.bind(this,this._("#fileElem"))),this._("nav.modal-nav").addEventListener("scroll",this.handleScroll.bind(this)),this.enabledTargets.split(",").length>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 e=this._(".paddles");e&&e.classList.add("hidden")}}))}disconnectedCallback(){super.disconnectedCallback()}preventDefaults(e){e.preventDefault(),e.stopPropagation()}highlight(e){this.dropArea.classList.add("highlight")}unhighlight(e){this.dropArea.classList.remove("highlight")}handleDrop(e){if(this.disabled)return;let t=e.dataTransfer.files;this.handleFiles(t)}async handleChange(e){let t=e;0!==t.files.length&&(await this.handleFiles(t.files),t.value="")}async handleFiles(e){var t=this;let i=e.length;await y(e,(async function(e,l){0!==e.size?t.checkSize(e)&&(!t.decompressZip||"application/zip"!==e.type&&"application/x-zip-compressed"!==e.type?t.allowedMimeTypes&&!t.checkFileType(e)||await t.sendFileEvent(e,i):await y(await t.decompressZIP(e),((e,l,a)=>{i=l===a.length-1?i:i+1,t.sendFileEvent(e,i)}))):console.log("file '"+e.name+"' has size=0 and is denied!")}));const l=new CustomEvent("dbp-file-source-file-upload-finished",{detail:{count:i},bubbles:!0,composed:!0});this.dispatchEvent(l),this.closeDialog()}sendFileEvent(e,t){this.sendSource(),g.close(this._("#modal-picker"));const i=new CustomEvent("dbp-file-source-file-selected",{detail:{file:e,maxUpload:t},bubbles:!0,composed:!0});this.dispatchEvent(i)}sendSource(){let e={};e="nextcloud"===this.activeTarget?{target:this.activeTarget,path:this._("#nextcloud-file-picker").directoryPath}:{target:this.activeTarget},this.sendSetPropertyEvent("initial-file-handling-state",e)}checkFileType(e){const t=this._i18n,[i,l]=e.type.split("/"),a=this.allowedMimeTypes.split(",");let s=!0;return a.forEach((e=>{const[t,a]=e.split("/");s=s&&("*"!==t&&t!==i||"*"!==a&&a!==l)})),!s||(console.log(`mime type ${e.type} of file '${e.name}' is not compatible with ${this.allowedMimeTypes}`),$({summary:t.t("file-source.mime-type-title"),body:t.t("file-source.mime-type-body"),type:"danger",timeout:5}),!1)}checkSize(e){const t=this._i18n;return!(""!==this.maxFileSize&&1e3*this.maxFileSize<=e.size)||($({summary:t.t("file-source.too-big-file-title"),body:t.t("file-source.too-big-file-body",{size:w(1e3*this.maxFileSize,!0)}),type:"danger",timeout:5}),!1)}hasEnabledSource(e){return this.enabledTargets.split(",").includes(e)}async decompressZIP(e){var t=this;let i=(await import("./jszip.16927ca7.es.js").then((function(e){return e.j}))).default,l=[];if(await i.loadAsync(e).then((async function(i){await k(i.files,(async function(i){i.dir||await i.async("blob").then((async function(e){const a=await A(e),s=new File([e],i.name,{type:a});t.checkFileType(s)&&l.push(s)}),(t=>{console.error("Decompressing of file in "+e.name+" failed: "+t.message)}))}))}),(function(t){console.error("Loading of "+e.name+" failed: "+t.message)})),0===l.length){const e=this._i18n;console.error("ZIP file does not contain any files of "+this.allowedMimeTypes),$({summary:e.t("file-source.no-usable-files-in-zip"),body:e.t("file-source.no-usable-files-hint")+this.allowedMimeTypes,type:"danger",timeout:0})}return l}async sendFinishedEvent(e,t,i=!1){if(void 0===e)return;let l={fileName:t.name,status:e.status,json:{"hydra:description":""}};try{await e.json().then((e=>{l.json=e}))}catch(e){}i&&(l.file=t);const a=new CustomEvent("dbp-file-source-file-finished",{detail:l,bubbles:!0,composed:!0});this.dispatchEvent(a)}loadWebdavDirectory(){const e=this._("#nextcloud-file-picker");e&&e.checkLocalStorage().then((t=>{null!==e.webDavClient&&e.loadDirectory(e.directoryPath)}))}openDialog(){this.enabledTargets.includes("nextcloud")&&this.loadWebdavDirectory(),this.enabledTargets.includes("clipboard")&&this._("#clipboard-file-picker")&&this._("#clipboard-file-picker").generateClipboardTable();const e=this._("#modal-picker");if(e&&g.show(e,{disableScroll:!0,onClose:e=>{this.isDialogOpen=!1;const t=this._("#nextcloud-file-picker");t&&(t.selectAllButton=!0)}}),""!==this.initialFileHandlingState.target&&void 0!==this.initialFileHandlingState.target&&this.firstOpen){this.activeDestination=this.initialFileHandlingState.target,this.nextcloudPath=this.initialFileHandlingState.path;const e=this._("#nextcloud-file-picker");e&&null!==e.webDavClient&&e.loadDirectory(this.initialFileHandlingState.path),this.firstOpen=!1}}closeDialog(){if(this.sendSource(),this.enabledTargets.includes("nextcloud")){const e=this._("#nextcloud-file-picker");e&&e.tabulatorTable&&(e.tabulatorTable.deselectRow(),e._("#select_all")&&(e._("#select_all").checked=!1))}if(this.enabledTargets.includes("clipboard")){const e=this._("#clipboard-file-picker");e&&e.tabulatorTable&&(e.numberOfSelectedFiles=0,e.tabulatorTable.deselectRow(),e._("#select_all")&&(e._("#select_all").checked=!1))}g.close(this._("#modal-picker"))}getClipboardHtml(){return this.enabledTargets.includes("clipboard")?S(e||(e=r` <dbp-clipboard id="clipboard-file-picker" mode="file-source" subscribe="clipboard-files:clipboard-files,store-nextcloud-session" lang="${0}" auth-url="${0}" enabled-targets="${0}" nextcloud-auth-url="${0}" nextcloud-web-dav-url="${0}" nextcloud-name="${0}" nextcloud-file-url="${0}" allowed-mime-types="${0}" @dbp-clipboard-file-picker-file-downloaded="${0}"></dbp-clipboard> `),this.lang,this.nextcloudAuthUrl,this.enabledTargets,this.nextcloudAuthUrl,this.nextcloudWebDavUrl,this.nextcloudName,this.nextcloudFileURL,this.allowedMimeTypes,(e=>{this.sendFileEvent(e.detail.file,e.detail.maxUpload)})):S(t||(t=r``))}getNextcloudHtml(){return this.enabledTargets.includes("nextcloud")&&""!==this.nextcloudWebDavUrl&&""!==this.nextcloudAuthUrl?S(i||(i=r` <dbp-nextcloud-file-picker id="nextcloud-file-picker" class="${0}" ?disabled="${0}" lang="${0}" subscribe="html-overrides,auth" auth-url="${0}" web-dav-url="${0}" nextcloud-name="${0}" nextcloud-file-url="${0}" ?store-nextcloud-session="${0}" auth-info="${0}" allowed-mime-types="${0}" max-selected-items="${0}" @dbp-nextcloud-file-picker-file-downloaded="${0}"></dbp-nextcloud-file-picker> `),T({hidden:""===this.nextcloudWebDavUrl||""===this.nextcloudAuthUrl}),this.disabled,this.lang,this.nextcloudAuthUrl,this.nextcloudWebDavUrl,this.nextcloudName,this.nextcloudFileURL,this.nextcloudStoreSession,this.nextcloudAuthInfo,this.allowedMimeTypes,this.multipleFiles,(e=>{this.sendFileEvent(e.detail.file,e.detail.maxUpload)})):S(l||(l=r``))}static get styles(){return F(a||(a=r` ${0} ${0} ${0} ${0} ${0} p { margin-top: 0; } .block { margin-bottom: 10px; } #dropArea { border: var( --dbp-border, var(--FUBorderWidth, 2px) var(--FUBorderStyle, dashed) var(--FUBBorderColor, black) ); border-style: var(--FUBorderStyle, dashed); border-radius: var(--FUBorderRadius, var(--dbp-border-radius, 0)); border-width: var(--FUBorderWidth, 2px); width: auto; margin: var(--FUMargin, 0px); padding: var(--FUPadding, 20px); flex-grow: 1; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; } #dropArea.highlight { border-color: var(--FUBorderColorHighlight, purple); } #clipboard-file-picker { 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) { #dropArea { height: 100%; } } @media only screen and (orientation: portrait) and (max-width: 340px) { .paddles { display: inherit; } .paddles.hidden { display: none } } `),E(),_(),D(),U(),m())}render(){const e=this._i18n;let t=this.allowedMimeTypes;this.decompressZip&&""!==this.allowedMimeTypes&&(t+=",application/zip,application/x-zip-compressed");let i=S(s||(s=r``));return i=this.multipleFiles>1||!0===this.multipleFiles?S(n||(n=r` <input ?disabled="${0}" type="file" id="fileElem" multiple accept="${0}" name="file" /> `),this.disabled,z(t)):S(d||(d=r` <input ?disabled="${0}" type="file" id="fileElem" accept="${0}" name="file" /> `),this.disabled,z(t)),S(o||(o=r` <!-- <button class="button" ?disabled="${0}" @click="${0}">${0}</button> --> <div class="modal micromodal-slide" id="modal-picker" aria-hidden="true"> <div class="modal-overlay" tabindex="-1" data-micromodal-close> <div class="modal-container" role="dialog" aria-modal="true" aria-labelledby="modal-picker-title"> <div class="nav-wrapper modal-nav"> <nav class="modal-nav"> <div title="${0}" @click="${0}" class="${0}"> <dbp-icon class="nav-icon" name="laptop"></dbp-icon> <p>${0}</p> </div> <div title="Nextcloud" @click="${0}" class="${0}"> <dbp-icon class="nav-icon" name="cloud"></dbp-icon> <p>${0}</p> </div> <div title="${0}" @click="${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" @click="${0}"> <dbp-icon 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="dropArea"> <div class="block"> <p>${0}</p> </div> ${0} <label class="button is-primary" for="fileElem" ?disabled="${0}"> ${0} </label> </div> </div> <div class="source-main ${0}"> ${0} </div> <div class="source-main ${0}"> ${0} </div> </main> </div> </div> </div> `),this.disabled,(()=>{this.openDialog()}),e.t("file-source.open-menu"),e.t("file-source.nav-local"),(()=>{this.activeTarget="local"}),T({active:"local"===this.activeTarget,hidden:!this.hasEnabledSource("local")}),e.t("file-source.nav-local"),(()=>{this.activeTarget="nextcloud"}),T({active:"nextcloud"===this.activeTarget,hidden:!this.hasEnabledSource("nextcloud")||""===this.nextcloudWebDavUrl||""===this.nextcloudAuthUrl}),this.nextcloudName,e.t("file-source.clipboard"),(()=>{this.activeTarget="clipboard"}),T({active:"clipboard"===this.activeTarget,hidden:!this.hasEnabledSource("clipboard")}),e.t("file-source.clipboard"),e.t("file-source.modal-close"),(()=>{this.closeDialog()}),this.context,T({hidden:"local"!==this.activeTarget}),e.t("intro"),i,this.disabled,this.buttonLabel||e.t("upload-label"),T({hidden:"nextcloud"!==this.activeTarget||""===this.nextcloudWebDavUrl||""===this.nextcloudAuthUrl}),this.getNextcloudHtml(),T({hidden:"clipboard"!==this.activeTarget}),this.getClipboardHtml())}}export{L as FileSource}; //# sourceMappingURL=file-source.7dcfb7c2.es.js.map