Skip to content

Commit

Permalink
First proof of concept version
Browse files Browse the repository at this point in the history
  • Loading branch information
Khazuar committed Jan 30, 2019
1 parent c1c9547 commit 3ba3365
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# production
/build
/dist

# misc
.DS_Store
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"name": "react-mathlive",
"version": "1.0.0",
"description": "A react wrapper-component for mathlive.js",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"prepare": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Fabian Grewing",
Expand All @@ -14,6 +16,7 @@
"typescript": "^3.2.4"
},
"dependencies": {
"mathlive": "^0.25.0",
"react": "^16.7.0",
"react-dom": "^16.7.0"
}
Expand Down
40 changes: 40 additions & 0 deletions src/Mathfield.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'mathlive/dist/mathlive.core.css';
import 'mathlive/dist/mathlive.css';
import * as React from 'react';
import MathLive from 'mathlive/dist/mathlive.mjs';

interface Props {
latex: string;
onChange: (latex: string) => void;
options?: { [key: string]: any };
mathFieldRef?: (mf: any) => void;
}

export class MathField extends React.Component<Props> {
insertElement: HTMLElement | null = null;

render() {
return <div
ref={instance => this.insertElement = instance}
/>;
}

componentDidMount() {
if (!this.insertElement) {
throw new Error("React did apparently not mount the insert point correctly.");
}

let options = {
...this.props.options,
onContentDidChange: (mf: any) => {
this.props.onChange(mf.text("latex"))
}
};

const mf = MathLive.makeMathField(this.insertElement, options);

if (this.props.mathFieldRef) {
this.props.mathFieldRef(mf);
}
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { MathField } from './Mathfield';
7 changes: 7 additions & 0 deletions src/types/mathlive/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare module 'mathlive/dist/mathlive.mjs' {
const MathLive: {
makeMathField: (el: HTMLElement, options?: object) => any
};

export default MathLive;
}
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"compilerOptions": {
"outDir": "./lib",
"outDir": "./dist",
"target": "es5",
"module": "commonjs",
"noImplicitAny": true,
"strictNullChecks": true,
"removeComments": true,
"declaration": false,
"declaration": true,
"sourceMap": true,
"jsx": "react",
"typeRoots": [
Expand All @@ -19,6 +19,7 @@
"./src/**/*.ts"
],
"exclude": [
"node_modules"
"node_modules",
"dist"
]
}

0 comments on commit 3ba3365

Please sign in to comment.