mirror of
https://github.com/penpot/penpot.git
synced 2026-09-10 22:19:19 +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:
parent
e7e6303184
commit
eecb51ecc1
@ -135,7 +135,7 @@ function sortItems(a, b) {
|
|||||||
export async function fromNavigator(options) {
|
export async function fromNavigator(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
const items = await navigator.clipboard.read();
|
const items = await navigator.clipboard.read();
|
||||||
return Promise.all(
|
const result = await Promise.all(
|
||||||
Array.from(items).map(async (item) => {
|
Array.from(items).map(async (item) => {
|
||||||
const itemAllowedTypes = Array.from(item.types)
|
const itemAllowedTypes = Array.from(item.types)
|
||||||
.filter(filterAllowedTypes(options))
|
.filter(filterAllowedTypes(options))
|
||||||
@ -155,9 +155,15 @@ export async function fromNavigator(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const type = itemAllowedTypes.at(0);
|
const type = itemAllowedTypes.at(0);
|
||||||
|
|
||||||
|
if (type == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return item.getType(type);
|
return item.getType(type);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
return result.filter((item) => !!item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user