@strapi/content-manager 0.0.0-next.cb5f24c83e8fde7c31e5850c14430d38aa9b8862 → 0.0.0-next.cc6c39db185a337e2eafce8bcf06544351e92cc5

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