This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 831
First step of matrix-wysiwyg integration #9374
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bfb1638
Add wysisyg composer (can only send message, enable behind a labs flag)
florianduros 1d820cf
Remove console, unused variables...
florianduros a50329f
Focus and clear content after sending a message
florianduros 4938aa8
Remove unused code
florianduros 21677e6
Remove unused MatrixClient
florianduros c7f9125
Move mxClient to object in sendMessage
florianduros bcc53fc
Add style for WysiwygComposer
florianduros 67aab08
Update yarn.lock
florianduros 667e8ef
Add tests to message.ts
florianduros 3080d14
Remove unused localstorage hook
florianduros 200af78
Use published matrix-wysisyg
florianduros a0377f0
Update wysiwig flag description
florianduros 101fd62
Add WysiwygComposer test
florianduros 77005e2
Update wysiwyg version
florianduros 5bdac78
Merge remote-tracking branch 'origin/develop' into feat/matrix-wysisy…
florianduros ec1140e
Fix type errors
florianduros 6c71581
Add test in MessageComposer
florianduros 70f5779
Add more todo in message.ts
florianduros f8ec4ec
Disable wysiwyg at the end of the test
florianduros 7ad39ba
Merge branch 'develop' into feat/matrix-wysisyg-integration
florianduros 0dd9aba
Fix aria-disabled
florianduros 203f75f
Merge branch 'develop' into feat/matrix-wysisyg-integration
florianduros 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
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
53 changes: 53 additions & 0 deletions
53
res/css/views/rooms/wysiwyg_composer/_WysiwygComposer.pcss
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,53 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
.mx_WysiwygComposer { | ||
flex: 1; | ||
display: flex; | ||
flex-direction: column; | ||
font-size: $font-14px; | ||
/* fixed line height to prevent emoji from being taller than text */ | ||
line-height: $font-18px; | ||
justify-content: center; | ||
margin-right: 6px; | ||
/* don't grow wider than available space */ | ||
min-width: 0; | ||
|
||
.mx_WysiwygComposer_container { | ||
flex: 1; | ||
display: flex; | ||
flex-direction: column; | ||
/* min-height at this level so the mx_BasicMessageComposer_input */ | ||
/* still stays vertically centered when less than 55px. */ | ||
/* We also set this to ensure the voice message recording widget */ | ||
/* doesn't cause a jump. */ | ||
min-height: 55px; | ||
|
||
.mx_WysiwygComposer_content { | ||
border: 1px solid; | ||
border-radius: 20px; | ||
padding: 8px 10px; | ||
/* this will center the contenteditable */ | ||
/* in it's parent vertically */ | ||
/* while keeping the autocomplete at the top */ | ||
/* of the composer. The parent needs to be a flex container for this to work. */ | ||
margin: auto 0; | ||
/* max-height at this level so autocomplete doesn't get scrolled too */ | ||
max-height: 140px; | ||
overflow-y: auto; | ||
} | ||
} | ||
} |
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
71 changes: 71 additions & 0 deletions
71
src/components/views/rooms/wysiwyg_composer/WysiwygComposer.tsx
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,71 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React, { useCallback, useState } from 'react'; | ||
import { useWysiwyg } from "@matrix-org/matrix-wysiwyg"; | ||
import { IEventRelation, MatrixEvent } from 'matrix-js-sdk/src/models/event'; | ||
|
||
import { useRoomContext } from '../../../../contexts/RoomContext'; | ||
import { sendMessage } from './message'; | ||
import { RoomPermalinkCreator } from '../../../../utils/permalinks/Permalinks'; | ||
import { useMatrixClientContext } from '../../../../contexts/MatrixClientContext'; | ||
|
||
interface WysiwygProps { | ||
disabled?: boolean; | ||
onChange: (content: string) => void; | ||
relation?: IEventRelation; | ||
replyToEvent?: MatrixEvent; | ||
permalinkCreator: RoomPermalinkCreator; | ||
includeReplyLegacyFallback?: boolean; | ||
children?: (sendMessage: () => void) => void; | ||
} | ||
|
||
export function WysiwygComposer( | ||
{ disabled = false, onChange, children, ...props }: WysiwygProps, | ||
) { | ||
const roomContext = useRoomContext(); | ||
const mxClient = useMatrixClientContext(); | ||
|
||
const [content, setContent] = useState<string>(); | ||
const { ref, isWysiwygReady, wysiwyg } = useWysiwyg({ onChange: (_content) => { | ||
setContent(_content); | ||
onChange(_content); | ||
} }); | ||
|
||
const memoizedSendMessage = useCallback(() => { | ||
sendMessage(content, { mxClient, roomContext, ...props }); | ||
wysiwyg.clear(); | ||
ref.current?.focus(); | ||
}, [content, mxClient, roomContext, wysiwyg, props, ref]); | ||
|
||
return ( | ||
<div className="mx_WysiwygComposer"> | ||
<div className="mx_WysiwygComposer_container"> | ||
<div className="mx_WysiwygComposer_content" | ||
ref={ref} | ||
contentEditable={!disabled && isWysiwygReady} | ||
role="textbox" | ||
aria-multiline="true" | ||
aria-autocomplete="list" | ||
aria-haspopup="listbox" | ||
dir="auto" | ||
aria-disabled={disabled || !isWysiwygReady} | ||
/> | ||
</div> | ||
{ children?.(memoizedSendMessage) } | ||
</div> | ||
); | ||
} |
Oops, something went wrong.
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.
What do you think about making
sendMessage
a prop instead? That way we can keep the business logic separate and reusable, and this component easy to test.I also find the renderProps binding of
sendMessage
a bit weirdThere 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.
Since the parent already have the html content thanks to the
onChange
, thesendMessage
is not needed here and the logic can be in the parent. I will add a component in the next PRs between theWysiwygComposer
and theMessageComposer
. I'll avoid to add extra logic in theMessageComposer
because it's already big enough.I'm also not convinced by the
memoizedSendMessage
in the children but I'm searching a way to nicely do thefocus
andclear
. In the old composer a ref is used by I clearly don't like this solution.