@pie-lib/math-input 6.6.8 → 6.7.0
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/CHANGELOG.md +33 -0
- package/lib/horizontal-keypad.js +31 -37
- package/lib/horizontal-keypad.js.map +1 -1
- package/lib/index.js +12 -7
- package/lib/index.js.map +1 -1
- package/lib/keypad/index.js +93 -69
- package/lib/keypad/index.js.map +1 -1
- package/lib/keypad/keys-layout.js +5 -1
- package/lib/keypad/keys-layout.js.map +1 -1
- package/lib/keys/basic-operators.js +1 -1
- package/lib/keys/chars.js +1 -1
- package/lib/keys/comparison.js +7 -5
- package/lib/keys/comparison.js.map +1 -1
- package/lib/keys/constants.js +1 -1
- package/lib/keys/digits.js +2 -2
- package/lib/keys/digits.js.map +1 -1
- package/lib/keys/exponent.js +1 -1
- package/lib/keys/fractions.js +1 -1
- package/lib/keys/geometry.js +7 -5
- package/lib/keys/geometry.js.map +1 -1
- package/lib/keys/grades.js +14 -18
- package/lib/keys/grades.js.map +1 -1
- package/lib/keys/index.js +7 -3
- package/lib/keys/index.js.map +1 -1
- package/lib/keys/log.js +1 -1
- package/lib/keys/logic.js +1 -1
- package/lib/keys/matrices.js +1 -1
- package/lib/keys/misc.js +1 -1
- package/lib/keys/statistics.js +1 -1
- package/lib/keys/sub-sup.js +1 -1
- package/lib/keys/trigonometry.js +1 -1
- package/lib/keys/utils.js +11 -17
- package/lib/keys/utils.js.map +1 -1
- package/lib/keys/vars.js +1 -1
- package/lib/math-input.js +39 -47
- package/lib/math-input.js.map +1 -1
- package/lib/mq/index.js +2 -2
- package/lib/mq/index.js.map +1 -1
- package/lib/mq/input.js +30 -40
- package/lib/mq/input.js.map +1 -1
- package/lib/mq/static.js +26 -34
- package/lib/mq/static.js.map +1 -1
- package/package.json +2 -2
- package/src/horizontal-keypad.jsx +3 -1
- package/src/keypad/index.jsx +59 -9
- package/src/keys/grades.js +1 -1
package/lib/mq/static.js
CHANGED
|
@@ -1,41 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports["default"] = void 0;
|
|
7
9
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
11
|
|
|
14
|
-
var
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
13
|
|
|
16
|
-
var
|
|
14
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
var _react = _interopRequireDefault(require("react"));
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
var _mathquill = _interopRequireDefault(require("@pie-framework/mathquill"));
|
|
33
31
|
|
|
34
|
-
|
|
32
|
+
var _index = require("../index");
|
|
35
33
|
|
|
36
|
-
function
|
|
34
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
37
35
|
|
|
38
|
-
function
|
|
36
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
39
37
|
|
|
40
38
|
var MQ;
|
|
41
39
|
|
|
@@ -56,25 +54,22 @@ function stripSpaces() {
|
|
|
56
54
|
*/
|
|
57
55
|
|
|
58
56
|
|
|
59
|
-
var Static =
|
|
60
|
-
|
|
61
|
-
function (_React$Component) {
|
|
62
|
-
_inherits(Static, _React$Component);
|
|
57
|
+
var Static = /*#__PURE__*/function (_React$Component) {
|
|
58
|
+
(0, _inherits2["default"])(Static, _React$Component);
|
|
63
59
|
|
|
64
|
-
|
|
65
|
-
var _getPrototypeOf2;
|
|
60
|
+
var _super = _createSuper(Static);
|
|
66
61
|
|
|
62
|
+
function Static() {
|
|
67
63
|
var _this;
|
|
68
64
|
|
|
69
|
-
|
|
65
|
+
(0, _classCallCheck2["default"])(this, Static);
|
|
70
66
|
|
|
71
67
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
72
68
|
args[_key] = arguments[_key];
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
_this =
|
|
76
|
-
|
|
77
|
-
_defineProperty(_assertThisInitialized(_this), "onFocus", function (e) {
|
|
71
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
72
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onFocus", function (e) {
|
|
78
73
|
try {
|
|
79
74
|
var rootBlock = e.target.parentElement.nextSibling;
|
|
80
75
|
var id = parseInt(rootBlock.getAttribute('mathquill-block-id'), 10);
|
|
@@ -102,11 +97,10 @@ function (_React$Component) {
|
|
|
102
97
|
console.error('error finding root block', err.message);
|
|
103
98
|
}
|
|
104
99
|
});
|
|
105
|
-
|
|
106
100
|
return _this;
|
|
107
101
|
}
|
|
108
102
|
|
|
109
|
-
|
|
103
|
+
(0, _createClass2["default"])(Static, [{
|
|
110
104
|
key: "componentDidMount",
|
|
111
105
|
value: function componentDidMount() {
|
|
112
106
|
this.update();
|
|
@@ -193,7 +187,7 @@ function (_React$Component) {
|
|
|
193
187
|
var _this$props = this.props,
|
|
194
188
|
onBlur = _this$props.onBlur,
|
|
195
189
|
className = _this$props.className;
|
|
196
|
-
return _react["default"].createElement("span", {
|
|
190
|
+
return /*#__PURE__*/_react["default"].createElement("span", {
|
|
197
191
|
className: className,
|
|
198
192
|
onFocus: this.onFocus,
|
|
199
193
|
onBlur: onBlur,
|
|
@@ -203,13 +197,11 @@ function (_React$Component) {
|
|
|
203
197
|
});
|
|
204
198
|
}
|
|
205
199
|
}]);
|
|
206
|
-
|
|
207
200
|
return Static;
|
|
208
201
|
}(_react["default"].Component);
|
|
209
202
|
|
|
210
203
|
exports["default"] = Static;
|
|
211
|
-
|
|
212
|
-
_defineProperty(Static, "propTypes", {
|
|
204
|
+
(0, _defineProperty2["default"])(Static, "propTypes", {
|
|
213
205
|
latex: _propTypes["default"].string.isRequired,
|
|
214
206
|
onFocus: _propTypes["default"].func,
|
|
215
207
|
onBlur: _propTypes["default"].func,
|
package/lib/mq/static.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mq/static.jsx"],"names":["MQ","window","MathQuill","getInterface","log","REGEX","WHITESPACE_REGEX","stripSpaces","string","replace","Static","e","rootBlock","target","parentElement","nextSibling","id","parseInt","getAttribute","innerField","mathField","innerFields","find","f","name","props","getFieldName","setInput","onSubFieldFocus","err","console","error","message","update","field","onSubFieldChange","latex","Error","StaticMath","input","handlers","edit","onInputEdit","bind","parseLatex","blur","focus","nextProps","parsedLatex","stripped","newFieldCount","match","length","out","trim","Object","keys","warn","onBlur","className","onFocus","r","React","Component","PropTypes","isRequired","func"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/mq/static.jsx"],"names":["MQ","window","MathQuill","getInterface","log","REGEX","WHITESPACE_REGEX","stripSpaces","string","replace","Static","e","rootBlock","target","parentElement","nextSibling","id","parseInt","getAttribute","innerField","mathField","innerFields","find","f","name","props","getFieldName","setInput","onSubFieldFocus","err","console","error","message","update","field","onSubFieldChange","latex","Error","StaticMath","input","handlers","edit","onInputEdit","bind","parseLatex","blur","focus","nextProps","parsedLatex","stripped","newFieldCount","match","length","out","trim","Object","keys","warn","onBlur","className","onFocus","r","React","Component","PropTypes","isRequired","func"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAIA,EAAJ;;AACA,IAAI,OAAOC,MAAP,KAAkB,WAAtB,EAAmC;AACjCD,EAAAA,EAAE,GAAGE,sBAAUC,YAAV,CAAuB,CAAvB,CAAL;AACD;;AAED,IAAMC,GAAG,GAAG,uBAAM,8BAAN,CAAZ;AACA,IAAMC,KAAK,GAAG,wCAAd;AACA,IAAMC,gBAAgB,GAAG,IAAzB;;AAEA,SAASC,WAAT,GAAkC;AAAA,MAAbC,MAAa,uEAAJ,EAAI;AAChC,SAAOA,MAAM,CAACC,OAAP,CAAeH,gBAAf,EAAiC,EAAjC,CAAP;AACD;AAED;AACA;AACA;;;IACqBI,M;;;;;;;;;;;;;;;gGAqFT,UAAAC,CAAC,EAAI;AACb,UAAI;AACF,YAAIC,SAAS,GAAGD,CAAC,CAACE,MAAF,CAASC,aAAT,CAAuBC,WAAvC;AACA,YAAIC,EA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xB,IACAJ,aAAa,KAAKK,MAAM,CAACC,IAAP,CAAY,KAAKpC,SAAL,CAAeC,WAA3B,EAAwC+B,MAAxC,GAAiD,CAFrE;AAIAhD,QAAAA,GAAG,CAAC,0BAAD,EAA6BiD,GAA7B,CAAH;AACA,eAAOA,GAAP;AACD,OAXD,CAWE,OAAO1C,CAAP,EAAU;AACV;AACAmB,QAAAA,OAAO,CAAC2B,IAAR,CAAa,sBAAb,EAAqC9C,CAAC,CAACqB,OAAvC,EAAgD,aAAhD,EAFU,CAGV;;AACAF,QAAAA,OAAO,CAAC2B,IAAR,CAAa9C,CAAb;AACA,eAAO,KAAP;AACD;AACF;;;WA2BD,kBAAS;AAAA;;AACP,wBAA8B,KAAKc,KAAnC;AAAA,UAAQiC,MAAR,eAAQA,MAAR;AAAA,UAAgBC,SAAhB,eAAgBA,SAAhB;AAEA,0BACE;AACE,QAAA,SAAS,EAAEA,SADb;AAEE,QAAA,OAAO,EAAE,KAAKC,OAFhB;AAGE,QAAA,MAAM,EAAEF,MAHV;AAIE,QAAA,GAAG,EAAE,aAAAG,CAAC;AAAA,iBAAK,MAAI,CAACtB,KAAL,GAAasB,CAAlB;AAAA;AAJR,QADF;AAQD;;;EAzHiCC,kBAAMC,S;;;iCAArBrD,M,eACA;AACjB0B,EAAAA,KAAK,EAAE4B,sBAAUxD,MAAV,CAAiByD,UADP;AAEjBL,EAAAA,OAAO,EAAEI,sBAAUE,IAFF;AAGjBR,EAAAA,MAAM,EAAEM,sBAAUE,IAHD;AAIjBP,EAAAA,SAAS,EAAEK,sBAAUxD,MAJJ;AAKjBkB,EAAAA,YAAY,EAAEsC,sBAAUE,IALP;AAMjB/B,EAAAA,gBAAgB,EAAE6B,sBAAUE,IANX;AAOjBtC,EAAAA,eAAe,EAAEoC,sBAAUE,IAPV;AAQjBvC,EAAAA,QAAQ,EAAEqC,sBAAUE;AARH,C","sourcesContent":["import PropTypes from 'prop-types';\nimport React from 'react';\nimport debug from 'debug';\nimport MathQuill from '@pie-framework/mathquill';\nimport { updateSpans } from '../index';\n\nlet MQ;\nif (typeof window !== 'undefined') {\n MQ = MathQuill.getInterface(2);\n}\n\nconst log = debug('pie-lib:math-input:mq:static');\nconst REGEX = /\\\\MathQuillMathField\\[r\\d*\\]\\{(.*?)\\}/g;\nconst WHITESPACE_REGEX = / /g;\n\nfunction stripSpaces(string = '') {\n return string.replace(WHITESPACE_REGEX, '');\n}\n\n/**\n * Wrapper for MathQuill MQ.MathField.\n */\nexport default class Static extends React.Component {\n static propTypes = {\n latex: PropTypes.string.isRequired,\n onFocus: PropTypes.func,\n onBlur: PropTypes.func,\n className: PropTypes.string,\n getFieldName: PropTypes.func,\n onSubFieldChange: PropTypes.func,\n onSubFieldFocus: PropTypes.func,\n setInput: PropTypes.func\n };\n\n componentDidMount() {\n this.update();\n updateSpans();\n }\n\n componentDidUpdate() {\n this.update();\n updateSpans();\n }\n\n onInputEdit(field) {\n if (!this.mathField) {\n return;\n }\n const name = this.props.getFieldName(field, this.mathField.innerFields);\n if (this.props.onSubFieldChange) {\n this.props.onSubFieldChange(name, field.latex());\n }\n }\n\n update() {\n if (!MQ) {\n throw new Error('MQ is not defined - but component has mounted?');\n }\n // this.input.innerHTML = this.props.latex;\n if (!this.mathField) {\n this.mathField = MQ.StaticMath(this.input, {\n handlers: {\n edit: this.onInputEdit.bind(this)\n }\n });\n }\n\n try {\n this.mathField.parseLatex(this.props.latex);\n this.mathField.latex(this.props.latex);\n } catch (e) {\n // default latex if received has errors\n this.mathField.latex('\\\\MathQuillMathField[r1]{}');\n }\n }\n\n blur() {\n log('blur mathfield');\n this.mathField.blur();\n }\n\n focus() {\n log('focus mathfield...');\n this.mathField.focus();\n }\n\n shouldComponentUpdate(nextProps) {\n try {\n const parsedLatex = this.mathField.parseLatex(nextProps.latex);\n const stripped = stripSpaces(parsedLatex);\n const newFieldCount = (nextProps.latex.match(REGEX) || []).length;\n\n const out =\n stripped !== stripSpaces(this.mathField.latex().trim()) ||\n newFieldCount !== Object.keys(this.mathField.innerFields).length / 2;\n\n log('[shouldComponentUpdate] ', out);\n return out;\n } catch (e) {\n // eslint-disable-next-line no-console\n console.warn('Error parsing latex:', e.message, 'skip update');\n // eslint-disable-next-line no-console\n console.warn(e);\n return false;\n }\n }\n\n onFocus = e => {\n try {\n let rootBlock = e.target.parentElement.nextSibling;\n let id = parseInt(rootBlock.getAttribute('mathquill-block-id'), 10);\n\n if (!id) {\n rootBlock = rootBlock.parentElement;\n id = parseInt(rootBlock.getAttribute('mathquill-block-id'), 10);\n }\n\n const innerField = this.mathField.innerFields.find(f => f.id === id);\n\n if (innerField) {\n const name = this.props.getFieldName(innerField, this.mathField.innerFields);\n if (this.props.setInput) {\n this.props.setInput(innerField);\n }\n this.props.onSubFieldFocus(name, innerField);\n }\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error('error finding root block', err.message);\n }\n };\n\n render() {\n const { onBlur, className } = this.props;\n\n return (\n <span\n className={className}\n onFocus={this.onFocus}\n onBlur={onBlur}\n ref={r => (this.input = r)}\n />\n );\n }\n}\n"],"file":"static.js"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "6.
|
|
6
|
+
"version": "6.7.0",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"module": "src/index.jsx",
|
|
9
9
|
"dependencies": {
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"react-dom": "^16.9.0"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "f766e0fdb9e51a9449324db51ccaa93904211710"
|
|
26
26
|
}
|
|
@@ -18,6 +18,7 @@ export default class HorizontalKeypad extends React.Component {
|
|
|
18
18
|
static propTypes = {
|
|
19
19
|
className: PropTypes.string,
|
|
20
20
|
mode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
21
|
+
layoutForKeyPad: PropTypes.object,
|
|
21
22
|
onClick: PropTypes.func.isRequired,
|
|
22
23
|
onFocus: PropTypes.func,
|
|
23
24
|
noDecimal: PropTypes.bool,
|
|
@@ -37,7 +38,7 @@ export default class HorizontalKeypad extends React.Component {
|
|
|
37
38
|
};
|
|
38
39
|
|
|
39
40
|
render() {
|
|
40
|
-
const { mode, onFocus, noDecimal, className, additionalKeys } = this.props;
|
|
41
|
+
const { mode, onFocus, noDecimal, className, additionalKeys, layoutForKeyPad } = this.props;
|
|
41
42
|
const normalizedKeys = normalizeAdditionalKeys(additionalKeys);
|
|
42
43
|
|
|
43
44
|
return (
|
|
@@ -45,6 +46,7 @@ export default class HorizontalKeypad extends React.Component {
|
|
|
45
46
|
className={className}
|
|
46
47
|
onFocus={onFocus}
|
|
47
48
|
noDecimal={noDecimal}
|
|
49
|
+
layoutForKeyPad={layoutForKeyPad}
|
|
48
50
|
additionalKeys={extendKeySet(keysForGrade(mode), normalizedKeys)}
|
|
49
51
|
onPress={this.keypadPress}
|
|
50
52
|
mode={mode}
|
package/src/keypad/index.jsx
CHANGED
|
@@ -40,14 +40,17 @@ const LatexButton = withStyles(theme => ({
|
|
|
40
40
|
width: '30px',
|
|
41
41
|
marginTop: '0 !important',
|
|
42
42
|
borderTop: '2px solid black',
|
|
43
|
+
fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
|
|
44
|
+
|
|
43
45
|
'&.mq-arrow-both': {
|
|
46
|
+
top: '5px !important',
|
|
44
47
|
'& *': {
|
|
45
48
|
lineHeight: '1 !important'
|
|
46
49
|
},
|
|
47
50
|
'&:before': {
|
|
48
51
|
fontSize: '80%',
|
|
49
52
|
left: 'calc(-13%)',
|
|
50
|
-
top: '-0.
|
|
53
|
+
top: '-0.31em'
|
|
51
54
|
},
|
|
52
55
|
'&:after': {
|
|
53
56
|
fontSize: '80% !important',
|
|
@@ -57,12 +60,12 @@ const LatexButton = withStyles(theme => ({
|
|
|
57
60
|
'&.mq-empty:before': {
|
|
58
61
|
fontSize: '80%',
|
|
59
62
|
left: 'calc(-13%)',
|
|
60
|
-
top: '-0.
|
|
63
|
+
top: '-0.26em'
|
|
61
64
|
},
|
|
62
65
|
'&.mq-empty:after': {
|
|
63
66
|
fontSize: '80%',
|
|
64
67
|
right: 'calc(-13%)',
|
|
65
|
-
top: '-0.
|
|
68
|
+
top: '-0.26em'
|
|
66
69
|
},
|
|
67
70
|
'&.mq-empty': {
|
|
68
71
|
minHeight: '1.4em'
|
|
@@ -123,7 +126,7 @@ const LatexButton = withStyles(theme => ({
|
|
|
123
126
|
paddingTop: '0 !important'
|
|
124
127
|
},
|
|
125
128
|
'&:after': {
|
|
126
|
-
top: '-
|
|
129
|
+
top: '-2.8em !important'
|
|
127
130
|
}
|
|
128
131
|
}
|
|
129
132
|
}
|
|
@@ -145,6 +148,20 @@ const LatexButton = withStyles(theme => ({
|
|
|
145
148
|
} else {
|
|
146
149
|
buttonClass = classNames(props.classes.latexButton, props.mqClassName);
|
|
147
150
|
}
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
const MQ = MathQuill.getInterface(2);
|
|
154
|
+
const span = document.createElement('span');
|
|
155
|
+
span.innerHTML = '';
|
|
156
|
+
const mathField = MQ.StaticMath(span);
|
|
157
|
+
|
|
158
|
+
mathField.parseLatex(props.latex);
|
|
159
|
+
mathField.latex(props.latex);
|
|
160
|
+
} catch (e) {
|
|
161
|
+
// received latex has errors - do not create button
|
|
162
|
+
return <></>;
|
|
163
|
+
}
|
|
164
|
+
|
|
148
165
|
return (
|
|
149
166
|
<Button className={classNames(props.classes.root, props.className)} onClick={props.onClick}>
|
|
150
167
|
<mq.Static className={buttonClass} latex={props.latex} />
|
|
@@ -152,12 +169,25 @@ const LatexButton = withStyles(theme => ({
|
|
|
152
169
|
);
|
|
153
170
|
});
|
|
154
171
|
|
|
172
|
+
const createCustomLayout = layoutObj => {
|
|
173
|
+
if (layoutObj) {
|
|
174
|
+
return {
|
|
175
|
+
gridTemplateColumns: `repeat(${layoutObj.columns}, minmax(min-content, 150px))`,
|
|
176
|
+
gridTemplateRows: `repeat(${layoutObj.rows}, minmax(40px, 60px))`,
|
|
177
|
+
gridAutoFlow: 'initial'
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return {};
|
|
182
|
+
};
|
|
183
|
+
|
|
155
184
|
export class KeyPad extends React.Component {
|
|
156
185
|
static propTypes = {
|
|
157
186
|
classes: PropTypes.object.isRequired,
|
|
158
187
|
className: PropTypes.string,
|
|
159
188
|
baseSet: PropTypes.array,
|
|
160
189
|
additionalKeys: PropTypes.array,
|
|
190
|
+
layoutForKeyPad: PropTypes.object,
|
|
161
191
|
onPress: PropTypes.func.isRequired,
|
|
162
192
|
onFocus: PropTypes.func,
|
|
163
193
|
noDecimal: PropTypes.bool,
|
|
@@ -193,14 +223,23 @@ export class KeyPad extends React.Component {
|
|
|
193
223
|
};
|
|
194
224
|
|
|
195
225
|
render() {
|
|
196
|
-
const {
|
|
226
|
+
const {
|
|
227
|
+
classes,
|
|
228
|
+
className,
|
|
229
|
+
baseSet,
|
|
230
|
+
additionalKeys,
|
|
231
|
+
layoutForKeyPad,
|
|
232
|
+
onFocus,
|
|
233
|
+
mode
|
|
234
|
+
} = this.props;
|
|
197
235
|
|
|
198
236
|
const noBaseSet = [
|
|
199
237
|
'non-negative-integers',
|
|
200
238
|
'integers',
|
|
201
239
|
'decimals',
|
|
202
240
|
'fractions',
|
|
203
|
-
'item-authoring'
|
|
241
|
+
'item-authoring',
|
|
242
|
+
'language'
|
|
204
243
|
];
|
|
205
244
|
|
|
206
245
|
const keysWithoutBaseSet = noBaseSet.includes(mode);
|
|
@@ -211,10 +250,15 @@ export class KeyPad extends React.Component {
|
|
|
211
250
|
const shift = allKeys.length % 5 ? 1 : 0;
|
|
212
251
|
const style = {
|
|
213
252
|
gridTemplateColumns: `repeat(${Math.floor(allKeys.length / 5) +
|
|
214
|
-
shift}, minmax(min-content, 150px))
|
|
253
|
+
shift}, minmax(min-content, 150px))`,
|
|
254
|
+
...createCustomLayout(layoutForKeyPad)
|
|
215
255
|
};
|
|
216
256
|
return (
|
|
217
|
-
<div
|
|
257
|
+
<div
|
|
258
|
+
className={classNames(classes.keys, className, classes[mode])}
|
|
259
|
+
style={style}
|
|
260
|
+
onFocus={onFocus}
|
|
261
|
+
>
|
|
218
262
|
{allKeys.map((k, index) => {
|
|
219
263
|
const onClick = this.buttonClick.bind(this, k);
|
|
220
264
|
|
|
@@ -227,11 +271,14 @@ export class KeyPad extends React.Component {
|
|
|
227
271
|
className: classNames(
|
|
228
272
|
classes.labelButton,
|
|
229
273
|
!keysWithoutBaseSet && classes[k.category],
|
|
274
|
+
classes[k.extraClass],
|
|
230
275
|
k.label === ',' && classes.comma,
|
|
231
276
|
k.label === '.' && classes.dot
|
|
232
277
|
),
|
|
233
278
|
disabled: this.keyIsNotAllowed(k),
|
|
234
|
-
key: `${k.label || k.latex || k.command}-${index}
|
|
279
|
+
key: `${k.label || k.latex || k.command}-${index}`,
|
|
280
|
+
...(k.actions || {}),
|
|
281
|
+
...(k.extraProps || {})
|
|
235
282
|
};
|
|
236
283
|
|
|
237
284
|
if (k.latex) {
|
|
@@ -267,6 +314,9 @@ const styles = theme => ({
|
|
|
267
314
|
gridColumnGap: '0px',
|
|
268
315
|
gridAutoFlow: 'column'
|
|
269
316
|
},
|
|
317
|
+
character: {
|
|
318
|
+
textTransform: 'initial !important'
|
|
319
|
+
},
|
|
270
320
|
holder: {
|
|
271
321
|
position: 'relative',
|
|
272
322
|
width: '100%',
|
package/src/keys/grades.js
CHANGED