diff --git a/src/examples/error-handling.tsx b/src/examples/error-handling.tsx index c71c5b68..17fe738a 100644 --- a/src/examples/error-handling.tsx +++ b/src/examples/error-handling.tsx @@ -5,13 +5,18 @@ import { ConditionalContents, DiffSourceToggleWrapper, MDXEditor, + MdastImportVisitor, ShowSandpackInfo, UndoRedo, diffSourcePlugin, + realmPlugin, + system, toolbarPlugin } from '../' import markdown from './assets/buggy-markdown.md?raw' import { ALL_PLUGINS } from './_boilerplate' +import * as Mdast from 'mdast' +import { $createParagraphNode } from 'lexical' export function BuggyMarkdown() { return ( @@ -56,3 +61,54 @@ export function MissingPlugins() { /> ) } + +const CatchAllVisitor: MdastImportVisitor = { + testNode: () => true, + visitNode: ({ mdastNode, actions }) => { + console.warn('catch all', { mdastNode }) + actions.addAndStepInto($createParagraphNode()) + }, + priority: -500 +} + +const [catchAllPlugin] = realmPlugin({ + id: 'catch-all', + systemSpec: system(() => ({})), + init: (realm) => { + realm.pubKey('addImportVisitor', CatchAllVisitor) + } +}) + +export function CatchAllPlugin() { + return ( + console.warn(msg)} + markdown={`# Hello`} + onChange={(md) => console.log('change', { md })} + plugins={[ + catchAllPlugin(), + toolbarPlugin({ + toolbarContents: () => ( + + editor?.editorType === 'codeblock', contents: () => }, + { when: (editor) => editor?.editorType === 'sandpack', contents: () => }, + { + fallback: () => ( + <> + + + + ) + } + ]} + /> + + ) + }), + diffSourcePlugin({ viewMode: 'rich-text', diffMarkdown: 'boo' }) + ]} + /> + ) +}