pure-upload
Advanced tools
Comparing version 2.2.2 to 2.2.3
CHANGELOG | ||
=== | ||
2.2.3 | ||
-- | ||
Fix | ||
- | ||
Removed duplications when same file is adding many times to queue. | ||
Few options of UploadArea changed to be acceptable as a function. | ||
2.2.2 | ||
-- | ||
New features | ||
Fix | ||
- | ||
@@ -8,0 +16,0 @@ |
45
index.js
@@ -75,2 +75,8 @@ "use strict"; | ||
; | ||
function getValueOrResult(valueOrGetter) { | ||
if (typeof valueOrGetter === 'function') | ||
return valueOrGetter(); | ||
return valueOrGetter; | ||
} | ||
exports.getValueOrResult = getValueOrResult; | ||
function newGuid() { | ||
@@ -221,2 +227,3 @@ var d = new Date().getTime(); | ||
file.guid = newGuid(); | ||
delete file.uploadStatus; | ||
file.url = _this.uploadCore.getUrl(file); | ||
@@ -274,15 +281,11 @@ file.onError = _this.options.onFileError || (function () { ; }); | ||
} | ||
if (this.options.clickable) { | ||
var onClick_1 = function () { return _this.onClick(); }; | ||
addEventHandler(this.targetElement, 'click', onClick_1); | ||
this.unregisterOnClick = function () { return removeEventHandler(_this.targetElement, 'click', onClick_1); }; | ||
} | ||
if (this.options.allowDragDrop) { | ||
var onDrag_1 = function (e) { return _this.onDrag(e); }; | ||
addEventHandler(this.targetElement, 'dragover', onDrag_1); | ||
this.unregisterOnDragOver = function () { return removeEventHandler(_this.targetElement, 'dragover', onDrag_1); }; | ||
var onDrop_1 = function (e) { return _this.onDrop(e); }; | ||
addEventHandler(this.targetElement, 'drop', onDrop_1); | ||
this.unregisterOnDrop = function () { return removeEventHandler(_this.targetElement, 'drop', onDrop_1); }; | ||
} | ||
var onClick = function () { return _this.onClick(); }; | ||
addEventHandler(this.targetElement, 'click', onClick); | ||
this.unregisterOnClick = function () { return removeEventHandler(_this.targetElement, 'click', onClick); }; | ||
var onDrag = function (e) { return _this.onDrag(e); }; | ||
addEventHandler(this.targetElement, 'dragover', onDrag); | ||
this.unregisterOnDragOver = function () { return removeEventHandler(_this.targetElement, 'dragover', onDrag); }; | ||
var onDrop = function (e) { return _this.onDrop(e); }; | ||
addEventHandler(this.targetElement, 'drop', onDrop); | ||
this.unregisterOnDrop = function () { return removeEventHandler(_this.targetElement, 'drop', onDrop); }; | ||
// attach to body | ||
@@ -419,2 +422,4 @@ document.body.appendChild(this.fileInput); | ||
UploadArea.prototype.onDrag = function (e) { | ||
if (!getValueOrResult(this.options.allowDragDrop)) | ||
return; | ||
var efct = undefined; | ||
@@ -431,2 +436,4 @@ try { | ||
UploadArea.prototype.onDrop = function (e) { | ||
if (!getValueOrResult(this.options.allowDragDrop)) | ||
return; | ||
this.stopEventPropagation(e); | ||
@@ -460,2 +467,4 @@ if (!e.dataTransfer) { | ||
var _this = this; | ||
if (!getValueOrResult(this.options.clickable)) | ||
return; | ||
this.fileInput.value = ''; | ||
@@ -767,6 +776,8 @@ if (this.isIeVersion(10)) { | ||
forEach(files, function (file) { | ||
_this.queuedFiles.push(file); | ||
file.remove = decorateSimpleFunction(file.remove, function () { | ||
_this.removeFile(file); | ||
}); | ||
if (!_this.queuedFiles.some(function (queuedFile) { return queuedFile === file || (!!queuedFile.guid && queuedFile.guid === file.guid); })) { | ||
_this.queuedFiles.push(file); | ||
file.remove = decorateSimpleFunction(file.remove, function () { | ||
_this.removeFile(file); | ||
}); | ||
} | ||
if (_this.callbacks.onFileAddedCallback) | ||
@@ -773,0 +784,0 @@ _this.callbacks.onFileAddedCallback(file); |
57
index.ts
@@ -85,2 +85,8 @@ export function addEventHandler(el: Element | HTMLElement, event: string, handler: (ev: UIEvent) => void) { | ||
export function getValueOrResult<T>(valueOrGetter?: T | (() => T)): T | undefined { | ||
if (typeof valueOrGetter === 'function') | ||
return valueOrGetter(); | ||
return valueOrGetter; | ||
} | ||
export function newGuid(): string { | ||
@@ -127,4 +133,4 @@ let d = new Date().getTime(); | ||
maxFileSize?: number; | ||
allowDragDrop?: boolean; | ||
clickable?: boolean; | ||
allowDragDrop?: boolean | (() => boolean); | ||
clickable?: boolean | (() => boolean); | ||
accept?: string; | ||
@@ -353,2 +359,3 @@ multiple?: boolean; | ||
file.guid = newGuid(); | ||
delete file.uploadStatus; | ||
file.url = this.uploadCore.getUrl(file); | ||
@@ -405,3 +412,3 @@ file.onError = this.options.onFileError || (() => { ; }); | ||
let onChange = (e: Event) => this.onChange(e); | ||
const onChange = (e: Event) => this.onChange(e); | ||
addEventHandler(this.fileInput, 'change', onChange); | ||
@@ -413,16 +420,15 @@ this.unregisterOnChange = () => removeEventHandler(this.fileInput, 'change', onchange); | ||
} | ||
if (this.options.clickable) { | ||
let onClick = () => this.onClick(); | ||
addEventHandler(this.targetElement, 'click', onClick); | ||
this.unregisterOnClick = () => removeEventHandler(this.targetElement, 'click', onClick); | ||
} | ||
if (this.options.allowDragDrop) { | ||
let onDrag = (e: DragEvent) => this.onDrag(e); | ||
addEventHandler(this.targetElement, 'dragover', onDrag); | ||
this.unregisterOnDragOver = () => removeEventHandler(this.targetElement, 'dragover', onDrag); | ||
let onDrop = (e: DragEvent) => this.onDrop(e); | ||
addEventHandler(this.targetElement, 'drop', onDrop); | ||
this.unregisterOnDrop = () => removeEventHandler(this.targetElement, 'drop', onDrop); | ||
} | ||
const onClick = () => this.onClick(); | ||
addEventHandler(this.targetElement, 'click', onClick); | ||
this.unregisterOnClick = () => removeEventHandler(this.targetElement, 'click', onClick); | ||
const onDrag = (e: DragEvent) => this.onDrag(e); | ||
addEventHandler(this.targetElement, 'dragover', onDrag); | ||
this.unregisterOnDragOver = () => removeEventHandler(this.targetElement, 'dragover', onDrag); | ||
const onDrop = (e: DragEvent) => this.onDrop(e); | ||
addEventHandler(this.targetElement, 'drop', onDrop); | ||
this.unregisterOnDrop = () => removeEventHandler(this.targetElement, 'drop', onDrop); | ||
// attach to body | ||
@@ -580,2 +586,5 @@ document.body.appendChild(this.fileInput); | ||
private onDrag(e: DragEvent): void { | ||
if (!getValueOrResult(this.options.allowDragDrop)) | ||
return; | ||
let efct: string | undefined = undefined; | ||
@@ -590,2 +599,5 @@ try { | ||
private onDrop(e: DragEvent): void { | ||
if (!getValueOrResult(this.options.allowDragDrop)) | ||
return; | ||
this.stopEventPropagation(e); | ||
@@ -619,2 +631,5 @@ if (!e.dataTransfer) { | ||
private onClick(): void { | ||
if (!getValueOrResult(this.options.clickable)) | ||
return; | ||
this.fileInput.value = ''; | ||
@@ -958,7 +973,9 @@ | ||
forEach(files, file => { | ||
this.queuedFiles.push(file); | ||
if (!this.queuedFiles.some(queuedFile => queuedFile === file || (!!queuedFile.guid && queuedFile.guid === file.guid))) { | ||
this.queuedFiles.push(file); | ||
file.remove = decorateSimpleFunction(file.remove, () => { | ||
this.removeFile(file); | ||
}); | ||
file.remove = decorateSimpleFunction(file.remove, () => { | ||
this.removeFile(file); | ||
}); | ||
} | ||
@@ -965,0 +982,0 @@ if (this.callbacks.onFileAddedCallback) |
{ | ||
"name": "pure-upload", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"description": "The pure upload library without dependencies", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -10,2 +10,3 @@ declare module "pure-upload" { | ||
export function getUploader(options: IUploadQueueOptions, callbacks: IUploadQueueCallbacks): Uploader; | ||
export function getValueOrResult<T>(valueOrGetter?: T | (() => T)): T | undefined; | ||
export function newGuid(): string; | ||
@@ -29,4 +30,4 @@ export interface IFileExt extends File { | ||
maxFileSize?: number; | ||
allowDragDrop?: boolean; | ||
clickable?: boolean; | ||
allowDragDrop?: boolean | (() => boolean); | ||
clickable?: boolean | (() => boolean); | ||
accept?: string; | ||
@@ -33,0 +34,0 @@ multiple?: boolean; |
@@ -69,14 +69,21 @@ # Pure-upload | ||
params?: { [key: string]: string; }; | ||
localizer?: (message: string, params?: Object) => string; | ||
maxFileSize?: number; | ||
allowDragDrop?: boolean; | ||
clickable?: boolean; | ||
allowDragDrop?: boolean | (() => boolean); | ||
clickable?: boolean | (() => boolean); | ||
accept?: string; | ||
multiple?: boolean; | ||
validateExtension?: boolean; | ||
manualStart?: boolean; | ||
onFileAdded?: (file: IUploadFile) => void; | ||
onFileSelected?: (file: IUploadFile) => void | ||
onFileError?: (file: IUploadFile) => void; | ||
onFileCancelled?: (file: IUploadFile) => void; | ||
onFileSelected?: (file: IUploadFile) => void; | ||
onFileError?: (file: IUploadFile) => void; | ||
onFileCanceled?: (file: IUploadFile) => void; | ||
``` | ||
### Upload area - manual starting | ||
```typescript | ||
start(autoClear?: boolean): void; | ||
clear(): void; | ||
``` | ||
### Upload file | ||
@@ -83,0 +90,0 @@ Standard *File* object extended with additional informations and methods to manage a file in queue. |
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
91970
2057
110