-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathindex.jsx
More file actions
147 lines (135 loc) · 4.23 KB
/
index.jsx
File metadata and controls
147 lines (135 loc) · 4.23 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import {
Spinner,
Toast,
} from '@openedx/paragon';
import { useIntl } from '@edx/frontend-platform/i18n';
import { getConfig } from '@edx/frontend-platform';
import { actions, selectors } from '../../data/redux';
import { RequestKeys } from '../../data/constants/requests';
import EditorContainer from '../EditorContainer';
import RawEditor from '../../sharedComponents/RawEditor';
import * as hooks from './hooks';
import messages from './messages';
import TinyMceWidget from '../../sharedComponents/TinyMceWidget';
import { prepareEditorRef, useProcessedEditorContent } from '../../sharedComponents/TinyMceWidget/hooks';
const TextEditor = ({
onClose,
returnFunction,
// redux
showRawEditor,
blockValue,
blockId,
blockFailed,
initializeEditor,
blockFinished,
learningContextId,
images,
isLibrary,
validateAssetUrl,
}) => {
const intl = useIntl();
const { editorRef, refReady, setEditorRef } = prepareEditorRef();
const editorContent = useProcessedEditorContent({
initialContent: blockValue ? blockValue.data.data : '',
learningContextId,
validateAssetUrl,
});
let staticRootUrl;
if (isLibrary) {
staticRootUrl = `${getConfig().STUDIO_BASE_URL }/library_assets/blocks/${ blockId }/`;
}
if (!refReady) { return null; }
const selectEditor = () => {
if (showRawEditor) {
return (
<RawEditor
editorRef={editorRef}
content={blockValue}
/>
);
}
return (
<TinyMceWidget
editorType="text"
editorRef={editorRef}
editorContentHtml={editorContent}
setEditorRef={setEditorRef}
minHeight={500}
maxHeight={500}
initializeEditor={initializeEditor}
{...{
images,
isLibrary,
learningContextId,
staticRootUrl,
}}
/>
);
};
return (
<EditorContainer
getContent={hooks.getContent({ editorRef, showRawEditor })}
isDirty={hooks.isDirty({ editorRef, showRawEditor })}
onClose={onClose}
returnFunction={returnFunction}
>
<div className="editor-body h-75 overflow-auto">
<Toast show={blockFailed} onClose={hooks.nullMethod}>
{ intl.formatMessage(messages.couldNotLoadTextContext) }
</Toast>
{(!blockFinished)
? (
<div className="text-center p-6">
<Spinner
animation="border"
className="m-3"
screenreadertext={intl.formatMessage(messages.spinnerScreenReaderText)}
/>
</div>
) : (selectEditor())}
</div>
</EditorContainer>
);
};
TextEditor.defaultProps = {
blockValue: null,
blockFinished: null,
returnFunction: null,
validateAssetUrl: null,
};
TextEditor.propTypes = {
onClose: PropTypes.func.isRequired,
returnFunction: PropTypes.func,
// redux
blockValue: PropTypes.shape({
data: PropTypes.shape({ data: PropTypes.string }),
}),
blockId: PropTypes.string,
blockFailed: PropTypes.bool.isRequired,
initializeEditor: PropTypes.func.isRequired,
showRawEditor: PropTypes.bool.isRequired,
blockFinished: PropTypes.bool,
learningContextId: PropTypes.string, // This should be required but is NULL when the store is in initial state :/
images: PropTypes.shape({}).isRequired,
isLibrary: PropTypes.bool.isRequired,
validateAssetUrl: PropTypes.bool,
};
export const mapStateToProps = (state) => ({
blockValue: selectors.app.blockValue(state),
blockFailed: selectors.requests.isFailed(state, { requestKey: RequestKeys.fetchBlock }),
blockId: selectors.app.blockId(state),
showRawEditor: selectors.app.showRawEditor(state),
blockFinished: selectors.app.shouldCreateBlock(state)
|| selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchBlock }),
learningContextId: selectors.app.learningContextId(state),
images: selectors.app.images(state),
isLibrary: selectors.app.isLibrary(state),
});
export const mapDispatchToProps = {
initializeEditor: actions.app.initializeEditor,
};
export const TextEditorInternal = TextEditor; // For testing only
export default connect(mapStateToProps, mapDispatchToProps)(TextEditor);