@strapi/content-manager 5.60.0 → 5.61.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.
Files changed (256) hide show
  1. package/dist/admin/constants/customOrder.js +14 -0
  2. package/dist/admin/constants/customOrder.js.map +1 -0
  3. package/dist/admin/constants/customOrder.mjs +10 -0
  4. package/dist/admin/constants/customOrder.mjs.map +1 -0
  5. package/dist/admin/hooks/useDocument.js +22 -11
  6. package/dist/admin/hooks/useDocument.js.map +1 -1
  7. package/dist/admin/hooks/useDocument.mjs +22 -11
  8. package/dist/admin/hooks/useDocument.mjs.map +1 -1
  9. package/dist/admin/hooks/useDocumentLayout.js.map +1 -1
  10. package/dist/admin/hooks/useDocumentLayout.mjs.map +1 -1
  11. package/dist/admin/hooks/useHasBeenNearViewport.js +70 -0
  12. package/dist/admin/hooks/useHasBeenNearViewport.js.map +1 -0
  13. package/dist/admin/hooks/useHasBeenNearViewport.mjs +46 -0
  14. package/dist/admin/hooks/useHasBeenNearViewport.mjs.map +1 -0
  15. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Image.js +102 -32
  16. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Image.js.map +1 -1
  17. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Image.mjs +104 -35
  18. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Image.mjs.map +1 -1
  19. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/List.js +20 -17
  20. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/List.js.map +1 -1
  21. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/List.mjs +20 -17
  22. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/List.mjs.map +1 -1
  23. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js +15 -1
  24. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js.map +1 -1
  25. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs +17 -3
  26. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs.map +1 -1
  27. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/plugins/withStrapiSchema.js +21 -0
  28. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/plugins/withStrapiSchema.js.map +1 -1
  29. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/plugins/withStrapiSchema.mjs +22 -1
  30. package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/plugins/withStrapiSchema.mjs.map +1 -1
  31. package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js +4 -7
  32. package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js.map +1 -1
  33. package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.mjs +4 -7
  34. package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.mjs.map +1 -1
  35. package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js +46 -10
  36. package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js.map +1 -1
  37. package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs +47 -11
  38. package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs.map +1 -1
  39. package/dist/admin/pages/EditView/components/FormLayout.js +201 -51
  40. package/dist/admin/pages/EditView/components/FormLayout.js.map +1 -1
  41. package/dist/admin/pages/EditView/components/FormLayout.mjs +202 -53
  42. package/dist/admin/pages/EditView/components/FormLayout.mjs.map +1 -1
  43. package/dist/admin/pages/ListConfiguration/components/Settings.js +31 -2
  44. package/dist/admin/pages/ListConfiguration/components/Settings.js.map +1 -1
  45. package/dist/admin/pages/ListConfiguration/components/Settings.mjs +31 -2
  46. package/dist/admin/pages/ListConfiguration/components/Settings.mjs.map +1 -1
  47. package/dist/admin/pages/ListView/ListViewPage.js +196 -132
  48. package/dist/admin/pages/ListView/ListViewPage.js.map +1 -1
  49. package/dist/admin/pages/ListView/ListViewPage.mjs +196 -132
  50. package/dist/admin/pages/ListView/ListViewPage.mjs.map +1 -1
  51. package/dist/admin/pages/ListView/components/CustomOrder.js +571 -0
  52. package/dist/admin/pages/ListView/components/CustomOrder.js.map +1 -0
  53. package/dist/admin/pages/ListView/components/CustomOrder.mjs +546 -0
  54. package/dist/admin/pages/ListView/components/CustomOrder.mjs.map +1 -0
  55. package/dist/admin/pages/ListView/components/TableActions.js +4 -1
  56. package/dist/admin/pages/ListView/components/TableActions.js.map +1 -1
  57. package/dist/admin/pages/ListView/components/TableActions.mjs +4 -1
  58. package/dist/admin/pages/ListView/components/TableActions.mjs.map +1 -1
  59. package/dist/admin/services/documents.js +22 -1
  60. package/dist/admin/services/documents.js.map +1 -1
  61. package/dist/admin/services/documents.mjs +21 -2
  62. package/dist/admin/services/documents.mjs.map +1 -1
  63. package/dist/admin/src/constants/customOrder.d.ts +8 -0
  64. package/dist/admin/src/exports.d.ts +1 -1
  65. package/dist/admin/src/hooks/useDocument.d.ts +4 -0
  66. package/dist/admin/src/hooks/useDocumentLayout.d.ts +6 -2
  67. package/dist/admin/src/hooks/useHasBeenNearViewport.d.ts +13 -0
  68. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Image.d.ts +13 -1
  69. package/dist/admin/src/pages/EditView/components/FormLayout.d.ts +11 -1
  70. package/dist/admin/src/pages/ListView/components/CustomOrder.d.ts +72 -0
  71. package/dist/admin/src/services/documents.d.ts +10 -2
  72. package/dist/admin/translations/en.json.js +9 -0
  73. package/dist/admin/translations/en.json.js.map +1 -1
  74. package/dist/admin/translations/en.json.mjs +9 -0
  75. package/dist/admin/translations/en.json.mjs.map +1 -1
  76. package/dist/server/audit-logs.js +36 -0
  77. package/dist/server/audit-logs.js.map +1 -0
  78. package/dist/server/audit-logs.mjs +33 -0
  79. package/dist/server/audit-logs.mjs.map +1 -0
  80. package/dist/server/bootstrap.js +8 -0
  81. package/dist/server/bootstrap.js.map +1 -1
  82. package/dist/server/bootstrap.mjs +8 -0
  83. package/dist/server/bootstrap.mjs.map +1 -1
  84. package/dist/server/controllers/collection-types.js +8 -0
  85. package/dist/server/controllers/collection-types.js.map +1 -1
  86. package/dist/server/controllers/collection-types.mjs +8 -0
  87. package/dist/server/controllers/collection-types.mjs.map +1 -1
  88. package/dist/server/controllers/content-types.js +15 -0
  89. package/dist/server/controllers/content-types.js.map +1 -1
  90. package/dist/server/controllers/content-types.mjs +16 -1
  91. package/dist/server/controllers/content-types.mjs.map +1 -1
  92. package/dist/server/controllers/index.js +3 -1
  93. package/dist/server/controllers/index.js.map +1 -1
  94. package/dist/server/controllers/index.mjs +2 -0
  95. package/dist/server/controllers/index.mjs.map +1 -1
  96. package/dist/server/controllers/relations.js +5 -1
  97. package/dist/server/controllers/relations.js.map +1 -1
  98. package/dist/server/controllers/relations.mjs +5 -1
  99. package/dist/server/controllers/relations.mjs.map +1 -1
  100. package/dist/server/controllers/single-types.js +10 -1
  101. package/dist/server/controllers/single-types.js.map +1 -1
  102. package/dist/server/controllers/single-types.mjs +10 -1
  103. package/dist/server/controllers/single-types.mjs.map +1 -1
  104. package/dist/server/controllers/validation/model-configuration.js +2 -1
  105. package/dist/server/controllers/validation/model-configuration.js.map +1 -1
  106. package/dist/server/controllers/validation/model-configuration.mjs +2 -1
  107. package/dist/server/controllers/validation/model-configuration.mjs.map +1 -1
  108. package/dist/server/custom-order/constants.js +21 -0
  109. package/dist/server/custom-order/constants.js.map +1 -0
  110. package/dist/server/custom-order/constants.mjs +17 -0
  111. package/dist/server/custom-order/constants.mjs.map +1 -0
  112. package/dist/server/custom-order/controllers/custom-order.js +77 -0
  113. package/dist/server/custom-order/controllers/custom-order.js.map +1 -0
  114. package/dist/server/custom-order/controllers/custom-order.mjs +75 -0
  115. package/dist/server/custom-order/controllers/custom-order.mjs.map +1 -0
  116. package/dist/server/custom-order/controllers/index.js +10 -0
  117. package/dist/server/custom-order/controllers/index.js.map +1 -0
  118. package/dist/server/custom-order/controllers/index.mjs +8 -0
  119. package/dist/server/custom-order/controllers/index.mjs.map +1 -0
  120. package/dist/server/custom-order/index.js +71 -0
  121. package/dist/server/custom-order/index.js.map +1 -0
  122. package/dist/server/custom-order/index.mjs +69 -0
  123. package/dist/server/custom-order/index.mjs.map +1 -0
  124. package/dist/server/custom-order/routes/custom-order.js +38 -0
  125. package/dist/server/custom-order/routes/custom-order.js.map +1 -0
  126. package/dist/server/custom-order/routes/custom-order.mjs +36 -0
  127. package/dist/server/custom-order/routes/custom-order.mjs.map +1 -0
  128. package/dist/server/custom-order/routes/index.js +13 -0
  129. package/dist/server/custom-order/routes/index.js.map +1 -0
  130. package/dist/server/custom-order/routes/index.mjs +11 -0
  131. package/dist/server/custom-order/routes/index.mjs.map +1 -0
  132. package/dist/server/custom-order/services/custom-order.js +286 -0
  133. package/dist/server/custom-order/services/custom-order.js.map +1 -0
  134. package/dist/server/custom-order/services/custom-order.mjs +284 -0
  135. package/dist/server/custom-order/services/custom-order.mjs.map +1 -0
  136. package/dist/server/custom-order/services/document-middleware.js +83 -0
  137. package/dist/server/custom-order/services/document-middleware.js.map +1 -0
  138. package/dist/server/custom-order/services/document-middleware.mjs +81 -0
  139. package/dist/server/custom-order/services/document-middleware.mjs.map +1 -0
  140. package/dist/server/custom-order/services/index.js +10 -0
  141. package/dist/server/custom-order/services/index.js.map +1 -0
  142. package/dist/server/custom-order/services/index.mjs +8 -0
  143. package/dist/server/custom-order/services/index.mjs.map +1 -0
  144. package/dist/server/custom-order/services/utils.js +152 -0
  145. package/dist/server/custom-order/services/utils.js.map +1 -0
  146. package/dist/server/custom-order/services/utils.mjs +148 -0
  147. package/dist/server/custom-order/services/utils.mjs.map +1 -0
  148. package/dist/server/custom-order/utils.js +13 -0
  149. package/dist/server/custom-order/utils.js.map +1 -0
  150. package/dist/server/custom-order/utils.mjs +10 -0
  151. package/dist/server/custom-order/utils.mjs.map +1 -0
  152. package/dist/server/history/constants.js +2 -1
  153. package/dist/server/history/constants.js.map +1 -1
  154. package/dist/server/history/constants.mjs +2 -1
  155. package/dist/server/history/constants.mjs.map +1 -1
  156. package/dist/server/history/controllers/history-version.js +6 -2
  157. package/dist/server/history/controllers/history-version.js.map +1 -1
  158. package/dist/server/history/controllers/history-version.mjs +6 -2
  159. package/dist/server/history/controllers/history-version.mjs.map +1 -1
  160. package/dist/server/history/services/history.js +23 -6
  161. package/dist/server/history/services/history.js.map +1 -1
  162. package/dist/server/history/services/history.mjs +24 -7
  163. package/dist/server/history/services/history.mjs.map +1 -1
  164. package/dist/server/history/services/lifecycles.js +2 -16
  165. package/dist/server/history/services/lifecycles.js.map +1 -1
  166. package/dist/server/history/services/lifecycles.mjs +2 -16
  167. package/dist/server/history/services/lifecycles.mjs.map +1 -1
  168. package/dist/server/register.js +4 -0
  169. package/dist/server/register.js.map +1 -1
  170. package/dist/server/register.mjs +4 -0
  171. package/dist/server/register.mjs.map +1 -1
  172. package/dist/server/routes/index.js +3 -1
  173. package/dist/server/routes/index.js.map +1 -1
  174. package/dist/server/routes/index.mjs +2 -0
  175. package/dist/server/routes/index.mjs.map +1 -1
  176. package/dist/server/services/content-types.js +2 -2
  177. package/dist/server/services/content-types.js.map +1 -1
  178. package/dist/server/services/content-types.mjs +2 -2
  179. package/dist/server/services/content-types.mjs.map +1 -1
  180. package/dist/server/services/document-manager.js +13 -0
  181. package/dist/server/services/document-manager.js.map +1 -1
  182. package/dist/server/services/document-manager.mjs +14 -1
  183. package/dist/server/services/document-manager.mjs.map +1 -1
  184. package/dist/server/services/index.js +3 -1
  185. package/dist/server/services/index.js.map +1 -1
  186. package/dist/server/services/index.mjs +2 -0
  187. package/dist/server/services/index.mjs.map +1 -1
  188. package/dist/server/services/utils/configuration/settings.js +2 -1
  189. package/dist/server/services/utils/configuration/settings.js.map +1 -1
  190. package/dist/server/services/utils/configuration/settings.mjs +2 -1
  191. package/dist/server/services/utils/configuration/settings.mjs.map +1 -1
  192. package/dist/server/src/audit-logs.d.ts +40 -0
  193. package/dist/server/src/audit-logs.d.ts.map +1 -0
  194. package/dist/server/src/bootstrap.d.ts.map +1 -1
  195. package/dist/server/src/controllers/collection-types.d.ts +1 -1
  196. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  197. package/dist/server/src/controllers/content-types.d.ts.map +1 -1
  198. package/dist/server/src/controllers/index.d.ts +21 -3
  199. package/dist/server/src/controllers/index.d.ts.map +1 -1
  200. package/dist/server/src/controllers/relations.d.ts +19 -1
  201. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  202. package/dist/server/src/controllers/single-types.d.ts +1 -1
  203. package/dist/server/src/controllers/single-types.d.ts.map +1 -1
  204. package/dist/server/src/custom-order/constants.d.ts +18 -0
  205. package/dist/server/src/custom-order/constants.d.ts.map +1 -0
  206. package/dist/server/src/custom-order/controllers/custom-order.d.ts +8 -0
  207. package/dist/server/src/custom-order/controllers/custom-order.d.ts.map +1 -0
  208. package/dist/server/src/custom-order/controllers/index.d.ts +3 -0
  209. package/dist/server/src/custom-order/controllers/index.d.ts.map +1 -0
  210. package/dist/server/src/custom-order/index.d.ts +8 -0
  211. package/dist/server/src/custom-order/index.d.ts.map +1 -0
  212. package/dist/server/src/custom-order/routes/custom-order.d.ts +4 -0
  213. package/dist/server/src/custom-order/routes/custom-order.d.ts.map +1 -0
  214. package/dist/server/src/custom-order/routes/index.d.ts +10 -0
  215. package/dist/server/src/custom-order/routes/index.d.ts.map +1 -0
  216. package/dist/server/src/custom-order/services/custom-order.d.ts +43 -0
  217. package/dist/server/src/custom-order/services/custom-order.d.ts.map +1 -0
  218. package/dist/server/src/custom-order/services/document-middleware.d.ts +16 -0
  219. package/dist/server/src/custom-order/services/document-middleware.d.ts.map +1 -0
  220. package/dist/server/src/custom-order/services/index.d.ts +24 -0
  221. package/dist/server/src/custom-order/services/index.d.ts.map +1 -0
  222. package/dist/server/src/custom-order/services/utils.d.ts +34 -0
  223. package/dist/server/src/custom-order/services/utils.d.ts.map +1 -0
  224. package/dist/server/src/custom-order/utils.d.ts +6 -0
  225. package/dist/server/src/custom-order/utils.d.ts.map +1 -0
  226. package/dist/server/src/history/constants.d.ts.map +1 -1
  227. package/dist/server/src/history/controllers/history-version.d.ts.map +1 -1
  228. package/dist/server/src/history/services/history.d.ts.map +1 -1
  229. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  230. package/dist/server/src/index.d.ts +22 -6
  231. package/dist/server/src/index.d.ts.map +1 -1
  232. package/dist/server/src/register.d.ts.map +1 -1
  233. package/dist/server/src/routes/index.d.ts.map +1 -1
  234. package/dist/server/src/services/content-types.d.ts +1 -3
  235. package/dist/server/src/services/content-types.d.ts.map +1 -1
  236. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  237. package/dist/server/src/services/index.d.ts +1 -3
  238. package/dist/server/src/services/index.d.ts.map +1 -1
  239. package/dist/server/src/services/utils/configuration/settings.d.ts.map +1 -1
  240. package/dist/shared/contracts/content-types.d.ts +5 -0
  241. package/dist/shared/contracts/content-types.d.ts.map +1 -1
  242. package/dist/shared/contracts/custom-order.d.ts +33 -0
  243. package/dist/shared/contracts/custom-order.d.ts.map +1 -0
  244. package/dist/shared/contracts/custom-order.js +3 -0
  245. package/dist/shared/contracts/custom-order.js.map +1 -0
  246. package/dist/shared/contracts/custom-order.mjs +2 -0
  247. package/dist/shared/contracts/custom-order.mjs.map +1 -0
  248. package/dist/shared/contracts/history-versions.d.ts +0 -1
  249. package/dist/shared/contracts/history-versions.d.ts.map +1 -1
  250. package/dist/shared/contracts/index.d.ts +1 -0
  251. package/dist/shared/contracts/index.d.ts.map +1 -1
  252. package/dist/shared/contracts/index.js +2 -0
  253. package/dist/shared/contracts/index.js.map +1 -1
  254. package/dist/shared/contracts/index.mjs +2 -0
  255. package/dist/shared/contracts/index.mjs.map +1 -1
  256. package/package.json +8 -8
