add basic mention extension
This commit is contained in:
committed by
Hans Pagel
parent
72b4eb17bd
commit
eb695878a0
5
docs/src/demos/Nodes/Mention/index.spec.js
Normal file
5
docs/src/demos/Nodes/Mention/index.spec.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
context('/api/nodes/mention', () => {
|
||||||
|
before(() => {
|
||||||
|
cy.visit('/api/nodes/mention')
|
||||||
|
})
|
||||||
|
})
|
||||||
44
docs/src/demos/Nodes/Mention/index.vue
Normal file
44
docs/src/demos/Nodes/Mention/index.vue
Normal 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>
|
||||||
@@ -1,7 +1,16 @@
|
|||||||
# Mention
|
# Mention
|
||||||
|
|
||||||
:::pro Fund the development 💖
|
## Installation
|
||||||
We need your support to maintain, update, support and develop tiptap 2. If you’re waiting for this extension, [become a sponsor and fund open source](/sponsor).
|
```bash
|
||||||
:::
|
# with npm
|
||||||
|
npm install @tiptap/extension-mention
|
||||||
|
|
||||||
TODO
|
# 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" />
|
||||||
|
|||||||
14
packages/extension-mention/README.md
Normal file
14
packages/extension-mention/README.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# @tiptap/extension-mention
|
||||||
|
[](https://www.npmjs.com/package/@tiptap/extension-mention)
|
||||||
|
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
||||||
|
[](https://www.npmjs.com/package/@tiptap/extension-mention)
|
||||||
|
[](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).
|
||||||
30
packages/extension-mention/package.json
Normal file
30
packages/extension-mention/package.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
packages/extension-mention/src/index.ts
Normal file
5
packages/extension-mention/src/index.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { Mention } from './mention'
|
||||||
|
|
||||||
|
export * from './mention'
|
||||||
|
|
||||||
|
export default Mention
|
||||||
49
packages/extension-mention/src/mention.ts
Normal file
49
packages/extension-mention/src/mention.ts
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tiptap/suggestions",
|
"name": "@tiptap/suggestion",
|
||||||
"description": "suggestions",
|
"description": "suggestion plugin for tiptap",
|
||||||
"version": "2.0.0-alpha.0",
|
"version": "2.0.0-alpha.0",
|
||||||
"homepage": "https://tiptap.dev",
|
"homepage": "https://tiptap.dev",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -12,11 +12,11 @@
|
|||||||
"type": "github",
|
"type": "github",
|
||||||
"url": "https://github.com/sponsors/ueberdosis"
|
"url": "https://github.com/sponsors/ueberdosis"
|
||||||
},
|
},
|
||||||
"main": "dist/tiptap-suggestions.cjs.js",
|
"main": "dist/tiptap-suggestion.cjs.js",
|
||||||
"umd": "dist/tiptap-suggestions.umd.js",
|
"umd": "dist/tiptap-suggestion.umd.js",
|
||||||
"module": "dist/tiptap-suggestions.esm.js",
|
"module": "dist/tiptap-suggestion.esm.js",
|
||||||
"unpkg": "dist/tiptap-suggestions.bundle.umd.min.js",
|
"unpkg": "dist/tiptap-suggestion.bundle.umd.min.js",
|
||||||
"types": "dist/packages/suggestions/src/index.d.ts",
|
"types": "dist/packages/suggestion/src/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"src",
|
||||||
"dist"
|
"dist"
|
||||||
5
packages/suggestion/src/index.ts
Normal file
5
packages/suggestion/src/index.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { Suggestion } from './suggestion'
|
||||||
|
|
||||||
|
export * from './suggestion'
|
||||||
|
|
||||||
|
export default Suggestion
|
||||||
@@ -68,7 +68,7 @@ function triggerCharacter({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Suggestions({
|
export function Suggestion({
|
||||||
matcher = {
|
matcher = {
|
||||||
char: '@',
|
char: '@',
|
||||||
allowSpaces: false,
|
allowSpaces: false,
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
import { Suggestions } from './suggestions'
|
|
||||||
|
|
||||||
export * from './suggestions'
|
|
||||||
|
|
||||||
export default Suggestions
|
|
||||||
Reference in New Issue
Block a user