UNPKG

@findify/mjs

Version:
134 lines (107 loc) 4.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = undefined; var _unescape2 = require("lodash/unescape"); var _unescape3 = _interopRequireDefault(_unescape2); var _immutable = require("immutable"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(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 _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } 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, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var defaultPosition = { left: 0, top: 0, width: 0, height: 0 }; var Position = /*#__PURE__*/ function (_Record) { _inherits(Position, _Record); function Position() { var ClientRect = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultPosition; _classCallCheck(this, Position); return _possibleConstructorReturn(this, (Position.__proto__ || Object.getPrototypeOf(Position)).call(this, ClientRect)); } _createClass(Position, [{ key: "setValues", value: function setValues(ClientRect) { return this.set('top', ClientRect.top + (window.scrollY || document.documentElement.scrollTop)).set('left', ClientRect.left + (window.scrollX || document.documentElement.scrollLeft)).set('height', ClientRect.height).set('width', ClientRect.width); } }]); return Position; }((0, _immutable.Record)(defaultPosition)); var NodeState = /*#__PURE__*/ function (_Record2) { _inherits(NodeState, _Record2); function NodeState(_ref) { var _this; var node = _ref.node, initialHTML = _ref.initialHTML; _classCallCheck(this, NodeState); _this = _possibleConstructorReturn(this, (NodeState.__proto__ || Object.getPrototypeOf(NodeState)).call(this, { _node: node, _html: initialHTML, position: new Position(node && node.getBoundingClientRect()), value: node && node.value })); return _possibleConstructorReturn(_this, _assertThisInitialized(_this)); } _createClass(NodeState, [{ key: "computePosition", value: function computePosition() { if (!this.instance) return this; var rect = this.instance.getBoundingClientRect(); var position = this.get('position'); var newPosition = position.setValues(rect); if (position.equals(newPosition)) return false; return this.set('position', newPosition); } }, { key: "instance", get: function get() { return this.get('_node'); } }, { key: "html", get: function get() { return this.get('_html'); } }, { key: "hasFocus", get: function get() { return this.get('hasFocus'); } }, { key: "value", get: function get() { return this.get('value'); } }, { key: "fallback", get: function get() { if (this.get('_fallback')) return this.get('_fallback'); var html = document.getElementById('findify_fallback'); if (!html) return null; var fallback = (0, _unescape3.default)(html.innerHTML); this.set('_fallback', fallback); return fallback; } }]); return NodeState; }((0, _immutable.Record)({ _node: void 0, _html: '', _fallback: void 0, position: Position, hasFocus: false, value: '' })); exports.default = NodeState;