UNPKG

quiz-interactions

Version:

A React UI component Library for quiz interaction types.

129 lines (102 loc) 4.19 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get")); var _react = _interopRequireDefault(require("react")); var _uuid = require("uuid"); var _instructureValidations = require("instructure-validations"); var _quizRce = require("@instructure/quiz-rce"); var _interaction_slugs = require("../../interaction_slugs"); var _InteractionType2 = _interopRequireDefault(require("../InteractionType")); var _validationHelpers = require("../../util/validationHelpers"); var _formatMessage = _interopRequireDefault(require("@instructure/quiz-i18n/lib/format-message")); function newChoiceId() { return (0, _uuid.v4)(); } var eachChoiceRule = { itemBody: [(0, _instructureValidations.rule)('presence', { message: (0, _validationHelpers.presenceMessage)((0, _formatMessage.default)('Answer')) })] }; var MultipleChoiceInteractionType = /*#__PURE__*/ function (_InteractionType) { (0, _inherits2.default)(MultipleChoiceInteractionType, _InteractionType); function MultipleChoiceInteractionType(obj) { var _this; (0, _classCallCheck2.default)(this, MultipleChoiceInteractionType); _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(MultipleChoiceInteractionType).call(this)); _this.slug = _interaction_slugs.MULTIPLE_CHOICE_SLUG; _this.translatedName = (0, _formatMessage.default)('Multiple Choice'); _this.defaultProperties = { shuffleRules: { choices: { shuffled: false, toLock: [] } } }; _this.getDefaultScoringData = function (intData) { return { value: intData.choices[0].id }; }; _this.getDefaultInteractionData = function () { return { choices: [{ id: newChoiceId(), itemBody: '', position: 1 }, { id: newChoiceId(), itemBody: '', position: 2 }, { id: newChoiceId(), itemBody: '', position: 3 }, { id: newChoiceId(), itemBody: '', position: 4 }] }; }; _this.getRenderedResponse = function (responseValue, interactionData) { var choice = interactionData.choices.find(function (c) { return c.id === responseValue; }); return _react.default.createElement(_quizRce.RichContentRenderer, { content: choice ? choice.itemBody : '' }); }; (0, _get2.default)((0, _getPrototypeOf2.default)(MultipleChoiceInteractionType.prototype), "initializeProps", (0, _assertThisInitialized2.default)(_this)).call((0, _assertThisInitialized2.default)(_this), obj); return _this; } return MultipleChoiceInteractionType; }(_InteractionType2.default); exports.default = MultipleChoiceInteractionType; MultipleChoiceInteractionType.validations = { interactionData: { choices: [(0, _instructureValidations.each)(eachChoiceRule), (0, _instructureValidations.rule)('noDuplicates', { field: 'itemBody', message: (0, _validationHelpers.noDuplicatesMessage)((0, _formatMessage.default)('Answer')) }), (0, _instructureValidations.onSelf)((0, _instructureValidations.rule)('listSize', { minMessage: (0, _formatMessage.default)('You must have at least two choices'), min: 2 }))] }, scoringData: { value: [(0, _instructureValidations.rule)('presence', { message: (0, _formatMessage.default)('You must select a correct answer') })] } };