@sanity/orderable-document-list 0.0.10 → 1.0.0-v3-studio.2

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.
Files changed (61) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +135 -55
  3. package/lib/index.d.ts +31 -0
  4. package/lib/index.d.ts.map +1 -0
  5. package/lib/index.js +827 -30
  6. package/lib/index.js.map +1 -1
  7. package/lib/index.modern.js +818 -0
  8. package/lib/index.modern.js.map +1 -0
  9. package/package.json +57 -23
  10. package/src/{Document.js → Document.tsx} +30 -27
  11. package/src/{DocumentListQuery.js → DocumentListQuery.tsx} +27 -23
  12. package/src/{DocumentListWrapper.js → DocumentListWrapper.tsx} +24 -29
  13. package/src/DraggableList.tsx +304 -0
  14. package/src/{Feedback.js → Feedback.tsx} +2 -7
  15. package/src/OrderableContext.ts +7 -0
  16. package/src/{OrderableDocumentList.js → OrderableDocumentList.tsx} +23 -12
  17. package/src/desk-structure/{orderableDocumentListDeskItem.js → orderableDocumentListDeskItem.ts} +24 -10
  18. package/src/fields/{orderRankField.js → orderRankField.ts} +12 -10
  19. package/src/fields/{orderRankOrdering.js → orderRankOrdering.ts} +0 -0
  20. package/src/helpers/client.ts +5 -0
  21. package/src/helpers/constants.ts +1 -0
  22. package/src/helpers/{initialRank.js → initialRank.ts} +2 -2
  23. package/src/helpers/{reorderDocuments.js → reorderDocuments.ts} +33 -44
  24. package/src/helpers/{resetOrder.js → resetOrder.ts} +3 -8
  25. package/src/index.ts +9 -0
  26. package/.babelrc +0 -3
  27. package/.eslintignore +0 -1
  28. package/.eslintrc.js +0 -50
  29. package/lib/Document.js +0 -101
  30. package/lib/Document.js.map +0 -1
  31. package/lib/DocumentListQuery.js +0 -163
  32. package/lib/DocumentListQuery.js.map +0 -1
  33. package/lib/DocumentListWrapper.js +0 -107
  34. package/lib/DocumentListWrapper.js.map +0 -1
  35. package/lib/DraggableList.js +0 -314
  36. package/lib/DraggableList.js.map +0 -1
  37. package/lib/Feedback.js +0 -31
  38. package/lib/Feedback.js.map +0 -1
  39. package/lib/OrderableContext.js +0 -15
  40. package/lib/OrderableContext.js.map +0 -1
  41. package/lib/OrderableDocumentList.js +0 -103
  42. package/lib/OrderableDocumentList.js.map +0 -1
  43. package/lib/desk-structure/orderableDocumentListDeskItem.js +0 -57
  44. package/lib/desk-structure/orderableDocumentListDeskItem.js.map +0 -1
  45. package/lib/fields/orderRankField.js +0 -64
  46. package/lib/fields/orderRankField.js.map +0 -1
  47. package/lib/fields/orderRankOrdering.js +0 -19
  48. package/lib/fields/orderRankOrdering.js.map +0 -1
  49. package/lib/helpers/constants.js +0 -9
  50. package/lib/helpers/constants.js.map +0 -1
  51. package/lib/helpers/initialRank.js +0 -18
  52. package/lib/helpers/initialRank.js.map +0 -1
  53. package/lib/helpers/reorderDocuments.js +0 -131
  54. package/lib/helpers/reorderDocuments.js.map +0 -1
  55. package/lib/helpers/resetOrder.js +0 -62
  56. package/lib/helpers/resetOrder.js.map +0 -1
  57. package/sanity.json +0 -7
  58. package/src/DraggableList.js +0 -276
  59. package/src/OrderableContext.js +0 -3
  60. package/src/helpers/constants.js +0 -1
  61. package/src/index.js +0 -5
