Skip to content
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

MDXEditor v2 is here! Here's how you can upgrade #275

Open
petyosi opened this issue Jan 4, 2024 · 10 comments
Open

MDXEditor v2 is here! Here's how you can upgrade #275

petyosi opened this issue Jan 4, 2024 · 10 comments
Assignees

Comments

@petyosi
Copy link
Contributor

petyosi commented Jan 4, 2024

MDXEditor has a new major version with several breaking changes and dependency upgrades. The public API has not changed much, though - unless you have written custom plugins, you might not be affected by it.

If you're upgrading from v1, read the upgrade summary in the docs, and if something does not work, post a comment here with a runnable reproduction.

@petyosi petyosi pinned this issue Jan 4, 2024
@petyosi petyosi self-assigned this Jan 4, 2024
@Haschtl
Copy link

Haschtl commented Jan 8, 2024

Thanks for the update!

I think the docs need some update, e.g. the docs for directives:
const insertDirective = directivesPluginHooks.usePublisher('insertDirective') doesn't work anymore, because the hooks are not exported (at least I couldn't find it)

My solution now is this:

import {
    insertDirective$,
    usePublisher
} from '@mdxeditor/editor';

const MyComponent = () => {
   const insertDirective = usePublisher(insertDirective$)
   ...
}

@petyosi
Copy link
Contributor Author

petyosi commented Jan 8, 2024

@Haschtl - thanks! pushed a commit that fixes the docs. The plugin specific hooks are no longer necessary, you can just use the gurx ones.

@jdross
Copy link

jdross commented Jan 15, 2024

really nice work! Excited to play with the plugins at some point, just a basic user for now

@Erns
Copy link

Erns commented Jan 19, 2024

FYI, for anyone that is attempting to run unit tests locally via Vitest, I had to make this adjustment in my vitest.config.ts file to get the tests to work:

export default defineConfig({
	plugins: [react()],
	test: {
		...
		server: {
			deps: {
				inline: ["@mdxeditor/editor", "@mdxeditor/gurx"],
			},
		},
	},
});

@zasuh
Copy link

zasuh commented Feb 5, 2024

Where can I find the useEmitterValues hook now?

@petyosi
Copy link
Contributor Author

petyosi commented Feb 5, 2024

Where can I find the useEmitterValues hook now?

It's called useCellValues.

@zasuh
Copy link

zasuh commented Feb 5, 2024

Specifically asking because I am disabling the underline keyboard shortcut in my editor. How can I access rootEditor using useCellValues?

const BoldItalicToggles = () => {
  const [theLexicalEditor] = useCellValues('rootEditor');

  useEffect(
    () =>
      theLexicalEditor?.registerCommand(
        FORMAT_TEXT_COMMAND,
        (payload) => {
          if (payload === 'underline') {
            return true;
          }
          return false;
        },
        COMMAND_PRIORITY_CRITICAL,
      ),
    [theLexicalEditor],
  );

  return (
    <>
      <UndoRedo />
      <BoldItalicUnderlineToggles />
    </>
  );
};

@petyosi
Copy link
Contributor Author

petyosi commented Feb 5, 2024

The new hooks accept cell and signal references instead of strings. In your case, you can import rootEditor$ from the package and do something like this useCellValues(rootEditor$).

There's also the singular variant, which is a bit faster - useCellValue.

@zasuh
Copy link

zasuh commented Feb 6, 2024

@petyosi I'm using Next.js with pages router, on GH Actions when trying to build the app I get the following errors:
image

@petyosi
Copy link
Contributor Author

petyosi commented Feb 6, 2024

@petyosi I'm using Next.js with pages router, on GH Actions when trying to build the app I get the following errors:

image

Sorry, none of that looks familiar. Can you replicate in a sandbox?

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

No branches or pull requests

5 participants