@manuscripts/body-editor 1.5.7-LEAN-2055-0 → 1.5.7

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.
@@ -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, triggerUpdate) => {
37
+ const buildDecorations = (doc, citationNodes, popper, referencesModelMap) => {
38
38
  const decorations = [];
39
39
  let hasMissingItems = false;
40
40
  for (const [node, pos, citation] of citationNodes) {
@@ -72,15 +72,6 @@ const buildDecorations = (doc, citationNodes, popper, referencesModelMap, trigge
72
72
  }
73
73
  });
74
74
  }
75
- if (triggerUpdate) {
76
- doc.descendants((node, pos) => {
77
- if ((0, exports.isBibliographyElement)(node)) {
78
- decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {}, {
79
- triggerUpdate: true,
80
- }));
81
- }
82
- });
83
- }
84
75
  return decorations;
85
76
  };
86
77
  exports.buildDecorations = buildDecorations;
@@ -20,7 +20,6 @@ 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");
24
23
  const bibliography_utils_1 = require("./bibliography-utils");
25
24
  exports.bibliographyKey = new prosemirror_state_1.PluginKey('bibliography');
26
25
  exports.default = (props) => {
@@ -31,9 +30,8 @@ exports.default = (props) => {
31
30
  init(config, instance) {
32
31
  const referencesModelMap = (0, bibliography_utils_1.getReferencesModelMap)(instance.doc);
33
32
  const citationNodes = (0, library_1.buildCitationNodes)(instance.doc, referencesModelMap);
34
- const filteredCitationNodes = citationNodes.filter((node) => !(0, track_changes_utils_1.isDeleted)(node[0]) && !(0, track_changes_utils_1.isRejectedInsert)(node[0]));
35
- const citations = (0, library_1.buildCitations)(filteredCitationNodes, (id) => referencesModelMap.get(id));
36
- const bibliographyItems = (0, library_1.buildBibliographyItems)(filteredCitationNodes, (id) => referencesModelMap.get(id));
33
+ const citations = (0, library_1.buildCitations)(citationNodes, (id) => referencesModelMap.get(id));
34
+ const bibliographyItems = (0, library_1.buildBibliographyItems)(citationNodes, (id) => referencesModelMap.get(id));
37
35
  return {
38
36
  citationNodes,
39
37
  citations,
@@ -43,16 +41,12 @@ exports.default = (props) => {
43
41
  apply(tr, value, oldState, newState) {
44
42
  const referencesModelMap = (0, bibliography_utils_1.getReferencesModelMap)(newState.doc);
45
43
  const citationNodes = (0, library_1.buildCitationNodes)(newState.doc, referencesModelMap);
46
- const filteredCitationNodes = citationNodes.filter((node) => !(0, track_changes_utils_1.isDeleted)(node[0]) && !(0, track_changes_utils_1.isRejectedInsert)(node[0]));
47
- const citations = (0, library_1.buildCitations)(filteredCitationNodes, (id) => referencesModelMap.get(id));
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;
44
+ const citations = (0, library_1.buildCitations)(citationNodes, (id) => referencesModelMap.get(id));
45
+ const bibliographyItems = (0, library_1.buildBibliographyItems)(citationNodes, (id) => referencesModelMap.get(id));
51
46
  return {
52
47
  citationNodes,
53
48
  citations,
54
49
  bibliographyItems,
55
- triggerUpdate,
56
50
  };
57
51
  },
58
52
  },
@@ -80,9 +74,6 @@ exports.default = (props) => {
80
74
  if (selection instanceof prosemirror_state_1.NodeSelection) {
81
75
  tr.setSelection(prosemirror_state_1.NodeSelection.create(tr.doc, selection.from));
82
76
  }
83
- tr.setMeta(exports.bibliographyKey, {
84
- triggerUpdate: true,
85
- });
86
77
  tr.setMeta('origin', exports.bibliographyKey);
87
78
  return tr;
88
79
  }
@@ -92,8 +83,8 @@ exports.default = (props) => {
92
83
  },
93
84
  props: {
94
85
  decorations(state) {
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));
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)));
97
88
  },
98
89
  },
99
90
  });
@@ -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.id), {
44
+ decorations.push(prosemirror_view_1.Decoration.widget(change.from + 1, (0, exports.getAttrsTrackingButton)(change), {
45
45
  key: change.id,
46
46
  }));
47
47
  }
48
48
  });
49
49
  return decorations;
50
50
  };
