@kids-reporter/draft-editor 0.1.0 → 0.2.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.
Files changed (40) hide show
  1. package/lib/buttons/annotation.js +1 -14
  2. package/lib/buttons/image.js +0 -3
  3. package/lib/buttons/info-box.js +1 -4
  4. package/lib/buttons/selector/image-selector.js +3 -1
  5. package/lib/buttons/slideshow.js +2 -3
  6. package/lib/draft-editor.js +61 -363
  7. package/package.json +12 -7
  8. package/lib/block-renderer/background-image-block.js +0 -141
  9. package/lib/block-renderer/background-video-block.js +0 -151
  10. package/lib/block-renderer/color-box-block.js +0 -86
  11. package/lib/block-renderer/info-box-block.js +0 -86
  12. package/lib/block-renderer/side-index-block.js +0 -90
  13. package/lib/block-renderer/table-block.js +0 -408
  14. package/lib/block-renderer-fn.js +0 -131
  15. package/lib/buttons/audio.js +0 -65
  16. package/lib/buttons/background-color.js +0 -122
  17. package/lib/buttons/background-image.js +0 -223
  18. package/lib/buttons/background-video.js +0 -223
  19. package/lib/buttons/color-box.js +0 -173
  20. package/lib/buttons/divider.js +0 -63
  21. package/lib/buttons/font-color.js +0 -115
  22. package/lib/buttons/media.js +0 -121
  23. package/lib/buttons/related-post.js +0 -71
  24. package/lib/buttons/selector/audio-selector.js +0 -279
  25. package/lib/buttons/selector/post-selector.js +0 -317
  26. package/lib/buttons/selector/video-selector.js +0 -281
  27. package/lib/buttons/side-index.js +0 -200
  28. package/lib/buttons/table.js +0 -67
  29. package/lib/buttons/text-align.js +0 -88
  30. package/lib/buttons/video.js +0 -65
  31. package/lib/buttons/youtube.js +0 -147
  32. package/lib/const.js +0 -18
  33. package/lib/draft-converter/api-data-instance.js +0 -58
  34. package/lib/draft-converter/atomic-block-processor.js +0 -233
  35. package/lib/draft-converter/entities.js +0 -76
  36. package/lib/draft-converter/index.js +0 -201
  37. package/lib/draft-converter/inline-styles-processor.js +0 -236
  38. package/lib/entity-decorator.js +0 -20
  39. package/lib/modifier.js +0 -68
  40. package/lib/theme/index.js +0 -39
@@ -3,19 +3,22 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.buttonNames = void 0;
6
+ exports.buttonNames = exports.RichTextEditor = void 0;
7
+ Object.defineProperty(exports, "decorators", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _draftRenderer.decorators;
11
+ }
12
+ });
13
+ exports.default = void 0;
7
14
 
8
15
  var _react = _interopRequireDefault(require("react"));
9
16
 
10
17
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
11
18
 
12
- var _theme = _interopRequireDefault(require("./theme"));
13
-
14
19
  var _draftJs = require("draft-js");
15
20
 
16
- var _blockRendererFn = require("./block-renderer-fn");
17
-
18
- var _entityDecorator = _interopRequireDefault(require("./entity-decorator"));
21
+ var _draftRenderer = require("@kids-reporter/draft-renderer");
19
22
 
20
23
  var _annotation = require("./buttons/annotation");
21
24
 
@@ -31,40 +34,8 @@ var _link = require("./buttons/link");
31
34
 
32
35
  var _slideshow = require("./buttons/slideshow");
33
36
 
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
37
  var _imageSelector = require("./buttons/selector/image-selector");
61
38
 
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
39
  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
40
 
70
41
  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; }
@@ -89,44 +60,27 @@ const buttonNames = {
89
60
  codeBlock: 'code-block',
90
61
  // custom styles
91
62
  annotation: 'annotation',
92
- divider: 'divider',
93
63
  embed: 'embed',
94
- fontColor: 'font-color',
95
64
  image: 'image',
96
65
  infoBox: 'info-box',
97
66
  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'
67
+ slideshow: 'slideshow'
109
68
  };
110
69
  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];
