UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

88 lines 3.66 kB
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _inherits from "@babel/runtime/helpers/esm/inherits"; import _get from "@babel/runtime/helpers/esm/get"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; function _callSuper(_this, derived, args) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { return !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (e) { return false; } } derived = _getPrototypeOf(derived); return _possibleConstructorReturn(_this, isNativeReflectConstruct() ? Reflect.construct(derived, args || [], _getPrototypeOf(_this).constructor) : derived.apply(_this, args)); } import React from 'react'; import sanitizeHtml from 'sanitize-html'; import { rule, onSelf } from 'instructure-validations'; import { Text } from '@instructure/ui-text'; import { RichContentRenderer } from '@instructure/quiz-rce'; import InteractionType from '../InteractionType'; import { ESSAY_SLUG } from '../../interaction_slugs'; import t from '@instructure/quiz-i18n/es/format-message'; import { allowedTags } from '../../util/htmlAllowedTags'; var EssayInteractionType = /*#__PURE__*/function (_InteractionType) { function EssayInteractionType(obj) { var _this2; _classCallCheck(this, EssayInteractionType); _this2 = _callSuper(this, EssayInteractionType); _defineProperty(_this2, "slug", ESSAY_SLUG); _defineProperty(_this2, "translatedName", t('Essay')); _defineProperty(_this2, "isSubjective", true); _defineProperty(_this2, "getDefaultScoringData", function (intData) { return { value: '' }; }); _defineProperty(_this2, "getDefaultInteractionData", function () { return { essay: null, rce: true, spellCheck: false, wordCount: false, wordLimitEnabled: false, wordLimitMax: null, wordLimitMin: null, fileUpload: false }; }); _defineProperty(_this2, "getRenderedResponse", function (responseValue, interactionData) { if (interactionData.rce) { return /*#__PURE__*/React.createElement(RichContentRenderer, { content: sanitizeHtml(responseValue, { allowedTags: allowedTags }) }); } return /*#__PURE__*/React.createElement(Text, { color: "primary" }, responseValue); }); _get((_this2, _getPrototypeOf(EssayInteractionType.prototype)), "initializeProps", _this2).call(_this2, obj); return _this2; } _inherits(EssayInteractionType, _InteractionType); return _createClass(EssayInteractionType, null, [{ key: "validations", value: function validations() { return { interactionData: [onSelf(rule('boundaries', { enableKey: 'wordLimitEnabled', minKey: 'wordLimitMin', maxKey: 'wordLimitMax', presenceMessage: t('Both minimum and maximum word limits cannot be blank'), numberMessage: t('Both minimum and maximum word limit values must be integers'), rangeMessage: t('Minimum word limit must be less than maximum word limit') }))] }; } }]); }(InteractionType); export { EssayInteractionType as default };