UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

851 lines (850 loc) • 34.5 kB
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; 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 _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/esm/inherits"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; var _dec, _class, _DrawingContainer; 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; } 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)); } /** @jsx jsx */ import { Component, createRef } from 'react'; import PropTypes from 'prop-types'; import ReactDOM from 'react-dom'; import debounce from 'lodash/debounce'; import { Button, CondensedButton, IconButton } from '@instructure/ui-buttons'; import { IconTrashLine, IconUploadLine, IconExpandItemsLine } from '@instructure/ui-icons'; import { Text } from '@instructure/ui-text'; import { Spinner } from '@instructure/ui-spinner'; import { Popover } from '@instructure/ui-popover'; import { jsx } from '@instructure/emotion'; import { FileDrop, FormFieldGroup, SimpleModal, withStyleOverrides } from '@instructure/quiz-common'; import generateStyle from './styles'; import generateComponentTheme from './theme'; import t from '@instructure/quiz-i18n/es/format-message'; import { ScreenReaderContent } from '@instructure/ui-a11y-content'; var DrawingContainer = (_dec = withStyleOverrides(generateStyle, generateComponentTheme), _dec(_class = (_DrawingContainer = /*#__PURE__*/function (_Component) { function DrawingContainer() { var _this2; _classCallCheck(this, DrawingContainer); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this2 = _callSuper(this, DrawingContainer, [].concat(args)); _defineProperty(_this2, "state", { imageWidth: 0, imageHeight: 0, isModalOpen: false, currentPolygonCoordinates: null }); _defineProperty(_this2, "drawingContainerRef", createRef()); _defineProperty(_this2, "modalDrawingContainerRef", createRef()); // =========== // HELPERS // =========== _defineProperty(_this2, "currentImageWidth", function () { return _this2.state.imageWidth; }); _defineProperty(_this2, "currentImageHeight", function () { return _this2.state.imageHeight; }); _defineProperty(_this2, "updateSize", debounce(function () { if (_this2.props.url && _this2.image) { // ref element (this.image) is not enough to get the updated image dimensions var rectObject = ReactDOM.findDOMNode(_this2.image).getBoundingClientRect(); _this2.setDimensions(rectObject); } }, 50)); _defineProperty(_this2, "setDimensions", function (rectObject) { _this2.setState({ imageWidth: rectObject.width, imageHeight: rectObject.height }); }); _defineProperty(_this2, "transformCoordinates", function (coordinates, imageWidth, imageHeight) { return coordinates === null || coordinates === void 0 ? void 0 : coordinates.map(function (_ref) { var x = _ref.x, y = _ref.y; return { x: x * imageWidth, y: y * imageHeight }; }); }); _defineProperty(_this2, "updateCoordinates", function (coordinates, key, increment, imageWidth, imageHeight, shiftKey, altKey) { var updatedCoordinates = _toConsumableArray(coordinates); var _updatedCoordinates = _slicedToArray(updatedCoordinates, 2), topLeft = _updatedCoordinates[0], bottomRight = _updatedCoordinates[1]; if (shiftKey && altKey) { switch (key) { case 'ArrowLeft': bottomRight.x = Math.max(topLeft.x + increment, bottomRight.x - increment); break; case 'ArrowRight': topLeft.x = Math.min(bottomRight.x - increment, topLeft.x + increment); break; case 'ArrowUp': bottomRight.y = Math.max(topLeft.y + increment, bottomRight.y - increment); break; case 'ArrowDown': topLeft.y = Math.min(bottomRight.y - increment, topLeft.y + increment); break; default: break; } } else if (shiftKey) { switch (key) { case 'ArrowUp': topLeft.y = Math.max(0, topLeft.y - increment); break; case 'ArrowDown': bottomRight.y = Math.min(imageHeight, bottomRight.y + increment); break; case 'ArrowLeft': topLeft.x = Math.max(0, topLeft.x - increment); break; case 'ArrowRight': bottomRight.x = Math.min(imageWidth, bottomRight.x + increment); break; default: break; } } else { switch (key) { case 'ArrowUp': topLeft.y = Math.max(0, topLeft.y - increment); bottomRight.y = Math.max(0, bottomRight.y - increment); break; case 'ArrowDown': topLeft.y = Math.min(imageHeight, topLeft.y + increment); bottomRight.y = Math.min(imageHeight, bottomRight.y + increment); break; case 'ArrowLeft': topLeft.x = Math.max(0, topLeft.x - increment); bottomRight.x = Math.max(0, bottomRight.x - increment); break; case 'ArrowRight': topLeft.x = Math.min(imageWidth, topLeft.x + increment); bottomRight.x = Math.min(imageWidth, bottomRight.x + increment); break; default: break; } } return updatedCoordinates; }); _defineProperty(_this2, "isImageUploaded", function () { return !!_this2.image; }); _defineProperty(_this2, "isArrowKey", function (key) { return ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(key); }); _defineProperty(_this2, "isLetterKey", function (key) { return ['b', 'B', 'd', 'D', 'e', 'E', 'f', 'F', 'i', 'I', 'o', 'O', 'p', 'P', 'r', 'R'].includes(key); }); _defineProperty(_this2, "getCurrentHotspot", function () { return _this2.props.multipleHotSpotEnabled ? _this2.props.hotspots.find(function (hotspot) { return hotspot.id === _this2.props.currentHotspotId; }) : _this2.props.hotspots[0]; }); _defineProperty(_this2, "isOutsideDrawingContainer", function () { var _this2$drawingContain, _this2$modalDrawingCo; var activeElement = document.activeElement; return !((_this2$drawingContain = _this2.drawingContainerRef) !== null && _this2$drawingContain !== void 0 && (_this2$drawingContain = _this2$drawingContain.current) !== null && _this2$drawingContain !== void 0 && _this2$drawingContain.contains(activeElement)) && !((_this2$modalDrawingCo = _this2.modalDrawingContainerRef) !== null && _this2$modalDrawingCo !== void 0 && (_this2$modalDrawingCo = _this2$modalDrawingCo.current) !== null && _this2$modalDrawingCo !== void 0 && _this2$modalDrawingCo.contains(activeElement)); }); _defineProperty(_this2, "isBankOrOutcomesModalOpen", function () { return !!document.querySelector('[data-automation="sdk-add-to-bank-modal"], [data-automation="outcomePicker__modal"]'); }); // =========== // HANDLERS // ============ _defineProperty(_this2, "handleImageLoad", function (e) { _this2.setDimensions({ height: e.target.offsetHeight, width: e.target.offsetWidth }); }); _defineProperty(_this2, "handleSelectDrawOption", function (type) { _this2.props.onSetType(type); }); _defineProperty(_this2, "handleExpandImage", function () { if (_this2.isOutsideDrawingContainer()) { return; } _this2.props.onModalOpen(); _this2.setState({ isModalOpen: true }); }); _defineProperty(_this2, "handleCloseModal", function () { _this2.props.onModalClose(); _this2.setState({ isModalOpen: false }); }); _defineProperty(_this2, "handleCanvasRef", function (node) { _this2.canvas = node && node.canvas; }); _defineProperty(_this2, "handleImageRef", function (node) { _this2.image = node; }); _defineProperty(_this2, "handleFileDropRef", function (node) { _this2.fileDrop = node; }); _defineProperty(_this2, "moveOrResizePolygon", function (key, shiftKey, altKey) { var hotspot = _this2.getCurrentHotspot(); var coordinates = _this2.transformCoordinates(hotspot.coordinates, _this2.state.imageWidth, _this2.state.imageHeight); var increment = 10; var updatedCoordinates = _toConsumableArray(coordinates); var lastCoordinate = updatedCoordinates[updatedCoordinates.length - 1]; var lastCoordinatesCopy = _objectSpread({}, lastCoordinate); _this2.canvas = _this2.canvas || _this2.props.canvasRef; if (_this2.props.currentType !== 'polygon' || !_this2.canvas.isDrawing()) { return; } if (altKey && shiftKey) { switch (key) { case 'ArrowUp': lastCoordinatesCopy.y = Math.max(0, lastCoordinatesCopy.y + increment); break; case 'ArrowDown': lastCoordinatesCopy.y = Math.min(_this2.state.imageHeight, lastCoordinatesCopy.y - increment); break; case 'ArrowLeft': lastCoordinatesCopy.x = Math.max(0, lastCoordinatesCopy.x - increment); break; case 'ArrowRight': lastCoordinatesCopy.x = Math.min(_this2.state.imageWidth, lastCoordinatesCopy.x + increment); break; default: return; } if (updatedCoordinates.length > 1) { var lastIndex = updatedCoordinates.length - 1; var secondLastIndex = lastIndex - 1; if (updatedCoordinates[lastIndex].x === updatedCoordinates[secondLastIndex].x && updatedCoordinates[lastIndex].y === updatedCoordinates[secondLastIndex].y || updatedCoordinates[lastIndex].x === updatedCoordinates[0].x && updatedCoordinates[lastIndex].y === updatedCoordinates[0].y) { updatedCoordinates.pop(); } } updatedCoordinates = updatedCoordinates.slice(0, -1).concat(lastCoordinatesCopy); _this2.setState({ currentPolygonCoordinates: lastCoordinatesCopy }); } else if (shiftKey) { switch (key) { case 'ArrowUp': lastCoordinatesCopy.y = Math.max(0, lastCoordinatesCopy.y - increment); break; case 'ArrowDown': lastCoordinatesCopy.y = Math.min(_this2.state.imageHeight, lastCoordinatesCopy.y + increment); break; case 'ArrowLeft': lastCoordinatesCopy.x = Math.max(0, lastCoordinatesCopy.x - increment); break; case 'ArrowRight': lastCoordinatesCopy.x = Math.min(_this2.state.imageWidth, lastCoordinatesCopy.x + increment); break; default: return; } _this2.setState({ currentPolygonCoordinates: lastCoordinatesCopy }); updatedCoordinates = updatedCoordinates.slice(0, -1).concat(lastCoordinatesCopy); } else { updatedCoordinates = updatedCoordinates.map(function (coord) { switch (key) { case 'ArrowUp': return _objectSpread(_objectSpread({}, coord), {}, { y: Math.max(0, coord.y - increment) }); case 'ArrowDown': return _objectSpread(_objectSpread({}, coord), {}, { y: Math.min(_this2.state.imageHeight, coord.y + increment) }); case 'ArrowLeft': return _objectSpread(_objectSpread({}, coord), {}, { x: Math.max(0, coord.x - increment) }); case 'ArrowRight': return _objectSpread(_objectSpread({}, coord), {}, { x: Math.min(_this2.state.imageWidth, coord.x + increment) }); default: return coord; } }); } var lines = _toConsumableArray(updatedCoordinates); if (lines.length > 2) { lines.push(lines[0]); } _this2.canvas.drawShape(lines); _this2.props.convertCoordinates(updatedCoordinates, true, true); }); _defineProperty(_this2, "calculateCoordinates", function (shapeType, imageWidth, imageHeight) { var x1 = (imageWidth - 50) / 2; var y1 = (imageHeight - 50) / 2; var coordinates; switch (shapeType) { case 'square': coordinates = [{ x: x1, y: y1 }, { x: x1 + 50, y: y1 + 50 }]; break; case 'oval': coordinates = [{ x: imageWidth / 2 - 50, y: imageHeight / 2 - 50 }, { x: imageWidth / 2 + 50, y: imageHeight / 2 + 50 }]; break; case 'polygon': coordinates = [{ x: x1, y: y1 }, { x: x1 + 50, y: y1 }]; break; default: coordinates = []; } return coordinates; }); _defineProperty(_this2, "addSquareHotspot", function () { _this2.props.onSetType('square'); var initialCoordinate = _this2.calculateCoordinates('square', _this2.state.imageWidth, _this2.state.imageHeight); _this2.props.convertCoordinates(initialCoordinate, _this2.props.tempHotspot ? true : false); }); _defineProperty(_this2, "addOvalHotspot", function () { _this2.props.onSetType('oval'); var initialCoordinate = _this2.calculateCoordinates('oval', _this2.state.imageWidth, _this2.state.imageHeight); _this2.props.convertCoordinates(initialCoordinate, _this2.props.tempHotspot ? true : false); }); _defineProperty(_this2, "drawPolygonHotspot", function () { var _this2$canvas, _this2$canvas2; if ((_this2$canvas = _this2.canvas) !== null && _this2$canvas !== void 0 && _this2$canvas.isDrawing()) { return; } _this2.props.onSetType('polygon'); var initialCoordinate = _this2.calculateCoordinates('polygon', _this2.state.imageWidth, _this2.state.imageHeight); var currentHotspot = _this2.getCurrentHotspot(); var lines = currentHotspot.coordinates.concat(initialCoordinate); // add initial coordinate at the end of the array to close the polygon if (lines.length > 2) { lines = lines.concat([lines[0]]); } _this2.props.setCanvasRef(_this2.canvas); _this2.props.convertCoordinates(initialCoordinate, _this2.props.tempHotspot ? true : false); _this2.canvas = _this2.canvas || _this2.props.canvasRef; (_this2$canvas2 = _this2.canvas) === null || _this2$canvas2 === void 0 || _this2$canvas2.setState({ isDrawing: true }); }); _defineProperty(_this2, "addPolygonPoint", function () { var _this2$props = _this2.props, currentType = _this2$props.currentType, convertCoordinates = _this2$props.convertCoordinates; var _this2$state = _this2.state, currentPolygonCoordinates = _this2$state.currentPolygonCoordinates, imageWidth = _this2$state.imageWidth, imageHeight = _this2$state.imageHeight; var currentHotspot = _this2.getCurrentHotspot(); if (currentType !== 'polygon' || !_this2.canvas.isDrawing() || !currentHotspot.coordinates || !currentPolygonCoordinates && currentHotspot.coordinates.length !== 2) { _this2.setState({ currentPolygonCoordinates: null }); return; } var transformedCoordinates = _this2.transformCoordinates(currentHotspot.coordinates, imageWidth, imageHeight); var updatedCoordinates; if (currentHotspot.coordinates.length === 2) { var lastCoordinate = _this2.transformCoordinates([currentHotspot.coordinates[1]], imageWidth, imageHeight); updatedCoordinates = transformedCoordinates.concat(lastCoordinate); } else { updatedCoordinates = transformedCoordinates.concat(currentPolygonCoordinates); } convertCoordinates(updatedCoordinates, true, true); _this2.setState({ currentPolygonCoordinates: null }); }); _defineProperty(_this2, "OpenShortcutsModal", function () { if (_this2.isBankOrOutcomesModalOpen()) { return; } _this2.props.onOpenShortcutsModal(); }); _defineProperty(_this2, "handleCloseShape", function () { var _this2$canvas3; var currentType = _this2.props.currentType; var _this2$state2 = _this2.state, imageWidth = _this2$state2.imageWidth, imageHeight = _this2$state2.imageHeight; var currentHotspot = _this2.getCurrentHotspot(); if (currentType !== 'polygon' && !_this2.canvas.isDrawing()) { return; } var transformedCoordinates = _this2.transformCoordinates(currentHotspot.coordinates, imageWidth, imageHeight); var finalCoordinates = transformedCoordinates.concat(transformedCoordinates[0]); (_this2$canvas3 = _this2.canvas) === null || _this2$canvas3 === void 0 || _this2$canvas3.stopDrawing(finalCoordinates); }); _defineProperty(_this2, "handleKeyPress", function (event) { var key = event.key, shiftKey = event.shiftKey, altKey = event.altKey; var normalizedKey = _this2.isLetterKey(key) ? key.toLowerCase() : key; var activeElement = document.activeElement; var isInputElement = activeElement.tagName === 'INPUT'; var isTextAreaElement = activeElement.tagName === 'TEXTAREA'; var hasHotspots = _this2.props.hotspots.length > 0; var isImageUploaded = _this2.isImageUploaded(); var controlKeyAction = { b: function b() { return _this2.triggerFileUpload(); }, i: function i() { return _this2.props.onOpenShortcutsModal(); } }; if (isInputElement || isTextAreaElement) { return; } if (!isImageUploaded) { var _handleHotkey = controlKeyAction[normalizedKey]; if (_handleHotkey) { event.preventDefault(); _handleHotkey(); return; } } var imageKeyActions = { Delete: function Delete() { return _this2.deleteSelectedHotspot(); }, Backspace: function Backspace() { return _this2.deleteSelectedHotspot(); }, ArrowUp: function ArrowUp() { return _this2.moveOrResizeHotspot(normalizedKey, shiftKey, altKey); }, ArrowDown: function ArrowDown() { return _this2.moveOrResizeHotspot(normalizedKey, shiftKey, altKey); }, ArrowLeft: function ArrowLeft() { return _this2.moveOrResizeHotspot(normalizedKey, shiftKey, altKey); }, ArrowRight: function ArrowRight() { return _this2.moveOrResizeHotspot(normalizedKey, shiftKey, altKey); }, i: function i() { return _this2.OpenShortcutsModal(); }, f: function f() { return _this2.handleExpandImage(); }, r: function r() { return _this2.addSquareHotspot(); }, o: function o() { return _this2.addOvalHotspot(); }, p: function p() { return _this2.drawPolygonHotspot(); }, d: function d() { return _this2.props.onRemoveImage(); }, e: function e() { return _this2.handleCloseShape(); }, Enter: function Enter() { return _this2.addPolygonPoint(); }, Escape: function Escape() { return _this2.handleCloseModal(); } }; if (_this2.isArrowKey(normalizedKey) && hasHotspots) { event.preventDefault(); } var handleHotkey = imageKeyActions[normalizedKey]; if (handleHotkey) { event.preventDefault(); handleHotkey(); } }); _defineProperty(_this2, "deleteSelectedHotspot", function () { _this2.props.onRemoveHotspot(_this2.props.currentHotspotId); }); _defineProperty(_this2, "triggerFileUpload", function () { _this2.fileDrop.fileInputEl.click(); }); _defineProperty(_this2, "moveOrResizeHotspot", function (key, shiftKey, altKey) { var currentHotspot = _this2.getCurrentHotspot(); if (currentHotspot.coordinates.length === 0) return; if (_this2.props.currentType === 'polygon') { _this2.moveOrResizePolygon(key, shiftKey, altKey); } else { var coordinates = _this2.transformCoordinates(currentHotspot.coordinates, _this2.state.imageWidth, _this2.state.imageHeight); var increment = 10; // Move or resize by 10px var updatedCoordinates = _this2.updateCoordinates(coordinates, key, increment, _this2.state.imageWidth, _this2.state.imageHeight, shiftKey, altKey); _this2.props.convertCoordinates(updatedCoordinates, true, true); } }); _defineProperty(_this2, "convertCoordinatesForRendering", function (coordinates) { return coordinates.map(function (item) { var x = item.x * _this2.state.imageWidth; var y = item.y * _this2.state.imageHeight; return { x: x, y: y }; }); }); // =========== // RENDER // =========== _defineProperty(_this2, "renderCanvas", function () { var _this2$props2 = _this2.props, hotspots = _this2$props2.hotspots, tempHotspot = _this2$props2.tempHotspot, isUploading = _this2$props2.isUploading; if (!hotspots.length && !tempHotspot || isUploading) { return null; } // Create an array that includes all hotspots and tempHotspot if it exists var hotspotsToRender = tempHotspot ? [].concat(_toConsumableArray(hotspots), [tempHotspot]) : hotspots; return hotspotsToRender.map(function (hotspot, index) { var SelectedType = _this2.getSelectedTypeComponent(hotspot.type); var coordinates = _this2.convertCoordinatesForRendering(hotspot.coordinates || []); return jsx(SelectedType, { key: hotspot.id || index, ref: _this2.handleCanvasRef, handleSetCoordinates: _this2.props.convertCoordinates, coordinates: coordinates, width: _this2.state.imageWidth, height: _this2.state.imageHeight, hotspotId: hotspot.id }); }); }); return _this2; } _inherits(DrawingContainer, _Component); return _createClass(DrawingContainer, [{ key: "componentDidMount", value: function componentDidMount() { window.addEventListener('resize', this.updateSize); window.addEventListener('keydown', this.handleKeyPress); this.updateSize(); this.props.makeStyles({ isModal: this.state.isModalOpen }); } }, { key: "componentDidUpdate", value: function componentDidUpdate(lastProps, lastState) { if (lastProps.url && this.props.url === void 0) { this.fileDrop.fileInputEl.focus(); } if (lastState.imageWidth !== this.state.imageWidth || lastState.imageHeight !== this.state.imageHeight) { this.updateSize(); } this.props.makeStyles({ isModal: this.state.isModalOpen }); } }, { key: "componentWillUnmount", value: function componentWillUnmount() { window.removeEventListener('resize', this.updateSize); window.removeEventListener('keydown', this.handleKeyPress); this.updateSize.cancel(); } }, { key: "getSelectedTypeComponent", value: function getSelectedTypeComponent(currentType) { var type = this.props.drawTypes.find(function (item) { return item.type === currentType; }); return type === null || type === void 0 ? void 0 : type.component; } }, { key: "renderTypes", value: function renderTypes() { var _this3 = this; return jsx("div", { className: "mainContainerType", css: this.props.styles.mainContainerType }, this.props.drawTypes.map(function (item) { var TypeIcon = item.icon; var onButtonClick = function onButtonClick() { return _this3.handleSelectDrawOption(item.type); }; var color = 'secondary'; var wrapperStyle = _this3.props.styles.mainContainerTypeUnselected; if (item.type === (_this3.props.currentType || 'square')) { onButtonClick = null; color = 'primary-inverse'; wrapperStyle = _this3.props.styles.mainContainerTypeSelected; } return jsx(Popover, { key: item.type, color: "primary-inverse", onClick: onButtonClick, renderTrigger: jsx("div", { css: wrapperStyle }, jsx(IconButton, { color: color, withBackground: false, withBorder: false, screenReaderLabel: item.title, renderIcon: jsx(TypeIcon, { title: item.title }) })) }, jsx("div", { css: _this3.props.styles.popoverContent }, item.title)); })); } }, { key: "renderActionButton", value: function renderActionButton(onClick, label, Icon) { var automationData = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ''; return jsx(Popover, { onClick: onClick, color: "primary-inverse", renderTrigger: jsx(IconButton, Object.assign({ renderIcon: Icon, withBackground: false, withBorder: false, screenReaderLabel: label }, automationData && { 'data-automation': automationData })) }, jsx("div", { css: this.props.styles.popoverContent }, label)); } }, { key: "renderActions", value: function renderActions() { return jsx("div", { css: this.props.styles.mainContainerActions }, this.renderActionButton(this.handleExpandImage, t('Expand Image'), IconExpandItemsLine), jsx("div", { css: this.props.styles.mainContainerActionsRemove }, this.renderActionButton(this.props.onRemoveImage, t('Remove Image'), IconTrashLine, 'sdk-remove-image-button'))); } }, { key: "renderHeaderText", value: function renderHeaderText(isModal) { var _this$props = this.props, styles = _this$props.styles, currentType = _this$props.currentType, hotspots = _this$props.hotspots; if (currentType === 'polygon' && hotspots.length > 0) { return jsx("div", { css: styles.headerText }, t.rich('<0>Double click to</0> <1>close shape</1>', [function (_ref2) { var children = _ref2.children; return jsx(Text, { key: "1" }, children); }, function (_ref3) { var children = _ref3.children; return jsx(CondensedButton, { key: "2", size: "large", margin: "0 0 0 x-small", themeOverride: { largePadding: styles.headerText.condensedButton.padding, largeFontSize: styles.headerText.condensedButton.fontSize, largeHeight: styles.headerText.condensedButton.height } }, children); }])); } return jsx(Text, { color: "primary" }, t("Draw the hot spot's shape")); } }, { key: "renderImage", value: function renderImage() { return jsx("div", { css: this.props.styles.imageHolder }, jsx("img", { alt: t('Uploaded Image'), css: this.props.styles.mainContainerContentImage, onLoad: this.handleImageLoad, ref: this.handleImageRef, src: this.props.url }), !this.props.isUploading ? null : jsx("div", { css: this.props.styles.spinnerWrapper }, jsx("div", { css: this.props.styles.spinner }, jsx(Spinner, { renderTitle: t('Loading'), size: "large", variant: "inverse" }))), this.renderCanvas()); } }, { key: "renderDrawingContainer", value: function renderDrawingContainer() { return jsx("div", { css: this.props.styles.mainContainer, ref: this.drawingContainerRef }, this.props.isUploading ? null : jsx("div", { css: this.props.styles.mainContainerHeader }, jsx(FormFieldGroup, { description: jsx(ScreenReaderContent, null, t('Hot Spot editor')), messages: this.props.typeErrors }, jsx("div", { css: this.props.styles.mainContainerHeader }, jsx("div", null, this.renderHeaderText()), this.renderTypes())), this.renderActions()), jsx("div", { css: this.props.styles.mainContainerContentWrapper }, this.renderImage())); } }, { key: "renderFileDropContent", value: function renderFileDropContent() { var _this4 = this; return jsx("div", { css: this.props.styles.fileDropContent }, jsx("div", { css: this.props.styles.fileDropContentIcon }, jsx(IconUploadLine, null)), jsx("div", { css: this.props.styles.fileDropContentLabel }, t.rich("Drag n' Drop here or <0>Browse</0>", [function (_ref4) { var children = _ref4.children; return jsx("div", { key: "1", css: _this4.props.styles.fileDropContentLabelBrowse }, children); }]))); } }, { key: "renderFileDrop", value: function renderFileDrop() { return jsx("div", { css: this.props.styles.fileDropWrapper }, jsx(FileDrop, { accept: "image/*", renderLabel: this.renderFileDropContent(), onDropAccepted: this.props.onDropAccepted, ref: this.handleFileDropRef, messages: this.props.fileDropErrors })); } }, { key: "renderModal", value: function renderModal() { return jsx(SimpleModal, { footerContent: jsx(Button, { onClick: this.handleCloseModal, color: "primary" }, t('Done')), isModalOpen: this.state.isModalOpen, onModalDismiss: this.handleCloseModal, size: "fullscreen", title: this.renderHeaderText(true), label: t('Modal Dialog: Draw a hot spot') }, jsx("div", { css: this.props.styles.modalContent, ref: this.modalDrawingContainerRef }, jsx("div", { css: this.props.styles.modalContentTypes }, this.renderTypes()), jsx("div", { css: this.props.styles.modalContentImage }, this.renderImage()))); } }, { key: "render", value: function render() { if (!this.props.url) { return jsx("div", null, this.renderFileDrop()); } else if (this.state.isModalOpen === true) { return jsx("div", null, this.renderModal()); } else { return jsx(FormFieldGroup, { required: true, messages: this.props.canvasErrors, description: t('Hot Spot') }, this.renderDrawingContainer()); } } }]); }(Component), _defineProperty(_DrawingContainer, "displayName", 'DrawingContainer'), _defineProperty(_DrawingContainer, "componentId", "Quizzes".concat(_DrawingContainer.displayName)), _defineProperty(_DrawingContainer, "propTypes", { canvasErrors: PropTypes.array, convertCoordinates: PropTypes.func, currentType: PropTypes.string, drawTypes: PropTypes.array, fileDropErrors: PropTypes.array, isUploading: PropTypes.bool, onModalOpen: PropTypes.func, onModalClose: PropTypes.func, onDropAccepted: PropTypes.func, onSetType: PropTypes.func, onRemoveImage: PropTypes.func, onRemoveHotspot: PropTypes.func, typeErrors: PropTypes.array, url: PropTypes.string, makeStyles: PropTypes.func, styles: PropTypes.object, onOpenShortcutsModal: PropTypes.func, onCloseShortcutsModal: PropTypes.func, isShortcutsModalOpen: PropTypes.bool, hotspots: PropTypes.array, tempHotspot: PropTypes.object, currentHotspotId: PropTypes.number, setTempHotspot: PropTypes.func, setCanvasRef: PropTypes.func, canvasRef: PropTypes.object, multipleHotSpotEnabled: PropTypes.bool }), _defineProperty(_DrawingContainer, "defaultProps", { onModalOpen: Function.prototype, onModalClose: Function.prototype, canvasErrors: void 0, convertCoordinates: void 0, currentType: void 0, drawTypes: void 0, fileDropErrors: void 0, isUploading: void 0, onDropAccepted: void 0, onSetType: void 0, onRemoveImage: void 0, typeErrors: void 0, url: void 0, hotspots: void 0, tempHotspot: void 0, multipleHotSpotEnabled: false }), _DrawingContainer)) || _class); export { DrawingContainer as default };