datocms-plugin-sdk 0.3.30 → 0.3.34-alpha.1

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.
package/src/types.ts CHANGED
@@ -1,10 +1,19 @@
1
+ import {
2
+ BlockquoteType,
3
+ CodeType,
4
+ HeadingType,
5
+ ListType,
6
+ ParagraphType,
7
+ ThematicBreakType,
8
+ } from 'datocms-structured-text-utils';
9
+
1
10
  import {
2
11
  Account,
3
12
  Field,
13
+ Fieldset,
4
14
  Item,
5
15
  ModelBlock,
6
16
  Plugin,
7
- PluginAttributes,
8
17
  Role,
9
18
  Site,
10
19
  SsoUser,
@@ -42,7 +51,7 @@ export type MainNavigationTab = {
42
51
  * be displayed by ascending `rank`. If you want to specify an explicit value
43
52
  * for `rank`, make sure to offer a way for final users to customize it inside
44
53
  * the plugin's settings form, otherwise the hardcoded value you choose might
45
- * clash with the one of another plugin! *
54
+ * clash with the one of another plugin!
46
55
  */
47
56
  rank?: number;
48
57
  };
@@ -138,6 +147,27 @@ export type ContentAreaSidebarItem = {
138
147
 
139
148
  export type FieldExtensionType = 'editor' | 'addon';
140
149
 
150
+ export type FieldType =
151
+ | 'boolean'
152
+ | 'color'
153
+ | 'date_time'
154
+ | 'date'
155
+ | 'file'
156
+ | 'float'
157
+ | 'gallery'
158
+ | 'integer'
159
+ | 'json'
160
+ | 'lat_lon'
161
+ | 'link'
162
+ | 'links'
163
+ | 'rich_text'
164
+ | 'seo'
165
+ | 'slug'
166
+ | 'string'
167
+ | 'structured_text'
168
+ | 'text'
169
+ | 'video';
170
+
141
171
  /**
142
172
  * Field extensions extend the basic functionality of DatoCMS when it comes to
143
173
  * presenting record's fields to the final user. Depending on the extension type
@@ -163,8 +193,11 @@ export type ManualFieldExtension = {
163
193
  * editing page, mimicking a sidebar panel
164
194
  */
165
195
  asSidebarPanel?: boolean | { startOpen: boolean };
166
- /** The type of fields that the field extension in compatible with */
167
- fieldTypes: NonNullable<PluginAttributes['field_types']> | 'all';
196
+ /**
197
+ * The type of fields that the field extension in compatible with. You can use
198
+ * the shortcut `all` to target all types of fields
199
+ */
200
+ fieldTypes: 'all' | FieldType[];
168
201
  /**
169
202
  * Whether this field extension needs some configuration options before being
170
203
  * installed in a field or not. Will trigger the
@@ -267,6 +300,74 @@ export type AddonOverride = {
267
300
  initialHeight?: number;
268
301
  };
269
302
 
303
+ export type StructuredTextCustomMarkPlacement = [
304
+ 'before' | 'after',
305
+ 'strong' | 'emphasis' | 'underline' | 'code' | 'highlight' | 'strikethrough',
306
+ ];
307
+
308
+ /** An object expressing a custom mark for a Structured Text field */
309
+ export type StructuredTextCustomMark = {
310
+ /** ID of mark */
311
+ id: string;
312
+ /** Label representing the custom mark */
313
+ label: string;
314
+ toolbarButton: {
315
+ /**
316
+ * Icon to be shown alongside the label. Can be a FontAwesome icon name (ie.
317
+ * `"address-book"`) or a custom SVG definition. To maintain visual
318
+ * consistency with the rest of the interface, try to use FontAwesome icons
319
+ * whenever possible
320
+ */
321
+ icon: Icon;
322
+ /**
323
+ * Expresses where you want the custom mark button to be placed inside the
324
+ * toolbar. If not specified, the item will be placed after the standard
325
+ * marks provided by DatoCMS itself.
326
+ */
327
+ placement?: StructuredTextCustomMarkPlacement;
328
+ /**
329
+ * If multiple custom marks specify the same `placement` for their toolbar
330
+ * button, they will be sorted by ascending `rank`. If you want to specify
331
+ * an explicit value for `rank`, make sure to offer a way for final users to
332
+ * customize it inside the plugin's settings form, otherwise the hardcoded
333
+ * value you choose might clash with the one of another plugin!
334
+ */
335
+ rank?: number;
336
+ };
337
+ /**
338
+ * Keyboard shortcut associated with the custom mark, expressed using the
339
+ * https://github.com/ianstormtaylor/is-hotkey syntax (ie. `mod+shift+x`)
340
+ */
341
+ keyboardShortcut?: string;
342
+ /** How the custom mark will be styled inside the editor */
343
+ appliedStyle: React.CSSProperties;
344
+ };
345
+
346
+ /** An object expressing a custom block style for a Structured Text field */
347
+ export type StructuredTextCustomBlockStyle = {
348
+ /** ID of custom block style */
349
+ id: string;
350
+ /** The block node that can apply this style */
351
+ node:
352
+ | ParagraphType
353
+ | HeadingType
354
+ | ListType
355
+ | BlockquoteType
356
+ | CodeType
357
+ | ThematicBreakType;
358
+ /** ID of custom block style */
359
+ label: string;
360
+ /** How the block will be styled inside the editor to represent the style */
361
+ appliedStyle: React.CSSProperties;
362
+ /**
363
+ * Custom styles for a block node will be sorted by ascending `rank`. If you
364
+ * want to specify an explicit value for `rank`, make sure to offer a way for
365
+ * final users to customize it inside the plugin's settings form, otherwise
366
+ * the hardcoded value you choose might clash with the one of another plugin!
367
+ */
368
+ rank?: number;
369
+ };
370
+
270
371
  /** An object expressing some field extensions you want to force on a particular field */
271
372
  export type FieldExtensionOverride = {
272
373
  /** Force a field editor/sidebar extension on a field */
@@ -460,6 +561,14 @@ export type RenderAdditionalProperties = {
460
561
  * to load them.
461
562
  */
462
563
  fields: Partial<Record<string, Field>>;
564
+ /**
565
+ * All the fieldsets currently loaded for the current DatoCMS project, indexed
566
+ * by ID. It will always contain the current model fields and all the fields
567
+ * of the blocks it might contain via Modular Content/Structured Text fields.
568
+ * If some fields you need are not present, use the `loadItemTypeFieldsets`
569
+ * function to load them.
570
+ */
571
+ fieldsets: Partial<Record<string, Fieldset>>;
463
572
  /** An object containing the theme colors for the current DatoCMS project */
464
573
  theme: Theme;
465
574
  /**
@@ -613,6 +722,25 @@ export type LoadDataMethods = {
613
722
  * ```
614
723
  */
615
724
  loadItemTypeFields: (itemTypeId: string) => Promise<Field[]>;
725
+ /**
726
+ * Loads all the fieldsets for a specific model (or block). Fieldsets will be
727
+ * returned and will also be available in the the `fieldsets` property.
728
+ *
729
+ * @example
730
+ *
731
+ * ```js
732
+ * const itemTypeId = prompt('Please insert a model ID:');
733
+ *
734
+ * const fieldsets = await ctx.loadItemTypeFieldsets(itemTypeId);
735
+ *
736
+ * ctx.notice(
737
+ * `Success! ${fieldsets
738
+ * .map((fieldset) => fieldset.attributes.title)
739
+ * .join(', ')}`,
740
+ * );
741
+ * ```
742
+ */
743
+ loadItemTypeFieldsets: (itemTypeId: string) => Promise<Fieldset[]>;
616
744
  /**
617
745
  * Loads all the fields in the project that are currently using the plugin for
618
746
  * one of its manual field extensions.