@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
@@ -14,37 +14,13 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
24
- }) : (function(o, m, k, k2) {
25
- if (k2 === undefined) k2 = k;
26
- o[k2] = m[k];
27
- }));
28
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }) : function(o, v) {
31
- o["default"] = v;
32
- });
33
- var __importStar = (this && this.__importStar) || function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
17
  var __importDefault = (this && this.__importDefault) || function (mod) {
41
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
42
19
  };
43
20
  Object.defineProperty(exports, "__esModule", { value: true });
44
21
  exports.CitationView = void 0;
45
- const json_schema_1 = require("@manuscripts/json-schema");
46
22
  const prosemirror_model_1 = require("prosemirror-model");
47
- const react_1 = __importStar(require("react"));
23
+ const react_1 = require("react");
48
24
  const react_dom_1 = __importDefault(require("react-dom"));
49
25
  const TrackChangesReview_1 = require("../components/track-changes/TrackChangesReview");
50
26
  const dompurify_1 = require("../lib/dompurify");
@@ -56,38 +32,7 @@ const creators_1 = require("./creators");
56
32
  class CitationView extends base_node_view_1.BaseNodeView {
57
33
  constructor() {
58
34
  super(...arguments);
59
- this.showPopper = () => {
60
- const { components: { CitationViewer }, projectID, renderReactComponent, } = this.props;
61
- const items = this.getBibliographyItems();
62
- if (!this.popperContainer) {
63
- this.popperContainer = document.createElement('div');
64
- this.popperContainer.className = 'citation-editor';
65
- }
66
- renderReactComponent(react_1.default.createElement(CitationViewer, { items: items, projectID: projectID, scheduleUpdate: this.props.popper.update }), this.popperContainer);
67
- this.props.popper.show(this.dom, this.popperContainer, 'right');
68
- };
69
35
  this.ignoreMutation = () => true;
70
- this.selectNode = () => {
71
- var _a;
72
- const isDeleted = !!((_a = this.node.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.find(({ operation, status }) => operation === 'delete' && status !== 'rejected'));
73
- if (!isDeleted) {
74
- this.showPopper();
75
- this.dom.classList.add('ProseMirror-selectednode');
76
- }
77
- };
78
- this.deselectNode = () => {
79
- this.dom.classList.remove('ProseMirror-selectednode');
80
- this.props.popper.destroy();
81
- if (this.popperContainer) {
82
- this.props.unmountReactComponent(this.popperContainer);
83
- }
84
- };
85
- this.destroy = () => {
86
- this.props.popper.destroy();
87
- if (this.popperContainer) {
88
- this.props.unmountReactComponent(this.popperContainer);
89
- }
90
- };
91
36
  this.initialise = () => {
92
37
  if (!this.node.type.spec.toDOM) {
93
38
  throw Error(`Node view ${this.node.type} doesn't have toDOM method`);
@@ -138,22 +83,6 @@ class CitationView extends base_node_view_1.BaseNodeView {
138
83
  }
139
84
  return citation;
140
85
  };
141
- this.getBibliographyItems = () => {
142
- const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
143
- const citation = this.node;
144
- return citation.attrs.rids.map((rid) => {
145
- const item = bib.bibliographyItems.get(rid);
146
- if (!item) {
147
- const placeholder = {
148
- _id: rid,
149
- objectType: json_schema_1.ObjectTypes.BibliographyItem,
150
- title: '[missing library item]',
151
- };
152
- return placeholder;
153
- }
154
- return item;
155
- });
156
- };
157
86
  }
158
87
  }
159
88
  exports.CitationView = CitationView;
@@ -14,26 +14,6 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __rest = (this && this.__rest) || function (s, e) {
27
- var t = {};
28
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
29
- t[p] = s[p];
30
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
31
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
32
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
33
- t[p[i]] = s[p[i]];
34
- }
35
- return t;
36
- };
37
17
  var __importDefault = (this && this.__importDefault) || function (mod) {
38
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
39
19
  };
@@ -41,70 +21,90 @@ Object.defineProperty(exports, "__esModule", { value: true });
41
21
  exports.CitationEditableView = void 0;
42
22
  const json_schema_1 = require("@manuscripts/json-schema");
43
23
  const library_1 = require("@manuscripts/library");
24
+ const style_guide_1 = require("@manuscripts/style-guide");
44
25
  const transform_1 = require("@manuscripts/transform");
45
26
  const prosemirror_state_1 = require("prosemirror-state");
46
- const react_1 = __importDefault(require("react"));
27
+ const prosemirror_utils_1 = require("prosemirror-utils");
28
+ const citation_sources_1 = require("../citation-sources");
29
+ const track_changes_utils_1 = require("../lib/track-changes-utils");
47
30
  const bibliography_1 = require("../plugins/bibliography");
48
31
  const citation_1 = require("./citation");
32
+ const CitationEditorWrapper_1 = require("./CitationEditorWrapper");
49
33
  const creators_1 = require("./creators");
50
- const createBibliographySection = (bibItem) => transform_1.schema.nodes.bibliography_section.createAndFill({}, [
51
- transform_1.schema.nodes.section_title.create({}, transform_1.schema.text('References')),
52
- transform_1.schema.nodes.bibliography_element.create({}, bibItem ? [bibItem] : []),
34
+ const ReactSubView_1 = __importDefault(require("./ReactSubView"));
35
+ const createBibliographySection = (node) => transform_1.schema.nodes.bibliography_section.createAndFill({}, [
36
+ transform_1.schema.nodes.section_title.create({}, transform_1.schema.text('Bibliography')),
37
+ transform_1.schema.nodes.bibliography_element.create({}, node ? [node] : []),
53
38
  ]);
54
39
  class CitationEditableView extends citation_1.CitationView {
55
40
  constructor() {
56
41
  super(...arguments);
42
+ this.decoder = new transform_1.Decoder(new Map());
43
+ this.selectNode = () => {
44
+ if (!(0, track_changes_utils_1.isDeleted)(this.node)) {
45
+ this.showPopper();
46
+ this.dom.classList.add('ProseMirror-selectednode');
47
+ }
48
+ };
49
+ this.deselectNode = () => {
50
+ var _a;
51
+ (_a = this.editor) === null || _a === void 0 ? void 0 : _a.remove();
52
+ this.dom.classList.remove('ProseMirror-selectednode');
53
+ this.props.popper.destroy();
54
+ };
55
+ this.destroy = () => {
56
+ var _a;
57
+ (_a = this.editor) === null || _a === void 0 ? void 0 : _a.remove();
58
+ this.props.popper.destroy();
59
+ };
57
60
  this.showPopper = () => {
58
- const { components: { CitationEditor, CitationViewer }, getCapabilities, projectID, renderReactComponent, } = this.props;
59
- const capabilities = getCapabilities();
61
+ const can = this.props.getCapabilities();
60
62
  const citation = this.getCitation();
61
- const items = this.getBibliographyItems();
62
- const updateCitation = (data) => __awaiter(this, void 0, void 0, function* () {
63
- this.updateNode(Object.assign(Object.assign({}, citation), data));
64
- this.props.popper.update();
65
- });
66
- const findPosition = (doc, id) => {
67
- let nodePos = undefined;
68
- doc.descendants((node, pos) => {
69
- if (node.attrs.id === id) {
70
- nodePos = pos;
71
- }
72
- });
73
- return nodePos;
74
- };
75
- const handleSave = (data) => __awaiter(this, void 0, void 0, function* () {
76
- if (data._id && !findPosition(this.view.state.doc, data._id)) {
77
- this.insertBibliographyNode(this.view, data);
78
- }
79
- else {
80
- const _a = data, { _id: id, 'container-title': containerTitle, DOI: doi } = _a, rest = __rest(_a, ["_id", 'container-title', "DOI"]);
81
- this.updateNodeAttrs(Object.assign({ id,
82
- containerTitle,
83
- doi }, rest));
84
- }
85
- });
86
- if (!this.popperContainer) {
87
- this.popperContainer = document.createElement('div');
88
- this.popperContainer.className = 'citation-editor';
89
- }
63
+ const rids = citation.embeddedCitationItems.map((i) => i.bibliographyItem);
90
64
  const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
91
- const component = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.editArticle) ? (react_1.default.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_1.default.createElement(CitationViewer, { items: items, setComment: this.props.setComment, scheduleUpdate: this.props.popper.update }));
92
- renderReactComponent(component, this.popperContainer);
93
- this.props.popper.show(this.dom, this.popperContainer, 'right');
65
+ const items = Array.from(bib.bibliographyItems.values());
66
+ if (can.editArticle) {
67
+ const query = this.node.attrs.selectedText;
68
+ const componentProps = {
69
+ query,
70
+ rids,
71
+ items,
72
+ citationCounts: bib.citationCounts,
73
+ sources: [citation_sources_1.crossref],
74
+ onCite: this.handleCite,
75
+ onUncite: this.handleUncite,
76
+ onSave: this.handleSave,
77
+ onDelete: this.handleDelete,
78
+ onComment: this.handleComment,
79
+ onCancel: this.handleCancel,
80
+ canEdit: can.editCitationsAndRefs,
81
+ };
82
+ this.editor = (0, ReactSubView_1.default)(this.props, CitationEditorWrapper_1.CitationEditorWrapper, componentProps, this.node, this.getPos, this.view, 'citation-editor');
83
+ }
84
+ else {
85
+ const componentProps = {
86
+ rids,
87
+ items,
88
+ };
89
+ this.editor = (0, ReactSubView_1.default)(this.props, style_guide_1.CitationViewer, componentProps, this.node, this.getPos, this.view, 'citation-editor');
90
+ }
91
+ this.props.popper.show(this.dom, this.editor, 'right');
94
92
  };
95
- this.handleClose = () => {
93
+ this.handleCancel = () => {
96
94
  const selection = prosemirror_state_1.TextSelection.create(this.view.state.tr.doc, this.getPos() + 1);
97
95
  this.view.dispatch(this.view.state.tr.setSelection(selection));
98
96
  this.props.popper.destroy();
99
97
  };
100
- this.handleCancel = () => {
101
- const { state } = this.view;
102
- const pos = this.getPos();
103
- const tr = state.tr.delete(pos, pos + this.node.nodeSize);
104
- const selection = prosemirror_state_1.TextSelection.create(tr.doc, pos);
105
- this.view.dispatch(tr.setSelection(selection));
98
+ this.handleSave = (item) => {
99
+ if (item._id && !this.findPosition(item._id)) {
100
+ this.insertBibliographyNode(item);
101
+ }
102
+ else {
103
+ const node = this.decoder.decode(item);
104
+ this.updateNodeAttrs(node.attrs);
105
+ }
106
106
  };
107
- this.handleRemove = (id) => __awaiter(this, void 0, void 0, function* () {
107
+ this.handleUncite = (id) => {
108
108
  const citation = this.getCitation();
109
109
  const items = citation.embeddedCitationItems.filter((i) => i.bibliographyItem !== id);
110
110
  if (items.length > 0) {
@@ -121,23 +121,19 @@ class CitationEditableView extends citation_1.CitationView {
121
121
  this.view.dispatch(tr);
122
122
  }
123
123
  this.props.popper.destroy();
124
- });
125
- this.updatePopper = () => {
126
- this.props.popper.destroy();
127
- window.setTimeout(() => {
128
- this.showPopper();
129
- }, 100);
130
124
  };
131
- this.handleCite = (items) => __awaiter(this, void 0, void 0, function* () {
125
+ this.handleCite = (items) => {
132
126
  const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
133
127
  const citation = this.getCitation();
128
+ const rids = citation.embeddedCitationItems.map((i) => i.bibliographyItem);
129
+ items = items.filter((i) => !rids.includes(i._id));
134
130
  for (const item of items) {
135
131
  const existingItem = (0, library_1.findMatchingBibliographyItem)(item, bib.bibliographyItems);
136
132
  if (existingItem) {
137
133
  item._id = existingItem._id;
138
134
  }
139
135
  else {
140
- this.insertBibliographyNode(this.view, item);
136
+ this.insertBibliographyNode(item);
141
137
  }
142
138
  citation.embeddedCitationItems.push({
143
139
  _id: '_',
@@ -146,20 +142,15 @@ class CitationEditableView extends citation_1.CitationView {
146
142
  });
147
143
  }
148
144
  this.updateNode(citation);
149
- this.handleClose();
150
- });
151
- this.importItems = (items) => __awaiter(this, void 0, void 0, function* () {
152
- const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
153
- const newItems = [];
154
- for (const item of items) {
155
- const existingItem = (0, library_1.findMatchingBibliographyItem)(item, bib.bibliographyItems);
156
- if (!existingItem) {
157
- this.insertBibliographyNode(this.view, item);
158
- newItems.push(item);
159
- }
160
- }
161
- return newItems;
162
- });
145
+ this.handleCancel();
146
+ };
147
+ this.handleDelete = (item) => {
148
+ return this.deleteNode(item._id);
149
+ };
150
+ this.handleComment = () => {
151
+ const comment = (0, transform_1.buildComment)(this.node.attrs.id);
152
+ this.props.setComment(comment);
153
+ };
163
154
  this.updateNode = (citation) => {
164
155
  const rids = citation.embeddedCitationItems.map((i) => i.bibliographyItem);
165
156
  const { tr } = this.view.state;
@@ -168,28 +159,22 @@ class CitationEditableView extends citation_1.CitationView {
168
159
  rids,
169
160
  }));
170
161
  };
162
+ this.findPosition = (id) => {
163
+ const doc = this.view.state.doc;
164
+ const children = (0, prosemirror_utils_1.findChildren)(doc, (n) => n.attrs.id === id);
165
+ return children.length ? children[0] : undefined;
166
+ };
171
167
  }
172
- insertBibliographyNode(view, item) {
173
- const { doc, tr } = view.state;
174
- const { DOI: doi, ['container-title']: containerTitle } = item, restAttr = __rest(item, ["DOI", 'container-title']);
175
- let bibElement = null;
176
- let pos = null;
177
- doc.descendants((node, nodePos) => {
178
- if (node.type === transform_1.schema.nodes.bibliography_element) {
179
- bibElement = node;
180
- pos = nodePos;
181
- }
182
- });
183
- let newTr;
184
- const bibItem = transform_1.schema.nodes.bibliography_item.create(Object.assign({ id: item._id, doi,
185
- containerTitle }, restAttr));
186
- if (bibElement && pos) {
187
- newTr = tr.insert(pos + 1, bibItem);
168
+ insertBibliographyNode(item) {
169
+ const { doc, tr } = this.view.state;
170
+ const elements = (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.bibliography_element, true);
171
+ const node = this.decoder.decode(item);
172
+ if (elements.length) {
173
+ this.view.dispatch(tr.insert(elements[0].pos + 1, node));
188
174
  }
189
175
  else {
190
- newTr = tr.insert(tr.doc.content.size, createBibliographySection(bibItem));
176
+ this.view.dispatch(tr.insert(tr.doc.content.size, createBibliographySection(node)));
191
177
  }
192
- view.dispatch(newTr);
193
178
  return false;
194
179
  }
195
180
  }
@@ -30,34 +30,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.CrossReferenceEditableView = void 0;
31
31
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
32
32
  const prosemirror_state_1 = require("prosemirror-state");
33
- const react_1 = __importDefault(require("react"));
34
33
  const CrossReferenceItems_1 = require("../components/views/CrossReferenceItems");
35
34
  const objects_1 = require("../plugins/objects");
36
35
  const creators_1 = require("./creators");
37
36
  const cross_reference_1 = require("./cross_reference");
37
+ const ReactSubView_1 = __importDefault(require("./ReactSubView"));
38
38
  class CrossReferenceEditableView extends cross_reference_1.CrossReferenceView {
39
39
  constructor() {
40
40
  super(...arguments);
41
41
  this.selectNode = () => {
42
- const { getCapabilities, renderReactComponent } = this.props;
42
+ const { getCapabilities } = this.props;
43
43
  const xref = this.node;
44
44
  const rids = xref.attrs.rids;
45
45
  const can = getCapabilities();
46
46
  if (!(can === null || can === void 0 ? void 0 : can.editArticle) || rids.length) {
47
47
  return;
48
48
  }
49
- if (!this.popperContainer) {
50
- this.popperContainer = document.createElement('div');
51
- this.popperContainer.className = 'cross-reference-editor';
52
- }
53
- renderReactComponent(react_1.default.createElement(CrossReferenceItems_1.CrossReferenceItems, { handleSelect: this.handleSelect, targets: this.getTargets(), handleCancel: this.handleCancel, currentTargetId: rids[0], currentCustomLabel: this.node.attrs.customLabel }), this.popperContainer);
49
+ const componentProps = {
50
+ handleSelect: this.handleSelect,
51
+ targets: this.getTargets(),
52
+ handleCancel: this.handleCancel,
53
+ currentTargetId: rids[0],
54
+ currentCustomLabel: this.node.attrs.customLabel,
55
+ };
56
+ this.popperContainer = (0, ReactSubView_1.default)(this.props, CrossReferenceItems_1.CrossReferenceItems, componentProps, this.node, this.getPos, this.view, 'cross-reference-editor');
54
57
  this.props.popper.show(this.dom, this.popperContainer, 'right');
55
58
  };
56
59
  this.destroy = () => {
60
+ var _a;
57
61
  this.props.popper.destroy();
58
- if (this.popperContainer) {
59
- this.props.unmountReactComponent(this.popperContainer);
60
- }
62
+ (_a = this.popperContainer) === null || _a === void 0 ? void 0 : _a.remove();
61
63
  };
62
64
  this.deselectNode = () => {
63
65
  this.handleCancel();
@@ -17,6 +17,8 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.EquationView = void 0;
19
19
  const dompurify_1 = require("../lib/dompurify");
20
+ const mathml_to_svg_1 = require("../lib/mathml-to-svg");
21
+ const tex_to_svg_1 = require("../lib/tex-to-svg");
20
22
  const base_node_view_1 = require("./base_node_view");
21
23
  const creators_1 = require("./creators");
22
24
  class EquationView extends base_node_view_1.BaseNodeView {
@@ -32,12 +34,15 @@ class EquationView extends base_node_view_1.BaseNodeView {
32
34
  this.dom.setAttribute('id', this.node.attrs.id);
33
35
  };
34
36
  this.updateContents = () => {
35
- const { SVGStringRepresentation } = this.node.attrs;
37
+ const { contents, format } = this.node.attrs;
38
+ const svgContent = format === 'tex'
39
+ ? (0, tex_to_svg_1.convertTeXToSVG)(contents, true)
40
+ : (0, mathml_to_svg_1.convertMathMLToSVG)(contents, true);
36
41
  while (this.dom.hasChildNodes()) {
37
42
  this.dom.removeChild(this.dom.firstChild);
38
43
  }
39
- if (SVGStringRepresentation) {
40
- const fragment = (0, dompurify_1.sanitize)(SVGStringRepresentation, {
44
+ if (svgContent) {
45
+ const fragment = (0, dompurify_1.sanitize)(svgContent, {
41
46
  USE_PROFILES: { svg: true },
42
47
  });
43
48
  this.dom.appendChild(fragment);
@@ -48,7 +48,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
48
48
  };
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
50
  exports.EquationEditableView = void 0;
51
- const transform_1 = require("@manuscripts/transform");
52
51
  const prosemirror_state_1 = require("prosemirror-state");
53
52
  const creators_1 = require("./creators");
54
53
  const equation_1 = require("./equation");
@@ -62,21 +61,16 @@ class EquationEditableView extends equation_1.EquationView {
62
61
  const { createEditor } = yield Promise.resolve().then(() => __importStar(require('../lib/codemirror')));
63
62
  const placeholder = 'Enter LaTeX equation, e.g. "a^2 = \\sqrt{b^2 + c^2}"';
64
63
  const input = yield createEditor({
65
- value: this.node.attrs.TeXRepresentation || '',
64
+ value: this.node.attrs.contents || '',
66
65
  mode: 'stex',
67
66
  placeholder,
68
67
  autofocus: true,
69
68
  });
70
69
  input.on('changes', () => __awaiter(this, void 0, void 0, function* () {
71
- const TeXRepresentation = input.getValue();
72
- const SVGStringRepresentation = yield (0, transform_1.convertTeXToSVG)(TeXRepresentation, true);
73
- if (!SVGStringRepresentation) {
74
- throw new Error('No SVG output from MathJax');
75
- }
70
+ const contents = input.getValue();
76
71
  const pos = this.getPos();
77
72
  const { tr } = this.view.state;
78
- tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { TeXRepresentation,
79
- SVGStringRepresentation })).setSelection(prosemirror_state_1.NodeSelection.create(tr.doc, pos));
73
+ tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { contents, format: 'tex' })).setSelection(prosemirror_state_1.NodeSelection.create(tr.doc, pos));
80
74
  this.view.dispatch(tr);
81
75
  }));
82
76
  const wrapper = document.createElement('div');
@@ -27,9 +27,12 @@ class EquationElementView extends block_view_1.default {
27
27
  this.elementType = 'figure';
28
28
  this.updateContents = () => {
29
29
  var _a;
30
- const { suppressCaption, suppressTitle } = this.node.attrs;
31
- this.dom.classList.toggle('suppress-caption', suppressCaption);
32
- this.dom.classList.toggle('suppress-title', suppressTitle === undefined ? true : suppressTitle);
30
+ const { label } = this.node.attrs;
31
+ if (label) {
32
+ const labelEl = document.createElement('label');
33
+ labelEl.textContent = label;
34
+ this.dom.appendChild(labelEl);
35
+ }
33
36
  if ((_a = this.node.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.length) {
34
37
  const lastChange = this.node.attrs.dataTracked[this.node.attrs.dataTracked.length - 1];
35
38
  this.dom.setAttribute('data-track-status', lastChange.status);
@@ -17,6 +17,8 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.InlineEquationView = void 0;
19
19
  const dompurify_1 = require("../lib/dompurify");
20
+ const mathml_to_svg_1 = require("../lib/mathml-to-svg");
21
+ const tex_to_svg_1 = require("../lib/tex-to-svg");
20
22
  const track_changes_utils_1 = require("../lib/track-changes-utils");
21
23
  const base_node_view_1 = require("./base_node_view");
22
24
  const creators_1 = require("./creators");
@@ -29,12 +31,15 @@ class InlineEquationView extends base_node_view_1.BaseNodeView {
29
31
  };
30
32
  this.updateContents = () => {
31
33
  if (!(0, track_changes_utils_1.isRejectedInsert)(this.node)) {
32
- const { SVGRepresentation } = this.node.attrs;
34
+ const { contents, format } = this.node.attrs;
33
35
  while (this.dom.hasChildNodes()) {
34
36
  this.dom.removeChild(this.dom.firstChild);
35
37
  }
36
- if (SVGRepresentation) {
37
- const fragment = (0, dompurify_1.sanitize)(SVGRepresentation, {
38
+ const svgContent = format === 'tex'
39
+ ? (0, tex_to_svg_1.convertTeXToSVG)(contents, true)
40
+ : (0, mathml_to_svg_1.convertMathMLToSVG)(contents, true);
41
+ if (svgContent) {
42
+ const fragment = (0, dompurify_1.sanitize)(svgContent, {
38
43
  USE_PROFILES: { svg: true },
39
44
  });
40
45
  this.dom.appendChild(fragment);
@@ -48,7 +48,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
48
48
  };
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
50
  exports.InlineEquationEditableView = void 0;
51
- const transform_1 = require("@manuscripts/transform");
52
51
  const prosemirror_state_1 = require("prosemirror-state");
53
52
  const creators_1 = require("./creators");
54
53
  const inline_equation_1 = require("./inline_equation");
@@ -62,21 +61,16 @@ class InlineEquationEditableView extends inline_equation_1.InlineEquationView {
62
61
  const { createEditor } = yield Promise.resolve().then(() => __importStar(require('../lib/codemirror')));
63
62
  const placeholder = 'Enter LaTeX equation, e.g. "E=mc^2"';
64
63
  const input = yield createEditor({
65
- value: this.node.attrs.TeXRepresentation || '',
64
+ value: this.node.attrs.contents || '',
66
65
  mode: 'stex',
67
66
  placeholder,
68
67
  autofocus: true,
69
68
  });
70
69
  input.on('changes', () => __awaiter(this, void 0, void 0, function* () {
71
- const TeXRepresentation = input.getValue();
72
- const SVGRepresentation = yield (0, transform_1.convertTeXToSVG)(TeXRepresentation, true);
73
- if (!SVGRepresentation) {
74
- throw new Error('No SVG output from MathJax');
75
- }
70
+ const contents = input.getValue();
76
71
  const pos = this.getPos();
77
72
  const { tr } = this.view.state;
78
- tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { TeXRepresentation,
79
- SVGRepresentation })).setSelection(prosemirror_state_1.NodeSelection.create(tr.doc, pos));
73
+ tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { format: 'tex', contents })).setSelection(prosemirror_state_1.NodeSelection.create(tr.doc, pos));
80
74
  this.view.dispatch(tr);
81
75
  }));
82
76
  this.props.popper.show(this.dom, input.getWrapperElement(), 'bottom');
@@ -20,10 +20,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.LinkEditableView = void 0;
22
22
  const prosemirror_state_1 = require("prosemirror-state");
23
- const react_1 = __importDefault(require("react"));
24
23
  const LinkForm_1 = require("../components/views/LinkForm");
25
24
  const creators_1 = require("./creators");
26
25
  const link_1 = require("./link");
26
+ const ReactSubView_1 = __importDefault(require("./ReactSubView"));
27
27
  class LinkEditableView extends link_1.LinkView {
28
28
  constructor() {
29
29
  super(...arguments);
@@ -52,43 +52,51 @@ class LinkEditableView extends link_1.LinkView {
52
52
  title: this.node.attrs.title,
53
53
  text: this.node.textContent,
54
54
  };
55
- this.props.renderReactComponent(react_1.default.createElement(LinkForm_1.LinkForm, { value: originalValue, handleCancel: () => {
56
- const tr = this.view.state.tr;
57
- const pos = this.getPos();
58
- tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, pos));
59
- this.view.focus();
60
- this.view.dispatch(tr);
61
- this.closeForm();
62
- }, handleRemove: () => {
63
- const { tr } = this.view.state;
64
- const pos = this.getPos();
65
- const to = pos + this.node.nodeSize;
66
- tr.replaceWith(pos, to, this.node.content).setSelection(prosemirror_state_1.TextSelection.create(tr.doc, pos));
67
- this.view.focus();
68
- this.view.dispatch(tr);
69
- this.closeForm();
70
- }, handleSave: (data) => {
71
- const tr = this.view.state.tr;
72
- const pos = this.getPos();
73
- if (data.href !== originalValue.href ||
74
- data.title !== originalValue.title) {
75
- tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { href: data.href, title: data.title }));
76
- }
77
- if (data.text !== originalValue.text) {
78
- tr.insertText(data.text, pos + 1, pos + this.node.nodeSize - 1);
79
- }
80
- tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, pos));
81
- this.view.focus();
82
- this.view.dispatch(tr);
83
- this.closeForm();
84
- } }), this.popperContainer);
55
+ const componentProps = {
56
+ value: originalValue,
57
+ handleCancel: this.handleCancel,
58
+ handleRemove: this.handleRemove,
59
+ handleSave: this.handleSave,
60
+ };
61
+ this.popperContainer = (0, ReactSubView_1.default)(this.props, LinkForm_1.LinkForm, componentProps, this.node, this.getPos, this.view);
85
62
  this.props.popper.show(this.dom, this.popperContainer, 'bottom');
86
63
  };
64
+ this.handleCancel = () => {
65
+ const tr = this.view.state.tr;
66
+ const pos = this.getPos();
67
+ tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, pos));
68
+ this.view.focus();
69
+ this.view.dispatch(tr);
70
+ this.closeForm();
71
+ };
72
+ this.handleRemove = () => {
73
+ const tr = this.view.state.tr;
74
+ const pos = this.getPos();
75
+ const to = pos + this.node.nodeSize;
76
+ tr.replaceWith(pos, to, this.node.content).setSelection(prosemirror_state_1.TextSelection.create(tr.doc, pos));
77
+ this.view.focus();
78
+ this.view.dispatch(tr);
79
+ this.closeForm();
80
+ };
81
+ this.handleSave = (value) => {
82
+ const tr = this.view.state.tr;
83
+ const link = this.node;
84
+ const pos = this.getPos();
85
+ if (value.href !== link.attrs.href || value.title !== link.attrs.title) {
86
+ tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { href: value.href, title: value.title }));
87
+ }
88
+ if (value.text !== link.textContent) {
89
+ tr.insertText(value.text, pos + 1, pos + this.node.nodeSize - 1);
90
+ }
91
+ tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, pos));
92
+ this.view.focus();
93
+ this.view.dispatch(tr);
94
+ this.closeForm();
95
+ };
87
96
  this.closeForm = () => {
97
+ var _a;
88
98
  this.props.popper.destroy();
89
- if (this.popperContainer) {
90
- this.props.unmountReactComponent(this.popperContainer);
91
- }
99
+ (_a = this.popperContainer) === null || _a === void 0 ? void 0 : _a.remove();
92
100
  };
93
101
  }
94
102
  }