@scaleflex/widget-image-editor 0.0.1
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 +7509 -0
- package/LICENSE +21 -0
- package/README.md +106 -0
- package/dist/style.css +22 -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/lib/style.scss +30 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 scaleflex
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# `@scaleflex/widget-image-editor`
|
|
2
|
+
|
|
3
|
+
[![Plugins][plugins-image]](#plugins)
|
|
4
|
+
[![Website][filerobot-image]][sfx-url]
|
|
5
|
+
[![Version][filerobot-version]][version-url]
|
|
6
|
+
[![Scaleflex team][made-by-image]][sfx-url]
|
|
7
|
+
[![License][license-image]][license-url]
|
|
8
|
+
[![CodeSandbox][codeSandbox-image]][codeSandbox-url]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
<div align='center'>
|
|
12
|
+
<img title="Scaleflex Widget logo" alt="Scaleflex Widget logo" src="https://cdn.scaleflex.com/plugins/filerobot-widget/assets/filerobot_widget_logo_with_fire.png?vh=b2ff09" width="140"/>
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
The image editor plugin provides different functionality for editing the image available in [Scaleflex Media Asset Widget](https://www.npmjs.com/package/@scaleflex/widget-core), gives you the possibility to add watermark, text, shapes, edit image by filters, orientations...etc.
|
|
16
|
+
|
|
17
|
+
It is required in case you need to have edit image, variants, exporting functionalities.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### NPM
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install --save @scaleflex/widget-image-editor
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Yarn
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
yarn add @scaleflex/widget-image-editor
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
then
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import ImageEditor from '@scaleflex/widget-image-editor'
|
|
37
|
+
...
|
|
38
|
+
...
|
|
39
|
+
...
|
|
40
|
+
scaleflexWidget.use(ImageEditor, propertiesObject)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### CDN
|
|
44
|
+
|
|
45
|
+
The plugin from CDN is found inside `Scaleflex` global object `Scaleflex.ImageEditor`
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
const ImageEditor = window.ScaleflexWidget.ImageEditor
|
|
49
|
+
...
|
|
50
|
+
...
|
|
51
|
+
...
|
|
52
|
+
scaleflexWidget.use(ImageEditor, propertiesObject)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Plugin's styles
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
import '@scaleflex/widget-core/dist/style.css'
|
|
59
|
+
import '@scaleflex/widget-image-editor/dist/style.css'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
or if you prefer the minified version
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
import '@scaleflex/widget-core/dist/style.min.css'
|
|
66
|
+
import '@scaleflex/widget-image-editor/dist/style.min.css'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
> The plugin's css file should be imported after the [Core's css file](../core/#modules-styles) for having the styles shown correctly.
|
|
70
|
+
|
|
71
|
+
## Properties
|
|
72
|
+
|
|
73
|
+
### `locale`
|
|
74
|
+
|
|
75
|
+
<u>Type:</u> `object`.
|
|
76
|
+
|
|
77
|
+
<u>Default:</u> default locales inside `lib/defaultLocale.js`.
|
|
78
|
+
|
|
79
|
+
Customizing some of the translations or the language's strings and replace the default locale.
|
|
80
|
+
|
|
81
|
+
### `forceOpenOnImgAddedToUpload`
|
|
82
|
+
|
|
83
|
+
<u>Type:</u> `boolean`.
|
|
84
|
+
|
|
85
|
+
<u>Default:</u> `false`
|
|
86
|
+
|
|
87
|
+
Automatically open the image editor on adding a single image in upload panel. (Note: Upload panel must contain only 1 image).
|
|
88
|
+
|
|
89
|
+
Check the rest of the options available on [**filerobot-image-editor**](https://github.com/scaleflex/filerobot-image-editor#readme)
|
|
90
|
+
|
|
91
|
+
> Note: `filerobot` object property, would be overridden internally with your `container` property & SASS key generated through `securityTemplateId` property that are provided in [@scaleflex/widget-core](../core) and cloudimage.token property's value would be the same as `container` unless you provided another value.
|
|
92
|
+
|
|
93
|
+
<!-- Variables -->
|
|
94
|
+
|
|
95
|
+
[npm-url]: https://www.npmjs.com/package/@scaleflex/widget-image-editor
|
|
96
|
+
[license-url]: https://opensource.org/licenses/MIT
|
|
97
|
+
[sfx-url]: https://www.scaleflex.com/
|
|
98
|
+
[version-url]: https://www.npmjs.com/package/@scaleflex/widget-image-editor
|
|
99
|
+
[codeSandbox-url]: https://codesandbox.io/s/filerobot-widget-v3-c5l9th
|
|
100
|
+
|
|
101
|
+
[npm-image]: https://img.shields.io/npm/v/@telus/remark-config.svg?style=for-the-badge&logo=npm
|
|
102
|
+
[license-image]: https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge
|
|
103
|
+
[made-by-image]: https://img.shields.io/badge/%3C%2F%3E%20with%20%E2%99%A5%20by-the%20Scaleflex%20team-6986fa.svg?style=for-the-badge
|
|
104
|
+
[plugins-image]: https://img.shields.io/static/v1?label=Scaleflex&message=Plugins&color=yellow&style=for-the-badge
|
|
105
|
+
[filerobot-image]: https://img.shields.io/static/v1?label=Scaleflex&message=website&color=orange&style=for-the-badge
|
|
106
|
+
[filerobot-version]: https://img.shields.io/npm/v/@scaleflex/widget-image-editor?label=Version&style=for-the-badge&logo=npm
|
package/dist/style.css
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
.filerobot-ImageEditor-SaveAsModal-fieldInput {
|
|
7
|
+
margin-top: 4px;
|
|
8
|
+
height: 32px; }
|
|
9
|
+
|
|
10
|
+
.filerobot-ImageEditor-SaveAsModal-folderFieldGroup {
|
|
11
|
+
display: flex;
|
|
12
|
+
justify-content: flex-start;
|
|
13
|
+
align-items: center; }
|
|
14
|
+
|
|
15
|
+
.filerobot-ImageEditor-SaveAsModal-folderPathInput {
|
|
16
|
+
flex-grow: 1;
|
|
17
|
+
border-radius: 2px 0 0 2px;
|
|
18
|
+
height: 100%; }
|
|
19
|
+
|
|
20
|
+
.filerobot-ImageEditor-SaveAsModal-browseButton {
|
|
21
|
+
background: #E9EEF2;
|
|
22
|
+
border-radius: 0 2px 2px 0; }
|
|
@@ -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 { Filerobot } 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 = Filerobot.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
|
+
});
|