@pie-lib/math-input-mathlive 1.0.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/README.md +119 -0
- package/lib/__tests__/index.test.js +118 -0
- package/lib/__tests__/index.test.js.map +1 -0
- package/lib/__tests__/latex-bridge.test.js +186 -0
- package/lib/__tests__/latex-bridge.test.js.map +1 -0
- package/lib/__tests__/mathlive-instance.test.js +137 -0
- package/lib/__tests__/mathlive-instance.test.js.map +1 -0
- package/lib/horizontal-keypad.js +101 -0
- package/lib/horizontal-keypad.js.map +1 -0
- package/lib/index.js +143 -0
- package/lib/index.js.map +1 -0
- package/lib/keypad/index.js +365 -0
- package/lib/keypad/index.js.map +1 -0
- package/lib/keypad/keys-layout.js +22 -0
- package/lib/keypad/keys-layout.js.map +1 -0
- package/lib/keys/basic-operators.js +33 -0
- package/lib/keys/basic-operators.js.map +1 -0
- package/lib/keys/chars.js +12 -0
- package/lib/keys/chars.js.map +1 -0
- package/lib/keys/comparison.js +39 -0
- package/lib/keys/comparison.js.map +1 -0
- package/lib/keys/constants.js +37 -0
- package/lib/keys/constants.js.map +1 -0
- package/lib/keys/digits.js +46 -0
- package/lib/keys/digits.js.map +1 -0
- package/lib/keys/edit.js +14 -0
- package/lib/keys/edit.js.map +1 -0
- package/lib/keys/exponent.js +30 -0
- package/lib/keys/exponent.js.map +1 -0
- package/lib/keys/fractions.js +29 -0
- package/lib/keys/fractions.js.map +1 -0
- package/lib/keys/geometry.js +140 -0
- package/lib/keys/geometry.js.map +1 -0
- package/lib/keys/grades.js +259 -0
- package/lib/keys/grades.js.map +1 -0
- package/lib/keys/index.js +35 -0
- package/lib/keys/index.js.map +1 -0
- package/lib/keys/log.js +27 -0
- package/lib/keys/log.js.map +1 -0
- package/lib/keys/logic.js +19 -0
- package/lib/keys/logic.js.map +1 -0
- package/lib/keys/matrices.js +19 -0
- package/lib/keys/matrices.js.map +1 -0
- package/lib/keys/misc.js +62 -0
- package/lib/keys/misc.js.map +1 -0
- package/lib/keys/navigation.js +20 -0
- package/lib/keys/navigation.js.map +1 -0
- package/lib/keys/operators.js +15 -0
- package/lib/keys/operators.js.map +1 -0
- package/lib/keys/statistics.js +40 -0
- package/lib/keys/statistics.js.map +1 -0
- package/lib/keys/sub-sup.js +19 -0
- package/lib/keys/sub-sup.js.map +1 -0
- package/lib/keys/trigonometry.js +45 -0
- package/lib/keys/trigonometry.js.map +1 -0
- package/lib/keys/utils.js +87 -0
- package/lib/keys/utils.js.map +1 -0
- package/lib/keys/vars.js +24 -0
- package/lib/keys/vars.js.map +1 -0
- package/lib/latex-bridge.js +195 -0
- package/lib/latex-bridge.js.map +1 -0
- package/lib/math-input.js +143 -0
- package/lib/math-input.js.map +1 -0
- package/lib/mathlive-instance.js +319 -0
- package/lib/mathlive-instance.js.map +1 -0
- package/lib/mf/common-styles.js +111 -0
- package/lib/mf/common-styles.js.map +1 -0
- package/lib/mf/index.js +72 -0
- package/lib/mf/index.js.map +1 -0
- package/lib/mf/input.js +266 -0
- package/lib/mf/input.js.map +1 -0
- package/lib/mf/static.js +396 -0
- package/lib/mf/static.js.map +1 -0
- package/package.json +31 -0
- package/src/__tests__/index.test.jsx +109 -0
- package/src/__tests__/latex-bridge.test.js +151 -0
- package/src/__tests__/mathlive-instance.test.js +130 -0
- package/src/horizontal-keypad.jsx +73 -0
- package/src/index.jsx +63 -0
- package/src/keypad/index.jsx +335 -0
- package/src/keypad/keys-layout.js +16 -0
- package/src/keys/basic-operators.js +32 -0
- package/src/keys/chars.js +5 -0
- package/src/keys/comparison.js +28 -0
- package/src/keys/constants.js +35 -0
- package/src/keys/digits.js +40 -0
- package/src/keys/edit.js +3 -0
- package/src/keys/exponent.js +28 -0
- package/src/keys/fractions.js +26 -0
- package/src/keys/geometry.js +144 -0
- package/src/keys/grades.js +367 -0
- package/src/keys/index.js +20 -0
- package/src/keys/log.js +22 -0
- package/src/keys/logic.js +15 -0
- package/src/keys/matrices.js +15 -0
- package/src/keys/misc.js +65 -0
- package/src/keys/navigation.js +8 -0
- package/src/keys/operators.js +10 -0
- package/src/keys/statistics.js +38 -0
- package/src/keys/sub-sup.js +15 -0
- package/src/keys/trigonometry.js +15 -0
- package/src/keys/utils.js +66 -0
- package/src/keys/vars.js +19 -0
- package/src/latex-bridge.js +190 -0
- package/src/math-input.jsx +115 -0
- package/src/mathlive-instance.js +286 -0
- package/src/mf/common-styles.js +108 -0
- package/src/mf/index.js +26 -0
- package/src/mf/input.jsx +223 -0
- package/src/mf/static.jsx +358 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
11
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
12
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
13
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
+
var _react = _interopRequireDefault(require("react"));
|
|
15
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
16
|
+
var _grades = require("./keys/grades");
|
|
17
|
+
var _utils = require("./keys/utils");
|
|
18
|
+
var _keypad = _interopRequireDefault(require("./keypad"));
|
|
19
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
20
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
21
|
+
/**
|
|
22
|
+
* Maps a key definition to the legacy `{value, type}` shape that
|
|
23
|
+
* @pie-lib/math-toolbar consumes. Unchanged from the MathQuill implementation:
|
|
24
|
+
* the shape is part of the 4.x-compatible contract, and translation to MathLive
|
|
25
|
+
* happens later, in `latex-bridge.keyToAction`.
|
|
26
|
+
*/
|
|
27
|
+
var toOldModel = function toOldModel(d) {
|
|
28
|
+
if (d.command) {
|
|
29
|
+
return {
|
|
30
|
+
value: d.command,
|
|
31
|
+
type: 'command'
|
|
32
|
+
};
|
|
33
|
+
} else if (d.write) {
|
|
34
|
+
return {
|
|
35
|
+
value: d.write
|
|
36
|
+
};
|
|
37
|
+
} else if (d.keystroke) {
|
|
38
|
+
return {
|
|
39
|
+
type: 'cursor',
|
|
40
|
+
value: d.keystroke
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var HorizontalKeypad = exports["default"] = /*#__PURE__*/function (_React$Component) {
|
|
45
|
+
function HorizontalKeypad() {
|
|
46
|
+
var _this;
|
|
47
|
+
(0, _classCallCheck2["default"])(this, HorizontalKeypad);
|
|
48
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
49
|
+
args[_key] = arguments[_key];
|
|
50
|
+
}
|
|
51
|
+
_this = _callSuper(this, HorizontalKeypad, [].concat(args));
|
|
52
|
+
(0, _defineProperty2["default"])(_this, "keypadPress", function (data) {
|
|
53
|
+
_this.props.onClick(toOldModel(data));
|
|
54
|
+
});
|
|
55
|
+
return _this;
|
|
56
|
+
}
|
|
57
|
+
(0, _inherits2["default"])(HorizontalKeypad, _React$Component);
|
|
58
|
+
return (0, _createClass2["default"])(HorizontalKeypad, [{
|
|
59
|
+
key: "render",
|
|
60
|
+
value: function render() {
|
|
61
|
+
var _this$props = this.props,
|
|
62
|
+
mode = _this$props.mode,
|
|
63
|
+
onFocus = _this$props.onFocus,
|
|
64
|
+
controlledKeypadMode = _this$props.controlledKeypadMode,
|
|
65
|
+
noDecimal = _this$props.noDecimal,
|
|
66
|
+
className = _this$props.className,
|
|
67
|
+
additionalKeys = _this$props.additionalKeys,
|
|
68
|
+
layoutForKeyPad = _this$props.layoutForKeyPad,
|
|
69
|
+
setKeypadInteraction = _this$props.setKeypadInteraction;
|
|
70
|
+
var normalizedKeys = (0, _grades.normalizeAdditionalKeys)(additionalKeys);
|
|
71
|
+
return /*#__PURE__*/_react["default"].createElement(_keypad["default"], {
|
|
72
|
+
className: className,
|
|
73
|
+
controlledKeypadMode: controlledKeypadMode,
|
|
74
|
+
onFocus: onFocus,
|
|
75
|
+
noDecimal: noDecimal,
|
|
76
|
+
layoutForKeyPad: layoutForKeyPad,
|
|
77
|
+
additionalKeys: (0, _utils.extendKeySet)((0, _grades.keysForGrade)(mode), normalizedKeys),
|
|
78
|
+
onPress: this.keypadPress,
|
|
79
|
+
mode: mode,
|
|
80
|
+
setKeypadInteraction: setKeypadInteraction
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}]);
|
|
84
|
+
}(_react["default"].Component);
|
|
85
|
+
(0, _defineProperty2["default"])(HorizontalKeypad, "propTypes", {
|
|
86
|
+
className: _propTypes["default"].string,
|
|
87
|
+
controlledKeypadMode: _propTypes["default"].bool,
|
|
88
|
+
mode: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
|
|
89
|
+
layoutForKeyPad: _propTypes["default"].object,
|
|
90
|
+
onClick: _propTypes["default"].func.isRequired,
|
|
91
|
+
onFocus: _propTypes["default"].func,
|
|
92
|
+
noDecimal: _propTypes["default"].bool,
|
|
93
|
+
additionalKeys: _propTypes["default"].array,
|
|
94
|
+
setKeypadInteraction: _propTypes["default"].func
|
|
95
|
+
});
|
|
96
|
+
(0, _defineProperty2["default"])(HorizontalKeypad, "defaultProps", {
|
|
97
|
+
mode: 'scientific',
|
|
98
|
+
noDecimal: false,
|
|
99
|
+
additionalKeys: []
|
|
100
|
+
});
|
|
101
|
+
//# sourceMappingURL=horizontal-keypad.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"horizontal-keypad.js","names":["_react","_interopRequireDefault","require","_propTypes","_grades","_utils","_keypad","_callSuper","t","o","e","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","apply","Boolean","prototype","valueOf","call","toOldModel","d","command","value","type","write","keystroke","HorizontalKeypad","exports","_React$Component","_this","_classCallCheck2","_len","arguments","length","args","Array","_key","concat","_defineProperty2","data","props","onClick","_inherits2","_createClass2","key","render","_this$props","mode","onFocus","controlledKeypadMode","noDecimal","className","additionalKeys","layoutForKeyPad","setKeypadInteraction","normalizedKeys","normalizeAdditionalKeys","createElement","extendKeySet","keysForGrade","onPress","keypadPress","React","Component","PropTypes","string","bool","oneOfType","number","object","func","isRequired","array"],"sources":["../src/horizontal-keypad.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { keysForGrade, normalizeAdditionalKeys } from './keys/grades';\nimport { extendKeySet } from './keys/utils';\nimport Keypad from './keypad';\n\n/**\n * Maps a key definition to the legacy `{value, type}` shape that\n * @pie-lib/math-toolbar consumes. Unchanged from the MathQuill implementation:\n * the shape is part of the 4.x-compatible contract, and translation to MathLive\n * happens later, in `latex-bridge.keyToAction`.\n */\nconst toOldModel = (d) => {\n if (d.command) {\n return { value: d.command, type: 'command' };\n } else if (d.write) {\n return { value: d.write };\n } else if (d.keystroke) {\n return { type: 'cursor', value: d.keystroke };\n }\n};\n\nexport default class HorizontalKeypad extends React.Component {\n static propTypes = {\n className: PropTypes.string,\n controlledKeypadMode: PropTypes.bool,\n mode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n layoutForKeyPad: PropTypes.object,\n onClick: PropTypes.func.isRequired,\n onFocus: PropTypes.func,\n noDecimal: PropTypes.bool,\n additionalKeys: PropTypes.array,\n setKeypadInteraction: PropTypes.func,\n };\n\n static defaultProps = {\n mode: 'scientific',\n noDecimal: false,\n additionalKeys: [],\n };\n\n keypadPress = (data) => {\n this.props.onClick(toOldModel(data));\n };\n\n render() {\n const {\n mode,\n onFocus,\n controlledKeypadMode,\n noDecimal,\n className,\n additionalKeys,\n layoutForKeyPad,\n setKeypadInteraction,\n } = this.props;\n const normalizedKeys = normalizeAdditionalKeys(additionalKeys);\n\n return (\n <Keypad\n className={className}\n controlledKeypadMode={controlledKeypadMode}\n onFocus={onFocus}\n noDecimal={noDecimal}\n layoutForKeyPad={layoutForKeyPad}\n additionalKeys={extendKeySet(keysForGrade(mode), normalizedKeys)}\n onPress={this.keypadPress}\n mode={mode}\n setKeypadInteraction={setKeypadInteraction}\n />\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAL,sBAAA,CAAAC,OAAA;AAA8B,SAAAK,WAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,WAAAD,CAAA,OAAAE,gBAAA,aAAAF,CAAA,OAAAG,2BAAA,aAAAJ,CAAA,EAAAK,yBAAA,KAAAC,OAAA,CAAAC,SAAA,CAAAN,CAAA,EAAAC,CAAA,YAAAC,gBAAA,aAAAH,CAAA,EAAAQ,WAAA,IAAAP,CAAA,CAAAQ,KAAA,CAAAT,CAAA,EAAAE,CAAA;AAAA,SAAAG,0BAAA,cAAAL,CAAA,IAAAU,OAAA,CAAAC,SAAA,CAAAC,OAAA,CAAAC,IAAA,CAAAP,OAAA,CAAAC,SAAA,CAAAG,OAA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AEgB,qBAAS,CAACM,IAAI;EACvBpB,SAAS,EAAEc,qBAAS,CAACE,IAAI;EACzBd,cAAc,EAAEY,qBAAS,CAACQ,KAAK;EAC/BlB,oBAAoB,EAAEU,qBAAS,CAACM;AAClC,CAAC;AAAA,IAAAhC,gBAAA,aAXkBZ,gBAAgB,kBAab;EACpBqB,IAAI,EAAE,YAAY;EAClBG,SAAS,EAAE,KAAK;EAChBE,cAAc,EAAE;AAClB,CAAC","ignoreList":[]}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "HorizontalKeypad", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _horizontalKeypad["default"];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "KeyPad", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _keypad["default"];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "MathInput", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function get() {
|
|
23
|
+
return _mathInput["default"];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(exports, "NEWLINE_EMBED", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function get() {
|
|
29
|
+
return _latexBridge.NEWLINE_EMBED;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "PIE_MACROS", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _mathliveInstance.PIE_MACROS;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
exports.addBrackets = void 0;
|
|
39
|
+
Object.defineProperty(exports, "applyStaticMath", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function get() {
|
|
42
|
+
return _mathliveInstance.applyStaticMath;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "configureFonts", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function get() {
|
|
48
|
+
return _mathliveInstance.configureFonts;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "fromMathLive", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function get() {
|
|
54
|
+
return _latexBridge.fromMathLive;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, "getMacros", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function get() {
|
|
60
|
+
return _mathliveInstance.getMacros;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(exports, "keyToAction", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function get() {
|
|
66
|
+
return _latexBridge.keyToAction;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
exports.keys = void 0;
|
|
70
|
+
Object.defineProperty(exports, "keysForGrade", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function get() {
|
|
73
|
+
return _grades.keysForGrade;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(exports, "latexToMarkup", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function get() {
|
|
79
|
+
return _mathliveInstance.latexToMarkup;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(exports, "loadMathLive", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get: function get() {
|
|
85
|
+
return _mathliveInstance.loadMathLive;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
exports.mq = exports.mf = void 0;
|
|
89
|
+
Object.defineProperty(exports, "registerEmbed", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function get() {
|
|
92
|
+
return _mathliveInstance.registerEmbed;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
exports.removeBrackets = void 0;
|
|
96
|
+
Object.defineProperty(exports, "toMathLive", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get: function get() {
|
|
99
|
+
return _latexBridge.toMathLive;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
exports.updateSpans = void 0;
|
|
103
|
+
var _grades = require("./keys/grades");
|
|
104
|
+
var keys = _interopRequireWildcard(require("./keys"));
|
|
105
|
+
exports.keys = keys;
|
|
106
|
+
var _mathInput = _interopRequireDefault(require("./math-input"));
|
|
107
|
+
var _horizontalKeypad = _interopRequireDefault(require("./horizontal-keypad"));
|
|
108
|
+
var _keypad = _interopRequireDefault(require("./keypad"));
|
|
109
|
+
var mf = _interopRequireWildcard(require("./mf"));
|
|
110
|
+
exports.mf = mf;
|
|
111
|
+
exports.mq = mf;
|
|
112
|
+
var _mathliveInstance = require("./mathlive-instance");
|
|
113
|
+
var _latexBridge = require("./latex-bridge");
|
|
114
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
115
|
+
var addLeftBracket = function addLeftBracket(s) {
|
|
116
|
+
return s.indexOf('\\(') === 0 ? s : "\\(".concat(s);
|
|
117
|
+
};
|
|
118
|
+
var addRightBracket = function addRightBracket(s) {
|
|
119
|
+
return s.indexOf('\\)') === s.length - 2 ? s : "".concat(s, "\\)");
|
|
120
|
+
};
|
|
121
|
+
var rmLeftBracket = function rmLeftBracket(s) {
|
|
122
|
+
return s.indexOf('\\(') === 0 ? s.substring(2) : s;
|
|
123
|
+
};
|
|
124
|
+
var rmRightBracket = function rmRightBracket(s) {
|
|
125
|
+
return s.indexOf('\\)') === s.length - 2 ? s.substring(0, s.length - 2) : s;
|
|
126
|
+
};
|
|
127
|
+
var addBrackets = exports.addBrackets = function addBrackets(s) {
|
|
128
|
+
return addRightBracket(addLeftBracket(s));
|
|
129
|
+
};
|
|
130
|
+
var removeBrackets = exports.removeBrackets = function removeBrackets(s) {
|
|
131
|
+
return rmRightBracket(rmLeftBracket(s));
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* `updateSpans` is intentionally a no-op.
|
|
136
|
+
*
|
|
137
|
+
* In @pie-lib/math-input it patched MathQuill's rendered DOM by walking
|
|
138
|
+
* `span[mathquill-command-id]` to resize the parallel glyph and tag primes.
|
|
139
|
+
* MathLive emits none of those attributes and does not need the fixups, but the
|
|
140
|
+
* export is kept so callers do not break.
|
|
141
|
+
*/
|
|
142
|
+
var updateSpans = exports.updateSpans = function updateSpans() {};
|
|
143
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_grades","require","keys","_interopRequireWildcard","exports","_mathInput","_interopRequireDefault","_horizontalKeypad","_keypad","mf","mq","_mathliveInstance","_latexBridge","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","addLeftBracket","s","indexOf","concat","addRightBracket","length","rmLeftBracket","substring","rmRightBracket","addBrackets","removeBrackets","updateSpans"],"sources":["../src/index.jsx"],"sourcesContent":["import { keysForGrade } from './keys/grades';\nimport * as keys from './keys';\n\nimport MathInput from './math-input';\nimport HorizontalKeypad from './horizontal-keypad';\nimport KeyPad from './keypad';\n\nimport * as mf from './mf';\nimport {\n registerEmbed,\n applyStaticMath,\n latexToMarkup,\n loadMathLive,\n configureFonts,\n getMacros,\n PIE_MACROS,\n} from './mathlive-instance';\nimport { toMathLive, fromMathLive, keyToAction, NEWLINE_EMBED } from './latex-bridge';\n\nconst addLeftBracket = (s) => (s.indexOf('\\\\(') === 0 ? s : `\\\\(${s}`);\nconst addRightBracket = (s) => (s.indexOf('\\\\)') === s.length - 2 ? s : `${s}\\\\)`);\nconst rmLeftBracket = (s) => (s.indexOf('\\\\(') === 0 ? s.substring(2) : s);\nconst rmRightBracket = (s) => (s.indexOf('\\\\)') === s.length - 2 ? s.substring(0, s.length - 2) : s);\n\nconst addBrackets = (s) => addRightBracket(addLeftBracket(s));\nconst removeBrackets = (s) => rmRightBracket(rmLeftBracket(s));\n\n/**\n * `updateSpans` is intentionally a no-op.\n *\n * In @pie-lib/math-input it patched MathQuill's rendered DOM by walking\n * `span[mathquill-command-id]` to resize the parallel glyph and tag primes.\n * MathLive emits none of those attributes and does not need the fixups, but the\n * export is kept so callers do not break.\n */\nconst updateSpans = () => {};\n\nexport {\n keysForGrade,\n addBrackets,\n removeBrackets,\n keys,\n MathInput,\n HorizontalKeypad,\n KeyPad,\n updateSpans,\n // `mf` is the MathLive equivalent of math-input's `mq`. Both names are\n // exported so a consumer can switch packages by changing only the import.\n mf,\n mf as mq,\n registerEmbed,\n applyStaticMath,\n // MathLive-specific additions\n latexToMarkup,\n loadMathLive,\n configureFonts,\n getMacros,\n PIE_MACROS,\n toMathLive,\n fromMathLive,\n keyToAction,\n NEWLINE_EMBED,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,O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CAAC,CAAC;AAAA;;AAE9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMU,WAAW,GAAAxC,OAAA,CAAAwC,WAAA,GAAG,SAAdA,WAAWA,CAAA,EAAS,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = exports.LatexLabel = exports.KeyPad = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
14
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
15
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
16
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
|
+
var _react = _interopRequireDefault(require("react"));
|
|
19
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
20
|
+
var _Button = _interopRequireDefault(require("@mui/material/Button"));
|
|
21
|
+
var _IconButton = _interopRequireDefault(require("@mui/material/IconButton"));
|
|
22
|
+
var _styles = require("@mui/material/styles");
|
|
23
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
24
|
+
var _lodashEs = require("lodash-es");
|
|
25
|
+
var _renderUi = require("@pie-lib/render-ui");
|
|
26
|
+
var _keys = require("../keys");
|
|
27
|
+
var _keysLayout = require("./keys-layout");
|
|
28
|
+
var _commonStyles = require("../mf/common-styles");
|
|
29
|
+
var _mathliveInstance = require("../mathlive-instance");
|
|
30
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
31
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
32
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
33
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
34
|
+
var log = (0, _debug["default"])('pie-lib:math-input-mathlive:keypad');
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A LaTeX keypad label.
|
|
38
|
+
*
|
|
39
|
+
* The MathQuill implementation rendered every LaTeX label as its own
|
|
40
|
+
* `MQ.StaticMath` instance. Here each label is static HTML produced once by
|
|
41
|
+
* `convertLatexToMarkup`, so a 40-key keypad no longer creates 40 live math
|
|
42
|
+
* instances.
|
|
43
|
+
*/
|
|
44
|
+
var LabelHolder = (0, _styles.styled)('span')({
|
|
45
|
+
pointerEvents: 'none',
|
|
46
|
+
textTransform: 'none',
|
|
47
|
+
color: _renderUi.color.text(),
|
|
48
|
+
display: 'inline-flex',
|
|
49
|
+
alignItems: 'center',
|
|
50
|
+
justifyContent: 'center',
|
|
51
|
+
lineHeight: 1,
|
|
52
|
+
// Answer-block / empty-slot boxes inside a label.
|
|
53
|
+
'& .ML__placeholder': {
|
|
54
|
+
backgroundColor: _renderUi.color.keypadEmptyPlaceholder()
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
var LatexLabel = exports.LatexLabel = /*#__PURE__*/function (_React$Component) {
|
|
58
|
+
function LatexLabel(props) {
|
|
59
|
+
var _this;
|
|
60
|
+
(0, _classCallCheck2["default"])(this, LatexLabel);
|
|
61
|
+
_this = _callSuper(this, LatexLabel, [props]);
|
|
62
|
+
_this.state = {
|
|
63
|
+
markup: (0, _mathliveInstance.latexToMarkup)(props.latex)
|
|
64
|
+
};
|
|
65
|
+
return _this;
|
|
66
|
+
}
|
|
67
|
+
(0, _inherits2["default"])(LatexLabel, _React$Component);
|
|
68
|
+
return (0, _createClass2["default"])(LatexLabel, [{
|
|
69
|
+
key: "componentDidMount",
|
|
70
|
+
value: function () {
|
|
71
|
+
var _componentDidMount = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
72
|
+
return _regenerator["default"].wrap(function (_context) {
|
|
73
|
+
while (1) switch (_context.prev = _context.next) {
|
|
74
|
+
case 0:
|
|
75
|
+
if (this.state.markup) {
|
|
76
|
+
_context.next = 2;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
_context.next = 1;
|
|
80
|
+
return (0, _mathliveInstance.loadMathLive)();
|
|
81
|
+
case 1:
|
|
82
|
+
if (!this.unmounted) {
|
|
83
|
+
this.setState({
|
|
84
|
+
markup: (0, _mathliveInstance.latexToMarkup)(this.props.latex)
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
case 2:
|
|
88
|
+
case "end":
|
|
89
|
+
return _context.stop();
|
|
90
|
+
}
|
|
91
|
+
}, _callee, this);
|
|
92
|
+
}));
|
|
93
|
+
function componentDidMount() {
|
|
94
|
+
return _componentDidMount.apply(this, arguments);
|
|
95
|
+
}
|
|
96
|
+
return componentDidMount;
|
|
97
|
+
}()
|
|
98
|
+
}, {
|
|
99
|
+
key: "componentDidUpdate",
|
|
100
|
+
value: function componentDidUpdate(prevProps) {
|
|
101
|
+
if (prevProps.latex !== this.props.latex) {
|
|
102
|
+
this.setState({
|
|
103
|
+
markup: (0, _mathliveInstance.latexToMarkup)(this.props.latex)
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}, {
|
|
108
|
+
key: "componentWillUnmount",
|
|
109
|
+
value: function componentWillUnmount() {
|
|
110
|
+
this.unmounted = true;
|
|
111
|
+
}
|
|
112
|
+
}, {
|
|
113
|
+
key: "render",
|
|
114
|
+
value: function render() {
|
|
115
|
+
var markup = this.state.markup;
|
|
116
|
+
|
|
117
|
+
// Fall back to the raw latex so a button is never blank.
|
|
118
|
+
return markup ?
|
|
119
|
+
/*#__PURE__*/
|
|
120
|
+
// eslint-disable-next-line react/no-danger
|
|
121
|
+
_react["default"].createElement(LabelHolder, {
|
|
122
|
+
dangerouslySetInnerHTML: {
|
|
123
|
+
__html: markup
|
|
124
|
+
}
|
|
125
|
+
}) : /*#__PURE__*/_react["default"].createElement(LabelHolder, null, this.props.latex);
|
|
126
|
+
}
|
|
127
|
+
}]);
|
|
128
|
+
}(_react["default"].Component);
|
|
129
|
+
(0, _defineProperty2["default"])(LatexLabel, "propTypes", {
|
|
130
|
+
latex: _propTypes["default"].string.isRequired
|
|
131
|
+
});
|
|
132
|
+
var createCustomLayout = function createCustomLayout(layoutObj) {
|
|
133
|
+
if (layoutObj) {
|
|
134
|
+
return {
|
|
135
|
+
gridTemplateColumns: "repeat(".concat(layoutObj.columns, ", minmax(min-content, 150px))"),
|
|
136
|
+
gridTemplateRows: "repeat(".concat(layoutObj.rows, ", minmax(40px, 60px))"),
|
|
137
|
+
gridAutoFlow: 'initial'
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return {};
|
|
141
|
+
};
|
|
142
|
+
var KeyPadContainer = (0, _styles.styled)('div')(function () {
|
|
143
|
+
return _objectSpread(_objectSpread({}, _commonStyles.commonKeyboardStyles), {}, {
|
|
144
|
+
width: '100%',
|
|
145
|
+
display: 'grid',
|
|
146
|
+
gridTemplateRows: 'repeat(5, minmax(40px, 60px))',
|
|
147
|
+
gridRowGap: '0px',
|
|
148
|
+
gridColumnGap: '0px',
|
|
149
|
+
gridAutoFlow: 'column',
|
|
150
|
+
'&.character': {
|
|
151
|
+
textTransform: 'initial !important',
|
|
152
|
+
gridTemplateRows: 'repeat(5, minmax(40px, 50px)) !important'
|
|
153
|
+
},
|
|
154
|
+
'&.language': {
|
|
155
|
+
gridTemplateRows: 'repeat(4, minmax(40px, 50px)) !important',
|
|
156
|
+
'& *': {
|
|
157
|
+
fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important'
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
var buttonBackground = function buttonBackground(category) {
|
|
163
|
+
return {
|
|
164
|
+
backgroundColor: category === 'operators' ? _renderUi.color.keypadButtonOperator() : _renderUi.color.keypadButton(),
|
|
165
|
+
'&:hover': {
|
|
166
|
+
backgroundColor: category === 'operators' ? _renderUi.color.keypadButtonOperatorHover() : _renderUi.color.keypadButtonHover()
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
var StyledButton = (0, _styles.styled)(_Button["default"])(function (_ref) {
|
|
171
|
+
var category = _ref.category,
|
|
172
|
+
isDelete = _ref.isDelete,
|
|
173
|
+
isComma = _ref.isComma,
|
|
174
|
+
isDot = _ref.isDot;
|
|
175
|
+
return _objectSpread(_objectSpread({
|
|
176
|
+
minWidth: 'auto',
|
|
177
|
+
textTransform: 'none',
|
|
178
|
+
fontSize: isComma || isDot ? '200% !important' : '140% !important',
|
|
179
|
+
lineHeight: isComma || isDot ? '100%' : 'normal',
|
|
180
|
+
color: _renderUi.color.text()
|
|
181
|
+
}, buttonBackground(category)), {}, {
|
|
182
|
+
borderRadius: 0
|
|
183
|
+
}, isDelete && {
|
|
184
|
+
fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important'
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
var StyledLatexButtonWrapper = (0, _styles.styled)(_Button["default"])(function (_ref2) {
|
|
188
|
+
var category = _ref2.category;
|
|
189
|
+
return _objectSpread({
|
|
190
|
+
textTransform: 'none',
|
|
191
|
+
padding: 0,
|
|
192
|
+
margin: 0,
|
|
193
|
+
fontSize: '110% !important',
|
|
194
|
+
minWidth: 'auto',
|
|
195
|
+
borderRadius: 0
|
|
196
|
+
}, buttonBackground(category));
|
|
197
|
+
});
|
|
198
|
+
var StyledIconButton = (0, _styles.styled)(_IconButton["default"])(function (_ref3) {
|
|
199
|
+
var category = _ref3.category;
|
|
200
|
+
return _objectSpread(_objectSpread({
|
|
201
|
+
minWidth: 'auto'
|
|
202
|
+
}, buttonBackground(category)), {}, {
|
|
203
|
+
borderRadius: 0,
|
|
204
|
+
'& .icon': {
|
|
205
|
+
height: '30px'
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
var KeyPad = exports.KeyPad = /*#__PURE__*/function (_React$Component2) {
|
|
210
|
+
function KeyPad(props) {
|
|
211
|
+
var _this2;
|
|
212
|
+
(0, _classCallCheck2["default"])(this, KeyPad);
|
|
213
|
+
_this2 = _callSuper(this, KeyPad, [props]);
|
|
214
|
+
(0, _defineProperty2["default"])(_this2, "handleKeypadInteraction", function () {
|
|
215
|
+
if (_this2.props.setKeypadInteraction) {
|
|
216
|
+
_this2.props.setKeypadInteraction(true);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
(0, _defineProperty2["default"])(_this2, "buttonClick", function (key) {
|
|
220
|
+
log('[buttonClick]', key);
|
|
221
|
+
_this2.props.onPress(key);
|
|
222
|
+
});
|
|
223
|
+
(0, _defineProperty2["default"])(_this2, "flowKeys", function (base, extras) {
|
|
224
|
+
return (0, _lodashEs.flatten)([].concat((0, _toConsumableArray2["default"])((0, _keysLayout.sortKeys)(base)), (0, _toConsumableArray2["default"])((0, _keysLayout.sortKeys)(extras))));
|
|
225
|
+
});
|
|
226
|
+
(0, _defineProperty2["default"])(_this2, "keyIsNotAllowed", function (key) {
|
|
227
|
+
var noDecimal = _this2.props.noDecimal;
|
|
228
|
+
return !!((key.write === '.' && key.label === '.' || key.write === ',' && key.label === ',') && noDecimal);
|
|
229
|
+
});
|
|
230
|
+
_this2.keypadRef = /*#__PURE__*/_react["default"].createRef();
|
|
231
|
+
return _this2;
|
|
232
|
+
}
|
|
233
|
+
(0, _inherits2["default"])(KeyPad, _React$Component2);
|
|
234
|
+
return (0, _createClass2["default"])(KeyPad, [{
|
|
235
|
+
key: "componentDidMount",
|
|
236
|
+
value: function componentDidMount() {
|
|
237
|
+
var _this$keypadRef;
|
|
238
|
+
// Ensure MathLive is available for the LaTeX labels.
|
|
239
|
+
(0, _mathliveInstance.loadMathLive)();
|
|
240
|
+
var keyPadElement = (_this$keypadRef = this.keypadRef) === null || _this$keypadRef === void 0 ? void 0 : _this$keypadRef.current;
|
|
241
|
+
var mainContainer = keyPadElement === null || keyPadElement === void 0 ? void 0 : keyPadElement.closest('.main-container');
|
|
242
|
+
var currentToolbar = keyPadElement === null || keyPadElement === void 0 ? void 0 : keyPadElement.closest('.pie-toolbar');
|
|
243
|
+
|
|
244
|
+
// need only for math keyboard so we need also controlledKeypadMode
|
|
245
|
+
if (this.props.controlledKeypadMode && mainContainer && currentToolbar) {
|
|
246
|
+
var mainContainerPosition = mainContainer.getBoundingClientRect();
|
|
247
|
+
var currentToolbarPosition = currentToolbar.getBoundingClientRect();
|
|
248
|
+
var difference = mainContainerPosition.top + mainContainerPosition.height - (currentToolbarPosition.top + currentToolbarPosition.height);
|
|
249
|
+
if (difference < 0) {
|
|
250
|
+
var totalHeight = mainContainerPosition.height + mainContainerPosition.top - difference;
|
|
251
|
+
mainContainer.style.height = "".concat(totalHeight, "px");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (keyPadElement) {
|
|
255
|
+
keyPadElement.addEventListener('touchstart', this.handleKeypadInteraction, true);
|
|
256
|
+
keyPadElement.addEventListener('mousedown', this.handleKeypadInteraction, true);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}, {
|
|
260
|
+
key: "componentWillUnmount",
|
|
261
|
+
value: function componentWillUnmount() {
|
|
262
|
+
var _this$keypadRef2;
|
|
263
|
+
var keyPadElement = (_this$keypadRef2 = this.keypadRef) === null || _this$keypadRef2 === void 0 ? void 0 : _this$keypadRef2.current;
|
|
264
|
+
if (this.props.controlledKeypadMode && keyPadElement) {
|
|
265
|
+
var mainContainer = keyPadElement.closest('.main-container');
|
|
266
|
+
if (mainContainer) {
|
|
267
|
+
mainContainer.style.height = 'unset';
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (keyPadElement) {
|
|
271
|
+
keyPadElement.removeEventListener('touchstart', this.handleKeypadInteraction, true);
|
|
272
|
+
keyPadElement.removeEventListener('mousedown', this.handleKeypadInteraction, true);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}, {
|
|
276
|
+
key: "render",
|
|
277
|
+
value: function render() {
|
|
278
|
+
var _this3 = this;
|
|
279
|
+
var _this$props = this.props,
|
|
280
|
+
className = _this$props.className,
|
|
281
|
+
base = _this$props.baseSet,
|
|
282
|
+
additionalKeys = _this$props.additionalKeys,
|
|
283
|
+
layoutForKeyPad = _this$props.layoutForKeyPad,
|
|
284
|
+
onFocus = _this$props.onFocus,
|
|
285
|
+
mode = _this$props.mode;
|
|
286
|
+
var noBaseSet = ['non-negative-integers', 'integers', 'decimals', 'fractions', 'item-authoring', 'language'];
|
|
287
|
+
var keysWithoutBaseSet = noBaseSet.includes(mode);
|
|
288
|
+
var allKeys = keysWithoutBaseSet ? this.flowKeys([], additionalKeys || []) : this.flowKeys(base, additionalKeys || []);
|
|
289
|
+
var shift = allKeys.length % 5 ? 1 : 0;
|
|
290
|
+
var style = _objectSpread({
|
|
291
|
+
gridTemplateColumns: "repeat(".concat(Math.floor(allKeys.length / 5) + shift, ", minmax(min-content, 150px))")
|
|
292
|
+
}, createCustomLayout(layoutForKeyPad));
|
|
293
|
+
return /*#__PURE__*/_react["default"].createElement(KeyPadContainer, {
|
|
294
|
+
ref: this.keypadRef,
|
|
295
|
+
className: [className, mode].filter(Boolean).join(' '),
|
|
296
|
+
style: style,
|
|
297
|
+
onFocus: onFocus
|
|
298
|
+
}, allKeys.map(function (k, index) {
|
|
299
|
+
if (!k) {
|
|
300
|
+
return /*#__PURE__*/_react["default"].createElement("span", {
|
|
301
|
+
key: "empty-".concat(index)
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
var key = "".concat(k.label || k.latex || k.command, "-").concat(index);
|
|
305
|
+
var category = !keysWithoutBaseSet ? k.category : undefined;
|
|
306
|
+
var extra = _objectSpread(_objectSpread({}, k.actions || {}), k.extraProps || {});
|
|
307
|
+
var onClick = _this3.buttonClick.bind(_this3, k);
|
|
308
|
+
var disabled = _this3.keyIsNotAllowed(k);
|
|
309
|
+
var ariaLabel = k.ariaLabel ? k.ariaLabel : k.name || k.label;
|
|
310
|
+
if (k.latex) {
|
|
311
|
+
return /*#__PURE__*/_react["default"].createElement(StyledLatexButtonWrapper, (0, _extends2["default"])({
|
|
312
|
+
key: key,
|
|
313
|
+
onClick: onClick,
|
|
314
|
+
disabled: disabled,
|
|
315
|
+
category: category,
|
|
316
|
+
"aria-label": ariaLabel
|
|
317
|
+
}, extra), /*#__PURE__*/_react["default"].createElement(LatexLabel, {
|
|
318
|
+
latex: k.latex
|
|
319
|
+
}));
|
|
320
|
+
}
|
|
321
|
+
if (k.label) {
|
|
322
|
+
return /*#__PURE__*/_react["default"].createElement(StyledButton, (0, _extends2["default"])({
|
|
323
|
+
key: key,
|
|
324
|
+
onClick: onClick,
|
|
325
|
+
disabled: disabled,
|
|
326
|
+
category: category,
|
|
327
|
+
isDelete: k.label === '⌫',
|
|
328
|
+
isComma: k.label === ',',
|
|
329
|
+
isDot: k.label === '.',
|
|
330
|
+
"aria-label": ariaLabel
|
|
331
|
+
}, extra), k.label);
|
|
332
|
+
}
|
|
333
|
+
var Icon = k.icon ? k.icon : 'div';
|
|
334
|
+
return /*#__PURE__*/_react["default"].createElement(StyledIconButton, (0, _extends2["default"])({
|
|
335
|
+
key: key,
|
|
336
|
+
tabIndex: '-1',
|
|
337
|
+
onClick: onClick,
|
|
338
|
+
disabled: disabled,
|
|
339
|
+
category: category,
|
|
340
|
+
size: "large"
|
|
341
|
+
}, extra), /*#__PURE__*/_react["default"].createElement(Icon, {
|
|
342
|
+
className: "icon"
|
|
343
|
+
}));
|
|
344
|
+
}));
|
|
345
|
+
}
|
|
346
|
+
}]);
|
|
347
|
+
}(_react["default"].Component);
|
|
348
|
+
(0, _defineProperty2["default"])(KeyPad, "propTypes", {
|
|
349
|
+
className: _propTypes["default"].string,
|
|
350
|
+
controlledKeypadMode: _propTypes["default"].bool,
|
|
351
|
+
baseSet: _propTypes["default"].array,
|
|
352
|
+
additionalKeys: _propTypes["default"].array,
|
|
353
|
+
layoutForKeyPad: _propTypes["default"].object,
|
|
354
|
+
onPress: _propTypes["default"].func.isRequired,
|
|
355
|
+
onFocus: _propTypes["default"].func,
|
|
356
|
+
noDecimal: _propTypes["default"].bool,
|
|
357
|
+
setKeypadInteraction: _propTypes["default"].func,
|
|
358
|
+
mode: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number])
|
|
359
|
+
});
|
|
360
|
+
(0, _defineProperty2["default"])(KeyPad, "defaultProps", {
|
|
361
|
+
baseSet: _keys.baseSet,
|
|
362
|
+
noDecimal: false
|
|
363
|
+
});
|
|
364
|
+
var _default = exports["default"] = KeyPad;
|
|
365
|
+
//# sourceMappingURL=index.js.map
|