Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

1 рядок
10 KiB

  1. {"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _inheritsLoose from \"@babel/runtime/helpers/esm/inheritsLoose\";\nimport _assertThisInitialized from \"@babel/runtime/helpers/esm/assertThisInitialized\";\nimport React from 'react';\nimport PropTypes from 'prop-types';\nimport PopperContent from './PopperContent';\nimport { getTarget, targetPropType, omit, PopperPlacements, mapToCssModules, DOMElement } from './utils';\nexport var propTypes = {\n placement: PropTypes.oneOf(PopperPlacements),\n target: targetPropType.isRequired,\n container: targetPropType,\n isOpen: PropTypes.bool,\n disabled: PropTypes.bool,\n hideArrow: PropTypes.bool,\n boundariesElement: PropTypes.oneOfType([PropTypes.string, DOMElement]),\n className: PropTypes.string,\n innerClassName: PropTypes.string,\n arrowClassName: PropTypes.string,\n cssModule: PropTypes.object,\n toggle: PropTypes.func,\n autohide: PropTypes.bool,\n placementPrefix: PropTypes.string,\n delay: PropTypes.oneOfType([PropTypes.shape({\n show: PropTypes.number,\n hide: PropTypes.number\n }), PropTypes.number]),\n modifiers: PropTypes.object,\n offset: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.string, PropTypes.object]),\n trigger: PropTypes.string\n};\nvar DEFAULT_DELAYS = {\n show: 0,\n hide: 250\n};\nvar defaultProps = {\n isOpen: false,\n hideArrow: false,\n autohide: false,\n delay: DEFAULT_DELAYS,\n toggle: function toggle() {},\n trigger: 'click'\n};\n\nfunction isInDOMSubtree(element, subtreeRoot) {\n return subtreeRoot && (element === subtreeRoot || subtreeRoot.contains(element));\n}\n\nvar TooltipPopoverWrapper = /*#__PURE__*/function (_React$Component) {\n _inheritsLoose(TooltipPopoverWrapper, _React$Component);\n\n function TooltipPopoverWrapper(props) {\n var _this;\n\n _this = _React$Component.call(this, props) || this;\n _this._target = null;\n _this.addTargetEvents = _this.addTargetEvents.bind(_assertThisInitialized(_assertThisInitialized(_this)));\n _this.handleDocumentClick = _this.handleDocumentClick.bind(_assertThisInitialized(_assertThisInitialized(_this)));\n _this.removeTargetEvents = _this.removeTargetEvents.bind(_assertThisInitialized(_assertThisInitialized(_this)));\n _this.toggle = _this.toggle.bind(_assertThisInitialized(_assertThisInitialized(_this)));\n _this.showWithDelay = _this.showWithDelay.bind(_assertThisInitialized(_assertThisInitialized(_this)));\n _this.hideWithDelay = _this.hideWithDelay.bind(_assertThisInitialized(_assertThisInitialized(_this)));\n _this.onMouseOverTooltipContent = _this.onMouseOverTooltipContent.bind(_assertThisInitialized(_assertThisInitialized(_this)));\n _this.onMouseLeaveTooltipContent = _this.onMouseLeaveTooltipContent.bind(_assertThisInitialized(_assertThisInitialized(_this)));\n _this.show = _this.show.bind(_assertThisInitialized(_assertThisInitialized(_this)));\n _this.hide = _this.hide.bind(_assertThisInitialized(_assertThisInitialized(_this)));\n _this.onEscKeyDown = _this.onEscKeyDown.bind(_assertThisInitialized(_assertThisInitialized(_this)));\n _this.getRef = _this.getRef.bind(_assertThisInitialized(_assertThisInitialized(_this)));\n return _this;\n }\n\n var _proto = TooltipPopoverWrapper.prototype;\n\n _proto.componentDidMount = function componentDidMount() {\n this.updateTarget();\n };\n\n _proto.componentWillUnmount = function componentWillUnmount() {\n this.removeTargetEvents();\n };\n\n _proto.onMouseOverTooltipContent = function onMouseOverTooltipContent() {\n if (this.props.trigger.indexOf('hover') > -1 && !this.props.autohide) {\n if (this._hideTimeout) {\n this.clearHideTimeout();\n }\n }\n };\n\n _proto.onMouseLeaveTooltipContent = function onMouseLeaveTooltipContent(e) {\n if (this.props.trigger.indexOf('hover') > -1 && !this.props.autohide) {\n if (this._showTimeout) {\n this.clearShowTimeout();\n }\n\n e.persist();\n this._hideTimeout = setTimeout(this.hide.bind(this, e), this.getDelay('hide'));\n }\n };\n\n _proto.onEscKeyDown = function onEscKeyDown(e) {\n if (e.key === 'Escape') {\n this.hide(e);\n }\n };\n\n _proto.getRef = function getRef(ref) {\n var innerRef = this.props.innerRef;\n\n if (innerRef) {\n if (typeof innerRef === 'function') {\n innerRef(ref);\n } else if (typeof innerRef === 'object') {\n innerRef.current = ref;\n }\n }\n\n this._popover = ref;\n };\n\n _proto.getDelay = function getDelay(key) {\n var delay = this.props.delay;\n\n if (typeof delay === 'object') {\n return isNaN(delay[key]) ? DEFAULT_DELAYS[key] : delay[key];\n }\n\n return delay;\n };\n\n _proto.show = function show(e) {\n if (!this.props.isOpen) {\n this.clearShowTimeout();\n this.toggle(e);\n }\n };\n\n _proto.showWithDelay = function showWithDelay(e) {\n if (this._hideTimeout) {\n this.clearHideTimeout();\n }\n\n this._showTimeout = setTimeout(this.show.bind(this, e), this.getDelay('show'));\n };\n\n _proto.hide = function hide(e) {\n if (this.props.isOpen) {\n this.clearHideTimeout();\n this.toggle(e);\n }\n };\n\n _proto.hideWithDelay = function hideWithDelay(e) {\n if (this._showTimeout) {\n this.clearShowTimeout();\n }\n\n this._hideTimeout = setTimeout(this.hide.bind(this, e), this.getDelay('hide'));\n };\n\n _proto.clearShowTimeout = function clearShowTimeout() {\n clearTimeout(this._showTimeout);\n this._showTimeout = undefined;\n };\n\n _proto.clearHideTimeout = function clearHideTimeout() {\n clearTimeout(this._hideTimeout);\n this._hideTimeout = undefined;\n };\n\n _proto.handleDocumentClick = function handleDocumentClick(e) {\n var triggers = this.props.trigger.split(' ');\n\n if (triggers.indexOf('legacy') > -1 && (this.props.isOpen || isInDOMSubtree(e.target, this._target))) {\n if (this._hideTimeout) {\n this.clearHideTimeout();\n }\n\n if (this.props.isOpen && !isInDOMSubtree(e.target, this._popover)) {\n this.hideWithDelay(e);\n } else {\n this.showWithDelay(e);\n }\n } else if (triggers.indexOf('click') > -1 && isInDOMSubtree(e.target, this._target)) {\n if (this._hideTimeout) {\n this.clearHideTimeout();\n }\n\n if (!this.props.isOpen) {\n this.showWithDelay(e);\n } else {\n this.hideWithDelay(e);\n }\n }\n };\n\n _proto.addTargetEvents = function addTargetEvents() {\n var _this2 = this;\n\n if (this.props.trigger) {\n var triggers = this.props.trigger.split(' ');\n\n if (triggers.indexOf('manual') === -1) {\n if (triggers.indexOf('click') > -1 || triggers.indexOf('legacy') > -1) {\n ['click', 'touchstart'].forEach(function (event) {\n return document.addEventListener(event, _this2.handleDocumentClick, true);\n });\n }\n\n if (this._target) {\n if (triggers.indexOf('hover') > -1) {\n this._target.addEventListener('mouseover', this.showWithDelay, true);\n\n this._target.addEventListener('mouseout', this.hideWithDelay, true);\n }\n\n if (triggers.indexOf('focus') > -1) {\n this._target.addEventListener('focusin', this.show, true);\n\n this._target.addEventListener('focusout', this.hide, true);\n }\n\n this._target.addEventListener('keydown', this.onEscKeyDown, true);\n }\n }\n }\n };\n\n _proto.removeTargetEvents = function removeTargetEvents() {\n var _this3 = this;\n\n if (this._target) {\n this._target.removeEventListener('mouseover', this.showWithDelay, true);\n\n this._target.removeEventListener('mouseout', this.hideWithDelay, true);\n\n this._target.removeEventListener('keydown', this.onEscKeyDown, true);\n\n this._target.removeEventListener('focusin', this.show, true);\n\n this._target.removeEventListener('focusout', this.hide, true);\n }\n\n ['click', 'touchstart'].forEach(function (event) {\n return document.removeEventListener(event, _this3.handleDocumentClick, true);\n });\n };\n\n _proto.updateTarget = function updateTarget() {\n var newTarget = getTarget(this.props.target);\n\n if (newTarget !== this._target) {\n this.removeTargetEvents();\n this._target = newTarget;\n this.addTargetEvents();\n }\n };\n\n _proto.toggle = function toggle(e) {\n if (this.props.disabled) {\n return e && e.preventDefault();\n }\n\n return this.props.toggle(e);\n };\n\n _proto.render = function render() {\n if (!this.props.isOpen) {\n return null;\n }\n\n this.updateTarget();\n var _this$props = this.props,\n className = _this$props.className,\n cssModule = _this$props.cssModule,\n innerClassName = _this$props.innerClassName,\n target = _this$props.target,\n isOpen = _this$props.isOpen,\n hideArrow = _this$props.hideArrow,\n boundariesElement = _this$props.boundariesElement,\n placement = _this$props.placement,\n placementPrefix = _this$props.placementPrefix,\n arrowClassName = _this$props.arrowClassName,\n container = _this$props.container,\n modifiers = _this$props.modifiers,\n offset = _this$props.offset;\n var attributes = omit(this.props, Object.keys(propTypes));\n var popperClasses = mapToCssModules(className, cssModule);\n var classes = mapToCssModules(innerClassName, cssModule);\n return React.createElement(PopperContent, {\n className: popperClasses,\n target: target,\n isOpen: isOpen,\n hideArrow: hideArrow,\n boundariesElement: boundariesElement,\n placement: placement,\n placementPrefix: placementPrefix,\n arrowClassName: arrowClassName,\n container: container,\n modifiers: modifiers,\n offset: offset,\n cssModule: cssModule\n }, React.createElement(\"div\", _extends({}, attributes, {\n ref: this.getRef,\n className: classes,\n role: \"tooltip\",\n \"aria-hidden\": isOpen,\n onMouseOver: this.onMouseOverTooltipContent,\n onMouseLeave: this.onMouseLeaveTooltipContent,\n onKeyDown: this.onEscKeyDown\n })));\n };\n\n return TooltipPopoverWrapper;\n}(React.Component);\n\nTooltipPopoverWrapper.propTypes = propTypes;\nTooltipPopoverWrapper.defaultProps = defaultProps;\nexport default TooltipPopoverWrapper;","map":null,"metadata":{},"sourceType":"module"}