@kids-reporter/draft-editor 1.0.1 → 1.0.3

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,37 @@
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 = new _draftJs.CompositeDecorator([_draftRenderer.annotationDecorator, _draftRenderer.linkDecorator]);
36
+ exports.decorator = decorator;
212
37
  class RichTextEditor extends _react.default.Component {
213
38
  editorRef = null;
214
39
  constructor(props) {
@@ -217,6 +42,12 @@ class RichTextEditor extends _react.default.Component {
217
42
  isEnlarged: false,
218
43
  readOnly: false
219
44
  };
45
+ this.editorDecorator = new _draftJs.CompositeDecorator([_draftRenderer.annotationDecorator, _draftRenderer.linkDecorator, {
46
+ ..._anchor.editableAnchorDecorator,
47
+ props: {
48
+ ...this.customEditProps
49
+ }
50
+ }]);
220
51
  }
221
52
  onChange = editorState => {
222
53
  this.props.onChange(editorState);
@@ -284,52 +115,54 @@ class RichTextEditor extends _react.default.Component {
284
115
  isEnlarged: !this.state.isEnlarged
285
116
  });
286
117
  };
118
+ commonEditProps = {
119
+ onEditStart: () => {
120
+ this.setState({
121
+ // If custom block renderer requires mouse interaction,
122
+ // [Draft.js document](https://draftjs.org/docs/advanced-topics-block-components#recommendations-and-other-notes)
123
+ // suggests that we should temporarily set Editor
124
+ // to readOnly={true} during the interaction.
125
+ // In readOnly={true} condition, the user does not
126
+ // trigger any selection changes within the editor
127
+ // while interacting with custom block.
128
+ // If we don't set readOnly={true},
129
+ // it will cause some subtle bugs in InfoBox button.
130
+ readOnly: true
131
+ });
132
+ },
133
+ onEditFinish: () => {
134
+ this.setState({
135
+ readOnly: false
136
+ });
137
+ }
138
+ };
139
+ customEditProps = {
140
+ onEditStart: this.commonEditProps.onEditStart,
141
+ onEditFinish: ({
142
+ entityKey,
143
+ entityData
144
+ } = {}) => {
145
+ if (entityKey && entityData) {
146
+ const oldContentState = this.props.editorState.getCurrentContent();
147
+ const newContentState = oldContentState.replaceEntityData(entityKey, entityData);
148
+ this.onChange(_draftJs.EditorState.set(this.props.editorState, {
149
+ currentContent: newContentState
150
+ }));
151
+ }
152
+ this.commonEditProps.onEditFinish();
153
+ }
154
+ };
287
155
  blockRendererFn = block => {
288
156
  const atomicBlockObj = (0, _blockRendererFn.atomicBlockRenderer)(block);
289
157
  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
158
  // `onEditStart` and `onEditFinish` will be passed
325
159
  // into custom block component.
326
160
  // We can get them via `props.blockProps.onEditStart`
327
161
  // and `props.blockProps.onEditFinish` in the custom block components.
328
162
  atomicBlockObj['props'] = {
329
- onEditStart,
330
- onEditFinish,
163
+ ...this.customEditProps,
331
164
  RichTextEditorComponent: RichTextEditor,
332
- decorator: _draftRenderer.decorator,
165
+ decorator,
333
166
  getMainEditorReadOnly: () => this.state.readOnly
334
167
  };
335
168
  }
@@ -343,144 +176,69 @@ class RichTextEditor extends _react.default.Component {
343
176
  editorState
344
177
  } = this.props;
345
178
  if (!(editorState instanceof _draftJs.EditorState)) {
346
- editorState = _draftJs.EditorState.createEmpty(_draftRenderer.decorator);
179
+ editorState = _draftJs.EditorState.createEmpty(this.editorDecorator);
180
+ } else {
181
+ editorState = _draftJs.EditorState.set(editorState, {
182
+ decorator: this.editorDecorator
183
+ });
347
184
  }
348
185
  const {
349
186
  isEnlarged,
350
187
  readOnly
351
188
  } = this.state;
352
189
  const entityType = this.getEntityType(editorState);
