@emailmaker/emailmaker 1.0.109-alpha.2 → 1.0.109-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/README.md +2 -1
- package/asset-manifest.json +38 -36
- package/emailmaker-esm.js +1 -1
- package/emailmaker.d.ts +44 -1
- package/emailmaker.js +1 -1
- package/iframe/429.js +1 -1
- package/iframe/766.js +1 -1
- package/iframe/iframe-eblock.5f136dbd88b4aff20a4e.html +1 -0
- package/iframe/iframe.5f136dbd88b4aff20a4e.html +1 -0
- package/iframe/index.html +1 -1
- package/iframe/js/174.01401b47.js +1 -0
- package/iframe/js/525.e3d8308f.js +1 -0
- package/iframe/js/882.86c95d1e.js +1 -0
- package/iframe/sandbox-eblock.js +1 -1
- package/package.json +1 -1
- package/static/css/5102.cbdb59ca.chunk.css +2 -0
- package/static/css/{7282.739c0d6e.chunk.css → 7282.d5d7c046.chunk.css} +2 -2
- package/static/css/{main.3086b5d9.css → main.6b7ac1ef.css} +2 -2
- package/static/js/{1902.96d10b03.js → 1902.84af6230.js} +2 -2
- package/static/js/{9162.27f21a26.js → 2076.fa333dc2.js} +3 -3
- package/static/js/3628.25c1fb89.js +3 -0
- package/static/js/4298.df6cac3c.js +3 -0
- package/static/js/5102.eac304ab.js +2 -0
- package/static/js/5279.8904b618.js +2 -0
- package/static/js/{7282.0e0350e2.js → 7282.cf67c3fd.js} +3 -3
- package/static/js/8559.652fb850.js +2 -0
- package/static/js/8778.f3616411.js +2 -0
- package/static/js/{emailmaker_core.23ddf597.js → emailmaker_core.c2b562af.js} +3 -3
- package/iframe/iframe-eblock.fecd609b7217947f3d0a.html +0 -1
- package/iframe/iframe.fecd609b7217947f3d0a.html +0 -1
- package/iframe/js/174.d4af3f31.js +0 -1
- package/iframe/js/525.7b9b34e7.js +0 -1
- package/iframe/js/882.cbc0a3a7.js +0 -1
- package/static/css/5102.6eeeac5b.chunk.css +0 -2
- package/static/js/3628.e132c341.js +0 -3
- package/static/js/5102.af181f78.js +0 -2
- package/static/js/7126.139f5415.js +0 -3
- package/static/js/8017.2b02b271.js +0 -2
- package/static/js/8559.c810e5fe.js +0 -2
- package/static/js/8778.52a5c71c.js +0 -2
- /package/iframe/js/{174.d4af3f31.js.LICENSE.txt → 174.01401b47.js.LICENSE.txt} +0 -0
- /package/iframe/js/{525.7b9b34e7.js.LICENSE.txt → 525.e3d8308f.js.LICENSE.txt} +0 -0
- /package/iframe/js/{882.cbc0a3a7.js.LICENSE.txt → 882.86c95d1e.js.LICENSE.txt} +0 -0
- /package/static/js/{9162.27f21a26.js.LICENSE.txt → 2076.fa333dc2.js.LICENSE.txt} +0 -0
- /package/static/js/{3628.e132c341.js.LICENSE.txt → 3628.25c1fb89.js.LICENSE.txt} +0 -0
- /package/static/js/{7126.139f5415.js.LICENSE.txt → 4298.df6cac3c.js.LICENSE.txt} +0 -0
- /package/static/js/{7282.0e0350e2.js.LICENSE.txt → 7282.cf67c3fd.js.LICENSE.txt} +0 -0
- /package/static/js/{emailmaker_core.23ddf597.js.LICENSE.txt → emailmaker_core.c2b562af.js.LICENSE.txt} +0 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";(globalThis.webpackChunkemail_maker=globalThis.webpackChunkemail_maker||[]).push([[5102],{16160:(e,t,i)=>{i.r(t),i.d(t,{default:()=>te});var r=i(1936),o=i(71715),a=i(84075),n=i(18021),s=i(51114),l=i(6691),d=i(86331),h=i(60034),c=i(98173),u=i(78443),v=i(22817),f=i(81644),p=i(942),m=i(6403),w=i(65185);let g;var y;(y=g||(g={})).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 o=0;o<r;o++)if(!i(e[o],t[o]))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),o=!i.has(r);return i.add(r),o})};var I=i(47706),_=i(65893),F=i(93628),C=i(93506),P=(i(80708),i(10968)),b=i(2783);class A{constructor(e,t="",i="Trash",r="Trash",o=!0,a=I.nr){this._inner=e,this.rootPath=t,this.trashId=i,this.trashPath=r,this.ensureFolderTrailingSlash=o,this.i18n=a,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,"function"===typeof e.getUrl&&(this.getUrl=t=>e.getUrl({...t,id:this.pathForId(t.id,!1),folderId:t.folderId?this.pathForId(t.folderId,!0):this.rootPath})),"function"===typeof e.getThumbnailUrl&&(this.getThumbnailUrl=t=>e.getThumbnailUrl({...t,id:this.pathForId(t.id,!1),folderId:t.folderId?this.pathForId(t.folderId,!0):this.rootPath})),"function"!==typeof this._inner.deleteItems&&(this.deleteItems=void 0),"function"!==typeof this._inner.deleteItem&&(this.deleteItem=void 0),"function"!==typeof this._inner.moveItems?this.moveItems=void 0:this.moveItem=void 0,"function"!==typeof this._inner.copyItems?this.copyItems=void 0:this.copyItem=void 0,"function"!==typeof this._inner.uploadFiles?this.uploadFiles=void 0:this.uploadFile=void 0,"function"!==typeof this._inner.clearCache&&(this.clearCache=void 0),this._getOrGenerateId(this.rootPath)}setController(e){"function"===typeof this._inner.setController&&this._inner.setController({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("function"===typeof 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,P.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 o=this._idToPath.get(e);if(!o){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 b.FileManagerApiError(t,"FileNotFound")}}let a=0;for(;a<this.rootPath.length&&"/"===this.rootPath[a];)a++;if(a){let e=0;for(;e<o.length&&"/"===o[e];)e++;const t=o.slice(e);o="/".repeat(a)+t}return t&&this.ensureFolderTrailingSlash&&!o.endsWith("/")&&(o+="/"),o}_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,o=await this._inner.createFolder(e,r,i),a=this._getOrGenerateId(o.id),n=o.folderId?this._getOrGenerateId(o.folderId):this._getOrGenerateId(this.rootPath);return{...o,id:a,folderId:n}}async renameItem(e,t){const{__:i}=this.i18n;if("function"!==typeof 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 b.FileManagerApiError(e,"RenameNotAllowed")}const r=this.pathForId(e.id,e.isFolder),o=r;let{...a}=await this._inner.renameItem({...e,id:r,folderId:this.pathForId(e.folderId,!0)},t);return this._updateIdMapping(e.id,a.id),e.isFolder&&this.remapCachedFolderContents(e.id,o,a.id),a.folderId&&(a={...a,folderId:this._getOrGenerateId(a.folderId)}),{...a,id:this._getOrGenerateId(a.id)}}async deleteItem(e,t){const{__:i}=this.i18n;if("function"!==typeof this._inner.deleteItem){const e=i?i("Delete item is not supported by inner storage"):"Delete item is not supported by inner storage";throw new b.FileManagerApiError(e,"DeleteNotAllowed")}const r=this.pathForId(e.id,e.isFolder);await this._inner.deleteItem({...e,id:r,folderId:this.pathForId(e.folderId,!0)},t),this.recursivelyRemoveMappings(e.id,r)}async uploadFile(e){const{__:t}=this.i18n;if("function"!==typeof this._inner.uploadFile){const e=t?t("Upload file is not supported by inner storage"):"Upload file is not supported by inner storage";throw new b.FileManagerApiError(e,"UnsupportedOperation")}const i=e.folderId?this.pathForId(e.folderId,!0):this.rootPath,r=await this._inner.uploadFile({...e,folderId:i}),o=this._getOrGenerateId(r.id),a=r.folderId?this._getOrGenerateId(r.folderId):this._getOrGenerateId(this.rootPath);return{...r,id:o,folderId:a}}async uploadFiles(e){var t,i,r,o,a;const n=e.folderId,s=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===(o=e.items)||void 0===o?void 0:o.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===(a=h.detailed)||void 0===a?void 0:a.map((e,t)=>{var i,r;if(null===e||void 0===e||!e.data)return e;const o=e.data.id?this._getOrGenerateId(e.data.id):void 0,a=e.data.folderId?this._getOrGenerateId(e.data.folderId):null!==(i=null!==(r=s[t])&&void 0!==r?r:n)&&void 0!==i?i:this._getOrGenerateId(this.rootPath);return{...e,data:{...e.data,id:o,folderId:a}}})}}async findFileByUrl(e,t){const i=t?this.pathForId(t,!0):this.rootPath;if("function"===typeof this._inner.findFileByUrl){const t=await this._inner.findFileByUrl(e,i);if(!t)return;const r=this._getOrGenerateId(t.id),o=t.folderId?this._getOrGenerateId(t.folderId):this._getOrGenerateId(this.rootPath);return{...t,id:r,folderId:o}}}async uploadFileByUrl(e,t,i){const r=t?this.pathForId(t,!0):this.rootPath,o=await this._inner.uploadFileByUrl(e,r,i),a=this._getOrGenerateId(o.id),n=o.folderId?this._getOrGenerateId(o.folderId):this._getOrGenerateId(this.rootPath);return{...o,id:a,folderId:n}}async moveItem(e,t){const{__:i}=this.i18n;if("function"!==typeof this._inner.moveItem){const e=i?i("Move item is not supported by inner storage"):"Move item is not supported by inner storage";throw new b.FileManagerApiError(e,"MoveNotAllowed")}const r=this.pathForId(e.id,e.isFolder),o=this.pathForId(t,!0),a=await this._inner.moveItem({...e,id:r,folderId:this.pathForId(e.folderId,!0)},o);this._updateIdMapping(e.id,a.id),e.isFolder&&this.remapCachedFolderContents(e.id,r,a.id);const n=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):t;return{...a,id:n,folderId:s}}async moveItems(e,t){const{__:i}=this.i18n;if("function"!==typeof 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 b.FileManagerApiError(e,"MoveNotAllowed")}const r=t?this.pathForId(t,!0):this.rootPath,o=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.moveItems(o,r),n=[];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 o of e){const s=r.get(o.id)||(a.detailed.length===e.length?a.detailed[e.indexOf(o)]:void 0);if(null!==s&&void 0!==s&&s.success&&s.data){if(this._updateIdMapping(o.id,s.data.id),o.isFolder){const e=this.pathForId(o.id,o.isFolder);this.remapCachedFolderContents(o.id,e,s.data.id)}n.push({requestId:o.id,success:!0,data:{...s.data,id:this._getOrGenerateId(s.data.id),folderId:s.data.folderId?this._getOrGenerateId(s.data.folderId):t||this._getOrGenerateId(this.rootPath)}})}else{const e=i?i("Move operation failed - no detailed result"):"Move operation failed - no detailed result";n.push({requestId:o.id,success:!1,error:(null===s||void 0===s?void 0:s.error)||{message:e,code:"MoveNotAllowed"}})}}}else for(const s of e){const e=i?i("Move operation failed - no detailed results"):"Move operation failed - no detailed results";n.push({requestId:s.id,success:!1,error:{message:e,code:"MoveNotAllowed"}})}return{success:a.success,detailed:n,error:a.error}}async copyItems(e,t){const{__:i}=this.i18n;if("function"!==typeof 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 b.FileManagerApiError(e,"CopyNotAllowed")}const r=t?this.pathForId(t,!0):this.rootPath,o=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.copyItems(o,r),n=[];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 o of e){var s;const l=r.get(o.id)||(a.detailed.length===e.length?a.detailed[e.indexOf(o)]:void 0);if(null!==l&&void 0!==l&&l.success&&null!==(s=l.data)&&void 0!==s&&s.id){const e=this._getOrGenerateId(l.data.id);n.push({requestId:o.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"};n.push({requestId:o.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";n.push({requestId:h.id,success:!1,error:{message:e,code:"CopyNotAllowed"}})}const l=n.every(e=>e.success),d=i?i("Copy operation completed with errors"):"Copy operation completed with errors";return{success:l,detailed:n,error:l?void 0:a.error||{message:d,code:"CopyNotAllowed"}}}async deleteItems(e,t){const{__:i}=this.i18n;if("function"!==typeof 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 b.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})),o=await this._inner.deleteItems(r,t),a=[];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 n of e){const s=r.get(n.id)||(o.detailed.length===e.length?o.detailed[e.indexOf(n)]:void 0);if(null!==s&&void 0!==s&&s.success){const e=this.pathForId(n.id,n.isFolder);if(t.permanent)this.recursivelyRemoveMappings(n.id,e);else if(this._updateIdMapping(n.id,this.trashPath+"/"+e+(n.isFolder?"/":"")),n.isFolder){const t=this.pathForId(n.id,n.isFolder);this.remapCachedFolderContents(n.id,t,this.trashPath+"/"+e+(n.isFolder?"/":""))}a.push({requestId:n.id,success:!0})}else{const e=i?i("Delete operation failed"):"Delete operation failed";a.push({requestId:n.id,success:!1,error:(null===s||void 0===s?void 0:s.error)||{message:e,code:"DeleteNotAllowed"}})}}}else for(const l of e)if(o.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?"/":""))}a.push({requestId:l.id,success:!0})}else{const e=i?i("Delete operation failed"):"Delete operation failed";a.push({requestId:l.id,success:!1,error:o.error||{message:e,code:"DeleteNotAllowed"}})}const n=a.every(e=>e.success),s=i?i("Some items failed to delete"):"Some items failed to delete";return{success:n,detailed:a,error:n?void 0:o.error||{message:s,code:"DeleteNotAllowed"}}}remapCachedFolderContents(e,t,i){const r=t.replace(/\/+$/,""),o=i.replace(/\/+$/,""),a=[];for(const[n,s]of this._idToPath.entries()){const e=s.replace(/\/+$/,"");e!==r&&e.startsWith(r+"/")&&a.push({id:n,oldPath:e})}for(const{id:n,oldPath:s}of a){const e=o+s.substring(r.length);this._updateIdMapping(n,e)}}recursivelyRemoveMappings(e,t){const i=t.replace(/\/+$/,""),r=[],o=[];for(const[a,n]of this._idToPath.entries()){const e=n.replace(/\/+$/,"");(e===i||e.startsWith(i+"/"))&&(r.push(a),o.push(e))}for(let a=0;a<r.length;a++)this._idToPath.delete(r[a]),this._pathToId.delete(o[a])}async copyItem(e,t){const{__:i}=this.i18n;if("function"!==typeof this._inner.copyItem){const e=i?i("Copy item is not supported by inner storage"):"Copy item is not supported by inner storage";throw new b.FileManagerApiError(e,"CopyNotAllowed")}const r=this.pathForId(e.id,e.isFolder),o=this.pathForId(t,!0),a=await this._inner.copyItem({...e,id:r,folderId:this.pathForId(e.folderId,!0)},o),n=this._getOrGenerateId(a.id),s=a.folderId?this._getOrGenerateId(a.folderId):t;return{...a,id:n,folderId:s}}async updateFile(e,t){const{__:i}=this.i18n;if("function"!==typeof 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 b.FileManagerApiError(e,"UnsupportedOperation")}const r=this.pathForId(e.id,!1);let{...o}=await this._inner.updateFile({...e,id:r,folderId:this.pathForId(e.folderId,!0)},t);return this._updateIdMapping(e.id,o.id),o.folderId&&(o={...o,folderId:this._getOrGenerateId(o.folderId)}),{...o,id:this._getOrGenerateId(o.id)}}async getFileData(e,t){const{__:i}=this.i18n,r=this.pathForId(e.id,!1);if("function"===typeof this._inner.getFileData)return this._inner.getFileData({...e,id:r,folderId:this.pathForId(e.folderId,!0)},t);const o=e.url||("function"===typeof this.getUrl?await this.getUrl(e):void 0);if(!o){const e=i?i("Cannot get file data: no url and no inner.getFileData"):"Cannot get file data: no url and no inner.getFileData";throw new b.FileManagerApiError(e,"FileReadError")}return fetch(o,null!==t&&void 0!==t&&t.forceReload?{cache:"no-store"}:void 0).then(e=>e.blob())}async cleanTrash(){const{__:e}=this.i18n;if("function"!==typeof 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 b.FileManagerApiError(t,"UnsupportedOperation")}return await this._inner.cleanTrash()}}function E(e){return null==e||""===e?"":e}function M(e){if(null==e)return 1/0;const t=Number(e);return Number.isFinite(t)&&t>=0?t:1/0}function S(e){if(!e)return null;const t=e.folderId;return null==t?null:String(t)}function T(e){return!!e&&e.isFolder}function O(){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 N(e){if(!e||"object"!==typeof e)return String(null!==e&&void 0!==e?e:"");const t=e,i=[],r={},o=["page","pageSize","sortBy","sortOrder","search","itemType","limit"];for(const l of Object.keys(t).sort()){const e=t[l];o.includes(l)?i.push(`${l}=${String(null!==e&&void 0!==e?e:"")}`):r[l]=e}const a=Object.keys(r).length?JSON.stringify(r):"",n=i.join("|"),s=a?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)}(a):"";return`${n}${s?`|${s}`:""}`}class U{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&&!T(t)?t:void 0}getFolder(e){const t=this.getEntity(e);return t&&T(t)?t:void 0}getChildrenIds(e,t={}){const i=E(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,o=r?S(r):null,a=S(e),n=!!r&&T(r),s=T(e);let l;if(r&&T(r)&&s){const t=r.childrenCount,i=e.childrenCount;void 0!==t&&void 0===i&&(l=t)}if(r&&(o!==a||n!==s)){const t=E(o),i=this.childrenByParent.get(t);i&&(n?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=E(a);let c=this.childrenByParent.get(h);c||(c={files:new Set,folders:new Set},this.childrenByParent.set(h,c)),s?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||!T(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,o=S(r),a=E(o),n=this.childrenByParent.get(a);return n&&(T(r)?n.folders.delete(e):n.files.delete(e),0===n.files.size&&0===n.folders.size&&this.childrenByParent.delete(a)),this.entities.delete(e),{entity:{...r},parentId:o}}deleteFolderRecursive(e){const t=this.entities.get(e);if(!t||!T(t.value))return{deletedFolderRecords:[],deletedFileSystemItemRecords:[]};const i=[{id:e,parentId:S(t.value)}],r=[],o=[];for(;i.length;){const e=i.shift();r.push(e);const t=this.childrenByParent.get(E(e.id));if(t){for(const e of Array.from(t.folders)){const t=this.entities.get(e);t&&i.push({id:e,parentId:S(t.value)})}for(const e of Array.from(t.files))o.push(e)}}const a=[];for(const s of o){const e=this.entities.get(s);if(!e)continue;const t=e.value,i=E(S(t)),r=this.childrenByParent.get(i);r&&(r.files.delete(s),0===r.files.size&&0===r.folders.size&&this.childrenByParent.delete(i)),this.entities.delete(s),a.push({...t})}const n=[];for(let s=r.length-1;s>=0;s--){const{id:e,parentId:t}=r[s],i=this.entities.get(e);if(!i)continue;const o=i.value,a=E(o.id);this.childrenByParent.delete(a);const l=E(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),n.push({...o})}return{deletedFolderRecords:n,deletedFileSystemItemRecords:a}}moveEntityById(e,t){var i;const r=null!==(i=this.entities.get(e))&&void 0!==i?i:null;if(!r)return null;const o=r.value,a=E(S(o)),n=this.childrenByParent.get(a);n&&(T(o)?n.folders.delete(e):n.files.delete(e),0===n.files.size&&0===n.folders.size&&this.childrenByParent.delete(a));const s={...o,folderId:t};if(T(o)&&T(s)){const e=o.childrenCount;void 0!==e&&(s.childrenCount=e)}this.entities.set(e,{value:s,updatedAt:this.now()});const l=E(t);let d=this.childrenByParent.get(l);return d||(d={files:new Set,folders:new Set},this.childrenByParent.set(l,d)),T(s)?d.folders.add(e):d.files.add(e),{...s}}copyFileSystemItem(e,t,i){var r;const o=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!o||T(o.value))return null;const a={...o.value,id:t,folderId:i};return this.upsertEntity(a),{...a}}copyFolderShallow(e,t,i){var r;const o=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!o||!T(o.value))return null;const a={...o.value,id:t,folderId:i};return this.upsertEntity(a),{...a}}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,o,a;if(!e||""===e.trim())return[];const n=null===t||void 0===t?void 0:t.parentId,s=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!==(o=null===t||void 0===t?void 0:t.caseSensitive)&&void 0!==o&&o,h=null!==(a=null===t||void 0===t?void 0:t.limit)&&void 0!==a?a:1/0,c=d?e.trim():e.trim().toLowerCase(),u=[];let v=null;if(void 0!==n){v=new Set;const e=E(n);if(v.add(e),s){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[,p]of this.entities){var f;if(u.length>=h)break;const e=p.value;if(null!==v){const t=E(S(e));if(!v.has(t))continue}if("file"===l&&T(e))continue;if("folder"===l&&!T(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 U;for(const[o,a]of null!==(i=e.entities)&&void 0!==i?i:[]){var i;t.entities.set(o,{value:a.value,updatedAt:a.updatedAt})}for(const[o,a]of null!==(r=e.childrenByParent)&&void 0!==r?r:[]){var r;t.childrenByParent.set(o,{files:new Set(a.files),folders:new Set(a.folders)})}return t}}class D{constructor(e={},t=3e5,i=3e4,r){var o,a,n,s,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===(o=e.allowSortedInsert)||void 0===o||o,allowSearchInsert:null===(a=e.allowSearchInsert)||void 0===a||a,invalidateOnPaginationFull:null===(n=e.invalidateOnPaginationFull)||void 0===n||n,preloadPagesBefore:null!==(s=e.preloadPagesBefore)&&void 0!==s?s: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 E(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&&!T(e)||!("folder"!==t||!T(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 o;const a=this.parentKey(e),n=N(null!==t&&void 0!==t?t:{});let s=this.views.get(a);s||(s=new Map,this.views.set(a,s));let l=s.get(n);if(!l){l={params:t,view:{promise:null,value:void 0,meta:void 0,error:void 0,updatedAt:0,loadId:null}},s.set(n,l),this.cleanupOldViews(s)}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===(o=l.view.meta)||void 0===o||!o.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=O();l.view.loadId=c;const u=(async()=>{try{var o,n,s;const h=await i(e,t),u=function(e){return!!e&&"string"===typeof e.search&&e.search.trim().length>0}(t),v=u?{...h,total:void 0}:h,f=null===(o=this.views.get(a))||void 0===o?void 0:o.get(N(t));if(!f||f.view.loadId!==c){const e=new Error("StaleLoad");throw e.name="StaleLoad",e}for(const e of v.items)r.upsertEntity(e);l.view.value=v.items.map(e=>e.id);const{items:p,...m}=v,w={...m};l.view.meta=w,l.view.meta.stale=!1,l.view.error=null,l.view.updatedAt=this.now(),u||"number"!==typeof w.total||(this.serverChildrenCountHandler?this.serverChildrenCountHandler(null!==e&&void 0!==e?e:null,w.total,r):r.updateServerChildrenCount(e,w.total));const g=null!==(n=this.strategy.preloadPagesAfter)&&void 0!==n?n:0,y=null!==(s=this.strategy.preloadPagesBefore)&&void 0!==s?s:0,I=M(null===t||void 0===t?void 0:t.pageSize),_=Number.isFinite(I);if((g>0||y>0)&&_){var d;const o=e,a={...t},n="number"===typeof w.totalPages?w.totalPages:1,s=null!==(d=null===t||void 0===t?void 0:t.page)&&void 0!==d?d:1,l=I,h=i,u=c;setTimeout(()=>{this.preloadPagesAsync(o,a,s,n,l,g,y,r,w,h,u)},0)}return v}catch(p){var h,u,v,f;if("StaleLoad"===(null===p||void 0===p?void 0:p.name))throw l.view.error=null,l.view.value=void 0,l.view.updatedAt=this.now(),p;const e=p,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=p,l.view.value=void 0,l.view.updatedAt=this.now(),p}finally{l.view.promise=null}})();return l.view.promise=u,u}async preloadPagesAsync(e,t,i,r,o,a,n,s,l,d,h){try{const o=this.parentKey(e),l=this.views.get(o);if(!l)return;const c=l.get(N(t));if(!c)return;if(null!=h&&c.view.loadId!==h)return;const u=l.get(N(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 a=await d(e,r),n=this.views.get(o);if(!n)return;const l=n.get(N(t));if(!l)return;if(null!=h&&l.view.loadId!==h)return;if(l.view.loadId!==h)return;for(const e of a.items)s.upsertEntity(e);const c=N(r);let u=n.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}},n.set(c,u),this.cleanupOldViews(n)}if(!u.view.value||this.isExpired(u.view.updatedAt)){u.view.value=a.items.map(e=>e.id);const{items:e,...t}=a;u.view.meta={...t,page:i,totalPages:v},u.view.updatedAt=this.now()}}catch(a){}};if(a>0&&i<v)for(let e=1;e<=Math.min(a,v-i);e++){const r=i+e,o=N({...t,page:r}),a=l.get(o);null!==a&&void 0!==a&&a.view.value&&!this.isExpired(a.view.updatedAt)||f(r)}if(n>0&&i>1)for(let e=1;e<=Math.min(n,i-1);e++){const r=i-e,o=N({...t,page:r}),a=l.get(o);null!==a&&void 0!==a&&a.view.value&&!this.isExpired(a.view.updatedAt)||f(r)}}catch(c){}}removeEmptyPageIfNeeded(e,t,i,r,o){if(t.view.value&&0===t.view.value.length&&i<r){const t=N({...o,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 o=0;o<i.length;o++){const a=i[o];if(a!==r[o])return!1;if(e[a]!==t[a])return!1}return!0}syncTotalsInSameViews(e,t){var i;const r=t.view.meta;if(!r||"number"!==typeof r.total)return;const o=Number(r.total),a=M(null===(i=t.params)||void 0===i?void 0:i.pageSize),n=Number.isFinite(a)&&a>0?Math.max(1,Math.ceil(o/a)):void 0;for(const[,d]of e){var s,l;this.isParamsSame(null!==(s=d.params)&&void 0!==s?s:{},null!==(l=t.params)&&void 0!==l?l:{})&&(d.view.meta||(d.view.meta={}),d.view.meta.total=o,void 0!==n&&(d.view.meta.totalPages=n))}}canSafelyModifySortedView(e){return!e.sortBy&&!e.sortOrder||!!this.strategy.comparator}cascadeShiftPages(e,t,i,r,o,a,n){let s=t,l=i,d=!1;let h=0;for(;s.view.value&&s.view.value.length<r&&l<o&&h<100;){h++;const t=N({...n,page:l+1}),i=e.get(t);if(null===i||void 0===i||!i.view.value||this.isExpired(i.view.updatedAt)){var c;s.view.meta={...null!==(c=s.view.meta)&&void 0!==c?c:{},stale:!0};break}const o=r-s.view.value.length,v=i.view.value.slice(0,o).filter(e=>a.getEntity(e));if(0===v.length){var u;s.view.meta={...null!==(u=s.view.meta)&&void 0!==u?u:{},stale:!0};break}if(s.view.value=[...s.view.value,...v],s.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=N({...n,page:t});e.delete(i),d=!0}break}s=i,l++}var v;(!s.view.value||s.view.value.length<r)&&l>=o&&(s.view.meta={...null!==(v=s.view.meta)&&void 0!==v?v:{},stale:!0});return d}cascadeShiftToNextPage(e,t,i,r,o,a,n){var s,l;if(!t.view.value||t.view.value.length<=r)return!1;var d;if(i-(n.page||1)>=10)return t.view.meta={...null!==(d=t.view.meta)&&void 0!==d?d:{},stale:!0},!1;const h={...n,page:i+1},c=N(h);let u=e.get(c),v=!1;if(null===(s=u)||void 0===s||!s.view.value||this.isExpired(u.view.updatedAt)){var f;if(!(i>=o))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 p=t.view.value.slice(r).filter(e=>a.getEntity(e));if(0===p.length)return v&&e.delete(c),!1;t.view.value=t.view.value.slice(0,r),t.view.updatedAt=Date.now(),u.view.value=[...p,...null!==(l=u.view.value)&&void 0!==l?l:[]],u.view.updatedAt=Date.now();const m=u.view.meta&&"number"===typeof u.view.meta.totalPages?u.view.meta.totalPages:o;if(!v){if(this.cascadeShiftToNextPage(e,u,i+1,r,m,a,n))return!0}if(!u.view.value||0===u.view.value.length){const t=i+1,r=u.view.meta,o=r&&"number"===typeof r.totalPages?r.totalPages:1;this.removeEmptyPageIfNeeded(e,u,t,o,n)}return v}tryInsertSorted(e,t,i){var r;const o=this.strategy.comparator;if(!o)return!1;if(!e.view.value)return!1;const a=(null===(r=e.params)||void 0===r?void 0:r.itemType)||"all";if(!this.isEntityTypeCompatible(t,a))return!1;const n=e.view.value.map(e=>i.getEntity(e));if(n.some(e=>!e))return!1;let s=0,l=n.length;for(;s<l;){const i=Math.floor((s+l)/2),r=o(t,n[i],e.params);if("number"!==typeof r||Number.isNaN(r))return!1;r>=0?s=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,s),t.id,...e.view.value.slice(s)],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 o,a,n,s;const l=S(t);switch(e){case"delete":this.adjustChildrenCount(r,l,-1),null===(o=this.childrenCountInvalidator)||void 0===o||o.call(this,l);break;case"insert":case"copy":this.adjustChildrenCount(r,l,1),null===(a=this.childrenCountInvalidator)||void 0===a||a.call(this,l);break;case"move":this.adjustChildrenCount(r,i,-1),this.adjustChildrenCount(r,l,1),null===(n=this.childrenCountInvalidator)||void 0===n||n.call(this,i),null===(s=this.childrenCountInvalidator)||void 0===s||s.call(this,l)}}adjustChildrenCount(e,t,i){if(!t)return;const r=e.getFolder(t);if(r&&"number"===typeof r.childrenCount){const o=Math.max(0,r.childrenCount+i);e.updateServerChildrenCount(t,o)}}smartInvalidateChildrenViews(e,t,i,r,o,a){if(!t)return;this.updateChildrenCountForOperation(i,t,o,r);const n=this.parentKey(e),s=this.views.get(n);if(s)for(const[,u]of s){var l,d;const e=null!==(l=u.params)&&void 0!==l?l:{},a=null!==(d=null===e||void 0===e?void 0:e.page)&&void 0!==d?d:1,n=M(null===e||void 0===e?void 0:e.pageSize),v=Number.isFinite(n),f=!!(null!==e&&void 0!==e&&e.sortBy||null!==e&&void 0!==e&&e.sortOrder),p=!(null===e||void 0===e||!e.search),m=(null===e||void 0===e?void 0:e.itemType)||"all";if(!this.isEntityTypeCompatible(t,m))continue;if(p&&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=O(),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,a))u.view.meta={...null!==(c=u.view.meta)&&void 0!==c?c:{},stale:!0},u.view.loadId=O(),u.view.abortController&&(u.view.abortController.abort(),u.view.abortController=void 0);else switch(i){case"delete":this.handleDelete(s,u,a,n,v,t,r);break;case"insert":case"copy":this.handleInsert(s,u,a,n,v,f,t,r);break;case"update":this.handleUpdate(s,u,a,n,v,f,p,t,r);break;case"move":this.handleMove(s,u,a,n,v,f,t,o,r)}}}shouldInvalidateCompletely(e,t,i,r,o,a){return!(!(o&&a>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,o){var a,n;const s=(null===(a=e.params)||void 0===a?void 0:a.itemType)||"all";if(!this.isEntityTypeCompatible(t,s))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!==(n=e.params)&&void 0!==n?n:{};return!(!(!l.sortBy&&!l.sortOrder)&&!this.canSafelyModifySortedView(l))&&((!r||e.view.value.length<o)&&(e.view.value.push(t.id),!0))}handleDelete(e,t,i,r,o,a,n){const s=t.view.value.includes(a.id);if(s&&(t.view.value=t.view.value.filter(e=>e!==a.id)),t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total=Math.max(0,t.view.meta.total-1),o&&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(),s&&o&&t.view.value.length<r&&n){var l;const o=t.view.meta,a=o&&"number"===typeof o.totalPages?o.totalPages:1;if(this.cascadeShiftPages(e,t,i,r,a,n,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=O(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}handleInsert(e,t,i,r,o,a,n,s){if(!t.view.value.includes(n.id)){if(a&&this.strategy.allowSortedInsert&&this.strategy.comparator&&s){if(this.tryInsertSorted(t,n,s)&&t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total+=1,o&&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(o&&t.view.value.length>r&&s){var l;const o=t.view.meta,a=o&&"number"===typeof o.totalPages?o.totalPages:1;if(this.cascadeShiftToNextPage(e,t,i,r,a,s,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(!o||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,o&&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=O(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}}handleUpdate(e,t,i,r,o,a,n,s,l){var d;const h=t.view.value.includes(s.id),c=this.isEntityTypeCompatible(s,(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!==s.id),t.view.meta&&"number"===typeof t.view.meta.total&&(t.view.meta.total=Math.max(0,t.view.meta.total-1),o&&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(),o&&t.view.value.length<r&&l){var u;const o=t.view.meta,a=o&&"number"===typeof o.totalPages?o.totalPages:1;if(this.cascadeShiftPages(e,t,i,r,a,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=O(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0))}if(h&&(a||n)){t.view.value=t.view.value.filter(e=>e!==s.id);if(this.tryReinsertEntity(t,s,l,o,r)){if(t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total+=1,o&&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),o&&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(o&&t.view.value.length<r&&l){var v;const o=t.view.meta,a=o&&"number"===typeof o.totalPages?o.totalPages:1;if(this.cascadeShiftPages(e,t,i,r,a,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=O(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0))}if(h)return t.view.updatedAt=Date.now(),t.view.loadId=O(),void(t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0));if(c&&!n){if(a&&this.strategy.allowSortedInsert&&this.strategy.comparator&&l){if(this.tryInsertSorted(t,s,l)&&t.view.meta&&"number"===typeof t.view.meta.total){if(t.view.meta.total+=1,o&&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(!o||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,o&&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=O(),t.view.abortController&&(t.view.abortController.abort(),t.view.abortController=void 0)}}handleMove(e,t,i,r,o,a,n,s,l){if(t.view.value.includes(n.id)){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),o&&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(),o&&t.view.value.length<r&&l){var d;const o=t.view.meta,a=o&&"number"===typeof o.totalPages?o.totalPages:1;if(this.cascadeShiftPages(e,t,i,r,a,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=O(),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=O(),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[,n]of i){const e=n.view.meta;var o,a;if(e&&"number"===typeof e.total)if(!r||(null!==(o=n.view.updatedAt)&&void 0!==o?o:0)>r.updatedAt)r={total:Number(e.total),updatedAt:null!==(a=n.view.updatedAt)&&void 0!==a?a: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 D;for(const[r,o]of null!==(i=e.views)&&void 0!==i?i:[]){var i;const e=new Map;for(const[t,i]of o)e.set(t,i);t.views.set(r,e)}return t}}class x{invalidateChildrenCountCache(e){const t=E(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 U,this.views=new D(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?S(t):null,r=S(e),o=!!t&&T(t),a=T(e);if(this.entities.upsertEntity(e),t){if(i!==r||o!==a)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(E(i)===E(e))return!0;const t=this.entities.getEntity(i);if(!t)break;i=S(t),null===i&&(i="")}return!1}moveEntity(e,t){const i=this.entities.getEntity(e);if(!i)return null;if(T(i)&&null!==t&&this.isAncestor(e,t))return null;const r=S(i),o=this.entities.moveEntityById(e,t);return o?(this.views.smartInvalidateChildrenViews(r,i,"delete",this.entities),this.views.smartInvalidateChildrenViews(t,o,"insert",this.entities),o):null}copyEntity(e,t,i,r){const o=this.entities.getEntity(e);if(!o)return null;let a=null;if(T(o)){var n;const i=[e],o=[];for(;i.length;){const e=i.shift();o.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 o)d.set(e,O());for(const a of o){var s,l;const i=this.entities.getFolder(a),o=d.get(a),n=S(i),h=null===n?t:null!==(s=d.get(n))&&void 0!==s?s:null,c={...i,...a===e?r:void 0,id:o,folderId:null!==(l=a===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 o){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=O(),o={...i,id:r,folderId:t};this.entities.upsertEntity(o)}}a=null!==(n=this.entities.getEntity(d.get(e)))&&void 0!==n?n:null}else{const o=null!==i&&void 0!==i?i:O();if(a=this.entities.copyFileSystemItem(e,o,null!==t&&void 0!==t?t:null),a&&r){var d,h;const e={...a,...r,id:o,folderId:null!==(d=null!==(h=r.folderId)&&void 0!==h?h:t)&&void 0!==d?d:null};this.entities.upsertEntity(e),a=e}}return a&&this.views.smartInvalidateChildrenViews(t,a,"copy",this.entities),a}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(T(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(T(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=E(e),r=this.childrenCountPromises.get(i);if(r)return r;const o=(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 o=e;return"path_folder_not_found"===o.code||"path_folder_not_found"===(null===(t=o.data)||void 0===t?void 0:t.code)||404===o.status||404===(null===(i=o.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,o),o}toJSON(){return{entities:this.entities.toJSON(),views:this.views.toJSON(),ttl:this.ttl,errorTtl:this.errorTtl}}static fromJSON(e,t){var i,r,o,a;const n=new x(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),s=U.fromJSON(null!==(o=null===e||void 0===e?void 0:e.entities)&&void 0!==o?o:{}),l=D.fromJSON(null!==(a=null===e||void 0===e?void 0:e.views)&&void 0!==a?a:{});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 n.entities=s,n.views=l,l.setServerChildrenCountHandler((e,t,i)=>{n.handleServerReportedChildrenCount(e,t,null!==i&&void 0!==i?i:s)}),l.setChildrenCountInvalidator(e=>{n.invalidateChildrenCountCache(e)}),n}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 o=i.getFolder(r),a=null===o||void 0===o?void 0:o.childrenCount;void 0!==a&&a!==t&&this.views.forceInvalidateChildrenViews(r),i.updateServerChildrenCount(r,t)}}var B;function R(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 k=(z=B=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 b.FileManagerApiError(e,"ValidationError")}let o;for(const s of i){var a;const{files:i}=await this.getFiles({folderId:(null===(a=o)||void 0===a?void 0:a.id)||"",itemType:"folder"}),r=i.find(e=>e.name===s);if(r){if(!r.isFolder){const i=t("Path component '%s' in '%s' is not a folder").replace("%s",s).replace("%s",e);throw new b.FileManagerApiError(i,"ValidationError")}o={id:r.id,name:r.name,parentId:r.folderId}}else{var n;if("function"!==typeof this._dataProvider.createFolder)throw new b.FileManagerApiError(t("Create folder operation is not supported by data provider"),"UnsupportedOperation");o=await this.createFolder({name:s,parentId:null===(n=o)||void 0===n?void 0:n.id})}}return o}getTrashFolder(){return this._findOrCreateFolderByPath(this._pathOptions.trashPath||"Trash")}getTempFolder(){return this._findOrCreateFolderByPath(this._pathOptions.tempPath||"Edited")}constructor(e,t={},i,r=I.nr){var o,a;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._blobFetchForceReloadOnceIds=new Set,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 x(t.cacheStrategy||{},null===(o=t.cacheStrategy)||void 0===o?void 0:o.ttl,null===(a=t.cacheStrategy)||void 0===a?void 0:a.errorTtl),this.setController({invalidateItemCache:e=>{this._cache.forceInvalidate(e)},getCachedItem:e=>this._cache.getEntity(e)}),"function"!==typeof this._dataProvider.clearCache&&(this.clearCache=void 0)}setController(e){"function"===typeof this._dataProvider.setController&&this._dataProvider.setController(e)}async clearCache(e){if("function"!==typeof this._dataProvider.clearCache){const{__:e}=this.i18n;throw new b.FileManagerApiError(e("Clear cache is not supported by data provider"),"UnsupportedOperation")}this._cache.forceInvalidate(this._rootId),await this._dataProvider.clearCache(e)}markNextFileBlobFetchBypassHttpCache(e){this._blobFetchForceReloadOnceIds.add(this.normalizeId(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 b.FileManagerApiError(r,e)}if(/[\/\\:*?"<>|]/.test(e)){const{__:i}=this.i18n,r=t?"FolderInvalidName":"FileInvalidName",o=t?i("Folder name contains invalid characters: %s").replace("%s",e):i("File name contains invalid characters: %s").replace("%s",e);throw new b.FileManagerApiError(o,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 b.FileManagerApiError(i,"ValidationError")}}_checkNameExistsInCache(e,t,i,r){const o=this.normalizeId(e),a=this._cache.getChildrenIds(o);for(const n of a){const e=this._cache.getEntity(n);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"function"===typeof(null===(t=this._dataProvider)||void 0===t?void 0:t.getUrl)&&this._dataProvider.getUrl(e)||""}catch(i){}return""}async _getThumbnailUrl(e){if(e.thumbnailUrl)return e.thumbnailUrl;try{var t;return"function"===typeof(null===(t=this._dataProvider)||void 0===t?void 0:t.getThumbnailUrl)&&this._dataProvider.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 o=this._cache.getEntity(i);const a=new Set;for(;o&&o.folderId&&!a.has(o.id);){a.add(o.id);const e=this.normalizeId(o.folderId);if(e===r)return!0;if(o=this._cache.getEntity(e),!o||!o.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:o,limit:a,itemType:n="all",noFolder:s=!1}){var l,d;s&&(e=null===(d=await this.getTempFolder())||void 0===d?void 0:d.id);const h=this.normalizeId(null!==(l=e)&&void 0!==l?l:this._rootId),c=!1===this._options.enablePagination,u=c?1:o,v=c?1e3:a,f=this._options.clientSideFilter,p=this._options.clientSideSorting,m=this._options.clientSidePaging,w=m?Math.max(1,null!==o&&void 0!==o?o:1):void 0,g=m?"number"===typeof a&&Number.isFinite(a)&&a>0?a:25:void 0,y={folderId:h,itemType:n};f||(y.search=t),p||(y.sortBy=null!==i&&void 0!==i?i:"folder"!==n?"date":void 0,y.sortOrder=null!==r&&void 0!==r?r:"folder"!==n?"desc":void 0),m||(y.page=u,y.limit=v);const I={folderId:h,itemType:n,search:f?void 0:t,sortBy:p?void 0:y.sortBy,sortOrder:p?void 0:y.sortOrder,page:m?void 0:u,pageSize:m?void 0:v},_=await this._cache.getOrCreateChildren(h,I,async(e,t)=>{const i=await this._dataProvider.getItems({...t,folderId:e,limit:Number(t.pageSize)});var r;return m?{items:i.items,total:"number"===typeof(null===(r=i.pagination)||void 0===r?void 0:r.total)?i.pagination.total:i.items.length}:{items:i.items,...i.pagination}});let F,C=_.items;if(f)if("function"===typeof this._options.clientSideFilter)C=this._options.clientSideFilter(C,t);else if(t){const e=t.toLowerCase();C=C.filter(t=>{var i;return null===(i=t.name)||void 0===i?void 0:i.toLowerCase().includes(e)})}p&&(C="function"===typeof this._options.clientSideSorting?this._options.clientSideSorting(C,i,r):this._defaultClientSideSort(C,i,r)),F=m||f?C.length:_.total;let P=C;if(m)if("function"===typeof this._options.clientSidePaging)P=this._options.clientSidePaging(C,w,g);else{const e=(w-1)*g,t=e+g;P=C.slice(e,t)}if("function"===typeof this._dataProvider.getUrl||"function"===typeof this._dataProvider.getThumbnailUrl){const e=P.map(async e=>{if(e.isFolder)return e;const[t,i]=await Promise.all([e.url?Promise.resolve(e.url):"function"===typeof this._dataProvider.getUrl?this._dataProvider.getUrl(e):Promise.resolve(void 0),e.thumbnailUrl?Promise.resolve(e.thumbnailUrl):"function"===typeof this._dataProvider.getThumbnailUrl?this._dataProvider.getThumbnailUrl(e):Promise.resolve(void 0)]);return{...e,url:t,thumbnailUrl:i}});P=await Promise.all(e)}const b=m?{page:w,limit:g,total:F,totalPages:Math.max(1,Math.ceil(F/g)),hasNext:w*g<F,hasPrev:w>1}:{page:u,limit:v,total:F,...!m&&_.totalPages&&{totalPages:_.totalPages},...!m&&_.hasNextPage&&{hasNextPage:_.hasNextPage}};return{files:await Promise.all(P.map(this._mapItem)),pagination:b}}_defaultClientSideSort(e,t,i){return e.sort((e,r)=>{let o=0;switch(t){case"name":default:o=(e.name||"").localeCompare(r.name||"");break;case"date":o=new Date(e.date||0).getTime()-new Date(r.date||0).getTime();break;case"size":o=(Number(e.size)||0)-(Number(r.size)||0)}return"desc"===i?-o:o})}async getFileData(e,t){const i=this.normalizeId("string"===typeof e?e:e.id);let r=t;this._blobFetchForceReloadOnceIds.delete(i)&&(r={...t,forceReload:!0});const o=this._cache.getEntity(i)||("string"===typeof e?{id:i,name:"",folderId:this._rootId,isFolder:!1}:{...e,childrenCount:e.childCount});if("function"===typeof this._dataProvider.getFileData)return await this._dataProvider.getFileData(o,r);const{__:a}=this.i18n;if(!o.url&&"function"!==typeof this._dataProvider.getUrl)throw new b.FileManagerApiError(a("Cannot read file"),"FileReadError");const n=o.url||("function"===typeof this._dataProvider.getUrl?await this._dataProvider.getUrl(o):"");var s;if(n)return(await fetch(n,null!==(s=r)&&void 0!==s&&s.forceReload?{cache:"no-store"}:void 0)).blob();throw new b.FileManagerApiError(a("Unable to get file data"),"FileReadError")}async findFileByUrl(e){const t=this._cache.searchByUrl(e);if(t)return t;if("function"===typeof 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{if(this._options.clientSidePaging){var e;const i=await this.getFiles({folderId:t,itemType:"all",page:1,limit:25});return null!==(e=i.pagination.total)&&void 0!==e?e:i.files.length}const i=await this._dataProvider.getItems({folderId:t,limit:0,itemType:"all"});return"undefined"!==typeof i.pagination?i.pagination.total||0:!1===this._options.enablePagination?i.items.length:0}catch(i){if(this._isPathFolderNotFoundError(i))return 0;throw i}})}_isPathFolderNotFoundError(e){var t,i,r;if(!e||"object"!==typeof e)return!1;const o=e;return"path_folder_not_found"===o.code||"path_folder_not_found"===(null===(t=o.data)||void 0===t?void 0:t.code)||404===o.status||404===(null===(i=o.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),{__:r}=this.i18n;if("function"!==typeof this._dataProvider.uploadFile)throw new b.FileManagerApiError(r("Upload file operation is not supported by data provider"),"UnsupportedOperation");if(this._validateName(e.name,!1),this._validateDuplicates&&this._checkNameExistsInCache(i,e.name,!1)){const t=r("File '%s' already exists in target folder").replace("%s",e.name);throw new b.FileManagerApiError(t,"FileAlreadyExists")}const o={...this._cache.getEntity(i),...await this._dataProvider.uploadFile({...e,folderId:i}),folderId:i};return this._cache.upsertEntity(o),o}async uploadFiles(e){var t,i;const r=e.items.some(e=>e.noFolder)?await this.getTempFolder():null;e={...e,items:null===(t=e.items)||void 0===t?void 0:t.map(e=>({...e,folderId:e.noFolder?null===r||void 0===r?void 0:r.id:e.folderId}))};for(const v of e.items)v.folderId&&(e.folderId=v.folderId);const o=e.items||[],a=null!==(i=e.folderId)&&void 0!==i?i:this._rootId,n=this.normalizeId(a);if(this._validateDuplicates)for(const v of o)if(v.name){var s;this._validateName(v.name,!1);const e=this.normalizeId(null!==(s=v.folderId)&&void 0!==s?s:n);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 b.FileManagerApiError(t,"FileAlreadyExists")}}const l=this._cache.getEntity(n);let d={detailed:new Array(o.length),success:!0};if("function"===typeof this._dataProvider.uploadFiles){const e=o.map(e=>{var t;return{...e,folderId:this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:n)}});if(d=R(await this._dataProvider.uploadFiles({folderId:n,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:n};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("function"!==typeof this._dataProvider.uploadFile)throw new b.FileManagerApiError("Upload files is not supported by data provider","UnsupportedOperation");d.detailed=await Promise.all(o.map(async e=>{var t;const i=this.normalizeId(null!==(t=e.folderId)&&void 0!==t?t:n);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(n)}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("function"===typeof this._dataProvider.deleteItems){if(i=R(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"function"===typeof 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 b.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(o){return{requestId:e,error:o,success:!1}}})),i.success=!i.detailed.some(e=>!e.success));if(i.success&&r)try{this._cache.forceInvalidate(r.id)}catch(o){}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 b.FileManagerApiError(i,"FileNotFound")}if("function"!==typeof this._dataProvider.deleteItem){const{__:e}=this.i18n;throw new b.FileManagerApiError(e("Delete item operation is not supported by data provider"),"DeleteNotAllowed")}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 b.FileManagerApiError(e("Trash is not enabled"),"UnsupportedOperation");if("function"===typeof 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 b.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 b.FileManagerApiError(i,"FolderAlreadyExists")}const o=await this._dataProvider.createFolder(e,r,i);return this._cache.upsertEntity({id:o.id,folderId:r,name:o.name,isFolder:!0,childrenCount:o.childrenCount}),o}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("function"!==typeof this._dataProvider.renameItem)throw new b.FileManagerApiError(i("Rename folder is not supported"),"RenameNotAllowed");const r=this.normalizeId(e),o=this._cache.getEntity(r);if(!o){const t=i("Folder with id '%s' not found in cache").replace("%s",e);throw new b.FileManagerApiError(t,"FolderNotFound")}if(this._validateName(t,!0),this._validateDuplicates){const e=this.normalizeId(o.folderId);if(this._checkNameExistsInCache(e,t,!0,r)){const e=i("Folder '%s' already exists in parent folder").replace("%s",t);throw new b.FileManagerApiError(e,"FolderAlreadyExists")}}const a=await this._dataProvider.renameItem(o,t);return this._cache.upsertEntity({...this._cache.getEntity(a.id),...a}),this._cache.getEntity(a.id)}async renameFile(e,t){const{__:i}=this.i18n;if("function"!==typeof this._dataProvider.renameItem)throw new b.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 b.FileManagerApiError(t,"FileNotFound")}const o=this.normalizeId(e);if(this._validateName(t,!1),this._validateDuplicates){const e=this.normalizeId(r.folderId);if(this._checkNameExistsInCache(e,t,!1,o)){const e=i("File '%s' already exists in parent folder").replace("%s",t);throw new b.FileManagerApiError(e,"FileAlreadyExists")}}const a=await this._dataProvider.renameItem(r,t);return a&&this._cache.upsertEntity({...this._cache.getEntity(o),...a}),this._cache.getEntity(o)}async moveItem({itemId:e,targetFolderId:t,isFolder:i}){if("function"!==typeof this._dataProvider.moveItem){const{__:e}=this.i18n;throw new b.FileManagerApiError(e("Move item operation is not supported by data provider"),"MoveNotAllowed")}const r=this.normalizeId(t);this._validateTargetFolderType(t);const o=this._cache.getEntity(e);if(!o){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(s){}this._cache.upsertEntity({...t,folderId:r})}return!0}const{__:a}=this.i18n;if(o.isFolder){if(e===r)throw new b.FileManagerApiError(a("Cannot move folder into itself"),"MoveIntoSelf");if(this._isAncestor(e,r))throw new b.FileManagerApiError(a("Cannot move folder into its descendant"),"MoveIntoDescendant")}if(this._validateDuplicates&&r!==this.normalizeId(o.folderId)&&o.name&&this._checkNameExistsInCache(r,o.name,!!o.isFolder,e)){const e=o.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new b.FileManagerApiError(`${o.isFolder?"Folder":"File"} '${o.name}' already exists in target folder`,e)}const n=await this._dataProvider.moveItem(o,r);if(n.id===e){const t=this._cache.moveEntity(e,r);return this._cache.upsertEntity({...t,...n}),!0}{const t=this._cache.deleteEntity(e);return this._cache.upsertEntity({...t,...n,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 a of r)if(a){if(a.isFolder){const{__:e}=this.i18n;if(a.id===i){const t=e("Cannot move folder '%s' into itself").replace("%s",a.name);throw new b.FileManagerApiError(t,"MoveIntoSelf")}if(this._isAncestor(a.id,i)){const t=e("Cannot move folder '%s' into its descendant").replace("%s",a.name);throw new b.FileManagerApiError(t,"MoveIntoDescendant")}}if(this._validateDuplicates){const e=this.normalizeId(a.folderId);if(i!==e&&a.name&&this._checkNameExistsInCache(i,a.name,!!a.isFolder,a.id)){const e=a.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new b.FileManagerApiError(`${a.isFolder?"Folder":"File"} '${a.name}' already exists in target folder`,e)}}}let o={detailed:new Array(r.length),success:!0};if("function"===typeof this._dataProvider.moveItems)o=R(await this._dataProvider.moveItems(r,i),e=>e);else{if("function"!==typeof this._dataProvider.moveItem)throw new b.FileManagerApiError("Move items is not supported","MoveNotAllowed");o.detailed=await Promise.all(t.map(async(e,t)=>{const o=r[t]||{id:e,folderId:null,isFolder:!1,name:e};try{return{requestId:e,data:await this._dataProvider.moveItem(o,i),success:!0}}catch(a){return{requestId:e,success:!1,error:a}}}))}if(o.success){const e=o.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 o}{const{__:e}=this.i18n;return{success:!1,error:o.error||new b.FileManagerApiError(e("Move items failed"),"MoveNotAllowed")}}}async copyItem({itemId:e,targetFolderId:t}){if("function"!==typeof this._dataProvider.copyItem){const{__:e}=this.i18n;throw new b.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 b.FileManagerApiError(`${r.isFolder?"Folder":"File"} '${r.name}' already exists in target folder`,e)}}const o=await this._dataProvider.copyItem(r,i);return this._cache.copyEntity(e,i,o.id,{...o,folderId:i})||this._cache.upsertEntity({...o,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),o=r.map(e=>e.id),a=o.map((e,t)=>{var i;const o=this._cache.getEntity(e),a=null===(i=r[t])||void 0===i?void 0:i.newName;return o?a?{...o,name:a}:o:void 0});if(this._validateDuplicates)for(let l=0;l<a.length;l++){const e=a[l];if(e&&e.name){const t=this.normalizeId(e.folderId),r=i===t?o[l]:void 0;if(this._checkNameExistsInCache(i,e.name,!!e.isFolder,r)){const t=e.isFolder?"FolderAlreadyExists":"FileAlreadyExists";throw new b.FileManagerApiError(`${e.isFolder?"Folder":"File"} '${e.name}' already exists in target folder`,t)}}}let n={detailed:new Array(a.length),success:!0};if("function"===typeof this._dataProvider.copyItems)n=R(await this._dataProvider.copyItems(a,i),e=>e);else{if("function"!==typeof this._dataProvider.copyItem){const{__:e}=this.i18n;throw new b.FileManagerApiError(e("Copy items is not supported"),"CopyNotAllowed")}n.detailed=await Promise.all(o.map(async(e,t)=>{const r=a[t]||{id:e,folderId:null,isFolder:!1};try{return{requestId:e,data:await this._dataProvider.copyItem(r,i),success:!0}}catch(o){return{requestId:e,success:!1,error:o}}}))}if(n.success&&n.detailed)for(let l=0,d=n.detailed.length;l<d;l++){const e=n.detailed[l];var s;if(e.success&&null!==(s=e.data)&&void 0!==s&&s.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(!n.detailed)throw new b.FileManagerApiError("batchResult in copy method must have detailed results","ValidationError");return n}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("function"!==typeof this._dataProvider.updateFile)throw new b.FileManagerApiError(i("Update file is not supported"),"UnsupportedOperation");const r=this.normalizeId(e),o=this._cache.getEntity(r);if(!o){const t=i("File with id '%s' not found in cache").replace("%s",e);throw new b.FileManagerApiError(t,"FileNotFound")}if(t.name&&t.name!==o.name&&this._validateName(t.name,!1),this._validateDuplicates&&t.name&&t.name!==o.name){const e=this.normalizeId(o.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 b.FileManagerApiError(e,"FileAlreadyExists")}}const a=await this._dataProvider.updateFile(o,{...t});return this._cache.upsertEntity({...this._cache.getEntity(r),...a,...t}),this._cache.getEntity(r)}},class extends z{constructor(...e){super(...e);const t=Object.getOwnPropertyNames(z.prototype);for(const i of t){const e=Object.getOwnPropertyDescriptor(z.prototype,i);"constructor"!==i&&"function"===typeof(null===e||void 0===e?void 0:e.value)&&this[i]&&(this[i]=this[i].bind(this))}}}||B);var z,G=i(25516),L=i(20263),V=i(70529);const q="a_T7zSNUXtMfhVWQbIOMpXIPqzLQ8hm5Wfclm2nU98PtlSVxcft8FSn5InbD04056fYCpKXP20jJSySRLu",$={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 j(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 $[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"},o=await fetch("https://api-b2b.backenster.com/b1/api/v3/translate",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${q}`},body:JSON.stringify(e)});if(!o.ok)return i;const a=await o.json();if(a.err)return i;const n=a.result;return"string"===typeof n&&n.trim()?n.trim():i}catch(o){return i}}function K(){const e=(0,o.Pj)(),t=(0,o.d4)(c.B),i=(0,w.ml)(_.AZ.ON_TRANSLATE_ID);return(0,r.useCallback)(async(r,o={})=>{var a;const n=r.trim();if(!n)return n;const s=null!==(a=o.locale)&&void 0!==a?a:"string"===typeof t?t:void 0,l=void 0!==L.di.getInstance(e,V.Ef);try{const e=await i.fire({input:n,locale:s}),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?n:j(n,{locale:s}).catch(()=>n)},[t,e,i])}var H=i(2527),J=i(74397);const W=(0,r.memo)(F.KG),Y=(0,r.memo)(F.BC),{useToken:Z}=n.A,X="static/media/image-editor",Q="js/browser-image-compression.js",ee=({storageProvider:e})=>{var t,i;const n=(0,p.rD)(),{projectId:y,emailId:F,blockId:P}=(0,a.g)(),b=(0,I.s9)(),{__:E}=b,{token:M}=Z(),{error:S,notify:T}=(0,m.hN)(),O=(0,o.wA)(),N=(0,o.d4)(c.B$),U=(0,o.d4)(c.C1),D=(0,o.d4)(u.cL),x=(0,o.d4)(v.yN),B=K(),{request:R,resolveImagePicker:z}=(0,J.p)(),L=(0,r.useMemo)(()=>{const e=n.fileManager;if(e)return{...e,enablePagination:!1===e.enablePagination?Boolean(e.clientSidePaging):e.enablePagination}},[n.fileManager]),[V,q]=(0,r.useState)(""),[$,j]=(0,r.useState)("my_files"),[ee,te]=(0,r.useState)(!1),[ie,re]=(0,r.useState)(0),[oe,ae]=(0,r.useState)(""),[ne,se]=(0,r.useState)(()=>[]),le=(0,r.useCallback)(()=>{O((0,u.Oo)()),setTimeout(()=>q(""),600)},[O]),de=!(N||(null===(t=U.id)||void 0===t?void 0:t.toString())!==(null===x||void 0===x||null===(i=x.members)||void 0===i?void 0:i.owner.ID));(0,r.useEffect)(()=>{null!==R&&void 0!==R&&R.kind&&(q(R.kind),ae(R.currentUrl||"")),D===C.lx.UPLOAD_IMAGE_MODAL||D===C.lx.UPLOAD_BACKGROUND_MODAL?j("editor"):D===C.lx.UPLOAD_IMAGE_MODAL_AI||D===C.lx.UPLOAD_BACKGROUND_MODAL_AI?de?(te(!0),re(2)):j("ai"):D===C.lx.UPLOAD_IMAGE_MODAL_UPLOAD||D===C.lx.UPLOAD_BACKGROUND_MODAL_UPLOAD?j("my_files"):D===C.lx.UPLOAD_IMAGE_MODAL_STOCK||D===C.lx.UPLOAD_BACKGROUND_MODAL_STOCK?de?(te(!0),re(3)):j("stock_images"):D===C.lx.UPLOAD_IMAGE_MODAL_GIF||D===C.lx.UPLOAD_BACKGROUND_MODAL_GIF?de?(te(!0),re(3)):j("gif"):D===C.lx.UPLOAD_IMAGE_MODAL_EDIT||D===C.lx.UPLOAD_BACKGROUND_MODAL_EDIT?(de?(te(!0),re(5)):j("editor"),O((0,u.Wz)(C.lx.IMAGE_EDITOR_MODAL))):j("my_files")},[D,O,de,R]);const he=!de&&!!$&&(D.includes("UPLOAD_IMAGE_")||D.includes("UPLOAD_BACKGROUND_"));(0,r.useEffect)(()=>{const e=document.querySelector("#carrotquest-messenger-collapsed-container");e&&(e.style.display=he?"none":"")},[he]);const ce=(0,r.useMemo)(()=>e?e.pathMode?new A(e,e.rootId,"Trash",e.trashPath,!0,b):null:(S(E("Error when initializing file manager")),null),[e,S,b]),ue=(0,r.useMemo)(()=>new k(null!==ce&&void 0!==ce?ce:e,L,{...e,trashPath:e.pathMode?"trash":e.trashPath,rootId:e.pathMode?"":e.rootId},b),[e,ce,L,b]),ve=(0,r.useCallback)(e=>{const t=(0,G.e0)(e,ue,ce);return T(t,!0)},[ue,ce,T]),fe=(0,w.ml)(_.AZ.FILE_PROXY_EVENT_ID),pe=(0,H.p)(),me=(0,o.Pj)(),we=(0,r.useCallback)(async e=>{const t=await fe.fire({url:e,project:y});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},[fe,y,pe,me]),ge=r.createElement(d.A,{style:{fontSize:32,margin:-16},spin:!0}),ye=(0,r.useCallback)(e=>{g.isEqual(e,ne)||se(e)},[ne]),[Ie]=(0,h.Mv)(),_e=(0,r.useCallback)(async()=>{if(ue){const e=ne[0];if(e){const t=e.url||e.thumbnailUrl||e.thumbnail;t&&z({url:t,file:e,meta:{mode:"select"}})}}le()},[ue,le,ne,z]),Fe=(0,r.useCallback)(async(e,t)=>{let i=e.url;!i&&ue&&(i=await ue.getFileUrl(e.folderId,e.name)),i&&("save"===(null===t||void 0===t?void 0:t.mode)&&ue.markNextFileBlobFetchBypassHttpCache(e.id),z({url:i,file:e,meta:t})),le()},[ue,le,z]),Ce=(0,r.useCallback)(async()=>{le()},[le]),[Pe,{data:be=[]}]=(0,h.gg)(),Ae=(null===n||void 0===n?void 0:n.handleLimitUsageEmitter)||(0,w.ml)(_.AZ.ON_LIMIT_ID),Ee=(0,r.useCallback)(async function(e){try{await Pe(e).unwrap()}catch(t){}},[Pe]),Me=(0,r.useMemo)(()=>{const e=(null===n||void 0===n?void 0:n.icons)||{};if(e&&0!==Object.keys(e).length)return(0,G.Rt)(e)},[null===n||void 0===n?void 0:n.icons]),Se=(0,r.useCallback)(async(e,t={})=>await B(e,t),[B]),Te=(0,w.ml)(_.AZ.PROXY_URL_EVENT_ID),Oe=(0,r.useCallback)(async e=>(await Te.fire({url:e,project:y})).findLast(t=>t&&t!==e)||(0,G.W5)(e),[Te,y]),Ne=(0,r.useMemo)(()=>({assetsUrl:(0,G.Zq)("",X),compessorUrl:(0,G.Zq)("",Q),compressMaxSize:null===L||void 0===L?void 0:L.compressMaxSize,compressMaxWidthOrHeight:null===L||void 0===L?void 0:L.compressMaxWidthOrHeight,onClose:le,handleProxyUrl:Oe,handleFileProxy:we,expandRootFolderOnInit:!1!==(null===L||void 0===L?void 0:L.expandRootFolderOnInit),activeLibraryItem:$,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:oe,projectId:y,elementId:F||P,pushToGTM:null===n||void 0===n?void 0:n.pushToGTM,handleLimitUsageEmitter:Ae,sseQuery:Ee,messages:be,sendAIImageRequest:(null===n||void 0===n?void 0:n.sendAIImageRequest)||Ie,locale:U.locale.split("-")[0].split("_")[0],theme:U.theme,customTheme:M,enableTrashFolder:null===L||void 0===L?void 0:L.enableTrash,showNotifications:null===L||void 0===L?void 0:L.showNotifications,previewFallbackToFileUrl:null===L||void 0===L?void 0:L.previewFallbackToFileUrl,dedupeUploadNamesOnClient:null===L||void 0===L?void 0:L.dedupeUploadNamesOnClient,saveCopyToCurrentFolder:null===L||void 0===L?void 0:L.saveCopyToCurrentFolder,handleTranslate:Se,features:{enableStockImages:!1!==n.imageCenterStockEnabled,enableGif:!1!==n.imageCenterGifEnabled,enableIconStock:!1!==n.imageCenterIconStockEnabled,enableRenameFile:!1!==(null===L||void 0===L?void 0:L.enableRenameFile),enableRenameFolder:!1!==(null===L||void 0===L?void 0:L.enableRenameFolder),enableUpdateFile:!1!==(null===L||void 0===L?void 0:L.enableUpdateFile),enableCopyItem:!1!==(null===L||void 0===L?void 0:L.enableCopyFile),enableCopyFolder:!1!==(null===L||void 0===L?void 0:L.enableCopyFolder),enableDelete:!1!==(null===L||void 0===L?void 0:L.enableDelete),enableEdit:!1!==(null===L||void 0===L?void 0:L.enableEdit),enableMoveItem:!1!==(null===L||void 0===L?void 0:L.enableMoveFile),enableMoveFolder:!1!==(null===L||void 0===L?void 0:L.enableMoveFolder)},disablePagination:!1===(null===L||void 0===L?void 0:L.enablePagination),multiSelect:!1!==(null===L||void 0===L?void 0:L.multiSelect),sortOptions:null===L||void 0===L?void 0:L.sortOptions,defaultFolderName:null===L||void 0===L?void 0:L.defaultFolderName,availableImageExtensions:null===L||void 0===L?void 0:L.availableImageExtensions}),[L,le,Oe,we,$,oe,y,F,P,n,Ae,Ee,be,Ie,U.locale,U.theme,M,Se]);return R&&V&&ue?r.createElement(r.Fragment,null,!de&&r.createElement(s.A,{className:"file-manager",closable:!0,footer:null,open:he,width:"100vw",onOk:_e,onCancel:le},r.createElement(l.A,{spinning:!ue,indicator:ge},ue&&("editor"===$?r.createElement(Y,{onSave:Fe,onClose:Ce,compessorUrl:(0,G.Zq)("",Q),compressMaxSize:null===L||void 0===L?void 0:L.compressMaxSize,compressMaxWidthOrHeight:null===L||void 0===L?void 0:L.compressMaxWidthOrHeight,dedupeUploadNamesOnClient:null===L||void 0===L?void 0:L.dedupeUploadNamesOnClient,saveCopyToCurrentFolder:null===L||void 0===L?void 0:L.saveCopyToCurrentFolder,dataProviders:ue,handleFileProxy:we,theme:U.theme,file:oe,handleNotify:ve,assetsUrl:(0,G.Zq)("",X),locale:U.locale.split("-")[0].split("_")[0]}):r.createElement(W,{dataProviders:ue,onChangeSelection:ye,onEditorOk:Fe,handleNotify:ve,customIcons:Me,config:Ne})))),r.createElement(f.A,{open:ee,onCancel:()=>te(!1),initialSlide:ie,sideOnOk:void 0})):null},te=(0,r.memo)(ee)}}]);
|
|
2
|
+
//# sourceMappingURL=5102.eac304ab.js.map
|