Skip to content

Commit 7cb74cf

Browse files
committed
Merge branch 'develop'
2 parents ee52fc6 + d1d8845 commit 7cb74cf

File tree

5 files changed

+27
-77
lines changed

5 files changed

+27
-77
lines changed

src/components/ContentView.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<div
1616
id="text-content"
17+
ref="textContainer"
1718
class="custom-font item-content t-flex t-flex-col t-flex-1 t-overflow-auto"
1819
>
1920
<!-- eslint-disable -- https://eslint.vuejs.org/rules/no-v-html.html -->
@@ -25,7 +26,7 @@
2526
<script setup>
2627
2728
import {
28-
computed, readonly, ref, watch,
29+
computed, readonly, ref, useTemplateRef, watch,
2930
} from 'vue';
3031
import { useConfigStore } from '@/stores/config';
3132
import { useAnnotationsStore } from '@/stores/annotations';
@@ -40,6 +41,7 @@ const props = defineProps({
4041
fontSize: Number,
4142
});
4243
const emit = defineEmits(['loading']);
44+
const textContainer = useTemplateRef('textContainer');
4345
4446
const configStore = useConfigStore();
4547
const contentStore = useContentsStore();
@@ -77,7 +79,7 @@ async function loadContent(url) {
7779
setTimeout(async () => {
7880
emit('loading', false);
7981
80-
const root = document.getElementById('text-content');
82+
const root = textContainer.value;
8183
annotationStore.addHighlightAttributesToText(root);
8284
await annotationStore.addHighlightClickListeners();
8385

src/components/annotations/AnnotationsView.vue

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,28 @@ interface Props {
3737
const props = defineProps<Props>();
3838
const emit = defineEmits(['init'])
3939
40+
let lastLoadedAnnotations = null;
41+
let lastLoadedContentUrl = null;
42+
4043
const annotations = computed<Annotation[]>(() => annotationStore.annotations);
4144
const filteredAnnotations = computed<Annotation[]>(() => annotationStore.filteredAnnotations);
4245
const activeContentUrl = computed<string>(() => contentStore.activeContentUrl);
43-
const updateTextHighlighting = computed(() =>
46+
const updateTextHighlighting = computed(() => {
4447
// We need to make sure that annotations are loaded (this.annotations),
4548
// the text HTML is present in DOM (this.activeContentUrl is set after DOM update)
4649
// and the annotation are filtered by type (this.filteredAnnotations).
47-
`${annotations.value !== null}|${activeContentUrl.value}`);
50+
const annotationsChanged = lastLoadedContentUrl !== activeContentUrl.value && lastLoadedAnnotations !== annotations.value
51+
return `${annotations.value !== null}|${annotationsChanged}|${activeContentUrl.value}`
52+
});
4853
4954
watch(
5055
updateTextHighlighting,
51-
(contentData) => {
52-
const [hasAnnotations, activeContentUrl] = contentData.split('|');
53-
if (hasAnnotations !== 'true' || activeContentUrl === 'null') return;
56+
(value) => {
57+
const [hasAnnotations, annotationsChanged, activeContentUrl] = value.split('|');
58+
if (hasAnnotations !== 'true' || annotationsChanged !== 'true' || activeContentUrl === 'null') return;
59+
if (!value) return;
60+
lastLoadedAnnotations = annotationStore.annotations;
61+
lastLoadedContentUrl = contentStore.activeContentUrl
5462
annotationStore.resetAnnotations();
5563
annotationStore.selectFilteredAnnotations(props.types);
5664
annotationStore.highlightTargetsLevel0();

src/stores/annotations.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ export const useAnnotationsStore = defineStore('annotations', () => {
257257
annotationStore.setActiveAnnotations(activeAnnotationsList)
258258

259259
const selector = AnnotationUtils.generateTargetSelector(removeAnnotation);
260-
const textEl = document.querySelector('#text-content')
261-
const target = textEl.querySelector(selector)
260+
const target = document.querySelector(selector)
262261

263262
if (!target) return
264263

src/utils/annotations.js

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ export function generateTargetSelector(annotation) {
8989
}
9090
} else if (selector.type === 'CssSelector') {
9191
result = handleCssSelector(selector);
92-
} else if (selector.type === 'RangeSelector') {
93-
result = handleRangeSelector(selector);
9492
}
9593

9694
const isValid = Utils.isSelectorValid(result);
@@ -102,48 +100,6 @@ export function handleCssSelector(selector) {
102100
return selector.value ?? null;
103101
}
104102

105-
export function handleRangeSelector(selector) {
106-
const { startSelector, endSelector } = selector;
107-
if (startSelector && endSelector) {
108-
if (startSelector.type === 'CssSelector') {
109-
const start = document.querySelector(handleCssSelector(startSelector).replaceAll('\'', ''));
110-
const end = document.querySelector(handleCssSelector(endSelector).replaceAll('\'', ''));
111-
112-
const elementsInRange = [];
113-
114-
let started = false;
115-
let ended = false;
116-
117-
// eslint-disable-next-line no-inner-declarations
118-
function findElementsInRangeRecursive(element) {
119-
if (element === start) started = true;
120-
if (element === end) {
121-
ended = true;
122-
return;
123-
}
124-
125-
if (started && element.nodeValue !== ' ' && element.nodeName === '#text') {
126-
elementsInRange.push(element.parentElement);
127-
return;
128-
}
129-
130-
[...element.childNodes]
131-
.filter((childNode) => childNode.nodeName !== 'STYLE' && childNode.nodeName !== 'SCRIPT' && childNode.nodeName !== 'svg')
132-
.forEach((childNode) => {
133-
if (!ended) {
134-
findElementsInRangeRecursive(childNode);
135-
}
136-
});
137-
}
138-
139-
findElementsInRangeRecursive(document.getElementById('text-content'));
140-
141-
return elementsInRange.map((el) => Utils.elemToSelector(el)).join(',');
142-
}
143-
}
144-
return null;
145-
}
146-
147103
export function addIcon(element, annotation, iconName) {
148104
let foundSvg = false;
149105

@@ -231,8 +187,8 @@ function createWitnessEl(witness, witnessColor) {
231187

232188
export function removeWitnessesWrappers() {
233189
// remove witnesses in text Panel - it is used when switch off the variants tab
234-
const textPanelEl = document.querySelector('#text-content')
235-
const wrappers = textPanelEl.getElementsByClassName('witnesses')
190+
const textPanelEls = document.querySelectorAll('.content-view')
191+
const wrappers = textPanelEls.querySelectorAll('.witnesses')
236192
if (!wrappers) return;
237193
if(Array.from(wrappers).length === 0) return;
238194

@@ -245,8 +201,13 @@ export function removeWitnessesWrappers() {
245201
export function removeWitness(selector, idno) {
246202
// find the witnesses span which contains each 'witness' span child element
247203
// find this witness inside the 'witnesses' html span and remove it
248-
const textPanel = document.querySelector('#text-content')
249-
if (!textPanel.querySelector('.witnesses')) return;
204+
const textPanels = document.querySelectorAll('.content-view')
205+
if (textPanels.length === 0) return;
206+
207+
let hasWitnesses = false;
208+
textPanels.forEach(textPanel => hasWitnesses = textPanel.querySelectorAll('.witnesses').length > 0)
209+
210+
if (!hasWitnesses) return;
250211

251212
const wrapper = getWitnessesWrapper(selector)
252213
if (!wrapper) return;

src/utils/dom.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,6 @@ export function addToAttribute(element, attribute, newValue) {
5050
}
5151
}
5252

53-
export function elemToSelector(el) {
54-
if (el.id === 'text-content') return '#text-content';
55-
let str = el.tagName.toLowerCase();
56-
57-
if (el.id !== '') {
58-
str += `#${el.id}`;
59-
} else if (el.className) {
60-
const classes = el.className.trim().split(/\s+/);
61-
for (let i = 0; i < classes.length; i++) {
62-
str += `.${classes[i]}`;
63-
}
64-
}
65-
66-
if (el.hasAttribute('data-target')) {
67-
str += `[data-target=${el.getAttribute('data-target')}]`;
68-
}
69-
70-
return `${elemToSelector(el.parentNode)} > ${str}`;
71-
}
72-
7353
export function getValuesFromAttribute(element, attribute) {
7454
const value = element.getAttribute(attribute);
7555
return value ? value.split(' ') : [];

0 commit comments

Comments
 (0)