Skip to content

Commit 928ad5b

Browse files
lehnermKhaledgarbaya
authored andcommitted
feat(editorInterface): Add support for sidebar and entry editor extensions
* Rename entry control methods
1 parent 1882430 commit 928ad5b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+8045
-4329
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ npm-debug.log
2222
.vscode
2323
contentful-migration-cli-*.tgz
2424
errors-*
25+
.idea

README.md

+75-13
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,15 @@
7575
- [`editField(id[, opts])` : [Field](#field)](#editfieldid-opts--fieldfield)
7676
- [`deleteField(id)` : void](#deletefieldid--void)
7777
- [`changeFieldId (currentId, newId)` : void](#changefieldid-currentid-newid--void)
78-
- [`changeEditorInterface (fieldId, widgetId[, settings])` : void](#changeeditorinterface-fieldid-widgetid-settings--void)
79-
- [`resetEditorInterface (fieldId)` : void](#reseteditorinterface-fieldid--void)
80-
- [`copyEditorInterface (sourceFieldId, destinationFieldId)` : void](#copyeditorinterface-sourcefieldid-destinationfieldid--void)
78+
- [`changeFieldControl (fieldId, widgetNamespace, widgetId[, settings])` : void](#changefieldcontrol-fieldid-widgetid-widgetnamespace-settings--void)
79+
- [`resetFieldControl (fieldId)` : void](#resetfieldcontrol-fieldid--void)
80+
- [`copyFieldControl (sourceFieldId, destinationFieldId)` : void](#copyfieldcontrol-sourcefieldid-destinationfieldid--void)
81+
- [`addSidebarWidget (widgetNamespace, widgetId[, settings, insertBeforeWidgetId])` : void](#addsidebarwidget-widgetnamespace-widgetid-settings-insertbeforewidgetid--void)
82+
- [`updateSidebarWidget (widgetNamespace, widgetId, settings)` : void](#updatesidebarwidget-widgetnamespace-widgetid-settings--void)
83+
- [`removeSidebarWidget (widgetNamespace, widgetId)` : void](#removesidebarwidget-widgetnamespace-widgetid--void)
84+
- [`resetSidebarToDefault ()` : void](#resetsidebartodefault---void)
85+
- [`configureEntryEditor (widgetNamespace, widgetId[, settings])` : void](#configureentryeditor-widgetid-widgetnamespace-settings--void)
86+
- [`resetEditorToDefault()` : void](#reseteditortodefault---void)
8187
- [Field](#field)
8288
- [Validation errors](#validation-errors)
8389
- [Example migrations](#example-migrations)
@@ -107,9 +113,9 @@
107113
- Edit a field
108114
- Delete a field
109115
- Rename a field
110-
- Change editorInterface
111-
- Reset editorInterface
112-
- Copy editorInterface
116+
- Change a field's control
117+
- Reset a field's control
118+
- Copy a field's control
113119
- Move field
114120

115121
## Pre-requisites && Installation
@@ -517,15 +523,19 @@ module.exports = function (migration) {
517523
};
518524
```
519525

520-
#### `changeEditorInterface (fieldId, widgetId[, settings])` : void
526+
#### `changeFieldControl (fieldId, widgetNamespace, widgetId[, settings])` : void
521527

522-
Changes the editor interface of given field's ID.
528+
Changes control interface of given field's ID.
523529

524530
**`fieldId : string`** – The ID of the field.
525531

532+
**`widgetNamespace : string`** – The namespace of the widget, one of the following values:
533+
- `builtin` (Standard widget)
534+
- `extension` (Custom UI extension)
535+
526536
**`widgetId : string`** – The new widget ID for the field. See the [editor interface documentation](https://www.contentful.com/developers/docs/concepts/editor-interfaces/) for a list of available widgets.
527537

528-
**`settings : Object`** – Widget settings, with the following options:
538+
**`settings : Object`** – Widget settings and extension instance parameters. Key-value pairs of type (string, number | boolean | string). For builtin widgets, the the following options are available:
529539

530540
- **`helpText : string`** – This help text will show up below the field.
531541
- **`trueLabel : string`** _(only for fields of type boolean)_ – Shows this text next to the radio button that sets this value to `true`. Defaults to “Yes”.
@@ -535,14 +545,66 @@ Changes the editor interface of given field's ID.
535545
- **`ampm : string`** _(only for fields of type datePicker)_ – Specifies which type of clock to use. Must be one of the strings “12” or “24” (default).
536546
- **`bulkEditing : boolean`** _(only for fields of type Array)_ – Specifies whether bulk editing of linked entries is possible.
537547

538-
#### `resetEditorInterface (fieldId)` : void
548+
#### `resetFieldControl (fieldId)` : void
539549

540550
**`fieldId : string`** – The ID of the field.
541551

542-
#### `copyEditorInterface (sourceFieldId, destinationFieldId)` : void
552+
#### `copyFieldControl (sourceFieldId, destinationFieldId)` : void
553+
554+
**`sourceFieldId : string`** – The ID of the field to copy the control setting from.
555+
**`destinationFieldId : string`** – The ID of the field to apply the copied control setting to.
556+
557+
#### `addSidebarWidget (widgetNamespace, widgetId[, settings, insertBeforeWidgetId])` : void
558+
559+
Adds a builtin or custom widget to the sidebar of the content type.
560+
561+
**`widgetNamespace: string`** – The namespace of the widget, one of the following values:
562+
- `sidebar-builtin` (Standard widget, default)
563+
- `extension` (Custom UI extension)
564+
565+
**`widgetId : string`** – The ID of the builtin or extension widget to add.
566+
567+
**`settings : Object`** – Instance settings for the widget. Key-value pairs of type (string, number | boolean | string)
568+
569+
**`insertBeforeWidgetId : Object`** – Insert widget above this widget in the sidebar. If null, the widget will be added to the end.
570+
571+
#### `updateSidebarWidget (widgetNamespace, widgetId, settings)` : void
572+
573+
Updates the configuration of a widget in the sidebar of the content type.
574+
575+
**`widgetNamespace: string`** – The namespace of the widget, one of the following values:
576+
- `sidebar-builtin` (Standard widget, default)
577+
- `extension` (Custom UI extension)
578+
579+
**`widgetId : string`** – The ID of the builtin or extension widget to add.
580+
581+
**`settings : Object`** – Instance settings for the widget. Key-value pairs of type (string, number | boolean | string)
582+
583+
#### `removeSidebarWidget (widgetNamespace, widgetId)` : void
584+
585+
Removes a widget from the sidebar of the content type.
586+
587+
**`widgetNamespace: string`** – The namespace of the widget, one of the following values:
588+
- `sidebar-builtin` (Standard widget, default)
589+
- `extension` (Custom UI extension)
590+
591+
**`widgetId : string`** – The ID of the builtin or extension widget to remove.
592+
593+
#### `resetSidebarToDefault ()` : void
594+
595+
Resets the sidebar of the content type to default.
596+
597+
#### `configureEntryEditor (widgetNamespace, widgetId[, settings])` : void
598+
599+
Sets the entry editor to specified widget.
600+
601+
**`widgetNamespace: string`** – The namespace of the widget.
602+
**`widgetId : string`** – The ID of the builtin or extension widget to add.
603+
**`settings : Object`** – Instance settings for the widget. Key-value pairs of type (string, number | boolean | string). Optional.
604+
605+
#### `resetEntryEditorToDefault ()` : void
543606

544-
**`sourceFieldId : string`** – The ID of the field to copy the editorinterface setting from.
545-
**`destinationFieldId : string`** – The ID of the field to apply the copied editorinterface setting to.
607+
Resets the entry editor of the content type to default.
546608

547609
### Field
548610

examples/16-change-editor-interface.js examples/16-change-field-control.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ module.exports = function (migration) {
3434
type: 'Symbol',
3535
required: true
3636
});
37-
blogPost.changeEditorInterface('slug', 'slugEditor');
37+
blogPost.changeFieldControl('slug', 'slugEditor', 'builtin', { setting: 'value' });
3838
};

examples/17-change-editor-interface-for-existing-content-type.js examples/17-change-field-control-for-existing-content-type.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ module.exports = function (migration) {
44
description: 'super angry'
55
});
66

7-
blogPost.changeEditorInterface('slug', 'singleLine');
7+
blogPost
8+
.resetFieldControl('slug')
9+
.changeFieldControl('slug', 'singleLine', 'builtin');
810
};

examples/18-change-editor-interface-for-existing-content-type-adding-help-text.js examples/18-change-field-control-for-existing-content-type-adding-help-text.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ module.exports = function (migration) {
44
description: 'super angry'
55
});
66

7-
blogPost.changeEditorInterface(
7+
blogPost.changeFieldControl(
88
'slug',
99
'slugEditor',
10+
'builtin',
1011
{ helpText: 'This is the slug for the entry, it will be used for the URL' }
1112
);
1213
};

examples/21-copy-editor-interface-for-content-type.js examples/21-copy-field-control.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ module.exports = function (migration) {
1414
name: 'Instruction',
1515
type: 'Text'
1616
});
17-
recipe.changeEditorInterface('description', 'markdown');
18-
recipe.copyEditorInterface('description', 'instruction');
17+
recipe.changeFieldControl('description', 'markdown', 'builtin');
18+
recipe.copyFieldControl('description', 'instruction');
1919
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = function (migration) {
2+
const customSidebar = migration.createContentType('customSidebar', {
3+
name: 'Custom sidebar',
4+
description: 'How to add, remove and update widgets'
5+
});
6+
7+
customSidebar
8+
.addSidebarWidget('sidebar-builtin', 'not-needed');
9+
10+
customSidebar
11+
.addSidebarWidget('extension', 'imageTaggingExtensionId', {
12+
imageField: 'image'
13+
})
14+
.addSidebarWidget('sidebar-builtin', 'publication-widget', {}, 'imageTaggingExtensionId')
15+
.updateSidebarWidget(
16+
'extension',
17+
'imageTaggingExtensionId',
18+
{
19+
tagField: 'tags',
20+
imageField: 'image'
21+
}
22+
);
23+
24+
customSidebar
25+
.removeSidebarWidget('sidebar-builtin', 'not-needed');
26+
};

examples/25-configure-entry-editor.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = function (migration) {
2+
const customEntryEditor = migration.createContentType(
3+
'customEntryEditor_v5',
4+
{
5+
name: 'Entry Editor',
6+
description: 'Set entry editor'
7+
}
8+
);
9+
10+
customEntryEditor.configureEntryEditor(
11+
'extension',
12+
'customEntryEditor_v5',
13+
{}
14+
);
15+
};

examples/26-reset-entry-editor.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = function (migration) {
2+
const customEntryEditor = migration.createContentType('resetEntryEditor_v5', {
3+
name: 'Entry Editor',
4+
description: 'Set entry editor'
5+
});
6+
7+
customEntryEditor.configureEntryEditor('extension', 'resetEntryEditor_v5', {});
8+
9+
customEntryEditor.resetEntryEditor();
10+
};

index.d.ts

+72-6
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export interface IValidation {
9696
[validation: string]: any
9797
}
9898

99+
export type WidgetSettingsValue = number | boolean | string
100+
99101
export interface IEditorInterfaceOptions {
100102

101103
/** This help text will show up below the field. */
@@ -112,6 +114,14 @@ export interface IEditorInterfaceOptions {
112114
ampm?: '12' | '24'
113115
/** (only for References, many) Select whether to enable Bulk Editing mode */
114116
bulkEditing?: boolean
117+
118+
/** Instance settings for the sidebar widget as key-value pairs. */
119+
[setting: string]: WidgetSettingsValue
120+
}
121+
122+
export interface ISidebarWidgetSettings {
123+
/** Instance settings for the sidebar widget as key-value pairs. */
124+
[setting: string]: WidgetSettingsValue
115125
}
116126

117127
export interface ContentType {
@@ -140,29 +150,85 @@ export interface ContentType {
140150
changeFieldId (oldId: string, newId: string): void
141151

142152
/**
143-
* Changes the editor interface of given field's ID.
153+
* Changes the control of given field's ID.
144154
*
155+
* @param widgetNamespace The namespace of the widget. Use 'builtin' for standard widgets or 'extension' for UI extensions.
145156
* @param fieldId The ID of the field.
146157
* @param widgetId The new widget ID for the field.
147158
* @param settings Widget settings
148159
*/
149-
changeEditorInterface (fieldId: string, widgetId: string, settings?: IEditorInterfaceOptions): void
160+
changeFieldControl (fieldId: string, widgetNamespace: 'builtin' | 'extension', widgetId: string, settings?: IEditorInterfaceOptions): void
161+
162+
/**
163+
* @deprecated
164+
* Use change field control instead
165+
*/
166+
changeEditorInterface (fieldId: string, widgetId: string, settings?: IEditorInterfaceOptions, widgetNamespace?: 'builtin' | 'extension'): void
150167

151168
/**
152-
* Resets the editor interface of given field's ID.
169+
* Resets the field control of given field's ID.
153170
*
154171
* @param fieldId The ID of the field.
155172
*/
173+
resetFieldControl (fieldId: string): void
174+
175+
/**
176+
* @deprecated
177+
* Use resetFieldControl instead
178+
*/
156179
resetEditorInterface (fieldId: string): void
157180

158181
/**
159-
* copies the editor interface setting from a field to another field in the same content type.
182+
* copies the control settings from a field to another field in the same content type.
160183
*
161-
* @param sourceFieldId The ID of the field to copy the editorinterface setting from.
162-
* @param destinationFieldId The ID of the field to apply the copied editorinterface setting to.
184+
* @param sourceFieldId The ID of the field to copy the control setting from.
185+
* @param destinationFieldId The ID of the field to apply the copied control setting to.
186+
*/
187+
copyFieldControl (sourceFieldId: string, destinationFieldId: string): void
188+
189+
/**
190+
* @deprecated
191+
* Use copyFieldControl instead
163192
*/
164193
copyEditorInterface (sourceFieldId: string, destinationFieldId: string): void
165194

195+
/**
196+
* Adds a builtin or custom widget to the sidebar of the content type.
197+
*
198+
* @param widgetNamespace The namespace of the widget. Use 'sidebar-builtin' for standard widgets or 'extension' for UI extensions.
199+
* @param widgetId The ID of the builtin or extension widget to add.
200+
* @param settings Instance settings for the widget
201+
* @param insertBeforeWidgetId Insert widget above this widget in the sidebar. If null, the widget will be added to the end.
202+
*/
203+
addSidebarWidget (widgetNamespace: 'sidebar-builtin' | 'extension',
204+
widgetId: string,
205+
settings: ISidebarWidgetSettings,
206+
insertBeforeWidgetId: string): void
207+
208+
/**
209+
* Updates the configuration of a widget in the sidebar of the content type.
210+
*
211+
* @param widgetNamespace The namespace of the widget. Use 'sidebar-builtin' for standard widgets or 'extension' for UI extensions.
212+
* @param widgetId The ID of the widget to update.
213+
* @param settings Instance settings for the widget
214+
*/
215+
updateSidebarWidget (widgetNamespace: 'sidebar-builtin' | 'extension',
216+
widgetId: string,
217+
settings: ISidebarWidgetSettings): void
218+
219+
/**
220+
* Removes a widget from the sidebar of the content type.
221+
*
222+
* @param widgetNamespace The namespace of the widget. Use 'sidebar-builtin' for standard widgets or 'extension' for UI extensions.
223+
* @param widgetId The ID of the widget to remove.
224+
*/
225+
removeSidebarWidget (widgetNamespace: 'sidebar-builtin' | 'extension',
226+
widgetId: string): void
227+
228+
/**
229+
* Resets the sidebar of the content type to default
230+
*/
231+
resetSidebarToDefault (): void
166232
}
167233

168234
export interface IContentTypeOptions {

0 commit comments

Comments
 (0)