Developer guide
Developer guide

Public component API and decorators

WE compiles decorators from component source into the generated browser wrapper. Import them from WEngineElement, or from WEngineModal in a modal source. They are compiler annotations; source files are not meant to run directly in an ordinary browser without the WE build.

@apiAttribute

Use this decorator for a property that another component or page may set. A bare decorator uses String. Specify another type when needed:

import { WEngineElement, apiAttribute, apiFunction, Any } from 'WEngineElement';

class StatusPanel extends WEngineElement {
  @apiAttribute title = '';
  @apiAttribute({ type: Boolean }) expanded = false;
  @apiAttribute({ type: Number }) limit = 10;
  @apiAttribute({ type: Array }) items = [];
  @apiAttribute({ type: Object }) filter = {};
  @apiAttribute({ type: Any }) value;
  @apiAttribute({ type: String, name: 'display-title' }) displayTitle = '';

  @apiFunction
  refresh() { /* public method */ }
}

The generated HTML names are kebab case (displayTitle → display-title) unless name overrides them. A getter/setter pair can be decorated on either accessor. If both are decorated, their options must match. The record picker demonstrates type: [String, Array] for a property that accepts either form.

Object and array HTML attribute values must contain JSON. JavaScript property assignments preserve their type. Public object and array values are copied across the wrapper boundary. For Boolean attributes, removal, false, and the string "false" mean false; other present values mean true. Removing an attribute supplies null to the observing component.

@apiFunction

Only decorated methods are exposed through the browser wrapper. Call them on the element returned from DOM lookup. For example, input exposes focus(), checkValidity(), and reportValidity().

Template values and events

  • An exact binding such as field-value="{selectedId}" removes the attribute when the value becomes null or undefined.
  • A mixed value such as title="Record: {selectedId}" substitutes an empty string for a nullish value.
  • A component may emit new CustomEvent('change', { detail: ... }); parent templates use the corresponding onchange handler binding. Event names and payloads come from the component implementation. See individual reference pages for event names.

The source wrapper is encapsulated within the browser realm; it does not create a security sandbox for arbitrary JavaScript. For implementation detail and edge cases, see working/docs/component-wrapper.md.