-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathsingle.vue
54 lines (50 loc) · 1.54 KB
/
single.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<script setup lang="ts">
import { inject, toRef, computed, Ref } from 'vue'
import GroupToken from './group.vue'
const props = defineProps<{ data: any; modified: boolean; start: number }>()
const data = toRef(props, 'data')
const start = toRef(props, 'start')
const index = computed(() => start.value + data.value.index)
const current = inject<Ref<any>>('current')
const currentProp = inject<Ref<string>>('currentProp')
const setCurrent = (prop) => {
// console.log('setCurrent', data, prop)
if (current) {
current.value = data.value
}
if (currentProp) {
currentProp.value = prop
}
}
</script>
<template>
<GroupToken
v-if="data.type === 'group'"
:data="data"
:modified="modified"
:start="start"
/><span
v-else
@click="setCurrent('value')"
:class="{
[data.modifiedType]: true,
changed: data.value !== data.modifiedValue,
ignored: 'ignoredValue' in data,
[`start-${index}`]: true,
current: current === data && currentProp === 'value'
}"
>{{ modified ? data.modifiedValue : data.value }}</span
><span
v-if="modified ? data.modifiedSpaceAfter : data.spaceAfter"
@click="setCurrent('spaceAfter')"
:class="{
'token-space-after': true,
changed: data.spaceAfter !== data.modifiedSpaceAfter,
ignored: 'ignoredSpaceAfter' in data,
[`start-${index}`]: true,
current: current === data && currentProp === 'spaceAfter'
}"
>{{ modified ? data.modifiedSpaceAfter : data.spaceAfter }}</span
>
</template>
<style scoped src="./labels.css"></style>