UNPKG

@atlaskit/editor-plugin-annotation

Version:

Annotation plugin for @atlaskit/editor-core

38 lines 1.77 kB
import { useEffect } from 'react'; import { getRangeInlineNodeNames } from '@atlaskit/editor-common/utils'; import { fg } from '@atlaskit/platform-feature-flags'; import { resolveDraftBookmark } from '../../pm-plugins/utils'; import { fireCommentButtonViewedAnalyticsEvent } from './utils'; export const useCommentButtonMount = ({ state, annotationProviders, api, annotationSelectionType, bookmark }) => { useEffect(() => { var _getRangeInlineNodeNa; if (!state) { return; } if (annotationProviders !== null && annotationProviders !== void 0 && annotationProviders.inlineComment && fg('confluence_frontend_preload_inline_comment_editor')) { var _annotationProviders$, _annotationProviders$2; (_annotationProviders$ = (_annotationProviders$2 = annotationProviders.inlineComment).onCommentButtonMount) === null || _annotationProviders$ === void 0 ? void 0 : _annotationProviders$.call(_annotationProviders$2); } // Check if the selection includes an non-text inline node const inlineNodeNames = (_getRangeInlineNodeNa = getRangeInlineNodeNames({ doc: state.doc, pos: resolveDraftBookmark(state, bookmark) })) !== null && _getRangeInlineNodeNa !== void 0 ? _getRangeInlineNodeNa : []; const isNonTextInlineNodeInludedInComment = // eslint-disable-next-line @atlassian/perf-linting/no-expensive-computations-in-render -- Ignored via go/ees017 (to be fixed) inlineNodeNames.filter(nodeName => nodeName !== 'text').length > 0; fireCommentButtonViewedAnalyticsEvent({ api, isNonTextInlineNodeInludedInComment, annotationSelectionType }); // for now trying to replicate current onMount logic // eslint-disable-next-line react-hooks/exhaustive-deps }, []); };