353
- return /*#__PURE__*/_react.default.createElement(DraftEditorContainer, {
190
+ const commonProps = {
191
+ editorState: editorState,
192
+ onChange: this.onChange,
193
+ readOnly: this.state.readOnly
194
+ };
195
+ return /*#__PURE__*/_react.default.createElement(_styled.DraftEditorContainer, {
354
196
  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, {
197
+ }, /*#__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
198
  disabledButtons: disabledButtons,
369
199
  editorState: editorState,
370
200
  onToggle: this.toggleBlockType,
371
201
  readOnly: this.state.readOnly
372
- }), /*#__PURE__*/_react.default.createElement(InlineStyleControls, {
202
+ }), /*#__PURE__*/_react.default.createElement(_buttons.InlineStyleControls, {
373
203
  disabledButtons: disabledButtons,
374
204
  editorState: editorState,
375
205
  onToggle: this.toggleInlineStyle,
376
206
  readOnly: this.state.readOnly
377
- }), /*#__PURE__*/_react.default.createElement(EnlargeButtonWrapper, null, /*#__PURE__*/_react.default.createElement(CustomEnlargeButton, {
207
+ }), /*#__PURE__*/_react.default.createElement(_styled.EnlargeButtonWrapper, null, /*#__PURE__*/_react.default.createElement(_buttons.CustomEnlargeButton, {
378
208
  onToggle: this.toggleEnlarge,
379
209
  isEnlarged: isEnlarged
380
- })), /*#__PURE__*/_react.default.createElement(CustomLinkButton, {
210
+ })), /*#__PURE__*/_react.default.createElement(_buttons.CustomAnchorButton, _extends({
211
+ isDisabled: disabledButtons.includes(_btNames.default.anchor),
212
+ isActive: entityType === _draftRenderer.ANCHOR_ENTITY_TYPE
213
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomLinkButton, _extends({
381
214
  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, {
215
+ isActive: entityType === 'LINK'
216
+ }, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomBackgroundColorButton, _extends({
397
217
  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, {
218
+ isActive: editorState.getCurrentInlineStyle().find(styleName => typeof styleName === 'string' && styleName.startsWith(_bgColor.customStylePrefix)) !== undefined
219
+ }, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomFontColorButton, _extends({
413
220
  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, {
221
+ isActive: editorState.getCurrentInlineStyle().find(styleName => typeof styleName === 'string' && styleName.startsWith(_fontColor.customStylePrefix)) !== undefined
222
+ }, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomBlockquoteButton, _extends({
223
+ isDisabled: disabledButtons.includes(_btNames.default.blockquote)
224
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(CustomAnnotationButton, _extends({
434
225
  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, {
226
+ isActive: entityType === 'ANNOTATION'
227
+ }, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomImageButton, _extends({
452
228
  isDisabled: disabledButtons.includes(_btNames.default.image),
453
- editorState: editorState,
454
- onChange: this.onChange,
455
- readOnly: this.state.readOnly,
456
229
  ImageSelector: _imageSelector.ImageSelector
457
- }), /*#__PURE__*/_react.default.createElement(CustomSlideshowButton, {
230
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomSlideshowButton, _extends({
458
231
  isDisabled: disabledButtons.includes(_btNames.default.slideshow),
459
- editorState: editorState,
460
- onChange: this.onChange,
461
- readOnly: this.state.readOnly,
462
232
  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, {
233
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(CustomInfoBoxButton, _extends({
234
+ isDisabled: disabledButtons.includes(_btNames.default.infoBox)
235
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomEmbeddedCodeButton, _extends({
236
+ isDisabled: disabledButtons.includes(_btNames.default.embed)
237
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomNewsReadingButton, _extends({
238
+ isDisabled: disabledButtons.includes(_btNames.default.newsReading)
239
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomDividerButton, _extends({
240
+ isDisabled: disabledButtons.includes(_btNames.default.divider)
241
+ }, commonProps)))), /*#__PURE__*/_react.default.createElement(_styled.TextEditorWrapper, {
484
242
  onClick: () => {
485
243
  if (this.editorRef) {
486
244
  var _this$editorRef;
@@ -505,115 +263,18 @@ class RichTextEditor extends _react.default.Component {
505
263
  }
506
264
  }
507
265
  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
266
  const AnnotationButton = (0, _annotation.createAnnotationButton)({
602
267
  InnerEditor: RichTextEditor,
603
- decorator: _draftRenderer.decorator
268
+ decorator
604
269
  });
605
- const CustomAnnotationButton = (0, _styledComponents.default)(AnnotationButton)`
606
- ${buttonStyle}
607
- `;
608
270
  const InfoBoxButton = (0, _infoBox.createInfoBoxButton)({
609
271
  InnerEditor: RichTextEditor,
610
- decorator: _draftRenderer.decorator
272
+ decorator
611
273
  });
612
- const CustomInfoBoxButton = (0, _styledComponents.default)(InfoBoxButton)`
613
- ${buttonStyle}
614
- `;
274
+ const CustomAnnotationButton = (0, _buttons.withStyle)(AnnotationButton);
275
+ const CustomInfoBoxButton = (0, _buttons.withStyle)(InfoBoxButton);
615
276
  var _default = {
616
277
  RichTextEditor,
617
- decorator: _draftRenderer.decorator
278
+ decorator
618
279
  };
619
280
  exports.default = _default;