@strapi/content-manager 0.0.0-experimental.da85533897155e719d784f0271223c866d2f69ab → 0.0.0-experimental.de2b94258659463e5ddc5992e9a9490d66d950dd

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 (109) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-DyDkPajU.js → ComponentConfigurationPage-CQDCxI8x.js} +3 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-DyDkPajU.js.map → ComponentConfigurationPage-CQDCxI8x.js.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-9lRmRdIr.mjs → ComponentConfigurationPage-jmWwucg_.mjs} +3 -3
  4. package/dist/_chunks/{ComponentConfigurationPage-9lRmRdIr.mjs.map → ComponentConfigurationPage-jmWwucg_.mjs.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-DValmA0m.js → EditConfigurationPage-Ce4bIm4n.js} +3 -3
  6. package/dist/_chunks/{EditConfigurationPage-DValmA0m.js.map → EditConfigurationPage-Ce4bIm4n.js.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-Bk893vVY.mjs → EditConfigurationPage-W07CEdm2.mjs} +3 -3
  8. package/dist/_chunks/{EditConfigurationPage-Bk893vVY.mjs.map → EditConfigurationPage-W07CEdm2.mjs.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-Dk7Eaft4.js → EditViewPage-CqHMM0P0.js} +15 -5
  10. package/dist/_chunks/EditViewPage-CqHMM0P0.js.map +1 -0
  11. package/dist/_chunks/{EditViewPage-DiNFdFqP.mjs → EditViewPage-al5OO1NR.mjs} +15 -5
  12. package/dist/_chunks/EditViewPage-al5OO1NR.mjs.map +1 -0
  13. package/dist/_chunks/{Field-DH2OaqUP.js → Field-DSOUlTCm.js} +76 -42
  14. package/dist/_chunks/Field-DSOUlTCm.js.map +1 -0
  15. package/dist/_chunks/{Field-Dv_HTFTa.mjs → Field-EeG6NQ7x.mjs} +72 -38
  16. package/dist/_chunks/Field-EeG6NQ7x.mjs.map +1 -0
  17. package/dist/_chunks/{Form-Dy6P4HgH.mjs → Form-BAo9ANb_.mjs} +16 -8
  18. package/dist/_chunks/Form-BAo9ANb_.mjs.map +1 -0
  19. package/dist/_chunks/{Form-B_dUDizM.js → Form-DAEfHKzm.js} +16 -8
  20. package/dist/_chunks/Form-DAEfHKzm.js.map +1 -0
  21. package/dist/_chunks/{History-DrwsD1Vc.mjs → History-BpLIu67W.mjs} +24 -11
  22. package/dist/_chunks/History-BpLIu67W.mjs.map +1 -0
  23. package/dist/_chunks/{History-BT4w83Oa.js → History-CTFvy6XH.js} +23 -10
  24. package/dist/_chunks/History-CTFvy6XH.js.map +1 -0
  25. package/dist/_chunks/{ListConfigurationPage-CuYrMcW3.js → ListConfigurationPage-CDzlMBz_.js} +2 -2
  26. package/dist/_chunks/{ListConfigurationPage-CuYrMcW3.js.map → ListConfigurationPage-CDzlMBz_.js.map} +1 -1
  27. package/dist/_chunks/{ListConfigurationPage-BxIP0jRy.mjs → ListConfigurationPage-DOqj5f8Y.mjs} +2 -2
  28. package/dist/_chunks/{ListConfigurationPage-BxIP0jRy.mjs.map → ListConfigurationPage-DOqj5f8Y.mjs.map} +1 -1
  29. package/dist/_chunks/{ListViewPage-5a1vw-OK.mjs → ListViewPage-BbXYNI0v.mjs} +24 -12
  30. package/dist/_chunks/ListViewPage-BbXYNI0v.mjs.map +1 -0
  31. package/dist/_chunks/{ListViewPage-BvpwNur7.js → ListViewPage-D0fpPYKp.js} +28 -16
  32. package/dist/_chunks/ListViewPage-D0fpPYKp.js.map +1 -0
  33. package/dist/_chunks/{NoContentTypePage-UqEiWKkM.js → NoContentTypePage-DTzkSAV5.js} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-UqEiWKkM.js.map → NoContentTypePage-DTzkSAV5.js.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-Bm6tRcd3.mjs → NoContentTypePage-w2Q0VVOT.mjs} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-Bm6tRcd3.mjs.map → NoContentTypePage-w2Q0VVOT.mjs.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-C_vGRo8Q.js → NoPermissionsPage-BoI2rU68.js} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-C_vGRo8Q.js.map → NoPermissionsPage-BoI2rU68.js.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-BHPqn_tQ.mjs → NoPermissionsPage-Km0Vk5Wp.mjs} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-BHPqn_tQ.mjs.map → NoPermissionsPage-Km0Vk5Wp.mjs.map} +1 -1
  41. package/dist/_chunks/{Relations-C7fPyh5P.mjs → Relations-C_bpmSuQ.mjs} +50 -28
  42. package/dist/_chunks/Relations-C_bpmSuQ.mjs.map +1 -0
  43. package/dist/_chunks/{Relations-CznVF6LS.js → Relations-D6Nz5ksc.js} +50 -28
  44. package/dist/_chunks/Relations-D6Nz5ksc.js.map +1 -0
  45. package/dist/_chunks/{en-otD_UBJi.js → en-Bm0D0IWz.js} +12 -11
  46. package/dist/_chunks/{en-otD_UBJi.js.map → en-Bm0D0IWz.js.map} +1 -1
  47. package/dist/_chunks/{en-CbaIuYoB.mjs → en-DKV44jRb.mjs} +12 -11
  48. package/dist/_chunks/{en-CbaIuYoB.mjs.map → en-DKV44jRb.mjs.map} +1 -1
  49. package/dist/_chunks/{index-D9UmmBcM.js → index-BsMu2oVP.js} +2004 -1875
  50. package/dist/_chunks/index-BsMu2oVP.js.map +1 -0
  51. package/dist/_chunks/{index-BJ6uTqLL.mjs → index-DcQ6xogO.mjs} +2007 -1879
  52. package/dist/_chunks/index-DcQ6xogO.mjs.map +1 -0
  53. package/dist/_chunks/{layout-kfu5Wtix.js → layout-B4aCAdTt.js} +5 -4
  54. package/dist/_chunks/{layout-kfu5Wtix.js.map → layout-B4aCAdTt.js.map} +1 -1
  55. package/dist/_chunks/{layout-uomiIGbG.mjs → layout-BavJ6v4B.mjs} +5 -4
  56. package/dist/_chunks/{layout-uomiIGbG.mjs.map → layout-BavJ6v4B.mjs.map} +1 -1
  57. package/dist/_chunks/{relations-DiDufGSA.mjs → relations-DMG453Od.mjs} +2 -2
  58. package/dist/_chunks/{relations-DiDufGSA.mjs.map → relations-DMG453Od.mjs.map} +1 -1
  59. package/dist/_chunks/{relations-DKENrxko.js → relations-Lrm9nz_m.js} +2 -2
  60. package/dist/_chunks/{relations-DKENrxko.js.map → relations-Lrm9nz_m.js.map} +1 -1
  61. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  62. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  63. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  64. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  65. package/dist/admin/index.js +2 -1
  66. package/dist/admin/index.js.map +1 -1
  67. package/dist/admin/index.mjs +3 -2
  68. package/dist/admin/src/exports.d.ts +1 -1
  69. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  70. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  71. package/dist/admin/src/services/documents.d.ts +3 -1
  72. package/dist/server/index.js +74 -32
  73. package/dist/server/index.js.map +1 -1
  74. package/dist/server/index.mjs +74 -32
  75. package/dist/server/index.mjs.map +1 -1
  76. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  77. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  78. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  79. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  80. package/dist/server/src/history/services/history.d.ts.map +1 -1
  81. package/dist/server/src/index.d.ts +4 -4
  82. package/dist/server/src/services/document-metadata.d.ts +8 -8
  83. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  84. package/dist/server/src/services/index.d.ts +4 -4
  85. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  86. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  87. package/dist/server/src/utils/index.d.ts +2 -0
  88. package/dist/server/src/utils/index.d.ts.map +1 -1
  89. package/dist/shared/contracts/collection-types.d.ts +3 -1
  90. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  91. package/package.json +12 -12
  92. package/dist/_chunks/EditViewPage-DiNFdFqP.mjs.map +0 -1
  93. package/dist/_chunks/EditViewPage-Dk7Eaft4.js.map +0 -1
  94. package/dist/_chunks/Field-DH2OaqUP.js.map +0 -1
  95. package/dist/_chunks/Field-Dv_HTFTa.mjs.map +0 -1
  96. package/dist/_chunks/Form-B_dUDizM.js.map +0 -1
  97. package/dist/_chunks/Form-Dy6P4HgH.mjs.map +0 -1
  98. package/dist/_chunks/History-BT4w83Oa.js.map +0 -1
  99. package/dist/_chunks/History-DrwsD1Vc.mjs.map +0 -1
  100. package/dist/_chunks/ListViewPage-5a1vw-OK.mjs.map +0 -1
  101. package/dist/_chunks/ListViewPage-BvpwNur7.js.map +0 -1
  102. package/dist/_chunks/Relations-C7fPyh5P.mjs.map +0 -1
  103. package/dist/_chunks/Relations-CznVF6LS.js.map +0 -1
  104. package/dist/_chunks/index-BJ6uTqLL.mjs.map +0 -1
  105. package/dist/_chunks/index-D9UmmBcM.js.map +0 -1
  106. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  107. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  108. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  109. package/strapi-server.js +0 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounce-DmuSJIF3.mjs","sources":["../../admin/src/utils/urls.ts","../../admin/src/hooks/usePrev.ts","../../admin/src/hooks/useDebounce.ts"],"sourcesContent":["const prefixFileUrlWithBackendUrl = (fileURL?: string): string | undefined => {\n return !!fileURL && fileURL.startsWith('/') ? `${window.strapi.backendURL}${fileURL}` : fileURL;\n};\n\nexport { prefixFileUrlWithBackendUrl };\n","import { useEffect, useRef } from 'react';\n\nexport const usePrev = <T>(value: T): T | undefined => {\n const ref = useRef<T>();\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n};\n","import { useEffect, useState } from 'react';\n\nexport function useDebounce<TValue>(value: TValue, delay: number): TValue {\n const [debouncedValue, setDebouncedValue] = useState(value);\n\n useEffect(() => {\n const handler = setTimeout(() => {\n setDebouncedValue(value);\n }, delay);\n\n return () => {\n clearTimeout(handler);\n };\n }, [value, delay]);\n\n return debouncedValue;\n}\n"],"names":[],"mappings":";AAAM,MAAA,8BAA8B,CAAC,YAAyC;AAC5E,SAAO,CAAC,CAAC,WAAW,QAAQ,WAAW,GAAG,IAAI,GAAG,OAAO,OAAO,UAAU,GAAG,OAAO,KAAK;AAC1F;ACAa,MAAA,UAAU,CAAI,UAA4B;AACrD,QAAM,MAAM;AAEZ,YAAU,MAAM;AACd,QAAI,UAAU;AAAA,EAAA,GACb,CAAC,KAAK,CAAC;AAEV,SAAO,IAAI;AACb;ACRgB,SAAA,YAAoB,OAAe,OAAuB;AACxE,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAS,KAAK;AAE1D,YAAU,MAAM;AACR,UAAA,UAAU,WAAW,MAAM;AAC/B,wBAAkB,KAAK;AAAA,OACtB,KAAK;AAER,WAAO,MAAM;AACX,mBAAa,OAAO;AAAA,IAAA;AAAA,EACtB,GACC,CAAC,OAAO,KAAK,CAAC;AAEV,SAAA;AACT;"}
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const index = require("../_chunks/index-D9UmmBcM.js");
3
+ const index = require("../_chunks/index-BsMu2oVP.js");
4
4
  require("@strapi/icons");
