mirror of
https://github.com/penpot/penpot.git
synced 2026-03-14 22:46:00 +00:00
🐛 Fix clipboard getType error when no allowed types found (#8609)
When clipboard items have types that don't match the allowed types list, the filtering results in an empty array. Calling getType with undefined throws a NotFoundError. This change adds a check for null/undefined types and filters them from the result. Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
@@ -135,7 +135,7 @@ function sortItems(a, b) {
|
||||
export async function fromNavigator(options) {
|
||||
options = options || {};
|
||||
const items = await navigator.clipboard.read();
|
||||
return Promise.all(
|
||||
const result = await Promise.all(
|
||||
Array.from(items).map(async (item) => {
|
||||
const itemAllowedTypes = Array.from(item.types)
|
||||
.filter(filterAllowedTypes(options))
|
||||
@@ -155,9 +155,15 @@ export async function fromNavigator(options) {
|
||||
}
|
||||
|
||||
const type = itemAllowedTypes.at(0);
|
||||
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return item.getType(type);
|
||||
}),
|
||||
);
|
||||
return result.filter((item) => !!item);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user