Template for rendering a row of accessibility check results.
ReadonlyautoInterval 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.
ReadonlycontextReadonlydeviceKey for storing the last selected device size in localStorage.
ReadonlydeviceCSS property for setting the device width.
Main editor form.
ReadonlyhasCSS class to indicate that there are errors in the form.
ReadonlyhasReadonlyhasReadonlyhasReadonlyhasReadonlyiframeThe main preview <iframe> that is currently displayed.
ReadonlyiframeAll preview <iframe>s 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.
ReadonlymodePreview mode <select> element.
ReadonlynewNew tab button.
ReadonlypanelCSS property for the current width of the panel, to maintain the device scaling.
ReadonlyproxyCSS 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).
Promise for the current iframe reload. This is resolved when the new
iframe's load event is fired and the scroll position has been restored.
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.
ReadonlyselectedCSS class for the currently selected device size.
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.
ReadonlysizeDevice size <input type="radio"> elements.
ReadonlyspinnerLoading spinner.
Timeout before displaying the loading spinner.
Whether the preview data is considered stale and needs an 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.
ReadonlyurlURL for updating the preview data. Also used for rendering the preview if renderUrlValue is unset.
ReadonlywProgressController for the refresh button that may be displayed when auto-update is turned off.
StaticblessingsStaticclassesStaticfallbackThe device size width to use when the preview is not available.
StaticoutletsStaticscrollThe time tolerance between the iframe's load event and the scroll
restoration completion, which may not be instantaneous for cross-domain
preview iframes.
StatictargetsStaticvaluesThe 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.
StaticshouldApplies the selected size class to the specified device input's label, and removes the class from all other device inputs' labels.
Selected device name
OptionalnewValue: numberLike setPreviewData, but only updates the preview if the form has not changed.
whether the data is valid
Extracts the rendered content from the preview iframe via an Axe plugin.
Optionaloptions: 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.
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.
Restores the scroll position from the old iframe to the new one.
For same-origin iframes, this is done by calling scroll() on the new
iframe's content window with the scroll position of the old iframe.
For cross-origin iframes, this is done by using the postMessage API to
request the scroll position from the old iframe and send it to the new one.
The new iframe element that will replace the old one.
a Promise that resolves when the scroll position is restored or the timeout has lapsed.
Runs the accessibility checks using Axe.
Runs the content and accessibility checks. This is called when the iframe sends a message event from the userbar indicating that it has finished running the checks within itself.
Optionalevent: MessageEvent<{ wagtail: { type: string } }>The message event from the userbar
Runs the content checks by extracting the content from the preview iframe using an Axe plugin and calculating content metrics.
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.
whether the data is valid
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.
Optionalwidth: stringThe width of the preview device. If falsy:
Marks the preview data as stale, indicating it needs an update.
Accepts an optional stale parameter to explicitly override the value.
Optionalevent: Event & { params?: { stale: boolean } }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.
Staticafter
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