51
- const getAttrsTrackingButton = (changeID) => {
51
+ const getAttrsTrackingButton = (change) => {
52
52
  const el = document.createElement('button');
53
53
  el.className = 'attrs-popper-button';
54
- el.value = changeID;
54
+ el.value = change.id;
55
55
  el.innerHTML = editIcon;
56
56
  return el;
57
57
  };
@@ -14,160 +14,23 @@
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
  };
40
20
  Object.defineProperty(exports, "__esModule", { value: true });
41
21
  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");
52
22
  const block_view_1 = __importDefault(require("./block_view"));
53
23
  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
- });
72
24
  class BibliographyElementBlockView extends block_view_1.default {
73
25
  constructor() {
74
26
  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
- };
90
27
  this.stopEvent = () => true;
91
28
  this.ignoreMutation = () => true;
92
- this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
93
- const bibliographyItems = bibliography_1.bibliographyKey.getState(this.view.state).bibliographyItems;
94
- const commentsDecorationSet = comment_annotation_1.commentAnnotation.getState(this.view.state);
95
- const commentElementMap = new Map();
96
- const dataTrackedMap = new Map();
97
- this.node.descendants((node, pos) => {
98
- if (commentsDecorationSet) {
99
- const nodePosition = this.getPos() + pos + 2;
100
- const commentWidget = commentsDecorationSet.find(nodePosition, nodePosition);
101
- if (commentWidget.length) {
102
- const commentElement = commentWidget[0].type.toDOM();
103
- commentElementMap.set(commentElement.id, commentElement);
104
- }
105
- }
106
- const dataTracked = node.attrs.dataTracked;
107
- if (dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.length) {
108
- const lastChange = dataTracked[dataTracked.length - 1];
109
- dataTrackedMap.set(node.attrs.id, lastChange);
110
- }
111
- });
112
- const bibliographyFragment = yield createBibliography(bibliographyItems, this.props.cslProps);
113
- const bibItems = bibliographyFragment.querySelectorAll('.bib-item');
114
- bibItems.forEach((element) => {
115
- const doubleButton = document.createElement('div');
116
- const editButton = document.createElement('button');
117
- const commentButton = document.createElement('button');
118
- doubleButton.className = 'bibliography-double-button';
119
- editButton.className = 'bibliography-edit-button';
120
- commentButton.className = 'bibliography-comment-button';
121
- commentButton.addEventListener('click', (e) => {
122
- e.preventDefault();
123
- this.props.setComment((0, transform_1.buildComment)(element.id));
124
- });
125
- editButton.addEventListener('click', (e) => {
126
- e.preventDefault();
127
- this.showPopper(element.id);
128
- this.popperContainer = undefined;
129
- });
130
- editButton.innerHTML = assets_1.editIcon;
131
- commentButton.innerHTML = assets_1.commentIcon;
132
- doubleButton.append(editButton, commentButton);
133
- if (this.props.getCapabilities().seeReferencesButtons &&
134
- !element.querySelector('.bibliography-double-button')) {
135
- element.appendChild(doubleButton);
136
- }
137
- editButton.disabled = !this.props.getCapabilities().editCitationsAndRefs;
138
- const commentElement = commentElementMap.get(element.id);
139
- if (commentElement) {
140
- element.childNodes[0].appendChild(commentElement);
141
- }
142
- const dataTracked = dataTrackedMap.get(element.id);
143
- if (dataTracked) {
144
- element.classList.add('attrs-track-mark');
145
- const decoration = (0, tracking_mark_1.getMarkDecoration)(dataTracked);
146
- decoration.style && element.setAttribute('style', decoration.style);
147
- if (dataTracked.status === track_changes_plugin_1.CHANGE_STATUS.pending &&
148
- dataTracked.operation === track_changes_plugin_1.CHANGE_OPERATION.set_node_attributes) {
149
- element.childNodes[0].appendChild((0, tracking_mark_1.getAttrsTrackingButton)(dataTracked.id));
150
- }
151
- }
152
- });
153
- const oldContent = this.container.querySelector('.contents');
154
- if (oldContent) {
155
- this.container.replaceChild(bibliographyFragment, oldContent);
156
- }
157
- else {
158
- this.container.appendChild(bibliographyFragment);
159
- }
160
- });
161
29
  this.createElement = () => {
162
- this.container = document.createElement('div');
163
- this.container.classList.add('block');
164
- this.container.contentEditable = 'false';
165
- this.dom.appendChild(this.container);
166
30
  this.contentDOM = document.createElement('div');
167
31
  this.contentDOM.classList.add('block');
168
32
  this.contentDOM.setAttribute('id', this.node.attrs.id);
169
- this.contentDOM.hidden = true;
170
- this.container.appendChild(this.contentDOM);
33
+ this.dom.appendChild(this.contentDOM);
171
34
  };
