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
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: {
@@ -1150,7 +1150,7 @@ export const manifest: Manifest = {
1150
1150
  name: 'renderItemCollectionOutlet',
1151
1151
  comment: {
1152
1152
  markdownText:
1153
- 'This function will be called when the plugin needs to render an outlet\ndefined by the `itemFormOutlets()` hook.',
1153
+ 'This function will be called when the plugin needs to render an outlet\ndefined by the `itemCollectionOutlets()` hook.',
1154
1154
  tag: 'outlets',
1155
1155
  },
1156
1156
  nonCtxArguments: [
@@ -1171,10 +1171,21 @@ export const manifest: Manifest = {
1171
1171
  },
1172
1172
  location: {
1173
1173
  filePath: 'src/hooks/renderItemCollectionOutlet.ts',
1174
- lineNumber: 21,
1174
+ lineNumber: 24,
1175
1175
  },
1176
1176
  type: 'string',
1177
1177
  },
1178
+ itemType: {
1179
+ comment: {
1180
+ markdownText:
1181
+ 'The model for which the outlet is being rendered.',
1182
+ },
1183
+ location: {
1184
+ filePath: 'src/hooks/renderItemCollectionOutlet.ts',
1185
+ lineNumber: 26,
1186
+ },
1187
+ type: 'ItemType',
1188
+ },
1178
1189
  },
1179
1190
  },
1180
1191
  ],
@@ -1183,7 +1194,7 @@ export const manifest: Manifest = {
1183
1194
  returnType: 'void',
1184
1195
  location: {
1185
1196
  filePath: 'src/hooks/renderItemCollectionOutlet.ts',
1186
- lineNumber: 11,
1197
+ lineNumber: 14,
1187
1198
  },
1188
1199
  },
