Util.handleKeyboardClick(e, this.handleClick)} data-ref={ref}>
{sidebarNum}
{this.props.hideTitle ? null :
(
{title}
{this.props.titleButtons ?
e.stopPropagation()}>{this.props.titleButtons}
: null }
)}
{ textSegments }
{ this.props.showActionLinks ? actionLinks : null }
);
}
}
TextRange.propTypes = {
sref: PropTypes.string.isRequired,
currVersions: PropTypes.object.isRequired,
useVersionLanguage: PropTypes.bool,
highlightedRefs: PropTypes.array,
showHighlight: PropTypes.bool,
basetext: PropTypes.bool,
withContext: PropTypes.bool,
hideTitle: PropTypes.bool,
loadLinks: PropTypes.bool,
prefetchNextPrev: PropTypes.bool,
prefetchMultiple: PropTypes.number,
lowlight: PropTypes.bool,
numberLabel: PropTypes.number,
settings: PropTypes.object,
filter: PropTypes.array,
titleButtons: PropTypes.object,
showParashahHeaders: PropTypes.bool,
onTextLoad: PropTypes.func,
onRangeClick: PropTypes.func,
onSegmentClick: PropTypes.func,
onCitationClick: PropTypes.func,
onLinkerAdminCitationClick: PropTypes.func,
onNamedEntityClick: PropTypes.func,
showBaseText: PropTypes.func,
unsetTextHighlight: PropTypes.func,
panelsOpen: PropTypes.number, // used?
layoutWidth: PropTypes.number,
showActionLinks: PropTypes.bool,
inlineReference: PropTypes.object,
textHighlights: PropTypes.array,
translationLanguagePreference: PropTypes.string,
navigatePanel: PropTypes.func,
};
TextRange.defaultProps = {
currVersions: {en:null,he:null},
};
class TextSegment extends Component {
static contextType = ReaderPanelContext;
shouldComponentUpdate(nextProps) {
if (this.props.highlight !== nextProps.highlight) { return true; }
if (this.props.showHighlight !== nextProps.showHighlight) { return true; }
if (this.props.textHighlights !== nextProps.textHighlights) { return true; }
if (this.props.showLinkCount !== nextProps.showLinkCount) { return true; }
if (this.props.linkCount !== nextProps.linkCount) { return true; }
if (!!this.props.filter !== !!nextProps.filter) { return true; }
if (this.props.filter && nextProps.filter &&
!this.props.filter.compare(nextProps.filter)) { return true; }
if (this.props.en !== nextProps.en
|| this.props.he !== nextProps.he) { return true; }
return false;
}
componentDidUpdate(prevProps) {
if (this.props.highlight !== prevProps.highlight && !!this.props.textHighlights) {
this.props.unsetTextHighlight();
}
}
handleRefLinkClick(refLink, event) {
event.preventDefault();
let newRef = Sefaria.humanRef(refLink.attr("data-ref"));
const newBook = Sefaria.parseRef(newRef)?.index;
const currBook = Sefaria.parseRef(this.props.sref)?.index;
const isScrollLink = refLink.attr('data-scroll-link');
// two options: in most cases, we open a new panel, but if isScrollLink is 'true', we should navigate in the same panel to the new location
const canNavigatePanel = newBook === currBook && !!this.props.navigatePanel; // navigatePanel only works if we're scrolling to a location in the same book
if (isScrollLink === 'true' && canNavigatePanel) {
this.props.navigatePanel(newRef);
}
else {
const ven = refLink.attr("data-ven") ? refLink.attr("data-ven") : null;
const vhe = refLink.attr("data-vhe") ? refLink.attr("data-vhe") : null;
let currVersions = {"en": {versionTitle: ven}, "he": {versionTitle: vhe}};
this.props.onCitationClick(newRef, this.props.sref, true, currVersions);
}
event.stopPropagation();
Sefaria.track.event("Reader", "Citation Link Click", ref);
}
isRefLink (x) {
// 'x' is a jquery element
return x?.attr('data-ref') && x?.prop('tagName') === 'A';
}
handleClick(event) {
const mutcTarget = event.target.closest("a.mutc");
if (mutcTarget) {
const charRange = mutcTarget.getAttribute('data-range');
const contentSpan = mutcTarget.closest('.contentSpan');
const lang = contentSpan?.classList.contains('he') ? 'he' : 'en';
const key = `${this.props.sref}|${lang}|${charRange}`;
const spans = Sefaria._linkerOutputMap[key];
const sampleSpan = spans?.[0];
if (sampleSpan?.type === "citation" && Sefaria.is_moderator && this.props.onLinkerAdminCitationClick) {
this.props.onLinkerAdminCitationClick(this.props.sref, lang, charRange, spans);
} else {
Sefaria._makeLinkerDebugAlert(this.props.sref, lang, charRange, spans);
}
event.preventDefault();
event.stopPropagation();
return;
}
// grab refLink from target or parent (sometimes there is an