5
5
  exports.DocumentRBAC = index.DocumentRBAC;
6
6
  exports.buildValidParams = index.buildValidParams;
7
7
  exports.default = index.index;
8
+ exports.unstable_useContentManagerContext = index.useContentManagerContext;
8
9
  exports.unstable_useDocument = index.useDocument;
9
10
  exports.unstable_useDocumentActions = index.useDocumentActions;
10
11
  exports.unstable_useDocumentLayout = index.useDocumentLayout;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
@@ -1,11 +1,12 @@
1
- import { l, d, K, J, L, h, f } from "../_chunks/index-BJ6uTqLL.mjs";
1
+ import { l, d, K, L, J, M, h, f } from "../_chunks/index-DcQ6xogO.mjs";
2
2
  import "@strapi/icons";
3
3
  export {
4
4
  l as DocumentRBAC,
5
5
  d as buildValidParams,
6
6
  K as default,
7
+ L as unstable_useContentManagerContext,
7
8
  J as unstable_useDocument,
8
- L as unstable_useDocumentActions,
9
+ M as unstable_useDocumentActions,
9
10
  h as unstable_useDocumentLayout,
10
11
  f as useDocumentRBAC
11
12
  };
@@ -4,7 +4,7 @@
4
4
  * but should still export the same things.
