@sanity/orderable-document-list 1.0.4 → 1.1.1

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 +1,787 @@
1
- "use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function t(t){for(var r=1;r<arguments.length;r++){var i=null!=arguments[r]?arguments[r]:{};r%2?e(Object(i),!0).forEach((function(e){n(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function n(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 r=n.call(e,t||"default");if("object"!=typeof r)return r;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}Object.defineProperty(exports,"__esModule",{value:!0});var r=require("sanity"),i=require("lexorank"),s=require("@sanity/icons"),o=require("react/jsx-runtime"),l=require("react"),a=require("@sanity/ui"),c=require("@hello-pangea/dnd"),d=require("sanity/desk");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}const p="orderRank";const h={title:"Ordered",name:"ordered",by:[{field:p,direction:"asc"}]},g=u(l).default.createContext({});function f(e){let{doc:t,increment:n,entities:i,handleSelect:c,index:d,isFirst:u,isLast:p}=e;const{showIncrements:h}=l.useContext(g),f=r.useSchema();return o.jsxs(a.Flex,{align:"center",children:[o.jsx(a.Box,{paddingX:3,style:{flexShrink:0},children:o.jsx(a.Text,{size:4,children:o.jsx(s.DragHandleIcon,{})})}),h&&o.jsxs(a.Flex,{style:{flexShrink:0},align:"center",gap:1,paddingRight:1,children:[o.jsx(a.Button,{padding:2,mode:"ghost",onClick:()=>n(d,d+-1,t._id,i),disabled:u,icon:s.ChevronUpIcon}),o.jsx(a.Button,{padding:2,mode:"ghost",disabled:p,onClick:()=>n(d,d+1,t._id,i),icon:s.ChevronDownIcon})]}),o.jsx(a.Button,{style:{width:"100%"},padding:2,mode:"bleed",onClick:e=>c(t._id,d,e.nativeEvent),children:o.jsx(a.Flex,{flex:1,align:"center",children:o.jsx(a.Card,{tone:"default",children:o.jsx(r.Preview,{layout:"default",value:t,schemaType:f.get(t._type)})})})})]})}function m(e,t){return e[p]&&t[p]?e[p]<t[p]?-1:e[p]>t[p]?1:0:0}const x=e=>{let{entities:t,selectedIds:n,source:r,destination:s}=e;const o=r.index,l=s.index,a=o>l,c=t.filter((e=>n.includes(e._id))),d=["Moved",1===c.length?"1 Document":"".concat(c.length," Documents"),a?"up":"down","from position","".concat(o+1," to ").concat(l+1)].join(" "),{all:u,selected:h}=t.reduce(((e,r,s)=>{var o,d,u,h;if(n.includes(r._id))return{all:e.all,selected:e.selected};if(s===l){const n=s-1,l=(null==(o=t[n])?void 0:o[p])?i.LexoRank.parse(null==(d=t[n])?void 0:d[p]):i.LexoRank.min(),g=i.LexoRank.parse(t[s][p]),f=s+1,m=(null==(u=t[f])?void 0:u[p])?i.LexoRank.parse(null==(h=t[f])?void 0:h[p]):i.LexoRank.max();let x=a?l.between(g):g.between(m);for(let e=0;e<c.length;e+=1)c[e][p]=x.toString(),x=a?x.between(g):x.between(m);return{all:a?[...e.all,...c,r]:[...e.all,r,...c],selected:c}}return{all:[...e.all,r],selected:e.selected}}),{all:[],selected:[]}),g=h.map((e=>[e._id,{set:{[p]:e[p]}}]));return{newOrder:u.sort(m),patches:g,message:d}};function y(){return r.useClient({apiVersion:"2021-09-01"})}const v=(e,n)=>t({userSelect:"none",transition:"opacity 500ms ease-in-out",opacity:n?.2:1,pointerEvents:n?"none":void 0},e),b=e=>{const{isDuplicate:t,isGhosting:n,isDragging:r,isSelected:i}=e;return n?"transparent":r||i?"primary":t?"caution":void 0};function j(e){let{data:n,type:r,listIsUpdating:i,setListIsUpdating:s}=e;const u=a.useToast(),h=d.usePaneRouter(),{navigateIntent:g}=h,[m,j]=l.useState(n);l.useEffect((()=>{i||j(n)}),[n]);const[w,O]=l.useState(""),[S,I]=l.useState([]),k=l.useCallback((()=>I([])),[I]),D=l.useCallback(((e,t,n)=>{const i=S.includes(e),s=n.shiftKey,o=-1!==navigator.appVersion.indexOf("Win")?n.ctrlKey:n.metaKey;let l=[];if(!s&&!o)return g("edit",{id:e,type:r}),I([e]);if(s&&!i){const n=S[S.length-1],r=m.findIndex((e=>e._id===n)),i=t<r?t:r,s=t>r?t:r,o=m.filter(((e,t)=>t>i&&t<s)).map((e=>e._id));l=[...S,...o,e]}else l=i?S.filter((t=>t!==e)):[...S,e];return I(l)}),[I,g,m,S,r]),_=y(),C=l.useCallback((async(e,t)=>{const n=_.transaction();e.forEach((e=>{let[t,r]=e;return n.patch(t,r)})),await n.commit().then((e=>{k(),O(""),s(!1),u.push({title:"".concat(1===e.results.length?"1 Document":"".concat(e.results.length," Documents")," Reordered"),status:"success",description:t})})).catch((()=>{O(""),s(!1),u.push({title:"Reordering failed",status:"error"})}))}),[_,O,k,s,u]),R=l.useCallback(((e,t)=>{O("");const{source:n,destination:r,draggableId:i}=null!=e?e:{};if((null==n?void 0:n.index)===(null==r?void 0:r.index))return;if(!(null==t?void 0:t.length)||!i)return;const o=(null==S?void 0:S.length)?S:[i];if(!(null==o?void 0:o.length))return;s(!0),I(o);const{newOrder:l,patches:a,message:c}=x({entities:t,selectedIds:o,source:n,destination:r});(null==l?void 0:l.length)&&j(l),(null==a?void 0:a.length)&&C(a,c)}),[S,O,I,C,s]),E=l.useCallback((e=>{const t=e.draggableId;S.includes(t)||k(),O(t)}),[S,k,O]),P=l.useCallback(((e,t,n,r)=>R({draggableId:n,source:{index:e},destination:{index:t}},r)),[R]),L=l.useCallback((e=>{"Escape"===e.key&&k()}),[k]);l.useEffect((()=>(window.addEventListener("keydown",L),()=>{window.removeEventListener("keydown",L)})),[L]);const T=l.useMemo((()=>{if(!m.length)return[];const e=m.map((e=>e[p]));return e.filter(((t,n)=>e.indexOf(t)!==n))}),[m]),F=l.useCallback((e=>R(e,m)),[m,R]);return o.jsx(c.DragDropContext,{onDragStart:E,onDragEnd:F,children:o.jsx(c.Droppable,{droppableId:"documentSortZone",children:e=>o.jsxs("div",t(t({},e.droppableProps),{},{ref:e.innerRef,children:[m.map(((e,n)=>o.jsx(c.Draggable,{draggableId:e._id,index:n,children:(r,s)=>{const l=S.includes(e._id),c=s.isDragging,d=Boolean(!c&&w&&l),u=i&&l,h=Boolean(!e[p]),g=T.includes(e[p]),x=b({isDuplicate:g,isGhosting:d,isDragging:c,isSelected:l});return o.jsx("div",t(t(t({ref:r.innerRef},r.draggableProps),r.dragHandleProps),{},{style:h?{opacity:.2,pointerEvents:"none"}:v(r.draggableProps.style,u),children:o.jsx(a.Box,{paddingBottom:1,children:o.jsx(a.Card,{tone:x,shadow:c?2:void 0,radius:2,children:o.jsx(f,{doc:e,entities:m,handleSelect:D,increment:P,index:n,isFirst:0===n,isLast:n===m.length-1})})})}))}},"".concat(e._id,"-").concat(e[p])))),e.placeholder]}))})})}function w(e){let{children:t}=e;return o.jsx(a.Box,{padding:3,children:o.jsx(a.Card,{padding:4,radius:2,shadow:1,tone:"caution",children:o.jsx(a.Text,{children:t})})})}const O={};function S(e){let{type:t,filter:n,params:r=O}=e;const[i,s]=l.useState(!0),[c,d]=l.useState(!1),[u,h]=l.useState([]),g=y();l.useEffect((()=>{const e="*[_type == $type ".concat(n?"&& ".concat(n):"","]|order(@[$order] asc){\n _id, _type, ").concat(p,"\n }"),o=Object.assign(r,{type:t,order:p});let l;const a=async()=>{g.fetch(e,o).then((e=>{const t=e.reduce(((t,n)=>{if(!n._id.startsWith("drafts.")){return e.some((e=>e._id==="drafts.".concat(n._id)))?t:[...t,n]}return[...t,n]}),[]);h(t),i&&s(!1)}))};return c||u.length||(async()=>{s(!0),await a(),l||(l=g.listen(e,o).subscribe((()=>a())))})(),()=>null==l?void 0:l.unsubscribe()}),[t]);const f=l.useMemo((()=>u.length?u.filter((e=>!e[p])).length:0),[u]);return i?o.jsx(a.Flex,{style:{width:"100%",height:"100%"},align:"center",justify:"center",children:o.jsx(a.Spinner,{})}):o.jsxs(a.Stack,{space:1,style:{overflow:"auto",height:"100%"},children:[f>0&&o.jsxs(w,{children:[f,"/",u.length," Documents have no Order. Select"," ",o.jsx("strong",{children:"Reset Order"})," from the Menu above to fix."]}),o.jsx(a.Box,{padding:1,children:o.jsx(j,{data:u,type:t,listIsUpdating:c,setListIsUpdating:d})})]})}function I(e){let{type:t,showIncrements:n,resetOrderTransaction:i,filter:s,params:c}=e;const d=a.useToast(),u=r.useSchema();l.useEffect((()=>{(null==i?void 0:i.title)&&(null==i?void 0:i.status)&&d.push(i)}),[i,d]);const h=l.useMemo((()=>{if(!t)return o.jsxs(o.Fragment,{children:["No ",o.jsx("code",{children:"type"})," was configured"]});const e=u.get(t);return e?"fields"in e&&e.fields.some((e=>(null==e?void 0:e.name)===p))?"fields"in e&&e.fields.some((e=>{var t;return(null==e?void 0:e.name)===p&&"string"!==(null==(t=null==e?void 0:e.type)?void 0:t.name)}))?o.jsxs(o.Fragment,{children:[o.jsx("code",{children:p})," field on Schema ",o.jsx("code",{children:t})," must be"," ",o.jsx("code",{children:"string"})," type"]}):"":o.jsxs(o.Fragment,{children:["Schema ",o.jsx("code",{children:t})," must have an ",o.jsx("code",{children:p})," field of type"," ",o.jsx("code",{children:"string"})]}):o.jsxs(o.Fragment,{children:["Schema ",o.jsx("code",{children:t})," not found"]})}),[t,u]);return h?o.jsx(w,{children:h}):o.jsx(g.Provider,{value:{showIncrements:n},children:o.jsx(S,{type:t,filter:s,params:c})})}class k extends l.Component{constructor(e){super(e),this.actionHandlers={showIncrements:()=>{this.setState((e=>({showIncrements:!e.showIncrements})))},resetOrder:async()=>{var e;this.setState((()=>({resetOrderTransaction:{status:"info",title:"Reordering started...",closable:!0}})));const t=await async function(){let e=arguments.length>1?arguments[1]:void 0;const t={type:arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",order:p},n=await e.fetch("*[_type == $type]|order(@[$order] asc)._id",t);if(!n.length)return null;const r=e.transaction();let s=i.LexoRank.min();for(let e=0;e<n.length;e+=1)s=s.genNext().genNext(),r.patch(n[e],{set:{[p]:s.toString()}});return r.commit().then((e=>e)).catch((e=>e))}(this.props.options.type,this.props.options.client),n=null==(e=null==t?void 0:t.results)?void 0:e.length;this.setState((()=>({resetOrderTransaction:{status:n?"success":"info",title:n?"Reordered ".concat(1===t.results.length?"Document":"Documents"):"Reordering failed",closable:!0}})))}},this.state={showIncrements:!1,resetOrderTransaction:{}}}render(){var e,t,n,r,i,s;const l=null==(t=null==(e=null==this?void 0:this.props)?void 0:e.options)?void 0:t.type;return l?o.jsx(I,{filter:null==(r=null==(n=null==this?void 0:this.props)?void 0:n.options)?void 0:r.filter,params:null==(s=null==(i=null==this?void 0:this.props)?void 0:i.options)?void 0:s.params,type:l,showIncrements:this.state.showIncrements,resetOrderTransaction:this.state.resetOrderTransaction}):null}}exports.orderRankField=e=>{if(!(null==e?void 0:e.type))throw new Error("\n type must be provided.\n Example: orderRankField({type: 'category'})\n ");const{type:n}=e;return r.defineField(t(t({title:"Order Rank",readOnly:!0,hidden:!0},e),{},{name:p,type:"string",initialValue:async(e,t)=>{let{getClient:r}=t;return function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(e?i.LexoRank.parse(e):i.LexoRank.min()).genNext().genNext().toString()}(await r({apiVersion:"2021-09-01"}).fetch("*[_type == $type]|order(@[$order] desc)[0][$order]",{type:n,order:p}))}}))},exports.orderRankOrdering=h,exports.orderableDocumentListDeskItem=function(e){var t,n;if(!(null==e?void 0:e.type)||!e.context||!e.S)throw new Error("\n type, context and S (StructureBuilder) must be provided.\n context and S are available when configuring structure.\n Example: orderableDocumentListDeskItem({type: 'category'})\n ");const{type:r,filter:i,params:o,title:l,icon:a,id:c,context:d,S:u}=e,{schema:p,getClient:h}=d,g=h({apiVersion:"2021-09-01"}),f=null!=l?l:"Orderable ".concat(r),m=null!=c?c:"orderable-".concat(r),x=null!=a?a:s.SortIcon,y=null!=(n=null==(t=p.get(r))?void 0:t.title)?n:r;return u.listItem().title(f).id(m).icon(x).child(Object.assign(u.documentTypeList(r).serialize(),{__preserveInstance:!0,key:m,type:"component",component:k,options:{type:r,filter:i,params:o,client:g},menuItems:[u.menuItem().title("Create new ".concat(y)).intent({type:"create",params:{type:r}}).serialize(),u.menuItem().title("Reset Order").icon(s.GenerateIcon).action("resetOrder").serialize(),u.menuItem().title("Toggle Increments").icon(s.SortIcon).action("showIncrements").serialize()]})).serialize()};//# sourceMappingURL=index.js.map
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ });
6
+ var sanity = require('sanity');
7
+ var lexorank = require('lexorank');
8
+ var icons = require('@sanity/icons');
9
+ var jsxRuntime = require('react/jsx-runtime');
10
+ var React = require('react');
11
+ var ui = require('@sanity/ui');
12
+ var sanityPluginUtils = require('sanity-plugin-utils');
13
+ var dnd = require('@hello-pangea/dnd');
14
+ var desk = require('sanity/desk');
15
+ function _interopDefaultCompat(e) {
16
+ return e && typeof e === 'object' && 'default' in e ? e : {
17
+ default: e
18
+ };
19
+ }
20
+ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
21
+ const ORDER_FIELD_NAME = "orderRank";
22
+ function initialRank() {
23
+ let lastRankValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
24
+ const lastRank = lastRankValue ? lexorank.LexoRank.parse(lastRankValue) : lexorank.LexoRank.min();
25
+ const nextRank = lastRank.genNext().genNext();
26
+ return nextRank.toString();
27
+ }
28
+ const orderRankField = config => {
29
+ if (!(config == null ? void 0 : config.type)) {
30
+ throw new Error("\n type must be provided.\n Example: orderRankField({type: 'category'})\n ");
31
+ }
32
+ const {
33
+ type
34
+ } = config;
35
+ return sanity.defineField({
36
+ title: "Order Rank",
37
+ readOnly: true,
38
+ hidden: true,
39
+ ...config,
40
+ name: ORDER_FIELD_NAME,
41
+ type: "string",
42
+ initialValue: async (p, _ref) => {
43
+ let {
44
+ getClient
45
+ } = _ref;
46
+ const lastDocOrderRank = await getClient({
47
+ apiVersion: "2021-09-01"
48
+ }).fetch("*[_type == $type]|order(@[$order] desc)[0][$order]", {
49
+ type,
50
+ order: ORDER_FIELD_NAME
51
+ });
52
+ return initialRank(lastDocOrderRank);
53
+ }
54
+ });
55
+ };
56
+ const orderRankOrdering = {
57
+ title: "Ordered",
58
+ name: "ordered",
59
+ by: [{
60
+ field: ORDER_FIELD_NAME,
61
+ direction: "asc"
62
+ }]
63
+ };
64
+ const OrderableContext = React__default.default.createContext({});
65
+ function Document(_ref2) {
66
+ let {
67
+ doc,
68
+ increment,
69
+ entities,
70
+ index,
71
+ isFirst,
72
+ isLast,
73
+ dragBadge
74
+ } = _ref2;
75
+ var _a, _b;
76
+ const {
77
+ showIncrements
78
+ } = React.useContext(OrderableContext);
79
+ const schema = sanity.useSchema();
80
+ const router = desk.usePaneRouter();
81
+ const {
82
+ ChildLink,
83
+ groupIndex,
84
+ routerPanesState
85
+ } = router;
86
+ const currentDoc = ((_b = (_a = routerPanesState[groupIndex + 1]) == null ? void 0 : _a[0]) == null ? void 0 : _b.id) || false;
87
+ const pressed = currentDoc === doc._id || currentDoc === doc._id.replace("drafts.", "");
88
+ const selected = pressed && routerPanesState.length === groupIndex + 2;
89
+ const Link = React.useMemo(() => function LinkComponent(linkProps) {
90
+ return /* @__PURE__ */jsxRuntime.jsx(ChildLink, {
91
+ ...linkProps,
92
+ childId: doc._id
93
+ });
94
+ }, [ChildLink, doc._id]);
95
+ return /* @__PURE__ */jsxRuntime.jsx(sanity.PreviewCard, {
96
+ __unstable_focusRing: true,
97
+ as: Link,
98
+ "data-as": "a",
99
+ "data-ui": "PaneItem",
100
+ radius: 2,
101
+ pressed,
102
+ selected,
103
+ sizing: "border",
104
+ tabIndex: -1,
105
+ tone: "inherit",
106
+ width: "100%",
107
+ flex: 1,
108
+ children: /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
109
+ align: "center",
110
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
111
+ paddingX: 2,
112
+ style: {
113
+ flexShrink: 0
114
+ },
115
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
116
+ size: 2,
117
+ children: /* @__PURE__ */jsxRuntime.jsx(icons.DragHandleIcon, {
118
+ cursor: "grab"
119
+ })
120
+ })
121
+ }), showIncrements && /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
122
+ style: {
123
+ flexShrink: 0
124
+ },
125
+ align: "center",
126
+ gap: 1,
127
+ paddingRight: 1,
128
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Button, {
129
+ padding: 2,
130
+ mode: "ghost",
131
+ onClick: () => increment(index, index + -1, doc._id, entities),
132
+ disabled: isFirst,
133
+ icon: icons.ChevronUpIcon
134
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
135
+ padding: 2,
136
+ mode: "ghost",
137
+ disabled: isLast,
138
+ onClick: () => increment(index, index + 1, doc._id, entities),
139
+ icon: icons.ChevronDownIcon
140
+ })]
141
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
142
+ style: {
143
+ width: "100%"
144
+ },
145
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
146
+ flex: 1,
147
+ align: "center",
148
+ children: /* @__PURE__ */jsxRuntime.jsx(sanity.Preview, {
149
+ layout: "default",
150
+ value: doc,
151
+ schemaType: schema.get(doc._type)
152
+ })
153
+ })
154
+ }), dragBadge && /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
155
+ tone: "default",
156
+ marginRight: 4,
157
+ radius: 5,
158
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.AvatarCounter, {
159
+ count: dragBadge
160
+ })
161
+ })]
162
+ })
163
+ });
164
+ }
165
+ function lexicographicalSort(a, b) {
166
+ if (!a[ORDER_FIELD_NAME] || !b[ORDER_FIELD_NAME]) {
167
+ return 0;
168
+ } else if (a[ORDER_FIELD_NAME] < b[ORDER_FIELD_NAME]) {
169
+ return -1;
170
+ } else if (a[ORDER_FIELD_NAME] > b[ORDER_FIELD_NAME]) {
171
+ return 1;
172
+ }
173
+ return 0;
174
+ }
175
+ const reorderDocuments = _ref3 => {
176
+ let {
177
+ entities,
178
+ selectedIds,
179
+ source,
180
+ destination
181
+ } = _ref3;
182
+ const startIndex = source.index;
183
+ const endIndex = destination.index;
184
+ const isMovingUp = startIndex > endIndex;
185
+ const selectedItems = entities.filter(item => selectedIds.includes(item._id));
186
+ const message = ["Moved", selectedItems.length === 1 ? "1 document" : "".concat(selectedItems.length, " documents"), isMovingUp ? "up" : "down", "from position", "".concat(startIndex + 1, " to ").concat(endIndex + 1)].join(" ");
187
+ const {
188
+ all,
189
+ selected
190
+ } = entities.reduce((acc, cur, curIndex) => {
191
+ var _a, _b, _c, _d;
192
+ if (selectedIds.includes(cur._id)) {
193
+ return {
194
+ all: acc.all,
195
+ selected: acc.selected
196
+ };
197
+ }
198
+ if (curIndex === endIndex) {
199
+ const prevIndex = curIndex - 1;
200
+ const prevRank = ((_a = entities[prevIndex]) == null ? void 0 : _a[ORDER_FIELD_NAME]) ? lexorank.LexoRank.parse((_b = entities[prevIndex]) == null ? void 0 : _b[ORDER_FIELD_NAME]) : lexorank.LexoRank.min();
201
+ const curRank = lexorank.LexoRank.parse(entities[curIndex][ORDER_FIELD_NAME]);
202
+ const nextIndex = curIndex + 1;
203
+ const nextRank = ((_c = entities[nextIndex]) == null ? void 0 : _c[ORDER_FIELD_NAME]) ? lexorank.LexoRank.parse((_d = entities[nextIndex]) == null ? void 0 : _d[ORDER_FIELD_NAME]) : lexorank.LexoRank.max();
204
+ let betweenRank = isMovingUp ? prevRank.between(curRank) : curRank.between(nextRank);
205
+ for (let selectedIndex = 0; selectedIndex < selectedItems.length; selectedIndex += 1) {
206
+ selectedItems[selectedIndex][ORDER_FIELD_NAME] = betweenRank.toString();
207
+ betweenRank = isMovingUp ? betweenRank.between(curRank) : betweenRank.between(nextRank);
208
+ }
209
+ return {
210
+ // The `all` array gets sorted by order field later anyway
211
+ // so that this probably isn't necessary ¯\_(ツ)_/¯
212
+ all: isMovingUp ? [...acc.all, ...selectedItems, cur] : [...acc.all, cur, ...selectedItems],
213
+ selected: selectedItems
214
+ };
215
+ }
216
+ return {
217
+ all: [...acc.all, cur],
218
+ selected: acc.selected
219
+ };
220
+ }, {
221
+ all: [],
222
+ selected: []
223
+ });
224
+ const patches = selected.flatMap(doc => {
225
+ const docPatches = [[doc._id, {
226
+ set: {
227
+ [ORDER_FIELD_NAME]: doc[ORDER_FIELD_NAME]
228
+ }
229
+ }]];
230
+ if (doc._id.startsWith("drafts.") && doc.hasPublished) {
231
+ docPatches.push([doc._id.replace("drafts.", ""), {
232
+ set: {
233
+ [ORDER_FIELD_NAME]: doc[ORDER_FIELD_NAME]
234
+ }
235
+ }]);
236
+ }
237
+ return docPatches;
238
+ });
239
+ const allSorted = all.sort(lexicographicalSort);
240
+ return {
241
+ newOrder: allSorted,
242
+ patches,
243
+ message
244
+ };
245
+ };
246
+ function useSanityClient() {
247
+ return sanity.useClient({
248
+ apiVersion: "2021-09-01"
249
+ });
250
+ }
251
+ const getItemStyle = (draggableStyle, itemIsUpdating) => ({
252
+ userSelect: "none",
253
+ transition: "opacity 500ms ease-in-out",
254
+ opacity: itemIsUpdating ? 0.2 : 1,
255
+ pointerEvents: itemIsUpdating ? "none" : void 0,
256
+ ...draggableStyle
257
+ });
258
+ const cardTone = settings => {
259
+ const {
260
+ isDuplicate,
261
+ isGhosting,
262
+ isDragging,
263
+ isSelected
264
+ } = settings;
265
+ if (isGhosting) return "transparent";
266
+ if (isDragging || isSelected) return "primary";
267
+ if (isDuplicate) return "caution";
268
+ return void 0;
269
+ };
270
+ function DraggableList(_ref4) {
271
+ let {
272
+ data,
273
+ listIsUpdating,
274
+ setListIsUpdating
275
+ } = _ref4;
276
+ var _a, _b;
277
+ const toast = ui.useToast();
278
+ const router = desk.usePaneRouter();
279
+ const {
280
+ groupIndex,
281
+ routerPanesState
282
+ } = router;
283
+ const currentDoc = ((_b = (_a = routerPanesState[groupIndex + 1]) == null ? void 0 : _a[0]) == null ? void 0 : _b.id) || false;
284
+ const [orderedData, setOrderedData] = React.useState(data);
285
+ React.useEffect(() => {
286
+ if (!listIsUpdating) setOrderedData(data);
287
+ }, [data]);
288
+ const [draggingId, setDraggingId] = React.useState("");
289
+ const [selectedIds, setSelectedIds] = React.useState(currentDoc ? [currentDoc] : []);
290
+ const clearSelected = React.useCallback(() => setSelectedIds([]), [setSelectedIds]);
291
+ const handleSelect = React.useCallback((clickedId, index, nativeEvent) => {
292
+ const isSelected = selectedIds.includes(clickedId);
293
+ const selectMultiple = nativeEvent.shiftKey;
294
+ const isUsingWindows = navigator.appVersion.indexOf("Win") !== -1;
295
+ const selectAdditional = isUsingWindows ? nativeEvent.ctrlKey : nativeEvent.metaKey;
296
+ let updatedIds = [];
297
+ if (!selectMultiple && !selectAdditional) {
298
+ return setSelectedIds([clickedId]);
299
+ }
300
+ if (selectMultiple) {
301
+ nativeEvent.preventDefault();
302
+ }
303
+ if (selectMultiple && !isSelected) {
304
+ const lastSelectedId = selectedIds[selectedIds.length - 1];
305
+ const lastSelectedIndex = orderedData.findIndex(item => item._id === lastSelectedId);
306
+ const firstSelected = index < lastSelectedIndex ? index : lastSelectedIndex;
307
+ const lastSelected = index > lastSelectedIndex ? index : lastSelectedIndex;
308
+ const betweenIds = orderedData.filter((item, itemIndex) => itemIndex > firstSelected && itemIndex < lastSelected).map(item => item._id);
309
+ updatedIds = [...selectedIds, ...betweenIds, clickedId];
310
+ } else if (isSelected) {
311
+ updatedIds = selectedIds.filter(id => id !== clickedId);
312
+ } else {
313
+ updatedIds = [...selectedIds, clickedId];
314
+ }
315
+ return setSelectedIds(updatedIds);
316
+ }, [setSelectedIds, orderedData, selectedIds]);
317
+ const client = useSanityClient();
318
+ const transactPatches = React.useCallback(async (patches, message) => {
319
+ const transaction = client.transaction();
320
+ patches.forEach(_ref5 => {
321
+ let [docId, ops] = _ref5;
322
+ return transaction.patch(docId, ops);
323
+ });
324
+ await transaction.commit().then(updated => {
325
+ clearSelected();
326
+ setDraggingId("");
327
+ setListIsUpdating(false);
328
+ toast.push({
329
+ title: "".concat(updated.results.length === 1 ? "1 Document" : "".concat(updated.results.length, " Documents"), " Reordered"),
330
+ status: "success",
331
+ description: message
332
+ });
333
+ }).catch(() => {
334
+ setDraggingId("");
335
+ setListIsUpdating(false);
336
+ toast.push({
337
+ title: "Reordering failed",
338
+ status: "error"
339
+ });
340
+ });
341
+ }, [client, setDraggingId, clearSelected, setListIsUpdating, toast]);
342
+ const handleDragEnd = React.useCallback((result, entities) => {
343
+ setDraggingId("");
344
+ const {
345
+ source,
346
+ destination,
347
+ draggableId
348
+ } = result != null ? result : {};
349
+ if ((source == null ? void 0 : source.index) === (destination == null ? void 0 : destination.index)) return;
350
+ if (!(entities == null ? void 0 : entities.length) || !draggableId) return;
351
+ const effectedIds = (selectedIds == null ? void 0 : selectedIds.length) ? selectedIds : [draggableId];
352
+ if (!(effectedIds == null ? void 0 : effectedIds.length)) return;
353
+ setListIsUpdating(true);
354
+ setSelectedIds(effectedIds);
355
+ const {
356
+ newOrder,
357
+ patches,
358
+ message
359
+ } = reorderDocuments({
360
+ entities,
361
+ selectedIds: effectedIds,
362
+ source,
363
+ destination
364
+ });
365
+ if (newOrder == null ? void 0 : newOrder.length) {
366
+ setOrderedData(newOrder);
367
+ }
368
+ if (patches == null ? void 0 : patches.length) {
369
+ transactPatches(patches, message);
370
+ }
371
+ }, [selectedIds, setDraggingId, setSelectedIds, transactPatches, setListIsUpdating]);
372
+ const handleDragStart = React.useCallback(start => {
373
+ const id = start.draggableId;
374
+ const selected = selectedIds.includes(id);
375
+ if (!selected) clearSelected();
376
+ setDraggingId(id);
377
+ }, [selectedIds, clearSelected, setDraggingId]);
378
+ const incrementIndex = React.useCallback((shiftFrom, shiftTo, id, entities) => {
379
+ const result = {
380
+ draggableId: id,
381
+ source: {
382
+ index: shiftFrom
383
+ },
384
+ destination: {
385
+ index: shiftTo
386
+ }
387
+ };
388
+ return handleDragEnd(result, entities);
389
+ }, [handleDragEnd]);
390
+ const onWindowKeyDown = React.useCallback(event => {
391
+ if (event.key === "Escape") {
392
+ clearSelected();
393
+ }
394
+ }, [clearSelected]);
395
+ React.useEffect(() => {
396
+ window.addEventListener("keydown", onWindowKeyDown);
397
+ return () => {
398
+ window.removeEventListener("keydown", onWindowKeyDown);
399
+ };
400
+ }, [onWindowKeyDown]);
401
+ const duplicateOrders = React.useMemo(() => {
402
+ if (!orderedData.length) return [];
403
+ const orderField = orderedData.map(item => item[ORDER_FIELD_NAME]);
404
+ return orderField.filter((item, index) => orderField.indexOf(item) !== index);
405
+ }, [orderedData]);
406
+ const onDragEnd = React.useCallback(result => handleDragEnd(result, orderedData), [orderedData, handleDragEnd]);
407
+ return /* @__PURE__ */jsxRuntime.jsx(dnd.DragDropContext, {
408
+ onDragStart: handleDragStart,
409
+ onDragEnd,
410
+ children: /* @__PURE__ */jsxRuntime.jsx(dnd.Droppable, {
411
+ droppableId: "documentSortZone",
412
+ children: provided => /* @__PURE__ */jsxRuntime.jsxs("div", {
413
+ ...provided.droppableProps,
414
+ ref: provided.innerRef,
415
+ children: [orderedData.map((item, index) => /* @__PURE__ */jsxRuntime.jsx(dnd.Draggable, {
416
+ draggableId: item._id,
417
+ index,
418
+ children: (innerProvided, innerSnapshot) => {
419
+ const isSelected = selectedIds.includes(item._id);
420
+ const isDragging = innerSnapshot.isDragging;
421
+ const isGhosting = Boolean(!isDragging && draggingId && isSelected);
422
+ const isUpdating = listIsUpdating && isSelected;
423
+ const isDisabled = Boolean(!item[ORDER_FIELD_NAME]);
424
+ const isDuplicate = duplicateOrders.includes(item[ORDER_FIELD_NAME]);
425
+ const tone = cardTone({
426
+ isDuplicate,
427
+ isGhosting,
428
+ isDragging,
429
+ isSelected
430
+ });
431
+ const selectedCount = selectedIds.length;
432
+ const dragBadge = isDragging && selectedCount > 1 ? selectedCount : false;
433
+ return /* @__PURE__ */jsxRuntime.jsx("div", {
434
+ ref: innerProvided.innerRef,
435
+ ...innerProvided.draggableProps,
436
+ ...innerProvided.dragHandleProps,
437
+ style: isDisabled ? {
438
+ opacity: 0.2,
439
+ pointerEvents: "none"
440
+ } : getItemStyle(innerProvided.draggableProps.style, isUpdating),
441
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
442
+ paddingBottom: 1,
443
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
444
+ tone,
445
+ shadow: isDragging ? 2 : void 0,
446
+ radius: 2,
447
+ onClick: e => handleSelect(item._id, index, e.nativeEvent),
448
+ children: /* @__PURE__ */jsxRuntime.jsx(Document, {
449
+ doc: item,
450
+ entities: orderedData,
451
+ increment: incrementIndex,
452
+ index,
453
+ isFirst: index === 0,
454
+ isLast: index === orderedData.length - 1,
455
+ dragBadge
456
+ })
457
+ })
458
+ })
459
+ });
460
+ }
461
+ }, "".concat(item._id, "-").concat(item[ORDER_FIELD_NAME]))), provided.placeholder]
462
+ })
463
+ })
464
+ });
465
+ }
466
+ const DEFAULT_PARAMS = {};
467
+ function DocumentListQuery(_ref6) {
468
+ let {
469
+ type,
470
+ filter,
471
+ params = DEFAULT_PARAMS
472
+ } = _ref6;
473
+ const [listIsUpdating, setListIsUpdating] = React.useState(false);
474
+ const [data, setData] = React.useState([]);
475
+ const query = "*[_type == $type ".concat(filter ? "&& ".concat(filter) : "", "]|order(@[$order] asc){\n _id, _type, ").concat(ORDER_FIELD_NAME, "\n }");
476
+ const queryParams = {
477
+ ...params,
478
+ type,
479
+ order: ORDER_FIELD_NAME
480
+ };
481
+ const {
482
+ data: queryData,
483
+ loading,
484
+ error
485
+ } = sanityPluginUtils.useListeningQuery(query, {
486
+ params: queryParams,
487
+ initialValue: []
488
+ });
489
+ React.useEffect(() => {
490
+ if (queryData) {
491
+ const filteredDocuments = queryData.reduce((acc, cur) => {
492
+ if (!cur._id.startsWith("drafts.")) {
493
+ const alsoHasDraft = queryData.some(doc => doc._id === "drafts.".concat(cur._id));
494
+ return alsoHasDraft ? acc : [...acc, cur];
495
+ }
496
+ cur.hasPublished = queryData.some(doc => doc._id === cur._id.replace("drafts.", ""));
497
+ return [...acc, cur];
498
+ }, []);
499
+ setData(filteredDocuments);
500
+ } else {
501
+ setData([]);
502
+ }
503
+ }, [queryData]);
504
+ const unorderedDataCount = React.useMemo(() => (data == null ? void 0 : data.length) ? data.filter(doc => !doc[ORDER_FIELD_NAME]).length : 0, [data]);
505
+ if (loading) {
506
+ return /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
507
+ style: {
508
+ width: "100%",
509
+ height: "100%"
510
+ },
511
+ align: "center",
512
+ justify: "center",
513
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {})
514
+ });
515
+ }
516
+ if (error) {
517
+ return /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
518
+ padding: 2,
519
+ children: /* @__PURE__ */jsxRuntime.jsx(sanityPluginUtils.Feedback, {
520
+ tone: "critical",
521
+ title: "There was an error",
522
+ description: "Please try again later"
523
+ })
524
+ });
525
+ }
526
+ if (!data || (data == null ? void 0 : data.length) == 0) return /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
527
+ align: "center",
528
+ direction: "column",
529
+ height: "fill",
530
+ justify: "center",
531
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Container, {
532
+ width: 1,
533
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
534
+ paddingX: 4,
535
+ paddingY: 5,
536
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
537
+ align: "center",
538
+ muted: true,
539
+ children: "No documents of this type"
540
+ })
541
+ })
542
+ })
543
+ });
544
+ return /* @__PURE__ */jsxRuntime.jsx(ui.Stack, {
545
+ space: 1,
546
+ style: {
547
+ overflow: "auto",
548
+ height: "100%"
549
+ },
550
+ children: /* @__PURE__ */jsxRuntime.jsxs(ui.Box, {
551
+ padding: 2,
552
+ children: [unorderedDataCount > 0 && /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
553
+ marginBottom: 2,
554
+ children: /* @__PURE__ */jsxRuntime.jsx(sanityPluginUtils.Feedback, {
555
+ tone: "caution",
556
+ description: /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
557
+ children: [unorderedDataCount, "/", data == null ? void 0 : data.length, " documents have no order. Select", " ", /* @__PURE__ */jsxRuntime.jsx("strong", {
558
+ children: "Reset Order"
559
+ }), " from the menu above to fix."]
560
+ })
561
+ })
562
+ }), /* @__PURE__ */jsxRuntime.jsx(DraggableList, {
563
+ data,
564
+ listIsUpdating,
565
+ setListIsUpdating
566
+ })]
567
+ })
568
+ });
569
+ }
570
+ function DocumentListWrapper(_ref7) {
571
+ let {
572
+ type,
573
+ showIncrements,
574
+ resetOrderTransaction,
575
+ filter,
576
+ params
577
+ } = _ref7;
578
+ const toast = ui.useToast();
579
+ const schema = sanity.useSchema();
580
+ React.useEffect(() => {
581
+ if ((resetOrderTransaction == null ? void 0 : resetOrderTransaction.title) && (resetOrderTransaction == null ? void 0 : resetOrderTransaction.status)) {
582
+ toast.push(resetOrderTransaction);
583
+ }
584
+ }, [resetOrderTransaction, toast]);
585
+ const schemaIsInvalid = React.useMemo(() => {
586
+ if (!type) {
587
+ return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
588
+ children: ["No ", /* @__PURE__ */jsxRuntime.jsx("code", {
589
+ children: "type"
590
+ }), " was configured"]
591
+ });
592
+ }
593
+ const typeSchema = schema.get(type);
594
+ if (!typeSchema) {
595
+ return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
596
+ children: ["Schema ", /* @__PURE__ */jsxRuntime.jsx("code", {
597
+ children: type
598
+ }), " not found"]
599
+ });
600
+ }
601
+ if (!("fields" in typeSchema) || !typeSchema.fields.some(field => (field == null ? void 0 : field.name) === ORDER_FIELD_NAME)) {
602
+ return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
603
+ children: ["Schema ", /* @__PURE__ */jsxRuntime.jsx("code", {
604
+ children: type
605
+ }), " must have an ", /* @__PURE__ */jsxRuntime.jsx("code", {
606
+ children: ORDER_FIELD_NAME
607
+ }), " field of type", " ", /* @__PURE__ */jsxRuntime.jsx("code", {
608
+ children: "string"
609
+ })]
610
+ });
611
+ }
612
+ if ("fields" in typeSchema && typeSchema.fields.some(field => {
613
+ var _a;
614
+ return (field == null ? void 0 : field.name) === ORDER_FIELD_NAME && ((_a = field == null ? void 0 : field.type) == null ? void 0 : _a.name) !== "string";
615
+ })) {
616
+ return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
617
+ children: [/* @__PURE__ */jsxRuntime.jsx("code", {
618
+ children: ORDER_FIELD_NAME
619
+ }), " field on Schema ", /* @__PURE__ */jsxRuntime.jsx("code", {
620
+ children: type
621
+ }), " must be", " ", /* @__PURE__ */jsxRuntime.jsx("code", {
622
+ children: "string"
623
+ }), " type"]
624
+ });
625
+ }
626
+ return "";
627
+ }, [type, schema]);
628
+ if (schemaIsInvalid) {
629
+ return /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
630
+ padding: 2,
631
+ children: /* @__PURE__ */jsxRuntime.jsx(sanityPluginUtils.Feedback, {
632
+ description: schemaIsInvalid,
633
+ tone: "caution"
634
+ })
635
+ });
636
+ }
637
+ return /* @__PURE__ */jsxRuntime.jsx(OrderableContext.Provider, {
638
+ value: {
639
+ showIncrements
640
+ },
641
+ children: /* @__PURE__ */jsxRuntime.jsx(DocumentListQuery, {
642
+ type,
643
+ filter,
644
+ params
645
+ })
646
+ });
647
+ }
648
+ async function resetOrder() {
649
+ let type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
650
+ let client = arguments.length > 1 ? arguments[1] : undefined;
651
+ const query = "*[_type == $type]|order(@[$order] asc)._id";
652
+ const queryParams = {
653
+ type,
654
+ order: ORDER_FIELD_NAME
655
+ };
656
+ const documents = await client.fetch(query, queryParams);
657
+ if (!documents.length) {
658
+ return null;
659
+ }
660
+ const transaction = client.transaction();
661
+ let aLexoRank = lexorank.LexoRank.min();
662
+ for (let index = 0; index < documents.length; index += 1) {
663
+ aLexoRank = aLexoRank.genNext().genNext();
664
+ transaction.patch(documents[index], {
665
+ set: {
666
+ [ORDER_FIELD_NAME]: aLexoRank.toString()
667
+ }
668
+ });
669
+ }
670
+ return transaction.commit().then(update => update).catch(err => err);
671
+ }
672
+ var __defProp = Object.defineProperty;
673
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
674
+ enumerable: true,
675
+ configurable: true,
676
+ writable: true,
677
+ value
678
+ }) : obj[key] = value;
679
+ var __publicField = (obj, key, value) => {
680
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
681
+ return value;
682
+ };
683
+ class OrderableDocumentList extends React.Component {
684
+ constructor(props) {
685
+ super(props);
686
+ __publicField(this, "actionHandlers", {
687
+ showIncrements: () => {
688
+ this.setState(state => ({
689
+ showIncrements: !state.showIncrements
690
+ }));
691
+ },
692
+ resetOrder: async () => {
693
+ var _a;
694
+ this.setState(() => ({
695
+ resetOrderTransaction: {
696
+ status: "info",
697
+ title: "Reordering started...",
698
+ closable: true
699
+ }
700
+ }));
701
+ const update = await resetOrder(this.props.options.type, this.props.options.client);
702
+ const reorderWasSuccessful = (_a = update == null ? void 0 : update.results) == null ? void 0 : _a.length;
703
+ this.setState(() => ({
704
+ resetOrderTransaction: {
705
+ status: reorderWasSuccessful ? "success" : "info",
706
+ title: reorderWasSuccessful ? "Reordered ".concat(update.results.length === 1 ? "Document" : "Documents") : "Reordering failed",
707
+ closable: true
708
+ }
709
+ }));
710
+ }
711
+ });
712
+ this.state = {
713
+ showIncrements: false,
714
+ resetOrderTransaction: {}
715
+ };
716
+ }
717
+ render() {
718
+ var _a, _b, _c, _d, _e, _f;
719
+ const type = (_b = (_a = this == null ? void 0 : this.props) == null ? void 0 : _a.options) == null ? void 0 : _b.type;
720
+ if (!type) {
721
+ return null;
722
+ }
723
+ return /* @__PURE__ */jsxRuntime.jsx(DocumentListWrapper, {
724
+ filter: (_d = (_c = this == null ? void 0 : this.props) == null ? void 0 : _c.options) == null ? void 0 : _d.filter,
725
+ params: (_f = (_e = this == null ? void 0 : this.props) == null ? void 0 : _e.options) == null ? void 0 : _f.params,
726
+ type,
727
+ showIncrements: this.state.showIncrements,
728
+ resetOrderTransaction: this.state.resetOrderTransaction
729
+ });
730
+ }
731
+ }
732
+ function orderableDocumentListDeskItem(config) {
733
+ var _a, _b;
734
+ if (!(config == null ? void 0 : config.type) || !config.context || !config.S) {
735
+ throw new Error("\n type, context and S (StructureBuilder) must be provided.\n context and S are available when configuring structure.\n Example: orderableDocumentListDeskItem({type: 'category'})\n ");
736
+ }
737
+ const {
738
+ type,
739
+ filter,
740
+ menuItems = [],
741
+ createIntent,
742
+ params,
743
+ title,
744
+ icon,
745
+ id,
746
+ context,
747
+ S
748
+ } = config;
749
+ const {
750
+ schema,
751
+ getClient
752
+ } = context;
753
+ const client = getClient({
754
+ apiVersion: "2021-09-01"
755
+ });
756
+ const listTitle = title != null ? title : "Orderable ".concat(type);
757
+ const listId = id != null ? id : "orderable-".concat(type);
758
+ const listIcon = icon != null ? icon : icons.SortIcon;
759
+ const typeTitle = (_b = (_a = schema.get(type)) == null ? void 0 : _a.title) != null ? _b : type;
760
+ if (createIntent !== false) {
761
+ menuItems.push(S.menuItem().title("Create new ".concat(typeTitle)).intent({
762
+ type: "create",
763
+ params: {
764
+ type
765
+ }
766
+ }).serialize());
767
+ }
768
+ return S.listItem().title(listTitle).id(listId).icon(listIcon).child(Object.assign(S.documentTypeList(type).serialize(), {
769
+ // Prevents the component from re-rendering when switching documents
770
+ __preserveInstance: true,
771
+ // Prevents the component from NOT re-rendering when switching listItems
772
+ key: listId,
773
+ type: "component",
774
+ component: OrderableDocumentList,
775
+ options: {
776
+ type,
777
+ filter,
778
+ params,
779
+ client
780
+ },
781
+ menuItems: [...menuItems, S.menuItem().title("Reset Order").icon(icons.GenerateIcon).action("resetOrder").serialize(), S.menuItem().title("Toggle Increments").icon(icons.SortIcon).action("showIncrements").serialize()]
782
+ })).serialize();
783
+ }
784
+ exports.orderRankField = orderRankField;
785
+ exports.orderRankOrdering = orderRankOrdering;
786
+ exports.orderableDocumentListDeskItem = orderableDocumentListDeskItem;
787
+ //# sourceMappingURL=index.js.map