Sha256: 2f6064662eb31b3739faee8ade9bb521472b8c646a5f32f11bb386b94c83aea1

Contents?: true

Size: 890 Bytes

Versions: 13

Compression:

Stored size: 890 Bytes

Contents

import { Plugin } from "prosemirror-state";

import CharacterCount from "@tiptap/extension-character-count";

/**
 * Extends the character counter to prevent adding new paragraphs after the
 * character limit is reached. The original character counter allows that.
 *
 * See: https://github.com/ueberdosis/tiptap/issues/3721
 */
export default CharacterCount.extend({
  addProseMirrorPlugins() {
    const limit = this.options.limit;
    const plugins = this.parent?.();
    if (limit === 0 || limit === null || !limit) {
      return plugins;
    }

    const  { storage } = this.editor;
    return [
      ...plugins,
      new Plugin({
        props: {
          handleKeyDown(view, event) {
            if (event.key === "Enter") {
              return storage.characterCount.characters() >= limit;
            }

            return false;
          }
        }
      })
    ];
  }
});

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/packs/src/decidim/editor/extensions/character_count/index.js
decidim-core-0.28.4 app/packs/src/decidim/editor/extensions/character_count/index.js
decidim-core-0.29.0 app/packs/src/decidim/editor/extensions/character_count/index.js
decidim-core-0.28.3 app/packs/src/decidim/editor/extensions/character_count/index.js
decidim-core-0.29.0.rc4 app/packs/src/decidim/editor/extensions/character_count/index.js
decidim-core-0.29.0.rc3 app/packs/src/decidim/editor/extensions/character_count/index.js
decidim-core-0.29.0.rc2 app/packs/src/decidim/editor/extensions/character_count/index.js
decidim-core-0.29.0.rc1 app/packs/src/decidim/editor/extensions/character_count/index.js
decidim-core-0.28.2 app/packs/src/decidim/editor/extensions/character_count/index.js
decidim-core-0.28.1 app/packs/src/decidim/editor/extensions/character_count/index.js
decidim-core-0.28.0 app/packs/src/decidim/editor/extensions/character_count/index.js
decidim-core-0.28.0.rc5 app/packs/src/decidim/editor/extensions/character_count/index.js
decidim-core-0.28.0.rc4 app/packs/src/decidim/editor/extensions/character_count/index.js