@kids-reporter/draft-editor 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/lib/buttons/annotation.js +1 -14
  2. package/lib/buttons/image.js +0 -3
  3. package/lib/buttons/info-box.js +1 -4
  4. package/lib/buttons/selector/image-selector.js +3 -1
  5. package/lib/buttons/slideshow.js +2 -3
  6. package/lib/draft-editor.js +61 -363
  7. package/package.json +12 -7
  8. package/lib/block-renderer/background-image-block.js +0 -141
  9. package/lib/block-renderer/background-video-block.js +0 -151
  10. package/lib/block-renderer/color-box-block.js +0 -86
  11. package/lib/block-renderer/info-box-block.js +0 -86
  12. package/lib/block-renderer/side-index-block.js +0 -90
  13. package/lib/block-renderer/table-block.js +0 -408
  14. package/lib/block-renderer-fn.js +0 -131
  15. package/lib/buttons/audio.js +0 -65
  16. package/lib/buttons/background-color.js +0 -122
  17. package/lib/buttons/background-image.js +0 -223
  18. package/lib/buttons/background-video.js +0 -223
  19. package/lib/buttons/color-box.js +0 -173
  20. package/lib/buttons/divider.js +0 -63
  21. package/lib/buttons/font-color.js +0 -115
  22. package/lib/buttons/media.js +0 -121
  23. package/lib/buttons/related-post.js +0 -71
  24. package/lib/buttons/selector/audio-selector.js +0 -279
  25. package/lib/buttons/selector/post-selector.js +0 -317
  26. package/lib/buttons/selector/video-selector.js +0 -281
  27. package/lib/buttons/side-index.js +0 -200
  28. package/lib/buttons/table.js +0 -67
  29. package/lib/buttons/text-align.js +0 -88
  30. package/lib/buttons/video.js +0 -65
  31. package/lib/buttons/youtube.js +0 -147
  32. package/lib/const.js +0 -18
  33. package/lib/draft-converter/api-data-instance.js +0 -58
  34. package/lib/draft-converter/atomic-block-processor.js +0 -233
  35. package/lib/draft-converter/entities.js +0 -76
  36. package/lib/draft-converter/index.js +0 -201
  37. package/lib/draft-converter/inline-styles-processor.js +0 -236
  38. package/lib/entity-decorator.js +0 -20
  39. package/lib/modifier.js +0 -68
  40. package/lib/theme/index.js +0 -39
