@manuscripts/body-editor 1.6.13 → 1.6.14
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/citation-sources/crossref.js +27 -54
- package/dist/cjs/commands.js +3 -3
- package/dist/cjs/configs/editor-views.js +4 -4
- package/dist/cjs/lib/array-reducer.js +45 -0
- package/dist/cjs/plugins/bibliography/index.js +11 -1
- package/dist/cjs/testing/default-editor-data.js +0 -22
- package/dist/cjs/views/CitationEditorWrapper.js +65 -0
- package/dist/cjs/views/ReferencesEditor.js +50 -0
- package/dist/cjs/views/base_node_view.js +1 -1
- package/dist/cjs/views/bibliography_element.js +20 -27
- package/dist/cjs/views/citation.js +1 -72
- package/dist/cjs/views/citation_editable.js +91 -106
- package/dist/cjs/views/cross_reference_editable.js +12 -10
- package/dist/cjs/views/link_editable.js +42 -34
- package/dist/es/citation-sources/crossref.js +27 -54
- package/dist/es/commands.js +3 -3
- package/dist/es/configs/editor-views.js +4 -4
- package/dist/es/lib/array-reducer.js +41 -0
- package/dist/es/plugins/bibliography/index.js +11 -1
- package/dist/es/testing/default-editor-data.js +0 -22
- package/dist/es/views/CitationEditorWrapper.js +38 -0
- package/dist/es/views/ReferencesEditor.js +23 -0
- package/dist/es/views/base_node_view.js +1 -1
- package/dist/es/views/bibliography_element.js +21 -28
- package/dist/es/views/citation.js +1 -49
- package/dist/es/views/citation_editable.js +92 -107
- package/dist/es/views/cross_reference_editable.js +12 -10
- package/dist/es/views/editable_block.js +1 -1
- package/dist/es/views/link_editable.js +42 -34
- package/dist/types/citation-sources/crossref.d.ts +2 -11
- package/dist/types/commands.d.ts +3 -3
- package/dist/types/components/views/LinkForm.d.ts +2 -2
- package/dist/types/configs/ManuscriptsEditor.d.ts +1 -6
- package/dist/types/configs/editor-plugins.d.ts +1 -2
- package/dist/types/configs/editor-views.d.ts +1 -3
- package/dist/types/lib/array-reducer.d.ts +25 -0
- package/dist/types/lib/context-menu.d.ts +1 -1
- package/dist/types/plugins/bibliography/index.d.ts +1 -1
- package/dist/types/views/CitationEditorWrapper.d.ts +3 -0
- package/dist/types/views/ReferencesEditor.d.ts +4 -0
- package/dist/types/views/base_node_view.d.ts +0 -3
- package/dist/types/views/bibliography_element.d.ts +6 -5
- package/dist/types/views/citation.d.ts +2 -14
- package/dist/types/views/citation_editable.d.ts +12 -6
- package/dist/types/views/cross_reference.d.ts +0 -1
- package/dist/types/views/editable_block.d.ts +2 -4
- package/dist/types/views/keyword_group.d.ts +3 -15
- package/dist/types/views/link_editable.d.ts +3 -0
- package/package.json +3 -3
- package/dist/cjs/plugins/models.js +0 -48
- package/dist/cjs/views/ReactView.js +0 -94
- package/dist/es/plugins/models.js +0 -45
- package/dist/es/views/ReactView.js +0 -66
- package/dist/types/plugins/models.d.ts +0 -28
- package/dist/types/views/ReactView.d.ts +0 -33
|
@@ -16,8 +16,6 @@
|
|
|
16
16
|
import { getAllPermitted } from '@manuscripts/style-guide';
|
|
17
17
|
import { schema } from '@manuscripts/transform';
|
|
18
18
|
import { createBrowserHistory } from 'history';
|
|
19
|
-
import { uniqueId } from 'lodash';
|
|
20
|
-
import ReactDOM from 'react-dom';
|
|
21
19
|
import { PopperManager } from '../lib/popper';
|
|
22
20
|
import emptyEditorDocJson from './empty-editor-doc.json';
|
|
23
21
|
const theme = {};
|
|
@@ -64,10 +62,6 @@ export const defaultEditorProps = {
|
|
|
64
62
|
projectID: 'test-project-id',
|
|
65
63
|
getCurrentUser: () => TEST_DATA.USER,
|
|
66
64
|
history: createBrowserHistory(),
|
|
67
|
-
renderReactComponent: (child, container) => {
|
|
68
|
-
ReactDOM.render(child, container);
|
|
69
|
-
},
|
|
70
|
-
unmountReactComponent: ReactDOM.unmountComponentAtNode,
|
|
71
65
|
theme,
|
|
72
66
|
getFiles: () => [],
|
|
73
67
|
fileManagement: {
|
|
@@ -83,29 +77,13 @@ export const defaultEditorProps = {
|
|
|
83
77
|
},
|
|
84
78
|
getCitationProvider: () => undefined,
|
|
85
79
|
plugins: [],
|
|
86
|
-
saveModel: (model) => {
|
|
87
|
-
var _a, _b;
|
|
88
|
-
const id = (_a = model._id) !== null && _a !== void 0 ? _a : '';
|
|
89
|
-
const oldModel = (_b = TEST_DATA.MODEL_MAP.get(id)) !== null && _b !== void 0 ? _b : {};
|
|
90
|
-
const updatedModel = Object.assign(Object.assign({ createdAt: Date.now() / 1000, updatedAt: Date.now() / 1000, _id: uniqueId() }, oldModel), model);
|
|
91
|
-
TEST_DATA.MODEL_MAP.set(id, updatedModel);
|
|
92
|
-
return Promise.resolve(updatedModel);
|
|
93
|
-
},
|
|
94
80
|
deleteModel: (id) => {
|
|
95
81
|
TEST_DATA.MODEL_MAP.delete(id);
|
|
96
82
|
return Promise.resolve(id);
|
|
97
83
|
},
|
|
98
|
-
getLibraryItem: () => undefined,
|
|
99
|
-
setLibraryItem: () => undefined,
|
|
100
|
-
matchLibraryItemByIdentifier: () => undefined,
|
|
101
|
-
filterLibraryItems: () => Promise.resolve([]),
|
|
102
|
-
removeLibraryItem: () => undefined,
|
|
103
84
|
retrySync: () => Promise.resolve(),
|
|
104
85
|
setComment: () => undefined,
|
|
105
86
|
setSelectedComment: () => undefined,
|
|
106
87
|
setEditorSelectedSuggestion: () => undefined,
|
|
107
|
-
components: {},
|
|
108
88
|
environment: undefined,
|
|
109
|
-
setCiteprocCitations: () => undefined,
|
|
110
|
-
getCiteprocCitations: () => new Map(),
|
|
111
89
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CitationEditor } from '@manuscripts/style-guide';
|
|
2
|
+
import React, { useReducer } from 'react';
|
|
3
|
+
import { arrayReducer } from '../lib/array-reducer';
|
|
4
|
+
const itemsReducer = arrayReducer((a, b) => a._id === b._id);
|
|
5
|
+
const ridsReducer = arrayReducer();
|
|
6
|
+
export const CitationEditorWrapper = (props) => {
|
|
7
|
+
const [items, dispatchItems] = useReducer(itemsReducer, props.items);
|
|
8
|
+
const [rids, dispatchRids] = useReducer(ridsReducer, props.rids);
|
|
9
|
+
const handleSave = (item) => {
|
|
10
|
+
props.onSave(item);
|
|
11
|
+
dispatchItems({
|
|
12
|
+
type: 'update',
|
|
13
|
+
items: [item],
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
const handleDelete = (item) => {
|
|
17
|
+
props.onDelete(item);
|
|
18
|
+
dispatchItems({
|
|
19
|
+
type: 'delete',
|
|
20
|
+
item,
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const handleCite = (items) => {
|
|
24
|
+
props.onCite(items);
|
|
25
|
+
dispatchRids({
|
|
26
|
+
type: 'update',
|
|
27
|
+
items: items.map((i) => i._id),
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
const handleUncite = (rid) => {
|
|
31
|
+
props.onUncite(rid);
|
|
32
|
+
dispatchRids({
|
|
33
|
+
type: 'delete',
|
|
34
|
+
item: rid,
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
return (React.createElement(CitationEditor, Object.assign({}, props, { rids: rids, items: items, onCite: handleCite, onUncite: handleUncite, onSave: handleSave, onDelete: handleDelete })));
|
|
38
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ReferencesModal } from '@manuscripts/style-guide';
|
|
2
|
+
import React, { useReducer, useState } from 'react';
|
|
3
|
+
import { arrayReducer } from '../lib/array-reducer';
|
|
4
|
+
const itemsReducer = arrayReducer((a, b) => a._id === b._id);
|
|
5
|
+
export const ReferencesEditor = (props) => {
|
|
6
|
+
const [isOpen, setOpen] = useState(true);
|
|
7
|
+
const [items, dispatch] = useReducer(itemsReducer, props.items);
|
|
8
|
+
const handleSave = (item) => {
|
|
9
|
+
props.onSave(item);
|
|
10
|
+
dispatch({
|
|
11
|
+
type: 'update',
|
|
12
|
+
items: [item],
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
const handleDelete = (item) => {
|
|
16
|
+
props.onDelete(item);
|
|
17
|
+
dispatch({
|
|
18
|
+
type: 'delete',
|
|
19
|
+
item: item,
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
return (React.createElement(ReferencesModal, Object.assign({}, props, { isOpen: isOpen, onCancel: () => setOpen(false), items: items, onSave: handleSave, onDelete: handleDelete })));
|
|
23
|
+
};
|
|
@@ -72,7 +72,7 @@ export class BaseNodeView {
|
|
|
72
72
|
};
|
|
73
73
|
this.deleteNode = (id) => {
|
|
74
74
|
this.view.state.doc.descendants((node, pos) => {
|
|
75
|
-
if (
|
|
75
|
+
if (node.attrs.id === id) {
|
|
76
76
|
this.view.dispatch(this.view.state.tr.delete(pos, pos + node.nodeSize));
|
|
77
77
|
}
|
|
78
78
|
});
|
|
@@ -22,20 +22,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
22
22
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
-
var t = {};
|
|
27
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
-
t[p] = s[p];
|
|
29
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
-
t[p[i]] = s[p[i]];
|
|
33
|
-
}
|
|
34
|
-
return t;
|
|
35
|
-
};
|
|
36
25
|
import { CHANGE_OPERATION, CHANGE_STATUS, } from '@manuscripts/track-changes-plugin';
|
|
37
|
-
import { buildComment } from '@manuscripts/transform';
|
|
38
|
-
import React from 'react';
|
|
26
|
+
import { buildComment, Decoder, } from '@manuscripts/transform';
|
|
39
27
|
import { commentIcon, editIcon } from '../assets';
|
|
40
28
|
import { sanitize } from '../lib/dompurify';
|
|
41
29
|
import { getBibliographyPluginState } from '../plugins/bibliography';
|
|
@@ -43,25 +31,24 @@ import { commentAnnotation } from '../plugins/comment_annotation';
|
|
|
43
31
|
import { getAttrsTrackingButton, getMarkDecoration, } from '../plugins/tracking-mark';
|
|
44
32
|
import BlockView from './block_view';
|
|
45
33
|
import { createNodeView } from './creators';
|
|
34
|
+
import ReactSubView from './ReactSubView';
|
|
35
|
+
import { ReferencesEditor } from './ReferencesEditor';
|
|
46
36
|
export class BibliographyElementBlockView extends BlockView {
|
|
47
37
|
constructor() {
|
|
48
38
|
super(...arguments);
|
|
39
|
+
this.decoder = new Decoder(new Map());
|
|
49
40
|
this.gutterButtons = () => [];
|
|
50
|
-
this.showPopper = (
|
|
51
|
-
const { renderReactComponent, components: { ReferencesEditor }, } = this.props;
|
|
52
|
-
const handleSave = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
const _a = data, { _id: id, 'container-title': containerTitle, DOI: doi } = _a, rest = __rest(_a, ["_id", 'container-title', "DOI"]);
|
|
54
|
-
this.updateNodeAttrs(Object.assign({ id,
|
|
55
|
-
containerTitle,
|
|
56
|
-
doi }, rest));
|
|
57
|
-
});
|
|
58
|
-
if (!this.popperContainer) {
|
|
59
|
-
this.popperContainer = document.createElement('div');
|
|
60
|
-
this.popperContainer.className = 'references';
|
|
61
|
-
}
|
|
41
|
+
this.showPopper = (id) => {
|
|
62
42
|
const bib = getBibliographyPluginState(this.view.state);
|
|
63
|
-
|
|
64
|
-
|
|
43
|
+
const componentProps = {
|
|
44
|
+
items: Array.from(bib.bibliographyItems.values()),
|
|
45
|
+
citationCounts: bib.citationCounts,
|
|
46
|
+
item: bib.bibliographyItems.get(id),
|
|
47
|
+
onSave: this.handleSave,
|
|
48
|
+
onDelete: this.handleDelete,
|
|
49
|
+
};
|
|
50
|
+
this.editor = ReactSubView(this.props, ReferencesEditor, componentProps, this.node, this.getPos, this.view, 'references-modal');
|
|
51
|
+
this.props.popper.show(this.dom, this.editor, 'right');
|
|
65
52
|
};
|
|
66
53
|
this.stopEvent = () => true;
|
|
67
54
|
this.ignoreMutation = () => true;
|
|
@@ -106,7 +93,6 @@ export class BibliographyElementBlockView extends BlockView {
|
|
|
106
93
|
editButton.addEventListener('click', (e) => {
|
|
107
94
|
e.preventDefault();
|
|
108
95
|
this.showPopper(element.id);
|
|
109
|
-
this.popperContainer = undefined;
|
|
110
96
|
});
|
|
111
97
|
editButton.innerHTML = editIcon;
|
|
112
98
|
commentButton.innerHTML = commentIcon;
|
|
@@ -147,6 +133,13 @@ export class BibliographyElementBlockView extends BlockView {
|
|
|
147
133
|
this.dom.setAttribute('contenteditable', 'false');
|
|
148
134
|
this.dom.appendChild(this.container);
|
|
149
135
|
};
|
|
136
|
+
this.handleSave = (item) => {
|
|
137
|
+
const node = this.decoder.decode(item);
|
|
138
|
+
this.updateNodeAttrs(node.attrs);
|
|
139
|
+
};
|
|
140
|
+
this.handleDelete = (item) => {
|
|
141
|
+
return this.deleteNode(item._id);
|
|
142
|
+
};
|
|
150
143
|
}
|
|
151
144
|
}
|
|
152
145
|
export default createNodeView(BibliographyElementBlockView);
|
|
@@ -13,9 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { ObjectTypes } from '@manuscripts/json-schema';
|
|
17
16
|
import { DOMSerializer } from 'prosemirror-model';
|
|
18
|
-
import
|
|
17
|
+
import { createElement } from 'react';
|
|
19
18
|
import ReactDOM from 'react-dom';
|
|
20
19
|
import { TrackChangesReview } from '../components/track-changes/TrackChangesReview';
|
|
21
20
|
import { sanitize } from '../lib/dompurify';
|
|
@@ -27,38 +26,7 @@ import { createNodeView } from './creators';
|
|
|
27
26
|
export class CitationView extends BaseNodeView {
|
|
28
27
|
constructor() {
|
|
29
28
|
super(...arguments);
|
|
30
|
-
this.showPopper = () => {
|
|
31
|
-
const { components: { CitationViewer }, projectID, renderReactComponent, } = this.props;
|
|
32
|
-
const items = this.getBibliographyItems();
|
|
33
|
-
if (!this.popperContainer) {
|
|
34
|
-
this.popperContainer = document.createElement('div');
|
|
35
|
-
this.popperContainer.className = 'citation-editor';
|
|
36
|
-
}
|
|
37
|
-
renderReactComponent(React.createElement(CitationViewer, { items: items, projectID: projectID, scheduleUpdate: this.props.popper.update }), this.popperContainer);
|
|
38
|
-
this.props.popper.show(this.dom, this.popperContainer, 'right');
|
|
39
|
-
};
|
|
40
29
|
this.ignoreMutation = () => true;
|
|
41
|
-
this.selectNode = () => {
|
|
42
|
-
var _a;
|
|
43
|
-
const isDeleted = !!((_a = this.node.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.find(({ operation, status }) => operation === 'delete' && status !== 'rejected'));
|
|
44
|
-
if (!isDeleted) {
|
|
45
|
-
this.showPopper();
|
|
46
|
-
this.dom.classList.add('ProseMirror-selectednode');
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
this.deselectNode = () => {
|
|
50
|
-
this.dom.classList.remove('ProseMirror-selectednode');
|
|
51
|
-
this.props.popper.destroy();
|
|
52
|
-
if (this.popperContainer) {
|
|
53
|
-
this.props.unmountReactComponent(this.popperContainer);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
this.destroy = () => {
|
|
57
|
-
this.props.popper.destroy();
|
|
58
|
-
if (this.popperContainer) {
|
|
59
|
-
this.props.unmountReactComponent(this.popperContainer);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
30
|
this.initialise = () => {
|
|
63
31
|
if (!this.node.type.spec.toDOM) {
|
|
64
32
|
throw Error(`Node view ${this.node.type} doesn't have toDOM method`);
|
|
@@ -109,22 +77,6 @@ export class CitationView extends BaseNodeView {
|
|
|
109
77
|
}
|
|
110
78
|
return citation;
|
|
111
79
|
};
|
|
112
|
-
this.getBibliographyItems = () => {
|
|
113
|
-
const bib = getBibliographyPluginState(this.view.state);
|
|
114
|
-
const citation = this.node;
|
|
115
|
-
return citation.attrs.rids.map((rid) => {
|
|
116
|
-
const item = bib.bibliographyItems.get(rid);
|
|
117
|
-
if (!item) {
|
|
118
|
-
const placeholder = {
|
|
119
|
-
_id: rid,
|
|
120
|
-
objectType: ObjectTypes.BibliographyItem,
|
|
121
|
-
title: '[missing library item]',
|
|
122
|
-
};
|
|
123
|
-
return placeholder;
|
|
124
|
-
}
|
|
125
|
-
return item;
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
80
|
}
|
|
129
81
|
}
|
|
130
82
|
export default createNodeView(CitationView);
|
|
@@ -13,92 +13,92 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
-
var t = {};
|
|
27
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
-
t[p] = s[p];
|
|
29
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
-
t[p[i]] = s[p[i]];
|
|
33
|
-
}
|
|
34
|
-
return t;
|
|
35
|
-
};
|
|
36
16
|
import { ObjectTypes, } from '@manuscripts/json-schema';
|
|
37
17
|
import { findMatchingBibliographyItem } from '@manuscripts/library';
|
|
38
|
-
import {
|
|
18
|
+
import { CitationViewer, } from '@manuscripts/style-guide';
|
|
19
|
+
import { buildComment, Decoder, schema, } from '@manuscripts/transform';
|
|
39
20
|
import { TextSelection } from 'prosemirror-state';
|
|
40
|
-
import
|
|
21
|
+
import { findChildren, findChildrenByType } from 'prosemirror-utils';
|
|
22
|
+
import { crossref } from '../citation-sources';
|
|
23
|
+
import { isDeleted } from '../lib/track-changes-utils';
|
|
41
24
|
import { getBibliographyPluginState } from '../plugins/bibliography';
|
|
42
25
|
import { CitationView } from './citation';
|
|
26
|
+
import { CitationEditorWrapper } from './CitationEditorWrapper';
|
|
43
27
|
import { createEditableNodeView } from './creators';
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
schema.nodes.
|
|
28
|
+
import ReactSubView from './ReactSubView';
|
|
29
|
+
const createBibliographySection = (node) => schema.nodes.bibliography_section.createAndFill({}, [
|
|
30
|
+
schema.nodes.section_title.create({}, schema.text('Bibliography')),
|
|
31
|
+
schema.nodes.bibliography_element.create({}, node ? [node] : []),
|
|
47
32
|
]);
|
|
48
33
|
export class CitationEditableView extends CitationView {
|
|
49
34
|
constructor() {
|
|
50
35
|
super(...arguments);
|
|
36
|
+
this.decoder = new Decoder(new Map());
|
|
37
|
+
this.selectNode = () => {
|
|
38
|
+
if (!isDeleted(this.node)) {
|
|
39
|
+
this.showPopper();
|
|
40
|
+
this.dom.classList.add('ProseMirror-selectednode');
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
this.deselectNode = () => {
|
|
44
|
+
var _a;
|
|
45
|
+
(_a = this.editor) === null || _a === void 0 ? void 0 : _a.remove();
|
|
46
|
+
this.dom.classList.remove('ProseMirror-selectednode');
|
|
47
|
+
this.props.popper.destroy();
|
|
48
|
+
};
|
|
49
|
+
this.destroy = () => {
|
|
50
|
+
var _a;
|
|
51
|
+
(_a = this.editor) === null || _a === void 0 ? void 0 : _a.remove();
|
|
52
|
+
this.props.popper.destroy();
|
|
53
|
+
};
|
|
51
54
|
this.showPopper = () => {
|
|
52
|
-
const
|
|
53
|
-
const capabilities = getCapabilities();
|
|
55
|
+
const can = this.props.getCapabilities();
|
|
54
56
|
const citation = this.getCitation();
|
|
55
|
-
const
|
|
56
|
-
const updateCitation = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
this.updateNode(Object.assign(Object.assign({}, citation), data));
|
|
58
|
-
this.props.popper.update();
|
|
59
|
-
});
|
|
60
|
-
const findPosition = (doc, id) => {
|
|
61
|
-
let nodePos = undefined;
|
|
62
|
-
doc.descendants((node, pos) => {
|
|
63
|
-
if (node.attrs.id === id) {
|
|
64
|
-
nodePos = pos;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
return nodePos;
|
|
68
|
-
};
|
|
69
|
-
const handleSave = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
if (data._id && !findPosition(this.view.state.doc, data._id)) {
|
|
71
|
-
this.insertBibliographyNode(this.view, data);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
const _a = data, { _id: id, 'container-title': containerTitle, DOI: doi } = _a, rest = __rest(_a, ["_id", 'container-title', "DOI"]);
|
|
75
|
-
this.updateNodeAttrs(Object.assign({ id,
|
|
76
|
-
containerTitle,
|
|
77
|
-
doi }, rest));
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
if (!this.popperContainer) {
|
|
81
|
-
this.popperContainer = document.createElement('div');
|
|
82
|
-
this.popperContainer.className = 'citation-editor';
|
|
83
|
-
}
|
|
57
|
+
const rids = citation.embeddedCitationItems.map((i) => i.bibliographyItem);
|
|
84
58
|
const bib = getBibliographyPluginState(this.view.state);
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
59
|
+
const items = Array.from(bib.bibliographyItems.values());
|
|
60
|
+
if (can.editArticle) {
|
|
61
|
+
const query = this.node.attrs.selectedText;
|
|
62
|
+
const componentProps = {
|
|
63
|
+
query,
|
|
64
|
+
rids,
|
|
65
|
+
items,
|
|
66
|
+
citationCounts: bib.citationCounts,
|
|
67
|
+
sources: [crossref],
|
|
68
|
+
onCite: this.handleCite,
|
|
69
|
+
onUncite: this.handleUncite,
|
|
70
|
+
onSave: this.handleSave,
|
|
71
|
+
onDelete: this.handleDelete,
|
|
72
|
+
onComment: this.handleComment,
|
|
73
|
+
onCancel: this.handleCancel,
|
|
74
|
+
canEdit: can.editCitationsAndRefs,
|
|
75
|
+
};
|
|
76
|
+
this.editor = ReactSubView(this.props, CitationEditorWrapper, componentProps, this.node, this.getPos, this.view, 'citation-editor');
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const componentProps = {
|
|
80
|
+
rids,
|
|
81
|
+
items,
|
|
82
|
+
};
|
|
83
|
+
this.editor = ReactSubView(this.props, CitationViewer, componentProps, this.node, this.getPos, this.view, 'citation-editor');
|
|
84
|
+
}
|
|
85
|
+
this.props.popper.show(this.dom, this.editor, 'right');
|
|
88
86
|
};
|
|
89
|
-
this.
|
|
87
|
+
this.handleCancel = () => {
|
|
90
88
|
const selection = TextSelection.create(this.view.state.tr.doc, this.getPos() + 1);
|
|
91
89
|
this.view.dispatch(this.view.state.tr.setSelection(selection));
|
|
92
90
|
this.props.popper.destroy();
|
|
93
91
|
};
|
|
94
|
-
this.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
this.handleSave = (item) => {
|
|
93
|
+
if (item._id && !this.findPosition(item._id)) {
|
|
94
|
+
this.insertBibliographyNode(item);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const node = this.decoder.decode(item);
|
|
98
|
+
this.updateNodeAttrs(node.attrs);
|
|
99
|
+
}
|
|
100
100
|
};
|
|
101
|
-
this.
|
|
101
|
+
this.handleUncite = (id) => {
|
|
102
102
|
const citation = this.getCitation();
|
|
103
103
|
const items = citation.embeddedCitationItems.filter((i) => i.bibliographyItem !== id);
|
|
104
104
|
if (items.length > 0) {
|
|
@@ -115,23 +115,19 @@ export class CitationEditableView extends CitationView {
|
|
|
115
115
|
this.view.dispatch(tr);
|
|
116
116
|
}
|
|
117
117
|
this.props.popper.destroy();
|
|
118
|
-
});
|
|
119
|
-
this.updatePopper = () => {
|
|
120
|
-
this.props.popper.destroy();
|
|
121
|
-
window.setTimeout(() => {
|
|
122
|
-
this.showPopper();
|
|
123
|
-
}, 100);
|
|
124
118
|
};
|
|
125
|
-
this.handleCite = (items) =>
|
|
119
|
+
this.handleCite = (items) => {
|
|
126
120
|
const bib = getBibliographyPluginState(this.view.state);
|
|
127
121
|
const citation = this.getCitation();
|
|
122
|
+
const rids = citation.embeddedCitationItems.map((i) => i.bibliographyItem);
|
|
123
|
+
items = items.filter((i) => !rids.includes(i._id));
|
|
128
124
|
for (const item of items) {
|
|
129
125
|
const existingItem = findMatchingBibliographyItem(item, bib.bibliographyItems);
|
|
130
126
|
if (existingItem) {
|
|
131
127
|
item._id = existingItem._id;
|
|
132
128
|
}
|
|
133
129
|
else {
|
|
134
|
-
this.insertBibliographyNode(
|
|
130
|
+
this.insertBibliographyNode(item);
|
|
135
131
|
}
|
|
136
132
|
citation.embeddedCitationItems.push({
|
|
137
133
|
_id: '_',
|
|
@@ -140,20 +136,15 @@ export class CitationEditableView extends CitationView {
|
|
|
140
136
|
});
|
|
141
137
|
}
|
|
142
138
|
this.updateNode(citation);
|
|
143
|
-
this.
|
|
144
|
-
}
|
|
145
|
-
this.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
newItems.push(item);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return newItems;
|
|
156
|
-
});
|
|
139
|
+
this.handleCancel();
|
|
140
|
+
};
|
|
141
|
+
this.handleDelete = (item) => {
|
|
142
|
+
return this.deleteNode(item._id);
|
|
143
|
+
};
|
|
144
|
+
this.handleComment = () => {
|
|
145
|
+
const comment = buildComment(this.node.attrs.id);
|
|
146
|
+
this.props.setComment(comment);
|
|
147
|
+
};
|
|
157
148
|
this.updateNode = (citation) => {
|
|
158
149
|
const rids = citation.embeddedCitationItems.map((i) => i.bibliographyItem);
|
|
159
150
|
const { tr } = this.view.state;
|
|
@@ -162,28 +153,22 @@ export class CitationEditableView extends CitationView {
|
|
|
162
153
|
rids,
|
|
163
154
|
}));
|
|
164
155
|
};
|
|
156
|
+
this.findPosition = (id) => {
|
|
157
|
+
const doc = this.view.state.doc;
|
|
158
|
+
const children = findChildren(doc, (n) => n.attrs.id === id);
|
|
159
|
+
return children.length ? children[0] : undefined;
|
|
160
|
+
};
|
|
165
161
|
}
|
|
166
|
-
insertBibliographyNode(
|
|
167
|
-
const { doc, tr } = view.state;
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (node.type === schema.nodes.bibliography_element) {
|
|
173
|
-
bibElement = node;
|
|
174
|
-
pos = nodePos;
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
let newTr;
|
|
178
|
-
const bibItem = schema.nodes.bibliography_item.create(Object.assign({ id: item._id, doi,
|
|
179
|
-
containerTitle }, restAttr));
|
|
180
|
-
if (bibElement && pos) {
|
|
181
|
-
newTr = tr.insert(pos + 1, bibItem);
|
|
162
|
+
insertBibliographyNode(item) {
|
|
163
|
+
const { doc, tr } = this.view.state;
|
|
164
|
+
const elements = findChildrenByType(doc, schema.nodes.bibliography_element, true);
|
|
165
|
+
const node = this.decoder.decode(item);
|
|
166
|
+
if (elements.length) {
|
|
167
|
+
this.view.dispatch(tr.insert(elements[0].pos + 1, node));
|
|
182
168
|
}
|
|
183
169
|
else {
|
|
184
|
-
|
|
170
|
+
this.view.dispatch(tr.insert(tr.doc.content.size, createBibliographySection(node)));
|
|
185
171
|
}
|
|
186
|
-
view.dispatch(newTr);
|
|
187
172
|
return false;
|
|
188
173
|
}
|
|
189
174
|
}
|
|
@@ -24,34 +24,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
24
24
|
};
|
|
25
25
|
import { skipTracking } from '@manuscripts/track-changes-plugin';
|
|
26
26
|
import { TextSelection } from 'prosemirror-state';
|
|
27
|
-
import React from 'react';
|
|
28
27
|
import { CrossReferenceItems } from '../components/views/CrossReferenceItems';
|
|
29
28
|
import { objectsKey } from '../plugins/objects';
|
|
30
29
|
import { createEditableNodeView } from './creators';
|
|
31
30
|
import { CrossReferenceView } from './cross_reference';
|
|
31
|
+
import ReactSubView from './ReactSubView';
|
|
32
32
|
export class CrossReferenceEditableView extends CrossReferenceView {
|
|
33
33
|
constructor() {
|
|
34
34
|
super(...arguments);
|
|
35
35
|
this.selectNode = () => {
|
|
36
|
-
const { getCapabilities
|
|
36
|
+
const { getCapabilities } = this.props;
|
|
37
37
|
const xref = this.node;
|
|
38
38
|
const rids = xref.attrs.rids;
|
|
39
39
|
const can = getCapabilities();
|
|
40
40
|
if (!(can === null || can === void 0 ? void 0 : can.editArticle) || rids.length) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
const componentProps = {
|
|
44
|
+
handleSelect: this.handleSelect,
|
|
45
|
+
targets: this.getTargets(),
|
|
46
|
+
handleCancel: this.handleCancel,
|
|
47
|
+
currentTargetId: rids[0],
|
|
48
|
+
currentCustomLabel: this.node.attrs.customLabel,
|
|
49
|
+
};
|
|
50
|
+
this.popperContainer = ReactSubView(this.props, CrossReferenceItems, componentProps, this.node, this.getPos, this.view, 'cross-reference-editor');
|
|
48
51
|
this.props.popper.show(this.dom, this.popperContainer, 'right');
|
|
49
52
|
};
|
|
50
53
|
this.destroy = () => {
|
|
54
|
+
var _a;
|
|
51
55
|
this.props.popper.destroy();
|
|
52
|
-
|
|
53
|
-
this.props.unmountReactComponent(this.popperContainer);
|
|
54
|
-
}
|
|
56
|
+
(_a = this.popperContainer) === null || _a === void 0 ? void 0 : _a.remove();
|
|
55
57
|
};
|
|
56
58
|
this.deselectNode = () => {
|
|
57
59
|
this.handleCancel();
|
|
@@ -22,7 +22,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
22
22
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
|
-
import { nodeNames, schema
|
|
25
|
+
import { nodeNames, schema } from '@manuscripts/transform';
|
|
26
26
|
import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils';
|
|
27
27
|
import { ContextMenu } from '../lib/context-menu';
|
|
28
28
|
const isNotNull = (a) => a !== null;
|