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.
| Event | Detail keys | Fired on | When |
|---|---|---|---|
mrx:ready | none | document | The 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-saved | formCode, entityId, response | the editor's form | A 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-saved | success, message, product, entity_id, ext | the product form | The product editor saved. Kept next to mrx:form-saved for product-only listeners |
mrx:ai:result | field, action, text, findings, entity, store | the field the AI fills | Since 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:applied | field, action, text, findings, entity, store | the field the AI filled | Since 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-request | params, store, entity | the product form | Since 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:drafted | filled, review, categories, skipped, engine, store, values, cost, targets, claim, release | the product form | Since 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-decided | ids, decision, edited, store | the review tab | Since 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:updated | rows, total | the cost calculator card | Since 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:badges | items | document | The 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-sent | options, response | document | The contact-customer modal sent an email, so a timeline can refresh |
mrx:languagebeforechange | storeId, previousStoreId, option, switcher | the switcher | An editor's language switcher is about to change the store view. Cancel it with preventDefault() |
mrx:languagechange | storeId, previousStoreId, option, switcher | the switcher | The editor now shows another store view |
mrx:channelschange | ids, level, card | the Channels card | The channels of a product, discount, page or block changed |
mrx:tabchange | tab, panel | the tab list | A tab of a Light tab set opened |
mrx:themechange | source, state | document | The admin theme or scheme changed |
mrx:themepreference | state | document | The admin saved a theme preference |
mrx:share-image-change | name, value, url | the 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:valuechange | none | a form field | Since 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:
ctx.form.dispatchEvent(new CustomEvent('mrx:form-saved', {bubbles: true, detail: {formCode: formCode, entityId: ctx.entityId, response: response}}));Server events
| Event | Payload | Dispatched by | When |
|---|---|---|---|
mrx_return_resolved_after | return, an array with entity_id, increment_id and order_id | Mrx_Returns | A 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 |
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.
<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.
| Module | Exports | Use it for |
|---|---|---|
Mrx_Light/js/api | request, get, post, ApiError | JSON calls to your controllers, with the form key, error toasts and the session timeout handled |
Mrx_Light/js/config | get, url, all | The #mrx-config values below |
Mrx_Light/js/toast | show, error | Short confirmations and errors |
Mrx_Light/js/modal | open, confirm, isOpen | Dialogs, and confirmations before a destructive action |
Mrx_Light/js/save-bar | attach, get | The "Unsaved changes" bar on your own forms |
Mrx_Light/js/format | money, number, date, dateShort, dateTime, time, relative, parse, hydrate | Money, numbers and dates in the admin's locale and the store's time zone |
Mrx_Light/js/form-hooks | register, validate, extend, saved | Validation and extra payload for your fields on a Light editor (Fields on a Light editor) |
Mrx_Light/js/loader | during, button, skeleton, spinner | A 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.
| Key | Holds |
|---|---|
apiVersion | ExtensionApi::VERSION, the Light API version of this shop |
mode | simple or advanced |
stockView | Whether a stock screen is open through the advanced view in simple mode |
locale | The admin locale, for example nl-NL |
currency | The base currency of the default store |
timezone | The store time zone |
storeName | The store name |
sender | {name, email}, the default sender |
user | {username, name, email} of the signed-in admin |
canContact | Whether the admin may email customers |
urls | The shell's endpoints, among them cacheRefresh (light/cache/refresh, empty when the admin lacks Magento_Backend::cache) |
nav | The nav items the admin may open, {key: {label, url}} |
shortcuts | The keyboard shortcuts |
channels | The channels and their languages |
icons | The 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;detailis{tab, q, sort, dir, page, channel, filters}),mrx:settings-saved,mrx:settings-discard,mrx:pagechangeandmrx:order:updated. - The other modules of ui-kit section 5:
popover,tabs,rich-text,index-table,search-preview,command-palette,shortcuts,icons,dom,contact-customerand the channels modules. Use them on your own pages as the ui-kit shows; they are tier 2.
Last updated on
API reference
Every @api type with its members, generated by the doctor.
Packages and compatibility
Every Light package, which ones install on their own and which come as a set, what a shop may leave off, the bridges to other modules with their version ranges, and the platforms each release is checked on.