datocms-plugin-sdk 2.0.4 → 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 (131) 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/uploadSidebarPanels.js +17 -0
  30. package/dist/cjs/hooks/uploadSidebarPanels.js.map +1 -1
  31. package/dist/cjs/hooks/uploadSidebars.js +15 -0
  32. package/dist/cjs/hooks/uploadSidebars.js.map +1 -1
  33. package/dist/cjs/icon.js +9 -0
  34. package/dist/cjs/icon.js.map +1 -1
  35. package/dist/cjs/manifest.js +17 -17
  36. package/dist/cjs/shared.js +25 -0
  37. package/dist/cjs/shared.js.map +1 -1
  38. package/dist/esm/guardUtils.d.ts +7 -0
  39. package/dist/esm/guardUtils.js +24 -0
  40. package/dist/esm/guardUtils.js.map +1 -0
  41. package/dist/esm/hooks/assetSources.d.ts +11 -1
  42. package/dist/esm/hooks/assetSources.js +24 -1
  43. package/dist/esm/hooks/assetSources.js.map +1 -1
  44. package/dist/esm/hooks/buildItemPresentationInfo.d.ts +11 -0
  45. package/dist/esm/hooks/buildItemPresentationInfo.js +12 -1
  46. package/dist/esm/hooks/buildItemPresentationInfo.js.map +1 -1
  47. package/dist/esm/hooks/contentAreaSidebarItems.d.ts +11 -0
  48. package/dist/esm/hooks/contentAreaSidebarItems.js +16 -1
  49. package/dist/esm/hooks/contentAreaSidebarItems.js.map +1 -1
  50. package/dist/esm/hooks/customBlockStylesForStructuredTextField.d.ts +11 -1
  51. package/dist/esm/hooks/customBlockStylesForStructuredTextField.js +13 -1
  52. package/dist/esm/hooks/customBlockStylesForStructuredTextField.js.map +1 -1
  53. package/dist/esm/hooks/customMarksForStructuredTextField.d.ts +11 -1
  54. package/dist/esm/hooks/customMarksForStructuredTextField.js +17 -1
  55. package/dist/esm/hooks/customMarksForStructuredTextField.js.map +1 -1
  56. package/dist/esm/hooks/initialLocationQueryForItemSelector.d.ts +11 -0
  57. package/dist/esm/hooks/initialLocationQueryForItemSelector.js +11 -1
  58. package/dist/esm/hooks/initialLocationQueryForItemSelector.js.map +1 -1
  59. package/dist/esm/hooks/itemCollectionOutlets.d.ts +11 -1
  60. package/dist/esm/hooks/itemCollectionOutlets.js +12 -1
  61. package/dist/esm/hooks/itemCollectionOutlets.js.map +1 -1
  62. package/dist/esm/hooks/itemFormOutlets.d.ts +11 -0
  63. package/dist/esm/hooks/itemFormOutlets.js +12 -1
  64. package/dist/esm/hooks/itemFormOutlets.js.map +1 -1
  65. package/dist/esm/hooks/itemFormSidebarPanels.d.ts +12 -0
  66. package/dist/esm/hooks/itemFormSidebarPanels.js +16 -1
  67. package/dist/esm/hooks/itemFormSidebarPanels.js.map +1 -1
  68. package/dist/esm/hooks/itemFormSidebars.d.ts +12 -0
  69. package/dist/esm/hooks/itemFormSidebars.js +14 -1
  70. package/dist/esm/hooks/itemFormSidebars.js.map +1 -1
  71. package/dist/esm/hooks/mainNavigationTabs.d.ts +11 -1
  72. package/dist/esm/hooks/mainNavigationTabs.js +16 -1
  73. package/dist/esm/hooks/mainNavigationTabs.js.map +1 -1
  74. package/dist/esm/hooks/manualFieldExtensions.d.ts +12 -0
  75. package/dist/esm/hooks/manualFieldExtensions.js +24 -1
  76. package/dist/esm/hooks/manualFieldExtensions.js.map +1 -1
  77. package/dist/esm/hooks/overrideFieldExtensions.d.ts +20 -0
  78. package/dist/esm/hooks/overrideFieldExtensions.js +43 -1
  79. package/dist/esm/hooks/overrideFieldExtensions.js.map +1 -1
  80. package/dist/esm/hooks/uploadSidebarPanels.d.ts +12 -0
  81. package/dist/esm/hooks/uploadSidebarPanels.js +16 -1
  82. package/dist/esm/hooks/uploadSidebarPanels.js.map +1 -1
  83. package/dist/esm/hooks/uploadSidebars.d.ts +12 -0
  84. package/dist/esm/hooks/uploadSidebars.js +14 -1
  85. package/dist/esm/hooks/uploadSidebars.js.map +1 -1
  86. package/dist/esm/icon.d.ts +1 -0
  87. package/dist/esm/icon.js +8 -1
  88. package/dist/esm/icon.js.map +1 -1
  89. package/dist/esm/manifest.js +17 -17
  90. package/dist/esm/shared.d.ts +12 -0
  91. package/dist/esm/shared.js +23 -1
  92. package/dist/esm/shared.js.map +1 -1
  93. package/dist/types/guardUtils.d.ts +7 -0
  94. package/dist/types/hooks/assetSources.d.ts +11 -1
  95. package/dist/types/hooks/buildItemPresentationInfo.d.ts +11 -0
  96. package/dist/types/hooks/contentAreaSidebarItems.d.ts +11 -0
  97. package/dist/types/hooks/customBlockStylesForStructuredTextField.d.ts +11 -1
  98. package/dist/types/hooks/customMarksForStructuredTextField.d.ts +11 -1
  99. package/dist/types/hooks/initialLocationQueryForItemSelector.d.ts +11 -0
  100. package/dist/types/hooks/itemCollectionOutlets.d.ts +11 -1
  101. package/dist/types/hooks/itemFormOutlets.d.ts +11 -0
  102. package/dist/types/hooks/itemFormSidebarPanels.d.ts +12 -0
  103. package/dist/types/hooks/itemFormSidebars.d.ts +12 -0
  104. package/dist/types/hooks/mainNavigationTabs.d.ts +11 -1
  105. package/dist/types/hooks/manualFieldExtensions.d.ts +12 -0
  106. package/dist/types/hooks/overrideFieldExtensions.d.ts +20 -0
  107. package/dist/types/hooks/uploadSidebarPanels.d.ts +12 -0
  108. package/dist/types/hooks/uploadSidebars.d.ts +12 -0
  109. package/dist/types/icon.d.ts +1 -0
  110. package/dist/types/shared.d.ts +12 -0
  111. package/manifest.json +17 -17
  112. package/package.json +2 -2
  113. package/src/guardUtils.ts +34 -0
  114. package/src/hooks/assetSources.ts +32 -2
  115. package/src/hooks/buildItemPresentationInfo.ts +22 -0
  116. package/src/hooks/contentAreaSidebarItems.ts +32 -1
  117. package/src/hooks/customBlockStylesForStructuredTextField.ts +23 -1
  118. package/src/hooks/customMarksForStructuredTextField.ts +33 -2
  119. package/src/hooks/initialLocationQueryForItemSelector.ts +21 -1
  120. package/src/hooks/itemCollectionOutlets.ts +22 -1
  121. package/src/hooks/itemFormOutlets.ts +20 -0
  122. package/src/hooks/itemFormSidebarPanels.ts +34 -0
  123. package/src/hooks/itemFormSidebars.ts +23 -0
  124. package/src/hooks/mainNavigationTabs.ts +32 -2
  125. package/src/hooks/manualFieldExtensions.ts +42 -0
  126. package/src/hooks/overrideFieldExtensions.ts +64 -0
  127. package/src/hooks/uploadSidebarPanels.ts +34 -0
  128. package/src/hooks/uploadSidebars.ts +23 -0
  129. package/src/icon.ts +12 -0
  130. package/src/manifest.ts +17 -17
  131. package/src/shared.ts +48 -1
