@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
|
@@ -14,26 +14,6 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
27
|
-
var t = {};
|
|
28
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
29
|
-
t[p] = s[p];
|
|
30
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
31
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
32
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
33
|
-
t[p[i]] = s[p[i]];
|
|
34
|
-
}
|
|
35
|
-
return t;
|
|
36
|
-
};
|
|
37
17
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
38
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
19
|
};
|
|
@@ -41,70 +21,90 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
41
21
|
exports.CitationEditableView = void 0;
|
|
42
22
|
const json_schema_1 = require("@manuscripts/json-schema");
|
|
43
23
|
const library_1 = require("@manuscripts/library");
|
|
24
|
+
const style_guide_1 = require("@manuscripts/style-guide");
|
|
44
25
|
const transform_1 = require("@manuscripts/transform");
|
|
45
26
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
46
|
-
const
|
|
27
|
+
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
28
|
+
const citation_sources_1 = require("../citation-sources");
|
|
29
|
+
const track_changes_utils_1 = require("../lib/track-changes-utils");
|
|
47
30
|
const bibliography_1 = require("../plugins/bibliography");
|
|
48
31
|
const citation_1 = require("./citation");
|
|
32
|
+
const CitationEditorWrapper_1 = require("./CitationEditorWrapper");
|
|
49
33
|
const creators_1 = require("./creators");
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
transform_1.schema.nodes.
|
|
34
|
+
const ReactSubView_1 = __importDefault(require("./ReactSubView"));
|
|
35
|
+
const createBibliographySection = (node) => transform_1.schema.nodes.bibliography_section.createAndFill({}, [
|
|
36
|
+
transform_1.schema.nodes.section_title.create({}, transform_1.schema.text('Bibliography')),
|
|
37
|
+
transform_1.schema.nodes.bibliography_element.create({}, node ? [node] : []),
|
|
53
38
|
]);
|
|
54
39
|
class CitationEditableView extends citation_1.CitationView {
|
|
55
40
|
constructor() {
|
|
56
41
|
super(...arguments);
|
|
42
|
+
this.decoder = new transform_1.Decoder(new Map());
|
|
43
|
+
this.selectNode = () => {
|
|
44
|
+
if (!(0, track_changes_utils_1.isDeleted)(this.node)) {
|
|
45
|
+
this.showPopper();
|
|
46
|
+
this.dom.classList.add('ProseMirror-selectednode');
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
this.deselectNode = () => {
|
|
50
|
+
var _a;
|
|
51
|
+
(_a = this.editor) === null || _a === void 0 ? void 0 : _a.remove();
|
|
52
|
+
this.dom.classList.remove('ProseMirror-selectednode');
|
|
53
|
+
this.props.popper.destroy();
|
|
54
|
+
};
|
|
55
|
+
this.destroy = () => {
|
|
56
|
+
var _a;
|
|
57
|
+
(_a = this.editor) === null || _a === void 0 ? void 0 : _a.remove();
|
|
58
|
+
this.props.popper.destroy();
|
|
59
|
+
};
|
|
57
60
|
this.showPopper = () => {
|
|
58
|
-
const
|
|
59
|
-
const capabilities = getCapabilities();
|
|
61
|
+
const can = this.props.getCapabilities();
|
|
60
62
|
const citation = this.getCitation();
|
|
61
|
-
const
|
|
62
|
-
const updateCitation = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
this.updateNode(Object.assign(Object.assign({}, citation), data));
|
|
64
|
-
this.props.popper.update();
|
|
65
|
-
});
|
|
66
|
-
const findPosition = (doc, id) => {
|
|
67
|
-
let nodePos = undefined;
|
|
68
|
-
doc.descendants((node, pos) => {
|
|
69
|
-
if (node.attrs.id === id) {
|
|
70
|
-
nodePos = pos;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
return nodePos;
|
|
74
|
-
};
|
|
75
|
-
const handleSave = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
if (data._id && !findPosition(this.view.state.doc, data._id)) {
|
|
77
|
-
this.insertBibliographyNode(this.view, data);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
const _a = data, { _id: id, 'container-title': containerTitle, DOI: doi } = _a, rest = __rest(_a, ["_id", 'container-title', "DOI"]);
|
|
81
|
-
this.updateNodeAttrs(Object.assign({ id,
|
|
82
|
-
containerTitle,
|
|
83
|
-
doi }, rest));
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
if (!this.popperContainer) {
|
|
87
|
-
this.popperContainer = document.createElement('div');
|
|
88
|
-
this.popperContainer.className = 'citation-editor';
|
|
89
|
-
}
|
|
63
|
+
const rids = citation.embeddedCitationItems.map((i) => i.bibliographyItem);
|
|
90
64
|
const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
65
|
+
const items = Array.from(bib.bibliographyItems.values());
|
|
66
|
+
if (can.editArticle) {
|
|
67
|
+
const query = this.node.attrs.selectedText;
|
|
68
|
+
const componentProps = {
|
|
69
|
+
query,
|
|
70
|
+
rids,
|
|
71
|
+
items,
|
|
72
|
+
citationCounts: bib.citationCounts,
|
|
73
|
+
sources: [citation_sources_1.crossref],
|
|
74
|
+
onCite: this.handleCite,
|
|
75
|
+
onUncite: this.handleUncite,
|
|
76
|
+
onSave: this.handleSave,
|
|
77
|
+
onDelete: this.handleDelete,
|
|
78
|
+
onComment: this.handleComment,
|
|
79
|
+
onCancel: this.handleCancel,
|
|
80
|
+
canEdit: can.editCitationsAndRefs,
|
|
81
|
+
};
|
|
82
|
+
this.editor = (0, ReactSubView_1.default)(this.props, CitationEditorWrapper_1.CitationEditorWrapper, componentProps, this.node, this.getPos, this.view, 'citation-editor');
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const componentProps = {
|
|
86
|
+
rids,
|
|
87
|
+
items,
|
|
88
|
+
};
|
|
89
|
+
this.editor = (0, ReactSubView_1.default)(this.props, style_guide_1.CitationViewer, componentProps, this.node, this.getPos, this.view, 'citation-editor');
|
|
90
|
+
}
|
|
91
|
+
this.props.popper.show(this.dom, this.editor, 'right');
|
|
94
92
|
};
|
|
95
|
-
this.
|
|
93
|
+
this.handleCancel = () => {
|
|
96
94
|
const selection = prosemirror_state_1.TextSelection.create(this.view.state.tr.doc, this.getPos() + 1);
|
|
97
95
|
this.view.dispatch(this.view.state.tr.setSelection(selection));
|
|
98
96
|
this.props.popper.destroy();
|
|
99
97
|
};
|
|
100
|
-
this.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
this.handleSave = (item) => {
|
|
99
|
+
if (item._id && !this.findPosition(item._id)) {
|
|
100
|
+
this.insertBibliographyNode(item);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const node = this.decoder.decode(item);
|
|
104
|
+
this.updateNodeAttrs(node.attrs);
|
|
105
|
+
}
|
|
106
106
|
};
|
|
107
|
-
this.
|
|
107
|
+
this.handleUncite = (id) => {
|
|
108
108
|
const citation = this.getCitation();
|
|
109
109
|
const items = citation.embeddedCitationItems.filter((i) => i.bibliographyItem !== id);
|
|
110
110
|
if (items.length > 0) {
|
|
@@ -121,23 +121,19 @@ class CitationEditableView extends citation_1.CitationView {
|
|
|
121
121
|
this.view.dispatch(tr);
|
|
122
122
|
}
|
|
123
123
|
this.props.popper.destroy();
|
|
124
|
-
});
|
|
125
|
-
this.updatePopper = () => {
|
|
126
|
-
this.props.popper.destroy();
|
|
127
|
-
window.setTimeout(() => {
|
|
128
|
-
this.showPopper();
|
|
129
|
-
}, 100);
|
|
130
124
|
};
|
|
131
|
-
this.handleCite = (items) =>
|
|
125
|
+
this.handleCite = (items) => {
|
|
132
126
|
const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
|
|
133
127
|
const citation = this.getCitation();
|
|
128
|
+
const rids = citation.embeddedCitationItems.map((i) => i.bibliographyItem);
|
|
129
|
+
items = items.filter((i) => !rids.includes(i._id));
|
|
134
130
|
for (const item of items) {
|
|
135
131
|
const existingItem = (0, library_1.findMatchingBibliographyItem)(item, bib.bibliographyItems);
|
|
136
132
|
if (existingItem) {
|
|
137
133
|
item._id = existingItem._id;
|
|
138
134
|
}
|
|
139
135
|
else {
|
|
140
|
-
this.insertBibliographyNode(
|
|
136
|
+
this.insertBibliographyNode(item);
|
|
141
137
|
}
|
|
142
138
|
citation.embeddedCitationItems.push({
|
|
143
139
|
_id: '_',
|
|
@@ -146,20 +142,15 @@ class CitationEditableView extends citation_1.CitationView {
|
|
|
146
142
|
});
|
|
147
143
|
}
|
|
148
144
|
this.updateNode(citation);
|
|
149
|
-
this.
|
|
150
|
-
}
|
|
151
|
-
this.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
newItems.push(item);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return newItems;
|
|
162
|
-
});
|
|
145
|
+
this.handleCancel();
|
|
146
|
+
};
|
|
147
|
+
this.handleDelete = (item) => {
|
|
148
|
+
return this.deleteNode(item._id);
|
|
149
|
+
};
|
|
150
|
+
this.handleComment = () => {
|
|
151
|
+
const comment = (0, transform_1.buildComment)(this.node.attrs.id);
|
|
152
|
+
this.props.setComment(comment);
|
|
153
|
+
};
|
|
163
154
|
this.updateNode = (citation) => {
|
|
164
155
|
const rids = citation.embeddedCitationItems.map((i) => i.bibliographyItem);
|
|
165
156
|
const { tr } = this.view.state;
|
|
@@ -168,28 +159,22 @@ class CitationEditableView extends citation_1.CitationView {
|
|
|
168
159
|
rids,
|
|
169
160
|
}));
|
|
170
161
|
};
|
|
162
|
+
this.findPosition = (id) => {
|
|
163
|
+
const doc = this.view.state.doc;
|
|
164
|
+
const children = (0, prosemirror_utils_1.findChildren)(doc, (n) => n.attrs.id === id);
|
|
165
|
+
return children.length ? children[0] : undefined;
|
|
166
|
+
};
|
|
171
167
|
}
|
|
172
|
-
insertBibliographyNode(
|
|
173
|
-
const { doc, tr } = view.state;
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (node.type === transform_1.schema.nodes.bibliography_element) {
|
|
179
|
-
bibElement = node;
|
|
180
|
-
pos = nodePos;
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
let newTr;
|
|
184
|
-
const bibItem = transform_1.schema.nodes.bibliography_item.create(Object.assign({ id: item._id, doi,
|
|
185
|
-
containerTitle }, restAttr));
|
|
186
|
-
if (bibElement && pos) {
|
|
187
|
-
newTr = tr.insert(pos + 1, bibItem);
|
|
168
|
+
insertBibliographyNode(item) {
|
|
169
|
+
const { doc, tr } = this.view.state;
|
|
170
|
+
const elements = (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.bibliography_element, true);
|
|
171
|
+
const node = this.decoder.decode(item);
|
|
172
|
+
if (elements.length) {
|
|
173
|
+
this.view.dispatch(tr.insert(elements[0].pos + 1, node));
|
|
188
174
|
}
|
|
189
175
|
else {
|
|
190
|
-
|
|
176
|
+
this.view.dispatch(tr.insert(tr.doc.content.size, createBibliographySection(node)));
|
|
191
177
|
}
|
|
192
|
-
view.dispatch(newTr);
|
|
193
178
|
return false;
|
|
194
179
|
}
|
|
195
180
|
}
|
|
@@ -30,34 +30,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
30
30
|
exports.CrossReferenceEditableView = void 0;
|
|
31
31
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
32
32
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
33
|
-
const react_1 = __importDefault(require("react"));
|
|
34
33
|
const CrossReferenceItems_1 = require("../components/views/CrossReferenceItems");
|
|
35
34
|
const objects_1 = require("../plugins/objects");
|
|
36
35
|
const creators_1 = require("./creators");
|
|
37
36
|
const cross_reference_1 = require("./cross_reference");
|
|
37
|
+
const ReactSubView_1 = __importDefault(require("./ReactSubView"));
|
|
38
38
|
class CrossReferenceEditableView extends cross_reference_1.CrossReferenceView {
|
|
39
39
|
constructor() {
|
|
40
40
|
super(...arguments);
|
|
41
41
|
this.selectNode = () => {
|
|
42
|
-
const { getCapabilities
|
|
42
|
+
const { getCapabilities } = this.props;
|
|
43
43
|
const xref = this.node;
|
|
44
44
|
const rids = xref.attrs.rids;
|
|
45
45
|
const can = getCapabilities();
|
|
46
46
|
if (!(can === null || can === void 0 ? void 0 : can.editArticle) || rids.length) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
const componentProps = {
|
|
50
|
+
handleSelect: this.handleSelect,
|
|
51
|
+
targets: this.getTargets(),
|
|
52
|
+
handleCancel: this.handleCancel,
|
|
53
|
+
currentTargetId: rids[0],
|
|
54
|
+
currentCustomLabel: this.node.attrs.customLabel,
|
|
55
|
+
};
|
|
56
|
+
this.popperContainer = (0, ReactSubView_1.default)(this.props, CrossReferenceItems_1.CrossReferenceItems, componentProps, this.node, this.getPos, this.view, 'cross-reference-editor');
|
|
54
57
|
this.props.popper.show(this.dom, this.popperContainer, 'right');
|
|
55
58
|
};
|
|
56
59
|
this.destroy = () => {
|
|
60
|
+
var _a;
|
|
57
61
|
this.props.popper.destroy();
|
|
58
|
-
|
|
59
|
-
this.props.unmountReactComponent(this.popperContainer);
|
|
60
|
-
}
|
|
62
|
+
(_a = this.popperContainer) === null || _a === void 0 ? void 0 : _a.remove();
|
|
61
63
|
};
|
|
62
64
|
this.deselectNode = () => {
|
|
63
65
|
this.handleCancel();
|
|
@@ -20,10 +20,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.LinkEditableView = void 0;
|
|
22
22
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
23
|
-
const react_1 = __importDefault(require("react"));
|
|
24
23
|
const LinkForm_1 = require("../components/views/LinkForm");
|
|
25
24
|
const creators_1 = require("./creators");
|
|
26
25
|
const link_1 = require("./link");
|
|
26
|
+
const ReactSubView_1 = __importDefault(require("./ReactSubView"));
|
|
27
27
|
class LinkEditableView extends link_1.LinkView {
|
|
28
28
|
constructor() {
|
|
29
29
|
super(...arguments);
|
|
@@ -52,43 +52,51 @@ class LinkEditableView extends link_1.LinkView {
|
|
|
52
52
|
title: this.node.attrs.title,
|
|
53
53
|
text: this.node.textContent,
|
|
54
54
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}, handleRemove: () => {
|
|
63
|
-
const { tr } = this.view.state;
|
|
64
|
-
const pos = this.getPos();
|
|
65
|
-
const to = pos + this.node.nodeSize;
|
|
66
|
-
tr.replaceWith(pos, to, this.node.content).setSelection(prosemirror_state_1.TextSelection.create(tr.doc, pos));
|
|
67
|
-
this.view.focus();
|
|
68
|
-
this.view.dispatch(tr);
|
|
69
|
-
this.closeForm();
|
|
70
|
-
}, handleSave: (data) => {
|
|
71
|
-
const tr = this.view.state.tr;
|
|
72
|
-
const pos = this.getPos();
|
|
73
|
-
if (data.href !== originalValue.href ||
|
|
74
|
-
data.title !== originalValue.title) {
|
|
75
|
-
tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { href: data.href, title: data.title }));
|
|
76
|
-
}
|
|
77
|
-
if (data.text !== originalValue.text) {
|
|
78
|
-
tr.insertText(data.text, pos + 1, pos + this.node.nodeSize - 1);
|
|
79
|
-
}
|
|
80
|
-
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, pos));
|
|
81
|
-
this.view.focus();
|
|
82
|
-
this.view.dispatch(tr);
|
|
83
|
-
this.closeForm();
|
|
84
|
-
} }), this.popperContainer);
|
|
55
|
+
const componentProps = {
|
|
56
|
+
value: originalValue,
|
|
57
|
+
handleCancel: this.handleCancel,
|
|
58
|
+
handleRemove: this.handleRemove,
|
|
59
|
+
handleSave: this.handleSave,
|
|
60
|
+
};
|
|
61
|
+
this.popperContainer = (0, ReactSubView_1.default)(this.props, LinkForm_1.LinkForm, componentProps, this.node, this.getPos, this.view);
|
|
85
62
|
this.props.popper.show(this.dom, this.popperContainer, 'bottom');
|
|
86
63
|
};
|
|
64
|
+
this.handleCancel = () => {
|
|
65
|
+
const tr = this.view.state.tr;
|
|
66
|
+
const pos = this.getPos();
|
|
67
|
+
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, pos));
|
|
68
|
+
this.view.focus();
|
|
69
|
+
this.view.dispatch(tr);
|
|
70
|
+
this.closeForm();
|
|
71
|
+
};
|
|
72
|
+
this.handleRemove = () => {
|
|
73
|
+
const tr = this.view.state.tr;
|
|
74
|
+
const pos = this.getPos();
|
|
75
|
+
const to = pos + this.node.nodeSize;
|
|
76
|
+
tr.replaceWith(pos, to, this.node.content).setSelection(prosemirror_state_1.TextSelection.create(tr.doc, pos));
|
|
77
|
+
this.view.focus();
|
|
78
|
+
this.view.dispatch(tr);
|
|
79
|
+
this.closeForm();
|
|
80
|
+
};
|
|
81
|
+
this.handleSave = (value) => {
|
|
82
|
+
const tr = this.view.state.tr;
|
|
83
|
+
const link = this.node;
|
|
84
|
+
const pos = this.getPos();
|
|
85
|
+
if (value.href !== link.attrs.href || value.title !== link.attrs.title) {
|
|
86
|
+
tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { href: value.href, title: value.title }));
|
|
87
|
+
}
|
|
88
|
+
if (value.text !== link.textContent) {
|
|
89
|
+
tr.insertText(value.text, pos + 1, pos + this.node.nodeSize - 1);
|
|
90
|
+
}
|
|
91
|
+
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, pos));
|
|
92
|
+
this.view.focus();
|
|
93
|
+
this.view.dispatch(tr);
|
|
94
|
+
this.closeForm();
|
|
95
|
+
};
|
|
87
96
|
this.closeForm = () => {
|
|
97
|
+
var _a;
|
|
88
98
|
this.props.popper.destroy();
|
|
89
|
-
|
|
90
|
-
this.props.unmountReactComponent(this.popperContainer);
|
|
91
|
-
}
|
|
99
|
+
(_a = this.popperContainer) === null || _a === void 0 ? void 0 : _a.remove();
|
|
92
100
|
};
|
|
93
101
|
}
|
|
94
102
|
}
|
|
@@ -13,66 +13,39 @@
|
|
|
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
16
|
import { convertCSLToBibliographyItem } from '@manuscripts/library';
|
|
17
|
+
import { buildBibliographyItem } from '@manuscripts/transform';
|
|
26
18
|
import axios from 'axios';
|
|
27
|
-
const search = (query,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const response = yield axios.get(`https://api.crossref.org/works?mailto=${mailto}`, {
|
|
19
|
+
const search = (query, limit) => {
|
|
20
|
+
const controller = new AbortController();
|
|
21
|
+
const response = axios
|
|
22
|
+
.get(`https://api.crossref.org/works`, {
|
|
32
23
|
params: {
|
|
33
24
|
filter: 'type:journal-article',
|
|
34
25
|
query,
|
|
35
|
-
rows,
|
|
26
|
+
rows: limit,
|
|
36
27
|
},
|
|
37
|
-
|
|
28
|
+
signal: controller.signal,
|
|
29
|
+
})
|
|
30
|
+
.then((r) => {
|
|
31
|
+
if (r.status !== 200) {
|
|
32
|
+
throw new Error('There was a problem searching for this query.');
|
|
33
|
+
}
|
|
34
|
+
const items = r.data.message.items;
|
|
35
|
+
const total = r.data.message['total-results'];
|
|
36
|
+
return {
|
|
37
|
+
items: items.map((i) => buildBibliographyItem(convertCSLToBibliographyItem(i))),
|
|
38
|
+
total,
|
|
39
|
+
};
|
|
38
40
|
});
|
|
39
|
-
if (response.status !== 200) {
|
|
40
|
-
throw new Error('There was a problem searching for this query.');
|
|
41
|
-
}
|
|
42
|
-
const { message: { items, 'total-results': total }, } = response.data;
|
|
43
|
-
return {
|
|
44
|
-
items: items.map(convertCSLToBibliographyItem),
|
|
45
|
-
total,
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
const searchByDOI = (doi, mailto) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
-
const response = yield axios.get(`https://api.crossref.org/works/${encodeURIComponent(doi)}?mailto=${mailto}`);
|
|
50
|
-
if (response.status === 404) {
|
|
51
|
-
throw new Error('An item with this DOI could not be found.');
|
|
52
|
-
}
|
|
53
|
-
if (response.status !== 200) {
|
|
54
|
-
throw new Error('There was a problem searching for this DOI.');
|
|
55
|
-
}
|
|
56
|
-
const { message } = response.data;
|
|
57
|
-
const item = convertCSLToBibliographyItem(message);
|
|
58
41
|
return {
|
|
59
|
-
|
|
60
|
-
|
|
42
|
+
response: response,
|
|
43
|
+
cancel: () => controller.abort(),
|
|
44
|
+
isCancelled: controller.signal.aborted,
|
|
61
45
|
};
|
|
62
|
-
}
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
headers: {},
|
|
69
|
-
});
|
|
70
|
-
if (response.status === 404) {
|
|
71
|
-
throw new Error('An item with this DOI could not be found.');
|
|
72
|
-
}
|
|
73
|
-
if (response.status !== 200) {
|
|
74
|
-
throw new Error('There was a problem fetching this DOI.');
|
|
75
|
-
}
|
|
76
|
-
return convertCSLToBibliographyItem(response.data);
|
|
77
|
-
});
|
|
78
|
-
export const crossref = { fetch, search };
|
|
46
|
+
};
|
|
47
|
+
export const crossref = {
|
|
48
|
+
id: 'crossref',
|
|
49
|
+
label: 'External sources',
|
|
50
|
+
search,
|
|
51
|
+
};
|
package/dist/es/commands.js
CHANGED
|
@@ -219,7 +219,7 @@ export const insertLink = (state, dispatch) => {
|
|
|
219
219
|
}
|
|
220
220
|
return true;
|
|
221
221
|
};
|
|
222
|
-
export const insertInlineCitation = (state, dispatch
|
|
222
|
+
export const insertInlineCitation = (state, dispatch) => {
|
|
223
223
|
const node = state.schema.nodes.citation.create({
|
|
224
224
|
id: generateID(ObjectTypes.Citation),
|
|
225
225
|
rids: [],
|
|
@@ -374,10 +374,10 @@ export const insertList = (type, style) => (state, dispatch) => {
|
|
|
374
374
|
return skipCommandTracking(command)(state, dispatch);
|
|
375
375
|
}
|
|
376
376
|
};
|
|
377
|
-
export const insertBibliographySection = (
|
|
377
|
+
export const insertBibliographySection = () => {
|
|
378
378
|
return false;
|
|
379
379
|
};
|
|
380
|
-
export const insertTOCSection = (
|
|
380
|
+
export const insertTOCSection = () => {
|
|
381
381
|
return false;
|
|
382
382
|
};
|
|
383
383
|
export const ifInTableBody = (command) => (state) => {
|
|
@@ -47,11 +47,11 @@ import tocElement from '../views/toc_element_editable';
|
|
|
47
47
|
export default (props, dispatch) => {
|
|
48
48
|
return {
|
|
49
49
|
title: title(props, dispatch),
|
|
50
|
-
bibliography_element: bibliographyElement(props),
|
|
50
|
+
bibliography_element: bibliographyElement(props, dispatch),
|
|
51
51
|
blockquote_element: blockquoteElement(props),
|
|
52
52
|
bullet_list: bulletList(props),
|
|
53
|
-
citation: citation(props),
|
|
54
|
-
cross_reference: crossReference(props),
|
|
53
|
+
citation: citation(props, dispatch),
|
|
54
|
+
cross_reference: crossReference(props, dispatch),
|
|
55
55
|
contributors: contributorsSection(props, dispatch),
|
|
56
56
|
equation: equation(props),
|
|
57
57
|
equation_element: equationElement(props),
|
|
@@ -63,7 +63,7 @@ export default (props, dispatch) => {
|
|
|
63
63
|
inline_footnote: inlineFootnote(props),
|
|
64
64
|
keyword: keyword(props, dispatch),
|
|
65
65
|
keyword_group: keywordGroup(props, dispatch),
|
|
66
|
-
link: link(props),
|
|
66
|
+
link: link(props, dispatch),
|
|
67
67
|
listing: listing(props),
|
|
68
68
|
listing_element: listingElement(props),
|
|
69
69
|
ordered_list: orderedList(props),
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2024 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
|
+
export const arrayReducer = (isEqual = (a, b) => a === b) => {
|
|
17
|
+
return (state, action) => {
|
|
18
|
+
const handleUpdate = (state, items) => {
|
|
19
|
+
const copy = [...state];
|
|
20
|
+
items.forEach((item) => {
|
|
21
|
+
const index = copy.findIndex((i) => isEqual(item, i));
|
|
22
|
+
if (index >= 0) {
|
|
23
|
+
copy[index] = item;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
copy.push(item);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return copy;
|
|
30
|
+
};
|
|
31
|
+
const handleDelete = (state, item) => {
|
|
32
|
+
return state.filter((i) => !isEqual(item, i));
|
|
33
|
+
};
|
|
34
|
+
switch (action.type) {
|
|
35
|
+
case 'update':
|
|
36
|
+
return handleUpdate(state, action.items);
|
|
37
|
+
case 'delete':
|
|
38
|
+
return handleDelete(state, action.item);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -60,17 +60,27 @@ const buildBibliographyPluginState = (doc, csl, $old) => {
|
|
|
60
60
|
if (!csl.style) {
|
|
61
61
|
return $new;
|
|
62
62
|
}
|
|
63
|
-
if ($old &&
|
|
63
|
+
if ($old &&
|
|
64
|
+
isEqual(citations, $old.citations) &&
|
|
65
|
+
isEqual(modelMap, $old.bibliographyItems)) {
|
|
66
|
+
$new.citationCounts = $old.citationCounts;
|
|
64
67
|
$new.provider = $old.provider;
|
|
65
68
|
$new.renderedCitations = $old.renderedCitations;
|
|
66
69
|
}
|
|
67
70
|
else {
|
|
71
|
+
const citationCounts = new Map();
|
|
72
|
+
const rids = nodes.flatMap((e) => e[0].attrs.rids);
|
|
73
|
+
rids.forEach((rid) => {
|
|
74
|
+
const count = citationCounts.get(rid) || 0;
|
|
75
|
+
citationCounts.set(rid, count + 1);
|
|
76
|
+
});
|
|
68
77
|
const provider = new CitationProvider({
|
|
69
78
|
getLibraryItem: (id) => modelMap.get(id),
|
|
70
79
|
citationStyle: csl.style || '',
|
|
71
80
|
locale: csl.locale,
|
|
72
81
|
});
|
|
73
82
|
const citationTexts = provider.rebuildState(buildCitations(nodes));
|
|
83
|
+
$new.citationCounts = citationCounts;
|
|
74
84
|
$new.provider = provider;
|
|
75
85
|
$new.renderedCitations = new Map(citationTexts.map((i) => [i[0], i[2]]));
|
|
76
86
|
}
|