@mirrormedia/lilith-draft-editor 3.0.8 → 3.0.9

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
+ }
@@ -436,8 +436,15 @@ const DraftEditorContainer = _styledComponents.default.div`
436
436
  padding-bottom: 0;
437
437
  ` : ''}
438
438
  }
439
- `; // const ButtonGroup = styled.div``
440
-
439
+ `;
440
+ const ButtonGroup = _styledComponents.default.div`
441
+ margin: 0 10px 0 0;
442
+ ${({
443
+ isDisabled
444
+ }) => isDisabled ? (0, _styledComponents.css)`
445
+ display: none;
446
+ ` : ''}
447
+ `;
441
448
  const EnlargeButtonWrapper = _styledComponents.default.div`
442
449
  position: absolute;
443
450
  top: 0;
@@ -708,23 +715,31 @@ const RichTextEditor = ({
708
715
  }), /*#__PURE__*/_react.default.createElement(EnlargeButtonWrapper, null, /*#__PURE__*/_react.default.createElement(CustomEnlargeButton, {
709
716
  onToggle: toggleEnlarge,
710
717
  isEnlarged: isEnlarged
711
- }))), /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(CustomLinkButton, {
718
+ }))), /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(ButtonGroup, {
719
+ isDisabled: disabledButtons.includes(buttonNames.link)
720
+ }, /*#__PURE__*/_react.default.createElement(CustomLinkButton, {
712
721
  isDisabled: checkIsDisabled(buttonNames.link),
713
722
  isActive: entityType === 'LINK',
714
723
  readOnly: readOnly,
715
724
  editorState: editorState,
716
725
  onChange: onChange
717
- }), /*#__PURE__*/_react.default.createElement(CustomFontColorButton, {
726
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
727
+ isDisabled: disabledButtons.includes(buttonNames.fontColor)
728
+ }, /*#__PURE__*/_react.default.createElement(CustomFontColorButton, {
718
729
  isDisabled: checkIsDisabled(buttonNames.fontColor),
719
730
  isActive: Object.prototype.hasOwnProperty.call(customStyle, 'color'),
720
731
  readOnly: readOnly,
721
732
  editorState: editorState,
722
733
  onChange: onChange
723
- }), /*#__PURE__*/_react.default.createElement(CustomDividerButton, {
734
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
735
+ isDisabled: disabledButtons.includes(buttonNames.divider)
736
+ }, /*#__PURE__*/_react.default.createElement(CustomDividerButton, {
724
737
  isDisabled: checkIsDisabled(buttonNames.divider),
725
738
  editorState: editorState,
726
739
  onChange: onChange
727
- }), /*#__PURE__*/_react.default.createElement(CustomAnnotationButton, {
740
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
741
+ isDisabled: disabledButtons.includes(buttonNames.annotation)
742
+ }, /*#__PURE__*/_react.default.createElement(CustomAnnotationButton, {
728
743
  isDisabled: checkIsDisabled(buttonNames.annotation),
729
744
  isActive: entityType === 'ANNOTATION',
730
745
  readOnly: readOnly,
@@ -732,78 +747,104 @@ const RichTextEditor = ({
732
747
  onChange: onChange,
733
748
  renderBasicEditor: renderBasicEditor,
734
749
  decorators: _entityDecorator.default
735
- }), /*#__PURE__*/_react.default.createElement(CustomImageButton, {
750
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
751
+ isDisabled: disabledButtons.includes(buttonNames.image)
752
+ }, /*#__PURE__*/_react.default.createElement(CustomImageButton, {
736
753
  isDisabled: checkIsDisabled(buttonNames.image),
737
754
  readOnly: readOnly,
738
755
  editorState: editorState,
739
756
  onChange: onChange,
740
757
  ImageSelector: _imageSelector.ImageSelector
741
- }), /*#__PURE__*/_react.default.createElement(CustomVideoButton, {
758
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
759
+ isDisabled: disabledButtons.includes(buttonNames.video)
760
+ }, /*#__PURE__*/_react.default.createElement(CustomVideoButton, {
742
761
  isDisabled: checkIsDisabled(buttonNames.video),
743
762
  readOnly: readOnly,
744
763
  editorState: editorState,
745
764
  onChange: onChange,
746
765
  VideoSelector: _videoSelector.VideoSelector
747
- }), /*#__PURE__*/_react.default.createElement(CustomYoutubeButton, {
766
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
767
+ isDisabled: disabledButtons.includes(buttonNames.youtube)
768
+ }, /*#__PURE__*/_react.default.createElement(CustomYoutubeButton, {
748
769
  isDisabled: checkIsDisabled(buttonNames.youtube),
749
770
  readOnly: readOnly,
750
771
  editorState: editorState,
751
772
  onChange: onChange
752
- }), /*#__PURE__*/_react.default.createElement(CustomAudioButton, {
773
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
774
+ isDisabled: disabledButtons.includes(buttonNames.audio)
775
+ }, /*#__PURE__*/_react.default.createElement(CustomAudioButton, {
753
776
  isDisabled: checkIsDisabled(buttonNames.audio),
754
777
  readOnly: readOnly,
755
778
  editorState: editorState,
756
779
  onChange: onChange,
757
780
  AudioSelector: _audioSelector.AudioSelector
758
- }), /*#__PURE__*/_react.default.createElement(CustomSlideshowButton, {
781
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
782
+ isDisabled: disabledButtons.includes(buttonNames.slideshow)
783
+ }, /*#__PURE__*/_react.default.createElement(CustomSlideshowButton, {
759
784
  isDisabled: checkIsDisabled(buttonNames.slideshow),
760
785
  readOnly: readOnly,
761
786
  editorState: editorState,
762
787
  onChange: onChange,
763
788
  ImageSelector: _imageSelector.ImageSelector
764
- }), /*#__PURE__*/_react.default.createElement(CustomInfoBoxButton, {
789
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
790
+ isDisabled: disabledButtons.includes(buttonNames.infoBox)
791
+ }, /*#__PURE__*/_react.default.createElement(CustomInfoBoxButton, {
765
792
  isDisabled: checkIsDisabled(buttonNames.infoBox),
766
793
  readOnly: readOnly,
767
794
  editorState: editorState,
768
795
  onChange: onChange,
769
796
  renderBasicEditor: renderBasicEditor // decorators={decorators}
770
797
 
771
- }), /*#__PURE__*/_react.default.createElement(CustomEmbeddedCodeButton, {
798
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
799
+ isDisabled: disabledButtons.includes(buttonNames.embed)
800
+ }, /*#__PURE__*/_react.default.createElement(CustomEmbeddedCodeButton, {
772
801
  isDisabled: checkIsDisabled(buttonNames.embed),
773
802
  readOnly: readOnly,
774
803
  editorState: editorState,
775
804
  onChange: onChange
776
- }), /*#__PURE__*/_react.default.createElement(CustomTableButton, {
805
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
806
+ isDisabled: disabledButtons.includes(buttonNames.table)
807
+ }, /*#__PURE__*/_react.default.createElement(CustomTableButton, {
777
808
  isDisabled: checkIsDisabled(buttonNames.table),
778
809
  readOnly: readOnly,
779
810
  editorState: editorState,
780
811
  onChange: onChange
781
- })), /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(CustomAlignLeftButton, {
812
+ }))), /*#__PURE__*/_react.default.createElement(DraftEditorControlsWrapper, null, /*#__PURE__*/_react.default.createElement(ButtonGroup, {
813
+ isDisabled: disabledButtons.includes(buttonNames.textAlign)
814
+ }, /*#__PURE__*/_react.default.createElement(CustomAlignLeftButton, {
782
815
  isDisabled: checkIsDisabled(buttonNames.textAlign),
783
816
  isActive: (0, _textAlign.getSelectionBlockData)(editorState, 'textAlign') === 'left',
784
817
  readOnly: readOnly,
785
818
  editorState: editorState,
786
819
  onChange: onChange
787
- }), /*#__PURE__*/_react.default.createElement(CustomAlignCenterButton, {
820
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
821
+ isDisabled: disabledButtons.includes(buttonNames.textAlign)
822
+ }, /*#__PURE__*/_react.default.createElement(CustomAlignCenterButton, {
788
823
  isDisabled: checkIsDisabled(buttonNames.textAlign),
789
824
  isActive: (0, _textAlign.getSelectionBlockData)(editorState, 'textAlign') === 'center',
790
825
  readOnly: readOnly,
791
826
  editorState: editorState,
792
827
  onChange: onChange
793
- }), /*#__PURE__*/_react.default.createElement(CustomColorBoxButton, {
828
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
829
+ isDisabled: disabledButtons.includes(buttonNames.colorBox)
830
+ }, /*#__PURE__*/_react.default.createElement(CustomColorBoxButton, {
794
831
  isDisabled: checkIsDisabled(buttonNames.colorBox),
795
832
  readOnly: readOnly,
796
833
  editorState: editorState,
797
834
  onChange: onChange,
798
835
  renderBasicEditor: renderBasicEditor // decorators={decorators}
799
836
 
800
- }), /*#__PURE__*/_react.default.createElement(CustomBackgroundColorButton, {
837
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
838
+ isDisabled: disabledButtons.includes(buttonNames.backgroundColor)
839
+ }, /*#__PURE__*/_react.default.createElement(CustomBackgroundColorButton, {
801
840
  isDisabled: checkIsDisabled(buttonNames.backgroundColor),
802
841
  isActive: Object.prototype.hasOwnProperty.call(customStyle, 'backgroundColor'),
803
842
  readOnly: readOnly,
804
843
  editorState: editorState,
805
844
  onChange: onChange
806
- }), /*#__PURE__*/_react.default.createElement(CustomBGImageButton, {
845
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
846
+ isDisabled: disabledButtons.includes(buttonNames.backgroundImage)
847
+ }, /*#__PURE__*/_react.default.createElement(CustomBGImageButton, {
807
848
  isDisabled: checkIsDisabled(buttonNames.backgroundImage),
808
849
  readOnly: readOnly,
809
850
  editorState: editorState,
@@ -811,7 +852,9 @@ const RichTextEditor = ({
811
852
  ImageSelector: _imageSelector.ImageSelector,
812
853
  renderBasicEditor: renderBasicEditor,
813
854
  decorators: _entityDecorator.default
814
- }), /*#__PURE__*/_react.default.createElement(CustomBGVideoButton, {
855
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
856
+ isDisabled: disabledButtons.includes(buttonNames.backgroundVideo)
857
+ }, /*#__PURE__*/_react.default.createElement(CustomBGVideoButton, {
815
858
  isDisabled: checkIsDisabled(buttonNames.backgroundVideo),
816
859
  readOnly: readOnly,
817
860
  editorState: editorState,
@@ -819,18 +862,22 @@ const RichTextEditor = ({
819
862
  VideoSelector: _videoSelector.VideoSelector,
820
863
  renderBasicEditor: renderBasicEditor,
821
864
  decorators: _entityDecorator.default
822
- }), /*#__PURE__*/_react.default.createElement(CustomRelatedPostButton, {
865
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
866
+ isDisabled: disabledButtons.includes(buttonNames.relatedPost)
867
+ }, /*#__PURE__*/_react.default.createElement(CustomRelatedPostButton, {
823
868
  isDisabled: checkIsDisabled(buttonNames.relatedPost),
824
869
  readOnly: readOnly,
825
870
  editorState: editorState,
826
871
  onChange: onChange,
827
872
  PostSelector: _postSelector.PostSelector
828
- }), /*#__PURE__*/_react.default.createElement(CustomSideIndexButton, {
873
+ })), /*#__PURE__*/_react.default.createElement(ButtonGroup, {
874
+ isDisabled: disabledButtons.includes(buttonNames.sideIndex)
875
+ }, /*#__PURE__*/_react.default.createElement(CustomSideIndexButton, {
829
876
  isDisabled: checkIsDisabled(buttonNames.sideIndex),
830
877
  readOnly: readOnly,
831
878
  editorState: editorState,
832
879
  onChange: onChange
833
- }))), /*#__PURE__*/_react.default.createElement(TextEditorWrapper, {
880
+ })))), /*#__PURE__*/_react.default.createElement(TextEditorWrapper, {
834
881
  onClick: () => {
835
882
  var _editorRef$current;
836
883
 
@@ -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: 33.3333%;
96
110
  cursor: pointer;
97
111
  padding: 0 10px 10px;
98
112
  `;
