UNPKG

sanity-plugin-bulk-actions-table

Version:

A powerful table view plugin for Sanity Studio v3/v4 with bulk actions, column selection, and document management capabilities

440 lines (413 loc) 47.3 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("@sanity/icons"),n=require("@sanity/ui"),i=require("@sanity/ui/theme"),r=require("classnames"),s=require("lodash.get"),o=require("pluralize"),a=require("react"),l=require("sanity"),c=require("sanity/structure"),d=require("nanoid"),u=require("react-error-boundary"),h=require("styled-components"),p=require("lodash.debounce");function f(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var m=/* @__PURE__ */f(r),y=/* @__PURE__ */f(s),x=/* @__PURE__ */f(o),g=/* @__PURE__ */f(h),b=/* @__PURE__ */f(p);const v=[50,100],j={key:"",direction:"asc",type:null},w={_updatedAt:{key:"_updatedAt",title:"Updated",sortable:!0},_createdAt:{key:"_createdAt",title:"Created",sortable:!0},_lastPublishedAt:{key:"_lastPublishedAt",title:"Last published",sortable:!1}},S=Object.values(w);function _(e){return"function"==typeof e}function k(e){return function(t){if(function(e){return _(e?.lift)}(t))return t.lift(function(t){try{return e(t,this)}catch(e){this.error(e)}});throw new TypeError("Unable to lift unknown Observable type")}}var C=function(e,t){return(C=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function I(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}C(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function z(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],i=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function P(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var i,r,s=n.call(e),o=[];try{for(;(void 0===t||t-- >0)&&!(i=s.next()).done;)o.push(i.value)}catch(e){r={error:e}}finally{try{i&&!i.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return o}function A(e,t,n){if(n||2===arguments.length)for(var i,r=0,s=t.length;r<s;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))}var $,T=(($=function(e){Error.call(this),this.stack=(new Error).stack,this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map(function(e,t){return t+1+") "+e.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}).prototype=Object.create(Error.prototype),$.prototype.constructor=$,$);function B(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var E=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var e,t,n,i,r;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var o=z(s),a=o.next();!a.done;a=o.next())a.value.remove(this)}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}else s.remove(this);var l=this.initialTeardown;if(_(l))try{l()}catch(e){r=e instanceof T?e.errors:[e]}var c=this._finalizers;if(c){this._finalizers=null;try{for(var d=z(c),u=d.next();!u.done;u=d.next()){var h=u.value;try{D(h)}catch(e){r=r??[],e instanceof T?r=A(A([],P(r)),P(e.errors)):r.push(e)}}}catch(e){n={error:e}}finally{try{u&&!u.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}}if(r)throw new T(r)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)D(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&B(t,e)},e.prototype.remove=function(t){var n=this._finalizers;n&&B(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e;var t}();function D(e){_(e)?e():e.unsubscribe()}function O(){}var F=function(e){function t(t){var n,i=e.call(this)||this;return i.isStopped=!1,t?(i.destination=t,((n=t)instanceof E||n&&"closed"in n&&_(n.remove)&&_(n.add)&&_(n.unsubscribe))&&t.add(i)):i.destination=U,i}return I(t,e),t.create=function(e,t,n){return new N(e,t,n)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(E),M=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(e){q(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){q(e)}else q(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){q(e)}},e}(),N=function(e){function t(t,n,i){var r,s=e.call(this)||this;return r=_(t)||!t?{next:t??void 0,error:n??void 0,complete:i??void 0}:t,s.destination=new M(r),s}return I(t,e),t}(F);function q(e){var t;t=e,function(e,t){for(var n=[],i=2;i<arguments.length;i++)n[i-2]=arguments[i];setTimeout.apply(void 0,A([e,t],P(n)))}(function(){throw t})}var U={closed:!0,next:O,error:function(e){throw e},complete:O};function R(e){return e}function V(e,t,n,i,r){return new L(e,t,n,i,r)}var L=function(e){function t(t,n,i,r,s,o){var a=e.call(this,t)||this;return a.onFinalize=s,a.shouldUnsubscribe=o,a._next=n?function(e){try{n(e)}catch(e){t.error(e)}}:e.prototype._next,a._error=r?function(e){try{r(e)}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._error,a._complete=i?function(){try{i()}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._complete,a}return I(t,e),t.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;e.prototype.unsubscribe.call(this),!n&&(null===(t=this.onFinalize)||void 0===t||t.call(this))}},t}(F),W=function(e){function t(t,n){var i=e.call(this,t,n)||this;return i.scheduler=t,i.work=n,i.pending=!1,i}return I(t,e),t.prototype.schedule=function(e,t){var n;if(void 0===t&&(t=0),this.closed)return this;this.state=e;var i=this.id,r=this.scheduler;return null!=i&&(this.id=this.recycleAsyncId(r,i,t)),this.pending=!0,this.delay=t,this.id=null!==(n=this.id)&&void 0!==n?n:this.requestAsyncId(r,this.id,t),this},t.prototype.requestAsyncId=function(e,t,n){return void 0===n&&(n=0),function(e,t){for(var n=[],i=2;i<arguments.length;i++)n[i-2]=arguments[i];return setInterval.apply(void 0,A([e,t],P(n)))}(e.flush.bind(e,this),n)},t.prototype.recycleAsyncId=function(e,t,n){if(void 0===n&&(n=0),null!=n&&this.delay===n&&!1===this.pending)return t;null!=t&&clearInterval(t)},t.prototype.execute=function(e,t){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var n=this._execute(e,t);if(n)return n;!1===this.pending&&null!=this.id&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,t){var n,i=!1;try{this.work(e)}catch(e){i=!0,n=e||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),n},t.prototype.unsubscribe=function(){if(!this.closed){var t=this.id,n=this.scheduler,i=n.actions;this.work=this.state=this.scheduler=null,this.pending=!1,B(i,this),null!=t&&(this.id=this.recycleAsyncId(n,t,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},t}(function(e){function t(t,n){return e.call(this)||this}return I(t,e),t.prototype.schedule=function(e,t){return this},t}(E)),Y=function(){return Date.now()},J=function(){function e(t,n){void 0===n&&(n=e.now),this.schedulerActionCtor=t,this.now=n}return e.prototype.schedule=function(e,t,n){return void 0===t&&(t=0),new this.schedulerActionCtor(this,e).schedule(n,t)},e.now=Y,e}(),Q=new(function(e){function t(t,n){void 0===n&&(n=J.now);var i=e.call(this,t,n)||this;return i.actions=[],i._active=!1,i}return I(t,e),t.prototype.flush=function(e){var t=this.actions;if(this._active)t.push(e);else{var n;this._active=!0;do{if(n=e.execute(e.state,e.delay))break}while(e=t.shift());if(this._active=!1,n){for(;e=t.shift();)e.unsubscribe();throw n}}},t}(J))(W);function Z(e,t,n,i){const r=new Error(e);return r.context=t,r.operation=n,r.documentIds=i,r}function X(e,t){const n={timestamp:/* @__PURE__ */(new Date).toISOString(),context:t,message:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0,...e instanceof Error&&"context"in e&&{pluginContext:e.context},...e instanceof Error&&"operation"in e&&{operation:e.operation},...e instanceof Error&&"documentIds"in e&&{documentIds:e.documentIds}};"development"===process.env.NODE_ENV&&console.error("[Sanity Bulk Actions Table Plugin] Error:",n)}function G(e,t,n){const i=Z(`Bulk ${t} operation failed`,"BulkActionsMenu",t,n);return X(e,`Bulk ${t} operation`),i}function H(e,t){const n=Z(`Data fetch failed: ${e instanceof Error?e.message:String(e)}`,t,"fetch");return X(e,t),n}const K=e=>e.startsWith("drafts.")?e.substring(7):e;function ee(e){return e&&"string"==typeof e?e.replace(/['"]/g,"").replace(/\\/g,"").replace(/`/g,"").replace(/;/g,"").replace(/[{}]/g,"").replace(/[\[\]]/g,"").replace(/\|/g,"").replace(/\$/g,"").trim().slice(0,100):""}const te=a.createContext({options:{},schemaType:{},searchValue:"",setSearchValue:e=>{},pageSize:v[0],setPageSize:e=>{},selectedColumns:/* @__PURE__ */new Set,setSelectedColumns:e=>{},orderColumn:j,setOrderColumn:e=>{},selectedIds:/* @__PURE__ */new Set,setSelectedIds:()=>{},isSelectState:!1,setIsSelectState:e=>{},paginatedClient:{}}),ne=()=>a.useContext(te),ie=({options:t,children:n})=>{const{type:i,schema:r,client:s}=t,o=a.useMemo(()=>r.get(i),[i,r]),[l,c]=a.useState(""),[u,h]=a.useState(v[0]),[p,f]=function(e,t){const[n,i]=a.useState(()=>{const n=window.localStorage.getItem(t);return null!==n?new Set(JSON.parse(n)):e});return a.useEffect(()=>{n&&window.localStorage.setItem(t,JSON.stringify(Array.from(n)))},[t,n]),[n,i]}( /* @__PURE__ */new Set,`bulk-actions-table-${i}-selected-columns`),[m,y]=function(e,t){const[n,i]=a.useState(()=>{const n=window.localStorage.getItem(t);return null!==n?JSON.parse(n):e});return a.useEffect(()=>{n&&window.localStorage.setItem(t,JSON.stringify(n))},[t,n]),[n,i]}(j,`bulk-actions-table-${i}-order-column`),[x,g]=a.useState(/* @__PURE__ */new Set),[b,S]=a.useState(!1),C=a.useMemo(()=>("fields"in o?o.fields:[]).reduce((e,t)=>{const n=t.name;return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)&&("string"===t?.type?.jsonType&&e.push(e=>{const t=ee(e);return t?`${n} match "${t}*"`:"true"}),"slug"===t?.type?.name&&e.push(e=>{const t=ee(e);return t?`${n}.current match "${t}*"`:"true"}),"number"===t?.type?.name&&e.push(e=>{const t=ee(e);return t?`string(${n}) match "${t}*"`:"true"})),e},[]),[o]),I=function({type:e,pageSize:t,selectedColumns:n,searchableFields:i,orderColumn:r,client:s}){const[o,l]=a.useState(/* @__PURE__ */new Set),c=o.size>0,[u,h]=a.useState(0),p=Math.ceil(u/t),[f,m]=a.useState([]),[y,x]=a.useState(0),[g,b]=a.useState([]),[v,j]=a.useState(d.nanoid()),S=a.useCallback(()=>j(d.nanoid()),[]),[C,I]=a.useState(""),z=C.length&&i.length?` && (${i.map(e=>e(C)).join(" || ")})`:"",P=r?`| order(${r.key}${"slug"===r.type?".current":""} ${r.direction})`:"";return a.useEffect(()=>{let t=!1;return async function(){l(e=>{const t=new Set(e);return t.add("total_count"),t});const n=await s.fetch(`*[_type == $type && _id in path("drafts.**") ${z}]._id`,{type:e}),{draftsWithPublishedVersion:i,notDraftCount:r}=await s.fetch(`{\n "draftsWithPublishedVersion": *[_type == $type && _id in $ids ${z}]._id,\n "notDraftCount": count(*[_type == $type && !(_id in path("drafts.**")) ${z}]),\n }`,{ids:n.map(K),type:e}),o=n.length-i.length+r;t||(l(e=>{const t=new Set(e);return t.delete("total_count"),t}),h(o))}().catch(e=>{H(e,"getting total count")}),()=>{t=!0}},[e,v,z]),a.useEffect(()=>{(async n=>{l(e=>{const t=new Set(e);return t.add("page_ids"),t});const i=(await s.fetch(`*[_type == $type && _id in path("drafts.**") ${z}]._id`,{type:e})).reduce((e,t)=>(e.add(K(t)),e),/* @__PURE__ */new Set),r=await(async()=>{const r=3*t;let o=n*t*2,a=[],l=0;for(;a.length<t&&l<3;){const t=await s.fetch(`*[_type == $type ${z}]${P}[$start...$end]._id`,{type:e,start:o,end:o+r});if(0===t.length)break;const n=t.filter(e=>!!e.startsWith("drafts.")||!i.has(e)).map(K);a.push(...n),o+=r,l++}return a.slice(0,t)})();return l(e=>{const t=new Set(e);return t.delete("page_ids"),t}),r})(y).then(m).catch(e=>{H(e,"fetching page IDs")})},[y,t,e,v,z,P]),a.useEffect(()=>{const t=f.map(e=>[e,`drafts.${e}`]).flat(),i=Array.from(n).map(e=>e.includes(".")?`"${e}": ${e}`:e);!i.includes(w._updatedAt.key)&&i.includes(w._lastPublishedAt.key)&&i.push(w._updatedAt.key);const o=i.join(", "),a=`*[_id in $ids ${z}]${P}{ _id, _type, ${o} }`;async function c(){l(e=>{const t=new Set(e);return t.add("results"),t});const e=f.reduce((e,t,n)=>(e[t]=n,e),{}),n=await s.fetch(a,{ids:t}),i=Object.values(n.reduce((e,t)=>{const n=K(t._id),i=e[n],s=i?._id.startsWith("drafts."),o=t?._id.startsWith("drafts."),a=i?"published_with_pending_changes":o?"draft":"published";return e[n]=s?i:t,e[n]._status=a,e[n]._normalizedId=n,"_updatedAt"===r.key&&"desc"===r.direction?e[n]._lastPublishedAt=o?null:t._updatedAt:e[n]._lastPublishedAt=i?i._updatedAt:o?null:t._updatedAt,e},{}));l(e=>{const t=new Set(e);return t.delete("results"),t}),b(i.slice().sort((t,n)=>e[K(t._id)]-e[K(n._id)]))}c().catch(e=>{H(e,"fetching results")});const d=s.listen("*[_type == $type]",{type:e}).pipe((h=e=>{const t=e.documentId.replace("drafts.","");f.includes(t)||m([...f,t]),l(e=>{const t=new Set(e);return t.add("results"),t})},p=_(h)?{next:h,error:void 0,complete:void 0}:h,p?k(function(e,t){var n;null===(n=p.subscribe)||void 0===n||n.call(p);var i=!0;e.subscribe(V(t,function(e){var n;null===(n=p.next)||void 0===n||n.call(p,e),t.next(e)},function(){var e;i=!1,null===(e=p.complete)||void 0===e||e.call(p),t.complete()},function(e){var n;i=!1,null===(n=p.error)||void 0===n||n.call(p,e),t.error(e)},function(){var e,t;i&&(null===(e=p.unsubscribe)||void 0===e||e.call(p)),null===(t=p.finalize)||void 0===t||t.call(p)}))}):R),(void 0===u&&(u=Q),k(function(e,t){var n=null,i=null,r=null,s=function(){if(n){n.unsubscribe(),n=null;var e=i;i=null,t.next(e)}};function o(){var e=r+1e3,i=u.now();if(i<e)return n=this.schedule(void 0,e-i),void t.add(n);s()}e.subscribe(V(t,function(e){i=e,r=u.now(),n||(n=u.schedule(o,1e3),t.add(n))},function(){s(),t.complete()},void 0,function(){i=n=null}))}))).subscribe(c);var u,h,p;return()=>{d.unsubscribe()}},[f,n,v,z,P]),a.useEffect(()=>{y>=p&&x(0)},[y,p]),{results:g,page:y,totalPages:p,setPage:x,loading:c,pageIds:f,total:u,refresh:S,setUserQuery:I}}({type:i,pageSize:u,selectedColumns:p,searchableFields:C,orderColumn:m,client:s}),z={options:t,schemaType:o,searchValue:l,setSearchValue:c,pageSize:u,setPageSize:h,selectedColumns:p,setSelectedColumns:f,orderColumn:m,setOrderColumn:y,selectedIds:x,setSelectedIds:g,isSelectState:b,setIsSelectState:S,paginatedClient:I};/* @__PURE__ */ return e.jsx(te.Provider,{value:z,children:n})},re=g.default.div` padding: 0 1rem; font-size: 0.85rem; `,se=g.default.div` display: flex; align-items: center; gap: 0.5rem; justify-content: flex-end; padding: 0.75rem; `,oe=({e:t,schemaType:n})=>{const i="details"in t?t.details.items.map(e=>e.error.id):[];if(!i.length)return null;const r=1!==i.length;/* @__PURE__ */ return e.jsxs(u.ErrorBoundary,{fallback:null,children:[ /* @__PURE__ */e.jsxs("p",{children:["Please unselect ",r?"these":"this"," document",r?"s":""," ","and try again:"]}), /* @__PURE__ */e.jsx("p",{children:i.map(t=>/* @__PURE__ */e.jsx(l.Preview,{schemaType:n,layout:"default",value:{_id:t,_type:n.type}},t))})]})},ae=e=>e.startsWith("drafts.")?e.substring(7):e;function le({onDelete:i}){const{options:{client:r},selectedIds:s,setSelectedIds:o,schemaType:l}=ne(),c=a.useMemo(d.nanoid,[]),u=n.useToast(),h=a.useMemo(d.nanoid,[]),[p,f]=a.useState(null),[m,y]=a.useState(!1);/* @__PURE__ */ return e.jsxs(e.Fragment,{children:[ /* @__PURE__ */e.jsx(n.MenuButton,{id:c,button:/* @__PURE__ */e.jsx(n.Button,{space:2,fontSize:1,padding:2,text:"Update items",tone:"primary",iconRight:t.ChevronDownIcon}),popover:{portal:!0,placement:"bottom"},menu:/* @__PURE__ */e.jsxs(n.Menu,{style:{textAlign:"left"},children:[ /* @__PURE__ */e.jsx(n.MenuItem,{className:"prevent-nav",text:"Publish",icon:t.PublishIcon,tone:"positive",onClick:()=>f("publish")}), /* @__PURE__ */e.jsx(n.MenuItem,{className:"prevent-nav",text:"Discard staged changes",icon:t.ResetIcon,onClick:()=>f("discard_changes")}), /* @__PURE__ */e.jsx(n.MenuItem,{text:"Unpublish",icon:t.UnpublishIcon,tone:"caution",className:"prevent-nav",onClick:()=>f("unpublish")}), /* @__PURE__ */e.jsx(n.MenuDivider,{}), /* @__PURE__ */e.jsx(n.MenuItem,{tone:"critical",icon:t.TrashIcon,text:"Delete",className:"prevent-nav",onClick:()=>f("delete")})]})}),"discard_changes"===p&&/* @__PURE__ */e.jsx(n.Dialog,{id:h,header:"Discard Changes",zOffset:1e5,footer:/* @__PURE__ */e.jsxs(se,{children:[ /* @__PURE__ */e.jsx(n.Button,{text:"Cancel",mode:"ghost",disabled:m,onClick:()=>f(null)}), /* @__PURE__ */e.jsx(n.Button,{text:"Discard Changes",tone:"critical",mode:"ghost",disabled:m,onClick:async()=>{y(!0);try{const e=await r.fetch("*[_id in $ids]._id",{ids:Array.from(s).map(e=>[e,`drafts.${e}`]).flat()}),t=e.reduce((e,t)=>(e.add(t),e),/* @__PURE__ */new Set),n=e.filter(e=>e.startsWith("drafts.")&&t.has(e.substring(7))),i=r.transaction();for(const e of n)i.delete(e);await i.commit(),u.push({title:"Changes Discarded",description:`${s.size} documents reverted`,status:"success",closable:!0,duration:1e4}),o(/* @__PURE__ */new Set),f(null)}catch(t){G(t,"discard changes",Array.from(s)),u.push({title:"Error Bulk Discarding Changes",description:/* @__PURE__ */e.jsxs(e.Fragment,{children:[ /* @__PURE__ */e.jsx("p",{children:"The bulk discard changes failed."}), /* @__PURE__ */e.jsx(oe,{e:t,schemaType:l})]}),status:"error",closable:!0,duration:3e4})}finally{y(!1)}}})]}),onClose:()=>f(null),children:/* @__PURE__ */e.jsxs(re,{children:[ /* @__PURE__ */e.jsxs("p",{children:["Are you sure you want to discard changes to"," ", /* @__PURE__ */e.jsx("strong",{children:s.size})," document",1===s.size?"":"s","?"]}), /* @__PURE__ */e.jsx("p",{children:"Discarding changes reverts changes made to any drafts of the selected documents and restores the currently published versions."}), /* @__PURE__ */e.jsxs("p",{children:["You can use the"," ", /* @__PURE__ */e.jsx("a",{href:"https://www.sanity.io/docs/history-experience",target:"_blank",rel:"noreferrer noopener",children:"document history"})," ","of each individual document to track these changes."]})]})}),"unpublish"===p&&/* @__PURE__ */e.jsx(n.Dialog,{id:h,header:"Unpublish Documents",zOffset:1e5,footer:/* @__PURE__ */e.jsxs(se,{children:[ /* @__PURE__ */e.jsx(n.Button,{text:"Cancel",mode:"ghost",disabled:m,onClick:()=>f(null)}), /* @__PURE__ */e.jsx(n.Button,{text:"Unpublish Documents",tone:"caution",disabled:m,onClick:async()=>{y(!0);try{const e=await r.fetch("*[_id in $ids]",{ids:Array.from(s)}),t=r.transaction();for(const n of e)t.createIfNotExists({...n,_id:`drafts.${n._id}`,_updatedAt:/* @__PURE__ */(new Date).toISOString()}),t.delete(n._id);await t.commit(),u.push({title:"Unpublish Successful",description:`${s.size} documents unpublished`,status:"success",closable:!0,duration:1e4}),o(/* @__PURE__ */new Set)}catch(t){G(t,"unpublish",Array.from(s)),u.push({title:"Error Bulk Unpublishing",description:/* @__PURE__ */e.jsxs(e.Fragment,{children:[ /* @__PURE__ */e.jsx("p",{children:"The bulk unpublished failed. This usually occurs because there are other documents referencing the documents you’re trying to unpublish."}), /* @__PURE__ */e.jsx(oe,{e:t,schemaType:l})]}),status:"error",closable:!0,duration:3e4})}finally{f(null),y(!1)}}})]}),onClose:()=>f(null),children:/* @__PURE__ */e.jsxs(re,{children:[ /* @__PURE__ */e.jsxs("p",{children:["Are you sure you want to unpublish"," ", /* @__PURE__ */e.jsx("strong",{children:s.size})," document",1===s.size?"":"s","?"]}), /* @__PURE__ */e.jsx("p",{children:"If you unpublish a document, it will no longer be available to the public. Its contents will be moved into a draft if a draft does not already exist. From there you can continue to author the document and re-publish it later."}), /* @__PURE__ */e.jsxs("p",{children:["You can use the"," ", /* @__PURE__ */e.jsx("a",{href:"https://www.sanity.io/docs/history-experience",target:"_blank",rel:"noreferrer noopener",children:"document history"})," ","of each individual document to track these changes."]})]})}),"publish"===p&&/* @__PURE__ */e.jsx(n.Dialog,{id:h,header:"Publish Documents",zOffset:1e5,footer:/* @__PURE__ */e.jsxs(se,{children:[ /* @__PURE__ */e.jsx(n.Button,{text:"Cancel",mode:"ghost",disabled:m,onClick:()=>f(null)}), /* @__PURE__ */e.jsx(n.Button,{text:"Publish Documents",tone:"positive",disabled:m,onClick:async()=>{y(!0);try{const e=await r.fetch("*[_id in $ids]",{ids:Array.from(s).map(e=>`drafts.${e}`)}),t=r.transaction();for(const n of e)t.createOrReplace({...n,_id:ae(n._id),_updatedAt:/* @__PURE__ */(new Date).toISOString()}),t.delete(n._id);await t.commit(),u.push({title:"Publish Successful",description:`${s.size} documents published`,status:"success",closable:!0,duration:1e4}),o(/* @__PURE__ */new Set)}catch(t){G(t,"publish",Array.from(s)),u.push({title:"Error Bulk Publishing",description:/* @__PURE__ */e.jsxs(e.Fragment,{children:[ /* @__PURE__ */e.jsx("p",{children:"The bulk publish failed."}), /* @__PURE__ */e.jsx(oe,{e:t,schemaType:l})]}),status:"error",closable:!0,duration:3e4})}finally{f(null),y(!1)}}})]}),onClose:()=>f(null),children:/* @__PURE__ */e.jsxs(re,{children:[ /* @__PURE__ */e.jsxs("p",{children:["Are you sure you want to publish"," ", /* @__PURE__ */e.jsx("strong",{children:s.size})," document",1===s.size?"":"s","?"]}), /* @__PURE__ */e.jsx("p",{children:"Publishing a document makes the current contents of each document publicly available."}), /* @__PURE__ */e.jsxs("p",{children:["You can use the"," ", /* @__PURE__ */e.jsx("a",{href:"https://www.sanity.io/docs/history-experience",target:"_blank",rel:"noreferrer noopener",children:"document history"})," ","of each individual document to track these changes."]})]})}),"delete"===p&&/* @__PURE__ */e.jsx(n.Dialog,{id:h,header:"Delete Documents",zOffset:1e5,footer:/* @__PURE__ */e.jsxs(se,{children:[ /* @__PURE__ */e.jsx(n.Button,{text:"Cancel",mode:"ghost",disabled:m,onClick:()=>f(null)}), /* @__PURE__ */e.jsx(n.Button,{text:"Delete Documents",tone:"critical",disabled:m,onClick:async()=>{y(!0);try{const e=await r.fetch("*[_id in $ids]._id",{ids:Array.from(s).map(e=>[e,`drafts.${e}`]).flat()}),t=r.transaction();for(const n of e)t.delete(n);await t.commit(),u.push({title:"Delete Successful",description:`${s.size} documents deleted`,status:"success",closable:!0,duration:1e4}),i()}catch(t){G(t,"delete",Array.from(s)),u.push({title:"Error Bulk Deleting",description:/* @__PURE__ */e.jsxs(e.Fragment,{children:[ /* @__PURE__ */e.jsx("p",{children:"The bulk delete failed. This usually occurs because there are other documents referencing the documents you’re trying to delete."}), /* @__PURE__ */e.jsx(oe,{e:t,schemaType:l})]}),status:"error",closable:!0,duration:3e4})}finally{f(null),y(!1)}}})]}),onClose:()=>f(null),children:/* @__PURE__ */e.jsxs(re,{children:[ /* @__PURE__ */e.jsxs("p",{children:["Are you sure you want to delete"," ", /* @__PURE__ */e.jsx("strong",{children:s.size})," document",1===s.size?"":"s","?"]}), /* @__PURE__ */e.jsx("p",{children:"Deleting a document makes it no longer available to the public as well as removing any draft versions of it."}), /* @__PURE__ */e.jsxs("p",{children:[ /* @__PURE__ */e.jsx("strong",{children:"Note:"})," in order to delete a document, it must not be referenced by any other document. You may have to remove those references first."]})]})})]})}const ce=a.forwardRef((t={},i)=>/* @__PURE__ */e.jsx(n.Card,{as:"table",ref:i,...t})),de=g.default(ce)(()=>h.css` display: table; width: 100%; border-collapse: collapse; table-layout: fixed; &:not([hidden]) { display: table; border-collapse: collapse; } `),ue=a.forwardRef((t,n)=>{const{children:i,...r}=t;/* @__PURE__ */ return e.jsx(de,{ref:n,...r,children:i})}),he=g.default((t={})=>/* @__PURE__ */e.jsx(n.Card,{as:"tr",...t}))(()=>h.css` display: table-row; &:not([hidden]) { display: table-row; } `);function pe(t){const{children:n,...i}=t;/* @__PURE__ */ return e.jsx(he,{...i,children:n})}const fe=g.default(({as:t,...i})=>/* @__PURE__ */e.jsx(n.Card,{as:t||"td",...i}))(()=>h.css` display: table-cell; &:not([hidden]) { display: table-cell; } `);function me(t){const{children:n,...i}=t;/* @__PURE__ */ return e.jsx(fe,{...i,children:n})}const ye=g.default((t={})=>/* @__PURE__ */e.jsx(n.Card,{as:"thead",...t}))(()=>h.css` display: table-header-group; &:not([hidden]) { display: table-header-group; } `);function xe(t){const{children:n,...i}=t;/* @__PURE__ */ return e.jsx(ye,{...i,children:n})}const ge="41px",be=g.default.div` height: 100%; position: relative; overflow: hidden; display: flex; flex-direction: column; `,ve=g.default(n.Badge)` text-transform: capitalize; padding: 0.35rem 0.5rem; border-radius: 0.6rem; max-width: 100%; vertical-align: middle !important; div[data-ui='Text'] { font-size: 0.7rem; span { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; overflow: clip; } } `,je=g.default.div` container-type: inline-size; ${({hasResults:e})=>e?h.css` overflow: auto; position: relative; padding-bottom: 41px; flex-grow: 1; flex-shrink: 1; flex-basis: 0; `:h.css` overflow: auto; position: relative; padding-bottom: 41px; `} `,we=g.default.div(({theme:e})=>{const{color:t}=e.sanity,n=t.muted.default.disabled.muted.bg;return h.css` position: absolute; top: 0; height: 100%; left: 0; right: 0; pointer-events: none; transition: opacity 250ms; background-color: ${n}; z-index: 5; opacity: 0; display: flex; &.active { opacity: 0.5; } `}),Se=h.keyframes` from { transform: rotate(0deg); } to { transform: rotate(360deg); } `,_e=g.default(t.SpinnerIcon)` margin: auto; width: 32px; height: 32px; animation: ${Se} 1500ms linear infinite; `,ke=g.default(ue)(({theme:e})=>{const{color:t}=e.sanity,n=t.selectable.default.enabled.border;return h.css` /* Progressive width-based column hiding */ @container (max-width: 600px) { col:nth-child(n + 6), th:nth-child(n + 6), td:nth-child(n + 6) { display: none; } } @container (max-width: 500px) { col:nth-child(n + 5), th:nth-child(n + 5), td:nth-child(n + 5) { display: none; } } @container (max-width: 400px) { col:nth-child(n + 4), th:nth-child(n + 4), td:nth-child(n + 4) { display: none; } } @container (max-width: 300px) { col:nth-child(n + 3), th:nth-child(n + 3), td:nth-child(n + 3) { display: none; } } /* Fallback for browsers without container query support */ @supports not (container-type: inline-size) { @media (max-width: 600px) { col:nth-child(n + 6), th:nth-child(n + 6), td:nth-child(n + 6) { display: none; } } @media (max-width: 500px) { col:nth-child(n + 5), th:nth-child(n + 5), td:nth-child(n + 5) { display: none; } } @media (max-width: 400px) { col:nth-child(n + 4), th:nth-child(n + 4), td:nth-child(n + 4) { display: none; } } @media (max-width: 300px) { col:nth-child(n + 3), th:nth-child(n + 3), td:nth-child(n + 3) { display: none; } } } .preview-root { padding: 0.25rem 0; margin-right: -0.75rem; } .preview-status { display: none; } .preview-title { font-size: 0.75rem; } .preview-subtitle { font-size: 0.6875rem; } thead { position: sticky; top: 0; z-index: 1; } th { padding: 0.4rem 0.5rem; } th::after { position: absolute; content: ' '; left: 0; right: 0; bottom: 0; top: 0; border-bottom: 1px solid ${n}; pointer-events: none; } td, th { text-align: left; } th.title-cell, td.title-cell { //padding-right: 0; } td { padding: 0 0.5rem; border-bottom: 1px solid ${n}; } `}),Ce=g.default(me).attrs(()=>({as:"th"}))` width: ${ge}; `,Ie=g.default(me).attrs(()=>({as:"td"}))` width: ${ge}; `,ze=g.default(me).attrs(()=>({as:"th"}))` width: 30px; overflow: hidden; position: relative; > * > * { margin: auto; } `,Pe=g.default(me).attrs(()=>({as:"td"}))` width: 30px; overflow: hidden; position: relative; > * > * { margin: auto; } `,Ae=g.default.div` display: flex; pointer-events: none; `,$e=g.default.input.attrs({type:"checkbox"})` height: 100%; position: absolute; top: 0; bottom: 0; right: 0; left: 0; width: 100%; opacity: 0; cursor: pointer; `,Te=g.default.span` font-size: 11px; padding-left: 2px; padding-right: 2px; `,Be=["image","file","reference"];function Ee(e,t,n){return e.reduce((e,i)=>{if("array"===i.type.name)return e;const r=`${t}.${i.name}`,s={field:i,fieldPath:r,title:i.type.title,level:n,type:i.type.name,sortable:!Be.includes(i.type.name)};if("slug"===i.type.name||"reference"===i.type.name||"image"===i.type.name)return[...e,s];if("fields"in i.type&&Array.isArray(i.type.fields)&&i.type.fields.length>0){s.sortable=!1;const t=Ee(i.type.fields,r,n+1);if(t.length)return[...e,s,...t]}return[...e,s]},[])}function De(e=[]){return e.length?e.reduce((e,t)=>{if("array"===t.type.name)return e;const n=t.name,i={field:t,fieldPath:n,title:t.type.title,level:0,type:t.type.name,sortable:!Be.includes(t.type.name)};if("slug"===t.type.name||"reference"===t.type.name||"image"===t.type.name)return[...e,i];if("fields"in t.type&&Array.isArray(t.type.fields)&&t.type.fields.length>0){i.sortable=!1;const r=Ee(t.type.fields,n,1);if(r.length)return[...e,i,...r]}return[...e,i]},[]):[]}const Oe=g.default.input.attrs({type:"checkbox"})` height: 100%; position: absolute; top: 0; bottom: 0; right: 0; left: 0; width: 100%; opacity: 0; cursor: pointer; `,Fe=g.default.label` padding-right: 0.5rem; position: relative; display: block; height: 100%; `,Me=g.default(n.Menu)` max-height: 60vh; overflow-y: auto; overflow-x: hidden; max-width: 300px; `,Ne=g.default(n.MenuItem)` height: 1.38rem; > span[data-ui='Box'] { height: 100%; width: 100%; } `,qe=g.default(n.Flex)` height: 100%; max-width: 100%; `,Ue=g.default(n.Box)` width: 16px; height: 100%; `,Re=g.default(n.Text).attrs(()=>({textOverflow:"ellipsis"}))` font-size: 0.77rem; user-select: none; cursor: pointer; max-width: calc(100% - 20px); span { user-select: none; } `;function Ve({schemaType:i,selectedColumns:r,onToggleColumnSelect:s}){const o=a.useMemo(()=>De("fields"in i?i.fields:[]),[i]);/* @__PURE__ */ return e.jsx(n.MenuButton,{id:"select-columns",popover:{portal:!0,placement:"left"},button:/* @__PURE__ */e.jsx(n.Button,{icon:t.ControlsIcon,title:"Select Columns",mode:"bleed",padding:2}),menu:/* @__PURE__ */e.jsxs(Me,{children:[ /* @__PURE__ */e.jsx(Ne,{padding:0,disabled:!0,children:/* @__PURE__ */e.jsxs(qe,{align:"center",gap:1,children:[ /* @__PURE__ */e.jsx(t.CheckmarkIcon,{}), /* @__PURE__ */e.jsx(Re,{children:"Document"})]})}), /* @__PURE__ */e.jsx(Ne,{padding:0,disabled:!0,children:/* @__PURE__ */e.jsxs(qe,{align:"center",gap:1,children:[ /* @__PURE__ */e.jsx(t.CheckmarkIcon,{}), /* @__PURE__ */e.jsx(Re,{children:"Status"})]})}), /* @__PURE__ */e.jsx(n.MenuDivider,{}),S.map(({key:n,title:i})=>{const o=r.has(n);/* @__PURE__ */ return e.jsx(Ne,{padding:0,children:/* @__PURE__ */e.jsxs(Fe,{htmlFor:n,children:[ /* @__PURE__ */e.jsxs(qe,{align:"center",gap:1,children:[o?/* @__PURE__ */e.jsx(t.CheckmarkIcon,{}):/* @__PURE__ */e.jsx(Ue,{}), /* @__PURE__ */e.jsx(Re,{children:i})]}), /* @__PURE__ */e.jsx(Oe,{id:n,checked:o,onChange:e=>{e.stopPropagation(),s(n)}})]})},n)}), /* @__PURE__ */e.jsx(n.MenuDivider,{}),o.map(({fieldPath:n,title:i,level:a},l)=>{const c=l+1<o.length&&o[l+1].level>a,d=r.has(n);/* @__PURE__ */ return e.jsx(Ne,{padding:0,pressed:c,disabled:c,style:{paddingLeft:10*a},children:/* @__PURE__ */e.jsxs(Fe,{htmlFor:n,children:[ /* @__PURE__ */e.jsxs(qe,{align:"center",gap:1,children:[d?/* @__PURE__ */e.jsx(t.CheckmarkIcon,{}):c?/* @__PURE__ */e.jsx(Te,{children:"—"}):/* @__PURE__ */e.jsx(Ue,{}), /* @__PURE__ */e.jsx(Re,{children:i})]}), /* @__PURE__ */e.jsx(Oe,{id:n,disabled:c,checked:d,onChange:e=>{e.stopPropagation(),s(n)}})]})},n)})]})})}const Le=g.default.form` display: flex; gap: 0.5rem; `;function We(){const{paginatedClient:i,searchValue:r,setSearchValue:s}=ne(),o=a.useCallback(b.default(e=>{if(function(e){return!(!e||"string"!=typeof e||e.length<1||e.length>100||[/['"]/,/\\/,/`/,/;/,/[{}]/,/[\[\]]/,/\|/,/\$/,/@/,/->/,/\.\./].some(t=>t.test(e)))}(e)||0===e.length){const t=ee(e);i.setUserQuery(t)}},200),[i.setUserQuery]);return a.useEffect(()=>(o(r),()=>{o.cancel()}),[r,o]),/* @__PURE__ */e.jsx(Le,{onSubmit:e=>e.preventDefault(),children:/* @__PURE__ */e.jsx(n.TextInput,{placeholder:"Search",value:r,fontSize:1,padding:2,icon:t.SearchIcon,onChange:e=>s(e.currentTarget.value)})})}const Ye=g.default(n.Text)` font-size: ${e=>e.muted?"0.7rem":"0.75rem"}; `,Je=g.default.div` width: 2.0625rem; height: 2.0625rem; min-width: 2.0625rem; font-size: 0.75rem; > div > div { padding: 0; } `;function Qe(e,{includeTime:t}){const n=navigator.language||"en-US",i=t?{hour:"numeric",minute:"numeric",hour12:!0}:{};return new Date(e).toLocaleString(n,{year:"numeric",month:"numeric",day:"numeric",...i})}function Ze({field:t,fieldPath:n,value:i}){switch(t.type.name){case"date":case"datetime":case"_createdAt":case"_lastPublishedAt":case"_updatedAt":{const r="date"!==t.type.name,s="_lastPublishedAt"===t.type.name?"Not published":"-";/* @__PURE__ */ return e.jsx(me,{as:"td",children:/* @__PURE__ */e.jsx(Ye,{textOverflow:"ellipsis",muted:!i,children:i?Qe(i,{includeTime:r}):s})},n)}case"slug":/* @__PURE__ */ return e.jsx(me,{as:"td",children:/* @__PURE__ */e.jsx(Ye,{textOverflow:"ellipsis",children:i?.current||"-"})},n);case"text":case"url":case"string":case"number":/* @__PURE__ */ return e.jsx(me,{as:"td",children:/* @__PURE__ */e.jsx(Ye,{textOverflow:"ellipsis",children:i||"-"})},n);case"boolean":{let t="-";return!0===i&&(t="Yes"),!1===i&&(t="No"),/* @__PURE__ */e.jsx(me,{as:"td",children:/* @__PURE__ */e.jsx(Ye,{textOverflow:"ellipsis",children:t})},n)}case"array":/* @__PURE__ */ return e.jsx(me,{as:"td",children:/* @__PURE__ */e.jsxs(Ye,{textOverflow:"ellipsis",children:[i?.length||0," item",1===i?.length?"":"s"]})},n);case"image":/* @__PURE__ */ return e.jsx(me,{as:"td",children:i?/* @__PURE__ */e.jsx(Je,{children:/* @__PURE__ */e.jsx(l.Preview,{layout:"media",value:i,mediaDimensions:{fit:"fill",aspect:1},schemaType:t.type})}):/* @__PURE__ */e.jsx(Ye,{textOverflow:"ellipsis",children:"-"})},n);default:/* @__PURE__ */ return e.jsx(me,{as:"td",children:/* @__PURE__ */e.jsx(Ye,{textOverflow:"ellipsis",children:i?/* @__PURE__ */e.jsx(l.Preview,{value:i,layout:"default",schemaType:t.type}):"-"})},n)}}const Xe=g.default(n.Button)(({theme:e,disabled:t})=>{const{color:n}=e.sanity,i=n.button.bleed.default.enabled.fg;return h.css` div[data-ui='Text'] { font-size: 0.75rem; font-weight: 600; ${t?`color: ${i};`:""} } `});function Ge({field:i}){const{orderColumn:r,setOrderColumn:s}=ne(),o=a.useCallback(()=>{const{fieldPath:e,type:t,sortable:n}=i;if(n){if(r.key===e&&"desc"===r.direction)return void s(j);s({key:e,direction:"asc"===r?.direction&&r.key===e?"desc":"asc",type:t})}},[r,s]),l={mode:r.key===i.fieldPath?"ghost":"bleed"};return r.key===i.fieldPath&&(l.iconRight="asc"===r.direction?t.ChevronUpIcon:t.ChevronDownIcon),/* @__PURE__ */e.jsx(me,{as:"th",style:{paddingLeft:0},children:/* @__PURE__ */e.jsx(n.Tooltip,{content:/* @__PURE__ */e.jsx(n.Box,{padding:0,children:/* @__PURE__ */e.jsx(n.Text,{size:0,children:i.sortable?`Sort by ${i.title}`:"Not sortable"})}),placement:"bottom",portal:!0,delay:{open:400},children:/* @__PURE__ */e.jsx(n.Box,{display:"inline-block",children:/* @__PURE__ */e.jsx(Xe,{space:2,disabled:!i.sortable,paddingX:2,paddingY:2,text:i.title||"",onClick:o,...l})})})})}function He(e,t){return!!e&&(!!e.classList.contains(t)||He(e.parentElement,t))}const Ke=S.map(({key:e,title:t,sortable:n})=>({fieldPath:e,title:t,field:{type:{name:e}},level:0,sortable:n,type:e})),et=()=>{const{navigateIntent:i}=c.usePaneRouter(),{options:{type:r},selectedIds:s,setSelectedIds:o,paginatedClient:a,isSelectState:l,setIsSelectState:d}=ne();/* @__PURE__ */ return e.jsx(n.Card,{padding:2,children:l?/* @__PURE__ */e.jsxs(n.Flex,{align:"center",justify:"space-between",children:[ /* @__PURE__ */e.jsx(n.Text,{size:1,weight:"bold",children:0===s.size?"Select items":`${s.size} item${1===s.size?"":"s"} selected`}), /* @__PURE__ */e.jsxs(n.Flex,{gap:2,align:"center",children:[s.size>0&&/* @__PURE__ */e.jsx(le,{onDelete:()=>{o(/* @__PURE__ */new Set),a.setPage(0),a.refresh()}}), /* @__PURE__ */e.jsx(n.Tooltip,{content:/* @__PURE__ */e.jsx(n.Box,{padding:1,children:/* @__PURE__ */e.jsx(n.Text,{size:0,children:"Cancel bulk selection"})}),delay:{open:400},padding:1,placement:"bottom",portal:!0,children:/* @__PURE__ */e.jsx(n.Button,{fontSize:1,padding:2,text:"Cancel",mode:"default",onClick:()=>{d(!1),o(/* @__PURE__ */new Set)}})})]})]}):/* @__PURE__ */e.jsxs(n.Flex,{align:"center",justify:"space-between",children:[ /* @__PURE__ */e.jsxs(n.Text,{size:1,weight:"bold",children:[a.total," Items"]}), /* @__PURE__ */e.jsxs(n.Flex,{gap:2,align:"center",children:[ /* @__PURE__ */e.jsx(We,{}), /* @__PURE__ */e.jsx(n.Tooltip,{content:/* @__PURE__ */e.jsx(n.Box,{padding:1,children:/* @__PURE__ */e.jsx(n.Text,{size:0,children:"Bulk select"})}),delay:{open:400},padding:1,placement:"bottom",portal:!0,children:/* @__PURE__ */e.jsx(n.Button,{space:2,fontSize:1,padding:2,text:"Select",mode:"default",icon:t.CheckmarkIcon,onClick:()=>d(!0)})}), /* @__PURE__ */e.jsx(n.Button,{space:2,fontSize:1,padding:2,text:"Create",tone:"primary",icon:t.AddIcon,onClick:()=>i("create",{type:r})})]})]})})},tt=()=>{const{navigateIntent:t,groupIndex:i,routerPanesState:r}=c.usePaneRouter(),s=r[i+1]?.[0]?.id||null,{selectedColumns:o,setSelectedColumns:d,setOrderColumn:u,selectedIds:h,setSelectedIds:p,schemaType:f,isSelectState:m,paginatedClient:x}=ne(),g=a.useRef(null),b=[...a.useMemo(()=>Ke.filter(e=>o.has(e.fieldPath)),[Ke,o]),...a.useMemo(()=>De("fields"in f?f.fields:[]).filter(e=>o.has(e.fieldPath)),[f,o])],v=x.results.some(e=>h.has(e._normalizedId)),w=x.results.every(e=>h.has(e._normalizedId));/* @__PURE__ */ return e.jsx(je,{hasResults:!!x.results.length,children:/* @__PURE__ */e.jsxs(ke,{ref:g,children:[ /* @__PURE__ */e.jsxs("colgroup",{children:[m&&/* @__PURE__ */e.jsx("col",{}), /* @__PURE__ */e.jsx("col",{}), /* @__PURE__ */e.jsx("col",{}),b.map(t=>/* @__PURE__ */e.jsx("col",{},t.fieldPath)), /* @__PURE__ */e.jsx("col",{style:{width:ge}})]}), /* @__PURE__ */e.jsx(xe,{tone:"default",children:/* @__PURE__ */e.jsxs(pe,{children:[m&&/* @__PURE__ */e.jsxs(ze,{className:"prevent-nav",children:[ /* @__PURE__ */e.jsx($e,{type:"checkbox",checked:w,onChange:()=>{p(e=>{const t=new Set(e);if(w)for(const e of x.results||[])t.delete(e._normalizedId);else for(const e of x.results||[])t.add(e._normalizedId);return t})}}), /* @__PURE__ */e.jsx(Ae,{"aria-hidden":"true",children:/* @__PURE__ */e.jsx(n.Checkbox,{tabIndex:-1,checked:v,indeterminate:v&&!w,readOnly:!0})})]}), /* @__PURE__ */e.jsx(Ge,{field:{title:"Document",fieldPath:"_document",type:"string",sortable:!1,field:{type:{name:"string"}},level:0}}), /* @__PURE__ */e.jsx(Ge,{field:{title:"Status",fieldPath:"_status",type:"string",sortable:!1,field:{type:{name:"string"}},level:0}}),b.map(t=>/* @__PURE__ */e.jsx(Ge,{field:t},t.fieldPath)), /* @__PURE__ */e.jsx(Ce,{children:/* @__PURE__ */e.jsx(Ve,{schemaType:f,selectedColumns:o,onToggleColumnSelect:e=>{const t=new Set(o);t.has(e)&&u(j),t.has(e)?t.delete(e):t.add(e),d(t)}})})]})}), /* @__PURE__ */e.jsx("tbody",{children:x.results.map(i=>{const r=()=>{p(e=>{const t=new Set(e);return h.has(i._normalizedId)?t.delete(i._normalizedId):t.add(i._normalizedId),t})};/* @__PURE__ */ return e.jsxs(pe,{"data-as":"a",selected:i._id===s,tone:h.has(i._normalizedId)?"primary":"default",onClick:e=>{if(!He(e.target,"prevent-nav")){if(m)return void r();t("edit",{id:i._id,type:i._type,selectedRev:i._rev})}},children:[m&&/* @__PURE__ */e.jsxs(Pe,{className:"prevent-nav",children:[ /* @__PURE__ */e.jsx($e,{type:"checkbox",checked:h.has(i._normalizedId),onChange:e=>{e.preventDefault(),r(),e.stopPropagation()}}), /* @__PURE__ */e.jsx(Ae,{"aria-hidden":"true",children:/* @__PURE__ */e.jsx(n.Checkbox,{tabIndex:-1,checked:h.has(i._normalizedId),readOnly:!0})})]}), /* @__PURE__ */e.jsx(me,{as:"td",className:"title-cell",children:/* @__PURE__ */e.jsx(l.Preview,{schemaType:f,layout:"default",value:i})}), /* @__PURE__ */e.jsx(me,{as:"td",children:/* @__PURE__ */e.jsx(ve,{tone:"published"===i._status?"positive":"draft"===i._status?"caution":"primary",children:"published_with_pending_changes"===i._status?"Staged changes":i._status})}),b.map(t=>/* @__PURE__ */e.jsx(Ze,{field:t.field,fieldPath:t.fieldPath,value:y.default(i,t.fieldPath)},t.fieldPath)), /* @__PURE__ */e.jsx(Ie,{})]},i._normalizedId)})})]})})},nt=()=>{const{paginatedClient:t}=ne();/* @__PURE__ */ return e.jsx(we,{className:m.default({active:t.loading}),children:/* @__PURE__ */e.jsx(_e,{})})},it=()=>{const{navigateIntent:i}=c.usePaneRouter(),{options:{type:r,title:s},searchValue:a,paginatedClient:l}=ne();if(l.loading||l.results.length)return null;const d=x.default(s||"item",0).toLowerCase(),u=o.singular(s||"item").toLowerCase();/* @__PURE__ */ return e.jsx(n.Flex,{direction:"column",align:"center",children:/* @__PURE__ */e.jsx(n.Card,{padding:4,radius:2,shadow:1,children:/* @__PURE__ */e.jsxs(n.Flex,{direction:"column",align:"center",justify:"center",gap:4,children:[ /* @__PURE__ */e.jsx(n.Text,{size:2,align:"center",children:a.length?`No results for "${a}".`:`No ${d} in your collection.`}),!a.length&&/* @__PURE__ */e.jsx(n.Button,{padding:2,fontSize:1,tone:"default",icon:t.AddIcon,text:`Create ${u}`,onClick:()=>i("create",{type:r})})]})})})},rt=()=>{const{pageSize:i,setPageSize:r,paginatedClient:s}=ne();/* @__PURE__ */ return e.jsx(n.Card,{borderTop:!0,padding:[3,3,2],style:{position:"absolute",bottom:0,width:"100%"},children:/* @__PURE__ */e.jsxs(n.Flex,{align:"center",gap:2,children:[ /* @__PURE__ */e.jsxs(n.Flex,{align:"center",gap:2,children:[ /* @__PURE__ */e.jsx(n.Label,{style:{whiteSpace:"nowrap"},children:"Rows Per Page"}), /* @__PURE__ */e.jsx(n.Select,{fontSize:1,padding:2,value:i,onChange:e=>r(parseInt(e.currentTarget.value,10)),children:v.map(t=>/* @__PURE__ */e.jsx("option",{value:t,children:t},t))})]}), /* @__PURE__ */e.jsx(n.Box,{flex:1,children:/* @__PURE__ */e.jsxs(n.Flex,{align:"center",justify:"flex-end",gap:2,children:[ /* @__PURE__ */e.jsx(n.Button,{fontSize:1,padding:2,disabled:0===s.page,onClick:()=>s.setPage(s.page-1),icon:t.ChevronLeftIcon,title:"Previous page",mode:"bleed"}), /* @__PURE__ */e.jsxs(n.Label,{children:[0===s.totalPages?0:s.page+1," / ",s.totalPages]}), /* @__PURE__ */e.jsx(n.Button,{fontSize:1,padding:2,disabled:s.page===s.totalPages-1,onClick:()=>s.setPage(s.page+1),icon:t.ChevronRightIcon,title:"Next page",mode:"bleed"})]})})]})})},st=t=>{const r=a.useRef(null);/* @__PURE__ */ return e.jsx(n.ThemeProvider,{theme:i.buildTheme(),children:/* @__PURE__ */e.jsx(n.ToastProvider,{children:/* @__PURE__ */e.jsx(ie,{options:t.options,children:/* @__PURE__ */e.jsxs(be,{ref:r,children:[ /* @__PURE__ */e.jsx(et,{}), /* @__PURE__ */e.jsx(nt,{}), /* @__PURE__ */e.jsx(tt,{}), /* @__PURE__ */e.jsx(it,{}), /* @__PURE__ */e.jsx(rt,{})]})})})})};exports.createBulkActionsTable=function(e){if(!e)throw new Error("\n Configuration object is required.\n Example: createBulkActionsTable({type: 'category', S, context})\n ");if(!e.type||"string"!=typeof e.type)throw new Error("\n 'type' parameter is required and must be a string.\n The type should match a document schema type in your Sanity project.\n Example: createBulkActionsTable({type: 'post', S, context})\n ");if(!e.context)throw new Error("\n 'context' parameter is required.\n This should be the ConfigContext provided by the structure resolver.\n Example: structure: (S, context) => createBulkActionsTable({type: 'post', S, context})\n ");if(!e.S)throw new Error("\n 'S' (StructureBuilder) parameter is required.\n This should be the StructureBuilder provided by the structure resolver.\n Example: structure: (S, context) => createBulkActionsTable({type: 'post', S, context})\n ");if(void 0!==e.title&&"string"!=typeof e.title)throw new Error("\n 'title' parameter must be a string when provided.\n Example: createBulkActionsTable({type: 'post', S, context, title: 'Blog Posts'})\n ");if(void 0!==e.apiVersion&&"string"!=typeof e.apiVersion)throw new Error("\n 'apiVersion' parameter must be a string when provided.\n Example: createBulkActionsTable({type: 'post', S, context, apiVersion: '2024-03-12'})\n ");const{type:n,context:i,S:r,title:s,icon:o,apiVersion:a="2024-03-12"}=e,{schema:l,getClient:c}=i,d=c({apiVersion:a}),u=function(){const e=/* @__PURE__ */new Set;return{subscribe:function(t){return e.add(t),()=>{e.delete(t)}},notify:function(){for(const t of e)t()}}}();return r.listItem().id(n).title(s||n).icon(o||t.FolderIcon).child(Object.assign(r.documentTypeList(n).serialize(),{__preserveInstance:!0,key:n,type:"component",options:{type:n,client:d,schema:l,refresh:u,title:s},component:st,menuItems:[r.menuItem().title("Refresh").icon(t.SyncIcon).action(u.notify).serialize()]})).serialize()};