@strapi/content-manager 0.0.0-experimental.bb39175992a5cd205a7e3f2e13a96aa31eba2cff → 0.0.0-experimental.be7746d32e70ba7219186219896ff4ae64735740

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