@atlaskit/renderer
Version:
Renderer component
40 lines (39 loc) • 1.84 kB
JavaScript
import React, { useContext, useMemo, useCallback } from 'react';
import { ProvidersContext } from '../context';
import { useAnnotationClickEvent } from '../hooks/use-events';
import { RendererContext } from '../../../ui/RendererActionsContext';
var AnnotationView = function AnnotationView(props) {
var providers = useContext(ProvidersContext);
var actionContext = useContext(RendererContext);
var inlineCommentProvider = providers && providers.inlineComment;
var updateSubscriber = inlineCommentProvider && inlineCommentProvider.updateSubscriber || null;
var viewComponentProps = useAnnotationClickEvent({
updateSubscriber: updateSubscriber,
createAnalyticsEvent: props.createAnalyticsEvent,
isNestedRender: props.isNestedRender
});
var ViewComponent = inlineCommentProvider && inlineCommentProvider.viewComponent;
var deleteAnnotation = useMemo(function () {
return function (annotationInfo) {
return 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.
var getInlineNodeTypes = useCallback(function (annotationId) {
return actionContext.getInlineNodeTypes(annotationId);
}, [actionContext]);
if (ViewComponent && viewComponentProps) {
var annotations = viewComponentProps.annotations,
clickElementTarget = viewComponentProps.clickElementTarget;
return /*#__PURE__*/React.createElement(ViewComponent, {
annotations: annotations,
clickElementTarget: clickElementTarget,
deleteAnnotation: deleteAnnotation,
getInlineNodeTypes: getInlineNodeTypes
});
}
return null;
};
export { AnnotationView };