@atlaskit/editor-plugin-placeholder-text
Version:
placeholder text plugin for @atlaskit/editor-core
78 lines • 4.09 kB
JavaScript
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 { injectIntl } from 'react-intl';
import { placeholderTextMessages as messages } from '@atlaskit/editor-common/messages';
import { PanelTextInput } from '@atlaskit/editor-common/ui';
import FloatingToolbar from '../FloatingToolbar';
import { getNearestNonTextNode, getOffsetParent, handlePositionCalculatedWith } from '../FloatingToolbar/utils';
// eslint-disable-next-line @repo/internal/react/no-class-components
var PlaceholderFloatingToolbar = /*#__PURE__*/function (_React$Component) {
function PlaceholderFloatingToolbar() {
var _this;
_classCallCheck(this, PlaceholderFloatingToolbar);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, PlaceholderFloatingToolbar, [].concat(args));
_defineProperty(_this, "handleSubmit", function (value) {
if (value) {
_this.props.insertPlaceholder(value);
_this.props.setFocusInEditor();
} else {
_this.props.hidePlaceholderFloatingToolbar();
}
});
_defineProperty(_this, "handleBlur", function () {
_this.props.hidePlaceholderFloatingToolbar();
});
return _this;
}
_inherits(PlaceholderFloatingToolbar, _React$Component);
return _createClass(PlaceholderFloatingToolbar, [{
key: "render",
value: function render() {
var _this$props = this.props,
getNodeFromPos = _this$props.getNodeFromPos,
showInsertPanelAt = _this$props.showInsertPanelAt,
editorViewDOM = _this$props.editorViewDOM,
popupsMountPoint = _this$props.popupsMountPoint,
getFixedCoordinatesFromPos = _this$props.getFixedCoordinatesFromPos,
popupsBoundariesElement = _this$props.popupsBoundariesElement,
formatMessage = _this$props.intl.formatMessage;
var target = getNodeFromPos(showInsertPanelAt);
var offsetParent = getOffsetParent(editorViewDOM, popupsMountPoint);
var getFixedCoordinates = function getFixedCoordinates() {
return getFixedCoordinatesFromPos(showInsertPanelAt);
};
var handlePositionCalculated = handlePositionCalculatedWith(offsetParent, target, getFixedCoordinates);
return /*#__PURE__*/React.createElement(FloatingToolbar
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
, {
target: getNearestNonTextNode(target),
onPositionCalculated: handlePositionCalculated,
popupsMountPoint: popupsMountPoint,
popupsBoundariesElement: popupsBoundariesElement,
fitHeight: 32
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
,
offset: [0, 12]
}, /*#__PURE__*/React.createElement(PanelTextInput, {
placeholder: formatMessage(messages.placeholderTextPlaceholder),
onSubmit: this.handleSubmit,
onBlur: this.handleBlur,
autoFocus: true,
width: 300
}));
}
}]);
}(React.Component); // eslint-disable-next-line @typescript-eslint/ban-types
var _default_1 = injectIntl(PlaceholderFloatingToolbar);
export default _default_1;