@uppy/provider-views
Advanced tools
Comparing version 3.10.0 to 3.11.0
# @uppy/provider-views | ||
## 3.11.0 | ||
Released: 2024-03-27 | ||
Included in: Uppy v3.24.0 | ||
- @uppy/box,@uppy/companion-client,@uppy/provider-views,@uppy/status-bar: fix type imports (Antoine du Hamel / #5038) | ||
- @uppy/provider-views: fix `super.toggleCheckbox` bug (Mikael Finstad / #5004) | ||
- @uppy/core,@uppy/provider-views: Fix breadcrumbs (Evgenia Karunus / #4986) | ||
## 3.10.0 | ||
@@ -4,0 +13,0 @@ |
@@ -16,3 +16,3 @@ function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } | ||
const packageJson = { | ||
"version": "3.10.0" | ||
"version": "3.11.0" | ||
}; | ||
@@ -400,3 +400,2 @@ function formatBreadcrumbs(breadcrumbs) { | ||
isChecked, | ||
toggleCheckbox, | ||
recordShiftKeyPress, | ||
@@ -419,3 +418,3 @@ filterItems | ||
isChecked, | ||
toggleCheckbox, | ||
toggleCheckbox: this.toggleCheckbox.bind(this), | ||
recordShiftKeyPress, | ||
@@ -422,0 +421,0 @@ currentSelection, |
@@ -13,3 +13,3 @@ function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } | ||
const packageJson = { | ||
"version": "3.10.0" | ||
"version": "3.11.0" | ||
}; | ||
@@ -143,3 +143,2 @@ const defaultState = { | ||
isChecked, | ||
toggleCheckbox, | ||
filterItems, | ||
@@ -151,3 +150,3 @@ recordShiftKeyPress | ||
isChecked, | ||
toggleCheckbox, | ||
toggleCheckbox: this.toggleCheckbox.bind(this), | ||
recordShiftKeyPress, | ||
@@ -154,0 +153,0 @@ currentSelection, |
123
lib/View.js
@@ -23,63 +23,2 @@ import getFileType from '@uppy/utils/lib/getFileType'; | ||
}; | ||
/** | ||
* Toggles file/folder checkbox to on/off state while updating files list. | ||
* | ||
* Note that some extra complexity comes from supporting shift+click to | ||
* toggle multiple checkboxes at once, which is done by getting all files | ||
* in between last checked file and current one. | ||
*/ | ||
this.toggleCheckbox = (e, file) => { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
e.currentTarget.focus(); | ||
const { | ||
folders, | ||
files | ||
} = this.plugin.getPluginState(); | ||
const items = this.filterItems(folders.concat(files)); | ||
// Shift-clicking selects a single consecutive list of items | ||
// starting at the previous click. | ||
if (this.lastCheckbox && this.isShiftKeyPressed) { | ||
const { | ||
currentSelection | ||
} = this.plugin.getPluginState(); | ||
const prevIndex = items.indexOf(this.lastCheckbox); | ||
const currentIndex = items.indexOf(file); | ||
const newSelection = prevIndex < currentIndex ? items.slice(prevIndex, currentIndex + 1) : items.slice(currentIndex, prevIndex + 1); | ||
const reducedNewSelection = []; | ||
// Check restrictions on each file in currentSelection, | ||
// reduce it to only contain files that pass restrictions | ||
for (const item of newSelection) { | ||
const { | ||
uppy | ||
} = this.plugin; | ||
const restrictionError = uppy.validateRestrictions(remoteFileObjToLocal(item), [...uppy.getFiles(), ...reducedNewSelection]); | ||
if (!restrictionError) { | ||
reducedNewSelection.push(item); | ||
} else { | ||
uppy.info({ | ||
message: restrictionError.message | ||
}, 'error', uppy.opts.infoTimeout); | ||
} | ||
} | ||
this.plugin.setPluginState({ | ||
currentSelection: [...new Set([...currentSelection, ...reducedNewSelection])] | ||
}); | ||
return; | ||
} | ||
this.lastCheckbox = file; | ||
const { | ||
currentSelection | ||
} = this.plugin.getPluginState(); | ||
if (this.isChecked(file)) { | ||
this.plugin.setPluginState({ | ||
currentSelection: currentSelection.filter(item => item.id !== file.id) | ||
}); | ||
} else { | ||
this.plugin.setPluginState({ | ||
currentSelection: currentSelection.concat([file]) | ||
}); | ||
} | ||
}; | ||
this.isChecked = file => { | ||
@@ -162,3 +101,2 @@ const { | ||
isRemote: true, | ||
// @ts-expect-error meta is filled conditionally below | ||
data: file, | ||
@@ -199,2 +137,63 @@ // @ts-expect-error meta is filled conditionally below | ||
} | ||
/** | ||
* Toggles file/folder checkbox to on/off state while updating files list. | ||
* | ||
* Note that some extra complexity comes from supporting shift+click to | ||
* toggle multiple checkboxes at once, which is done by getting all files | ||
* in between last checked file and current one. | ||
*/ | ||
toggleCheckbox(e, file) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
e.currentTarget.focus(); | ||
const { | ||
folders, | ||
files | ||
} = this.plugin.getPluginState(); | ||
const items = this.filterItems(folders.concat(files)); | ||
// Shift-clicking selects a single consecutive list of items | ||
// starting at the previous click. | ||
if (this.lastCheckbox && this.isShiftKeyPressed) { | ||
const { | ||
currentSelection | ||
} = this.plugin.getPluginState(); | ||
const prevIndex = items.indexOf(this.lastCheckbox); | ||
const currentIndex = items.indexOf(file); | ||
const newSelection = prevIndex < currentIndex ? items.slice(prevIndex, currentIndex + 1) : items.slice(currentIndex, prevIndex + 1); | ||
const reducedNewSelection = []; | ||
// Check restrictions on each file in currentSelection, | ||
// reduce it to only contain files that pass restrictions | ||
for (const item of newSelection) { | ||
const { | ||
uppy | ||
} = this.plugin; | ||
const restrictionError = uppy.validateRestrictions(remoteFileObjToLocal(item), [...uppy.getFiles(), ...reducedNewSelection]); | ||
if (!restrictionError) { | ||
reducedNewSelection.push(item); | ||
} else { | ||
uppy.info({ | ||
message: restrictionError.message | ||
}, 'error', uppy.opts.infoTimeout); | ||
} | ||
} | ||
this.plugin.setPluginState({ | ||
currentSelection: [...new Set([...currentSelection, ...reducedNewSelection])] | ||
}); | ||
return; | ||
} | ||
this.lastCheckbox = file; | ||
const { | ||
currentSelection | ||
} = this.plugin.getPluginState(); | ||
if (this.isChecked(file)) { | ||
this.plugin.setPluginState({ | ||
currentSelection: currentSelection.filter(item => item.id !== file.id) | ||
}); | ||
} else { | ||
this.plugin.setPluginState({ | ||
currentSelection: currentSelection.concat([file]) | ||
}); | ||
} | ||
} | ||
setLoading(loading) { | ||
@@ -201,0 +200,0 @@ this.plugin.setPluginState({ |
{ | ||
"name": "@uppy/provider-views", | ||
"description": "View library for Uppy remote provider plugins.", | ||
"version": "3.10.0", | ||
"version": "3.11.0", | ||
"license": "MIT", | ||
@@ -23,3 +23,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@uppy/utils": "^5.7.4", | ||
"@uppy/utils": "^5.7.5", | ||
"classnames": "^2.2.6", | ||
@@ -31,4 +31,4 @@ "nanoid": "^4.0.0", | ||
"peerDependencies": { | ||
"@uppy/core": "^3.9.3" | ||
"@uppy/core": "^3.10.0" | ||
} | ||
} |
@@ -5,2 +5,3 @@ export { | ||
} from './ProviderView/index.ts' | ||
export { default as SearchProviderViews } from './SearchProviderView/index.ts' |
@@ -5,3 +5,3 @@ import type { | ||
} from '@uppy/core/lib/Uppy' | ||
import type { Body, Meta } from '@uppy/utils/lib/UppyFile' | ||
import type { Body, Meta, TagFile } from '@uppy/utils/lib/UppyFile' | ||
import type { CompanionFile } from '@uppy/utils/lib/CompanionFile' | ||
@@ -12,28 +12,2 @@ import getFileType from '@uppy/utils/lib/getFileType' | ||
type TagFile<M extends Meta> = { | ||
id: string | ||
source: string | ||
data: Blob | ||
name: string | ||
type: string | ||
isRemote: boolean | ||
preview?: string | ||
meta: { | ||
authorName?: string | ||
authorUrl?: string | ||
relativePath?: string | null | ||
absolutePath?: string | ||
} & M | ||
remote: { | ||
companionUrl: string | ||
url: string | ||
body: { | ||
fileId: string | ||
} | ||
providerName: string | ||
provider: string | ||
requestClientId: string | ||
} | ||
} | ||
type PluginType = 'Provider' | 'SearchProvider' | ||
@@ -160,3 +134,2 @@ | ||
isRemote: true, | ||
// @ts-expect-error meta is filled conditionally below | ||
data: file, | ||
@@ -190,4 +163,4 @@ // @ts-expect-error meta is filled conditionally below | ||
if (file.author.name != null) | ||
tagFile.meta.authorName = String(file.author.name) | ||
if (file.author.url) tagFile.meta.authorUrl = file.author.url | ||
tagFile.meta!.authorName = String(file.author.name) | ||
if (file.author.url) tagFile.meta!.authorUrl = file.author.url | ||
} | ||
@@ -197,7 +170,7 @@ | ||
if (file.relDirPath != null) | ||
tagFile.meta.relativePath = | ||
tagFile.meta!.relativePath = | ||
file.relDirPath ? `${file.relDirPath}/${tagFile.name}` : null | ||
// and absolutePath (with leading slash) https://github.com/transloadit/uppy/pull/4537#issuecomment-1614236655 | ||
if (file.absDirPath != null) | ||
tagFile.meta.absolutePath = | ||
tagFile.meta!.absolutePath = | ||
file.absDirPath ? | ||
@@ -234,3 +207,3 @@ `/${file.absDirPath}/${tagFile.name}` | ||
*/ | ||
toggleCheckbox = (e: Event, file: CompanionFile): void => { | ||
toggleCheckbox(e: Event, file: CompanionFile): void { | ||
e.stopPropagation() | ||
@@ -237,0 +210,0 @@ e.preventDefault() |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
301030
4371
Updated@uppy/utils@^5.7.5