sanity-plugin-media 2.0.3 → 2.0.5

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/lib/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";const e=["onValueChange","value"];var t,n,a,i,s,o,l,r,d,c,u,p,h,m,g,f,x,y,v,b,j,I,C,w,T,k,S,_,E,M,R,B,F,z,D,A,O,q,L,P,U;function V(e,t){if(null==e)return{};var n,a,i=function(e,t){if(null==e)return{};var n,a,i={},s=Object.keys(e);for(a=0;a<s.length;a++)n=s[a],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(a=0;a<s.length;a++)n=s[a],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function N(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function Q(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?N(Object(n),!0).forEach((function(t){X(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):N(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function X(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function H(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}Object.defineProperty(exports,"__esModule",{value:!0});var Y=require("sanity"),G=require("@sanity/icons"),W=require("react/jsx-runtime"),$=require("@sanity/ui"),K=require("react"),Z=require("is-hotkey"),J=require("groq"),ee=require("react-redux"),te=require("@reduxjs/toolkit"),ne=require("nanoid"),ae=require("redux-observable"),ie=require("rxjs"),se=require("rxjs/operators"),oe=require("@sanity/color"),le=require("styled-components"),re=require("pluralize"),de=require("@tanem/react-nprogress"),ce=require("react-select"),ue=require("react-virtuoso"),pe=require("@hookform/resolvers/yup"),he=require("react-hook-form"),me=require("yup"),ge=require("date-fns/format"),fe=require("filesize"),xe=require("copy-to-clipboard"),ye=require("sanity/router"),ve=require("react-file-icon"),be=require("react-select/creatable"),je=require("date-fns/formatRelative"),Ie=require("react-dropzone");function Ce(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function we(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var Te=Ce(Z),ke=Ce(J),Se=Ce(le),_e=Ce(re),Ee=Ce(ce),Me=we(me),Re=Ce(ge),Be=Ce(fe),Fe=Ce(xe),ze=Ce(be),De=Ce(je);const Ae=(e,t)=>{const n=K.useRef(!1);function a(a){Te.default(e,a)&&(n.current=!0,t&&t())}const i=()=>{n.current=!1};return K.useEffect((()=>(window.addEventListener("keydown",a),window.addEventListener("keyup",i),()=>{window.removeEventListener("keydown",a),window.removeEventListener("keyup",i)})),[]),n},Oe={type:"divider"},qe={altText:{assetTypes:["file","image"],field:"altText",name:"altText",operatorType:"empty",operatorTypes:["empty","notEmpty",null,"includes","doesNotInclude"],title:"Alt text",type:"string",value:""},description:{assetTypes:["file","image"],field:"description",name:"description",operatorType:"empty",operatorTypes:["empty","notEmpty",null,"includes","doesNotInclude"],title:"Description",type:"string",value:""},fileName:{assetTypes:["file","image"],field:"originalFilename",name:"filename",operatorType:"includes",operatorTypes:["includes","doesNotInclude"],title:"File name",type:"string",value:""},height:{assetTypes:["image"],field:"metadata.dimensions.height",name:"height",operatorType:"greaterThan",operatorTypes:["greaterThan","greaterThanOrEqualTo","lessThan","lessThanOrEqualTo",null,"equalTo"],title:"Height",type:"number",value:400},inCurrentDocument:{assetTypes:["file","image"],name:"inCurrentDocument",operatorType:"is",options:[{name:"true",title:"True",value:ke.default(t||(t=H(["_id in $documentAssetIds"])))},{name:"false",title:"False",value:ke.default(n||(n=H(["!(_id in $documentAssetIds)"])))}],selectOnly:!0,title:"In use in current document",type:"select",value:"true"},inUse:{assetTypes:["file","image"],name:"inUse",operatorType:"is",options:[{name:"true",title:"True",value:ke.default(a||(a=H(["count(*[references(^._id)]) > 0"])))},{name:"false",title:"False",value:ke.default(i||(i=H(["count(*[references(^._id)]) == 0"])))}],title:"In use",type:"select",value:"true"},isOpaque:{assetTypes:["image"],field:"metadata.isOpaque",name:"isOpaque",operatorType:"equalTo",options:[{name:"true",title:"True",value:"false"},{name:"false",title:"False",value:"true"}],title:"Has transparency",type:"select",value:"true"},orientation:{assetTypes:["image"],name:"orientation",operatorType:"is",operatorTypes:["is","isNot"],options:[{name:"portrait",title:"Portrait",value:"metadata.dimensions.aspectRatio < 1"},{name:"landscape",title:"Landscape",value:"metadata.dimensions.aspectRatio > 1"},{name:"square",title:"Square",value:"metadata.dimensions.aspectRatio == 1"}],title:"Orientation",type:"select",value:"portrait"},size:{assetTypes:["file","image"],field:"size",modifier:"kb",modifiers:[{name:"kb",title:"KB",fieldModifier:e=>"round(".concat(e," / 1000)")},{name:"mb",title:"MB",fieldModifier:e=>"round(".concat(e," / 1000000)")}],name:"size",operatorType:"greaterThan",operatorTypes:["greaterThan","greaterThanOrEqualTo","lessThan","lessThanOrEqualTo",null,"equalTo"],title:"File size",type:"number",value:0},tag:{assetTypes:["file","image"],field:"opt.media.tags",name:"tag",operatorType:"references",operatorTypes:["references","doesNotReference",null,"empty","notEmpty"],title:"Tags",type:"searchable"},title:{assetTypes:["file","image"],field:"title",name:"title",operatorType:"empty",operatorTypes:["empty","notEmpty",null,"includes","doesNotInclude"],title:"Title",type:"string",value:""},type:{assetTypes:["file","image"],name:"type",operatorType:"is",operatorTypes:["is","isNot"],options:[{name:"image",title:"Image",value:'mimeType match "image*"'},{name:"video",title:"Video",value:'mimeType match "video*"'},{name:"audio",title:"Audio",value:'mimeType match "audio*"'},{name:"pdf",title:"PDF",value:'mimeType == "application/pdf"'}],title:"File type",type:"select",value:"image"},width:{assetTypes:["image"],field:"metadata.dimensions.width",name:"width",operatorType:"greaterThan",operatorTypes:["greaterThan","greaterThanOrEqualTo","lessThan","lessThanOrEqualTo",null,"equalTo"],title:"Width",type:"number",value:400}},Le={doesNotInclude:{fn:(e,t)=>e?"!(".concat(t," match '*").concat(e,"*')"):void 0,label:"does not include"},doesNotReference:{fn:(e,t)=>e?"!references('".concat(e,"')"):void 0,label:"does not include"},empty:{fn:(e,t)=>"!defined(".concat(t,")"),hideInput:!0,label:"is empty"},equalTo:{fn:(e,t)=>e?"".concat(t," == ").concat(e):void 0,label:"is equal to"},greaterThan:{fn:(e,t)=>e?"".concat(t," > ").concat(e):void 0,label:"is greater than"},greaterThanOrEqualTo:{fn:(e,t)=>e?"".concat(t," >= ").concat(e):void 0,label:"is greater than or equal to"},includes:{fn:(e,t)=>e?"".concat(t," match '*").concat(e,"*'"):void 0,label:"includes"},is:{fn:(e,t)=>"".concat(e),label:"is"},isNot:{fn:(e,t)=>"!(".concat(e,")"),label:"is not"},lessThan:{fn:(e,t)=>e?"".concat(t," < ").concat(e):void 0,label:"is less than"},lessThanOrEqualTo:{fn:(e,t)=>e?"".concat(t," <= ").concat(e):void 0,label:"is less than or equal to"},notEmpty:{fn:(e,t)=>"defined(".concat(t,")"),hideInput:!0,label:"is not empty"},references:{fn:(e,t)=>e?"references('".concat(e,"')"):void 0,label:"includes"}},Pe=[{direction:"desc",field:"_createdAt"},{direction:"asc",field:"_createdAt"},null,{direction:"desc",field:"_updatedAt"},{direction:"asc",field:"_updatedAt"},null,{direction:"asc",field:"originalFilename"},{direction:"desc",field:"originalFilename"},null,{direction:"desc",field:"size"},{direction:"asc",field:"size"}],Ue=[qe.tag,Oe,qe.inUse,qe.inCurrentDocument,Oe,qe.title,qe.altText,qe.description,Oe,qe.isOpaque,Oe,qe.fileName,qe.size,qe.type,Oe,qe.orientation,qe.width,qe.height],Ve="3rem 100px auto 1.5rem",Ne="3rem 100px auto 5.5rem 5.5rem 3.5rem 8.5rem 2rem",Qe=K.createContext(void 0),Xe=e=>{const{children:t,onSelect:n}=e,a={onSelect:n};return W.jsx(Qe.Provider,{value:a,children:t})},He=()=>{const e=K.useContext(Qe);if(void 0===e)throw new Error("useAssetSourceActions must be used within an AssetSourceDispatchProvider");return e},Ye=()=>Y.useClient({apiVersion:"2022-10-01"}),Ge={_createdAt:{asc:"Last created: Oldest first",desc:"Last created: Newest first"},_updatedAt:{asc:"Last updated: Oldest first",desc:"Last updated: Newest first"},mimeType:{asc:"MIME type: A to Z",desc:"MIME type: Z to A"},originalFilename:{asc:"File name: A to Z",desc:"File name: Z to A"},size:{asc:"File size: Smallest first",desc:"File size: Largest first"}},We=(e,t)=>Ge[e][t],$e=e=>function(t){return ie.iif((()=>!!e),t.pipe(se.delay(3e3),se.mergeMap((e=>Math.random()>.5?ie.throwError({message:"Test error",statusCode:500}):ie.of(e)))),t)},Ke=e=>{let{assetTypes:t,searchFacets:n,searchQuery:a}=e;const i=t.map((e=>"sanity.".concat(e,"Asset"))),l=ke.default(s||(s=H(["\n _type in ",' && !(_id in path("drafts.**"))\n '])),JSON.stringify(i)),r=n.reduce(((e,t)=>{var n;if("number"===t.type){const{field:n,modifier:a,modifiers:i,operatorType:s,value:o}=t,l=Le[s],r=null==i?void 0:i.find((e=>e.name===a)),d=(null==r?void 0:r.fieldModifier)?r.fieldModifier(n):n,c=l.fn(o,d);c&&e.push(c)}if("searchable"===t.type){const{field:n,operatorType:a,value:i}=t,s=Le[a].fn(null==i?void 0:i.value,n);s&&e.push(s)}if("select"===t.type){const{field:a,operatorType:i,options:s,value:o}=t,l=Le[i],r=null==(n=null==s?void 0:s.find((e=>e.name===o)))?void 0:n.value,d=l.fn(r,a);d&&e.push(d)}if("string"===t.type){const{field:n,operatorType:a,value:i}=t,s=Le[a].fn(i,n);s&&e.push(s)}return e}),[]);return[l,...a?[ke.default(o||(o=H(["[_id, altText, assetId, description, originalFilename, title, url] match '*","*'"])),a.trim())]:[],...r].join(" && ")},Ze=(e,t)=>function(n){return n.pipe(se.mergeMap((()=>ie.from(e.fetch(ke.default(l||(l=H(['count(*[_type == "','" && name.current == $name])'])),"media.tag"),{name:t})))),se.mergeMap((e=>e>0?ie.throwError({message:"Tag already exists",statusCode:409}):ie.of(!0))))},Je=e=>e.reduce(((e,t)=>{var n;const a=null==t?void 0:t.tag;return a&&e.push({label:null==(n=null==a?void 0:a.name)?void 0:n.current,value:null==a?void 0:a._id}),e}),[]),et={tagsAddComplete:te.createAction("actions/tagsAddComplete",(function(e){let{assets:t,tag:n}=e;return{payload:{assets:t,tag:n}}})),tagsAddError:te.createAction("actions/tagsAddError",(function(e){let{assets:t,error:n,tag:a}=e;return{payload:{assets:t,error:n,tag:a}}})),tagsAddRequest:te.createAction("actions/tagsAddRequest",(function(e){let{assets:t,tag:n}=e;return{payload:{assets:t,tag:n}}})),tagsRemoveComplete:te.createAction("actions/tagsRemoveComplete",(function(e){let{assets:t,tag:n}=e;return{payload:{assets:t,tag:n}}})),tagsRemoveError:te.createAction("actions/tagsRemoveError",(function(e){let{assets:t,error:n,tag:a}=e;return{payload:{assets:t,error:n,tag:a}}})),tagsRemoveRequest:te.createAction("actions/tagsRemoveRequest",(function(e){let{assets:t,tag:n}=e;return{payload:{assets:t,tag:n}}}))},tt={showTagCreate:te.createAction("dialog/showTagCreate"),showTagEdit:te.createAction("dialog/showTagEdit",(function(e){let{tagId:t}=e;return{payload:{tagId:t}}}))},nt=te.createSlice({name:"tags",initialState:{allIds:[],byIds:{},creating:!1,creatingError:void 0,fetchCount:-1,fetching:!1,fetchingError:void 0,panelVisible:!0},extraReducers:e=>{e.addCase(tt.showTagCreate,(e=>{delete e.creatingError})).addCase(tt.showTagEdit,((e,t)=>{const{tagId:n}=t.payload;delete e.byIds[n].error})).addMatcher((e=>[et.tagsAddComplete.type,et.tagsAddError.type,et.tagsRemoveComplete.type,et.tagsRemoveError.type].includes(e.type)),((e,t)=>{const{tag:n}=t.payload;e.byIds[n._id].updating=!1})).addMatcher((e=>[et.tagsAddRequest.type,et.tagsRemoveRequest.type].includes(e.type)),((e,t)=>{const{tag:n}=t.payload;e.byIds[n._id].updating=!0}))},reducers:{createComplete(e,t){const{tag:n}=t.payload;e.creating=!1,e.allIds.includes(n._id)||e.allIds.push(n._id),e.byIds[n._id]={_type:"tag",picked:!1,tag:n,updating:!1}},createError(e,t){e.creating=!1,e.creatingError=t.payload.error},createRequest(e,t){e.creating=!0,delete e.creatingError},deleteComplete(e,t){const{tagId:n}=t.payload,a=e.allIds.indexOf(n);a>=0&&e.allIds.splice(a,1),delete e.byIds[n]},deleteError(e,t){const{error:n,tag:a}=t.payload,i=null==a?void 0:a._id;e.byIds[i].error=n,e.byIds[i].updating=!1},deleteRequest(e,t){var n,a;const i=null==(a=null==(n=t.payload)?void 0:n.tag)?void 0:a._id;e.byIds[i].picked=!1,e.byIds[i].updating=!0,Object.keys(e.byIds).forEach((t=>{delete e.byIds[t].error}))},fetchComplete(e,t){const{tags:n}=t.payload;null==n||n.forEach((t=>{e.allIds.push(t._id),e.byIds[t._id]={_type:"tag",picked:!1,tag:t,updating:!1}})),e.fetching=!1,e.fetchCount=n.length||0,delete e.fetchingError},fetchError(e,t){const{error:n}=t.payload;e.fetching=!1,e.fetchingError=n},fetchRequest:{reducer:(e,t)=>{e.fetching=!0,delete e.fetchingError},prepare:()=>({payload:{query:ke.default(r||(r=H(['\n {\n "items": *[\n _type == "','"\n && !(_id in path("drafts.**"))\n ] {\n _createdAt,\n _updatedAt,\n _id,\n _rev,\n _type,\n name\n } | order(name.current asc),\n }\n '])),"media.tag")}})},listenerCreateQueue(e,t){},listenerCreateQueueComplete(e,t){const{tags:n}=t.payload;null==n||n.forEach((t=>{e.byIds[t._id]={_type:"tag",picked:!1,tag:t,updating:!1},e.allIds.includes(t._id)||e.allIds.push(t._id)}))},listenerDeleteQueue(e,t){},listenerDeleteQueueComplete(e,t){const{tagIds:n}=t.payload;null==n||n.forEach((t=>{const n=e.allIds.indexOf(t);n>=0&&e.allIds.splice(n,1),delete e.byIds[t]}))},listenerUpdateQueue(e,t){},listenerUpdateQueueComplete(e,t){const{tags:n}=t.payload;null==n||n.forEach((t=>{e.byIds[t._id]&&(e.byIds[t._id].tag=t)}))},panelVisibleSet(e,t){const{panelVisible:n}=t.payload;e.panelVisible=n},sort(e){e.allIds.sort(((t,n)=>{const a=e.byIds[t].tag.name.current,i=e.byIds[n].tag.name.current;return a<i?-1:a>i?1:0}))},updateComplete(e,t){const{tag:n}=t.payload;e.byIds[n._id].tag=n,e.byIds[n._id].updating=!1},updateError(e,t){const{error:n,tag:a}=t.payload,i=null==a?void 0:a._id;e.byIds[i].error=n,e.byIds[i].updating=!1},updateRequest(e,t){const{tag:n}=t.payload;e.byIds[null==n?void 0:n._id].updating=!0}}}),at=e=>e.tags.byIds,it=te.createSelector([at,e=>e.tags.allIds],((e,t)=>t.map((t=>e[t])))),st=te.createSelector([at,(e,t)=>t],((e,t)=>e[t])),ot=nt.actions;var lt=nt.reducer;const rt=te.createSlice({name:"search",initialState:{facets:[],query:""},reducers:{facetsAdd(e,t){e.facets.push(t.payload.facet)},facetsClear(e){e.facets=[]},facetsRemove(e,t){e.facets=e.facets.filter((e=>e.name!==t.payload.facetName))},facetsUpdate(e,t){const{modifier:n,name:a,operatorType:i,value:s}=t.payload;e.facets.forEach(((t,o)=>{t.name===a&&("number"===t.type&&n&&(t.modifier=n),i&&(t.operatorType=i),void 0!==s&&(e.facets[o].value=s))}))},querySet(e,t){var n;e.query=null==(n=t.payload)?void 0:n.searchQuery}}}),dt=te.createSelector((e=>e.search.facets),(e=>!!(null==e?void 0:e.find((e=>"tag"===e.name))))),ct=te.createSelector([e=>e.tags.byIds,e=>e.search.facets,(e,t)=>t],((e,t,n)=>{var a,i,s;const o=null==t?void 0:t.find((e=>"tag"===e.name));if("searchable"===(null==o?void 0:o.type)){const t=null==(a=o.value)?void 0:a.value;if(t)return(null==(s=null==(i=e[t])?void 0:i.tag)?void 0:s._id)===n&&"references"===(null==o?void 0:o.operatorType)}return!1})),ut=rt.actions;var pt=rt.reducer;const ht={uploadComplete:te.createAction("uploads/uploadComplete",(function(e){let{asset:t}=e;return{payload:{asset:t}}}))},mt=Pe[0],gt={allIds:[],assetTypes:[],byIds:{},fetchCount:-1,fetching:!1,fetchingError:void 0,lastPicked:void 0,order:{direction:mt.direction,field:mt.field,title:We(mt.field,mt.direction)},pageIndex:0,pageSize:50,view:"grid"},ft=te.createSlice({name:"assets",initialState:gt,extraReducers:e=>{e.addCase(ht.uploadComplete,((e,t)=>{const{asset:n}=t.payload;e.byIds[n._id]={_type:"asset",asset:n,picked:!1,updating:!1}})).addCase(et.tagsAddComplete,((e,t)=>{const{assets:n}=t.payload;n.forEach((t=>{e.byIds[t.asset._id].updating=!1}))})).addCase(et.tagsAddError,((e,t)=>{const{assets:n}=t.payload;n.forEach((t=>{e.byIds[t.asset._id].updating=!1}))})).addCase(et.tagsAddRequest,((e,t)=>{const{assets:n}=t.payload;n.forEach((t=>{e.byIds[t.asset._id].updating=!0}))})).addCase(et.tagsRemoveComplete,((e,t)=>{const{assets:n}=t.payload;n.forEach((t=>{e.byIds[t.asset._id].updating=!1}))})).addCase(et.tagsRemoveError,((e,t)=>{const{assets:n}=t.payload;n.forEach((t=>{e.byIds[t.asset._id].updating=!1}))})).addCase(et.tagsRemoveRequest,((e,t)=>{const{assets:n}=t.payload;n.forEach((t=>{e.byIds[t.asset._id].updating=!0}))}))},reducers:{clear(e){e.allIds=[]},deleteComplete(e,t){const{assetIds:n}=t.payload;null==n||n.forEach((t=>{const n=e.allIds.indexOf(t);n>=0&&e.allIds.splice(n,1),delete e.byIds[t]})),e.pageIndex=Math.floor(e.allIds.length/e.pageSize)-1},deleteError(e,t){var n,a,i,s;const{assetIds:o,error:l}=t.payload,r=null==(s=null==(i=null==(a=null==(n=null==l?void 0:l.response)?void 0:n.body)?void 0:a.error)?void 0:i.items)?void 0:s.map((e=>e.error));null==o||o.forEach((t=>{e.byIds[t].updating=!1})),null==r||r.forEach((t=>{e.byIds[t.id].error=t.description}))},deleteRequest(e,t){const{assets:n}=t.payload;n.forEach((t=>{e.byIds[null==t?void 0:t._id].updating=!0})),Object.keys(e.byIds).forEach((t=>{delete e.byIds[t].error}))},fetchComplete(e,t){var n;const a=(null==(n=t.payload)?void 0:n.assets)||[];a&&a.forEach((t=>{e.allIds.includes(t._id)||e.allIds.push(t._id),e.byIds[t._id]={_type:"asset",asset:t,picked:!1,updating:!1}})),e.fetching=!1,e.fetchCount=a.length||0,delete e.fetchingError},fetchError(e,t){const n=t.payload;e.fetching=!1,e.fetchingError=n},fetchRequest:{reducer:(e,t)=>{e.fetching=!0,delete e.fetchingError},prepare:e=>{let{params:t={},queryFilter:n,selector:a="",sort:i=ke.default(c||(c=H(["order(_updatedAt desc)"])))}=e;const s=i||a?"|":"";return{payload:{params:t,query:ke.default(u||(u=H(['\n {\n "items": *[',"] {\n _id,\n _type,\n _createdAt,\n _updatedAt,\n altText,\n description,\n extension,\n metadata {\n dimensions,\n exif,\n isOpaque,\n },\n mimeType,\n opt {\n media\n },\n originalFilename,\n size,\n title,\n url\n } "," "," ",",\n }\n "])),n,s,i,a)}}}},insertUploads(e,t){const{results:n}=t.payload;Object.entries(n).forEach((t=>{let[n,a]=t;a&&!e.allIds.includes(n)&&e.allIds.push(a)}))},listenerCreateQueue(e,t){},listenerCreateQueueComplete(e,t){const{assets:n}=t.payload;null==n||n.forEach((t=>{var n;(null==(n=e.byIds[null==t?void 0:t._id])?void 0:n.asset)&&(e.byIds[t._id].asset=t)}))},listenerDeleteQueue(e,t){},listenerDeleteQueueComplete(e,t){const{assetIds:n}=t.payload;null==n||n.forEach((t=>{const n=e.allIds.indexOf(t);n>=0&&e.allIds.splice(n,1),delete e.byIds[t]}))},listenerUpdateQueue(e,t){},listenerUpdateQueueComplete(e,t){const{assets:n}=t.payload;null==n||n.forEach((t=>{var n;(null==(n=e.byIds[null==t?void 0:t._id])?void 0:n.asset)&&(e.byIds[t._id].asset=t)}))},loadNextPage(){},loadPageIndex(e,t){e.pageIndex=t.payload.pageIndex},orderSet(e,t){var n;e.order=null==(n=t.payload)?void 0:n.order,e.pageIndex=0},pick(e,t){const{assetId:n,picked:a}=t.payload;e.byIds[n].picked=a,e.lastPicked=a?n:void 0},pickAll(e){e.allIds.forEach((t=>{e.byIds[t].picked=!0}))},pickClear(e){e.lastPicked=void 0,Object.values(e.byIds).forEach((t=>{e.byIds[t.asset._id].picked=!1}))},pickRange(e,t){const n=e.allIds.findIndex((e=>e===t.payload.startId)),a=e.allIds.findIndex((e=>e===t.payload.endId)),i=[n,a].sort(((e,t)=>e-t));e.allIds.slice(i[0],i[1]+1).forEach((t=>{e.byIds[t].picked=!0})),e.lastPicked=e.allIds[a]},sort(e){e.allIds.sort(((t,n)=>{const a=e.byIds[t].asset[e.order.field],i=e.byIds[n].asset[e.order.field];return a<i?"asc"===e.order.direction?-1:1:a>i?"asc"===e.order.direction?1:-1:0}))},updateComplete(e,t){const{asset:n}=t.payload;e.byIds[n._id].updating=!1,e.byIds[n._id].asset=n},updateError(e,t){const{asset:n,error:a}=t.payload,i=null==n?void 0:n._id;e.byIds[i].error=a.message,e.byIds[i].updating=!1},updateRequest(e,t){var n,a;const i=null==(a=null==(n=t.payload)?void 0:n.asset)?void 0:a._id;e.byIds[i].updating=!0},viewSet(e,t){var n;e.view=null==(n=t.payload)?void 0:n.view}}}),xt=te.createSelector([e=>e.assets.byIds,(e,t)=>t],((e,t)=>e[t])),yt=te.createSelector([e=>e.assets.byIds,e=>e.assets.allIds],((e,t)=>t.map((t=>e[t])))),vt=te.createSelector([yt],(e=>e.length)),bt=te.createSelector([yt],(e=>e.filter((e=>null==e?void 0:e.picked)))),jt=te.createSelector([bt],(e=>e.length)),It=ft.actions;var Ct,wt,Tt=ft.reducer;const kt=le.css(g||(g=H(["\n ::-webkit-scrollbar {\n width: 14px;\n }\n\n ::-webkit-scrollbar-thumb {\n border-radius: 10px;\n border: 4px solid rgba(0, 0, 0, 0);\n background: ",";\n background-clip: padding-box;\n\n &:hover {\n background: ",";\n background-clip: padding-box;\n }\n }\n"])),null==(Ct=oe.hues.gray)?void 0:Ct[800].hex,null==(wt=oe.hues.gray)?void 0:wt[400].hex),St=le.createGlobalStyle(f||(f=H(["\n .media__custom-scrollbar {\n ",'\n }\n\n // @sanity/ui overrides\n\n // Custom scrollbar on Box (used in Dialogs)\n div[data-ui="Box"] {\n ','\n }\n\n // Dialog background color\n div[data-ui="Dialog"] {\n background-color: rgba(15, 17, 18, 0.9);\n }\n\n'])),kt,kt),_t=ee.useSelector,Et=te.createSlice({name:"dialog",initialState:{items:[]},extraReducers:e=>{e.addCase(tt.showTagCreate,(e=>{e.items.push({id:"tagCreate",type:"tagCreate"})})),e.addCase(tt.showTagEdit,((e,t)=>{const{tagId:n}=t.payload;e.items.push({id:n,tagId:n,type:"tagEdit"})}))},reducers:{clear(e){e.items=[]},inlineTagCreate(e,t){const{assetId:n,tag:a}=t.payload;e.items.forEach((e=>{"assetEdit"===e.type&&e.assetId===n&&(e.lastCreatedTag={label:a.name.current,value:a._id})}))},inlineTagRemove(e,t){const{tagIds:n}=t.payload;e.items.forEach((e=>{"assetEdit"===e.type&&(e.lastRemovedTagIds=n)}))},remove(e,t){var n;const a=null==(n=t.payload)?void 0:n.id;e.items=e.items.filter((e=>e.id!==a))},showConfirmAssetsTagAdd(e,t){const{assetsPicked:n,closeDialogId:a,tag:i}=t.payload,s="".concat(n.length," ").concat(_e.default("asset",n.length));e.items.push({closeDialogId:a,confirmCallbackAction:et.tagsAddRequest({assets:n,tag:i}),confirmText:"Yes, add tag to ".concat(s),title:"Add tag ".concat(i.name.current," to ").concat(s,"?"),id:"confirm",headerTitle:"Confirm tag addition",tone:"primary",type:"confirm"})},showConfirmAssetsTagRemove(e,t){const{assetsPicked:n,closeDialogId:a,tag:i}=t.payload,s="".concat(n.length," ").concat(_e.default("asset",n.length));e.items.push({closeDialogId:a,confirmCallbackAction:et.tagsRemoveRequest({assets:n,tag:i}),confirmText:"Yes, remove tag from ".concat(s),headerTitle:"Confirm tag removal",id:"confirm",title:"Remove tag ".concat(i.name.current," from ").concat(s,"?"),tone:"critical",type:"confirm"})},showConfirmDeleteAssets(e,t){const{assets:n,closeDialogId:a}=t.payload,i="".concat(n.length," ").concat(_e.default("asset",n.length));e.items.push({closeDialogId:a,confirmCallbackAction:It.deleteRequest({assets:n.map((e=>e.asset))}),confirmText:"Yes, delete ".concat(i),description:"This operation cannot be reversed. Are you sure you want to continue?",title:"Permanently delete ".concat(i,"?"),id:"confirm",headerTitle:"Confirm deletion",tone:"critical",type:"confirm"})},showConfirmDeleteTag(e,t){const{closeDialogId:n,tag:a}=t.payload;e.items.push({closeDialogId:n,confirmCallbackAction:ot.deleteRequest({tag:a}),confirmText:"Yes, delete ".concat("tag"),description:"This operation cannot be reversed. Are you sure you want to continue?",title:"Permanently delete ".concat("tag","?"),id:"confirm",headerTitle:"Confirm deletion",tone:"critical",type:"confirm"})},showAssetEdit(e,t){const{assetId:n}=t.payload;e.items.push({assetId:n,id:n,type:"assetEdit"})},showSearchFacets(e){e.items.push({id:"searchFacets",type:"searchFacets"})},showTags(e){e.items.push({id:"tags",type:"tags"})}}}),Mt=Et.actions;var Rt=Et.reducer;const Bt=()=>{const e=ee.useDispatch(),t=_t((e=>e.assets.view));return W.jsxs($.Inline,{space:0,style:{whiteSpace:"nowrap"},children:[W.jsx($.Button,{fontSize:1,icon:G.ThLargeIcon,mode:"grid"===t?"default":"ghost",onClick:()=>e(It.viewSet({view:"grid"})),style:{borderBottomRightRadius:0,borderTopRightRadius:0}}),W.jsx($.Button,{fontSize:1,icon:G.ThListIcon,mode:"table"===t?"default":"ghost",onClick:()=>e(It.viewSet({view:"table"})),style:{borderBottomLeftRadius:0,borderTopLeftRadius:0}})]})},Ft=()=>{var e;const t=ee.useDispatch(),n=_t((e=>e.assets.order));return W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,icon:G.SortIcon,iconRight:G.SelectIcon,mode:"ghost",padding:3,text:We(n.field,n.direction)}),id:"order",menu:W.jsx($.Menu,{children:null==(e=Pe)?void 0:e.map(((e,a)=>e?W.jsx($.MenuItem,{disabled:n.field===e.field&&n.direction===e.direction,fontSize:1,onClick:()=>t(It.orderSet({order:{direction:e.direction,field:e.field}})),padding:2,text:We(e.field,e.direction)},a):W.jsx($.MenuDivider,{},a)))})})},zt=e=>{const{loading:t}=e,{animationDuration:n,isFinished:a,progress:i}=de.useNProgress({animationDuration:300,isAnimating:t});return W.jsx($.Box,{style:{opacity:a?0:1,transition:"opacity ".concat(n,"ms linear")},children:W.jsx($.Box,{style:{height:"1px",background:"rgba(255, 255, 255, 0.5)",position:"absolute",left:0,top:0,transition:"width ".concat(n,"ms linear"),width:"".concat(100*i,"%")}})})},Dt=Se.default($.Box)(x||(x=H(["\n background: rgba(255, 255, 255, 0.05);\n border-radius: ","px;\n"])),(e=>e.theme.sanity.radius[2])),At=e=>{const{children:t,facet:n}=e,a=ee.useDispatch();return W.jsx(Dt,{padding:[2,2,1],children:W.jsxs($.Flex,{align:["flex-start","flex-start","center"],direction:["column","column","row"],children:[W.jsx($.Box,{paddingBottom:[3,3,0],paddingLeft:1,paddingRight:2,paddingTop:[1,1,0],children:W.jsx($.Label,{size:0,style:{whiteSpace:"nowrap"},children:n.title})}),W.jsxs($.Flex,{align:"center",children:[t,W.jsx($.Box,{marginLeft:1,paddingX:2,children:W.jsx($.Text,{muted:!0,size:0,children:W.jsx(G.CloseIcon,{onClick:()=>{a(ut.facetsRemove({facetName:n.name}))}})})})]})]})})},Ot=t=>{const{onValueChange:n,value:a}=t,i=V(t,e);return W.jsx($.TextInput,Q(Q({},i),{},{onChange:e=>{const t=e.target.value;(""===t||/^[0-9\b]+$/.test(t))&&n(parseInt(t,10)||"")},value:null!=a?a:""}))},qt=e=>{var t;const{facet:n}=e,a=ee.useDispatch(),i=null==n?void 0:n.modifiers,s=(null==n?void 0:n.modifier)?null==i?void 0:i.find((e=>e.name===(null==n?void 0:n.modifier))):null==i?void 0:i[0],o=null!=(t=n.operatorType)?t:"greaterThan";return W.jsxs(At,{facet:n,children:[(null==n?void 0:n.operatorTypes)&&W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,iconRight:G.SelectIcon,padding:2,text:Le[o].label}),id:"operators",menu:W.jsx($.Menu,{children:n.operatorTypes.map(((e,t)=>e?W.jsx($.MenuItem,{disabled:e===o,fontSize:1,onClick:()=>(e=>{a(ut.facetsUpdate({name:n.name,operatorType:e}))})(e),padding:2,text:Le[e].label},e):W.jsx($.MenuDivider,{},t)))})}),W.jsx($.Box,{marginX:1,style:{maxWidth:"50px"},children:W.jsx(Ot,{fontSize:1,onValueChange:e=>{a(ut.facetsUpdate({name:n.name,value:e}))},padding:2,radius:2,width:2,value:null==n?void 0:n.value})}),i&&W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,iconRight:G.SelectIcon,padding:2,text:null==s?void 0:s.title}),id:"modifier",menu:W.jsx($.Menu,{children:i.map((e=>W.jsx($.MenuItem,{disabled:e.name===n.modifier,fontSize:1,onClick:()=>(e=>{a(ut.facetsUpdate({name:n.name,modifier:e.name}))})(e),padding:2,text:e.title},e.name)))})})]})},Lt=e=>{var t;const{facet:n}=e,a=ee.useDispatch(),i=null==n?void 0:n.options,s=null==i?void 0:i.find((e=>e.name===(null==n?void 0:n.value))),o=null!=(t=null==n?void 0:n.operatorType)?t:"is";return W.jsxs(At,{facet:n,children:[(null==n?void 0:n.operatorTypes)&&W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,iconRight:G.SelectIcon,padding:2,style:{marginRight:"4px"},text:Le[o].label}),id:"operators",menu:W.jsx($.Menu,{children:n.operatorTypes.map(((e,t)=>e?W.jsx($.MenuItem,{disabled:e===o,fontSize:1,onClick:()=>(e=>{a(ut.facetsUpdate({name:n.name,operatorType:e}))})(e),padding:2,text:Le[e].label},e):W.jsx($.MenuDivider,{},t)))})}),W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,iconRight:G.SelectIcon,padding:2,text:null==s?void 0:s.title}),id:"list",menu:W.jsx($.Menu,{children:null==i?void 0:i.map(((e,t)=>W.jsx($.MenuItem,{disabled:e.name===(null==s?void 0:s.name),fontSize:1,onClick:()=>{return e=i[t],void a(ut.facetsUpdate({name:n.name,value:e.name}));var e},padding:2,text:e.title},e.name)))})})]})},Pt=e=>{const{facet:t}=e,n=ee.useDispatch(),a=t.operatorType;return W.jsxs(At,{facet:t,children:[(null==t?void 0:t.operatorTypes)&&W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,iconRight:G.SelectIcon,padding:2,text:Le[a].label}),id:"operators",menu:W.jsx($.Menu,{children:t.operatorTypes.map(((e,i)=>e?W.jsx($.MenuItem,{disabled:e===a,fontSize:1,onClick:()=>(e=>{n(ut.facetsUpdate({name:t.name,operatorType:e}))})(e),padding:2,text:Le[e].label},e):W.jsx($.MenuDivider,{},i)))})}),!Le[a].hideInput&&W.jsx($.Box,{marginLeft:1,style:{maxWidth:"125px"},children:W.jsx($.TextInput,{fontSize:1,onChange:e=>{n(ut.facetsUpdate({name:t.name,value:e.target.value}))},padding:2,radius:2,width:2,value:null==t?void 0:t.value})})]})};var Ut,Vt,Nt,Qt,Xt,Ht,Yt,Gt,Wt,$t,Kt,Zt,Jt,en,tn;const nn=null==(Xt=null==(Qt=null==(Nt=null==(Vt=null==(Ut=$.studioTheme)?void 0:Ut.color)?void 0:Vt.dark)?void 0:Nt.primary)?void 0:Qt.spot)?void 0:Xt.blue,an=null==($t=null==(Wt=null==(Gt=null==(Yt=null==(Ht=$.studioTheme)?void 0:Ht.color)?void 0:Yt.dark)?void 0:Gt.default)?void 0:Wt.base)?void 0:$t.bg,sn=null==(Kt=$.studioTheme)?void 0:Kt.radius,on=null==(Zt=$.studioTheme)?void 0:Zt.space,ln=null==(tn=null==(en=null==(Jt=$.studioTheme)?void 0:Jt.fonts)?void 0:en.text)?void 0:tn.sizes,rn={control:(e,t)=>{let{isDisabled:n,isFocused:a}=t,i="inset 0 0 0 1px ".concat(oe.hues.gray[900].hex);return a&&(i="inset 0 0 0 1px ".concat(oe.hues.gray[900].hex,", 0 0 0 1px var(--card-bg-color), 0 0 0 3px var(--card-focus-ring-color) !important")),Q(Q({},e),{},{backgroundColor:an,color:oe.white.hex,border:"none",borderRadius:sn[2],boxShadow:i,fontSize:ln[1].fontSize,minHeight:"25px",opacity:n?.5:"inherit",outline:"none",transition:"none","&:hover":{boxShadow:"inset 0 0 0 1px ".concat($.studioTheme.color.dark.default.input.default.hovered.border)}})},input:e=>Q(Q({},e),{},{color:oe.white.hex,fontFamily:$.studioTheme.fonts.text.family,marginLeft:on[2]}),menuList:e=>Q(Q({},e),{},{padding:0}),noOptionsMessage:e=>Q(Q({},e),{},{fontFamily:$.studioTheme.fonts.text.family,fontSize:ln[1].fontSize,lineHeight:"1em"}),option:(e,t)=>{let{isFocused:n}=t;return Q(Q({},e),{},{backgroundColor:n?nn:"transparent",borderRadius:sn[2],color:n?oe.black.hex:"inherit",fontSize:ln[1].fontSize,lineHeight:"1em",padding:"4px 6px","&:hover":{backgroundColor:nn,color:oe.black.hex}})},placeholder:e=>Q(Q({},e),{},{fontFamily:$.studioTheme.fonts.text.family,marginLeft:on[2],paddingBottom:"2px"}),singleValue:e=>Q(Q({},e),{},{color:oe.white.hex,lineHeight:"1em",paddingBottom:"1px"}),valueContainer:e=>Q(Q({},e),{},{margin:0,padding:0})},dn=e=>W.jsx($.Box,{padding:1,children:W.jsx(ce.components.Option,Q(Q({},e),{},{children:W.jsx($.Box,{paddingY:1,children:W.jsx($.Text,{size:1,style:{color:"inherit"},textOverflow:"ellipsis",children:e.children})})}))}),cn={ClearIndicator:e=>W.jsx(ce.components.ClearIndicator,Q(Q({},e),{},{children:W.jsx($.Box,{paddingRight:1,style:{transform:"scale(0.85)"},children:W.jsx($.Text,{muted:!0,size:0,children:W.jsx(G.CloseIcon,{})})})})),DropdownIndicator:null,IndicatorSeparator:null,Menu:e=>W.jsx(ce.components.Menu,Q(Q({},e),{},{children:W.jsx($.Card,{radius:1,shadow:2,children:e.children})})),MenuList:e=>{const{children:t}=e;if(Array.isArray(t)){const e=t.length>5?165:33*t.length;return W.jsx(ue.Virtuoso,{className:"media__custom-scrollbar",itemContent:e=>{const n=t[e];return W.jsx(dn,Q({},n.props))},style:{height:e},totalCount:t.length})}return W.jsx(ce.components.MenuList,Q(Q({},e),{},{children:t}))},NoOptionsMessage:e=>W.jsx(ce.components.NoOptionsMessage,Q(Q({},e),{},{children:e.children})),Option:dn,SingleValue:e=>W.jsx(ce.components.SingleValue,Q(Q({},e),{},{children:W.jsx($.Box,{paddingLeft:2,children:W.jsx($.Text,{size:1,style:{color:"inherit",lineHeight:"2em"},textOverflow:"ellipsis",children:e.children})})}))},un=e=>{const{facet:t}=e,n=ee.useDispatch(),a=_t((e=>it(e))),i=_t((e=>e.tags.fetching)),s=Je(a),o=t.operatorType;return W.jsxs(At,{facet:t,children:[(null==t?void 0:t.operatorTypes)&&W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,iconRight:G.SelectIcon,padding:2,text:Le[o].label}),id:"operators",menu:W.jsx($.Menu,{children:t.operatorTypes.map(((e,a)=>e?W.jsx($.MenuItem,{disabled:e===o,fontSize:1,onClick:()=>(e=>{n(ut.facetsUpdate({name:t.name,operatorType:e}))})(e),padding:2,text:Le[e].label},e):W.jsx($.MenuDivider,{},a)))})}),!Le[o].hideInput&&W.jsx($.Box,{marginX:1,style:{width:"160px"},children:W.jsx(Ee.default,{components:cn,instanceId:"facet-searchable",isClearable:!0,isDisabled:i,isSearchable:!0,name:"tags",noOptionsMessage:()=>"No tags",onChange:e=>{return a=e,void n(ut.facetsUpdate({name:t.name,value:a}));var a},options:s,placeholder:i?"Loading...":"Select...",styles:rn,value:null==t?void 0:t.value})})]})},pn=Se.default($.Flex)(y||(y=H(["\n > * {\n margin-bottom: ","px;\n }\n"])),(e=>e.theme.sanity.space[2])),hn=e=>{const{layout:t="inline"}=e,n=_t((e=>e.search.facets)),a=n.map((e=>"number"===e.type?W.jsx(qt,{facet:e},e.name):"searchable"===e.type?W.jsx(un,{facet:e},e.name):"select"===e.type?W.jsx(Lt,{facet:e},e.name):"string"===e.type?W.jsx(Pt,{facet:e},e.name):null));if("inline"===t)return 0===n.length?null:W.jsx($.Box,{marginBottom:2,children:W.jsx($.Inline,{space:2,children:a})});if("stack"===t)return W.jsx(pn,{align:"flex-start",direction:"column",children:a});throw Error("Invalid layout")},mn=()=>{const e=ee.useDispatch(),t=_t((e=>e.assets.assetTypes)),n=_t((e=>e.search.facets)),a=!_t((e=>e.selected.document)),i=Ue.filter((e=>{if("group"===e.type||"divider"===e.type)return!0;if(a)return!(null==e?void 0:e.selectOnly);return e.assetTypes.filter((e=>t.includes(e))).length>0})).filter(((e,t,n)=>{const a=n[t-1];return("divider"!==e.type||0!==t&&t!==n.length-1)&&("divider"!==e.type||"divider"!==(null==a?void 0:a.type))})),s=i.filter((e=>e)).length-n.length>0,o=function(t){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return W.jsx(W.Fragment,{children:null==t?void 0:t.map(((t,i)=>{if("divider"===t.type)return W.jsx($.MenuDivider,{},i);if("group"===t.type)return W.jsx($.MenuGroup,{text:t.title,title:t.title,children:o(t.facets,a+1)},"group-".concat(a,"-").concat(i));if(t){const a=!!n.find((e=>e.name===t.name));return W.jsx($.MenuItem,{disabled:a,fontSize:1,onClick:()=>e(ut.facetsAdd({facet:t})),padding:2,text:t.title},t.name)}return null}))})};return W.jsxs($.Flex,{children:[W.jsx($.MenuButton,{button:W.jsx($.Button,{disabled:!s,fontSize:1,icon:G.AddCircleIcon,mode:"bleed",text:"Add filter",tone:"primary"}),id:"facets",menu:W.jsx($.Menu,{children:o(i)}),placement:"right-start",portal:!0}),n.length>0&&W.jsx($.Button,{fontSize:1,mode:"bleed",onClick:()=>e(ut.facetsClear()),text:"Clear"})]})},gn=()=>W.jsxs("svg",{"data-sanity-icon":"media__tag",fill:"currentColor",height:"1em",stroke:"currentColor",strokeWidth:"0",viewBox:"0 0 512 512",width:"1em",children:[W.jsx("path",{d:"M435.25 48h-122.9a14.46 14.46 0 00-10.2 4.2L56.45 297.9a28.85 28.85 0 000 40.7l117 117a28.85 28.85 0 0040.7 0L459.75 210a14.46 14.46 0 004.2-10.2v-123a28.66 28.66 0 00-28.7-28.8z",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"32"}),W.jsx("path",{d:"M384 160a32 32 0 1132-32 32 32 0 01-32 32z"})]}),fn=()=>{const e=_t((e=>e.search.query)),t=ee.useDispatch();return W.jsxs($.Box,{style:{position:"relative"},children:[W.jsx($.TextInput,{fontSize:1,icon:G.SearchIcon,onChange:e=>{t(ut.querySet({searchQuery:e.currentTarget.value}))},placeholder:"Search",radius:2,value:e}),e.length>0&&W.jsx($.Flex,{align:"center",justify:"center",onClick:()=>{t(ut.querySet({searchQuery:""}))},style:{cursor:"pointer",height:"100%",opacity:.75,position:"absolute",right:0,top:0,width:"2em",zIndex:1},children:W.jsx(G.CloseIcon,{})})]})},xn=()=>{var e;const t=ee.useDispatch(),n=_t((e=>e.assets.fetching)),a=_t((e=>e.assets.pageIndex)),i=_t((e=>e.search.facets)),s=_t((e=>e.tags.panelVisible)),o=$.useMediaIndex();return W.jsxs($.Box,{paddingY:2,style:{borderBottom:"1px solid ".concat(null==(e=oe.hues.gray)?void 0:e[900].hex),zIndex:2},children:[W.jsx($.Box,{marginBottom:2,children:W.jsx($.Flex,{align:"flex-start",direction:["column","column","column","column","row"],justify:"space-between",children:W.jsxs($.Flex,{flex:1,style:{alignItems:"flex-start",flex:1,height:"100%",justifyContent:o<2?"space-between":"flex-start",position:"relative",width:"100%"},children:[W.jsx($.Box,{marginX:2,style:{minWidth:"200px"},children:W.jsx(fn,{})}),W.jsxs($.Box,{display:["none","none","block"],children:[W.jsx(hn,{}),W.jsx(mn,{})]}),W.jsx($.Box,{display:["block","block","none"],marginX:2,children:W.jsxs($.Inline,{space:2,style:{whiteSpace:"nowrap"},children:[W.jsx($.Button,{fontSize:1,mode:"ghost",onClick:()=>{t(Mt.showSearchFacets())},text:"Filters".concat(i.length>0?" (".concat(i.length,")"):""),tone:"primary"}),W.jsx($.Button,{fontSize:1,mode:"ghost",onClick:()=>{t(Mt.showTags())},text:"Tags",tone:"primary"})]})})]})})}),W.jsx($.Box,{children:W.jsxs($.Flex,{align:"center",justify:["space-between"],children:[W.jsx($.Box,{marginX:2,children:W.jsx(Bt,{})}),W.jsxs($.Flex,{marginX:2,children:[W.jsx(Ft,{}),W.jsx($.Box,{display:["none","none","block"],marginLeft:2,children:W.jsx($.Button,{fontSize:1,icon:W.jsx($.Box,{style:{transform:"scale(0.75)"},children:W.jsx(gn,{})}),onClick:()=>{t(ot.panelVisibleSet({panelVisible:!s}))},mode:s?"default":"ghost",text:s?"Tags":""})})]})]})}),W.jsx(zt,{loading:n},a)]})},yn=te.createSlice({name:"debug",initialState:{badConnection:!1,enabled:!1},reducers:{setBadConnection(e,t){e.badConnection=t.payload},toggleEnabled(e){e.enabled=!e.enabled}}}),vn=yn.actions;var bn=yn.reducer;const jn=()=>{const e=ee.useDispatch(),t=_t((e=>e.debug.badConnection)),n=_t((e=>e.debug.enabled));return Ae("alt+ctrl+shift+/",(()=>{e(vn.toggleEnabled())})),n?W.jsx($.Box,{padding:4,style:{bottom:0,left:0,pointerEvents:"none",position:"fixed",width:"100%"},children:W.jsxs($.Flex,{align:"center",children:[W.jsx($.Box,{marginRight:3,children:W.jsx($.Text,{muted:!0,size:1,children:W.jsx(G.PlugIcon,{})})}),W.jsx($.Tooltip,{content:W.jsx($.Box,{padding:2,children:W.jsx($.Text,{muted:!0,size:1,children:t?"Bad connection: +3000ms & 50% chance to fail":"No connection throttling"})}),fallbackPlacements:["right","left"],placement:"bottom",children:W.jsx($.Switch,{checked:t,onChange:t=>{const n=t.target.checked;e(vn.setBadConnection(n))},style:{pointerEvents:"auto"}})})]})}):null},In=(e,t)=>{const n="undefined"!=typeof window&&window.devicePixelRatio?Math.round(window.devicePixelRatio):1,a=(null==t?void 0:t.height)?(null==t?void 0:t.height)*Math.max(1,n):void 0,i=t.width*Math.max(1,n),s=new URLSearchParams;return s.append("fit","max"),s.append("w",i.toString()),a&&s.append("h",a.toString()),"".concat(e.url,"?").concat(s.toString())},Cn=e=>Object.keys(e).reduce(((t,n)=>{const a=e[n];return"object"==typeof a&&null!==a&&a.constructor!==Array?t[n]=Cn(a):""===a||void 0===a||0===(null==a?void 0:a.length)?t[n]=null:t[n]="string"==typeof a&&a?e[n].trim():e[n],t}),{}),wn=e=>"sanity.fileAsset"===e._type,Tn=e=>"sanity.imageAsset"===e._type,kn=e=>"".concat(e.metadata.dimensions.width,"x").concat(e.metadata.dimensions.height,"px"),Sn=e=>{const{disabled:t,url:n}=e,a=K.useRef(),[i,s]=K.useState(!1);return K.useEffect((()=>()=>{a.current&&clearTimeout(a.current)}),[]),W.jsx($.Popover,{content:W.jsx($.Text,{muted:!0,size:1,children:"Copied!"}),open:i,padding:2,placement:"top",radius:1,children:W.jsx($.Button,{disabled:t,fontSize:1,icon:G.ClipboardIcon,mode:"ghost",onClick:()=>{a.current&&clearTimeout(a.current),s(!0),Fe.default(n),a.current=setTimeout((()=>{s(!1)}),1250)},text:"Copy URL"})})},_n=e=>{let{label:t,value:n}=e;return W.jsxs($.Flex,{justify:"space-between",children:[W.jsx($.Text,{size:1,style:{opacity:.8,width:"40%"},textOverflow:"ellipsis",children:t}),W.jsx($.Text,{size:1,style:{opacity:.4,textAlign:"right",width:"60%"},textOverflow:"ellipsis",children:n})]})},En=e=>{var t;const{asset:n,item:a}=e,i=null==(t=null==n?void 0:n.metadata)?void 0:t.exif;return W.jsxs($.Box,{marginTop:3,children:[W.jsx($.Box,{children:W.jsxs($.Stack,{space:3,children:[W.jsx(_n,{label:"Size",value:Be.default(null==n?void 0:n.size,{base:10,round:0})}),W.jsx(_n,{label:"MIME type",value:null==n?void 0:n.mimeType}),W.jsx(_n,{label:"Extension",value:(null==n?void 0:n.extension).toUpperCase()}),Tn(n)&&W.jsx(_n,{label:"Dimensions",value:kn(n)})]})}),i&&W.jsxs(W.Fragment,{children:[W.jsx($.Box,{marginY:4,style:{background:"#222",height:"1px",width:"100%"}}),W.jsx($.Box,{children:W.jsxs($.Stack,{space:3,children:[i.ISO&&W.jsx(_n,{label:"ISO",value:i.ISO}),i.FNumber&&W.jsx(_n,{label:"Aperture",value:"ƒ/".concat(i.FNumber)}),i.FocalLength&&W.jsx(_n,{label:"Focal length",value:"".concat(i.FocalLength,"mm")}),i.ExposureTime&&W.jsx(_n,{label:"Exposure time",value:"1/".concat(1/i.ExposureTime)}),i.DateTimeOriginal&&W.jsx(_n,{label:"Original date",value:Re.default(new Date(i.DateTimeOriginal),"PPp")})]})})]}),W.jsx($.Box,{marginTop:5,children:W.jsxs($.Inline,{space:2,children:[W.jsx($.Button,{disabled:!a||(null==a?void 0:a.updating),fontSize:1,icon:G.DownloadIcon,mode:"ghost",onClick:()=>{window.location.href="".concat(n.url,"?dl=").concat(n.originalFilename)},text:"Download"}),W.jsx(Sn,{disabled:!a||(null==a?void 0:a.updating),url:n.url})]})})]})},Mn=e=>W.jsx($.Dialog,Q(Q({},e),{},{style:{position:"fixed"}})),Rn=e=>{const{assetId:t}=e,n=Y.useDocumentStore();return W.jsx(Y.WithReferringDocuments,{documentStore:n,id:t,children:e=>{let{isLoading:t,referringDocuments:n}=e;return W.jsx(Bn,{isLoading:t,referringDocuments:n})}})},Bn=e=>{const{isLoading:t,referringDocuments:n}=e,a=Y.useSchema(),i=n.reduce(((e,t)=>t._id.startsWith("drafts.")?e.concat(t._id.slice(7)):e),[]),s=n.filter((e=>!i.includes(e._id)));return t?W.jsx($.Text,{size:1,children:"Loading..."}):0===s.length?W.jsx($.Text,{size:1,children:"No documents are referencing this asset"}):W.jsx($.Card,{flex:1,marginBottom:2,padding:2,radius:2,shadow:1,children:W.jsx($.Stack,{space:2,children:null==s?void 0:s.map((e=>W.jsx(Fn,{doc:e,schemaType:a.get(e._type)},e._id)))})})},Fn=e=>{const{doc:t,schemaType:n}=e,{onClick:a}=ye.useIntentLink({intent:"edit",params:{id:t._id}});return n?W.jsx($.Button,{mode:"bleed",onClick:a,padding:2,style:{width:"100%"},children:W.jsx(Y.Preview,{layout:"default",schemaType:n,value:t})},t._id):W.jsx($.Box,{padding:2,children:W.jsxs($.Text,{size:1,children:["A document of the unknown type ",W.jsx("em",{children:t._type})]})})},zn=Se.default($.Box)(v||(v=H(["\n text {\n font-family: "," !important;\n font-size: 8px !important;\n font-weight: 500 !important;\n }\n"])),(e=>e.theme.sanity.fonts.text.family)),Dn=e=>{const{extension:t,onClick:n,width:a}=e;return W.jsx($.Flex,{align:"center",justify:"center",onClick:n,style:{height:"100%"},children:W.jsx(zn,{style:{width:a},children:t?W.jsx(ve.FileIcon,Q({extension:t},ve.defaultStyles[t])):W.jsx(ve.FileIcon,{})})})},An=e=>{const{asset:t}=e;return 0===t.mimeType.search("audio")?W.jsx($.Flex,{align:"center",justify:"center",style:{height:"100%"},children:W.jsx("audio",{controls:!0,src:t.url,style:{width:"100%"}})}):0===t.mimeType.search("video")?W.jsx("video",{controls:!0,src:t.url,style:{height:"100%",width:"100%"}}):W.jsx(Dn,{extension:t.extension,width:"50%"})},On=Se.default(G.ErrorOutlineIcon)((e=>{let{theme:t}=e;return{color:t.sanity.color.spot.red}})),qn=e=>{const{description:t,error:n,label:a,name:i}=e;return W.jsxs(W.Fragment,{children:[W.jsx($.Box,{marginY:3,children:W.jsxs($.Inline,{space:2,children:[W.jsx($.Text,{as:"label",htmlFor:i,size:1,weight:"semibold",children:a}),n&&W.jsx($.Text,{size:1,children:W.jsx($.Tooltip,{content:W.jsx($.Box,{padding:2,children:W.jsxs($.Text,{muted:!0,size:1,children:[W.jsx(On,{style:{marginRight:"0.1em"}}),n.message]})}),fallbackPlacements:["top","left"],placement:"right",portal:!0,children:W.jsx(On,{})})})]})}),t&&W.jsx($.Box,{marginY:3,children:W.jsx($.Text,{htmlFor:i,muted:!0,size:1,children:t})})]})},Ln=K.forwardRef(((e,t)=>{const{description:n,disabled:a,error:i,extension:s,label:o,name:l,placeholder:r,value:d}=e;return W.jsxs($.Box,{children:[W.jsx(qn,{description:n,error:i,label:o,name:l}),W.jsxs($.Flex,{children:[W.jsx($.Box,{style:{flexGrow:1},children:W.jsx($.TextInput,{autoComplete:"off",autoFocus:!0,defaultValue:d,disabled:a,id:l,name:l,placeholder:r,ref:t})}),W.jsx($.Box,{style:{width:"70px"},children:W.jsx($.TextInput,{defaultValue:".".concat(s),disabled:!0})})]})]})}));var Pn,Un,Vn,Nn,Qn,Xn,Hn,Yn,Gn,Wn,$n,Kn;const Zn=null==(Qn=null==(Nn=null==(Vn=null==(Un=null==(Pn=$.studioTheme)?void 0:Pn.color)?void 0:Un.dark)?void 0:Vn.primary)?void 0:Nn.spot)?void 0:Qn.blue,Jn=null==(Wn=null==(Gn=null==(Yn=null==(Hn=null==(Xn=$.studioTheme)?void 0:Xn.color)?void 0:Hn.dark)?void 0:Yn.primary)?void 0:Gn.spot)?void 0:Wn.gray,ea=null==($n=$.studioTheme)?void 0:$n.radius,ta=null==(Kn=$.studioTheme)?void 0:Kn.space,na={control:(e,t)=>{let{isDisabled:n,isFocused:a}=t,i="inset 0 0 0 1px ".concat(oe.hues.gray[900].hex);return a&&(i="inset 0 0 0 1px ".concat(oe.hues.gray[900].hex,", 0 0 0 1px var(--card-bg-color), 0 0 0 3px var(--card-focus-ring-color) !important")),Q(Q({},e),{},{background:n?$.studioTheme.color.dark.default.input.default.disabled.bg:"transparent",color:oe.white.hex,border:"none",borderRadius:ea[1],boxShadow:i,minHeight:"35px",outline:"none",transition:"none","&:hover":{boxShadow:"inset 0 0 0 1px ".concat($.studioTheme.color.dark.default.input.default.hovered.border)}})},indicatorsContainer:(e,t)=>{let{isDisabled:n}=t;return Q(Q({},e),{},{opacity:n?.25:1})},input:e=>Q(Q({},e),{},{color:oe.white.hex,fontFamily:$.studioTheme.fonts.text.family,marginLeft:ta[2]}),menuList:e=>Q({},e),multiValue:(e,t)=>{let{isDisabled:n}=t;return Q(Q({},e),{},{backgroundColor:Jn,borderRadius:ea[2],opacity:n?.5:1})},multiValueRemove:e=>Q(Q({},e),{},{paddingLeft:0,"&:hover":{background:"transparent",color:"inherit"}}),noOptionsMessage:e=>Q(Q({},e),{},{fontFamily:$.studioTheme.fonts.text.family,lineHeight:"1em"}),option:(e,t)=>{let{isFocused:n}=t;return Q(Q({},e),{},{backgroundColor:n?Zn:"transparent",borderRadius:ea[2],color:n?oe.black.hex:"inherit",fontFamily:$.studioTheme.fonts.text.family,padding:"4px 8px","&:hover":{backgroundColor:Zn,color:oe.black.hex}})},placeholder:e=>Q(Q({},e),{},{fontFamily:$.studioTheme.fonts.text.family,marginLeft:ta[2]}),valueContainer:e=>Q(Q({},e),{},{marginBottom:ta[0],marginLeft:ta[1],marginTop:ta[0],padding:0})},aa=e=>W.jsx($.Box,{paddingX:1,paddingY:1,children:W.jsx(ce.components.Option,Q(Q({},e),{},{children:W.jsxs($.Flex,{align:"center",children:[e.data.__isNew__&&W.jsx(G.AddIcon,{style:{marginRight:"3px"}}),e.children]})}))}),ia={DropdownIndicator:e=>W.jsx(ce.components.DropdownIndicator,Q(Q({},e),{},{children:W.jsx($.Box,{paddingX:2,children:W.jsx($.Text,{size:1,children:W.jsx(G.ChevronDownIcon,{})})})})),IndicatorSeparator:null,Menu:e=>W.jsx(ce.components.Menu,Q(Q({},e),{},{children:W.jsx($.Card,{radius:1,shadow:2,children:e.children})})),MenuList:e=>{const{children:t}=e;if(Array.isArray(t)){const e=t.length>5?185:37*t.length;return W.jsx(ue.Virtuoso,{className:"media__custom-scrollbar",itemContent:e=>{const n=t[e];return W.jsx(aa,Q({},n.props))},style:{height:e},totalCount:t.length})}return W.jsx(ce.components.MenuList,Q(Q({},e),{},{children:t}))},MultiValueLabel:e=>W.jsx($.Box,{paddingLeft:1,paddingRight:0,paddingY:1,children:W.jsx($.Text,{size:2,weight:"medium",children:W.jsx(ce.components.MultiValueLabel,Q({},e))})}),MultiValueRemove:e=>W.jsx(ce.components.MultiValueRemove,Q(Q({},e),{},{children:W.jsx(G.CloseIcon,{color:"#1f2123"})})),Option:aa},sa=e=>{const{control:t,description:n,disabled:a,error:i,label:s,name:o,onCreateTag:l,options:r,placeholder:d,value:c}=e,u=_t((e=>e.tags.creating)),p=_t((e=>e.tags.fetching));return W.jsxs($.Box,{style:{zIndex:2},children:[W.jsx(qn,{description:n,error:i,label:s,name:o}),W.jsx(he.Controller,{control:t,defaultValue:c,name:o,render:e=>{let{onBlur:t,onChange:n,value:i}=e;return W.jsx(ze.default,{components:ia,instanceId:"tags",isClearable:!1,isDisabled:u||a||p,isLoading:u,isMulti:!0,name:o,noOptionsMessage:()=>"No tags",onBlur:t,onChange:n,onCreateOption:l,options:r,placeholder:p?"Loading...":d,styles:na,value:i})}})]})},oa=K.forwardRef(((e,t)=>{const{description:n,disabled:a,error:i,label:s,name:o,placeholder:l,value:r}=e;return W.jsxs($.Box,{children:[W.jsx(qn,{description:n,error:i,label:s,name:o}),W.jsx($.TextInput,{autoComplete:"off",autoFocus:!0,defaultValue:r,disabled:a,id:o,name:o,placeholder:l,ref:t})]})})),la=K.forwardRef(((e,t)=>{const{description:n,disabled:a,error:i,label:s,name:o,placeholder:l,rows:r,value:d}=e;return W.jsxs($.Box,{children:[W.jsx(qn,{description:n,error:i,label:s,name:o}),W.jsx($.TextArea,{autoComplete:"off",defaultValue:d,disabled:a,id:o,name:o,placeholder:l,ref:t,rows:r})]})})),ra=e=>{const{disabled:t,isValid:n,lastUpdated:a,onClick:i}=e;let s;return s=n?a?W.jsxs(W.Fragment,{children:["Last updated",W.jsx("br",{})," ",Re.default(new Date(a),"PPp")]}):"No unpublished changes":"There are validation errors that need to be fixed before this document can be published",W.jsx($.Tooltip,{content:W.jsx($.Box,{padding:3,style:{maxWidth:"185px"},children:W.jsx($.Text,{muted:!0,size:1,children:s})}),disabled:"ontouchstart"in window,placement:"top",children:W.jsx($.Box,{children:W.jsx($.Button,{disabled:t,fontSize:1,onClick:i,text:"Save and close",tone:"primary"})})})},da=Se.default.img(b||(b=H(["\n --checkerboard-color: ",";\n\n display: block;\n width: 100%;\n height: 100%;\n object-fit: contain;\n\n ","\n"])),oe.hues.gray[900].hex,(e=>e.showCheckerboard&&le.css(j||(j=H(["\n background-image: linear-gradient(45deg, var(--checkerboard-color) 25%, transparent 25%),\n linear-gradient(-45deg, var(--checkerboard-color) 25%, transparent 25%),\n linear-gradient(45deg, transparent 75%, var(--checkerboard-color) 75%),\n linear-gradient(-45deg, transparent 75%, var(--checkerboard-color) 75%);\n background-size: 20px 20px;\n background-position: 0 0, 0 10px, 10px -10px, -10px 0;\n "]))))),ca=Me.object().shape({originalFilename:Me.string().required("Filename cannot be empty")}),ua=e=>{var t,n;const a=null==(t=null==e?void 0:e.originalFilename)?void 0:t.toLowerCase().lastIndexOf(".".concat(e.extension));return null==(n=null==e?void 0:e.originalFilename)?void 0:n.slice(0,a)},pa=e=>{var t,n,a;const{children:i,dialog:{assetId:s,id:o,lastCreatedTag:l,lastRemovedTagIds:r}}=e,d=Ye(),c=ee.useDispatch(),u=_t((e=>xt(e,String(s)))),p=_t(it),h=K.useRef(!1),[m,g]=K.useState(null==u?void 0:u.asset),[f,x]=K.useState("details"),y=u?null==u?void 0:u.asset:m,v=Je(p),b=_t((j=y,e=>{var t,n,a;const i=null==(a=null==(n=null==(t=null==j?void 0:j.opt)?void 0:t.media)?void 0:n.tags)?void 0:a.reduce(((t,n)=>{const a=e.tags.byIds[n._ref];return(null==a?void 0:a.tag)&&t.push(a),t}),[]);return i&&(null==i?void 0:i.length)>0?Je(i):null}));var j;const C=e=>({altText:(null==e?void 0:e.altText)||"",description:(null==e?void 0:e.description)||"",originalFilename:e?ua(e):void 0,opt:{media:{tags:b}},title:(null==e?void 0:e.title)||""}),w=null==b?void 0:b.map((e=>e.label)).join(","),{control:T,formState:{errors:k,isDirty:S,isValid:_},getValues:E,handleSubmit:M,register:R,reset:B,setValue:F}=he.useForm({defaultValues:C(null==u?void 0:u.asset),mode:"onChange",resolver:pe.yupResolver(ca)}),z=!u||(null==u?void 0:u.updating),D=()=>{(null==u?void 0:u.asset)&&c(Mt.showConfirmDeleteAssets({assets:[u],closeDialogId:null==u?void 0:u.asset._id}))},A=e=>{const{result:t,transition:n}=e;t&&"update"===n&&(g(t),B(C(t)))},O=async e=>{var t;if(!(null==u?void 0:u.asset))return;const n=Cn(e);c(It.updateRequest({asset:null==u?void 0:u.asset,closeDialogId:null==u?void 0:u.asset._id,formData:Q(Q({},n),{},{opt:{media:Q(Q({},n.opt.media),{},{tags:(null==(t=n.opt.media.tags)?void 0:t.map((e=>({_ref:e.value,_type:"reference",_weak:!0}))))||null})},originalFilename:"".concat(n.originalFilename,".").concat(null==u?void 0:u.asset.extension)})}))};K.useEffect((()=>{if(!(null==u?void 0:u.asset))return;const e=d.listen(ke.default(I||(I=H(["*[_id == $id]"]))),{id:null==u?void 0:u.asset._id}).subscribe(A);return()=>{null==e||e.unsubscribe()}}),[]),K.useEffect((()=>{h.current&&B({opt:{media:{tags:b}}},{errors:!0,dirtyFields:!0,isDirty:!0}),h.current=!0}),[w]),K.useEffect((()=>{if(l){const e=(E("opt.media.tags")||[]).concat([l]);F("opt.media.tags",e,{shouldDirty:!0})}}),[l]),K.useEffect((()=>{if(r){const e=(E("opt.media.tags")||[]).filter((e=>!r.includes(e.value)));F("opt.media.tags",e,{shouldDirty:!0})}}),[r]);const q=()=>W.jsx($.Box,{padding:3,children:W.jsxs($.Flex,{justify:"space-between",children:[W.jsx($.Button,{disabled:z,fontSize:1,mode:"bleed",onClick:D,text:"Delete",tone:"critical"}),W.jsx(ra,{disabled:z||!S||!_,isValid:_,lastUpdated:y._updatedAt,onClick:M(O)})]})});return y?W.jsxs(Mn,{footer:W.jsx(q,{}),header:"Asset details",id:o,onClose:()=>{c(Mt.remove({id:o}))},width:3,children:[W.jsxs($.Flex,{direction:["column-reverse","column-reverse","row-reverse"],children:[W.jsxs($.Box,{flex:1,marginTop:[5,5,0],padding:4,children:[W.jsxs($.TabList,{space:2,children:[W.jsx($.Tab,{"aria-controls":"details-panel",disabled:z,id:"details-tab",label:"Details",onClick:()=>x("details"),selected:"details"===f,size:2}),W.jsx($.Tab,{"aria-controls":"references-panel",disabled:z,id:"references-tab",label:"References",onClick:()=>x("references"),selected:"references"===f,size:2})]}),W.jsxs($.Box,{as:"form",marginTop:4,onSubmit:M(O),children:[!u&&W.jsx($.Card,{marginBottom:3,padding:3,radius:2,shadow:1,tone:"critical",children:W.jsx($.Text,{size:1,children:"This file cannot be found – it may have been deleted."})}),W.jsx("button",{style:{display:"none"},tabIndex:-1,type:"submit"}),W.jsx($.TabPanel,{"aria-labelledby":"details",hidden:"details"!==f,id:"details-panel",children:W.jsxs($.Stack,{space:3,children:[W.jsx(sa,{control:T,disabled:z,error:null==(n=null==(t=null==k?void 0:k.opt)?void 0:t.media)?void 0:n.tags,label:"Tags",name:"opt.media.tags",onCreateTag:e=>{c(ot.createRequest({assetId:null==y?void 0:y._id,name:e}))},options:v,placeholder:"Select or create...",value:b}),W.jsx(Ln,{disabled:z,error:null==k?void 0:k.originalFilename,extension:(null==y?void 0:y.extension)||"",label:"Filename",name:"originalFilename",ref:R,value:ua(y)}),W.jsx(oa,{disabled:z,error:null==k?void 0:k.title,label:"Title",name:"title",ref:R,value:null==y?void 0:y.title}),W.jsx(oa,{disabled:z,error:null==k?void 0:k.altText,label:"Alt Text",name:"altText",ref:R,value:null==y?void 0:y.altText}),W.jsx(la,{disabled:z,error:null==k?void 0:k.description,label:"Description",name:"description",ref:R,rows:3,value:null==y?void 0:y.description})]})}),W.jsx($.TabPanel,{"aria-labelledby":"references",hidden:"references"!==f,id:"references-panel",children:W.jsx($.Box,{marginTop:5,children:(null==u?void 0:u.asset)&&W.jsx(Rn,{assetId:null==u?void 0:u.asset._id})})})]})]}),W.jsxs($.Box,{flex:1,padding:4,children:[W.jsxs($.Box,{style:{aspectRatio:"1"},children:[wn(y)&&W.jsx(An,{asset:y}),Tn(y)&&W.jsx(da,{draggable:!1,showCheckerboard:!(null==(a=null==y?void 0:y.metadata)?void 0:a.isOpaque),src:In(y,{height:600,width:600})})]}),y&&W.jsx($.Box,{marginTop:4,children:W.jsx(En,{asset:y,item:u})})]})]}),i]}):null},ha=e=>{const{children:t,dialog:n}=e,a=ee.useDispatch(),i=()=>{a(Mt.remove({id:null==n?void 0:n.id}))},s=()=>{(null==n?void 0:n.closeDialogId)&&a(Mt.remove({id:null==n?void 0:n.closeDialogId})),(null==n?void 0:n.confirmCallbackAction)&&a(n.confirmCallbackAction),i()},o=()=>W.jsx($.Box,{padding:3,children:W.jsxs($.Flex,{justify:"space-between",children:[W.jsx($.Button,{fontSize:1,mode:"bleed",onClick:i,text:"Cancel"}),W.jsx($.Button,{fontSize:1,onClick:s,text:null==n?void 0:n.confirmText,tone:null==n?void 0:n.tone})]})}),l=()=>W.jsxs($.Flex,{align:"center",children:[W.jsx($.Box,{paddingX:1,children:W.jsx(G.WarningOutlineIcon,{})}),W.jsx($.Box,{marginLeft:2,children:null==n?void 0:n.headerTitle})]});return W.jsxs(Mn,{footer:W.jsx(o,{}),header:W.jsx(l,{}),id:"confirm",onClose:i,width:1,children:[W.jsx($.Box,{paddingX:4,paddingY:4,children:W.jsxs($.Stack,{space:3,children:[(null==n?void 0:n.title)&&W.jsx($.Text,{size:1,children:n.title}),(null==n?void 0:n.description)&&W.jsx($.Text,{muted:!0,size:1,children:W.jsx("em",{children:n.description})})]})}),t]})},ma=e=>{const{children:t,dialog:{id:n}}=e,a=ee.useDispatch(),i=K.useCallback((()=>{a(Mt.clear())}),[]);return W.jsxs(Mn,{header:"Filters",id:n,onClose:i,width:1,children:[W.jsxs($.Box,{padding:3,children:[W.jsx(hn,{layout:"stack"}),W.jsx(mn,{})]}),t]})},ga=Me.object().shape({name:Me.string().required("Name cannot be empty")}),fa=e=>{const{children:t,dialog:{id:n}}=e,a=ee.useDispatch(),i=_t((e=>e.tags.creating)),s=_t((e=>e.tags.creatingError)),{formState:{errors:o,isDirty:l,isValid:r},handleSubmit:d,register:c,setError:u}=he.useForm({defaultValues:{name:""},mode:"onChange",resolver:pe.yupResolver(ga)}),p=i,h=async e=>{const t=Cn(e);a(ot.createRequest({name:t.name}))};K.useEffect((()=>{s&&u("name",{message:null==s?void 0:s.message})}),[s]);const m=()=>W.jsx($.Box,{padding:3,children:W.jsx($.Flex,{justify:"flex-end",children:W.jsx(ra,{disabled:p||!l||!r,isValid:r,onClick:d(h)})})});return W.jsxs(Mn,{footer:W.jsx(m,{}),header:"Create Tag",id:n,onClose:()=>{a(Mt.clear())},width:1,children:[W.jsxs($.Box,{as:"form",padding:4,onSubmit:d(h),children:[W.jsx("button",{style:{display:"none"},tabIndex:-1,type:"submit"}),W.jsx(oa,{disabled:p,error:null==o?void 0:o.name,label:"Name",name:"name",ref:c})]}),t]})},xa=Me.object().shape({name:Me.string().required("Name cannot be empty")}),ya=e=>{const{children:t,dialog:{id:n,tagId:a}}=e,i=Ye(),s=ee.useDispatch(),o=_t((e=>st(e,String(a)))),[l,r]=K.useState(null==o?void 0:o.tag),d=o?null==o?void 0:o.tag:l,c=e=>{var t;return{name:(null==(t=null==e?void 0:e.name)?void 0:t.current)||""}},{formState:{errors:u,isDirty:p,isValid:h},handleSubmit:m,register:g,reset:f,setError:x}=he.useForm({defaultValues:c(null==o?void 0:o.tag),mode:"onChange",resolver:pe.yupResolver(xa)}),y=!o||(null==o?void 0:o.updating),v=async e=>{var t;if(!(null==o?void 0:o.tag))return;const n=Cn(e);s(ot.updateRequest({closeDialogId:null==(t=null==o?void 0:o.tag)?void 0:t._id,formData:{name:{_type:"slug",current:n.name}},tag:null==o?void 0:o.tag}))},b=()=>{var e;(null==o?void 0:o.tag)&&s(Mt.showConfirmDeleteTag({closeDialogId:null==(e=null==o?void 0:o.tag)?void 0:e._id,tag:null==o?void 0:o.tag}))},j=e=>{const{result:t,transition:n}=e;t&&"update"===n&&(r(t),f(c(t)))};K.useEffect((()=>{var e;(null==o?void 0:o.error)&&x("name",{message:null==(e=o.error)?void 0:e.message})}),[null==o?void 0:o.error]),K.useEffect((()=>{if(!(null==o?void 0:o.tag))return;const e=i.listen(ke.default(C||(C=H(["*[_id == $id]"]))),{id:null==o?void 0:o.tag._id}).subscribe(j);return()=>{null==e||e.unsubscribe()}}),[]);const I=()=>{var e;return W.jsx($.Box,{padding:3,children:W.jsxs($.Flex,{justify:"space-between",children:[W.jsx($.Button,{disabled:y,fontSize:1,mode:"bleed",onClick:b,text:"Delete",tone:"critical"}),W.jsx(ra,{disabled:y||!p||!h,isValid:h,lastUpdated:null==(e=null==o?void 0:o.tag)?void 0:e._updatedAt,onClick:m(v)})]})})};return d?W.jsxs(Mn,{footer:W.jsx(I,{}),header:"Edit Tag",id:n,onClose:()=>{s(Mt.remove({id:n}))},width:1,children:[W.jsxs($.Box,{as:"form",padding:4,onSubmit:m(v),children:[!o&&W.jsx($.Card,{marginBottom:3,padding:3,radius:2,shadow:1,tone:"critical",children:W.jsx($.Text,{size:1,children:"This tag cannot be found – it may have been deleted."})}),W.jsx("button",{style:{display:"none"},tabIndex:-1,type:"submit"}),W.jsx(oa,{disabled:y,error:null==u?void 0:u.name,label:"Name",name:"name",ref:g})]}),t]}):null},va=Se.default($.Flex)(w||(w=H(["\n height: ","px;\n"])),32),ba=Se.default($.Flex)(T||(T=H(["\n @media (pointer: fine) {\n visibility: hidden;\n }\n\n @media (hover: hover) and (pointer: fine) {\n ",":hover & {\n visibility: visible;\n }\n }\n"])),va),ja=e=>{const{disabled:t,icon:n,onClick:a,tone:i,tooltip:s}=e;return W.jsx($.Tooltip,{content:W.jsx($.Container,{padding:2,width:0,children:W.jsx($.Text,{muted:!0,size:1,children:s})}),disabled:"ontouchstart"in window,placement:"top",children:W.jsx($.Button,{disabled:t,fontSize:1,icon:n,mode:"bleed",onClick:a,padding:2,tone:i})})},Ia=e=>{var t,n;const{actions:a,tag:i}=e,s=ee.useDispatch(),o=_t(bt),l=_t(dt),r=_t((e=>{var t;return ct(e,null==(t=null==i?void 0:i.tag)?void 0:t._id)}));return W.jsxs(va,{align:"center",flex:1,justify:"space-between",paddingLeft:3,children:[W.jsx($.Box,{flex:1,children:W.jsx($.Text,{size:1,style:{color:(null==i?void 0:i.updating)?oe.hues.gray[800].hex:oe.hues.gray[500].hex,userSelect:"none"},textOverflow:"ellipsis",children:null==(n=null==(t=null==i?void 0:i.tag)?void 0:t.name)?void 0:n.current})}),W.jsxs(ba,{align:"center",style:{flexShrink:0},children:[(null==a?void 0:a.includes("search"))&&W.jsx(ja,{disabled:null==i?void 0:i.updating,icon:r?W.jsx(G.CloseIcon,{}):W.jsx(G.SearchIcon,{}),onClick:r?()=>{s(ut.facetsRemove({facetName:"tag"}))}:()=>{var e,t,n;const a=Q(Q({},qe.tag),{},{value:{label:null==(t=null==(e=null==i?void 0:i.tag)?void 0:e.name)?void 0:t.current,value:null==(n=null==i?void 0:i.tag)?void 0:n._id}});s(l?ut.facetsUpdate({name:"tag",operatorType:"references",value:a.value}):ut.facetsAdd({facet:a}))},tooltip:r?"Remove filter":"Filter by tag"}),(null==a?void 0:a.includes("edit"))&&W.jsx(ja,{disabled:null==i?void 0:i.updating,icon:W.jsx(G.EditIcon,{}),onClick:()=>{var e;s(tt.showTagEdit({tagId:null==(e=null==i?void 0:i.tag)?void 0:e._id}))},tone:"primary",tooltip:"Edit tag"}),(null==a?void 0:a.includes("applyAll"))&&W.jsx(ja,{disabled:null==i?void 0:i.updating,icon:W.jsx(G.ArrowUpIcon,{}),onClick:()=>{s(Mt.showConfirmAssetsTagAdd({assetsPicked:o,tag:i.tag}))},tone:"primary",tooltip:"Add tag to selected assets"}),(null==a?void 0:a.includes("removeAll"))&&W.jsx(ja,{disabled:null==i?void 0:i.updating,icon:W.jsx(G.ArrowDownIcon,{}),onClick:()=>{s(Mt.showConfirmAssetsTagRemove({assetsPicked:o,tag:i.tag}))},tone:"critical",tooltip:"Remove tag from selected assets"}),(null==a?void 0:a.includes("delete"))&&W.jsx(ja,{disabled:null==i?void 0:i.updating,icon:W.jsx(G.TrashIcon,{}),onClick:()=>{s(Mt.showConfirmDeleteTag({tag:i.tag}))},tone:"critical",tooltip:"Delete tag"})]})]})},Ca=K.memo((e=>{let{isScrolling:t,item:n}=e;var a;return"string"==typeof n?W.jsx($.Flex,{align:"center",justify:"space-between",paddingX:3,style:{height:"".concat(32,"px")},children:W.jsx($.Label,{size:0,children:n})},n):W.jsx(Ia,{actions:t?void 0:n.actions,tag:n},null==(a=n.tag)?void 0:a._id)})),wa=()=>{const e=_t(bt),t=_t(it),[n,a]=K.useState(!1),i=null==e?void 0:e.reduce(((e,t)=>{var n,a,i,s;const o=(null==(s=null==(i=null==(a=null==(n=null==t?void 0:t.asset)?void 0:n.opt)?void 0:a.media)?void 0:i.tags)?void 0:s.map((e=>e._ref)))||[];return e=e.concat(o)}),[]),s=[...new Set(i)],o=s.reduce(((t,n)=>{const a=e.every((e=>{var t,a,i,s;return(null!=(s=null==(i=null==(a=null==(t=e.asset.opt)?void 0:t.media)?void 0:a.tags)?void 0:i.findIndex((e=>e._ref===n)))?s:-1)>=0}));return a?t.appliedToAll.push(n):t.appliedToSome.push(n),t}),{appliedToAll:[],appliedToSome:[]}),l=t.filter((e=>o.appliedToAll.includes(e.tag._id))).map((e=>Q(Q({},e),{},{actions:["delete","edit","removeAll","search"]}))),r=t.filter((e=>o.appliedToSome.includes(e.tag._id))).map((e=>Q(Q({},e),{},{actions:["applyAll","delete","edit","removeAll","search"]}))),d=t.filter((e=>!s.includes(e.tag._id))).map((e=>Q(Q({},e),{},{actions:["applyAll","delete","edit","search"]})));let c=[];return 0===e.length?c=t.map((e=>Q(Q({},e),{},{actions:["delete","edit","search"]}))):((null==l?void 0:l.length)>0&&(c=[...c,1===e.length?"Used":"Used by all",...l]),(null==r?void 0:r.length)>0&&(c=[...c,"Used by some",...r]),(null==d?void 0:d.length)>0&&(c=[...c,"Unused",...d])),W.jsx(ue.Virtuoso,{className:"media__custom-scrollbar",computeItemKey:e=>{const t=c[e];return"string"==typeof t?t:t.tag._id},isScrolling:a,itemContent:e=>W.jsx(Ca,{isScrolling:n,item:c[e]}),style:{flex:1,overflowX:"hidden"},totalCount:c.length})},Ta=e=>{var t,n;const{allowCreate:a,light:i,title:s}=e,o=ee.useDispatch(),l=_t((e=>e.tags.creating)),r=_t((e=>e.tags.fetching));return W.jsx(W.Fragment,{children:W.jsxs($.Flex,{align:"center",justify:"space-between",paddingLeft:3,style:{background:i?null==(t=oe.hues.gray)?void 0:t[900].hex:oe.black.hex,borderBottom:"1px solid ".concat(null==(n=oe.hues.gray)?void 0:n[900].hex),height:"".concat(32,"px")},children:[W.jsxs($.Inline,{space:2,children:[W.jsx($.Label,{size:0,children:s}),r&&W.jsx($.Label,{size:0,style:{opacity:.3},children:"Loading..."})]}),a&&W.jsx($.Box,{marginRight:1,children:W.jsx($.Button,{disabled:l,fontSize:1,icon:G.ComposeIcon,mode:"bleed",onClick:()=>{o(tt.showTagCreate())},style:{background:"transparent",boxShadow:"none"}})})]})})},ka=()=>{const e=_t(jt),t=_t(it),n=_t((e=>e.tags.fetching)),a=-1!==_t((e=>e.tags.fetchCount)),i=!n&&(null==t?void 0:t.length)>0,s=!!(e>0);return W.jsxs($.Flex,{direction:"column",flex:1,style:{background:oe.black.hex,height:"100%"},children:[W.jsx(Ta,{allowCreate:!0,light:s,title:s?"Tags (in selection)":"Tags"}),a&&!i&&W.jsx($.Box,{padding:3,children:W.jsx($.Text,{size:1,style:{color:oe.hues.gray[700].hex},children:W.jsx("em",{children:"No tags"})})}),i&&W.jsx(wa,{})]})},Sa=e=>{const{children:t,dialog:{id:n}}=e,a=ee.useDispatch(),i=K.useCallback((()=>{a(Mt.clear())}),[]);return W.jsxs(Mn,{header:"All Tags",id:n,onClose:i,width:1,children:[W.jsx($.Box,{style:{height:"100%",minHeight:"420px"},children:W.jsx(ka,{})}),t]})},_a=()=>{const e=_t((e=>e.dialog.items)),t=(e,n)=>{if(0===e.length||n>=e.length)return null;const a=e[n],i=t(e,n+1);return"assetEdit"===a.type?W.jsx(pa,{dialog:a,children:i},n):"confirm"===a.type?W.jsx(ha,{dialog:a,children:i},n):"searchFacets"===a.type?W.jsx(ma,{dialog:a,children:i},n):"tagCreate"===a.type?W.jsx(fa,{dialog:a,children:i},n):"tagEdit"===a.type?W.jsx(ya,{dialog:a,children:i},n):"tags"===a.type?W.jsx(Sa,{dialog:a,children:i},n):null};return t(e,0)},Ea=K.createContext(void 0),Ma=e=>{const{children:t,open:n}=e,a={open:n};return W.jsx(Ea.Provider,{value:a,children:t})},Ra=e=>{const{onClose:t}=e,{open:n}=(()=>{const e=K.useContext(Ea);if(void 0===e)throw new Error("useDropzoneActions must be used within an DropzoneDispatchProvider");return e})(),{onSelect:a}=He(),i=_t((e=>e.assets.assetTypes)),s=_t((e=>e.selected.document));return W.jsx($.Box,{paddingY:2,children:W.jsxs($.Flex,{align:"center",justify:"space-between",children:[W.jsx($.Box,{flex:1,marginX:3,children:W.jsxs($.Inline,{style:{whiteSpace:"nowrap"},children:[W.jsx($.Text,{textOverflow:"ellipsis",weight:"semibold",children:W.jsx("span",{children:a?"Insert ".concat(i.join(" or ")):"Browse Assets"})}),s&&W.jsx($.Box,{display:["none","none","block"],children:W.jsxs($.Text,{children:[W.jsx("span",{style:{margin:"0 0.5em"},children:W.jsx(G.Icon,{symbol:"arrow-right"})}),W.jsx("span",{style:{textTransform:"capitalize"},children:s._type})]})})]})}),W.jsxs($.Flex,{marginX:2,children:[W.jsx($.Button,{fontSize:1,icon:G.UploadIcon,mode:"bleed",onClick:n,text:"Upload ".concat(1===i.length?_e.default(i[0]):"assets"),tone:"primary"}),t&&W.jsx($.Box,{style:{flexShrink:0},children:W.jsx($.Button,{disabled:!t,icon:G.CloseIcon,mode:"bleed",onClick:t,radius:2})})]})]})})},Ba=te.createSelector([e=>e.assets.allIds,e=>e.uploads.allIds],((e,t)=>{const n=e.map((e=>({id:e,type:"asset"})));return[...t.map((e=>({id:e,type:"upload"}))),...n]})),Fa=Se.default($.Flex)(k||(k=H(["\n box-sizing: border-box;\n height: 100%;\n overflow: hidden;\n padding: 2px;\n position: relative;\n width: 100%;\n"]))),za=Se.default($.Flex)(S||(S=H(["\n border: 1px solid transparent;\n height: 100%;\n pointer-events: ",";\n position: relative;\n transition: all 300ms;\n user-select: none;\n width: 100%;\n\n border: ",";\n\n ","\n"])),(e=>e.updating?"none":"auto"),(e=>e.picked?"1px solid ".concat(e.theme.sanity.color.spot.orange," !important"):"1px solid inherit"),(e=>!e.updating&&le.css(_||(_=H(["\n @media (hover: hover) and (pointer: fine) {\n &:hover {\n border: 1px solid ",";\n }\n }\n "])),oe.hues.gray[500].hex))),Da=Se.default($.Flex)(E||(E=H(["\n cursor: ",";\n height: ","px;\n transition: all 300ms;\n\n @media (hover: hover) and (pointer: fine) {\n &:hover {\n background: ",";\n }\n }\n"])),(e=>e.selected?"default":"pointer"),32,oe.hues.gray[950].hex),Aa=Se.default(G.WarningFilledIcon)((e=>{let{theme:t}=e;return{color:t.sanity.color.spot.red}}));var Oa=K.memo((e=>{var t,n;const{id:a,selected:i}=e,s=Ae("shift"),o=ee.useDispatch(),l=_t((e=>e.assets.lastPicked)),r=_t((e=>xt(e,a))),d=null==r?void 0:r.asset,c=null==r?void 0:r.error,u=null==(n=null==(t=null==r?void 0:r.asset)?void 0:t.metadata)?void 0:n.isOpaque,p=null==r?void 0:r.picked,h=null==r?void 0:r.updating,{onSelect:m}=He();if(!d)return null;const g=h?.5:1,f=i||h?.25:1;return W.jsx(Fa,{children:W.jsxs(za,{direction:"column",picked:p,updating:r.updating,children:[W.jsxs($.Box,{flex:1,style:{cursor:i?"default":"pointer",position:"relative"},children:[W.jsxs("div",{onClick:e=>{e.stopPropagation(),m?m([{kind:"assetDocumentId",value:d._id}]):s.current?o(p?It.pick({assetId:d._id,picked:!p}):It.pickRange({startId:l||d._id,endId:d._id})):o(Mt.showAssetEdit({assetId:d._id}))},style:{height:"100%",opacity:f},children:[wn(d)&&W.jsx(Dn,{extension:d.extension,width:"80px"}),Tn(d)&&W.jsx(da,{draggable:!1,showCheckerboard:!u,src:In(d,{height:250,width:250}),style:{draggable:!1,transition:"opacity 1000ms"}})]}),i&&!h&&W.jsx($.Flex,{align:"center",justify:"center",style:{height:"100%",left:0,opacity:g,position:"absolute",top:0,width:"100%"},children:W.jsx($.Text,{size:2,children:W.jsx(G.CheckmarkCircleIcon,{})})}),h&&W.jsx($.Flex,{align:"center",justify:"center",style:{height:"100%",left:0,position:"absolute",top:0,width:"100%"},children:W.jsx($.Spinner,{})})]}),W.jsxs(Da,{align:"center",onClick:e=>{e.stopPropagation(),m?o(Mt.showAssetEdit({assetId:d._id})):s.current&&!p?o(It.pickRange({startId:l||d._id,endId:d._id})):o(It.pick({assetId:d._id,picked:!p}))},paddingX:1,style:{opacity:g},children:[m?W.jsx(G.EditIcon,{style:{flexShrink:0,opacity:.5}}):W.jsx($.Checkbox,{checked:p,readOnly:!0,style:{flexShrink:0,pointerEvents:"none",transform:"scale(0.8)"}}),W.jsx($.Box,{marginLeft:2,children:W.jsx($.Text,{muted:!0,size:0,textOverflow:"ellipsis",children:d.originalFilename})})]}),c&&W.jsx($.Box,{padding:3,style:{position:"absolute",right:0,top:0},children:W.jsx($.Tooltip,{content:W.jsx($.Container,{padding:2,width:0,children:W.jsx($.Text,{size:1,children:c})}),placement:"left",portal:!0,children:W.jsx($.Text,{size:1,children:W.jsx(Aa,{color:"critical"})})})})]})})}));const qa=async e=>{const t=await(e=>new Promise((t=>{const n=window.URL.createObjectURL(e),a=new Image;a.onload=()=>{window.URL.revokeObjectURL(n),t(a)},a.src=n})))(e),n=await(a=t,new Promise((e=>{const t=a.width/a.height,n=document.createElement("canvas");n.width=180,n.height=Math.max(180/t,1);try{const i=n.getContext("2d");null==i||i.drawImage(a,0,0,180,180/t),n.toBlob(e,"image/jpeg")}catch(e){console.warn("Unable to generate preview image:",e)}})));var a;if(!n)throw Error("Unable to generate file Blob");return window.URL.createObjectURL(n)};function La(e,t){const n=e.indexOf(t);return n>-1&&e.splice(n,1),e}const Pa=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:4;const t=[],n=[],a=new ie.Subject;function i(o){return new ie.Observable((l=>{if(t.length>=e)return s(o).pipe(se.mergeMap(i)).subscribe(l);const r=o.subscribe(l);return t.push(r),()=>{for(La(t,r),La(n,o),r.unsubscribe();n.length>0&&t.length<e;)a.next(n.shift())}}))}function s(e){return n.push(e),a.asObservable().pipe(se.first((t=>t===e)))}return i},Ua=e=>Array.prototype.map.call(new Uint8Array(e),(e=>"00".concat(e.toString(16)).slice(-2))).join(""),Va=e=>window.crypto&&window.crypto.subtle&&window.FileReader?(e=>new ie.Observable((t=>{const n=new FileReader;return n.onload=()=>{t.next(n.result),t.complete()},n.onerror=e=>{t.error(e)},n.readAsArrayBuffer(e),()=>{n.abort()}})))(e).pipe(se.mergeMap((e=>window.crypto.subtle.digest("SHA-1",e))),se.map(Ua)):ie.throwError({message:"Unable to generate hash: uploads are only allowed in secure contexts",statusCode:500}),Na=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;const n=Pa(t);return function(){return ie.from(n(e(...arguments)))}}(((e,t,n,a)=>ie.of(null).pipe(se.mergeMap((()=>((e,t,n)=>e.observable.fetch("*[_type == $documentType && sha1hash == $hash][0]",{documentType:t,hash:n}))(e,"sanity.".concat(t,"Asset"),a))),se.mergeMap((e=>e?ie.throwError({message:"Asset already exists",statusCode:409}):ie.of(null))),se.mergeMap((()=>e.observable.assets.upload(t,n,{extract:["blurhash","exif","location","lqip","palette"],preserveFilename:!0}).pipe(se.map((e=>"response"===e.type?{asset:e.body.document,id:e.body.document._id,type:"complete"}:e)))))))),Qa=te.createSlice({name:"uploads",initialState:{allIds:[],byIds:{}},extraReducers:e=>{e.addCase(ht.uploadComplete,((e,t)=>{const{asset:n}=t.payload;e.byIds[n.sha1hash]&&(e.byIds[n.sha1hash].status="complete")}))},reducers:{checkRequest(e,t){},checkComplete(e,t){const{results:n}=t.payload;Object.keys(n).forEach((t=>{const n=e.allIds.indexOf(t);if(n>=0&&e.allIds.splice(n,1),e.byIds[t]){const n=e.byIds[t].objectUrl;n&&window.URL.revokeObjectURL(n),delete e.byIds[t]}}))},previewReady(e,t){const{blobUrl:n,hash:a}=t.payload;e.byIds[a]&&(e.byIds[a].objectUrl=n)},uploadCancel(e,t){const{hash:n}=t.payload,a=e.allIds.indexOf(n);a>=0&&e.allIds.splice(a,1),e.byIds[n]&&delete e.byIds[n]},uploadError(e,t){const{hash:n}=t.payload,a=e.allIds.indexOf(n);a>=0&&e.allIds.splice(a,1),delete e.byIds[n]},uploadRequest(e,t){},uploadProgress(e,t){const{event:n,uploadHash:a}=t.payload;e.byIds[a].percent=n.percent,e.byIds[a].status="uploading"},uploadStart(e,t){const{uploadItem:n}=t.payload;e.allIds.includes(n.hash)||e.allIds.push(n.hash),e.byIds[n.hash]=n}}}),Xa=te.createSelector([e=>e.uploads.byIds,(e,t)=>t],((e,t)=>e[t]));te.createSelector([e=>e.uploads.byIds,e=>e.uploads.allIds],((e,t)=>t.map((t=>e[t]))));const Ha=Qa.actions;var Ya=Qa.reducer;const Ga=Se.default($.Flex)(R||(R=H(["\n box-sizing: border-box;\n height: 100%;\n overflow: hidden;\n padding: 2px;\n position: relative;\n width: 100%;\n"]))),Wa=e=>{const{id:t}=e,n=ee.useDispatch(),a=_t((e=>Xa(e,t)));if(!a)return null;const i=Be.default(a.size,{base:10,round:0}),s=Math.round(a.percent||0),o="complete"===a.status,l="uploading"===a.status,r="queued"===a.status;let d;o&&(d="Verifying"),l&&(d="".concat(s,"%")),r&&(d="Queued");return W.jsx(Ga,{children:W.jsxs($.Flex,{direction:"column",flex:1,style:{background:oe.hues.gray[950].hex,border:"1px solid transparent",height:"100%",position:"relative"},children:[W.jsx("div",{style:{background:oe.hues.gray[600].hex,bottom:0,height:"1px",left:0,position:"absolute",width:"100%",transform:"scaleX(".concat(.01*s,")"),transformOrigin:"bottom left",transition:"all 1000ms ease-out"}}),W.jsxs($.Box,{flex:1,style:{position:"relative"},children:["image"===a.assetType&&(null==a?void 0:a.objectUrl)&&W.jsx(da,{draggable:!1,src:a.objectUrl,style:{opacity:.4}}),"file"===a.assetType&&W.jsx("div",{style:{height:"100%",opacity:.1},children:W.jsx(Dn,{width:"80px"})}),!o&&100!==s&&W.jsx($.Flex,{align:"center",direction:"column",justify:"center",style:{height:"100%",left:0,position:"absolute",top:0,width:"100%"},children:W.jsx($.Tooltip,{content:W.jsx($.Box,{padding:2,children:W.jsx($.Text,{muted:!0,size:1,children:"Cancel"})}),disabled:"ontouchstart"in window,placement:"top",children:W.jsx($.Button,{fontSize:4,icon:G.CloseIcon,mode:"bleed",onClick:()=>{n(Ha.uploadCancel({hash:a.hash}))},padding:2,style:{background:"none",boxShadow:"none"},tone:"critical"})})})]}),W.jsxs($.Flex,{align:"center",justify:"space-between",paddingX:2,style:{height:"".concat(32,"px")},children:[W.jsx($.Box,{flex:1,marginRight:1,children:W.jsxs($.Text,{size:0,textOverflow:"ellipsis",children:[a.name," (",i,")"]})}),W.jsx($.Text,{size:0,style:{flexShrink:0},weight:"semibold",children:d})]})]})})},$a=K.memo((e=>{let{item:t,selected:n}=e;return"asset"===(null==t?void 0:t.type)?W.jsx(Oa,{id:t.id,selected:n}):"upload"===(null==t?void 0:t.type)?W.jsx(Wa,{id:t.id}):null})),Ka=Se.default.div(B||(B=H(["\n height: ","px;\n width: ","px;\n"])),220,240),Za=Se.default.div(F||(F=H(["\n display: grid;\n grid-template-columns: repeat(auto-fill, ","px);\n justify-content: center;\n margin: 0 auto;\n"])),240),Ja=e=>{const{items:t,onLoadMore:n}=e,a=_t((e=>e.selected.assets)),i=a&&a.map((e=>e._id))||[],s=null==t?void 0:t.length;return 0===s?null:W.jsx(ue.VirtuosoGrid,{className:"media__custom-scrollbar",computeItemKey:e=>{const n=t[e];return null==n?void 0:n.id},components:{Item:Ka,List:Za},endReached:n,itemContent:e=>{const n=t[e],a=i.includes(null==n?void 0:n.id);return W.jsx($a,{item:n,selected:a})},overscan:48,style:{overflowX:"hidden"},totalCount:s})},ei=e=>{const{field:t,title:n}=e,a=ee.useDispatch(),i=_t((e=>e.assets.order)),s=i.field===t;return W.jsx($.Label,{muted:!t,size:0,children:W.jsxs($.Box,{onClick:t?()=>{if(t&&n)if(s){const e="asc"===i.direction?"desc":"asc";a(It.orderSet({order:{field:t,direction:e}}))}else a(It.orderSet({order:{field:t,direction:"asc"}}))}:void 0,style:{cursor:t?"pointer":"default",display:"inline",whiteSpace:"nowrap"},children:[W.jsx("span",{style:{marginRight:"0.4em"},children:n}),s&&"asc"===(null==i?void 0:i.direction)&&W.jsx(G.ChevronUpIcon,{}),s&&"desc"===(null==i?void 0:i.direction)&&W.jsx(G.ChevronDownIcon,{})]})})};var ti;const ni=Se.default($.Flex)(z||(z=H(["\n cursor: pointer;\n\n @media (hover: hover) and (pointer: fine) {\n &:hover {\n background: ",";\n }\n }\n"])),null==(ti=oe.hues.gray)?void 0:ti[900].hex),ai=()=>{var e;const t=ee.useDispatch(),n=_t((e=>e.assets.fetching)),a=_t(vt),i=_t(jt),s=$.useMediaIndex(),{onSelect:o}=He(),l=i===a;return W.jsxs($.Grid,{style:{alignItems:"center",background:oe.black.hex,borderBottom:"1px solid ".concat(null==(e=oe.hues.gray)?void 0:e[900].hex),gridColumnGap:s<3?0:"16px",gridTemplateColumns:Ne,height:s<3?0:"".concat(32,"px"),letterSpacing:"0.025em",position:"sticky",textTransform:"uppercase",top:0,visibility:s<3?"hidden":"visible",width:"100%",zIndex:1},children:[o?W.jsx(ei,{}):W.jsx(ni,{align:"center",justify:"center",onClick:e=>{e.stopPropagation(),t(l?It.pickClear():It.pickAll())},style:{height:"100%",position:"relative"},children:W.jsx($.Checkbox,{checked:!n&&l,readOnly:!0,style:{pointerEvents:"none",transform:"scale(0.8)"}})}),W.jsx(ei,{}),W.jsx(ei,{field:"originalFilename",title:"Filename"}),W.jsx(ei,{title:"Resolution"}),W.jsx(ei,{field:"mimeType",title:"MIME type"}),W.jsx(ei,{field:"size",title:"Size"}),W.jsx(ei,{field:"_updatedAt",title:"Last updated"}),W.jsx(ei,{})]})};var ii;const si=Se.default($.Grid)(D||(D=H(["\n align-items: center;\n cursor: ",";\n height: 100%;\n pointer-events: ",";\n user-select: none;\n white-space: nowrap;\n\n ","\n"])),(e=>e.selected?"default":"pointer"),(e=>e.updating?"none":"auto"),(e=>{var t;return!e.updating&&le.css(A||(A=H(["\n @media (hover: hover) and (pointer: fine) {\n &:hover {\n background: ",";\n }\n }\n "])),null==(t=oe.hues.gray)?void 0:t[950].hex)})),oi=Se.default($.Flex)(O||(O=H(["\n cursor: pointer;\n\n @media (hover: hover) and (pointer: fine) {\n &:hover {\n background: ",";\n }\n }\n"])),null==(ii=oe.hues.gray)?void 0:ii[900].hex),li=Se.default(G.WarningFilledIcon)((e=>{let{theme:t}=e;return{color:t.sanity.color.spot.red}}));var ri=K.memo((e=>{var t,n;const{id:a,selected:i}=e,s=Ae("shift"),o=ee.useDispatch(),l=_t((e=>e.assets.lastPicked)),r=_t((e=>xt(e,a))),d=$.useMediaIndex(),c=null==r?void 0:r.asset,u=null==r?void 0:r.error,p=null==(n=null==(t=null==r?void 0:r.asset)?void 0:t.metadata)?void 0:n.isOpaque,h=null==r?void 0:r.picked,m=null==r?void 0:r.updating,{onSelect:g}=He();if(!c)return null;const f=m?.5:1,x=i||m?.1:1;return W.jsxs(si,{onClick:i?void 0:e=>{e.stopPropagation(),g?g([{kind:"assetDocumentId",value:c._id}]):s.current?o(h?It.pick({assetId:c._id,picked:!h}):It.pickRange({startId:l||c._id,endId:c._id})):o(Mt.showAssetEdit({assetId:c._id}))},selected:i,style:{gridColumnGap:d<3?0:"16px",gridRowGap:0,gridTemplateColumns:d<3?Ve:Ne,gridTemplateRows:d<3?"auto":"1fr"},updating:r.updating,children:[W.jsx(oi,{onClick:e=>{e.stopPropagation(),g?o(Mt.showAssetEdit({assetId:c._id})):s.current&&!h?o(It.pickRange({startId:l||c._id,endId:c._id})):o(It.pick({assetId:c._id,picked:!h}))},style:{alignItems:"center",gridColumn:1,gridRowStart:1,gridRowEnd:"span 5",height:"100%",justifyContent:"center",opacity:f,position:"relative"},children:g?W.jsx(G.EditIcon,{style:{flexShrink:0,opacity:.5}}):W.jsx($.Checkbox,{checked:h,readOnly:!0,style:{pointerEvents:"none",transform:"scale(0.8)"}})}),W.jsx($.Box,{style:{gridColumn:2,gridRowStart:1,gridRowEnd:"span 5",height:"90px",width:"100px"},children:W.jsxs($.Flex,{align:"center",justify:"center",style:{height:"100%",position:"relative"},children:[W.jsxs($.Box,{style:{height:"100%",opacity:x,position:"relative"},children:[wn(c)&&W.jsx(Dn,{extension:c.extension,width:"40px"}),Tn(c)&&W.jsx(da,{draggable:!1,showCheckerboard:!p,src:In(c,{height:100,width:100})})]}),m&&W.jsx($.Flex,{align:"center",justify:"center",style:{height:"100%",left:0,position:"absolute",top:0,width:"100%"},children:W.jsx($.Spinner,{})}),i&&!m&&W.jsx($.Flex,{align:"center",justify:"center",style:{height:"100%",left:0,position:"absolute",top:0,width:"100%"},children:W.jsx($.Text,{size:2,children:W.jsx(G.CheckmarkCircleIcon,{})})})]})}),W.jsx($.Box,{marginLeft:d<3?3:0,style:{gridColumn:3,gridRow:d<3?2:"auto",opacity:f},children:W.jsx($.Text,{muted:!0,size:1,style:{lineHeight:"2em"},textOverflow:"ellipsis",children:c.originalFilename})}),W.jsx($.Box,{marginLeft:d<3?3:0,style:{gridColumn:d<3?3:4,gridRow:d<3?3:"auto",opacity:f},children:W.jsx($.Text,{muted:!0,size:1,style:{lineHeight:"2em"},textOverflow:"ellipsis",children:Tn(c)&&kn(c)})}),W.jsx($.Box,{style:{display:d<3?"none":"block",gridColumn:5,gridRow:"auto",opacity:f},children:W.jsx($.Text,{muted:!0,size:1,style:{lineHeight:"2em"},textOverflow:"ellipsis",children:c.mimeType})}),W.jsx($.Box,{style:{display:d<3?"none":"block",gridColumn:6,gridRow:"auto",opacity:f},children:W.jsx($.Text,{muted:!0,size:1,style:{lineHeight:"2em"},textOverflow:"ellipsis",children:Be.default(c.size,{base:10,round:0})})}),W.jsx($.Box,{marginLeft:d<3?3:0,style:{gridColumn:d<3?3:7,gridRow:d<3?4:"auto",opacity:f},children:W.jsx($.Text,{muted:!0,size:1,style:{lineHeight:"2em"},textOverflow:"ellipsis",children:De.default(new Date(c._updatedAt),new Date)})}),W.jsx($.Flex,{align:"center",justify:"center",style:{gridColumn:d<3?4:8,gridRowStart:"1",gridRowEnd:d<3?"span 5":"auto",opacity:f},children:u&&W.jsx($.Box,{padding:2,children:W.jsx($.Tooltip,{content:W.jsx($.Container,{padding:2,width:0,children:W.jsx($.Text,{size:1,children:u})}),placement:"left",portal:!0,children:W.jsx($.Text,{size:1,children:W.jsx(li,{color:"critical"})})})})})]})}));const di=e=>{const{id:t}=e,n=ee.useDispatch(),a=_t((e=>Xa(e,t))),i=$.useMediaIndex();if(!a)return null;const s=Be.default(a.size,{base:10,round:0}),o=Math.round(a.percent||0),l="complete"===a.status,r="uploading"===a.status,d="queued"===a.status;let c;l&&(c="Verifying"),r&&(c="".concat(o,"%")),d&&(c="Queued");return W.jsxs($.Grid,{style:{alignItems:"center",background:oe.hues.gray[950].hex,gridColumnGap:i<3?0:"16px",gridRowGap:0,gridTemplateColumns:i<3?Ve:Ne,gridTemplateRows:i<3?"auto":"1fr",height:"100%",position:"relative"},children:[W.jsx("div",{style:{background:oe.hues.gray[600].hex,bottom:0,height:"1px",left:0,position:"absolute",width:"100%",transform:"scaleX(".concat(.01*o,")"),transformOrigin:"bottom left",transition:"all 1000ms ease-out"}}),W.jsx($.Box,{style:{gridColumn:2,gridRowStart:i<3?1:"auto",gridRowEnd:i<3?"span 4":"auto",height:"90px",width:"100px"},children:W.jsxs($.Box,{style:{height:"100%",position:"relative"},children:["image"===a.assetType&&(null==a?void 0:a.objectUrl)&&W.jsx(da,{draggable:!1,src:a.objectUrl,style:{opacity:.25}}),"file"===a.assetType&&W.jsx("div",{style:{height:"100%",opacity:.1},children:W.jsx(Dn,{width:"40px"})}),!l&&100!==o&&W.jsx($.Flex,{align:"center",justify:"center",style:{position:"absolute",height:"100%",left:0,top:0,width:"100%"},children:W.jsx($.Tooltip,{content:W.jsx($.Box,{padding:2,children:W.jsx($.Text,{muted:!0,size:1,children:"Cancel"})}),disabled:"ontouchstart"in window,placement:"top",children:W.jsx($.Button,{fontSize:3,icon:G.CloseIcon,mode:"bleed",onClick:()=>{n(Ha.uploadCancel({hash:a.hash}))},padding:2,style:{background:"none",boxShadow:"none"},tone:"critical"})})})]})}),W.jsx($.Box,{style:{gridColumn:i<3?3:"3/8",gridRow:i<3?"2/4":"auto",marginLeft:i<3?3:0},children:W.jsxs($.Stack,{space:3,children:[W.jsxs($.Text,{muted:!0,size:1,textOverflow:"ellipsis",children:[a.name," (",s,")"]}),W.jsx($.Text,{size:1,textOverflow:"ellipsis",weight:"semibold",children:c})]})})]})},ci=K.memo((e=>{let{item:t,selected:n}=e;return"asset"===(null==t?void 0:t.type)?W.jsx($.Box,{style:{height:"100px"},children:W.jsx(ri,{id:t.id,selected:n})}):"upload"===(null==t?void 0:t.type)?W.jsx($.Box,{style:{height:"100px"},children:W.jsx(di,{id:t.id})}):null})),ui=e=>{const{items:t,onLoadMore:n}=e,a=_t((e=>e.selected.assets)),i=a&&a.map((e=>e._id))||[],s=null==t?void 0:t.length;return 0===s?null:W.jsx(ue.GroupedVirtuoso,{className:"media__custom-scrollbar",computeItemKey:e=>{const n=t[e];return(null==n?void 0:n.id)||e},endReached:n,groupCounts:Array(1).fill(s),groupContent:()=>W.jsx(ai,{}),itemContent:e=>{const n=t[e],a=i.includes(null==n?void 0:n.id);return W.jsx(ci,{item:n,selected:a})},style:{overflowX:"hidden"}})},pi=()=>{const e=ee.useDispatch(),t=_t((e=>e.assets.fetchCount)),n=_t((e=>e.assets.fetching)),a=_t((e=>e.tags.panelVisible)),i=_t((e=>e.assets.view)),s=_t(Ba),o=(()=>{var e,t;const n=null==(t=null==(e=$.studioTheme)?void 0:e.container)?void 0:t.map((e=>window.matchMedia("(max-width: ".concat(e,"px)")))),a=()=>n.findIndex((e=>e.matches)),[i,s]=K.useState(a());return K.useEffect((()=>{const e=()=>{s(a)};return n.forEach((t=>{try{t.addEventListener("change",e)}catch(n){try{t.addListener(e)}catch(e){}}})),()=>{try{n.forEach((t=>t.removeEventListener("change",e)))}catch(t){try{n.forEach((t=>t.removeListener(e)))}catch(e){}}}}),[]),i})(),l=t>=0,r=s.length>0,d=()=>{n||e(It.loadNextPage())};K.useEffect((()=>{o<=1&&a&&e(ot.panelVisibleSet({panelVisible:!1}))}),[o]);const c=!r&&l&&!n;return W.jsx($.Box,{flex:1,style:{width:"100%"},children:c?W.jsx($.Box,{padding:4,children:W.jsx($.Text,{size:1,weight:"semibold",children:"No results for the current query"})}):W.jsxs(W.Fragment,{children:["grid"===i&&W.jsx(Ja,{items:s,onLoadMore:d}),"table"===i&&W.jsx(ui,{items:s,onLoadMore:d})]})})},hi=()=>{const e=_t((e=>e.notifications.items)),t=$.useToast();return K.useEffect((()=>{if(e.length>0){const n=e[e.length-1];t.push({closable:!0,status:n.status,title:n.title})}}),[e.length]),null},mi=()=>{var e,t;const n=ee.useDispatch(),a=_t(bt);return 0===a.length?null:W.jsx($.Flex,{align:"center",justify:"flex-start",style:{background:null==(e=oe.hues.gray)?void 0:e[900].hex,borderBottom:"1px solid ".concat(null==(t=oe.hues.gray)?void 0:t[900].hex),height:"".concat(32,"px"),position:"relative",width:"100%"},children:W.jsxs($.Flex,{align:"center",paddingX:3,children:[W.jsx($.Box,{paddingRight:2,children:W.jsxs($.Label,{size:0,style:{color:"inherit"},children:[a.length," ",_e.default("asset",a.length)," selected"]})}),W.jsx($.Button,{mode:"bleed",onClick:()=>{n(It.pickClear())},padding:2,style:{background:"none",boxShadow:"none"},tone:"default",children:W.jsx($.Label,{size:0,children:"Deselect"})}),W.jsx($.Button,{mode:"bleed",onClick:()=>{n(Mt.showConfirmDeleteAssets({assets:a}))},padding:2,style:{background:"none",boxShadow:"none"},tone:"critical",children:W.jsx($.Label,{size:0,children:"Delete"})})]})})};var gi=te.createSlice({name:"selected",initialState:{assets:[],document:void 0,documentAssetIds:[]},reducers:{}}).reducer;const fi=te.createSlice({name:"notifications",initialState:{items:[]},reducers:{add(e,t){const{asset:n,status:a,title:i}=t.payload;e.items.push({asset:n,status:a,title:i})}}}),xi=fi.actions;var yi=fi.reducer;const vi=ae.combineEpics(((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(It.deleteRequest.match),se.mergeMap((e=>{const{assets:t}=e.payload,n=t.map((e=>e._id));return ie.of(t).pipe(se.mergeMap((()=>a.observable.delete({query:ke.default(p||(p=H(["*[_id in ","]"])),JSON.stringify(n))}))),se.mergeMap((()=>ie.of(It.deleteComplete({assetIds:n})))),se.catchError((e=>ie.of(It.deleteError({assetIds:n,error:e})))))})))}),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(It.fetchRequest.match),se.withLatestFrom(t),se.switchMap((e=>{let[t,n]=e;var i,s;const o=null==(i=t.payload)?void 0:i.params,l=null==(s=t.payload)?void 0:s.query;return ie.of(t).pipe($e(n.debug.badConnection),se.mergeMap((()=>a.observable.fetch(l,o))),se.mergeMap((e=>{const{items:t}=e;return ie.of(It.fetchComplete({assets:t}))})),se.catchError((e=>ie.of(It.fetchError({message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500})))))})))}),((e,t)=>e.pipe(se.filter(It.deleteComplete.match),se.withLatestFrom(t),se.switchMap((e=>{let[t,n]=e;if(0===n.assets.allIds.length){const e=Math.floor(n.assets.allIds.length/n.assets.pageSize);return ie.of(It.loadPageIndex({pageIndex:e}))}return ie.empty()})))),((e,t)=>e.pipe(se.filter(It.loadNextPage.match),se.withLatestFrom(t),se.switchMap((e=>{let[t,n]=e;return ie.of(It.loadPageIndex({pageIndex:n.assets.pageIndex+1}))})))),((e,t)=>e.pipe(se.filter(It.loadPageIndex.match),se.withLatestFrom(t),se.switchMap((e=>{let[t,n]=e;var a,i,s,o,l,r;const d=n.assets.pageSize,c=t.payload.pageIndex*d,u=c+d,p=null==(a=null==n?void 0:n.selected.document)?void 0:a._id,g=null==(i=null==n?void 0:n.selected)?void 0:i.documentAssetIds,f=Ke({assetTypes:n.assets.assetTypes,searchFacets:n.search.facets,searchQuery:n.search.query}),x=Q(Q({},p?{documentId:p}:{}),{},{documentAssetIds:g});return ie.of(It.fetchRequest({params:x,queryFilter:f,selector:ke.default(h||(h=H(["[","...","]"])),c,u),sort:ke.default(m||(m=H(["order("," ",")"])),null==(o=null==(s=n.assets)?void 0:s.order)?void 0:o.field,null==(r=null==(l=n.assets)?void 0:l.order)?void 0:r.direction)}))})))),(e=>e.pipe(se.filter(It.listenerCreateQueue.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=null==e?void 0:e.map((e=>e.payload.asset));return ie.of(It.listenerCreateQueueComplete({assets:t}))})))),(e=>e.pipe(se.filter(It.listenerDeleteQueue.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=null==e?void 0:e.map((e=>e.payload.assetId));return ie.of(It.listenerDeleteQueueComplete({assetIds:t}))})))),(e=>e.pipe(se.filter(It.listenerUpdateQueue.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=null==e?void 0:e.map((e=>e.payload.asset));return ie.of(It.listenerUpdateQueueComplete({assets:t}))})))),(e=>e.pipe(se.filter(It.orderSet.match),se.mergeMap((()=>ie.of(It.clear(),It.loadPageIndex({pageIndex:0})))))),(e=>e.pipe(ae.ofType(ut.facetsAdd.type,ut.facetsClear.type,ut.facetsRemove.type,ut.facetsUpdate.type,ut.querySet.type),se.debounceTime(400),se.mergeMap((()=>ie.of(It.clear(),It.loadPageIndex({pageIndex:0})))))),(e=>e.pipe(ae.ofType(It.insertUploads.type,It.listenerUpdateQueueComplete.type,It.updateComplete.type),se.mergeMap((()=>ie.of(It.sort()))))),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(et.tagsAddRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{assets:i,tag:s}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),se.mergeMap((()=>{const e=bt(n),t=null==e?void 0:e.filter((e=>t=>{var n,a,i,s,o;return(null!=(o=null==(s=null==(i=null==(a=null==(n=null==t?void 0:t.asset)?void 0:n.opt)?void 0:a.media)?void 0:i.tags)?void 0:s.findIndex((t=>t._ref===(null==e?void 0:e._id))))?o:-1)<0})(s)),i=t.reduce(((e,t)=>{var n;return e.patch(null==(n=null==t?void 0:t.asset)?void 0:n._id,(e=>{let{tag:t}=e;return e=>e.setIfMissing({opt:{}}).setIfMissing({"opt.media":{}}).setIfMissing({"opt.media.tags":[]}).append("opt.media.tags",[{_key:ne.nanoid(),_ref:null==t?void 0:t._id,_type:"reference",_weak:!0}])})({tag:s}))}),a.transaction());return ie.from(i.commit())})),se.mergeMap((()=>ie.of(et.tagsAddComplete({assets:i,tag:s})))),se.catchError((e=>ie.of(et.tagsAddError({assets:i,error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500},tag:s})))))})))}),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(et.tagsRemoveRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{assets:i,tag:s}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),se.mergeMap((()=>{const e=bt(n).reduce(((e,t)=>{var n;return e.patch(null==(n=null==t?void 0:t.asset)?void 0:n._id,(e=>{let{asset:t,tag:n}=e;return e=>{var a;return e.ifRevisionId(null==(a=null==t?void 0:t.asset)?void 0:a._rev).unset(['opt.media.tags[_ref == "'.concat(n._id,'"]')])}})({asset:t,tag:s}))}),a.transaction());return ie.from(e.commit())})),se.mergeMap((()=>ie.of(et.tagsRemoveComplete({assets:i,tag:s})))),se.catchError((e=>ie.of(et.tagsRemoveError({assets:i,error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500},tag:s})))))})))}),(e=>e.pipe(ae.ofType(It.orderSet.type,It.viewSet.type,ut.facetsAdd.type,ut.facetsClear.type,ut.facetsRemove.type,ut.facetsUpdate.type,ut.querySet.type),se.mergeMap((()=>ie.of(It.pickClear()))))),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(It.updateRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{asset:i,closeDialogId:s,formData:o}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),se.mergeMap((()=>ie.from(a.patch(i._id).setIfMissing({opt:{}}).setIfMissing({"opt.media":{}}).set(o).commit()))),se.mergeMap((e=>ie.of(It.updateComplete({asset:e,closeDialogId:s})))),se.catchError((e=>ie.of(It.updateError({asset:i,error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500}})))))})))}),(e=>e.pipe(ae.ofType(It.deleteComplete.type,It.updateComplete.type,ot.deleteComplete.type,ot.updateComplete.type),se.filter((e=>{var t;return!!(null==(t=null==e?void 0:e.payload)?void 0:t.closeDialogId)})),se.mergeMap((e=>{var t;const n=null==(t=null==e?void 0:e.payload)?void 0:t.closeDialogId;return n?ie.of(Et.actions.remove({id:n})):ie.empty()})))),(e=>e.pipe(se.filter(ot.createComplete.match),se.mergeMap((e=>{const{assetId:t,tag:n}=null==e?void 0:e.payload;return t?ie.of(Et.actions.inlineTagCreate({tag:n,assetId:t})):n._id?ie.of(Et.actions.remove({id:"tagCreate"})):ie.empty()})))),(e=>e.pipe(se.filter(ot.listenerDeleteQueueComplete.match),se.mergeMap((e=>{const{tagIds:t}=null==e?void 0:e.payload;return ie.of(Et.actions.inlineTagRemove({tagIds:t}))})))),(e=>e.pipe(se.filter(It.deleteError.match),se.mergeMap((e=>{const{assetIds:t}=e.payload,n=t.length;return ie.of(fi.actions.add({status:"error",title:"Unable to delete ".concat(n," ").concat(_e.default("asset",n),". Please review any asset errors and try again.")}))})))),(e=>e.pipe(se.filter(It.deleteComplete.match),se.mergeMap((e=>{const{assetIds:t}=e.payload,n=t.length;return ie.of(fi.actions.add({status:"info",title:"".concat(n," ").concat(_e.default("asset",n)," deleted")}))})))),(e=>e.pipe(se.filter(et.tagsAddComplete.match),se.mergeMap((e=>{var t,n;const a=null==(n=null==(t=null==e?void 0:e.payload)?void 0:t.assets)?void 0:n.length;return ie.of(fi.actions.add({status:"info",title:"Tag added to ".concat(a," ").concat(_e.default("asset",a))}))})))),(e=>e.pipe(se.filter(et.tagsRemoveComplete.match),se.mergeMap((e=>{var t,n;const a=null==(n=null==(t=null==e?void 0:e.payload)?void 0:t.assets)?void 0:n.length;return ie.of(fi.actions.add({status:"info",title:"Tag removed from ".concat(a," ").concat(_e.default("asset",a))}))})))),(e=>e.pipe(se.filter(It.updateComplete.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=e.length;return ie.of(fi.actions.add({status:"info",title:"".concat(t," ").concat(_e.default("asset",t)," updated")}))})))),(e=>e.pipe(ae.ofType(It.fetchError.type,It.updateError.type,ot.createError.type,ot.deleteError.type,ot.fetchError.type,ot.updateError.type,Ha.uploadError.type),se.mergeMap((e=>{var t;const n=null==(t=e.payload)?void 0:t.error;return ie.of(fi.actions.add({status:"error",title:"An error occured: ".concat(n.message)}))})))),(e=>e.pipe(se.filter(ot.createComplete.match),se.mergeMap((()=>ie.of(fi.actions.add({status:"info",title:"Tag created"})))))),(e=>e.pipe(se.filter(ot.deleteComplete.match),se.mergeMap((()=>ie.of(fi.actions.add({status:"info",title:"Tag deleted"})))))),(e=>e.pipe(se.filter(ot.updateComplete.match),se.mergeMap((()=>ie.of(fi.actions.add({status:"info",title:"Tag updated"})))))),((e,t)=>e.pipe(se.filter(ot.updateComplete.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;var a,i,s,o,l;const{tag:r}=t.payload,d=null==(a=n.search.facets)?void 0:a.find((e=>"tag"===e.name)),c=n.tags.byIds[r._id];return"searchable"===(null==d?void 0:d.type)&&(null==(i=d.value)?void 0:i.value)===r._id?ie.of(rt.actions.facetsUpdate({name:"tag",value:{label:null==(o=null==(s=null==c?void 0:c.tag)?void 0:s.name)?void 0:o.current,value:null==(l=null==c?void 0:c.tag)?void 0:l._id}})):ie.empty()})))),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(nt.actions.createRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{assetId:i,name:s}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),Ze(a,s),se.mergeMap((()=>a.observable.create({_type:"media.tag",name:{_type:"slug",current:s}}))),se.mergeMap((e=>ie.of(nt.actions.createComplete({assetId:i,tag:e})))),se.catchError((e=>ie.of(nt.actions.createError({error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500},name:s})))))})))}),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(nt.actions.deleteRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{tag:i}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),se.mergeMap((()=>a.observable.fetch(ke.default(d||(d=H(['*[\n _type in ["sanity.fileAsset", "sanity.imageAsset"]\n && references(*[_type == "media.tag" && name.current == $tagName]._id)\n ] {\n _id,\n _rev,\n opt\n }']))),{tagName:i.name.current}))),se.mergeMap((e=>{const t=e.map((e=>({id:e._id,patch:{ifRevisionID:e._rev,unset:['opt.media.tags[_ref == "'.concat(i._id,'"]')]}}))).reduce(((e,t)=>e.patch(t.id,t.patch)),a.transaction());return t.delete(i._id),ie.from(t.commit())})),se.mergeMap((()=>ie.of(nt.actions.deleteComplete({tagId:i._id})))),se.catchError((e=>ie.of(nt.actions.deleteError({error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500},tag:i})))))})))}),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(nt.actions.fetchRequest.match),se.withLatestFrom(t),se.switchMap((e=>{let[t,n]=e;const{query:i}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),se.mergeMap((()=>a.observable.fetch(i))),se.mergeMap((e=>{const{items:t}=e;return ie.of(nt.actions.fetchComplete({tags:t}))})),se.catchError((e=>ie.of(nt.actions.fetchError({error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500}})))))})))}),(e=>e.pipe(se.filter(nt.actions.listenerCreateQueue.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=null==e?void 0:e.map((e=>e.payload.tag));return ie.of(nt.actions.listenerCreateQueueComplete({tags:t}))})))),(e=>e.pipe(se.filter(nt.actions.listenerDeleteQueue.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=null==e?void 0:e.map((e=>e.payload.tagId));return ie.of(nt.actions.listenerDeleteQueueComplete({tagIds:t}))})))),(e=>e.pipe(se.filter(nt.actions.listenerUpdateQueue.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=null==e?void 0:e.map((e=>e.payload.tag));return ie.of(nt.actions.listenerUpdateQueueComplete({tags:t}))})))),(e=>e.pipe(ae.ofType(nt.actions.listenerCreateQueueComplete.type,nt.actions.listenerUpdateQueueComplete.type),se.bufferTime(1e3),se.filter((e=>e.length>0)),se.mergeMap((()=>ie.of(nt.actions.sort()))))),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(nt.actions.updateRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;var i;const{closeDialogId:s,formData:o,tag:l}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),Ze(a,null==(i=null==o?void 0:o.name)?void 0:i.current),se.mergeMap((()=>ie.from(a.patch(l._id).set({name:{_type:"slug",current:null==o?void 0:o.name.current}}).commit()))),se.mergeMap((e=>ie.of(nt.actions.updateComplete({closeDialogId:s,tag:e})))),se.catchError((e=>ie.of(nt.actions.updateError({error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500},tag:l})))))})))}),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(Ha.uploadStart.match),se.mergeMap((t=>{const{file:n,uploadItem:i}=t.payload;return ie.merge(ie.of(null).pipe(se.mergeMap((()=>(e=>ie.of(null).pipe(se.mergeMap((()=>ie.from(qa(e))))))(n))),se.mergeMap((e=>ie.of(Ha.previewReady({blobUrl:e,hash:i.hash}))))),ie.of(null).pipe(se.mergeMap((()=>Na(a,i.assetType,n,i.hash))),se.takeUntil(e.pipe(se.filter(Ha.uploadCancel.match),se.filter((e=>e.payload.hash===i.hash)))),se.mergeMap((e=>"complete"===(null==e?void 0:e.type)?ie.of(ht.uploadComplete({asset:e.asset})):"progress"===(null==e?void 0:e.type)&&"upload"===(null==e?void 0:e.stage)?ie.of(Ha.uploadProgress({event:e,uploadHash:i.hash})):ie.empty())),se.catchError((e=>ie.of(Ha.uploadError({error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500},hash:i.hash}))))))})))}),((e,t)=>e.pipe(se.filter(Ha.uploadRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{file:a,forceAsAssetType:i}=t.payload;return ie.of(t).pipe(se.mergeMap((()=>Va(a))),se.filter((e=>!!!n.uploads.byIds[e])),se.mergeMap((e=>{const t={_type:"upload",assetType:i||(a.type.indexOf("image")>=0?"image":"file"),hash:e,name:a.name,size:a.size,status:"queued"};return ie.of(Ha.uploadStart({file:a,uploadItem:t}))})))})))),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(Ha.checkRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{assets:i}=t.payload,s=i.map((e=>e._id)),o=Ke({assetTypes:n.assets.assetTypes,searchFacets:n.search.facets,searchQuery:n.search.query}),l=ke.default(M||(M=H(["\n *["," && _id in $documentIds].sha1hash\n "])),o);return ie.of(t).pipe(se.delay(1e3),se.mergeMap((()=>a.observable.fetch(l,{documentIds:s}))),se.mergeMap((e=>{const t=i.reduce(((t,n)=>(t[n.sha1hash]=e.includes(n.sha1hash)?n._id:null,t)),{});return ie.of(Ha.checkComplete({results:t}),It.insertUploads({results:t}))})))})))}),(e=>e.pipe(se.filter(ht.uploadComplete.match),se.mergeMap((e=>ie.of(Ha.checkRequest({assets:[e.payload.asset]}))))))),bi=te.combineReducers({assets:Tt,debug:bn,dialog:Rt,notifications:yi,search:pt,selected:gi,tags:lt,uploads:Ya}),ji=e=>null!==e&&"object"==typeof e&&!Array.isArray(e),Ii=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];var n,a;return Array.isArray(e)&&e.forEach((e=>{Ii(e,t)})),ji(e)&&("reference"===(null==(n=null==e?void 0:e.asset)?void 0:n._type)&&(null==(a=null==e?void 0:e.asset)?void 0:a._ref)&&t.push(e.asset._ref),Object.values(e).forEach((e=>{Ii(e,t)}))),t},Ci=e=>{const t=Ii(e);return[...new Set(t.sort())]};class wi extends K.Component{constructor(e){super(e);const t=ae.createEpicMiddleware({dependencies:{client:e.client}});this.store=te.configureStore({reducer:bi,middleware:e=>e({serializableCheck:!1,thunk:!1}).prepend(t),devTools:!0,preloadedState:{assets:Q(Q({},gt),{},{assetTypes:(null==e?void 0:e.assetType)?[e.assetType]:["file","image"]}),selected:{assets:e.selectedAssets||[],document:e.document,documentAssetIds:e.document?Ci(e.document):[]}}}),t.run(vi)}render(){return W.jsx(ee.Provider,{store:this.store,children:this.props.children})}}const Ti=()=>{var e;return _t((e=>e.tags.panelVisible))?W.jsx($.Box,{style:{position:"relative",width:250},children:W.jsx($.Box,{className:"media__custom-scrollbar",style:{borderLeft:"1px solid ".concat(null==(e=oe.hues.gray)?void 0:e[900].hex),height:"100%",overflowX:"hidden",overflowY:"auto",position:"absolute",right:0,top:0,width:"100%"},children:W.jsx(ka,{})})}):null},ki=Se.default.div(q||(q=H(["\n color: white;\n height: 100%;\n min-height: 100%;\n right: 0;\n top: 0;\n width: 100%;\n\n &:focus {\n outline: none;\n }\n"]))),Si=Se.default.div(L||(L=H(["\n align-items: center;\n background: rgba(0, 0, 0, 0.75);\n display: flex;\n height: 100%;\n justify-content: center;\n position: absolute;\n right: 0;\n top: 0;\n width: 100%;\n z-index: 3;\n"])));const _i=e=>{const{children:t}=e,{onSelect:n}=He(),a=ee.useDispatch(),i=_t((e=>e.assets.assetTypes)),s=1===i.length&&"image"===i[0],{getRootProps:o,getInputProps:l,isDragActive:r,open:d}=Ie.useDropzone({accept:s?"image/*":"",getFilesFromEvent:async e=>{var t;let n;if("drop"===e.type&&"dataTransfer"in e&&(n=null==(t=null==e?void 0:e.dataTransfer)?void 0:t.files),"change"===e.type){const t=null==e?void 0:e.target;(null==t?void 0:t.files)&&(n=t.files)}if(!n)return[];const i=await async function(e){const t=Array.from(e),n=[];for(const e of t)try{await e.slice(0,1).arrayBuffer(),n.push(e)}catch(e){}return n}(n);return(null==n?void 0:n.length)!==i.length&&a(xi.add({status:"error",title:"Unable to upload some items (folders and packages aren't supported)"})),i},noClick:!0,noDrag:!!n,onDrop:async e=>{e.forEach((e=>a(Ha.uploadRequest({file:e,forceAsAssetType:1===i.length?i[0]:void 0}))))}});return W.jsx(Ma,{open:d,children:W.jsxs(ki,Q(Q({},o()),{},{children:[W.jsx("input",Q({},l())),r&&W.jsx(Si,{children:W.jsx($.Flex,{direction:"column",justify:"center",style:{color:oe.white.hex},children:W.jsx($.Text,{size:3,style:{color:"inherit"},children:"Drop files to upload"})})}),t]}))})},Ei=e=>{let{onClose:t}=e;const n=Ye(),a=ee.useDispatch(),i=e=>{const{documentId:t,result:n,transition:i}=e;"appear"===i&&a(It.listenerCreateQueue({asset:n})),"disappear"===i&&a(It.listenerDeleteQueue({assetId:t})),"update"===i&&a(It.listenerUpdateQueue({asset:n}))},s=e=>{const{documentId:t,result:n,transition:i}=e;"appear"===i&&a(ot.listenerCreateQueue({tag:n})),"disappear"===i&&a(ot.listenerDeleteQueue({tagId:t})),"update"===i&&a(ot.listenerUpdateQueue({tag:n}))};return K.useEffect((()=>{a(It.loadPageIndex({pageIndex:0})),a(ot.fetchRequest());const e=n.listen(ke.default(P||(P=H(['*[_type in ["sanity.fileAsset", "sanity.imageAsset"] && !(_id in path("drafts.**"))]'])))).subscribe(i),t=n.listen(ke.default(U||(U=H(['*[_type == "','" && !(_id in path("drafts.**"))]'])),"media.tag")).subscribe(s);return()=>{null==e||e.unsubscribe(),null==t||t.unsubscribe()}}),[]),W.jsxs(_i,{children:[W.jsx(_a,{}),W.jsx(hi,{}),W.jsx($.Card,{display:"flex",height:"fill",children:W.jsxs($.Flex,{direction:"column",flex:1,children:[W.jsx(Ra,{onClose:t}),W.jsx(xn,{}),W.jsxs($.Flex,{flex:1,children:[W.jsxs($.Flex,{align:"flex-end",direction:"column",flex:1,style:{position:"relative"},children:[W.jsx(mi,{}),W.jsx(pi,{})]}),W.jsx(Ti,{})]}),W.jsx(jn,{})]})})]})},Mi=e=>{const t=Ye();return W.jsx(wi,{assetType:null==e?void 0:e.assetType,client:t,document:null==e?void 0:e.document,selectedAssets:null==e?void 0:e.selectedAssets,children:W.jsx($.ThemeProvider,{scheme:"dark",theme:$.studioTheme,children:W.jsx($.ToastProvider,{children:W.jsxs(Xe,{onSelect:null==e?void 0:e.onSelect,children:[W.jsx(St,{}),W.jsx(Ei,{onClose:null==e?void 0:e.onClose})]})})})})},Ri=()=>{const[e]=K.useState((()=>document.createElement("div")));return K.useEffect((()=>(e.classList.add("media-portal"),document.body.appendChild(e),()=>{document.body.removeChild(e)})),[]),e};var Bi={title:"Media Tag",icon:gn,name:"media.tag",type:"document",fields:[{title:"Name",name:"name",type:"slug"}],preview:{select:{name:"name"},prepare(e){const{name:t}=e;return{media:gn,title:null==t?void 0:t.current}}}};const Fi={icon:G.ImageIcon,name:"media",title:"Media"},zi=Q(Q({},Fi),{},{component:e=>{const{onClose:t}=e,n=Ri(),a=Y.useFormValue([]);Ae("escape",t);const i=e=>{e.nativeEvent.stopImmediatePropagation(),e.stopPropagation()},{zIndex:s}=$.useLayer();return W.jsx($.PortalProvider,{element:n,children:W.jsx($.Portal,{children:W.jsx($.Box,{onDragEnter:i,onDragLeave:i,onDragOver:i,onDrop:i,onMouseUp:i,style:{bottom:0,height:"auto",left:0,position:"fixed",top:0,width:"100%",zIndex:s},children:W.jsx(Mi,Q({document:a},e))})})})}}),Di=Q(Q({},Fi),{},{component:()=>W.jsx($.Flex,{direction:"column",height:"fill",flex:1,children:W.jsx(Mi,{})})}),Ai=Y.definePlugin({name:"media",form:{file:{assetSources:e=>[...e,zi]},image:{assetSources:e=>[...e,zi]}},schema:{types:[Bi]},tools:e=>[...e,Di]});exports.media=Ai,exports.mediaAssetSource=zi;
1
+ "use strict";const e=["onValueChange","value"];var t,n,a,i,s,o,l,r,d,c,u,p,h,m,g,f,x,y,v,b,j,I,C,w,T,k,S,_,E,M,R,B,z,D,F,A,q,O,L,P,U;function N(e,t){if(null==e)return{};var n,a,i=function(e,t){if(null==e)return{};var n,a,i={},s=Object.keys(e);for(a=0;a<s.length;a++)n=s[a],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(a=0;a<s.length;a++)n=s[a],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function V(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function Q(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?V(Object(n),!0).forEach((function(t){X(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):V(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function X(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var a=n.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function H(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}Object.defineProperty(exports,"__esModule",{value:!0});var Y=require("sanity"),G=require("@sanity/icons"),W=require("react/jsx-runtime"),$=require("@sanity/ui"),K=require("react"),Z=require("is-hotkey"),J=require("groq"),ee=require("react-redux"),te=require("@reduxjs/toolkit"),ne=require("nanoid"),ae=require("redux-observable"),ie=require("rxjs"),se=require("rxjs/operators"),oe=require("@sanity/color"),le=require("styled-components"),re=require("pluralize"),de=require("@tanem/react-nprogress"),ce=require("react-select"),ue=require("react-virtuoso"),pe=require("@hookform/resolvers/yup"),he=require("react-hook-form"),me=require("yup"),ge=require("date-fns/format"),fe=require("filesize"),xe=require("copy-to-clipboard"),ye=require("sanity/router"),ve=require("react-file-icon"),be=require("react-select/creatable"),je=require("date-fns/formatRelative"),Ie=require("react-dropzone");function Ce(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function we(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var Te=Ce(Z),ke=Ce(J),Se=Ce(le),_e=Ce(re),Ee=Ce(ce),Me=we(me),Re=Ce(ge),Be=Ce(fe),ze=Ce(xe),De=Ce(be),Fe=Ce(je);const Ae=(e,t)=>{const n=K.useRef(!1);function a(a){Te.default(e,a)&&(n.current=!0,t&&t())}const i=()=>{n.current=!1};return K.useEffect((()=>(window.addEventListener("keydown",a),window.addEventListener("keyup",i),()=>{window.removeEventListener("keydown",a),window.removeEventListener("keyup",i)})),[]),n},qe={type:"divider"},Oe={altText:{assetTypes:["file","image"],field:"altText",name:"altText",operatorType:"empty",operatorTypes:["empty","notEmpty",null,"includes","doesNotInclude"],title:"Alt text",type:"string",value:""},description:{assetTypes:["file","image"],field:"description",name:"description",operatorType:"empty",operatorTypes:["empty","notEmpty",null,"includes","doesNotInclude"],title:"Description",type:"string",value:""},fileName:{assetTypes:["file","image"],field:"originalFilename",name:"filename",operatorType:"includes",operatorTypes:["includes","doesNotInclude"],title:"File name",type:"string",value:""},height:{assetTypes:["image"],field:"metadata.dimensions.height",name:"height",operatorType:"greaterThan",operatorTypes:["greaterThan","greaterThanOrEqualTo","lessThan","lessThanOrEqualTo",null,"equalTo"],title:"Height",type:"number",value:400},inCurrentDocument:{assetTypes:["file","image"],name:"inCurrentDocument",operatorType:"is",options:[{name:"true",title:"True",value:ke.default(t||(t=H(["_id in $documentAssetIds"])))},{name:"false",title:"False",value:ke.default(n||(n=H(["!(_id in $documentAssetIds)"])))}],selectOnly:!0,title:"In use in current document",type:"select",value:"true"},inUse:{assetTypes:["file","image"],name:"inUse",operatorType:"is",options:[{name:"true",title:"True",value:ke.default(a||(a=H(["count(*[references(^._id)]) > 0"])))},{name:"false",title:"False",value:ke.default(i||(i=H(["count(*[references(^._id)]) == 0"])))}],title:"In use",type:"select",value:"true"},isOpaque:{assetTypes:["image"],field:"metadata.isOpaque",name:"isOpaque",operatorType:"equalTo",options:[{name:"true",title:"True",value:"false"},{name:"false",title:"False",value:"true"}],title:"Has transparency",type:"select",value:"true"},orientation:{assetTypes:["image"],name:"orientation",operatorType:"is",operatorTypes:["is","isNot"],options:[{name:"portrait",title:"Portrait",value:"metadata.dimensions.aspectRatio < 1"},{name:"landscape",title:"Landscape",value:"metadata.dimensions.aspectRatio > 1"},{name:"square",title:"Square",value:"metadata.dimensions.aspectRatio == 1"}],title:"Orientation",type:"select",value:"portrait"},size:{assetTypes:["file","image"],field:"size",modifier:"kb",modifiers:[{name:"kb",title:"KB",fieldModifier:e=>"round(".concat(e," / 1000)")},{name:"mb",title:"MB",fieldModifier:e=>"round(".concat(e," / 1000000)")}],name:"size",operatorType:"greaterThan",operatorTypes:["greaterThan","greaterThanOrEqualTo","lessThan","lessThanOrEqualTo",null,"equalTo"],title:"File size",type:"number",value:0},tag:{assetTypes:["file","image"],field:"opt.media.tags",name:"tag",operatorType:"references",operatorTypes:["references","doesNotReference",null,"empty","notEmpty"],title:"Tags",type:"searchable"},title:{assetTypes:["file","image"],field:"title",name:"title",operatorType:"empty",operatorTypes:["empty","notEmpty",null,"includes","doesNotInclude"],title:"Title",type:"string",value:""},type:{assetTypes:["file","image"],name:"type",operatorType:"is",operatorTypes:["is","isNot"],options:[{name:"image",title:"Image",value:'mimeType match "image*"'},{name:"video",title:"Video",value:'mimeType match "video*"'},{name:"audio",title:"Audio",value:'mimeType match "audio*"'},{name:"pdf",title:"PDF",value:'mimeType == "application/pdf"'}],title:"File type",type:"select",value:"image"},width:{assetTypes:["image"],field:"metadata.dimensions.width",name:"width",operatorType:"greaterThan",operatorTypes:["greaterThan","greaterThanOrEqualTo","lessThan","lessThanOrEqualTo",null,"equalTo"],title:"Width",type:"number",value:400}},Le={doesNotInclude:{fn:(e,t)=>e?"!(".concat(t," match '*").concat(e,"*')"):void 0,label:"does not include"},doesNotReference:{fn:(e,t)=>e?"!references('".concat(e,"')"):void 0,label:"does not include"},empty:{fn:(e,t)=>"!defined(".concat(t,")"),hideInput:!0,label:"is empty"},equalTo:{fn:(e,t)=>e?"".concat(t," == ").concat(e):void 0,label:"is equal to"},greaterThan:{fn:(e,t)=>e?"".concat(t," > ").concat(e):void 0,label:"is greater than"},greaterThanOrEqualTo:{fn:(e,t)=>e?"".concat(t," >= ").concat(e):void 0,label:"is greater than or equal to"},includes:{fn:(e,t)=>e?"".concat(t," match '*").concat(e,"*'"):void 0,label:"includes"},is:{fn:(e,t)=>"".concat(e),label:"is"},isNot:{fn:(e,t)=>"!(".concat(e,")"),label:"is not"},lessThan:{fn:(e,t)=>e?"".concat(t," < ").concat(e):void 0,label:"is less than"},lessThanOrEqualTo:{fn:(e,t)=>e?"".concat(t," <= ").concat(e):void 0,label:"is less than or equal to"},notEmpty:{fn:(e,t)=>"defined(".concat(t,")"),hideInput:!0,label:"is not empty"},references:{fn:(e,t)=>e?"references('".concat(e,"')"):void 0,label:"includes"}},Pe=[{direction:"desc",field:"_createdAt"},{direction:"asc",field:"_createdAt"},null,{direction:"desc",field:"_updatedAt"},{direction:"asc",field:"_updatedAt"},null,{direction:"asc",field:"originalFilename"},{direction:"desc",field:"originalFilename"},null,{direction:"desc",field:"size"},{direction:"asc",field:"size"}],Ue=[Oe.tag,qe,Oe.inUse,Oe.inCurrentDocument,qe,Oe.title,Oe.altText,Oe.description,qe,Oe.isOpaque,qe,Oe.fileName,Oe.size,Oe.type,qe,Oe.orientation,Oe.width,Oe.height],Ne="3rem 100px auto 1.5rem",Ve="3rem 100px auto 5.5rem 5.5rem 3.5rem 8.5rem 2rem",Qe=K.createContext(void 0),Xe=e=>{const{children:t,onSelect:n}=e,a={onSelect:n};return W.jsx(Qe.Provider,{value:a,children:t})},He=()=>{const e=K.useContext(Qe);if(void 0===e)throw new Error("useAssetSourceActions must be used within an AssetSourceDispatchProvider");return e},Ye=()=>Y.useClient({apiVersion:"2022-10-01"}),Ge={_createdAt:{asc:"Last created: Oldest first",desc:"Last created: Newest first"},_updatedAt:{asc:"Last updated: Oldest first",desc:"Last updated: Newest first"},mimeType:{asc:"MIME type: A to Z",desc:"MIME type: Z to A"},originalFilename:{asc:"File name: A to Z",desc:"File name: Z to A"},size:{asc:"File size: Smallest first",desc:"File size: Largest first"}},We=(e,t)=>Ge[e][t],$e=e=>function(t){return ie.iif((()=>!!e),t.pipe(se.delay(3e3),se.mergeMap((e=>Math.random()>.5?ie.throwError({message:"Test error",statusCode:500}):ie.of(e)))),t)},Ke=e=>{let{assetTypes:t,searchFacets:n,searchQuery:a}=e;const i=t.map((e=>"sanity.".concat(e,"Asset"))),l=ke.default(s||(s=H(["\n _type in ",' && !(_id in path("drafts.**"))\n '])),JSON.stringify(i)),r=n.reduce(((e,t)=>{var n;if("number"===t.type){const{field:n,modifier:a,modifiers:i,operatorType:s,value:o}=t,l=Le[s],r=null==i?void 0:i.find((e=>e.name===a)),d=(null==r?void 0:r.fieldModifier)?r.fieldModifier(n):n,c=l.fn(o,d);c&&e.push(c)}if("searchable"===t.type){const{field:n,operatorType:a,value:i}=t,s=Le[a].fn(null==i?void 0:i.value,n);s&&e.push(s)}if("select"===t.type){const{field:a,operatorType:i,options:s,value:o}=t,l=Le[i],r=null==(n=null==s?void 0:s.find((e=>e.name===o)))?void 0:n.value,d=l.fn(r,a);d&&e.push(d)}if("string"===t.type){const{field:n,operatorType:a,value:i}=t,s=Le[a].fn(i,n);s&&e.push(s)}return e}),[]);return[l,...a?[ke.default(o||(o=H(["[_id, altText, assetId, description, originalFilename, title, url] match '*","*'"])),a.trim())]:[],...r].join(" && ")},Ze=(e,t)=>function(n){return n.pipe(se.mergeMap((()=>ie.from(e.fetch(ke.default(l||(l=H(['count(*[_type == "','" && name.current == $name])'])),"media.tag"),{name:t})))),se.mergeMap((e=>e>0?ie.throwError({message:"Tag already exists",statusCode:409}):ie.of(!0))))},Je=e=>e.reduce(((e,t)=>{var n;const a=null==t?void 0:t.tag;return a&&e.push({label:null==(n=null==a?void 0:a.name)?void 0:n.current,value:null==a?void 0:a._id}),e}),[]),et={tagsAddComplete:te.createAction("actions/tagsAddComplete",(function(e){let{assets:t,tag:n}=e;return{payload:{assets:t,tag:n}}})),tagsAddError:te.createAction("actions/tagsAddError",(function(e){let{assets:t,error:n,tag:a}=e;return{payload:{assets:t,error:n,tag:a}}})),tagsAddRequest:te.createAction("actions/tagsAddRequest",(function(e){let{assets:t,tag:n}=e;return{payload:{assets:t,tag:n}}})),tagsRemoveComplete:te.createAction("actions/tagsRemoveComplete",(function(e){let{assets:t,tag:n}=e;return{payload:{assets:t,tag:n}}})),tagsRemoveError:te.createAction("actions/tagsRemoveError",(function(e){let{assets:t,error:n,tag:a}=e;return{payload:{assets:t,error:n,tag:a}}})),tagsRemoveRequest:te.createAction("actions/tagsRemoveRequest",(function(e){let{assets:t,tag:n}=e;return{payload:{assets:t,tag:n}}}))},tt={showTagCreate:te.createAction("dialog/showTagCreate"),showTagEdit:te.createAction("dialog/showTagEdit",(function(e){let{tagId:t}=e;return{payload:{tagId:t}}}))},nt=te.createSlice({name:"tags",initialState:{allIds:[],byIds:{},creating:!1,creatingError:void 0,fetchCount:-1,fetching:!1,fetchingError:void 0,panelVisible:!0},extraReducers:e=>{e.addCase(tt.showTagCreate,(e=>{delete e.creatingError})).addCase(tt.showTagEdit,((e,t)=>{const{tagId:n}=t.payload;delete e.byIds[n].error})).addMatcher((e=>[et.tagsAddComplete.type,et.tagsAddError.type,et.tagsRemoveComplete.type,et.tagsRemoveError.type].includes(e.type)),((e,t)=>{const{tag:n}=t.payload;e.byIds[n._id].updating=!1})).addMatcher((e=>[et.tagsAddRequest.type,et.tagsRemoveRequest.type].includes(e.type)),((e,t)=>{const{tag:n}=t.payload;e.byIds[n._id].updating=!0}))},reducers:{createComplete(e,t){const{tag:n}=t.payload;e.creating=!1,e.allIds.includes(n._id)||e.allIds.push(n._id),e.byIds[n._id]={_type:"tag",picked:!1,tag:n,updating:!1}},createError(e,t){e.creating=!1,e.creatingError=t.payload.error},createRequest(e,t){e.creating=!0,delete e.creatingError},deleteComplete(e,t){const{tagId:n}=t.payload,a=e.allIds.indexOf(n);a>=0&&e.allIds.splice(a,1),delete e.byIds[n]},deleteError(e,t){const{error:n,tag:a}=t.payload,i=null==a?void 0:a._id;e.byIds[i].error=n,e.byIds[i].updating=!1},deleteRequest(e,t){var n,a;const i=null==(a=null==(n=t.payload)?void 0:n.tag)?void 0:a._id;e.byIds[i].picked=!1,e.byIds[i].updating=!0,Object.keys(e.byIds).forEach((t=>{delete e.byIds[t].error}))},fetchComplete(e,t){const{tags:n}=t.payload;null==n||n.forEach((t=>{e.allIds.push(t._id),e.byIds[t._id]={_type:"tag",picked:!1,tag:t,updating:!1}})),e.fetching=!1,e.fetchCount=n.length||0,delete e.fetchingError},fetchError(e,t){const{error:n}=t.payload;e.fetching=!1,e.fetchingError=n},fetchRequest:{reducer:(e,t)=>{e.fetching=!0,delete e.fetchingError},prepare:()=>({payload:{query:ke.default(r||(r=H(['\n {\n "items": *[\n _type == "','"\n && !(_id in path("drafts.**"))\n ] {\n _createdAt,\n _updatedAt,\n _id,\n _rev,\n _type,\n name\n } | order(name.current asc),\n }\n '])),"media.tag")}})},listenerCreateQueue(e,t){},listenerCreateQueueComplete(e,t){const{tags:n}=t.payload;null==n||n.forEach((t=>{e.byIds[t._id]={_type:"tag",picked:!1,tag:t,updating:!1},e.allIds.includes(t._id)||e.allIds.push(t._id)}))},listenerDeleteQueue(e,t){},listenerDeleteQueueComplete(e,t){const{tagIds:n}=t.payload;null==n||n.forEach((t=>{const n=e.allIds.indexOf(t);n>=0&&e.allIds.splice(n,1),delete e.byIds[t]}))},listenerUpdateQueue(e,t){},listenerUpdateQueueComplete(e,t){const{tags:n}=t.payload;null==n||n.forEach((t=>{e.byIds[t._id]&&(e.byIds[t._id].tag=t)}))},panelVisibleSet(e,t){const{panelVisible:n}=t.payload;e.panelVisible=n},sort(e){e.allIds.sort(((t,n)=>{const a=e.byIds[t].tag.name.current,i=e.byIds[n].tag.name.current;return a<i?-1:a>i?1:0}))},updateComplete(e,t){const{tag:n}=t.payload;e.byIds[n._id].tag=n,e.byIds[n._id].updating=!1},updateError(e,t){const{error:n,tag:a}=t.payload,i=null==a?void 0:a._id;e.byIds[i].error=n,e.byIds[i].updating=!1},updateRequest(e,t){const{tag:n}=t.payload;e.byIds[null==n?void 0:n._id].updating=!0}}}),at=e=>e.tags.byIds,it=te.createSelector([at,e=>e.tags.allIds],((e,t)=>t.map((t=>e[t])))),st=te.createSelector([at,(e,t)=>t],((e,t)=>e[t])),ot=nt.actions;var lt=nt.reducer;const rt=te.createSlice({name:"search",initialState:{facets:[],query:""},reducers:{facetsAdd(e,t){e.facets.push(t.payload.facet)},facetsClear(e){e.facets=[]},facetsRemove(e,t){e.facets=e.facets.filter((e=>e.name!==t.payload.facetName))},facetsUpdate(e,t){const{modifier:n,name:a,operatorType:i,value:s}=t.payload;e.facets.forEach(((t,o)=>{t.name===a&&("number"===t.type&&n&&(t.modifier=n),i&&(t.operatorType=i),void 0!==s&&(e.facets[o].value=s))}))},querySet(e,t){var n;e.query=null==(n=t.payload)?void 0:n.searchQuery}}}),dt=te.createSelector((e=>e.search.facets),(e=>!!(null==e?void 0:e.find((e=>"tag"===e.name))))),ct=te.createSelector([e=>e.tags.byIds,e=>e.search.facets,(e,t)=>t],((e,t,n)=>{var a,i,s;const o=null==t?void 0:t.find((e=>"tag"===e.name));if("searchable"===(null==o?void 0:o.type)){const t=null==(a=o.value)?void 0:a.value;if(t)return(null==(s=null==(i=e[t])?void 0:i.tag)?void 0:s._id)===n&&"references"===(null==o?void 0:o.operatorType)}return!1})),ut=rt.actions;var pt=rt.reducer;const ht={uploadComplete:te.createAction("uploads/uploadComplete",(function(e){let{asset:t}=e;return{payload:{asset:t}}}))},mt=Pe[0],gt={allIds:[],assetTypes:[],byIds:{},fetchCount:-1,fetching:!1,fetchingError:void 0,lastPicked:void 0,order:{direction:mt.direction,field:mt.field,title:We(mt.field,mt.direction)},pageIndex:0,pageSize:50,view:"grid"},ft=te.createSlice({name:"assets",initialState:gt,extraReducers:e=>{e.addCase(ht.uploadComplete,((e,t)=>{const{asset:n}=t.payload;e.byIds[n._id]={_type:"asset",asset:n,picked:!1,updating:!1}})).addCase(et.tagsAddComplete,((e,t)=>{const{assets:n}=t.payload;n.forEach((t=>{e.byIds[t.asset._id].updating=!1}))})).addCase(et.tagsAddError,((e,t)=>{const{assets:n}=t.payload;n.forEach((t=>{e.byIds[t.asset._id].updating=!1}))})).addCase(et.tagsAddRequest,((e,t)=>{const{assets:n}=t.payload;n.forEach((t=>{e.byIds[t.asset._id].updating=!0}))})).addCase(et.tagsRemoveComplete,((e,t)=>{const{assets:n}=t.payload;n.forEach((t=>{e.byIds[t.asset._id].updating=!1}))})).addCase(et.tagsRemoveError,((e,t)=>{const{assets:n}=t.payload;n.forEach((t=>{e.byIds[t.asset._id].updating=!1}))})).addCase(et.tagsRemoveRequest,((e,t)=>{const{assets:n}=t.payload;n.forEach((t=>{e.byIds[t.asset._id].updating=!0}))}))},reducers:{clear(e){e.allIds=[]},deleteComplete(e,t){const{assetIds:n}=t.payload;null==n||n.forEach((t=>{const n=e.allIds.indexOf(t);n>=0&&e.allIds.splice(n,1),delete e.byIds[t]})),e.pageIndex=Math.floor(e.allIds.length/e.pageSize)-1},deleteError(e,t){var n,a,i,s;const{assetIds:o,error:l}=t.payload,r=null==(s=null==(i=null==(a=null==(n=null==l?void 0:l.response)?void 0:n.body)?void 0:a.error)?void 0:i.items)?void 0:s.map((e=>e.error));null==o||o.forEach((t=>{e.byIds[t].updating=!1})),null==r||r.forEach((t=>{e.byIds[t.id].error=t.description}))},deleteRequest(e,t){const{assets:n}=t.payload;n.forEach((t=>{e.byIds[null==t?void 0:t._id].updating=!0})),Object.keys(e.byIds).forEach((t=>{delete e.byIds[t].error}))},fetchComplete(e,t){var n;const a=(null==(n=t.payload)?void 0:n.assets)||[];a&&a.forEach((t=>{e.allIds.includes(t._id)||e.allIds.push(t._id),e.byIds[t._id]={_type:"asset",asset:t,picked:!1,updating:!1}})),e.fetching=!1,e.fetchCount=a.length||0,delete e.fetchingError},fetchError(e,t){const n=t.payload;e.fetching=!1,e.fetchingError=n},fetchRequest:{reducer:(e,t)=>{e.fetching=!0,delete e.fetchingError},prepare:e=>{let{params:t={},queryFilter:n,selector:a="",sort:i=ke.default(c||(c=H(["order(_updatedAt desc)"])))}=e;const s=i||a?"|":"";return{payload:{params:t,query:ke.default(u||(u=H(['\n {\n "items": *[',"] {\n _id,\n _type,\n _createdAt,\n _updatedAt,\n altText,\n description,\n extension,\n metadata {\n dimensions,\n exif,\n isOpaque,\n },\n mimeType,\n opt {\n media\n },\n originalFilename,\n size,\n title,\n url\n } "," "," ",",\n }\n "])),n,s,i,a)}}}},insertUploads(e,t){const{results:n}=t.payload;Object.entries(n).forEach((t=>{let[n,a]=t;a&&!e.allIds.includes(n)&&e.allIds.push(a)}))},listenerCreateQueue(e,t){},listenerCreateQueueComplete(e,t){const{assets:n}=t.payload;null==n||n.forEach((t=>{var n;(null==(n=e.byIds[null==t?void 0:t._id])?void 0:n.asset)&&(e.byIds[t._id].asset=t)}))},listenerDeleteQueue(e,t){},listenerDeleteQueueComplete(e,t){const{assetIds:n}=t.payload;null==n||n.forEach((t=>{const n=e.allIds.indexOf(t);n>=0&&e.allIds.splice(n,1),delete e.byIds[t]}))},listenerUpdateQueue(e,t){},listenerUpdateQueueComplete(e,t){const{assets:n}=t.payload;null==n||n.forEach((t=>{var n;(null==(n=e.byIds[null==t?void 0:t._id])?void 0:n.asset)&&(e.byIds[t._id].asset=t)}))},loadNextPage(){},loadPageIndex(e,t){e.pageIndex=t.payload.pageIndex},orderSet(e,t){var n;e.order=null==(n=t.payload)?void 0:n.order,e.pageIndex=0},pick(e,t){const{assetId:n,picked:a}=t.payload;e.byIds[n].picked=a,e.lastPicked=a?n:void 0},pickAll(e){e.allIds.forEach((t=>{e.byIds[t].picked=!0}))},pickClear(e){e.lastPicked=void 0,Object.values(e.byIds).forEach((t=>{e.byIds[t.asset._id].picked=!1}))},pickRange(e,t){const n=e.allIds.findIndex((e=>e===t.payload.startId)),a=e.allIds.findIndex((e=>e===t.payload.endId)),i=[n,a].sort(((e,t)=>e-t));e.allIds.slice(i[0],i[1]+1).forEach((t=>{e.byIds[t].picked=!0})),e.lastPicked=e.allIds[a]},sort(e){e.allIds.sort(((t,n)=>{const a=e.byIds[t].asset[e.order.field],i=e.byIds[n].asset[e.order.field];return a<i?"asc"===e.order.direction?-1:1:a>i?"asc"===e.order.direction?1:-1:0}))},updateComplete(e,t){const{asset:n}=t.payload;e.byIds[n._id].updating=!1,e.byIds[n._id].asset=n},updateError(e,t){const{asset:n,error:a}=t.payload,i=null==n?void 0:n._id;e.byIds[i].error=a.message,e.byIds[i].updating=!1},updateRequest(e,t){var n,a;const i=null==(a=null==(n=t.payload)?void 0:n.asset)?void 0:a._id;e.byIds[i].updating=!0},viewSet(e,t){var n;e.view=null==(n=t.payload)?void 0:n.view}}}),xt=te.createSelector([e=>e.assets.byIds,(e,t)=>t],((e,t)=>e[t])),yt=te.createSelector([e=>e.assets.byIds,e=>e.assets.allIds],((e,t)=>t.map((t=>e[t])))),vt=te.createSelector([yt],(e=>e.length)),bt=te.createSelector([yt],(e=>e.filter((e=>null==e?void 0:e.picked)))),jt=te.createSelector([bt],(e=>e.length)),It=ft.actions;var Ct,wt,Tt=ft.reducer;const kt=le.css(g||(g=H(["\n ::-webkit-scrollbar {\n width: 14px;\n }\n\n ::-webkit-scrollbar-thumb {\n border-radius: 10px;\n border: 4px solid rgba(0, 0, 0, 0);\n background: ",";\n background-clip: padding-box;\n\n &:hover {\n background: ",";\n background-clip: padding-box;\n }\n }\n"])),null==(Ct=oe.hues.gray)?void 0:Ct[800].hex,null==(wt=oe.hues.gray)?void 0:wt[400].hex),St=le.createGlobalStyle(f||(f=H(["\n .media__custom-scrollbar {\n ",'\n }\n\n // @sanity/ui overrides\n\n // Custom scrollbar on Box (used in Dialogs)\n div[data-ui="Box"] {\n ','\n }\n\n // Dialog background color\n div[data-ui="Dialog"] {\n background-color: rgba(15, 17, 18, 0.9);\n }\n\n'])),kt,kt),_t=ee.useSelector,Et=te.createSlice({name:"dialog",initialState:{items:[]},extraReducers:e=>{e.addCase(tt.showTagCreate,(e=>{e.items.push({id:"tagCreate",type:"tagCreate"})})),e.addCase(tt.showTagEdit,((e,t)=>{const{tagId:n}=t.payload;e.items.push({id:n,tagId:n,type:"tagEdit"})}))},reducers:{clear(e){e.items=[]},inlineTagCreate(e,t){const{assetId:n,tag:a}=t.payload;e.items.forEach((e=>{"assetEdit"===e.type&&e.assetId===n&&(e.lastCreatedTag={label:a.name.current,value:a._id})}))},inlineTagRemove(e,t){const{tagIds:n}=t.payload;e.items.forEach((e=>{"assetEdit"===e.type&&(e.lastRemovedTagIds=n)}))},remove(e,t){var n;const a=null==(n=t.payload)?void 0:n.id;e.items=e.items.filter((e=>e.id!==a))},showConfirmAssetsTagAdd(e,t){const{assetsPicked:n,closeDialogId:a,tag:i}=t.payload,s="".concat(n.length," ").concat(_e.default("asset",n.length));e.items.push({closeDialogId:a,confirmCallbackAction:et.tagsAddRequest({assets:n,tag:i}),confirmText:"Yes, add tag to ".concat(s),title:"Add tag ".concat(i.name.current," to ").concat(s,"?"),id:"confirm",headerTitle:"Confirm tag addition",tone:"primary",type:"confirm"})},showConfirmAssetsTagRemove(e,t){const{assetsPicked:n,closeDialogId:a,tag:i}=t.payload,s="".concat(n.length," ").concat(_e.default("asset",n.length));e.items.push({closeDialogId:a,confirmCallbackAction:et.tagsRemoveRequest({assets:n,tag:i}),confirmText:"Yes, remove tag from ".concat(s),headerTitle:"Confirm tag removal",id:"confirm",title:"Remove tag ".concat(i.name.current," from ").concat(s,"?"),tone:"critical",type:"confirm"})},showConfirmDeleteAssets(e,t){const{assets:n,closeDialogId:a}=t.payload,i="".concat(n.length," ").concat(_e.default("asset",n.length));e.items.push({closeDialogId:a,confirmCallbackAction:It.deleteRequest({assets:n.map((e=>e.asset))}),confirmText:"Yes, delete ".concat(i),description:"This operation cannot be reversed. Are you sure you want to continue?",title:"Permanently delete ".concat(i,"?"),id:"confirm",headerTitle:"Confirm deletion",tone:"critical",type:"confirm"})},showConfirmDeleteTag(e,t){const{closeDialogId:n,tag:a}=t.payload;e.items.push({closeDialogId:n,confirmCallbackAction:ot.deleteRequest({tag:a}),confirmText:"Yes, delete ".concat("tag"),description:"This operation cannot be reversed. Are you sure you want to continue?",title:"Permanently delete ".concat("tag","?"),id:"confirm",headerTitle:"Confirm deletion",tone:"critical",type:"confirm"})},showAssetEdit(e,t){const{assetId:n}=t.payload;e.items.push({assetId:n,id:n,type:"assetEdit"})},showSearchFacets(e){e.items.push({id:"searchFacets",type:"searchFacets"})},showTags(e){e.items.push({id:"tags",type:"tags"})}}}),Mt=Et.actions;var Rt=Et.reducer;const Bt=()=>{const e=ee.useDispatch(),t=_t((e=>e.assets.view));return W.jsxs($.Inline,{space:0,style:{whiteSpace:"nowrap"},children:[W.jsx($.Button,{fontSize:1,icon:G.ThLargeIcon,mode:"grid"===t?"default":"ghost",onClick:()=>e(It.viewSet({view:"grid"})),style:{borderBottomRightRadius:0,borderTopRightRadius:0}}),W.jsx($.Button,{fontSize:1,icon:G.ThListIcon,mode:"table"===t?"default":"ghost",onClick:()=>e(It.viewSet({view:"table"})),style:{borderBottomLeftRadius:0,borderTopLeftRadius:0}})]})},zt=()=>{var e;const t=ee.useDispatch(),n=_t((e=>e.assets.order));return W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,icon:G.SortIcon,iconRight:G.SelectIcon,mode:"ghost",padding:3,text:We(n.field,n.direction)}),id:"order",menu:W.jsx($.Menu,{children:null==(e=Pe)?void 0:e.map(((e,a)=>e?W.jsx($.MenuItem,{disabled:n.field===e.field&&n.direction===e.direction,fontSize:1,onClick:()=>t(It.orderSet({order:{direction:e.direction,field:e.field}})),padding:2,text:We(e.field,e.direction)},a):W.jsx($.MenuDivider,{},a)))})})},Dt=e=>{const{loading:t}=e,{animationDuration:n,isFinished:a,progress:i}=de.useNProgress({animationDuration:300,isAnimating:t});return W.jsx($.Box,{style:{opacity:a?0:1,transition:"opacity ".concat(n,"ms linear")},children:W.jsx($.Box,{style:{height:"1px",background:"rgba(255, 255, 255, 0.5)",position:"absolute",left:0,top:0,transition:"width ".concat(n,"ms linear"),width:"".concat(100*i,"%")}})})},Ft=Se.default($.Box)(x||(x=H(["\n background: rgba(255, 255, 255, 0.05);\n border-radius: ","px;\n"])),(e=>e.theme.sanity.radius[2])),At=e=>{const{children:t,facet:n}=e,a=ee.useDispatch();return W.jsx(Ft,{padding:[2,2,1],children:W.jsxs($.Flex,{align:["flex-start","flex-start","center"],direction:["column","column","row"],children:[W.jsx($.Box,{paddingBottom:[3,3,0],paddingLeft:1,paddingRight:2,paddingTop:[1,1,0],children:W.jsx($.Label,{size:0,style:{whiteSpace:"nowrap"},children:n.title})}),W.jsxs($.Flex,{align:"center",children:[t,W.jsx($.Box,{marginLeft:1,paddingX:2,children:W.jsx($.Text,{muted:!0,size:0,children:W.jsx(G.CloseIcon,{onClick:()=>{a(ut.facetsRemove({facetName:n.name}))}})})})]})]})})},qt=t=>{const{onValueChange:n,value:a}=t,i=N(t,e);return W.jsx($.TextInput,Q(Q({},i),{},{onChange:e=>{const t=e.target.value;(""===t||/^[0-9\b]+$/.test(t))&&n(parseInt(t,10)||"")},value:null!=a?a:""}))},Ot=e=>{var t;const{facet:n}=e,a=ee.useDispatch(),i=null==n?void 0:n.modifiers,s=(null==n?void 0:n.modifier)?null==i?void 0:i.find((e=>e.name===(null==n?void 0:n.modifier))):null==i?void 0:i[0],o=null!=(t=n.operatorType)?t:"greaterThan";return W.jsxs(At,{facet:n,children:[(null==n?void 0:n.operatorTypes)&&W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,iconRight:G.SelectIcon,padding:2,text:Le[o].label}),id:"operators",menu:W.jsx($.Menu,{children:n.operatorTypes.map(((e,t)=>e?W.jsx($.MenuItem,{disabled:e===o,fontSize:1,onClick:()=>(e=>{a(ut.facetsUpdate({name:n.name,operatorType:e}))})(e),padding:2,text:Le[e].label},e):W.jsx($.MenuDivider,{},t)))})}),W.jsx($.Box,{marginX:1,style:{maxWidth:"50px"},children:W.jsx(qt,{fontSize:1,onValueChange:e=>{a(ut.facetsUpdate({name:n.name,value:e}))},padding:2,radius:2,width:2,value:null==n?void 0:n.value})}),i&&W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,iconRight:G.SelectIcon,padding:2,text:null==s?void 0:s.title}),id:"modifier",menu:W.jsx($.Menu,{children:i.map((e=>W.jsx($.MenuItem,{disabled:e.name===n.modifier,fontSize:1,onClick:()=>(e=>{a(ut.facetsUpdate({name:n.name,modifier:e.name}))})(e),padding:2,text:e.title},e.name)))})})]})},Lt=e=>{var t;const{facet:n}=e,a=ee.useDispatch(),i=null==n?void 0:n.options,s=null==i?void 0:i.find((e=>e.name===(null==n?void 0:n.value))),o=null!=(t=null==n?void 0:n.operatorType)?t:"is";return W.jsxs(At,{facet:n,children:[(null==n?void 0:n.operatorTypes)&&W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,iconRight:G.SelectIcon,padding:2,style:{marginRight:"4px"},text:Le[o].label}),id:"operators",menu:W.jsx($.Menu,{children:n.operatorTypes.map(((e,t)=>e?W.jsx($.MenuItem,{disabled:e===o,fontSize:1,onClick:()=>(e=>{a(ut.facetsUpdate({name:n.name,operatorType:e}))})(e),padding:2,text:Le[e].label},e):W.jsx($.MenuDivider,{},t)))})}),W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,iconRight:G.SelectIcon,padding:2,text:null==s?void 0:s.title}),id:"list",menu:W.jsx($.Menu,{children:null==i?void 0:i.map(((e,t)=>W.jsx($.MenuItem,{disabled:e.name===(null==s?void 0:s.name),fontSize:1,onClick:()=>{return e=i[t],void a(ut.facetsUpdate({name:n.name,value:e.name}));var e},padding:2,text:e.title},e.name)))})})]})},Pt=e=>{const{facet:t}=e,n=ee.useDispatch(),a=t.operatorType;return W.jsxs(At,{facet:t,children:[(null==t?void 0:t.operatorTypes)&&W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,iconRight:G.SelectIcon,padding:2,text:Le[a].label}),id:"operators",menu:W.jsx($.Menu,{children:t.operatorTypes.map(((e,i)=>e?W.jsx($.MenuItem,{disabled:e===a,fontSize:1,onClick:()=>(e=>{n(ut.facetsUpdate({name:t.name,operatorType:e}))})(e),padding:2,text:Le[e].label},e):W.jsx($.MenuDivider,{},i)))})}),!Le[a].hideInput&&W.jsx($.Box,{marginLeft:1,style:{maxWidth:"125px"},children:W.jsx($.TextInput,{fontSize:1,onChange:e=>{n(ut.facetsUpdate({name:t.name,value:e.target.value}))},padding:2,radius:2,width:2,value:null==t?void 0:t.value})})]})};var Ut,Nt,Vt,Qt,Xt,Ht,Yt,Gt,Wt,$t,Kt,Zt,Jt,en,tn;const nn=null==(Xt=null==(Qt=null==(Vt=null==(Nt=null==(Ut=$.studioTheme)?void 0:Ut.color)?void 0:Nt.dark)?void 0:Vt.primary)?void 0:Qt.spot)?void 0:Xt.blue,an=null==($t=null==(Wt=null==(Gt=null==(Yt=null==(Ht=$.studioTheme)?void 0:Ht.color)?void 0:Yt.dark)?void 0:Gt.default)?void 0:Wt.base)?void 0:$t.bg,sn=null==(Kt=$.studioTheme)?void 0:Kt.radius,on=null==(Zt=$.studioTheme)?void 0:Zt.space,ln=null==(tn=null==(en=null==(Jt=$.studioTheme)?void 0:Jt.fonts)?void 0:en.text)?void 0:tn.sizes,rn={control:(e,t)=>{let{isDisabled:n,isFocused:a}=t,i="inset 0 0 0 1px ".concat(oe.hues.gray[900].hex);return a&&(i="inset 0 0 0 1px ".concat(oe.hues.gray[900].hex,", 0 0 0 1px var(--card-bg-color), 0 0 0 3px var(--card-focus-ring-color) !important")),Q(Q({},e),{},{backgroundColor:an,color:oe.white.hex,border:"none",borderRadius:sn[2],boxShadow:i,fontSize:ln[1].fontSize,minHeight:"25px",opacity:n?.5:"inherit",outline:"none",transition:"none","&:hover":{boxShadow:"inset 0 0 0 1px ".concat($.studioTheme.color.dark.default.input.default.hovered.border)}})},input:e=>Q(Q({},e),{},{color:oe.white.hex,fontFamily:$.studioTheme.fonts.text.family,marginLeft:on[2]}),menuList:e=>Q(Q({},e),{},{padding:0}),noOptionsMessage:e=>Q(Q({},e),{},{fontFamily:$.studioTheme.fonts.text.family,fontSize:ln[1].fontSize,lineHeight:"1em"}),option:(e,t)=>{let{isFocused:n}=t;return Q(Q({},e),{},{backgroundColor:n?nn:"transparent",borderRadius:sn[2],color:n?oe.black.hex:"inherit",fontSize:ln[1].fontSize,lineHeight:"1em",padding:"4px 6px","&:hover":{backgroundColor:nn,color:oe.black.hex}})},placeholder:e=>Q(Q({},e),{},{fontFamily:$.studioTheme.fonts.text.family,marginLeft:on[2],paddingBottom:"2px"}),singleValue:e=>Q(Q({},e),{},{color:oe.white.hex,lineHeight:"1em",paddingBottom:"1px"}),valueContainer:e=>Q(Q({},e),{},{margin:0,padding:0})},dn=e=>W.jsx($.Box,{padding:1,children:W.jsx(ce.components.Option,Q(Q({},e),{},{children:W.jsx($.Box,{paddingY:1,children:W.jsx($.Text,{size:1,style:{color:"inherit"},textOverflow:"ellipsis",children:e.children})})}))}),cn={ClearIndicator:e=>W.jsx(ce.components.ClearIndicator,Q(Q({},e),{},{children:W.jsx($.Box,{paddingRight:1,style:{transform:"scale(0.85)"},children:W.jsx($.Text,{muted:!0,size:0,children:W.jsx(G.CloseIcon,{})})})})),DropdownIndicator:null,IndicatorSeparator:null,Menu:e=>W.jsx(ce.components.Menu,Q(Q({},e),{},{children:W.jsx($.Card,{radius:1,shadow:2,children:e.children})})),MenuList:e=>{const{children:t}=e;if(Array.isArray(t)){const e=t.length>5?165:33*t.length;return W.jsx(ue.Virtuoso,{className:"media__custom-scrollbar",itemContent:e=>{const n=t[e];return W.jsx(dn,Q({},n.props))},style:{height:e},totalCount:t.length})}return W.jsx(ce.components.MenuList,Q(Q({},e),{},{children:t}))},NoOptionsMessage:e=>W.jsx(ce.components.NoOptionsMessage,Q(Q({},e),{},{children:e.children})),Option:dn,SingleValue:e=>W.jsx(ce.components.SingleValue,Q(Q({},e),{},{children:W.jsx($.Box,{paddingLeft:2,children:W.jsx($.Text,{size:1,style:{color:"inherit",lineHeight:"2em"},textOverflow:"ellipsis",children:e.children})})}))},un=e=>{const{facet:t}=e,n=ee.useDispatch(),a=_t((e=>it(e))),i=_t((e=>e.tags.fetching)),s=Je(a),o=t.operatorType;return W.jsxs(At,{facet:t,children:[(null==t?void 0:t.operatorTypes)&&W.jsx($.MenuButton,{button:W.jsx($.Button,{fontSize:1,iconRight:G.SelectIcon,padding:2,text:Le[o].label}),id:"operators",menu:W.jsx($.Menu,{children:t.operatorTypes.map(((e,a)=>e?W.jsx($.MenuItem,{disabled:e===o,fontSize:1,onClick:()=>(e=>{n(ut.facetsUpdate({name:t.name,operatorType:e}))})(e),padding:2,text:Le[e].label},e):W.jsx($.MenuDivider,{},a)))})}),!Le[o].hideInput&&W.jsx($.Box,{marginX:1,style:{width:"160px"},children:W.jsx(Ee.default,{components:cn,instanceId:"facet-searchable",isClearable:!0,isDisabled:i,isSearchable:!0,name:"tags",noOptionsMessage:()=>"No tags",onChange:e=>{return a=e,void n(ut.facetsUpdate({name:t.name,value:a}));var a},options:s,placeholder:i?"Loading...":"Select...",styles:rn,value:null==t?void 0:t.value})})]})},pn=Se.default($.Flex)(y||(y=H(["\n > * {\n margin-bottom: ","px;\n }\n"])),(e=>e.theme.sanity.space[2])),hn=e=>{const{layout:t="inline"}=e,n=_t((e=>e.search.facets)),a=n.map((e=>"number"===e.type?W.jsx(Ot,{facet:e},e.name):"searchable"===e.type?W.jsx(un,{facet:e},e.name):"select"===e.type?W.jsx(Lt,{facet:e},e.name):"string"===e.type?W.jsx(Pt,{facet:e},e.name):null));if("inline"===t)return 0===n.length?null:W.jsx($.Box,{marginBottom:2,children:W.jsx($.Inline,{space:2,children:a})});if("stack"===t)return W.jsx(pn,{align:"flex-start",direction:"column",children:a});throw Error("Invalid layout")},mn=()=>{const e=ee.useDispatch(),t=_t((e=>e.assets.assetTypes)),n=_t((e=>e.search.facets)),a=!_t((e=>e.selected.document)),i=Ue.filter((e=>{if("group"===e.type||"divider"===e.type)return!0;if(a)return!(null==e?void 0:e.selectOnly);return e.assetTypes.filter((e=>t.includes(e))).length>0})).filter(((e,t,n)=>{const a=n[t-1];return("divider"!==e.type||0!==t&&t!==n.length-1)&&("divider"!==e.type||"divider"!==(null==a?void 0:a.type))})),s=i.filter((e=>e)).length-n.length>0,o=function(t){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return W.jsx(W.Fragment,{children:null==t?void 0:t.map(((t,i)=>{if("divider"===t.type)return W.jsx($.MenuDivider,{},i);if("group"===t.type)return W.jsx($.MenuGroup,{text:t.title,title:t.title,children:o(t.facets,a+1)},"group-".concat(a,"-").concat(i));if(t){const a=!!n.find((e=>e.name===t.name));return W.jsx($.MenuItem,{disabled:a,fontSize:1,onClick:()=>e(ut.facetsAdd({facet:t})),padding:2,text:t.title},t.name)}return null}))})};return W.jsxs($.Flex,{children:[W.jsx($.MenuButton,{button:W.jsx($.Button,{disabled:!s,fontSize:1,icon:G.AddCircleIcon,mode:"bleed",text:"Add filter",tone:"primary"}),id:"facets",menu:W.jsx($.Menu,{children:o(i)}),placement:"right-start",portal:!0}),n.length>0&&W.jsx($.Button,{fontSize:1,mode:"bleed",onClick:()=>e(ut.facetsClear()),text:"Clear"})]})},gn=()=>W.jsxs("svg",{"data-sanity-icon":"media__tag",fill:"currentColor",height:"1em",stroke:"currentColor",strokeWidth:"0",viewBox:"0 0 512 512",width:"1em",children:[W.jsx("path",{d:"M435.25 48h-122.9a14.46 14.46 0 00-10.2 4.2L56.45 297.9a28.85 28.85 0 000 40.7l117 117a28.85 28.85 0 0040.7 0L459.75 210a14.46 14.46 0 004.2-10.2v-123a28.66 28.66 0 00-28.7-28.8z",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"32"}),W.jsx("path",{d:"M384 160a32 32 0 1132-32 32 32 0 01-32 32z"})]}),fn=()=>{const e=_t((e=>e.search.query)),t=ee.useDispatch();return W.jsxs($.Box,{style:{position:"relative"},children:[W.jsx($.TextInput,{fontSize:1,icon:G.SearchIcon,onChange:e=>{t(ut.querySet({searchQuery:e.currentTarget.value}))},placeholder:"Search",radius:2,value:e}),e.length>0&&W.jsx($.Flex,{align:"center",justify:"center",onClick:()=>{t(ut.querySet({searchQuery:""}))},style:{cursor:"pointer",height:"100%",opacity:.75,position:"absolute",right:0,top:0,width:"2em",zIndex:1},children:W.jsx(G.CloseIcon,{})})]})},xn=()=>{var e;const t=ee.useDispatch(),n=_t((e=>e.assets.fetching)),a=_t((e=>e.assets.pageIndex)),i=_t((e=>e.search.facets)),s=_t((e=>e.tags.panelVisible)),o=$.useMediaIndex();return W.jsxs($.Box,{paddingY:2,style:{borderBottom:"1px solid ".concat(null==(e=oe.hues.gray)?void 0:e[900].hex),zIndex:2},children:[W.jsx($.Box,{marginBottom:2,children:W.jsx($.Flex,{align:"flex-start",direction:["column","column","column","column","row"],justify:"space-between",children:W.jsxs($.Flex,{flex:1,style:{alignItems:"flex-start",flex:1,height:"100%",justifyContent:o<2?"space-between":"flex-start",position:"relative",width:"100%"},children:[W.jsx($.Box,{marginX:2,style:{minWidth:"200px"},children:W.jsx(fn,{})}),W.jsxs($.Box,{display:["none","none","block"],children:[W.jsx(hn,{}),W.jsx(mn,{})]}),W.jsx($.Box,{display:["block","block","none"],marginX:2,children:W.jsxs($.Inline,{space:2,style:{whiteSpace:"nowrap"},children:[W.jsx($.Button,{fontSize:1,mode:"ghost",onClick:()=>{t(Mt.showSearchFacets())},text:"Filters".concat(i.length>0?" (".concat(i.length,")"):""),tone:"primary"}),W.jsx($.Button,{fontSize:1,mode:"ghost",onClick:()=>{t(Mt.showTags())},text:"Tags",tone:"primary"})]})})]})})}),W.jsx($.Box,{children:W.jsxs($.Flex,{align:"center",justify:["space-between"],children:[W.jsx($.Box,{marginX:2,children:W.jsx(Bt,{})}),W.jsxs($.Flex,{marginX:2,children:[W.jsx(zt,{}),W.jsx($.Box,{display:["none","none","block"],marginLeft:2,children:W.jsx($.Button,{fontSize:1,icon:W.jsx($.Box,{style:{transform:"scale(0.75)"},children:W.jsx(gn,{})}),onClick:()=>{t(ot.panelVisibleSet({panelVisible:!s}))},mode:s?"default":"ghost",text:s?"Tags":""})})]})]})}),W.jsx(Dt,{loading:n},a)]})},yn=te.createSlice({name:"debug",initialState:{badConnection:!1,enabled:!1},reducers:{setBadConnection(e,t){e.badConnection=t.payload},toggleEnabled(e){e.enabled=!e.enabled}}}),vn=yn.actions;var bn=yn.reducer;const jn=()=>{const e=ee.useDispatch(),t=_t((e=>e.debug.badConnection)),n=_t((e=>e.debug.enabled));return Ae("alt+ctrl+shift+/",(()=>{e(vn.toggleEnabled())})),n?W.jsx($.Box,{padding:4,style:{bottom:0,left:0,pointerEvents:"none",position:"fixed",width:"100%"},children:W.jsxs($.Flex,{align:"center",children:[W.jsx($.Box,{marginRight:3,children:W.jsx($.Text,{muted:!0,size:1,children:W.jsx(G.PlugIcon,{})})}),W.jsx($.Tooltip,{content:W.jsx($.Box,{padding:2,children:W.jsx($.Text,{muted:!0,size:1,children:t?"Bad connection: +3000ms & 50% chance to fail":"No connection throttling"})}),fallbackPlacements:["right","left"],placement:"bottom",children:W.jsx($.Switch,{checked:t,onChange:t=>{const n=t.target.checked;e(vn.setBadConnection(n))},style:{pointerEvents:"auto"}})})]})}):null},In=(e,t)=>{const n="undefined"!=typeof window&&window.devicePixelRatio?Math.round(window.devicePixelRatio):1,a=(null==t?void 0:t.height)?(null==t?void 0:t.height)*Math.max(1,n):void 0,i=t.width*Math.max(1,n),s=new URLSearchParams;return s.append("fit","max"),s.append("w",i.toString()),a&&s.append("h",a.toString()),"".concat(e.url,"?").concat(s.toString())},Cn=e=>Object.keys(e).reduce(((t,n)=>{const a=e[n];return"object"==typeof a&&null!==a&&a.constructor!==Array?t[n]=Cn(a):""===a||void 0===a||0===(null==a?void 0:a.length)?t[n]=null:t[n]="string"==typeof a&&a?e[n].trim():e[n],t}),{}),wn=e=>"sanity.fileAsset"===e._type,Tn=e=>"sanity.imageAsset"===e._type,kn=e=>"".concat(e.metadata.dimensions.width,"x").concat(e.metadata.dimensions.height,"px"),Sn=e=>{const{disabled:t,url:n}=e,a=K.useRef(),[i,s]=K.useState(!1);return K.useEffect((()=>()=>{a.current&&clearTimeout(a.current)}),[]),W.jsx($.Popover,{content:W.jsx($.Text,{muted:!0,size:1,children:"Copied!"}),open:i,padding:2,placement:"top",radius:1,children:W.jsx($.Button,{disabled:t,fontSize:1,icon:G.ClipboardIcon,mode:"ghost",onClick:()=>{a.current&&clearTimeout(a.current),s(!0),ze.default(n),a.current=setTimeout((()=>{s(!1)}),1250)},text:"Copy URL"})})},_n=e=>{let{label:t,value:n}=e;return W.jsxs($.Flex,{justify:"space-between",children:[W.jsx($.Text,{size:1,style:{opacity:.8,width:"40%"},textOverflow:"ellipsis",children:t}),W.jsx($.Text,{size:1,style:{opacity:.4,textAlign:"right",width:"60%"},textOverflow:"ellipsis",children:n})]})},En=e=>{var t;const{asset:n,item:a}=e,i=null==(t=null==n?void 0:n.metadata)?void 0:t.exif;return W.jsxs($.Box,{marginTop:3,children:[W.jsx($.Box,{children:W.jsxs($.Stack,{space:3,children:[W.jsx(_n,{label:"Size",value:Be.default(null==n?void 0:n.size,{base:10,round:0})}),W.jsx(_n,{label:"MIME type",value:null==n?void 0:n.mimeType}),W.jsx(_n,{label:"Extension",value:(null==n?void 0:n.extension).toUpperCase()}),Tn(n)&&W.jsx(_n,{label:"Dimensions",value:kn(n)})]})}),i&&W.jsxs(W.Fragment,{children:[W.jsx($.Box,{marginY:4,style:{background:"#222",height:"1px",width:"100%"}}),W.jsx($.Box,{children:W.jsxs($.Stack,{space:3,children:[i.ISO&&W.jsx(_n,{label:"ISO",value:i.ISO}),i.FNumber&&W.jsx(_n,{label:"Aperture",value:"ƒ/".concat(i.FNumber)}),i.FocalLength&&W.jsx(_n,{label:"Focal length",value:"".concat(i.FocalLength,"mm")}),i.ExposureTime&&W.jsx(_n,{label:"Exposure time",value:"1/".concat(1/i.ExposureTime)}),i.DateTimeOriginal&&W.jsx(_n,{label:"Original date",value:Re.default(new Date(i.DateTimeOriginal),"PPp")})]})})]}),W.jsx($.Box,{marginTop:5,children:W.jsxs($.Inline,{space:2,children:[W.jsx($.Button,{disabled:!a||(null==a?void 0:a.updating),fontSize:1,icon:G.DownloadIcon,mode:"ghost",onClick:()=>{window.location.href="".concat(n.url,"?dl=").concat(n.originalFilename)},text:"Download"}),W.jsx(Sn,{disabled:!a||(null==a?void 0:a.updating),url:n.url})]})})]})},Mn=e=>W.jsx($.Dialog,Q(Q({},e),{},{style:{position:"fixed"}})),Rn=e=>{const{assetId:t}=e,n=Y.useDocumentStore();return W.jsx(Y.WithReferringDocuments,{documentStore:n,id:t,children:e=>{let{isLoading:t,referringDocuments:n}=e;return W.jsx(Bn,{isLoading:t,referringDocuments:n})}})},Bn=e=>{const{isLoading:t,referringDocuments:n}=e,a=Y.useSchema(),i=n.reduce(((e,t)=>t._id.startsWith("drafts.")?e.concat(t._id.slice(7)):e),[]),s=n.filter((e=>!i.includes(e._id)));return t?W.jsx($.Text,{size:1,children:"Loading..."}):0===s.length?W.jsx($.Text,{size:1,children:"No documents are referencing this asset"}):W.jsx($.Card,{flex:1,marginBottom:2,padding:2,radius:2,shadow:1,children:W.jsx($.Stack,{space:2,children:null==s?void 0:s.map((e=>W.jsx(zn,{doc:e,schemaType:a.get(e._type)},e._id)))})})},zn=e=>{const{doc:t,schemaType:n}=e,{onClick:a}=ye.useIntentLink({intent:"edit",params:{id:t._id}});return n?W.jsx($.Button,{mode:"bleed",onClick:a,padding:2,style:{width:"100%"},children:W.jsx(Y.Preview,{layout:"default",schemaType:n,value:t})},t._id):W.jsx($.Box,{padding:2,children:W.jsxs($.Text,{size:1,children:["A document of the unknown type ",W.jsx("em",{children:t._type})]})})},Dn=Se.default($.Box)(v||(v=H(["\n text {\n font-family: "," !important;\n font-size: 8px !important;\n font-weight: 500 !important;\n }\n"])),(e=>e.theme.sanity.fonts.text.family)),Fn=e=>{const{extension:t,onClick:n,width:a}=e;return W.jsx($.Flex,{align:"center",justify:"center",onClick:n,style:{height:"100%"},children:W.jsx(Dn,{style:{width:a},children:t?W.jsx(ve.FileIcon,Q({extension:t},ve.defaultStyles[t])):W.jsx(ve.FileIcon,{})})})},An=e=>{const{asset:t}=e;return 0===t.mimeType.search("audio")?W.jsx($.Flex,{align:"center",justify:"center",style:{height:"100%"},children:W.jsx("audio",{controls:!0,src:t.url,style:{width:"100%"}})}):0===t.mimeType.search("video")?W.jsx("video",{controls:!0,src:t.url,style:{height:"100%",width:"100%"}}):W.jsx(Fn,{extension:t.extension,width:"50%"})};var qn,On,Ln,Pn,Un,Nn,Vn,Qn,Xn,Hn,Yn,Gn;const Wn=null==(Un=null==(Pn=null==(Ln=null==(On=null==(qn=$.studioTheme)?void 0:qn.color)?void 0:On.dark)?void 0:Ln.primary)?void 0:Pn.spot)?void 0:Un.blue,$n=null==(Hn=null==(Xn=null==(Qn=null==(Vn=null==(Nn=$.studioTheme)?void 0:Nn.color)?void 0:Vn.dark)?void 0:Qn.primary)?void 0:Xn.spot)?void 0:Hn.gray,Kn=null==(Yn=$.studioTheme)?void 0:Yn.radius,Zn=null==(Gn=$.studioTheme)?void 0:Gn.space,Jn={control:(e,t)=>{let{isDisabled:n,isFocused:a}=t,i="inset 0 0 0 1px ".concat(oe.hues.gray[900].hex);return a&&(i="inset 0 0 0 1px ".concat(oe.hues.gray[900].hex,", 0 0 0 1px var(--card-bg-color), 0 0 0 3px var(--card-focus-ring-color) !important")),Q(Q({},e),{},{background:n?$.studioTheme.color.dark.default.input.default.disabled.bg:"transparent",color:oe.white.hex,border:"none",borderRadius:Kn[1],boxShadow:i,minHeight:"35px",outline:"none",transition:"none","&:hover":{boxShadow:"inset 0 0 0 1px ".concat($.studioTheme.color.dark.default.input.default.hovered.border)}})},indicatorsContainer:(e,t)=>{let{isDisabled:n}=t;return Q(Q({},e),{},{opacity:n?.25:1})},input:e=>Q(Q({},e),{},{color:oe.white.hex,fontFamily:$.studioTheme.fonts.text.family,marginLeft:Zn[2]}),menuList:e=>Q({},e),multiValue:(e,t)=>{let{isDisabled:n}=t;return Q(Q({},e),{},{backgroundColor:$n,borderRadius:Kn[2],opacity:n?.5:1})},multiValueRemove:e=>Q(Q({},e),{},{paddingLeft:0,"&:hover":{background:"transparent",color:"inherit"}}),noOptionsMessage:e=>Q(Q({},e),{},{fontFamily:$.studioTheme.fonts.text.family,lineHeight:"1em"}),option:(e,t)=>{let{isFocused:n}=t;return Q(Q({},e),{},{backgroundColor:n?Wn:"transparent",borderRadius:Kn[2],color:n?oe.black.hex:"inherit",fontFamily:$.studioTheme.fonts.text.family,padding:"4px 8px","&:hover":{backgroundColor:Wn,color:oe.black.hex}})},placeholder:e=>Q(Q({},e),{},{fontFamily:$.studioTheme.fonts.text.family,marginLeft:Zn[2]}),valueContainer:e=>Q(Q({},e),{},{marginBottom:Zn[0],marginLeft:Zn[1],marginTop:Zn[0],padding:0})},ea=e=>W.jsx($.Box,{paddingX:1,paddingY:1,children:W.jsx(ce.components.Option,Q(Q({},e),{},{children:W.jsxs($.Flex,{align:"center",children:[e.data.__isNew__&&W.jsx(G.AddIcon,{style:{marginRight:"3px"}}),e.children]})}))}),ta={DropdownIndicator:e=>W.jsx(ce.components.DropdownIndicator,Q(Q({},e),{},{children:W.jsx($.Box,{paddingX:2,children:W.jsx($.Text,{size:1,children:W.jsx(G.ChevronDownIcon,{})})})})),IndicatorSeparator:null,Menu:e=>W.jsx(ce.components.Menu,Q(Q({},e),{},{children:W.jsx($.Card,{radius:1,shadow:2,children:e.children})})),MenuList:e=>{const{children:t}=e;if(Array.isArray(t)){const e=t.length>5?185:37*t.length;return W.jsx(ue.Virtuoso,{className:"media__custom-scrollbar",itemContent:e=>{const n=t[e];return W.jsx(ea,Q({},n.props))},style:{height:e},totalCount:t.length})}return W.jsx(ce.components.MenuList,Q(Q({},e),{},{children:t}))},MultiValueLabel:e=>W.jsx($.Box,{paddingLeft:1,paddingRight:0,paddingY:1,children:W.jsx($.Text,{size:2,weight:"medium",children:W.jsx(ce.components.MultiValueLabel,Q({},e))})}),MultiValueRemove:e=>W.jsx(ce.components.MultiValueRemove,Q(Q({},e),{},{children:W.jsx(G.CloseIcon,{color:"#1f2123"})})),Option:ea},na=Se.default(G.ErrorOutlineIcon)((e=>{let{theme:t}=e;return{color:t.sanity.color.spot.red}})),aa=e=>{const{description:t,error:n,label:a,name:i}=e;return W.jsxs(W.Fragment,{children:[W.jsx($.Box,{marginY:3,children:W.jsxs($.Inline,{space:2,children:[W.jsx($.Text,{as:"label",htmlFor:i,size:1,weight:"semibold",children:a}),n&&W.jsx($.Text,{size:1,children:W.jsx($.Tooltip,{content:W.jsx($.Box,{padding:2,children:W.jsxs($.Text,{muted:!0,size:1,children:[W.jsx(na,{style:{marginRight:"0.1em"}}),n.message]})}),fallbackPlacements:["top","left"],placement:"right",portal:!0,children:W.jsx(na,{})})})]})}),t&&W.jsx($.Box,{marginY:3,children:W.jsx($.Text,{htmlFor:i,muted:!0,size:1,children:t})})]})},ia=e=>{const{control:t,description:n,disabled:a,error:i,label:s,name:o,onCreateTag:l,options:r,placeholder:d,value:c}=e,u=_t((e=>e.tags.creating)),p=_t((e=>e.tags.fetching));return W.jsxs($.Box,{style:{zIndex:2},children:[W.jsx(aa,{description:n,error:i,label:s,name:o}),W.jsx(he.Controller,{control:t,defaultValue:c,name:o,render:e=>{let{onBlur:t,onChange:n,value:i}=e;return W.jsx(De.default,{components:ta,instanceId:"tags",isClearable:!1,isDisabled:u||a||p,isLoading:u,isMulti:!0,name:o,noOptionsMessage:()=>"No tags",onBlur:t,onChange:n,onCreateOption:l,options:r,placeholder:p?"Loading...":d,styles:Jn,value:i})}})]})},sa=K.forwardRef(((e,t)=>{const{description:n,disabled:a,error:i,label:s,name:o,placeholder:l,value:r}=e;return W.jsxs($.Box,{children:[W.jsx(aa,{description:n,error:i,label:s,name:o}),W.jsx($.TextInput,{autoComplete:"off",autoFocus:!0,defaultValue:r,disabled:a,id:o,name:o,placeholder:l,ref:t})]})})),oa=K.forwardRef(((e,t)=>{const{description:n,disabled:a,error:i,label:s,name:o,placeholder:l,rows:r,value:d}=e;return W.jsxs($.Box,{children:[W.jsx(aa,{description:n,error:i,label:s,name:o}),W.jsx($.TextArea,{autoComplete:"off",defaultValue:d,disabled:a,id:o,name:o,placeholder:l,ref:t,rows:r})]})})),la=e=>{const{disabled:t,isValid:n,lastUpdated:a,onClick:i}=e;let s;return s=n?a?W.jsxs(W.Fragment,{children:["Last updated",W.jsx("br",{})," ",Re.default(new Date(a),"PPp")]}):"No unpublished changes":"There are validation errors that need to be fixed before this document can be published",W.jsx($.Tooltip,{content:W.jsx($.Box,{padding:3,style:{maxWidth:"185px"},children:W.jsx($.Text,{muted:!0,size:1,children:s})}),disabled:"ontouchstart"in window,placement:"top",children:W.jsx($.Box,{children:W.jsx($.Button,{disabled:t,fontSize:1,onClick:i,text:"Save and close",tone:"primary"})})})},ra=Se.default.img(b||(b=H(["\n --checkerboard-color: ",";\n\n display: block;\n width: 100%;\n height: 100%;\n object-fit: contain;\n\n ","\n"])),oe.hues.gray[900].hex,(e=>e.showCheckerboard&&le.css(j||(j=H(["\n background-image: linear-gradient(45deg, var(--checkerboard-color) 25%, transparent 25%),\n linear-gradient(-45deg, var(--checkerboard-color) 25%, transparent 25%),\n linear-gradient(45deg, transparent 75%, var(--checkerboard-color) 75%),\n linear-gradient(-45deg, transparent 75%, var(--checkerboard-color) 75%);\n background-size: 20px 20px;\n background-position: 0 0, 0 10px, 10px -10px, -10px 0;\n "]))))),da=Me.object().shape({originalFilename:Me.string().trim().required("Filename cannot be empty")}),ca=e=>{var t,n,a;const{children:i,dialog:{assetId:s,id:o,lastCreatedTag:l,lastRemovedTagIds:r}}=e,d=Ye(),c=ee.useDispatch(),u=_t((e=>xt(e,String(s)))),p=_t(it),h=K.useRef(!1),[m,g]=K.useState(null==u?void 0:u.asset),[f,x]=K.useState("details"),y=u?null==u?void 0:u.asset:m,v=Je(p),b=_t((j=y,e=>{var t,n,a;const i=null==(a=null==(n=null==(t=null==j?void 0:j.opt)?void 0:t.media)?void 0:n.tags)?void 0:a.reduce(((t,n)=>{const a=e.tags.byIds[n._ref];return(null==a?void 0:a.tag)&&t.push(a),t}),[]);return i&&(null==i?void 0:i.length)>0?Je(i):null}));var j;const C=e=>({altText:(null==e?void 0:e.altText)||"",description:(null==e?void 0:e.description)||"",originalFilename:(null==e?void 0:e.originalFilename)||"",opt:{media:{tags:b}},title:(null==e?void 0:e.title)||""}),w=null==b?void 0:b.map((e=>e.label)).join(","),{control:T,formState:{errors:k,isDirty:S,isValid:_},getValues:E,handleSubmit:M,register:R,reset:B,setValue:z}=he.useForm({defaultValues:C(null==u?void 0:u.asset),mode:"onChange",resolver:pe.yupResolver(da)}),D=!u||(null==u?void 0:u.updating),F=()=>{(null==u?void 0:u.asset)&&c(Mt.showConfirmDeleteAssets({assets:[u],closeDialogId:null==u?void 0:u.asset._id}))},A=e=>{const{result:t,transition:n}=e;t&&"update"===n&&(g(t),B(C(t)))},q=async e=>{var t;if(!(null==u?void 0:u.asset))return;const n=Cn(e);c(It.updateRequest({asset:null==u?void 0:u.asset,closeDialogId:null==u?void 0:u.asset._id,formData:Q(Q({},n),{},{opt:{media:Q(Q({},n.opt.media),{},{tags:(null==(t=n.opt.media.tags)?void 0:t.map((e=>({_ref:e.value,_type:"reference",_weak:!0}))))||null})}})}))};K.useEffect((()=>{if(!(null==u?void 0:u.asset))return;const e=d.listen(ke.default(I||(I=H(["*[_id == $id]"]))),{id:null==u?void 0:u.asset._id}).subscribe(A);return()=>{null==e||e.unsubscribe()}}),[]),K.useEffect((()=>{h.current&&B({opt:{media:{tags:b}}},{errors:!0,dirtyFields:!0,isDirty:!0}),h.current=!0}),[w]),K.useEffect((()=>{if(l){const e=(E("opt.media.tags")||[]).concat([l]);z("opt.media.tags",e,{shouldDirty:!0})}}),[l]),K.useEffect((()=>{if(r){const e=(E("opt.media.tags")||[]).filter((e=>!r.includes(e.value)));z("opt.media.tags",e,{shouldDirty:!0})}}),[r]);const O=()=>W.jsx($.Box,{padding:3,children:W.jsxs($.Flex,{justify:"space-between",children:[W.jsx($.Button,{disabled:D,fontSize:1,mode:"bleed",onClick:F,text:"Delete",tone:"critical"}),W.jsx(la,{disabled:D||!S||!_,isValid:_,lastUpdated:y._updatedAt,onClick:M(q)})]})});return y?W.jsxs(Mn,{footer:W.jsx(O,{}),header:"Asset details",id:o,onClose:()=>{c(Mt.remove({id:o}))},width:3,children:[W.jsxs($.Flex,{direction:["column-reverse","column-reverse","row-reverse"],children:[W.jsxs($.Box,{flex:1,marginTop:[5,5,0],padding:4,children:[W.jsxs($.TabList,{space:2,children:[W.jsx($.Tab,{"aria-controls":"details-panel",disabled:D,id:"details-tab",label:"Details",onClick:()=>x("details"),selected:"details"===f,size:2}),W.jsx($.Tab,{"aria-controls":"references-panel",disabled:D,id:"references-tab",label:"References",onClick:()=>x("references"),selected:"references"===f,size:2})]}),W.jsxs($.Box,{as:"form",marginTop:4,onSubmit:M(q),children:[!u&&W.jsx($.Card,{marginBottom:3,padding:3,radius:2,shadow:1,tone:"critical",children:W.jsx($.Text,{size:1,children:"This file cannot be found – it may have been deleted."})}),W.jsx("button",{style:{display:"none"},tabIndex:-1,type:"submit"}),W.jsx($.TabPanel,{"aria-labelledby":"details",hidden:"details"!==f,id:"details-panel",children:W.jsxs($.Stack,{space:3,children:[W.jsx(ia,{control:T,disabled:D,error:null==(n=null==(t=null==k?void 0:k.opt)?void 0:t.media)?void 0:n.tags,label:"Tags",name:"opt.media.tags",onCreateTag:e=>{c(ot.createRequest({assetId:null==y?void 0:y._id,name:e}))},options:v,placeholder:"Select or create...",value:b}),W.jsx(sa,{disabled:D,error:null==k?void 0:k.originalFilename,label:"Filename",name:"originalFilename",ref:R,value:null==y?void 0:y.originalFilename}),W.jsx(sa,{disabled:D,error:null==k?void 0:k.title,label:"Title",name:"title",ref:R,value:null==y?void 0:y.title}),W.jsx(sa,{disabled:D,error:null==k?void 0:k.altText,label:"Alt Text",name:"altText",ref:R,value:null==y?void 0:y.altText}),W.jsx(oa,{disabled:D,error:null==k?void 0:k.description,label:"Description",name:"description",ref:R,rows:3,value:null==y?void 0:y.description})]})}),W.jsx($.TabPanel,{"aria-labelledby":"references",hidden:"references"!==f,id:"references-panel",children:W.jsx($.Box,{marginTop:5,children:(null==u?void 0:u.asset)&&W.jsx(Rn,{assetId:null==u?void 0:u.asset._id})})})]})]}),W.jsxs($.Box,{flex:1,padding:4,children:[W.jsxs($.Box,{style:{aspectRatio:"1"},children:[wn(y)&&W.jsx(An,{asset:y}),Tn(y)&&W.jsx(ra,{draggable:!1,showCheckerboard:!(null==(a=null==y?void 0:y.metadata)?void 0:a.isOpaque),src:In(y,{height:600,width:600})})]}),y&&W.jsx($.Box,{marginTop:4,children:W.jsx(En,{asset:y,item:u})})]})]}),i]}):null},ua=e=>{const{children:t,dialog:n}=e,a=ee.useDispatch(),i=()=>{a(Mt.remove({id:null==n?void 0:n.id}))},s=()=>{(null==n?void 0:n.closeDialogId)&&a(Mt.remove({id:null==n?void 0:n.closeDialogId})),(null==n?void 0:n.confirmCallbackAction)&&a(n.confirmCallbackAction),i()},o=()=>W.jsx($.Box,{padding:3,children:W.jsxs($.Flex,{justify:"space-between",children:[W.jsx($.Button,{fontSize:1,mode:"bleed",onClick:i,text:"Cancel"}),W.jsx($.Button,{fontSize:1,onClick:s,text:null==n?void 0:n.confirmText,tone:null==n?void 0:n.tone})]})}),l=()=>W.jsxs($.Flex,{align:"center",children:[W.jsx($.Box,{paddingX:1,children:W.jsx(G.WarningOutlineIcon,{})}),W.jsx($.Box,{marginLeft:2,children:null==n?void 0:n.headerTitle})]});return W.jsxs(Mn,{footer:W.jsx(o,{}),header:W.jsx(l,{}),id:"confirm",onClose:i,width:1,children:[W.jsx($.Box,{paddingX:4,paddingY:4,children:W.jsxs($.Stack,{space:3,children:[(null==n?void 0:n.title)&&W.jsx($.Text,{size:1,children:n.title}),(null==n?void 0:n.description)&&W.jsx($.Text,{muted:!0,size:1,children:W.jsx("em",{children:n.description})})]})}),t]})},pa=e=>{const{children:t,dialog:{id:n}}=e,a=ee.useDispatch(),i=K.useCallback((()=>{a(Mt.clear())}),[]);return W.jsxs(Mn,{header:"Filters",id:n,onClose:i,width:1,children:[W.jsxs($.Box,{padding:3,children:[W.jsx(hn,{layout:"stack"}),W.jsx(mn,{})]}),t]})},ha=Me.object().shape({name:Me.string().required("Name cannot be empty")}),ma=e=>{const{children:t,dialog:{id:n}}=e,a=ee.useDispatch(),i=_t((e=>e.tags.creating)),s=_t((e=>e.tags.creatingError)),{formState:{errors:o,isDirty:l,isValid:r},handleSubmit:d,register:c,setError:u}=he.useForm({defaultValues:{name:""},mode:"onChange",resolver:pe.yupResolver(ha)}),p=i,h=async e=>{const t=Cn(e);a(ot.createRequest({name:t.name}))};K.useEffect((()=>{s&&u("name",{message:null==s?void 0:s.message})}),[s]);const m=()=>W.jsx($.Box,{padding:3,children:W.jsx($.Flex,{justify:"flex-end",children:W.jsx(la,{disabled:p||!l||!r,isValid:r,onClick:d(h)})})});return W.jsxs(Mn,{footer:W.jsx(m,{}),header:"Create Tag",id:n,onClose:()=>{a(Mt.clear())},width:1,children:[W.jsxs($.Box,{as:"form",padding:4,onSubmit:d(h),children:[W.jsx("button",{style:{display:"none"},tabIndex:-1,type:"submit"}),W.jsx(sa,{disabled:p,error:null==o?void 0:o.name,label:"Name",name:"name",ref:c})]}),t]})},ga=Me.object().shape({name:Me.string().required("Name cannot be empty")}),fa=e=>{const{children:t,dialog:{id:n,tagId:a}}=e,i=Ye(),s=ee.useDispatch(),o=_t((e=>st(e,String(a)))),[l,r]=K.useState(null==o?void 0:o.tag),d=o?null==o?void 0:o.tag:l,c=e=>{var t;return{name:(null==(t=null==e?void 0:e.name)?void 0:t.current)||""}},{formState:{errors:u,isDirty:p,isValid:h},handleSubmit:m,register:g,reset:f,setError:x}=he.useForm({defaultValues:c(null==o?void 0:o.tag),mode:"onChange",resolver:pe.yupResolver(ga)}),y=!o||(null==o?void 0:o.updating),v=async e=>{var t;if(!(null==o?void 0:o.tag))return;const n=Cn(e);s(ot.updateRequest({closeDialogId:null==(t=null==o?void 0:o.tag)?void 0:t._id,formData:{name:{_type:"slug",current:n.name}},tag:null==o?void 0:o.tag}))},b=()=>{var e;(null==o?void 0:o.tag)&&s(Mt.showConfirmDeleteTag({closeDialogId:null==(e=null==o?void 0:o.tag)?void 0:e._id,tag:null==o?void 0:o.tag}))},j=e=>{const{result:t,transition:n}=e;t&&"update"===n&&(r(t),f(c(t)))};K.useEffect((()=>{var e;(null==o?void 0:o.error)&&x("name",{message:null==(e=o.error)?void 0:e.message})}),[null==o?void 0:o.error]),K.useEffect((()=>{if(!(null==o?void 0:o.tag))return;const e=i.listen(ke.default(C||(C=H(["*[_id == $id]"]))),{id:null==o?void 0:o.tag._id}).subscribe(j);return()=>{null==e||e.unsubscribe()}}),[]);const I=()=>{var e;return W.jsx($.Box,{padding:3,children:W.jsxs($.Flex,{justify:"space-between",children:[W.jsx($.Button,{disabled:y,fontSize:1,mode:"bleed",onClick:b,text:"Delete",tone:"critical"}),W.jsx(la,{disabled:y||!p||!h,isValid:h,lastUpdated:null==(e=null==o?void 0:o.tag)?void 0:e._updatedAt,onClick:m(v)})]})})};return d?W.jsxs(Mn,{footer:W.jsx(I,{}),header:"Edit Tag",id:n,onClose:()=>{s(Mt.remove({id:n}))},width:1,children:[W.jsxs($.Box,{as:"form",padding:4,onSubmit:m(v),children:[!o&&W.jsx($.Card,{marginBottom:3,padding:3,radius:2,shadow:1,tone:"critical",children:W.jsx($.Text,{size:1,children:"This tag cannot be found – it may have been deleted."})}),W.jsx("button",{style:{display:"none"},tabIndex:-1,type:"submit"}),W.jsx(sa,{disabled:y,error:null==u?void 0:u.name,label:"Name",name:"name",ref:g})]}),t]}):null},xa=Se.default($.Flex)(w||(w=H(["\n height: ","px;\n"])),32),ya=Se.default($.Flex)(T||(T=H(["\n @media (pointer: fine) {\n visibility: hidden;\n }\n\n @media (hover: hover) and (pointer: fine) {\n ",":hover & {\n visibility: visible;\n }\n }\n"])),xa),va=e=>{const{disabled:t,icon:n,onClick:a,tone:i,tooltip:s}=e;return W.jsx($.Tooltip,{content:W.jsx($.Container,{padding:2,width:0,children:W.jsx($.Text,{muted:!0,size:1,children:s})}),disabled:"ontouchstart"in window,placement:"top",children:W.jsx($.Button,{disabled:t,fontSize:1,icon:n,mode:"bleed",onClick:a,padding:2,tone:i})})},ba=e=>{var t,n;const{actions:a,tag:i}=e,s=ee.useDispatch(),o=_t(bt),l=_t(dt),r=_t((e=>{var t;return ct(e,null==(t=null==i?void 0:i.tag)?void 0:t._id)}));return W.jsxs(xa,{align:"center",flex:1,justify:"space-between",paddingLeft:3,children:[W.jsx($.Box,{flex:1,children:W.jsx($.Text,{size:1,style:{color:(null==i?void 0:i.updating)?oe.hues.gray[800].hex:oe.hues.gray[500].hex,userSelect:"none"},textOverflow:"ellipsis",children:null==(n=null==(t=null==i?void 0:i.tag)?void 0:t.name)?void 0:n.current})}),W.jsxs(ya,{align:"center",style:{flexShrink:0},children:[(null==a?void 0:a.includes("search"))&&W.jsx(va,{disabled:null==i?void 0:i.updating,icon:r?W.jsx(G.CloseIcon,{}):W.jsx(G.SearchIcon,{}),onClick:r?()=>{s(ut.facetsRemove({facetName:"tag"}))}:()=>{var e,t,n;const a=Q(Q({},Oe.tag),{},{value:{label:null==(t=null==(e=null==i?void 0:i.tag)?void 0:e.name)?void 0:t.current,value:null==(n=null==i?void 0:i.tag)?void 0:n._id}});s(l?ut.facetsUpdate({name:"tag",operatorType:"references",value:a.value}):ut.facetsAdd({facet:a}))},tooltip:r?"Remove filter":"Filter by tag"}),(null==a?void 0:a.includes("edit"))&&W.jsx(va,{disabled:null==i?void 0:i.updating,icon:W.jsx(G.EditIcon,{}),onClick:()=>{var e;s(tt.showTagEdit({tagId:null==(e=null==i?void 0:i.tag)?void 0:e._id}))},tone:"primary",tooltip:"Edit tag"}),(null==a?void 0:a.includes("applyAll"))&&W.jsx(va,{disabled:null==i?void 0:i.updating,icon:W.jsx(G.ArrowUpIcon,{}),onClick:()=>{s(Mt.showConfirmAssetsTagAdd({assetsPicked:o,tag:i.tag}))},tone:"primary",tooltip:"Add tag to selected assets"}),(null==a?void 0:a.includes("removeAll"))&&W.jsx(va,{disabled:null==i?void 0:i.updating,icon:W.jsx(G.ArrowDownIcon,{}),onClick:()=>{s(Mt.showConfirmAssetsTagRemove({assetsPicked:o,tag:i.tag}))},tone:"critical",tooltip:"Remove tag from selected assets"}),(null==a?void 0:a.includes("delete"))&&W.jsx(va,{disabled:null==i?void 0:i.updating,icon:W.jsx(G.TrashIcon,{}),onClick:()=>{s(Mt.showConfirmDeleteTag({tag:i.tag}))},tone:"critical",tooltip:"Delete tag"})]})]})},ja=K.memo((e=>{let{isScrolling:t,item:n}=e;var a;return"string"==typeof n?W.jsx($.Flex,{align:"center",justify:"space-between",paddingX:3,style:{height:"".concat(32,"px")},children:W.jsx($.Label,{size:0,children:n})},n):W.jsx(ba,{actions:t?void 0:n.actions,tag:n},null==(a=n.tag)?void 0:a._id)})),Ia=()=>{const e=_t(bt),t=_t(it),[n,a]=K.useState(!1),i=null==e?void 0:e.reduce(((e,t)=>{var n,a,i,s;const o=(null==(s=null==(i=null==(a=null==(n=null==t?void 0:t.asset)?void 0:n.opt)?void 0:a.media)?void 0:i.tags)?void 0:s.map((e=>e._ref)))||[];return e=e.concat(o)}),[]),s=[...new Set(i)],o=s.reduce(((t,n)=>{const a=e.every((e=>{var t,a,i,s;return(null!=(s=null==(i=null==(a=null==(t=e.asset.opt)?void 0:t.media)?void 0:a.tags)?void 0:i.findIndex((e=>e._ref===n)))?s:-1)>=0}));return a?t.appliedToAll.push(n):t.appliedToSome.push(n),t}),{appliedToAll:[],appliedToSome:[]}),l=t.filter((e=>o.appliedToAll.includes(e.tag._id))).map((e=>Q(Q({},e),{},{actions:["delete","edit","removeAll","search"]}))),r=t.filter((e=>o.appliedToSome.includes(e.tag._id))).map((e=>Q(Q({},e),{},{actions:["applyAll","delete","edit","removeAll","search"]}))),d=t.filter((e=>!s.includes(e.tag._id))).map((e=>Q(Q({},e),{},{actions:["applyAll","delete","edit","search"]})));let c=[];return 0===e.length?c=t.map((e=>Q(Q({},e),{},{actions:["delete","edit","search"]}))):((null==l?void 0:l.length)>0&&(c=[...c,1===e.length?"Used":"Used by all",...l]),(null==r?void 0:r.length)>0&&(c=[...c,"Used by some",...r]),(null==d?void 0:d.length)>0&&(c=[...c,"Unused",...d])),W.jsx(ue.Virtuoso,{className:"media__custom-scrollbar",computeItemKey:e=>{const t=c[e];return"string"==typeof t?t:t.tag._id},isScrolling:a,itemContent:e=>W.jsx(ja,{isScrolling:n,item:c[e]}),style:{flex:1,overflowX:"hidden"},totalCount:c.length})},Ca=e=>{var t,n;const{allowCreate:a,light:i,title:s}=e,o=ee.useDispatch(),l=_t((e=>e.tags.creating)),r=_t((e=>e.tags.fetching));return W.jsx(W.Fragment,{children:W.jsxs($.Flex,{align:"center",justify:"space-between",paddingLeft:3,style:{background:i?null==(t=oe.hues.gray)?void 0:t[900].hex:oe.black.hex,borderBottom:"1px solid ".concat(null==(n=oe.hues.gray)?void 0:n[900].hex),height:"".concat(32,"px")},children:[W.jsxs($.Inline,{space:2,children:[W.jsx($.Label,{size:0,children:s}),r&&W.jsx($.Label,{size:0,style:{opacity:.3},children:"Loading..."})]}),a&&W.jsx($.Box,{marginRight:1,children:W.jsx($.Button,{disabled:l,fontSize:1,icon:G.ComposeIcon,mode:"bleed",onClick:()=>{o(tt.showTagCreate())},style:{background:"transparent",boxShadow:"none"}})})]})})},wa=()=>{const e=_t(jt),t=_t(it),n=_t((e=>e.tags.fetching)),a=-1!==_t((e=>e.tags.fetchCount)),i=!n&&(null==t?void 0:t.length)>0,s=!!(e>0);return W.jsxs($.Flex,{direction:"column",flex:1,style:{background:oe.black.hex,height:"100%"},children:[W.jsx(Ca,{allowCreate:!0,light:s,title:s?"Tags (in selection)":"Tags"}),a&&!i&&W.jsx($.Box,{padding:3,children:W.jsx($.Text,{size:1,style:{color:oe.hues.gray[700].hex},children:W.jsx("em",{children:"No tags"})})}),i&&W.jsx(Ia,{})]})},Ta=e=>{const{children:t,dialog:{id:n}}=e,a=ee.useDispatch(),i=K.useCallback((()=>{a(Mt.clear())}),[]);return W.jsxs(Mn,{header:"All Tags",id:n,onClose:i,width:1,children:[W.jsx($.Box,{style:{height:"100%",minHeight:"420px"},children:W.jsx(wa,{})}),t]})},ka=()=>{const e=_t((e=>e.dialog.items)),t=(e,n)=>{if(0===e.length||n>=e.length)return null;const a=e[n],i=t(e,n+1);return"assetEdit"===a.type?W.jsx(ca,{dialog:a,children:i},n):"confirm"===a.type?W.jsx(ua,{dialog:a,children:i},n):"searchFacets"===a.type?W.jsx(pa,{dialog:a,children:i},n):"tagCreate"===a.type?W.jsx(ma,{dialog:a,children:i},n):"tagEdit"===a.type?W.jsx(fa,{dialog:a,children:i},n):"tags"===a.type?W.jsx(Ta,{dialog:a,children:i},n):null};return t(e,0)},Sa=K.createContext(void 0),_a=e=>{const{children:t,open:n}=e,a={open:n};return W.jsx(Sa.Provider,{value:a,children:t})},Ea=e=>{const{onClose:t}=e,{open:n}=(()=>{const e=K.useContext(Sa);if(void 0===e)throw new Error("useDropzoneActions must be used within an DropzoneDispatchProvider");return e})(),{onSelect:a}=He(),i=_t((e=>e.assets.assetTypes)),s=_t((e=>e.selected.document));return W.jsx($.Box,{paddingY:2,children:W.jsxs($.Flex,{align:"center",justify:"space-between",children:[W.jsx($.Box,{flex:1,marginX:3,children:W.jsxs($.Inline,{style:{whiteSpace:"nowrap"},children:[W.jsx($.Text,{textOverflow:"ellipsis",weight:"semibold",children:W.jsx("span",{children:a?"Insert ".concat(i.join(" or ")):"Browse Assets"})}),s&&W.jsx($.Box,{display:["none","none","block"],children:W.jsxs($.Text,{children:[W.jsx("span",{style:{margin:"0 0.5em"},children:W.jsx(G.Icon,{symbol:"arrow-right"})}),W.jsx("span",{style:{textTransform:"capitalize"},children:s._type})]})})]})}),W.jsxs($.Flex,{marginX:2,children:[W.jsx($.Button,{fontSize:1,icon:G.UploadIcon,mode:"bleed",onClick:n,text:"Upload ".concat(1===i.length?_e.default(i[0]):"assets"),tone:"primary"}),t&&W.jsx($.Box,{style:{flexShrink:0},children:W.jsx($.Button,{disabled:!t,icon:G.CloseIcon,mode:"bleed",onClick:t,radius:2})})]})]})})},Ma=te.createSelector([e=>e.assets.allIds,e=>e.uploads.allIds],((e,t)=>{const n=e.map((e=>({id:e,type:"asset"})));return[...t.map((e=>({id:e,type:"upload"}))),...n]})),Ra=Se.default($.Flex)(k||(k=H(["\n box-sizing: border-box;\n height: 100%;\n overflow: hidden;\n padding: 2px;\n position: relative;\n width: 100%;\n"]))),Ba=Se.default($.Flex)(S||(S=H(["\n border: 1px solid transparent;\n height: 100%;\n pointer-events: ",";\n position: relative;\n transition: all 300ms;\n user-select: none;\n width: 100%;\n\n border: ",";\n\n ","\n"])),(e=>e.updating?"none":"auto"),(e=>e.picked?"1px solid ".concat(e.theme.sanity.color.spot.orange," !important"):"1px solid inherit"),(e=>!e.updating&&le.css(_||(_=H(["\n @media (hover: hover) and (pointer: fine) {\n &:hover {\n border: 1px solid ",";\n }\n }\n "])),oe.hues.gray[500].hex))),za=Se.default($.Flex)(E||(E=H(["\n cursor: ",";\n height: ","px;\n transition: all 300ms;\n\n @media (hover: hover) and (pointer: fine) {\n &:hover {\n background: ",";\n }\n }\n"])),(e=>e.selected?"default":"pointer"),32,oe.hues.gray[950].hex),Da=Se.default(G.WarningFilledIcon)((e=>{let{theme:t}=e;return{color:t.sanity.color.spot.red}}));var Fa=K.memo((e=>{var t,n;const{id:a,selected:i}=e,s=Ae("shift"),o=ee.useDispatch(),l=_t((e=>e.assets.lastPicked)),r=_t((e=>xt(e,a))),d=null==r?void 0:r.asset,c=null==r?void 0:r.error,u=null==(n=null==(t=null==r?void 0:r.asset)?void 0:t.metadata)?void 0:n.isOpaque,p=null==r?void 0:r.picked,h=null==r?void 0:r.updating,{onSelect:m}=He();if(!d)return null;const g=h?.5:1,f=i||h?.25:1;return W.jsx(Ra,{children:W.jsxs(Ba,{direction:"column",picked:p,updating:r.updating,children:[W.jsxs($.Box,{flex:1,style:{cursor:i?"default":"pointer",position:"relative"},children:[W.jsxs("div",{onClick:e=>{e.stopPropagation(),m?m([{kind:"assetDocumentId",value:d._id}]):s.current?o(p?It.pick({assetId:d._id,picked:!p}):It.pickRange({startId:l||d._id,endId:d._id})):o(Mt.showAssetEdit({assetId:d._id}))},style:{height:"100%",opacity:f},children:[wn(d)&&W.jsx(Fn,{extension:d.extension,width:"80px"}),Tn(d)&&W.jsx(ra,{draggable:!1,showCheckerboard:!u,src:In(d,{height:250,width:250}),style:{draggable:!1,transition:"opacity 1000ms"}})]}),i&&!h&&W.jsx($.Flex,{align:"center",justify:"center",style:{height:"100%",left:0,opacity:g,position:"absolute",top:0,width:"100%"},children:W.jsx($.Text,{size:2,children:W.jsx(G.CheckmarkCircleIcon,{})})}),h&&W.jsx($.Flex,{align:"center",justify:"center",style:{height:"100%",left:0,position:"absolute",top:0,width:"100%"},children:W.jsx($.Spinner,{})})]}),W.jsxs(za,{align:"center",onClick:e=>{e.stopPropagation(),m?o(Mt.showAssetEdit({assetId:d._id})):s.current&&!p?o(It.pickRange({startId:l||d._id,endId:d._id})):o(It.pick({assetId:d._id,picked:!p}))},paddingX:1,style:{opacity:g},children:[m?W.jsx(G.EditIcon,{style:{flexShrink:0,opacity:.5}}):W.jsx($.Checkbox,{checked:p,readOnly:!0,style:{flexShrink:0,pointerEvents:"none",transform:"scale(0.8)"}}),W.jsx($.Box,{marginLeft:2,children:W.jsx($.Text,{muted:!0,size:0,textOverflow:"ellipsis",children:d.originalFilename})})]}),c&&W.jsx($.Box,{padding:3,style:{position:"absolute",right:0,top:0},children:W.jsx($.Tooltip,{content:W.jsx($.Container,{padding:2,width:0,children:W.jsx($.Text,{size:1,children:c})}),placement:"left",portal:!0,children:W.jsx($.Text,{size:1,children:W.jsx(Da,{color:"critical"})})})})]})})}));const Aa=async e=>{const t=await(e=>new Promise((t=>{const n=window.URL.createObjectURL(e),a=new Image;a.onload=()=>{window.URL.revokeObjectURL(n),t(a)},a.src=n})))(e),n=await(a=t,new Promise((e=>{const t=a.width/a.height,n=document.createElement("canvas");n.width=180,n.height=Math.max(180/t,1);try{const i=n.getContext("2d");null==i||i.drawImage(a,0,0,180,180/t),n.toBlob(e,"image/jpeg")}catch(e){console.warn("Unable to generate preview image:",e)}})));var a;if(!n)throw Error("Unable to generate file Blob");return window.URL.createObjectURL(n)};function qa(e,t){const n=e.indexOf(t);return n>-1&&e.splice(n,1),e}const Oa=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:4;const t=[],n=[],a=new ie.Subject;function i(o){return new ie.Observable((l=>{if(t.length>=e)return s(o).pipe(se.mergeMap(i)).subscribe(l);const r=o.subscribe(l);return t.push(r),()=>{for(qa(t,r),qa(n,o),r.unsubscribe();n.length>0&&t.length<e;)a.next(n.shift())}}))}function s(e){return n.push(e),a.asObservable().pipe(se.first((t=>t===e)))}return i},La=e=>Array.prototype.map.call(new Uint8Array(e),(e=>"00".concat(e.toString(16)).slice(-2))).join(""),Pa=e=>window.crypto&&window.crypto.subtle&&window.FileReader?(e=>new ie.Observable((t=>{const n=new FileReader;return n.onload=()=>{t.next(n.result),t.complete()},n.onerror=e=>{t.error(e)},n.readAsArrayBuffer(e),()=>{n.abort()}})))(e).pipe(se.mergeMap((e=>window.crypto.subtle.digest("SHA-1",e))),se.map(La)):ie.throwError({message:"Unable to generate hash: uploads are only allowed in secure contexts",statusCode:500}),Ua=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;const n=Oa(t);return function(){return ie.from(n(e(...arguments)))}}(((e,t,n,a)=>ie.of(null).pipe(se.mergeMap((()=>((e,t,n)=>e.observable.fetch("*[_type == $documentType && sha1hash == $hash][0]",{documentType:t,hash:n}))(e,"sanity.".concat(t,"Asset"),a))),se.mergeMap((e=>e?ie.throwError({message:"Asset already exists",statusCode:409}):ie.of(null))),se.mergeMap((()=>e.observable.assets.upload(t,n,{extract:["blurhash","exif","location","lqip","palette"],preserveFilename:!0}).pipe(se.map((e=>"response"===e.type?{asset:e.body.document,id:e.body.document._id,type:"complete"}:e)))))))),Na=te.createSlice({name:"uploads",initialState:{allIds:[],byIds:{}},extraReducers:e=>{e.addCase(ht.uploadComplete,((e,t)=>{const{asset:n}=t.payload;e.byIds[n.sha1hash]&&(e.byIds[n.sha1hash].status="complete")}))},reducers:{checkRequest(e,t){},checkComplete(e,t){const{results:n}=t.payload;Object.keys(n).forEach((t=>{const n=e.allIds.indexOf(t);if(n>=0&&e.allIds.splice(n,1),e.byIds[t]){const n=e.byIds[t].objectUrl;n&&window.URL.revokeObjectURL(n),delete e.byIds[t]}}))},previewReady(e,t){const{blobUrl:n,hash:a}=t.payload;e.byIds[a]&&(e.byIds[a].objectUrl=n)},uploadCancel(e,t){const{hash:n}=t.payload,a=e.allIds.indexOf(n);a>=0&&e.allIds.splice(a,1),e.byIds[n]&&delete e.byIds[n]},uploadError(e,t){const{hash:n}=t.payload,a=e.allIds.indexOf(n);a>=0&&e.allIds.splice(a,1),delete e.byIds[n]},uploadRequest(e,t){},uploadProgress(e,t){const{event:n,uploadHash:a}=t.payload;e.byIds[a].percent=n.percent,e.byIds[a].status="uploading"},uploadStart(e,t){const{uploadItem:n}=t.payload;e.allIds.includes(n.hash)||e.allIds.push(n.hash),e.byIds[n.hash]=n}}}),Va=te.createSelector([e=>e.uploads.byIds,(e,t)=>t],((e,t)=>e[t]));te.createSelector([e=>e.uploads.byIds,e=>e.uploads.allIds],((e,t)=>t.map((t=>e[t]))));const Qa=Na.actions;var Xa=Na.reducer;const Ha=Se.default($.Flex)(R||(R=H(["\n box-sizing: border-box;\n height: 100%;\n overflow: hidden;\n padding: 2px;\n position: relative;\n width: 100%;\n"]))),Ya=e=>{const{id:t}=e,n=ee.useDispatch(),a=_t((e=>Va(e,t)));if(!a)return null;const i=Be.default(a.size,{base:10,round:0}),s=Math.round(a.percent||0),o="complete"===a.status,l="uploading"===a.status,r="queued"===a.status;let d;o&&(d="Verifying"),l&&(d="".concat(s,"%")),r&&(d="Queued");return W.jsx(Ha,{children:W.jsxs($.Flex,{direction:"column",flex:1,style:{background:oe.hues.gray[950].hex,border:"1px solid transparent",height:"100%",position:"relative"},children:[W.jsx("div",{style:{background:oe.hues.gray[600].hex,bottom:0,height:"1px",left:0,position:"absolute",width:"100%",transform:"scaleX(".concat(.01*s,")"),transformOrigin:"bottom left",transition:"all 1000ms ease-out"}}),W.jsxs($.Box,{flex:1,style:{position:"relative"},children:["image"===a.assetType&&(null==a?void 0:a.objectUrl)&&W.jsx(ra,{draggable:!1,src:a.objectUrl,style:{opacity:.4}}),"file"===a.assetType&&W.jsx("div",{style:{height:"100%",opacity:.1},children:W.jsx(Fn,{width:"80px"})}),!o&&100!==s&&W.jsx($.Flex,{align:"center",direction:"column",justify:"center",style:{height:"100%",left:0,position:"absolute",top:0,width:"100%"},children:W.jsx($.Tooltip,{content:W.jsx($.Box,{padding:2,children:W.jsx($.Text,{muted:!0,size:1,children:"Cancel"})}),disabled:"ontouchstart"in window,placement:"top",children:W.jsx($.Button,{fontSize:4,icon:G.CloseIcon,mode:"bleed",onClick:()=>{n(Qa.uploadCancel({hash:a.hash}))},padding:2,style:{background:"none",boxShadow:"none"},tone:"critical"})})})]}),W.jsxs($.Flex,{align:"center",justify:"space-between",paddingX:2,style:{height:"".concat(32,"px")},children:[W.jsx($.Box,{flex:1,marginRight:1,children:W.jsxs($.Text,{size:0,textOverflow:"ellipsis",children:[a.name," (",i,")"]})}),W.jsx($.Text,{size:0,style:{flexShrink:0},weight:"semibold",children:d})]})]})})},Ga=K.memo((e=>{let{item:t,selected:n}=e;return"asset"===(null==t?void 0:t.type)?W.jsx(Fa,{id:t.id,selected:n}):"upload"===(null==t?void 0:t.type)?W.jsx(Ya,{id:t.id}):null})),Wa=Se.default.div(B||(B=H(["\n height: ","px;\n width: ","px;\n"])),220,240),$a=Se.default.div(z||(z=H(["\n display: grid;\n grid-template-columns: repeat(auto-fill, ","px);\n justify-content: center;\n margin: 0 auto;\n"])),240),Ka=e=>{const{items:t,onLoadMore:n}=e,a=_t((e=>e.selected.assets)),i=a&&a.map((e=>e._id))||[],s=null==t?void 0:t.length;return 0===s?null:W.jsx(ue.VirtuosoGrid,{className:"media__custom-scrollbar",computeItemKey:e=>{const n=t[e];return null==n?void 0:n.id},components:{Item:Wa,List:$a},endReached:n,itemContent:e=>{const n=t[e],a=i.includes(null==n?void 0:n.id);return W.jsx(Ga,{item:n,selected:a})},overscan:48,style:{overflowX:"hidden"},totalCount:s})},Za=e=>{const{field:t,title:n}=e,a=ee.useDispatch(),i=_t((e=>e.assets.order)),s=i.field===t;return W.jsx($.Label,{muted:!t,size:0,children:W.jsxs($.Box,{onClick:t?()=>{if(t&&n)if(s){const e="asc"===i.direction?"desc":"asc";a(It.orderSet({order:{field:t,direction:e}}))}else a(It.orderSet({order:{field:t,direction:"asc"}}))}:void 0,style:{cursor:t?"pointer":"default",display:"inline",whiteSpace:"nowrap"},children:[W.jsx("span",{style:{marginRight:"0.4em"},children:n}),s&&"asc"===(null==i?void 0:i.direction)&&W.jsx(G.ChevronUpIcon,{}),s&&"desc"===(null==i?void 0:i.direction)&&W.jsx(G.ChevronDownIcon,{})]})})};var Ja;const ei=Se.default($.Flex)(D||(D=H(["\n cursor: pointer;\n\n @media (hover: hover) and (pointer: fine) {\n &:hover {\n background: ",";\n }\n }\n"])),null==(Ja=oe.hues.gray)?void 0:Ja[900].hex),ti=()=>{var e;const t=ee.useDispatch(),n=_t((e=>e.assets.fetching)),a=_t(vt),i=_t(jt),s=$.useMediaIndex(),{onSelect:o}=He(),l=i===a;return W.jsxs($.Grid,{style:{alignItems:"center",background:oe.black.hex,borderBottom:"1px solid ".concat(null==(e=oe.hues.gray)?void 0:e[900].hex),gridColumnGap:s<3?0:"16px",gridTemplateColumns:Ve,height:s<3?0:"".concat(32,"px"),letterSpacing:"0.025em",position:"sticky",textTransform:"uppercase",top:0,visibility:s<3?"hidden":"visible",width:"100%",zIndex:1},children:[o?W.jsx(Za,{}):W.jsx(ei,{align:"center",justify:"center",onClick:e=>{e.stopPropagation(),t(l?It.pickClear():It.pickAll())},style:{height:"100%",position:"relative"},children:W.jsx($.Checkbox,{checked:!n&&l,readOnly:!0,style:{pointerEvents:"none",transform:"scale(0.8)"}})}),W.jsx(Za,{}),W.jsx(Za,{field:"originalFilename",title:"Filename"}),W.jsx(Za,{title:"Resolution"}),W.jsx(Za,{field:"mimeType",title:"MIME type"}),W.jsx(Za,{field:"size",title:"Size"}),W.jsx(Za,{field:"_updatedAt",title:"Last updated"}),W.jsx(Za,{})]})};var ni;const ai=Se.default($.Grid)(F||(F=H(["\n align-items: center;\n cursor: ",";\n height: 100%;\n pointer-events: ",";\n user-select: none;\n white-space: nowrap;\n\n ","\n"])),(e=>e.selected?"default":"pointer"),(e=>e.updating?"none":"auto"),(e=>{var t;return!e.updating&&le.css(A||(A=H(["\n @media (hover: hover) and (pointer: fine) {\n &:hover {\n background: ",";\n }\n }\n "])),null==(t=oe.hues.gray)?void 0:t[950].hex)})),ii=Se.default($.Flex)(q||(q=H(["\n cursor: pointer;\n\n @media (hover: hover) and (pointer: fine) {\n &:hover {\n background: ",";\n }\n }\n"])),null==(ni=oe.hues.gray)?void 0:ni[900].hex),si=Se.default(G.WarningFilledIcon)((e=>{let{theme:t}=e;return{color:t.sanity.color.spot.red}}));var oi=K.memo((e=>{var t,n;const{id:a,selected:i}=e,s=Ae("shift"),o=ee.useDispatch(),l=_t((e=>e.assets.lastPicked)),r=_t((e=>xt(e,a))),d=$.useMediaIndex(),c=null==r?void 0:r.asset,u=null==r?void 0:r.error,p=null==(n=null==(t=null==r?void 0:r.asset)?void 0:t.metadata)?void 0:n.isOpaque,h=null==r?void 0:r.picked,m=null==r?void 0:r.updating,{onSelect:g}=He();if(!c)return null;const f=m?.5:1,x=i||m?.1:1;return W.jsxs(ai,{onClick:i?void 0:e=>{e.stopPropagation(),g?g([{kind:"assetDocumentId",value:c._id}]):s.current?o(h?It.pick({assetId:c._id,picked:!h}):It.pickRange({startId:l||c._id,endId:c._id})):o(Mt.showAssetEdit({assetId:c._id}))},selected:i,style:{gridColumnGap:d<3?0:"16px",gridRowGap:0,gridTemplateColumns:d<3?Ne:Ve,gridTemplateRows:d<3?"auto":"1fr"},updating:r.updating,children:[W.jsx(ii,{onClick:e=>{e.stopPropagation(),g?o(Mt.showAssetEdit({assetId:c._id})):s.current&&!h?o(It.pickRange({startId:l||c._id,endId:c._id})):o(It.pick({assetId:c._id,picked:!h}))},style:{alignItems:"center",gridColumn:1,gridRowStart:1,gridRowEnd:"span 5",height:"100%",justifyContent:"center",opacity:f,position:"relative"},children:g?W.jsx(G.EditIcon,{style:{flexShrink:0,opacity:.5}}):W.jsx($.Checkbox,{checked:h,readOnly:!0,style:{pointerEvents:"none",transform:"scale(0.8)"}})}),W.jsx($.Box,{style:{gridColumn:2,gridRowStart:1,gridRowEnd:"span 5",height:"90px",width:"100px"},children:W.jsxs($.Flex,{align:"center",justify:"center",style:{height:"100%",position:"relative"},children:[W.jsxs($.Box,{style:{height:"100%",opacity:x,position:"relative"},children:[wn(c)&&W.jsx(Fn,{extension:c.extension,width:"40px"}),Tn(c)&&W.jsx(ra,{draggable:!1,showCheckerboard:!p,src:In(c,{height:100,width:100})})]}),m&&W.jsx($.Flex,{align:"center",justify:"center",style:{height:"100%",left:0,position:"absolute",top:0,width:"100%"},children:W.jsx($.Spinner,{})}),i&&!m&&W.jsx($.Flex,{align:"center",justify:"center",style:{height:"100%",left:0,position:"absolute",top:0,width:"100%"},children:W.jsx($.Text,{size:2,children:W.jsx(G.CheckmarkCircleIcon,{})})})]})}),W.jsx($.Box,{marginLeft:d<3?3:0,style:{gridColumn:3,gridRow:d<3?2:"auto",opacity:f},children:W.jsx($.Text,{muted:!0,size:1,style:{lineHeight:"2em"},textOverflow:"ellipsis",children:c.originalFilename})}),W.jsx($.Box,{marginLeft:d<3?3:0,style:{gridColumn:d<3?3:4,gridRow:d<3?3:"auto",opacity:f},children:W.jsx($.Text,{muted:!0,size:1,style:{lineHeight:"2em"},textOverflow:"ellipsis",children:Tn(c)&&kn(c)})}),W.jsx($.Box,{style:{display:d<3?"none":"block",gridColumn:5,gridRow:"auto",opacity:f},children:W.jsx($.Text,{muted:!0,size:1,style:{lineHeight:"2em"},textOverflow:"ellipsis",children:c.mimeType})}),W.jsx($.Box,{style:{display:d<3?"none":"block",gridColumn:6,gridRow:"auto",opacity:f},children:W.jsx($.Text,{muted:!0,size:1,style:{lineHeight:"2em"},textOverflow:"ellipsis",children:Be.default(c.size,{base:10,round:0})})}),W.jsx($.Box,{marginLeft:d<3?3:0,style:{gridColumn:d<3?3:7,gridRow:d<3?4:"auto",opacity:f},children:W.jsx($.Text,{muted:!0,size:1,style:{lineHeight:"2em"},textOverflow:"ellipsis",children:Fe.default(new Date(c._updatedAt),new Date)})}),W.jsx($.Flex,{align:"center",justify:"center",style:{gridColumn:d<3?4:8,gridRowStart:"1",gridRowEnd:d<3?"span 5":"auto",opacity:f},children:u&&W.jsx($.Box,{padding:2,children:W.jsx($.Tooltip,{content:W.jsx($.Container,{padding:2,width:0,children:W.jsx($.Text,{size:1,children:u})}),placement:"left",portal:!0,children:W.jsx($.Text,{size:1,children:W.jsx(si,{color:"critical"})})})})})]})}));const li=e=>{const{id:t}=e,n=ee.useDispatch(),a=_t((e=>Va(e,t))),i=$.useMediaIndex();if(!a)return null;const s=Be.default(a.size,{base:10,round:0}),o=Math.round(a.percent||0),l="complete"===a.status,r="uploading"===a.status,d="queued"===a.status;let c;l&&(c="Verifying"),r&&(c="".concat(o,"%")),d&&(c="Queued");return W.jsxs($.Grid,{style:{alignItems:"center",background:oe.hues.gray[950].hex,gridColumnGap:i<3?0:"16px",gridRowGap:0,gridTemplateColumns:i<3?Ne:Ve,gridTemplateRows:i<3?"auto":"1fr",height:"100%",position:"relative"},children:[W.jsx("div",{style:{background:oe.hues.gray[600].hex,bottom:0,height:"1px",left:0,position:"absolute",width:"100%",transform:"scaleX(".concat(.01*o,")"),transformOrigin:"bottom left",transition:"all 1000ms ease-out"}}),W.jsx($.Box,{style:{gridColumn:2,gridRowStart:i<3?1:"auto",gridRowEnd:i<3?"span 4":"auto",height:"90px",width:"100px"},children:W.jsxs($.Box,{style:{height:"100%",position:"relative"},children:["image"===a.assetType&&(null==a?void 0:a.objectUrl)&&W.jsx(ra,{draggable:!1,src:a.objectUrl,style:{opacity:.25}}),"file"===a.assetType&&W.jsx("div",{style:{height:"100%",opacity:.1},children:W.jsx(Fn,{width:"40px"})}),!l&&100!==o&&W.jsx($.Flex,{align:"center",justify:"center",style:{position:"absolute",height:"100%",left:0,top:0,width:"100%"},children:W.jsx($.Tooltip,{content:W.jsx($.Box,{padding:2,children:W.jsx($.Text,{muted:!0,size:1,children:"Cancel"})}),disabled:"ontouchstart"in window,placement:"top",children:W.jsx($.Button,{fontSize:3,icon:G.CloseIcon,mode:"bleed",onClick:()=>{n(Qa.uploadCancel({hash:a.hash}))},padding:2,style:{background:"none",boxShadow:"none"},tone:"critical"})})})]})}),W.jsx($.Box,{style:{gridColumn:i<3?3:"3/8",gridRow:i<3?"2/4":"auto",marginLeft:i<3?3:0},children:W.jsxs($.Stack,{space:3,children:[W.jsxs($.Text,{muted:!0,size:1,textOverflow:"ellipsis",children:[a.name," (",s,")"]}),W.jsx($.Text,{size:1,textOverflow:"ellipsis",weight:"semibold",children:c})]})})]})},ri=K.memo((e=>{let{item:t,selected:n}=e;return"asset"===(null==t?void 0:t.type)?W.jsx($.Box,{style:{height:"100px"},children:W.jsx(oi,{id:t.id,selected:n})}):"upload"===(null==t?void 0:t.type)?W.jsx($.Box,{style:{height:"100px"},children:W.jsx(li,{id:t.id})}):null})),di=e=>{const{items:t,onLoadMore:n}=e,a=_t((e=>e.selected.assets)),i=a&&a.map((e=>e._id))||[],s=null==t?void 0:t.length;return 0===s?null:W.jsx(ue.GroupedVirtuoso,{className:"media__custom-scrollbar",computeItemKey:e=>{const n=t[e];return(null==n?void 0:n.id)||e},endReached:n,groupCounts:Array(1).fill(s),groupContent:()=>W.jsx(ti,{}),itemContent:e=>{const n=t[e],a=i.includes(null==n?void 0:n.id);return W.jsx(ri,{item:n,selected:a})},style:{overflowX:"hidden"}})},ci=()=>{const e=ee.useDispatch(),t=_t((e=>e.assets.fetchCount)),n=_t((e=>e.assets.fetching)),a=_t((e=>e.tags.panelVisible)),i=_t((e=>e.assets.view)),s=_t(Ma),o=(()=>{var e,t;const n=null==(t=null==(e=$.studioTheme)?void 0:e.container)?void 0:t.map((e=>window.matchMedia("(max-width: ".concat(e,"px)")))),a=()=>n.findIndex((e=>e.matches)),[i,s]=K.useState(a());return K.useEffect((()=>{const e=()=>{s(a)};return n.forEach((t=>{try{t.addEventListener("change",e)}catch(n){try{t.addListener(e)}catch(e){}}})),()=>{try{n.forEach((t=>t.removeEventListener("change",e)))}catch(t){try{n.forEach((t=>t.removeListener(e)))}catch(e){}}}}),[]),i})(),l=t>=0,r=s.length>0,d=()=>{n||e(It.loadNextPage())};K.useEffect((()=>{o<=1&&a&&e(ot.panelVisibleSet({panelVisible:!1}))}),[o]);const c=!r&&l&&!n;return W.jsx($.Box,{flex:1,style:{width:"100%"},children:c?W.jsx($.Box,{padding:4,children:W.jsx($.Text,{size:1,weight:"semibold",children:"No results for the current query"})}):W.jsxs(W.Fragment,{children:["grid"===i&&W.jsx(Ka,{items:s,onLoadMore:d}),"table"===i&&W.jsx(di,{items:s,onLoadMore:d})]})})},ui=()=>{const e=_t((e=>e.notifications.items)),t=$.useToast();return K.useEffect((()=>{if(e.length>0){const n=e[e.length-1];t.push({closable:!0,status:n.status,title:n.title})}}),[e.length]),null},pi=()=>{var e,t;const n=ee.useDispatch(),a=_t(bt);return 0===a.length?null:W.jsx($.Flex,{align:"center",justify:"flex-start",style:{background:null==(e=oe.hues.gray)?void 0:e[900].hex,borderBottom:"1px solid ".concat(null==(t=oe.hues.gray)?void 0:t[900].hex),height:"".concat(32,"px"),position:"relative",width:"100%"},children:W.jsxs($.Flex,{align:"center",paddingX:3,children:[W.jsx($.Box,{paddingRight:2,children:W.jsxs($.Label,{size:0,style:{color:"inherit"},children:[a.length," ",_e.default("asset",a.length)," selected"]})}),W.jsx($.Button,{mode:"bleed",onClick:()=>{n(It.pickClear())},padding:2,style:{background:"none",boxShadow:"none"},tone:"default",children:W.jsx($.Label,{size:0,children:"Deselect"})}),W.jsx($.Button,{mode:"bleed",onClick:()=>{n(Mt.showConfirmDeleteAssets({assets:a}))},padding:2,style:{background:"none",boxShadow:"none"},tone:"critical",children:W.jsx($.Label,{size:0,children:"Delete"})})]})})};var hi=te.createSlice({name:"selected",initialState:{assets:[],document:void 0,documentAssetIds:[]},reducers:{}}).reducer;const mi=te.createSlice({name:"notifications",initialState:{items:[]},reducers:{add(e,t){const{asset:n,status:a,title:i}=t.payload;e.items.push({asset:n,status:a,title:i})}}}),gi=mi.actions;var fi=mi.reducer;const xi=ae.combineEpics(((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(It.deleteRequest.match),se.mergeMap((e=>{const{assets:t}=e.payload,n=t.map((e=>e._id));return ie.of(t).pipe(se.mergeMap((()=>a.observable.delete({query:ke.default(p||(p=H(["*[_id in ","]"])),JSON.stringify(n))}))),se.mergeMap((()=>ie.of(It.deleteComplete({assetIds:n})))),se.catchError((e=>ie.of(It.deleteError({assetIds:n,error:e})))))})))}),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(It.fetchRequest.match),se.withLatestFrom(t),se.switchMap((e=>{let[t,n]=e;var i,s;const o=null==(i=t.payload)?void 0:i.params,l=null==(s=t.payload)?void 0:s.query;return ie.of(t).pipe($e(n.debug.badConnection),se.mergeMap((()=>a.observable.fetch(l,o))),se.mergeMap((e=>{const{items:t}=e;return ie.of(It.fetchComplete({assets:t}))})),se.catchError((e=>ie.of(It.fetchError({message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500})))))})))}),((e,t)=>e.pipe(se.filter(It.deleteComplete.match),se.withLatestFrom(t),se.switchMap((e=>{let[t,n]=e;if(0===n.assets.allIds.length){const e=Math.floor(n.assets.allIds.length/n.assets.pageSize);return ie.of(It.loadPageIndex({pageIndex:e}))}return ie.empty()})))),((e,t)=>e.pipe(se.filter(It.loadNextPage.match),se.withLatestFrom(t),se.switchMap((e=>{let[t,n]=e;return ie.of(It.loadPageIndex({pageIndex:n.assets.pageIndex+1}))})))),((e,t)=>e.pipe(se.filter(It.loadPageIndex.match),se.withLatestFrom(t),se.switchMap((e=>{let[t,n]=e;var a,i,s,o,l,r;const d=n.assets.pageSize,c=t.payload.pageIndex*d,u=c+d,p=null==(a=null==n?void 0:n.selected.document)?void 0:a._id,g=null==(i=null==n?void 0:n.selected)?void 0:i.documentAssetIds,f=Ke({assetTypes:n.assets.assetTypes,searchFacets:n.search.facets,searchQuery:n.search.query}),x=Q(Q({},p?{documentId:p}:{}),{},{documentAssetIds:g});return ie.of(It.fetchRequest({params:x,queryFilter:f,selector:ke.default(h||(h=H(["[","...","]"])),c,u),sort:ke.default(m||(m=H(["order("," ",")"])),null==(o=null==(s=n.assets)?void 0:s.order)?void 0:o.field,null==(r=null==(l=n.assets)?void 0:l.order)?void 0:r.direction)}))})))),(e=>e.pipe(se.filter(It.listenerCreateQueue.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=null==e?void 0:e.map((e=>e.payload.asset));return ie.of(It.listenerCreateQueueComplete({assets:t}))})))),(e=>e.pipe(se.filter(It.listenerDeleteQueue.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=null==e?void 0:e.map((e=>e.payload.assetId));return ie.of(It.listenerDeleteQueueComplete({assetIds:t}))})))),(e=>e.pipe(se.filter(It.listenerUpdateQueue.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=null==e?void 0:e.map((e=>e.payload.asset));return ie.of(It.listenerUpdateQueueComplete({assets:t}))})))),(e=>e.pipe(se.filter(It.orderSet.match),se.mergeMap((()=>ie.of(It.clear(),It.loadPageIndex({pageIndex:0})))))),(e=>e.pipe(ae.ofType(ut.facetsAdd.type,ut.facetsClear.type,ut.facetsRemove.type,ut.facetsUpdate.type,ut.querySet.type),se.debounceTime(400),se.mergeMap((()=>ie.of(It.clear(),It.loadPageIndex({pageIndex:0})))))),(e=>e.pipe(ae.ofType(It.insertUploads.type,It.listenerUpdateQueueComplete.type,It.updateComplete.type),se.mergeMap((()=>ie.of(It.sort()))))),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(et.tagsAddRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{assets:i,tag:s}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),se.mergeMap((()=>{const e=bt(n),t=null==e?void 0:e.filter((e=>t=>{var n,a,i,s,o;return(null!=(o=null==(s=null==(i=null==(a=null==(n=null==t?void 0:t.asset)?void 0:n.opt)?void 0:a.media)?void 0:i.tags)?void 0:s.findIndex((t=>t._ref===(null==e?void 0:e._id))))?o:-1)<0})(s)),i=t.reduce(((e,t)=>{var n;return e.patch(null==(n=null==t?void 0:t.asset)?void 0:n._id,(e=>{let{tag:t}=e;return e=>e.setIfMissing({opt:{}}).setIfMissing({"opt.media":{}}).setIfMissing({"opt.media.tags":[]}).append("opt.media.tags",[{_key:ne.nanoid(),_ref:null==t?void 0:t._id,_type:"reference",_weak:!0}])})({tag:s}))}),a.transaction());return ie.from(i.commit())})),se.mergeMap((()=>ie.of(et.tagsAddComplete({assets:i,tag:s})))),se.catchError((e=>ie.of(et.tagsAddError({assets:i,error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500},tag:s})))))})))}),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(et.tagsRemoveRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{assets:i,tag:s}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),se.mergeMap((()=>{const e=bt(n).reduce(((e,t)=>{var n;return e.patch(null==(n=null==t?void 0:t.asset)?void 0:n._id,(e=>{let{asset:t,tag:n}=e;return e=>{var a;return e.ifRevisionId(null==(a=null==t?void 0:t.asset)?void 0:a._rev).unset(['opt.media.tags[_ref == "'.concat(n._id,'"]')])}})({asset:t,tag:s}))}),a.transaction());return ie.from(e.commit())})),se.mergeMap((()=>ie.of(et.tagsRemoveComplete({assets:i,tag:s})))),se.catchError((e=>ie.of(et.tagsRemoveError({assets:i,error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500},tag:s})))))})))}),(e=>e.pipe(ae.ofType(It.orderSet.type,It.viewSet.type,ut.facetsAdd.type,ut.facetsClear.type,ut.facetsRemove.type,ut.facetsUpdate.type,ut.querySet.type),se.mergeMap((()=>ie.of(It.pickClear()))))),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(It.updateRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{asset:i,closeDialogId:s,formData:o}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),se.mergeMap((()=>ie.from(a.patch(i._id).setIfMissing({opt:{}}).setIfMissing({"opt.media":{}}).set(o).commit()))),se.mergeMap((e=>ie.of(It.updateComplete({asset:e,closeDialogId:s})))),se.catchError((e=>ie.of(It.updateError({asset:i,error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500}})))))})))}),(e=>e.pipe(ae.ofType(It.deleteComplete.type,It.updateComplete.type,ot.deleteComplete.type,ot.updateComplete.type),se.filter((e=>{var t;return!!(null==(t=null==e?void 0:e.payload)?void 0:t.closeDialogId)})),se.mergeMap((e=>{var t;const n=null==(t=null==e?void 0:e.payload)?void 0:t.closeDialogId;return n?ie.of(Et.actions.remove({id:n})):ie.empty()})))),(e=>e.pipe(se.filter(ot.createComplete.match),se.mergeMap((e=>{const{assetId:t,tag:n}=null==e?void 0:e.payload;return t?ie.of(Et.actions.inlineTagCreate({tag:n,assetId:t})):n._id?ie.of(Et.actions.remove({id:"tagCreate"})):ie.empty()})))),(e=>e.pipe(se.filter(ot.listenerDeleteQueueComplete.match),se.mergeMap((e=>{const{tagIds:t}=null==e?void 0:e.payload;return ie.of(Et.actions.inlineTagRemove({tagIds:t}))})))),(e=>e.pipe(se.filter(It.deleteError.match),se.mergeMap((e=>{const{assetIds:t}=e.payload,n=t.length;return ie.of(mi.actions.add({status:"error",title:"Unable to delete ".concat(n," ").concat(_e.default("asset",n),". Please review any asset errors and try again.")}))})))),(e=>e.pipe(se.filter(It.deleteComplete.match),se.mergeMap((e=>{const{assetIds:t}=e.payload,n=t.length;return ie.of(mi.actions.add({status:"info",title:"".concat(n," ").concat(_e.default("asset",n)," deleted")}))})))),(e=>e.pipe(se.filter(et.tagsAddComplete.match),se.mergeMap((e=>{var t,n;const a=null==(n=null==(t=null==e?void 0:e.payload)?void 0:t.assets)?void 0:n.length;return ie.of(mi.actions.add({status:"info",title:"Tag added to ".concat(a," ").concat(_e.default("asset",a))}))})))),(e=>e.pipe(se.filter(et.tagsRemoveComplete.match),se.mergeMap((e=>{var t,n;const a=null==(n=null==(t=null==e?void 0:e.payload)?void 0:t.assets)?void 0:n.length;return ie.of(mi.actions.add({status:"info",title:"Tag removed from ".concat(a," ").concat(_e.default("asset",a))}))})))),(e=>e.pipe(se.filter(It.updateComplete.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=e.length;return ie.of(mi.actions.add({status:"info",title:"".concat(t," ").concat(_e.default("asset",t)," updated")}))})))),(e=>e.pipe(ae.ofType(It.fetchError.type,It.updateError.type,ot.createError.type,ot.deleteError.type,ot.fetchError.type,ot.updateError.type,Qa.uploadError.type),se.mergeMap((e=>{var t;const n=null==(t=e.payload)?void 0:t.error;return ie.of(mi.actions.add({status:"error",title:"An error occured: ".concat(n.message)}))})))),(e=>e.pipe(se.filter(ot.createComplete.match),se.mergeMap((()=>ie.of(mi.actions.add({status:"info",title:"Tag created"})))))),(e=>e.pipe(se.filter(ot.deleteComplete.match),se.mergeMap((()=>ie.of(mi.actions.add({status:"info",title:"Tag deleted"})))))),(e=>e.pipe(se.filter(ot.updateComplete.match),se.mergeMap((()=>ie.of(mi.actions.add({status:"info",title:"Tag updated"})))))),((e,t)=>e.pipe(se.filter(ot.updateComplete.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;var a,i,s,o,l;const{tag:r}=t.payload,d=null==(a=n.search.facets)?void 0:a.find((e=>"tag"===e.name)),c=n.tags.byIds[r._id];return"searchable"===(null==d?void 0:d.type)&&(null==(i=d.value)?void 0:i.value)===r._id?ie.of(rt.actions.facetsUpdate({name:"tag",value:{label:null==(o=null==(s=null==c?void 0:c.tag)?void 0:s.name)?void 0:o.current,value:null==(l=null==c?void 0:c.tag)?void 0:l._id}})):ie.empty()})))),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(nt.actions.createRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{assetId:i,name:s}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),Ze(a,s),se.mergeMap((()=>a.observable.create({_type:"media.tag",name:{_type:"slug",current:s}}))),se.mergeMap((e=>ie.of(nt.actions.createComplete({assetId:i,tag:e})))),se.catchError((e=>ie.of(nt.actions.createError({error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500},name:s})))))})))}),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(nt.actions.deleteRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{tag:i}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),se.mergeMap((()=>a.observable.fetch(ke.default(d||(d=H(['*[\n _type in ["sanity.fileAsset", "sanity.imageAsset"]\n && references(*[_type == "media.tag" && name.current == $tagName]._id)\n ] {\n _id,\n _rev,\n opt\n }']))),{tagName:i.name.current}))),se.mergeMap((e=>{const t=e.map((e=>({id:e._id,patch:{ifRevisionID:e._rev,unset:['opt.media.tags[_ref == "'.concat(i._id,'"]')]}}))).reduce(((e,t)=>e.patch(t.id,t.patch)),a.transaction());return t.delete(i._id),ie.from(t.commit())})),se.mergeMap((()=>ie.of(nt.actions.deleteComplete({tagId:i._id})))),se.catchError((e=>ie.of(nt.actions.deleteError({error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500},tag:i})))))})))}),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(nt.actions.fetchRequest.match),se.withLatestFrom(t),se.switchMap((e=>{let[t,n]=e;const{query:i}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),se.mergeMap((()=>a.observable.fetch(i))),se.mergeMap((e=>{const{items:t}=e;return ie.of(nt.actions.fetchComplete({tags:t}))})),se.catchError((e=>ie.of(nt.actions.fetchError({error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500}})))))})))}),(e=>e.pipe(se.filter(nt.actions.listenerCreateQueue.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=null==e?void 0:e.map((e=>e.payload.tag));return ie.of(nt.actions.listenerCreateQueueComplete({tags:t}))})))),(e=>e.pipe(se.filter(nt.actions.listenerDeleteQueue.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=null==e?void 0:e.map((e=>e.payload.tagId));return ie.of(nt.actions.listenerDeleteQueueComplete({tagIds:t}))})))),(e=>e.pipe(se.filter(nt.actions.listenerUpdateQueue.match),se.bufferTime(2e3),se.filter((e=>e.length>0)),se.mergeMap((e=>{const t=null==e?void 0:e.map((e=>e.payload.tag));return ie.of(nt.actions.listenerUpdateQueueComplete({tags:t}))})))),(e=>e.pipe(ae.ofType(nt.actions.listenerCreateQueueComplete.type,nt.actions.listenerUpdateQueueComplete.type),se.bufferTime(1e3),se.filter((e=>e.length>0)),se.mergeMap((()=>ie.of(nt.actions.sort()))))),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(nt.actions.updateRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;var i;const{closeDialogId:s,formData:o,tag:l}=t.payload;return ie.of(t).pipe($e(n.debug.badConnection),Ze(a,null==(i=null==o?void 0:o.name)?void 0:i.current),se.mergeMap((()=>ie.from(a.patch(l._id).set({name:{_type:"slug",current:null==o?void 0:o.name.current}}).commit()))),se.mergeMap((e=>ie.of(nt.actions.updateComplete({closeDialogId:s,tag:e})))),se.catchError((e=>ie.of(nt.actions.updateError({error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500},tag:l})))))})))}),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(Qa.uploadStart.match),se.mergeMap((t=>{const{file:n,uploadItem:i}=t.payload;return ie.merge(ie.of(null).pipe(se.mergeMap((()=>(e=>ie.of(null).pipe(se.mergeMap((()=>ie.from(Aa(e))))))(n))),se.mergeMap((e=>ie.of(Qa.previewReady({blobUrl:e,hash:i.hash}))))),ie.of(null).pipe(se.mergeMap((()=>Ua(a,i.assetType,n,i.hash))),se.takeUntil(e.pipe(se.filter(Qa.uploadCancel.match),se.filter((e=>e.payload.hash===i.hash)))),se.mergeMap((e=>"complete"===(null==e?void 0:e.type)?ie.of(ht.uploadComplete({asset:e.asset})):"progress"===(null==e?void 0:e.type)&&"upload"===(null==e?void 0:e.stage)?ie.of(Qa.uploadProgress({event:e,uploadHash:i.hash})):ie.empty())),se.catchError((e=>ie.of(Qa.uploadError({error:{message:(null==e?void 0:e.message)||"Internal error",statusCode:(null==e?void 0:e.statusCode)||500},hash:i.hash}))))))})))}),((e,t)=>e.pipe(se.filter(Qa.uploadRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{file:a,forceAsAssetType:i}=t.payload;return ie.of(t).pipe(se.mergeMap((()=>Pa(a))),se.filter((e=>!!!n.uploads.byIds[e])),se.mergeMap((e=>{const t={_type:"upload",assetType:i||(a.type.indexOf("image")>=0?"image":"file"),hash:e,name:a.name,size:a.size,status:"queued"};return ie.of(Qa.uploadStart({file:a,uploadItem:t}))})))})))),((e,t,n)=>{let{client:a}=n;return e.pipe(se.filter(Qa.checkRequest.match),se.withLatestFrom(t),se.mergeMap((e=>{let[t,n]=e;const{assets:i}=t.payload,s=i.map((e=>e._id)),o=Ke({assetTypes:n.assets.assetTypes,searchFacets:n.search.facets,searchQuery:n.search.query}),l=ke.default(M||(M=H(["\n *["," && _id in $documentIds].sha1hash\n "])),o);return ie.of(t).pipe(se.delay(1e3),se.mergeMap((()=>a.observable.fetch(l,{documentIds:s}))),se.mergeMap((e=>{const t=i.reduce(((t,n)=>(t[n.sha1hash]=e.includes(n.sha1hash)?n._id:null,t)),{});return ie.of(Qa.checkComplete({results:t}),It.insertUploads({results:t}))})))})))}),(e=>e.pipe(se.filter(ht.uploadComplete.match),se.mergeMap((e=>ie.of(Qa.checkRequest({assets:[e.payload.asset]}))))))),yi=te.combineReducers({assets:Tt,debug:bn,dialog:Rt,notifications:fi,search:pt,selected:hi,tags:lt,uploads:Xa}),vi=e=>null!==e&&"object"==typeof e&&!Array.isArray(e),bi=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];var n,a;return Array.isArray(e)&&e.forEach((e=>{bi(e,t)})),vi(e)&&("reference"===(null==(n=null==e?void 0:e.asset)?void 0:n._type)&&(null==(a=null==e?void 0:e.asset)?void 0:a._ref)&&t.push(e.asset._ref),Object.values(e).forEach((e=>{bi(e,t)}))),t},ji=e=>{const t=bi(e);return[...new Set(t.sort())]};class Ii extends K.Component{constructor(e){super(e);const t=ae.createEpicMiddleware({dependencies:{client:e.client}});this.store=te.configureStore({reducer:yi,middleware:e=>e({serializableCheck:!1,thunk:!1}).prepend(t),devTools:!0,preloadedState:{assets:Q(Q({},gt),{},{assetTypes:(null==e?void 0:e.assetType)?[e.assetType]:["file","image"]}),selected:{assets:e.selectedAssets||[],document:e.document,documentAssetIds:e.document?ji(e.document):[]}}}),t.run(xi)}render(){return W.jsx(ee.Provider,{store:this.store,children:this.props.children})}}const Ci=()=>{var e;return _t((e=>e.tags.panelVisible))?W.jsx($.Box,{style:{position:"relative",width:250},children:W.jsx($.Box,{className:"media__custom-scrollbar",style:{borderLeft:"1px solid ".concat(null==(e=oe.hues.gray)?void 0:e[900].hex),height:"100%",overflowX:"hidden",overflowY:"auto",position:"absolute",right:0,top:0,width:"100%"},children:W.jsx(wa,{})})}):null},wi=Se.default.div(O||(O=H(["\n color: white;\n height: 100%;\n min-height: 100%;\n right: 0;\n top: 0;\n width: 100%;\n\n &:focus {\n outline: none;\n }\n"]))),Ti=Se.default.div(L||(L=H(["\n align-items: center;\n background: rgba(0, 0, 0, 0.75);\n display: flex;\n height: 100%;\n justify-content: center;\n position: absolute;\n right: 0;\n top: 0;\n width: 100%;\n z-index: 3;\n"])));const ki=e=>{const{children:t}=e,{onSelect:n}=He(),a=ee.useDispatch(),i=_t((e=>e.assets.assetTypes)),s=1===i.length&&"image"===i[0],{getRootProps:o,getInputProps:l,isDragActive:r,open:d}=Ie.useDropzone({accept:s?"image/*":"",getFilesFromEvent:async e=>{var t;let n;if("drop"===e.type&&"dataTransfer"in e&&(n=null==(t=null==e?void 0:e.dataTransfer)?void 0:t.files),"change"===e.type){const t=null==e?void 0:e.target;(null==t?void 0:t.files)&&(n=t.files)}if(!n)return[];const i=await async function(e){const t=Array.from(e),n=[];for(const e of t)try{await e.slice(0,1).arrayBuffer(),n.push(e)}catch(e){}return n}(n);return(null==n?void 0:n.length)!==i.length&&a(gi.add({status:"error",title:"Unable to upload some items (folders and packages aren't supported)"})),i},noClick:!0,noDrag:!!n,onDrop:async e=>{e.forEach((e=>a(Qa.uploadRequest({file:e,forceAsAssetType:1===i.length?i[0]:void 0}))))}});return W.jsx(_a,{open:d,children:W.jsxs(wi,Q(Q({},o()),{},{children:[W.jsx("input",Q({},l())),r&&W.jsx(Ti,{children:W.jsx($.Flex,{direction:"column",justify:"center",style:{color:oe.white.hex},children:W.jsx($.Text,{size:3,style:{color:"inherit"},children:"Drop files to upload"})})}),t]}))})},Si=e=>{let{onClose:t}=e;const n=Ye(),a=ee.useDispatch(),i=e=>{const{documentId:t,result:n,transition:i}=e;"appear"===i&&a(It.listenerCreateQueue({asset:n})),"disappear"===i&&a(It.listenerDeleteQueue({assetId:t})),"update"===i&&a(It.listenerUpdateQueue({asset:n}))},s=e=>{const{documentId:t,result:n,transition:i}=e;"appear"===i&&a(ot.listenerCreateQueue({tag:n})),"disappear"===i&&a(ot.listenerDeleteQueue({tagId:t})),"update"===i&&a(ot.listenerUpdateQueue({tag:n}))};return K.useEffect((()=>{a(It.loadPageIndex({pageIndex:0})),a(ot.fetchRequest());const e=n.listen(ke.default(P||(P=H(['*[_type in ["sanity.fileAsset", "sanity.imageAsset"] && !(_id in path("drafts.**"))]'])))).subscribe(i),t=n.listen(ke.default(U||(U=H(['*[_type == "','" && !(_id in path("drafts.**"))]'])),"media.tag")).subscribe(s);return()=>{null==e||e.unsubscribe(),null==t||t.unsubscribe()}}),[]),W.jsxs(ki,{children:[W.jsx(ka,{}),W.jsx(ui,{}),W.jsx($.Card,{display:"flex",height:"fill",children:W.jsxs($.Flex,{direction:"column",flex:1,children:[W.jsx(Ea,{onClose:t}),W.jsx(xn,{}),W.jsxs($.Flex,{flex:1,children:[W.jsxs($.Flex,{align:"flex-end",direction:"column",flex:1,style:{position:"relative"},children:[W.jsx(pi,{}),W.jsx(ci,{})]}),W.jsx(Ci,{})]}),W.jsx(jn,{})]})})]})},_i=e=>{const t=Ye();return W.jsx(Ii,{assetType:null==e?void 0:e.assetType,client:t,document:null==e?void 0:e.document,selectedAssets:null==e?void 0:e.selectedAssets,children:W.jsx($.ThemeProvider,{scheme:"dark",theme:$.studioTheme,children:W.jsx($.ToastProvider,{children:W.jsxs(Xe,{onSelect:null==e?void 0:e.onSelect,children:[W.jsx(St,{}),W.jsx(Si,{onClose:null==e?void 0:e.onClose})]})})})})},Ei=()=>{const[e]=K.useState((()=>document.createElement("div")));return K.useEffect((()=>(e.classList.add("media-portal"),document.body.appendChild(e),()=>{document.body.removeChild(e)})),[]),e};var Mi={title:"Media Tag",icon:gn,name:"media.tag",type:"document",fields:[{title:"Name",name:"name",type:"slug"}],preview:{select:{name:"name"},prepare(e){const{name:t}=e;return{media:gn,title:null==t?void 0:t.current}}}};const Ri={icon:G.ImageIcon,name:"media",title:"Media"},Bi=Q(Q({},Ri),{},{component:e=>{const{onClose:t}=e,n=Ei(),a=Y.useFormValue([]);Ae("escape",t);const i=e=>{e.nativeEvent.stopImmediatePropagation(),e.stopPropagation()},{zIndex:s}=$.useLayer();return W.jsx($.PortalProvider,{element:n,children:W.jsx($.Portal,{children:W.jsx($.Box,{onDragEnter:i,onDragLeave:i,onDragOver:i,onDrop:i,onMouseUp:i,style:{bottom:0,height:"auto",left:0,position:"fixed",top:0,width:"100%",zIndex:s},children:W.jsx(_i,Q({document:a},e))})})})}}),zi=Q(Q({},Ri),{},{component:()=>W.jsx($.Flex,{direction:"column",height:"fill",flex:1,children:W.jsx(_i,{})})}),Di=Y.definePlugin({name:"media",form:{file:{assetSources:e=>[...e,Bi]},image:{assetSources:e=>[...e,Bi]}},schema:{types:[Mi]},tools:e=>[...e,zi]});exports.media=Di,exports.mediaAssetSource=Bi;
2
2
  //# sourceMappingURL=index.js.map