@emailmaker/emailmaker 1.0.93-alpha.2 → 1.0.93-alpha.3

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.
@@ -1 +1 @@
1
- "use strict";(globalThis.webpackChunkemail_maker=globalThis.webpackChunkemail_maker||[]).push([[57],{10653:(e,t,i)=>{i.r(t),i.d(t,{default:()=>x});var r=i(98173),n=i(2604),s=i(62272),l=i(40120),o=i(48753),a=i(98447),d=i(38826),u=i(871),h=i(47014),c=i(23424),v=i(80772),f=i(84572),p=i(48956),w=i(27941),g=i(64909),m=i(90614),y=i(73180);let I;var F;(F=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 n=0;n<r;n++)if(!i(e[n],t[n]))return!1;return!0},F.unique=function(e,t){t||(t=e=>e);const i=new Set;return e.filter((e=>{const r=t(e),n=!i.has(r);return i.add(r),n}))};var A=i(12543),O=i(15626),_=i(51213);function S(e){return null==e||""===e?"":e}function E(e){if(null==e)return 1/0;const t=Number(e);return Number.isFinite(t)&&t>=0?t:1/0}function P(e){if(!e)return"";const t=e.folderId;return null==t?"":String(t)}function D(e){return!!e&&!0===e.isFolder}function T(){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)}`}class C{constructor(){this.entities=new Map,this.childrenByParent=new Map}now(){return Date.now()}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)}getFile(e){const t=this.getEntity(e);return t&&!D(t)?t:void 0}getFolder(e){const t=this.getEntity(e);return t&&D(t)?t:void 0}getChildrenIds(e,t={}){const i=S(e),r=this.childrenByParent.get(i);return r?t.onlyFiles?Array.from(r.files):t.onlyFolders?Array.from(r.folders):[...Array.from(r.folders),...Array.from(r.files)]:[]}upsertEntity(e){var t;const i=null!==(t=this.entities.get(e.id))&&void 0!==t?t:null,r=i?i.value:null,n=r?P(r):"",s=P(e),l=!!r&&D(r),o=D(e);if(r&&(n!==s||l!==o)){const t=S(n),i=this.childrenByParent.get(t);i&&(l?i.folders.delete(e.id):i.files.delete(e.id),0===i.files.size&&0===i.folders.size&&this.childrenByParent.delete(t))}this.entities.set(e.id,{value:{...e},updatedAt:this.now()});const a=S(s);let d=this.childrenByParent.get(a);d||(d={files:new Set,folders:new Set},this.childrenByParent.set(a,d)),o?d.folders.add(e.id):d.files.add(e.id)}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,n=P(r),s=S(n),l=this.childrenByParent.get(s);return l&&(D(r)?l.folders.delete(e):l.files.delete(e),0===l.files.size&&0===l.folders.size&&this.childrenByParent.delete(s)),this.entities.delete(e),{entity:{...r},parentId:n}}deleteFolderRecursive(e){const t=this.entities.get(e);if(!t||!D(t.value))return{deletedFolderRecords:[],deletedFileRecords:[]};const i=[e],r=[],n=[];for(;i.length;){const e=i.shift();r.push(e);const t=this.childrenByParent.get(S(e));if(t){for(const e of Array.from(t.folders))i.push(e);for(const e of Array.from(t.files))n.push(e)}}const s=[];for(const o of n){const e=this.entities.get(o);if(!e)continue;const t=e.value,i=S(P(t)),r=this.childrenByParent.get(i);r&&(r.files.delete(o),0===r.files.size&&0===r.folders.size&&this.childrenByParent.delete(i)),this.entities.delete(o),s.push({...t})}const l=[];for(const o of r.reverse()){const e=this.entities.get(o);if(!e)continue;const t=e.value,i=S(t.id);this.childrenByParent.delete(i);const r=S(P(t)),n=this.childrenByParent.get(r);n&&(n.folders.delete(o),0===n.files.size&&0===n.folders.size&&this.childrenByParent.delete(r)),this.entities.delete(o),l.push({...t})}return{deletedFolderRecords:l,deletedFileRecords:s}}moveEntityById(e,t){var i;const r=null!==(i=this.entities.get(e))&&void 0!==i?i:null;if(!r)return null;const n=r.value,s=S(P(n)),l=this.childrenByParent.get(s);l&&(D(n)?l.folders.delete(e):l.files.delete(e),0===l.files.size&&0===l.folders.size&&this.childrenByParent.delete(s));const o={...n,folderId:t};this.entities.set(e,{value:o,updatedAt:this.now()});const a=S(t);let d=this.childrenByParent.get(a);return d||(d={files:new Set,folders:new Set},this.childrenByParent.set(a,d)),D(o)?d.folders.add(e):d.files.add(e),{...o}}copyFile(e,t,i){var r;const n=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!n||D(n.value))return null;const s={...n.value,id:t,folderId:i};return this.upsertEntity(s),{...s}}copyFolderShallow(e,t,i){var r;const n=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!n||!D(n.value))return null;const s={...n.value,id:t,folderId:i};return this.upsertEntity(s),{...s}}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}))}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 C;for(const[n,s]of null!==(i=e.entities)&&void 0!==i?i:[]){var i;t.entities.set(n,{value:s.value,updatedAt:s.updatedAt})}for(const[n,s]of null!==(r=e.childrenByParent)&&void 0!==r?r:[]){var r;t.childrenByParent.set(n,{files:new Set(s.files),folders:new Set(s.folders)})}return t}}class M{constructor(e={},t=3e5,i=3e4,r){var n,s,l;this.views=new Map,this.strategy=void 0,this.ttl=void 0,this.errorTtl=void 0,this.entityTtl=void 0,this.strategy={allowSortedInsert:null===(n=e.allowSortedInsert)||void 0===n||n,allowSearchInsert:null===(s=e.allowSearchInsert)||void 0===s||s,invalidateOnPaginationFull:null===(l=e.invalidateOnPaginationFull)||void 0===l||l,comparator:e.comparator,filterMatch:e.filterMatch},this.ttl=t,this.errorTtl=i,this.entityTtl=null!==r&&void 0!==r?r:t}now(){return Date.now()}parentKey(e){return S(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){if(!e)return!0;for(const i of e)if(t.isEntityStale(i,this.entityTtl))return!0;return!1}async getOrCreateChildren(e,t,i,r){var n;const s=this.parentKey(e),l=function(e){const t=new WeakSet;try{return function e(i){return null===i?"null":"boolean"===typeof i?i?"true":"false":"number"===typeof i?Number.isNaN(i)?"NaN":i===1/0?"Infinity":i===-1/0?"-Infinity":Object.is(i,-0)?"-0":String(i):"string"===typeof i?JSON.stringify(i):"undefined"===typeof i?"undefined":"symbol"===typeof i?String(i.toString()):"function"===typeof i?'"[function]"':i instanceof Date?`"Date(${i.toISOString()})"`:i instanceof RegExp?`"RegExp(${i.toString()})"`:"object"===typeof i?t.has(i)?'"[Circular]"':(t.add(i),i instanceof Map?`{Map:${Array.from(i.entries()).map((([t,i])=>`[${e(t)}:${e(i)}]`)).join(",")}}`:i instanceof Set?`{Set:${Array.from(i.values()).map((t=>e(t))).join(",")}}`:Array.isArray(i)?`[${i.map((t=>e(t))).join(",")}]`:`{${Object.entries(i).sort((([e],[t])=>e.localeCompare(t))).map((([t,i])=>`${JSON.stringify(t)}:${e(i)}`)).join(",")}}`):JSON.stringify(String(i))}(e)}catch(i){try{return JSON.stringify(e)}catch{return String(e)}}}(null!==t&&void 0!==t?t:{});let o=this.views.get(s);o||(o=new Map,this.views.set(s,o));let a=o.get(l);if(!a){a={params:t,view:{promise:null,value:void 0,meta:void 0,error:void 0,updatedAt:0}},o.set(l,a)}if(a.view.error&&!this.isErrorExpired(a.view.updatedAt))throw a.view.error;if(a.view.value&&!this.isExpired(a.view.updatedAt)&&!this.areEntitiesStale(a.view.value,r)&&(null===(n=a.view.meta)||void 0===n||!n.stale)){var d;return{items:a.view.value.map((e=>r.getEntity(e))).filter(Boolean),...null!==(d=a.view.meta)&&void 0!==d?d:{}}}return a.view.promise||(a.view.promise=(async()=>{try{const n=await i(e,t);for(const e of n.items)r.upsertEntity(e);a.view.value=n.items.map((e=>e.id));const{items:s,...l}=n,o={...l};return"number"!==typeof o.total&&(o.total=Number(o.total)||(a.view.value?a.view.value.length:0)),a.view.meta=o,a.view.error=null,a.view.updatedAt=this.now(),n}catch(n){throw a.view.error=n,a.view.value=void 0,a.view.updatedAt=this.now(),n}finally{a.view.promise=null}})()),a.view.promise}tryInsertSorted(e,t,i){const r=this.strategy.comparator;if(!r)return!1;if(!e.view.value)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),o=r(t,n[i],e.params);if("number"!==typeof o||Number.isNaN(o))return!1;o>=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)}smartInvalidateChildrenViews(e,t,i,r,n,s){const l=this.parentKey(null!==e&&void 0!==e?e:null),o=this.views.get(l);if(o)for(const[,c]of o){var a,d;const e=null!==(a=c.params)&&void 0!==a?a:{},o=null!==(d=null===e||void 0===e?void 0:e.page)&&void 0!==d?d:1,v=E(null===e||void 0===e?void 0:e.pageSize),f=Number.isFinite(v),p=!!(null!==e&&void 0!==e&&e.sortBy||null!==e&&void 0!==e&&e.sortOrder),w=["page","pageSize","sortBy","sortOrder","search"].some((t=>null===e||void 0===e?void 0:e[t]));if(!c.view.value){var u;c.view.meta={...null!==(u=c.view.meta)&&void 0!==u?u:{},stale:!0};continue}const g=()=>{c.view.meta||(c.view.meta={}),c.view.meta.total=c.view.value.length};if("delete"===i&&t){const e=c.view.value.length;c.view.value.includes(t.id)&&(c.view.value=c.view.value.filter((e=>e!==t.id)),g(),f&&e===v&&(c.view.meta.stale=!0),c.view.updatedAt=Date.now())}else if("insert"!==i&&"copy"!==i&&"update"!==i||!t)if("move"===i&&t){var h;const e=this.parentKey(null!==n&&void 0!==n?n:null),i=this.parentKey(null!==(h=t.folderId)&&void 0!==h?h:null);if(l===e&&c.view.value.includes(t.id)){const e=c.view.value.length;c.view.value=c.view.value.filter((e=>e!==t.id)),g(),f&&e===v&&(c.view.meta.stale=!0),c.view.updatedAt=Date.now()}if(l===i){if(f&&o>1){c.view.meta.stale=!0;continue}if(w&&this.strategy.filterMatch&&!this.strategy.filterMatch(t,c.params))continue;let e=!1;p&&this.strategy.allowSortedInsert&&this.strategy.comparator&&r&&(e=this.tryInsertSorted(c,t,r)),!e&&c.view.value.length<v?c.view.value.push(t.id):e||(c.view.meta.stale=!0),g(),c.view.updatedAt=Date.now()}}else;else{let e=c.view.value.includes(t.id);const n=!!this.strategy.comparator,l=!!s&&(n||Object.keys(t).some((e=>s[e]!==t[e])));let o=i;if((e||l)&&(o="update"),w&&this.strategy.filterMatch&&!this.strategy.filterMatch(t,c.params)){e&&(c.view.value=c.view.value.filter((e=>e!==t.id)),g(),c.view.updatedAt=Date.now());continue}if("update"===o){if(!p&&!w){c.view.updatedAt=Date.now(),g();continue}c.view.value=c.view.value.filter((e=>e!==t.id)),e=!1}let a=!1;!e&&p&&this.strategy.allowSortedInsert&&this.strategy.comparator&&r&&(a=this.tryInsertSorted(c,t,r)),e||a||(!f||c.view.value.length<v?c.view.value.push(t.id):c.view.meta.stale=!0),g(),c.view.updatedAt=Date.now()}}}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}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}}}static fromJSON(e,t){var i,r,n;const s=new M(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,null!==(n=null===e||void 0===e?void 0:e.entityTtl)&&void 0!==n?n:void 0);for(const[v,f]of null!==(l=null===e||void 0===e?void 0:e.views)&&void 0!==l?l:[]){var l;const e=new Map;for(const[t,i]of f){var o,a,d,u,h,c;const r=null!==(o=i.params)&&void 0!==o?o:{},n=null!==(a=i.view)&&void 0!==a?a:{},s={promise:null,value:null!==(d=n.value)&&void 0!==d?d:void 0,meta:null!==(u=n.meta)&&void 0!==u?u:void 0,error:null!==(h=n.error)&&void 0!==h?h:null,updatedAt:null!==(c=n.updatedAt)&&void 0!==c?c:0};e.set(t,{params:r,view:s})}s.views.set(v,e)}return s}}class b{constructor(e={},t=3e5,i=3e4){this.entities=void 0,this.views=void 0,this.ttl=void 0,this.errorTtl=void 0,this.ttl=t,this.errorTtl=i,this.entities=new C,this.views=new M(e,t,i)}getEntity(e){return this.entities.getEntity(e)}getFile(e){return this.entities.getFile(e)}getFolder(e){return this.entities.getFolder(e)}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?P(t):"",r=P(e),n=t?D(t):"",s=D(e);if(this.entities.upsertEntity(e),t){if(i!==r||n!==s)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;for(;i;){if(i===e)return!0;const t=this.entities.getEntity(i);if(!t)break;i=P(t)}return!1}moveEntity(e,t){const i=this.entities.getEntity(e);if(!i)return null;if(D(i)&&null!==t&&this.isAncestor(e,t))return null;const r=P(i),n=this.entities.moveEntityById(e,t);return n?(this.views.smartInvalidateChildrenViews(r,i,"delete",this.entities),this.views.smartInvalidateChildrenViews(t,n,"insert",this.entities),n):null}copyEntity(e,t,i){var r;const n=this.entities.getEntity(e);if(!n)return null;if(!D(n)){const r=null!==i&&void 0!==i?i:T(),n=this.entities.copyFile(e,r,null!==t&&void 0!==t?t:null);return n?(this.views.smartInvalidateChildrenViews(t,n,"copy",this.entities),r):null}const s=[e],l=[];for(;s.length;){const e=s.shift();l.push(e);const t=this.entities.getChildrenIds(e,{onlyFolders:!0});for(const i of t)s.push(i)}const o=new Map;for(const u of l)o.set(u,T());for(const u of l){var a,d;const e=this.entities.getFolder(u),i=o.get(u),r=P(e),n=null===r?t:null!==(a=o.get(r))&&void 0!==a?a:null,s={...e,id:i,folderId:n};this.entities.upsertEntity(s),this.views.smartInvalidateChildrenViews(null!==(d=s.folderId)&&void 0!==d?d:null,s,"copy",this.entities)}for(const u of l){const e=o.get(u),t=this.entities.getChildrenIds(u,{onlyFiles:!0});for(const i of t){const t=this.entities.getFile(i);if(!t)continue;const r=T(),n={...t,id:r,folderId:e};this.entities.upsertEntity(n),this.views.smartInvalidateChildrenViews(e,n,"copy",this.entities)}}return null!==(r=o.get(e))&&void 0!==r?r:null}deleteEntity(e){const t=this.entities.getEntity(e);if(!t)return null;if(D(t)){const{deletedFolderRecords:i,deletedFileRecords: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);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,deletedFileRecords: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);return{deletedFileIds: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(D(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)}toJSON(){return{entities:this.entities.toJSON(),views:this.views.toJSON(),ttl:this.ttl,errorTtl:this.errorTtl}}static fromJSON(e,t){var i,r,n,s;const l=new b(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),o=C.fromJSON(null!==(n=null===e||void 0===e?void 0:e.entities)&&void 0!==n?n:{}),a=M.fromJSON(null!==(s=null===e||void 0===e?void 0:e.views)&&void 0!==s?s:{},null!==t&&void 0!==t?t:{});return l.entities=o,l.views=a,l}}var B;function N(e){return null!==e&&void 0!==e?e:""}let L=(0,_.A)(B=class{constructor(e,t={}){this._dataProvider=e,this.options=t,this._cache=void 0,this.ROOT_ID="",this._cache=new b(t.cacheStrategy||{},t.cacheStrategy.ttl,t.cacheStrategy.errorTtl)}async getFiles({folderId:e,search:t,sortBy:i,sortOrder:r,page:n,limit:s,itemType:l="all"}){const o=N(null!==e&&void 0!==e?e:this.ROOT_ID);"folder"!==l&&(i??="date",r??="desc",n??=1,s??=50);const a=this.options.clientSideFilter||this.options.clientSideSorting||this.options.clientSidePaging?{folderId:o,itemType:l}:{folderId:o,page:n,pageSize:s,itemType:l};let d=(await this._cache.getOrCreateChildren(o,a,(async()=>{const e=await this._dataProvider.getFiles({folderId:o,search:t,sortBy:i,sortOrder:r,page:n,limit:s,itemType:l});return{items:e.files,...e.pagination}}))).items;if(this.options.clientSideFilter)if("function"===typeof this.options.clientSideFilter)d=this.options.clientSideFilter(d,t);else if(t){const e=t.toLowerCase();d=d.filter((t=>{var i;return null===(i=t.name)||void 0===i?void 0:i.toLowerCase().includes(e)}))}this.options.clientSideSorting&&(d="function"===typeof this.options.clientSideSorting?this.options.clientSideSorting(d,i,r):d.sort(((e,t)=>(e.name||"").localeCompare(t.name||""))));const u=d.length;if(this.options.clientSidePaging)if("function"===typeof this.options.clientSidePaging)d=this.options.clientSidePaging(d,n,s);else{const e=(n-1)*s,t=e+s;d=d.slice(e,t)}return{files:d,pagination:{page:n,limit:s,total:u}}}async getFileData(e){if(this._dataProvider.getFileData)return this._dataProvider.getFileData(e);if(!e.url)throw new Error("Cannot read file");return(await fetch(e.url)).blob()}async uploadFile(e){var t;const i=N(null!==(t=e.folderId)&&void 0!==t?t:this.ROOT_ID),r=await this._dataProvider.uploadFile({...e,folderId:i});return this._cache.upsertEntity({...r,folderId:i}),r}async deleteFile(e){const t=await this._dataProvider.deleteFile(e);return t&&this._cache.deleteEntity(e),t}async createFolder({name:e,parentId:t}){const i=N(null!==t&&void 0!==t?t:this.ROOT_ID),r=await this._dataProvider.createFolder({name:e,parentId:i});return this._cache.upsertEntity({id:r.id,folderId:i,name:r.name,isFolder:!0}),r}async deleteFolder(e){const t=await this._dataProvider.deleteFolder(e);return t&&this._cache.deleteFolderRecursive(e),t}async renameFolder(e,t){if(!this._dataProvider.renameFolder)throw new Error("Rename folder is not supported");const i=await this._dataProvider.renameFolder(e,t);return i&&this._cache.upsertEntity({id:i.id,folderId:N(i.parentId),name:i.name,isFolder:!0}),i}async renameFile(e,t){if(!this._dataProvider.renameFile)throw new Error("Rename file is not supported");const i=await this._dataProvider.renameFile(e,t);return i&&this._cache.upsertEntity({...i,folderId:N(i.folderId)}),i}async moveItem({itemId:e,targetFolderId:t,isFolder:i}){const r=N(t),n=await this._dataProvider.moveItem({itemId:e,targetFolderId:r,isFolder:i});return n&&this._cache.moveEntity(e,r),n}async copyItem({itemId:e,targetFolderId:t,isFolder:i}){if(!this._dataProvider.copyItem)throw new Error("Copy item is not supported");const r=N(t),n=await this._dataProvider.copyItem({itemId:e,targetFolderId:r,isFolder:i});return n&&this._cache.copyEntity(e,r),n}async uploadFileByUrl(e){var t;const i=N(null!==(t=e.folderId)&&void 0!==t?t:this.ROOT_ID),r=await this._dataProvider.uploadFileByUrl({...e,folderId:i});return this._cache.upsertEntity({...r,folderId:i}),r}async updateFile(e,t){if(!this._dataProvider.updateFile)throw new Error("Update file is not supported");const i=await this._dataProvider.updateFile(e,t);return i&&this._cache.upsertEntity({...i,folderId:N(i.folderId)}),i}})||B;var U=i(85954),R=i(32947),G=(i(51731),i(82900));class k{constructor(e){this.inner=e,this.pathToId=new Map,this.idToPath=new Map}getOrGenerateId(e){const t=e.replace(/^\/+|\/+$/g,"");if(!this.pathToId.has(t)){const e=(0,G.A)();this.pathToId.set(t,e),this.idToPath.set(e,t)}return this.pathToId.get(t)}pathForId(e){const t=this.idToPath.get(e);if(!t)throw new Error(`Path not found for ID: ${e}`);return t}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 getFiles(e){const t=e.folderId?this.pathForId(e.folderId):void 0,i=await this.inner.getFiles({...e,folderId:t}),r=i.files.map((e=>{const t=this.getOrGenerateId(e.id),i=e.folderId?this.getOrGenerateId(e.folderId):void 0;return{...e,id:t,folderId:i}}));return{...i,files:r}}async createFolder(e){const t=e.parentId?this.pathForId(e.parentId):void 0,i=await this.inner.createFolder({...e,parentId:t}),r=this.getOrGenerateId(i.id),n=i.parentId?this.getOrGenerateId(i.parentId):void 0;return{...i,id:r,parentId:n}}async renameFolder(e,t){const i=this.pathForId(e),r=await this.inner.renameFolder(i,t);this.updateIdMapping(e,r.id);const n=r.parentId?this.getOrGenerateId(r.parentId):void 0;return{...r,id:e,parentId:n}}async deleteFolder(e){const t=this.pathForId(e),i=await this.inner.deleteFolder(t);if(i){const t=this.idToPath.get(e);t&&(this.pathToId.delete(t),this.idToPath.delete(e))}return i}async uploadFile(e){const t=e.folderId?this.pathForId(e.folderId):void 0,i=await this.inner.uploadFile({...e,folderId:t}),r=this.getOrGenerateId(i.id),n=i.folderId?this.getOrGenerateId(i.folderId):void 0;return{...i,id:r,folderId:n}}async uploadFileByUrl(e){const t=e.folderId?this.pathForId(e.folderId):void 0,i=await this.inner.uploadFileByUrl({...e,folderId:t}),r=this.getOrGenerateId(i.id),n=i.folderId?this.getOrGenerateId(i.folderId):void 0;return{...i,id:r,folderId:n}}async deleteFile(e){const t=this.pathForId(e),i=await this.inner.deleteFile(t);if(i){const t=this.idToPath.get(e);t&&(this.pathToId.delete(t),this.idToPath.delete(e))}return i}async renameFile(e,t){const i=this.pathForId(e),r=await this.inner.renameFile(i,t);this.updateIdMapping(e,r.id);const n=r.folderId?this.getOrGenerateId(r.folderId):void 0;return{...r,id:e,folderId:n}}async moveItem({itemId:e,targetFolderId:t,isFolder:i}){const r=this.pathForId(e),n=this.pathForId(t),s=await this.inner.moveItem({itemId:r,targetFolderId:n,isFolder:i});return s&&this.updateIdMapping(e,`${n}/${e}`),s}async copyItem({itemId:e,targetFolderId:t,isFolder:i}){const r=this.pathForId(e),n=this.pathForId(t),s=await this.inner.copyItem({itemId:r,targetFolderId:n,isFolder:i});return s.id=this.getOrGenerateId(s.id),s}async updateFile(e,t){const i=this.pathForId(e),r=await this.inner.updateFile(i,t);this.updateIdMapping(e,r.id);const n=r.folderId?this.getOrGenerateId(r.folderId):void 0;return{...r,id:e,folderId:n}}async getFileData(e){const t=this.pathForId(e.id);return this.inner.getFileData?this.inner.getFileData({...e,id:t}):fetch(e.id).then((e=>e.blob()))}}const{useToken:V}=l.A,x=({storageProvider:e})=>{var t,i,l,F,_;const S=(0,w.rD)(),{projectId:E,emailId:P,blockId:D}=(0,s.g)(),{__:T}=(0,A.s9)(),{token:C}=V(),{error:M}=(0,g.hN)(),b=(0,n.wA)(),B=(0,n.d4)(h.B$),N=(0,n.d4)(h.C1),G=(0,n.d4)(c.cL),x=(0,n.d4)(v.Ac),$=(0,n.d4)(f.yN),K=(0,n.d4)(v.js),[z,J]=(0,r.useState)(""),[j,q]=(0,r.useState)("my_files"),[Y,H]=(0,r.useState)(!1),[Q,W]=(0,r.useState)(0),[X,Z]=(0,r.useState)(""),[ee,te]=(0,r.useState)((()=>[])),ie=()=>{b((0,c.Oo)()),setTimeout((()=>J("")),600)};let re=!(B||(null===(t=N.id)||void 0===t?void 0:t.toString())!==(null===$||void 0===$||null===(i=$.members)||void 0===i?void 0:i.owner.ID))&&!0;const ne=(0,r.useMemo)((()=>({img:K,background:x})),[K,x]);(0,r.useEffect)((()=>{G.includes("UPLOAD_BACKGROUND_MODAL")?(J("background"),ne.background&&Z(ne.background)):G.includes("UPLOAD_IMAGE_MODAL")&&(J("img"),ne.img&&Z(ne.img)),G===R.lx.UPLOAD_IMAGE_MODAL||G===R.lx.UPLOAD_BACKGROUND_MODAL?q("editor"):G===R.lx.UPLOAD_IMAGE_MODAL_AI||G===R.lx.UPLOAD_BACKGROUND_MODAL_AI?re?(H(!0),W(2)):q("ai"):G===R.lx.UPLOAD_IMAGE_MODAL_UPLOAD||G===R.lx.UPLOAD_BACKGROUND_MODAL_UPLOAD?q("my_files"):G===R.lx.UPLOAD_IMAGE_MODAL_STOCK||G===R.lx.UPLOAD_BACKGROUND_MODAL_STOCK?re?(H(!0),W(3)):q("stock_images"):G===R.lx.UPLOAD_IMAGE_MODAL_GIF||G===R.lx.UPLOAD_BACKGROUND_MODAL_GIF?re?(H(!0),W(3)):q("gif"):G===R.lx.UPLOAD_IMAGE_MODAL_EDIT||G===R.lx.UPLOAD_BACKGROUND_MODAL_EDIT?(re?(H(!0),W(5)):q("editor"),b((0,c.Wz)(R.lx.IMAGE_EDITOR_MODAL))):q("my_files")}),[G,b,re,ne]);const se=(0,y.mx)((async()=>e?(e=e.pathMode?new k(e):e,new L(e)):(M(T("Error when initializing file manager")),null)),[e,M,T]),le=r.createElement(d.A,{style:{fontSize:32,margin:-16},spin:!0}),oe=(0,r.useCallback)((e=>{I.isEqual(e,ee)||te(e)}),[ee]),[ae]=(0,u.Mv)(),de=(0,r.useCallback)((async()=>{if(se){const e=ee[0];if(e){const t=e.url||e.thumbnailUrl;"img"===z?b((0,v.tm)(t)):"background"===z&&b((0,v.e_)(t))}}ie()}),[se,b,c.Oo,ee,z]),ue=(0,r.useCallback)((async e=>{if(se&&e){const t=e.url||e.thumbnailUrl;"img"===z?b((0,v.tm)(t)):"background"===z&&b((0,v.e_)(t))}ie()}),[se,b,c.Oo,z]),he=(0,r.useCallback)((async()=>{ie()}),[b,c.Oo]),[ce,{data:ve=[]}]=(0,u.gg)(),fe=(null===S||void 0===S?void 0:S.handleLimitUsageEmitter)||(0,m.ml)(O.AZ.ON_LIMIT_ID),pe=(0,r.useCallback)((async function(e){try{await ce(e).unwrap()}catch(t){}}),[ce]);return z&&se?r.createElement(r.Fragment,null,!re&&r.createElement(o.A,{className:"file-manager",closable:!0,footer:null,open:!!j&&G.includes("UPLOAD_IMAGE_"),width:"100vw",onOk:de,onCancel:ie},r.createElement(a.A,{spinning:!se,indicator:le},se&&("editor"===j?r.createElement(U.BC,{onSave:ue,onClose:he,dataProviders:se,theme:N.theme,file:X}):r.createElement(U.KG,{dataProviders:se,onChangeSelection:oe,onEditorOk:ue,config:{activeLibraryItem:j,REACT_APP_GIPHY_KEY:"Nh77eBlPeMn1ed9MBAvL542NUGeNO26F",UNSPLASH_KEY:"S5iNcLqYgRBIOLQdluHdTsCJnjCvahzhG7JfYQOrV7o",APP_NAME_UNSPLASH:"Nh77eBlPeMn1ed9MBAvL542NUGeNO26F",fileForEdit:X,projectId:E,elementId:P||D,pushToGTM:null===S||void 0===S?void 0:S.pushToGTM,handleLimitUsageEmitter:fe,sseQuery:pe,messages:ve,sendAIImageRequest:(null===S||void 0===S?void 0:S.sendAIImageRequest)||ae,locale:N.locale,theme:N.theme,customTheme:C,features:{enableRenameFile:!1!==(null===(l=S.fileManager)||void 0===l?void 0:l.enableRenameFile),enableRenameFolder:!1!==(null===(F=S.fileManager)||void 0===F?void 0:F.enableRenameFolder),enableUpdateFile:!1!==(null===(_=S.fileManager)||void 0===_?void 0:_.enableUpdateFile)}}})))),r.createElement(p.A,{open:Y,onCancel:()=>H(!1),initialSlide:Q,sideOnOk:void 0})):null}}}]);
1
+ "use strict";(globalThis.webpackChunkemail_maker=globalThis.webpackChunkemail_maker||[]).push([[57],{10653:(e,t,i)=>{i.r(t),i.d(t,{default:()=>x});var r=i(98173),n=i(2604),s=i(62272),l=i(40120),o=i(48753),a=i(98447),d=i(38826),u=i(871),h=i(47014),c=i(23424),v=i(80772),f=i(84572),p=i(48956),w=i(27941),g=i(64909),m=i(90614),y=i(73180);let I;var F;(F=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 n=0;n<r;n++)if(!i(e[n],t[n]))return!1;return!0},F.unique=function(e,t){t||(t=e=>e);const i=new Set;return e.filter((e=>{const r=t(e),n=!i.has(r);return i.add(r),n}))};var A=i(12543),O=i(15626),_=i(51213);function S(e){return null==e||""===e?"":e}function E(e){if(null==e)return 1/0;const t=Number(e);return Number.isFinite(t)&&t>=0?t:1/0}function P(e){if(!e)return"";const t=e.folderId;return null==t?"":String(t)}function D(e){return!!e&&!0===e.isFolder}function T(){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)}`}class C{constructor(){this.entities=new Map,this.childrenByParent=new Map}now(){return Date.now()}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)}getFile(e){const t=this.getEntity(e);return t&&!D(t)?t:void 0}getFolder(e){const t=this.getEntity(e);return t&&D(t)?t:void 0}getChildrenIds(e,t={}){const i=S(e),r=this.childrenByParent.get(i);return r?t.onlyFiles?Array.from(r.files):t.onlyFolders?Array.from(r.folders):[...Array.from(r.folders),...Array.from(r.files)]:[]}upsertEntity(e){var t;const i=null!==(t=this.entities.get(e.id))&&void 0!==t?t:null,r=i?i.value:null,n=r?P(r):"",s=P(e),l=!!r&&D(r),o=D(e);if(r&&(n!==s||l!==o)){const t=S(n),i=this.childrenByParent.get(t);i&&(l?i.folders.delete(e.id):i.files.delete(e.id),0===i.files.size&&0===i.folders.size&&this.childrenByParent.delete(t))}this.entities.set(e.id,{value:{...e},updatedAt:this.now()});const a=S(s);let d=this.childrenByParent.get(a);d||(d={files:new Set,folders:new Set},this.childrenByParent.set(a,d)),o?d.folders.add(e.id):d.files.add(e.id)}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,n=P(r),s=S(n),l=this.childrenByParent.get(s);return l&&(D(r)?l.folders.delete(e):l.files.delete(e),0===l.files.size&&0===l.folders.size&&this.childrenByParent.delete(s)),this.entities.delete(e),{entity:{...r},parentId:n}}deleteFolderRecursive(e){const t=this.entities.get(e);if(!t||!D(t.value))return{deletedFolderRecords:[],deletedFileRecords:[]};const i=[e],r=[],n=[];for(;i.length;){const e=i.shift();r.push(e);const t=this.childrenByParent.get(S(e));if(t){for(const e of Array.from(t.folders))i.push(e);for(const e of Array.from(t.files))n.push(e)}}const s=[];for(const o of n){const e=this.entities.get(o);if(!e)continue;const t=e.value,i=S(P(t)),r=this.childrenByParent.get(i);r&&(r.files.delete(o),0===r.files.size&&0===r.folders.size&&this.childrenByParent.delete(i)),this.entities.delete(o),s.push({...t})}const l=[];for(const o of r.reverse()){const e=this.entities.get(o);if(!e)continue;const t=e.value,i=S(t.id);this.childrenByParent.delete(i);const r=S(P(t)),n=this.childrenByParent.get(r);n&&(n.folders.delete(o),0===n.files.size&&0===n.folders.size&&this.childrenByParent.delete(r)),this.entities.delete(o),l.push({...t})}return{deletedFolderRecords:l,deletedFileRecords:s}}moveEntityById(e,t){var i;const r=null!==(i=this.entities.get(e))&&void 0!==i?i:null;if(!r)return null;const n=r.value,s=S(P(n)),l=this.childrenByParent.get(s);l&&(D(n)?l.folders.delete(e):l.files.delete(e),0===l.files.size&&0===l.folders.size&&this.childrenByParent.delete(s));const o={...n,folderId:t};this.entities.set(e,{value:o,updatedAt:this.now()});const a=S(t);let d=this.childrenByParent.get(a);return d||(d={files:new Set,folders:new Set},this.childrenByParent.set(a,d)),D(o)?d.folders.add(e):d.files.add(e),{...o}}copyFile(e,t,i){var r;const n=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!n||D(n.value))return null;const s={...n.value,id:t,folderId:i};return this.upsertEntity(s),{...s}}copyFolderShallow(e,t,i){var r;const n=null!==(r=this.entities.get(e))&&void 0!==r?r:null;if(!n||!D(n.value))return null;const s={...n.value,id:t,folderId:i};return this.upsertEntity(s),{...s}}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}))}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 C;for(const[n,s]of null!==(i=e.entities)&&void 0!==i?i:[]){var i;t.entities.set(n,{value:s.value,updatedAt:s.updatedAt})}for(const[n,s]of null!==(r=e.childrenByParent)&&void 0!==r?r:[]){var r;t.childrenByParent.set(n,{files:new Set(s.files),folders:new Set(s.folders)})}return t}}class M{constructor(e={},t=3e5,i=3e4,r){var n,s,l;this.views=new Map,this.strategy=void 0,this.ttl=void 0,this.errorTtl=void 0,this.entityTtl=void 0,this.strategy={allowSortedInsert:null===(n=e.allowSortedInsert)||void 0===n||n,allowSearchInsert:null===(s=e.allowSearchInsert)||void 0===s||s,invalidateOnPaginationFull:null===(l=e.invalidateOnPaginationFull)||void 0===l||l,comparator:e.comparator,filterMatch:e.filterMatch},this.ttl=t,this.errorTtl=i,this.entityTtl=null!==r&&void 0!==r?r:t}now(){return Date.now()}parentKey(e){return S(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){if(!e)return!0;for(const i of e)if(t.isEntityStale(i,this.entityTtl))return!0;return!1}async getOrCreateChildren(e,t,i,r){var n;const s=this.parentKey(e),l=function(e){const t=new WeakSet;try{return function e(i){return null===i?"null":"boolean"===typeof i?i?"true":"false":"number"===typeof i?Number.isNaN(i)?"NaN":i===1/0?"Infinity":i===-1/0?"-Infinity":Object.is(i,-0)?"-0":String(i):"string"===typeof i?JSON.stringify(i):"undefined"===typeof i?"undefined":"symbol"===typeof i?String(i.toString()):"function"===typeof i?'"[function]"':i instanceof Date?`"Date(${i.toISOString()})"`:i instanceof RegExp?`"RegExp(${i.toString()})"`:"object"===typeof i?t.has(i)?'"[Circular]"':(t.add(i),i instanceof Map?`{Map:${Array.from(i.entries()).map((([t,i])=>`[${e(t)}:${e(i)}]`)).join(",")}}`:i instanceof Set?`{Set:${Array.from(i.values()).map((t=>e(t))).join(",")}}`:Array.isArray(i)?`[${i.map((t=>e(t))).join(",")}]`:`{${Object.entries(i).sort((([e],[t])=>e.localeCompare(t))).map((([t,i])=>`${JSON.stringify(t)}:${e(i)}`)).join(",")}}`):JSON.stringify(String(i))}(e)}catch(i){try{return JSON.stringify(e)}catch{return String(e)}}}(null!==t&&void 0!==t?t:{});let o=this.views.get(s);o||(o=new Map,this.views.set(s,o));let a=o.get(l);if(!a){a={params:t,view:{promise:null,value:void 0,meta:void 0,error:void 0,updatedAt:0}},o.set(l,a)}if(a.view.error&&!this.isErrorExpired(a.view.updatedAt))throw a.view.error;if(a.view.value&&!this.isExpired(a.view.updatedAt)&&!this.areEntitiesStale(a.view.value,r)&&(null===(n=a.view.meta)||void 0===n||!n.stale)){var d;return{items:a.view.value.map((e=>r.getEntity(e))).filter(Boolean),...null!==(d=a.view.meta)&&void 0!==d?d:{}}}return a.view.promise||(a.view.promise=(async()=>{try{const n=await i(e,t);for(const e of n.items)r.upsertEntity(e);a.view.value=n.items.map((e=>e.id));const{items:s,...l}=n,o={...l};return"number"!==typeof o.total&&(o.total=Number(o.total)||(a.view.value?a.view.value.length:0)),a.view.meta=o,a.view.error=null,a.view.updatedAt=this.now(),n}catch(n){throw a.view.error=n,a.view.value=void 0,a.view.updatedAt=this.now(),n}finally{a.view.promise=null}})()),a.view.promise}tryInsertSorted(e,t,i){const r=this.strategy.comparator;if(!r)return!1;if(!e.view.value)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),o=r(t,n[i],e.params);if("number"!==typeof o||Number.isNaN(o))return!1;o>=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)}smartInvalidateChildrenViews(e,t,i,r,n,s){const l=this.parentKey(null!==e&&void 0!==e?e:null),o=this.views.get(l);if(o)for(const[,c]of o){var a,d;const e=null!==(a=c.params)&&void 0!==a?a:{},o=null!==(d=null===e||void 0===e?void 0:e.page)&&void 0!==d?d:1,v=E(null===e||void 0===e?void 0:e.pageSize),f=Number.isFinite(v),p=!!(null!==e&&void 0!==e&&e.sortBy||null!==e&&void 0!==e&&e.sortOrder),w=["page","pageSize","sortBy","sortOrder","search"].some((t=>null===e||void 0===e?void 0:e[t]));if(!c.view.value){var u;c.view.meta={...null!==(u=c.view.meta)&&void 0!==u?u:{},stale:!0};continue}const g=()=>{c.view.meta||(c.view.meta={}),c.view.meta.total=c.view.value.length};if("delete"===i&&t){const e=c.view.value.length;c.view.value.includes(t.id)&&(c.view.value=c.view.value.filter((e=>e!==t.id)),g(),f&&e===v&&(c.view.meta.stale=!0),c.view.updatedAt=Date.now())}else if("insert"!==i&&"copy"!==i&&"update"!==i||!t)if("move"===i&&t){var h;const e=this.parentKey(null!==n&&void 0!==n?n:null),i=this.parentKey(null!==(h=t.folderId)&&void 0!==h?h:null);if(l===e&&c.view.value.includes(t.id)){const e=c.view.value.length;c.view.value=c.view.value.filter((e=>e!==t.id)),g(),f&&e===v&&(c.view.meta.stale=!0),c.view.updatedAt=Date.now()}if(l===i){if(f&&o>1){c.view.meta.stale=!0;continue}if(w&&this.strategy.filterMatch&&!this.strategy.filterMatch(t,c.params))continue;let e=!1;p&&this.strategy.allowSortedInsert&&this.strategy.comparator&&r&&(e=this.tryInsertSorted(c,t,r)),!e&&c.view.value.length<v?c.view.value.push(t.id):e||(c.view.meta.stale=!0),g(),c.view.updatedAt=Date.now()}}else;else{let e=c.view.value.includes(t.id);const n=!!this.strategy.comparator,l=!!s&&(n||Object.keys(t).some((e=>s[e]!==t[e])));let o=i;if((e||l)&&(o="update"),w&&this.strategy.filterMatch&&!this.strategy.filterMatch(t,c.params)){e&&(c.view.value=c.view.value.filter((e=>e!==t.id)),g(),c.view.updatedAt=Date.now());continue}if("update"===o){if(!p&&!w){c.view.updatedAt=Date.now(),g();continue}c.view.value=c.view.value.filter((e=>e!==t.id)),e=!1}let a=!1;!e&&p&&this.strategy.allowSortedInsert&&this.strategy.comparator&&r&&(a=this.tryInsertSorted(c,t,r)),e||a||(!f||c.view.value.length<v?c.view.value.push(t.id):c.view.meta.stale=!0),g(),c.view.updatedAt=Date.now()}}}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}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}}}static fromJSON(e,t){var i,r,n;const s=new M(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,null!==(n=null===e||void 0===e?void 0:e.entityTtl)&&void 0!==n?n:void 0);for(const[v,f]of null!==(l=null===e||void 0===e?void 0:e.views)&&void 0!==l?l:[]){var l;const e=new Map;for(const[t,i]of f){var o,a,d,u,h,c;const r=null!==(o=i.params)&&void 0!==o?o:{},n=null!==(a=i.view)&&void 0!==a?a:{},s={promise:null,value:null!==(d=n.value)&&void 0!==d?d:void 0,meta:null!==(u=n.meta)&&void 0!==u?u:void 0,error:null!==(h=n.error)&&void 0!==h?h:null,updatedAt:null!==(c=n.updatedAt)&&void 0!==c?c:0};e.set(t,{params:r,view:s})}s.views.set(v,e)}return s}}class b{constructor(e={},t=3e5,i=3e4){this.entities=void 0,this.views=void 0,this.ttl=void 0,this.errorTtl=void 0,this.ttl=t,this.errorTtl=i,this.entities=new C,this.views=new M(e,t,i)}getEntity(e){return this.entities.getEntity(e)}getFile(e){return this.entities.getFile(e)}getFolder(e){return this.entities.getFolder(e)}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?P(t):"",r=P(e),n=t?D(t):"",s=D(e);if(this.entities.upsertEntity(e),t){if(i!==r||n!==s)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;for(;i;){if(i===e)return!0;const t=this.entities.getEntity(i);if(!t)break;i=P(t)}return!1}moveEntity(e,t){const i=this.entities.getEntity(e);if(!i)return null;if(D(i)&&null!==t&&this.isAncestor(e,t))return null;const r=P(i),n=this.entities.moveEntityById(e,t);return n?(this.views.smartInvalidateChildrenViews(r,i,"delete",this.entities),this.views.smartInvalidateChildrenViews(t,n,"insert",this.entities),n):null}copyEntity(e,t,i){var r;const n=this.entities.getEntity(e);if(!n)return null;if(!D(n)){const r=null!==i&&void 0!==i?i:T(),n=this.entities.copyFile(e,r,null!==t&&void 0!==t?t:null);return n?(this.views.smartInvalidateChildrenViews(t,n,"copy",this.entities),r):null}const s=[e],l=[];for(;s.length;){const e=s.shift();l.push(e);const t=this.entities.getChildrenIds(e,{onlyFolders:!0});for(const i of t)s.push(i)}const o=new Map;for(const u of l)o.set(u,T());for(const u of l){var a,d;const e=this.entities.getFolder(u),i=o.get(u),r=P(e),n=null===r?t:null!==(a=o.get(r))&&void 0!==a?a:null,s={...e,id:i,folderId:n};this.entities.upsertEntity(s),this.views.smartInvalidateChildrenViews(null!==(d=s.folderId)&&void 0!==d?d:null,s,"copy",this.entities)}for(const u of l){const e=o.get(u),t=this.entities.getChildrenIds(u,{onlyFiles:!0});for(const i of t){const t=this.entities.getFile(i);if(!t)continue;const r=T(),n={...t,id:r,folderId:e};this.entities.upsertEntity(n),this.views.smartInvalidateChildrenViews(e,n,"copy",this.entities)}}return null!==(r=o.get(e))&&void 0!==r?r:null}deleteEntity(e){const t=this.entities.getEntity(e);if(!t)return null;if(D(t)){const{deletedFolderRecords:i,deletedFileRecords: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);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,deletedFileRecords: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);return{deletedFileIds: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(D(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)}toJSON(){return{entities:this.entities.toJSON(),views:this.views.toJSON(),ttl:this.ttl,errorTtl:this.errorTtl}}static fromJSON(e,t){var i,r,n,s;const l=new b(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),o=C.fromJSON(null!==(n=null===e||void 0===e?void 0:e.entities)&&void 0!==n?n:{}),a=M.fromJSON(null!==(s=null===e||void 0===e?void 0:e.views)&&void 0!==s?s:{},null!==t&&void 0!==t?t:{});return l.entities=o,l.views=a,l}}var B;function N(e){return null!==e&&void 0!==e?e:""}let L=(0,_.A)(B=class{constructor(e,t={}){var i,r;this._dataProvider=e,this.options=t,this._cache=void 0,this.ROOT_ID="",this._cache=new b(t.cacheStrategy||{},null===(i=t.cacheStrategy)||void 0===i?void 0:i.ttl,null===(r=t.cacheStrategy)||void 0===r?void 0:r.errorTtl)}async getFiles({folderId:e,search:t,sortBy:i,sortOrder:r,page:n,limit:s,itemType:l="all"}){const o=N(null!==e&&void 0!==e?e:this.ROOT_ID);"folder"!==l&&(i??="date",r??="desc");const a=this.options.clientSideFilter||this.options.clientSideSorting||this.options.clientSidePaging?{folderId:o,itemType:l}:{folderId:o,page:n,pageSize:s,itemType:l};let d=(await this._cache.getOrCreateChildren(o,a,(async()=>{const e=await this._dataProvider.getFiles({folderId:o,search:t,sortBy:i,sortOrder:r,page:n,limit:s,itemType:l});return{items:e.files,...e.pagination}}))).items;if(this.options.clientSideFilter)if("function"===typeof this.options.clientSideFilter)d=this.options.clientSideFilter(d,t);else if(t){const e=t.toLowerCase();d=d.filter((t=>{var i;return null===(i=t.name)||void 0===i?void 0:i.toLowerCase().includes(e)}))}this.options.clientSideSorting&&(d="function"===typeof this.options.clientSideSorting?this.options.clientSideSorting(d,i,r):d.sort(((e,t)=>(e.name||"").localeCompare(t.name||""))));const u=d.length;if(this.options.clientSidePaging)if("function"===typeof this.options.clientSidePaging)d=this.options.clientSidePaging(d,n,s);else{const e=(n-1)*s,t=e+s;d=d.slice(e,t)}return{files:d,pagination:{page:n,limit:s,total:u}}}async getFileData(e){if(this._dataProvider.getFileData)return this._dataProvider.getFileData(e);if(!e.url)throw new Error("Cannot read file");return(await fetch(e.url)).blob()}async uploadFile(e){var t;const i=N(null!==(t=e.folderId)&&void 0!==t?t:this.ROOT_ID),r=await this._dataProvider.uploadFile({...e,folderId:i});return this._cache.upsertEntity({...r,folderId:i}),r}async deleteFile(e){const t=await this._dataProvider.deleteFile(e);return t&&this._cache.deleteEntity(e),t}async createFolder({name:e,parentId:t}){const i=N(null!==t&&void 0!==t?t:this.ROOT_ID),r=await this._dataProvider.createFolder({name:e,parentId:i});return this._cache.upsertEntity({id:r.id,folderId:i,name:r.name,isFolder:!0}),r}async deleteFolder(e){const t=await this._dataProvider.deleteFolder(e);return t&&this._cache.deleteFolderRecursive(e),t}async renameFolder(e,t){if(!this._dataProvider.renameFolder)throw new Error("Rename folder is not supported");const i=await this._dataProvider.renameFolder(e,t);return i&&this._cache.upsertEntity({id:i.id,folderId:N(i.parentId),name:i.name,isFolder:!0}),i}async renameFile(e,t){if(!this._dataProvider.renameFile)throw new Error("Rename file is not supported");const i=await this._dataProvider.renameFile(e,t);return i&&this._cache.upsertEntity({...i,folderId:N(i.folderId)}),i}async moveItem({itemId:e,targetFolderId:t,isFolder:i}){const r=N(t),n=await this._dataProvider.moveItem({itemId:e,targetFolderId:r,isFolder:i});return n&&this._cache.moveEntity(e,r),n}async copyItem({itemId:e,targetFolderId:t,isFolder:i}){if(!this._dataProvider.copyItem)throw new Error("Copy item is not supported");const r=N(t),n=await this._dataProvider.copyItem({itemId:e,targetFolderId:r,isFolder:i});return n&&this._cache.copyEntity(e,r),n}async uploadFileByUrl(e){var t;const i=N(null!==(t=e.folderId)&&void 0!==t?t:this.ROOT_ID),r=await this._dataProvider.uploadFileByUrl({...e,folderId:i});return this._cache.upsertEntity({...r,folderId:i}),r}async updateFile(e,t){if(!this._dataProvider.updateFile)throw new Error("Update file is not supported");const i=await this._dataProvider.updateFile(e,t);return i&&this._cache.upsertEntity({...i,folderId:N(i.folderId)}),i}})||B;var U=i(85954),R=i(32947),G=(i(51731),i(82900));class k{constructor(e){this.inner=e,this.pathToId=new Map,this.idToPath=new Map}getOrGenerateId(e){const t=e.replace(/^\/+|\/+$/g,"");if(!this.pathToId.has(t)){const e=(0,G.A)();this.pathToId.set(t,e),this.idToPath.set(e,t)}return this.pathToId.get(t)}pathForId(e){const t=this.idToPath.get(e);if(!t)throw new Error(`Path not found for ID: ${e}`);return t}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 getFiles(e){const t=e.folderId?this.pathForId(e.folderId):void 0,i=await this.inner.getFiles({...e,folderId:t}),r=i.files.map((e=>{const t=this.getOrGenerateId(e.id),i=e.folderId?this.getOrGenerateId(e.folderId):void 0;return{...e,id:t,folderId:i}}));return{...i,files:r}}async createFolder(e){const t=e.parentId?this.pathForId(e.parentId):void 0,i=await this.inner.createFolder({...e,parentId:t}),r=this.getOrGenerateId(i.id),n=i.parentId?this.getOrGenerateId(i.parentId):void 0;return{...i,id:r,parentId:n}}async renameFolder(e,t){const i=this.pathForId(e),r=await this.inner.renameFolder(i,t);this.updateIdMapping(e,r.id);const n=r.parentId?this.getOrGenerateId(r.parentId):void 0;return{...r,id:e,parentId:n}}async deleteFolder(e){const t=this.pathForId(e),i=await this.inner.deleteFolder(t);if(i){const t=this.idToPath.get(e);t&&(this.pathToId.delete(t),this.idToPath.delete(e))}return i}async uploadFile(e){const t=e.folderId?this.pathForId(e.folderId):void 0,i=await this.inner.uploadFile({...e,folderId:t}),r=this.getOrGenerateId(i.id),n=i.folderId?this.getOrGenerateId(i.folderId):void 0;return{...i,id:r,folderId:n}}async uploadFileByUrl(e){const t=e.folderId?this.pathForId(e.folderId):void 0,i=await this.inner.uploadFileByUrl({...e,folderId:t}),r=this.getOrGenerateId(i.id),n=i.folderId?this.getOrGenerateId(i.folderId):void 0;return{...i,id:r,folderId:n}}async deleteFile(e){const t=this.pathForId(e),i=await this.inner.deleteFile(t);if(i){const t=this.idToPath.get(e);t&&(this.pathToId.delete(t),this.idToPath.delete(e))}return i}async renameFile(e,t){const i=this.pathForId(e),r=await this.inner.renameFile(i,t);this.updateIdMapping(e,r.id);const n=r.folderId?this.getOrGenerateId(r.folderId):void 0;return{...r,id:e,folderId:n}}async moveItem({itemId:e,targetFolderId:t,isFolder:i}){const r=this.pathForId(e),n=this.pathForId(t),s=await this.inner.moveItem({itemId:r,targetFolderId:n,isFolder:i});return s&&this.updateIdMapping(e,`${n}/${e}`),s}async copyItem({itemId:e,targetFolderId:t,isFolder:i}){const r=this.pathForId(e),n=this.pathForId(t),s=await this.inner.copyItem({itemId:r,targetFolderId:n,isFolder:i});return s.id=this.getOrGenerateId(s.id),s}async updateFile(e,t){const i=this.pathForId(e),r=await this.inner.updateFile(i,t);this.updateIdMapping(e,r.id);const n=r.folderId?this.getOrGenerateId(r.folderId):void 0;return{...r,id:e,folderId:n}}async getFileData(e){const t=this.pathForId(e.id);return this.inner.getFileData?this.inner.getFileData({...e,id:t}):fetch(e.id).then((e=>e.blob()))}}const{useToken:V}=l.A,x=({storageProvider:e})=>{var t,i,l,F,_,S;const E=(0,w.rD)(),{projectId:P,emailId:D,blockId:T}=(0,s.g)(),{__:C}=(0,A.s9)(),{token:M}=V(),{error:b}=(0,g.hN)(),B=(0,n.wA)(),N=(0,n.d4)(h.B$),G=(0,n.d4)(h.C1),x=(0,n.d4)(c.cL),$=(0,n.d4)(v.Ac),K=(0,n.d4)(f.yN),z=(0,n.d4)(v.js),[J,j]=(0,r.useState)(""),[q,Y]=(0,r.useState)("my_files"),[H,Q]=(0,r.useState)(!1),[W,X]=(0,r.useState)(0),[Z,ee]=(0,r.useState)(""),[te,ie]=(0,r.useState)((()=>[])),re=()=>{B((0,c.Oo)()),setTimeout((()=>j("")),600)};let ne=!(N||(null===(t=G.id)||void 0===t?void 0:t.toString())!==(null===K||void 0===K||null===(i=K.members)||void 0===i?void 0:i.owner.ID))&&!0;const se=(0,r.useMemo)((()=>({img:z,background:$})),[z,$]);(0,r.useEffect)((()=>{x.includes("UPLOAD_BACKGROUND_MODAL")?(j("background"),se.background&&ee(se.background)):x.includes("UPLOAD_IMAGE_MODAL")&&(j("img"),se.img&&ee(se.img)),x===R.lx.UPLOAD_IMAGE_MODAL||x===R.lx.UPLOAD_BACKGROUND_MODAL?Y("editor"):x===R.lx.UPLOAD_IMAGE_MODAL_AI||x===R.lx.UPLOAD_BACKGROUND_MODAL_AI?ne?(Q(!0),X(2)):Y("ai"):x===R.lx.UPLOAD_IMAGE_MODAL_UPLOAD||x===R.lx.UPLOAD_BACKGROUND_MODAL_UPLOAD?Y("my_files"):x===R.lx.UPLOAD_IMAGE_MODAL_STOCK||x===R.lx.UPLOAD_BACKGROUND_MODAL_STOCK?ne?(Q(!0),X(3)):Y("stock_images"):x===R.lx.UPLOAD_IMAGE_MODAL_GIF||x===R.lx.UPLOAD_BACKGROUND_MODAL_GIF?ne?(Q(!0),X(3)):Y("gif"):x===R.lx.UPLOAD_IMAGE_MODAL_EDIT||x===R.lx.UPLOAD_BACKGROUND_MODAL_EDIT?(ne?(Q(!0),X(5)):Y("editor"),B((0,c.Wz)(R.lx.IMAGE_EDITOR_MODAL))):Y("my_files")}),[x,B,ne,se]);const le=(0,y.mx)((async()=>e?(e=e.pathMode?new k(e):e,new L(e)):(b(C("Error when initializing file manager")),null)),[e,b,C]),oe=r.createElement(d.A,{style:{fontSize:32,margin:-16},spin:!0}),ae=(0,r.useCallback)((e=>{I.isEqual(e,te)||ie(e)}),[te]),[de]=(0,u.Mv)(),ue=(0,r.useCallback)((async()=>{if(le){const e=te[0];if(e){const t=e.url||e.thumbnailUrl;"img"===J?B((0,v.tm)(t)):"background"===J&&B((0,v.e_)(t))}}re()}),[le,B,c.Oo,te,J]),he=(0,r.useCallback)((async e=>{if(le&&e){const t=e.url||e.thumbnailUrl;"img"===J?B((0,v.tm)(t)):"background"===J&&B((0,v.e_)(t))}re()}),[le,B,c.Oo,J]),ce=(0,r.useCallback)((async()=>{re()}),[B,c.Oo]),[ve,{data:fe=[]}]=(0,u.gg)(),pe=(null===E||void 0===E?void 0:E.handleLimitUsageEmitter)||(0,m.ml)(O.AZ.ON_LIMIT_ID),we=(0,r.useCallback)((async function(e){try{await ve(e).unwrap()}catch(t){}}),[ve]);return J&&le?r.createElement(r.Fragment,null,!ne&&r.createElement(o.A,{className:"file-manager",closable:!0,footer:null,open:!!q&&x.includes("UPLOAD_IMAGE_"),width:"100vw",onOk:ue,onCancel:re},r.createElement(a.A,{spinning:!le,indicator:oe},le&&("editor"===q?r.createElement(U.BC,{onSave:he,onClose:ce,dataProviders:le,theme:G.theme,file:Z}):r.createElement(U.KG,{dataProviders:le,onChangeSelection:ae,onEditorOk:he,config:{activeLibraryItem:q,REACT_APP_GIPHY_KEY:"Nh77eBlPeMn1ed9MBAvL542NUGeNO26F",UNSPLASH_KEY:"S5iNcLqYgRBIOLQdluHdTsCJnjCvahzhG7JfYQOrV7o",APP_NAME_UNSPLASH:"Nh77eBlPeMn1ed9MBAvL542NUGeNO26F",fileForEdit:Z,projectId:P,elementId:D||T,pushToGTM:null===E||void 0===E?void 0:E.pushToGTM,handleLimitUsageEmitter:pe,sseQuery:we,messages:fe,sendAIImageRequest:(null===E||void 0===E?void 0:E.sendAIImageRequest)||de,locale:G.locale,theme:G.theme,customTheme:M,features:{enableRenameFile:!1!==(null===(l=E.fileManager)||void 0===l?void 0:l.enableRenameFile),enableRenameFolder:!1!==(null===(F=E.fileManager)||void 0===F?void 0:F.enableRenameFolder),enableUpdateFile:!1!==(null===(_=E.fileManager)||void 0===_?void 0:_.enableUpdateFile)},disablePagination:!1===(null===(S=E.fileManager)||void 0===S?void 0:S.enablePagination)}})))),r.createElement(p.A,{open:H,onCancel:()=>Q(!1),initialSlide:W,sideOnOk:void 0})):null}}}]);