1189
1200
  renderFieldExtension: {
@@ -1590,7 +1601,7 @@ export const manifest: Manifest = {
1590
1601
  itemType: {
1591
1602
  location: {
1592
1603
  filePath: 'src/hooks/overrideFieldExtensions.ts',
1593
- lineNumber: 22,
1604
+ lineNumber: 31,
1594
1605
  },
1595
1606
  type: 'ItemType',
1596
1607
  },
@@ -1602,7 +1613,7 @@ export const manifest: Manifest = {
1602
1613
  returnType: 'FieldExtensionOverride | undefined',
1603
1614
  location: {
1604
1615
  filePath: 'src/hooks/overrideFieldExtensions.ts',
1605
- lineNumber: 15,
1616
+ lineNumber: 24,
1606
1617
  },
1607
1618
  },
1608
1619
  onBoot: {
@@ -1736,7 +1747,7 @@ export const manifest: Manifest = {
1736
1747
  returnType: 'ManualFieldExtension[]',
1737
1748
  location: {
1738
1749
  filePath: 'src/hooks/manualFieldExtensions.ts',
1739
- lineNumber: 10,
1750
+ lineNumber: 18,
1740
1751
  },
1741
1752
  },
1742
1753
  mainNavigationTabs: {
@@ -1755,7 +1766,7 @@ export const manifest: Manifest = {
1755
1766
  returnType: 'MainNavigationTab[]',
1756
1767
  location: {
1757
1768
  filePath: 'src/hooks/mainNavigationTabs.ts',
1758
- lineNumber: 11,
1769
+ lineNumber: 18,
1759
1770
  },
1760
1771
  },
1761
1772
  itemsDropdownActions: {
@@ -1815,7 +1826,7 @@ export const manifest: Manifest = {
1815
1826
  returnType: 'ItemFormSidebar[]',
1816
1827
  location: {
1817
1828
  filePath: 'src/hooks/itemFormSidebars.ts',
1818
- lineNumber: 13,
1829
+ lineNumber: 14,
1819
1830
  },
1820
1831
  },
1821
1832
  itemFormSidebarPanels: {
@@ -1839,7 +1850,7 @@ export const manifest: Manifest = {
1839
1850
  returnType: 'ItemFormSidebarPanel[]',
1840
1851
  location: {
1841
1852
  filePath: 'src/hooks/itemFormSidebarPanels.ts',
1842
- lineNumber: 14,
1853
+ lineNumber: 22,
1843
1854
  },
1844
1855
  },
1845
1856
  itemFormOutlets: {
@@ -1863,7 +1874,7 @@ export const manifest: Manifest = {
1863
1874
  returnType: 'ItemFormOutlet[]',
1864
1875
  location: {
1865
1876
  filePath: 'src/hooks/itemFormOutlets.ts',
1866
- lineNumber: 13,
1877
+ lineNumber: 14,
1867
1878
  },
1868
1879
  },
1869
1880
  itemFormDropdownActions: {
@@ -2006,7 +2017,7 @@ export const manifest: Manifest = {
2006
2017
  returnType: 'ItemCollectionOutlet[]',
2007
2018
  location: {
2008
2019
  filePath: 'src/hooks/itemCollectionOutlets.ts',
2009
- lineNumber: 13,
2020
+ lineNumber: 14,
2010
2021
  },
2011
2022
  },
2012
2023
  initialLocationQueryForItemSelector: {
@@ -2840,7 +2851,7 @@ export const manifest: Manifest = {
2840
2851
  itemType: {
2841
2852
  location: {
2842
2853
  filePath: 'src/hooks/customMarksForStructuredTextField.ts',
2843
- lineNumber: 22,
2854
+ lineNumber: 29,
2844
2855
  },
2845
2856
  type: 'ItemType',
2846
2857
  },
@@ -2852,7 +2863,7 @@ export const manifest: Manifest = {
2852
2863
  returnType: 'StructuredTextCustomMark[] | undefined',
2853
2864
  location: {
2854
2865
  filePath: 'src/hooks/customMarksForStructuredTextField.ts',
2855
- lineNumber: 15,
2866
+ lineNumber: 22,
2856
2867
  },
2857
2868
  },
2858
2869
  customBlockStylesForStructuredTextField: {
@@ -2877,7 +2888,7 @@ export const manifest: Manifest = {
2877
2888
  location: {
2878
2889
  filePath:
2879
2890
  'src/hooks/customBlockStylesForStructuredTextField.ts',
2880
- lineNumber: 22,
2891
+ lineNumber: 23,
2881
2892
  },
2882
2893
  type: 'ItemType',
2883
2894
  },
@@ -2889,7 +2900,7 @@ export const manifest: Manifest = {
2889
2900
  returnType: 'StructuredTextCustomBlockStyle[] | undefined',
2890
2901
  location: {
2891
2902
  filePath: 'src/hooks/customBlockStylesForStructuredTextField.ts',
2892
- lineNumber: 15,
2903
+ lineNumber: 16,
2893
2904
  },
2894
2905
  },
2895
2906
  contentAreaSidebarItems: {
@@ -2908,7 +2919,7 @@ export const manifest: Manifest = {
2908
2919
  returnType: 'ContentAreaSidebarItem[]',
2909
2920
  location: {
2910
2921
  filePath: 'src/hooks/contentAreaSidebarItems.ts',
2911
- lineNumber: 10,
2922
+ lineNumber: 17,
2912
2923
  },
2913
2924
  },
2914
2925
  buildItemPresentationInfo: {
@@ -2932,7 +2943,7 @@ export const manifest: Manifest = {
2932
2943
  returnType: 'MaybePromise<ItemPresentationInfo | undefined>',
2933
2944
  location: {
2934
2945
  filePath: 'src/hooks/buildItemPresentationInfo.ts',
2935
- lineNumber: 14,
2946
+ lineNumber: 15,
2936
2947
  },
2937
2948
  },
2938
2949
  assetSources: {
@@ -2951,7 +2962,7 @@ export const manifest: Manifest = {
2951
2962
  returnType: 'AssetSource[] | undefined',
2952
2963
  location: {
2953
2964
  filePath: 'src/hooks/assetSources.ts',
2954
- lineNumber: 11,
2965
+ lineNumber: 12,
2955
2966
  },
2956
2967
  },
2957
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
+ }