Skip to content

Latest commit

 

History

History
431 lines (241 loc) · 16.9 KB

API.md

File metadata and controls

431 lines (241 loc) · 16.9 KB

AdaptiveComponent

Extends superclass

Mixin to create Adaptive Web Component classes.

variant

The current AdaptiveVariant instance for this component.

Returns AdaptiveVariant the current variant's instance.

managing

Indicates if this component is managing its decentants or behaves transparent in terms of PROFILE_REQUEST_EVENTs from the decentants in its shadow DOM.

Returns Boolean true if the component is managing, false if not.

managing

Sets this component to managing mode or transparent mode (default). In managing mode, it manages the adaptation behavior of the decentants in its shadow DOM. In transparent mode, it does not influence the bubbling of PROFILE_REQUEST_EVENTs comming from its shadow DOM.

Parameters

  • flag Boolean true to set the component to managing mode, false to set it to transparent mode.

managed

Indicates if this components adaptation is managed by another component. If in managed mode, this component does not itself listen to PROFILE_CHANGED_EVENTs. Instead, the managing component will call AdaptiveComponent#prepareAdaptation and AdaptiveComponent#performAdaptation directly.

Returns Boolean true if the component is managed, false if not.

connectedCallback

Called when the instance of the component has been connected to, i.e. inserted into a document.

disconnectedCallback

Called when the instance of the component has been disconnected from, i.e. removed from a document.

attributeChangedCallback

Called when an attribute was added, removed or modified at the instance of the component.

Parameters

  • attrName String The name of the changed attribute.
  • oldVal Any The old value of the attribute.
  • newVal Any The new value of the attribute.

adoptedCallback

Called when the instance of the component has been adopted by another document.

Parameters

  • oldDocument Document The document the element has been taken from.
  • newDocument Document The document the element has been adpoted by.

prepareAdaptation

Prepares the adaptation of the component according to the given profile.

Parameters

  • profile Object The profile to adapt to.

performAdaptation

Performes the adaptation of the component according to the given profile.

Parameters

  • profile Object The profile to adapt to.

removeManagedComponent

Removes a component from the list of managed components. Typically because it has been removed from the shadow DOM of this component and should therefore no further be managed.

Parameters

observedAttributes

Defines the attributes that are observed, i.e. for which attributes the #attributeChangedCallback will be called.

registerVariant

Registers a variant for this component.

Parameters

defaultVariant

Sets an already registered variant as the default variant for this component.

Parameters

  • variant Class The registered subclass of AdaptiveVariant that should be used as default variant.

  • Throws Error If 'variant' is not a registered variant of this component.

defaultVariant

Returns Class The subclass of AdaptiveVariant set as default variant.

AWC_ATTRIBUTE_PREFIX

Prefix for all attributes related to the adaptive web components framework.

Type: string

AdaptiveVariant

A variant of an Adaptive Web Component.

template

Returns DocumentFragment

contentRoot

Returns Node The node that contains the variant's DOM contents, e.g. the shadow root.

contentRoot

Sets the node that contains the variant's DOM contents.

Parameters

  • node Node The node that contains the variant's DOM contents, e.g. the shadow root.

selectedCallback

Called when the variant has been selected as the current variant for the owning component.

Parameters

  • state Object The internal state the variant should take up

deselectedCallback

Called when the variant has been deselected as the current variant for the owning component.

Returns Object The internal state of the variant

connectedCallback

Called after the variant has been connected to the component's content root.

disconnectedCallback

Called after the variant's contents have been removed from the component's content root.

matches

Checks if the variant matches the given context.

Parameters

ContextQuery

A ContextQuery object represents a context query expression, and handles sending notifications to listeners when the context query state changes (i.e. when it starts or stops matching the current context). It mainly replicates the interface of MediaQueryList.

Parameters

  • query String The query expression this ContextQuery represents, defaults to empty string and therefore a query that matches any context (always true). (optional, default "")
  • attachTo EventTarget Specifies the node this ContextQuery will dispatch the PROFILE_REQUEST_EVENT to, defaults to window. (optional, default window)

query

The original query expression.

Returns String The original query expression.

matches

Checks if this ContextQuery matches the current context as known by the node it is attached to.

Returns Boolean true if this query matches the current context, false if not.

