@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
394 lines (393 loc) • 18 kB
JavaScript
/** @jsx jsx */ 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 { Component } from 'react';
import PropTypes from 'prop-types';
import { Checkbox } from '@instructure/ui-checkbox';
import NumberInput from '@instructure/quiz-number-input';
import { ScreenReaderContent } from '@instructure/ui-a11y-content';
import { jsx } from '@instructure/emotion';
import EssayInteractionType from '../../../records/interactions/essay';
import QuestionSettingsContainer from '../../common/edit/components/QuestionSettingsContainer';
import QuestionContainer from '../../common/edit/components/QuestionContainer';
import generateStyle from './styles';
import generateComponentTheme from './theme';
import withEditTools from '../../../util/withEditTools';
import t from '@instructure/quiz-i18n/format-message';
import QuestionSettingsPanel from '../../common/edit/components/QuestionSettingsPanel';
import CalculatorOptionWithOqaatAlert from '../../common/edit/components/CalculatorOptionWithOqaatAlert';
import { TextArea, withStyleOverrides, FormFieldGroup } from '@instructure/quiz-common';
var EssayEdit = /*#__PURE__*/ function(Component) {
"use strict";
_inherits(EssayEdit, Component);
function EssayEdit(props) {
_class_call_check(this, EssayEdit);
var _this;
_this = _call_super(this, EssayEdit, [
props
]), // =============
// HANDLERS
// =============
_define_property(_this, "handleCalculatorTypeChange", function(e, value) {
_this.props.changeItemState({
calculatorType: value
});
}), _define_property(_this, "handleCheckboxChange", function(event) {
_this.mergeInteractionData(_define_property({}, event.target.value, !_this.props.interactionData[event.target.value]));
}), _define_property(_this, "handleNotesChange", function(event) {
_this.props.changeItemState({
scoringData: {
value: event.target.value
}
});
}), _define_property(_this, "handleWordLimitMinChange", function(event, value, normalizedValue) {
_this.setState({
wordLimitMin: value,
normalizedWordLimitMin: normalizedValue
});
}), _define_property(_this, "handleWordLimitMaxChange", function(event, value, normalizedValue) {
_this.setState({
wordLimitMax: value,
normalizedWordLimitMax: normalizedValue
});
}), _define_property(_this, "handleWordLimitBlur", function(key, normalizedKey) {
if (_this.state[normalizedKey] == null) {
_this.mergeInteractionData(_define_property({}, key, null));
_this.setState(_define_property({}, key, null));
} else {
var wordLimit = parseInt(_this.state[normalizedKey], 10) || 0;
_this.mergeInteractionData(_define_property({}, key, wordLimit.toString()));
_this.setState(_define_property({}, key, wordLimit));
}
}), _define_property(_this, "handleWordLimitMinBlur", function() {
_this.handleWordLimitBlur('wordLimitMin', 'normalizedWordLimitMin');
}), _define_property(_this, "handleWordLimitMaxBlur", function() {
_this.handleWordLimitBlur('wordLimitMax', 'normalizedWordLimitMax');
}), _define_property(_this, "handleDescriptionChange", function(itemBody) {
return _this.props.changeItemState({
itemBody: itemBody
});
});
var _props_interactionData = props.interactionData, wordLimitMin = _props_interactionData.wordLimitMin, wordLimitMax = _props_interactionData.wordLimitMax;
_this.state = {
wordLimitMin: wordLimitMin && Number(wordLimitMin),
wordLimitMax: wordLimitMax && Number(wordLimitMax),
normalizedWordLimitMin: wordLimitMin,
normalizedWordLimitMax: wordLimitMax
};
return _this;
}
_create_class(EssayEdit, [
{
// =============
// HELPERS
// =============
key: "mergeInteractionData",
value: function mergeInteractionData(intDataDiff) {
this.props.changeItemState({
interactionData: Object.assign({}, this.props.interactionData, intDataDiff)
});
}
},
{
// =============
// RENDERING
// =============
key: "renderGradingNotes",
value: function renderGradingNotes() {
return /*#__PURE__*/ jsx(TextArea, {
disabled: this.props.overrideEditableForRegrading,
label: /*#__PURE__*/ jsx(ScreenReaderContent, null, t('Grading Notes')),
defaultValue: this.props.scoringData.value,
onChange: this.handleNotesChange,
autoGrow: this.context.disableTextAreaAutoGrow ? false : null,
"data-automation": "sdk-essay-grading-notes-text-area"
});
}
},
{
key: "renderOptions",
value: function renderOptions() {
var description = /*#__PURE__*/ jsx(ScreenReaderContent, null, t('Essay options'));
return /*#__PURE__*/ jsx(FormFieldGroup, {
rowSpacing: "small",
description: description
}, this.props.showCalculatorOption && /*#__PURE__*/ jsx(CalculatorOptionWithOqaatAlert, {
disabled: this.props.overrideEditableForRegrading,
calculatorValue: this.props.calculatorType,
onCalculatorTypeChange: this.handleCalculatorTypeChange,
oqaatChecked: this.props.oneQuestionAtATime,
onOqaatChange: this.props.setOneQuestionAtATime
}), /*#__PURE__*/ jsx(Checkbox, {
disabled: this.props.overrideEditableForRegrading,
value: "rce",
"data-automation": "sdk-essay-rce-checkbox",
label: t('Rich Content Editor'),
onChange: this.handleCheckboxChange,
checked: this.props.interactionData.rce
}), /*#__PURE__*/ jsx(Checkbox, {
disabled: this.props.overrideEditableForRegrading,
value: "spellCheck",
"data-automation": "sdk-essay-spellcheck-checkbox",
label: t('Spell-check'),
onChange: this.handleCheckboxChange,
checked: this.props.interactionData.spellCheck
}), /*#__PURE__*/ jsx(Checkbox, {
disabled: this.props.overrideEditableForRegrading,
value: "wordCount",
"data-automation": "sdk-essay-wordcount-checkbox",
label: t('Show Word Count'),
onChange: this.handleCheckboxChange,
checked: this.props.interactionData.wordCount
}), /*#__PURE__*/ jsx(Checkbox, {
disabled: this.props.overrideEditableForRegrading,
value: "wordLimitEnabled",
"data-automation": "sdk-essay-wordlimit-checkbox",
label: t('Set Word Limit'),
onChange: this.handleCheckboxChange,
checked: this.props.interactionData.wordLimitEnabled
}), this.renderWordLimitInput());
}
},
{
key: "renderWordLimitInput",
value: function renderWordLimitInput() {
if (this.props.interactionData.wordLimitEnabled) {
var currentMinValue = this.state.wordLimitMin == null ? '' : this.state.wordLimitMin;
var currentMaxValue = this.state.wordLimitMax == null ? '' : this.state.wordLimitMax;
return /*#__PURE__*/ jsx("div", null, /*#__PURE__*/ jsx("div", {
css: this.props.styles.wordLimitInputsContainer
}, /*#__PURE__*/ jsx("div", {
css: this.props.styles.wordLimitInput
}, /*#__PURE__*/ jsx(NumberInput, {
disabled: this.props.overrideEditableForRegrading,
"data-automation": "sdk-essay-wordlimit-min",
min: "0",
width: "8rem",
renderLabel: t('Minimum'),
placeholder: t('Limit'),
value: currentMinValue,
onChange: this.handleWordLimitMinChange,
onBlur: this.handleWordLimitMinBlur,
messages: this.props.getErrors('interactionData.$errors'),
"aria-valuetext": "".concat(currentMinValue, " ").concat(t('Words minimum'))
})), /*#__PURE__*/ jsx("div", {
css: this.props.styles.wordLimitInput
}, /*#__PURE__*/ jsx(NumberInput, {
disabled: this.props.overrideEditableForRegrading,
"data-automation": "sdk-essay-wordlimit-max",
min: "0",
width: "8rem",
renderLabel: t('Maximum'),
placeholder: t('Limit'),
value: currentMaxValue,
onChange: this.handleWordLimitMaxChange,
onBlur: this.handleWordLimitMaxBlur,
"aria-valuetext": "".concat(currentMaxValue, " ").concat(t('Words maximum'))
}))));
}
}
},
{
key: "renderQuestionConfigContainer",
value: function renderQuestionConfigContainer() {
return /*#__PURE__*/ jsx(QuestionSettingsContainer, {
additionalOptions: this.props.additionalOptions
}, /*#__PURE__*/ jsx(QuestionSettingsPanel, {
label: t('Options'),
defaultExpanded: true
}, this.renderOptions()), /*#__PURE__*/ jsx(QuestionSettingsPanel, {
label: t('Grading Notes')
}, this.renderGradingNotes()));
}
},
{
key: "render",
value: function render() {
return /*#__PURE__*/ jsx("div", null, /*#__PURE__*/ jsx(QuestionContainer, {
disabled: this.props.overrideEditableForRegrading,
enableRichContentEditor: this.props.enableRichContentEditor,
itemBody: this.props.itemBody,
onDescriptionChange: this.handleDescriptionChange,
onModalClose: this.props.onModalClose,
onModalOpen: this.props.onModalOpen,
openImportModal: this.props.openImportModal,
stemErrors: this.props.getErrors('itemBody'),
automationData: "sdk-essay-rce"
}), this.renderQuestionConfigContainer());
}
}
]);
return EssayEdit;
}(Component);
_define_property(EssayEdit, "displayName", 'EssayEdit');
_define_property(EssayEdit, "componentId", "Quizzes".concat(EssayEdit.displayName));
_define_property(EssayEdit, "interactionType", EssayInteractionType);
_define_property(EssayEdit, "propTypes", _object_spread_props(_object_spread({
additionalOptions: PropTypes.array,
calculatorType: PropTypes.string,
changeItemState: PropTypes.func.isRequired,
enableRichContentEditor: PropTypes.bool,
interactionData: PropTypes.object.isRequired,
itemBody: PropTypes.string.isRequired,
onModalClose: PropTypes.func,
onModalOpen: PropTypes.func,
oneQuestionAtATime: PropTypes.bool,
openImportModal: PropTypes.func,
overrideEditableForRegrading: PropTypes.bool,
scoringData: PropTypes.shape({
value: PropTypes.string.isRequired
}).isRequired,
setOneQuestionAtATime: PropTypes.func
}, withEditTools.injectedProps), {
styles: PropTypes.object,
showCalculatorOption: PropTypes.bool
}));
_define_property(EssayEdit, "defaultProps", {
calculatorType: 'none',
enableRichContentEditor: true,
oneQuestionAtATime: false,
overrideEditableForRegrading: false,
additionalOptions: [],
setOneQuestionAtATime: Function.prototype,
onModalClose: void 0,
onModalOpen: void 0,
openImportModal: void 0,
showCalculatorOption: true
});
_define_property(EssayEdit, "contextTypes", {
disableTextAreaAutoGrow: PropTypes.bool
});
export { EssayEdit as default };
EssayEdit = _ts_decorate([
withEditTools,
withStyleOverrides(generateStyle, generateComponentTheme)
], EssayEdit);