@manuscripts/body-editor 3.18.5 → 3.18.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/references/CitationEditor.js +5 -5
- package/dist/cjs/components/references/InsertCitationModal.js +142 -0
- package/dist/cjs/components/references/ReferenceSearchResults.js +2 -2
- package/dist/cjs/components/references/ReferenceSearchSection.js +16 -10
- package/dist/cjs/components/references/SearchInput.js +1 -8
- package/dist/cjs/versions.js +1 -1
- package/dist/cjs/views/citation_editable.js +1 -0
- package/dist/es/components/references/CitationEditor.js +5 -5
- package/dist/es/components/references/InsertCitationModal.js +102 -0
- package/dist/es/components/references/ReferenceSearchResults.js +2 -2
- package/dist/es/components/references/ReferenceSearchSection.js +16 -10
- package/dist/es/components/references/SearchInput.js +0 -7
- package/dist/es/versions.js +1 -1
- package/dist/es/views/citation_editable.js +1 -0
- package/dist/types/components/references/CitationEditor.d.ts +1 -0
- package/dist/types/components/references/{ReferenceSearch.d.ts → InsertCitationModal.d.ts} +2 -1
- package/dist/types/components/references/ReferenceSearchResults.d.ts +1 -0
- package/dist/types/components/references/ReferenceSearchSection.d.ts +1 -0
- package/dist/types/components/references/SearchInput.d.ts +0 -1
- package/dist/types/versions.d.ts +1 -1
- package/package.json +2 -2
- package/src/components/references/CitationEditor.tsx +8 -4
- package/src/components/references/InsertCitationModal.tsx +198 -0
- package/src/components/references/ReferenceSearchResults.tsx +15 -2
- package/src/components/references/ReferenceSearchSection.tsx +19 -10
- package/src/components/references/SearchInput.tsx +0 -8
- package/src/versions.ts +1 -1
- package/src/views/citation_editable.ts +1 -0
- package/styles/popper.css +4 -0
- package/dist/cjs/components/references/ReferenceSearch.js +0 -133
- package/dist/es/components/references/ReferenceSearch.js +0 -93
- package/src/components/references/ReferenceSearch.tsx +0 -149
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* © 2023 Atypon Systems LLC
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
AddNewIcon,
|
|
19
|
-
ButtonGroup,
|
|
20
|
-
IconTextButton,
|
|
21
|
-
PrimaryButton,
|
|
22
|
-
SecondaryButton,
|
|
23
|
-
withFocusTrap,
|
|
24
|
-
} from '@manuscripts/style-guide'
|
|
25
|
-
import { BibliographyItemAttrs } from '@manuscripts/transform'
|
|
26
|
-
import debounce from 'lodash/debounce'
|
|
27
|
-
import React, { useState } from 'react'
|
|
28
|
-
import styled from 'styled-components'
|
|
29
|
-
|
|
30
|
-
import {
|
|
31
|
-
BibliographyItemSource,
|
|
32
|
-
DocumentReferenceSource,
|
|
33
|
-
} from './BibliographyItemSource'
|
|
34
|
-
import { ReferenceSearchSection } from './ReferenceSearchSection'
|
|
35
|
-
import { SearchInput } from './SearchInput'
|
|
36
|
-
|
|
37
|
-
const ReferenceSearchSectionContainer = styled.div`
|
|
38
|
-
max-height: 400px;
|
|
39
|
-
overflow-y: auto;
|
|
40
|
-
`
|
|
41
|
-
|
|
42
|
-
const Actions = styled(ButtonGroup)`
|
|
43
|
-
align-items: center;
|
|
44
|
-
box-shadow: 0 -2px 12px 0 rgba(216, 216, 216, 0.26);
|
|
45
|
-
display: flex;
|
|
46
|
-
justify-content: space-between;
|
|
47
|
-
padding: ${(props) => props.theme.grid.unit * 4}px;
|
|
48
|
-
`
|
|
49
|
-
|
|
50
|
-
const Container = withFocusTrap(styled.div`
|
|
51
|
-
flex: 1;
|
|
52
|
-
font-family: ${(props) => props.theme.font.family.sans};
|
|
53
|
-
`)
|
|
54
|
-
|
|
55
|
-
const AddReferenceActions = styled(ButtonGroup)`
|
|
56
|
-
button {
|
|
57
|
-
margin-right: ${(props) => props.theme.grid.unit * 8}px;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
button:hover,
|
|
61
|
-
button:active {
|
|
62
|
-
path {
|
|
63
|
-
stroke: ${(props) => props.theme.colors.brand.medium};
|
|
64
|
-
}
|
|
65
|
-
rect {
|
|
66
|
-
stroke: ${(props) => props.theme.colors.brand.medium};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
`
|
|
70
|
-
|
|
71
|
-
export const ReferenceSearch: React.FC<{
|
|
72
|
-
query?: string
|
|
73
|
-
sources: BibliographyItemSource[]
|
|
74
|
-
items: BibliographyItemAttrs[]
|
|
75
|
-
onAdd: () => void
|
|
76
|
-
onCite: (items: BibliographyItemAttrs[]) => void
|
|
77
|
-
onCancel: () => void
|
|
78
|
-
}> = ({ query: initialQuery, sources, items, onAdd, onCite, onCancel }) => {
|
|
79
|
-
const [query, setQuery] = useState<string>(initialQuery || '')
|
|
80
|
-
const [selections, setSelections] = useState(
|
|
81
|
-
new Map<string, BibliographyItemAttrs>()
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
const toggleSelection = (item: BibliographyItemAttrs) => {
|
|
85
|
-
const id = item.id
|
|
86
|
-
if (selections.has(id)) {
|
|
87
|
-
selections.delete(id)
|
|
88
|
-
setSelections(new Map([...selections]))
|
|
89
|
-
} else {
|
|
90
|
-
selections.set(id, item)
|
|
91
|
-
setSelections(new Map([...selections]))
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const isSelected = (item: BibliographyItemAttrs) => {
|
|
96
|
-
return selections.has(item.id)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const document = new DocumentReferenceSource(items)
|
|
100
|
-
|
|
101
|
-
const handleClick = () => {
|
|
102
|
-
const items = Array.from(selections.values())
|
|
103
|
-
return onCite(items)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const debouncedSetQuery = debounce((e) => {
|
|
107
|
-
setQuery(e.target.value.trim())
|
|
108
|
-
}, 800)
|
|
109
|
-
|
|
110
|
-
return (
|
|
111
|
-
<Container data-cy={'reference-finder'}>
|
|
112
|
-
<SearchInput onChange={debouncedSetQuery} defaultValue={initialQuery} />
|
|
113
|
-
<ReferenceSearchSectionContainer>
|
|
114
|
-
<ReferenceSearchSection
|
|
115
|
-
key={document.id}
|
|
116
|
-
query={query}
|
|
117
|
-
source={document}
|
|
118
|
-
isSelected={isSelected}
|
|
119
|
-
onSelect={toggleSelection}
|
|
120
|
-
/>
|
|
121
|
-
{query.length
|
|
122
|
-
? sources.map((source) => (
|
|
123
|
-
<ReferenceSearchSection
|
|
124
|
-
key={source.id}
|
|
125
|
-
query={query}
|
|
126
|
-
source={source}
|
|
127
|
-
isSelected={isSelected}
|
|
128
|
-
onSelect={toggleSelection}
|
|
129
|
-
/>
|
|
130
|
-
))
|
|
131
|
-
: ''}
|
|
132
|
-
</ReferenceSearchSectionContainer>
|
|
133
|
-
<Actions>
|
|
134
|
-
<AddReferenceActions>
|
|
135
|
-
<IconTextButton onClick={onAdd}>
|
|
136
|
-
<AddNewIcon />
|
|
137
|
-
Add new
|
|
138
|
-
</IconTextButton>
|
|
139
|
-
</AddReferenceActions>
|
|
140
|
-
<ButtonGroup>
|
|
141
|
-
<SecondaryButton onClick={onCancel}>Close</SecondaryButton>
|
|
142
|
-
<PrimaryButton onClick={handleClick} disabled={selections.size === 0}>
|
|
143
|
-
Cite
|
|
144
|
-
</PrimaryButton>
|
|
145
|
-
</ButtonGroup>
|
|
146
|
-
</Actions>
|
|
147
|
-
</Container>
|
|
148
|
-
)
|
|
149
|
-
}
|