@mirrormedia/lilith-draft-editor 3.0.8 → 3.0.10

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.
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VideoUploader = VideoUploader;
7
+
8
+ var _apollo = require("@keystone-6/core/admin-ui/apollo");
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ var _fileConvert = require("../utils/file-convert");
13
+
14
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
15
+
16
+ var _button = require("@keystone-ui/button");
17
+
18
+ var _modals = require("@keystone-ui/modals");
19
+
20
+ var _lodash = _interopRequireDefault(require("lodash"));
21
+
22
+ var _fields = require("@keystone-ui/fields");
23
+
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+
26
+ 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); }
27
+
28
+ 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; }
29
+
30
+ const videoMutation = (0, _apollo.gql)`
31
+ mutation AddVideo($data: VideoCreateInput!) {
32
+ video: createVideo(data: $data) {
33
+ id
34
+ name
35
+ videoSrc
36
+ youtubeUrl
37
+ file {
38
+ filename
39
+ filesize
40
+ url
41
+ }
42
+ heroImage {
43
+ id
44
+ name
45
+ imageFile {
46
+ url
47
+ }
48
+ resized {
49
+ original
50
+ }
51
+ }
52
+ }
53
+ }
54
+ `;
55
+ const CustomButton = (0, _styledComponents.default)(_button.Button)`
56
+ margin: 10px 0;
57
+ `;
58
+ const HiddenInput = _styledComponents.default.input`
59
+ display: none;
60
+ `;
61
+ const VideoWrapper = _styledComponents.default.div`
62
+ overflow: auto;
63
+ margin-top: 10px;
64
+ `;
65
+ const Video = _styledComponents.default.video`
66
+ width: 100%;
67
+ aspect-ratio: 2;
68
+ object-fit: contain;
69
+ `;
70
+ const VideoName = _styledComponents.default.p`
71
+ text-align: center;
72
+ `;
73
+ const Label = _styledComponents.default.label`
74
+ display: block;
75
+ margin: 10px 0;
76
+ font-weight: 600;
77
+ `;
78
+ const HintWrapper = _styledComponents.default.div`
79
+ margin: 10px 0;
80
+ `;
81
+
82
+ const AddVideo = ({
83
+ onAddVideo
84
+ }) => {
85
+ const inputRef = (0, _react.useRef)(null);
86
+
87
+ const inputChangeHandler = async event => {
88
+ const files = event.target.files;
89
+ event.target.files = null;
90
+ if (!files) return;
91
+ const videoFiles = await (0, _fileConvert.convertFilesToVideoData)(files);
92
+ onAddVideo(videoFiles[0]);
93
+ };
94
+
95
+ const onUploadButton = () => {
96
+ var _inputRef$current;
97
+
98
+ (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.click();
99
+ };
100
+
101
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(CustomButton, {
102
+ onClick: onUploadButton
103
+ }, "\u65B0\u589E\u5F71\u7247"), /*#__PURE__*/_react.default.createElement(HiddenInput, {
104
+ type: "file",
105
+ multiple: false,
106
+ accept: "video/*",
107
+ ref: inputRef,
108
+ onChange: inputChangeHandler
109
+ }));
110
+ };
111
+
112
+ function VideoUploader({
113
+ onChange
114
+ }) {
115
+ const [file, setFile] = (0, _react.useState)();
116
+ const [addVideo, {
117
+ data: uploadData,
118
+ loading: uploadLoading,
119
+ error: uploadError
120
+ }] = (0, _apollo.useMutation)(videoMutation);
121
+
122
+ const onAddVideo = file => {
123
+ setFile(file);
124
+ };
125
+
126
+ const onVideoNameChange = e => {
127
+ if (!file) return;
128
+ setFile({ ...file,
129
+ name: e.target.value
130
+ });
131
+ };
132
+
133
+ const onConfirm = async () => {
134
+ if (!file) return onChange();
135
+ const data = { ...file,
136
+ file: await (0, _fileConvert.convertStringToFile)(file.blobURL, file.name, file.type)
137
+ };
138
+ addVideo({
139
+ variables: {
140
+ data: {
141
+ name: data.name,
142
+ file: {
143
+ upload: data.file
144
+ }
145
+ }
146
+ }
147
+ });
148
+ };
149
+
150
+ (0, _react.useEffect)(() => {
151
+ if (uploadData !== null && uploadData !== void 0 && uploadData.video) {
152
+ onChange(uploadData.video);
153
+ }
154
+ }, [uploadData, onChange]);
155
+ return /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
156
+ isOpen: true
157
+ }, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
158
+ title: "Upload images",
159
+ actions: {
160
+ cancel: {
161
+ label: 'Cancel',
162
+ action: () => {
163
+ onChange();
164
+ }
165
+ },
166
+ confirm: {
167
+ label: 'Confirm',
168
+ action: onConfirm
169
+ }
170
+ },
171
+ width: "narrow"
172
+ }, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(AddVideo, {
173
+ onAddVideo: onAddVideo
174
+ }), file && /*#__PURE__*/_react.default.createElement(VideoWrapper, null, /*#__PURE__*/_react.default.createElement(Video, {
175
+ src: file === null || file === void 0 ? void 0 : file.blobURL,
176
+ muted: true,
177
+ loop: true,
178
+ controls: true,
179
+ autoPlay: true
180
+ }), /*#__PURE__*/_react.default.createElement(Label, {
181
+ htmlFor: "name"
182
+ }, "Video Name"), /*#__PURE__*/_react.default.createElement(_fields.TextInput, {
183
+ id: "name",
184
+ type: "text",
185
+ defaultValue: file.name,
186
+ onChange: _lodash.default.debounce(onVideoNameChange)
187
+ }), /*#__PURE__*/_react.default.createElement(VideoName, null, file.name)), uploadLoading && /*#__PURE__*/_react.default.createElement(HintWrapper, null, "loading"), uploadError && /*#__PURE__*/_react.default.createElement(HintWrapper, null, uploadError.message))));
188
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertBlobToString = convertBlobToString;
7
+ exports.convertFilesToImageData = convertFilesToImageData;
8
+ exports.convertFilesToVideoData = convertFilesToVideoData;
9
+ exports.convertStringToFile = convertStringToFile;
10
+
11
+ var _jsSha = require("js-sha256");
12
+
13
+ async function convertFilesToMediaData(fileList, isValidFile, wrapResult) {
14
+ const files = Array.from(fileList);
15
+ const fileNamePostfix = new Intl.DateTimeFormat('fr-CA', {
16
+ year: 'numeric',
17
+ month: '2-digit',
18
+ day: '2-digit'
19
+ }).format(Date.now());
20
+ const tasks = files.map(async file => {
21
+ if (!isValidFile(file)) return;
22
+ const uInt8Data = await file.arrayBuffer();
23
+ const name = file.name;
24
+ const positionOfLastDot = name.lastIndexOf('.');
25
+ const filename = positionOfLastDot > -1 ? `${name.slice(0, positionOfLastDot)}_${fileNamePostfix}${name.slice(positionOfLastDot)}` : `${name}_${fileNamePostfix}`;
26
+ return wrapResult({
27
+ uid: (0, _jsSha.sha256)(uInt8Data),
28
+ name: filename,
29
+ type: file.type,
30
+ blobURL: convertBlobToString(file)
31
+ });
32
+ });
33
+ const results = await Promise.allSettled(tasks);
34
+ return results.filter(r => r.status === 'fulfilled').map(r => r.value).filter(r => Boolean(r));
35
+ }
36
+
37
+ function isImageFile(file) {
38
+ return file.type.startsWith('image/');
39
+ }
40
+
41
+ async function convertFilesToImageData(fileList) {
42
+ return convertFilesToMediaData(fileList, isImageFile, ({
43
+ uid,
44
+ name,
45
+ type,
46
+ blobURL
47
+ }) => ({
48
+ uid,
49
+ name,
50
+ type,
51
+ blobURL
52
+ }));
53
+ }
54
+
55
+ async function convertFilesToVideoData(fileList) {
56
+ return convertFilesToMediaData(fileList, isVideoFile, ({
57
+ uid,
58
+ name,
59
+ type,
60
+ blobURL
61
+ }) => ({
62
+ uid,
63
+ name,
64
+ type,
65
+ blobURL
66
+ }));
67
+ }
68
+
69
+ function isVideoFile(file) {
70
+ return file.type.startsWith('video/');
71
+ }
72
+
73
+ function blobToFile(blob, fileName, extension) {
74
+ return new File([blob], fileName, {
75
+ type: extension
76
+ });
77
+ }
78
+
79
+ function convertBlobToString(blob) {
80
+ return URL.createObjectURL(blob);
81
+ }
82
+
83
+ async function convertStringToFile(str, fileName, extension) {
84
+ const request = new Request(str);
85
+ return await fetch(request).then(response => response.blob()).then(blob => blobToFile(blob, fileName, extension ?? blob.type));
86
+ }
@@ -352,6 +352,10 @@ const DraftEditorControlsWrapper = _styledComponents.default.div`
352
352
  flex-wrap: wrap;
353
353
  padding-right: 45px;
354
354
  column-gap: 5px;
355
+
356
+ @media (max-width: 767px) {
357
+ padding-right: 10px;
358
+ }
355
359
  `;
