UNPKG

@atlaskit/editor-plugin-placeholder-text

Version:

placeholder text plugin for @atlaskit/editor-core

64 lines (63 loc) 2.48 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; 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 class PlaceholderFloatingToolbar extends React.Component { constructor(...args) { super(...args); _defineProperty(this, "handleSubmit", value => { if (value) { this.props.insertPlaceholder(value); this.props.setFocusInEditor(); } else { this.props.hidePlaceholderFloatingToolbar(); } }); _defineProperty(this, "handleBlur", () => { this.props.hidePlaceholderFloatingToolbar(); }); } render() { const { getNodeFromPos, showInsertPanelAt, editorViewDOM, popupsMountPoint, getFixedCoordinatesFromPos, popupsBoundariesElement, intl: { formatMessage } } = this.props; const target = getNodeFromPos(showInsertPanelAt); const offsetParent = getOffsetParent(editorViewDOM, popupsMountPoint); const getFixedCoordinates = () => getFixedCoordinatesFromPos(showInsertPanelAt); const 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 })); } } // eslint-disable-next-line @typescript-eslint/ban-types const _default_1 = injectIntl(PlaceholderFloatingToolbar); export default _default_1;