Preview Events
Methods for adjusting the preview in response to user actions.
As content editors interact with various controls in the Netlify Create visual editor, Netlify Create runs a preview of the site to reflect content changes in real time.
By default, the preview server is just your development server, along with an injected JavaScript snippet for communicating with the Netlify Create API. This snippet provides various hooks for customizing the preview experience in response to user actions.
Emitted Events
Netlify Create fires the events below based on the various triggers from actions taken by content editors in the Netlify Create application.
stackbitObjectsChanged
Fires when content changed. This event is typically used to override the default automatic content reload behavior.
Usage Example
1
2
3
event.preventDefault()
in the callback.
Event Object Details
The event.detail
object contains the following unique properties, along with the base-level context properties.
1
2
3
4
5
6
7
8
stackbitLocaleChanged
Fires when an editor changes the current locale using the locale switcher.
Usage Example
1
2
3
4
Event Object Details
The event.detail
object contains the following unique properties, along with the base-level context properties.
1
2
3
4
Event Callback Properties
When event callback fires, the function is called with the standard Event
properties, along with a detail
property, containing the necessary editing-specific context.
The detail
property contains unique properties for the event, as referenced above, along with a set of base-level properties, documented below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Event Context Example
Here's an example of an expected shape for the base-level context object, available as event.detail
in an event listener callback. Additional custom properties are documented below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Editor Actions
A stackbit
object is attached to the window by the snippet script. It contains properties that can be used to customize the visual editing experience, as documented below.
setLocale
Switches the current locale. The updated locale will be reflected in the locale switcher.
Usage Example
1
Parameters
Preview Controls
The following objects are attached directly to the window
object.
stackbitPreviewControls
Provides the ability to add custom controls to the Netlify Create visual editor. This enables editors to change some context within the preview without adjusting the underlying content.
The property should be set to an array of individual control objects. The options for controls are documented below.
Usage Example
Here's a brief and incomplete example for the sake of usage. See the feature guide for a more thorough example.
1
2
3
4
5
6
7
8
9
10
Configuration Properties
Preview control definitions are extensions of field definitions. The field definition specifies how to render the preview control for the user. See the fields reference for the desired field type.
Shared Properties
The control-specific properties are dependent on the context in which the control should be rendered. The shared properties are listed below, followed by unique properties for each context.
Global Context Properties
The global context requires no additional properties.
Field Context Properties
Field contexts require the following additional properties to specify where exactly the control should be rendered.