@mirrormedia/lilith-draft-editor 1.1.0-alpha.3 → 1.1.0-alpha.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.
Files changed (72) hide show
  1. package/lib/draft-js/buttons/annotation.js +22 -0
  2. package/lib/draft-js/buttons/audio.js +16 -3
  3. package/lib/draft-js/buttons/background-color.js +26 -0
  4. package/lib/draft-js/buttons/background-image.js +32 -13
  5. package/lib/draft-js/buttons/background-video.js +32 -13
  6. package/lib/draft-js/buttons/color-box.js +21 -5
  7. package/lib/draft-js/buttons/divider.js +12 -3
  8. package/lib/draft-js/buttons/embedded-code.js +16 -5
  9. package/lib/draft-js/buttons/enlarge.js +3 -0
  10. package/lib/draft-js/buttons/font-color.js +26 -0
  11. package/lib/draft-js/buttons/image.js +16 -5
  12. package/lib/draft-js/buttons/info-box.js +21 -5
  13. package/lib/draft-js/buttons/link.js +19 -0
  14. package/lib/draft-js/buttons/media.js +16 -3
  15. package/lib/draft-js/buttons/related-post.js +14 -3
  16. package/lib/draft-js/buttons/selector/align-selector.js +11 -2
  17. package/lib/draft-js/buttons/selector/audio-selector.js +33 -4
  18. package/lib/draft-js/buttons/selector/image-selector.js +50 -6
  19. package/lib/draft-js/buttons/selector/pagination.js +6 -2
  20. package/lib/draft-js/buttons/selector/post-selector.js +39 -6
  21. package/lib/draft-js/buttons/selector/search-box.js +9 -0
  22. package/lib/draft-js/buttons/selector/video-selector.js +33 -4
  23. package/lib/draft-js/buttons/side-index.js +31 -15
  24. package/lib/draft-js/buttons/slideshow.js +16 -7
  25. package/lib/draft-js/buttons/table.js +11 -5
  26. package/lib/draft-js/buttons/text-align.js +14 -0
  27. package/lib/draft-js/buttons/video.js +16 -3
  28. package/lib/draft-js/const.js +2 -0
  29. package/lib/draft-js/draft-converter/api-data-instance.js +14 -0
  30. package/lib/draft-js/draft-converter/atomic-block-processor.js +41 -12
  31. package/lib/draft-js/draft-converter/entities.js +0 -1
  32. package/lib/draft-js/draft-converter/index.js +29 -10
  33. package/lib/draft-js/draft-converter/inline-styles-processor.js +55 -22
  34. package/lib/draft-js/modifier.js +13 -5
  35. package/lib/index.js +4 -0
  36. package/lib/website/mirrormedia/block-renderer/background-image-block.js +14 -2
  37. package/lib/website/mirrormedia/block-renderer/background-video-block.js +14 -2
  38. package/lib/website/mirrormedia/block-renderer/color-box-block.js +14 -2
  39. package/lib/website/mirrormedia/block-renderer/embedded-code-block.js +12 -3
  40. package/lib/website/mirrormedia/block-renderer/info-box-block.js +14 -2
  41. package/lib/website/mirrormedia/block-renderer/side-index-block.js +13 -2
  42. package/lib/website/mirrormedia/block-renderer/slideshow-block.js +11 -4
  43. package/lib/website/mirrormedia/block-renderer/table-block.js +62 -28
  44. package/lib/website/mirrormedia/block-renderer-fn.js +30 -0
  45. package/lib/website/mirrormedia/draft-editor.js +106 -10
  46. package/lib/website/mirrormedia/entity-decorator.js +4 -0
  47. package/lib/website/mirrormedia/index.js +3 -0
  48. package/lib/website/mirrormedia/selector/align-selector.js +11 -2
  49. package/lib/website/mirrormedia/selector/audio-selector.js +33 -4
  50. package/lib/website/mirrormedia/selector/image-selector.js +49 -6
  51. package/lib/website/mirrormedia/selector/pagination.js +6 -2
  52. package/lib/website/mirrormedia/selector/post-selector.js +39 -6
  53. package/lib/website/mirrormedia/selector/search-box.js +9 -0
  54. package/lib/website/mirrormedia/selector/video-selector.js +32 -4
  55. package/lib/website/readr/block-renderer/background-image-block.js +14 -2
  56. package/lib/website/readr/block-renderer/background-video-block.js +14 -2
  57. package/lib/website/readr/block-renderer/color-box-block.js +14 -2
  58. package/lib/website/readr/block-renderer/info-box-block.js +14 -2
  59. package/lib/website/readr/block-renderer/side-index-block.js +13 -2
  60. package/lib/website/readr/block-renderer/table-block.js +62 -28
  61. package/lib/website/readr/block-renderer-fn.js +28 -0
  62. package/lib/website/readr/draft-editor.js +106 -10
  63. package/lib/website/readr/entity-decorator.js +4 -0
  64. package/lib/website/readr/index.js +3 -0
  65. package/lib/website/readr/selector/align-selector.js +11 -2
  66. package/lib/website/readr/selector/audio-selector.js +33 -16
  67. package/lib/website/readr/selector/image-selector.js +49 -6
  68. package/lib/website/readr/selector/pagination.js +6 -2
  69. package/lib/website/readr/selector/post-selector.js +39 -6
  70. package/lib/website/readr/selector/search-box.js +9 -0
  71. package/lib/website/readr/selector/video-selector.js +32 -4
  72. package/package.json +2 -2
