@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.
@@ -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/lib/style.scss ADDED
@@ -0,0 +1,30 @@
1
+ // packages/@scaleflex/widget-image-editor/src/components/SaveAsModalContent.jsx
2
+ @import '@scaleflex/widget-core/lib/_variables.scss';
3
+
4
+ .filerobot-ImageEditor-SaveAsModal-fieldGroup {
5
+ text-align: left;
6
+ margin-bottom: 12px;
7
+ }
8
+
9
+ .filerobot-ImageEditor-SaveAsModal-fieldInput {
10
+ margin-top: 4px;
11
+ height: 32px;
12
+ }
13
+
14
+ .filerobot-ImageEditor-SaveAsModal-folderFieldGroup {
15
+ display: flex;
16
+ justify-content: flex-start;
17
+ align-items: center;
18
+ }
19
+
20
+ .filerobot-ImageEditor-SaveAsModal-folderPathInput {
21
+ flex-grow: 1;
22
+ border-radius: 2px 0 0 2px;
23
+ height: 100%;
24
+ }
25
+
26
+ .filerobot-ImageEditor-SaveAsModal-browseButton {
27
+ background: $active-secondary;
28
+ border-radius: 0 2px 2px 0;
29
+
30
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@scaleflex/widget-image-editor",
3
+ "version": "0.0.1",
4
+ "description": "FilerobotImageEditor integration with Scaleflex",
5
+ "license": "MIT",
6
+ "main": "lib/index.js",
7
+ "files": [
8
+ "/dist",
9
+ "/lib",
10
+ "/types"
11
+ ],
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@scaleflex/icons": "^3.0.0-beta.11",
17
+ "@scaleflex/ui": "^3.0.0-beta.11",
18
+ "@scaleflex/widget-common": "^0.0.1",
19
+ "@scaleflex/widget-icons": "^0.0.1",
20
+ "@scaleflex/widget-utils": "^0.0.1",
21
+ "react-filerobot-image-editor": "5.0.0-beta.93",
22
+ "react-filerobot-video-editor": "1.1.3"
23
+ },
24
+ "devDependencies": {
25
+ "react": "^19.0.0",
26
+ "react-dom": "^19.0.0",
27
+ "react-konva": "19.0.3"
28
+ },
29
+ "peerDependencies": {
30
+ "@reduxjs/toolkit": "^1.9.5",
31
+ "@scaleflex/widget-core": "^0.0.0",
32
+ "@scaleflex/widget-explorer": "^0.0.0",
33
+ "react": ">=19.0.0",
34
+ "react-dom": ">=19.0.0",
35
+ "react-konva": ">=19.0.3",
36
+ "react-redux": "^8.1.1"
37
+ },
38
+ "gitHead": "64ea82e745b7deda36d6794863350e6671e9010d"
39
+ }