Skip to content

Feat/expose on math click for math node#89

Open
FrankLiu007 wants to merge 2 commits into
Tsuzat:nextfrom
FrankLiu007:feat/expose-onMathClick-for-math-node
Open

Feat/expose on math click for math node#89
FrankLiu007 wants to merge 2 commits into
Tsuzat:nextfrom
FrankLiu007:feat/expose-onMathClick-for-math-node

Conversation

@FrankLiu007

@FrankLiu007 FrankLiu007 commented Jul 24, 2026

Copy link
Copy Markdown

exposure onMathClick for math node

Summary by CodeRabbit

  • New Features

    • Added support for handling clicks on inline and block mathematical expressions.
    • Exposed shared math rendering options and editor callback types for customization.
    • Math click handlers now receive the selected expression, location, expression type, and editor context.
  • Documentation

    • Added guidance and examples for configuring custom math click handling.

@vercel

vercel Bot commented Jul 24, 2026

Copy link
Copy Markdown

@FrankLiu007 is attempting to deploy a commit to the Alok Singh's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

The PR exports shared KaTeX options, adds optional onMathClick handling for block and inline math in both editor variants, re-exports the callback types, and documents custom math click handling.

Math click handling

Layer / File(s) Summary
Shared KaTeX configuration
src/lib/edra/extensions.ts
Exports shared KaTeX options and removes Mathematics configuration from the default extension list.
Editor callback wiring
src/lib/edra/headless/editor.ts, src/lib/edra/shadcn/editor.ts
Adds the MathClickHandler contract and forwards math-node click details through block and inline Mathematics handlers.
Public API and documentation
src/lib/edra/headless/index.ts, src/lib/edra/shadcn/index.ts, src/routes/docs/extensions/mathematics/+page.svelte
Re-exports the new types and documents a custom math click handler example.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Host
  participant createEditor
  participant Mathematics
  participant onMathClick
  Host->>createEditor: pass onMathClick
  createEditor->>Mathematics: configure block and inline click handlers
  Mathematics->>onMathClick: provide node, position, block status, and editor
Loading

Possibly related issues

Possibly related PRs

  • Tsuzat/Edra#84 — Also changes extension wiring around mathematics and atom selection.

Suggested reviewers: tsuzat

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: exposing an onMathClick handler for math nodes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/edra/extensions.ts`:
- Line 28: Align the KaTeX error behavior across the shared katexOptions
configuration and documentation: update src/lib/edra/extensions.ts lines 28-28
so the throwOnError setting and inline comment accurately describe the intended
default, then update src/routes/docs/extensions/mathematics/+page.svelte lines
47-53 to display that same behavior. Ensure both sites consistently indicate
whether invalid LaTeX throws.

In `@src/lib/edra/headless/editor.ts`:
- Line 61: The deferred editorRef declarations violate prefer-const because they
are assigned only once. In src/lib/edra/headless/editor.ts lines 61-61 and
src/lib/edra/shadcn/editor.ts lines 64-64, capture the useEditor(...) result
directly in a const and remove the later editorRef = editor assignment in each
file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 234cc22a-8b30-4100-ba6a-da49aed339be

📥 Commits

Reviewing files that changed from the base of the PR and between 78e4592 and 8378384.

📒 Files selected for processing (6)
  • src/lib/edra/extensions.ts
  • src/lib/edra/headless/editor.ts
  • src/lib/edra/headless/index.ts
  • src/lib/edra/shadcn/editor.ts
  • src/lib/edra/shadcn/index.ts
  • src/routes/docs/extensions/mathematics/+page.svelte

* Shared KaTeX options for Mathematics (wired in createEditor so onMathClick can be injected).
*/
export const katexOptions: KatexOptions = {
throwOnError: true, // don't throw an error if the LaTeX code is invalid

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Align the documented KaTeX error behavior with the actual default.

katexOptions enables throwOnError, while the inline comment and displayed configuration indicate invalid LaTeX will not throw.

  • src/lib/edra/extensions.ts#L28-L28: correct the comment, or change the option if non-throwing rendering is intended.
  • src/routes/docs/extensions/mathematics/+page.svelte#L47-L53: show the same behavior as the shared default.
📍 Affects 2 files
  • src/lib/edra/extensions.ts#L28-L28 (this comment)
  • src/routes/docs/extensions/mathematics/+page.svelte#L47-L53
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/edra/extensions.ts` at line 28, Align the KaTeX error behavior across
the shared katexOptions configuration and documentation: update
src/lib/edra/extensions.ts lines 28-28 so the throwOnError setting and inline
comment accurately describe the intended default, then update
src/routes/docs/extensions/mathematics/+page.svelte lines 47-53 to display that
same behavior. Ensure both sites consistently indicate whether invalid LaTeX
throws.

export const createEditor = (props?: EdraEditorProps) =>
useEditor({
export const createEditor = (props?: EdraEditorProps) => {
let editorRef: Editor | undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Remove the single-assignment let declarations.

The configured prefer-const rule reports both declarations as errors; capture the useEditor(...) result directly in a const and remove the later editorRef = editor assignment.

  • src/lib/edra/headless/editor.ts#L61-L61: replace the deferred editorRef assignment pattern.
  • src/lib/edra/shadcn/editor.ts#L64-L64: apply the same change.
🧰 Tools
🪛 ESLint

[error] 61-61: 'editorRef' is never reassigned. Use 'const' instead.

(prefer-const)

📍 Affects 2 files
  • src/lib/edra/headless/editor.ts#L61-L61 (this comment)
  • src/lib/edra/shadcn/editor.ts#L64-L64
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/edra/headless/editor.ts` at line 61, The deferred editorRef
declarations violate prefer-const because they are assigned only once. In
src/lib/edra/headless/editor.ts lines 61-61 and src/lib/edra/shadcn/editor.ts
lines 64-64, capture the useEditor(...) result directly in a const and remove
the later editorRef = editor assignment in each file.

Source: Linters/SAST tools

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant