UNPKG

@salla.sa/twilight-components

Version:
587 lines (583 loc) 49.7 kB
/*! * Crafted with ❤ by Salla */ import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client'; const sallaFileUploadCss = "/*!\n * FilePond 4.32.8\n * Licensed under MIT, https://opensource.org/licenses/MIT/\n * Please visit https://pqina.nl/filepond/ for details.\n */.filepond--assistant{position:absolute;overflow:hidden;height:1px;width:1px;padding:0;border:0;clip:rect(1px,1px,1px,1px);-webkit-clip-path:inset(50%);clip-path:inset(50%);white-space:nowrap}.filepond--browser.filepond--browser{position:absolute;margin:0;padding:0;left:1em;top:1.75em;width:calc(100% - 2em);opacity:0;font-size:0}.filepond--data{position:absolute;width:0;height:0;padding:0;margin:0;border:none;visibility:hidden;pointer-events:none;contain:strict}.filepond--drip{position:absolute;top:0;left:0;right:0;bottom:0;overflow:hidden;opacity:.1;pointer-events:none;border-radius:.5em;background:rgba(0,0,0,.01)}.filepond--drip-blob{-webkit-transform-origin:center center;transform-origin:center center;width:8em;height:8em;margin-left:-4em;margin-top:-4em;background:#292625;border-radius:50%}.filepond--drip-blob,.filepond--drop-label{position:absolute;top:0;left:0;will-change:transform,opacity}.filepond--drop-label{right:0;margin:0;color:#4f4f4f;display:flex;justify-content:center;align-items:center;height:0;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.filepond--drop-label.filepond--drop-label label{display:block;margin:0;padding:.5em}.filepond--drop-label label{cursor:default;font-size:.875em;font-weight:400;text-align:center;line-height:1.5}.filepond--label-action{text-decoration:underline;-webkit-text-decoration-skip:ink;text-decoration-skip-ink:auto;-webkit-text-decoration-color:#a7a4a4;text-decoration-color:#a7a4a4;cursor:pointer}.filepond--root[data-disabled] .filepond--drop-label label{opacity:.5}.filepond--file-action-button.filepond--file-action-button{font-size:1em;width:1.625em;height:1.625em;font-family:inherit;line-height:inherit;margin:0;padding:0;border:none;outline:none;will-change:transform,opacity}.filepond--file-action-button.filepond--file-action-button span{position:absolute;overflow:hidden;height:1px;width:1px;padding:0;border:0;clip:rect(1px,1px,1px,1px);-webkit-clip-path:inset(50%);clip-path:inset(50%);white-space:nowrap}.filepond--file-action-button.filepond--file-action-button svg{width:100%;height:100%}.filepond--file-action-button.filepond--file-action-button:after{position:absolute;left:-.75em;right:-.75em;top:-.75em;bottom:-.75em;content:\"\"}.filepond--file-action-button{cursor:auto;color:#fff;border-radius:50%;background-color:rgba(0,0,0,.5);background-image:none;box-shadow:0 0 0 0 hsla(0,0%,100%,0);transition:box-shadow .25s ease-in}.filepond--file-action-button:focus,.filepond--file-action-button:hover{box-shadow:0 0 0 .125em hsla(0,0%,100%,.9)}.filepond--file-action-button[disabled]{color:hsla(0,0%,100%,.5);background-color:rgba(0,0,0,.25)}.filepond--file-action-button[hidden]{display:none}.filepond--action-edit-item.filepond--action-edit-item{width:2em;height:2em;padding:.1875em}.filepond--action-edit-item.filepond--action-edit-item[data-align*=center]{margin-left:-.1875em}.filepond--action-edit-item.filepond--action-edit-item[data-align*=bottom]{margin-bottom:-.1875em}.filepond--action-edit-item-alt{border:none;line-height:inherit;background:transparent;font-family:inherit;color:inherit;outline:none;padding:0;margin:0 0 0 .25em;pointer-events:all;position:absolute}.filepond--action-edit-item-alt svg{width:1.3125em;height:1.3125em}.filepond--action-edit-item-alt span{font-size:0;opacity:0}.filepond--file-info{position:static;display:flex;flex-direction:column;align-items:flex-start;flex:1;margin:0 .5em 0 0;min-width:0;will-change:transform,opacity;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.filepond--file-info *{margin:0}.filepond--file-info .filepond--file-info-main{font-size:.75em;line-height:1.2;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;width:100%}.filepond--file-info .filepond--file-info-sub{font-size:.625em;opacity:.5;transition:opacity .25s ease-in-out;white-space:nowrap}.filepond--file-info .filepond--file-info-sub:empty{display:none}.filepond--file-status{position:static;display:flex;flex-direction:column;align-items:flex-end;flex-grow:0;flex-shrink:0;margin:0;min-width:2.25em;text-align:right;will-change:transform,opacity;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.filepond--file-status *{margin:0;white-space:nowrap}.filepond--file-status .filepond--file-status-main{font-size:.75em;line-height:1.2}.filepond--file-status .filepond--file-status-sub{font-size:.625em;opacity:.5;transition:opacity .25s ease-in-out}.filepond--file-wrapper.filepond--file-wrapper{border:none;margin:0;padding:0;min-width:0;height:100%}.filepond--file-wrapper.filepond--file-wrapper>legend{position:absolute;overflow:hidden;height:1px;width:1px;padding:0;border:0;clip:rect(1px,1px,1px,1px);-webkit-clip-path:inset(50%);clip-path:inset(50%);white-space:nowrap}.filepond--file{position:static;display:flex;height:100%;align-items:flex-start;padding:.5625em;color:#fff;border-radius:.5em}.filepond--file .filepond--file-status{margin-left:auto;margin-right:2.25em}.filepond--file .filepond--processing-complete-indicator{pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;z-index:3}.filepond--file .filepond--file-action-button,.filepond--file .filepond--processing-complete-indicator,.filepond--file .filepond--progress-indicator{position:absolute}.filepond--file [data-align*=left]{left:.5625em}.filepond--file [data-align*=right]{right:.5625em}.filepond--file [data-align*=center]{left:calc(50% - .8125em)}.filepond--file [data-align*=bottom]{bottom:1.125em}.filepond--file [data-align=center]{top:calc(50% - .8125em)}.filepond--file .filepond--progress-indicator{margin-top:.1875em}.filepond--file .filepond--progress-indicator[data-align*=right]{margin-right:.1875em}.filepond--file .filepond--progress-indicator[data-align*=left]{margin-left:.1875em}[data-filepond-item-state*=error] .filepond--file-info,[data-filepond-item-state*=invalid] .filepond--file-info,[data-filepond-item-state=cancelled] .filepond--file-info{margin-right:2.25em}[data-filepond-item-state~=processing] .filepond--file-status-sub{opacity:0}[data-filepond-item-state~=processing] .filepond--action-abort-item-processing~.filepond--file-status .filepond--file-status-sub{opacity:.5}[data-filepond-item-state=processing-error] .filepond--file-status-sub{opacity:0}[data-filepond-item-state=processing-error] .filepond--action-retry-item-processing~.filepond--file-status .filepond--file-status-sub{opacity:.5}[data-filepond-item-state=processing-complete] .filepond--action-revert-item-processing svg{-webkit-animation:fall .5s linear .125s both;animation:fall .5s linear .125s both}[data-filepond-item-state=processing-complete] .filepond--file-status-sub{opacity:.5}[data-filepond-item-state=processing-complete] .filepond--file-info-sub,[data-filepond-item-state=processing-complete] .filepond--processing-complete-indicator:not([style*=hidden])~.filepond--file-status .filepond--file-status-sub{opacity:0}[data-filepond-item-state=processing-complete] .filepond--action-revert-item-processing~.filepond--file-info .filepond--file-info-sub{opacity:.5}[data-filepond-item-state*=error] .filepond--file-wrapper,[data-filepond-item-state*=error] .filepond--panel,[data-filepond-item-state*=invalid] .filepond--file-wrapper,[data-filepond-item-state*=invalid] .filepond--panel{-webkit-animation:shake .65s linear both;animation:shake .65s linear both}[data-filepond-item-state*=busy] .filepond--progress-indicator svg{-webkit-animation:spin 1s linear infinite;animation:spin 1s linear infinite}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}@keyframes spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}@-webkit-keyframes shake{10%,90%{-webkit-transform:translateX(-.0625em);transform:translateX(-.0625em)}20%,80%{-webkit-transform:translateX(.125em);transform:translateX(.125em)}30%,50%,70%{-webkit-transform:translateX(-.25em);transform:translateX(-.25em)}40%,60%{-webkit-transform:translateX(.25em);transform:translateX(.25em)}}@keyframes shake{10%,90%{-webkit-transform:translateX(-.0625em);transform:translateX(-.0625em)}20%,80%{-webkit-transform:translateX(.125em);transform:translateX(.125em)}30%,50%,70%{-webkit-transform:translateX(-.25em);transform:translateX(-.25em)}40%,60%{-webkit-transform:translateX(.25em);transform:translateX(.25em)}}@-webkit-keyframes fall{0%{opacity:0;-webkit-transform:scale(.5);transform:scale(.5);-webkit-animation-timing-function:ease-out;animation-timing-function:ease-out}70%{opacity:1;-webkit-transform:scale(1.1);transform:scale(1.1);-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out}to{-webkit-transform:scale(1);transform:scale(1);-webkit-animation-timing-function:ease-out;animation-timing-function:ease-out}}@keyframes fall{0%{opacity:0;-webkit-transform:scale(.5);transform:scale(.5);-webkit-animation-timing-function:ease-out;animation-timing-function:ease-out}70%{opacity:1;-webkit-transform:scale(1.1);transform:scale(1.1);-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out}to{-webkit-transform:scale(1);transform:scale(1);-webkit-animation-timing-function:ease-out;animation-timing-function:ease-out}}.filepond--hopper[data-hopper-state=drag-over]>*{pointer-events:none}.filepond--hopper[data-hopper-state=drag-over]:after{content:\"\";position:absolute;left:0;top:0;right:0;bottom:0;z-index:100}.filepond--progress-indicator{z-index:103}.filepond--file-action-button{z-index:102}.filepond--file-status{z-index:101}.filepond--file-info{z-index:100}.filepond--item{position:absolute;top:0;left:0;right:0;z-index:1;padding:0;margin:.25em;will-change:transform,opacity;touch-action:auto}.filepond--item>.filepond--panel{z-index:-1}.filepond--item>.filepond--panel .filepond--panel-bottom{box-shadow:0 .0625em .125em -.0625em rgba(0,0,0,.25)}.filepond--item>.filepond--file-wrapper,.filepond--item>.filepond--panel{transition:opacity .15s ease-out}.filepond--item[data-drag-state]{cursor:-webkit-grab;cursor:grab}.filepond--item[data-drag-state]>.filepond--panel{transition:box-shadow .125s ease-in-out;box-shadow:0 0 0 transparent}.filepond--item[data-drag-state=drag]{cursor:-webkit-grabbing;cursor:grabbing}.filepond--item[data-drag-state=drag]>.filepond--panel{box-shadow:0 .125em .3125em rgba(0,0,0,.325)}.filepond--item[data-drag-state]:not([data-drag-state=idle]){z-index:2}.filepond--item-panel{background-color:#64605e}[data-filepond-item-state=processing-complete] .filepond--item-panel{background-color:#369763}[data-filepond-item-state*=error] .filepond--item-panel,[data-filepond-item-state*=invalid] .filepond--item-panel{background-color:#c44e47}.filepond--item-panel{border-radius:.5em;transition:background-color .25s}.filepond--list-scroller{position:absolute;top:0;left:0;right:0;margin:0;will-change:transform}.filepond--list-scroller[data-state=overflow] .filepond--list{bottom:0;right:0}.filepond--list-scroller[data-state=overflow]{overflow-y:scroll;overflow-x:hidden;-webkit-overflow-scrolling:touch;-webkit-mask:linear-gradient(180deg,#000 calc(100% - .5em),transparent);mask:linear-gradient(180deg,#000 calc(100% - .5em),transparent)}.filepond--list-scroller::-webkit-scrollbar{background:transparent}.filepond--list-scroller::-webkit-scrollbar:vertical{width:1em}.filepond--list-scroller::-webkit-scrollbar:horizontal{height:0}.filepond--list-scroller::-webkit-scrollbar-thumb{background-color:rgba(0,0,0,.3);border-radius:99999px;border:.3125em solid transparent;background-clip:content-box}.filepond--list.filepond--list{position:absolute;top:0;margin:0;padding:0;list-style-type:none;will-change:transform}.filepond--list{left:.75em;right:.75em}.filepond--root[data-style-panel-layout~=integrated]{width:100%;height:100%;max-width:none;margin:0}.filepond--root[data-style-panel-layout~=circle] .filepond--panel-root,.filepond--root[data-style-panel-layout~=integrated] .filepond--panel-root{border-radius:0}.filepond--root[data-style-panel-layout~=circle] .filepond--panel-root>*,.filepond--root[data-style-panel-layout~=integrated] .filepond--panel-root>*{display:none}.filepond--root[data-style-panel-layout~=circle] .filepond--drop-label,.filepond--root[data-style-panel-layout~=integrated] .filepond--drop-label{bottom:0;height:auto;display:flex;justify-content:center;align-items:center;z-index:7}.filepond--root[data-style-panel-layout~=circle] .filepond--item-panel,.filepond--root[data-style-panel-layout~=integrated] .filepond--item-panel{display:none}.filepond--root[data-style-panel-layout~=compact] .filepond--list-scroller,.filepond--root[data-style-panel-layout~=integrated] .filepond--list-scroller{overflow:hidden;height:100%;margin-top:0;margin-bottom:0}.filepond--root[data-style-panel-layout~=compact] .filepond--list,.filepond--root[data-style-panel-layout~=integrated] .filepond--list{left:0;right:0;height:100%}.filepond--root[data-style-panel-layout~=compact] .filepond--item,.filepond--root[data-style-panel-layout~=integrated] .filepond--item{margin:0}.filepond--root[data-style-panel-layout~=compact] .filepond--file-wrapper,.filepond--root[data-style-panel-layout~=integrated] .filepond--file-wrapper{height:100%}.filepond--root[data-style-panel-layout~=compact] .filepond--drop-label,.filepond--root[data-style-panel-layout~=integrated] .filepond--drop-label{z-index:7}.filepond--root[data-style-panel-layout~=circle]{border-radius:99999rem;overflow:hidden}.filepond--root[data-style-panel-layout~=circle]>.filepond--panel{border-radius:inherit}.filepond--root[data-style-panel-layout~=circle]>.filepond--panel>*{display:none}.filepond--root[data-style-panel-layout~=circle] .filepond--file-info,.filepond--root[data-style-panel-layout~=circle] .filepond--file-status{display:none}.filepond--root[data-style-panel-layout~=circle] .filepond--action-edit-item{opacity:1!important;visibility:visible!important}@media not all and (min-resolution:0.001dpcm){@supports (-webkit-appearance:none) and (stroke-color:transparent){.filepond--root[data-style-panel-layout~=circle]{will-change:transform}}}.filepond--panel-root{border-radius:.5em;background-color:#f1f0ef}.filepond--panel{position:absolute;left:0;top:0;right:0;margin:0;height:100%!important;pointer-events:none}.filepond-panel:not([data-scalable=false]){height:auto!important}.filepond--panel[data-scalable=false]>div{display:none}.filepond--panel[data-scalable=true]{-webkit-transform-style:preserve-3d;transform-style:preserve-3d;background-color:transparent!important;border:none!important}.filepond--panel-bottom,.filepond--panel-center,.filepond--panel-top{position:absolute;left:0;top:0;right:0;margin:0;padding:0}.filepond--panel-bottom,.filepond--panel-top{height:.5em}.filepond--panel-top{border-bottom-left-radius:0!important;border-bottom-right-radius:0!important;border-bottom:none!important}.filepond--panel-top:after{content:\"\";position:absolute;height:2px;left:0;right:0;bottom:-1px;background-color:inherit}.filepond--panel-bottom,.filepond--panel-center{will-change:transform;-webkit-backface-visibility:hidden;backface-visibility:hidden;-webkit-transform-origin:left top;transform-origin:left top;-webkit-transform:translate3d(0,.5em,0);transform:translate3d(0,.5em,0)}.filepond--panel-bottom{border-top-left-radius:0!important;border-top-right-radius:0!important;border-top:none!important}.filepond--panel-bottom:before{content:\"\";position:absolute;height:2px;left:0;right:0;top:-1px;background-color:inherit}.filepond--panel-center{height:100px!important;border-top:none!important;border-bottom:none!important;border-radius:0!important}.filepond--panel-center:not([style]){visibility:hidden}.filepond--progress-indicator{position:static;width:1.25em;height:1.25em;color:#fff;margin:0;pointer-events:none;will-change:transform,opacity}.filepond--progress-indicator svg{width:100%;height:100%;vertical-align:top;transform-box:fill-box}.filepond--progress-indicator path{fill:none;stroke:currentColor}.filepond--list-scroller{z-index:6}.filepond--drop-label{z-index:5}.filepond--drip{z-index:3}.filepond--root>.filepond--panel{z-index:2}.filepond--browser{z-index:1}.filepond--root{box-sizing:border-box;position:relative;margin-bottom:1em;font-size:1rem;line-height:normal;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;font-weight:450;text-align:left;text-rendering:optimizeLegibility;direction:ltr;contain:layout style size}.filepond--root *{box-sizing:inherit;line-height:inherit}.filepond--root :not(text){font-size:inherit}.filepond--root[data-disabled]{pointer-events:none}.filepond--root[data-disabled] .filepond--list-scroller{pointer-events:all}.filepond--root[data-disabled] .filepond--list{pointer-events:none}.filepond--root .filepond--drop-label{min-height:4.75em}.filepond--root .filepond--list-scroller{margin-top:1em;margin-bottom:1em}.filepond--root .filepond--credits{position:absolute;right:0;opacity:.4;line-height:.85;font-size:11px;color:inherit;text-decoration:none;z-index:3;bottom:-14px}.filepond--root .filepond--credits[style]{top:0;bottom:auto;margin-top:14px}/*!\n * FilePondPluginImagePreview 4.6.12\n * Licensed under MIT, https://opensource.org/licenses/MIT/\n * Please visit https://pqina.nl/filepond/ for details.\n */.filepond--image-preview-markup{position:absolute;left:0;top:0}.filepond--image-preview-wrapper{z-index:2}.filepond--image-preview-overlay{display:block;position:absolute;left:0;top:0;width:100%;min-height:5rem;max-height:7rem;margin:0;opacity:0;z-index:2;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.filepond--image-preview-overlay svg{width:100%;height:auto;color:inherit;max-height:inherit}.filepond--image-preview-overlay-idle{mix-blend-mode:multiply;color:rgba(40, 40, 40, 0.85)}.filepond--image-preview-overlay-success{mix-blend-mode:normal;color:rgba(54, 151, 99, 1)}.filepond--image-preview-overlay-failure{mix-blend-mode:normal;color:rgba(196, 78, 71, 1)}@supports (-webkit-marquee-repetition: infinite) and\n ((-o-object-fit: fill) or (object-fit: fill)){.filepond--image-preview-overlay-idle{mix-blend-mode:normal}}.filepond--image-preview-wrapper{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;position:absolute;left:0;top:0;right:0;height:100%;margin:0;border-radius:0.45em;overflow:hidden;background:rgba(0, 0, 0, 0.01)}.filepond--image-preview{position:absolute;left:0;top:0;z-index:1;display:flex;align-items:center;height:100%;width:100%;pointer-events:none;background:#222;will-change:transform, opacity}.filepond--image-clip{position:relative;overflow:hidden;margin:0 auto;}.filepond--image-clip[data-transparency-indicator='grid'] img,.filepond--image-clip[data-transparency-indicator='grid'] canvas{background-color:#fff;background-image:url(\"data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg' fill='%23eee'%3E%3Cpath d='M0 0 H50 V50 H0'/%3E%3Cpath d='M50 50 H100 V100 H50'/%3E%3C/svg%3E\");background-size:1.25em 1.25em}.filepond--image-bitmap,.filepond--image-vector{position:absolute;left:0;top:0;will-change:transform}.filepond--root[data-style-panel-layout~='integrated'] .filepond--image-preview-wrapper{border-radius:0}.filepond--root[data-style-panel-layout~='integrated'] .filepond--image-preview{height:100%;display:flex;justify-content:center;align-items:center}.filepond--root[data-style-panel-layout~='circle'] .filepond--image-preview-wrapper{border-radius:99999rem}.filepond--root[data-style-panel-layout~='circle'] .filepond--image-preview-overlay{top:auto;bottom:0;-webkit-transform:scaleY(-1);transform:scaleY(-1)}.filepond--root[data-style-panel-layout~='circle'] .filepond--file .filepond--file-action-button[data-align*='bottom']:not([data-align*='center']){margin-bottom:0.325em}.filepond--root[data-style-panel-layout~='circle'] .filepond--file [data-align*='left']{left:calc(50% - 3em)}.filepond--root[data-style-panel-layout~='circle'] .filepond--file [data-align*='right']{right:calc(50% - 3em)}.filepond--root[data-style-panel-layout~='circle'] .filepond--progress-indicator[data-align*='bottom'][data-align*='left'],.filepond--root[data-style-panel-layout~='circle'] .filepond--progress-indicator[data-align*='bottom'][data-align*='right']{margin-bottom:calc(0.325em + 0.1875em)}.filepond--root[data-style-panel-layout~='circle'] .filepond--progress-indicator[data-align*='bottom'][data-align*='center']{margin-top:0;margin-bottom:0.1875em;margin-left:0.1875em}/*!\n * FilePondPluginImageEdit 1.6.3\n * Licensed under MIT, https://opensource.org/licenses/MIT/\n * Please visit https://pqina.nl/filepond/ for details.\n */.filepond--action-edit-item.filepond--action-edit-item{width:2em;height:2em;padding:0.1875em}.filepond--action-edit-item.filepond--action-edit-item[data-align*='center']{margin-left:-0.1875em}.filepond--action-edit-item.filepond--action-edit-item[data-align*='bottom']{margin-bottom:-0.1875em}.filepond--action-edit-item-alt{border:none;line-height:inherit;background:transparent;font-family:inherit;color:inherit;outline:none;padding:0;margin:0 0 0 0.25em;pointer-events:all;position:absolute}.filepond--action-edit-item-alt svg{width:1.3125em;height:1.3125em}.filepond--action-edit-item-alt span{font-size:0;opacity:0}.filepond--root[data-style-panel-layout~='circle'] .filepond--action-edit-item{opacity:1 !important;visibility:visible !important}.s-file-upload-wrapper .filepond--file-info-main{-webkit-line-clamp:1;display:-webkit-box;-webkit-box-orient:vertical}"; const SallaFileUpload = /*@__PURE__*/ proxyCustomElement(class SallaFileUpload extends HTMLElement { /** * Lazy load FilePond and all plugins * This reduces initial bundle size by ~200-250KB */ async loadFilePond() { if (this.filePondLoaded) return; try { const [FilePondModule, FilePondPluginFileValidateSize, FilePondPluginImageExifOrientation, FilePondPluginImagePreview, FilePondPluginImageEdit, FilePondPluginFileValidateType, FilePondPluginFilePoster] = await Promise.all([ import('./filepond.js').then(function (n) { return n.f; }), import('./filepond-plugin-file-validate-size.js').then(function (n) { return n.f; }), import('./filepond-plugin-image-exif-orientation.js').then(function (n) { return n.f; }), import('./filepond-plugin-image-preview.js').then(function (n) { return n.f; }), import('./filepond-plugin-image-edit.js').then(function (n) { return n.f; }), import('./filepond-plugin-file-validate-type.js').then(function (n) { return n.f; }), import('./filepond-plugin-file-poster.js').then(function (n) { return n.f; }) ]); this.FilePond = FilePondModule; // Register plugins this.FilePond.registerPlugin(FilePondPluginImagePreview.default, FilePondPluginImageExifOrientation.default, FilePondPluginFileValidateSize.default, FilePondPluginImageEdit.default, FilePondPluginFileValidateType.default, FilePondPluginFilePoster.default); this.filePondLoaded = true; } catch (error) { console.error('Failed to load FilePond:', error); salla.notify?.error?.('Failed to load file uploader. Please refresh the page.'); throw error; } } constructor() { super(); this.__registerHost(); this.added = createEvent(this, "added", 7); this.invalidInput = createEvent(this, "invalidInput", 7); this.uploaded = createEvent(this, "uploaded", 7); this.removed = createEvent(this, "removed", 7); this.filePondLoaded = false; this.max_images_count = (count) => salla.lang.get('common.uploader.max_images_count', { count }); this.max_count_hint = (count) => salla.lang.get('common.uploader.max_count_hint', { count }); this.uploadedFiles = []; this.isListScrollerListenerAdded = false; this.showMaxCountHint = false; /** * Set the component to be profile image uploader with a preview and a circular shape */ this.profileImage = false; /** * Allow to pass extra params to be sent with the upload request */ this.payloadParams = {}; /** * Accepted file types */ this.accept = "image/png, image/jpeg, image/jpg, image/gif"; /** * The submit request method. */ this.method = 'POST'; /** * json formData to be injected in the submit request */ this.formData = "{}"; /** * Enable or disable drag n' drop */ this.allowDrop = true; /** * Enable or disable file browser */ this.allowBrowse = true; /** * Allow drop to replace a file, only works when allowMultiple is false */ this.allowReplace = true; /** * Enable or disable the revert processing button */ this.allowRevert = true; /** * When set to false the remove button is hidden and disabled */ this.allowRemove = true; /** * Enable or disable preview mode */ this.allowImagePreview = true; /** * Fixed image preview height, overrides min and max preview height */ this.imagePreviewHeight = null; /** * Fixed image poster height, overrides min and max preview height */ this.filePosterHeight = null; /** * The maximum number of files that the pond can handle */ this.maxFilesCount = 1; /** * The maxmimum number of files that can be uploaded in parallel */ this.maxParallelUploads = 3; /** * Set to 'after' to add files to end of list (when dropped at the top of the list or added using browse or paste), * set to 'before' to add files at start of list. * Set to a compare function to automatically sort items when added */ this.itemInsertLocation = 'after'; /** * The interval to use before showing each item being added to the list */ this.itemInsertInterval = 75; /** * Require drop on the FilePond element itself to catch the file. */ this.dropOnElement = true; /** * Ignored file names when handling dropped directories. Dropping directories is not supported on all browsers. */ this.ignoredFiles = ['.ds_store', 'thumbs.db', 'desktop.ini']; /** * The size of a chunk in bytes */ this.chunkSize = 5000000; /** * Amount of times, and delayes, between retried uploading of a chunk */ this.chunkRetryDelays = [500, 1000, 3000]; /// Labels Props /** * The decimal separator used to render numbers. By default this is determined automatically. */ this.labelDecimalSeparator = undefined; /** * The thousdands separator used to render numbers. By default this is determined automatically. */ this.labelThousandsSeparator = undefined; /// SVG Icons /** * The icon used for remove actions */ this.iconRemove = '<svg>...</svg>'; /** * The icon used for process actions */ this.iconProcess = '<svg>...</svg>'; /** * The icon used for retry actions */ this.iconRetry = '<svg>...</svg>'; /** * The icon used for undo actions */ this.iconUndo = '<svg>...</svg>'; this.openFileBrowser = () => { this.filepond.browse(); }; //if cartItemIdIsPassed, we need to set the url if (!this.url && this.cartItemId) { this.url = salla.cart.getUploadImageEndpoint(); this.instantUpload = true; } if (!this.url && this.profileImage) { this.url = salla.url.api('profile/update'); this.instantUpload = true; this.host.hasAttribute('name') || (this.name = 'avatar'); } if (!this.name) { this.name = 'file'; } salla.lang.onLoaded(() => { this.host.querySelectorAll('.filepond--drop-label>label').forEach(label => label.innerHTML = this.getLabel()); if (this.filepond) { this.filepond.labelFileTypeNotAllowed = salla.lang.get('common.uploader.invalid_type'); this.filepond.labelMaxFileSizeExceeded = salla.lang.get('common.uploader.too_large'); this.filepond.labelFileSizeNotAvailable = salla.lang.get('common.uploader.size_not_available'); this.filepond.labelFileLoading = salla.lang.get('common.elements.loading'); this.filepond.labelFileLoadError = salla.lang.get('common.uploader.failed_to_load'); this.filepond.labelFileProcessingAborted = salla.lang.get('common.uploader.upload_cancelled'); this.filepond.labelTapToCancel = salla.lang.get("common.elements.cancel"); this.filepond.labelTapToRetry = salla.lang.get("common.elements.retry"); this.filepond.labelButtonRemoveItem = salla.lang.get("common.elements.remove"); this.filepond.labelButtonUndoItemProcessing = salla.lang.get("common.elements.undo"); this.filepond.labelButtonProcessItem = salla.lang.get("common.uploader.upload"); this.filepond.labelFileProcessingComplete = salla.lang.get('common.uploader.file_processing_complete'), this.filepond.labelTapToUndo = salla.lang.get('common.uploader.tap_to_undo'), this.filepond.labelFileProcessing = salla.lang.get('common.uploader.file_processing'), this.filepond.labelFileProcessingError = salla.lang.get('common.uploader.file_processing_error'); } const setNestedAsync = (lang, key, value) => { return new Promise((resolve) => { salla.helpers.setNested(salla.lang.messages[lang], key, value); resolve(true); }); }; const setTranslations = async () => { await setNestedAsync('ar.trans', 'common.uploader.max_images_count', '.أضف :count صور كحد أقصى'); await setNestedAsync('en.trans', 'common.uploader.max_images_count', 'Add up to :count images maximum.'); await setNestedAsync('ar.trans', 'common.uploader.max_count_hint', 'يمكنك رفع حتى :count صور'); await setNestedAsync('en.trans', 'common.uploader.max_count_hint', 'You can upload up to :count images.'); }; this.max_count_hint = (count) => salla.lang.get('common.uploader.max_count_hint', { count }); this.max_images_count = (count) => salla.lang.get('common.uploader.max_images_count', { count }); setTranslations(); }); } addedHandler(error, file) { this.added.emit({ error: error, file: file }); //if the file passed on initiate will not have type this.host.querySelector('.filepond--root').classList.remove('s-file-upload-has-error'); if (error || !file.file.type) { this.host.querySelector('.filepond--root').classList.add('s-file-upload-has-error'); return; } let container = new DataTransfer; let fileInput = this.getFormDataFileInput(); // @ts-ignore container.items.add(file.file); fileInput.type = 'file'; fileInput.files = container.files; fileInput.dispatchEvent(new window.Event('change', { bubbles: true })); } uploadedHandler() { let fileInput = this.getFormDataFileInput(); fileInput.type = 'hidden'; fileInput.value = this.value; this.hiddenInput.value = this.value; fileInput.dispatchEvent(new window.Event('change', { bubbles: true })); return this.uploaded.emit(this.value); } removedHandler(deletedFile) { let fileInput = this.getFormDataFileInput(); fileInput.type = 'hidden'; fileInput.value = ''; this.host.closest('.s-product-options-option')?.removeAttribute('data-has-value'); if (salla.url.is_page("cart") && deletedFile.getMetadata('id')) { salla.cart.api.deleteImage(deletedFile.getMetadata('id')); } if (this.height) { setTimeout(() => this.host.querySelector('.filepond--root').style.height = this.height, 1000); } this.hiddenInput.value = ''; fileInput.dispatchEvent(new window.Event('change', { bubbles: true })); let toDelete = this.allowMultiple ? deletedFile.getMetadata('id') : deletedFile; return this.removed.emit(toDelete); } /** * Method to set option for filepond * */ async setOption(key, value) { this.filepond[key] = value; } getLabel() { if (this.labelIdle) { //some times we are passing label before translations is loaded, so here we will make sure that all translations are translated return this.labelIdle .replace('common.uploader.drag_and_drop', salla.lang.get('common.uploader.drag_and_drop')) .replace('common.uploader.browse', salla.lang.get('common.uploader.browse')); } return `${salla.lang.get('common.uploader.drag_and_drop')}<span class="filepond--label-action"> ${salla.lang.get('common.uploader.browse')} </span>`; } /** * * This method will fire head request to get the file size, it's head request,so it will be too fast. */ getFileSize(url) { let http = new XMLHttpRequest(); http.open('HEAD', url, false); // false = Synchronous http.send(null); // it will stop here until this http request is complete return http.status === 200 ? http.getResponseHeader('content-length') : ''; } getFormDataFileInput() { return this.host.querySelector('.filepond--data input'); } getFiles() { if (!this.value && !this.files) { return []; } try { let files = this.files ? typeof this.files === 'string' ? JSON.parse(this.files) : this.files : this.value.split(',').map(file => ({ url: file })); if (files.length) { this.host.closest('.s-product-options-option')?.setAttribute('data-has-value', 'true'); } return files.map(file => ({ source: file.id ? `${file.id}` : file.url, options: { type: 'local', file: { name: file.url.substring(file.url.lastIndexOf('/') + 1), size: this.getFileSize(file.url) }, metadata: { poster: file.url, name: file.url, id: file.id }, }, })); } catch (e) { salla.log('failed To get files from: ' + (this.files || this.value)); } return []; } async componentWillLoad() { // Load FilePond before component renders (reduces initial bundle by ~200-250KB) await this.loadFilePond(); if (!this.labelIdle) { this.labelIdle = this.host.innerHTML; this.host.innerHTML = ''; } } render() { return (h(Host, { key: 'b33365d20c42081e38ebf7c8b63bc0580807bc4e', class: { "s-file-upload": true, "s-file-upload-profile-image": this.profileImage, "s-file-upload-multiple": this.allowMultiple, } }, h("input", { key: '6e4458218bbeae75c21db781c85a376b29d5b11b', type: "file", name: this.name, value: this.value, ref: ele => this.fileUploader = ele, required: this.required, class: "s-file-upload-wrapper s-file-upload-input", accept: this.accept }), this.allowMultiple && this.showMaxCountHint ? h("div", { class: "s-file-upload-hint s-hidden" }, this.max_count_hint(this.maxFilesCount)) : '', h("input", { key: 'f06888dc84c34236d11c7b2ad7250bb41d8b9bfe', class: "s-hidden", name: 'hidden-' + this.name, required: this.required, value: this.value, ref: input => this.hiddenInput = input }))); } componentDidLoad() { let files = this.getFiles(); this.filepond = this.FilePond.create(this.fileUploader, { name: this.payloadName || this.name, //@ts-ignore files: files, required: this.required, disabled: this.disabled, allowDrop: this.allowDrop, allowBrowse: this.allowBrowse, allowPaste: this.allowPaste, allowMultiple: this.allowMultiple, //||files.length, allowReplace: this.allowReplace, allowRevert: this.allowRevert, allowProcess: this.allowProcess, allowReorder: this.allowReorder, storeAsFile: this.storeAsFile, forceRevert: this.forceRevert, maxFiles: this.maxFilesCount, imagePreviewHeight: this.imagePreviewHeight, filePosterHeight: this.filePosterHeight, allowImagePreview: this.allowImagePreview, maxParallelUploads: this.maxParallelUploads, checkValidity: this.checkValidity, itemInsertLocation: this.itemInsertLocation, itemInsertInterval: this.itemInsertInterval, credits: this.credits, dropOnPage: this.dropOnPage, dropOnElement: this.dropOnElement, dropValidation: this.dropValidation, ignoredFiles: this.ignoredFiles, onaddfile: (error, file) => this.addedHandler(error, file), onwarning: (error, _file, _status) => { if (error.body === "Max files") { salla.notify.error(this.max_images_count(this.maxFilesCount)); } }, onprocessfile: (error, file) => { if (this.allowMultiple && !error) { // Find the uploaded file data using the serverId returned from onload const serverId = file.serverId; const uploadedFile = this.uploadedFiles.find(f => f.id === serverId); if (uploadedFile) { // Set metadata on the file file.setMetadata('id', uploadedFile.id, true); file.setMetadata('url', uploadedFile.url, true); this.value = { id: uploadedFile.id, url: uploadedFile.url }; this.uploadedHandler(); } } }, onupdatefiles: (fileItems) => { const dropLabel = this.host.querySelector('.filepond--drop-label'); const listScroller = this.host.querySelector('.filepond--list-scroller'); if (this.allowMultiple) { if (fileItems.length > 0) { dropLabel.classList.add('s-hidden'); if (!this.isListScrollerListenerAdded && fileItems.length < this.maxFilesCount) { this.showMaxCountHint = true; listScroller.addEventListener('click', this.openFileBrowser); this.isListScrollerListenerAdded = true; } } else { dropLabel.classList.remove('s-hidden'); if (this.isListScrollerListenerAdded) { listScroller.removeEventListener('click', this.openFileBrowser); this.isListScrollerListenerAdded = false; } } // Check if fileItems length equals maxFilesCount and remove event listener if (fileItems.length === this.maxFilesCount && this.isListScrollerListenerAdded) { listScroller.removeEventListener('click', this.openFileBrowser); this.isListScrollerListenerAdded = false; this.showMaxCountHint = false; } } }, server: { url: this.url, method: this.method, revert: null, // @ts-ignore process: { onload: (response) => { let responseData = JSON.parse(response).data; if ((this.instantUpload || this.allowMultiple) && Array.isArray(responseData) && responseData.length > 0) { const fileId = `${this.host.id}-${Math.floor(100 + Math.random() * 900)}`; const fileUrl = responseData[0]; // Store the upload result to be picked up by onprocessfile this.uploadedFiles.push({ id: fileId, url: fileUrl }); // Return the serverId that FilePond will use to identify this file // We'll use the fileId as the serverId return fileId; } else { this.value = responseData.filePath || responseData.url; this.uploadedHandler(); return this.value; } }, headers: salla.api.getHeaders(), onerror: response => { try { let field = JSON.parse(response).error.fields; field = field[this.payloadName || this.name]; return (field && field[0]) || salla.lang.get('common.errors.error_occurred'); } catch (e) { salla.log('FileUpload:: Error', e); return salla.lang.get('common.errors.error_occurred'); } }, ondata: formData => { if (this.allowMultiple) { const newFormData = new FormData(); // ? This line suppose to send all files in one request but its not working properly // const filesArray = this.filepond.getFiles().map(file => file.file); formData.forEach((value) => { newFormData.append(`files[]`, value); }); newFormData.append("type", this.type); return newFormData; } if (this.payloadName && this.payloadName != this.name && !this.allowMultiple) { formData.append(this.payloadName, this.filepond.getFile(0).file); formData.delete(this.name); } if (this.payloadParams) { for (const [k, v] of Object.entries(this.payloadParams)) { formData.append(k, v); } } if (this.cartItemId) { formData.append('cart_item_id', this.cartItemId); } try { Object.entries(JSON.parse(this.formData)).forEach((value) => value[1] && formData.append(value[0], value[1])); } catch (e) { salla.log('Error to inject formData', e); } return formData; } }, }, instantUpload: this.instantUpload, chunkUploads: this.chunkUploads, chunkForce: this.chunkForce, chunkSize: this.chunkSize, chunkRetryDelays: this.chunkRetryDelays, labelDecimalSeparator: this.labelDecimalSeparator, labelThousandsSeparator: this.labelThousandsSeparator, labelIdle: this.getLabel(), acceptedFileTypes: this.accept.replace(/\s+/g, '').split(','), labelFileTypeNotAllowed: salla.lang.get('common.uploader.invalid_type'), labelFileProcessingComplete: salla.lang.get('common.uploader.file_processing_complete'), labelTapToUndo: salla.lang.get('common.uploader.tap_to_undo'), labelFileProcessing: salla.lang.get('common.uploader.file_processing'), labelFileProcessingError: salla.lang.get('common.uploader.file_processing_error'), fileValidateTypeLabelExpectedTypes: '{allButLastType}, {lastType}', labelMaxFileSizeExceeded: salla.lang.get('common.uploader.too_large'), labelMaxFileSize: '{filesize}', maxFileSize: `${salla.config.get('store.settings.upload_size')}KB` || this.maxFileSize, beforeRemoveFile: (deletedFile) => new Promise((resolve) => { this.removedHandler(deletedFile); resolve(true); }), }); this.hiddenInput.addEventListener('invalid', e => { this.invalidInput.emit(e); }); this.hiddenInput.addEventListener('change', () => { this.hiddenInput.setCustomValidity(''); this.hiddenInput.reportValidity(); }); } get host() { return this; } static get style() { return sallaFileUploadCss; } }, [0, "salla-file-upload", { "value": [1544], "files": [513], "height": [513], "cartItemId": [1, "cart-item-id"], "profileImage": [516, "profile-image"], "name": [1537], "payloadName": [1, "payload-name"], "payloadParams": [16, "payload-params"], "type": [1], "accept": [1537], "fileId": [2, "file-id"], "url": [1025], "method": [1], "formData": [1, "form-data"], "required": [4], "maxFileSize": [1, "max-file-size"], "disabled": [4], "allowDrop": [4, "allow-drop"], "allowBrowse": [4, "allow-browse"], "allowPaste": [4, "allow-paste"], "allowMultiple": [4, "allow-multiple"], "allowReplace": [4, "allow-replace"], "allowRevert": [4, "allow-revert"], "allowRemove": [4, "allow-remove"], "allowProcess": [4, "allow-process"], "allowReorder": [4, "allow-reorder"], "allowImagePreview": [4, "allow-image-preview"], "imagePreviewHeight": [2, "image-preview-height"], "filePosterHeight": [2, "file-poster-height"], "storeAsFile": [4, "store-as-file"], "forceRevert": [4, "force-revert"], "maxFilesCount": [2, "max-files-count"], "maxParallelUploads": [2, "max-parallel-uploads"], "checkValidity": [4, "check-validity"], "itemInsertLocation": [1, "item-insert-location"], "itemInsertInterval": [2, "item-insert-interval"], "credits": [4], "dropOnPage": [4, "drop-on-page"], "dropOnElement": [4, "drop-on-element"], "dropValidation": [4, "drop-validation"], "ignoredFiles": [16, "ignored-files"], "instantUpload": [1028, "instant-upload"], "chunkUploads": [4, "chunk-uploads"], "chunkForce": [4, "chunk-force"], "chunkSize": [2, "chunk-size"], "chunkRetryDelays": [16, "chunk-retry-delays"], "labelDecimalSeparator": [1, "label-decimal-separator"], "labelThousandsSeparator": [1, "label-thousands-separator"], "labelIdle": [1025, "label-idle"], "iconRemove": [1, "icon-remove"], "iconProcess": [1, "icon-process"], "iconRetry": [1, "icon-retry"], "iconUndo": [1, "icon-undo"], "max_images_count": [32], "max_count_hint": [32], "uploadedFiles": [32], "isListScrollerListenerAdded": [32], "showMaxCountHint": [32], "setOption": [64] }]); function defineCustomElement() { if (typeof customElements === "undefined") { return; } const components = ["salla-file-upload"]; components.forEach(tagName => { switch (tagName) { case "salla-file-upload": if (!customElements.get(tagName)) { customElements.define(tagName, SallaFileUpload); } break; } }); } defineCustomElement(); export { SallaFileUpload as S, defineCustomElement as d };