0.7.15 • Published 1 year ago

calliope-editor v0.7.15

Weekly downloads
-
License
BSD-2-Clause
Repository
-
Last release
1 year ago

Calliope

An extensible WYSWYG editor based on Lexical.

What is Calliope?

Calliope Editor is a ready-to-use editor based on lexical. It is intended to be easy to use and ships with several ready to use plugins.

It does not contain a graphical interface beyond that of the editor itself, and is therefore not tied to any particular UI.

Overview

Built in plugins

  • Code highlight and code formatting.
  • Drag and drop images.
  • Emojis (english default).
  • Floating link editor.
  • Table cell.
  • Mentions
  • Citation block
  • Speech to text
  • Text spoiler
  • Block spoiler (collapsible)
  • Insert tweets
  • Insert videos (Youtube, Facebook, Dailymotion, Soundcloud, Twitch).
  • Basic formatting (bold, italic, underline, strikethrough, superscript, subscript).
  • Text coloring (font and background).
  • Different font types
  • Different block types (heading, bullet list, numbered list, check list, quote and code block).

Installation

Install the yarn pacakge.

yarn add calliope-editor

Import the editor

import { CalliopeEditor } from 'calliope-editor';

Usage

The editor component takes three parameters

  • config (required) : an object containing configuration options (detailed below).
  • containerRef (required): a react ref used to manipulate the editor.
  • setFormats (optional): a function used to set the formats applied to the selected text. Useful when building UIs.
<CalliopeEditor
  config={config}
  containerRef={containerRef}
  setFormats={setFormats}
/>

Configuration

The configuration object (config parameter) looks like this.

{
  placeholderText: t('toolbar.placeholderText'),
  initialState: initialState,
  isReadOnly: false,
  autoFocus: true,
  onError: (error) => {
    throw error;
  },
  plugins: [],
  imageConfig: {
    addCaptionText: t('internal.addCaption'),
    defaultCaptionText: t('internal.enterCaption'),
  },
  twitterConfig: {
    loadingComponent: ({ tweetId }) => (
      <p>
        {t('internal.loadingTweet')}...(ID={tweetId})
      </p>
    ),
  },
  collapsibleConfig: {
    open: true,
  },
  citation: {
    sourceLinkComponent: ({ sourceLink }) => (
      <a href={sourceLink} className="source-link-component">
        <FontAwesomeIcon icon={sourceIcon} size="lg" />
      </a>
    ) /*,
    authorComponent: ({ author }) => (
      <a href={author.link} className="author-link-container">
        <AccountAvatar
          avatar={author.avatar}
          username={author.name}
          size="5px"
          shape="circle"
        />
        <span className="author-link-quote">{author.name}</span>
      </a>
    ),*/,
  },
  mentions: {
    onSearchChange: onSearchChange,
    onAddMention: (mention) => {
      setMentions([...mentions, mention.name]);
    },
    onRemoveMention: ({ name, link }) => {
      const newMentions = mentions.filter((m) => m !== name);
      setMentions(newMentions);
    },
    entryComponent: ({ option: { avatar, name, link } }) => (
      <>
        <AccountAvatar avatar={avatar} username={name} size="5px" shape="circle" />
        &nbsp; <strong className="user-name-mentions">{name}</strong>
      </>
    ),
    mentionsData: suggestions,
  },
  emojiConfig: {
    emojiData: emojiData,
  },
  dragAndDropImage: {
    handleDroppedFile: async (file) => {
      const resp = await uploadFileToServer(file);
      const { src } = resp;

      if (src === null) {
        notification.error({
          message: 'Failed to upload File',
          description: "Couldn't upload file to the server (file type not allowed).",
          placement: 'topRight',
        });
        return;
      }
      const imageSrc = `/static/uploads/${src}`;
      containerRef.current.executeCommand('INSERT_IMAGE', {
        src: imageSrc,
        altText: file.name,
      });
    },
  },
}

Utility functions

Accesible using the containerRef ref.

Editor commands

Valid code languages

The following code languages are accepted by the highlighter. The value column indicates the value passed as the parameter of the CHANGE_CODE_LANGUAGE command.

0.7.11

1 year ago

0.7.10

1 year ago

0.7.13

1 year ago

0.7.12

1 year ago

0.7.15

1 year ago

0.7.9

1 year ago

0.7.8

1 year ago

0.7.4

1 year ago

0.7.6

1 year ago

0.7.5

1 year ago

0.7.7

1 year ago

0.7.2

1 year ago

0.7.3

1 year ago

0.6.7

1 year ago

0.6.6

1 year ago

0.6.9

1 year ago

0.6.8

1 year ago

0.6.10

1 year ago

0.6.1-beta4

1 year ago

0.6.1-beta3

1 year ago

0.7.1

1 year ago

0.7.0

1 year ago

0.6.1-gamma3

1 year ago

0.6.1-gamma2

1 year ago

0.6.1-gamma1

1 year ago

0.6.3

1 year ago

0.6.2

1 year ago

0.6.5

1 year ago

0.6.4

1 year ago

0.4.9

2 years ago

0.4.8

2 years ago

0.5.8-beta

1 year ago

0.5.8-alpha

1 year ago

0.4.8-omega

2 years ago

0.5.8-gamma

1 year ago

0.6.1-beta2

1 year ago

0.5.8-gamma2

1 year ago

0.5.9-omega

1 year ago

0.5.4

1 year ago

0.6.1-beta1

1 year ago

0.5.3

2 years ago

0.5.6

1 year ago

0.5.5

1 year ago

0.5.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.8-omega

1 year ago

0.4.65

2 years ago

0.5.8

1 year ago

0.5.7

1 year ago

0.4.8-beta

2 years ago

0.5.9

1 year ago

0.4.8-alpha

2 years ago

0.5.6-beta

1 year ago

0.5.3-beta

2 years ago

0.6.1-alpha

1 year ago

0.6.1-alpha2

1 year ago

0.6.1-alpha3

1 year ago

0.6.1-alpha4

1 year ago

0.5.9-gamma

1 year ago

0.4.7

2 years ago

0.5.9-omega4

1 year ago

0.6.1

1 year ago

0.5.9-omega3

1 year ago

0.6.0

1 year ago

0.5.9-omega2

1 year ago

0.3.70

2 years ago

0.3.61

2 years ago

0.3.60

2 years ago

0.4.5

2 years ago

0.4.6

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.50

2 years ago

0.3.46

2 years ago

0.3.45

2 years ago

0.3.42

2 years ago

0.3.41

2 years ago

0.3.40

2 years ago

0.3.36

2 years ago

0.3.35

2 years ago

0.3.34

2 years ago

0.3.33

2 years ago

0.3.32

2 years ago

0.3.31

2 years ago

0.3.30

2 years ago

0.3.27

2 years ago

0.3.26

2 years ago

0.3.25

2 years ago

0.3.22

2 years ago

0.3.20

2 years ago

0.3.18

2 years ago

0.3.17

2 years ago

0.3.16

2 years ago

0.3.15

2 years ago

0.3.14

2 years ago

0.3.13

2 years ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.10

2 years ago

0.3.9

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.0

2 years ago