UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

114 lines 4.16 kB
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; 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 _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else 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; } import hash from 'object-hash'; var entries = ['Triassic', 'Jurassic', 'Cretaceous']; var labelProperties = { topLabel: 'Earliest', bottomLabel: 'Latest' }; var baseProps = { enableRichContentEditor: false, changeItemState: Function.prototype, openImportModal: Function.prototype }; function exampleLabel(properties) { var enabledProperties = Object.keys(properties).filter(function (prop) { return properties[prop] && !labelProperties[prop]; }); return enabledProperties.length ? "Ordering Edit (".concat(enabledProperties.join(', '), ")") : 'Ordering Edit'; } function validProps(properties) { var ids = entries.map(hash.MD5); var choices = ids.reduce(function (obj, id, index) { return _objectSpread(_objectSpread({}, obj), {}, _defineProperty({}, id, { id: id, itemBody: entries[index] })); }, {}); return _objectSpread(_objectSpread({}, baseProps), {}, { itemBody: exampleLabel(properties), interactionData: { choices: choices }, scoringData: { value: ids }, properties: properties }); } function errorProps() { var ids = entries.map(hash.MD5); var choices = ids.reduce(function (obj, id) { return _objectSpread(_objectSpread({}, obj), {}, _defineProperty({}, id, { id: id, itemBody: '' })); }, {}); return _objectSpread(_objectSpread({}, baseProps), {}, { itemBody: '', interactionData: { choices: choices }, scoringData: { value: ids }, properties: { includeLabels: true, displayAnswersParagraph: false, topLabel: '', bottomLabel: '' }, errors: { itemBody: ['You must have an item body'], interactionData: { choices: ids.reduce(function (obj, id) { return _objectSpread(_objectSpread({}, obj), {}, _defineProperty({}, id, { itemBody: ['Answer cannot be blank'] })); }, {}) }, properties: { topLabel: ['Top label cannot be blank'], bottomLabel: ['Bottom label cannot be blank'] } } }); } var errorExampleShown = false; export default { propValues: { errorsAreShowing: [false, true], properties: [_objectSpread({ displayAnswersParagraph: false, includeLabels: false }, labelProperties), _objectSpread({ displayAnswersParagraph: false, includeLabels: true }, labelProperties), _objectSpread({ displayAnswersParagraph: true, includeLabels: false }, labelProperties), _objectSpread({ displayAnswersParagraph: true, includeLabels: true }, labelProperties)] }, getComponentProps: function getComponentProps(props) { var errorsAreShowing = props.errorsAreShowing, properties = props.properties; if (errorsAreShowing) { return errorProps(); } return validProps(properties); }, filter: function filter(_ref) { var errorsAreShowing = _ref.errorsAreShowing; // Show all the errors in a single example, to avoid ending up // with thousands of permutations and running out of memory. if (errorsAreShowing && errorExampleShown) { return true; } errorExampleShown = true; return false; } };