@@ -1,314 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = DraggableList;
7
-
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
- var _react = _interopRequireWildcard(require("react"));
11
-
12
- var _reactBeautifulDnd = require("react-beautiful-dnd");
13
-
14
- var _deskTool = require("@sanity/desk-tool");
15
-
16
- var _ui = require("@sanity/ui");
17
-
18
- var _client = _interopRequireDefault(require("part:@sanity/base/client"));
19
-
20
- var _Document = _interopRequireDefault(require("./Document"));
21
-
22
- var _reorderDocuments2 = require("./helpers/reorderDocuments");
23
-
24
- var _constants = require("./helpers/constants");
25
-
26
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
-
28
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
-
30
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
-
32
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
33
-
34
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
35
-
36
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
37
-
38
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
39
-
40
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
41
-
42
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
43
-
44
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
45
-
46
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
47
-
48
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
49
-
50
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
51
-
52
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
53
-
54
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
55
-
56
- var client = _client.default.withConfig({
57
- apiVersion: '2021-09-01'
58
- });
59
-
60
- var getItemStyle = (draggableStyle, itemIsUpdating) => _objectSpread({
61
- userSelect: 'none',
62
- transition: "opacity 500ms ease-in-out",
63
- opacity: itemIsUpdating ? 0.2 : 1,
64
- pointerEvents: itemIsUpdating ? "none" : undefined
65
- }, draggableStyle);
66
-
67
- var cardTone = settings => {
68
- var isDuplicate = settings.isDuplicate,
69
- isGhosting = settings.isGhosting,
70
- isDragging = settings.isDragging,
71
- isSelected = settings.isSelected;
72
- if (isGhosting) return "transparent";
73
- if (isDragging || isSelected) return "primary";
74
- if (isDuplicate) return "caution";
75
- return undefined;
76
- };
77
-
78
- function DraggableList(_ref) {
79
- var data = _ref.data,
80
- type = _ref.type,
81
- listIsUpdating = _ref.listIsUpdating,
82
- setListIsUpdating = _ref.setListIsUpdating;
83
- var toast = (0, _ui.useToast)();
84
- var router = (0, _deskTool.usePaneRouter)();
85
- var navigateIntent = router.navigateIntent; // Maintains local state order before transaction completes
86
-
87
- var _useState = (0, _react.useState)(data),
88
- _useState2 = _slicedToArray(_useState, 2),
89
- orderedData = _useState2[0],
90
- setOrderedData = _useState2[1]; // Update local state when documents change from an outside source
91
-
92
-
93
- (0, _react.useEffect)(() => {
94
- if (!listIsUpdating) setOrderedData(data);
95
- /* eslint-disable-next-line react-hooks/exhaustive-deps */
96
- }, [data]);
97
-
98
- var _useState3 = (0, _react.useState)(""),
99
- _useState4 = _slicedToArray(_useState3, 2),
100
- draggingId = _useState4[0],
101
- setDraggingId = _useState4[1];
102
-
103
- var _useState5 = (0, _react.useState)([]),
104
- _useState6 = _slicedToArray(_useState5, 2),
105
- selectedIds = _useState6[0],
106
- setSelectedIds = _useState6[1];
107
-
108
- var clearSelected = () => setSelectedIds([]);
109
-
110
- var handleSelect = (clickedId, index, nativeEvent) => {
111
- var isSelected = selectedIds.includes(clickedId);
112
- var selectMultiple = nativeEvent.shiftKey;
113
- var isUsingWindows = navigator.appVersion.indexOf('Win') !== -1;
114
- var selectAdditional = isUsingWindows ? nativeEvent.ctrlKey : nativeEvent.metaKey;
115
- var updatedIds = []; // No modifier keys pressed during click:
116
- // - update selected to just this one
117
- // - open document
118
-
119
- if (!selectMultiple && !selectAdditional) {
120
- navigateIntent('edit', {
121
- id: clickedId,
122
- type
123
- });
124
- return setSelectedIds([clickedId]);
125
- } // Shift key was held, add id's between last selected and this one
126
- // ...before adding this one
127
-
128
-
129
- if (selectMultiple && !isSelected) {
130
- var lastSelectedId = selectedIds.at(-1);
131
- var lastSelectedIndex = orderedData.findIndex(item => item._id === lastSelectedId);
132
- var firstSelected = index < lastSelectedIndex ? index : lastSelectedIndex;
133
- var lastSelected = index > lastSelectedIndex ? index : lastSelectedIndex;
134
- var betweenIds = orderedData.filter((item, itemIndex) => itemIndex > firstSelected && itemIndex < lastSelected).map(item => item._id);
135
- updatedIds = [...selectedIds, ...betweenIds, clickedId];
136
- } else if (isSelected) {
137
- // Toggle off a single id
138
- updatedIds = selectedIds.filter(id => id !== clickedId);
139
- } else {
140
- // Toggle on a single id
141
- updatedIds = [...selectedIds, clickedId];
142
- }
143
-
144
- return setSelectedIds(updatedIds);
145
- };
146
-
147
- var transactPatches = /*#__PURE__*/function () {
148
- var _ref2 = _asyncToGenerator(function* (patches, message) {
149
- var transaction = client.transaction();
150
- patches.forEach(patchArgs => transaction.patch(...patchArgs));
151
- yield transaction.commit().then(updated => {
152
- clearSelected();
153
- setDraggingId("");
154
- setListIsUpdating(false);
155
- toast.push({
156
- title: "".concat(updated.results.length === 1 ? "1 Document" : "".concat(updated.results.length, " Documents"), " Reordered"),
157
- status: "success",
158
- description: message
159
- });
160
- }).catch(() => {
161
- setDraggingId("");
162
- setListIsUpdating(false);
163
- toast.push({
164
- title: "Reordering failed",
165
- status: "critical"
166
- });
167
- });
168
- });
169
-
170
- return function transactPatches(_x, _x2) {
171
- return _ref2.apply(this, arguments);
172
- };
173
- }();
174
-
175
- var handleDragEnd = (result, entities) => {
176
- setDraggingId("");
177
-
178
- var _ref3 = result !== null && result !== void 0 ? result : {},
179
- source = _ref3.source,
180
- destination = _ref3.destination,
181
- draggableId = _ref3.draggableId; // Don't do anything if nothing changed
182
-
183
-
184
- if (source.index === destination.index) return; // Don't do anything if we don't have the entitites
185
-
186
- if (!(entities !== null && entities !== void 0 && entities.length)) return; // A document can be dragged without being one-of-many-selected
187
-
188
- var effectedIds = selectedIds !== null && selectedIds !== void 0 && selectedIds.length ? selectedIds : [draggableId]; // Don't do anything if we don't have ids to effect
189
-
190
- if (!(effectedIds !== null && effectedIds !== void 0 && effectedIds.length)) return; // Update state to update styles + prevent data refetching
191
-
192
- setListIsUpdating(true);
193
- setSelectedIds(effectedIds);
194
-
195
- var _reorderDocuments = (0, _reorderDocuments2.reorderDocuments)({
196
- entities,
197
- selectedIds: effectedIds,
198
- source,
199
- destination
200
- }),
201
- newOrder = _reorderDocuments.newOrder,
202
- patches = _reorderDocuments.patches,
203
- message = _reorderDocuments.message; // Update local state
204
-
205
-
206
- if (newOrder !== null && newOrder !== void 0 && newOrder.length) {
207
- setOrderedData(newOrder);
208
- } // Transact new order patches
209
-
210
-
211
- if (patches !== null && patches !== void 0 && patches.length) {
212
- transactPatches(patches, message);
213
- }
214
- };
215
-
216
- var handleDragStart = start => {
217
- var id = start.draggableId;
218
- var selected = selectedIds.includes(id); // if dragging an item that is not selected - unselect all items
219
-
220
- if (!selected) clearSelected();
221
- setDraggingId(id);
222
- }; // Move one document up or down one place, by fake invoking the drag function
223
-
224
-
225
- var incrementIndex = (shiftFrom, shiftTo, id, entities) => {
226
- var result = {
227
- draggableId: id,
228
- source: {
229
- index: shiftFrom
230
- },
231
- destination: {
232
- index: shiftTo
233
- }
234
- };
235
- return handleDragEnd(result, entities);
236
- };
237
-
238
- var onWindowKeyDown = event => {
239
- if (event.key === 'Escape') {
240
- clearSelected();
241
- }
242
- };
243
-
244
- (0, _react.useEffect)(() => {
245
- window.addEventListener('keydown', onWindowKeyDown);
246
- return () => {
247
- window.removeEventListener('keydown', onWindowKeyDown);
248
- };
249
- }, []); // Find all items with duplicate order field
250
-
251
- var duplicateOrders = (0, _react.useMemo)(() => {
252
- if (!orderedData.length) return [];
253
- var orderField = orderedData.map(item => item[_constants.ORDER_FIELD_NAME]);
254
- return orderField.filter((item, index) => orderField.indexOf(item) !== index);
255
- }, [orderedData]);
256
- return /*#__PURE__*/_react.default.createElement(_reactBeautifulDnd.DragDropContext, {
257
- onDragStart: handleDragStart,
258
- onDragEnd: result => handleDragEnd(result, orderedData)
259
- }, /*#__PURE__*/_react.default.createElement(_reactBeautifulDnd.Droppable, {
260
- droppableId: "documentSortZone"
261
- }, (provided, snapshot) => /*#__PURE__*/_react.default.createElement("div", _extends({}, provided.droppableProps, {
262
- ref: provided.innerRef
263
- }), orderedData.map((item, index) => /*#__PURE__*/_react.default.createElement(_reactBeautifulDnd.Draggable, {
264
- key: "".concat(item._id, "-").concat(item[_constants.ORDER_FIELD_NAME]),
265
- draggableId: item._id,
266
- index: index // onClick={(event) => handleDraggableClick(event, provided, snapshot)}
267
-
268
- }, (innerProvided, innerSnapshot) => {
269
- var isSelected = selectedIds.includes(item._id);
270
- var isDragging = innerSnapshot.isDragging;
271
- var isGhosting = Boolean(!isDragging && draggingId && isSelected);
272
- var isUpdating = listIsUpdating && isSelected;
273
- var isDisabled = Boolean(!item[_constants.ORDER_FIELD_NAME]);
274
- var isDuplicate = duplicateOrders.includes(item[_constants.ORDER_FIELD_NAME]);
275
- var tone = cardTone({
276
- isDuplicate,
277
- isGhosting,
278
- isDragging,
279
- isSelected
280
- });
281
- return /*#__PURE__*/_react.default.createElement("div", _extends({
282
- ref: innerProvided.innerRef
283
- }, innerProvided.draggableProps, innerProvided.dragHandleProps, {
284
- style: isDisabled ? {
285
- opacity: 0.2,
286
- pointerEvents: "none"
287
- } : getItemStyle(innerProvided.draggableProps.style, isUpdating, isGhosting)
288
- }), /*#__PURE__*/_react.default.createElement(_ui.Box, {
289
- paddingBottom: 1
290
- }, /*#__PURE__*/_react.default.createElement(_ui.Card, {
291
- tone: tone,
292
- shadow: isDragging ? "2" : undefined,
293
- radius: 2
294
- }, /*#__PURE__*/_react.default.createElement(_Document.default, {
295
- doc: item,
296
- entities: orderedData,
297
- handleSelect: handleSelect,
298
- increment: incrementIndex,
299
- index: index,
300
- isFirst: index === 0,
301
- isLast: index === orderedData.length - 1
302
- }))));
303
- })), provided.placeholder)));
304
- }
305
-
306
- DraggableList.propTypes = {
307
- data: _propTypes.default.arrayOf(_propTypes.default.shape({
308
- _id: _propTypes.default.string
309
- }).isRequired).isRequired,
310
- type: _propTypes.default.string.isRequired,
311
- listIsUpdating: _propTypes.default.bool.isRequired,
312
- setListIsUpdating: _propTypes.default.func.isRequired
313
- };
314
- //# sourceMappingURL=DraggableList.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DraggableList.js","names":["client","sanityClient","withConfig","apiVersion","getItemStyle","draggableStyle","itemIsUpdating","userSelect","transition","opacity","pointerEvents","undefined","cardTone","settings","isDuplicate","isGhosting","isDragging","isSelected","DraggableList","data","type","listIsUpdating","setListIsUpdating","toast","useToast","router","usePaneRouter","navigateIntent","useState","orderedData","setOrderedData","useEffect","draggingId","setDraggingId","selectedIds","setSelectedIds","clearSelected","handleSelect","clickedId","index","nativeEvent","includes","selectMultiple","shiftKey","isUsingWindows","navigator","appVersion","indexOf","selectAdditional","ctrlKey","metaKey","updatedIds","id","lastSelectedId","at","lastSelectedIndex","findIndex","item","_id","firstSelected","lastSelected","betweenIds","filter","itemIndex","map","transactPatches","patches","message","transaction","forEach","patchArgs","patch","commit","then","updated","push","title","results","length","status","description","catch","handleDragEnd","result","entities","source","destination","draggableId","effectedIds","reorderDocuments","newOrder","handleDragStart","start","selected","incrementIndex","shiftFrom","shiftTo","onWindowKeyDown","event","key","window","addEventListener","removeEventListener","duplicateOrders","useMemo","orderField","ORDER_FIELD_NAME","provided","snapshot","droppableProps","innerRef","innerProvided","innerSnapshot","Boolean","isUpdating","isDisabled","tone","draggableProps","dragHandleProps","style","placeholder","propTypes","PropTypes","arrayOf","shape","string","isRequired","bool","func"],"sources":["../src/DraggableList.js"],"sourcesContent":["import PropTypes from 'prop-types'\nimport React, {useMemo, useState, useEffect} from 'react'\nimport {DragDropContext, Droppable, Draggable} from 'react-beautiful-dnd'\nimport {usePaneRouter} from '@sanity/desk-tool'\nimport {Box, Card, useToast} from '@sanity/ui'\nimport sanityClient from 'part:@sanity/base/client'\n\nimport Document from './Document'\nimport {reorderDocuments} from './helpers/reorderDocuments'\nimport {ORDER_FIELD_NAME} from './helpers/constants'\n\nconst client = sanityClient.withConfig({\n apiVersion: '2021-09-01',\n})\n\nconst getItemStyle = (draggableStyle, itemIsUpdating) => ({\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) => {\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 default function DraggableList({data, type, listIsUpdating, setListIsUpdating}) {\n const toast = useToast()\n const router = usePaneRouter()\n const {navigateIntent} = router\n\n // Maintains local state order before transaction completes\n const [orderedData, setOrderedData] = useState(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([])\n\n const clearSelected = () => setSelectedIds([])\n\n const handleSelect = (clickedId, index, nativeEvent) => {\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 navigateIntent('edit', {id: clickedId, type})\n return setSelectedIds([clickedId])\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.at(-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\n const transactPatches = async (patches, message) => {\n const transaction = client.transaction()\n\n patches.forEach((patchArgs) => transaction.patch(...patchArgs))\n\n await transaction\n .commit()\n .then((updated) => {\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 })\n .catch(() => {\n setDraggingId(``)\n setListIsUpdating(false)\n toast.push({\n title: `Reordering failed`,\n status: `critical`,\n })\n })\n }\n\n const handleDragEnd = (result, entities) => {\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) 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\n const handleDragStart = (start) => {\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\n // Move one document up or down one place, by fake invoking the drag function\n const incrementIndex = (shiftFrom, shiftTo, id, entities) => {\n const result = {\n draggableId: id,\n source: {index: shiftFrom},\n destination: {index: shiftTo},\n }\n\n return handleDragEnd(result, entities)\n }\n\n const onWindowKeyDown = (event) => {\n if (event.key === 'Escape') {\n clearSelected()\n }\n }\n\n useEffect(() => {\n window.addEventListener('keydown', onWindowKeyDown)\n\n return () => {\n window.removeEventListener('keydown', onWindowKeyDown)\n }\n }, [])\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 return (\n <DragDropContext\n onDragStart={handleDragStart}\n onDragEnd={(result) => handleDragEnd(result, orderedData)}\n >\n <Droppable droppableId=\"documentSortZone\">\n {(provided, snapshot) => (\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\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, isGhosting)\n }\n >\n <Box paddingBottom={1}>\n <Card tone={tone} shadow={isDragging ? `2` : undefined} radius={2}>\n <Document\n doc={item}\n entities={orderedData}\n handleSelect={handleSelect}\n increment={incrementIndex}\n index={index}\n isFirst={index === 0}\n isLast={index === orderedData.length - 1}\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\nDraggableList.propTypes = {\n data: PropTypes.arrayOf(\n PropTypes.shape({\n _id: PropTypes.string,\n }).isRequired\n ).isRequired,\n type: PropTypes.string.isRequired,\n listIsUpdating: PropTypes.bool.isRequired,\n setListIsUpdating: PropTypes.func.isRequired,\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,MAAM,GAAGC,eAAA,CAAaC,UAAb,CAAwB;EACrCC,UAAU,EAAE;AADyB,CAAxB,CAAf;;AAIA,IAAMC,YAAY,GAAG,CAACC,cAAD,EAAiBC,cAAjB;EACnBC,UAAU,EAAE,MADO;EAEnBC,UAAU,6BAFS;EAGnBC,OAAO,EAAEH,cAAc,GAAG,GAAH,GAAS,CAHb;EAInBI,aAAa,EAAEJ,cAAc,YAAYK;AAJtB,GAKhBN,cALgB,CAArB;;AAQA,IAAMO,QAAQ,GAAIC,QAAD,IAAc;EAC7B,IAAOC,WAAP,GAA0DD,QAA1D,CAAOC,WAAP;EAAA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BE,KAA9B,EAAqCL,UAArC,EAAiDnG,UAAjD;IAPpB,iBAUE,6BAAC,OAAD;MAAK,aAAa,EAAE;IAApB,gBACE,6BAAC,QAAD;MAAM,IAAI,EAAEqG,IAAZ;MAAkB,MAAM,EAAEpG,UAAU,SAASL,SAA7C;MAAwD,MAAM,EAAE;IAAhE,gBACE,6BAAC,iBAAD;MACE,GAAG,EAAE8C,IADP;MAEE,QAAQ,EAAE5B,WAFZ;MAGE,YAAY,EAAEQ,YAHhB;MAIE,SAAS,EAAEyD,cAJb;MAKE,KAAK,EAAEvD,KALT;MAME,OAAO,EAAEA,KAAK,KAAK,CANrB;MAOE,MAAM,EAAEA,KAAK,KAAKV,WAAW,CAACiD,MAAZ,GAAqB;IAPzC,EADF,CADF,CAVF,CADF;EA0BD,CAzCH,CADD,CADH,EA8CG6B,QAAQ,CAACa,WA9CZ,CAFJ,CAJF,CADF;AA2DD;;AAEDtG,aAAa,CAACuG,SAAd,GAA0B;EACxBtG,IAAI,EAAEuG,kBAAA,CAAUC,OAAV,CACJD,kBAAA,CAAUE,KAAV,CAAgB;IACdlE,GAAG,EAAEgE,kBAAA,CAAUG;EADD,CAAhB,EAEGC,UAHC,EAIJA,UALsB;EAMxB1G,IAAI,EAAEsG,kBAAA,CAAUG,MAAV,CAAiBC,UANC;EAOxBzG,cAAc,EAAEqG,kBAAA,CAAUK,IAAV,CAAeD,UAPP;EAQxBxG,iBAAiB,EAAEoG,kBAAA,CAAUM,IAAV,CAAeF;AARV,CAA1B"}
package/lib/Feedback.js DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = Feedback;
7
-
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
- var _react = _interopRequireDefault(require("react"));
11
-
12
- var _ui = require("@sanity/ui");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- function Feedback(_ref) {
17
- var children = _ref.children;
18
- return /*#__PURE__*/_react.default.createElement(_ui.Box, {
19
- padding: 3
20
- }, /*#__PURE__*/_react.default.createElement(_ui.Card, {
21
- padding: 4,
22
- radius: 2,
23
- shadow: 1,
24
- tone: "caution"
25
- }, /*#__PURE__*/_react.default.createElement(_ui.Text, null, children)));
26
- }
27
-
28
- Feedback.propTypes = {
29
- children: _propTypes.default.node.isRequired
30
- };
31
- //# sourceMappingURL=Feedback.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Feedback.js","names":["Feedback","children","propTypes","PropTypes","node","isRequired"],"sources":["../src/Feedback.js"],"sourcesContent":["import PropTypes from 'prop-types'\nimport React from 'react'\nimport {Box, Card, Text} from '@sanity/ui'\n\nexport default function Feedback({children}) {\n return (\n <Box padding={3}>\n <Card padding={4} radius={2} shadow={1} tone=\"caution\">\n <Text>{children}</Text>\n </Card>\n </Box>\n )\n}\n\nFeedback.propTypes = {\n children: PropTypes.node.isRequired,\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEe,SAASA,QAAT,OAA8B;EAAA,IAAXC,QAAW,QAAXA,QAAW;EAC3C,oBACE,6BAAC,OAAD;IAAK,OAAO,EAAE;EAAd,gBACE,6BAAC,QAAD;IAAM,OAAO,EAAE,CAAf;IAAkB,MAAM,EAAE,CAA1B;IAA6B,MAAM,EAAE,CAArC;IAAwC,IAAI,EAAC;EAA7C,gBACE,6BAAC,QAAD,QAAOA,QAAP,CADF,CADF,CADF;AAOD;;AAEDD,QAAQ,CAACE,SAAT,GAAqB;EACnBD,QAAQ,EAAEE,kBAAA,CAAUC,IAAV,CAAeC;AADN,CAArB"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.OrderableContext = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- var OrderableContext = /*#__PURE__*/_react.default.createContext({});
13
-
14
- exports.OrderableContext = OrderableContext;
15
- //# sourceMappingURL=OrderableContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OrderableContext.js","names":["OrderableContext","React","createContext"],"sources":["../src/OrderableContext.js"],"sourcesContent":["import React from 'react'\n\nexport const OrderableContext = React.createContext({})\n"],"mappings":";;;;;;;AAAA;;;;AAEO,IAAMA,gBAAgB,gBAAGC,cAAA,CAAMC,aAAN,CAAoB,EAApB,CAAzB"}
@@ -1,103 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
- var _react = _interopRequireWildcard(require("react"));
11
-
12
- var _DocumentListWrapper = _interopRequireDefault(require("./DocumentListWrapper"));
13
-
14
- var _resetOrder3 = require("./helpers/resetOrder");
15
-
16
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
23
-
24
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
25
-
26
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
-
28
- // Must use a Class Component here so the actionHandlers can be called
29
- class OrderableDocumentList extends _react.Component {
30
- constructor(props) {
31
- var _this;
32
-
33
- super(props);
34
- _this = this;
35
-
36
- _defineProperty(this, "actionHandlers", {
37
- showIncrements: () => {
38
- this.setState(state => ({
39
- showIncrements: !state.showIncrements
40
- }));
41
- },
42
- resetOrder: function () {
43
- var _resetOrder2 = _asyncToGenerator(function* () {
44
- var _update$results;
45
-
46
- _this.setState(() => ({
47
- resetOrderTransaction: {
48
- status: "info",
49
- title: "Reordering started...",
50
- closable: true
51
- }
52
- }));
53
-
54
- var update = yield (0, _resetOrder3.resetOrder)(_this.props.options.type);
55
- var reorderWasSuccessful = update === null || update === void 0 ? void 0 : (_update$results = update.results) === null || _update$results === void 0 ? void 0 : _update$results.length;
56
-
57
- _this.setState(() => ({
58
- resetOrderTransaction: {
59
- status: reorderWasSuccessful ? "success" : "info",
60
- title: reorderWasSuccessful ? "Reordered ".concat(update.results.length === 1 ? "Document" : "Documents") : "Reordering failed",
61
- closable: true
62
- }
63
- }));
64
- });
65
-
66
- function resetOrder() {
67
- return _resetOrder2.apply(this, arguments);
68
- }
69
-
70
- return resetOrder;
71
- }()
72
- });
73
-
74
- this.state = {
75
- showIncrements: false,
76
- resetOrderTransaction: {}
77
- };
78
- }
79
-
80
- render() {
81
- var _this$props, _this$props$options, _this$props2, _this$props2$options, _this$props3, _this$props3$options;
82
-
83
- return /*#__PURE__*/_react.default.createElement(_DocumentListWrapper.default, {
84
- type: this === null || this === void 0 ? void 0 : (_this$props = this.props) === null || _this$props === void 0 ? void 0 : (_this$props$options = _this$props.options) === null || _this$props$options === void 0 ? void 0 : _this$props$options.type,
85
- filter: this === null || this === void 0 ? void 0 : (_this$props2 = this.props) === null || _this$props2 === void 0 ? void 0 : (_this$props2$options = _this$props2.options) === null || _this$props2$options === void 0 ? void 0 : _this$props2$options.filter,
86
- params: this === null || this === void 0 ? void 0 : (_this$props3 = this.props) === null || _this$props3 === void 0 ? void 0 : (_this$props3$options = _this$props3.options) === null || _this$props3$options === void 0 ? void 0 : _this$props3$options.params,
87
- showIncrements: this.state.showIncrements,
88
- resetOrderTransaction: this.state.resetOrderTransaction
89
- });
90
- }
91
-
92
- }
93
-
94
- exports.default = OrderableDocumentList;
95
-
96
- _defineProperty(OrderableDocumentList, "propTypes", {
97
- options: _propTypes.default.shape({
98
- type: _propTypes.default.string,
99
- filter: _propTypes.default.string,
100
- params: _propTypes.default.object
101
- }).isRequired
102
- });
103
- //# sourceMappingURL=OrderableDocumentList.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OrderableDocumentList.js","names":["OrderableDocumentList","Component","constructor","props","showIncrements","setState","state","resetOrder","resetOrderTransaction","status","title","closable","update","options","type","reorderWasSuccessful","results","length","render","filter","params","PropTypes","shape","string","object","isRequired"],"sources":["../src/OrderableDocumentList.js"],"sourcesContent":["import PropTypes from 'prop-types'\nimport React, {Component} from 'react'\n\nimport DocumentListWrapper from './DocumentListWrapper'\nimport {resetOrder} from './helpers/resetOrder'\n\n// Must use a Class Component here so the actionHandlers can be called\nexport default class OrderableDocumentList extends Component {\n static propTypes = {\n options: PropTypes.shape({\n type: PropTypes.string,\n filter: PropTypes.string,\n params: PropTypes.object,\n }).isRequired,\n }\n\n constructor(props) {\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)\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 return (\n <DocumentListWrapper\n type={this?.props?.options?.type}\n filter={this?.props?.options?.filter}\n params={this?.props?.options?.params}\n showIncrements={this.state.showIncrements}\n resetOrderTransaction={this.state.resetOrderTransaction}\n />\n )\n }\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;;;;;;;;;;;;;AAEA;AACe,MAAMA,qBAAN,SAAoCC,gBAApC,CAA8C;EAS3DC,WAAW,CAACC,KAAD,EAAQ;IAAA;;IACjB,MAAMA,KAAN,CADiB;IAAA;;IAAA,wCAQF;MACfC,cAAc,EAAE,MAAM;QACpB,KAAKC,QAAL,CAAeC,KAAD,KAAY;UACxBF,cAAc,EAAE,CAACE,KAAK,CAACF;QADC,CAAZ,CAAd;MAGD,CALc;MAOfG,UAAU;QAAA,qCAAE,aAAY;UAAA;;UACtB,KAAI,CAACF,QAAL,CAAc,OAAO;YACnBG,qBAAqB,EAAE;cACrBC,MAAM,QADe;cAErBC,KAAK,yBAFgB;cAGrBC,QAAQ,EAAE;YAHW;UADJ,CAAP,CAAd;;UAQA,IAAMC,MAAM,SAAS,IAAAL,uBAAA,EAAW,KAAI,CAACJ,KAAL,CAAWU,OAAX,CAAmBC,IAA9B,CAArB;UAEA,IAAMC,oBAAoB,GAAGH,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entListDeskItem = orderableDocumentListDeskItem;
7
-
8
- var _structureBuilder = _interopRequireDefault(require("@sanity/desk-tool/structure-builder"));
9
-
10
- var _icons = require("@sanity/icons");
11
-
12
- var _schema = _interopRequireDefault(require("part:@sanity/base/schema"));
13
-
14
- var _OrderableDocumentList = _interopRequireDefault(require("../OrderableDocumentList"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function orderableDocumentListDeskItem() {
19
- var _schema$get$title, _schema$get;
20
-
21
- var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
22
-
23
- if (!(config !== null && config !== void 0 && config.type)) {
24
- throw new Error("\n \"type\" not defined in orderableDocumentListDeskItem parameters.\n \n\n\n Example: orderableDocumentListDeskItem({type: 'category'})\n ");
25
- }
26
-
27
- var type = config.type,
28
- filter = config.filter,
29
- params = config.params,
30
- title = config.title,
31
- icon = config.icon,
32
- id = config.id;
33
- var listTitle = title !== null && title !== void 0 ? title : "Orderable ".concat(type);
34
- var listId = id !== null && id !== void 0 ? id : "orderable-".concat(type);
35
- var listIcon = icon !== null && icon !== void 0 ? icon : _icons.SortIcon;
36
- var typeTitle = (_schema$get$title = (_schema$get = _schema.default.get(type)) === null || _schema$get === void 0 ? void 0 : _schema$get.title) !== null && _schema$get$title !== void 0 ? _schema$get$title : type;
37
- return _structureBuilder.default.listItem(type).title(listTitle).id(listId).icon(listIcon).child(Object.assign(_structureBuilder.default.documentTypeList(type).serialize(), {
38
- // Prevents the component from re-rendering when switching documents
39
- __preserveInstance: true,
40
- // Prevents the component from NOT re-rendering when switching listItems
41
- key: listId,
42
- type: 'component',
43
- component: _OrderableDocumentList.default,
44
- options: {
45
- type,
46
- filter,
47
- params
48
- },
49
- menuItems: [_structureBuilder.default.menuItem().title("Create new ".concat(typeTitle)).intent({
50
- type: 'create',
51
- params: {
52
- type
53
- }
54
- }).serialize(), _structureBuilder.default.menuItem().title("Reset Order").icon(_icons.GenerateIcon).action("resetOrder").serialize(), _structureBuilder.default.menuItem().title("Show Increments").icon(_icons.SortIcon).action("showIncrements").serialize()]
55
- })).serialize();
56
- }
57
- //# sourceMappingURL=orderableDocumentListDeskItem.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"orderableDocumentListDeskItem.js","names":["orderableDocumentListDeskItem","config","type","Error","filter","params","title","icon","id","listTitle","listId","listIcon","SortIcon","typeTitle","schema","get","S","listItem","child","Object","assign","documentTypeList","serialize","__preserveInstance","key","component","OrderableDocumentList","options","menuItems","menuItem","intent","GenerateIcon","action"],"sources":["../../src/desk-structure/orderableDocumentListDeskItem.js"],"sourcesContent":["import S from '@sanity/desk-tool/structure-builder'\nimport {SortIcon, GenerateIcon} from '@sanity/icons'\nimport schema from 'part:@sanity/base/schema'\n\nimport OrderableDocumentList from '../OrderableDocumentList'\n\nexport function orderableDocumentListDeskItem(config = {}) {\n if (!config?.type) {\n throw new Error(`\n \"type\" not defined in orderableDocumentListDeskItem parameters.\n \\n\\n\n Example: orderableDocumentListDeskItem({type: 'category'})\n `)\n }\n\n const {type, filter, params, title, icon, id} = config\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 return S.listItem(type)\n .title(listTitle)\n .id(listId)\n .icon(listIcon)\n .child(\n Object.assign(S.documentTypeList(type).serialize(), {\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},\n menuItems: [\n S.menuItem()\n .title(`Create new ${typeTitle}`)\n .intent({type: 'create', params: {type}})\n .serialize(),\n S.menuItem().title(`Reset Order`).icon(GenerateIcon).action(`resetOrder`).serialize(),\n S.menuItem().title(`Show Increments`).icon(SortIcon).action(`showIncrements`).serialize(),\n ],\n })\n )\n .serialize()\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAE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