The View is accessed using the view object. The view restricts the viewport to be within the "safe area": A rectangular area that does not include any cutouts for cameras or other devices.
The view attaches to a DOM node with an ID of root. This must be defined in the app's index.html file before the view is initialized.
The View defines the following custom properties:
--main-text-color--main-text-warning-color--main-text-caution-color--main-text-bg-color--main-text-color-sel--main-text-bg-color-sel--main-fill-color--main-input-color--main-input-bg-color--main-input-border-color--main-output-color--main-disabledInput-color--main-disabledInput-bgColor--main-wrapper-haze--main-button-text-color--main-button-text-bg-color--main-dialog-border-color--main-list-border-colorThese properties are adjusted when switching between dark mode and light mode. The application should use these properties when appropriate.
The application can choose a set of device size breakpoints to use in its CSS. A size class is associated with each range of sizes between the breakpoints. For example, if the breakpoints are viewport widths of 512 and 1024 then the class large can be associated with widths ≥ 1024, the class medium can be associated with widths ≥ 512 and < 512, and the class small can be associated with widths < 512.
Once the size classes are defined, the view can set up useful class strings. For example, if the device size is medium, then the view can set up the following CSS classes in the root node:
viewSize-mediumviewSizeGE-mediumviewSizeGE-smalldevsizeLT-largeSee the view.setSizeClass() method.
viewimport {view} from 'common/mvcs/export.js';
The view object contains the properties and methods used to communicate with the View.
view methodsappendNodes()view.appendNodes(parent, nodes)
Appends child DOM nodes to a parent DOM node. The nodes array will be flattened and compacted. Elements may be strings or DOM nodes. If an element is a string, it is converted to a DOM test node after having any custom character entities processed (See Character Entities).
parentnodescreateNode()view.createNode(tag, props, children)
Returns a DOM node with the specified properties and children. Properties starting with 'data-' are set as node data properties. The following attributes are converted to their equivalent DOM properties:
class is converted to classNamerowspan is converted to rowSpancolspan is converted to colSpantagprops (optional)children (optional)view.appenNodes(). If a string, it is used to set the node's innerHTML property.defineComponentTag()view.defineComponentTag(tag, component)
Associate a component tag string with its Component subclass. Once defined, the tag may be used in TML strings. Otherwise, the TML template would have to import and refer to the component itself.
tagcomponentdoSync()view.doSync()
Synchronize the entire view from the root. Calls the sync() method on the root Component. This will traverse the Component tree calling the sync() method as required to cause the Components to update the displayed elements to the current state variable state.
Unlike view.sync(), this synchronizes the View immediately.
getComponentById()view.getComponentById(id)
Return the component given the ID.
Most Components generate DOM elements containing the Component ID in the data-cid attribute. Use this ID with view.getComponentById() in the debugger console to explore the Component controlling the DOM element.
A Component.
getComponentClass()view.getComponentClass(tag)
Return the component class for a given component tag string. See defineComponentTag()
tagA Component.
resize()view.resize()
Notify the entire View that the viewport has been resized.
setSizeClass()view.setSizeClass(curSizeClass, sizeClasses)
Sets the size class CSS strings in the root node. The sizeClasses parameter is an array of the possible size class strings ordered from largest to smallest. The curSizeClass is the viewport's current size class. The setSizeClass() method will set a series of CSS class strings of the form prefix-sizeClass. The sizeCLass is one of the size class strings and the prefix is one of:
viewSize-viewSize-medium CSS class would apply only when the viewport size falls into the medium size class.viewSizeLT-viewSizeLT-medium CSS class would apply only when the viewport size is smaller than medium.viewSizeGE-viewSizeGE-medium CSS class would apply only when the viewport size is medium or larger.curSizeClasssizeClassessync()view.sync()
Schedule a synchronization of the entire View. This can be called multiple times and the synchronization, using view.doSync()).
toText()view.toText(template)
Extracts the text from anything that the view accepts as a template (strings, arrays or templates).
templateview propertiesbottomThe viewport offset from the bottom of the screen in px.
A number.
hasSafeAreaTrue if the device's viewport has a "safe area": A rectangular area that excludes any intrusions on the viewport.
A Boolean.
rootNodeThe current root DOM node of the View.
A DOM node
heightThe viewport height in px.
A number
leftThe viewport offset from the left of the screen in px.
A number.
rightThe viewport offset from the right of the screen in px.
A number.
topThe viewport offset from the top of the screen in px.
A number.
widthThe viewport width in px.
A number.