-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathWysiwygEditorView.tsx
More file actions
87 lines (79 loc) · 2.81 KB
/
Copy pathWysiwygEditorView.tsx
File metadata and controls
87 lines (79 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import type {QAProps} from '@gravity-ui/uikit';
import {type ClassNameProps, cn} from '../classname';
import {ReactRendererComponent} from '../extensions';
import {globalLogger} from '../logger';
import {useRenderTime} from '../react-utils/hooks';
import type {EditorInt} from './Editor';
import {ToolbarView} from './ToolbarView';
import {WysiwygEditorComponent} from './WysiwygEditorComponent';
import type {ToolbarDisplay, WToolbarData, WToolbarItemData} from './toolbar/types';
import './WysiwygEditorView.scss';
const b = cn('wysiwyg-editor');
export type WysiwygEditorViewProps = ClassNameProps &
QAProps & {
editor: EditorInt;
autofocus?: boolean;
settingsVisible?: boolean;
toolbarConfig: WToolbarData;
toolbarVisible?: boolean;
stickyToolbar?: boolean;
toolbarClassName?: string;
hiddenActionsConfig?: WToolbarItemData[];
children?: React.ReactNode;
toolbarDisplay?: ToolbarDisplay;
scrollContainerRef?: React.RefObject<HTMLElement>;
};
export const WysiwygEditorView: React.FC<WysiwygEditorViewProps> = (props) => {
const {
editor,
autofocus,
settingsVisible,
toolbarVisible,
toolbarConfig,
hiddenActionsConfig,
qa,
className,
toolbarClassName,
children,
stickyToolbar = true,
toolbarDisplay,
scrollContainerRef,
} = props;
useRenderTime((time) => {
globalLogger.metrics({
component: 'wysiwyg-editor',
event: 'render',
duration: time,
});
editor.logger.metrics({
component: 'wysiwyg-editor',
event: 'render',
duration: time,
});
});
return (
<div className={b({toolbar: toolbarVisible}, [className])} data-qa={qa}>
{toolbarVisible ? (
<ToolbarView
qa="g-md-toolbar-main"
editor={editor}
editorMode="wysiwyg"
toolbarEditor={editor}
stickyToolbar={stickyToolbar}
toolbarConfig={toolbarConfig}
hiddenActionsConfig={hiddenActionsConfig}
settingsVisible={settingsVisible}
className={b('toolbar', [toolbarClassName])}
toolbarDisplay={toolbarDisplay}
scrollContainerRef={scrollContainerRef}
>
{children}
</ToolbarView>
) : null}
<WysiwygEditorComponent autofocus={autofocus} editor={editor} className={b('editor')}>
<ReactRendererComponent storage={editor.renderStorage} />
</WysiwygEditorComponent>
</div>
);
};
WysiwygEditorView.displayName = 'MarkdownWysiwgEditorView';