UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

330 lines (329 loc) • 15.5 kB
function _array_like_to_array(arr, len) { if (len == null || len > arr.length) len = arr.length; for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } function _array_without_holes(arr) { if (Array.isArray(arr)) return _array_like_to_array(arr); } 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 _iterable_to_array(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _non_iterable_spread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } 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 _to_consumable_array(arr) { return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread(); } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } function _unsupported_iterable_to_array(o, minLen) { if (!o) return; if (typeof o === "string") return _array_like_to_array(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen); } 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 { ScreenReaderContent } from '@instructure/ui-a11y-content'; import { Checkbox } from '@instructure/ui-checkbox'; import { TextInput, FormFieldGroup } from '@instructure/quiz-common'; import NumberInput from '@instructure/quiz-number-input'; import FileUploadInteractionType from '../../../records/interactions/file_upload'; import QuestionContainer from '../../common/edit/components/QuestionContainer'; import QuestionSettingsContainer from '../../common/edit/components/QuestionSettingsContainer'; 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'; var FileUploadEdit = /*#__PURE__*/ function(Component) { "use strict"; _inherits(FileUploadEdit, Component); function FileUploadEdit() { _class_call_check(this, FileUploadEdit); var _this; _this = _call_super(this, FileUploadEdit, arguments), _define_property(_this, "handleCalculatorTypeChange", function(e, value) { _this.props.changeItemState({ calculatorType: value }); }), _define_property(_this, "handleRestrictCountChange", function() { return _this.props.changeItemState({ interactionData: _object_spread_props(_object_spread({}, _this.props.interactionData), { restrictCount: !_this.props.interactionData.restrictCount }) }); }), _define_property(_this, "handleFilesCountChange", function(event, countString, normalizedCountString) { return _this.props.changeItemState({ interactionData: _object_spread_props(_object_spread({}, _this.props.interactionData), { filesCount: normalizedCountString }) }); }), _define_property(_this, "handleRestrictTypesChange", function(event) { return _this.props.changeItemState({ properties: _object_spread_props(_object_spread({}, _this.props.properties), { restrictTypes: event.target.checked }) }); }), _define_property(_this, "handleAllowedTypesChange", function(event) { return _this.props.changeItemState({ properties: _object_spread_props(_object_spread({}, _this.props.properties), { allowedTypes: event.target.value }) }); }); return _this; } _create_class(FileUploadEdit, [ { key: "renderOptions", value: function renderOptions() { var _this_props_properties = this.props.properties, restrictTypes = _this_props_properties.restrictTypes, allowedTypes = _this_props_properties.allowedTypes; var _this_props_interactionData = this.props.interactionData, restrictCount = _this_props_interactionData.restrictCount, filesCount = _this_props_interactionData.filesCount; var allowedTypesDescription = t('File extensions'); var filesCountDescription = t('Max number of files'); var description = /*#__PURE__*/ React.createElement(ScreenReaderContent, null, t('File upload options')); var fieldGroup = /*#__PURE__*/ React.createElement(FormFieldGroup, { rowSpacing: "small", description: description }, this.props.showCalculatorOption && /*#__PURE__*/ React.createElement(CalculatorOptionWithOqaatAlert, { disabled: this.props.overrideEditableForRegrading, calculatorValue: this.props.calculatorType, onCalculatorTypeChange: this.handleCalculatorTypeChange, oqaatChecked: this.props.oneQuestionAtATime, onOqaatChange: this.props.setOneQuestionAtATime }), /*#__PURE__*/ React.createElement(Checkbox, { disabled: this.props.overrideEditableForRegrading, checked: restrictCount, label: t('Limit File number'), onChange: this.handleRestrictCountChange, value: "restrictCount", "data-automation": "sdk-limit-file-number-checkbox" }), restrictCount && /*#__PURE__*/ React.createElement(NumberInput, { disabled: this.props.overrideEditableForRegrading, renderLabel: /*#__PURE__*/ React.createElement(ScreenReaderContent, null, filesCountDescription), messages: this.props.getErrors('interactionData.filesCount'), min: 1, onChange: this.handleFilesCountChange, placeholder: filesCountDescription, value: filesCount, "data-automation": "sdk-limit-file-number-input" }), /*#__PURE__*/ React.createElement(Checkbox, { checked: restrictTypes, disabled: this.props.overrideEditableForRegrading, label: t('Restrict File Types'), onChange: this.handleRestrictTypesChange, value: "restrictTypes", "data-automation": "sdk-restrict-file-type-checkbox" }), restrictTypes && /*#__PURE__*/ React.createElement(TextInput, { interaction: this.props.overrideEditableForRegrading ? 'disabled' : 'enabled', renderLabel: /*#__PURE__*/ React.createElement(ScreenReaderContent, null, allowedTypesDescription), messages: _to_consumable_array(this.props.getErrors('properties.allowedTypes')).concat([ { text: t('Enter file extensions separated by a comma'), type: 'hint' } ]), onChange: this.handleAllowedTypesChange, placeholder: allowedTypesDescription, type: "text", value: allowedTypes, "data-automation": "sdk-file-extensions-input" })); return /*#__PURE__*/ React.createElement(QuestionSettingsContainer, { additionalOptions: this.props.additionalOptions }, /*#__PURE__*/ React.createElement(QuestionSettingsPanel, { label: t('Options'), defaultExpanded: true }, fieldGroup)); } }, { 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') }), this.renderOptions()); } } ]); return FileUploadEdit; }(Component); _define_property(FileUploadEdit, "interactionType", FileUploadInteractionType); _define_property(FileUploadEdit, "propTypes", _object_spread_props(_object_spread({ additionalOptions: PropTypes.array, calculatorType: PropTypes.string, changeItemState: PropTypes.func, enableRichContentEditor: PropTypes.bool, interactionData: PropTypes.shape({ restrictCount: PropTypes.bool.isRequired, filesCount: PropTypes.string.isRequired }).isRequired, itemBody: PropTypes.string.isRequired, onModalClose: PropTypes.func, onModalOpen: PropTypes.func, oneQuestionAtATime: PropTypes.bool, openImportModal: PropTypes.func, overrideEditableForRegrading: PropTypes.bool, properties: PropTypes.shape({ restrictTypes: PropTypes.bool.isRequired, allowedTypes: PropTypes.string }).isRequired, setOneQuestionAtATime: PropTypes.func }, withEditTools.injectedProps), { showCalculatorOption: PropTypes.bool })); _define_property(FileUploadEdit, "defaultProps", { additionalOptions: [], calculatorType: 'none', enableRichContentEditor: true, oneQuestionAtATime: false, overrideEditableForRegrading: false, setOneQuestionAtATime: Function.prototype, changeItemState: void 0, onModalClose: void 0, onModalOpen: void 0, openImportModal: void 0, showCalculatorOption: true }); export { FileUploadEdit as default }; FileUploadEdit = _ts_decorate([ withEditTools ], FileUploadEdit);