UNPKG

@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

297 lines (280 loc) 22.4 kB
let e=e=>e,t,n,r,i,a,o,s,c,l;function u(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 d(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?u(Object(n),!0).forEach(function(t){f(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):u(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function f(e,t,n){return(t=p(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function p(e){var t=m(e,`string`);return typeof t==`symbol`?t:t+``}function m(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(`@@toPrimitive 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 */ import{r as h}from"./chunk.Cdv43ikU.js";import{$ as g,C as _,D as v,F as y,I as b,K as x,N as S,P as C,Q as w,R as T,T as E,c as D,nt as O,p as k,t as A,z as j}from"./dbp-lit-element.BfjLvJVI.js";import{i as M,l as N,n as P,o as F,r as I,t as L}from"./dbp-file-handling-lit-element.CduMSkeZ.js";function R(e){let t={"application/pdf":[`.pdf`],"application/zip":[`.zip`]},n=[];return e.split(`,`).forEach(e=>{n.push(e),e.trim()in t&&(n=n.concat(t[e.trim()]))}),n.join(`,`)}var z=class extends D(C(L),N){constructor(){super(),this.context=``,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":b,"dbp-mini-spinner":y,"dbp-nextcloud-file-picker":I,"dbp-clipboard":P}}static get properties(){return d(d({},super.properties),{},{context:{type:String,attribute:`context`},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`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`:this.activeTarget===`nextcloud`&&this.loadWebdavDirectory();break}}),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{let 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;t.files.length!==0&&(await this.handleFiles(t.files),t.value=``)}async handleFiles(e){var t=this;let n=this._i18n,r=e.length;await T(e,async function(e,i){if(e.size===0){console.log(`file '`+e.name+`' has size=0 and is denied!`),A({summary:n.t(`file-source.empty-file-error-title`),body:n.t(`file-source.empty-file-error-text`,{filename:e.name}),type:`danger`,timeout:10}),r--;return}if(!t.checkSize(e)){console.log(`file "${e.name}" has size ${e.size} which is too large and is denied!`),r--;return}if(t.decompressZip&&(e.type===`application/zip`||e.type===`application/x-zip-compressed`)){await T(await t.decompressZIP(e),(e,n,i)=>{r=n===i.length-1?r:r+1,t.sendFileEvent(e,r)});return}else if(t.allowedMimeTypes&&!t.checkFileType(e)){r--;return}await t.sendFileEvent(e,r)});let i=new CustomEvent(`dbp-file-source-file-upload-finished`,{detail:{count:r},bubbles:!0,composed:!0});this.dispatchEvent(i),this.closeDialog()}sendFileEvent(e,t){this.sendSource(),F.close(this._(`#modal-picker`));let n={file:e,maxUpload:t},r=new CustomEvent(`dbp-file-source-file-selected`,{detail:n,bubbles:!0,composed:!0});this.dispatchEvent(r)}sendSource(){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)}checkFileType(e){let t=this._i18n,[n,r]=e.type.split(`/`),i=this.allowedMimeTypes.split(`,`),a=!0;return i.forEach(e=>{let[t,i]=e.split(`/`);a&&=t!==`*`&&t!==n||i!==`*`&&i!==r}),a?(console.log(`mime type ${e.type} of file '${e.name}' is not compatible with ${this.allowedMimeTypes}`),A({summary:t.t(`file-source.mime-type-title`),body:t.t(`file-source.mime-type-body`),type:`danger`,timeout:5}),!1):!0}checkSize(e){let t=this._i18n;return this.maxFileSize!==``&&this.maxFileSize*1e3<=e.size?(A({summary:t.t(`file-source.too-big-file-title`),body:t.t(`file-source.too-big-file-body`,{size:O(this.maxFileSize*1e3,!0)}),type:`danger`,timeout:5}),!1):!0}hasEnabledSource(e){return this.enabledTargets.split(`,`).includes(e)}async decompressZIP(e){var t=this;let n=(await import(`./jszip.Cxpk0N-m.js`).then(h(1))).default,r=[];if(await n.loadAsync(e).then(async function(n){await j(n.files,async function(n){n.dir||await n.async(`blob`).then(async function(e){let i=await x(e),a=new File([e],n.name,{type:i});t.checkFileType(a)&&r.push(a)},t=>{console.error(`Decompressing of file in `+e.name+` failed: `+t.message)})})},function(t){console.error(`Loading of `+e.name+` failed: `+t.message)}),r.length===0){let e=this._i18n;console.error(`ZIP file does not contain any files of `+this.allowedMimeTypes),A({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 r}async sendFinishedEvent(e,t,n=!1){if(e===void 0)return;let r={fileName:t.name,status:e.status,json:{"hydra:description":``}};try{await e.json().then(e=>{r.json=e})}catch{}n&&(r.file=t);let i=new CustomEvent(`dbp-file-source-file-finished`,{detail:r,bubbles:!0,composed:!0});this.dispatchEvent(i)}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`)&&this._(`#clipboard-file-picker`).generateClipboardTable();let e=this._(`#modal-picker`);if(e&&F.show(e,{disableScroll:!0,onClose:e=>{this.isDialogOpen=!1;let t=this._(`#nextcloud-file-picker`);t&&(t.selectAllButton=!0);let n=new CustomEvent(`dbp-file-source-dialog-closed`,{detail:{},bubbles:!0,composed:!0});this.dispatchEvent(n)}}),this.initialFileHandlingState.target!==``&&this.initialFileHandlingState.target!==void 0&&this.firstOpen){this.activeDestination=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}}closeDialog(){if(this.sendSource(),this.enabledTargets.includes(`nextcloud`)){let e=this._(`#nextcloud-file-picker`);e&&e.tabulatorTable&&(e.tabulatorTable.deselectRow(),e._(`#select_all`)&&(e._(`#select_all`).checked=!1))}if(this.enabledTargets.includes(`clipboard`)){let e=this._(`#clipboard-file-picker`);e&&e.tabulatorTable&&(e.numberOfSelectedFiles=0,e.tabulatorTable.deselectRow(),e._(`#select_all`)&&(e._(`#select_all`).checked=!1))}F.close(this._(`#modal-picker`))}getClipboardHtml(){return this.enabledTargets.includes(`clipboard`)?w(t||=e` <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)}):w(n||=e``)}getNextcloudHtml(){return this.enabledTargets.includes(`nextcloud`)&&this.nextcloudWebDavUrl!==``&&this.nextcloudAuthUrl!==``?w(r||=e` <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> `,k({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)}):w(i||=e``)}static get styles(){return g(a||=e` ${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; } } `,S(),E(),_(),v(),M())}render(){let t=this._i18n,n=this.allowedMimeTypes;this.decompressZip&&this.allowedMimeTypes!==``&&(n+=`,application/zip,application/x-zip-compressed`);let r=w(o||=e``);return r=this.multipleFiles>1||this.multipleFiles===!0?w(s||=e` <input ?disabled="${0}" type="file" id="fileElem" multiple accept="${0}" name="file" /> `,this.disabled,R(n)):w(c||=e` <input ?disabled="${0}" type="file" id="fileElem" accept="${0}" name="file" /> `,this.disabled,R(n)),w(l||=e` <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" role="tablist"> <button role="tab" aria-selected="${0}" aria-controls="select-local" title="${0}" @click="${0}" class="${0}"> <dbp-icon class="nav-icon" name="laptop"></dbp-icon> <p>${0}</p> </button> <button role="tab" aria-selected="${0}" aria-controls="select-cloud" title="Nextcloud" @click="${0}" class="${0}"> <dbp-icon class="nav-icon" name="cloud"></dbp-icon> <p>${0}</p> </button> <button role="tab" aria-selected="${0}" aria-controls="select-clipboard" title="${0}" @click="${0}" class="${0}"> <dbp-icon class="nav-icon" name="clipboard"></dbp-icon> <p>${0}</p> </button> </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" id="modal-picker-title">${0}</p> </div> <main class="modal-content" id="modal-picker-content"> <div id="select-local" role="tabpanel" 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 id="select-cloud" role="tabpanel" class="source-main ${0}"> ${0} </div> <div id="select-clipboard" role="tabpanel" class="source-main ${0}"> ${0} </div> </main> </div> </div> </div> `,this.activeTarget===`local`,t.t(`file-source.nav-local`),()=>{this.activeTarget=`local`},k({active:this.activeTarget===`local`,hidden:!this.hasEnabledSource(`local`)}),t.t(`file-source.nav-local`),this.activeTarget===`nextcloud`,()=>{this.activeTarget=`nextcloud`},k({active:this.activeTarget===`nextcloud`,hidden:!this.hasEnabledSource(`nextcloud`)||this.nextcloudWebDavUrl===``||this.nextcloudAuthUrl===``}),this.nextcloudName,this.activeTarget===`clipboard`,t.t(`file-source.clipboard`),()=>{this.activeTarget=`clipboard`},k({active:this.activeTarget===`clipboard`,hidden:!this.hasEnabledSource(`clipboard`)}),t.t(`file-source.clipboard`),t.t(`file-source.modal-close`),()=>{this.closeDialog()},this.context,k({hidden:this.activeTarget!==`local`}),t.t(`intro`),r,this.disabled,this.buttonLabel||t.t(`upload-label`),k({hidden:this.activeTarget!==`nextcloud`||this.nextcloudWebDavUrl===``||this.nextcloudAuthUrl===``}),this.getNextcloudHtml(),k({hidden:this.activeTarget!==`clipboard`}),this.getClipboardHtml())}};export{z as t}; //# sourceMappingURL=file-source.fWrDCXC2.js.map