@strapi/content-manager 0.0.0-next.b6435ada233136a0d0b14fba67961ff8f16cdac2 → 0.0.0-next.b8a93ec6cfca2f18075819bb617db6bca123b8e2

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