Giter Club home page Giter Club logo

Comments (3)

pedrobonamin avatar pedrobonamin commented on August 23, 2024

Hello, I'm getting the same issue, have you been able to fix it?
Trying to use the plugin in a NextJs embebed editor.

from sanity-plugin-markdown.

iamhectorsosa avatar iamhectorsosa commented on August 23, 2024

@pedrobonamin Nope. I've got nothing so far. I've reached out to the Sanity folks on their Slack channel but they've advised me to contact the plugin creators. Hence, here we are.

from sanity-plugin-markdown.

pedrobonamin avatar pedrobonamin commented on August 23, 2024

I managed to fix it, following the recommendation from here:
#27

What I did:

  • Copied the src folder from this project into my project.
  • Updated the MarkdownInput component into this:
export const MarkdownInput = React.forwardRef(
  (props: MarkdownInputProps, ref: React.MutableRefObject<any>) => {
    const {
      value = '',
      onChange,
      elementProps: { onBlur, onFocus },
      reactMdeProps: { options: mdeCustomOptions, ...reactMdeProps } = {},
      schemaType,
    } = props;
    const client = useClient({ apiVersion: '2022-01-01' });
    const { imageUrl } =
      (schemaType.options as MarkdownOptions | undefined) ?? {};

    const imageUpload = useCallback(
      (
        file: File,
        onSuccess: (url: string) => void,
        onError: (error: string) => void,
      ) => {
        client.assets
          .upload('image', file)
          .then((doc) =>
            onSuccess(imageUrl ? imageUrl(doc) : `${doc.url}?w=450`),
          )
          .catch((e) => {
            console.error(e);
            onError(e.message);
          });
      },
      [client, imageUrl],
    );

    const mdeOptions: EasyMdeOptions = useMemo(() => {
      return {
        autofocus: false,
        spellChecker: false,
        sideBySideFullscreen: false,
        uploadImage: true,
        imageUploadFunction: imageUpload,
        toolbar: defaultMdeTools,
        status: false,
        ...mdeCustomOptions,
      };
    }, [imageUpload, mdeCustomOptions]);

    const handleChange = useCallback(
      (newValue: string) => {
        onChange(PatchEvent.from(newValue ? set(newValue) : unset()));
      },
      [onChange],
    );

    return (
      <MarkdownInputStyles focused={props.focused}> // Added some focused styles for this component
        <SimpleMdeReact
          {...reactMdeProps}
          ref={ref}
          value={value}
          onChange={handleChange}
          onBlur={onBlur}
          onFocus={onFocus}
          options={mdeOptions}
          spellCheck={false}
        />
      </MarkdownInputStyles>
    );
  },
);

  • Used the plugin from my project instead of the installed one.

from sanity-plugin-markdown.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.