@stackbit/cms-core 0.8.4-develop.1 → 0.8.4-develop.2

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.
@@ -34,6 +34,7 @@ function documentToLocalizedApiObject({
34
34
  }): ContentStoreTypes.APIDocumentObject {
35
35
  const { type, fields, getPreview, getDocumentActions, ...rest } = document;
36
36
  return omitByUndefined({
37
+ // for historical reasons, stackbit app works with { type: 'object' } not { type: 'document' }
37
38
  type: 'object',
38
39
  ...rest,
39
40
  srcObjectLabel: getPreview({ delegate, locale }).previewTitle,
@@ -62,6 +63,42 @@ function toLocalizedAPIFields({
62
63
  });
63
64
  }
64
65
 
66
+ /**
67
+ * For historical reasons, Stackit app works with fields that can have only one
68
+ * locale. When Stackbit app fetches documents, it passes the current locale.
69
+ * This function converts the internal document field (DocumentField), possibly
70
+ * with nested locales, into an API field (DocumentFieldAPI) with single locale.
71
+ *
72
+ * DocumentField:
73
+ * {
74
+ * type: "string",
75
+ * localized: true,
76
+ * locales: {
77
+ * 'en-US': {
78
+ * locale: 'en-US',
79
+ * value: 'hello
80
+ * },
81
+ * 'fr-FR': {
82
+ * locale: 'fr-FR',
83
+ * valie: 'bonjour'
84
+ * }
85
+ * }
86
+ * }
87
+ *
88
+ * DocumentFieldAPI:
89
+ * {
90
+ * type: "string",
91
+ * localized: true,
92
+ * locale: 'fr-FR',
93
+ * value: 'bonjour'
94
+ * }
95
+ *
96
+ * It also does some conversions between field types:
97
+ * type: 'model' => 'object',
98
+ * type: 'reference' => 'unresolved_reference',
99
+ * refType: 'asset' => 'image'
100
+ * refType: 'document' => 'object'
101
+ */
65
102
  function toLocalizedAPIField({
66
103
  docField,
67
104
  delegate,
@@ -542,12 +579,12 @@ function concatObjectAndFieldActions(
542
579
  fieldActions?: APICustomActionField[]
543
580
  ): (APICustomActionObject | APICustomActionField)[] | undefined {
544
581
  let result: (APICustomActionObject | APICustomActionField)[] = [];
545
- if (objectActions) {
546
- result = result.concat(objectActions);
547
- }
548
582
  if (fieldActions) {
549
583
  result = result.concat(fieldActions);
550
584
  }
585
+ if (objectActions) {
586
+ result = result.concat(objectActions);
587
+ }
551
588
  if (result.length) {
552
589
  return result;
553
590
  }