@zzish/math-rich-input 0.1.29 → 0.1.31
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 +131 -123
- package/dist/math-rich-input.css +130 -130
- package/package.json +1 -1
- package/src/MathRichInput.jsx +90 -79
- package/src/mathRichInputHelper.js +29 -29
package/dist/index.js
CHANGED
|
@@ -21032,8 +21032,8 @@ function elementToMarkedRawText(element) {
|
|
|
21032
21032
|
var nodeToMark = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
21033
21033
|
var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
21034
21034
|
var useHtmlMath = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
21035
|
-
console.log("elementToMarkedRawText")
|
|
21036
|
-
console.log(element.innerHTML)
|
|
21035
|
+
// console.log("elementToMarkedRawText")
|
|
21036
|
+
// console.log(element.innerHTML)
|
|
21037
21037
|
if (element.innerHTML === "<p><br></p>") throw new Error("We are here"); // console.log("Node to mark:")
|
|
21038
21038
|
// console.log(nodeToMark)
|
|
21039
21039
|
|
|
@@ -21351,17 +21351,17 @@ function findNodeAndOffsetForGlobalOffset(node, globalOffset) {
|
|
|
21351
21351
|
|
|
21352
21352
|
if (isTextNode(node)) {
|
|
21353
21353
|
result.node = node;
|
|
21354
|
-
result.lastTextNode = node;
|
|
21355
|
-
console.log("
|
|
21356
|
-
|
|
21354
|
+
result.lastTextNode = node; // console.log("Found text node \'"+node.nodeValue+"\' of length "+node.nodeValue.length)
|
|
21355
|
+
// console.log("result.offset was: "+result.offset)
|
|
21356
|
+
|
|
21357
21357
|
result.offset += node.nodeValue.length;
|
|
21358
21358
|
|
|
21359
21359
|
if (nodeStartsWithSmallSpace(node)) {
|
|
21360
|
-
console.log("Text node starts with small space")
|
|
21360
|
+
// console.log("Text node starts with small space")
|
|
21361
21361
|
result.offset -= 1;
|
|
21362
|
-
}
|
|
21362
|
+
} // console.log("result.offset now: "+result.offset)
|
|
21363
|
+
|
|
21363
21364
|
|
|
21364
|
-
console.log("result.offset now: " + result.offset);
|
|
21365
21365
|
return false;
|
|
21366
21366
|
}
|
|
21367
21367
|
|
|
@@ -21381,10 +21381,9 @@ function findNodeAndOffsetForGlobalOffset(node, globalOffset) {
|
|
|
21381
21381
|
}
|
|
21382
21382
|
|
|
21383
21383
|
if (node.nodeType === 1 && node.tagName === "P") {
|
|
21384
|
-
console.log("Leaving p node")
|
|
21384
|
+
// console.log("Leaving p node")
|
|
21385
21385
|
result.node = null;
|
|
21386
|
-
result.offset++;
|
|
21387
|
-
console.log("result.offset now: " + result.offset);
|
|
21386
|
+
result.offset++; // console.log("result.offset now: "+result.offset)
|
|
21388
21387
|
}
|
|
21389
21388
|
|
|
21390
21389
|
return false;
|
|
@@ -21405,10 +21404,9 @@ function findFirstTextNode(node) {
|
|
|
21405
21404
|
function findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, globalOffset) {
|
|
21406
21405
|
var result = {
|
|
21407
21406
|
offset: 0
|
|
21408
|
-
};
|
|
21409
|
-
|
|
21410
|
-
findNodeAndOffsetForGlobalOffset(editableDiv, globalOffset, result);
|
|
21411
|
-
console.log(result);
|
|
21407
|
+
}; // console.log("Finding node and offset within: "+editableDiv.outerHTML)
|
|
21408
|
+
|
|
21409
|
+
findNodeAndOffsetForGlobalOffset(editableDiv, globalOffset, result); // console.log(result)
|
|
21412
21410
|
|
|
21413
21411
|
if (result.node === null) {
|
|
21414
21412
|
if (globalOffset > 0 && result.lastTextNode !== null) {
|
|
@@ -21441,8 +21439,8 @@ function findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, globalOffset
|
|
|
21441
21439
|
|
|
21442
21440
|
|
|
21443
21441
|
function getRangeParams(editableDiv) {
|
|
21444
|
-
|
|
21445
|
-
|
|
21442
|
+
// console.log ("getRangeParams")
|
|
21443
|
+
// console.log("Inner html: "+editableDiv.innerHTML)
|
|
21446
21444
|
var isSupported = typeof window.getSelection !== "undefined";
|
|
21447
21445
|
|
|
21448
21446
|
if (!isSupported) {
|
|
@@ -21523,12 +21521,11 @@ function setRangeParamsFromGlobalOffsets(editableDiv, params) {
|
|
|
21523
21521
|
var startResult = findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, params.startGlobalOffset);
|
|
21524
21522
|
var endResult = findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, params.endGlobalOffset);
|
|
21525
21523
|
|
|
21526
|
-
if (startResult.node !== null) {
|
|
21527
|
-
console.log("
|
|
21528
|
-
console.log("
|
|
21529
|
-
console.log("
|
|
21530
|
-
console.log("
|
|
21531
|
-
console.log(" offset:" + startResult.offset);
|
|
21524
|
+
if (startResult.node !== null) {// console.log("Setting range to start in node:")
|
|
21525
|
+
// console.log(" node type: "+startResult.node.nodeType)
|
|
21526
|
+
// console.log(" tag name: "+startResult.node.tagName)
|
|
21527
|
+
// console.log(" node value: "+startResult.node.nodeValue)
|
|
21528
|
+
// console.log(" offset:"+startResult.offset)
|
|
21532
21529
|
} else {
|
|
21533
21530
|
console.warn("Can't set range, null start node returned");
|
|
21534
21531
|
return;
|
|
@@ -21561,14 +21558,13 @@ function setRangeParams(editableDiv, params) {
|
|
|
21561
21558
|
|
|
21562
21559
|
|
|
21563
21560
|
if (params.startGlobalOffset !== null && params.startGlobalOffset !== undefined) {
|
|
21564
|
-
console.log("Setting range from global offsets")
|
|
21561
|
+
// console.log("Setting range from global offsets")
|
|
21565
21562
|
setRangeParamsFromGlobalOffsets(editableDiv, params);
|
|
21566
21563
|
return;
|
|
21567
21564
|
} // Otherwise use the old way of doing things
|
|
21565
|
+
// console.log("Setting range from node index and local offset")
|
|
21568
21566
|
|
|
21569
21567
|
|
|
21570
|
-
console.log("Setting range from node index and local offset");
|
|
21571
|
-
|
|
21572
21568
|
if (params.startNodeIndex === null || params.startNodeIndex === undefined) {
|
|
21573
21569
|
console.error("Can't set range params: params.startNodeIndex === " + params.startNodeIndex);
|
|
21574
21570
|
return;
|
|
@@ -21594,17 +21590,17 @@ function setRangeParams(editableDiv, params) {
|
|
|
21594
21590
|
if (params.endNodeIndex === 0 && params.endOffset === 1 && isSmallSpace(nodes[0])) endOffset = 0; // Find the nodes
|
|
21595
21591
|
|
|
21596
21592
|
var startNode = findNodeWithIndex(editableDiv, params.startNodeIndex);
|
|
21597
|
-
var endNode = findNodeWithIndex(editableDiv, params.endNodeIndex);
|
|
21598
|
-
console.log("
|
|
21599
|
-
console.log("
|
|
21600
|
-
console.log("
|
|
21601
|
-
console.log("
|
|
21602
|
-
console.log("
|
|
21603
|
-
console.log("
|
|
21604
|
-
console.log("
|
|
21605
|
-
console.log("
|
|
21606
|
-
console.log("
|
|
21607
|
-
|
|
21593
|
+
var endNode = findNodeWithIndex(editableDiv, params.endNodeIndex); // console.log("Setting range to start in node:")
|
|
21594
|
+
// console.log(" node type: "+startNode.nodeType)
|
|
21595
|
+
// console.log(" tag name: "+startNode.tagName)
|
|
21596
|
+
// console.log(" node value: "+startNode.nodeValue)
|
|
21597
|
+
// console.log(" offset:"+startOffset)
|
|
21598
|
+
// console.log("Setting range to end in node:")
|
|
21599
|
+
// console.log(" node type: "+endNode.nodeType)
|
|
21600
|
+
// console.log(" tag name: "+endNode.tagName)
|
|
21601
|
+
// console.log(" node value: "+endNode.nodeValue)
|
|
21602
|
+
// console.log(" offset:"+endOffset)
|
|
21603
|
+
// Set range in document
|
|
21608
21604
|
|
|
21609
21605
|
if (startNode === null) {
|
|
21610
21606
|
console.warn("Could not set range to start node with index " + params.startNodeIndex);
|
|
@@ -21979,18 +21975,12 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
21979
21975
|
});
|
|
21980
21976
|
|
|
21981
21977
|
_defineProperty(_assertThisInitialized(_this2), "applyChangesToComponent", function (value, mimeType, rangeParams, isExpertMode, selectedTab) {
|
|
21982
|
-
// if (this.props.outputTex !== null && this.props.outputTex !== undefined && this.props.outputTex) {
|
|
21983
|
-
// if (mimeType === MIME_TYPE_HTML) {
|
|
21984
|
-
// console.warn("Html found when outputTex=true")
|
|
21985
|
-
// value = convertHtmlToPlainText(value)
|
|
21986
|
-
// mimeType = MIME_TYPE_PLAIN_TEXT
|
|
21987
|
-
// } else if (mimeType === MIME_TYPE_ZZISH_HTML_MATH) {
|
|
21988
|
-
// value = convertHtmlMathToTex(value)
|
|
21989
|
-
// mimeType = MIME_TYPE_TEX
|
|
21990
|
-
// }
|
|
21991
|
-
// }
|
|
21992
21978
|
// rangeParams, isExpertMode and selectedTab can be null, in which case we will set them
|
|
21993
|
-
if (rangeParams === null) rangeParams = _this2.lastSetRangeParams;
|
|
21979
|
+
if (rangeParams === null) rangeParams = _this2.lastSetRangeParams;
|
|
21980
|
+
_this2.afterComponentUpdateData = {
|
|
21981
|
+
rangeParams: rangeParams,
|
|
21982
|
+
value: value
|
|
21983
|
+
};
|
|
21994
21984
|
var options = _this2.props.options || DEFAULT_OPTIONS;
|
|
21995
21985
|
if (isExpertMode === null) isExpertMode = options.isExpertMode;
|
|
21996
21986
|
if (selectedTab === null) selectedTab = options.selectedTab; // Add this to the history
|
|
@@ -22110,7 +22100,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22110
22100
|
}
|
|
22111
22101
|
|
|
22112
22102
|
if (deleteToEmpty) {
|
|
22113
|
-
console.log("deleteToEmpty")
|
|
22103
|
+
// console.log("deleteToEmpty")
|
|
22114
22104
|
var _new_rangeParams = {
|
|
22115
22105
|
startNodeIndex: 0,
|
|
22116
22106
|
startOffset: 1,
|
|
@@ -22207,9 +22197,9 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22207
22197
|
var rangeParams = _this2._getRangeParams();
|
|
22208
22198
|
|
|
22209
22199
|
rangeParams.startNodeIndex;
|
|
22210
|
-
rangeParams.startOffset;
|
|
22211
|
-
console.log(
|
|
22212
|
-
|
|
22200
|
+
rangeParams.startOffset; // console.log("handleKeyDownArrowLeft")
|
|
22201
|
+
// console.log(rangeParams)
|
|
22202
|
+
|
|
22213
22203
|
var new_globalOffset = rangeParams.endGlobalOffset - 1;
|
|
22214
22204
|
var new_rangeParams = null;
|
|
22215
22205
|
|
|
@@ -22223,9 +22213,9 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22223
22213
|
startGlobalOffset: new_globalOffset,
|
|
22224
22214
|
endGlobalOffset: new_globalOffset
|
|
22225
22215
|
};
|
|
22226
|
-
}
|
|
22216
|
+
} // console.log(new_rangeParams)
|
|
22217
|
+
|
|
22227
22218
|
|
|
22228
|
-
console.log(new_rangeParams);
|
|
22229
22219
|
e.preventDefault();
|
|
22230
22220
|
|
|
22231
22221
|
_this2._setRangeParams(new_rangeParams);
|
|
@@ -22377,8 +22367,8 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22377
22367
|
|
|
22378
22368
|
if (new_accent === "") _this2.accent = "";else {
|
|
22379
22369
|
e.preventDefault();
|
|
22380
|
-
_this2.accent = new_accent;
|
|
22381
|
-
|
|
22370
|
+
_this2.accent = new_accent; // console.log("Accent set: " + this.accent);
|
|
22371
|
+
|
|
22382
22372
|
return true;
|
|
22383
22373
|
}
|
|
22384
22374
|
|
|
@@ -22443,41 +22433,43 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22443
22433
|
if (e.key === "i") _this2.styleText(e, "Italic");
|
|
22444
22434
|
if (e.key === "u") _this2.styleText(e, "Underline"); // Don't apply superscript is ctrl ^, this is reserved for creating accents
|
|
22445
22435
|
|
|
22446
|
-
if (/(Win)/i.test(window.navigator.platform) && e.ctrlKey && (e.key === "6" || e.key === "^"))
|
|
22447
|
-
|
|
22448
|
-
|
|
22449
|
-
|
|
22450
|
-
|
|
22451
|
-
|
|
22452
|
-
|
|
22453
|
-
|
|
22454
|
-
|
|
22455
|
-
|
|
22456
|
-
|
|
22457
|
-
|
|
22436
|
+
if (/(Win)/i.test(window.navigator.platform) && e.ctrlKey && (e.key === "6" || e.key === "^")) {// do nothing
|
|
22437
|
+
} else {
|
|
22438
|
+
// otherwise
|
|
22439
|
+
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"
|
|
22440
|
+
// if (/(Win)/i.test(window.navigator.platform) && e.ctrlKey && e.key === "-")
|
|
22441
|
+
// return
|
|
22442
|
+
// if (/(Mac)/i.test(window.navigator.platform) && e.metaKey && e.key === "-")
|
|
22443
|
+
// return
|
|
22444
|
+
// otherwise
|
|
22445
|
+
|
|
22446
|
+
if (e.key === "-" || e.key === "_") _this2.styleText(e, "Subscript");
|
|
22447
|
+
e.preventDefault();
|
|
22448
|
+
return;
|
|
22449
|
+
}
|
|
22458
22450
|
}
|
|
22459
22451
|
|
|
22460
22452
|
if ((e.metaKey || e.ctrlKey) && e.key === "v") {
|
|
22461
|
-
console.log("Executing paste");
|
|
22453
|
+
// console.log("Executing paste");
|
|
22462
22454
|
document.execCommand("paste");
|
|
22463
22455
|
return;
|
|
22464
22456
|
}
|
|
22465
22457
|
|
|
22466
22458
|
if ((e.metaKey || e.ctrlKey) && e.key === "c") {
|
|
22467
|
-
console.log("Executing copy");
|
|
22459
|
+
// console.log("Executing copy");
|
|
22468
22460
|
document.execCommand("copy");
|
|
22469
22461
|
return;
|
|
22470
22462
|
}
|
|
22471
22463
|
|
|
22472
22464
|
if ((e.metaKey || e.ctrlKey) && e.key === "x") {
|
|
22473
|
-
console.log("Executing cut");
|
|
22465
|
+
// console.log("Executing cut");
|
|
22474
22466
|
document.execCommand("cut");
|
|
22475
22467
|
return;
|
|
22476
22468
|
} // Ignore automatic key repeat presses on Windows so that we can show an accent bar on
|
|
22477
22469
|
// long key press
|
|
22478
22470
|
|
|
22479
22471
|
|
|
22480
|
-
if (
|
|
22472
|
+
if (/(Win)/i.test(window.navigator.platform)) {
|
|
22481
22473
|
if (e.key === _this2.keyPressed && _this2.keyPressStartTime > 0) {
|
|
22482
22474
|
if (e.key.length === 1 && ("a" <= e.key && e.key <= "z" || "A" <= e.key && e.key <= "Z" || e.key === "!" || e.key === "?")) {
|
|
22483
22475
|
e.preventDefault();
|
|
@@ -22490,15 +22482,20 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22490
22482
|
var key = _this2.fetchAccentLetter();
|
|
22491
22483
|
|
|
22492
22484
|
if (key === "a" || key === "e" || key === "i" || key === "o" || key === "u" || key === "c" || key === "l" || key === "n" || key === "s" || key === "?" || key === "!") {
|
|
22485
|
+
console.log("showing/hiding accent bar");
|
|
22486
|
+
|
|
22493
22487
|
_this2.setState({
|
|
22494
22488
|
showAccentBar: !_this2.state.showAccentBar
|
|
22495
22489
|
});
|
|
22496
22490
|
} else {
|
|
22491
|
+
console.log("hiding accent bar");
|
|
22492
|
+
|
|
22497
22493
|
_this2.setState({
|
|
22498
22494
|
showAccentBar: false
|
|
22499
22495
|
});
|
|
22500
22496
|
}
|
|
22501
22497
|
|
|
22498
|
+
e.preventDefault();
|
|
22502
22499
|
return;
|
|
22503
22500
|
}
|
|
22504
22501
|
|
|
@@ -22513,9 +22510,14 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22513
22510
|
|
|
22514
22511
|
if (_this2.keyPressStartTime < 0) {
|
|
22515
22512
|
_this2.keyPressStartTime = Date.now();
|
|
22516
|
-
|
|
22517
|
-
|
|
22518
|
-
|
|
22513
|
+
|
|
22514
|
+
if (_this2.state.showAccentBar) {
|
|
22515
|
+
console.log("Hiding accent bar 2");
|
|
22516
|
+
|
|
22517
|
+
_this2.setState({
|
|
22518
|
+
showAccentBar: false
|
|
22519
|
+
});
|
|
22520
|
+
}
|
|
22519
22521
|
}
|
|
22520
22522
|
|
|
22521
22523
|
if (e.key === "Backspace") {
|
|
@@ -22609,8 +22611,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22609
22611
|
|
|
22610
22612
|
if (e.key.length === 1 && // ie, it's not something like "arrowLeft"
|
|
22611
22613
|
params.startOffset === 0 && _this2.nodeStartsWithSmallSpace(startNode)) {
|
|
22612
|
-
console.log("Handling character input at start of text node with small space")
|
|
22613
|
-
|
|
22614
|
+
// console.log("Handling character input at start of text node with small space")
|
|
22614
22615
|
_this2.insertAfterSmallSpace(e.key, params);
|
|
22615
22616
|
|
|
22616
22617
|
e.preventDefault();
|
|
@@ -22709,9 +22710,8 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22709
22710
|
|
|
22710
22711
|
_defineProperty(_assertThisInitialized(_this2), "handleInput", function (event) {
|
|
22711
22712
|
try {
|
|
22712
|
-
console.log("handleInput")
|
|
22713
|
+
// console.log("handleInput")
|
|
22713
22714
|
var raw_text = elementToMarkedRawText(_this2.editableDiv, null, 0, _this2.enableHtml());
|
|
22714
|
-
console.log("handleInput 2");
|
|
22715
22715
|
|
|
22716
22716
|
var params = _this2._getRangeParams();
|
|
22717
22717
|
|
|
@@ -22733,8 +22733,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22733
22733
|
|
|
22734
22734
|
_defineProperty(_assertThisInitialized(_this2), "updateActiveButtons", function () {
|
|
22735
22735
|
try {
|
|
22736
|
-
console.log("updateActiveButtons")
|
|
22737
|
-
|
|
22736
|
+
// console.log("updateActiveButtons")
|
|
22738
22737
|
var rangeParams = _this2._getRangeParams();
|
|
22739
22738
|
|
|
22740
22739
|
if (rangeParams === null || rangeParams === undefined) {
|
|
@@ -22803,20 +22802,21 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22803
22802
|
if (clipboardData === null || clipboardData === undefined) {
|
|
22804
22803
|
console.warn("handlePaste called, but no clipboard data");
|
|
22805
22804
|
return;
|
|
22806
|
-
}
|
|
22805
|
+
} // for (let i = 0; i < clipboardData.types.length; i++)
|
|
22806
|
+
// console.log(
|
|
22807
|
+
// clipboardData.types[i] +
|
|
22808
|
+
// ": " +
|
|
22809
|
+
// clipboardData.getData(clipboardData.types[i])
|
|
22810
|
+
// );
|
|
22807
22811
|
|
|
22808
|
-
for (var i = 0; i < clipboardData.types.length; i++) {
|
|
22809
|
-
console.log(clipboardData.types[i] + ": " + clipboardData.getData(clipboardData.types[i]));
|
|
22810
|
-
}
|
|
22811
22812
|
|
|
22812
22813
|
var pasteHtml = clipboardData.getData("text/html");
|
|
22813
22814
|
|
|
22814
22815
|
if (pasteHtml !== null && pasteHtml.length > 0) {
|
|
22815
|
-
console.log("** Paste html");
|
|
22816
|
-
console.log(pasteHtml);
|
|
22817
|
-
pasteHtml = sanitiseHtml(pasteHtml);
|
|
22818
|
-
console.log(
|
|
22819
|
-
console.log(pasteHtml);
|
|
22816
|
+
// console.log("** Paste html");
|
|
22817
|
+
// console.log(pasteHtml);
|
|
22818
|
+
pasteHtml = sanitiseHtml(pasteHtml); // console.log("** Santised paste html");
|
|
22819
|
+
// console.log(pasteHtml);
|
|
22820
22820
|
|
|
22821
22821
|
_this2.insertHtml(pasteHtml);
|
|
22822
22822
|
|
|
@@ -22872,9 +22872,9 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22872
22872
|
// console.log(node)
|
|
22873
22873
|
|
|
22874
22874
|
if (node === null || node === undefined) {
|
|
22875
|
-
console.error("Could not find node with index: " + rangeParams.startNodeIndex);
|
|
22876
|
-
console.log(
|
|
22877
|
-
|
|
22875
|
+
console.error("Could not find node with index: " + rangeParams.startNodeIndex); // console.log("Child nodes:");
|
|
22876
|
+
// console.log(this.editableDiv.childNodes);
|
|
22877
|
+
|
|
22878
22878
|
node = _this2._findFirstTextNode();
|
|
22879
22879
|
offset = 0;
|
|
22880
22880
|
}
|
|
@@ -23017,10 +23017,10 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
23017
23017
|
|
|
23018
23018
|
var end_pos = _this2.markedRawText.indexOf(MARK, start_pos + MARK.length);
|
|
23019
23019
|
|
|
23020
|
-
var oldRangeParams = _this2.getOldRangeParams();
|
|
23020
|
+
var oldRangeParams = _this2.getOldRangeParams(); // console.log("Old range params")
|
|
23021
|
+
// console.log(oldRangeParams)
|
|
23022
|
+
// Handle case of empty string returned
|
|
23021
23023
|
|
|
23022
|
-
console.log("Old range params");
|
|
23023
|
-
console.log(oldRangeParams); // Handle case of empty string returned
|
|
23024
23024
|
|
|
23025
23025
|
if (latex === "") {
|
|
23026
23026
|
// console.log("Empty latex returned from equation editor")
|
|
@@ -23204,21 +23204,25 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
23204
23204
|
|
|
23205
23205
|
var new_rangeParams = _objectSpread2({}, rangeParams);
|
|
23206
23206
|
|
|
23207
|
-
new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, new_text)); // console.log("
|
|
23208
|
-
// console.log(
|
|
23209
|
-
// if (rangeParams.startNodeIndex === rangeParams.endNodeIndex &&
|
|
23210
|
-
// rangeParams.startOffset === rangeParams.endOffset)
|
|
23211
|
-
// new_rangeParams.startOffset = new_rangeParams.startOffset + new_text.length
|
|
23212
|
-
|
|
23213
|
-
new_rangeParams.endOffset = new_rangeParams.endOffset + new_text.length;
|
|
23207
|
+
new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, new_text)); // console.log("Range params before insert")
|
|
23208
|
+
// console.log(rangeParams)
|
|
23214
23209
|
|
|
23215
|
-
if (
|
|
23216
|
-
new_rangeParams.startNodeIndex =
|
|
23217
|
-
new_rangeParams.startOffset =
|
|
23218
|
-
|
|
23210
|
+
if (selectInsertedText) {
|
|
23211
|
+
new_rangeParams.startNodeIndex = rangeParams.endNodeIndex;
|
|
23212
|
+
new_rangeParams.startOffset = rangeParams.endOffset;
|
|
23213
|
+
new_rangeParams.endNodeIndex = rangeParams.endNodeIndex;
|
|
23214
|
+
new_rangeParams.endOffset = rangeParams.endOffset + new_text.length;
|
|
23215
|
+
new_rangeParams.startGlobalOffset = rangeParams.endGlobalOffset;
|
|
23216
|
+
new_rangeParams.endGlobalOffset = rangeParams.endGlobalOffset + new_text.length;
|
|
23217
|
+
} else {
|
|
23218
|
+
new_rangeParams.startNodeIndex = rangeParams.endNodeIndex;
|
|
23219
|
+
new_rangeParams.startOffset = rangeParams.endOffset + new_text.length;
|
|
23220
|
+
new_rangeParams.endNodeIndex = rangeParams.endNodeIndex;
|
|
23221
|
+
new_rangeParams.endOffset = rangeParams.endOffset + new_text.length;
|
|
23222
|
+
new_rangeParams.startGlobalOffset = rangeParams.endGlobalOffset + new_text.length;
|
|
23223
|
+
new_rangeParams.endGlobalOffset = rangeParams.endGlobalOffset + new_text.length;
|
|
23224
|
+
} // console.log("Range params after insert")
|
|
23219
23225
|
// console.log(new_rangeParams)
|
|
23220
|
-
// console.log("Setting new mime-type: ")
|
|
23221
|
-
// console.log(this.props.mimeType)
|
|
23222
23226
|
|
|
23223
23227
|
|
|
23224
23228
|
new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.props.mimeType, _this2.enableHtml());
|
|
@@ -23406,11 +23410,11 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
23406
23410
|
var node = _this2._findNodeWithIndex(rangeParams.endNodeIndex);
|
|
23407
23411
|
|
|
23408
23412
|
var offset = rangeParams.endOffset;
|
|
23409
|
-
var raw_text = elementToMarkedRawText(_this2.editableDiv, node, offset, _this2.enableHtml());
|
|
23410
|
-
console.log(
|
|
23411
|
-
console.log(
|
|
23412
|
-
console.log(
|
|
23413
|
-
|
|
23413
|
+
var raw_text = elementToMarkedRawText(_this2.editableDiv, node, offset, _this2.enableHtml()); // console.log("Raw text before line insert")
|
|
23414
|
+
// console.log(raw_text)
|
|
23415
|
+
// console.log("Range params before line insert")
|
|
23416
|
+
// console.log(rangeParams)
|
|
23417
|
+
|
|
23414
23418
|
var new_raw_text = null;
|
|
23415
23419
|
|
|
23416
23420
|
var new_rangeParams = _objectSpread2({}, rangeParams);
|
|
@@ -23433,11 +23437,10 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
23433
23437
|
new_rangeParams.endOffset++;
|
|
23434
23438
|
}
|
|
23435
23439
|
|
|
23436
|
-
new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.props.mimeType, _this2.enableHtml());
|
|
23437
|
-
console.log(
|
|
23438
|
-
console.log(
|
|
23439
|
-
console.log(
|
|
23440
|
-
console.log(new_rangeParams);
|
|
23440
|
+
new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.props.mimeType, _this2.enableHtml()); // console.log("New raw text after line insert")
|
|
23441
|
+
// console.log(new_raw_text)
|
|
23442
|
+
// console.log("New range params after line insert")
|
|
23443
|
+
// console.log(new_rangeParams)
|
|
23441
23444
|
|
|
23442
23445
|
_this2.applyChangesToComponent(new_raw_text, _this2.props.mimeType, new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
|
|
23443
23446
|
} catch (error) {
|
|
@@ -23485,6 +23488,8 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
23485
23488
|
try {
|
|
23486
23489
|
_this2.insertAccentLetter(event, oldCharacter, newCharacter);
|
|
23487
23490
|
|
|
23491
|
+
console.log("Hiding accent bar 3");
|
|
23492
|
+
|
|
23488
23493
|
_this2.setState({
|
|
23489
23494
|
showAccentBar: false
|
|
23490
23495
|
});
|
|
@@ -23523,6 +23528,8 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
23523
23528
|
}
|
|
23524
23529
|
|
|
23525
23530
|
try {
|
|
23531
|
+
console.log("Hiding accent bar 4");
|
|
23532
|
+
|
|
23526
23533
|
_this2.setState({
|
|
23527
23534
|
hasFocus: false,
|
|
23528
23535
|
showAccentBar: false
|
|
@@ -23566,7 +23573,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
23566
23573
|
};
|
|
23567
23574
|
_this2.moveCursorOnInsert = false; // Elements defining the current state of range
|
|
23568
23575
|
|
|
23569
|
-
_this2.
|
|
23576
|
+
_this2.afterComponentUpdateData = null; // Set this to update the selection after rendering
|
|
23570
23577
|
|
|
23571
23578
|
_this2.lastSetRangeParmas = null; // This is set automatically each time the range params are set with setRangeParams
|
|
23572
23579
|
|
|
@@ -23701,10 +23708,11 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
23701
23708
|
key: "componentDidUpdate",
|
|
23702
23709
|
value: function componentDidUpdate() {
|
|
23703
23710
|
try {
|
|
23704
|
-
|
|
23705
|
-
|
|
23711
|
+
// console.log("componentDidUpdate")
|
|
23712
|
+
if (this.afterComponentUpdateData !== null && this.afterComponentUpdateData !== undefined && this.afterComponentUpdateData.value === this.props.value) {
|
|
23713
|
+
this._setRangeParams(this.afterComponentUpdateData.rangeParams);
|
|
23706
23714
|
|
|
23707
|
-
this.
|
|
23715
|
+
this.afterComponentUpdateData = null;
|
|
23708
23716
|
this.updateActiveButtons();
|
|
23709
23717
|
}
|
|
23710
23718
|
} catch (error) {
|
package/dist/math-rich-input.css
CHANGED
|
@@ -233,136 +233,6 @@
|
|
|
233
233
|
.EquationEditorModal .slider.round:before {
|
|
234
234
|
border-radius: 50%;
|
|
235
235
|
}
|
|
236
|
-
/* Note that the top left position of the toolbar is set programatically in componentDidMount */
|
|
237
|
-
|
|
238
|
-
.Toolbar {
|
|
239
|
-
position: absolute;
|
|
240
|
-
z-index: 1;
|
|
241
|
-
display: flex;
|
|
242
|
-
height: 42px;
|
|
243
|
-
background-color: white;
|
|
244
|
-
border: 1px solid #d0d0d0;
|
|
245
|
-
border-radius: 5px;
|
|
246
|
-
box-shadow: 1px 1px 5px #a0a0a0;
|
|
247
|
-
animation: 0.5s fadeIn1;
|
|
248
|
-
animation-fill-mode: forwards;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
@keyframes fadeIn1 {
|
|
252
|
-
0% {
|
|
253
|
-
opacity: 0;
|
|
254
|
-
}
|
|
255
|
-
100% {
|
|
256
|
-
opacity: 1;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
.Toolbar-button {
|
|
261
|
-
font-family: sans-serif;
|
|
262
|
-
font-size: 16px;
|
|
263
|
-
width: 40px;
|
|
264
|
-
height: 36px;
|
|
265
|
-
background-color: white;
|
|
266
|
-
border-radius: 5px;
|
|
267
|
-
border: 0px;
|
|
268
|
-
padding: 1px;
|
|
269
|
-
margin: 2px;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
.Toolbar-button:hover {
|
|
273
|
-
color: white;
|
|
274
|
-
background: #663676;
|
|
275
|
-
cursor: pointer;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
.Toolbar-button:active {
|
|
279
|
-
background: #808080;
|
|
280
|
-
color: white;
|
|
281
|
-
cursor: pointer;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
.TB-narrow {
|
|
285
|
-
width: 30px;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
.TB-wide {
|
|
289
|
-
width: 46px;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
.TB-selected {
|
|
293
|
-
background: #d0d0d0;
|
|
294
|
-
color: black;
|
|
295
|
-
cursor: pointer;
|
|
296
|
-
animation: 0.2s TB-fadeIn;
|
|
297
|
-
animation-fill-mode: forwards;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
.TB-selected:hover {
|
|
301
|
-
color: white;
|
|
302
|
-
background: #663676;
|
|
303
|
-
cursor: pointer;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
@keyframes TB-fadeIn {
|
|
307
|
-
00% {
|
|
308
|
-
background: white;
|
|
309
|
-
}
|
|
310
|
-
100% {
|
|
311
|
-
background: #d0d0d0;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/* Tooltip text */
|
|
316
|
-
.Toolbar-button .tooltiptext {
|
|
317
|
-
font-weight: normal;
|
|
318
|
-
visibility: hidden;
|
|
319
|
-
width: 100px;
|
|
320
|
-
background-color: #222;
|
|
321
|
-
color: #fff;
|
|
322
|
-
/*font-weight: bold;*/
|
|
323
|
-
font-size: 12px;
|
|
324
|
-
text-align: center;
|
|
325
|
-
padding: 4px 10px;
|
|
326
|
-
border-radius: 6px;
|
|
327
|
-
|
|
328
|
-
/* Position the tooltip text - see examples below! */
|
|
329
|
-
position: absolute;
|
|
330
|
-
z-index: 2;
|
|
331
|
-
top: -90%; /* Must leave a small gap between tooltip and button */
|
|
332
|
-
left: 50px;
|
|
333
|
-
|
|
334
|
-
/* transform: translate (50%,0%); */
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/* Show the tooltip text when you mouse over the tooltip container */
|
|
338
|
-
.Toolbar-button:hover .tooltiptext {
|
|
339
|
-
animation: 0.8s fadeIn2;
|
|
340
|
-
animation-fill-mode: forwards;
|
|
341
|
-
visibility: visible;
|
|
342
|
-
/* width: 100px; */
|
|
343
|
-
/* top: -90%; */ /* Must leave a small gap between tooltip and button */
|
|
344
|
-
/* left: 20%; */
|
|
345
|
-
/* margin-left: -50px; */
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
@keyframes fadeIn2 {
|
|
349
|
-
00% {
|
|
350
|
-
opacity: 0;
|
|
351
|
-
}
|
|
352
|
-
70% {
|
|
353
|
-
opacity: 0;
|
|
354
|
-
}
|
|
355
|
-
100% {
|
|
356
|
-
visibility: visible;
|
|
357
|
-
opacity: 0.9;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/* .tooltip {
|
|
362
|
-
position: relative;
|
|
363
|
-
display: inline-block;
|
|
364
|
-
border-bottom: 1px dotted black; /* If you want dots under the hoverable text
|
|
365
|
-
} */
|
|
366
236
|
/* Note that the top left position of the accent bar is set programatically in componentDidMount */
|
|
367
237
|
|
|
368
238
|
.AccentBar {
|
|
@@ -538,6 +408,136 @@
|
|
|
538
408
|
animation: 0.4s fadeIn1;
|
|
539
409
|
animation-fill-mode: forwards;
|
|
540
410
|
}
|
|
411
|
+
/* Note that the top left position of the toolbar is set programatically in componentDidMount */
|
|
412
|
+
|
|
413
|
+
.Toolbar {
|
|
414
|
+
position: absolute;
|
|
415
|
+
z-index: 1;
|
|
416
|
+
display: flex;
|
|
417
|
+
height: 42px;
|
|
418
|
+
background-color: white;
|
|
419
|
+
border: 1px solid #d0d0d0;
|
|
420
|
+
border-radius: 5px;
|
|
421
|
+
box-shadow: 1px 1px 5px #a0a0a0;
|
|
422
|
+
animation: 0.5s fadeIn1;
|
|
423
|
+
animation-fill-mode: forwards;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
@keyframes fadeIn1 {
|
|
427
|
+
0% {
|
|
428
|
+
opacity: 0;
|
|
429
|
+
}
|
|
430
|
+
100% {
|
|
431
|
+
opacity: 1;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
.Toolbar-button {
|
|
436
|
+
font-family: sans-serif;
|
|
437
|
+
font-size: 16px;
|
|
438
|
+
width: 40px;
|
|
439
|
+
height: 36px;
|
|
440
|
+
background-color: white;
|
|
441
|
+
border-radius: 5px;
|
|
442
|
+
border: 0px;
|
|
443
|
+
padding: 1px;
|
|
444
|
+
margin: 2px;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
.Toolbar-button:hover {
|
|
448
|
+
color: white;
|
|
449
|
+
background: #663676;
|
|
450
|
+
cursor: pointer;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
.Toolbar-button:active {
|
|
454
|
+
background: #808080;
|
|
455
|
+
color: white;
|
|
456
|
+
cursor: pointer;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
.TB-narrow {
|
|
460
|
+
width: 30px;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
.TB-wide {
|
|
464
|
+
width: 46px;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
.TB-selected {
|
|
468
|
+
background: #d0d0d0;
|
|
469
|
+
color: black;
|
|
470
|
+
cursor: pointer;
|
|
471
|
+
animation: 0.2s TB-fadeIn;
|
|
472
|
+
animation-fill-mode: forwards;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
.TB-selected:hover {
|
|
476
|
+
color: white;
|
|
477
|
+
background: #663676;
|
|
478
|
+
cursor: pointer;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
@keyframes TB-fadeIn {
|
|
482
|
+
00% {
|
|
483
|
+
background: white;
|
|
484
|
+
}
|
|
485
|
+
100% {
|
|
486
|
+
background: #d0d0d0;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/* Tooltip text */
|
|
491
|
+
.Toolbar-button .tooltiptext {
|
|
492
|
+
font-weight: normal;
|
|
493
|
+
visibility: hidden;
|
|
494
|
+
width: 100px;
|
|
495
|
+
background-color: #222;
|
|
496
|
+
color: #fff;
|
|
497
|
+
/*font-weight: bold;*/
|
|
498
|
+
font-size: 12px;
|
|
499
|
+
text-align: center;
|
|
500
|
+
padding: 4px 10px;
|
|
501
|
+
border-radius: 6px;
|
|
502
|
+
|
|
503
|
+
/* Position the tooltip text - see examples below! */
|
|
504
|
+
position: absolute;
|
|
505
|
+
z-index: 2;
|
|
506
|
+
top: -90%; /* Must leave a small gap between tooltip and button */
|
|
507
|
+
left: 50px;
|
|
508
|
+
|
|
509
|
+
/* transform: translate (50%,0%); */
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/* Show the tooltip text when you mouse over the tooltip container */
|
|
513
|
+
.Toolbar-button:hover .tooltiptext {
|
|
514
|
+
animation: 0.8s fadeIn2;
|
|
515
|
+
animation-fill-mode: forwards;
|
|
516
|
+
visibility: visible;
|
|
517
|
+
/* width: 100px; */
|
|
518
|
+
/* top: -90%; */ /* Must leave a small gap between tooltip and button */
|
|
519
|
+
/* left: 20%; */
|
|
520
|
+
/* margin-left: -50px; */
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
@keyframes fadeIn2 {
|
|
524
|
+
00% {
|
|
525
|
+
opacity: 0;
|
|
526
|
+
}
|
|
527
|
+
70% {
|
|
528
|
+
opacity: 0;
|
|
529
|
+
}
|
|
530
|
+
100% {
|
|
531
|
+
visibility: visible;
|
|
532
|
+
opacity: 0.9;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/* .tooltip {
|
|
537
|
+
position: relative;
|
|
538
|
+
display: inline-block;
|
|
539
|
+
border-bottom: 1px dotted black; /* If you want dots under the hoverable text
|
|
540
|
+
} */
|
|
541
541
|
.EquationEditor {
|
|
542
542
|
height: auto;
|
|
543
543
|
text-align: center;
|
package/package.json
CHANGED
package/src/MathRichInput.jsx
CHANGED
|
@@ -194,7 +194,7 @@ export default class MathRichInput extends React.Component {
|
|
|
194
194
|
this.moveCursorOnInsert = false;
|
|
195
195
|
|
|
196
196
|
// Elements defining the current state of range
|
|
197
|
-
this.
|
|
197
|
+
this.afterComponentUpdateData = null; // Set this to update the selection after rendering
|
|
198
198
|
this.lastSetRangeParmas = null; // This is set automatically each time the range params are set with setRangeParams
|
|
199
199
|
|
|
200
200
|
this.lastSetActiveButtons = null;
|
|
@@ -286,20 +286,11 @@ export default class MathRichInput extends React.Component {
|
|
|
286
286
|
isExpertMode,
|
|
287
287
|
selectedTab
|
|
288
288
|
) => {
|
|
289
|
-
// if (this.props.outputTex !== null && this.props.outputTex !== undefined && this.props.outputTex) {
|
|
290
|
-
// if (mimeType === MIME_TYPE_HTML) {
|
|
291
|
-
// console.warn("Html found when outputTex=true")
|
|
292
|
-
// value = convertHtmlToPlainText(value)
|
|
293
|
-
// mimeType = MIME_TYPE_PLAIN_TEXT
|
|
294
|
-
// } else if (mimeType === MIME_TYPE_ZZISH_HTML_MATH) {
|
|
295
|
-
// value = convertHtmlMathToTex(value)
|
|
296
|
-
// mimeType = MIME_TYPE_TEX
|
|
297
|
-
// }
|
|
298
|
-
// }
|
|
299
289
|
|
|
300
290
|
// rangeParams, isExpertMode and selectedTab can be null, in which case we will set them
|
|
301
291
|
if (rangeParams === null) rangeParams = this.lastSetRangeParams;
|
|
302
|
-
|
|
292
|
+
|
|
293
|
+
this.afterComponentUpdateData = {rangeParams, value}
|
|
303
294
|
|
|
304
295
|
let options = this.props.options || DEFAULT_OPTIONS;
|
|
305
296
|
if (isExpertMode === null) isExpertMode = options.isExpertMode;
|
|
@@ -461,7 +452,7 @@ export default class MathRichInput extends React.Component {
|
|
|
461
452
|
}
|
|
462
453
|
|
|
463
454
|
if (deleteToEmpty) {
|
|
464
|
-
console.log("deleteToEmpty")
|
|
455
|
+
// console.log("deleteToEmpty")
|
|
465
456
|
let new_rangeParams = {
|
|
466
457
|
startNodeIndex: 0,
|
|
467
458
|
startOffset: 1,
|
|
@@ -590,8 +581,8 @@ export default class MathRichInput extends React.Component {
|
|
|
590
581
|
let index = rangeParams.startNodeIndex;
|
|
591
582
|
let offset = rangeParams.startOffset;
|
|
592
583
|
|
|
593
|
-
console.log("handleKeyDownArrowLeft")
|
|
594
|
-
console.log(rangeParams)
|
|
584
|
+
// console.log("handleKeyDownArrowLeft")
|
|
585
|
+
// console.log(rangeParams)
|
|
595
586
|
let new_globalOffset = rangeParams.endGlobalOffset - 1;
|
|
596
587
|
let new_rangeParams = null
|
|
597
588
|
if (e.shiftKey && new_globalOffset > rangeParams.startGlobalOffset) {
|
|
@@ -605,7 +596,7 @@ export default class MathRichInput extends React.Component {
|
|
|
605
596
|
endGlobalOffset: new_globalOffset,
|
|
606
597
|
};
|
|
607
598
|
}
|
|
608
|
-
console.log(new_rangeParams)
|
|
599
|
+
// console.log(new_rangeParams)
|
|
609
600
|
e.preventDefault();
|
|
610
601
|
this._setRangeParams(new_rangeParams);
|
|
611
602
|
return;
|
|
@@ -785,7 +776,7 @@ export default class MathRichInput extends React.Component {
|
|
|
785
776
|
else {
|
|
786
777
|
e.preventDefault();
|
|
787
778
|
this.accent = new_accent;
|
|
788
|
-
console.log("Accent set: " + this.accent);
|
|
779
|
+
// console.log("Accent set: " + this.accent);
|
|
789
780
|
return true;
|
|
790
781
|
}
|
|
791
782
|
if (new_char !== "") {
|
|
@@ -866,42 +857,44 @@ export default class MathRichInput extends React.Component {
|
|
|
866
857
|
/(Win)/i.test(window.navigator.platform) &&
|
|
867
858
|
e.ctrlKey &&
|
|
868
859
|
(e.key === "6" || e.key === "^")
|
|
869
|
-
)
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
860
|
+
) {
|
|
861
|
+
// do nothing
|
|
862
|
+
} else {
|
|
863
|
+
// otherwise
|
|
864
|
+
if (e.key === "6" || e.key === "^" || e.key === "+" || e.key === "=")
|
|
865
|
+
this.styleText(e, "Superscript");
|
|
866
|
+
// Don't apply subscript if it is the browser command key for "smaller"
|
|
867
|
+
// if (/(Win)/i.test(window.navigator.platform) && e.ctrlKey && e.key === "-")
|
|
868
|
+
// return
|
|
869
|
+
// if (/(Mac)/i.test(window.navigator.platform) && e.metaKey && e.key === "-")
|
|
870
|
+
// return
|
|
871
|
+
// otherwise
|
|
872
|
+
if (e.key === "-" || e.key === "_") this.styleText(e, "Subscript");
|
|
881
873
|
|
|
882
|
-
|
|
883
|
-
|
|
874
|
+
e.preventDefault();
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
884
877
|
}
|
|
885
878
|
|
|
886
879
|
if ((e.metaKey || e.ctrlKey) && e.key === "v") {
|
|
887
|
-
console.log("Executing paste");
|
|
880
|
+
// console.log("Executing paste");
|
|
888
881
|
document.execCommand("paste");
|
|
889
882
|
return;
|
|
890
883
|
}
|
|
891
884
|
if ((e.metaKey || e.ctrlKey) && e.key === "c") {
|
|
892
|
-
console.log("Executing copy");
|
|
885
|
+
// console.log("Executing copy");
|
|
893
886
|
document.execCommand("copy");
|
|
894
887
|
return;
|
|
895
888
|
}
|
|
896
889
|
if ((e.metaKey || e.ctrlKey) && e.key === "x") {
|
|
897
|
-
console.log("Executing cut");
|
|
890
|
+
// console.log("Executing cut");
|
|
898
891
|
document.execCommand("cut");
|
|
899
892
|
return;
|
|
900
893
|
}
|
|
901
894
|
|
|
902
895
|
// Ignore automatic key repeat presses on Windows so that we can show an accent bar on
|
|
903
896
|
// long key press
|
|
904
|
-
if (
|
|
897
|
+
if (/(Win)/i.test(window.navigator.platform)) {
|
|
905
898
|
if (e.key === this.keyPressed && this.keyPressStartTime > 0) {
|
|
906
899
|
if (
|
|
907
900
|
e.key.length === 1 &&
|
|
@@ -931,10 +924,13 @@ export default class MathRichInput extends React.Component {
|
|
|
931
924
|
key === "?" ||
|
|
932
925
|
key === "!"
|
|
933
926
|
) {
|
|
934
|
-
|
|
927
|
+
console.log("showing/hiding accent bar")
|
|
928
|
+
this.setState({ showAccentBar: !this.state.showAccentBar});
|
|
935
929
|
} else {
|
|
930
|
+
console.log("hiding accent bar")
|
|
936
931
|
this.setState({ showAccentBar: false });
|
|
937
932
|
}
|
|
933
|
+
e.preventDefault()
|
|
938
934
|
return;
|
|
939
935
|
}
|
|
940
936
|
|
|
@@ -946,7 +942,10 @@ export default class MathRichInput extends React.Component {
|
|
|
946
942
|
// (keyPressStartTime is reset to -1 on key up)
|
|
947
943
|
if (this.keyPressStartTime < 0) {
|
|
948
944
|
this.keyPressStartTime = Date.now();
|
|
949
|
-
if (this.state.showAccentBar)
|
|
945
|
+
if (this.state.showAccentBar) {
|
|
946
|
+
console.log("Hiding accent bar 2")
|
|
947
|
+
this.setState({ showAccentBar: false });
|
|
948
|
+
}
|
|
950
949
|
}
|
|
951
950
|
|
|
952
951
|
if (e.key === "Backspace") {
|
|
@@ -1038,7 +1037,7 @@ export default class MathRichInput extends React.Component {
|
|
|
1038
1037
|
if (e.key.length === 1 && // ie, it's not something like "arrowLeft"
|
|
1039
1038
|
params.startOffset === 0 &&
|
|
1040
1039
|
this.nodeStartsWithSmallSpace(startNode)) {
|
|
1041
|
-
console.log("Handling character input at start of text node with small space")
|
|
1040
|
+
// console.log("Handling character input at start of text node with small space")
|
|
1042
1041
|
this.insertAfterSmallSpace(e.key, params);
|
|
1043
1042
|
e.preventDefault();
|
|
1044
1043
|
return;
|
|
@@ -1143,14 +1142,13 @@ export default class MathRichInput extends React.Component {
|
|
|
1143
1142
|
|
|
1144
1143
|
handleInput = (event) => {
|
|
1145
1144
|
try {
|
|
1146
|
-
console.log("handleInput")
|
|
1145
|
+
// console.log("handleInput")
|
|
1147
1146
|
let raw_text = elementToMarkedRawText(
|
|
1148
1147
|
this.editableDiv,
|
|
1149
1148
|
null,
|
|
1150
1149
|
0,
|
|
1151
1150
|
this.enableHtml()
|
|
1152
1151
|
);
|
|
1153
|
-
console.log("handleInput 2")
|
|
1154
1152
|
const params = this._getRangeParams();
|
|
1155
1153
|
if (params === null || params === undefined)
|
|
1156
1154
|
console.error("Could not get range params from input field");
|
|
@@ -1189,7 +1187,7 @@ export default class MathRichInput extends React.Component {
|
|
|
1189
1187
|
|
|
1190
1188
|
updateActiveButtons = () => {
|
|
1191
1189
|
try {
|
|
1192
|
-
console.log("updateActiveButtons")
|
|
1190
|
+
// console.log("updateActiveButtons")
|
|
1193
1191
|
let rangeParams = this._getRangeParams();
|
|
1194
1192
|
if (rangeParams === null || rangeParams === undefined) {
|
|
1195
1193
|
console.warn(
|
|
@@ -1255,19 +1253,19 @@ export default class MathRichInput extends React.Component {
|
|
|
1255
1253
|
console.warn("handlePaste called, but no clipboard data");
|
|
1256
1254
|
return;
|
|
1257
1255
|
}
|
|
1258
|
-
for (let i = 0; i < clipboardData.types.length; i++)
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1256
|
+
// for (let i = 0; i < clipboardData.types.length; i++)
|
|
1257
|
+
// console.log(
|
|
1258
|
+
// clipboardData.types[i] +
|
|
1259
|
+
// ": " +
|
|
1260
|
+
// clipboardData.getData(clipboardData.types[i])
|
|
1261
|
+
// );
|
|
1264
1262
|
let pasteHtml = clipboardData.getData("text/html");
|
|
1265
1263
|
if (pasteHtml !== null && pasteHtml.length > 0) {
|
|
1266
|
-
console.log("** Paste html");
|
|
1267
|
-
console.log(pasteHtml);
|
|
1264
|
+
// console.log("** Paste html");
|
|
1265
|
+
// console.log(pasteHtml);
|
|
1268
1266
|
pasteHtml = sanitiseHtml(pasteHtml);
|
|
1269
|
-
console.log("** Santised paste html");
|
|
1270
|
-
console.log(pasteHtml);
|
|
1267
|
+
// console.log("** Santised paste html");
|
|
1268
|
+
// console.log(pasteHtml);
|
|
1271
1269
|
this.insertHtml(pasteHtml);
|
|
1272
1270
|
event.preventDefault();
|
|
1273
1271
|
} else {
|
|
@@ -1308,12 +1306,14 @@ export default class MathRichInput extends React.Component {
|
|
|
1308
1306
|
|
|
1309
1307
|
componentDidUpdate() {
|
|
1310
1308
|
try {
|
|
1309
|
+
// console.log("componentDidUpdate")
|
|
1311
1310
|
if (
|
|
1312
|
-
this.
|
|
1313
|
-
this.
|
|
1311
|
+
this.afterComponentUpdateData !== null &&
|
|
1312
|
+
this.afterComponentUpdateData !== undefined &&
|
|
1313
|
+
this.afterComponentUpdateData.value === this.props.value
|
|
1314
1314
|
) {
|
|
1315
|
-
this._setRangeParams(this.
|
|
1316
|
-
this.
|
|
1315
|
+
this._setRangeParams(this.afterComponentUpdateData.rangeParams);
|
|
1316
|
+
this.afterComponentUpdateData = null;
|
|
1317
1317
|
this.updateActiveButtons();
|
|
1318
1318
|
}
|
|
1319
1319
|
} catch (error) {
|
|
@@ -1356,8 +1356,8 @@ export default class MathRichInput extends React.Component {
|
|
|
1356
1356
|
console.error(
|
|
1357
1357
|
"Could not find node with index: " + rangeParams.startNodeIndex
|
|
1358
1358
|
);
|
|
1359
|
-
console.log("Child nodes:");
|
|
1360
|
-
console.log(this.editableDiv.childNodes);
|
|
1359
|
+
// console.log("Child nodes:");
|
|
1360
|
+
// console.log(this.editableDiv.childNodes);
|
|
1361
1361
|
node = this._findFirstTextNode();
|
|
1362
1362
|
offset = 0;
|
|
1363
1363
|
}
|
|
@@ -1498,8 +1498,8 @@ export default class MathRichInput extends React.Component {
|
|
|
1498
1498
|
let start_pos = this.markedRawText.indexOf(MARK);
|
|
1499
1499
|
let end_pos = this.markedRawText.indexOf(MARK, start_pos + MARK.length);
|
|
1500
1500
|
let oldRangeParams = this.getOldRangeParams();
|
|
1501
|
-
console.log("Old range params")
|
|
1502
|
-
console.log(oldRangeParams)
|
|
1501
|
+
// console.log("Old range params")
|
|
1502
|
+
// console.log(oldRangeParams)
|
|
1503
1503
|
|
|
1504
1504
|
// Handle case of empty string returned
|
|
1505
1505
|
if (latex === "") {
|
|
@@ -1722,20 +1722,29 @@ export default class MathRichInput extends React.Component {
|
|
|
1722
1722
|
new_raw_text = removeMarks(
|
|
1723
1723
|
insertCharacterBeforeMarks(raw_text, new_text)
|
|
1724
1724
|
);
|
|
1725
|
-
|
|
1726
|
-
// console.log(
|
|
1727
|
-
//
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
new_rangeParams.
|
|
1733
|
-
new_rangeParams.
|
|
1725
|
+
|
|
1726
|
+
// console.log("Range params before insert")
|
|
1727
|
+
// console.log(rangeParams)
|
|
1728
|
+
|
|
1729
|
+
if (selectInsertedText) {
|
|
1730
|
+
new_rangeParams.startNodeIndex = rangeParams.endNodeIndex;
|
|
1731
|
+
new_rangeParams.startOffset = rangeParams.endOffset;
|
|
1732
|
+
new_rangeParams.endNodeIndex = rangeParams.endNodeIndex;
|
|
1733
|
+
new_rangeParams.endOffset = rangeParams.endOffset + new_text.length;
|
|
1734
|
+
new_rangeParams.startGlobalOffset = rangeParams.endGlobalOffset;
|
|
1735
|
+
new_rangeParams.endGlobalOffset = rangeParams.endGlobalOffset+ new_text.length;
|
|
1736
|
+
} else {
|
|
1737
|
+
new_rangeParams.startNodeIndex = rangeParams.endNodeIndex;
|
|
1738
|
+
new_rangeParams.startOffset = rangeParams.endOffset + new_text.length;
|
|
1739
|
+
new_rangeParams.endNodeIndex = rangeParams.endNodeIndex;
|
|
1740
|
+
new_rangeParams.endOffset = rangeParams.endOffset + new_text.length;
|
|
1741
|
+
new_rangeParams.startGlobalOffset = rangeParams.endGlobalOffset + new_text.length;
|
|
1742
|
+
new_rangeParams.endGlobalOffset = rangeParams.endGlobalOffset + new_text.length;
|
|
1734
1743
|
}
|
|
1735
|
-
|
|
1744
|
+
|
|
1745
|
+
// console.log("Range params after insert")
|
|
1736
1746
|
// console.log(new_rangeParams)
|
|
1737
|
-
|
|
1738
|
-
// console.log(this.props.mimeType)
|
|
1747
|
+
|
|
1739
1748
|
new_raw_text = removeEncodingIfPlainText(
|
|
1740
1749
|
new_raw_text,
|
|
1741
1750
|
this.props.mimeType,
|
|
@@ -1956,10 +1965,10 @@ export default class MathRichInput extends React.Component {
|
|
|
1956
1965
|
this.enableHtml()
|
|
1957
1966
|
);
|
|
1958
1967
|
|
|
1959
|
-
console.log("Raw text before line insert")
|
|
1960
|
-
console.log(raw_text)
|
|
1961
|
-
console.log("Range params before line insert")
|
|
1962
|
-
console.log(rangeParams)
|
|
1968
|
+
// console.log("Raw text before line insert")
|
|
1969
|
+
// console.log(raw_text)
|
|
1970
|
+
// console.log("Range params before line insert")
|
|
1971
|
+
// console.log(rangeParams)
|
|
1963
1972
|
|
|
1964
1973
|
let new_raw_text = null;
|
|
1965
1974
|
let new_rangeParams = { ...rangeParams };
|
|
@@ -1992,10 +2001,10 @@ export default class MathRichInput extends React.Component {
|
|
|
1992
2001
|
this.enableHtml()
|
|
1993
2002
|
);
|
|
1994
2003
|
|
|
1995
|
-
console.log("New raw text after line insert")
|
|
1996
|
-
console.log(new_raw_text)
|
|
1997
|
-
console.log("New range params after line insert")
|
|
1998
|
-
console.log(new_rangeParams)
|
|
2004
|
+
// console.log("New raw text after line insert")
|
|
2005
|
+
// console.log(new_raw_text)
|
|
2006
|
+
// console.log("New range params after line insert")
|
|
2007
|
+
// console.log(new_rangeParams)
|
|
1999
2008
|
|
|
2000
2009
|
|
|
2001
2010
|
this.applyChangesToComponent(
|
|
@@ -2108,6 +2117,7 @@ export default class MathRichInput extends React.Component {
|
|
|
2108
2117
|
handleAccentButtonClick = (event, oldCharacter, newCharacter) => {
|
|
2109
2118
|
try {
|
|
2110
2119
|
this.insertAccentLetter(event, oldCharacter, newCharacter);
|
|
2120
|
+
console.log("Hiding accent bar 3")
|
|
2111
2121
|
this.setState({ showAccentBar: false });
|
|
2112
2122
|
} catch (error) {
|
|
2113
2123
|
console.error(error);
|
|
@@ -2137,6 +2147,7 @@ export default class MathRichInput extends React.Component {
|
|
|
2137
2147
|
onBlur();
|
|
2138
2148
|
}
|
|
2139
2149
|
try {
|
|
2150
|
+
console.log("Hiding accent bar 4")
|
|
2140
2151
|
this.setState({ hasFocus: false, showAccentBar: false });
|
|
2141
2152
|
} catch (error) {
|
|
2142
2153
|
console.error(error);
|
|
@@ -382,8 +382,8 @@ function addTextForNode(node, arrayOfText, nodeToMark=null, offset=0, useHtmlMat
|
|
|
382
382
|
// Marked nodes are useful if a node may need to be deleted and allows the node to be
|
|
383
383
|
// deleted by stripping it out of the raw text.
|
|
384
384
|
export function elementToMarkedRawText(element, nodeToMark=null, offset=0, useHtmlMath=true) {
|
|
385
|
-
console.log("elementToMarkedRawText")
|
|
386
|
-
console.log(element.innerHTML)
|
|
385
|
+
// console.log("elementToMarkedRawText")
|
|
386
|
+
// console.log(element.innerHTML)
|
|
387
387
|
if (element.innerHTML === "<p><br></p>")
|
|
388
388
|
throw new Error ("We are here")
|
|
389
389
|
// console.log("Node to mark:")
|
|
@@ -734,14 +734,14 @@ function findNodeAndOffsetForGlobalOffset(node, globalOffset, result=null) {
|
|
|
734
734
|
if (isTextNode(node)) {
|
|
735
735
|
result.node = node
|
|
736
736
|
result.lastTextNode = node
|
|
737
|
-
console.log("Found text node \'"+node.nodeValue+"\' of length "+node.nodeValue.length)
|
|
738
|
-
console.log("result.offset was: "+result.offset)
|
|
737
|
+
// console.log("Found text node \'"+node.nodeValue+"\' of length "+node.nodeValue.length)
|
|
738
|
+
// console.log("result.offset was: "+result.offset)
|
|
739
739
|
result.offset += node.nodeValue.length
|
|
740
740
|
if (nodeStartsWithSmallSpace(node)) {
|
|
741
|
-
console.log("Text node starts with small space")
|
|
741
|
+
// console.log("Text node starts with small space")
|
|
742
742
|
result.offset -= 1
|
|
743
743
|
}
|
|
744
|
-
console.log("result.offset now: "+result.offset)
|
|
744
|
+
// console.log("result.offset now: "+result.offset)
|
|
745
745
|
return false
|
|
746
746
|
}
|
|
747
747
|
const childNodes = node.childNodes
|
|
@@ -762,10 +762,10 @@ function findNodeAndOffsetForGlobalOffset(node, globalOffset, result=null) {
|
|
|
762
762
|
}
|
|
763
763
|
|
|
764
764
|
if (node.nodeType === 1 && node.tagName === "P") {
|
|
765
|
-
console.log("Leaving p node")
|
|
765
|
+
// console.log("Leaving p node")
|
|
766
766
|
result.node = null
|
|
767
767
|
result.offset ++
|
|
768
|
-
console.log("result.offset now: "+result.offset)
|
|
768
|
+
// console.log("result.offset now: "+result.offset)
|
|
769
769
|
}
|
|
770
770
|
return false;
|
|
771
771
|
}
|
|
@@ -786,9 +786,9 @@ export function findFirstTextNode(node) {
|
|
|
786
786
|
|
|
787
787
|
function findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, globalOffset) {
|
|
788
788
|
let result = {offset:0}
|
|
789
|
-
console.log("Finding node and offset within: "+editableDiv.outerHTML)
|
|
789
|
+
// console.log("Finding node and offset within: "+editableDiv.outerHTML)
|
|
790
790
|
findNodeAndOffsetForGlobalOffset(editableDiv, globalOffset, result)
|
|
791
|
-
console.log(result)
|
|
791
|
+
// console.log(result)
|
|
792
792
|
|
|
793
793
|
if (result.node === null) {
|
|
794
794
|
if (globalOffset > 0 && result.lastTextNode !== null) {
|
|
@@ -823,7 +823,7 @@ function findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, globalOffset
|
|
|
823
823
|
|
|
824
824
|
// https://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html
|
|
825
825
|
export function getRangeParams(editableDiv) {
|
|
826
|
-
console.log ("getRangeParams")
|
|
826
|
+
// console.log ("getRangeParams")
|
|
827
827
|
// console.log("Inner html: "+editableDiv.innerHTML)
|
|
828
828
|
const isSupported = typeof window.getSelection !== "undefined";
|
|
829
829
|
if (!isSupported) {
|
|
@@ -907,11 +907,11 @@ function setRangeParamsFromGlobalOffsets(editableDiv, params) {
|
|
|
907
907
|
findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, params.endGlobalOffset)
|
|
908
908
|
|
|
909
909
|
if (startResult.node !== null) {
|
|
910
|
-
console.log("Setting range to start in node:")
|
|
911
|
-
console.log(" node type: "+startResult.node.nodeType)
|
|
912
|
-
console.log(" tag name: "+startResult.node.tagName)
|
|
913
|
-
console.log(" node value: "+startResult.node.nodeValue)
|
|
914
|
-
console.log(" offset:"+startResult.offset)
|
|
910
|
+
// console.log("Setting range to start in node:")
|
|
911
|
+
// console.log(" node type: "+startResult.node.nodeType)
|
|
912
|
+
// console.log(" tag name: "+startResult.node.tagName)
|
|
913
|
+
// console.log(" node value: "+startResult.node.nodeValue)
|
|
914
|
+
// console.log(" offset:"+startResult.offset)
|
|
915
915
|
} else {
|
|
916
916
|
console.warn("Can't set range, null start node returned")
|
|
917
917
|
return
|
|
@@ -944,13 +944,13 @@ export function setRangeParams(editableDiv, params) {
|
|
|
944
944
|
|
|
945
945
|
// New way of doing things
|
|
946
946
|
if (params.startGlobalOffset !== null && params.startGlobalOffset !== undefined) {
|
|
947
|
-
console.log("Setting range from global offsets")
|
|
947
|
+
// console.log("Setting range from global offsets")
|
|
948
948
|
setRangeParamsFromGlobalOffsets(editableDiv, params)
|
|
949
949
|
return
|
|
950
950
|
}
|
|
951
951
|
|
|
952
952
|
// Otherwise use the old way of doing things
|
|
953
|
-
console.log("Setting range from node index and local offset")
|
|
953
|
+
// console.log("Setting range from node index and local offset")
|
|
954
954
|
|
|
955
955
|
if (params.startNodeIndex === null || params.startNodeIndex === undefined) {
|
|
956
956
|
console.error("Can't set range params: params.startNodeIndex === "+params.startNodeIndex)
|
|
@@ -987,17 +987,17 @@ export function setRangeParams(editableDiv, params) {
|
|
|
987
987
|
let startNode = findNodeWithIndex(editableDiv, params.startNodeIndex)
|
|
988
988
|
let endNode = findNodeWithIndex(editableDiv, params.endNodeIndex)
|
|
989
989
|
|
|
990
|
-
console.log("Setting range to start in node:")
|
|
991
|
-
console.log(" node type: "+startNode.nodeType)
|
|
992
|
-
console.log(" tag name: "+startNode.tagName)
|
|
993
|
-
console.log(" node value: "+startNode.nodeValue)
|
|
994
|
-
console.log(" offset:"+startOffset)
|
|
995
|
-
|
|
996
|
-
console.log("Setting range to end in node:")
|
|
997
|
-
console.log(" node type: "+endNode.nodeType)
|
|
998
|
-
console.log(" tag name: "+endNode.tagName)
|
|
999
|
-
console.log(" node value: "+endNode.nodeValue)
|
|
1000
|
-
console.log(" offset:"+endOffset)
|
|
990
|
+
// console.log("Setting range to start in node:")
|
|
991
|
+
// console.log(" node type: "+startNode.nodeType)
|
|
992
|
+
// console.log(" tag name: "+startNode.tagName)
|
|
993
|
+
// console.log(" node value: "+startNode.nodeValue)
|
|
994
|
+
// console.log(" offset:"+startOffset)
|
|
995
|
+
|
|
996
|
+
// console.log("Setting range to end in node:")
|
|
997
|
+
// console.log(" node type: "+endNode.nodeType)
|
|
998
|
+
// console.log(" tag name: "+endNode.tagName)
|
|
999
|
+
// console.log(" node value: "+endNode.nodeValue)
|
|
1000
|
+
// console.log(" offset:"+endOffset)
|
|
1001
1001
|
|
|
1002
1002
|
// Set range in document
|
|
1003
1003
|
if (startNode === null) {
|