@manuscripts/body-editor 1.6.13 → 1.6.14-LEAN-3094

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.
Files changed (70) hide show
  1. package/dist/cjs/citation-sources/crossref.js +27 -54
  2. package/dist/cjs/commands.js +5 -6
  3. package/dist/cjs/configs/editor-views.js +4 -4
  4. package/dist/cjs/lib/array-reducer.js +45 -0
  5. package/dist/cjs/lib/mathml-to-svg.js +70 -0
  6. package/dist/cjs/lib/tex-to-svg.js +60 -0
  7. package/dist/cjs/plugins/bibliography/index.js +11 -1
  8. package/dist/cjs/testing/default-editor-data.js +0 -22
  9. package/dist/cjs/views/CitationEditorWrapper.js +65 -0
  10. package/dist/cjs/views/ReferencesEditor.js +50 -0
  11. package/dist/cjs/views/base_node_view.js +1 -1
  12. package/dist/cjs/views/bibliography_element.js +20 -27
  13. package/dist/cjs/views/citation.js +1 -72
  14. package/dist/cjs/views/citation_editable.js +91 -106
  15. package/dist/cjs/views/cross_reference_editable.js +12 -10
  16. package/dist/cjs/views/equation.js +8 -3
  17. package/dist/cjs/views/equation_editable.js +3 -9
  18. package/dist/cjs/views/equation_element.js +6 -3
  19. package/dist/cjs/views/inline_equation.js +8 -3
  20. package/dist/cjs/views/inline_equation_editable.js +3 -9
  21. package/dist/cjs/views/link_editable.js +42 -34
  22. package/dist/es/citation-sources/crossref.js +27 -54
  23. package/dist/es/commands.js +6 -7
  24. package/dist/es/configs/editor-views.js +4 -4
  25. package/dist/es/lib/array-reducer.js +41 -0
  26. package/dist/es/lib/mathml-to-svg.js +66 -0
  27. package/dist/es/lib/tex-to-svg.js +56 -0
  28. package/dist/es/plugins/bibliography/index.js +11 -1
  29. package/dist/es/testing/default-editor-data.js +0 -22
  30. package/dist/es/views/CitationEditorWrapper.js +38 -0
  31. package/dist/es/views/ReferencesEditor.js +23 -0
  32. package/dist/es/views/base_node_view.js +1 -1
  33. package/dist/es/views/bibliography_element.js +21 -28
  34. package/dist/es/views/citation.js +1 -49
  35. package/dist/es/views/citation_editable.js +92 -107
  36. package/dist/es/views/cross_reference_editable.js +12 -10
  37. package/dist/es/views/editable_block.js +1 -1
  38. package/dist/es/views/equation.js +8 -3
  39. package/dist/es/views/equation_editable.js +3 -9
  40. package/dist/es/views/equation_element.js +6 -3
  41. package/dist/es/views/inline_equation.js +8 -3
  42. package/dist/es/views/inline_equation_editable.js +3 -9
  43. package/dist/es/views/link_editable.js +42 -34
  44. package/dist/types/citation-sources/crossref.d.ts +2 -11
  45. package/dist/types/commands.d.ts +3 -3
  46. package/dist/types/components/views/LinkForm.d.ts +2 -2
  47. package/dist/types/configs/ManuscriptsEditor.d.ts +1 -6
  48. package/dist/types/configs/editor-plugins.d.ts +1 -2
  49. package/dist/types/configs/editor-views.d.ts +1 -3
  50. package/dist/types/lib/array-reducer.d.ts +25 -0
  51. package/dist/types/lib/context-menu.d.ts +1 -1
  52. package/dist/types/{plugins/models.d.ts → lib/mathml-to-svg.d.ts} +2 -13
  53. package/dist/types/lib/tex-to-svg.d.ts +18 -0
  54. package/dist/types/plugins/bibliography/index.d.ts +1 -1
  55. package/dist/types/views/CitationEditorWrapper.d.ts +3 -0
  56. package/dist/types/views/ReferencesEditor.d.ts +4 -0
  57. package/dist/types/views/base_node_view.d.ts +0 -3
  58. package/dist/types/views/bibliography_element.d.ts +6 -5
  59. package/dist/types/views/citation.d.ts +2 -14
  60. package/dist/types/views/citation_editable.d.ts +12 -6
  61. package/dist/types/views/cross_reference.d.ts +0 -1
  62. package/dist/types/views/editable_block.d.ts +2 -4
  63. package/dist/types/views/keyword_group.d.ts +3 -15
  64. package/dist/types/views/link_editable.d.ts +3 -0
  65. package/package.json +6 -5
  66. package/dist/cjs/plugins/models.js +0 -48
  67. package/dist/cjs/views/ReactView.js +0 -94
  68. package/dist/es/plugins/models.js +0 -45
  69. package/dist/es/views/ReactView.js +0 -66
  70. package/dist/types/views/ReactView.d.ts +0 -33
