@zzish/math-rich-input 0.1.24 → 0.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -18167,6 +18167,18 @@ var LATEX_SYMBOLS = [// {name:"Times",latex:"\\times",tooltip:"Times [#X)"},
18167
18167
  buttonLatex: "\\oint",
18168
18168
  tooltip: "Contour integral",
18169
18169
  moveCursor: -2
18170
+ }, {
18171
+ name: "Surface integral",
18172
+ latex: "\\oiint_{#}^{#}",
18173
+ buttonLatex: "\\oiint",
18174
+ tooltip: "Surface integral",
18175
+ moveCursor: -2
18176
+ }, {
18177
+ name: "Volume integral",
18178
+ latex: "\\oiiint_{#}^{#}",
18179
+ buttonLatex: "\\oiiint",
18180
+ tooltip: "Volume integral",
18181
+ moveCursor: -2
18170
18182
  }, {
18171
18183
  name: "Integral a b",
18172
18184
  latex: "\\int_{#}^{#}",
@@ -18235,6 +18247,11 @@ var LATEX_SYMBOLS = [// {name:"Times",latex:"\\times",tooltip:"Times [#X)"},
18235
18247
  latex: "\\pm",
18236
18248
  buttonLatex: "\\pm",
18237
18249
  tooltip: "Plus or minus"
18250
+ }, {
18251
+ name: "Minus or plus",
18252
+ latex: "\\mp",
18253
+ buttonLatex: "\\mp",
18254
+ tooltip: "Minus or plus"
18238
18255
  }, {
18239
18256
  name: "Times",
18240
18257
  latex: "\\times",
@@ -18620,7 +18637,7 @@ var BUTTON_AREAS = {
18620
18637
  "Common": ["Squared", "Power", "Subscript", "Over", "Surd", "Root", "Nth root", "Hat", "Line", "Ray", "Line segment", "Dot", "dxdy", "Partial dxdy", "Integral a b", "Sum a b", "Product a b", "Right arrow", "Infinity", "Limit x to infinity"],
18621
18638
  "Operators": ["Plus", "Minus", "Center dot", "Times", "Divide", "Equals", "Less than", "Greater than", "Not equal", "Less than or equal", "Greater than or equal", "Plus or minus", "Proportionate", "Approximately", "Implies"],
18622
18639
  "Angles": ["degree", "theta", "phi", "pi", "alpha", "beta", "gamma", "delta", "epsilon", "Delta", "angle", "Parallel", "Perpendicular", "Similar", "Congruent"],
18623
- "GreekLower": ["alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", "iota", "kappa", "lambda", "mu", "nu", "xi", "omicron", "pi", "rho", "sigma", "tau", "upsilon", "phi", "chi", "psi", "omega"],
18640
+ "GreekLower": ["alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", "iota", "kappa", "lambda", "mu", "nu", "xi", "omicron", "pi", "rho", "sigma", "tau", "upsilon", "phi", "varphi", "chi", "psi", "omega"],
18624
18641
  "GreekUpper": ["Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma", "Phi", "Psi", "Omega", "nabla"],
18625
18642
  "Sets": ["cup", "cap", "in", "notin", "emptyset", "forall", "exists", "nexists", "subset", "subseteq", "supset", "supseteq", "nsubset", "nsubseteq", "neg", "Complex numbers", "Natural numbers", "Rational numbers", "Real numbers", "Integers"],
18626
18643
  "Misc": ["because", "therefore", "dots", "cdots", "ll", "gg", "leftarrow", "leftrightarrow", "Leftrightarrow", "mapsto", "bullet", "circ", "Box", "bigcirc", "bigtriangleup", "bigtriangledown", "heartsuit", "diamondsuit", "clubsuit", "spadesuit"],
@@ -18633,8 +18650,8 @@ var BUTTON_AREAS = {
18633
18650
  // "_Cu"]
18634
18651
  "Physics1": ["Squared", "Power", "Subscript", "Over", "Root", "Nth root", "Surd", "Root a over b", "Half", "Third", "Over root 2", "Over root 3", "sum", "delta", "Delta", "Capacitor discharge", "Radioactive decay", "Attenuation of rays", "Delta x over delta t", "dxdt"],
18635
18652
  "Physics2": ["Plus", "Minus", "Plus or minus", "Times", "Equals", "Approximately", "Proportionate"],
18636
- "Physics3": ["alpha", "varepsilon", "eta", "gamma", "lambda", "omega", "mu", "nu", "pi", "rho", "sigma", "phi", "varPhi", "theta", "overline{v_e}", "overline{v_\\mu}", "Subscript zero", "Subscript max", "Subscript min", "Subscript rms"],
18637
- "Expert": ["langle", "rangle", "Double integral", "Triple integral", "Contour integral", "Double dot", "Widehat", "Check", "Tilde", "Mathring", "Right arrow with text", "rightleftharpoons"],
18653
+ "Physics3": ["alpha", "varepsilon", "eta", "gamma", "lambda", "omega", "mu", "nu", "pi", "rho", "sigma", "phi", "Phi", "theta", "overline{v_e}", "overline{v_\\mu}", "Subscript zero", "Subscript max", "Subscript min", "Subscript rms"],
18654
+ "Expert": ["langle", "rangle", "Double integral", "Triple integral", "Contour integral", "Surface integral", "Volume integral", "Double dot", "Widehat", "Check", "Tilde", "Mathring", "Right arrow with text", "rightleftharpoons", "Minus or plus"],
18638
18655
  "Matrices": ["1-vector", "1x2 matrix", "1x3 matrix", "2-vector", "2x2 matrix", "2x3 matrix", "3-vector", "3x2 matrix", "3x3 matrix", "cdots", "vdots", "ddots", "vec{a}", "2x2 matrix round brackets", "2x2 matrix curly brackets"]
18639
18656
  };
18640
18657
 
@@ -18690,10 +18707,16 @@ function toDict(symbols) {
18690
18707
  return dict;
18691
18708
  }
18692
18709
 
18693
- var LATEX_SYMBOLS_DICT = toDict(LATEX_SYMBOLS);
18694
- var NORMAL_SYMBOLS_DICT = toDict(NORMAL_SYMBOLS);
18710
+ var LATEX_SYMBOLS_DICT = null;
18711
+ var NORMAL_SYMBOLS_DICT = null;
18712
+
18713
+ function initialise() {
18714
+ LATEX_SYMBOLS_DICT = toDict(LATEX_SYMBOLS);
18715
+ NORMAL_SYMBOLS_DICT = toDict(NORMAL_SYMBOLS);
18716
+ }
18695
18717
 
18696
18718
  function getSymbolData(name) {
18719
+ if (LATEX_SYMBOLS_DICT === null) initialise();
18697
18720
  if (name in LATEX_SYMBOLS_DICT) return LATEX_SYMBOLS_DICT[name];
18698
18721
  if (name in NORMAL_SYMBOLS_DICT) return NORMAL_SYMBOLS_DICT[name];
18699
18722
 
@@ -20699,7 +20722,7 @@ var SPAN_OPEN_BASE = "<span class=\"base\">";
20699
20722
  var SPAN_CLOSE = "</span>";
20700
20723
  var MARK$1 = String.fromCharCode(0); // const MARK = "_M_A_R_K_"
20701
20724
 
20702
- var MARK_REG_EXP$1 = new RegExp(MARK$1, "g");
20725
+ var MARK_REG_EXP = new RegExp(MARK$1, "g");
20703
20726
  var TEMP_CHAR = String.fromCharCode(1);
20704
20727
  var TEMP_CHAR_REG_EXP = new RegExp(TEMP_CHAR, "g");
20705
20728
  var DOLLAR_SLASH_REG_EXP = /\\\$/g;
@@ -20713,6 +20736,9 @@ var MIME_TYPE_HTML$1 = "text/html";
20713
20736
  var MIME_TYPE_TEX$1 = "application/x-tex";
20714
20737
  var MIME_TYPE_LATEX = "application/x-latex";
20715
20738
  var MIME_TYPE_ZZISH_HTML_MATH$1 = "application/x-zzish-html-math";
20739
+ function getMark() {
20740
+ return MARK$1;
20741
+ }
20716
20742
  function isKatexNode(node) {
20717
20743
  return node.className === "katex" || node.className === "katex-error";
20718
20744
  }
@@ -20724,7 +20750,8 @@ function isTextNode(node) {
20724
20750
  function isBIUNode(node) {
20725
20751
  if (node.nodeType !== 1) return false;
20726
20752
  var tagName = node.tagName.toLowerCase();
20727
- return tagName === "b" || tagName === "i" || tagName === "u" || tagName === "sup" || tagName === "sub" || tagName === "p";
20753
+ if (tagName === "span") return !isKatexNode(node);
20754
+ return tagName === "b" || tagName === "strong" || tagName === "i" || tagName === "em" || tagName === "u" || tagName === "sup" || tagName === "sub" || tagName === "p";
20728
20755
  }
20729
20756
 
20730
20757
  function isBrNode(node) {
@@ -20732,13 +20759,18 @@ function isBrNode(node) {
20732
20759
  return node.tagName.toLowerCase() === "br";
20733
20760
  }
20734
20761
 
20762
+ function nodeStartsWithSmallSpace(node) {
20763
+ if (node.nodeType === 3 && node.nodeValue.length >= 1 && node.nodeValue.charCodeAt(0) === SMALL_SPACE_CHAR_CODE$1) return true;
20764
+ return false;
20765
+ }
20766
+
20735
20767
  function isSmallSpace(node) {
20736
20768
  if (node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === SMALL_SPACE_CHAR_CODE$1) return true;
20737
20769
  return false;
20738
20770
  }
20739
20771
 
20740
- function startsWithSmallSpace(node) {
20741
- var textNode = findFirstTextNode(node);
20772
+ function startsWithSmallSpace(editableDiv) {
20773
+ var textNode = findFirstTextNode(editableDiv);
20742
20774
  return isSmallSpace(textNode);
20743
20775
  }
20744
20776
  function countNodeTypes(node) {
@@ -20782,7 +20814,7 @@ function getNodeTextLength(node) {
20782
20814
  return text.length;
20783
20815
  }
20784
20816
  function removeMarks(raw_text) {
20785
- return raw_text.replace(MARK_REG_EXP$1, "");
20817
+ return raw_text.replace(MARK_REG_EXP, "");
20786
20818
  }
20787
20819
  function getCharacterBeforeMarks(text) {
20788
20820
  var start = text.indexOf(MARK$1);
@@ -20960,8 +20992,6 @@ function addTextForNode(node, arrayOfText) {
20960
20992
  try {
20961
20993
  if (isTextNode(node)) {
20962
20994
  addText(arrayOfText, useHtmlMath ? encodeToHtml(node.nodeValue) : encodeToLatex(node.nodeValue), mark, offset, useHtmlMath);
20963
- } else if (isBrNode(node)) {
20964
- useHtmlMath && arrayOfText.push("<br>");
20965
20995
  } else if (isBIUNode(node)) {
20966
20996
  useHtmlMath && arrayOfText.push("<" + node.nodeName + ">");
20967
20997
 
@@ -21097,8 +21127,12 @@ function renderLatexString(katex, s, t) {
21097
21127
  return renderedString;
21098
21128
  }
21099
21129
  function rawTextToHtml(katex, string, mimeType) {
21100
- if (string === "") return "";
21101
- if (mimeType === null || mimeType === undefined || mimeType === "") mimeType = determineMimeType(string);
21130
+ if (string === "") return "<p>" + SMALL_SPACE$1 + "</p>";
21131
+
21132
+ if (mimeType == null || mimeType === "") {
21133
+ mimeType = determineMimeType(string);
21134
+ }
21135
+
21102
21136
  if (mimeType === MIME_TYPE_PLAIN_TEXT$1) return encodeToHtml(string);
21103
21137
  var parseAsTex;
21104
21138
  if (mimeType === MIME_TYPE_TEX$1 || mimeType === MIME_TYPE_LATEX) parseAsTex = true;else if (mimeType === MIME_TYPE_HTML$1 || mimeType === MIME_TYPE_ZZISH_HTML_MATH$1) parseAsTex = false;else {
@@ -21256,6 +21290,93 @@ function findNodeWithIndex(node, index) {
21256
21290
 
21257
21291
  return null;
21258
21292
  }
21293
+
21294
+ function findGlobalOffset(node, nodeToFind, offset) {
21295
+ var result = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
21296
+ // console.log(node.nodeType+":"+node.nodeValue+" === "+ nodeToFind.nodeType+":"+nodeToFind.nodeValue)
21297
+ // console.log(node === nodeToFind)
21298
+ if (result === null || result === undefined) throw error;
21299
+
21300
+ if (node === nodeToFind) {
21301
+ result.offset = result.offset + offset; // console.log("result.offset now: "+result.offset)
21302
+
21303
+ if (isTextNode(node) && nodeStartsWithSmallSpace(node)) {
21304
+ if (offset > 0) result.offset = result.offset - 1;
21305
+ }
21306
+
21307
+ return true;
21308
+ }
21309
+
21310
+ if (isKatexNode(node)) {
21311
+ if (node === nodeToFind || node.contains(nodeToFind)) return true;else {
21312
+ result.offset++;
21313
+ return false;
21314
+ }
21315
+ }
21316
+
21317
+ if (isTextNode(node)) {
21318
+ result.offset += node.nodeValue.length;
21319
+ if (nodeStartsWithSmallSpace(node)) result.offset -= 1;
21320
+ return false;
21321
+ }
21322
+
21323
+ var childNodes = node.childNodes;
21324
+ if (childNodes === null || childNodes === undefined) return false;
21325
+
21326
+ for (var i = 0; i < childNodes.length; i++) {
21327
+ var child = childNodes[i]; // console.log("Checking child:"+child.nodeType+":"+child.tagName+":"+child.nodeValue)
21328
+
21329
+ var found = findGlobalOffset(child, nodeToFind, offset, result);
21330
+ if (found) return true;
21331
+ }
21332
+
21333
+ if (node.nodeType === 1 && node.tagName === "P") {
21334
+ result.offset++;
21335
+ }
21336
+
21337
+ return false;
21338
+ }
21339
+
21340
+ function findNodeAndOffsetForGlobalOffset(node, globalOffset) {
21341
+ var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
21342
+
21343
+ if (isKatexNode(node)) {
21344
+ result.node = null;
21345
+ result.offset++;
21346
+ return false;
21347
+ }
21348
+
21349
+ if (isTextNode(node)) {
21350
+ result.node = node;
21351
+ result.offset += node.nodeValue.length;
21352
+ if (nodeStartsWithSmallSpace(node)) result.offset -= 1; // console.log("result.offset now: "+result.offset)
21353
+
21354
+ return false;
21355
+ }
21356
+
21357
+ var childNodes = node.childNodes;
21358
+ if (childNodes === null || childNodes === undefined) return false;
21359
+
21360
+ for (var i = 0; i < childNodes.length; i++) {
21361
+ var found = findNodeAndOffsetForGlobalOffset(childNodes[i], globalOffset, result);
21362
+ if (found) return true;
21363
+
21364
+ if (result.node !== null && result.node !== undefined) {
21365
+ if (result.offset >= globalOffset) {
21366
+ result.offset = globalOffset - (result.offset - result.node.nodeValue.length);
21367
+ return true;
21368
+ }
21369
+ }
21370
+ }
21371
+
21372
+ if (node.nodeType === 1 && node.tagName === "P") {
21373
+ result.node = null;
21374
+ result.offset++;
21375
+ }
21376
+
21377
+ return false;
21378
+ }
21379
+
21259
21380
  function findFirstTextNode(node) {
21260
21381
  if (isTextNode(node)) return node;
21261
21382
  var nodes = node.childNodes;
@@ -21266,7 +21387,8 @@ function findFirstTextNode(node) {
21266
21387
  }
21267
21388
 
21268
21389
  return null;
21269
- }
21390
+ } // https://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html
21391
+
21270
21392
  function getRangeParams(editableDiv) {
21271
21393
  // console.log ("getRangeParams")
21272
21394
  // console.log("Inner html: "+editableDiv.innerHTML)
@@ -21284,22 +21406,113 @@ function getRangeParams(editableDiv) {
21284
21406
  return null;
21285
21407
  }
21286
21408
 
21287
- var range = selection.getRangeAt(0);
21409
+ var range = selection.getRangeAt(0); // logAllDescendants(editableDiv)
21410
+ // If the range is not within a text node, move it to a text node
21411
+ // This typically happens when the end of a range is at the start of a new line
21412
+
21413
+ if (range.startContainer.nodeType !== 3) {
21414
+ var textNode = findFirstTextNode(range.startContainer);
21415
+
21416
+ if (textNode !== null) {
21417
+ console.warn("Adjusting start pos in getRangeParams as container was of type: " + range.startContainer.nodeName);
21418
+ range.setStart(textNode, 0);
21419
+ } else {
21420
+ console.error("Unable to getRangeParams. seletion.startContainer is not a text node. " + "Node type: " + range.startContainer.nodeName);
21421
+ return null;
21422
+ }
21423
+ }
21424
+
21425
+ if (range.endContainer.nodeType !== 3) {
21426
+ var _textNode = findFirstTextNode(range.endContainer);
21427
+
21428
+ if (_textNode !== null) {
21429
+ console.warn("Adjusting end pos in getRangeParams as container was of type: " + range.endContainer.nodeName);
21430
+ range.setEnd(_textNode, 0);
21431
+ } else {
21432
+ console.error("Unable to getRangeParams. seletion.endContainer is not a text node. " + "Node type: " + range.endContainer.nodeName);
21433
+ return null;
21434
+ }
21435
+ } // Find the index of the start and end nodes
21436
+
21437
+
21288
21438
  var startNodeIndex = findIndexOfNode(editableDiv, range.startContainer);
21289
21439
  var endNodeIndex = findIndexOfNode(editableDiv, range.endContainer); // console.log(editableDiv)
21290
21440
  // console.log("Start node: "+range.startContainer)
21291
21441
  // console.log("Start node: |"+range.startContainer.nodeValue+"|")
21292
21442
  // console.log("Start node index found: "+startNodeIndex)
21293
21443
  // console.log("Start node offset: "+range.startOffset)
21444
+ // Find the global offset of the start and end nodes
21445
+
21446
+ var startResult = {
21447
+ offset: 0
21448
+ };
21449
+ findGlobalOffset(editableDiv, range.startContainer, range.startOffset, startResult); // console.log("Global offset of start: "+startResult.offset)
21450
+
21451
+ var endResult = {
21452
+ offset: 0
21453
+ };
21454
+ findGlobalOffset(editableDiv, range.endContainer, range.endOffset, endResult); // console.log("Global offset of end: "+endResult.offset)
21294
21455
 
21295
21456
  var rangeParams = {
21296
21457
  startNodeIndex: startNodeIndex,
21297
21458
  startOffset: range.startOffset,
21298
21459
  endNodeIndex: endNodeIndex,
21299
- endOffset: range.endOffset
21460
+ endOffset: range.endOffset,
21461
+ startGlobalOffset: startResult.offset,
21462
+ endGlobalOffset: endResult.offset
21300
21463
  };
21301
21464
  return rangeParams;
21302
21465
  }
21466
+
21467
+ function setRangeParamsFromGlobalOffsets(editableDiv, params) {
21468
+ var new_range = null;
21469
+
21470
+ try {
21471
+ if (params === null || params === undefined) throw new Error("Can't set range params: params === " + params);
21472
+ var startResult = {
21473
+ offset: 0
21474
+ };
21475
+ findNodeAndOffsetForGlobalOffset(editableDiv, params.startGlobalOffset, startResult); // console.log(startResult.node.nodeType+":"+startResult.node.tagName+":"+
21476
+ // startResult.node.nodeValue+":"+startResult.offset)
21477
+
21478
+ var endResult = {
21479
+ offset: 0
21480
+ };
21481
+ findNodeAndOffsetForGlobalOffset(editableDiv, params.endGlobalOffset, endResult); // console.log(endResult.node.nodeType+":"+endResult.node.tagName+":"+
21482
+ // endResult.node.nodeValue+":"+endResult.offset)
21483
+
21484
+ if (!startResult.node || !endResult.node || !startResult.offset || !endResult.offset) {
21485
+ console.log("Can't set range with start and end results");
21486
+ console.log(startResult);
21487
+ console.log(endResult);
21488
+ throw new Error("Could not extract valid nodes and offsets from params");
21489
+ }
21490
+
21491
+ if (startResult.offset === 0 && startResult.node.nodeValue.length > 0 && nodeStartsWithSmallSpace(startResult.node)) {
21492
+ startResult.offset = 1;
21493
+ }
21494
+
21495
+ if (endResult.offset === 0 && endResult.node.nodeValue.length > 0 && nodeStartsWithSmallSpace(endResult.node)) {
21496
+ endResult.offset = 1;
21497
+ } // console.log("Setting range to:")
21498
+ // console.log(startResult.node.nodeType+":"+startResult.node.tagName+":"+
21499
+ // startResult.node.nodeValue+":"+startResult.offset)
21500
+
21501
+
21502
+ new_range = document.createRange();
21503
+ new_range.setStart(startResult.node, startResult.offset);
21504
+ new_range.setEnd(endResult.node, endResult.offset);
21505
+ var selection = window.getSelection();
21506
+ selection.removeAllRanges();
21507
+ selection.addRange(new_range);
21508
+ } catch (error) {
21509
+ console.error(error);
21510
+ console.log("Trying to set range:");
21511
+ console.log(new_range);
21512
+ console.log(editableDiv.childNodes);
21513
+ }
21514
+ }
21515
+
21303
21516
  function setRangeParams(editableDiv, params) {
21304
21517
  // console.log("setRangeParams")
21305
21518
  // console.log(params)
@@ -21311,6 +21524,11 @@ function setRangeParams(editableDiv, params) {
21311
21524
  return;
21312
21525
  }
21313
21526
 
21527
+ if (params.startGlobalOffset) {
21528
+ setRangeParamsFromGlobalOffsets(editableDiv, params);
21529
+ return;
21530
+ }
21531
+
21314
21532
  if (params.startNodeIndex === null || params.startNodeIndex === undefined) {
21315
21533
  console.error("Can't set range params: params.startNodeIndex === " + params.startNodeIndex);
21316
21534
  return;
@@ -21369,7 +21587,7 @@ function setRangeParams(editableDiv, params) {
21369
21587
  }
21370
21588
 
21371
21589
  if (endNode === null) {
21372
- console.error("Could not set range to start node with index " + params.endNodeIndex);
21590
+ console.error("Could not set range to end node with index " + params.endNodeIndex);
21373
21591
  endNode = findFirstTextNode(editableDiv);
21374
21592
  endOffset = 0;
21375
21593
  }
@@ -21386,6 +21604,12 @@ function setRangeParams(editableDiv, params) {
21386
21604
 
21387
21605
  new_range = document.createRange();
21388
21606
  new_range.setStart(startNode, startOffset);
21607
+
21608
+ if (endOffset > endNode.length) {
21609
+ console.warn("endOffset > endNode.length when setting range: " + endOffset + " > " + endNode.length + " - " + endNode.nodeType + " - " + endNode.nodeValue);
21610
+ endOffset = endNode.length;
21611
+ }
21612
+
21389
21613
  new_range.setEnd(endNode, endOffset); // console.log("Setting range")
21390
21614
  // console.log(new_range)
21391
21615
 
@@ -21400,6 +21624,163 @@ function setRangeParams(editableDiv, params) {
21400
21624
  }
21401
21625
  } // https://stackoverflow.com/questions/6659351/removing-all-script-tags-from-html-with-js-regular-expression
21402
21626
 
21627
+ function sanitiseHtmlForElement(element) {
21628
+ if (isTextNode(element)) return document.createTextNode(element.nodeValue);
21629
+
21630
+ if (isKatexNode(element)) {
21631
+ // console.log("Copying katex node")
21632
+ var clone = element.cloneNode(true);
21633
+ return clone;
21634
+ }
21635
+
21636
+ if (element.tagName === "HEAD" || element.tagName === "STYLE" || element.tagName === "LINK") return null;
21637
+ var new_element = null;
21638
+
21639
+ if (isBIUNode(element)) {
21640
+ // console.log("Updating descendent: "+element.textContent)
21641
+ new_element = document.createElement(element.tagName);
21642
+ } else if (element.nodeType === 1 && (element.tagName === "LI" || element.tagName === "DT" || element.tagName === "DD" || element.tagName === "THEAD" || element.tagName === "TR" || element.tagName === "H1" || element.tagName === "H2" || element.tagName === "H3" || element.tagName === "H4" || element.tagName === "H5" || element.tagName === "H6")) {
21643
+ // console.log("Converting descendent: <"+element.tagName+">"+element.textContent)
21644
+ new_element = document.createElement('p');
21645
+ } else {
21646
+ // console.log("Stripping descendent: <"+element.tagName+">"+element.textContent)
21647
+ new_element = document.createElement('span');
21648
+ }
21649
+
21650
+ if (element.hasChildNodes()) {
21651
+ for (var i = 0; i < element.childNodes.length; i++) {
21652
+ var new_child = sanitiseHtmlForElement(element.childNodes[i]);
21653
+ if (new_child !== null) new_element.appendChild(new_child);
21654
+ if (element.childNodes[i].tagName === "TH" || element.childNodes[i].tagName === "TD") new_element.appendChild(document.createTextNode(" "));
21655
+ }
21656
+ }
21657
+
21658
+ return new_element;
21659
+ }
21660
+
21661
+ var SPAN_TAG = new RegExp("<span>|</span>", "g"); // const BR_TAG_REG_EXP = new RegExp("<br[\s\S]*?>","g")
21662
+ // const COMMENT_TAG_REG_EXP = new RegExp("<!--.+?-->","g")
21663
+ // const COMMENT_TAG_REG_EXP = new RegExp("(?=<!--([\s\S]*?)-->","g")
21664
+ // const COMMENT_TAG_REG_EXP = new RegExp("<!--[\s\S]*?-->","gm")
21665
+ // const MULTI_WHITE_SPACE_REG_EXP = new RegExp("\s{2,}","gm")
21666
+
21667
+ var KATEX_START_HTML = "<span class=\"katex\"";
21668
+ var KATEX_END_HTML = "</span></span></span></span>";
21669
+ function sanitiseHtml(s) {
21670
+ // Remove all <br> tags (as some of these can be inside katex tags)
21671
+ s = s.replace(/<br[\s\S]*?>/gm, ""); // console.log("After removing comments:")
21672
+ // console.log(s)
21673
+ // Next, convert all elements to supported elements
21674
+
21675
+ var div = document.createElement('div');
21676
+ div.innerHTML = s;
21677
+ var sanitisedElement = sanitiseHtmlForElement(div);
21678
+ var sanitised = sanitisedElement.innerHTML; // Next, remove all span tags, except those for katex span nodes
21679
+ // NB: A simpler solution may have been to create something other than
21680
+ // span tags in the sanitiseHtmlForElement(div) method and then simply
21681
+ // remove all span tags.
21682
+
21683
+ var i = 0;
21684
+ var j = 0;
21685
+ var its = 0;
21686
+ var output = [];
21687
+
21688
+ do {
21689
+ its++;
21690
+ j = sanitised.indexOf(KATEX_START_HTML, i);
21691
+
21692
+ if (j < 0) {
21693
+ var _part = sanitised.substring(i, sanitised.length);
21694
+
21695
+ _part = _part.replace(SPAN_TAG, "");
21696
+ output.push(_part);
21697
+ break;
21698
+ }
21699
+
21700
+ var part = sanitised.substring(i, j);
21701
+ part = part.replace(SPAN_TAG, "");
21702
+ output.push(part);
21703
+ var k = sanitised.indexOf(KATEX_END_HTML, j) + KATEX_END_HTML.length;
21704
+
21705
+ if (k < 0) {
21706
+ console.warn("Unable to find closing katex tag");
21707
+ k = sanitised.length;
21708
+ }
21709
+
21710
+ output.push(sanitised.substring(j, k));
21711
+ i = k;
21712
+ } while (j > 0 && its < 20);
21713
+
21714
+ sanitised = output.join(""); // Remove new lines
21715
+
21716
+ sanitised = sanitised.replace(/(\r\n|\r|\n)/gm, ""); // new line
21717
+ // Convert any multispaces to a single space
21718
+
21719
+ sanitised = sanitised.replace(/\s{2,}/gm, " "); // 2 or more white spaces
21720
+ // Next, make sure that each line of html is wrapped in paragraph tags
21721
+
21722
+ i = 0;
21723
+ j = 0;
21724
+ its = 0;
21725
+ output = [];
21726
+
21727
+ do {
21728
+ its++;
21729
+ j = sanitised.indexOf("</p>", i);
21730
+
21731
+ if (j < 0) {
21732
+ output.push(sanitised.substring(i, sanitised.length));
21733
+ break;
21734
+ }
21735
+
21736
+ j = j + 4; // Move j four characters to end of </p> tag
21737
+
21738
+ output.push(sanitised.substring(i, j)); // copy as far as </p>
21739
+ // if we have reached the end of the string, finish
21740
+
21741
+ if (j === sanitised.length) break; // if not enough characters for a <p> then can't be a <p>
21742
+
21743
+ if (j + 3 > sanitised.length) {
21744
+ output.push("<p>");
21745
+ output.push(sanitised.substring(j, sanitised.length));
21746
+ output.push("</p>");
21747
+ break;
21748
+ } // If the next characters are the start of a paragraph tag then continue
21749
+
21750
+
21751
+ var nextChars = sanitised.substring(j, j + 3);
21752
+
21753
+ if (nextChars === "<p>") {
21754
+ i = j;
21755
+ continue;
21756
+ } // If the next characters are the start of a katex tag then continue
21757
+
21758
+
21759
+ if (j + KATEX_START_HTML.length < sanitised.length) {
21760
+ nextChars = sanitised.substring(j, j + KATEX_START_HTML.length);
21761
+
21762
+ if (nextChars === KATEX_START_HTML) {
21763
+ i = j;
21764
+ continue;
21765
+ }
21766
+ } // Ok! We have found some html that is not wrapped in a paragraph tag
21767
+ // Lets insert the paragraph tags
21768
+
21769
+
21770
+ output.push("<p>");
21771
+
21772
+ var _k = sanitised.indexOf("<p>", j);
21773
+
21774
+ if (_k < 0) _k = sanitised.length;
21775
+ output.push(sanitised.substring(j, _k));
21776
+ output.push("</p>");
21777
+ i = _k;
21778
+ } while (j > 0 && its < 20);
21779
+
21780
+ sanitised = output.join("");
21781
+ return sanitised;
21782
+ }
21783
+
21403
21784
  var MIME_TYPE_PLAIN_TEXT = "text/plain";
21404
21785
  var MIME_TYPE_HTML = "text/html";
21405
21786
  var MIME_TYPE_TEX = "application/x-tex";
@@ -21408,14 +21789,135 @@ var SMALL_SPACE_CHAR_CODE = 8203;
21408
21789
  var SMALL_SPACE = String.fromCharCode(SMALL_SPACE_CHAR_CODE);
21409
21790
  var SMALL_SPACE_LENGTH = SMALL_SPACE.length; // const SMALL_SPACE_REG_EXP = new RegExp(SMALL_SPACE, "g")
21410
21791
 
21411
- var MARK = "_M_A_R_K_";
21412
- var MARK_REG_EXP = new RegExp(MARK, "g"); // const LATEX_MARKER_START = "<annotation encoding=\"application/x-tex\">"
21792
+ var MARK = getMark();
21413
21793
  // const LATEX_MARKER_END = "</annotation>"
21414
21794
 
21415
21795
  var MAX_HISTORY_LENGTH = 100;
21416
21796
  var DEFAULT_OPTIONS = {
21417
21797
  useExpertMode: false,
21418
21798
  selectedTab: null
21799
+ }; // Consts for creating accented letters in handleKeyDownAccentHelper
21800
+
21801
+ var GRAVE_LETTERS = {
21802
+ a: "à",
21803
+ e: "è",
21804
+ i: "ì",
21805
+ o: "ò",
21806
+ u: "ù",
21807
+ d: "ð",
21808
+ A: "À",
21809
+ E: "È",
21810
+ I: "Ì",
21811
+ O: "Ò",
21812
+ U: "Ù",
21813
+ D: "Ð"
21814
+ };
21815
+ var ACCUTE_LETTERS = {
21816
+ a: "á",
21817
+ e: "é",
21818
+ i: "í",
21819
+ n: "ń",
21820
+ o: "ó",
21821
+ u: "ú",
21822
+ y: "ý",
21823
+ A: "Á",
21824
+ E: "É",
21825
+ I: "Í",
21826
+ N: "Ń",
21827
+ O: "Ó",
21828
+ U: "Ú",
21829
+ Y: "Ý"
21830
+ };
21831
+ var CARET_LETTERS = {
21832
+ a: "â",
21833
+ e: "ê",
21834
+ i: "î",
21835
+ o: "ô",
21836
+ u: "û",
21837
+ A: "Â",
21838
+ E: "Ê",
21839
+ I: "Î",
21840
+ O: "Ô",
21841
+ U: "Û"
21842
+ };
21843
+ var TILDE_LETTERS = {
21844
+ a: "ã",
21845
+ n: "ñ",
21846
+ o: "õ",
21847
+ A: "Ã",
21848
+ N: "Ñ",
21849
+ O: "Õ"
21850
+ };
21851
+ var COLON_LETTERS = {
21852
+ a: "ä",
21853
+ e: "ë",
21854
+ i: "ï",
21855
+ o: "ö",
21856
+ u: "ü",
21857
+ y: "ÿ",
21858
+ A: "Ä",
21859
+ E: "Ë",
21860
+ I: "Ï",
21861
+ O: "Ö",
21862
+ U: "Ü",
21863
+ Y: "Ÿ"
21864
+ };
21865
+ var AT_LETTERS = {
21866
+ a: "å",
21867
+ A: "Å"
21868
+ };
21869
+ var AND_LETTERS = {
21870
+ a: "æ",
21871
+ o: "œ",
21872
+ s: "ß",
21873
+ A: "Æ",
21874
+ O: "Œ",
21875
+ S: "ß"
21876
+ };
21877
+ var COMMA_LETTERS = {
21878
+ c: "ç",
21879
+ C: "Ç"
21880
+ };
21881
+ var SLASH_LETTERS = {
21882
+ o: "ø",
21883
+ O: "Ø"
21884
+ };
21885
+ var MINUS_LETTERS = {
21886
+ a: "ā",
21887
+ e: "ē",
21888
+ i: "ī",
21889
+ o: "ō",
21890
+ u: "ū",
21891
+ A: "Ā",
21892
+ E: "Ē",
21893
+ I: "Ī",
21894
+ O: "Ō",
21895
+ U: "Ū"
21896
+ };
21897
+ var CTRL_ALT_SHIFT_LETTERS = {
21898
+ "?": "¿",
21899
+ "!": "¡",
21900
+ "/": "¿",
21901
+ 1: "¡"
21902
+ }; // Necessary
21903
+
21904
+ var LETTERS = {
21905
+ "`": GRAVE_LETTERS,
21906
+ "'": ACCUTE_LETTERS,
21907
+ '"': ACCUTE_LETTERS,
21908
+ // Necessary
21909
+ "^": CARET_LETTERS,
21910
+ 6: CARET_LETTERS,
21911
+ "~": TILDE_LETTERS,
21912
+ ":": COLON_LETTERS,
21913
+ "@": AT_LETTERS,
21914
+ 2: AT_LETTERS,
21915
+ "&": AND_LETTERS,
21916
+ 7: AND_LETTERS,
21917
+ // Necessary
21918
+ ",": COMMA_LETTERS,
21919
+ "/": SLASH_LETTERS,
21920
+ "-": MINUS_LETTERS
21419
21921
  };
21420
21922
 
21421
21923
  var MathRichInput = /*#__PURE__*/function (_React$Component) {
@@ -21570,10 +22072,12 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
21570
22072
  startNodeIndex: 0,
21571
22073
  startOffset: 0,
21572
22074
  endNodeIndex: 0,
21573
- endOffset: 0
22075
+ endOffset: 0,
22076
+ startGlobalOffset: 0,
22077
+ endGlobalOffset: 0
21574
22078
  };
21575
22079
 
21576
- _this2.applyChangesToComponent("", MIME_TYPE_PLAIN_TEXT, _new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
22080
+ _this2.applyChangesToComponent("", _this2.getMimeType(false, false), _new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
21577
22081
 
21578
22082
  return;
21579
22083
  } // Treat backspace normally in the following situations
@@ -21658,202 +22162,36 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
21658
22162
  _defineProperty(_assertThisInitialized(_this2), "handleKeyDownArrowLeft", function (e) {
21659
22163
  var rangeParams = _this2._getRangeParams();
21660
22164
 
21661
- var index = rangeParams.startNodeIndex;
21662
- var offset = rangeParams.startOffset; // console.log("Old: "+index+"->"+offset)
21663
- // The user shouldn't be in a katex node, but lets deal with it anyway
21664
-
21665
- var node = _this2._findNodeWithIndex(index);
21666
-
21667
- if (isKatexNode(node)) {
21668
- console.warn("Cursor is inside katex node");
21669
-
21670
- var _new_index = index - 1; // Jump out of the latex node
21671
-
21672
-
21673
- var prev_node = _this2._findNodeWithIndex(index - 1);
21674
-
21675
- var _new_offset = getNodeTextLength(prev_node);
21676
-
21677
- var _new_rangeParams2 = {
21678
- startNodeIndex: _new_index,
21679
- startOffset: _new_offset,
21680
- endNodeIndex: _new_index,
21681
- endOffset: _new_offset
21682
- };
21683
-
21684
- _this2._setRangeParams(_new_rangeParams2);
21685
-
21686
- e.preventDefault();
21687
- return;
21688
- }
21689
-
21690
- if (offset > 2) return;
21691
- var new_index = -1;
21692
- var new_offset = -1; // Deal with case of inserted small space at start of <p> element or after katex node
21693
-
21694
- if (offset === 2) {
21695
- new_index = index;
21696
-
21697
- if (_this2.nodeStartsWithSmallSpace(node)) {
21698
- if (index > 0 && isKatexNode(_this2._findNodeWithIndex(index - 1))) new_offset = 1;else new_offset = 0;
21699
- } else new_offset = 1;
21700
- }
21701
-
21702
- if (offset === 1) {
21703
- if (_this2.nodeStartsWithSmallSpace(node)) {
21704
- if (index === 0) {
21705
- e.preventDefault();
21706
- return;
21707
- }
21708
-
21709
- var _prev_node = _this2._findNodeWithIndex(index - 1);
21710
-
21711
- if (index >= 2 && isKatexNode(_prev_node)) new_index = index - 2;else new_index = index - 1;
21712
-
21713
- var new_node = _this2._findNodeWithIndex(new_index);
21714
-
21715
- new_offset = getNodeTextLength(new_node);
21716
- } else {
21717
- new_index = index;
21718
- new_offset = 0;
21719
- }
21720
- }
21721
-
21722
- if (offset === 0) {
21723
- var _prev_node2 = _this2._findNodeWithIndex(index - 1);
21724
-
21725
- if (index >= 2 && isKatexNode(_prev_node2)) new_index = index - 2;else new_index = index - 1;
21726
-
21727
- var _new_node = _this2._findNodeWithIndex(new_index);
21728
-
21729
- new_offset = getNodeTextLength(_new_node);
21730
-
21731
- if (new_offset === 1) {
21732
- if (_this2.nodeStartsWithSmallSpace(_new_node)) {
21733
- if (index > 0 && isKatexNode(_this2._findNodeWithIndex(index - 1))) new_offset = 1;else new_offset = 0;
21734
- }
21735
- }
21736
- } // Move cursor to start of field if in starting small space
21737
-
21738
-
21739
- if (new_index === 0 && new_offset === 1 && _this2.inputStartsWithSmallSpace()) {
21740
- new_offset = 0;
21741
- }
21742
-
21743
- if (new_index === -1 || new_offset === -1) return;
22165
+ rangeParams.startNodeIndex;
22166
+ rangeParams.startOffset;
22167
+ var new_globalOffset = rangeParams.startGlobalOffset - 1;
21744
22168
  var new_rangeParams = {
21745
- startNodeIndex: new_index,
21746
- startOffset: new_offset,
21747
- endNodeIndex: new_index,
21748
- endOffset: new_offset
22169
+ startGlobalOffset: new_globalOffset,
22170
+ endGlobalOffset: new_globalOffset
21749
22171
  };
22172
+ e.preventDefault();
21750
22173
 
21751
22174
  _this2._setRangeParams(new_rangeParams);
21752
22175
 
21753
- e.preventDefault();
22176
+ return; // console.log("Old: "+index+"->"+offset)
21754
22177
  });
21755
22178
 
21756
22179
  _defineProperty(_assertThisInitialized(_this2), "handleKeyDownArrowRight", function (e) {
21757
22180
  // console.log("handleKeyDownArrowRight")
21758
22181
  var rangeParams = _this2._getRangeParams();
21759
22182
 
21760
- var index = rangeParams.startNodeIndex;
21761
- var offset = rangeParams.startOffset;
21762
- if (index < 0) // Empty input field
21763
- return;
21764
-
21765
- var node = _this2._findNodeWithIndex(index);
21766
-
21767
- var length = getNodeTextLength(node); // The user shouldn't be in a katex node, but lets deal with it anyway
21768
-
21769
- if (isKatexNode(node)) {
21770
- console.warn("Cursor is inside katex node");
21771
- var new_index = index + 1; // Jump out of the latex node
21772
-
21773
- var new_offset = SMALL_SPACE_LENGTH; // As there will be a SMALL_SPACE at the start of the text node
21774
-
21775
- var new_rangeParams = {
21776
- startNodeIndex: new_index,
21777
- startOffset: new_offset,
21778
- endNodeIndex: new_index,
21779
- endOffset: new_offset
21780
- };
21781
-
21782
- _this2._setRangeParams(new_rangeParams);
21783
-
21784
- e.preventDefault();
21785
- return;
21786
- } // Deal with case of inserted small space at start of <p> element
21787
-
21788
-
21789
- if (offset === 0) {
21790
- if (_this2.nodeStartsWithSmallSpace(node)) {
21791
- // console.log("Offset = 0 and node starts with small space");
21792
- var _new_index2 = -1;
21793
-
21794
- var _new_offset2 = -1;
21795
-
21796
- if (node.nodeValue.length > 1) {
21797
- _new_index2 = index;
21798
- _new_offset2 = SMALL_SPACE_LENGTH + 1;
21799
- } else {
21800
- _new_index2 = index + 1;
21801
-
21802
- var next_node = _this2._findNodeWithIndex(_new_index2);
21803
-
21804
- if (next_node !== null) {
21805
- if (isKatexNode(next_node)) {
21806
- _new_index2 = index + 2;
21807
- _new_offset2 = SMALL_SPACE_LENGTH;
21808
- } else {
21809
- _new_index2 = index + 1;
21810
- _new_offset2 = 0;
21811
- }
21812
- } else {
21813
- _new_index2 = index;
21814
- _new_offset2 = offset;
21815
- }
21816
- }
21817
-
21818
- var _new_rangeParams3 = {
21819
- startNodeIndex: _new_index2,
21820
- startOffset: _new_offset2,
21821
- endNodeIndex: _new_index2,
21822
- endOffset: _new_offset2
21823
- };
21824
-
21825
- _this2._setRangeParams(_new_rangeParams3);
21826
-
21827
- e.preventDefault();
21828
- return;
21829
- }
21830
- } // If at the end of a text node
21831
-
21832
-
21833
- if (offset === length || index === 0 && _this2.inputStartsWithSmallSpace()) {
21834
- var _next_node = _this2._findNodeWithIndex(index + 1); // If there is no next node, then we can't move, so do the default action
21835
- // If the next node is a normal node, do the default action
21836
-
21837
-
21838
- if (_next_node === null || !isKatexNode(_next_node)) return;
21839
-
21840
- var _new_index3 = index + 2; // Jump over the latex node
21841
-
21842
-
21843
- var _new_offset3 = SMALL_SPACE_LENGTH; // As there will be a SMALL_SPACE at the start of the text node
21844
-
21845
- var _new_rangeParams4 = {
21846
- startNodeIndex: _new_index3,
21847
- startOffset: _new_offset3,
21848
- endNodeIndex: _new_index3,
21849
- endOffset: _new_offset3
21850
- };
22183
+ rangeParams.startNodeIndex;
22184
+ rangeParams.startOffset;
22185
+ var new_globalOffset = rangeParams.startGlobalOffset + 1;
22186
+ var new_rangeParams = {
22187
+ startGlobalOffset: new_globalOffset,
22188
+ endGlobalOffset: new_globalOffset
22189
+ };
22190
+ e.preventDefault();
21851
22191
 
21852
- _this2._setRangeParams(_new_rangeParams4);
22192
+ _this2._setRangeParams(new_rangeParams);
21853
22193
 
21854
- e.preventDefault();
21855
- return;
21856
- }
22194
+ return;
21857
22195
  });
21858
22196
 
21859
22197
  _defineProperty(_assertThisInitialized(_this2), "editableDivIsPlainText", function () {
@@ -21892,10 +22230,18 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
21892
22230
  convert_to_latex = true;
21893
22231
  }
21894
22232
 
21895
- if (!convert_to_latex) return;
21896
- node.nodeValue = node.nodeValue.substring(0, first_dollar_pos) + MARK + node.nodeValue.substring(first_dollar_pos + 1, second_dollar_pos) + MARK + node.nodeValue.substring(second_dollar_pos);
21897
- var raw_text = elementToMarkedRawText(e.target, null, 0, _this2.enableHtml());
21898
- raw_text = raw_text.replace(MARK_REG_EXP, "$"); // We are turning one node into three and want the cursor at the start of the third node
22233
+ if (!convert_to_latex) return; // So we will convert to latex
22234
+ // If we get the raw text without replacing the dollars with marks, the dollars
22235
+ // will be converted to html codes. So we will replace them with marks and then
22236
+ // replace the marks with dollars later
22237
+ // Remove first dollar and insert marks into the node instead of dollars
22238
+
22239
+ var latex = node.nodeValue.substring(first_dollar_pos + 1, second_dollar_pos);
22240
+ node.nodeValue = node.nodeValue.substring(0, first_dollar_pos) + MARK + latex + MARK + node.nodeValue.substring(second_dollar_pos); // Get the raw text and now put the dollars back
22241
+
22242
+ var raw_text = elementToMarkedRawText(e.target, null, 0, _this2.enableHtml()); // now replace the marks with math
22243
+
22244
+ raw_text = replaceMarksWithMath(raw_text, latex, _this2.enableHtml()); // We are turning one node into three and want the cursor at the start of the third node
21899
22245
 
21900
22246
  var new_rangeParams = {
21901
22247
  startNodeIndex: params.startNodeIndex + 2,
@@ -21934,6 +22280,84 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
21934
22280
  e.preventDefault();
21935
22281
  });
21936
22282
 
22283
+ _defineProperty(_assertThisInitialized(_this2), "handleKeyDownAccentHelper", function (e) {
22284
+ // console.log(e.ctrlKey)
22285
+ // console.log(e.altKey)
22286
+ // console.log(e.shiftKey)
22287
+ var new_accent = "";
22288
+ var new_char = ""; // console.log(e.key)
22289
+
22290
+ if (e.ctrlKey) {
22291
+ // First check for CTRL+ALT+SHIFT keys
22292
+ if (e.shiftKey && e.altKey) {
22293
+ console.log(e.key);
22294
+ if (CTRL_ALT_SHIFT_LETTERS.hasOwnProperty(e.key)) new_char = CTRL_ALT_SHIFT_LETTERS[e.key];
22295
+ } // Second check special case of CTRL-tilde
22296
+ else if (e.shiftKey && e.key === "`") new_accent = "~"; // Finally check for normal accent keys
22297
+ else if (LETTERS.hasOwnProperty(e.key)) new_accent = e.key;
22298
+ } else if (_this2.accent !== "") {
22299
+ // Ignore key events for shift and caps lock as that can mean the user
22300
+ // is simply changing to or from capitals and we don't want to reset
22301
+ // this.accent in this case
22302
+ if (e.key === "Shift") return false;
22303
+ if (e.key === "CapsLock") return false; // Get the possible letters that use this accent and test to see if the
22304
+ // current key pressed is one of those letters.
22305
+
22306
+ var letters = LETTERS[_this2.accent];
22307
+ if (letters.hasOwnProperty(e.key)) new_char = letters[e.key];
22308
+ } // If a new accent has been set, store it in this.accent, otherwise clear this.accent
22309
+
22310
+
22311
+ if (new_accent === "") _this2.accent = "";else {
22312
+ e.preventDefault();
22313
+ _this2.accent = new_accent;
22314
+ console.log("Accent set: " + _this2.accent);
22315
+ return true;
22316
+ }
22317
+
22318
+ if (new_char !== "") {
22319
+ // Prevent the original character being insereted
22320
+ e.preventDefault(); // Insert the accented character a the cursor position
22321
+
22322
+ _this2.insertRawText(new_char, false);
22323
+
22324
+ return true;
22325
+ } // Mechanism 2 : Automatically convert a/` into à, for example
22326
+ // if (ACCENT_KEYS.includes(e.key)) {
22327
+ // let pos = e.target.selectionStart
22328
+ // let text = e.target.value
22329
+ // if (pos < 2)
22330
+ // return
22331
+ // if (text.charAt(pos-1) !== '/')
22332
+ // return
22333
+ // let letters = LETTERS[e.key]
22334
+ // let old_letter = text.charAt(pos-2)
22335
+ // if (letters.hasOwnProperty(old_letter)) {
22336
+ // e.preventDefault()
22337
+ // text = text.substring(0,pos-2) + letters[old_letter] + text.substring(pos)
22338
+ // this.setState({value:text},
22339
+ // () => {e.target.selectionStart = e.target.selectionEnd = pos - 1
22340
+ // })
22341
+ // return true
22342
+ // }
22343
+ // }
22344
+ // if (CTRL_ALT_SHIFT_KEYS.includes(e.key)) {
22345
+ // let pos = e.target.selectionStart
22346
+ // let text = e.target.value
22347
+ // if (pos < 1)
22348
+ // return
22349
+ // if (text.charAt(pos-1) !== '/')
22350
+ // return
22351
+ // e.preventDefault()
22352
+ // text = text.substring(0,pos-1) + CTRL_ALT_SHIFT_LETTERS[e.key] + text.substring(pos)
22353
+ // this.setState({value:text},
22354
+ // () => {e.target.selectionStart = e.target.selectionEnd = pos
22355
+ // })
22356
+ // return true
22357
+ // }
22358
+
22359
+ });
22360
+
21937
22361
  _defineProperty(_assertThisInitialized(_this2), "handleKeyDown", function (e) {
21938
22362
  try {
21939
22363
  // Lets set up or update the undo redo history
@@ -21947,23 +22371,41 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
21947
22371
 
21948
22372
  if (!(e.ctrlKey || e.metaKey)) _this2.resetHistoryRedo();
21949
22373
 
21950
- if ((e.metaKey || e.ctrlKey) && (e.key === "b" || e.key === "i" || e.key === "u" || e.key === "6" || e.key === "^" || e.key === "-" || e.key === "_")) {
21951
- if (!_this2.enableHtml()) {
21952
- e.preventDefault();
21953
- return;
21954
- }
21955
-
22374
+ if ((e.metaKey || e.ctrlKey) && (e.key === "b" || e.key === "i" || e.key === "u" || e.key === "6" || e.key === "^" || e.key === "-" || e.key === "_" || e.key === "+" || e.key === "=") && _this2.enableHtml()) {
21956
22375
  if (e.key === "b") _this2.styleText(e, "Bold");
21957
22376
  if (e.key === "i") _this2.styleText(e, "Italic");
21958
- if (e.key === "u") _this2.styleText(e, "Underline");
21959
- if (e.key === "6" || e.key === "^") _this2.styleText(e, "Superscript"); // don't apply subscript if it is the browser command key for "smaller"
22377
+ if (e.key === "u") _this2.styleText(e, "Underline"); // Don't apply superscript is ctrl ^, this is reserved for creating accents
22378
+
22379
+ if (/(Win)/i.test(window.navigator.platform) && e.ctrlKey && (e.key === "6" || e.key === "^")) return; // otherwise
21960
22380
 
21961
- if (/(Win)/i.test(window.navigator.platform) && e.ctrlKey && e.key === "-") return;
21962
- if (/(Mac)/i.test(window.navigator.platform) && e.metaKey && e.key === "-") return; // otherwise
22381
+ if (e.key === "6" || e.key === "^" || e.key === "+" || e.key === "=") _this2.styleText(e, "Superscript"); // Don't apply subscript if it is the browser command key for "smaller"
22382
+ // if (/(Win)/i.test(window.navigator.platform) && e.ctrlKey && e.key === "-")
22383
+ // return
22384
+ // if (/(Mac)/i.test(window.navigator.platform) && e.metaKey && e.key === "-")
22385
+ // return
22386
+ // otherwise
21963
22387
 
21964
22388
  if (e.key === "-" || e.key === "_") _this2.styleText(e, "Subscript");
21965
22389
  e.preventDefault();
21966
22390
  return;
22391
+ }
22392
+
22393
+ if ((e.metaKey || e.ctrlKey) && e.key === "v") {
22394
+ console.log("Executing paste");
22395
+ document.execCommand("paste");
22396
+ return;
22397
+ }
22398
+
22399
+ if ((e.metaKey || e.ctrlKey) && e.key === "c") {
22400
+ console.log("Executing copy");
22401
+ document.execCommand("copy");
22402
+ return;
22403
+ }
22404
+
22405
+ if ((e.metaKey || e.ctrlKey) && e.key === "x") {
22406
+ console.log("Executing cut");
22407
+ document.execCommand("cut");
22408
+ return;
21967
22409
  } // Ignore automatic key repeat presses on Windows so that we can show an accent bar on
21968
22410
  // long key press
21969
22411
 
@@ -22094,8 +22536,9 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22094
22536
  e.preventDefault();
22095
22537
  return;
22096
22538
  }
22097
- } // Check if inserting character in element that starts with small space
22539
+ }
22098
22540
 
22541
+ if (_this2.handleKeyDownAccentHelper(e)) return; // Check if inserting character in element that starts with small space
22099
22542
 
22100
22543
  if (e.key.length === 1 && params.startOffset === 0 && _this2.nodeStartsWithSmallSpace(startNode)) {
22101
22544
  _this2.replaceNextLetter(e.key);
@@ -22176,14 +22619,14 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22176
22619
  _new_offset4 = SMALL_SPACE_LENGTH;
22177
22620
  }
22178
22621
 
22179
- var _new_rangeParams5 = {
22622
+ var _new_rangeParams7 = {
22180
22623
  startNodeIndex: _new_index4,
22181
22624
  startOffset: _new_offset4,
22182
22625
  endNodeIndex: _new_index4,
22183
22626
  endOffset: _new_offset4
22184
22627
  }; // console.log(new_rangeParams)
22185
22628
 
22186
- _this2._setRangeParams(_new_rangeParams5);
22629
+ _this2._setRangeParams(_new_rangeParams7);
22187
22630
  }
22188
22631
  }
22189
22632
  }
@@ -22221,7 +22664,15 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22221
22664
  try {
22222
22665
  var rangeParams = _this2._getRangeParams();
22223
22666
 
22224
- if (rangeParams.startNodeIndex < 0) return;
22667
+ if (rangeParams === null || rangeParams === undefined) {
22668
+ console.warn("Unable to updateActiveButtons. rangeParams: " + rangeParams);
22669
+ return;
22670
+ }
22671
+
22672
+ if (rangeParams.startNodeIndex < 0) {
22673
+ console.warn("Unable to updateActiveButtons. rangeParams.startNodeIndex: " + rangeParams.startNodeIndex);
22674
+ return;
22675
+ }
22225
22676
 
22226
22677
  var node = _this2._findNodeWithIndex(rangeParams.startNodeIndex);
22227
22678
 
@@ -22273,6 +22724,46 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22273
22724
  }
22274
22725
  });
22275
22726
 
22727
+ _defineProperty(_assertThisInitialized(_this2), "handlePaste", function (event) {
22728
+ var clipboardData = event.clipboardData || window.clipboardData;
22729
+
22730
+ if (clipboardData === null || clipboardData === undefined) {
22731
+ console.warn("handlePaste called, but no clipboard data");
22732
+ return;
22733
+ }
22734
+
22735
+ for (var i = 0; i < clipboardData.types.length; i++) {
22736
+ console.log(clipboardData.types[i] + ": " + clipboardData.getData(clipboardData.types[i]));
22737
+ }
22738
+
22739
+ var pasteHtml = clipboardData.getData("text/html");
22740
+
22741
+ if (pasteHtml !== null && pasteHtml.length > 0) {
22742
+ console.log("** Paste html");
22743
+ console.log(pasteHtml);
22744
+ pasteHtml = sanitiseHtml(pasteHtml);
22745
+ console.log("** Santised paste html");
22746
+ console.log(pasteHtml);
22747
+
22748
+ _this2.insertHtml(pasteHtml);
22749
+
22750
+ event.preventDefault();
22751
+ } else {
22752
+ var paste = clipboardData.getData("text");
22753
+ var selection = window.getSelection();
22754
+
22755
+ if (!selection.rangeCount) {
22756
+ console.warn("handlePaste called, but unable to get selection");
22757
+ return false;
22758
+ }
22759
+
22760
+ event.preventDefault();
22761
+ selection.deleteFromDocument();
22762
+
22763
+ _this2.insertRawText(paste);
22764
+ }
22765
+ });
22766
+
22276
22767
  _defineProperty(_assertThisInitialized(_this2), "showEquationEditor", function () {
22277
22768
  var moveCursorOnInsert = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
22278
22769
  var node = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
@@ -22282,8 +22773,6 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22282
22773
 
22283
22774
  if (rangeParams.startNodeIndex < 0) {
22284
22775
  console.error("Could not find position of cursor in node list");
22285
- console.log(rangeParams);
22286
- console.log(_this2.editableDiv.childNodes);
22287
22776
 
22288
22777
  _this2.setOldRangeParams({
22289
22778
  startNodeIndex: 2,
@@ -22359,7 +22848,10 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22359
22848
  node = node.parentNode;
22360
22849
  } while (node !== _this2.editableDiv && node !== null);
22361
22850
 
22362
- if (!isLatex) return;
22851
+ if (!isLatex) {
22852
+ return;
22853
+ }
22854
+
22363
22855
  _this2.showEquationEditorOnMouseUp = true; // Save current range parameters so that we can restore them later if we wish
22364
22856
 
22365
22857
  _this2.setOldRangeParams(_this2._getRangeParams()); // this.editableDiv.focus()
@@ -22478,14 +22970,14 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22478
22970
  }
22479
22971
  }
22480
22972
 
22481
- var _new_rangeParams6 = {
22973
+ var _new_rangeParams8 = {
22482
22974
  startNodeIndex: new_index,
22483
22975
  startOffset: new_offset,
22484
22976
  endNodeIndex: new_index,
22485
22977
  endOffset: new_offset
22486
22978
  };
22487
22979
 
22488
- _this2.setOldRangeParams(_new_rangeParams6);
22980
+ _this2.setOldRangeParams(_new_rangeParams8);
22489
22981
 
22490
22982
  var _nodeCounts = _this2._countNodeTypes();
22491
22983
 
@@ -22493,7 +22985,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22493
22985
  if (_this2.editingExistingEquation) _mimeType = _this2.getMimeType(_nodeCounts.html > 0, _nodeCounts.katex > 1);else _mimeType = _this2.getMimeType(_nodeCounts.html > 0, _nodeCounts.katex > 0);
22494
22986
  _new_raw_text = removeEncodingIfPlainText(_new_raw_text, _mimeType, _this2.enableHtml());
22495
22987
 
22496
- _this2.applyChangesToComponent(_new_raw_text, _mimeType, _new_rangeParams6, _this2.props.useExpertMode, _this2.props.selectedTab);
22988
+ _this2.applyChangesToComponent(_new_raw_text, _mimeType, _new_rangeParams8, _this2.props.useExpertMode, _this2.props.selectedTab);
22497
22989
 
22498
22990
  _this2.setState({
22499
22991
  showEquationEditor: false
@@ -22504,20 +22996,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22504
22996
  // console.log("Latex returned from equation editor: "+latex)
22505
22997
 
22506
22998
 
22507
- var new_raw_text = replaceMarksWithMath(_this2.markedRawText, latex, _this2.enableHtml()); // let new_raw_text =
22508
- // this.markedRawText.substring(0,start_pos) +
22509
- // RAW_TEXT_MATH_START_TAG + latex + RAW_TEXT_MATH_END_TAG +
22510
- // this.markedRawText.substring(end_pos + MARK.length)
22511
- // console.log(
22512
- // "Old cursor pos: " +
22513
- // oldRangeParams.startNodeIndex +
22514
- // "->" +
22515
- // oldRangeParams.startOffset
22516
- // );
22517
- // console.log("Old raw text: " + this.props.value);
22518
- // console.log("Old raw text length: " + this.props.value.length);
22519
- // console.log("Old marked raw text:" + this.markedRawText);
22520
- // console.log("New raw text: " + new_raw_text);
22999
+ var new_raw_text = replaceMarksWithMath(_this2.markedRawText, latex, _this2.enableHtml());
22521
23000
 
22522
23001
  var new_rangeParams = _this2.getOldRangeParams();
22523
23002
 
@@ -22559,7 +23038,30 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22559
23038
  _defineProperty(_assertThisInitialized(_this2), "styleText", function (event, style) {
22560
23039
  try {
22561
23040
  style = style.toLowerCase();
22562
- var success = document.execCommand(style, false, null);
23041
+ var success = false; // This first part is a workaround whereby executing subscript or superscript
23042
+ // within an existing subscript or superscript makes the text even smaller instead
23043
+ // of toggling it off. Thus we manually toggle it off with some jigerry pokery!
23044
+
23045
+ if (style === "subscript" && _this2.state.activeButtons.subscript || style === "superscript" && _this2.state.activeButtons.superscript) {
23046
+ var selection = document.getSelection();
23047
+ var range = selection.getRangeAt(0);
23048
+
23049
+ if (range.endContainer === range.startContainer && range.endOffset === range.startOffset) {
23050
+ success = document.execCommand("insertText", false, " ");
23051
+ range.setEnd(range.endContainer, range.endOffset + 1);
23052
+ selection.removeAllRanges();
23053
+ selection.addRange(range);
23054
+ }
23055
+
23056
+ success = document.execCommand("removeFormat", false, null);
23057
+ if (_this2.state.activeButtons.bold) success = document.execCommand("bold", false, null);
23058
+ if (_this2.state.activeButtons.italic) success = document.execCommand("italic", false, null);
23059
+ if (_this2.state.activeButtons.underline) success = document.execCommand("underline", false, null);
23060
+ } else {
23061
+ // This is the normal code ...
23062
+ success = document.execCommand(style, false, null);
23063
+ }
23064
+
22563
23065
  var buttonState = _this2.state.activeButtons[style];
22564
23066
  if (buttonState === null || buttonState === undefined) return success;
22565
23067
  buttonState = !buttonState;
@@ -22613,7 +23115,9 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22613
23115
  }
22614
23116
  });
22615
23117
 
22616
- _defineProperty(_assertThisInitialized(_this2), "insertRawText", function (event, new_text) {
23118
+ _defineProperty(_assertThisInitialized(_this2), "insertRawText", function (new_text) {
23119
+ var selectInsertedText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
23120
+
22617
23121
  try {
22618
23122
  var rangeParams = _this2._getRangeParams();
22619
23123
 
@@ -22625,12 +23129,166 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22625
23129
 
22626
23130
  var new_rangeParams = _objectSpread2({}, rangeParams);
22627
23131
 
22628
- new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, new_text));
22629
- if (rangeParams.startNodeIndex === rangeParams.endNodeIndex && rangeParams.startOffset === rangeParams.endOffset) new_rangeParams.startOffset = new_rangeParams.startOffset + new_text.length;
23132
+ new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, new_text)); // console.log("New raw text:")
23133
+ // console.log(new_raw_text)
23134
+ // if (rangeParams.startNodeIndex === rangeParams.endNodeIndex &&
23135
+ // rangeParams.startOffset === rangeParams.endOffset)
23136
+ // new_rangeParams.startOffset = new_rangeParams.startOffset + new_text.length
23137
+
22630
23138
  new_rangeParams.endOffset = new_rangeParams.endOffset + new_text.length;
22631
- new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.state.mimeType, _this2.enableHtml());
22632
23139
 
22633
- _this2.applyChangesToComponent(new_raw_text, _this2.state.mimeType, new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
23140
+ if (!selectInsertedText) {
23141
+ new_rangeParams.startNodeIndex = new_rangeParams.endNodeIndex;
23142
+ new_rangeParams.startOffset = new_rangeParams.endOffset;
23143
+ } // console.log("Setting new range params: ")
23144
+ // console.log(new_rangeParams)
23145
+ // console.log("Setting new mime-type: ")
23146
+ // console.log(this.props.mimeType)
23147
+
23148
+
23149
+ new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.props.mimeType, _this2.enableHtml());
23150
+
23151
+ _this2.applyChangesToComponent(new_raw_text, _this2.props.mimeType, new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
23152
+ } catch (error) {
23153
+ console.error(error);
23154
+ }
23155
+ });
23156
+
23157
+ _defineProperty(_assertThisInitialized(_this2), "pasteHtmlAtCaret", function (html, selectPastedContent) {
23158
+ var sel, range;
23159
+
23160
+ if (window.getSelection) {
23161
+ // IE9 and non-IE
23162
+ sel = window.getSelection();
23163
+
23164
+ if (sel.getRangeAt && sel.rangeCount) {
23165
+ range = sel.getRangeAt(0);
23166
+ range.deleteContents(); // Range.createContextualFragment() would be useful here but is
23167
+ // only relatively recently standardized and is not supported in
23168
+ // some browsers (IE9, for one)
23169
+
23170
+ var el = document.createElement("div");
23171
+ el.innerHTML = html;
23172
+ var frag = document.createDocumentFragment(),
23173
+ node,
23174
+ lastNode;
23175
+
23176
+ while (node = el.firstChild) {
23177
+ lastNode = frag.appendChild(node);
23178
+ }
23179
+
23180
+ var firstNode = frag.firstChild;
23181
+ range.insertNode(frag); // Preserve the selection
23182
+
23183
+ if (lastNode) {
23184
+ range = range.cloneRange();
23185
+ range.setStartAfter(lastNode);
23186
+
23187
+ if (selectPastedContent) {
23188
+ range.setStartBefore(firstNode);
23189
+ } else {
23190
+ range.collapse(true);
23191
+ }
23192
+
23193
+ sel.removeAllRanges();
23194
+ sel.addRange(range);
23195
+ }
23196
+ }
23197
+ } else if ((sel = document.selection) && sel.type != "Control") {
23198
+ // IE < 9
23199
+ var originalRange = sel.createRange();
23200
+ originalRange.collapse(true);
23201
+ sel.createRange().pasteHTML(html);
23202
+
23203
+ if (selectPastedContent) {
23204
+ range = sel.createRange();
23205
+ range.setEndPoint("StartToStart", originalRange);
23206
+ range.select();
23207
+ }
23208
+ }
23209
+ });
23210
+
23211
+ _defineProperty(_assertThisInitialized(_this2), "insertHtml", function (new_html) {
23212
+ try {
23213
+ // console.log("New html: "+new_html)
23214
+ // console.log("inserting: "+new_html)
23215
+ _this2.pasteHtmlAtCaret(new_html, true);
23216
+
23217
+ var new_rangeParams = null; // console.log("New range params: ")
23218
+
23219
+ try {
23220
+ new_rangeParams = _this2._getRangeParams(); // console.log("New range params: ")
23221
+ // console.log(new_rangeParams)
23222
+ } catch (error) {
23223
+ console.error(error);
23224
+ } // TODO: Fix the bug that fails to get range params correctly
23225
+
23226
+
23227
+ if (new_rangeParams.startNodeIndex < 0 || new_rangeParams.endNodeIndex < 0) {
23228
+ console.warn("Selection range params were not fetched correctly. Unable to set highlight inserted text.");
23229
+ } // Even if fetches valid range params, they are probably incorrect
23230
+ // So lets clear them for now
23231
+
23232
+
23233
+ new_rangeParams = {
23234
+ startNodeIndex: 0,
23235
+ startOffset: 0,
23236
+ endNodeIndex: 0,
23237
+ endOffset: 0
23238
+ };
23239
+ var new_raw_text = elementToMarkedRawText(_this2.editableDiv, null, -1, _this2.enableHtml()); // console.log("New raw text:"+new_raw_text)
23240
+
23241
+ var nodeCounts = _this2._countNodeTypes();
23242
+
23243
+ var mimeType = _this2.getMimeType(nodeCounts.html > 0, nodeCounts.math > 0);
23244
+
23245
+ new_raw_text = removeEncodingIfPlainText(new_raw_text, mimeType, _this2.enableHtml()); // OK, got to remove the double <p> and double </p> inserted
23246
+ // After inserting <p>a</p><p>b</p> into <p>xy</p> we will have
23247
+ // <P>x<P>a</P><P>b</P>y</P> and we want <P>xa</P><P>by</P>
23248
+
23249
+ try {
23250
+ var i = -1;
23251
+
23252
+ do {
23253
+ i = new_raw_text.indexOf("<P>", i + 1);
23254
+
23255
+ if (i >= 0) {
23256
+ var j = new_raw_text.indexOf("<P>", i + 1);
23257
+ var k = new_raw_text.indexOf("</P>", i + 1);
23258
+
23259
+ if (j >= 0) {
23260
+ if (k < 0 || k > j) {
23261
+ new_raw_text = new_raw_text.substring(0, j) + new_raw_text.substring(j + 3, new_raw_text.length);
23262
+ i = -1;
23263
+ }
23264
+ }
23265
+ }
23266
+ } while (i >= 0 && i < new_raw_text.length - 4);
23267
+
23268
+ i = -1;
23269
+
23270
+ do {
23271
+ i = new_raw_text.indexOf("</P>", i + 1);
23272
+
23273
+ if (i >= 0) {
23274
+ var _j = new_raw_text.indexOf("</P>", i + 1);
23275
+
23276
+ var _k = new_raw_text.indexOf("<P>", i + 1);
23277
+
23278
+ if (_j >= 0) {
23279
+ if (_k < 0 || _k > _j) {
23280
+ new_raw_text = new_raw_text.substring(0, i) + new_raw_text.substring(i + 4, new_raw_text.length);
23281
+ i = -1;
23282
+ }
23283
+ }
23284
+ }
23285
+ } while (i >= 0 && i < new_raw_text.length - 4);
23286
+ } catch (error) {
23287
+ console.error(error);
23288
+ } // console.log("New raw text:"+new_raw_text)
23289
+
23290
+
23291
+ _this2.applyChangesToComponent(new_raw_text, mimeType, new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
22634
23292
  } catch (error) {
22635
23293
  console.error(error);
22636
23294
  }
@@ -22655,14 +23313,12 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22655
23313
  new_rangeParams.startNodeIndex = rangeParams.startNodeIndex - 1;
22656
23314
  new_rangeParams.startOffset = new_offset;
22657
23315
  new_rangeParams.endNodeIndex = rangeParams.endNodeIndex - 1;
22658
- new_rangeParams.endOffset = new_offset; // console.log("About to apply new range params");
22659
- // console.log(new_rangeParams);
22660
- // console.log("Old nodes");
22661
- // console.log(this.editableDiv.childNodes);
22662
-
22663
- new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.state.mimeType, _this2.enableHtml());
23316
+ new_rangeParams.endOffset = new_offset;
23317
+ new_rangeParams.srartGlobalOffset--;
23318
+ new_rangeParams.endGlobalOffset--;
23319
+ new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.props.mimeType, _this2.enableHtml());
22664
23320
 
22665
- _this2.applyChangesToComponent(new_raw_text, _this2.state.mimeType, new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
23321
+ _this2.applyChangesToComponent(new_raw_text, _this2.props.mimeType, new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
22666
23322
  } catch (error) {
22667
23323
  console.error(error);
22668
23324
  }
@@ -22680,6 +23336,11 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22680
23336
 
22681
23337
  var new_rangeParams = _objectSpread2({}, rangeParams);
22682
23338
 
23339
+ if (new_rangeParams.startGlobalOffset) {
23340
+ new_rangeParams.startGlobalOffset++;
23341
+ new_rangeParams.endGlobalOffset++;
23342
+ }
23343
+
22683
23344
  if (_this2.enableHtml()) {
22684
23345
  new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, "</p><p>"));
22685
23346
  if (new_raw_text.substring(0, 3).toLowerCase() !== "<p>") new_raw_text = "<p>" + new_raw_text + "</p>";
@@ -22691,15 +23352,11 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22691
23352
  new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, "\n"));
22692
23353
  new_rangeParams.startOffset++;
22693
23354
  new_rangeParams.endOffset++;
22694
- } // console.log("About to apply new range params");
22695
- // console.log(new_rangeParams);
22696
- // console.log("Old nodes");
22697
- // console.log(this.editableDiv.childNodes);
22698
-
23355
+ }
22699
23356
 
22700
- new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.state.mimeType, _this2.enableHtml());
23357
+ new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.props.mimeType, _this2.enableHtml());
22701
23358
 
22702
- _this2.applyChangesToComponent(new_raw_text, _this2.state.mimeType, new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
23359
+ _this2.applyChangesToComponent(new_raw_text, _this2.props.mimeType, new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
22703
23360
  } catch (error) {
22704
23361
  console.error(error);
22705
23362
  }
@@ -22721,9 +23378,9 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22721
23378
  new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, new_char));
22722
23379
  if (rangeParams.startNodeIndex === rangeParams.endNodeIndex && rangeParams.startOffset === rangeParams.endOffset) new_rangeParams.startOffset = new_rangeParams.startOffset + new_char.length + 1;
22723
23380
  new_rangeParams.endOffset = new_rangeParams.endOffset + new_char.length + 1;
22724
- new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.state.mimeType, _this2.enableHtml());
23381
+ new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.props.mimeType, _this2.enableHtml());
22725
23382
 
22726
- _this2.applyChangesToComponent(new_raw_text, _this2.state.mimeType, new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
23383
+ _this2.applyChangesToComponent(new_raw_text, _this2.props.mimeType, new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
22727
23384
  } catch (error) {
22728
23385
  console.error(error);
22729
23386
  }
@@ -22741,15 +23398,18 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22741
23398
 
22742
23399
  var new_rangeParams = _objectSpread2({}, rangeParams);
22743
23400
 
23401
+ new_rangeParams.startGlobalOffset++;
23402
+ new_rangeParams.endGlobalOffset++;
23403
+
22744
23404
  if (old_char === null) {
22745
23405
  new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, new_char));
22746
23406
  if (rangeParams.startNodeIndex === rangeParams.endNodeIndex && rangeParams.startOffset === rangeParams.endOffset) new_rangeParams.startOffset = new_rangeParams.startOffset + new_char.length;
22747
23407
  new_rangeParams.endOffset = new_rangeParams.endOffset + new_char.length;
22748
23408
  } else new_raw_text = removeMarks(replaceCharacterBeforeMarks(raw_text, new_char));
22749
23409
 
22750
- new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.state.mimeType, _this2.enableHtml());
23410
+ new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.props.mimeType, _this2.enableHtml());
22751
23411
 
22752
- _this2.applyChangesToComponent(new_raw_text, _this2.state.mimeType, new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
23412
+ _this2.applyChangesToComponent(new_raw_text, _this2.props.mimeType, new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
22753
23413
  } catch (error) {
22754
23414
  console.error(error);
22755
23415
  }
@@ -22767,6 +23427,10 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22767
23427
  }
22768
23428
  });
22769
23429
 
23430
+ _defineProperty(_assertThisInitialized(_this2), "focus", function () {
23431
+ _this2.editableDiv.focus();
23432
+ });
23433
+
22770
23434
  _defineProperty(_assertThisInitialized(_this2), "handleFocus", function (event) {
22771
23435
  var onFocus = _this2.props.onFocus;
22772
23436
 
@@ -22848,6 +23512,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22848
23512
  _this2.initialHistoryState = null;
22849
23513
  _this2.undoHistory = [];
22850
23514
  _this2.redoHistory = [];
23515
+ _this2.accent = "";
22851
23516
  return _this2;
22852
23517
  }
22853
23518
 
@@ -22949,6 +23614,8 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22949
23614
  setupKatex();
22950
23615
  this.editableDiv.addEventListener("keydown", this.handleKeyDown);
22951
23616
  this.editableDiv.addEventListener("keyup", this.handleKeyUp);
23617
+ this.editableDiv.addEventListener("paste", this.handlePaste);
23618
+ if (this.props.autofocus === true) this.editableDiv.focus();
22952
23619
  } catch (error) {
22953
23620
  console.error(error);
22954
23621
  }
@@ -22959,6 +23626,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
22959
23626
  try {
22960
23627
  this.editableDiv.removeEventListener("keydown", this.handleKeyDown);
22961
23628
  this.editableDiv.removeEventListener("keyup", this.handleKeyUp);
23629
+ this.editableDiv.removeEventListener("paste", this.handlePaste);
22962
23630
  } catch (error) {
22963
23631
  console.error(error);
22964
23632
  }