03a4410272
主要工作是共享同一套“画布内核与通用 UI 源码”,网站和 Tauri 只分别实现宿主适配层。 --------- Co-authored-by: 段舒康 <kdletters@qq.com> Co-authored-by: kdletters <kdletters@qq.com> Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/136 Co-authored-by: menghao <mh18530625731@163.com> Co-committed-by: menghao <mh18530625731@163.com>
85 lines
2.4 KiB
TypeScript
85 lines
2.4 KiB
TypeScript
import type { CanvasGenerationDialogState, CanvasLayer } from './types';
|
|
|
|
export const CANVAS_GENERATION_SELECTION_PREFIX = 'generation-dialog:';
|
|
|
|
export function getCanvasGenerationSelectionId(dialogId: string) {
|
|
return `${CANVAS_GENERATION_SELECTION_PREFIX}${dialogId}`;
|
|
}
|
|
|
|
export function getCanvasGenerationDialogIdFromSelectionId(targetId: string) {
|
|
return targetId.startsWith(CANVAS_GENERATION_SELECTION_PREFIX)
|
|
? targetId.slice(CANVAS_GENERATION_SELECTION_PREFIX.length)
|
|
: null;
|
|
}
|
|
|
|
export function isCanvasGenerationSelectionId(targetId: string) {
|
|
return getCanvasGenerationDialogIdFromSelectionId(targetId) !== null;
|
|
}
|
|
|
|
export function getSelectedLayerIds(selectionIds: string[]) {
|
|
return selectionIds.filter(
|
|
(selectionId) => !isCanvasGenerationSelectionId(selectionId),
|
|
);
|
|
}
|
|
|
|
export function getSelectedGenerationDialogIds(selectionIds: string[]) {
|
|
return selectionIds.flatMap((selectionId) => {
|
|
const dialogId = getCanvasGenerationDialogIdFromSelectionId(selectionId);
|
|
return dialogId ? [dialogId] : [];
|
|
});
|
|
}
|
|
|
|
export function dedupeSelectionIds(selectionIds: string[]) {
|
|
return Array.from(new Set(selectionIds));
|
|
}
|
|
|
|
export function firstSelectedLayerId(selectionIds: string[]) {
|
|
return getSelectedLayerIds(selectionIds)[0] ?? null;
|
|
}
|
|
|
|
export function normalizeCanvasSelectionIds({
|
|
selectionIds,
|
|
layers,
|
|
generationDialogs,
|
|
}: {
|
|
selectionIds: string[];
|
|
layers: CanvasLayer[];
|
|
generationDialogs: CanvasGenerationDialogState[];
|
|
}) {
|
|
const layerIds = new Set(layers.map((layer) => layer.id));
|
|
const generationDialogIds = new Set(
|
|
generationDialogs.map((dialog) => dialog.id),
|
|
);
|
|
return dedupeSelectionIds(selectionIds).filter((selectionId) => {
|
|
if (isCanvasGenerationSelectionId(selectionId)) {
|
|
const dialogId = getCanvasGenerationDialogIdFromSelectionId(selectionId);
|
|
return Boolean(dialogId && generationDialogIds.has(dialogId));
|
|
}
|
|
return layerIds.has(selectionId);
|
|
});
|
|
}
|
|
|
|
export function resolvePointerSelection({
|
|
targetId,
|
|
selectedIds,
|
|
isMultiSelectGesture,
|
|
}: {
|
|
targetId: string;
|
|
selectedIds: string[];
|
|
isMultiSelectGesture: boolean;
|
|
}) {
|
|
if (!isMultiSelectGesture) {
|
|
if (selectedIds.includes(targetId)) {
|
|
return selectedIds;
|
|
}
|
|
return [targetId];
|
|
}
|
|
if (!selectedIds.includes(targetId)) {
|
|
return [...selectedIds, targetId];
|
|
}
|
|
if (selectedIds.length <= 1) {
|
|
return [targetId];
|
|
}
|
|
return selectedIds.filter((selectedId) => selectedId !== targetId);
|
|
}
|