@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.
@@ -10,36 +10,42 @@ import {
10
10
  } from '@stackbit/types';
11
11
  import { User } from './index';
12
12
 
13
- export type ContentStoreCustomActionMap = Record<string, ContentStoreCustomAction>;
14
-
15
- export type ContentStoreCustomAction =
16
- | ContentStoreCustomActionGlobal
17
- | ContentStoreCustomActionBulk
18
- | ContentStoreCustomActionDocument
19
- | ContentStoreCustomActionObjectModel
20
- | ContentStoreCustomActionObjectField
21
- | ContentStoreCustomActionField;
22
-
23
- export type ContentStoreCustomActionGlobal = CustomActionGlobal & ContentStoreCustomActionCommonProps;
24
- export type ContentStoreCustomActionBulk = CustomActionBulk & ContentStoreCustomActionCommonProps;
25
- export type ContentStoreCustomActionDocument = CustomActionDocument &
13
+ export type CustomActionRunStateMap = Record<string, CustomActionRunState>;
14
+ export type CustomActionRunState = {
15
+ // specifies if the action is current running in this container instance
16
+ runningHandler?: boolean;
17
+ // the action state returned by the recent 'run' invocation
18
+ lastResultState?: CustomActionState;
19
+ };
20
+
21
+ export type ExtendedCustomAction =
22
+ | ExtendedCustomActionGlobal
23
+ | ExtendedCustomActionBulk
24
+ | ExtendedCustomActionDocument
25
+ | ExtendedCustomActionObjectModel
26
+ | ExtendedCustomActionObjectField
27
+ | ExtendedCustomActionField;
28
+
29
+ export type ExtendedCustomActionGlobal = CustomActionGlobal & ContentStoreCustomActionCommonProps;
30
+ export type ExtendedCustomActionBulk = CustomActionBulk & ContentStoreCustomActionCommonProps;
31
+ export type ExtendedCustomActionDocument = CustomActionDocument &
26
32
  ContentStoreCustomActionCommonProps & {
27
33
  type: 'document';
28
34
  documentSpec: APICustomActionDocumentSpecifier;
29
35
  };
30
- export type ContentStoreCustomActionObjectModel = CustomActionObjectModel &
36
+ export type ExtendedCustomActionObjectModel = CustomActionObjectModel &
31
37
  ContentStoreCustomActionCommonProps & {
32
38
  type: 'objectModel';
33
39
  documentSpec: APICustomActionDocumentSpecifier;
34
40
  fieldPath: (string | number)[];
35
41
  };
36
- export type ContentStoreCustomActionObjectField = Omit<CustomActionObjectField, 'type'> &
42
+ export type ExtendedCustomActionObjectField = Omit<CustomActionObjectField, 'type'> &
37
43
  ContentStoreCustomActionCommonProps & {
38
44
  type: 'objectField';
39
45
  documentSpec: APICustomActionDocumentSpecifier;
40
46
  fieldPath: (string | number)[];
41
47
  };
