UNPKG

@txdfe/at

Version:

一个设计体系组件库

87 lines (86 loc) 3.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _reactDom = require("react-dom"); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var ServiceManager = exports["default"] = /*#__PURE__*/function () { function ServiceManager(queue) { var _this = this; var tag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'span'; _classCallCheck(this, ServiceManager); _defineProperty(this, "handleClose", function (key) { _this.queue["delete"](key); }); this.queue = queue; this.tag = tag; } return _createClass(ServiceManager, [{ key: "close", value: function close(key) { this.handleClose(key); } }, { key: "destroy", value: function destroy() { this.queue.deleteAll(); if (this.el) { (0, _reactDom.unmountComponentAtNode)(this.el); document.body.removeChild(this.el); this.el = null; } } }, { key: "mountNode", get: function get() { if (this.el) { return this.el; } var node = this.createMountNode(this.tag); this.el = node; return node; } }, { key: "createSlice", value: function createSlice(key, duration) { var _this2 = this; var timeoutKey; var startTimeout = function startTimeout() { if (typeof duration === 'number' && duration !== 0) { timeoutKey = window.setTimeout(function () { _this2.handleClose(key); }, duration); } }; var clearTimeout = function clearTimeout() { if (timeoutKey) { window.clearTimeout(timeoutKey); } }; startTimeout(); return { clearTimeout: clearTimeout, startTimeout: startTimeout }; } }, { key: "createMountNode", value: function createMountNode(tag) { var el = document.createElement(tag); document.body.appendChild(el); return el; } }, { key: "flush", value: function flush(component, callback) { (0, _reactDom.render)(component, this.mountNode, callback); } }]); }();