1 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
2 | var _excluded = ["cssModule", "children", "isOpen", "flip", "target", "offset", "fallbackPlacements", "placementPrefix", "arrowClassName", "hideArrow", "popperClassName", "tag", "container", "modifiers", "strategy", "boundariesElement", "onClosed", "fade", "transition", "placement"];
|
3 | function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
4 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
5 | function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
6 | function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
7 | function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
8 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
9 | function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
10 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
11 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
12 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
13 | 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); } }
|
14 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
15 | 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, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
16 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
17 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
18 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
19 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
20 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
21 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
22 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
23 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
24 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
25 | import React from 'react';
|
26 | import PropTypes from 'prop-types';
|
27 | import ReactDOM from 'react-dom';
|
28 | import classNames from 'classnames';
|
29 | import { Popper as ReactPopper } from 'react-popper';
|
30 | import { getTarget, targetPropType, mapToCssModules, DOMElement, tagPropType } from './utils';
|
31 | import Fade from './Fade';
|
32 | function noop() {}
|
33 | var propTypes = {
|
34 | children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
|
35 | popperClassName: PropTypes.string,
|
36 | placement: PropTypes.string,
|
37 | placementPrefix: PropTypes.string,
|
38 | arrowClassName: PropTypes.string,
|
39 | hideArrow: PropTypes.bool,
|
40 | tag: tagPropType,
|
41 | isOpen: PropTypes.bool,
|
42 | cssModule: PropTypes.object,
|
43 | offset: PropTypes.arrayOf(PropTypes.number),
|
44 | fallbackPlacements: PropTypes.array,
|
45 | flip: PropTypes.bool,
|
46 | container: targetPropType,
|
47 | target: targetPropType.isRequired,
|
48 | modifiers: PropTypes.array,
|
49 | strategy: PropTypes.string,
|
50 | boundariesElement: PropTypes.oneOfType([PropTypes.string, DOMElement]),
|
51 | onClosed: PropTypes.func,
|
52 | fade: PropTypes.bool,
|
53 | transition: PropTypes.shape(Fade.propTypes)
|
54 | };
|
55 | var defaultProps = {
|
56 | boundariesElement: 'scrollParent',
|
57 | placement: 'auto',
|
58 | hideArrow: false,
|
59 | isOpen: false,
|
60 | offset: [0, 0],
|
61 | flip: true,
|
62 | container: 'body',
|
63 | modifiers: [],
|
64 | onClosed: noop,
|
65 | fade: true,
|
66 | transition: _objectSpread({}, Fade.defaultProps)
|
67 | };
|
68 | var PopperContent = function (_React$Component) {
|
69 | _inherits(PopperContent, _React$Component);
|
70 | var _super = _createSuper(PopperContent);
|
71 | function PopperContent(props) {
|
72 | var _this;
|
73 | _classCallCheck(this, PopperContent);
|
74 | _this = _super.call(this, props);
|
75 | _this.setTargetNode = _this.setTargetNode.bind(_assertThisInitialized(_this));
|
76 | _this.getTargetNode = _this.getTargetNode.bind(_assertThisInitialized(_this));
|
77 | _this.getRef = _this.getRef.bind(_assertThisInitialized(_this));
|
78 | _this.onClosed = _this.onClosed.bind(_assertThisInitialized(_this));
|
79 | _this.state = {
|
80 | isOpen: props.isOpen
|
81 | };
|
82 | return _this;
|
83 | }
|
84 | _createClass(PopperContent, [{
|
85 | key: "componentDidUpdate",
|
86 | value: function componentDidUpdate() {
|
87 | if (this._element && this._element.childNodes && this._element.childNodes[0] && this._element.childNodes[0].focus) {
|
88 | this._element.childNodes[0].focus();
|
89 | }
|
90 | }
|
91 | }, {
|
92 | key: "onClosed",
|
93 | value: function onClosed() {
|
94 | this.props.onClosed();
|
95 | this.setState({
|
96 | isOpen: false
|
97 | });
|
98 | }
|
99 | }, {
|
100 | key: "getTargetNode",
|
101 | value: function getTargetNode() {
|
102 | return this.targetNode;
|
103 | }
|
104 | }, {
|
105 | key: "getContainerNode",
|
106 | value: function getContainerNode() {
|
107 | return getTarget(this.props.container);
|
108 | }
|
109 | }, {
|
110 | key: "getRef",
|
111 | value: function getRef(ref) {
|
112 | this._element = ref;
|
113 | }
|
114 | }, {
|
115 | key: "setTargetNode",
|
116 | value: function setTargetNode(node) {
|
117 | this.targetNode = typeof node === 'string' ? getTarget(node) : node;
|
118 | }
|
119 | }, {
|
120 | key: "renderChildren",
|
121 | value: function renderChildren() {
|
122 | var _this$props = this.props,
|
123 | cssModule = _this$props.cssModule,
|
124 | children = _this$props.children,
|
125 | isOpen = _this$props.isOpen,
|
126 | flip = _this$props.flip,
|
127 | target = _this$props.target,
|
128 | offset = _this$props.offset,
|
129 | fallbackPlacements = _this$props.fallbackPlacements,
|
130 | placementPrefix = _this$props.placementPrefix,
|
131 | _arrowClassName = _this$props.arrowClassName,
|
132 | hideArrow = _this$props.hideArrow,
|
133 | _popperClassName = _this$props.popperClassName,
|
134 | tag = _this$props.tag,
|
135 | container = _this$props.container,
|
136 | modifiers = _this$props.modifiers,
|
137 | strategy = _this$props.strategy,
|
138 | boundariesElement = _this$props.boundariesElement,
|
139 | onClosed = _this$props.onClosed,
|
140 | fade = _this$props.fade,
|
141 | transition = _this$props.transition,
|
142 | placement = _this$props.placement,
|
143 | attrs = _objectWithoutProperties(_this$props, _excluded);
|
144 | var arrowClassName = mapToCssModules(classNames('arrow', _arrowClassName), cssModule);
|
145 | var popperClassName = mapToCssModules(classNames(_popperClassName, placementPrefix ? "".concat(placementPrefix, "-auto") : ''), this.props.cssModule);
|
146 | var modifierNames = modifiers.map(function (m) {
|
147 | return m.name;
|
148 | });
|
149 | var baseModifiers = [{
|
150 | name: 'offset',
|
151 | options: {
|
152 | offset: offset
|
153 | }
|
154 | }, {
|
155 | name: 'flip',
|
156 | enabled: flip,
|
157 | options: {
|
158 | fallbackPlacements: fallbackPlacements
|
159 | }
|
160 | }, {
|
161 | name: 'preventOverflow',
|
162 | options: {
|
163 | boundary: boundariesElement
|
164 | }
|
165 | }].filter(function (m) {
|
166 | return !modifierNames.includes(m.name);
|
167 | });
|
168 | var extendedModifiers = [].concat(_toConsumableArray(baseModifiers), _toConsumableArray(modifiers));
|
169 | var popperTransition = _objectSpread(_objectSpread(_objectSpread({}, Fade.defaultProps), transition), {}, {
|
170 | baseClass: fade ? transition.baseClass : '',
|
171 | timeout: fade ? transition.timeout : 0
|
172 | });
|
173 | return React.createElement(Fade, _extends({}, popperTransition, attrs, {
|
174 | "in": isOpen,
|
175 | onExited: this.onClosed,
|
176 | tag: tag
|
177 | }), React.createElement(ReactPopper, {
|
178 | referenceElement: this.targetNode,
|
179 | modifiers: extendedModifiers,
|
180 | placement: placement,
|
181 | strategy: strategy
|
182 | }, function (_ref) {
|
183 | var ref = _ref.ref,
|
184 | style = _ref.style,
|
185 | popperPlacement = _ref.placement,
|
186 | isReferenceHidden = _ref.isReferenceHidden,
|
187 | arrowProps = _ref.arrowProps,
|
188 | update = _ref.update;
|
189 | return React.createElement("div", {
|
190 | ref: ref,
|
191 | style: style,
|
192 | className: popperClassName,
|
193 | "data-popper-placement": popperPlacement,
|
194 | "data-popper-reference-hidden": isReferenceHidden ? 'true' : undefined
|
195 | }, typeof children === 'function' ? children({
|
196 | update: update
|
197 | }) : children, !hideArrow && React.createElement("span", {
|
198 | ref: arrowProps.ref,
|
199 | className: arrowClassName,
|
200 | style: arrowProps.style
|
201 | }));
|
202 | }));
|
203 | }
|
204 | }, {
|
205 | key: "render",
|
206 | value: function render() {
|
207 | this.setTargetNode(this.props.target);
|
208 | if (this.state.isOpen) {
|
209 | return this.props.container === 'inline' ? this.renderChildren() : ReactDOM.createPortal( React.createElement("div", {
|
210 | ref: this.getRef
|
211 | }, this.renderChildren()), this.getContainerNode());
|
212 | }
|
213 | return null;
|
214 | }
|
215 | }], [{
|
216 | key: "getDerivedStateFromProps",
|
217 | value: function getDerivedStateFromProps(props, state) {
|
218 | if (props.isOpen && !state.isOpen) {
|
219 | return {
|
220 | isOpen: props.isOpen
|
221 | };
|
222 | }
|
223 | return null;
|
224 | }
|
225 | }]);
|
226 | return PopperContent;
|
227 | }(React.Component);
|
228 | PopperContent.propTypes = propTypes;
|
229 | PopperContent.defaultProps = defaultProps;
|
230 | export default PopperContent; |
\ | No newline at end of file |