Light API 0.18.0 is a public beta: a minor release such as 0.19.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. It fires once, also when one of those steps threw or the palette or shortcuts module failed to load: the error is in the browser console, and the parts that installed work. A module the shell itself depends on that fails to load stops the shell, and then it does not fire
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:ai:resultfield, action, text, findings, entity, storethe field the AI fillsSince 0.6.0. An AI answer is about to fill a field: the product editor's AI menu, search listing and Fill in from photo, "Translate from" in the product, category, CMS page and block editors, Write a draft with AI on Settings > AI (action draft, entity shop_profile), each field "Fill in with AI" puts into a new product (action draft, entity product) and an option name filled from Product options (entity attribute_option). Change detail.text to fill something else; preventDefault() keeps the field as it is (AI in your module)
mrx:ai:appliedfield, action, text, findings, entity, storethe field the AI filledSince 0.6.0. The AI filled the field, with the text that went in. Since 0.7.0 also for a translation approved in the review tab of Products > Translations (action review, entity the type of the item)
mrx:ai:draft-requestparams, store, entitythe product formSince 0.7.0. "Fill in with AI" on a new product is about to send its request. Push the draftFields key of a field you fill into params.empty_fields (AI in your module, step 11)
mrx:ai:draftedfilled, review, categories, skipped, engine, store, values, cost, targets, claim, releasethe product formSince 0.7.0; cost and targets since 0.8.0 (additive). The draft's answer is in the form. Read values[<draftFields key>], fill your field and call claim(key, undo), so the note under the card counts it and "Undo all" calls your undo. If your field has its own Undo, call release(key) from it: the save then stops recording that key as the AI's
mrx:ai:review-decidedids, decision, edited, storethe review tabSince 0.7.0. A decision on waiting translations is about to be sent (approve, reject or approve with an edit). Cancelable: preventDefault() stops it
mrx:ai:calculator:updatedrows, totalthe cost calculator cardSince 0.7.0. The Cost calculator on Settings > AI recomputed its rows after a change of the products, the languages, a job or a model
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
mrx:share-image-changename, value, urlthe Share image field's root, [data-mrx-share-image]Since 0.11.0. The field's image changed: after an upload, Remove, a discard and a switch to "Use default". name is the posted input's name, value the path under media ('' for none), url the image's URL ('' for none). A native change follows on the hidden input, for the save bar (A share image for your page)
mrx:valuechangenonea form fieldSince 0.11.0. The save bar's Discard put the field's saved value back; it fires on each field, bubbles, and replaces input there. A widget that mirrors a hidden field (the rich text editor, the Share image field) listens for it to redraw (Design system, section 5)

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, mrx_has_tracking, mrx_track_url, mrx_track_number and mrx_carrier with a shipment, and mrx_customer_email while the owner shows the customer's email address for the mail's channel. 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:table:bulk, mrx:table:channel, mrx:table:loaded, mrx:table:state (since 0.6.0: after every change of a list's tab, search, sort, page, channel or filters, Back and Forward included; detail is {tab, q, sort, dir, page, channel, filters}), 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