@atlaskit/editor-plugin-annotation
Version:
Annotation plugin for @atlaskit/editor-core
39 lines • 2 kB
JavaScript
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 var useCommentButtonMount = function useCommentButtonMount(_ref) {
var state = _ref.state,
annotationProviders = _ref.annotationProviders,
api = _ref.api,
annotationSelectionType = _ref.annotationSelectionType,
bookmark = _ref.bookmark;
useEffect(function () {
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 || _annotationProviders$.call(_annotationProviders$2);
}
// Check if the selection includes an non-text inline node
var inlineNodeNames = (_getRangeInlineNodeNa = getRangeInlineNodeNames({
doc: state.doc,
pos: resolveDraftBookmark(state, bookmark)
})) !== null && _getRangeInlineNodeNa !== void 0 ? _getRangeInlineNodeNa : [];
var isNonTextInlineNodeInludedInComment =
// eslint-disable-next-line @atlassian/perf-linting/no-expensive-computations-in-render -- Ignored via go/ees017 (to be fixed)
inlineNodeNames.filter(function (nodeName) {
return nodeName !== 'text';
}).length > 0;
fireCommentButtonViewedAnalyticsEvent({
api: api,
isNonTextInlineNodeInludedInComment: isNonTextInlineNodeInludedInComment,
annotationSelectionType: annotationSelectionType
});
// for now trying to replicate current onMount logic
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
};