@strapi/content-manager 0.0.0-experimental.cb74730ce5154c26404d4dccca14976a22319002 → 0.0.0-experimental.cf8bb33f3f3ac8c6469f469802867e9fc2005e58

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