5
5
  */
6
6
  export { buildValidParams } from './utils/api';
7
- export { useDocument as unstable_useDocument } from './hooks/useDocument';
7
+ export { useDocument as unstable_useDocument, useContentManagerContext as unstable_useContentManagerContext, } from './hooks/useDocument';
8
8
  export { useDocumentActions as unstable_useDocumentActions } from './hooks/useDocumentActions';
9
9
  export { useDocumentLayout as unstable_useDocumentLayout } from './hooks/useDocumentLayout';
10
10
  export type { EditFieldLayout, EditLayout, ListFieldLayout, ListLayout, } from './hooks/useDocumentLayout';
@@ -31,7 +31,9 @@ type UseDocument = (args: UseDocumentArgs, opts?: UseDocumentOpts) => {
31
31
  * This is the schema of the content type, it is not the same as the layout.
32
32
  */
33
33
  schema?: Schema;
34
+ schemas?: Schema[];
34
35
  validate: (document: Document) => null | FormErrors;
36
+ hasError?: boolean;
35
37
  };
36
38
  /**
37
39
  * @alpha
@@ -78,10 +80,39 @@ declare const useDoc: () => {
78
80
  * This is the schema of the content type, it is not the same as the layout.
79
81
  */
80
82
  schema?: ContentType | undefined;