70
+ const disabledButtonsOnBasicEditor = [buttonNames.h2, buttonNames.h3, buttonNames.code, buttonNames.codeBlock, buttonNames.blockquote, buttonNames.annotation, buttonNames.embed, buttonNames.image, buttonNames.infoBox, buttonNames.slideshow];
112
71
  const buttonStyle = (0, _styledComponents.css)`
72
+ cursor: pointer;
113
73
  border-radius: 6px;
114
74
  text-align: center;
115
75
  font-size: 1rem;
116
76
  padding: 0 12px;
117
- margin: 0px 0px 10px 0px;
77
+ margin: ${props => props.isDisabled ? '0' : '0 0 10px 0'};
118
78
  background-color: #fff;
119
79
  border: solid 1px rgb(193, 199, 208);
120
80
  align-items: center;
121
81
  height: 40px;
122
82
 
123
- cursor: ${props => {
124
- if (props.readOnly) {
125
- return 'not-allowed';
126
- }
127
-
128
- return 'pointer';
129
- }};
83
+ cursor: ${props => props.readOnly ? 'not-allowed' : 'pointer'};
130
84
  color: ${props => {
131
85
  if (props.readOnly) {
132
86
  return '#c1c7d0';
@@ -171,85 +125,31 @@ const buttonStyle = (0, _styledComponents.css)`
171
125
  return 'inline-flex';
172
126
  }};
173
127
  `;
174
- const longFormButtonStyle = (0, _styledComponents.css)`
128
+ const CustomButton = _styledComponents.default.div`
129
+ ${buttonStyle}
130
+ `;
131
+ const CustomAnnotationButton = (0, _styledComponents.default)(_annotation.AnnotationButton)`
175
132
  ${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
133
  `;
211
- const CustomFontColorButton = (0, _styledComponents.default)(_fontColor.FontColorButton)`
134
+ const CustomLinkButton = (0, _styledComponents.default)(_link.LinkButton)`
212
135
  ${buttonStyle}
213
136
  `;
214
- const CustomBackgroundColorButton = (0, _styledComponents.default)(_backgroundColor.BackgroundColorButton)`
215
- ${longFormButtonStyle}
137
+ const CustomEnlargeButton = (0, _styledComponents.default)(_enlarge.EnlargeButton)`
138
+ ${buttonStyle}
139
+ color: #999;
216
140
  `;
217
- const CustomButton = _styledComponents.default.div`
141
+ const CustomImageButton = (0, _styledComponents.default)(_image.ImageButton)`
218
142
  ${buttonStyle}
219
143
  `;
220
- const CustomAnnotationButton = (0, _styledComponents.default)(_annotation.AnnotationButton)`
144
+ const CustomSlideshowButton = (0, _styledComponents.default)(_slideshow.SlideshowButton)`
221
145
  ${buttonStyle}
222
146
  `;
223
- const CustomLinkButton = (0, _styledComponents.default)(_link.LinkButton)`
147
+ const CustomEmbeddedCodeButton = (0, _styledComponents.default)(_embeddedCode.EmbeddedCodeButton)`
148
+ ${buttonStyle}
149
+ `;
150
+ const CustomInfoBoxButton = (0, _styledComponents.default)(_infoBox.InfoBoxButton)`
224
151
  ${buttonStyle}
225
152
  `;
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
153
  const DraftEditorWrapper = _styledComponents.default.div`
254
154
  /* Rich-editor default setting (.RichEditor-root)*/
255
155
  background: #fff;
@@ -267,33 +167,6 @@ const DraftEditorWrapper = _styledComponents.default.div`
267
167
  background: rgb(255, 255, 255);
268
168
  border-radius: 6px;
269
169
  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
170
  `;
298
171
  const DraftEditorControls = _styledComponents.default.div`
299
172
  padding-top: 1rem;
@@ -314,32 +187,9 @@ const TextEditorWrapper = _styledComponents.default.div`
314
187
  cursor: text;
315
188
  font-size: 16px;
316
189
  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
190
  `;
342
191
  const DraftEditorContainer = _styledComponents.default.div`
192
+ overflow-x: hidden;
343
193
  position: relative;
344
194
  margin-top: 4px;