@@ -4,16 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.AnnotationButton = AnnotationButton;
7
+
7
8
  var _react = _interopRequireWildcard(require("react"));
9
+
8
10
  var _draftJs = require("draft-js");
11
+
9
12
  var _modals = require("@keystone-ui/modals");
13
+
10
14
  var _draftConverter = _interopRequireDefault(require("../draft-converter"));
15
+
11
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
12
18
  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); }
19
+
13
20
  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; }
21
+
14
22
  function escapeHTML(s) {
15
23
  return s.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&#39;');
16
24
  }
25
+
17
26
  function AnnotationButton(props) {
18
27
  const toggleEntity = _draftJs.RichUtils.toggleLink;
19
28
  const {
@@ -27,42 +36,53 @@ function AnnotationButton(props) {
27
36
  const [inputValue, setInputValue] = (0, _react.useState)({
28
37
  editorStateOfBasicEditor: _draftJs.EditorState.createEmpty(decorators)
29
38
  });
39
+
30
40
  const promptForAnnotation = e => {
31
41
  e.preventDefault();
32
42
  const selection = editorState.getSelection();
43
+
33
44
  if (!selection.isCollapsed()) {
34
45
  setToShowInput(true);
35
46
  }
36
47
  };
48
+
37
49
  const confirmAnnotation = () => {
38
50
  const contentState = editorState.getCurrentContent();
39
51
  const rawContentState = (0, _draftJs.convertToRaw)(inputValue.editorStateOfBasicEditor.getCurrentContent());
52
+
40
53
  const bodyHTML = _draftConverter.default.convertToHtml(rawContentState);
54
+
41
55
  const contentStateWithEntity = contentState.createEntity('ANNOTATION', 'MUTABLE', {
42
56
  rawContentState,
43
57
  bodyHTML,
44
58
  bodyEscapedHTML: escapeHTML(bodyHTML)
45
59
  });
46
60
  const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
61
+
47
62
  const newEditorState = _draftJs.EditorState.set(editorState, {
48
63
  currentContent: contentStateWithEntity
49
64
  });
65
+
50
66
  onChange(toggleEntity(newEditorState, newEditorState.getSelection(), entityKey));
51
67
  setToShowInput(false);
52
68
  setInputValue({
53
69
  editorStateOfBasicEditor: _draftJs.EditorState.createEmpty(decorators)
54
70
  });
55
71
  };
72
+
56
73
  const removeAnnotation = () => {
57
74
  const selection = editorState.getSelection();
75
+
58
76
  if (!selection.isCollapsed()) {
59
77
  onChange(toggleEntity(editorState, selection, null));
60
78
  }
79
+
61
80
  setToShowInput(false);
62
81
  setInputValue({
63
82
  editorStateOfBasicEditor: _draftJs.EditorState.createEmpty(decorators)
64
83
  });
65
84
  };
85
+
66
86
  const basicEditorJsx = renderBasicEditor({
67
87
  editorState: inputValue.editorStateOfBasicEditor,
68
88
  onChange: editorStateOfBasicEditor => {
@@ -71,6 +91,7 @@ function AnnotationButton(props) {
71
91
  });
72
92
  }
73
93
  });
94
+
74
95
  const urlInput = /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
75
96
  isOpen: toShowInput
76
97
  }, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
@@ -86,6 +107,7 @@ function AnnotationButton(props) {
86
107
  }
87
108
  }
