@mirrormedia/lilith-draft-editor 2.3.0 → 3.0.1

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