@manuscripts/body-editor 1.4.24 → 1.5.0-LEAN-2055-0
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/plugins/bibliography/bibliography-utils.js +11 -1
- package/dist/cjs/plugins/bibliography/index.js +13 -4
- package/dist/cjs/plugins/tracking-mark.js +3 -3
- package/dist/cjs/views/bibliography_element.js +139 -1
- package/dist/es/plugins/bibliography/bibliography-utils.js +11 -1
- package/dist/es/plugins/bibliography/index.js +13 -4
- package/dist/es/plugins/tracking-mark.js +3 -3
- package/dist/es/views/bibliography_element.js +139 -1
- package/dist/types/plugins/bibliography/bibliography-utils.d.ts +1 -1
- package/dist/types/plugins/bibliography/types.d.ts +1 -0
- package/dist/types/plugins/tracking-mark.d.ts +2 -2
- package/dist/types/views/bibliography_element.d.ts +12 -1
- package/package.json +5 -5
- package/styles/Editor.css +4 -8
|
@@ -34,7 +34,7 @@ const lodash_es_1 = require("lodash-es");
|
|
|
34
34
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
35
35
|
const isBibliographyElement = (node) => node.type === node.type.schema.nodes.bibliography_element;
|
|
36
36
|
exports.isBibliographyElement = isBibliographyElement;
|
|
37
|
-
const buildDecorations = (doc, citationNodes, popper, referencesModelMap) => {
|
|
37
|
+
const buildDecorations = (doc, citationNodes, popper, referencesModelMap, triggerUpdate) => {
|
|
38
38
|
const decorations = [];
|
|
39
39
|
let hasMissingItems = false;
|
|
40
40
|
for (const [node, pos, citation] of citationNodes) {
|
|
@@ -72,6 +72,16 @@ const buildDecorations = (doc, citationNodes, popper, referencesModelMap) => {
|
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
+
if (triggerUpdate) {
|
|
76
|
+
console.log('Push a decoration to trigger bibliography element update ^^^^');
|
|
77
|
+
doc.descendants((node, pos) => {
|
|
78
|
+
if ((0, exports.isBibliographyElement)(node)) {
|
|
79
|
+
decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {}, {
|
|
80
|
+
triggerUpdate: true,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
75
85
|
return decorations;
|
|
76
86
|
};
|
|
77
87
|
exports.buildDecorations = buildDecorations;
|
|
@@ -20,6 +20,7 @@ const library_1 = require("@manuscripts/library");
|
|
|
20
20
|
const lodash_es_1 = require("lodash-es");
|
|
21
21
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
22
22
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
23
|
+
const track_changes_utils_1 = require("../../lib/track-changes-utils");
|
|
23
24
|
const bibliography_utils_1 = require("./bibliography-utils");
|
|
24
25
|
exports.bibliographyKey = new prosemirror_state_1.PluginKey('bibliography');
|
|
25
26
|
exports.default = (props) => {
|
|
@@ -31,7 +32,8 @@ exports.default = (props) => {
|
|
|
31
32
|
const referencesModelMap = (0, bibliography_utils_1.getReferencesModelMap)(instance.doc);
|
|
32
33
|
const citationNodes = (0, library_1.buildCitationNodes)(instance.doc, referencesModelMap);
|
|
33
34
|
const citations = (0, library_1.buildCitations)(citationNodes, (id) => referencesModelMap.get(id));
|
|
34
|
-
const
|
|
35
|
+
const filteredCitationNodes = citationNodes.filter((node) => !(0, track_changes_utils_1.isDeleted)(node[0]));
|
|
36
|
+
const bibliographyItems = (0, library_1.buildBibliographyItems)(filteredCitationNodes, (id) => referencesModelMap.get(id));
|
|
35
37
|
return {
|
|
36
38
|
citationNodes,
|
|
37
39
|
citations,
|
|
@@ -42,11 +44,15 @@ exports.default = (props) => {
|
|
|
42
44
|
const referencesModelMap = (0, bibliography_utils_1.getReferencesModelMap)(newState.doc);
|
|
43
45
|
const citationNodes = (0, library_1.buildCitationNodes)(newState.doc, referencesModelMap);
|
|
44
46
|
const citations = (0, library_1.buildCitations)(citationNodes, (id) => referencesModelMap.get(id));
|
|
45
|
-
const
|
|
47
|
+
const filteredCitationNodes = citationNodes.filter((node) => !(0, track_changes_utils_1.isDeleted)(node[0]));
|
|
48
|
+
const bibliographyItems = (0, library_1.buildBibliographyItems)(filteredCitationNodes, (id) => referencesModelMap.get(id));
|
|
49
|
+
const meta = tr.getMeta(exports.bibliographyKey);
|
|
50
|
+
const triggerUpdate = meta && meta.triggerUpdate;
|
|
46
51
|
return {
|
|
47
52
|
citationNodes,
|
|
48
53
|
citations,
|
|
49
54
|
bibliographyItems,
|
|
55
|
+
triggerUpdate,
|
|
50
56
|
};
|
|
51
57
|
},
|
|
52
58
|
},
|
|
@@ -74,6 +80,9 @@ exports.default = (props) => {
|
|
|
74
80
|
if (selection instanceof prosemirror_state_1.NodeSelection) {
|
|
75
81
|
tr.setSelection(prosemirror_state_1.NodeSelection.create(tr.doc, selection.from));
|
|
76
82
|
}
|
|
83
|
+
tr.setMeta(exports.bibliographyKey, {
|
|
84
|
+
triggerUpdate: true,
|
|
85
|
+
});
|
|
77
86
|
tr.setMeta('origin', exports.bibliographyKey);
|
|
78
87
|
return tr;
|
|
79
88
|
}
|
|
@@ -83,8 +92,8 @@ exports.default = (props) => {
|
|
|
83
92
|
},
|
|
84
93
|
props: {
|
|
85
94
|
decorations(state) {
|
|
86
|
-
const { citationNodes } = exports.bibliographyKey.getState(state);
|
|
87
|
-
return prosemirror_view_1.DecorationSet.create(state.doc, (0, bibliography_utils_1.buildDecorations)(state.doc, citationNodes, props.popper, (0, bibliography_utils_1.getReferencesModelMap)(state.doc)));
|
|
95
|
+
const { citationNodes, triggerUpdate } = exports.bibliographyKey.getState(state);
|
|
96
|
+
return prosemirror_view_1.DecorationSet.create(state.doc, (0, bibliography_utils_1.buildDecorations)(state.doc, citationNodes, props.popper, (0, bibliography_utils_1.getReferencesModelMap)(state.doc), triggerUpdate));
|
|
88
97
|
},
|
|
89
98
|
},
|
|
90
99
|
});
|
|
@@ -41,17 +41,17 @@ const buildDecorations = (state) => {
|
|
|
41
41
|
if (change.type === 'node-attr-change' &&
|
|
42
42
|
change.dataTracked.status === track_changes_plugin_1.CHANGE_STATUS.pending &&
|
|
43
43
|
change.dataTracked.operation === track_changes_plugin_1.CHANGE_OPERATION.set_node_attributes) {
|
|
44
|
-
decorations.push(prosemirror_view_1.Decoration.widget(change.from + 1, (0, exports.getAttrsTrackingButton)(change), {
|
|
44
|
+
decorations.push(prosemirror_view_1.Decoration.widget(change.from + 1, (0, exports.getAttrsTrackingButton)(change.id), {
|
|
45
45
|
key: change.id,
|
|
46
46
|
}));
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
return decorations;
|
|
50
50
|
};
|
|
51
|
-
const getAttrsTrackingButton = (
|
|
51
|
+
const getAttrsTrackingButton = (changeID) => {
|
|
52
52
|
const el = document.createElement('button');
|
|
53
53
|
el.className = 'attrs-popper-button';
|
|
54
|
-
el.value =
|
|
54
|
+
el.value = changeID;
|
|
55
55
|
el.innerHTML = editIcon;
|
|
56
56
|
return el;
|
|
57
57
|
};
|
|
@@ -14,23 +14,161 @@
|
|
|
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
|
+
};
|
|
17
37
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
38
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
39
|
};
|
|
20
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
41
|
exports.BibliographyElementBlockView = void 0;
|
|
42
|
+
const library_1 = require("@manuscripts/library");
|
|
43
|
+
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
44
|
+
const transform_1 = require("@manuscripts/transform");
|
|
45
|
+
const react_1 = __importDefault(require("react"));
|
|
46
|
+
const assets_1 = require("../assets");
|
|
47
|
+
const dompurify_1 = require("../lib/dompurify");
|
|
48
|
+
const bibliography_1 = require("../plugins/bibliography");
|
|
49
|
+
const bibliography_utils_1 = require("../plugins/bibliography/bibliography-utils");
|
|
50
|
+
const comment_annotation_1 = require("../plugins/comment_annotation");
|
|
51
|
+
const tracking_mark_1 = require("../plugins/tracking-mark");
|
|
22
52
|
const block_view_1 = __importDefault(require("./block_view"));
|
|
23
53
|
const creators_1 = require("./creators");
|
|
54
|
+
const createBibliography = (bibliographyItems, cslProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const bibliographyItemsMap = new Map(bibliographyItems.map((item) => [item._id, item]));
|
|
56
|
+
const getLibraryItem = (id) => bibliographyItemsMap.get(id);
|
|
57
|
+
const { style = '', locale } = cslProps;
|
|
58
|
+
const provider = new library_1.CitationProvider({
|
|
59
|
+
getLibraryItem,
|
|
60
|
+
citationStyle: style,
|
|
61
|
+
locale,
|
|
62
|
+
});
|
|
63
|
+
const [bibmeta, generatedBibliographyItems] = provider.makeBibliography(bibliographyItems);
|
|
64
|
+
if (bibmeta.bibliography_errors.length) {
|
|
65
|
+
console.error(bibmeta.bibliography_errors);
|
|
66
|
+
}
|
|
67
|
+
const bibliographyFragment = generatedBibliographyItems
|
|
68
|
+
.map((item, i) => `<div id=${bibmeta.entry_ids[i]} class="bib-item"><div><div class="csl-bib-body">${item}</div></div></div>`)
|
|
69
|
+
.join('');
|
|
70
|
+
return (0, dompurify_1.sanitize)(`<div class="contents">${bibliographyFragment}</div>`);
|
|
71
|
+
});
|
|
24
72
|
class BibliographyElementBlockView extends block_view_1.default {
|
|
25
73
|
constructor() {
|
|
26
74
|
super(...arguments);
|
|
75
|
+
this.showPopper = (referenceID) => {
|
|
76
|
+
const { renderReactComponent, components: { ReferencesEditor }, } = this.props;
|
|
77
|
+
const handleSave = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const _a = data, { _id: id, 'container-title': containerTitle, DOI: doi } = _a, rest = __rest(_a, ["_id", 'container-title', "DOI"]);
|
|
79
|
+
this.updateNodeAttrs(Object.assign({ id,
|
|
80
|
+
containerTitle,
|
|
81
|
+
doi }, rest));
|
|
82
|
+
});
|
|
83
|
+
if (!this.popperContainer) {
|
|
84
|
+
this.popperContainer = document.createElement('div');
|
|
85
|
+
this.popperContainer.className = 'references';
|
|
86
|
+
}
|
|
87
|
+
renderReactComponent(react_1.default.createElement(ReferencesEditor, { saveModel: handleSave, deleteModel: this.deleteNode, modelMap: (0, bibliography_utils_1.getReferencesModelMap)(this.view.state.doc, true), referenceID: referenceID }), this.popperContainer);
|
|
88
|
+
this.props.popper.show(this.dom, this.popperContainer, 'right');
|
|
89
|
+
};
|
|
27
90
|
this.stopEvent = () => true;
|
|
28
91
|
this.ignoreMutation = () => true;
|
|
92
|
+
this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
console.log('Update contents ^^');
|
|
94
|
+
const bibliographyItems = bibliography_1.bibliographyKey.getState(this.view.state).bibliographyItems;
|
|
95
|
+
const commentsDecorationSet = comment_annotation_1.commentAnnotation.getState(this.view.state);
|
|
96
|
+
const commentElementMap = new Map();
|
|
97
|
+
const dataTrackedMap = new Map();
|
|
98
|
+
this.node.descendants((node, pos) => {
|
|
99
|
+
if (commentsDecorationSet) {
|
|
100
|
+
const nodePosition = this.getPos() + pos + 2;
|
|
101
|
+
const commentWidget = commentsDecorationSet.find(nodePosition, nodePosition);
|
|
102
|
+
if (commentWidget.length) {
|
|
103
|
+
const commentElement = commentWidget[0].type.toDOM();
|
|
104
|
+
commentElementMap.set(commentElement.id, commentElement);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const dataTracked = node.attrs.dataTracked;
|
|
108
|
+
if (dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.length) {
|
|
109
|
+
const lastChange = dataTracked[dataTracked.length - 1];
|
|
110
|
+
dataTrackedMap.set(node.attrs.id, lastChange);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
const bibliographyFragment = yield createBibliography(bibliographyItems, this.props.cslProps);
|
|
114
|
+
const bibItems = bibliographyFragment.querySelectorAll('.bib-item');
|
|
115
|
+
bibItems.forEach((element) => {
|
|
116
|
+
const doubleButton = document.createElement('div');
|
|
117
|
+
const editButton = document.createElement('button');
|
|
118
|
+
const commentButton = document.createElement('button');
|
|
119
|
+
doubleButton.className = 'bibliography-double-button';
|
|
120
|
+
editButton.className = 'bibliography-edit-button';
|
|
121
|
+
commentButton.className = 'bibliography-comment-button';
|
|
122
|
+
commentButton.addEventListener('click', (e) => {
|
|
123
|
+
e.preventDefault();
|
|
124
|
+
this.props.setComment((0, transform_1.buildComment)(element.id));
|
|
125
|
+
});
|
|
126
|
+
editButton.addEventListener('click', (e) => {
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
this.showPopper(element.id);
|
|
129
|
+
this.popperContainer = undefined;
|
|
130
|
+
});
|
|
131
|
+
editButton.innerHTML = assets_1.editIcon;
|
|
132
|
+
commentButton.innerHTML = assets_1.commentIcon;
|
|
133
|
+
doubleButton.append(editButton, commentButton);
|
|
134
|
+
if (this.props.getCapabilities().seeReferencesButtons &&
|
|
135
|
+
!element.querySelector('.bibliography-double-button')) {
|
|
136
|
+
element.appendChild(doubleButton);
|
|
137
|
+
}
|
|
138
|
+
editButton.disabled = !this.props.getCapabilities().editCitationsAndRefs;
|
|
139
|
+
const commentElement = commentElementMap.get(element.id);
|
|
140
|
+
if (commentElement) {
|
|
141
|
+
element.childNodes[0].appendChild(commentElement);
|
|
142
|
+
}
|
|
143
|
+
const dataTracked = dataTrackedMap.get(element.id);
|
|
144
|
+
if (dataTracked) {
|
|
145
|
+
element.classList.add('attrs-track-mark');
|
|
146
|
+
const decoration = (0, tracking_mark_1.getMarkDecoration)(dataTracked);
|
|
147
|
+
decoration.style && element.setAttribute('style', decoration.style);
|
|
148
|
+
if (dataTracked.status === track_changes_plugin_1.CHANGE_STATUS.pending &&
|
|
149
|
+
dataTracked.operation === track_changes_plugin_1.CHANGE_OPERATION.set_node_attributes) {
|
|
150
|
+
element.childNodes[0].appendChild((0, tracking_mark_1.getAttrsTrackingButton)(dataTracked.id));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
const oldContent = this.container.querySelector('.contents');
|
|
155
|
+
if (oldContent) {
|
|
156
|
+
this.container.replaceChild(bibliographyFragment, oldContent);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
this.container.appendChild(bibliographyFragment);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
29
162
|
this.createElement = () => {
|
|
163
|
+
this.container = document.createElement('div');
|
|
164
|
+
this.container.classList.add('block');
|
|
165
|
+
this.container.contentEditable = 'false';
|
|
166
|
+
this.dom.appendChild(this.container);
|
|
30
167
|
this.contentDOM = document.createElement('div');
|
|
31
168
|
this.contentDOM.classList.add('block');
|
|
32
169
|
this.contentDOM.setAttribute('id', this.node.attrs.id);
|
|
33
|
-
this.
|
|
170
|
+
this.contentDOM.hidden = true;
|
|
171
|
+
this.container.appendChild(this.contentDOM);
|
|
34
172
|
};
|
|
35
173
|
}
|
|
36
174
|
}
|
|
@@ -30,7 +30,7 @@ import { schema } from '@manuscripts/transform';
|
|
|
30
30
|
import { pickBy } from 'lodash-es';
|
|
31
31
|
import { Decoration } from 'prosemirror-view';
|
|
32
32
|
export const isBibliographyElement = (node) => node.type === node.type.schema.nodes.bibliography_element;
|
|
33
|
-
export const buildDecorations = (doc, citationNodes, popper, referencesModelMap) => {
|
|
33
|
+
export const buildDecorations = (doc, citationNodes, popper, referencesModelMap, triggerUpdate) => {
|
|
34
34
|
const decorations = [];
|
|
35
35
|
let hasMissingItems = false;
|
|
36
36
|
for (const [node, pos, citation] of citationNodes) {
|
|
@@ -68,6 +68,16 @@ export const buildDecorations = (doc, citationNodes, popper, referencesModelMap)
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
+
if (triggerUpdate) {
|
|
72
|
+
console.log('Push a decoration to trigger bibliography element update ^^^^');
|
|
73
|
+
doc.descendants((node, pos) => {
|
|
74
|
+
if (isBibliographyElement(node)) {
|
|
75
|
+
decorations.push(Decoration.node(pos, pos + node.nodeSize, {}, {
|
|
76
|
+
triggerUpdate: true,
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
71
81
|
return decorations;
|
|
72
82
|
};
|
|
73
83
|
const cleanData = (model) => pickBy(model, (value) => value !== undefined);
|
|
@@ -17,6 +17,7 @@ import { buildBibliographyItems, buildCitationNodes, buildCitations, CitationPro
|
|
|
17
17
|
import { isEqual } from 'lodash-es';
|
|
18
18
|
import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
|
|
19
19
|
import { DecorationSet } from 'prosemirror-view';
|
|
20
|
+
import { isDeleted } from '../../lib/track-changes-utils';
|
|
20
21
|
import { buildDecorations, getReferencesModelMap } from './bibliography-utils';
|
|
21
22
|
export const bibliographyKey = new PluginKey('bibliography');
|
|
22
23
|
export default (props) => {
|
|
@@ -28,7 +29,8 @@ export default (props) => {
|
|
|
28
29
|
const referencesModelMap = getReferencesModelMap(instance.doc);
|
|
29
30
|
const citationNodes = buildCitationNodes(instance.doc, referencesModelMap);
|
|
30
31
|
const citations = buildCitations(citationNodes, (id) => referencesModelMap.get(id));
|
|
31
|
-
const
|
|
32
|
+
const filteredCitationNodes = citationNodes.filter((node) => !isDeleted(node[0]));
|
|
33
|
+
const bibliographyItems = buildBibliographyItems(filteredCitationNodes, (id) => referencesModelMap.get(id));
|
|
32
34
|
return {
|
|
33
35
|
citationNodes,
|
|
34
36
|
citations,
|
|
@@ -39,11 +41,15 @@ export default (props) => {
|
|
|
39
41
|
const referencesModelMap = getReferencesModelMap(newState.doc);
|
|
40
42
|
const citationNodes = buildCitationNodes(newState.doc, referencesModelMap);
|
|
41
43
|
const citations = buildCitations(citationNodes, (id) => referencesModelMap.get(id));
|
|
42
|
-
const
|
|
44
|
+
const filteredCitationNodes = citationNodes.filter((node) => !isDeleted(node[0]));
|
|
45
|
+
const bibliographyItems = buildBibliographyItems(filteredCitationNodes, (id) => referencesModelMap.get(id));
|
|
46
|
+
const meta = tr.getMeta(bibliographyKey);
|
|
47
|
+
const triggerUpdate = meta && meta.triggerUpdate;
|
|
43
48
|
return {
|
|
44
49
|
citationNodes,
|
|
45
50
|
citations,
|
|
46
51
|
bibliographyItems,
|
|
52
|
+
triggerUpdate,
|
|
47
53
|
};
|
|
48
54
|
},
|
|
49
55
|
},
|
|
@@ -71,6 +77,9 @@ export default (props) => {
|
|
|
71
77
|
if (selection instanceof NodeSelection) {
|
|
72
78
|
tr.setSelection(NodeSelection.create(tr.doc, selection.from));
|
|
73
79
|
}
|
|
80
|
+
tr.setMeta(bibliographyKey, {
|
|
81
|
+
triggerUpdate: true,
|
|
82
|
+
});
|
|
74
83
|
tr.setMeta('origin', bibliographyKey);
|
|
75
84
|
return tr;
|
|
76
85
|
}
|
|
@@ -80,8 +89,8 @@ export default (props) => {
|
|
|
80
89
|
},
|
|
81
90
|
props: {
|
|
82
91
|
decorations(state) {
|
|
83
|
-
const { citationNodes } = bibliographyKey.getState(state);
|
|
84
|
-
return DecorationSet.create(state.doc, buildDecorations(state.doc, citationNodes, props.popper, getReferencesModelMap(state.doc)));
|
|
92
|
+
const { citationNodes, triggerUpdate } = bibliographyKey.getState(state);
|
|
93
|
+
return DecorationSet.create(state.doc, buildDecorations(state.doc, citationNodes, props.popper, getReferencesModelMap(state.doc), triggerUpdate));
|
|
85
94
|
},
|
|
86
95
|
},
|
|
87
96
|
});
|
|
@@ -38,17 +38,17 @@ const buildDecorations = (state) => {
|
|
|
38
38
|
if (change.type === 'node-attr-change' &&
|
|
39
39
|
change.dataTracked.status === CHANGE_STATUS.pending &&
|
|
40
40
|
change.dataTracked.operation === CHANGE_OPERATION.set_node_attributes) {
|
|
41
|
-
decorations.push(Decoration.widget(change.from + 1, getAttrsTrackingButton(change), {
|
|
41
|
+
decorations.push(Decoration.widget(change.from + 1, getAttrsTrackingButton(change.id), {
|
|
42
42
|
key: change.id,
|
|
43
43
|
}));
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
return decorations;
|
|
47
47
|
};
|
|
48
|
-
export const getAttrsTrackingButton = (
|
|
48
|
+
export const getAttrsTrackingButton = (changeID) => {
|
|
49
49
|
const el = document.createElement('button');
|
|
50
50
|
el.className = 'attrs-popper-button';
|
|
51
|
-
el.value =
|
|
51
|
+
el.value = changeID;
|
|
52
52
|
el.innerHTML = editIcon;
|
|
53
53
|
return el;
|
|
54
54
|
};
|
|
@@ -13,18 +13,156 @@
|
|
|
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
|
+
import { CitationProvider } from '@manuscripts/library';
|
|
37
|
+
import { CHANGE_OPERATION, CHANGE_STATUS, } from '@manuscripts/track-changes-plugin';
|
|
38
|
+
import { buildComment } from '@manuscripts/transform';
|
|
39
|
+
import React from 'react';
|
|
40
|
+
import { commentIcon, editIcon } from '../assets';
|
|
41
|
+
import { sanitize } from '../lib/dompurify';
|
|
42
|
+
import { bibliographyKey } from '../plugins/bibliography';
|
|
43
|
+
import { getReferencesModelMap } from '../plugins/bibliography/bibliography-utils';
|
|
44
|
+
import { commentAnnotation } from '../plugins/comment_annotation';
|
|
45
|
+
import { getAttrsTrackingButton, getMarkDecoration, } from '../plugins/tracking-mark';
|
|
16
46
|
import BlockView from './block_view';
|
|
17
47
|
import { createNodeView } from './creators';
|
|
48
|
+
const createBibliography = (bibliographyItems, cslProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const bibliographyItemsMap = new Map(bibliographyItems.map((item) => [item._id, item]));
|
|
50
|
+
const getLibraryItem = (id) => bibliographyItemsMap.get(id);
|
|
51
|
+
const { style = '', locale } = cslProps;
|
|
52
|
+
const provider = new CitationProvider({
|
|
53
|
+
getLibraryItem,
|
|
54
|
+
citationStyle: style,
|
|
55
|
+
locale,
|
|
56
|
+
});
|
|
57
|
+
const [bibmeta, generatedBibliographyItems] = provider.makeBibliography(bibliographyItems);
|
|
58
|
+
if (bibmeta.bibliography_errors.length) {
|
|
59
|
+
console.error(bibmeta.bibliography_errors);
|
|
60
|
+
}
|
|
61
|
+
const bibliographyFragment = generatedBibliographyItems
|
|
62
|
+
.map((item, i) => `<div id=${bibmeta.entry_ids[i]} class="bib-item"><div><div class="csl-bib-body">${item}</div></div></div>`)
|
|
63
|
+
.join('');
|
|
64
|
+
return sanitize(`<div class="contents">${bibliographyFragment}</div>`);
|
|
65
|
+
});
|
|
18
66
|
export class BibliographyElementBlockView extends BlockView {
|
|
19
67
|
constructor() {
|
|
20
68
|
super(...arguments);
|
|
69
|
+
this.showPopper = (referenceID) => {
|
|
70
|
+
const { renderReactComponent, components: { ReferencesEditor }, } = this.props;
|
|
71
|
+
const handleSave = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const _a = data, { _id: id, 'container-title': containerTitle, DOI: doi } = _a, rest = __rest(_a, ["_id", 'container-title', "DOI"]);
|
|
73
|
+
this.updateNodeAttrs(Object.assign({ id,
|
|
74
|
+
containerTitle,
|
|
75
|
+
doi }, rest));
|
|
76
|
+
});
|
|
77
|
+
if (!this.popperContainer) {
|
|
78
|
+
this.popperContainer = document.createElement('div');
|
|
79
|
+
this.popperContainer.className = 'references';
|
|
80
|
+
}
|
|
81
|
+
renderReactComponent(React.createElement(ReferencesEditor, { saveModel: handleSave, deleteModel: this.deleteNode, modelMap: getReferencesModelMap(this.view.state.doc, true), referenceID: referenceID }), this.popperContainer);
|
|
82
|
+
this.props.popper.show(this.dom, this.popperContainer, 'right');
|
|
83
|
+
};
|
|
21
84
|
this.stopEvent = () => true;
|
|
22
85
|
this.ignoreMutation = () => true;
|
|
86
|
+
this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
console.log('Update contents ^^');
|
|
88
|
+
const bibliographyItems = bibliographyKey.getState(this.view.state).bibliographyItems;
|
|
89
|
+
const commentsDecorationSet = commentAnnotation.getState(this.view.state);
|
|
90
|
+
const commentElementMap = new Map();
|
|
91
|
+
const dataTrackedMap = new Map();
|
|
92
|
+
this.node.descendants((node, pos) => {
|
|
93
|
+
if (commentsDecorationSet) {
|
|
94
|
+
const nodePosition = this.getPos() + pos + 2;
|
|
95
|
+
const commentWidget = commentsDecorationSet.find(nodePosition, nodePosition);
|
|
96
|
+
if (commentWidget.length) {
|
|
97
|
+
const commentElement = commentWidget[0].type.toDOM();
|
|
98
|
+
commentElementMap.set(commentElement.id, commentElement);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const dataTracked = node.attrs.dataTracked;
|
|
102
|
+
if (dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.length) {
|
|
103
|
+
const lastChange = dataTracked[dataTracked.length - 1];
|
|
104
|
+
dataTrackedMap.set(node.attrs.id, lastChange);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const bibliographyFragment = yield createBibliography(bibliographyItems, this.props.cslProps);
|
|
108
|
+
const bibItems = bibliographyFragment.querySelectorAll('.bib-item');
|
|
109
|
+
bibItems.forEach((element) => {
|
|
110
|
+
const doubleButton = document.createElement('div');
|
|
111
|
+
const editButton = document.createElement('button');
|
|
112
|
+
const commentButton = document.createElement('button');
|
|
113
|
+
doubleButton.className = 'bibliography-double-button';
|
|
114
|
+
editButton.className = 'bibliography-edit-button';
|
|
115
|
+
commentButton.className = 'bibliography-comment-button';
|
|
116
|
+
commentButton.addEventListener('click', (e) => {
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
this.props.setComment(buildComment(element.id));
|
|
119
|
+
});
|
|
120
|
+
editButton.addEventListener('click', (e) => {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
this.showPopper(element.id);
|
|
123
|
+
this.popperContainer = undefined;
|
|
124
|
+
});
|
|
125
|
+
editButton.innerHTML = editIcon;
|
|
126
|
+
commentButton.innerHTML = commentIcon;
|
|
127
|
+
doubleButton.append(editButton, commentButton);
|
|
128
|
+
if (this.props.getCapabilities().seeReferencesButtons &&
|
|
129
|
+
!element.querySelector('.bibliography-double-button')) {
|
|
130
|
+
element.appendChild(doubleButton);
|
|
131
|
+
}
|
|
132
|
+
editButton.disabled = !this.props.getCapabilities().editCitationsAndRefs;
|
|
133
|
+
const commentElement = commentElementMap.get(element.id);
|
|
134
|
+
if (commentElement) {
|
|
135
|
+
element.childNodes[0].appendChild(commentElement);
|
|
136
|
+
}
|
|
137
|
+
const dataTracked = dataTrackedMap.get(element.id);
|
|
138
|
+
if (dataTracked) {
|
|
139
|
+
element.classList.add('attrs-track-mark');
|
|
140
|
+
const decoration = getMarkDecoration(dataTracked);
|
|
141
|
+
decoration.style && element.setAttribute('style', decoration.style);
|
|
142
|
+
if (dataTracked.status === CHANGE_STATUS.pending &&
|
|
143
|
+
dataTracked.operation === CHANGE_OPERATION.set_node_attributes) {
|
|
144
|
+
element.childNodes[0].appendChild(getAttrsTrackingButton(dataTracked.id));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
const oldContent = this.container.querySelector('.contents');
|
|
149
|
+
if (oldContent) {
|
|
150
|
+
this.container.replaceChild(bibliographyFragment, oldContent);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
this.container.appendChild(bibliographyFragment);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
23
156
|
this.createElement = () => {
|
|
157
|
+
this.container = document.createElement('div');
|
|
158
|
+
this.container.classList.add('block');
|
|
159
|
+
this.container.contentEditable = 'false';
|
|
160
|
+
this.dom.appendChild(this.container);
|
|
24
161
|
this.contentDOM = document.createElement('div');
|
|
25
162
|
this.contentDOM.classList.add('block');
|
|
26
163
|
this.contentDOM.setAttribute('id', this.node.attrs.id);
|
|
27
|
-
this.
|
|
164
|
+
this.contentDOM.hidden = true;
|
|
165
|
+
this.container.appendChild(this.contentDOM);
|
|
28
166
|
};
|
|
29
167
|
}
|
|
30
168
|
}
|
|
@@ -19,6 +19,6 @@ import { ManuscriptNode } from '@manuscripts/transform';
|
|
|
19
19
|
import { Decoration } from 'prosemirror-view';
|
|
20
20
|
import { PopperManager } from '../../lib/popper';
|
|
21
21
|
export declare const isBibliographyElement: (node: ManuscriptNode) => boolean;
|
|
22
|
-
export declare const buildDecorations: (doc: ManuscriptNode, citationNodes: CitationNodes, popper: PopperManager, referencesModelMap: Map<string, Model
|
|
22
|
+
export declare const buildDecorations: (doc: ManuscriptNode, citationNodes: CitationNodes, popper: PopperManager, referencesModelMap: Map<string, Model>, triggerUpdate?: boolean) => Decoration[];
|
|
23
23
|
export declare const getNodeModel: <T extends Model>(node: ManuscriptNode, excludeDeletedNode?: boolean) => T | undefined;
|
|
24
24
|
export declare const getReferencesModelMap: (doc: ManuscriptNode, excludeDeletedNode?: boolean) => Map<string, Model>;
|
|
@@ -29,6 +29,7 @@ export interface PluginState {
|
|
|
29
29
|
citationNodes: CitationNodes;
|
|
30
30
|
citations: CiteProcCitation[];
|
|
31
31
|
bibliographyItems: BibliographyItem[];
|
|
32
|
+
triggerUpdate?: boolean;
|
|
32
33
|
}
|
|
33
34
|
export interface BibliographyProps {
|
|
34
35
|
getCitationProvider: () => CitationProvider | undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TrackedAttrs } from '@manuscripts/track-changes-plugin';
|
|
2
2
|
import { Plugin } from 'prosemirror-state';
|
|
3
3
|
import { DecorationAttrs, DecorationSet } from 'prosemirror-view';
|
|
4
4
|
declare const _default: () => Plugin<DecorationSet>;
|
|
5
5
|
export default _default;
|
|
6
|
-
export declare const getAttrsTrackingButton: (
|
|
6
|
+
export declare const getAttrsTrackingButton: (changeID: string) => HTMLButtonElement;
|
|
7
7
|
export declare const getMarkDecoration: (dataTracked: TrackedAttrs, htmlNode?: HTMLElement) => DecorationAttrs;
|
|
@@ -13,11 +13,22 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { CommentAnnotation } from '@manuscripts/json-schema';
|
|
17
|
+
import React from 'react';
|
|
16
18
|
import { BaseNodeProps } from './base_node_view';
|
|
17
19
|
import BlockView from './block_view';
|
|
18
|
-
|
|
20
|
+
import { EditableBlockProps } from './editable_block';
|
|
21
|
+
interface BibliographyElementViewProps extends BaseNodeProps {
|
|
22
|
+
setComment: (comment?: CommentAnnotation) => void;
|
|
23
|
+
components: Record<string, React.ComponentType<any>>;
|
|
24
|
+
}
|
|
25
|
+
export declare class BibliographyElementBlockView<PropsType extends BibliographyElementViewProps & EditableBlockProps> extends BlockView<PropsType> {
|
|
26
|
+
container: HTMLElement;
|
|
27
|
+
popperContainer?: HTMLDivElement;
|
|
28
|
+
showPopper: (referenceID: string) => void;
|
|
19
29
|
stopEvent: () => boolean;
|
|
20
30
|
ignoreMutation: () => boolean;
|
|
31
|
+
updateContents: () => Promise<void>;
|
|
21
32
|
createElement: () => void;
|
|
22
33
|
}
|
|
23
34
|
declare const _default: (props: BaseNodeProps, dispatch?: import("..").Dispatch | undefined) => import("../types").NodeViewCreator<BibliographyElementBlockView<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.
|
|
4
|
+
"version": "1.5.0-LEAN-2055-0",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"@manuscripts/assets": "^0.6.4",
|
|
31
31
|
"@manuscripts/comment-editor": "^1.0.3",
|
|
32
32
|
"@manuscripts/json-schema": "^2.2.0",
|
|
33
|
-
"@manuscripts/library": "
|
|
34
|
-
"@manuscripts/style-guide": "
|
|
33
|
+
"@manuscripts/library": "1.2.0",
|
|
34
|
+
"@manuscripts/style-guide": "1.4.0",
|
|
35
35
|
"@manuscripts/title-editor": "^1.1.0",
|
|
36
36
|
"@manuscripts/track-changes-plugin": "^1.7.2",
|
|
37
|
-
"@manuscripts/transform": "
|
|
37
|
+
"@manuscripts/transform": "1.5.0",
|
|
38
38
|
"astrocite-eutils": "^0.16.4",
|
|
39
39
|
"axios": "^1.2.2",
|
|
40
40
|
"codemirror": "^5.58.1",
|
|
@@ -145,4 +145,4 @@
|
|
|
145
145
|
"resolutions": {
|
|
146
146
|
"@types/react": "^17.0.2"
|
|
147
147
|
}
|
|
148
|
-
}
|
|
148
|
+
}
|
package/styles/Editor.css
CHANGED
|
@@ -731,12 +731,8 @@
|
|
|
731
731
|
text-align: center;
|
|
732
732
|
}
|
|
733
733
|
|
|
734
|
-
.ProseMirror .block {
|
|
735
|
-
counter-reset: bib_item;
|
|
736
|
-
}
|
|
737
734
|
|
|
738
735
|
.ProseMirror .bib-item {
|
|
739
|
-
counter-increment: bib_item;
|
|
740
736
|
position: relative;
|
|
741
737
|
margin-right: 40px;
|
|
742
738
|
}
|
|
@@ -751,12 +747,12 @@
|
|
|
751
747
|
|
|
752
748
|
.ProseMirror .csl-left-margin {
|
|
753
749
|
padding-right: 1ch;
|
|
754
|
-
display:
|
|
750
|
+
display: table-cell;
|
|
755
751
|
}
|
|
756
752
|
|
|
757
|
-
.ProseMirror .csl-right-inline
|
|
758
|
-
|
|
759
|
-
}
|
|
753
|
+
/* .ProseMirror .csl-right-inline {
|
|
754
|
+
display: table-cell;
|
|
755
|
+
} */
|
|
760
756
|
|
|
761
757
|
.ProseMirror .csl-entry a {
|
|
762
758
|
color: inherit;
|