@scaleflex/widget-preupload-processors 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,95 @@
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
+ import { useDispatch, useSelector } from 'react-redux';
8
+ import ProcessSelect from './ProcessSelect';
9
+ import Styled from './PreProcessor.styled';
10
+ import { preUpProcessorsCommonStateUpdated, selectPreUpProcessorsCommonState } from '../common.slice';
11
+ import ProcessorToggle from './ProcessorToggle';
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ var VideoProcessor = function VideoProcessor(_ref) {
14
+ var i18n = _ref.i18n,
15
+ pluginOpts = _ref.pluginOpts;
16
+ var dispatch = useDispatch();
17
+ var isVideoProcessActive = useSelector(function (state) {
18
+ return selectPreUpProcessorsCommonState(state).isVideoProcessActive;
19
+ });
20
+ var videoTranscoding = useSelector(function (state) {
21
+ return selectPreUpProcessorsCommonState(state).videoTranscoding;
22
+ });
23
+ var videoTranscodingOptions = pluginOpts.videoTranscodingOptions;
24
+ var toggleVideoProcessor = function toggleVideoProcessor(e) {
25
+ dispatch(preUpProcessorsCommonStateUpdated({
26
+ isVideoProcessActive: e.target.checked
27
+ }));
28
+ };
29
+ var updateVideoTranscoding = function updateVideoTranscoding(newState) {
30
+ dispatch(preUpProcessorsCommonStateUpdated({
31
+ videoTranscoding: _objectSpread(_objectSpread({}, videoTranscoding), newState)
32
+ }));
33
+ };
34
+ var renderVideoProtocols = function renderVideoProtocols() {
35
+ var protocols = videoTranscodingOptions.protocols;
36
+ var updateProtocol = function updateProtocol(protocol) {
37
+ updateVideoTranscoding({
38
+ protocol: protocol
39
+ });
40
+ };
41
+ return /*#__PURE__*/_jsxs("div", {
42
+ children: [/*#__PURE__*/_jsx(Styled.UploadOptionLabel, {
43
+ disabled: !isVideoProcessActive,
44
+ children: i18n('preuploadProtocolsText')
45
+ }), /*#__PURE__*/_jsx(Styled.Protocols, {
46
+ children: protocols.map(function (protocol) {
47
+ return /*#__PURE__*/_jsx(Styled.ProtocolWrapper, {
48
+ children: /*#__PURE__*/_jsx(Styled.ProtocolsRadio, {
49
+ size: "md",
50
+ disabled: !isVideoProcessActive,
51
+ checked: videoTranscoding.protocol.toLowerCase() === protocol.value.toLowerCase(),
52
+ label: protocol.label,
53
+ onChange: function onChange() {
54
+ return updateProtocol(protocol.value);
55
+ },
56
+ labelStyle: {
57
+ marginBottom: 2,
58
+ fontSize: 16,
59
+ lineHeight: '18px'
60
+ }
61
+ })
62
+ }, protocol.value);
63
+ })
64
+ })]
65
+ });
66
+ };
67
+ var renderVideoResolution = function renderVideoResolution() {
68
+ var resolutionSelectProps = {
69
+ title: i18n('preuploadVideoResolutionTitle'),
70
+ options: videoTranscodingOptions.resolutions,
71
+ value: videoTranscoding.resolution,
72
+ onChange: function onChange(resolution) {
73
+ return updateVideoTranscoding({
74
+ resolution: resolution
75
+ });
76
+ },
77
+ description: i18n('preuploadVideoResolutionText'),
78
+ disabled: !isVideoProcessActive
79
+ };
80
+ return /*#__PURE__*/_jsx(ProcessSelect, _objectSpread({}, resolutionSelectProps));
81
+ };
82
+ return /*#__PURE__*/_jsxs(Styled.SettingsContainer, {
83
+ children: [/*#__PURE__*/_jsx(Styled.UploadProcessorTitle, {
84
+ children: i18n('preuploadOptimizeVideoTitle')
85
+ }), /*#__PURE__*/_jsx(ProcessorToggle, {
86
+ toggleText: i18n('preuploadOptimizeVideoSubTitle'),
87
+ tooltipText: i18n('preuploadQuickUploadModeHint'),
88
+ isProcessActive: isVideoProcessActive,
89
+ toggleProcessor: toggleVideoProcessor
90
+ }), /*#__PURE__*/_jsxs(Styled.OperationsContainer, {
91
+ children: [renderVideoResolution(), renderVideoProtocols()]
92
+ })]
93
+ });
94
+ };
95
+ export default VideoProcessor;
@@ -0,0 +1,27 @@
1
+ export default {
2
+ preuploadUploadSettingsLabel: 'Upload Settings',
3
+ preuploadQuickUploadModeLabel: 'Quick upload mode',
4
+ preuploadQuickUploadModeHint: 'In quick mode, the file is send, but the file is still in being processed and will not be visible in the Filerobot infra before its finished. Its useful for uploading big files to not have freezing behaviour',
5
+ preuploadOptimizeImagesLabel: 'Optimize image(s)',
6
+ preuploadImageOperationLabel: 'Operation',
7
+ preuploadImageOperationText: 'Operation that is being applied automatically before passing the image to uploading stage',
8
+ preuploadTranscodeLabel: 'Transcode video(s)',
9
+ preuploadVideoResolutionTitle: 'Resolution',
10
+ preuploadVideoResolutionText: 'The resolution of video transcoding',
11
+ preuploadProtocolsText: 'Protocols',
12
+ preuploadMaxWidth: 'Max Width',
13
+ preuploadMaxHeight: 'Max Height',
14
+ preuploadOptimizeImagesTitle: 'Image settings',
15
+ preuploadOptimizeImagesSubTitle: 'Resize Images',
16
+ preuploadOptimizeVideoTitle: 'Video settings',
17
+ preuploadOptimizeVideoSubTitle: 'Transcode video',
18
+ preuploadResumableUploadTitle: 'Resumable upload',
19
+ preuploadAssetsTransformationsLabel: 'Transformations',
20
+ preuploadAssetsTransformationsHint: 'Transformations are dynamically created variants based on image presets.',
21
+ preuploadAssetsTransformationsPresetsLabel: 'Presets',
22
+ preuploadAssetsTransformationsPresetPlaceholder: 'Select preset',
23
+ preuploadAssetsTransformationsPresetShowMore: 'more',
24
+ preuploadResumableUploadInfo: '(experimental feature) Resumable file transfer protocol designed to ensure smooth and efficient file uploads. Adds the functionality to pause and resume upload, optimizing data delivery for a seamless experience.',
25
+ preuploadResumableUploadBetaTitle: 'Beta',
26
+ preuploadResumableUploadBetaMsg: 'This functionality is in Beta and may not work in all cases until official release'
27
+ };
package/lib/index.js ADDED
@@ -0,0 +1,175 @@
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 _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
+ 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; }
4
+ 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; }
5
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
6
+ 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); } }
7
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
8
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
9
+ 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); }
10
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
11
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
12
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
13
+ 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); }
14
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
15
+ 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; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
17
+ 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); }
18
+ import { createElement } from 'react';
19
+ import { Plugin } from '@scaleflex/widget-core';
20
+ import Translator from '@scaleflex/widget-utils/lib/Translator';
21
+ import { PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants';
22
+ import defaultLocale from './defaultLocale';
23
+ import DEFAULT_VIDEO_TRANSCODING from './DEFAULT_VIDEO_TRANSCODING';
24
+ import ProcessorsUI from './components/ProcessorsUI';
25
+ import preUploadProcessorsReducer, { preUpProcessorsCommonStateUpdated, selectPreUpProcessorsCommonState } from './common.slice';
26
+ var PreUploadProcessors = /*#__PURE__*/function (_Plugin) {
27
+ function PreUploadProcessors(filerobot) {
28
+ var _this;
29
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
30
+ _classCallCheck(this, PreUploadProcessors);
31
+ _this = _callSuper(this, PreUploadProcessors, [filerobot, opts]);
32
+ _defineProperty(_this, "_pluginObject", void 0);
33
+ _defineProperty(_this, "triggerImageProcessor", function (filesIds) {
34
+ var _selectPreUpProcessor = selectPreUpProcessorsCommonState(_this.getGlobalState()),
35
+ imageOperation = _selectPreUpProcessor.imageOperation,
36
+ isImageProcessActive = _selectPreUpProcessor.isImageProcessActive,
37
+ isUserAllowedToOptimize = _selectPreUpProcessor.isUserAllowedToOptimize;
38
+ _this.filerobot.setCoreCommonState({
39
+ imageProcessor: _objectSpread(_objectSpread({}, imageOperation), {}, {
40
+ isImageProcessActive: isImageProcessActive,
41
+ isUserAllowedToOptimize: isUserAllowedToOptimize,
42
+ filesIds: filesIds
43
+ })
44
+ });
45
+ });
46
+ _defineProperty(_this, "triggerVideoProcessor", function (filesIds) {
47
+ var _selectPreUpProcessor2 = selectPreUpProcessorsCommonState(_this.getGlobalState()),
48
+ videoTranscoding = _selectPreUpProcessor2.videoTranscoding,
49
+ isUserAllowedToOptimize = _selectPreUpProcessor2.isUserAllowedToOptimize,
50
+ isVideoProcessActive = _selectPreUpProcessor2.isVideoProcessActive;
51
+ _this.filerobot.setCoreCommonState({
52
+ videoTranscoding: _objectSpread(_objectSpread({}, videoTranscoding), {}, {
53
+ isUserAllowedToOptimize: isUserAllowedToOptimize,
54
+ isVideoProcessActive: isVideoProcessActive,
55
+ filesIds: filesIds
56
+ })
57
+ });
58
+ });
59
+ _defineProperty(_this, "resetState", function () {
60
+ _this.dispatch(preUpProcessorsCommonStateUpdated(_this.defaultPluginState));
61
+ });
62
+ _this.id = PLUGINS_IDS.PREUPLOAD_PROCESSORS;
63
+ _this.type = 'modifier';
64
+ _this.invisible = false;
65
+ _this.defaultLocale = {
66
+ strings: defaultLocale
67
+ };
68
+ var defaultOptions = {
69
+ imageProcessorByDefault: false,
70
+ videoProcessorByDefault: false,
71
+ imageOperations: null,
72
+ videoTranscodingOptions: DEFAULT_VIDEO_TRANSCODING
73
+ };
74
+ _this.getPluginObject = _this.getPluginObject.bind(_this);
75
+ _this.areThereOperations = _this.areThereOperations.bind(_this);
76
+ _this.render = _this.render.bind(_this);
77
+ _this.i18nInit();
78
+ _this.opts = _extends({}, defaultOptions, opts);
79
+ _this.handleProcess = _this.handleProcess.bind(_this);
80
+ return _this;
81
+ }
82
+ _inherits(PreUploadProcessors, _Plugin);
83
+ return _createClass(PreUploadProcessors, [{
84
+ key: "i18nInit",
85
+ value: function i18nInit() {
86
+ this.translator = new Translator([this.defaultLocale, this.filerobot.locale, this.opts.locale]);
87
+ this.i18n = this.translator.translate.bind(this.translator);
88
+ }
89
+ }, {
90
+ key: "handleProcess",
91
+ value: function handleProcess(filesIds) {
92
+ filesIds = filesIds.filter(function (file) {
93
+ return !file.error;
94
+ });
95
+ this.triggerImageProcessor(filesIds);
96
+ this.triggerVideoProcessor(filesIds);
97
+ }
98
+ }, {
99
+ key: "areThereOperations",
100
+ value: function areThereOperations() {
101
+ return this.opts.imageOperations && Object.keys(this.opts.imageOperations).length > 0;
102
+ }
103
+ }, {
104
+ key: "getPluginObject",
105
+ value: function getPluginObject() {
106
+ if (!this._pluginObject) {
107
+ this._pluginObject = {
108
+ render: this.render,
109
+ process: this.handleProcess
110
+ };
111
+ }
112
+ return this._pluginObject;
113
+ }
114
+ }, {
115
+ key: "getOperationOptionsFirstValues",
116
+ value: function getOperationOptionsFirstValues(operation) {
117
+ var optionValues = {};
118
+ Object.keys(operation).forEach(function (optionKey) {
119
+ optionValues[optionKey] = operation[optionKey];
120
+ });
121
+ return optionValues;
122
+ }
123
+ }, {
124
+ key: "install",
125
+ value: function install() {
126
+ if (this.areThereOperations()) {
127
+ this.filerobot.addPreProcessor(this.getPluginObject());
128
+ var firstOperationKey = Object.keys(this.opts.imageOperations)[0];
129
+ this.defaultPluginState = {
130
+ imageOperation: {
131
+ name: firstOperationKey,
132
+ values: this.getOperationOptionsFirstValues(this.opts.imageOperations[firstOperationKey]),
133
+ isRatioLocked: true
134
+ },
135
+ videoTranscoding: {
136
+ resolution: this.opts.videoTranscodingOptions.defaultResolution,
137
+ protocol: this.opts.videoTranscodingOptions.defaultProtocol
138
+ },
139
+ isImageProcessActive: this.opts.imageProcessorByDefault,
140
+ isUserAllowedToOptimize: this.opts.imageProcessorUserAllowance,
141
+ isVideoProcessActive: this.opts.videoProcessorByDefault
142
+ };
143
+ this.resetState();
144
+ this.filerobot.on('cancel-uploads', this.resetState);
145
+ }
146
+ }
147
+ }, {
148
+ key: "uninstall",
149
+ value: function uninstall() {
150
+ this.filerobot.removePreProcessor(this.getPluginObject());
151
+ this.filerobot.off('cancel-uploads', this.resetState);
152
+ }
153
+ }, {
154
+ key: "getPluginReducer",
155
+ value: function getPluginReducer() {
156
+ return preUploadProcessorsReducer;
157
+ }
158
+ }, {
159
+ key: "render",
160
+ value: function render(_state) {
161
+ if (_state.autoProceed) {
162
+ return null;
163
+ }
164
+ if (this.areThereOperations()) {
165
+ // we're using createElement here as ProcessorsUI contains react's hooks and we need this to be considered as react component
166
+
167
+ return /*#__PURE__*/createElement(ProcessorsUI, {
168
+ i18n: this.i18n,
169
+ pluginOpts: this.opts
170
+ });
171
+ }
172
+ }
173
+ }]);
174
+ }(Plugin);
175
+ export default PreUploadProcessors;
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@scaleflex/widget-preupload-processors",
3
+ "version": "0.0.1",
4
+ "description": "Scaleflex preupload-processors module.",
5
+ "main": "lib/index.js",
6
+ "types": "types/index.d.ts",
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-tus": "^0.0.1",
21
+ "@scaleflex/widget-utils": "^0.0.1"
22
+ },
23
+ "devDependencies": {
24
+ "react": "^19.0.0",
25
+ "react-dom": "^19.0.0"
26
+ },
27
+ "peerDependencies": {
28
+ "@scaleflex/widget-core": "^0.0.0",
29
+ "react": ">=19.0.0",
30
+ "react-dom": ">=19.0.0"
31
+ },
32
+ "license": "MIT",
33
+ "gitHead": "64ea82e745b7deda36d6794863350e6671e9010d"
34
+ }