@strapi/content-manager 0.0.0-next.6d1431fe2a53b80b47ad9f00187cd7bae9d5f46b → 0.0.0-next.6d1dbc97a99dbfe8847598f6cbea3f7a1df2c89c

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