UNPKG

@atlaskit/editor-plugin-status

Version:

Status plugin for @atlaskit/editor-core

69 lines 2.99 kB
import React, { useCallback, useMemo } from 'react'; import { useSharedPluginState } from '@atlaskit/editor-common/hooks'; import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils'; import { fg } from '@atlaskit/platform-feature-flags'; import { commitStatusPicker, updateStatus } from '../pm-plugins/actions'; import StatusPicker from './statusPicker'; export function ContentComponent(_ref) { var api = _ref.api, popupsMountPoint = _ref.popupsMountPoint, popupsBoundariesElement = _ref.popupsBoundariesElement, popupsScrollableElement = _ref.popupsScrollableElement, editorView = _ref.editorView, domAtPos = _ref.domAtPos; var _useSharedPluginState = useSharedPluginState(api, ['status']), statusState = _useSharedPluginState.statusState; var _ref2 = statusState !== null && statusState !== void 0 ? statusState : {}, showStatusPickerAt = _ref2.showStatusPickerAt; var target = useMemo(function () { return ( // Ignored via go/ees005 // eslint-disable-next-line @atlaskit/editor/no-as-casting showStatusPickerAt ? findDomRefAtPos(showStatusPickerAt, domAtPos) : null ); }, [showStatusPickerAt, domAtPos]); var statusNode = useMemo(function () { return showStatusPickerAt ? editorView.state.doc.nodeAt(showStatusPickerAt) : undefined; }, [showStatusPickerAt, editorView]); var onSelect = useCallback(function (status) { updateStatus(status)(editorView.state, editorView.dispatch); }, [editorView]); var onTextChanged = useCallback(function (status) { updateStatus(status)(editorView.state, editorView.dispatch); }, [editorView]); var closeStatusPicker = useCallback(function (closingPayload) { commitStatusPicker(closingPayload)(editorView); }, [editorView]); var onEnter = useCallback(function () { commitStatusPicker()(editorView); }, [editorView]); if (typeof showStatusPickerAt !== 'number') { return null; } if (!statusNode || statusNode.type.name !== 'status') { return null; } var _statusNode$attrs = statusNode.attrs, text = _statusNode$attrs.text, color = _statusNode$attrs.color, localId = _statusNode$attrs.localId, style = _statusNode$attrs.style; var displayText = style !== 'mixedCase' && fg('platform-dst-lozenge-tag-badge-visual-uplifts') ? text.toUpperCase() : text; return /*#__PURE__*/React.createElement(StatusPicker, { isNew: statusState === null || statusState === void 0 ? void 0 : statusState.isNew, focusStatusInput: statusState === null || statusState === void 0 ? void 0 : statusState.focusStatusInput, target: target, defaultText: displayText, defaultColor: color, defaultLocalId: localId, mountTo: popupsMountPoint, boundariesElement: popupsBoundariesElement, scrollableElement: popupsScrollableElement, onSelect: onSelect, onTextChanged: onTextChanged, closeStatusPicker: closeStatusPicker, onEnter: onEnter, editorView: editorView, api: api }); }