UNPKG

@atlaskit/renderer

Version:
36 lines (35 loc) 1.71 kB
import React, { useContext, useMemo, useCallback } from 'react'; import { ProvidersContext } from '../context'; import { useAnnotationClickEvent } from '../hooks/use-events'; import { RendererContext } from '../../../ui/RendererActionsContext'; const AnnotationView = props => { const providers = useContext(ProvidersContext); const actionContext = useContext(RendererContext); const inlineCommentProvider = providers && providers.inlineComment; const updateSubscriber = inlineCommentProvider && inlineCommentProvider.updateSubscriber || null; const viewComponentProps = useAnnotationClickEvent({ updateSubscriber, createAnalyticsEvent: props.createAnalyticsEvent, isNestedRender: props.isNestedRender }); const ViewComponent = inlineCommentProvider && inlineCommentProvider.viewComponent; const deleteAnnotation = useMemo(() => annotationInfo => actionContext.deleteAnnotation(annotationInfo.id, annotationInfo.type), [actionContext]); // For view mode, the finding of inline node types is a bit more complex, // that's why we will not provide it as a `inlineNodeTypes` props to the view component, // to speed up the rendering process. const getInlineNodeTypes = useCallback(annotationId => actionContext.getInlineNodeTypes(annotationId), [actionContext]); if (ViewComponent && viewComponentProps) { const { annotations, clickElementTarget } = viewComponentProps; return /*#__PURE__*/React.createElement(ViewComponent, { annotations: annotations, clickElementTarget: clickElementTarget, deleteAnnotation: deleteAnnotation, getInlineNodeTypes: getInlineNodeTypes }); } return null; }; export { AnnotationView };