@@ -0,0 +1,571 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var React = require('react');
5
+ var core = require('@dnd-kit/core');
6
+ var sortable = require('@dnd-kit/sortable');
7
+ var utilities = require('@dnd-kit/utilities');
8
+ var query = require('@reduxjs/toolkit/query');
9
+ var strapiAdmin = require('@strapi/admin/strapi-admin');
10
+ var designSystem = require('@strapi/design-system');
11
+ var Icons = require('@strapi/icons');
12
+ var reactIntl = require('react-intl');
13
+ var reactRedux = require('react-redux');
14
+ var styledComponents = require('styled-components');
15
+ var customOrder = require('../../../constants/customOrder.js');
16
+ var documents = require('../../../services/documents.js');
17
+ var translations = require('../../../utils/translations.js');
18
+
19
+ function _interopNamespace(e) {
20
+ if (e && e.__esModule) return e;
21
+ var n = Object.create(null);
22
+ if (e) {
23
+ Object.keys(e).forEach(function (k) {
24
+ if (k !== 'default') {
25
+ var d = Object.getOwnPropertyDescriptor(e, k);
26
+ Object.defineProperty(n, k, d.get ? d : {
27
+ enumerable: true,
28
+ get: function () { return e[k]; }
29
+ });
30
+ }
31
+ });
32
+ }
33
+ n.default = e;
34
+ return Object.freeze(n);
35
+ }
36
+
37
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
38
+
39
+ /**
40
+ * How many times the list is asked again after a move before giving up. Each attempt waits
41
+ * for a whole request, so two are enough in practice (see `refetchList`).
42
+ */ const MAX_REFETCH_ATTEMPTS = 3;
43
+ const useCustomOrder = ({ model, isAvailable, canUpdate, sort, params, results, pagination })=>{
44
+ const { formatMessage } = reactIntl.useIntl();
45
+ const { toggleNotification } = strapiAdmin.useNotification();
46
+ const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler(translations.getTranslation);
47
+ const [moveDocument] = documents.useMoveDocumentMutation();
48
+ const [fetchDocuments] = documents.useLazyGetAllDocumentsQuery();
49
+ const store = reactRedux.useStore();
50
+ const [isMoving, setIsMoving] = React__namespace.useState(false);
51
+ // Same value for the handlers, which may run again before React has rendered the state
52
+ const isMovingRef = React__namespace.useRef(false);
53
+ /** Order to display until the move has landed, when it stays within the page. */ const [pendingOrder, setPendingOrder] = React__namespace.useState(null);
54
+ const isActive = isAvailable && sort?.toUpperCase() === customOrder.CUSTOM_ORDER_SORT.toUpperCase();
55
+ /**
56
+ * The list is fetched again after each move. Until that answer lands, the table keeps
57
+ * showing its rows instead of a loading state, which would make every move blink.
58
+ * Any other answer landing in the meantime does not touch the order shown.
59
+ */ const rows = React__namespace.useMemo(()=>{
60
+ if (!isMoving || !pendingOrder) {
61
+ return results;
62
+ }
63
+ const rowsById = new Map(results.map((row)=>[
64
+ row.documentId,
65
+ row
66
+ ]));
67
+ return pendingOrder.flatMap((documentId)=>rowsById.get(documentId) ?? []);
68
+ }, [
69
+ isMoving,
70
+ pendingOrder,
71
+ results
72
+ ]);
73
+ const offset = pagination ? (pagination.page - 1) * pagination.pageSize : 0;
74
+ const total = pagination?.total ?? results.length;
75
+ const locale = typeof params.locale === 'string' ? params.locale : undefined;
76
+ /**
77
+ * Runs a move while blocking any other one: from the moment it is asked until the list
78
+ * shows its result, the handles, the position inputs and the row actions are inert.
79
+ */ const runExclusively = async (run)=>{
80
+ if (isMovingRef.current) {
81
+ return;
82
+ }
83
+ isMovingRef.current = true;
84
+ setIsMoving(true);
85
+ try {
86
+ await run();
87
+ } finally{
88
+ isMovingRef.current = false;
89
+ setPendingOrder(null);
90
+ setIsMoving(false);
91
+ }
92
+ };
93
+ /**
94
+ * Resolves once no request of the list is in flight anymore.
95
+ */ const waitForList = (queryCacheKey)=>new Promise((resolve)=>{
96
+ const isSettled = ()=>store.getState().adminApi.queries[queryCacheKey]?.status !== query.QueryStatus.pending;
97
+ if (isSettled()) {
98
+ resolve();
99
+ return;
100
+ }
101
+ const unsubscribe = store.subscribe(()=>{
102
+ if (isSettled()) {
103
+ unsubscribe();
104
+ resolve();
105
+ }
106
+ });
107
+ });
108
+ /**
109
+ * Waits for the list to be fetched again after a move. The mutation invalidates the list,
110
+ * but RTK Query drops that refetch when another request is already in flight, and that
111
+ * request may have started before the server applied the move. So the list is asked again
112
+ * until a request started after the move was answered, otherwise the table could settle on
113
+ * a stale snapshot. An attempt is dropped the same way when a request is in flight: it
114
+ * then waits for that request, which is the one the mutation started most of the time.
115
+ *
116
+ * @param movedAt - When the server answered the move
117
+ */ const refetchList = async (movedAt)=>{
118
+ for(let attempt = 0; attempt < MAX_REFETCH_ATTEMPTS; attempt += 1){
119
+ const request = fetchDocuments({
120
+ model,
121
+ params
122
+ });
123
+ const { requestId, startedTimeStamp = 0 } = await request;
124
+ // The page subscribes to the list itself
125
+ request.unsubscribe();
126
+ if (requestId === request.requestId) {
127
+ return;
128
+ }
129
+ await waitForList(request.queryCacheKey);
130
+ if (startedTimeStamp >= movedAt) {
131
+ return;
132
+ }
133
+ }
134
+ };
135
+ const move = async (documentId, anchorId, placement, order)=>{
136
+ if (order) {
137
+ setPendingOrder(order);
138
+ }
139
+ const mutation = moveDocument({
140
+ model,
141
+ id: documentId,
142
+ body: placement === 'before' ? {
143
+ before: anchorId
144
+ } : {
145
+ after: anchorId
146
+ },
147
+ params: {
148
+ locale
149
+ }
150
+ });
151
+ const res = await mutation;
152
+ if ('error' in res) {
153
+ setPendingOrder(null);
154
+ toggleNotification({
155
+ type: 'danger',
156
+ message: formatAPIError(res.error)
157
+ });
158
+ return false;
159
+ }
160
+ const { fulfilledTimeStamp: movedAt = Date.now() } = store.getState().adminApi.mutations[mutation.requestId] ?? {};
161
+ await refetchList(movedAt);
162
+ return true;
163
+ };
164
+ const moveWithinPage = (from, to)=>{
165
+ const moved = rows[from];
166
+ const anchor = rows[to];
167
+ return move(moved.documentId, anchor.documentId, to > from ? 'after' : 'before', sortable.arrayMove(rows, from, to).map((row)=>row.documentId));
168
+ };
169
+ const moveToIndex = async (from, to)=>{
170
+ if (from === to || !rows[from] || !rows[to]) {
171
+ return;
172
+ }
173
+ await runExclusively(async ()=>{
174
+ await moveWithinPage(from, to);
175
+ });
176
+ };
177
+ const moveToPosition = async (documentId, position)=>{
178
+ const from = rows.findIndex((row)=>row.documentId === documentId);
179
+ if (from === -1 || total === 0) {
180
+ return;
181
+ }
182
+ const currentPosition = offset + from + 1;
183
+ const targetPosition = Math.min(Math.max(Math.trunc(position), 1), total);
184
+ if (targetPosition === currentPosition) {
185
+ return;
186
+ }
187
+ const to = targetPosition - offset - 1;
188
+ await runExclusively(async ()=>{
189
+ if (to >= 0 && to < rows.length) {
190
+ await moveWithinPage(from, to);
191
+ return;
192
+ }
193
+ // The destination is on another page: ask the server which entry sits there in this view
194
+ const lookup = fetchDocuments({
195
+ model,
196
+ params: {
197
+ ...params,
198
+ page: String(targetPosition),
199
+ pageSize: '1'
200
+ }
201
+ });
202
+ const res = await lookup;
203
+ // Otherwise every later invalidation of the list would fetch that entry again
204
+ lookup.unsubscribe();
205
+ if (res.error) {
206
+ toggleNotification({
207
+ type: 'danger',
208
+ message: formatAPIError(res.error)
209
+ });
210
+ return;
211
+ }
212
+ const anchor = res.data?.results[0];
213
+ if (!anchor) {
214
+ return;
215
+ }
216
+ const hasMoved = await move(documentId, anchor.documentId, targetPosition > currentPosition ? 'after' : 'before');
217
+ if (hasMoved) {
218
+ toggleNotification({
219
+ type: 'success',
220
+ message: formatMessage({
221
+ id: translations.getTranslation('custom-order.moved'),
222
+ defaultMessage: 'Entry moved to position {position}'
223
+ }, {
224
+ position: targetPosition
225
+ })
226
+ });
227
+ }
228
+ });
229
+ };
230
+ return {
231
+ isAvailable,
232
+ isActive,
233
+ canReorder: isActive && canUpdate,
234
+ isMoving,
235
+ rows,
236
+ total,
237
+ getPosition (documentId) {
238
+ const index = rows.findIndex((row)=>row.documentId === documentId);
239
+ return index === -1 ? undefined : offset + index + 1;
240
+ },
241
+ moveToIndex,
242
+ moveToPosition
243
+ };
244
+ };
245
+ const CustomOrderContext = /*#__PURE__*/ React__namespace.createContext({
246
+ isAvailable: false,
247
+ isActive: false,
248
+ canReorder: false,
249
+ isMoving: false,
250
+ rows: [],
251
+ total: 0,
252
+ getPosition: ()=>undefined,
253
+ moveToIndex: async ()=>{},
254
+ moveToPosition: async ()=>{}
255
+ });
256
+ /* -------------------------------------------------------------------------------------------------
257
+ * Root
258
+ * -----------------------------------------------------------------------------------------------*/ const restrictToVerticalAxis = ({ transform })=>({
259
+ ...transform,
260
+ x: 0
261
+ });
262
+ /**
263
+ * Has to wrap the whole table: the drag and drop context renders elements for screen
264
+ * readers next to its children, and those are not valid inside a table.
265
+ */ const Root = ({ children, state })=>{
266
+ // Entries are dragged with a pointer only. The grid owns the arrow keys, so the keyboard
267
+ // goes through the position input and the row actions instead.
268
+ const sensors = core.useSensors(core.useSensor(core.PointerSensor, {
269
+ activationConstraint: {
270
+ distance: 4
271
+ }
272
+ }));
273
+ const items = React__namespace.useMemo(()=>state.rows.map((row)=>row.documentId), [
274
+ state.rows
275
+ ]);
276
+ if (!state.isAvailable) {
277
+ return children;
278
+ }
279
+ const handleDragEnd = ({ active, over })=>{
280
+ if (!over || active.id === over.id) {
281
+ return;
282
+ }
283
+ void state.moveToIndex(items.indexOf(String(active.id)), items.indexOf(String(over.id)));
284
+ };
285
+ return /*#__PURE__*/ jsxRuntime.jsx(CustomOrderContext.Provider, {
286
+ value: state,
287
+ children: /*#__PURE__*/ jsxRuntime.jsx(core.DndContext, {
288
+ sensors: sensors,
289
+ collisionDetection: core.closestCenter,
290
+ modifiers: [
291
+ restrictToVerticalAxis
292
+ ],
293
+ onDragEnd: handleDragEnd,
294
+ children: /*#__PURE__*/ jsxRuntime.jsx(sortable.SortableContext, {
295
+ items: items,
296
+ strategy: sortable.verticalListSortingStrategy,
297
+ disabled: !state.canReorder || state.isMoving,
298
+ children: children
299
+ })
300
+ })
301
+ });
302
+ };
303
+ const SortableRowContext = /*#__PURE__*/ React__namespace.createContext(null);
304
+ /**
305
+ * A table row that can be dragged when the entries follow a custom order,
306
+ * a regular table row otherwise.
307
+ */ const Row = ({ documentId, ...props })=>{
308
+ const { isAvailable } = React__namespace.useContext(CustomOrderContext);
309
+ if (!isAvailable) {
310
+ return /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Table.Row, {
311
+ ...props
312
+ });
313
+ }
314
+ return /*#__PURE__*/ jsxRuntime.jsx(DraggableRow, {
315
+ documentId: documentId,
316
+ ...props
317
+ });
318
+ };
319
+ const DraggableRow = ({ documentId, style, ...props })=>{
320
+ const { setNodeRef, setActivatorNodeRef, listeners, transform, transition, isDragging } = sortable.useSortable({
321
+ id: documentId
322
+ });
323
+ const sortableRow = React__namespace.useMemo(()=>({
324
+ setNodeRef,
325
+ setActivatorNodeRef,
326
+ listeners,
327
+ isDragging
328
+ }), [
329
+ setNodeRef,
330
+ setActivatorNodeRef,
331
+ listeners,
332
+ isDragging
333
+ ]);
334
+ // The provider has to stay outside of the row, which only expects cells as children
335
+ return /*#__PURE__*/ jsxRuntime.jsx(SortableRowContext.Provider, {
336
+ value: sortableRow,
337
+ children: /*#__PURE__*/ jsxRuntime.jsx(StyledRow, {
338
+ ...props,
339
+ $isDragging: isDragging,
340
+ style: {
341
+ ...style,
342
+ transform: utilities.CSS.Translate.toString(transform),
343
+ transition
344
+ }
345
+ })
346
+ });
347
+ };
348
+ const StyledRow = styledComponents.styled(strapiAdmin.Table.Row)`
349
+ ${({ $isDragging, theme })=>$isDragging && styledComponents.css`
350
+ position: relative;
351
+ z-index: 1;
352
+ background: ${theme.colors.primary100};
353
+ box-shadow: ${theme.shadows.tableShadow};
354
+ `}
355
+ `;
356
+ const PositionCell = ({ documentId, position, total, ...props })=>{
357
+ const { formatMessage } = reactIntl.useIntl();
358
+ const { isActive, canReorder, isMoving, moveToPosition } = React__namespace.useContext(CustomOrderContext);
359
+ const sortableRow = React__namespace.useContext(SortableRowContext);
360
+ const [isEditing, setIsEditing] = React__namespace.useState(false);
361
+ const buttonRef = React__namespace.useRef(null);
362
+ const shouldRestoreFocus = React__namespace.useRef(false);
363
+ /**
364
+ * Table rows don't forward their ref, so the row is reached through its cell.
365
+ */ const setRowNode = sortableRow?.setNodeRef;
366
+ const setCellNode = React__namespace.useCallback((node)=>{
367
+ setRowNode?.(node?.parentElement ?? null);
368
+ }, [
369
+ setRowNode
370
+ ]);
371
+ /**
372
+ * The button is disabled while the entry moves, and a disabled button cannot take the
373
+ * focus: when the input was left to move the entry, the focus comes back once the move
374
+ * is over.
375
+ */ React__namespace.useEffect(()=>{
376
+ if (!isEditing && !isMoving && shouldRestoreFocus.current) {
377
+ shouldRestoreFocus.current = false;
378
+ buttonRef.current?.focus();
379
+ }
380
+ }, [
381
+ isEditing,
382
+ isMoving
383
+ ]);
384
+ const handleKeyDown = (e)=>{
385
+ // Keeps the keys typed in the input away from the keyboard navigation of the grid
386
+ e.stopPropagation();
387
+ if (e.key === 'Enter') {
388
+ e.preventDefault();
389
+ shouldRestoreFocus.current = true;
390
+ setIsEditing(false);
391
+ const nextPosition = Number.parseInt(e.currentTarget.value, 10);
392
+ if (!Number.isNaN(nextPosition)) {
393
+ void moveToPosition(documentId, nextPosition);
394
+ }
395
+ } else if (e.key === 'Escape') {
396
+ shouldRestoreFocus.current = true;
397
+ setIsEditing(false);
398
+ }
399
+ };
400
+ const renderPosition = ()=>{
401
+ if (!canReorder) {
402
+ return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
403
+ textColor: "neutral800",
404
+ children: position
405
+ });
406
+ }
407
+ if (isEditing) {
408
+ return /*#__PURE__*/ jsxRuntime.jsx(PositionInput, {
409
+ // eslint-disable-next-line jsx-a11y/no-autofocus -- the input replaces the button that was just activated
410
+ autoFocus: true,
411
+ "aria-label": formatMessage({
412
+ id: translations.getTranslation('custom-order.position.input'),
413
+ defaultMessage: 'New position, from 1 to {total}'
414
+ }, {
415
+ total
416
+ }),
417
+ defaultValue: position,
418
+ inputMode: "numeric",
419
+ onBlur: ()=>setIsEditing(false),
420
+ onFocus: (e)=>e.currentTarget.select(),
421
+ onKeyDown: handleKeyDown
422
+ });
423
+ }
424
+ return /*#__PURE__*/ jsxRuntime.jsx(PositionButton, {
425
+ ref: buttonRef,
426
+ type: "button",
427
+ "aria-label": formatMessage({
428
+ id: translations.getTranslation('custom-order.position.button'),
429
+ defaultMessage: 'Position {position} of {total}, change position'
430
+ }, {
431
+ position,
432
+ total
433
+ }),
434
+ disabled: isMoving,
435
+ onClick: ()=>setIsEditing(true),
436
+ children: position
437
+ });
438
+ };
439
+ return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Td, {
440
+ ref: setCellNode,
441
+ ...props,
442
+ onClick: (e)=>e.stopPropagation(),
443
+ children: isActive ? /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
444
+ gap: 1,
445
+ alignItems: "center",
446
+ children: [
447
+ canReorder ? /*#__PURE__*/ jsxRuntime.jsx(Handle, {
448
+ ref: sortableRow?.setActivatorNodeRef,
449
+ ...sortableRow?.listeners,
450
+ "aria-hidden": true,
451
+ $isDragging: sortableRow?.isDragging ?? false,
452
+ children: /*#__PURE__*/ jsxRuntime.jsx(Icons.Drag, {})
453
+ }) : null,
454
+ renderPosition()
455
+ ]
456
+ }) : /*#__PURE__*/ jsxRuntime.jsx(designSystem.Tooltip, {
457
+ label: formatMessage({
458
+ id: translations.getTranslation('custom-order.inactive'),
459
+ defaultMessage: 'Sort by order to move entries'
460
+ }),
461
+ children: /*#__PURE__*/ jsxRuntime.jsx(InactiveHandle, {
462
+ children: /*#__PURE__*/ jsxRuntime.jsx(Icons.Drag, {})
463
+ })
464
+ })
465
+ });
466
+ };
467
+ const Handle = styledComponents.styled.span`
468
+ display: flex;
469
+ align-items: center;
470
+ padding: ${({ theme })=>theme.spaces[1]};
471
+ color: ${({ theme })=>theme.colors.neutral500};
472
+ cursor: ${({ $isDragging })=>$isDragging ? 'grabbing' : 'grab'};
473
+ /* Lets a finger drag the row instead of scrolling the page */
474
+ touch-action: none;
475
+
476
+ &:hover {
477
+ color: ${({ theme })=>theme.colors.neutral700};
478
+ }
479
+ `;
480
+ const InactiveHandle = styledComponents.styled.span`
481
+ display: inline-flex;
482
+ align-items: center;
483
+ padding: ${({ theme })=>theme.spaces[1]};
484
+ color: ${({ theme })=>theme.colors.neutral300};
485
+ `;
486
+ const positionControl = styledComponents.css`
487
+ width: 4.8rem;
488
+ height: 3.2rem;
489
+ padding: 0 ${({ theme })=>theme.spaces[2]};
490
+ border: 1px solid transparent;
491
+ border-radius: ${({ theme })=>theme.borderRadius};
492
+ background: transparent;
493
+ color: ${({ theme })=>theme.colors.neutral800};
494
+ font-size: ${({ theme })=>theme.fontSizes[2]};
495
+ text-align: left;
496
+ `;
497
+ const PositionButton = styledComponents.styled.button`
498
+ ${positionControl}
499
+ cursor: text;
500
+
501
+ &:hover:not(:disabled),
502
+ &:focus-visible {
503
+ border-color: ${({ theme })=>theme.colors.neutral200};
504
+ background: ${({ theme })=>theme.colors.neutral0};
505
+ }
506
+
507
+ &:disabled {
508
+ cursor: default;
509
+ }
510
+ `;
511
+ const PositionInput = styledComponents.styled.input`
512
+ ${positionControl}
513
+ border-color: ${({ theme })=>theme.colors.primary600};
514
+ background: ${({ theme })=>theme.colors.neutral0};
515
+ outline: none;
516
+ box-shadow: ${({ theme })=>theme.colors.primary600} 0px 0px 0px 2px;
517
+ `;
518
+ /* -------------------------------------------------------------------------------------------------
519
+ * Row actions
520
+ * -----------------------------------------------------------------------------------------------*/ const MoveToTopAction = ({ documentId })=>{
521
+ const { formatMessage } = reactIntl.useIntl();
522
+ const { canReorder, isMoving, getPosition, moveToPosition } = React__namespace.useContext(CustomOrderContext);
523
+ if (!canReorder || !documentId) {
524
+ return null;
525
+ }
526
+ return {
527
+ disabled: isMoving || getPosition(documentId) === 1,
528
+ icon: /*#__PURE__*/ jsxRuntime.jsx(Icons.ArrowUp, {}),
529
+ label: formatMessage({
530
+ id: 'content-manager.actions.move-to-top.label',
531
+ defaultMessage: 'Move to top'
532
+ }),
533
+ position: 'table-row',
534
+ onClick: ()=>{
535
+ void moveToPosition(documentId, 1);
536
+ }
537
+ };
538
+ };
539
+ MoveToTopAction.position = 'table-row';
540
+ const MoveToBottomAction = ({ documentId })=>{
541
+ const { formatMessage } = reactIntl.useIntl();
542
+ const { canReorder, isMoving, total, getPosition, moveToPosition } = React__namespace.useContext(CustomOrderContext);
543
+ if (!canReorder || !documentId) {
544
+ return null;
545
+ }
546
+ return {
547
+ disabled: isMoving || getPosition(documentId) === total,
548
+ icon: /*#__PURE__*/ jsxRuntime.jsx(Icons.ArrowDown, {}),
549
+ label: formatMessage({
550
+ id: 'content-manager.actions.move-to-bottom.label',
551
+ defaultMessage: 'Move to bottom'
552
+ }),
553
+ position: 'table-row',
554
+ onClick: ()=>{
555
+ // Positions past the end are brought back to the last one
556
+ void moveToPosition(documentId, Number.MAX_SAFE_INTEGER);
557
+ }
558
+ };
559
+ };
560
+ MoveToBottomAction.position = 'table-row';
561
+ const CustomOrder = {
562
+ Root,
563
+ Row,
564
+ PositionCell
565
+ };
566
+
567
+ exports.CustomOrder = CustomOrder;
568
+ exports.MoveToBottomAction = MoveToBottomAction;
569
+ exports.MoveToTopAction = MoveToTopAction;
570
+ exports.useCustomOrder = useCustomOrder;
571
+ //# sourceMappingURL=CustomOrder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomOrder.js","sources":["../../../../../admin/src/pages/ListView/components/CustomOrder.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n DndContext,\n PointerSensor,\n closestCenter,\n useSensor,\n useSensors,\n type DragEndEvent,\n type Modifier,\n} from '@dnd-kit/core';\nimport {\n SortableContext,\n arrayMove,\n useSortable,\n verticalListSortingStrategy,\n} from '@dnd-kit/sortable';\nimport { CSS } from '@dnd-kit/utilities';\nimport { QueryStatus } from '@reduxjs/toolkit/query';\nimport { Table, useAPIErrorHandler, useNotification } from '@strapi/admin/strapi-admin';\nimport { Flex, Td, Tooltip, Typography } from '@strapi/design-system';\nimport { ArrowDown, ArrowUp, Drag } from '@strapi/icons';\nimport { useIntl } from 'react-intl';\nimport { useStore } from 'react-redux';\nimport { css, styled } from 'styled-components';\n\nimport { CUSTOM_ORDER_SORT } from '../../../constants/customOrder';\nimport { useLazyGetAllDocumentsQuery, useMoveDocumentMutation } from '../../../services/documents';\nimport { getTranslation } from '../../../utils/translations';\n\nimport type { DocumentActionComponent } from '../../../content-manager';\nimport type { Document } from '../../../hooks/useDocument';\nimport type { Store } from '@strapi/admin/strapi-admin';\n\n/* -------------------------------------------------------------------------------------------------\n * useCustomOrder\n * -----------------------------------------------------------------------------------------------*/\n\ninterface CustomOrderState {\n /** Custom order is turned on for the content type. */\n isAvailable: boolean;\n /** The list is sorted by its custom order, so the position of an entry means something. */\n isActive: boolean;\n /** The user is allowed to move entries, and the list is in a state where they can be moved. */\n canReorder: boolean;\n /**\n * A move is in progress: from the moment it is asked until the list shows its result.\n * No other move can start in the meantime.\n */\n isMoving: boolean;\n /** The entries of the page, in the order they should be displayed. */\n rows: Document[];\n /** Number of entries in the current view, all pages included. */\n total: number;\n /** 1-based position of an entry of the page in the current view. */\n getPosition: (documentId: string) => number | undefined;\n /** Moves an entry of the page to the place of another entry of the page. */\n moveToIndex: (from: number, to: number) => Promise<void>;\n /** Moves an entry of the page to a position of the current view, on this page or another. */\n moveToPosition: (documentId: string, position: number) => Promise<void>;\n}\n\ninterface UseCustomOrderOptions {\n model: string;\n isAvailable: boolean;\n canUpdate: boolean;\n sort?: string;\n /**\n * Params of the list request. Reused to find which entry sits at a given position\n * of the same view when it is not on the current page.\n */\n params: Record<string, unknown>;\n results: Document[];\n pagination?: { page: number; pageSize: number; total: number };\n /**\n * Not needed anymore: the hook fetches the list again itself after a move and knows when\n * that answer lands. Still accepted so that existing callers keep compiling.\n */\n fulfilledTimeStamp?: number;\n}\n\n/**\n * How many times the list is asked again after a move before giving up. Each attempt waits\n * for a whole request, so two are enough in practice (see `refetchList`).\n */\nconst MAX_REFETCH_ATTEMPTS = 3;\n\nconst useCustomOrder = ({\n model,\n isAvailable,\n canUpdate,\n sort,\n params,\n results,\n pagination,\n}: UseCustomOrderOptions): CustomOrderState => {\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler(getTranslation);\n const [moveDocument] = useMoveDocumentMutation();\n const [fetchDocuments] = useLazyGetAllDocumentsQuery();\n const store = useStore<ReturnType<Store['getState']>>();\n\n const [isMoving, setIsMoving] = React.useState(false);\n // Same value for the handlers, which may run again before React has rendered the state\n const isMovingRef = React.useRef(false);\n /** Order to display until the move has landed, when it stays within the page. */\n const [pendingOrder, setPendingOrder] = React.useState<string[] | null>(null);\n\n const isActive = isAvailable && sort?.toUpperCase() === CUSTOM_ORDER_SORT.toUpperCase();\n\n /**\n * The list is fetched again after each move. Until that answer lands, the table keeps\n * showing its rows instead of a loading state, which would make every move blink.\n * Any other answer landing in the meantime does not touch the order shown.\n */\n const rows = React.useMemo(() => {\n if (!isMoving || !pendingOrder) {\n return results;\n }\n\n const rowsById = new Map(results.map((row) => [row.documentId, row]));\n\n return pendingOrder.flatMap((documentId) => rowsById.get(documentId) ?? []);\n }, [isMoving, pendingOrder, results]);\n\n const offset = pagination ? (pagination.page - 1) * pagination.pageSize : 0;\n const total = pagination?.total ?? results.length;\n const locale = typeof params.locale === 'string' ? params.locale : undefined;\n\n /**\n * Runs a move while blocking any other one: from the moment it is asked until the list\n * shows its result, the handles, the position inputs and the row actions are inert.\n */\n const runExclusively = async (run: () => Promise<void>) => {\n if (isMovingRef.current) {\n return;\n }\n\n isMovingRef.current = true;\n setIsMoving(true);\n\n try {\n await run();\n } finally {\n isMovingRef.current = false;\n setPendingOrder(null);\n setIsMoving(false);\n }\n };\n\n /**\n * Resolves once no request of the list is in flight anymore.\n */\n const waitForList = (queryCacheKey: string) =>\n new Promise<void>((resolve) => {\n const isSettled = () =>\n store.getState().adminApi.queries[queryCacheKey]?.status !== QueryStatus.pending;\n\n if (isSettled()) {\n resolve();\n\n return;\n }\n\n const unsubscribe = store.subscribe(() => {\n if (isSettled()) {\n unsubscribe();\n resolve();\n }\n });\n });\n\n /**\n * Waits for the list to be fetched again after a move. The mutation invalidates the list,\n * but RTK Query drops that refetch when another request is already in flight, and that\n * request may have started before the server applied the move. So the list is asked again\n * until a request started after the move was answered, otherwise the table could settle on\n * a stale snapshot. An attempt is dropped the same way when a request is in flight: it\n * then waits for that request, which is the one the mutation started most of the time.\n *\n * @param movedAt - When the server answered the move\n */\n const refetchList = async (movedAt: number) => {\n for (let attempt = 0; attempt < MAX_REFETCH_ATTEMPTS; attempt += 1) {\n const request = fetchDocuments({ model, params });\n const { requestId, startedTimeStamp = 0 } = await request;\n // The page subscribes to the list itself\n request.unsubscribe();\n\n if (requestId === request.requestId) {\n return;\n }\n\n await waitForList(request.queryCacheKey);\n\n if (startedTimeStamp >= movedAt) {\n return;\n }\n }\n };\n\n const move = async (\n documentId: string,\n anchorId: string,\n placement: 'before' | 'after',\n order?: string[]\n ) => {\n if (order) {\n setPendingOrder(order);\n }\n\n const mutation = moveDocument({\n model,\n id: documentId,\n body: placement === 'before' ? { before: anchorId } : { after: anchorId },\n params: { locale },\n });\n const res = await mutation;\n\n if ('error' in res) {\n setPendingOrder(null);\n toggleNotification({ type: 'danger', message: formatAPIError(res.error) });\n\n return false;\n }\n\n const { fulfilledTimeStamp: movedAt = Date.now() } =\n store.getState().adminApi.mutations[mutation.requestId] ?? {};\n\n await refetchList(movedAt);\n\n return true;\n };\n\n const moveWithinPage = (from: number, to: number) => {\n const moved = rows[from];\n const anchor = rows[to];\n\n return move(\n moved.documentId,\n anchor.documentId,\n to > from ? 'after' : 'before',\n arrayMove(rows, from, to).map((row) => row.documentId)\n );\n };\n\n const moveToIndex: CustomOrderState['moveToIndex'] = async (from, to) => {\n if (from === to || !rows[from] || !rows[to]) {\n return;\n }\n\n await runExclusively(async () => {\n await moveWithinPage(from, to);\n });\n };\n\n const moveToPosition: CustomOrderState['moveToPosition'] = async (documentId, position) => {\n const from = rows.findIndex((row) => row.documentId === documentId);\n\n if (from === -1 || total === 0) {\n return;\n }\n\n const currentPosition = offset + from + 1;\n const targetPosition = Math.min(Math.max(Math.trunc(position), 1), total);\n\n if (targetPosition === currentPosition) {\n return;\n }\n\n const to = targetPosition - offset - 1;\n\n await runExclusively(async () => {\n if (to >= 0 && to < rows.length) {\n await moveWithinPage(from, to);\n\n return;\n }\n\n // The destination is on another page: ask the server which entry sits there in this view\n const lookup = fetchDocuments({\n model,\n params: { ...params, page: String(targetPosition), pageSize: '1' },\n });\n const res = await lookup;\n // Otherwise every later invalidation of the list would fetch that entry again\n lookup.unsubscribe();\n\n if (res.error) {\n toggleNotification({ type: 'danger', message: formatAPIError(res.error) });\n\n return;\n }\n\n const anchor = res.data?.results[0];\n\n if (!anchor) {\n return;\n }\n\n const hasMoved = await move(\n documentId,\n anchor.documentId,\n targetPosition > currentPosition ? 'after' : 'before'\n );\n\n if (hasMoved) {\n toggleNotification({\n type: 'success',\n message: formatMessage(\n {\n id: getTranslation('custom-order.moved'),\n defaultMessage: 'Entry moved to position {position}',\n },\n { position: targetPosition }\n ),\n });\n }\n });\n };\n\n return {\n isAvailable,\n isActive,\n canReorder: isActive && canUpdate,\n isMoving,\n rows,\n total,\n getPosition(documentId) {\n const index = rows.findIndex((row) => row.documentId === documentId);\n\n return index === -1 ? undefined : offset + index + 1;\n },\n moveToIndex,\n moveToPosition,\n };\n};\n\nconst CustomOrderContext = React.createContext<CustomOrderState>({\n isAvailable: false,\n isActive: false,\n canReorder: false,\n isMoving: false,\n rows: [],\n total: 0,\n getPosition: () => undefined,\n moveToIndex: async () => {},\n moveToPosition: async () => {},\n});\n\n/* -------------------------------------------------------------------------------------------------\n * Root\n * -----------------------------------------------------------------------------------------------*/\n\nconst restrictToVerticalAxis: Modifier = ({ transform }) => ({ ...transform, x: 0 });\n\ninterface RootProps {\n children: React.ReactNode;\n state: CustomOrderState;\n}\n\n/**\n * Has to wrap the whole table: the drag and drop context renders elements for screen\n * readers next to its children, and those are not valid inside a table.\n */\nconst Root = ({ children, state }: RootProps) => {\n // Entries are dragged with a pointer only. The grid owns the arrow keys, so the keyboard\n // goes through the position input and the row actions instead.\n const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 4 } }));\n const items = React.useMemo(() => state.rows.map((row) => row.documentId), [state.rows]);\n\n if (!state.isAvailable) {\n return children;\n }\n\n const handleDragEnd = ({ active, over }: DragEndEvent) => {\n if (!over || active.id === over.id) {\n return;\n }\n\n void state.moveToIndex(items.indexOf(String(active.id)), items.indexOf(String(over.id)));\n };\n\n return (\n <CustomOrderContext.Provider value={state}>\n <DndContext\n sensors={sensors}\n collisionDetection={closestCenter}\n modifiers={[restrictToVerticalAxis]}\n onDragEnd={handleDragEnd}\n >\n <SortableContext\n items={items}\n strategy={verticalListSortingStrategy}\n disabled={!state.canReorder || state.isMoving}\n >\n {children}\n </SortableContext>\n </DndContext>\n </CustomOrderContext.Provider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Row\n * -----------------------------------------------------------------------------------------------*/\n\ntype SortableRow = Pick<\n ReturnType<typeof useSortable>,\n 'setNodeRef' | 'setActivatorNodeRef' | 'listeners' | 'isDragging'\n>;\n\nconst SortableRowContext = React.createContext<SortableRow | null>(null);\n\ntype RowProps = React.ComponentProps<typeof Table.Row> & {\n documentId: string;\n};\n\n/**\n * A table row that can be dragged when the entries follow a custom order,\n * a regular table row otherwise.\n */\nconst Row = ({ documentId, ...props }: RowProps) => {\n const { isAvailable } = React.useContext(CustomOrderContext);\n\n if (!isAvailable) {\n return <Table.Row {...props} />;\n }\n\n return <DraggableRow documentId={documentId} {...props} />;\n};\n\nconst DraggableRow = ({ documentId, style, ...props }: RowProps) => {\n const { setNodeRef, setActivatorNodeRef, listeners, transform, transition, isDragging } =\n useSortable({ id: documentId });\n\n const sortableRow = React.useMemo(\n () => ({ setNodeRef, setActivatorNodeRef, listeners, isDragging }),\n [setNodeRef, setActivatorNodeRef, listeners, isDragging]\n );\n\n // The provider has to stay outside of the row, which only expects cells as children\n return (\n <SortableRowContext.Provider value={sortableRow}>\n <StyledRow\n {...props}\n $isDragging={isDragging}\n style={{ ...style, transform: CSS.Translate.toString(transform), transition }}\n />\n </SortableRowContext.Provider>\n );\n};\n\nconst StyledRow = styled(Table.Row)<{ $isDragging: boolean }>`\n ${({ $isDragging, theme }) =>\n $isDragging &&\n css`\n position: relative;\n z-index: 1;\n background: ${theme.colors.primary100};\n box-shadow: ${theme.shadows.tableShadow};\n `}\n`;\n\n/* -------------------------------------------------------------------------------------------------\n * PositionCell\n * -----------------------------------------------------------------------------------------------*/\n\ntype PositionCellProps = React.ComponentProps<typeof Td> & {\n documentId: string;\n position: number;\n total: number;\n};\n\nconst PositionCell = ({ documentId, position, total, ...props }: PositionCellProps) => {\n const { formatMessage } = useIntl();\n const { isActive, canReorder, isMoving, moveToPosition } = React.useContext(CustomOrderContext);\n const sortableRow = React.useContext(SortableRowContext);\n const [isEditing, setIsEditing] = React.useState(false);\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n const shouldRestoreFocus = React.useRef(false);\n\n /**\n * Table rows don't forward their ref, so the row is reached through its cell.\n */\n const setRowNode = sortableRow?.setNodeRef;\n const setCellNode = React.useCallback(\n (node: HTMLTableCellElement | null) => {\n setRowNode?.(node?.parentElement ?? null);\n },\n [setRowNode]\n );\n\n /**\n * The button is disabled while the entry moves, and a disabled button cannot take the\n * focus: when the input was left to move the entry, the focus comes back once the move\n * is over.\n */\n React.useEffect(() => {\n if (!isEditing && !isMoving && shouldRestoreFocus.current) {\n shouldRestoreFocus.current = false;\n buttonRef.current?.focus();\n }\n }, [isEditing, isMoving]);\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n // Keeps the keys typed in the input away from the keyboard navigation of the grid\n e.stopPropagation();\n\n if (e.key === 'Enter') {\n e.preventDefault();\n shouldRestoreFocus.current = true;\n setIsEditing(false);\n\n const nextPosition = Number.parseInt(e.currentTarget.value, 10);\n\n if (!Number.isNaN(nextPosition)) {\n void moveToPosition(documentId, nextPosition);\n }\n } else if (e.key === 'Escape') {\n shouldRestoreFocus.current = true;\n setIsEditing(false);\n }\n };\n\n const renderPosition = () => {\n if (!canReorder) {\n return <Typography textColor=\"neutral800\">{position}</Typography>;\n }\n\n if (isEditing) {\n return (\n <PositionInput\n // eslint-disable-next-line jsx-a11y/no-autofocus -- the input replaces the button that was just activated\n autoFocus\n aria-label={formatMessage(\n {\n id: getTranslation('custom-order.position.input'),\n defaultMessage: 'New position, from 1 to {total}',\n },\n { total }\n )}\n defaultValue={position}\n inputMode=\"numeric\"\n onBlur={() => setIsEditing(false)}\n onFocus={(e) => e.currentTarget.select()}\n onKeyDown={handleKeyDown}\n />\n );\n }\n\n return (\n <PositionButton\n ref={buttonRef}\n type=\"button\"\n aria-label={formatMessage(\n {\n id: getTranslation('custom-order.position.button'),\n defaultMessage: 'Position {position} of {total}, change position',\n },\n { position, total }\n )}\n disabled={isMoving}\n onClick={() => setIsEditing(true)}\n >\n {position}\n </PositionButton>\n );\n };\n\n return (\n <Td ref={setCellNode} {...props} onClick={(e: React.MouseEvent) => e.stopPropagation()}>\n {isActive ? (\n <Flex gap={1} alignItems=\"center\">\n {canReorder ? (\n <Handle\n ref={sortableRow?.setActivatorNodeRef}\n {...sortableRow?.listeners}\n aria-hidden\n $isDragging={sortableRow?.isDragging ?? false}\n >\n <Drag />\n </Handle>\n ) : null}\n {renderPosition()}\n </Flex>\n ) : (\n <Tooltip\n label={formatMessage({\n id: getTranslation('custom-order.inactive'),\n defaultMessage: 'Sort by order to move entries',\n })}\n >\n <InactiveHandle>\n <Drag />\n </InactiveHandle>\n </Tooltip>\n )}\n </Td>\n );\n};\n\nconst Handle = styled.span<{ $isDragging: boolean }>`\n display: flex;\n align-items: center;\n padding: ${({ theme }) => theme.spaces[1]};\n color: ${({ theme }) => theme.colors.neutral500};\n cursor: ${({ $isDragging }) => ($isDragging ? 'grabbing' : 'grab')};\n /* Lets a finger drag the row instead of scrolling the page */\n touch-action: none;\n\n &:hover {\n color: ${({ theme }) => theme.colors.neutral700};\n }\n`;\n\nconst InactiveHandle = styled.span`\n display: inline-flex;\n align-items: center;\n padding: ${({ theme }) => theme.spaces[1]};\n color: ${({ theme }) => theme.colors.neutral300};\n`;\n\nconst positionControl = css`\n width: 4.8rem;\n height: 3.2rem;\n padding: 0 ${({ theme }) => theme.spaces[2]};\n border: 1px solid transparent;\n border-radius: ${({ theme }) => theme.borderRadius};\n background: transparent;\n color: ${({ theme }) => theme.colors.neutral800};\n font-size: ${({ theme }) => theme.fontSizes[2]};\n text-align: left;\n`;\n\nconst PositionButton = styled.button`\n ${positionControl}\n cursor: text;\n\n &:hover:not(:disabled),\n &:focus-visible {\n border-color: ${({ theme }) => theme.colors.neutral200};\n background: ${({ theme }) => theme.colors.neutral0};\n }\n\n &:disabled {\n cursor: default;\n }\n`;\n\nconst PositionInput = styled.input`\n ${positionControl}\n border-color: ${({ theme }) => theme.colors.primary600};\n background: ${({ theme }) => theme.colors.neutral0};\n outline: none;\n box-shadow: ${({ theme }) => theme.colors.primary600} 0px 0px 0px 2px;\n`;\n\n/* -------------------------------------------------------------------------------------------------\n * Row actions\n * -----------------------------------------------------------------------------------------------*/\n\nconst MoveToTopAction: DocumentActionComponent = ({ documentId }) => {\n const { formatMessage } = useIntl();\n const { canReorder, isMoving, getPosition, moveToPosition } =\n React.useContext(CustomOrderContext);\n\n if (!canReorder || !documentId) {\n return null;\n }\n\n return {\n disabled: isMoving || getPosition(documentId) === 1,\n icon: <ArrowUp />,\n label: formatMessage({\n id: 'content-manager.actions.move-to-top.label',\n defaultMessage: 'Move to top',\n }),\n position: 'table-row',\n onClick: () => {\n void moveToPosition(documentId, 1);\n },\n };\n};\n\nMoveToTopAction.position = 'table-row';\n\nconst MoveToBottomAction: DocumentActionComponent = ({ documentId }) => {\n const { formatMessage } = useIntl();\n const { canReorder, isMoving, total, getPosition, moveToPosition } =\n React.useContext(CustomOrderContext);\n\n if (!canReorder || !documentId) {\n return null;\n }\n\n return {\n disabled: isMoving || getPosition(documentId) === total,\n icon: <ArrowDown />,\n label: formatMessage({\n id: 'content-manager.actions.move-to-bottom.label',\n defaultMessage: 'Move to bottom',\n }),\n position: 'table-row',\n onClick: () => {\n // Positions past the end are brought back to the last one\n void moveToPosition(documentId, Number.MAX_SAFE_INTEGER);\n },\n };\n};\n\nMoveToBottomAction.position = 'table-row';\n\nconst CustomOrder = {\n Root,\n Row,\n PositionCell,\n};\n\nexport { CustomOrder, useCustomOrder, MoveToTopAction, MoveToBottomAction };\nexport type { CustomOrderState };\n"],"names":["MAX_REFETCH_ATTEMPTS","useCustomOrder","model","isAvailable","canUpdate","sort","params","results","pagination","formatMessage","useIntl","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","getTranslation","moveDocument","useMoveDocumentMutation","fetchDocuments","useLazyGetAllDocumentsQuery","store","useStore","isMoving","setIsMoving","React","useState","isMovingRef","useRef","pendingOrder","setPendingOrder","isActive","toUpperCase","CUSTOM_ORDER_SORT","rows","useMemo","rowsById","Map","map","row","documentId","flatMap","get","offset","page","pageSize","total","length","locale","undefined","runExclusively","run","current","waitForList","queryCacheKey","Promise","resolve","isSettled","getState","adminApi","queries","status","QueryStatus","pending","unsubscribe","subscribe","refetchList","movedAt","attempt","request","requestId","startedTimeStamp","move","anchorId","placement","order","mutation","id","body","before","after","res","type","message","error","fulfilledTimeStamp","Date","now","mutations","moveWithinPage","from","to","moved","anchor","arrayMove","moveToIndex","moveToPosition","position","findIndex","currentPosition","targetPosition","Math","min","max","trunc","lookup","String","data","hasMoved","defaultMessage","canReorder","getPosition","index","CustomOrderContext","createContext","restrictToVerticalAxis","transform","x","Root","children","state","sensors","useSensors","useSensor","PointerSensor","activationConstraint","distance","items","handleDragEnd","active","over","indexOf","_jsx","Provider","value","DndContext","collisionDetection","closestCenter","modifiers","onDragEnd","SortableContext","strategy","verticalListSortingStrategy","disabled","SortableRowContext","Row","props","useContext","Table","DraggableRow","style","setNodeRef","setActivatorNodeRef","listeners","transition","isDragging","useSortable","sortableRow","StyledRow","$isDragging","CSS","Translate","toString","styled","theme","css","colors","primary100","shadows","tableShadow","PositionCell","isEditing","setIsEditing","buttonRef","shouldRestoreFocus","setRowNode","setCellNode","useCallback","node","parentElement","useEffect","focus","handleKeyDown","e","stopPropagation","key","preventDefault","nextPosition","Number","parseInt","currentTarget","isNaN","renderPosition","Typography","textColor","PositionInput","autoFocus","aria-label","defaultValue","inputMode","onBlur","onFocus","select","onKeyDown","PositionButton","ref","onClick","Td","_jsxs","Flex","gap","alignItems","Handle","aria-hidden","Drag","Tooltip","label","InactiveHandle","span","spaces","neutral500","neutral700","neutral300","positionControl","borderRadius","neutral800","fontSizes","button","neutral200","neutral0","input","primary600","MoveToTopAction","icon","ArrowUp","MoveToBottomAction","ArrowDown","MAX_SAFE_INTEGER","CustomOrder"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA;;;AAGC,IACD,MAAMA,oBAAAA,GAAuB,CAAA;AAE7B,MAAMC,iBAAiB,CAAC,EACtBC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,IAAI,EACJC,MAAM,EACNC,OAAO,EACPC,UAAU,EACY,GAAA;IACtB,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;IAC1B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,8BAAAA,CAAmBC,2BAAAA,CAAAA;IACvE,MAAM,CAACC,aAAa,GAAGC,iCAAAA,EAAAA;IACvB,MAAM,CAACC,eAAe,GAAGC,qCAAAA,EAAAA;AACzB,IAAA,MAAMC,KAAAA,GAAQC,mBAAAA,EAAAA;AAEd,IAAA,MAAM,CAACC,QAAAA,EAAUC,WAAAA,CAAY,GAAGC,gBAAAA,CAAMC,QAAQ,CAAC,KAAA,CAAA;;IAE/C,MAAMC,WAAAA,GAAcF,gBAAAA,CAAMG,MAAM,CAAC,KAAA,CAAA;sFAEjC,MAAM,CAACC,YAAAA,EAAcC,gBAAgB,GAAGL,gBAAAA,CAAMC,QAAQ,CAAkB,IAAA,CAAA;AAExE,IA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