@@ -280,6 +294,7 @@ function ImageSelector(props) {
280
294
  const [selected, setSelected] = (0, _react.useState)(initialSelected);
281
295
  const [delay, setDelay] = (0, _react.useState)(initialDelay ?? '5');
282
296
  const [align, setAlign] = (0, _react.useState)(initialAlign);
297
+ const [showImageUploader, setShowImageUploader] = (0, _react.useState)(false);
283
298
  const contentWrapperRef = (0, _react.useRef)(null);
284
299
  const pageSize = 18;
285
300
  const options = [{
@@ -329,6 +344,15 @@ function ImageSelector(props) {
329
344
  }
330
345
  };
331
346
 
347
+ const onImageUploaderChange = images => {
348
+ setSelected(prev => prev.concat(images.map(image => ({
349
+ image,
350
+ desc: '',
351
+ url: ''
352
+ }))));
353
+ setShowImageUploader(false);
354
+ };
355
+
332
356
  const onImageMetaChange = imageEntityWithMeta => {
333
357
  if (enableMultiSelect) {
334
358
  const foundIndex = selected.findIndex(ele => {
@@ -414,10 +438,10 @@ function ImageSelector(props) {
414
438
  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
439
  }
416
440
 
417
- return /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
441
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(GlobalStyle, null), /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
418
442
  isOpen: true
419
443
  }, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
420
- title: "Select image",
444
+ title: "Select images",
421
445
  actions: {
422
446
  cancel: {
423
447
  label: 'Cancel',
@@ -427,10 +451,13 @@ function ImageSelector(props) {
427
451
  label: 'Confirm',
428
452
  action: onSave
429
453
  }
430
- }
454
+ },
455
+ width: "narrow"
431
456
  }, /*#__PURE__*/_react.default.createElement("div", {
432
457
  ref: contentWrapperRef
433
- }, /*#__PURE__*/_react.default.createElement(ImageSearchBox, {
458
+ }, /*#__PURE__*/_react.default.createElement(CustomButton, {
459
+ onClick: () => setShowImageUploader(true)
460
+ }, "\u4E0A\u50B3\u5716\u7247"), /*#__PURE__*/_react.default.createElement(ImageSearchBox, {
434
461
  onChange: onSearchBoxChange
435
462
  }), /*#__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
463
  imageMetas: selected,
@@ -447,5 +474,7 @@ function ImageSelector(props) {
447
474
  options: options,
448
475
  onChange: onAlignSelectChange,
449
476
  onOpen: onAlignSelectOpen
450
- })))));
477
+ }))))), showImageUploader && /*#__PURE__*/_react.default.createElement(_imageUploader.ImageUploader, {
478
+ onChange: onImageUploaderChange
479
+ }));
451
480
  }