@scaleflex/widget-image-editor 4.4.0 → 4.5.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.
- package/CHANGELOG.md +8 -0
- package/dist/style.css +27 -0
- package/dist/style.min.css +1 -0
- package/lib/ImageEditor.js +452 -0
- package/lib/ImageEditor.thunks.js +63 -0
- package/lib/b64ToBlob.js +19 -0
- package/lib/defaultLocale.js +13 -0
- package/lib/index.js +126 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [4.5.0](https://code.scaleflex.cloud/scaleflex/widget/compare/v4.4.0...v4.5.0) (2025-10-08)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @scaleflex/widget-image-editor
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [4.4.0](https://code.scaleflex.cloud/scaleflex/widget/compare/v4.1.0...v4.4.0) (2025-10-07)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @scaleflex/widget-image-editor
|
package/dist/style.css
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap");
|
|
2
|
+
.filerobot-ImageEditor-SaveAsModal-fieldGroup {
|
|
3
|
+
text-align: left;
|
|
4
|
+
margin-bottom: 12px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.filerobot-ImageEditor-SaveAsModal-fieldInput {
|
|
8
|
+
margin-top: 4px;
|
|
9
|
+
height: 32px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.filerobot-ImageEditor-SaveAsModal-folderFieldGroup {
|
|
13
|
+
display: flex;
|
|
14
|
+
justify-content: flex-start;
|
|
15
|
+
align-items: center;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.filerobot-ImageEditor-SaveAsModal-folderPathInput {
|
|
19
|
+
flex-grow: 1;
|
|
20
|
+
border-radius: 2px 0 0 2px;
|
|
21
|
+
height: 100%;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.filerobot-ImageEditor-SaveAsModal-browseButton {
|
|
25
|
+
background: #E9EEF2;
|
|
26
|
+
border-radius: 0 2px 2px 0;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap");.filerobot-ImageEditor-SaveAsModal-fieldGroup{margin-bottom:12px;text-align:left}.filerobot-ImageEditor-SaveAsModal-fieldInput{height:32px;margin-top:4px}.filerobot-ImageEditor-SaveAsModal-folderFieldGroup{align-items:center;display:flex;justify-content:flex-start}.filerobot-ImageEditor-SaveAsModal-folderPathInput{border-radius:2px 0 0 2px;flex-grow:1;height:100%}.filerobot-ImageEditor-SaveAsModal-browseButton{background:#e9eef2;border-radius:0 2px 2px 0}
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
10
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
11
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
13
|
+
import { useEffect, useState, useMemo } from 'react';
|
|
14
|
+
import { useSelector, useDispatch } from 'react-redux';
|
|
15
|
+
import FilerobotImageEditor from 'react-filerobot-image-editor';
|
|
16
|
+
import FilerobotVideoEditor from 'react-filerobot-video-editor';
|
|
17
|
+
import { ScaleflexWidget } from '@scaleflex/widget-core';
|
|
18
|
+
import { FolderMoveTo, Duplicate } from '@scaleflex/icons';
|
|
19
|
+
import handlePromise from '@scaleflex/widget-utils/lib/handlePromise';
|
|
20
|
+
import blobToDataURI from '@scaleflex/widget-utils/lib/blobToDataURI';
|
|
21
|
+
import { HistoryIcon } from '@scaleflex/widget-icons';
|
|
22
|
+
import { LoaderView, PC } from '@scaleflex/widget-common';
|
|
23
|
+
import { IMAGE_EDITOR_MODES, PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants';
|
|
24
|
+
import { useModal, useCore, usePlugin } from '@scaleflex/widget-core/lib/hooks';
|
|
25
|
+
import { useExplorer, useLocateFile } from '@scaleflex/widget-explorer/lib/hooks';
|
|
26
|
+
import { selectCurrentFolderPath } from '@scaleflex/widget-explorer/lib/slices/folders.slice';
|
|
27
|
+
import isUploadableFile from '@scaleflex/widget-utils/lib/isUploadableFile';
|
|
28
|
+
import getImageEditUrl from '@scaleflex/widget-utils/lib/getImageEditUrl';
|
|
29
|
+
import { useTheme } from '@scaleflex/ui/theme/hooks';
|
|
30
|
+
import FolderSelector from '@scaleflex/widget-explorer/lib/components/common/FolderSelector';
|
|
31
|
+
import { addUploadActivity } from '@scaleflex/widget-explorer/lib/thunks/uploads.thunks';
|
|
32
|
+
import { selectContainerWidth } from '@scaleflex/widget-explorer/lib/slices/common.slice';
|
|
33
|
+
import getFileLink from '@scaleflex/widget-utils/lib/getFileLink';
|
|
34
|
+
import isVideo from '@scaleflex/widget-utils/lib/isVideo';
|
|
35
|
+
import b64toBlob from './b64ToBlob';
|
|
36
|
+
import { addVideoProcessingActivity } from './ImageEditor.thunks';
|
|
37
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
38
|
+
var fallbackFolderPath = encodeURI('/Edited by image editor');
|
|
39
|
+
|
|
40
|
+
// TODO: we might split this component into 2 components: one for handling image link retrieving if not found, and another for showing the editor.
|
|
41
|
+
var ImageEditor = function ImageEditor(_ref) {
|
|
42
|
+
var _pluginOpts$cloudimag2, _pluginOpts$cloudimag3, _pluginOpts$cloudimag4;
|
|
43
|
+
var file = _ref.file,
|
|
44
|
+
userMode = _ref.mode,
|
|
45
|
+
showBackButton = _ref.showBackButton,
|
|
46
|
+
hideSavingOptions = _ref.hideSavingOptions,
|
|
47
|
+
pluginOpts = _ref.opts,
|
|
48
|
+
closeEditor = _ref.closeEditor,
|
|
49
|
+
i18n = _ref.i18n;
|
|
50
|
+
var dispatch = useDispatch();
|
|
51
|
+
var _useCore = useCore(),
|
|
52
|
+
info = _useCore.info,
|
|
53
|
+
hideInfo = _useCore.hideInfo,
|
|
54
|
+
addFile = _useCore.addFile,
|
|
55
|
+
emit = _useCore.emit,
|
|
56
|
+
off = _useCore.off,
|
|
57
|
+
setFileStateBeforeUpload = _useCore.setFileStateBeforeUpload,
|
|
58
|
+
_useCore$opts = _useCore.opts,
|
|
59
|
+
language = _useCore$opts.language,
|
|
60
|
+
container = _useCore$opts.container,
|
|
61
|
+
securityTemplateId = _useCore$opts.securityTemplateId,
|
|
62
|
+
sassKey = _useCore$opts.sassKey;
|
|
63
|
+
var _useExplorer = useExplorer(),
|
|
64
|
+
closeModal = _useExplorer.closeModal,
|
|
65
|
+
isDevEnv = _useExplorer.isDevEnv,
|
|
66
|
+
_useExplorer$opts = _useExplorer.opts,
|
|
67
|
+
inline = _useExplorer$opts.inline,
|
|
68
|
+
closeAfterImageEdit = _useExplorer$opts.closeAfterImageEdit,
|
|
69
|
+
imageEditorMode = _useExplorer$opts.imageEditorMode;
|
|
70
|
+
var isUpload = isUploadableFile(file);
|
|
71
|
+
var mode = !isUpload && userMode === IMAGE_EDITOR_MODES.DEFAULT && imageEditorMode || userMode;
|
|
72
|
+
var theme = useTheme();
|
|
73
|
+
var toggleModal = useModal();
|
|
74
|
+
var containerWidth = useSelector(selectContainerWidth);
|
|
75
|
+
var currentFolderPath = useSelector(selectCurrentFolderPath);
|
|
76
|
+
var progressPanelInstance = usePlugin(PLUGINS_IDS.PROGRESS_PANEL);
|
|
77
|
+
var locateFile = useLocateFile();
|
|
78
|
+
var _ref2 = (file === null || file === void 0 ? void 0 : file.info) || {},
|
|
79
|
+
imgWidth = _ref2.img_w,
|
|
80
|
+
imgHeight = _ref2.img_h;
|
|
81
|
+
var _useState = useState(function () {
|
|
82
|
+
var _window;
|
|
83
|
+
return getImageEditUrl(file, {
|
|
84
|
+
isDevEnv: isDevEnv,
|
|
85
|
+
containerToken: container,
|
|
86
|
+
mode: mode,
|
|
87
|
+
containerWidth: parseInt(containerWidth) || ((_window = window) === null || _window === void 0 ? void 0 : _window.innerWidth)
|
|
88
|
+
});
|
|
89
|
+
}),
|
|
90
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
91
|
+
imgFileUrl = _useState2[0],
|
|
92
|
+
setImgFileUrl = _useState2[1];
|
|
93
|
+
var _useState3 = useState(function () {
|
|
94
|
+
return Boolean(imgFileUrl);
|
|
95
|
+
}),
|
|
96
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
97
|
+
isLoadingUrl = _useState4[0],
|
|
98
|
+
setIsLoadingUrl = _useState4[1];
|
|
99
|
+
var isCloudimageMode = mode === IMAGE_EDITOR_MODES.CLOUDIMAGE || pluginOpts.useCloudimage;
|
|
100
|
+
var source = useMemo(function () {
|
|
101
|
+
return (
|
|
102
|
+
// we're providing width, height & src cause the provided src might be optimized by cloudimage's resizing then not the real original dimensions
|
|
103
|
+
isCloudimageMode && imgWidth && imgHeight ? {
|
|
104
|
+
width: imgWidth,
|
|
105
|
+
height: imgHeight,
|
|
106
|
+
src: imgFileUrl
|
|
107
|
+
} : imgFileUrl
|
|
108
|
+
);
|
|
109
|
+
}, [isCloudimageMode, imgWidth, imgHeight, imgFileUrl]);
|
|
110
|
+
|
|
111
|
+
// We remove the bg-primary-active provided from the theme as it is not handled properly from configurations, so we are keep using image editor's default.
|
|
112
|
+
var defaultImgEditorTheme = useMemo(function () {
|
|
113
|
+
var newTheme = _objectSpread({
|
|
114
|
+
palette: _objectSpread({}, theme.palette)
|
|
115
|
+
}, theme.typography && {
|
|
116
|
+
typography: {
|
|
117
|
+
fontFamily: theme.typography.fontFamily
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
if (newTheme.palette['bg-primary-active']) {
|
|
121
|
+
delete newTheme.palette['bg-primary-active'];
|
|
122
|
+
}
|
|
123
|
+
return newTheme;
|
|
124
|
+
}, [theme]);
|
|
125
|
+
var iconAccentActiveColor = theme.palette[PC.AccentPrimaryActive];
|
|
126
|
+
var handleClose = function handleClose() {
|
|
127
|
+
closeEditor();
|
|
128
|
+
off('url-modified');
|
|
129
|
+
if (!inline && closeAfterImageEdit) {
|
|
130
|
+
closeModal();
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
useEffect(function () {
|
|
134
|
+
if (!imgFileUrl && isUpload) {
|
|
135
|
+
info(i18n('imageEditorImgPreparationForEditInfo', 'info'));
|
|
136
|
+
setIsLoadingUrl(true);
|
|
137
|
+
var fileData = ScaleflexWidget.uploadFilesData[file.id];
|
|
138
|
+
if (isVideo(file)) {
|
|
139
|
+
setImgFileUrl(fileData);
|
|
140
|
+
} else {
|
|
141
|
+
handlePromise(blobToDataURI(fileData), setImgFileUrl, info, function () {
|
|
142
|
+
info(i18n('imageEditorInvalidImageUrl'), 'error', 5000);
|
|
143
|
+
setIsLoadingUrl(false);
|
|
144
|
+
hideInfo();
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}, [file.uuid, file.id]);
|
|
149
|
+
useEffect(function () {
|
|
150
|
+
var _pluginOpts$cloudimag;
|
|
151
|
+
if (mode === IMAGE_EDITOR_MODES.CLOUDIMAGE && !((_pluginOpts$cloudimag = pluginOpts.cloudimage) !== null && _pluginOpts$cloudimag !== void 0 && _pluginOpts$cloudimag.token)) {
|
|
152
|
+
handleClose();
|
|
153
|
+
info(i18n('imageEditorNoCloudimgTokenInfo'), 'error', 5000);
|
|
154
|
+
}
|
|
155
|
+
}, [mode, (_pluginOpts$cloudimag2 = pluginOpts.cloudimage) === null || _pluginOpts$cloudimag2 === void 0 ? void 0 : _pluginOpts$cloudimag2.token]);
|
|
156
|
+
if (!imgFileUrl) {
|
|
157
|
+
if (isLoadingUrl) {
|
|
158
|
+
return /*#__PURE__*/_jsx(LoaderView, {
|
|
159
|
+
loaderLabel: i18n('loaderLoadingLabel')
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
if (mode === IMAGE_EDITOR_MODES.CLOUDIMAGE && !((_pluginOpts$cloudimag3 = pluginOpts.cloudimage) !== null && _pluginOpts$cloudimag3 !== void 0 && _pluginOpts$cloudimag3.token)) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
var uploadToFolder = currentFolderPath || fallbackFolderPath;
|
|
168
|
+
var showEditor = mode !== IMAGE_EDITOR_MODES.CLOUDIMAGE || mode === IMAGE_EDITOR_MODES.CLOUDIMAGE && ((_pluginOpts$cloudimag4 = pluginOpts.cloudimage) === null || _pluginOpts$cloudimag4 === void 0 ? void 0 : _pluginOpts$cloudimag4.token);
|
|
169
|
+
|
|
170
|
+
// newFolderPath are being passed in 2 cases of folder (canceling or selecting).
|
|
171
|
+
var toggleFolderSelector = function toggleFolderSelector(triggerUpload, newFolderPath) {
|
|
172
|
+
var defaultFolderPath = newFolderPath || uploadToFolder;
|
|
173
|
+
toggleModal({
|
|
174
|
+
icon: /*#__PURE__*/_jsx(FolderMoveTo, {
|
|
175
|
+
size: 29,
|
|
176
|
+
color: iconAccentActiveColor
|
|
177
|
+
}),
|
|
178
|
+
title: i18n('imageEditorChooseFolderPathTitle'),
|
|
179
|
+
showTitleLabel: true,
|
|
180
|
+
content: function content(_ref3) {
|
|
181
|
+
var setPrimaryButtonDisabled = _ref3.setPrimaryButtonDisabled,
|
|
182
|
+
updateData = _ref3.updateData,
|
|
183
|
+
data = _ref3.data;
|
|
184
|
+
return /*#__PURE__*/_jsx(FolderSelector, {
|
|
185
|
+
setPrimaryButtonDisabled: setPrimaryButtonDisabled,
|
|
186
|
+
selectedFolder: data || defaultFolderPath,
|
|
187
|
+
onSelect: updateData,
|
|
188
|
+
onRemoveSelectedFolder: function onRemoveSelectedFolder() {
|
|
189
|
+
return updateData(null);
|
|
190
|
+
},
|
|
191
|
+
hideAddNewFolderButton: true
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
buttonPrimaryLabel: i18n('mutualizedConfirmButtonLabel'),
|
|
195
|
+
onButtonPrimaryClick: function onButtonPrimaryClick(_ref4) {
|
|
196
|
+
var selectedFolder = _ref4.data,
|
|
197
|
+
closeModal = _ref4.closeModal;
|
|
198
|
+
triggerUpload((selectedFolder === null || selectedFolder === void 0 ? void 0 : selectedFolder.path) || defaultFolderPath);
|
|
199
|
+
closeModal();
|
|
200
|
+
handleClose();
|
|
201
|
+
},
|
|
202
|
+
enterKeySubmits: true,
|
|
203
|
+
modalStyle: {
|
|
204
|
+
maxWidth: 400
|
|
205
|
+
},
|
|
206
|
+
modalFooterStyle: {
|
|
207
|
+
flexDirection: 'row'
|
|
208
|
+
},
|
|
209
|
+
modalPrimaryButton: {
|
|
210
|
+
width: 170
|
|
211
|
+
},
|
|
212
|
+
modalSecondaryButton: {
|
|
213
|
+
width: 170
|
|
214
|
+
},
|
|
215
|
+
modalSecondaryButtonColor: 'basic'
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
var uploadNewFile = function uploadNewFile(fileDescriptor, toFolder, activityId) {
|
|
219
|
+
var _file$folder;
|
|
220
|
+
var onUpload = function onUpload(file) {
|
|
221
|
+
if (progressPanelInstance) {
|
|
222
|
+
dispatch(addUploadActivity({
|
|
223
|
+
file: file,
|
|
224
|
+
locateFile: locateFile,
|
|
225
|
+
activityId: activityId
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
addFile(_objectSpread(_objectSpread({}, fileDescriptor), {}, {
|
|
230
|
+
meta: file.meta,
|
|
231
|
+
product: file.product,
|
|
232
|
+
toFolder: toFolder || ((_file$folder = file.folder) === null || _file$folder === void 0 ? void 0 : _file$folder.name) || file.toFolder,
|
|
233
|
+
currentUploadId: activityId
|
|
234
|
+
}), true, onUpload);
|
|
235
|
+
if (!isVideo(file)) {
|
|
236
|
+
info(i18n('imageEditorImgNewVersionStartedUploading'), 'info', 3000);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
var prepareNewFile = function prepareNewFile(_ref5) {
|
|
240
|
+
var mediaFile = _ref5.mediaFile,
|
|
241
|
+
blobData = _ref5.blobData,
|
|
242
|
+
url = _ref5.url;
|
|
243
|
+
try {
|
|
244
|
+
var fileName = mediaFile.fullName || mediaFile.name;
|
|
245
|
+
var commonFileDescriptor = {
|
|
246
|
+
source: PLUGINS_IDS.IMAGE_EDITOR,
|
|
247
|
+
name: fileName,
|
|
248
|
+
type: mediaFile.mimeType,
|
|
249
|
+
xhrQueryParams: {
|
|
250
|
+
image_editor: 'edited'
|
|
251
|
+
},
|
|
252
|
+
info: {
|
|
253
|
+
type: mediaFile.mimeType
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
var fileDescriptor = {};
|
|
257
|
+
if (blobData) {
|
|
258
|
+
var newFileData = new File([blobData], fileName, {
|
|
259
|
+
type: mediaFile.mimeType
|
|
260
|
+
});
|
|
261
|
+
fileDescriptor = _objectSpread(_objectSpread({}, commonFileDescriptor), {}, {
|
|
262
|
+
data: newFileData,
|
|
263
|
+
size: newFileData.size
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
if (url) {
|
|
267
|
+
fileDescriptor = _objectSpread(_objectSpread({}, commonFileDescriptor), {}, {
|
|
268
|
+
uploadUrl: url,
|
|
269
|
+
xhrHeaders: {
|
|
270
|
+
'Content-Type': 'application/json'
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return fileDescriptor;
|
|
275
|
+
// It is not needed to pass the new file data in the file's object
|
|
276
|
+
// as thumbnail generator retrieves the files from the core state while generating previews
|
|
277
|
+
} catch (err) {
|
|
278
|
+
info(err, 'error', 3000);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
var finishSaving = function finishSaving(_ref6) {
|
|
282
|
+
var newFile = _ref6.newFile,
|
|
283
|
+
toFolderPath = _ref6.toFolderPath,
|
|
284
|
+
activityId = _ref6.activityId,
|
|
285
|
+
avoidSaveAsModal = _ref6.avoidSaveAsModal;
|
|
286
|
+
if (isUploadableFile(file)) {
|
|
287
|
+
setFileStateBeforeUpload(file.id, newFile);
|
|
288
|
+
emit('thumbnail:update', _objectSpread({
|
|
289
|
+
id: file.id
|
|
290
|
+
}, newFile));
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (avoidSaveAsModal) {
|
|
294
|
+
uploadNewFile(newFile, toFolderPath, activityId);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
toggleFolderSelector(function (toFolderPath) {
|
|
298
|
+
uploadNewFile(newFile, toFolderPath, activityId);
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
var handleSaving = async function handleSaving(_ref7) {
|
|
302
|
+
var mediaFile = _ref7.mediaFile,
|
|
303
|
+
designState = _ref7.designState,
|
|
304
|
+
_ref7$avoidSaveAsModa = _ref7.avoidSaveAsModal,
|
|
305
|
+
avoidSaveAsModal = _ref7$avoidSaveAsModa === void 0 ? true : _ref7$avoidSaveAsModa,
|
|
306
|
+
activityId = _ref7.activityId,
|
|
307
|
+
toFolderPath = _ref7.toFolderPath,
|
|
308
|
+
_ref7$enableClose = _ref7.enableClose,
|
|
309
|
+
enableClose = _ref7$enableClose === void 0 ? true : _ref7$enableClose;
|
|
310
|
+
if (mediaFile.videoBlob || mediaFile.videoUrl) {
|
|
311
|
+
var newFile = prepareNewFile({
|
|
312
|
+
mediaFile: mediaFile,
|
|
313
|
+
blobData: mediaFile.videoBlob,
|
|
314
|
+
url: mediaFile.videoUrl
|
|
315
|
+
});
|
|
316
|
+
finishSaving({
|
|
317
|
+
newFile: newFile,
|
|
318
|
+
toFolderPath: toFolderPath,
|
|
319
|
+
activityId: activityId,
|
|
320
|
+
avoidSaveAsModal: avoidSaveAsModal
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
if (mediaFile.cloudimageUrl) {
|
|
324
|
+
var _designState$adjustme;
|
|
325
|
+
var sanitizedCloudimageUrl = mediaFile.cloudimageUrl.replace(imgFileUrl, getFileLink(file));
|
|
326
|
+
emit('url-modified', sanitizedCloudimageUrl, _objectSpread(_objectSpread({}, designState === null || designState === void 0 ? void 0 : (_designState$adjustme = designState.adjustments) === null || _designState$adjustme === void 0 ? void 0 : _designState$adjustme.crop), {}, {
|
|
327
|
+
onClose: handleClose
|
|
328
|
+
}), info);
|
|
329
|
+
}
|
|
330
|
+
if (mediaFile.imageBase64) {
|
|
331
|
+
b64toBlob(mediaFile.imageBase64).then(function (blobData) {
|
|
332
|
+
var newFile = prepareNewFile({
|
|
333
|
+
mediaFile: mediaFile,
|
|
334
|
+
blobData: blobData
|
|
335
|
+
});
|
|
336
|
+
finishSaving({
|
|
337
|
+
newFile: newFile,
|
|
338
|
+
toFolderPath: toFolderPath,
|
|
339
|
+
activityId: activityId,
|
|
340
|
+
avoidSaveAsModal: avoidSaveAsModal
|
|
341
|
+
});
|
|
342
|
+
})["catch"](function (err) {
|
|
343
|
+
info(err, 'error', 3000);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
if (enableClose) {
|
|
347
|
+
handleClose();
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
var handleSavingVideoAfterUpload = async function handleSavingVideoAfterUpload(_ref8) {
|
|
351
|
+
var mediaFile = _ref8.mediaFile,
|
|
352
|
+
processVideo = _ref8.processVideo,
|
|
353
|
+
checkVideoStatus = _ref8.checkVideoStatus,
|
|
354
|
+
getFinalVideoData = _ref8.getFinalVideoData,
|
|
355
|
+
toFolderPath = _ref8.toFolderPath;
|
|
356
|
+
handleClose();
|
|
357
|
+
var processedFileData = await dispatch(addVideoProcessingActivity({
|
|
358
|
+
mediaFile: mediaFile,
|
|
359
|
+
processVideo: processVideo,
|
|
360
|
+
checkVideoStatus: checkVideoStatus
|
|
361
|
+
}));
|
|
362
|
+
var processedMediaFile = getFinalVideoData(processedFileData.mediaFileInfo, processedFileData.result);
|
|
363
|
+
handleSaving({
|
|
364
|
+
mediaFile: processedMediaFile.data,
|
|
365
|
+
activityId: processedFileData.activity.id,
|
|
366
|
+
toFolderPath: toFolderPath,
|
|
367
|
+
enableClose: false
|
|
368
|
+
});
|
|
369
|
+
};
|
|
370
|
+
var moreSavingOptions = [_objectSpread({
|
|
371
|
+
label: i18n('imageEditorSaveAsNewVersionLabel'),
|
|
372
|
+
icon: HistoryIcon,
|
|
373
|
+
onClick: function onClick(_, startSaving) {
|
|
374
|
+
startSaving(function (mediaFile, designState) {
|
|
375
|
+
return handleSaving({
|
|
376
|
+
mediaFile: mediaFile,
|
|
377
|
+
designState: designState
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}, !isUploadableFile(file) && isVideo(file) && {
|
|
382
|
+
onSaveVideoCb: function onSaveVideoCb(_, startSaving) {
|
|
383
|
+
startSaving(handleSavingVideoAfterUpload);
|
|
384
|
+
}
|
|
385
|
+
}), _objectSpread({
|
|
386
|
+
label: i18n('imageEditorDuplicateTheImageLabel'),
|
|
387
|
+
icon: Duplicate,
|
|
388
|
+
onClick: function onClick(triggerSaveModal) {
|
|
389
|
+
triggerSaveModal(function (mediaFile, designState) {
|
|
390
|
+
return handleSaving({
|
|
391
|
+
mediaFile: mediaFile,
|
|
392
|
+
designState: designState,
|
|
393
|
+
avoidSaveAsModal: false,
|
|
394
|
+
enableClose: false
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}, !isUploadableFile(file) && isVideo(file) && {
|
|
399
|
+
onSaveVideoCb: function onSaveVideoCb(triggerSaveModal) {
|
|
400
|
+
triggerSaveModal(function (_ref9) {
|
|
401
|
+
var mediaFile = _ref9.mediaFile,
|
|
402
|
+
processVideo = _ref9.processVideo,
|
|
403
|
+
checkVideoStatus = _ref9.checkVideoStatus,
|
|
404
|
+
getFinalVideoData = _ref9.getFinalVideoData;
|
|
405
|
+
toggleFolderSelector(function (toFolderPath) {
|
|
406
|
+
handleSavingVideoAfterUpload({
|
|
407
|
+
mediaFile: mediaFile,
|
|
408
|
+
processVideo: processVideo,
|
|
409
|
+
checkVideoStatus: checkVideoStatus,
|
|
410
|
+
getFinalVideoData: getFinalVideoData,
|
|
411
|
+
toFolderPath: toFolderPath
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
})];
|
|
417
|
+
var commonProps = _objectSpread(_objectSpread({
|
|
418
|
+
language: language.toLowerCase(),
|
|
419
|
+
defaultSavedImageName: file.name,
|
|
420
|
+
onBeforeSave: function onBeforeSave() {
|
|
421
|
+
return false;
|
|
422
|
+
},
|
|
423
|
+
theme: defaultImgEditorTheme
|
|
424
|
+
}, pluginOpts), {}, {
|
|
425
|
+
onClose: handleClose,
|
|
426
|
+
source: source,
|
|
427
|
+
onSave: function onSave(mediaFile, designState) {
|
|
428
|
+
return handleSaving({
|
|
429
|
+
mediaFile: mediaFile,
|
|
430
|
+
designState: designState
|
|
431
|
+
});
|
|
432
|
+
},
|
|
433
|
+
showBackButton: showBackButton,
|
|
434
|
+
useCloudimage: mode === IMAGE_EDITOR_MODES.CLOUDIMAGE || pluginOpts.useCloudimage,
|
|
435
|
+
moreSaveOptions: mode !== IMAGE_EDITOR_MODES.CLOUDIMAGE && !hideSavingOptions && moreSavingOptions,
|
|
436
|
+
cloudimage: _objectSpread(_objectSpread({}, pluginOpts.cloudimage), {}, {
|
|
437
|
+
loadableQuery: file.cloudimageQuery
|
|
438
|
+
})
|
|
439
|
+
});
|
|
440
|
+
if (isVideo(file) && showEditor) {
|
|
441
|
+
return /*#__PURE__*/_jsx(FilerobotVideoEditor, _objectSpread(_objectSpread({}, commonProps), {}, {
|
|
442
|
+
useBackendProcess: true,
|
|
443
|
+
backendProcess: {
|
|
444
|
+
token: container,
|
|
445
|
+
key: securityTemplateId || sassKey,
|
|
446
|
+
url: getFileLink(file, 'permalink')
|
|
447
|
+
}
|
|
448
|
+
}));
|
|
449
|
+
}
|
|
450
|
+
return showEditor && /*#__PURE__*/_jsx(FilerobotImageEditor, _objectSpread({}, commonProps));
|
|
451
|
+
};
|
|
452
|
+
export default ImageEditor;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
3
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
4
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
5
|
+
import cuid from 'cuid';
|
|
6
|
+
import createThunk from '@scaleflex/widget-utils/lib/createThunk';
|
|
7
|
+
import { PLUGINS_IDS, PROGRESS_PANEL_STATUS, PROGRESS_PANEL_ACTIVITY } from '@scaleflex/widget-utils/lib/constants';
|
|
8
|
+
import { PC } from '@scaleflex/widget-common';
|
|
9
|
+
export var addVideoProcessingActivity = createThunk(async function (_ref, thunkApi) {
|
|
10
|
+
var activityId = _ref.id,
|
|
11
|
+
mediaFile = _ref.mediaFile,
|
|
12
|
+
processVideo = _ref.processVideo,
|
|
13
|
+
checkVideoStatus = _ref.checkVideoStatus;
|
|
14
|
+
var extra = thunkApi.extra;
|
|
15
|
+
var progressPanelPlugin = extra.filerobot.getPlugin(PLUGINS_IDS.PROGRESS_PANEL);
|
|
16
|
+
var id = activityId || cuid();
|
|
17
|
+
if (progressPanelPlugin) {
|
|
18
|
+
return progressPanelPlugin.addActivity({
|
|
19
|
+
activity: {
|
|
20
|
+
id: id,
|
|
21
|
+
name: "".concat(mediaFile.name, ".").concat(mediaFile.extension),
|
|
22
|
+
type: PROGRESS_PANEL_ACTIVITY.PROCESSING_VIDEO,
|
|
23
|
+
progress: {
|
|
24
|
+
percentage: 0,
|
|
25
|
+
startedAt: Date.now(),
|
|
26
|
+
status: PROGRESS_PANEL_STATUS.PREPARING
|
|
27
|
+
},
|
|
28
|
+
icon: {
|
|
29
|
+
name: 'Video',
|
|
30
|
+
color: PC.Instagram
|
|
31
|
+
},
|
|
32
|
+
statusData: _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, PROGRESS_PANEL_STATUS.PREPARING, {
|
|
33
|
+
labelI18nKey: 'progressPanelPreparingVideoLabel'
|
|
34
|
+
}), PROGRESS_PANEL_STATUS.PROGRESSING, {
|
|
35
|
+
labelI18nKey: 'progressPanelPreparingVideoLabel'
|
|
36
|
+
}), PROGRESS_PANEL_STATUS.ERROR, {
|
|
37
|
+
labelI18nKey: 'progressPanelVideoFailedLabel'
|
|
38
|
+
}), PROGRESS_PANEL_STATUS.COMPLETE, {
|
|
39
|
+
labelI18nKey: 'progressPanelVideoCompletedLabel'
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
onStart: function onStart() {
|
|
43
|
+
return processVideo(mediaFile);
|
|
44
|
+
},
|
|
45
|
+
onProgress: async function onProgress(_ref2) {
|
|
46
|
+
var onStartData = _ref2.onStartData;
|
|
47
|
+
return await checkVideoStatus({
|
|
48
|
+
response: onStartData.response,
|
|
49
|
+
mediaFileInfo: onStartData.mediaFileInfo,
|
|
50
|
+
isRecursive: false
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
onRetry: function onRetry() {
|
|
54
|
+
return addVideoProcessingActivity({
|
|
55
|
+
id: id,
|
|
56
|
+
mediaFile: mediaFile,
|
|
57
|
+
processVideo: processVideo,
|
|
58
|
+
checkVideoStatus: checkVideoStatus
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
package/lib/b64ToBlob.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var b64toBlob = function b64toBlob(b64Data) {
|
|
2
|
+
return new Promise(function (resolve, reject) {
|
|
3
|
+
var xhr = new XMLHttpRequest();
|
|
4
|
+
xhr.responseType = 'blob';
|
|
5
|
+
xhr.open('GET', b64Data);
|
|
6
|
+
xhr.send();
|
|
7
|
+
xhr.onload = function () {
|
|
8
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
9
|
+
resolve(xhr.response);
|
|
10
|
+
} else {
|
|
11
|
+
reject(new Error("Error while loading base64 image. (".concat(xhr.status, ": ").concat(xhr.error, ")")));
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
xhr.onerror = function () {
|
|
15
|
+
reject(new Error("Error while loading base64 image. (".concat(xhr.status, ": ").concat(xhr.error, ")")));
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export default b64toBlob;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
imageEditorPathText: 'Path',
|
|
3
|
+
imageEditorBrowseFoldersButtonLabel: 'Browse',
|
|
4
|
+
imageEditorNoCloudimgTokenInfo: 'No cloudimage token is provided, so it is not possible to edit the URL.',
|
|
5
|
+
imageEditorChooseFolderPathTitle: 'Choose folder path',
|
|
6
|
+
imageEditorSelectFolderTitle: 'Select folder',
|
|
7
|
+
mutualizedSelectLabel: 'Select',
|
|
8
|
+
imageEditorSaveAsNewVersionLabel: 'Save as new version',
|
|
9
|
+
imageEditorDuplicateTheImageLabel: 'Duplicate the image',
|
|
10
|
+
imageEditorInvalidImageUrl: 'Wrong image URL provided (not found or not valid).',
|
|
11
|
+
imageEditorImgPreparationForEditInfo: 'Please wait, Image is being prepared for editing...',
|
|
12
|
+
imageEditorImgNewVersionStartedUploading: 'New version started uploading'
|
|
13
|
+
};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
5
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
6
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
7
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
8
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
9
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
10
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
11
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
12
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
13
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
14
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
16
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
17
|
+
import { Plugin } from '@scaleflex/widget-core';
|
|
18
|
+
import Explorer from '@scaleflex/widget-explorer';
|
|
19
|
+
import isImage from '@scaleflex/widget-utils/lib/isImage';
|
|
20
|
+
import Translator from '@scaleflex/widget-utils/lib/Translator';
|
|
21
|
+
import { PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants';
|
|
22
|
+
import { selectUploadsCount } from '@scaleflex/widget-core/lib/slices/uploads.slice';
|
|
23
|
+
import { imageEditorOpened, selectImageEditorFile } from '@scaleflex/widget-explorer/lib/slices/panels.slice';
|
|
24
|
+
import ImageEditorUI from './ImageEditor';
|
|
25
|
+
import defaultLocale from './defaultLocale';
|
|
26
|
+
// TODO: find a way to show version of the current plugin
|
|
27
|
+
// why solution below isn't good?
|
|
28
|
+
// first import doesn't work with webpack 5 as it was deprecated
|
|
29
|
+
// second import fixes webpack 5 issue as it was mentioned in their docs
|
|
30
|
+
// but it exposes our package.json to the client and it is mentioned as security rist in mutiple places
|
|
31
|
+
// https://github.com/axelpale/genversion
|
|
32
|
+
// https://stackoverflow.com/questions/64993118/error-should-not-import-the-named-export-version-imported-as-version
|
|
33
|
+
// https://stackoverflow.com/questions/9153571/is-there-a-way-to-get-version-from-package-json-in-nodejs-code/10855054#10855054
|
|
34
|
+
// import { version } from '../package.json'
|
|
35
|
+
// import packageInfo from '../package.json'
|
|
36
|
+
var ImageEditor = /*#__PURE__*/function (_Plugin) {
|
|
37
|
+
// static VERSION = packageInfo.version
|
|
38
|
+
|
|
39
|
+
function ImageEditor(filerobot) {
|
|
40
|
+
var _this;
|
|
41
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
42
|
+
_classCallCheck(this, ImageEditor);
|
|
43
|
+
_this = _callSuper(this, ImageEditor, [filerobot, opts]);
|
|
44
|
+
_defineProperty(_this, "forceOpenImgEditor", function (file) {
|
|
45
|
+
if (isImage(file) && selectUploadsCount(_this.getGlobalState()) === 1) {
|
|
46
|
+
_this.dispatch(imageEditorOpened({
|
|
47
|
+
file: file,
|
|
48
|
+
showBackButton: 'auto'
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
_defineProperty(_this, "closeImgEditor", function (closeReason) {
|
|
53
|
+
// If the force open for image editor enabled, and user closed the image editor then remove the image as it is not saved from image editor.
|
|
54
|
+
if (closeReason && _this.opts.forceOpenOnImgAddedToUpload && selectUploadsCount(_this.getGlobalState()) > 0) {
|
|
55
|
+
_this.filerobot.removeUploads(selectImageEditorFile(_this.getGlobalState()));
|
|
56
|
+
}
|
|
57
|
+
_this.dispatch(imageEditorOpened({
|
|
58
|
+
file: null,
|
|
59
|
+
showBackButton: 'auto'
|
|
60
|
+
}));
|
|
61
|
+
});
|
|
62
|
+
_defineProperty(_this, "render", function (props) {
|
|
63
|
+
return ImageEditorUI(_objectSpread(_objectSpread({}, props), {}, {
|
|
64
|
+
closeEditor: _this.closeImgEditor,
|
|
65
|
+
opts: _this.opts,
|
|
66
|
+
i18n: _this.i18n
|
|
67
|
+
}));
|
|
68
|
+
});
|
|
69
|
+
_this.id = PLUGINS_IDS.IMAGE_EDITOR;
|
|
70
|
+
_this.title = 'Image Editor';
|
|
71
|
+
_this.type = 'editor';
|
|
72
|
+
_this.defaultLocale = {
|
|
73
|
+
strings: defaultLocale
|
|
74
|
+
};
|
|
75
|
+
_this.i18nInit();
|
|
76
|
+
_this.opts = _objectSpread(_objectSpread({
|
|
77
|
+
forceOpenOnImgAddedToUpload: false
|
|
78
|
+
}, opts), {}, {
|
|
79
|
+
cloudimage: _objectSpread(_objectSpread({
|
|
80
|
+
token: filerobot.opts.container
|
|
81
|
+
}, opts.cloudimage), {}, {
|
|
82
|
+
dontPrefixUrl: true
|
|
83
|
+
}),
|
|
84
|
+
showBackButton: true
|
|
85
|
+
});
|
|
86
|
+
return _this;
|
|
87
|
+
}
|
|
88
|
+
_inherits(ImageEditor, _Plugin);
|
|
89
|
+
return _createClass(ImageEditor, [{
|
|
90
|
+
key: "i18nInit",
|
|
91
|
+
value: function i18nInit() {
|
|
92
|
+
this.translator = new Translator([this.defaultLocale, this.filerobot.locale, this.opts.locale]);
|
|
93
|
+
this.i18n = this.translator.translate.bind(this.translator);
|
|
94
|
+
this.i18nArray = this.translator.translateArray.bind(this.translator);
|
|
95
|
+
}
|
|
96
|
+
}, {
|
|
97
|
+
key: "install",
|
|
98
|
+
value: function install() {
|
|
99
|
+
var _this2 = this;
|
|
100
|
+
if (Explorer) {
|
|
101
|
+
this.mount(Explorer, this);
|
|
102
|
+
if (this.opts.forceOpenOnImgAddedToUpload) {
|
|
103
|
+
this.filerobot.on('file-added', this.forceOpenImgEditor);
|
|
104
|
+
}
|
|
105
|
+
if (this.opts.forceOpenAfterUpload) {
|
|
106
|
+
this.filerobot.on('complete', function (_ref) {
|
|
107
|
+
var successful = _ref.successful;
|
|
108
|
+
return _this2.forceOpenImgEditor(successful === null || successful === void 0 ? void 0 : successful[0]);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "uninstall",
|
|
115
|
+
value: function uninstall() {
|
|
116
|
+
this.unmount();
|
|
117
|
+
if (this.opts.forceOpenOnImgAddedToUpload) {
|
|
118
|
+
this.filerobot.off('file-added', this.forceOpenImgEditor);
|
|
119
|
+
}
|
|
120
|
+
if (this.opts.forceOpenAfterUpload) {
|
|
121
|
+
this.filerobot.off('complete', this.forceOpenImgEditor);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}]);
|
|
125
|
+
}(Plugin);
|
|
126
|
+
export default ImageEditor;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleflex/widget-image-editor",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "FilerobotImageEditor integration with Scaleflex",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@scaleflex/icons": "^3.0.0-beta.11",
|
|
17
17
|
"@scaleflex/ui": "^3.0.0-beta.11",
|
|
18
|
-
"@scaleflex/widget-common": "^4.
|
|
19
|
-
"@scaleflex/widget-icons": "^4.
|
|
20
|
-
"@scaleflex/widget-utils": "^4.
|
|
18
|
+
"@scaleflex/widget-common": "^4.5.0",
|
|
19
|
+
"@scaleflex/widget-icons": "^4.5.0",
|
|
20
|
+
"@scaleflex/widget-utils": "^4.5.0",
|
|
21
21
|
"react-filerobot-image-editor": "5.0.0-beta.93",
|
|
22
22
|
"react-filerobot-video-editor": "1.1.3"
|
|
23
23
|
},
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"react-konva": ">=19.0.3",
|
|
36
36
|
"react-redux": "^8.1.1"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "df64ca68034ed6c33e123e7dfa215176aa0a1196"
|
|
39
39
|
}
|