172
35
  }
173
36
  }
@@ -119,7 +119,7 @@ class CitationView extends base_node_view_1.BaseNodeView {
119
119
  const citeprocContent = citeprocCitations === null || citeprocCitations === void 0 ? void 0 : citeprocCitations.get(this.node.attrs.rid);
120
120
  const fragment = (0, dompurify_1.sanitize)(citeprocContent && citeprocContent !== '[NO_PRINTED_FORM]'
121
121
  ? citeprocContent
122
- : ' ', {
122
+ : this.node.attrs.contents, {
123
123
  ALLOWED_TAGS: ['i', 'b', 'span', 'sup', 'sub', '#text'],
124
124
  });
125
125
  citationElement.appendChild(fragment);
@@ -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, triggerUpdate) => {
33
+ export const buildDecorations = (doc, citationNodes, popper, referencesModelMap) => {
34
34
  const decorations = [];
35
35
  let hasMissingItems = false;
36
36
  for (const [node, pos, citation] of citationNodes) {
@@ -68,15 +68,6 @@ export const buildDecorations = (doc, citationNodes, popper, referencesModelMap,
68
68
  }
69
69
  });
70
70
  }
71
- if (triggerUpdate) {
72
- doc.descendants((node, pos) => {
73
- if (isBibliographyElement(node)) {
74
- decorations.push(Decoration.node(pos, pos + node.nodeSize, {}, {
75
- triggerUpdate: true,
76
- }));
77
- }
78
- });
79
- }
80
71
  return decorations;
81
72
  };
82
73
  const cleanData = (model) => pickBy(model, (value) => value !== undefined);
@@ -17,7 +17,6 @@ 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, isRejectedInsert } from '../../lib/track-changes-utils';
21
20
  import { buildDecorations, getReferencesModelMap } from './bibliography-utils';
22
21
  export const bibliographyKey = new PluginKey('bibliography');
23
22
  export default (props) => {
@@ -28,9 +27,8 @@ export default (props) => {
28
27
  init(config, instance) {
29
28
  const referencesModelMap = getReferencesModelMap(instance.doc);
30
29
  const citationNodes = buildCitationNodes(instance.doc, referencesModelMap);
31
- const filteredCitationNodes = citationNodes.filter((node) => !isDeleted(node[0]) && !isRejectedInsert(node[0]));
32
- const citations = buildCitations(filteredCitationNodes, (id) => referencesModelMap.get(id));
33
- const bibliographyItems = buildBibliographyItems(filteredCitationNodes, (id) => referencesModelMap.get(id));
30
+ const citations = buildCitations(citationNodes, (id) => referencesModelMap.get(id));
31
+ const bibliographyItems = buildBibliographyItems(citationNodes, (id) => referencesModelMap.get(id));
34
32
  return {
35
33
  citationNodes,
36
34
  citations,
@@ -40,16 +38,12 @@ export default (props) => {
40
38
  apply(tr, value, oldState, newState) {
41
39
  const referencesModelMap = getReferencesModelMap(newState.doc);
42
40
  const citationNodes = buildCitationNodes(newState.doc, referencesModelMap);
43
- const filteredCitationNodes = citationNodes.filter((node) => !isDeleted(node[0]) && !isRejectedInsert(node[0]));
44
- const citations = buildCitations(filteredCitationNodes, (id) => referencesModelMap.get(id));
45
- const bibliographyItems = buildBibliographyItems(filteredCitationNodes, (id) => referencesModelMap.get(id));
46
- const meta = tr.getMeta(bibliographyKey);
47
- const triggerUpdate = meta && meta.triggerUpdate;
41
+ const citations = buildCitations(citationNodes, (id) => referencesModelMap.get(id));
42
+ const bibliographyItems = buildBibliographyItems(citationNodes, (id) => referencesModelMap.get(id));
48
43
  return {
49
44
  citationNodes,
50
45
  citations,
51
46
  bibliographyItems,
52
- triggerUpdate,
53
47
  };
54
48
  },
55
49
  },
@@ -77,9 +71,6 @@ export default (props) => {
77
71
  if (selection instanceof NodeSelection) {
78
72
  tr.setSelection(NodeSelection.create(tr.doc, selection.from));
79
73
  }
80
- tr.setMeta(bibliographyKey, {
81
- triggerUpdate: true,
82
- });
83
74
  tr.setMeta('origin', bibliographyKey);
84
75
  return tr;
85
76
  }
@@ -89,8 +80,8 @@ export default (props) => {
89
80
  },
90
81
  props: {
91
82
  decorations(state) {
92
- const { citationNodes, triggerUpdate } = bibliographyKey.getState(state);
93
- return DecorationSet.create(state.doc, buildDecorations(state.doc, citationNodes, props.popper, getReferencesModelMap(state.doc), triggerUpdate));
83
+ const { citationNodes } = bibliographyKey.getState(state);
84
+ return DecorationSet.create(state.doc, buildDecorations(state.doc, citationNodes, props.popper, getReferencesModelMap(state.doc)));
94
85
  },
95
86
  },
96
87
  });
@@ -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.id), {
41
+ decorations.push(Decoration.widget(change.from + 1, getAttrsTrackingButton(change), {
42
42
  key: change.id,
43
43
  }));
44
44
  }
45
45
  });
