UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

79 lines (78 loc) 3.09 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 _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/esm/inherits"; 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, { Component } from 'react'; import PropTypes from 'prop-types'; import { DropTarget } from 'react-dnd'; import { processNewMathInElem } from '@instructure/quiz-rce'; export var DropTargetContainer = /*#__PURE__*/function (_Component) { function DropTargetContainer() { var _this2; _classCallCheck(this, DropTargetContainer); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this2 = _callSuper(this, DropTargetContainer, [].concat(args)); _defineProperty(_this2, "containerRef", null); _defineProperty(_this2, "handleContainerRef", function (node) { _this2.containerRef = node; }); _defineProperty(_this2, "componentDidUpdate", function (prevProps) { processNewMathInElem(_this2.containerRef); }); return _this2; } _inherits(DropTargetContainer, _Component); return _createClass(DropTargetContainer, [{ key: "render", value: function render() { return this.props.connectDropTarget(/*#__PURE__*/React.createElement("div", { className: this.props.className, ref: this.handleContainerRef }, this.props.children)); } }]); }(Component); // ============= // DRAG AND DROP // ============= _defineProperty(DropTargetContainer, "propTypes", { children: PropTypes.oneOfType([PropTypes.array, PropTypes.object]).isRequired, className: PropTypes.string, connectDropTarget: PropTypes.func.isRequired, // injected by React DnD onDrop: PropTypes.func.isRequired }); _defineProperty(DropTargetContainer, "defaultProps", { className: void 0 }); export var dropTarget = { drop: function drop(props, monitor, component) { var droppedItem = monitor.getItem(); props.onDrop(droppedItem); } }; function collectDrop(connect, monitor) { return { connectDropTarget: connect.dropTarget() }; } var DropTargetWrapper = DropTarget('dnd', dropTarget, collectDrop)(DropTargetContainer); export default DropTargetWrapper;