@mirrormedia/lilith-draft-editor 3.0.8-beta.1 → 3.0.8-beta.2
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.
|
@@ -9,7 +9,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
9
9
|
|
|
10
10
|
var _debounce = _interopRequireDefault(require("lodash/debounce"));
|
|
11
11
|
|
|
12
|
-
var _styledComponents =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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(
|
|
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
|
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ImageUploader = ImageUploader;
|
|
7
|
+
|
|
8
|
+
var _apollo = require("@keystone-6/core/admin-ui/apollo");
|
|
9
|
+
|
|
10
|
+
var _modals = require("@keystone-ui/modals");
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
|
|
14
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
15
|
+
|
|
16
|
+
var _fileConvert = require("../utils/file-convert");
|
|
17
|
+
|
|
18
|
+
var _button = require("@keystone-ui/button");
|
|
19
|
+
|
|
20
|
+
var _fields = require("@keystone-ui/fields");
|
|
21
|
+
|
|
22
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
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 imagesMutation = (0, _apollo.gql)`
|
|
31
|
+
mutation AddPhotos($data: [PhotoCreateInput!]!) {
|
|
32
|
+
photos: createPhotos(data: $data) {
|
|
33
|
+
id
|
|
34
|
+
name
|
|
35
|
+
imageFile {
|
|
36
|
+
url
|
|
37
|
+
width
|
|
38
|
+
height
|
|
39
|
+
}
|
|
40
|
+
resized {
|
|
41
|
+
original
|
|
42
|
+
w480
|
|
43
|
+
w800
|
|
44
|
+
w1200
|
|
45
|
+
w1600
|
|
46
|
+
w2400
|
|
47
|
+
}
|
|
48
|
+
resizedWebp {
|
|
49
|
+
original
|
|
50
|
+
w480
|
|
51
|
+
w800
|
|
52
|
+
w1200
|
|
53
|
+
w1600
|
|
54
|
+
w2400
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
const CustomButton = (0, _styledComponents.default)(_button.Button)`
|
|
60
|
+
margin-top: 10px;
|
|
61
|
+
`;
|
|
62
|
+
const HiddenInput = _styledComponents.default.input`
|
|
63
|
+
display: none;
|
|
64
|
+
`;
|
|
65
|
+
const ImagesWrapper = _styledComponents.default.div`
|
|
66
|
+
overflow: auto;
|
|
67
|
+
margin-top: 10px;
|
|
68
|
+
`;
|
|
69
|
+
const ImageFilesWrapper = _styledComponents.default.div`
|
|
70
|
+
display: flex;
|
|
71
|
+
flex-wrap: wrap;
|
|
72
|
+
overflow: auto;
|
|
73
|
+
`;
|
|
74
|
+
const ImageFileWrapper = _styledComponents.default.div`
|
|
75
|
+
width: 33%;
|
|
76
|
+
cursor: pointer;
|
|
77
|
+
padding: 0 10px 10px;
|
|
78
|
+
`;
|
|
79
|
+
const Image = _styledComponents.default.img`
|
|
80
|
+
display: block;
|
|
81
|
+
width: 100%;
|
|
82
|
+
aspect-ratio: 2;
|
|
83
|
+
object-fit: contain;
|
|
84
|
+
`;
|
|
85
|
+
const ImageName = _styledComponents.default.p`
|
|
86
|
+
text-align: center;
|
|
87
|
+
`;
|
|
88
|
+
const Label = _styledComponents.default.label`
|
|
89
|
+
display: block;
|
|
90
|
+
margin: 10px 0;
|
|
91
|
+
font-weight: 600;
|
|
92
|
+
`;
|
|
93
|
+
const CustomCheckbox = (0, _styledComponents.default)(_fields.Checkbox)`
|
|
94
|
+
display: flex;
|
|
95
|
+
align-items: center;
|
|
96
|
+
cursor: pointer;
|
|
97
|
+
`;
|
|
98
|
+
const WatermarkTypeWrapper = _styledComponents.default.div`
|
|
99
|
+
margin-top: 10px;
|
|
100
|
+
`;
|
|
101
|
+
const WatermarkToggleWrapper = _styledComponents.default.div`
|
|
102
|
+
margin-top: 10px;
|
|
103
|
+
padding: 10px;
|
|
104
|
+
background-color: #f5f5f5;
|
|
105
|
+
border-radius: 4px;
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
const AddImages = ({
|
|
109
|
+
onAddImages
|
|
110
|
+
}) => {
|
|
111
|
+
const inputRef = (0, _react.useRef)(null);
|
|
112
|
+
|
|
113
|
+
const inputChangeHandler = async event => {
|
|
114
|
+
const files = event.target.files;
|
|
115
|
+
event.target.files = null;
|
|
116
|
+
if (!files) return;
|
|
117
|
+
const imagesFiles = await (0, _fileConvert.convertFilesToImageData)(files);
|
|
118
|
+
console.log('imagesFiles', imagesFiles);
|
|
119
|
+
onAddImages(imagesFiles);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const onUploadButton = () => {
|
|
123
|
+
var _inputRef$current;
|
|
124
|
+
|
|
125
|
+
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.click();
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(CustomButton, {
|
|
129
|
+
onClick: onUploadButton
|
|
130
|
+
}, "\u65B0\u589E\u5716\u7247"), /*#__PURE__*/_react.default.createElement(HiddenInput, {
|
|
131
|
+
type: "file",
|
|
132
|
+
multiple: true,
|
|
133
|
+
accept: "image/*",
|
|
134
|
+
ref: inputRef,
|
|
135
|
+
onChange: inputChangeHandler
|
|
136
|
+
}));
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const ImageFiles = ({
|
|
140
|
+
files,
|
|
141
|
+
onChange
|
|
142
|
+
}) => {
|
|
143
|
+
return /*#__PURE__*/_react.default.createElement(ImageFilesWrapper, null, files.map(file => /*#__PURE__*/_react.default.createElement(ImageFile, {
|
|
144
|
+
key: file.uid,
|
|
145
|
+
file: file,
|
|
146
|
+
onChange: onChange
|
|
147
|
+
})));
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const ImageFile = ({
|
|
151
|
+
file,
|
|
152
|
+
onChange
|
|
153
|
+
}) => {
|
|
154
|
+
return /*#__PURE__*/_react.default.createElement(ImageFileWrapper, null, /*#__PURE__*/_react.default.createElement(Image, {
|
|
155
|
+
src: file.blobURL
|
|
156
|
+
}), /*#__PURE__*/_react.default.createElement(Label, {
|
|
157
|
+
htmlFor: "name"
|
|
158
|
+
}, "Image Name"), /*#__PURE__*/_react.default.createElement(_fields.TextInput, {
|
|
159
|
+
id: "name",
|
|
160
|
+
type: "text",
|
|
161
|
+
defaultValue: file.name,
|
|
162
|
+
onChange: _lodash.default.debounce(e => {
|
|
163
|
+
onChange({ ...file,
|
|
164
|
+
name: e.target.value
|
|
165
|
+
});
|
|
166
|
+
})
|
|
167
|
+
}), /*#__PURE__*/_react.default.createElement(ImageName, null, file.name), /*#__PURE__*/_react.default.createElement(CustomCheckbox, {
|
|
168
|
+
defaultChecked: file.shouldSetWatermark,
|
|
169
|
+
onChange: _lodash.default.debounce(e => {
|
|
170
|
+
onChange({ ...file,
|
|
171
|
+
shouldSetWatermark: e.target.checked
|
|
172
|
+
});
|
|
173
|
+
})
|
|
174
|
+
}, "\u6D6E\u6C34\u5370"), file.shouldSetWatermark && /*#__PURE__*/_react.default.createElement(WatermarkTypeWrapper, null, /*#__PURE__*/_react.default.createElement(_fields.Select, {
|
|
175
|
+
value: {
|
|
176
|
+
label: file.watermarkType === 'mirrordaily' ? '鏡報' : '鏡週刊',
|
|
177
|
+
value: file.watermarkType
|
|
178
|
+
},
|
|
179
|
+
onChange: option => {
|
|
180
|
+
onChange({ ...file,
|
|
181
|
+
watermarkType: (option === null || option === void 0 ? void 0 : option.value) || 'mirrormedia'
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
options: [{
|
|
185
|
+
label: '鏡週刊',
|
|
186
|
+
value: 'mirrormedia'
|
|
187
|
+
}, {
|
|
188
|
+
label: '鏡報',
|
|
189
|
+
value: 'mirrordaily'
|
|
190
|
+
}]
|
|
191
|
+
})));
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
function ImageUploader({
|
|
195
|
+
onChange
|
|
196
|
+
}) {
|
|
197
|
+
const [files, setFiles] = (0, _react.useState)([]);
|
|
198
|
+
const [watermarkAll, setWatermarkAll] = (0, _react.useState)(true);
|
|
199
|
+
const [watermarkTypeAll, setWatermarkTypeAll] = (0, _react.useState)('mirrormedia');
|
|
200
|
+
const [addPhotos, {
|
|
201
|
+
data: uploadData,
|
|
202
|
+
loading: uploadLoading,
|
|
203
|
+
error: uploadError
|
|
204
|
+
}] = (0, _apollo.useMutation)(imagesMutation);
|
|
205
|
+
|
|
206
|
+
const onAddImages = rawFiles => {
|
|
207
|
+
const existedImageUids = new Set(files.map(file => file.uid));
|
|
208
|
+
const newFiles = rawFiles.filter(file => !existedImageUids.has(file.uid)).map(rawFile => ({ ...rawFile,
|
|
209
|
+
shouldSetWatermark: watermarkAll,
|
|
210
|
+
watermarkType: watermarkTypeAll
|
|
211
|
+
}));
|
|
212
|
+
setFiles(prev => prev.concat(newFiles));
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const toggleAllWatermarks = checked => {
|
|
216
|
+
setWatermarkAll(checked);
|
|
217
|
+
setFiles(prev => prev.map(file => ({ ...file,
|
|
218
|
+
shouldSetWatermark: checked
|
|
219
|
+
})));
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const changeAllWatermarkTypes = type => {
|
|
223
|
+
setWatermarkTypeAll(type);
|
|
224
|
+
setFiles(prev => prev.map(file => ({ ...file,
|
|
225
|
+
watermarkType: type
|
|
226
|
+
})));
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const onConfirm = async () => {
|
|
230
|
+
if (!files.length) return onChange([]);
|
|
231
|
+
const tasks = files.map(async data => ({ ...data,
|
|
232
|
+
file: await (0, _fileConvert.convertStringToFile)(data.blobURL, data.name, data.type)
|
|
233
|
+
}));
|
|
234
|
+
const data = (await Promise.allSettled(tasks)).filter(function (settledResult) {
|
|
235
|
+
return settledResult.status === 'fulfilled';
|
|
236
|
+
}).map(result => result.value);
|
|
237
|
+
addPhotos({
|
|
238
|
+
variables: {
|
|
239
|
+
data: data.map(d => ({
|
|
240
|
+
name: d.name,
|
|
241
|
+
imageFile: {
|
|
242
|
+
upload: d.file
|
|
243
|
+
},
|
|
244
|
+
waterMark: d.shouldSetWatermark,
|
|
245
|
+
watermarkType: d.watermarkType
|
|
246
|
+
}))
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const onImageFileChang = file => {
|
|
252
|
+
const newFiles = Array.from(files);
|
|
253
|
+
const foundIndex = newFiles.findIndex(ele => ele.uid === file.uid);
|
|
254
|
+
|
|
255
|
+
if (foundIndex !== -1) {
|
|
256
|
+
newFiles[foundIndex] = file;
|
|
257
|
+
setFiles(newFiles);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
(0, _react.useEffect)(() => {
|
|
262
|
+
var _uploadData$photos;
|
|
263
|
+
|
|
264
|
+
if (uploadData !== null && uploadData !== void 0 && (_uploadData$photos = uploadData.photos) !== null && _uploadData$photos !== void 0 && _uploadData$photos.length) {
|
|
265
|
+
onChange(uploadData.photos);
|
|
266
|
+
}
|
|
267
|
+
}, [uploadData, onChange]);
|
|
268
|
+
return /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
|
|
269
|
+
isOpen: true
|
|
270
|
+
}, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
|
|
271
|
+
title: "Upload images",
|
|
272
|
+
actions: {
|
|
273
|
+
cancel: {
|
|
274
|
+
label: 'Cancel',
|
|
275
|
+
action: () => {
|
|
276
|
+
onChange([]);
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
confirm: {
|
|
280
|
+
label: 'Confirm',
|
|
281
|
+
action: onConfirm
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
width: "narrow"
|
|
285
|
+
}, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(AddImages, {
|
|
286
|
+
onAddImages: onAddImages
|
|
287
|
+
}), files.length > 0 && /*#__PURE__*/_react.default.createElement(WatermarkToggleWrapper, null, /*#__PURE__*/_react.default.createElement(CustomCheckbox, {
|
|
288
|
+
checked: watermarkAll,
|
|
289
|
+
onChange: e => {
|
|
290
|
+
toggleAllWatermarks(e.target.checked);
|
|
291
|
+
}
|
|
292
|
+
}, "\u5168\u90E8\u52A0\u4E0A\u6D6E\u6C34\u5370"), watermarkAll && /*#__PURE__*/_react.default.createElement(WatermarkTypeWrapper, null, /*#__PURE__*/_react.default.createElement(_fields.Select, {
|
|
293
|
+
value: {
|
|
294
|
+
label: watermarkTypeAll === 'mirrordaily' ? '鏡報' : '鏡週刊',
|
|
295
|
+
value: watermarkTypeAll
|
|
296
|
+
},
|
|
297
|
+
onChange: option => {
|
|
298
|
+
const type = (option === null || option === void 0 ? void 0 : option.value) || 'mirrormedia';
|
|
299
|
+
changeAllWatermarkTypes(type);
|
|
300
|
+
},
|
|
301
|
+
options: [{
|
|
302
|
+
label: '鏡週刊',
|
|
303
|
+
value: 'mirrormedia'
|
|
304
|
+
}, {
|
|
305
|
+
label: '鏡報',
|
|
306
|
+
value: 'mirrordaily'
|
|
307
|
+
}]
|
|
308
|
+
}))), /*#__PURE__*/_react.default.createElement(ImagesWrapper, null, /*#__PURE__*/_react.default.createElement(ImageFiles, {
|
|
309
|
+
files: files,
|
|
310
|
+
onChange: onImageFileChang
|
|
311
|
+
})), uploadLoading && /*#__PURE__*/_react.default.createElement("div", null, "loading"), uploadError && /*#__PURE__*/_react.default.createElement("div", null, uploadError.message))));
|
|
312
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.convertBlobToString = convertBlobToString;
|
|
7
|
+
exports.convertFilesToImageData = convertFilesToImageData;
|
|
8
|
+
exports.convertStringToFile = convertStringToFile;
|
|
9
|
+
|
|
10
|
+
var _jsSha = require("js-sha256");
|
|
11
|
+
|
|
12
|
+
async function convertFilesToMediaData(fileList, isValidFile, wrapResult) {
|
|
13
|
+
const files = Array.from(fileList);
|
|
14
|
+
const fileNamePostfix = new Intl.DateTimeFormat('fr-CA', {
|
|
15
|
+
year: 'numeric',
|
|
16
|
+
month: '2-digit',
|
|
17
|
+
day: '2-digit'
|
|
18
|
+
}).format(Date.now());
|
|
19
|
+
const tasks = files.map(async file => {
|
|
20
|
+
if (!isValidFile(file)) return;
|
|
21
|
+
const uInt8Data = await file.arrayBuffer();
|
|
22
|
+
const name = file.name;
|
|
23
|
+
const positionOfLastDot = name.lastIndexOf('.');
|
|
24
|
+
const filename = positionOfLastDot > -1 ? `${name.slice(0, positionOfLastDot)}_${fileNamePostfix}${name.slice(positionOfLastDot)}` : `${name}_${fileNamePostfix}`;
|
|
25
|
+
return wrapResult({
|
|
26
|
+
uid: (0, _jsSha.sha256)(uInt8Data),
|
|
27
|
+
name: filename,
|
|
28
|
+
type: file.type,
|
|
29
|
+
blobURL: convertBlobToString(file)
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
const results = await Promise.allSettled(tasks);
|
|
33
|
+
return results.filter(r => r.status === 'fulfilled').map(r => r.value).filter(r => Boolean(r));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isImageFile(file) {
|
|
37
|
+
return file.type.startsWith('image/');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function convertFilesToImageData(fileList) {
|
|
41
|
+
return convertFilesToMediaData(fileList, isImageFile, ({
|
|
42
|
+
uid,
|
|
43
|
+
name,
|
|
44
|
+
type,
|
|
45
|
+
blobURL
|
|
46
|
+
}) => ({
|
|
47
|
+
uid,
|
|
48
|
+
name,
|
|
49
|
+
type,
|
|
50
|
+
blobURL
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function blobToFile(blob, fileName, extension) {
|
|
55
|
+
return new File([blob], fileName, {
|
|
56
|
+
type: extension
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function convertBlobToString(blob) {
|
|
61
|
+
return URL.createObjectURL(blob);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function convertStringToFile(str, fileName, extension) {
|
|
65
|
+
const request = new Request(str);
|
|
66
|
+
return await fetch(request).then(response => response.blob()).then(blob => blobToFile(blob, fileName, extension ?? blob.type));
|
|
67
|
+
}
|