@pie-lib/math-input 6.8.1 → 6.8.2-next.140
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/lib/mq/input.js +0 -37
- package/lib/mq/input.js.map +1 -1
- package/package.json +2 -2
- package/src/mq/input.jsx +0 -35
package/lib/mq/input.js
CHANGED
|
@@ -104,43 +104,6 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
104
104
|
|
|
105
105
|
_this.onInputEdit();
|
|
106
106
|
}
|
|
107
|
-
|
|
108
|
-
if (event.charCode === 47) {
|
|
109
|
-
// Whenever the math editor cursor is positioned after an integer
|
|
110
|
-
// (i.e. a sequence of 1 or more digits) followed immediately by a space followed immediately by another integer,
|
|
111
|
-
// then a side effect of pressing the forward slash key or clicking the B fraction button should be to remove
|
|
112
|
-
// the space between the first integer and the second integer (which is now the numerator of a new fraction).
|
|
113
|
-
// E.g. if the user were trying to enter the mixed number one and two-thirds, and typed [1], [space], [2], [forward slash],
|
|
114
|
-
// producing the latex 1\ \frac{2}{|} (where | is not actually part of the representation, but rather
|
|
115
|
-
// represents the position of the cursor), this should be automatically transformed to 1\frac{2}{|}
|
|
116
|
-
// (with | again representing the position of the cursor).
|
|
117
|
-
// Similarly, if the user had typed [1], [2], [space], [3], [4], [forward slash], then the resulting representation should
|
|
118
|
-
// be transformed from 12\ \frac{34}{|} to 12\frac{34}{|}.
|
|
119
|
-
var latex = _this.mathField.latex();
|
|
120
|
-
|
|
121
|
-
if (latex.match(/([1-9])\\ /)) {
|
|
122
|
-
event.preventDefault();
|
|
123
|
-
event.stopPropagation();
|
|
124
|
-
|
|
125
|
-
_this.clear();
|
|
126
|
-
|
|
127
|
-
var indexOfSpace = latex.lastIndexOf('\\ '); // split the latex by the last space added
|
|
128
|
-
|
|
129
|
-
var firstPart = latex.slice(0, indexOfSpace);
|
|
130
|
-
var secondPart = latex.slice(indexOfSpace + 2); // reconstruct the latex without the extra space
|
|
131
|
-
|
|
132
|
-
var newLatex = firstPart + '\\frac{' + secondPart + '}{}';
|
|
133
|
-
|
|
134
|
-
_this.mathField.latex(newLatex); // trigger pressing keydown to move focus on the denominator
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
_this.mathField.el().dispatchEvent(new KeyboardEvent('keydown', {
|
|
138
|
-
keyCode: 37
|
|
139
|
-
}));
|
|
140
|
-
|
|
141
|
-
_this.onInputEdit();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
107
|
});
|
|
145
108
|
return _this;
|
|
146
109
|
}
|
package/lib/mq/input.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mq/input.jsx"],"names":["MQ","window","MathQuill","getInterface","registerEmbed","log","Input","onChange","props","mathField","latex","blur","focus","event","keys","Object","__controller","options","indexOf","refresh","charCode","write","onInputEdit","match","preventDefault","stopPropagation","clear","indexOfSpace","lastIndexOf","firstPart","slice","secondPart","newLatex","el","dispatchEvent","KeyboardEvent","keyCode","Error","MathField","input","handlers","edit","bind","updateLatex","v","Array","isArray","forEach","vv","cmd","keystroke","nextProps","onClick","onFocus","onBlur","classes","className","onKeyPress","r","React","Component","PropTypes","string","object","isRequired","func","styles"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAIA,EAAJ;;AACA,IAAI,OAAOC,MAAP,KAAkB,WAAtB,EAAmC;AACjCD,EAAAA,EAAE,GAAGE,sBAAUC,YAAV,CAAuB,CAAvB,CAAL;;AAEA,MAAIH,EAAE,IAAIA,EAAE,CAACI,aAAb,EAA4B;AAC1B,2CAAkBJ,EAAlB;AACD;AACF;;AAED,IAAMK,GAAG,GAAG,uBAAM,qBAAN,CAAZ;AAEA;AACA;AACA;;IACaC,K;;;;;;;;;;;;;;;oGAgFG,YAAM;AAClBD,MAAAA,GAAG,CAAC,mBAAD,CAAH;AACA,UAAQE,QAAR,GAAqB,MAAKC,KAA1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KC,UAFnB;AAGE,QAAA,OAAO,EAAEL,OAHX;AAIE,QAAA,OAAO,EAAEC,OAJX;AAKE,QAAA,MAAM,EAAEC,MALV;AAME,QAAA,GAAG,EAAE,aAAAI,CAAC;AAAA,iBAAK,MAAI,CAACnB,KAAL,GAAamB,CAAlB;AAAA;AANR,QADF;AAUD;;;EA1KwBC,kBAAMC,S;;;iCAApBtD,K,eACQ;AACjBkD,EAAAA,SAAS,EAAEK,sBAAUC,MADJ;AAEjBP,EAAAA,OAAO,EAAEM,sBAAUE,MAAV,CAAiBC,UAFT;AAGjBZ,EAAAA,OAAO,EAAES,sBAAUI,IAHF;AAIjB1D,EAAAA,QAAQ,EAAEsD,sBAAUI,IAJH;AAKjBvD,EAAAA,KAAK,EAAEmD,sBAAUC,MALA;AAMjBT,EAAAA,OAAO,EAAEQ,sBAAUI,IANF;AAOjBX,EAAAA,MAAM,EAAEO,sBAAUI;AAPD,C;;AA4KrB,IAAMC,MAAM,GAAG,SAATA,MAAS;AAAA,SAAO,EAAP;AAAA,CAAf;;eAEe,wBAAWA,MAAX,EAAmB5D,KAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport debug from 'debug';\nimport classNames from 'classnames';\nimport { registerLineBreak } from './custom-elements';\nimport MathQuill from '@pie-framework/mathquill';\n\nlet MQ;\nif (typeof window !== 'undefined') {\n MQ = MathQuill.getInterface(2);\n\n if (MQ && MQ.registerEmbed) {\n registerLineBreak(MQ);\n }\n}\n\nconst log = debug('math-input:mq:input');\n\n/**\n * Wrapper for MathQuill MQ.MathField.\n */\nexport class Input extends React.Component {\n static propTypes = {\n className: PropTypes.string,\n classes: PropTypes.object.isRequired,\n onClick: PropTypes.func,\n onChange: PropTypes.func,\n latex: PropTypes.string,\n onFocus: PropTypes.func,\n onBlur: PropTypes.func\n };\n\n componentDidMount() {\n if (!MQ) {\n throw new Error('MQ is not defined - but component has mounted?');\n }\n\n this.mathField = MQ.MathField(this.input, {\n handlers: {\n edit: this.onInputEdit.bind(this)\n }\n });\n\n this.updateLatex();\n }\n\n componentDidUpdate() {\n this.updateLatex();\n }\n\n updateLatex() {\n if (!this.mathField) {\n return;\n }\n const { latex } = this.props;\n if (latex) {\n this.mathField.latex(latex);\n }\n }\n\n clear() {\n this.mathField.latex('');\n return '';\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 command(v) {\n log('command: ', v);\n if (Array.isArray(v)) {\n v.forEach(vv => {\n this.mathField.cmd(vv);\n });\n } else {\n this.mathField.cmd(v);\n }\n this.mathField.focus();\n return this.mathField.latex();\n }\n\n keystroke(v) {\n this.mathField.keystroke(v);\n this.mathField.focus();\n return this.mathField.latex();\n }\n\n write(v) {\n log('write: ', v);\n this.mathField.write(v);\n this.mathField.focus();\n return this.mathField.latex();\n }\n\n onInputEdit = () => {\n log('[onInputEdit] ...');\n const { onChange } = this.props;\n if (!this.mathField) {\n return;\n }\n\n if (onChange) {\n onChange(this.mathField.latex());\n }\n };\n\n refresh = () => {\n this.blur();\n this.focus();\n };\n\n onKeyPress = event => {\n const keys = Object.keys(this.mathField.__controller.options);\n\n if (keys.indexOf('ignoreNextMousedown') < 0) {\n // It seems like the controller has the above handler as an option\n // when all the right events are set and everything works fine\n // this seems to work in all cases\n this.refresh();\n }\n\n if (event.charCode === 13) {\n // if enter's pressed, we're going for a custom embedded element that'll\n // have a block display (empty div) - for a hacked line break using ccs\n // all because mathquill doesn't support a line break\n this.write('\\\\embed{newLine}[]');\n this.onInputEdit();\n }\n\n if (event.charCode === 47) {\n // Whenever the math editor cursor is positioned after an integer\n // (i.e. a sequence of 1 or more digits) followed immediately by a space followed immediately by another integer,\n // then a side effect of pressing the forward slash key or clicking the B fraction button should be to remove\n // the space between the first integer and the second integer (which is now the numerator of a new fraction).\n // E.g. if the user were trying to enter the mixed number one and two-thirds, and typed [1], [space], [2], [forward slash],\n // producing the latex 1\\ \\frac{2}{|} (where | is not actually part of the representation, but rather\n // represents the position of the cursor), this should be automatically transformed to 1\\frac{2}{|}\n // (with | again representing the position of the cursor).\n // Similarly, if the user had typed [1], [2], [space], [3], [4], [forward slash], then the resulting representation should\n // be transformed from 12\\ \\frac{34}{|} to 12\\frac{34}{|}.\n const latex = this.mathField.latex();\n\n if (latex.match(/([1-9])\\\\ /)) {\n event.preventDefault();\n event.stopPropagation();\n\n this.clear();\n\n const indexOfSpace = latex.lastIndexOf('\\\\ ');\n // split the latex by the last space added\n const firstPart = latex.slice(0, indexOfSpace);\n const secondPart = latex.slice(indexOfSpace + 2);\n\n // reconstruct the latex without the extra space\n const newLatex = firstPart + '\\\\frac{' + secondPart + '}{}';\n\n this.mathField.latex(newLatex);\n // trigger pressing keydown to move focus on the denominator\n this.mathField.el().dispatchEvent(new KeyboardEvent('keydown', { keyCode: 37 }));\n\n this.onInputEdit();\n }\n }\n };\n\n shouldComponentUpdate(nextProps) {\n log('next: ', nextProps.latex);\n log('current: ', this.mathField.latex());\n return nextProps.latex !== this.mathField.latex();\n }\n\n render() {\n const { onClick, onFocus, onBlur, classes, className } = this.props;\n\n return (\n <span\n className={classNames(classes.input, className)}\n onKeyPress={this.onKeyPress}\n onClick={onClick}\n onFocus={onFocus}\n onBlur={onBlur}\n ref={r => (this.input = r)}\n />\n );\n }\n}\n\nconst styles = () => ({});\n\nexport default withStyles(styles)(Input);\n"],"file":"input.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/mq/input.jsx"],"names":["MQ","window","MathQuill","getInterface","registerEmbed","log","Input","onChange","props","mathField","latex","blur","focus","event","keys","Object","__controller","options","indexOf","refresh","charCode","write","onInputEdit","Error","MathField","input","handlers","edit","bind","updateLatex","v","Array","isArray","forEach","vv","cmd","keystroke","nextProps","onClick","onFocus","onBlur","classes","className","onKeyPress","r","React","Component","PropTypes","string","object","isRequired","func","styles"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA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jBzC,EAAAA,KAAK,EAAEqC,sBAAUC,MALA;AAMjBT,EAAAA,OAAO,EAAEQ,sBAAUI,IANF;AAOjBX,EAAAA,MAAM,EAAEO,sBAAUI;AAPD,C;;AAyIrB,IAAMC,MAAM,GAAG,SAATA,MAAS;AAAA,SAAO,EAAP;AAAA,CAAf;;eAEe,wBAAWA,MAAX,EAAmB9C,KAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport debug from 'debug';\nimport classNames from 'classnames';\nimport { registerLineBreak } from './custom-elements';\nimport MathQuill from '@pie-framework/mathquill';\n\nlet MQ;\nif (typeof window !== 'undefined') {\n MQ = MathQuill.getInterface(2);\n\n if (MQ && MQ.registerEmbed) {\n registerLineBreak(MQ);\n }\n}\n\nconst log = debug('math-input:mq:input');\n\n/**\n * Wrapper for MathQuill MQ.MathField.\n */\nexport class Input extends React.Component {\n static propTypes = {\n className: PropTypes.string,\n classes: PropTypes.object.isRequired,\n onClick: PropTypes.func,\n onChange: PropTypes.func,\n latex: PropTypes.string,\n onFocus: PropTypes.func,\n onBlur: PropTypes.func\n };\n\n componentDidMount() {\n if (!MQ) {\n throw new Error('MQ is not defined - but component has mounted?');\n }\n\n this.mathField = MQ.MathField(this.input, {\n handlers: {\n edit: this.onInputEdit.bind(this)\n }\n });\n\n this.updateLatex();\n }\n\n componentDidUpdate() {\n this.updateLatex();\n }\n\n updateLatex() {\n if (!this.mathField) {\n return;\n }\n const { latex } = this.props;\n if (latex) {\n this.mathField.latex(latex);\n }\n }\n\n clear() {\n this.mathField.latex('');\n return '';\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 command(v) {\n log('command: ', v);\n if (Array.isArray(v)) {\n v.forEach(vv => {\n this.mathField.cmd(vv);\n });\n } else {\n this.mathField.cmd(v);\n }\n this.mathField.focus();\n return this.mathField.latex();\n }\n\n keystroke(v) {\n this.mathField.keystroke(v);\n this.mathField.focus();\n return this.mathField.latex();\n }\n\n write(v) {\n log('write: ', v);\n this.mathField.write(v);\n this.mathField.focus();\n return this.mathField.latex();\n }\n\n onInputEdit = () => {\n log('[onInputEdit] ...');\n const { onChange } = this.props;\n if (!this.mathField) {\n return;\n }\n\n if (onChange) {\n onChange(this.mathField.latex());\n }\n };\n\n refresh = () => {\n this.blur();\n this.focus();\n };\n\n onKeyPress = event => {\n const keys = Object.keys(this.mathField.__controller.options);\n\n if (keys.indexOf('ignoreNextMousedown') < 0) {\n // It seems like the controller has the above handler as an option\n // when all the right events are set and everything works fine\n // this seems to work in all cases\n this.refresh();\n }\n\n if (event.charCode === 13) {\n // if enter's pressed, we're going for a custom embedded element that'll\n // have a block display (empty div) - for a hacked line break using ccs\n // all because mathquill doesn't support a line break\n this.write('\\\\embed{newLine}[]');\n this.onInputEdit();\n }\n };\n\n shouldComponentUpdate(nextProps) {\n log('next: ', nextProps.latex);\n log('current: ', this.mathField.latex());\n return nextProps.latex !== this.mathField.latex();\n }\n\n render() {\n const { onClick, onFocus, onBlur, classes, className } = this.props;\n\n return (\n <span\n className={classNames(classes.input, className)}\n onKeyPress={this.onKeyPress}\n onClick={onClick}\n onFocus={onFocus}\n onBlur={onBlur}\n ref={r => (this.input = r)}\n />\n );\n }\n}\n\nconst styles = () => ({});\n\nexport default withStyles(styles)(Input);\n"],"file":"input.js"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "6.8.
|
|
6
|
+
"version": "6.8.2-next.140+040c8b73",
|
|
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": "040c8b739fced2ea0cce2e593cb9e29b6f5b5130"
|
|
26
26
|
}
|
package/src/mq/input.jsx
CHANGED
|
@@ -134,41 +134,6 @@ export class Input extends React.Component {
|
|
|
134
134
|
this.write('\\embed{newLine}[]');
|
|
135
135
|
this.onInputEdit();
|
|
136
136
|
}
|
|
137
|
-
|
|
138
|
-
if (event.charCode === 47) {
|
|
139
|
-
// Whenever the math editor cursor is positioned after an integer
|
|
140
|
-
// (i.e. a sequence of 1 or more digits) followed immediately by a space followed immediately by another integer,
|
|
141
|
-
// then a side effect of pressing the forward slash key or clicking the B fraction button should be to remove
|
|
142
|
-
// the space between the first integer and the second integer (which is now the numerator of a new fraction).
|
|
143
|
-
// E.g. if the user were trying to enter the mixed number one and two-thirds, and typed [1], [space], [2], [forward slash],
|
|
144
|
-
// producing the latex 1\ \frac{2}{|} (where | is not actually part of the representation, but rather
|
|
145
|
-
// represents the position of the cursor), this should be automatically transformed to 1\frac{2}{|}
|
|
146
|
-
// (with | again representing the position of the cursor).
|
|
147
|
-
// Similarly, if the user had typed [1], [2], [space], [3], [4], [forward slash], then the resulting representation should
|
|
148
|
-
// be transformed from 12\ \frac{34}{|} to 12\frac{34}{|}.
|
|
149
|
-
const latex = this.mathField.latex();
|
|
150
|
-
|
|
151
|
-
if (latex.match(/([1-9])\\ /)) {
|
|
152
|
-
event.preventDefault();
|
|
153
|
-
event.stopPropagation();
|
|
154
|
-
|
|
155
|
-
this.clear();
|
|
156
|
-
|
|
157
|
-
const indexOfSpace = latex.lastIndexOf('\\ ');
|
|
158
|
-
// split the latex by the last space added
|
|
159
|
-
const firstPart = latex.slice(0, indexOfSpace);
|
|
160
|
-
const secondPart = latex.slice(indexOfSpace + 2);
|
|
161
|
-
|
|
162
|
-
// reconstruct the latex without the extra space
|
|
163
|
-
const newLatex = firstPart + '\\frac{' + secondPart + '}{}';
|
|
164
|
-
|
|
165
|
-
this.mathField.latex(newLatex);
|
|
166
|
-
// trigger pressing keydown to move focus on the denominator
|
|
167
|
-
this.mathField.el().dispatchEvent(new KeyboardEvent('keydown', { keyCode: 37 }));
|
|
168
|
-
|
|
169
|
-
this.onInputEdit();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
137
|
};
|
|
173
138
|
|
|
174
139
|
shouldComponentUpdate(nextProps) {
|