@sanity/orderable-document-list 1.2.2 → 1.3.0
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/LICENSE +1 -1
- package/lib/index.cjs +499 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +36 -0
- package/lib/index.d.ts +5 -13
- package/lib/index.js +428 -712
- package/lib/index.js.map +1 -1
- package/package.json +41 -40
- package/src/Document.tsx +4 -4
- package/src/DocumentListQuery.tsx +7 -9
- package/src/DocumentListWrapper.tsx +4 -5
- package/src/DraggableList.tsx +41 -44
- package/src/OrderableContext.ts +2 -2
- package/src/OrderableDocumentList.tsx +3 -3
- package/src/desk-structure/orderableDocumentListDeskItem.ts +5 -5
- package/src/fields/orderRankField.ts +10 -9
- package/src/fields/orderRankOrdering.ts +1 -1
- package/src/helpers/client.ts +2 -2
- package/src/helpers/initialRank.ts +2 -2
- package/src/helpers/reorderDocuments.ts +8 -8
- package/src/helpers/resetOrder.ts +17 -12
- package/lib/index.esm.js +0 -778
- package/lib/index.esm.js.map +0 -1
package/LICENSE
CHANGED
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
+
var sanity = require("sanity"), lexorank = require("lexorank"), icons = require("@sanity/icons"), jsxRuntime = require("react/jsx-runtime"), react = require("react"), ui = require("@sanity/ui"), sanityPluginUtils = require("sanity-plugin-utils"), dnd = require("@hello-pangea/dnd"), structure = require("sanity/structure");
|
|
4
|
+
const ORDER_FIELD_NAME = "orderRank", API_VERSION = "2021-09-01";
|
|
5
|
+
function initialRank(compareRankValue = "", newItemPosition = "after") {
|
|
6
|
+
const compareRank = compareRankValue ? lexorank.LexoRank.parse(compareRankValue) : lexorank.LexoRank.min();
|
|
7
|
+
return (newItemPosition === "before" ? compareRank.genPrev().genPrev() : compareRank.genNext().genNext()).toString();
|
|
8
|
+
}
|
|
9
|
+
const orderRankField = (config) => {
|
|
10
|
+
if (!config?.type)
|
|
11
|
+
throw new Error(
|
|
12
|
+
`
|
|
13
|
+
type must be provided.
|
|
14
|
+
Example: orderRankField({type: 'category'})
|
|
15
|
+
`
|
|
16
|
+
);
|
|
17
|
+
const { type, newItemPosition = "after", ...rest } = config;
|
|
18
|
+
return sanity.defineField({
|
|
19
|
+
title: "Order Rank",
|
|
20
|
+
readOnly: !0,
|
|
21
|
+
hidden: !0,
|
|
22
|
+
...rest,
|
|
23
|
+
name: ORDER_FIELD_NAME,
|
|
24
|
+
type: "string",
|
|
25
|
+
initialValue: async (p, { getClient }) => {
|
|
26
|
+
const direction = newItemPosition === "before" ? "asc" : "desc", lastDocOrderRank = await getClient({ apiVersion: API_VERSION }).fetch(
|
|
27
|
+
`*[_type == $type]|order(@[$order] ${direction})[0][$order]`,
|
|
28
|
+
{ type, order: ORDER_FIELD_NAME },
|
|
29
|
+
{ tag: "orderable-document-list.last-doc-order-rank" }
|
|
30
|
+
);
|
|
31
|
+
return initialRank(lastDocOrderRank, newItemPosition);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}, orderRankOrdering = {
|
|
35
|
+
title: "Ordered",
|
|
36
|
+
name: "ordered",
|
|
37
|
+
by: [{ field: ORDER_FIELD_NAME, direction: "asc" }]
|
|
38
|
+
}, OrderableContext = react.createContext({});
|
|
39
|
+
function Document({
|
|
40
|
+
doc,
|
|
41
|
+
increment,
|
|
42
|
+
entities,
|
|
43
|
+
index,
|
|
44
|
+
isFirst,
|
|
45
|
+
isLast,
|
|
46
|
+
dragBadge
|
|
47
|
+
}) {
|
|
48
|
+
const { showIncrements } = react.useContext(OrderableContext), schema = sanity.useSchema(), router = structure.usePaneRouter(), { ChildLink, groupIndex, routerPanesState } = router, currentDoc = routerPanesState[groupIndex + 1]?.[0]?.id || !1, pressed = currentDoc === doc._id || currentDoc === doc._id.replace("drafts.", ""), selected = pressed && routerPanesState.length === groupIndex + 2, Link = react.useMemo(
|
|
49
|
+
() => function(linkProps) {
|
|
50
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ChildLink, { ...linkProps, childId: doc._id });
|
|
51
|
+
},
|
|
52
|
+
[ChildLink, doc._id]
|
|
53
|
+
);
|
|
54
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
55
|
+
sanity.PreviewCard,
|
|
56
|
+
{
|
|
57
|
+
__unstable_focusRing: !0,
|
|
58
|
+
as: Link,
|
|
59
|
+
"data-as": "a",
|
|
60
|
+
"data-ui": "PaneItem",
|
|
61
|
+
radius: 2,
|
|
62
|
+
pressed,
|
|
63
|
+
selected,
|
|
64
|
+
sizing: "border",
|
|
65
|
+
tabIndex: -1,
|
|
66
|
+
tone: "inherit",
|
|
67
|
+
width: "100%",
|
|
68
|
+
flex: 1,
|
|
69
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", children: [
|
|
70
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Box, { paddingX: 2, style: { flexShrink: 0 }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 2, children: /* @__PURE__ */ jsxRuntime.jsx(icons.DragHandleIcon, { cursor: "grab" }) }) }),
|
|
71
|
+
showIncrements && /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { style: { flexShrink: 0 }, align: "center", gap: 1, paddingRight: 1, children: [
|
|
72
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
73
|
+
ui.Button,
|
|
74
|
+
{
|
|
75
|
+
padding: 2,
|
|
76
|
+
mode: "ghost",
|
|
77
|
+
onClick: () => increment(index, index + -1, doc._id, entities),
|
|
78
|
+
disabled: isFirst,
|
|
79
|
+
icon: icons.ChevronUpIcon
|
|
80
|
+
}
|
|
81
|
+
),
|
|
82
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
83
|
+
ui.Button,
|
|
84
|
+
{
|
|
85
|
+
padding: 2,
|
|
86
|
+
mode: "ghost",
|
|
87
|
+
disabled: isLast,
|
|
88
|
+
onClick: () => increment(index, index + 1, doc._id, entities),
|
|
89
|
+
icon: icons.ChevronDownIcon
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
] }),
|
|
93
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { width: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { flex: 1, align: "center", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
94
|
+
sanity.Preview,
|
|
95
|
+
{
|
|
96
|
+
layout: "default",
|
|
97
|
+
value: doc,
|
|
98
|
+
schemaType: schema.get(doc._type)
|
|
99
|
+
}
|
|
100
|
+
) }) }),
|
|
101
|
+
dragBadge && /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { tone: "default", marginRight: 4, radius: 5, children: /* @__PURE__ */ jsxRuntime.jsx(ui.AvatarCounter, { count: dragBadge }) })
|
|
102
|
+
] })
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
function lexicographicalSort(a, b) {
|
|
107
|
+
return !a[ORDER_FIELD_NAME] || !b[ORDER_FIELD_NAME] ? 0 : a[ORDER_FIELD_NAME] < b[ORDER_FIELD_NAME] ? -1 : a[ORDER_FIELD_NAME] > b[ORDER_FIELD_NAME] ? 1 : 0;
|
|
108
|
+
}
|
|
109
|
+
const reorderDocuments = ({
|
|
110
|
+
entities,
|
|
111
|
+
selectedIds,
|
|
112
|
+
source,
|
|
113
|
+
destination
|
|
114
|
+
}) => {
|
|
115
|
+
const startIndex = source.index, endIndex = destination.index, isMovingUp = startIndex > endIndex, selectedItems = entities.filter((item) => selectedIds.includes(item._id)), message = [
|
|
116
|
+
"Moved",
|
|
117
|
+
selectedItems.length === 1 ? "1 document" : `${selectedItems.length} documents`,
|
|
118
|
+
isMovingUp ? "up" : "down",
|
|
119
|
+
"from position",
|
|
120
|
+
`${startIndex + 1} to ${endIndex + 1}`
|
|
121
|
+
].join(" "), { all, selected } = entities.reduce(
|
|
122
|
+
(acc, cur, curIndex) => {
|
|
123
|
+
if (selectedIds.includes(cur._id))
|
|
124
|
+
return { all: acc.all, selected: acc.selected };
|
|
125
|
+
if (curIndex === endIndex) {
|
|
126
|
+
const prevIndex = curIndex - 1, prevRank = entities[prevIndex]?.[ORDER_FIELD_NAME] ? lexorank.LexoRank.parse(entities[prevIndex]?.[ORDER_FIELD_NAME]) : lexorank.LexoRank.min(), curRank = lexorank.LexoRank.parse(entities[curIndex][ORDER_FIELD_NAME]), nextIndex = curIndex + 1, nextRank = entities[nextIndex]?.[ORDER_FIELD_NAME] ? lexorank.LexoRank.parse(entities[nextIndex]?.[ORDER_FIELD_NAME]) : lexorank.LexoRank.max();
|
|
127
|
+
let betweenRank = isMovingUp ? prevRank.between(curRank) : curRank.between(nextRank);
|
|
128
|
+
for (let selectedIndex = 0; selectedIndex < selectedItems.length; selectedIndex += 1)
|
|
129
|
+
selectedItems[selectedIndex][ORDER_FIELD_NAME] = betweenRank.toString(), betweenRank = isMovingUp ? betweenRank.between(curRank) : betweenRank.between(nextRank);
|
|
130
|
+
return {
|
|
131
|
+
// The `all` array gets sorted by order field later anyway
|
|
132
|
+
// so that this probably isn't necessary ¯\_(ツ)_/¯
|
|
133
|
+
all: isMovingUp ? [...acc.all, ...selectedItems, cur] : [...acc.all, cur, ...selectedItems],
|
|
134
|
+
selected: selectedItems
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return { all: [...acc.all, cur], selected: acc.selected };
|
|
138
|
+
},
|
|
139
|
+
{ all: [], selected: [] }
|
|
140
|
+
), patches = selected.flatMap((doc) => {
|
|
141
|
+
const docPatches = [
|
|
142
|
+
[
|
|
143
|
+
doc._id,
|
|
144
|
+
{
|
|
145
|
+
set: {
|
|
146
|
+
[ORDER_FIELD_NAME]: doc[ORDER_FIELD_NAME]
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
];
|
|
151
|
+
return doc._id.startsWith("drafts.") && doc.hasPublished && docPatches.push([
|
|
152
|
+
doc._id.replace("drafts.", ""),
|
|
153
|
+
{
|
|
154
|
+
set: {
|
|
155
|
+
[ORDER_FIELD_NAME]: doc[ORDER_FIELD_NAME]
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
]), docPatches;
|
|
159
|
+
});
|
|
160
|
+
return { newOrder: all.sort(lexicographicalSort), patches, message };
|
|
161
|
+
};
|
|
162
|
+
function useSanityClient() {
|
|
163
|
+
return sanity.useClient({ apiVersion: API_VERSION });
|
|
164
|
+
}
|
|
165
|
+
const getItemStyle = (draggableStyle, itemIsUpdating) => ({
|
|
166
|
+
userSelect: "none",
|
|
167
|
+
transition: "opacity 500ms ease-in-out",
|
|
168
|
+
opacity: itemIsUpdating ? 0.2 : 1,
|
|
169
|
+
pointerEvents: itemIsUpdating ? "none" : void 0,
|
|
170
|
+
...draggableStyle
|
|
171
|
+
}), cardTone = (settings) => {
|
|
172
|
+
const { isDuplicate, isGhosting, isDragging, isSelected } = settings;
|
|
173
|
+
if (isGhosting) return "transparent";
|
|
174
|
+
if (isDragging || isSelected) return "primary";
|
|
175
|
+
if (isDuplicate) return "caution";
|
|
176
|
+
};
|
|
177
|
+
function DraggableList({ data, listIsUpdating, setListIsUpdating }) {
|
|
178
|
+
const toast = ui.useToast(), router = structure.usePaneRouter(), { groupIndex, routerPanesState } = router, currentDoc = routerPanesState[groupIndex + 1]?.[0]?.id || !1, [orderedData, setOrderedData] = react.useState(data);
|
|
179
|
+
react.useEffect(() => {
|
|
180
|
+
listIsUpdating || setOrderedData(data);
|
|
181
|
+
}, [data]);
|
|
182
|
+
const [draggingId, setDraggingId] = react.useState(""), [selectedIds, setSelectedIds] = react.useState(currentDoc ? [currentDoc] : []), clearSelected = react.useCallback(() => setSelectedIds([]), [setSelectedIds]), handleSelect = react.useCallback(
|
|
183
|
+
(clickedId, index, nativeEvent) => {
|
|
184
|
+
const isSelected = selectedIds.includes(clickedId), selectMultiple = nativeEvent.shiftKey, selectAdditional = navigator.appVersion.indexOf("Win") !== -1 ? nativeEvent.ctrlKey : nativeEvent.metaKey;
|
|
185
|
+
let updatedIds = [];
|
|
186
|
+
if (!selectMultiple && !selectAdditional)
|
|
187
|
+
return setSelectedIds([clickedId]);
|
|
188
|
+
if (selectMultiple && nativeEvent.preventDefault(), selectMultiple && !isSelected) {
|
|
189
|
+
const lastSelectedId = selectedIds[selectedIds.length - 1], lastSelectedIndex = orderedData.findIndex((item) => item._id === lastSelectedId), firstSelected = index < lastSelectedIndex ? index : lastSelectedIndex, lastSelected = index > lastSelectedIndex ? index : lastSelectedIndex, betweenIds = orderedData.filter((item, itemIndex) => itemIndex > firstSelected && itemIndex < lastSelected).map((item) => item._id);
|
|
190
|
+
updatedIds = [...selectedIds, ...betweenIds, clickedId];
|
|
191
|
+
} else isSelected ? updatedIds = selectedIds.filter((id) => id !== clickedId) : updatedIds = [...selectedIds, clickedId];
|
|
192
|
+
return setSelectedIds(updatedIds);
|
|
193
|
+
},
|
|
194
|
+
[setSelectedIds, orderedData, selectedIds]
|
|
195
|
+
), client = useSanityClient(), transactPatches = react.useCallback(
|
|
196
|
+
async (patches, message) => {
|
|
197
|
+
const transaction = client.transaction();
|
|
198
|
+
patches.forEach(([docId, ops]) => transaction.patch(docId, ops));
|
|
199
|
+
try {
|
|
200
|
+
const updated = await transaction.commit({
|
|
201
|
+
visibility: "async",
|
|
202
|
+
tag: "orderable-document-list.reorder"
|
|
203
|
+
});
|
|
204
|
+
clearSelected(), setDraggingId(""), setListIsUpdating(!1), toast.push({
|
|
205
|
+
title: `${updated.results.length === 1 ? "1 document" : `${updated.results.length} documents`} reordered`,
|
|
206
|
+
status: "success",
|
|
207
|
+
description: message
|
|
208
|
+
});
|
|
209
|
+
} catch {
|
|
210
|
+
setDraggingId(""), setListIsUpdating(!1), toast.push({
|
|
211
|
+
title: "Reordering failed",
|
|
212
|
+
status: "error"
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
[client, setDraggingId, clearSelected, setListIsUpdating, toast]
|
|
217
|
+
), handleDragEnd = react.useCallback(
|
|
218
|
+
(result, entities) => {
|
|
219
|
+
setDraggingId("");
|
|
220
|
+
const { source, destination, draggableId } = result ?? {};
|
|
221
|
+
if (source?.index === destination?.index || !entities?.length || !draggableId) return;
|
|
222
|
+
const effectedIds = selectedIds?.length ? selectedIds : [draggableId];
|
|
223
|
+
if (!effectedIds?.length) return;
|
|
224
|
+
setListIsUpdating(!0), setSelectedIds(effectedIds);
|
|
225
|
+
const { newOrder, patches, message } = reorderDocuments({
|
|
226
|
+
entities,
|
|
227
|
+
selectedIds: effectedIds,
|
|
228
|
+
source,
|
|
229
|
+
destination
|
|
230
|
+
});
|
|
231
|
+
newOrder?.length && setOrderedData(newOrder), patches?.length && transactPatches(patches, message);
|
|
232
|
+
},
|
|
233
|
+
[selectedIds, setDraggingId, setSelectedIds, transactPatches, setListIsUpdating]
|
|
234
|
+
), handleDragStart = react.useCallback(
|
|
235
|
+
(start) => {
|
|
236
|
+
const id = start.draggableId;
|
|
237
|
+
selectedIds.includes(id) || clearSelected(), setDraggingId(id);
|
|
238
|
+
},
|
|
239
|
+
[selectedIds, clearSelected, setDraggingId]
|
|
240
|
+
), incrementIndex = react.useCallback(
|
|
241
|
+
(shiftFrom, shiftTo, id, entities) => handleDragEnd({
|
|
242
|
+
draggableId: id,
|
|
243
|
+
source: { index: shiftFrom },
|
|
244
|
+
destination: { index: shiftTo }
|
|
245
|
+
}, entities),
|
|
246
|
+
[handleDragEnd]
|
|
247
|
+
), onWindowKeyDown = react.useCallback(
|
|
248
|
+
(event) => {
|
|
249
|
+
event.key === "Escape" && clearSelected();
|
|
250
|
+
},
|
|
251
|
+
[clearSelected]
|
|
252
|
+
);
|
|
253
|
+
react.useEffect(() => (window.addEventListener("keydown", onWindowKeyDown), () => {
|
|
254
|
+
window.removeEventListener("keydown", onWindowKeyDown);
|
|
255
|
+
}), [onWindowKeyDown]);
|
|
256
|
+
const duplicateOrders = react.useMemo(() => {
|
|
257
|
+
if (!orderedData.length) return [];
|
|
258
|
+
const orderField = orderedData.map((item) => item[ORDER_FIELD_NAME]);
|
|
259
|
+
return orderField.filter((item, index) => orderField.indexOf(item) !== index);
|
|
260
|
+
}, [orderedData]), onDragEnd = react.useCallback(
|
|
261
|
+
(result) => handleDragEnd(result, orderedData),
|
|
262
|
+
[orderedData, handleDragEnd]
|
|
263
|
+
);
|
|
264
|
+
return /* @__PURE__ */ jsxRuntime.jsx(dnd.DragDropContext, { onDragStart: handleDragStart, onDragEnd, children: /* @__PURE__ */ jsxRuntime.jsx(dnd.Droppable, { droppableId: "documentSortZone", children: (provided) => /* @__PURE__ */ jsxRuntime.jsxs("div", { ...provided.droppableProps, ref: provided.innerRef, children: [
|
|
265
|
+
orderedData.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
266
|
+
dnd.Draggable,
|
|
267
|
+
{
|
|
268
|
+
draggableId: item._id,
|
|
269
|
+
index,
|
|
270
|
+
children: (innerProvided, innerSnapshot) => {
|
|
271
|
+
const isSelected = selectedIds.includes(item._id), isDragging = innerSnapshot.isDragging, isGhosting = !!(!isDragging && draggingId && isSelected), isUpdating = listIsUpdating && isSelected, isDisabled = !item[ORDER_FIELD_NAME], isDuplicate = duplicateOrders.includes(item[ORDER_FIELD_NAME]), tone = cardTone({ isDuplicate, isGhosting, isDragging, isSelected }), selectedCount = selectedIds.length, dragBadge = isDragging && selectedCount > 1 ? selectedCount : !1;
|
|
272
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
273
|
+
"div",
|
|
274
|
+
{
|
|
275
|
+
ref: innerProvided.innerRef,
|
|
276
|
+
...innerProvided.draggableProps,
|
|
277
|
+
...innerProvided.dragHandleProps,
|
|
278
|
+
style: isDisabled ? { opacity: 0.2, pointerEvents: "none" } : getItemStyle(innerProvided.draggableProps.style, isUpdating),
|
|
279
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { paddingBottom: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
280
|
+
ui.Card,
|
|
281
|
+
{
|
|
282
|
+
tone,
|
|
283
|
+
shadow: isDragging ? 2 : void 0,
|
|
284
|
+
radius: 2,
|
|
285
|
+
onClick: (e) => handleSelect(item._id, index, e.nativeEvent),
|
|
286
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
287
|
+
Document,
|
|
288
|
+
{
|
|
289
|
+
doc: item,
|
|
290
|
+
entities: orderedData,
|
|
291
|
+
increment: incrementIndex,
|
|
292
|
+
index,
|
|
293
|
+
isFirst: index === 0,
|
|
294
|
+
isLast: index === orderedData.length - 1,
|
|
295
|
+
dragBadge
|
|
296
|
+
}
|
|
297
|
+
)
|
|
298
|
+
}
|
|
299
|
+
) })
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
`${item._id}-${item[ORDER_FIELD_NAME]}`
|
|
305
|
+
)),
|
|
306
|
+
provided.placeholder
|
|
307
|
+
] }) }) });
|
|
308
|
+
}
|
|
309
|
+
const DEFAULT_PARAMS = {};
|
|
310
|
+
function DocumentListQuery({ type, filter, params = DEFAULT_PARAMS }) {
|
|
311
|
+
const [listIsUpdating, setListIsUpdating] = react.useState(!1), [data, setData] = react.useState([]), query = `*[_type == $type ${filter ? `&& ${filter}` : ""}]|order(@[$order] asc){
|
|
312
|
+
_id, _type, ${ORDER_FIELD_NAME}
|
|
313
|
+
}`, queryParams = {
|
|
314
|
+
...params,
|
|
315
|
+
type,
|
|
316
|
+
order: ORDER_FIELD_NAME
|
|
317
|
+
}, {
|
|
318
|
+
data: _queryData,
|
|
319
|
+
loading,
|
|
320
|
+
error
|
|
321
|
+
} = sanityPluginUtils.useListeningQuery(query, {
|
|
322
|
+
params: queryParams,
|
|
323
|
+
initialValue: []
|
|
324
|
+
}), queryData = _queryData;
|
|
325
|
+
react.useEffect(() => {
|
|
326
|
+
if (queryData) {
|
|
327
|
+
const filteredDocuments = queryData.reduce((acc, cur) => cur._id.startsWith("drafts.") ? (cur.hasPublished = queryData.some((doc) => doc._id === cur._id.replace("drafts.", "")), [...acc, cur]) : queryData.some((doc) => doc._id === `drafts.${cur._id}`) ? acc : [...acc, cur], []);
|
|
328
|
+
setData(filteredDocuments);
|
|
329
|
+
} else
|
|
330
|
+
setData([]);
|
|
331
|
+
}, [queryData]);
|
|
332
|
+
const unorderedDataCount = react.useMemo(
|
|
333
|
+
() => data?.length ? data.filter((doc) => !doc[ORDER_FIELD_NAME]).length : 0,
|
|
334
|
+
[data]
|
|
335
|
+
);
|
|
336
|
+
return loading ? /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { style: { width: "100%", height: "100%" }, align: "center", justify: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, {}) }) : error ? /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(sanityPluginUtils.Feedback, { tone: "critical", title: "There was an error", description: "Please try again later" }) }) : !data || data?.length == 0 ? /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { align: "center", direction: "column", height: "fill", justify: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { width: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { paddingX: 4, paddingY: 5, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { align: "center", muted: !0, children: "No documents of this type" }) }) }) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 1, style: { overflow: "auto", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { padding: 2, children: [
|
|
337
|
+
unorderedDataCount > 0 && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginBottom: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
338
|
+
sanityPluginUtils.Feedback,
|
|
339
|
+
{
|
|
340
|
+
tone: "caution",
|
|
341
|
+
description: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
342
|
+
unorderedDataCount,
|
|
343
|
+
"/",
|
|
344
|
+
data?.length,
|
|
345
|
+
" documents have no order. Select",
|
|
346
|
+
" ",
|
|
347
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: "Reset Order" }),
|
|
348
|
+
" from the menu above to fix."
|
|
349
|
+
] })
|
|
350
|
+
}
|
|
351
|
+
) }),
|
|
352
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
353
|
+
DraggableList,
|
|
354
|
+
{
|
|
355
|
+
data,
|
|
356
|
+
listIsUpdating,
|
|
357
|
+
setListIsUpdating
|
|
358
|
+
}
|
|
359
|
+
)
|
|
360
|
+
] }) });
|
|
361
|
+
}
|
|
362
|
+
function DocumentListWrapper({
|
|
363
|
+
type,
|
|
364
|
+
showIncrements,
|
|
365
|
+
resetOrderTransaction,
|
|
366
|
+
filter,
|
|
367
|
+
params
|
|
368
|
+
}) {
|
|
369
|
+
const toast = ui.useToast(), schema = sanity.useSchema();
|
|
370
|
+
react.useEffect(() => {
|
|
371
|
+
resetOrderTransaction?.title && resetOrderTransaction?.status && toast.push(resetOrderTransaction);
|
|
372
|
+
}, [resetOrderTransaction, toast]);
|
|
373
|
+
const schemaIsInvalid = react.useMemo(() => {
|
|
374
|
+
if (!type)
|
|
375
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
376
|
+
"No ",
|
|
377
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: "type" }),
|
|
378
|
+
" was configured"
|
|
379
|
+
] });
|
|
380
|
+
const typeSchema = schema.get(type);
|
|
381
|
+
return typeSchema ? !("fields" in typeSchema) || !typeSchema.fields.some((field) => field?.name === ORDER_FIELD_NAME) ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
382
|
+
"Schema ",
|
|
383
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: type }),
|
|
384
|
+
" must have an ",
|
|
385
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: ORDER_FIELD_NAME }),
|
|
386
|
+
" field of type",
|
|
387
|
+
" ",
|
|
388
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: "string" })
|
|
389
|
+
] }) : "fields" in typeSchema && typeSchema.fields.some(
|
|
390
|
+
(field) => field?.name === ORDER_FIELD_NAME && field?.type?.name !== "string"
|
|
391
|
+
) ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
392
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: ORDER_FIELD_NAME }),
|
|
393
|
+
" field on Schema ",
|
|
394
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: type }),
|
|
395
|
+
" must be",
|
|
396
|
+
" ",
|
|
397
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: "string" }),
|
|
398
|
+
" type"
|
|
399
|
+
] }) : "" : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
400
|
+
"Schema ",
|
|
401
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: type }),
|
|
402
|
+
" not found"
|
|
403
|
+
] });
|
|
404
|
+
}, [type, schema]);
|
|
405
|
+
return schemaIsInvalid ? /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(sanityPluginUtils.Feedback, { description: schemaIsInvalid, tone: "caution" }) }) : /* @__PURE__ */ jsxRuntime.jsx(OrderableContext.Provider, { value: { showIncrements }, children: /* @__PURE__ */ jsxRuntime.jsx(DocumentListQuery, { type, filter, params }) });
|
|
406
|
+
}
|
|
407
|
+
async function resetOrder(type, client) {
|
|
408
|
+
const query = "*[_type == $type]|order(@[$order] asc)._id", queryParams = { type, order: ORDER_FIELD_NAME }, documentIds = await client.fetch(query, queryParams, {
|
|
409
|
+
tag: "orderable-document-list.reset-order"
|
|
410
|
+
});
|
|
411
|
+
if (documentIds.length === 0)
|
|
412
|
+
return null;
|
|
413
|
+
let aLexoRank = lexorank.LexoRank.min();
|
|
414
|
+
return documentIds.reduce((trx, documentId) => (aLexoRank = aLexoRank.genNext().genNext(), trx.patch(documentId, {
|
|
415
|
+
set: { [ORDER_FIELD_NAME]: aLexoRank.toString() }
|
|
416
|
+
})), client.transaction()).commit({
|
|
417
|
+
visibility: "async",
|
|
418
|
+
tag: "orderable-document-list.reset-order"
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
class OrderableDocumentList extends react.Component {
|
|
422
|
+
constructor(props) {
|
|
423
|
+
super(props), this.state = {
|
|
424
|
+
showIncrements: !1,
|
|
425
|
+
resetOrderTransaction: {}
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
actionHandlers = {
|
|
429
|
+
showIncrements: () => {
|
|
430
|
+
this.setState((state) => ({
|
|
431
|
+
showIncrements: !state.showIncrements
|
|
432
|
+
}));
|
|
433
|
+
},
|
|
434
|
+
resetOrder: async () => {
|
|
435
|
+
this.setState(() => ({
|
|
436
|
+
resetOrderTransaction: {
|
|
437
|
+
status: "info",
|
|
438
|
+
title: "Reordering started...",
|
|
439
|
+
closable: !0
|
|
440
|
+
}
|
|
441
|
+
}));
|
|
442
|
+
const update = await resetOrder(this.props.options.type, this.props.options.client), reorderWasSuccessful = update?.results?.length;
|
|
443
|
+
this.setState(() => ({
|
|
444
|
+
resetOrderTransaction: {
|
|
445
|
+
status: reorderWasSuccessful ? "success" : "info",
|
|
446
|
+
title: reorderWasSuccessful ? `Reordered ${update.results.length === 1 ? "Document" : "Documents"}` : "Reordering failed",
|
|
447
|
+
closable: !0
|
|
448
|
+
}
|
|
449
|
+
}));
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
render() {
|
|
453
|
+
const type = this?.props?.options?.type;
|
|
454
|
+
return type ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
455
|
+
DocumentListWrapper,
|
|
456
|
+
{
|
|
457
|
+
filter: this?.props?.options?.filter,
|
|
458
|
+
params: this?.props?.options?.params,
|
|
459
|
+
type,
|
|
460
|
+
showIncrements: this.state.showIncrements,
|
|
461
|
+
resetOrderTransaction: this.state.resetOrderTransaction
|
|
462
|
+
}
|
|
463
|
+
) : null;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
function orderableDocumentListDeskItem(config) {
|
|
467
|
+
if (!config?.type || !config.context || !config.S)
|
|
468
|
+
throw new Error(`
|
|
469
|
+
type, context and S (StructureBuilder) must be provided.
|
|
470
|
+
context and S are available when configuring structure.
|
|
471
|
+
Example: orderableDocumentListDeskItem({type: 'category'})
|
|
472
|
+
`);
|
|
473
|
+
const { type, filter, menuItems = [], createIntent, params, title, icon, id, context, S } = config, { schema, getClient } = context, client = getClient({ apiVersion: API_VERSION }), listTitle = title ?? `Orderable ${type}`, listId = id ?? `orderable-${type}`, listIcon = icon ?? icons.SortIcon, typeTitle = schema.get(type)?.title ?? type;
|
|
474
|
+
return createIntent !== !1 && menuItems.push(
|
|
475
|
+
S.menuItem().title(`Create new ${typeTitle}`).intent({ type: "create", params: { type } }).serialize()
|
|
476
|
+
), S.listItem().title(listTitle).id(listId).icon(listIcon).schemaType(type).child(
|
|
477
|
+
Object.assign(
|
|
478
|
+
S.documentTypeList(type).canHandleIntent(() => !!createIntent).serialize(),
|
|
479
|
+
{
|
|
480
|
+
// Prevents the component from re-rendering when switching documents
|
|
481
|
+
__preserveInstance: !0,
|
|
482
|
+
// Prevents the component from NOT re-rendering when switching listItems
|
|
483
|
+
key: listId,
|
|
484
|
+
type: "component",
|
|
485
|
+
component: OrderableDocumentList,
|
|
486
|
+
options: { type, filter, params, client },
|
|
487
|
+
menuItems: [
|
|
488
|
+
...menuItems,
|
|
489
|
+
S.menuItem().title("Reset Order").icon(icons.GenerateIcon).action("resetOrder").serialize(),
|
|
490
|
+
S.menuItem().title("Toggle Increments").icon(icons.SortIcon).action("showIncrements").serialize()
|
|
491
|
+
]
|
|
492
|
+
}
|
|
493
|
+
)
|
|
494
|
+
).serialize();
|
|
495
|
+
}
|
|
496
|
+
exports.orderRankField = orderRankField;
|
|
497
|
+
exports.orderRankOrdering = orderRankOrdering;
|
|
498
|
+
exports.orderableDocumentListDeskItem = orderableDocumentListDeskItem;
|
|
499
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/helpers/constants.ts","../src/helpers/initialRank.ts","../src/fields/orderRankField.ts","../src/fields/orderRankOrdering.ts","../src/OrderableContext.ts","../src/Document.tsx","../src/helpers/reorderDocuments.ts","../src/helpers/client.ts","../src/DraggableList.tsx","../src/DocumentListQuery.tsx","../src/DocumentListWrapper.tsx","../src/helpers/resetOrder.ts","../src/OrderableDocumentList.tsx","../src/desk-structure/orderableDocumentListDeskItem.ts"],"sourcesContent":["export const ORDER_FIELD_NAME = `orderRank` as const\n\nexport const API_VERSION = `2021-09-01` as const\n","import {LexoRank} from 'lexorank'\nimport {NewItemPosition} from '../types'\n\n// Use in initial value field by passing in the rank value of the last document\n// If not value passed, generate a sensibly low rank\nexport function initialRank(\n compareRankValue = ``,\n newItemPosition: NewItemPosition = 'after',\n): string {\n const compareRank = compareRankValue ? LexoRank.parse(compareRankValue) : LexoRank.min()\n const rank =\n newItemPosition === 'before' ? compareRank.genPrev().genPrev() : compareRank.genNext().genNext()\n\n return rank.toString()\n}\n","import {type ConfigContext, defineField, type StringDefinition} from 'sanity'\nimport {API_VERSION, ORDER_FIELD_NAME} from '../helpers/constants'\nimport {initialRank} from '../helpers/initialRank'\nimport type {NewItemPosition} from '../types'\n\nexport type SchemaContext = Omit<ConfigContext, 'schema' | 'currentUser' | 'client'>\n\nexport interface RankFieldConfig extends Omit<StringDefinition, 'name' | 'type' | 'initialValue'> {\n type: string\n newItemPosition?: NewItemPosition\n}\n\nexport const orderRankField = (config: RankFieldConfig): StringDefinition => {\n if (!config?.type) {\n throw new Error(\n `\n type must be provided.\n Example: orderRankField({type: 'category'})\n `,\n )\n }\n\n const {type, newItemPosition = 'after', ...rest} = config\n return defineField({\n title: 'Order Rank',\n readOnly: true,\n hidden: true,\n ...rest,\n name: ORDER_FIELD_NAME,\n type: 'string',\n initialValue: async (p, {getClient}) => {\n const direction = newItemPosition === 'before' ? 'asc' : 'desc'\n\n const lastDocOrderRank = await getClient({apiVersion: API_VERSION}).fetch(\n `*[_type == $type]|order(@[$order] ${direction})[0][$order]`,\n {type, order: ORDER_FIELD_NAME},\n {tag: 'orderable-document-list.last-doc-order-rank'},\n )\n return initialRank(lastDocOrderRank, newItemPosition)\n },\n })\n}\n","import type {SortOrdering} from 'sanity'\nimport {ORDER_FIELD_NAME} from '../helpers/constants'\n\nexport const orderRankOrdering: SortOrdering = {\n title: 'Ordered',\n name: 'ordered',\n by: [{field: ORDER_FIELD_NAME, direction: 'asc'}],\n}\n","import {createContext} from 'react'\n\nexport interface OrderableContextValue {\n showIncrements?: boolean\n}\n\nexport const OrderableContext = createContext<OrderableContextValue>({})\n","import {useContext, useMemo, type ReactNode} from 'react'\nimport {ChevronDownIcon, ChevronUpIcon, DragHandleIcon} from '@sanity/icons'\nimport {AvatarCounter, Card, Box, Button, Flex, Text} from '@sanity/ui'\nimport {useSchema, SchemaType, PreviewCard, Preview} from 'sanity'\nimport {usePaneRouter} from 'sanity/structure'\n\nimport {OrderableContext} from './OrderableContext'\nimport type {SanityDocumentWithOrder} from './types'\n\nexport interface DocumentProps {\n doc: SanityDocumentWithOrder\n entities: SanityDocumentWithOrder[]\n increment: (\n index: number,\n nextIndex: number,\n docId: string,\n entities: SanityDocumentWithOrder[],\n ) => void\n index: number\n isFirst: boolean\n isLast: boolean\n dragBadge: number | false\n}\n\nexport function Document({\n doc,\n increment,\n entities,\n index,\n isFirst,\n isLast,\n dragBadge,\n}: DocumentProps) {\n const {showIncrements} = useContext(OrderableContext)\n const schema = useSchema()\n const router = usePaneRouter()\n const {ChildLink, groupIndex, routerPanesState} = router\n\n const currentDoc = routerPanesState[groupIndex + 1]?.[0]?.id || false\n const pressed = currentDoc === doc._id || currentDoc === doc._id.replace(`drafts.`, ``)\n const selected = pressed && routerPanesState.length === groupIndex + 2\n\n const Link = useMemo(\n () =>\n function LinkComponent(linkProps: {children: ReactNode}) {\n return <ChildLink {...linkProps} childId={doc._id} />\n },\n [ChildLink, doc._id],\n )\n\n return (\n <PreviewCard\n __unstable_focusRing\n // @ts-expect-error\n as={Link}\n data-as=\"a\"\n data-ui=\"PaneItem\"\n radius={2}\n pressed={pressed}\n selected={selected}\n sizing=\"border\"\n tabIndex={-1}\n tone=\"inherit\"\n width=\"100%\"\n flex={1}\n >\n <Flex align=\"center\">\n <Box paddingX={2} style={{flexShrink: 0}}>\n <Text size={2}>\n <DragHandleIcon cursor=\"grab\" />\n </Text>\n </Box>\n {showIncrements && (\n <Flex style={{flexShrink: 0}} align=\"center\" gap={1} paddingRight={1}>\n <Button\n padding={2}\n mode=\"ghost\"\n // eslint-disable-next-line react/jsx-no-bind\n onClick={() => increment(index, index + -1, doc._id, entities)}\n disabled={isFirst}\n icon={ChevronUpIcon}\n />\n <Button\n padding={2}\n mode=\"ghost\"\n disabled={isLast}\n // eslint-disable-next-line react/jsx-no-bind\n onClick={() => increment(index, index + 1, doc._id, entities)}\n icon={ChevronDownIcon}\n />\n </Flex>\n )}\n <Box style={{width: `100%`}}>\n <Flex flex={1} align=\"center\">\n <Preview\n layout=\"default\"\n value={doc}\n schemaType={schema.get(doc._type) as SchemaType}\n />\n </Flex>\n </Box>\n {dragBadge && (\n <Card tone=\"default\" marginRight={4} radius={5}>\n <AvatarCounter count={dragBadge} />\n </Card>\n )}\n </Flex>\n </PreviewCard>\n )\n}\n","import {LexoRank} from 'lexorank'\nimport type {PatchOperations} from 'sanity'\n\nimport type {SanityDocumentWithOrder} from '../types'\nimport {ORDER_FIELD_NAME} from './constants'\n\nexport interface MaifestArgs {\n entities: SanityDocumentWithOrder[]\n selectedItems: SanityDocumentWithOrder[]\n isMovingUp: boolean\n curIndex: number\n nextIndex: number\n prevIndex: number\n}\n\nexport interface ReorderArgs {\n entities: SanityDocumentWithOrder[]\n selectedIds: string[]\n source: any\n destination: any\n}\n\nexport interface ReorderReturn {\n newOrder: SanityDocumentWithOrder[]\n patches: [string, PatchOperations][]\n message: any\n}\n\nfunction lexicographicalSort(a: SanityDocumentWithOrder, b: SanityDocumentWithOrder) {\n if (!a[ORDER_FIELD_NAME] || !b[ORDER_FIELD_NAME]) {\n return 0\n } else if (a[ORDER_FIELD_NAME] < b[ORDER_FIELD_NAME]) {\n return -1\n } else if (a[ORDER_FIELD_NAME] > b[ORDER_FIELD_NAME]) {\n return 1\n }\n return 0\n}\n\nexport const reorderDocuments = ({\n entities,\n selectedIds,\n source,\n destination,\n}: ReorderArgs): ReorderReturn => {\n const startIndex = source.index\n const endIndex = destination.index\n const isMovingUp = startIndex > endIndex\n const selectedItems = entities.filter((item) => selectedIds.includes(item._id))\n const message = [\n 'Moved',\n selectedItems.length === 1 ? '1 document' : `${selectedItems.length} documents`,\n isMovingUp ? 'up' : 'down',\n 'from position',\n `${startIndex + 1} to ${endIndex + 1}`,\n ].join(' ')\n\n const {all, selected} = entities.reduce<{\n all: SanityDocumentWithOrder[]\n selected: SanityDocumentWithOrder[]\n }>(\n (acc, cur, curIndex) => {\n // Selected items get spread in below, so skip them here\n if (selectedIds.includes(cur._id)) {\n return {all: acc.all, selected: acc.selected}\n }\n\n // Drop selected items in\n if (curIndex === endIndex) {\n const prevIndex = curIndex - 1\n const prevRank = entities[prevIndex]?.[ORDER_FIELD_NAME]\n ? LexoRank.parse(entities[prevIndex]?.[ORDER_FIELD_NAME] as string)\n : LexoRank.min()\n\n const curRank = LexoRank.parse(entities[curIndex][ORDER_FIELD_NAME] as string)\n\n const nextIndex = curIndex + 1\n const nextRank = entities[nextIndex]?.[ORDER_FIELD_NAME]\n ? LexoRank.parse(entities[nextIndex]?.[ORDER_FIELD_NAME] as string)\n : LexoRank.max()\n\n let betweenRank = isMovingUp ? prevRank.between(curRank) : curRank.between(nextRank)\n\n // For each selected item, assign a new orderRank between now and next\n for (let selectedIndex = 0; selectedIndex < selectedItems.length; selectedIndex += 1) {\n selectedItems[selectedIndex][ORDER_FIELD_NAME] = betweenRank.toString()\n betweenRank = isMovingUp ? betweenRank.between(curRank) : betweenRank.between(nextRank)\n }\n\n return {\n // The `all` array gets sorted by order field later anyway\n // so that this probably isn't necessary ¯\\_(ツ)_/¯\n all: isMovingUp\n ? [...acc.all, ...selectedItems, cur]\n : [...acc.all, cur, ...selectedItems],\n selected: selectedItems,\n }\n }\n\n return {all: [...acc.all, cur], selected: acc.selected}\n },\n {all: [], selected: []},\n )\n\n const patches = selected.flatMap((doc) => {\n const docPatches: [string, PatchOperations][] = [\n [\n doc._id,\n {\n set: {\n [ORDER_FIELD_NAME]: doc[ORDER_FIELD_NAME],\n },\n },\n ],\n ]\n\n // If it's a draft, we need to patch the published document as well\n if (doc._id.startsWith('drafts.') && doc.hasPublished) {\n docPatches.push([\n doc._id.replace('drafts.', ''),\n {\n set: {\n [ORDER_FIELD_NAME]: doc[ORDER_FIELD_NAME],\n },\n },\n ])\n }\n\n return docPatches\n })\n\n // Safety-check to make sure everything is in order\n const allSorted = all.sort(lexicographicalSort)\n\n return {newOrder: allSorted, patches, message}\n}\n","import {type SanityClient, useClient} from 'sanity'\nimport {API_VERSION} from './constants'\n\nexport function useSanityClient(): SanityClient {\n return useClient({apiVersion: API_VERSION})\n}\n","import {useEffect, useState, useMemo, useCallback, type CSSProperties} from 'react'\nimport {DragDropContext, Draggable, Droppable, type DropResult} from '@hello-pangea/dnd'\nimport {Box, Card, useToast} from '@sanity/ui'\nimport type {PatchOperations} from 'sanity'\nimport {usePaneRouter} from 'sanity/structure'\n\nimport {Document} from './Document'\nimport {reorderDocuments} from './helpers/reorderDocuments'\nimport {ORDER_FIELD_NAME} from './helpers/constants'\nimport {useSanityClient} from './helpers/client'\nimport type {SanityDocumentWithOrder} from './types'\n\ninterface ListSetting {\n isDuplicate: boolean\n isGhosting: boolean\n isDragging: boolean\n isSelected: boolean\n}\n\nexport interface DraggableListProps {\n data: SanityDocumentWithOrder[]\n listIsUpdating: boolean\n setListIsUpdating: (val: boolean) => void\n}\n\nconst getItemStyle = (\n draggableStyle: CSSProperties | undefined,\n itemIsUpdating: boolean,\n): CSSProperties => ({\n userSelect: 'none',\n transition: 'opacity 500ms ease-in-out',\n opacity: itemIsUpdating ? 0.2 : 1,\n pointerEvents: itemIsUpdating ? 'none' : undefined,\n ...draggableStyle,\n})\n\nconst cardTone = (settings: ListSetting) => {\n const {isDuplicate, isGhosting, isDragging, isSelected} = settings\n\n if (isGhosting) return 'transparent'\n if (isDragging || isSelected) return 'primary'\n if (isDuplicate) return 'caution'\n\n return undefined\n}\n\nexport function DraggableList({data, listIsUpdating, setListIsUpdating}: DraggableListProps) {\n const toast = useToast()\n const router = usePaneRouter()\n const {groupIndex, routerPanesState} = router\n\n const currentDoc = routerPanesState[groupIndex + 1]?.[0]?.id || false\n\n // Maintains local state order before transaction completes\n const [orderedData, setOrderedData] = useState<SanityDocumentWithOrder[]>(data)\n\n // Update local state when documents change from an outside source\n useEffect(() => {\n if (!listIsUpdating) setOrderedData(data)\n /* eslint-disable-next-line react-hooks/exhaustive-deps */\n }, [data])\n\n const [draggingId, setDraggingId] = useState('')\n const [selectedIds, setSelectedIds] = useState<string[]>(currentDoc ? [currentDoc] : [])\n\n const clearSelected = useCallback(() => setSelectedIds([]), [setSelectedIds])\n\n const handleSelect = useCallback(\n (clickedId: string, index: number, nativeEvent: MouseEvent) => {\n const isSelected = selectedIds.includes(clickedId)\n const selectMultiple = nativeEvent.shiftKey\n const isUsingWindows = navigator.appVersion.indexOf('Win') !== -1\n const selectAdditional = isUsingWindows ? nativeEvent.ctrlKey : nativeEvent.metaKey\n\n let updatedIds = []\n\n // No modifier keys pressed during click:\n // - update selected to just this one\n // - open document\n if (!selectMultiple && !selectAdditional) {\n return setSelectedIds([clickedId])\n }\n\n // If shift key was held, prevent default to avoid new window opening\n if (selectMultiple) {\n nativeEvent.preventDefault()\n }\n\n // Shift key was held, add id's between last selected and this one\n // ...before adding this one\n if (selectMultiple && !isSelected) {\n const lastSelectedId = selectedIds[selectedIds.length - 1]\n const lastSelectedIndex = orderedData.findIndex((item) => item._id === lastSelectedId)\n\n const firstSelected = index < lastSelectedIndex ? index : lastSelectedIndex\n const lastSelected = index > lastSelectedIndex ? index : lastSelectedIndex\n\n const betweenIds = orderedData\n .filter((item, itemIndex) => itemIndex > firstSelected && itemIndex < lastSelected)\n .map((item) => item._id)\n\n updatedIds = [...selectedIds, ...betweenIds, clickedId]\n } else if (isSelected) {\n // Toggle off a single id\n updatedIds = selectedIds.filter((id) => id !== clickedId)\n } else {\n // Toggle on a single id\n updatedIds = [...selectedIds, clickedId]\n }\n\n return setSelectedIds(updatedIds)\n },\n [setSelectedIds, orderedData, selectedIds],\n )\n\n const client = useSanityClient()\n\n const transactPatches = useCallback(\n async (patches: [string, PatchOperations][], message: string) => {\n const transaction = client.transaction()\n\n patches.forEach(([docId, ops]) => transaction.patch(docId, ops))\n\n try {\n const updated = await transaction.commit({\n visibility: 'async',\n tag: 'orderable-document-list.reorder',\n })\n clearSelected()\n setDraggingId('')\n setListIsUpdating(false)\n toast.push({\n title: `${\n updated.results.length === 1 ? '1 document' : `${updated.results.length} documents`\n } reordered`,\n status: 'success',\n description: message,\n })\n } catch (err) {\n setDraggingId('')\n setListIsUpdating(false)\n toast.push({\n title: 'Reordering failed',\n status: 'error',\n })\n }\n },\n [client, setDraggingId, clearSelected, setListIsUpdating, toast],\n )\n\n const handleDragEnd = useCallback(\n (result: DropResult | undefined, entities: SanityDocumentWithOrder[]) => {\n setDraggingId('')\n\n const {source, destination, draggableId} = result ?? {}\n\n // Don't do anything if nothing changed\n if (source?.index === destination?.index) return\n\n // Don't do anything if we don't have the entitites\n if (!entities?.length || !draggableId) return\n\n // A document can be dragged without being one-of-many-selected\n const effectedIds = selectedIds?.length ? selectedIds : [draggableId]\n\n // Don't do anything if we don't have ids to effect\n if (!effectedIds?.length) return\n\n // Update state to update styles + prevent data refetching\n setListIsUpdating(true)\n setSelectedIds(effectedIds)\n\n const {newOrder, patches, message} = reorderDocuments({\n entities,\n selectedIds: effectedIds,\n source,\n destination,\n })\n\n // Update local state\n if (newOrder?.length) {\n setOrderedData(newOrder)\n }\n\n // Transact new order patches\n if (patches?.length) {\n transactPatches(patches, message)\n }\n },\n [selectedIds, setDraggingId, setSelectedIds, transactPatches, setListIsUpdating],\n )\n\n const handleDragStart = useCallback(\n (start: {draggableId: string}) => {\n const id = start.draggableId\n const selected = selectedIds.includes(id)\n\n // if dragging an item that is not selected - unselect all items\n if (!selected) clearSelected()\n\n setDraggingId(id)\n },\n [selectedIds, clearSelected, setDraggingId],\n )\n\n // Move one document up or down one place, by fake invoking the drag function\n const incrementIndex = useCallback(\n (shiftFrom: number, shiftTo: number, id: string, entities: SanityDocumentWithOrder[]) => {\n const result = {\n draggableId: id,\n source: {index: shiftFrom},\n destination: {index: shiftTo},\n }\n\n return handleDragEnd(result as DropResult, entities)\n },\n [handleDragEnd],\n )\n\n const onWindowKeyDown = useCallback(\n (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n clearSelected()\n }\n },\n [clearSelected],\n )\n\n useEffect(() => {\n window.addEventListener('keydown', onWindowKeyDown)\n\n return () => {\n window.removeEventListener('keydown', onWindowKeyDown)\n }\n }, [onWindowKeyDown])\n\n // Find all items with duplicate order field\n const duplicateOrders = useMemo(() => {\n if (!orderedData.length) return []\n\n const orderField = orderedData.map((item) => item[ORDER_FIELD_NAME])\n\n return orderField.filter((item, index) => orderField.indexOf(item) !== index)\n }, [orderedData])\n\n const onDragEnd = useCallback(\n (result: DropResult) => handleDragEnd(result, orderedData),\n [orderedData, handleDragEnd],\n )\n\n return (\n <DragDropContext onDragStart={handleDragStart} onDragEnd={onDragEnd}>\n <Droppable droppableId=\"documentSortZone\">\n {(provided) => (\n <div {...provided.droppableProps} ref={provided.innerRef}>\n {orderedData.map((item, index) => (\n <Draggable\n key={`${item._id}-${item[ORDER_FIELD_NAME]}`}\n draggableId={item._id}\n index={index}\n // onClick={(event) => handleDraggableClick(event, provided, snapshot)}\n >\n {(innerProvided, innerSnapshot) => {\n const isSelected = selectedIds.includes(item._id)\n const isDragging = innerSnapshot.isDragging\n const isGhosting = Boolean(!isDragging && draggingId && isSelected)\n const isUpdating = listIsUpdating && isSelected\n const isDisabled = Boolean(!item[ORDER_FIELD_NAME])\n const isDuplicate = duplicateOrders.includes(item[ORDER_FIELD_NAME])\n const tone = cardTone({isDuplicate, isGhosting, isDragging, isSelected})\n const selectedCount = selectedIds.length\n\n const dragBadge = isDragging && selectedCount > 1 ? selectedCount : false\n\n return (\n <div\n ref={innerProvided.innerRef}\n {...innerProvided.draggableProps}\n {...innerProvided.dragHandleProps}\n style={\n isDisabled\n ? {opacity: 0.2, pointerEvents: 'none'}\n : getItemStyle(innerProvided.draggableProps.style, isUpdating)\n }\n >\n <Box paddingBottom={1}>\n <Card\n tone={tone}\n shadow={isDragging ? 2 : undefined}\n radius={2}\n // eslint-disable-next-line react/jsx-no-bind\n onClick={(e) => handleSelect(item._id, index, e.nativeEvent)}\n >\n <Document\n doc={item}\n entities={orderedData}\n increment={incrementIndex}\n index={index}\n isFirst={index === 0}\n isLast={index === orderedData.length - 1}\n dragBadge={dragBadge}\n />\n </Card>\n </Box>\n </div>\n )\n }}\n </Draggable>\n ))}\n {provided.placeholder}\n </div>\n )}\n </Droppable>\n </DragDropContext>\n )\n}\n","import {useEffect, useMemo, useState} from 'react'\nimport {Box, Flex, Container, Spinner, Stack, Text} from '@sanity/ui'\n\nimport {useListeningQuery, Feedback} from 'sanity-plugin-utils'\nimport {DraggableList} from './DraggableList'\nimport {ORDER_FIELD_NAME} from './helpers/constants'\nimport type {SanityDocumentWithOrder} from './types'\n\nexport interface DocumentListQueryProps {\n type: string\n filter?: string\n params?: Record<string, unknown>\n}\n\nconst DEFAULT_PARAMS = {}\n\nexport function DocumentListQuery({type, filter, params = DEFAULT_PARAMS}: DocumentListQueryProps) {\n const [listIsUpdating, setListIsUpdating] = useState(false)\n const [data, setData] = useState<SanityDocumentWithOrder[] | null>([])\n\n const query = `*[_type == $type ${filter ? `&& ${filter}` : ''}]|order(@[$order] asc){\n _id, _type, ${ORDER_FIELD_NAME}\n }`\n const queryParams = {\n ...params,\n type,\n order: ORDER_FIELD_NAME,\n }\n\n const {\n data: _queryData,\n loading,\n error,\n } = useListeningQuery<SanityDocumentWithOrder[]>(query, {\n params: queryParams,\n initialValue: [],\n })\n // @ts-expect-error Should not be needed to \"cast\", but sanity-plugin-utils is not typed correctly\n const queryData: SanityDocumentWithOrder[] = _queryData\n\n useEffect(() => {\n if (queryData) {\n const filteredDocuments = queryData.reduce<SanityDocumentWithOrder[]>((acc, cur) => {\n if (!cur._id.startsWith(`drafts.`)) {\n // eslint-disable-next-line max-nested-callbacks\n const alsoHasDraft = queryData.some((doc) => doc._id === `drafts.${cur._id}`)\n return alsoHasDraft ? acc : [...acc, cur]\n }\n\n // Check if the draft has a published version\n cur.hasPublished = queryData.some((doc) => doc._id === cur._id.replace(`drafts.`, ``))\n\n return [...acc, cur]\n }, [])\n\n setData(filteredDocuments)\n } else {\n setData([])\n }\n }, [queryData])\n\n const unorderedDataCount = useMemo(\n () => (data?.length ? data.filter((doc) => !doc[ORDER_FIELD_NAME]).length : 0),\n [data],\n )\n\n if (loading) {\n return (\n <Flex style={{width: `100%`, height: `100%`}} align=\"center\" justify=\"center\">\n <Spinner />\n </Flex>\n )\n }\n\n if (error) {\n return (\n <Box padding={2}>\n <Feedback tone=\"critical\" title=\"There was an error\" description=\"Please try again later\" />\n </Box>\n )\n }\n\n if (!data || data?.length == 0)\n return (\n <Flex align=\"center\" direction=\"column\" height=\"fill\" justify=\"center\">\n <Container width={1}>\n <Box paddingX={4} paddingY={5}>\n <Text align=\"center\" muted>\n No documents of this type\n </Text>\n </Box>\n </Container>\n </Flex>\n )\n\n return (\n <Stack space={1} style={{overflow: `auto`, height: `100%`}}>\n <Box padding={2}>\n {unorderedDataCount > 0 && (\n <Box marginBottom={2}>\n <Feedback\n tone=\"caution\"\n description={\n <>\n {unorderedDataCount}/{data?.length} documents have no order. Select{' '}\n <strong>Reset Order</strong> from the menu above to fix.\n </>\n }\n />\n </Box>\n )}\n <DraggableList\n data={data}\n listIsUpdating={listIsUpdating}\n setListIsUpdating={setListIsUpdating}\n />\n </Box>\n </Stack>\n )\n}\n","import {useEffect, useMemo} from 'react'\nimport {useToast, Box, type ToastParams} from '@sanity/ui'\n\nimport {useSchema} from 'sanity'\nimport {Feedback} from 'sanity-plugin-utils'\nimport {DocumentListQuery} from './DocumentListQuery'\nimport {OrderableContext} from './OrderableContext'\n\nimport {ORDER_FIELD_NAME} from './helpers/constants'\n\nexport interface DocumentListWrapperProps {\n showIncrements: boolean\n type: string\n resetOrderTransaction: ToastParams\n // eslint-disable-next-line react/require-default-props\n filter?: string\n // eslint-disable-next-line react/require-default-props\n params?: Record<string, unknown>\n}\n\n// 1. Validate first that the schema has been configured for ordering\n// 2. Setup context for showIncrements\nexport function DocumentListWrapper({\n type,\n showIncrements,\n resetOrderTransaction,\n filter,\n params,\n}: DocumentListWrapperProps) {\n const toast = useToast()\n const schema = useSchema()\n\n useEffect(() => {\n if (resetOrderTransaction?.title && resetOrderTransaction?.status) {\n toast.push(resetOrderTransaction)\n }\n }, [resetOrderTransaction, toast])\n\n const schemaIsInvalid = useMemo(() => {\n // Option not passed\n if (!type) {\n return (\n <>\n No <code>type</code> was configured\n </>\n )\n }\n\n const typeSchema = schema.get(type)\n\n // Schema not found\n if (!typeSchema) {\n return (\n <>\n Schema <code>{type}</code> not found\n </>\n )\n }\n\n // Schema lacks an order field\n if (\n !('fields' in typeSchema) ||\n !typeSchema.fields.some((field) => field?.name === ORDER_FIELD_NAME)\n ) {\n return (\n <>\n Schema <code>{type}</code> must have an <code>{ORDER_FIELD_NAME}</code> field of type{' '}\n <code>string</code>\n </>\n )\n }\n\n // Schema's order field is not a string\n if (\n 'fields' in typeSchema &&\n typeSchema.fields.some(\n (field) => field?.name === ORDER_FIELD_NAME && field?.type?.name !== 'string',\n )\n ) {\n return (\n <>\n <code>{ORDER_FIELD_NAME}</code> field on Schema <code>{type}</code> must be{' '}\n <code>string</code> type\n </>\n )\n }\n\n return ''\n }, [type, schema])\n\n if (schemaIsInvalid) {\n return (\n <Box padding={2}>\n <Feedback description={schemaIsInvalid} tone=\"caution\" />\n </Box>\n )\n }\n\n return (\n <OrderableContext.Provider value={{showIncrements}}>\n <DocumentListQuery type={type} filter={filter} params={params} />\n </OrderableContext.Provider>\n )\n}\n","import {LexoRank} from 'lexorank'\nimport type {MultipleMutationResult, SanityClient} from '@sanity/client'\nimport {ORDER_FIELD_NAME} from './constants'\n\n// Function to wipe and re-do ordering with LexoRank\n// Will at least attempt to start with the current order\nexport async function resetOrder(\n type: string,\n client: SanityClient,\n): Promise<MultipleMutationResult | null> {\n const query = `*[_type == $type]|order(@[$order] asc)._id`\n const queryParams = {type, order: ORDER_FIELD_NAME}\n const documentIds = await client.fetch<Array<string>>(query, queryParams, {\n tag: 'orderable-document-list.reset-order',\n })\n\n if (documentIds.length === 0) {\n return null\n }\n\n let aLexoRank = LexoRank.min()\n\n const transaction = documentIds.reduce((trx, documentId) => {\n // Generate next rank before even the first document so there's room to move!\n aLexoRank = aLexoRank.genNext().genNext()\n\n return trx.patch(documentId, {\n set: {[ORDER_FIELD_NAME]: aLexoRank.toString()},\n })\n }, client.transaction())\n\n return transaction.commit({\n visibility: 'async',\n tag: 'orderable-document-list.reset-order',\n })\n}\n","import {Component} from 'react'\n\nimport type {SanityClient} from '@sanity/client'\nimport type {ToastParams} from '@sanity/ui'\nimport {DocumentListWrapper} from './DocumentListWrapper'\nimport {resetOrder} from './helpers/resetOrder'\n\nexport interface OrderableDocumentListProps {\n options: {\n type: string\n client: SanityClient\n filter?: string\n params?: Record<string, unknown>\n }\n}\n\ninterface State {\n showIncrements: boolean\n resetOrderTransaction: ToastParams\n}\n\n// Must use a Class Component here so the actionHandlers can be called\nexport class OrderableDocumentList extends Component<OrderableDocumentListProps, State> {\n constructor(props: OrderableDocumentListProps) {\n super(props)\n this.state = {\n showIncrements: false,\n resetOrderTransaction: {},\n }\n }\n\n actionHandlers = {\n showIncrements: () => {\n this.setState((state) => ({\n showIncrements: !state.showIncrements,\n }))\n },\n\n resetOrder: async () => {\n this.setState(() => ({\n resetOrderTransaction: {\n status: `info`,\n title: `Reordering started...`,\n closable: true,\n },\n }))\n\n const update = await resetOrder(this.props.options.type, this.props.options.client)\n\n const reorderWasSuccessful = update?.results?.length\n\n this.setState(() => ({\n resetOrderTransaction: {\n status: reorderWasSuccessful ? `success` : `info`,\n title: reorderWasSuccessful\n ? `Reordered ${update.results.length === 1 ? `Document` : `Documents`}`\n : `Reordering failed`,\n closable: true,\n },\n }))\n },\n }\n\n render() {\n const type = this?.props?.options?.type\n if (!type) {\n return null\n }\n return (\n <DocumentListWrapper\n filter={this?.props?.options?.filter}\n params={this?.props?.options?.params}\n type={type}\n showIncrements={this.state.showIncrements}\n resetOrderTransaction={this.state.resetOrderTransaction}\n />\n )\n }\n}\n","import {GenerateIcon, SortIcon} from '@sanity/icons'\nimport type {ConfigContext} from 'sanity'\n\nimport type {ComponentType} from 'react'\nimport {StructureBuilder, type ListItem, type MenuItem} from 'sanity/structure'\nimport {OrderableDocumentList} from '../OrderableDocumentList'\nimport {API_VERSION} from '../helpers/constants'\n\nexport interface OrderableListConfig {\n type: string\n id?: string\n title?: string\n icon?: ComponentType\n params?: Record<string, unknown>\n filter?: string\n menuItems?: MenuItem[]\n createIntent?: boolean\n context: ConfigContext\n S: StructureBuilder\n}\n\nexport function orderableDocumentListDeskItem(config: OrderableListConfig): ListItem {\n if (!config?.type || !config.context || !config.S) {\n 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 `)\n }\n\n const {type, filter, menuItems = [], createIntent, params, title, icon, id, context, S} = config\n const {schema, getClient} = context\n const client = getClient({apiVersion: API_VERSION})\n\n const listTitle = title ?? `Orderable ${type}`\n const listId = id ?? `orderable-${type}`\n const listIcon = icon ?? SortIcon\n const typeTitle = schema.get(type)?.title ?? type\n\n if (createIntent !== false) {\n menuItems.push(\n S.menuItem()\n .title(`Create new ${typeTitle}`)\n .intent({type: 'create', params: {type}})\n .serialize(),\n )\n }\n return S.listItem()\n .title(listTitle)\n .id(listId)\n .icon(listIcon)\n .schemaType(type)\n .child(\n Object.assign(\n S.documentTypeList(type)\n .canHandleIntent(() => !!createIntent)\n .serialize(),\n {\n // Prevents the component from re-rendering when switching documents\n __preserveInstance: true,\n // Prevents the component from NOT re-rendering when switching listItems\n key: listId,\n\n type: 'component',\n component: OrderableDocumentList,\n options: {type, filter, params, client},\n menuItems: [\n ...menuItems,\n S.menuItem().title(`Reset Order`).icon(GenerateIcon).action(`resetOrder`).serialize(),\n S.menuItem()\n .title(`Toggle Increments`)\n .icon(SortIcon)\n .action(`showIncrements`)\n .serialize(),\n ],\n },\n ),\n )\n .serialize()\n}\n"],"names":["LexoRank","defineField","createContext","useContext","useSchema","usePaneRouter","useMemo","jsx","PreviewCard","jsxs","Flex","Box","Text","DragHandleIcon","Button","ChevronUpIcon","ChevronDownIcon","Preview","Card","AvatarCounter","useClient","useToast","useState","useEffect","useCallback","DragDropContext","Droppable","Draggable","useListeningQuery","Spinner","Feedback","Container","Stack","Fragment","Component","SortIcon","GenerateIcon"],"mappings":";;;AAAa,MAAA,mBAAmB,aAEnB,cAAc;ACGpB,SAAS,YACd,mBAAmB,IACnB,kBAAmC,SAC3B;AACR,QAAM,cAAc,mBAAmBA,SAAA,SAAS,MAAM,gBAAgB,IAAIA,kBAAS,IAAI;AAIvF,UAFE,oBAAoB,WAAW,YAAY,QAAU,EAAA,QAAY,IAAA,YAAY,QAAQ,EAAE,QAAQ,GAErF,SAAS;AACvB;ACFa,MAAA,iBAAiB,CAAC,WAA8C;AAC3E,MAAI,CAAC,QAAQ;AACX,UAAM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