@kids-reporter/draft-editor 1.0.2 → 1.0.4

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.
@@ -3,212 +3,36 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.RichTextEditor = void 0;
7
- Object.defineProperty(exports, "decorator", {
8
- enumerable: true,
9
- get: function () {
10
- return _draftRenderer.decorator;
11
- }
12
- });
13
- exports.default = void 0;
6
+ exports.default = exports.decorator = exports.RichTextEditor = void 0;
14
7
  var _react = _interopRequireDefault(require("react"));
15
- var _btNames = _interopRequireDefault(require("./buttons/bt-names"));
16
- var _styledComponents = _interopRequireWildcard(require("styled-components"));
17
8
  var _draftJs = require("draft-js");
18
- var _bgColor = require("./buttons/bg-color");
19
- var _blockquote = require("./buttons/blockquote");
20
- var _divider = require("./buttons/divider");
21
- var _embeddedCode = require("./buttons/embedded-code");
22
- var _enlarge = require("./buttons/enlarge");
23
- var _fontColor = require("./buttons/font-color");
24
- var _image = require("./buttons/image");
25
- var _link = require("./buttons/link");
26
- var _slideshow = require("./buttons/slideshow");
27
- var _imageSelector = require("./buttons/selector/image-selector");
28
- var _newsReading = require("./buttons/news-reading");
29
- var _blockRendererFn = require("./block-renderer-fn");
30
9
  var _draftRenderer = require("@kids-reporter/draft-renderer");
10
+ var _btNames = _interopRequireDefault(require("./buttons/bt-names"));
11
+ var _blockRendererFn = require("./block-renderer-fn");
12
+ var _styled = require("./styled");
13
+ var _buttons = require("./buttons");
14
+ var _imageSelector = require("./buttons/selector/image-selector");
31
15
  var _annotation = require("./buttons/annotation");
32
16
  var _infoBox = require("./buttons/info-box");
