UNPKG

@shopgate/engage

Version:
17 lines 1.75 kB
import defaultsDeep from'lodash/defaultsDeep';import{getPageSettings}from"./getPageSettings";import{getWidgetConfig}from"./getWidgetConfig";/** * Retrieves the settings of a specific widget by its id and an optional index on the given page. * If no index is given it will return the first found widget settings by widgetId on that page. * Widget settings that are not defined in the widget settings directly, are inherited from page * and theme settings in the upper hierarchy of the config, scoped by the widgetId as key. * Settings containing arrays will not be deeply inherited. * If no widget is not found on the given page or at the given index, or no settings exist for the * given widget id/index combination, then the result will always be an empty object. * * @param {string} pagePattern The pattern of the page where the widget is located. * @param {string} widgetId The id of the widget to look for, which must exist in the config. * @param {number|undefined} [index=0] The optional index of the widget. * @returns {Object} */export function getWidgetSettings(pagePattern,widgetId){var index=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;// Use widget id as key to filter by in page settings var inheritedPageSettings=getPageSettings(pagePattern,widgetId);var _getWidgetConfig=getWidgetConfig(pagePattern,widgetId,index),_getWidgetConfig$sett=_getWidgetConfig.settings,localWidgetSettings=_getWidgetConfig$sett===void 0?{}:_getWidgetConfig$sett;// Trying to inherit settings from page scope by key can result in an undefined value, because // the given keys are not always present. if(inheritedPageSettings===undefined){return localWidgetSettings;}return defaultsDeep(localWidgetSettings,inheritedPageSettings);}