Skip to content

Releases: andrerpena/react-mde

Allow customizing paste command options

05 Apr 21:53
dbdc595
Compare
Choose a tag to compare

11.0.0

02 Sep 20:20
6f961c8
Compare
Choose a tag to compare
  • Remove grip bar and add support for uploading images by clicking the bar #268
  • Fix errors/warning from typescript, as triggeredBy parameter is missing in loadSuggestions function signature, but in fact is passed #274

10.2.0

11 Aug 22:11
826e33f
Compare
Choose a tag to compare
  • Fix misplaced suggestions #264
  • Text area events don't override suggestions anymore #263
  • Min height can no longer be greater than Max height #261
  • Chinese l18n object #257

10.1.0

28 Jun 10:17
b9e0f7a
Compare
Choose a tag to compare
  • Fix code command erroneously linked to quote command #248
  • Opportunity to provide custom initial editor height (optional) #246

10.0.0

06 May 05:12
Compare
Choose a tag to compare

New features:

You can now pass a paste prop with a saveImage function and an optional command to execute on paste.

Example:

paste={{
  command: "save-image", // optional
  saveImage: save
}}

saveImage should be an async generator function that yields the URL for the uploaded image and returns true, indicating the upload was successful.

const save: SaveImageHandler = async function*(data: ArrayBuffer) {
  // Promise that waits for "time" milliseconds
  const wait = function(time: number) {
    return new Promise((a, r) => {
      setTimeout(() => a(), time);
    });
  };

  // Upload "data" to your server
  // Use XMLHttpRequest.send to send a FormData object containing
  // "data"
  // Check this question: https://stackoverflow.com/questions/18055422/how-to-receive-php-image-data-over-copy-n-paste-javascript-with-xmlhttprequest

  await wait(2000);
  // yields the URL that should be inserted in the markdown
  yield "https://picsum.photos/300";
  await wait(2000);

  // returns true meaning that the save was successful
  return true;
};

You can now specify toolbar commands in an easier way

Before, if you wanted to control which commands would display in the toolbar, you would have to import each command, compose them in the desired way and pass them into React-mde.

Now, the commands and the way they are displayed have been separated.

The optional commands prop expects a CommandMap, which is an object that has string keys and, for each key, a Command object. If no commands are passed, the default ones are used. Before, you had to pass all commands in, including the default ones. Now, you only need to pass a map of custom Commands. The default commands are always available.

The most interesting new prop is toolbarCommands, that receives a string[][] representing which commands should be displayed on the toolbar.

Example:

toolbarCommands={[["code", "bold"], ["italic"]]}

Breaking changes:

The way commands are selected changes

This change does not impact you if you did not customize which commands were displayed.

Before, the commands prop was a Command[][]. Now it is a Record<string, Command>. This is because the way commands are displayed on the toolbar have been disassociated with the list of commands itself.

As stated on the "New features", to specify the commands on the toolbar, use the the toolbarCommands prop:
toolbarCommands={[["code", "bold"], ["italic"]]}

The Command execute API changed

This change does not affect you if you don't implement custom commands.

Before, the execute signature was:

execute(state0: TextState, api: TextApi) { } 

Now it is

execute({ initialState, textApi, context, l18n  }: ExecuteOptions) {}

Now execute takes an ExecuteOptions object. This is, of course, because new APIs had to be introduced. context, now, varies with the command. For the paste commands, context contains event and saveImage, the function that really saves the image.

Commands no longer have a name

The commands are now identified by their keys on the CommandMap

9.1.0

27 Apr 06:34
Compare
Choose a tag to compare

PRs:

New features:

  • It is now possible to specify a custom textarea through the prop textAreaComponent

Thanks to @vitorqb

9.0.0

26 Apr 18:11
Compare
Choose a tag to compare

PRs:

Breaking changes:

  • className prop is gone. You must now pass classes using the classes object. This prop has been obsolete for a while.
    Example of how to do it now:
          classes={{
            reactMde: "react-mde",
            suggestionsDropdown: "sug-dropdown",
          }}
  • textAreaProps prop is gone. You must now use the childProps. This prop has been obsolete for a while.
    Example of how to do it now:
          childProps={{
            textArea: {
              a: 1
            }
          }}
  • For custom commands, the keyCommand field is gone. This was useless and was left there from the Draft.js times.

New features:

  • Commands can now have async execute functions. This is to facilitate adding the upload image functionality, since I am planning that to be a long running command, under the hoods.
  • Commands now can implement a handleKeyCommand handler. This function will be called for every keydown inside the textarea. If this function returns true, the command will be executed.
  • It is now possible use Cmd+B for bold, Cmd+I for italic and Cmd+k for link as shortcuts.

Fixes

  • getState() added to the TextApi typings

8.3.0

19 Apr 18:11
Compare
Choose a tag to compare
  • Fixed bug that prevented the editor markdown to update while preview mode was on. Thanks to @rozman-michael #225
  • Allow the command API to get the current editor state. This is useful for async commands. Thanks to @n1ru4l #227

8.0.2

07 Feb 22:22
Compare
Choose a tag to compare

Fixed a bug where the undo/redo would not work after you clicked Preview and then back to Write

8.0.0

07 Feb 22:21
Compare
Choose a tag to compare

Added support for auto-completion