feat: add contextual layer inspector
This commit is contained in:
@@ -143,6 +143,25 @@ export function addLayerMask(documentIndex: DocumentReadIndex, layerInfo: Indexe
|
||||
});
|
||||
}
|
||||
|
||||
export function duplicateLayer(documentIndex: DocumentReadIndex, layerInfo: IndexedLayerInfo, dispatch: AppStore["dispatch"]) {
|
||||
const ids = collectDuplicateIds(layerInfo.layer, layerInfo.siblings);
|
||||
dispatch(commandIds.documentDuplicateLayer, {
|
||||
layerId: layerInfo.layer.id,
|
||||
idByLayerId: Object.fromEntries(ids.map((id) => [id, crypto.randomUUID()])),
|
||||
});
|
||||
}
|
||||
|
||||
function collectDuplicateIds(layer: Layer, siblings: readonly Layer[]): string[] {
|
||||
const ids = collectTreeIds(layer);
|
||||
const maskId = getLayerMask(layer)?.maskLayerId;
|
||||
const mask = maskId ? siblings.find((candidate) => candidate.id === maskId) : undefined;
|
||||
return mask ? [...collectTreeIds(mask), ...ids] : ids;
|
||||
}
|
||||
|
||||
function collectTreeIds(layer: Layer): string[] {
|
||||
return [layer.id, ...(layer.type === "group" ? layer.children.flatMap(collectTreeIds) : [])];
|
||||
}
|
||||
|
||||
const emptyLayerIds = new Set<string>();
|
||||
|
||||
function createGroup(name: string): Extract<Layer, { type: "group" }> {
|
||||
|
||||
Reference in New Issue
Block a user