83
+ schemas?: ContentType[] | undefined;
81
84
  validate: (document: Document) => null | FormErrors;
85
+ hasError?: boolean | undefined;
82
86
  collectionType: string;
83
87
  model: string;
84
88
  id: string | undefined;
85
89
  };
86
- export { useDocument, useDoc };
90
+ /**
91
+ * @public
92
+ * @experimental
93
+ * Content manager context hooks for plugin development.
94
+ * Make sure to use this hook inside the content manager.
95
+ */
96
+ declare const useContentManagerContext: () => {
97
+ error: import("@reduxjs/toolkit").SerializedError | import("../utils/api").BaseQueryError | undefined;
98
+ isLoading: boolean;
99
+ model: string;
100
+ collectionType: string;
101
+ id: string | undefined;
102
+ slug: string;
103
+ isCreatingEntry: boolean;
104
+ isSingleType: boolean;
105
+ hasDraftAndPublish: boolean;
106
+ components: ComponentsDictionary;
107
+ contentType: ContentType | undefined;
108
+ contentTypes: ContentType[] | undefined;
109
+ form: import("@strapi/admin/strapi-admin").FormContextValue<import("@strapi/admin/strapi-admin").FormValues>;
110
+ layout: {
111
+ error?: import("@reduxjs/toolkit").SerializedError | import("../utils/api").BaseQueryError | undefined;
112
+ isLoading: boolean;
113
+ edit: import("./useDocumentLayout").EditLayout;
114
+ list: import("./useDocumentLayout").ListLayout;
115
+ };
116
+ };
117
+ export { useDocument, useDoc, useContentManagerContext };
87
118
  export type { UseDocument, UseDocumentArgs, Document, Schema, ComponentsDictionary };
@@ -6,20 +6,20 @@ interface HeaderProps {
6
6
  title?: string;
7
7
  }
8
8
  declare const Header: ({ isCreating, status, title: documentTitle }: HeaderProps) => import("react/jsx-runtime").JSX.Element;
