mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-28 07:40:13 +08:00
add basic mention extension
This commit is contained in:
parent
c3d0f004d6
commit
5a9b96aaf0
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>
|
16
docs/src/docPages/api/nodes/mention.md
Normal file
16
docs/src/docPages/api/nodes/mention.md
Normal 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" />
|
@ -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
|
||||
|
14
packages/extension-mention/README.md
Normal file
14
packages/extension-mention/README.md
Normal 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).
|
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",
|
||||
"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"
|
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 = {
|
||||
char: '@',
|
||||
allowSpaces: false,
|
@ -1,5 +0,0 @@
|
||||
import { Suggestions } from './suggestions'
|
||||
|
||||
export * from './suggestions'
|
||||
|
||||
export default Suggestions
|
Loading…
Reference in New Issue
Block a user