Add React MathType example#8692
Conversation
|
Hi @culpen90! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
potatowagon
left a comment
There was a problem hiding this comment.
Reviewed by Navi (Tater Thoughts Bobblehead) on behalf of @potatowagon.
Assessment: LGTM (pending CLA)
What this PR does: Adds a standalone examples/react-mathtype/ example showing WIRIS MathType integration with Lexical. Introduces MathTypeNode (DecoratorNode), a React context/provider for integration state, a toolbar plugin, and supporting utilities for MathML encode/decode and DOM import/export.
What I checked:
-
Code quality & architecture: Well-structured with clear separation of concerns —
MathTypeData(pure MathML utilities),MathTypeGlobals(type declarations + window global accessor),MathTypeContext(React state management),MathTypeNode(Lexical node definition), andMathTypePlugin(integration bootstrap). Uses the modern$config()protocol withcreateState,$getState,$setState, andbuildImportMap— follows the latest Lexical patterns from the 0.45.x API. -
Correctness:
$commitFormulacorrectly handles both edit (existing nodeKey) and insert (range selection fallback → root append) paths.- DOM import uses priority 3 and checks for both
.Wirisformulaclass anddata-mathmlattribute — good defensive conversion. insertFormulaoverride properly clearstemporalImageandpendingNodeKeyRefafter commit, preventing stale references.encodeMathML/decodeMathMLuse WirisPlugin.MathML when available with a manual fallback using Unicode character substitutions — matches WIRIS's established encoding scheme.
-
Edge cases:
parseOptionalNumberguards against NaN, Infinity, and non-positive values.MathTypeFormulaComponentdouble-click handler is gated onisEditable.- Integration cleanup in useEffect properly nulls
integrationRefonly if it still owns the reference (multi-mount safe). contentEditable={true}on.mathtype-targetdiv is intentional — it's the hidden proxy element that WIRIS requires for its generic integration API.
-
www compatibility: No concerns — this is a standalone example under
examples/, no core library changes, no API surface modifications. -
Security: The
@wiris/mathtype-genericdependency loads from npm (^8.15.2). The example is self-contained; no new deps added to the core library. The MathML encode/decode uses character substitution (not eval/innerHTML injection). -
CI status: Vercel previews pass, CLA is failing (first-time contributor needs to sign). No unit/integration/browser tests triggered since this is example-only.
Minor observations (non-blocking):
- The
declare module '@wiris/mathtype-generic'invite-env.d.tsis a minimal type stub — fine for an example, but contributors could later add a proper.d.tsif the example grows. - No test files included, which is consistent with other standalone examples in the repo.
Verdict: Clean, well-typed MathType example that follows established Lexical patterns. Ready to approve once CLA is signed.
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
etrepum
left a comment
There was a problem hiding this comment.
I'd recommend refactoring this for extensions so it can take advantage of newer features
Summary
examples/react-mathtype.Fixes #7806.
Validation
corepack pnpm run typecheckfromexamples/react-mathtypecorepack pnpm run buildfromexamples/react-mathtypecorepack pnpm exec prettier --check examples/react-mathtypecorepack pnpm exec eslint examples/react-mathtype --no-error-on-unmatched-pattern