@strapi/content-manager 0.0.0-experimental.3c73a4c6f6073abdf1608121a200c3d4d87b1aa8 → 0.0.0-experimental.3fd705928266d1b836afc8a30fceb35aac0ae2f8

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 (130) hide show
  1. package/LICENSE +18 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-Cxz51Sve.mjs → ComponentConfigurationPage-CpBFh6_r.mjs} +3 -3
  3. package/dist/_chunks/{ComponentConfigurationPage-Cxz51Sve.mjs.map → ComponentConfigurationPage-CpBFh6_r.mjs.map} +1 -1
  4. package/dist/_chunks/{ComponentConfigurationPage-BZIaEffq.js → ComponentConfigurationPage-_zF8p6CY.js} +3 -3
  5. package/dist/_chunks/{ComponentConfigurationPage-BZIaEffq.js.map → ComponentConfigurationPage-_zF8p6CY.js.map} +1 -1
  6. package/dist/_chunks/{EditConfigurationPage-CZLbgfIp.mjs → EditConfigurationPage-CE_yavTi.mjs} +3 -3
  7. package/dist/_chunks/{EditConfigurationPage-CZLbgfIp.mjs.map → EditConfigurationPage-CE_yavTi.mjs.map} +1 -1
  8. package/dist/_chunks/{EditConfigurationPage-CM62NN0L.js → EditConfigurationPage-_aG2DJSU.js} +3 -3
  9. package/dist/_chunks/{EditConfigurationPage-CM62NN0L.js.map → EditConfigurationPage-_aG2DJSU.js.map} +1 -1
  10. package/dist/_chunks/{EditViewPage-CzuJgWWp.mjs → EditViewPage-DeTn7rAF.mjs} +58 -47
  11. package/dist/_chunks/EditViewPage-DeTn7rAF.mjs.map +1 -0
  12. package/dist/_chunks/{EditViewPage-CU7724gt.js → EditViewPage-G9uNzwYL.js} +57 -46
  13. package/dist/_chunks/EditViewPage-G9uNzwYL.js.map +1 -0
  14. package/dist/_chunks/{Field-QtUSh5mU.mjs → Field-CnCKhI1R.mjs} +526 -218
  15. package/dist/_chunks/Field-CnCKhI1R.mjs.map +1 -0
  16. package/dist/_chunks/{Field-Dh1yZyqy.js → Field-DDHUWEfV.js} +528 -220
  17. package/dist/_chunks/Field-DDHUWEfV.js.map +1 -0
  18. package/dist/_chunks/{Form-BOR8NOe1.js → Form-DYETaKUX.js} +51 -33
  19. package/dist/_chunks/Form-DYETaKUX.js.map +1 -0
  20. package/dist/_chunks/{Form-COLpvlnv.mjs → Form-IvVVwqRL.mjs} +53 -35
  21. package/dist/_chunks/Form-IvVVwqRL.mjs.map +1 -0
  22. package/dist/_chunks/{History-Bu53Yfw-.mjs → History-BMunT-do.mjs} +141 -37
  23. package/dist/_chunks/History-BMunT-do.mjs.map +1 -0
  24. package/dist/_chunks/{History-CW2akQ6h.js → History-CnZDctSO.js} +140 -36
  25. package/dist/_chunks/History-CnZDctSO.js.map +1 -0
  26. package/dist/_chunks/{ListConfigurationPage-jzdhEk_u.js → ListConfigurationPage-BynalOp8.js} +57 -46
  27. package/dist/_chunks/ListConfigurationPage-BynalOp8.js.map +1 -0
  28. package/dist/_chunks/{ListConfigurationPage-TqrmwjPN.mjs → ListConfigurationPage-CDqkCxgV.mjs} +58 -48
  29. package/dist/_chunks/ListConfigurationPage-CDqkCxgV.mjs.map +1 -0
  30. package/dist/_chunks/{ListViewPage-B3bMOrMv.js → ListViewPage-I88Ouzoq.js} +100 -103
  31. package/dist/_chunks/ListViewPage-I88Ouzoq.js.map +1 -0
  32. package/dist/_chunks/{ListViewPage-BO_mOXIl.mjs → ListViewPage-_5gS-DOF.mjs} +98 -101
  33. package/dist/_chunks/ListViewPage-_5gS-DOF.mjs.map +1 -0
  34. package/dist/_chunks/{NoContentTypePage-D77xsNHj.js → NoContentTypePage-BaWQ7HsA.js} +2 -2
  35. package/dist/_chunks/{NoContentTypePage-D77xsNHj.js.map → NoContentTypePage-BaWQ7HsA.js.map} +1 -1
  36. package/dist/_chunks/{NoContentTypePage-DqB0QV0k.mjs → NoContentTypePage-Dht-55hr.mjs} +2 -2
  37. package/dist/_chunks/{NoContentTypePage-DqB0QV0k.mjs.map → NoContentTypePage-Dht-55hr.mjs.map} +1 -1
  38. package/dist/_chunks/{NoPermissionsPage-DTXi042N.mjs → NoPermissionsPage-Bs8D5W_v.mjs} +2 -2
  39. package/dist/_chunks/{NoPermissionsPage-DTXi042N.mjs.map → NoPermissionsPage-Bs8D5W_v.mjs.map} +1 -1
  40. package/dist/_chunks/{NoPermissionsPage-C6qTGogm.js → NoPermissionsPage-DCVUh5at.js} +2 -2
  41. package/dist/_chunks/{NoPermissionsPage-C6qTGogm.js.map → NoPermissionsPage-DCVUh5at.js.map} +1 -1
  42. package/dist/_chunks/{Relations-B6fb2POW.js → Relations-BPgFQeGj.js} +4 -4
  43. package/dist/_chunks/Relations-BPgFQeGj.js.map +1 -0
  44. package/dist/_chunks/{Relations-CJ4qdkRo.mjs → Relations-Chdt5qWc.mjs} +4 -4
  45. package/dist/_chunks/Relations-Chdt5qWc.mjs.map +1 -0
  46. package/dist/_chunks/{en-DZXjRiWA.js → en-BVzUkPxZ.js} +12 -8
  47. package/dist/_chunks/{en-DZXjRiWA.js.map → en-BVzUkPxZ.js.map} +1 -1
  48. package/dist/_chunks/{en-9GwRW_ku.mjs → en-CPTj6CjC.mjs} +12 -8
  49. package/dist/_chunks/{en-9GwRW_ku.mjs.map → en-CPTj6CjC.mjs.map} +1 -1
  50. package/dist/_chunks/{index-DcUu-_72.js → index-BhbLFX4l.js} +527 -439
  51. package/dist/_chunks/index-BhbLFX4l.js.map +1 -0
  52. package/dist/_chunks/{index-Dahjdw4h.mjs → index-D4UGPFZC.mjs} +534 -446
  53. package/dist/_chunks/index-D4UGPFZC.mjs.map +1 -0
  54. package/dist/_chunks/{layout-jcY4dyUG.js → layout-CYA7s0qO.js} +25 -12
  55. package/dist/_chunks/layout-CYA7s0qO.js.map +1 -0
  56. package/dist/_chunks/{layout-omucV6TV.mjs → layout-D4HI4_PS.mjs} +27 -14
  57. package/dist/_chunks/layout-D4HI4_PS.mjs.map +1 -0
  58. package/dist/_chunks/{relations-CN0-aw6p.mjs → relations-1pXaYpBK.mjs} +2 -2
  59. package/dist/_chunks/{relations-CN0-aw6p.mjs.map → relations-1pXaYpBK.mjs.map} +1 -1
  60. package/dist/_chunks/{relations-DGzD7ORa.js → relations-DDZ9OxNo.js} +2 -2
  61. package/dist/_chunks/{relations-DGzD7ORa.js.map → relations-DDZ9OxNo.js.map} +1 -1
  62. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  63. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  64. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  65. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  66. package/dist/admin/index.js +1 -1
  67. package/dist/admin/index.mjs +1 -1
  68. package/dist/admin/src/history/components/VersionInputRenderer.d.ts +1 -1
  69. package/dist/admin/src/history/index.d.ts +3 -0
  70. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  71. package/dist/admin/src/index.d.ts +1 -0
  72. package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +8 -3
  73. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +4 -0
  74. package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
  75. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
  76. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
  77. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +6 -58
  78. package/dist/admin/src/pages/EditView/components/Header.d.ts +10 -11
  79. package/dist/admin/src/pages/ListView/components/BulkActions/Actions.d.ts +3 -30
  80. package/dist/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.d.ts +2 -2
  81. package/dist/admin/src/services/api.d.ts +1 -1
  82. package/dist/admin/src/services/components.d.ts +2 -2
  83. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  84. package/dist/admin/src/services/documents.d.ts +19 -17
  85. package/dist/admin/src/services/init.d.ts +1 -1
  86. package/dist/admin/src/services/relations.d.ts +2 -2
  87. package/dist/admin/src/services/uid.d.ts +3 -3
  88. package/dist/admin/src/utils/validation.d.ts +4 -1
  89. package/dist/server/index.js +181 -107
  90. package/dist/server/index.js.map +1 -1
  91. package/dist/server/index.mjs +182 -108
  92. package/dist/server/index.mjs.map +1 -1
  93. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  94. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  95. package/dist/server/src/controllers/uid.d.ts.map +1 -1
  96. package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
  97. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
  98. package/dist/server/src/history/services/history.d.ts.map +1 -1
  99. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  100. package/dist/server/src/history/services/utils.d.ts +2 -1
  101. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  102. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  103. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  104. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  105. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  106. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  107. package/dist/shared/contracts/collection-types.d.ts +3 -1
  108. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  109. package/package.json +9 -9
  110. package/dist/_chunks/EditViewPage-CU7724gt.js.map +0 -1
  111. package/dist/_chunks/EditViewPage-CzuJgWWp.mjs.map +0 -1
  112. package/dist/_chunks/Field-Dh1yZyqy.js.map +0 -1
  113. package/dist/_chunks/Field-QtUSh5mU.mjs.map +0 -1
  114. package/dist/_chunks/Form-BOR8NOe1.js.map +0 -1
  115. package/dist/_chunks/Form-COLpvlnv.mjs.map +0 -1
  116. package/dist/_chunks/History-Bu53Yfw-.mjs.map +0 -1
  117. package/dist/_chunks/History-CW2akQ6h.js.map +0 -1
  118. package/dist/_chunks/ListConfigurationPage-TqrmwjPN.mjs.map +0 -1
  119. package/dist/_chunks/ListConfigurationPage-jzdhEk_u.js.map +0 -1
  120. package/dist/_chunks/ListViewPage-B3bMOrMv.js.map +0 -1
  121. package/dist/_chunks/ListViewPage-BO_mOXIl.mjs.map +0 -1
  122. package/dist/_chunks/Relations-B6fb2POW.js.map +0 -1
  123. package/dist/_chunks/Relations-CJ4qdkRo.mjs.map +0 -1
  124. package/dist/_chunks/index-Dahjdw4h.mjs.map +0 -1
  125. package/dist/_chunks/index-DcUu-_72.js.map +0 -1
  126. package/dist/_chunks/layout-jcY4dyUG.js.map +0 -1
  127. package/dist/_chunks/layout-omucV6TV.mjs.map +0 -1
  128. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  129. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  130. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
