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 830
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 #9503 from matrix-org/feat/add-plain-text-mode
Feat/add plain text mode
- Loading branch information
Showing
26 changed files
with
636 additions
and
156 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
56 changes: 56 additions & 0 deletions
56
src/components/views/rooms/wysiwyg_composer/components/PlainTextComposer.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,56 @@ | ||
/* | ||
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, { MutableRefObject, ReactNode } from 'react'; | ||
|
||
import { useComposerFunctions } from '../hooks/useComposerFunctions'; | ||
import { usePlainTextInitialization } from '../hooks/usePlainTextInitialization'; | ||
import { usePlainTextListeners } from '../hooks/usePlainTextListeners'; | ||
import { useSetCursorPosition } from '../hooks/useSetCursorPosition'; | ||
import { ComposerFunctions } from '../types'; | ||
import { Editor } from "./Editor"; | ||
|
||
interface PlainTextComposerProps { | ||
disabled?: boolean; | ||
onChange?: (content: string) => void; | ||
onSend: () => void; | ||
initialContent?: string; | ||
className?: string; | ||
children?: ( | ||
ref: MutableRefObject<HTMLDivElement | null>, | ||
composerFunctions: ComposerFunctions, | ||
) => ReactNode; | ||
} | ||
|
||
export function PlainTextComposer({ | ||
className, disabled, onSend, onChange, children, initialContent }: PlainTextComposerProps, | ||
) { | ||
const { ref, onInput, onPaste, onKeyDown } = usePlainTextListeners(onChange, onSend); | ||
const composerFunctions = useComposerFunctions(ref); | ||
usePlainTextInitialization(initialContent, ref); | ||
useSetCursorPosition(disabled, ref); | ||
|
||
return <div | ||
data-testid="PlainTextComposer" | ||
className={className} | ||
onInput={onInput} | ||
onPaste={onPaste} | ||
onKeyDown={onKeyDown} | ||
> | ||
<Editor ref={ref} disabled={disabled} /> | ||
{ children?.(ref, composerFunctions) } | ||
</div>; | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/components/views/rooms/wysiwyg_composer/hooks/useComposerFunctions.ts
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 @@ | ||
/* | ||
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 { RefObject, useMemo } from "react"; | ||
|
||
export function useComposerFunctions(ref: RefObject<HTMLDivElement>) { | ||
return useMemo(() => ({ | ||
clear: () => { | ||
if (ref.current) { | ||
ref.current.innerHTML = ''; | ||
} | ||
}, | ||
}), [ref]); | ||
} |
Oops, something went wrong.