@manuscripts/body-editor 1.7.5 → 1.7.6-LEAN-3092-5

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.
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.updateCommentAnnotationState = exports.addComment = exports.deleteHighlightMarkers = exports.insertHighlight = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.ifInTableBody = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertSection = exports.insertGraphicalAbstract = exports.insertInlineFootnote = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertFileAsFigure = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = void 0;
18
+ exports.insertTableFootnote = exports.updateCommentAnnotationState = exports.addComment = exports.deleteHighlightMarkers = exports.insertHighlight = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.ifInTableBody = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertSection = exports.insertGraphicalAbstract = exports.insertInlineFootnote = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertFileAsFigure = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = void 0;
19
19
  const json_schema_1 = require("@manuscripts/json-schema");
20
20
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
21
21
  const transform_1 = require("@manuscripts/transform");
@@ -109,7 +109,6 @@ const createBlock = (nodeType, position, state, dispatch) => {
109
109
  case state.schema.nodes.equation_element:
110
110
  node = state.schema.nodes.equation_element.create({}, [
111
111
  state.schema.nodes.equation.create(),
112
- createAndFillFigcaptionElement(state),
113
112
  ]);
114
113
  break;
115
114
  default:
@@ -264,10 +263,10 @@ const insertCrossReference = (state, dispatch) => {
264
263
  };
265
264
  exports.insertCrossReference = insertCrossReference;
266
265
  const insertInlineEquation = (state, dispatch) => {
267
- const inlineMathFragment = (0, transform_1.buildInlineMathFragment)(state.selection.$anchor.parent.attrs.id, selectedText().replace(/^\$/, '').replace(/\$$/, ''));
268
266
  const sourcePos = state.selection.from - 1;
269
267
  const tr = state.tr.replaceSelectionWith(state.schema.nodes.inline_equation.create({
270
- id: inlineMathFragment._id,
268
+ format: 'tex',
269
+ contents: selectedText().replace(/^\$/, '').replace(/\$$/, ''),
271
270
  }));
272
271
  if (dispatch) {
273
272
  const selection = prosemirror_state_1.NodeSelection.create(tr.doc, tr.mapping.map(sourcePos) + 1);
@@ -688,3 +687,41 @@ const updateCommentAnnotationState = (state, dispatch) => {
688
687
  }
689
688
  };
690
689
  exports.updateCommentAnnotationState = updateCommentAnnotationState;
690
+ const insertTableFootnote = (node, position, state, dispatch) => {
691
+ var _a;
692
+ const footnote = state.schema.nodes.footnote.createAndFill({
693
+ id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Footnote),
694
+ kind: 'footnote',
695
+ });
696
+ const insertedAt = state.selection.to;
697
+ const inlineFootnotes = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.inline_footnote);
698
+ const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
699
+ rids: [footnote.attrs.id],
700
+ contents: inlineFootnotes.length + 1,
701
+ });
702
+ const tr = state.tr;
703
+ tr.insert(insertedAt, inlineFootnoteNode);
704
+ const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
705
+ const tableElementFooter = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.table_element_footer);
706
+ let insertionPos;
707
+ if (tableElementFooter.length) {
708
+ const pos = tableElementFooter[0].pos;
709
+ insertionPos = position + pos + tableElementFooter[0].node.nodeSize + 1;
710
+ tr.insert(insertionPos, footnoteElement);
711
+ }
712
+ else {
713
+ const tableSize = (_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize;
714
+ if (tableSize) {
715
+ insertionPos = position + tableSize + 2;
716
+ const tableElementFooter = transform_1.schema.nodes.table_element_footer.create({
717
+ id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.TableElementFooter),
718
+ }, [footnoteElement]);
719
+ tr.insert(insertionPos, tableElementFooter);
720
+ }
721
+ }
722
+ if (dispatch && insertionPos) {
723
+ const nodeSelection = prosemirror_state_1.NodeSelection.create(tr.doc, insertionPos);
724
+ dispatch(tr.setSelection(nodeSelection));
725
+ }
726
+ };
727
+ exports.insertTableFootnote = insertTableFootnote;
@@ -17,6 +17,7 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.ContextMenu = exports.sectionLevel = void 0;
19
19
  const transform_1 = require("@manuscripts/transform");
20
+ const prosemirror_utils_1 = require("prosemirror-utils");
20
21
  const commands_1 = require("../commands");
21
22
  const popper_1 = require("./popper");
22
23
  const popper = new popper_1.PopperManager();
@@ -164,6 +165,20 @@ class ContextMenu {
164
165
  }));
165
166
  }));
166
167
  }