@@ -1,17 +1,17 @@
1
- import { ClockCounterClockwise, CrossCircle, More, WarningCircle, ListPlus, Pencil, Trash, Check, CheckCircle, ArrowsCounterClockwise, ChevronRight, Duplicate, Feather } from "@strapi/icons";
1
+ import { More, Cross, WarningCircle, ListPlus, Pencil, Trash, Check, CrossCircle, CheckCircle, ArrowsCounterClockwise, ChevronRight, Duplicate, ClockCounterClockwise, Feather } from "@strapi/icons";
2
2
  import { jsx, Fragment, jsxs } from "react/jsx-runtime";
3
- import { useStrapiApp, useQueryParams, createContext, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors, useTracking, useForm, BackButton, DescriptionComponentRenderer, useTable, Table } from "@strapi/admin/strapi-admin";
4
- import { stringify } from "qs";
5
- import { useIntl } from "react-intl";
6
- import { useNavigate, useParams, Navigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
3
+ import { useStrapiApp, createContext, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors, useQueryParams, useTracking, useForm, BackButton, DescriptionComponentRenderer, useTable, Table } from "@strapi/admin/strapi-admin";
7
4
  import * as React from "react";
8
5
  import { lazy } from "react";
9
- import { Menu, VisuallyHidden, Flex, Typography, Dialog, DialogBody, DialogFooter, Button, ModalLayout, ModalHeader, ModalBody, Box, Radio, Status, SingleSelect, SingleSelectOption, ModalFooter, Loader, IconButton, Tooltip, LinkButton } from "@strapi/design-system";
10
- import { styled } from "styled-components";
6
+ import { Button, Menu, VisuallyHidden, Flex, Typography, Dialog, Modal, Radio, Status, Box, SingleSelect, SingleSelectOption, IconButton, Loader, Tooltip, LinkButton } from "@strapi/design-system";
7
+ import { useIntl } from "react-intl";
8
+ import { useParams, useNavigate, Navigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
11
9
  import * as yup from "yup";
12
10
  import { ValidationError } from "yup";
13
11
  import pipe from "lodash/fp/pipe";
14
12
  import { intervalToDuration, isPast } from "date-fns";
13
+ import { styled } from "styled-components";
14
+ import { stringify } from "qs";
15
15
  import { createSlice, combineReducers } from "@reduxjs/toolkit";
16
16
  const __variableDynamicImportRuntimeHelper = (glob, path) => {
17
17
  const v = glob[path];
@@ -49,42 +49,6 @@ const useInjectionZone = (area) => {
49
49
  const [page, position] = area.split(".");
50
50
  return contentManagerPlugin.getInjectedComponents(page, position);
51
51
  };
52
- const HistoryAction = ({ model, document }) => {
53
- const { formatMessage } = useIntl();
54
- const [{ query }] = useQueryParams();
55
- const navigate = useNavigate();
56
- const pluginsQueryParams = stringify({ plugins: query.plugins }, { encode: false });
57
- if (!window.strapi.features.isEnabled("cms-content-history")) {
58
- return null;
59
- }
60
- return {
61
- icon: /* @__PURE__ */ jsx(ClockCounterClockwise, {}),
62
- label: formatMessage({
63
- id: "content-manager.history.document-action",
64
- defaultMessage: "Content History"
65
- }),
66
- onClick: () => navigate({ pathname: "history", search: pluginsQueryParams }),
67
- disabled: (
68
- /**
69
- * The user is creating a new document.
70
- * It hasn't been saved yet, so there's no history to go to
71
- */
72
- !document || /**
73
- * The document has been created but the current dimension has never been saved.
74
- * For example, the user is creating a new locale in an existing document,
75
- * so there's no history for the document in that locale
76
- */
77
- !document.id || /**
78
- * History is only available for content types created by the user.
79
- * These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
80
- * which start with `admin::` or `plugin::`
81
- */
82
- !model.startsWith("api::")
83
- ),
84
- position: "header"
85
- };
86
- };
87
- HistoryAction.type = "history";
88
52
  const ID = "id";
89
53
  const CREATED_BY_ATTRIBUTE_NAME = "createdBy";
90
54
  const UPDATED_BY_ATTRIBUTE_NAME = "updatedBy";
@@ -194,10 +158,12 @@ const contentManagerApi = adminApi.enhanceEndpoints({
194
158
  "Document",
195
159
  "InitialData",
196
160
  "HistoryVersion",
197
- "Relations"
161
+ "Relations",
162
+ "UidAvailability"
198
163
  ]
199
164
  });
200
165
  const documentApi = contentManagerApi.injectEndpoints({
166
+ overrideExisting: true,
201
167
  endpoints: (builder) => ({
202
168
  autoCloneDocument: builder.mutation({
203
169
  query: ({ model, sourceId, query }) => ({
@@ -207,7 +173,12 @@ const documentApi = contentManagerApi.injectEndpoints({
207
173
  params: query
208
174
  }
209
175
  }),
210
- invalidatesTags: (_result, _error, { model }) => [{ type: "Document", id: `${model}_LIST` }]
176
+ invalidatesTags: (_result, error, { model }) => {
177
+ if (error) {
178
+ return [];
179
+ }
180
+ return [{ type: "Document", id: `${model}_LIST` }];
181
+ }
211
182
  }),
212
183
  cloneDocument: builder.mutation({
213
184
  query: ({ model, sourceId, data, params }) => ({
@@ -218,7 +189,10 @@ const documentApi = contentManagerApi.injectEndpoints({
218
189
  params
219
190
  }
220
191
  }),
221
- invalidatesTags: (_result, _error, { model }) => [{ type: "Document", id: `${model}_LIST` }]
192
+ invalidatesTags: (_result, _error, { model }) => [
193
+ { type: "Document", id: `${model}_LIST` },
194
+ { type: "UidAvailability", id: model }
195
+ ]
222
196
  }),
223
197
  /**
224
198
  * Creates a new collection-type document. This should ONLY be used for collection-types.
@@ -235,7 +209,8 @@ const documentApi = contentManagerApi.injectEndpoints({
235
209
  }),
236
210
  invalidatesTags: (result, _error, { model }) => [
237
211
  { type: "Document", id: `${model}_LIST` },
238
- "Relations"
212
+ "Relations",
213
+ { type: "UidAvailability", id: model }
239
214
  ]
240
215
  }),
241
216
  deleteDocument: builder.mutation({
@@ -276,7 +251,8 @@ const documentApi = contentManagerApi.injectEndpoints({
276
251
  id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
277
252
  },
278
253
  { type: "Document", id: `${model}_LIST` },
279
- "Relations"
254
+ "Relations",
255
+ { type: "UidAvailability", id: model }
280
256
  ];
281
257
  }
282
258
  }),
@@ -294,6 +270,7 @@ const documentApi = contentManagerApi.injectEndpoints({
294
270
  }),
295
271
  providesTags: (result, _error, arg) => {
296
272
  return [
273
+ { type: "Document", id: `ALL_LIST` },
297
274
  { type: "Document", id: `${arg.model}_LIST` },
298
275
  ...result?.results.map(({ documentId }) => ({
299
276
  type: "Document",
@@ -332,6 +309,11 @@ const documentApi = contentManagerApi.injectEndpoints({
332
309
  {
333
310
  type: "Document",
334
311
  id: collectionType !== SINGLE_TYPES ? `${model}_${result && "documentId" in result ? result.documentId : documentId}` : model
312
+ },
313
+ // Make it easy to invalidate all individual documents queries for a model
314
+ {
315
+ type: "Document",
316
+ id: `${model}_ALL_ITEMS`
335
317
  }
336
318
  ];
337
319
  }
@@ -395,8 +377,21 @@ const documentApi = contentManagerApi.injectEndpoints({
395
377
  type: "Document",
396
378
  id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
397
379
  },
398
- "Relations"
380
+ "Relations",
381
+ { type: "UidAvailability", id: model }
399
382
  ];
383
+ },
384
+ async onQueryStarted({ data, ...patch }, { dispatch, queryFulfilled }) {
385
+ const patchResult = dispatch(
386
+ documentApi.util.updateQueryData("getDocument", patch, (draft) => {
387
+ Object.assign(draft.data, data);
388
+ })
389
+ );
390
+ try {
391
+ await queryFulfilled;
392
+ } catch {
393
+ patchResult.undo();
394
+ }
400
395
  }
401
396
  }),
402
397
  unpublishDocument: builder.mutation({
@@ -466,7 +461,7 @@ const buildValidParams = (query) => {
466
461
  const isBaseQueryError = (error) => {
467
462
  return error.name !== void 0;
468
463
  };
469
- const createYupSchema = (attributes = {}, components = {}) => {
464
+ const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
470
465
  const createModelSchema = (attributes2) => yup.object().shape(
471
466
  Object.entries(attributes2).reduce((acc, [name, attribute]) => {
472
467
  if (DOCUMENT_META_FIELDS.includes(name)) {
@@ -479,7 +474,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
479
474
  addMinValidation,
480
475
  addMaxValidation,
481
476
  addRegexValidation
482
- ].map((fn) => fn(attribute));
477
+ ].map((fn) => fn(attribute, options));
483
478
  const transformSchema = pipe(...validations);
484
479
  switch (attribute.type) {
485
480
  case "component": {
@@ -580,6 +575,14 @@ const createAttributeSchema = (attribute) => {
580
575
  if (!value || typeof value === "string" && value.length === 0) {
581
576
  return true;
582
577
  }
578
+ if (typeof value === "object") {
579
+ try {
580
+ JSON.stringify(value);
581
+ return true;
582
+ } catch (err) {
583
+ return false;
584
+ }
585
+ }
583
586
  try {
584
587
  JSON.parse(value);
585
588
  return true;
@@ -598,13 +601,7 @@ const createAttributeSchema = (attribute) => {
598
601
  return yup.mixed();
599
602
  }
600
603
  };
601
- const addRequiredValidation = (attribute) => (schema) => {
602
- if (attribute.required) {
603
- return schema.required({
604
- id: translatedErrors.required.id,
605
- defaultMessage: "This field is required."
606
- });
607
- }
604
+ const nullableSchema = (schema) => {
608
605
  return schema?.nullable ? schema.nullable() : (
609
606
  // In some cases '.nullable' will not be available on the schema.
610
607
  // e.g. when the schema has been built using yup.lazy (e.g. for relations).
@@ -612,7 +609,22 @@ const addRequiredValidation = (attribute) => (schema) => {
612
609
  schema
613
610
  );
614
611
  };
615
- const addMinLengthValidation = (attribute) => (schema) => {
612
+ const addRequiredValidation = (attribute, options) => (schema) => {
613
+ if (options.status === "draft") {
614
+ return nullableSchema(schema);
615
+ }
616
+ if ((attribute.type === "component" && attribute.repeatable || attribute.type === "dynamiczone") && attribute.required && "min" in schema) {
617
+ return schema.min(1, translatedErrors.required);
618
+ }
619
+ if (attribute.required && attribute.type !== "relation") {
620
+ return schema.required(translatedErrors.required);
621
+ }
622
+ return nullableSchema(schema);
623
+ };
624
+ const addMinLengthValidation = (attribute, options) => (schema) => {
625
+ if (options.status === "draft") {
626
+ return schema;
627
+ }
616
628
  if ("minLength" in attribute && attribute.minLength && Number.isInteger(attribute.minLength) && "min" in schema) {
617
629
  return schema.min(attribute.minLength, {
618
630
  ...translatedErrors.minLength,
@@ -634,9 +646,31 @@ const addMaxLengthValidation = (attribute) => (schema) => {
634
646
  }
635
647
  return schema;
636
648
  };
637
- const addMinValidation = (attribute) => (schema) => {
649
+ const addMinValidation = (attribute, options) => (schema) => {
638
650
  if ("min" in attribute) {
639
651
  const min = toInteger(attribute.min);
652
+ if (attribute.type === "component" && attribute.repeatable || attribute.type === "dynamiczone") {
653
+ if (options.status !== "draft" && !attribute.required && "test" in schema && min) {
654
+ return schema.test(
655
+ "custom-min",
656
+ {
657
+ ...translatedErrors.min,
658
+ values: {
659
+ min: attribute.min
660
+ }
661
+ },
662
+ (value) => {
663
+ if (!value) {
664
+ return true;
665
+ }
666
+ if (Array.isArray(value) && value.length === 0) {
667
+ return true;
668
+ }
669
+ return value.length >= min;
670
+ }
671
+ );
672
+ }
673
+ }
640
674
  if ("min" in schema && min) {
641
675
  return schema.min(min, {
642
676
  ...translatedErrors.min,
@@ -763,7 +797,10 @@ const useDocument = (args, opts) => {
763
797
  isLoading: isLoadingDocument,
764
798
  isFetching: isFetchingDocument,
765
799
  error
766
- } = useGetDocumentQuery(args, opts);
800
+ } = useGetDocumentQuery(args, {
801
+ ...opts,
802
+ skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
803
+ });
767
804
  const { components, schema, isLoading: isLoadingSchema } = useContentTypeSchema(args.model);
768
805
  React.useEffect(() => {
769
806
  if (error) {
@@ -849,6 +886,7 @@ const useDocumentActions = () => {
849
886
  const { formatMessage } = useIntl();
850
887
  const { trackUsage } = useTracking();
851
888
  const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
889
+ const navigate = useNavigate();
852
890
  const [deleteDocument] = useDeleteDocumentMutation();
853
891
  const _delete = React.useCallback(
854
892
  async ({ collectionType, model, documentId, params }, trackerProperty) => {
@@ -1184,7 +1222,6 @@ const useDocumentActions = () => {
1184
1222
  sourceId
1185
1223
  });
1186
1224
  if ("error" in res) {
1187
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1188
1225
  return { error: res.error };
1189
1226
  }
1190
1227
  toggleNotification({
@@ -1203,7 +1240,7 @@ const useDocumentActions = () => {
1203
1240
  throw err;
1204
1241
  }
1205
1242
  },
1206
- [autoCloneDocument, formatAPIError, formatMessage, toggleNotification]
1243
+ [autoCloneDocument, formatMessage, toggleNotification]
1207
1244
  );
1208
1245
  const [cloneDocument] = useCloneDocumentMutation();
1209
1246
  const clone = React.useCallback(
@@ -1229,6 +1266,7 @@ const useDocumentActions = () => {
1229
1266
  defaultMessage: "Cloned document"
1230
1267
  })
1231
1268
  });
1269
+ navigate(`../../${res.data.data.documentId}`, { relative: "path" });
1232
1270
  return res.data;
1233
1271
  } catch (err) {
1234
1272
  toggleNotification({
@@ -1239,7 +1277,7 @@ const useDocumentActions = () => {
1239
1277
  throw err;
1240
1278
  }
1241
1279
  },
1242
- [cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError]
1280
+ [cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError, navigate]
1243
1281
  );
1244
1282
  const [getDoc] = useLazyGetDocumentQuery();
1245
1283
  const getDocument = React.useCallback(
@@ -1265,7 +1303,7 @@ const useDocumentActions = () => {
1265
1303
  };
1266
1304
  };
1267
1305
  const ProtectedHistoryPage = lazy(
1268
- () => import("./History-Bu53Yfw-.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
1306
+ () => import("./History-BMunT-do.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
1269
1307
  );
1270
1308
  const routes$1 = [
1271
1309
  {
@@ -1278,31 +1316,31 @@ const routes$1 = [
1278
1316
  }
1279
1317
  ];
1280
1318
  const ProtectedEditViewPage = lazy(
1281
- () => import("./EditViewPage-CzuJgWWp.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
1319
+ () => import("./EditViewPage-DeTn7rAF.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
1282
1320
  );
1283
1321
  const ProtectedListViewPage = lazy(
1284
- () => import("./ListViewPage-BO_mOXIl.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
1322
+ () => import("./ListViewPage-_5gS-DOF.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
1285
1323
  );
1286
1324
  const ProtectedListConfiguration = lazy(
1287
- () => import("./ListConfigurationPage-TqrmwjPN.mjs").then((mod) => ({
1325
+ () => import("./ListConfigurationPage-CDqkCxgV.mjs").then((mod) => ({
1288
1326
  default: mod.ProtectedListConfiguration
1289
1327
  }))
1290
1328
  );
1291
1329
  const ProtectedEditConfigurationPage = lazy(
1292
- () => import("./EditConfigurationPage-CZLbgfIp.mjs").then((mod) => ({
1330
+ () => import("./EditConfigurationPage-CE_yavTi.mjs").then((mod) => ({
1293
1331
  default: mod.ProtectedEditConfigurationPage
1294
1332
  }))
1295
1333
  );
1296
1334
  const ProtectedComponentConfigurationPage = lazy(
1297
- () => import("./ComponentConfigurationPage-Cxz51Sve.mjs").then((mod) => ({
1335
+ () => import("./ComponentConfigurationPage-CpBFh6_r.mjs").then((mod) => ({
1298
1336
  default: mod.ProtectedComponentConfigurationPage
1299
1337
  }))
1300
1338
  );
1301
1339
  const NoPermissions = lazy(
1302
- () => import("./NoPermissionsPage-DTXi042N.mjs").then((mod) => ({ default: mod.NoPermissions }))
1340
+ () => import("./NoPermissionsPage-Bs8D5W_v.mjs").then((mod) => ({ default: mod.NoPermissions }))
1303
1341
  );
1304
1342
  const NoContentType = lazy(
1305
- () => import("./NoContentTypePage-DqB0QV0k.mjs").then((mod) => ({ default: mod.NoContentType }))
1343
+ () => import("./NoContentTypePage-Dht-55hr.mjs").then((mod) => ({ default: mod.NoContentType }))
1306
1344
  );
1307
1345
  const CollectionTypePages = () => {
1308
1346
  const { collectionType } = useParams();
@@ -1416,12 +1454,14 @@ const DocumentActionButton = (action) => {
1416
1454
  /* @__PURE__ */ jsx(
1417
1455
  Button,
1418
1456
  {
1419
- flex: 1,
1457
+ flex: "auto",
1420
1458
  startIcon: action.icon,
1421
1459
  disabled: action.disabled,
1422
1460
  onClick: handleClick(action),
1423
1461
  justifyContent: "center",
1424
1462
  variant: action.variant || "default",
1463
+ paddingTop: "7px",
1464
+ paddingBottom: "7px",
1425
1465
  children: action.label
1426
1466
  }
1427
1467
  ),
@@ -1429,7 +1469,7 @@ const DocumentActionButton = (action) => {
1429
1469
  DocumentActionConfirmDialog,
1430
1470
  {
1431
1471
  ...action.dialog,
1432
- variant: action.variant,
1472
+ variant: action.dialog?.variant ?? action.variant,
1433
1473
  isOpen: dialogId === action.id,
1434
1474
  onClose: handleClose
1435
1475
  }
@@ -1486,9 +1526,9 @@ const DocumentActionsMenu = ({
1486
1526
  disabled: isDisabled,
1487
1527
  size: "S",
1488
1528
  endIcon: null,
1489
- paddingTop: "7px",
1490
- paddingLeft: "9px",
1491
- paddingRight: "9px",
1529
+ paddingTop: "4px",
1530
+ paddingLeft: "7px",
1531
+ paddingRight: "7px",
1492
1532
  variant,
1493
1533
  children: [
1494
1534
  /* @__PURE__ */ jsx(More, { "aria-hidden": true, focusable: false }),
@@ -1508,10 +1548,25 @@ const DocumentActionsMenu = ({
1508
1548
  onSelect: handleClick(action),
1509
1549
  display: "block",
1510
1550
  children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", gap: 4, children: [
1511
- /* @__PURE__ */ jsxs(Flex, { color: convertActionVariantToColor(action.variant), gap: 2, tag: "span", children: [
1512
- action.icon,
1513
- action.label
1514
- ] }),
1551
+ /* @__PURE__ */ jsxs(
1552
+ Flex,
1553
+ {
1554
+ color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
1555
+ gap: 2,
1556
+ tag: "span",
1557
+ children: [
1558
+ /* @__PURE__ */ jsx(
1559
+ Flex,
1560
+ {
1561
+ tag: "span",
1562
+ color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
1563
+ children: action.icon
1564
+ }
1565
+ ),
1566
+ action.label
1567
+ ]
1568
+ }
1569
+ ),
1515
1570
  action.id.startsWith("HistoryAction") && /* @__PURE__ */ jsx(
1516
1571
  Flex,
1517
1572
  {
@@ -1570,6 +1625,18 @@ const convertActionVariantToColor = (variant = "secondary") => {
1570
1625
  return "primary600";
1571
1626
  }
1572
1627
  };
1628
+ const convertActionVariantToIconColor = (variant = "secondary") => {
1629
+ switch (variant) {
1630
+ case "danger":
1631
+ return "danger600";
1632
+ case "secondary":
1633
+ return "neutral500";
1634
+ case "success":
1635
+ return "success600";
1636
+ default:
1637
+ return "primary600";
1638
+ }
1639
+ };
1573
1640
  const DocumentActionConfirmDialog = ({
1574
1641
  onClose,
1575
1642
  onCancel,
@@ -1592,22 +1659,20 @@ const DocumentActionConfirmDialog = ({
1592
1659
  }
1593
1660
  onClose();
1594
1661
  };
1595
- return /* @__PURE__ */ jsxs(Dialog, { isOpen, title, onClose: handleClose, children: [
1596
- /* @__PURE__ */ jsx(DialogBody, { children: content }),
1597
- /* @__PURE__ */ jsx(
1598
- DialogFooter,
1599
- {
1600
- startAction: /* @__PURE__ */ jsx(Button, { onClick: handleClose, variant: "tertiary", children: formatMessage({
1601
- id: "app.components.Button.cancel",
1602
- defaultMessage: "Cancel"
1603
- }) }),
1604
- endAction: /* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, children: formatMessage({
1605
- id: "app.components.Button.confirm",
1606
- defaultMessage: "Confirm"
1607
- }) })
1608
- }
1609
- )
1610
- ] });
1662
+ return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
1663
+ /* @__PURE__ */ jsx(Dialog.Header, { children: title }),
1664
+ /* @__PURE__ */ jsx(Dialog.Body, { children: content }),
1665
+ /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
1666
+ /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", fullWidth: true, children: formatMessage({
1667
+ id: "app.components.Button.cancel",
1668
+ defaultMessage: "Cancel"
1669
+ }) }) }),
1670
+ /* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, fullWidth: true, children: formatMessage({
1671
+ id: "app.components.Button.confirm",
1672
+ defaultMessage: "Confirm"
1673
+ }) })
1674
+ ] })
1675
+ ] }) });
1611
1676
  };
1612
1677
  const DocumentActionModal = ({
1613
1678
  isOpen,
@@ -1617,34 +1682,17 @@ const DocumentActionModal = ({
1617
1682
  content: Content,
1618
1683
  onModalClose
1619
1684
  }) => {
1620
- const id = React.useId();
1621
- if (!isOpen) {
1622
- return null;
1623
- }
1624
1685
  const handleClose = () => {
1625
1686
  if (onClose) {
1626
1687
  onClose();
1627
1688
  }
1628
1689
  onModalClose();
1629
1690
  };
1630
- return /* @__PURE__ */ jsxs(ModalLayout, { borderRadius: "4px", overflow: "hidden", onClose: handleClose, labelledBy: id, children: [
1631
- /* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: "neutral800", tag: "h2", id, children: title }) }),
1632
- /* @__PURE__ */ jsx(ModalBody, { children: typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : Content }),
1633
- /* @__PURE__ */ jsx(
1634
- Box,
1635
- {
1636
- paddingTop: 4,
1637
- paddingBottom: 4,
1638
- paddingLeft: 5,
1639
- paddingRight: 5,
1640
- borderWidth: "1px 0 0 0",
1641
- borderStyle: "solid",
1642
- borderColor: "neutral150",
1643
- background: "neutral100",
1644
- children: typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
1645
- }
1646
- )
1647
- ] });
1691
+ return /* @__PURE__ */ jsx(Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Modal.Content, { children: [
1692
+ /* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: title }) }),
1693
+ typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsx(Modal.Body, { children: Content }),
1694
+ typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
1695
+ ] }) });
1648
1696
  };
1649
1697
  const PublishAction$1 = ({
1650
1698
  activeTab,
@@ -1658,13 +1706,17 @@ const PublishAction$1 = ({
1658
1706
  const navigate = useNavigate();
1659
1707
  const { toggleNotification } = useNotification();
1660
1708
  const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
1709
+ const isListView = useMatch(LIST_PATH) !== null;
1661
1710
  const isCloning = useMatch(CLONE_PATH) !== null;
1662
1711
  const { formatMessage } = useIntl();
1663
- const { canPublish, canCreate, canUpdate } = useDocumentRBAC(
1664
- "PublishAction",
1665
- ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 }) => ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 })
1666
- );
1712
+ const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
1667
1713
  const { publish } = useDocumentActions();
1714
+ const [
1715
+ countDraftRelations,
1716
+ { isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
1717
+ ] = useLazyGetDraftRelationCountQuery();
1718
+ const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React.useState(0);
1719
+ const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React.useState(0);
1668
1720
  const [{ query, rawQuery }] = useQueryParams();
1669
1721
  const params = React.useMemo(() => buildValidParams(query), [query]);
1670
1722
  const modified = useForm("PublishAction", ({ modified: modified2 }) => modified2);
@@ -1673,10 +1725,103 @@ const PublishAction$1 = ({
1673
1725
  const validate = useForm("PublishAction", (state) => state.validate);
1674
1726
  const setErrors = useForm("PublishAction", (state) => state.setErrors);
1675
1727
  const formValues = useForm("PublishAction", ({ values }) => values);
1728
+ React.useEffect(() => {
1729
+ if (isErrorDraftRelations) {
1730
+ toggleNotification({
1731
+ type: "danger",
1732
+ message: formatMessage({
1733
+ id: getTranslation("error.records.fetch-draft-relatons"),
1734
+ defaultMessage: "An error occurred while fetching draft relations on this document."
1735
+ })
1736
+ });
1737
+ }
1738
+ }, [isErrorDraftRelations, toggleNotification, formatMessage]);
1739
+ React.useEffect(() => {
1740
+ const localDraftRelations = /* @__PURE__ */ new Set();
1741
+ const extractDraftRelations = (data) => {
1742
+ const relations = data.connect || [];
1743
+ relations.forEach((relation) => {
1744
+ if (relation.status === "draft") {
1745
+ localDraftRelations.add(relation.id);
1746
+ }
1747
+ });
1748
+ };
1749
+ const traverseAndExtract = (data) => {
1750
+ Object.entries(data).forEach(([key, value]) => {
1751
+ if (key === "connect" && Array.isArray(value)) {
1752
+ extractDraftRelations({ connect: value });
1753
+ } else if (typeof value === "object" && value !== null) {
1754
+ traverseAndExtract(value);
1755
+ }
1756
+ });
1757
+ };
1758
+ if (!documentId || modified) {
1759
+ traverseAndExtract(formValues);
1760
+ setLocalCountOfDraftRelations(localDraftRelations.size);
1761
+ }
1762
+ }, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
1763
+ React.useEffect(() => {
1764
+ if (!document || !document.documentId || isListView) {
1765
+ return;
1766
+ }
1767
+ const fetchDraftRelationsCount = async () => {
1768
+ const { data, error } = await countDraftRelations({
1769
+ collectionType,
1770
+ model,
1771
+ documentId,
1772
+ params
1773
+ });
1774
+ if (error) {
1775
+ throw error;
1776
+ }
1777
+ if (data) {
1778
+ setServerCountOfDraftRelations(data.data);
1779
+ }
1780
+ };
1781
+ fetchDraftRelationsCount();
1782
+ }, [isListView, document, documentId, countDraftRelations, collectionType, model, params]);
1676
1783
  const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
1677
1784
  if (!schema?.options?.draftAndPublish) {
1678
1785
  return null;
1679
1786
  }
1787
+ const performPublish = async () => {
1788
+ setSubmitting(true);
1789
+ try {
1790
+ const { errors } = await validate();
1791
+ if (errors) {
1792
+ toggleNotification({
1793
+ type: "danger",
1794
+ message: formatMessage({
1795
+ id: "content-manager.validation.error",
1796
+ defaultMessage: "There are validation errors in your document. Please fix them before saving."
1797
+ })
1798
+ });
1799
+ return;
1800
+ }
1801
+ const res = await publish(
1802
+ {
1803
+ collectionType,
1804
+ model,
1805
+ documentId,
1806
+ params
1807
+ },
1808
+ formValues
1809
+ );
1810
+ if ("data" in res && collectionType !== SINGLE_TYPES) {
1811
+ navigate({
1812
+ pathname: `../${collectionType}/${model}/${res.data.documentId}`,
1813
+ search: rawQuery
1814
+ });
1815
+ } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1816
+ setErrors(formatValidationErrors(res.error));
1817
+ }
1818
+ } finally {
1819
+ setSubmitting(false);
1820
+ }
1821
+ };
1822
+ const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
1823
+ const enableDraftRelationsCount = false;
1824
+ const hasDraftRelations = enableDraftRelationsCount;
1680
1825
  return {
1681
1826
  /**
1682
1827
  * Disabled when:
@@ -1686,49 +1831,36 @@ const PublishAction$1 = ({
1686
1831
  * - the document is already published & not modified
1687
1832
  * - the document is being created & not modified
1688
1833
  * - the user doesn't have the permission to publish
1689
- * - the user doesn't have the permission to create a new document
1690
- * - the user doesn't have the permission to update the document
1691
1834
  */
1692
- disabled: isCloning || isSubmitting || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish || Boolean(!document?.documentId && !canCreate || document?.documentId && !canUpdate),
1835
+ disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
1693
1836
  label: formatMessage({
1694
1837
  id: "app.utils.publish",
1695
1838
  defaultMessage: "Publish"
1696
1839
  }),
1697
1840
  onClick: async () => {
1698
- setSubmitting(true);
1699
- try {
1700
- const { errors } = await validate();
1701
- if (errors) {
1702
- toggleNotification({
1703
- type: "danger",
1704
- message: formatMessage({
1705
- id: "content-manager.validation.error",
1706
- defaultMessage: "There are validation errors in your document. Please fix them before saving."
1707
- })
1708
- });
1709
- return;
1710
- }
1711
- const res = await publish(
1712
- {
1713
- collectionType,
1714
- model,
1715
- documentId,
1716
- params
1717
- },
1718
- formValues
1719
- );
1720
- if ("data" in res && collectionType !== SINGLE_TYPES) {
1721
- navigate({
1722
- pathname: `../${collectionType}/${model}/${res.data.documentId}`,
1723
- search: rawQuery
1724
- });
1725
- } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1726
- setErrors(formatValidationErrors(res.error));
1841
+ await performPublish();
1842
+ },
1843
+ dialog: hasDraftRelations ? {
1844
+ type: "dialog",
1845
+ variant: "danger",
1846
+ footer: null,
1847
+ title: formatMessage({
1848
+ id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
1849
+ defaultMessage: "Confirmation"
1850
+ }),
1851
+ content: formatMessage(
1852
+ {
1853
+ id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
1854
+ defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
1855
+ },
1856
+ {
1857
+ count: totalDraftRelations
1727
1858
  }
1728
- } finally {
1729
- setSubmitting(false);
1859
+ ),
1860
+ onConfirm: async () => {
1861
+ await performPublish();
1730
1862
  }
1731
- }
1863
+ } : void 0
1732
1864
  };
1733
1865
  };
1734
1866
  PublishAction$1.type = "publish";
@@ -1744,10 +1876,6 @@ const UpdateAction = ({
1744
1876
  const cloneMatch = useMatch(CLONE_PATH);
1745
1877
  const isCloning = cloneMatch !== null;
1746
1878
  const { formatMessage } = useIntl();
1747
- const { canCreate, canUpdate } = useDocumentRBAC("UpdateAction", ({ canCreate: canCreate2, canUpdate: canUpdate2 }) => ({
1748
- canCreate: canCreate2,
1749
- canUpdate: canUpdate2
1750
- }));
1751
1879
  const { create, update, clone } = useDocumentActions();
1752
1880
  const [{ query, rawQuery }] = useQueryParams();
1753
1881
  const params = React.useMemo(() => buildValidParams(query), [query]);
@@ -1764,10 +1892,8 @@ const UpdateAction = ({
1764
1892
  * - the form is submitting
1765
1893
  * - the document is not modified & we're not cloning (you can save a clone entity straight away)
1766
1894
  * - the active tab is the published tab
1767
- * - the user doesn't have the permission to create a new document
1768
- * - the user doesn't have the permission to update the document
1769
1895
  */
1770
- disabled: isSubmitting || !modified && !isCloning || activeTab === "published" || Boolean(!documentId && !canCreate || documentId && !canUpdate),
1896
+ disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
1771
1897
  label: formatMessage({
1772
1898
  id: "content-manager.containers.Edit.save",
1773
1899
  defaultMessage: "Save"
@@ -1775,16 +1901,18 @@ const UpdateAction = ({
1775
1901
  onClick: async () => {
1776
1902
  setSubmitting(true);
1777
1903
  try {
1778
- const { errors } = await validate();
1779
- if (errors) {
1780
- toggleNotification({
1781
- type: "danger",
1782
- message: formatMessage({
1783
- id: "content-manager.validation.error",
1784
- defaultMessage: "There are validation errors in your document. Please fix them before saving."
1785
- })
1786
- });
1787
- return;
1904
+ if (activeTab !== "draft") {
1905
+ const { errors } = await validate();
1906
+ if (errors) {
1907
+ toggleNotification({
1908
+ type: "danger",
1909
+ message: formatMessage({
1910
+ id: "content-manager.validation.error",
1911
+ defaultMessage: "There are validation errors in your document. Please fix them before saving."
1912
+ })
1913
+ });
1914
+ return;
1915
+ }
1788
1916
  }
1789
1917
  if (isCloning) {
1790
1918
  const res = await clone(
@@ -1796,10 +1924,13 @@ const UpdateAction = ({
1796
1924
  document
1797
1925
  );
1798
1926
  if ("data" in res) {
1799
- navigate({
1800
- pathname: `../${collectionType}/${model}/${res.data.documentId}`,
1801
- search: rawQuery
1802
- });
1927
+ navigate(
1928
+ {
1929
+ pathname: `../${res.data.documentId}`,
1930
+ search: rawQuery
1931
+ },
1932
+ { relative: "path" }
1933
+ );
1803
1934
  } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1804
1935
  setErrors(formatValidationErrors(res.error));
1805
1936
  }
@@ -1827,10 +1958,13 @@ const UpdateAction = ({
1827
1958
  document
1828
1959
  );
1829
1960
  if ("data" in res && collectionType !== SINGLE_TYPES) {
1830
- navigate({
1831
- pathname: `../${collectionType}/${model}/${res.data.documentId}`,
1832
- search: rawQuery
1833
- });
1961
+ navigate(
1962
+ {
1963
+ pathname: `../${res.data.documentId}`,
1964
+ search: rawQuery
1965
+ },
1966
+ { replace: true, relative: "path" }
1967
+ );
1834
1968
  } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1835
1969
  setErrors(formatValidationErrors(res.error));
1836
1970
  }
@@ -1862,10 +1996,8 @@ const UnpublishAction$1 = ({
1862
1996
  const { toggleNotification } = useNotification();
1863
1997
  const [shouldKeepDraft, setShouldKeepDraft] = React.useState(true);
1864
1998
  const isDocumentModified = document?.status === "modified";
1865
- const handleChange = (e) => {
1866
- if ("value" in e.target) {
1867
- setShouldKeepDraft(e.target.value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
1868
- }
1999
+ const handleChange = (value) => {
2000
+ setShouldKeepDraft(value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
1869
2001
  };
1870
2002
  if (!schema?.options?.draftAndPublish) {
1871
2003
  return null;
@@ -1876,7 +2008,7 @@ const UnpublishAction$1 = ({
1876
2008
  id: "app.utils.unpublish",
1877
2009
  defaultMessage: "Unpublish"
1878
2010
  }),
1879
- icon: /* @__PURE__ */ jsx(StyledCrossCircle, {}),
2011
+ icon: /* @__PURE__ */ jsx(Cross, {}),
1880
2012
  onClick: async () => {
1881
2013
  if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
1882
2014
  if (!documentId) {
@@ -1915,40 +2047,24 @@ const UnpublishAction$1 = ({
1915
2047
  }) })
1916
2048
  ] }),
1917
2049
  /* @__PURE__ */ jsxs(
1918
- Flex,
2050
+ Radio.Group,
1919
2051
  {
1920
- onChange: handleChange,
1921
- direction: "column",
1922
- alignItems: "flex-start",
1923
- tag: "fieldset",
1924
- borderWidth: 0,
1925
- gap: 3,
2052
+ defaultValue: UNPUBLISH_DRAFT_OPTIONS.KEEP,
2053
+ name: "discard-options",
2054
+ "aria-label": formatMessage({
2055
+ id: "content-manager.actions.unpublish.dialog.radio-label",
2056
+ defaultMessage: "Choose an option to unpublish the document."
2057
+ }),
2058
+ onValueChange: handleChange,
1926
2059
  children: [
1927
- /* @__PURE__ */ jsx(VisuallyHidden, { tag: "legend" }),
1928
- /* @__PURE__ */ jsx(
1929
- Radio,
1930
- {
1931
- checked: shouldKeepDraft,
1932
- value: UNPUBLISH_DRAFT_OPTIONS.KEEP,
1933
- name: "discard-options",
1934
- children: formatMessage({
1935
- id: "content-manager.actions.unpublish.dialog.option.keep-draft",
1936
- defaultMessage: "Keep draft"
1937
- })
1938
- }
1939
- ),
1940
- /* @__PURE__ */ jsx(
1941
- Radio,
1942
- {
1943
- checked: !shouldKeepDraft,
1944
- value: UNPUBLISH_DRAFT_OPTIONS.DISCARD,
1945
- name: "discard-options",
1946
- children: formatMessage({
1947
- id: "content-manager.actions.unpublish.dialog.option.replace-draft",
1948
- defaultMessage: "Replace draft"
1949
- })
1950
- }
1951
- )
2060
+ /* @__PURE__ */ jsx(Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
2061
+ id: "content-manager.actions.unpublish.dialog.option.keep-draft",
2062
+ defaultMessage: "Keep draft"
2063
+ }) }),
2064
+ /* @__PURE__ */ jsx(Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
2065
+ id: "content-manager.actions.unpublish.dialog.option.replace-draft",
2066
+ defaultMessage: "Replace draft"
2067
+ }) })
1952
2068
  ]
1953
2069
  }
1954
2070
  )
@@ -2004,7 +2120,7 @@ const DiscardAction = ({
2004
2120
  id: "content-manager.actions.discard.label",
2005
2121
  defaultMessage: "Discard changes"
2006
2122
  }),
2007
- icon: /* @__PURE__ */ jsx(StyledCrossCircle, {}),
2123
+ icon: /* @__PURE__ */ jsx(Cross, {}),
2008
2124
  position: ["panel", "table-row"],
2009
2125
  variant: "danger",
2010
2126
  dialog: {
@@ -2032,11 +2148,6 @@ const DiscardAction = ({
2032
2148
  };
2033
2149
  };
2034
2150
  DiscardAction.type = "discard";
2035
- const StyledCrossCircle = styled(CrossCircle)`
2036
- path {
2037
- fill: currentColor;
2038
- }
2039
- `;
2040
2151
  const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
2041
2152
  const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
2042
2153
  const RelativeTime = React.forwardRef(
@@ -2084,7 +2195,7 @@ const getDisplayName = ({
2084
2195
  };
2085
2196
  const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
2086
2197
  const DocumentStatus = ({ status = "draft", ...restProps }) => {
2087
- const statusVariant = status === "draft" ? "primary" : status === "published" ? "success" : "alternative";
2198
+ const statusVariant = status === "draft" ? "secondary" : status === "published" ? "success" : "alternative";
2088
2199
  return /* @__PURE__ */ jsx(Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsx(Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: capitalise(status) }) });
2089
2200
  };
2090
2201
  const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
@@ -2094,23 +2205,13 @@ const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
2094
2205
  id: "content-manager.containers.edit.title.new",
2095
2206
  defaultMessage: "Create an entry"
2096
2207
  }) : documentTitle;
2097
- return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop: 8, paddingBottom: 4, gap: 3, children: [
2208
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
2098
2209
  /* @__PURE__ */ jsx(BackButton, {}),
2099
- /* @__PURE__ */ jsxs(
2100
- Flex,
2101
- {
2102
- width: "100%",
2103
- justifyContent: "space-between",
2104
- paddingTop: 1,
2105
- gap: "80px",
2106
- alignItems: "flex-start",
2107
- children: [
2108
- /* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
2109
- /* @__PURE__ */ jsx(HeaderToolbar, {})
2110
- ]
2111
- }
2112
- ),
2113
- status ? /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) : null
2210
+ /* @__PURE__ */ jsxs(Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
2211
+ /* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
2212
+ /* @__PURE__ */ jsx(HeaderToolbar, {})
2213
+ ] }),
2214
+ status ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
2114
2215
  ] });
2115
2216
  };
2116
2217
  const HeaderToolbar = () => {
@@ -2277,8 +2378,22 @@ const Information = ({ activeTab }) => {
2277
2378
  );
2278
2379
  };
2279
2380
  const HeaderActions = ({ actions: actions2 }) => {
2280
- return /* @__PURE__ */ jsx(Flex, { children: actions2.map((action) => {
2281
- if ("options" in action) {
2381
+ const [dialogId, setDialogId] = React.useState(null);
2382
+ const handleClick = (action) => async (e) => {
2383
+ if (!("options" in action)) {
2384
+ const { onClick = () => false, dialog, id } = action;
2385
+ const muteDialog = await onClick(e);
2386
+ if (dialog && !muteDialog) {
2387
+ e.preventDefault();
2388
+ setDialogId(id);
2389
+ }
2390
+ }
2391
+ };
2392
+ const handleClose = () => {
2393
+ setDialogId(null);
2394
+ };
2395
+ return /* @__PURE__ */ jsx(Flex, { gap: 1, children: actions2.map((action) => {
2396
+ if (action.options) {
2282
2397
  return /* @__PURE__ */ jsx(
2283
2398
  SingleSelect,
2284
2399
  {
@@ -2292,10 +2407,49 @@ const HeaderActions = ({ actions: actions2 }) => {
2292
2407
  action.id
2293
2408
  );
2294
2409
  } else {
2295
- return null;
2410
+ if (action.type === "icon") {
2411
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [
2412
+ /* @__PURE__ */ jsx(
2413
+ IconButton,
2414
+ {
2415
+ disabled: action.disabled,
2416
+ label: action.label,
2417
+ size: "S",
2418
+ onClick: handleClick(action),
2419
+ children: action.icon
2420
+ }
2421
+ ),
2422
+ action.dialog ? /* @__PURE__ */ jsx(
2423
+ HeaderActionDialog,
2424
+ {
2425
+ ...action.dialog,
2426
+ isOpen: dialogId === action.id,
2427
+ onClose: handleClose
2428
+ }
2429
+ ) : null
2430
+ ] }, action.id);
2431
+ }
2296
2432
  }
2297
2433
  }) });
2298
2434
  };
2435
+ const HeaderActionDialog = ({
2436
+ onClose,
2437
+ onCancel,
2438
+ title,
2439
+ content: Content,
2440
+ isOpen
2441
+ }) => {
2442
+ const handleClose = async () => {
2443
+ if (onCancel) {
2444
+ await onCancel();
2445
+ }
2446
+ onClose();
2447
+ };
2448
+ return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
2449
+ /* @__PURE__ */ jsx(Dialog.Header, { children: title }),
2450
+ typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : Content
2451
+ ] }) });
2452
+ };
2299
2453
  const ConfigureTheViewAction = ({ collectionType, model }) => {
2300
2454
  const navigate = useNavigate();
2301
2455
  const { formatMessage } = useIntl();
@@ -2431,7 +2585,7 @@ const ActionsPanel = () => {
2431
2585
  return {
2432
2586
  title: formatMessage({
2433
2587
  id: "content-manager.containers.edit.panels.default.title",
2434
- defaultMessage: "Document"
2588
+ defaultMessage: "Entry"
2435
2589
  }),
2436
2590
  content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
2437
2591
  };
@@ -2675,7 +2829,8 @@ const formatEditLayout = (data, {
2675
2829
  layout: convertEditLayoutToFieldLayouts(
2676
2830
  configuration.layouts.edit,
2677
2831
  components[uid].attributes,
2678
- configuration.metadatas
2832
+ configuration.metadatas,
2833
+ { configurations: data.components, schemas: components }
2679
2834
  ),
2680
2835
  settings: {
2681
2836
  ...configuration.settings,
@@ -2801,30 +2956,23 @@ const ConfirmBulkActionDialog = ({
2801
2956
  endAction
2802
2957
  }) => {
2803
2958
  const { formatMessage } = useIntl();
2804
- return /* @__PURE__ */ jsxs(
2805
- Dialog,
2806
- {
2807
- onClose: onToggleDialog,
2808
- title: formatMessage({
2809
- id: "app.components.ConfirmDialog.title",
2810
- defaultMessage: "Confirmation"
2811
- }),
2812
- isOpen,
2813
- children: [
2814
- /* @__PURE__ */ jsx(DialogBody, { icon: /* @__PURE__ */ jsx(WarningCircle, {}), children: /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: dialogBody }) }),
2815
- /* @__PURE__ */ jsx(
2816
- DialogFooter,
2817
- {
2818
- startAction: /* @__PURE__ */ jsx(Button, { onClick: onToggleDialog, variant: "tertiary", children: formatMessage({
2819
- id: "app.components.Button.cancel",
2820
- defaultMessage: "Cancel"
2821
- }) }),
2822
- endAction
2823
- }
2824
- )
2825
- ]
2826
- }
2827
- );
2959
+ return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
2960
+ /* @__PURE__ */ jsx(Dialog.Header, { children: formatMessage({
2961
+ id: "app.components.ConfirmDialog.title",
2962
+ defaultMessage: "Confirmation"
2963
+ }) }),
2964
+ /* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
2965
+ /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
2966
+ dialogBody
2967
+ ] }) }),
2968
+ /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
2969
+ /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { fullWidth: true, onClick: onToggleDialog, variant: "tertiary", children: formatMessage({
2970
+ id: "app.components.Button.cancel",
2971
+ defaultMessage: "Cancel"
2972
+ }) }) }),
2973
+ endAction
2974
+ ] })
2975
+ ] }) });
2828
2976
  };
2829
2977
  const BoldChunk$1 = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: chunks });
2830
2978
  const ConfirmDialogPublishAll = ({
@@ -2839,6 +2987,7 @@ const ConfirmDialogPublishAll = ({
2839
2987
  const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler(getTranslation);
2840
2988
  const { model, schema } = useDoc();
2841
2989
  const [{ query }] = useQueryParams();
2990
+ const enableDraftRelationsCount = false;
2842
2991
  const {
2843
2992
  data: countDraftRelations = 0,
2844
2993
  isLoading,
@@ -2850,7 +2999,7 @@ const ConfirmDialogPublishAll = ({
2850
2999
  locale: query?.plugins?.i18n?.locale
2851
3000
  },
2852
3001
  {
2853
- skip: selectedEntries.length === 0
3002
+ skip: !enableDraftRelationsCount
2854
3003
  }
2855
3004
  );
2856
3005
  React.useEffect(() => {
@@ -2929,7 +3078,14 @@ const formatErrorMessages = (errors, parentKey, formatMessage) => {
2929
3078
  )
2930
3079
  );
2931
3080
  } else {
2932
- messages.push(...formatErrorMessages(value, currentKey, formatMessage));
3081
+ messages.push(
3082
+ ...formatErrorMessages(
3083
+ // @ts-expect-error TODO: check why value is not compatible with FormErrors
3084
+ value,
3085
+ currentKey,
3086
+ formatMessage
3087
+ )
3088
+ );
2933
3089
  }
2934
3090
  } else {
2935
3091
  messages.push(
@@ -3028,7 +3184,7 @@ const SelectedEntriesTableContent = ({
3028
3184
  status: row.status
3029
3185
  }
3030
3186
  ) }),
3031
- /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(
3187
+ /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
3032
3188
  IconButton,
3033
3189
  {
3034
3190
  tag: Link,
@@ -3051,9 +3207,10 @@ const SelectedEntriesTableContent = ({
3051
3207
  ),
3052
3208
  target: "_blank",
3053
3209
  marginLeft: "auto",
3054
- children: /* @__PURE__ */ jsx(Pencil, {})
3210
+ variant: "ghost",
3211
+ children: /* @__PURE__ */ jsx(Pencil, { width: "1.6rem", height: "1.6rem" })
3055
3212
  }
3056
- ) })
3213
+ ) }) })
3057
3214
  ] }, row.id)) })
3058
3215
  ] });
3059
3216
  };
@@ -3090,7 +3247,13 @@ const SelectedEntriesModalContent = ({
3090
3247
  );
3091
3248
  const { rows, validationErrors } = React.useMemo(() => {
3092
3249
  if (data.length > 0 && schema) {
3093
- const validate = createYupSchema(schema.attributes, components);
3250
+ const validate = createYupSchema(
3251
+ schema.attributes,
3252
+ components,
3253
+ // Since this is the "Publish" action, the validation
3254
+ // schema must enforce the rules for published entities
3255
+ { status: "published" }
3256
+ );
3094
3257
  const validationErrors2 = {};
3095
3258
  const rows2 = data.map((entry) => {
3096
3259
  try {
@@ -3166,7 +3329,7 @@ const SelectedEntriesModalContent = ({
3166
3329
  );
3167
3330
  };
3168
3331
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3169
- /* @__PURE__ */ jsxs(ModalBody, { children: [
3332
+ /* @__PURE__ */ jsxs(Modal.Body, { children: [
3170
3333
  /* @__PURE__ */ jsx(Typography, { children: getFormattedCountMessage() }),
3171
3334
  /* @__PURE__ */ jsx(Box, { marginTop: 5, children: /* @__PURE__ */ jsx(
3172
3335
  SelectedEntriesTableContent,
@@ -3178,27 +3341,24 @@ const SelectedEntriesModalContent = ({
3178
3341
  }
3179
3342
  ) })
3180
3343
  ] }),
3181
- /* @__PURE__ */ jsx(
3182
- ModalFooter,
3183
- {
3184
- startActions: /* @__PURE__ */ jsx(Button, { onClick: toggleModal, variant: "tertiary", children: formatMessage({
3185
- id: "app.components.Button.cancel",
3186
- defaultMessage: "Cancel"
3187
- }) }),
3188
- endActions: /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3189
- /* @__PURE__ */ jsx(Button, { onClick: refetch, variant: "tertiary", loading: isFetching, children: formatMessage({ id: "app.utils.refresh", defaultMessage: "Refresh" }) }),
3190
- /* @__PURE__ */ jsx(
3191
- Button,
3192
- {
3193
- onClick: toggleDialog,
3194
- disabled: selectedEntries.length === 0 || selectedEntries.length === selectedEntriesWithErrorsCount || selectedEntriesPublished === selectedEntries.length || isLoading,
3195
- loading: isSubmittingForm,
3196
- children: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" })
3197
- }
3198
- )
3199
- ] })
3200
- }
3201
- ),
3344
+ /* @__PURE__ */ jsxs(Modal.Footer, { children: [
3345
+ /* @__PURE__ */ jsx(Button, { onClick: toggleModal, variant: "tertiary", children: formatMessage({
3346
+ id: "app.components.Button.cancel",
3347
+ defaultMessage: "Cancel"
3348
+ }) }),
3349
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3350
+ /* @__PURE__ */ jsx(Button, { onClick: refetch, variant: "tertiary", loading: isFetching, children: formatMessage({ id: "app.utils.refresh", defaultMessage: "Refresh" }) }),
3351
+ /* @__PURE__ */ jsx(
3352
+ Button,
3353
+ {
3354
+ onClick: toggleDialog,
3355
+ disabled: selectedEntries.length === 0 || selectedEntries.length === selectedEntriesWithErrorsCount || selectedEntriesPublished === selectedEntries.length || isLoading,
3356
+ loading: isSubmittingForm,
3357
+ children: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" })
3358
+ }
3359
+ )
3360
+ ] })
3361
+ ] }),
3202
3362
  /* @__PURE__ */ jsx(
3203
3363
  ConfirmDialogPublishAll,
3204
3364
  {
@@ -3263,143 +3423,10 @@ const BulkActionsRenderer = () => {
3263
3423
  documents: selectedRows
3264
3424
  },
3265
3425
  descriptions: plugins["content-manager"].apis.getBulkActions(),
3266
- children: (actions2) => actions2.map((action) => /* @__PURE__ */ jsx(BulkActionAction, { ...action }, action.id))
3426
+ children: (actions2) => actions2.map((action) => /* @__PURE__ */ jsx(DocumentActionButton, { ...action }, action.id))
3267
3427
  }
3268
3428
  ) });
3269
3429
  };
3270
- const BulkActionAction = (action) => {
3271
- const [dialogId, setDialogId] = React.useState(null);
3272
- const { toggleNotification } = useNotification();
3273
- const handleClick = (action2) => (e) => {
3274
- const { onClick, dialog, id } = action2;
3275
- if (onClick) {
3276
- onClick(e);
3277
- }
3278
- if (dialog) {
3279
- switch (dialog.type) {
3280
- case "notification":
3281
- toggleNotification({
3282
- title: dialog.title,
3283
- message: dialog.content,
3284
- type: dialog.status,
3285
- timeout: dialog.timeout,
3286
- onClose: dialog.onClose
3287
- });
3288
- break;
3289
- case "dialog":
3290
- case "modal": {
3291
- e.preventDefault();
3292
- setDialogId(id);
3293
- }
3294
- }
3295
- }
3296
- };
3297
- const handleClose = () => {
3298
- setDialogId(null);
3299
- if (action.dialog?.type === "modal" && action.dialog?.onClose) {
3300
- action.dialog.onClose();
3301
- }
3302
- };
3303
- return /* @__PURE__ */ jsxs(Fragment, { children: [
3304
- /* @__PURE__ */ jsx(
3305
- Button,
3306
- {
3307
- disabled: action.disabled,
3308
- startIcon: action.icon,
3309
- variant: action.variant,
3310
- onClick: handleClick(action),
3311
- children: action.label
3312
- }
3313
- ),
3314
- action.dialog?.type === "dialog" ? /* @__PURE__ */ jsx(
3315
- BulkActionConfirmDialog,
3316
- {
3317
- ...action.dialog,
3318
- variant: action.variant,
3319
- isOpen: dialogId === action.id,
3320
- onClose: handleClose
3321
- }
3322
- ) : null,
3323
- action.dialog?.type === "modal" ? /* @__PURE__ */ jsx(
3324
- BulkActionModal,
3325
- {
3326
- ...action.dialog,
3327
- onModalClose: handleClose,
3328
- isOpen: dialogId === action.id
3329
- }
3330
- ) : null
3331
- ] });
3332
- };
3333
- const BulkActionConfirmDialog = ({
3334
- onClose,
3335
- onCancel,
3336
- onConfirm,
3337
- title,
3338
- content,
3339
- confirmButton,
3340
- isOpen,
3341
- variant = "secondary"
3342
- }) => {
3343
- const { formatMessage } = useIntl();
3344
- const handleClose = async () => {
3345
- if (onCancel) {
3346
- await onCancel();
3347
- }
3348
- onClose();
3349
- };
3350
- const handleConfirm = async () => {
3351
- if (onConfirm) {
3352
- await onConfirm();
3353
- }
3354
- onClose();
3355
- };
3356
- return /* @__PURE__ */ jsxs(Dialog, { isOpen, title, onClose: handleClose, children: [
3357
- /* @__PURE__ */ jsx(DialogBody, { icon: /* @__PURE__ */ jsx(WarningCircle, {}), children: content }),
3358
- /* @__PURE__ */ jsx(
3359
- DialogFooter,
3360
- {
3361
- startAction: /* @__PURE__ */ jsx(Button, { onClick: handleClose, variant: "tertiary", children: formatMessage({
3362
- id: "app.components.Button.cancel",
3363
- defaultMessage: "Cancel"
3364
- }) }),
3365
- endAction: /* @__PURE__ */ jsx(
3366
- Button,
3367
- {
3368
- onClick: handleConfirm,
3369
- variant: variant === "danger-light" ? variant : "secondary",
3370
- startIcon: variant === "danger-light" ? /* @__PURE__ */ jsx(Trash, {}) : /* @__PURE__ */ jsx(Check, {}),
3371
- children: confirmButton ? confirmButton : formatMessage({
3372
- id: "app.components.Button.confirm",
3373
- defaultMessage: "Confirm"
3374
- })
3375
- }
3376
- )
3377
- }
3378
- )
3379
- ] });
3380
- };
3381
- const BulkActionModal = ({
3382
- isOpen,
3383
- title,
3384
- onClose,
3385
- content: Content,
3386
- onModalClose
3387
- }) => {
3388
- const id = React.useId();
3389
- if (!isOpen) {
3390
- return null;
3391
- }
3392
- const handleClose = () => {
3393
- if (onClose) {
3394
- onClose();
3395
- }
3396
- onModalClose();
3397
- };
3398
- return /* @__PURE__ */ jsxs(ModalLayout, { borderRadius: "4px", overflow: "hidden", onClose: handleClose, labelledBy: id, children: [
3399
- /* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: "neutral800", tag: "h2", id, children: title }) }),
3400
- /* @__PURE__ */ jsx(Content, { onClose: handleClose })
3401
- ] });
3402
- };
3403
3430
  const DeleteAction = ({ documents, model }) => {
3404
3431
  const { formatMessage } = useIntl();
3405
3432
  const { schema: contentType } = useDoc();
@@ -3432,6 +3459,7 @@ const DeleteAction = ({ documents, model }) => {
3432
3459
  defaultMessage: "Confirmation"
3433
3460
  }),
3434
3461
  content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
3462
+ /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
3435
3463
  /* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
3436
3464
  id: "popUpWarning.bodyMessage.contentType.delete.all",
3437
3465
  defaultMessage: "Are you sure you want to delete these entries?"
@@ -3481,6 +3509,7 @@ const UnpublishAction = ({ documents, model }) => {
3481
3509
  defaultMessage: "Confirmation"
3482
3510
  }),
3483
3511
  content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
3512
+ /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
3484
3513
  /* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
3485
3514
  id: "popUpWarning.bodyMessage.contentType.unpublish.all",
3486
3515
  defaultMessage: "Are you sure you want to unpublish these entries?"
@@ -3574,7 +3603,7 @@ const TableActions = ({ document }) => {
3574
3603
  DescriptionComponentRenderer,
3575
3604
  {
3576
3605
  props,
3577
- descriptions: plugins["content-manager"].apis.getDocumentActions(),
3606
+ descriptions: plugins["content-manager"].apis.getDocumentActions().filter((action) => action.name !== "PublishAction"),
3578
3607
  children: (actions2) => {
3579
3608
  const tableRowActions = actions2.filter((action) => {
3580
3609
  const positions = Array.isArray(action.position) ? action.position : [action.position];
@@ -3685,7 +3714,7 @@ const CloneAction = ({ model, documentId }) => {
3685
3714
  }),
3686
3715
  content: /* @__PURE__ */ jsx(AutoCloneFailureModalBody, { prohibitedFields }),
3687
3716
  footer: ({ onClose }) => {
3688
- return /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", children: [
3717
+ return /* @__PURE__ */ jsxs(Modal.Footer, { children: [
3689
3718
  /* @__PURE__ */ jsx(Button, { onClick: onClose, variant: "tertiary", children: formatMessage({
3690
3719
  id: "cancel",
3691
3720
  defaultMessage: "Cancel"
@@ -3726,8 +3755,7 @@ class ContentManagerPlugin {
3726
3755
  documentActions = [
3727
3756
  ...DEFAULT_ACTIONS,
3728
3757
  ...DEFAULT_TABLE_ROW_ACTIONS,
3729
- ...DEFAULT_HEADER_ACTIONS,
3730
- HistoryAction
3758
+ ...DEFAULT_HEADER_ACTIONS
3731
3759
  ];
3732
3760
  editViewSidePanels = [ActionsPanel];
3733
3761
  headerActions = [];
@@ -3816,6 +3844,52 @@ const getPrintableType = (value) => {
3816
3844
  }
3817
3845
  return nativeType;
3818
3846
  };
3847
+ const HistoryAction = ({ model, document }) => {
3848
+ const { formatMessage } = useIntl();
3849
+ const [{ query }] = useQueryParams();
3850
+ const navigate = useNavigate();
3851
+ const pluginsQueryParams = stringify({ plugins: query.plugins }, { encode: false });
3852
+ if (!window.strapi.features.isEnabled("cms-content-history")) {
3853
+ return null;
3854
+ }
3855
+ return {
3856
+ icon: /* @__PURE__ */ jsx(ClockCounterClockwise, {}),
3857
+ label: formatMessage({
3858
+ id: "content-manager.history.document-action",
3859
+ defaultMessage: "Content History"
3860
+ }),
3861
+ onClick: () => navigate({ pathname: "history", search: pluginsQueryParams }),
3862
+ disabled: (
3863
+ /**
3864
+ * The user is creating a new document.
3865
+ * It hasn't been saved yet, so there's no history to go to
3866
+ */
3867
+ !document || /**
3868
+ * The document has been created but the current dimension has never been saved.
3869
+ * For example, the user is creating a new locale in an existing document,
3870
+ * so there's no history for the document in that locale
3871
+ */
3872
+ !document.id || /**
3873
+ * History is only available for content types created by the user.
3874
+ * These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
3875
+ * which start with `admin::` or `plugin::`
3876
+ */
3877
+ !model.startsWith("api::")
3878
+ ),
3879
+ position: "header"
3880
+ };
3881
+ };
3882
+ HistoryAction.type = "history";
3883
+ const historyAdmin = {
3884
+ bootstrap(app) {
3885
+ const { addDocumentAction } = app.getPlugin("content-manager").apis;
3886
+ addDocumentAction((actions2) => {
3887
+ const indexOfDeleteAction = actions2.findIndex((action) => action.type === "delete");
3888
+ actions2.splice(indexOfDeleteAction, 0, HistoryAction);
3889
+ return actions2;
3890
+ });
3891
+ }
3892
+ };
3819
3893
  const initialState = {
3820
3894
  collectionTypeLinks: [],
3821
3895
  components: [],
@@ -3866,15 +3940,29 @@ const index = {
3866
3940
  defaultMessage: "Content Manager"
3867
3941
  },
3868
3942
  permissions: [],
3869
- Component: () => import("./layout-omucV6TV.mjs").then((mod) => ({ default: mod.Layout })),
3870
3943
  position: 1
3871
3944
  });
3945
+ app.router.addRoute({
3946
+ path: "content-manager/*",
3947
+ lazy: async () => {
3948
+ const { Layout } = await import("./layout-D4HI4_PS.mjs");
3949
+ return {
3950
+ Component: Layout
3951
+ };
3952
+ },
3953
+ children: routes
3954
+ });
3872
3955
  app.registerPlugin(cm.config);
3873
3956
  },
3957
+ bootstrap(app) {
3958
+ if (typeof historyAdmin.bootstrap === "function") {
3959
+ historyAdmin.bootstrap(app);
3960
+ }
3961
+ },
3874
3962
  async registerTrads({ locales }) {
3875
3963
  const importedTrads = await Promise.all(
3876
3964
  locales.map((locale) => {
3877
- 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-9GwRW_ku.mjs"), "./translations/es.json": () => import("./es-CeXiYflN.mjs"), "./translations/eu.json": () => import("./eu-CdALomew.mjs"), "./translations/fr.json": () => import("./fr-CD9VFbPM.mjs"), "./translations/gu.json": () => import("./gu-CNpaMDpH.mjs"), "./translations/hi.json": () => import("./hi-Dwvd04m3.mjs"), "./translations/hu.json": () => import("./hu-CeYvaaO0.mjs"), "./translations/id.json": () => import("./id-BtwA9WJT.mjs"), "./translations/it.json": () => import("./it-BrVPqaf1.mjs"), "./translations/ja.json": () => import("./ja-CtsUxOvk.mjs"), "./translations/ko.json": () => import("./ko-HVQRlfUI.mjs"), "./translations/ml.json": () => import("./ml-BihZwQit.mjs"), "./translations/ms.json": () => import("./ms-m_WjyWx7.mjs"), "./translations/nl.json": () => import("./nl-D4R9gHx5.mjs"), "./translations/pl.json": () => import("./pl-sbx9mSt_.mjs"), "./translations/pt-BR.json": () => import("./pt-BR-C71iDxnh.mjs"), "./translations/pt.json": () => import("./pt-BsaFvS8-.mjs"), "./translations/ru.json": () => import("./ru-BE6A4Exp.mjs"), "./translations/sa.json": () => import("./sa-Dag0k-Z8.mjs"), "./translations/sk.json": () => import("./sk-BFg-R8qJ.mjs"), "./translations/sv.json": () => import("./sv-CUnfWGsh.mjs"), "./translations/th.json": () => import("./th-BqbI8lIT.mjs"), "./translations/tr.json": () => import("./tr-CgeK3wJM.mjs"), "./translations/uk.json": () => import("./uk-CR-zDhAY.mjs"), "./translations/vi.json": () => import("./vi-DUXIk_fw.mjs"), "./translations/zh-Hans.json": () => import("./zh-Hans-BPQcRIyH.mjs"), "./translations/zh.json": () => import("./zh-BWZspA60.mjs") }), `./translations/${locale}.json`).then(({ default: data }) => {
3965
+ 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-CPTj6CjC.mjs"), "./translations/es.json": () => import("./es-CeXiYflN.mjs"), "./translations/eu.json": () => import("./eu-CdALomew.mjs"), "./translations/fr.json": () => import("./fr-CD9VFbPM.mjs"), "./translations/gu.json": () => import("./gu-CNpaMDpH.mjs"), "./translations/hi.json": () => import("./hi-Dwvd04m3.mjs"), "./translations/hu.json": () => import("./hu-CeYvaaO0.mjs"), "./translations/id.json": () => import("./id-BtwA9WJT.mjs"), "./translations/it.json": () => import("./it-BrVPqaf1.mjs"), "./translations/ja.json": () => import("./ja-CtsUxOvk.mjs"), "./translations/ko.json": () => import("./ko-HVQRlfUI.mjs"), "./translations/ml.json": () => import("./ml-BihZwQit.mjs"), "./translations/ms.json": () => import("./ms-m_WjyWx7.mjs"), "./translations/nl.json": () => import("./nl-D4R9gHx5.mjs"), "./translations/pl.json": () => import("./pl-sbx9mSt_.mjs"), "./translations/pt-BR.json": () => import("./pt-BR-C71iDxnh.mjs"), "./translations/pt.json": () => import("./pt-BsaFvS8-.mjs"), "./translations/ru.json": () => import("./ru-BE6A4Exp.mjs"), "./translations/sa.json": () => import("./sa-Dag0k-Z8.mjs"), "./translations/sk.json": () => import("./sk-BFg-R8qJ.mjs"), "./translations/sv.json": () => import("./sv-CUnfWGsh.mjs"), "./translations/th.json": () => import("./th-BqbI8lIT.mjs"), "./translations/tr.json": () => import("./tr-CgeK3wJM.mjs"), "./translations/uk.json": () => import("./uk-CR-zDhAY.mjs"), "./translations/vi.json": () => import("./vi-DUXIk_fw.mjs"), "./translations/zh-Hans.json": () => import("./zh-Hans-BPQcRIyH.mjs"), "./translations/zh.json": () => import("./zh-BWZspA60.mjs") }), `./translations/${locale}.json`).then(({ default: data }) => {
3878
3966
  return {
3879
3967
  data: prefixPluginTranslations(data, PLUGIN_ID),
3880
3968
  locale
@@ -3920,11 +4008,11 @@ export {
3920
4008
  PERMISSIONS as k,
3921
4009
  DocumentRBAC as l,
3922
4010
  DOCUMENT_META_FIELDS as m,
3923
- useDocLayout as n,
3924
- useGetContentTypeConfigurationQuery as o,
3925
- CREATOR_FIELDS as p,
3926
- getMainField as q,
3927
- routes as r,
4011
+ CLONE_PATH as n,
4012
+ useDocLayout as o,
4013
+ useGetContentTypeConfigurationQuery as p,
4014
+ CREATOR_FIELDS as q,
4015
+ getMainField as r,
3928
4016
  setInitialData as s,
3929
4017
  getDisplayName as t,
3930
4018
  useContentTypeSchema as u,
@@ -3934,4 +4022,4 @@ export {
3934
4022
  capitalise as y,
3935
4023
  useUpdateContentTypeConfigurationMutation as z
3936
4024
  };
3937
- //# sourceMappingURL=index-Dahjdw4h.mjs.map
4025
+ //# sourceMappingURL=index-D4UGPFZC.mjs.map