Skip to content

Add React MathType example#8692

Open
culpen90 wants to merge 4 commits into
facebook:mainfrom
culpen90:feature/react-mathtype-example
Open

Add React MathType example#8692
culpen90 wants to merge 4 commits into
facebook:mainfrom
culpen90:feature/react-mathtype-example

Conversation

@culpen90

@culpen90 culpen90 commented Jun 13, 2026

Copy link
Copy Markdown

Summary

  • Add a standalone React MathType example under examples/react-mathtype.
  • Store MathType formulas in a custom Lexical node so editor state remains authoritative.
  • Bridge MathType insert/edit callbacks into Lexical updates and document the example setup.

Fixes #7806.

Validation

  • corepack pnpm run typecheck from examples/react-mathtype
  • corepack pnpm run build from examples/react-mathtype
  • corepack pnpm exec prettier --check examples/react-mathtype
  • corepack pnpm exec eslint examples/react-mathtype --no-error-on-unmatched-pattern

@meta-cla

meta-cla Bot commented Jun 13, 2026

Copy link
Copy Markdown

Hi @culpen90!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@vercel

vercel Bot commented Jun 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Jun 20, 2026 1:32pm
lexical-playground Ready Ready Preview, Comment Jun 20, 2026 1:32pm

Request Review

@potatowagon potatowagon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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), and MathTypePlugin (integration bootstrap). Uses the modern $config() protocol with createState, $getState, $setState, and buildImportMap — follows the latest Lexical patterns from the 0.45.x API.

  2. Correctness:

    • $commitFormula correctly handles both edit (existing nodeKey) and insert (range selection fallback → root append) paths.
    • DOM import uses priority 3 and checks for both .Wirisformula class and data-mathml attribute — good defensive conversion.
    • insertFormula override properly clears temporalImage and pendingNodeKeyRef after commit, preventing stale references.
    • encodeMathML/decodeMathML use WirisPlugin.MathML when available with a manual fallback using Unicode character substitutions — matches WIRIS's established encoding scheme.
  3. Edge cases:

    • parseOptionalNumber guards against NaN, Infinity, and non-positive values.
    • MathTypeFormulaComponent double-click handler is gated on isEditable.
    • Integration cleanup in useEffect properly nulls integrationRef only if it still owns the reference (multi-mount safe).
    • contentEditable={true} on .mathtype-target div is intentional — it's the hidden proxy element that WIRIS requires for its generic integration API.
  4. www compatibility: No concerns — this is a standalone example under examples/, no core library changes, no API surface modifications.

  5. Security: The @wiris/mathtype-generic dependency 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).

  6. 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' in vite-env.d.ts is a minimal type stub — fine for an example, but contributors could later add a proper .d.ts if 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.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 13, 2026
@meta-cla

meta-cla Bot commented Jun 13, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend refactoring this for extensions so it can take advantage of newer features

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: MathType integration

3 participants