9
- interface HeaderButtonAction {
9
+ interface DialogOptions {
10
+ type: 'dialog';
11
+ title: string;
12
+ content?: React.ReactNode;
13
+ footer?: React.ReactNode;
14
+ }
15
+ interface HeaderActionDescription {
10
16
  disabled?: boolean;
11
17
  label: string;
12
18
  icon?: React.ReactNode;
13
- /**
14
- * @default 'default'
15
- */
16
19
  type?: 'icon' | 'default';
17
- onClick?: (event: React.SyntheticEvent) => void;
18
- }
19
- interface HeaderSelectAction {
20
- disabled?: boolean;
21
- label: string;
22
- options: Array<{
20
+ onClick?: (event: React.SyntheticEvent) => Promise<boolean | void> | boolean | void;
21
+ dialog?: DialogOptions;
22
+ options?: Array<{
23
23
  disabled?: boolean;
24
24
  label: string;
25
25
  startIcon?: React.ReactNode;
@@ -28,8 +28,8 @@ interface HeaderSelectAction {
28
28
  }>;
29
29
  onSelect?: (value: string) => void;
30
30
  value?: string;
31
+ customizeContent?: (value: string) => React.ReactNode;
31
32
  }
32
- type HeaderActionDescription = HeaderButtonAction | HeaderSelectAction;
33
33
  declare const DEFAULT_HEADER_ACTIONS: DocumentActionComponent[];
34
34
  export { Header, DEFAULT_HEADER_ACTIONS };
35
35
  export type { HeaderProps, HeaderActionDescription };
@@ -96,6 +96,8 @@ declare const useAutoCloneDocumentMutation: import("@reduxjs/toolkit/dist/query/
96
96
  }, import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@strapi/admin/strapi-admin").QueryArguments, unknown, import("@strapi/admin/strapi-admin").BaseQueryError, {}, {}>, "ComponentConfiguration" | "ContentTypesConfiguration" | "ContentTypeSettings" | "Document" | "InitialData" | "HistoryVersion" | "Relations" | "UidAvailability", Unpublish.Response, "adminApi">>, useUnpublishManyDocumentsMutation: import("@reduxjs/toolkit/dist/query/react/buildHooks").UseMutation<import("@reduxjs/toolkit/query").MutationDefinition<Pick<BulkUnpublish.Params, "model"> & {
97
97
  documentIds: string[];
98
98
  } & {
99
- params?: {} | undefined;
99
+ params?: {
100
+ locale?: string | string[] | null | undefined;
101
+ } | undefined;
100
102
  }, import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@strapi/admin/strapi-admin").QueryArguments, unknown, import("@strapi/admin/strapi-admin").BaseQueryError, {}, {}>, "ComponentConfiguration" | "ContentTypesConfiguration" | "ContentTypeSettings" | "Document" | "InitialData" | "HistoryVersion" | "Relations" | "UidAvailability", BulkUnpublish.Response, "adminApi">>;
101
103
  export { useAutoCloneDocumentMutation, useCloneDocumentMutation, useCreateDocumentMutation, useDeleteDocumentMutation, useDeleteManyDocumentsMutation, useDiscardDocumentMutation, useGetAllDocumentsQuery, useLazyGetDocumentQuery, useGetDocumentQuery, useLazyGetDraftRelationCountQuery as useGetDraftRelationCountQuery, useGetManyDraftRelationCountQuery, usePublishDocumentMutation, usePublishManyDocumentsMutation, useUpdateDocumentMutation, useUnpublishDocumentMutation, useUnpublishManyDocumentsMutation, };
@@ -393,7 +393,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
393
393
  if (userToPopulate == null) {
394
394
  return null;
395
395
  }
396
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
396
+ return strapi2.query("admin::user").findOne({
397
+ where: {
398
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
399
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
400
+ }
401
+ });
397
402
  })
398
403
  );
