Files
Bogdan Chadkin fb466caed1 feat: show when asset is used (#5365)
Ref https://github.com/webstudio-is/webstudio/issues/572
https://github.com/webstudio-is/webstudio/issues/3261

- made settings gear visible when asset is used anywhere
- when asset is used delete button shows dialog with all usages

<img width="235" height="149" alt="image"
src="https://github.com/user-attachments/assets/50fc7e45-fb84-451d-9825-592b3ef45388"
/>



<img width="277" height="288" alt="image"
src="https://github.com/user-attachments/assets/37187a5c-92b5-413c-bcdf-caaf506525a4"
/>


<img width="428" height="246" alt="Screenshot 2025-08-09 at 11 30 37"
src="https://github.com/user-attachments/assets/e77d262a-3de0-4d46-b681-b38becb55862"
/>
2025-08-09 15:14:22 +02:00

76 lines
1.6 KiB
TypeScript

export const setDifference = <Item>(current: Set<Item>, other: Set<Item>) => {
const result = new Set<Item>(current);
if (current.size <= other.size) {
for (const item of current) {
if (other.has(item)) {
result.delete(item);
}
}
} else {
for (const item of other) {
if (current.has(item)) {
result.delete(item);
}
}
}
return result;
};
export const setUnion = <Item>(current: Set<Item>, other: Set<Item>) => {
const result = new Set<Item>(current);
for (const item of other) {
result.add(item);
}
return result;
};
export const setIsSubsetOf = <Item>(current: Set<Item>, other: Set<Item>) => {
if (current.size > other.size) {
return false;
}
for (const item of current) {
if (!other.has(item)) {
return false;
}
}
return true;
};
export const mapGroupBy = <Item, Key>(
array: Item[] | Iterable<Item>,
getKey: (item: Item) => Key
) => {
const groups = new Map<Key, Item[]>();
for (const item of array) {
const key = getKey(item);
let group = groups.get(key);
if (group === undefined) {
group = [];
groups.set(key, group);
}
group.push(item);
}
return groups;
};
export const objectGroupBy = <Item, Key>(
array: Item[] | Iterable<Item>,
getKey: (item: Item) => Key
) => {
return Object.fromEntries(mapGroupBy(array, getKey));
};
// https://github.com/tc39/proposal-upsert
export const mapGetOrInsert = <Key, Value>(
map: Map<Key, Value>,
key: Key,
defaultValue: Value
): Value => {
let value = map.get(key);
if (value === undefined) {
value = defaultValue;
map.set(key, value);
}
return value;
};