UNPKG

@atlaskit/editor-plugin-status

Version:

Status plugin for @atlaskit/editor-core

68 lines 2.57 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({ api, popupsMountPoint, popupsBoundariesElement, popupsScrollableElement, editorView, domAtPos }) { const { statusState } = useSharedPluginState(api, ['status']); const { showStatusPickerAt } = statusState !== null && statusState !== void 0 ? statusState : {}; const target = useMemo(() => // Ignored via go/ees005 // eslint-disable-next-line @atlaskit/editor/no-as-casting showStatusPickerAt ? findDomRefAtPos(showStatusPickerAt, domAtPos) : null, [showStatusPickerAt, domAtPos]); const statusNode = useMemo(() => showStatusPickerAt ? editorView.state.doc.nodeAt(showStatusPickerAt) : undefined, [showStatusPickerAt, editorView]); const onSelect = useCallback(status => { updateStatus(status)(editorView.state, editorView.dispatch); }, [editorView]); const onTextChanged = useCallback(status => { updateStatus(status)(editorView.state, editorView.dispatch); }, [editorView]); const closeStatusPicker = useCallback(closingPayload => { commitStatusPicker(closingPayload)(editorView); }, [editorView]); const onEnter = useCallback(() => { commitStatusPicker()(editorView); }, [editorView]); if (typeof showStatusPickerAt !== 'number') { return null; } if (!statusNode || statusNode.type.name !== 'status') { return null; } const { text, color, localId, style } = statusNode.attrs; const 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 }); }