datocms-plugin-sdk 2.0.3 → 2.0.5

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 (138) hide show
  1. package/dist/cjs/guardUtils.js +33 -0
  2. package/dist/cjs/guardUtils.js.map +1 -0
  3. package/dist/cjs/hooks/assetSources.js +25 -0
  4. package/dist/cjs/hooks/assetSources.js.map +1 -1
  5. package/dist/cjs/hooks/buildItemPresentationInfo.js +13 -0
  6. package/dist/cjs/hooks/buildItemPresentationInfo.js.map +1 -1
  7. package/dist/cjs/hooks/contentAreaSidebarItems.js +17 -0
  8. package/dist/cjs/hooks/contentAreaSidebarItems.js.map +1 -1
  9. package/dist/cjs/hooks/customBlockStylesForStructuredTextField.js +14 -0
  10. package/dist/cjs/hooks/customBlockStylesForStructuredTextField.js.map +1 -1
  11. package/dist/cjs/hooks/customMarksForStructuredTextField.js +18 -0
  12. package/dist/cjs/hooks/customMarksForStructuredTextField.js.map +1 -1
  13. package/dist/cjs/hooks/initialLocationQueryForItemSelector.js +12 -0
  14. package/dist/cjs/hooks/initialLocationQueryForItemSelector.js.map +1 -1
  15. package/dist/cjs/hooks/itemCollectionOutlets.js +13 -0
  16. package/dist/cjs/hooks/itemCollectionOutlets.js.map +1 -1
  17. package/dist/cjs/hooks/itemFormOutlets.js +13 -0
  18. package/dist/cjs/hooks/itemFormOutlets.js.map +1 -1
  19. package/dist/cjs/hooks/itemFormSidebarPanels.js +17 -0
  20. package/dist/cjs/hooks/itemFormSidebarPanels.js.map +1 -1
  21. package/dist/cjs/hooks/itemFormSidebars.js +15 -0
  22. package/dist/cjs/hooks/itemFormSidebars.js.map +1 -1
  23. package/dist/cjs/hooks/mainNavigationTabs.js +17 -0
  24. package/dist/cjs/hooks/mainNavigationTabs.js.map +1 -1
  25. package/dist/cjs/hooks/manualFieldExtensions.js +25 -0
  26. package/dist/cjs/hooks/manualFieldExtensions.js.map +1 -1
  27. package/dist/cjs/hooks/overrideFieldExtensions.js +46 -0
  28. package/dist/cjs/hooks/overrideFieldExtensions.js.map +1 -1
  29. package/dist/cjs/hooks/renderItemCollectionOutlet.js.map +1 -1
  30. package/dist/cjs/hooks/uploadSidebarPanels.js +17 -0
  31. package/dist/cjs/hooks/uploadSidebarPanels.js.map +1 -1
  32. package/dist/cjs/hooks/uploadSidebars.js +15 -0
  33. package/dist/cjs/hooks/uploadSidebars.js.map +1 -1
  34. package/dist/cjs/icon.js +9 -0
  35. package/dist/cjs/icon.js.map +1 -1
  36. package/dist/cjs/manifest.js +30 -20
  37. package/dist/cjs/manifest.js.map +1 -1
  38. package/dist/cjs/shared.js +25 -0
  39. package/dist/cjs/shared.js.map +1 -1
  40. package/dist/esm/guardUtils.d.ts +7 -0
  41. package/dist/esm/guardUtils.js +24 -0
  42. package/dist/esm/guardUtils.js.map +1 -0
  43. package/dist/esm/hooks/assetSources.d.ts +11 -1
  44. package/dist/esm/hooks/assetSources.js +24 -1
  45. package/dist/esm/hooks/assetSources.js.map +1 -1
  46. package/dist/esm/hooks/buildItemPresentationInfo.d.ts +11 -0
  47. package/dist/esm/hooks/buildItemPresentationInfo.js +12 -1
  48. package/dist/esm/hooks/buildItemPresentationInfo.js.map +1 -1
  49. package/dist/esm/hooks/contentAreaSidebarItems.d.ts +11 -0
  50. package/dist/esm/hooks/contentAreaSidebarItems.js +16 -1
  51. package/dist/esm/hooks/contentAreaSidebarItems.js.map +1 -1
  52. package/dist/esm/hooks/customBlockStylesForStructuredTextField.d.ts +11 -1
  53. package/dist/esm/hooks/customBlockStylesForStructuredTextField.js +13 -1
  54. package/dist/esm/hooks/customBlockStylesForStructuredTextField.js.map +1 -1
  55. package/dist/esm/hooks/customMarksForStructuredTextField.d.ts +11 -1
  56. package/dist/esm/hooks/customMarksForStructuredTextField.js +17 -1
  57. package/dist/esm/hooks/customMarksForStructuredTextField.js.map +1 -1
  58. package/dist/esm/hooks/initialLocationQueryForItemSelector.d.ts +11 -0
  59. package/dist/esm/hooks/initialLocationQueryForItemSelector.js +11 -1
  60. package/dist/esm/hooks/initialLocationQueryForItemSelector.js.map +1 -1
  61. package/dist/esm/hooks/itemCollectionOutlets.d.ts +11 -1
  62. package/dist/esm/hooks/itemCollectionOutlets.js +12 -1
  63. package/dist/esm/hooks/itemCollectionOutlets.js.map +1 -1
  64. package/dist/esm/hooks/itemFormOutlets.d.ts +11 -0
  65. package/dist/esm/hooks/itemFormOutlets.js +12 -1
  66. package/dist/esm/hooks/itemFormOutlets.js.map +1 -1
  67. package/dist/esm/hooks/itemFormSidebarPanels.d.ts +12 -0
  68. package/dist/esm/hooks/itemFormSidebarPanels.js +16 -1
  69. package/dist/esm/hooks/itemFormSidebarPanels.js.map +1 -1
  70. package/dist/esm/hooks/itemFormSidebars.d.ts +12 -0
  71. package/dist/esm/hooks/itemFormSidebars.js +14 -1
  72. package/dist/esm/hooks/itemFormSidebars.js.map +1 -1
  73. package/dist/esm/hooks/mainNavigationTabs.d.ts +11 -1
  74. package/dist/esm/hooks/mainNavigationTabs.js +16 -1
  75. package/dist/esm/hooks/mainNavigationTabs.js.map +1 -1
  76. package/dist/esm/hooks/manualFieldExtensions.d.ts +12 -0
  77. package/dist/esm/hooks/manualFieldExtensions.js +24 -1
  78. package/dist/esm/hooks/manualFieldExtensions.js.map +1 -1
  79. package/dist/esm/hooks/overrideFieldExtensions.d.ts +20 -0
  80. package/dist/esm/hooks/overrideFieldExtensions.js +43 -1
  81. package/dist/esm/hooks/overrideFieldExtensions.js.map +1 -1
  82. package/dist/esm/hooks/renderItemCollectionOutlet.d.ts +6 -1
  83. package/dist/esm/hooks/renderItemCollectionOutlet.js.map +1 -1
  84. package/dist/esm/hooks/uploadSidebarPanels.d.ts +12 -0
  85. package/dist/esm/hooks/uploadSidebarPanels.js +16 -1
  86. package/dist/esm/hooks/uploadSidebarPanels.js.map +1 -1
  87. package/dist/esm/hooks/uploadSidebars.d.ts +12 -0
  88. package/dist/esm/hooks/uploadSidebars.js +14 -1
  89. package/dist/esm/hooks/uploadSidebars.js.map +1 -1
  90. package/dist/esm/icon.d.ts +1 -0
  91. package/dist/esm/icon.js +8 -1
  92. package/dist/esm/icon.js.map +1 -1
  93. package/dist/esm/manifest.js +30 -20
  94. package/dist/esm/manifest.js.map +1 -1
  95. package/dist/esm/shared.d.ts +12 -0
  96. package/dist/esm/shared.js +23 -1
  97. package/dist/esm/shared.js.map +1 -1
  98. package/dist/types/guardUtils.d.ts +7 -0
  99. package/dist/types/hooks/assetSources.d.ts +11 -1
  100. package/dist/types/hooks/buildItemPresentationInfo.d.ts +11 -0
  101. package/dist/types/hooks/contentAreaSidebarItems.d.ts +11 -0
  102. package/dist/types/hooks/customBlockStylesForStructuredTextField.d.ts +11 -1
  103. package/dist/types/hooks/customMarksForStructuredTextField.d.ts +11 -1
  104. package/dist/types/hooks/initialLocationQueryForItemSelector.d.ts +11 -0
  105. package/dist/types/hooks/itemCollectionOutlets.d.ts +11 -1
  106. package/dist/types/hooks/itemFormOutlets.d.ts +11 -0
  107. package/dist/types/hooks/itemFormSidebarPanels.d.ts +12 -0
  108. package/dist/types/hooks/itemFormSidebars.d.ts +12 -0
  109. package/dist/types/hooks/mainNavigationTabs.d.ts +11 -1
  110. package/dist/types/hooks/manualFieldExtensions.d.ts +12 -0
  111. package/dist/types/hooks/overrideFieldExtensions.d.ts +20 -0
  112. package/dist/types/hooks/renderItemCollectionOutlet.d.ts +6 -1
  113. package/dist/types/hooks/uploadSidebarPanels.d.ts +12 -0
  114. package/dist/types/hooks/uploadSidebars.d.ts +12 -0
  115. package/dist/types/icon.d.ts +1 -0
  116. package/dist/types/shared.d.ts +12 -0
  117. package/manifest.json +30 -20
  118. package/package.json +2 -2
  119. package/src/guardUtils.ts +34 -0
  120. package/src/hooks/assetSources.ts +32 -2
  121. package/src/hooks/buildItemPresentationInfo.ts +22 -0
  122. package/src/hooks/contentAreaSidebarItems.ts +32 -1
  123. package/src/hooks/customBlockStylesForStructuredTextField.ts +23 -1
  124. package/src/hooks/customMarksForStructuredTextField.ts +33 -2
  125. package/src/hooks/initialLocationQueryForItemSelector.ts +21 -1
  126. package/src/hooks/itemCollectionOutlets.ts +22 -1
  127. package/src/hooks/itemFormOutlets.ts +20 -0
  128. package/src/hooks/itemFormSidebarPanels.ts +34 -0
  129. package/src/hooks/itemFormSidebars.ts +23 -0
  130. package/src/hooks/mainNavigationTabs.ts +32 -2
  131. package/src/hooks/manualFieldExtensions.ts +42 -0
  132. package/src/hooks/overrideFieldExtensions.ts +64 -0
  133. package/src/hooks/renderItemCollectionOutlet.ts +6 -1
  134. package/src/hooks/uploadSidebarPanels.ts +34 -0
  135. package/src/hooks/uploadSidebars.ts +23 -0
  136. package/src/icon.ts +12 -0
  137. package/src/manifest.ts +31 -20
  138. package/src/shared.ts +48 -1