46
46
  return decorations;
47
47
  };
48
- export const getAttrsTrackingButton = (changeID) => {
48
+ export const getAttrsTrackingButton = (change) => {
49
49
  const el = document.createElement('button');
50
50
  el.className = 'attrs-popper-button';
51
- el.value = changeID;
51
+ el.value = change.id;
52
52
  el.innerHTML = editIcon;
53
53
  return el;
54
54
  };
@@ -13,155 +13,18 @@
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';
46
16
  import BlockView from './block_view';
47
17
  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
- });
66
18
  export class BibliographyElementBlockView extends BlockView {
67
19
  constructor() {
68
20
  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
- };
84
21
  this.stopEvent = () => true;
85
22
  this.ignoreMutation = () => true;
86
- this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
87
- const bibliographyItems = bibliographyKey.getState(this.view.state).bibliographyItems;
88
- const commentsDecorationSet = commentAnnotation.getState(this.view.state);
89
- const commentElementMap = new Map();
90
- const dataTrackedMap = new Map();
91
- this.node.descendants((node, pos) => {
92
- if (commentsDecorationSet) {
93
- const nodePosition = this.getPos() + pos + 2;
94
- const commentWidget = commentsDecorationSet.find(nodePosition, nodePosition);
95
- if (commentWidget.length) {
96
- const commentElement = commentWidget[0].type.toDOM();
97
- commentElementMap.set(commentElement.id, commentElement);
98
- }
99
- }
100
- const dataTracked = node.attrs.dataTracked;
101
- if (dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.length) {
102
- const lastChange = dataTracked[dataTracked.length - 1];
103
- dataTrackedMap.set(node.attrs.id, lastChange);
104
- }
105
- });
106
- const bibliographyFragment = yield createBibliography(bibliographyItems, this.props.cslProps);
107
- const bibItems = bibliographyFragment.querySelectorAll('.bib-item');
108
- bibItems.forEach((element) => {
109
- const doubleButton = document.createElement('div');
110
- const editButton = document.createElement('button');
111
- const commentButton = document.createElement('button');
112
- doubleButton.className = 'bibliography-double-button';
113
- editButton.className = 'bibliography-edit-button';
114
- commentButton.className = 'bibliography-comment-button';
115
- commentButton.addEventListener('click', (e) => {
116
- e.preventDefault();
117
- this.props.setComment(buildComment(element.id));
118
- });
119
- editButton.addEventListener('click', (e) => {
120
- e.preventDefault();
121
- this.showPopper(element.id);
122
- this.popperContainer = undefined;
123
- });
124
- editButton.innerHTML = editIcon;
125
- commentButton.innerHTML = commentIcon;
126
- doubleButton.append(editButton, commentButton);
127
- if (this.props.getCapabilities().seeReferencesButtons &&
128
- !element.querySelector('.bibliography-double-button')) {
129
- element.appendChild(doubleButton);
130
- }
131
- editButton.disabled = !this.props.getCapabilities().editCitationsAndRefs;
132
- const commentElement = commentElementMap.get(element.id);
133
- if (commentElement) {
134
- element.childNodes[0].appendChild(commentElement);
135
- }
136
- const dataTracked = dataTrackedMap.get(element.id);
137
- if (dataTracked) {
138
- element.classList.add('attrs-track-mark');
139
- const decoration = getMarkDecoration(dataTracked);
140
- decoration.style && element.setAttribute('style', decoration.style);
141
- if (dataTracked.status === CHANGE_STATUS.pending &&
142
- dataTracked.operation === CHANGE_OPERATION.set_node_attributes) {
143
- element.childNodes[0].appendChild(getAttrsTrackingButton(dataTracked.id));
144
- }
145
- }
146
- });
147
- const oldContent = this.container.querySelector('.contents');
148
- if (oldContent) {
149
- this.container.replaceChild(bibliographyFragment, oldContent);
150
- }
151
- else {
152
- this.container.appendChild(bibliographyFragment);
153
- }
154
- });
155
23
  this.createElement = () => {
156
- this.container = document.createElement('div');
157
- this.container.classList.add('block');
158
- this.container.contentEditable = 'false';
159
- this.dom.appendChild(this.container);
160
24
  this.contentDOM = document.createElement('div');
161
25
  this.contentDOM.classList.add('block');
162
26
  this.contentDOM.setAttribute('id', this.node.attrs.id);
163
- this.contentDOM.hidden = true;
164
- this.container.appendChild(this.contentDOM);
27
+ this.dom.appendChild(this.contentDOM);
165
28
  };
