UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

68 lines (67 loc) 3.34 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/inherits"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } import React from 'react'; import ChromeCollapsed from '../ChromeCollapsed'; import { IntlProviderIfMissingWrapper } from '../IntlProviderIfMissingWrapper/IntlProviderIfMissingWrapper'; // Ignored via go/ees005 // eslint-disable-next-line @repo/internal/react/no-class-components var CollapsedEditor = /*#__PURE__*/function (_React$Component) { function CollapsedEditor() { var _this; _classCallCheck(this, CollapsedEditor); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _callSuper(this, CollapsedEditor, [].concat(args)); _defineProperty(_this, "handleEditorRef", function (editorRef, editorRefCallback) { if (editorRefCallback && typeof editorRefCallback === 'function') { editorRefCallback(editorRef); } _this.editorComponent = editorRef; }); return _this; } _inherits(CollapsedEditor, _React$Component); return _createClass(CollapsedEditor, [{ key: "componentDidUpdate", value: function componentDidUpdate() { if (this.props.isExpanded && (this.editorComponent || this.functionalEditor) && (!this.previouslyExpanded || this.previouslyExpanded === undefined)) { var _this$props$onExpand, _this$props; (_this$props$onExpand = (_this$props = this.props).onExpand) === null || _this$props$onExpand === void 0 || _this$props$onExpand.call(_this$props); } this.previouslyExpanded = this.props.isExpanded; } }, { key: "render", value: // eslint-disable-next-line @typescript-eslint/no-explicit-any function render() { var _this2 = this; var child = React.Children.only(this.props.children); this.functionalEditor = typeof child.type === 'function'; if (!this.props.isExpanded) { return /*#__PURE__*/React.createElement(IntlProviderIfMissingWrapper, null, /*#__PURE__*/React.createElement(ChromeCollapsed, { onFocus: this.props.onFocus, text: this.props.placeholder, label: this.props.assistiveLabel })); } // Let's avoid ref logic for functional Editor if (this.functionalEditor) { return child; } return /*#__PURE__*/React.cloneElement(child, { ref: function ref(editorComponent) { return _this2.handleEditorRef(editorComponent, child.ref); } }); } }]); }(React.Component); export { CollapsedEditor as default };