@mirrormedia/lilith-draft-editor 3.0.12 → 3.0.13

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