88
109
  }, basicEditorJsx));
110
+
89
111
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, urlInput, /*#__PURE__*/_react.default.createElement("div", {
90
112
  className: props.className,
91
113
  onMouseDown: isActive ? removeAnnotation : promptForAnnotation
@@ -4,11 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.AudioButton = AudioButton;
7
+
7
8
  var _react = _interopRequireWildcard(require("react"));
9
+
8
10
  var _draftJs = require("draft-js");
11
+
9
12
  var _audioSelector = require("./selector/audio-selector");
13
+
10
14
  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); }
15
+
11
16
  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
+
12
18
  function AudioButton(props) {
13
19
  const {
14
20
  editorState,
@@ -17,30 +23,37 @@ function AudioButton(props) {
17
23
  AudioSelector = _audioSelector.AudioSelector
18
24
  } = props;
19
25
  const [toShowAudioSelector, setToShowAudioSelector] = (0, _react.useState)(false);
26
+
20
27
  const promptForAudioSelector = () => {
21
28
  setToShowAudioSelector(true);
22
29
  };
30
+
23
31
  const onAudioSelectorChange = selectedAudiosWithMeta => {
24
32
  var _selectedAudiosWithMe;
33
+
25
34
  const audio = selectedAudiosWithMeta === null || selectedAudiosWithMeta === void 0 ? void 0 : (_selectedAudiosWithMe = selectedAudiosWithMeta[0]) === null || _selectedAudiosWithMe === void 0 ? void 0 : _selectedAudiosWithMe.audio;
35
+
26
36
  if (!audio) {
27
37
  setToShowAudioSelector(false);
28
38
  return;
29
39
  }
40
+
30
41
  const contentState = editorState.getCurrentContent();
31
42
  const contentStateWithEntity = contentState.createEntity('AUDIO', 'IMMUTABLE', {
32
43
  audio
33
44
  });
34
45
  const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
46
+
35
47
  const newEditorState = _draftJs.EditorState.set(editorState, {
36
48
  currentContent: contentStateWithEntity
37
- });
38
-
39
- // The third parameter here is a space string, not an empty string
49
+ }); // The third parameter here is a space string, not an empty string
40
50
  // If you set an empty string, you will get an error: Unknown DraftEntity key: null
51
+
52
+
41
53
  onChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
42
54
  setToShowAudioSelector(false);
43
55
  };
56
+
44
57
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, toShowAudioSelector && /*#__PURE__*/_react.default.createElement(AudioSelector, {
45
58
  onChange: onAudioSelectorChange
46
59
  }), /*#__PURE__*/_react.default.createElement("div", {
@@ -4,21 +4,33 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.BackgroundColorButton = BackgroundColorButton;
7
+
7
8
  var _react = _interopRequireWildcard(require("react"));
9
+
8
10
  var _modals = require("@keystone-ui/modals");
11
+
9
12
  var _draftJs = require("draft-js");
13
+
10
14
  var _fields = require("@keystone-ui/fields");
15
+
11
16
  var _styledComponents = _interopRequireDefault(require("styled-components"));
17
+
12
18
  var _modifier = require("../modifier");
19
+
13
20
  var _const = require("../const");
21
+
14
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
15
24
  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); }
25
+
16
26
  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; }
27
+
17
28
  const ColorHexInput = (0, _styledComponents.default)(_fields.TextInput)`
18
29
  font-family: Georgia, serif;
19
30
  margin-right: 10px;
20
31
  padding: 10px;
21
32
  `;
