mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 23:15:15 +08:00
Merge branch 'main' of github.com:ueberdosis/tiptap
This commit is contained in:
commit
61e14c0465
@ -1,10 +1,10 @@
|
||||
import React from "react";
|
||||
import { useEditor, EditorContent } from "@tiptap/react";
|
||||
import Document from "@tiptap/extension-document";
|
||||
import Paragraph from "@tiptap/extension-paragraph";
|
||||
import Heading from "@tiptap/extension-heading";
|
||||
import Text from "@tiptap/extension-text";
|
||||
import TextAlign from "@tiptap/extension-text-align";
|
||||
import React from 'react'
|
||||
import { useEditor, EditorContent } from '@tiptap/react'
|
||||
import Document from '@tiptap/extension-document'
|
||||
import Paragraph from '@tiptap/extension-paragraph'
|
||||
import Heading from '@tiptap/extension-heading'
|
||||
import Text from '@tiptap/extension-text'
|
||||
import TextAlign from '@tiptap/extension-text-align'
|
||||
|
||||
export default () => {
|
||||
const editor = useEditor({
|
||||
@ -14,7 +14,7 @@ export default () => {
|
||||
Text,
|
||||
Heading,
|
||||
TextAlign.configure({
|
||||
types: ["heading", "paragraph"],
|
||||
types: ['heading', 'paragraph'],
|
||||
}),
|
||||
],
|
||||
content: `
|
||||
@ -22,40 +22,40 @@ export default () => {
|
||||
<p style="text-align: center">first paragraph</p>
|
||||
<p style="text-align: right">second paragraph</p>
|
||||
`,
|
||||
});
|
||||
})
|
||||
|
||||
if (!editor) {
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button
|
||||
onClick={() => editor.chain().focus().setTextAlign("left").run()}
|
||||
className={editor.isActive({ textAlign: "left" }) ? "is-active" : ""}
|
||||
onClick={() => editor.chain().focus().setTextAlign('left').run()}
|
||||
className={editor.isActive({ textAlign: 'left' }) ? 'is-active' : ''}
|
||||
>
|
||||
left
|
||||
</button>
|
||||
<button
|
||||
onClick={() => editor.chain().focus().setTextAlign("center").run()}
|
||||
className={editor.isActive({ textAlign: "center" }) ? "is-active" : ""}
|
||||
onClick={() => editor.chain().focus().setTextAlign('center').run()}
|
||||
className={editor.isActive({ textAlign: 'center' }) ? 'is-active' : ''}
|
||||
>
|
||||
center
|
||||
</button>
|
||||
<button
|
||||
onClick={() => editor.chain().focus().setTextAlign("right").run()}
|
||||
className={editor.isActive({ textAlign: "right" }) ? "is-active" : ""}
|
||||
onClick={() => editor.chain().focus().setTextAlign('right').run()}
|
||||
className={editor.isActive({ textAlign: 'right' }) ? 'is-active' : ''}
|
||||
>
|
||||
right
|
||||
</button>
|
||||
<button
|
||||
onClick={() => editor.chain().focus().setTextAlign("justify").run()}
|
||||
className={editor.isActive({ textAlign: "justify" }) ? "is-active" : ""}
|
||||
onClick={() => editor.chain().focus().setTextAlign('justify').run()}
|
||||
className={editor.isActive({ textAlign: 'justify' }) ? 'is-active' : ''}
|
||||
>
|
||||
justify
|
||||
</button>
|
||||
<button onClick={() => editor.chain().focus().unsetTextAlign().run()}>unsetTextAlign</button>
|
||||
<EditorContent editor={editor} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
)
|
||||
}
|
||||
|
@ -1,97 +1,97 @@
|
||||
context("/src/Extensions/TextAlign/React/", () => {
|
||||
context('/src/Extensions/TextAlign/React/', () => {
|
||||
before(() => {
|
||||
cy.visit("/src/Extensions/TextAlign/React/");
|
||||
});
|
||||
cy.visit('/src/Extensions/TextAlign/React/')
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
cy.get(".ProseMirror").then(([{ editor }]) => {
|
||||
editor.commands.setContent("<p>Example Text</p>");
|
||||
});
|
||||
});
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p>Example Text</p>')
|
||||
})
|
||||
})
|
||||
|
||||
it("should parse left align text correctly (and not render)", () => {
|
||||
cy.get(".ProseMirror").then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p style="text-align: left">Example Text</p>');
|
||||
expect(editor.getHTML()).to.eq("<p>Example Text</p>");
|
||||
});
|
||||
});
|
||||
it('should parse left align text correctly (and not render)', () => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p style="text-align: left">Example Text</p>')
|
||||
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
|
||||
})
|
||||
})
|
||||
|
||||
it("should parse center align text correctly", () => {
|
||||
cy.get(".ProseMirror").then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p style="text-align: center">Example Text</p>');
|
||||
expect(editor.getHTML()).to.eq('<p style="text-align: center">Example Text</p>');
|
||||
});
|
||||
});
|
||||
it('should parse center align text correctly', () => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p style="text-align: center">Example Text</p>')
|
||||
expect(editor.getHTML()).to.eq('<p style="text-align: center">Example Text</p>')
|
||||
})
|
||||
})
|
||||
|
||||
it("should parse right align text correctly", () => {
|
||||
cy.get(".ProseMirror").then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p style="text-align: right">Example Text</p>');
|
||||
expect(editor.getHTML()).to.eq('<p style="text-align: right">Example Text</p>');
|
||||
});
|
||||
});
|
||||
it('should parse right align text correctly', () => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p style="text-align: right">Example Text</p>')
|
||||
expect(editor.getHTML()).to.eq('<p style="text-align: right">Example Text</p>')
|
||||
})
|
||||
})
|
||||
|
||||
it("should parse left justify text correctly", () => {
|
||||
cy.get(".ProseMirror").then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p style="text-align: justify">Example Text</p>');
|
||||
expect(editor.getHTML()).to.eq('<p style="text-align: justify">Example Text</p>');
|
||||
});
|
||||
});
|
||||
it('should parse left justify text correctly', () => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p style="text-align: justify">Example Text</p>')
|
||||
expect(editor.getHTML()).to.eq('<p style="text-align: justify">Example Text</p>')
|
||||
})
|
||||
})
|
||||
|
||||
it("aligns the text left on the 1st button", () => {
|
||||
cy.get("button:nth-child(1)").click();
|
||||
it('aligns the text left on the 1st button', () => {
|
||||
cy.get('button:nth-child(1)').click()
|
||||
|
||||
cy.get(".ProseMirror").find("p").should("not.have.css", "text-align", "left");
|
||||
});
|
||||
cy.get('.ProseMirror').find('p').should('not.have.css', 'text-align', 'left')
|
||||
})
|
||||
|
||||
it("aligns the text center on the 2nd button", () => {
|
||||
cy.get("button:nth-child(2)").click();
|
||||
it('aligns the text center on the 2nd button', () => {
|
||||
cy.get('button:nth-child(2)').click()
|
||||
|
||||
cy.get(".ProseMirror").find("p").should("have.css", "text-align", "center");
|
||||
});
|
||||
cy.get('.ProseMirror').find('p').should('have.css', 'text-align', 'center')
|
||||
})
|
||||
|
||||
it("aligns the text right on the 3rd button", () => {
|
||||
cy.get("button:nth-child(3)").click();
|
||||
it('aligns the text right on the 3rd button', () => {
|
||||
cy.get('button:nth-child(3)').click()
|
||||
|
||||
cy.get(".ProseMirror").find("p").should("have.css", "text-align", "right");
|
||||
});
|
||||
cy.get('.ProseMirror').find('p').should('have.css', 'text-align', 'right')
|
||||
})
|
||||
|
||||
it("aligns the text justified on the 4th button", () => {
|
||||
cy.get("button:nth-child(4)").click();
|
||||
it('aligns the text justified on the 4th button', () => {
|
||||
cy.get('button:nth-child(4)').click()
|
||||
|
||||
cy.get(".ProseMirror").find("p").should("have.css", "text-align", "justify");
|
||||
});
|
||||
cy.get('.ProseMirror').find('p').should('have.css', 'text-align', 'justify')
|
||||
})
|
||||
|
||||
it("aligns the text default on the 5th button", () => {
|
||||
cy.get("button:nth-child(5)").click();
|
||||
it('aligns the text default on the 5th button', () => {
|
||||
cy.get('button:nth-child(5)').click()
|
||||
|
||||
cy.get(".ProseMirror").find("p").should("not.have.css", "text-align", "left");
|
||||
});
|
||||
cy.get('.ProseMirror').find('p').should('not.have.css', 'text-align', 'left')
|
||||
})
|
||||
|
||||
it("aligns the text left when pressing the keyboard shortcut", () => {
|
||||
cy.get(".ProseMirror")
|
||||
.trigger("keydown", { modKey: true, shiftKey: true, key: "l" })
|
||||
.find("p")
|
||||
.should("not.have.css", "text-align", "left");
|
||||
});
|
||||
it('aligns the text left when pressing the keyboard shortcut', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.trigger('keydown', { modKey: true, shiftKey: true, key: 'l' })
|
||||
.find('p')
|
||||
.should('not.have.css', 'text-align', 'left')
|
||||
})
|
||||
|
||||
it("aligns the text center when pressing the keyboard shortcut", () => {
|
||||
cy.get(".ProseMirror")
|
||||
.trigger("keydown", { modKey: true, shiftKey: true, key: "e" })
|
||||
.find("p")
|
||||
.should("have.css", "text-align", "center");
|
||||
});
|
||||
it('aligns the text center when pressing the keyboard shortcut', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.trigger('keydown', { modKey: true, shiftKey: true, key: 'e' })
|
||||
.find('p')
|
||||
.should('have.css', 'text-align', 'center')
|
||||
})
|
||||
|
||||
it("aligns the text right when pressing the keyboard shortcut", () => {
|
||||
cy.get(".ProseMirror")
|
||||
.trigger("keydown", { modKey: true, shiftKey: true, key: "r" })
|
||||
.find("p")
|
||||
.should("have.css", "text-align", "right");
|
||||
});
|
||||
it('aligns the text right when pressing the keyboard shortcut', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.trigger('keydown', { modKey: true, shiftKey: true, key: 'r' })
|
||||
.find('p')
|
||||
.should('have.css', 'text-align', 'right')
|
||||
})
|
||||
|
||||
it("aligns the text justified when pressing the keyboard shortcut", () => {
|
||||
cy.get(".ProseMirror")
|
||||
.trigger("keydown", { modKey: true, shiftKey: true, key: "j" })
|
||||
.find("p")
|
||||
.should("have.css", "text-align", "justify");
|
||||
});
|
||||
});
|
||||
it('aligns the text justified when pressing the keyboard shortcut', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.trigger('keydown', { modKey: true, shiftKey: true, key: 'j' })
|
||||
.find('p')
|
||||
.should('have.css', 'text-align', 'justify')
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user