@@ -13,92 +13,92 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- };
25
- var __rest = (this && this.__rest) || function (s, e) {
26
- var t = {};
27
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
- t[p] = s[p];
29
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
- t[p[i]] = s[p[i]];
33
- }
34
- return t;
35
- };
36
16
  import { ObjectTypes, } from '@manuscripts/json-schema';
37
17
  import { findMatchingBibliographyItem } from '@manuscripts/library';
38
- import { schema } from '@manuscripts/transform';
18
+ import { CitationViewer, } from '@manuscripts/style-guide';
19
+ import { buildComment, Decoder, schema, } from '@manuscripts/transform';
39
20
  import { TextSelection } from 'prosemirror-state';
40
- import React from 'react';
21
+ import { findChildren, findChildrenByType } from 'prosemirror-utils';
22
+ import { crossref } from '../citation-sources';
23
+ import { isDeleted } from '../lib/track-changes-utils';
41
24
  import { getBibliographyPluginState } from '../plugins/bibliography';
42
25
  import { CitationView } from './citation';
26
+ import { CitationEditorWrapper } from './CitationEditorWrapper';
43
27
  import { createEditableNodeView } from './creators';
44
- const createBibliographySection = (bibItem) => schema.nodes.bibliography_section.createAndFill({}, [
45
- schema.nodes.section_title.create({}, schema.text('References')),
46
- schema.nodes.bibliography_element.create({}, bibItem ? [bibItem] : []),
28
+ import ReactSubView from './ReactSubView';
29
+ const createBibliographySection = (node) => schema.nodes.bibliography_section.createAndFill({}, [
30
+ schema.nodes.section_title.create({}, schema.text('Bibliography')),
31
+ schema.nodes.bibliography_element.create({}, node ? [node] : []),
47
32
  ]);
48
33
  export class CitationEditableView extends CitationView {
49
34
  constructor() {
50
35
  super(...arguments);
36
+ this.decoder = new Decoder(new Map());
37
+ this.selectNode = () => {
38
+ if (!isDeleted(this.node)) {
39
+ this.showPopper();
40
+ this.dom.classList.add('ProseMirror-selectednode');
41
+ }
42
+ };
43
+ this.deselectNode = () => {
44
+ var _a;
45
+ (_a = this.editor) === null || _a === void 0 ? void 0 : _a.remove();
46
+ this.dom.classList.remove('ProseMirror-selectednode');
47
+ this.props.popper.destroy();
48
+ };
49
+ this.destroy = () => {
50
+ var _a;
51
+ (_a = this.editor) === null || _a === void 0 ? void 0 : _a.remove();
52
+ this.props.popper.destroy();
53
+ };
51
54
  this.showPopper = () => {
52
- const { components: { CitationEditor, CitationViewer }, getCapabilities, projectID, renderReactComponent, } = this.props;
53
- const capabilities = getCapabilities();
55
+ const can = this.props.getCapabilities();
54
56
  const citation = this.getCitation();
55
- const items = this.getBibliographyItems();
56
- const updateCitation = (data) => __awaiter(this, void 0, void 0, function* () {
57
- this.updateNode(Object.assign(Object.assign({}, citation), data));
58
- this.props.popper.update();
59
- });
60
- const findPosition = (doc, id) => {
61
- let nodePos = undefined;
62
- doc.descendants((node, pos) => {
63
- if (node.attrs.id === id) {
64
- nodePos = pos;
65
- }
66
- });
67
- return nodePos;
68
- };
69
- const handleSave = (data) => __awaiter(this, void 0, void 0, function* () {
70
- if (data._id && !findPosition(this.view.state.doc, data._id)) {
71
- this.insertBibliographyNode(this.view, data);
72
- }
73
- else {
74
- const _a = data, { _id: id, 'container-title': containerTitle, DOI: doi } = _a, rest = __rest(_a, ["_id", 'container-title', "DOI"]);
75
- this.updateNodeAttrs(Object.assign({ id,
76
- containerTitle,
77
- doi }, rest));
78
- }
79
- });
80
- if (!this.popperContainer) {
81
- this.popperContainer = document.createElement('div');
82
- this.popperContainer.className = 'citation-editor';
83
- }
57
+ const rids = citation.embeddedCitationItems.map((i) => i.bibliographyItem);
84
58
  const bib = getBibliographyPluginState(this.view.state);
85
- const component = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.editArticle) ? (React.createElement(CitationEditor, { items: items, saveModel: handleSave, deleteModel: this.deleteNode, insertBibliographyNode: (item) => this.insertBibliographyNode(this.view, item), modelMap: bib.bibliographyItems, 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 }));
86
- renderReactComponent(component, this.popperContainer);
87
- this.props.popper.show(this.dom, this.popperContainer, 'right');
59
+ const items = Array.from(bib.bibliographyItems.values());
60
+ if (can.editArticle) {
61
+ const query = this.node.attrs.selectedText;
62
+ const componentProps = {
63
+ query,
64
+ rids,
65
+ items,
66
+ citationCounts: bib.citationCounts,
67
+ sources: [crossref],
68
+ onCite: this.handleCite,
69
+ onUncite: this.handleUncite,
70
+ onSave: this.handleSave,
71
+ onDelete: this.handleDelete,
72
+ onComment: this.handleComment,
73
+ onCancel: this.handleCancel,
74
+ canEdit: can.editCitationsAndRefs,
75
+ };
76
+ this.editor = ReactSubView(this.props, CitationEditorWrapper, componentProps, this.node, this.getPos, this.view, 'citation-editor');
77
+ }
78
+ else {
79
+ const componentProps = {
80
+ rids,
81
+ items,
82
+ };
83
+ this.editor = ReactSubView(this.props, CitationViewer, componentProps, this.node, this.getPos, this.view, 'citation-editor');
84
+ }
85
+ this.props.popper.show(this.dom, this.editor, 'right');
88
86
  };
89
- this.handleClose = () => {
87
+ this.handleCancel = () => {
90
88
  const selection = TextSelection.create(this.view.state.tr.doc, this.getPos() + 1);
91
89
  this.view.dispatch(this.view.state.tr.setSelection(selection));
92
90
  this.props.popper.destroy();
93
91
  };
94
- this.handleCancel = () => {
95
- const { state } = this.view;
96
- const pos = this.getPos();
97
- const tr = state.tr.delete(pos, pos + this.node.nodeSize);
98
- const selection = TextSelection.create(tr.doc, pos);
99
- this.view.dispatch(tr.setSelection(selection));
92
+ this.handleSave = (item) => {
93
+ if (item._id && !this.findPosition(item._id)) {
94
+ this.insertBibliographyNode(item);
95
+ }
96
+ else {
97
+ const node = this.decoder.decode(item);
98
+ this.updateNodeAttrs(node.attrs);
99
+ }
100
100
  };
101
- this.handleRemove = (id) => __awaiter(this, void 0, void 0, function* () {
101
+ this.handleUncite = (id) => {
102
102
  const citation = this.getCitation();
103
103
  const items = citation.embeddedCitationItems.filter((i) => i.bibliographyItem !== id);
104
104
  if (items.length > 0) {
@@ -115,23 +115,19 @@ export class CitationEditableView extends CitationView {
115
115
  this.view.dispatch(tr);
116
116
  }
117
117
  this.props.popper.destroy();
118
- });
119
- this.updatePopper = () => {
120
- this.props.popper.destroy();
121
- window.setTimeout(() => {
122
- this.showPopper();
123
- }, 100);
124
118
  };
125
- this.handleCite = (items) => __awaiter(this, void 0, void 0, function* () {
119
+ this.handleCite = (items) => {
126
120
  const bib = getBibliographyPluginState(this.view.state);
127
121
  const citation = this.getCitation();
122
+ const rids = citation.embeddedCitationItems.map((i) => i.bibliographyItem);
123
+ items = items.filter((i) => !rids.includes(i._id));
128
124
  for (const item of items) {
129
125
  const existingItem = findMatchingBibliographyItem(item, bib.bibliographyItems);
130
126
  if (existingItem) {
131
127
  item._id = existingItem._id;
132
128
  }
133
129
  else {
134
- this.insertBibliographyNode(this.view, item);
130
+ this.insertBibliographyNode(item);
135
131
  }
136
132
  citation.embeddedCitationItems.push({
137
133
  _id: '_',
@@ -140,20 +136,15 @@ export class CitationEditableView extends CitationView {
140
136
  });
141
137
  }
142
138
  this.updateNode(citation);
143
- this.handleClose();
144
- });
145
- this.importItems = (items) => __awaiter(this, void 0, void 0, function* () {
146
- const bib = getBibliographyPluginState(this.view.state);
147
- const newItems = [];
148
- for (const item of items) {
149
- const existingItem = findMatchingBibliographyItem(item, bib.bibliographyItems);
150
- if (!existingItem) {
151
- this.insertBibliographyNode(this.view, item);
152
- newItems.push(item);
153
- }
154
- }
155
- return newItems;
156
- });
139
+ this.handleCancel();
140
+ };
141
+ this.handleDelete = (item) => {
142
+ return this.deleteNode(item._id);
143
+ };
144
+ this.handleComment = () => {
145
+ const comment = buildComment(this.node.attrs.id);
146
+ this.props.setComment(comment);
147
+ };
157
148
  this.updateNode = (citation) => {
158
149
  const rids = citation.embeddedCitationItems.map((i) => i.bibliographyItem);
159
150
  const { tr } = this.view.state;
@@ -162,28 +153,22 @@ export class CitationEditableView extends CitationView {
162
153
  rids,
163
154
  }));
164
155
  };
156
+ this.findPosition = (id) => {
157
+ const doc = this.view.state.doc;
158
+ const children = findChildren(doc, (n) => n.attrs.id === id);
159
+ return children.length ? children[0] : undefined;
160
+ };
165
161
  }
166
- insertBibliographyNode(view, item) {
167
- const { doc, tr } = view.state;
168
- const { DOI: doi, ['container-title']: containerTitle } = item, restAttr = __rest(item, ["DOI", 'container-title']);
169
- let bibElement = null;
170
- let pos = null;
171
- doc.descendants((node, nodePos) => {
172
- if (node.type === schema.nodes.bibliography_element) {
173
- bibElement = node;
174
- pos = nodePos;
175
- }
176
- });
177
- let newTr;
178
- const bibItem = schema.nodes.bibliography_item.create(Object.assign({ id: item._id, doi,
179
- containerTitle }, restAttr));
180
- if (bibElement && pos) {
181
- newTr = tr.insert(pos + 1, bibItem);
162
+ insertBibliographyNode(item) {
163
+ const { doc, tr } = this.view.state;
164
+ const elements = findChildrenByType(doc, schema.nodes.bibliography_element, true);
165
+ const node = this.decoder.decode(item);
166
+ if (elements.length) {
167
+ this.view.dispatch(tr.insert(elements[0].pos + 1, node));
182
168
  }
183
169
  else {
184
- newTr = tr.insert(tr.doc.content.size, createBibliographySection(bibItem));
170
+ this.view.dispatch(tr.insert(tr.doc.content.size, createBibliographySection(node)));
185
171
  }
186
- view.dispatch(newTr);
187
172
  return false;
188
173
  }
189
174
  }
@@ -24,34 +24,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
24
24
  };
25
25
  import { skipTracking } from '@manuscripts/track-changes-plugin';
26
26
  import { TextSelection } from 'prosemirror-state';
27
- import React from 'react';
28
27
  import { CrossReferenceItems } from '../components/views/CrossReferenceItems';
29
28
  import { objectsKey } from '../plugins/objects';
30
29
  import { createEditableNodeView } from './creators';
31
30
  import { CrossReferenceView } from './cross_reference';
31
+ import ReactSubView from './ReactSubView';
32
32
  export class CrossReferenceEditableView extends CrossReferenceView {
33
33
  constructor() {
34
34
  super(...arguments);
35
35
  this.selectNode = () => {
36
- const { getCapabilities, renderReactComponent } = this.props;
36
+ const { getCapabilities } = this.props;
37
37
  const xref = this.node;
38
38
  const rids = xref.attrs.rids;
39
39
  const can = getCapabilities();
40
40
  if (!(can === null || can === void 0 ? void 0 : can.editArticle) || rids.length) {
41
41
  return;
42
42
  }
43
- if (!this.popperContainer) {
44
- this.popperContainer = document.createElement('div');
45
- this.popperContainer.className = 'cross-reference-editor';
46
- }
47
- renderReactComponent(React.createElement(CrossReferenceItems, { handleSelect: this.handleSelect, targets: this.getTargets(), handleCancel: this.handleCancel, currentTargetId: rids[0], currentCustomLabel: this.node.attrs.customLabel }), this.popperContainer);
43
+ const componentProps = {
44
+ handleSelect: this.handleSelect,
45
+ targets: this.getTargets(),
46
+ handleCancel: this.handleCancel,
47
+ currentTargetId: rids[0],
48
+ currentCustomLabel: this.node.attrs.customLabel,
49
+ };
50
+ this.popperContainer = ReactSubView(this.props, CrossReferenceItems, componentProps, this.node, this.getPos, this.view, 'cross-reference-editor');
48
51
  this.props.popper.show(this.dom, this.popperContainer, 'right');
49
52
  };
50
53
  this.destroy = () => {
54
+ var _a;
51
55
  this.props.popper.destroy();
52
- if (this.popperContainer) {
53
- this.props.unmountReactComponent(this.popperContainer);
54
- }
56
+ (_a = this.popperContainer) === null || _a === void 0 ? void 0 : _a.remove();
55
57
  };
56
58
  this.deselectNode = () => {
57
59
  this.handleCancel();
@@ -22,7 +22,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
23
  });
24
24
  };
25
- import { nodeNames, schema, } from '@manuscripts/transform';
25
+ import { nodeNames, schema } from '@manuscripts/transform';
26
26
  import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils';
27
27
  import { ContextMenu } from '../lib/context-menu';
28
28
  const isNotNull = (a) => a !== null;
@@ -14,6 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { sanitize } from '../lib/dompurify';
17
+ import { convertMathMLToSVG } from '../lib/mathml-to-svg';
18
+ import { convertTeXToSVG } from '../lib/tex-to-svg';
17
19
  import { BaseNodeView } from './base_node_view';
18
20
  import { createNodeView } from './creators';
19
21
  export class EquationView extends BaseNodeView {
@@ -29,12 +31,15 @@ export class EquationView extends BaseNodeView {
29
31
  this.dom.setAttribute('id', this.node.attrs.id);
30
32
  };
31
33
  this.updateContents = () => {
32
- const { SVGStringRepresentation } = this.node.attrs;
34
+ const { contents, format } = this.node.attrs;
35
+ const svgContent = format === 'tex'
36
+ ? convertTeXToSVG(contents, true)
37
+ : convertMathMLToSVG(contents, true);
33
38
  while (this.dom.hasChildNodes()) {
34
39
  this.dom.removeChild(this.dom.firstChild);
35
40
  }
36
- if (SVGStringRepresentation) {
37
- const fragment = sanitize(SVGStringRepresentation, {
41
+ if (svgContent) {
42
+ const fragment = sanitize(svgContent, {
38
43
  USE_PROFILES: { svg: true },
39
44
  });
40
45
  this.dom.appendChild(fragment);
@@ -22,7 +22,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
23
  });
24
24
  };
25
- import { convertTeXToSVG } from '@manuscripts/transform';
26
25
  import { NodeSelection } from 'prosemirror-state';
27
26
  import { createEditableNodeView } from './creators';
28
27
  import { EquationView } from './equation';
@@ -36,21 +35,16 @@ export class EquationEditableView extends EquationView {
36
35
  const { createEditor } = yield import('../lib/codemirror');
37
36
  const placeholder = 'Enter LaTeX equation, e.g. "a^2 = \\sqrt{b^2 + c^2}"';
38
37
  const input = yield createEditor({
39
- value: this.node.attrs.TeXRepresentation || '',
38
+ value: this.node.attrs.contents || '',
40
39
  mode: 'stex',
41
40
  placeholder,
42
41
  autofocus: true,
43
42
  });
44
43
  input.on('changes', () => __awaiter(this, void 0, void 0, function* () {
45
- const TeXRepresentation = input.getValue();
46
- const SVGStringRepresentation = yield convertTeXToSVG(TeXRepresentation, true);
47
- if (!SVGStringRepresentation) {
48
- throw new Error('No SVG output from MathJax');
49
- }
44
+ const contents = input.getValue();
50
45
  const pos = this.getPos();
51
46
  const { tr } = this.view.state;
52
- tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { TeXRepresentation,
53
- SVGStringRepresentation })).setSelection(NodeSelection.create(tr.doc, pos));
47
+ tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { contents, format: 'tex' })).setSelection(NodeSelection.create(tr.doc, pos));
54
48
  this.view.dispatch(tr);
55
49
  }));
56
50
  const wrapper = document.createElement('div');
@@ -21,9 +21,12 @@ export class EquationElementView extends BlockView {
21
21
  this.elementType = 'figure';
22
22
  this.updateContents = () => {
23
23
  var _a;
24
- const { suppressCaption, suppressTitle } = this.node.attrs;
25
- this.dom.classList.toggle('suppress-caption', suppressCaption);
26
- this.dom.classList.toggle('suppress-title', suppressTitle === undefined ? true : suppressTitle);
24
+ const { label } = this.node.attrs;
25
+ if (label) {
26
+ const labelEl = document.createElement('label');
27
+ labelEl.textContent = label;
28
+ this.dom.appendChild(labelEl);
29
+ }
27
30
  if ((_a = this.node.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.length) {
28
31
  const lastChange = this.node.attrs.dataTracked[this.node.attrs.dataTracked.length - 1];
29
32
  this.dom.setAttribute('data-track-status', lastChange.status);
@@ -14,6 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { sanitize } from '../lib/dompurify';
17
+ import { convertMathMLToSVG } from '../lib/mathml-to-svg';
18
+ import { convertTeXToSVG } from '../lib/tex-to-svg';
17
19
  import { isRejectedInsert } from '../lib/track-changes-utils';
18
20
  import { BaseNodeView } from './base_node_view';
19
21
  import { createNodeView } from './creators';
@@ -26,12 +28,15 @@ export class InlineEquationView extends BaseNodeView {
26
28
  };
27
29
  this.updateContents = () => {
28
30
  if (!isRejectedInsert(this.node)) {
29
- const { SVGRepresentation } = this.node.attrs;
31
+ const { contents, format } = this.node.attrs;
30
32
  while (this.dom.hasChildNodes()) {
31
33
  this.dom.removeChild(this.dom.firstChild);
32
34
  }
33
- if (SVGRepresentation) {
34
- const fragment = sanitize(SVGRepresentation, {
35
+ const svgContent = format === 'tex'
36
+ ? convertTeXToSVG(contents, true)
37
+ : convertMathMLToSVG(contents, true);
38
+ if (svgContent) {
39
+ const fragment = sanitize(svgContent, {
35
40
  USE_PROFILES: { svg: true },
36
41
  });
37
42
  this.dom.appendChild(fragment);
@@ -22,7 +22,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
23
  });
24
24
  };
25
- import { convertTeXToSVG } from '@manuscripts/transform';
26
25
  import { NodeSelection } from 'prosemirror-state';
27
26
  import { createEditableNodeView } from './creators';
28
27
  import { InlineEquationView } from './inline_equation';
@@ -36,21 +35,16 @@ export class InlineEquationEditableView extends InlineEquationView {
36
35
  const { createEditor } = yield import('../lib/codemirror');
37
36
  const placeholder = 'Enter LaTeX equation, e.g. "E=mc^2"';
38
37
  const input = yield createEditor({
39
- value: this.node.attrs.TeXRepresentation || '',
38
+ value: this.node.attrs.contents || '',
40
39
  mode: 'stex',
41
40
  placeholder,
42
41
  autofocus: true,
43
42
  });
44
43
  input.on('changes', () => __awaiter(this, void 0, void 0, function* () {
45
- const TeXRepresentation = input.getValue();
46
- const SVGRepresentation = yield convertTeXToSVG(TeXRepresentation, true);
47
- if (!SVGRepresentation) {
48
- throw new Error('No SVG output from MathJax');
49
- }
44
+ const contents = input.getValue();
50
45
  const pos = this.getPos();
51
46
  const { tr } = this.view.state;
52
- tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { TeXRepresentation,
53
- SVGRepresentation })).setSelection(NodeSelection.create(tr.doc, pos));
47
+ tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { format: 'tex', contents })).setSelection(NodeSelection.create(tr.doc, pos));
54
48
  this.view.dispatch(tr);
55
49
  }));
56
50
  this.props.popper.show(this.dom, input.getWrapperElement(), 'bottom');
@@ -14,10 +14,10 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { TextSelection } from 'prosemirror-state';
17
- import React from 'react';
18
17
  import { LinkForm } from '../components/views/LinkForm';
19
18
  import { createEditableNodeView } from './creators';
20
19
  import { LinkView } from './link';
20
+ import ReactSubView from './ReactSubView';
21
21
  export class LinkEditableView extends LinkView {
22
22
  constructor() {
23
23
  super(...arguments);
@@ -46,43 +46,51 @@ export class LinkEditableView extends LinkView {
46
46
  title: this.node.attrs.title,
47
47
  text: this.node.textContent,
48
48
  };
49
- this.props.renderReactComponent(React.createElement(LinkForm, { value: originalValue, handleCancel: () => {
50
- const tr = this.view.state.tr;
51
- const pos = this.getPos();
52
- tr.setSelection(TextSelection.create(tr.doc, pos));
53
- this.view.focus();
54
- this.view.dispatch(tr);
55
- this.closeForm();
56
- }, handleRemove: () => {
57
- const { tr } = this.view.state;
58
- const pos = this.getPos();
59
- const to = pos + this.node.nodeSize;
60
- tr.replaceWith(pos, to, this.node.content).setSelection(TextSelection.create(tr.doc, pos));
61
- this.view.focus();
62
- this.view.dispatch(tr);
63
- this.closeForm();
64
- }, handleSave: (data) => {
65
- const tr = this.view.state.tr;
66
- const pos = this.getPos();
67
- if (data.href !== originalValue.href ||
68
- data.title !== originalValue.title) {
69
- tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { href: data.href, title: data.title }));
70
- }
71
- if (data.text !== originalValue.text) {
72
- tr.insertText(data.text, pos + 1, pos + this.node.nodeSize - 1);
73
- }
74
- tr.setSelection(TextSelection.create(tr.doc, pos));
75
- this.view.focus();
76
- this.view.dispatch(tr);
77
- this.closeForm();
78
- } }), this.popperContainer);
49
+ const componentProps = {
50
+ value: originalValue,
51
+ handleCancel: this.handleCancel,
52
+ handleRemove: this.handleRemove,
53
+ handleSave: this.handleSave,
54
+ };
55
+ this.popperContainer = ReactSubView(this.props, LinkForm, componentProps, this.node, this.getPos, this.view);
79
56
  this.props.popper.show(this.dom, this.popperContainer, 'bottom');
80
57
  };
58
+ this.handleCancel = () => {
59
+ const tr = this.view.state.tr;
60
+ const pos = this.getPos();
61
+ tr.setSelection(TextSelection.create(tr.doc, pos));
62
+ this.view.focus();
63
+ this.view.dispatch(tr);
64
+ this.closeForm();
65
+ };
66
+ this.handleRemove = () => {
67
+ const tr = this.view.state.tr;
68
+ const pos = this.getPos();
69
+ const to = pos + this.node.nodeSize;
70
+ tr.replaceWith(pos, to, this.node.content).setSelection(TextSelection.create(tr.doc, pos));
71
+ this.view.focus();
72
+ this.view.dispatch(tr);
73
+ this.closeForm();
74
+ };
75
+ this.handleSave = (value) => {
76
+ const tr = this.view.state.tr;
77
+ const link = this.node;
78
+ const pos = this.getPos();
79
+ if (value.href !== link.attrs.href || value.title !== link.attrs.title) {
80
+ tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { href: value.href, title: value.title }));
81
+ }
82
+ if (value.text !== link.textContent) {
83
+ tr.insertText(value.text, pos + 1, pos + this.node.nodeSize - 1);
84
+ }
85
+ tr.setSelection(TextSelection.create(tr.doc, pos));
86
+ this.view.focus();
87
+ this.view.dispatch(tr);
88
+ this.closeForm();
89
+ };
81
90
  this.closeForm = () => {
91
+ var _a;
82
92
  this.props.popper.destroy();
83
- if (this.popperContainer) {
84
- this.props.unmountReactComponent(this.popperContainer);
85
- }
93
+ (_a = this.popperContainer) === null || _a === void 0 ? void 0 : _a.remove();
86
94
  };
87
95
  }
88
96
  }
@@ -13,14 +13,5 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { BibliographyItem } from '@manuscripts/json-schema';
17
- import { CancelToken } from 'axios';
18
- interface SearchResults {
19
- items: BibliographyItem[];
20
- total: number;
21
- }
22
- export declare const crossref: {
23
- fetch: (item: Partial<BibliographyItem>) => Promise<Partial<BibliographyItem>>;
24
- search: (query: string, rows: number, mailto: string, tokenSource?: CancelToken) => Promise<SearchResults>;
25
- };
26
- export {};
16
+ import { BibliographyItemSource } from '@manuscripts/style-guide';
17
+ export declare const crossref: BibliographyItemSource;
@@ -32,15 +32,15 @@ export declare const deleteBlock: (typeToDelete: string) => (state: ManuscriptEd
32
32
  export declare const insertBreak: EditorAction;
33
33
  export declare const insertSectionLabel: (state: ManuscriptEditorState, dispatch?: Dispatch, currentTr?: Transaction) => boolean;
34
34
  export declare const insertLink: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
35
- export declare const insertInlineCitation: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: ManuscriptEditorView) => boolean;
35
+ export declare const insertInlineCitation: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
36
36
  export declare const insertCrossReference: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
37
37
  export declare const insertInlineEquation: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
38
38
  export declare const insertInlineFootnote: (kind: 'footnote' | 'endnote') => (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
39
39
  export declare const insertGraphicalAbstract: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
40
40
  export declare const insertSection: (subsection?: boolean) => (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
41
41
  export declare const insertList: (type: ManuscriptNodeType, style?: string) => (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
42
- export declare const insertBibliographySection: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
43
- export declare const insertTOCSection: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
42
+ export declare const insertBibliographySection: () => boolean;
43
+ export declare const insertTOCSection: () => boolean;
44
44
  export declare const ifInTableBody: (command: (state: ManuscriptEditorState) => boolean) => (state: ManuscriptEditorState) => boolean;
45
45
  export declare const isAtStartOfTextBlock: (state: ManuscriptEditorState, $cursor: ResolvedPos, view?: ManuscriptEditorView) => boolean;
46
46
  export declare const isTextSelection: (selection: Selection) => selection is TextSelection;
@@ -20,8 +20,8 @@ export interface LinkValue {
20
20
  title?: string;
21
21
  }
22
22
  export declare const LinkForm: React.FC<{
23
- handleCancel: (event: React.MouseEvent<HTMLButtonElement>) => void;
24
- handleRemove: (event: React.MouseEvent<HTMLButtonElement>) => void;
23
+ handleCancel: () => void;
24
+ handleRemove: () => void;
25
25
  handleSave: (value: LinkValue) => void;
26
26
  value: LinkValue;
27
27
  }>;
@@ -16,11 +16,10 @@
16
16
  import 'prosemirror-view/style/prosemirror.css';
17
17
  import { CommentAnnotation, Manuscript, Model, UserProfile } from '@manuscripts/json-schema';
18
18
  import { Capabilities, FileAttachment, FileManagement } from '@manuscripts/style-guide';
19
- import { Build, ManuscriptNode } from '@manuscripts/transform';
19
+ import { ManuscriptNode } from '@manuscripts/transform';
20
20
  import { History } from 'history';
21
21
  import { EditorState, Plugin } from 'prosemirror-state';
22
22
  import { EditorView } from 'prosemirror-view';
23
- import React from 'react';
24
23
  import { DefaultTheme } from 'styled-components';
25
24
  import { CollabProvider } from '../classes/collabProvider';
26
25
  import { Dispatch } from '../commands';
@@ -41,15 +40,11 @@ export interface EditorProps {
41
40
  doc: ManuscriptNode;
42
41
  getModelMap: () => Map<string, Model>;
43
42
  getManuscript: () => Manuscript;
44
- saveModel: <T extends Model>(model: T | Build<T> | Partial<T>) => Promise<T>;
45
43
  deleteModel: (id: string) => Promise<string>;
46
44
  getFiles: () => FileAttachment[];
47
45
  fileManagement: FileManagement;
48
46
  popper: PopperManager;
49
47
  history: History;
50
- renderReactComponent: (child: React.ReactNode, container: HTMLElement) => void;
51
- unmountReactComponent: (container: HTMLElement) => void;
52
- components: Record<string, React.ComponentType<any>>;
53
48
  getCapabilities: () => Capabilities;
54
49
  cslProps: CSLProps;
55
50
  setComment: (comment?: CommentAnnotation) => void;