-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathDocumentEditor.vue
317 lines (307 loc) · 7.08 KB
/
DocumentEditor.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<template>
<div class="flex flex-col overflow-y-auto pr-3">
<div>
<t-select
:options="{
Article: 'Journal Article',
PhDThesis: 'PhD Thesis',
}"
variant="plaincaps"
>
<template #arrow="{ className }">
<UIcon
name="ri:arrow-drop-down-line"
:class="className"
/>
</template>
</t-select>
</div>
<div class="z-10 grid -mt-2">
<!-- Auto-grow textarea, taken from https://css-tricks.com/the-cleanest-trick-for-autogrowing-textareas/ -->
<div
class="whitespace-pre-wrap text-xl row-span-1 col-span-1 col-start-1 row-start-1 py-2 px-3 invisible"
>
{{ title + ' ' }}
</div>
<t-textarea
v-model="title"
variant="plain"
class="text-xl resize-none overflow-hidden row-span-1 col-span-1 col-start-1 row-start-1"
></t-textarea>
</div>
<div class="-mt-3">
<Tags
v-model="authors"
placeholder="Add author"
:delimiters="undefined"
:whitelist="authorSuggestions"
/>
</div>
<div>
<document-editor-input v-model="published"></document-editor-input>
<span class="text-gray-400">|</span>
<document-editor-input v-model="journal"></document-editor-input>
</div>
<div class="-mt-1">
<span class="pl-3">
Volume:
<document-editor-input v-model="volume"></document-editor-input>
</span>
<span class="text-gray-400 pr-3">|</span>
<span>
Issue:
<document-editor-input v-model="issue"></document-editor-input>
</span>
<span class="text-gray-400 pr-3">|</span>
<span>
pp.
<document-editor-input v-model="pages"></document-editor-input>
</span>
</div>
<div>
<document-editor-header
heading="Abstract"
class="mt-4 -mb-1"
></document-editor-header>
<t-textarea
v-model="abstract"
variant="plain"
rows="5"
></t-textarea>
</div>
<div>
<document-editor-header
heading="Keywords"
class="mt-4"
></document-editor-header>
<Tags
v-model="keywords"
placeholder="Add keyword"
:delimiters="undefined"
:whitelist="keywordSuggestions"
tag-class="border rounded-md"
/>
</div>
<div>
<document-editor-header
heading="Groups"
class="mt-4"
></document-editor-header>
<Tags
v-model="groups"
placeholder="Add group"
:delimiters="undefined"
:whitelist="groupSuggestions"
tag-class="bg-primary-50 rounded-md"
/>
</div>
<div>
<document-editor-header
heading="External"
class="mt-4 mb-1"
></document-editor-header>
<t-table
:data="externalLinks"
variant="plain"
class="text-sm"
></t-table>
</div>
</div>
</template>
<script lang="ts" setup>
import { useQuery } from '@vue/apollo-composable'
import { gql, useFragment } from '~/apollo'
import type { PersonFullDetailsFragment } from '~/apollo/graphql'
import Tags from './tagify.vue'
const PersonFullDetails = gql(/* GraphQL */ `
fragment PersonFullDetails on Person {
id
family
given
suffix
nonDroppingParticle
droppingParticle
}
`)
const DocumentDetails = gql(/* GraphQL */ `
fragment DocumentDetails on Document {
id
title
keywords
abstract
doi
authors {
... on Person {
...PersonFullDetails
}
... on Organization {
id
name
}
}
... on JournalArticle {
in {
id
volume
number
journal {
id
name
}
}
published
pageStart
pageEnd
}
... on ProceedingsArticle {
in {
id
title
}
}
... on Thesis {
institution {
id
name
}
}
}
`)
const props = defineProps({
documentId: {
type: String,
required: true,
},
})
const { result } = useQuery(
gql(/* GraphQL */ `
query DocumentDetails($documentId: ID!) {
userDocument(id: $documentId) {
...DocumentDetails
}
}
`),
() => ({
documentId: props.documentId,
}),
)
const document = computed(() =>
useFragment(DocumentDetails, result.value?.userDocument),
)
function formatAuthor(author: PersonFullDetailsFragment) {
let result = ''
if (author.nonDroppingParticle) {
result += author.nonDroppingParticle + ' '
}
result += author.family ?? ''
if (author.suffix) {
result += ' ' + author.suffix
}
if (author.given) {
result += ', ' + author.given
}
return result
}
const authors = computed({
get: () =>
document.value?.authors.map((author) => ({
value:
author.__typename === 'Organization'
? author.name
: author.__typename === 'Person'
? formatAuthor(useFragment(PersonFullDetails, author))
: '',
})),
set: (_value) => {
// TODO: implement
},
})
const authorSuggestions = [{ value: 'Linus' }]
const keywords = computed({
get: () =>
document.value?.keywords.map((keyword) => ({
value: keyword,
})),
set: (_value) => {
// TODO: implement
},
})
const keywordSuggestions = [{ value: 'Differential Geometry' }]
const groups = [{ value: 'Chocolate Making' }, { value: 'Consumption' }]
const groupSuggestions = [{ value: 'Grinding' }]
const externalLinks = computed(() => [
{ name: 'DOI', value: document.value?.doi },
{ name: 'ArXiv', value: '1812.04695' },
{ name: 'MathSciNet', value: 'MR3997558' },
])
const title = computed({
get: () => document.value?.title,
set: (_value) => {
// TODO: implement
},
})
const published = computed({
get: () =>
document.value && 'published' in document.value
? document.value.published
: null,
set: (_value) => {
// TODO: implement
},
})
const journal = computed({
get: () =>
document.value &&
'in' in document.value &&
document.value.in &&
'journal' in document.value.in
? document.value.in.journal?.name
: null,
set: (_value) => {
// TODO: implement
},
})
const volume = computed({
get: () =>
document.value &&
'in' in document.value &&
document.value.in &&
'volume' in document.value.in
? document.value.in.volume
: null,
set: (_value) => {
// TODO: implement
},
})
const issue = computed({
get: () =>
document.value &&
'in' in document.value &&
document.value.in &&
'number' in document.value.in
? document.value.in.number
: null,
set: (_value) => {
// TODO: implement
},
})
const pages = computed({
get: () =>
document.value && 'pageStart' in document.value
? (document.value.pageStart ?? '') +
(document.value.pageEnd ? '-' + document.value.pageEnd : '')
: null,
set: (_value) => {
// TODO: implement
},
})
const abstract = computed({
get: () =>
document.value && 'abstract' in document.value
? document.value.abstract
: null,
set: (_value) => {
// TODO: implement
},
})
</script>