-
Notifications
You must be signed in to change notification settings - Fork 28
Feat/expose on math click for math node #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,11 @@ import { | |
| SlashCommand, | ||
| SvelteNodeViewRenderer, | ||
| useEditor, | ||
| VideoExtended | ||
| VideoExtended, | ||
| type Editor | ||
| } from '../tiptap/index.ts'; | ||
| import { all, createLowlight } from 'lowlight'; | ||
| import extensions from '../extensions.ts'; | ||
| import extensions, { katexOptions } from '../extensions.ts'; | ||
| const lowlight = createLowlight(all); | ||
| import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight'; | ||
| import CodeBlock from './components/CodeBlock.svelte'; | ||
|
|
@@ -22,6 +23,15 @@ import IFrameComp from './components/IFrame.svelte'; | |
| import MermaidComp from './components/Mermaid.svelte'; | ||
| import SlashCommandComp from './components/SlashCommand.svelte'; | ||
| import CalloutComp from './components/Callout.svelte'; | ||
| import Mathematics from '@tiptap/extension-mathematics'; | ||
| import type { Node } from '@tiptap/pm/model'; | ||
|
|
||
| export type MathClickHandler = ( | ||
| node: Node, | ||
| pos: number, | ||
| isBlock: boolean, | ||
| editor: Editor | ||
| ) => void; | ||
|
|
||
| export interface EdraEditorProps { | ||
| onUpdate?: () => void; | ||
|
|
@@ -40,12 +50,37 @@ export interface EdraEditorProps { | |
| onChunk: (chunk: string) => void, | ||
| onError: (error: Error) => void | ||
| ) => Promise<void>; | ||
| /** | ||
| * Called when the user clicks a math node. Forwards TipTap Mathematics `onClick` | ||
| * for both block and inline math, and includes `isBlock` plus the editor instance. | ||
| */ | ||
| onMathClick?: MathClickHandler; | ||
| } | ||
|
|
||
| export const createEditor = (props?: EdraEditorProps) => | ||
| useEditor({ | ||
| export const createEditor = (props?: EdraEditorProps) => { | ||
| let editorRef: Editor | undefined; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win Remove the single-assignment The configured
🧰 Tools🪛 ESLint[error] 61-61: 'editorRef' is never reassigned. Use 'const' instead. (prefer-const) 📍 Affects 2 files
🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
| const onMathClick = props?.onMathClick; | ||
|
|
||
| const editor = useEditor({ | ||
| extensions: [ | ||
| ...extensions, | ||
| Mathematics.configure({ | ||
| katexOptions, | ||
| blockOptions: onMathClick | ||
| ? { | ||
| onClick: (node, pos) => { | ||
| if (editorRef) onMathClick(node, pos, true, editorRef); | ||
| } | ||
| } | ||
| : undefined, | ||
| inlineOptions: onMathClick | ||
| ? { | ||
| onClick: (node, pos) => { | ||
| if (editorRef) onMathClick(node, pos, false, editorRef); | ||
| } | ||
| } | ||
| : undefined | ||
| }), | ||
| CodeBlockLowlight.configure({ | ||
| lowlight | ||
| }).extend({ | ||
|
|
@@ -68,3 +103,7 @@ export const createEditor = (props?: EdraEditorProps) => | |
| ], | ||
| onUpdate: props?.onUpdate || (() => {}) | ||
| }); | ||
|
|
||
| editorRef = editor; | ||
| return editor; | ||
| }; | ||
There was a problem hiding this comment.
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.
katexOptionsenablesthrowOnError, 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