@emailmaker/emailmaker 1.0.105-alpha.3 → 1.0.105-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emailmaker/emailmaker",
3
- "version": "1.0.105-alpha.3",
3
+ "version": "1.0.105-alpha.4",
4
4
  "private": false,
5
5
  "main": "emailmaker.js",
6
6
  "module": "emailmaker-esm.js",
@@ -1,2 +1,2 @@
1
- "use strict";(globalThis.webpackChunkemail_maker=globalThis.webpackChunkemail_maker||[]).push([[5102],{16160:(e,t,i)=>{i.r(t),i.d(t,{default:()=>Q});var r=i(1936),a=i(71715),o=i(84075),s=i(18021),n=i(51114),l=i(6691),d=i(86331),h=i(60034),c=i(98173),u=i(78443),v=i(75301),f=i(22817),m=i(81644),p=i(942),w=i(6403),g=i(65185);let I;var y;(y=I||(I={})).isEqual=function(e,t,i=(e,t)=>e===t){if(e===t)return!0;const r=e.length;if(r!==t.length)return!1;for(let a=0;a<r;a++)if(!i(e[a],t[a]))return!1;return!0},y.unique=function(e,t){t||(t=e=>e);const i=new Set;return e.filter(e=>{const r=t(e),a=!i.has(r);return i.add(r),a})};var _=i(47706),F=i(65893);function C(e){return null==e||""===e?"":e}function P(e){if(null==e)return 1/0;const t=Number(e);return Number.isFinite(t)&&t>=0?t:1/0}function A(e){if(!e)return null;const t=e.folderId;return null==t?null:String(t)}function b(e){return!!e&&e.isFolder}function E(){var e;if("function"===typeof(null===globalThis||void 0===globalThis||null===(e=globalThis.crypto)||void 0===e?void 0:e.randomUUID))return globalThis.crypto.randomUUID();try{const e=globalThis.crypto||globalThis.msCrypto;if(e&&"function"===typeof e.getRandomValues){const t=new Uint8Array(16);e.getRandomValues(t);let i="";for(let e=0;e<t.length;e++)i+=t[e].toString(16).padStart(2,"0");return`id_${i}`}}catch{}return`id_fallback_${Date.now().toString(36)}_${Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(36).slice(0,8)}`}function M(e){if(!e||"object"!==typeof e)return String(null!==e&&void 0!==e?e:"");const t=e,i=[],r={},a=["page","pageSize","sortBy","sortOrder","search","itemType","limit"];for(const l of Object.keys(t).sort()){const e=t[l];a.includes(l)?i.push(`${l}=${String(null!==e&&void 0!==e?e:"")}`):r[l]=e}const o=Object.keys(r).length?JSON.stringify(r):"",s=i.join("|"),n=o?function(e){let t=2166136261;for(let i=0;i<e.length;i++)t^=e.charCodeAt(i),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t.toString(36)}(o):"";return`${s}${n?`|${n}`:""}`}class S{constructor(){this.entities=new Map,this.childrenByParent=new Map,this.maxCacheSize=1e4}now(){return Date.now()}checkCacheSize(){if(this.entities.size>this.maxCacheSize){const e=Array.from(this.entities.entries()).sort((e,t)=>e[1].updatedAt-t[1].updatedAt),t=Math.floor(.1*this.maxCacheSize);for(let i=0;i<t&&i<e.length;i++){const[t,r]=e[i];this.deleteEntityById(t)}}}getEntity(e){var t;return null===(t=this.entities.get(e))||void 0===t?void 0:t.value}getRecord(e){return this.entities.get(e)}getFileSystemItem(e){const t=this.getEntity(e);return t&&!b(t)?t:void 0}getFolder(e){const t=this.getEntity(e);return t&&b(t)?t:void 0}getChildrenIds(e,t={}){const i=C(e),r=this.childrenByParent.get(i);return r?t.onlyFileSystemItems?Array.from(r.files):t.onlyFolders?Array.from(r.folders):[...Array.from(r.folders),...Array.from(r.files)]:[]}searchByUrl(e){for(const t of this.entities.values())if(t.value.url===e)return t.value;return null}upsertEntity(e){var t;const i=null!==(t=this.entities.get(e.id))&&void 0!==t?t:null,r=i?i.value:null,a=r?A(r):null,o=A(e),s=!!r&&b(r),n=b(e);let l;if(r&&b(r)&&n){const t=r.childrenCount,i=e.childrenCount;void 0!==t&&void 0===i&&(l=t)}if(r&&(a!==o||s!==n)){const t=C(a),i=this.childrenByParent.get(t);i&&(s?i.folders.delete(e.id):i.files.delete(e.id),0===i.files.size&&0===i.folders.size&&this.childrenByParent.delete(t))}let d=e;void 0!==l&&(d={...e,childrenCount:l}),this.entities.set(e.id,{value:{...d},updatedAt:this.now()}),this.checkCacheSize();const h=C(o);let c=this.childrenByParent.get(h);c||(c={files:new Set,folders:new Set},this.childrenByParent.set(h,c)),n?c.folders.add(e.id):c.files.add(e.id)}updateServerChildrenCount(e,t){if(null==e||null==t||Number.isNaN(t))return;const i=this.entities.get(e);if(!i||!b(i.value))return;const r={...i.value,childrenCount:t};this.entities.set(e,{value:r,updatedAt:this.now()})}deleteEntityById(e){var t;const i=null!==(t=this.entities.get(e))&&void 0!==t?t:null;if(!i)return{entity:null,parentId:null};const r=i.value,a=A(r),o=C(a),s=this.childrenByParent.get(o);return s&&(b(r)?s.folders.delete(e):s.files.delete(e),0===s.files.size&&0===s.folders.size&&this.childrenByParent.delete(o)),this.entities.delete(e),{entity:{...r},parentId:a}}deleteFolderRecursive(e){const t=this.entities.get(e);if(!t||!b(t.value))return{deletedFolderRecords:[],deletedFileSystemItemRecords:[]};const i=[{id:e,parentId:A(t.value)}],r=[],a=[];for(;i.length;){const e=i.shift();r.push(e);const t=this.childrenByParent.get(C(e.id));if(t){for(const e of Array.from(t.folders)){const t=this.entities.get(e);t&&i.push({id:e,parentId:A(t.value)})}for(const e of Array.from(t.files))a.push(e)}}const o=[];for(const n of a){const e=this.entities.get(n);if(!e)continue;const t=e.value,i=C(A(t)),r=this.childrenByParent.get(i);r&&(r.files.delete(n),0===r.files.size&&0===r.folders.size&&this.childrenByParent.delete(i)),this.entities.delete(n),o.push({...t})}const s=[];for(let n=r.length-1;n>=0;n--){const{id:e,parentId:t}=r[n],i=this.entities.get(e);if(!i)continue;const a=i.value,o=C(a.id);this.childrenByParent.delete(o);const l=C(t),d=this.childrenByParent.get(l);d&&(d.folders.delete(e),0===d.files.size&&0===d.folders.size&&this.childrenByParent.delete(l)),this.entities.delete(e),s.push({...a})}return{deletedFolderRecords:s,deletedFileSystemItemRecords:o}}moveEntityById(e,t){var i;const r=null!==(i=this.entities.get(e))&&void 0!==i?i:null;if(!r)return null;const a=r.value,o=C(A(a)),s=this.childrenByParent.get(o);s&&(b(a)?s.folders.delete(e):s.files.delete(e),0===s.files.size&&0===s.folders.size&&this.childrenByParent.delete(o));const n={...a,folderId:t};if(b(a)&&b(n)){const e=a.childrenCount;void 0!==e&&(n.childrenCount=e)}this.entities.set(e,{value:n,updatedAt:this.now()});const l=C(t);let d=this.childrenByParent.get(l);return d||(d={files:new Set,folders:new Set},this.childrenByParent.set(l,d)),b(n)?d.folders.add(e):d.files.add(e),{...n}}copyFileSystemItem(e,t,i){var r;const a=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!a||b(a.value))return null;const o={...a.value,id:t,folderId:i};return this.upsertEntity(o),{...o}}copyFolderShallow(e,t,i){var r;const a=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!a||!b(a.value))return null;const o={...a.value,id:t,folderId:i};return this.upsertEntity(o),{...o}}isEntityStale(e,t){var i;const r=null!==(i=this.entities.get(e))&&void 0!==i?i:null;return!r||t!==1/0&&this.now()-r.updatedAt>t}touch(e,t){const i=this.entities.get(e);i&&(i.updatedAt=null!==t&&void 0!==t?t:this.now())}getEntitiesByIds(e){return e.map(e=>{var t,i;return null!==(t=null===(i=this.entities.get(e))||void 0===i?void 0:i.value)&&void 0!==t?t:null})}searchByName(e,t){var i,r,a,o;if(!e||""===e.trim())return[];const s=null===t||void 0===t?void 0:t.parentId,n=null!==(i=null===t||void 0===t?void 0:t.recursive)&&void 0!==i&&i,l=null!==(r=null===t||void 0===t?void 0:t.itemType)&&void 0!==r?r:"all",d=null!==(a=null===t||void 0===t?void 0:t.caseSensitive)&&void 0!==a&&a,h=null!==(o=null===t||void 0===t?void 0:t.limit)&&void 0!==o?o:1/0,c=d?e.trim():e.trim().toLowerCase(),u=[];let v=null;if(void 0!==s){v=new Set;const e=C(s);if(v.add(e),n){const t=[e],i=new Set;for(;t.length>0;){const e=t.shift();if(i.has(e))continue;i.add(e);const r=this.childrenByParent.get(e);if(r)for(const i of r.folders)v.add(i),t.push(i)}}}for(const[,m]of this.entities){var f;if(u.length>=h)break;const e=m.value;if(null!==v){const t=C(A(e));if(!v.has(t))continue}if("file"===l&&b(e))continue;if("folder"===l&&!b(e))continue;const t=null!==(f=e.name)&&void 0!==f?f:"";(d?t:t.toLowerCase()).includes(c)&&u.push({...e})}return u}toJSON(){return{entities:Array.from(this.entities.entries()),childrenByParent:Array.from(this.childrenByParent.entries()).map(([e,t])=>[e,{files:Array.from(t.files),folders:Array.from(t.folders)}])}}static fromJSON(e){const t=new S;for(const[a,o]of null!==(i=e.entities)&&void 0!==i?i:[]){var i;t.entities.set(a,{value:o.value,updatedAt:o.updatedAt})}for(const[a,o]of null!==(r=e.childrenByParent)&&void 0!==r?r:[]){var r;t.childrenByParent.set(a,{files:new Set(o.files),folders:new Set(o.folders)})}return t}}class T{constructor(e={},t=3e5,i=3e4,r){var a,o,s,n,l;this.views=new Map,this.strategy=void 0,this.ttl=void 0,this.errorTtl=void 0,this.entityTtl=void 0,this.serverChildrenCountHandler=void 0,this.childrenCountInvalidator=void 0,this.maxViewsPerParent=50,this.strategy={allowSortedInsert:null===(a=e.allowSortedInsert)||void 0===a||a,allowSearchInsert:null===(o=e.allowSearchInsert)||void 0===o||o,invalidateOnPaginationFull:null===(s=e.invalidateOnPaginationFull)||void 0===s||s,preloadPagesBefore:null!==(n=e.preloadPagesBefore)&&void 0!==n?n:0,preloadPagesAfter:null!==(l=e.preloadPagesAfter)&&void 0!==l?l:1,comparator:e.comparator,filterMatch:e.filterMatch},this.ttl=t,this.errorTtl=i,this.entityTtl=null!==r&&void 0!==r?r:t}setServerChildrenCountHandler(e){this.serverChildrenCountHandler=e}setChildrenCountInvalidator(e){this.childrenCountInvalidator=e}now(){return Date.now()}parentKey(e){return C(null!==e&&void 0!==e?e:null)}isExpired(e){return null==e||this.ttl!==1/0&&this.now()-e>this.ttl}isErrorExpired(e){return null==e||this.errorTtl!==1/0&&this.now()-e>this.errorTtl}areEntitiesStale(e,t){return!e||e.some(e=>!t.getEntity(e)||t.isEntityStale(e,this.entityTtl))}isEntityTypeCompatible(e,t){return!t||"all"===t||("file"===t&&!b(e)||!("folder"!==t||!b(e)))}cleanupOldViews(e){if(e.size<=this.maxViewsPerParent)return;const t=Array.from(e.entries()).sort((e,t)=>(t[1].view.updatedAt||0)-(e[1].view.updatedAt||0));for(;e.size>this.maxViewsPerParent&&t.length>0;){const[i]=t.pop();e.delete(i)}}async getOrCreateChildren(e,t,i,r){var a;const o=this.parentKey(e),s=M(null!==t&&void 0!==t?t:{});let n=this.views.get(o);n||(n=new Map,this.views.set(o,n));let l=n.get(s);if(!l){l={params:t,view:{promise:null,value:void 0,meta:void 0,error:void 0,updatedAt:0,loadId:null}},n.set(s,l),this.cleanupOldViews(n)}if(l.view.error&&!this.isErrorExpired(l.view.updatedAt))throw l.view.error;if(l.view.value&&!this.isExpired(l.view.updatedAt)&&!this.areEntitiesStale(l.view.value,r)&&(null===(a=l.view.meta)||void 0===a||!a.stale)){var d,h;const e=l.view.value.map(e=>r.getEntity(e)).filter(Boolean),t=(null===(d=l.params)||void 0===d?void 0:d.itemType)||"all";return{items:e.filter(e=>this.isEntityTypeCompatible(e,t)),...null!==(h=l.view.meta)&&void 0!==h?h:{}}}if(l.view.promise)return l.view.promise;const c=E();l.view.loadId=c;const u=(async()=>{try{var a,s,n;const h=await i(e,t),u=null===(a=this.views.get(o))||void 0===a?void 0:a.get(M(t));if(!u||u.view.loadId!==c){const e=new Error("StaleLoad");throw e.name="StaleLoad",e}for(const e of h.items)r.upsertEntity(e);l.view.value=h.items.map(e=>e.id);const{items:v,...f}=h,m={...f};l.view.meta=m,l.view.meta.stale=!1,l.view.error=null,l.view.updatedAt=this.now(),"number"===typeof m.total&&(this.serverChildrenCountHandler?this.serverChildrenCountHandler(null!==e&&void 0!==e?e:null,m.total,r):r.updateServerChildrenCount(e,m.total));const p=null!==(s=this.strategy.preloadPagesAfter)&&void 0!==s?s:0,w=null!==(n=this.strategy.preloadPagesBefore)&&void 0!==n?n:0,g=P(null===t||void 0===t?void 0:t.pageSize),I=Number.isFinite(g);if((p>0||w>0)&&I){var d;const a=e,o={...t},s="number"===typeof m.totalPages?m.totalPages:1,n=null!==(d=null===t||void 0===t?void 0:t.page)&&void 0!==d?d:1,l=g,h=i,u=c;setTimeout(()=>{this.preloadPagesAsync(a,o,n,s,l,p,w,r,m,h,u)},0)}return h}catch(m){var h,u,v,f;if("StaleLoad"===(null===m||void 0===m?void 0:m.name))throw l.view.error=null,l.view.value=void 0,l.view.updatedAt=this.now(),m;const e=m,t=null!==(h=null===e||void 0===e?void 0:e.status)&&void 0!==h?h:null===e||void 0===e||null===(u=e.data)||void 0===u?void 0:u.status,i=null!==(v=null===e||void 0===e?void 0:e.code)&&void 0!==v?v:null===e||void 0===e||null===(f=e.data)||void 0===f?void 0:f.code;if(404===t||"FileNotFound"===i||"FolderNotFound"===i||"path_folder_not_found"===i)return l.view.error=null,l.view.value=[],l.view.meta={total:0,totalPages:0},l.view.updatedAt=this.now(),{items:[],total:0,totalPages:0};throw l.view.error=m,l.view.value=void 0,l.view.updatedAt=this.now(),m}finally{l.view.promise=null}})();return l.view.promise=u,u}async preloadPagesAsync(e,t,i,r,a,o,s,n,l,d,h){try{const a=this.parentKey(e),l=this.views.get(a);if(!l)return;const c=l.get(M(t));if(!c)return;if(null!=h&&c.view.loadId!==h)return;const u=l.get(M(t));if(null===u||void 0===u||!u.view.meta)return;const v="number"===typeof u.view.meta.totalPages?u.view.meta.totalPages:1;if(v!==r)return;const f=async i=>{const r={...t,page:i};try{const o=await d(e,r),s=this.views.get(a);if(!s)return;const l=s.get(M(t));if(!l)return;if(null!=h&&l.view.loadId!==h)return;if(l.view.loadId!==h)return;for(const e of o.items)n.upsertEntity(e);const c=M(r);let u=s.get(c);if(!u){u={params:r,view:{promise:null,value:void 0,meta:void 0,error:void 0,updatedAt:0,loadId:l.view.loadId}},s.set(c,u),this.cleanupOldViews(s)}if(!u.view.value||this.isExpired(u.view.updatedAt)){u.view.value=o.items.map(e=>e.id);const{items:e,...t}=o;u.view.meta={...t,page:i,totalPages:v},u.view.updatedAt=this.now()}}catch(o){}};if(o>0&&i<v)for(let e=1;e<=Math.min(o,v-i);e++){const r=i+e,a=M({...t,page:r}),o=l.get(a);null!==o&&void 0!==o&&o.view.value&&!this.isExpired(o.view.updatedAt)||f(r)}if(s>0&&i>1)for(let e=1;e<=Math.min(s,i-1);e++){const r=i-e,a=M({...t,page:r}),o=l.get(a);null!==o&&void 0!==o&&o.view.value&&!this.isExpired(o.view.updatedAt)||f(r)}}catch(c){}}removeEmptyPageIfNeeded(e,t,i,r,a){if(t.view.value&&0===t.view.value.length&&i<r){const t=M({...a,page:i});e.delete(t)}}updateTotalPagesForAllViews(e,t){for(const[,i]of e)i.view.meta&&(i.view.meta.totalPages=t)}isParamsSame(e,t){const i=Object.keys(null!==e&&void 0!==e?e:{}).filter(e=>"page"!==e).sort(),r=Object.keys(null!==t&&void 0!==t?t:{}).filter(e=>"page"!==e).sort();if(i.length!==r.length)return!1;for(let a=0;a<i.length;a++){const o=i[a];if(o!==r[a])return!1;if(e[o]!==t[o])return!1}return!0}syncTotalsInSameViews(e,t){var i;const r=t.view.meta;if(!r||"number"!==typeof r.total)return;const a=Number(r.total),o=P(null===(i=t.params)||void 0===i?void 0:i.pageSize),s=Number.isFinite(o)&&o>0?Math.max(1,Math.ceil(a/o)):void 0;for(const[,d]of e){var n,l;this.isParamsSame(null!==(n=d.params)&&void 0!==n?n:{},null!==(l=t.params)&&void 0!==l?l:{})&&(d.view.meta||(d.view.meta={}),d.view.meta.total=a,void 0!==s&&(d.view.meta.totalPages=s))}}canSafelyModifySortedView(e){return!e.sortBy&&!e.sortOrder||!!this.strategy.comparator}cascadeShiftPages(e,t,i,r,a,o,s){let n=t,l=i,d=!1;let h=0;for(;n.view.value&&n.view.value.length<r&&l<a&&h<100;){h++;const t=M({...s,page:l+1}),i=e.get(t);if(null===i||void 0===i||!i.view.value||this.isExpired(i.view.updatedAt)){var c;n.view.meta={...null!==(c=n.view.meta)&&void 0!==c?c:{},stale:!0};break}const a=r-n.view.value.length,v=i.view.value.slice(0,a).filter(e=>o.getEntity(e));if(0===v.length){var u;n.view.meta={...null!==(u=n.view.meta)&&void 0!==u?u:{},stale:!0};break}if(n.view.value=[...n.view.value,...v],n.view.updatedAt=Date.now(),i.view.value=i.view.value.slice(v.length),i.view.updatedAt=Date.now(),0===i.view.value.length){const t=l+1,r=i.view.meta;if(t<(r&&"number"===typeof r.totalPages?r.totalPages:1)){const i=M({...s,page:t});e.delete(i),d=!0}break}n=i,l++}var v;(!n.view.value||n.view.value.length<r)&&l>=a&&(n.view.meta={...null!==(v=n.view.meta)&&void 0!==v?v:{},stale:!0});return d}cascadeShiftToNextPage(e,t,i,r,a,o,s){var n,l;if(!t.view.value||t.view.value.length<=r)return!1;var d;if(i-(s.page||1)>=10)return t.view.meta={...null!==(d=t.view.meta)&&void 0!==d?d:{},stale:!0},!1;const h={...s,page:i+1},c=M(h);let u=e.get(c),v=!1;if(null===(n=u)||void 0===n||!n.view.value||this.isExpired(u.view.updatedAt)){var f;if(!(i>=a))return t.view.meta={...null!==(f=t.view.meta)&&void 0!==f?f:{},stale:!0},!1;{u={params:h,view:{promise:null,value:void 0,meta:void 0,error:void 0,updatedAt:0,loadId:null}},e.set(c,u),this.cleanupOldViews(e);const r=t.view.meta;r&&(u.view.meta={...r,page:i+1}),v=!0}}const m=t.view.value.slice(r).filter(e=>o.getEntity(e));if(0===m.length)return v&&e.delete(c),!1;t.view.value=t.view.value.slice(0,r),t.view.updatedAt=Date.now(),u.view.value=[...m,...null!==(l=u.view.value)&&void 0!==l?l:[]],u.view.updatedAt=Date.now();const p=u.view.meta&&"number"===typeof u.view.meta.totalPages?u.view.meta.totalPages:a;if(!v){if(this.cascadeShiftToNextPage(e,u,i+1,r,p,o,s))return!0}if(!u.view.value||0===u.view.value.length){const t=i+1,r=u.view.meta,a=r&&"number"===typeof r.totalPages?r.totalPages:1;this.removeEmptyPageIfNeeded(e,u,t,a,s)}return v}tryInsertSorted(e,t,i){var r;const a=this.strategy.comparator;if(!a)return!1;if(!e.view.value)return!1;const o=(null===(r=e.params)||void 0===r?void 0:r.itemType)||"all";if(!this.isEntityTypeCompatible(t,o))return!1;const s=e.view.value.map(e=>i.getEntity(e));if(s.some(e=>!e))return!1;let n=0,l=s.length;for(;n<l;){const i=Math.floor((n+l)/2),r=a(t,s[i],e.params);if("number"!==typeof r||Number.isNaN(r))return!1;r>=0?n=i+1:l=i}return e.view.value.includes(t.id)?(e.view.updatedAt=this.now(),!0):(e.view.value=[...e.view.value.slice(0,n),t.id,...e.view.value.slice(n)],e.view.updatedAt=this.now(),e.view.meta&&"number"===typeof e.view.meta.total&&(e.view.meta.total=Number(e.view.meta.total)+1),!0)}updateChildrenCountForOperation(e,t,i,r){var a,o,s,n;const l=A(t);switch(e){case"delete":this.adjustChildrenCount(r,l,-1),null===(a=this.childrenCountInvalidator)||void 0===a||a.call(this,l);break;case"insert":case"copy":this.adjustChildrenCount(r,l,1),null===(o=this.childrenCountInvalidator)||void 0===o||o.call(this,l);break;case"move":this.adjustChildrenCount(r,i,-1),this.adjustChildrenCount(r,l,1),null===(s=this.childrenCountInvalidator)||void 0===s||s.call(this,i),null===(n=this.childrenCountInvalidator)||void 0===n||n.call(this,l)}}adjustChildrenCount(e,t,i){if(!t)return;const r=e.getFolder(t);if(r&&"number"===typeof r.childrenCount){const a=Math.max(0,r.childrenCount+i);e.updateServerChildrenCount(t,a)}}smartInvalidateChildrenViews(e,t,i,r,a,o){if(!t)return;this.updateChildrenCountForOperation(i,t,a,r);const s=this.parentKey(e),n=this.views.get(s);if(n)for(const[,u]of n){var l,d;const e=null!==(l=u.params)&&void 0!==l?l:{},o=null!==(d=null===e||void 0===e?void 0:e.page)&&void 0!==d?d:1,s=P(null===e||void 0===e?void 0:e.pageSize),v=Number.isFinite(s),f=!!(null!==e&&void 0!==e&&e.sortBy||null!==e&&void 0!==e&&e.sortOrder),m=!(null===e||void 0===e||!e.search),p=(null===e||void 0===e?void 0:e.itemType)||"all";if(!this.isEntityTypeCompatible(t,p))continue;if(m&&this.strategy.filterMatch&&!this.strategy.filterMatch(t,u.params)){var h;null!==(h=u.view.value)&&void 0!==h&&h.includes(t.id)&&(u.view.value=u.view.value.filter(e=>e!==t.id),u.view.meta&&"number"===typeof u.view.meta.total&&(u.view.meta.total=Math.max(0,u.view.meta.total-1)),u.view.updatedAt=Date.now());continue}if(!u.view.value){u.view.meta&&(u.view.meta.stale=!0),u.view.loadId=E(),u.view.abortController&&(u.view.abortController.abort(),u.view.abortController=void 0);continue}u.view.value.includes(t.id);var c;if(this.shouldInvalidateCompletely(u,i,t,f,v,o))u.view.meta={...null!==(c=u.view.meta)&&void 0!==c?c:{},stale:!0},u.view.loadId=E(),u.view.abortController&&(u.view.abortController.abort(),u.view.abortController=void 0);else switch(i){case"delete":this.handleDelete(n,u,o,s,v,t,r);break;case"insert":case"copy":this.handleInsert(n,u,o,s,v,f,t,r);break;case"update":this.handleUpdate(n,u,o,s,v,f,m,t,r);break;case"move":this.handleMove(n,u,o,s,v,f,t,a,r)}}}shouldInvalidateCompletely(e,t,i,r,a,o){return!(!(a&&o>1)||"insert"!==t&&"delete"!==t&&"move"!==t)||(!(!r||this.strategy.comparator||"insert"!==t&&"move"!==t)||!!this.isExpired(e.view.updatedAt))}tryReinsertEntity(e,t,i,r,a){var o,s;const n=(null===(o=e.params)||void 0===o?void 0:o.itemType)||"all";if(!this.isEntityTypeCompatible(t,n))return!1;if(this.strategy.comparator&&this.strategy.filterMatch){if(!this.strategy.filterMatch(t,e.params))return!1;if(this.tryInsertSorted(e,t,i))return!0}const l=null!==(s=e.params)&&void 0!==s?s:{};return!(!(!l.sortBy&&!l.sortOrder)&&!this.canSafelyModifySortedView(l))&&((!r||e.view.value.length<a)&&(e.view.value.push(t.id),!0))}handleDelete(e,t,i,r,a,o,s){const n=t.view.value.includes(o.id);if(n&&(t.view.value=t.view.value.filter(e=>e!==o.id)),t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total=Math.max(0,t.view.meta.total-1),a&&Number.isFinite(r)&&"number"===typeof t.view.meta.total){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}if(t.view.updatedAt=Date.now(),n&&a&&t.view.value.length<r&&s){var l;const a=t.view.meta,o=a&&"number"===typeof a.totalPages?a.totalPages:1;if(this.cascadeShiftPages(e,t,i,r,o,s,null!==(l=t.params)&&void 0!==l?l:{})&&t.view.meta&&"number"===typeof t.view.meta.totalPages){const i=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=i,this.updateTotalPagesForAllViews(e,i)}}t.view.loadId=E(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}handleInsert(e,t,i,r,a,o,s,n){if(!t.view.value.includes(s.id)){if(o&&this.strategy.allowSortedInsert&&this.strategy.comparator&&n){if(this.tryInsertSorted(t,s,n)&&t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total+=1,a&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}if(a&&t.view.value.length>r&&n){var l;const a=t.view.meta,o=a&&"number"===typeof a.totalPages?a.totalPages:1;if(this.cascadeShiftToNextPage(e,t,i,r,o,n,null!==(l=t.params)&&void 0!==l?l:{})&&t.view.meta&&"number"===typeof t.view.meta.totalPages){const i=t.view.meta.totalPages+1;t.view.meta.totalPages=i,this.updateTotalPagesForAllViews(e,i)}}}else if(!a||t.view.value.length<r){if(t.view.value.push(s.id),t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total+=1,a&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}t.view.updatedAt=Date.now()}else{var d;t.view.meta={...null!==(d=t.view.meta)&&void 0!==d?d:{},stale:!0}}t.view.loadId=E(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}}handleUpdate(e,t,i,r,a,o,s,n,l){var d;const h=t.view.value.includes(n.id),c=this.isEntityTypeCompatible(n,(null===(d=t.params)||void 0===d?void 0:d.itemType)||"all");if(h&&!c){if(t.view.value=t.view.value.filter(e=>e!==n.id),t.view.meta&&"number"===typeof t.view.meta.total&&(t.view.meta.total=Math.max(0,t.view.meta.total-1),a&&Number.isFinite(r)&&"number"===typeof t.view.meta.total)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}if(t.view.updatedAt=Date.now(),a&&t.view.value.length<r&&l){var u;const a=t.view.meta,o=a&&"number"===typeof a.totalPages?a.totalPages:1;if(this.cascadeShiftPages(e,t,i,r,o,l,null!==(u=t.params)&&void 0!==u?u:{})&&t.view.meta&&"number"===typeof t.view.meta.totalPages){const i=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=i,this.updateTotalPagesForAllViews(e,i)}}return t.view.loadId=E(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0))}if(h&&(o||s)){t.view.value=t.view.value.filter(e=>e!==n.id);if(this.tryReinsertEntity(t,n,l,a,r)){if(t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total+=1,a&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}}else{if(t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total=Math.max(0,t.view.meta.total-1),a&&Number.isFinite(r)&&"number"===typeof t.view.meta.total){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}if(a&&t.view.value.length<r&&l){var v;const a=t.view.meta,o=a&&"number"===typeof a.totalPages?a.totalPages:1;if(this.cascadeShiftPages(e,t,i,r,o,l,null!==(v=t.params)&&void 0!==v?v:{})&&t.view.meta&&"number"===typeof t.view.meta.totalPages){const i=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=i,this.updateTotalPagesForAllViews(e,i)}}}return t.view.updatedAt=Date.now(),t.view.loadId=E(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0))}if(h)return t.view.updatedAt=Date.now(),t.view.loadId=E(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0));if(c&&!s){if(o&&this.strategy.allowSortedInsert&&this.strategy.comparator&&l){if(this.tryInsertSorted(t,n,l)&&t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total+=1,a&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}}else if(!a||t.view.value.length<r){if(t.view.value.push(n.id),t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total+=1,a&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}t.view.updatedAt=Date.now()}else{var f;t.view.meta={...null!==(f=t.view.meta)&&void 0!==f?f:{},stale:!0}}t.view.loadId=E(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}}handleMove(e,t,i,r,a,o,s,n,l){if(t.view.value.includes(s.id)){if(t.view.value=t.view.value.filter(e=>e!==s.id),t.view.meta&&"number"===typeof t.view.meta.total&&(t.view.meta.total=Math.max(0,t.view.meta.total-1),a&&Number.isFinite(r)&&"number"===typeof t.view.meta.total)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}if(t.view.updatedAt=Date.now(),a&&t.view.value.length<r&&l){var d;const a=t.view.meta,o=a&&"number"===typeof a.totalPages?a.totalPages:1;if(this.cascadeShiftPages(e,t,i,r,o,l,null!==(d=t.params)&&void 0!==d?d:{})&&t.view.meta&&"number"===typeof t.view.meta.totalPages){const i=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=i,this.updateTotalPagesForAllViews(e,i)}}this.syncTotalsInSameViews(e,t)}t.view.loadId=E(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}forceInvalidateChildrenViews(e){const t=this.parentKey(null!==e&&void 0!==e?e:null),i=this.views.get(t);if(i)for(const[,r]of i)r.view.value=void 0,r.view.error=null,r.view.meta=void 0,r.view.promise=null,r.view.updatedAt=0,r.view.loadId=E(),r.view.abortController&&(r.view.abortController.abort(),r.view.abortController=void 0)}getKnownTotal(e){const t=this.parentKey(null!==e&&void 0!==e?e:null),i=this.views.get(t);if(!i)return;let r=null;for(const[,s]of i){const e=s.view.meta;var a,o;if(e&&"number"===typeof e.total)if(!r||(null!==(a=s.view.updatedAt)&&void 0!==a?a:0)>r.updatedAt)r={total:Number(e.total),updatedAt:null!==(o=s.view.updatedAt)&&void 0!==o?o:0}}return r?r.total:void 0}toJSON(){return{views:Array.from(this.views.entries()).map(([e,t])=>[e,Array.from(t.entries())]),ttl:this.ttl,errorTtl:this.errorTtl,entityTtl:this.entityTtl,strategy:{allowSortedInsert:this.strategy.allowSortedInsert,allowSearchInsert:this.strategy.allowSearchInsert,invalidateOnPaginationFull:this.strategy.invalidateOnPaginationFull,preloadPagesBefore:this.strategy.preloadPagesBefore,preloadPagesAfter:this.strategy.preloadPagesAfter}}}static fromJSON(e){const t=new T;for(const[r,a]of null!==(i=e.views)&&void 0!==i?i:[]){var i;const e=new Map;for(const[t,i]of a)e.set(t,i);t.views.set(r,e)}return t}}class O{invalidateChildrenCountCache(e){const t=C(null!==e&&void 0!==e?e:"");this.childrenCountPromises.delete(t)}constructor(e={},t=3e5,i=3e4){this.entities=void 0,this.views=void 0,this.ttl=void 0,this.errorTtl=void 0,this.childrenCountPromises=new Map,this.ttl=t,this.errorTtl=i,this.entities=new S,this.views=new T(e,t,i),this.views.setServerChildrenCountHandler((e,t,i)=>{this.handleServerReportedChildrenCount(e,t,null!==i&&void 0!==i?i:this.entities)}),this.views.setChildrenCountInvalidator(e=>{this.invalidateChildrenCountCache(e)})}getEntity(e){var t;return null!==(t=this.entities.getEntity(e))&&void 0!==t?t:null}getFileSystemItem(e){var t;return null!==(t=this.entities.getFileSystemItem(e))&&void 0!==t?t:null}getFolder(e){var t;return null!==(t=this.entities.getFolder(e))&&void 0!==t?t:null}async getOrCreateChildren(e,t,i){return this.views.getOrCreateChildren(e,t,i,this.entities)}upsertEntity(e){const t=this.entities.getEntity(e.id),i=t?A(t):null,r=A(e),a=!!t&&b(t),o=b(e);if(this.entities.upsertEntity(e),t){if(i!==r||a!==o)return this.views.smartInvalidateChildrenViews(i,t,"delete",this.entities),void this.views.smartInvalidateChildrenViews(r,e,"insert",this.entities);this.views.smartInvalidateChildrenViews(r,e,"update",this.entities,void 0,t)}else this.views.smartInvalidateChildrenViews(r,e,"insert",this.entities)}isAncestor(e,t){let i=t;const r=new Set;for(;i&&!r.has(i);){r.add(i);if(C(i)===C(e))return!0;const t=this.entities.getEntity(i);if(!t)break;i=A(t),null===i&&(i="")}return!1}moveEntity(e,t){const i=this.entities.getEntity(e);if(!i)return null;if(b(i)&&null!==t&&this.isAncestor(e,t))return null;const r=A(i),a=this.entities.moveEntityById(e,t);return a?(this.views.smartInvalidateChildrenViews(r,i,"delete",this.entities),this.views.smartInvalidateChildrenViews(t,a,"insert",this.entities),a):null}copyEntity(e,t,i,r){const a=this.entities.getEntity(e);if(!a)return null;let o=null;if(b(a)){var s;const i=[e],a=[];for(;i.length;){const e=i.shift();a.push(e);const t=this.entities.getChildrenIds(e,{onlyFolders:!0});for(const r of t)i.push(r)}const d=new Map;for(const e of a)d.set(e,E());for(const o of a){var n,l;const i=this.entities.getFolder(o),a=d.get(o),s=A(i),h=null===s?t:null!==(n=d.get(s))&&void 0!==n?n:null,c={...i,...o===e?r:void 0,id:a,folderId:null!==(l=o===e?null===r||void 0===r?void 0:r.folderId:void 0)&&void 0!==l?l:h};this.entities.upsertEntity(c)}for(const e of a){const t=d.get(e),i=this.entities.getChildrenIds(e,{onlyFileSystemItems:!0});for(const e of i){const i=this.entities.getFileSystemItem(e);if(!i)continue;const r=E(),a={...i,id:r,folderId:t};this.entities.upsertEntity(a)}}o=null!==(s=this.entities.getEntity(d.get(e)))&&void 0!==s?s:null}else{const a=null!==i&&void 0!==i?i:E();if(o=this.entities.copyFileSystemItem(e,a,null!==t&&void 0!==t?t:null),o&&r){var d,h;const e={...o,...r,id:a,folderId:null!==(d=null!==(h=r.folderId)&&void 0!==h?h:t)&&void 0!==d?d:null};this.entities.upsertEntity(e),o=e}}return o&&this.views.smartInvalidateChildrenViews(t,o,"copy",this.entities),o}searchByUrl(e){var t;return null!==(t=this.entities.searchByUrl(e))&&void 0!==t?t:null}deleteEntity(e){const t=this.entities.getEntity(e);if(!t)return null;if(b(t)){const{deletedFolderRecords:i,deletedFileSystemItemRecords:r}=this.entities.deleteFolderRecursive(e);for(const e of r)this.views.smartInvalidateChildrenViews(e.folderId,e,"delete",this.entities);for(const e of i)this.views.smartInvalidateChildrenViews(e.folderId,e,"delete",this.entities);for(const e of i)this.views.forceInvalidateChildrenViews(e.id);return t}{const{entity:t,parentId:i}=this.entities.deleteEntityById(e);return t&&this.views.smartInvalidateChildrenViews(i,t,"delete",this.entities),t}}deleteFolderRecursive(e){const{deletedFolderRecords:t,deletedFileSystemItemRecords:i}=this.entities.deleteFolderRecursive(e);for(const r of i)this.views.smartInvalidateChildrenViews(r.folderId,r,"delete",this.entities);for(const r of t)this.views.smartInvalidateChildrenViews(r.folderId,r,"delete",this.entities);for(const r of t)this.views.forceInvalidateChildrenViews(r.id);return{deletedFileSystemItemIds:i.map(e=>e.id),deletedFolderIds:t.map(e=>e.id)}}forceInvalidate(e){const t=this.entities.getEntity(e);if(!t)return;const i=new Set;if(b(t)){const t=[e];for(;t.length;){const e=t.pop();if(i.has(e))continue;i.add(e),this.views.forceInvalidateChildrenViews(e);const r=this.entities.getChildrenIds(e,{onlyFolders:!0});for(const i of r)t.push(i)}}else{var r;const e=null!==(r=t.folderId)&&void 0!==r?r:null;this.views.forceInvalidateChildrenViews(e)}}getChildrenIds(e){return this.entities.getChildrenIds(e)}searchByName(e,t){return this.entities.searchByName(e,t)}async getChildrenCount(e="",t){const i=C(e),r=this.childrenCountPromises.get(i);if(r)return r;const a=(async()=>{try{const i=this.entities.getFolder(e);if(i&&"number"===typeof i.childrenCount)return i.childrenCount;const r=this.views.getKnownTotal(e);if("number"===typeof r)return i&&this.handleServerReportedChildrenCount(e,r,this.entities),r;if(t){const i=await t(e);return this.entities.getFolder(e)&&this.handleServerReportedChildrenCount(e,i,this.entities),i}return this.entities.getChildrenIds(e).length}catch(r){if(this.childrenCountPromises.delete(i),function(e){var t,i,r;if(!e||"object"!==typeof e)return!1;const a=e;return"path_folder_not_found"===a.code||"path_folder_not_found"===(null===(t=a.data)||void 0===t?void 0:t.code)||404===a.status||404===(null===(i=a.data)||void 0===i||null===(r=i.data)||void 0===r?void 0:r.status)}(r))return 0;throw r}finally{this.childrenCountPromises.delete(i)}})();return this.childrenCountPromises.set(i,a),a}toJSON(){return{entities:this.entities.toJSON(),views:this.views.toJSON(),ttl:this.ttl,errorTtl:this.errorTtl}}static fromJSON(e,t){var i,r,a,o;const s=new O(null!==t&&void 0!==t?t:{},null!==(i=null===e||void 0===e?void 0:e.ttl)&&void 0!==i?i:3e5,null!==(r=null===e||void 0===e?void 0:e.errorTtl)&&void 0!==r?r:3e4),n=S.fromJSON(null!==(a=null===e||void 0===e?void 0:e.entities)&&void 0!==a?a:{}),l=T.fromJSON(null!==(o=null===e||void 0===e?void 0:e.views)&&void 0!==o?o:{});var d,h,c,u,v;t&&(l.strategy={allowSortedInsert:null===(d=t.allowSortedInsert)||void 0===d||d,allowSearchInsert:null===(h=t.allowSearchInsert)||void 0===h||h,invalidateOnPaginationFull:null===(c=t.invalidateOnPaginationFull)||void 0===c||c,preloadPagesBefore:null!==(u=t.preloadPagesBefore)&&void 0!==u?u:0,preloadPagesAfter:null!==(v=t.preloadPagesAfter)&&void 0!==v?v:1,comparator:t.comparator,filterMatch:t.filterMatch});return s.entities=n,s.views=l,l.setServerChildrenCountHandler((e,t,i)=>{s.handleServerReportedChildrenCount(e,t,null!==i&&void 0!==i?i:n)}),l.setChildrenCountInvalidator(e=>{s.invalidateChildrenCountCache(e)}),s}handleServerReportedChildrenCount(e,t,i){this.checkAndResolveChildrenCountConflict(e,t,i),this.invalidateChildrenCountCache(e)}checkAndResolveChildrenCountConflict(e,t,i){if(!i||void 0===t)return;const r=null!==e&&void 0!==e?e:null;if(!r)return void i.updateServerChildrenCount(r,t);const a=i.getFolder(r),o=null===a||void 0===a?void 0:a.childrenCount;void 0!==o&&o!==t&&this.views.forceInvalidateChildrenViews(r),i.updateServerChildrenCount(r,t)}}var N,D=i(2783);function U(e,t){const i=null!==e&&void 0!==e?e:{},r=Array.isArray(i.detailed)?i.detailed.map(e=>{var i;return{requestId:null!==(i=e.requestId)&&void 0!==i?i:e.id,success:!!e.success,data:t(e.data),error:e.error}}):void 0;return{success:!!i.success,error:i.error,detailed:r}}let x=(B=N=class{async _findOrCreateFolderByPath(e){const{__:t}=this.i18n,i=(r=e)?r.replaceAll("\\","/").split("/").filter(Boolean):[];var r;if(i.length>10){const e=t("Path depth exceeds maximum limit of %s").replace("%s",String(10));throw new D.FileManagerApiError(e,"ValidationError")}let a;for(const n of i){var o;const{files:i}=await this.getFiles({folderId:(null===(o=a)||void 0===o?void 0:o.id)||"",itemType:"folder"}),r=i.find(e=>e.name===n);if(r){if(!r.isFolder){const i=t("Path component '%s' in '%s' is not a folder").replace("%s",n).replace("%s",e);throw new D.FileManagerApiError(i,"ValidationError")}a={id:r.id,name:r.name,parentId:r.folderId}}else{var s;if(!this._dataProvider.createFolder)throw new D.FileManagerApiError(t("Create folder operation is not supported by data provider"),"UnsupportedOperation");a=await this.createFolder({name:n,parentId:null===(s=a)||void 0===s?void 0:s.id})}}return a}getTrashFolder(){return this._findOrCreateFolderByPath(this._pathOptions.trashPath||"Trash")}getTempFolder(){return this._findOrCreateFolderByPath(this._pathOptions.tempPath||"Edited")}constructor(e,t={},i,r=_.nr){var a,o;this._dataProvider=e,this._options=t,this._pathOptions=i,this.i18n=r,this._cache=void 0,this._rootId=void 0,this._useSoftDelete=void 0,this._enableTrash=void 0,this._validateDuplicates=void 0,this._mapItem=async({childrenCount:e,...t})=>{if(t.isFolder)return{...t,childCount:e,url:"",thumbnailUrl:""};const[i,r]=await Promise.all([this._getUrl(t),this._getThumbnailUrl(t)]);return{...t,childCount:0,url:i,thumbnailUrl:r}},this._useSoftDelete=this._pathOptions.useSoftDelete,this._rootId=this._pathOptions.rootId||"",this._enableTrash=void 0===this._options.enableTrash||this._options.enableTrash,this._validateDuplicates=this._dataProvider.validateDuplicates,this._cache=new O(t.cacheStrategy||{},null===(a=t.cacheStrategy)||void 0===a?void 0:a.ttl,null===(o=t.cacheStrategy)||void 0===o?void 0:o.errorTtl),this.setController({invalidateItemCache:e=>{this._cache.forceInvalidate(e)},getCachedItem:e=>this._cache.getEntity(e)}),this._dataProvider.clearCache||(this.clearCache=void 0)}setController(e){var t,i;null===(t=(i=this._dataProvider).setController)||void 0===t||t.call(i,e)}async clearCache(e){if(!this._dataProvider.clearCache){const{__:e}=this.i18n;throw new D.FileManagerApiError(e("Clear cache is not supported by data provider"),"UnsupportedOperation")}this._cache.forceInvalidate(this._rootId),await this._dataProvider.clearCache(e)}normalizeId(e){return e?"root"===e||"folders"===e?this._rootId:e:this._rootId}_validateName(e,t=!1){if(!e||0===e.trim().length){const e=t?"FolderInvalidName":"FileInvalidName",{__:i}=this.i18n,r=i(t?"Folder name cannot be empty":"File name cannot be empty");throw new D.FileManagerApiError(r,e)}if(/[\/\\:*?"<>|]/.test(e)){const{__:i}=this.i18n,r=t?"FolderInvalidName":"FileInvalidName",a=t?i("Folder name contains invalid characters: %s").replace("%s",e):i("File name contains invalid characters: %s").replace("%s",e);throw new D.FileManagerApiError(a,r)}}_validateTargetFolderType(e){const t=this.normalizeId(e);if(t===this._rootId)return;const i=this._cache.getEntity(t);if(i&&!i.isFolder){const{__:t}=this.i18n,i=t("Target item with id '%s' is not a folder").replace("%s",e);throw new D.FileManagerApiError(i,"ValidationError")}}_checkNameExistsInCache(e,t,i,r){const a=this.normalizeId(e),o=this._cache.getChildrenIds(a);for(const s of o){const e=this._cache.getEntity(s);if(e&&e.name===t&&!!e.isFolder===i&&(!r||e.id!==r))return!0}return!1}async _getUrl(e){if(e.url)return e.url;try{var t;return(null===(t=this._dataProvider)||void 0===t?void 0:t.getUrl(e))||""}catch(i){}return""}async _getThumbnailUrl(e){if(e.thumbnailUrl)return e.thumbnailUrl;try{var t;return(null===(t=this._dataProvider)||void 0===t?void 0:t.getThumbnailUrl(e))||""}catch(i){}return""}_isAncestor(e,t){if(!t)return!1;const i=this.normalizeId(t),r=this.normalizeId(e);if(i===r)return!0;let a=this._cache.getEntity(i);const o=new Set;for(;a&&a.folderId&&!o.has(a.id);){o.add(a.id);const e=this.normalizeId(a.folderId);if(e===r)return!0;if(a=this._cache.getEntity(e),!a||!a.isFolder)break}return!1}async getFile(e,t){return this._cache.searchByName(t,{parentId:this.normalizeId(e),caseSensitive:!0,recursive:!1,itemType:"file"})[0]||(await this.getFiles({folderId:e,itemType:"file",search:t})).files[0]}async getFileUrl(e,t){const i=await this.getFile(e,t);return await this._getUrl(i)||await this._getThumbnailUrl(i)||i.thumbnail}async getFiles({folderId:e,search:t,sortBy:i,sortOrder:r,page:a,limit:o,itemType:s="all"}){const n=this.normalizeId(null!==e&&void 0!==e?e:this._rootId),l=!1===this._options.enablePagination,d=l?1:a,h=l?1e3:o,c=this._options.clientSideFilter,u=this._options.clientSideSorting,v=this._options.clientSidePaging,f={folderId:n,itemType:s};c||(f.search=t),u||(f.sortBy=null!==i&&void 0!==i?i:"folder"!==s?"date":void 0,f.sortOrder=null!==r&&void 0!==r?r:"folder"!==s?"desc":void 0),v||(f.page=d,f.limit=h);const m={folderId:n,itemType:s,search:c?void 0:t,sortBy:u?void 0:f.sortBy,sortOrder:u?void 0:f.sortOrder,page:v?void 0:d,pageSize:v?void 0:h},p=await this._cache.getOrCreateChildren(n,m,async(e,t)=>{const i=await this._dataProvider.getItems({...t,folderId:e,limit:Number(t.pageSize)});return{items:i.items,...i.pagination}});let w,g=p.items;if(c)if("function"===typeof this._options.clientSideFilter)g=this._options.clientSideFilter(g,t);else if(t){const e=t.toLowerCase();g=g.filter(t=>{var i;return null===(i=t.name)||void 0===i?void 0:i.toLowerCase().includes(e)})}u&&(g="function"===typeof this._options.clientSideSorting?this._options.clientSideSorting(g,i,r):this._defaultClientSideSort(g,i,r)),w=v||c?g.length:p.total;let I=g;if(v&&a&&o)if("function"===typeof this._options.clientSidePaging)I=this._options.clientSidePaging(g,a,o);else{const e=(a-1)*o,t=e+o;I=g.slice(e,t)}if(this._dataProvider.getUrl||this._dataProvider.getThumbnailUrl){const e=I.map(async e=>{if(e.isFolder)return e;const[t,i]=await Promise.all([e.url?Promise.resolve(e.url):this._dataProvider.getUrl?this._dataProvider.getUrl(e):Promise.resolve(void 0),e.thumbnailUrl?Promise.resolve(e.thumbnailUrl):this._dataProvider.getThumbnailUrl?this._dataProvider.getThumbnailUrl(e):Promise.resolve(void 0)]);return{...e,url:t,thumbnailUrl:i}});I=await Promise.all(e)}const y={page:d,limit:h,total:w,...!v&&p.totalPages&&{totalPages:p.totalPages},...!v&&p.hasNextPage&&{hasNextPage:p.hasNextPage}};return{files:await Promise.all(I.map(this._mapItem)),pagination:y}}_defaultClientSideSort(e,t,i){return e.sort((e,r)=>{let a=0;switch(t){case"name":default:a=(e.name||"").localeCompare(r.name||"");break;case"date":a=new Date(e.date||0).getTime()-new Date(r.date||0).getTime();break;case"size":a=(Number(e.size)||0)-(Number(r.size)||0)}return"desc"===i?-a:a})}async getFileData(e){const t=this.normalizeId("string"===typeof e?e:e.id),i=this._cache.getEntity(t)||("string"===typeof e?{id:t,name:"",folderId:this._rootId,isFolder:!1}:{...e,childrenCount:e.childCount});if(this._dataProvider.getFileData)return await this._dataProvider.getFileData(i);const{__:r}=this.i18n;if(!i.url&&!this._dataProvider.getUrl)throw new D.FileManagerApiError(r("Cannot read file"),"FileReadError");const a=i.url||await this._dataProvider.getUrl(i);if(a)return(await fetch(a)).blob();throw new D.FileManagerApiError(r("Unable to get file data"),"FileReadError")}async findFileByUrl(e){const t=this._cache.searchByUrl(e);if(t)return t;if(this._dataProvider.findFileByUrl)try{const t=await this._dataProvider.findFileByUrl(e);if(t)return this._cache.upsertEntity(t),t}catch(i){}return null}async getChildrenCount(e){if(!e)return 0;const t=this.normalizeId(null!==e&&void 0!==e?e:this._rootId);return this._cache.getChildrenCount(t,async()=>{try{const e=await this._dataProvider.getItems({folderId:t,limit:0,itemType:"all"});return"undefined"!==typeof e.pagination?e.pagination.total||0:!1===this._options.enablePagination?e.items.length:0}catch(e){if(this._isPathFolderNotFoundError(e))return 0;throw e}})}_isPathFolderNotFoundError(e){var t,i,r;if(!e||"object"!==typeof e)return!1;const a=e;return"path_folder_not_found"===a.code||"path_folder_not_found"===(null===(t=a.data)||void 0===t?void 0:t.code)||404===a.status||404===(null===(i=a.data)||void 0===i||null===(r=i.data)||void 0===r?void 0:r.status)}async _uploadFile(e){var t;const i=this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:this._rootId);if(this._validateName(e.name,!1),this._validateDuplicates&&this._checkNameExistsInCache(i,e.name,!1)){const{__:t}=this.i18n,i=t("File '%s' already exists in target folder").replace("%s",e.name);throw new D.FileManagerApiError(i,"FileAlreadyExists")}const r={...this._cache.getEntity(i),...await this._dataProvider.uploadFile({...e,folderId:i}),folderId:i};return this._cache.upsertEntity(r),r}async uploadFiles(e){var t,i;const r=(e={...e,items:null===(t=e.items)||void 0===t?void 0:t.map(e=>({...e,folderId:e.noFolder?o.id:e.folderId}))}).items||[],a=null!==(i=e.folderId)&&void 0!==i?i:this._rootId,o=await this.getTempFolder(),s=this.normalizeId(a);if(this._validateDuplicates)for(const v of r)if(v.name){var n;this._validateName(v.name,!1);const e=this.normalizeId(null!==(n=v.folderId)&&void 0!==n?n:s);if(this._checkNameExistsInCache(e,v.name,!1)){const{__:e}=this.i18n,t=e("File '%s' already exists in target folder").replace("%s",v.name);throw new D.FileManagerApiError(t,"FileAlreadyExists")}}const l=this._cache.getEntity(s);let d={detailed:new Array(r.length),success:!0};if(this._dataProvider.uploadFiles){const e=r.map(e=>{var t;return{...e,folderId:this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:s)}});if(d=U(await this._dataProvider.uploadFiles({folderId:s,items:e}),e=>{if(e)return{id:e.id,name:e.name,folderId:e.folderId}}),d.detailed&&d.detailed.length){for(let e=0;e<d.detailed.length;e++){const t=d.detailed[e];if(t&&t.success){var h,c;const e=t.data,i=null!==(h=null===e||void 0===e?void 0:e.id)&&void 0!==h?h:t.requestId,r={...l,...e,folderId:null!==(c=null===e||void 0===e?void 0:e.folderId)&&void 0!==c?c:s};this._cache.upsertEntity(r),t.requestId=i}}void 0===d.success&&(d.success=!d.detailed.some(e=>!e.success))}else d.success=!d.error&&!!d.success}else{if(!this._dataProvider.uploadFile)throw new D.FileManagerApiError("Upload files is not supported by data provider","UnsupportedOperation");d.detailed=await Promise.all(r.map(async e=>{var t;const i=this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:s);try{const t=await this._uploadFile({...e,folderId:i});return{requestId:t.id,data:t,success:!0}}catch(r){return{requestId:null===e||void 0===e?void 0:e.id,success:!1,error:r}}})),d.success=!d.detailed.some(e=>!e.success)}if(d.success&&this._enableTrash)try{this._cache.forceInvalidate(s)}catch(u){}return d}async deleteFile(e){const t=this.normalizeId(e);if(this._useSoftDelete&&this._enableTrash){const e=await this.getTrashFolder();return await this.moveItem({itemId:t,targetFolderId:e.id,isFolder:!1})}return await this.hardDeleteItem(t)}async deleteItems(e,t){if(this._useSoftDelete&&this._enableTrash&&!0!==t.permanent){const t=await this.getTrashFolder();return await this.moveItems(t.id,e)}return await this.hardDeleteItems(e,t)}async hardDeleteItems(e,t){let i={success:!0,detailed:[]};const r=t.permanent?null:await this.getTrashFolder();if(this._dataProvider.deleteItems){if(i=U(await this._dataProvider.deleteItems(e.map(e=>this._cache.getEntity(e)),t),e=>e),i.success){const t=i.detailed||e.map(e=>({requestId:e,success:!0,error:void 0}));for(const e of t)e.success&&(r?this._cache.moveEntity(e.requestId,r.id):this._cache.deleteEntity(e.requestId))}}else this._dataProvider.deleteItem&&(i.detailed=await Promise.all(e.map(async e=>{const i=this._cache.getEntity(e);if(!i){const t="FileNotFound",{__:i}=this.i18n,r=i("Item with id '%s' not found").replace("%s",e);return{requestId:e,success:!1,error:new D.FileManagerApiError(r,t)}}try{return await this._dataProvider.deleteItem(i,t),r?this._cache.moveEntity(e,r.id):this._cache.deleteEntity(e),{requestId:e,success:!0}}catch(a){return{requestId:e,error:a,success:!1}}})),i.success=!i.detailed.some(e=>!e.success));if(i.success&&r)try{this._cache.forceInvalidate(r.id)}catch(a){}return i}async hardDeleteItem(e){const t=this._cache.getEntity(e);if(!t){const{__:t}=this.i18n,i=t("Item with id '%s' not found in cache").replace("%s",e);throw new D.FileManagerApiError(i,"FileNotFound")}if(await this._dataProvider.deleteItem(t,{permanent:!0}),this._cache.deleteEntity(e),this._enableTrash)try{const e=await this.getTrashFolder();e&&this._cache.forceInvalidate(e.id)}catch(i){}return!0}async cleanTrash(){const{__:e}=this.i18n;if(!this._enableTrash)throw new D.FileManagerApiError(e("Trash is not enabled"),"UnsupportedOperation");if(this._dataProvider.cleanTrash){const e=await this._dataProvider.cleanTrash();try{const e=await this.getTrashFolder();e&&this._cache.forceInvalidate(e.id)}catch(t){}return e}throw new D.FileManagerApiError(e("Clean trash is not supported by data provider"),"UnsupportedOperation")}async createFolder({name:e,parentId:t,is_force_create:i}){const r=this.normalizeId(null!==t&&void 0!==t?t:this._rootId);if(this._validateName(e,!0),this._validateDuplicates&&this._checkNameExistsInCache(r,e,!0)){const{__:t}=this.i18n,i=t("Folder '%s' already exists in parent folder").replace("%s",e);throw new D.FileManagerApiError(i,"FolderAlreadyExists")}const a=await this._dataProvider.createFolder(e,r,i);return this._cache.upsertEntity({id:a.id,folderId:r,name:a.name,isFolder:!0,childrenCount:a.childrenCount}),a}async deleteFolder(e){const t=this.normalizeId(e);if(this._useSoftDelete&&this._enableTrash)try{const e=await this.getTrashFolder();return!!await this.moveItem({itemId:t,targetFolderId:e.id,isFolder:!0})&&(this._cache.deleteFolderRecursive(t),!0)}catch(i){return await this.hardDeleteItem(t)}return await this.hardDeleteItem(t)}async renameFolder(e,t){const{__:i}=this.i18n;if(!this._dataProvider.renameItem)throw new D.FileManagerApiError(i("Rename folder is not supported"),"RenameNotAllowed");const r=this.normalizeId(e),a=this._cache.getEntity(r);if(!a){const t=i("Folder with id '%s' not found in cache").replace("%s",e);throw new D.FileManagerApiError(t,"FolderNotFound")}if(this._validateName(t,!0),this._validateDuplicates){const e=this.normalizeId(a.folderId);if(this._checkNameExistsInCache(e,t,!0,r)){const e=i("Folder '%s' already exists in parent folder").replace("%s",t);throw new D.FileManagerApiError(e,"FolderAlreadyExists")}}const o=await this._dataProvider.renameItem(a,t);return this._cache.upsertEntity({...this._cache.getEntity(o.id),...o}),this._cache.getEntity(o.id)}async renameFile(e,t){const{__:i}=this.i18n;if(!this._dataProvider.renameItem)throw new D.FileManagerApiError(i("Rename file is not supported"),"RenameNotAllowed");const r=this._cache.getEntity(e);if(!r){const t=i("File with id '%s' not found in cache").replace("%s",e);throw new D.FileManagerApiError(t,"FileNotFound")}const a=this.normalizeId(e);if(this._validateName(t,!1),this._validateDuplicates){const e=this.normalizeId(r.folderId);if(this._checkNameExistsInCache(e,t,!1,a)){const e=i("File '%s' already exists in parent folder").replace("%s",t);throw new D.FileManagerApiError(e,"FileAlreadyExists")}}const o=await this._dataProvider.renameItem(r,t);return o&&this._cache.upsertEntity({...this._cache.getEntity(a),...o}),this._cache.getEntity(a)}async moveItem({itemId:e,targetFolderId:t,isFolder:i}){const r=this.normalizeId(t);this._validateTargetFolderType(t);const a=this._cache.getEntity(e);if(!a){const t=await this._dataProvider.moveItem({id:e,folderId:r,isFolder:i},r);if(t.id===e)this._cache.upsertEntity({...t,folderId:r});else{try{this._cache.deleteEntity(e)}catch(n){}this._cache.upsertEntity({...t,folderId:r})}return!0}const{__:o}=this.i18n;if(a.isFolder){if(e===r)throw new D.FileManagerApiError(o("Cannot move folder into itself"),"MoveIntoSelf");if(this._isAncestor(e,r))throw new D.FileManagerApiError(o("Cannot move folder into its descendant"),"MoveIntoDescendant")}if(this._validateDuplicates&&r!==this.normalizeId(a.folderId)&&a.name&&this._checkNameExistsInCache(r,a.name,!!a.isFolder,e)){const e=a.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new D.FileManagerApiError(`${a.isFolder?"Folder":"File"} '${a.name}' already exists in target folder`,e)}const s=await this._dataProvider.moveItem(a,r);if(s.id===e){const t=this._cache.moveEntity(e,r);return this._cache.upsertEntity({...t,...s}),!0}{const t=this._cache.deleteEntity(e);return this._cache.upsertEntity({...t,...s,folderId:r}),!0}}async moveItems(e,t){const i=this.normalizeId(e);this._validateTargetFolderType(e);const r=t.map(e=>this._cache.getEntity(e));for(const o of r)if(o){if(o.isFolder){const{__:e}=this.i18n;if(o.id===i){const t=e("Cannot move folder '%s' into itself").replace("%s",o.name);throw new D.FileManagerApiError(t,"MoveIntoSelf")}if(this._isAncestor(o.id,i)){const t=e("Cannot move folder '%s' into its descendant").replace("%s",o.name);throw new D.FileManagerApiError(t,"MoveIntoDescendant")}}if(this._validateDuplicates){const e=this.normalizeId(o.folderId);if(i!==e&&o.name&&this._checkNameExistsInCache(i,o.name,!!o.isFolder,o.id)){const e=o.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new D.FileManagerApiError(`${o.isFolder?"Folder":"File"} '${o.name}' already exists in target folder`,e)}}}let a={detailed:new Array(r.length),success:!0};if(this._dataProvider.moveItems)a=U(await this._dataProvider.moveItems(r,i),e=>e);else{if(!this._dataProvider.moveItem)throw new D.FileManagerApiError("Move items is not supported","MoveNotAllowed");a.detailed=await Promise.all(t.map(async(e,t)=>{const a=r[t]||{id:e,folderId:null,isFolder:!1,name:e};try{return{requestId:e,data:await this._dataProvider.moveItem(a,i),success:!0}}catch(o){return{requestId:e,success:!1,error:o}}}))}if(a.success){const e=a.detailed||t.map(e=>({requestId:e,success:!0,data:void 0}));for(const t of e)if(t.success)if(t.data&&t.data.id!==t.requestId){const e=this._cache.deleteEntity(t.requestId);this._cache.upsertEntity({...e,...t.data,folderId:i})}else this._cache.moveEntity(t.requestId,i),t.data&&this._cache.upsertEntity({...this._cache.getEntity(t.requestId),...t.data,folderId:i});return a}{const{__:e}=this.i18n;return{success:!1,error:a.error||new D.FileManagerApiError(e("Move items failed"),"MoveNotAllowed")}}}async copyItem({itemId:e,targetFolderId:t}){if(!this._dataProvider.copyItem){const{__:e}=this.i18n;throw new D.FileManagerApiError(e("Copy item is not supported"),"CopyNotAllowed")}const i=this.normalizeId(t);this._validateTargetFolderType(t);const r=this._cache.getEntity(e);if(!r){const t=await this._dataProvider.copyItem({id:e,folderId:i},i);return this._cache.copyEntity(e,i,t.id),this._cache.upsertEntity({...t,folderId:i}),!0}if(this._validateDuplicates&&r.name){const t=i===this.normalizeId(r.folderId)?e:void 0;if(this._checkNameExistsInCache(i,r.name,!!r.isFolder,t)){const e=r.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new D.FileManagerApiError(`${r.isFolder?"Folder":"File"} '${r.name}' already exists in target folder`,e)}}const a=await this._dataProvider.copyItem(r,i);return this._cache.copyEntity(e,i,a.id,{...a,folderId:i})||this._cache.upsertEntity({...a,folderId:i}),!0}async copyItems(e,t){const i=this.normalizeId(e);this._validateTargetFolderType(e);const r=t.map(e=>"string"===typeof e?{id:e}:e),a=r.map(e=>e.id),o=a.map((e,t)=>{var i;const a=this._cache.getEntity(e),o=null===(i=r[t])||void 0===i?void 0:i.newName;return a?o?{...a,name:o}:a:void 0});if(this._validateDuplicates)for(let l=0;l<o.length;l++){const e=o[l];if(e&&e.name){const t=this.normalizeId(e.folderId),r=i===t?a[l]:void 0;if(this._checkNameExistsInCache(i,e.name,!!e.isFolder,r)){const t=e.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new D.FileManagerApiError(`${e.isFolder?"Folder":"File"} '${e.name}' already exists in target folder`,t)}}}let s={detailed:new Array(o.length),success:!0};if(this._dataProvider.copyItems)s=U(await this._dataProvider.copyItems(o,i),e=>e);else{if(!this._dataProvider.copyItem){const{__:e}=this.i18n;throw new D.FileManagerApiError(e("Copy items is not supported"),"CopyNotAllowed")}s.detailed=await Promise.all(a.map(async(e,t)=>{const r=o[t]||{id:e,folderId:null,isFolder:!1};try{return{requestId:e,data:await this._dataProvider.copyItem(r,i),success:!0}}catch(a){return{requestId:e,success:!1,error:a}}}))}if(s.success&&s.detailed)for(let l=0,d=s.detailed.length;l<d;l++){const e=s.detailed[l];var n;if(e.success&&null!==(n=e.data)&&void 0!==n&&n.id){const t=e.data.folderId||i;!this._cache.copyEntity(e.requestId,t,e.data.id,{...e.data,folderId:t})&&e.data&&this._cache.upsertEntity({...e.data,folderId:t})}}else if(!s.detailed)throw new D.FileManagerApiError("batchResult in copy method must have detailed results","ValidationError");return s}async uploadFileByUrl(e){var t;if(e.noFolder){const t=await this.getTempFolder();e={...e,folderId:t.id}}const i=this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:this._rootId);try{const t=await this._dataProvider.uploadFileByUrl(e.url,i,{eventSource:e.eventSource});return this._cache.upsertEntity({...t,folderId:i}),t}catch(r){throw r}}async updateFile(e,t){const{__:i}=this.i18n;if(!this._dataProvider.updateFile)throw new D.FileManagerApiError(i("Update file is not supported"),"UnsupportedOperation");const r=this.normalizeId(e),a=this._cache.getEntity(r);if(!a){const t=i("File with id '%s' not found in cache").replace("%s",e);throw new D.FileManagerApiError(t,"FileNotFound")}if(t.name&&t.name!==a.name&&this._validateName(t.name,!1),this._validateDuplicates&&t.name&&t.name!==a.name){const e=this.normalizeId(a.folderId);if(this._checkNameExistsInCache(e,t.name,!1,r)){const e=i("File '%s' already exists in parent folder").replace("%s",t.name);throw new D.FileManagerApiError(e,"FileAlreadyExists")}}const o=await this._dataProvider.updateFile(a,{...t});return this._cache.upsertEntity({...this._cache.getEntity(r),...o,...t}),this._cache.getEntity(r)}},class extends B{constructor(...e){super(...e);const t=Object.getOwnPropertyNames(B.prototype);for(const i of t){const e=Object.getOwnPropertyDescriptor(B.prototype,i);"constructor"!==i&&"function"===typeof(null===e||void 0===e?void 0:e.value)&&this[i]&&(this[i]=this[i].bind(this))}}}||N);var B,R=i(93628),k=i(93506),z=(i(80708),i(10968));class G{constructor(e,t="",i="Trash",r="Trash",a=!0,o=_.nr){this._inner=e,this.rootPath=t,this.trashId=i,this.trashPath=r,this.ensureFolderTrailingSlash=a,this.i18n=o,this._pathToId=new Map,this._idToPath=new Map,this.getUrl=void 0,this.getThumbnailUrl=void 0,this.validateDuplicates=void 0,this.validateDuplicates=this._inner.validateDuplicates,e.getUrl&&(this.getUrl=t=>e.getUrl({...t,id:this.pathForId(t.id,!1),folderId:t.folderId?this.pathForId(t.folderId,!0):this.rootPath})),e.getThumbnailUrl&&(this.getThumbnailUrl=t=>e.getThumbnailUrl({...t,id:this.pathForId(t.id,!1),folderId:t.folderId?this.pathForId(t.folderId,!0):this.rootPath})),this._inner.deleteItems||(this.deleteItems=void 0),this._inner.deleteItem||(this.deleteItem=void 0),this._inner.moveItems?this.moveItem=void 0:this.moveItems=void 0,this._inner.copyItems?this.copyItem=void 0:this.copyItems=void 0,this._inner.uploadFiles?this.uploadFile=void 0:this.uploadFiles=void 0,this._inner.clearCache||(this.clearCache=void 0),this._getOrGenerateId(this.rootPath)}setController(e){var t,i;null===(t=(i=this._inner).setController)||void 0===t||t.call(i,{invalidateItemCache:t=>{const i=t.replace(/^\/+|\/+$/g,""),r=this._pathToId.get(i);r&&e.invalidateItemCache(r)},getCachedItem:t=>{const i=t.replace(/^\/+|\/+$/g,""),r=this._pathToId.get(i);if(r){const t=e.getCachedItem(r);if(t)return{...t,id:this.pathForId(t.id,t.isFolder),folderId:this.pathForId(t.folderId,t.isFolder)}}}})}clearCache(e){if(this._inner.clearCache)return this._inner.clearCache(e)}_getOrGenerateId(e){if(e===this.rootPath)return;const t=e.replaceAll(/^\/+|\/+$/g,"");if(t===this.trashPath.replaceAll(/^\/+|\/+$/g,""))return this.trashId;if(this._pathToId.has(t))return this._pathToId.get(t);const i=(0,z.A)();return this._pathToId.set(t,i),this._idToPath.set(i,t),i}pathForId(e,t,i){const{__:r}=this.i18n;if(""===e||void 0===e)return this.rootPath;if(e===this.trashId)return this.trashPath;let a=this._idToPath.get(e);if(!a){if(i)return`unknown folder ${e}`;{const t=r?r(`Path for id '${e}' not found in mapping`):`Path for id '${e}' not found in mapping`;throw new D.FileManagerApiError(t,"FileNotFound")}}let o=0;for(;o<this.rootPath.length&&"/"===this.rootPath[o];)o++;if(o){let e=0;for(;e<a.length&&"/"===a[e];)e++;const t=a.slice(e);a="/".repeat(o)+t}return t&&this.ensureFolderTrailingSlash&&!a.endsWith("/")&&(a+="/"),a}_updateIdMapping(e,t){const i=t.replace(/^\/+|\/+$/g,""),r=this._idToPath.get(e);r&&this._pathToId.delete(r),this._idToPath.set(e,i),this._pathToId.set(i,e)}async getItems(e){const t=e.folderId?this.pathForId(e.folderId,!0):this.rootPath,i=await this._inner.getItems({...e,folderId:t}),r=i.items.map(e=>{const t=this._getOrGenerateId(e.id),i=e.folderId?this._getOrGenerateId(e.folderId):this._getOrGenerateId(this.rootPath);return{...e,id:t,folderId:i}});return{...i,items:r}}async createFolder(e,t,i){const r=t?this.pathForId(t,!0):this.rootPath,a=await this._inner.createFolder(e,r,i),o=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):this._getOrGenerateId(this.rootPath);return{...a,id:o,folderId:s}}async renameItem(e,t){const{__:i}=this.i18n;if(!this._inner.renameItem){const e=i?i("Rename item is not supported by inner storage"):"Rename item is not supported by inner storage";throw new D.FileManagerApiError(e,"RenameNotAllowed")}const r=this.pathForId(e.id,e.isFolder),a=r;let{...o}=await this._inner.renameItem({...e,id:r,folderId:this.pathForId(e.folderId,!0)},t);return this._updateIdMapping(e.id,o.id),e.isFolder&&this.remapCachedFolderContents(e.id,a,o.id),o.folderId&&(o={...o,folderId:this._getOrGenerateId(o.folderId)}),{...o,id:this._getOrGenerateId(o.id)}}async deleteItem(e,t){const i=this.pathForId(e.id,e.isFolder);await this._inner.deleteItem({...e,id:i,folderId:this.pathForId(e.folderId,!0)},t),this.recursivelyRemoveMappings(e.id,i)}async uploadFile(e){const t=e.folderId?this.pathForId(e.folderId,!0):this.rootPath,i=await this._inner.uploadFile({...e,folderId:t}),r=this._getOrGenerateId(i.id),a=i.folderId?this._getOrGenerateId(i.folderId):this._getOrGenerateId(this.rootPath);return{...i,id:r,folderId:a}}async uploadFiles(e){var t,i,r,a,o;const s=e.folderId,n=null!==(t=null===(i=e.items)||void 0===i?void 0:i.map(e=>e.folderId))&&void 0!==t?t:[],l=e.folderId?this.pathForId(e.folderId,!0):this.rootPath,d={...e,folderId:l,items:null!==(r=null===(a=e.items)||void 0===a?void 0:a.map(e=>({...e,folderId:e.folderId?this.pathForId(e.folderId,!0):l})))&&void 0!==r?r:[]},h=await this._inner.uploadFiles(d);return{...h,detailed:null===(o=h.detailed)||void 0===o?void 0:o.map((e,t)=>{var i,r;if(null===e||void 0===e||!e.data)return e;const a=e.data.id?this._getOrGenerateId(e.data.id):void 0,o=e.data.folderId?this._getOrGenerateId(e.data.folderId):null!==(i=null!==(r=n[t])&&void 0!==r?r:s)&&void 0!==i?i:this._getOrGenerateId(this.rootPath);return{...e,data:{...e.data,id:a,folderId:o}}})}}async findFileByUrl(e,t){const i=t?this.pathForId(t,!0):this.rootPath;if(this._inner.findFileByUrl){const t=await this._inner.findFileByUrl(e,i);if(!t)return;const r=this._getOrGenerateId(t.id),a=t.folderId?this._getOrGenerateId(t.folderId):this._getOrGenerateId(this.rootPath);return{...t,id:r,folderId:a}}}async uploadFileByUrl(e,t,i){const r=t?this.pathForId(t,!0):this.rootPath,a=await this._inner.uploadFileByUrl(e,r,i),o=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):this._getOrGenerateId(this.rootPath);return{...a,id:o,folderId:s}}async moveItem(e,t){const i=this.pathForId(e.id,e.isFolder),r=this.pathForId(t,!0),a=await this._inner.moveItem({...e,id:i,folderId:this.pathForId(e.folderId,!0)},r);this._updateIdMapping(e.id,a.id),e.isFolder&&this.remapCachedFolderContents(e.id,i,a.id);const o=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):t;return{...a,id:o,folderId:s}}async moveItems(e,t){const{__:i}=this.i18n;if(!this._inner.moveItems){const e=i?i("Move items is not supported by inner storage"):"Move items is not supported by inner storage";throw new D.FileManagerApiError(e,"MoveNotAllowed")}const r=t?this.pathForId(t,!0):this.rootPath,a=e.map(e=>({...e,id:this.pathForId(e.id,e.isFolder),folderId:e.folderId?this.pathForId(e.folderId,!0):this.rootPath})),o=await this._inner.moveItems(a,r),s=[];if(o.detailed&&o.detailed.length>0){const r=new Map;for(let t=0;t<o.detailed.length;t++){const i=o.detailed[t],a=i.requestId||(t<e.length?e[t].id:void 0);a&&r.set(a,i)}for(const a of e){const n=r.get(a.id)||(o.detailed.length===e.length?o.detailed[e.indexOf(a)]:void 0);if(null!==n&&void 0!==n&&n.success&&n.data){if(this._updateIdMapping(a.id,n.data.id),a.isFolder){const e=this.pathForId(a.id,a.isFolder);this.remapCachedFolderContents(a.id,e,n.data.id)}s.push({requestId:a.id,success:!0,data:{...n.data,id:this._getOrGenerateId(n.data.id),folderId:n.data.folderId?this._getOrGenerateId(n.data.folderId):t||this._getOrGenerateId(this.rootPath)}})}else{const e=i?i("Move operation failed - no detailed result"):"Move operation failed - no detailed result";s.push({requestId:a.id,success:!1,error:(null===n||void 0===n?void 0:n.error)||{message:e,code:"MoveNotAllowed"}})}}}else for(const n of e){const e=i?i("Move operation failed - no detailed results"):"Move operation failed - no detailed results";s.push({requestId:n.id,success:!1,error:{message:e,code:"MoveNotAllowed"}})}return{success:o.success,detailed:s,error:o.error}}async copyItems(e,t){const{__:i}=this.i18n;if(!this._inner.copyItems){const e=i?i("Copy items is not supported by inner storage"):"Copy items is not supported by inner storage";throw new D.FileManagerApiError(e,"CopyNotAllowed")}const r=t?this.pathForId(t,!0):this.rootPath,a=e.map(e=>({...e,id:this.pathForId(e.id,e.isFolder),folderId:e.folderId?this.pathForId(e.folderId,!0):this.rootPath})),o=await this._inner.copyItems(a,r),s=[];if(o.detailed&&o.detailed.length>0){const r=new Map;for(let t=0;t<o.detailed.length;t++){const i=o.detailed[t],a=i.requestId||(t<e.length?e[t].id:void 0);a&&r.set(a,i)}for(const a of e){var n;const l=r.get(a.id)||(o.detailed.length===e.length?o.detailed[e.indexOf(a)]:void 0);if(null!==l&&void 0!==l&&l.success&&null!==(n=l.data)&&void 0!==n&&n.id){const e=this._getOrGenerateId(l.data.id);s.push({requestId:a.id,success:!0,data:{...l.data,id:e,folderId:l.data.folderId?this._getOrGenerateId(l.data.folderId):t||this._getOrGenerateId(this.rootPath)}})}else{const e=l?l.success?l.data?l.data.id?{message:i?i("Unknown copy error"):"Unknown copy error",code:"CopyNotAllowed"}:{message:i?i("No ID in copied item data"):"No ID in copied item data",code:"CopyNotAllowed"}:{message:i?i("No data returned from copy operation"):"No data returned from copy operation",code:"CopyNotAllowed"}:l.error||{message:i?i("Copy operation failed"):"Copy operation failed",code:"CopyNotAllowed"}:{message:i?i("No detailed result from copy operation"):"No detailed result from copy operation",code:"CopyNotAllowed"};s.push({requestId:a.id,success:!1,error:e})}}}else for(const h of e){const e=i?i("No detailed results from copy operation"):"No detailed results from copy operation";s.push({requestId:h.id,success:!1,error:{message:e,code:"CopyNotAllowed"}})}const l=s.every(e=>e.success),d=i?i("Copy operation completed with errors"):"Copy operation completed with errors";return{success:l,detailed:s,error:l?void 0:o.error||{message:d,code:"CopyNotAllowed"}}}async deleteItems(e,t){const{__:i}=this.i18n;if(!this._inner.deleteItems){const e=i?i("Delete items is not supported by inner storage"):"Delete items is not supported by inner storage";throw new D.FileManagerApiError(e,"DeleteNotAllowed")}const r=e.map(e=>({...e,id:this.pathForId(e.id,e.isFolder),folderId:e.folderId?this.pathForId(e.folderId,!0):this.rootPath})),a=await this._inner.deleteItems(r,t),o=[];if(a.detailed&&a.detailed.length>0){const r=new Map;for(let t=0;t<a.detailed.length;t++){const i=a.detailed[t],o=i.requestId||(t<e.length?e[t].id:void 0);o&&r.set(o,i)}for(const s of e){const n=r.get(s.id)||(a.detailed.length===e.length?a.detailed[e.indexOf(s)]:void 0);if(null!==n&&void 0!==n&&n.success){const e=this.pathForId(s.id,s.isFolder);if(t.permanent)this.recursivelyRemoveMappings(s.id,e);else if(this._updateIdMapping(s.id,this.trashPath+"/"+e+(s.isFolder?"/":"")),s.isFolder){const t=this.pathForId(s.id,s.isFolder);this.remapCachedFolderContents(s.id,t,this.trashPath+"/"+e+(s.isFolder?"/":""))}o.push({requestId:s.id,success:!0})}else{const e=i?i("Delete operation failed"):"Delete operation failed";o.push({requestId:s.id,success:!1,error:(null===n||void 0===n?void 0:n.error)||{message:e,code:"DeleteNotAllowed"}})}}}else for(const l of e)if(a.success){const e=this.pathForId(l.id,l.isFolder);if(t.permanent)this.recursivelyRemoveMappings(l.id,e);else if(this._updateIdMapping(l.id,this.trashPath+"/"+e+(l.isFolder?"/":"")),l.isFolder){const t=this.pathForId(l.id,l.isFolder);this.remapCachedFolderContents(l.id,t,this.trashPath+"/"+e+(l.isFolder?"/":""))}o.push({requestId:l.id,success:!0})}else{const e=i?i("Delete operation failed"):"Delete operation failed";o.push({requestId:l.id,success:!1,error:a.error||{message:e,code:"DeleteNotAllowed"}})}const s=o.every(e=>e.success),n=i?i("Some items failed to delete"):"Some items failed to delete";return{success:s,detailed:o,error:s?void 0:a.error||{message:n,code:"DeleteNotAllowed"}}}remapCachedFolderContents(e,t,i){const r=t.replace(/\/+$/,""),a=i.replace(/\/+$/,""),o=[];for(const[s,n]of this._idToPath.entries()){const e=n.replace(/\/+$/,"");e!==r&&e.startsWith(r+"/")&&o.push({id:s,oldPath:e})}for(const{id:s,oldPath:n}of o){const e=a+n.substring(r.length);this._updateIdMapping(s,e)}}recursivelyRemoveMappings(e,t){const i=t.replace(/\/+$/,""),r=[],a=[];for(const[o,s]of this._idToPath.entries()){const e=s.replace(/\/+$/,"");(e===i||e.startsWith(i+"/"))&&(r.push(o),a.push(e))}for(let o=0;o<r.length;o++)this._idToPath.delete(r[o]),this._pathToId.delete(a[o])}async copyItem(e,t){const i=this.pathForId(e.id,e.isFolder),r=this.pathForId(t,!0),a=await this._inner.copyItem({...e,id:i,folderId:this.pathForId(e.folderId,!0)},r),o=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):t;return{...a,id:o,folderId:s}}async updateFile(e,t){const{__:i}=this.i18n;if(!this._inner.updateFile){const e=i?i("Update file is not supported by inner storage"):"Update file is not supported by inner storage";throw new D.FileManagerApiError(e,"UnsupportedOperation")}const r=this.pathForId(e.id,!1);let{...a}=await this._inner.updateFile({...e,id:r,folderId:this.pathForId(e.folderId,!0)},t);return this._updateIdMapping(e.id,a.id),a.folderId&&(a={...a,folderId:this._getOrGenerateId(a.folderId)}),{...a,id:this._getOrGenerateId(a.id)}}async getFileData(e){const{__:t}=this.i18n,i=this.pathForId(e.id,!1);if(this._inner.getFileData)return this._inner.getFileData({...e,id:i,folderId:this.pathForId(e.folderId,!0)});const r=e.url||this.getUrl&&await this.getUrl(e);if(!r){const e=t?t("Cannot get file data: no url and no inner.getFileData"):"Cannot get file data: no url and no inner.getFileData";throw new D.FileManagerApiError(e,"FileReadError")}return fetch(r).then(e=>e.blob())}async cleanTrash(){const{__:e}=this.i18n;if(!this._inner.cleanTrash){const t=e?e("Clean trash is not supported by inner storage"):"Clean trash is not supported by inner storage";throw new D.FileManagerApiError(t,"UnsupportedOperation")}return await this._inner.cleanTrash()}}var L=i(25516),V=i(20263),q=i(70529);const $="a_T7zSNUXtMfhVWQbIOMpXIPqzLQ8hm5Wfclm2nU98PtlSVxcft8FSn5InbD04056fYCpKXP20jJSySRLu",j={ru:"ru_RU",en:"en_GB",uk:"uk_UA",de:"de_DE",fr:"fr_FR",es:"es_ES",it:"it_IT",pt:"pt_PT",pl:"pl_PL",zh:"zh-Hans_CN",ja:"ja_JP"};async function K(e,t={}){const i=e.trim();if(!i)return i;const r=(e=>{if(!e)return"en_GB";const t=e.toLowerCase().split(/[-_]/)[0];return j[t]||"auto"})(t.locale);if(t.locale&&"en_GB"===r)return i;try{const e={from:t.locale?r:"auto",to:"en_GB",data:i,platform:"api"},a=await fetch("https://api-b2b.backenster.com/b1/api/v3/translate",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${$}`},body:JSON.stringify(e)});if(!a.ok)return i;const o=await a.json();if(o.err)return i;const s=o.result;return"string"===typeof s&&s.trim()?s.trim():i}catch(a){return i}}function J(){const e=(0,a.Pj)(),t=(0,a.d4)(c.B),i=(0,g.ml)(F.AZ.ON_TRANSLATE_ID);return(0,r.useCallback)(async(r,a={})=>{var o;const s=r.trim();if(!s)return s;const n=null!==(o=a.locale)&&void 0!==o?o:"string"===typeof t?t:void 0,l=void 0!==V.di.getInstance(e,q.Ef);try{const e=await i.fire({input:s,locale:n}),t=function(e){for(const t of e)if("string"===typeof t&&t.trim().length>0)return t.trim();return null}(Array.isArray(e)?e:[e]);if(t)return t}catch(d){}return l?s:K(s,{locale:n}).catch(()=>s)},[t,e,i])}var H=i(2527),Y=i(50548);const W=(0,r.memo)(R.KG),X=(0,r.memo)(R.BC),{useToken:Z}=s.A,Q=({storageProvider:e})=>{var t,i,s,y,C,P,A,b,E,M,S,T,O,N,D,U,B,R;const z=(0,p.rD)(),{projectId:q,emailId:$,blockId:j}=(0,o.g)(),K=(0,_.s9)(),{__:Q}=K,{token:ee}=Z(),{error:te,notify:ie}=(0,w.hN)(),re=(0,a.wA)(),ae=(0,a.d4)(c.B$),oe=(0,a.d4)(c.C1),se=(0,a.d4)(u.cL),ne=(0,a.d4)(v.Ac),le=(0,a.d4)(f.yN),de=(0,a.d4)(v.js),he=J(),[ce,ue]=(0,r.useState)(""),[ve,fe]=(0,r.useState)("my_files"),[me,pe]=(0,r.useState)(!1),[we,ge]=(0,r.useState)(0),[Ie,ye]=(0,r.useState)(""),[_e,Fe]=(0,r.useState)(()=>[]),Ce=()=>{re((0,u.Oo)()),setTimeout(()=>ue(""),600)},Pe=!(ae||(null===(t=oe.id)||void 0===t?void 0:t.toString())!==(null===le||void 0===le||null===(i=le.members)||void 0===i?void 0:i.owner.ID)),Ae=(0,r.useMemo)(()=>({img:de,background:ne}),[de,ne]);(0,r.useEffect)(()=>{se.includes("UPLOAD_BACKGROUND_MODAL")?(ue("background"),Ae.background&&ye(Ae.background)):se.includes("UPLOAD_IMAGE_MODAL")&&(ue("img"),Ae.img&&ye(Ae.img)),se===k.lx.UPLOAD_IMAGE_MODAL||se===k.lx.UPLOAD_BACKGROUND_MODAL?fe("editor"):se===k.lx.UPLOAD_IMAGE_MODAL_AI||se===k.lx.UPLOAD_BACKGROUND_MODAL_AI?Pe?(pe(!0),ge(2)):fe("ai"):se===k.lx.UPLOAD_IMAGE_MODAL_UPLOAD||se===k.lx.UPLOAD_BACKGROUND_MODAL_UPLOAD?fe("my_files"):se===k.lx.UPLOAD_IMAGE_MODAL_STOCK||se===k.lx.UPLOAD_BACKGROUND_MODAL_STOCK?Pe?(pe(!0),ge(3)):fe("stock_images"):se===k.lx.UPLOAD_IMAGE_MODAL_GIF||se===k.lx.UPLOAD_BACKGROUND_MODAL_GIF?Pe?(pe(!0),ge(3)):fe("gif"):se===k.lx.UPLOAD_IMAGE_MODAL_EDIT||se===k.lx.UPLOAD_BACKGROUND_MODAL_EDIT?(Pe?(pe(!0),ge(5)):fe("editor"),re((0,u.Wz)(k.lx.IMAGE_EDITOR_MODAL))):fe("my_files")},[se,re,Pe,Ae]);const be=!Pe&&!!ve&&(se.includes("UPLOAD_IMAGE_")||se.includes("UPLOAD_BACKGROUND_"));(0,r.useEffect)(()=>{const e=document.querySelector("#carrotquest-messenger-collapsed-container");e&&(e.style.display=be?"none":"")},[be]);const Ee=(0,r.useMemo)(()=>e?e.pathMode?new G(e,e.rootId,"Trash",e.trashPath,!0,K):null:(te(Q("Error when initializing file manager")),null),[e,te,K]),Me=(0,r.useMemo)(()=>new x(null!==Ee&&void 0!==Ee?Ee:e,z.fileManager,{...e,trashPath:e.pathMode?"trash":e.trashPath,rootId:e.pathMode?"":e.rootId},K),[e,Ee,z.fileManager,K]),Se=(0,r.useCallback)(e=>{const t=(0,L.e0)(e,Me,Ee);return ie(t,!0)},[Me,Ee,ie]),Te=(0,g.ml)(F.AZ.FILE_PROXY_EVENT_ID),Oe=(0,H.p)(),Ne=(0,a.Pj)(),De=(0,r.useCallback)(async e=>{const t=await Te.fire({url:e,project:q});let i=await t.find(e=>e);if(!i){const t=Oe.get(k.A9.em_token)||await V.di.getInstance(Ne,Y.Y),r=await fetch(`https://app.emailmaker.ru/api/wp-json/cors-proxy/v1/get?url=${encodeURIComponent(e)}`,{headers:{authorization:`Bearer ${t}`}});i=await r.blob()}return i},[Te,q,Oe,Ne]),Ue=r.createElement(d.A,{style:{fontSize:32,margin:-16},spin:!0}),xe=(0,r.useCallback)(e=>{I.isEqual(e,_e)||Fe(e)},[_e]),[Be]=(0,h.Mv)(),Re=(0,r.useCallback)(async()=>{if(Me){const e=_e[0];if(e){const t=e.url||e.thumbnailUrl||e.thumbnail;"img"===ce?re((0,v.tm)(t)):"background"===ce&&re((0,v.e_)(t))}}Ce()},[Me,re,u.Oo,_e,ce]),ke=(0,r.useCallback)(async e=>{let t=e.url||e.thumbnailUrl||e.thumbnail;!t&&Me&&(t=await Me.getFileUrl(e.folderId,e.name)),t&&("img"===ce?re((0,v.tm)(t)):"background"===ce&&re((0,v.e_)(t))),Ce()},[Me,re,u.Oo,ce]),ze=(0,r.useCallback)(async()=>{Ce()},[re,u.Oo]),[Ge,{data:Le=[]}]=(0,h.gg)(),Ve=(null===z||void 0===z?void 0:z.handleLimitUsageEmitter)||(0,g.ml)(F.AZ.ON_LIMIT_ID),qe=(0,r.useCallback)(async function(e){try{await Ge(e).unwrap()}catch(t){}},[Ge]),$e=(0,r.useMemo)(()=>{const e=(null===z||void 0===z?void 0:z.icons)||{};if(e&&0!==Object.keys(e).length)return(0,L.Rt)(e)},[null===z||void 0===z?void 0:z.icons]),je=(0,r.useCallback)(async(e,t={})=>await he(e,t),[he]),Ke=(0,g.ml)(F.AZ.PROXY_URL_EVENT_ID),Je=(0,r.useCallback)(async e=>(await Ke.fire({url:e,project:q})).findLast(t=>t&&t!==e)||(0,L.W5)(e),[Ke,q]);return ce&&Me?r.createElement(r.Fragment,null,!Pe&&r.createElement(n.A,{className:"file-manager",closable:!0,footer:null,open:be,width:"100vw",onOk:Re,onCancel:Ce},r.createElement(l.A,{spinning:!Me,indicator:Ue},Me&&("editor"===ve?r.createElement(X,{onSave:ke,onClose:ze,dataProviders:Me,handleFileProxy:De,theme:oe.theme,file:Ie,handleNotify:Se,assetsUrl:(0,L.Zq)("","static/media/image-editor"),locale:oe.locale.split("-")[0].split("_")[0]}):r.createElement(W,{dataProviders:Me,onChangeSelection:xe,onEditorOk:ke,handleNotify:Se,customIcons:$e,config:{assetsUrl:(0,L.Zq)("","static/media/image-editor"),onClose:Ce,handleProxyUrl:Je,handleFileProxy:De,expandRootFolderOnInit:!1!==(null===(s=z.fileManager)||void 0===s?void 0:s.expandRootFolderOnInit),activeLibraryItem:ve,REACT_APP_GIPHY_KEY:"Nh77eBlPeMn1ed9MBAvL542NUGeNO26F",UNSPLASH_KEY:"S5iNcLqYgRBIOLQdluHdTsCJnjCvahzhG7JfYQOrV7o",APP_NAME_UNSPLASH:"Nh77eBlPeMn1ed9MBAvL542NUGeNO26F",UNSLASH_PROXY_URL:"https://api.emailmaker.ru/services/agent",STREAMLINE_API_KEY:{}.REACT_APP_STREAMLINE_API_KEY,fileForEdit:Ie,projectId:q,elementId:$||j,pushToGTM:null===z||void 0===z?void 0:z.pushToGTM,handleLimitUsageEmitter:Ve,sseQuery:qe,messages:Le,sendAIImageRequest:(null===z||void 0===z?void 0:z.sendAIImageRequest)||Be,locale:oe.locale.split("-")[0].split("_")[0],theme:oe.theme,customTheme:ee,enableTrashFolder:null===(y=z.fileManager)||void 0===y?void 0:y.enableTrash,showNotifications:null===(C=z.fileManager)||void 0===C?void 0:C.showNotifications,handleTranslate:je,features:{enableRenameFile:!1!==(null===(P=z.fileManager)||void 0===P?void 0:P.enableRenameFile),enableRenameFolder:!1!==(null===(A=z.fileManager)||void 0===A?void 0:A.enableRenameFolder),enableUpdateFile:!1!==(null===(b=z.fileManager)||void 0===b?void 0:b.enableUpdateFile),enableCopyItem:!1!==(null===(E=z.fileManager)||void 0===E?void 0:E.enableCopyFile),enableCopyFolder:!1!==(null===(M=z.fileManager)||void 0===M?void 0:M.enableCopyFolder),enableDelete:!1!==(null===(S=z.fileManager)||void 0===S?void 0:S.enableDelete),enableEdit:!1!==(null===(T=z.fileManager)||void 0===T?void 0:T.enableEdit),enableMoveItem:!1!==(null===(O=z.fileManager)||void 0===O?void 0:O.enableMoveFile),enableMoveFolder:!1!==(null===(N=z.fileManager)||void 0===N?void 0:N.enableMoveFolder)},disablePagination:!1===(null===(D=z.fileManager)||void 0===D?void 0:D.enablePagination),multiSelect:!1!==(null===(U=z.fileManager)||void 0===U?void 0:U.multiSelect),defaultFolderName:null===(B=z.fileManager)||void 0===B?void 0:B.defaultFolderName,availableImageExtensions:null===(R=z.fileManager)||void 0===R?void 0:R.availableImageExtensions}})))),r.createElement(m.A,{open:me,onCancel:()=>pe(!1),initialSlide:we,sideOnOk:void 0})):null}}}]);
2
- //# sourceMappingURL=5102.c0da6ad7.js.map
1
+ "use strict";(globalThis.webpackChunkemail_maker=globalThis.webpackChunkemail_maker||[]).push([[5102],{16160:(e,t,i)=>{i.r(t),i.d(t,{default:()=>Z});var r=i(1936),a=i(71715),o=i(84075),s=i(18021),n=i(51114),l=i(6691),d=i(86331),h=i(60034),c=i(98173),u=i(78443),v=i(75301),f=i(22817),m=i(81644),p=i(942),w=i(6403),g=i(65185);let I;var y;(y=I||(I={})).isEqual=function(e,t,i=(e,t)=>e===t){if(e===t)return!0;const r=e.length;if(r!==t.length)return!1;for(let a=0;a<r;a++)if(!i(e[a],t[a]))return!1;return!0},y.unique=function(e,t){t||(t=e=>e);const i=new Set;return e.filter(e=>{const r=t(e),a=!i.has(r);return i.add(r),a})};var _=i(47706),F=i(65893);function P(e){return null==e||""===e?"":e}function C(e){if(null==e)return 1/0;const t=Number(e);return Number.isFinite(t)&&t>=0?t:1/0}function A(e){if(!e)return null;const t=e.folderId;return null==t?null:String(t)}function b(e){return!!e&&e.isFolder}function E(){var e;if("function"===typeof(null===globalThis||void 0===globalThis||null===(e=globalThis.crypto)||void 0===e?void 0:e.randomUUID))return globalThis.crypto.randomUUID();try{const e=globalThis.crypto||globalThis.msCrypto;if(e&&"function"===typeof e.getRandomValues){const t=new Uint8Array(16);e.getRandomValues(t);let i="";for(let e=0;e<t.length;e++)i+=t[e].toString(16).padStart(2,"0");return`id_${i}`}}catch{}return`id_fallback_${Date.now().toString(36)}_${Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(36).slice(0,8)}`}function M(e){if(!e||"object"!==typeof e)return String(null!==e&&void 0!==e?e:"");const t=e,i=[],r={},a=["page","pageSize","sortBy","sortOrder","search","itemType","limit"];for(const l of Object.keys(t).sort()){const e=t[l];a.includes(l)?i.push(`${l}=${String(null!==e&&void 0!==e?e:"")}`):r[l]=e}const o=Object.keys(r).length?JSON.stringify(r):"",s=i.join("|"),n=o?function(e){let t=2166136261;for(let i=0;i<e.length;i++)t^=e.charCodeAt(i),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t.toString(36)}(o):"";return`${s}${n?`|${n}`:""}`}class S{constructor(){this.entities=new Map,this.childrenByParent=new Map,this.maxCacheSize=1e4}now(){return Date.now()}checkCacheSize(){if(this.entities.size>this.maxCacheSize){const e=Array.from(this.entities.entries()).sort((e,t)=>e[1].updatedAt-t[1].updatedAt),t=Math.floor(.1*this.maxCacheSize);for(let i=0;i<t&&i<e.length;i++){const[t,r]=e[i];this.deleteEntityById(t)}}}getEntity(e){var t;return null===(t=this.entities.get(e))||void 0===t?void 0:t.value}getRecord(e){return this.entities.get(e)}getFileSystemItem(e){const t=this.getEntity(e);return t&&!b(t)?t:void 0}getFolder(e){const t=this.getEntity(e);return t&&b(t)?t:void 0}getChildrenIds(e,t={}){const i=P(e),r=this.childrenByParent.get(i);return r?t.onlyFileSystemItems?Array.from(r.files):t.onlyFolders?Array.from(r.folders):[...Array.from(r.folders),...Array.from(r.files)]:[]}searchByUrl(e){for(const t of this.entities.values())if(t.value.url===e)return t.value;return null}upsertEntity(e){var t;const i=null!==(t=this.entities.get(e.id))&&void 0!==t?t:null,r=i?i.value:null,a=r?A(r):null,o=A(e),s=!!r&&b(r),n=b(e);let l;if(r&&b(r)&&n){const t=r.childrenCount,i=e.childrenCount;void 0!==t&&void 0===i&&(l=t)}if(r&&(a!==o||s!==n)){const t=P(a),i=this.childrenByParent.get(t);i&&(s?i.folders.delete(e.id):i.files.delete(e.id),0===i.files.size&&0===i.folders.size&&this.childrenByParent.delete(t))}let d=e;void 0!==l&&(d={...e,childrenCount:l}),this.entities.set(e.id,{value:{...d},updatedAt:this.now()}),this.checkCacheSize();const h=P(o);let c=this.childrenByParent.get(h);c||(c={files:new Set,folders:new Set},this.childrenByParent.set(h,c)),n?c.folders.add(e.id):c.files.add(e.id)}updateServerChildrenCount(e,t){if(null==e||null==t||Number.isNaN(t))return;const i=this.entities.get(e);if(!i||!b(i.value))return;const r={...i.value,childrenCount:t};this.entities.set(e,{value:r,updatedAt:this.now()})}deleteEntityById(e){var t;const i=null!==(t=this.entities.get(e))&&void 0!==t?t:null;if(!i)return{entity:null,parentId:null};const r=i.value,a=A(r),o=P(a),s=this.childrenByParent.get(o);return s&&(b(r)?s.folders.delete(e):s.files.delete(e),0===s.files.size&&0===s.folders.size&&this.childrenByParent.delete(o)),this.entities.delete(e),{entity:{...r},parentId:a}}deleteFolderRecursive(e){const t=this.entities.get(e);if(!t||!b(t.value))return{deletedFolderRecords:[],deletedFileSystemItemRecords:[]};const i=[{id:e,parentId:A(t.value)}],r=[],a=[];for(;i.length;){const e=i.shift();r.push(e);const t=this.childrenByParent.get(P(e.id));if(t){for(const e of Array.from(t.folders)){const t=this.entities.get(e);t&&i.push({id:e,parentId:A(t.value)})}for(const e of Array.from(t.files))a.push(e)}}const o=[];for(const n of a){const e=this.entities.get(n);if(!e)continue;const t=e.value,i=P(A(t)),r=this.childrenByParent.get(i);r&&(r.files.delete(n),0===r.files.size&&0===r.folders.size&&this.childrenByParent.delete(i)),this.entities.delete(n),o.push({...t})}const s=[];for(let n=r.length-1;n>=0;n--){const{id:e,parentId:t}=r[n],i=this.entities.get(e);if(!i)continue;const a=i.value,o=P(a.id);this.childrenByParent.delete(o);const l=P(t),d=this.childrenByParent.get(l);d&&(d.folders.delete(e),0===d.files.size&&0===d.folders.size&&this.childrenByParent.delete(l)),this.entities.delete(e),s.push({...a})}return{deletedFolderRecords:s,deletedFileSystemItemRecords:o}}moveEntityById(e,t){var i;const r=null!==(i=this.entities.get(e))&&void 0!==i?i:null;if(!r)return null;const a=r.value,o=P(A(a)),s=this.childrenByParent.get(o);s&&(b(a)?s.folders.delete(e):s.files.delete(e),0===s.files.size&&0===s.folders.size&&this.childrenByParent.delete(o));const n={...a,folderId:t};if(b(a)&&b(n)){const e=a.childrenCount;void 0!==e&&(n.childrenCount=e)}this.entities.set(e,{value:n,updatedAt:this.now()});const l=P(t);let d=this.childrenByParent.get(l);return d||(d={files:new Set,folders:new Set},this.childrenByParent.set(l,d)),b(n)?d.folders.add(e):d.files.add(e),{...n}}copyFileSystemItem(e,t,i){var r;const a=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!a||b(a.value))return null;const o={...a.value,id:t,folderId:i};return this.upsertEntity(o),{...o}}copyFolderShallow(e,t,i){var r;const a=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!a||!b(a.value))return null;const o={...a.value,id:t,folderId:i};return this.upsertEntity(o),{...o}}isEntityStale(e,t){var i;const r=null!==(i=this.entities.get(e))&&void 0!==i?i:null;return!r||t!==1/0&&this.now()-r.updatedAt>t}touch(e,t){const i=this.entities.get(e);i&&(i.updatedAt=null!==t&&void 0!==t?t:this.now())}getEntitiesByIds(e){return e.map(e=>{var t,i;return null!==(t=null===(i=this.entities.get(e))||void 0===i?void 0:i.value)&&void 0!==t?t:null})}searchByName(e,t){var i,r,a,o;if(!e||""===e.trim())return[];const s=null===t||void 0===t?void 0:t.parentId,n=null!==(i=null===t||void 0===t?void 0:t.recursive)&&void 0!==i&&i,l=null!==(r=null===t||void 0===t?void 0:t.itemType)&&void 0!==r?r:"all",d=null!==(a=null===t||void 0===t?void 0:t.caseSensitive)&&void 0!==a&&a,h=null!==(o=null===t||void 0===t?void 0:t.limit)&&void 0!==o?o:1/0,c=d?e.trim():e.trim().toLowerCase(),u=[];let v=null;if(void 0!==s){v=new Set;const e=P(s);if(v.add(e),n){const t=[e],i=new Set;for(;t.length>0;){const e=t.shift();if(i.has(e))continue;i.add(e);const r=this.childrenByParent.get(e);if(r)for(const i of r.folders)v.add(i),t.push(i)}}}for(const[,m]of this.entities){var f;if(u.length>=h)break;const e=m.value;if(null!==v){const t=P(A(e));if(!v.has(t))continue}if("file"===l&&b(e))continue;if("folder"===l&&!b(e))continue;const t=null!==(f=e.name)&&void 0!==f?f:"";(d?t:t.toLowerCase()).includes(c)&&u.push({...e})}return u}toJSON(){return{entities:Array.from(this.entities.entries()),childrenByParent:Array.from(this.childrenByParent.entries()).map(([e,t])=>[e,{files:Array.from(t.files),folders:Array.from(t.folders)}])}}static fromJSON(e){const t=new S;for(const[a,o]of null!==(i=e.entities)&&void 0!==i?i:[]){var i;t.entities.set(a,{value:o.value,updatedAt:o.updatedAt})}for(const[a,o]of null!==(r=e.childrenByParent)&&void 0!==r?r:[]){var r;t.childrenByParent.set(a,{files:new Set(o.files),folders:new Set(o.folders)})}return t}}class T{constructor(e={},t=3e5,i=3e4,r){var a,o,s,n,l;this.views=new Map,this.strategy=void 0,this.ttl=void 0,this.errorTtl=void 0,this.entityTtl=void 0,this.serverChildrenCountHandler=void 0,this.childrenCountInvalidator=void 0,this.maxViewsPerParent=50,this.strategy={allowSortedInsert:null===(a=e.allowSortedInsert)||void 0===a||a,allowSearchInsert:null===(o=e.allowSearchInsert)||void 0===o||o,invalidateOnPaginationFull:null===(s=e.invalidateOnPaginationFull)||void 0===s||s,preloadPagesBefore:null!==(n=e.preloadPagesBefore)&&void 0!==n?n:0,preloadPagesAfter:null!==(l=e.preloadPagesAfter)&&void 0!==l?l:1,comparator:e.comparator,filterMatch:e.filterMatch},this.ttl=t,this.errorTtl=i,this.entityTtl=null!==r&&void 0!==r?r:t}setServerChildrenCountHandler(e){this.serverChildrenCountHandler=e}setChildrenCountInvalidator(e){this.childrenCountInvalidator=e}now(){return Date.now()}parentKey(e){return P(null!==e&&void 0!==e?e:null)}isExpired(e){return null==e||this.ttl!==1/0&&this.now()-e>this.ttl}isErrorExpired(e){return null==e||this.errorTtl!==1/0&&this.now()-e>this.errorTtl}areEntitiesStale(e,t){return!e||e.some(e=>!t.getEntity(e)||t.isEntityStale(e,this.entityTtl))}isEntityTypeCompatible(e,t){return!t||"all"===t||("file"===t&&!b(e)||!("folder"!==t||!b(e)))}cleanupOldViews(e){if(e.size<=this.maxViewsPerParent)return;const t=Array.from(e.entries()).sort((e,t)=>(t[1].view.updatedAt||0)-(e[1].view.updatedAt||0));for(;e.size>this.maxViewsPerParent&&t.length>0;){const[i]=t.pop();e.delete(i)}}async getOrCreateChildren(e,t,i,r){var a;const o=this.parentKey(e),s=M(null!==t&&void 0!==t?t:{});let n=this.views.get(o);n||(n=new Map,this.views.set(o,n));let l=n.get(s);if(!l){l={params:t,view:{promise:null,value:void 0,meta:void 0,error:void 0,updatedAt:0,loadId:null}},n.set(s,l),this.cleanupOldViews(n)}if(l.view.error&&!this.isErrorExpired(l.view.updatedAt))throw l.view.error;if(l.view.value&&!this.isExpired(l.view.updatedAt)&&!this.areEntitiesStale(l.view.value,r)&&(null===(a=l.view.meta)||void 0===a||!a.stale)){var d,h;const e=l.view.value.map(e=>r.getEntity(e)).filter(Boolean),t=(null===(d=l.params)||void 0===d?void 0:d.itemType)||"all";return{items:e.filter(e=>this.isEntityTypeCompatible(e,t)),...null!==(h=l.view.meta)&&void 0!==h?h:{}}}if(l.view.promise)return l.view.promise;const c=E();l.view.loadId=c;const u=(async()=>{try{var a,s,n;const h=await i(e,t),u=null===(a=this.views.get(o))||void 0===a?void 0:a.get(M(t));if(!u||u.view.loadId!==c){const e=new Error("StaleLoad");throw e.name="StaleLoad",e}for(const e of h.items)r.upsertEntity(e);l.view.value=h.items.map(e=>e.id);const{items:v,...f}=h,m={...f};l.view.meta=m,l.view.meta.stale=!1,l.view.error=null,l.view.updatedAt=this.now(),"number"===typeof m.total&&(this.serverChildrenCountHandler?this.serverChildrenCountHandler(null!==e&&void 0!==e?e:null,m.total,r):r.updateServerChildrenCount(e,m.total));const p=null!==(s=this.strategy.preloadPagesAfter)&&void 0!==s?s:0,w=null!==(n=this.strategy.preloadPagesBefore)&&void 0!==n?n:0,g=C(null===t||void 0===t?void 0:t.pageSize),I=Number.isFinite(g);if((p>0||w>0)&&I){var d;const a=e,o={...t},s="number"===typeof m.totalPages?m.totalPages:1,n=null!==(d=null===t||void 0===t?void 0:t.page)&&void 0!==d?d:1,l=g,h=i,u=c;setTimeout(()=>{this.preloadPagesAsync(a,o,n,s,l,p,w,r,m,h,u)},0)}return h}catch(m){var h,u,v,f;if("StaleLoad"===(null===m||void 0===m?void 0:m.name))throw l.view.error=null,l.view.value=void 0,l.view.updatedAt=this.now(),m;const e=m,t=null!==(h=null===e||void 0===e?void 0:e.status)&&void 0!==h?h:null===e||void 0===e||null===(u=e.data)||void 0===u?void 0:u.status,i=null!==(v=null===e||void 0===e?void 0:e.code)&&void 0!==v?v:null===e||void 0===e||null===(f=e.data)||void 0===f?void 0:f.code;if(404===t||"FileNotFound"===i||"FolderNotFound"===i||"path_folder_not_found"===i)return l.view.error=null,l.view.value=[],l.view.meta={total:0,totalPages:0},l.view.updatedAt=this.now(),{items:[],total:0,totalPages:0};throw l.view.error=m,l.view.value=void 0,l.view.updatedAt=this.now(),m}finally{l.view.promise=null}})();return l.view.promise=u,u}async preloadPagesAsync(e,t,i,r,a,o,s,n,l,d,h){try{const a=this.parentKey(e),l=this.views.get(a);if(!l)return;const c=l.get(M(t));if(!c)return;if(null!=h&&c.view.loadId!==h)return;const u=l.get(M(t));if(null===u||void 0===u||!u.view.meta)return;const v="number"===typeof u.view.meta.totalPages?u.view.meta.totalPages:1;if(v!==r)return;const f=async i=>{const r={...t,page:i};try{const o=await d(e,r),s=this.views.get(a);if(!s)return;const l=s.get(M(t));if(!l)return;if(null!=h&&l.view.loadId!==h)return;if(l.view.loadId!==h)return;for(const e of o.items)n.upsertEntity(e);const c=M(r);let u=s.get(c);if(!u){u={params:r,view:{promise:null,value:void 0,meta:void 0,error:void 0,updatedAt:0,loadId:l.view.loadId}},s.set(c,u),this.cleanupOldViews(s)}if(!u.view.value||this.isExpired(u.view.updatedAt)){u.view.value=o.items.map(e=>e.id);const{items:e,...t}=o;u.view.meta={...t,page:i,totalPages:v},u.view.updatedAt=this.now()}}catch(o){}};if(o>0&&i<v)for(let e=1;e<=Math.min(o,v-i);e++){const r=i+e,a=M({...t,page:r}),o=l.get(a);null!==o&&void 0!==o&&o.view.value&&!this.isExpired(o.view.updatedAt)||f(r)}if(s>0&&i>1)for(let e=1;e<=Math.min(s,i-1);e++){const r=i-e,a=M({...t,page:r}),o=l.get(a);null!==o&&void 0!==o&&o.view.value&&!this.isExpired(o.view.updatedAt)||f(r)}}catch(c){}}removeEmptyPageIfNeeded(e,t,i,r,a){if(t.view.value&&0===t.view.value.length&&i<r){const t=M({...a,page:i});e.delete(t)}}updateTotalPagesForAllViews(e,t){for(const[,i]of e)i.view.meta&&(i.view.meta.totalPages=t)}isParamsSame(e,t){const i=Object.keys(null!==e&&void 0!==e?e:{}).filter(e=>"page"!==e).sort(),r=Object.keys(null!==t&&void 0!==t?t:{}).filter(e=>"page"!==e).sort();if(i.length!==r.length)return!1;for(let a=0;a<i.length;a++){const o=i[a];if(o!==r[a])return!1;if(e[o]!==t[o])return!1}return!0}syncTotalsInSameViews(e,t){var i;const r=t.view.meta;if(!r||"number"!==typeof r.total)return;const a=Number(r.total),o=C(null===(i=t.params)||void 0===i?void 0:i.pageSize),s=Number.isFinite(o)&&o>0?Math.max(1,Math.ceil(a/o)):void 0;for(const[,d]of e){var n,l;this.isParamsSame(null!==(n=d.params)&&void 0!==n?n:{},null!==(l=t.params)&&void 0!==l?l:{})&&(d.view.meta||(d.view.meta={}),d.view.meta.total=a,void 0!==s&&(d.view.meta.totalPages=s))}}canSafelyModifySortedView(e){return!e.sortBy&&!e.sortOrder||!!this.strategy.comparator}cascadeShiftPages(e,t,i,r,a,o,s){let n=t,l=i,d=!1;let h=0;for(;n.view.value&&n.view.value.length<r&&l<a&&h<100;){h++;const t=M({...s,page:l+1}),i=e.get(t);if(null===i||void 0===i||!i.view.value||this.isExpired(i.view.updatedAt)){var c;n.view.meta={...null!==(c=n.view.meta)&&void 0!==c?c:{},stale:!0};break}const a=r-n.view.value.length,v=i.view.value.slice(0,a).filter(e=>o.getEntity(e));if(0===v.length){var u;n.view.meta={...null!==(u=n.view.meta)&&void 0!==u?u:{},stale:!0};break}if(n.view.value=[...n.view.value,...v],n.view.updatedAt=Date.now(),i.view.value=i.view.value.slice(v.length),i.view.updatedAt=Date.now(),0===i.view.value.length){const t=l+1,r=i.view.meta;if(t<(r&&"number"===typeof r.totalPages?r.totalPages:1)){const i=M({...s,page:t});e.delete(i),d=!0}break}n=i,l++}var v;(!n.view.value||n.view.value.length<r)&&l>=a&&(n.view.meta={...null!==(v=n.view.meta)&&void 0!==v?v:{},stale:!0});return d}cascadeShiftToNextPage(e,t,i,r,a,o,s){var n,l;if(!t.view.value||t.view.value.length<=r)return!1;var d;if(i-(s.page||1)>=10)return t.view.meta={...null!==(d=t.view.meta)&&void 0!==d?d:{},stale:!0},!1;const h={...s,page:i+1},c=M(h);let u=e.get(c),v=!1;if(null===(n=u)||void 0===n||!n.view.value||this.isExpired(u.view.updatedAt)){var f;if(!(i>=a))return t.view.meta={...null!==(f=t.view.meta)&&void 0!==f?f:{},stale:!0},!1;{u={params:h,view:{promise:null,value:void 0,meta:void 0,error:void 0,updatedAt:0,loadId:null}},e.set(c,u),this.cleanupOldViews(e);const r=t.view.meta;r&&(u.view.meta={...r,page:i+1}),v=!0}}const m=t.view.value.slice(r).filter(e=>o.getEntity(e));if(0===m.length)return v&&e.delete(c),!1;t.view.value=t.view.value.slice(0,r),t.view.updatedAt=Date.now(),u.view.value=[...m,...null!==(l=u.view.value)&&void 0!==l?l:[]],u.view.updatedAt=Date.now();const p=u.view.meta&&"number"===typeof u.view.meta.totalPages?u.view.meta.totalPages:a;if(!v){if(this.cascadeShiftToNextPage(e,u,i+1,r,p,o,s))return!0}if(!u.view.value||0===u.view.value.length){const t=i+1,r=u.view.meta,a=r&&"number"===typeof r.totalPages?r.totalPages:1;this.removeEmptyPageIfNeeded(e,u,t,a,s)}return v}tryInsertSorted(e,t,i){var r;const a=this.strategy.comparator;if(!a)return!1;if(!e.view.value)return!1;const o=(null===(r=e.params)||void 0===r?void 0:r.itemType)||"all";if(!this.isEntityTypeCompatible(t,o))return!1;const s=e.view.value.map(e=>i.getEntity(e));if(s.some(e=>!e))return!1;let n=0,l=s.length;for(;n<l;){const i=Math.floor((n+l)/2),r=a(t,s[i],e.params);if("number"!==typeof r||Number.isNaN(r))return!1;r>=0?n=i+1:l=i}return e.view.value.includes(t.id)?(e.view.updatedAt=this.now(),!0):(e.view.value=[...e.view.value.slice(0,n),t.id,...e.view.value.slice(n)],e.view.updatedAt=this.now(),e.view.meta&&"number"===typeof e.view.meta.total&&(e.view.meta.total=Number(e.view.meta.total)+1),!0)}updateChildrenCountForOperation(e,t,i,r){var a,o,s,n;const l=A(t);switch(e){case"delete":this.adjustChildrenCount(r,l,-1),null===(a=this.childrenCountInvalidator)||void 0===a||a.call(this,l);break;case"insert":case"copy":this.adjustChildrenCount(r,l,1),null===(o=this.childrenCountInvalidator)||void 0===o||o.call(this,l);break;case"move":this.adjustChildrenCount(r,i,-1),this.adjustChildrenCount(r,l,1),null===(s=this.childrenCountInvalidator)||void 0===s||s.call(this,i),null===(n=this.childrenCountInvalidator)||void 0===n||n.call(this,l)}}adjustChildrenCount(e,t,i){if(!t)return;const r=e.getFolder(t);if(r&&"number"===typeof r.childrenCount){const a=Math.max(0,r.childrenCount+i);e.updateServerChildrenCount(t,a)}}smartInvalidateChildrenViews(e,t,i,r,a,o){if(!t)return;this.updateChildrenCountForOperation(i,t,a,r);const s=this.parentKey(e),n=this.views.get(s);if(n)for(const[,u]of n){var l,d;const e=null!==(l=u.params)&&void 0!==l?l:{},o=null!==(d=null===e||void 0===e?void 0:e.page)&&void 0!==d?d:1,s=C(null===e||void 0===e?void 0:e.pageSize),v=Number.isFinite(s),f=!!(null!==e&&void 0!==e&&e.sortBy||null!==e&&void 0!==e&&e.sortOrder),m=!(null===e||void 0===e||!e.search),p=(null===e||void 0===e?void 0:e.itemType)||"all";if(!this.isEntityTypeCompatible(t,p))continue;if(m&&this.strategy.filterMatch&&!this.strategy.filterMatch(t,u.params)){var h;null!==(h=u.view.value)&&void 0!==h&&h.includes(t.id)&&(u.view.value=u.view.value.filter(e=>e!==t.id),u.view.meta&&"number"===typeof u.view.meta.total&&(u.view.meta.total=Math.max(0,u.view.meta.total-1)),u.view.updatedAt=Date.now());continue}if(!u.view.value){u.view.meta&&(u.view.meta.stale=!0),u.view.loadId=E(),u.view.abortController&&(u.view.abortController.abort(),u.view.abortController=void 0);continue}u.view.value.includes(t.id);var c;if(this.shouldInvalidateCompletely(u,i,t,f,v,o))u.view.meta={...null!==(c=u.view.meta)&&void 0!==c?c:{},stale:!0},u.view.loadId=E(),u.view.abortController&&(u.view.abortController.abort(),u.view.abortController=void 0);else switch(i){case"delete":this.handleDelete(n,u,o,s,v,t,r);break;case"insert":case"copy":this.handleInsert(n,u,o,s,v,f,t,r);break;case"update":this.handleUpdate(n,u,o,s,v,f,m,t,r);break;case"move":this.handleMove(n,u,o,s,v,f,t,a,r)}}}shouldInvalidateCompletely(e,t,i,r,a,o){return!(!(a&&o>1)||"insert"!==t&&"delete"!==t&&"move"!==t)||(!(!r||this.strategy.comparator||"insert"!==t&&"move"!==t)||!!this.isExpired(e.view.updatedAt))}tryReinsertEntity(e,t,i,r,a){var o,s;const n=(null===(o=e.params)||void 0===o?void 0:o.itemType)||"all";if(!this.isEntityTypeCompatible(t,n))return!1;if(this.strategy.comparator&&this.strategy.filterMatch){if(!this.strategy.filterMatch(t,e.params))return!1;if(this.tryInsertSorted(e,t,i))return!0}const l=null!==(s=e.params)&&void 0!==s?s:{};return!(!(!l.sortBy&&!l.sortOrder)&&!this.canSafelyModifySortedView(l))&&((!r||e.view.value.length<a)&&(e.view.value.push(t.id),!0))}handleDelete(e,t,i,r,a,o,s){const n=t.view.value.includes(o.id);if(n&&(t.view.value=t.view.value.filter(e=>e!==o.id)),t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total=Math.max(0,t.view.meta.total-1),a&&Number.isFinite(r)&&"number"===typeof t.view.meta.total){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}if(t.view.updatedAt=Date.now(),n&&a&&t.view.value.length<r&&s){var l;const a=t.view.meta,o=a&&"number"===typeof a.totalPages?a.totalPages:1;if(this.cascadeShiftPages(e,t,i,r,o,s,null!==(l=t.params)&&void 0!==l?l:{})&&t.view.meta&&"number"===typeof t.view.meta.totalPages){const i=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=i,this.updateTotalPagesForAllViews(e,i)}}t.view.loadId=E(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}handleInsert(e,t,i,r,a,o,s,n){if(!t.view.value.includes(s.id)){if(o&&this.strategy.allowSortedInsert&&this.strategy.comparator&&n){if(this.tryInsertSorted(t,s,n)&&t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total+=1,a&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}if(a&&t.view.value.length>r&&n){var l;const a=t.view.meta,o=a&&"number"===typeof a.totalPages?a.totalPages:1;if(this.cascadeShiftToNextPage(e,t,i,r,o,n,null!==(l=t.params)&&void 0!==l?l:{})&&t.view.meta&&"number"===typeof t.view.meta.totalPages){const i=t.view.meta.totalPages+1;t.view.meta.totalPages=i,this.updateTotalPagesForAllViews(e,i)}}}else if(!a||t.view.value.length<r){if(t.view.value.push(s.id),t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total+=1,a&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}t.view.updatedAt=Date.now()}else{var d;t.view.meta={...null!==(d=t.view.meta)&&void 0!==d?d:{},stale:!0}}t.view.loadId=E(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}}handleUpdate(e,t,i,r,a,o,s,n,l){var d;const h=t.view.value.includes(n.id),c=this.isEntityTypeCompatible(n,(null===(d=t.params)||void 0===d?void 0:d.itemType)||"all");if(h&&!c){if(t.view.value=t.view.value.filter(e=>e!==n.id),t.view.meta&&"number"===typeof t.view.meta.total&&(t.view.meta.total=Math.max(0,t.view.meta.total-1),a&&Number.isFinite(r)&&"number"===typeof t.view.meta.total)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}if(t.view.updatedAt=Date.now(),a&&t.view.value.length<r&&l){var u;const a=t.view.meta,o=a&&"number"===typeof a.totalPages?a.totalPages:1;if(this.cascadeShiftPages(e,t,i,r,o,l,null!==(u=t.params)&&void 0!==u?u:{})&&t.view.meta&&"number"===typeof t.view.meta.totalPages){const i=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=i,this.updateTotalPagesForAllViews(e,i)}}return t.view.loadId=E(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0))}if(h&&(o||s)){t.view.value=t.view.value.filter(e=>e!==n.id);if(this.tryReinsertEntity(t,n,l,a,r)){if(t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total+=1,a&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}}else{if(t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total=Math.max(0,t.view.meta.total-1),a&&Number.isFinite(r)&&"number"===typeof t.view.meta.total){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}if(a&&t.view.value.length<r&&l){var v;const a=t.view.meta,o=a&&"number"===typeof a.totalPages?a.totalPages:1;if(this.cascadeShiftPages(e,t,i,r,o,l,null!==(v=t.params)&&void 0!==v?v:{})&&t.view.meta&&"number"===typeof t.view.meta.totalPages){const i=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=i,this.updateTotalPagesForAllViews(e,i)}}}return t.view.updatedAt=Date.now(),t.view.loadId=E(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0))}if(h)return t.view.updatedAt=Date.now(),t.view.loadId=E(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0));if(c&&!s){if(o&&this.strategy.allowSortedInsert&&this.strategy.comparator&&l){if(this.tryInsertSorted(t,n,l)&&t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total+=1,a&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}}else if(!a||t.view.value.length<r){if(t.view.value.push(n.id),t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total+=1,a&&Number.isFinite(r)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}this.syncTotalsInSameViews(e,t)}t.view.updatedAt=Date.now()}else{var f;t.view.meta={...null!==(f=t.view.meta)&&void 0!==f?f:{},stale:!0}}t.view.loadId=E(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}}handleMove(e,t,i,r,a,o,s,n,l){if(t.view.value.includes(s.id)){if(t.view.value=t.view.value.filter(e=>e!==s.id),t.view.meta&&"number"===typeof t.view.meta.total&&(t.view.meta.total=Math.max(0,t.view.meta.total-1),a&&Number.isFinite(r)&&"number"===typeof t.view.meta.total)){const e=r;e>0&&(t.view.meta.totalPages=Math.max(1,Math.ceil(t.view.meta.total/e)))}if(t.view.updatedAt=Date.now(),a&&t.view.value.length<r&&l){var d;const a=t.view.meta,o=a&&"number"===typeof a.totalPages?a.totalPages:1;if(this.cascadeShiftPages(e,t,i,r,o,l,null!==(d=t.params)&&void 0!==d?d:{})&&t.view.meta&&"number"===typeof t.view.meta.totalPages){const i=Math.max(1,t.view.meta.totalPages-1);t.view.meta.totalPages=i,this.updateTotalPagesForAllViews(e,i)}}this.syncTotalsInSameViews(e,t)}t.view.loadId=E(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}forceInvalidateChildrenViews(e){const t=this.parentKey(null!==e&&void 0!==e?e:null),i=this.views.get(t);if(i)for(const[,r]of i)r.view.value=void 0,r.view.error=null,r.view.meta=void 0,r.view.promise=null,r.view.updatedAt=0,r.view.loadId=E(),r.view.abortController&&(r.view.abortController.abort(),r.view.abortController=void 0)}getKnownTotal(e){const t=this.parentKey(null!==e&&void 0!==e?e:null),i=this.views.get(t);if(!i)return;let r=null;for(const[,s]of i){const e=s.view.meta;var a,o;if(e&&"number"===typeof e.total)if(!r||(null!==(a=s.view.updatedAt)&&void 0!==a?a:0)>r.updatedAt)r={total:Number(e.total),updatedAt:null!==(o=s.view.updatedAt)&&void 0!==o?o:0}}return r?r.total:void 0}toJSON(){return{views:Array.from(this.views.entries()).map(([e,t])=>[e,Array.from(t.entries())]),ttl:this.ttl,errorTtl:this.errorTtl,entityTtl:this.entityTtl,strategy:{allowSortedInsert:this.strategy.allowSortedInsert,allowSearchInsert:this.strategy.allowSearchInsert,invalidateOnPaginationFull:this.strategy.invalidateOnPaginationFull,preloadPagesBefore:this.strategy.preloadPagesBefore,preloadPagesAfter:this.strategy.preloadPagesAfter}}}static fromJSON(e){const t=new T;for(const[r,a]of null!==(i=e.views)&&void 0!==i?i:[]){var i;const e=new Map;for(const[t,i]of a)e.set(t,i);t.views.set(r,e)}return t}}class O{invalidateChildrenCountCache(e){const t=P(null!==e&&void 0!==e?e:"");this.childrenCountPromises.delete(t)}constructor(e={},t=3e5,i=3e4){this.entities=void 0,this.views=void 0,this.ttl=void 0,this.errorTtl=void 0,this.childrenCountPromises=new Map,this.ttl=t,this.errorTtl=i,this.entities=new S,this.views=new T(e,t,i),this.views.setServerChildrenCountHandler((e,t,i)=>{this.handleServerReportedChildrenCount(e,t,null!==i&&void 0!==i?i:this.entities)}),this.views.setChildrenCountInvalidator(e=>{this.invalidateChildrenCountCache(e)})}getEntity(e){var t;return null!==(t=this.entities.getEntity(e))&&void 0!==t?t:null}getFileSystemItem(e){var t;return null!==(t=this.entities.getFileSystemItem(e))&&void 0!==t?t:null}getFolder(e){var t;return null!==(t=this.entities.getFolder(e))&&void 0!==t?t:null}async getOrCreateChildren(e,t,i){return this.views.getOrCreateChildren(e,t,i,this.entities)}upsertEntity(e){const t=this.entities.getEntity(e.id),i=t?A(t):null,r=A(e),a=!!t&&b(t),o=b(e);if(this.entities.upsertEntity(e),t){if(i!==r||a!==o)return this.views.smartInvalidateChildrenViews(i,t,"delete",this.entities),void this.views.smartInvalidateChildrenViews(r,e,"insert",this.entities);this.views.smartInvalidateChildrenViews(r,e,"update",this.entities,void 0,t)}else this.views.smartInvalidateChildrenViews(r,e,"insert",this.entities)}isAncestor(e,t){let i=t;const r=new Set;for(;i&&!r.has(i);){r.add(i);if(P(i)===P(e))return!0;const t=this.entities.getEntity(i);if(!t)break;i=A(t),null===i&&(i="")}return!1}moveEntity(e,t){const i=this.entities.getEntity(e);if(!i)return null;if(b(i)&&null!==t&&this.isAncestor(e,t))return null;const r=A(i),a=this.entities.moveEntityById(e,t);return a?(this.views.smartInvalidateChildrenViews(r,i,"delete",this.entities),this.views.smartInvalidateChildrenViews(t,a,"insert",this.entities),a):null}copyEntity(e,t,i,r){const a=this.entities.getEntity(e);if(!a)return null;let o=null;if(b(a)){var s;const i=[e],a=[];for(;i.length;){const e=i.shift();a.push(e);const t=this.entities.getChildrenIds(e,{onlyFolders:!0});for(const r of t)i.push(r)}const d=new Map;for(const e of a)d.set(e,E());for(const o of a){var n,l;const i=this.entities.getFolder(o),a=d.get(o),s=A(i),h=null===s?t:null!==(n=d.get(s))&&void 0!==n?n:null,c={...i,...o===e?r:void 0,id:a,folderId:null!==(l=o===e?null===r||void 0===r?void 0:r.folderId:void 0)&&void 0!==l?l:h};this.entities.upsertEntity(c)}for(const e of a){const t=d.get(e),i=this.entities.getChildrenIds(e,{onlyFileSystemItems:!0});for(const e of i){const i=this.entities.getFileSystemItem(e);if(!i)continue;const r=E(),a={...i,id:r,folderId:t};this.entities.upsertEntity(a)}}o=null!==(s=this.entities.getEntity(d.get(e)))&&void 0!==s?s:null}else{const a=null!==i&&void 0!==i?i:E();if(o=this.entities.copyFileSystemItem(e,a,null!==t&&void 0!==t?t:null),o&&r){var d,h;const e={...o,...r,id:a,folderId:null!==(d=null!==(h=r.folderId)&&void 0!==h?h:t)&&void 0!==d?d:null};this.entities.upsertEntity(e),o=e}}return o&&this.views.smartInvalidateChildrenViews(t,o,"copy",this.entities),o}searchByUrl(e){var t;return null!==(t=this.entities.searchByUrl(e))&&void 0!==t?t:null}deleteEntity(e){const t=this.entities.getEntity(e);if(!t)return null;if(b(t)){const{deletedFolderRecords:i,deletedFileSystemItemRecords:r}=this.entities.deleteFolderRecursive(e);for(const e of r)this.views.smartInvalidateChildrenViews(e.folderId,e,"delete",this.entities);for(const e of i)this.views.smartInvalidateChildrenViews(e.folderId,e,"delete",this.entities);for(const e of i)this.views.forceInvalidateChildrenViews(e.id);return t}{const{entity:t,parentId:i}=this.entities.deleteEntityById(e);return t&&this.views.smartInvalidateChildrenViews(i,t,"delete",this.entities),t}}deleteFolderRecursive(e){const{deletedFolderRecords:t,deletedFileSystemItemRecords:i}=this.entities.deleteFolderRecursive(e);for(const r of i)this.views.smartInvalidateChildrenViews(r.folderId,r,"delete",this.entities);for(const r of t)this.views.smartInvalidateChildrenViews(r.folderId,r,"delete",this.entities);for(const r of t)this.views.forceInvalidateChildrenViews(r.id);return{deletedFileSystemItemIds:i.map(e=>e.id),deletedFolderIds:t.map(e=>e.id)}}forceInvalidate(e){const t=this.entities.getEntity(e);if(!t)return;const i=new Set;if(b(t)){const t=[e];for(;t.length;){const e=t.pop();if(i.has(e))continue;i.add(e),this.views.forceInvalidateChildrenViews(e);const r=this.entities.getChildrenIds(e,{onlyFolders:!0});for(const i of r)t.push(i)}}else{var r;const e=null!==(r=t.folderId)&&void 0!==r?r:null;this.views.forceInvalidateChildrenViews(e)}}getChildrenIds(e){return this.entities.getChildrenIds(e)}searchByName(e,t){return this.entities.searchByName(e,t)}async getChildrenCount(e="",t){const i=P(e),r=this.childrenCountPromises.get(i);if(r)return r;const a=(async()=>{try{const i=this.entities.getFolder(e);if(i&&"number"===typeof i.childrenCount)return i.childrenCount;const r=this.views.getKnownTotal(e);if("number"===typeof r)return i&&this.handleServerReportedChildrenCount(e,r,this.entities),r;if(t){const i=await t(e);return this.entities.getFolder(e)&&this.handleServerReportedChildrenCount(e,i,this.entities),i}return this.entities.getChildrenIds(e).length}catch(r){if(this.childrenCountPromises.delete(i),function(e){var t,i,r;if(!e||"object"!==typeof e)return!1;const a=e;return"path_folder_not_found"===a.code||"path_folder_not_found"===(null===(t=a.data)||void 0===t?void 0:t.code)||404===a.status||404===(null===(i=a.data)||void 0===i||null===(r=i.data)||void 0===r?void 0:r.status)}(r))return 0;throw r}finally{this.childrenCountPromises.delete(i)}})();return this.childrenCountPromises.set(i,a),a}toJSON(){return{entities:this.entities.toJSON(),views:this.views.toJSON(),ttl:this.ttl,errorTtl:this.errorTtl}}static fromJSON(e,t){var i,r,a,o;const s=new O(null!==t&&void 0!==t?t:{},null!==(i=null===e||void 0===e?void 0:e.ttl)&&void 0!==i?i:3e5,null!==(r=null===e||void 0===e?void 0:e.errorTtl)&&void 0!==r?r:3e4),n=S.fromJSON(null!==(a=null===e||void 0===e?void 0:e.entities)&&void 0!==a?a:{}),l=T.fromJSON(null!==(o=null===e||void 0===e?void 0:e.views)&&void 0!==o?o:{});var d,h,c,u,v;t&&(l.strategy={allowSortedInsert:null===(d=t.allowSortedInsert)||void 0===d||d,allowSearchInsert:null===(h=t.allowSearchInsert)||void 0===h||h,invalidateOnPaginationFull:null===(c=t.invalidateOnPaginationFull)||void 0===c||c,preloadPagesBefore:null!==(u=t.preloadPagesBefore)&&void 0!==u?u:0,preloadPagesAfter:null!==(v=t.preloadPagesAfter)&&void 0!==v?v:1,comparator:t.comparator,filterMatch:t.filterMatch});return s.entities=n,s.views=l,l.setServerChildrenCountHandler((e,t,i)=>{s.handleServerReportedChildrenCount(e,t,null!==i&&void 0!==i?i:n)}),l.setChildrenCountInvalidator(e=>{s.invalidateChildrenCountCache(e)}),s}handleServerReportedChildrenCount(e,t,i){this.checkAndResolveChildrenCountConflict(e,t,i),this.invalidateChildrenCountCache(e)}checkAndResolveChildrenCountConflict(e,t,i){if(!i||void 0===t)return;const r=null!==e&&void 0!==e?e:null;if(!r)return void i.updateServerChildrenCount(r,t);const a=i.getFolder(r),o=null===a||void 0===a?void 0:a.childrenCount;void 0!==o&&o!==t&&this.views.forceInvalidateChildrenViews(r),i.updateServerChildrenCount(r,t)}}var N,D=i(2783);function U(e,t){const i=null!==e&&void 0!==e?e:{},r=Array.isArray(i.detailed)?i.detailed.map(e=>{var i;return{requestId:null!==(i=e.requestId)&&void 0!==i?i:e.id,success:!!e.success,data:t(e.data),error:e.error}}):void 0;return{success:!!i.success,error:i.error,detailed:r}}let x=(B=N=class{async _findOrCreateFolderByPath(e){const{__:t}=this.i18n,i=(r=e)?r.replaceAll("\\","/").split("/").filter(Boolean):[];var r;if(i.length>10){const e=t("Path depth exceeds maximum limit of %s").replace("%s",String(10));throw new D.FileManagerApiError(e,"ValidationError")}let a;for(const n of i){var o;const{files:i}=await this.getFiles({folderId:(null===(o=a)||void 0===o?void 0:o.id)||"",itemType:"folder"}),r=i.find(e=>e.name===n);if(r){if(!r.isFolder){const i=t("Path component '%s' in '%s' is not a folder").replace("%s",n).replace("%s",e);throw new D.FileManagerApiError(i,"ValidationError")}a={id:r.id,name:r.name,parentId:r.folderId}}else{var s;if(!this._dataProvider.createFolder)throw new D.FileManagerApiError(t("Create folder operation is not supported by data provider"),"UnsupportedOperation");a=await this.createFolder({name:n,parentId:null===(s=a)||void 0===s?void 0:s.id})}}return a}getTrashFolder(){return this._findOrCreateFolderByPath(this._pathOptions.trashPath||"Trash")}getTempFolder(){return this._findOrCreateFolderByPath(this._pathOptions.tempPath||"Edited")}constructor(e,t={},i,r=_.nr){var a,o;this._dataProvider=e,this._options=t,this._pathOptions=i,this.i18n=r,this._cache=void 0,this._rootId=void 0,this._useSoftDelete=void 0,this._enableTrash=void 0,this._validateDuplicates=void 0,this._mapItem=async({childrenCount:e,...t})=>{if(t.isFolder)return{...t,childCount:e,url:"",thumbnailUrl:""};const[i,r]=await Promise.all([this._getUrl(t),this._getThumbnailUrl(t)]);return{...t,childCount:0,url:i,thumbnailUrl:r}},this._useSoftDelete=this._pathOptions.useSoftDelete,this._rootId=this._pathOptions.rootId||"",this._enableTrash=void 0===this._options.enableTrash||this._options.enableTrash,this._validateDuplicates=this._dataProvider.validateDuplicates,this._cache=new O(t.cacheStrategy||{},null===(a=t.cacheStrategy)||void 0===a?void 0:a.ttl,null===(o=t.cacheStrategy)||void 0===o?void 0:o.errorTtl),this.setController({invalidateItemCache:e=>{this._cache.forceInvalidate(e)},getCachedItem:e=>this._cache.getEntity(e)}),this._dataProvider.clearCache||(this.clearCache=void 0)}setController(e){var t,i;null===(t=(i=this._dataProvider).setController)||void 0===t||t.call(i,e)}async clearCache(e){if(!this._dataProvider.clearCache){const{__:e}=this.i18n;throw new D.FileManagerApiError(e("Clear cache is not supported by data provider"),"UnsupportedOperation")}this._cache.forceInvalidate(this._rootId),await this._dataProvider.clearCache(e)}normalizeId(e){return e?"root"===e||"folders"===e?this._rootId:e:this._rootId}_validateName(e,t=!1){if(!e||0===e.trim().length){const e=t?"FolderInvalidName":"FileInvalidName",{__:i}=this.i18n,r=i(t?"Folder name cannot be empty":"File name cannot be empty");throw new D.FileManagerApiError(r,e)}if(/[\/\\:*?"<>|]/.test(e)){const{__:i}=this.i18n,r=t?"FolderInvalidName":"FileInvalidName",a=t?i("Folder name contains invalid characters: %s").replace("%s",e):i("File name contains invalid characters: %s").replace("%s",e);throw new D.FileManagerApiError(a,r)}}_validateTargetFolderType(e){const t=this.normalizeId(e);if(t===this._rootId)return;const i=this._cache.getEntity(t);if(i&&!i.isFolder){const{__:t}=this.i18n,i=t("Target item with id '%s' is not a folder").replace("%s",e);throw new D.FileManagerApiError(i,"ValidationError")}}_checkNameExistsInCache(e,t,i,r){const a=this.normalizeId(e),o=this._cache.getChildrenIds(a);for(const s of o){const e=this._cache.getEntity(s);if(e&&e.name===t&&!!e.isFolder===i&&(!r||e.id!==r))return!0}return!1}async _getUrl(e){if(e.url)return e.url;try{var t;return(null===(t=this._dataProvider)||void 0===t?void 0:t.getUrl(e))||""}catch(i){}return""}async _getThumbnailUrl(e){if(e.thumbnailUrl)return e.thumbnailUrl;try{var t;return(null===(t=this._dataProvider)||void 0===t?void 0:t.getThumbnailUrl(e))||""}catch(i){}return""}_isAncestor(e,t){if(!t)return!1;const i=this.normalizeId(t),r=this.normalizeId(e);if(i===r)return!0;let a=this._cache.getEntity(i);const o=new Set;for(;a&&a.folderId&&!o.has(a.id);){o.add(a.id);const e=this.normalizeId(a.folderId);if(e===r)return!0;if(a=this._cache.getEntity(e),!a||!a.isFolder)break}return!1}async getFile(e,t){return this._cache.searchByName(t,{parentId:this.normalizeId(e),caseSensitive:!0,recursive:!1,itemType:"file"})[0]||(await this.getFiles({folderId:e,itemType:"file",search:t})).files[0]}async getFileUrl(e,t){const i=await this.getFile(e,t);return await this._getUrl(i)||await this._getThumbnailUrl(i)||i.thumbnail}async getFiles({folderId:e,search:t,sortBy:i,sortOrder:r,page:a,limit:o,itemType:s="all"}){const n=this.normalizeId(null!==e&&void 0!==e?e:this._rootId),l=!1===this._options.enablePagination,d=l?1:a,h=l?1e3:o,c=this._options.clientSideFilter,u=this._options.clientSideSorting,v=this._options.clientSidePaging,f={folderId:n,itemType:s};c||(f.search=t),u||(f.sortBy=null!==i&&void 0!==i?i:"folder"!==s?"date":void 0,f.sortOrder=null!==r&&void 0!==r?r:"folder"!==s?"desc":void 0),v||(f.page=d,f.limit=h);const m={folderId:n,itemType:s,search:c?void 0:t,sortBy:u?void 0:f.sortBy,sortOrder:u?void 0:f.sortOrder,page:v?void 0:d,pageSize:v?void 0:h},p=await this._cache.getOrCreateChildren(n,m,async(e,t)=>{const i=await this._dataProvider.getItems({...t,folderId:e,limit:Number(t.pageSize)});return{items:i.items,...i.pagination}});let w,g=p.items;if(c)if("function"===typeof this._options.clientSideFilter)g=this._options.clientSideFilter(g,t);else if(t){const e=t.toLowerCase();g=g.filter(t=>{var i;return null===(i=t.name)||void 0===i?void 0:i.toLowerCase().includes(e)})}u&&(g="function"===typeof this._options.clientSideSorting?this._options.clientSideSorting(g,i,r):this._defaultClientSideSort(g,i,r)),w=v||c?g.length:p.total;let I=g;if(v&&a&&o)if("function"===typeof this._options.clientSidePaging)I=this._options.clientSidePaging(g,a,o);else{const e=(a-1)*o,t=e+o;I=g.slice(e,t)}if(this._dataProvider.getUrl||this._dataProvider.getThumbnailUrl){const e=I.map(async e=>{if(e.isFolder)return e;const[t,i]=await Promise.all([e.url?Promise.resolve(e.url):this._dataProvider.getUrl?this._dataProvider.getUrl(e):Promise.resolve(void 0),e.thumbnailUrl?Promise.resolve(e.thumbnailUrl):this._dataProvider.getThumbnailUrl?this._dataProvider.getThumbnailUrl(e):Promise.resolve(void 0)]);return{...e,url:t,thumbnailUrl:i}});I=await Promise.all(e)}const y={page:d,limit:h,total:w,...!v&&p.totalPages&&{totalPages:p.totalPages},...!v&&p.hasNextPage&&{hasNextPage:p.hasNextPage}};return{files:await Promise.all(I.map(this._mapItem)),pagination:y}}_defaultClientSideSort(e,t,i){return e.sort((e,r)=>{let a=0;switch(t){case"name":default:a=(e.name||"").localeCompare(r.name||"");break;case"date":a=new Date(e.date||0).getTime()-new Date(r.date||0).getTime();break;case"size":a=(Number(e.size)||0)-(Number(r.size)||0)}return"desc"===i?-a:a})}async getFileData(e){const t=this.normalizeId("string"===typeof e?e:e.id),i=this._cache.getEntity(t)||("string"===typeof e?{id:t,name:"",folderId:this._rootId,isFolder:!1}:{...e,childrenCount:e.childCount});if(this._dataProvider.getFileData)return await this._dataProvider.getFileData(i);const{__:r}=this.i18n;if(!i.url&&!this._dataProvider.getUrl)throw new D.FileManagerApiError(r("Cannot read file"),"FileReadError");const a=i.url||await this._dataProvider.getUrl(i);if(a)return(await fetch(a)).blob();throw new D.FileManagerApiError(r("Unable to get file data"),"FileReadError")}async findFileByUrl(e){const t=this._cache.searchByUrl(e);if(t)return t;if(this._dataProvider.findFileByUrl)try{const t=await this._dataProvider.findFileByUrl(e);if(t)return this._cache.upsertEntity(t),t}catch(i){}return null}async getChildrenCount(e){if(!e)return 0;const t=this.normalizeId(null!==e&&void 0!==e?e:this._rootId);return this._cache.getChildrenCount(t,async()=>{try{const e=await this._dataProvider.getItems({folderId:t,limit:0,itemType:"all"});return"undefined"!==typeof e.pagination?e.pagination.total||0:!1===this._options.enablePagination?e.items.length:0}catch(e){if(this._isPathFolderNotFoundError(e))return 0;throw e}})}_isPathFolderNotFoundError(e){var t,i,r;if(!e||"object"!==typeof e)return!1;const a=e;return"path_folder_not_found"===a.code||"path_folder_not_found"===(null===(t=a.data)||void 0===t?void 0:t.code)||404===a.status||404===(null===(i=a.data)||void 0===i||null===(r=i.data)||void 0===r?void 0:r.status)}async _uploadFile(e){var t;const i=this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:this._rootId);if(this._validateName(e.name,!1),this._validateDuplicates&&this._checkNameExistsInCache(i,e.name,!1)){const{__:t}=this.i18n,i=t("File '%s' already exists in target folder").replace("%s",e.name);throw new D.FileManagerApiError(i,"FileAlreadyExists")}const r={...this._cache.getEntity(i),...await this._dataProvider.uploadFile({...e,folderId:i}),folderId:i};return this._cache.upsertEntity(r),r}async uploadFiles(e){var t,i;const r=(e={...e,items:null===(t=e.items)||void 0===t?void 0:t.map(e=>({...e,folderId:e.noFolder?o.id:e.folderId}))}).items||[],a=null!==(i=e.folderId)&&void 0!==i?i:this._rootId,o=await this.getTempFolder(),s=this.normalizeId(a);if(this._validateDuplicates)for(const v of r)if(v.name){var n;this._validateName(v.name,!1);const e=this.normalizeId(null!==(n=v.folderId)&&void 0!==n?n:s);if(this._checkNameExistsInCache(e,v.name,!1)){const{__:e}=this.i18n,t=e("File '%s' already exists in target folder").replace("%s",v.name);throw new D.FileManagerApiError(t,"FileAlreadyExists")}}const l=this._cache.getEntity(s);let d={detailed:new Array(r.length),success:!0};if(this._dataProvider.uploadFiles){const e=r.map(e=>{var t;return{...e,folderId:this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:s)}});if(d=U(await this._dataProvider.uploadFiles({folderId:s,items:e}),e=>{if(e)return{id:e.id,name:e.name,folderId:e.folderId}}),d.detailed&&d.detailed.length){for(let e=0;e<d.detailed.length;e++){const t=d.detailed[e];if(t&&t.success){var h,c;const e=t.data,i=null!==(h=null===e||void 0===e?void 0:e.id)&&void 0!==h?h:t.requestId,r={...l,...e,folderId:null!==(c=null===e||void 0===e?void 0:e.folderId)&&void 0!==c?c:s};this._cache.upsertEntity(r),t.requestId=i}}void 0===d.success&&(d.success=!d.detailed.some(e=>!e.success))}else d.success=!d.error&&!!d.success}else{if(!this._dataProvider.uploadFile)throw new D.FileManagerApiError("Upload files is not supported by data provider","UnsupportedOperation");d.detailed=await Promise.all(r.map(async e=>{var t;const i=this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:s);try{const t=await this._uploadFile({...e,folderId:i});return{requestId:t.id,data:t,success:!0}}catch(r){return{requestId:null===e||void 0===e?void 0:e.id,success:!1,error:r}}})),d.success=!d.detailed.some(e=>!e.success)}if(d.success&&this._enableTrash)try{this._cache.forceInvalidate(s)}catch(u){}return d}async deleteFile(e){const t=this.normalizeId(e);if(this._useSoftDelete&&this._enableTrash){const e=await this.getTrashFolder();return await this.moveItem({itemId:t,targetFolderId:e.id,isFolder:!1})}return await this.hardDeleteItem(t)}async deleteItems(e,t){if(this._useSoftDelete&&this._enableTrash&&!0!==t.permanent){const t=await this.getTrashFolder();return await this.moveItems(t.id,e)}return await this.hardDeleteItems(e,t)}async hardDeleteItems(e,t){let i={success:!0,detailed:[]};const r=t.permanent?null:await this.getTrashFolder();if(this._dataProvider.deleteItems){if(i=U(await this._dataProvider.deleteItems(e.map(e=>this._cache.getEntity(e)),t),e=>e),i.success){const t=i.detailed||e.map(e=>({requestId:e,success:!0,error:void 0}));for(const e of t)e.success&&(r?this._cache.moveEntity(e.requestId,r.id):this._cache.deleteEntity(e.requestId))}}else this._dataProvider.deleteItem&&(i.detailed=await Promise.all(e.map(async e=>{const i=this._cache.getEntity(e);if(!i){const t="FileNotFound",{__:i}=this.i18n,r=i("Item with id '%s' not found").replace("%s",e);return{requestId:e,success:!1,error:new D.FileManagerApiError(r,t)}}try{return await this._dataProvider.deleteItem(i,t),r?this._cache.moveEntity(e,r.id):this._cache.deleteEntity(e),{requestId:e,success:!0}}catch(a){return{requestId:e,error:a,success:!1}}})),i.success=!i.detailed.some(e=>!e.success));if(i.success&&r)try{this._cache.forceInvalidate(r.id)}catch(a){}return i}async hardDeleteItem(e){const t=this._cache.getEntity(e);if(!t){const{__:t}=this.i18n,i=t("Item with id '%s' not found in cache").replace("%s",e);throw new D.FileManagerApiError(i,"FileNotFound")}if(await this._dataProvider.deleteItem(t,{permanent:!0}),this._cache.deleteEntity(e),this._enableTrash)try{const e=await this.getTrashFolder();e&&this._cache.forceInvalidate(e.id)}catch(i){}return!0}async cleanTrash(){const{__:e}=this.i18n;if(!this._enableTrash)throw new D.FileManagerApiError(e("Trash is not enabled"),"UnsupportedOperation");if(this._dataProvider.cleanTrash){const e=await this._dataProvider.cleanTrash();try{const e=await this.getTrashFolder();e&&this._cache.forceInvalidate(e.id)}catch(t){}return e}throw new D.FileManagerApiError(e("Clean trash is not supported by data provider"),"UnsupportedOperation")}async createFolder({name:e,parentId:t,is_force_create:i}){const r=this.normalizeId(null!==t&&void 0!==t?t:this._rootId);if(this._validateName(e,!0),this._validateDuplicates&&this._checkNameExistsInCache(r,e,!0)){const{__:t}=this.i18n,i=t("Folder '%s' already exists in parent folder").replace("%s",e);throw new D.FileManagerApiError(i,"FolderAlreadyExists")}const a=await this._dataProvider.createFolder(e,r,i);return this._cache.upsertEntity({id:a.id,folderId:r,name:a.name,isFolder:!0,childrenCount:a.childrenCount}),a}async deleteFolder(e){const t=this.normalizeId(e);if(this._useSoftDelete&&this._enableTrash)try{const e=await this.getTrashFolder();return!!await this.moveItem({itemId:t,targetFolderId:e.id,isFolder:!0})&&(this._cache.deleteFolderRecursive(t),!0)}catch(i){return await this.hardDeleteItem(t)}return await this.hardDeleteItem(t)}async renameFolder(e,t){const{__:i}=this.i18n;if(!this._dataProvider.renameItem)throw new D.FileManagerApiError(i("Rename folder is not supported"),"RenameNotAllowed");const r=this.normalizeId(e),a=this._cache.getEntity(r);if(!a){const t=i("Folder with id '%s' not found in cache").replace("%s",e);throw new D.FileManagerApiError(t,"FolderNotFound")}if(this._validateName(t,!0),this._validateDuplicates){const e=this.normalizeId(a.folderId);if(this._checkNameExistsInCache(e,t,!0,r)){const e=i("Folder '%s' already exists in parent folder").replace("%s",t);throw new D.FileManagerApiError(e,"FolderAlreadyExists")}}const o=await this._dataProvider.renameItem(a,t);return this._cache.upsertEntity({...this._cache.getEntity(o.id),...o}),this._cache.getEntity(o.id)}async renameFile(e,t){const{__:i}=this.i18n;if(!this._dataProvider.renameItem)throw new D.FileManagerApiError(i("Rename file is not supported"),"RenameNotAllowed");const r=this._cache.getEntity(e);if(!r){const t=i("File with id '%s' not found in cache").replace("%s",e);throw new D.FileManagerApiError(t,"FileNotFound")}const a=this.normalizeId(e);if(this._validateName(t,!1),this._validateDuplicates){const e=this.normalizeId(r.folderId);if(this._checkNameExistsInCache(e,t,!1,a)){const e=i("File '%s' already exists in parent folder").replace("%s",t);throw new D.FileManagerApiError(e,"FileAlreadyExists")}}const o=await this._dataProvider.renameItem(r,t);return o&&this._cache.upsertEntity({...this._cache.getEntity(a),...o}),this._cache.getEntity(a)}async moveItem({itemId:e,targetFolderId:t,isFolder:i}){const r=this.normalizeId(t);this._validateTargetFolderType(t);const a=this._cache.getEntity(e);if(!a){const t=await this._dataProvider.moveItem({id:e,folderId:r,isFolder:i},r);if(t.id===e)this._cache.upsertEntity({...t,folderId:r});else{try{this._cache.deleteEntity(e)}catch(n){}this._cache.upsertEntity({...t,folderId:r})}return!0}const{__:o}=this.i18n;if(a.isFolder){if(e===r)throw new D.FileManagerApiError(o("Cannot move folder into itself"),"MoveIntoSelf");if(this._isAncestor(e,r))throw new D.FileManagerApiError(o("Cannot move folder into its descendant"),"MoveIntoDescendant")}if(this._validateDuplicates&&r!==this.normalizeId(a.folderId)&&a.name&&this._checkNameExistsInCache(r,a.name,!!a.isFolder,e)){const e=a.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new D.FileManagerApiError(`${a.isFolder?"Folder":"File"} '${a.name}' already exists in target folder`,e)}const s=await this._dataProvider.moveItem(a,r);if(s.id===e){const t=this._cache.moveEntity(e,r);return this._cache.upsertEntity({...t,...s}),!0}{const t=this._cache.deleteEntity(e);return this._cache.upsertEntity({...t,...s,folderId:r}),!0}}async moveItems(e,t){const i=this.normalizeId(e);this._validateTargetFolderType(e);const r=t.map(e=>this._cache.getEntity(e));for(const o of r)if(o){if(o.isFolder){const{__:e}=this.i18n;if(o.id===i){const t=e("Cannot move folder '%s' into itself").replace("%s",o.name);throw new D.FileManagerApiError(t,"MoveIntoSelf")}if(this._isAncestor(o.id,i)){const t=e("Cannot move folder '%s' into its descendant").replace("%s",o.name);throw new D.FileManagerApiError(t,"MoveIntoDescendant")}}if(this._validateDuplicates){const e=this.normalizeId(o.folderId);if(i!==e&&o.name&&this._checkNameExistsInCache(i,o.name,!!o.isFolder,o.id)){const e=o.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new D.FileManagerApiError(`${o.isFolder?"Folder":"File"} '${o.name}' already exists in target folder`,e)}}}let a={detailed:new Array(r.length),success:!0};if(this._dataProvider.moveItems)a=U(await this._dataProvider.moveItems(r,i),e=>e);else{if(!this._dataProvider.moveItem)throw new D.FileManagerApiError("Move items is not supported","MoveNotAllowed");a.detailed=await Promise.all(t.map(async(e,t)=>{const a=r[t]||{id:e,folderId:null,isFolder:!1,name:e};try{return{requestId:e,data:await this._dataProvider.moveItem(a,i),success:!0}}catch(o){return{requestId:e,success:!1,error:o}}}))}if(a.success){const e=a.detailed||t.map(e=>({requestId:e,success:!0,data:void 0}));for(const t of e)if(t.success)if(t.data&&t.data.id!==t.requestId){const e=this._cache.deleteEntity(t.requestId);this._cache.upsertEntity({...e,...t.data,folderId:i})}else this._cache.moveEntity(t.requestId,i),t.data&&this._cache.upsertEntity({...this._cache.getEntity(t.requestId),...t.data,folderId:i});return a}{const{__:e}=this.i18n;return{success:!1,error:a.error||new D.FileManagerApiError(e("Move items failed"),"MoveNotAllowed")}}}async copyItem({itemId:e,targetFolderId:t}){if(!this._dataProvider.copyItem){const{__:e}=this.i18n;throw new D.FileManagerApiError(e("Copy item is not supported"),"CopyNotAllowed")}const i=this.normalizeId(t);this._validateTargetFolderType(t);const r=this._cache.getEntity(e);if(!r){const t=await this._dataProvider.copyItem({id:e,folderId:i},i);return this._cache.copyEntity(e,i,t.id),this._cache.upsertEntity({...t,folderId:i}),!0}if(this._validateDuplicates&&r.name){const t=i===this.normalizeId(r.folderId)?e:void 0;if(this._checkNameExistsInCache(i,r.name,!!r.isFolder,t)){const e=r.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new D.FileManagerApiError(`${r.isFolder?"Folder":"File"} '${r.name}' already exists in target folder`,e)}}const a=await this._dataProvider.copyItem(r,i);return this._cache.copyEntity(e,i,a.id,{...a,folderId:i})||this._cache.upsertEntity({...a,folderId:i}),!0}async copyItems(e,t){const i=this.normalizeId(e);this._validateTargetFolderType(e);const r=t.map(e=>"string"===typeof e?{id:e}:e),a=r.map(e=>e.id),o=a.map((e,t)=>{var i;const a=this._cache.getEntity(e),o=null===(i=r[t])||void 0===i?void 0:i.newName;return a?o?{...a,name:o}:a:void 0});if(this._validateDuplicates)for(let l=0;l<o.length;l++){const e=o[l];if(e&&e.name){const t=this.normalizeId(e.folderId),r=i===t?a[l]:void 0;if(this._checkNameExistsInCache(i,e.name,!!e.isFolder,r)){const t=e.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new D.FileManagerApiError(`${e.isFolder?"Folder":"File"} '${e.name}' already exists in target folder`,t)}}}let s={detailed:new Array(o.length),success:!0};if(this._dataProvider.copyItems)s=U(await this._dataProvider.copyItems(o,i),e=>e);else{if(!this._dataProvider.copyItem){const{__:e}=this.i18n;throw new D.FileManagerApiError(e("Copy items is not supported"),"CopyNotAllowed")}s.detailed=await Promise.all(a.map(async(e,t)=>{const r=o[t]||{id:e,folderId:null,isFolder:!1};try{return{requestId:e,data:await this._dataProvider.copyItem(r,i),success:!0}}catch(a){return{requestId:e,success:!1,error:a}}}))}if(s.success&&s.detailed)for(let l=0,d=s.detailed.length;l<d;l++){const e=s.detailed[l];var n;if(e.success&&null!==(n=e.data)&&void 0!==n&&n.id){const t=e.data.folderId||i;!this._cache.copyEntity(e.requestId,t,e.data.id,{...e.data,folderId:t})&&e.data&&this._cache.upsertEntity({...e.data,folderId:t})}}else if(!s.detailed)throw new D.FileManagerApiError("batchResult in copy method must have detailed results","ValidationError");return s}async uploadFileByUrl(e){var t;if(e.noFolder){const t=await this.getTempFolder();e={...e,folderId:t.id}}const i=this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:this._rootId);try{const t=await this._dataProvider.uploadFileByUrl(e.url,i,{eventSource:e.eventSource});return this._cache.upsertEntity({...t,folderId:i}),t}catch(r){throw r}}async updateFile(e,t){const{__:i}=this.i18n;if(!this._dataProvider.updateFile)throw new D.FileManagerApiError(i("Update file is not supported"),"UnsupportedOperation");const r=this.normalizeId(e),a=this._cache.getEntity(r);if(!a){const t=i("File with id '%s' not found in cache").replace("%s",e);throw new D.FileManagerApiError(t,"FileNotFound")}if(t.name&&t.name!==a.name&&this._validateName(t.name,!1),this._validateDuplicates&&t.name&&t.name!==a.name){const e=this.normalizeId(a.folderId);if(this._checkNameExistsInCache(e,t.name,!1,r)){const e=i("File '%s' already exists in parent folder").replace("%s",t.name);throw new D.FileManagerApiError(e,"FileAlreadyExists")}}const o=await this._dataProvider.updateFile(a,{...t});return this._cache.upsertEntity({...this._cache.getEntity(r),...o,...t}),this._cache.getEntity(r)}},class extends B{constructor(...e){super(...e);const t=Object.getOwnPropertyNames(B.prototype);for(const i of t){const e=Object.getOwnPropertyDescriptor(B.prototype,i);"constructor"!==i&&"function"===typeof(null===e||void 0===e?void 0:e.value)&&this[i]&&(this[i]=this[i].bind(this))}}}||N);var B,R=i(93628),k=i(93506),z=(i(80708),i(10968));class G{constructor(e,t="",i="Trash",r="Trash",a=!0,o=_.nr){this._inner=e,this.rootPath=t,this.trashId=i,this.trashPath=r,this.ensureFolderTrailingSlash=a,this.i18n=o,this._pathToId=new Map,this._idToPath=new Map,this.getUrl=void 0,this.getThumbnailUrl=void 0,this.validateDuplicates=void 0,this.validateDuplicates=this._inner.validateDuplicates,e.getUrl&&(this.getUrl=t=>e.getUrl({...t,id:this.pathForId(t.id,!1),folderId:t.folderId?this.pathForId(t.folderId,!0):this.rootPath})),e.getThumbnailUrl&&(this.getThumbnailUrl=t=>e.getThumbnailUrl({...t,id:this.pathForId(t.id,!1),folderId:t.folderId?this.pathForId(t.folderId,!0):this.rootPath})),this._inner.deleteItems||(this.deleteItems=void 0),this._inner.deleteItem||(this.deleteItem=void 0),this._inner.moveItems?this.moveItem=void 0:this.moveItems=void 0,this._inner.copyItems?this.copyItem=void 0:this.copyItems=void 0,this._inner.uploadFiles?this.uploadFile=void 0:this.uploadFiles=void 0,this._inner.clearCache||(this.clearCache=void 0),this._getOrGenerateId(this.rootPath)}setController(e){var t,i;null===(t=(i=this._inner).setController)||void 0===t||t.call(i,{invalidateItemCache:t=>{const i=t.replace(/^\/+|\/+$/g,""),r=this._pathToId.get(i);r&&e.invalidateItemCache(r)},getCachedItem:t=>{const i=t.replace(/^\/+|\/+$/g,""),r=this._pathToId.get(i);if(r){const t=e.getCachedItem(r);if(t)return{...t,id:this.pathForId(t.id,t.isFolder),folderId:this.pathForId(t.folderId,t.isFolder)}}}})}clearCache(e){if(this._inner.clearCache)return this._inner.clearCache(e)}_getOrGenerateId(e){if(e===this.rootPath)return;const t=e.replaceAll(/^\/+|\/+$/g,"");if(t===this.trashPath.replaceAll(/^\/+|\/+$/g,""))return this.trashId;if(this._pathToId.has(t))return this._pathToId.get(t);const i=(0,z.A)();return this._pathToId.set(t,i),this._idToPath.set(i,t),i}pathForId(e,t,i){const{__:r}=this.i18n;if(""===e||void 0===e)return this.rootPath;if(e===this.trashId)return this.trashPath;let a=this._idToPath.get(e);if(!a){if(i)return`unknown folder ${e}`;{const t=r?r(`Path for id '${e}' not found in mapping`):`Path for id '${e}' not found in mapping`;throw new D.FileManagerApiError(t,"FileNotFound")}}let o=0;for(;o<this.rootPath.length&&"/"===this.rootPath[o];)o++;if(o){let e=0;for(;e<a.length&&"/"===a[e];)e++;const t=a.slice(e);a="/".repeat(o)+t}return t&&this.ensureFolderTrailingSlash&&!a.endsWith("/")&&(a+="/"),a}_updateIdMapping(e,t){const i=t.replace(/^\/+|\/+$/g,""),r=this._idToPath.get(e);r&&this._pathToId.delete(r),this._idToPath.set(e,i),this._pathToId.set(i,e)}async getItems(e){const t=e.folderId?this.pathForId(e.folderId,!0):this.rootPath,i=await this._inner.getItems({...e,folderId:t}),r=i.items.map(e=>{const t=this._getOrGenerateId(e.id),i=e.folderId?this._getOrGenerateId(e.folderId):this._getOrGenerateId(this.rootPath);return{...e,id:t,folderId:i}});return{...i,items:r}}async createFolder(e,t,i){const r=t?this.pathForId(t,!0):this.rootPath,a=await this._inner.createFolder(e,r,i),o=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):this._getOrGenerateId(this.rootPath);return{...a,id:o,folderId:s}}async renameItem(e,t){const{__:i}=this.i18n;if(!this._inner.renameItem){const e=i?i("Rename item is not supported by inner storage"):"Rename item is not supported by inner storage";throw new D.FileManagerApiError(e,"RenameNotAllowed")}const r=this.pathForId(e.id,e.isFolder),a=r;let{...o}=await this._inner.renameItem({...e,id:r,folderId:this.pathForId(e.folderId,!0)},t);return this._updateIdMapping(e.id,o.id),e.isFolder&&this.remapCachedFolderContents(e.id,a,o.id),o.folderId&&(o={...o,folderId:this._getOrGenerateId(o.folderId)}),{...o,id:this._getOrGenerateId(o.id)}}async deleteItem(e,t){const i=this.pathForId(e.id,e.isFolder);await this._inner.deleteItem({...e,id:i,folderId:this.pathForId(e.folderId,!0)},t),this.recursivelyRemoveMappings(e.id,i)}async uploadFile(e){const t=e.folderId?this.pathForId(e.folderId,!0):this.rootPath,i=await this._inner.uploadFile({...e,folderId:t}),r=this._getOrGenerateId(i.id),a=i.folderId?this._getOrGenerateId(i.folderId):this._getOrGenerateId(this.rootPath);return{...i,id:r,folderId:a}}async uploadFiles(e){var t,i,r,a,o;const s=e.folderId,n=null!==(t=null===(i=e.items)||void 0===i?void 0:i.map(e=>e.folderId))&&void 0!==t?t:[],l=e.folderId?this.pathForId(e.folderId,!0):this.rootPath,d={...e,folderId:l,items:null!==(r=null===(a=e.items)||void 0===a?void 0:a.map(e=>({...e,folderId:e.folderId?this.pathForId(e.folderId,!0):l})))&&void 0!==r?r:[]},h=await this._inner.uploadFiles(d);return{...h,detailed:null===(o=h.detailed)||void 0===o?void 0:o.map((e,t)=>{var i,r;if(null===e||void 0===e||!e.data)return e;const a=e.data.id?this._getOrGenerateId(e.data.id):void 0,o=e.data.folderId?this._getOrGenerateId(e.data.folderId):null!==(i=null!==(r=n[t])&&void 0!==r?r:s)&&void 0!==i?i:this._getOrGenerateId(this.rootPath);return{...e,data:{...e.data,id:a,folderId:o}}})}}async findFileByUrl(e,t){const i=t?this.pathForId(t,!0):this.rootPath;if(this._inner.findFileByUrl){const t=await this._inner.findFileByUrl(e,i);if(!t)return;const r=this._getOrGenerateId(t.id),a=t.folderId?this._getOrGenerateId(t.folderId):this._getOrGenerateId(this.rootPath);return{...t,id:r,folderId:a}}}async uploadFileByUrl(e,t,i){const r=t?this.pathForId(t,!0):this.rootPath,a=await this._inner.uploadFileByUrl(e,r,i),o=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):this._getOrGenerateId(this.rootPath);return{...a,id:o,folderId:s}}async moveItem(e,t){const i=this.pathForId(e.id,e.isFolder),r=this.pathForId(t,!0),a=await this._inner.moveItem({...e,id:i,folderId:this.pathForId(e.folderId,!0)},r);this._updateIdMapping(e.id,a.id),e.isFolder&&this.remapCachedFolderContents(e.id,i,a.id);const o=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):t;return{...a,id:o,folderId:s}}async moveItems(e,t){const{__:i}=this.i18n;if(!this._inner.moveItems){const e=i?i("Move items is not supported by inner storage"):"Move items is not supported by inner storage";throw new D.FileManagerApiError(e,"MoveNotAllowed")}const r=t?this.pathForId(t,!0):this.rootPath,a=e.map(e=>({...e,id:this.pathForId(e.id,e.isFolder),folderId:e.folderId?this.pathForId(e.folderId,!0):this.rootPath})),o=await this._inner.moveItems(a,r),s=[];if(o.detailed&&o.detailed.length>0){const r=new Map;for(let t=0;t<o.detailed.length;t++){const i=o.detailed[t],a=i.requestId||(t<e.length?e[t].id:void 0);a&&r.set(a,i)}for(const a of e){const n=r.get(a.id)||(o.detailed.length===e.length?o.detailed[e.indexOf(a)]:void 0);if(null!==n&&void 0!==n&&n.success&&n.data){if(this._updateIdMapping(a.id,n.data.id),a.isFolder){const e=this.pathForId(a.id,a.isFolder);this.remapCachedFolderContents(a.id,e,n.data.id)}s.push({requestId:a.id,success:!0,data:{...n.data,id:this._getOrGenerateId(n.data.id),folderId:n.data.folderId?this._getOrGenerateId(n.data.folderId):t||this._getOrGenerateId(this.rootPath)}})}else{const e=i?i("Move operation failed - no detailed result"):"Move operation failed - no detailed result";s.push({requestId:a.id,success:!1,error:(null===n||void 0===n?void 0:n.error)||{message:e,code:"MoveNotAllowed"}})}}}else for(const n of e){const e=i?i("Move operation failed - no detailed results"):"Move operation failed - no detailed results";s.push({requestId:n.id,success:!1,error:{message:e,code:"MoveNotAllowed"}})}return{success:o.success,detailed:s,error:o.error}}async copyItems(e,t){const{__:i}=this.i18n;if(!this._inner.copyItems){const e=i?i("Copy items is not supported by inner storage"):"Copy items is not supported by inner storage";throw new D.FileManagerApiError(e,"CopyNotAllowed")}const r=t?this.pathForId(t,!0):this.rootPath,a=e.map(e=>({...e,id:this.pathForId(e.id,e.isFolder),folderId:e.folderId?this.pathForId(e.folderId,!0):this.rootPath})),o=await this._inner.copyItems(a,r),s=[];if(o.detailed&&o.detailed.length>0){const r=new Map;for(let t=0;t<o.detailed.length;t++){const i=o.detailed[t],a=i.requestId||(t<e.length?e[t].id:void 0);a&&r.set(a,i)}for(const a of e){var n;const l=r.get(a.id)||(o.detailed.length===e.length?o.detailed[e.indexOf(a)]:void 0);if(null!==l&&void 0!==l&&l.success&&null!==(n=l.data)&&void 0!==n&&n.id){const e=this._getOrGenerateId(l.data.id);s.push({requestId:a.id,success:!0,data:{...l.data,id:e,folderId:l.data.folderId?this._getOrGenerateId(l.data.folderId):t||this._getOrGenerateId(this.rootPath)}})}else{const e=l?l.success?l.data?l.data.id?{message:i?i("Unknown copy error"):"Unknown copy error",code:"CopyNotAllowed"}:{message:i?i("No ID in copied item data"):"No ID in copied item data",code:"CopyNotAllowed"}:{message:i?i("No data returned from copy operation"):"No data returned from copy operation",code:"CopyNotAllowed"}:l.error||{message:i?i("Copy operation failed"):"Copy operation failed",code:"CopyNotAllowed"}:{message:i?i("No detailed result from copy operation"):"No detailed result from copy operation",code:"CopyNotAllowed"};s.push({requestId:a.id,success:!1,error:e})}}}else for(const h of e){const e=i?i("No detailed results from copy operation"):"No detailed results from copy operation";s.push({requestId:h.id,success:!1,error:{message:e,code:"CopyNotAllowed"}})}const l=s.every(e=>e.success),d=i?i("Copy operation completed with errors"):"Copy operation completed with errors";return{success:l,detailed:s,error:l?void 0:o.error||{message:d,code:"CopyNotAllowed"}}}async deleteItems(e,t){const{__:i}=this.i18n;if(!this._inner.deleteItems){const e=i?i("Delete items is not supported by inner storage"):"Delete items is not supported by inner storage";throw new D.FileManagerApiError(e,"DeleteNotAllowed")}const r=e.map(e=>({...e,id:this.pathForId(e.id,e.isFolder),folderId:e.folderId?this.pathForId(e.folderId,!0):this.rootPath})),a=await this._inner.deleteItems(r,t),o=[];if(a.detailed&&a.detailed.length>0){const r=new Map;for(let t=0;t<a.detailed.length;t++){const i=a.detailed[t],o=i.requestId||(t<e.length?e[t].id:void 0);o&&r.set(o,i)}for(const s of e){const n=r.get(s.id)||(a.detailed.length===e.length?a.detailed[e.indexOf(s)]:void 0);if(null!==n&&void 0!==n&&n.success){const e=this.pathForId(s.id,s.isFolder);if(t.permanent)this.recursivelyRemoveMappings(s.id,e);else if(this._updateIdMapping(s.id,this.trashPath+"/"+e+(s.isFolder?"/":"")),s.isFolder){const t=this.pathForId(s.id,s.isFolder);this.remapCachedFolderContents(s.id,t,this.trashPath+"/"+e+(s.isFolder?"/":""))}o.push({requestId:s.id,success:!0})}else{const e=i?i("Delete operation failed"):"Delete operation failed";o.push({requestId:s.id,success:!1,error:(null===n||void 0===n?void 0:n.error)||{message:e,code:"DeleteNotAllowed"}})}}}else for(const l of e)if(a.success){const e=this.pathForId(l.id,l.isFolder);if(t.permanent)this.recursivelyRemoveMappings(l.id,e);else if(this._updateIdMapping(l.id,this.trashPath+"/"+e+(l.isFolder?"/":"")),l.isFolder){const t=this.pathForId(l.id,l.isFolder);this.remapCachedFolderContents(l.id,t,this.trashPath+"/"+e+(l.isFolder?"/":""))}o.push({requestId:l.id,success:!0})}else{const e=i?i("Delete operation failed"):"Delete operation failed";o.push({requestId:l.id,success:!1,error:a.error||{message:e,code:"DeleteNotAllowed"}})}const s=o.every(e=>e.success),n=i?i("Some items failed to delete"):"Some items failed to delete";return{success:s,detailed:o,error:s?void 0:a.error||{message:n,code:"DeleteNotAllowed"}}}remapCachedFolderContents(e,t,i){const r=t.replace(/\/+$/,""),a=i.replace(/\/+$/,""),o=[];for(const[s,n]of this._idToPath.entries()){const e=n.replace(/\/+$/,"");e!==r&&e.startsWith(r+"/")&&o.push({id:s,oldPath:e})}for(const{id:s,oldPath:n}of o){const e=a+n.substring(r.length);this._updateIdMapping(s,e)}}recursivelyRemoveMappings(e,t){const i=t.replace(/\/+$/,""),r=[],a=[];for(const[o,s]of this._idToPath.entries()){const e=s.replace(/\/+$/,"");(e===i||e.startsWith(i+"/"))&&(r.push(o),a.push(e))}for(let o=0;o<r.length;o++)this._idToPath.delete(r[o]),this._pathToId.delete(a[o])}async copyItem(e,t){const i=this.pathForId(e.id,e.isFolder),r=this.pathForId(t,!0),a=await this._inner.copyItem({...e,id:i,folderId:this.pathForId(e.folderId,!0)},r),o=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):t;return{...a,id:o,folderId:s}}async updateFile(e,t){const{__:i}=this.i18n;if(!this._inner.updateFile){const e=i?i("Update file is not supported by inner storage"):"Update file is not supported by inner storage";throw new D.FileManagerApiError(e,"UnsupportedOperation")}const r=this.pathForId(e.id,!1);let{...a}=await this._inner.updateFile({...e,id:r,folderId:this.pathForId(e.folderId,!0)},t);return this._updateIdMapping(e.id,a.id),a.folderId&&(a={...a,folderId:this._getOrGenerateId(a.folderId)}),{...a,id:this._getOrGenerateId(a.id)}}async getFileData(e){const{__:t}=this.i18n,i=this.pathForId(e.id,!1);if(this._inner.getFileData)return this._inner.getFileData({...e,id:i,folderId:this.pathForId(e.folderId,!0)});const r=e.url||this.getUrl&&await this.getUrl(e);if(!r){const e=t?t("Cannot get file data: no url and no inner.getFileData"):"Cannot get file data: no url and no inner.getFileData";throw new D.FileManagerApiError(e,"FileReadError")}return fetch(r).then(e=>e.blob())}async cleanTrash(){const{__:e}=this.i18n;if(!this._inner.cleanTrash){const t=e?e("Clean trash is not supported by inner storage"):"Clean trash is not supported by inner storage";throw new D.FileManagerApiError(t,"UnsupportedOperation")}return await this._inner.cleanTrash()}}var L=i(25516),V=i(20263),q=i(70529);const $="a_T7zSNUXtMfhVWQbIOMpXIPqzLQ8hm5Wfclm2nU98PtlSVxcft8FSn5InbD04056fYCpKXP20jJSySRLu",j={ru:"ru_RU",en:"en_GB",uk:"uk_UA",de:"de_DE",fr:"fr_FR",es:"es_ES",it:"it_IT",pt:"pt_PT",pl:"pl_PL",zh:"zh-Hans_CN",ja:"ja_JP"};async function K(e,t={}){const i=e.trim();if(!i)return i;const r=(e=>{if(!e)return"en_GB";const t=e.toLowerCase().split(/[-_]/)[0];return j[t]||"auto"})(t.locale);if(t.locale&&"en_GB"===r)return i;try{const e={from:t.locale?r:"auto",to:"en_GB",data:i,platform:"api"},a=await fetch("https://api-b2b.backenster.com/b1/api/v3/translate",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${$}`},body:JSON.stringify(e)});if(!a.ok)return i;const o=await a.json();if(o.err)return i;const s=o.result;return"string"===typeof s&&s.trim()?s.trim():i}catch(a){return i}}function J(){const e=(0,a.Pj)(),t=(0,a.d4)(c.B),i=(0,g.ml)(F.AZ.ON_TRANSLATE_ID);return(0,r.useCallback)(async(r,a={})=>{var o;const s=r.trim();if(!s)return s;const n=null!==(o=a.locale)&&void 0!==o?o:"string"===typeof t?t:void 0,l=void 0!==V.di.getInstance(e,q.Ef);try{const e=await i.fire({input:s,locale:n}),t=function(e){for(const t of e)if("string"===typeof t&&t.trim().length>0)return t.trim();return null}(Array.isArray(e)?e:[e]);if(t)return t}catch(d){}return l?s:K(s,{locale:n}).catch(()=>s)},[t,e,i])}var H=i(2527);const Y=(0,r.memo)(R.KG),W=(0,r.memo)(R.BC),{useToken:X}=s.A,Z=({storageProvider:e})=>{var t,i,s,y,P,C,A,b,E,M,S,T,O,N,D,U,B,R;const z=(0,p.rD)(),{projectId:V,emailId:q,blockId:$}=(0,o.g)(),j=(0,_.s9)(),{__:K}=j,{token:Z}=X(),{error:Q,notify:ee}=(0,w.hN)(),te=(0,a.wA)(),ie=(0,a.d4)(c.B$),re=(0,a.d4)(c.C1),ae=(0,a.d4)(u.cL),oe=(0,a.d4)(v.Ac),se=(0,a.d4)(f.yN),ne=(0,a.d4)(v.js),le=J(),[de,he]=(0,r.useState)(""),[ce,ue]=(0,r.useState)("my_files"),[ve,fe]=(0,r.useState)(!1),[me,pe]=(0,r.useState)(0),[we,ge]=(0,r.useState)(""),[Ie,ye]=(0,r.useState)(()=>[]),_e=()=>{te((0,u.Oo)()),setTimeout(()=>he(""),600)},Fe=!(ie||(null===(t=re.id)||void 0===t?void 0:t.toString())!==(null===se||void 0===se||null===(i=se.members)||void 0===i?void 0:i.owner.ID)),Pe=(0,r.useMemo)(()=>({img:ne,background:oe}),[ne,oe]);(0,r.useEffect)(()=>{ae.includes("UPLOAD_BACKGROUND_MODAL")?(he("background"),Pe.background&&ge(Pe.background)):ae.includes("UPLOAD_IMAGE_MODAL")&&(he("img"),Pe.img&&ge(Pe.img)),ae===k.lx.UPLOAD_IMAGE_MODAL||ae===k.lx.UPLOAD_BACKGROUND_MODAL?ue("editor"):ae===k.lx.UPLOAD_IMAGE_MODAL_AI||ae===k.lx.UPLOAD_BACKGROUND_MODAL_AI?Fe?(fe(!0),pe(2)):ue("ai"):ae===k.lx.UPLOAD_IMAGE_MODAL_UPLOAD||ae===k.lx.UPLOAD_BACKGROUND_MODAL_UPLOAD?ue("my_files"):ae===k.lx.UPLOAD_IMAGE_MODAL_STOCK||ae===k.lx.UPLOAD_BACKGROUND_MODAL_STOCK?Fe?(fe(!0),pe(3)):ue("stock_images"):ae===k.lx.UPLOAD_IMAGE_MODAL_GIF||ae===k.lx.UPLOAD_BACKGROUND_MODAL_GIF?Fe?(fe(!0),pe(3)):ue("gif"):ae===k.lx.UPLOAD_IMAGE_MODAL_EDIT||ae===k.lx.UPLOAD_BACKGROUND_MODAL_EDIT?(Fe?(fe(!0),pe(5)):ue("editor"),te((0,u.Wz)(k.lx.IMAGE_EDITOR_MODAL))):ue("my_files")},[ae,te,Fe,Pe]);const Ce=!Fe&&!!ce&&(ae.includes("UPLOAD_IMAGE_")||ae.includes("UPLOAD_BACKGROUND_"));(0,r.useEffect)(()=>{const e=document.querySelector("#carrotquest-messenger-collapsed-container");e&&(e.style.display=Ce?"none":"")},[Ce]);const Ae=(0,r.useMemo)(()=>e?e.pathMode?new G(e,e.rootId,"Trash",e.trashPath,!0,j):null:(Q(K("Error when initializing file manager")),null),[e,Q,j]),be=(0,r.useMemo)(()=>new x(null!==Ae&&void 0!==Ae?Ae:e,z.fileManager,{...e,trashPath:e.pathMode?"trash":e.trashPath,rootId:e.pathMode?"":e.rootId},j),[e,Ae,z.fileManager,j]),Ee=(0,r.useCallback)(e=>{const t=(0,L.e0)(e,be,Ae);return ee(t,!0)},[be,Ae,ee]),Me=(0,g.ml)(F.AZ.FILE_PROXY_EVENT_ID),Se=(0,H.p)(),Te=(0,a.Pj)(),Oe=(0,r.useCallback)(async e=>{const t=await Me.fire({url:e,project:V});let i=await t.find(e=>e);if(!i)try{{const t=new URL(e),i="https://px0.racs.rest".replace(/\/$/,""),r=new URLSearchParams(t.searchParams);r.set("proxy_url",t.origin),e=`${i}/${t.pathname.replace(/^\//,"")}?${r}${t.hash}`}const t=await fetch(e);i=await t.blob()}catch(r){return null}return i},[Me,V,Se,Te]),Ne=r.createElement(d.A,{style:{fontSize:32,margin:-16},spin:!0}),De=(0,r.useCallback)(e=>{I.isEqual(e,Ie)||ye(e)},[Ie]),[Ue]=(0,h.Mv)(),xe=(0,r.useCallback)(async()=>{if(be){const e=Ie[0];if(e){const t=e.url||e.thumbnailUrl||e.thumbnail;"img"===de?te((0,v.tm)(t)):"background"===de&&te((0,v.e_)(t))}}_e()},[be,te,u.Oo,Ie,de]),Be=(0,r.useCallback)(async e=>{let t=e.url||e.thumbnailUrl||e.thumbnail;!t&&be&&(t=await be.getFileUrl(e.folderId,e.name)),t&&("img"===de?te((0,v.tm)(t)):"background"===de&&te((0,v.e_)(t))),_e()},[be,te,u.Oo,de]),Re=(0,r.useCallback)(async()=>{_e()},[te,u.Oo]),[ke,{data:ze=[]}]=(0,h.gg)(),Ge=(null===z||void 0===z?void 0:z.handleLimitUsageEmitter)||(0,g.ml)(F.AZ.ON_LIMIT_ID),Le=(0,r.useCallback)(async function(e){try{await ke(e).unwrap()}catch(t){}},[ke]),Ve=(0,r.useMemo)(()=>{const e=(null===z||void 0===z?void 0:z.icons)||{};if(e&&0!==Object.keys(e).length)return(0,L.Rt)(e)},[null===z||void 0===z?void 0:z.icons]),qe=(0,r.useCallback)(async(e,t={})=>await le(e,t),[le]),$e=(0,g.ml)(F.AZ.PROXY_URL_EVENT_ID),je=(0,r.useCallback)(async e=>(await $e.fire({url:e,project:V})).findLast(t=>t&&t!==e)||(0,L.W5)(e),[$e,V]);return de&&be?r.createElement(r.Fragment,null,!Fe&&r.createElement(n.A,{className:"file-manager",closable:!0,footer:null,open:Ce,width:"100vw",onOk:xe,onCancel:_e},r.createElement(l.A,{spinning:!be,indicator:Ne},be&&("editor"===ce?r.createElement(W,{onSave:Be,onClose:Re,dataProviders:be,handleFileProxy:Oe,theme:re.theme,file:we,handleNotify:Ee,assetsUrl:(0,L.Zq)("","static/media/image-editor"),locale:re.locale.split("-")[0].split("_")[0]}):r.createElement(Y,{dataProviders:be,onChangeSelection:De,onEditorOk:Be,handleNotify:Ee,customIcons:Ve,config:{assetsUrl:(0,L.Zq)("","static/media/image-editor"),onClose:_e,handleProxyUrl:je,handleFileProxy:Oe,expandRootFolderOnInit:!1!==(null===(s=z.fileManager)||void 0===s?void 0:s.expandRootFolderOnInit),activeLibraryItem:ce,REACT_APP_GIPHY_KEY:"Nh77eBlPeMn1ed9MBAvL542NUGeNO26F",UNSPLASH_KEY:"S5iNcLqYgRBIOLQdluHdTsCJnjCvahzhG7JfYQOrV7o",APP_NAME_UNSPLASH:"Nh77eBlPeMn1ed9MBAvL542NUGeNO26F",UNSLASH_PROXY_URL:"https://api.emailmaker.ru/services/agent",STREAMLINE_API_KEY:{}.REACT_APP_STREAMLINE_API_KEY,fileForEdit:we,projectId:V,elementId:q||$,pushToGTM:null===z||void 0===z?void 0:z.pushToGTM,handleLimitUsageEmitter:Ge,sseQuery:Le,messages:ze,sendAIImageRequest:(null===z||void 0===z?void 0:z.sendAIImageRequest)||Ue,locale:re.locale.split("-")[0].split("_")[0],theme:re.theme,customTheme:Z,enableTrashFolder:null===(y=z.fileManager)||void 0===y?void 0:y.enableTrash,showNotifications:null===(P=z.fileManager)||void 0===P?void 0:P.showNotifications,handleTranslate:qe,features:{enableRenameFile:!1!==(null===(C=z.fileManager)||void 0===C?void 0:C.enableRenameFile),enableRenameFolder:!1!==(null===(A=z.fileManager)||void 0===A?void 0:A.enableRenameFolder),enableUpdateFile:!1!==(null===(b=z.fileManager)||void 0===b?void 0:b.enableUpdateFile),enableCopyItem:!1!==(null===(E=z.fileManager)||void 0===E?void 0:E.enableCopyFile),enableCopyFolder:!1!==(null===(M=z.fileManager)||void 0===M?void 0:M.enableCopyFolder),enableDelete:!1!==(null===(S=z.fileManager)||void 0===S?void 0:S.enableDelete),enableEdit:!1!==(null===(T=z.fileManager)||void 0===T?void 0:T.enableEdit),enableMoveItem:!1!==(null===(O=z.fileManager)||void 0===O?void 0:O.enableMoveFile),enableMoveFolder:!1!==(null===(N=z.fileManager)||void 0===N?void 0:N.enableMoveFolder)},disablePagination:!1===(null===(D=z.fileManager)||void 0===D?void 0:D.enablePagination),multiSelect:!1!==(null===(U=z.fileManager)||void 0===U?void 0:U.multiSelect),defaultFolderName:null===(B=z.fileManager)||void 0===B?void 0:B.defaultFolderName,availableImageExtensions:null===(R=z.fileManager)||void 0===R?void 0:R.availableImageExtensions}})))),r.createElement(m.A,{open:ve,onCancel:()=>fe(!1),initialSlide:me,sideOnOk:void 0})):null}}}]);
2
+ //# sourceMappingURL=5102.35699661.js.map