@kids-reporter/draft-editor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -0
- package/lib/.selector/align-selector.js +71 -0
- package/lib/.selector/audio-selector.js +268 -0
- package/lib/.selector/image-selector.js +430 -0
- package/lib/.selector/pagination.js +82 -0
- package/lib/.selector/post-selector.js +311 -0
- package/lib/.selector/search-box.js +46 -0
- package/lib/.selector/video-selector.js +285 -0
- package/lib/block-renderer/background-image-block.js +141 -0
- package/lib/block-renderer/background-video-block.js +151 -0
- package/lib/block-renderer/color-box-block.js +86 -0
- package/lib/block-renderer/info-box-block.js +86 -0
- package/lib/block-renderer/side-index-block.js +90 -0
- package/lib/block-renderer/table-block.js +408 -0
- package/lib/block-renderer-fn.js +131 -0
- package/lib/buttons/annotation.js +117 -0
- package/lib/buttons/audio.js +65 -0
- package/lib/buttons/background-color.js +122 -0
- package/lib/buttons/background-image.js +223 -0
- package/lib/buttons/background-video.js +223 -0
- package/lib/buttons/color-box.js +173 -0
- package/lib/buttons/divider.js +63 -0
- package/lib/buttons/embedded-code.js +109 -0
- package/lib/buttons/enlarge.js +24 -0
- package/lib/buttons/font-color.js +115 -0
- package/lib/buttons/image.js +70 -0
- package/lib/buttons/info-box.js +148 -0
- package/lib/buttons/link.js +107 -0
- package/lib/buttons/media.js +121 -0
- package/lib/buttons/related-post.js +71 -0
- package/lib/buttons/selector/align-selector.js +71 -0
- package/lib/buttons/selector/audio-selector.js +279 -0
- package/lib/buttons/selector/image-selector.js +417 -0
- package/lib/buttons/selector/pagination.js +82 -0
- package/lib/buttons/selector/post-selector.js +317 -0
- package/lib/buttons/selector/search-box.js +46 -0
- package/lib/buttons/selector/video-selector.js +281 -0
- package/lib/buttons/side-index.js +200 -0
- package/lib/buttons/slideshow.js +71 -0
- package/lib/buttons/table.js +67 -0
- package/lib/buttons/text-align.js +88 -0
- package/lib/buttons/video.js +65 -0
- package/lib/buttons/youtube.js +147 -0
- package/lib/const.js +18 -0
- package/lib/draft-converter/api-data-instance.js +58 -0
- package/lib/draft-converter/atomic-block-processor.js +233 -0
- package/lib/draft-converter/entities.js +76 -0
- package/lib/draft-converter/index.js +201 -0
- package/lib/draft-converter/inline-styles-processor.js +236 -0
- package/lib/draft-editor.js +918 -0
- package/lib/entity-decorator.js +20 -0
- package/lib/index.js +15 -0
- package/lib/modifier.js +68 -0
- package/lib/theme/index.js +39 -0
- package/package.json +41 -0
|
@@ -0,0 +1,918 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.buttonNames = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
11
|
+
|
|
12
|
+
var _theme = _interopRequireDefault(require("./theme"));
|
|
13
|
+
|
|
14
|
+
var _draftJs = require("draft-js");
|
|
15
|
+
|
|
16
|
+
var _blockRendererFn = require("./block-renderer-fn");
|
|
17
|
+
|
|
18
|
+
var _entityDecorator = _interopRequireDefault(require("./entity-decorator"));
|
|
19
|
+
|
|
20
|
+
var _annotation = require("./buttons/annotation");
|
|
21
|
+
|
|
22
|
+
var _embeddedCode = require("./buttons/embedded-code");
|
|
23
|
+
|
|
24
|
+
var _enlarge = require("./buttons/enlarge");
|
|
25
|
+
|
|
26
|
+
var _image = require("./buttons/image");
|
|
27
|
+
|
|
28
|
+
var _infoBox = require("./buttons/info-box");
|
|
29
|
+
|
|
30
|
+
var _link = require("./buttons/link");
|
|
31
|
+
|
|
32
|
+
var _slideshow = require("./buttons/slideshow");
|
|
33
|
+
|
|
34
|
+
var _table = require("./buttons/table");
|
|
35
|
+
|
|
36
|
+
var _divider = require("./buttons/divider");
|
|
37
|
+
|
|
38
|
+
var _colorBox = require("./buttons/color-box");
|
|
39
|
+
|
|
40
|
+
var _backgroundImage = require("./buttons/background-image");
|
|
41
|
+
|
|
42
|
+
var _backgroundVideo = require("./buttons/background-video");
|
|
43
|
+
|
|
44
|
+
var _relatedPost = require("./buttons/related-post");
|
|
45
|
+
|
|
46
|
+
var _sideIndex = require("./buttons/side-index");
|
|
47
|
+
|
|
48
|
+
var _textAlign = require("./buttons/text-align");
|
|
49
|
+
|
|
50
|
+
var _fontColor = require("./buttons/font-color");
|
|
51
|
+
|
|
52
|
+
var _backgroundColor = require("./buttons/background-color");
|
|
53
|
+
|
|
54
|
+
var _video = require("./buttons/video");
|
|
55
|
+
|
|
56
|
+
var _audio = require("./buttons/audio");
|
|
57
|
+
|
|
58
|
+
var _const = require("./const");
|
|
59
|
+
|
|
60
|
+
var _imageSelector = require("./buttons/selector/image-selector");
|
|
61
|
+
|
|
62
|
+
var _videoSelector = require("./buttons/selector/video-selector");
|
|
63
|
+
|
|
64
|
+
var _postSelector = require("./buttons/selector/post-selector");
|
|
65
|
+
|
|
66
|
+
var _audioSelector = require("./buttons/selector/audio-selector");
|
|
67
|
+
|
|
68
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
69
|
+
|
|
70
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
71
|
+
|
|
72
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
73
|
+
|
|
74
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
75
|
+
|
|
76
|
+
const buttonNames = {
|
|
77
|
+
// inline styles
|
|
78
|
+
bold: 'bold',
|
|
79
|
+
italic: 'italic',
|
|
80
|
+
underline: 'underline',
|
|
81
|
+
code: 'code',
|
|
82
|
+
// block styles
|
|
83
|
+
h2: 'header-two',
|
|
84
|
+
h3: 'header-three',
|
|
85
|
+
h4: 'header-four',
|
|
86
|
+
blockquote: 'blockquote',
|
|
87
|
+
ul: 'unordered-list-item',
|
|
88
|
+
ol: 'ordered-list-item',
|
|
89
|
+
codeBlock: 'code-block',
|
|
90
|
+
// custom styles
|
|
91
|
+
annotation: 'annotation',
|
|
92
|
+
divider: 'divider',
|
|
93
|
+
embed: 'embed',
|
|
94
|
+
fontColor: 'font-color',
|
|
95
|
+
image: 'image',
|
|
96
|
+
infoBox: 'info-box',
|
|
97
|
+
link: 'link',
|
|
98
|
+
slideshow: 'slideshow',
|
|
99
|
+
table: 'table',
|
|
100
|
+
textAlign: 'text-align',
|
|
101
|
+
colorBox: 'color-box',
|
|
102
|
+
backgroundColor: 'background-color',
|
|
103
|
+
backgroundImage: 'background-image',
|
|
104
|
+
backgroundVideo: 'background-video',
|
|
105
|
+
relatedPost: 'related-post',
|
|
106
|
+
sideIndex: 'side-index',
|
|
107
|
+
video: 'video',
|
|
108
|
+
audio: 'audio'
|
|
109
|
+
};
|
|
110
|
+
exports.buttonNames = buttonNames;
|
|
111
|
+
const disabledButtonsOnBasicEditor = [buttonNames.annotation, buttonNames.divider, buttonNames.embed, buttonNames.image, buttonNames.infoBox, buttonNames.slideshow, buttonNames.table, buttonNames.textAlign, buttonNames.colorBox, buttonNames.backgroundColor, buttonNames.backgroundImage, buttonNames.backgroundVideo, buttonNames.relatedPost, buttonNames.sideIndex, buttonNames.video, buttonNames.audio];
|
|
112
|
+
const buttonStyle = (0, _styledComponents.css)`
|
|
113
|
+
border-radius: 6px;
|
|
114
|
+
text-align: center;
|
|
115
|
+
font-size: 1rem;
|
|
116
|
+
padding: 0 12px;
|
|
117
|
+
margin: 0px 0px 10px 0px;
|
|
118
|
+
background-color: #fff;
|
|
119
|
+
border: solid 1px rgb(193, 199, 208);
|
|
120
|
+
align-items: center;
|
|
121
|
+
height: 40px;
|
|
122
|
+
|
|
123
|
+
cursor: ${props => {
|
|
124
|
+
if (props.readOnly) {
|
|
125
|
+
return 'not-allowed';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return 'pointer';
|
|
129
|
+
}};
|
|
130
|
+
color: ${props => {
|
|
131
|
+
if (props.readOnly) {
|
|
132
|
+
return '#c1c7d0';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (props.isActive) {
|
|
136
|
+
return '#3b82f6';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return '#6b7280';
|
|
140
|
+
}};
|
|
141
|
+
border: solid 1px
|
|
142
|
+
${props => {
|
|
143
|
+
if (props.readOnly) {
|
|
144
|
+
return '#c1c7d0';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (props.isActive) {
|
|
148
|
+
return '#3b82f6';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return '#6b7280';
|
|
152
|
+
}};
|
|
153
|
+
box-shadow: ${props => {
|
|
154
|
+
if (props.readOnly) {
|
|
155
|
+
return 'unset';
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (props.isActive) {
|
|
159
|
+
return 'rgba(38, 132, 255, 20%) 0px 1px 4px ';
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return 'unset';
|
|
163
|
+
}};
|
|
164
|
+
transition: box-shadow 100ms linear;
|
|
165
|
+
|
|
166
|
+
display: ${props => {
|
|
167
|
+
if (props.isDisabled) {
|
|
168
|
+
return 'none';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return 'inline-flex';
|
|
172
|
+
}};
|
|
173
|
+
`;
|
|
174
|
+
const longFormButtonStyle = (0, _styledComponents.css)`
|
|
175
|
+
${buttonStyle}
|
|
176
|
+
color: ${props => {
|
|
177
|
+
if (props.readOnly) {
|
|
178
|
+
return '#c1c7d0';
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (props.isActive) {
|
|
182
|
+
return '#ED8B00';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return '#6b7280';
|
|
186
|
+
}};
|
|
187
|
+
border: solid 1px
|
|
188
|
+
${props => {
|
|
189
|
+
if (props.readOnly) {
|
|
190
|
+
return '#c1c7d0';
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (props.isActive) {
|
|
194
|
+
return '#ED8B00';
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return '#FECC85';
|
|
198
|
+
}};
|
|
199
|
+
box-shadow: ${props => {
|
|
200
|
+
if (props.readOnly) {
|
|
201
|
+
return 'unset';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (props.isActive) {
|
|
205
|
+
return 'rgba(237, 139, 0, 0.5) 0px 1px 4px';
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return 'unset';
|
|
209
|
+
}};
|
|
210
|
+
`;
|
|
211
|
+
const CustomFontColorButton = (0, _styledComponents.default)(_fontColor.FontColorButton)`
|
|
212
|
+
${buttonStyle}
|
|
213
|
+
`;
|
|
214
|
+
const CustomBackgroundColorButton = (0, _styledComponents.default)(_backgroundColor.BackgroundColorButton)`
|
|
215
|
+
${longFormButtonStyle}
|
|
216
|
+
`;
|
|
217
|
+
const CustomButton = _styledComponents.default.div`
|
|
218
|
+
${buttonStyle}
|
|
219
|
+
`;
|
|
220
|
+
const CustomAnnotationButton = (0, _styledComponents.default)(_annotation.AnnotationButton)`
|
|
221
|
+
${buttonStyle}
|
|
222
|
+
`;
|
|
223
|
+
const CustomLinkButton = (0, _styledComponents.default)(_link.LinkButton)`
|
|
224
|
+
${buttonStyle}
|
|
225
|
+
`;
|
|
226
|
+
|
|
227
|
+
function createButtonWithoutProps(referenceComponent, isLongForm = false, additionalCSS = ``) {
|
|
228
|
+
return isLongForm ? (0, _styledComponents.default)(referenceComponent)`
|
|
229
|
+
${longFormButtonStyle}
|
|
230
|
+
${additionalCSS}
|
|
231
|
+
` : (0, _styledComponents.default)(referenceComponent)`
|
|
232
|
+
${buttonStyle}
|
|
233
|
+
${additionalCSS}
|
|
234
|
+
`;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const CustomEnlargeButton = createButtonWithoutProps(_enlarge.EnlargeButton, false, `color: #999`);
|
|
238
|
+
const CustomImageButton = createButtonWithoutProps(_image.ImageButton);
|
|
239
|
+
const CustomSlideshowButton = createButtonWithoutProps(_slideshow.SlideshowButton);
|
|
240
|
+
const CustomEmbeddedCodeButton = createButtonWithoutProps(_embeddedCode.EmbeddedCodeButton);
|
|
241
|
+
const CustomTableButton = createButtonWithoutProps(_table.TableButton);
|
|
242
|
+
const CustomInfoBoxButton = createButtonWithoutProps(_infoBox.InfoBoxButton);
|
|
243
|
+
const CustomDividerButton = createButtonWithoutProps(_divider.DividerButton);
|
|
244
|
+
const CustomColorBoxButton = createButtonWithoutProps(_colorBox.ColorBoxButton, true);
|
|
245
|
+
const CustomBGImageButton = createButtonWithoutProps(_backgroundImage.BGImageButton, true);
|
|
246
|
+
const CustomBGVideoButton = createButtonWithoutProps(_backgroundVideo.BGVideoButton, true);
|
|
247
|
+
const CustomRelatedPostButton = createButtonWithoutProps(_relatedPost.RelatedPostButton, true);
|
|
248
|
+
const CustomSideIndexButton = createButtonWithoutProps(_sideIndex.SideIndexButton, true);
|
|
249
|
+
const CustomAlignCenterButton = createButtonWithoutProps(_textAlign.AlignCenterButton, true);
|
|
250
|
+
const CustomAlignLeftButton = createButtonWithoutProps(_textAlign.AlignLeftButton, true);
|
|
251
|
+
const CustomVideoButton = createButtonWithoutProps(_video.VideoButton);
|
|
252
|
+
const CustomAudioButton = createButtonWithoutProps(_audio.AudioButton);
|
|
253
|
+
const DraftEditorWrapper = _styledComponents.default.div`
|
|
254
|
+
/* Rich-editor default setting (.RichEditor-root)*/
|
|
255
|
+
background: #fff;
|
|
256
|
+
border: 1px solid #ddd;
|
|
257
|
+
font-family: 'Georgia', serif;
|
|
258
|
+
font-size: 14px;
|
|
259
|
+
padding: 15px;
|
|
260
|
+
|
|
261
|
+
/* Custom setting */
|
|
262
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
|
263
|
+
'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji',
|
|
264
|
+
'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
|
|
265
|
+
width: 100%;
|
|
266
|
+
height: 100%;
|
|
267
|
+
background: rgb(255, 255, 255);
|
|
268
|
+
border-radius: 6px;
|
|
269
|
+
padding: 0 1rem 1rem;
|
|
270
|
+
|
|
271
|
+
/* Draft built-in buttons' style */
|
|
272
|
+
.public-DraftStyleDefault-header-two {
|
|
273
|
+
}
|
|
274
|
+
.public-DraftStyleDefault-header-three {
|
|
275
|
+
}
|
|
276
|
+
.public-DraftStyleDefault-header-four {
|
|
277
|
+
}
|
|
278
|
+
.public-DraftStyleDefault-blockquote {
|
|
279
|
+
}
|
|
280
|
+
.public-DraftStyleDefault-ul {
|
|
281
|
+
}
|
|
282
|
+
.public-DraftStyleDefault-unorderedListItem {
|
|
283
|
+
}
|
|
284
|
+
.public-DraftStyleDefault-ol {
|
|
285
|
+
}
|
|
286
|
+
.public-DraftStyleDefault-orderedListItem {
|
|
287
|
+
}
|
|
288
|
+
/* code-block */
|
|
289
|
+
.public-DraftStyleDefault-pre {
|
|
290
|
+
}
|
|
291
|
+
.alignCenter * {
|
|
292
|
+
text-align: center;
|
|
293
|
+
}
|
|
294
|
+
.alignLeft * {
|
|
295
|
+
text-align: left;
|
|
296
|
+
}
|
|
297
|
+
`;
|
|
298
|
+
const DraftEditorControls = _styledComponents.default.div`
|
|
299
|
+
padding-top: 1rem;
|
|
300
|
+
width: 100%;
|
|
301
|
+
background: rgb(255, 255, 255);
|
|
302
|
+
`;
|
|
303
|
+
const DraftEditorControlsWrapper = _styledComponents.default.div`
|
|
304
|
+
width: 100%;
|
|
305
|
+
position: relative;
|
|
306
|
+
display: flex;
|
|
307
|
+
flex-direction: row;
|
|
308
|
+
flex-wrap: wrap;
|
|
309
|
+
padding-right: 45px;
|
|
310
|
+
`;
|
|
311
|
+
const TextEditorWrapper = _styledComponents.default.div`
|
|
312
|
+
/* Rich-editor default setting (.RichEditor-editor)*/
|
|
313
|
+
border-top: 1px solid #ddd;
|
|
314
|
+
cursor: text;
|
|
315
|
+
font-size: 16px;
|
|
316
|
+
margin-top: 10px;
|
|
317
|
+
/* Custom setting */
|
|
318
|
+
h2 {
|
|
319
|
+
font-size: 22px;
|
|
320
|
+
}
|
|
321
|
+
h3 {
|
|
322
|
+
font-size: 17.5px;
|
|
323
|
+
}
|
|
324
|
+
font-weight: normal;
|
|
325
|
+
max-width: 800px;
|
|
326
|
+
|
|
327
|
+
// atimoic block float setting
|
|
328
|
+
display: flow-root;
|
|
329
|
+
figure {
|
|
330
|
+
clear: both;
|
|
331
|
+
margin: 0;
|
|
332
|
+
}
|
|
333
|
+
figure.left {
|
|
334
|
+
float: left;
|
|
335
|
+
width: 33%;
|
|
336
|
+
}
|
|
337
|
+
figure.right {
|
|
338
|
+
float: right;
|
|
339
|
+
width: 33%;
|
|
340
|
+
}
|
|
341
|
+
`;
|
|
342
|
+
const DraftEditorContainer = _styledComponents.default.div`
|
|
343
|
+
position: relative;
|
|
344
|
+
margin-top: 4px;
|
|
345
|
+
${props => props.isEnlarged ? (0, _styledComponents.css)`
|
|
346
|
+
position: fixed;
|
|
347
|
+
width: 100%;
|
|
348
|
+
height: 100%;
|
|
349
|
+
top: 0;
|
|
350
|
+
left: 0;
|
|
351
|
+
z-index: 30;
|
|
352
|
+
padding-left: 3em;
|
|
353
|
+
padding-right: 3em;
|
|
354
|
+
background: rgba(0, 0, 0, 0.5);
|
|
355
|
+
` : ''}
|
|
356
|
+
${DraftEditorWrapper} {
|
|
357
|
+
${props => props.isEnlarged ? (0, _styledComponents.css)`
|
|
358
|
+
width: 100%;
|
|
359
|
+
height: 100%;
|
|
360
|
+
padding: 0 1rem 0;
|
|
361
|
+
overflow: scroll;
|
|
362
|
+
` : ''}
|
|
363
|
+
}
|
|
364
|
+
${DraftEditorControls} {
|
|
365
|
+
${props => props.isEnlarged ? (0, _styledComponents.css)`
|
|
366
|
+
position: sticky;
|
|
367
|
+
top: 0;
|
|
368
|
+
z-index: 12;
|
|
369
|
+
` : ''}
|
|
370
|
+
}
|
|
371
|
+
${DraftEditorControlsWrapper} {
|
|
372
|
+
${props => props.isEnlarged ? (0, _styledComponents.css)`
|
|
373
|
+
overflow: auto;
|
|
374
|
+
padding-bottom: 0;
|
|
375
|
+
` : ''}
|
|
376
|
+
}
|
|
377
|
+
${TextEditorWrapper} {
|
|
378
|
+
${props => props.isEnlarged ? (0, _styledComponents.css)`
|
|
379
|
+
max-width: 100%;
|
|
380
|
+
min-height: 100vh;
|
|
381
|
+
padding-bottom: 0;
|
|
382
|
+
` : ''}
|
|
383
|
+
}
|
|
384
|
+
`;
|
|
385
|
+
const ButtonGroup = _styledComponents.default.div`
|
|
386
|
+
margin: 0 10px 0 0;
|
|
387
|
+
`;
|
|
388
|
+
const EnlargeButtonWrapper = _styledComponents.default.div`
|
|
389
|
+
position: absolute;
|
|
390
|
+
top: 0;
|
|
391
|
+
right: 0;
|
|
392
|
+
margin: 0;
|
|
393
|
+
`;
|
|
394
|
+
|
|
395
|
+
class RichTextEditor extends _react.default.Component {
|
|
396
|
+
constructor(props) {
|
|
397
|
+
super(props);
|
|
398
|
+
this.state = {
|
|
399
|
+
isEnlarged: false,
|
|
400
|
+
readOnly: false
|
|
401
|
+
}; // Custom overrides for "code" style.
|
|
402
|
+
|
|
403
|
+
this.customStyleMap = {
|
|
404
|
+
CODE: {
|
|
405
|
+
backgroundColor: 'rgba(0, 0, 0, 0.05)',
|
|
406
|
+
fontFamily: '"Inconsolata", "Menlo", "Consolas", monospace',
|
|
407
|
+
fontSize: 16,
|
|
408
|
+
padding: 2
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
onChange = editorState => {
|
|
414
|
+
this.props.onChange(editorState);
|
|
415
|
+
};
|
|
416
|
+
handleKeyCommand = (command, editorState) => {
|
|
417
|
+
const newState = _draftJs.RichUtils.handleKeyCommand(editorState, command);
|
|
418
|
+
|
|
419
|
+
if (newState) {
|
|
420
|
+
this.onChange(newState);
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return false;
|
|
425
|
+
};
|
|
426
|
+
handleReturn = event => {
|
|
427
|
+
if (_draftJs.KeyBindingUtil.isSoftNewlineEvent(event)) {
|
|
428
|
+
const {
|
|
429
|
+
onChange,
|
|
430
|
+
editorState
|
|
431
|
+
} = this.props;
|
|
432
|
+
onChange(_draftJs.RichUtils.insertSoftNewline(editorState));
|
|
433
|
+
return 'handled';
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
return 'not-handled';
|
|
437
|
+
};
|
|
438
|
+
mapKeyToEditorCommand = e => {
|
|
439
|
+
if (e.keyCode === 9
|
|
440
|
+
/* TAB */
|
|
441
|
+
) {
|
|
442
|
+
const newEditorState = _draftJs.RichUtils.onTab(e, this.props.editorState, 4
|
|
443
|
+
/* maxDepth */
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
if (newEditorState !== this.props.editorState) {
|
|
447
|
+
this.onChange(newEditorState);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return (0, _draftJs.getDefaultKeyBinding)(e);
|
|
454
|
+
};
|
|
455
|
+
toggleBlockType = blockType => {
|
|
456
|
+
this.onChange(_draftJs.RichUtils.toggleBlockType(this.props.editorState, blockType));
|
|
457
|
+
};
|
|
458
|
+
toggleInlineStyle = inlineStyle => {
|
|
459
|
+
this.onChange(_draftJs.RichUtils.toggleInlineStyle(this.props.editorState, inlineStyle));
|
|
460
|
+
};
|
|
461
|
+
getEntityType = editorState => {
|
|
462
|
+
const contentState = editorState.getCurrentContent();
|
|
463
|
+
const selection = editorState.getSelection();
|
|
464
|
+
const startOffset = selection.getStartOffset();
|
|
465
|
+
const startBlock = editorState.getCurrentContent().getBlockForKey(selection.getStartKey());
|
|
466
|
+
const endOffset = selection.getEndOffset();
|
|
467
|
+
let entityInstance;
|
|
468
|
+
let entityKey;
|
|
469
|
+
|
|
470
|
+
if (!selection.isCollapsed()) {
|
|
471
|
+
entityKey = startBlock.getEntityAt(startOffset);
|
|
472
|
+
} else {
|
|
473
|
+
entityKey = startBlock.getEntityAt(endOffset);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if (entityKey !== null) {
|
|
477
|
+
entityInstance = contentState.getEntity(entityKey);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
let entityType = '';
|
|
481
|
+
|
|
482
|
+
if (entityInstance) {
|
|
483
|
+
entityType = entityInstance.getType();
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return entityType;
|
|
487
|
+
};
|
|
488
|
+
getCustomStyle = style => {
|
|
489
|
+
return style.reduce((styles, styleName) => {
|
|
490
|
+
if (styleName !== null && styleName !== void 0 && styleName.startsWith(_const.CUSTOM_STYLE_PREFIX_FONT_COLOR)) {
|
|
491
|
+
styles['color'] = styleName.split(_const.CUSTOM_STYLE_PREFIX_FONT_COLOR)[1];
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if (styleName !== null && styleName !== void 0 && styleName.startsWith(_const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR)) {
|
|
495
|
+
styles['backgroundColor'] = styleName.split(_const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR)[1];
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return styles;
|
|
499
|
+
}, {});
|
|
500
|
+
};
|
|
501
|
+
toggleEnlarge = () => {
|
|
502
|
+
this.setState({
|
|
503
|
+
isEnlarged: !this.state.isEnlarged
|
|
504
|
+
});
|
|
505
|
+
};
|
|
506
|
+
customStyleFn = style => {
|
|
507
|
+
return this.getCustomStyle(style);
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
blockStyleFn(block) {
|
|
511
|
+
var _entity$getData;
|
|
512
|
+
|
|
513
|
+
const {
|
|
514
|
+
editorState
|
|
515
|
+
} = this.props;
|
|
516
|
+
const entityKey = block.getEntityAt(0);
|
|
517
|
+
const entity = entityKey ? editorState.getCurrentContent().getEntity(entityKey) : null;
|
|
518
|
+
let result = '';
|
|
519
|
+
const blockData = block.getData();
|
|
520
|
+
|
|
521
|
+
if (blockData) {
|
|
522
|
+
const textAlign = blockData === null || blockData === void 0 ? void 0 : blockData.get('textAlign');
|
|
523
|
+
|
|
524
|
+
if (textAlign === 'center') {
|
|
525
|
+
result += 'alignCenter ';
|
|
526
|
+
} else if (textAlign === 'left') {
|
|
527
|
+
result += 'alignLeft ';
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
switch (block.getType()) {
|
|
532
|
+
case 'header-two':
|
|
533
|
+
case 'header-three':
|
|
534
|
+
case 'header-four':
|
|
535
|
+
case 'blockquote':
|
|
536
|
+
result += 'public-DraftStyleDefault-' + block.getType();
|
|
537
|
+
break;
|
|
538
|
+
|
|
539
|
+
case 'atomic':
|
|
540
|
+
if ((_entity$getData = entity.getData()) !== null && _entity$getData !== void 0 && _entity$getData.alignment) {
|
|
541
|
+
// support all atomic block to set alignment
|
|
542
|
+
result += ' ' + entity.getData().alignment;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
break;
|
|
546
|
+
|
|
547
|
+
default:
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
return result;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
blockRendererFn = block => {
|
|
555
|
+
const atomicBlockObj = (0, _blockRendererFn.atomicBlockRenderer)(block);
|
|
556
|
+
|
|
557
|
+
if (atomicBlockObj) {
|
|
558
|
+
const onEditStart = () => {
|
|
559
|
+
this.setState({
|
|
560
|
+
// If custom block renderer requires mouse interaction,
|
|
561
|
+
// [Draft.js document](https://draftjs.org/docs/advanced-topics-block-components#recommendations-and-other-notes)
|
|
562
|
+
// suggests that we should temporarily set Editor
|
|
563
|
+
// to readOnly={true} during the interaction.
|
|
564
|
+
// In readOnly={true} condition, the user does not
|
|
565
|
+
// trigger any selection changes within the editor
|
|
566
|
+
// while interacting with custom block.
|
|
567
|
+
// If we don't set readOnly={true},
|
|
568
|
+
// it will cause some subtle bugs in InfoBox button.
|
|
569
|
+
readOnly: true
|
|
570
|
+
});
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
const onEditFinish = ({
|
|
574
|
+
entityKey,
|
|
575
|
+
entityData
|
|
576
|
+
}) => {
|
|
577
|
+
if (entityKey) {
|
|
578
|
+
const oldContentState = this.props.editorState.getCurrentContent();
|
|
579
|
+
const newContentState = oldContentState.replaceEntityData(entityKey, entityData);
|
|
580
|
+
this.onChange(_draftJs.EditorState.set(this.props.editorState, {
|
|
581
|
+
currentContent: newContentState
|
|
582
|
+
}));
|
|
583
|
+
} // Custom block interaction is finished.
|
|
584
|
+
// Therefore, we set readOnly={false} to
|
|
585
|
+
// make editor editable.
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
this.setState({
|
|
589
|
+
readOnly: false
|
|
590
|
+
});
|
|
591
|
+
}; // `onEditStart` and `onEditFinish` will be passed
|
|
592
|
+
// into custom block component.
|
|
593
|
+
// We can get them via `props.blockProps.onEditStart`
|
|
594
|
+
// and `props.blockProps.onEditFinish` in the custom block components.
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
atomicBlockObj['props'] = {
|
|
598
|
+
onEditStart,
|
|
599
|
+
onEditFinish,
|
|
600
|
+
getMainEditorReadOnly: () => this.state.readOnly,
|
|
601
|
+
renderBasicEditor: propsOfBasicEditor => {
|
|
602
|
+
return /*#__PURE__*/_react.default.createElement(RichTextEditor, _extends({}, propsOfBasicEditor, {
|
|
603
|
+
disabledButtons: disabledButtonsOnBasicEditor
|
|
604
|
+
}));
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
return atomicBlockObj;
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
render() {
|
|
613
|
+
const {
|
|
614
|
+
disabledButtons = []
|
|
615
|
+
} = this.props;
|
|
616
|
+
let {
|
|
617
|
+
editorState
|
|
618
|
+
} = this.props;
|
|
619
|
+
|
|
620
|
+
if (!(editorState instanceof _draftJs.EditorState)) {
|
|
621
|
+
editorState = _draftJs.EditorState.createEmpty(_entityDecorator.default);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const {
|
|
625
|
+
isEnlarged,
|
|
626
|
+
readOnly
|
|
627
|
+
} = this.state;
|
|
628
|
+
const entityType = this.getEntityType(editorState);
|
|
629
|
+
const customStyle = this.getCustomStyle(editorState.getCurrentInlineStyle());
|
|
630
|
+
|
|
631
|
+
const renderBasicEditor = propsOfBasicEditor => {
|
|
632
|
+
return /*#__PURE__*/_react.default.createElement(RichTextEditor, _extends({}, propsOfBasicEditor, {
|
|
633
|
+
disabledButtons: disabledButtonsOnBasicEditor
|
|
634
|
+
}));
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
return /*#__PURE__*/_react.default.createElement(_styledComponents.ThemeProvider, {
|
|
638
|
+
theme: _theme.default
|
|
639
|
+
}, /*#__PURE__*/_react.default.createElement(DraftEditorContainer, {
|
|
640
|
+
isEnlarged: isEnlarged
|
|
641
|
+
}, /*#__PURE__*/_react.default.createElement(DraftEditorWrapper, null, /*#__PURE__*/_react.default.createElement("link", {
|
|
642
|
+
href: "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css",
|
|
643
|
+
rel: "stylesheet",
|
|
644
|
+
type: "text/css"
|
|
645
|
+
}), /*#__PURE__*/_react.default.createElement("link", {
|
|
646
|
+
href: "https://storage.googleapis.com/static-readr-tw-dev/cdn/draft-js/rich-editor.css",
|
|
647
|
+
rel: "stylesheet",
|
|
648
|
+
type: "text/css"
|
|
649
|
+
}), /*#__PURE__*/_react.default.createElement("link", {
|
|
650
|
+
href: "https://cdnjs.cloudflare.com/ajax/libs/draft-js/0.11.7/Draft.css",
|
|
651
|
+
rel: "stylesheet",
|
|
652
|
+
type: "text/css"
|
|
653
|
+
}), /*#__PURE__*/_react.default.createElement("link", {
|
|
654
|
+
href: "https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css",
|
|
655
|
+
rel: "stylesheet",
|
|
656
|
+
type: "text/css"
|
|
657
|
+
}), /*#__PURE__*/_react.default.createElement(DraftEditorControls, null, /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(BlockStyleControls, {
|
|
658
|
+
disabledButtons: disabledButtons,
|
|
659
|
+
editorState: editorState,
|
|
660
|
+
onToggle: this.toggleBlockType,
|
|
661
|
+
readOnly: this.state.readOnly
|
|
662
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(InlineStyleControls, {
|
|
663
|
+
disabledButtons: disabledButtons,
|
|
664
|
+
editorState: editorState,
|
|
665
|
+
onToggle: this.toggleInlineStyle,
|
|
666
|
+
readOnly: this.state.readOnly
|
|
667
|
+
})), /*#__PURE__*/_react.default.createElement(EnlargeButtonWrapper, null, /*#__PURE__*/_react.default.createElement(CustomEnlargeButton, {
|
|
668
|
+
onToggle: this.toggleEnlarge,
|
|
669
|
+
isEnlarged: isEnlarged
|
|
670
|
+
}))), /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomLinkButton, {
|
|
671
|
+
isDisabled: disabledButtons.includes(buttonNames.link),
|
|
672
|
+
isActive: entityType === 'LINK',
|
|
673
|
+
editorState: editorState,
|
|
674
|
+
onChange: this.onChange,
|
|
675
|
+
readOnly: this.state.readOnly
|
|
676
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomFontColorButton, {
|
|
677
|
+
isDisabled: disabledButtons.includes(buttonNames.fontColor),
|
|
678
|
+
isActive: Object.prototype.hasOwnProperty.call(customStyle, 'color'),
|
|
679
|
+
editorState: editorState,
|
|
680
|
+
onChange: this.onChange,
|
|
681
|
+
readOnly: this.state.readOnly
|
|
682
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomDividerButton, {
|
|
683
|
+
isDisabled: disabledButtons.includes(buttonNames.divider),
|
|
684
|
+
editorState: editorState,
|
|
685
|
+
onChange: this.onChange
|
|
686
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomAnnotationButton, {
|
|
687
|
+
isDisabled: disabledButtons.includes(buttonNames.annotation),
|
|
688
|
+
isActive: entityType === 'ANNOTATION',
|
|
689
|
+
editorState: editorState,
|
|
690
|
+
onChange: this.onChange,
|
|
691
|
+
readOnly: this.state.readOnly,
|
|
692
|
+
renderBasicEditor: renderBasicEditor,
|
|
693
|
+
decorators: _entityDecorator.default
|
|
694
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomImageButton, {
|
|
695
|
+
isDisabled: disabledButtons.includes(buttonNames.image),
|
|
696
|
+
editorState: editorState,
|
|
697
|
+
onChange: this.onChange,
|
|
698
|
+
readOnly: this.state.readOnly,
|
|
699
|
+
ImageSelector: _imageSelector.ImageSelector
|
|
700
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomVideoButton, {
|
|
701
|
+
isDisabled: disabledButtons.includes(buttonNames.video),
|
|
702
|
+
editorState: editorState,
|
|
703
|
+
onChange: this.onChange,
|
|
704
|
+
readOnly: this.state.readOnly,
|
|
705
|
+
VideoSelector: _videoSelector.VideoSelector
|
|
706
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomAudioButton, {
|
|
707
|
+
isDisabled: disabledButtons.includes(buttonNames.audio),
|
|
708
|
+
editorState: editorState,
|
|
709
|
+
onChange: this.onChange,
|
|
710
|
+
readOnly: this.state.readOnly,
|
|
711
|
+
AudioSelector: _audioSelector.AudioSelector
|
|
712
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomSlideshowButton, {
|
|
713
|
+
isDisabled: disabledButtons.includes(buttonNames.slideshow),
|
|
714
|
+
editorState: editorState,
|
|
715
|
+
onChange: this.onChange,
|
|
716
|
+
readOnly: this.state.readOnly,
|
|
717
|
+
ImageSelector: _imageSelector.ImageSelector
|
|
718
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomInfoBoxButton, {
|
|
719
|
+
isDisabled: disabledButtons.includes(buttonNames.infoBox),
|
|
720
|
+
editorState: editorState,
|
|
721
|
+
onChange: this.onChange,
|
|
722
|
+
readOnly: this.state.readOnly,
|
|
723
|
+
renderBasicEditor: renderBasicEditor,
|
|
724
|
+
decorators: _entityDecorator.default
|
|
725
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomEmbeddedCodeButton, {
|
|
726
|
+
isDisabled: disabledButtons.includes(buttonNames.embed),
|
|
727
|
+
editorState: editorState,
|
|
728
|
+
onChange: this.onChange,
|
|
729
|
+
readOnly: this.state.readOnly
|
|
730
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomTableButton, {
|
|
731
|
+
isDisabled: disabledButtons.includes(buttonNames.table),
|
|
732
|
+
editorState: editorState,
|
|
733
|
+
onChange: this.onChange,
|
|
734
|
+
readOnly: this.state.readOnly
|
|
735
|
+
}))), /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomAlignLeftButton, {
|
|
736
|
+
isDisabled: disabledButtons.includes(buttonNames.textAlign),
|
|
737
|
+
isActive: (0, _textAlign.getSelectionBlockData)(editorState, 'textAlign') === 'left',
|
|
738
|
+
editorState: editorState,
|
|
739
|
+
onChange: this.onChange,
|
|
740
|
+
readOnly: this.state.readOnly
|
|
741
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomAlignCenterButton, {
|
|
742
|
+
isDisabled: disabledButtons.includes(buttonNames.textAlign),
|
|
743
|
+
isActive: (0, _textAlign.getSelectionBlockData)(editorState, 'textAlign') === 'center',
|
|
744
|
+
editorState: editorState,
|
|
745
|
+
onChange: this.onChange,
|
|
746
|
+
readOnly: this.state.readOnly
|
|
747
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomColorBoxButton, {
|
|
748
|
+
isDisabled: disabledButtons.includes(buttonNames.colorBox),
|
|
749
|
+
editorState: editorState,
|
|
750
|
+
onChange: this.onChange,
|
|
751
|
+
readOnly: this.state.readOnly,
|
|
752
|
+
renderBasicEditor: renderBasicEditor,
|
|
753
|
+
decorators: _entityDecorator.default
|
|
754
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomBackgroundColorButton, {
|
|
755
|
+
isDisabled: disabledButtons.includes(buttonNames.backgroundColor),
|
|
756
|
+
isActive: Object.prototype.hasOwnProperty.call(customStyle, 'backgroundColor'),
|
|
757
|
+
editorState: editorState,
|
|
758
|
+
onChange: this.onChange,
|
|
759
|
+
readOnly: this.state.readOnly
|
|
760
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomBGImageButton, {
|
|
761
|
+
isDisabled: disabledButtons.includes(buttonNames.backgroundImage),
|
|
762
|
+
editorState: editorState,
|
|
763
|
+
onChange: this.onChange,
|
|
764
|
+
readOnly: this.state.readOnly,
|
|
765
|
+
ImageSelector: _imageSelector.ImageSelector,
|
|
766
|
+
renderBasicEditor: renderBasicEditor,
|
|
767
|
+
decorators: _entityDecorator.default
|
|
768
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomBGVideoButton, {
|
|
769
|
+
isDisabled: disabledButtons.includes(buttonNames.backgroundVideo),
|
|
770
|
+
editorState: editorState,
|
|
771
|
+
onChange: this.onChange,
|
|
772
|
+
readOnly: this.state.readOnly,
|
|
773
|
+
VideoSelector: _videoSelector.VideoSelector,
|
|
774
|
+
renderBasicEditor: renderBasicEditor,
|
|
775
|
+
decorators: _entityDecorator.default
|
|
776
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomRelatedPostButton, {
|
|
777
|
+
isDisabled: disabledButtons.includes(buttonNames.relatedPost),
|
|
778
|
+
editorState: editorState,
|
|
779
|
+
onChange: this.onChange,
|
|
780
|
+
readOnly: this.state.readOnly,
|
|
781
|
+
PostSelector: _postSelector.PostSelector
|
|
782
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomSideIndexButton, {
|
|
783
|
+
isDisabled: disabledButtons.includes(buttonNames.sideIndex),
|
|
784
|
+
editorState: editorState,
|
|
785
|
+
onChange: this.onChange,
|
|
786
|
+
readOnly: this.state.readOnly
|
|
787
|
+
})))), /*#__PURE__*/_react.default.createElement(TextEditorWrapper, {
|
|
788
|
+
onClick: () => {
|
|
789
|
+
var _this$refs$editor;
|
|
790
|
+
|
|
791
|
+
// eslint-disable-next-line prettier/prettier
|
|
792
|
+
(_this$refs$editor = this.refs.editor) === null || _this$refs$editor === void 0 ? void 0 : _this$refs$editor.focus();
|
|
793
|
+
}
|
|
794
|
+
}, /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
|
|
795
|
+
blockStyleFn: this.blockStyleFn.bind(this),
|
|
796
|
+
blockRendererFn: this.blockRendererFn,
|
|
797
|
+
customStyleMap: this.customStyleMap,
|
|
798
|
+
customStyleFn: this.customStyleFn,
|
|
799
|
+
editorState: editorState,
|
|
800
|
+
handleKeyCommand: this.handleKeyCommand,
|
|
801
|
+
handleReturn: this.handleReturn,
|
|
802
|
+
keyBindingFn: this.mapKeyToEditorCommand,
|
|
803
|
+
onChange: this.onChange,
|
|
804
|
+
placeholder: "Tell a story...",
|
|
805
|
+
ref: "editor",
|
|
806
|
+
spellCheck: true,
|
|
807
|
+
readOnly: readOnly
|
|
808
|
+
})))));
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
class StyleButton extends _react.default.Component {
|
|
814
|
+
onToggle = e => {
|
|
815
|
+
e.preventDefault();
|
|
816
|
+
this.props.onToggle(this.props.style);
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
render() {
|
|
820
|
+
return /*#__PURE__*/_react.default.createElement(CustomButton, {
|
|
821
|
+
isDisabled: this.props.isDisabled,
|
|
822
|
+
isActive: this.props.active,
|
|
823
|
+
onMouseDown: this.onToggle,
|
|
824
|
+
readOnly: this.props.readOnly
|
|
825
|
+
}, this.props.icon && /*#__PURE__*/_react.default.createElement("i", {
|
|
826
|
+
className: this.props.icon
|
|
827
|
+
}), /*#__PURE__*/_react.default.createElement("span", null, !this.props.icon ? this.props.label : ''));
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
const blockStyles = [{
|
|
833
|
+
label: 'H2',
|
|
834
|
+
style: 'header-two',
|
|
835
|
+
icon: ''
|
|
836
|
+
}, {
|
|
837
|
+
label: 'H3',
|
|
838
|
+
style: 'header-three',
|
|
839
|
+
icon: ''
|
|
840
|
+
}, {
|
|
841
|
+
label: 'H4',
|
|
842
|
+
style: 'header-four',
|
|
843
|
+
icon: ''
|
|
844
|
+
}, {
|
|
845
|
+
label: 'Blockquote',
|
|
846
|
+
style: 'blockquote',
|
|
847
|
+
icon: 'fas fa-quote-right'
|
|
848
|
+
}, {
|
|
849
|
+
label: 'UL',
|
|
850
|
+
style: 'unordered-list-item',
|
|
851
|
+
icon: 'fas fa-list-ul'
|
|
852
|
+
}, {
|
|
853
|
+
label: 'OL',
|
|
854
|
+
style: 'ordered-list-item',
|
|
855
|
+
icon: 'fas fa-list-ol'
|
|
856
|
+
}, {
|
|
857
|
+
label: 'Code Block',
|
|
858
|
+
style: 'code-block',
|
|
859
|
+
icon: 'fas fa-code'
|
|
860
|
+
}];
|
|
861
|
+
|
|
862
|
+
const BlockStyleControls = props => {
|
|
863
|
+
const {
|
|
864
|
+
editorState,
|
|
865
|
+
disabledButtons
|
|
866
|
+
} = props;
|
|
867
|
+
const selection = editorState.getSelection();
|
|
868
|
+
const blockType = editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
|
|
869
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, blockStyles.map(type => /*#__PURE__*/_react.default.createElement(StyleButton, {
|
|
870
|
+
isDisabled: disabledButtons.includes(type.style),
|
|
871
|
+
key: type.label,
|
|
872
|
+
active: type.style === blockType,
|
|
873
|
+
label: type.label,
|
|
874
|
+
onToggle: props.onToggle,
|
|
875
|
+
style: type.style,
|
|
876
|
+
icon: type.icon,
|
|
877
|
+
readOnly: props.readOnly
|
|
878
|
+
})));
|
|
879
|
+
};
|
|
880
|
+
|
|
881
|
+
const inlineStyles = [{
|
|
882
|
+
label: 'Bold',
|
|
883
|
+
style: 'BOLD',
|
|
884
|
+
icon: 'fas fa-bold'
|
|
885
|
+
}, {
|
|
886
|
+
label: 'Italic',
|
|
887
|
+
style: 'ITALIC',
|
|
888
|
+
icon: 'fas fa-italic'
|
|
889
|
+
}, {
|
|
890
|
+
label: 'Underline',
|
|
891
|
+
style: 'UNDERLINE',
|
|
892
|
+
icon: 'fas fa-underline'
|
|
893
|
+
}, {
|
|
894
|
+
label: 'Monospace',
|
|
895
|
+
style: 'CODE',
|
|
896
|
+
icon: 'fas fa-terminal'
|
|
897
|
+
}];
|
|
898
|
+
|
|
899
|
+
const InlineStyleControls = props => {
|
|
900
|
+
const currentStyle = props.editorState.getCurrentInlineStyle();
|
|
901
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, inlineStyles.map(type => /*#__PURE__*/_react.default.createElement(StyleButton, {
|
|
902
|
+
isDisabled: props.disabledButtons.includes(type.style.toLowerCase()),
|
|
903
|
+
key: type.label,
|
|
904
|
+
active: currentStyle.has(type.style),
|
|
905
|
+
label: type.label,
|
|
906
|
+
onToggle: props.onToggle,
|
|
907
|
+
style: type.style,
|
|
908
|
+
icon: type.icon,
|
|
909
|
+
readOnly: props.readOnly
|
|
910
|
+
})));
|
|
911
|
+
};
|
|
912
|
+
|
|
913
|
+
const DraftEditor = {
|
|
914
|
+
RichTextEditor,
|
|
915
|
+
decorators: _entityDecorator.default
|
|
916
|
+
};
|
|
917
|
+
var _default = DraftEditor;
|
|
918
|
+
exports.default = _default;
|