Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rpldy/upload-preview

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rpldy/upload-preview - npm Package Compare versions

Comparing version 0.11.4 to 0.11.5

2

lib/cjs/consts.js

@@ -7,3 +7,3 @@ "use strict";

exports.PREVIEW_TYPES = void 0;
var PREVIEW_TYPES = {
const PREVIEW_TYPES = {
IMAGE: "image",

@@ -10,0 +10,0 @@ VIDEO: "video"

@@ -10,3 +10,3 @@ "use strict";

var PREVIEW_DEFAULTS = (0, _shared.devFreeze)({
const PREVIEW_DEFAULTS = (0, _shared.devFreeze)({
rememberPreviousBatches: false,

@@ -13,0 +13,0 @@ loadFirstOnly: false,

@@ -8,4 +8,4 @@ "use strict";

enumerable: true,
get: function get() {
return _UploadPreview["default"];
get: function () {
return _UploadPreview.default;
}

@@ -15,7 +15,7 @@ });

enumerable: true,
get: function get() {
get: function () {
return _consts.PREVIEW_TYPES;
}
});
exports["default"] = void 0;
exports.default = void 0;

@@ -26,5 +26,5 @@ var _UploadPreview = _interopRequireDefault(require("./UploadPreview"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = _UploadPreview["default"];
exports["default"] = _default;
var _default = _UploadPreview.default;
exports.default = _default;
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _usePreviewsLoader2 = _interopRequireDefault(require("./usePreviewsLoader"));
var _usePreviewsLoader = _interopRequireDefault(require("./usePreviewsLoader"));

@@ -18,33 +16,25 @@ var _utils = require("./utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var showBasicPreview = function (type, url, previewProps, onImgError) {
return type === _consts.PREVIEW_TYPES.VIDEO ? /*#__PURE__*/_react["default"].createElement("video", _extends({
key: url,
src: url,
controls: true
}, previewProps)) : /*#__PURE__*/_react["default"].createElement("img", _extends({
key: url,
onError: onImgError,
src: url
}, previewProps));
};
const showBasicPreview = (type, url, previewProps, onImgError) => type === _consts.PREVIEW_TYPES.VIDEO ? /*#__PURE__*/_react.default.createElement("video", _extends({
key: url,
src: url,
controls: true
}, previewProps)) : /*#__PURE__*/_react.default.createElement("img", _extends({
key: url,
onError: onImgError,
src: url
}, previewProps));
var usePreviewMethods = function (previews, clearPreviews, previewMethodsRef, onPreviewsChanged) {
(0, _react.useImperativeHandle)(previewMethodsRef, function () {
return {
clear: clearPreviews
};
}, [clearPreviews]);
(0, _react.useEffect)(function () {
const usePreviewMethods = (previews, clearPreviews, previewMethodsRef, onPreviewsChanged) => {
(0, _react.useImperativeHandle)(previewMethodsRef, () => ({
clear: clearPreviews
}), [clearPreviews]);
(0, _react.useEffect)(() => {
if (onPreviewsChanged) {

@@ -56,16 +46,17 @@ onPreviewsChanged(previews);

var UploadPreview = function (props) {
var PreviewComponent = props.PreviewComponent,
previewMethodsRef = props.previewMethodsRef,
onPreviewsChanged = props.onPreviewsChanged,
previewOptions = _objectWithoutProperties(props, ["PreviewComponent", "previewMethodsRef", "onPreviewsChanged"]);
const UploadPreview = props => {
const {
PreviewComponent,
previewMethodsRef,
onPreviewsChanged,
...previewOptions
} = props;
const {
previews,
clearPreviews
} = (0, _usePreviewsLoader.default)(previewOptions);
const onImagePreviewLoadError = (0, _react.useCallback)(e => {
const img = e.target;
const fallback = (0, _utils.getFallbackUrlData)(props.fallbackUrl, img.src);
var _usePreviewsLoader = (0, _usePreviewsLoader2["default"])(previewOptions),
previews = _usePreviewsLoader.previews,
clearPreviews = _usePreviewsLoader.clearPreviews;
var onImagePreviewLoadError = (0, _react.useCallback)(function (e) {
var img = e.target;
var fallback = (0, _utils.getFallbackUrlData)(props.fallbackUrl, img.src);
if (fallback) {

@@ -76,10 +67,12 @@ img.src = fallback.url;

usePreviewMethods(previews, clearPreviews, previewMethodsRef, onPreviewsChanged);
return previews.map(function (data) {
var id = data.id,
url = data.url,
type = data.type,
name = data.name,
isFallback = data.isFallback,
previewProps = data.props;
return PreviewComponent ? /*#__PURE__*/_react["default"].createElement(PreviewComponent, _extends({
return previews.map(data => {
const {
id,
url,
type,
name,
isFallback,
props: previewProps
} = data;
return PreviewComponent ? /*#__PURE__*/_react.default.createElement(PreviewComponent, _extends({
key: id + url,

@@ -96,2 +89,2 @@ id: id,

var _default = UploadPreview;
exports["default"] = _default;
exports.default = _default;

@@ -6,3 +6,3 @@ "use strict";

});
exports["default"] = void 0;
exports.default = void 0;

@@ -19,23 +19,5 @@ var _react = require("react");

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
const getFilePreviewUrl = (file, options) => {
let data = (0, _utils.getFileObjectUrlByType)(_consts.PREVIEW_TYPES.IMAGE, options.imageMimeTypes, options.maxPreviewImageSize || 0, file);
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."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var getFilePreviewUrl = function (file, options) {
var data = (0, _utils.getFileObjectUrlByType)(_consts.PREVIEW_TYPES.IMAGE, options.imageMimeTypes, options.maxPreviewImageSize || 0, file);
if (!data) {

@@ -48,4 +30,4 @@ data = (0, _utils.getFileObjectUrlByType)(_consts.PREVIEW_TYPES.VIDEO, options.videoMimeTypes, options.maxPreviewVideoSize || 0, file);

var loadPreviewData = function (item, options, previewComponentProps) {
var data,
const loadPreviewData = (item, options, previewComponentProps) => {
let data,
props,

@@ -55,3 +37,3 @@ isFallback = false;

if (item.file) {
var file = item.file;
const file = item.file;
data = getFilePreviewUrl(item.file, options);

@@ -72,22 +54,21 @@

if (data) {
var _data = data,
url = _data.url,
type = _data.type;
const {
url,
type
} = data;
props = (0, _shared.isFunction)(previewComponentProps) ? previewComponentProps(item, url, type) : previewComponentProps;
}
return data && _objectSpread(_objectSpread({}, data), {}, {
return data && { ...data,
id: item.id,
isFallback: isFallback,
props: props
});
isFallback,
props
};
};
var mergePreviewData = function (prev, next) {
var newItems = []; //dedupe and merge new with existing
const mergePreviewData = (prev, next) => {
const newItems = []; //dedupe and merge new with existing
next.forEach(function (n) {
var existingIndex = prev.findIndex(function (p) {
return p.id === n.id;
});
next.forEach(n => {
const existingIndex = prev.findIndex(p => p.id === n.id);

@@ -103,25 +84,19 @@ if (~existingIndex) {

var _default = function _default(props) {
var _useState = (0, _react.useState)([]),
_useState2 = _slicedToArray(_useState, 2),
previews = _useState2[0],
setPreviews = _useState2[1];
var previewOptions = (0, _utils.getWithMandatoryOptions)(props);
var clearPreviews = (0, _react.useCallback)(function () {
var _default = props => {
const [previews, setPreviews] = (0, _react.useState)([]);
const previewOptions = (0, _utils.getWithMandatoryOptions)(props);
const clearPreviews = (0, _react.useCallback)(() => {
setPreviews([]);
}, []);
(0, _sharedUi.useBatchStartListener)(function (batch) {
var items = previewOptions.loadFirstOnly ? batch.items.slice(0, 1) : batch.items;
var previewsData = items.map(function (item) {
return loadPreviewData(item, previewOptions, props.previewComponentProps);
}).filter(Boolean);
(0, _sharedUi.useBatchStartListener)(batch => {
const items = previewOptions.loadFirstOnly ? batch.items.slice(0, 1) : batch.items;
const previewsData = items.map(item => loadPreviewData(item, previewOptions, props.previewComponentProps)).filter(Boolean);
setPreviews(props.rememberPreviousBatches ? mergePreviewData(previews, previewsData) : previewsData);
});
return {
previews: previews,
clearPreviews: clearPreviews
previews,
clearPreviews
};
};
exports["default"] = _default;
exports.default = _default;

@@ -8,3 +8,3 @@ "use strict";

enumerable: true,
get: function get() {
get: function () {
return _shared.isFunction;

@@ -21,10 +21,6 @@ }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var getWithMandatoryOptions = function (options) {
return _objectSpread(_objectSpread({}, _defaults.PREVIEW_DEFAULTS), options);
const getWithMandatoryOptions = options => {
return { ..._defaults.PREVIEW_DEFAULTS,
...options
};
};

@@ -34,4 +30,4 @@

var getFallbackUrlData = function (fallbackProp, file) {
var data = (0, _shared.isFunction)(fallbackProp) ? fallbackProp(file) : fallbackProp;
const getFallbackUrlData = (fallbackProp, file) => {
let data = (0, _shared.isFunction)(fallbackProp) ? fallbackProp(file) : fallbackProp;

@@ -52,4 +48,4 @@ if (typeof data === "string") {

var getFileObjectUrlByType = function (type, mimeTypes, max, file) {
var data;
const getFileObjectUrlByType = (type, mimeTypes, max, file) => {
let data;

@@ -61,3 +57,3 @@ if (mimeTypes && ~mimeTypes.indexOf(file.type)) {

name: file.name,
type: type
type
};

@@ -64,0 +60,0 @@ }

@@ -1,4 +0,4 @@

export var PREVIEW_TYPES = {
export const PREVIEW_TYPES = {
IMAGE: "image",
VIDEO: "video"
};
import { devFreeze } from "@rpldy/shared";
export var PREVIEW_DEFAULTS = devFreeze({
export const PREVIEW_DEFAULTS = devFreeze({
rememberPreviousBatches: false,

@@ -4,0 +4,0 @@ loadFirstOnly: false,

@@ -1,5 +0,1 @@

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

@@ -12,21 +8,17 @@

var showBasicPreview = function (type, url, previewProps, onImgError) {
return type === PREVIEW_TYPES.VIDEO ? /*#__PURE__*/React.createElement("video", _extends({
key: url,
src: url,
controls: true
}, previewProps)) : /*#__PURE__*/React.createElement("img", _extends({
key: url,
onError: onImgError,
src: url
}, previewProps));
};
const showBasicPreview = (type, url, previewProps, onImgError) => type === PREVIEW_TYPES.VIDEO ? /*#__PURE__*/React.createElement("video", _extends({
key: url,
src: url,
controls: true
}, previewProps)) : /*#__PURE__*/React.createElement("img", _extends({
key: url,
onError: onImgError,
src: url
}, previewProps));
var usePreviewMethods = function (previews, clearPreviews, previewMethodsRef, onPreviewsChanged) {
useImperativeHandle(previewMethodsRef, function () {
return {
clear: clearPreviews
};
}, [clearPreviews]);
useEffect(function () {
const usePreviewMethods = (previews, clearPreviews, previewMethodsRef, onPreviewsChanged) => {
useImperativeHandle(previewMethodsRef, () => ({
clear: clearPreviews
}), [clearPreviews]);
useEffect(() => {
if (onPreviewsChanged) {

@@ -38,16 +30,17 @@ onPreviewsChanged(previews);

var UploadPreview = function (props) {
var PreviewComponent = props.PreviewComponent,
previewMethodsRef = props.previewMethodsRef,
onPreviewsChanged = props.onPreviewsChanged,
previewOptions = _objectWithoutProperties(props, ["PreviewComponent", "previewMethodsRef", "onPreviewsChanged"]);
const UploadPreview = props => {
const {
PreviewComponent,
previewMethodsRef,
onPreviewsChanged,
...previewOptions
} = props;
const {
previews,
clearPreviews
} = usePreviewsLoader(previewOptions);
const onImagePreviewLoadError = useCallback(e => {
const img = e.target;
const fallback = getFallbackUrlData(props.fallbackUrl, img.src);
var _usePreviewsLoader = usePreviewsLoader(previewOptions),
previews = _usePreviewsLoader.previews,
clearPreviews = _usePreviewsLoader.clearPreviews;
var onImagePreviewLoadError = useCallback(function (e) {
var img = e.target;
var fallback = getFallbackUrlData(props.fallbackUrl, img.src);
if (fallback) {

@@ -58,9 +51,11 @@ img.src = fallback.url;

usePreviewMethods(previews, clearPreviews, previewMethodsRef, onPreviewsChanged);
return previews.map(function (data) {
var id = data.id,
url = data.url,
type = data.type,
name = data.name,
isFallback = data.isFallback,
previewProps = data.props;
return previews.map(data => {
const {
id,
url,
type,
name,
isFallback,
props: previewProps
} = data;
return PreviewComponent ? /*#__PURE__*/React.createElement(PreviewComponent, _extends({

@@ -67,0 +62,0 @@ key: id + url,

@@ -1,19 +0,1 @@

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
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."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import { useState, useCallback } from "react";

@@ -25,4 +7,4 @@ import { isFunction } from "@rpldy/shared";

var getFilePreviewUrl = function (file, options) {
var data = getFileObjectUrlByType(PREVIEW_TYPES.IMAGE, options.imageMimeTypes, options.maxPreviewImageSize || 0, file);
const getFilePreviewUrl = (file, options) => {
let data = getFileObjectUrlByType(PREVIEW_TYPES.IMAGE, options.imageMimeTypes, options.maxPreviewImageSize || 0, file);

@@ -36,4 +18,4 @@ if (!data) {

var loadPreviewData = function (item, options, previewComponentProps) {
var data,
const loadPreviewData = (item, options, previewComponentProps) => {
let data,
props,

@@ -43,3 +25,3 @@ isFallback = false;

if (item.file) {
var file = item.file;
const file = item.file;
data = getFilePreviewUrl(item.file, options);

@@ -60,22 +42,21 @@

if (data) {
var _data = data,
url = _data.url,
type = _data.type;
const {
url,
type
} = data;
props = isFunction(previewComponentProps) ? previewComponentProps(item, url, type) : previewComponentProps;
}
return data && _objectSpread(_objectSpread({}, data), {}, {
return data && { ...data,
id: item.id,
isFallback: isFallback,
props: props
});
isFallback,
props
};
};
var mergePreviewData = function (prev, next) {
var newItems = []; //dedupe and merge new with existing
const mergePreviewData = (prev, next) => {
const newItems = []; //dedupe and merge new with existing
next.forEach(function (n) {
var existingIndex = prev.findIndex(function (p) {
return p.id === n.id;
});
next.forEach(n => {
const existingIndex = prev.findIndex(p => p.id === n.id);

@@ -91,23 +72,17 @@ if (~existingIndex) {

export default (function (props) {
var _useState = useState([]),
_useState2 = _slicedToArray(_useState, 2),
previews = _useState2[0],
setPreviews = _useState2[1];
var previewOptions = getWithMandatoryOptions(props);
var clearPreviews = useCallback(function () {
export default (props => {
const [previews, setPreviews] = useState([]);
const previewOptions = getWithMandatoryOptions(props);
const clearPreviews = useCallback(() => {
setPreviews([]);
}, []);
useBatchStartListener(function (batch) {
var items = previewOptions.loadFirstOnly ? batch.items.slice(0, 1) : batch.items;
var previewsData = items.map(function (item) {
return loadPreviewData(item, previewOptions, props.previewComponentProps);
}).filter(Boolean);
useBatchStartListener(batch => {
const items = previewOptions.loadFirstOnly ? batch.items.slice(0, 1) : batch.items;
const previewsData = items.map(item => loadPreviewData(item, previewOptions, props.previewComponentProps)).filter(Boolean);
setPreviews(props.rememberPreviousBatches ? mergePreviewData(previews, previewsData) : previewsData);
});
return {
previews: previews,
clearPreviews: clearPreviews
previews,
clearPreviews
};
});

@@ -1,7 +0,1 @@

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import { isFunction } from "@rpldy/shared";

@@ -11,8 +5,10 @@ import { PREVIEW_TYPES } from "./consts";

var getWithMandatoryOptions = function (options) {
return _objectSpread(_objectSpread({}, PREVIEW_DEFAULTS), options);
const getWithMandatoryOptions = options => {
return { ...PREVIEW_DEFAULTS,
...options
};
};
var getFallbackUrlData = function (fallbackProp, file) {
var data = isFunction(fallbackProp) ? fallbackProp(file) : fallbackProp;
const getFallbackUrlData = (fallbackProp, file) => {
let data = isFunction(fallbackProp) ? fallbackProp(file) : fallbackProp;

@@ -31,4 +27,4 @@ if (typeof data === "string") {

var getFileObjectUrlByType = function (type, mimeTypes, max, file) {
var data;
const getFileObjectUrlByType = (type, mimeTypes, max, file) => {
let data;

@@ -40,3 +36,3 @@ if (mimeTypes && ~mimeTypes.indexOf(file.type)) {

name: file.name,
type: type
type
};

@@ -43,0 +39,0 @@ }

{
"version": "0.11.4",
"version": "0.11.5",
"name": "@rpldy/upload-preview",

@@ -21,10 +21,10 @@ "description": "preview component to show image or video being uploaded",

"dependencies": {
"@rpldy/shared": "^0.11.4",
"@rpldy/shared-ui": "^0.11.4"
"@rpldy/shared": "^0.11.5",
"@rpldy/shared-ui": "^0.11.5"
},
"devDependencies": {
"@rpldy/upload-button": "^0.11.4",
"@rpldy/upload-url-input": "^0.11.4",
"@storybook/addon-knobs": "^6.1.10",
"flow-bin": "^0.146.0",
"@rpldy/upload-button": "^0.11.5",
"@rpldy/upload-url-input": "^0.11.5",
"@storybook/addon-knobs": "^6.2.1",
"flow-bin": "^0.147.0",
"react-image-crop": "^8.6.4",

@@ -40,3 +40,3 @@ "styled-components": "^5.2.0"

},
"gitHead": "ffa687483c1ff9d6d2df3c992810b030943482b6"
"gitHead": "39a78c4a9cf417433bd5989d65dc84f358952780"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc