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 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9488 from matrix-org/feat/add-message-edition-wys…
…iwyg-composer Add message editing to wysiwyg composer
- Loading branch information
Showing
37 changed files
with
1,679 additions
and
585 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
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
58 changes: 58 additions & 0 deletions
58
res/css/views/rooms/wysiwyg_composer/_EditWysiwygComposer.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,58 @@ | ||
/* | ||
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_EditWysiwygComposer { | ||
--EditWysiwygComposer-padding-inline: 3px; | ||
|
||
display: flex; | ||
flex-direction: column; | ||
max-width: 100%; /* disable overflow */ | ||
width: auto; | ||
gap: 8px; | ||
padding: 8px var(--EditWysiwygComposer-padding-inline); | ||
|
||
.mx_WysiwygComposer_content { | ||
border-radius: 4px; | ||
border: solid 1px $primary-hairline-color; | ||
background-color: $background; | ||
max-height: 200px; | ||
padding: 3px 6px; | ||
|
||
&:focus { | ||
border-color: rgba($accent, 0.5); /* Only ever used here */ | ||
} | ||
} | ||
|
||
.mx_EditWysiwygComposer_buttons { | ||
display: flex; | ||
flex-flow: row wrap-reverse; /* display "Save" over "Cancel" */ | ||
justify-content: flex-end; | ||
gap: 5px; | ||
margin-inline-start: auto; | ||
|
||
.mx_AccessibleButton { | ||
flex: 1; | ||
box-sizing: border-box; | ||
min-width: 100px; /* magic number to align the edge of the button with the input area */ | ||
} | ||
} | ||
|
||
.mx_FormattingButtons_Button { | ||
&:first-child { | ||
margin-left: 0px; | ||
} | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
res/css/views/rooms/wysiwyg_composer/components/_Editor.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,37 @@ | ||
/* | ||
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_container { | ||
position: relative; | ||
|
||
@keyframes visualbell { | ||
from { background-color: $visual-bell-bg-color; } | ||
to { background-color: $background; } | ||
} | ||
|
||
.mx_WysiwygComposer_content { | ||
white-space: pre-wrap; | ||
word-wrap: break-word; | ||
outline: none; | ||
overflow-x: hidden; | ||
|
||
/* Force caret nodes to be selected in full so that they can be */ | ||
/* navigated through in a single keypress */ | ||
.caretNode { | ||
user-select: all; | ||
} | ||
} | ||
} |
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
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
64 changes: 64 additions & 0 deletions
64
src/components/views/rooms/wysiwyg_composer/EditWysiwygComposer.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,64 @@ | ||
/* | ||
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, { forwardRef, RefObject } from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
import EditorStateTransfer from '../../../../utils/EditorStateTransfer'; | ||
import { WysiwygComposer } from './components/WysiwygComposer'; | ||
import { EditionButtons } from './components/EditionButtons'; | ||
import { useWysiwygEditActionHandler } from './hooks/useWysiwygEditActionHandler'; | ||
import { useEditing } from './hooks/useEditing'; | ||
import { useInitialContent } from './hooks/useInitialContent'; | ||
|
||
interface ContentProps { | ||
disabled: boolean; | ||
} | ||
|
||
const Content = forwardRef<HTMLElement, ContentProps>( | ||
function Content({ disabled }: ContentProps, forwardRef: RefObject<HTMLElement>) { | ||
useWysiwygEditActionHandler(disabled, forwardRef); | ||
return null; | ||
}, | ||
); | ||
|
||
interface EditWysiwygComposerProps { | ||
disabled?: boolean; | ||
onChange?: (content: string) => void; | ||
editorStateTransfer: EditorStateTransfer; | ||
className?: string; | ||
} | ||
|
||
export function EditWysiwygComposer({ editorStateTransfer, className, ...props }: EditWysiwygComposerProps) { | ||
const initialContent = useInitialContent(editorStateTransfer); | ||
const isReady = !editorStateTransfer || Boolean(initialContent); | ||
|
||
const { editMessage, endEditing, onChange, isSaveDisabled } = useEditing(initialContent, editorStateTransfer); | ||
|
||
return isReady && <WysiwygComposer | ||
className={classNames("mx_EditWysiwygComposer", className)} | ||
initialContent={initialContent} | ||
onChange={onChange} | ||
onSend={editMessage} | ||
{...props}> | ||
{ (ref) => ( | ||
<> | ||
<Content disabled={props.disabled} ref={ref} /> | ||
<EditionButtons onCancelClick={endEditing} onSaveClick={editMessage} isSaveDisabled={isSaveDisabled} /> | ||
</>) | ||
} | ||
</WysiwygComposer>; | ||
} |
46 changes: 46 additions & 0 deletions
46
src/components/views/rooms/wysiwyg_composer/SendWysiwygComposer.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,46 @@ | ||
/* | ||
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, { forwardRef, RefObject } from 'react'; | ||
import { FormattingFunctions } from '@matrix-org/matrix-wysiwyg'; | ||
|
||
import { useWysiwygSendActionHandler } from './hooks/useWysiwygSendActionHandler'; | ||
import { WysiwygComposer } from './components/WysiwygComposer'; | ||
|
||
interface SendWysiwygComposerProps { | ||
disabled?: boolean; | ||
onChange: (content: string) => void; | ||
onSend: () => void; | ||
} | ||
interface ContentProps { | ||
disabled: boolean; | ||
formattingFunctions: FormattingFunctions; | ||
} | ||
|
||
const Content = forwardRef<HTMLElement, ContentProps>( | ||
function Content({ disabled, formattingFunctions: wysiwyg }: ContentProps, forwardRef: RefObject<HTMLElement>) { | ||
useWysiwygSendActionHandler(disabled, forwardRef, wysiwyg); | ||
return null; | ||
}, | ||
); | ||
|
||
export function SendWysiwygComposer(props: SendWysiwygComposerProps) { | ||
return ( | ||
<WysiwygComposer className="mx_SendWysiwygComposer" {...props}>{ (ref, wysiwyg) => ( | ||
<Content disabled={props.disabled} ref={ref} formattingFunctions={wysiwyg} /> | ||
) } | ||
</WysiwygComposer>); | ||
} |
Oops, something went wrong.