399
404
  return {
@@ -1715,7 +1720,7 @@ const updateDocument = async (ctx, opts) => {
1715
1720
  throw new strapiUtils.errors.ForbiddenError();
1716
1721
  }
1717
1722
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1718
- const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
1723
+ const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
1719
1724
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1720
1725
  const sanitizedBody = await sanitizeFn(body);
1721
1726
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1787,7 +1792,7 @@ const collectionTypes = {
1787
1792
  permissionChecker2,
1788
1793
  model,
1789
1794
  // @ts-expect-error TODO: fix
1790
- { id, locale, publishedAt: null },
1795
+ { documentId: id, locale, publishedAt: null },
1791
1796
  { availableLocales: true, availableStatus: false }
1792
1797
  );
1793
1798
  ctx.body = { data: {}, meta };
@@ -1924,11 +1929,17 @@ const collectionTypes = {
1924
1929
  }
1925
1930
  const isUpdate = !isCreate;
1926
1931
  if (isUpdate) {
1927
- document = await documentManager2.findOne(id, model, { populate, locale });
1928
- if (!document) {
1932
+ const documentExists = documentManager2.exists(model, id);
1933
+ if (!documentExists) {
1929
1934
  throw new strapiUtils.errors.NotFoundError("Document not found");
1930
1935
  }
1931
- if (permissionChecker2.can.update(document)) {
1936
+ document = await documentManager2.findOne(id, model, { populate, locale });
1937
+ if (!document) {
1938
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
1939
+ throw new strapiUtils.errors.ForbiddenError();
1940
+ }
1941
+ document = await updateDocument(ctx);
1942
+ } else if (permissionChecker2.can.update(document)) {
1932
1943
  await updateDocument(ctx);
1933
1944
  }
1934
1945
  }
@@ -1990,7 +2001,9 @@ const collectionTypes = {
1990
2001
  if (permissionChecker2.cannot.unpublish()) {
1991
2002
  return ctx.forbidden();
1992
2003
  }
1993
- const { locale } = await getDocumentLocaleAndStatus(body, model);
2004
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2005
+ allowMultipleLocales: true
2006
+ });
1994
2007
  const entityPromises = documentIds.map(
1995
2008
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1996
2009
  );
@@ -2351,15 +2364,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2351
2364
  }
2352
2365
  return mainField;
2353
2366
  };
