Add types for react-mathquill (#40861)

* Add types for react-mathquill

* Fix formatting issues

* Fix typescript header version

* Remove single quote character from typescript version header

* Fix typing for function

* Add type definitions for @edtr-io/mathquill and update react-mathquill to reflect that.

* Add paths property to @edtr-io/mathquill tsconfig

* Fix dt-header package version

* Update types/react-mathquill/index.d.ts

Co-Authored-By: Dmitry Demensky <10235949+demensky@users.noreply.github.com>

* Update types/edtr-io__mathquill/edtr-io__mathquill-tests.ts

Co-Authored-By: Dmitry Demensky <10235949+demensky@users.noreply.github.com>

* Update types/react-mathquill/tsconfig.json

Co-Authored-By: Dmitry Demensky <10235949+demensky@users.noreply.github.com>

* Update types/react-mathquill/index.d.ts

Co-Authored-By: Dmitry Demensky <10235949+demensky@users.noreply.github.com>

* Update types/react-mathquill/index.d.ts

Co-Authored-By: Dmitry Demensky <10235949+demensky@users.noreply.github.com>

* Update types/react-mathquill/index.d.ts

Co-Authored-By: Dmitry Demensky <10235949+demensky@users.noreply.github.com>

* Update types/react-mathquill/index.d.ts

Co-Authored-By: Dmitry Demensky <10235949+demensky@users.noreply.github.com>

* Update types/react-mathquill/react-mathquill-tests.tsx

Co-Authored-By: Dmitry Demensky <10235949+demensky@users.noreply.github.com>

Co-authored-by: Dmitry Demensky <10235949+demensky@users.noreply.github.com>
This commit is contained in:
magonzalez9
2020-01-02 15:18:03 -08:00
committed by Ryan Cavanaugh
co-authored by Dmitry Demensky
parent 20755a9214
commit 0f375a72b5
8 changed files with 220 additions and 0 deletions
@@ -0,0 +1,39 @@
import { MQ, Config } from '@edtr-io/mathquill';
const Test = () => {
const config: Config = {
spaceBehavesLikeTab: true,
leftRightIntoCmdGoes: 'up',
autoSubscriptNumerals: true,
maxDepth: 10,
substituteTextarea() {
return document.createElement('textarea');
},
restrictMismatchedBrackets: true,
sumStartsWithNEquals: true,
supSubsRequireOperand: true,
charsThatBreakOutOfSupSub: '+-=<>',
autoCommands: 'pi theta sqrt',
autoOperatorNames: 'sin cos tan log',
handlers: {
edit(mathField: MQ) {
return mathField;
},
enter(mathField: MQ) {
mathField.blur();
mathField.focus();
mathField.keystroke('Tab');
mathField.typedText('test');
mathField.moveToLeftEnd();
mathField.moveToRightEnd();
mathField.moveToDirEnd(1);
},
upOutOf(mathField: MQ) {
mathField.keystroke('Enter');
},
moveOutOf(dir: number, mathField: MQ) {
if (dir === 1) mathField.clearSelection();
},
},
};
};
+50
View File
@@ -0,0 +1,50 @@
// Type definitions for @edtr-io/mathquill 0.11
// Project: https://github.com/edtr-io/mathquill#readme
// Definitions by: Marco Gonzalez <https://github.com/magonzalez9>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.5
export interface MathField {
focus(): MQ;
blur(): MQ;
write(latex: string): MQ;
cmd(latex: string): MQ;
select(): MQ;
clearSelection(): MQ;
moveToLeftEnd(): MQ;
moveToRightEnd(): MQ;
moveToDirEnd(direction: number): MQ;
keystroke(keys: string): MQ;
typedText(text: string): MQ;
config(config: Config): MQ;
}
export interface MQ extends MathField {
L: number;
R: number;
revert(): MQ;
reflow(): MQ;
el(): HTMLElement;
latex(): string;
latex(latex: string): MQ;
}
export interface Config {
spaceBehavesLikeTab?: boolean;
leftRightIntoCmdGoes?: string;
restrictMismatchedBrackets?: boolean;
sumStartsWithNEquals?: boolean;
supSubsRequireOperand?: boolean;
charsThatBreakOutOfSupSub?: string;
autoSubscriptNumerals?: boolean;
autoCommands?: string;
autoOperatorNames?: string;
maxDepth?: number;
substituteTextarea?(): HTMLTextAreaElement;
handlers?: {
enter?(mathField: MQ): any;
edit?(mathField: MQ): any;
upOutOf?(mathField: MQ): any;
moveOutOf?(direction: number, mathField: MQ): any;
};
}
+27
View File
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@edtr-io/mathquill": ["edtr-io__mathquill"]
}
},
"files": [
"index.d.ts",
"edtr-io__mathquill-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
+21
View File
@@ -0,0 +1,21 @@
// Type definitions for react-mathquill 0.1
// Project: https://github.com/viktorstrate/react-mathquill#readme
// Definitions by: Marco Gonzalez <https://github.com/magonzalez9>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.5
import { ComponentProps, Component } from 'react';
import { MQ, Config } from '@edtr-io/mathquill';
export interface Props extends Omit<ComponentProps<'span'>, 'onChange'> {
latex?: string;
config?: Config;
onChange?(mathField: MQ): void;
mathquillDidMount?(mathField: MQ): void;
}
export function addStyles(): void;
declare class MathQuill extends Component<Props> {}
export default MathQuill;
@@ -0,0 +1,54 @@
import * as React from 'react';
import MathQuill, { addStyles } from 'react-mathquill';
import { Config, MQ } from '@edtr-io/mathquill';
addStyles();
const Test = () => {
const [latex, setLatex] = React.useState<string>('');
const config: Config = {
spaceBehavesLikeTab: true,
leftRightIntoCmdGoes: 'up',
autoSubscriptNumerals: true,
maxDepth: 10,
substituteTextarea() {
return '';
},
restrictMismatchedBrackets: true,
sumStartsWithNEquals: true,
supSubsRequireOperand: true,
charsThatBreakOutOfSupSub: '+-=<>',
autoCommands: 'pi theta sqrt',
autoOperatorNames: 'sin cos tan log',
handlers: {
edit(mathField: MQ) {
return mathField;
},
enter(mathField: MQ) {
mathField.blur();
mathField.focus();
mathField.keystroke('Tab');
mathField.typedText('test');
mathField.moveToLeftEnd();
mathField.moveToRightEnd();
mathField.moveToDirEnd(1);
},
upOutOf(mathField: MQ) {
mathField.keystroke('Enter');
},
moveOutOf(dir: number, mathField: MQ) {
if (dir === 1) mathField.clearSelection();
},
},
};
return (
<MathQuill
latex={latex}
onChange={(MQ: MQ) => setLatex(MQ.latex())}
config={config}
mathquillDidMount={(MQ: MQ) => MQ.latex('\\sqrt{}')}
/>
);
};
+27
View File
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"jsx": "react",
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@edtr-io/mathquill": ["edtr-io__mathquill"]
}
},
"files": [
"index.d.ts",
"react-mathquill-tests.tsx"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }