UNPKG

@shopify/app-bridge-host

Version:

App Bridge Host contains components and middleware to be consumed by the app's host, as well as the host itself. The middleware and `Frame` component are responsible for facilitating communication between the client and host, and used to act on actions se

89 lines (81 loc) 4.17 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib = require('tslib'); var TitleBar = require('@shopify/app-bridge-core/actions/TitleBar'); var ButtonGroup = require('@shopify/app-bridge-core/actions/ButtonGroup'); var helper = require('@shopify/app-bridge-core/actions/helper'); var generateUuid = require('@shopify/app-bridge-core/actions/uuid'); var utilities = require('../utilities.js'); var actionCreators = require('./actionCreators.js'); var store_reducers_embeddedApp_titleBar_reducer = require('./reducer.js'); var utils = require('./utils.js'); var actions = require('./actions.js'); function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n.default = e; return Object.freeze(n); } var TitleBar__namespace = /*#__PURE__*/_interopNamespace(TitleBar); var generateUuid__default = /*#__PURE__*/_interopDefault(generateUuid); var getApi = function (_a) { var actions = _a.actions, dispatch = _a.dispatch, subscribe = _a.subscribe, getState = _a.getState; var api = { update: function (payload) { var newPayload = helper.getMergedProps(getState().titleBar || {}, payload); var buttons = newPayload.buttons; // [TODO] revisit unsubscribe implementation // Releases all subscriptions and retained methods because we're rebuilding all of them after. utils.unsub(); if (buttons === null || buttons === void 0 ? void 0 : buttons.primary) { buttons.primary = tslib.__assign(tslib.__assign({}, buttons.primary), { id: utils.updateButton(TitleBar__namespace.Action.BUTTON_CLICK, buttons.primary, subscribe, dispatch) }); } if (buttons === null || buttons === void 0 ? void 0 : buttons.secondary) { buttons.secondary = buttons.secondary.map(function (btn) { if (ButtonGroup.isGroupedButton(btn)) { // Groups can only be one level deep so it's not necessary to make a recursive call return tslib.__assign(tslib.__assign({}, btn), { id: generateUuid__default.default(), buttons: btn.buttons.map(function (groupBtn) { return (tslib.__assign(tslib.__assign({}, groupBtn), { id: utils.updateButton(TitleBar__namespace.Action.BUTTON_CLICK, groupBtn, subscribe, dispatch) })); }) }); } else { return tslib.__assign(tslib.__assign({}, btn), { id: utils.updateButton(TitleBar__namespace.Action.BUTTON_CLICK, btn, subscribe, dispatch) }); } }); } actions.update(newPayload); }, }; return api; }; /** * An object containing the key, actions, initial state and reducer of the TitleBar feature * Can be used with the `withFeature` decorator to add the reducer * and then make its actions and store available to the wrapped component * @public * */ var feature = { actions: actionCreators.titleBarActionCreatorsMap, key: 'titleBar', initialState: store_reducers_embeddedApp_titleBar_reducer.defaultTitlebarStore, reducer: utilities.resetStateReducer(store_reducers_embeddedApp_titleBar_reducer.default), getApi: getApi, }; exports.titleBarActionCreatorsMap = actionCreators.titleBarActionCreatorsMap; exports.default = store_reducers_embeddedApp_titleBar_reducer.default; exports.defaultTitlebarStore = store_reducers_embeddedApp_titleBar_reducer.defaultTitlebarStore; exports.SET_APP_INFO = actions.SET_APP_INFO; exports.SET_PAGINATION = actions.SET_PAGINATION; exports.setAppInfo = actions.setAppInfo; exports.setPagination = actions.setPagination; exports.feature = feature;