feat(ui): add RTL support in feed editor (#14052)

* feat(ui): add RTL support in feed editor

* apply rtl on content only
This commit is contained in:
Sachin Chaurasiya 2023-11-22 14:47:46 +05:30 committed by GitHub
parent 9c990fef19
commit 5e6e1d4f3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 3 deletions

View File

@ -34,7 +34,11 @@ import {
} from '../../constants/Feeds.constants'; } from '../../constants/Feeds.constants';
import { HTMLToMarkdown, matcher } from '../../utils/FeedUtils'; import { HTMLToMarkdown, matcher } from '../../utils/FeedUtils';
import { LinkBlot } from '../../utils/QuillLink/QuillLink'; import { LinkBlot } from '../../utils/QuillLink/QuillLink';
import { insertMention, insertRef } from '../../utils/QuillUtils'; import {
directionHandler,
insertMention,
insertRef,
} from '../../utils/QuillUtils';
import { getEntityIcon } from '../../utils/TableUtils'; import { getEntityIcon } from '../../utils/TableUtils';
import { editorRef } from '../common/RichTextEditor/RichTextEditor.interface'; import { editorRef } from '../common/RichTextEditor/RichTextEditor.interface';
import './feed-editor.less'; import './feed-editor.less';
@ -77,6 +81,7 @@ export const FeedEditor = forwardRef<editorRef, FeedEditorProp>(
handlers: { handlers: {
insertMention: insertMention, insertMention: insertMention,
insertRef: insertRef, insertRef: insertRef,
direction: directionHandler,
}, },
}, },
'emoji-toolbar': true, 'emoji-toolbar': true,
@ -226,7 +231,10 @@ export const FeedEditor = forwardRef<editorRef, FeedEditorProp>(
}, [focused, editorRef]); }, [focused, editorRef]);
return ( return (
<div className={className} data-testid="editor-wrapper"> <div
className={className}
data-testid="editor-wrapper"
id="om-quill-editor">
<ReactQuill <ReactQuill
className={classNames('editor-container', editorClass)} className={classNames('editor-container', editorClass)}
modules={modules} modules={modules}

View File

@ -1036,12 +1036,19 @@
text-decoration: none; text-decoration: none;
} }
.ql-snow.ql-toolbar .ql-formats:nth-child(5) {
vertical-align: baseline;
}
.ql-snow.ql-toolbar .ql-formats button.ql-insertMention {
padding: 0px;
}
.ql-insertMention::after { .ql-insertMention::after {
content: '@'; content: '@';
font-weight: bold; font-weight: bold;
font-size: 18px; font-size: 18px;
display: block; display: block;
margin-top: -4px;
} }
.ql-insertRef::after { .ql-insertRef::after {
content: '#'; content: '#';
@ -1095,3 +1102,9 @@ button.ql-emoji {
height: 24px; height: 24px;
width: 24px; width: 24px;
} }
#om-quill-editor[data-dir='rtl'] {
.ql-editor.ql-blank::before {
text-align: right;
}
}

View File

@ -45,6 +45,7 @@ export const TOOLBAR_ITEMS = [
[{ list: 'ordered' }, { list: 'bullet' }], [{ list: 'ordered' }, { list: 'bullet' }],
['link'], ['link'],
['insertMention', 'insertRef', 'emoji'], ['insertMention', 'insertRef', 'emoji'],
[{ direction: 'rtl' }],
]; ];
export enum TaskOperation { export enum TaskOperation {

View File

@ -21,3 +21,19 @@ export function insertRef() {
const ref = this.quill.getModule('mention'); const ref = this.quill.getModule('mention');
ref.openMenu('#'); ref.openMenu('#');
} }
export function directionHandler(value) {
const { align } = this.quill.getFormat();
// get the editor container
const container = document.getElementById('om-quill-editor');
if (value === 'rtl' && align == null) {
container.setAttribute('data-dir', value);
this.quill.format('align', 'right', 'user');
} else if (!value && align === 'right') {
this.quill.format('align', false, 'user');
container.setAttribute('data-dir', 'ltr');
}
this.quill.format('direction', value, 'user');
}