UNPKG

@mopinion/survey

Version:

Collect customer feedback with the Mopinion survey library

92 lines (91 loc) 3.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCurrentVisibleId = getCurrentVisibleId; exports.getInitialElementValue = getInitialElementValue; exports.getNextVisibleId = getNextVisibleId; exports.isNestedStateProp = isNestedStateProp; var _utils = require("../../../utils"); var _constants = require("../../../constants"); function getInitialElementValue() { var _block$properties, _block$properties2; var block = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var preselectScoreValue = null; if ((_block$properties = block.properties) !== null && _block$properties !== void 0 && _block$properties.preselectScore) { switch (block.typeName) { case 'nps': case 'thumbs': preselectScoreValue = (0, _utils.getUrlParam)(block.typeName, (0, _utils.getPageSearch)()); break; case 'rating': default: if (block.properties.type === 'emoji') { preselectScoreValue = (0, _utils.getUrlParam)('smiley', (0, _utils.getPageSearch)()); if (preselectScoreValue && block.properties.labelsAsValue && block.properties.labelsAsValue) { var _block$properties$emo, _block$properties$emo2; preselectScoreValue = (_block$properties$emo = (_block$properties$emo2 = block.properties.emoji) === null || _block$properties$emo2 === void 0 || (_block$properties$emo2 = _block$properties$emo2[preselectScoreValue]) === null || _block$properties$emo2 === void 0 ? void 0 : _block$properties$emo2.label) !== null && _block$properties$emo !== void 0 ? _block$properties$emo : ''; } break; } preselectScoreValue = (0, _utils.getUrlParam)('score', (0, _utils.getPageSearch)()); } if (preselectScoreValue) { return { post: true, logic: true, value: preselectScoreValue }; } } var urlParamValue = (0, _utils.getUrlParam)("".concat(block.typeName, "_").concat(block.id), (0, _utils.getPageSearch)()) || (0, _utils.getUrlParam)("".concat(block.typeName, "_").concat(block.uuid), (0, _utils.getPageSearch)()); if (urlParamValue) { return { post: true, logic: true, value: urlParamValue }; } if ((_block$properties2 = block.properties) !== null && _block$properties2 !== void 0 && _block$properties2.value) { return { logic: true, value: block.properties.value }; } return { value: '' }; } function isNestedStateProp() { var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; return ['dom', 'selector'].indexOf(str) > -1 || !isNaN(Number(str)); } function getCurrentVisibleId(_ref) { var _layout$filter$pop; var layout = _ref.layout, blockState = _ref.blockState, blocks = _ref.blocks; return (_layout$filter$pop = layout.filter(function (blockId) { var state = blockState[blockId]; var block = blocks[blockId]; return state.isVisible && state.showInConvo && _constants.alwaysNotVisibleBlocks.indexOf(block === null || block === void 0 ? void 0 : block.typeName) === -1; }).pop()) !== null && _layout$filter$pop !== void 0 ? _layout$filter$pop : null; } function getNextVisibleId(_ref2) { var layout = _ref2.layout, blockState = _ref2.blockState, blocks = _ref2.blocks; var currentVisibleBlockId = getCurrentVisibleId({ layout: layout, blockState: blockState, blocks: blocks }); var currentIndex = layout.indexOf(currentVisibleBlockId); var nextVisibleId = layout.slice(currentIndex + 1, layout.length).filter(function (blockId) { var state = blockState[blockId]; var block = blocks[blockId]; return state.isVisible && _constants.alwaysNotVisibleBlocks.indexOf(block.typeName) === -1; })[0]; return nextVisibleId; } //# sourceMappingURL=index.js.map