Template for rendering a row of accessibility check results.
Readonly
autoInterval in milliseconds when the form is checked for changes. Also used as the debounce duration for the update request.
Whether the preview is currently available. This is used to distinguish
whether we are rendering a preview or the "Preview is not available"
screen. So even if the preview is currently outdated, this is still true
as long as the preview data is available and the preview is rendered (e.g.
if the form becomes invalid after the preview is successfully rendered).
Configuration for Axe.
Container for rendering content checks results.
Content checks counter inside the checks panel.
Side panel for content checks.
Content checks counter on the side panel toggle.
Whether content checks are enabled.
Promise for the current content checks request. This resolved when both the content checks and the accessibility checks are completed. Useful for queueing the checks, as Axe does not allow concurrent runs.
Configuration for Wagtail's Axe content extractor plugin instance.
Readonly
contextReadonly
deviceKey for storing the last selected device size in localStorage.
Readonly
deviceCSS property for setting the device width.
Main editor form.
Serialized form payload to be compared in between intervals to determine whether an update should be performed. Note that we currently do not handle file inputs.
Readonly
hasCSS class to indicate that there are errors in the form.
Readonly
hasReadonly
hasReadonly
hasReadonly
hasReadonly
iframeThe main preview <iframe>
that is currently displayed.
Readonly
iframeAll preview <iframes>
that are currently in the DOM.
This contains the currently displayed <iframe>
and may also contain
the new <iframe>
that will replace the current one.
Readonly
modePreview mode <select>
element.
Readonly
newNew tab button.
Readonly
panelCSS property for the current width of the panel, to maintain the device scaling.
Readonly
proxyCSS class for elements that are invisible and only rendered for functionality purposes.
Whether the preview is ready for further updates.
The preview data is stored in the session, which means:
To ensure the preview data is available when the preview panel is opened, we send an update request immediately. This can result in two scenarios:
In edit views, the form is usually valid on initial load, as the object was successfully saved before. In this case, we can go ahead with rendering the preview and updating it with any new data.
However, there may be cases where the form is invalid on initial load, e.g.
if the "expiry date" in the publishing schedule has become in the past.
Another common example is in create views, where the form is likely invalid
on initial load due to missing required fields (e.g. title
).
When this happens, Wagtail will not update the preview data in the session, which means it may still contain the outdated preview data from the previous full-page load. We want to clear this data immediately so that the preview panel displays the "Preview is not available" screen instead of an outdated preview.
This flag determines whether the preview is "ready" for further updates – i.e. this is true if the preview data has been cleared after an invalid initial load, or if the preview data is already valid on initial load.
An alternative approach would be to handle the initial state of the session's preview data in the backend, but this would require the logic to be applied in all the different places (i.e. page and snippets create and edit views).
URL for rendering the preview, defaults to urlValue
.
Useful for headless setups where the front-end may be hosted at a different URL.
ResizeObserver to observe when the panel is resized so we can maintain the device size scaling.
Readonly
selectedCSS class for the currently selected device size.
Updates the preview data in the session. If the data is valid, the preview iframe will be reloaded. If the data is invalid, the preview panel will display an error message.
Side panel element of the preview panel, i.e. the element with the
data-side-panel
attribute. Useful for listening to show/hide events.
Normally, this is the parent element of the controller element.
Readonly
sizeDevice size <input type="radio">
elements.
Readonly
spinnerLoading spinner.
Timeout before displaying the loading spinner.
Interval for the auto-update.
Promise for the current update request. This is resolved as soon as the update request is successful, so the preview iframe may not have been fully reloaded.
Readonly
urlURL for updating the preview data. Also used for rendering the preview if renderUrlValue
is unset.
Readonly
wProgressController for the refresh button that may be displayed when auto-update is turned off.
Static
blessingsStatic
classesStatic
fallbackThe device size width to use when the preview is not available.
Static
outletsStatic
scrollThe time tolerance between the iframe's load
event and the scroll
restoration completion, which may not be instantaneous for cross-domain
preview iframes.
Static
targetsStatic
valuesThe currently active device size input element. Falls back to the default size input.
The URL of the preview iframe and the new tab button. This takes into account the currently selected preview mode.
Static
shouldActivates the preview mechanism. The preview data is immediately updated. If auto-update is enabled, an interval is set up to automatically check the form and update the preview data.
Sets the interval for auto-updating the preview and applies debouncing to
setPreviewData
for subsequent calls.
Applies the selected size class to the specified device input's label, and removes the class from all other device inputs' labels.
Selected device name
Like setPreviewData
, but only updates the preview if there is no pending
update and the form has not changed.
whether the data is valid
Clears the auto-update interval.
Deactivates the preview mechanism.
If auto-update is enabled, clear the auto-update interval.
Extracts the rendered content from the preview iframe via an Axe plugin.
Optional
options: ContentExtractorOptionsOptions object for extracting the content. Supported options:
targetElement
: CSS selector for the element to extract content from.
Defaults to main, [role="main"]
.An ExtractedContent
object with lang
, innerText
, and innerHTML
properties.
Resets the preview panel state to be ready for the next update.
Checks whether the form data has changed since the last call to this method.
whether the form data has changed
Observes the preview panel size and set the --preview-panel-width
CSS variable.
This is used to maintain the simulated device width as the side panel is resized.
Like setPreviewDataWithAlert
, but also opens the preview in a new tab.
If an existing tab for the preview is already open, it will be focused and
reloaded.
The click event
whether the data is valid
Reloads the preview iframe.
Instead of reloading the iframe with iframe.contentWindow.location.reload()
or updating the src
attribute, this works by creating a new iframe that
replaces the old one once the new one has been loaded. This prevents the
iframe from flashing when reloading.
Restores the last saved preferences. Currently, only the last selected device size is restored.
Runs the content and accessibility checks. This is called when the preview iframe is loaded, or when the iframe sends a message event from the userbar indicating that it has finished running the checks within itself.
Optional
event: MessageEvent<{ wagtail: { type: string } }>The message event from the userbar
Like setPreviewData
, but also displays an alert if an error occurred while
updating the preview data. Note that this will not display an alert if the
update request was successful, but the data is invalid.
This is useful when the preview data is updated in response to a user interaction, such as:
whether the data is valid
Updates the new tab link with the currently selected preview mode, then updates the preview.
Sets the simulated device width of the preview iframe.
Optional
width: stringThe width of the preview device. If falsy:
Toggles the preview size based on the selected input.
The selected device name (input[value]
) is stored in localStorage.
InputEvent
from the size input
Updates the URL of the new tab button with the currently selected preview mode.
Static
after
Controls the preview panel component to submit the current form state and update the preview iframe if the form is valid.
Dispatches the following events in this order.
Fires
PreviewController#update - Before sending the preview data to the server. Cancelable.
Fires
PreviewController#json - After the preview data update request is completed.
Fires
PreviewController#error - When an error occurs while updating the preview data.
Fires
PreviewController#load - Before reloading the preview iframe. Cancelable.
Fires
PreviewController#loaded - After the preview iframe has been reloaded.
Fires
PreviewController#content - When the content of the preview iframe is extracted to be analyzed.
Fires
PreviewController#ready - When the preview is ready for further updates – only fired on initial load.
Fires
PreviewController#updated - After an update cycle is finished – may or may not involve reloading the iframe.
PreviewController#update