33
- 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); }
34
- 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; }
17
+ var _bgColor = require("./buttons/bg-color");
18
+ var _fontColor = require("./buttons/font-color");
19
+ var _anchor = require("./entity-decorators/anchor");
35
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
- const buttonStyle = (0, _styledComponents.css)`
37
- cursor: pointer;
38
- border-radius: 6px;
39
- text-align: center;
40
- font-size: 1rem;
41
- padding: 0 12px;
42
- margin: ${props => props.isDisabled ? '0' : '0 0 10px 0'};
43
- background-color: #fff;
44
- border: solid 1px rgb(193, 199, 208);
45
- align-items: center;
46
- height: 40px;
47
-
48
- cursor: ${props => props.readOnly ? 'not-allowed' : 'pointer'};
49
- color: ${props => {
50
- if (props.readOnly) {
51
- return '#c1c7d0';
52
- }
53
- if (props.isActive) {
54
- return '#3b82f6';
55
- }
56
- return '#6b7280';
57
- }};
58
- border: solid 1px
59
- ${props => {
60
- if (props.readOnly) {
61
- return '#c1c7d0';
62
- }
63
- if (props.isActive) {
64
- return '#3b82f6';
65
- }
66
- return '#6b7280';
67
- }};
68
- box-shadow: ${props => {
69
- if (props.readOnly) {
70
- return 'unset';
71
- }
72
- if (props.isActive) {
73
- return 'rgba(38, 132, 255, 20%) 0px 1px 4px ';
74
- }
75
- return 'unset';
76
- }};
77
- transition: box-shadow 100ms linear;
78
-
79
- display: ${props => {
80
- if (props.isDisabled) {
81
- return 'none';
82
- }
83
- return 'inline-flex';
84
- }};
85
- `;
86
-
87
- // TODO: refactor custom button
88
- // Refactoring goal is to avoid `styled()` on every button,
89
- // which is tedious and duplicate.
90
- const CustomButton = _styledComponents.default.div`
91
- ${buttonStyle}
92
- `;
93
- const CustomBlockquoteButton = (0, _styledComponents.default)(_blockquote.BlockquoteButton)`
94
- ${buttonStyle}
95
- `;
96
- const CustomLinkButton = (0, _styledComponents.default)(_link.LinkButton)`
97
- ${buttonStyle}
98
- `;
99
- const CustomEnlargeButton = (0, _styledComponents.default)(_enlarge.EnlargeButton)`
100
- ${buttonStyle}
101
- color: #999;
102
- `;
103
- const CustomImageButton = (0, _styledComponents.default)(_image.ImageButton)`
104
- ${buttonStyle}
105
- `;
106
- const CustomSlideshowButton = (0, _styledComponents.default)(_slideshow.SlideshowButton)`
107
- ${buttonStyle}
108
- `;
109
- const CustomEmbeddedCodeButton = (0, _styledComponents.default)(_embeddedCode.EmbeddedCodeButton)`
110
- ${buttonStyle}
111
- `;
112
- const CustomNewsReadingButton = (0, _styledComponents.default)(_newsReading.NewsReadingButton)`
113
- ${buttonStyle}
114
- `;
115
- const CustomBackgroundColorButton = (0, _styledComponents.default)(_bgColor.BackgroundColorButton)`
116
- ${buttonStyle}
117
- `;
118
- const CustomFontColorButton = (0, _styledComponents.default)(_fontColor.FontColorButton)`
119
- ${buttonStyle}
120
- `;
121
- const CustomDividerButton = (0, _styledComponents.default)(_divider.DividerButton)`
122
- ${buttonStyle}
123
- `;
124
- const DraftEditorWrapper = _styledComponents.default.div`
125
- /* Rich-editor default setting (.RichEditor-root)*/
126
- background: #fff;
127
- border: 1px solid #ddd;
128
- font-family: 'Georgia', serif;
129
- font-size: 14px;
130
- padding: 15px;
131
-
132
- /* Custom setting */
133
- font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
134
- 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji',
135
- 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
136
- width: 100%;
137
- height: 100%;
138
- background: rgb(255, 255, 255);
139
- border-radius: 6px;
140
- padding: 0 1rem 1rem;
141
- `;
142
- const DraftEditorControls = _styledComponents.default.div`
143
- padding-top: 1rem;
144
- width: 100%;
145
- background: rgb(255, 255, 255);
146
- `;
147
- const DraftEditorControlsWrapper = _styledComponents.default.div`
148
- width: 100%;
149
- position: relative;
150
- display: flex;
151
- flex-direction: row;
152
- flex-wrap: wrap;
153
- padding-right: 45px;
154
- `;
155
- const TextEditorWrapper = _styledComponents.default.div`
156
- /* Rich-editor default setting (.RichEditor-editor)*/
157
- border-top: 1px solid #ddd;
158
- cursor: text;
159
- font-size: 16px;
160
- margin-top: 10px;
161
- `;
162
- const DraftEditorContainer = _styledComponents.default.div`
163
- overflow-x: hidden;
164
- position: relative;
165
- margin-top: 4px;
166
- ${props => props.isEnlarged ? (0, _styledComponents.css)`
167
- position: fixed;
168
- width: 100%;
169
- height: 100%;
170
- top: 0;
171
- left: 0;
172
- z-index: 30;
173
- padding-left: 3em;
174
- padding-right: 3em;
175
- background: rgba(0, 0, 0, 0.5);
176
- ` : ''}
177
- ${DraftEditorWrapper} {
178
- ${props => props.isEnlarged ? (0, _styledComponents.css)`
179
- width: 100%;
180
- height: 100%;
181
- padding: 0 1rem 0;
182
- overflow: scroll;
183
- ` : ''}
184
- }
185
- ${DraftEditorControls} {
186
- ${props => props.isEnlarged ? (0, _styledComponents.css)`
187
- position: sticky;
188
- top: 0;
189
- z-index: 12;
190
- ` : ''}
191
- }
192
- ${DraftEditorControlsWrapper} {
193
- ${props => props.isEnlarged ? (0, _styledComponents.css)`
194
- overflow: auto;
195
- padding-bottom: 0;
196
- ` : ''}
197
- }
198
- ${TextEditorWrapper} {
199
- ${props => props.isEnlarged ? (0, _styledComponents.css)`
200
- max-width: 100%;
201
- min-height: 100vh;
202
- padding-bottom: 0;
203
- ` : ''}
204
- }
205
- `;
206
- const EnlargeButtonWrapper = _styledComponents.default.div`
207
- position: absolute;
208
- top: 0;
209
- right: 0;
210
- margin: 0;
211
- `;
21
+ 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); }
22
+ const styleSource = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("link", {
23
+ href: "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css",
24
+ rel: "stylesheet",
25
+ type: "text/css"
26
+ }), /*#__PURE__*/_react.default.createElement("link", {
27
+ href: "https://storage.googleapis.com/static-readr-tw-dev/cdn/draft-js/rich-editor.css",
28
+ rel: "stylesheet",
29
+ type: "text/css"
30
+ }), /*#__PURE__*/_react.default.createElement("link", {
31
+ href: "https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css",
32
+ rel: "stylesheet",
33
+ type: "text/css"
34
+ }));
35
+ const decorator = exports.decorator = new _draftJs.CompositeDecorator([_draftRenderer.annotationDecorator, _draftRenderer.linkDecorator]);
212
36
  class RichTextEditor extends _react.default.Component {
213
37
  editorRef = null;
214
38
  constructor(props) {
@@ -217,6 +41,12 @@ class RichTextEditor extends _react.default.Component {
217
41
  isEnlarged: false,
218
42
  readOnly: false
219
43
  };
44
+ this.editorDecorator = new _draftJs.CompositeDecorator([_draftRenderer.annotationDecorator, _draftRenderer.linkDecorator, {
45
+ ..._anchor.editableAnchorDecorator,
46
+ props: {
47
+ ...this.customEditProps
48
+ }
49
+ }]);
220
50
  }
221
51
  onChange = editorState => {
222
52
  this.props.onChange(editorState);
@@ -243,7 +73,6 @@ class RichTextEditor extends _react.default.Component {
243
73
  mapKeyToEditorCommand = e => {
244
74
  if (e.keyCode === 9 /* TAB */) {
245
75
  const newEditorState = _draftJs.RichUtils.onTab(e, this.props.editorState, 4 /* maxDepth */);
246
-
247
76
  if (newEditorState !== this.props.editorState) {
248
77
  this.onChange(newEditorState);
249
78
  }
@@ -284,52 +113,54 @@ class RichTextEditor extends _react.default.Component {
284
113
  isEnlarged: !this.state.isEnlarged
285
114
  });
286
115
  };
116
+ commonEditProps = {
117
+ onEditStart: () => {
118
+ this.setState({
119
+ // If custom block renderer requires mouse interaction,
120
+ // [Draft.js document](https://draftjs.org/docs/advanced-topics-block-components#recommendations-and-other-notes)
121
+ // suggests that we should temporarily set Editor
122
+ // to readOnly={true} during the interaction.
123
+ // In readOnly={true} condition, the user does not
124
+ // trigger any selection changes within the editor
125
+ // while interacting with custom block.
126
+ // If we don't set readOnly={true},
127
+ // it will cause some subtle bugs in InfoBox button.
128
+ readOnly: true
129
+ });
130
+ },
131
+ onEditFinish: () => {
132
+ this.setState({
133
+ readOnly: false
134
+ });
135
+ }
136
+ };
137
+ customEditProps = {
138
+ onEditStart: this.commonEditProps.onEditStart,
139
+ onEditFinish: ({
140
+ entityKey,
141
+ entityData
142
+ } = {}) => {
143
+ if (entityKey && entityData) {
144
+ const oldContentState = this.props.editorState.getCurrentContent();
145
+ const newContentState = oldContentState.replaceEntityData(entityKey, entityData);
146
+ this.onChange(_draftJs.EditorState.set(this.props.editorState, {
147
+ currentContent: newContentState
148
+ }));
149
+ }
150
+ this.commonEditProps.onEditFinish();
151
+ }
152
+ };
287
153
  blockRendererFn = block => {
288
154
  const atomicBlockObj = (0, _blockRendererFn.atomicBlockRenderer)(block);
289
155
  if (atomicBlockObj) {
290
- const onEditStart = () => {
291
- this.setState({
292
- // If custom block renderer requires mouse interaction,
293
- // [Draft.js document](https://draftjs.org/docs/advanced-topics-block-components#recommendations-and-other-notes)
294
- // suggests that we should temporarily set Editor
295
- // to readOnly={true} during the interaction.
296
- // In readOnly={true} condition, the user does not
297
- // trigger any selection changes within the editor
298
- // while interacting with custom block.
299
- // If we don't set readOnly={true},
300
- // it will cause some subtle bugs in InfoBox button.
301
- readOnly: true
302
- });
303
- };
304
- const onEditFinish = ({
305
- entityKey,
306
- entityData
307
- } = {}) => {
308
- if (entityKey && entityData) {
309
- const oldContentState = this.props.editorState.getCurrentContent();
310
- const newContentState = oldContentState.replaceEntityData(entityKey, entityData);
311
- this.onChange(_draftJs.EditorState.set(this.props.editorState, {
312
- currentContent: newContentState
313
- }));
314
- }
315
-
316
- // Custom block interaction is finished.
317
- // Therefore, we set readOnly={false} to
318
- // make editor editable.
319
- this.setState({
320
- readOnly: false
321
- });
322
- };
323
-
324
156
  // `onEditStart` and `onEditFinish` will be passed
325
157
  // into custom block component.
326
158
  // We can get them via `props.blockProps.onEditStart`
327
159
  // and `props.blockProps.onEditFinish` in the custom block components.
328
160
  atomicBlockObj['props'] = {
329
- onEditStart,
330
- onEditFinish,
161
+ ...this.customEditProps,
331
162
  RichTextEditorComponent: RichTextEditor,
332
- decorator: _draftRenderer.decorator,
163
+ decorator,
333
164
  getMainEditorReadOnly: () => this.state.readOnly
334
165
  };
335
166
  }
@@ -343,149 +174,74 @@ class RichTextEditor extends _react.default.Component {
343
174
  editorState
344
175
  } = this.props;
345
176
  if (!(editorState instanceof _draftJs.EditorState)) {
346
- editorState = _draftJs.EditorState.createEmpty(_draftRenderer.decorator);
177
+ editorState = _draftJs.EditorState.createEmpty(this.editorDecorator);
178
+ } else {
179
+ editorState = _draftJs.EditorState.set(editorState, {
180
+ decorator: this.editorDecorator
181
+ });
347
182
  }
348
183
  const {
349
184
  isEnlarged,
350
185
  readOnly
351
186
  } = this.state;
352
187
  const entityType = this.getEntityType(editorState);
353
- return /*#__PURE__*/_react.default.createElement(DraftEditorContainer, {
188
+ const commonProps = {
189
+ editorState: editorState,
190
+ onChange: this.onChange,
191
+ readOnly: this.state.readOnly
192
+ };
193
+ return /*#__PURE__*/_react.default.createElement(_styled.DraftEditorContainer, {
354
194
  isEnlarged: isEnlarged
355
- }, /*#__PURE__*/_react.default.createElement(DraftEditorWrapper, null, /*#__PURE__*/_react.default.createElement("link", {
356
- href: "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css",
357
- rel: "stylesheet",
358
- type: "text/css"
359
- }), /*#__PURE__*/_react.default.createElement("link", {
360
- href: "https://storage.googleapis.com/static-readr-tw-dev/cdn/draft-js/rich-editor.css",
361
- rel: "stylesheet",
362
- type: "text/css"
363
- }), /*#__PURE__*/_react.default.createElement("link", {
364
- href: "https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css",
365
- rel: "stylesheet",
366
- type: "text/css"
367
- }), /*#__PURE__*/_react.default.createElement(DraftEditorControls, null, /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(BlockStyleControls, {
195
+ }, /*#__PURE__*/_react.default.createElement(_styled.DraftEditorWrapper, null, styleSource, /*#__PURE__*/_react.default.createElement(_styled.DraftEditorControls, null, /*#__PURE__*/_react.default.createElement(_styled.DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(_buttons.BlockStyleControls, {
368
196
  disabledButtons: disabledButtons,
369
197
  editorState: editorState,
370
198
  onToggle: this.toggleBlockType,
371
199
  readOnly: this.state.readOnly
372
- }), /*#__PURE__*/_react.default.createElement(InlineStyleControls, {
200
+ }), /*#__PURE__*/_react.default.createElement(_buttons.InlineStyleControls, {
373
201
  disabledButtons: disabledButtons,
374
202
  editorState: editorState,
375
203
  onToggle: this.toggleInlineStyle,
376
204
  readOnly: this.state.readOnly
377
- }), /*#__PURE__*/_react.default.createElement(EnlargeButtonWrapper, null, /*#__PURE__*/_react.default.createElement(CustomEnlargeButton, {
205
+ }), /*#__PURE__*/_react.default.createElement(_styled.EnlargeButtonWrapper, null, /*#__PURE__*/_react.default.createElement(_buttons.CustomEnlargeButton, {
378
206
  onToggle: this.toggleEnlarge,
379
207
  isEnlarged: isEnlarged
380
- })), /*#__PURE__*/_react.default.createElement(CustomLinkButton, {
208
+ })), /*#__PURE__*/_react.default.createElement(_buttons.CustomAnchorButton, _extends({
209
+ isDisabled: disabledButtons.includes(_btNames.default.anchor),
210
+ isActive: entityType === _draftRenderer.ANCHOR_ENTITY_TYPE
211
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomLinkButton, _extends({
381
212
  isDisabled: disabledButtons.includes(_btNames.default.link),
382
- isActive: entityType === 'LINK',
383
- editorState: editorState,
384
- onChange: this.onChange,
385
- readOnly: this.state.readOnly,
386
- onEditStart: () => {
387
- this.setState({
388
- readOnly: true
389
- });
390
- },
391
- onEditFinish: () => {
392
- this.setState({
393
- readOnly: false
394
- });
395
- }
396
- }), /*#__PURE__*/_react.default.createElement(CustomBackgroundColorButton, {
213
+ isActive: entityType === 'LINK'
214
+ }, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomBackgroundColorButton, _extends({
397
215
  isDisabled: disabledButtons.includes(_btNames.default.backgroundColor),
398
- isActive: editorState.getCurrentInlineStyle().find(styleName => typeof styleName === 'string' && styleName.startsWith(_bgColor.customStylePrefix)) !== undefined,
399
- editorState: editorState,
400
- onChange: this.onChange,
401
- readOnly: this.state.readOnly,
402
- onEditStart: () => {
403
- this.setState({
404
- readOnly: true
405
- });
406
- },
407
- onEditFinish: () => {
408
- this.setState({
409
- readOnly: false
410
- });
411
- }
412
- }), /*#__PURE__*/_react.default.createElement(CustomFontColorButton, {
216
+ isActive: editorState.getCurrentInlineStyle().find(styleName => typeof styleName === 'string' && styleName.startsWith(_bgColor.customStylePrefix)) !== undefined
217
+ }, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomFontColorButton, _extends({
413
218
  isDisabled: disabledButtons.includes(_btNames.default.fontColor),
414
- isActive: editorState.getCurrentInlineStyle().find(styleName => typeof styleName === 'string' && styleName.startsWith(_fontColor.customStylePrefix)) !== undefined,
415
- editorState: editorState,
416
- onChange: this.onChange,
417
- readOnly: this.state.readOnly,
418
- onEditStart: () => {
419
- this.setState({
420
- readOnly: true
421
- });
422
- },
423
- onEditFinish: () => {
424
- this.setState({
425
- readOnly: false
426
- });
427
- }
428
- }), /*#__PURE__*/_react.default.createElement(CustomBlockquoteButton, {
429
- isDisabled: disabledButtons.includes(_btNames.default.blockquote),
430
- editorState: editorState,
431
- onChange: this.onChange,
432
- readOnly: this.state.readOnly
433
- }), /*#__PURE__*/_react.default.createElement(CustomAnnotationButton, {
219
+ isActive: editorState.getCurrentInlineStyle().find(styleName => typeof styleName === 'string' && styleName.startsWith(_fontColor.customStylePrefix)) !== undefined
220
+ }, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomBlockquoteButton, _extends({
221
+ isDisabled: disabledButtons.includes(_btNames.default.blockquote)
222
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(CustomAnnotationButton, _extends({
434
223
  isDisabled: disabledButtons.includes(_btNames.default.annotation),
435
- isActive: entityType === 'ANNOTATION',
436
- editorState: editorState,
437
- onChange: editorState => {
438
- this.onChange(editorState);
439
- },
440
- readOnly: this.state.readOnly,
441
- onEditStart: () => {
442
- this.setState({
443
- readOnly: true
444
- });
445
- },
446
- onEditFinish: () => {
447
- this.setState({
448
- readOnly: false
449
- });
450
- }
451
- }), /*#__PURE__*/_react.default.createElement(CustomImageButton, {
224
+ isActive: entityType === 'ANNOTATION'
225
+ }, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomImageButton, _extends({
452
226
  isDisabled: disabledButtons.includes(_btNames.default.image),
453
- editorState: editorState,
454
- onChange: this.onChange,
455
- readOnly: this.state.readOnly,
456
227
  ImageSelector: _imageSelector.ImageSelector
457
- }), /*#__PURE__*/_react.default.createElement(CustomSlideshowButton, {
228
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomSlideshowButton, _extends({
458
229
  isDisabled: disabledButtons.includes(_btNames.default.slideshow),
459
- editorState: editorState,
460
- onChange: this.onChange,
461
- readOnly: this.state.readOnly,
462
230
  ImageSelector: _imageSelector.ImageSelector
463
- }), /*#__PURE__*/_react.default.createElement(CustomInfoBoxButton, {
464
- isDisabled: disabledButtons.includes(_btNames.default.infoBox),
465
- editorState: editorState,
466
- onChange: this.onChange,
467
- readOnly: this.state.readOnly
468
- }), /*#__PURE__*/_react.default.createElement(CustomEmbeddedCodeButton, {
469
- isDisabled: disabledButtons.includes(_btNames.default.embed),
470
- editorState: editorState,
471
- onChange: this.onChange,
472
- readOnly: this.state.readOnly
473
- }), /*#__PURE__*/_react.default.createElement(CustomNewsReadingButton, {
474
- isDisabled: disabledButtons.includes(_btNames.default.newsReading),
475
- editorState: editorState,
476
- onChange: this.onChange,
477
- readOnly: this.state.readOnly
478
- }), /*#__PURE__*/_react.default.createElement(CustomDividerButton, {
479
- isDisabled: disabledButtons.includes(_btNames.default.divider),
480
- editorState: editorState,
481
- onChange: this.onChange,
482
- readOnly: this.state.readOnly
483
- }))), /*#__PURE__*/_react.default.createElement(TextEditorWrapper, {
231
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(CustomInfoBoxButton, _extends({
232
+ isDisabled: disabledButtons.includes(_btNames.default.infoBox)
233
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomEmbeddedCodeButton, _extends({
234
+ isDisabled: disabledButtons.includes(_btNames.default.embed)
235
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomNewsReadingButton, _extends({
236
+ isDisabled: disabledButtons.includes(_btNames.default.newsReading)
237
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomDividerButton, _extends({
238
+ isDisabled: disabledButtons.includes(_btNames.default.divider)
239
+ }, commonProps)))), /*#__PURE__*/_react.default.createElement(_styled.TextEditorWrapper, {
484
240
  onClick: () => {
485
241
  if (this.editorRef) {
486
242
  var _this$editorRef;
487
243
  // eslint-disable-next-line prettier/prettier
488
- (_this$editorRef = this.editorRef) === null || _this$editorRef === void 0 ? void 0 : _this$editorRef.focus();
244
+ (_this$editorRef = this.editorRef) === null || _this$editorRef === void 0 || _this$editorRef.focus();
489
245
  }
490
246
  }
491
247
  }, /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
@@ -505,115 +261,17 @@ class RichTextEditor extends _react.default.Component {
505
261
  }
506
262
  }
507
263
  exports.RichTextEditor = RichTextEditor;
508
- class StyleButton extends _react.default.Component {
509
- onToggle = e => {
510
- e.preventDefault();
511
- this.props.onToggle(this.props.style);
512
- };
513
- render() {
514
- return /*#__PURE__*/_react.default.createElement(CustomButton, {
515
- isDisabled: this.props.isDisabled,
516
- isActive: this.props.active,
517
- onMouseDown: this.onToggle,
518
- readOnly: this.props.readOnly
519
- }, this.props.icon && /*#__PURE__*/_react.default.createElement("i", {
520
- className: this.props.icon
521
- }), /*#__PURE__*/_react.default.createElement("span", null, !this.props.icon ? this.props.label : ''));
522
- }
523
- }
524
- const blockStyles = [{
525
- label: 'H2',
526
- style: 'header-two',
527
- icon: ''
528
- }, {
529
- label: 'H3',
530
- style: 'header-three',
531
- icon: ''
532
- }, {
533
- label: 'H4',
534
- style: 'header-four',
535
- icon: ''
536
- }, {
537
- label: 'H5',
538
- style: 'header-five',
539
- icon: ''
540
- }, {
541
- label: 'UL',
542
- style: 'unordered-list-item',
543
- icon: 'fas fa-list-ul'
544
- }, {
545
- label: 'OL',
546
- style: 'ordered-list-item',
547
- icon: 'fas fa-list-ol'
548
- }, {
549
- label: 'Code Block',
550
- style: 'code-block',
551
- icon: 'fas fa-code'
552
- }];
553
- const BlockStyleControls = props => {
554
- const {
555
- editorState,
556
- disabledButtons
557
- } = props;
558
- const selection = editorState.getSelection();
559
- const blockType = editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
560
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, blockStyles.map(type => /*#__PURE__*/_react.default.createElement(StyleButton, {
561
- isDisabled: disabledButtons.includes(type.style),
562
- key: type.label,
563
- active: type.style === blockType,
564
- label: type.label,
565
- onToggle: props.onToggle,
566
- style: type.style,
567
- icon: type.icon,
568
- readOnly: props.readOnly
569
- })));
570
- };
571
- const inlineStyles = [{
572
- label: 'Bold',
573
- style: 'BOLD',
574
- icon: 'fas fa-bold'
575
- }, {
576
- label: 'Italic',
577
- style: 'ITALIC',
578
- icon: 'fas fa-italic'
579
- }, {
580
- label: 'Underline',
581
- style: 'UNDERLINE',
582
- icon: 'fas fa-underline'
583
- }, {
584
- label: 'Monospace',
585
- style: 'CODE',
586
- icon: 'fas fa-terminal'
587
- }];
588
- const InlineStyleControls = props => {
589
- const currentStyle = props.editorState.getCurrentInlineStyle();
590
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, inlineStyles.map(type => /*#__PURE__*/_react.default.createElement(StyleButton, {
591
- isDisabled: props.disabledButtons.includes(type.style.toLowerCase()),
592
- key: type.label,
593
- active: currentStyle.has(type.style),
594
- label: type.label,
595
- onToggle: props.onToggle,
596
- style: type.style,
597
- icon: type.icon,
598
- readOnly: props.readOnly
599
- })));
600
- };
601
264
  const AnnotationButton = (0, _annotation.createAnnotationButton)({
602
265
  InnerEditor: RichTextEditor,
603
- decorator: _draftRenderer.decorator
266
+ decorator
604
267
  });
605
- const CustomAnnotationButton = (0, _styledComponents.default)(AnnotationButton)`
606
- ${buttonStyle}
607
- `;
608
268
  const InfoBoxButton = (0, _infoBox.createInfoBoxButton)({
609
269
  InnerEditor: RichTextEditor,
610
- decorator: _draftRenderer.decorator
270
+ decorator
611
271
  });
612
- const CustomInfoBoxButton = (0, _styledComponents.default)(InfoBoxButton)`
613
- ${buttonStyle}
614
- `;
615
- var _default = {
272
+ const CustomAnnotationButton = (0, _buttons.withStyle)(AnnotationButton);
273
+ const CustomInfoBoxButton = (0, _buttons.withStyle)(InfoBoxButton);
274
+ var _default = exports.default = {
616
275
  RichTextEditor,
617
- decorator: _draftRenderer.decorator
618
- };
619
- exports.default = _default;
276
+ decorator
277
+ };