@zzish/math-rich-input 0.1.6 → 0.1.8
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 +74 -36
- package/dist/math-rich-input.css +8 -15
- package/package.json +1 -1
- package/src/AccentBar.css +4 -5
- package/src/AccentBar.jsx +35 -20
- package/src/MathRichInput.css +3 -2
- package/src/Toolbar.css +1 -3
- package/src/Toolbar.jsx +29 -16
package/dist/index.js
CHANGED
|
@@ -19497,8 +19497,7 @@ var EquationEditorModal = /*#__PURE__*/function (_React$Component) {
|
|
|
19497
19497
|
}(React__default['default'].Component);
|
|
19498
19498
|
|
|
19499
19499
|
var DEFAULT_TOP$1 = -1;
|
|
19500
|
-
var
|
|
19501
|
-
var TOP_MARGIN = 3;
|
|
19500
|
+
var DEFAULT_RIGHT$1 = -1;
|
|
19502
19501
|
var ACCENTS_FOR_LETTER = {
|
|
19503
19502
|
a: ["à", "á", "â", "ä", "æ", "ã", "å", "ā"],
|
|
19504
19503
|
c: ["ç", "ć", "č"],
|
|
@@ -19698,6 +19697,11 @@ var AccentBar = /*#__PURE__*/function (_React$Component) {
|
|
|
19698
19697
|
if (insert) _this.suppliedClickHandler(e, null, character);else _this.suppliedClickHandler(e, _this.letterForAccents, character);
|
|
19699
19698
|
});
|
|
19700
19699
|
|
|
19700
|
+
_defineProperty(_assertThisInitialized(_this), "isInViewport", function (element) {
|
|
19701
|
+
var rect = element.getBoundingClientRect();
|
|
19702
|
+
return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth);
|
|
19703
|
+
});
|
|
19704
|
+
|
|
19701
19705
|
_defineProperty(_assertThisInitialized(_this), "handleSelectTab", function (tab) {
|
|
19702
19706
|
GLOBAL_last_selected_tab = tab;
|
|
19703
19707
|
|
|
@@ -19707,7 +19711,6 @@ var AccentBar = /*#__PURE__*/function (_React$Component) {
|
|
|
19707
19711
|
});
|
|
19708
19712
|
|
|
19709
19713
|
_defineProperty(_assertThisInitialized(_this), "componentDidUpdate", function (prevProps) {
|
|
19710
|
-
// console.log("componentDidUpdate")
|
|
19711
19714
|
var accentKey = _this.props.keyPressed;
|
|
19712
19715
|
|
|
19713
19716
|
if (accentKey === "Backspace" || accentKey === "ArrowLeft" || accentKey === "ArrowRight") {
|
|
@@ -19727,7 +19730,8 @@ var AccentBar = /*#__PURE__*/function (_React$Component) {
|
|
|
19727
19730
|
_this.state = {
|
|
19728
19731
|
selectedTab: GLOBAL_last_selected_tab,
|
|
19729
19732
|
top: DEFAULT_TOP$1,
|
|
19730
|
-
|
|
19733
|
+
right: DEFAULT_RIGHT$1,
|
|
19734
|
+
shouldHorizontiallyAlign: false
|
|
19731
19735
|
};
|
|
19732
19736
|
_this.suppliedClickHandler = null;
|
|
19733
19737
|
_this.handleButtonClick = _this.handleButtonClick.bind(_assertThisInitialized(_this));
|
|
@@ -19759,23 +19763,32 @@ var AccentBar = /*#__PURE__*/function (_React$Component) {
|
|
|
19759
19763
|
return;
|
|
19760
19764
|
}
|
|
19761
19765
|
|
|
19766
|
+
var toolBarBounds = thisBar.parentNode.getBoundingClientRect();
|
|
19762
19767
|
var inputBounds = node.getBoundingClientRect();
|
|
19763
19768
|
var thisBounds = thisBar.getBoundingClientRect();
|
|
19764
19769
|
this.shouldUpdatePosition = false; // Vertically align below input field
|
|
19765
19770
|
|
|
19766
|
-
var top = inputBounds.bottom
|
|
19771
|
+
var top = inputBounds.bottom - toolBarBounds.height;
|
|
19772
|
+
if (this.props.compactMode) top = inputBounds.height; // Horizontally align
|
|
19767
19773
|
|
|
19768
|
-
var
|
|
19769
|
-
|
|
19770
|
-
if (this.props.compactMode) left = inputBounds.left; // left align
|
|
19774
|
+
var right = 0; // right align
|
|
19771
19775
|
// Make sure it is on screen horizontally
|
|
19772
19776
|
|
|
19773
|
-
|
|
19774
|
-
|
|
19775
|
-
if (
|
|
19777
|
+
var shouldHorizontiallyAlign = false;
|
|
19778
|
+
|
|
19779
|
+
if (thisBounds.width > inputBounds.width) {
|
|
19780
|
+
shouldHorizontiallyAlign = true;
|
|
19781
|
+
|
|
19782
|
+
if (this.isInViewport(thisBar)) {
|
|
19783
|
+
right = right - (thisBounds.width - inputBounds.width) / 2;
|
|
19784
|
+
} // else remain right aligned
|
|
19785
|
+
|
|
19786
|
+
}
|
|
19787
|
+
|
|
19776
19788
|
this.setState({
|
|
19777
|
-
|
|
19778
|
-
top: top
|
|
19789
|
+
right: right,
|
|
19790
|
+
top: top,
|
|
19791
|
+
shouldHorizontiallyAlign: shouldHorizontiallyAlign
|
|
19779
19792
|
});
|
|
19780
19793
|
} else {
|
|
19781
19794
|
this.shouldUpdatePosition = true;
|
|
@@ -19804,8 +19817,11 @@ var AccentBar = /*#__PURE__*/function (_React$Component) {
|
|
|
19804
19817
|
|
|
19805
19818
|
var style = _objectSpread2({}, this.props.style);
|
|
19806
19819
|
|
|
19807
|
-
if (this.state.
|
|
19808
|
-
|
|
19820
|
+
if (this.state.right !== DEFAULT_RIGHT$1 || this.state.top !== DEFAULT_TOP$1) {
|
|
19821
|
+
if (!this.props.compactMode || this.state.shouldHorizontiallyAlign) {
|
|
19822
|
+
style.right = this.state.right + "px";
|
|
19823
|
+
}
|
|
19824
|
+
|
|
19809
19825
|
style.top = this.state.top + "px";
|
|
19810
19826
|
}
|
|
19811
19827
|
|
|
@@ -19824,7 +19840,7 @@ var AccentBar = /*#__PURE__*/function (_React$Component) {
|
|
|
19824
19840
|
onClick: function onClick(e) {
|
|
19825
19841
|
return e.preventDefault();
|
|
19826
19842
|
}
|
|
19827
|
-
}, compactMode && /*#__PURE__*/React__default['default'].createElement(
|
|
19843
|
+
}, compactMode && /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, quickAccents.map(function (character, index) {
|
|
19828
19844
|
return /*#__PURE__*/React__default['default'].createElement("button", {
|
|
19829
19845
|
className: "AccentBar-button AB-narrow AB-compact",
|
|
19830
19846
|
key: "accent-button-" + index,
|
|
@@ -20242,7 +20258,7 @@ var AccentBar = /*#__PURE__*/function (_React$Component) {
|
|
|
20242
20258
|
}(React__default['default'].Component);
|
|
20243
20259
|
|
|
20244
20260
|
var DEFAULT_TOP = 0;
|
|
20245
|
-
var
|
|
20261
|
+
var DEFAULT_RIGHT = 0;
|
|
20246
20262
|
var BOTTOM_MARGIN = 5;
|
|
20247
20263
|
var CTRL_OR_META = /(Mac)/i.test(window.navigator.platform) ? "\u2318" : "CTRL+";
|
|
20248
20264
|
|
|
@@ -20300,10 +20316,16 @@ var Toolbar = /*#__PURE__*/function (_React$Component) {
|
|
|
20300
20316
|
|
|
20301
20317
|
});
|
|
20302
20318
|
|
|
20319
|
+
_defineProperty(_assertThisInitialized(_this), "isInViewport", function (element) {
|
|
20320
|
+
var rect = element.getBoundingClientRect();
|
|
20321
|
+
return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth);
|
|
20322
|
+
});
|
|
20323
|
+
|
|
20303
20324
|
_this.state = {
|
|
20304
20325
|
showAccents: false,
|
|
20305
20326
|
top: DEFAULT_TOP,
|
|
20306
|
-
|
|
20327
|
+
right: DEFAULT_RIGHT,
|
|
20328
|
+
shouldHorizontiallyAlign: false
|
|
20307
20329
|
};
|
|
20308
20330
|
_this.handleButtonClick = _this.handleButtonClick.bind(_assertThisInitialized(_this));
|
|
20309
20331
|
_this.suppliedClickHandler = null;
|
|
@@ -20336,16 +20358,25 @@ var Toolbar = /*#__PURE__*/function (_React$Component) {
|
|
|
20336
20358
|
var thisBounds = thisBar.getBoundingClientRect();
|
|
20337
20359
|
this.shouldUpdatePosition = false; // Vertically align above input field
|
|
20338
20360
|
|
|
20339
|
-
var top =
|
|
20361
|
+
var top = (thisBounds.height + BOTTOM_MARGIN) * -1; // Horizontally align
|
|
20362
|
+
|
|
20363
|
+
var right = 0; // right align
|
|
20340
20364
|
|
|
20341
|
-
var
|
|
20365
|
+
var shouldHorizontiallyAlign = false;
|
|
20366
|
+
|
|
20367
|
+
if (thisBounds.width > inputBounds.width) {
|
|
20368
|
+
shouldHorizontiallyAlign = true;
|
|
20369
|
+
|
|
20370
|
+
if (this.isInViewport(thisBar)) {
|
|
20371
|
+
right = right - (thisBounds.width - inputBounds.width) / 2;
|
|
20372
|
+
} // else remain right aligned
|
|
20373
|
+
|
|
20374
|
+
}
|
|
20342
20375
|
|
|
20343
|
-
if (thisBounds.width > inputBounds.width) left = inputBounds.left - (thisBounds.width - inputBounds.width) / 2;
|
|
20344
|
-
if (left + thisBounds.width > window.innerWidth) left = window.innerWidth - thisBounds.width - 2;
|
|
20345
|
-
if (left < 0) left = 0;
|
|
20346
20376
|
this.setState({
|
|
20347
|
-
|
|
20348
|
-
top: top
|
|
20377
|
+
right: right,
|
|
20378
|
+
top: top,
|
|
20379
|
+
shouldHorizontiallyAlign: shouldHorizontiallyAlign
|
|
20349
20380
|
});
|
|
20350
20381
|
} else {
|
|
20351
20382
|
this.shouldUpdatePosition = true;
|
|
@@ -20376,8 +20407,11 @@ var Toolbar = /*#__PURE__*/function (_React$Component) {
|
|
|
20376
20407
|
// }
|
|
20377
20408
|
|
|
20378
20409
|
|
|
20379
|
-
if (this.state.
|
|
20380
|
-
|
|
20410
|
+
if (this.state.right !== DEFAULT_RIGHT || this.state.top !== DEFAULT_TOP) {
|
|
20411
|
+
if (!this.props.compactMode || this.state.shouldHorizontiallyAlign) {
|
|
20412
|
+
style.right = this.state.right + "px";
|
|
20413
|
+
}
|
|
20414
|
+
|
|
20381
20415
|
style.top = this.state.top + "px";
|
|
20382
20416
|
}
|
|
20383
20417
|
|
|
@@ -21974,7 +22008,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
21974
22008
|
});
|
|
21975
22009
|
} else {
|
|
21976
22010
|
_this2.setState({
|
|
21977
|
-
showAccentBar:
|
|
22011
|
+
showAccentBar: false
|
|
21978
22012
|
});
|
|
21979
22013
|
}
|
|
21980
22014
|
|
|
@@ -21993,7 +22027,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
21993
22027
|
if (_this2.keyPressStartTime < 0) {
|
|
21994
22028
|
_this2.keyPressStartTime = Date.now();
|
|
21995
22029
|
if (_this2.state.showAccentBar) _this2.setState({
|
|
21996
|
-
showAccentBar:
|
|
22030
|
+
showAccentBar: false
|
|
21997
22031
|
});
|
|
21998
22032
|
}
|
|
21999
22033
|
|
|
@@ -22752,7 +22786,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22752
22786
|
_this2.insertAccentLetter(event, oldCharacter, newCharacter);
|
|
22753
22787
|
|
|
22754
22788
|
_this2.setState({
|
|
22755
|
-
showAccentBar:
|
|
22789
|
+
showAccentBar: false
|
|
22756
22790
|
});
|
|
22757
22791
|
} catch (error) {
|
|
22758
22792
|
console.error(error);
|
|
@@ -22772,17 +22806,21 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22772
22806
|
}
|
|
22773
22807
|
});
|
|
22774
22808
|
|
|
22775
|
-
_defineProperty(_assertThisInitialized(_this2), "handleBlur", function (event) {
|
|
22776
|
-
|
|
22777
|
-
|
|
22778
|
-
|
|
22779
|
-
|
|
22809
|
+
_defineProperty(_assertThisInitialized(_this2), "handleBlur", function (event) {
|
|
22810
|
+
try {
|
|
22811
|
+
_this2.setState({
|
|
22812
|
+
hasFocus: false,
|
|
22813
|
+
showAccentBar: false
|
|
22814
|
+
});
|
|
22815
|
+
} catch (error) {
|
|
22816
|
+
console.error(error);
|
|
22817
|
+
}
|
|
22780
22818
|
});
|
|
22781
22819
|
|
|
22782
22820
|
_this2.state = {
|
|
22783
22821
|
showEquationEditor: false,
|
|
22784
22822
|
equationEditorLatex: "",
|
|
22785
|
-
showAccentBar:
|
|
22823
|
+
showAccentBar: false,
|
|
22786
22824
|
activeButtons: {
|
|
22787
22825
|
bold: false,
|
|
22788
22826
|
italic: false,
|
package/dist/math-rich-input.css
CHANGED
|
@@ -18,10 +18,9 @@
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
.MathRichInput-scrollview {
|
|
21
|
+
position: relative;
|
|
21
22
|
display: flex;
|
|
22
|
-
overflow: scroll;
|
|
23
23
|
border-radius: 5px;
|
|
24
|
-
overflow: overlay;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
.MathRichInput p {
|
|
@@ -35,6 +34,8 @@
|
|
|
35
34
|
width: 100%;
|
|
36
35
|
border-radius: 5px;
|
|
37
36
|
background-color: #fff;
|
|
37
|
+
overflow-x: scroll;
|
|
38
|
+
overflow: overlay;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
.MathRichInput:focus {
|
|
@@ -226,7 +227,7 @@
|
|
|
226
227
|
/* Note that the top left position of the toolbar is set programatically in componentDidMount */
|
|
227
228
|
|
|
228
229
|
.Toolbar {
|
|
229
|
-
position:
|
|
230
|
+
position: absolute;
|
|
230
231
|
z-index: 1;
|
|
231
232
|
display: flex;
|
|
232
233
|
height: 42px;
|
|
@@ -236,8 +237,6 @@
|
|
|
236
237
|
box-shadow: 1px 1px 5px #a0a0a0;
|
|
237
238
|
animation: 0.5s fadeIn1;
|
|
238
239
|
animation-fill-mode: forwards;
|
|
239
|
-
top: 0px;
|
|
240
|
-
left: 0px; /* important to set this so that toolbar initially renders full width */
|
|
241
240
|
}
|
|
242
241
|
|
|
243
242
|
@keyframes fadeIn1 {
|
|
@@ -281,11 +280,6 @@
|
|
|
281
280
|
width: 46px;
|
|
282
281
|
}
|
|
283
282
|
|
|
284
|
-
.TB-up4 {
|
|
285
|
-
position: relative;
|
|
286
|
-
top: -4px;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
283
|
.TB-selected {
|
|
290
284
|
background: #d0d0d0;
|
|
291
285
|
color: black;
|
|
@@ -363,28 +357,27 @@
|
|
|
363
357
|
/* Note that the top left position of the accent bar is set programatically in componentDidMount */
|
|
364
358
|
|
|
365
359
|
.AccentBar {
|
|
366
|
-
position:
|
|
360
|
+
position: absolute;
|
|
367
361
|
z-index: 1;
|
|
368
362
|
width: 360px;
|
|
369
363
|
background-color: #fff;
|
|
370
364
|
border: 1px solid #d0d0d0;
|
|
371
365
|
border-radius: 5px;
|
|
372
366
|
box-shadow: 1px 1px 5px #a0a0a0;
|
|
373
|
-
padding:
|
|
367
|
+
padding: 8px;
|
|
374
368
|
animation: 0.4s fadeIn1;
|
|
375
369
|
animation-fill-mode: forwards;
|
|
376
370
|
}
|
|
377
371
|
|
|
378
372
|
.AccentBar-compact {
|
|
379
|
-
|
|
373
|
+
display: flex;
|
|
374
|
+
position: absolute;
|
|
380
375
|
z-index: 1;
|
|
381
376
|
background-color: white;
|
|
382
377
|
border: 1px solid #d0d0d0;
|
|
383
378
|
border-radius: 5px;
|
|
384
379
|
box-shadow: 1px 1px 5px #a0a0a0;
|
|
385
380
|
padding: 5px;
|
|
386
|
-
top: 0px;
|
|
387
|
-
left: 0px; /* Important to set this default so that accent bar renders to optimal width */
|
|
388
381
|
animation: 0.4s fadeIn1;
|
|
389
382
|
animation-fill-mode: forwards;
|
|
390
383
|
}
|
package/package.json
CHANGED
package/src/AccentBar.css
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
/* Note that the top left position of the accent bar is set programatically in componentDidMount */
|
|
2
2
|
|
|
3
3
|
.AccentBar {
|
|
4
|
-
position:
|
|
4
|
+
position: absolute;
|
|
5
5
|
z-index: 1;
|
|
6
6
|
width: 360px;
|
|
7
7
|
background-color: #fff;
|
|
8
8
|
border: 1px solid #d0d0d0;
|
|
9
9
|
border-radius: 5px;
|
|
10
10
|
box-shadow: 1px 1px 5px #a0a0a0;
|
|
11
|
-
padding:
|
|
11
|
+
padding: 8px;
|
|
12
12
|
animation: 0.4s fadeIn1;
|
|
13
13
|
animation-fill-mode: forwards;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
.AccentBar-compact {
|
|
17
|
-
|
|
17
|
+
display: flex;
|
|
18
|
+
position: absolute;
|
|
18
19
|
z-index: 1;
|
|
19
20
|
background-color: white;
|
|
20
21
|
border: 1px solid #d0d0d0;
|
|
21
22
|
border-radius: 5px;
|
|
22
23
|
box-shadow: 1px 1px 5px #a0a0a0;
|
|
23
24
|
padding: 5px;
|
|
24
|
-
top: 0px;
|
|
25
|
-
left: 0px; /* Important to set this default so that accent bar renders to optimal width */
|
|
26
25
|
animation: 0.4s fadeIn1;
|
|
27
26
|
animation-fill-mode: forwards;
|
|
28
27
|
}
|
package/src/AccentBar.jsx
CHANGED
|
@@ -3,7 +3,7 @@ import React from "react";
|
|
|
3
3
|
import "./AccentBar.css";
|
|
4
4
|
|
|
5
5
|
const DEFAULT_TOP = -1;
|
|
6
|
-
const
|
|
6
|
+
const DEFAULT_RIGHT = -1;
|
|
7
7
|
const TOP_MARGIN = 3;
|
|
8
8
|
|
|
9
9
|
const ACCENTS_FOR_LETTER = {
|
|
@@ -566,7 +566,8 @@ export default class AccentBar extends React.Component {
|
|
|
566
566
|
this.state = {
|
|
567
567
|
selectedTab: GLOBAL_last_selected_tab,
|
|
568
568
|
top: DEFAULT_TOP,
|
|
569
|
-
|
|
569
|
+
right: DEFAULT_RIGHT,
|
|
570
|
+
shouldHorizontiallyAlign: false,
|
|
570
571
|
};
|
|
571
572
|
this.suppliedClickHandler = null;
|
|
572
573
|
this.handleButtonClick = this.handleButtonClick.bind(this);
|
|
@@ -586,6 +587,17 @@ export default class AccentBar extends React.Component {
|
|
|
586
587
|
else this.suppliedClickHandler(e, this.letterForAccents, character);
|
|
587
588
|
};
|
|
588
589
|
|
|
590
|
+
isInViewport = (element) => {
|
|
591
|
+
const rect = element.getBoundingClientRect();
|
|
592
|
+
return (
|
|
593
|
+
rect.top >= 0 &&
|
|
594
|
+
rect.left >= 0 &&
|
|
595
|
+
rect.bottom <=
|
|
596
|
+
(window.innerHeight || document.documentElement.clientHeight) &&
|
|
597
|
+
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
|
|
598
|
+
);
|
|
599
|
+
};
|
|
600
|
+
|
|
589
601
|
componentDidMount() {
|
|
590
602
|
// We render once to find out the component's preferred size and then render again to update it
|
|
591
603
|
|
|
@@ -606,28 +618,30 @@ export default class AccentBar extends React.Component {
|
|
|
606
618
|
return;
|
|
607
619
|
}
|
|
608
620
|
|
|
609
|
-
|
|
610
|
-
|
|
621
|
+
const toolBarBounds = thisBar.parentNode.getBoundingClientRect();
|
|
622
|
+
const inputBounds = node.getBoundingClientRect();
|
|
623
|
+
const thisBounds = thisBar.getBoundingClientRect();
|
|
611
624
|
|
|
612
625
|
this.shouldUpdatePosition = false;
|
|
613
626
|
|
|
614
627
|
// Vertically align below input field
|
|
615
|
-
let top = inputBounds.bottom
|
|
628
|
+
let top = inputBounds.bottom - toolBarBounds.height;
|
|
629
|
+
if (this.props.compactMode) top = inputBounds.height;
|
|
616
630
|
|
|
617
|
-
// Horizontally align
|
|
618
|
-
let
|
|
619
|
-
if (this.props.compactMode) left = inputBounds.left; // left align
|
|
631
|
+
// Horizontally align
|
|
632
|
+
let right = 0; // right align
|
|
620
633
|
|
|
621
634
|
// Make sure it is on screen horizontally
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
if (left + thisBounds.width > window.innerWidth)
|
|
626
|
-
left = window.innerWidth - thisBounds.width - 2;
|
|
635
|
+
let shouldHorizontiallyAlign = false;
|
|
636
|
+
if (thisBounds.width > inputBounds.width) {
|
|
637
|
+
shouldHorizontiallyAlign = true;
|
|
627
638
|
|
|
628
|
-
|
|
639
|
+
if (this.isInViewport(thisBar)) {
|
|
640
|
+
right = right - (thisBounds.width - inputBounds.width) / 2;
|
|
641
|
+
} // else remain right aligned
|
|
642
|
+
}
|
|
629
643
|
|
|
630
|
-
this.setState({
|
|
644
|
+
this.setState({ right, top, shouldHorizontiallyAlign });
|
|
631
645
|
} else {
|
|
632
646
|
this.shouldUpdatePosition = true;
|
|
633
647
|
}
|
|
@@ -639,7 +653,6 @@ export default class AccentBar extends React.Component {
|
|
|
639
653
|
};
|
|
640
654
|
|
|
641
655
|
componentDidUpdate = (prevProps) => {
|
|
642
|
-
// console.log("componentDidUpdate")
|
|
643
656
|
let accentKey = this.props.keyPressed;
|
|
644
657
|
if (
|
|
645
658
|
accentKey === "Backspace" ||
|
|
@@ -692,8 +705,10 @@ export default class AccentBar extends React.Component {
|
|
|
692
705
|
|
|
693
706
|
// Set up the tranlation to place the accent bar where we want it
|
|
694
707
|
let style = { ...this.props.style };
|
|
695
|
-
if (this.state.
|
|
696
|
-
|
|
708
|
+
if (this.state.right !== DEFAULT_RIGHT || this.state.top !== DEFAULT_TOP) {
|
|
709
|
+
if (!this.props.compactMode || this.state.shouldHorizontiallyAlign) {
|
|
710
|
+
style.right = this.state.right + "px";
|
|
711
|
+
}
|
|
697
712
|
style.top = this.state.top + "px";
|
|
698
713
|
}
|
|
699
714
|
|
|
@@ -708,7 +723,7 @@ export default class AccentBar extends React.Component {
|
|
|
708
723
|
>
|
|
709
724
|
{/* Compact mode */}
|
|
710
725
|
{compactMode && (
|
|
711
|
-
|
|
726
|
+
<>
|
|
712
727
|
{quickAccents.map((character, index) => {
|
|
713
728
|
return (
|
|
714
729
|
<button
|
|
@@ -722,7 +737,7 @@ export default class AccentBar extends React.Component {
|
|
|
722
737
|
</button>
|
|
723
738
|
);
|
|
724
739
|
})}
|
|
725
|
-
|
|
740
|
+
</>
|
|
726
741
|
)}
|
|
727
742
|
|
|
728
743
|
{/* Normal mode */}
|
package/src/MathRichInput.css
CHANGED
|
@@ -18,10 +18,9 @@
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
.MathRichInput-scrollview {
|
|
21
|
+
position: relative;
|
|
21
22
|
display: flex;
|
|
22
|
-
overflow: scroll;
|
|
23
23
|
border-radius: 5px;
|
|
24
|
-
overflow: overlay;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
.MathRichInput p {
|
|
@@ -35,6 +34,8 @@
|
|
|
35
34
|
width: 100%;
|
|
36
35
|
border-radius: 5px;
|
|
37
36
|
background-color: #fff;
|
|
37
|
+
overflow-x: scroll;
|
|
38
|
+
overflow: overlay;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
.MathRichInput:focus {
|
package/src/Toolbar.css
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Note that the top left position of the toolbar is set programatically in componentDidMount */
|
|
2
2
|
|
|
3
3
|
.Toolbar {
|
|
4
|
-
position:
|
|
4
|
+
position: absolute;
|
|
5
5
|
z-index: 1;
|
|
6
6
|
display: flex;
|
|
7
7
|
height: 42px;
|
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
box-shadow: 1px 1px 5px #a0a0a0;
|
|
12
12
|
animation: 0.5s fadeIn1;
|
|
13
13
|
animation-fill-mode: forwards;
|
|
14
|
-
top: 0px;
|
|
15
|
-
left: 0px; /* important to set this so that toolbar initially renders full width */
|
|
16
14
|
}
|
|
17
15
|
|
|
18
16
|
@keyframes fadeIn1 {
|
package/src/Toolbar.jsx
CHANGED
|
@@ -5,9 +5,8 @@ import AccentBar from "./AccentBar";
|
|
|
5
5
|
|
|
6
6
|
import "./Toolbar.css";
|
|
7
7
|
|
|
8
|
-
// const DEFAULT_TRANSLATE = 0
|
|
9
8
|
const DEFAULT_TOP = 0;
|
|
10
|
-
const
|
|
9
|
+
const DEFAULT_RIGHT = 0;
|
|
11
10
|
const BOTTOM_MARGIN = 5;
|
|
12
11
|
|
|
13
12
|
const CTRL_OR_META = /(Mac)/i.test(window.navigator.platform)
|
|
@@ -21,7 +20,8 @@ export default class Toolbar extends React.Component {
|
|
|
21
20
|
this.state = {
|
|
22
21
|
showAccents: false,
|
|
23
22
|
top: DEFAULT_TOP,
|
|
24
|
-
|
|
23
|
+
right: DEFAULT_RIGHT,
|
|
24
|
+
shouldHorizontiallyAlign: false,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
this.handleButtonClick = this.handleButtonClick.bind(this);
|
|
@@ -66,6 +66,17 @@ export default class Toolbar extends React.Component {
|
|
|
66
66
|
// this.hideAccentBar(null)
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
+
isInViewport = (element) => {
|
|
70
|
+
const rect = element.getBoundingClientRect();
|
|
71
|
+
return (
|
|
72
|
+
rect.top >= 0 &&
|
|
73
|
+
rect.left >= 0 &&
|
|
74
|
+
rect.bottom <=
|
|
75
|
+
(window.innerHeight || document.documentElement.clientHeight) &&
|
|
76
|
+
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
69
80
|
componentDidMount() {
|
|
70
81
|
// We render once to find out the component's preferred size and then render again to update it
|
|
71
82
|
if (this.shouldUpdatePosition) {
|
|
@@ -91,21 +102,21 @@ export default class Toolbar extends React.Component {
|
|
|
91
102
|
this.shouldUpdatePosition = false;
|
|
92
103
|
|
|
93
104
|
// Vertically align above input field
|
|
94
|
-
let top =
|
|
105
|
+
let top = (thisBounds.height + BOTTOM_MARGIN) * -1;
|
|
95
106
|
|
|
96
|
-
// Horizontally align
|
|
97
|
-
let
|
|
107
|
+
// Horizontally align
|
|
108
|
+
let right = 0; // right align
|
|
98
109
|
|
|
99
|
-
|
|
100
|
-
if (thisBounds.width > inputBounds.width)
|
|
101
|
-
|
|
110
|
+
let shouldHorizontiallyAlign = false;
|
|
111
|
+
if (thisBounds.width > inputBounds.width) {
|
|
112
|
+
shouldHorizontiallyAlign = true;
|
|
102
113
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
114
|
+
if (this.isInViewport(thisBar)) {
|
|
115
|
+
right = right - (thisBounds.width - inputBounds.width) / 2;
|
|
116
|
+
} // else remain right aligned
|
|
117
|
+
}
|
|
107
118
|
|
|
108
|
-
this.setState({
|
|
119
|
+
this.setState({ right, top, shouldHorizontiallyAlign });
|
|
109
120
|
} else {
|
|
110
121
|
this.shouldUpdatePosition = true;
|
|
111
122
|
}
|
|
@@ -133,8 +144,10 @@ export default class Toolbar extends React.Component {
|
|
|
133
144
|
// if (this.state.translateX !== DEFAULT_TRANSLATE) {
|
|
134
145
|
// style.transform = "translate("+this.state.translateX+"px, "+this.state.translateY+"px)";
|
|
135
146
|
// }
|
|
136
|
-
if (this.state.
|
|
137
|
-
|
|
147
|
+
if (this.state.right !== DEFAULT_RIGHT || this.state.top !== DEFAULT_TOP) {
|
|
148
|
+
if (!this.props.compactMode || this.state.shouldHorizontiallyAlign) {
|
|
149
|
+
style.right = this.state.right + "px";
|
|
150
|
+
}
|
|
138
151
|
style.top = this.state.top + "px";
|
|
139
152
|
}
|
|
140
153
|
|