diff --git a/types/edtr-io__mathquill/edtr-io__mathquill-tests.ts b/types/edtr-io__mathquill/edtr-io__mathquill-tests.ts new file mode 100644 index 0000000000..e8bd657de4 --- /dev/null +++ b/types/edtr-io__mathquill/edtr-io__mathquill-tests.ts @@ -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(); + }, + }, + }; +}; diff --git a/types/edtr-io__mathquill/index.d.ts b/types/edtr-io__mathquill/index.d.ts new file mode 100644 index 0000000000..dafc430d7f --- /dev/null +++ b/types/edtr-io__mathquill/index.d.ts @@ -0,0 +1,50 @@ +// Type definitions for @edtr-io/mathquill 0.11 +// Project: https://github.com/edtr-io/mathquill#readme +// Definitions by: Marco Gonzalez +// 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; + }; +} diff --git a/types/edtr-io__mathquill/tsconfig.json b/types/edtr-io__mathquill/tsconfig.json new file mode 100644 index 0000000000..c73ecfab9a --- /dev/null +++ b/types/edtr-io__mathquill/tsconfig.json @@ -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" + ] +} diff --git a/types/edtr-io__mathquill/tslint.json b/types/edtr-io__mathquill/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/edtr-io__mathquill/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/react-mathquill/index.d.ts b/types/react-mathquill/index.d.ts new file mode 100644 index 0000000000..49706bc0b9 --- /dev/null +++ b/types/react-mathquill/index.d.ts @@ -0,0 +1,21 @@ +// Type definitions for react-mathquill 0.1 +// Project: https://github.com/viktorstrate/react-mathquill#readme +// Definitions by: Marco Gonzalez +// 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, 'onChange'> { + latex?: string; + config?: Config; + onChange?(mathField: MQ): void; + mathquillDidMount?(mathField: MQ): void; +} + +export function addStyles(): void; + +declare class MathQuill extends Component {} + +export default MathQuill; diff --git a/types/react-mathquill/react-mathquill-tests.tsx b/types/react-mathquill/react-mathquill-tests.tsx new file mode 100644 index 0000000000..4d74820047 --- /dev/null +++ b/types/react-mathquill/react-mathquill-tests.tsx @@ -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(''); + + 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 ( + setLatex(MQ.latex())} + config={config} + mathquillDidMount={(MQ: MQ) => MQ.latex('\\sqrt{}')} + /> + ); +}; diff --git a/types/react-mathquill/tsconfig.json b/types/react-mathquill/tsconfig.json new file mode 100644 index 0000000000..05de0a8721 --- /dev/null +++ b/types/react-mathquill/tsconfig.json @@ -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" + ] +} diff --git a/types/react-mathquill/tslint.json b/types/react-mathquill/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-mathquill/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }