@strapi/content-manager 5.8.1 → 5.10.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 (435) hide show
  1. package/dist/admin/chunks/CardDragPreview-DwuraT0K.mjs +80 -0
  2. package/dist/admin/chunks/CardDragPreview-DwuraT0K.mjs.map +1 -0
  3. package/dist/admin/chunks/CardDragPreview-_dubYgXO.js +82 -0
  4. package/dist/admin/chunks/CardDragPreview-_dubYgXO.js.map +1 -0
  5. package/dist/admin/chunks/ComponentConfigurationPage-BN2kOtDm.mjs +277 -0
  6. package/dist/admin/chunks/ComponentConfigurationPage-BN2kOtDm.mjs.map +1 -0
  7. package/dist/admin/chunks/ComponentConfigurationPage-C5H-5L1u.js +299 -0
  8. package/dist/admin/chunks/ComponentConfigurationPage-C5H-5L1u.js.map +1 -0
  9. package/dist/admin/chunks/ComponentIcon-BZcTc4rj.mjs +153 -0
  10. package/dist/admin/chunks/ComponentIcon-BZcTc4rj.mjs.map +1 -0
  11. package/dist/admin/chunks/ComponentIcon-C-EjOUPA.js +176 -0
  12. package/dist/admin/chunks/ComponentIcon-C-EjOUPA.js.map +1 -0
  13. package/dist/admin/chunks/EditConfigurationPage-BExtZuB7.js +181 -0
  14. package/dist/admin/chunks/EditConfigurationPage-BExtZuB7.js.map +1 -0
  15. package/dist/admin/chunks/EditConfigurationPage-tMgOELQG.mjs +159 -0
  16. package/dist/admin/chunks/EditConfigurationPage-tMgOELQG.mjs.map +1 -0
  17. package/dist/admin/chunks/EditViewPage-CYe7wAXF.mjs +314 -0
  18. package/dist/admin/chunks/EditViewPage-CYe7wAXF.mjs.map +1 -0
  19. package/dist/admin/chunks/EditViewPage-DFkloeMZ.js +337 -0
  20. package/dist/admin/chunks/EditViewPage-DFkloeMZ.js.map +1 -0
  21. package/dist/admin/chunks/FieldTypeIcon-BY6MrVF4.mjs +56 -0
  22. package/dist/admin/chunks/FieldTypeIcon-BY6MrVF4.mjs.map +1 -0
  23. package/dist/admin/chunks/FieldTypeIcon-Bxh-7Jin.js +58 -0
  24. package/dist/admin/chunks/FieldTypeIcon-Bxh-7Jin.js.map +1 -0
  25. package/dist/admin/chunks/Form-DGUP3zQO.js +978 -0
  26. package/dist/admin/chunks/Form-DGUP3zQO.js.map +1 -0
  27. package/dist/admin/chunks/Form-DTO0ZIaB.mjs +955 -0
  28. package/dist/admin/chunks/Form-DTO0ZIaB.mjs.map +1 -0
  29. package/dist/admin/chunks/History-C333pgXF.mjs +1357 -0
  30. package/dist/admin/chunks/History-C333pgXF.mjs.map +1 -0
  31. package/dist/admin/chunks/History-CQznK1pG.js +1380 -0
  32. package/dist/admin/chunks/History-CQznK1pG.js.map +1 -0
  33. package/dist/admin/chunks/Input-BexkC_pp.mjs +7190 -0
  34. package/dist/admin/chunks/Input-BexkC_pp.mjs.map +1 -0
  35. package/dist/admin/chunks/Input-DLJZHw9Y.js +7221 -0
  36. package/dist/admin/chunks/Input-DLJZHw9Y.js.map +1 -0
  37. package/dist/admin/chunks/ListConfigurationPage-71I_stAM.js +819 -0
  38. package/dist/admin/chunks/ListConfigurationPage-71I_stAM.js.map +1 -0
  39. package/dist/admin/chunks/ListConfigurationPage-BX2WR7MI.mjs +796 -0
  40. package/dist/admin/chunks/ListConfigurationPage-BX2WR7MI.mjs.map +1 -0
  41. package/dist/admin/chunks/ListViewPage-BDeT3Dkk.mjs +1133 -0
  42. package/dist/admin/chunks/ListViewPage-BDeT3Dkk.mjs.map +1 -0
  43. package/dist/admin/chunks/ListViewPage-DV3heO4F.js +1155 -0
  44. package/dist/admin/chunks/ListViewPage-DV3heO4F.js.map +1 -0
  45. package/dist/admin/chunks/NoContentTypePage-9JHYpYVX.mjs +58 -0
  46. package/dist/admin/chunks/NoContentTypePage-9JHYpYVX.mjs.map +1 -0
  47. package/dist/admin/chunks/NoContentTypePage-COih9y2J.js +60 -0
  48. package/dist/admin/chunks/NoContentTypePage-COih9y2J.js.map +1 -0
  49. package/dist/admin/chunks/NoPermissionsPage-DGAwRIlN.js +39 -0
  50. package/dist/admin/chunks/NoPermissionsPage-DGAwRIlN.js.map +1 -0
  51. package/dist/admin/chunks/NoPermissionsPage-DTe9I47q.mjs +37 -0
  52. package/dist/admin/chunks/NoPermissionsPage-DTe9I47q.mjs.map +1 -0
  53. package/dist/admin/chunks/Preview-BEq0FXda.mjs +551 -0
  54. package/dist/admin/chunks/Preview-BEq0FXda.mjs.map +1 -0
  55. package/dist/admin/chunks/Preview-CXtc9yEV.js +573 -0
  56. package/dist/admin/chunks/Preview-CXtc9yEV.js.map +1 -0
  57. package/dist/admin/chunks/Relations-o7_hVGyK.js +1318 -0
  58. package/dist/admin/chunks/Relations-o7_hVGyK.js.map +1 -0
  59. package/dist/admin/chunks/Relations-qeZyLDgQ.mjs +1291 -0
  60. package/dist/admin/chunks/Relations-qeZyLDgQ.mjs.map +1 -0
  61. package/dist/admin/chunks/ar-DckYq_WK.mjs +222 -0
  62. package/dist/{_chunks/ar-CCEVvqGG.mjs.map → admin/chunks/ar-DckYq_WK.mjs.map} +1 -1
  63. package/dist/admin/chunks/ar-DeQBSsfl.js +227 -0
  64. package/dist/{_chunks/ru-BT3ybNny.js.map → admin/chunks/ar-DeQBSsfl.js.map} +1 -1
  65. package/dist/admin/chunks/ca-ClDTvatJ.js +202 -0
  66. package/dist/admin/chunks/ca-ClDTvatJ.js.map +1 -0
  67. package/dist/admin/chunks/ca-DviY7mRj.mjs +197 -0
  68. package/dist/admin/chunks/ca-DviY7mRj.mjs.map +1 -0
  69. package/dist/admin/chunks/cs-BJFxwIWj.js +126 -0
  70. package/dist/{_chunks/cs-CkJy6B2v.js.map → admin/chunks/cs-BJFxwIWj.js.map} +1 -1
  71. package/dist/admin/chunks/cs-C7OSYFQ7.mjs +122 -0
  72. package/dist/{_chunks/cs-CM2aBUar.mjs.map → admin/chunks/cs-C7OSYFQ7.mjs.map} +1 -1
  73. package/dist/admin/chunks/de-5QRlDHyR.mjs +195 -0
  74. package/dist/{_chunks/eu-CdALomew.mjs.map → admin/chunks/de-5QRlDHyR.mjs.map} +1 -1
  75. package/dist/admin/chunks/de-CbImAUA5.js +200 -0
  76. package/dist/{_chunks/gu-BRmF601H.js.map → admin/chunks/de-CbImAUA5.js.map} +1 -1
  77. package/dist/admin/chunks/en-C1CjdAtC.js +313 -0
  78. package/dist/{_chunks/en-BzQmavmK.js.map → admin/chunks/en-C1CjdAtC.js.map} +1 -1
  79. package/dist/admin/chunks/en-LfhocNG2.mjs +308 -0
  80. package/dist/{_chunks/en-CSxLmrh1.mjs.map → admin/chunks/en-LfhocNG2.mjs.map} +1 -1
  81. package/dist/admin/chunks/es-C8vLuvZL.js +197 -0
  82. package/dist/{_chunks/es-9K52xZIr.js.map → admin/chunks/es-C8vLuvZL.js.map} +1 -1
  83. package/dist/admin/chunks/es-DkoWSExG.mjs +192 -0
  84. package/dist/{_chunks/ja-BHqhDq4V.mjs.map → admin/chunks/es-DkoWSExG.mjs.map} +1 -1
  85. package/dist/admin/chunks/eu-BG1xX7HK.mjs +198 -0
  86. package/dist/admin/chunks/eu-BG1xX7HK.mjs.map +1 -0
  87. package/dist/admin/chunks/eu-BJW3AvXu.js +203 -0
  88. package/dist/admin/chunks/eu-BJW3AvXu.js.map +1 -0
  89. package/dist/admin/chunks/fr-CFdRaRVj.mjs +215 -0
  90. package/dist/admin/chunks/fr-CFdRaRVj.mjs.map +1 -0
  91. package/dist/admin/chunks/fr-gQSilC7w.js +220 -0
  92. package/dist/admin/chunks/fr-gQSilC7w.js.map +1 -0
  93. package/dist/admin/chunks/gu-D5MMMXRs.mjs +196 -0
  94. package/dist/admin/chunks/gu-D5MMMXRs.mjs.map +1 -0
  95. package/dist/admin/chunks/gu-DPU4wyx7.js +201 -0
  96. package/dist/{_chunks/eu-VDH-3ovk.js.map → admin/chunks/gu-DPU4wyx7.js.map} +1 -1
  97. package/dist/admin/chunks/hi-Dp4omeBb.js +201 -0
  98. package/dist/admin/chunks/hi-Dp4omeBb.js.map +1 -0
  99. package/dist/admin/chunks/hi-lp17SCjr.mjs +196 -0
  100. package/dist/admin/chunks/hi-lp17SCjr.mjs.map +1 -0
  101. package/dist/{_chunks/hooks-BAaaKPS_.js → admin/chunks/hooks-D-sOYd1s.js} +6 -3
  102. package/dist/admin/chunks/hooks-D-sOYd1s.js.map +1 -0
  103. package/dist/admin/chunks/hooks-DMvik5y_.mjs +7 -0
  104. package/dist/admin/chunks/hooks-DMvik5y_.mjs.map +1 -0
  105. package/dist/admin/chunks/hu-CLka1U2C.mjs +198 -0
  106. package/dist/admin/chunks/hu-CLka1U2C.mjs.map +1 -0
  107. package/dist/admin/chunks/hu-CtFJuhTd.js +203 -0
  108. package/dist/admin/chunks/hu-CtFJuhTd.js.map +1 -0
  109. package/dist/admin/chunks/id-D7V5S1rB.js +161 -0
  110. package/dist/{_chunks/it-DkBIs7vD.js.map → admin/chunks/id-D7V5S1rB.js.map} +1 -1
  111. package/dist/admin/chunks/id-USfY9m1g.mjs +156 -0
  112. package/dist/{_chunks/id-BtwA9WJT.mjs.map → admin/chunks/id-USfY9m1g.mjs.map} +1 -1
  113. package/dist/admin/chunks/index-BHimg6jW.js +5417 -0
  114. package/dist/admin/chunks/index-BHimg6jW.js.map +1 -0
  115. package/dist/admin/chunks/index-Cs6qwFQu.mjs +5351 -0
  116. package/dist/admin/chunks/index-Cs6qwFQu.mjs.map +1 -0
  117. package/dist/admin/chunks/it-BAHrwmYS.mjs +158 -0
  118. package/dist/{_chunks/it-BrVPqaf1.mjs.map → admin/chunks/it-BAHrwmYS.mjs.map} +1 -1
  119. package/dist/admin/chunks/it-CQFpa_Dc.js +163 -0
  120. package/dist/{_chunks/ko-woFZPmLk.js.map → admin/chunks/it-CQFpa_Dc.js.map} +1 -1
  121. package/dist/admin/chunks/ja-BWKmBJFT.mjs +192 -0
  122. package/dist/{_chunks/ko-HVQRlfUI.mjs.map → admin/chunks/ja-BWKmBJFT.mjs.map} +1 -1
  123. package/dist/admin/chunks/ja-jdQM-B79.js +197 -0
  124. package/dist/{_chunks/de-CCEmbAah.js.map → admin/chunks/ja-jdQM-B79.js.map} +1 -1
  125. package/dist/admin/chunks/ko-CgADGBNt.mjs +191 -0
  126. package/dist/{_chunks/es-D34tqjMw.mjs.map → admin/chunks/ko-CgADGBNt.mjs.map} +1 -1
  127. package/dist/admin/chunks/ko-k46sEyzt.js +196 -0
  128. package/dist/{_chunks/ja-7sfIbjxE.js.map → admin/chunks/ko-k46sEyzt.js.map} +1 -1
  129. package/dist/admin/chunks/layout-DStNia_P.mjs +599 -0
  130. package/dist/admin/chunks/layout-DStNia_P.mjs.map +1 -0
  131. package/dist/admin/chunks/layout-Dtahn4Ue.js +619 -0
  132. package/dist/admin/chunks/layout-Dtahn4Ue.js.map +1 -0
  133. package/dist/admin/chunks/ml-CnhCfOn_.mjs +196 -0
  134. package/dist/admin/chunks/ml-CnhCfOn_.mjs.map +1 -0
  135. package/dist/admin/chunks/ml-DqxPwODx.js +201 -0
  136. package/dist/admin/chunks/ml-DqxPwODx.js.map +1 -0
  137. package/dist/admin/chunks/ms-Bh09NFff.mjs +140 -0
  138. package/dist/{_chunks/ms-m_WjyWx7.mjs.map → admin/chunks/ms-Bh09NFff.mjs.map} +1 -1
  139. package/dist/admin/chunks/ms-CvSC0OdG.js +145 -0
  140. package/dist/{_chunks/ms-BuFotyP_.js.map → admin/chunks/ms-CvSC0OdG.js.map} +1 -1
  141. package/dist/admin/chunks/nl-BEubhS8C.js +203 -0
  142. package/dist/admin/chunks/nl-BEubhS8C.js.map +1 -0
  143. package/dist/admin/chunks/nl-C8HYflTc.mjs +198 -0
  144. package/dist/admin/chunks/nl-C8HYflTc.mjs.map +1 -0
  145. package/dist/admin/chunks/objects-C3EebVVe.js +76 -0
  146. package/dist/admin/chunks/objects-C3EebVVe.js.map +1 -0
  147. package/dist/admin/chunks/objects-wl73iEma.mjs +73 -0
  148. package/dist/admin/chunks/objects-wl73iEma.mjs.map +1 -0
  149. package/dist/admin/chunks/pl-DWhGDzmM.js +200 -0
  150. package/dist/{_chunks/ca-Cmk45QO6.js.map → admin/chunks/pl-DWhGDzmM.js.map} +1 -1
  151. package/dist/admin/chunks/pl-MFCZJZuZ.mjs +195 -0
  152. package/dist/{_chunks/ca-5U32ON2v.mjs.map → admin/chunks/pl-MFCZJZuZ.mjs.map} +1 -1
  153. package/dist/admin/chunks/pt-BR-CPtAXD-4.js +202 -0
  154. package/dist/{_chunks/pt-BR-BiOz37D9.js.map → admin/chunks/pt-BR-CPtAXD-4.js.map} +1 -1
  155. package/dist/admin/chunks/pt-BR-CcotyBGJ.mjs +197 -0
  156. package/dist/{_chunks/pt-BR-C71iDxnh.mjs.map → admin/chunks/pt-BR-CcotyBGJ.mjs.map} +1 -1
  157. package/dist/admin/chunks/pt-BoPxN80n.js +96 -0
  158. package/dist/admin/chunks/pt-BoPxN80n.js.map +1 -0
  159. package/dist/admin/chunks/pt-HbmgeiYO.mjs +93 -0
  160. package/dist/admin/chunks/pt-HbmgeiYO.mjs.map +1 -0
  161. package/dist/admin/chunks/relations-Cq8NRUto.mjs +173 -0
  162. package/dist/admin/chunks/relations-Cq8NRUto.mjs.map +1 -0
  163. package/dist/admin/chunks/relations-XOYEEqMz.js +178 -0
  164. package/dist/admin/chunks/relations-XOYEEqMz.js.map +1 -0
  165. package/dist/admin/chunks/ru-C0op0ALG.js +232 -0
  166. package/dist/admin/chunks/ru-C0op0ALG.js.map +1 -0
  167. package/dist/admin/chunks/ru-CB4BUyQp.mjs +230 -0
  168. package/dist/{_chunks/ru-BE6A4Exp.mjs.map → admin/chunks/ru-CB4BUyQp.mjs.map} +1 -1
  169. package/dist/admin/chunks/sa-B_FuPyMw.js +201 -0
  170. package/dist/admin/chunks/sa-B_FuPyMw.js.map +1 -0
  171. package/dist/admin/chunks/sa-n_aPA-pU.mjs +196 -0
  172. package/dist/admin/chunks/sa-n_aPA-pU.mjs.map +1 -0
  173. package/dist/admin/chunks/sk-D_iXML2C.js +203 -0
  174. package/dist/admin/chunks/sk-D_iXML2C.js.map +1 -0
  175. package/dist/admin/chunks/sk-tn_BDjE2.mjs +198 -0
  176. package/dist/admin/chunks/sk-tn_BDjE2.mjs.map +1 -0
  177. package/dist/admin/chunks/sv-BstBC1Yp.js +203 -0
  178. package/dist/admin/chunks/sv-BstBC1Yp.js.map +1 -0
  179. package/dist/admin/chunks/sv-cq4ZrQRd.mjs +198 -0
  180. package/dist/admin/chunks/sv-cq4ZrQRd.mjs.map +1 -0
  181. package/dist/admin/chunks/th-lXoOCqPC.js +149 -0
  182. package/dist/{_chunks/th-D9_GfAjc.js.map → admin/chunks/th-lXoOCqPC.js.map} +1 -1
  183. package/dist/admin/chunks/th-mUH7hEtc.mjs +144 -0
  184. package/dist/{_chunks/th-BqbI8lIT.mjs.map → admin/chunks/th-mUH7hEtc.mjs.map} +1 -1
  185. package/dist/admin/chunks/tr-CkS6sLIE.js +200 -0
  186. package/dist/admin/chunks/tr-CkS6sLIE.js.map +1 -0
  187. package/dist/admin/chunks/tr-Yt38daxh.mjs +195 -0
  188. package/dist/{_chunks/de-C72KDNOl.mjs.map → admin/chunks/tr-Yt38daxh.mjs.map} +1 -1
  189. package/dist/admin/chunks/uk-B24MoTVg.js +145 -0
  190. package/dist/{_chunks/uk-C8EiqJY7.js.map → admin/chunks/uk-B24MoTVg.js.map} +1 -1
  191. package/dist/admin/chunks/uk-Cpgmm7gE.mjs +140 -0
  192. package/dist/{_chunks/uk-CR-zDhAY.mjs.map → admin/chunks/uk-Cpgmm7gE.mjs.map} +1 -1
  193. package/dist/admin/chunks/useDragAndDrop-HYwNDExe.mjs +247 -0
  194. package/dist/admin/chunks/useDragAndDrop-HYwNDExe.mjs.map +1 -0
  195. package/dist/admin/chunks/useDragAndDrop-gcqEJMnO.js +271 -0
  196. package/dist/admin/chunks/useDragAndDrop-gcqEJMnO.js.map +1 -0
  197. package/dist/admin/chunks/usePrev-Bjw2dhmq.mjs +18 -0
  198. package/dist/admin/chunks/usePrev-Bjw2dhmq.mjs.map +1 -0
  199. package/dist/admin/chunks/usePrev-DIYl-IAL.js +21 -0
  200. package/dist/admin/chunks/usePrev-DIYl-IAL.js.map +1 -0
  201. package/dist/admin/chunks/vi-BGr1X_HZ.js +112 -0
  202. package/dist/{_chunks/vi-CJlYDheJ.js.map → admin/chunks/vi-BGr1X_HZ.js.map} +1 -1
  203. package/dist/admin/chunks/vi-CvBGlTjr.mjs +108 -0
  204. package/dist/{_chunks/vi-DUXIk_fw.mjs.map → admin/chunks/vi-CvBGlTjr.mjs.map} +1 -1
  205. package/dist/admin/chunks/zh-BmF-sHaT.mjs +205 -0
  206. package/dist/admin/chunks/zh-BmF-sHaT.mjs.map +1 -0
  207. package/dist/admin/chunks/zh-DwFu_Kfj.js +210 -0
  208. package/dist/admin/chunks/zh-DwFu_Kfj.js.map +1 -0
  209. package/dist/admin/chunks/zh-Hans-CI0HKio3.mjs +934 -0
  210. package/dist/{_chunks/zh-Hans-BPQcRIyH.mjs.map → admin/chunks/zh-Hans-CI0HKio3.mjs.map} +1 -1
  211. package/dist/admin/chunks/zh-Hans-JVK9x7xr.js +953 -0
  212. package/dist/{_chunks/zh-Hans-9kOncHGw.js.map → admin/chunks/zh-Hans-JVK9x7xr.js.map} +1 -1
  213. package/dist/admin/index.js +24 -4
  214. package/dist/admin/index.js.map +1 -1
  215. package/dist/admin/index.mjs +17 -13
  216. package/dist/admin/index.mjs.map +1 -1
  217. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  218. package/dist/admin/src/hooks/useDocument.d.ts +21 -4
  219. package/dist/admin/src/index.d.ts +1 -0
  220. package/dist/admin/src/pages/EditView/components/EditorToolbarObserver.d.ts +11 -0
  221. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.d.ts +49 -1
  222. package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +2 -1
  223. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygNav.d.ts +1 -2
  224. package/dist/admin/src/pages/EditView/components/FormLayout.d.ts +29 -1
  225. package/dist/admin/src/pages/EditView/utils/data.d.ts +1 -0
  226. package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -1
  227. package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -1
  228. package/dist/admin/src/preview/index.d.ts +2 -3
  229. package/dist/admin/src/preview/pages/Preview.d.ts +3 -1
  230. package/dist/server/index.js +5459 -4387
  231. package/dist/server/index.js.map +1 -1
  232. package/dist/server/index.mjs +5446 -4372
  233. package/dist/server/index.mjs.map +1 -1
  234. package/dist/server/src/controllers/utils/metadata.d.ts +1 -1
  235. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  236. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  237. package/dist/server/src/services/utils/count.d.ts +1 -1
  238. package/dist/server/src/services/utils/count.d.ts.map +1 -1
  239. package/dist/server/src/services/utils/populate.d.ts +1 -1
  240. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  241. package/dist/shared/contracts/collection-types.d.ts +0 -1
  242. package/dist/shared/contracts/components.d.ts +0 -1
  243. package/dist/shared/contracts/content-types.d.ts +0 -1
  244. package/dist/shared/contracts/history-versions.d.ts +0 -1
  245. package/dist/shared/contracts/index.d.ts +0 -1
  246. package/dist/shared/contracts/init.d.ts +0 -1
  247. package/dist/shared/contracts/preview.d.ts +0 -1
  248. package/dist/shared/contracts/relations.d.ts +1 -2
  249. package/dist/shared/contracts/relations.d.ts.map +1 -1
  250. package/dist/shared/contracts/review-workflows.d.ts +0 -1
  251. package/dist/shared/contracts/single-types.d.ts +0 -1
  252. package/dist/shared/contracts/uid.d.ts +0 -1
  253. package/dist/shared/index.d.ts +0 -1
  254. package/dist/shared/index.js +35 -24
  255. package/dist/shared/index.js.map +1 -1
  256. package/dist/shared/index.mjs +34 -25
  257. package/dist/shared/index.mjs.map +1 -1
  258. package/package.json +15 -12
  259. package/dist/_chunks/CardDragPreview-C0QyJgRA.js +0 -69
  260. package/dist/_chunks/CardDragPreview-C0QyJgRA.js.map +0 -1
  261. package/dist/_chunks/CardDragPreview-DOxamsuj.mjs +0 -70
  262. package/dist/_chunks/CardDragPreview-DOxamsuj.mjs.map +0 -1
  263. package/dist/_chunks/ComponentConfigurationPage-DquE3cSt.js +0 -254
  264. package/dist/_chunks/ComponentConfigurationPage-DquE3cSt.js.map +0 -1
  265. package/dist/_chunks/ComponentConfigurationPage-xgUutqCq.mjs +0 -236
  266. package/dist/_chunks/ComponentConfigurationPage-xgUutqCq.mjs.map +0 -1
  267. package/dist/_chunks/ComponentIcon-CRbtQEUV.js +0 -175
  268. package/dist/_chunks/ComponentIcon-CRbtQEUV.js.map +0 -1
  269. package/dist/_chunks/ComponentIcon-u4bIXTFY.mjs +0 -157
  270. package/dist/_chunks/ComponentIcon-u4bIXTFY.mjs.map +0 -1
  271. package/dist/_chunks/EditConfigurationPage-BxxS_VjE.mjs +0 -132
  272. package/dist/_chunks/EditConfigurationPage-BxxS_VjE.mjs.map +0 -1
  273. package/dist/_chunks/EditConfigurationPage-DBZcYu4y.js +0 -150
  274. package/dist/_chunks/EditConfigurationPage-DBZcYu4y.js.map +0 -1
  275. package/dist/_chunks/EditViewPage-CxbLxtSZ.mjs +0 -254
  276. package/dist/_chunks/EditViewPage-CxbLxtSZ.mjs.map +0 -1
  277. package/dist/_chunks/EditViewPage-eVQAzqrX.js +0 -272
  278. package/dist/_chunks/EditViewPage-eVQAzqrX.js.map +0 -1
  279. package/dist/_chunks/Field-B1V9AyU1.js +0 -5655
  280. package/dist/_chunks/Field-B1V9AyU1.js.map +0 -1
  281. package/dist/_chunks/Field-CZwQcrmw.mjs +0 -5623
  282. package/dist/_chunks/Field-CZwQcrmw.mjs.map +0 -1
  283. package/dist/_chunks/FieldTypeIcon-CMlNO8PE.mjs +0 -50
  284. package/dist/_chunks/FieldTypeIcon-CMlNO8PE.mjs.map +0 -1
  285. package/dist/_chunks/FieldTypeIcon-Dnwq_IRF.js +0 -49
  286. package/dist/_chunks/FieldTypeIcon-Dnwq_IRF.js.map +0 -1
  287. package/dist/_chunks/Form-3kEYdc-J.mjs +0 -758
  288. package/dist/_chunks/Form-3kEYdc-J.mjs.map +0 -1
  289. package/dist/_chunks/Form-DDb5-H01.js +0 -778
  290. package/dist/_chunks/Form-DDb5-H01.js.map +0 -1
  291. package/dist/_chunks/History-COpTRR4s.js +0 -1019
  292. package/dist/_chunks/History-COpTRR4s.js.map +0 -1
  293. package/dist/_chunks/History-DXZrV891.mjs +0 -999
  294. package/dist/_chunks/History-DXZrV891.mjs.map +0 -1
  295. package/dist/_chunks/ListConfigurationPage-B1BlI0vS.mjs +0 -633
  296. package/dist/_chunks/ListConfigurationPage-B1BlI0vS.mjs.map +0 -1
  297. package/dist/_chunks/ListConfigurationPage-D5zn8EA8.js +0 -652
  298. package/dist/_chunks/ListConfigurationPage-D5zn8EA8.js.map +0 -1
  299. package/dist/_chunks/ListViewPage-CfHJAt9S.mjs +0 -851
  300. package/dist/_chunks/ListViewPage-CfHJAt9S.mjs.map +0 -1
  301. package/dist/_chunks/ListViewPage-OqGWxoXp.js +0 -874
  302. package/dist/_chunks/ListViewPage-OqGWxoXp.js.map +0 -1
  303. package/dist/_chunks/NoContentTypePage-B1vde0d2.mjs +0 -51
  304. package/dist/_chunks/NoContentTypePage-B1vde0d2.mjs.map +0 -1
  305. package/dist/_chunks/NoContentTypePage-BwuxzVhz.js +0 -51
  306. package/dist/_chunks/NoContentTypePage-BwuxzVhz.js.map +0 -1
  307. package/dist/_chunks/NoPermissionsPage-BZx6YZ0-.mjs +0 -23
  308. package/dist/_chunks/NoPermissionsPage-BZx6YZ0-.mjs.map +0 -1
  309. package/dist/_chunks/NoPermissionsPage-CM4q9eyp.js +0 -23
  310. package/dist/_chunks/NoPermissionsPage-CM4q9eyp.js.map +0 -1
  311. package/dist/_chunks/Preview-DZWvwEHg.js +0 -312
  312. package/dist/_chunks/Preview-DZWvwEHg.js.map +0 -1
  313. package/dist/_chunks/Preview-DeD_aLg6.mjs +0 -294
  314. package/dist/_chunks/Preview-DeD_aLg6.mjs.map +0 -1
  315. package/dist/_chunks/Relations-DXVAOSqj.js +0 -747
  316. package/dist/_chunks/Relations-DXVAOSqj.js.map +0 -1
  317. package/dist/_chunks/Relations-i1BqMPqp.mjs +0 -728
  318. package/dist/_chunks/Relations-i1BqMPqp.mjs.map +0 -1
  319. package/dist/_chunks/ar-BUUWXIYu.js +0 -226
  320. package/dist/_chunks/ar-BUUWXIYu.js.map +0 -1
  321. package/dist/_chunks/ar-CCEVvqGG.mjs +0 -226
  322. package/dist/_chunks/ca-5U32ON2v.mjs +0 -201
  323. package/dist/_chunks/ca-Cmk45QO6.js +0 -201
  324. package/dist/_chunks/cs-CM2aBUar.mjs +0 -125
  325. package/dist/_chunks/cs-CkJy6B2v.js +0 -125
  326. package/dist/_chunks/de-C72KDNOl.mjs +0 -199
  327. package/dist/_chunks/de-CCEmbAah.js +0 -199
  328. package/dist/_chunks/en-BzQmavmK.js +0 -310
  329. package/dist/_chunks/en-CSxLmrh1.mjs +0 -310
  330. package/dist/_chunks/es-9K52xZIr.js +0 -196
  331. package/dist/_chunks/es-D34tqjMw.mjs +0 -196
  332. package/dist/_chunks/eu-CdALomew.mjs +0 -202
  333. package/dist/_chunks/eu-VDH-3ovk.js +0 -202
  334. package/dist/_chunks/fr--pg5jUbt.mjs +0 -216
  335. package/dist/_chunks/fr--pg5jUbt.mjs.map +0 -1
  336. package/dist/_chunks/fr-B2Kyv8Z9.js +0 -216
  337. package/dist/_chunks/fr-B2Kyv8Z9.js.map +0 -1
  338. package/dist/_chunks/gu-BRmF601H.js +0 -200
  339. package/dist/_chunks/gu-CNpaMDpH.mjs +0 -200
  340. package/dist/_chunks/gu-CNpaMDpH.mjs.map +0 -1
  341. package/dist/_chunks/hi-CCJBptSq.js +0 -200
  342. package/dist/_chunks/hi-CCJBptSq.js.map +0 -1
  343. package/dist/_chunks/hi-Dwvd04m3.mjs +0 -200
  344. package/dist/_chunks/hi-Dwvd04m3.mjs.map +0 -1
  345. package/dist/_chunks/hooks-BAaaKPS_.js.map +0 -1
  346. package/dist/_chunks/hooks-E5u1mcgM.mjs +0 -8
  347. package/dist/_chunks/hooks-E5u1mcgM.mjs.map +0 -1
  348. package/dist/_chunks/hu-CeYvaaO0.mjs +0 -202
  349. package/dist/_chunks/hu-CeYvaaO0.mjs.map +0 -1
  350. package/dist/_chunks/hu-sNV_yLYy.js +0 -202
  351. package/dist/_chunks/hu-sNV_yLYy.js.map +0 -1
  352. package/dist/_chunks/id-B5Ser98A.js +0 -160
  353. package/dist/_chunks/id-B5Ser98A.js.map +0 -1
  354. package/dist/_chunks/id-BtwA9WJT.mjs +0 -160
  355. package/dist/_chunks/index-D9vDl-4J.js +0 -4303
  356. package/dist/_chunks/index-D9vDl-4J.js.map +0 -1
  357. package/dist/_chunks/index-Rej95OkL.mjs +0 -4284
  358. package/dist/_chunks/index-Rej95OkL.mjs.map +0 -1
  359. package/dist/_chunks/it-BrVPqaf1.mjs +0 -162
  360. package/dist/_chunks/it-DkBIs7vD.js +0 -162
  361. package/dist/_chunks/ja-7sfIbjxE.js +0 -196
  362. package/dist/_chunks/ja-BHqhDq4V.mjs +0 -196
  363. package/dist/_chunks/ko-HVQRlfUI.mjs +0 -195
  364. package/dist/_chunks/ko-woFZPmLk.js +0 -195
  365. package/dist/_chunks/layout-B4X3h5C4.js +0 -488
  366. package/dist/_chunks/layout-B4X3h5C4.js.map +0 -1
  367. package/dist/_chunks/layout-CKw8rE38.mjs +0 -471
  368. package/dist/_chunks/layout-CKw8rE38.mjs.map +0 -1
  369. package/dist/_chunks/ml-BihZwQit.mjs +0 -200
  370. package/dist/_chunks/ml-BihZwQit.mjs.map +0 -1
  371. package/dist/_chunks/ml-C2W8N8k1.js +0 -200
  372. package/dist/_chunks/ml-C2W8N8k1.js.map +0 -1
  373. package/dist/_chunks/ms-BuFotyP_.js +0 -144
  374. package/dist/_chunks/ms-m_WjyWx7.mjs +0 -144
  375. package/dist/_chunks/nl-D4R9gHx5.mjs +0 -202
  376. package/dist/_chunks/nl-D4R9gHx5.mjs.map +0 -1
  377. package/dist/_chunks/nl-bbEOHChV.js +0 -202
  378. package/dist/_chunks/nl-bbEOHChV.js.map +0 -1
  379. package/dist/_chunks/objects-BcXOv6_9.js +0 -47
  380. package/dist/_chunks/objects-BcXOv6_9.js.map +0 -1
  381. package/dist/_chunks/objects-D6yBsdmx.mjs +0 -45
  382. package/dist/_chunks/objects-D6yBsdmx.mjs.map +0 -1
  383. package/dist/_chunks/pl-sbx9mSt_.mjs +0 -199
  384. package/dist/_chunks/pl-sbx9mSt_.mjs.map +0 -1
  385. package/dist/_chunks/pl-uzwG-hk7.js +0 -199
  386. package/dist/_chunks/pl-uzwG-hk7.js.map +0 -1
  387. package/dist/_chunks/pt-BR-BiOz37D9.js +0 -201
  388. package/dist/_chunks/pt-BR-C71iDxnh.mjs +0 -201
  389. package/dist/_chunks/pt-BsaFvS8-.mjs +0 -95
  390. package/dist/_chunks/pt-BsaFvS8-.mjs.map +0 -1
  391. package/dist/_chunks/pt-CeXQuq50.js +0 -95
  392. package/dist/_chunks/pt-CeXQuq50.js.map +0 -1
  393. package/dist/_chunks/relations-CvZ0Uu8l.js +0 -133
  394. package/dist/_chunks/relations-CvZ0Uu8l.js.map +0 -1
  395. package/dist/_chunks/relations-GpHbwwdj.mjs +0 -134
  396. package/dist/_chunks/relations-GpHbwwdj.mjs.map +0 -1
  397. package/dist/_chunks/ru-BE6A4Exp.mjs +0 -231
  398. package/dist/_chunks/ru-BT3ybNny.js +0 -231
  399. package/dist/_chunks/sa-CcvkYInH.js +0 -200
  400. package/dist/_chunks/sa-CcvkYInH.js.map +0 -1
  401. package/dist/_chunks/sa-Dag0k-Z8.mjs +0 -200
  402. package/dist/_chunks/sa-Dag0k-Z8.mjs.map +0 -1
  403. package/dist/_chunks/sk-BFg-R8qJ.mjs +0 -202
  404. package/dist/_chunks/sk-BFg-R8qJ.mjs.map +0 -1
  405. package/dist/_chunks/sk-CvY09Xjv.js +0 -202
  406. package/dist/_chunks/sk-CvY09Xjv.js.map +0 -1
  407. package/dist/_chunks/sv-CUnfWGsh.mjs +0 -202
  408. package/dist/_chunks/sv-CUnfWGsh.mjs.map +0 -1
  409. package/dist/_chunks/sv-MYDuzgvT.js +0 -202
  410. package/dist/_chunks/sv-MYDuzgvT.js.map +0 -1
  411. package/dist/_chunks/th-BqbI8lIT.mjs +0 -148
  412. package/dist/_chunks/th-D9_GfAjc.js +0 -148
  413. package/dist/_chunks/tr-CgeK3wJM.mjs +0 -199
  414. package/dist/_chunks/tr-CgeK3wJM.mjs.map +0 -1
  415. package/dist/_chunks/tr-D9UH-O_R.js +0 -199
  416. package/dist/_chunks/tr-D9UH-O_R.js.map +0 -1
  417. package/dist/_chunks/uk-C8EiqJY7.js +0 -144
  418. package/dist/_chunks/uk-CR-zDhAY.mjs +0 -144
  419. package/dist/_chunks/useDebounce-CtcjDB3L.js +0 -28
  420. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +0 -1
  421. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +0 -29
  422. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +0 -1
  423. package/dist/_chunks/useDragAndDrop-BMtgCYzL.js +0 -245
  424. package/dist/_chunks/useDragAndDrop-BMtgCYzL.js.map +0 -1
  425. package/dist/_chunks/useDragAndDrop-DJ6jqvZN.mjs +0 -228
  426. package/dist/_chunks/useDragAndDrop-DJ6jqvZN.mjs.map +0 -1
  427. package/dist/_chunks/vi-CJlYDheJ.js +0 -111
  428. package/dist/_chunks/vi-DUXIk_fw.mjs +0 -111
  429. package/dist/_chunks/zh-BWZspA60.mjs +0 -209
  430. package/dist/_chunks/zh-BWZspA60.mjs.map +0 -1
  431. package/dist/_chunks/zh-CQQfszqR.js +0 -209
  432. package/dist/_chunks/zh-CQQfszqR.js.map +0 -1
  433. package/dist/_chunks/zh-Hans-9kOncHGw.js +0 -952
  434. package/dist/_chunks/zh-Hans-BPQcRIyH.mjs +0 -952
  435. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/utils/prismLanguages.d.ts +0 -49
@@ -1,4284 +0,0 @@
1
- import { More, Cross, WarningCircle, ListPlus, Pencil, Trash, Check, CrossCircle, CheckCircle, ArrowsCounterClockwise, ChevronRight, Duplicate, ClockCounterClockwise, Feather } from "@strapi/icons";
2
- import { jsx, Fragment, jsxs } from "react/jsx-runtime";
3
- import { useStrapiApp, createContext, useQueryParams, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors, useForm, useTracking, useGuidedTour, BackButton, DescriptionComponentRenderer, useTable, Table } from "@strapi/admin/strapi-admin";
4
- import * as React from "react";
5
- import { lazy } from "react";
6
- import { Menu, Button, VisuallyHidden, Flex, Dialog, Modal, Typography, Radio, Status, Box, SingleSelect, SingleSelectOption, IconButton, Loader, Tooltip, LinkButton } from "@strapi/design-system";
7
- import mapValues from "lodash/fp/mapValues";
8
- import { useIntl } from "react-intl";
9
- import { useParams, useNavigate, Navigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
10
- import { styled } from "styled-components";
11
- import * as yup from "yup";
12
- import { ValidationError } from "yup";
13
- import { stringify } from "qs";
14
- import pipe from "lodash/fp/pipe";
15
- import { intervalToDuration, isPast } from "date-fns";
16
- import { createSlice, combineReducers } from "@reduxjs/toolkit";
17
- const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
18
- const v = glob[path];
19
- if (v) {
20
- return typeof v === "function" ? v() : Promise.resolve(v);
21
- }
22
- return new Promise((_, reject) => {
23
- (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
24
- reject.bind(
25
- null,
26
- new Error(
27
- "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
28
- )
29
- )
30
- );
31
- });
32
- };
33
- const PLUGIN_ID = "content-manager";
34
- const PERMISSIONS = [
35
- "plugin::content-manager.explorer.create",
36
- "plugin::content-manager.explorer.read",
37
- "plugin::content-manager.explorer.update",
38
- "plugin::content-manager.explorer.delete",
39
- "plugin::content-manager.explorer.publish"
40
- ];
41
- const INJECTION_ZONES = {
42
- editView: { informations: [], "right-links": [] },
43
- listView: {
44
- actions: [],
45
- deleteModalAdditionalInfos: [],
46
- publishModalAdditionalInfos: [],
47
- unpublishModalAdditionalInfos: []
48
- }
49
- };
50
- const InjectionZone = ({ area, ...props }) => {
51
- const components = useInjectionZone(area);
52
- return /* @__PURE__ */ jsx(Fragment, { children: components.map((component) => /* @__PURE__ */ jsx(component.Component, { ...props }, component.name)) });
53
- };
54
- const useInjectionZone = (area) => {
55
- const getPlugin = useStrapiApp("useInjectionZone", (state) => state.getPlugin);
56
- const contentManagerPlugin = getPlugin(PLUGIN_ID);
57
- const [page, position] = area.split(".");
58
- return contentManagerPlugin.getInjectedComponents(page, position);
59
- };
60
- const ID = "id";
61
- const CREATED_BY_ATTRIBUTE_NAME = "createdBy";
62
- const UPDATED_BY_ATTRIBUTE_NAME = "updatedBy";
63
- const CREATOR_FIELDS = [CREATED_BY_ATTRIBUTE_NAME, UPDATED_BY_ATTRIBUTE_NAME];
64
- const PUBLISHED_BY_ATTRIBUTE_NAME = "publishedBy";
65
- const CREATED_AT_ATTRIBUTE_NAME = "createdAt";
66
- const UPDATED_AT_ATTRIBUTE_NAME = "updatedAt";
67
- const PUBLISHED_AT_ATTRIBUTE_NAME = "publishedAt";
68
- const DOCUMENT_META_FIELDS = [
69
- ID,
70
- ...CREATOR_FIELDS,
71
- PUBLISHED_BY_ATTRIBUTE_NAME,
72
- CREATED_AT_ATTRIBUTE_NAME,
73
- UPDATED_AT_ATTRIBUTE_NAME,
74
- PUBLISHED_AT_ATTRIBUTE_NAME
75
- ];
76
- const ATTRIBUTE_TYPES_THAT_CANNOT_BE_MAIN_FIELD = [
77
- "dynamiczone",
78
- "json",
79
- "text",
80
- "relation",
81
- "component",
82
- "boolean",
83
- "media",
84
- "password",
85
- "richtext",
86
- "timestamp",
87
- "blocks"
88
- ];
89
- const SINGLE_TYPES = "single-types";
90
- const COLLECTION_TYPES = "collection-types";
91
- const [DocumentRBACProvider, useDocumentRBAC] = createContext(
92
- "DocumentRBAC",
93
- {
94
- canCreate: false,
95
- canCreateFields: [],
96
- canDelete: false,
97
- canPublish: false,
98
- canRead: false,
99
- canReadFields: [],
100
- canUpdate: false,
101
- canUpdateFields: [],
102
- canUserAction: () => false,
103
- isLoading: false
104
- }
105
- );
106
- const DocumentRBAC = ({ children, permissions }) => {
107
- const { slug } = useParams();
108
- if (!slug) {
109
- throw new Error("Cannot find the slug param in the URL");
110
- }
111
- const [{ rawQuery }] = useQueryParams();
112
- const userPermissions = useAuth("DocumentRBAC", (state) => state.permissions);
113
- const contentTypePermissions = React.useMemo(() => {
114
- const contentTypePermissions2 = userPermissions.filter(
115
- (permission) => permission.subject === slug
116
- );
117
- return contentTypePermissions2.reduce((acc, permission) => {
118
- const [action] = permission.action.split(".").slice(-1);
119
- return { ...acc, [action]: [permission] };
120
- }, {});
121
- }, [slug, userPermissions]);
122
- const { isLoading, allowedActions } = useRBAC(
123
- contentTypePermissions,
124
- permissions ?? void 0,
125
- // TODO: useRBAC context should be typed and built differently
126
- // We are passing raw query as context to the hook so that it can
127
- // rely on the locale provided from DocumentRBAC for its permission calculations.
128
- rawQuery
129
- );
130
- const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
131
- const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
132
- const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
133
- const canUserAction = React.useCallback(
134
- (fieldName, fieldsUserCanAction, fieldType) => {
135
- const name = removeNumericalStrings(fieldName.split("."));
136
- const componentFieldNames = fieldsUserCanAction.filter((field) => field.split(".").length > 1);
137
- if (fieldType === "component") {
138
- return componentFieldNames.some((field) => {
139
- return field.includes(name.join("."));
140
- });
141
- }
142
- if (name.length > 1) {
143
- return componentFieldNames.includes(name.join("."));
144
- }
145
- return fieldsUserCanAction.includes(fieldName);
146
- },
147
- []
148
- );
149
- if (isLoading) {
150
- return /* @__PURE__ */ jsx(Page.Loading, {});
151
- }
152
- return /* @__PURE__ */ jsx(
153
- DocumentRBACProvider,
154
- {
155
- isLoading,
156
- canCreateFields,
157
- canReadFields,
158
- canUpdateFields,
159
- canUserAction,
160
- ...allowedActions,
161
- children
162
- }
163
- );
164
- };
165
- const extractAndDedupeFields = (permissions = []) => permissions.flatMap((permission) => permission.properties?.fields).filter(
166
- (field, index2, arr) => arr.indexOf(field) === index2 && typeof field === "string"
167
- );
168
- const removeNumericalStrings = (arr) => arr.filter((item) => isNaN(Number(item)));
169
- const contentManagerApi = adminApi.enhanceEndpoints({
170
- addTagTypes: [
171
- "ComponentConfiguration",
172
- "ContentTypesConfiguration",
173
- "ContentTypeSettings",
174
- "Document",
175
- "InitialData",
176
- "HistoryVersion",
177
- "Relations",
178
- "UidAvailability",
179
- "RecentDocumentList"
180
- ]
181
- });
182
- const documentApi = contentManagerApi.injectEndpoints({
183
- overrideExisting: true,
184
- endpoints: (builder) => ({
185
- autoCloneDocument: builder.mutation({
186
- query: ({ model, sourceId, query }) => ({
187
- url: `/content-manager/collection-types/${model}/auto-clone/${sourceId}`,
188
- method: "POST",
189
- config: {
190
- params: query
191
- }
192
- }),
193
- invalidatesTags: (_result, error, { model }) => {
194
- if (error) {
195
- return [];
196
- }
197
- return [{ type: "Document", id: `${model}_LIST` }, "RecentDocumentList"];
198
- }
199
- }),
200
- cloneDocument: builder.mutation({
201
- query: ({ model, sourceId, data, params }) => ({
202
- url: `/content-manager/collection-types/${model}/clone/${sourceId}`,
203
- method: "POST",
204
- data,
205
- config: {
206
- params
207
- }
208
- }),
209
- invalidatesTags: (_result, _error, { model }) => [
210
- { type: "Document", id: `${model}_LIST` },
211
- { type: "UidAvailability", id: model },
212
- "RecentDocumentList"
213
- ]
214
- }),
215
- /**
216
- * Creates a new collection-type document. This should ONLY be used for collection-types.
217
- * single-types should always be using `updateDocument` since they always exist.
218
- */
219
- createDocument: builder.mutation({
220
- query: ({ model, data, params }) => ({
221
- url: `/content-manager/collection-types/${model}`,
222
- method: "POST",
223
- data,
224
- config: {
225
- params
226
- }
227
- }),
228
- invalidatesTags: (result, _error, { model }) => [
229
- { type: "Document", id: `${model}_LIST` },
230
- "Relations",
231
- { type: "UidAvailability", id: model },
232
- "RecentDocumentList"
233
- ],
234
- transformResponse: (response, meta, arg) => {
235
- if (!("data" in response) && arg.model === "plugin::users-permissions.user") {
236
- return {
237
- data: response,
238
- meta: {
239
- availableStatus: [],
240
- availableLocales: []
241
- }
242
- };
243
- }
244
- return response;
245
- }
246
- }),
247
- deleteDocument: builder.mutation({
248
- query: ({ collectionType, model, documentId, params }) => ({
249
- url: `/content-manager/${collectionType}/${model}${collectionType !== SINGLE_TYPES && documentId ? `/${documentId}` : ""}`,
250
- method: "DELETE",
251
- config: {
252
- params
253
- }
254
- }),
255
- invalidatesTags: (_result, _error, { collectionType, model }) => [
256
- { type: "Document", id: collectionType !== SINGLE_TYPES ? `${model}_LIST` : model },
257
- "RecentDocumentList"
258
- ]
259
- }),
260
- deleteManyDocuments: builder.mutation({
261
- query: ({ model, params, ...body }) => ({
262
- url: `/content-manager/collection-types/${model}/actions/bulkDelete`,
263
- method: "POST",
264
- data: body,
265
- config: {
266
- params
267
- }
268
- }),
269
- invalidatesTags: (_res, _error, { model }) => [
270
- { type: "Document", id: `${model}_LIST` },
271
- "RecentDocumentList"
272
- ]
273
- }),
274
- discardDocument: builder.mutation({
275
- query: ({ collectionType, model, documentId, params }) => ({
276
- url: documentId ? `/content-manager/${collectionType}/${model}/${documentId}/actions/discard` : `/content-manager/${collectionType}/${model}/actions/discard`,
277
- method: "POST",
278
- config: {
279
- params
280
- }
281
- }),
282
- invalidatesTags: (_result, _error, { collectionType, model, documentId }) => {
283
- return [
284
- {
285
- type: "Document",
286
- id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
287
- },
288
- { type: "Document", id: `${model}_LIST` },
289
- "Relations",
290
- { type: "UidAvailability", id: model },
291
- "RecentDocumentList"
292
- ];
293
- }
294
- }),
295
- /**
296
- * Gets all documents of a collection type or single type.
297
- * By passing different params you can get different results e.g. only published documents or 'es' documents.
298
- */
299
- getAllDocuments: builder.query({
300
- query: ({ model, params }) => ({
301
- url: `/content-manager/collection-types/${model}`,
302
- method: "GET",
303
- config: {
304
- params: stringify(params, { encode: true })
305
- }
306
- }),
307
- providesTags: (result, _error, arg) => {
308
- return [
309
- { type: "Document", id: `ALL_LIST` },
310
- { type: "Document", id: `${arg.model}_LIST` },
311
- ...result?.results.map(({ documentId }) => ({
312
- type: "Document",
313
- id: `${arg.model}_${documentId}`
314
- })) ?? []
315
- ];
316
- }
317
- }),
318
- getDraftRelationCount: builder.query({
319
- query: ({ collectionType, model, documentId, params }) => ({
320
- url: documentId ? `/content-manager/${collectionType}/${model}/${documentId}/actions/countDraftRelations` : `/content-manager/${collectionType}/${model}/actions/countDraftRelations`,
321
- method: "GET",
322
- config: {
323
- params
324
- }
325
- })
326
- }),
327
- getDocument: builder.query({
328
- // @ts-expect-error – TODO: fix ts error where data unknown doesn't work with response via an assertion?
329
- queryFn: async ({ collectionType, model, documentId, params }, _api, _extraOpts, baseQuery) => {
330
- const res = await baseQuery({
331
- url: `/content-manager/${collectionType}/${model}${documentId ? `/${documentId}` : ""}`,
332
- method: "GET",
333
- config: {
334
- params
335
- }
336
- });
337
- if (res.error && res.error.name === "NotFoundError" && collectionType === SINGLE_TYPES) {
338
- return { data: { document: void 0 }, error: void 0 };
339
- }
340
- return res;
341
- },
342
- providesTags: (result, _error, { collectionType, model, documentId }) => {
343
- return [
344
- // we prefer the result's id because we don't fetch single-types with an ID.
345
- {
346
- type: "Document",
347
- id: collectionType !== SINGLE_TYPES ? `${model}_${result && "documentId" in result ? result.documentId : documentId}` : model
348
- },
349
- // Make it easy to invalidate all individual documents queries for a model
350
- {
351
- type: "Document",
352
- id: `${model}_ALL_ITEMS`
353
- }
354
- ];
355
- }
356
- }),
357
- getManyDraftRelationCount: builder.query({
358
- query: ({ model, ...params }) => ({
359
- url: `/content-manager/collection-types/${model}/actions/countManyEntriesDraftRelations`,
360
- method: "GET",
361
- config: {
362
- params
363
- }
364
- }),
365
- transformResponse: (response) => response.data
366
- }),
367
- /**
368
- * This endpoint will either create or update documents at the same time as publishing.
369
- */
370
- publishDocument: builder.mutation({
371
- query: ({ collectionType, model, documentId, params, data }) => ({
372
- url: documentId ? `/content-manager/${collectionType}/${model}/${documentId}/actions/publish` : `/content-manager/${collectionType}/${model}/actions/publish`,
373
- method: "POST",
374
- data,
375
- config: {
376
- params
377
- }
378
- }),
379
- invalidatesTags: (_result, _error, { collectionType, model, documentId }) => {
380
- return [
381
- {
382
- type: "Document",
383
- id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
384
- },
385
- { type: "Document", id: `${model}_LIST` },
386
- "Relations",
387
- "RecentDocumentList"
388
- ];
389
- }
390
- }),
391
- publishManyDocuments: builder.mutation({
392
- query: ({ model, params, ...body }) => ({
393
- url: `/content-manager/collection-types/${model}/actions/bulkPublish`,
394
- method: "POST",
395
- data: body,
396
- config: {
397
- params
398
- }
399
- }),
400
- invalidatesTags: (_res, _error, { model, documentIds }) => documentIds.map((id) => ({ type: "Document", id: `${model}_${id}` }))
401
- }),
402
- updateDocument: builder.mutation({
403
- query: ({ collectionType, model, documentId, data, params }) => ({
404
- url: `/content-manager/${collectionType}/${model}${documentId ? `/${documentId}` : ""}`,
405
- method: "PUT",
406
- data,
407
- config: {
408
- params
409
- }
410
- }),
411
- invalidatesTags: (_result, _error, { collectionType, model, documentId }) => {
412
- return [
413
- {
414
- type: "Document",
415
- id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
416
- },
417
- "Relations",
418
- { type: "UidAvailability", id: model },
419
- "RecentDocumentList",
420
- "RecentDocumentList"
421
- ];
422
- },
423
- async onQueryStarted({ data, ...patch }, { dispatch, queryFulfilled }) {
424
- const patchResult = dispatch(
425
- documentApi.util.updateQueryData("getDocument", patch, (draft) => {
426
- Object.assign(draft.data, data);
427
- })
428
- );
429
- try {
430
- await queryFulfilled;
431
- } catch {
432
- patchResult.undo();
433
- }
434
- }
435
- }),
436
- unpublishDocument: builder.mutation({
437
- query: ({ collectionType, model, documentId, params, data }) => ({
438
- url: documentId ? `/content-manager/${collectionType}/${model}/${documentId}/actions/unpublish` : `/content-manager/${collectionType}/${model}/actions/unpublish`,
439
- method: "POST",
440
- data,
441
- config: {
442
- params
443
- }
444
- }),
445
- invalidatesTags: (_result, _error, { collectionType, model, documentId }) => {
446
- return [
447
- {
448
- type: "Document",
449
- id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
450
- },
451
- "RecentDocumentList"
452
- ];
453
- }
454
- }),
455
- unpublishManyDocuments: builder.mutation({
456
- query: ({ model, params, ...body }) => ({
457
- url: `/content-manager/collection-types/${model}/actions/bulkUnpublish`,
458
- method: "POST",
459
- data: body,
460
- config: {
461
- params
462
- }
463
- }),
464
- invalidatesTags: (_res, _error, { model, documentIds }) => [
465
- ...documentIds.map((id) => ({ type: "Document", id: `${model}_${id}` })),
466
- "RecentDocumentList"
467
- ]
468
- })
469
- })
470
- });
471
- const {
472
- useAutoCloneDocumentMutation,
473
- useCloneDocumentMutation,
474
- useCreateDocumentMutation,
475
- useDeleteDocumentMutation,
476
- useDeleteManyDocumentsMutation,
477
- useDiscardDocumentMutation,
478
- useGetAllDocumentsQuery,
479
- useLazyGetDocumentQuery,
480
- useGetDocumentQuery,
481
- useLazyGetDraftRelationCountQuery,
482
- useGetManyDraftRelationCountQuery,
483
- usePublishDocumentMutation,
484
- usePublishManyDocumentsMutation,
485
- useUpdateDocumentMutation,
486
- useUnpublishDocumentMutation,
487
- useUnpublishManyDocumentsMutation
488
- } = documentApi;
489
- const buildValidParams = (query) => {
490
- if (!query) return query;
491
- const { plugins: _, ...validQueryParams } = {
492
- ...query,
493
- ...Object.values(query?.plugins ?? {}).reduce(
494
- (acc, current) => Object.assign(acc, current),
495
- {}
496
- )
497
- };
498
- return validQueryParams;
499
- };
500
- const isBaseQueryError = (error) => {
501
- return error.name !== void 0;
502
- };
503
- const arrayValidator = (attribute, options) => ({
504
- message: translatedErrors.required,
505
- test(value) {
506
- if (options.status === "draft") {
507
- return true;
508
- }
509
- if (!attribute.required) {
510
- return true;
511
- }
512
- if (!value) {
513
- return false;
514
- }
515
- if (Array.isArray(value) && value.length === 0) {
516
- return false;
517
- }
518
- return true;
519
- }
520
- });
521
- const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
522
- const createModelSchema = (attributes2) => yup.object().shape(
523
- Object.entries(attributes2).reduce((acc, [name, attribute]) => {
524
- if (DOCUMENT_META_FIELDS.includes(name)) {
525
- return acc;
526
- }
527
- const validations = [
528
- addNullableValidation,
529
- addRequiredValidation,
530
- addMinLengthValidation,
531
- addMaxLengthValidation,
532
- addMinValidation,
533
- addMaxValidation,
534
- addRegexValidation
535
- ].map((fn) => fn(attribute, options));
536
- const transformSchema = pipe(...validations);
537
- switch (attribute.type) {
538
- case "component": {
539
- const { attributes: attributes3 } = components[attribute.component];
540
- if (attribute.repeatable) {
541
- return {
542
- ...acc,
543
- [name]: transformSchema(
544
- yup.array().of(createModelSchema(attributes3).nullable(false))
545
- ).test(arrayValidator(attribute, options))
546
- };
547
- } else {
548
- return {
549
- ...acc,
550
- [name]: transformSchema(createModelSchema(attributes3).nullable())
551
- };
552
- }
553
- }
554
- case "dynamiczone":
555
- return {
556
- ...acc,
557
- [name]: transformSchema(
558
- yup.array().of(
559
- yup.lazy(
560
- (data) => {
561
- const attributes3 = components?.[data?.__component]?.attributes;
562
- const validation = yup.object().shape({
563
- __component: yup.string().required().oneOf(Object.keys(components))
564
- }).nullable(false);
565
- if (!attributes3) {
566
- return validation;
567
- }
568
- return validation.concat(createModelSchema(attributes3));
569
- }
570
- )
571
- )
572
- ).test(arrayValidator(attribute, options))
573
- };
574
- case "relation":
575
- return {
576
- ...acc,
577
- [name]: transformSchema(
578
- yup.lazy((value) => {
579
- if (!value) {
580
- return yup.mixed().nullable(true);
581
- } else if (Array.isArray(value)) {
582
- return yup.array().of(
583
- yup.object().shape({
584
- id: yup.number().required()
585
- })
586
- );
587
- } else if (typeof value === "object") {
588
- return yup.object();
589
- } else {
590
- return yup.mixed().test(
591
- "type-error",
592
- "Relation values must be either null, an array of objects with {id} or an object.",
593
- () => false
594
- );
595
- }
596
- })
597
- )
598
- };
599
- default:
600
- return {
601
- ...acc,
602
- [name]: transformSchema(createAttributeSchema(attribute))
603
- };
604
- }
605
- }, {})
606
- ).default(null);
607
- return createModelSchema(attributes);
608
- };
609
- const createAttributeSchema = (attribute) => {
610
- switch (attribute.type) {
611
- case "biginteger":
612
- return yup.string().matches(/^-?\d*$/);
613
- case "boolean":
614
- return yup.boolean();
615
- case "blocks":
616
- return yup.mixed().test("isBlocks", translatedErrors.json, (value) => {
617
- if (!value || Array.isArray(value)) {
618
- return true;
619
- } else {
620
- return false;
621
- }
622
- });
623
- case "decimal":
624
- case "float":
625
- case "integer":
626
- return yup.number();
627
- case "email":
628
- return yup.string().email(translatedErrors.email);
629
- case "enumeration":
630
- return yup.string().oneOf([...attribute.enum, null]);
631
- case "json":
632
- return yup.mixed().test("isJSON", translatedErrors.json, (value) => {
633
- if (!value || typeof value === "string" && value.length === 0) {
634
- return true;
635
- }
636
- if (typeof value === "object") {
637
- try {
638
- JSON.stringify(value);
639
- return true;
640
- } catch (err) {
641
- return false;
642
- }
643
- }
644
- try {
645
- JSON.parse(value);
646
- return true;
647
- } catch (err) {
648
- return false;
649
- }
650
- });
651
- case "password":
652
- case "richtext":
653
- case "string":
654
- case "text":
655
- return yup.string();
656
- case "uid":
657
- return yup.string().matches(/^[A-Za-z0-9-_.~]*$/);
658
- default:
659
- return yup.mixed();
660
- }
661
- };
662
- const nullableSchema = (schema) => {
663
- return schema?.nullable ? schema.nullable() : (
664
- // In some cases '.nullable' will not be available on the schema.
665
- // e.g. when the schema has been built using yup.lazy (e.g. for relations).
666
- // In these cases we should just return the schema as it is.
667
- schema
668
- );
669
- };
670
- const addNullableValidation = () => (schema) => {
671
- return nullableSchema(schema);
672
- };
673
- const addRequiredValidation = (attribute, options) => (schema) => {
674
- if (options.status === "draft" || !attribute.required) {
675
- return schema;
676
- }
677
- if (attribute.required && "required" in schema) {
678
- return schema.required(translatedErrors.required);
679
- }
680
- return schema;
681
- };
682
- const addMinLengthValidation = (attribute, options) => (schema) => {
683
- if (options.status === "draft") {
684
- return schema;
685
- }
686
- if ("minLength" in attribute && attribute.minLength && Number.isInteger(attribute.minLength) && "min" in schema) {
687
- return schema.min(attribute.minLength, {
688
- ...translatedErrors.minLength,
689
- values: {
690
- min: attribute.minLength
691
- }
692
- });
693
- }
694
- return schema;
695
- };
696
- const addMaxLengthValidation = (attribute) => (schema) => {
697
- if ("maxLength" in attribute && attribute.maxLength && Number.isInteger(attribute.maxLength) && "max" in schema) {
698
- return schema.max(attribute.maxLength, {
699
- ...translatedErrors.maxLength,
700
- values: {
701
- max: attribute.maxLength
702
- }
703
- });
704
- }
705
- return schema;
706
- };
707
- const addMinValidation = (attribute, options) => (schema) => {
708
- if (options.status === "draft") {
709
- return schema;
710
- }
711
- if ("min" in attribute && "min" in schema) {
712
- const min = toInteger(attribute.min);
713
- if (min) {
714
- return schema.min(min, {
715
- ...translatedErrors.min,
716
- values: {
717
- min
718
- }
719
- });
720
- }
721
- }
722
- return schema;
723
- };
724
- const addMaxValidation = (attribute) => (schema) => {
725
- if ("max" in attribute) {
726
- const max = toInteger(attribute.max);
727
- if ("max" in schema && max) {
728
- return schema.max(max, {
729
- ...translatedErrors.max,
730
- values: {
731
- max
732
- }
733
- });
734
- }
735
- }
736
- return schema;
737
- };
738
- const toInteger = (val) => {
739
- if (typeof val === "number" || val === void 0) {
740
- return val;
741
- } else {
742
- const num = Number(val);
743
- return isNaN(num) ? void 0 : num;
744
- }
745
- };
746
- const addRegexValidation = (attribute) => (schema) => {
747
- if ("regex" in attribute && attribute.regex && "matches" in schema) {
748
- return schema.matches(new RegExp(attribute.regex), {
749
- message: {
750
- id: translatedErrors.regex.id,
751
- defaultMessage: "The value does not match the defined pattern."
752
- },
753
- excludeEmptyString: !attribute.required
754
- });
755
- }
756
- return schema;
757
- };
758
- const initApi = contentManagerApi.injectEndpoints({
759
- endpoints: (builder) => ({
760
- getInitialData: builder.query({
761
- query: () => "/content-manager/init",
762
- transformResponse: (response) => response.data,
763
- providesTags: ["InitialData"]
764
- })
765
- })
766
- });
767
- const { useGetInitialDataQuery } = initApi;
768
- const useContentTypeSchema = (model) => {
769
- const { toggleNotification } = useNotification();
770
- const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
771
- const { data, error, isLoading, isFetching } = useGetInitialDataQuery(void 0);
772
- const { components, contentType, contentTypes } = React.useMemo(() => {
773
- const contentType2 = data?.contentTypes.find((ct) => ct.uid === model);
774
- const componentsByKey = data?.components.reduce((acc, component) => {
775
- acc[component.uid] = component;
776
- return acc;
777
- }, {});
778
- const components2 = extractContentTypeComponents(contentType2?.attributes, componentsByKey);
779
- return {
780
- components: Object.keys(components2).length === 0 ? void 0 : components2,
781
- contentType: contentType2,
782
- contentTypes: data?.contentTypes ?? []
783
- };
784
- }, [model, data]);
785
- React.useEffect(() => {
786
- if (error) {
787
- toggleNotification({
788
- type: "danger",
789
- message: formatAPIError(error)
790
- });
791
- }
792
- }, [toggleNotification, error, formatAPIError]);
793
- return {
794
- // This must be memoized to avoid inifiinite re-renders where the empty object is different everytime.
795
- components: React.useMemo(() => components ?? {}, [components]),
796
- schema: contentType,
797
- schemas: contentTypes,
798
- isLoading: isLoading || isFetching
799
- };
800
- };
801
- const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
802
- const getComponents = (attributes2) => {
803
- return attributes2.reduce((acc, attribute) => {
804
- if (attribute.type === "component") {
805
- const componentAttributes = Object.values(
806
- allComponents[attribute.component]?.attributes ?? {}
807
- );
808
- acc.push(attribute.component, ...getComponents(componentAttributes));
809
- } else if (attribute.type === "dynamiczone") {
810
- acc.push(
811
- ...attribute.components,
812
- ...attribute.components.flatMap((componentUid) => {
813
- const componentAttributes = Object.values(
814
- allComponents[componentUid]?.attributes ?? {}
815
- );
816
- return getComponents(componentAttributes);
817
- })
818
- );
819
- }
820
- return acc;
821
- }, []);
822
- };
823
- const componentUids = getComponents(Object.values(attributes));
824
- const uniqueComponentUids = [...new Set(componentUids)];
825
- const componentsByKey = uniqueComponentUids.reduce((acc, uid) => {
826
- acc[uid] = allComponents[uid];
827
- return acc;
828
- }, {});
829
- return componentsByKey;
830
- };
831
- const HOOKS = {
832
- /**
833
- * Hook that allows to mutate the displayed headers of the list view table
834
- * @constant
835
- * @type {string}
836
- */
837
- INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
838
- /**
839
- * Hook that allows to mutate the CM's collection types links pre-set filters
840
- * @constant
841
- * @type {string}
842
- */
843
- MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
844
- /**
845
- * Hook that allows to mutate the CM's edit view layout
846
- * @constant
847
- * @type {string}
848
- */
849
- MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
850
- /**
851
- * Hook that allows to mutate the CM's single types links pre-set filters
852
- * @constant
853
- * @type {string}
854
- */
855
- MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
856
- };
857
- const contentTypesApi = contentManagerApi.injectEndpoints({
858
- endpoints: (builder) => ({
859
- getContentTypeConfiguration: builder.query({
860
- query: (uid) => ({
861
- url: `/content-manager/content-types/${uid}/configuration`,
862
- method: "GET"
863
- }),
864
- transformResponse: (response) => response.data,
865
- providesTags: (_result, _error, uid) => [
866
- { type: "ContentTypesConfiguration", id: uid },
867
- { type: "ContentTypeSettings", id: "LIST" }
868
- ]
869
- }),
870
- getAllContentTypeSettings: builder.query({
871
- query: () => "/content-manager/content-types-settings",
872
- transformResponse: (response) => response.data,
873
- providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
874
- }),
875
- updateContentTypeConfiguration: builder.mutation({
876
- query: ({ uid, ...body }) => ({
877
- url: `/content-manager/content-types/${uid}/configuration`,
878
- method: "PUT",
879
- data: body
880
- }),
881
- transformResponse: (response) => response.data,
882
- invalidatesTags: (_result, _error, { uid }) => [
883
- { type: "ContentTypesConfiguration", id: uid },
884
- { type: "ContentTypeSettings", id: "LIST" },
885
- // Is this necessary?
886
- { type: "InitialData" }
887
- ]
888
- })
889
- })
890
- });
891
- const {
892
- useGetContentTypeConfigurationQuery,
893
- useGetAllContentTypeSettingsQuery,
894
- useUpdateContentTypeConfigurationMutation
895
- } = contentTypesApi;
896
- const checkIfAttributeIsDisplayable = (attribute) => {
897
- const { type } = attribute;
898
- if (type === "relation") {
899
- return !attribute.relation.toLowerCase().includes("morph");
900
- }
901
- return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
902
- };
903
- const getMainField = (attribute, mainFieldName, { schemas, components }) => {
904
- if (!mainFieldName) {
905
- return void 0;
906
- }
907
- const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
908
- // @ts-expect-error – `targetModel` does exist on the attribute for a relation.
909
- schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
910
- );
911
- return {
912
- name: mainFieldName,
913
- type: mainFieldType ?? "string"
914
- };
915
- };
916
- const DEFAULT_SETTINGS = {
917
- bulkable: false,
918
- filterable: false,
919
- searchable: false,
920
- pagination: false,
921
- defaultSortBy: "",
922
- defaultSortOrder: "asc",
923
- mainField: "id",
924
- pageSize: 10
925
- };
926
- const useDocumentLayout = (model) => {
927
- const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
928
- const [{ query }] = useQueryParams();
929
- const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
930
- const { toggleNotification } = useNotification();
931
- const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
932
- const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
933
- const {
934
- data,
935
- isLoading: isLoadingConfigs,
936
- error,
937
- isFetching: isFetchingConfigs
938
- } = useGetContentTypeConfigurationQuery(model);
939
- const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
940
- React.useEffect(() => {
941
- if (error) {
942
- toggleNotification({
943
- type: "danger",
944
- message: formatAPIError(error)
945
- });
946
- }
947
- }, [error, formatAPIError, toggleNotification]);
948
- const editLayout = React.useMemo(
949
- () => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
950
- layout: [],
951
- components: {},
952
- metadatas: {},
953
- options: {},
954
- settings: DEFAULT_SETTINGS
955
- },
956
- [data, isLoading, schemas, schema, components]
957
- );
958
- const listLayout = React.useMemo(() => {
959
- return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
960
- layout: [],
961
- metadatas: {},
962
- options: {},
963
- settings: DEFAULT_SETTINGS
964
- };
965
- }, [data, isLoading, schemas, schema, components]);
966
- const { layout: edit } = React.useMemo(
967
- () => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
968
- layout: editLayout,
969
- query
970
- }),
971
- [editLayout, query, runHookWaterfall]
972
- );
973
- return {
974
- error,
975
- isLoading,
976
- edit,
977
- list: listLayout
978
- };
979
- };
980
- const useDocLayout = () => {
981
- const { model } = useDoc();
982
- return useDocumentLayout(model);
983
- };
984
- const formatEditLayout = (data, {
985
- schemas,
986
- schema,
987
- components
988
- }) => {
989
- let currentPanelIndex = 0;
990
- const panelledEditAttributes = convertEditLayoutToFieldLayouts(
991
- data.contentType.layouts.edit,
992
- schema?.attributes,
993
- data.contentType.metadatas,
994
- { configurations: data.components, schemas: components },
995
- schemas
996
- ).reduce((panels, row) => {
997
- if (row.some((field) => field.type === "dynamiczone")) {
998
- panels.push([row]);
999
- currentPanelIndex += 2;
1000
- } else {
1001
- if (!panels[currentPanelIndex]) {
1002
- panels.push([row]);
1003
- } else {
1004
- panels[currentPanelIndex].push(row);
1005
- }
1006
- }
1007
- return panels;
1008
- }, []);
1009
- const componentEditAttributes = Object.entries(data.components).reduce(
1010
- (acc, [uid, configuration]) => {
1011
- acc[uid] = {
1012
- layout: convertEditLayoutToFieldLayouts(
1013
- configuration.layouts.edit,
1014
- components[uid].attributes,
1015
- configuration.metadatas,
1016
- { configurations: data.components, schemas: components }
1017
- ),
1018
- settings: {
1019
- ...configuration.settings,
1020
- icon: components[uid].info.icon,
1021
- displayName: components[uid].info.displayName
1022
- }
1023
- };
1024
- return acc;
1025
- },
1026
- {}
1027
- );
1028
- const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
1029
- (acc, [attribute, metadata]) => {
1030
- return {
1031
- ...acc,
1032
- [attribute]: metadata.edit
1033
- };
1034
- },
1035
- {}
1036
- );
1037
- return {
1038
- layout: panelledEditAttributes,
1039
- components: componentEditAttributes,
1040
- metadatas: editMetadatas,
1041
- settings: {
1042
- ...data.contentType.settings,
1043
- displayName: schema?.info.displayName
1044
- },
1045
- options: {
1046
- ...schema?.options,
1047
- ...schema?.pluginOptions,
1048
- ...data.contentType.options
1049
- }
1050
- };
1051
- };
1052
- const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
1053
- return rows.map(
1054
- (row) => row.map((field) => {
1055
- const attribute = attributes[field.name];
1056
- if (!attribute) {
1057
- return null;
1058
- }
1059
- const { edit: metadata } = metadatas[field.name];
1060
- const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
1061
- return {
1062
- attribute,
1063
- disabled: !metadata.editable,
1064
- hint: metadata.description,
1065
- label: metadata.label ?? "",
1066
- name: field.name,
1067
- // @ts-expect-error – mainField does exist on the metadata for a relation.
1068
- mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
1069
- schemas,
1070
- components: components?.schemas ?? {}
1071
- }),
1072
- placeholder: metadata.placeholder ?? "",
1073
- required: attribute.required ?? false,
1074
- size: field.size,
1075
- unique: "unique" in attribute ? attribute.unique : false,
1076
- visible: metadata.visible ?? true,
1077
- type: attribute.type
1078
- };
1079
- }).filter((field) => field !== null)
1080
- );
1081
- };
1082
- const formatListLayout = (data, {
1083
- schemas,
1084
- schema,
1085
- components
1086
- }) => {
1087
- const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
1088
- (acc, [attribute, metadata]) => {
1089
- return {
1090
- ...acc,
1091
- [attribute]: metadata.list
1092
- };
1093
- },
1094
- {}
1095
- );
1096
- const listAttributes = convertListLayoutToFieldLayouts(
1097
- data.contentType.layouts.list,
1098
- schema?.attributes,
1099
- listMetadatas,
1100
- { configurations: data.components, schemas: components },
1101
- schemas
1102
- );
1103
- return {
1104
- layout: listAttributes,
1105
- settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
1106
- metadatas: listMetadatas,
1107
- options: {
1108
- ...schema?.options,
1109
- ...schema?.pluginOptions,
1110
- ...data.contentType.options
1111
- }
1112
- };
1113
- };
1114
- const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
1115
- return columns.map((name) => {
1116
- const attribute = attributes[name];
1117
- if (!attribute) {
1118
- return null;
1119
- }
1120
- const metadata = metadatas[name];
1121
- const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
1122
- return {
1123
- attribute,
1124
- label: metadata.label ?? "",
1125
- mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
1126
- schemas,
1127
- components: components?.schemas ?? {}
1128
- }),
1129
- name,
1130
- searchable: metadata.searchable ?? true,
1131
- sortable: metadata.sortable ?? true
1132
- };
1133
- }).filter((field) => field !== null);
1134
- };
1135
- const useDocument = (args, opts) => {
1136
- const { toggleNotification } = useNotification();
1137
- const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
1138
- const {
1139
- currentData: data,
1140
- isLoading: isLoadingDocument,
1141
- isFetching: isFetchingDocument,
1142
- error
1143
- } = useGetDocumentQuery(args, {
1144
- ...opts,
1145
- skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
1146
- });
1147
- const {
1148
- components,
1149
- schema,
1150
- schemas,
1151
- isLoading: isLoadingSchema
1152
- } = useContentTypeSchema(args.model);
1153
- React.useEffect(() => {
1154
- if (error) {
1155
- toggleNotification({
1156
- type: "danger",
1157
- message: formatAPIError(error)
1158
- });
1159
- }
1160
- }, [toggleNotification, error, formatAPIError, args.collectionType]);
1161
- const validationSchema = React.useMemo(() => {
1162
- if (!schema) {
1163
- return null;
1164
- }
1165
- return createYupSchema(schema.attributes, components);
1166
- }, [schema, components]);
1167
- const validate = React.useCallback(
1168
- (document) => {
1169
- if (!validationSchema) {
1170
- throw new Error(
1171
- "There is no validation schema generated, this is likely due to the schema not being loaded yet."
1172
- );
1173
- }
1174
- try {
1175
- validationSchema.validateSync(document, { abortEarly: false, strict: true });
1176
- return null;
1177
- } catch (error2) {
1178
- if (error2 instanceof ValidationError) {
1179
- return getYupValidationErrors(error2);
1180
- }
1181
- throw error2;
1182
- }
1183
- },
1184
- [validationSchema]
1185
- );
1186
- const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
1187
- const hasError = !!error;
1188
- return {
1189
- components,
1190
- document: data?.data,
1191
- meta: data?.meta,
1192
- isLoading,
1193
- hasError,
1194
- schema,
1195
- schemas,
1196
- validate
1197
- };
1198
- };
1199
- const useDoc = () => {
1200
- const { id, slug, collectionType, origin } = useParams();
1201
- const [{ query }] = useQueryParams();
1202
- const params = React.useMemo(() => buildValidParams(query), [query]);
1203
- if (!collectionType) {
1204
- throw new Error("Could not find collectionType in url params");
1205
- }
1206
- if (!slug) {
1207
- throw new Error("Could not find model in url params");
1208
- }
1209
- const document = useDocument(
1210
- { documentId: origin || id, model: slug, collectionType, params },
1211
- {
1212
- skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
1213
- }
1214
- );
1215
- const returnId = origin || id === "create" ? void 0 : id;
1216
- return {
1217
- collectionType,
1218
- model: slug,
1219
- id: returnId,
1220
- ...document
1221
- };
1222
- };
1223
- const useContentManagerContext = () => {
1224
- const {
1225
- collectionType,
1226
- model,
1227
- id,
1228
- components,
1229
- isLoading: isLoadingDoc,
1230
- schema,
1231
- schemas
1232
- } = useDoc();
1233
- const layout = useDocumentLayout(model);
1234
- const form = useForm("useContentManagerContext", (state) => state);
1235
- const isSingleType = collectionType === SINGLE_TYPES;
1236
- const slug = model;
1237
- const isCreatingEntry = id === "create";
1238
- useContentTypeSchema();
1239
- const isLoading = isLoadingDoc || layout.isLoading;
1240
- const error = layout.error;
1241
- return {
1242
- error,
1243
- isLoading,
1244
- // Base metadata
1245
- model,
1246
- collectionType,
1247
- id,
1248
- slug,
1249
- isCreatingEntry,
1250
- isSingleType,
1251
- hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
1252
- // All schema infos
1253
- components,
1254
- contentType: schema,
1255
- contentTypes: schemas,
1256
- // Form state
1257
- form,
1258
- // layout infos
1259
- layout
1260
- };
1261
- };
1262
- const prefixPluginTranslations = (trad, pluginId) => {
1263
- return Object.keys(trad).reduce((acc, current) => {
1264
- acc[`${pluginId}.${current}`] = trad[current];
1265
- return acc;
1266
- }, {});
1267
- };
1268
- const getTranslation = (id) => `content-manager.${id}`;
1269
- const DEFAULT_UNEXPECTED_ERROR_MSG = {
1270
- id: "notification.error",
1271
- defaultMessage: "An error occurred, please try again"
1272
- };
1273
- const useDocumentActions = () => {
1274
- const { toggleNotification } = useNotification();
1275
- const { formatMessage } = useIntl();
1276
- const { trackUsage } = useTracking();
1277
- const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
1278
- const navigate = useNavigate();
1279
- const setCurrentStep = useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
1280
- const [deleteDocument] = useDeleteDocumentMutation();
1281
- const _delete = React.useCallback(
1282
- async ({ collectionType, model, documentId, params }, trackerProperty) => {
1283
- try {
1284
- trackUsage("willDeleteEntry", trackerProperty);
1285
- const res = await deleteDocument({
1286
- collectionType,
1287
- model,
1288
- documentId,
1289
- params
1290
- });
1291
- if ("error" in res) {
1292
- toggleNotification({
1293
- type: "danger",
1294
- message: formatAPIError(res.error)
1295
- });
1296
- return { error: res.error };
1297
- }
1298
- toggleNotification({
1299
- type: "success",
1300
- message: formatMessage({
1301
- id: getTranslation("success.record.delete"),
1302
- defaultMessage: "Deleted document"
1303
- })
1304
- });
1305
- trackUsage("didDeleteEntry", trackerProperty);
1306
- return res.data;
1307
- } catch (err) {
1308
- toggleNotification({
1309
- type: "danger",
1310
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1311
- });
1312
- trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
1313
- throw err;
1314
- }
1315
- },
1316
- [trackUsage, deleteDocument, toggleNotification, formatMessage, formatAPIError]
1317
- );
1318
- const [deleteManyDocuments] = useDeleteManyDocumentsMutation();
1319
- const deleteMany = React.useCallback(
1320
- async ({ model, documentIds, params }) => {
1321
- try {
1322
- trackUsage("willBulkDeleteEntries");
1323
- const res = await deleteManyDocuments({
1324
- model,
1325
- documentIds,
1326
- params
1327
- });
1328
- if ("error" in res) {
1329
- toggleNotification({
1330
- type: "danger",
1331
- message: formatAPIError(res.error)
1332
- });
1333
- return { error: res.error };
1334
- }
1335
- toggleNotification({
1336
- type: "success",
1337
- title: formatMessage({
1338
- id: getTranslation("success.records.delete"),
1339
- defaultMessage: "Successfully deleted."
1340
- }),
1341
- message: ""
1342
- });
1343
- trackUsage("didBulkDeleteEntries");
1344
- return res.data;
1345
- } catch (err) {
1346
- toggleNotification({
1347
- type: "danger",
1348
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1349
- });
1350
- trackUsage("didNotBulkDeleteEntries");
1351
- throw err;
1352
- }
1353
- },
1354
- [trackUsage, deleteManyDocuments, toggleNotification, formatMessage, formatAPIError]
1355
- );
1356
- const [discardDocument] = useDiscardDocumentMutation();
1357
- const discard = React.useCallback(
1358
- async ({ collectionType, model, documentId, params }) => {
1359
- try {
1360
- const res = await discardDocument({
1361
- collectionType,
1362
- model,
1363
- documentId,
1364
- params
1365
- });
1366
- if ("error" in res) {
1367
- toggleNotification({
1368
- type: "danger",
1369
- message: formatAPIError(res.error)
1370
- });
1371
- return { error: res.error };
1372
- }
1373
- toggleNotification({
1374
- type: "success",
1375
- message: formatMessage({
1376
- id: "content-manager.success.record.discard",
1377
- defaultMessage: "Changes discarded"
1378
- })
1379
- });
1380
- return res.data;
1381
- } catch (err) {
1382
- toggleNotification({
1383
- type: "danger",
1384
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1385
- });
1386
- throw err;
1387
- }
1388
- },
1389
- [discardDocument, formatAPIError, formatMessage, toggleNotification]
1390
- );
1391
- const [publishDocument] = usePublishDocumentMutation();
1392
- const publish = React.useCallback(
1393
- async ({ collectionType, model, documentId, params }, data) => {
1394
- try {
1395
- trackUsage("willPublishEntry");
1396
- const res = await publishDocument({
1397
- collectionType,
1398
- model,
1399
- documentId,
1400
- data,
1401
- params
1402
- });
1403
- if ("error" in res) {
1404
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1405
- return { error: res.error };
1406
- }
1407
- trackUsage("didPublishEntry");
1408
- toggleNotification({
1409
- type: "success",
1410
- message: formatMessage({
1411
- id: getTranslation("success.record.publish"),
1412
- defaultMessage: "Published document"
1413
- })
1414
- });
1415
- return res.data;
1416
- } catch (err) {
1417
- toggleNotification({
1418
- type: "danger",
1419
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1420
- });
1421
- throw err;
1422
- }
1423
- },
1424
- [trackUsage, publishDocument, toggleNotification, formatMessage, formatAPIError]
1425
- );
1426
- const [publishManyDocuments] = usePublishManyDocumentsMutation();
1427
- const publishMany = React.useCallback(
1428
- async ({ model, documentIds, params }) => {
1429
- try {
1430
- const res = await publishManyDocuments({
1431
- model,
1432
- documentIds,
1433
- params
1434
- });
1435
- if ("error" in res) {
1436
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1437
- return { error: res.error };
1438
- }
1439
- toggleNotification({
1440
- type: "success",
1441
- message: formatMessage({
1442
- id: getTranslation("success.record.publish"),
1443
- defaultMessage: "Published document"
1444
- })
1445
- });
1446
- return res.data;
1447
- } catch (err) {
1448
- toggleNotification({
1449
- type: "danger",
1450
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1451
- });
1452
- throw err;
1453
- }
1454
- },
1455
- [
1456
- // trackUsage,
1457
- publishManyDocuments,
1458
- toggleNotification,
1459
- formatMessage,
1460
- formatAPIError
1461
- ]
1462
- );
1463
- const [updateDocument] = useUpdateDocumentMutation();
1464
- const update = React.useCallback(
1465
- async ({ collectionType, model, documentId, params }, data, trackerProperty) => {
1466
- try {
1467
- trackUsage("willEditEntry", trackerProperty);
1468
- const res = await updateDocument({
1469
- collectionType,
1470
- model,
1471
- documentId,
1472
- data,
1473
- params
1474
- });
1475
- if ("error" in res) {
1476
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1477
- trackUsage("didNotEditEntry", { error: res.error, ...trackerProperty });
1478
- return { error: res.error };
1479
- }
1480
- trackUsage("didEditEntry", trackerProperty);
1481
- toggleNotification({
1482
- type: "success",
1483
- message: formatMessage({
1484
- id: getTranslation("success.record.save"),
1485
- defaultMessage: "Saved document"
1486
- })
1487
- });
1488
- return res.data;
1489
- } catch (err) {
1490
- trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
1491
- toggleNotification({
1492
- type: "danger",
1493
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1494
- });
1495
- throw err;
1496
- }
1497
- },
1498
- [trackUsage, updateDocument, toggleNotification, formatMessage, formatAPIError]
1499
- );
1500
- const [unpublishDocument] = useUnpublishDocumentMutation();
1501
- const unpublish = React.useCallback(
1502
- async ({ collectionType, model, documentId, params }, discardDraft = false) => {
1503
- try {
1504
- trackUsage("willUnpublishEntry");
1505
- const res = await unpublishDocument({
1506
- collectionType,
1507
- model,
1508
- documentId,
1509
- params,
1510
- data: {
1511
- discardDraft
1512
- }
1513
- });
1514
- if ("error" in res) {
1515
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1516
- return { error: res.error };
1517
- }
1518
- trackUsage("didUnpublishEntry");
1519
- toggleNotification({
1520
- type: "success",
1521
- message: formatMessage({
1522
- id: getTranslation("success.record.unpublish"),
1523
- defaultMessage: "Unpublished document"
1524
- })
1525
- });
1526
- return res.data;
1527
- } catch (err) {
1528
- toggleNotification({
1529
- type: "danger",
1530
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1531
- });
1532
- throw err;
1533
- }
1534
- },
1535
- [trackUsage, unpublishDocument, toggleNotification, formatMessage, formatAPIError]
1536
- );
1537
- const [unpublishManyDocuments] = useUnpublishManyDocumentsMutation();
1538
- const unpublishMany = React.useCallback(
1539
- async ({ model, documentIds, params }) => {
1540
- try {
1541
- trackUsage("willBulkUnpublishEntries");
1542
- const res = await unpublishManyDocuments({
1543
- model,
1544
- documentIds,
1545
- params
1546
- });
1547
- if ("error" in res) {
1548
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1549
- return { error: res.error };
1550
- }
1551
- trackUsage("didBulkUnpublishEntries");
1552
- toggleNotification({
1553
- type: "success",
1554
- title: formatMessage({
1555
- id: getTranslation("success.records.unpublish"),
1556
- defaultMessage: "Successfully unpublished."
1557
- }),
1558
- message: ""
1559
- });
1560
- return res.data;
1561
- } catch (err) {
1562
- toggleNotification({
1563
- type: "danger",
1564
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1565
- });
1566
- trackUsage("didNotBulkUnpublishEntries");
1567
- throw err;
1568
- }
1569
- },
1570
- [trackUsage, unpublishManyDocuments, toggleNotification, formatMessage, formatAPIError]
1571
- );
1572
- const [createDocument] = useCreateDocumentMutation();
1573
- const create = React.useCallback(
1574
- async ({ model, params }, data, trackerProperty) => {
1575
- try {
1576
- const res = await createDocument({
1577
- model,
1578
- data,
1579
- params
1580
- });
1581
- if ("error" in res) {
1582
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1583
- trackUsage("didNotCreateEntry", { error: res.error, ...trackerProperty });
1584
- return { error: res.error };
1585
- }
1586
- trackUsage("didCreateEntry", trackerProperty);
1587
- toggleNotification({
1588
- type: "success",
1589
- message: formatMessage({
1590
- id: getTranslation("success.record.save"),
1591
- defaultMessage: "Saved document"
1592
- })
1593
- });
1594
- setCurrentStep("contentManager.success");
1595
- return res.data;
1596
- } catch (err) {
1597
- toggleNotification({
1598
- type: "danger",
1599
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1600
- });
1601
- trackUsage("didNotCreateEntry", { error: err, ...trackerProperty });
1602
- throw err;
1603
- }
1604
- },
1605
- [createDocument, formatAPIError, formatMessage, toggleNotification, trackUsage]
1606
- );
1607
- const [autoCloneDocument] = useAutoCloneDocumentMutation();
1608
- const autoClone = React.useCallback(
1609
- async ({ model, sourceId }) => {
1610
- try {
1611
- const res = await autoCloneDocument({
1612
- model,
1613
- sourceId
1614
- });
1615
- if ("error" in res) {
1616
- return { error: res.error };
1617
- }
1618
- toggleNotification({
1619
- type: "success",
1620
- message: formatMessage({
1621
- id: getTranslation("success.record.clone"),
1622
- defaultMessage: "Cloned document"
1623
- })
1624
- });
1625
- return res.data;
1626
- } catch (err) {
1627
- toggleNotification({
1628
- type: "danger",
1629
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1630
- });
1631
- throw err;
1632
- }
1633
- },
1634
- [autoCloneDocument, formatMessage, toggleNotification]
1635
- );
1636
- const [cloneDocument] = useCloneDocumentMutation();
1637
- const clone = React.useCallback(
1638
- async ({ model, documentId, params }, body, trackerProperty) => {
1639
- try {
1640
- const { id: _id, ...restBody } = body;
1641
- const res = await cloneDocument({
1642
- model,
1643
- sourceId: documentId,
1644
- data: restBody,
1645
- params
1646
- });
1647
- if ("error" in res) {
1648
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1649
- trackUsage("didNotCreateEntry", { error: res.error, ...trackerProperty });
1650
- return { error: res.error };
1651
- }
1652
- trackUsage("didCreateEntry", trackerProperty);
1653
- toggleNotification({
1654
- type: "success",
1655
- message: formatMessage({
1656
- id: getTranslation("success.record.clone"),
1657
- defaultMessage: "Cloned document"
1658
- })
1659
- });
1660
- navigate(`../../${res.data.data.documentId}`, { relative: "path" });
1661
- return res.data;
1662
- } catch (err) {
1663
- toggleNotification({
1664
- type: "danger",
1665
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1666
- });
1667
- trackUsage("didNotCreateEntry", { error: err, ...trackerProperty });
1668
- throw err;
1669
- }
1670
- },
1671
- [cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError, navigate]
1672
- );
1673
- const [getDoc] = useLazyGetDocumentQuery();
1674
- const getDocument = React.useCallback(
1675
- async (args) => {
1676
- const { data } = await getDoc(args);
1677
- return data;
1678
- },
1679
- [getDoc]
1680
- );
1681
- return {
1682
- autoClone,
1683
- clone,
1684
- create,
1685
- delete: _delete,
1686
- deleteMany,
1687
- discard,
1688
- getDocument,
1689
- publish,
1690
- publishMany,
1691
- unpublish,
1692
- unpublishMany,
1693
- update
1694
- };
1695
- };
1696
- const ProtectedHistoryPage = React.lazy(
1697
- () => import("./History-DXZrV891.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
1698
- );
1699
- const routes$2 = [
1700
- {
1701
- path: ":collectionType/:slug/:id/history",
1702
- Component: ProtectedHistoryPage
1703
- },
1704
- {
1705
- path: ":collectionType/:slug/history",
1706
- Component: ProtectedHistoryPage
1707
- }
1708
- ];
1709
- const ProtectedPreviewPage = React.lazy(
1710
- () => import("./Preview-DeD_aLg6.mjs").then((mod) => ({ default: mod.ProtectedPreviewPage }))
1711
- );
1712
- const routes$1 = [
1713
- {
1714
- path: ":collectionType/:slug/:id/preview",
1715
- Component: ProtectedPreviewPage
1716
- },
1717
- {
1718
- path: ":collectionType/:slug/preview",
1719
- Component: ProtectedPreviewPage
1720
- }
1721
- ];
1722
- const ProtectedEditViewPage = lazy(
1723
- () => import("./EditViewPage-CxbLxtSZ.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
1724
- );
1725
- const ProtectedListViewPage = lazy(
1726
- () => import("./ListViewPage-CfHJAt9S.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
1727
- );
1728
- const ProtectedListConfiguration = lazy(
1729
- () => import("./ListConfigurationPage-B1BlI0vS.mjs").then((mod) => ({
1730
- default: mod.ProtectedListConfiguration
1731
- }))
1732
- );
1733
- const ProtectedEditConfigurationPage = lazy(
1734
- () => import("./EditConfigurationPage-BxxS_VjE.mjs").then((mod) => ({
1735
- default: mod.ProtectedEditConfigurationPage
1736
- }))
1737
- );
1738
- const ProtectedComponentConfigurationPage = lazy(
1739
- () => import("./ComponentConfigurationPage-xgUutqCq.mjs").then((mod) => ({
1740
- default: mod.ProtectedComponentConfigurationPage
1741
- }))
1742
- );
1743
- const NoPermissions = lazy(
1744
- () => import("./NoPermissionsPage-BZx6YZ0-.mjs").then((mod) => ({ default: mod.NoPermissions }))
1745
- );
1746
- const NoContentType = lazy(
1747
- () => import("./NoContentTypePage-B1vde0d2.mjs").then((mod) => ({ default: mod.NoContentType }))
1748
- );
1749
- const CollectionTypePages = () => {
1750
- const { collectionType } = useParams();
1751
- if (collectionType !== COLLECTION_TYPES && collectionType !== SINGLE_TYPES) {
1752
- return /* @__PURE__ */ jsx(Navigate, { to: "/404" });
1753
- }
1754
- return collectionType === COLLECTION_TYPES ? /* @__PURE__ */ jsx(ProtectedListViewPage, {}) : /* @__PURE__ */ jsx(ProtectedEditViewPage, {});
1755
- };
1756
- const CLONE_RELATIVE_PATH = ":collectionType/:slug/clone/:origin";
1757
- const CLONE_PATH = `/content-manager/${CLONE_RELATIVE_PATH}`;
1758
- const LIST_RELATIVE_PATH = ":collectionType/:slug";
1759
- const LIST_PATH = `/content-manager/collection-types/:slug`;
1760
- const routes = [
1761
- {
1762
- path: LIST_RELATIVE_PATH,
1763
- element: /* @__PURE__ */ jsx(CollectionTypePages, {})
1764
- },
1765
- {
1766
- path: ":collectionType/:slug/:id",
1767
- Component: ProtectedEditViewPage
1768
- },
1769
- {
1770
- path: CLONE_RELATIVE_PATH,
1771
- Component: ProtectedEditViewPage
1772
- },
1773
- {
1774
- path: ":collectionType/:slug/configurations/list",
1775
- Component: ProtectedListConfiguration
1776
- },
1777
- {
1778
- path: "components/:slug/configurations/edit",
1779
- Component: ProtectedComponentConfigurationPage
1780
- },
1781
- {
1782
- path: ":collectionType/:slug/configurations/edit",
1783
- Component: ProtectedEditConfigurationPage
1784
- },
1785
- {
1786
- path: "403",
1787
- Component: NoPermissions
1788
- },
1789
- {
1790
- path: "no-content-types",
1791
- Component: NoContentType
1792
- },
1793
- ...routes$2,
1794
- ...routes$1
1795
- ];
1796
- const DocumentActions = ({ actions: actions2 }) => {
1797
- const { formatMessage } = useIntl();
1798
- const [primaryAction, secondaryAction, ...restActions] = actions2.filter((action) => {
1799
- if (action.position === void 0) {
1800
- return true;
1801
- }
1802
- const positions = Array.isArray(action.position) ? action.position : [action.position];
1803
- return positions.includes("panel");
1804
- });
1805
- if (!primaryAction) {
1806
- return null;
1807
- }
1808
- return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, alignItems: "stretch", width: "100%", children: [
1809
- /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
1810
- /* @__PURE__ */ jsx(DocumentActionButton, { ...primaryAction, variant: primaryAction.variant || "default" }),
1811
- restActions.length > 0 ? /* @__PURE__ */ jsx(
1812
- DocumentActionsMenu,
1813
- {
1814
- actions: restActions,
1815
- label: formatMessage({
1816
- id: "content-manager.containers.edit.panels.default.more-actions",
1817
- defaultMessage: "More document actions"
1818
- })
1819
- }
1820
- ) : null
1821
- ] }),
1822
- secondaryAction ? /* @__PURE__ */ jsx(
1823
- DocumentActionButton,
1824
- {
1825
- ...secondaryAction,
1826
- variant: secondaryAction.variant || "secondary"
1827
- }
1828
- ) : null
1829
- ] });
1830
- };
1831
- const DocumentActionButton = (action) => {
1832
- const [dialogId, setDialogId] = React.useState(null);
1833
- const { toggleNotification } = useNotification();
1834
- const handleClick = (action2) => async (e) => {
1835
- const { onClick = () => false, dialog, id } = action2;
1836
- const muteDialog = await onClick(e);
1837
- if (dialog && !muteDialog) {
1838
- switch (dialog.type) {
1839
- case "notification":
1840
- toggleNotification({
1841
- title: dialog.title,
1842
- message: dialog.content,
1843
- type: dialog.status,
1844
- timeout: dialog.timeout,
1845
- onClose: dialog.onClose
1846
- });
1847
- break;
1848
- case "dialog":
1849
- case "modal":
1850
- e.preventDefault();
1851
- setDialogId(id);
1852
- }
1853
- }
1854
- };
1855
- const handleClose = () => {
1856
- setDialogId(null);
1857
- };
1858
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1859
- /* @__PURE__ */ jsx(
1860
- Button,
1861
- {
1862
- flex: "auto",
1863
- startIcon: action.icon,
1864
- disabled: action.disabled,
1865
- onClick: handleClick(action),
1866
- justifyContent: "center",
1867
- variant: action.variant || "default",
1868
- paddingTop: "7px",
1869
- paddingBottom: "7px",
1870
- children: action.label
1871
- }
1872
- ),
1873
- action.dialog?.type === "dialog" ? /* @__PURE__ */ jsx(
1874
- DocumentActionConfirmDialog,
1875
- {
1876
- ...action.dialog,
1877
- variant: action.dialog?.variant ?? action.variant,
1878
- isOpen: dialogId === action.id,
1879
- onClose: handleClose
1880
- }
1881
- ) : null,
1882
- action.dialog?.type === "modal" ? /* @__PURE__ */ jsx(
1883
- DocumentActionModal,
1884
- {
1885
- ...action.dialog,
1886
- onModalClose: handleClose,
1887
- isOpen: dialogId === action.id
1888
- }
1889
- ) : null
1890
- ] });
1891
- };
1892
- const MenuItem = styled(Menu.Item)`
1893
- &:hover {
1894
- background: ${({ theme, isVariantDanger, isDisabled }) => isVariantDanger && !isDisabled ? theme.colors.danger100 : "neutral"};
1895
- }
1896
- `;
1897
- const DocumentActionsMenu = ({
1898
- actions: actions2,
1899
- children,
1900
- label,
1901
- variant = "tertiary"
1902
- }) => {
1903
- const [isOpen, setIsOpen] = React.useState(false);
1904
- const [dialogId, setDialogId] = React.useState(null);
1905
- const { formatMessage } = useIntl();
1906
- const { toggleNotification } = useNotification();
1907
- const isDisabled = actions2.every((action) => action.disabled) || actions2.length === 0;
1908
- const handleClick = (action) => async (e) => {
1909
- const { onClick = () => false, dialog, id } = action;
1910
- const muteDialog = await onClick(e);
1911
- if (dialog && !muteDialog) {
1912
- switch (dialog.type) {
1913
- case "notification":
1914
- toggleNotification({
1915
- title: dialog.title,
1916
- message: dialog.content,
1917
- type: dialog.status,
1918
- timeout: dialog.timeout,
1919
- onClose: dialog.onClose
1920
- });
1921
- break;
1922
- case "dialog":
1923
- case "modal":
1924
- setDialogId(id);
1925
- }
1926
- }
1927
- };
1928
- const handleClose = () => {
1929
- setDialogId(null);
1930
- setIsOpen(false);
1931
- };
1932
- return /* @__PURE__ */ jsxs(Menu.Root, { open: isOpen, onOpenChange: setIsOpen, children: [
1933
- /* @__PURE__ */ jsxs(
1934
- Menu.Trigger,
1935
- {
1936
- disabled: isDisabled,
1937
- size: "S",
1938
- endIcon: null,
1939
- paddingTop: "4px",
1940
- paddingLeft: "7px",
1941
- paddingRight: "7px",
1942
- variant,
1943
- children: [
1944
- /* @__PURE__ */ jsx(More, { "aria-hidden": true, focusable: false }),
1945
- /* @__PURE__ */ jsx(VisuallyHidden, { tag: "span", children: label || formatMessage({
1946
- id: "content-manager.containers.edit.panels.default.more-actions",
1947
- defaultMessage: "More document actions"
1948
- }) })
1949
- ]
1950
- }
1951
- ),
1952
- /* @__PURE__ */ jsxs(Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
1953
- actions2.map((action) => {
1954
- return /* @__PURE__ */ jsx(
1955
- MenuItem,
1956
- {
1957
- disabled: action.disabled,
1958
- onSelect: handleClick(action),
1959
- display: "block",
1960
- isVariantDanger: action.variant === "danger",
1961
- isDisabled: action.disabled,
1962
- children: /* @__PURE__ */ jsx(Flex, { justifyContent: "space-between", gap: 4, children: /* @__PURE__ */ jsxs(
1963
- Flex,
1964
- {
1965
- color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
1966
- gap: 2,
1967
- tag: "span",
1968
- children: [
1969
- /* @__PURE__ */ jsx(
1970
- Flex,
1971
- {
1972
- tag: "span",
1973
- color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
1974
- children: action.icon
1975
- }
1976
- ),
1977
- action.label
1978
- ]
1979
- }
1980
- ) })
1981
- },
1982
- action.id
1983
- );
1984
- }),
1985
- children
1986
- ] }),
1987
- actions2.map((action) => {
1988
- return /* @__PURE__ */ jsxs(React.Fragment, { children: [
1989
- action.dialog?.type === "dialog" ? /* @__PURE__ */ jsx(
1990
- DocumentActionConfirmDialog,
1991
- {
1992
- ...action.dialog,
1993
- variant: action.variant,
1994
- isOpen: dialogId === action.id,
1995
- onClose: handleClose
1996
- }
1997
- ) : null,
1998
- action.dialog?.type === "modal" ? /* @__PURE__ */ jsx(
1999
- DocumentActionModal,
2000
- {
2001
- ...action.dialog,
2002
- onModalClose: handleClose,
2003
- isOpen: dialogId === action.id
2004
- }
2005
- ) : null
2006
- ] }, action.id);
2007
- })
2008
- ] });
2009
- };
2010
- const convertActionVariantToColor = (variant = "secondary") => {
2011
- switch (variant) {
2012
- case "danger":
2013
- return "danger600";
2014
- case "secondary":
2015
- return void 0;
2016
- case "success":
2017
- return "success600";
2018
- default:
2019
- return "primary600";
2020
- }
2021
- };
2022
- const convertActionVariantToIconColor = (variant = "secondary") => {
2023
- switch (variant) {
2024
- case "danger":
2025
- return "danger600";
2026
- case "secondary":
2027
- return "neutral500";
2028
- case "success":
2029
- return "success600";
2030
- default:
2031
- return "primary600";
2032
- }
2033
- };
2034
- const DocumentActionConfirmDialog = ({
2035
- onClose,
2036
- onCancel,
2037
- onConfirm,
2038
- title,
2039
- content,
2040
- isOpen,
2041
- variant = "secondary"
2042
- }) => {
2043
- const { formatMessage } = useIntl();
2044
- const handleClose = async () => {
2045
- if (onCancel) {
2046
- await onCancel();
2047
- }
2048
- onClose();
2049
- };
2050
- const handleConfirm = async () => {
2051
- if (onConfirm) {
2052
- await onConfirm();
2053
- }
2054
- onClose();
2055
- };
2056
- return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
2057
- /* @__PURE__ */ jsx(Dialog.Header, { children: title }),
2058
- /* @__PURE__ */ jsx(Dialog.Body, { children: content }),
2059
- /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
2060
- /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", fullWidth: true, children: formatMessage({
2061
- id: "app.components.Button.cancel",
2062
- defaultMessage: "Cancel"
2063
- }) }) }),
2064
- /* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, fullWidth: true, children: formatMessage({
2065
- id: "app.components.Button.confirm",
2066
- defaultMessage: "Confirm"
2067
- }) })
2068
- ] })
2069
- ] }) });
2070
- };
2071
- const DocumentActionModal = ({
2072
- isOpen,
2073
- title,
2074
- onClose,
2075
- footer: Footer,
2076
- content: Content,
2077
- onModalClose
2078
- }) => {
2079
- const handleClose = () => {
2080
- if (onClose) {
2081
- onClose();
2082
- }
2083
- onModalClose();
2084
- };
2085
- return /* @__PURE__ */ jsx(Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Modal.Content, { children: [
2086
- /* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: title }) }),
2087
- typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsx(Modal.Body, { children: Content }),
2088
- typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
2089
- ] }) });
2090
- };
2091
- const transformData = (data) => {
2092
- if (Array.isArray(data)) {
2093
- return data.map(transformData);
2094
- }
2095
- if (typeof data === "object" && data !== null) {
2096
- if ("apiData" in data) {
2097
- return data.apiData;
2098
- }
2099
- return mapValues(transformData)(data);
2100
- }
2101
- return data;
2102
- };
2103
- const PublishAction$1 = ({
2104
- activeTab,
2105
- documentId,
2106
- model,
2107
- collectionType,
2108
- meta,
2109
- document
2110
- }) => {
2111
- const { schema } = useDoc();
2112
- const navigate = useNavigate();
2113
- const { toggleNotification } = useNotification();
2114
- const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
2115
- const isListView = useMatch(LIST_PATH) !== null;
2116
- const isCloning = useMatch(CLONE_PATH) !== null;
2117
- const { id } = useParams();
2118
- const { formatMessage } = useIntl();
2119
- const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
2120
- const { publish } = useDocumentActions();
2121
- const [
2122
- countDraftRelations,
2123
- { isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
2124
- ] = useLazyGetDraftRelationCountQuery();
2125
- const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React.useState(0);
2126
- const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React.useState(0);
2127
- const [{ query, rawQuery }] = useQueryParams();
2128
- const params = React.useMemo(() => buildValidParams(query), [query]);
2129
- const modified = useForm("PublishAction", ({ modified: modified2 }) => modified2);
2130
- const setSubmitting = useForm("PublishAction", ({ setSubmitting: setSubmitting2 }) => setSubmitting2);
2131
- const isSubmitting = useForm("PublishAction", ({ isSubmitting: isSubmitting2 }) => isSubmitting2);
2132
- const validate = useForm("PublishAction", (state) => state.validate);
2133
- const setErrors = useForm("PublishAction", (state) => state.setErrors);
2134
- const formValues = useForm("PublishAction", ({ values }) => values);
2135
- React.useEffect(() => {
2136
- if (isErrorDraftRelations) {
2137
- toggleNotification({
2138
- type: "danger",
2139
- message: formatMessage({
2140
- id: getTranslation("error.records.fetch-draft-relatons"),
2141
- defaultMessage: "An error occurred while fetching draft relations on this document."
2142
- })
2143
- });
2144
- }
2145
- }, [isErrorDraftRelations, toggleNotification, formatMessage]);
2146
- React.useEffect(() => {
2147
- const localDraftRelations = /* @__PURE__ */ new Set();
2148
- const extractDraftRelations = (data) => {
2149
- const relations = data.connect || [];
2150
- relations.forEach((relation) => {
2151
- if (relation.status === "draft") {
2152
- localDraftRelations.add(relation.id);
2153
- }
2154
- });
2155
- };
2156
- const traverseAndExtract = (data) => {
2157
- Object.entries(data).forEach(([key, value]) => {
2158
- if (key === "connect" && Array.isArray(value)) {
2159
- extractDraftRelations({ connect: value });
2160
- } else if (typeof value === "object" && value !== null) {
2161
- traverseAndExtract(value);
2162
- }
2163
- });
2164
- };
2165
- if (!documentId || modified) {
2166
- traverseAndExtract(formValues);
2167
- setLocalCountOfDraftRelations(localDraftRelations.size);
2168
- }
2169
- }, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
2170
- React.useEffect(() => {
2171
- if (!document || !document.documentId || isListView) {
2172
- return;
2173
- }
2174
- const fetchDraftRelationsCount = async () => {
2175
- const { data, error } = await countDraftRelations({
2176
- collectionType,
2177
- model,
2178
- documentId,
2179
- params
2180
- });
2181
- if (error) {
2182
- throw error;
2183
- }
2184
- if (data) {
2185
- setServerCountOfDraftRelations(data.data);
2186
- }
2187
- };
2188
- fetchDraftRelationsCount();
2189
- }, [isListView, document, documentId, countDraftRelations, collectionType, model, params]);
2190
- const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
2191
- if (!schema?.options?.draftAndPublish) {
2192
- return null;
2193
- }
2194
- const performPublish = async () => {
2195
- setSubmitting(true);
2196
- try {
2197
- const { errors } = await validate(true, {
2198
- status: "published"
2199
- });
2200
- if (errors) {
2201
- toggleNotification({
2202
- type: "danger",
2203
- message: formatMessage({
2204
- id: "content-manager.validation.error",
2205
- defaultMessage: "There are validation errors in your document. Please fix them before saving."
2206
- })
2207
- });
2208
- return;
2209
- }
2210
- const res = await publish(
2211
- {
2212
- collectionType,
2213
- model,
2214
- documentId,
2215
- params
2216
- },
2217
- transformData(formValues)
2218
- );
2219
- if ("data" in res && collectionType !== SINGLE_TYPES) {
2220
- if (id === "create") {
2221
- navigate({
2222
- pathname: `../${collectionType}/${model}/${res.data.documentId}`,
2223
- search: rawQuery
2224
- });
2225
- }
2226
- } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
2227
- setErrors(formatValidationErrors(res.error));
2228
- }
2229
- } finally {
2230
- setSubmitting(false);
2231
- }
2232
- };
2233
- const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
2234
- const enableDraftRelationsCount = false;
2235
- const hasDraftRelations = enableDraftRelationsCount;
2236
- return {
2237
- /**
2238
- * Disabled when:
2239
- * - currently if you're cloning a document we don't support publish & clone at the same time.
2240
- * - the form is submitting
2241
- * - the active tab is the published tab
2242
- * - the document is already published & not modified
2243
- * - the document is being created & not modified
2244
- * - the user doesn't have the permission to publish
2245
- */
2246
- disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
2247
- label: formatMessage({
2248
- id: "app.utils.publish",
2249
- defaultMessage: "Publish"
2250
- }),
2251
- onClick: async () => {
2252
- await performPublish();
2253
- },
2254
- dialog: hasDraftRelations ? {
2255
- type: "dialog",
2256
- variant: "danger",
2257
- footer: null,
2258
- title: formatMessage({
2259
- id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
2260
- defaultMessage: "Confirmation"
2261
- }),
2262
- content: formatMessage(
2263
- {
2264
- id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
2265
- defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
2266
- },
2267
- {
2268
- count: totalDraftRelations
2269
- }
2270
- ),
2271
- onConfirm: async () => {
2272
- await performPublish();
2273
- }
2274
- } : void 0
2275
- };
2276
- };
2277
- PublishAction$1.type = "publish";
2278
- PublishAction$1.position = "panel";
2279
- const UpdateAction = ({
2280
- activeTab,
2281
- documentId,
2282
- model,
2283
- collectionType
2284
- }) => {
2285
- const navigate = useNavigate();
2286
- const { toggleNotification } = useNotification();
2287
- const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
2288
- const cloneMatch = useMatch(CLONE_PATH);
2289
- const isCloning = cloneMatch !== null;
2290
- const { formatMessage } = useIntl();
2291
- const { create, update, clone } = useDocumentActions();
2292
- const [{ query, rawQuery }] = useQueryParams();
2293
- const params = React.useMemo(() => buildValidParams(query), [query]);
2294
- const isSubmitting = useForm("UpdateAction", ({ isSubmitting: isSubmitting2 }) => isSubmitting2);
2295
- const modified = useForm("UpdateAction", ({ modified: modified2 }) => modified2);
2296
- const setSubmitting = useForm("UpdateAction", ({ setSubmitting: setSubmitting2 }) => setSubmitting2);
2297
- const document = useForm("UpdateAction", ({ values }) => values);
2298
- const validate = useForm("UpdateAction", (state) => state.validate);
2299
- const setErrors = useForm("UpdateAction", (state) => state.setErrors);
2300
- const resetForm = useForm("PublishAction", ({ resetForm: resetForm2 }) => resetForm2);
2301
- const handleUpdate = React.useCallback(async () => {
2302
- setSubmitting(true);
2303
- try {
2304
- if (!modified) {
2305
- return;
2306
- }
2307
- const { errors } = await validate(true, {
2308
- status: "draft"
2309
- });
2310
- if (errors) {
2311
- toggleNotification({
2312
- type: "danger",
2313
- message: formatMessage({
2314
- id: "content-manager.validation.error",
2315
- defaultMessage: "There are validation errors in your document. Please fix them before saving."
2316
- })
2317
- });
2318
- return;
2319
- }
2320
- if (isCloning) {
2321
- const res = await clone(
2322
- {
2323
- model,
2324
- documentId: cloneMatch.params.origin,
2325
- params
2326
- },
2327
- transformData(document)
2328
- );
2329
- if ("data" in res) {
2330
- navigate(
2331
- {
2332
- pathname: `../${res.data.documentId}`,
2333
- search: rawQuery
2334
- },
2335
- { relative: "path" }
2336
- );
2337
- } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
2338
- setErrors(formatValidationErrors(res.error));
2339
- }
2340
- } else if (documentId || collectionType === SINGLE_TYPES) {
2341
- const res = await update(
2342
- {
2343
- collectionType,
2344
- model,
2345
- documentId,
2346
- params
2347
- },
2348
- transformData(document)
2349
- );
2350
- if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
2351
- setErrors(formatValidationErrors(res.error));
2352
- } else {
2353
- resetForm();
2354
- }
2355
- } else {
2356
- const res = await create(
2357
- {
2358
- model,
2359
- params
2360
- },
2361
- transformData(document)
2362
- );
2363
- if ("data" in res && collectionType !== SINGLE_TYPES) {
2364
- navigate(
2365
- {
2366
- pathname: `../${res.data.documentId}`,
2367
- search: rawQuery
2368
- },
2369
- { replace: true, relative: "path" }
2370
- );
2371
- } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
2372
- setErrors(formatValidationErrors(res.error));
2373
- }
2374
- }
2375
- } finally {
2376
- setSubmitting(false);
2377
- }
2378
- }, [
2379
- clone,
2380
- cloneMatch?.params.origin,
2381
- collectionType,
2382
- create,
2383
- document,
2384
- documentId,
2385
- formatMessage,
2386
- formatValidationErrors,
2387
- isCloning,
2388
- model,
2389
- modified,
2390
- navigate,
2391
- params,
2392
- rawQuery,
2393
- resetForm,
2394
- setErrors,
2395
- setSubmitting,
2396
- toggleNotification,
2397
- update,
2398
- validate
2399
- ]);
2400
- React.useEffect(() => {
2401
- const handleKeyDown = (e) => {
2402
- if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
2403
- e.preventDefault();
2404
- handleUpdate();
2405
- }
2406
- };
2407
- window.addEventListener("keydown", handleKeyDown);
2408
- return () => {
2409
- window.removeEventListener("keydown", handleKeyDown);
2410
- };
2411
- }, [handleUpdate]);
2412
- return {
2413
- /**
2414
- * Disabled when:
2415
- * - the form is submitting
2416
- * - the document is not modified & we're not cloning (you can save a clone entity straight away)
2417
- * - the active tab is the published tab
2418
- */
2419
- disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
2420
- label: formatMessage({
2421
- id: "global.save",
2422
- defaultMessage: "Save"
2423
- }),
2424
- onClick: handleUpdate
2425
- };
2426
- };
2427
- UpdateAction.type = "update";
2428
- UpdateAction.position = "panel";
2429
- const UNPUBLISH_DRAFT_OPTIONS = {
2430
- KEEP: "keep",
2431
- DISCARD: "discard"
2432
- };
2433
- const UnpublishAction$1 = ({
2434
- activeTab,
2435
- documentId,
2436
- model,
2437
- collectionType,
2438
- document
2439
- }) => {
2440
- const { formatMessage } = useIntl();
2441
- const { schema } = useDoc();
2442
- const canPublish = useDocumentRBAC("UnpublishAction", ({ canPublish: canPublish2 }) => canPublish2);
2443
- const { unpublish } = useDocumentActions();
2444
- const [{ query }] = useQueryParams();
2445
- const params = React.useMemo(() => buildValidParams(query), [query]);
2446
- const { toggleNotification } = useNotification();
2447
- const [shouldKeepDraft, setShouldKeepDraft] = React.useState(true);
2448
- const isDocumentModified = document?.status === "modified";
2449
- const handleChange = (value) => {
2450
- setShouldKeepDraft(value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
2451
- };
2452
- if (!schema?.options?.draftAndPublish) {
2453
- return null;
2454
- }
2455
- return {
2456
- disabled: !canPublish || activeTab === "published" || document?.status !== "published" && document?.status !== "modified",
2457
- label: formatMessage({
2458
- id: "app.utils.unpublish",
2459
- defaultMessage: "Unpublish"
2460
- }),
2461
- icon: /* @__PURE__ */ jsx(Cross, {}),
2462
- onClick: async () => {
2463
- if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
2464
- if (!documentId) {
2465
- console.error(
2466
- "You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
2467
- );
2468
- toggleNotification({
2469
- message: formatMessage({
2470
- id: "content-manager.actions.unpublish.error",
2471
- defaultMessage: "An error occurred while trying to unpublish the document."
2472
- }),
2473
- type: "danger"
2474
- });
2475
- }
2476
- return;
2477
- }
2478
- await unpublish({
2479
- collectionType,
2480
- model,
2481
- documentId,
2482
- params
2483
- });
2484
- },
2485
- dialog: isDocumentModified ? {
2486
- type: "dialog",
2487
- title: formatMessage({
2488
- id: "app.components.ConfirmDialog.title",
2489
- defaultMessage: "Confirmation"
2490
- }),
2491
- content: /* @__PURE__ */ jsxs(Flex, { alignItems: "flex-start", direction: "column", gap: 6, children: [
2492
- /* @__PURE__ */ jsxs(Flex, { width: "100%", direction: "column", gap: 2, children: [
2493
- /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
2494
- /* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
2495
- id: "content-manager.actions.unpublish.dialog.body",
2496
- defaultMessage: "Are you sure?"
2497
- }) })
2498
- ] }),
2499
- /* @__PURE__ */ jsxs(
2500
- Radio.Group,
2501
- {
2502
- defaultValue: UNPUBLISH_DRAFT_OPTIONS.KEEP,
2503
- name: "discard-options",
2504
- "aria-label": formatMessage({
2505
- id: "content-manager.actions.unpublish.dialog.radio-label",
2506
- defaultMessage: "Choose an option to unpublish the document."
2507
- }),
2508
- onValueChange: handleChange,
2509
- children: [
2510
- /* @__PURE__ */ jsx(Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
2511
- id: "content-manager.actions.unpublish.dialog.option.keep-draft",
2512
- defaultMessage: "Keep draft"
2513
- }) }),
2514
- /* @__PURE__ */ jsx(Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
2515
- id: "content-manager.actions.unpublish.dialog.option.replace-draft",
2516
- defaultMessage: "Replace draft"
2517
- }) })
2518
- ]
2519
- }
2520
- )
2521
- ] }),
2522
- onConfirm: async () => {
2523
- if (!documentId && collectionType !== SINGLE_TYPES) {
2524
- console.error(
2525
- "You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
2526
- );
2527
- toggleNotification({
2528
- message: formatMessage({
2529
- id: "content-manager.actions.unpublish.error",
2530
- defaultMessage: "An error occurred while trying to unpublish the document."
2531
- }),
2532
- type: "danger"
2533
- });
2534
- }
2535
- await unpublish(
2536
- {
2537
- collectionType,
2538
- model,
2539
- documentId,
2540
- params
2541
- },
2542
- !shouldKeepDraft
2543
- );
2544
- }
2545
- } : void 0,
2546
- variant: "danger",
2547
- position: ["panel", "table-row"]
2548
- };
2549
- };
2550
- UnpublishAction$1.type = "unpublish";
2551
- UnpublishAction$1.position = "panel";
2552
- const DiscardAction = ({
2553
- activeTab,
2554
- documentId,
2555
- model,
2556
- collectionType,
2557
- document
2558
- }) => {
2559
- const { formatMessage } = useIntl();
2560
- const { schema } = useDoc();
2561
- const canUpdate = useDocumentRBAC("DiscardAction", ({ canUpdate: canUpdate2 }) => canUpdate2);
2562
- const { discard } = useDocumentActions();
2563
- const [{ query }] = useQueryParams();
2564
- const params = React.useMemo(() => buildValidParams(query), [query]);
2565
- if (!schema?.options?.draftAndPublish) {
2566
- return null;
2567
- }
2568
- return {
2569
- disabled: !canUpdate || activeTab === "published" || document?.status !== "modified",
2570
- label: formatMessage({
2571
- id: "content-manager.actions.discard.label",
2572
- defaultMessage: "Discard changes"
2573
- }),
2574
- icon: /* @__PURE__ */ jsx(Cross, {}),
2575
- position: ["panel", "table-row"],
2576
- variant: "danger",
2577
- dialog: {
2578
- type: "dialog",
2579
- title: formatMessage({
2580
- id: "app.components.ConfirmDialog.title",
2581
- defaultMessage: "Confirmation"
2582
- }),
2583
- content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
2584
- /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
2585
- /* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
2586
- id: "content-manager.actions.discard.dialog.body",
2587
- defaultMessage: "Are you sure?"
2588
- }) })
2589
- ] }),
2590
- onConfirm: async () => {
2591
- await discard({
2592
- collectionType,
2593
- model,
2594
- documentId,
2595
- params
2596
- });
2597
- }
2598
- }
2599
- };
2600
- };
2601
- DiscardAction.type = "discard";
2602
- DiscardAction.position = "panel";
2603
- const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
2604
- const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
2605
- const RelativeTime = React.forwardRef(
2606
- ({ timestamp, customIntervals = [], ...restProps }, forwardedRef) => {
2607
- const { formatRelativeTime, formatDate, formatTime } = useIntl();
2608
- const interval = intervalToDuration({
2609
- start: timestamp,
2610
- end: Date.now()
2611
- // see https://github.com/date-fns/date-fns/issues/2891 – No idea why it's all partial it returns it every time.
2612
- });
2613
- const unit = intervals.find((intervalUnit) => {
2614
- return interval[intervalUnit] > 0 && Object.keys(interval).includes(intervalUnit);
2615
- }) ?? "seconds";
2616
- const relativeTime = isPast(timestamp) ? -interval[unit] : interval[unit];
2617
- const customInterval = customIntervals.find(
2618
- (custom) => interval[custom.unit] < custom.threshold
2619
- );
2620
- const displayText = customInterval ? customInterval.text : formatRelativeTime(relativeTime, unit, { numeric: "auto" });
2621
- return /* @__PURE__ */ jsx(
2622
- "time",
2623
- {
2624
- ref: forwardedRef,
2625
- dateTime: timestamp.toISOString(),
2626
- role: "time",
2627
- title: `${formatDate(timestamp)} ${formatTime(timestamp)}`,
2628
- ...restProps,
2629
- children: displayText
2630
- }
2631
- );
2632
- }
2633
- );
2634
- const getDisplayName = ({
2635
- firstname,
2636
- lastname,
2637
- username,
2638
- email
2639
- } = {}) => {
2640
- if (username) {
2641
- return username;
2642
- }
2643
- if (firstname) {
2644
- return `${firstname} ${lastname ?? ""}`.trim();
2645
- }
2646
- return email ?? "";
2647
- };
2648
- const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
2649
- const DocumentStatus = ({ status = "draft", size = "S", ...restProps }) => {
2650
- const statusVariant = status === "draft" ? "secondary" : status === "published" ? "success" : "alternative";
2651
- const { formatMessage } = useIntl();
2652
- return /* @__PURE__ */ jsx(Status, { ...restProps, size, variant: statusVariant, children: /* @__PURE__ */ jsx(Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: formatMessage({
2653
- id: `content-manager.containers.List.${status}`,
2654
- defaultMessage: capitalise(status)
2655
- }) }) });
2656
- };
2657
- const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
2658
- const { formatMessage } = useIntl();
2659
- const isCloning = useMatch(CLONE_PATH) !== null;
2660
- const params = useParams();
2661
- const title = isCreating ? formatMessage({
2662
- id: "content-manager.containers.edit.title.new",
2663
- defaultMessage: "Create an entry"
2664
- }) : documentTitle;
2665
- return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
2666
- /* @__PURE__ */ jsx(
2667
- BackButton,
2668
- {
2669
- fallback: params.collectionType === SINGLE_TYPES ? void 0 : `../${COLLECTION_TYPES}/${params.slug}`
2670
- }
2671
- ),
2672
- /* @__PURE__ */ jsxs(Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
2673
- /* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
2674
- /* @__PURE__ */ jsx(HeaderToolbar, {})
2675
- ] }),
2676
- status ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
2677
- ] });
2678
- };
2679
- const HeaderToolbar = () => {
2680
- const { formatMessage } = useIntl();
2681
- const isCloning = useMatch(CLONE_PATH) !== null;
2682
- const [
2683
- {
2684
- query: { status = "draft" }
2685
- }
2686
- ] = useQueryParams();
2687
- const { model, id, document, meta, collectionType } = useDoc();
2688
- const plugins = useStrapiApp("HeaderToolbar", (state) => state.plugins);
2689
- return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
2690
- /* @__PURE__ */ jsx(
2691
- DescriptionComponentRenderer,
2692
- {
2693
- props: {
2694
- activeTab: status,
2695
- model,
2696
- documentId: id,
2697
- document: isCloning ? void 0 : document,
2698
- meta: isCloning ? void 0 : meta,
2699
- collectionType
2700
- },
2701
- descriptions: plugins["content-manager"].apis.getHeaderActions(),
2702
- children: (actions2) => {
2703
- if (actions2.length > 0) {
2704
- return /* @__PURE__ */ jsx(HeaderActions, { actions: actions2 });
2705
- } else {
2706
- return null;
2707
- }
2708
- }
2709
- }
2710
- ),
2711
- /* @__PURE__ */ jsx(
2712
- DescriptionComponentRenderer,
2713
- {
2714
- props: {
2715
- activeTab: status,
2716
- model,
2717
- documentId: id,
2718
- document: isCloning ? void 0 : document,
2719
- meta: isCloning ? void 0 : meta,
2720
- collectionType
2721
- },
2722
- descriptions: plugins["content-manager"].apis.getDocumentActions("header"),
2723
- children: (actions2) => {
2724
- const headerActions = actions2.filter((action) => {
2725
- const positions = Array.isArray(action.position) ? action.position : [action.position];
2726
- return positions.includes("header");
2727
- });
2728
- return /* @__PURE__ */ jsx(
2729
- DocumentActionsMenu,
2730
- {
2731
- actions: headerActions,
2732
- label: formatMessage({
2733
- id: "content-manager.containers.edit.header.more-actions",
2734
- defaultMessage: "More actions"
2735
- }),
2736
- children: /* @__PURE__ */ jsx(Information, { activeTab: status })
2737
- }
2738
- );
2739
- }
2740
- }
2741
- )
2742
- ] });
2743
- };
2744
- const Information = ({ activeTab }) => {
2745
- const { formatMessage } = useIntl();
2746
- const { document, meta } = useDoc();
2747
- if (!document || !document.id) {
2748
- return null;
2749
- }
2750
- const createAndUpdateDocument = activeTab === "draft" ? document : meta?.availableStatus.find((status) => status.publishedAt === null);
2751
- const publishDocument = activeTab === "published" ? document : meta?.availableStatus.find((status) => status.publishedAt !== null);
2752
- const creator = createAndUpdateDocument?.[CREATED_BY_ATTRIBUTE_NAME] ? getDisplayName(createAndUpdateDocument[CREATED_BY_ATTRIBUTE_NAME]) : null;
2753
- const updator = createAndUpdateDocument?.[UPDATED_BY_ATTRIBUTE_NAME] ? getDisplayName(createAndUpdateDocument[UPDATED_BY_ATTRIBUTE_NAME]) : null;
2754
- const information = [
2755
- {
2756
- isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
2757
- label: formatMessage({
2758
- id: "content-manager.containers.edit.information.last-published.label",
2759
- defaultMessage: "Published"
2760
- }),
2761
- value: formatMessage(
2762
- {
2763
- id: "content-manager.containers.edit.information.last-published.value",
2764
- defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2765
- },
2766
- {
2767
- time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
2768
- isAnonymous: !publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME],
2769
- author: publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME] ? getDisplayName(publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME]) : null
2770
- }
2771
- )
2772
- },
2773
- {
2774
- isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
2775
- label: formatMessage({
2776
- id: "content-manager.containers.edit.information.last-draft.label",
2777
- defaultMessage: "Updated"
2778
- }),
2779
- value: formatMessage(
2780
- {
2781
- id: "content-manager.containers.edit.information.last-draft.value",
2782
- defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2783
- },
2784
- {
2785
- time: /* @__PURE__ */ jsx(
2786
- RelativeTime,
2787
- {
2788
- timestamp: new Date(createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME])
2789
- }
2790
- ),
2791
- isAnonymous: !updator,
2792
- author: updator
2793
- }
2794
- )
2795
- },
2796
- {
2797
- isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
2798
- label: formatMessage({
2799
- id: "content-manager.containers.edit.information.document.label",
2800
- defaultMessage: "Created"
2801
- }),
2802
- value: formatMessage(
2803
- {
2804
- id: "content-manager.containers.edit.information.document.value",
2805
- defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2806
- },
2807
- {
2808
- time: /* @__PURE__ */ jsx(
2809
- RelativeTime,
2810
- {
2811
- timestamp: new Date(createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME])
2812
- }
2813
- ),
2814
- isAnonymous: !creator,
2815
- author: creator
2816
- }
2817
- )
2818
- }
2819
- ].filter((info) => info.isDisplayed);
2820
- return /* @__PURE__ */ jsx(
2821
- Flex,
2822
- {
2823
- borderWidth: "1px 0 0 0",
2824
- borderStyle: "solid",
2825
- borderColor: "neutral150",
2826
- direction: "column",
2827
- marginTop: 2,
2828
- tag: "dl",
2829
- padding: 5,
2830
- gap: 3,
2831
- alignItems: "flex-start",
2832
- marginLeft: "-0.4rem",
2833
- marginRight: "-0.4rem",
2834
- width: "calc(100% + 8px)",
2835
- children: information.map((info) => /* @__PURE__ */ jsxs(Flex, { gap: 1, direction: "column", alignItems: "flex-start", children: [
2836
- /* @__PURE__ */ jsx(Typography, { tag: "dt", variant: "pi", fontWeight: "bold", children: info.label }),
2837
- /* @__PURE__ */ jsx(Typography, { tag: "dd", variant: "pi", textColor: "neutral600", children: info.value })
2838
- ] }, info.label))
2839
- }
2840
- );
2841
- };
2842
- const HeaderActions = ({ actions: actions2 }) => {
2843
- const [dialogId, setDialogId] = React.useState(null);
2844
- const handleClick = (action) => async (e) => {
2845
- if (!("options" in action)) {
2846
- const { onClick = () => false, dialog, id } = action;
2847
- const muteDialog = await onClick(e);
2848
- if (dialog && !muteDialog) {
2849
- e.preventDefault();
2850
- setDialogId(id);
2851
- }
2852
- }
2853
- };
2854
- const handleClose = () => {
2855
- setDialogId(null);
2856
- };
2857
- return /* @__PURE__ */ jsx(Flex, { gap: 1, children: actions2.map((action) => {
2858
- if (action.options) {
2859
- return /* @__PURE__ */ jsx(
2860
- SingleSelect,
2861
- {
2862
- size: "S",
2863
- onChange: action.onSelect,
2864
- "aria-label": action.label,
2865
- ...action,
2866
- children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
2867
- },
2868
- action.id
2869
- );
2870
- } else {
2871
- if (action.type === "icon") {
2872
- return /* @__PURE__ */ jsxs(React.Fragment, { children: [
2873
- /* @__PURE__ */ jsx(
2874
- IconButton,
2875
- {
2876
- disabled: action.disabled,
2877
- label: action.label,
2878
- size: "S",
2879
- onClick: handleClick(action),
2880
- children: action.icon
2881
- }
2882
- ),
2883
- action.dialog ? /* @__PURE__ */ jsx(
2884
- HeaderActionDialog,
2885
- {
2886
- ...action.dialog,
2887
- isOpen: dialogId === action.id,
2888
- onClose: handleClose
2889
- }
2890
- ) : null
2891
- ] }, action.id);
2892
- }
2893
- }
2894
- }) });
2895
- };
2896
- const HeaderActionDialog = ({
2897
- onClose,
2898
- onCancel,
2899
- title,
2900
- content: Content,
2901
- isOpen
2902
- }) => {
2903
- const handleClose = async () => {
2904
- if (onCancel) {
2905
- await onCancel();
2906
- }
2907
- onClose();
2908
- };
2909
- return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
2910
- /* @__PURE__ */ jsx(Dialog.Header, { children: title }),
2911
- typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : Content
2912
- ] }) });
2913
- };
2914
- const ConfigureTheViewAction = ({ collectionType, model }) => {
2915
- const navigate = useNavigate();
2916
- const { formatMessage } = useIntl();
2917
- return {
2918
- label: formatMessage({
2919
- id: "app.links.configure-view",
2920
- defaultMessage: "Configure the view"
2921
- }),
2922
- icon: /* @__PURE__ */ jsx(ListPlus, {}),
2923
- onClick: () => {
2924
- navigate(`../${collectionType}/${model}/configurations/edit`);
2925
- },
2926
- position: "header"
2927
- };
2928
- };
2929
- ConfigureTheViewAction.type = "configure-the-view";
2930
- ConfigureTheViewAction.position = "header";
2931
- const EditTheModelAction = ({ model }) => {
2932
- const navigate = useNavigate();
2933
- const { formatMessage } = useIntl();
2934
- return {
2935
- label: formatMessage({
2936
- id: "content-manager.link-to-ctb",
2937
- defaultMessage: "Edit the model"
2938
- }),
2939
- icon: /* @__PURE__ */ jsx(Pencil, {}),
2940
- onClick: () => {
2941
- navigate(`/plugins/content-type-builder/content-types/${model}`);
2942
- },
2943
- position: "header"
2944
- };
2945
- };
2946
- EditTheModelAction.type = "edit-the-model";
2947
- EditTheModelAction.position = "header";
2948
- const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
2949
- const navigate = useNavigate();
2950
- const { formatMessage } = useIntl();
2951
- const listViewPathMatch = useMatch(LIST_PATH);
2952
- const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
2953
- const { delete: deleteAction } = useDocumentActions();
2954
- const { toggleNotification } = useNotification();
2955
- const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
2956
- const isLocalized = document?.locale != null;
2957
- return {
2958
- disabled: !canDelete || !document,
2959
- label: formatMessage(
2960
- {
2961
- id: "content-manager.actions.delete.label",
2962
- defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
2963
- },
2964
- { isLocalized }
2965
- ),
2966
- icon: /* @__PURE__ */ jsx(Trash, {}),
2967
- dialog: {
2968
- type: "dialog",
2969
- title: formatMessage({
2970
- id: "app.components.ConfirmDialog.title",
2971
- defaultMessage: "Confirmation"
2972
- }),
2973
- content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
2974
- /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
2975
- /* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
2976
- id: "content-manager.actions.delete.dialog.body",
2977
- defaultMessage: "Are you sure?"
2978
- }) })
2979
- ] }),
2980
- onConfirm: async () => {
2981
- if (!listViewPathMatch) {
2982
- setSubmitting(true);
2983
- }
2984
- try {
2985
- if (!documentId && collectionType !== SINGLE_TYPES) {
2986
- console.error(
2987
- "You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
2988
- );
2989
- toggleNotification({
2990
- message: formatMessage({
2991
- id: "content-manager.actions.delete.error",
2992
- defaultMessage: "An error occurred while trying to delete the document."
2993
- }),
2994
- type: "danger"
2995
- });
2996
- return;
2997
- }
2998
- const res = await deleteAction({
2999
- documentId,
3000
- model,
3001
- collectionType,
3002
- params: {
3003
- locale: "*"
3004
- }
3005
- });
3006
- if (!("error" in res)) {
3007
- navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
3008
- }
3009
- } finally {
3010
- if (!listViewPathMatch) {
3011
- setSubmitting(false);
3012
- }
3013
- }
3014
- }
3015
- },
3016
- variant: "danger",
3017
- position: ["header", "table-row"]
3018
- };
3019
- };
3020
- DeleteAction$1.type = "delete";
3021
- DeleteAction$1.position = ["header", "table-row"];
3022
- const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
3023
- const Panels = () => {
3024
- const isCloning = useMatch(CLONE_PATH) !== null;
3025
- const [
3026
- {
3027
- query: { status }
3028
- }
3029
- ] = useQueryParams({
3030
- status: "draft"
3031
- });
3032
- const { model, id, document, meta, collectionType } = useDoc();
3033
- const plugins = useStrapiApp("Panels", (state) => state.plugins);
3034
- const props = {
3035
- activeTab: status,
3036
- model,
3037
- documentId: id,
3038
- document: isCloning ? void 0 : document,
3039
- meta: isCloning ? void 0 : meta,
3040
- collectionType
3041
- };
3042
- return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
3043
- DescriptionComponentRenderer,
3044
- {
3045
- props,
3046
- descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
3047
- children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
3048
- }
3049
- ) });
3050
- };
3051
- const ActionsPanel = () => {
3052
- const { formatMessage } = useIntl();
3053
- return {
3054
- title: formatMessage({
3055
- id: "content-manager.containers.edit.panels.default.title",
3056
- defaultMessage: "Entry"
3057
- }),
3058
- content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
3059
- };
3060
- };
3061
- ActionsPanel.type = "actions";
3062
- const ActionsPanelContent = () => {
3063
- const isCloning = useMatch(CLONE_PATH) !== null;
3064
- const [
3065
- {
3066
- query: { status = "draft" }
3067
- }
3068
- ] = useQueryParams();
3069
- const { model, id, document, meta, collectionType } = useDoc();
3070
- const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
3071
- const props = {
3072
- activeTab: status,
3073
- model,
3074
- documentId: id,
3075
- document: isCloning ? void 0 : document,
3076
- meta: isCloning ? void 0 : meta,
3077
- collectionType
3078
- };
3079
- return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
3080
- /* @__PURE__ */ jsx(
3081
- DescriptionComponentRenderer,
3082
- {
3083
- props,
3084
- descriptions: plugins["content-manager"].apis.getDocumentActions("panel"),
3085
- children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
3086
- }
3087
- ),
3088
- /* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
3089
- ] });
3090
- };
3091
- const Panel = React.forwardRef(({ children, title }, ref) => {
3092
- return /* @__PURE__ */ jsxs(
3093
- Flex,
3094
- {
3095
- ref,
3096
- tag: "aside",
3097
- "aria-labelledby": "additional-information",
3098
- background: "neutral0",
3099
- borderColor: "neutral150",
3100
- hasRadius: true,
3101
- paddingBottom: 4,
3102
- paddingLeft: 4,
3103
- paddingRight: 4,
3104
- paddingTop: 4,
3105
- shadow: "tableShadow",
3106
- gap: 3,
3107
- direction: "column",
3108
- justifyContent: "stretch",
3109
- alignItems: "flex-start",
3110
- children: [
3111
- /* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", textColor: "neutral600", children: title }),
3112
- children
3113
- ]
3114
- }
3115
- );
3116
- });
3117
- const ConfirmBulkActionDialog = ({
3118
- onToggleDialog,
3119
- isOpen = false,
3120
- dialogBody,
3121
- endAction
3122
- }) => {
3123
- const { formatMessage } = useIntl();
3124
- return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
3125
- /* @__PURE__ */ jsx(Dialog.Header, { children: formatMessage({
3126
- id: "app.components.ConfirmDialog.title",
3127
- defaultMessage: "Confirmation"
3128
- }) }),
3129
- /* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
3130
- /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
3131
- dialogBody
3132
- ] }) }),
3133
- /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
3134
- /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { fullWidth: true, onClick: onToggleDialog, variant: "tertiary", children: formatMessage({
3135
- id: "app.components.Button.cancel",
3136
- defaultMessage: "Cancel"
3137
- }) }) }),
3138
- endAction
3139
- ] })
3140
- ] }) });
3141
- };
3142
- const BoldChunk$1 = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: chunks });
3143
- const ConfirmDialogPublishAll = ({
3144
- isOpen,
3145
- onToggleDialog,
3146
- isConfirmButtonLoading = false,
3147
- onConfirm
3148
- }) => {
3149
- const { formatMessage } = useIntl();
3150
- const selectedEntries = useTable("ConfirmDialogPublishAll", (state) => state.selectedRows);
3151
- const { toggleNotification } = useNotification();
3152
- const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler(getTranslation);
3153
- const { model, schema } = useDoc();
3154
- const [{ query }] = useQueryParams();
3155
- const enableDraftRelationsCount = false;
3156
- const {
3157
- data: countDraftRelations = 0,
3158
- isLoading,
3159
- error
3160
- } = useGetManyDraftRelationCountQuery(
3161
- {
3162
- model,
3163
- documentIds: selectedEntries.map((entry) => entry.documentId),
3164
- locale: query?.plugins?.i18n?.locale
3165
- },
3166
- {
3167
- skip: !enableDraftRelationsCount
3168
- }
3169
- );
3170
- React.useEffect(() => {
3171
- if (error) {
3172
- toggleNotification({ type: "danger", message: formatAPIError(error) });
3173
- }
3174
- }, [error, formatAPIError, toggleNotification]);
3175
- if (error) {
3176
- return null;
3177
- }
3178
- return /* @__PURE__ */ jsx(
3179
- ConfirmBulkActionDialog,
3180
- {
3181
- isOpen: isOpen && !isLoading,
3182
- onToggleDialog,
3183
- dialogBody: /* @__PURE__ */ jsxs(Fragment, { children: [
3184
- /* @__PURE__ */ jsxs(Typography, { id: "confirm-description", textAlign: "center", children: [
3185
- countDraftRelations > 0 && formatMessage(
3186
- {
3187
- id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
3188
- defaultMessage: "<b>{count} {count, plural, one { relation } other { relations } } out of {entities} { entities, plural, one { entry } other { entries } } {count, plural, one { is } other { are } }</b> not published yet and might lead to unexpected behavior. "
3189
- },
3190
- {
3191
- b: BoldChunk$1,
3192
- count: countDraftRelations,
3193
- entities: selectedEntries.length
3194
- }
3195
- ),
3196
- formatMessage({
3197
- id: getTranslation("popUpWarning.bodyMessage.contentType.publish.all"),
3198
- defaultMessage: "Are you sure you want to publish these entries?"
3199
- })
3200
- ] }),
3201
- schema?.pluginOptions && "i18n" in schema.pluginOptions && schema?.pluginOptions.i18n && /* @__PURE__ */ jsx(Typography, { textColor: "danger500", textAlign: "center", children: formatMessage(
3202
- {
3203
- id: getTranslation("Settings.list.actions.publishAdditionalInfos"),
3204
- defaultMessage: "This will publish the active locale versions <em>(from Internationalization)</em>"
3205
- },
3206
- {
3207
- em: Emphasis
3208
- }
3209
- ) })
3210
- ] }),
3211
- endAction: /* @__PURE__ */ jsx(
3212
- Button,
3213
- {
3214
- onClick: onConfirm,
3215
- variant: "secondary",
3216
- startIcon: /* @__PURE__ */ jsx(Check, {}),
3217
- loading: isConfirmButtonLoading,
3218
- children: formatMessage({
3219
- id: "app.utils.publish",
3220
- defaultMessage: "Publish"
3221
- })
3222
- }
3223
- )
3224
- }
3225
- );
3226
- };
3227
- const TypographyMaxWidth = styled(Typography)`
3228
- max-width: 300px;
3229
- `;
3230
- const formatErrorMessages = (errors, parentKey, formatMessage) => {
3231
- const messages = [];
3232
- Object.entries(errors).forEach(([key, value]) => {
3233
- const currentKey = parentKey ? `${parentKey}.${key}` : key;
3234
- if (typeof value === "object" && value !== null && !Array.isArray(value)) {
3235
- if ("id" in value && "defaultMessage" in value) {
3236
- messages.push(
3237
- formatMessage(
3238
- {
3239
- id: `${value.id}.withField`,
3240
- defaultMessage: value.defaultMessage
3241
- },
3242
- { field: currentKey }
3243
- )
3244
- );
3245
- } else {
3246
- messages.push(
3247
- ...formatErrorMessages(
3248
- // @ts-expect-error TODO: check why value is not compatible with FormErrors
3249
- value,
3250
- currentKey,
3251
- formatMessage
3252
- )
3253
- );
3254
- }
3255
- } else {
3256
- messages.push(
3257
- formatMessage(
3258
- {
3259
- id: `${value}.withField`,
3260
- defaultMessage: value
3261
- },
3262
- { field: currentKey }
3263
- )
3264
- );
3265
- }
3266
- });
3267
- return messages;
3268
- };
3269
- const EntryValidationText = ({ validationErrors, status }) => {
3270
- const { formatMessage } = useIntl();
3271
- if (validationErrors) {
3272
- const validationErrorsMessages = formatErrorMessages(validationErrors, "", formatMessage).join(
3273
- " "
3274
- );
3275
- return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3276
- /* @__PURE__ */ jsx(CrossCircle, { fill: "danger600" }),
3277
- /* @__PURE__ */ jsx(Tooltip, { description: validationErrorsMessages, children: /* @__PURE__ */ jsx(TypographyMaxWidth, { textColor: "danger600", variant: "omega", fontWeight: "semiBold", ellipsis: true, children: validationErrorsMessages }) })
3278
- ] });
3279
- }
3280
- if (status === "published") {
3281
- return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3282
- /* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
3283
- /* @__PURE__ */ jsx(Typography, { textColor: "success600", fontWeight: "bold", children: formatMessage({
3284
- id: "content-manager.bulk-publish.already-published",
3285
- defaultMessage: "Already Published"
3286
- }) })
3287
- ] });
3288
- }
3289
- if (status === "modified") {
3290
- return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3291
- /* @__PURE__ */ jsx(ArrowsCounterClockwise, { fill: "alternative600" }),
3292
- /* @__PURE__ */ jsx(Typography, { children: formatMessage({
3293
- id: "content-manager.bulk-publish.modified",
3294
- defaultMessage: "Ready to publish changes"
3295
- }) })
3296
- ] });
3297
- }
3298
- return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3299
- /* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
3300
- /* @__PURE__ */ jsx(Typography, { children: formatMessage({
3301
- id: "app.utils.ready-to-publish",
3302
- defaultMessage: "Ready to publish"
3303
- }) })
3304
- ] });
3305
- };
3306
- const TABLE_HEADERS = [
3307
- { name: "id", label: "id" },
3308
- { name: "name", label: "name" },
3309
- { name: "status", label: "status" },
3310
- { name: "publicationStatus", label: "Publication status" }
3311
- ];
3312
- const SelectedEntriesTableContent = ({
3313
- isPublishing,
3314
- rowsToDisplay = [],
3315
- entriesToPublish = [],
3316
- validationErrors = {}
3317
- }) => {
3318
- const { pathname } = useLocation();
3319
- const { formatMessage } = useIntl();
3320
- const {
3321
- list: {
3322
- settings: { mainField }
3323
- }
3324
- } = useDocLayout();
3325
- const shouldDisplayMainField = mainField != null && mainField !== "id";
3326
- return /* @__PURE__ */ jsxs(Table.Content, { children: [
3327
- /* @__PURE__ */ jsxs(Table.Head, { children: [
3328
- /* @__PURE__ */ jsx(Table.HeaderCheckboxCell, {}),
3329
- TABLE_HEADERS.filter((head) => head.name !== "name" || shouldDisplayMainField).map(
3330
- (head) => /* @__PURE__ */ jsx(Table.HeaderCell, { ...head }, head.name)
3331
- )
3332
- ] }),
3333
- /* @__PURE__ */ jsx(Table.Loading, {}),
3334
- /* @__PURE__ */ jsx(Table.Body, { children: rowsToDisplay.map((row, index2) => /* @__PURE__ */ jsxs(Table.Row, { children: [
3335
- /* @__PURE__ */ jsx(Table.CheckboxCell, { id: row.id }),
3336
- /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Typography, { children: row.id }) }),
3337
- shouldDisplayMainField && /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Typography, { children: row[mainField] }) }),
3338
- /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(DocumentStatus, { status: row.status, maxWidth: "min-content" }) }),
3339
- /* @__PURE__ */ jsx(Table.Cell, { children: isPublishing && entriesToPublish.includes(row.documentId) ? /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3340
- /* @__PURE__ */ jsx(Typography, { children: formatMessage({
3341
- id: "content-manager.success.record.publishing",
3342
- defaultMessage: "Publishing..."
3343
- }) }),
3344
- /* @__PURE__ */ jsx(Loader, { small: true })
3345
- ] }) : /* @__PURE__ */ jsx(
3346
- EntryValidationText,
3347
- {
3348
- validationErrors: validationErrors[row.documentId],
3349
- status: row.status
3350
- }
3351
- ) }),
3352
- /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
3353
- IconButton,
3354
- {
3355
- tag: Link,
3356
- to: {
3357
- pathname: `${pathname}/${row.documentId}`,
3358
- search: row.locale && `?plugins[i18n][locale]=${row.locale}`
3359
- },
3360
- state: { from: pathname },
3361
- label: formatMessage({
3362
- id: "content-manager.bulk-publish.edit",
3363
- defaultMessage: "Edit"
3364
- }),
3365
- target: "_blank",
3366
- marginLeft: "auto",
3367
- variant: "ghost",
3368
- children: /* @__PURE__ */ jsx(Pencil, { width: "1.6rem", height: "1.6rem" })
3369
- }
3370
- ) }) })
3371
- ] }, row.id)) })
3372
- ] });
3373
- };
3374
- const BoldChunk = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: chunks });
3375
- const SelectedEntriesModalContent = ({
3376
- listViewSelectedEntries,
3377
- toggleModal,
3378
- setListViewSelectedDocuments,
3379
- model
3380
- }) => {
3381
- const { formatMessage } = useIntl();
3382
- const { schema, components } = useContentTypeSchema(model);
3383
- const documentIds = listViewSelectedEntries.map(({ documentId }) => documentId);
3384
- const [{ query }] = useQueryParams();
3385
- const params = React.useMemo(() => buildValidParams(query), [query]);
3386
- const { data, isLoading, isFetching, refetch } = useGetAllDocumentsQuery(
3387
- {
3388
- model,
3389
- params: {
3390
- page: "1",
3391
- pageSize: documentIds.length.toString(),
3392
- sort: query.sort,
3393
- filters: {
3394
- documentId: {
3395
- $in: documentIds
3396
- }
3397
- },
3398
- locale: query.plugins?.i18n?.locale
3399
- }
3400
- },
3401
- {
3402
- selectFromResult: ({ data: data2, ...restRes }) => ({ data: data2?.results ?? [], ...restRes })
3403
- }
3404
- );
3405
- const { rows, validationErrors } = React.useMemo(() => {
3406
- if (data.length > 0 && schema) {
3407
- const validate = createYupSchema(
3408
- schema.attributes,
3409
- components,
3410
- // Since this is the "Publish" action, the validation
3411
- // schema must enforce the rules for published entities
3412
- { status: "published" }
3413
- );
3414
- const validationErrors2 = {};
3415
- const rows2 = data.map((entry) => {
3416
- try {
3417
- validate.validateSync(entry, { abortEarly: false });
3418
- return entry;
3419
- } catch (e) {
3420
- if (e instanceof ValidationError) {
3421
- validationErrors2[entry.documentId] = getYupValidationErrors(e);
3422
- }
3423
- return entry;
3424
- }
3425
- });
3426
- return { rows: rows2, validationErrors: validationErrors2 };
3427
- }
3428
- return {
3429
- rows: [],
3430
- validationErrors: {}
3431
- };
3432
- }, [components, data, schema]);
3433
- const [publishedCount, setPublishedCount] = React.useState(0);
3434
- const [isDialogOpen, setIsDialogOpen] = React.useState(false);
3435
- const { publishMany: bulkPublishAction } = useDocumentActions();
3436
- const [, { isLoading: isSubmittingForm }] = usePublishManyDocumentsMutation();
3437
- const selectedRows = useTable("publishAction", (state) => state.selectedRows);
3438
- const selectedEntries = rows.filter(
3439
- (entry) => selectedRows.some((selectedEntry) => selectedEntry.documentId === entry.documentId)
3440
- );
3441
- const entriesToPublish = selectedEntries.filter((entry) => !validationErrors[entry.documentId]).map((entry) => entry.documentId);
3442
- const selectedEntriesWithErrorsCount = selectedEntries.filter(
3443
- ({ documentId }) => validationErrors[documentId]
3444
- ).length;
3445
- const selectedEntriesPublished = selectedEntries.filter(
3446
- ({ status }) => status === "published"
3447
- ).length;
3448
- const selectedEntriesWithNoErrorsCount = selectedEntries.length - selectedEntriesWithErrorsCount - selectedEntriesPublished;
3449
- const toggleDialog = () => setIsDialogOpen((prev) => !prev);
3450
- const handleConfirmBulkPublish = async () => {
3451
- toggleDialog();
3452
- const res = await bulkPublishAction({ model, documentIds: entriesToPublish, params });
3453
- if (!("error" in res)) {
3454
- setPublishedCount(res.count);
3455
- const unpublishedEntries = rows.filter((row) => {
3456
- return !entriesToPublish.includes(row.documentId);
3457
- });
3458
- setListViewSelectedDocuments(unpublishedEntries);
3459
- }
3460
- };
3461
- const getFormattedCountMessage = () => {
3462
- if (publishedCount) {
3463
- return formatMessage(
3464
- {
3465
- id: getTranslation("containers.list.selectedEntriesModal.publishedCount"),
3466
- defaultMessage: "<b>{publishedCount}</b> {publishedCount, plural, =0 {entries} one {entry} other {entries}} published. <b>{withErrorsCount}</b> {withErrorsCount, plural, =0 {entries} one {entry} other {entries}} waiting for action."
3467
- },
3468
- {
3469
- publishedCount,
3470
- withErrorsCount: selectedEntriesWithErrorsCount,
3471
- b: BoldChunk
3472
- }
3473
- );
3474
- }
3475
- return formatMessage(
3476
- {
3477
- id: getTranslation("containers.list.selectedEntriesModal.selectedCount"),
3478
- defaultMessage: "<b>{alreadyPublishedCount}</b> {alreadyPublishedCount, plural, =0 {entries} one {entry} other {entries}} already published. <b>{readyToPublishCount}</b> {readyToPublishCount, plural, =0 {entries} one {entry} other {entries}} ready to publish. <b>{withErrorsCount}</b> {withErrorsCount, plural, =0 {entries} one {entry} other {entries}} waiting for action."
3479
- },
3480
- {
3481
- readyToPublishCount: selectedEntriesWithNoErrorsCount,
3482
- withErrorsCount: selectedEntriesWithErrorsCount,
3483
- alreadyPublishedCount: selectedEntriesPublished,
3484
- b: BoldChunk
3485
- }
3486
- );
3487
- };
3488
- return /* @__PURE__ */ jsxs(Fragment, { children: [
3489
- /* @__PURE__ */ jsxs(Modal.Body, { children: [
3490
- /* @__PURE__ */ jsx(Typography, { children: getFormattedCountMessage() }),
3491
- /* @__PURE__ */ jsx(Box, { marginTop: 5, children: /* @__PURE__ */ jsx(
3492
- SelectedEntriesTableContent,
3493
- {
3494
- isPublishing: isSubmittingForm,
3495
- rowsToDisplay: rows,
3496
- entriesToPublish,
3497
- validationErrors
3498
- }
3499
- ) })
3500
- ] }),
3501
- /* @__PURE__ */ jsxs(Modal.Footer, { children: [
3502
- /* @__PURE__ */ jsx(Button, { onClick: toggleModal, variant: "tertiary", children: formatMessage({
3503
- id: "app.components.Button.cancel",
3504
- defaultMessage: "Cancel"
3505
- }) }),
3506
- /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3507
- /* @__PURE__ */ jsx(Button, { onClick: refetch, variant: "tertiary", loading: isFetching, children: formatMessage({ id: "app.utils.refresh", defaultMessage: "Refresh" }) }),
3508
- /* @__PURE__ */ jsx(
3509
- Button,
3510
- {
3511
- onClick: toggleDialog,
3512
- disabled: selectedEntries.length === 0 || selectedEntries.length === selectedEntriesWithErrorsCount || selectedEntriesPublished === selectedEntries.length || isLoading,
3513
- loading: isSubmittingForm,
3514
- children: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" })
3515
- }
3516
- )
3517
- ] })
3518
- ] }),
3519
- /* @__PURE__ */ jsx(
3520
- ConfirmDialogPublishAll,
3521
- {
3522
- isOpen: isDialogOpen,
3523
- onToggleDialog: toggleDialog,
3524
- isConfirmButtonLoading: isSubmittingForm,
3525
- onConfirm: handleConfirmBulkPublish
3526
- }
3527
- )
3528
- ] });
3529
- };
3530
- const PublishAction = ({ documents, model }) => {
3531
- const { formatMessage } = useIntl();
3532
- const hasPublishPermission = useDocumentRBAC("unpublishAction", (state) => state.canPublish);
3533
- const showPublishButton = hasPublishPermission && documents.some(({ status }) => status !== "published");
3534
- const setListViewSelectedDocuments = useTable("publishAction", (state) => state.selectRow);
3535
- const refetchList = () => {
3536
- contentManagerApi.util.invalidateTags([{ type: "Document", id: `${model}_LIST` }]);
3537
- };
3538
- if (!showPublishButton) return null;
3539
- return {
3540
- actionType: "publish",
3541
- variant: "tertiary",
3542
- label: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" }),
3543
- dialog: {
3544
- type: "modal",
3545
- title: formatMessage({
3546
- id: getTranslation("containers.ListPage.selectedEntriesModal.title"),
3547
- defaultMessage: "Publish entries"
3548
- }),
3549
- content: ({ onClose }) => {
3550
- return /* @__PURE__ */ jsx(Table.Root, { rows: documents, defaultSelectedRows: documents, headers: TABLE_HEADERS, children: /* @__PURE__ */ jsx(
3551
- SelectedEntriesModalContent,
3552
- {
3553
- listViewSelectedEntries: documents,
3554
- toggleModal: () => {
3555
- onClose();
3556
- refetchList();
3557
- },
3558
- setListViewSelectedDocuments,
3559
- model
3560
- }
3561
- ) });
3562
- },
3563
- onClose: () => {
3564
- refetchList();
3565
- }
3566
- }
3567
- };
3568
- };
3569
- const BulkActionsRenderer = () => {
3570
- const plugins = useStrapiApp("BulkActionsRenderer", (state) => state.plugins);
3571
- const { model, collectionType } = useDoc();
3572
- const { selectedRows } = useTable("BulkActionsRenderer", (state) => state);
3573
- return /* @__PURE__ */ jsx(Flex, { gap: 2, children: /* @__PURE__ */ jsx(
3574
- DescriptionComponentRenderer,
3575
- {
3576
- props: {
3577
- model,
3578
- collectionType,
3579
- documents: selectedRows
3580
- },
3581
- descriptions: plugins["content-manager"].apis.getBulkActions(),
3582
- children: (actions2) => actions2.map((action) => /* @__PURE__ */ jsx(DocumentActionButton, { ...action }, action.id))
3583
- }
3584
- ) });
3585
- };
3586
- const DeleteAction = ({ documents, model }) => {
3587
- const { formatMessage } = useIntl();
3588
- const { schema: contentType } = useDoc();
3589
- const selectRow = useTable("DeleteAction", (state) => state.selectRow);
3590
- const hasI18nEnabled = Boolean(contentType?.pluginOptions?.i18n);
3591
- const [{ query }] = useQueryParams();
3592
- const params = React.useMemo(() => buildValidParams(query), [query]);
3593
- const hasDeletePermission = useDocumentRBAC("deleteAction", (state) => state.canDelete);
3594
- const { deleteMany: bulkDeleteAction } = useDocumentActions();
3595
- const documentIds = documents.map(({ documentId }) => documentId);
3596
- const handleConfirmBulkDelete = async () => {
3597
- const res = await bulkDeleteAction({
3598
- documentIds,
3599
- model,
3600
- params
3601
- });
3602
- if (!("error" in res)) {
3603
- selectRow([]);
3604
- }
3605
- };
3606
- if (!hasDeletePermission) return null;
3607
- return {
3608
- variant: "danger-light",
3609
- label: formatMessage({ id: "global.delete", defaultMessage: "Delete" }),
3610
- dialog: {
3611
- type: "dialog",
3612
- title: formatMessage({
3613
- id: "app.components.ConfirmDialog.title",
3614
- defaultMessage: "Confirmation"
3615
- }),
3616
- content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
3617
- /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
3618
- /* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
3619
- id: "popUpWarning.bodyMessage.contentType.delete.all",
3620
- defaultMessage: "Are you sure you want to delete these entries?"
3621
- }) }),
3622
- hasI18nEnabled && /* @__PURE__ */ jsx(Box, { textAlign: "center", padding: 3, children: /* @__PURE__ */ jsx(Typography, { textColor: "danger500", children: formatMessage(
3623
- {
3624
- id: getTranslation("Settings.list.actions.deleteAdditionalInfos"),
3625
- defaultMessage: "This will delete the active locale versions <em>(from Internationalization)</em>"
3626
- },
3627
- {
3628
- em: Emphasis
3629
- }
3630
- ) }) })
3631
- ] }),
3632
- onConfirm: handleConfirmBulkDelete
3633
- }
3634
- };
3635
- };
3636
- DeleteAction.type = "delete";
3637
- const UnpublishAction = ({ documents, model }) => {
3638
- const { formatMessage } = useIntl();
3639
- const { schema } = useDoc();
3640
- const selectRow = useTable("UnpublishAction", (state) => state.selectRow);
3641
- const hasPublishPermission = useDocumentRBAC("unpublishAction", (state) => state.canPublish);
3642
- const hasI18nEnabled = Boolean(schema?.pluginOptions?.i18n);
3643
- const hasDraftAndPublishEnabled = Boolean(schema?.options?.draftAndPublish);
3644
- const { unpublishMany: bulkUnpublishAction } = useDocumentActions();
3645
- const documentIds = documents.map(({ documentId }) => documentId);
3646
- const [{ query }] = useQueryParams();
3647
- const params = React.useMemo(() => buildValidParams(query), [query]);
3648
- const handleConfirmBulkUnpublish = async () => {
3649
- const data = await bulkUnpublishAction({ documentIds, model, params });
3650
- if (!("error" in data)) {
3651
- selectRow([]);
3652
- }
3653
- };
3654
- const showUnpublishButton = hasDraftAndPublishEnabled && hasPublishPermission && documents.some((entry) => entry.status === "published" || entry.status === "modified");
3655
- if (!showUnpublishButton) return null;
3656
- return {
3657
- variant: "tertiary",
3658
- label: formatMessage({ id: "app.utils.unpublish", defaultMessage: "Unpublish" }),
3659
- dialog: {
3660
- type: "dialog",
3661
- title: formatMessage({
3662
- id: "app.components.ConfirmDialog.title",
3663
- defaultMessage: "Confirmation"
3664
- }),
3665
- content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
3666
- /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
3667
- /* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
3668
- id: "popUpWarning.bodyMessage.contentType.unpublish.all",
3669
- defaultMessage: "Are you sure you want to unpublish these entries?"
3670
- }) }),
3671
- hasI18nEnabled && /* @__PURE__ */ jsx(Box, { textAlign: "center", padding: 3, children: /* @__PURE__ */ jsx(Typography, { textColor: "danger500", children: formatMessage(
3672
- {
3673
- id: getTranslation("Settings.list.actions.unpublishAdditionalInfos"),
3674
- defaultMessage: "This will unpublish the active locale versions <em>(from Internationalization)</em>"
3675
- },
3676
- {
3677
- em: Emphasis
3678
- }
3679
- ) }) })
3680
- ] }),
3681
- confirmButton: formatMessage({
3682
- id: "app.utils.unpublish",
3683
- defaultMessage: "Unpublish"
3684
- }),
3685
- onConfirm: handleConfirmBulkUnpublish
3686
- }
3687
- };
3688
- };
3689
- UnpublishAction.type = "unpublish";
3690
- const Emphasis = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "semiBold", textColor: "danger500", children: chunks });
3691
- const DEFAULT_BULK_ACTIONS = [PublishAction, UnpublishAction, DeleteAction];
3692
- const AutoCloneFailureModalBody = ({ prohibitedFields }) => {
3693
- const { formatMessage } = useIntl();
3694
- const getDefaultErrorMessage = (reason) => {
3695
- switch (reason) {
3696
- case "relation":
3697
- return "Duplicating the relation could remove it from the original entry.";
3698
- case "unique":
3699
- return "Identical values in a unique field are not allowed";
3700
- default:
3701
- return reason;
3702
- }
3703
- };
3704
- return /* @__PURE__ */ jsxs(Fragment, { children: [
3705
- /* @__PURE__ */ jsx(Typography, { variant: "beta", children: formatMessage({
3706
- id: getTranslation("containers.list.autoCloneModal.title"),
3707
- defaultMessage: "This entry can't be duplicated directly."
3708
- }) }),
3709
- /* @__PURE__ */ jsx(Box, { marginTop: 2, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage({
3710
- id: getTranslation("containers.list.autoCloneModal.description"),
3711
- defaultMessage: "A new entry will be created with the same content, but you'll have to change the following fields to save it."
3712
- }) }) }),
3713
- /* @__PURE__ */ jsx(Flex, { marginTop: 6, gap: 2, direction: "column", alignItems: "stretch", children: prohibitedFields.map(([fieldPath, reason]) => /* @__PURE__ */ jsxs(
3714
- Flex,
3715
- {
3716
- direction: "column",
3717
- gap: 2,
3718
- alignItems: "flex-start",
3719
- borderColor: "neutral200",
3720
- hasRadius: true,
3721
- padding: 6,
3722
- children: [
3723
- /* @__PURE__ */ jsx(Flex, { direction: "row", tag: "ol", children: fieldPath.map((pathSegment, index2) => /* @__PURE__ */ jsxs(Typography, { fontWeight: "semiBold", tag: "li", children: [
3724
- pathSegment,
3725
- index2 !== fieldPath.length - 1 && /* @__PURE__ */ jsx(
3726
- ChevronRight,
3727
- {
3728
- fill: "neutral500",
3729
- height: "0.8rem",
3730
- width: "0.8rem",
3731
- style: { margin: "0 0.8rem" }
3732
- }
3733
- )
3734
- ] }, index2)) }),
3735
- /* @__PURE__ */ jsx(Typography, { tag: "p", textColor: "neutral600", children: formatMessage({
3736
- id: getTranslation(`containers.list.autoCloneModal.error.${reason}`),
3737
- defaultMessage: getDefaultErrorMessage(reason)
3738
- }) })
3739
- ]
3740
- },
3741
- fieldPath.join()
3742
- )) })
3743
- ] });
3744
- };
3745
- const TableActions = ({ document }) => {
3746
- const { formatMessage } = useIntl();
3747
- const { model, collectionType } = useDoc();
3748
- const plugins = useStrapiApp("TableActions", (state) => state.plugins);
3749
- const props = {
3750
- activeTab: null,
3751
- model,
3752
- documentId: document.documentId,
3753
- collectionType,
3754
- document
3755
- };
3756
- return /* @__PURE__ */ jsx(
3757
- DescriptionComponentRenderer,
3758
- {
3759
- props,
3760
- descriptions: plugins["content-manager"].apis.getDocumentActions("table-row").filter((action) => action.name !== "PublishAction"),
3761
- children: (actions2) => {
3762
- const tableRowActions = actions2.filter((action) => {
3763
- const positions = Array.isArray(action.position) ? action.position : [action.position];
3764
- return positions.includes("table-row");
3765
- });
3766
- return /* @__PURE__ */ jsx(
3767
- DocumentActionsMenu,
3768
- {
3769
- actions: tableRowActions,
3770
- label: formatMessage({
3771
- id: "content-manager.containers.list.table.row-actions",
3772
- defaultMessage: "Row action"
3773
- }),
3774
- variant: "ghost"
3775
- }
3776
- );
3777
- }
3778
- }
3779
- );
3780
- };
3781
- const EditAction = ({ documentId }) => {
3782
- const navigate = useNavigate();
3783
- const { formatMessage } = useIntl();
3784
- const { canRead } = useDocumentRBAC("EditAction", ({ canRead: canRead2 }) => ({ canRead: canRead2 }));
3785
- const { toggleNotification } = useNotification();
3786
- const [{ query }] = useQueryParams();
3787
- return {
3788
- disabled: !canRead,
3789
- icon: /* @__PURE__ */ jsx(StyledPencil, {}),
3790
- label: formatMessage({
3791
- id: "content-manager.actions.edit.label",
3792
- defaultMessage: "Edit"
3793
- }),
3794
- position: "table-row",
3795
- onClick: async () => {
3796
- if (!documentId) {
3797
- console.error(
3798
- "You're trying to edit a document without an id, this is likely a bug with Strapi. Please open an issue."
3799
- );
3800
- toggleNotification({
3801
- message: formatMessage({
3802
- id: "content-manager.actions.edit.error",
3803
- defaultMessage: "An error occurred while trying to edit the document."
3804
- }),
3805
- type: "danger"
3806
- });
3807
- return;
3808
- }
3809
- navigate({
3810
- pathname: documentId,
3811
- search: stringify({
3812
- plugins: query.plugins
3813
- })
3814
- });
3815
- }
3816
- };
3817
- };
3818
- EditAction.type = "edit";
3819
- EditAction.position = "table-row";
3820
- const StyledPencil = styled(Pencil)`
3821
- path {
3822
- fill: currentColor;
3823
- }
3824
- `;
3825
- const CloneAction = ({ model, documentId }) => {
3826
- const navigate = useNavigate();
3827
- const { formatMessage } = useIntl();
3828
- const { canCreate } = useDocumentRBAC("CloneAction", ({ canCreate: canCreate2 }) => ({ canCreate: canCreate2 }));
3829
- const { toggleNotification } = useNotification();
3830
- const { autoClone } = useDocumentActions();
3831
- const [prohibitedFields, setProhibitedFields] = React.useState([]);
3832
- return {
3833
- disabled: !canCreate,
3834
- icon: /* @__PURE__ */ jsx(StyledDuplicate, {}),
3835
- label: formatMessage({
3836
- id: "content-manager.actions.clone.label",
3837
- defaultMessage: "Duplicate"
3838
- }),
3839
- position: "table-row",
3840
- onClick: async () => {
3841
- if (!documentId) {
3842
- console.error(
3843
- "You're trying to clone a document in the table without an id, this is likely a bug with Strapi. Please open an issue."
3844
- );
3845
- toggleNotification({
3846
- message: formatMessage({
3847
- id: "content-manager.actions.clone.error",
3848
- defaultMessage: "An error occurred while trying to clone the document."
3849
- }),
3850
- type: "danger"
3851
- });
3852
- return;
3853
- }
3854
- const res = await autoClone({ model, sourceId: documentId });
3855
- if ("data" in res) {
3856
- navigate(res.data.documentId);
3857
- return true;
3858
- }
3859
- if (isBaseQueryError(res.error) && res.error.details && typeof res.error.details === "object" && "prohibitedFields" in res.error.details && Array.isArray(res.error.details.prohibitedFields)) {
3860
- const prohibitedFields2 = res.error.details.prohibitedFields;
3861
- setProhibitedFields(prohibitedFields2);
3862
- }
3863
- },
3864
- dialog: {
3865
- type: "modal",
3866
- title: formatMessage({
3867
- id: "content-manager.containers.list.autoCloneModal.header",
3868
- defaultMessage: "Duplicate"
3869
- }),
3870
- content: /* @__PURE__ */ jsx(AutoCloneFailureModalBody, { prohibitedFields }),
3871
- footer: ({ onClose }) => {
3872
- return /* @__PURE__ */ jsxs(Modal.Footer, { children: [
3873
- /* @__PURE__ */ jsx(Button, { onClick: onClose, variant: "tertiary", children: formatMessage({
3874
- id: "cancel",
3875
- defaultMessage: "Cancel"
3876
- }) }),
3877
- /* @__PURE__ */ jsx(
3878
- LinkButton,
3879
- {
3880
- tag: NavLink,
3881
- to: {
3882
- pathname: `clone/${documentId}`
3883
- },
3884
- children: formatMessage({
3885
- id: "content-manager.containers.list.autoCloneModal.create",
3886
- defaultMessage: "Create"
3887
- })
3888
- }
3889
- )
3890
- ] });
3891
- }
3892
- }
3893
- };
3894
- };
3895
- CloneAction.type = "clone";
3896
- CloneAction.position = "table-row";
3897
- const StyledDuplicate = styled(Duplicate)`
3898
- path {
3899
- fill: currentColor;
3900
- }
3901
- `;
3902
- const DEFAULT_TABLE_ROW_ACTIONS = [EditAction, CloneAction];
3903
- class ContentManagerPlugin {
3904
- /**
3905
- * The following properties are the stored ones provided by any plugins registering with
3906
- * the content-manager. The function calls however, need to be called at runtime in the
3907
- * application, so instead we collate them and run them later with the complete list incl.
3908
- * ones already registered & the context of the view.
3909
- */
3910
- bulkActions = [...DEFAULT_BULK_ACTIONS];
3911
- documentActions = [
3912
- ...DEFAULT_ACTIONS,
3913
- ...DEFAULT_TABLE_ROW_ACTIONS,
3914
- ...DEFAULT_HEADER_ACTIONS
3915
- ];
3916
- editViewSidePanels = [ActionsPanel];
3917
- headerActions = [];
3918
- constructor() {
3919
- }
3920
- addEditViewSidePanel(panels) {
3921
- if (Array.isArray(panels)) {
3922
- this.editViewSidePanels = [...this.editViewSidePanels, ...panels];
3923
- } else if (typeof panels === "function") {
3924
- this.editViewSidePanels = panels(this.editViewSidePanels);
3925
- } else {
3926
- throw new Error(
3927
- `Expected the \`panels\` passed to \`addEditViewSidePanel\` to be an array or a function, but received ${getPrintableType(
3928
- panels
3929
- )}`
3930
- );
3931
- }
3932
- }
3933
- addDocumentAction(actions2) {
3934
- if (Array.isArray(actions2)) {
3935
- this.documentActions = [...this.documentActions, ...actions2];
3936
- } else if (typeof actions2 === "function") {
3937
- this.documentActions = actions2(this.documentActions);
3938
- } else {
3939
- throw new Error(
3940
- `Expected the \`actions\` passed to \`addDocumentAction\` to be an array or a function, but received ${getPrintableType(
3941
- actions2
3942
- )}`
3943
- );
3944
- }
3945
- }
3946
- addDocumentHeaderAction(actions2) {
3947
- if (Array.isArray(actions2)) {
3948
- this.headerActions = [...this.headerActions, ...actions2];
3949
- } else if (typeof actions2 === "function") {
3950
- this.headerActions = actions2(this.headerActions);
3951
- } else {
3952
- throw new Error(
3953
- `Expected the \`actions\` passed to \`addDocumentHeaderAction\` to be an array or a function, but received ${getPrintableType(
3954
- actions2
3955
- )}`
3956
- );
3957
- }
3958
- }
3959
- addBulkAction(actions2) {
3960
- if (Array.isArray(actions2)) {
3961
- this.bulkActions = [...this.bulkActions, ...actions2];
3962
- } else if (typeof actions2 === "function") {
3963
- this.bulkActions = actions2(this.bulkActions);
3964
- } else {
3965
- throw new Error(
3966
- `Expected the \`actions\` passed to \`addBulkAction\` to be an array or a function, but received ${getPrintableType(
3967
- actions2
3968
- )}`
3969
- );
3970
- }
3971
- }
3972
- get config() {
3973
- return {
3974
- id: PLUGIN_ID,
3975
- name: "Content Manager",
3976
- injectionZones: INJECTION_ZONES,
3977
- apis: {
3978
- addBulkAction: this.addBulkAction.bind(this),
3979
- addDocumentAction: this.addDocumentAction.bind(this),
3980
- addDocumentHeaderAction: this.addDocumentHeaderAction.bind(this),
3981
- addEditViewSidePanel: this.addEditViewSidePanel.bind(this),
3982
- getBulkActions: () => this.bulkActions,
3983
- getDocumentActions: (position) => {
3984
- if (position) {
3985
- return this.documentActions.filter(
3986
- (action) => action.position == void 0 || [action.position].flat().includes(position)
3987
- );
3988
- }
3989
- return this.documentActions;
3990
- },
3991
- getEditViewSidePanels: () => this.editViewSidePanels,
3992
- getHeaderActions: () => this.headerActions
3993
- }
3994
- };
3995
- }
3996
- }
3997
- const getPrintableType = (value) => {
3998
- const nativeType = typeof value;
3999
- if (nativeType === "object") {
4000
- if (value === null) return "null";
4001
- if (Array.isArray(value)) return "array";
4002
- if (value instanceof Object && value.constructor.name !== "Object") {
4003
- return value.constructor.name;
4004
- }
4005
- }
4006
- return nativeType;
4007
- };
4008
- const HistoryAction = ({ model, document }) => {
4009
- const { formatMessage } = useIntl();
4010
- const [{ query }] = useQueryParams();
4011
- const navigate = useNavigate();
4012
- const { trackUsage } = useTracking();
4013
- const { pathname } = useLocation();
4014
- const pluginsQueryParams = stringify({ plugins: query.plugins }, { encode: false });
4015
- if (!window.strapi.features.isEnabled("cms-content-history")) {
4016
- return null;
4017
- }
4018
- const handleOnClick = () => {
4019
- const destination = { pathname: "history", search: pluginsQueryParams };
4020
- trackUsage("willNavigate", {
4021
- from: pathname,
4022
- to: `${pathname}/${destination.pathname}`
4023
- });
4024
- navigate(destination);
4025
- };
4026
- return {
4027
- icon: /* @__PURE__ */ jsx(ClockCounterClockwise, {}),
4028
- label: formatMessage({
4029
- id: "content-manager.history.document-action",
4030
- defaultMessage: "Content History"
4031
- }),
4032
- onClick: handleOnClick,
4033
- disabled: (
4034
- /**
4035
- * The user is creating a new document.
4036
- * It hasn't been saved yet, so there's no history to go to
4037
- */
4038
- !document || /**
4039
- * The document has been created but the current dimension has never been saved.
4040
- * For example, the user is creating a new locale in an existing document,
4041
- * so there's no history for the document in that locale
4042
- */
4043
- !document.id || /**
4044
- * History is only available for content types created by the user.
4045
- * These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
4046
- * which start with `admin::` or `plugin::`
4047
- */
4048
- !model.startsWith("api::")
4049
- ),
4050
- position: "header"
4051
- };
4052
- };
4053
- HistoryAction.type = "history";
4054
- HistoryAction.position = "header";
4055
- const historyAdmin = {
4056
- bootstrap(app) {
4057
- const { addDocumentAction } = app.getPlugin("content-manager").apis;
4058
- addDocumentAction((actions2) => {
4059
- const indexOfDeleteAction = actions2.findIndex((action) => action.type === "delete");
4060
- actions2.splice(indexOfDeleteAction, 0, HistoryAction);
4061
- return actions2;
4062
- });
4063
- }
4064
- };
4065
- const initialState = {
4066
- collectionTypeLinks: [],
4067
- components: [],
4068
- fieldSizes: {},
4069
- models: [],
4070
- singleTypeLinks: [],
4071
- isLoading: true
4072
- };
4073
- const appSlice = createSlice({
4074
- name: "app",
4075
- initialState,
4076
- reducers: {
4077
- setInitialData(state, action) {
4078
- const {
4079
- authorizedCollectionTypeLinks,
4080
- authorizedSingleTypeLinks,
4081
- components,
4082
- contentTypeSchemas,
4083
- fieldSizes
4084
- } = action.payload;
4085
- state.collectionTypeLinks = authorizedCollectionTypeLinks.filter(
4086
- ({ isDisplayed }) => isDisplayed
4087
- );
4088
- state.singleTypeLinks = authorizedSingleTypeLinks.filter(({ isDisplayed }) => isDisplayed);
4089
- state.components = components;
4090
- state.models = contentTypeSchemas;
4091
- state.fieldSizes = fieldSizes;
4092
- state.isLoading = false;
4093
- }
4094
- }
4095
- });
4096
- const { actions, reducer: reducer$1 } = appSlice;
4097
- const { setInitialData } = actions;
4098
- const reducer = combineReducers({
4099
- app: reducer$1
4100
- });
4101
- const previewApi = contentManagerApi.injectEndpoints({
4102
- endpoints: (builder) => ({
4103
- getPreviewUrl: builder.query({
4104
- query({ query, params }) {
4105
- return {
4106
- url: `/content-manager/preview/url/${params.contentType}`,
4107
- method: "GET",
4108
- config: {
4109
- params: query
4110
- }
4111
- };
4112
- }
4113
- })
4114
- })
4115
- });
4116
- const { useGetPreviewUrlQuery } = previewApi;
4117
- const ConditionalTooltip = ({ isShown, label, children }) => {
4118
- if (isShown) {
4119
- return /* @__PURE__ */ jsx(Tooltip, { label, children });
4120
- }
4121
- return children;
4122
- };
4123
- const PreviewSidePanel = ({ model, documentId, document }) => {
4124
- const { formatMessage } = useIntl();
4125
- const { trackUsage } = useTracking();
4126
- const { pathname } = useLocation();
4127
- const [{ query }] = useQueryParams();
4128
- const isModified = useForm("PreviewSidePanel", (state) => state.modified);
4129
- const { data, error } = useGetPreviewUrlQuery({
4130
- params: {
4131
- contentType: model
4132
- },
4133
- query: {
4134
- documentId,
4135
- locale: document?.locale,
4136
- status: document?.status
4137
- }
4138
- });
4139
- if (!data?.data?.url || error) {
4140
- return null;
4141
- }
4142
- const trackNavigation = () => {
4143
- const destinationPathname = pathname.replace(/\/$/, "") + "/preview";
4144
- trackUsage("willNavigate", { from: pathname, to: destinationPathname });
4145
- };
4146
- return {
4147
- title: formatMessage({ id: "content-manager.preview.panel.title", defaultMessage: "Preview" }),
4148
- content: /* @__PURE__ */ jsx(
4149
- ConditionalTooltip,
4150
- {
4151
- label: formatMessage({
4152
- id: "content-manager.preview.panel.button-disabled-tooltip",
4153
- defaultMessage: "Please save to open the preview"
4154
- }),
4155
- isShown: isModified,
4156
- children: /* @__PURE__ */ jsx(Box, { cursor: "not-allowed", width: "100%", children: /* @__PURE__ */ jsx(
4157
- Button,
4158
- {
4159
- variant: "tertiary",
4160
- tag: Link,
4161
- to: { pathname: "preview", search: stringify(query, { encode: false }) },
4162
- onClick: trackNavigation,
4163
- width: "100%",
4164
- disabled: isModified,
4165
- pointerEvents: isModified ? "none" : void 0,
4166
- tabIndex: isModified ? -1 : void 0,
4167
- children: formatMessage({
4168
- id: "content-manager.preview.panel.button",
4169
- defaultMessage: "Open preview"
4170
- })
4171
- }
4172
- ) })
4173
- }
4174
- )
4175
- };
4176
- };
4177
- const previewAdmin = {
4178
- bootstrap(app) {
4179
- const contentManagerPluginApis = app.getPlugin("content-manager").apis;
4180
- contentManagerPluginApis.addEditViewSidePanel([PreviewSidePanel]);
4181
- }
4182
- };
4183
- const index = {
4184
- register(app) {
4185
- const cm = new ContentManagerPlugin();
4186
- app.addReducers({
4187
- [PLUGIN_ID]: reducer
4188
- });
4189
- app.addMenuLink({
4190
- to: PLUGIN_ID,
4191
- icon: Feather,
4192
- intlLabel: {
4193
- id: `content-manager.plugin.name`,
4194
- defaultMessage: "Content Manager"
4195
- },
4196
- permissions: [],
4197
- position: 1
4198
- });
4199
- app.router.addRoute({
4200
- path: "content-manager/*",
4201
- lazy: async () => {
4202
- const { Layout } = await import("./layout-CKw8rE38.mjs");
4203
- return {
4204
- Component: Layout
4205
- };
4206
- },
4207
- children: routes
4208
- });
4209
- app.registerPlugin(cm.config);
4210
- },
4211
- bootstrap(app) {
4212
- if (typeof historyAdmin.bootstrap === "function") {
4213
- historyAdmin.bootstrap(app);
4214
- }
4215
- if (typeof previewAdmin.bootstrap === "function") {
4216
- previewAdmin.bootstrap(app);
4217
- }
4218
- },
4219
- async registerTrads({ locales }) {
4220
- const importedTrads = await Promise.all(
4221
- locales.map((locale) => {
4222
- return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => import("./ar-CCEVvqGG.mjs"), "./translations/ca.json": () => import("./ca-5U32ON2v.mjs"), "./translations/cs.json": () => import("./cs-CM2aBUar.mjs"), "./translations/de.json": () => import("./de-C72KDNOl.mjs"), "./translations/en.json": () => import("./en-CSxLmrh1.mjs"), "./translations/es.json": () => import("./es-D34tqjMw.mjs"), "./translations/eu.json": () => import("./eu-CdALomew.mjs"), "./translations/fr.json": () => import("./fr--pg5jUbt.mjs"), "./translations/gu.json": () => import("./gu-CNpaMDpH.mjs"), "./translations/hi.json": () => import("./hi-Dwvd04m3.mjs"), "./translations/hu.json": () => import("./hu-CeYvaaO0.mjs"), "./translations/id.json": () => import("./id-BtwA9WJT.mjs"), "./translations/it.json": () => import("./it-BrVPqaf1.mjs"), "./translations/ja.json": () => import("./ja-BHqhDq4V.mjs"), "./translations/ko.json": () => import("./ko-HVQRlfUI.mjs"), "./translations/ml.json": () => import("./ml-BihZwQit.mjs"), "./translations/ms.json": () => import("./ms-m_WjyWx7.mjs"), "./translations/nl.json": () => import("./nl-D4R9gHx5.mjs"), "./translations/pl.json": () => import("./pl-sbx9mSt_.mjs"), "./translations/pt-BR.json": () => import("./pt-BR-C71iDxnh.mjs"), "./translations/pt.json": () => import("./pt-BsaFvS8-.mjs"), "./translations/ru.json": () => import("./ru-BE6A4Exp.mjs"), "./translations/sa.json": () => import("./sa-Dag0k-Z8.mjs"), "./translations/sk.json": () => import("./sk-BFg-R8qJ.mjs"), "./translations/sv.json": () => import("./sv-CUnfWGsh.mjs"), "./translations/th.json": () => import("./th-BqbI8lIT.mjs"), "./translations/tr.json": () => import("./tr-CgeK3wJM.mjs"), "./translations/uk.json": () => import("./uk-CR-zDhAY.mjs"), "./translations/vi.json": () => import("./vi-DUXIk_fw.mjs"), "./translations/zh-Hans.json": () => import("./zh-Hans-BPQcRIyH.mjs"), "./translations/zh.json": () => import("./zh-BWZspA60.mjs") }), `./translations/${locale}.json`, 3).then(({ default: data }) => {
4223
- return {
4224
- data: prefixPluginTranslations(data, PLUGIN_ID),
4225
- locale
4226
- };
4227
- }).catch(() => {
4228
- return {
4229
- data: {},
4230
- locale
4231
- };
4232
- });
4233
- })
4234
- );
4235
- return Promise.resolve(importedTrads);
4236
- }
4237
- };
4238
- export {
4239
- ATTRIBUTE_TYPES_THAT_CANNOT_BE_MAIN_FIELD as A,
4240
- BulkActionsRenderer as B,
4241
- COLLECTION_TYPES as C,
4242
- DocumentStatus as D,
4243
- extractContentTypeComponents as E,
4244
- DEFAULT_SETTINGS as F,
4245
- convertEditLayoutToFieldLayouts as G,
4246
- HOOKS as H,
4247
- InjectionZone as I,
4248
- useDocument as J,
4249
- useGetPreviewUrlQuery as K,
4250
- index as L,
4251
- useContentManagerContext as M,
4252
- useDocumentActions as N,
4253
- Panels as P,
4254
- RelativeTime as R,
4255
- SINGLE_TYPES as S,
4256
- TableActions as T,
4257
- useGetInitialDataQuery as a,
4258
- useGetAllContentTypeSettingsQuery as b,
4259
- useDoc as c,
4260
- buildValidParams as d,
4261
- contentManagerApi as e,
4262
- useDocumentRBAC as f,
4263
- getTranslation as g,
4264
- useDocumentLayout as h,
4265
- createYupSchema as i,
4266
- Header as j,
4267
- PERMISSIONS as k,
4268
- DocumentRBAC as l,
4269
- DOCUMENT_META_FIELDS as m,
4270
- CLONE_PATH as n,
4271
- useDocLayout as o,
4272
- useGetContentTypeConfigurationQuery as p,
4273
- CREATOR_FIELDS as q,
4274
- getMainField as r,
4275
- setInitialData as s,
4276
- getDisplayName as t,
4277
- useContentTypeSchema as u,
4278
- checkIfAttributeIsDisplayable as v,
4279
- useGetAllDocumentsQuery as w,
4280
- convertListLayoutToFieldLayouts as x,
4281
- capitalise as y,
4282
- useUpdateContentTypeConfigurationMutation as z
4283
- };
4284
- //# sourceMappingURL=index-Rej95OkL.mjs.map