DocumentView
Class of @saij/wp-app-framework/view; your view extends it.
The base class of a document view (assets/**\/*.view.js): one instance per page, for the document element,
mounted before the views of blocks.
Members
findAll()
The elements of the whole document that match a selector.
Returns Element[]: The elements in document order.
mount()
Sets the view up: find elements, listen to events. Override it.
unmount()
Releases what listen() and onUnmount() do not cover. Override it if needed.
element
The root element of the view: the root element of the block, or the document element for a document view.
document
The document of the view: in the preview of the block editor the one of the canvas iframe.
window
The window of the view: in the preview of the block editor the one of the canvas iframe.
isPreview
Whether the view runs in the preview of the block editor.
find()
The first element below the root element that matches a selector, without elements of nested blocks with view scripts.
Returns Element | null: The element, or null.
data()
A value of the view data of your theme or plugin, set in PHP with ViewData::set().
Returns DataValue: The value; an unknown key throws an error that names the known keys.
loadScript()
Loads an external script into the document of the view, once per URL and document.
Returns Promise<void>: Fulfilled once the script has loaded; rejected if it fails to load.
listen()
Adds an event listener that is removed when the view unmounts.
onUnmount()
Runs a function when the view unmounts, after unmount(): for observers, timers and the like.