docs: update content
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<div class="demo" v-else>
|
||||
<template v-if="mainFile">
|
||||
<demo-frame class="demo__preview" v-bind="props" />
|
||||
<div class="demo__source" v-if="showSource">
|
||||
<div class="demo__source" v-if="!hideSource">
|
||||
<div class="demo__scroller" v-if="showFileNames">
|
||||
<div class="demo__tabs">
|
||||
<button
|
||||
|
||||
@@ -17,9 +17,9 @@ export default {
|
||||
default: null,
|
||||
},
|
||||
|
||||
showSource: {
|
||||
hideSource: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -38,7 +38,7 @@ export default {
|
||||
name: this.name,
|
||||
inline: this.inline,
|
||||
highlight: this.highlight,
|
||||
showSource: this.showSource,
|
||||
hideSource: this.hideSource,
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<demo
|
||||
:name="selectedItem.name"
|
||||
:key="selectedItem.title"
|
||||
:hide-source="hideSource"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -29,6 +30,10 @@ export default {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
hideSource: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
|
||||
data() {
|
||||
|
||||
@@ -15,7 +15,10 @@ export default () => {
|
||||
],
|
||||
content: `
|
||||
<p>
|
||||
Hey, try to select some text here. There will popup a menu for selecting some inline styles. Remember: you have full control about content and styling of this menu.
|
||||
Try to select <em>this text</em> to see what we call the bubble menu.
|
||||
</p>
|
||||
<p>
|
||||
Neat, isn’t it? Add an empty paragraph to see the floating menu.
|
||||
</p>
|
||||
`,
|
||||
})
|
||||
@@ -27,19 +30,19 @@ export default () => {
|
||||
onClick={() => editor.chain().focus().toggleBold().run()}
|
||||
className={editor.isActive('bold') ? 'is-active' : ''}
|
||||
>
|
||||
bold
|
||||
Bold
|
||||
</button>
|
||||
<button
|
||||
onClick={() => editor.chain().focus().toggleItalic().run()}
|
||||
className={editor.isActive('italic') ? 'is-active' : ''}
|
||||
>
|
||||
italic
|
||||
Italic
|
||||
</button>
|
||||
<button
|
||||
onClick={() => editor.chain().focus().toggleStrike().run()}
|
||||
className={editor.isActive('strike') ? 'is-active' : ''}
|
||||
>
|
||||
strike
|
||||
Strike
|
||||
</button>
|
||||
</BubbleMenu>}
|
||||
|
||||
@@ -48,19 +51,19 @@ export default () => {
|
||||
onClick={() => editor.chain().focus().toggleHeading({ level: 1 }).run()}
|
||||
className={editor.isActive('heading', { level: 1 }) ? 'is-active' : ''}
|
||||
>
|
||||
h1
|
||||
H1
|
||||
</button>
|
||||
<button
|
||||
onClick={() => editor.chain().focus().toggleHeading({ level: 2 }).run()}
|
||||
className={editor.isActive('heading', { level: 2 }) ? 'is-active' : ''}
|
||||
>
|
||||
h2
|
||||
H2
|
||||
</button>
|
||||
<button
|
||||
onClick={() => editor.chain().focus().toggleBulletList().run()}
|
||||
className={editor.isActive('bulletList') ? 'is-active' : ''}
|
||||
>
|
||||
bullet list
|
||||
Bullet List
|
||||
</button>
|
||||
</FloatingMenu>}
|
||||
|
||||
|
||||
@@ -2,25 +2,25 @@
|
||||
<div style="position: relative">
|
||||
<bubble-menu class="bubble-menu" :editor="editor" v-if="editor">
|
||||
<button @click="editor.chain().focus().toggleBold().run()" :class="{ 'is-active': editor.isActive('bold') }">
|
||||
bold
|
||||
Bold
|
||||
</button>
|
||||
<button @click="editor.chain().focus().toggleItalic().run()" :class="{ 'is-active': editor.isActive('italic') }">
|
||||
italic
|
||||
Italic
|
||||
</button>
|
||||
<button @click="editor.chain().focus().toggleStrike().run()" :class="{ 'is-active': editor.isActive('strike') }">
|
||||
strike
|
||||
Strike
|
||||
</button>
|
||||
</bubble-menu>
|
||||
|
||||
<floating-menu class="floating-menu" :editor="editor" v-if="editor">
|
||||
<button @click="editor.chain().focus().toggleHeading({ level: 1 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 1 }) }">
|
||||
h1
|
||||
H1
|
||||
</button>
|
||||
<button @click="editor.chain().focus().toggleHeading({ level: 2 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 2 }) }">
|
||||
h2
|
||||
H2
|
||||
</button>
|
||||
<button @click="editor.chain().focus().toggleBulletList().run()" :class="{ 'is-active': editor.isActive('bulletList') }">
|
||||
bullet list
|
||||
Bullet List
|
||||
</button>
|
||||
</floating-menu>
|
||||
|
||||
@@ -57,7 +57,10 @@ export default {
|
||||
],
|
||||
content: `
|
||||
<p>
|
||||
Hey, try to select some text here. You’ll see a formatting menu pop up. And as always, you are in full control about content and styling of this menu.
|
||||
Try to select <em>this text</em> to see what we call the bubble menu.
|
||||
</p>
|
||||
<p>
|
||||
Neat, isn’t it? Add an empty paragraph to see the floating menu.
|
||||
</p>
|
||||
`,
|
||||
})
|
||||
|
||||
@@ -10,8 +10,9 @@ export default () => {
|
||||
],
|
||||
content: `
|
||||
<p>
|
||||
This is an example of a medium-like editor. Enter a new line and some buttons will appear.
|
||||
This is an example of a Medium-like editor. Enter a new line and some buttons will appear.
|
||||
</p>
|
||||
<p></p>
|
||||
`,
|
||||
})
|
||||
|
||||
|
||||
@@ -38,8 +38,9 @@ export default {
|
||||
],
|
||||
content: `
|
||||
<p>
|
||||
This is an example of a medium-like editor. Enter a new line and some buttons will appear.
|
||||
This is an example of a Medium-like editor. Enter a new line and some buttons will appear.
|
||||
</p>
|
||||
<p></p>
|
||||
`,
|
||||
})
|
||||
},
|
||||
|
||||
@@ -31,6 +31,26 @@ In the example above two different commands are executed at once. When a user cl
|
||||
|
||||
All chained commands are kind of queued up. They are combined to one single transaction. That means, the content is only updated once, also the `update` event is only triggered once.
|
||||
|
||||
#### Chaining inside custom commands
|
||||
When chaining a command, the transaction is held back. If you want to chain commands inside your custom commands, you’ll need to use said transaction and add to it. Here is how you would do that:
|
||||
|
||||
```js
|
||||
addCommands() {
|
||||
return {
|
||||
insertTimecode: attributes => ({ chain }) => {
|
||||
// Doesn’t work:
|
||||
// return editor.chain() …
|
||||
|
||||
// Does work:
|
||||
return chain()
|
||||
.insertNode('timecode', attributes)
|
||||
.insertText(' ')
|
||||
.run()
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Inline commands
|
||||
In some cases, it’s helpful to put some more logic in a command. That’s why you can execute commands in commands. I know, that sounds crazy, but let’s look at an example:
|
||||
|
||||
@@ -208,9 +228,26 @@ this.editor
|
||||
.createParagraphNear()
|
||||
.insertHTML('<p></p>')
|
||||
.run()
|
||||
``` -->
|
||||
```
|
||||
|
||||
## Add your own commands
|
||||
Add a custom command to insert a node.
|
||||
```js
|
||||
addCommands() {
|
||||
return {
|
||||
insertTimecode: attributes => ({ chain }) => {
|
||||
return chain()
|
||||
.focus()
|
||||
.insertNode('timecode', attributes)
|
||||
.insertText(' ')
|
||||
.run();
|
||||
},
|
||||
}
|
||||
},
|
||||
```
|
||||
-->
|
||||
|
||||
## Add custom commands
|
||||
All extensions can add additional commands (and most do), check out the specific [documentation for the provided nodes](/api/nodes), [marks](/api/marks), and [extensions](/api/extensions) to learn more about those.
|
||||
|
||||
Of course, you can [add your custom extensions](/guide/build-extensions) with custom commands aswell.
|
||||
|
||||
|
||||
@@ -23,3 +23,4 @@ ProseMirror has its own vocabulary and you’ll stumble upon all those words now
|
||||
| Node | Adds blocks, like heading, paragraph. |
|
||||
| Mark | Adds inline formatting, for example bold or italic. |
|
||||
| Command | Execute an action inside the editor, that somehow changes the state. |
|
||||
| Decoration | Styling on top of the document, for example to highlight mistakes. |
|
||||
|
||||
@@ -5,8 +5,30 @@
|
||||
## Introduction
|
||||
This class is a central building block of tiptap. It does most of the heavy lifting of creating a working [ProseMirror](https://ProseMirror.net/) editor such as creating the [`EditorView`](https://ProseMirror.net/docs/ref/#view.EditorView), setting the initial [`EditorState`](https://ProseMirror.net/docs/ref/#state.Editor_State) and so on.
|
||||
|
||||
## List of available settings
|
||||
Check out the API documentation to see [all available options](/api/editor/).
|
||||
## Methods
|
||||
The editor instance will provide a bunch of public methods. They’ll help you to work with the editor.
|
||||
|
||||
Don’t confuse methods with [commands](/api/commands). Commands are used to change the state of editor (content, selection, and so on) and only return `true` or `false`. Methods are regular functions and can return anything.
|
||||
|
||||
| Method | Parameters | Description |
|
||||
| --------------------- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
||||
| `can()` | - | Check if a command or a command chain can be executed. Without executing it. |
|
||||
| `chain()` | - | Create a command chain to call multiple commands at once. |
|
||||
| `createDocument()` | `content` EditorContent<br>`parseOptions` | Creates a ProseMirror document. |
|
||||
| `destroy()` | – | Stops the editor instance and unbinds all events. |
|
||||
| `getHTML()` | – | Returns the current content as HTML. |
|
||||
| `getJSON()` | – | Returns the current content as JSON. |
|
||||
| `getMarkAttributes()` | `name` Name of the mark | Get attributes of the currently selected mark. |
|
||||
| `getNodeAttributes()` | `name` Name of the node | Get attributes of the currently selected node. |
|
||||
| `isActive()` | `name` Name of the node or mark<br>`attrs` Attributes of the node or mark | Returns if the currently selected node or mark is active. |
|
||||
| `isEditable()` | - | Returns whether the editor is editable. |
|
||||
| `isEmpty()` | - | Check if there is no content. |
|
||||
| `getCharacterCount()` | - | Get the number of characters for the current document. |
|
||||
| `registerPlugin()` | `plugin` A ProseMirror plugin<br>`handlePlugins` Control how to merge the plugin into the existing plugins. | Register a ProseMirror plugin. |
|
||||
| `setOptions()` | `options` A list of options | Update editor options. |
|
||||
| `unregisterPlugin()` | `name` The plugins name | Unregister a ProseMirror plugin. |
|
||||
|
||||
## Settings
|
||||
|
||||
### Element
|
||||
The `element` specifies the HTML element the editor will be binded too. The following code will integrate tiptap with an element with the `.element` class:
|
||||
@@ -147,37 +169,28 @@ new Editor({
|
||||
})
|
||||
```
|
||||
|
||||
<!--
|
||||
| Setting | Type | Default | Description |
|
||||
| ------------------ | --------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `autofocus` | `Boolean` | `false` | Focus the editor on init. |
|
||||
| `content` | `Object|String` | `null` | The editor state object used by Prosemirror. You can also pass HTML to the `content` slot. When used both, the `content` slot will be ignored. |
|
||||
| `editable` | `Boolean` | `true` | When set to `false` the editor is read-only. |
|
||||
| ~~`editorProps`~~ | ~~`Object`~~ | ~~`{}`~~ | ~~A list of [Prosemirror editorProps](https://prosemirror.net/docs/ref/#view.EditorProps).~~ |
|
||||
| `element` | `Element` | `false` | Focus the editor on init. |
|
||||
| `extensions` | `Array` | `[]` | A list of extensions you would like to use. Can be [`Nodes`](/api/nodes), [`Marks`](/api/marks) or [`Extensions`](/api/extensions). |
|
||||
| `injectCSS` | `Boolean` | `true` | When set to `false` tiptap won’t load [the default ProseMirror CSS](https://github.com/ueberdosis/tiptap-next/tree/main/packages/core/src/style.ts). |
|
||||
| ~~`parseOptions`~~ | ~~`Object`~~ | ~~`{}`~~ | ~~A list of [Prosemirror parseOptions](https://prosemirror.net/docs/ref/#model.ParseOptions).~~ | -->
|
||||
### Editor props
|
||||
For advanced use cases, you can pass `editorProps` which will be handled by [ProseMirror](https://prosemirror.net/docs/ref/#view.EditorProps). Here is an example how you can pass a few [Tailwind](https://tailwindcss.com/) classes to the editor container, but there is a lot more you can do.
|
||||
|
||||
## List of available methods
|
||||
An editor instance will provide the following public methods. They’ll help you to work with the editor.
|
||||
```js
|
||||
new Editor({
|
||||
// Learn more: https://prosemirror.net/docs/ref/#view.EditorProps
|
||||
editorProps: {
|
||||
attributes: {
|
||||
class: 'prose prose-sm sm:prose lg:prose-lg xl:prose-2xl mx-auto focus:outline-none',
|
||||
}
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
Don’t confuse methods with [commands](/api/commands), which are used to change the state of editor (content, selection, and so on) and only return `true` or `false`.
|
||||
### Parse options
|
||||
Passed content is parsed by ProseMirror. To hook into the parsing, you can pass `parseOptions` which are then handled by [ProseMirror](https://prosemirror.net/docs/ref/#model.ParseOptions).
|
||||
|
||||
| Method | Parameters | Description |
|
||||
| --------------------- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
||||
| `can()` | - | Check if a command or a command chain can be executed. Without executing it. |
|
||||
| `chain()` | - | Create a command chain to call multiple commands at once. |
|
||||
| `createDocument()` | `content` EditorContent<br>`parseOptions` | Creates a ProseMirror document. |
|
||||
| `destroy()` | – | Stops the editor instance and unbinds all events. |
|
||||
| `getHTML()` | – | Returns the current content as HTML. |
|
||||
| `getJSON()` | – | Returns the current content as JSON. |
|
||||
| `getMarkAttributes()` | `name` Name of the mark | Get attributes of the currently selected mark. |
|
||||
| `getNodeAttributes()` | `name` Name of the node | Get attributes of the currently selected node. |
|
||||
| `isActive()` | `name` Name of the node or mark<br>`attrs` Attributes of the node or mark | Returns if the currently selected node or mark is active. |
|
||||
| `isEditable()` | - | Returns whether the editor is editable. |
|
||||
| `isEmpty()` | - | Check if there is no content. |
|
||||
| `getCharacterCount()` | - | Get the number of characters for the current document. |
|
||||
| `registerPlugin()` | `plugin` A ProseMirror plugin<br>`handlePlugins` Control how to merge the plugin into the existing plugins. | Register a ProseMirror plugin. |
|
||||
| `setOptions()` | `options` A list of options | Update editor options. |
|
||||
| `unregisterPlugin()` | `name` The plugins name | Unregister a ProseMirror plugin. |
|
||||
```js
|
||||
new Editor({
|
||||
// Learn more: https://prosemirror.net/docs/ref/#model.ParseOptions
|
||||
parseOptions: {
|
||||
preserveWhitespace: 'full',
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
@@ -41,5 +41,5 @@ This extension requires the [`Collaboration`](/api/extensions/collaboration) ext
|
||||
The content of this editor is shared with other users.
|
||||
:::
|
||||
|
||||
<demo name="Extensions/CollaborationCursor" :show-source="false" />
|
||||
<demo name="Extensions/CollaborationCursor" hide-source />
|
||||
<demo name="Extensions/CollaborationCursor" highlight="11,39-45" />
|
||||
|
||||
@@ -48,5 +48,5 @@ yarn add @tiptap/extension-collaboration yjs y-websocket
|
||||
:::warning Public
|
||||
The content of this editor is shared with other users.
|
||||
:::
|
||||
<demo name="Extensions/Collaboration" :show-source="false" />
|
||||
<demo name="Extensions/Collaboration" hide-source />
|
||||
<demo name="Extensions/Collaboration" highlight="10,27-28,35-37,44" />
|
||||
|
||||
7
docs/src/docPages/api/nodes/code-block-lowlight.md
Normal file
7
docs/src/docPages/api/nodes/code-block-lowlight.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# CodeBlockLowlight
|
||||
|
||||
:::pro Fund the development ♥
|
||||
We need your support to maintain, update, support and develop tiptap 2. If you’re waiting for this extension, [become a sponsor and fund our work](/sponsor).
|
||||
:::
|
||||
|
||||
TODO
|
||||
@@ -7,7 +7,7 @@ With the CodeBlock extension you can add fenced code blocks to your documents. I
|
||||
Type <code>``` </code> (three backticks and a space) or <code>∼∼∼ </code> (three tildes and a space) and a code block is instantly added for you. You can even specify the language, try writing <code>```css </code>. That should add a `language-css` class to the `<code>`-tag.
|
||||
|
||||
::: warning Restrictions
|
||||
The CodeBlock extension doesn’t come with styling and has no syntax highlighting built-in. It’s on our roadmap though.
|
||||
The CodeBlock extension doesn’t come with styling and has no syntax highlighting built-in. It’s [on our roadmap](/api/nodes/code-block-lowlight) though.
|
||||
:::
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -40,7 +40,7 @@ editor.commands.setContent({
|
||||
|
||||
Here is an interactive example where you can see that in action:
|
||||
|
||||
<demo name="Guide/Content/ExportJSON" :show-source="false"/>
|
||||
<demo name="Guide/Content/ExportJSON" hide-source/>
|
||||
|
||||
### Option 2: HTML
|
||||
HTML can be easily rendered in other places, for example in emails and it’s wildly used, so it’s probably easier to switch the editor at some point. Anyway, every editor instance provides a method to get HTML from the current document:
|
||||
@@ -64,7 +64,7 @@ editor.commands.setContent(`<p>Example Text</p>`)
|
||||
|
||||
Use this interactive example to fiddle around:
|
||||
|
||||
<demo name="Guide/Content/ExportHTML" :show-source="false"/>
|
||||
<demo name="Guide/Content/ExportHTML" hide-source/>
|
||||
|
||||
### Option 3: Y.js
|
||||
Our editor has amazing support for Y.js, which is amazing to add [realtime collaboration, offline editing, or syncing between devices](/guide/collaborative-editing).
|
||||
|
||||
115
docs/src/docPages/guide/menus.md
Normal file
115
docs/src/docPages/guide/menus.md
Normal file
@@ -0,0 +1,115 @@
|
||||
# Create menus
|
||||
|
||||
## toc
|
||||
|
||||
## Introduction
|
||||
tiptap comes very raw, but that’s a good thing. You have full control (and when we say full, we mean full) about the appearance of it. That also means you can (and have to) build a menu on your own. You can start with a few buttons, and we help you to wire everything up.
|
||||
|
||||
## Menus
|
||||
The editor provides a fluent API to trigger commands and add active states. You can use any markup you like. To make the positioning of line menus easier, we provide a few utilities and components. Let’s go through the most typical use cases one by one.
|
||||
|
||||
### Fixed menu
|
||||
A fixed menu, for example on top of the editor, can be anything. We don’t provide such menu. Just add a `<div>` with a few `<button>`s. How those buttons can trigger [commands](/api/commands) is [explained below](#actions).
|
||||
|
||||
### Bubble menu
|
||||
The [bubble menu](/api/extensions/bubble-menu) appears when selecting text. Markup and styling is totally up to you.
|
||||
|
||||
<demos
|
||||
:items="{
|
||||
Vue: 'Extensions/BubbleMenu/Vue',
|
||||
React: 'Extensions/BubbleMenu/React',
|
||||
}"
|
||||
hide-source
|
||||
/>
|
||||
|
||||
It’ll get an absolute position near the text selection. Make sure to add `position: relative` to the wrapper.
|
||||
|
||||
### Floating menu
|
||||
The [floating menu](/api/extensions/floating-menu) appears in empty lines. Markup and styling is totally up to you.
|
||||
|
||||
<demos
|
||||
:items="{
|
||||
Vue: 'Extensions/FloatingMenu/Vue',
|
||||
React: 'Extensions/FloatingMenu/React',
|
||||
}"
|
||||
hide-source
|
||||
/>
|
||||
|
||||
## Buttons
|
||||
Okay, you’ve got your menu. But how do you wire things up?
|
||||
### Commands
|
||||
Let’s assume you’ve got the editor running already and you want to add your first button. You’ll need a `<button>` HTML tag with a click handler. Depending on your setup, that can look like the following example:
|
||||
|
||||
```html
|
||||
<button onclick="editor.chain().toggleBold().focus().run()">
|
||||
Bold
|
||||
</button>
|
||||
```
|
||||
|
||||
Oh, that’s a long command, right? Actually, it’s a [chain of commands](/api/commands#chain-commands), so let’s go through this one by one:
|
||||
|
||||
```js
|
||||
editor.chain().toggleBold().focus().run()
|
||||
```
|
||||
|
||||
1. `editor` should be a tiptap instance,
|
||||
2. `chain()` is used to tell the editor you want to execute multiple commands,
|
||||
3. `focus()` sets the focus back to the editor,
|
||||
4. `toggleBold()` marks the selected text bold, or removes the bold mark from the text selection if it’s already applied and
|
||||
5. `run()` will execute the chain.
|
||||
|
||||
In other words: This will be a typical **Bold** button for your text editor.
|
||||
|
||||
Which commands are available depends on what extensions you have registered with the editor. Most extensions come with a `set…()`, `unset…()` and `toggle…()` command. Read the extension documentation to see what’s actually available or just surf through your code editor’s autocomplete.
|
||||
|
||||
### Keep the focus
|
||||
You have seen the `focus()` command in the above example already. When you click on the button, the browser focuses that DOM element and the editor loses focus. It’s likely you want to add `focus()` to all your menu buttons, so the writing flow of your users isn’t interrupted.
|
||||
|
||||
### The active state
|
||||
The editor provides an `isActive()` method to check if something is applied to the selected text already. In Vue.js you can toggle a CSS class with help of that function like that:
|
||||
|
||||
```html
|
||||
<button :class="{ 'is-active': editor.isActive('bold') }" @click="editor.chain().toggleBold().focus().run()">
|
||||
Bold
|
||||
</button>
|
||||
```
|
||||
|
||||
This toggles the `.is-active` class accordingly and works for nodes and marks. You can even check for specific attributes, here is an example with the [`Highlight`](/api/marks/highlight) mark, that ignores different attributes:
|
||||
|
||||
```js
|
||||
editor.isActive('highlight')
|
||||
```
|
||||
|
||||
And an example that compares the given attribute(s):
|
||||
|
||||
```js
|
||||
editor.isActive('highlight', { color: '#ffa8a8' })
|
||||
```
|
||||
|
||||
You can even ignore nodes and marks, but check for the attributes only. Here is an example with the [`TextAlign`](/api/extensions/text-align) extension:
|
||||
|
||||
```js
|
||||
editor.isActive({ textAlign: 'right' })
|
||||
```
|
||||
|
||||
If your selection spans multiple nodes or marks, or only part of the selection has a mark, `isActive()` will return `false` and indicate nothing is active. This is how it is supposed to be, because it allows people to apply a new node or mark to that selection right-away.
|
||||
|
||||
## User experience
|
||||
When designing a great user experience you should consider a few things.
|
||||
|
||||
### Accessibility
|
||||
* Make sure users can navigate the menu with their keyboard
|
||||
* Use proper [title attributes](https://developer.mozilla.org/de/docs/Web/HTML/Global_attributes/title)
|
||||
* Use proper [aria attributes](https://developer.mozilla.org/en-US/docs/Learn/Accessibility/WAI-ARIA_basics)
|
||||
* List available keyboard shortcuts
|
||||
|
||||
:::warning Incomplete
|
||||
This section needs some work. Do you know what else needs to be taken into account when building an editor menu? Let us know on [GitHub](https://github.com/ueberdosis/tiptap-next) or send us an email to [humans@tiptap.dev](mailto:humans@tiptap.dev)!
|
||||
:::
|
||||
|
||||
### Icons
|
||||
Most editor menus use icons for their buttons. In some of our demos, we use the open-source icon set [Remix Icon](https://remixicon.com/), that’s free to use. But it’s totally up to you what you use. Here are a few icon sets you can consider:
|
||||
|
||||
* [Remix Icon](https://remixicon.com/#editor)
|
||||
* [Font Awesome](https://fontawesome.com/icons?c=editors)
|
||||
* [UI icons](https://www.ibm.com/design/language/iconography/ui-icons/library/)
|
||||
@@ -1,72 +0,0 @@
|
||||
# Create a toolbar
|
||||
|
||||
## toc
|
||||
|
||||
## Introduction
|
||||
tiptap comes very raw, but that’s a good thing. You have full control (and when we say full, we mean full) about the appearance of it. That also means you have to build the editor toolbar on your own. Don’t worry though, you can start with a few buttons and we help you with everything else.
|
||||
|
||||
## Commands
|
||||
Let’s assume you’ve got the editor running already and you want to add your first button. You’ll need a `<button>` HTML tag, and add a click handler. Depending on your setup, that can look like the following Vue.js example:
|
||||
|
||||
```html
|
||||
<button @click="editor.chain().toggleBold().focus().run()">
|
||||
Bold
|
||||
</button>
|
||||
```
|
||||
|
||||
Oh, that’s a long command, right? Actually, it’s a [chain of commands](/api/commands#chain-commands), so let’s go through this one by one:
|
||||
|
||||
```js
|
||||
editor.chain().toggleBold().focus().run()
|
||||
```
|
||||
|
||||
1. `editor` should be a tiptap instance,
|
||||
2. `chain()` is used to tell the editor you want to execute multiple commands,
|
||||
3. `focus()` sets the focus back to the editor,
|
||||
4. `toggleBold()` marks the selected text bold, or removes the bold mark from the text selection if it’s already applied and
|
||||
5. `run()` will execute the chain.
|
||||
|
||||
In other words: This will be the typical **Bold** button for your text editor.
|
||||
|
||||
Which commands are available depends on what extensions you’ve registered with the editor. Most of the extensions come with a `set…()`, `unset…()` and `toggle…()` command. Read the extension documentation to see what’s actually available or just surf through your code editor’s autocomplete.
|
||||
|
||||
## Keep the focus
|
||||
You’ve seen the `focus()` command in the above example already. When you click on the button, the browser focuses that DOM element and the editor loses focus. It’s likely you want to add `focus()` to all your toolbar buttons, so the writing flow of your users isn’t interrupted.
|
||||
|
||||
## The active state
|
||||
The editor provides an `isActive()` method to check if something is applied to the selected text already. In Vue.js you can toggle a CSS class with help of that function like that:
|
||||
|
||||
```html
|
||||
<button :class="{ 'is-active': editor.isActive('bold') }" @click="editor.chain().toggleBold().focus().run()">
|
||||
Bold
|
||||
</button>
|
||||
```
|
||||
|
||||
This toggles the `.is-active` class accordingly. This works for nodes, and marks. You can even check for specific attributes, here is an example with the [`Highlight`](/api/marks/highlight) mark, that ignores different attributes:
|
||||
|
||||
```js
|
||||
editor.isActive('highlight')
|
||||
```
|
||||
|
||||
And an example that compares the given attribute(s):
|
||||
|
||||
```js
|
||||
editor.isActive('highlight', { color: '#ffa8a8' })
|
||||
```
|
||||
|
||||
You can even ignore nodes and marks, but check for the attributes only. Here is an example with the [`TextAlign`](/api/extensions/text-align) extension:
|
||||
|
||||
```js
|
||||
editor.isActive({ textAlign: 'right' })
|
||||
```
|
||||
|
||||
If your selection spans multiple nodes or marks, or only part of the selection has a mark, `isActive()` will return `false` and indicate nothing is active. That is how it is supposed to be, because it allows people to apply a new node or mark to that selection right-away.
|
||||
|
||||
## Icons
|
||||
Most editor toolbars use icons for their buttons. In some of our demos, we use the open-source icon set [Remix Icon](https://remixicon.com/), that’s free to use. But it’s totally up to you what you use. Here are a few icon sets you can consider:
|
||||
|
||||
* [Remix Icon](https://remixicon.com/#editor)
|
||||
* [Font Awesome](https://fontawesome.com/icons?c=editors)
|
||||
* [UI icons](https://www.ibm.com/design/language/iconography/ui-icons/library/)
|
||||
|
||||
Also, we’re working on providing a configurable interface for tiptap. If you think that’s a great idea, [become a sponsor](/sponsor) to show us your support. ♥
|
||||
@@ -13,7 +13,7 @@ tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a
|
||||
Create exactly the rich text editor you want out of customizable building blocks. tiptap comes with sensible defaults, a lot of extensions and a friendly API to customize every aspect. It’s backed by a welcoming community, open-source, and free.
|
||||
|
||||
## Example
|
||||
<demo name="Examples/CollaborativeEditing" :show-source="false" inline />
|
||||
<demo name="Examples/CollaborativeEditing" hide-source inline />
|
||||
|
||||
## Features
|
||||
**Headless.** We don’t tell you what a menu should look like or where it should be rendered in the DOM. That’s why tiptap is headless and comes without any CSS. You are in full control over markup, styling and behaviour.
|
||||
|
||||
@@ -143,6 +143,9 @@ All new extensions come with specific commands to set, unset and toggle styles.
|
||||
| ~~`.underline()`~~ | `.toggleUnderline()` |
|
||||
| … | … |
|
||||
|
||||
### MenuBar, BubbleMenu and FloatingMenu
|
||||
Read the dedicated [guide on creating menus](/guide/menus) to migrate your menus.
|
||||
|
||||
### Commands can be chained now
|
||||
Most commands can be combined to one call now. That’s shorter than separate function calls in most cases. Here is an example to make the selected text bold:
|
||||
|
||||
|
||||
@@ -82,8 +82,9 @@
|
||||
items:
|
||||
- title: Configure the editor
|
||||
link: /guide/configuration
|
||||
- title: Create a toolbar
|
||||
link: /guide/toolbar
|
||||
- title: Create menus
|
||||
link: /guide/menus
|
||||
type: new
|
||||
- title: Custom styling
|
||||
link: /guide/styling
|
||||
- title: Accessibility
|
||||
@@ -131,6 +132,9 @@
|
||||
link: /api/nodes/bullet-list
|
||||
- title: CodeBlock
|
||||
link: /api/nodes/code-block
|
||||
- title: CodeBlockLowlight
|
||||
link: /api/nodes/code-block-lowlight
|
||||
type: draft
|
||||
- title: Document
|
||||
link: /api/nodes/document
|
||||
- title: Emoji
|
||||
|
||||
Reference in New Issue
Block a user