42
- export type ContentStoreCustomActionField = CustomActionField &
48
+ export type ExtendedCustomActionField = CustomActionField &
43
49
  ContentStoreCustomActionCommonProps & {
44
50
  type: 'field';
45
51
  documentSpec: APICustomActionDocumentSpecifier;
@@ -1,34 +1,21 @@
1
1
  import _ from 'lodash';
2
2
  import { Model, ObjectModel, ImageModel, PageModel, DataModel } from '@stackbit/sdk';
3
3
  import { omitByNil } from '@stackbit/utils';
4
- import {
5
- Field,
6
- FieldSpecificProps,
7
- FieldList,
8
- FieldModelProps,
9
- FieldObjectProps,
10
- isLocalizedField,
11
- getLocalizedFieldForLocale,
12
- isDocumentFieldOneOfFieldTypes
13
- } from '@stackbit/types';
14
- import * as CSITypes from '@stackbit/types';
4
+ import { isLocalizedField, getLocalizedFieldForLocale, isDocumentFieldOneOfFieldTypes } from '@stackbit/types';
5
+ import type * as StackbitTypes from '@stackbit/types';
15
6
 
16
- import * as ContentStoreTypes from '../types';
7
+ import type * as ContentStoreTypes from '../types';
17
8
  import { IMAGE_MODEL } from '../common/common-schema';
18
9
  import { BackCompatContentSourceInterface } from './backward-compatibility';
19
10
  import { getImageFieldsFromSourceData } from './asset-sources-utils';
20
- import {
21
- convertDocumentActionToAPICustomDocumentAction,
22
- convertFieldActionToAPICustomAction,
23
- convertObjectModelActionToAPICustomObjectAction
24
- } from './custom-actions';
11
+ import { getDocumentActionsThunk, getFieldActions, getObjectFieldActionsThunk, getObjectModelActionsThunk } from './custom-actions';
25
12
 
26
13
  export function mapCSIAssetsToStoreAssets({
27
14
  csiAssets,
28
15
  contentSourceInstance,
29
16
  defaultLocaleCode
30
17
  }: {
31
- csiAssets: CSITypes.Asset[];
18
+ csiAssets: StackbitTypes.Asset[];
32
19
  contentSourceInstance: BackCompatContentSourceInterface;
33
20
  defaultLocaleCode?: string;
34
21
  }): ContentStoreTypes.Asset[] {
@@ -47,7 +34,7 @@ function sourceAssetToStoreAsset({
47
34
  defaultLocaleCode,
48
35
  extra
49
36
  }: {
50
- csiAsset: CSITypes.Asset;
37
+ csiAsset: StackbitTypes.Asset;
51
38
  defaultLocaleCode?: string;
52
39
  extra: { srcType: string; srcProjectId: string; srcProjectUrl: string; srcEnvironment: string };
53
40
  }): ContentStoreTypes.Asset {
@@ -98,6 +85,9 @@ function sourceAssetToStoreAsset({
98
85
  * @param contentSourceInstance
99
86
  * @param modelMap
100
87
  * @param defaultLocaleCode
88
+ * @param assetSources
89
+ * @param createConfigDelegate
90
+ * @param customActionRunStateMap
101
91
  */
102
92
  export function mapCSIDocumentsToStoreDocuments({
103
93
  csiDocuments,
@@ -106,15 +96,15 @@ export function mapCSIDocumentsToStoreDocuments({
106
96
  defaultLocaleCode,
107
97
  assetSources,
108
98
  createConfigDelegate,
109
- customActionMap
99
+ customActionRunStateMap
110
100
  }: {
111
- csiDocuments: CSITypes.Document[];
101
+ csiDocuments: StackbitTypes.Document[];
112
102
  contentSourceInstance: BackCompatContentSourceInterface;
113
103
  modelMap: Record<string, Model>;
114
104
  defaultLocaleCode?: string;
115
- assetSources: CSITypes.AssetSource[];
116
- createConfigDelegate: () => CSITypes.ConfigDelegate;
117
- customActionMap: ContentStoreTypes.ContentStoreCustomActionMap;
105
+ assetSources: StackbitTypes.AssetSource[];
106
+ createConfigDelegate: () => StackbitTypes.ConfigDelegate;
107
+ customActionRunStateMap: ContentStoreTypes.CustomActionRunStateMap;
118
108
  }): ContentStoreTypes.Document[] {
119
109
  const meta = getMetadataFromContentStore({ contentSourceInstance });
120
110
  return csiDocuments.map((csiDocument) =>
@@ -126,7 +116,7 @@ export function mapCSIDocumentsToStoreDocuments({
126
116
  meta,
127
117
  assetSources,
128
118
  createConfigDelegate,
129
- customActionMap
119
+ customActionRunStateMap
130
120
  })
131
121
  );
132
122
  }
@@ -139,23 +129,23 @@ function mapCSIDocumentToStoreDocument({
139
129
  meta,
140
130
  assetSources,
141
131
  createConfigDelegate,
142
- customActionMap
132
+ customActionRunStateMap
143
133
  }: {
144
- csiDocument: CSITypes.Document;
134
+ csiDocument: StackbitTypes.Document;
145
135
  model: Model;
146
136
  modelMap: Record<string, Model>;
147
137
  defaultLocaleCode?: string;
148
138
  meta: { srcType: string; srcProjectId: string; srcProjectUrl: string; srcEnvironment: string };
149
- assetSources: CSITypes.AssetSource[];
150
- createConfigDelegate: () => CSITypes.ConfigDelegate;
151
- customActionMap: ContentStoreTypes.ContentStoreCustomActionMap;
139
+ assetSources: StackbitTypes.AssetSource[];
140
+ createConfigDelegate: () => StackbitTypes.ConfigDelegate;
141
+ customActionRunStateMap: ContentStoreTypes.CustomActionRunStateMap;
152
142
  }): ContentStoreTypes.Document {
153
143
  return omitByNil({
154
144
  type: 'document',
155
145
  ...meta,
156
146
  srcObjectId: csiDocument.id,
157
147
  srcObjectUrl: csiDocument.manageUrl,
158
- getPreview: ({ delegate, locale }: { delegate?: CSITypes.ConfigDelegate; locale?: string }) =>
148
+ getPreview: ({ delegate, locale }: { delegate?: StackbitTypes.ConfigDelegate; locale?: string }) =>
159
149
  getDocumentPreview({
160
150
  csiDocument,
161
151
  model,
@@ -173,14 +163,13 @@ function mapCSIDocumentToStoreDocument({
173
163
  updatedAt: csiDocument.updatedAt,
174
164
  updatedBy: csiDocument.updatedBy,
175
165
  locale: getDocumentLocale({ csiDocument, model }),
176
- getDocumentActions: () =>
177
- getDocumentActions({
178
- csiDocument,
179
- model: model as PageModel | DataModel,
180
- srcType: meta.srcType,
181
- srcProjectId: meta.srcProjectId,
182
- customActionMap
183
- }),
166
+ getDocumentActions: getDocumentActionsThunk({
167
+ csiDocument,
168
+ model: model as PageModel | DataModel,
169
+ srcType: meta.srcType,
170
+ srcProjectId: meta.srcProjectId,
171
+ customActionRunStateMap
172
+ }),
184
173
  fields: mapCSIFieldsToStoreFields({
185
174
  csiDocumentFields: csiDocument.fields,
186
175
  modelFields: model.fields ?? [],
@@ -192,7 +181,7 @@ function mapCSIDocumentToStoreDocument({
192
181
  defaultLocaleCode,
193
182
  assetSources,
194
183
  createConfigDelegate,
195
- customActionMap,
184
+ customActionRunStateMap,
196
185
  fieldPath: []
197
186
  }
198
187
  })
@@ -202,12 +191,12 @@ function mapCSIDocumentToStoreDocument({
202
191
  type MapContext = {
203
192
  srcType: string;
204
193
  srcProjectId: string;
205
- parentDocument: CSITypes.Document;
194
+ parentDocument: StackbitTypes.Document;
206
195
  modelMap: Record<string, Model>;
207
196
  defaultLocaleCode?: string;
208
- assetSources: CSITypes.AssetSource[];
209
- createConfigDelegate: () => CSITypes.ConfigDelegate;
210
- customActionMap: ContentStoreTypes.ContentStoreCustomActionMap;
197
+ assetSources: StackbitTypes.AssetSource[];
198
+ createConfigDelegate: () => StackbitTypes.ConfigDelegate;
199
+ customActionRunStateMap: ContentStoreTypes.CustomActionRunStateMap;
211
200
  fieldPath: (string | number)[];
212
201
  };
213
202
 
@@ -216,8 +205,8 @@ function mapCSIFieldsToStoreFields({
216
205
  modelFields,
217
206
  context
218
207
  }: {
219
- csiDocumentFields: Record<string, CSITypes.DocumentField>;
220
- modelFields: Field[];
208
+ csiDocumentFields: Record<string, StackbitTypes.DocumentField>;
209
+ modelFields: StackbitTypes.Field[];
221
210
  context: MapContext;
222
211
  }): Record<string, ContentStoreTypes.DocumentField> {
223
212
  return modelFields.reduce((result: Record<string, ContentStoreTypes.DocumentField>, modelField) => {
@@ -234,17 +223,15 @@ function mapCSIFieldsToStoreFields({
234
223
  });
235
224
  docField.label = modelField.label;
236
225
  if (Array.isArray(modelField.actions)) {
237
- docField.getFieldActions = ({ locale }: { locale?: string } = {}) => {
238
- return getFieldActions({
226
+ docField.getFieldActions = ({ locale }: { locale?: string } = {}) =>
227
+ getFieldActions({
239
228
  modelField,
240
229
  csiParentDocument: context.parentDocument,
241
230
  srcType: context.srcType,
242
231
  srcProjectId: context.srcProjectId,
243
- customActionMap: context.customActionMap,
244
- fieldPath: fieldPath,
245
- locale
232
+ customActionRunStateMap: context.customActionRunStateMap,
233
+ fieldPath: locale ? fieldPath.concat(locale) : fieldPath
246
234
  });
247
- };
248
235
  }
249
236
  result[modelField.name] = docField;
250
237
  return result;
@@ -257,8 +244,8 @@ function mapCSIFieldToStoreField({
257
244
  localized,
258
245
  context
259
246
  }: {
260
- csiDocumentField: CSITypes.DocumentField | undefined;
261
- modelField: Field | FieldSpecificProps;
247
+ csiDocumentField: StackbitTypes.DocumentField | undefined;
248
+ modelField: StackbitTypes.Field | StackbitTypes.FieldSpecificProps;
262
249
  localized?: boolean;
263
250
  context: MapContext;
264
251
  }): ContentStoreTypes.DocumentField {
@@ -309,16 +296,16 @@ function mapCSIFieldToStoreField({
309
296
  case 'cross-reference':
310
297
  return mapCrossReferenceField(csiDocumentField);
311
298
  case 'object':
312
- return mapObjectField(csiDocumentField as CSITypes.DocumentObjectField, modelField, context);
299
+ return mapObjectField(csiDocumentField as StackbitTypes.DocumentObjectField, modelField, context);
313
300
  case 'model':
314
- return mapModelField(csiDocumentField as CSITypes.DocumentModelField, modelField, context);
301
+ return mapModelField(csiDocumentField as StackbitTypes.DocumentModelField, modelField, context);
315
302
  case 'list':
316
303
  // list can not be in list, so modelField must be FieldList
317
- return mapListField(csiDocumentField as CSITypes.DocumentListField, modelField as FieldList, context);
304
+ return mapListField(csiDocumentField as StackbitTypes.DocumentListField, modelField as StackbitTypes.FieldList, context);
318
305
  case 'richText':
319
- return mapRichTextField(csiDocumentField as CSITypes.DocumentRichTextField);
306
+ return mapRichTextField(csiDocumentField as StackbitTypes.DocumentRichTextField);
320
307
  case 'markdown':
321
- return mapMarkdownField(csiDocumentField as CSITypes.DocumentStringLikeField);
308
+ return mapMarkdownField(csiDocumentField as StackbitTypes.DocumentStringLikeField);
322
309
  default: {
323
310
  const _exhaustiveCheck: never = modelField;
324
311
  return _exhaustiveCheck;
@@ -327,9 +314,9 @@ function mapCSIFieldToStoreField({
327
314
  }
328
315
 
329
316
  function mapImageField(
330
- csiDocumentField: CSITypes.DocumentField,
331
- imageModelField: CSITypes.FieldImageProps,
332
- assetSources: CSITypes.AssetSource[]
317
+ csiDocumentField: StackbitTypes.DocumentField,
318
+ imageModelField: StackbitTypes.FieldImageProps,
319
+ assetSources: StackbitTypes.AssetSource[]
333
320
  ): ContentStoreTypes.DocumentImageField {
334
321
  // the image can be remapped from 'string', 'text' or 'json' fields
335
322
  if (isDocumentFieldOneOfFieldTypes(csiDocumentField, ['string', 'text', 'json'])) {
@@ -413,7 +400,7 @@ function mapImageField(
413
400
  });
414
401
  }
415
402
 
416
- function mapCrossReferenceField(csiDocumentField: CSITypes.DocumentField): ContentStoreTypes.DocumentCrossReferenceField {
403
+ function mapCrossReferenceField(csiDocumentField: StackbitTypes.DocumentField): ContentStoreTypes.DocumentCrossReferenceField {
417
404
  const unlocalizedUnset = {
418
405
  type: 'cross-reference',
419
406
  refType: 'document',
@@ -507,11 +494,11 @@ function mapCrossReferenceField(csiDocumentField: CSITypes.DocumentField): Conte
507
494
  }
508
495
 
509
496
  function mapObjectField(
510
- csiDocumentField: CSITypes.DocumentObjectField,
511
- modelField: FieldObjectProps,
497
+ csiDocumentField: StackbitTypes.DocumentObjectField,
498
+ modelField: StackbitTypes.FieldObjectProps,
512
499
  context: MapContext
513
500
  ): ContentStoreTypes.DocumentObjectField {
514
- const _getObjectPreview = ({ delegate, locale }: { delegate?: CSITypes.ConfigDelegate; locale?: string }) => {
501
+ const _getObjectPreview = ({ delegate, locale }: { delegate?: StackbitTypes.ConfigDelegate; locale?: string }) => {
515
502
  return getObjectPreview({
516
503
  parentDocument: context.parentDocument,
517
504
  documentField: csiDocumentField,
@@ -522,13 +509,13 @@ function mapObjectField(
522
509
  locale
523
510
  }) as ContentStoreTypes.DocumentObjectFieldPreview;
524
511
  };
525
- const _getObjectActions = (fieldPath: (string | number)[]) => () =>
526
- getObjectFieldActions({
512
+ const _getObjectActions = (fieldPath: (string | number)[]) =>
513
+ getObjectFieldActionsThunk({
527
514
  modelField: modelField,
528
515
  csiParentDocument: context.parentDocument,
529
516
  srcType: context.srcType,
530
517
  srcProjectId: context.srcProjectId,
531
- customActionMap: context.customActionMap,
518
+ customActionRunStateMap: context.customActionRunStateMap,
532
519
  fieldPath: fieldPath
533
520
  });
534
521
  if (!isLocalizedField(csiDocumentField)) {
@@ -565,10 +552,14 @@ function mapObjectField(
565
552
  };
566
553
  }
567
554
 
568
- function mapModelField(csiDocumentField: CSITypes.DocumentModelField, modelField: FieldModelProps, context: MapContext): ContentStoreTypes.DocumentModelField {
555
+ function mapModelField(
556
+ csiDocumentField: StackbitTypes.DocumentModelField,
557
+ modelField: StackbitTypes.FieldModelProps,
558
+ context: MapContext
559
+ ): ContentStoreTypes.DocumentModelField {
569
560
  const _getObjectPreview =
570
561
  (model: ObjectModel) =>
571
- ({ delegate, locale }: { delegate?: CSITypes.ConfigDelegate; locale?: string }) => {
562
+ ({ delegate, locale }: { delegate?: StackbitTypes.ConfigDelegate; locale?: string }) => {
572
563
  return getObjectPreview({
573
564
  parentDocument: context.parentDocument,
574
565
  documentField: csiDocumentField,
@@ -579,13 +570,13 @@ function mapModelField(csiDocumentField: CSITypes.DocumentModelField, modelField
579
570
  locale
580
571
  }) as ContentStoreTypes.DocumentModelFieldPreview;
581
572
  };
582
- const _getObjectActions = (model: ObjectModel, fieldPath: (string | number)[]) => () =>
583
- getObjectModelActions({
573
+ const _getObjectActions = (model: ObjectModel, fieldPath: (string | number)[]) =>
574
+ getObjectModelActionsThunk({
584
575
  csiParentDocument: context.parentDocument,
585
576
  model: model,
586
577
  srcType: context.srcType,
587
578
  srcProjectId: context.srcProjectId,
588
- customActionMap: context.customActionMap,
579
+ customActionRunStateMap: context.customActionRunStateMap,
589
580
  fieldPath: fieldPath
590
581
  });
591
582
  if (!isLocalizedField(csiDocumentField)) {
@@ -628,7 +619,11 @@ function mapModelField(csiDocumentField: CSITypes.DocumentModelField, modelField
628
619
  };
629
620
  }
630
621
 
631
- function mapListField(csiDocumentField: CSITypes.DocumentListField, modelField: FieldList, context: MapContext): ContentStoreTypes.DocumentListField {
622
+ function mapListField(
623
+ csiDocumentField: StackbitTypes.DocumentListField,
624
+ modelField: StackbitTypes.FieldList,
625
+ context: MapContext
626
+ ): ContentStoreTypes.DocumentListField {
632
627
  if (!isLocalizedField(csiDocumentField)) {
633
628
  return {
634
629
  type: csiDocumentField.type,
@@ -671,7 +666,7 @@ function mapListField(csiDocumentField: CSITypes.DocumentListField, modelField:
671
666
  };
672
667
  }
673
668
 
674
- function mapRichTextField(csiDocumentField: CSITypes.DocumentRichTextField): ContentStoreTypes.DocumentRichTextField {
669
+ function mapRichTextField(csiDocumentField: StackbitTypes.DocumentRichTextField): ContentStoreTypes.DocumentRichTextField {
675
670
  if (!isLocalizedField(csiDocumentField)) {
676
671
  return {
677
672
  ...csiDocumentField,
@@ -690,7 +685,7 @@ function mapRichTextField(csiDocumentField: CSITypes.DocumentRichTextField): Con
690
685
  };
691
686
  }
692
687
 
693
- function mapMarkdownField(csiDocumentField: CSITypes.DocumentStringLikeField): ContentStoreTypes.DocumentMarkdownField {
688
+ function mapMarkdownField(csiDocumentField: StackbitTypes.DocumentStringLikeField): ContentStoreTypes.DocumentMarkdownField {
694
689
  if (!isLocalizedField(csiDocumentField)) {
695
690
  return {
696
691
  type: 'markdown',
@@ -724,7 +719,7 @@ function getMetadataFromContentStore({ contentSourceInstance }: { contentSourceI
724
719
  };
725
720
  }
726
721
 
727
- export function getDocumentLocale({ csiDocument, model }: { csiDocument: CSITypes.Document; model: Model }): string | undefined {
722
+ export function getDocumentLocale({ csiDocument, model }: { csiDocument: StackbitTypes.Document; model: Model }): string | undefined {
728
723
  if (csiDocument.locale) {
729
724
  return csiDocument.locale;
730
725
  }
@@ -741,11 +736,11 @@ export function getDocumentPreview({
741
736
  delegate,
742
737
  locale
743
738
  }: {
744
- csiDocument: CSITypes.Document;
739
+ csiDocument: StackbitTypes.Document;
745
740
  model: Model;
746
741
  srcType: string;
747
742
  srcProjectId: string;
748
- delegate: CSITypes.ConfigDelegate;
743
+ delegate: StackbitTypes.ConfigDelegate;
749
744
  locale?: string;
750
745
  }): ContentStoreTypes.DocumentPreview {
751
746
  let previewTitle: string | undefined;
@@ -781,7 +776,7 @@ export function getDocumentPreview({
781
776
  return { previewTitle };
782
777
  }
783
778
 
784
- function getObjectPreview<Type extends CSITypes.DocumentModelField | CSITypes.DocumentObjectField>({
779
+ function getObjectPreview<Type extends StackbitTypes.DocumentModelField | StackbitTypes.DocumentObjectField>({
785
780
  parentDocument,
786
781
  documentField,
787
782
  objectModelOrObjectField,
@@ -790,12 +785,12 @@ function getObjectPreview<Type extends CSITypes.DocumentModelField | CSITypes.Do
790
785
  delegate,
791
786
  locale
792
787
  }: {
793
- parentDocument: CSITypes.Document;
788
+ parentDocument: StackbitTypes.Document;
794
789
  documentField: Type;
795
- objectModelOrObjectField: Type extends CSITypes.DocumentModelField ? ObjectModel : CSITypes.FieldObjectProps;
790
+ objectModelOrObjectField: Type extends StackbitTypes.DocumentModelField ? ObjectModel : StackbitTypes.FieldObjectProps;
796
791
  srcType: string;
797
792
  srcProjectId: string;
798
- delegate: CSITypes.ConfigDelegate;
793
+ delegate: StackbitTypes.ConfigDelegate;
799
794
  locale?: string;
800
795
  }): ContentStoreTypes.DocumentObjectFieldPreview {
801
796
  let previewTitle: string | undefined;
@@ -839,10 +834,10 @@ function resolveDocumentLabelForFieldPath({
839
834
  fieldPath,
840
835
  delegate
841
836
  }: {
842
- document: CSITypes.DocumentWithSource;
843
- fromField?: CSITypes.DocumentModelField | CSITypes.DocumentObjectField;
837
+ document: StackbitTypes.DocumentWithSource;
838
+ fromField?: StackbitTypes.DocumentModelField | StackbitTypes.DocumentObjectField;
844
839
  fieldPath: string;
845
- delegate: CSITypes.ConfigDelegate;
840
+ delegate: StackbitTypes.ConfigDelegate;
846
841
  }): string | undefined {
847
842
  const documentField = delegate.getDocumentFieldForFieldPath({
848
843
  document: document,
@@ -862,10 +857,10 @@ function getObjectTitleFromLabelField({
862
857
  delegate,
863
858
  locale
864
859
  }: {
865
- document: CSITypes.DocumentWithSource;
866
- documentField?: CSITypes.DocumentModelField | CSITypes.DocumentObjectField;
867
- modelOrObjectField: Model | FieldObjectProps | ImageModel;
868
- delegate: CSITypes.ConfigDelegate;
860
+ document: StackbitTypes.DocumentWithSource;
861
+ documentField?: StackbitTypes.DocumentModelField | StackbitTypes.DocumentObjectField;
862
+ modelOrObjectField: Model | StackbitTypes.FieldObjectProps | ImageModel;
863
+ delegate: StackbitTypes.ConfigDelegate;
869
864
  locale?: string;
870
865
  }): string | undefined {
871
866
  const labelField = modelOrObjectField.labelField;
@@ -880,7 +875,7 @@ function getObjectTitleFromLabelField({
880
875
  });
881
876
  }
882
877
 
883
- function getAssetLabel(csiAsset: CSITypes.Asset, locale?: string): string {
878
+ function getAssetLabel(csiAsset: StackbitTypes.Asset, locale?: string): string {
884
879
  const imageModel = IMAGE_MODEL;
885
880
  let label = getAssetLabelFromLabelField(csiAsset, imageModel, locale);
886
881
  if (!label) {
@@ -889,7 +884,7 @@ function getAssetLabel(csiAsset: CSITypes.Asset, locale?: string): string {
889
884
  return label;
890
885
  }
891
886
 
892
- function getAssetLabelFromLabelField(csiAsset: CSITypes.Asset, imageModel: ImageModel, locale?: string): string | undefined {
887
+ function getAssetLabelFromLabelField(csiAsset: StackbitTypes.Asset, imageModel: ImageModel, locale?: string): string | undefined {
893
888
  const labelField = imageModel.labelField;
894
889
  if (!labelField) {
895
890
  return;
@@ -898,7 +893,7 @@ function getAssetLabelFromLabelField(csiAsset: CSITypes.Asset, imageModel: Image
898
893
  if (!field) {
899
894
  return;
900
895
  }
901
- const localizedField = getLocalizedFieldForLocale(field as CSITypes.DocumentField, locale);
896
+ const localizedField = getLocalizedFieldForLocale(field as StackbitTypes.DocumentField, locale);
902
897
  if (localizedField && 'value' in localizedField && localizedField.value) {
903
898
  return localizedField.value;
904
899
  }
@@ -907,136 +902,3 @@ function getAssetLabelFromLabelField(csiAsset: CSITypes.Asset, imageModel: Image
907
902
  function getObjectTitleFromModel(model: Model | ImageModel): string {
908
903
  return model.label ? model.label : _.startCase(model.name);
909
904
  }
910
-
911
- function getDocumentActions({
912
- csiDocument,
913
- model,
914
- srcType,
915
- srcProjectId,
916
- customActionMap
917
- }: {
918
- csiDocument: CSITypes.Document;
919
- model: PageModel | DataModel;
920
- srcType: string;
921
- srcProjectId: string;
922
- customActionMap: ContentStoreTypes.ContentStoreCustomActionMap;
923
- }): ContentStoreTypes.APICustomActionDocument[] | undefined {
924
- if (!('actions' in model) || !Array.isArray(model.actions)) {
925
- return undefined;
926
- }
927
- return model.actions.map((action) => {
928
- return convertDocumentActionToAPICustomDocumentAction({
929
- action,
930
- customActionMap,
931
- csiDocument: {
932
- ...csiDocument,
933
- srcType,
934
- srcProjectId
935
- }
936
- });
937
- });
938
- }
939
-
940
- function getObjectModelActions({
941
- model,
942
- csiParentDocument,
943
- srcType,
944
- srcProjectId,
945
- customActionMap,
946
- fieldPath
947
- }: {
948
- model: ObjectModel;
949
- csiParentDocument: CSITypes.Document;
950
- srcType: string;
951
- srcProjectId: string;
952
- customActionMap: ContentStoreTypes.ContentStoreCustomActionMap;
953
- fieldPath: (string | number)[];
954
- }): ContentStoreTypes.APICustomActionObject[] | undefined {
955
- if (!('actions' in model) || !Array.isArray(model.actions)) {
956
- return undefined;
957
- }
958
- return model.actions.map((action) => {
959
- return convertObjectModelActionToAPICustomObjectAction({
960
- action,
961
- customActionMap,
962
- fieldPath: fieldPath,
963
- csiParentDocument: {
964
- ...csiParentDocument,
965
- srcType,
966
- srcProjectId
967
- }
968
- });
969
- });
970
- }
971
-
972
- function getObjectFieldActions({
973
- modelField,
974
- csiParentDocument,
975
- srcType,
976
- srcProjectId,
977
- customActionMap,
978
- fieldPath,
979
- locale
980
- }: {
981
- modelField: FieldObjectProps;
982
- csiParentDocument: CSITypes.Document;
983
- srcType: string;
984
- srcProjectId: string;
985
- customActionMap: ContentStoreTypes.ContentStoreCustomActionMap;
986
- fieldPath: (string | number)[];
987
- locale?: string;
988
- }): ContentStoreTypes.APICustomActionObject[] | undefined {
989
- if (!('actions' in modelField) || !Array.isArray(modelField.actions)) {
990
- return undefined;
991
- }
992
- return modelField.actions
993
- .filter((action): action is CSITypes.CustomActionObjectField => action.type === 'object')
994
- .map((action) => {
995
- return convertFieldActionToAPICustomAction({
996
- action,
997
- customActionMap,
998
- fieldPath: locale ? fieldPath.concat(locale) : fieldPath,
999
- csiParentDocument: {
1000
- ...csiParentDocument,
1001
- srcType,
1002
- srcProjectId
1003
- }
1004
- });
1005
- });
1006
- }
1007
-
1008
- function getFieldActions({
1009
- modelField,
1010
- csiParentDocument,
1011
- srcType,
1012
- srcProjectId,
1013
- customActionMap,
1014
- fieldPath,
1015
- locale
1016
- }: {
1017
- modelField: FieldSpecificProps;
1018
- csiParentDocument: CSITypes.Document;
1019
- srcType: string;
1020
- srcProjectId: string;
1021
- customActionMap: ContentStoreTypes.ContentStoreCustomActionMap;
1022
- fieldPath: (string | number)[];
1023
- locale?: string;
1024
- }): ContentStoreTypes.APICustomActionField[] | undefined {
1025
- if (!('actions' in modelField) || !Array.isArray(modelField.actions)) {
1026
- return undefined;
1027
- }
1028
- return modelField.actions
1029
- .filter((action): action is CSITypes.CustomActionField => action.type !== 'object')
1030
- .map((action) => {
1031
- return convertFieldActionToAPICustomAction({
1032
- action,
1033
- customActionMap,
1034
- fieldPath: locale ? fieldPath.concat(locale) : fieldPath,
1035
- csiParentDocument: {
1036
- ...csiParentDocument,
1037
- srcType,
1038
- srcProjectId
1039
- }
1040
- });
1041
- });
1042
- }