2354
- const addStatusToRelations = async (uid2, relations2) => {
2355
- if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2367
+ const addStatusToRelations = async (targetUid, relations2) => {
2368
+ if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
2356
2369
  return relations2;
2357
2370
  }
2358
2371
  const documentMetadata2 = getService$1("document-metadata");
2359
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2372
+ if (!relations2.length) {
2373
+ return relations2;
2374
+ }
2375
+ const firstRelation = relations2[0];
2376
+ const filters = {
2377
+ documentId: { $in: relations2.map((r) => r.documentId) },
2378
+ // NOTE: find the "opposite" status
2379
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2380
+ };
2381
+ const availableStatus = await strapi.query(targetUid).findMany({
2382
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2383
+ filters
2384
+ });
2360
2385
  return relations2.map((relation) => {
2361
- const availableStatuses = documentsAvailableStatus.filter(
2362
- (availableDocument) => availableDocument.documentId === relation.documentId
2386
+ const availableStatuses = availableStatus.filter(
2387
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2363
2388
  );
2364
2389
  return {
2365
2390
  ...relation,
@@ -2380,11 +2405,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2380
2405
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2381
2406
  const isSourceLocalized = isLocalized(sourceModel);
2382
2407
  const isTargetLocalized = isLocalized(targetModel);
2383
- let validatedLocale = locale;
2384
- if (!targetModel || !isTargetLocalized)
2385
- validatedLocale = void 0;
2386
2408
  return {
2387
- locale: validatedLocale,
2409
+ locale,
2388
2410
  isSourceLocalized,
2389
2411
  isTargetLocalized
2390
2412
  };
@@ -2487,7 +2509,7 @@ const relations = {
2487
2509
  attribute,
2488
2510
  fieldsToSelect,
2489
2511
  mainField,
2490
- source: { schema: sourceSchema },
2512
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2491
2513
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2492
2514
  sourceSchema,
2493
2515
  targetSchema,
@@ -2509,7 +2531,8 @@ const relations = {
2509
2531
  fieldsToSelect,
2510
2532
  mainField,
2511
2533
  source: {
2512
- schema: { uid: sourceUid, modelType: sourceModelType }
2534
+ schema: { uid: sourceUid, modelType: sourceModelType },
2535
+ isLocalized: isSourceLocalized
2513
2536
  },
2514
2537
  target: {
2515
2538
  schema: { uid: targetUid },
@@ -2547,12 +2570,16 @@ const relations = {
2547
2570
  } else {
2548
2571
  where.id = id;
2549
2572
  }
2550
- if (status) {
2551
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2573
+ const publishedAt = getPublishedAtClause(status, targetUid);
2574
+ if (!fp.isEmpty(publishedAt)) {
2575
+ where[`${alias}.published_at`] = publishedAt;
2552
2576
  }
2553
- if (filterByLocale) {
2577
+ if (isTargetLocalized && locale) {
2554
2578
  where[`${alias}.locale`] = locale;
2555
2579
  }
2580
+ if (isSourceLocalized && locale) {
2581
+ where.locale = locale;
2582
+ }
2556
2583
  if ((idsToInclude?.length ?? 0) !== 0) {
2557
2584
  where[`${alias}.id`].$notIn = idsToInclude;
2558
2585
  }
@@ -2570,7 +2597,8 @@ const relations = {
2570
2597
  id: { $notIn: fp.uniq(idsToOmit) }
2571
2598
  });
2572
2599
  }
2573
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2600
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2601
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2574
2602
  ctx.body = {
2575
2603
  ...res,
2576
2604
  results: await addStatusToRelations(targetUid, res.results)
@@ -2585,21 +2613,33 @@ const relations = {
2585
2613
  attribute,
2586
2614
  targetField,
2587
2615
  fieldsToSelect,
2588
- source: {
2589
- schema: { uid: sourceUid }
2590
- },
2591
- target: {
2592
- schema: { uid: targetUid }
2593
- }
2616
+ status,
2617
+ source: { schema: sourceSchema },
2618
+ target: { schema: targetSchema }
2594
2619
  } = await this.extractAndValidateRequestInfo(ctx, id);
2620
+ const { uid: sourceUid } = sourceSchema;
2621
+ const { uid: targetUid } = targetSchema;
2595
2622
  const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2596
2623
  const dbQuery = strapi.db.query(sourceUid);
2597
2624
  const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2625
+ const filters = {};
2626
+ if (sourceSchema?.options?.draftAndPublish) {
2627
+ if (targetSchema?.options?.draftAndPublish) {
2628
+ if (status === "published") {
2629
+ filters.publishedAt = { $notNull: true };
2630
+ } else {
2631
+ filters.publishedAt = { $null: true };
2632
+ }
2633
+ }
2634
+ } else if (targetSchema?.options?.draftAndPublish) {
2635
+ filters.publishedAt = { $null: true };
2636
+ }
2598
2637
  const res = await loadRelations({ id: entryId }, targetField, {
2599
- select: ["id", "documentId", "locale", "publishedAt"],
2638
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2600
2639
  ordering: "desc",
2601
2640
  page: ctx.request.query.page,
2602
- pageSize: ctx.request.query.pageSize
2641
+ pageSize: ctx.request.query.pageSize,
2642
+ filters
2603
2643
  });
2604
2644
  const loadedIds = res.results.map((item) => item.id);
2605
2645
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
@@ -2692,7 +2732,7 @@ const singleTypes = {
2692
2732
  permissionChecker2,
2693
2733
  model,
2694
2734
  // @ts-expect-error - fix types
2695
- { id: document.documentId, locale, publishedAt: null },
2735
+ { documentId: document.documentId, locale, publishedAt: null },
2696
2736
  { availableLocales: true, availableStatus: false }
2697
2737
  );
2698
2738
  ctx.body = { data: {}, meta };
@@ -4063,7 +4103,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4063
4103
  */
4064
4104
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4065
4105
  const versionsByLocale = fp.groupBy("locale", allVersions);
4066
- delete versionsByLocale[version.locale];
4106
+ if (version.locale) {
4107
+ delete versionsByLocale[version.locale];
4108
+ }
4067
4109
  const model = strapi2.getModel(uid2);
4068
4110
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4069
4111
  const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(