add basic mention extension

This commit is contained in:
Philipp Kühn 2020-12-17 17:13:35 +01:00
parent c3d0f004d6
commit 5a9b96aaf0
13 changed files with 179 additions and 13 deletions

View File

@ -0,0 +1,5 @@
context('/api/nodes/mention', () => {
before(() => {
cy.visit('/api/nodes/mention')
})
})

View File

@ -0,0 +1,44 @@
<template>
<div v-if="editor">
<editor-content :editor="editor" />
</div>
</template>
<script>
import { Editor } from '@tiptap/core'
import { EditorContent } from '@tiptap/vue'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import Mention from '@tiptap/extension-mention'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document,
Paragraph,
Text,
Mention,
],
content: `
<p>text <span data-mention></span></p>
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>

View File

@ -0,0 +1,16 @@
# Mention
## Installation
```bash
# with npm
npm install @tiptap/extension-mention
# with Yarn
yarn add @tiptap/extension-mention
```
## Source code
[packages/extension-mention/](https://github.com/ueberdosis/tiptap-next/blob/main/packages/extension-mention/)
## Usage
<demo name="Nodes/Mention" />

View File

@ -91,6 +91,9 @@
link: /api/nodes/image
- title: ListItem
link: /api/nodes/list-item
- title: Mention
link: /api/nodes/mention
draft: true
- title: OrderedList
link: /api/nodes/ordered-list
- title: Paragraph

View File

@ -0,0 +1,14 @@
# @tiptap/extension-mention
[![Version](https://img.shields.io/npm/v/@tiptap/extension-mention.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-mention)
[![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-mention.svg)](https://npmcharts.com/compare/tiptap?minimal=true)
[![License](https://img.shields.io/npm/l/@tiptap/extension-mention.svg)](https://www.npmjs.com/package/@tiptap/extension-mention)
[![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](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).

View File

@ -0,0 +1,30 @@
{
"name": "@tiptap/extension-mention",
"description": "mention extension for tiptap",
"version": "2.0.0-alpha.0",
"homepage": "https://tiptap.dev",
"keywords": [
"tiptap",
"tiptap extension"
],
"license": "MIT",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/ueberdosis"
},
"main": "dist/tiptap-extension-mention.cjs.js",
"umd": "dist/tiptap-extension-mention.umd.js",
"module": "dist/tiptap-extension-mention.esm.js",
"unpkg": "dist/tiptap-extension-mention.bundle.umd.min.js",
"types": "dist/packages/extension-mention/src/index.d.ts",
"files": [
"src",
"dist"
],
"peerDependencies": {
"@tiptap/core": "^2.0.0-alpha.6"
},
"dependencies": {
"@tiptap/suggestion": "^2.0.0-alpha.0"
}
}

View File

@ -0,0 +1,5 @@
import { Mention } from './mention'
export * from './mention'
export default Mention

View File

@ -0,0 +1,49 @@
import { Node } from '@tiptap/core'
import Suggestion from '@tiptap/suggestion'
export const Mention = Node.create({
name: 'mention',
group: 'inline',
inline: true,
selectable: false,
atom: true,
addAttributes() {
return {
id: {
default: null,
},
label: {
default: null,
},
}
},
parseHTML() {
return [
{
tag: 'span[data-mention]',
},
]
},
renderHTML({ node, HTMLAttributes }) {
return ['span', HTMLAttributes, `@${node.attrs.label}`]
},
addProseMirrorPlugins() {
return [
Suggestion({}),
]
},
})
declare module '@tiptap/core' {
interface AllExtensions {
Mention: typeof Mention,
}
}

View File

@ -1,6 +1,6 @@
{
"name": "@tiptap/suggestions",
"description": "suggestions",
"name": "@tiptap/suggestion",
"description": "suggestion plugin for tiptap",
"version": "2.0.0-alpha.0",
"homepage": "https://tiptap.dev",
"keywords": [
@ -12,11 +12,11 @@
"type": "github",
"url": "https://github.com/sponsors/ueberdosis"
},
"main": "dist/tiptap-suggestions.cjs.js",
"umd": "dist/tiptap-suggestions.umd.js",
"module": "dist/tiptap-suggestions.esm.js",
"unpkg": "dist/tiptap-suggestions.bundle.umd.min.js",
"types": "dist/packages/suggestions/src/index.d.ts",
"main": "dist/tiptap-suggestion.cjs.js",
"umd": "dist/tiptap-suggestion.umd.js",
"module": "dist/tiptap-suggestion.esm.js",
"unpkg": "dist/tiptap-suggestion.bundle.umd.min.js",
"types": "dist/packages/suggestion/src/index.d.ts",
"files": [
"src",
"dist"

View File

@ -0,0 +1,5 @@
import { Suggestion } from './suggestion'
export * from './suggestion'
export default Suggestion

View File

@ -68,7 +68,7 @@ function triggerCharacter({
}
}
export function Suggestions({
export function Suggestion({
matcher = {
char: '@',
allowSpaces: false,

View File

@ -1,5 +0,0 @@
import { Suggestions } from './suggestions'
export * from './suggestions'
export default Suggestions