@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
@@ -10,8 +10,7 @@ const qs = require("qs");
10
10
  const slugify = require("@sindresorhus/slugify");
11
11
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
12
12
  function _interopNamespace(e) {
13
- if (e && e.__esModule)
14
- return e;
13
+ if (e && e.__esModule) return e;
15
14
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
16
15
  if (e) {
17
16
  for (const k in e) {
@@ -167,8 +166,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
167
166
  };
168
167
  const getRelationRestoreValue = async (versionRelationData, attribute) => {
169
168
  if (Array.isArray(versionRelationData)) {
170
- if (versionRelationData.length === 0)
171
- return versionRelationData;
169
+ if (versionRelationData.length === 0) return versionRelationData;
172
170
  const existingAndMissingRelations = await Promise.all(
173
171
  versionRelationData.map((relation) => {
174
172
  return strapi2.documents(attribute.target).findOne({
@@ -203,8 +201,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
203
201
  const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
204
202
  const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
205
203
  const getLocaleDictionary = async () => {
206
- if (!localesService)
207
- return {};
204
+ if (!localesService) return {};
208
205
  const locales = await localesService.find() || [];
209
206
  return locales.reduce(
210
207
  (acc, locale) => {
@@ -393,7 +390,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
393
390
  if (userToPopulate == null) {
394
391
  return null;
395
392
  }
396
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
393
+ return strapi2.query("admin::user").findOne({
394
+ where: {
395
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
396
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
397
+ }
398
+ });
397
399
  })
398
400
  );
399
401
  return {
@@ -690,7 +692,7 @@ const historyVersion = {
690
692
  }
691
693
  }
692
694
  };
693
- const getFeature = () => {
695
+ const getFeature$1 = () => {
694
696
  if (strapi.ee.features.isEnabled("cms-content-history")) {
695
697
  return {
696
698
  register({ strapi: strapi2 }) {
@@ -713,7 +715,7 @@ const getFeature = () => {
713
715
  }
714
716
  };
715
717
  };
716
- const history = getFeature();
718
+ const history = getFeature$1();
717
719
  const register = async ({ strapi: strapi2 }) => {
718
720
  await history.register?.({ strapi: strapi2 });
719
721
  };
@@ -721,6 +723,18 @@ const ALLOWED_WEBHOOK_EVENTS = {
721
723
  ENTRY_PUBLISH: "entry.publish",
722
724
  ENTRY_UNPUBLISH: "entry.unpublish"
723
725
  };
726
+ const FEATURE_ID = "preview";
727
+ const getFeature = () => {
728
+ if (!strapi.features.future.isEnabled(FEATURE_ID)) {
729
+ return {};
730
+ }
731
+ return {
732
+ bootstrap() {
733
+ console.log("Bootstrapping preview server");
734
+ }
735
+ };
736
+ };
737
+ const preview = getFeature();
724
738
  const bootstrap = async () => {
725
739
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
726
740
  strapi.get("webhookStore").addAllowedEvent(key, value);
@@ -730,6 +744,7 @@ const bootstrap = async () => {
730
744
  await getService$1("content-types").syncConfigurations();
731
745
  await getService$1("permission").registerPermissions();
732
746
  await history.bootstrap?.({ strapi });
747
+ await preview.bootstrap?.({ strapi });
733
748
  };
734
749
  const destroy = async ({ strapi: strapi2 }) => {
735
750
  await history.destroy?.({ strapi: strapi2 });
@@ -1282,8 +1297,7 @@ const isSortable = (schema, name) => {
1282
1297
  if (!___default.default.has(schema.attributes, name)) {
1283
1298
  return false;
1284
1299
  }
1285
- if (schema.modelType === "component" && name === "id")
1286
- return false;
1300
+ if (schema.modelType === "component" && name === "id") return false;
1287
1301
  const attribute = schema.attributes[name];
1288
1302
  if (NON_SORTABLES.includes(attribute.type)) {
1289
1303
  return false;
@@ -1428,8 +1442,7 @@ const createDefaultSettings = async (schema) => {
1428
1442
  };
1429
1443
  };
1430
1444
  const syncSettings = async (configuration, schema) => {
1431
- if (fp.isEmpty(configuration.settings))
1432
- return createDefaultSettings(schema);
1445
+ if (fp.isEmpty(configuration.settings)) return createDefaultSettings(schema);
1433
1446
  const defaultField = getDefaultMainField(schema);
1434
1447
  const { mainField = defaultField, defaultSortBy = defaultField } = configuration.settings || {};
1435
1448
  return {
@@ -1605,8 +1618,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
1605
1618
  }
1606
1619
  switch (attribute.type) {
1607
1620
  case "relation": {
1608
- if (canCreate(attributePath))
1609
- return body2;
1621
+ if (canCreate(attributePath)) return body2;
1610
1622
  return fp.set(attributePath, { set: [] }, body2);
1611
1623
  }
1612
1624
  case "component": {
@@ -1616,8 +1628,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
1616
1628
  ]);
1617
1629
  }
1618
1630
  default: {
1619
- if (canCreate(attributePath))
1620
- return body2;
1631
+ if (canCreate(attributePath)) return body2;
1621
1632
  return fp.set(attributePath, null, body2);
1622
1633
  }
1623
1634
  }
@@ -1715,7 +1726,7 @@ const updateDocument = async (ctx, opts) => {
1715
1726
  throw new strapiUtils.errors.ForbiddenError();
1716
1727
  }
1717
1728
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1718
- const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
1729
+ const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
1719
1730
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1720
1731
  const sanitizedBody = await sanitizeFn(body);
1721
1732
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1787,7 +1798,7 @@ const collectionTypes = {
1787
1798
  permissionChecker2,
1788
1799
  model,
1789
1800
  // @ts-expect-error TODO: fix
1790
- { id, locale, publishedAt: null },
1801
+ { documentId: id, locale, publishedAt: null },
1791
1802
  { availableLocales: true, availableStatus: false }
1792
1803
  );
1793
1804
  ctx.body = { data: {}, meta };
@@ -1924,11 +1935,17 @@ const collectionTypes = {
1924
1935
  }
1925
1936
  const isUpdate = !isCreate;
1926
1937
  if (isUpdate) {
1927
- document = await documentManager2.findOne(id, model, { populate, locale });
1928
- if (!document) {
1938
+ const documentExists = documentManager2.exists(model, id);
1939
+ if (!documentExists) {
1929
1940
  throw new strapiUtils.errors.NotFoundError("Document not found");
1930
1941
  }
1931
- if (permissionChecker2.can.update(document)) {
1942
+ document = await documentManager2.findOne(id, model, { populate, locale });
1943
+ if (!document) {
1944
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
1945
+ throw new strapiUtils.errors.ForbiddenError();
1946
+ }
1947
+ document = await updateDocument(ctx);
1948
+ } else if (permissionChecker2.can.update(document)) {
1932
1949
  await updateDocument(ctx);
1933
1950
  }
1934
1951
  }
@@ -2353,15 +2370,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2353
2370
  }
2354
2371
  return mainField;
2355
2372
  };
2356
- const addStatusToRelations = async (uid2, relations2) => {
2357
- if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2373
+ const addStatusToRelations = async (targetUid, relations2) => {
2374
+ if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
2358
2375
  return relations2;
2359
2376
  }
2360
2377
  const documentMetadata2 = getService$1("document-metadata");
2361
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2378
+ if (!relations2.length) {
2379
+ return relations2;
2380
+ }
2381
+ const firstRelation = relations2[0];
2382
+ const filters = {
2383
+ documentId: { $in: relations2.map((r) => r.documentId) },
2384
+ // NOTE: find the "opposite" status
2385
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2386
+ };
2387
+ const availableStatus = await strapi.query(targetUid).findMany({
2388
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2389
+ filters
2390
+ });
2362
2391
  return relations2.map((relation) => {
2363
- const availableStatuses = documentsAvailableStatus.filter(
2364
- (availableDocument) => availableDocument.documentId === relation.documentId
2392
+ const availableStatuses = availableStatus.filter(
2393
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2365
2394
  );
2366
2395
  return {
2367
2396
  ...relation,
@@ -2382,11 +2411,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2382
2411
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2383
2412
  const isSourceLocalized = isLocalized(sourceModel);
2384
2413
  const isTargetLocalized = isLocalized(targetModel);
2385
- let validatedLocale = locale;
2386
- if (!targetModel || !isTargetLocalized)
2387
- validatedLocale = void 0;
2388
2414
  return {
2389
- locale: validatedLocale,
2415
+ locale,
2390
2416
  isSourceLocalized,
2391
2417
  isTargetLocalized
2392
2418
  };
@@ -2395,8 +2421,7 @@ const validateStatus = (sourceUid, status) => {
2395
2421
  const sourceModel = strapi.getModel(sourceUid);
2396
2422
  const isDP = strapiUtils.contentTypes.hasDraftAndPublish;
2397
2423
  const isSourceDP = isDP(sourceModel);
2398
- if (!isSourceDP)
2399
- return { status: void 0 };
2424
+ if (!isSourceDP) return { status: void 0 };
2400
2425
  switch (status) {
2401
2426
  case "published":
2402
2427
  return { status: "published" };
@@ -2489,7 +2514,7 @@ const relations = {
2489
2514
  attribute,
2490
2515
  fieldsToSelect,
2491
2516
  mainField,
2492
- source: { schema: sourceSchema },
2517
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2493
2518
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2494
2519
  sourceSchema,
2495
2520
  targetSchema,
@@ -2511,7 +2536,8 @@ const relations = {
2511
2536
  fieldsToSelect,
2512
2537
  mainField,
2513
2538
  source: {
2514
- schema: { uid: sourceUid, modelType: sourceModelType }
2539
+ schema: { uid: sourceUid, modelType: sourceModelType },
2540
+ isLocalized: isSourceLocalized
2515
2541
  },
2516
2542
  target: {
2517
2543
  schema: { uid: targetUid },
@@ -2549,12 +2575,16 @@ const relations = {
2549
2575
  } else {
2550
2576
  where.id = id;
2551
2577
  }
2552
- if (status) {
2553
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2578
+ const publishedAt = getPublishedAtClause(status, targetUid);
2579
+ if (!fp.isEmpty(publishedAt)) {
2580
+ where[`${alias}.published_at`] = publishedAt;
2554
2581
  }
2555
- if (filterByLocale) {
2582
+ if (isTargetLocalized && locale) {
2556
2583
  where[`${alias}.locale`] = locale;
2557
2584
  }
2585
+ if (isSourceLocalized && locale) {
2586
+ where.locale = locale;
2587
+ }
2558
2588
  if ((idsToInclude?.length ?? 0) !== 0) {
2559
2589
  where[`${alias}.id`].$notIn = idsToInclude;
2560
2590
  }
@@ -2572,7 +2602,8 @@ const relations = {
2572
2602
  id: { $notIn: fp.uniq(idsToOmit) }
2573
2603
  });
2574
2604
  }
2575
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2605
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2606
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2576
2607
  ctx.body = {
2577
2608
  ...res,
2578
2609
  results: await addStatusToRelations(targetUid, res.results)
@@ -2587,21 +2618,33 @@ const relations = {
2587
2618
  attribute,
2588
2619
  targetField,
2589
2620
  fieldsToSelect,
2590
- source: {
2591
- schema: { uid: sourceUid }
2592
- },
2593
- target: {
2594
- schema: { uid: targetUid }
2595
- }
2621
+ status,
2622
+ source: { schema: sourceSchema },
2623
+ target: { schema: targetSchema }
2596
2624
  } = await this.extractAndValidateRequestInfo(ctx, id);
2625
+ const { uid: sourceUid } = sourceSchema;
2626
+ const { uid: targetUid } = targetSchema;
2597
2627
  const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2598
2628
  const dbQuery = strapi.db.query(sourceUid);
2599
2629
  const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2630
+ const filters = {};
2631
+ if (sourceSchema?.options?.draftAndPublish) {
2632
+ if (targetSchema?.options?.draftAndPublish) {
2633
+ if (status === "published") {
2634
+ filters.publishedAt = { $notNull: true };
2635
+ } else {
2636
+ filters.publishedAt = { $null: true };
2637
+ }
2638
+ }
2639
+ } else if (targetSchema?.options?.draftAndPublish) {
2640
+ filters.publishedAt = { $null: true };
2641
+ }
2600
2642
  const res = await loadRelations({ id: entryId }, targetField, {
2601
- select: ["id", "documentId", "locale", "publishedAt"],
2643
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2602
2644
  ordering: "desc",
2603
2645
  page: ctx.request.query.page,
2604
- pageSize: ctx.request.query.pageSize
2646
+ pageSize: ctx.request.query.pageSize,
2647
+ filters
2605
2648
  });
2606
2649
  const loadedIds = res.results.map((item) => item.id);
2607
2650
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
@@ -2694,7 +2737,7 @@ const singleTypes = {
2694
2737
  permissionChecker2,
2695
2738
  model,
2696
2739
  // @ts-expect-error - fix types
2697
- { id: document.documentId, locale, publishedAt: null },
2740
+ { documentId: document.documentId, locale, publishedAt: null },
2698
2741
  { availableLocales: true, availableStatus: false }
2699
2742
  );
2700
2743
  ctx.body = { data: {}, meta };
@@ -3022,18 +3065,15 @@ async function syncMetadatas(configuration, schema) {
3022
3065
  ___default.default.set(updatedMeta, ["list", "searchable"], false);
3023
3066
  ___default.default.set(acc, [key], updatedMeta);
3024
3067
  }
3025
- if (!___default.default.has(edit, "mainField"))
3026
- return acc;
3068
+ if (!___default.default.has(edit, "mainField")) return acc;
3027
3069
  if (!isRelation$1(attr)) {
3028
3070
  ___default.default.set(updatedMeta, "edit", ___default.default.omit(edit, ["mainField"]));
3029
3071
  ___default.default.set(acc, [key], updatedMeta);
3030
3072
  return acc;
3031
3073
  }
3032
- if (edit.mainField === "id")
3033
- return acc;
3074
+ if (edit.mainField === "id") return acc;
3034
3075
  const targetSchema = getTargetSchema(attr.targetModel);
3035
- if (!targetSchema)
3036
- return acc;
3076
+ if (!targetSchema) return acc;
3037
3077
  if (!isSortable(targetSchema, edit.mainField) && !isListable(targetSchema, edit.mainField)) {
3038
3078
  ___default.default.set(updatedMeta, ["edit", "mainField"], getDefaultMainField(targetSchema));
3039
3079
  ___default.default.set(acc, [key], updatedMeta);
@@ -3078,8 +3118,7 @@ function createDefaultEditLayout(schema) {
3078
3118
  return appendToEditLayout([], keys2, schema);
3079
3119
  }
3080
3120
  function syncLayouts(configuration, schema) {
3081
- if (___default.default.isEmpty(configuration.layouts))
3082
- return createDefaultLayouts(schema);
3121
+ if (___default.default.isEmpty(configuration.layouts)) return createDefaultLayouts(schema);
3083
3122
  const { list = [], editRelations = [], edit = [] } = configuration.layouts || {};
3084
3123
  let cleanList = list.filter((attr) => isListable(schema, attr));
3085
3124
  const cleanEditRelations = editRelations.filter(
@@ -3090,8 +3129,7 @@ function syncLayouts(configuration, schema) {
3090
3129
  for (const row of edit) {
3091
3130
  const newRow = [];
3092
3131
  for (const el of row) {
3093
- if (!hasEditableAttribute(schema, el.name))
3094
- continue;
3132
+ if (!hasEditableAttribute(schema, el.name)) continue;
3095
3133
  const { hasFieldSize } = getService$1("field-sizes");
3096
3134
  const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
3097
3135
  if (!isAllowedFieldSize(fieldType, el.size)) {
@@ -3122,8 +3160,7 @@ function syncLayouts(configuration, schema) {
3122
3160
  };
3123
3161
  }
3124
3162
  const appendToEditLayout = (layout = [], keysToAppend, schema) => {
3125
- if (keysToAppend.length === 0)
3126
- return layout;
3163
+ if (keysToAppend.length === 0) return layout;
3127
3164
  let currentRowIndex = Math.max(layout.length - 1, 0);
3128
3165
  if (!layout[currentRowIndex]) {
3129
3166
  layout[currentRowIndex] = [];
@@ -4065,7 +4102,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4065
4102
  */
4066
4103
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4067
4104
  const versionsByLocale = fp.groupBy("locale", allVersions);
4068
- delete versionsByLocale[version.locale];
4105
+ if (version.locale) {
4106
+ delete versionsByLocale[version.locale];
4107
+ }
4069
4108
  const model = strapi2.getModel(uid2);
4070
4109
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4071
4110
  const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
@@ -4112,8 +4151,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4112
4151
  const matchStatus = status === "published" ? v.publishedAt !== null : v.publishedAt === null;
4113
4152
  return matchLocale && matchStatus;
4114
4153
  });
4115
- if (!availableStatus)
4116
- return availableStatus;
4154
+ if (!availableStatus) return availableStatus;
4117
4155
  return fp.pick(AVAILABLE_STATUS_FIELDS, availableStatus);
4118
4156
  },
4119
4157
  /**
@@ -4123,8 +4161,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4123
4161
  * @returns
4124
4162
  */
4125
4163
  async getManyAvailableStatus(uid2, documents) {
4126
- if (!documents.length)
4127
- return [];
4164
+ if (!documents.length) return [];
4128
4165
  const status = documents[0].publishedAt !== null ? "published" : "draft";
4129
4166
  const locale = documents[0]?.locale;
4130
4167
  const otherStatus = status === "published" ? "draft" : "published";
@@ -4151,10 +4188,8 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4151
4188
  } else if (otherVersion) {
4152
4189
  draftVersion = otherVersion;
4153
4190
  }
4154
- if (!draftVersion)
4155
- return CONTENT_MANAGER_STATUS.PUBLISHED;
4156
- if (!publishedVersion)
4157
- return CONTENT_MANAGER_STATUS.DRAFT;
4191
+ if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;
4192
+ if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;
4158
4193
  const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
4159
4194
  return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
4160
4195
  },