356
360
  const TextEditorWrapper = _styledComponents.default.div`
357
361
  /* Rich-editor default setting (.RichEditor-editor)*/
@@ -436,8 +440,15 @@ const DraftEditorContainer = _styledComponents.default.div`
436
440
  padding-bottom: 0;
437
441
  ` : ''}
438
442
  }
439
- `; // const ButtonGroup = styled.div``
440
-
443
+ `;
444
+ const ButtonGroup = _styledComponents.default.div`
445
+ margin: 0;
446
+ ${({
447
+ isDisabled
448
+ }) => isDisabled ? (0, _styledComponents.css)`
449
+ display: none;
450
+ ` : ''}
451
+ `;
441
452
  const EnlargeButtonWrapper = _styledComponents.default.div`
442
453
  position: absolute;
443
454
  top: 0;
@@ -708,23 +719,31 @@ const RichTextEditor = ({
708
719
  }), /*#__PURE__*/_react.default.createElement(EnlargeButtonWrapper, null, /*#__PURE__*/_react.default.createElement(CustomEnlargeButton, {
709
720
  onToggle: toggleEnlarge,
710
721
  isEnlarged: isEnlarged
711
- }))), /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(CustomLinkButton, {
722
+ }))), /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(ButtonGroup, {
723
+ isDisabled: disabledButtons.includes(buttonNames.link)
724
+ }, /*#__PURE__*/_react.default.createElement(CustomLinkButton, {
712
725
  isDisabled: checkIsDisabled(buttonNames.link),
713
726
  isActive: entityType === 'LINK',
714
727
  readOnly: readOnly,
715
728
  editorState: editorState,
716
729
  onChange: onChange
717
- }), /*#__PURE__*/_react.default.createElement(CustomFontColorButton, {
730
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
731
+ isDisabled: disabledButtons.includes(buttonNames.fontColor)
732
+ }, /*#__PURE__*/_react.default.createElement(CustomFontColorButton, {
718
733
  isDisabled: checkIsDisabled(buttonNames.fontColor),
719
734
  isActive: Object.prototype.hasOwnProperty.call(customStyle, 'color'),
720
735
  readOnly: readOnly,
721
736
  editorState: editorState,
722
737
  onChange: onChange
723
- }), /*#__PURE__*/_react.default.createElement(CustomDividerButton, {
738
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
739
+ isDisabled: disabledButtons.includes(buttonNames.divider)
740
+ }, /*#__PURE__*/_react.default.createElement(CustomDividerButton, {
724
741
  isDisabled: checkIsDisabled(buttonNames.divider),
725
742
  editorState: editorState,
726
743
  onChange: onChange
727
- }), /*#__PURE__*/_react.default.createElement(CustomAnnotationButton, {
744
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
745
+ isDisabled: disabledButtons.includes(buttonNames.annotation)
746
+ }, /*#__PURE__*/_react.default.createElement(CustomAnnotationButton, {
728
747
  isDisabled: checkIsDisabled(buttonNames.annotation),
729
748
  isActive: entityType === 'ANNOTATION',
730
749
  readOnly: readOnly,
@@ -732,78 +751,104 @@ const RichTextEditor = ({
732
751
  onChange: onChange,
733
752
  renderBasicEditor: renderBasicEditor,
734
753
  decorators: _entityDecorator.default
735
- }), /*#__PURE__*/_react.default.createElement(CustomImageButton, {
754
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
755
+ isDisabled: disabledButtons.includes(buttonNames.image)
756
+ }, /*#__PURE__*/_react.default.createElement(CustomImageButton, {
736
757
  isDisabled: checkIsDisabled(buttonNames.image),
737
758
  readOnly: readOnly,
738
759
  editorState: editorState,
739
760
  onChange: onChange,
740
761
  ImageSelector: _imageSelector.ImageSelector
741
- }), /*#__PURE__*/_react.default.createElement(CustomVideoButton, {
762
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
763
+ isDisabled: disabledButtons.includes(buttonNames.video)
764
+ }, /*#__PURE__*/_react.default.createElement(CustomVideoButton, {
742
765
  isDisabled: checkIsDisabled(buttonNames.video),
743
766
  readOnly: readOnly,
744
767
  editorState: editorState,
745
768
  onChange: onChange,
746
769
  VideoSelector: _videoSelector.VideoSelector
747
- }), /*#__PURE__*/_react.default.createElement(CustomYoutubeButton, {
770
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
771
+ isDisabled: disabledButtons.includes(buttonNames.youtube)
772
+ }, /*#__PURE__*/_react.default.createElement(CustomYoutubeButton, {
748
773
  isDisabled: checkIsDisabled(buttonNames.youtube),
749
774
  readOnly: readOnly,
750
775
  editorState: editorState,
751
776
  onChange: onChange
752
- }), /*#__PURE__*/_react.default.createElement(CustomAudioButton, {
777
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
778
+ isDisabled: disabledButtons.includes(buttonNames.audio)
779
+ }, /*#__PURE__*/_react.default.createElement(CustomAudioButton, {
753
780
  isDisabled: checkIsDisabled(buttonNames.audio),
754
781
  readOnly: readOnly,
755
782
  editorState: editorState,
756
783
  onChange: onChange,
757
784
  AudioSelector: _audioSelector.AudioSelector
758
- }), /*#__PURE__*/_react.default.createElement(CustomSlideshowButton, {
785
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
786
+ isDisabled: disabledButtons.includes(buttonNames.slideshow)
787
+ }, /*#__PURE__*/_react.default.createElement(CustomSlideshowButton, {
759
788
  isDisabled: checkIsDisabled(buttonNames.slideshow),
760
789
  readOnly: readOnly,
761
790
  editorState: editorState,
762
791
  onChange: onChange,
763
792
  ImageSelector: _imageSelector.ImageSelector
764
- }), /*#__PURE__*/_react.default.createElement(CustomInfoBoxButton, {
793
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
794
+ isDisabled: disabledButtons.includes(buttonNames.infoBox)
795
+ }, /*#__PURE__*/_react.default.createElement(CustomInfoBoxButton, {
765
796
  isDisabled: checkIsDisabled(buttonNames.infoBox),
766
797
  readOnly: readOnly,
767
798
  editorState: editorState,
768
799
  onChange: onChange,
769
800
  renderBasicEditor: renderBasicEditor // decorators={decorators}
770
801
 
771
- }), /*#__PURE__*/_react.default.createElement(CustomEmbeddedCodeButton, {
802
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
803
+ isDisabled: disabledButtons.includes(buttonNames.embed)
804
+ }, /*#__PURE__*/_react.default.createElement(CustomEmbeddedCodeButton, {
772
805
  isDisabled: checkIsDisabled(buttonNames.embed),
773
806
  readOnly: readOnly,
774
807
  editorState: editorState,
775
808
  onChange: onChange
776
- }), /*#__PURE__*/_react.default.createElement(CustomTableButton, {
809
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
810
+ isDisabled: disabledButtons.includes(buttonNames.table)
811
+ }, /*#__PURE__*/_react.default.createElement(CustomTableButton, {
777
812
  isDisabled: checkIsDisabled(buttonNames.table),
778
813
  readOnly: readOnly,
779
814
  editorState: editorState,
780
815
  onChange: onChange
781
- })), /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(CustomAlignLeftButton, {
816
+ }))), /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(ButtonGroup, {
817
+ isDisabled: disabledButtons.includes(buttonNames.textAlign)
818
+ }, /*#__PURE__*/_react.default.createElement(CustomAlignLeftButton, {
782
819
  isDisabled: checkIsDisabled(buttonNames.textAlign),
783
820
  isActive: (0, _textAlign.getSelectionBlockData)(editorState, 'textAlign') === 'left',
784
821
  readOnly: readOnly,
785
822
  editorState: editorState,
786
823
  onChange: onChange
787
- }), /*#__PURE__*/_react.default.createElement(CustomAlignCenterButton, {
824
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
825
+ isDisabled: disabledButtons.includes(buttonNames.textAlign)
826
+ }, /*#__PURE__*/_react.default.createElement(CustomAlignCenterButton, {
788
827
  isDisabled: checkIsDisabled(buttonNames.textAlign),
789
828
  isActive: (0, _textAlign.getSelectionBlockData)(editorState, 'textAlign') === 'center',
790
829
  readOnly: readOnly,
791
830
  editorState: editorState,
792
831
  onChange: onChange
793
- }), /*#__PURE__*/_react.default.createElement(CustomColorBoxButton, {
832
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
833
+ isDisabled: disabledButtons.includes(buttonNames.colorBox)
834
+ }, /*#__PURE__*/_react.default.createElement(CustomColorBoxButton, {
794
835
  isDisabled: checkIsDisabled(buttonNames.colorBox),
795
836
  readOnly: readOnly,
796
837
  editorState: editorState,
797
838
  onChange: onChange,
798
839
  renderBasicEditor: renderBasicEditor // decorators={decorators}
799
840
 
800
- }), /*#__PURE__*/_react.default.createElement(CustomBackgroundColorButton, {
841
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
842
+ isDisabled: disabledButtons.includes(buttonNames.backgroundColor)
843
+ }, /*#__PURE__*/_react.default.createElement(CustomBackgroundColorButton, {
801
844
  isDisabled: checkIsDisabled(buttonNames.backgroundColor),
802
845
  isActive: Object.prototype.hasOwnProperty.call(customStyle, 'backgroundColor'),
803
846
  readOnly: readOnly,
804
847
  editorState: editorState,
805
848
  onChange: onChange
806
- }), /*#__PURE__*/_react.default.createElement(CustomBGImageButton, {
849
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
850
+ isDisabled: disabledButtons.includes(buttonNames.backgroundImage)
851
+ }, /*#__PURE__*/_react.default.createElement(CustomBGImageButton, {
807
852
  isDisabled: checkIsDisabled(buttonNames.backgroundImage),
808
853
  readOnly: readOnly,
809
854
  editorState: editorState,
@@ -811,7 +856,9 @@ const RichTextEditor = ({
811
856
  ImageSelector: _imageSelector.ImageSelector,
812
857
  renderBasicEditor: renderBasicEditor,
813
858
  decorators: _entityDecorator.default
814
- }), /*#__PURE__*/_react.default.createElement(CustomBGVideoButton, {
859
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
860
+ isDisabled: disabledButtons.includes(buttonNames.backgroundVideo)
861
+ }, /*#__PURE__*/_react.default.createElement(CustomBGVideoButton, {
815
862
  isDisabled: checkIsDisabled(buttonNames.backgroundVideo),
816
863
  readOnly: readOnly,
817
864
  editorState: editorState,
@@ -819,18 +866,22 @@ const RichTextEditor = ({
819
866
  VideoSelector: _videoSelector.VideoSelector,
820
867
  renderBasicEditor: renderBasicEditor,
821
868
  decorators: _entityDecorator.default
822
- }), /*#__PURE__*/_react.default.createElement(CustomRelatedPostButton, {
869
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
870
+ isDisabled: disabledButtons.includes(buttonNames.relatedPost)
871
+ }, /*#__PURE__*/_react.default.createElement(CustomRelatedPostButton, {
823
872
  isDisabled: checkIsDisabled(buttonNames.relatedPost),
824
873
  readOnly: readOnly,
825
874
  editorState: editorState,
826
875
  onChange: onChange,
827
876
  PostSelector: _postSelector.PostSelector
828
- }), /*#__PURE__*/_react.default.createElement(CustomSideIndexButton, {
877
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
878
+ isDisabled: disabledButtons.includes(buttonNames.sideIndex)
879
+ }, /*#__PURE__*/_react.default.createElement(CustomSideIndexButton, {
829
880
  isDisabled: checkIsDisabled(buttonNames.sideIndex),
830
881
  readOnly: readOnly,
831
882
  editorState: editorState,
832
883
  onChange: onChange
833
- }))), /*#__PURE__*/_react.default.createElement(TextEditorWrapper, {
884
+ })))), /*#__PURE__*/_react.default.createElement(TextEditorWrapper, {
834
885
  onClick: () => {
835
886
  var _editorRef$current;
836
887
 
@@ -9,7 +9,7 @@ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _debounce = _interopRequireDefault(require("lodash/debounce"));
11
11
 
12
- var _styledComponents = _interopRequireDefault(require("styled-components"));
12
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
13
13
 
14
14
  var _fields = require("@keystone-ui/fields");
15
15
 
@@ -23,6 +23,10 @@ var _searchBox = require("./search-box");
23
23
 
24
24
  var _pagination = require("./pagination");
25
25
 
26
+ var _button = require("@keystone-ui/button");
27
+
28
+ var _imageUploader = require("./image-uploader");
29
+
26
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
31
 
28
32
  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); }
@@ -67,9 +71,19 @@ const imagesQuery = (0, _apollo.gql)`
67
71
  const _ = {
68
72
  debounce: _debounce.default
69
73
  };
74
+ const GlobalStyle = (0, _styledComponents.createGlobalStyle)`
75
+ form {
76
+ @media (max-width: 575px) {
77
+ width: 100vw !important;
78
+ }
79
+ }
80
+ `;
70
81
  const ImageSearchBox = (0, _styledComponents.default)(_searchBox.SearchBox)`
71
82
  margin-top: 10px;
72
83
  `;
84
+ const CustomButton = (0, _styledComponents.default)(_button.Button)`
85
+ margin-top: 10px;
86
+ `;
73
87
  const ImageSelectionWrapper = _styledComponents.default.div`
74
88
  overflow: auto;
75
89
  margin-top: 10px;
@@ -82,7 +96,7 @@ const ImageGridsWrapper = _styledComponents.default.div`
82
96
  margin-top: 5px;
83
97
  `;
84
98
  const ImageGridWrapper = _styledComponents.default.div`
85
- flex: 0 0 33.3333%;
99
+ width: 33.3333%;
86
100
  cursor: pointer;
87
101
  padding: 0 10px 10px;
88
102
  `;
@@ -92,7 +106,7 @@ const ImageMetaGridsWrapper = _styledComponents.default.div`
92
106
  overflow: auto;
93
107
  `;
94
108
  const ImageMetaGridWrapper = _styledComponents.default.div`
95
- flex: 0 0 33.3333%;
109
+ width: 100%;
96
110
  cursor: pointer;
97
111
  padding: 0 10px 10px;
98
112
  `;
@@ -107,6 +121,9 @@ const Label = _styledComponents.default.label`
107
121
  margin: 10px 0;
108
122
  font-weight: 600;
109
123
  `;
124
+ const StyledTextInput = (0, _styledComponents.default)(_fields.TextInput)`
125
+ width: 100%;
126
+ `;
110
127
  const SeparationLine = _styledComponents.default.div`
111
128
  border: #e1e5e9 1px solid;
112
129
  margin-top: 10px;
@@ -206,7 +223,7 @@ function ImageMetaGrid(props) {
206
223
  }
207
224
  }), /*#__PURE__*/_react.default.createElement(ImageName, null, image === null || image === void 0 ? void 0 : image.name), enableCaption && /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(Label, {
208
225
  htmlFor: "caption"
209
- }, "Image Caption:"), /*#__PURE__*/_react.default.createElement(_fields.TextInput, {
226
+ }, "Image Caption:"), /*#__PURE__*/_react.default.createElement(StyledTextInput, {
210
227
  id: "caption",
211
228
  type: "text",
212
229
  placeholder: image === null || image === void 0 ? void 0 : image.name,
@@ -220,7 +237,7 @@ function ImageMetaGrid(props) {
220
237
  })
221
238
  })), enableUrl && /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(Label, {
222
239
  htmlFor: "url"
223
- }, "Url:"), /*#__PURE__*/_react.default.createElement(_fields.TextInput, {
240
+ }, "Url:"), /*#__PURE__*/_react.default.createElement(StyledTextInput, {
224
241
  id: "url",
225
242
  type: "text",
226
243
  placeholder: "(Optional)",
@@ -280,6 +297,7 @@ function ImageSelector(props) {
280
297
  const [selected, setSelected] = (0, _react.useState)(initialSelected);
281
298
  const [delay, setDelay] = (0, _react.useState)(initialDelay ?? '5');
282
299
  const [align, setAlign] = (0, _react.useState)(initialAlign);
300
+ const [showImageUploader, setShowImageUploader] = (0, _react.useState)(false);
283
301
  const contentWrapperRef = (0, _react.useRef)(null);
284
302
  const pageSize = 18;
285
303
  const options = [{
@@ -329,6 +347,15 @@ function ImageSelector(props) {
329
347
  }
330
348
  };
331
349
 
350
+ const onImageUploaderChange = images => {
351
+ setSelected(prev => prev.concat(images.map(image => ({
352
+ image,
353
+ desc: '',
354
+ url: ''
355
+ }))));
356
+ setShowImageUploader(false);
357
+ };
358
+
332
359
  const onImageMetaChange = imageEntityWithMeta => {
333
360
  if (enableMultiSelect) {
334
361
  const foundIndex = selected.findIndex(ele => {
@@ -414,10 +441,10 @@ function ImageSelector(props) {
414
441
  searchResult = /*#__PURE__*/_react.default.createElement(ErrorWrapper, null, /*#__PURE__*/_react.default.createElement("h3", null, "Errors occurs in the `images` query"), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("b", null, "Message:"), /*#__PURE__*/_react.default.createElement("div", null, error.message), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("b", null, "Stack:"), /*#__PURE__*/_react.default.createElement("div", null, error.stack), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("b", null, "Query:"), /*#__PURE__*/_react.default.createElement("pre", null, imagesQuery === null || imagesQuery === void 0 ? void 0 : (_imagesQuery$loc = imagesQuery.loc) === null || _imagesQuery$loc === void 0 ? void 0 : (_imagesQuery$loc$sour = _imagesQuery$loc.source) === null || _imagesQuery$loc$sour === void 0 ? void 0 : _imagesQuery$loc$sour.body)));
415
442
  }
416
443
 
417
- return /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
444
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(GlobalStyle, null), /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
418
445
  isOpen: true
419
446
  }, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
420
- title: "Select image",
447
+ title: "Select images",
421
448
  actions: {
422
449
  cancel: {
423
450
  label: 'Cancel',
@@ -427,10 +454,13 @@ function ImageSelector(props) {
427
454
  label: 'Confirm',
428
455
  action: onSave
429
456
  }
430
- }
457
+ },
458
+ width: "narrow"
431
459
  }, /*#__PURE__*/_react.default.createElement("div", {
432
460
  ref: contentWrapperRef
433
- }, /*#__PURE__*/_react.default.createElement(ImageSearchBox, {
461
+ }, /*#__PURE__*/_react.default.createElement(CustomButton, {
462
+ onClick: () => setShowImageUploader(true)
463
+ }, "\u4E0A\u50B3\u5716\u7247"), /*#__PURE__*/_react.default.createElement(ImageSearchBox, {
434
464
  onChange: onSearchBoxChange
435
465
  }), /*#__PURE__*/_react.default.createElement(ImageSelectionWrapper, null, /*#__PURE__*/_react.default.createElement("div", null, searchResult), !!selected.length && /*#__PURE__*/_react.default.createElement(SeparationLine, null), /*#__PURE__*/_react.default.createElement(ImageMetaGrids, {
436
466
  imageMetas: selected,
@@ -447,5 +477,7 @@ function ImageSelector(props) {
447
477
  options: options,
448
478
  onChange: onAlignSelectChange,
449
479
  onOpen: onAlignSelectOpen
450
- })))));
480
+ }))))), showImageUploader && /*#__PURE__*/_react.default.createElement(_imageUploader.ImageUploader, {
481
+ onChange: onImageUploaderChange
482
+ }));
451
483
  }