add the character count extension
This commit is contained in:
@@ -1,4 +0,0 @@
|
|||||||
import { CharacterLimit } from './CharacterLimit'
|
|
||||||
|
|
||||||
export * from './CharacterLimit'
|
|
||||||
export default CharacterLimit
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<editor-content :editor="editor" />
|
<editor-content :editor="editor" />
|
||||||
<div class="character-limit">
|
|
||||||
{{ characters }}/{{ limit }}
|
<div :class="{'character-limit': true, 'character-limit--warning': characters === limit}">
|
||||||
|
{{ characters }}/{{ limit }} characters
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -12,7 +13,7 @@ import { Editor, EditorContent } from '@tiptap/vue-starter-kit'
|
|||||||
import Document from '@tiptap/extension-document'
|
import Document from '@tiptap/extension-document'
|
||||||
import Paragraph from '@tiptap/extension-paragraph'
|
import Paragraph from '@tiptap/extension-paragraph'
|
||||||
import Text from '@tiptap/extension-text'
|
import Text from '@tiptap/extension-text'
|
||||||
import CharacterLimit from './extension'
|
import CharacterCount from '@tiptap/extension-character-count'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -32,7 +33,7 @@ export default {
|
|||||||
Document,
|
Document,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
Text,
|
Text,
|
||||||
CharacterLimit.configure({
|
CharacterCount.configure({
|
||||||
limit: this.limit,
|
limit: this.limit,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@@ -70,6 +71,10 @@ export default {
|
|||||||
|
|
||||||
.character-limit {
|
.character-limit {
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
color: #adb5bd;
|
color: #868e96;
|
||||||
|
|
||||||
|
&--warning {
|
||||||
|
color: #f03e3e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
25
docs/src/docPages/api/extensions/character-count.md
Normal file
25
docs/src/docPages/api/extensions/character-count.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# CharacterCount
|
||||||
|
[](https://www.npmjs.com/package/@tiptap/extension-character-count)
|
||||||
|
[](https://npmcharts.com/compare/@tiptap/extension-character-count?minimal=true)
|
||||||
|
|
||||||
|
The `CharacterCount` extension limits the number of allowed character to a specific length. That’s it, that’s all.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
```bash
|
||||||
|
# with npm
|
||||||
|
npm install @tiptap/extension-character-count
|
||||||
|
|
||||||
|
# with Yarn
|
||||||
|
yarn add @tiptap/extension-character-count
|
||||||
|
```
|
||||||
|
|
||||||
|
## Settings
|
||||||
|
| Option | Type | Default | Description |
|
||||||
|
| ------ | -------- | ------- | -------------------------------------------------------- |
|
||||||
|
| limit | `Number` | `0` | The maximum number of characters that should be allowed. |
|
||||||
|
|
||||||
|
## Source code
|
||||||
|
[packages/extension-character-count/](https://github.com/ueberdosis/tiptap-next/blob/main/packages/extension-character-count/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
<demo name="Extensions/CharacterCount" highlight="" />
|
||||||
@@ -9,4 +9,4 @@ Congratulations! You’ve found our secret playground with a list of experiments
|
|||||||
* [Commands](/experiments/commands)
|
* [Commands](/experiments/commands)
|
||||||
|
|
||||||
## Waiting for approval
|
## Waiting for approval
|
||||||
* [CharacterLimit](/experiments/character-limit)
|
–
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
# CharacterLimit
|
|
||||||
|
|
||||||
⚠️ Experiment
|
|
||||||
|
|
||||||
<demo name="Experiments/CharacterLimit" />
|
|
||||||
@@ -183,6 +183,9 @@
|
|||||||
# - title: Annotation
|
# - title: Annotation
|
||||||
# link: /api/extensions/annotation
|
# link: /api/extensions/annotation
|
||||||
# type: draft
|
# type: draft
|
||||||
|
- title: CharacterCount
|
||||||
|
link: /api/extensions/character-count
|
||||||
|
type: new
|
||||||
- title: Collaboration
|
- title: Collaboration
|
||||||
link: /api/extensions/collaboration
|
link: /api/extensions/collaboration
|
||||||
type: pro
|
type: pro
|
||||||
|
|||||||
14
packages/extension-character-count/README.md
Normal file
14
packages/extension-character-count/README.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# @tiptap/extension-character-count
|
||||||
|
[](https://www.npmjs.com/package/@tiptap/extension-character-count)
|
||||||
|
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
||||||
|
[](https://www.npmjs.com/package/@tiptap/extension-character-count)
|
||||||
|
[](https://github.com/sponsors/ueberdosis)
|
||||||
|
|
||||||
|
## Introduction
|
||||||
|
tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
|
||||||
|
|
||||||
|
## Offical Documentation
|
||||||
|
Documentation can be found on the [tiptap website](https://tiptap.dev).
|
||||||
|
|
||||||
|
## License
|
||||||
|
tiptap is open-sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap-next/blob/main/LICENSE.md).
|
||||||
28
packages/extension-character-count/package.json
Normal file
28
packages/extension-character-count/package.json
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "@tiptap/extension-character-count",
|
||||||
|
"description": "font family extension for tiptap",
|
||||||
|
"version": "2.0.0-alpha.5",
|
||||||
|
"homepage": "https://tiptap.dev",
|
||||||
|
"keywords": [
|
||||||
|
"tiptap",
|
||||||
|
"tiptap extension"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"funding": {
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/ueberdosis"
|
||||||
|
},
|
||||||
|
"main": "dist/tiptap-extension-character-count.cjs.js",
|
||||||
|
"umd": "dist/tiptap-extension-character-count.umd.js",
|
||||||
|
"module": "dist/tiptap-extension-character-count.esm.js",
|
||||||
|
"unpkg": "dist/tiptap-extension-character-count.bundle.umd.min.js",
|
||||||
|
"types": "dist/packages/extension-character-count/src/index.d.ts",
|
||||||
|
"files": [
|
||||||
|
"src",
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"peerDependencies": {
|
||||||
|
"@tiptap/core": "^2.0.0-alpha.6",
|
||||||
|
"@tiptap/extension-text-style": "^2.0.0-alpha.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +1,17 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { Extension } from '@tiptap/core'
|
import { Extension } from '@tiptap/core'
|
||||||
import {
|
import { Plugin, PluginKey } from 'prosemirror-state'
|
||||||
Plugin, PluginKey,
|
|
||||||
} from 'prosemirror-state'
|
|
||||||
|
|
||||||
export const pluginKey = new PluginKey('characterLimit')
|
export const pluginKey = new PluginKey('characterLimit')
|
||||||
|
|
||||||
export interface CharacterLimitOptions {
|
export interface CharacterCountOptions {
|
||||||
limit: number,
|
limit?: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CharacterLimit = Extension.create({
|
export const CharacterCount = Extension.create({
|
||||||
name: 'characterLimit',
|
name: 'characterCount',
|
||||||
|
|
||||||
defaultOptions: <CharacterLimitOptions>{
|
defaultOptions: <CharacterCountOptions>{
|
||||||
limit: 100,
|
limit: 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
addProseMirrorPlugins() {
|
addProseMirrorPlugins() {
|
||||||
@@ -28,7 +25,7 @@ export const CharacterLimit = Extension.create({
|
|||||||
appendTransaction: (transactions, oldState, newState) => {
|
appendTransaction: (transactions, oldState, newState) => {
|
||||||
const length = newState.doc.content.size
|
const length = newState.doc.content.size
|
||||||
|
|
||||||
if (length > options.limit) {
|
if (options.limit && length > options.limit) {
|
||||||
return newState.tr.insertText('', options.limit + 1, length)
|
return newState.tr.insertText('', options.limit + 1, length)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -39,6 +36,6 @@ export const CharacterLimit = Extension.create({
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface AllExtensions {
|
interface AllExtensions {
|
||||||
CharacterLimit: typeof CharacterLimit,
|
CharacterCount: typeof CharacterCount,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
5
packages/extension-character-count/src/index.ts
Normal file
5
packages/extension-character-count/src/index.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { CharacterCount } from './character-count'
|
||||||
|
|
||||||
|
export * from './character-count'
|
||||||
|
|
||||||
|
export default CharacterCount
|
||||||
Reference in New Issue
Block a user