Merge pull request #9573 from matrix-org/tech/update-rich-text-editor
Update @matrix-org/matrix-wysiwyg dependency
This commit is contained in:
commit
ebb0e2e520
9 changed files with 22 additions and 22 deletions
|
@ -57,7 +57,7 @@
|
|||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@matrix-org/analytics-events": "^0.3.0",
|
||||
"@matrix-org/matrix-wysiwyg": "^0.3.2",
|
||||
"@matrix-org/matrix-wysiwyg": "^0.6.0",
|
||||
"@matrix-org/react-sdk-module-api": "^0.0.3",
|
||||
"@sentry/browser": "^6.11.0",
|
||||
"@sentry/tracing": "^6.11.0",
|
||||
|
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import React, { MouseEventHandler } from "react";
|
||||
import { FormattingFunctions, FormattingStates } from "@matrix-org/matrix-wysiwyg";
|
||||
import { FormattingFunctions, AllActionStates } from "@matrix-org/matrix-wysiwyg";
|
||||
import classNames from "classnames";
|
||||
|
||||
import AccessibleTooltipButton from "../../../elements/AccessibleTooltipButton";
|
||||
|
@ -56,14 +56,14 @@ function Button({ label, keyCombo, onClick, isActive, className }: ButtonProps)
|
|||
|
||||
interface FormattingButtonsProps {
|
||||
composer: FormattingFunctions;
|
||||
formattingStates: FormattingStates;
|
||||
actionStates: AllActionStates;
|
||||
}
|
||||
|
||||
export function FormattingButtons({ composer, formattingStates }: FormattingButtonsProps) {
|
||||
export function FormattingButtons({ composer, actionStates }: FormattingButtonsProps) {
|
||||
return <div className="mx_FormattingButtons">
|
||||
<Button isActive={formattingStates.bold === 'reversed'} label={_td("Bold")} keyCombo={{ ctrlOrCmdKey: true, key: 'b' }} onClick={() => composer.bold()} className="mx_FormattingButtons_Button_bold" />
|
||||
<Button isActive={formattingStates.italic === 'reversed'} label={_td('Italic')} keyCombo={{ ctrlOrCmdKey: true, key: 'i' }} onClick={() => composer.italic()} className="mx_FormattingButtons_Button_italic" />
|
||||
<Button isActive={formattingStates.underline === 'reversed'} label={_td('Underline')} keyCombo={{ ctrlOrCmdKey: true, key: 'u' }} onClick={() => composer.underline()} className="mx_FormattingButtons_Button_underline" />
|
||||
<Button isActive={formattingStates.strikeThrough === 'reversed'} label={_td('Strikethrough')} onClick={() => composer.strikeThrough()} className="mx_FormattingButtons_Button_strikethrough" />
|
||||
<Button isActive={actionStates.bold === 'reversed'} label={_td("Bold")} keyCombo={{ ctrlOrCmdKey: true, key: 'b' }} onClick={() => composer.bold()} className="mx_FormattingButtons_Button_bold" />
|
||||
<Button isActive={actionStates.italic === 'reversed'} label={_td('Italic')} keyCombo={{ ctrlOrCmdKey: true, key: 'i' }} onClick={() => composer.italic()} className="mx_FormattingButtons_Button_italic" />
|
||||
<Button isActive={actionStates.underline === 'reversed'} label={_td('Underline')} keyCombo={{ ctrlOrCmdKey: true, key: 'u' }} onClick={() => composer.underline()} className="mx_FormattingButtons_Button_underline" />
|
||||
<Button isActive={actionStates.strikeThrough === 'reversed'} label={_td('Strikethrough')} onClick={() => composer.strikeThrough()} className="mx_FormattingButtons_Button_strikethrough" />
|
||||
</div>;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ export const WysiwygComposer = memo(function WysiwygComposer(
|
|||
) {
|
||||
const inputEventProcessor = useInputEventProcessor(onSend);
|
||||
|
||||
const { ref, isWysiwygReady, content, formattingStates, wysiwyg } =
|
||||
const { ref, isWysiwygReady, content, actionStates, wysiwyg } =
|
||||
useWysiwyg({ initialContent, inputEventProcessor });
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -68,7 +68,7 @@ export const WysiwygComposer = memo(function WysiwygComposer(
|
|||
|
||||
return (
|
||||
<div data-testid="WysiwygComposer" className={classNames(className, { [`${className}-focused`]: isFocused })} onFocus={onFocus} onBlur={onFocus}>
|
||||
<FormattingButtons composer={wysiwyg} formattingStates={formattingStates} />
|
||||
<FormattingButtons composer={wysiwyg} actionStates={actionStates} />
|
||||
<Editor ref={ref} disabled={!isReady} leftComponent={leftComponent} rightComponent={rightComponent} />
|
||||
{ children?.(ref, wysiwyg) }
|
||||
</div>
|
||||
|
|
|
@ -47,7 +47,7 @@ import { SendWysiwygComposer } from "../../../../src/components/views/rooms/wysi
|
|||
jest.mock("@matrix-org/matrix-wysiwyg", () => ({
|
||||
useWysiwyg: () => {
|
||||
return { ref: { current: null }, isWysiwygReady: true, wysiwyg: { clear: () => void 0 },
|
||||
formattingStates: { bold: 'enabled', italic: 'enabled', underline: 'enabled', strikeThrough: 'enabled' } };
|
||||
actionStates: { bold: 'enabled', italic: 'enabled', underline: 'enabled', strikeThrough: 'enabled' } };
|
||||
},
|
||||
}));
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ jest.mock("@matrix-org/matrix-wysiwyg", () => ({
|
|||
content: mockContent,
|
||||
isWysiwygReady: true,
|
||||
wysiwyg: { clear: mockClear },
|
||||
formattingStates: {
|
||||
actionStates: {
|
||||
bold: 'enabled',
|
||||
italic: 'enabled',
|
||||
underline: 'enabled',
|
||||
|
|
|
@ -41,7 +41,7 @@ jest.mock("@matrix-org/matrix-wysiwyg", () => ({
|
|||
content: '<b>html</b>',
|
||||
isWysiwygReady: true,
|
||||
wysiwyg: { clear: mockClear },
|
||||
formattingStates: {
|
||||
actionStates: {
|
||||
bold: 'enabled',
|
||||
italic: 'enabled',
|
||||
underline: 'enabled',
|
||||
|
|
|
@ -29,7 +29,7 @@ describe('FormattingButtons', () => {
|
|||
strikeThrough: jest.fn(),
|
||||
} as any;
|
||||
|
||||
const formattingStates = {
|
||||
const actionStates = {
|
||||
bold: 'reversed',
|
||||
italic: 'reversed',
|
||||
underline: 'enabled',
|
||||
|
@ -42,7 +42,7 @@ describe('FormattingButtons', () => {
|
|||
|
||||
it('Should have the correspond CSS classes', () => {
|
||||
// When
|
||||
render(<FormattingButtons composer={wysiwyg} formattingStates={formattingStates} />);
|
||||
render(<FormattingButtons composer={wysiwyg} actionStates={actionStates} />);
|
||||
|
||||
// Then
|
||||
expect(screen.getByLabelText('Bold')).toHaveClass('mx_FormattingButtons_active');
|
||||
|
@ -53,7 +53,7 @@ describe('FormattingButtons', () => {
|
|||
|
||||
it('Should call wysiwyg function on button click', () => {
|
||||
// When
|
||||
render(<FormattingButtons composer={wysiwyg} formattingStates={formattingStates} />);
|
||||
render(<FormattingButtons composer={wysiwyg} actionStates={actionStates} />);
|
||||
screen.getByLabelText('Bold').click();
|
||||
screen.getByLabelText('Italic').click();
|
||||
screen.getByLabelText('Underline').click();
|
||||
|
@ -69,7 +69,7 @@ describe('FormattingButtons', () => {
|
|||
it('Should display the tooltip on mouse over', async () => {
|
||||
// When
|
||||
const user = userEvent.setup();
|
||||
render(<FormattingButtons composer={wysiwyg} formattingStates={formattingStates} />);
|
||||
render(<FormattingButtons composer={wysiwyg} actionStates={actionStates} />);
|
||||
await user.hover(screen.getByLabelText('Bold'));
|
||||
|
||||
// Then
|
||||
|
|
|
@ -35,7 +35,7 @@ jest.mock("@matrix-org/matrix-wysiwyg", () => ({
|
|||
content: '<b>html</b>',
|
||||
isWysiwygReady: true,
|
||||
wysiwyg: { clear: () => void 0 },
|
||||
formattingStates: {
|
||||
actionStates: {
|
||||
bold: 'enabled',
|
||||
italic: 'enabled',
|
||||
underline: 'enabled',
|
||||
|
|
|
@ -1788,10 +1788,10 @@
|
|||
resolved "https://registry.yarnpkg.com/@matrix-org/analytics-events/-/analytics-events-0.3.0.tgz#a428f7e3f164ffadf38f35bc0f0f9a3e47369ce6"
|
||||
integrity sha512-f1WIMA8tjNB3V5g1C34yIpIJK47z6IJ4SLiY4j+J9Gw4X8C3TKGTAx563rMcMvW3Uk/PFqnIBXtkavHBXoYJ9A==
|
||||
|
||||
"@matrix-org/matrix-wysiwyg@^0.3.2":
|
||||
version "0.3.2"
|
||||
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-wysiwyg/-/matrix-wysiwyg-0.3.2.tgz#586f3ad2f4a7bf39d8e2063630c52294c877bcd6"
|
||||
integrity sha512-Q6Ntj2q1/7rVUlro94snn9eZy/3EbrGqaq5nqNMbttXcnFzYtgligDV1avViB4Um6ZRdDOxnQEPkMca/SqYSmw==
|
||||
"@matrix-org/matrix-wysiwyg@^0.6.0":
|
||||
version "0.6.0"
|
||||
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-wysiwyg/-/matrix-wysiwyg-0.6.0.tgz#f06577eec5a98fa414d2cd66688d32d984544c94"
|
||||
integrity sha512-6wq6RzpGZLxAcczHL7+QuGLJwGcvUSAm1zXd/0FzevfIKORbGKF2uCWgQ4JoZVpe4rbBNJgtPGb1r36W/i66/A==
|
||||
|
||||
"@matrix-org/olm@https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.8.tgz":
|
||||
version "3.2.8"
|
||||
|
|
Loading…
Reference in a new issue