@manuscripts/body-editor 3.14.0 → 3.15.1
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/affiliations/AffiliationsModal.js +9 -9
- package/dist/cjs/components/authors/AuthorsModal.js +9 -7
- package/dist/cjs/components/authors-affiliations/AuthorsAndAffiliationsModals.js +1 -0
- package/dist/cjs/components/cross-ref-check-modal/CrossRefWarningModal.js +182 -0
- package/dist/cjs/components/cross-ref-check-modal/openModal.js +38 -0
- package/dist/cjs/components/references/ImportBibliographyForm.js +5 -2
- package/dist/cjs/components/references/ReferenceSearch.js +2 -2
- package/dist/cjs/components/references/ReferencesModal.js +2 -2
- package/dist/cjs/plugins/affiliations.js +6 -3
- package/dist/cjs/plugins/bibliography.js +6 -3
- package/dist/cjs/plugins/cross-references.js +165 -2
- package/dist/cjs/plugins/footnotes.js +6 -3
- package/dist/cjs/versions.js +1 -1
- package/dist/cjs/views/embed.js +2 -2
- package/dist/cjs/views/footnote.js +2 -2
- package/dist/es/components/affiliations/AffiliationsModal.js +1 -1
- package/dist/es/components/authors/AuthorsModal.js +3 -1
- package/dist/es/components/authors-affiliations/AuthorsAndAffiliationsModals.js +1 -0
- package/dist/es/components/cross-ref-check-modal/CrossRefWarningModal.js +142 -0
- package/dist/es/components/cross-ref-check-modal/openModal.js +31 -0
- package/dist/es/components/references/ImportBibliographyForm.js +1 -1
- package/dist/es/components/references/ReferenceSearch.js +1 -1
- package/dist/es/components/references/ReferencesModal.js +1 -1
- package/dist/es/plugins/affiliations.js +1 -1
- package/dist/es/plugins/bibliography.js +1 -1
- package/dist/es/plugins/cross-references.js +163 -3
- package/dist/es/plugins/footnotes.js +1 -1
- package/dist/es/versions.js +1 -1
- package/dist/es/views/embed.js +1 -1
- package/dist/es/views/footnote.js +1 -1
- package/dist/types/components/authors-affiliations/AuthorsAndAffiliationsModals.d.ts +1 -1
- package/dist/types/components/cross-ref-check-modal/CrossRefWarningModal.d.ts +29 -0
- package/dist/types/components/cross-ref-check-modal/openModal.d.ts +19 -0
- package/dist/types/versions.d.ts +1 -1
- package/package.json +2 -2
- package/src/components/affiliations/AffiliationsModal.tsx +1 -1
- package/src/components/authors/AuthorsModal.tsx +3 -1
- package/src/components/authors-affiliations/AuthorsAndAffiliationsModals.tsx +2 -0
- package/src/components/cross-ref-check-modal/CrossRefWarningModal.tsx +223 -0
- package/src/components/cross-ref-check-modal/openModal.ts +50 -0
- package/src/components/references/ImportBibliographyForm.tsx +1 -1
- package/src/components/references/ReferenceSearch.tsx +1 -1
- package/src/components/references/ReferencesModal.tsx +1 -1
- package/src/plugins/affiliations.ts +1 -1
- package/src/plugins/bibliography.ts +1 -1
- package/src/plugins/cross-references.ts +233 -7
- package/src/plugins/footnotes.ts +1 -1
- package/src/versions.ts +1 -1
- package/src/views/embed.ts +1 -1
- package/src/views/footnote.ts +1 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2026 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 { ManuscriptNode } from '@manuscripts/transform'
|
|
18
|
+
import React, { useState } from 'react'
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
AttentionOrangeIcon,
|
|
22
|
+
CloseButton,
|
|
23
|
+
ModalContainer,
|
|
24
|
+
ModalHeader,
|
|
25
|
+
PrimaryButton,
|
|
26
|
+
StyledModal,
|
|
27
|
+
TertiaryButton,
|
|
28
|
+
TextButton,
|
|
29
|
+
} from '@manuscripts/style-guide'
|
|
30
|
+
import { ResolvedPos } from 'prosemirror-model'
|
|
31
|
+
import { startCase } from 'lodash'
|
|
32
|
+
import styled from 'styled-components'
|
|
33
|
+
|
|
34
|
+
export type XrefGroup = {
|
|
35
|
+
referenced: ManuscriptNode
|
|
36
|
+
label: string
|
|
37
|
+
xrefs: [ManuscriptNode, ResolvedPos][]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const CrossRefWarningModal: React.FC<{
|
|
41
|
+
onClose: () => void
|
|
42
|
+
xrefs: XrefGroup[]
|
|
43
|
+
onConfirm: () => void
|
|
44
|
+
selectAndScrollTo: ($pos: ResolvedPos) => void
|
|
45
|
+
}> = ({ onClose, xrefs, onConfirm, selectAndScrollTo }) => {
|
|
46
|
+
const [isOpen, setIsOpen] = useState(true)
|
|
47
|
+
const handleClose = () => {
|
|
48
|
+
setIsOpen(false)
|
|
49
|
+
onClose()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Modal
|
|
54
|
+
isOpen={isOpen}
|
|
55
|
+
onRequestClose={() => handleClose()}
|
|
56
|
+
shouldCloseOnOverlayClick={false}
|
|
57
|
+
hideOverlay={true}
|
|
58
|
+
>
|
|
59
|
+
<Container data-cy="cross-reference-warning-modal">
|
|
60
|
+
<ModalHeader>
|
|
61
|
+
<CloseButton
|
|
62
|
+
onClick={() => handleClose()}
|
|
63
|
+
data-cy="modal-close-button"
|
|
64
|
+
/>
|
|
65
|
+
</ModalHeader>
|
|
66
|
+
<Body>
|
|
67
|
+
<Title>
|
|
68
|
+
<AttentionOrangeIcon width={24} height={22} /> Delete referenced
|
|
69
|
+
content?
|
|
70
|
+
</Title>
|
|
71
|
+
<p>You are deleting content referenced elsewhere in the document:</p>
|
|
72
|
+
<ScrolableItems>
|
|
73
|
+
{xrefs.map((group, i) => (
|
|
74
|
+
<XrefGroupDisplay
|
|
75
|
+
key={i}
|
|
76
|
+
group={group}
|
|
77
|
+
selectAndScrollTo={selectAndScrollTo}
|
|
78
|
+
/>
|
|
79
|
+
))}
|
|
80
|
+
</ScrolableItems>
|
|
81
|
+
<Actions>
|
|
82
|
+
<TertiaryButton type="button" onClick={() => handleClose()}>
|
|
83
|
+
Cancel
|
|
84
|
+
</TertiaryButton>
|
|
85
|
+
<PrimaryButton
|
|
86
|
+
$danger={true}
|
|
87
|
+
type="button"
|
|
88
|
+
onClick={() => {
|
|
89
|
+
onConfirm()
|
|
90
|
+
setIsOpen(false)
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
Delete & remove citation
|
|
94
|
+
</PrimaryButton>
|
|
95
|
+
</Actions>
|
|
96
|
+
</Body>
|
|
97
|
+
</Container>
|
|
98
|
+
</Modal>
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const XrefGroupDisplay: React.FC<{
|
|
103
|
+
group: XrefGroup
|
|
104
|
+
selectAndScrollTo: ($pos: ResolvedPos) => void
|
|
105
|
+
}> = ({ group, selectAndScrollTo }) => {
|
|
106
|
+
return (
|
|
107
|
+
<div>
|
|
108
|
+
<h3>{group.label}</h3>
|
|
109
|
+
<ReferencesList>
|
|
110
|
+
{group.xrefs.map(([, pos], i) => {
|
|
111
|
+
return (
|
|
112
|
+
<li key={i}>
|
|
113
|
+
<TextButton onClick={() => selectAndScrollTo(pos)}>
|
|
114
|
+
{`${startCase(pos.parent.type.name)} - ${pos.parent.textContent}`}
|
|
115
|
+
</TextButton>
|
|
116
|
+
</li>
|
|
117
|
+
)
|
|
118
|
+
})}
|
|
119
|
+
</ReferencesList>
|
|
120
|
+
</div>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const Container = styled(ModalContainer)`
|
|
125
|
+
position: absolute;
|
|
126
|
+
top: 1rem;
|
|
127
|
+
left: 50%;
|
|
128
|
+
right: 0;
|
|
129
|
+
max-height: calc(50vh - 2rem);
|
|
130
|
+
min-height: 280px;
|
|
131
|
+
transform: translate(-50%, 0);
|
|
132
|
+
max-width: 480px;
|
|
133
|
+
transition:
|
|
134
|
+
top 0.2s,
|
|
135
|
+
transform 0.2s;
|
|
136
|
+
`
|
|
137
|
+
|
|
138
|
+
// since we need to scroll inside the editor when this dialog is active, we can't use dialog.showModal()
|
|
139
|
+
// so we recreate the appearance using classic position:fixed/after approach.
|
|
140
|
+
// While showModal doesn't block scrolling - it doesn't allow to focus on the editor and that kills the scrollIntoView
|
|
141
|
+
const Modal = styled(StyledModal)`
|
|
142
|
+
position: fixed;
|
|
143
|
+
top: 0;
|
|
144
|
+
left: 0;
|
|
145
|
+
width: 100%;
|
|
146
|
+
height: 100%;
|
|
147
|
+
z-index: 1100;
|
|
148
|
+
color: #6e6e6e;
|
|
149
|
+
margin: auto;
|
|
150
|
+
|
|
151
|
+
&.modal-bottom ${Container} {
|
|
152
|
+
top: calc(100% - 2rem);
|
|
153
|
+
transform: translate(-50%, -100%);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
&:after {
|
|
157
|
+
content: '';
|
|
158
|
+
display: block;
|
|
159
|
+
position: fixed;
|
|
160
|
+
z-index: -1;
|
|
161
|
+
left: 0;
|
|
162
|
+
top: 0;
|
|
163
|
+
right: 0;
|
|
164
|
+
bottom: 0;
|
|
165
|
+
background: rgba(0, 0, 0, 0.2);
|
|
166
|
+
}
|
|
167
|
+
h3 {
|
|
168
|
+
font-size: 16px;
|
|
169
|
+
margin: 0.5em 0;
|
|
170
|
+
}
|
|
171
|
+
p {
|
|
172
|
+
margin: 0.5em 0;
|
|
173
|
+
}
|
|
174
|
+
`
|
|
175
|
+
|
|
176
|
+
const Body = styled.div`
|
|
177
|
+
margin: 1.5rem;
|
|
178
|
+
display: flex;
|
|
179
|
+
flex-flow: column;
|
|
180
|
+
`
|
|
181
|
+
|
|
182
|
+
const Title = styled.h2`
|
|
183
|
+
font-size: 18px;
|
|
184
|
+
font-weight: 700;
|
|
185
|
+
line-height: 1.5;
|
|
186
|
+
margin: 0;
|
|
187
|
+
color: #353535;
|
|
188
|
+
svg {
|
|
189
|
+
vertical-align: text-top;
|
|
190
|
+
}
|
|
191
|
+
`
|
|
192
|
+
|
|
193
|
+
const ReferencesList = styled.ul`
|
|
194
|
+
padding: 8px;
|
|
195
|
+
margin-left: 0;
|
|
196
|
+
list-style: none;
|
|
197
|
+
background: #f2f2f2;
|
|
198
|
+
border: 1px solid #e2e2e2;
|
|
199
|
+
border-radius: 3px;
|
|
200
|
+
|
|
201
|
+
${TextButton} {
|
|
202
|
+
margin-left: 0;
|
|
203
|
+
text-decoration: underline;
|
|
204
|
+
&:hover {
|
|
205
|
+
text-decoration: none;
|
|
206
|
+
}
|
|
207
|
+
display: block;
|
|
208
|
+
max-width: 100%;
|
|
209
|
+
overflow: hidden;
|
|
210
|
+
color: #353535;
|
|
211
|
+
text-overflow: ellipsis;
|
|
212
|
+
}
|
|
213
|
+
`
|
|
214
|
+
|
|
215
|
+
const Actions = styled.footer`
|
|
216
|
+
text-align: right;
|
|
217
|
+
padding-top: 1rem;
|
|
218
|
+
`
|
|
219
|
+
const ScrolableItems = styled.div`
|
|
220
|
+
max-height: 16vh;
|
|
221
|
+
min-height: 100px;
|
|
222
|
+
overflow-y: auto;
|
|
223
|
+
`
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2026 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 { ManuscriptEditorView } from '@manuscripts/transform'
|
|
18
|
+
import { ResolvedPos } from 'prosemirror-model'
|
|
19
|
+
|
|
20
|
+
import { getEditorProps } from '../../plugins/editor-props'
|
|
21
|
+
import ReactSubView from '../../views/ReactSubView'
|
|
22
|
+
import { CrossRefWarningModal, XrefGroup } from './CrossRefWarningModal'
|
|
23
|
+
|
|
24
|
+
export const openCrossRefWarningModal = (
|
|
25
|
+
view: ManuscriptEditorView,
|
|
26
|
+
xrefGroups: XrefGroup[],
|
|
27
|
+
onConfirm: () => void,
|
|
28
|
+
onClose: () => void,
|
|
29
|
+
selectAndScrollTo: ($pos: ResolvedPos) => void
|
|
30
|
+
): HTMLDivElement => {
|
|
31
|
+
const { state } = view
|
|
32
|
+
const props = getEditorProps(state)
|
|
33
|
+
const componentProps = {
|
|
34
|
+
xrefs: xrefGroups,
|
|
35
|
+
onConfirm,
|
|
36
|
+
onClose,
|
|
37
|
+
selectAndScrollTo,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const dialog = ReactSubView(
|
|
41
|
+
props,
|
|
42
|
+
CrossRefWarningModal,
|
|
43
|
+
componentProps,
|
|
44
|
+
state.doc,
|
|
45
|
+
() => 0,
|
|
46
|
+
view
|
|
47
|
+
)
|
|
48
|
+
document.body.appendChild(dialog)
|
|
49
|
+
return dialog
|
|
50
|
+
}
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
} from '@manuscripts/style-guide'
|
|
26
26
|
import { BibliographyItemAttrs } from '@manuscripts/transform'
|
|
27
27
|
import { useFormik } from 'formik'
|
|
28
|
-
import
|
|
28
|
+
import debounce from 'lodash/debounce'
|
|
29
29
|
import React, {
|
|
30
30
|
KeyboardEvent,
|
|
31
31
|
useCallback,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
withFocusTrap,
|
|
25
25
|
} from '@manuscripts/style-guide'
|
|
26
26
|
import { BibliographyItemAttrs } from '@manuscripts/transform'
|
|
27
|
-
import
|
|
27
|
+
import debounce from 'lodash/debounce'
|
|
28
28
|
import React, { useState } from 'react'
|
|
29
29
|
import styled from 'styled-components'
|
|
30
30
|
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
withNavigableListItem,
|
|
33
33
|
} from '@manuscripts/style-guide'
|
|
34
34
|
import { BibliographyItemAttrs } from '@manuscripts/transform'
|
|
35
|
-
import
|
|
35
|
+
import isEqual from 'lodash/isEqual'
|
|
36
36
|
import React, { useEffect, useRef, useState } from 'react'
|
|
37
37
|
import styled from 'styled-components'
|
|
38
38
|
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
isContributorNode,
|
|
25
25
|
ManuscriptNode,
|
|
26
26
|
} from '@manuscripts/transform'
|
|
27
|
-
import
|
|
27
|
+
import isEqual from 'lodash/isEqual'
|
|
28
28
|
import { Plugin, PluginKey } from 'prosemirror-state'
|
|
29
29
|
import { Decoration, DecorationSet } from 'prosemirror-view'
|
|
30
30
|
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
ManuscriptNode,
|
|
25
25
|
} from '@manuscripts/transform'
|
|
26
26
|
import * as Citeproc from 'citeproc'
|
|
27
|
-
import
|
|
27
|
+
import isEqual from 'lodash/isEqual'
|
|
28
28
|
import { EditorState, Plugin, PluginKey } from 'prosemirror-state'
|
|
29
29
|
import { Decoration, DecorationSet } from 'prosemirror-view'
|
|
30
30
|
|
|
@@ -14,24 +14,102 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
import {
|
|
18
|
+
ManuscriptEditorView,
|
|
19
|
+
ManuscriptNode,
|
|
20
|
+
schema,
|
|
21
|
+
Target,
|
|
22
|
+
} from '@manuscripts/transform'
|
|
23
|
+
import { trackChangesPluginKey } from '@manuscripts/track-changes-plugin'
|
|
24
|
+
import isEqual from 'lodash/isEqual'
|
|
25
|
+
import { Node, ResolvedPos } from 'prosemirror-model'
|
|
26
|
+
import { NodeSelection, Plugin, Transaction } from 'prosemirror-state'
|
|
27
|
+
import { Decoration, DecorationSet, EditorView } from 'prosemirror-view'
|
|
22
28
|
|
|
29
|
+
import { XrefGroup } from '../components/cross-ref-check-modal/CrossRefWarningModal'
|
|
30
|
+
import { openCrossRefWarningModal } from '../components/cross-ref-check-modal/openModal'
|
|
23
31
|
import { objectsKey } from './objects'
|
|
24
32
|
|
|
33
|
+
let modalActive = false
|
|
34
|
+
let modalElement: HTMLDivElement | null = null
|
|
35
|
+
|
|
25
36
|
export default () => {
|
|
37
|
+
let view: ManuscriptEditorView | null = null
|
|
38
|
+
|
|
26
39
|
return new Plugin({
|
|
40
|
+
view(editorView) {
|
|
41
|
+
view = editorView as ManuscriptEditorView
|
|
42
|
+
return {
|
|
43
|
+
update(v) {
|
|
44
|
+
view = v as ManuscriptEditorView
|
|
45
|
+
},
|
|
46
|
+
destroy() {
|
|
47
|
+
view = null
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
filterTransaction(tr, state) {
|
|
53
|
+
// plugins working with content silently are not the subject to a warning. Especially the Collab plugin!
|
|
54
|
+
if (
|
|
55
|
+
!view ||
|
|
56
|
+
!tr.docChanged ||
|
|
57
|
+
tr.getMeta(trackChangesPluginKey) ||
|
|
58
|
+
tr.getMeta('addToHistory') === false
|
|
59
|
+
) {
|
|
60
|
+
return true
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Block doc-changing transactions while modal is active - freezing to stabilize doc so same steps can be applied onConfirm
|
|
64
|
+
if (modalActive) {
|
|
65
|
+
return false
|
|
66
|
+
}
|
|
67
|
+
const targets = objectsKey.getState(state) as Map<string, Target>
|
|
68
|
+
const xrefGroups = createXrefGroups(targets, state.doc, tr.doc)
|
|
69
|
+
|
|
70
|
+
// Orphaned rids were already broken before this transaction — allow
|
|
71
|
+
if (xrefGroups.length === 0) {
|
|
72
|
+
return true
|
|
73
|
+
}
|
|
74
|
+
// Block the transaction and show a warning modal
|
|
75
|
+
modalActive = true
|
|
76
|
+
|
|
77
|
+
const cleanup = () => {
|
|
78
|
+
modalActive = false
|
|
79
|
+
if (modalElement) {
|
|
80
|
+
modalElement.classList.remove('modal-bottom')
|
|
81
|
+
modalElement.remove()
|
|
82
|
+
modalElement = null
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const deletedIds = new Set(
|
|
87
|
+
xrefGroups.map((g) => g.referenced.attrs.id as string)
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
const onClose = () => {
|
|
91
|
+
cleanup()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (view) {
|
|
95
|
+
modalElement = openCrossRefWarningModal(
|
|
96
|
+
view,
|
|
97
|
+
xrefGroups,
|
|
98
|
+
onConfirmCreator(view, cleanup, deletedIds, tr),
|
|
99
|
+
onClose,
|
|
100
|
+
selectAndScrollToCreator(view)
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return false
|
|
105
|
+
},
|
|
106
|
+
|
|
27
107
|
state: {
|
|
28
108
|
init() {
|
|
29
|
-
// Initialize decorations with an empty set
|
|
30
109
|
return DecorationSet.empty
|
|
31
110
|
},
|
|
32
111
|
apply(tr, oldDecorationSet, oldState, newState) {
|
|
33
112
|
let decoSet = oldDecorationSet
|
|
34
|
-
// Check if document or targets have changed
|
|
35
113
|
const oldTargets = objectsKey.getState(oldState)
|
|
36
114
|
const newTargets = objectsKey.getState(newState)
|
|
37
115
|
if (tr.docChanged && !isEqual(oldTargets, newTargets)) {
|
|
@@ -68,3 +146,151 @@ function createDecorations(doc: Node): Decoration[] {
|
|
|
68
146
|
})
|
|
69
147
|
return decorations
|
|
70
148
|
}
|
|
149
|
+
|
|
150
|
+
function createXrefGroups(
|
|
151
|
+
targets: Map<string, Target>,
|
|
152
|
+
stateDoc: ManuscriptNode,
|
|
153
|
+
resultDoc: ManuscriptNode
|
|
154
|
+
) {
|
|
155
|
+
const newIds = new Set<string>()
|
|
156
|
+
const xrefRids = new Set<string>()
|
|
157
|
+
const xrefGroups: XrefGroup[] = []
|
|
158
|
+
|
|
159
|
+
resultDoc.descendants((node) => {
|
|
160
|
+
if (node.attrs.id) {
|
|
161
|
+
newIds.add(node.attrs.id)
|
|
162
|
+
}
|
|
163
|
+
if (node.type === schema.nodes.cross_reference) {
|
|
164
|
+
for (const rid of node.attrs.rids as string[]) {
|
|
165
|
+
xrefRids.add(rid)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
// Find xref rids that point to ids no longer present in the resulting doc
|
|
171
|
+
const orphanedRids = new Set<string>()
|
|
172
|
+
for (const rid of xrefRids) {
|
|
173
|
+
if (!newIds.has(rid)) {
|
|
174
|
+
orphanedRids.add(rid)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// No broken xrefs — allow the transaction
|
|
179
|
+
if (orphanedRids.size === 0) {
|
|
180
|
+
return []
|
|
181
|
+
}
|
|
182
|
+
// collect the referenced nodes and their xrefs with resolved positions for the modal.
|
|
183
|
+
const referencedNodes = new Map<string, ManuscriptNode>()
|
|
184
|
+
const xrefsByRid = new Map<string, [ManuscriptNode, ResolvedPos][]>()
|
|
185
|
+
|
|
186
|
+
stateDoc.descendants((node, pos) => {
|
|
187
|
+
const id = node.attrs.id
|
|
188
|
+
if (id && orphanedRids.has(id)) {
|
|
189
|
+
referencedNodes.set(id, node as ManuscriptNode)
|
|
190
|
+
}
|
|
191
|
+
if (node.type === schema.nodes.cross_reference) {
|
|
192
|
+
for (const rid of node.attrs.rids as string[]) {
|
|
193
|
+
if (orphanedRids.has(rid)) {
|
|
194
|
+
let entries = xrefsByRid.get(rid)
|
|
195
|
+
if (!entries) {
|
|
196
|
+
entries = []
|
|
197
|
+
xrefsByRid.set(rid, entries)
|
|
198
|
+
}
|
|
199
|
+
entries.push([node as ManuscriptNode, stateDoc.resolve(pos)])
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
for (const [id, referenced] of referencedNodes) {
|
|
206
|
+
const xrefs = xrefsByRid.get(id)
|
|
207
|
+
if (xrefs?.length) {
|
|
208
|
+
const label = targets.get(referenced.attrs.id)?.label || ''
|
|
209
|
+
xrefGroups.push({ referenced, label, xrefs })
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return xrefGroups
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const onConfirmCreator =
|
|
216
|
+
(
|
|
217
|
+
view: EditorView,
|
|
218
|
+
cleanup: () => void,
|
|
219
|
+
deletedIds: Set<string>,
|
|
220
|
+
tr: Transaction
|
|
221
|
+
) =>
|
|
222
|
+
() => {
|
|
223
|
+
cleanup()
|
|
224
|
+
if (!view) {
|
|
225
|
+
return
|
|
226
|
+
}
|
|
227
|
+
// Replay the intercepted transaction's steps on the current state
|
|
228
|
+
const newTr = view.state.tr
|
|
229
|
+
for (const step of tr.steps) {
|
|
230
|
+
const result = step.apply(newTr.doc)
|
|
231
|
+
if (result.failed) {
|
|
232
|
+
console.warn(
|
|
233
|
+
'Cross-ref deletion warning: could not replay step —',
|
|
234
|
+
result.failed
|
|
235
|
+
)
|
|
236
|
+
return
|
|
237
|
+
}
|
|
238
|
+
newTr.step(step)
|
|
239
|
+
}
|
|
240
|
+
// Remove cross-references that pointed to the now-deleted nodes.
|
|
241
|
+
// Collect positions in reverse order so deletions don't shift
|
|
242
|
+
// positions of earlier entries.
|
|
243
|
+
const xrefPositions: { from: number; to: number }[] = []
|
|
244
|
+
newTr.doc.descendants((node, pos) => {
|
|
245
|
+
if (node.type === schema.nodes.cross_reference) {
|
|
246
|
+
const rids = node.attrs.rids as string[]
|
|
247
|
+
if (rids.some((rid) => deletedIds.has(rid))) {
|
|
248
|
+
xrefPositions.push({ from: pos, to: pos + node.nodeSize })
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
})
|
|
252
|
+
for (let i = xrefPositions.length - 1; i >= 0; i--) {
|
|
253
|
+
const { from, to } = xrefPositions[i]
|
|
254
|
+
newTr.delete(from, to)
|
|
255
|
+
}
|
|
256
|
+
view.dispatch(newTr)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const selectAndScrollToCreator = (view: EditorView) => ($pos: ResolvedPos) => {
|
|
260
|
+
if (!view) {
|
|
261
|
+
return
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const selTr = view.state.tr
|
|
265
|
+
selTr.setSelection(NodeSelection.create(view.state.doc, $pos.pos))
|
|
266
|
+
view.focus()
|
|
267
|
+
view.dispatch(selTr)
|
|
268
|
+
// Standard PM's scrollIntoView doesn't allow placement control - hence switching to native DOM's peer method.
|
|
269
|
+
let scrollable = view.dom.parentElement
|
|
270
|
+
|
|
271
|
+
while (
|
|
272
|
+
scrollable != null &&
|
|
273
|
+
scrollable.scrollHeight <= scrollable.clientHeight
|
|
274
|
+
) {
|
|
275
|
+
scrollable = scrollable.parentElement
|
|
276
|
+
}
|
|
277
|
+
if (!scrollable) {
|
|
278
|
+
return // will need more advance handling not to overlap if there is no scroll. The plethora of edge-cases suggest that the warning shouldn't be overlapping the editor really
|
|
279
|
+
}
|
|
280
|
+
const coords = view.coordsAtPos($pos.pos)
|
|
281
|
+
const containerRect = scrollable.getBoundingClientRect()
|
|
282
|
+
const offsetInContainer =
|
|
283
|
+
coords.top - containerRect.top + scrollable.scrollTop
|
|
284
|
+
const containerHeight = scrollable.clientHeight
|
|
285
|
+
// We want the element at 75% of the container (middle of bottom half)
|
|
286
|
+
const scrollTo = offsetInContainer - containerHeight * 0.75
|
|
287
|
+
if (scrollTo < 0) {
|
|
288
|
+
// Element is too close to the top of the document to scroll into
|
|
289
|
+
// the bottom half — move the modal to the bottom instead.
|
|
290
|
+
modalElement?.classList.add('modal-bottom')
|
|
291
|
+
scrollable.scrollTo({ top: 0, behavior: 'smooth' })
|
|
292
|
+
} else {
|
|
293
|
+
modalElement?.classList.remove('modal-bottom')
|
|
294
|
+
scrollable.scrollTo({ top: scrollTo, behavior: 'smooth' })
|
|
295
|
+
}
|
|
296
|
+
}
|
package/src/plugins/footnotes.ts
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
ManuscriptNode,
|
|
25
25
|
schema,
|
|
26
26
|
} from '@manuscripts/transform'
|
|
27
|
-
import
|
|
27
|
+
import isEqual from 'lodash/isEqual'
|
|
28
28
|
import { Plugin, PluginKey, TextSelection } from 'prosemirror-state'
|
|
29
29
|
import { findChildrenByType } from 'prosemirror-utils'
|
|
30
30
|
import { Decoration, DecorationSet } from 'prosemirror-view'
|
package/src/versions.ts
CHANGED
package/src/views/embed.ts
CHANGED
package/src/views/footnote.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { ContextMenu, ContextMenuProps } from '@manuscripts/style-guide'
|
|
|
18
18
|
import { isDeleted, isPendingInsert } from '@manuscripts/track-changes-plugin'
|
|
19
19
|
import { FootnoteNode, ManuscriptNode, schema } from '@manuscripts/transform'
|
|
20
20
|
|
|
21
|
-
import
|
|
21
|
+
import isEqual from 'lodash/isEqual'
|
|
22
22
|
import { NodeSelection, Transaction } from 'prosemirror-state'
|
|
23
23
|
import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils'
|
|
24
24
|
|