@@ -1,5 +1,6 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import { isNullish, isNumber, isRecord, isString } from '../guardUtils.js';
3
4
  import type { MaybePromise } from '../utils';
4
5
 
5
6
  type Item = SchemaTypes.Item;
@@ -19,6 +20,11 @@ export type BuildItemPresentationInfoHook = {
19
20
 
20
21
  export type BuildItemPresentationInfoCtx = Ctx;
21
22
 
23
+ /**
24
+ * An object expressing how a record should be presented in the interface
25
+ *
26
+ * @see {isItemPresentationInfo}
27
+ */
22
28
  export type ItemPresentationInfo = {
23
29
  /** The title to present the record */
24
30
  title: string;
@@ -33,3 +39,19 @@ export type ItemPresentationInfo = {
33
39
  */
34
40
  rank?: number;
35
41
  };
42
+
43
+ /**
44
+ * Checks if the value is an ItemPresentationInfo type.
45
+ * @param value The value to check.
46
+ * @returns True if the value is an ItemPresentationInfo, false otherwise.
47
+ */
48
+ export function isItemPresentationInfo(
49
+ value: unknown,
50
+ ): value is ItemPresentationInfo {
51
+ return (
52
+ isRecord(value) &&
53
+ isString(value.title) &&
54
+ (isNullish(value.imageUrl) || isString(value.imageUrl)) &&
55
+ (isNullish(value.rank) || isNumber(value.rank))
56
+ );
57
+ }
@@ -1,5 +1,12 @@
1
1
  import { Ctx } from '../ctx/base';
2
- import { Icon } from '../icon';
2
+ import {
3
+ isNullish,
4
+ isNumber,
5
+ isPlacement,
6
+ isRecord,
7
+ isString,
8
+ } from '../guardUtils.js';
9
+ import { Icon, isIcon } from '../icon';
3
10
 
4
11
  export type ContentAreaSidebarItemsHook = {
5
12
  /**
@@ -14,6 +21,11 @@ export type ContentAreaSidebarItemsHook = {
14
21
 
15
22
  export type ContentAreaSidebarItemsCtx = Ctx;
16
23
 
24
+ /**
25
+ * An object expressing an item in the content area sidebar
26
+ *
27
+ * @see {isContentAreaSidebarItem}
28
+ */
17
29
  export type ContentAreaSidebarItem = {
18
30
  /** Label to be shown. Must be unique. */
19
31
  label: string;
@@ -43,3 +55,22 @@ export type ContentAreaSidebarItem = {
43
55
  */
44
56
  rank?: number;
45
57
  };
58
+
59
+ /**
60
+ * Checks if the value is a ContentAreaSidebarItem.
61
+ * @param value - The value to check.
62
+ * @returns True if the value is a ContentAreaSidebarItem, false otherwise.
63
+ */
64
+ export function isContentAreaSidebarItem(
65
+ value: unknown,
66
+ ): value is ContentAreaSidebarItem {
67
+ return (
68
+ isRecord(value) &&
69
+ isString(value.label) &&
70
+ isIcon(value.icon) &&
71
+ isRecord(value.pointsTo) &&
72
+ isString(value.pointsTo.pageId) &&
73
+ (isNullish(value.placement) || isPlacement(value.placement)) &&
74
+ (isNullish(value.rank) || isNumber(value.rank))
75
+ );
76
+ }
@@ -1,6 +1,7 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { BlockNodeTypeWithCustomStyle } from 'datocms-structured-text-utils';
3
3
  import { Ctx } from '../ctx/base';
4
+ import { isNullish, isNumber, isRecord, isString } from '../guardUtils.js';
4
5
 
5
6
  type Field = SchemaTypes.Field;
6
7
  type ItemType = SchemaTypes.ItemType;
@@ -22,7 +23,11 @@ export type CustomBlockStylesForStructuredTextFieldCtx = Ctx<{
22
23
  itemType: ItemType;
23
24
  }>;
24
25
 
25
- /** An object expressing a custom block style for a Structured Text field */
26
+ /**
27
+ * An object expressing a custom block style for a Structured Text field
28
+ *
29
+ * @see {isStructuredTextCustomBlockStyle}
30
+ */
26
31
  export type StructuredTextCustomBlockStyle = {
27
32
  /** ID of custom block style */
28
33
  id: string;
@@ -40,3 +45,20 @@ export type StructuredTextCustomBlockStyle = {
40
45
  */
41
46
  rank?: number;
42
47
  };
48
+
49
+ /**
50
+ * Checks if the given value is a StructuredTextCustomBlockStyle.
51
+ * @param value - The value to check.
52
+ * @returns True if the value is a StructuredTextCustomBlockStyle, otherwise false.
53
+ */
54
+ export function isStructuredTextCustomBlockStyle(
55
+ value: unknown,
56
+ ): value is StructuredTextCustomBlockStyle {
57
+ return (
58
+ isRecord(value) &&
59
+ isString(value.id) &&
60
+ isString(value.label) &&
61
+ isString(value.node) &&
62
+ (isNullish(value.rank) || isNumber(value.rank))
63
+ );
64
+ }
@@ -1,6 +1,13 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
- import { Icon } from '../icon';
3
+ import {
4
+ isNullish,
5
+ isNumber,
6
+ isPlacement,
7
+ isRecord,
8
+ isString,
9
+ } from '../guardUtils.js';
10
+ import { Icon, isIcon } from '../icon';
4
11
 
5
12
  type Field = SchemaTypes.Field;
6
13
  type ItemType = SchemaTypes.ItemType;
@@ -22,7 +29,11 @@ export type CustomMarksForStructuredTextFieldCtx = Ctx<{
22
29
  itemType: ItemType;
23
30
  }>;
24
31
 
25
- /** An object expressing a custom mark for a Structured Text field */
32
+ /**
33
+ * An object expressing a custom mark for a Structured Text field
34
+ *
35
+ * @see {isStructuredTextCustomMark}
36
+ */
26
37
  export type StructuredTextCustomMark = {
27
38
  /** ID of mark */
28
39
  id: string;
@@ -62,3 +73,23 @@ export type StructuredTextCustomMarkPlacement = [
62
73
  'before' | 'after',
63
74
  'strong' | 'emphasis' | 'underline' | 'code' | 'highlight' | 'strikethrough',
64
75
  ];
76
+
77
+ /**
78
+ * Checks if the given value is a StructuredTextCustomMark.
79
+ * @param value The value to check.
80
+ * @returns True if the value is a StructuredTextCustomMark, false otherwise.
81
+ */
82
+ export function isStructuredTextCustomMark(
83
+ value: unknown,
84
+ ): value is StructuredTextCustomMark {
85
+ return (
86
+ isRecord(value) &&
87
+ isString(value.id) &&
88
+ isString(value.label) &&
89
+ isIcon(value.icon) &&
90
+ (isNullish(value.placement) || isPlacement(value.placement)) &&
91
+ (isNullish(value.rank) || isNumber(value.rank)) &&
92
+ (isNullish(value.keyboardShortcut) || isString(value.keyboardShortcut)) &&
93
+ isRecord(value.appliedStyle)
94
+ );
95
+ }
@@ -1,6 +1,6 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx, ItemListLocationQuery } from '../ctx/base';
3
-
3
+ import { isNullish, isNumber, isRecord } from '../guardUtils.js';
4
4
  import { MaybePromise } from '../utils';
5
5
 
6
6
  type Field = SchemaTypes.Field;
@@ -22,6 +22,11 @@ export type InitialLocationQueryForItemSelectorHook = {
22
22
 
23
23
  export type InitialLocationQueryForItemSelectorCtx = Ctx;
24
24
 
25
+ /**
26
+ * An object expressing which filters should be applied to the record selector
27
+ *
28
+ * @see {isInitialLocationQueryForItemSelector}
29
+ */
25
30
  export type InitialLocationQueryForItemSelector = {
26
31
  locationQuery: ItemListLocationQuery;
27
32
  /**
@@ -33,3 +38,18 @@ export type InitialLocationQueryForItemSelector = {
33
38
  */
34
39
  rank?: number;
35
40
  };
41
+
42
+ /**
43
+ * Type guard for InitialLocationQueryForItemSelector
44
+ * @param value - The value to check
45
+ * @returns True if value is of type InitialLocationQueryForItemSelector, false otherwise
46
+ */
47
+ export function isInitialLocationQueryForItemSelector(
48
+ value: unknown,
49
+ ): value is InitialLocationQueryForItemSelector {
50
+ return (
51
+ isRecord(value) &&
52
+ isRecord(value.locationQuery) &&
53
+ (isNullish(value.rank) || isNumber(value.rank))
54
+ );
55
+ }
@@ -1,5 +1,6 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import { isNullish, isNumber, isRecord, isString } from '../guardUtils.js';
3
4
 
4
5
  type ItemType = SchemaTypes.ItemType;
5
6
 
@@ -18,7 +19,11 @@ export type ItemCollectionOutletsHook = {
18
19
 
19
20
  export type ItemCollectionOutletsCtx = Ctx;
20
21
 
21
- /** An outlet to be shown at the top of a record's collection page */
22
+ /**
23
+ * An object expressing an outlet to be shown at the top of a record's collection page
24
+ *
25
+ * @see {isItemCollectionOutlet}
26
+ */
22
27
  export type ItemCollectionOutlet = {
23
28
  /**
24
29
  * ID of the outlet. Will be the first argument for the `renderItemCollectionOutlet`
@@ -35,3 +40,19 @@ export type ItemCollectionOutlet = {
35
40
  /** The initial height to set for the iframe that will render the outlet */
36
41
  initialHeight?: number;
37
42
  };
43
+
44
+ /**
45
+ * Checks if the given value is an ItemCollectionOutlet.
46
+ * @param value - The value to check.
47
+ * @returns True if the value is an ItemCollectionOutlet, false otherwise.
48
+ */
49
+ export function isItemCollectionOutlet(
50
+ value: unknown,
51
+ ): value is ItemCollectionOutlet {
52
+ return (
53
+ isRecord(value) &&
54
+ isString(value.id) &&
55
+ (isNullish(value.rank) || isNumber(value.rank)) &&
56
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
57
+ );
58
+ }
@@ -1,5 +1,6 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import { isNullish, isNumber, isRecord, isString } from '../guardUtils.js';
3
4
 
4
5
  type ItemType = SchemaTypes.ItemType;
5
6
 
@@ -18,6 +19,11 @@ export type ItemFormOutletsHook = {
18
19
 
19
20
  export type ItemFormOutletsCtx = Ctx;
20
21
 
22
+ /**
23
+ * An object expressing an outlet to be shown at the top of a record's editing page
24
+ *
25
+ * @see {isItemFormOutlet}
26
+ */
21
27
  export type ItemFormOutlet = {
22
28
  /**
23
29
  * ID of the outlet. Will be the first argument for the `renderItemFormOutlet`
@@ -34,3 +40,17 @@ export type ItemFormOutlet = {
34
40
  /** The initial height to set for the iframe that will render the outlet */
35
41
  initialHeight?: number;
36
42
  };
43
+
44
+ /**
45
+ * Checks if the given value is an ItemFormOutlet.
46
+ * @param value - The value to check.
47
+ * @returns True if the value is an ItemFormOutlet, false otherwise.
48
+ */
49
+ export function isItemFormOutlet(value: unknown): value is ItemFormOutlet {
50
+ return (
51
+ isRecord(value) &&
52
+ isString(value.id) &&
53
+ (isNullish(value.rank) || isNumber(value.rank)) &&
54
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
55
+ );
56
+ }
@@ -1,5 +1,13 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import {
4
+ isBoolean,
5
+ isNullish,
6
+ isNumber,
7
+ isPlacement,
8
+ isRecord,
9
+ isString,
10
+ } from '../guardUtils.js';
3
11
  import { ItemFormSidebarPanelPlacement } from '../shared';
4
12
 
5
13
  type ItemType = SchemaTypes.ItemType;
@@ -19,6 +27,12 @@ export type ItemFormSidebarPanelsHook = {
19
27
 
20
28
  export type ItemFormSidebarPanelsCtx = Ctx;
21
29
 
30
+ /**
31
+ * An object expressing a sidebar panel to be shown when the user
32
+ * edits records of a particular model
33
+ *
34
+ * @see {isItemFormSidebarPanel}
35
+ */
22
36
  export type ItemFormSidebarPanel = {
23
37
  /**
24
38
  * ID of the panel. Will be the first argument for the
@@ -52,3 +66,23 @@ export type ItemFormSidebarPanel = {
52
66
  /** The initial height to set for the iframe that will render the sidebar panel */
53
67
  initialHeight?: number;
54
68
  };
69
+
70
+ /**
71
+ * Checks if the given value is an ItemFormSidebarPanel.
72
+ * @param value - The value to check.
73
+ * @returns True if the value is an ItemFormSidebarPanel, false otherwise.
74
+ */
75
+ export function isItemFormSidebarPanel(
76
+ value: unknown,
77
+ ): value is ItemFormSidebarPanel {
78
+ return (
79
+ isRecord(value) &&
80
+ isString(value.id) &&
81
+ isString(value.label) &&
82
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
83
+ (isNullish(value.startOpen) || isBoolean(value.startOpen)) &&
84
+ (isNullish(value.placement) || isPlacement(value.placement)) &&
85
+ (isNullish(value.rank) || isNumber(value.rank)) &&
86
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
87
+ );
88
+ }
@@ -1,5 +1,6 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import { isNullish, isNumber, isRecord, isString } from '../guardUtils.js';
3
4
 
4
5
  type ItemType = SchemaTypes.ItemType;
5
6
 
@@ -18,6 +19,12 @@ export type ItemFormSidebarsHook = {
18
19
 
19
20
  export type ItemFormSidebarsCtx = Ctx;
20
21
 
22
+ /**
23
+ * An object expressing a sidebar to be shown when the user edits
24
+ * records of a particular model
25
+ *
26
+ * @see {isItemFormSidebar}
27
+ */
21
28
  export type ItemFormSidebar = {
22
29
  /**
23
30
  * ID of the sidebar. Will be the first argument for the
@@ -42,3 +49,19 @@ export type ItemFormSidebar = {
42
49
  /** The preferred width for the sidebar */
43
50
  preferredWidth?: number;
44
51
  };
52
+
53
+ /**
54
+ * Type guard to check if the value is an ItemFormSidebar.
55
+ * @param value - The value to check.
56
+ * @returns true if the value is an ItemFormSidebar, false otherwise.
57
+ */
58
+ export function isItemFormSidebar(value: unknown): value is ItemFormSidebar {
59
+ return (
60
+ isRecord(value) &&
61
+ isString(value.id) &&
62
+ isString(value.label) &&
63
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
64
+ (isNullish(value.rank) || isNumber(value.rank)) &&
65
+ (isNullish(value.preferredWidth) || isNumber(value.preferredWidth))
66
+ );
67
+ }
@@ -1,5 +1,12 @@
1
1
  import { Ctx } from '../ctx/base';
2
- import { Icon } from '../icon';
2
+ import {
3
+ isNullish,
4
+ isNumber,
5
+ isPlacement,
6
+ isRecord,
7
+ isString,
8
+ } from '../guardUtils.js';
9
+ import { Icon, isIcon } from '../icon';
3
10
 
4
11
  export type MainNavigationTabsHook = {
5
12
  /**
@@ -13,7 +20,11 @@ export type MainNavigationTabsHook = {
13
20
 
14
21
  export type MainNavigationTabsCtx = Ctx;
15
22
 
16
- /** A tab to be displayed in the top-bar of the UI */
23
+ /**
24
+ * An object expressing a tab to be displayed in the top-bar of the UI
25
+ *
26
+ * @see {isMainNavigationTab}
27
+ */
17
28
  export type MainNavigationTab = {
18
29
  /** Label to be shown. Must be unique. */
19
30
  label: string;
@@ -45,3 +56,22 @@ export type MainNavigationTab = {
45
56
  */
46
57
  rank?: number;
47
58
  };
59
+
60
+ /**
61
+ * Checks if the given value is a MainNavigationTab.
62
+ * @param value The value to check.
63
+ * @returns True if the value is a MainNavigationTab, false otherwise.
64
+ */
65
+ export function isMainNavigationTab(
66
+ value: unknown,
67
+ ): value is MainNavigationTab {
68
+ return (
69
+ isRecord(value) &&
70
+ isString(value.label) &&
71
+ isIcon(value.icon) &&
72
+ isRecord(value.pointsTo) &&
73
+ isString(value.pointsTo.pageId) &&
74
+ (isNullish(value.placement) || isPlacement(value.placement)) &&
75
+ (isNullish(value.rank) || isNumber(value.rank))
76
+ );
77
+ }
@@ -1,4 +1,12 @@
1
1
  import { Ctx } from '../ctx/base';
2
+ import {
3
+ isArray,
4
+ isBoolean,
5
+ isNullish,
6
+ isNumber,
7
+ isRecord,
8
+ isString,
9
+ } from '../guardUtils.js';
2
10
 
3
11
  export type ManualFieldExtensionsHook = {
4
12
  /**
@@ -14,6 +22,12 @@ export type ManualFieldExtensionsHook = {
14
22
 
15
23
  export type ManualFieldExtensionsCtx = Ctx;
16
24
 
25
+ /**
26
+ * An object expressing a field extension that users will be able
27
+ * to install manually in some field
28
+ *
29
+ * @see {isManualFieldExtension}
30
+ */
17
31
  export type ManualFieldExtension = {
18
32
  /**
19
33
  * ID of field extension. Will be the first argument for the
@@ -80,3 +94,31 @@ export type FieldType =
80
94
  | 'structured_text'
81
95
  | 'text'
82
96
  | 'video';
97
+
98
+ /**
99
+ * Checks if the provided value is a ManualFieldExtension.
100
+ * @param value - The value to check.
101
+ * @returns True if the value is a ManualFieldExtension, otherwise false.
102
+ */
103
+ export function isManualFieldExtension(
104
+ value: unknown,
105
+ ): value is ManualFieldExtension {
106
+ return (
107
+ isRecord(value) &&
108
+ isString(value.id) &&
109
+ isString(value.name) &&
110
+ isString(value.type) &&
111
+ ['editor', 'addon'].includes(value.type) &&
112
+ (isNullish(value.asSidebarPanel) ||
113
+ isBoolean(value.asSidebarPanel) ||
114
+ (isRecord(value.asSidebarPanel) &&
115
+ isBoolean(value.asSidebarPanel.startOpen))) &&
116
+ ((isString(value.fieldTypes) && value.fieldTypes === 'all') ||
117
+ isArray(value.fieldTypes, isString)) &&
118
+ (isNullish(value.configurable) ||
119
+ isBoolean(value.configurable) ||
120
+ (isRecord(value.configurable) &&
121
+ isNumber(value.configurable.initialHeight))) &&
122
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
123
+ );
124
+ }
@@ -1,5 +1,14 @@
1
1
  import type { SchemaTypes } from '@datocms/cma-client';
2
2
  import { Ctx } from '../ctx/base';
3
+ import {
4
+ isArray,
5
+ isBoolean,
6
+ isNullish,
7
+ isNumber,
8
+ isPlacement,
9
+ isRecord,
10
+ isString,
11
+ } from '../guardUtils.js';
3
12
  import { ItemFormSidebarPanelPlacement } from '../shared';
4
13
 
5
14
  type Field = SchemaTypes.Field;
@@ -25,6 +34,8 @@ export type OverrideFieldExtensionsCtx = Ctx<{
25
34
  /**
26
35
  * An object expressing some field extensions you want to force on a particular
27
36
  * field
37
+ *
38
+ * @see {isFieldExtensionOverride}
28
39
  */
29
40
  export type FieldExtensionOverride = {
30
41
  /** Force a field editor/sidebar extension on a field */
@@ -93,3 +104,56 @@ export type AddonOverride = {
93
104
  */
94
105
  initialHeight?: number;
95
106
  };
107
+
108
+ /**
109
+ * Checks if the value is a FieldExtensionOverride.
110
+ * @param value The value to check.
111
+ * @returns True if the value is a FieldExtensionOverride, false otherwise.
112
+ */
113
+ export function isFieldExtensionOverride(
114
+ value: unknown,
115
+ ): value is FieldExtensionOverride {
116
+ return (
117
+ isNullish(value) ||
118
+ (isRecord(value) &&
119
+ (isNullish(value.editor) || isEditorOverride(value.editor)) &&
120
+ (isNullish(value.addons) || isArray(value.addons, isAddonOverride)))
121
+ );
122
+ }
123
+
124
+ /**
125
+ * Checks if the value is an EditorOverride.
126
+ * @param value The value to check.
127
+ * @returns True if the value is an EditorOverride, false otherwise.
128
+ */
129
+ export function isEditorOverride(value: unknown): value is EditorOverride {
130
+ return (
131
+ isRecord(value) &&
132
+ isString(value.id) &&
133
+ (isNullish(value.asSidebarPanel) ||
134
+ isBoolean(value.asSidebarPanel) ||
135
+ (isRecord(value.asSidebarPanel) &&
136
+ (isNullish(value.asSidebarPanel.startOpen) ||
137
+ isBoolean(value.asSidebarPanel.startOpen)) &&
138
+ (isNullish(value.asSidebarPanel.placement) ||
139
+ isPlacement(value.asSidebarPanel.placement)))) &&
140
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
141
+ (isNullish(value.rank) || isNumber(value.rank)) &&
142
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
143
+ );
144
+ }
145
+
146
+ /**
147
+ * Checks if the value is an AddonOverride.
148
+ * @param value The value to check.
149
+ * @returns True if the value is an AddonOverride, false otherwise.
150
+ */
151
+ export function isAddonOverride(value: unknown): value is AddonOverride {
152
+ return (
153
+ isRecord(value) &&
154
+ isString(value.id) &&
155
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
156
+ (isNullish(value.rank) || isNumber(value.rank)) &&
157
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
158
+ );
159
+ }
@@ -1,10 +1,13 @@
1
+ import type { SchemaTypes } from '@datocms/cma-client';
1
2
  import { SelfResizingPluginFrameCtx } from '../ctx/pluginFrame';
2
3
  import { containedRenderModeBootstrapper } from '../utils';
3
4
 
5
+ type ItemType = SchemaTypes.ItemType;
6
+
4
7
  export type RenderItemCollectionOutletHook = {
5
8
  /**
6
9
  * This function will be called when the plugin needs to render an outlet
7
- * defined by the `itemFormOutlets()` hook.
10
+ * defined by the `itemCollectionOutlets()` hook.
8
11
  *
9
12
  * @tag outlets
10
13
  */
@@ -19,6 +22,8 @@ export type RenderItemCollectionOutletCtx = SelfResizingPluginFrameCtx<
19
22
  {
20
23
  /** The ID of the outlet that needs to be rendered */
21
24
  itemCollectionOutletId: string;
25
+ /** The model for which the outlet is being rendered */
26
+ itemType: ItemType;
22
27
  }
23
28
  >;
24
29
 
@@ -1,4 +1,12 @@
1
1
  import { Ctx } from '../ctx/base';
2
+ import {
3
+ isBoolean,
4
+ isNullish,
5
+ isNumber,
6
+ isPlacement,
7
+ isRecord,
8
+ isString,
9
+ } from '../guardUtils.js';
2
10
 
3
11
  export type UploadSidebarPanelsHook = {
4
12
  /**
@@ -12,6 +20,12 @@ export type UploadSidebarPanelsHook = {
12
20
 
13
21
  export type UploadSidebarPanelsCtx = Ctx;
14
22
 
23
+ /**
24
+ * An object expressing a sidebar panel to be shown when the user
25
+ * opens up an asset in the Media Area
26
+ *
27
+ * @see {isUploadSidebarPanel}
28
+ */
15
29
  export type UploadSidebarPanel = {
16
30
  /**
17
31
  * ID of the panel. Will be the first argument for the
@@ -57,3 +71,23 @@ export type UploadSidebarPanelPlacement = [
57
71
  | 'replace'
58
72
  ),
59
73
  ];
74
+
75
+ /**
76
+ * Type guard for UploadSidebarPanel
77
+ * @param value - The value to check
78
+ * @returns True if the value is an UploadSidebarPanel
79
+ */
80
+ export function isUploadSidebarPanel(
81
+ value: unknown,
82
+ ): value is UploadSidebarPanel {
83
+ return (
84
+ isRecord(value) &&
85
+ isString(value.id) &&
86
+ isString(value.label) &&
87
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
88
+ (isNullish(value.startOpen) || isBoolean(value.startOpen)) &&
89
+ (isNullish(value.placement) || isPlacement(value.placement)) &&
90
+ (isNullish(value.rank) || isNumber(value.rank)) &&
91
+ (isNullish(value.initialHeight) || isNumber(value.initialHeight))
92
+ );
93
+ }
@@ -1,4 +1,5 @@
1
1
  import { Ctx } from '../ctx/base';
2
+ import { isNullish, isNumber, isRecord, isString } from '../guardUtils.js';
2
3
 
3
4
  export type UploadSidebarsHook = {
4
5
  /**
@@ -12,6 +13,12 @@ export type UploadSidebarsHook = {
12
13
 
13
14
  export type UploadSidebarsCtx = Ctx;
14
15
 
16
+ /**
17
+ * An object expressing a sidebar to be shown when the user opens
18
+ * up an asset in the Media Area
19
+ *
20
+ * @see {isUploadSidebar}
21
+ */
15
22
  export type UploadSidebar = {
16
23
  /**
17
24
  * ID of the sidebar. Will be the first argument for the
@@ -36,3 +43,19 @@ export type UploadSidebar = {
36
43
  /** The preferred width for the sidebar */
37
44
  preferredWidth?: number;
38
45
  };
46
+
47
+ /**
48
+ * Checks if the provided value is an UploadSidebar.
49
+ * @param value - The value to check.
50
+ * @returns True if the value is an UploadSidebar, otherwise false.
51
+ */
52
+ export function isUploadSidebar(value: unknown): value is UploadSidebar {
53
+ return (
54
+ isRecord(value) &&
55
+ isString(value.id) &&
56
+ isString(value.label) &&
57
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
58
+ (isNullish(value.rank) || isNumber(value.rank)) &&
59
+ (isNullish(value.preferredWidth) || isNumber(value.preferredWidth))
60
+ );
61
+ }