33
+
22
34
  function BackgroundColorButton(props) {
23
35
  const {
24
36
  isActive,
@@ -27,40 +39,53 @@ function BackgroundColorButton(props) {
27
39
  } = props;
28
40
  const [toShowColorInput, setToShowColorInput] = (0, _react.useState)(false);
29
41
  const [colorValue, setColorValue] = (0, _react.useState)('');
42
+
30
43
  const promptForColor = e => {
31
44
  e.preventDefault();
32
45
  const selection = editorState.getSelection();
46
+
33
47
  if (!selection.isCollapsed()) {
34
48
  setToShowColorInput(true);
35
49
  }
36
50
  };
51
+
37
52
  const confirmColor = () => {
38
53
  const selection = editorState.getSelection();
39
54
  const contentState = editorState.getCurrentContent();
55
+
40
56
  let newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, _const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR);
57
+
41
58
  if (colorValue) {
42
59
  newContentState = _modifier.Modifier.applyInlineStyle(newContentState, selection, _const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR + colorValue);
43
60
  }
61
+
44
62
  onChange(_draftJs.EditorState.push(editorState, newContentState, 'change-inline-style'));
45
63
  setToShowColorInput(false);
46
64
  setColorValue('');
47
65
  };
66
+
48
67
  const onColorInputKeyDown = e => {
49
68
  if (e.which === 13) {
50
69
  e.preventDefault();
51
70
  confirmColor();
52
71
  }
53
72
  };
73
+
54
74
  const removeColor = () => {
55
75
  const selection = editorState.getSelection();
76
+
56
77
  if (!selection.isCollapsed()) {
57
78
  const contentState = editorState.getCurrentContent();
79
+
58
80
  const newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, _const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR);
81
+
59
82
  onChange(_draftJs.EditorState.push(editorState, newContentState, 'change-inline-style'));
60
83
  }
84
+
61
85
  setToShowColorInput(false);
62
86
  setColorValue('');
63
87
  };
88
+
64
89
  const colorInput = /*#__PURE__*/_react.default.createElement(_modals.AlertDialog, {
65
90
  title: "Hex Color Code (#ffffff)",
66
91
  isOpen: toShowColorInput,
@@ -80,6 +105,7 @@ function BackgroundColorButton(props) {
80
105
  value: colorValue,
81
106
  onKeyDown: onColorInputKeyDown
82
107
  }));
108
+
83
109
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, colorInput, /*#__PURE__*/_react.default.createElement("div", {
84
110
  className: props.className,
85
111
  onMouseDown: isActive ? removeColor : promptForColor
@@ -5,17 +5,29 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.BGImageButton = BGImageButton;
7
7
  exports.BGImageInput = BGImageInput;
8
+
8
9
  var _react = _interopRequireWildcard(require("react"));
10
+
9
11
  var _draftJs = require("draft-js");
12
+
10
13
  var _modals = require("@keystone-ui/modals");
14
+
11
15
  var _button = require("@keystone-ui/button");
16
+
12
17
  var _draftConverter = _interopRequireDefault(require("../draft-converter"));
18
+
13
19
  var _styledComponents = _interopRequireDefault(require("styled-components"));
20
+
14
21
  var _imageSelector = require("./selector/image-selector");
22
+
15
23
  var _alignSelector = require("./selector/align-selector");
24
+
16
25
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
+
17
27
  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); }
28
+
18
29
  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; }
30
+
19
31
  const Label = _styledComponents.default.label`
20
32
  display: block;
21
33
  font-weight: 600;
@@ -25,8 +37,10 @@ const ImageInputText = _styledComponents.default.span`
25
37
  display: inline-block;
26
38
  margin-right: 10px;