166
29
  }
167
30
  }
@@ -90,7 +90,7 @@ export class CitationView extends BaseNodeView {
90
90
  const citeprocContent = citeprocCitations === null || citeprocCitations === void 0 ? void 0 : citeprocCitations.get(this.node.attrs.rid);
91
91
  const fragment = sanitize(citeprocContent && citeprocContent !== '[NO_PRINTED_FORM]'
92
92
  ? citeprocContent
93
- : ' ', {
93
+ : this.node.attrs.contents, {
94
94
  ALLOWED_TAGS: ['i', 'b', 'span', 'sup', 'sub', '#text'],
95
95
  });
96
96
  citationElement.appendChild(fragment);
@@ -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>, triggerUpdate?: boolean) => Decoration[];
22
+ export declare const buildDecorations: (doc: ManuscriptNode, citationNodes: CitationNodes, popper: PopperManager, referencesModelMap: Map<string, Model>) => 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,7 +29,6 @@ export interface PluginState {
29
29
  citationNodes: CitationNodes;
30
30
  citations: CiteProcCitation[];
31
31
  bibliographyItems: BibliographyItem[];
32
- triggerUpdate?: boolean;
33
32
  }
34
33
  export interface BibliographyProps {
35
34
  getCitationProvider: () => CitationProvider | undefined;
@@ -1,7 +1,7 @@
1
- import { TrackedAttrs } from '@manuscripts/track-changes-plugin';
1
+ import { NodeAttrChange, 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: (changeID: string) => HTMLButtonElement;
6
+ export declare const getAttrsTrackingButton: (change: NodeAttrChange) => HTMLButtonElement;
7
7
  export declare const getMarkDecoration: (dataTracked: TrackedAttrs, htmlNode?: HTMLElement) => DecorationAttrs;
@@ -13,22 +13,11 @@
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';
18
16
  import { BaseNodeProps } from './base_node_view';
19
17
  import BlockView from './block_view';
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;
18
+ export declare class BibliographyElementBlockView<PropsType extends BaseNodeProps> extends BlockView<PropsType> {
29
19
  stopEvent: () => boolean;
30
20
  ignoreMutation: () => boolean;
31
- updateContents: () => Promise<void>;
32
21
  createElement: () => void;
33
22
  }
34
23
  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.5.7-LEAN-2055-0",
4
+ "version": "1.5.7",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -144,4 +144,4 @@
144
144
  "resolutions": {
145
145
  "@types/react": "^17.0.2"
146
146
  }
147
- }
147
+ }
package/styles/Editor.css CHANGED
@@ -731,8 +731,12 @@
731
731
  text-align: center;
732
732
  }
733
733
 
734
+ .ProseMirror .block {
735
+ counter-reset: bib_item;
736
+ }
734
737
 
735
738
  .ProseMirror .bib-item {
739
+ counter-increment: bib_item;
736
740
  position: relative;
737
741
  margin-right: 40px;
738
742
  }
@@ -747,7 +751,11 @@
747
751
 
748
752
  .ProseMirror .csl-left-margin {
749
753
  padding-right: 1ch;
750
- display: table-cell;
754
+ display: none;
755
+ }
756
+
757
+ .ProseMirror .csl-right-inline::before {
758
+ content: counter(bib_item) '. ';
751
759
  }
752
760
 
753
761
  .ProseMirror .csl-entry a {