Light API 0.4.0 is a public beta: a minor release such as 0.5.0 may still break. What that means for your module
Light
Developer guideReference

Events, JS modules and #mrx-config keys

The DOM events, server events, JS modules and #mrx-config keys that are contract.

Everything on this page is in the API surface (event, js and config lines of surface.json), so it is versioned like the PHP API: a name or a detail key is never renamed or removed before the next major (Versioning). npm run docs:check fails when the surface has an event, module, export or key this page doesn't name. The ui-kit describes the modules in full (Design system, section 5); this page is the contract.

DOM events

Each event carries its data in event.detail. An event fired on an element bubbles, so you can listen on that element or on document.

EventDetail keysFired onWhen
mrx:readynonedocumentThe shell has installed popovers, formatting, the mode switch and, in simple mode, the palette and shortcuts. html[data-mrx-ready="true"] is set at the same moment
mrx:form-savedformCode, entityId, responsethe editor's formA Light editor saved. formCode is one of the seven form codes, response the editor's JSON with success, message, entity_id and ext (Fields on a Light editor)
mrx:product-savedsuccess, message, product, entity_id, extthe product formThe product editor saved. Kept next to mrx:form-saved for product-only listeners
mrx:badgesitemsdocumentThe nav counters were refreshed in the background. items maps a nav item key to {count, display, tone, label} (A nav item with a counter)
mrx:customer-message-sentoptions, responsedocumentThe contact-customer modal sent an email, so a timeline can refresh
mrx:languagebeforechangestoreId, previousStoreId, option, switcherthe switcherAn editor's language switcher is about to change the store view. Cancel it with preventDefault()
mrx:languagechangestoreId, previousStoreId, option, switcherthe switcherThe editor now shows another store view
mrx:channelschangeids, level, cardthe Channels cardThe channels of a product, discount, page or block changed
mrx:tabchangetab, panelthe tab listA tab of a Light tab set opened
mrx:themechangesource, statedocumentThe admin theme or scheme changed
mrx:themepreferencestatedocumentThe admin saved a theme preference

The editors dispatch mrx:form-saved from the form hooks module:

app/code/Mrx/Light/view/adminhtml/web/js/form-hooks.js
ctx.form.dispatchEvent(new CustomEvent('mrx:form-saved', {bubbles: true, detail: {formCode: formCode, entityId: ctx.entityId, response: response}}));

Server events

EventPayloadDispatched byWhen
mrx_return_resolved_afterreturn, an array with entity_id, increment_id and order_idMrx_ReturnsA return is closed after a refund or a check. It runs inside try/catch, so an observer that fails never undoes the return's new status
app/code/Mrx/Returns/Model/Backend/ReturnEvents.php
public const EVENT_RESOLVED = 'mrx_return_resolved_after';

An observer of an mrx_* event uses Light, so its module declares a Light API range (Versioning).

Light also observes Magento's email_order_set_template_vars_before, email_invoice_set_template_vars_before, email_shipment_set_template_vars_before and email_creditmemo_set_template_vars_before, in the global area. Mrx_Documents adds the mrx_* variables its bodies read: mrx_order_url and mrx_created_at on every sales mail, mrx_invoice_date with an invoice, and mrx_has_tracking, mrx_track_url, mrx_track_number and mrx_carrier with a shipment. It only adds keys, so your own observer of these events still runs and its variables still reach the body (Your module's email and document). Mrx_Documents dispatches no events of its own.

app/code/Mrx/Documents/etc/events.xml
<event name="email_order_set_template_vars_before">
    <observer name="mrx_documents_sales_email_variables" instance="Mrx\Documents\Observer\AddSalesEmailVariables"/>
</event>

JS modules

Each module is a RequireJS AMD module. Only the exports listed here are contract.

ModuleExportsUse it for
Mrx_Light/js/apirequest, get, post, ApiErrorJSON calls to your controllers, with the form key, error toasts and the session timeout handled
Mrx_Light/js/configget, url, allThe #mrx-config values below
Mrx_Light/js/toastshow, errorShort confirmations and errors
Mrx_Light/js/modalopen, confirm, isOpenDialogs, and confirmations before a destructive action
Mrx_Light/js/save-barattach, getThe "Unsaved changes" bar on your own forms
Mrx_Light/js/formatmoney, number, date, dateShort, dateTime, time, relative, parse, hydrateMoney, numbers and dates in the admin's locale and the store's time zone
Mrx_Light/js/form-hooksregister, validate, extend, savedValidation and extra payload for your fields on a Light editor (Fields on a Light editor)
Mrx_Light/js/loaderduring, button, skeleton, spinnerA skeleton shaped like what is coming while a region waits for a request, and the spinner on a busy button (Design system, Loading states)

A palette action's command works the other way round: it names a module of your own that returns an object with run(), and the palette calls run() after it closes (The command palette).

#mrx-config keys

config.get('<key>') reads them.

KeyHolds
apiVersionExtensionApi::VERSION, the Light API version of this shop
modesimple or advanced
stockViewWhether a stock screen is open through the advanced view in simple mode
localeThe admin locale, for example nl-NL
currencyThe base currency of the default store
timezoneThe store time zone
storeNameThe store name
sender{name, email}, the default sender
user{username, name, email} of the signed-in admin
canContactWhether the admin may email customers
urlsThe shell's endpoints, among them cacheRefresh (light/cache/refresh, empty when the admin lacks Magento_Backend::cache)
navThe nav items the admin may open, {key: {label, url}}
shortcutsThe keyboard shortcuts
channelsThe channels and their languages
iconsThe registered icons

Not in the contract

These work, but a minor release may change them. Don't build on them.

  • Internal events: mrx:valuechange (the save bar fires it on each field after a discard; a custom widget in your own form may listen for it to redraw, but that is tier 2), mrx:table:bulk, mrx:table:channel, mrx:table:loaded, mrx:settings-saved, mrx:settings-discard, mrx:pagechange and mrx:order:updated.
  • The other modules of ui-kit section 5: popover, tabs, rich-text, index-table, search-preview, command-palette, shortcuts, icons, dom, contact-customer and the channels modules. Use them on your own pages as the ui-kit shows; they are tier 2.

Last updated on

On this page