27
39
  `;
40
+
28
41
  function BGImageInput(props) {
29
42
  var _inputValue$image;
43
+
30
44
  const {
31
45
  isOpen,
32
46
  onChange,
@@ -67,33 +81,36 @@ function BGImageInput(props) {
67
81
  };
68
82
  const [inputValue, setInputValue] = (0, _react.useState)(initialInputValue);
69
83
  const [toShowImageSelector, setToShowImageSelector] = (0, _react.useState)(false);
84
+
70
85
  const clearInputValue = () => {
71
- setInputValue(oldInputValue => ({
72
- ...oldInputValue,
86
+ setInputValue(oldInputValue => ({ ...oldInputValue,
73
87
  editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)({
74
88
  blocks: [],
75
89
  entityMap: {}
76
90
  }), decorators)
77
91
  }));
78
92
  };
93
+
79
94
  const onImageSelectorChange = selectedImagesWithMeta => {
80
95
  var _selectedImagesWithMe;
96
+
81
97
  const image = selectedImagesWithMeta === null || selectedImagesWithMeta === void 0 ? void 0 : (_selectedImagesWithMe = selectedImagesWithMeta[0]) === null || _selectedImagesWithMe === void 0 ? void 0 : _selectedImagesWithMe.image;
98
+
82
99
  if (!image) {
83
100
  setToShowImageSelector(false);
84
101
  return;
85
102
  }
86
- setInputValue(oldInputValue => ({
87
- ...oldInputValue,
103
+
104
+ setInputValue(oldInputValue => ({ ...oldInputValue,
88
105
  image: image
89
106
  }));
90
107
  setToShowImageSelector(false);
91
108
  };
109
+
92
110
  const basicEditorJsx = renderBasicEditor({
93
111
  editorState: inputValue.editorStateOfBasicEditor,
94
112
  onChange: editorStateOfBasicEditor => {
95
- setInputValue(oldInputValue => ({
96
- ...oldInputValue,
113
+ setInputValue(oldInputValue => ({ ...oldInputValue,
97
114
  editorStateOfBasicEditor
98
115
  }));
99
116
  }
@@ -138,13 +155,13 @@ function BGImageInput(props) {
138
155
  align: inputValue.textBlockAlign,
139
156
  options: options,
140
157
  onChange: textBlockAlign => {
141
- setInputValue(oldInputValue => ({
142
- ...oldInputValue,
158
+ setInputValue(oldInputValue => ({ ...oldInputValue,
143
159
  textBlockAlign
144
160
  }));
145
161
  }
146
162
  }), /*#__PURE__*/_react.default.createElement(Label, null, "\u5167\u6587"), basicEditorJsx)));
147
163
  }
164
+
148
165
  function BGImageButton(props) {
149
166
  const [toShowInput, setToShowInput] = (0, _react.useState)(false);
150
167
  const {
@@ -154,14 +171,14 @@ function BGImageButton(props) {
154
171
  ImageSelector,
155
172
  renderBasicEditor
156
173
  } = props;
174
+
157
175
  const onChange = ({
158
176
  textBlockAlign,
159
177
  image,
160
178
  rawContentState
161
179
  }) => {
162
- const contentState = editorState.getCurrentContent();
180
+ const contentState = editorState.getCurrentContent(); // create an BGImage entity
163
181
 
164
- // create an BGImage entity
165
182
  const contentStateWithEntity = contentState.createEntity('BACKGROUNDIMAGE', 'IMMUTABLE', {
166
183
  textBlockAlign,
167
184
  image,
@@ -169,15 +186,17 @@ function BGImageButton(props) {
169
186
  body: _draftConverter.default.convertToHtml(rawContentState)
170
187
  });
171
188
  const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
189
+
172
190
  const newEditorState = _draftJs.EditorState.set(editorState, {
173
191
  currentContent: contentStateWithEntity
174
- });
175
-
176
- //The third parameter here is a space string, not an empty string
192
+ }); //The third parameter here is a space string, not an empty string
177
193
  //If you set an empty string, you will get an error: Unknown DraftEntity key: null
194
+
195
+
178
196
  onEditorStateChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
179
197
  setToShowInput(false);
180
198
  };
199
+
181
200
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(BGImageInput, {
182
201
  renderBasicEditor: renderBasicEditor,
183
202
  onChange: onChange,
@@ -5,17 +5,29 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.BGVideoButton = BGVideoButton;
7
7
  exports.BGVideoInput = BGVideoInput;
8
+
8
9
  var _react = _interopRequireWildcard(require("react"));
10
+
9
11
  var _draftJs = require("draft-js");
12
+
10
13
  var _modals = require("@keystone-ui/modals");
14
+
11
15
  var _button = require("@keystone-ui/button");
16
+
12
17
  var _draftConverter = _interopRequireDefault(require("../draft-converter"));
18
+
13
19
  var _styledComponents = _interopRequireDefault(require("styled-components"));
20
+
14
21
  var _videoSelector = require("./selector/video-selector");
22
+
15
23
  var _alignSelector = require("./selector/align-selector");
24
+
16
25
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
+
17
27
  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); }
28
+
18
29
  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; }
30
+
19
31
  const Label = _styledComponents.default.label`
20
32
  display: block;
21
33
  font-weight: 600;
@@ -25,8 +37,10 @@ const VideoInputText = _styledComponents.default.span`
25
37
  display: inline-block;
26
38
  margin-right: 10px;
27
39
  `;
