-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing reoccurring issue #3331 and improving related PR #3533 #3862
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,9 +75,7 @@ export class PureEditorContent extends React.Component<EditorContentProps, Edito | |
// lifecycle methods, and React doesn't allow calling flushSync from inside | ||
// a lifecycle method. | ||
if (this.initialized) { | ||
queueMicrotask(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this still prevent the initial issue we had before all those changes regarding the cursor position / rendering? Our Netlify build didn't work for this so I can't test it right now. I'll check it out on my machine in the meantime to test your changes. |
||
flushSync(fn) | ||
}) | ||
flushSync(fn) | ||
} else { | ||
fn() | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to test the behavior addressed in this PR, but I could not reproduce in Cypress environment.
But I think this example is still helpful to find this problem easily.