@atlaskit/renderer
Version:
Renderer component
37 lines • 1.56 kB
JavaScript
/* eslint-disable jsdoc/require-jsdoc */
import { fg } from '@atlaskit/platform-feature-flags';
import { useAnnotationRangeState } from '../contexts/AnnotationRangeContext';
export function useInlineAnnotationProps(props) {
const {
selectionDraftDocumentPosition: draftPosition
} = useAnnotationRangeState();
if (!fg('editor_inline_comments_on_inline_nodes')) {
return {};
}
if (!props.dataAttributes) {
// the inlineCard component is currently used by the block card, embed card and card error boundary components
// when used via these components, no dataAttributes are passed (and we don't want it setup for inline comments)
return {};
}
const inlineCardPosition = props.dataAttributes['data-renderer-start-pos'] - 1;
const hasDraft = draftPosition &&
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(draftPosition === null || draftPosition === void 0 ? void 0 : draftPosition.from) <= inlineCardPosition &&
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(draftPosition === null || draftPosition === void 0 ? void 0 : draftPosition.to) >= inlineCardPosition + 1;
if (hasDraft) {
return {
'data-renderer-mark': true,
'data-annotation-draft-mark': true,
'data-annotation-inline-node': true,
'data-renderer-start-pos': inlineCardPosition
};
}
return {
'data-annotation-inline-node': true,
'data-annotation-mark': true,
'data-renderer-start-pos': inlineCardPosition
};
}