@kids-reporter/draft-editor 1.0.6 → 1.0.7

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.
@@ -32,9 +32,7 @@ function EditableInfoBox(props) {
32
32
  } = props;
33
33
  const {
34
34
  onEditStart,
35
- onEditFinish,
36
- RichTextEditorComponent: Editor,
37
- decorator
35
+ onEditFinish
38
36
  } = blockProps;
39
37
  const entityKey = block.getEntityAt(0);
40
38
  const entity = contentState.getEntity(entityKey);
@@ -54,9 +52,7 @@ function EditableInfoBox(props) {
54
52
  onEditFinish();
55
53
  },
56
54
  onConfirm: onInputChange,
57
- inputValue: data,
58
- Editor: Editor,
59
- decorator: decorator
55
+ inputValue: data
60
56
  }), /*#__PURE__*/_react.default.createElement(EditableBlock, {
61
57
  component: /*#__PURE__*/_react.default.createElement(StyledInfoBox, {
62
58
  data: data
@@ -3,95 +3,61 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createAnnotationButton = createAnnotationButton;
6
+ exports.AnnotationButton = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
- var _btNames = _interopRequireDefault(require("./bt-names"));
9
8
  var _draftJs = require("draft-js");
10
- var _modals = require("@keystone-ui/modals");
11
9
  var _draftRenderer = require("@kids-reporter/draft-renderer");
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ var _annotation = require("../entity-decorators/annotation");
13
11
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
12
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
- const disabledButtons = [_btNames.default.h2, _btNames.default.h3, _btNames.default.code, _btNames.default.codeBlock, _btNames.default.blockquote, _btNames.default.annotation, _btNames.default.embed, _btNames.default.image, _btNames.default.infoBox, _btNames.default.slideshow, _btNames.default.newsReading, _btNames.default.tocAnchor, _btNames.default.anchor];
16
- function createAnnotationButton({
17
- InnerEditor,
18
- decorator
19
- }) {
20
- return function AnnotationButton(props) {
21
- const toggleEntity = _draftJs.RichUtils.toggleLink;
22
- const {
23
- isActive,
24
- editorState: editorStateOfOuterEditor,
25
- onChange
26
- } = props;
27
- const [toShowInput, setToShowInput] = (0, _react.useState)(false);
28
- const [inputValue, setInputValue] = (0, _react.useState)({
29
- editorStateOfInnerEditor: _draftJs.EditorState.createEmpty(decorator)
13
+ const AnnotationButton = props => {
14
+ const toggleEntity = _draftJs.RichUtils.toggleLink;
15
+ const {
16
+ isActive,
17
+ editorState: editorStateOfOuterEditor,
18
+ onChange
19
+ } = props;
20
+ const [toShowInput, setToShowInput] = (0, _react.useState)(false);
21
+ const promptForAnnotation = e => {
22
+ e.preventDefault();
23
+ const selection = editorStateOfOuterEditor.getSelection();
24
+ if (!selection.isCollapsed()) {
25
+ props.onEditStart();
26
+ setToShowInput(true);
27
+ }
28
+ };
29
+ const confirmAnnotation = editorState => {
30
+ const contentState = editorStateOfOuterEditor.getCurrentContent();
31
+ const rawContentState = (0, _draftJs.convertToRaw)(editorState.getCurrentContent());
32
+ const contentStateWithEntity = contentState.createEntity(_draftRenderer.ENTITY.Annotation, 'MUTABLE', {
33
+ rawContentState
34
+ });
35
+ const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
36
+ const newEditorState = _draftJs.EditorState.set(editorStateOfOuterEditor, {
37
+ currentContent: contentStateWithEntity
30
38
  });
31
- const promptForAnnotation = e => {
32
- e.preventDefault();
33
- const selection = editorStateOfOuterEditor.getSelection();
34
- if (!selection.isCollapsed()) {
35
- props.onEditStart();
36
- setToShowInput(true);
37
- }
38
- };
39
- const confirmAnnotation = () => {
40
- const contentState = editorStateOfOuterEditor.getCurrentContent();
41
- const rawContentState = (0, _draftJs.convertToRaw)(inputValue.editorStateOfInnerEditor.getCurrentContent());
42
- const contentStateWithEntity = contentState.createEntity(_draftRenderer.ENTITY.Annotation, 'MUTABLE', {
43
- rawContentState
44
- });
45
- const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
46
- const newEditorState = _draftJs.EditorState.set(editorStateOfOuterEditor, {
47
- currentContent: contentStateWithEntity
48
- });
49
- onChange(toggleEntity(newEditorState, newEditorState.getSelection(), entityKey));
50
- setToShowInput(false);
51
- setInputValue({
52
- editorStateOfInnerEditor: _draftJs.EditorState.createEmpty(decorator)
53
- });
54
- props.onEditFinish();
55
- };
56
- const removeAnnotation = () => {
57
- const selection = editorStateOfOuterEditor.getSelection();
58
- if (!selection.isCollapsed()) {
59
- onChange(toggleEntity(editorStateOfOuterEditor, selection, null));
60
- }
61
- setToShowInput(false);
62
- setInputValue({
63
- editorStateOfInnerEditor: _draftJs.EditorState.createEmpty(decorator)
64
- });
65
- props.onEditFinish();
66
- };
67
- const input = /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
68
- isOpen: toShowInput
69
- }, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
70
- title: "\u8A3B\u89E3",
71
- actions: {
72
- cancel: {
73
- label: 'Cancel',
74
- action: removeAnnotation
75
- },
76
- confirm: {
77
- label: 'Confirm',
78
- action: confirmAnnotation
79
- }
80
- }
81
- }, /*#__PURE__*/_react.default.createElement(InnerEditor, {
82
- disabledButtons: disabledButtons,
83
- editorState: inputValue.editorStateOfInnerEditor,
84
- onChange: editorState => {
85
- setInputValue({
86
- editorStateOfInnerEditor: editorState
87
- });
88
- }
89
- })));
90
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, input, /*#__PURE__*/_react.default.createElement("div", {
91
- className: props.className,
92
- onMouseDown: isActive ? removeAnnotation : promptForAnnotation
93
- }, /*#__PURE__*/_react.default.createElement("i", {
94
- className: "far"
95
- }), /*#__PURE__*/_react.default.createElement("span", null, "Annotation")));
39
+ onChange(toggleEntity(newEditorState, newEditorState.getSelection(), entityKey));
40
+ setToShowInput(false);
41
+ props.onEditFinish();
42
+ };
43
+ const removeAnnotation = () => {
44
+ const selection = editorStateOfOuterEditor.getSelection();
45
+ if (!selection.isCollapsed()) {
46
+ onChange(toggleEntity(editorStateOfOuterEditor, selection, null));
47
+ }
48
+ setToShowInput(false);
49
+ props.onEditFinish();
96
50
  };
97
- }
51
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, toShowInput && /*#__PURE__*/_react.default.createElement(_annotation.AnnotationEditor, {
52
+ isOpen: toShowInput,
53
+ editorStateValue: _draftJs.EditorState.createEmpty(),
54
+ onConfirm: confirmAnnotation,
55
+ onCancel: removeAnnotation
56
+ }), /*#__PURE__*/_react.default.createElement("div", {
57
+ className: props.className,
58
+ onMouseDown: isActive ? removeAnnotation : promptForAnnotation
59
+ }, /*#__PURE__*/_react.default.createElement("i", {
60
+ className: "far"
61
+ }), /*#__PURE__*/_react.default.createElement("span", null, "Annotation")));
62
+ };
63
+ exports.AnnotationButton = AnnotationButton;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.withStyle = exports.InlineStyleControls = exports.CustomTOCAnchorButton = exports.CustomSlideshowButton = exports.CustomNewsReadingButton = exports.CustomLinkButton = exports.CustomImageButton = exports.CustomFontColorButton = exports.CustomEnlargeButton = exports.CustomEmbeddedCodeButton = exports.CustomDividerButton = exports.CustomBlockquoteButton = exports.CustomBackgroundColorButton = exports.CustomAnchorButton = exports.BlockStyleControls = void 0;
6
+ exports.withStyle = exports.InlineStyleControls = exports.CustomTOCAnchorButton = exports.CustomSlideshowButton = exports.CustomNewsReadingButton = exports.CustomLinkButton = exports.CustomInfoBoxButton = exports.CustomImageButton = exports.CustomFontColorButton = exports.CustomEnlargeButton = exports.CustomEmbeddedCodeButton = exports.CustomDividerButton = exports.CustomBlockquoteButton = exports.CustomBackgroundColorButton = exports.CustomAnnotationButton = exports.CustomAnchorButton = exports.BlockStyleControls = void 0;
7
7
  var _styledComponents = _interopRequireDefault(require("styled-components"));
8
8
  var _controlButtons = require("./control-buttons");
9
9
  var _bgColor = require("./bg-color");
@@ -16,8 +16,10 @@ var _image = require("./image");
16
16
  var _tocAnchor = require("./toc-anchor");
17
17
  var _anchor = require("./anchor");
18
18
  var _link = require("./link");
19
+ var _annotation = require("./annotation");
19
20
  var _slideshow = require("./slideshow");
20
21
  var _newsReading = require("./news-reading");
22
+ var _infoBox = require("./info-box");
21
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
24
  const withStyle = Button => {
23
25
  return (0, _styledComponents.default)(Button)`
@@ -31,6 +33,7 @@ const CustomBlockquoteButton = exports.CustomBlockquoteButton = withStyle(_block
31
33
  const CustomTOCAnchorButton = exports.CustomTOCAnchorButton = withStyle(_tocAnchor.TOCAnchorButton);
32
34
  const CustomAnchorButton = exports.CustomAnchorButton = withStyle(_anchor.AnchorButton);
33
35
  const CustomLinkButton = exports.CustomLinkButton = withStyle(_link.LinkButton);
36
+ const CustomAnnotationButton = exports.CustomAnnotationButton = withStyle(_annotation.AnnotationButton);
34
37
  const CustomEnlargeButton = exports.CustomEnlargeButton = (0, _styledComponents.default)(withStyle(_enlarge.EnlargeButton))`
35
38
  color: #999;
36
39
  `;
@@ -40,4 +43,5 @@ const CustomEmbeddedCodeButton = exports.CustomEmbeddedCodeButton = withStyle(_e
40
43
  const CustomNewsReadingButton = exports.CustomNewsReadingButton = withStyle(_newsReading.NewsReadingButton);
41
44
  const CustomBackgroundColorButton = exports.CustomBackgroundColorButton = withStyle(_bgColor.BackgroundColorButton);
42
45
  const CustomFontColorButton = exports.CustomFontColorButton = withStyle(_fontColor.FontColorButton);
43
- const CustomDividerButton = exports.CustomDividerButton = withStyle(_divider.DividerButton);
46
+ const CustomDividerButton = exports.CustomDividerButton = withStyle(_divider.DividerButton);
47
+ const CustomInfoBoxButton = exports.CustomInfoBoxButton = withStyle(_infoBox.InfoBoxButton);
@@ -3,13 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.InfoBoxButton = void 0;
6
7
  exports.InfoBoxInput = InfoBoxInput;
7
- exports.createInfoBoxButton = createInfoBoxButton;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _btNames = _interopRequireDefault(require("./bt-names"));
10
10
  var _draftJs = require("draft-js");
11
11
  var _modals = require("@keystone-ui/modals");
12
+ var _richTextEditor = require("../rich-text-editor");
12
13
  var _select = require("./form/select");
14
+ var _annotation = require("../entity-decorators/annotation");
15
+ var _link = require("../entity-decorators/link");
13
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
17
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
18
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -31,14 +34,12 @@ function InfoBoxInput(props) {
31
34
  isOpen,
32
35
  onConfirm,
33
36
  onCancel,
34
- Editor,
35
- decorator,
36
37
  inputValue
37
38
  } = props;
38
39
  const contentState = (0, _draftJs.convertFromRaw)(inputValue.rawContentState);
39
40
  const [inputValueState, setInputValueState] = (0, _react.useState)({
40
41
  type: inputValue.type,
41
- editorState: _draftJs.EditorState.createWithContent(contentState, decorator)
42
+ editorState: _draftJs.EditorState.createWithContent(contentState)
42
43
  });
43
44
  return /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
44
45
  isOpen: isOpen
@@ -80,7 +81,8 @@ function InfoBoxInput(props) {
80
81
  editorState: inputValueState.editorState
81
82
  });
82
83
  }
83
- }), /*#__PURE__*/_react.default.createElement(Editor, {
84
+ }), /*#__PURE__*/_react.default.createElement(_richTextEditor.RichTextEditor, {
85
+ decorators: [_annotation.editableAnnotationDecorator, _link.editableLinkDecorator],
84
86
  disabledButtons: disabledButtons,
85
87
  editorState: inputValueState.editorState,
86
88
  onChange: editorState => {
@@ -91,60 +93,54 @@ function InfoBoxInput(props) {
91
93
  }
92
94
  })));
93
95
  }
94
- function createInfoBoxButton({
95
- InnerEditor,
96
- decorator
97
- }) {
98
- return function InfoBoxButton(props) {
99
- const [toShowInput, setToShowInput] = (0, _react.useState)(false);
100
- const {
101
- className,
102
- editorState,
103
- onChange: onEditorStateChange
104
- } = props;
105
- const onChange = ({
96
+ const InfoBoxButton = props => {
97
+ const [toShowInput, setToShowInput] = (0, _react.useState)(false);
98
+ const {
99
+ className,
100
+ editorState,
101
+ onChange: onEditorStateChange
102
+ } = props;
103
+ const onChange = ({
104
+ type,
105
+ rawContentState
106
+ }) => {
107
+ const contentState = editorState.getCurrentContent();
108
+
109
+ // create an InfoBox entity
110
+ const contentStateWithEntity = contentState.createEntity('INFOBOX', 'IMMUTABLE', {
106
111
  type,
107
112
  rawContentState
108
- }) => {
109
- const contentState = editorState.getCurrentContent();
113
+ });
114
+ const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
115
+ const newEditorState = _draftJs.EditorState.set(editorState, {
116
+ currentContent: contentStateWithEntity
117
+ });
110
118
 
111
- // create an InfoBox entity
112
- const contentStateWithEntity = contentState.createEntity('INFOBOX', 'IMMUTABLE', {
113
- type,
114
- rawContentState
115
- });
116
- const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
117
- const newEditorState = _draftJs.EditorState.set(editorState, {
118
- currentContent: contentStateWithEntity
119
- });
120
-
121
- //The third parameter here is a space string, not an empty string
122
- //If you set an empty string, you will get an error: Unknown DraftEntity key: null
123
- onEditorStateChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
119
+ //The third parameter here is a space string, not an empty string
120
+ //If you set an empty string, you will get an error: Unknown DraftEntity key: null
121
+ onEditorStateChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
122
+ setToShowInput(false);
123
+ };
124
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, toShowInput && /*#__PURE__*/_react.default.createElement(InfoBoxInput, {
125
+ onConfirm: onChange,
126
+ onCancel: () => {
124
127
  setToShowInput(false);
125
- };
126
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, toShowInput && /*#__PURE__*/_react.default.createElement(InfoBoxInput, {
127
- Editor: InnerEditor,
128
- decorator: decorator,
129
- onConfirm: onChange,
130
- onCancel: () => {
131
- setToShowInput(false);
132
- },
133
- isOpen: toShowInput,
134
- inputValue: {
135
- type: InfoBoxTypeEnum.newsChargeStation,
136
- rawContentState: {
137
- blocks: [],
138
- entityMap: {}
139
- }
140
- }
141
- }), /*#__PURE__*/_react.default.createElement("div", {
142
- className: className,
143
- onClick: () => {
144
- setToShowInput(true);
128
+ },
129
+ isOpen: toShowInput,
130
+ inputValue: {
131
+ type: InfoBoxTypeEnum.newsChargeStation,
132
+ rawContentState: {
133
+ blocks: [],
134
+ entityMap: {}
145
135
  }
146
- }, /*#__PURE__*/_react.default.createElement("i", {
147
- className: "far"
148
- }), /*#__PURE__*/_react.default.createElement("span", null, "InfoBox")));
149
- };
150
- }
136
+ }
137
+ }), /*#__PURE__*/_react.default.createElement("div", {
138
+ className: className,
139
+ onClick: () => {
140
+ setToShowInput(true);
141
+ }
142
+ }, /*#__PURE__*/_react.default.createElement("i", {
143
+ className: "far"
144
+ }), /*#__PURE__*/_react.default.createElement("span", null, "InfoBox")));
145
+ };
146
+ exports.InfoBoxButton = InfoBoxButton;
@@ -5,19 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.LinkButton = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
- var _modals = require("@keystone-ui/modals");
9
8
  var _draftJs = require("draft-js");
10
- var _fields = require("@keystone-ui/fields");
11
9
  var _draftRenderer = require("@kids-reporter/draft-renderer");
10
+ var _link = require("../entity-decorators/link");
12
11
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
12
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
- const styles = {
15
- urlInput: {
16
- fontFamily: "'Georgia', serif",
17
- marginRight: 10,
18
- padding: 10
19
- }
20
- };
21
13
  const LinkButton = props => {
22
14
  const {
23
15
  isActive,
@@ -25,7 +17,6 @@ const LinkButton = props => {
25
17
  onChange
26
18
  } = props;
27
19
  const [toShowUrlInput, setToShowUrlInput] = (0, _react.useState)(false);
28
- const [urlValue, setUrlValue] = (0, _react.useState)('');
29
20
  const promptForLink = e => {
30
21
  e.preventDefault();
31
22
  const selection = editorState.getSelection();
@@ -34,7 +25,7 @@ const LinkButton = props => {
34
25
  setToShowUrlInput(true);
35
26
  }
36
27
  };
37
- const confirmLink = () => {
28
+ const confirmLink = urlValue => {
38
29
  const contentState = editorState.getCurrentContent();
39
30
  const contentStateWithEntity = contentState.createEntity(_draftRenderer.ENTITY.Link, 'MUTABLE', {
40
31
  url: urlValue
@@ -45,45 +36,22 @@ const LinkButton = props => {
45
36
  });
46
37
  onChange(_draftJs.RichUtils.toggleLink(newEditorState, newEditorState.getSelection(), entityKey));
47
38
  setToShowUrlInput(false);
48
- setUrlValue('');
49
39
  props.onEditFinish();
50
40
  };
51
- const onLinkInputKeyDown = e => {
52
- if (e.which === 13) {
53
- e.preventDefault();
54
- confirmLink();
55
- }
56
- };
57
41
  const removeLink = () => {
58
42
  const selection = editorState.getSelection();
59
43
  if (!selection.isCollapsed()) {
60
44
  onChange(_draftJs.RichUtils.toggleLink(editorState, selection, null));
61
45
  }
62
46
  setToShowUrlInput(false);
63
- setUrlValue('');
64
47
  props.onEditFinish();
65
48
  };
66
- const urlInput = /*#__PURE__*/_react.default.createElement(_modals.AlertDialog, {
67
- title: "\u7DE8\u8F2F\u5916\u90E8\u9023\u7D50\u6216\u5167\u90E8\u9328\u9EDE(ID)",
49
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, toShowUrlInput && /*#__PURE__*/_react.default.createElement(_link.LinkEditor, {
68
50
  isOpen: toShowUrlInput,
69
- actions: {
70
- cancel: {
71
- label: 'Cancel',
72
- action: removeLink
73
- },
74
- confirm: {
75
- label: 'Confirm',
76
- action: confirmLink
77
- }
78
- }
79
- }, /*#__PURE__*/_react.default.createElement("p", null, /*#__PURE__*/_react.default.createElement("br", null), "\u5916\u90E8\u9023\u7D50\u7BC4\u4F8B:", /*#__PURE__*/_react.default.createElement("br", null), "https://kids.twreporter.org/article/article1#part1", /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), "\u5167\u90E8\u9328\u9EDE\u7BC4\u4F8B:", /*#__PURE__*/_react.default.createElement("br", null), "#part1"), /*#__PURE__*/_react.default.createElement(_fields.TextInput, {
80
- onChange: e => setUrlValue(e.target.value),
81
- style: styles.urlInput,
82
- type: "text",
83
- value: urlValue,
84
- onKeyDown: onLinkInputKeyDown
85
- }));
86
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, urlInput, /*#__PURE__*/_react.default.createElement("div", {
51
+ urlValue: '',
52
+ onConfirm: confirmLink,
53
+ onCancel: removeLink
54
+ }), /*#__PURE__*/_react.default.createElement("div", {
87
55
  className: props.className,
88
56
  onMouseDown: isActive ? removeLink : promptForLink
89
57
  }, /*#__PURE__*/_react.default.createElement("i", {
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.editableAnnotationDecorator = exports.AnnotationEditor = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _draftJs = require("draft-js");
9
+ var _modals = require("@keystone-ui/modals");
10
+ var _draftRenderer = require("@kids-reporter/draft-renderer");
11
+ var _btNames = _interopRequireDefault(require("../buttons/bt-names"));
12
+ var _richTextEditor = require("../rich-text-editor");
13
+ var _wrapper = require("./wrapper");
14
+ var _link = require("./link");
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
+ const disabledButtons = [_btNames.default.h2, _btNames.default.h3, _btNames.default.code, _btNames.default.codeBlock, _btNames.default.blockquote, _btNames.default.annotation, _btNames.default.embed, _btNames.default.image, _btNames.default.infoBox, _btNames.default.slideshow, _btNames.default.newsReading, _btNames.default.tocAnchor, _btNames.default.anchor];
19
+ const AnnotationEditor = props => {
20
+ const {
21
+ isOpen,
22
+ editorStateValue,
23
+ onConfirm,
24
+ onCancel
25
+ } = props;
26
+ const [editorState, setEditorState] = (0, _react.useState)({
27
+ value: editorStateValue
28
+ });
29
+ return /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
30
+ isOpen: isOpen
31
+ }, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
32
+ title: "\u8A3B\u89E3",
33
+ actions: {
34
+ cancel: {
35
+ label: 'Cancel',
36
+ action: () => onCancel()
37
+ },
38
+ confirm: {
39
+ label: 'Confirm',
40
+ action: () => onConfirm(editorState.value)
41
+ }
42
+ }
43
+ }, /*#__PURE__*/_react.default.createElement(_richTextEditor.RichTextEditor, {
44
+ decorators: [_link.editableLinkDecorator],
45
+ disabledButtons: disabledButtons,
46
+ editorState: editorState.value,
47
+ onChange: editorState => {
48
+ setEditorState({
49
+ value: editorState
50
+ });
51
+ }
52
+ })));
53
+ };
54
+ exports.AnnotationEditor = AnnotationEditor;
55
+ const EditableAnnotation = props => {
56
+ var _contentState$getEnti;
57
+ const {
58
+ children,
59
+ contentState,
60
+ entityKey
61
+ } = props;
62
+ const [isModalOpen, setIsModalOpen] = (0, _react.useState)(false);
63
+ const [editorState, setEditorState] = (0, _react.useState)({
64
+ value: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(contentState === null || contentState === void 0 || (_contentState$getEnti = contentState.getEntity(entityKey).getData()) === null || _contentState$getEnti === void 0 ? void 0 : _contentState$getEnti.rawContentState))
65
+ });
66
+ (0, _react.useEffect)(() => {
67
+ var _contentState$getEnti2;
68
+ setEditorState({
69
+ value: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(contentState === null || contentState === void 0 || (_contentState$getEnti2 = contentState.getEntity(entityKey).getData()) === null || _contentState$getEnti2 === void 0 ? void 0 : _contentState$getEnti2.rawContentState))
70
+ });
71
+ }, [contentState, entityKey]);
72
+ const onEditorStateChange = editorState => {
73
+ setIsModalOpen(false);
74
+ setEditorState({
75
+ value: editorState
76
+ });
77
+ props.onEditFinish({
78
+ entityKey,
79
+ entityData: {
80
+ rawContentState: editorState ? (0, _draftJs.convertToRaw)(editorState.getCurrentContent()) : undefined
81
+ }
82
+ });
83
+ };
84
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isModalOpen && /*#__PURE__*/_react.default.createElement(AnnotationEditor, {
85
+ isOpen: isModalOpen,
86
+ editorStateValue: editorState.value,
87
+ onConfirm: onEditorStateChange,
88
+ onCancel: () => {
89
+ setIsModalOpen(false);
90
+ props.onEditFinish();
91
+ }
92
+ }), /*#__PURE__*/_react.default.createElement(_wrapper.EditableWrapper, {
93
+ component: /*#__PURE__*/_react.default.createElement(_draftRenderer.annotationDecorator.component, {
94
+ children,
95
+ contentState,
96
+ entityKey
97
+ }),
98
+ onClick: e => {
99
+ e.preventDefault();
100
+ setIsModalOpen(true);
101
+ props.onEditStart();
102
+ }
103
+ }));
104
+ };
105
+ const editableAnnotationDecorator = exports.editableAnnotationDecorator = {
106
+ strategy: _draftRenderer.annotationDecorator.strategy,
107
+ component: EditableAnnotation
108
+ };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.editableLinkDecorator = exports.LinkEditor = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _modals = require("@keystone-ui/modals");
9
+ var _fields = require("@keystone-ui/fields");
10
+ var _draftRenderer = require("@kids-reporter/draft-renderer");
11
+ var _wrapper = require("./wrapper");
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ const LinkEditor = props => {
15
+ const {
16
+ isOpen,
17
+ urlValue,
18
+ onConfirm,
19
+ onCancel
20
+ } = props;
21
+ const [url, setURL] = (0, _react.useState)(urlValue);
22
+ return /*#__PURE__*/_react.default.createElement(_modals.AlertDialog, {
23
+ title: "\u7DE8\u8F2F\u5916\u90E8\u9023\u7D50\u6216\u5167\u90E8\u9328\u9EDE(ID)",
24
+ isOpen: isOpen,
25
+ actions: {
26
+ cancel: {
27
+ label: 'Cancel',
28
+ action: () => onCancel()
29
+ },
30
+ confirm: {
31
+ label: 'Confirm',
32
+ action: () => onConfirm(url)
33
+ }
34
+ }
35
+ }, /*#__PURE__*/_react.default.createElement("p", null, /*#__PURE__*/_react.default.createElement("br", null), "\u5916\u90E8\u9023\u7D50\u7BC4\u4F8B:", /*#__PURE__*/_react.default.createElement("br", null), "https://kids.twreporter.org/article/article1#part1", /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), "\u5167\u90E8\u9328\u9EDE\u7BC4\u4F8B:", /*#__PURE__*/_react.default.createElement("br", null), "#part1"), /*#__PURE__*/_react.default.createElement(_fields.TextInput, {
36
+ placeholder: "\u9023\u7D50",
37
+ type: "text",
38
+ value: url,
39
+ onChange: e => setURL(e.target.value)
40
+ }));
41
+ };
42
+ exports.LinkEditor = LinkEditor;
43
+ const EditableLink = props => {
44
+ var _contentState$getEnti;
45
+ const {
46
+ children,
47
+ contentState,
48
+ entityKey
49
+ } = props;
50
+ const [isModalOpen, setIsModalOpen] = (0, _react.useState)(false);
51
+ const [url, setURL] = (0, _react.useState)(contentState === null || contentState === void 0 || (_contentState$getEnti = contentState.getEntity(entityKey)) === null || _contentState$getEnti === void 0 || (_contentState$getEnti = _contentState$getEnti.getData()) === null || _contentState$getEnti === void 0 ? void 0 : _contentState$getEnti.url);
52
+ (0, _react.useEffect)(() => {
53
+ var _contentState$getEnti2;
54
+ setURL(contentState === null || contentState === void 0 || (_contentState$getEnti2 = contentState.getEntity(entityKey).getData()) === null || _contentState$getEnti2 === void 0 ? void 0 : _contentState$getEnti2.url);
55
+ });
56
+ const onURLChange = url => {
57
+ setIsModalOpen(false);
58
+ setURL(url);
59
+ props.onEditFinish({
60
+ entityKey,
61
+ entityData: {
62
+ url: url
63
+ }
64
+ });
65
+ };
66
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isModalOpen && /*#__PURE__*/_react.default.createElement(LinkEditor, {
67
+ isOpen: isModalOpen,
68
+ urlValue: url,
69
+ onConfirm: onURLChange,
70
+ onCancel: () => {
71
+ setIsModalOpen(false);
72
+ props.onEditFinish();
73
+ }
74
+ }), /*#__PURE__*/_react.default.createElement(_wrapper.EditableWrapper, {
75
+ component: /*#__PURE__*/_react.default.createElement(_draftRenderer.linkDecorator.component, {
76
+ children,
77
+ contentState,
78
+ entityKey
79
+ }),
80
+ onClick: e => {
81
+ e.preventDefault();
82
+ setIsModalOpen(true);
83
+ props.onEditStart();
84
+ }
85
+ }));
86
+ };
87
+ const editableLinkDecorator = exports.editableLinkDecorator = {
88
+ strategy: _draftRenderer.linkDecorator.strategy,
89
+ component: EditableLink
90
+ };
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.EditableWrapper = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ const Wrapper = _styledComponents.default.span`
11
+ display: inline;
12
+ color: #8e8e8e;
13
+ `;
14
+ const EditButton = _styledComponents.default.div`
15
+ display: inline;
16
+ cursor: pointer;
17
+ padding-left: 2px;
18
+ padding-right: 2px;
19
+ `;
20
+ const EditableWrapper = props => {
21
+ return /*#__PURE__*/_react.default.createElement(Wrapper, null, props.component, /*#__PURE__*/_react.default.createElement(EditButton, {
22
+ onClick: props.onClick
23
+ }, /*#__PURE__*/_react.default.createElement("i", {
24
+ className: "fas fa-pen"
25
+ })));
26
+ };
27
+ exports.EditableWrapper = EditableWrapper;
package/lib/index.js CHANGED
@@ -3,30 +3,30 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "RichTextEditor", {
7
- enumerable: true,
8
- get: function () {
9
- return _draftEditor.RichTextEditor;
10
- }
11
- });
6
+ exports.RichTextEditor = void 0;
12
7
  Object.defineProperty(exports, "buttonNames", {
13
8
  enumerable: true,
14
9
  get: function () {
15
10
  return _btNames.default;
16
11
  }
17
12
  });
18
- Object.defineProperty(exports, "decorator", {
19
- enumerable: true,
20
- get: function () {
21
- return _draftEditor.decorator;
22
- }
23
- });
24
13
  exports.default = void 0;
25
- var _draftEditor = require("./draft-editor");
14
+ var _react = _interopRequireDefault(require("react"));
15
+ var _richTextEditor = require("./rich-text-editor");
26
16
  var _btNames = _interopRequireDefault(require("./buttons/bt-names"));
17
+ var _annotation = require("./entity-decorators/annotation");
18
+ var _link = require("./entity-decorators/link");
19
+ var _tocAnchor = require("./entity-decorators/toc-anchor");
20
+ var _anchor = require("./entity-decorators/anchor");
27
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+ 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); }
23
+ const RichTextEditor = props => {
24
+ return /*#__PURE__*/_react.default.createElement(_richTextEditor.RichTextEditor, _extends({
25
+ decorators: [_annotation.editableAnnotationDecorator, _link.editableLinkDecorator, _tocAnchor.editableTOCAnchorDecorator, _anchor.editableAnchorDecorator]
26
+ }, props));
27
+ };
28
+ exports.RichTextEditor = RichTextEditor;
28
29
  var _default = exports.default = {
29
- RichTextEditor: _draftEditor.RichTextEditor,
30
- buttonNames: _btNames.default,
31
- decorator: _draftEditor.decorator
30
+ RichTextEditor,
31
+ buttonNames: _btNames.default
32
32
  };
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.RichTextEditor = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _draftJs = require("draft-js");
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");
15
+ var _bgColor = require("./buttons/bg-color");
16
+ var _fontColor = require("./buttons/font-color");
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ 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); }
19
+ const styleSource = ['https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css', 'https://storage.googleapis.com/static-readr-tw-dev/cdn/draft-js/rich-editor.css', 'https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css'].map((src, index) => /*#__PURE__*/_react.default.createElement("link", {
20
+ key: `style-src-${index}`,
21
+ href: src,
22
+ rel: "stylesheet",
23
+ type: "text/css"
24
+ }));
25
+ class RichTextEditor extends _react.default.Component {
26
+ editorRef = null;
27
+ constructor(props) {
28
+ var _props$decorators;
29
+ super(props);
30
+ // Assign edit props to decorators
31
+ const editableDecorators = new _draftJs.CompositeDecorator((_props$decorators = props.decorators) === null || _props$decorators === void 0 ? void 0 : _props$decorators.map(editableDecorator => {
32
+ return {
33
+ ...editableDecorator,
34
+ props: {
35
+ ...this.customEditProps
36
+ }
37
+ };
38
+ }));
39
+ const {
40
+ editorState
41
+ } = props;
42
+ this.state = {
43
+ isEnlarged: false,
44
+ readOnly: false,
45
+ editorState: !(editorState instanceof _draftJs.EditorState) ? _draftJs.EditorState.createEmpty(editableDecorators) : _draftJs.EditorState.set(editorState, {
46
+ decorator: editableDecorators
47
+ })
48
+ };
49
+ }
50
+ onChange = editorState => {
51
+ this.setState({
52
+ editorState: editorState
53
+ });
54
+ this.props.onChange(editorState);
55
+ };
56
+ handleKeyCommand = (command, editorState) => {
57
+ const newState = _draftJs.RichUtils.handleKeyCommand(editorState, command);
58
+ if (newState) {
59
+ this.onChange(newState);
60
+ return 'handled';
61
+ }
62
+ return 'not-handled';
63
+ };
64
+ handleReturn = event => {
65
+ if (_draftJs.KeyBindingUtil.isSoftNewlineEvent(event)) {
66
+ this.onChange(_draftJs.RichUtils.insertSoftNewline(this.state.editorState));
67
+ return 'handled';
68
+ }
69
+ return 'not-handled';
70
+ };
71
+ mapKeyToEditorCommand = e => {
72
+ if (e.keyCode === 9 /* TAB */) {
73
+ const newEditorState = _draftJs.RichUtils.onTab(e, this.state.editorState, 4 /* maxDepth */);
74
+ if (newEditorState !== this.state.editorState) {
75
+ this.onChange(newEditorState);
76
+ }
77
+ return null;
78
+ }
79
+ return (0, _draftJs.getDefaultKeyBinding)(e);
80
+ };
81
+ toggleBlockType = blockType => {
82
+ this.onChange(_draftJs.RichUtils.toggleBlockType(this.state.editorState, blockType));
83
+ };
84
+ toggleInlineStyle = inlineStyle => {
85
+ this.onChange(_draftJs.RichUtils.toggleInlineStyle(this.state.editorState, inlineStyle));
86
+ };
87
+ getEntityType = editorState => {
88
+ const contentState = editorState.getCurrentContent();
89
+ const selection = editorState.getSelection();
90
+ const startOffset = selection.getStartOffset();
91
+ const startBlock = editorState.getCurrentContent().getBlockForKey(selection.getStartKey());
92
+ const endOffset = selection.getEndOffset();
93
+ let entityInstance;
94
+ let entityKey;
95
+ if (!selection.isCollapsed()) {
96
+ entityKey = startBlock.getEntityAt(startOffset);
97
+ } else {
98
+ entityKey = startBlock.getEntityAt(endOffset);
99
+ }
100
+ if (entityKey !== null) {
101
+ entityInstance = contentState.getEntity(entityKey);
102
+ }
103
+ let entityType = '';
104
+ if (entityInstance) {
105
+ entityType = entityInstance.getType();
106
+ }
107
+ return entityType;
108
+ };
109
+ toggleEnlarge = () => {
110
+ this.setState({
111
+ isEnlarged: !this.state.isEnlarged
112
+ });
113
+ };
114
+ commonEditProps = {
115
+ onEditStart: () => {
116
+ this.setState({
117
+ // If custom block renderer requires mouse interaction,
118
+ // [Draft.js document](https://draftjs.org/docs/advanced-topics-block-components#recommendations-and-other-notes)
119
+ // suggests that we should temporarily set Editor
120
+ // to readOnly={true} during the interaction.
121
+ // In readOnly={true} condition, the user does not
122
+ // trigger any selection changes within the editor
123
+ // while interacting with custom block.
124
+ // If we don't set readOnly={true},
125
+ // it will cause some subtle bugs in InfoBox button.
126
+ readOnly: true
127
+ });
128
+ },
129
+ onEditFinish: () => {
130
+ this.setState({
131
+ readOnly: false
132
+ });
133
+ }
134
+ };
135
+ customEditProps = {
136
+ onEditStart: this.commonEditProps.onEditStart,
137
+ onEditFinish: ({
138
+ entityKey,
139
+ entityData
140
+ } = {}) => {
141
+ if (entityKey && entityData) {
142
+ const oldContentState = this.state.editorState.getCurrentContent();
143
+ const newContentState = oldContentState.replaceEntityData(entityKey, entityData);
144
+ this.onChange(_draftJs.EditorState.set(this.state.editorState, {
145
+ currentContent: newContentState
146
+ }));
147
+ }
148
+ this.commonEditProps.onEditFinish();
149
+ }
150
+ };
151
+ blockRendererFn = block => {
152
+ const atomicBlockObj = (0, _blockRendererFn.atomicBlockRenderer)(block);
153
+ if (atomicBlockObj) {
154
+ // `onEditStart` and `onEditFinish` will be passed
155
+ // into custom block component.
156
+ // We can get them via `props.blockProps.onEditStart`
157
+ // and `props.blockProps.onEditFinish` in the custom block components.
158
+ atomicBlockObj['props'] = {
159
+ ...this.customEditProps,
160
+ getMainEditorReadOnly: () => this.state.readOnly
161
+ };
162
+ }
163
+ return atomicBlockObj;
164
+ };
165
+ render() {
166
+ const {
167
+ disabledButtons = []
168
+ } = this.props;
169
+ const {
170
+ isEnlarged,
171
+ readOnly,
172
+ editorState
173
+ } = this.state;
174
+ const entityType = this.getEntityType(editorState);
175
+ const commonProps = {
176
+ editorState: editorState,
177
+ onChange: this.onChange,
178
+ readOnly: readOnly
179
+ };
180
+ return /*#__PURE__*/_react.default.createElement(_styled.DraftEditorContainer, {
181
+ isEnlarged: isEnlarged
182
+ }, /*#__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, {
183
+ disabledButtons: disabledButtons,
184
+ editorState: editorState,
185
+ onToggle: this.toggleBlockType,
186
+ readOnly: readOnly
187
+ }), /*#__PURE__*/_react.default.createElement(_buttons.InlineStyleControls, {
188
+ disabledButtons: disabledButtons,
189
+ editorState: editorState,
190
+ onToggle: this.toggleInlineStyle,
191
+ readOnly: readOnly
192
+ }), /*#__PURE__*/_react.default.createElement(_styled.EnlargeButtonWrapper, null, /*#__PURE__*/_react.default.createElement(_buttons.CustomEnlargeButton, {
193
+ onToggle: this.toggleEnlarge,
194
+ isEnlarged: isEnlarged
195
+ })), /*#__PURE__*/_react.default.createElement(_buttons.CustomTOCAnchorButton, _extends({
196
+ isDisabled: disabledButtons.includes(_btNames.default.tocAnchor),
197
+ isActive: entityType === _draftRenderer.ENTITY.TOCAnchor
198
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomAnchorButton, _extends({
199
+ isDisabled: disabledButtons.includes(_btNames.default.anchor),
200
+ isActive: entityType === _draftRenderer.ENTITY.Anchor
201
+ }, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomLinkButton, _extends({
202
+ isDisabled: disabledButtons.includes(_btNames.default.link),
203
+ isActive: entityType === _draftRenderer.ENTITY.Link
204
+ }, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomBackgroundColorButton, _extends({
205
+ isDisabled: disabledButtons.includes(_btNames.default.backgroundColor),
206
+ isActive: editorState.getCurrentInlineStyle().find(styleName => typeof styleName === 'string' && styleName.startsWith(_bgColor.customStylePrefix)) !== undefined
207
+ }, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomFontColorButton, _extends({
208
+ isDisabled: disabledButtons.includes(_btNames.default.fontColor),
209
+ isActive: editorState.getCurrentInlineStyle().find(styleName => typeof styleName === 'string' && styleName.startsWith(_fontColor.customStylePrefix)) !== undefined
210
+ }, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomBlockquoteButton, _extends({
211
+ isDisabled: disabledButtons.includes(_btNames.default.blockquote)
212
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomAnnotationButton, _extends({
213
+ isDisabled: disabledButtons.includes(_btNames.default.annotation),
214
+ isActive: entityType === _draftRenderer.ENTITY.Annotation
215
+ }, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomImageButton, _extends({
216
+ isDisabled: disabledButtons.includes(_btNames.default.image),
217
+ ImageSelector: _imageSelector.ImageSelector
218
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomSlideshowButton, _extends({
219
+ isDisabled: disabledButtons.includes(_btNames.default.slideshow),
220
+ ImageSelector: _imageSelector.ImageSelector
221
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomInfoBoxButton, _extends({
222
+ isDisabled: disabledButtons.includes(_btNames.default.infoBox)
223
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomEmbeddedCodeButton, _extends({
224
+ isDisabled: disabledButtons.includes(_btNames.default.embed)
225
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomNewsReadingButton, _extends({
226
+ isDisabled: disabledButtons.includes(_btNames.default.newsReading)
227
+ }, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomDividerButton, _extends({
228
+ isDisabled: disabledButtons.includes(_btNames.default.divider)
229
+ }, commonProps)))), /*#__PURE__*/_react.default.createElement(_styled.TextEditorWrapper, {
230
+ onClick: () => {
231
+ if (this.editorRef) {
232
+ var _this$editorRef;
233
+ // eslint-disable-next-line prettier/prettier
234
+ (_this$editorRef = this.editorRef) === null || _this$editorRef === void 0 || _this$editorRef.focus();
235
+ }
236
+ }
237
+ }, /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
238
+ blockRenderMap: _draftRenderer.blockRenderMap,
239
+ blockRendererFn: this.blockRendererFn,
240
+ customStyleFn: _draftRenderer.customStyleFn,
241
+ editorState: editorState,
242
+ handleKeyCommand: this.handleKeyCommand,
243
+ handleReturn: this.handleReturn,
244
+ keyBindingFn: this.mapKeyToEditorCommand,
245
+ onChange: this.onChange,
246
+ placeholder: "Tell a story...",
247
+ ref: this.editorRef,
248
+ spellCheck: true,
249
+ readOnly: readOnly
250
+ }))));
251
+ }
252
+ }
253
+ exports.RichTextEditor = RichTextEditor;
254
+ var _default = exports.default = {
255
+ RichTextEditor
256
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kids-reporter/draft-editor",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {