-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix emptyTextBlock detection to handle leaf nodes too (#5838)
* fix: #4327 * merge forked PR --------- Co-authored-by: Tony Hallett <[email protected]>
- Loading branch information
1 parent
ca6269e
commit d9b6ef5
Showing
10 changed files
with
197 additions
and
4 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,5 @@ | ||
--- | ||
"@tiptap/extension-floating-menu": patch | ||
--- | ||
|
||
Fixed an issue that cause the floating menu empty-node check to not respect leaf nodes that didn't count into a nodes text content |
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,26 @@ | ||
import { mergeAttributes, Node } from '@tiptap/core' | ||
|
||
export default Node.create({ | ||
name: 'foo', | ||
|
||
group: 'inline', | ||
|
||
inline: true, | ||
|
||
parseHTML() { | ||
return [ | ||
{ | ||
tag: 'span', | ||
getAttrs: node => (node as HTMLElement).hasAttribute('data-foo') && null, | ||
}, | ||
] | ||
}, | ||
|
||
renderHTML({ HTMLAttributes }) { | ||
return ['span', mergeAttributes({ 'data-foo': '', HTMLAttributes }), 'foo'] | ||
}, | ||
|
||
renderText() { | ||
return 'foo' | ||
}, | ||
}) |
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, FloatingMenu, useEditor } from '@tiptap/react' | ||
import StarterKit from '@tiptap/starter-kit' | ||
import React from 'react' | ||
|
||
import Foo from './foo.js' | ||
|
||
export default () => { | ||
const editor = useEditor({ | ||
extensions: [ | ||
StarterKit, Foo, | ||
], | ||
content: ` | ||
<p><span data-foo=''>foo</span></p> | ||
`, | ||
}) | ||
|
||
return ( | ||
<> | ||
{editor && <FloatingMenu editor={editor} tippyOptions={{ duration: 100 }}> | ||
<div>Hello</div> | ||
</FloatingMenu>} | ||
<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,10 @@ | ||
.tiptap { | ||
> * + * { | ||
margin-top: 0.75em; | ||
} | ||
|
||
ul, | ||
ol { | ||
padding: 0 1rem; | ||
} | ||
} |
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,26 @@ | ||
import { mergeAttributes, Node } from '@tiptap/core' | ||
|
||
export default Node.create({ | ||
name: 'foo', | ||
|
||
group: 'inline', | ||
|
||
inline: true, | ||
|
||
parseHTML() { | ||
return [ | ||
{ | ||
tag: 'span', | ||
getAttrs: node => (node as HTMLElement).hasAttribute('data-foo') && null, | ||
}, | ||
] | ||
}, | ||
|
||
renderHTML({ HTMLAttributes }) { | ||
return ['span', mergeAttributes({ 'data-foo': '', HTMLAttributes }), 'foo'] | ||
}, | ||
|
||
renderText() { | ||
return 'foo' | ||
}, | ||
}) |
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
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,35 @@ | ||
context('/src/Extensions/FloatingMenu/React/', () => { | ||
before(() => { | ||
cy.visit('/src/Extensions/FloatingMenu/React/') | ||
}) | ||
|
||
it('should not render a floating menu on non-empty nodes', () => { | ||
cy.get('.tiptap').then(([{ editor }]) => { | ||
editor.chain().setContent('<p>Example Text</p>').focus().run() | ||
const floatingMenu = cy.get('[data-testID="floating-menu"]') | ||
|
||
floatingMenu.should('not.exist') | ||
}) | ||
}) | ||
|
||
it('should render a floating menu on empty nodes', () => { | ||
cy.get('.tiptap').then(([{ editor }]) => { | ||
editor.chain().setContent('<p></p>').focus().run() | ||
const floatingMenu = cy.get('[data-testID="floating-menu"]') | ||
|
||
floatingMenu.should('exist') | ||
}) | ||
}) | ||
|
||
it('should not render a floating menu when a leaf node is inserted', () => { | ||
cy.get('.tiptap').then(([{ editor }]) => { | ||
editor.chain().setContent('<p></p>').focus().run() | ||
|
||
cy.get('[data-testID="insert-foo"]').click() | ||
|
||
const floatingMenu = cy.get('[data-testID="floating-menu"]') | ||
|
||
floatingMenu.should('not.exist') | ||
}) | ||
}) | ||
}) |
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
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,18 @@ | ||
/// <reference types="cypress" /> | ||
|
||
import { Editor } from '@tiptap/core' | ||
|
||
interface EditorElement extends HTMLElement { | ||
editor: Editor | ||
} | ||
context('/cypress/integration/Issue4327/React/', () => { | ||
before(() => { | ||
cy.visit('/src/Examples/Issue4327/React/') | ||
}) | ||
it('should not show menu when node has renderText returning text with length > 0', () => { | ||
cy.get('.tiptap').then(([editorElement]) => { | ||
(editorElement as EditorElement).editor.commands.focus() | ||
}).get('.ProseMirror-focused').get('#app') | ||
.should('not.have.descendants', '[data-tippy-root]') | ||
}) | ||
}) |