@manuscripts/body-editor 3.16.0 → 3.16.2
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/commands.js +45 -10
- package/dist/cjs/components/form/FormFooter.js +2 -2
- package/dist/cjs/components/keyboard-shortcuts-modal/KeyboardShortcutsModal.js +4 -2
- package/dist/cjs/components/references/CitationEditor.js +13 -19
- package/dist/cjs/components/references/ImportBibliography.js +77 -0
- package/dist/cjs/components/references/ImportBibliographyForm.js +1 -1
- package/dist/cjs/components/references/ImportBibliographyModal.js +12 -81
- package/dist/cjs/components/references/ImportReferencesConfirmation.js +113 -0
- package/dist/cjs/components/references/ImportSuccessPlaceholder.js +56 -0
- package/dist/cjs/components/references/ReferenceSearch.js +2 -5
- package/dist/cjs/components/references/ReferencesEditor.js +18 -2
- package/dist/cjs/components/references/ReferencesModal.js +86 -33
- package/dist/cjs/components/views/CrossReferenceItems.js +139 -52
- package/dist/cjs/components/views/DeleteSupplementDialog.js +1 -1
- package/dist/cjs/lib/supplements.js +9 -1
- package/dist/cjs/lib/view.js +39 -1
- package/dist/cjs/menus.js +35 -0
- package/dist/cjs/plugins/objects.js +1 -1
- package/dist/cjs/toolbar.js +6 -0
- package/dist/cjs/versions.js +1 -1
- package/dist/cjs/views/bibliography_element.js +1 -2
- package/dist/cjs/views/citation_editable.js +2 -29
- package/dist/cjs/views/cross_reference.js +12 -2
- package/dist/cjs/views/cross_reference_editable.js +95 -4
- package/dist/cjs/views/figure_editable.js +3 -0
- package/dist/es/commands.js +43 -9
- package/dist/es/components/form/FormFooter.js +2 -2
- package/dist/es/components/keyboard-shortcuts-modal/KeyboardShortcutsModal.js +4 -2
- package/dist/es/components/references/CitationEditor.js +13 -19
- package/dist/es/components/references/ImportBibliography.js +70 -0
- package/dist/es/components/references/ImportBibliographyForm.js +1 -1
- package/dist/es/components/references/ImportBibliographyModal.js +13 -79
- package/dist/es/components/references/ImportReferencesConfirmation.js +73 -0
- package/dist/es/components/references/ImportSuccessPlaceholder.js +49 -0
- package/dist/es/components/references/ReferenceSearch.js +3 -6
- package/dist/es/components/references/ReferencesEditor.js +19 -3
- package/dist/es/components/references/ReferencesModal.js +88 -35
- package/dist/es/components/views/CrossReferenceItems.js +141 -54
- package/dist/es/components/views/DeleteSupplementDialog.js +2 -2
- package/dist/es/lib/supplements.js +8 -1
- package/dist/es/lib/view.js +36 -0
- package/dist/es/menus.js +36 -1
- package/dist/es/plugins/objects.js +1 -1
- package/dist/es/toolbar.js +8 -2
- package/dist/es/versions.js +1 -1
- package/dist/es/views/bibliography_element.js +2 -3
- package/dist/es/views/citation_editable.js +3 -30
- package/dist/es/views/cross_reference.js +12 -2
- package/dist/es/views/cross_reference_editable.js +96 -5
- package/dist/es/views/figure_editable.js +3 -0
- package/dist/types/commands.d.ts +1 -0
- package/dist/types/components/form/FormFooter.d.ts +2 -1
- package/dist/types/components/references/CitationEditor.d.ts +1 -1
- package/dist/types/components/references/ImportBibliography.d.ts +7 -0
- package/dist/types/components/references/ImportReferencesConfirmation.d.ts +8 -0
- package/dist/types/components/references/ImportSuccessPlaceholder.d.ts +5 -0
- package/dist/types/components/references/ReferenceSearch.d.ts +0 -1
- package/dist/types/components/references/ReferencesEditor.d.ts +4 -1
- package/dist/types/components/references/ReferencesModal.d.ts +1 -0
- package/dist/types/components/views/CrossReferenceItems.d.ts +3 -0
- package/dist/types/lib/supplements.d.ts +1 -0
- package/dist/types/lib/view.d.ts +3 -1
- package/dist/types/versions.d.ts +1 -1
- package/dist/types/views/citation_editable.d.ts +0 -1
- package/dist/types/views/cross_reference_editable.d.ts +6 -0
- package/package.json +4 -4
- package/src/commands.ts +52 -10
- package/src/components/ChangeHandlingForm.tsx +4 -2
- package/src/components/form/FormFooter.tsx +3 -1
- package/src/components/keyboard-shortcuts-modal/KeyboardShortcutsModal.tsx +6 -7
- package/src/components/references/CitationEditor.tsx +16 -25
- package/src/components/references/ImportBibliography.tsx +119 -0
- package/src/components/references/ImportBibliographyForm.tsx +1 -1
- package/src/components/references/ImportBibliographyModal.tsx +34 -110
- package/src/components/references/ImportReferencesConfirmation.tsx +133 -0
- package/src/components/references/ImportSuccessPlaceholder.tsx +93 -0
- package/src/components/references/ReferenceSearch.tsx +0 -7
- package/src/components/references/ReferencesEditor.tsx +35 -6
- package/src/components/references/ReferencesModal.tsx +164 -78
- package/src/components/toolbar/InsertEmbedDialog.tsx +6 -2
- package/src/components/toolbar/type-selector/styles.ts +2 -1
- package/src/components/views/CrossReferenceItems.tsx +227 -100
- package/src/components/views/DeleteSupplementDialog.tsx +3 -6
- package/src/lib/footnotes.ts +3 -1
- package/src/lib/supplements.ts +13 -1
- package/src/lib/utils.ts +15 -4
- package/src/lib/view.ts +65 -0
- package/src/menus.tsx +39 -0
- package/src/plugins/add-subtitle.ts +18 -16
- package/src/plugins/objects.ts +2 -6
- package/src/toolbar.tsx +9 -0
- package/src/versions.ts +1 -1
- package/src/views/bibliography_element.ts +3 -4
- package/src/views/citation_editable.ts +5 -50
- package/src/views/cross_reference.ts +17 -3
- package/src/views/cross_reference_editable.ts +123 -11
- package/src/views/figure_editable.ts +4 -0
- package/src/views/supplement.ts +0 -1
- package/src/views/supplements.ts +2 -2
package/src/plugins/objects.ts
CHANGED
|
@@ -60,7 +60,7 @@ export default () => {
|
|
|
60
60
|
if (id) {
|
|
61
61
|
const target = targets.get(id)
|
|
62
62
|
|
|
63
|
-
if (target) {
|
|
63
|
+
if (target && target.label) {
|
|
64
64
|
const caption = findChildren(
|
|
65
65
|
node,
|
|
66
66
|
(node) =>
|
|
@@ -115,11 +115,7 @@ export default () => {
|
|
|
115
115
|
* Returns the position for a widget decoration when there is no caption.
|
|
116
116
|
* Falls back to the end of the node.
|
|
117
117
|
*/
|
|
118
|
-
const getDecorationPos = (
|
|
119
|
-
target: Target,
|
|
120
|
-
doc: ManuscriptNode,
|
|
121
|
-
pos: number
|
|
122
|
-
) => {
|
|
118
|
+
const getDecorationPos = (target: Target, doc: ManuscriptNode, pos: number) => {
|
|
123
119
|
const $pos = doc.resolve(pos + 1)
|
|
124
120
|
return $pos.end()
|
|
125
121
|
}
|
package/src/toolbar.tsx
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
ToolbarBoldIcon,
|
|
25
25
|
ToolbarBoxedTextIcon,
|
|
26
26
|
ToolbarCitationIcon,
|
|
27
|
+
ToolbarCrossReferenceIcon,
|
|
27
28
|
ToolbarEquationIcon,
|
|
28
29
|
ToolbarFigureIcon,
|
|
29
30
|
ToolbarIndentIcon,
|
|
@@ -47,9 +48,11 @@ import {
|
|
|
47
48
|
addInlineComment,
|
|
48
49
|
blockActive,
|
|
49
50
|
canInsert,
|
|
51
|
+
canInsertCrossReference,
|
|
50
52
|
Dispatch,
|
|
51
53
|
insertBlock,
|
|
52
54
|
insertBoxElement,
|
|
55
|
+
insertCrossReference,
|
|
53
56
|
insertEmbed,
|
|
54
57
|
insertInlineCitation,
|
|
55
58
|
insertLink,
|
|
@@ -179,6 +182,12 @@ export const toolbar: ToolbarConfig = {
|
|
|
179
182
|
isEnabled: isEnabled(canInsert(schema.nodes.highlight_marker)), // TODO: check both ends of selection
|
|
180
183
|
run: addInlineComment,
|
|
181
184
|
},
|
|
185
|
+
cross_reference: {
|
|
186
|
+
title: 'Insert cross-reference',
|
|
187
|
+
content: <ToolbarCrossReferenceIcon />,
|
|
188
|
+
isEnabled: isEnabled(canInsertCrossReference),
|
|
189
|
+
run: insertCrossReference,
|
|
190
|
+
},
|
|
182
191
|
citation: {
|
|
183
192
|
title: 'Insert citation',
|
|
184
193
|
content: <ToolbarCitationIcon />,
|
package/src/versions.ts
CHANGED
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
BibliographyElementNode,
|
|
20
20
|
BibliographyItemAttrs,
|
|
21
21
|
BibliographyItemNode,
|
|
22
|
-
schema,
|
|
23
22
|
} from '@manuscripts/transform'
|
|
24
23
|
import { NodeSelection } from 'prosemirror-state'
|
|
25
24
|
|
|
@@ -32,7 +31,7 @@ import { handleEnterKey } from '../lib/navigation-utils'
|
|
|
32
31
|
import { findNodeByID } from '../lib/doc'
|
|
33
32
|
import { sanitize } from '../lib/dompurify'
|
|
34
33
|
|
|
35
|
-
import { deleteNode, findChildByID,
|
|
34
|
+
import { deleteNode, findChildByID, saveBibliographyItem } from '../lib/view'
|
|
36
35
|
import { getBibliographyPluginState } from '../plugins/bibliography'
|
|
37
36
|
import { commentsKey, setCommentSelection } from '../plugins/comments'
|
|
38
37
|
import { selectedSuggestionKey } from '../plugins/selected-suggestion'
|
|
@@ -269,8 +268,8 @@ export class BibliographyElementBlockView extends BlockView<
|
|
|
269
268
|
this.dom.appendChild(this.container)
|
|
270
269
|
}
|
|
271
270
|
|
|
272
|
-
private handleSave = (attrs: BibliographyItemAttrs) => {
|
|
273
|
-
|
|
271
|
+
private handleSave = (attrs: BibliographyItemAttrs[]) => {
|
|
272
|
+
saveBibliographyItem(this.view, attrs)
|
|
274
273
|
}
|
|
275
274
|
|
|
276
275
|
private handleDelete = (item: BibliographyItemAttrs) => {
|
|
@@ -16,13 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
import { ContextMenu, ContextMenuProps } from '@manuscripts/style-guide'
|
|
18
18
|
import { isDeleted } from '@manuscripts/track-changes-plugin'
|
|
19
|
-
import {
|
|
20
|
-
BibliographyItemAttrs,
|
|
21
|
-
ManuscriptNode,
|
|
22
|
-
schema,
|
|
23
|
-
} from '@manuscripts/transform'
|
|
19
|
+
import { BibliographyItemAttrs } from '@manuscripts/transform'
|
|
24
20
|
import { TextSelection } from 'prosemirror-state'
|
|
25
|
-
import { findChildrenByType } from 'prosemirror-utils'
|
|
26
21
|
|
|
27
22
|
import {
|
|
28
23
|
CitationEditor,
|
|
@@ -35,18 +30,12 @@ import {
|
|
|
35
30
|
import { handleComment } from '../lib/comments'
|
|
36
31
|
import { Crossref } from '../lib/crossref'
|
|
37
32
|
import { handleEnterKey } from '../lib/navigation-utils'
|
|
38
|
-
import { deleteNode,
|
|
33
|
+
import { deleteNode, saveBibliographyItem } from '../lib/view'
|
|
39
34
|
import { getBibliographyPluginState } from '../plugins/bibliography'
|
|
40
35
|
import { CitationView } from './citation'
|
|
41
36
|
import { createEditableNodeView } from './creators'
|
|
42
37
|
import ReactSubView from './ReactSubView'
|
|
43
38
|
|
|
44
|
-
const createBibliographySection = (node: ManuscriptNode) =>
|
|
45
|
-
schema.nodes.bibliography_section.createAndFill({}, [
|
|
46
|
-
schema.nodes.section_title.create({}, schema.text('References')),
|
|
47
|
-
schema.nodes.bibliography_element.create({}, node ? [node] : []),
|
|
48
|
-
]) as ManuscriptNode
|
|
49
|
-
|
|
50
39
|
export class CitationEditableView extends CitationView {
|
|
51
40
|
private editor: HTMLElement
|
|
52
41
|
private contextMenu: HTMLElement
|
|
@@ -216,12 +205,8 @@ export class CitationEditableView extends CitationView {
|
|
|
216
205
|
this.props.popper.destroy()
|
|
217
206
|
}
|
|
218
207
|
|
|
219
|
-
private handleSave = (attrs: BibliographyItemAttrs) => {
|
|
220
|
-
|
|
221
|
-
this.insertBibliographyNode(attrs)
|
|
222
|
-
} else {
|
|
223
|
-
updateNodeAttrs(this.view, schema.nodes.bibliography_item, attrs)
|
|
224
|
-
}
|
|
208
|
+
private handleSave = (attrs: BibliographyItemAttrs[]) => {
|
|
209
|
+
saveBibliographyItem(this.view, attrs)
|
|
225
210
|
}
|
|
226
211
|
|
|
227
212
|
private handleUncite = (id: string) => {
|
|
@@ -260,7 +245,7 @@ export class CitationEditableView extends CitationView {
|
|
|
260
245
|
if (existingItem) {
|
|
261
246
|
item.id = existingItem.id
|
|
262
247
|
} else {
|
|
263
|
-
this.
|
|
248
|
+
saveBibliographyItem(this.view, [item])
|
|
264
249
|
}
|
|
265
250
|
|
|
266
251
|
rids.push(item.id)
|
|
@@ -277,36 +262,6 @@ export class CitationEditableView extends CitationView {
|
|
|
277
262
|
private handleDelete = (item: BibliographyItemAttrs) => {
|
|
278
263
|
return deleteNode(this.view, item.id)
|
|
279
264
|
}
|
|
280
|
-
|
|
281
|
-
private insertBibliographyNode(attrs: BibliographyItemAttrs) {
|
|
282
|
-
const { doc, tr } = this.view.state
|
|
283
|
-
|
|
284
|
-
const biblioSection = findChildrenByType(
|
|
285
|
-
doc,
|
|
286
|
-
schema.nodes.bibliography_element,
|
|
287
|
-
true
|
|
288
|
-
)
|
|
289
|
-
|
|
290
|
-
const backmatter = findChildrenByType(doc, schema.nodes.backmatter, true)
|
|
291
|
-
const backmatterEnd = backmatter[0]
|
|
292
|
-
? backmatter[0].node.nodeSize + backmatter[0].pos
|
|
293
|
-
: 0
|
|
294
|
-
|
|
295
|
-
const node = schema.nodes.bibliography_item.create(attrs)
|
|
296
|
-
|
|
297
|
-
if (biblioSection.length) {
|
|
298
|
-
this.view.dispatch(tr.insert(biblioSection[0].pos + 1, node))
|
|
299
|
-
} else {
|
|
300
|
-
this.view.dispatch(
|
|
301
|
-
tr.insert(
|
|
302
|
-
backmatterEnd ? backmatterEnd - 1 : tr.doc.content.size,
|
|
303
|
-
createBibliographySection(node)
|
|
304
|
-
)
|
|
305
|
-
)
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return false
|
|
309
|
-
}
|
|
310
265
|
}
|
|
311
266
|
|
|
312
267
|
export default createEditableNodeView(CitationEditableView)
|
|
@@ -17,10 +17,14 @@
|
|
|
17
17
|
import {
|
|
18
18
|
CrossReferenceNode,
|
|
19
19
|
ManuscriptNodeView,
|
|
20
|
+
schema,
|
|
21
|
+
SupplementNode,
|
|
20
22
|
Target,
|
|
21
23
|
} from '@manuscripts/transform'
|
|
22
24
|
|
|
25
|
+
import { findNodeByID } from '../lib/doc'
|
|
23
26
|
import { handleEnterKey } from '../lib/navigation-utils'
|
|
27
|
+
import { getSupplementDisplayLabel } from '../lib/supplements'
|
|
24
28
|
import { objectsKey } from '../plugins/objects'
|
|
25
29
|
import { Trackable } from '../types'
|
|
26
30
|
import { BaseNodeView } from './base_node_view'
|
|
@@ -45,10 +49,20 @@ export class CrossReferenceView
|
|
|
45
49
|
super.updateContents()
|
|
46
50
|
const targets = objectsKey.getState(this.view.state) as Map<string, Target>
|
|
47
51
|
const attrs = this.node.attrs
|
|
52
|
+
const target = attrs.rids.length ? targets.get(attrs.rids[0]) : undefined
|
|
48
53
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
let derivedLabel = target?.label || ''
|
|
55
|
+
if (target?.type === schema.nodes.supplement.name && target.href) {
|
|
56
|
+
const found = findNodeByID(this.view.state.doc, target.id)
|
|
57
|
+
if (found) {
|
|
58
|
+
derivedLabel = getSupplementDisplayLabel(
|
|
59
|
+
found.node as SupplementNode,
|
|
60
|
+
this.props.getFiles()
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this.dom.textContent = attrs.label || derivedLabel
|
|
52
66
|
this.dom.addEventListener('click', this.handleClick)
|
|
53
67
|
}
|
|
54
68
|
|
|
@@ -14,11 +14,15 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
17
|
+
import { ContextMenu, ContextMenuProps } from '@manuscripts/style-guide'
|
|
18
|
+
import { isDeleted, skipTracking } from '@manuscripts/track-changes-plugin'
|
|
19
|
+
import { schema, SupplementNode, Target } from '@manuscripts/transform'
|
|
19
20
|
import { TextSelection } from 'prosemirror-state'
|
|
20
21
|
|
|
21
22
|
import { CrossReferenceItems } from '../components/views/CrossReferenceItems'
|
|
23
|
+
import { handleComment } from '../lib/comments'
|
|
24
|
+
import { findNodeByID } from '../lib/doc'
|
|
25
|
+
import { getSupplementDisplayLabel } from '../lib/supplements'
|
|
22
26
|
import { objectsKey } from '../plugins/objects'
|
|
23
27
|
import { createEditableNodeView } from './creators'
|
|
24
28
|
import { CrossReferenceView } from './cross_reference'
|
|
@@ -26,6 +30,7 @@ import ReactSubView from './ReactSubView'
|
|
|
26
30
|
|
|
27
31
|
export class CrossReferenceEditableView extends CrossReferenceView {
|
|
28
32
|
protected popperContainer: HTMLDivElement
|
|
33
|
+
protected contextMenu: HTMLElement
|
|
29
34
|
|
|
30
35
|
public selectNode = () => {
|
|
31
36
|
const { getCapabilities } = this.props
|
|
@@ -37,12 +42,20 @@ export class CrossReferenceEditableView extends CrossReferenceView {
|
|
|
37
42
|
return
|
|
38
43
|
}
|
|
39
44
|
|
|
45
|
+
this.showPicker()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public showPicker = () => {
|
|
49
|
+
const rids = this.node.attrs.rids
|
|
50
|
+
|
|
40
51
|
const componentProps = {
|
|
41
52
|
handleSelect: this.handleSelect,
|
|
42
53
|
targets: this.getTargets(),
|
|
54
|
+
files: this.props.getFiles(),
|
|
43
55
|
handleCancel: this.handleCancel,
|
|
44
56
|
currentTargetId: rids[0],
|
|
45
57
|
currentCustomLabel: this.node.attrs.label,
|
|
58
|
+
isEdit: rids.length > 0,
|
|
46
59
|
}
|
|
47
60
|
|
|
48
61
|
this.popperContainer = ReactSubView(
|
|
@@ -51,8 +64,7 @@ export class CrossReferenceEditableView extends CrossReferenceView {
|
|
|
51
64
|
componentProps,
|
|
52
65
|
this.node,
|
|
53
66
|
this.getPos,
|
|
54
|
-
this.view
|
|
55
|
-
['cross-reference-editor']
|
|
67
|
+
this.view
|
|
56
68
|
)
|
|
57
69
|
this.popperContainer.setAttribute('tabindex', '0')
|
|
58
70
|
this.props.popper.show(this.dom, this.popperContainer, 'auto')
|
|
@@ -68,13 +80,28 @@ export class CrossReferenceEditableView extends CrossReferenceView {
|
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
public getTargets = () => {
|
|
71
|
-
const excludedTypes = [schema.nodes.image_element.name]
|
|
72
|
-
|
|
73
83
|
const targets = objectsKey.getState(this.view.state) as Map<string, Target>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
const files = this.props.getFiles()
|
|
85
|
+
const fileMap = new Map(files.map((f) => [f.id, f.name]))
|
|
86
|
+
const excludedTypes = [schema.nodes.image_element.name]
|
|
87
|
+
const supplement = schema.nodes.supplement.name
|
|
88
|
+
|
|
89
|
+
return Array.from(targets.values()).reduce<Target[]>((acc, t) => {
|
|
90
|
+
if (excludedTypes.includes(t.type)) {
|
|
91
|
+
return acc
|
|
92
|
+
}
|
|
93
|
+
// Prefer caption title, then URL / file name for supplements and weblinks.
|
|
94
|
+
if (t.type === supplement && t.href) {
|
|
95
|
+
const found = findNodeByID(this.view.state.doc, t.id)
|
|
96
|
+
const label = found
|
|
97
|
+
? getSupplementDisplayLabel(found.node as SupplementNode, files)
|
|
98
|
+
: (fileMap.get(t.href) ?? t.href)
|
|
99
|
+
acc.push({ ...t, label, caption: '' })
|
|
100
|
+
} else {
|
|
101
|
+
acc.push(t)
|
|
102
|
+
}
|
|
103
|
+
return acc
|
|
104
|
+
}, [])
|
|
78
105
|
}
|
|
79
106
|
|
|
80
107
|
public handleCancel = () => {
|
|
@@ -82,7 +109,17 @@ export class CrossReferenceEditableView extends CrossReferenceView {
|
|
|
82
109
|
const { state } = this.view
|
|
83
110
|
|
|
84
111
|
const pos = this.getPos()
|
|
85
|
-
|
|
112
|
+
if (pos === undefined) {
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
const label = this.node.attrs.label
|
|
116
|
+
const tr = label
|
|
117
|
+
? state.tr.replaceWith(
|
|
118
|
+
pos,
|
|
119
|
+
pos + this.node.nodeSize,
|
|
120
|
+
state.schema.text(label)
|
|
121
|
+
)
|
|
122
|
+
: state.tr.delete(pos, pos + this.node.nodeSize)
|
|
86
123
|
tr.setSelection(TextSelection.create(tr.doc, pos))
|
|
87
124
|
skipTracking(tr)
|
|
88
125
|
this.view.dispatch(tr)
|
|
@@ -108,6 +145,81 @@ export class CrossReferenceEditableView extends CrossReferenceView {
|
|
|
108
145
|
|
|
109
146
|
this.destroy()
|
|
110
147
|
}
|
|
148
|
+
|
|
149
|
+
public handleClick = () => {
|
|
150
|
+
if (isDeleted(this.node)) {
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
if (!this.node.attrs.rids.length) {
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
this.showContextMenu()
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public showContextMenu = () => {
|
|
160
|
+
this.props.popper.destroy()
|
|
161
|
+
|
|
162
|
+
const can = this.props.getCapabilities()
|
|
163
|
+
|
|
164
|
+
const targets = objectsKey.getState(this.view.state) as Map<string, Target>
|
|
165
|
+
const rid = this.node.attrs.rids[0]
|
|
166
|
+
const isOrphaned = !targets?.get(rid)
|
|
167
|
+
|
|
168
|
+
const actions: ContextMenuProps['actions'] = [
|
|
169
|
+
{
|
|
170
|
+
label: 'Comment',
|
|
171
|
+
icon: 'AddComment',
|
|
172
|
+
action: () => {
|
|
173
|
+
this.props.popper.destroy()
|
|
174
|
+
handleComment(this.node, this.view)
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
label: 'Go to content',
|
|
179
|
+
icon: 'Scroll',
|
|
180
|
+
action: () => this.navigateToTarget(),
|
|
181
|
+
disabled: isOrphaned,
|
|
182
|
+
},
|
|
183
|
+
]
|
|
184
|
+
|
|
185
|
+
if (can?.editArticle) {
|
|
186
|
+
actions.unshift({
|
|
187
|
+
label: 'Edit',
|
|
188
|
+
icon: 'Edit',
|
|
189
|
+
action: () => this.handleEdit(),
|
|
190
|
+
disabled: isOrphaned,
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
this.contextMenu = ReactSubView(
|
|
195
|
+
this.props,
|
|
196
|
+
ContextMenu,
|
|
197
|
+
{ actions },
|
|
198
|
+
this.node,
|
|
199
|
+
this.getPos,
|
|
200
|
+
this.view,
|
|
201
|
+
['context-menu']
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
this.props.popper.show(this.dom, this.contextMenu, 'right-start', false)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private navigateToTarget = () => {
|
|
208
|
+
this.props.popper.destroy()
|
|
209
|
+
const rids = this.node.attrs.rids
|
|
210
|
+
if (!rids.length) {
|
|
211
|
+
return
|
|
212
|
+
}
|
|
213
|
+
this.props.navigate({
|
|
214
|
+
pathname: this.props.location.pathname,
|
|
215
|
+
hash: '#' + rids[0],
|
|
216
|
+
})
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private handleEdit = () => {
|
|
220
|
+
this.props.popper.destroy()
|
|
221
|
+
this.showPicker()
|
|
222
|
+
}
|
|
111
223
|
}
|
|
112
224
|
|
|
113
225
|
export default createEditableNodeView(CrossReferenceEditableView)
|
package/src/views/supplement.ts
CHANGED
|
@@ -25,7 +25,6 @@ import { Trackable } from '../types'
|
|
|
25
25
|
import { BaseNodeView } from './base_node_view'
|
|
26
26
|
import { createNodeView } from './creators'
|
|
27
27
|
|
|
28
|
-
|
|
29
28
|
export class SupplementView extends BaseNodeView<Trackable<SupplementNode>> {
|
|
30
29
|
private supplementInfoEl: HTMLDivElement
|
|
31
30
|
private static currentDragSupplementId: string | null = null
|
package/src/views/supplements.ts
CHANGED
|
@@ -32,7 +32,7 @@ export class SupplementsView extends BlockView<Trackable<SupplementsNode>> {
|
|
|
32
32
|
this.toggleButton = document.createElement('button')
|
|
33
33
|
this.toggleButton.classList.add('supplements-toggle-btn', 'button-reset')
|
|
34
34
|
this.toggleButton.innerHTML = arrowUp
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
const handleToggle = () => {
|
|
37
37
|
this.collapsed = !this.collapsed
|
|
38
38
|
this.toggleContent()
|
|
@@ -63,4 +63,4 @@ export class SupplementsView extends BlockView<Trackable<SupplementsNode>> {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export default createNodeView(SupplementsView)
|
|
66
|
+
export default createNodeView(SupplementsView)
|