40
+
28
41
  function BGVideoInput(props) {
29
42
  var _inputValue$video;
43
+
30
44
  const {
31
45
  isOpen,
32
46
  onChange,
@@ -67,33 +81,36 @@ function BGVideoInput(props) {
67
81
  };
68
82
  const [inputValue, setInputValue] = (0, _react.useState)(initialInputValue);
69
83
  const [toShowVideoSelector, setToShowVideoSelector] = (0, _react.useState)(false);
84
+
70
85
  const clearInputValue = () => {
71
- setInputValue(oldInputValue => ({
72
- ...oldInputValue,
86
+ setInputValue(oldInputValue => ({ ...oldInputValue,
73
87
  editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)({
74
88
  blocks: [],
75
89
  entityMap: {}
76
90
  }), decorators)
77
91
  }));
78
92
  };
93
+
79
94
  const onVideoSelectorChange = selectedVideosWithMeta => {
80
95
  var _selectedVideosWithMe;
96
+
81
97
  const video = selectedVideosWithMeta === null || selectedVideosWithMeta === void 0 ? void 0 : (_selectedVideosWithMe = selectedVideosWithMeta[0]) === null || _selectedVideosWithMe === void 0 ? void 0 : _selectedVideosWithMe.video;
98
+
82
99
  if (!video) {
83
100
  setToShowVideoSelector(false);
84
101
  return;
85
102
  }
86
- setInputValue(oldInputValue => ({
87
- ...oldInputValue,
103
+
104
+ setInputValue(oldInputValue => ({ ...oldInputValue,
88
105
  video: video
89
106
  }));
90
107
  setToShowVideoSelector(false);
91
108
  };
109
+
92
110
  const basicEditorJsx = renderBasicEditor({
93
111
  editorState: inputValue.editorStateOfBasicEditor,
94
112
  onChange: editorStateOfBasicEditor => {
95
- setInputValue(oldInputValue => ({
96
- ...oldInputValue,
113
+ setInputValue(oldInputValue => ({ ...oldInputValue,
97
114
  editorStateOfBasicEditor
98
115
  }));
99
116
  }
@@ -138,13 +155,13 @@ function BGVideoInput(props) {
138
155
  align: inputValue.textBlockAlign,
139
156
  options: options,
140
157
  onChange: textBlockAlign => {
141
- setInputValue(oldInputValue => ({
142
- ...oldInputValue,
158
+ setInputValue(oldInputValue => ({ ...oldInputValue,
143
159
  textBlockAlign
144
160
  }));
145
161
  }
146
162
  }), /*#__PURE__*/_react.default.createElement(Label, null, "\u5167\u6587"), basicEditorJsx)));
147
163
  }
164
+
148
165
  function BGVideoButton(props) {
149
166
  const [toShowInput, setToShowInput] = (0, _react.useState)(false);
150
167
  const {
@@ -154,14 +171,14 @@ function BGVideoButton(props) {
154
171
  VideoSelector,
155
172
  renderBasicEditor
156
173
  } = props;
174
+
157
175
  const onChange = ({
158
176
  textBlockAlign,
159
177
  video,
160
178
  rawContentState
161
179
  }) => {
162
- const contentState = editorState.getCurrentContent();
180
+ const contentState = editorState.getCurrentContent(); // create an BGVideo entity
163
181
 
164
- // create an BGVideo entity
165
182
  const contentStateWithEntity = contentState.createEntity('BACKGROUNDVIDEO', 'IMMUTABLE', {
166
183
  textBlockAlign,
167
184
  video,
@@ -169,15 +186,17 @@ function BGVideoButton(props) {
169
186
  body: _draftConverter.default.convertToHtml(rawContentState)
170
187
  });
171
188
  const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
189
+
172
190
  const newEditorState = _draftJs.EditorState.set(editorState, {
173
191
  currentContent: contentStateWithEntity
174
- });
175
-
176
- //The third parameter here is a space string, not an empty string
192
+ }); //The third parameter here is a space string, not an empty string
177
193
  //If you set an empty string, you will get an error: Unknown DraftEntity key: null
194
+
195
+
178
196
  onEditorStateChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
179
197
  setToShowInput(false);
180
198
  };
199
+
181
200
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(BGVideoInput, {
182
201
  renderBasicEditor: renderBasicEditor,
183
202
  onChange: onChange,
@@ -5,15 +5,25 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.ColorBoxButton = ColorBoxButton;
7
7
  exports.ColorBoxInput = ColorBoxInput;
8
+
8
9
  var _react = _interopRequireWildcard(require("react"));
10
+
9
11
  var _draftJs = require("draft-js");
12
+
10
13
  var _modals = require("@keystone-ui/modals");
14
+
11
15
  var _fields = require("@keystone-ui/fields");
16
+
12
17
  var _draftConverter = _interopRequireDefault(require("../draft-converter"));
18
+
13
19
  var _styledComponents = _interopRequireDefault(require("styled-components"));
20
+
14
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+
15
23
  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); }
24
+
16
25
  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; }
26
+
17
27
  const Label = _styledComponents.default.label`
18
28
  display: block;
19
29
  font-weight: 600;
@@ -22,6 +32,7 @@ const Label = _styledComponents.default.label`
22
32
  const ColorHexInput = (0, _styledComponents.default)(_fields.TextInput)`
23
33
  margin-bottom: 10px;
24
34
  `;
35
+
25
36
  function ColorBoxInput(props) {
26
37
  const {
27
38
  isOpen,
@@ -42,6 +53,7 @@ function ColorBoxInput(props) {
42
53
  editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(rawContentState), decorators)
43
54
  };
44
55
  const [inputValue, setInputValue] = (0, _react.useState)(initialInputValue);
56
+
45
57
  const clearInputValue = () => {
46
58
  setInputValue({
47
59
  color: '',
@@ -51,6 +63,7 @@ function ColorBoxInput(props) {
51
63
  }), decorators)
52
64
  });
53
65
  };
66
+
54
67
  (0, _react.useEffect)(() => {
55
68
  if (isOpen) {
56
69
  setInputValue(initialInputValue);
@@ -99,6 +112,7 @@ function ColorBoxInput(props) {
99
112
  value: inputValue.color
100
113
  }), /*#__PURE__*/_react.default.createElement(Label, null, "\u5167\u6587"), basicEditorJsx));
101
114
  }
115
+
102
116
  function ColorBoxButton(props) {
103
117
  const [toShowInput, setToShowInput] = (0, _react.useState)(false);
104
118
  const {
@@ -107,28 +121,30 @@ function ColorBoxButton(props) {
107
121
  onChange: onEditorStateChange,
108
122
  renderBasicEditor
109
123
  } = props;
124
+
110
125
  const onChange = ({
111
126
  color,
112
127
  rawContentState
113
128
  }) => {
114
- const contentState = editorState.getCurrentContent();
129
+ const contentState = editorState.getCurrentContent(); // create an ColorBox entity
115
130
 
116
- // create an ColorBox entity
117
131
  const contentStateWithEntity = contentState.createEntity('COLORBOX', 'IMMUTABLE', {
118
132
  color,
119
133
  rawContentState,
120
134
  body: _draftConverter.default.convertToHtml(rawContentState)
121
135
  });
122
136
  const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
137
+
123
138
  const newEditorState = _draftJs.EditorState.set(editorState, {
124
139
  currentContent: contentStateWithEntity
125
- });
126
-
127
- //The third parameter here is a space string, not an empty string
140
+ }); //The third parameter here is a space string, not an empty string
128
141
  //If you set an empty string, you will get an error: Unknown DraftEntity key: null
142
+
143
+
129
144
  onEditorStateChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
130
145
  setToShowInput(false);
131
146
  };
147
+
132
148
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(ColorBoxInput, {
133
149
  renderBasicEditor: renderBasicEditor,
134
150
  onChange: onChange,
@@ -4,33 +4,42 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DividerButton = DividerButton;
7
+
7
8
  var _react = _interopRequireDefault(require("react"));
9
+
8
10
  var _draftJs = require("draft-js");
11
+
9
12
  var _styledComponents = _interopRequireDefault(require("styled-components"));
13
+
10
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
11
16
  const IconWrapper = _styledComponents.default.span`
12
17
  display: inline-block;
13
18
  position: relative;
14
19
  top: 2px;
15
20
  `;
21
+
16
22
  function DividerButton(props) {
17
23
  const {
18
24
  editorState,
19
25
  onChange,
20
26
  className
21
27
  } = props;
28
+
22
29
  const onClick = () => {
23
30
  const contentState = editorState.getCurrentContent();
24
31
  const contentStateWithEntity = contentState.createEntity('DIVIDER', 'IMMUTABLE', {});
25
32
  const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
33
+
26
34
  const newEditorState = _draftJs.EditorState.set(editorState, {
27
35
  currentContent: contentStateWithEntity
28
- });
29
-
30
- // The third parameter here is a space string, not an empty string
36
+ }); // The third parameter here is a space string, not an empty string
31
37
  // If you set an empty string, you will get an error: Unknown DraftEntity key: null
38
+
39
+
32
40
  onChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
33
41
  };
42
+
34
43
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
35
44
  onClick: onClick,
36
45
  className: className