@strapi/content-manager 0.0.0-experimental.1610404a03d98b65f497f9adda35815021b8fd76 → 0.0.0-experimental.16cb0821de17dd12078d915e3a10249158807e5e

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