@@ -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,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
+ }
package/src/icon.ts CHANGED
@@ -1,7 +1,19 @@
1
+ import { isRecord, isString } from './guardUtils.js';
2
+
1
3
  export type Icon =
2
4
  | AwesomeFontIconIdentifier
3
5
  | { type: 'svg'; viewBox: string; content: string };
4
6
 
7
+ export function isIcon(value: unknown): value is Icon {
8
+ return (
9
+ isString(value) ||
10
+ (isRecord(value) &&
11
+ value.type === 'svg' &&
12
+ isString(value.viewBox) &&
13
+ isString(value.content))
14
+ );
15
+ }
16
+
5
17
  export type AwesomeFontIconIdentifier =
6
18
  | '0'
7
19
  | '00'
package/src/manifest.ts CHANGED
@@ -60,7 +60,7 @@ export const manifest: Manifest = {
60
60
  returnType: 'UploadSidebar[]',
61
61
  location: {
62
62
  filePath: 'src/hooks/uploadSidebars.ts',
63
- lineNumber: 10,
63
+ lineNumber: 11,
64
64
  },
65
65
  },
66
66
  uploadSidebarPanels: {
@@ -79,7 +79,7 @@ export const manifest: Manifest = {
79
79
  returnType: 'UploadSidebarPanel[]',
80
80
  location: {
81
81
  filePath: 'src/hooks/uploadSidebarPanels.ts',
82
- lineNumber: 10,
82
+ lineNumber: 18,
83
83
  },
84
84
  },
85
85
  settingsAreaSidebarItemGroups: {
@@ -1601,7 +1601,7 @@ export const manifest: Manifest = {
1601
1601
  itemType: {
1602
1602
  location: {
1603
1603
  filePath: 'src/hooks/overrideFieldExtensions.ts',
1604
- lineNumber: 22,
1604
+ lineNumber: 31,
1605
1605
  },
1606
1606
  type: 'ItemType',
1607
1607
  },
@@ -1613,7 +1613,7 @@ export const manifest: Manifest = {
1613
1613
  returnType: 'FieldExtensionOverride | undefined',
1614
1614
  location: {
1615
1615
  filePath: 'src/hooks/overrideFieldExtensions.ts',
1616
- lineNumber: 15,
1616
+ lineNumber: 24,
1617
1617
  },
1618
1618
  },
1619
1619
  onBoot: {
@@ -1747,7 +1747,7 @@ export const manifest: Manifest = {
1747
1747
  returnType: 'ManualFieldExtension[]',
1748
1748
  location: {
1749
1749
  filePath: 'src/hooks/manualFieldExtensions.ts',
1750
- lineNumber: 10,
1750
+ lineNumber: 18,
1751
1751
  },
1752
1752
  },
1753
1753
  mainNavigationTabs: {
@@ -1766,7 +1766,7 @@ export const manifest: Manifest = {
1766
1766
  returnType: 'MainNavigationTab[]',
1767
1767
  location: {
1768
1768
  filePath: 'src/hooks/mainNavigationTabs.ts',
1769
- lineNumber: 11,
1769
+ lineNumber: 18,
1770
1770
  },
1771
1771
  },
1772
1772
  itemsDropdownActions: {
@@ -1826,7 +1826,7 @@ export const manifest: Manifest = {
1826
1826
  returnType: 'ItemFormSidebar[]',
1827
1827
  location: {
1828
1828
  filePath: 'src/hooks/itemFormSidebars.ts',
1829
- lineNumber: 13,
1829
+ lineNumber: 14,
1830
1830
  },
1831
1831
  },
1832
1832
  itemFormSidebarPanels: {
@@ -1850,7 +1850,7 @@ export const manifest: Manifest = {
1850
1850
  returnType: 'ItemFormSidebarPanel[]',
1851
1851
  location: {
1852
1852
  filePath: 'src/hooks/itemFormSidebarPanels.ts',
1853
- lineNumber: 14,
1853
+ lineNumber: 22,
1854
1854
  },
1855
1855
  },
1856
1856
  itemFormOutlets: {
@@ -1874,7 +1874,7 @@ export const manifest: Manifest = {
1874
1874
  returnType: 'ItemFormOutlet[]',
1875
1875
  location: {
1876
1876
  filePath: 'src/hooks/itemFormOutlets.ts',
1877
- lineNumber: 13,
1877
+ lineNumber: 14,
1878
1878
  },
1879
1879
  },
1880
1880
  itemFormDropdownActions: {
@@ -2017,7 +2017,7 @@ export const manifest: Manifest = {
2017
2017
  returnType: 'ItemCollectionOutlet[]',
2018
2018
  location: {
2019
2019
  filePath: 'src/hooks/itemCollectionOutlets.ts',
2020
- lineNumber: 13,
2020
+ lineNumber: 14,
2021
2021
  },
2022
2022
  },
2023
2023
  initialLocationQueryForItemSelector: {
@@ -2851,7 +2851,7 @@ export const manifest: Manifest = {
2851
2851
  itemType: {
2852
2852
  location: {
2853
2853
  filePath: 'src/hooks/customMarksForStructuredTextField.ts',
2854
- lineNumber: 22,
2854
+ lineNumber: 29,
2855
2855
  },
2856
2856
  type: 'ItemType',
2857
2857
  },
@@ -2863,7 +2863,7 @@ export const manifest: Manifest = {
2863
2863
  returnType: 'StructuredTextCustomMark[] | undefined',
2864
2864
  location: {
2865
2865
  filePath: 'src/hooks/customMarksForStructuredTextField.ts',
2866
- lineNumber: 15,
2866
+ lineNumber: 22,
2867
2867
  },
2868
2868
  },
2869
2869
  customBlockStylesForStructuredTextField: {
@@ -2888,7 +2888,7 @@ export const manifest: Manifest = {
2888
2888
  location: {
2889
2889
  filePath:
2890
2890
  'src/hooks/customBlockStylesForStructuredTextField.ts',
2891
- lineNumber: 22,
2891
+ lineNumber: 23,
2892
2892
  },
2893
2893
  type: 'ItemType',
2894
2894
  },
@@ -2900,7 +2900,7 @@ export const manifest: Manifest = {
2900
2900
  returnType: 'StructuredTextCustomBlockStyle[] | undefined',
2901
2901
  location: {
2902
2902
  filePath: 'src/hooks/customBlockStylesForStructuredTextField.ts',
2903
- lineNumber: 15,
2903
+ lineNumber: 16,
2904
2904
  },
2905
2905
  },
2906
2906
  contentAreaSidebarItems: {
@@ -2919,7 +2919,7 @@ export const manifest: Manifest = {
2919
2919
  returnType: 'ContentAreaSidebarItem[]',
2920
2920
  location: {
2921
2921
  filePath: 'src/hooks/contentAreaSidebarItems.ts',
2922
- lineNumber: 10,
2922
+ lineNumber: 17,
2923
2923
  },
2924
2924
  },
2925
2925
  buildItemPresentationInfo: {
@@ -2943,7 +2943,7 @@ export const manifest: Manifest = {
2943
2943
  returnType: 'MaybePromise<ItemPresentationInfo | undefined>',
2944
2944
  location: {
2945
2945
  filePath: 'src/hooks/buildItemPresentationInfo.ts',
2946
- lineNumber: 14,
2946
+ lineNumber: 15,
2947
2947
  },
2948
2948
  },
2949
2949
  assetSources: {
@@ -2962,7 +2962,7 @@ export const manifest: Manifest = {
2962
2962
  returnType: 'AssetSource[] | undefined',
2963
2963
  location: {
2964
2964
  filePath: 'src/hooks/assetSources.ts',
2965
- lineNumber: 11,
2965
+ lineNumber: 12,
2966
2966
  },
2967
2967
  },
2968
2968
  },
package/src/shared.ts CHANGED
@@ -1,5 +1,18 @@
1
- import { Icon } from './icon';
1
+ import {
2
+ isArray,
3
+ isBoolean,
4
+ isNullish,
5
+ isNumber,
6
+ isRecord,
7
+ isString,
8
+ } from './guardUtils.js';
9
+ import { Icon, isIcon } from './icon';
2
10
 
11
+ /**
12
+ * An object expressing a dropdown action to be shown in the interface
13
+ *
14
+ * @see {isDropdownAction}
15
+ */
3
16
  export type DropdownAction = {
4
17
  /**
5
18
  * ID of action. Will be the first argument for the
@@ -38,6 +51,11 @@ export type DropdownAction = {
38
51
  rank?: number;
39
52
  };
40
53
 
54
+ /**
55
+ * An object expressing a dropdown submenu containing actions to be shown in the interface
56
+ *
57
+ * @see {isDropdownActionGroup}
58
+ */
41
59
  export type DropdownActionGroup = {
42
60
  /** Label to be shown. Must be unique. */
43
61
  label: string;
@@ -65,3 +83,32 @@ export type ItemFormSidebarPanelPlacement = [
65
83
  'before' | 'after',
66
84
  'info' | 'publishedVersion' | 'schedule' | 'links' | 'history',
67
85
  ];
86
+
87
+ export function isDropdownAction(value: unknown): value is DropdownAction {
88
+ if (!isRecord(value)) return false;
89
+
90
+ return (
91
+ isString(value.id) &&
92
+ (isNullish(value.parameters) || isRecord(value.parameters)) &&
93
+ isString(value.label) &&
94
+ isIcon(value.icon) &&
95
+ (isNullish(value.active) || isBoolean(value.active)) &&
96
+ (isNullish(value.alert) || isBoolean(value.alert)) &&
97
+ (isNullish(value.disabled) || isBoolean(value.disabled)) &&
98
+ (isNullish(value.closeMenuOnClick) || isBoolean(value.closeMenuOnClick)) &&
99
+ (isNullish(value.rank) || isNumber(value.rank))
100
+ );
101
+ }
102
+
103
+ export function isDropdownActionGroup(
104
+ value: unknown,
105
+ ): value is DropdownActionGroup {
106
+ if (!isRecord(value)) return false;
107
+
108
+ return (
109
+ isString(value.label) &&
110
+ isIcon(value.icon) &&
111
+ isArray(value.actions, isDropdownAction) &&
112
+ (isNullish(value.rank) || isNumber(value.rank))
113
+ );
114
+ }