Merge branch 'main' into feature/blockquote-extension

This commit is contained in:
Hans Pagel 2020-09-10 11:25:25 +02:00 committed by GitHub
commit e92da4c966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 177 additions and 103 deletions

View File

@ -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')
})
})
})

View File

@ -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')
})
})

View File

@ -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')
})
})

View File

@ -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')
})
})

View File

@ -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`

View File

@ -17,7 +17,7 @@ The extension will generate the corresponding `<strong>` HTML tags when reading
| ------- | ------- | --------------- |
| bold | — | Mark text bold. |
## Keybindings
## Keyboard shortcuts
* Windows & Linux: `Control` + `B`
* macOS: `Command` + `B`

View File

@ -15,7 +15,7 @@ Its intended to be used with the `ListItem` extension.
| ----------- | ------- | --------------------- |
| bullet_list | — | Toggle a bullet list. |
## Keybindings
## Keyboard shortcuts
* `Control` + `Shift` + `8`
## Usage

View File

@ -7,5 +7,5 @@ Enables you to use the `<pre>` HTML tag with auto-detected syntax highlighting i
## Commands
*None*
## Keybindings
## Keyboard shortcuts
*None*

View File

@ -7,5 +7,5 @@ Enables you to use the `<pre>` HTML tag in the editor.
## Commands
*None*
## Keybindings
## Keyboard shortcuts
*None*

View File

@ -11,7 +11,7 @@ The Code extensions enables you to use the `<code>` HTML tag in the editor. If y
| ------- | ------- | ------------------------- |
| code | — | Mark text as inline code. |
## Keybindings
## Keyboard shortcuts
* `Alt` + `
## Source Code

View File

@ -4,6 +4,6 @@ Enables you to use the `<br>` HTML tag in the editor.
## Options
*None*
## Keybindings
## Keyboard shortcuts
* `Command` + `Enter`
* `Shift` + `Enter`

View File

@ -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

View File

@ -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`

View File

@ -11,7 +11,7 @@ Enables you to use the `<hr>` HTML tag in the editor.
| --------------- | ------- | ------------------------- |
| horizontal_rule | — | Create a horizontal rule. |
## Keybindings
## Keyboard shortcuts
*None*
## Usage

View File

@ -15,7 +15,7 @@ The extension will generate the corresponding `<em>` HTML tags when reading cont
| ------- | ------- | ----------------- |
| italic | — | Mark text italic. |
## Keybindings
## Keyboard shortcuts
* Windows & Linux: `Control` + `I`
* macOS: `Command` + `I`

View File

@ -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

View File

@ -9,7 +9,7 @@ Yes, the schema is very strict. Without this extension you wont even be able
## Commands
*None*
## Keybindings
## Keyboard shortcuts
*None*
## Source Code

View File

@ -11,7 +11,7 @@ Enables you to use the `<s>` HTML tag in the editor.
| ------- | ------- | --------------------------- |
| strike | — | Mark text as strikethrough. |
## Keybindings
## Keyboard shortcuts
* Windows & Linux: `Control` + `D`
* macOS: `Command` + `D`

View File

@ -13,5 +13,5 @@ This extensions is intended to be used with the `TodoList` extension.
## Commands
*None*
## Keybindings
## Keyboard shortcuts
*None*

View File

@ -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

View File

@ -11,7 +11,7 @@ Enables you to use the `<u>` HTML tag in the editor.
| --------- | ------- | ------------------------ |
| underline | — | Mark text as underlined. |
## Keybindings
## Keyboard shortcuts
* Windows & Linux: `Control` + `U`
* macOS: `Command` + `U`

View File

@ -29,7 +29,7 @@ export default new Mark()
],
toDOM: () => ['strong', 0],
}))
.commands(({ editor, name, type }) => ({
.commands(({ editor, name }) => ({
bold: next => () => {
editor.toggleMark(name)
next()

View File

@ -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()

View File

@ -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"
}
}

View File

@ -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()

View File

@ -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"
}
}