168
+ if (type === transform_1.schema.nodes.table_element) {
169
+ const isInTable = (0, prosemirror_utils_1.hasParentNodeOfType)(transform_1.schema.nodes.table)(this.view.state.selection);
170
+ if (isInTable) {
171
+ menu.appendChild(this.createMenuSection((section) => {
172
+ section.appendChild(this.createMenuItem('Add Reference Note', () => {
173
+ const footnotesElement = (0, prosemirror_utils_1.findChildrenByType)(this.node, transform_1.schema.nodes.footnotes_element);
174
+ if (!footnotesElement.length) {
175
+ const { state, dispatch } = this.view;
176
+ (0, commands_1.insertTableFootnote)(this.node, this.getPos(), state, dispatch);
177
+ }
178
+ }));
179
+ }));
180
+ }
181
+ }
167
182
  if (!readonlyTypes.includes(type) &&
168
183
  !readonlyTypes.includes($pos.parent.type)) {
169
184
  menu.appendChild(this.createMenuSection((section) => {
@@ -14,8 +14,40 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
+ return new (P || (P = Promise))(function (resolve, reject) {
43
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
47
+ });
48
+ };
17
49
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.mergeSimilarItems = exports.nearestAncestor = exports.isNodeOfType = void 0;
50
+ exports.renderMath = exports.mergeSimilarItems = exports.nearestAncestor = exports.isNodeOfType = void 0;
19
51
  const isNodeOfType = (...type) => (node) => {
20
52
  const [head, ...tail] = type;
21
53
  if (node.type === node.type.schema.nodes[head]) {
@@ -50,3 +82,14 @@ const mergeSimilarItems = (compareFunc, mergeFunc) => (items) => {
50
82
  }, []);
51
83
  };
52
84
  exports.mergeSimilarItems = mergeSimilarItems;
85
+ const renderMath = (math, format) => __awaiter(void 0, void 0, void 0, function* () {
86
+ if (format === 'tex') {
87
+ const { convertTeXToSVG } = yield Promise.resolve().then(() => __importStar(require('../lib/tex-to-svg')));
88
+ return convertTeXToSVG(math);
89
+ }
90
+ else {
91
+ const { convertMathMLToSVG } = yield Promise.resolve().then(() => __importStar(require('../lib/mathml-to-svg')));
92
+ return convertMathMLToSVG(math);
93
+ }
94
+ });
95
+ exports.renderMath = renderMath;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.convertMathMLToSVG = void 0;
19
+ require("mathjax-full/js/util/entities/all");
20
+ const transform_1 = require("@manuscripts/transform");
21
+ const HTMLAdaptor_1 = require("mathjax-full/js/adaptors/HTMLAdaptor");
22
+ const MmlFactory_1 = require("mathjax-full/js/core/MmlTree/MmlFactory");
23
+ const HTMLDocument_1 = require("mathjax-full/js/handlers/html/HTMLDocument");
24
+ const mathml_1 = require("mathjax-full/js/input/mathml");
25
+ const svg_1 = require("mathjax-full/js/output/svg");
26
+ class ManuscriptsMmlFactory extends MmlFactory_1.MmlFactory {
27
+ constructor() {
28
+ super();
29
+ this.nodeMap.set('image', this.nodeMap.get('none'));
30
+ }
31
+ create(kind, properties = {}, children = []) {
32
+ if (kind === 'image') {
33
+ return this.node['none'](properties, children);
34
+ }
35
+ return this.node[kind](properties, children);
36
+ }
37
+ }
38
+ class ManuscriptsHTMLAdaptor extends HTMLAdaptor_1.HTMLAdaptor {
39
+ setAttribute(node, name, value, ns) {
40
+ if (name !== 'xmlns') {
41
+ ns ? node.setAttributeNS(ns, name, value) : node.setAttribute(name, value);
42
+ }
43
+ }
44
+ }
45
+ const InputJax = new mathml_1.MathML();
46
+ const OutputJax = new svg_1.SVG({
47
+ fontCache: 'none',
48
+ });
49
+ const adaptor = new ManuscriptsHTMLAdaptor(window);
50
+ const doc = new HTMLDocument_1.HTMLDocument(document, adaptor, {
51
+ InputJax,
52
+ OutputJax,
53
+ MmlFactory: new ManuscriptsMmlFactory(),
54
+ });
55
+ doc.addStyleSheet();
56
+ const convertMathMLToSVG = (mathml, display = true) => {
57
+ const item = doc.convert(mathml, {
58
+ display,
59
+ em: 16,
60
+ ex: 8,
61
+ containerWidth: 1000000,
62
+ lineWidth: 1000000,
63
+ scale: 1,
64
+ });
65
+ if (!item || !item.firstChild) {
66
+ return null;
67
+ }
68
+ return transform_1.xmlSerializer.serializeToString(item.firstChild);
69
+ };
70
+ exports.convertMathMLToSVG = convertMathMLToSVG;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.convertTeXToSVG = exports.packages = void 0;
19
+ require("mathjax-full/js/util/entities/all");
20
+ const transform_1 = require("@manuscripts/transform");
21
+ const HTMLAdaptor_1 = require("mathjax-full/js/adaptors/HTMLAdaptor");
22
+ const HTMLDocument_1 = require("mathjax-full/js/handlers/html/HTMLDocument");
23
+ const tex_1 = require("mathjax-full/js/input/tex");
24
+ const AllPackages_1 = require("mathjax-full/js/input/tex/AllPackages");
25
+ const svg_1 = require("mathjax-full/js/output/svg");
26
+ exports.packages = AllPackages_1.AllPackages.filter((name) => name !== 'html' && name !== 'bussproofs');
27
+ class ManuscriptsHTMLAdaptor extends HTMLAdaptor_1.HTMLAdaptor {
28
+ setAttribute(node, name, value, ns) {
29
+ if (name !== 'xmlns') {
30
+ ns ? node.setAttributeNS(ns, name, value) : node.setAttribute(name, value);
31
+ }
32
+ }
33
+ }
34
+ const InputJax = new tex_1.TeX({
35
+ packages: exports.packages,
36
+ });
37
+ const OutputJax = new svg_1.SVG({
38
+ fontCache: 'none',
39
+ });
40
+ const adaptor = new ManuscriptsHTMLAdaptor(window);
41
+ const doc = new HTMLDocument_1.HTMLDocument(document, adaptor, {
42
+ InputJax,
43
+ OutputJax,
44
+ });
45
+ doc.addStyleSheet();
46
+ const convertTeXToSVG = (tex, display = true) => {
47
+ const item = doc.convert(tex, {
48
+ display,
49
+ em: 16,
50
+ ex: 8,
51
+ containerWidth: 1000000,
52
+ lineWidth: 1000000,
53
+ scale: 1,
54
+ });
55
+ if (!item || !item.firstChild) {
56
+ return null;
57
+ }
58
+ return transform_1.xmlSerializer.serializeToString(item.firstChild);
59
+ };
60
+ exports.convertTeXToSVG = convertTeXToSVG;
@@ -22,6 +22,7 @@ const prosemirror_state_1 = require("prosemirror-state");
22
22
  const prosemirror_utils_1 = require("prosemirror-utils");
23
23
  const prosemirror_view_1 = require("prosemirror-view");
24
24
  const utils_1 = require("../../lib/utils");
25
+ const placeholder_1 = require("../placeholder");
25
26
  exports.footnotesKey = new prosemirror_state_1.PluginKey('footnotes');
26
27
  const buildPluginState = (doc) => {
27
28
  const nodes = [];
@@ -101,9 +102,10 @@ exports.default = () => {
101
102
  }
102
103
  const { labels } = exports.footnotesKey.getState(state);
103
104
  state.doc.descendants((node, pos) => {
104
- if (labels) {
105
- if ((0, transform_1.isFootnoteNode)(node)) {
106
- const id = node.attrs.id;
105
+ var _a;
106
+ if ((0, transform_1.isFootnoteNode)(node)) {
107
+ const id = node.attrs.id;
108
+ if (labels) {
107
109
  const label = labels.get(id);
108
110
  if (label) {
109
111
  decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, labelWidget(label, id), {
@@ -111,6 +113,9 @@ exports.default = () => {
111
113
  }));
112
114
  }
113
115
  }
116
+ if (!((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.textContent)) {
117
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, (0, placeholder_1.placeholderWidget)('Add new note here')));
118
+ }
114
119
  }
115
120
  if (node.type === transform_1.schema.nodes.footnotes_element) {
116
121
  decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
@@ -15,6 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.placeholderWidget = void 0;
18
19
  const prosemirror_state_1 = require("prosemirror-state");
19
20
  const prosemirror_view_1 = require("prosemirror-view");
20
21
  const placeholderWidget = (placeholder) => (view, getPos) => {
@@ -27,6 +28,7 @@ const placeholderWidget = (placeholder) => (view, getPos) => {
27
28
  });
28
29
  return element;
29
30
  };
31
+ exports.placeholderWidget = placeholderWidget;
30
32
  exports.default = () => new prosemirror_state_1.Plugin({
31
33
  props: {
32
34
  decorations: (state) => {
@@ -38,7 +40,7 @@ exports.default = () => new prosemirror_state_1.Plugin({
38
40
  node.type.isBlock &&
39
41
  node.childCount === 0) {
40
42
  if (node.type === node.type.schema.nodes.paragraph) {
41
- decorations.push(prosemirror_view_1.Decoration.widget(pos + 1, placeholderWidget(placeholder)));
43
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + 1, (0, exports.placeholderWidget)(placeholder)));
42
44
  }
43
45
  else {
44
46
  decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
@@ -17,6 +17,7 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.EquationView = void 0;
19
19
  const dompurify_1 = require("../lib/dompurify");
20
+ const helpers_1 = require("../lib/helpers");
20
21
  const base_node_view_1 = require("./base_node_view");
21
22
  const creators_1 = require("./creators");
22
23
  class EquationView extends base_node_view_1.BaseNodeView {
@@ -32,22 +33,29 @@ class EquationView extends base_node_view_1.BaseNodeView {
32
33
  this.dom.setAttribute('id', this.node.attrs.id);
33
34
  };
34
35
  this.updateContents = () => {
35
- const { SVGStringRepresentation } = this.node.attrs;
36
+ const { contents, format } = this.node.attrs;
36
37
  while (this.dom.hasChildNodes()) {
37
38
  this.dom.removeChild(this.dom.firstChild);
38
39
  }
39
- if (SVGStringRepresentation) {
40
- const fragment = (0, dompurify_1.sanitize)(SVGStringRepresentation, {
41
- USE_PROFILES: { svg: true },
42
- });
43
- this.dom.appendChild(fragment);
44
- }
45
- else {
46
- const placeholder = document.createElement('div');
47
- placeholder.className = 'equation-placeholder';
48
- placeholder.textContent = '<Equation>';
49
- this.dom.appendChild(placeholder);
50
- }
40
+ (0, helpers_1.renderMath)(contents, format)
41
+ .then((svgContent) => {
42
+ if (svgContent) {
43
+ const fragment = (0, dompurify_1.sanitize)(svgContent, {
44
+ USE_PROFILES: { svg: true },
45
+ });
46
+ this.dom.appendChild(fragment);
47
+ }
48
+ else {
49
+ const placeholder = document.createElement('div');
50
+ placeholder.className = 'equation-placeholder';
51
+ placeholder.textContent = '<Equation>';
52
+ this.dom.appendChild(placeholder);
53
+ }
54
+ return true;
55
+ })
56
+ .catch((error) => {
57
+ console.error(error);
58
+ });
51
59
  };
52
60
  this.ignoreMutation = () => true;
53
61
  }
@@ -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,7 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.InlineEquationView = void 0;
19
19
  const dompurify_1 = require("../lib/dompurify");
20
+ const helpers_1 = require("../lib/helpers");
20
21
  const track_changes_utils_1 = require("../lib/track-changes-utils");
21
22
  const base_node_view_1 = require("./base_node_view");
22
23
  const creators_1 = require("./creators");
@@ -29,22 +30,29 @@ class InlineEquationView extends base_node_view_1.BaseNodeView {
29
30
  };
30
31
  this.updateContents = () => {
31
32
  if (!(0, track_changes_utils_1.isRejectedInsert)(this.node)) {
32
- const { SVGRepresentation } = this.node.attrs;
33
+ const { contents, format } = this.node.attrs;
33
34
  while (this.dom.hasChildNodes()) {
34
35
  this.dom.removeChild(this.dom.firstChild);
35
36
  }
36
- if (SVGRepresentation) {
37
- const fragment = (0, dompurify_1.sanitize)(SVGRepresentation, {
38
- USE_PROFILES: { svg: true },
39
- });
40
- this.dom.appendChild(fragment);
41
- }
42
- else {
43
- const placeholder = document.createElement('div');
44
- placeholder.className = 'equation-placeholder';
45
- placeholder.textContent = '<Equation>';
46
- this.dom.appendChild(placeholder);
47
- }
37
+ (0, helpers_1.renderMath)(contents, format)
38
+ .then((svgContent) => {
39
+ if (svgContent) {
40
+ const fragment = (0, dompurify_1.sanitize)(svgContent, {
41
+ USE_PROFILES: { svg: true },
42
+ });
43
+ this.dom.appendChild(fragment);
44
+ }
45
+ else {
46
+ const placeholder = document.createElement('div');
47
+ placeholder.className = 'equation-placeholder';
48
+ placeholder.textContent = '<Equation>';
49
+ this.dom.appendChild(placeholder);
50
+ }
51
+ return true;
52
+ })
53
+ .catch((error) => {
54
+ console.error(error);
55
+ });
48
56
  }
49
57
  else {
50
58
  this.dom.innerHTML = '';
@@ -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');
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { ObjectTypes } from '@manuscripts/json-schema';
17
17
  import { skipTracking } from '@manuscripts/track-changes-plugin';
18
- import { buildComment, buildInlineMathFragment, generateID, isElementNodeType, isInBibliographySection, isListNode, isSectionNodeType, schema, } from '@manuscripts/transform';
18
+ import { buildComment, generateID, isElementNodeType, isInBibliographySection, isListNode, isSectionNodeType, schema, } from '@manuscripts/transform';
19
19
  import { NodeRange } from 'prosemirror-model';
20
20
  import { wrapInList } from 'prosemirror-schema-list';
21
21
  import { NodeSelection, TextSelection, } from 'prosemirror-state';
@@ -101,7 +101,6 @@ export const createBlock = (nodeType, position, state, dispatch) => {
101
101
  case state.schema.nodes.equation_element:
102
102
  node = state.schema.nodes.equation_element.create({}, [
103
103
  state.schema.nodes.equation.create(),
104
- createAndFillFigcaptionElement(state),
105
104
  ]);
106
105
  break;
107
106
  default:
@@ -247,10 +246,10 @@ export const insertCrossReference = (state, dispatch) => {
247
246
  return true;
248
247
  };
249
248
  export const insertInlineEquation = (state, dispatch) => {
250
- const inlineMathFragment = buildInlineMathFragment(state.selection.$anchor.parent.attrs.id, selectedText().replace(/^\$/, '').replace(/\$$/, ''));
251
249
  const sourcePos = state.selection.from - 1;
252
250
  const tr = state.tr.replaceSelectionWith(state.schema.nodes.inline_equation.create({
253
- id: inlineMathFragment._id,
251
+ format: 'tex',
252
+ contents: selectedText().replace(/^\$/, '').replace(/\$$/, ''),
254
253
  }));
255
254
  if (dispatch) {
256
255
  const selection = NodeSelection.create(tr.doc, tr.mapping.map(sourcePos) + 1);
@@ -652,3 +651,40 @@ export const updateCommentAnnotationState = (state, dispatch) => {
652
651
  dispatch(tr);
653
652
  }
654
653
  };
654
+ export const insertTableFootnote = (node, position, state, dispatch) => {
655
+ var _a;
656
+ const footnote = state.schema.nodes.footnote.createAndFill({
657
+ id: generateID(ObjectTypes.Footnote),
658
+ kind: 'footnote',
659
+ });
660
+ const insertedAt = state.selection.to;
661
+ const inlineFootnotes = findChildrenByType(node, schema.nodes.inline_footnote);
662
+ const inlineFootnoteNode = state.schema.nodes.inline_footnote.create({
663
+ rids: [footnote.attrs.id],
664
+ contents: inlineFootnotes.length + 1,
665
+ });
666
+ const tr = state.tr;
667
+ tr.insert(insertedAt, inlineFootnoteNode);
668
+ const footnoteElement = state.schema.nodes.footnotes_element.create({}, footnote);
669
+ const tableElementFooter = findChildrenByType(node, schema.nodes.table_element_footer);
670
+ let insertionPos;
671
+ if (tableElementFooter.length) {
672
+ const pos = tableElementFooter[0].pos;
673
+ insertionPos = position + pos + tableElementFooter[0].node.nodeSize + 1;
674
+ tr.insert(insertionPos, footnoteElement);
675
+ }
676
+ else {
677
+ const tableSize = (_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize;
678
+ if (tableSize) {
679
+ insertionPos = position + tableSize + 2;
680
+ const tableElementFooter = schema.nodes.table_element_footer.create({
681
+ id: generateID(ObjectTypes.TableElementFooter),
682
+ }, [footnoteElement]);
683
+ tr.insert(insertionPos, tableElementFooter);
684
+ }
685
+ }
686
+ if (dispatch && insertionPos) {
687
+ const nodeSelection = NodeSelection.create(tr.doc, insertionPos);
688
+ dispatch(tr.setSelection(nodeSelection));
689
+ }
690
+ };
@@ -14,7 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { isInBibliographySection, nodeNames, schema, } from '@manuscripts/transform';
17
- import { addComment, createBlock } from '../commands';
17
+ import { findChildrenByType, hasParentNodeOfType } from 'prosemirror-utils';
18
+ import { addComment, createBlock, insertTableFootnote } from '../commands';
18
19
  import { PopperManager } from './popper';
19
20
  const popper = new PopperManager();
20
21
  const listTypes = [schema.nodes.ordered_list, schema.nodes.bullet_list];
@@ -160,6 +161,20 @@ export class ContextMenu {
160
161
  }));
161
162
  }));
162
163
  }
164
+ if (type === schema.nodes.table_element) {
165
+ const isInTable = hasParentNodeOfType(schema.nodes.table)(this.view.state.selection);
166
+ if (isInTable) {
167
+ menu.appendChild(this.createMenuSection((section) => {
168
+ section.appendChild(this.createMenuItem('Add Reference Note', () => {
169
+ const footnotesElement = findChildrenByType(this.node, schema.nodes.footnotes_element);
170
+ if (!footnotesElement.length) {
171
+ const { state, dispatch } = this.view;
172
+ insertTableFootnote(this.node, this.getPos(), state, dispatch);
173
+ }
174
+ }));
175
+ }));
176
+ }
177
+ }
163
178
  if (!readonlyTypes.includes(type) &&
164
179
  !readonlyTypes.includes($pos.parent.type)) {
165
180
  menu.appendChild(this.createMenuSection((section) => {
@@ -13,6 +13,15 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
16
25
  export const isNodeOfType = (...type) => (node) => {
17
26
  const [head, ...tail] = type;
18
27
  if (node.type === node.type.schema.nodes[head]) {
@@ -44,3 +53,13 @@ export const mergeSimilarItems = (compareFunc, mergeFunc) => (items) => {
44
53
  ];
45
54
  }, []);
46
55
  };
56
+ export const renderMath = (math, format) => __awaiter(void 0, void 0, void 0, function* () {
57
+ if (format === 'tex') {
58
+ const { convertTeXToSVG } = yield import('../lib/tex-to-svg');
59
+ return convertTeXToSVG(math);
60
+ }
61
+ else {
62
+ const { convertMathMLToSVG } = yield import('../lib/mathml-to-svg');
63
+ return convertMathMLToSVG(math);
64
+ }
65
+ });
@@ -0,0 +1,66 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import 'mathjax-full/js/util/entities/all';
17
+ import { xmlSerializer } from '@manuscripts/transform';
18
+ import { HTMLAdaptor } from 'mathjax-full/js/adaptors/HTMLAdaptor';
19
+ import { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';
20
+ import { HTMLDocument } from 'mathjax-full/js/handlers/html/HTMLDocument';
21
+ import { MathML } from 'mathjax-full/js/input/mathml';
22
+ import { SVG } from 'mathjax-full/js/output/svg';
23
+ class ManuscriptsMmlFactory extends MmlFactory {
24
+ constructor() {
25
+ super();
26
+ this.nodeMap.set('image', this.nodeMap.get('none'));
27
+ }
28
+ create(kind, properties = {}, children = []) {
29
+ if (kind === 'image') {
30
+ return this.node['none'](properties, children);
31
+ }
32
+ return this.node[kind](properties, children);
33
+ }
34
+ }
35
+ class ManuscriptsHTMLAdaptor extends HTMLAdaptor {
36
+ setAttribute(node, name, value, ns) {
37
+ if (name !== 'xmlns') {
38
+ ns ? node.setAttributeNS(ns, name, value) : node.setAttribute(name, value);
39
+ }
40
+ }
41
+ }
42
+ const InputJax = new MathML();
43
+ const OutputJax = new SVG({
44
+ fontCache: 'none',
45
+ });
46
+ const adaptor = new ManuscriptsHTMLAdaptor(window);
47
+ const doc = new HTMLDocument(document, adaptor, {
48
+ InputJax,
49
+ OutputJax,
50
+ MmlFactory: new ManuscriptsMmlFactory(),
51
+ });
52
+ doc.addStyleSheet();
53
+ export const convertMathMLToSVG = (mathml, display = true) => {
54
+ const item = doc.convert(mathml, {
55
+ display,
56
+ em: 16,
57
+ ex: 8,
58
+ containerWidth: 1000000,
59
+ lineWidth: 1000000,
60
+ scale: 1,
61
+ });
62
+ if (!item || !item.firstChild) {
63
+ return null;
64
+ }
65
+ return xmlSerializer.serializeToString(item.firstChild);
66
+ };
@@ -0,0 +1,56 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import 'mathjax-full/js/util/entities/all';
17
+ import { xmlSerializer } from '@manuscripts/transform';
18
+ import { HTMLAdaptor } from 'mathjax-full/js/adaptors/HTMLAdaptor';
19
+ import { HTMLDocument } from 'mathjax-full/js/handlers/html/HTMLDocument';
20
+ import { TeX } from 'mathjax-full/js/input/tex';
21
+ import { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';
22
+ import { SVG } from 'mathjax-full/js/output/svg';
23
+ export const packages = AllPackages.filter((name) => name !== 'html' && name !== 'bussproofs');
24
+ class ManuscriptsHTMLAdaptor extends HTMLAdaptor {
25
+ setAttribute(node, name, value, ns) {
26
+ if (name !== 'xmlns') {
27
+ ns ? node.setAttributeNS(ns, name, value) : node.setAttribute(name, value);
28
+ }
29
+ }
30
+ }
31
+ const InputJax = new TeX({
32
+ packages,
33
+ });
34
+ const OutputJax = new SVG({
35
+ fontCache: 'none',
36
+ });
37
+ const adaptor = new ManuscriptsHTMLAdaptor(window);
38
+ const doc = new HTMLDocument(document, adaptor, {
39
+ InputJax,
40
+ OutputJax,
41
+ });
42
+ doc.addStyleSheet();
43
+ export const convertTeXToSVG = (tex, display = true) => {
44
+ const item = doc.convert(tex, {
45
+ display,
46
+ em: 16,
47
+ ex: 8,
48
+ containerWidth: 1000000,
49
+ lineWidth: 1000000,
50
+ scale: 1,
51
+ });
52
+ if (!item || !item.firstChild) {
53
+ return null;
54
+ }
55
+ return xmlSerializer.serializeToString(item.firstChild);
56
+ };
@@ -19,6 +19,7 @@ import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
19
19
  import { hasParentNodeOfType } from 'prosemirror-utils';
20
20
  import { Decoration, DecorationSet } from 'prosemirror-view';
21
21
  import { findParentNodeWithIdValue } from '../../lib/utils';
22
+ import { placeholderWidget } from '../placeholder';
22
23
  export const footnotesKey = new PluginKey('footnotes');
23
24
  export const buildPluginState = (doc) => {
24
25
  const nodes = [];
@@ -97,9 +98,10 @@ export default () => {
97
98
  }
98
99
  const { labels } = footnotesKey.getState(state);
99
100
  state.doc.descendants((node, pos) => {
100
- if (labels) {
101
- if (isFootnoteNode(node)) {
102
- const id = node.attrs.id;
101
+ var _a;
102
+ if (isFootnoteNode(node)) {
103
+ const id = node.attrs.id;
104
+ if (labels) {
103
105
  const label = labels.get(id);
104
106
  if (label) {
105
107
  decorations.push(Decoration.widget(pos + 2, labelWidget(label, id), {
@@ -107,6 +109,9 @@ export default () => {
107
109
  }));
108
110
  }
109
111
  }
112
+ if (!((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.textContent)) {
113
+ decorations.push(Decoration.widget(pos + 2, placeholderWidget('Add new note here')));
114
+ }
110
115
  }
111
116
  if (node.type === schema.nodes.footnotes_element) {
112
117
  decorations.push(Decoration.node(pos, pos + node.nodeSize, {
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { Plugin, TextSelection } from 'prosemirror-state';
17
17
  import { Decoration, DecorationSet } from 'prosemirror-view';
18
- const placeholderWidget = (placeholder) => (view, getPos) => {
18
+ export const placeholderWidget = (placeholder) => (view, getPos) => {
19
19
  const element = document.createElement('span');
20
20
  element.className = 'placeholder-text';
21
21
  element.textContent = placeholder;
@@ -14,6 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { sanitize } from '../lib/dompurify';
17
+ import { renderMath } from '../lib/helpers';
17
18
  import { BaseNodeView } from './base_node_view';
18
19
  import { createNodeView } from './creators';
19
20
  export class EquationView extends BaseNodeView {
@@ -29,22 +30,29 @@ export class EquationView extends BaseNodeView {
29
30
  this.dom.setAttribute('id', this.node.attrs.id);
30
31
  };
31
32
  this.updateContents = () => {
32
- const { SVGStringRepresentation } = this.node.attrs;
33
+ const { contents, format } = this.node.attrs;
33
34
  while (this.dom.hasChildNodes()) {
34
35
  this.dom.removeChild(this.dom.firstChild);
35
36
  }
36
- if (SVGStringRepresentation) {
37
- const fragment = sanitize(SVGStringRepresentation, {
38
- USE_PROFILES: { svg: true },
39
- });
40
- this.dom.appendChild(fragment);
41
- }
42
- else {
43
- const placeholder = document.createElement('div');
44
- placeholder.className = 'equation-placeholder';
45
- placeholder.textContent = '<Equation>';
46
- this.dom.appendChild(placeholder);
47
- }
37
+ renderMath(contents, format)
38
+ .then((svgContent) => {
39
+ if (svgContent) {
40
+ const fragment = sanitize(svgContent, {
41
+ USE_PROFILES: { svg: true },
42
+ });
43
+ this.dom.appendChild(fragment);
44
+ }
45
+ else {
46
+ const placeholder = document.createElement('div');
47
+ placeholder.className = 'equation-placeholder';
48
+ placeholder.textContent = '<Equation>';
49
+ this.dom.appendChild(placeholder);
50
+ }
51
+ return true;
52
+ })
53
+ .catch((error) => {
54
+ console.error(error);
55
+ });
48
56
  };
49
57
  this.ignoreMutation = () => true;
50
58
  }
@@ -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,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { sanitize } from '../lib/dompurify';
17
+ import { renderMath } from '../lib/helpers';
17
18
  import { isRejectedInsert } from '../lib/track-changes-utils';
18
19
  import { BaseNodeView } from './base_node_view';
19
20
  import { createNodeView } from './creators';
@@ -26,22 +27,29 @@ export class InlineEquationView extends BaseNodeView {
26
27
  };
27
28
  this.updateContents = () => {
28
29
  if (!isRejectedInsert(this.node)) {
29
- const { SVGRepresentation } = this.node.attrs;
30
+ const { contents, format } = this.node.attrs;
30
31
  while (this.dom.hasChildNodes()) {
31
32
  this.dom.removeChild(this.dom.firstChild);
32
33
  }
33
- if (SVGRepresentation) {
34
- const fragment = sanitize(SVGRepresentation, {
35
- USE_PROFILES: { svg: true },
36
- });
37
- this.dom.appendChild(fragment);
38
- }
39
- else {
40
- const placeholder = document.createElement('div');
41
- placeholder.className = 'equation-placeholder';
42
- placeholder.textContent = '<Equation>';
43
- this.dom.appendChild(placeholder);
44
- }
34
+ renderMath(contents, format)
35
+ .then((svgContent) => {
36
+ if (svgContent) {
37
+ const fragment = sanitize(svgContent, {
38
+ USE_PROFILES: { svg: true },
39
+ });
40
+ this.dom.appendChild(fragment);
41
+ }
42
+ else {
43
+ const placeholder = document.createElement('div');
44
+ placeholder.className = 'equation-placeholder';
45
+ placeholder.textContent = '<Equation>';
46
+ this.dom.appendChild(placeholder);
47
+ }
48
+ return true;
49
+ })
50
+ .catch((error) => {
51
+ console.error(error);
52
+ });
45
53
  }
46
54
  else {
47
55
  this.dom.innerHTML = '';
@@ -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');
@@ -54,3 +54,4 @@ export declare const deleteHighlightMarkers: (rid: string) => Command;
54
54
  export declare function addComment(state: ManuscriptEditorState, dispatch?: Dispatch): boolean;
55
55
  export declare function addComment(state: ManuscriptEditorState, dispatch?: Dispatch, viewNode?: ManuscriptNode, resolvePos?: ResolvedPos): boolean;
56
56
  export declare const updateCommentAnnotationState: (state: ManuscriptEditorState, dispatch?: Dispatch) => void;
57
+ export declare const insertTableFootnote: (node: ManuscriptNode, position: number, state: ManuscriptEditorState, dispatch?: Dispatch) => void;
@@ -18,3 +18,4 @@ import { Node, ResolvedPos } from 'prosemirror-model';
18
18
  export declare const isNodeOfType: (...type: string[]) => (node: Node) => boolean;
19
19
  export declare const nearestAncestor: (func: (node: ManuscriptNode) => boolean) => ($pos: ResolvedPos) => number | null;
20
20
  export declare const mergeSimilarItems: <T>(compareFunc: (a: T, b: T) => boolean, mergeFunc: (a: T, b: T) => T) => (items: T[]) => T[];
21
+ export declare const renderMath: (math: string, format: string) => Promise<string | null>;
@@ -0,0 +1,17 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import 'mathjax-full/js/util/entities/all';
17
+ export declare const convertMathMLToSVG: (mathml: string, display?: boolean) => string | null;
@@ -0,0 +1,18 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import 'mathjax-full/js/util/entities/all';
17
+ export declare const packages: string[];
18
+ export declare const convertTeXToSVG: (tex: string, display?: boolean) => string | null;
@@ -13,6 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { ManuscriptEditorView } from '@manuscripts/transform';
16
17
  import { Plugin } from 'prosemirror-state';
18
+ export declare const placeholderWidget: (placeholder: string) => (view: ManuscriptEditorView, getPos: () => number | undefined) => HTMLSpanElement;
17
19
  declare const _default: () => Plugin<null>;
18
20
  export default _default;
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.7.5",
4
+ "version": "1.7.6-LEAN-3092-5",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -29,13 +29,14 @@
29
29
  "dependencies": {
30
30
  "@iarna/word-count": "^1.1.2",
31
31
  "@manuscripts/assets": "^0.6.4",
32
- "@manuscripts/json-schema": "^2.2.2",
33
- "@manuscripts/library": "1.3.2",
34
- "@manuscripts/style-guide": "1.7.4",
32
+ "@manuscripts/json-schema": "2.2.3-LEAN-3092-1",
33
+ "@manuscripts/library": "1.3.2-LEAN-3092-3",
34
+ "@manuscripts/style-guide": "1.7.4-LEAN-3092-5",
35
35
  "@manuscripts/track-changes-plugin": "^1.7.5",
36
- "@manuscripts/transform": "2.1.1",
36
+ "@manuscripts/transform": "2.1.1-LEAN-3092-7",
37
37
  "astrocite-eutils": "^0.16.4",
38
38
  "axios": "^1.6.7",
39
+ "mathjax-full": "^3.2.2",
39
40
  "codemirror": "^5.58.1",
40
41
  "dompurify": "^2.4.1",
41
42
  "grapheme-splitter": "^1.0.4",
@@ -109,4 +110,4 @@
109
110
  "resolutions": {
110
111
  "@types/react": "^17.0.2"
111
112
  }
112
- }
113
+ }
package/styles/Editor.css CHANGED
@@ -546,6 +546,7 @@
546
546
  }
547
547
 
548
548
  .ProseMirror .placeholder-text {
549
+ font-style: italic;
549
550
  color: #c9c9c9;
550
551
  margin: 0;
551
552
  }