@zzish/math-rich-input 0.1.27 → 0.1.28
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 +73 -62
- package/dist/math-rich-input.css +130 -130
- package/package.json +1 -1
- package/src/MathRichInput.jsx +26 -6
- package/src/mathRichInputHelper.js +54 -53
package/dist/index.js
CHANGED
|
@@ -21007,7 +21007,7 @@ function addTextForNode(node, arrayOfText) {
|
|
|
21007
21007
|
arrayOfText.push(useHtmlMath ? RAW_TEXT_MATH_END_TAG_HTML_MATH : RAW_TEXT_MATH_END_TAG_TEX);
|
|
21008
21008
|
if (mark) arrayOfText.push(MARK$1);
|
|
21009
21009
|
} else {
|
|
21010
|
-
console.error("
|
|
21010
|
+
console.error("Can't render node in editable div: Unknown node type");
|
|
21011
21011
|
console.log(node);
|
|
21012
21012
|
console.log("Node.type:" + node.type);
|
|
21013
21013
|
console.log("Node.tagName:" + node.tagName);
|
|
@@ -21032,8 +21032,11 @@ 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
|
-
|
|
21035
|
+
console.log("elementToMarkedRawText");
|
|
21036
|
+
console.log(element.innerHTML);
|
|
21037
|
+
if (element.innerHTML === "<p><br></p>") throw new Error("We are here"); // console.log("Node to mark:")
|
|
21036
21038
|
// console.log(nodeToMark)
|
|
21039
|
+
|
|
21037
21040
|
var nodes = element.childNodes; // console.log(nodes)
|
|
21038
21041
|
|
|
21039
21042
|
var result = [];
|
|
@@ -21388,8 +21391,37 @@ function findFirstTextNode(node) {
|
|
|
21388
21391
|
}
|
|
21389
21392
|
|
|
21390
21393
|
return null;
|
|
21394
|
+
}
|
|
21395
|
+
|
|
21396
|
+
function findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, globalOffset) {
|
|
21397
|
+
var result = {
|
|
21398
|
+
offset: 0
|
|
21399
|
+
};
|
|
21400
|
+
findNodeAndOffsetForGlobalOffset(editableDiv, globalOffset, result);
|
|
21401
|
+
console.log(result);
|
|
21402
|
+
|
|
21403
|
+
if (result.node === null) {
|
|
21404
|
+
if (globalOffset > 0 && result.lastTextNode !== null) {
|
|
21405
|
+
result.node = result.lastTextNode;
|
|
21406
|
+
result.offset = result.lastTextNode.nodeValue.length;
|
|
21407
|
+
} else {
|
|
21408
|
+
console.warn("Unable to find node and offset for global offset: " + globalOffset);
|
|
21409
|
+
console.log(editableDiv.innerHTML);
|
|
21410
|
+
console.log(result);
|
|
21411
|
+
result.node = findFirstTextNode(editableDiv);
|
|
21412
|
+
result.offset = 0;
|
|
21413
|
+
}
|
|
21414
|
+
} // if (result.offset === 0 &&
|
|
21415
|
+
// result.node.nodeValue.length > 0 &&
|
|
21416
|
+
// nodeStartsWithSmallSpace(result.node)) {
|
|
21417
|
+
// result.offset = 1
|
|
21418
|
+
// }
|
|
21419
|
+
|
|
21420
|
+
|
|
21421
|
+
return result;
|
|
21391
21422
|
} // https://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html
|
|
21392
21423
|
|
|
21424
|
+
|
|
21393
21425
|
function getRangeParams(editableDiv) {
|
|
21394
21426
|
// console.log ("getRangeParams")
|
|
21395
21427
|
// console.log("Inner html: "+editableDiv.innerHTML)
|
|
@@ -21470,58 +21502,20 @@ function setRangeParamsFromGlobalOffsets(editableDiv, params) {
|
|
|
21470
21502
|
|
|
21471
21503
|
try {
|
|
21472
21504
|
if (params === null || params === undefined) throw new Error("Can't set range params: params === " + params);
|
|
21473
|
-
var startResult =
|
|
21474
|
-
|
|
21475
|
-
|
|
21476
|
-
|
|
21477
|
-
|
|
21478
|
-
|
|
21479
|
-
|
|
21480
|
-
|
|
21481
|
-
|
|
21482
|
-
|
|
21483
|
-
|
|
21484
|
-
|
|
21485
|
-
// failed to find an appropriate node (this could happen if the global offset is bigger
|
|
21486
|
-
// than the length of the text in the node), then lets try and fix it
|
|
21487
|
-
|
|
21488
|
-
if (startResult.node === null || endResult.node === null) {
|
|
21489
|
-
console.warn("Can't set range from global offsets, as could not find text nodes");
|
|
21490
|
-
console.log(startResult);
|
|
21491
|
-
console.log(endResult);
|
|
21492
|
-
|
|
21493
|
-
if (startResult.node === null) {
|
|
21494
|
-
if (params.startGlobalOffset > 0 && startResult.lastTextNode !== null) {
|
|
21495
|
-
startResult.node = startResult.lastTextNode;
|
|
21496
|
-
startResult.offset = startResult.lastTextNode.nodeValue.length;
|
|
21497
|
-
} else {
|
|
21498
|
-
startResult.node = findFirstTextNode(editableDiv);
|
|
21499
|
-
startResult.offset = 0;
|
|
21500
|
-
}
|
|
21501
|
-
}
|
|
21502
|
-
|
|
21503
|
-
if (endResult.node === null) {
|
|
21504
|
-
if (params.endGlobalOffset > 0 && endResult.lastTextNode !== null) {
|
|
21505
|
-
endResult.node = endResult.lastTextNode;
|
|
21506
|
-
endResult.offset = endResult.lastTextNode.nodeValue.length;
|
|
21507
|
-
} else {
|
|
21508
|
-
endResult.node = findFirstTextNode(editableDiv);
|
|
21509
|
-
endResult.offset = 0;
|
|
21510
|
-
}
|
|
21511
|
-
}
|
|
21512
|
-
}
|
|
21513
|
-
|
|
21514
|
-
if (startResult.offset === 0 && startResult.node.nodeValue.length > 0 && nodeStartsWithSmallSpace(startResult.node)) {
|
|
21515
|
-
startResult.offset = 1;
|
|
21505
|
+
var startResult = findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, params.startGlobalOffset);
|
|
21506
|
+
var endResult = findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, params.endGlobalOffset);
|
|
21507
|
+
|
|
21508
|
+
if (startResult.node !== null) {
|
|
21509
|
+
console.log("Setting range to start in node:");
|
|
21510
|
+
console.log(" node type: " + startResult.node.nodeType);
|
|
21511
|
+
console.log(" tag name: " + startResult.node.tagName);
|
|
21512
|
+
console.log(" node value: " + startResult.node.nodeValue);
|
|
21513
|
+
console.log(" offset:" + startResult.offset);
|
|
21514
|
+
} else {
|
|
21515
|
+
console.warn("Can't set range, null start node returned");
|
|
21516
|
+
return;
|
|
21516
21517
|
}
|
|
21517
21518
|
|
|
21518
|
-
if (endResult.offset === 0 && endResult.node.nodeValue.length > 0 && nodeStartsWithSmallSpace(endResult.node)) {
|
|
21519
|
-
endResult.offset = 1;
|
|
21520
|
-
} // console.log("Setting range to:")
|
|
21521
|
-
// console.log(startResult.node.nodeType+":"+startResult.node.tagName+":"+
|
|
21522
|
-
// startResult.node.nodeValue+":"+startResult.offset)
|
|
21523
|
-
|
|
21524
|
-
|
|
21525
21519
|
new_range = document.createRange();
|
|
21526
21520
|
new_range.setStart(startResult.node, startResult.offset);
|
|
21527
21521
|
new_range.setEnd(endResult.node, endResult.offset);
|
|
@@ -21545,12 +21539,14 @@ function setRangeParams(editableDiv, params) {
|
|
|
21545
21539
|
if (params === null || params === undefined) {
|
|
21546
21540
|
console.error("Can't set range params: params === " + params);
|
|
21547
21541
|
return;
|
|
21548
|
-
}
|
|
21542
|
+
} // New way of doing things
|
|
21543
|
+
|
|
21549
21544
|
|
|
21550
|
-
if (params.startGlobalOffset) {
|
|
21545
|
+
if (params.startGlobalOffset !== null && params.startGlobalOffset !== undefined) {
|
|
21551
21546
|
setRangeParamsFromGlobalOffsets(editableDiv, params);
|
|
21552
21547
|
return;
|
|
21553
|
-
}
|
|
21548
|
+
} // Otherwise use the old way of doing things
|
|
21549
|
+
|
|
21554
21550
|
|
|
21555
21551
|
if (params.startNodeIndex === null || params.startNodeIndex === undefined) {
|
|
21556
21552
|
console.error("Can't set range params: params.startNodeIndex === " + params.startNodeIndex);
|
|
@@ -22103,6 +22099,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22103
22099
|
|
|
22104
22100
|
_this2.applyChangesToComponent("", _this2.getMimeType(false, false), _new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
|
|
22105
22101
|
|
|
22102
|
+
e.preventDefault();
|
|
22106
22103
|
return;
|
|
22107
22104
|
} // Treat backspace normally in the following situations
|
|
22108
22105
|
|
|
@@ -22188,11 +22185,14 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22188
22185
|
|
|
22189
22186
|
rangeParams.startNodeIndex;
|
|
22190
22187
|
rangeParams.startOffset;
|
|
22188
|
+
console.log("handleKeyDownArrowLeft");
|
|
22189
|
+
console.log(rangeParams);
|
|
22191
22190
|
var new_globalOffset = rangeParams.startGlobalOffset - 1;
|
|
22192
22191
|
var new_rangeParams = {
|
|
22193
22192
|
startGlobalOffset: new_globalOffset,
|
|
22194
22193
|
endGlobalOffset: new_globalOffset
|
|
22195
22194
|
};
|
|
22195
|
+
console.log(new_rangeParams);
|
|
22196
22196
|
e.preventDefault();
|
|
22197
22197
|
|
|
22198
22198
|
_this2._setRangeParams(new_rangeParams);
|
|
@@ -22666,8 +22666,9 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22666
22666
|
|
|
22667
22667
|
_defineProperty(_assertThisInitialized(_this2), "handleInput", function (event) {
|
|
22668
22668
|
try {
|
|
22669
|
-
|
|
22669
|
+
console.log("handleInput");
|
|
22670
22670
|
var raw_text = elementToMarkedRawText(_this2.editableDiv, null, 0, _this2.enableHtml());
|
|
22671
|
+
console.log("handleInput 2");
|
|
22671
22672
|
|
|
22672
22673
|
var params = _this2._getRangeParams();
|
|
22673
22674
|
|
|
@@ -22971,8 +22972,10 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22971
22972
|
|
|
22972
22973
|
var end_pos = _this2.markedRawText.indexOf(MARK, start_pos + MARK.length);
|
|
22973
22974
|
|
|
22974
|
-
var oldRangeParams = _this2.getOldRangeParams();
|
|
22975
|
+
var oldRangeParams = _this2.getOldRangeParams();
|
|
22975
22976
|
|
|
22977
|
+
console.log("Old range params");
|
|
22978
|
+
console.log(oldRangeParams); // Handle case of empty string returned
|
|
22976
22979
|
|
|
22977
22980
|
if (latex === "") {
|
|
22978
22981
|
// console.log("Empty latex returned from equation editor")
|
|
@@ -23359,15 +23362,14 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
23359
23362
|
|
|
23360
23363
|
var offset = rangeParams.endOffset;
|
|
23361
23364
|
var raw_text = elementToMarkedRawText(_this2.editableDiv, node, offset, _this2.enableHtml());
|
|
23365
|
+
console.log("Raw text before line insert");
|
|
23366
|
+
console.log(raw_text);
|
|
23367
|
+
console.log("Range params before line insert");
|
|
23368
|
+
console.log(rangeParams);
|
|
23362
23369
|
var new_raw_text = null;
|
|
23363
23370
|
|
|
23364
23371
|
var new_rangeParams = _objectSpread2({}, rangeParams);
|
|
23365
23372
|
|
|
23366
|
-
if (new_rangeParams.startGlobalOffset) {
|
|
23367
|
-
new_rangeParams.startGlobalOffset++;
|
|
23368
|
-
new_rangeParams.endGlobalOffset++;
|
|
23369
|
-
}
|
|
23370
|
-
|
|
23371
23373
|
if (_this2.enableHtml()) {
|
|
23372
23374
|
new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, "</p><p>"));
|
|
23373
23375
|
if (new_raw_text.substring(0, 3).toLowerCase() !== "<p>") new_raw_text = "<p>" + new_raw_text + "</p>";
|
|
@@ -23375,6 +23377,11 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
23375
23377
|
new_rangeParams.startOffset = 0;
|
|
23376
23378
|
new_rangeParams.endNodeIndex = rangeParams.endNodeIndex + 1;
|
|
23377
23379
|
new_rangeParams.endOffset = 0;
|
|
23380
|
+
|
|
23381
|
+
if (new_rangeParams.startGlobalOffset) {
|
|
23382
|
+
new_rangeParams.startGlobalOffset++;
|
|
23383
|
+
new_rangeParams.endGlobalOffset++;
|
|
23384
|
+
}
|
|
23378
23385
|
} else {
|
|
23379
23386
|
new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, "\n"));
|
|
23380
23387
|
new_rangeParams.startOffset++;
|
|
@@ -23382,6 +23389,10 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
23382
23389
|
}
|
|
23383
23390
|
|
|
23384
23391
|
new_raw_text = removeEncodingIfPlainText(new_raw_text, _this2.props.mimeType, _this2.enableHtml());
|
|
23392
|
+
console.log("New raw text after line insert");
|
|
23393
|
+
console.log(new_raw_text);
|
|
23394
|
+
console.log("New range params after line insert");
|
|
23395
|
+
console.log(new_rangeParams);
|
|
23385
23396
|
|
|
23386
23397
|
_this2.applyChangesToComponent(new_raw_text, _this2.props.mimeType, new_rangeParams, _this2.props.useExpertMode, _this2.props.selectedTab);
|
|
23387
23398
|
} catch (error) {
|
package/dist/math-rich-input.css
CHANGED
|
@@ -78,136 +78,6 @@
|
|
|
78
78
|
padding: 2px;
|
|
79
79
|
margin: 0px 2px;
|
|
80
80
|
}
|
|
81
|
-
/* Note that the top left position of the toolbar is set programatically in componentDidMount */
|
|
82
|
-
|
|
83
|
-
.Toolbar {
|
|
84
|
-
position: absolute;
|
|
85
|
-
z-index: 1;
|
|
86
|
-
display: flex;
|
|
87
|
-
height: 42px;
|
|
88
|
-
background-color: white;
|
|
89
|
-
border: 1px solid #d0d0d0;
|
|
90
|
-
border-radius: 5px;
|
|
91
|
-
box-shadow: 1px 1px 5px #a0a0a0;
|
|
92
|
-
animation: 0.5s fadeIn1;
|
|
93
|
-
animation-fill-mode: forwards;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@keyframes fadeIn1 {
|
|
97
|
-
0% {
|
|
98
|
-
opacity: 0;
|
|
99
|
-
}
|
|
100
|
-
100% {
|
|
101
|
-
opacity: 1;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
.Toolbar-button {
|
|
106
|
-
font-family: sans-serif;
|
|
107
|
-
font-size: 16px;
|
|
108
|
-
width: 40px;
|
|
109
|
-
height: 36px;
|
|
110
|
-
background-color: white;
|
|
111
|
-
border-radius: 5px;
|
|
112
|
-
border: 0px;
|
|
113
|
-
padding: 1px;
|
|
114
|
-
margin: 2px;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
.Toolbar-button:hover {
|
|
118
|
-
color: white;
|
|
119
|
-
background: #663676;
|
|
120
|
-
cursor: pointer;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
.Toolbar-button:active {
|
|
124
|
-
background: #808080;
|
|
125
|
-
color: white;
|
|
126
|
-
cursor: pointer;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
.TB-narrow {
|
|
130
|
-
width: 30px;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
.TB-wide {
|
|
134
|
-
width: 46px;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
.TB-selected {
|
|
138
|
-
background: #d0d0d0;
|
|
139
|
-
color: black;
|
|
140
|
-
cursor: pointer;
|
|
141
|
-
animation: 0.2s TB-fadeIn;
|
|
142
|
-
animation-fill-mode: forwards;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
.TB-selected:hover {
|
|
146
|
-
color: white;
|
|
147
|
-
background: #663676;
|
|
148
|
-
cursor: pointer;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
@keyframes TB-fadeIn {
|
|
152
|
-
00% {
|
|
153
|
-
background: white;
|
|
154
|
-
}
|
|
155
|
-
100% {
|
|
156
|
-
background: #d0d0d0;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/* Tooltip text */
|
|
161
|
-
.Toolbar-button .tooltiptext {
|
|
162
|
-
font-weight: normal;
|
|
163
|
-
visibility: hidden;
|
|
164
|
-
width: 100px;
|
|
165
|
-
background-color: #222;
|
|
166
|
-
color: #fff;
|
|
167
|
-
/*font-weight: bold;*/
|
|
168
|
-
font-size: 12px;
|
|
169
|
-
text-align: center;
|
|
170
|
-
padding: 4px 10px;
|
|
171
|
-
border-radius: 6px;
|
|
172
|
-
|
|
173
|
-
/* Position the tooltip text - see examples below! */
|
|
174
|
-
position: absolute;
|
|
175
|
-
z-index: 2;
|
|
176
|
-
top: -90%; /* Must leave a small gap between tooltip and button */
|
|
177
|
-
left: 50px;
|
|
178
|
-
|
|
179
|
-
/* transform: translate (50%,0%); */
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/* Show the tooltip text when you mouse over the tooltip container */
|
|
183
|
-
.Toolbar-button:hover .tooltiptext {
|
|
184
|
-
animation: 0.8s fadeIn2;
|
|
185
|
-
animation-fill-mode: forwards;
|
|
186
|
-
visibility: visible;
|
|
187
|
-
/* width: 100px; */
|
|
188
|
-
/* top: -90%; */ /* Must leave a small gap between tooltip and button */
|
|
189
|
-
/* left: 20%; */
|
|
190
|
-
/* margin-left: -50px; */
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
@keyframes fadeIn2 {
|
|
194
|
-
00% {
|
|
195
|
-
opacity: 0;
|
|
196
|
-
}
|
|
197
|
-
70% {
|
|
198
|
-
opacity: 0;
|
|
199
|
-
}
|
|
200
|
-
100% {
|
|
201
|
-
visibility: visible;
|
|
202
|
-
opacity: 0.9;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/* .tooltip {
|
|
207
|
-
position: relative;
|
|
208
|
-
display: inline-block;
|
|
209
|
-
border-bottom: 1px dotted black; /* If you want dots under the hoverable text
|
|
210
|
-
} */
|
|
211
81
|
.EquationEditorModal-background {
|
|
212
82
|
position: fixed;
|
|
213
83
|
top: 0;
|
|
@@ -363,6 +233,136 @@
|
|
|
363
233
|
.EquationEditorModal .slider.round:before {
|
|
364
234
|
border-radius: 50%;
|
|
365
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
366
|
/* Note that the top left position of the accent bar is set programatically in componentDidMount */
|
|
367
367
|
|
|
368
368
|
.AccentBar {
|
package/package.json
CHANGED
package/src/MathRichInput.jsx
CHANGED
|
@@ -477,6 +477,7 @@ export default class MathRichInput extends React.Component {
|
|
|
477
477
|
this.props.useExpertMode,
|
|
478
478
|
this.props.selectedTab
|
|
479
479
|
);
|
|
480
|
+
e.preventDefault()
|
|
480
481
|
return;
|
|
481
482
|
}
|
|
482
483
|
|
|
@@ -589,11 +590,15 @@ export default class MathRichInput extends React.Component {
|
|
|
589
590
|
let index = rangeParams.startNodeIndex;
|
|
590
591
|
let offset = rangeParams.startOffset;
|
|
591
592
|
|
|
593
|
+
console.log("handleKeyDownArrowLeft")
|
|
594
|
+
console.log(rangeParams)
|
|
592
595
|
let new_globalOffset = rangeParams.startGlobalOffset - 1;
|
|
596
|
+
|
|
593
597
|
let new_rangeParams = {
|
|
594
598
|
startGlobalOffset: new_globalOffset,
|
|
595
599
|
endGlobalOffset: new_globalOffset,
|
|
596
600
|
};
|
|
601
|
+
console.log(new_rangeParams)
|
|
597
602
|
e.preventDefault();
|
|
598
603
|
this._setRangeParams(new_rangeParams);
|
|
599
604
|
return;
|
|
@@ -1306,13 +1311,14 @@ export default class MathRichInput extends React.Component {
|
|
|
1306
1311
|
|
|
1307
1312
|
handleInput = (event) => {
|
|
1308
1313
|
try {
|
|
1309
|
-
|
|
1314
|
+
console.log("handleInput")
|
|
1310
1315
|
let raw_text = elementToMarkedRawText(
|
|
1311
1316
|
this.editableDiv,
|
|
1312
1317
|
null,
|
|
1313
1318
|
0,
|
|
1314
1319
|
this.enableHtml()
|
|
1315
1320
|
);
|
|
1321
|
+
console.log("handleInput 2")
|
|
1316
1322
|
const params = this._getRangeParams();
|
|
1317
1323
|
if (params === null || params === undefined)
|
|
1318
1324
|
console.error("Could not get range params from input field");
|
|
@@ -1659,6 +1665,8 @@ export default class MathRichInput extends React.Component {
|
|
|
1659
1665
|
let start_pos = this.markedRawText.indexOf(MARK);
|
|
1660
1666
|
let end_pos = this.markedRawText.indexOf(MARK, start_pos + MARK.length);
|
|
1661
1667
|
let oldRangeParams = this.getOldRangeParams();
|
|
1668
|
+
console.log("Old range params")
|
|
1669
|
+
console.log(oldRangeParams)
|
|
1662
1670
|
|
|
1663
1671
|
// Handle case of empty string returned
|
|
1664
1672
|
if (latex === "") {
|
|
@@ -2114,14 +2122,15 @@ export default class MathRichInput extends React.Component {
|
|
|
2114
2122
|
offset,
|
|
2115
2123
|
this.enableHtml()
|
|
2116
2124
|
);
|
|
2125
|
+
|
|
2126
|
+
console.log("Raw text before line insert")
|
|
2127
|
+
console.log(raw_text)
|
|
2128
|
+
console.log("Range params before line insert")
|
|
2129
|
+
console.log(rangeParams)
|
|
2130
|
+
|
|
2117
2131
|
let new_raw_text = null;
|
|
2118
2132
|
let new_rangeParams = { ...rangeParams };
|
|
2119
2133
|
|
|
2120
|
-
if (new_rangeParams.startGlobalOffset) {
|
|
2121
|
-
new_rangeParams.startGlobalOffset++;
|
|
2122
|
-
new_rangeParams.endGlobalOffset++;
|
|
2123
|
-
}
|
|
2124
|
-
|
|
2125
2134
|
if (this.enableHtml()) {
|
|
2126
2135
|
new_raw_text = removeMarks(
|
|
2127
2136
|
insertCharacterBeforeMarks(raw_text, "</p><p>")
|
|
@@ -2133,6 +2142,11 @@ export default class MathRichInput extends React.Component {
|
|
|
2133
2142
|
new_rangeParams.startOffset = 0;
|
|
2134
2143
|
new_rangeParams.endNodeIndex = rangeParams.endNodeIndex + 1;
|
|
2135
2144
|
new_rangeParams.endOffset = 0;
|
|
2145
|
+
if (new_rangeParams.startGlobalOffset) {
|
|
2146
|
+
new_rangeParams.startGlobalOffset++;
|
|
2147
|
+
new_rangeParams.endGlobalOffset++;
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2136
2150
|
} else {
|
|
2137
2151
|
new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, "\n"));
|
|
2138
2152
|
new_rangeParams.startOffset++;
|
|
@@ -2144,6 +2158,12 @@ export default class MathRichInput extends React.Component {
|
|
|
2144
2158
|
this.props.mimeType,
|
|
2145
2159
|
this.enableHtml()
|
|
2146
2160
|
);
|
|
2161
|
+
|
|
2162
|
+
console.log("New raw text after line insert")
|
|
2163
|
+
console.log(new_raw_text)
|
|
2164
|
+
console.log("New range params after line insert")
|
|
2165
|
+
console.log(new_rangeParams)
|
|
2166
|
+
|
|
2147
2167
|
|
|
2148
2168
|
this.applyChangesToComponent(
|
|
2149
2169
|
new_raw_text,
|
|
@@ -360,7 +360,7 @@ function addTextForNode(node, arrayOfText, nodeToMark=null, offset=0, useHtmlMat
|
|
|
360
360
|
if (mark)
|
|
361
361
|
arrayOfText.push(MARK)
|
|
362
362
|
} else {
|
|
363
|
-
console.error("
|
|
363
|
+
console.error("Can't render node in editable div: Unknown node type")
|
|
364
364
|
console.log(node)
|
|
365
365
|
console.log("Node.type:"+node.type)
|
|
366
366
|
console.log("Node.tagName:"+node.tagName)
|
|
@@ -382,6 +382,10 @@ 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)
|
|
387
|
+
if (element.innerHTML === "<p><br></p>")
|
|
388
|
+
throw new Error ("We are here")
|
|
385
389
|
// console.log("Node to mark:")
|
|
386
390
|
// console.log(nodeToMark)
|
|
387
391
|
let nodes = element.childNodes
|
|
@@ -757,7 +761,7 @@ function findNodeAndOffsetForGlobalOffset(node, globalOffset, result=null) {
|
|
|
757
761
|
result.node = null
|
|
758
762
|
result.offset ++
|
|
759
763
|
}
|
|
760
|
-
|
|
764
|
+
return false;
|
|
761
765
|
}
|
|
762
766
|
|
|
763
767
|
export function findFirstTextNode(node) {
|
|
@@ -774,6 +778,33 @@ export function findFirstTextNode(node) {
|
|
|
774
778
|
return null
|
|
775
779
|
}
|
|
776
780
|
|
|
781
|
+
function findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, globalOffset) {
|
|
782
|
+
let result = {offset:0}
|
|
783
|
+
findNodeAndOffsetForGlobalOffset(editableDiv, globalOffset, result)
|
|
784
|
+
console.log(result)
|
|
785
|
+
|
|
786
|
+
if (result.node === null) {
|
|
787
|
+
if (globalOffset > 0 && result.lastTextNode !== null) {
|
|
788
|
+
result.node = result.lastTextNode
|
|
789
|
+
result.offset = result.lastTextNode.nodeValue.length
|
|
790
|
+
} else {
|
|
791
|
+
console.warn("Unable to find node and offset for global offset: "+globalOffset)
|
|
792
|
+
console.log(editableDiv.innerHTML)
|
|
793
|
+
console.log(result)
|
|
794
|
+
result.node = findFirstTextNode(editableDiv)
|
|
795
|
+
result.offset = 0
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// if (result.offset === 0 &&
|
|
800
|
+
// result.node.nodeValue.length > 0 &&
|
|
801
|
+
// nodeStartsWithSmallSpace(result.node)) {
|
|
802
|
+
// result.offset = 1
|
|
803
|
+
// }
|
|
804
|
+
|
|
805
|
+
return result
|
|
806
|
+
}
|
|
807
|
+
|
|
777
808
|
// https://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html
|
|
778
809
|
export function getRangeParams(editableDiv) {
|
|
779
810
|
// console.log ("getRangeParams")
|
|
@@ -852,56 +883,23 @@ function setRangeParamsFromGlobalOffsets(editableDiv, params) {
|
|
|
852
883
|
try {
|
|
853
884
|
if (params === null || params === undefined)
|
|
854
885
|
throw new Error("Can't set range params: params === "+params)
|
|
855
|
-
let startResult =
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
console.warn("Can't set range
|
|
869
|
-
|
|
870
|
-
console.log(endResult)
|
|
871
|
-
|
|
872
|
-
if (startResult.node === null) {
|
|
873
|
-
if (params.startGlobalOffset > 0 && startResult.lastTextNode !== null) {
|
|
874
|
-
startResult.node = startResult.lastTextNode
|
|
875
|
-
startResult.offset = startResult.lastTextNode.nodeValue.length
|
|
876
|
-
} else {
|
|
877
|
-
startResult.node = findFirstTextNode(editableDiv)
|
|
878
|
-
startResult.offset = 0
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
if (endResult.node === null) {
|
|
882
|
-
if (params.endGlobalOffset > 0 && endResult.lastTextNode !== null) {
|
|
883
|
-
endResult.node = endResult.lastTextNode
|
|
884
|
-
endResult.offset = endResult.lastTextNode.nodeValue.length
|
|
885
|
-
} else {
|
|
886
|
-
endResult.node = findFirstTextNode(editableDiv)
|
|
887
|
-
endResult.offset = 0
|
|
888
|
-
}
|
|
889
|
-
}
|
|
886
|
+
let startResult =
|
|
887
|
+
findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, params.startGlobalOffset)
|
|
888
|
+
|
|
889
|
+
let endResult =
|
|
890
|
+
findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, params.endGlobalOffset)
|
|
891
|
+
|
|
892
|
+
if (startResult.node !== null) {
|
|
893
|
+
console.log("Setting range to start in node:")
|
|
894
|
+
console.log(" node type: "+startResult.node.nodeType)
|
|
895
|
+
console.log(" tag name: "+startResult.node.tagName)
|
|
896
|
+
console.log(" node value: "+startResult.node.nodeValue)
|
|
897
|
+
console.log(" offset:"+startResult.offset)
|
|
898
|
+
} else {
|
|
899
|
+
console.warn("Can't set range, null start node returned")
|
|
900
|
+
return
|
|
890
901
|
}
|
|
891
902
|
|
|
892
|
-
if (startResult.offset === 0 &&
|
|
893
|
-
startResult.node.nodeValue.length > 0 &&
|
|
894
|
-
nodeStartsWithSmallSpace(startResult.node)) {
|
|
895
|
-
startResult.offset = 1
|
|
896
|
-
}
|
|
897
|
-
if (endResult.offset === 0 &&
|
|
898
|
-
endResult.node.nodeValue.length > 0 &&
|
|
899
|
-
nodeStartsWithSmallSpace(endResult.node)) {
|
|
900
|
-
endResult.offset = 1
|
|
901
|
-
}
|
|
902
|
-
// console.log("Setting range to:")
|
|
903
|
-
// console.log(startResult.node.nodeType+":"+startResult.node.tagName+":"+
|
|
904
|
-
// startResult.node.nodeValue+":"+startResult.offset)
|
|
905
903
|
new_range = document.createRange();
|
|
906
904
|
new_range.setStart(startResult.node, startResult.offset);
|
|
907
905
|
new_range.setEnd(endResult.node, endResult.offset);
|
|
@@ -926,12 +924,15 @@ export function setRangeParams(editableDiv, params) {
|
|
|
926
924
|
console.error("Can't set range params: params === "+params)
|
|
927
925
|
return
|
|
928
926
|
}
|
|
929
|
-
|
|
930
|
-
|
|
927
|
+
|
|
928
|
+
// New way of doing things
|
|
929
|
+
if (params.startGlobalOffset !== null && params.startGlobalOffset !== undefined) {
|
|
931
930
|
setRangeParamsFromGlobalOffsets(editableDiv, params)
|
|
932
931
|
return
|
|
933
932
|
}
|
|
934
|
-
|
|
933
|
+
|
|
934
|
+
// Otherwise use the old way of doing things
|
|
935
|
+
|
|
935
936
|
if (params.startNodeIndex === null || params.startNodeIndex === undefined) {
|
|
936
937
|
console.error("Can't set range params: params.startNodeIndex === "+params.startNodeIndex)
|
|
937
938
|
return
|