Widget Query Functions
Functions for querying the widget registry. All imported from @evershop/evershop/lib/widget.
Import
import {
getAllWidgets,
getEnabledWidgets,
getWidget,
hasWidget
} from '@evershop/evershop/lib/widget';
Functions
getAllWidgets
getAllWidgets(): Widget[]
Returns all registered widgets (both enabled and disabled).
getEnabledWidgets
getEnabledWidgets(): Widget[]
Returns only widgets where enabled === true. It reads through the same underlying call as getAllWidgets() and therefore freezes the registry too.
Both of these freeze the registry
After the first call to either getAllWidgets() or getEnabledWidgets(), the widget manager becomes read-only. Any later registerWidget, updateWidget or removeWidget throws. getWidget() and hasWidget() are safe — they do not freeze anything.
Returned shape
Both functions return frozen copies of the registered widget objects, with three generated component keys added:
| Field | Description |
|---|---|
componentKey | Bundle key for the storefront component, derived from the component path. |
settingComponentKey | Bundle key for the admin settings component, derived from the settingComponent path. |
previewComponentKey | Bundle key for the page-builder palette preview. Unlike the other two it is derived from the widget type, not the path — it is always admin_widget_preview_<type>. |
getWidget
getWidget(widgetType: string): Widget | undefined
Returns a single widget by its type identifier.
hasWidget
hasWidget(widgetType: string): boolean
Checks if a widget with the given type is registered.
Examples
import { getEnabledWidgets, getWidget, hasWidget } from '@evershop/evershop/lib/widget';
const widgets = getEnabledWidgets();
console.log(`${widgets.length} widgets available`);
if (hasWidget('collection_products')) {
const widget = getWidget('collection_products');
console.log(widget.name); // 'Collection products'
}
See Also
- registerWidget — Register a widget
- updateWidget — Update a widget
- removeWidget — Remove a widget
- Widget Development — Full widget guide