@strapi/content-manager 0.0.0-experimental.145e7d7ddefd1aef71aaf3d9bb86440d013035bf → 0.0.0-experimental.1610404a03d98b65f497f9adda35815021b8fd76

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 (125) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-DJEJ49QD.mjs → ComponentConfigurationPage-C5xJlht8.mjs} +4 -4
  2. package/dist/_chunks/{ComponentConfigurationPage-DJEJ49QD.mjs.map → ComponentConfigurationPage-C5xJlht8.mjs.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-D_g11bYV.js → ComponentConfigurationPage-CyzIs3Wp.js} +5 -6
  4. package/dist/_chunks/{ComponentConfigurationPage-D_g11bYV.js.map → ComponentConfigurationPage-CyzIs3Wp.js.map} +1 -1
  5. package/dist/_chunks/{ComponentIcon-BXdiCGQp.js → ComponentIcon-CRbtQEUV.js} +2 -3
  6. package/dist/_chunks/{ComponentIcon-BXdiCGQp.js.map → ComponentIcon-CRbtQEUV.js.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-QBZdUYyG.mjs → EditConfigurationPage-B1JTGbDa.mjs} +4 -4
  8. package/dist/_chunks/{EditConfigurationPage-QBZdUYyG.mjs.map → EditConfigurationPage-B1JTGbDa.mjs.map} +1 -1
  9. package/dist/_chunks/{EditConfigurationPage-CeL712KW.js → EditConfigurationPage-BoY4_TQp.js} +5 -6
  10. package/dist/_chunks/{EditConfigurationPage-CeL712KW.js.map → EditConfigurationPage-BoY4_TQp.js.map} +1 -1
  11. package/dist/_chunks/{EditViewPage-CvRUUpVh.mjs → EditViewPage-B8Uz26ZK.mjs} +15 -5
  12. package/dist/_chunks/EditViewPage-B8Uz26ZK.mjs.map +1 -0
  13. package/dist/_chunks/{EditViewPage-g5TwrgRY.js → EditViewPage-DxszpwJd.js} +16 -7
  14. package/dist/_chunks/EditViewPage-DxszpwJd.js.map +1 -0
  15. package/dist/_chunks/{Field-reyvfnop.mjs → Field-CquZadQb.mjs} +93 -78
  16. package/dist/_chunks/Field-CquZadQb.mjs.map +1 -0
  17. package/dist/_chunks/{Field-ncdInvxS.js → Field-DzgX4ael.js} +99 -85
  18. package/dist/_chunks/Field-DzgX4ael.js.map +1 -0
  19. package/dist/_chunks/{Form-BJ7bYiUx.js → Form-C8a2ftQg.js} +17 -12
  20. package/dist/_chunks/Form-C8a2ftQg.js.map +1 -0
  21. package/dist/_chunks/{Form-DoMGsYxH.mjs → Form-DuJm__5A.mjs} +15 -9
  22. package/dist/_chunks/Form-DuJm__5A.mjs.map +1 -0
  23. package/dist/_chunks/{History-pbhkxIrf.js → History-B1sa22d-.js} +25 -13
  24. package/dist/_chunks/History-B1sa22d-.js.map +1 -0
  25. package/dist/_chunks/{History-BseDJOrj.mjs → History-C7xPTX16.mjs} +25 -12
  26. package/dist/_chunks/History-C7xPTX16.mjs.map +1 -0
  27. package/dist/_chunks/{ListConfigurationPage-DWE_fr5B.mjs → ListConfigurationPage-C6zgYhFZ.mjs} +4 -4
  28. package/dist/_chunks/{ListConfigurationPage-DWE_fr5B.mjs.map → ListConfigurationPage-C6zgYhFZ.mjs.map} +1 -1
  29. package/dist/_chunks/{ListConfigurationPage-Bna8zfjr.js → ListConfigurationPage-CYWB9ZNc.js} +5 -6
  30. package/dist/_chunks/{ListConfigurationPage-Bna8zfjr.js.map → ListConfigurationPage-CYWB9ZNc.js.map} +1 -1
  31. package/dist/_chunks/{ListViewPage-lQ-VLV2G.mjs → ListViewPage-BkzGZ8pS.mjs} +36 -13
  32. package/dist/_chunks/ListViewPage-BkzGZ8pS.mjs.map +1 -0
  33. package/dist/_chunks/{ListViewPage-Dymsvnv6.js → ListViewPage-D7jZkQ1q.js} +41 -19
  34. package/dist/_chunks/ListViewPage-D7jZkQ1q.js.map +1 -0
  35. package/dist/_chunks/{NoContentTypePage-B4t_OsDR.js → NoContentTypePage-C-eluJ5b.js} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-B4t_OsDR.js.map → NoContentTypePage-C-eluJ5b.js.map} +1 -1
  37. package/dist/_chunks/{NoContentTypePage-VCQOMwlf.mjs → NoContentTypePage-CNTp9Je-.mjs} +2 -2
  38. package/dist/_chunks/{NoContentTypePage-VCQOMwlf.mjs.map → NoContentTypePage-CNTp9Je-.mjs.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-BOwB6hki.js → NoPermissionsPage-5BRSh_ql.js} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-BOwB6hki.js.map → NoPermissionsPage-5BRSh_ql.js.map} +1 -1
  41. package/dist/_chunks/{NoPermissionsPage-TV830k4P.mjs → NoPermissionsPage-B1-Nl_T8.mjs} +2 -2
  42. package/dist/_chunks/{NoPermissionsPage-TV830k4P.mjs.map → NoPermissionsPage-B1-Nl_T8.mjs.map} +1 -1
  43. package/dist/_chunks/{Relations-DdlstXTu.js → Relations-CXy88hPa.js} +72 -42
  44. package/dist/_chunks/Relations-CXy88hPa.js.map +1 -0
  45. package/dist/_chunks/{Relations-D6NAlnsl.mjs → Relations-DqHS7-Cx.mjs} +72 -41
  46. package/dist/_chunks/Relations-DqHS7-Cx.mjs.map +1 -0
  47. package/dist/_chunks/{en-Cf41pH5f.js → en-Bm0D0IWz.js} +9 -9
  48. package/dist/_chunks/{en-Cf41pH5f.js.map → en-Bm0D0IWz.js.map} +1 -1
  49. package/dist/_chunks/{en-DCszE74t.mjs → en-DKV44jRb.mjs} +9 -9
  50. package/dist/_chunks/{en-DCszE74t.mjs.map → en-DKV44jRb.mjs.map} +1 -1
  51. package/dist/_chunks/{index-CQos-KS0.js → index-BwWfprNi.js} +1905 -1763
  52. package/dist/_chunks/index-BwWfprNi.js.map +1 -0
  53. package/dist/_chunks/{index-BYSWwHBJ.mjs → index-LwSbWlvf.mjs} +1906 -1764
  54. package/dist/_chunks/index-LwSbWlvf.mjs.map +1 -0
  55. package/dist/_chunks/{layout-0TY7UtKO.mjs → layout-BS7u3JUZ.mjs} +6 -5
  56. package/dist/_chunks/{layout-0TY7UtKO.mjs.map → layout-BS7u3JUZ.mjs.map} +1 -1
  57. package/dist/_chunks/{layout-B4XAqu1v.js → layout-a7hNwceU.js} +7 -7
  58. package/dist/_chunks/{layout-B4XAqu1v.js.map → layout-a7hNwceU.js.map} +1 -1
  59. package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
  60. package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
  61. package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
  62. package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
  63. package/dist/_chunks/{relations-xZ2tMj1G.js → relations-DedckVWc.js} +3 -7
  64. package/dist/_chunks/relations-DedckVWc.js.map +1 -0
  65. package/dist/_chunks/{relations-DFDWfa0s.mjs → relations-L9TlNEnv.mjs} +3 -7
  66. package/dist/_chunks/relations-L9TlNEnv.mjs.map +1 -0
  67. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  68. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  69. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  70. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  71. package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js → useDragAndDrop-BMtgCYzL.js} +5 -9
  72. package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js.map → useDragAndDrop-BMtgCYzL.js.map} +1 -1
  73. package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs → useDragAndDrop-DJ6jqvZN.mjs} +4 -7
  74. package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs.map → useDragAndDrop-DJ6jqvZN.mjs.map} +1 -1
  75. package/dist/admin/index.js +2 -1
  76. package/dist/admin/index.js.map +1 -1
  77. package/dist/admin/index.mjs +3 -2
  78. package/dist/admin/src/exports.d.ts +1 -1
  79. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  80. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  81. package/dist/admin/src/preview/constants.d.ts +1 -0
  82. package/dist/admin/src/preview/index.d.ts +4 -0
  83. package/dist/server/index.js +104 -69
  84. package/dist/server/index.js.map +1 -1
  85. package/dist/server/index.mjs +103 -67
  86. package/dist/server/index.mjs.map +1 -1
  87. package/dist/server/src/bootstrap.d.ts.map +1 -1
  88. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  89. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  90. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  91. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  92. package/dist/server/src/history/services/history.d.ts.map +1 -1
  93. package/dist/server/src/index.d.ts +4 -4
  94. package/dist/server/src/preview/constants.d.ts +2 -0
  95. package/dist/server/src/preview/constants.d.ts.map +1 -0
  96. package/dist/server/src/preview/index.d.ts +4 -0
  97. package/dist/server/src/preview/index.d.ts.map +1 -0
  98. package/dist/server/src/services/document-metadata.d.ts +8 -8
  99. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  100. package/dist/server/src/services/index.d.ts +4 -4
  101. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  102. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  103. package/dist/server/src/utils/index.d.ts +2 -0
  104. package/dist/server/src/utils/index.d.ts.map +1 -1
  105. package/package.json +13 -13
  106. package/dist/_chunks/EditViewPage-CvRUUpVh.mjs.map +0 -1
  107. package/dist/_chunks/EditViewPage-g5TwrgRY.js.map +0 -1
  108. package/dist/_chunks/Field-ncdInvxS.js.map +0 -1
  109. package/dist/_chunks/Field-reyvfnop.mjs.map +0 -1
  110. package/dist/_chunks/Form-BJ7bYiUx.js.map +0 -1
  111. package/dist/_chunks/Form-DoMGsYxH.mjs.map +0 -1
  112. package/dist/_chunks/History-BseDJOrj.mjs.map +0 -1
  113. package/dist/_chunks/History-pbhkxIrf.js.map +0 -1
  114. package/dist/_chunks/ListViewPage-Dymsvnv6.js.map +0 -1
  115. package/dist/_chunks/ListViewPage-lQ-VLV2G.mjs.map +0 -1
  116. package/dist/_chunks/Relations-D6NAlnsl.mjs.map +0 -1
  117. package/dist/_chunks/Relations-DdlstXTu.js.map +0 -1
  118. package/dist/_chunks/index-BYSWwHBJ.mjs.map +0 -1
  119. package/dist/_chunks/index-CQos-KS0.js.map +0 -1
  120. package/dist/_chunks/relations-DFDWfa0s.mjs.map +0 -1
  121. package/dist/_chunks/relations-xZ2tMj1G.js.map +0 -1
  122. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  123. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  124. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  125. package/strapi-server.js +0 -3
