diff --git a/docs/src/demos/Examples/MarkdownShortcuts/index.spec.js b/docs/src/demos/Examples/MarkdownShortcuts/index.spec.js index 5cbd292e..4502f7bf 100644 --- a/docs/src/demos/Examples/MarkdownShortcuts/index.spec.js +++ b/docs/src/demos/Examples/MarkdownShortcuts/index.spec.js @@ -10,117 +10,91 @@ context('/examples/markdown-shortcuts', () => { describe('headlines', () => { it('should make a h1', () => { - cy.get('.ProseMirror').window().then(window => { - cy.get('.ProseMirror') - .type('# Headline', {force: true}) - .contains('h1', 'Headline') - }) + cy.get('.ProseMirror') + .type('# Headline', {force: true}) + .contains('h1', 'Headline') }) it('should make a h2', () => { - cy.get('.ProseMirror').window().then(window => { - cy.get('.ProseMirror') - .type('## Headline', {force: true}) - .contains('h2', 'Headline') - }) + cy.get('.ProseMirror') + .type('## Headline', {force: true}) + .contains('h2', 'Headline') }) it('should make a h3', () => { - cy.get('.ProseMirror').window().then(window => { - cy.get('.ProseMirror') - .type('### Headline', {force: true}) - .contains('h3', 'Headline') - }) + cy.get('.ProseMirror') + .type('### Headline', {force: true}) + .contains('h3', 'Headline') }) it('should make a h4', () => { - cy.get('.ProseMirror').window().then(window => { - cy.get('.ProseMirror') - .type('#### Headline', {force: true}) - .contains('h4', 'Headline') - }) + cy.get('.ProseMirror') + .type('#### Headline', {force: true}) + .contains('h4', 'Headline') }) it('should make a h5', () => { - cy.get('.ProseMirror').window().then(window => { - cy.get('.ProseMirror') - .type('##### Headline', {force: true}) - .contains('h5', 'Headline') - }) + cy.get('.ProseMirror') + .type('##### Headline', {force: true}) + .contains('h5', 'Headline') }) it('should make a h6', () => { - cy.get('.ProseMirror').window().then(window => { - cy.get('.ProseMirror') - .type('###### Headline', {force: true}) - .contains('h6', 'Headline') - }) + cy.get('.ProseMirror') + .type('###### Headline', {force: true}) + .contains('h6', 'Headline') }) }) describe('code', () => { it('should create inline code', () => { - cy.get('.ProseMirror').window().then(window => { - cy.get('.ProseMirror') - .type('`$foobar`', {force: true}) - .contains('code', '$foobar') - }) + cy.get('.ProseMirror') + .type('`$foobar`', {force: true}) + .contains('code', '$foobar') }) }) describe('code block', () => { it.skip('should create a code block without language', () => { - cy.get('.ProseMirror').window().then(window => { - cy.get('.ProseMirror') - .type('``` {enter}const foo = bar{enter}```', {force: true}) - .contains('pre', 'const foo = bar') - }) + cy.get('.ProseMirror') + .type('``` {enter}const foo = bar{enter}```', {force: true}) + .contains('pre', 'const foo = bar') }) }) describe('bullet list', () => { it.skip('should create a bullet list from asteriks', () => { - cy.get('.ProseMirror').window().then(window => { - cy.get('.ProseMirror') - .type('* foobar', {force: true}) - .contains('ul', 'foobar') - }) + cy.get('.ProseMirror') + .type('* foobar', {force: true}) + .contains('ul', 'foobar') }) it.skip('should create a bullet list from dashes', () => { - cy.get('.ProseMirror').window().then(window => { - cy.get('.ProseMirror') - .type('- foobar', {force: true}) - .contains('ul', 'foobar') - }) + cy.get('.ProseMirror') + .type('- foobar', {force: true}) + .contains('ul', 'foobar') }) it.skip('should create a bullet list from pluses', () => { - cy.get('.ProseMirror').window().then(window => { - cy.get('.ProseMirror') - .type('+ foobar', {force: true}) - .contains('ul', 'foobar') - }) + cy.get('.ProseMirror') + .type('+ foobar', {force: true}) + .contains('ul', 'foobar') }) }) describe('ordered list', () => { it.skip('should create a ordered list', () => { - cy.get('.ProseMirror').window().then(window => { - cy.get('.ProseMirror') - .type('1. foobar', {force: true}) - .contains('ol', 'foobar') - }) + cy.get('.ProseMirror') + .type('1. foobar', {force: true}) + .contains('ol', 'foobar') }) }) describe('blockquote', () => { it.skip('should create a blockquote', () => { - cy.get('.ProseMirror').window().then(window => { - cy.get('.ProseMirror') - .type('> foobar', {force: true}) - .contains('blockquote', 'foobar') - }) + cy.get('.ProseMirror') + .type('> foobar', {force: true}) + .contains('blockquote', 'foobar') }) }) }) \ No newline at end of file diff --git a/docs/src/demos/Extensions/Bold/index.spec.js b/docs/src/demos/Extensions/Bold/index.spec.js index 85a66e41..8d54f47b 100644 --- a/docs/src/demos/Extensions/Bold/index.spec.js +++ b/docs/src/demos/Extensions/Bold/index.spec.js @@ -21,16 +21,12 @@ context('/api/extensions/bold', () => { }) it('the keyboard shortcut should make the selected text bold', () => { - const shortcut = Cypress.platform === 'darwin' ? '{meta}b' : '{ctrl}b' - - cy.get('.ProseMirror').type(shortcut, {force: true}) + cy.get('.ProseMirror').type('{meta}b', {force: true}) cy.get('.ProseMirror').contains('strong', 'Example Text') }) it('the keyboard shortcut should toggle the selected text bold', () => { - const shortcut = Cypress.platform === 'darwin' ? '{meta}b' : '{ctrl}b' - - cy.get('.ProseMirror').type(shortcut, {force: true}).type(shortcut, {force: true}) + cy.get('.ProseMirror').type('{meta}b', {force: true}).type('{meta}b', {force: true}) cy.get('.ProseMirror strong').should('not.exist') }) }) diff --git a/docs/src/demos/Extensions/History/index.spec.js b/docs/src/demos/Extensions/History/index.spec.js index 75d2f2ad..d3d571c8 100644 --- a/docs/src/demos/Extensions/History/index.spec.js +++ b/docs/src/demos/Extensions/History/index.spec.js @@ -19,9 +19,7 @@ context('/api/extensions/history', () => { }) it('the keyboard shortcut should make the last change undone', () => { - const shortcut = Cypress.platform === 'darwin' ? '{meta}z' : '{ctrl}z' - - cy.get('.ProseMirror').type(shortcut, {force: true}) + cy.get('.ProseMirror').type('{meta}z', {force: true}) cy.get('.ProseMirror').should('not.contain', 'Mistake') }) }) @@ -39,13 +37,10 @@ context('/api/extensions/history', () => { }) it.skip('the keyboard shortcut should apply the last undone change again', () => { - const undoShortcut = Cypress.platform === 'darwin' ? '{meta}z' : '{ctrl}z' - const redoShortcut = Cypress.platform === 'darwin' ? '{meta}{shift}z' : '{ctrl}{shift}z' - - cy.get('.ProseMirror').type(undoShortcut, {force: true}) + cy.get('.ProseMirror').type('{meta}z', {force: true}) cy.get('.ProseMirror').should('not.contain', 'Mistake') - cy.get('.ProseMirror').type(redoShortcut, {force: true}) + cy.get('.ProseMirror').type('{meta}{shift}z', {force: true}) cy.get('.ProseMirror').should('contain', 'Mistake') }) }) diff --git a/docs/src/demos/Extensions/Italic/index.spec.js b/docs/src/demos/Extensions/Italic/index.spec.js index 8aad2e17..4abfaac9 100644 --- a/docs/src/demos/Extensions/Italic/index.spec.js +++ b/docs/src/demos/Extensions/Italic/index.spec.js @@ -21,16 +21,12 @@ context('/api/extensions/italic', () => { }) it('the keyboard shortcut should make the selected text italic', () => { - const shortcut = Cypress.platform === 'darwin' ? '{meta}i' : '{ctrl}i' - - cy.get('.ProseMirror').type(shortcut, {force: true}) + cy.get('.ProseMirror').type('{meta}i', {force: true}) cy.get('.ProseMirror').contains('em', 'Example Text') }) it('the keyboard shortcut should toggle the selected text italic', () => { - const shortcut = Cypress.platform === 'darwin' ? '{meta}i' : '{ctrl}i' - - cy.get('.ProseMirror').type(shortcut, {force: true}).type(shortcut, {force: true}) + cy.get('.ProseMirror').type('{meta}i', {force: true}).type('{meta}i', {force: true}) cy.get('.ProseMirror em').should('not.exist') }) }) diff --git a/docs/src/docPages/api/extensions/blockquote.md b/docs/src/docPages/api/extensions/blockquote.md index c31b079b..b6d4e9c8 100644 --- a/docs/src/docPages/api/extensions/blockquote.md +++ b/docs/src/docPages/api/extensions/blockquote.md @@ -13,7 +13,7 @@ Type `> ` on the beginning of a new line and it will be magically transformed to | ---------- | ------- | ----------------------------- | | blockquote | — | Wrap content in a blockquote. | -## Keybindings +## Keyboard shortcuts * Windows & Linux: `Control` + `Shift` + `9` * macOS: `Command` + `Shift` + `9` diff --git a/docs/src/docPages/api/extensions/bold.md b/docs/src/docPages/api/extensions/bold.md index e3a7682b..f7daa154 100644 --- a/docs/src/docPages/api/extensions/bold.md +++ b/docs/src/docPages/api/extensions/bold.md @@ -17,7 +17,7 @@ The extension will generate the corresponding `` HTML tags when reading | ------- | ------- | --------------- | | bold | — | Mark text bold. | -## Keybindings +## Keyboard shortcuts * Windows & Linux: `Control` + `B` * macOS: `Command` + `B` diff --git a/docs/src/docPages/api/extensions/bullet-list.md b/docs/src/docPages/api/extensions/bullet-list.md index dec853eb..ce140970 100644 --- a/docs/src/docPages/api/extensions/bullet-list.md +++ b/docs/src/docPages/api/extensions/bullet-list.md @@ -15,7 +15,7 @@ It’s intended to be used with the `ListItem` extension. | ----------- | ------- | --------------------- | | bullet_list | — | Toggle a bullet list. | -## Keybindings +## Keyboard shortcuts * `Control` + `Shift` + `8` ## Usage diff --git a/docs/src/docPages/api/extensions/code-block-highlight.md b/docs/src/docPages/api/extensions/code-block-highlight.md index 80cce042..0d8e7d99 100644 --- a/docs/src/docPages/api/extensions/code-block-highlight.md +++ b/docs/src/docPages/api/extensions/code-block-highlight.md @@ -7,5 +7,5 @@ Enables you to use the `
` HTML tag with auto-detected syntax highlighting i
 ## Commands
 *None*
 
-## Keybindings
+## Keyboard shortcuts
 *None*
\ No newline at end of file
diff --git a/docs/src/docPages/api/extensions/code-block.md b/docs/src/docPages/api/extensions/code-block.md
index 71e3b08d..11e44289 100644
--- a/docs/src/docPages/api/extensions/code-block.md
+++ b/docs/src/docPages/api/extensions/code-block.md
@@ -7,5 +7,5 @@ Enables you to use the `
` HTML tag in the editor.
 ## Commands
 *None*
 
-## Keybindings
+## Keyboard shortcuts
 *None*
\ No newline at end of file
diff --git a/docs/src/docPages/api/extensions/code.md b/docs/src/docPages/api/extensions/code.md
index 034a337c..147a9b13 100644
--- a/docs/src/docPages/api/extensions/code.md
+++ b/docs/src/docPages/api/extensions/code.md
@@ -11,7 +11,7 @@ The Code extensions enables you to use the `` HTML tag in the editor. If y
 | ------- | ------- | ------------------------- |
 | code    | —       | Mark text as inline code. |
 
-## Keybindings
+## Keyboard shortcuts
 * `Alt` + `
 
 ## Source Code
