forked from ueberdosis/tiptap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing reoccurring issue ueberdosis#3331 and improving related PR ue…
…berdosis#3533 (ueberdosis#3862) * Add custom paragraph example * Remove unnecessary queueMicrotask
- Loading branch information
1 parent
c304b8c
commit b42bfce
Showing
11 changed files
with
220 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Paragraph as BaseParagraph } from '@tiptap/extension-paragraph' | ||
import { | ||
NodeViewContent, | ||
NodeViewWrapper, | ||
ReactNodeViewRenderer, | ||
} from '@tiptap/react' | ||
|
||
const ParagraphComponent = ({ node }) => { | ||
return ( | ||
<NodeViewWrapper style={{ position: 'relative' }}> | ||
<span contentEditable={false} className="label" style={{ | ||
position: 'absolute', right: '100%', fontSize: '10px', color: '#999', | ||
}}> | ||
{node.textContent.length} | ||
</span> | ||
<NodeViewContent as="p" /> | ||
</NodeViewWrapper> | ||
) | ||
} | ||
|
||
export const Paragraph = BaseParagraph.extend({ | ||
addNodeView() { | ||
return ReactNodeViewRenderer(ParagraphComponent) | ||
}, | ||
}) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import './styles.scss' | ||
|
||
import { EditorContent, useEditor } from '@tiptap/react' | ||
import StarterKit from '@tiptap/starter-kit' | ||
import React from 'react' | ||
|
||
import { Paragraph } from './Paragraph.jsx' | ||
|
||
export default () => { | ||
const editor = useEditor({ | ||
extensions: [ | ||
StarterKit.configure({ | ||
paragraph: false, | ||
}), | ||
Paragraph, | ||
], | ||
content: ` | ||
<p> | ||
Each line shows the number of characters in the paragraph. | ||
</p> | ||
`, | ||
}) | ||
|
||
return ( | ||
<EditorContent editor={editor} /> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
context('/src/Examples/CustomParagraph/React/', () => { | ||
beforeEach(() => { | ||
cy.visit('/src/Examples/CustomParagraph/React/') | ||
}) | ||
|
||
it('should have a working tiptap instance', () => { | ||
cy.get('.ProseMirror').then(([{ editor }]) => { | ||
// eslint-disable-next-line | ||
expect(editor).to.not.be.null | ||
}) | ||
}) | ||
|
||
it('should have a paragraph and text length', () => { | ||
cy.get('.ProseMirror p').should('exist').should('have.text', 'Each line shows the number of characters in the paragraph.') | ||
cy.get('.ProseMirror .label').should('exist').should('have.text', '58') | ||
}) | ||
|
||
it('should have new paragraph', () => { | ||
cy.get('.ProseMirror').type('{selectall}{moveToEnd}{enter}') | ||
cy.get('.ProseMirror p').eq(1).should('exist').should('have.text', '') | ||
cy.get('.ProseMirror .label').eq(1).should('exist').should('have.text', '0') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* Basic editor styles */ | ||
.ProseMirror { | ||
> * + * { | ||
margin-top: 0.75em; | ||
} | ||
} | ||
|
||
/* Placeholder (at the top) */ | ||
/*.ProseMirror p.is-editor-empty:first-child::before { | ||
content: attr(data-placeholder); | ||
float: left; | ||
color: #ced4da; | ||
pointer-events: none; | ||
height: 0; | ||
}*/ | ||
|
||
/* Placeholder (on every new line) */ | ||
.ProseMirror .is-empty::before { | ||
content: attr(data-placeholder); | ||
float: left; | ||
color: #ced4da; | ||
pointer-events: none; | ||
height: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<template> | ||
<node-view-wrapper class="vue-component"> | ||
<span contenteditable="false" class="label">{{ node.textContent.length }}</span> | ||
<node-view-content as="p" /> | ||
</node-view-wrapper> | ||
</template> | ||
|
||
<script> | ||
import { NodeViewContent, nodeViewProps, NodeViewWrapper } from '@tiptap/vue-3' | ||
export default { | ||
components: { | ||
NodeViewWrapper, | ||
NodeViewContent, | ||
}, | ||
props: nodeViewProps, | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
.vue-component { | ||
position: relative; | ||
} | ||
.label { | ||
position: absolute; | ||
right: 100%; | ||
font-size: 10px; | ||
color: #999; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Paragraph as BaseParagraph } from '@tiptap/extension-paragraph' | ||
import { VueNodeViewRenderer } from '@tiptap/vue-3' | ||
|
||
import Component from './Component.vue' | ||
|
||
export default BaseParagraph.extend({ | ||
addNodeView() { | ||
return VueNodeViewRenderer(Component) | ||
}, | ||
}) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
context('/src/Examples/CustomParagraph/React/', () => { | ||
beforeEach(() => { | ||
cy.visit('/src/Examples/CustomParagraph/React/') | ||
}) | ||
|
||
it('should have a working tiptap instance', () => { | ||
cy.get('.ProseMirror').then(([{ editor }]) => { | ||
// eslint-disable-next-line | ||
expect(editor).to.not.be.null | ||
}) | ||
}) | ||
|
||
it('should have a paragraph and text length', () => { | ||
cy.get('.ProseMirror p').should('exist').should('have.text', 'Each line shows the number of characters in the paragraph.') | ||
cy.get('.ProseMirror .label').should('exist').should('have.text', '58') | ||
}) | ||
|
||
it('should have new paragraph', () => { | ||
cy.get('.ProseMirror').type('{selectall}{moveToEnd}{enter}') | ||
cy.get('.ProseMirror p').eq(1).should('exist').should('have.text', '') | ||
cy.get('.ProseMirror .label').eq(1).should('exist').should('have.text', '0') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<template> | ||
<editor-content :editor="editor" /> | ||
</template> | ||
|
||
<script> | ||
import StarterKit from '@tiptap/starter-kit' | ||
import { Editor, EditorContent } from '@tiptap/vue-3' | ||
import Paragraph from './Extension.js' | ||
export default { | ||
components: { | ||
EditorContent, | ||
}, | ||
data() { | ||
return { | ||
editor: null, | ||
} | ||
}, | ||
mounted() { | ||
this.editor = new Editor({ | ||
extensions: [ | ||
StarterKit.configure({ | ||
paragraph: false, | ||
}), | ||
Paragraph, | ||
], | ||
content: ` | ||
<p> | ||
Each line shows the number of characters in the paragraph. | ||
</p> | ||
<p> | ||
Hello, custom paragraph! | ||
</p> | ||
`, | ||
}) | ||
}, | ||
beforeUnmount() { | ||
this.editor.destroy() | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
/* Basic editor styles */ | ||
.ProseMirror { | ||
> * + * { | ||
margin-top: 0.75em; | ||
} | ||
} | ||
</style> | ||
n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters