-
- protected positionForReference() {
- if (!this.commentContentRef) {
- return;
- }
-
- const [refId, refHash, refRange] = this.commentContentRef.split(':');
- const refEl = document.getElementById(refId);
- if (!refEl) {
- // TODO - Show outdated marker for comment
- return;
- }
-
- const actualHash = hashElement(refEl);
- if (actualHash !== refHash) {
- // TODO - Show outdated marker for comment
- return;
- }
-
- const refElBounds = refEl.getBoundingClientRect();
- let bounds = refElBounds;
- const [rangeStart, rangeEnd] = refRange.split('-');
- if (rangeStart && rangeEnd) {
- const range = new Range();
- const relStart = findTargetNodeAndOffset(refEl, Number(rangeStart));
- const relEnd = findTargetNodeAndOffset(refEl, Number(rangeEnd));
- if (relStart && relEnd) {
- range.setStart(relStart.node, relStart.offset);
- range.setEnd(relEnd.node, relEnd.offset);
- bounds = range.getBoundingClientRect();
- }
- }
-
- const relLeft = bounds.left - refElBounds.left;
- const relTop = bounds.top - refElBounds.top;
- // TODO - Extract to class, Use theme color
- const marker = el('div', {
- class: 'content-comment-highlight',
- style: `left: ${relLeft}px; top: ${relTop}px; width: ${bounds.width}px; height: ${bounds.height}px;`
- }, ['']);
-
- refEl.style.position = 'relative';
- refEl.append(marker);
- }