-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathstatus.vue
126 lines (118 loc) · 3.11 KB
/
status.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<script setup lang="ts">
import { Ref, computed, inject } from 'vue'
const TOKEN_TYPE_MAP = {
'': '',
'western-letter': 'Wester letters and numbers',
'cjk-char': 'CJK characters',
'halfwidth-pause-or-stop': 'Half-width punctuation',
'fullwidth-pause-or-stop': 'Full-width punctuation',
'halfwidth-other-punctuation': 'Half-width punctuation',
'fullwidth-other-punctuation': 'Full-width punctuation',
'hyper-mark': 'Non-content',
'hyper-content': 'Non-content',
'code-content': 'Code',
'bracket-mark': 'Bracket',
group: 'Quotation',
unmatched: 'Unpaired bracket/quotation',
'non-block': 'Non-content'
}
const PROP_MAP = {
// type: {
// modified: 'modifiedType',
// ignored: 'ignoredType',
// label: 'Type',
// },
value: {
modified: 'modifiedValue',
ignored: 'ignoredValue',
label: 'Value'
},
spaceAfter: {
modified: 'modifiedSpaceAfter',
ignored: 'ignoredSpaceAfter',
label: 'Space After'
},
startValue: {
modified: 'modifiedStartValue',
ignored: 'ignoredStartValue',
label: 'Left Quotation'
},
innerSpaceBefore: {
modified: 'modifiedInnerSpaceBefore',
ignored: 'ignoredInnerSpaceBefore',
label: 'Inner Left Space in Quotations'
},
endValue: {
modified: 'modifiedEndValue',
ignored: 'ignoredEndValue',
label: 'Right Quotation'
}
}
const current = inject<Ref<any>>('current')
const currentProp = inject<Ref<string>>('currentProp')
const checkSpace = (prop) =>
prop === 'spaceAfter' || prop === 'innerSpaceBefore'
const checkType = (data, prop) => {
if (!data || !prop) {
return 'Nothing selected'
}
if (checkSpace(prop)) {
return 'Space'
}
if (data?.type === data?.modifiedType) {
return TOKEN_TYPE_MAP[data?.type]
} else {
return (
TOKEN_TYPE_MAP[data?.type] +
' is modified into ' +
TOKEN_TYPE_MAP[data?.modifiedType]
)
}
}
const checkProp = (data, prop) => {
if (!data || !prop) {
return {
desc: 'click the tokens in "Origin" or "Formatted" to see more details'
}
}
const { modified, ignored } = PROP_MAP[prop]
console.log(
data,
prop,
modified,
ignored,
data[modified] === data[prop],
ignored in data
)
if (data[modified] !== data[prop]) {
if (checkSpace(prop)) {
if (data[modified] && data[prop]) {
return { desc: 'normalized' }
}
return { desc: !data[prop] ? 'added' : 'removed' }
}
return {
desc: ' is modified into ',
original: data[prop],
modified: data[modified]
}
} else if (ignored in data) {
return { desc: 'modification ignored' }
} else {
return { desc: 'nothing to modify' }
}
}
const type = computed(() => checkType(current?.value, currentProp?.value))
const prop = computed(() => checkProp(current?.value, currentProp?.value))
</script>
<template>
<div class="status">
<h3>Selected Token</h3>
<pre>{{ type }} (<span v-if="prop.original" class="string">{{ prop.original }}</span>{{ prop.desc }}<span v-if="prop.modified" class="string">{{ prop.modified }}</span>)</pre>
</div>
</template>
<style scoped>
.string {
background-color: #eee;
}
</style>