345
195
  ${props => props.isEnlarged ? (0, _styledComponents.css)`
@@ -382,9 +232,6 @@ const DraftEditorContainer = _styledComponents.default.div`
382
232
  ` : ''}
383
233
  }
384
234
  `;
385
- const ButtonGroup = _styledComponents.default.div`
386
- margin: 0 10px 0 0;
387
- `;
388
235
  const EnlargeButtonWrapper = _styledComponents.default.div`
389
236
  position: absolute;
390
237
  top: 0;
@@ -393,20 +240,13 @@ const EnlargeButtonWrapper = _styledComponents.default.div`
393
240
  `;
394
241
 
395
242
  class RichTextEditor extends _react.default.Component {
243
+ editorRef = null;
244
+
396
245
  constructor(props) {
397
246
  super(props);
398
247
  this.state = {
399
248
  isEnlarged: false,
400
249
  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
250
  };
411
251
  }
412
252
 
@@ -418,10 +258,10 @@ class RichTextEditor extends _react.default.Component {
418
258
 
419
259
  if (newState) {
420
260
  this.onChange(newState);
421
- return true;
261
+ return 'handled';
422
262
  }
423
263
 
424
- return false;
264
+ return 'not-handled';
425
265
  };
426
266
  handleReturn = event => {
427
267
  if (_draftJs.KeyBindingUtil.isSoftNewlineEvent(event)) {
@@ -447,7 +287,7 @@ class RichTextEditor extends _react.default.Component {
447
287
  this.onChange(newEditorState);
448
288
  }
449
289
 
450
- return;
290
+ return null;
451
291
  }
452
292
 
453
293
  return (0, _draftJs.getDefaultKeyBinding)(e);
@@ -485,74 +325,13 @@ class RichTextEditor extends _react.default.Component {
485
325
 
486
326
  return entityType;
487
327
  };
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
328
  toggleEnlarge = () => {
502
329
  this.setState({
503
330
  isEnlarged: !this.state.isEnlarged
504
331
  });
505
332
  };
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
333
  blockRendererFn = block => {
555
- const atomicBlockObj = (0, _blockRendererFn.atomicBlockRenderer)(block);
334
+ const atomicBlockObj = (0, _draftRenderer.atomicBlockRenderer)(block);
556
335
 
557
336
  if (atomicBlockObj) {
558
337
  const onEditStart = () => {
@@ -618,7 +397,7 @@ class RichTextEditor extends _react.default.Component {
618
397
  } = this.props;
619
398
 
620
399
  if (!(editorState instanceof _draftJs.EditorState)) {
621
- editorState = _draftJs.EditorState.createEmpty(_entityDecorator.default);
400
+ editorState = _draftJs.EditorState.createEmpty(_draftRenderer.decorators);
622
401
  }
623
402
 
624
403
  const {
@@ -626,7 +405,6 @@ class RichTextEditor extends _react.default.Component {
626
405
  readOnly
627
406
  } = this.state;
628
407
  const entityType = this.getEntityType(editorState);
629
- const customStyle = this.getCustomStyle(editorState.getCurrentInlineStyle());
630
408
 
631
409
  const renderBasicEditor = propsOfBasicEditor => {
632
410
  return /*#__PURE__*/_react.default.createElement(RichTextEditor, _extends({}, propsOfBasicEditor, {
@@ -634,9 +412,7 @@ class RichTextEditor extends _react.default.Component {
634
412
  }));
635
413
  };
636
414
 
637
- return /*#__PURE__*/_react.default.createElement(_styledComponents.ThemeProvider, {
638
- theme: _theme.default
639
- }, /*#__PURE__*/_react.default.createElement(DraftEditorContainer, {
415
+ return /*#__PURE__*/_react.default.createElement(DraftEditorContainer, {
640
416
  isEnlarged: isEnlarged
641
417
  }, /*#__PURE__*/_react.default.createElement(DraftEditorWrapper, null, /*#__PURE__*/_react.default.createElement("link", {
642
418
  href: "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css",
@@ -654,162 +430,85 @@ class RichTextEditor extends _react.default.Component {
654
430
  href: "https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css",
655
431
  rel: "stylesheet",
656
432
  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, {
433
+ }), /*#__PURE__*/_react.default.createElement(DraftEditorControls, null, /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(BlockStyleControls, {
658
434
  disabledButtons: disabledButtons,
659
435
  editorState: editorState,
660
436
  onToggle: this.toggleBlockType,
661
437
  readOnly: this.state.readOnly
662
- })), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(InlineStyleControls, {
438
+ }), /*#__PURE__*/_react.default.createElement(InlineStyleControls, {
663
439
  disabledButtons: disabledButtons,
664
440
  editorState: editorState,
665
441
  onToggle: this.toggleInlineStyle,
666
442
  readOnly: this.state.readOnly
667
- })), /*#__PURE__*/_react.default.createElement(EnlargeButtonWrapper, null, /*#__PURE__*/_react.default.createElement(CustomEnlargeButton, {
443
+ }), /*#__PURE__*/_react.default.createElement(EnlargeButtonWrapper, null, /*#__PURE__*/_react.default.createElement(CustomEnlargeButton, {
668
444
  onToggle: this.toggleEnlarge,
669
445
  isEnlarged: isEnlarged
670
- }))), /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomLinkButton, {
446
+ })), /*#__PURE__*/_react.default.createElement(CustomLinkButton, {
671
447
  isDisabled: disabledButtons.includes(buttonNames.link),
672
448
  isActive: entityType === 'LINK',
673
449
  editorState: editorState,
674
450
  onChange: this.onChange,
675
451
  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, {
452
+ }), /*#__PURE__*/_react.default.createElement(CustomAnnotationButton, {
687
453
  isDisabled: disabledButtons.includes(buttonNames.annotation),
688
454
  isActive: entityType === 'ANNOTATION',
689
455
  editorState: editorState,
690
456
  onChange: this.onChange,
691
457
  readOnly: this.state.readOnly,
692
458
  renderBasicEditor: renderBasicEditor,
693
- decorators: _entityDecorator.default
694
- })), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomImageButton, {
459
+ decorators: _draftRenderer.decorators
460
+ }), /*#__PURE__*/_react.default.createElement(CustomImageButton, {
695
461
  isDisabled: disabledButtons.includes(buttonNames.image),
696
462
  editorState: editorState,
697
463
  onChange: this.onChange,
698
464
  readOnly: this.state.readOnly,
699
465
  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, {
466
+ }), /*#__PURE__*/_react.default.createElement(CustomSlideshowButton, {
713
467
  isDisabled: disabledButtons.includes(buttonNames.slideshow),
714
468
  editorState: editorState,
715
469
  onChange: this.onChange,
716
470
  readOnly: this.state.readOnly,
717
471
  ImageSelector: _imageSelector.ImageSelector
718
- })), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomInfoBoxButton, {
472
+ }), /*#__PURE__*/_react.default.createElement(CustomInfoBoxButton, {
719
473
  isDisabled: disabledButtons.includes(buttonNames.infoBox),
720
474
  editorState: editorState,
721
475
  onChange: this.onChange,
722
476
  readOnly: this.state.readOnly,
723
477
  renderBasicEditor: renderBasicEditor,
724
- decorators: _entityDecorator.default
725
- })), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomEmbeddedCodeButton, {
478
+ decorators: _draftRenderer.decorators
479
+ }), /*#__PURE__*/_react.default.createElement(CustomEmbeddedCodeButton, {
726
480
  isDisabled: disabledButtons.includes(buttonNames.embed),
727
481
  editorState: editorState,
728
482
  onChange: this.onChange,
729
483
  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, {
484
+ }))), /*#__PURE__*/_react.default.createElement(TextEditorWrapper, {
788
485
  onClick: () => {
789
- var _this$refs$editor;
486
+ if (this.editorRef) {
487
+ var _this$editorRef;
790
488
 
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();
489
+ // eslint-disable-next-line prettier/prettier
490
+ (_this$editorRef = this.editorRef) === null || _this$editorRef === void 0 ? void 0 : _this$editorRef.focus();
491
+ }
793
492
  }
794
493
  }, /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
795
- blockStyleFn: this.blockStyleFn.bind(this),
494
+ blockRenderMap: _draftRenderer.blockRenderMap,
796
495
  blockRendererFn: this.blockRendererFn,
797
- customStyleMap: this.customStyleMap,
798
- customStyleFn: this.customStyleFn,
799
496
  editorState: editorState,
800
497
  handleKeyCommand: this.handleKeyCommand,
801
498
  handleReturn: this.handleReturn,
802
499
  keyBindingFn: this.mapKeyToEditorCommand,
803
500
  onChange: this.onChange,
804
501
  placeholder: "Tell a story...",
805
- ref: "editor",
502
+ ref: this.editorRef,
806
503
  spellCheck: true,
807
504
  readOnly: readOnly
808
- })))));
505
+ }))));
809
506
  }
810
507
 
811
508
  }
812
509
 
510
+ exports.RichTextEditor = RichTextEditor;
511
+
813
512
  class StyleButton extends _react.default.Component {
814
513
  onToggle = e => {
815
514
  e.preventDefault();
@@ -910,9 +609,8 @@ const InlineStyleControls = props => {
910
609
  })));
911
610
  };
912
611
 
913
- const DraftEditor = {
612
+ var _default = {
914
613
  RichTextEditor,
915
- decorators: _entityDecorator.default
614
+ decorators: _draftRenderer.decorators
916
615
  };
917
- var _default = DraftEditor;
918
616
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kids-reporter/draft-editor",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -23,17 +23,22 @@
23
23
  ],
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
- "draft-js": "^0.11.7",
27
- "@kids-reporter/draft-renderer": "0.1.0"
26
+ "@kids-reporter/draft-renderer": "0.2.0",
27
+ "draft-js": "^0.11.7"
28
28
  },
29
29
  "peerDependencies": {
30
- "react": "18.2.0",
31
- "react-dom": "18.2.0",
32
- "styled-components": "5.3.5",
33
30
  "@keystone-6/core": "5.2.0",
34
31
  "@keystone-ui/button": "^7.0.2",
35
32
  "@keystone-ui/fields": "^7.2.0",
36
- "@keystone-ui/modals": "^6.0.3"
33
+ "@keystone-ui/modals": "^6.0.3",
34
+ "react": "18.2.0",
35
+ "react-dom": "18.2.0",
36
+ "styled-components": "5.3.5"
37
+ },
38
+ "devDependencies": {
39
+ "react": "18.2.0",
40
+ "react-dom": "18.2.0",
41
+ "styled-components": "5.3.5"
37
42
  },
38
43
  "files": [
39
44
  "lib"