@@ -1,122 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.BackgroundColorButton = BackgroundColorButton;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _modals = require("@keystone-ui/modals");
11
-
12
- var _draftJs = require("draft-js");
13
-
14
- var _fields = require("@keystone-ui/fields");
15
-
16
- var _styledComponents = _interopRequireDefault(require("styled-components"));
17
-
18
- var _modifier = require("../modifier");
19
-
20
- var _const = require("../const");
21
-
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
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
-
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
-
28
- const ColorHexInput = (0, _styledComponents.default)(_fields.TextInput)`
29
- font-family: Georgia, serif;
30
- margin-right: 10px;
31
- padding: 10px;
32
- `;
33
-
34
- function BackgroundColorButton(props) {
35
- const {
36
- isActive,
37
- editorState,
38
- onChange
39
- } = props;
40
- const [toShowColorInput, setToShowColorInput] = (0, _react.useState)(false);
41
- const [colorValue, setColorValue] = (0, _react.useState)('');
42
-
43
- const promptForColor = e => {
44
- e.preventDefault();
45
- const selection = editorState.getSelection();
46
-
47
- if (!selection.isCollapsed()) {
48
- setToShowColorInput(true);
49
- }
50
- };
51
-
52
- const confirmColor = () => {
53
- const selection = editorState.getSelection();
54
- const contentState = editorState.getCurrentContent();
55
-
56
- let newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, _const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR);
57
-
58
- if (colorValue) {
59
- newContentState = _modifier.Modifier.applyInlineStyle(newContentState, selection, _const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR + colorValue);
60
- }
61
-
62
- onChange(_draftJs.EditorState.push(editorState, newContentState, 'change-inline-style'));
63
- setToShowColorInput(false);
64
- setColorValue('');
65
- };
66
-
67
- const onColorInputKeyDown = e => {
68
- if (e.which === 13) {
69
- e.preventDefault();
70
- confirmColor();
71
- }
72
- };
73
-
74
- const removeColor = () => {
75
- const selection = editorState.getSelection();
76
-
77
- if (!selection.isCollapsed()) {
78
- const contentState = editorState.getCurrentContent();
79
-
80
- const newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, _const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR);
81
-
82
- onChange(_draftJs.EditorState.push(editorState, newContentState, 'change-inline-style'));
83
- }
84
-
85
- setToShowColorInput(false);
86
- setColorValue('');
87
- };
88
-
89
- const colorInput = /*#__PURE__*/_react.default.createElement(_modals.AlertDialog, {
90
- title: "Hex Color Code (#ffffff)",
91
- isOpen: toShowColorInput,
92
- actions: {
93
- cancel: {
94
- label: 'Cancel',
95
- action: removeColor
96
- },
97
- confirm: {
98
- label: 'Confirm',
99
- action: confirmColor
100
- }
101
- }
102
- }, /*#__PURE__*/_react.default.createElement(ColorHexInput, {
103
- onChange: e => setColorValue(e.target.value),
104
- type: "text",
105
- value: colorValue,
106
- onKeyDown: onColorInputKeyDown
107
- }));
108
-
109
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, colorInput, /*#__PURE__*/_react.default.createElement("div", {
110
- className: props.className,
111
- onMouseDown: isActive ? removeColor : promptForColor
112
- }, /*#__PURE__*/_react.default.createElement("svg", {
113
- width: "16",
114
- height: "14",
115
- viewBox: "0 0 16 14",
116
- fill: "none",
117
- xmlns: "http://www.w3.org/2000/svg"
118
- }, /*#__PURE__*/_react.default.createElement("path", {
119
- d: "M3.74443 8.75V6.78945C3.74443 6.37109 3.98306 5.98008 4.34542 5.73125L12.3911 0.229633C12.6091 0.0804726 12.8477 0 13.1453 0C13.4811 0 13.8022 0.124113 14.0409 0.345078L15.6553 1.84242C15.8939 2.06336 16 2.36305 16 2.67531C16 2.92578 15.9411 3.14727 15.779 3.37422L9.85159 10.8418C9.5835 11.1781 9.1357 11.375 8.71147 11.375H6.57264L5.85086 12.0695C5.4826 12.4113 4.8875 12.4113 4.51924 12.0695L3.02265 10.6805C2.65439 10.3387 2.65439 9.78633 3.02265 9.44453L3.74443 8.75ZM13.9466 2.73219L13.0834 1.9302L6.74646 6.26172L9.25354 8.58867L13.9466 2.73219ZM0.207107 12.7504L2.064 11.0277L4.14509 12.9582L3.23182 13.784C3.09925 13.9316 2.91954 14 2.73099 14H0.707052C0.3167 14 0 13.7074 0 13.3438V13.2152C0 13.0184 0.0745351 12.8734 0.207107 12.7504Z",
120
- fill: isActive ? '#ED8B00' : '#6b7280'
121
- })), /*#__PURE__*/_react.default.createElement("span", null, " Highlight")));
122
- }
@@ -1,223 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.BGImageButton = BGImageButton;
7
- exports.BGImageInput = BGImageInput;
8
-
9
- var _react = _interopRequireWildcard(require("react"));
10
-
11
- var _draftJs = require("draft-js");
12
-
13
- var _modals = require("@keystone-ui/modals");
14
-
15
- var _button = require("@keystone-ui/button");
16
-
17
- var _draftConverter = _interopRequireDefault(require("../draft-converter"));
18
-
19
- var _styledComponents = _interopRequireDefault(require("styled-components"));
20
-
21
- var _imageSelector = require("./selector/image-selector");
22
-
23
- var _alignSelector = require("./selector/align-selector");
24
-
25
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
-
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
-
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
-
31
- const Label = _styledComponents.default.label`
32
- display: block;
33
- font-weight: 600;
34
- margin: 10px 0;
35
- `;
36
- const ImageInputText = _styledComponents.default.span`
37
- display: inline-block;
38
- margin-right: 10px;
39
- `;
40
-
41
- function BGImageInput(props) {
42
- var _inputValue$image;
43
-
44
- const {
45
- isOpen,
46
- onChange,
47
- onCancel,
48
- textBlockAlign,
49
- image,
50
- rawContentStateForBGImageEditor,
51
- ImageSelector = _imageSelector.ImageSelector,
52
- renderBasicEditor,
53
- decorators
54
- } = props;
55
- const rawContentState = rawContentStateForBGImageEditor || {
56
- blocks: [],
57
- entityMap: {}
58
- };
59
- const options = [{
60
- value: 'fixed',
61
- label: 'fixed (default)',
62
- isDisabled: false
63
- }, {
64
- value: 'bottom',
65
- label: 'bottom',
66
- isDisabled: false
67
- }, {
68
- value: 'left',
69
- label: 'left',
70
- isDisabled: false
71
- }, {
72
- value: 'right',
73
- label: 'right',
74
- isDisabled: false
75
- }];
76
- const initialInputValue = {
77
- textBlockAlign: textBlockAlign || 'fixed',
78
- image: image || undefined,
79
- // create an `editorState` from raw content state object
80
- editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(rawContentState), decorators)
81
- };
82
- const [inputValue, setInputValue] = (0, _react.useState)(initialInputValue);
83
- const [toShowImageSelector, setToShowImageSelector] = (0, _react.useState)(false);
84
-
85
- const clearInputValue = () => {
86
- setInputValue(oldInputValue => ({ ...oldInputValue,
87
- editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)({
88
- blocks: [],
89
- entityMap: {}
90
- }), decorators)
91
- }));
92
- };
93
-
94
- const onImageSelectorChange = selectedImagesWithMeta => {
95
- var _selectedImagesWithMe;
96
-
97
- const image = selectedImagesWithMeta === null || selectedImagesWithMeta === void 0 ? void 0 : (_selectedImagesWithMe = selectedImagesWithMeta[0]) === null || _selectedImagesWithMe === void 0 ? void 0 : _selectedImagesWithMe.image;
98
-
99
- if (!image) {
100
- setToShowImageSelector(false);
101
- return;
102
- }
103
-
104
- setInputValue(oldInputValue => ({ ...oldInputValue,
105
- image: image
106
- }));
107
- setToShowImageSelector(false);
108
- };
109
-
110
- const basicEditorJsx = renderBasicEditor({
111
- editorState: inputValue.editorStateOfBasicEditor,
112
- onChange: editorStateOfBasicEditor => {
113
- setInputValue(oldInputValue => ({ ...oldInputValue,
114
- editorStateOfBasicEditor
115
- }));
116
- }
117
- });
118
- (0, _react.useEffect)(() => {
119
- if (isOpen) {
120
- setInputValue(initialInputValue);
121
- }
122
- }, [isOpen]);
123
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, toShowImageSelector && /*#__PURE__*/_react.default.createElement(ImageSelector, {
124
- onChange: onImageSelectorChange
125
- }), /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
126
- isOpen: isOpen
127
- }, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
128
- title: `Insert Background Image`,
129
- actions: {
130
- cancel: {
131
- label: 'Cancel',
132
- action: () => {
133
- clearInputValue();
134
- onCancel();
135
- }
136
- },
137
- confirm: {
138
- label: 'Confirm',
139
- action: () => {
140
- onChange({
141
- textBlockAlign: inputValue.textBlockAlign,
142
- image: inputValue.image,
143
- // convert `contentState` of the `editorState` into raw content state object
144
- rawContentState: (0, _draftJs.convertToRaw)(inputValue.editorStateOfBasicEditor.getCurrentContent())
145
- });
146
- clearInputValue();
147
- }
148
- }
149
- }
150
- }, /*#__PURE__*/_react.default.createElement(Label, null, "\u5716\u7247"), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(ImageInputText, null, (_inputValue$image = inputValue.image) !== null && _inputValue$image !== void 0 && _inputValue$image.name ? inputValue.image.name : '尚未選取圖片'), /*#__PURE__*/_react.default.createElement(_button.Button, {
151
- type: "button",
152
- onClick: () => setToShowImageSelector(true),
153
- tone: "passive"
154
- }, "\u6DFB\u52A0\u5716\u7247")), /*#__PURE__*/_react.default.createElement(_alignSelector.AlignSelector, {
155
- align: inputValue.textBlockAlign,
156
- options: options,
157
- onChange: textBlockAlign => {
158
- setInputValue(oldInputValue => ({ ...oldInputValue,
159
- textBlockAlign
160
- }));
161
- }
162
- }), /*#__PURE__*/_react.default.createElement(Label, null, "\u5167\u6587"), basicEditorJsx)));
163
- }
164
-
165
- function BGImageButton(props) {
166
- const [toShowInput, setToShowInput] = (0, _react.useState)(false);
167
- const {
168
- className,
169
- editorState,
170
- onChange: onEditorStateChange,
171
- ImageSelector,
172
- renderBasicEditor
173
- } = props;
174
-
175
- const onChange = ({
176
- textBlockAlign,
177
- image,
178
- rawContentState
179
- }) => {
180
- const contentState = editorState.getCurrentContent(); // create an BGImage entity
181
-
182
- const contentStateWithEntity = contentState.createEntity('BACKGROUNDIMAGE', 'IMMUTABLE', {
183
- textBlockAlign,
184
- image,
185
- rawContentState,
186
- body: _draftConverter.default.convertToHtml(rawContentState)
187
- });
188
- const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
189
-
190
- const newEditorState = _draftJs.EditorState.set(editorState, {
191
- currentContent: contentStateWithEntity
192
- }); //The third parameter here is a space string, not an empty string
193
- //If you set an empty string, you will get an error: Unknown DraftEntity key: null
194
-
195
-
196
- onEditorStateChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
197
- setToShowInput(false);
198
- };
199
-
200
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(BGImageInput, {
201
- renderBasicEditor: renderBasicEditor,
202
- onChange: onChange,
203
- onCancel: () => {
204
- setToShowInput(false);
205
- },
206
- isOpen: toShowInput,
207
- ImageSelector: ImageSelector
208
- }), /*#__PURE__*/_react.default.createElement("div", {
209
- className: className,
210
- onClick: () => {
211
- setToShowInput(true);
212
- }
213
- }, /*#__PURE__*/_react.default.createElement("svg", {
214
- width: "16",
215
- height: "14",
216
- viewBox: "0 0 16 14",
217
- fill: "none",
218
- xmlns: "http://www.w3.org/2000/svg"
219
- }, /*#__PURE__*/_react.default.createElement("path", {
220
- d: "M7.42974 10.2188C7.01697 9.80208 6.81059 9.29167 6.81059 8.6875C6.81059 8.08333 7.02783 7.57292 7.46232 7.15625C7.89681 6.73958 8.41819 6.53125 9.02648 6.53125C9.65648 6.53125 10.1887 6.73958 10.6232 7.15625C11.0577 7.57292 11.2749 8.08333 11.2749 8.6875C11.2749 9.27083 11.0577 9.77083 10.6232 10.1875C10.1887 10.6042 9.65648 10.8125 9.02648 10.8125C8.39647 10.8125 7.86422 10.6146 7.42974 10.2188ZM6.58248 11.0312C7.25594 11.6771 8.0706 12 9.02648 12C9.98235 12 10.797 11.6771 11.4705 11.0312C12.1656 10.3854 12.5132 9.60417 12.5132 8.6875C12.5132 7.77083 12.1656 6.98958 11.4705 6.34375C10.797 5.67708 9.98235 5.34375 9.02648 5.34375C8.0706 5.34375 7.25594 5.67708 6.58248 6.34375C5.90903 6.98958 5.5723 7.77083 5.5723 8.6875C5.5723 9.60417 5.90903 10.3854 6.58248 11.0312ZM4.17108 6V4H6.25662V2H11.112L12.3829 3.34375H14.5988C14.9681 3.34375 15.294 3.47917 15.5764 3.75C15.8588 4.02083 16 4.33333 16 4.6875V12.6875C16 13.0417 15.8588 13.3542 15.5764 13.625C15.294 13.875 14.9681 14 14.5988 14H3.48676C3.11745 14 2.79158 13.875 2.50916 13.625C2.22675 13.3542 2.08554 13.0417 2.08554 12.6875V6H4.17108ZM2.08554 2V0H3.48676V2H5.5723V3.34375H3.48676V5.34375H2.08554V3.34375H0V2H2.08554Z",
221
- fill: "#6b7280"
222
- })), /*#__PURE__*/_react.default.createElement("span", null, "Background Image")));
223
- }
@@ -1,223 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.BGVideoButton = BGVideoButton;
7
- exports.BGVideoInput = BGVideoInput;
8
-
9
- var _react = _interopRequireWildcard(require("react"));
10
-
11
- var _draftJs = require("draft-js");
12
-
13
- var _modals = require("@keystone-ui/modals");
14
-
15
- var _button = require("@keystone-ui/button");
16
-
17
- var _draftConverter = _interopRequireDefault(require("../draft-converter"));
18
-
19
- var _styledComponents = _interopRequireDefault(require("styled-components"));
20
-
21
- var _videoSelector = require("./selector/video-selector");
22
-
23
- var _alignSelector = require("./selector/align-selector");
24
-
25
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
-
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
-
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
-
31
- const Label = _styledComponents.default.label`
32
- display: block;
33
- font-weight: 600;
34
- margin: 10px 0;
35
- `;
36
- const VideoInputText = _styledComponents.default.span`
37
- display: inline-block;
38
- margin-right: 10px;
39
- `;
40
-
41
- function BGVideoInput(props) {
42
- var _inputValue$video;
43
-
44
- const {
45
- isOpen,
46
- onChange,
47
- onCancel,
48
- textBlockAlign,
49
- video,
50
- rawContentStateForBGVideoEditor,
51
- VideoSelector = _videoSelector.VideoSelector,
52
- renderBasicEditor,
53
- decorators
54
- } = props;
55
- const rawContentState = rawContentStateForBGVideoEditor || {
56
- blocks: [],
57
- entityMap: {}
58
- };
59
- const options = [{
60
- value: 'fixed',
61
- label: 'fixed (default)',
62
- isDisabled: false
63
- }, {
64
- value: 'bottom',
65
- label: 'bottom',
66
- isDisabled: false
67
- }, {
68
- value: 'left',
69
- label: 'left',
70
- isDisabled: false
71
- }, {
72
- value: 'right',
73
- label: 'right',
74
- isDisabled: false
75
- }];
76
- const initialInputValue = {
77
- textBlockAlign: textBlockAlign || 'fixed',
78
- video: video || undefined,
79
- // create an `editorState` from raw content state object
80
- editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(rawContentState), decorators)
81
- };
82
- const [inputValue, setInputValue] = (0, _react.useState)(initialInputValue);
83
- const [toShowVideoSelector, setToShowVideoSelector] = (0, _react.useState)(false);
84
-
85
- const clearInputValue = () => {
86
- setInputValue(oldInputValue => ({ ...oldInputValue,
87
- editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)({
88
- blocks: [],
89
- entityMap: {}
90
- }), decorators)
91
- }));
92
- };
93
-
94
- const onVideoSelectorChange = selectedVideosWithMeta => {
95
- var _selectedVideosWithMe;
96
-
97
- const video = selectedVideosWithMeta === null || selectedVideosWithMeta === void 0 ? void 0 : (_selectedVideosWithMe = selectedVideosWithMeta[0]) === null || _selectedVideosWithMe === void 0 ? void 0 : _selectedVideosWithMe.video;
98
-
99
- if (!video) {
100
- setToShowVideoSelector(false);
101
- return;
102
- }
103
-
104
- setInputValue(oldInputValue => ({ ...oldInputValue,
105
- video: video
106
- }));
107
- setToShowVideoSelector(false);
108
- };
109
-
110
- const basicEditorJsx = renderBasicEditor({
111
- editorState: inputValue.editorStateOfBasicEditor,
112
- onChange: editorStateOfBasicEditor => {
113
- setInputValue(oldInputValue => ({ ...oldInputValue,
114
- editorStateOfBasicEditor
115
- }));
116
- }
117
- });
118
- (0, _react.useEffect)(() => {
119
- if (isOpen) {
120
- setInputValue(initialInputValue);
121
- }
122
- }, [isOpen]);
123
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, toShowVideoSelector && /*#__PURE__*/_react.default.createElement(VideoSelector, {
124
- onChange: onVideoSelectorChange
125
- }), /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
126
- isOpen: isOpen
127
- }, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
128
- title: `Insert Background Video`,
129
- actions: {
130
- cancel: {
131
- label: 'Cancel',
132
- action: () => {
133
- clearInputValue();
134
- onCancel();
135
- }
136
- },
137
- confirm: {
138
- label: 'Confirm',
139
- action: () => {
140
- onChange({
141
- textBlockAlign: inputValue.textBlockAlign,
142
- video: inputValue.video,
143
- // convert `contentState` of the `editorState` into raw content state object
144
- rawContentState: (0, _draftJs.convertToRaw)(inputValue.editorStateOfBasicEditor.getCurrentContent())
145
- });
146
- clearInputValue();
147
- }
148
- }
149
- }
150
- }, /*#__PURE__*/_react.default.createElement(Label, null, "\u5F71\u7247"), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(VideoInputText, null, (_inputValue$video = inputValue.video) !== null && _inputValue$video !== void 0 && _inputValue$video.name ? inputValue.video.name : '尚未選取影片'), /*#__PURE__*/_react.default.createElement(_button.Button, {
151
- type: "button",
152
- onClick: () => setToShowVideoSelector(true),
153
- tone: "passive"
154
- }, "\u6DFB\u52A0\u5F71\u7247")), /*#__PURE__*/_react.default.createElement(_alignSelector.AlignSelector, {
155
- align: inputValue.textBlockAlign,
156
- options: options,
157
- onChange: textBlockAlign => {
158
- setInputValue(oldInputValue => ({ ...oldInputValue,
159
- textBlockAlign
160
- }));
161
- }
162
- }), /*#__PURE__*/_react.default.createElement(Label, null, "\u5167\u6587"), basicEditorJsx)));
163
- }
164
-
165
- function BGVideoButton(props) {
166
- const [toShowInput, setToShowInput] = (0, _react.useState)(false);
167
- const {
168
- className,
169
- editorState,
170
- onChange: onEditorStateChange,
171
- VideoSelector,
172
- renderBasicEditor
173
- } = props;
174
-
175
- const onChange = ({
176
- textBlockAlign,
177
- video,
178
- rawContentState
179
- }) => {
180
- const contentState = editorState.getCurrentContent(); // create an BGVideo entity
181
-
182
- const contentStateWithEntity = contentState.createEntity('BACKGROUNDVIDEO', 'IMMUTABLE', {
183
- textBlockAlign,
184
- video,
185
- rawContentState,
186
- body: _draftConverter.default.convertToHtml(rawContentState)
187
- });
188
- const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
189
-
190
- const newEditorState = _draftJs.EditorState.set(editorState, {
191
- currentContent: contentStateWithEntity
192
- }); //The third parameter here is a space string, not an empty string
193
- //If you set an empty string, you will get an error: Unknown DraftEntity key: null
194
-
195
-
196
- onEditorStateChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
197
- setToShowInput(false);
198
- };
199
-
200
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(BGVideoInput, {
201
- renderBasicEditor: renderBasicEditor,
202
- onChange: onChange,
203
- onCancel: () => {
204
- setToShowInput(false);
205
- },
206
- isOpen: toShowInput,
207
- VideoSelector: VideoSelector
208
- }), /*#__PURE__*/_react.default.createElement("div", {
209
- className: className,
210
- onClick: () => {
211
- setToShowInput(true);
212
- }
213
- }, /*#__PURE__*/_react.default.createElement("svg", {
214
- width: "16",
215
- height: "10",
216
- viewBox: "0 0 16 10",
217
- fill: "none",
218
- xmlns: "http://www.w3.org/2000/svg"
219
- }, /*#__PURE__*/_react.default.createElement("path", {
220
- d: "M10.6667 1.25V8.75C10.6667 9.44036 10.0697 10 9.33333 10H1.33333C0.596944 10 0 9.44036 0 8.75V1.25C0 0.559635 0.596944 0 1.33333 0H9.33333C10.0694 0 10.6667 0.559635 10.6667 1.25ZM16 1.65365V8.34375C16 9.00781 15.1897 9.39557 14.6003 9.01536L11.5556 7.04948V2.95052L14.6 0.982812C15.1917 0.602344 16 0.992188 16 1.65365Z",
221
- fill: "#6b7280"
222
- })), /*#__PURE__*/_react.default.createElement("span", null, "Background Video")));
223
- }