UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

274 lines (273 loc) • 11.6 kB
function _assert_this_initialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _call_super(_this, derived, args) { derived = _get_prototype_of(derived); return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args)); } function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for(var i = 0; i < props.length; i++){ var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _create_class(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _define_property(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _get_prototype_of(o) { _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _get_prototype_of(o); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _set_prototype_of(subClass, superClass); } function _object_spread(target) { for(var i = 1; i < arguments.length; i++){ var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === "function") { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function(key) { _define_property(target, key, source[key]); }); } return target; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function(sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _object_spread_props(target, source) { source = source != null ? source : {}; if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function(key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _possible_constructor_return(self, call) { if (call && (_type_of(call) === "object" || typeof call === "function")) { return call; } return _assert_this_initialized(self); } function _set_prototype_of(o, p) { _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _set_prototype_of(o, p); } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } function _is_native_reflect_construct() { try { var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {})); } catch (_) {} return (_is_native_reflect_construct = function() { return !!result; })(); } function _ts_decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } import React, { Component } from 'react'; import PropTypes from 'prop-types'; import getOr from 'lodash/fp/getOr'; import t from '@instructure/quiz-i18n/format-message'; import ChoiceBody from '../components/ChoiceBody'; import QuestionSettingsContainer from '../../common/edit/components/QuestionSettingsContainer'; import QuestionContainer from '../../common/edit/components/QuestionContainer'; import TrueFalseInteractionType from '../../../records/interactions/true_false'; import withEditTools from '../../../util/withEditTools'; import QuestionSettingsPanel from '../../common/edit/components/QuestionSettingsPanel'; import CalculatorOptionWithOqaatAlert from '../../common/edit/components/CalculatorOptionWithOqaatAlert'; import { ScreenReaderContent } from '@instructure/ui-a11y-content'; import { FormFieldGroup } from '@instructure/quiz-common'; var TRUE_VALUE = 'trueChoice'; var FALSE_VALUE = 'falseChoice'; var TrueFalseEdit = /*#__PURE__*/ function(Component) { "use strict"; _inherits(TrueFalseEdit, Component); function TrueFalseEdit() { _class_call_check(this, TrueFalseEdit); var _this; _this = _call_super(this, TrueFalseEdit, arguments), _define_property(_this, "stemElement", null), _define_property(_this, "handleCalculatorTypeChange", function(e, value) { _this.props.changeItemState({ calculatorType: value }); }), _define_property(_this, "handleSelectionUpdate", function(event, newChoice) { _this.props.changeItemState({ scoringData: _object_spread_props(_object_spread({}, _this.props.scoringData), { value: newChoice === TRUE_VALUE }) }); }), _define_property(_this, "handleStemRef", function(node) { _this.stemElement = node; }), _define_property(_this, "focusErrors", function() { var stemErrors = getOr([], 'itemBody', _this.props.errors); if (stemErrors.length) { _this.stemElement.focus(); } }); return _this; } _create_class(TrueFalseEdit, [ { key: "renderOptionsDescription", value: function renderOptionsDescription() { return /*#__PURE__*/ React.createElement(ScreenReaderContent, null, t('True or false options')); } }, { key: "selectedValue", value: function selectedValue() { if (this.props.isSurvey) { return ''; } return this.props.scoringData.value ? TRUE_VALUE : FALSE_VALUE; } }, { key: "render", value: function render() { return /*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement(QuestionContainer, { disabled: this.props.overrideEditableForRegrading, enableRichContentEditor: this.props.enableRichContentEditor, itemBody: this.props.itemBody, onDescriptionChange: this.props.onDescriptionChange, onModalClose: this.props.onModalClose, onModalOpen: this.props.onModalOpen, openImportModal: this.props.openImportModal, stemErrors: this.props.getErrors('itemBody'), textareaRef: this.handleStemRef }, /*#__PURE__*/ React.createElement(ChoiceBody, { selectedValue: this.selectedValue(), readOnly: this.props.isSurvey, falseChoiceLabel: this.props.interactionData.falseChoice, name: "edit_interaction_".concat(this.props.itemId), onSelectionUpdate: this.handleSelectionUpdate, trueChoiceLabel: this.props.interactionData.trueChoice, itemBody: this.props.itemBody, screenreaderOnlyDescription: true })), /*#__PURE__*/ React.createElement(QuestionSettingsContainer, { additionalOptions: this.props.additionalOptions }, this.props.showCalculatorOption && /*#__PURE__*/ React.createElement(QuestionSettingsPanel, { label: t('Options'), defaultExpanded: true }, /*#__PURE__*/ React.createElement(FormFieldGroup, { rowSpacing: "small", description: this.renderOptionsDescription() }, /*#__PURE__*/ React.createElement(CalculatorOptionWithOqaatAlert, { disabled: this.props.overrideEditableForRegrading, calculatorValue: this.props.calculatorType, onCalculatorTypeChange: this.handleCalculatorTypeChange, oqaatChecked: this.props.oneQuestionAtATime, onOqaatChange: this.props.setOneQuestionAtATime }))))); } } ]); return TrueFalseEdit; }(Component); _define_property(TrueFalseEdit, "interactionType", TrueFalseInteractionType); _define_property(TrueFalseEdit, "propTypes", _object_spread_props(_object_spread({ additionalOptions: QuestionSettingsContainer.propTypes.additionalOptions, calculatorType: PropTypes.string, changeItemState: PropTypes.func, enableRichContentEditor: PropTypes.bool, interactionData: PropTypes.shape({ trueChoice: PropTypes.string, falseChoice: PropTypes.string }).isRequired, itemBody: PropTypes.string.isRequired, itemId: PropTypes.string, onModalClose: PropTypes.func, onModalOpen: PropTypes.func, oneQuestionAtATime: PropTypes.bool, openImportModal: PropTypes.func, overrideEditableForRegrading: PropTypes.bool, scoringData: PropTypes.shape({ value: PropTypes.bool }).isRequired, setOneQuestionAtATime: PropTypes.func }, withEditTools.injectedProps), { showCalculatorOption: PropTypes.bool, isSurvey: PropTypes.bool })); _define_property(TrueFalseEdit, "defaultProps", { additionalOptions: void 0, calculatorType: 'none', changeItemState: void 0, enableRichContentEditor: true, itemId: void 0, onModalClose: void 0, onModalOpen: void 0, oneQuestionAtATime: false, openImportModal: void 0, overrideEditableForRegrading: false, setOneQuestionAtATime: Function.prototype, showCalculatorOption: true }); export { TrueFalseEdit as default }; TrueFalseEdit = _ts_decorate([ withEditTools ], TrueFalseEdit);