@@ -141,8 +141,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
141
141
  };
142
142
  const getRelationRestoreValue = async (versionRelationData, attribute) => {
143
143
  if (Array.isArray(versionRelationData)) {
144
- if (versionRelationData.length === 0)
145
- return versionRelationData;
144
+ if (versionRelationData.length === 0) return versionRelationData;
146
145
  const existingAndMissingRelations = await Promise.all(
147
146
  versionRelationData.map((relation) => {
148
147
  return strapi2.documents(attribute.target).findOne({
@@ -177,8 +176,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
177
176
  const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
178
177
  const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
179
178
  const getLocaleDictionary = async () => {
180
- if (!localesService)
181
- return {};
179
+ if (!localesService) return {};
182
180
  const locales = await localesService.find() || [];
183
181
  return locales.reduce(
184
182
  (acc, locale) => {
@@ -367,7 +365,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
367
365
  if (userToPopulate == null) {
368
366
  return null;
369
367
  }
370
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
368
+ return strapi2.query("admin::user").findOne({
369
+ where: {
370
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
371
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
372
+ }
373
+ });
371
374
  })
372
375
  );
373
376
  return {
@@ -664,7 +667,7 @@ const historyVersion = {
664
667
  }
665
668
  }
666
669
  };
667
- const getFeature = () => {
670
+ const getFeature$1 = () => {
668
671
  if (strapi.ee.features.isEnabled("cms-content-history")) {
669
672
  return {
670
673
  register({ strapi: strapi2 }) {
@@ -687,7 +690,7 @@ const getFeature = () => {
687
690
  }
688
691
  };
689
692
  };
690
- const history = getFeature();
693
+ const history = getFeature$1();
691
694
  const register = async ({ strapi: strapi2 }) => {
692
695
  await history.register?.({ strapi: strapi2 });
693
696
  };
@@ -695,6 +698,18 @@ const ALLOWED_WEBHOOK_EVENTS = {
695
698
  ENTRY_PUBLISH: "entry.publish",
696
699
  ENTRY_UNPUBLISH: "entry.unpublish"
697
700
  };
701
+ const FEATURE_ID = "preview";
702
+ const getFeature = () => {
703
+ if (!strapi.features.future.isEnabled(FEATURE_ID)) {
704
+ return {};
705
+ }
706
+ return {
707
+ bootstrap() {
708
+ console.log("Bootstrapping preview server");
709
+ }
710
+ };
711
+ };
712
+ const preview = getFeature();
698
713
  const bootstrap = async () => {
699
714
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
700
715
  strapi.get("webhookStore").addAllowedEvent(key, value);
@@ -704,6 +719,7 @@ const bootstrap = async () => {
704
719
  await getService$1("content-types").syncConfigurations();
705
720
  await getService$1("permission").registerPermissions();
706
721
  await history.bootstrap?.({ strapi });
722
+ await preview.bootstrap?.({ strapi });
707
723
  };
708
724
  const destroy = async ({ strapi: strapi2 }) => {
709
725
  await history.destroy?.({ strapi: strapi2 });
@@ -1256,8 +1272,7 @@ const isSortable = (schema, name) => {
1256
1272
  if (!_.has(schema.attributes, name)) {
1257
1273
  return false;
1258
1274
  }
1259
- if (schema.modelType === "component" && name === "id")
1260
- return false;
1275
+ if (schema.modelType === "component" && name === "id") return false;
1261
1276
  const attribute = schema.attributes[name];
1262
1277
  if (NON_SORTABLES.includes(attribute.type)) {
1263
1278
  return false;
@@ -1402,8 +1417,7 @@ const createDefaultSettings = async (schema) => {
1402
1417
  };
1403
1418
  };
1404
1419
  const syncSettings = async (configuration, schema) => {
1405
- if (isEmpty(configuration.settings))
1406
- return createDefaultSettings(schema);
1420
+ if (isEmpty(configuration.settings)) return createDefaultSettings(schema);
1407
1421
  const defaultField = getDefaultMainField(schema);
1408
1422
  const { mainField = defaultField, defaultSortBy = defaultField } = configuration.settings || {};
1409
1423
  return {
@@ -1579,8 +1593,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
1579
1593
  }
1580
1594
  switch (attribute.type) {
1581
1595
  case "relation": {
1582
- if (canCreate(attributePath))
1583
- return body2;
1596
+ if (canCreate(attributePath)) return body2;
1584
1597
  return set(attributePath, { set: [] }, body2);
1585
1598
  }
1586
1599
  case "component": {
@@ -1590,8 +1603,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
1590
1603
  ]);
1591
1604
  }
1592
1605
  default: {
1593
- if (canCreate(attributePath))
1594
- return body2;
1606
+ if (canCreate(attributePath)) return body2;
1595
1607
  return set(attributePath, null, body2);
1596
1608
  }
1597
1609
  }
@@ -1689,7 +1701,7 @@ const updateDocument = async (ctx, opts) => {
1689
1701
  throw new errors.ForbiddenError();
1690
1702
  }
1691
1703
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1692
- const setCreator = setCreatorFields({ user, isEdition: true });
1704
+ const setCreator = documentVersion ? setCreatorFields({ user, isEdition: true }) : setCreatorFields({ user });
1693
1705
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1694
1706
  const sanitizedBody = await sanitizeFn(body);
1695
1707
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1761,7 +1773,7 @@ const collectionTypes = {
1761
1773
  permissionChecker2,
1762
1774
  model,
1763
1775
  // @ts-expect-error TODO: fix
1764
- { id, locale, publishedAt: null },
1776
+ { documentId: id, locale, publishedAt: null },
1765
1777
  { availableLocales: true, availableStatus: false }
1766
1778
  );
1767
1779
  ctx.body = { data: {}, meta };
@@ -1898,11 +1910,17 @@ const collectionTypes = {
1898
1910
  }
1899
1911
  const isUpdate = !isCreate;
1900
1912
  if (isUpdate) {
1901
- document = await documentManager2.findOne(id, model, { populate, locale });
1902
- if (!document) {
1913
+ const documentExists = documentManager2.exists(model, id);
1914
+ if (!documentExists) {
1903
1915
  throw new errors.NotFoundError("Document not found");
1904
1916
  }
1905
- if (permissionChecker2.can.update(document)) {
1917
+ document = await documentManager2.findOne(id, model, { populate, locale });
1918
+ if (!document) {
1919
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
1920
+ throw new errors.ForbiddenError();
1921
+ }
1922
+ document = await updateDocument(ctx);
1923
+ } else if (permissionChecker2.can.update(document)) {
1906
1924
  await updateDocument(ctx);
1907
1925
  }
1908
1926
  }
@@ -2327,15 +2345,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2327
2345
  }
2328
2346
  return mainField;
2329
2347
  };
2330
- const addStatusToRelations = async (uid2, relations2) => {
2331
- if (!contentTypes$1.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2348
+ const addStatusToRelations = async (targetUid, relations2) => {
2349
+ if (!contentTypes$1.hasDraftAndPublish(strapi.getModel(targetUid))) {
2332
2350
  return relations2;
2333
2351
  }
2334
2352
  const documentMetadata2 = getService$1("document-metadata");
2335
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2353
+ if (!relations2.length) {
2354
+ return relations2;
2355
+ }
2356
+ const firstRelation = relations2[0];
2357
+ const filters = {
2358
+ documentId: { $in: relations2.map((r) => r.documentId) },
2359
+ // NOTE: find the "opposite" status
2360
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2361
+ };
2362
+ const availableStatus = await strapi.query(targetUid).findMany({
2363
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2364
+ filters
2365
+ });
2336
2366
  return relations2.map((relation) => {
2337
- const availableStatuses = documentsAvailableStatus.filter(
2338
- (availableDocument) => availableDocument.documentId === relation.documentId
2367
+ const availableStatuses = availableStatus.filter(
2368
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2339
2369
  );
2340
2370
  return {
2341
2371
  ...relation,
@@ -2356,11 +2386,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2356
2386
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2357
2387
  const isSourceLocalized = isLocalized(sourceModel);
2358
2388
  const isTargetLocalized = isLocalized(targetModel);
2359
- let validatedLocale = locale;
2360
- if (!targetModel || !isTargetLocalized)
2361
- validatedLocale = void 0;
2362
2389
  return {
2363
- locale: validatedLocale,
2390
+ locale,
2364
2391
  isSourceLocalized,
2365
2392
  isTargetLocalized
2366
2393
  };
@@ -2369,8 +2396,7 @@ const validateStatus = (sourceUid, status) => {
2369
2396
  const sourceModel = strapi.getModel(sourceUid);
2370
2397
  const isDP = contentTypes$1.hasDraftAndPublish;
2371
2398
  const isSourceDP = isDP(sourceModel);
2372
- if (!isSourceDP)
2373
- return { status: void 0 };
2399
+ if (!isSourceDP) return { status: void 0 };
2374
2400
  switch (status) {
2375
2401
  case "published":
2376
2402
  return { status: "published" };
@@ -2463,7 +2489,7 @@ const relations = {
2463
2489
  attribute,
2464
2490
  fieldsToSelect,
2465
2491
  mainField,
2466
- source: { schema: sourceSchema },
2492
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2467
2493
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2468
2494
  sourceSchema,
2469
2495
  targetSchema,
@@ -2485,7 +2511,8 @@ const relations = {
2485
2511
  fieldsToSelect,
2486
2512
  mainField,
2487
2513
  source: {
2488
- schema: { uid: sourceUid, modelType: sourceModelType }
2514
+ schema: { uid: sourceUid, modelType: sourceModelType },
2515
+ isLocalized: isSourceLocalized
2489
2516
  },
2490
2517
  target: {
2491
2518
  schema: { uid: targetUid },
@@ -2523,12 +2550,16 @@ const relations = {
2523
2550
  } else {
2524
2551
  where.id = id;
2525
2552
  }
2526
- if (status) {
2527
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2553
+ const publishedAt = getPublishedAtClause(status, targetUid);
2554
+ if (!isEmpty(publishedAt)) {
2555
+ where[`${alias}.published_at`] = publishedAt;
2528
2556
  }
2529
- if (filterByLocale) {
2557
+ if (isTargetLocalized && locale) {
2530
2558
  where[`${alias}.locale`] = locale;
2531
2559
  }
2560
+ if (isSourceLocalized && locale) {
2561
+ where.locale = locale;
2562
+ }
2532
2563
  if ((idsToInclude?.length ?? 0) !== 0) {
2533
2564
  where[`${alias}.id`].$notIn = idsToInclude;
2534
2565
  }
@@ -2546,7 +2577,8 @@ const relations = {
2546
2577
  id: { $notIn: uniq(idsToOmit) }
2547
2578
  });
2548
2579
  }
2549
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2580
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2581
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2550
2582
  ctx.body = {
2551
2583
  ...res,
2552
2584
  results: await addStatusToRelations(targetUid, res.results)
@@ -2561,21 +2593,33 @@ const relations = {
2561
2593
  attribute,
2562
2594
  targetField,
2563
2595
  fieldsToSelect,
2564
- source: {
2565
- schema: { uid: sourceUid }
2566
- },
2567
- target: {
2568
- schema: { uid: targetUid }
2569
- }
2596
+ status,
2597
+ source: { schema: sourceSchema },
2598
+ target: { schema: targetSchema }
2570
2599
  } = await this.extractAndValidateRequestInfo(ctx, id);
2600
+ const { uid: sourceUid } = sourceSchema;
2601
+ const { uid: targetUid } = targetSchema;
2571
2602
  const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2572
2603
  const dbQuery = strapi.db.query(sourceUid);
2573
2604
  const loadRelations = relations$1.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2605
+ const filters = {};
2606
+ if (sourceSchema?.options?.draftAndPublish) {
2607
+ if (targetSchema?.options?.draftAndPublish) {
2608
+ if (status === "published") {
2609
+ filters.publishedAt = { $notNull: true };
2610
+ } else {
2611
+ filters.publishedAt = { $null: true };
2612
+ }
2613
+ }
2614
+ } else if (targetSchema?.options?.draftAndPublish) {
2615
+ filters.publishedAt = { $null: true };
2616
+ }
2574
2617
  const res = await loadRelations({ id: entryId }, targetField, {
2575
- select: ["id", "documentId", "locale", "publishedAt"],
2618
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2576
2619
  ordering: "desc",
2577
2620
  page: ctx.request.query.page,
2578
- pageSize: ctx.request.query.pageSize
2621
+ pageSize: ctx.request.query.pageSize,
2622
+ filters
2579
2623
  });
2580
2624
  const loadedIds = res.results.map((item) => item.id);
2581
2625
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
@@ -2668,7 +2712,7 @@ const singleTypes = {
2668
2712
  permissionChecker2,
2669
2713
  model,
2670
2714
  // @ts-expect-error - fix types
2671
- { id: document.documentId, locale, publishedAt: null },
2715
+ { documentId: document.documentId, locale, publishedAt: null },
2672
2716
  { availableLocales: true, availableStatus: false }
2673
2717
  );
2674
2718
  ctx.body = { data: {}, meta };
@@ -2996,18 +3040,15 @@ async function syncMetadatas(configuration, schema) {
2996
3040
  _.set(updatedMeta, ["list", "searchable"], false);
2997
3041
  _.set(acc, [key], updatedMeta);
2998
3042
  }
2999
- if (!_.has(edit, "mainField"))
3000
- return acc;
3043
+ if (!_.has(edit, "mainField")) return acc;
3001
3044
  if (!isRelation$1(attr)) {
3002
3045
  _.set(updatedMeta, "edit", _.omit(edit, ["mainField"]));
3003
3046
  _.set(acc, [key], updatedMeta);
3004
3047
  return acc;
3005
3048
  }
3006
- if (edit.mainField === "id")
3007
- return acc;
3049
+ if (edit.mainField === "id") return acc;
3008
3050
  const targetSchema = getTargetSchema(attr.targetModel);
3009
- if (!targetSchema)
3010
- return acc;
3051
+ if (!targetSchema) return acc;
3011
3052
  if (!isSortable(targetSchema, edit.mainField) && !isListable(targetSchema, edit.mainField)) {
3012
3053
  _.set(updatedMeta, ["edit", "mainField"], getDefaultMainField(targetSchema));
3013
3054
  _.set(acc, [key], updatedMeta);
@@ -3052,8 +3093,7 @@ function createDefaultEditLayout(schema) {
3052
3093
  return appendToEditLayout([], keys2, schema);
3053
3094
  }
3054
3095
  function syncLayouts(configuration, schema) {
3055
- if (_.isEmpty(configuration.layouts))
3056
- return createDefaultLayouts(schema);
3096
+ if (_.isEmpty(configuration.layouts)) return createDefaultLayouts(schema);
3057
3097
  const { list = [], editRelations = [], edit = [] } = configuration.layouts || {};
3058
3098
  let cleanList = list.filter((attr) => isListable(schema, attr));
3059
3099
  const cleanEditRelations = editRelations.filter(
@@ -3064,8 +3104,7 @@ function syncLayouts(configuration, schema) {
3064
3104
  for (const row of edit) {
3065
3105
  const newRow = [];
3066
3106
  for (const el of row) {
3067
- if (!hasEditableAttribute(schema, el.name))
3068
- continue;
3107
+ if (!hasEditableAttribute(schema, el.name)) continue;
3069
3108
  const { hasFieldSize } = getService$1("field-sizes");
3070
3109
  const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
3071
3110
  if (!isAllowedFieldSize(fieldType, el.size)) {
@@ -3096,8 +3135,7 @@ function syncLayouts(configuration, schema) {
3096
3135
  };
3097
3136
  }
3098
3137
  const appendToEditLayout = (layout = [], keysToAppend, schema) => {
3099
- if (keysToAppend.length === 0)
3100
- return layout;
3138
+ if (keysToAppend.length === 0) return layout;
3101
3139
  let currentRowIndex = Math.max(layout.length - 1, 0);
3102
3140
  if (!layout[currentRowIndex]) {
3103
3141
  layout[currentRowIndex] = [];
@@ -4039,7 +4077,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4039
4077
  */
4040
4078
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4041
4079
  const versionsByLocale = groupBy("locale", allVersions);
4042
- delete versionsByLocale[version.locale];
4080
+ if (version.locale) {
4081
+ delete versionsByLocale[version.locale];
4082
+ }
4043
4083
  const model = strapi2.getModel(uid2);
4044
4084
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4045
4085
  const traversalFunction = async (localeVersion) => traverseEntity(
@@ -4086,8 +4126,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4086
4126
  const matchStatus = status === "published" ? v.publishedAt !== null : v.publishedAt === null;
4087
4127
  return matchLocale && matchStatus;
4088
4128
  });
4089
- if (!availableStatus)
4090
- return availableStatus;
4129
+ if (!availableStatus) return availableStatus;
4091
4130
  return pick(AVAILABLE_STATUS_FIELDS, availableStatus);
4092
4131
  },
4093
4132
  /**
@@ -4097,8 +4136,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4097
4136
  * @returns
4098
4137
  */
4099
4138
  async getManyAvailableStatus(uid2, documents) {
4100
- if (!documents.length)
4101
- return [];
4139
+ if (!documents.length) return [];
4102
4140
  const status = documents[0].publishedAt !== null ? "published" : "draft";
4103
4141
  const locale = documents[0]?.locale;
4104
4142
  const otherStatus = status === "published" ? "draft" : "published";
@@ -4125,10 +4163,8 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4125
4163
  } else if (otherVersion) {
4126
4164
  draftVersion = otherVersion;
4127
4165
  }
4128
- if (!draftVersion)
4129
- return CONTENT_MANAGER_STATUS.PUBLISHED;
4130
- if (!publishedVersion)
4131
- return CONTENT_MANAGER_STATUS.DRAFT;
4166
+ if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;
4167
+ if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;
4132
4168
  const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
4133
4169
  return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
4134
4170
  },