@manuscripts/body-editor 1.2.21 → 1.2.22-LEAN-2143-v2
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/views/bibliography_item.js +7 -4
- package/dist/cjs/views/citation.js +35 -3
- package/dist/cjs/views/citation_editable.js +1 -1
- package/dist/es/views/bibliography_item.js +7 -4
- package/dist/es/views/citation.js +35 -3
- package/dist/es/views/citation_editable.js +1 -1
- package/dist/types/views/base_node_view.d.ts +1 -0
- package/dist/types/views/citation.d.ts +1 -1
- package/package.json +4 -4
- package/styles/AdvancedEditor.css +7 -0
|
@@ -82,15 +82,17 @@ class BibliographyItemView extends base_node_view_1.BaseNodeView {
|
|
|
82
82
|
this.dom.innerHTML = '';
|
|
83
83
|
this.dom.appendChild(fragment);
|
|
84
84
|
const doubleButton = document.createElement('div');
|
|
85
|
-
const editButton = document.createElement('
|
|
86
|
-
const commentButton = document.createElement('
|
|
85
|
+
const editButton = document.createElement('button');
|
|
86
|
+
const commentButton = document.createElement('button');
|
|
87
87
|
doubleButton.className = 'bibliography-double-button';
|
|
88
88
|
editButton.className = 'bibliography-edit-button';
|
|
89
89
|
commentButton.className = 'bibliography-comment-button';
|
|
90
|
-
commentButton.addEventListener('click', () => {
|
|
90
|
+
commentButton.addEventListener('click', (e) => {
|
|
91
|
+
e.preventDefault();
|
|
91
92
|
this.props.setComment((0, transform_1.buildComment)(this.node.attrs.id));
|
|
92
93
|
});
|
|
93
|
-
editButton.addEventListener('click', () => {
|
|
94
|
+
editButton.addEventListener('click', (e) => {
|
|
95
|
+
e.preventDefault();
|
|
94
96
|
this.showPopper(this.node.attrs.id);
|
|
95
97
|
this.popperContainer = undefined;
|
|
96
98
|
});
|
|
@@ -100,6 +102,7 @@ class BibliographyItemView extends base_node_view_1.BaseNodeView {
|
|
|
100
102
|
if (this.props.getCapabilities().seeReferencesButtons) {
|
|
101
103
|
this.dom.appendChild(doubleButton);
|
|
102
104
|
}
|
|
105
|
+
editButton.disabled = !this.props.getCapabilities().editCitationsAndRefs;
|
|
103
106
|
}
|
|
104
107
|
catch (e) {
|
|
105
108
|
console.error(e);
|
|
@@ -14,17 +14,34 @@
|
|
|
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
|
+
};
|
|
17
26
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
28
|
};
|
|
20
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
30
|
exports.CitationView = void 0;
|
|
22
31
|
const json_schema_1 = require("@manuscripts/json-schema");
|
|
32
|
+
const library_1 = require("@manuscripts/library");
|
|
33
|
+
const transform_1 = require("@manuscripts/transform");
|
|
23
34
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
24
35
|
const react_1 = __importDefault(require("react"));
|
|
25
36
|
const dompurify_1 = require("../lib/dompurify");
|
|
26
37
|
const base_node_view_1 = require("./base_node_view");
|
|
27
38
|
const creators_1 = require("./creators");
|
|
39
|
+
const createCitation = (citations, citation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
const styleOpts = { bundleID: transform_1.DEFAULT_BUNDLE };
|
|
41
|
+
const citationStyle = yield (0, library_1.loadCitationStyle)(styleOpts);
|
|
42
|
+
const citationText = library_1.CitationProvider.makeCitationCluster(citations, citation, citationStyle);
|
|
43
|
+
return citationText !== '[NO_PRINTED_FORM]' ? citationText : '';
|
|
44
|
+
});
|
|
28
45
|
class CitationView extends base_node_view_1.BaseNodeView {
|
|
29
46
|
constructor() {
|
|
30
47
|
super(...arguments);
|
|
@@ -83,14 +100,29 @@ class CitationView extends base_node_view_1.BaseNodeView {
|
|
|
83
100
|
this.updateContents();
|
|
84
101
|
return this;
|
|
85
102
|
};
|
|
86
|
-
this.updateContents = () => {
|
|
87
|
-
|
|
103
|
+
this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
var _a;
|
|
105
|
+
const citations = [];
|
|
106
|
+
(_a = this.props.modelMap) === null || _a === void 0 ? void 0 : _a.forEach((value) => {
|
|
107
|
+
if (value.objectType === 'MPBibliographyItem') {
|
|
108
|
+
citations.push(value);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const nodeModel = this.props.getModel(this.node.attrs.rid);
|
|
112
|
+
let citationText = '';
|
|
113
|
+
try {
|
|
114
|
+
citationText = yield createCitation(citations, nodeModel);
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
citationText = this.node.attrs.contents;
|
|
118
|
+
}
|
|
119
|
+
const fragment = (0, dompurify_1.sanitize)(citationText, {
|
|
88
120
|
ALLOWED_TAGS: ['i', 'b', 'span', 'sup', 'sub', '#text'],
|
|
89
121
|
});
|
|
90
122
|
this.dom.innerHTML = '';
|
|
91
123
|
this.dom.appendChild(fragment);
|
|
92
124
|
this.setDomAttrs(this.node, this.dom, ['rid', 'contents', 'selectedText']);
|
|
93
|
-
};
|
|
125
|
+
});
|
|
94
126
|
this.getCitation = () => {
|
|
95
127
|
const citation = this.props.getModel(this.node.attrs.rid);
|
|
96
128
|
if (!citation) {
|
|
@@ -78,7 +78,7 @@ class CitationEditableView extends citation_1.CitationView {
|
|
|
78
78
|
this.popperContainer = document.createElement('div');
|
|
79
79
|
this.popperContainer.className = 'citation-editor';
|
|
80
80
|
}
|
|
81
|
-
const component = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.editArticle) ? (react_1.default.createElement(CitationEditor, { items: items, saveModel: handleSave, deleteModel: deleteModel, modelMap: modelMap, setLibraryItem: setLibraryItem, filterLibraryItems: filterLibraryItems, removeLibraryItem: removeLibraryItem, importItems: this.importItems, selectedText: this.node.attrs.selectedText, setComment: this.props.setComment, handleCancel: this.handleCancel, handleClose: this.handleClose, handleRemove: this.handleRemove, updatePopper: this.updatePopper, handleCite: this.handleCite, citation: citation, updateCitation: updateCitation, projectID: projectID, scheduleUpdate: this.props.popper.update })) : (react_1.default.createElement(CitationViewer, { items: items, setComment: this.props.setComment, scheduleUpdate: this.props.popper.update }));
|
|
81
|
+
const component = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.editArticle) ? (react_1.default.createElement(CitationEditor, { items: items, saveModel: handleSave, deleteModel: deleteModel, modelMap: modelMap, setLibraryItem: setLibraryItem, filterLibraryItems: filterLibraryItems, removeLibraryItem: removeLibraryItem, importItems: this.importItems, selectedText: this.node.attrs.selectedText, setComment: this.props.setComment, handleCancel: this.handleCancel, handleClose: this.handleClose, handleRemove: this.handleRemove, updatePopper: this.updatePopper, handleCite: this.handleCite, canEdit: capabilities.editCitationsAndRefs, citation: citation, updateCitation: updateCitation, projectID: projectID, scheduleUpdate: this.props.popper.update })) : (react_1.default.createElement(CitationViewer, { items: items, setComment: this.props.setComment, scheduleUpdate: this.props.popper.update }));
|
|
82
82
|
renderReactComponent(component, this.popperContainer);
|
|
83
83
|
this.props.popper.show(this.dom, this.popperContainer, 'right');
|
|
84
84
|
};
|
|
@@ -76,15 +76,17 @@ export class BibliographyItemView extends BaseNodeView {
|
|
|
76
76
|
this.dom.innerHTML = '';
|
|
77
77
|
this.dom.appendChild(fragment);
|
|
78
78
|
const doubleButton = document.createElement('div');
|
|
79
|
-
const editButton = document.createElement('
|
|
80
|
-
const commentButton = document.createElement('
|
|
79
|
+
const editButton = document.createElement('button');
|
|
80
|
+
const commentButton = document.createElement('button');
|
|
81
81
|
doubleButton.className = 'bibliography-double-button';
|
|
82
82
|
editButton.className = 'bibliography-edit-button';
|
|
83
83
|
commentButton.className = 'bibliography-comment-button';
|
|
84
|
-
commentButton.addEventListener('click', () => {
|
|
84
|
+
commentButton.addEventListener('click', (e) => {
|
|
85
|
+
e.preventDefault();
|
|
85
86
|
this.props.setComment(buildComment(this.node.attrs.id));
|
|
86
87
|
});
|
|
87
|
-
editButton.addEventListener('click', () => {
|
|
88
|
+
editButton.addEventListener('click', (e) => {
|
|
89
|
+
e.preventDefault();
|
|
88
90
|
this.showPopper(this.node.attrs.id);
|
|
89
91
|
this.popperContainer = undefined;
|
|
90
92
|
});
|
|
@@ -94,6 +96,7 @@ export class BibliographyItemView extends BaseNodeView {
|
|
|
94
96
|
if (this.props.getCapabilities().seeReferencesButtons) {
|
|
95
97
|
this.dom.appendChild(doubleButton);
|
|
96
98
|
}
|
|
99
|
+
editButton.disabled = !this.props.getCapabilities().editCitationsAndRefs;
|
|
97
100
|
}
|
|
98
101
|
catch (e) {
|
|
99
102
|
console.error(e);
|
|
@@ -13,12 +13,29 @@
|
|
|
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
|
+
};
|
|
16
25
|
import { ObjectTypes, } from '@manuscripts/json-schema';
|
|
26
|
+
import { CitationProvider, loadCitationStyle } from '@manuscripts/library';
|
|
27
|
+
import { DEFAULT_BUNDLE } from '@manuscripts/transform';
|
|
17
28
|
import { DOMSerializer } from 'prosemirror-model';
|
|
18
29
|
import React from 'react';
|
|
19
30
|
import { sanitize } from '../lib/dompurify';
|
|
20
31
|
import { BaseNodeView } from './base_node_view';
|
|
21
32
|
import { createNodeView } from './creators';
|
|
33
|
+
const createCitation = (citations, citation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const styleOpts = { bundleID: DEFAULT_BUNDLE };
|
|
35
|
+
const citationStyle = yield loadCitationStyle(styleOpts);
|
|
36
|
+
const citationText = CitationProvider.makeCitationCluster(citations, citation, citationStyle);
|
|
37
|
+
return citationText !== '[NO_PRINTED_FORM]' ? citationText : '';
|
|
38
|
+
});
|
|
22
39
|
export class CitationView extends BaseNodeView {
|
|
23
40
|
constructor() {
|
|
24
41
|
super(...arguments);
|
|
@@ -77,14 +94,29 @@ export class CitationView extends BaseNodeView {
|
|
|
77
94
|
this.updateContents();
|
|
78
95
|
return this;
|
|
79
96
|
};
|
|
80
|
-
this.updateContents = () => {
|
|
81
|
-
|
|
97
|
+
this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
var _a;
|
|
99
|
+
const citations = [];
|
|
100
|
+
(_a = this.props.modelMap) === null || _a === void 0 ? void 0 : _a.forEach((value) => {
|
|
101
|
+
if (value.objectType === 'MPBibliographyItem') {
|
|
102
|
+
citations.push(value);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const nodeModel = this.props.getModel(this.node.attrs.rid);
|
|
106
|
+
let citationText = '';
|
|
107
|
+
try {
|
|
108
|
+
citationText = yield createCitation(citations, nodeModel);
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
citationText = this.node.attrs.contents;
|
|
112
|
+
}
|
|
113
|
+
const fragment = sanitize(citationText, {
|
|
82
114
|
ALLOWED_TAGS: ['i', 'b', 'span', 'sup', 'sub', '#text'],
|
|
83
115
|
});
|
|
84
116
|
this.dom.innerHTML = '';
|
|
85
117
|
this.dom.appendChild(fragment);
|
|
86
118
|
this.setDomAttrs(this.node, this.dom, ['rid', 'contents', 'selectedText']);
|
|
87
|
-
};
|
|
119
|
+
});
|
|
88
120
|
this.getCitation = () => {
|
|
89
121
|
const citation = this.props.getModel(this.node.attrs.rid);
|
|
90
122
|
if (!citation) {
|
|
@@ -72,7 +72,7 @@ export class CitationEditableView extends CitationView {
|
|
|
72
72
|
this.popperContainer = document.createElement('div');
|
|
73
73
|
this.popperContainer.className = 'citation-editor';
|
|
74
74
|
}
|
|
75
|
-
const component = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.editArticle) ? (React.createElement(CitationEditor, { items: items, saveModel: handleSave, deleteModel: deleteModel, modelMap: modelMap, setLibraryItem: setLibraryItem, filterLibraryItems: filterLibraryItems, removeLibraryItem: removeLibraryItem, importItems: this.importItems, selectedText: this.node.attrs.selectedText, setComment: this.props.setComment, handleCancel: this.handleCancel, handleClose: this.handleClose, handleRemove: this.handleRemove, updatePopper: this.updatePopper, handleCite: this.handleCite, citation: citation, updateCitation: updateCitation, projectID: projectID, scheduleUpdate: this.props.popper.update })) : (React.createElement(CitationViewer, { items: items, setComment: this.props.setComment, scheduleUpdate: this.props.popper.update }));
|
|
75
|
+
const component = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.editArticle) ? (React.createElement(CitationEditor, { items: items, saveModel: handleSave, deleteModel: deleteModel, modelMap: modelMap, setLibraryItem: setLibraryItem, filterLibraryItems: filterLibraryItems, removeLibraryItem: removeLibraryItem, importItems: this.importItems, selectedText: this.node.attrs.selectedText, setComment: this.props.setComment, handleCancel: this.handleCancel, handleClose: this.handleClose, handleRemove: this.handleRemove, updatePopper: this.updatePopper, handleCite: this.handleCite, canEdit: capabilities.editCitationsAndRefs, citation: citation, updateCitation: updateCitation, projectID: projectID, scheduleUpdate: this.props.popper.update })) : (React.createElement(CitationViewer, { items: items, setComment: this.props.setComment, scheduleUpdate: this.props.popper.update }));
|
|
76
76
|
renderReactComponent(component, this.popperContainer);
|
|
77
77
|
this.props.popper.show(this.dom, this.popperContainer, 'right');
|
|
78
78
|
};
|
|
@@ -25,6 +25,7 @@ export interface BaseNodeProps {
|
|
|
25
25
|
getModel: <T extends Model>(id: string) => T | undefined;
|
|
26
26
|
renderReactComponent: (child: React.ReactElement, container: HTMLElement) => void;
|
|
27
27
|
unmountReactComponent: (container: HTMLElement) => void;
|
|
28
|
+
modelMap?: Map<string, Model>;
|
|
28
29
|
}
|
|
29
30
|
export declare class BaseNodeView<PropsType extends BaseNodeProps> implements NodeView {
|
|
30
31
|
readonly props: PropsType;
|
|
@@ -30,7 +30,7 @@ export declare class CitationView<PropsType extends CitationViewProps> extends B
|
|
|
30
30
|
deselectNode: () => void;
|
|
31
31
|
destroy: () => void;
|
|
32
32
|
initialise: () => this;
|
|
33
|
-
updateContents: () => void
|
|
33
|
+
updateContents: () => Promise<void>;
|
|
34
34
|
getCitation: () => Citation;
|
|
35
35
|
}
|
|
36
36
|
declare const _default: (props: BaseNodeProps, dispatch?: import("..").Dispatch | undefined) => import("../types").NodeViewCreator<CitationView<any>>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/body-editor",
|
|
3
3
|
"description": "Prosemirror components for editing and viewing manuscripts",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.22-LEAN-2143-v2",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"@manuscripts/assets": "^0.6.2",
|
|
32
32
|
"@manuscripts/comment-editor": "^1.0.1",
|
|
33
33
|
"@manuscripts/json-schema": "^2.0.2",
|
|
34
|
-
"@manuscripts/library": "^1.1.2",
|
|
35
|
-
"@manuscripts/style-guide": "^1.1.
|
|
34
|
+
"@manuscripts/library": "^1.1.2-LEAN-2143-v6",
|
|
35
|
+
"@manuscripts/style-guide": "^1.1.11",
|
|
36
36
|
"@manuscripts/title-editor": "^1.1.0",
|
|
37
37
|
"@manuscripts/track-changes-plugin": "^1.6.1",
|
|
38
38
|
"@manuscripts/transform": "^1.3.0",
|
|
@@ -150,4 +150,4 @@
|
|
|
150
150
|
"resolutions": {
|
|
151
151
|
"@types/react": "^17.0.2"
|
|
152
152
|
}
|
|
153
|
-
}
|
|
153
|
+
}
|
|
@@ -700,6 +700,8 @@
|
|
|
700
700
|
|
|
701
701
|
.bibliography-double-button {
|
|
702
702
|
display: inline-flex;
|
|
703
|
+
text-decoration: none;
|
|
704
|
+
color: inherit;
|
|
703
705
|
flex-direction: column;
|
|
704
706
|
position: absolute;
|
|
705
707
|
top: -50%;
|
|
@@ -711,15 +713,20 @@
|
|
|
711
713
|
|
|
712
714
|
.bibliography-edit-button,
|
|
713
715
|
.bibliography-comment-button {
|
|
716
|
+
text-decoration: none;
|
|
714
717
|
display: inline-flex;
|
|
715
718
|
flex-wrap: wrap;
|
|
716
719
|
align-content: center;
|
|
717
720
|
justify-content: center;
|
|
718
721
|
height: 40px;
|
|
719
722
|
background: #ffffff;
|
|
723
|
+
color: inherit;
|
|
720
724
|
border: 1px solid #e2e2e2;
|
|
721
725
|
border-radius: 32px 32px 0 0;
|
|
722
726
|
}
|
|
727
|
+
.bibliography-double-button button:disabled svg {
|
|
728
|
+
opacity: 0.25;
|
|
729
|
+
}
|
|
723
730
|
|
|
724
731
|
.bibliography-comment-button {
|
|
725
732
|
border-radius: 0 0 32px 32px;
|