@strapi/content-manager 0.0.0-next.185e16fdc3e6f1895610ab73932bc3f044bb59e9 → 0.0.0-next.23a591758a1d192f794079bbe4821ef8d26e1555

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