redux-file-upload-header
Advanced tools
Comparing version 0.0.24 to 0.0.26
@@ -12,2 +12,6 @@ 'use strict'; | ||
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties'); | ||
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2); | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
@@ -23,12 +27,8 @@ | ||
var _detectNode = require('detect-node'); | ||
var _helpers = require('./helpers'); | ||
var _detectNode2 = _interopRequireDefault(_detectNode); | ||
var _fileapi = require('fileapi'); | ||
var _helpers = require('./helpers'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var FileAPI = !_detectNode2.default ? require('fileapi') : null; | ||
var THUMBNAIL_WIDTH = exports.THUMBNAIL_WIDTH = 200; | ||
@@ -52,3 +52,3 @@ var THUMBNAIL_HEIGHT = exports.THUMBNAIL_HEIGHT = 200; | ||
return new _promise2.default(function (resolve, reject) { | ||
FileAPI.Image(imageFile).preview(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT).get(function (err, canvas) { | ||
(0, _fileapi.Image)(imageFile).preview(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT).get(function (err, canvas) { | ||
if (err) reject(err); | ||
@@ -64,10 +64,26 @@ | ||
function uploadFile(dispatch, url, identificator, file, data, fileAPIOptions) { | ||
return new _promise2.default(function (resolve) { | ||
FileAPI.upload((0, _extends3.default)({}, fileAPIOptions, { | ||
function uploadFile(dispatch, url, identificator, file, data, fileApiOptions) { | ||
var _fileApiOptions$cors = fileApiOptions.cors, | ||
cors = _fileApiOptions$cors === undefined ? false : _fileApiOptions$cors, | ||
rest = (0, _objectWithoutProperties3.default)(fileApiOptions, ['cors']); | ||
var headers = fileApiOptions.headers; | ||
if (cors) { | ||
headers = (0, _extends3.default)({}, headers, { | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Methods': 'POST', | ||
'Access-Control-Allow-Headers': '*' | ||
}); | ||
} | ||
return new _promise2.default(function (complete) { | ||
(0, _fileapi.upload)((0, _extends3.default)({ | ||
headers: headers | ||
}, rest, { | ||
data: data, | ||
complete: complete, | ||
files: { | ||
file: file | ||
}, | ||
complete: resolve, | ||
fileprogress: function fileprogress() { | ||
@@ -74,0 +90,0 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { |
@@ -54,10 +54,2 @@ 'use strict'; | ||
var _detectNode = require('detect-node'); | ||
var _detectNode2 = _interopRequireDefault(_detectNode); | ||
var _bluebird = require('bluebird'); | ||
var _bluebird2 = _interopRequireDefault(_bluebird); | ||
var _radium = require('radium'); | ||
@@ -75,2 +67,4 @@ | ||
var _fileapi = require('fileapi'); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
@@ -109,4 +103,2 @@ | ||
var FileAPI = !_detectNode2.default ? _bluebird2.default.promisifyAll(require('fileapi')) : null; | ||
var FileUpload = (_dec = (0, _reactRedux.connect)(null, actions), _dec(_class = (0, _radium2.default)(_class = (_class2 = (_temp2 = _class3 = function (_Component) { | ||
@@ -134,4 +126,4 @@ (0, _inherits3.default)(FileUpload, _Component); | ||
value: function componentDidMount() { | ||
FileAPI.event.on(this.refs.fileInput, 'change', this.handleFileChange); | ||
FileAPI.event.dnd(this.refs.fileInput, this.handleDragHover, this.handleFileChange); | ||
_fileapi.event.on(this.refs.fileInput, 'change', this.handleFileChange); | ||
_fileapi.event.dnd(this.refs.fileInput, this.handleDragHover, this.handleFileChange); | ||
document.addEventListener('drop', this.preventDropEvent); | ||
@@ -145,4 +137,4 @@ document.addEventListener('dragover', this.preventDragOverEvent); | ||
value: function componentWillUnmount() { | ||
FileAPI.event.off(this.refs.fileInput, 'change', this.handleFileChange); | ||
FileAPI.event.dnd.off(this.refs.fileInput, this.handleDragHover, this.handleFileChange); | ||
_fileapi.event.off(this.refs.fileInput, 'change', this.handleFileChange); | ||
_fileapi.event.dnd.off(this.refs.fileInput, this.handleDragHover, this.handleFileChange); | ||
document.removeEventListener('drop', this.preventDropEvent); | ||
@@ -149,0 +141,0 @@ document.removeEventListener('dragover', this.preventDragOverEvent); |
@@ -6,2 +6,7 @@ 'use strict'; | ||
}); | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
exports.isImage = isImage; | ||
@@ -13,9 +18,6 @@ exports.isDoc = isDoc; | ||
var _bluebird = require('bluebird'); | ||
var _fileapi = require('fileapi'); | ||
var _bluebird2 = _interopRequireDefault(_bluebird); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var FileAPI = process.env.IS_BROWSER ? require('fileapi') : null; | ||
var IMAGE_TYPES = /^image\/(jpe?g|png|gif|jf?if|tiff?)$/i; | ||
@@ -32,4 +34,4 @@ | ||
function filterImageFiles(payload) { | ||
return new _bluebird2.default(function (resolve) { | ||
if (payload instanceof Event) FileAPI.getFiles(payload, isImage, resolve);else FileAPI.filterFiles(payload, isImage, resolve); | ||
return new _promise2.default(function (resolve) { | ||
if (payload instanceof Event) (0, _fileapi.getFiles)(payload, isImage, resolve);else (0, _fileapi.filterFiles)(payload, isImage, resolve); | ||
}); | ||
@@ -39,4 +41,4 @@ } | ||
function filterDocFiles(payload) { | ||
return new _bluebird2.default(function (resolve) { | ||
if (payload instanceof Event) FileAPI.getFiles(payload, isDoc, resolve);else FileAPI.filterFiles(payload, isDoc, resolve); | ||
return new _promise2.default(function (resolve) { | ||
if (payload instanceof Event) (0, _fileapi.getFiles)(payload, isDoc, resolve);else (0, _fileapi.filterFiles)(payload, isDoc, resolve); | ||
}); | ||
@@ -48,6 +50,6 @@ } | ||
return new _bluebird2.default(function (resolve) { | ||
if (payload instanceof Event) FileAPI.getFiles(payload, function (file) { | ||
return new _promise2.default(function (resolve) { | ||
if (payload instanceof Event) (0, _fileapi.getFiles)(payload, function (file) { | ||
return allowedFilter.test(file.type); | ||
}, resolve);else FileAPI.filterFiles(payload, function (file) { | ||
}, resolve);else (0, _fileapi.filterFiles)(payload, function (file) { | ||
return allowedFilter.test(file.type); | ||
@@ -54,0 +56,0 @@ }, resolve); |
@@ -26,7 +26,6 @@ 'use strict'; | ||
var InitialState = (0, _immutable.Record)({ | ||
var initialState = new _immutable.Record({ | ||
documents: (0, _immutable.Map)(), | ||
images: (0, _immutable.Map)() | ||
}); | ||
var initialState = new InitialState(); | ||
@@ -41,3 +40,3 @@ function revive() { | ||
if (!(state instanceof InitialState)) return revive(state); | ||
if (!(state instanceof _immutable.Record)) return revive(state); | ||
@@ -44,0 +43,0 @@ switch (action.type) { |
{ | ||
"name": "redux-file-upload-header", | ||
"version": "0.0.24", | ||
"version": "0.0.26", | ||
"description": "Redux-friendly file upload made easy", | ||
@@ -49,8 +49,14 @@ "main": "lib/index.js", | ||
"enzyme": "^2.3.0", | ||
"eslint": "^3.19.0", | ||
"eslint-config-airbnb": "^8.0.0", | ||
"eslint-plugin-import": "^1.0.3", | ||
"eslint-plugin-jsx-a11y": "^1.0.4", | ||
"eslint-plugin-react": "^5.0.1", | ||
"eslint": "3.19", | ||
"eslint-config-react-app": "^0.6.2", | ||
"eslint-loader": "1.6.0", | ||
"eslint-plugin-flowtype": "2.21.0", | ||
"eslint-plugin-import": "2.0.1", | ||
"eslint-plugin-jsx-a11y": "4.0.0", | ||
"eslint-plugin-react": "6.4.1", | ||
"react": "^15.5.4", | ||
"react-addons-test-utils": ">=0.14", | ||
"react-dom": "^15.5.4", | ||
"react-redux": "^5.0.4", | ||
"redux": "^3.6.0", | ||
"rimraf": "^2.4.3" | ||
@@ -66,8 +72,3 @@ }, | ||
}, | ||
"peerDependencies": { | ||
"react": ">=15.5.0", | ||
"react-dom": ">=15.5.0", | ||
"react-redux": ">=5.0.0", | ||
"redux": ">=3.6.0" | ||
} | ||
"peerDependencies": {} | ||
} |
@@ -1,6 +0,4 @@ | ||
import isServer from 'detect-node'; | ||
import { isDoc, isImage } from './helpers'; | ||
import { Image, upload } from 'fileapi' | ||
const FileAPI = !isServer ? require('fileapi') : null; | ||
export const THUMBNAIL_WIDTH = 200; | ||
@@ -26,3 +24,3 @@ export const THUMBNAIL_HEIGHT = 200; | ||
return new Promise((resolve, reject) => { | ||
FileAPI.Image(imageFile) | ||
Image(imageFile) | ||
.preview(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT) | ||
@@ -40,11 +38,25 @@ .get((err, canvas) => { | ||
function uploadFile(dispatch, url, identificator, file, data, fileAPIOptions) { | ||
return new Promise(resolve => { | ||
FileAPI.upload({ | ||
...fileAPIOptions, | ||
function uploadFile(dispatch, url, identificator, file, data, fileApiOptions) { | ||
const { cors = false, ...rest } = fileApiOptions | ||
let { headers } = fileApiOptions | ||
if(cors){ | ||
headers = { | ||
...headers, | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Methods': 'POST', | ||
'Access-Control-Allow-Headers': '*' | ||
} | ||
} | ||
return new Promise(complete => { | ||
upload({ | ||
headers, | ||
...rest, | ||
data, | ||
complete, | ||
files: { | ||
file | ||
}, | ||
complete: resolve, | ||
fileprogress: (...args) => dispatch(fileProgress(identificator, ...args)), | ||
@@ -51,0 +63,0 @@ filecomplete: (...args) => dispatch(fileComplete(identificator, ...args)), |
import * as actions from './actions'; | ||
import autobind from 'core-decorators/lib/autobind'; | ||
import Component from 'react-pure-render/component'; | ||
import isServer from 'detect-node'; | ||
import Promise from 'bluebird'; | ||
import Radium from 'radium'; | ||
@@ -10,5 +8,4 @@ import React, { PropTypes as RPT } from 'react'; | ||
import { filterAllowedFiles, filterDocFiles, filterImageFiles } from './helpers'; | ||
import { event as fileApiEvent } from 'fileapi' | ||
const FileAPI = !isServer ? Promise.promisifyAll(require('fileapi')) : null; | ||
@connect(null, actions) | ||
@@ -40,4 +37,4 @@ @Radium | ||
componentDidMount() { | ||
FileAPI.event.on(this.refs.fileInput, 'change', this.handleFileChange); | ||
FileAPI.event.dnd(this.refs.fileInput, this.handleDragHover, this.handleFileChange); | ||
fileApiEvent.on(this.refs.fileInput, 'change', this.handleFileChange); | ||
fileApiEvent.dnd(this.refs.fileInput, this.handleDragHover, this.handleFileChange); | ||
document.addEventListener('drop', this.preventDropEvent); | ||
@@ -50,4 +47,4 @@ document.addEventListener('dragover', this.preventDragOverEvent); | ||
componentWillUnmount() { | ||
FileAPI.event.off(this.refs.fileInput, 'change', this.handleFileChange); | ||
FileAPI.event.dnd.off(this.refs.fileInput, this.handleDragHover, this.handleFileChange); | ||
fileApiEvent.off(this.refs.fileInput, 'change', this.handleFileChange); | ||
fileApiEvent.dnd.off(this.refs.fileInput, this.handleDragHover, this.handleFileChange); | ||
document.removeEventListener('drop', this.preventDropEvent); | ||
@@ -54,0 +51,0 @@ document.removeEventListener('dragover', this.preventDragOverEvent); |
@@ -1,4 +0,3 @@ | ||
import Promise from 'bluebird'; | ||
import {filterFiles, getFiles} from 'fileapi' | ||
const FileAPI = process.env.IS_BROWSER ? require('fileapi') : null; | ||
const IMAGE_TYPES = /^image\/(jpe?g|png|gif|jf?if|tiff?)$/i; | ||
@@ -16,4 +15,4 @@ | ||
return new Promise(resolve => { | ||
if (payload instanceof Event) FileAPI.getFiles(payload, isImage, resolve); | ||
else FileAPI.filterFiles(payload, isImage, resolve); | ||
if (payload instanceof Event) getFiles(payload, isImage, resolve); | ||
else filterFiles(payload, isImage, resolve); | ||
}); | ||
@@ -24,4 +23,4 @@ } | ||
return new Promise(resolve => { | ||
if (payload instanceof Event) FileAPI.getFiles(payload, isDoc, resolve); | ||
else FileAPI.filterFiles(payload, isDoc, resolve); | ||
if (payload instanceof Event) getFiles(payload, isDoc, resolve); | ||
else filterFiles(payload, isDoc, resolve); | ||
}); | ||
@@ -34,5 +33,5 @@ } | ||
return new Promise(resolve => { | ||
if (payload instanceof Event) FileAPI.getFiles(payload, file => allowedFilter.test(file.type), resolve); | ||
else FileAPI.filterFiles(payload, file => allowedFilter.test(file.type), resolve); | ||
if (payload instanceof Event) getFiles(payload, file => allowedFilter.test(file.type), resolve); | ||
else filterFiles(payload, file => allowedFilter.test(file.type), resolve); | ||
}); | ||
} |
@@ -6,15 +6,13 @@ import * as actions from './actions'; | ||
const InitialState = Record({ | ||
const initialState = new Record({ | ||
documents: Map(), | ||
images: Map() | ||
}); | ||
const initialState = new InitialState; | ||
function revive() { | ||
return initialState.merge({ | ||
}); | ||
return initialState.merge({}); | ||
} | ||
export default function fileUploadReducer(state = initialState, action) { | ||
if (!(state instanceof InitialState)) return revive(state); | ||
if (!(state instanceof Record)) return revive(state); | ||
@@ -21,0 +19,0 @@ switch (action.type) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
200292
6
987
0
24