onchange

Sets a function as event handler for the change event, i.e. when the status of the query changes.

Parameters

  • handler Function The function to be called on change with the event object as parameter or null to remove the current handler.

onchange

The function as event handler for the change event, i.e. when the status of the query changes.

Returns Function The function currently set as change event handler or null if no current handler is set.

addEventListener

Add the specified function to the list of listeners to be called when an event of the specified type occurs. This is basically an optionless version of EventTarget.addEventListener.

Parameters

  • type String A string representing the event type to listen for. Only change events are expected to occur on ContextQuery objects.
  • listener Function The function to be called on change with the event object as parameter.

removeEventListener

Remove the specified function from the list of listeners to be called for the specified event type. This is basically an optionless version of EventTarget.removeEventListener.

Parameters

  • type String A string which specifies the event type for which to remove a listener.
  • listener Function The listener function that should be removed from the list.

dispatchEvent

Dispatches the specified event.

Parameters

  • event Event The event to dispatch.

prepareAdaptation

Prepares the adaptation of the component according to the given profile.

Parameters

  • profile Object The profile to adapt to.

performAdaptation

Performes the adaptation of the component according to the given profile.

Parameters

  • profile Object The profile to adapt to.

parse

Parameters

ContextStyle

Extends HTMLElement

The context-style custom element polyfills CSS @context rules.

getContent

Parameters

  • attr string the query from the "context" attribute

getURL

Parameters

  • url string the link to an external context query sheet

instantiateContextQueryObjects

Parameters

  • str string the styles found inside the custom element
  • attr string the query of the "context" attribute

findClosingBracket

Parameters

  • brackets string the type of brackets as pair [],{},()
  • str string the string where the brackets are to be found

factoriseContextQueries

Parameters

  • str string the content of the custom element
  • attr string the content of the context attribute, false if the context attribute is empty

LocalProfileStore

Extends ProfileStore

A ProfileStore implementation based on HTML5 Local Storage.

Parameters

  • attachTo EventTarget Specifies the node this ProfileStore is attached to and dispatches its events to. (optional, default window)

changeProfile

Allows to request a value change of profile properties. It returns a promise to

Parameters

  • newValues Object A map of the requested property changes. JSON structured like { propertyName: newValue , ... }.

LOCAL_STORAGE_KEY

The storage key used for storing the profile.

Type: string

ProfileStore

Simple volatile in-memory profile store. Mainly serves as a base class for implementations that represent different sources, storage locations or fetch methods for user interface profiles.

Parameters

  • changeable Boolean Specifies if the store supports to change the stored profile. (optional, default false)
  • attachTo EventTarget Specifies the node this ProfileStore is attached to and dispatches its events to. (optional, default window)

_profile

The current profile

Type: Object

profile

The current user interface profile.

Returns Promise A promise to the current user interface profile.

changeable

Indicates if changes of the profile are supported.

Returns Boolean true if profile store supports to change the profile, false if not.

changeProfile

Allows to request a value change of profile properties. It returns the effective changes.

Parameters

  • newValues Object<String, Any?> A map of the requested property changes. JSON structured like { propertyName: newValue , ... }.

Returns Promise A promise to the effective changes.

_profileChanged

Creates and dispatches a profile changed event containing information on changed values of profile properties.

Parameters

  • diff ProfileDiff A data structure describing the last changes to the profile properties. Expected to be structured like { propertyName: { from: oldValue, to: newValue }, ... }.

PROFILE_CHANGED_EVENT

The type of the CustomEvent that is triggered when a profile has been changed.

Type: string

PROFILE_REQUEST_EVENT

The type of CustomEvents that represent a request to provide the current profile.

Type: string

ProfileChange

An object representing the value change of a profile property.

Type: Object

Properties

  • from Any? the old value or null
  • to Any? the new value or null

ProfileDiff

A structured object describing the changes that occurred or have been made to a profile. Each changed profile property is represented by its property name. The value of this property is an object with a from property representing the old value and a to property representing the new current value. If from is null, the property has just been added. Accordingly, if to is null, the property has been removed from the profile.

Type: Object<String, ProfileChange>

Examples

{
  changed: {from: 1, to: 5},
  new: {from: null, to: 'foo'},
  removed: {from: true, to: null}
}