-
diff --git a/docs/src/demos/Nodes/HardBreak/index.vue b/docs/src/demos/Nodes/HardBreak/index.vue
index ea2bee88..64459920 100644
--- a/docs/src/demos/Nodes/HardBreak/index.vue
+++ b/docs/src/demos/Nodes/HardBreak/index.vue
@@ -1,6 +1,6 @@
-
+
hardBreak
diff --git a/docs/src/demos/Nodes/Heading/index.vue b/docs/src/demos/Nodes/Heading/index.vue
index b8d47e8e..cbeda076 100644
--- a/docs/src/demos/Nodes/Heading/index.vue
+++ b/docs/src/demos/Nodes/Heading/index.vue
@@ -1,12 +1,12 @@
-
+
h1
-
+
h2
-
+
h3
diff --git a/docs/src/demos/Nodes/HorizontalRule/index.vue b/docs/src/demos/Nodes/HorizontalRule/index.vue
index a2743866..14923124 100644
--- a/docs/src/demos/Nodes/HorizontalRule/index.vue
+++ b/docs/src/demos/Nodes/HorizontalRule/index.vue
@@ -1,6 +1,6 @@
-
+
horizontalRule
diff --git a/docs/src/demos/Nodes/Image/index.vue b/docs/src/demos/Nodes/Image/index.vue
index 061737f0..8c59b3bb 100644
--- a/docs/src/demos/Nodes/Image/index.vue
+++ b/docs/src/demos/Nodes/Image/index.vue
@@ -31,7 +31,7 @@ export default {
addImage() {
const url = window.prompt('URL')
- this.editor.chain().focus().image({ src: url }).run()
+ this.editor.chain().focus().setImage({ src: url }).run()
},
},
diff --git a/docs/src/demos/Nodes/TaskList/index.spec.js b/docs/src/demos/Nodes/TaskList/index.spec.js
index 34ef8a02..8d7db95e 100644
--- a/docs/src/demos/Nodes/TaskList/index.spec.js
+++ b/docs/src/demos/Nodes/TaskList/index.spec.js
@@ -12,15 +12,15 @@ context('/api/nodes/task-list', () => {
it('should parse unordered lists correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
- editor.commands.setContent('')
- expect(editor.getHTML()).to.eq('')
+ editor.commands.setContent('')
+ expect(editor.getHTML()).to.eq('')
})
})
it('should parse unordered lists without paragraphs correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
- editor.commands.setContent('')
- expect(editor.getHTML()).to.eq('')
+ editor.commands.setContent('')
+ expect(editor.getHTML()).to.eq('')
})
})
@@ -35,11 +35,11 @@ context('/api/nodes/task-list', () => {
.click()
cy.get('.ProseMirror')
- .find('ul[data-type="task_list"]')
+ .find('ul[data-type="taskList"]')
.should('contain', 'Example Text')
cy.get('.ProseMirror')
- .find('ul[data-type="task_list"] li')
+ .find('ul[data-type="taskList"] li')
.should('contain', 'Example Text')
})
@@ -51,7 +51,7 @@ context('/api/nodes/task-list', () => {
.click()
cy.get('.ProseMirror')
- .find('ul[data-type="task_list"]')
+ .find('ul[data-type="taskList"]')
.should('contain', 'Example Text')
cy.get('.demo__preview button:nth-child(1)')
diff --git a/docs/src/docPages/guide/working-with-typescript.md b/docs/src/docPages/guide/working-with-typescript.md
index a7aed418..0e4a1a01 100644
--- a/docs/src/docPages/guide/working-with-typescript.md
+++ b/docs/src/docPages/guide/working-with-typescript.md
@@ -14,7 +14,7 @@ If you’re using TypeScript in your project and want to extend tiptap, there ar
## Options type
To extend or create default options for an extension, you’ll need to define a custom type, here is an example:
-```js
+```ts
import { Extension } from '@tiptap/core'
export interface CustomExtensionOptions {
@@ -31,7 +31,7 @@ const CustomExtension = Extension.create({
## Command type
The core package also exports a `Command` type, which needs to be added to all commands that you specify in your code. Here is an example:
-```js
+```ts
import { Command, Extension } from '@tiptap/core'
const CustomExtension = Extension.create({
diff --git a/docs/src/main.js b/docs/src/main.js
index c1966e16..2257fc1d 100644
--- a/docs/src/main.js
+++ b/docs/src/main.js
@@ -1,6 +1,7 @@
// eslint-disable-next-line
import Prism from 'prismjs'
import 'prismjs/components/prism-jsx.js'
+import 'prismjs/components/prism-typescript.js'
import 'prismjs/components/prism-scss.js'
import PortalVue from 'portal-vue'
import App from '~/layouts/App'
diff --git a/packages/core/src/commands/updateNodeAttributes.ts b/packages/core/src/commands/updateNodeAttributes.ts
index 1ac80d3b..4fd60868 100644
--- a/packages/core/src/commands/updateNodeAttributes.ts
+++ b/packages/core/src/commands/updateNodeAttributes.ts
@@ -1,11 +1,14 @@
+import { NodeType } from 'prosemirror-model'
+import getNodeType from '../utils/getNodeType'
import { Command } from '../types'
-export default (attributes: {}): Command => ({ tr, state, dispatch }) => {
+export default (typeOrName: string | NodeType, attributes: {}): Command => ({ tr, state, dispatch }) => {
+ const type = getNodeType(typeOrName, state.schema)
const { selection } = tr
const { from, to } = selection
state.doc.nodesBetween(from, to, (node, pos) => {
- if (!node.type.isText && dispatch) {
+ if (node.type === type && dispatch) {
tr.setNodeMarkup(pos, undefined, {
...node.attrs,
...attributes,
diff --git a/packages/extension-hard-break/src/index.ts b/packages/extension-hard-break/src/index.ts
index 677b0941..22a24e81 100644
--- a/packages/extension-hard-break/src/index.ts
+++ b/packages/extension-hard-break/src/index.ts
@@ -25,7 +25,7 @@ const HardBreak = Node.create({
/**
* Add a hard break
*/
- hardBreak: (): Command => ({ commands, state, dispatch }) => {
+ setHardBreak: (): Command => ({ commands, state, dispatch }) => {
return commands.try([
() => exitCode(state, dispatch),
() => {
@@ -42,8 +42,8 @@ const HardBreak = Node.create({
addKeyboardShortcuts() {
return {
- 'Mod-Enter': () => this.editor.commands.hardBreak(),
- 'Shift-Enter': () => this.editor.commands.hardBreak(),
+ 'Mod-Enter': () => this.editor.commands.setHardBreak(),
+ 'Shift-Enter': () => this.editor.commands.setHardBreak(),
}
},
})
diff --git a/packages/extension-heading/src/index.ts b/packages/extension-heading/src/index.ts
index c02b8a81..a9a1ee39 100644
--- a/packages/extension-heading/src/index.ts
+++ b/packages/extension-heading/src/index.ts
@@ -53,14 +53,24 @@ const Heading = Node.create({
addCommands() {
return {
/**
- * Toggle a heading node
+ * Set a heading node
*/
- heading: (options: { level: Level }): Command => ({ commands }) => {
- if (!this.options.levels.includes(options.level)) {
+ setHeading: (attributes: { level: Level }): Command => ({ commands }) => {
+ if (!this.options.levels.includes(attributes.level)) {
return false
}
- return commands.toggleBlockType('heading', 'paragraph', options)
+ return commands.setBlockType('heading', attributes)
+ },
+ /**
+ * Toggle a heading node
+ */
+ toggleHeading: (attributes: { level: Level }): Command => ({ commands }) => {
+ if (!this.options.levels.includes(attributes.level)) {
+ return false
+ }
+
+ return commands.toggleBlockType('heading', 'paragraph', attributes)
},
}
},
@@ -69,7 +79,7 @@ const Heading = Node.create({
return this.options.levels.reduce((items, level) => ({
...items,
...{
- [`Mod-Alt-${level}`]: () => this.editor.commands.setBlockType('heading', { level }),
+ [`Mod-Alt-${level}`]: () => this.editor.commands.toggleHeading({ level }),
},
}), {})
},
diff --git a/packages/extension-horizontal-rule/src/index.ts b/packages/extension-horizontal-rule/src/index.ts
index ebab3e3b..a6765ddc 100644
--- a/packages/extension-horizontal-rule/src/index.ts
+++ b/packages/extension-horizontal-rule/src/index.ts
@@ -30,8 +30,10 @@ const HorizontalRule = Node.create({
/**
* Add a horizontal rule
*/
- horizontalRule: (): Command => ({ tr }) => {
- tr.replaceSelectionWith(this.type.create())
+ setHorizontalRule: (): Command => ({ tr, dispatch }) => {
+ if (dispatch) {
+ tr.replaceSelectionWith(this.type.create())
+ }
return true
},
diff --git a/packages/extension-image/src/index.ts b/packages/extension-image/src/index.ts
index 7eeb831b..a4c67761 100644
--- a/packages/extension-image/src/index.ts
+++ b/packages/extension-image/src/index.ts
@@ -58,11 +58,13 @@ const Image = Node.create({
/**
* Add an image
*/
- image: (options: { src: string, alt?: string, title?: string }): Command => ({ tr }) => {
+ setImage: (options: { src: string, alt?: string, title?: string }): Command => ({ tr, dispatch }) => {
const { selection } = tr
const node = this.type.create(options)
- tr.replaceRangeWith(selection.from, selection.to, node)
+ if (dispatch) {
+ tr.replaceRangeWith(selection.from, selection.to, node)
+ }
return true
},
diff --git a/packages/extension-paragraph/src/index.ts b/packages/extension-paragraph/src/index.ts
index 961d08eb..ffe062c1 100644
--- a/packages/extension-paragraph/src/index.ts
+++ b/packages/extension-paragraph/src/index.ts
@@ -32,7 +32,7 @@ const Paragraph = Node.create({
/**
* Toggle a paragraph
*/
- paragraph: (): Command => ({ commands }) => {
+ setParagraph: (): Command => ({ commands }) => {
return commands.toggleBlockType('paragraph', 'paragraph')
},
}
@@ -40,7 +40,7 @@ const Paragraph = Node.create({
addKeyboardShortcuts() {
return {
- 'Mod-Alt-0': () => this.editor.commands.paragraph(),
+ 'Mod-Alt-0': () => this.editor.commands.setParagraph(),
}
},
})
diff --git a/packages/extension-text-align/src/index.ts b/packages/extension-text-align/src/index.ts
index 63fb2279..7477e145 100644
--- a/packages/extension-text-align/src/index.ts
+++ b/packages/extension-text-align/src/index.ts
@@ -35,14 +35,20 @@ const TextAlign = Extension.create({
addCommands() {
return {
/**
- * Update the text align attribute
+ * Set the text align attribute
*/
- textAlign: (alignment: string): Command => ({ commands }) => {
+ setTextAlign: (alignment: string): Command => ({ commands }) => {
if (!this.options.alignments.includes(alignment)) {
return false
}
- return commands.updateNodeAttributes({ textAlign: alignment })
+ return this.options.types.every(type => commands.updateNodeAttributes(type, { textAlign: alignment }))
+ },
+ /**
+ * Unset the text align attribute
+ */
+ unsetTextAlign: (): Command => ({ commands }) => {
+ return this.options.types.every(type => commands.updateNodeAttributes(type, { textAlign: null }))
},
}
},
@@ -55,10 +61,10 @@ const TextAlign = Extension.create({
Enter: () => this.editor.commands.splitBlock({
withAttributes: true,
}),
- 'Ctrl-Shift-l': () => this.editor.commands.textAlign('left'),
- 'Ctrl-Shift-e': () => this.editor.commands.textAlign('center'),
- 'Ctrl-Shift-r': () => this.editor.commands.textAlign('right'),
- 'Ctrl-Shift-j': () => this.editor.commands.textAlign('justify'),
+ 'Ctrl-Shift-l': () => this.editor.commands.setTextAlign('left'),
+ 'Ctrl-Shift-e': () => this.editor.commands.setTextAlign('center'),
+ 'Ctrl-Shift-r': () => this.editor.commands.setTextAlign('right'),
+ 'Ctrl-Shift-j': () => this.editor.commands.setTextAlign('justify'),
}
},
})