diff --git a/examples/ahiqar-arabic-karshuni-with-variants-local.html b/examples/ahiqar-arabic-karshuni-with-variants-local.html index 2f1a7241..13abae1d 100644 --- a/examples/ahiqar-arabic-karshuni-with-variants-local.html +++ b/examples/ahiqar-arabic-karshuni-with-variants-local.html @@ -114,19 +114,19 @@ "types": [ { "name": "Person", - "icon": "biPersonFill" + "icon": "person" }, { "name": "Place", - "icon": "biGeoAltFill" + "icon": "marker" }, { "name": "Editorial Comment", - "icon": "biChatFill" + "icon": "chat" }, { "name": "Reference", - "icon": "biBoxArrowUpRight" + "icon": "externalLink" } ] } @@ -141,7 +141,7 @@ "types": [ { "name": "Motif", - "icon": "biPenFill" + "icon": "pen" } ] } @@ -156,7 +156,7 @@ "types": [ { "name": "Variant", - "icon": "biPenFill" + "icon": "pen" } ] } diff --git a/src/components/annotations/AnnotationVariantItem.vue b/src/components/annotations/AnnotationVariantItem.vue index 5cdfa992..c3b0f935 100644 --- a/src/components/annotations/AnnotationVariantItem.vue +++ b/src/components/annotations/AnnotationVariantItem.vue @@ -1,21 +1,47 @@ diff --git a/src/components/annotations/AnnotationsList.vue b/src/components/annotations/AnnotationsList.vue index e121347c..2783c7bc 100644 --- a/src/components/annotations/AnnotationsList.vue +++ b/src/components/annotations/AnnotationsList.vue @@ -1,28 +1,24 @@ + + \ No newline at end of file diff --git a/src/components/annotations/TopBar.vue b/src/components/annotations/TopBar.vue new file mode 100644 index 00000000..f6d7d7df --- /dev/null +++ b/src/components/annotations/TopBar.vue @@ -0,0 +1,63 @@ + + + + + + \ No newline at end of file diff --git a/src/components/annotations/WitnessChipInTopBar.vue b/src/components/annotations/WitnessChipInTopBar.vue new file mode 100644 index 00000000..c7bf8a6f --- /dev/null +++ b/src/components/annotations/WitnessChipInTopBar.vue @@ -0,0 +1,105 @@ + + + + + \ No newline at end of file diff --git a/src/stores/annotations.ts b/src/stores/annotations.ts index 8a026748..8a9b2aa1 100644 --- a/src/stores/annotations.ts +++ b/src/stores/annotations.ts @@ -7,7 +7,7 @@ import * as AnnotationUtils from '@/utils/annotations'; import { request } from '@/utils/http'; import * as Utils from '@/utils'; import { scrollIntoViewIfNeeded } from '@/utils'; -import { useConfigStore} from '@/stores/config'; +import { useConfigStore } from '@/stores/config'; export const useAnnotationsStore = defineStore('annotations', () => { @@ -62,6 +62,9 @@ export const useAnnotationsStore = defineStore('annotations', () => { if (elements.length > 0) { const target: HTMLElement = elements[0]; Utils.addIcon(target, newActiveAnnotation, iconName); + if (newActiveAnnotation.body['x-content-type'] === 'Variant') { + Utils.addWitness(target, newActiveAnnotation); + } scrollIntoViewIfNeeded(target, target.closest('.panel-body')); } }; @@ -133,11 +136,13 @@ export const useAnnotationsStore = defineStore('annotations', () => { if (selector) { AnnotationUtils.highlightTargets(selector, { operation: 'DEC' }); AnnotationUtils.removeIcon(removeAnnotation); + if(removeAnnotation.body['x-content-type'] === 'Variant') { + AnnotationUtils.removeWitness(selector, removeAnnotation) + } } }; - const resetAnnotations = () => { if (annotations.value !== null) { diff --git a/src/utils/annotations.js b/src/utils/annotations.js index 634b12d4..6096f8b5 100644 --- a/src/utils/annotations.js +++ b/src/utils/annotations.js @@ -1,6 +1,7 @@ import * as Utils from '@/utils/index'; import { getIcon } from '@/utils/icons'; import { i18n } from '@/i18n'; +import colors from '@/utils/color' // utility functions that we can use as generic way for perform tranformation on annotations. @@ -233,6 +234,60 @@ export function removeIcon(annotation) { } } +export function addWitness(element, annotation) { + + const variantItemsList = annotation.body.value; + const parentOfElement = element.parentElement; + const indexOfElement = [].slice.call(parentOfElement.children).indexOf(element) + + // get the number of variant items for this annotation and create a list of colors for the border color + const numberVariantItems = Object.keys(variantItemsList).length + const hexaDecimalColors = colors().slice(0, numberVariantItems) + + //let prevElement = element; + let i = 0; + variantItemsList.forEach((variantItem) => { + const witHtmlElement = document.createElement("SPAN"); + witHtmlElement.innerHTML = variantItem.witness; + witHtmlElement.classList.add('t-rounded-3xl', 't-box-border', 't-w-75', 't-h-8', 't-border-2', 't-p-[2px]', 't-text-sm', 't-ml-[3px]') + witHtmlElement.style.borderColor = hexaDecimalColors[i] //'t-border-'.concat(tailwindClassColors[i],'-600')) + i += 1; + // get the parent of the element, find its position in the parent div and then append it after it in order to show it after it - the style of the chip should be different from the element + //prevElement.after(witnessHtmlElement) + //prevElement = witnessHtmlElement + parentOfElement.insertBefore(witHtmlElement, parentOfElement.children[indexOfElement]); + }); + //element.after(witnessesHtml) +} + +export function removeWitness(selector, removeAnnotation) { + // selector: the selector of the annotated text + + const annotatedHtmlEl = document.getElementById(selector.split('#')[1]) + const parentOfAnnotatedEl = annotatedHtmlEl.parentElement; + const variantItemsList = removeAnnotation.body.value; + + const witnessesStringArray = getWitnesses(variantItemsList) + + parentOfAnnotatedEl.querySelectorAll('span').forEach( (element) => { + if (witnessesStringArray.includes(element.innerHTML)) { + element.remove() + } + }) + +} + +function getWitnesses(variantItemsList) { + const witnessesStringArray = [] + + variantItemsList.forEach((variantItem) => { + const witnessString = variantItem.witness; + witnessesStringArray.push(witnessString) + }); + + return witnessesStringArray +} + export function getAnnotationListElement(id, container) { return [...container.querySelectorAll('.q-item')].find((annotationItem) => { if (!annotationItem.hasAttribute('data-annotation-id')) return false; diff --git a/src/utils/color.js b/src/utils/color.js index f0e47879..6a25a7f6 100644 --- a/src/utils/color.js +++ b/src/utils/color.js @@ -7,3 +7,14 @@ export const getRGBColor = (hex, type) => { return `--color-${type}: ${r}, ${g}, ${b}; --color-${type}-accent: ${r - 15}, ${g - 15}, ${b - 15};`; }; + + +export default function colors() { + + const hexaDecimalColors = ['#FEF08A', '#BEF264', '#A8A29E', '#D8B4FE', '#A8A29E'] + return hexaDecimalColors; +} + +export function getItemColorBasedOnIndex(index){ + return colors()[index] +} \ No newline at end of file