diff --git a/docs/src/docPages/api/extensions/hard-break.md b/docs/src/docPages/api/extensions/hard-break.md
index 9e1e84ac..0741a68a 100644
--- a/docs/src/docPages/api/extensions/hard-break.md
+++ b/docs/src/docPages/api/extensions/hard-break.md
@@ -4,6 +4,6 @@ Enables you to use the `
` HTML tag in the editor. ## Options *None* -## Keybindings +## Keyboard shortcuts * `Command` + `Enter` * `Shift` + `Enter` \ No newline at end of file diff --git a/docs/src/docPages/api/extensions/heading.md b/docs/src/docPages/api/extensions/heading.md index b39aca38..7c4e1965 100644 --- a/docs/src/docPages/api/extensions/heading.md +++ b/docs/src/docPages/api/extensions/heading.md @@ -12,7 +12,7 @@ Enables you to use headline HTML tags in the editor. | ------- | ------- | ----------------------- | | heading | level | Creates a heading node. | -## Keybindings +## Keyboard shortcuts * `Control` + `Shift` + `1` → H1 * `Control` + `Shift` + `2` → H2 * `Control` + `Shift` + `3` → H3 diff --git a/docs/src/docPages/api/extensions/history.md b/docs/src/docPages/api/extensions/history.md index 363ec10f..a4900072 100644 --- a/docs/src/docPages/api/extensions/history.md +++ b/docs/src/docPages/api/extensions/history.md @@ -10,7 +10,7 @@ This extension provides history support. All changes to the document will be tra | undo | — | Undo the last change. | | redo | — | Redo the last change. | -## Keybindings +## Keyboard shortcuts * Windows & Linux: `Control` + `Z` * macOS: `Command` + `Z` diff --git a/docs/src/docPages/api/extensions/horizontal-rule.md b/docs/src/docPages/api/extensions/horizontal-rule.md index db333b61..5c64e87f 100644 --- a/docs/src/docPages/api/extensions/horizontal-rule.md +++ b/docs/src/docPages/api/extensions/horizontal-rule.md @@ -11,7 +11,7 @@ Enables you to use the `
` HTML tag in the editor. | --------------- | ------- | ------------------------- | | horizontal_rule | — | Create a horizontal rule. | -## Keybindings +## Keyboard shortcuts *None* ## Usage diff --git a/docs/src/docPages/api/extensions/italic.md b/docs/src/docPages/api/extensions/italic.md index 625bf543..892453ef 100644 --- a/docs/src/docPages/api/extensions/italic.md +++ b/docs/src/docPages/api/extensions/italic.md @@ -15,7 +15,7 @@ The extension will generate the corresponding `` HTML tags when reading cont | ------- | ------- | ----------------- | | italic | — | Mark text italic. | -## Keybindings +## Keyboard shortcuts * Windows & Linux: `Control` + `I` * macOS: `Command` + `I` diff --git a/docs/src/docPages/api/extensions/ordered-list.md b/docs/src/docPages/api/extensions/ordered-list.md index af958466..f53326fd 100644 --- a/docs/src/docPages/api/extensions/ordered-list.md +++ b/docs/src/docPages/api/extensions/ordered-list.md @@ -15,7 +15,7 @@ This extensions is intended to be used with the `ListItem` extension. | ------------ | ------- | ----------------------- | | ordered_list | — | Toggle an ordered list. | -## Keybindings +## Keyboard shortcuts * `Control` + `Shift` + `9` ## Usage diff --git a/docs/src/docPages/api/extensions/paragraph.md b/docs/src/docPages/api/extensions/paragraph.md index afa82f97..b6326538 100644 --- a/docs/src/docPages/api/extensions/paragraph.md +++ b/docs/src/docPages/api/extensions/paragraph.md @@ -9,7 +9,7 @@ Yes, the schema is very strict. Without this extension you won’t even be able ## Commands *None* -## Keybindings +## Keyboard shortcuts *None* ## Source Code diff --git a/docs/src/docPages/api/extensions/strike.md b/docs/src/docPages/api/extensions/strike.md index 061c8ba8..d562d6cc 100644 --- a/docs/src/docPages/api/extensions/strike.md +++ b/docs/src/docPages/api/extensions/strike.md @@ -11,7 +11,7 @@ Enables you to use the `` HTML tag in the editor. | ------- | ------- | --------------------------- | | strike | — | Mark text as strikethrough. | -## Keybindings +## Keyboard shortcuts * Windows & Linux: `Control` + `D` * macOS: `Command` + `D` diff --git a/docs/src/docPages/api/extensions/todo-item.md b/docs/src/docPages/api/extensions/todo-item.md index 729fed80..f1a8cef7 100644 --- a/docs/src/docPages/api/extensions/todo-item.md +++ b/docs/src/docPages/api/extensions/todo-item.md @@ -13,5 +13,5 @@ This extensions is intended to be used with the `TodoList` extension. ## Commands *None* -## Keybindings +## Keyboard shortcuts *None* \ No newline at end of file diff --git a/docs/src/docPages/api/extensions/todo-list.md b/docs/src/docPages/api/extensions/todo-list.md index c4718f1c..620a8011 100644 --- a/docs/src/docPages/api/extensions/todo-list.md +++ b/docs/src/docPages/api/extensions/todo-list.md @@ -13,7 +13,7 @@ This extensions is intended to be used with the `TodoItem` extension. | --------- | ------- | ----------------- | | todo_list | — | Toggle todo list. | -## Keybindings +## Keyboard shortcuts *None* ## Usage diff --git a/docs/src/docPages/api/extensions/underline.md b/docs/src/docPages/api/extensions/underline.md index 89e115d0..3c4c57d5 100644 --- a/docs/src/docPages/api/extensions/underline.md +++ b/docs/src/docPages/api/extensions/underline.md @@ -11,7 +11,7 @@ Enables you to use the `` HTML tag in the editor. | --------- | ------- | ------------------------ | | underline | — | Mark text as underlined. | -## Keybindings +## Keyboard shortcuts * Windows & Linux: `Control` + `U` * macOS: `Command` + `U` diff --git a/packages/extension-bold/index.ts b/packages/extension-bold/index.ts index e4e7b0a6..ca93bd55 100644 --- a/packages/extension-bold/index.ts +++ b/packages/extension-bold/index.ts @@ -29,7 +29,7 @@ export default new Mark() ], toDOM: () => ['strong', 0], })) - .commands(({ editor, name, type }) => ({ + .commands(({ editor, name }) => ({ bold: next => () => { editor.toggleMark(name) next() diff --git a/packages/extension-strike/index.ts b/packages/extension-strike/index.ts new file mode 100644 index 00000000..350648c4 --- /dev/null +++ b/packages/extension-strike/index.ts @@ -0,0 +1,47 @@ +import { Mark, markInputRule, markPasteRule } from '@tiptap/core' + +declare module '@tiptap/core/src/Editor' { + interface Editor { + strike(): Editor, + } +} + +export const inputRegex = /(?:^|\s)((?:~)((?:[^~]+))(?:~))$/gm +export const pasteRegex = /(?:^|\s)((?:~)((?:[^~]+))(?:~))/gm + +export default new Mark() + .name('strike') + .schema(() => ({ + parseDOM: [ + { + tag: 's', + }, + { + tag: 'del', + }, + { + tag: 'strike', + }, + { + style: 'text-decoration', + getAttrs: node => node === 'line-through' ? {} : false, + }, + ], + toDOM: () => ['s', 0], + })) + .commands(({ editor, name }) => ({ + strike: next => () => { + editor.toggleMark(name) + next() + }, + })) + .keys(({ editor }) => ({ + 'Mod-d': () => editor.strike() + })) + .inputRules(({ type }) => [ + markInputRule(inputRegex, type) + ]) + .pasteRules(({ type }) => [ + markPasteRule(inputRegex, type) + ]) + .create() diff --git a/packages/extension-strike/package.json b/packages/extension-strike/package.json new file mode 100644 index 00000000..6e024b03 --- /dev/null +++ b/packages/extension-strike/package.json @@ -0,0 +1,17 @@ +{ + "name": "@tiptap/extension-strike", + "version": "1.0.0", + "source": "index.ts", + "main": "dist/tiptap-extension-strike.js", + "umd:main": "dist/tiptap-extension-strike.umd.js", + "module": "dist/tiptap-extension-strike.mjs", + "unpkg": "dist/tiptap-extension-strike.js", + "jsdelivr": "dist/tiptap-extension-strike.js", + "files": [ + "src", + "dist" + ], + "peerDependencies": { + "@tiptap/core": "2.x" + } +} diff --git a/packages/extension-underline/index.ts b/packages/extension-underline/index.ts new file mode 100644 index 00000000..abb950fa --- /dev/null +++ b/packages/extension-underline/index.ts @@ -0,0 +1,32 @@ +import { Mark } from '@tiptap/core' + +declare module '@tiptap/core/src/Editor' { + interface Editor { + underline(): Editor, + } +} + +export default new Mark() + .name('underline') + .schema(() => ({ + parseDOM: [ + { + tag: 'u', + }, + { + style: 'text-decoration', + getAttrs: node => node === 'underline' ? {} : false, + }, + ], + toDOM: () => ['u', 0], + })) + .commands(({ editor, name }) => ({ + underline: next => () => { + editor.toggleMark(name) + next() + }, + })) + .keys(({ editor }) => ({ + 'Mod-u': () => editor.underline() + })) + .create() diff --git a/packages/extension-underline/package.json b/packages/extension-underline/package.json new file mode 100644 index 00000000..b39a9aa2 --- /dev/null +++ b/packages/extension-underline/package.json @@ -0,0 +1,17 @@ +{ + "name": "@tiptap/extension-underline", + "version": "1.0.0", + "source": "index.ts", + "main": "dist/tiptap-extension-underline.js", + "umd:main": "dist/tiptap-extension-underline.umd.js", + "module": "dist/tiptap-extension-underline.mjs", + "unpkg": "dist/tiptap-extension-underline.js", + "jsdelivr": "dist/tiptap-extension-underline.js", + "files": [ + "src", + "dist" + ], + "peerDependencies": { + "@tiptap/core": "2.x" + } +}