Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(canvas): drag child rows to reorder and move modifiers
Josh Corbettf1b91ba00c55
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.jsonindex 4e364e812c..b86a79e75a 100644--- a/invokeai/frontend/webv2/performance/browser-baseline.json+++ b/invokeai/frontend/webv2/performance/browser-baseline.json@@ -25,13 +25,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 125.89999999850988,+ "domContentLoadedMedianMs": 120.69999999552965,"id": "launchpad","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,"layoutSwitchMedianMs": 0,- "loadMedianMs": 126.10000000149012,- "longestTaskMaxMs": 78,+ "loadMedianMs": 120.79999999701977,+ "longestTaskMaxMs": 72,"owner": "app","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:launchpad",@@ -41,24 +41,24 @@"fontRawBytes": 23664,"imageRawBytes": 0,"largestAssetRawBytes": 746376,- "otherRawBytes": 158619,+ "otherRawBytes": 158673,"requestCount": 38,"scriptRawBytes": 1634420,"scriptRequestCount": 34,- "totalRawBytes": 1818862+ "totalRawBytes": 1818916},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 0,"largestAssetRawBytes": 753840,- "otherRawBytes": 160206,+ "otherRawBytes": 160260,"requestCount": 38,"scriptRawBytes": 1650765,"scriptRequestCount": 34,- "totalRawBytes": 1837051+ "totalRawBytes": 1837106},- "routeReadyMedianMs": 283.3999999985099,+ "routeReadyMedianMs": 266.8999999985099,"scriptSourceOwnerSet": "launchpad-static","stateProfile": "empty"},@@ -85,13 +85,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 123.10000000149012,+ "domContentLoadedMedianMs": 128.30000000447035,"id": "launchpad","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,"layoutSwitchMedianMs": 0,- "loadMedianMs": 123.29999999701977,- "longestTaskMaxMs": 71,+ "loadMedianMs": 128.5,+ "longestTaskMaxMs": 76,"owner": "app","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:launchpad",@@ -101,24 +101,24 @@"fontRawBytes": 23664,"imageRawBytes": 0,"largestAssetRawBytes": 746376,- "otherRawBytes": 158619,+ "otherRawBytes": 158673,"requestCount": 38,"scriptRawBytes": 1634420,"scriptRequestCount": 34,- "totalRawBytes": 1818862+ "totalRawBytes": 1818916},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 0,"largestAssetRawBytes": 753840,- "otherRawBytes": 160206,+ "otherRawBytes": 160260,"requestCount": 38,"scriptRawBytes": 1650765,"scriptRequestCount": 34,- "totalRawBytes": 1837051+ "totalRawBytes": 1837106},- "routeReadyMedianMs": 292.19999999552965,+ "routeReadyMedianMs": 298,"scriptSourceOwnerSet": "launchpad-static","stateProfile": "representative"},@@ -145,15 +145,15 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 122.60000000149012,+ "domContentLoadedMedianMs": 125,"id": "editor-minimal","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,"layoutSwitchMedianMs": 0,- "loadMedianMs": 122.80000000447035,- "longestTaskMaxMs": 104,+ "loadMedianMs": 125.10000000149012,+ "longestTaskMaxMs": 108,"owner": "workbench",- "projectSwitchMedianMs": 40.20000000298023,+ "projectSwitchMedianMs": 40.600000001490116,"readyMark": "invokeai:ready:widget:center:preview","remediationTicket": "deepen-widget-registry-loading","resourceBaseline": {@@ -161,24 +161,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 158619,+ "otherRawBytes": 158673,"requestCount": 115,- "scriptRawBytes": 3267315,+ "scriptRawBytes": 3268726,"scriptRequestCount": 110,- "totalRawBytes": 3608133+ "totalRawBytes": 3609598},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160206,+ "otherRawBytes": 160260,"requestCount": 115,- "scriptRawBytes": 3299989,+ "scriptRawBytes": 3301414,"scriptRequestCount": 110,- "totalRawBytes": 3644215+ "totalRawBytes": 3645694},- "routeReadyMedianMs": 684,+ "routeReadyMedianMs": 692.8000000044703,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "empty"},@@ -205,15 +205,15 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 121.29999999701977,+ "domContentLoadedMedianMs": 122.70000000298023,"id": "editor-minimal","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,"layoutSwitchMedianMs": 0,- "loadMedianMs": 121.5,- "longestTaskMaxMs": 198,+ "loadMedianMs": 122.80000000447035,+ "longestTaskMaxMs": 197,"owner": "workbench",- "projectSwitchMedianMs": 79.79999999701977,+ "projectSwitchMedianMs": 82,"readyMark": "invokeai:ready:widget:center:preview","remediationTicket": "deepen-widget-registry-loading","resourceBaseline": {@@ -221,24 +221,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 158619,+ "otherRawBytes": 158673,"requestCount": 115,- "scriptRawBytes": 3267315,+ "scriptRawBytes": 3268726,"scriptRequestCount": 110,- "totalRawBytes": 3608133+ "totalRawBytes": 3609598},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160206,+ "otherRawBytes": 160260,"requestCount": 115,- "scriptRawBytes": 3299989,+ "scriptRawBytes": 3301414,"scriptRequestCount": 110,- "totalRawBytes": 3644215+ "totalRawBytes": 3645694},- "routeReadyMedianMs": 473,+ "routeReadyMedianMs": 476.30000000447035,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "representative"},@@ -247,31 +247,31 @@"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 271870,+ "largestAssetRawBytes": 277476,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 429522,+ "scriptRawBytes": 435128,"scriptRequestCount": 7,- "totalRawBytes": 429522+ "totalRawBytes": 435128},"activatedResourceLimits": {"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 274589,+ "largestAssetRawBytes": 280251,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 433818,+ "scriptRawBytes": 439480,"scriptRequestCount": 7,- "totalRawBytes": 433818+ "totalRawBytes": 439480},- "domContentLoadedMedianMs": 120.70000000298023,+ "domContentLoadedMedianMs": 124.20000000298023,"id": "editor-canvas","layoutAckMedianMs": 2.5,- "layoutReturnSwitchMedianMs": 59,- "layoutSwitchMedianMs": 94,- "loadMedianMs": 120.89999999850988,- "longestTaskMaxMs": 135,+ "layoutReturnSwitchMedianMs": 57,+ "layoutSwitchMedianMs": 89.39999999850988,+ "loadMedianMs": 124.30000000447035,+ "longestTaskMaxMs": 133,"owner": "canvas","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:canvas",@@ -281,24 +281,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 158619,+ "otherRawBytes": 158673,"requestCount": 122,- "scriptRawBytes": 3696837,+ "scriptRawBytes": 3703854,"scriptRequestCount": 117,- "totalRawBytes": 4037655+ "totalRawBytes": 4044726},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160206,+ "otherRawBytes": 160260,"requestCount": 122,- "scriptRawBytes": 3733806,+ "scriptRawBytes": 3740893,"scriptRequestCount": 117,- "totalRawBytes": 4078032+ "totalRawBytes": 4085174},- "routeReadyMedianMs": 1070.7999999970198,+ "routeReadyMedianMs": 1068.8999999985099,"scriptSourceOwnerSet": "editor-canvas-static","stateProfile": "empty"},@@ -307,30 +307,30 @@"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 271870,+ "largestAssetRawBytes": 277476,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 429522,+ "scriptRawBytes": 435128,"scriptRequestCount": 7,- "totalRawBytes": 429522+ "totalRawBytes": 435128},"activatedResourceLimits": {"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 274589,+ "largestAssetRawBytes": 280251,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 433818,+ "scriptRawBytes": 439480,"scriptRequestCount": 7,- "totalRawBytes": 433818+ "totalRawBytes": 439480},- "domContentLoadedMedianMs": 120.80000000447035,+ "domContentLoadedMedianMs": 122.20000000298023,"id": "editor-canvas",- "layoutAckMedianMs": 3,- "layoutReturnSwitchMedianMs": 49,- "layoutSwitchMedianMs": 90.5,- "loadMedianMs": 120.89999999850988,+ "layoutAckMedianMs": 3.2000000029802322,+ "layoutReturnSwitchMedianMs": 48.80000000447035,+ "layoutSwitchMedianMs": 90,+ "loadMedianMs": 122.5,"longestTaskMaxMs": 197,"owner": "canvas","projectSwitchMedianMs": 0,@@ -341,24 +341,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 158619,+ "otherRawBytes": 158673,"requestCount": 122,- "scriptRawBytes": 3696837,+ "scriptRawBytes": 3703854,"scriptRequestCount": 117,- "totalRawBytes": 4037655+ "totalRawBytes": 4044726},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160206,+ "otherRawBytes": 160260,"requestCount": 122,- "scriptRawBytes": 3733806,+ "scriptRawBytes": 3740893,"scriptRequestCount": 117,- "totalRawBytes": 4078032+ "totalRawBytes": 4085174},- "routeReadyMedianMs": 1200.8999999985099,+ "routeReadyMedianMs": 1210.6999999955297,"scriptSourceOwnerSet": "editor-canvas-static","stateProfile": "representative"},@@ -385,13 +385,13 @@"scriptRequestCount": 6,"totalRawBytes": 383447},- "domContentLoadedMedianMs": 123.39999999850988,+ "domContentLoadedMedianMs": 125.60000000149012,"id": "editor-workflow",- "layoutAckMedianMs": 3,- "layoutReturnSwitchMedianMs": 36,- "layoutSwitchMedianMs": 88.70000000298023,- "loadMedianMs": 123.5,- "longestTaskMaxMs": 101,+ "layoutAckMedianMs": 2.600000001490116,+ "layoutReturnSwitchMedianMs": 37,+ "layoutSwitchMedianMs": 85.19999999552965,+ "loadMedianMs": 125.79999999701977,+ "longestTaskMaxMs": 108,"owner": "workflow","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:workflow",@@ -401,24 +401,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 158619,+ "otherRawBytes": 158673,"requestCount": 122,- "scriptRawBytes": 3631552,+ "scriptRawBytes": 3632963,"scriptRequestCount": 116,- "totalRawBytes": 3987783+ "totalRawBytes": 3989248},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160206,+ "otherRawBytes": 160260,"requestCount": 122,- "scriptRawBytes": 3667868,+ "scriptRawBytes": 3669293,"scriptRequestCount": 116,- "totalRawBytes": 4027661+ "totalRawBytes": 4029141},- "routeReadyMedianMs": 1064.2999999970198,+ "routeReadyMedianMs": 1074,"scriptSourceOwnerSet": "editor-workflow-static","stateProfile": "empty"},@@ -445,13 +445,13 @@"scriptRequestCount": 6,"totalRawBytes": 383447},- "domContentLoadedMedianMs": 122.60000000149012,+ "domContentLoadedMedianMs": 122.69999999552965,"id": "editor-workflow",- "layoutAckMedianMs": 2.7000000029802322,- "layoutReturnSwitchMedianMs": 45.20000000298023,- "layoutSwitchMedianMs": 135.39999999850988,- "loadMedianMs": 122.70000000298023,- "longestTaskMaxMs": 389,+ "layoutAckMedianMs": 2.7999999970197678,+ "layoutReturnSwitchMedianMs": 43.70000000298023,+ "layoutSwitchMedianMs": 134.20000000298023,+ "loadMedianMs": 122.69999999552965,+ "longestTaskMaxMs": 390,"owner": "workflow","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:workflow",@@ -461,24 +461,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 158619,+ "otherRawBytes": 158673,"requestCount": 122,- "scriptRawBytes": 3631552,+ "scriptRawBytes": 3632963,"scriptRequestCount": 116,- "totalRawBytes": 3987783+ "totalRawBytes": 3989248},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160206,+ "otherRawBytes": 160260,"requestCount": 122,- "scriptRawBytes": 3667868,+ "scriptRawBytes": 3669293,"scriptRequestCount": 116,- "totalRawBytes": 4027661+ "totalRawBytes": 4029141},- "routeReadyMedianMs": 1258.8999999985099,+ "routeReadyMedianMs": 1252.8999999985099,"scriptSourceOwnerSet": "editor-workflow-static","stateProfile": "representative"},@@ -505,13 +505,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 123.30000000447035,+ "domContentLoadedMedianMs": 123.79999999701977,"id": "editor-gallery","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,- "layoutSwitchMedianMs": 29.5,- "loadMedianMs": 123.5,- "longestTaskMaxMs": 103,+ "layoutSwitchMedianMs": 27.399999998509884,+ "loadMedianMs": 124,+ "longestTaskMaxMs": 108,"owner": "gallery","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:gallery",@@ -521,24 +521,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 158619,+ "otherRawBytes": 158673,"requestCount": 115,- "scriptRawBytes": 3267315,+ "scriptRawBytes": 3268726,"scriptRequestCount": 110,- "totalRawBytes": 3608133+ "totalRawBytes": 3609598},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160206,+ "otherRawBytes": 160260,"requestCount": 115,- "scriptRawBytes": 3299989,+ "scriptRawBytes": 3301414,"scriptRequestCount": 110,- "totalRawBytes": 3644215+ "totalRawBytes": 3645694},- "routeReadyMedianMs": 1290,+ "routeReadyMedianMs": 1299.6000000014901,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "empty"},@@ -565,13 +565,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 122.39999999850988,+ "domContentLoadedMedianMs": 124.70000000298023,"id": "editor-gallery","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,- "layoutSwitchMedianMs": 96.5,- "loadMedianMs": 122.5,- "longestTaskMaxMs": 194,+ "layoutSwitchMedianMs": 97,+ "loadMedianMs": 124.90000000596046,+ "longestTaskMaxMs": 207,"owner": "gallery","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:gallery",@@ -581,24 +581,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 158619,+ "otherRawBytes": 158673,"requestCount": 115,- "scriptRawBytes": 3267315,+ "scriptRawBytes": 3268726,"scriptRequestCount": 110,- "totalRawBytes": 3608133+ "totalRawBytes": 3609598},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160206,+ "otherRawBytes": 160260,"requestCount": 115,- "scriptRawBytes": 3299989,+ "scriptRawBytes": 3301414,"scriptRequestCount": 110,- "totalRawBytes": 3644215+ "totalRawBytes": 3645694},- "routeReadyMedianMs": 1518.3000000044703,+ "routeReadyMedianMs": 1517,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "representative"}diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex 729e88fee5..8411fc3125 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -3034,7 +3034,9 @@"moveDown": "Move down","moveUp": "Move up","removeAdjustment": "Remove adjustment",- "reorderAdjustment": "Reorder adjustment"+ "reorderAdjustment": "Reorder adjustment",+ "moveReferenceImage": "Move reference image",+ "moveToLayer": "Move to “{{name}}”"}},"gallery": {diff --git a/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts b/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.tsindex 9b7525e633..5ad868815e 100644--- a/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts+++ b/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts@@ -140,6 +140,7 @@ const CANVAS_EDIT_CONFIDENCE = {toggleCanvasStagingVisibility: 'none',updateCanvasLayer: 'conditional',updateCanvasLayerConfig: 'high',+ updateCanvasLayerConfigs: 'high',updateCanvasLayerSource: 'high',} satisfies Record<CanvasProjectMutation['type'], CanvasEditConfidence>;diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentCommands.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentCommands.tsindex 6ae85164fd..9981b320a4 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentCommands.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentCommands.ts@@ -55,6 +55,15 @@ export type DocumentCommand =readonly config: CanvasLayerConfigPatch;readonly before?: CanvasLayerConfigPatch;}+ | {+ /** One atomic edit patching several layers' config, e.g. moving a modifier between two of them. */+ readonly type: 'patch-config-batch';+ readonly patches: readonly {+ readonly id: string;+ readonly config: CanvasLayerConfigPatch;+ readonly before?: CanvasLayerConfigPatch;+ }[];+ }| { readonly type: 'patch-source'; readonly id: string; readonly source: CanvasLayerSourceContract }| { readonly type: 'set-enabled'; readonly updates: readonly { id: string; isEnabled: boolean }[] }| { readonly type: 'set-hidden'; readonly updates: readonly { id: string; isHidden: boolean }[] }diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentModel.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentModel.test.tsindex 4a855906e4..4c44d61489 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentModel.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentModel.test.ts@@ -732,6 +732,76 @@ describe('createDocumentModel', () => {expect(Object.hasOwn(mask, 'noise')).toBe(false);});+ it('round-trips an atomic cross-layer config batch and refuses malformed batches', () => {+ const ref = {+ config: {+ beginEndStepPct: [0, 1] as [number, number],+ clipVisionModel: 'ViT-H' as const,+ image: null,+ method: 'full' as const,+ model: null,+ type: 'ip_adapter' as const,+ weight: 1,+ },+ id: 'ref1',+ isEnabled: true,+ };+ const nodes = [+ layer('ga', 'regional_guidance', { referenceImages: [ref] }),+ layer('gb', 'regional_guidance'),+ layer('r1'),+ ];+ const project = projectWith(nodes, 'ga');+ const move = {+ patches: [+ {+ before: { layerType: 'regional_guidance' as const, referenceImages: [ref] },+ config: { layerType: 'regional_guidance' as const, referenceImages: [] },+ id: 'ga',+ },+ {+ before: { layerType: 'regional_guidance' as const, referenceImages: [] },+ config: { layerType: 'regional_guidance' as const, referenceImages: [ref] },+ id: 'gb',+ },+ ],+ type: 'patch-config-batch' as const,+ };+ const { after } = roundTrip(project, move);+ const leaves = getDocumentLeaves(after.canvas.document);+ const refsOf = (id: string) => {+ const found = leaves.find((leaf) => leaf.id === id);+ return found?.type === 'regional_guidance' ? found.referenceImages.map((entry) => entry.id) : null;+ };+ expect(refsOf('ga')).toEqual([]);+ expect(refsOf('gb')).toEqual(['ref1']);++ expect(modelOf(project).prepare({ patches: [], type: 'patch-config-batch' })).toEqual({+ operation: 'patch nothing',+ status: 'unsupported',+ });+ expect(+ modelOf(project).prepare({ patches: [move.patches[0]!, move.patches[0]!], type: 'patch-config-batch' })+ ).toEqual({ operation: 'batch patches one layer twice', status: 'unsupported' });+ const locked = projectWith(+ [layer('ga', 'regional_guidance', { isLocked: true, referenceImages: [ref] }), nodes[1]!, layer('r1')],+ 'ga'+ );+ expect(modelOf(locked).prepare(move)).toMatchObject({ status: 'locked' });+ expect(+ modelOf(project).prepare({+ patches: [+ {+ before: { layerType: 'regional_guidance', referenceImages: [ref] },+ config: { layerType: 'regional_guidance', referenceImages: [ref] },+ id: 'ga',+ },+ ],+ type: 'patch-config-batch',+ })+ ).toEqual({ status: 'unchanged' });+ });+it('round-trips config, source and flag commands through the reducer, groups included', () => {const project = projectWith(tree(), 'r1');const control = roundTrip(project, {diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentModel.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentModel.tsindex 30159d478c..35d27951f4 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentModel.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentModel.ts@@ -1224,6 +1224,59 @@ export const createDocumentModel = ();};+ const preparePatchConfigBatch = (+ command: Extract<DocumentCommand, { type: 'patch-config-batch' }>+ ): PrepareEditResult => {+ if (command.patches.length === 0) {+ return { operation: 'patch nothing', status: 'unsupported' };+ }+ if (unique(command.patches.map((patch) => patch.id)).length !== command.patches.length) {+ return { operation: 'batch patches one layer twice', status: 'unsupported' };+ }+ const forward: { id: string; config: CanvasLayerConfigPatch }[] = [];+ const inverse: { id: string; config: CanvasLayerConfigPatch }[] = [];+ const postconditions: EditPostcondition[] = [];+ const touchedStacks = new Set<LayerStackKind>();+ let changed = false;+ for (const patch of command.patches) {+ const found = editableLeaf(patch.id);+ if ('status' in found) {+ return found;+ }+ const { entry, layer } = found;+ if (layer.type !== patch.config.layerType) {+ return { actual: layer.type, expected: [patch.config.layerType], status: 'wrong-type' };+ }+ if (Object.keys(patch.config).length <= 1) {+ return { operation: 'patch nothing', status: 'unsupported' };+ }+ if (patch.before && patch.before.layerType !== patch.config.layerType) {+ return { operation: 'config baseline names another layer type', status: 'unsupported' };+ }+ if (patch.before && !sameKeys(patch.before, patch.config, CONFIG_CONTAINERS)) {+ return { operation: 'config baseline names other fields', status: 'unsupported' };+ }+ changed ||= patch.before ? !sameValue(patch.before, patch.config) : !isConfigApplied(layer, patch.config);+ forward.push({ config: patch.config, id: patch.id });+ inverse.push({ config: patch.before ?? configInverse(layer, patch.config), id: patch.id });+ postconditions.push({ config: patch.config, id: patch.id, kind: 'config' });+ touchedStacks.add(entry.stack);+ }+ if (!changed) {+ return { status: 'unchanged' };+ }+ return prepared(+ { type: 'updateCanvasLayerConfigs', updates: forward },+ { type: 'updateCanvasLayerConfigs', updates: [...inverse].reverse() },+ {+ postconditions,+ selectionAfter: selectedLayerId,+ touchedIds: command.patches.map((patch) => patch.id),+ touchedStacks: [...touchedStacks],+ }+ );+ };+const preparePatchSource = (command: Extract<DocumentCommand, { type: 'patch-source' }>): PrepareEditResult => {const found = editableLeaf(command.id);if ('status' in found) {@@ -1449,6 +1502,8 @@ export const createDocumentModel = (return preparePatch(command);case 'patch-config':return preparePatchConfig(command);+ case 'patch-config-batch':+ return preparePatchConfigBatch(command);case 'patch-source':return preparePatchSource(command);case 'set-enabled':diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/mutationContracts.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/mutationContracts.tsindex 5568d36584..bec2a9f375 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/mutationContracts.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/mutationContracts.ts@@ -112,6 +112,11 @@ export type CanvasProjectMutation =| { type: 'setCanvasLayersHidden'; updates: readonly { id: string; isHidden: boolean }[] }| { type: 'updateCanvasLayerSource'; id: string; source: CanvasLayerSourceContract }| { type: 'updateCanvasLayerConfig'; id: string; config: CanvasLayerConfigPatch }+ | {+ /** One atomic config patch across several layers, e.g. moving a modifier between two of them. */+ type: 'updateCanvasLayerConfigs';+ updates: readonly { id: string; config: CanvasLayerConfigPatch }[];+ }| {type: 'convertCanvasLayer';id: string;diff --git a/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.ts b/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.tsindex ec9933b59f..66d49ac589 100644--- a/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.ts+++ b/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.ts@@ -82,6 +82,7 @@ const CANVAS_PROJECT_MUTATION_TYPES: ReadonlySet<string> = new Set<CanvasProject'toggleCanvasStagingVisibility','updateCanvasLayer','updateCanvasLayerConfig',+ 'updateCanvasLayerConfigs','updateCanvasLayerSource',]);@@ -828,6 +829,23 @@ export const applyCanvasProjectMutation = (project: Project, mutation: CanvasProreturn updateCanvasDocument(project, (document) =>mapLayer(document, mutation.id, (layer) => patchLayerConfig(layer, mutation.config)));+ case 'updateCanvasLayerConfigs':+ return updateCanvasDocument(project, (document) => {+ // All-or-nothing, like setCanvasLayerPositions: a batch with any+ // unresolvable target applies nothing (history replay must never+ // half-apply an entry).+ const applicable = mutation.updates.every((update) => {+ const layer = getDocumentLayer(document, update.id);+ return layer !== null && layer.type === update.config.layerType;+ });+ if (!applicable) {+ return document;+ }+ return mutation.updates.reduce(+ (current, update) => mapLayer(current, update.id, (layer) => patchLayerConfig(layer, update.config)),+ document+ );+ });case 'convertCanvasLayer': {if (mutation.layer.type !== mutation.targetType) {return project;diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerChildMenu.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerChildMenu.tsxindex 9f1e403bb5..9a3d02f162 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerChildMenu.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerChildMenu.tsx@@ -2,7 +2,16 @@ import type { ComponentProps } from 'react';import { HStack, Icon, Menu, Portal, Text } from '@chakra-ui/react';import { MenuContent } from '@platform/ui';-import { ArrowDownIcon, ArrowUpIcon, CircleIcon, CircleOffIcon, CopyIcon, XIcon, type LucideIcon } from 'lucide-react';+import {+ ArrowDownIcon,+ ArrowRightIcon,+ ArrowUpIcon,+ CircleIcon,+ CircleOffIcon,+ CopyIcon,+ XIcon,+ type LucideIcon,+} from 'lucide-react';import { useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';@@ -41,12 +50,15 @@ export const LayerChildMenu = ({child,commands,editingLocked,+ moveTargets,onClose,}: {anchor: LayerSurfaceAnchor;child: ProjectedChildRow;commands: LayerRowCommands;editingLocked: boolean;+ /** Other layers the item can move to (reference images), keyboard parity for the cross-layer drag. */+ moveTargets: readonly { id: string; name: string }[];onClose: () => void;}) => {const { t } = useTranslation();@@ -106,6 +118,15 @@ export const LayerChildMenu = ({/></>) : null}+ {moveTargets.map((target) => (+ <MoveToLayerItem+ key={target.id}+ child={child}+ commands={commands}+ disabled={editingLocked}+ target={target}+ />+ ))}<ChildMenuItemdisabled={editingLocked}icon={XIcon}@@ -120,3 +141,27 @@ export const LayerChildMenu = ({</Menu.Root>);};++const MoveToLayerItem = ({+ child,+ commands,+ disabled,+ target,+}: {+ child: ProjectedChildRow;+ commands: LayerRowCommands;+ disabled: boolean;+ target: { id: string; name: string };+}) => {+ const { t } = useTranslation();+ const handleSelect = useCallback(() => commands.moveChildToLayer(child, target.id), [child, commands, target.id]);+ return (+ <ChildMenuItem+ disabled={disabled}+ icon={ArrowRightIcon}+ label={t('widgets.layers.modifiers.moveToLayer', { name: target.name })}+ value={`move-to:${target.id}`}+ onSelect={handleSelect}+ />+ );+};diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerChildRow.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerChildRow.tsxindex 3b037a1b0a..076a6e594f 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerChildRow.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerChildRow.tsx@@ -1,16 +1,16 @@import type { CSSProperties, KeyboardEvent, MouseEvent } from 'react';-import { Box, Icon, Text } from '@chakra-ui/react';-import { useDroppable } from '@dnd-kit/core';+import { Box, HStack, Icon, Text } from '@chakra-ui/react';+import { useDraggable, useDroppable } from '@dnd-kit/core';import { Row } from '@platform/ui';import { DropletIcon, GaugeIcon, ImageIcon, SplineIcon, SunMediumIcon, WavesIcon, type LucideIcon } from 'lucide-react';import { memo, useCallback, useMemo, useRef } from 'react';import { useTranslation } from 'react-i18next';-import type { LayerChildRowKind, ProjectedChildRow } from './layerChildRows';import type { LayerRowCommands } from './layerRowCommands';import { LayerActiveDot, ROW_SELECTION_FOCUS } from './LayerActiveDot';+import { isOrderedChildKind, type LayerChildRowKind, type ProjectedChildRow } from './layerChildRows';import { LAYER_TREE_INDENT_PX } from './layerPanelRows';import { anchorFromPoint } from './layerRowCommands';@@ -25,8 +25,12 @@ const CHILD_ROW_GLYPHS: Record<LayerChildRowKind, LucideIcon> = {'reference-image': ImageIcon,};+/** Kinds whose rows can be picked up: reorderable entries and movable reference images. */+export const isDraggableChildKind = (kind: LayerChildRowKind): boolean =>+ kind === 'reference-image' || isOrderedChildKind(kind);+/** The row's display name; reference images are numbered, other modifiers named by kind. */-const childRowName = (child: ProjectedChildRow, t: (key: string) => string): string => {+export const childRowName = (child: ProjectedChildRow, t: (key: string) => string): string => {switch (child.kind) {case 'reference-image':return `${t('widgets.layers.regionalGuidance.referenceImage')} ${child.posInSet}`;@@ -76,13 +80,27 @@ const LayerChildRowComponent = ({disabled: dragDisabled,id: child.key,});+ const { listeners, setNodeRef: setDragRef } = useDraggable({+ data: { stack: child.stack },+ disabled: dragDisabled || !isDraggableChildKind(child.kind),+ id: child.key,+ });const setRowRef = useCallback((element: HTMLDivElement | null) => {rowElement.current = element;setDropRef(element);+ setDragRef(element);},- [setDropRef]+ [setDragRef, setDropRef]);+ // Pointer listeners only, like layer rows: the tree owns the keyboard model.+ const dragListeners = useMemo(() => {+ if (dragDisabled || !listeners) {+ return {};+ }+ const { onKeyDown: _onKeyDown, ...rest } = listeners;+ return rest;+ }, [dragDisabled, listeners]);const name = childRowName(child, t);const indentStyle = useMemo(() => ({ paddingLeft: `${child.depth * LAYER_TREE_INDENT_PX}px` }), [child.depth]);@@ -123,6 +141,7 @@ const LayerChildRowComponent = ({return (<Boxref={setRowRef}+ {...dragListeners}aria-label={name}aria-level={child.depth + 2}aria-posinset={child.posInSet}@@ -192,3 +211,27 @@ const LayerChildRowComponent = ({};export const LayerChildRow = memo(LayerChildRowComponent);++/** The compact card that follows the pointer while a child row is dragged. */+export const ChildDragGhost = ({ child }: { child: ProjectedChildRow }) => {+ const { t } = useTranslation();+ return (+ <HStack+ bg="bg.panel"+ borderColor="accent.solid"+ borderWidth="1px"+ boxShadow="lg"+ cursor="grabbing"+ gap="2"+ maxW="14rem"+ px="2"+ py="1"+ rounded="sm"+ >+ <Icon as={CHILD_ROW_GLYPHS[child.kind]} boxSize="3" color="fg.muted" flexShrink={0} />+ <Text fontSize="2xs" fontWeight="700" truncate>+ {childRowName(child, t)}+ </Text>+ </HStack>+ );+};diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerSurfaceHost.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerSurfaceHost.tsxindex 2a2f6c589d..1c54b2e0b6 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerSurfaceHost.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerSurfaceHost.tsx@@ -3,7 +3,7 @@ import type { CanvasProjectMutation } from '@workbench/canvasProjectMutations';import type { CanvasEngineHandle } from '@workbench/widgets/canvas/useCanvasEngine';import type { Dispatch } from 'react';-import { getDocumentNode } from '@workbench/canvas-engine/api';+import { getDocumentLeaves, getDocumentNode } from '@workbench/canvas-engine/api';import { useCallback, useMemo } from 'react';import type { LayerRowCommands, LayerSurfaceAnchor } from './layerRowCommands';@@ -72,6 +72,21 @@ export const LayerSurfaceHost = ({}return item.isEnabled === child.isEnabled ? child : { ...child, isEnabled: item.isEnabled };}, [document, surface]);+ // Keyboard parity for the cross-layer drag: other regional layers a reference image can move to.+ const moveTargets = useMemo(() => {+ if (surface?.kind !== 'child-menu' || surface.child.kind !== 'reference-image') {+ return [];+ }+ const { child } = surface;+ return getDocumentLeaves(document)+ .filter(+ (leaf) =>+ leaf.type === 'regional_guidance' &&+ leaf.id !== child.layerId &&+ !leaf.referenceImages.some((ref) => ref.id === child.itemId)+ )+ .map((leaf) => ({ id: leaf.id, name: leaf.name }));+ }, [document, surface]);if (surface?.kind === 'stack-menu') {return (<LayerStackMenu@@ -94,6 +109,7 @@ export const LayerSurfaceHost = ({child={liveChild}commands={commands}editingLocked={editingLocked}+ moveTargets={moveTargets}onClose={onClose}/>);diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.browser.test.tsxindex 12d1074c07..a44dcc0854 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.browser.test.tsx@@ -235,12 +235,15 @@ const Harness = ({ initialNodes }: { initialNodes: CanvasNodeContract[] }) => {})()}</output><output data-testid="regional-refs" style={HIDDEN}>- {(() => {- const layer = getDocumentLayer(document, 'rg');- return layer?.type === 'regional_guidance'- ? layer.referenceImages.map((ref) => `${ref.id}:${ref.isEnabled ? 'on' : 'off'}`).join(',') || 'empty'- : 'none';- })()}+ {['rg', 'rg2']+ .map((id) => {+ const layer = getDocumentLayer(document, id);+ return layer?.type === 'regional_guidance'+ ? `${id}[${layer.referenceImages.map((ref) => `${ref.id}:${ref.isEnabled ? 'on' : 'off'}`).join(',')}]`+ : null;+ })+ .filter(Boolean)+ .join(' ') || 'none'}</output><output data-testid="selected-layers" style={HIDDEN}>{panel.selectedIds.join(',') || 'none'}@@ -625,11 +628,11 @@ describe('LayersTree projected child rows', () => {await renderTree(regionWithRefs());const dot = treeitem('Reference image 1').querySelector<HTMLButtonElement>('button[aria-label="Toggle active"]')!;await act(() => userEvent.click(dot));- expect(output('regional-refs')).toBe('ref1:off,ref2:on');+ expect(output('regional-refs')).toBe('rg[ref1:off,ref2:on]');expect(output('selected-layer')).toBe('none');treeitem('Reference image 2').focus();await act(() => userEvent.keyboard('{Delete}'));- expect(output('regional-refs')).toBe('ref1:off');+ expect(output('regional-refs')).toBe('rg[ref1:off]');});it('selecting a child selects its owner, records the sub-selection, and reveals Properties', async () => {@@ -682,6 +685,43 @@ describe('LayersTree projected child rows', () => {expect(output('raster-adjustments')).toBe('a1:on,a2:off,a3:on');});+ it('reorders adjustment entries with a pointer drag', async () => {+ await renderTree([+ layerContract('r1', 'raster', {+ adjustments: [+ { brightness: 0.2, contrast: 0, id: 'a1', isEnabled: true, type: 'brightness-contrast' },+ { curves: {}, id: 'a2', isEnabled: true, type: 'curves' },+ ],+ name: 'Painting',+ }),+ ]);+ const curves = host!.querySelector<HTMLElement>('[data-layer-row-id="child:r1:a2"]')!;+ const bc = host!.querySelector<HTMLElement>('[data-layer-row-id="child:r1:a1"]')!;+ const start = centre(curves);+ const end = centre(bc);+ await act(() => pointer('pointerdown', curves, start.x, start.y));+ await act(() => pointer('pointermove', document, start.x + 8, start.y));+ await act(() => pointer('pointermove', document, end.x, end.y - 10));+ await act(() => pointer('pointerup', document, end.x, end.y - 10));+ expect(output('raster-adjustments')).toBe('a2:on,a1:on');+ });++ it('moves a reference image to another regional layer with a pointer drag', async () => {+ await renderTree([+ layerContract('rg', 'regional_guidance', { name: 'Region A', referenceImages: [referenceImage('ref1')] }),+ layerContract('rg2', 'regional_guidance', { name: 'Region B' }),+ ]);+ const refRow = host!.querySelector<HTMLElement>('[data-layer-row-id="child:rg:ref1"]')!;+ const targetRow = host!.querySelector<HTMLElement>('[data-layer-row-id="rg2"]')!;+ const start = centre(refRow);+ const end = centre(targetRow);+ await act(() => pointer('pointerdown', refRow, start.x, start.y));+ await act(() => pointer('pointermove', document, start.x + 8, start.y));+ await act(() => pointer('pointermove', document, end.x, end.y));+ await act(() => pointer('pointerup', document, end.x, end.y));+ expect(output('regional-refs')).toBe('rg[] rg2[ref1:on]');+ });+it('walks child rows from the keyboard and routes their context menu', async () => {await renderTree(regionWithRefs());treeitem('Region').focus();diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.tsxindex 343932783d..04de5bfafc 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.tsx@@ -28,12 +28,14 @@ import type { LayerRowCommands, LayerSurfaceAnchor } from './layerRowCommands';import type { LayerStackRowsByKind } from './layerTreeRows';import type { LayerStackActionsEngine } from './useLayerStackActions';-import { LayerChildRow } from './LayerChildRow';+import { ChildDragGhost, LayerChildRow } from './LayerChildRow';import {+ layerChildDropCommand,layerChildRemoveLabelKey,layerChildRowCommand,layerChildRowKey,projectLayerChildRows,+ type LayerChildDropTarget,type ProjectedChildRow,} from './layerChildRows';import { clearLayerChildSelection, selectLayerChild, useLayerChildSelection } from './layerChildSelection';@@ -82,6 +84,12 @@ interface DragState {readonly depthOffset: number;}+interface ChildDragState {+ readonly child: ProjectedChildRow;+ readonly overKey: string | null;+ readonly edge: 'above' | 'below';+}+interface LayersTreeProps {degraded: boolean;dispatch: Dispatch<CanvasProjectMutation>;@@ -115,6 +123,10 @@ const edgeOf = (return y >= rect.top + rect.height / 2 ? 'below' : 'above';};+/** Which half of a child row the pointer sits in; landings are always between rows. */+const childEdgeOf = (rect: { top: number; height: number } | undefined, y: number): 'above' | 'below' =>+ !rect || y >= rect.top + rect.height / 2 ? 'below' : 'above';+const isMenuKey = (event: KeyboardEvent<HTMLElement>): boolean =>event.key === 'ContextMenu' || (event.key === 'F10' && event.shiftKey);@@ -165,6 +177,12 @@ export const LayersTree = ({useLayoutEffect(() => {dragRef.current = drag;}, [drag]);+ // A child-row drag is its own mode: one row, landings only where its kind allows.+ const [childDrag, setChildDrag] = useState<ChildDragState | null>(null);+ const childDragRef = useRef<ChildDragState | null>(null);+ useLayoutEffect(() => {+ childDragRef.current = childDrag;+ }, [childDrag]);const pointerStart = useRef({ x: 0, y: 0 });const pointerY = useRef(0);const hoverTimer = useRef<ReturnType<typeof setTimeout> | null>(null);@@ -499,6 +517,12 @@ export const LayersTree = ({runStructural(t('widgets.layers.modifiers.reorderAdjustment'), command);}},+ moveChildToLayer: (child, layerId) => {+ const command = layerChildDropCommand(latest.current.document, child, { beforeItemId: null, layerId });+ if (command) {+ runStructural(t('widgets.layers.modifiers.moveReferenceImage'), command);+ }+ },openChildMenu: (child, anchor: LayerSurfaceAnchor) => setSurface({ anchor, child, kind: 'child-menu' }),openMenu: (id, anchor: LayerSurfaceAnchor) => setSurface({ anchor, id, kind: 'menu' }),openStackMenu: (stack, anchor: LayerSurfaceAnchor) => setSurface({ anchor, kind: 'stack-menu', stack }),@@ -689,8 +713,30 @@ export const LayersTree = ({const sensors = useSensors(useSensor(PointerSensor, POINTER_SENSOR_OPTIONS));const dragDisabled = editingLocked || degraded || panel.filter.trim() !== '';const collisionDetection = useCallback<CollisionDetection>((args) => {- const current = dragRef.current;const stack = args.active.data.current?.stack as LayerStackKind | undefined;+ const { childRowByKey: childRows } = latest.current;+ const dragChild = childRows.get(String(args.active.id));+ if (dragChild) {+ // An adjustment lands only among its own layer's rows; a reference image+ // also lands on any other regional layer or its reference rows.+ return pointerWithin({+ ...args,+ droppableContainers: args.droppableContainers.filter((container) => {+ const id = String(container.id);+ if (id === dragChild.key) {+ return false;+ }+ const overChild = childRows.get(id);+ if (dragChild.kind === 'reference-image') {+ return overChild+ ? overChild.kind === 'reference-image'+ : container.data.current?.stack === 'regional_guidance';+ }+ return overChild ? overChild.layerId === dragChild.layerId : id === dragChild.layerId;+ }),+ });+ }+ const current = dragRef.current;// Only a row of the same stack under the pointer counts: nothing snaps across stacks or gaps.// A child row counts as its owner, so it is out whenever the owner travels.return pointerWithin({@@ -700,7 +746,7 @@ export const LayersTree = ({return false;}const id = String(container.id);- const owner = latest.current.childRowByKey.get(id)?.layerId ?? id;+ const owner = childRows.get(id)?.layerId ?? id;return !(current?.travelling.has(owner) ?? false);}),});@@ -709,6 +755,14 @@ export const LayersTree = ({const handleDragStart = useCallback((event: DragStartEvent) => {const activeId = String(event.active.id);+ const activator = event.activatorEvent as PointerEvent;+ const dragChild = childRowByKey.get(activeId);+ if (dragChild) {+ pointerStart.current = { x: activator.clientX ?? 0, y: activator.clientY ?? 0 };+ pointerY.current = pointerStart.current.y;+ setChildDrag({ child: dragChild, edge: 'above', overKey: null });+ return;+ }const stack = event.active.data.current?.stack as LayerStackKind;const rows = stacks[stack].rows;const selected = new Set(selectedSet.has(activeId) ? selectedIds : [activeId]);@@ -727,7 +781,6 @@ export const LayersTree = ({covering = row.vm.depth;}}- const activator = event.activatorEvent as PointerEvent;pointerStart.current = { x: activator.clientX ?? 0, y: activator.clientY ?? 0 };pointerY.current = pointerStart.current.y;setDrag({@@ -743,12 +796,22 @@ export const LayersTree = ({travelling,});},- [selectedIds, selectedSet, stacks]+ [childRowByKey, selectedIds, selectedSet, stacks]);const handleDragMove = useCallback((event: DragMoveEvent) => {- const depthOffset = Math.round(event.delta.x / LAYER_TREE_INDENT_PX);pointerY.current = pointerStart.current.y + event.delta.y;autoScroller.current?.update(pointerY.current);+ if (childDragRef.current) {+ setChildDrag((current) => {+ if (!current) {+ return current;+ }+ const edge = childEdgeOf(event.over?.rect, pointerY.current);+ return current.edge !== edge ? { ...current, edge } : current;+ });+ return;+ }+ const depthOffset = Math.round(event.delta.x / LAYER_TREE_INDENT_PX);setDrag((current) => {if (!current) {return current;@@ -760,6 +823,13 @@ export const LayersTree = ({const handleDragOver = useCallback((event: DragOverEvent) => {const rawOverId = event.over ? String(event.over.id) : null;+ if (childDragRef.current) {+ const edge = childEdgeOf(event.over?.rect, pointerY.current);+ setChildDrag((state) =>+ state && (state.overKey !== rawOverId || state.edge !== edge) ? { ...state, edge, overKey: rawOverId } : state+ );+ return;+ }// A child row stands in for its owner: the only landing beside it is below the owner.const overChild = rawOverId ? childRowByKey.get(rawOverId) : undefined;const overId = overChild ? overChild.layerId : rawOverId;@@ -816,24 +886,99 @@ export const LayersTree = ({[engine, target]);+ // The dragged child's landing plus the command it resolves to; the indicator shows only real landings.+ const childDropPlan = useMemo(() => {+ if (!childDrag?.overKey) {+ return null;+ }+ const { child, edge, overKey } = childDrag;+ const overChild = childRowByKey.get(overKey);+ let dropTarget: LayerChildDropTarget;+ let depth: number;+ if (overChild) {+ const ownerRow = stacks[overChild.stack].rows.find((row) => row.id === overChild.layerId);+ const siblings = ownerRow ? projectLayerChildRows(ownerRow.vm) : [];+ const index = siblings.findIndex((sibling) => sibling.itemId === overChild.itemId);+ dropTarget = {+ beforeItemId: edge === 'above' ? overChild.itemId : (siblings[index + 1]?.itemId ?? null),+ layerId: overChild.layerId,+ };+ depth = overChild.depth;+ } else {+ // Onto a layer row: append to its items (cross-layer for reference images).+ const ownerRow = stacks[child.stack].rows.find((row) => row.id === overKey);+ if (!ownerRow) {+ return null;+ }+ dropTarget = { beforeItemId: null, layerId: overKey };+ depth = ownerRow.vm.depth + 1;+ }+ const command = layerChildDropCommand(document, child, dropTarget);+ if (!command) {+ return null;+ }+ // The model previews locks exactly as it will at drop; a refused landing shows no indicator.+ if (engine && engine.document.model()?.refusalFor(command)) {+ return null;+ }+ return { command, depth, dropTarget };+ }, [childDrag, childRowByKey, document, engine, stacks]);++ const childIndicator = useMemo(() => {+ if (!childDropPlan) {+ return null;+ }+ const { depth, dropTarget } = childDropPlan;+ const beforeKey = dropTarget.beforeItemId ? layerChildRowKey(dropTarget.layerId, dropTarget.beforeItemId) : null;+ const beforeIndex = beforeKey ? rowIndexByKey.get(beforeKey) : undefined;+ if (beforeIndex !== undefined) {+ return { left: depth * LAYER_TREE_INDENT_PX + 14, top: offsets[beforeIndex]! };+ }+ // The end of the layer's rendered children, or right below a childless owner row.+ let index = rowIndexByKey.get(dropTarget.layerId);+ if (index === undefined) {+ return null;+ }+ while (panelRows[index + 1]?.kind === 'child') {+ index += 1;+ }+ return { left: depth * LAYER_TREE_INDENT_PX + 14, top: offsets[index + 1]! };+ }, [childDropPlan, offsets, panelRows, rowIndexByKey]);+const finishDrag = useCallback(() => {clearHoverTimer();autoScroller.current?.stop();setDrag(null);+ setChildDrag(null);}, [clearHoverTimer]);const handleDragEnd = useCallback((_event: DragEndEvent) => {const landing = target;const refused = refusal;+ const childLanding = childDragRef.current ? childDropPlan : null;+ const childKind = childDragRef.current?.child.kind;finishDrag();- if (!landing || refused || dragDisabled) {+ if (dragDisabled) {+ return;+ }+ if (childKind) {+ if (childLanding) {+ const label =+ childKind === 'reference-image'+ ? t('widgets.layers.modifiers.moveReferenceImage')+ : t('widgets.layers.modifiers.reorderAdjustment');+ commitPrepared(label, (model) => model.prepare(childLanding.command));+ }+ return;+ }+ if (!landing || refused) {return;}commitPrepared(t('widgets.layers.actions.reorder'), (model) =>model.prepare({ beforeId: landing.beforeId, ids: landing.ids, parentId: landing.parentId, type: 'reparent' }));},- [commitPrepared, dragDisabled, finishDrag, refusal, t, target]+ [childDropPlan, commitPrepared, dragDisabled, finishDrag, refusal, t, target]);const indicator = useMemo(() => {@@ -978,7 +1123,9 @@ export const LayersTree = ({<LayerChildRowchild={panelRow.child}commands={commands}- dimmed={drag?.travelling.has(panelRow.child.layerId) ?? false}+ dimmed={+ (drag?.travelling.has(panelRow.child.layerId) ?? false) || childDrag?.child.key === panelRow.key+ }dragDisabled={dragDisabled}editingLocked={editingLocked}focused={panelRow.key === focusKey}@@ -990,6 +1137,19 @@ export const LayersTree = ({</VirtualSlot>);})}+ {childIndicator ? (+ <Box+ aria-hidden+ bg="accent.solid"+ h="2px"+ left={`${childIndicator.left}px`}+ pointerEvents="none"+ position="absolute"+ right="2"+ rounded="full"+ top={`${childIndicator.top - 1}px`}+ />+ ) : null}{indicator ? (<Boxaria-hidden@@ -1037,7 +1197,11 @@ export const LayersTree = ({</Box>) : null}<DragOverlay dropAnimation={null} modifiers={OVERLAY_MODIFIERS}>- {activeVm && drag ? <LayerDragGhost count={drag.selectedCount} vm={activeVm} /> : null}+ {childDrag ? (+ <ChildDragGhost child={childDrag.child} />+ ) : activeVm && drag ? (+ <LayerDragGhost count={drag.selectedCount} vm={activeVm} />+ ) : null}</DragOverlay></Box><LayerSurfaceHostdiff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.test.tsindex 2282a3dfe0..ef17491dcd 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.test.ts@@ -3,7 +3,13 @@ import type { RegionalGuidanceReferenceImage } from '@workbench/canvas-engine/apimport { documentFrom, layerContract } from '@workbench/canvas-engine/document-model/documentFixtures.testStub';import { describe, expect, it } from 'vitest';-import { getLayerChildItem, layerChildRowCommand, layerChildRowKey, projectLayerChildRows } from './layerChildRows';+import {+ getLayerChildItem,+ layerChildDropCommand,+ layerChildRowCommand,+ layerChildRowKey,+ projectLayerChildRows,+} from './layerChildRows';import { buildLayerStackRows } from './layerTreeRows';const referenceImage = (id: string, overrides: Partial<RegionalGuidanceReferenceImage> = {}) => ({@@ -229,3 +235,69 @@ describe('adjustment rows', () => {expect(getLayerChildItem(document, 'r1', 'a3')).toEqual({ isEnabled: true, kind: 'adjustment-curves' });});});++describe('layerChildDropCommand', () => {+ const entries = () => [+ { brightness: 0.1, contrast: 0, id: 'a1', isEnabled: true, type: 'brightness-contrast' as const },+ { id: 'a2', isEnabled: false, saturation: -0.4, type: 'hsl' as const },+ { curves: {}, id: 'a3', isEnabled: true, type: 'curves' as const },+ ];+ const twoRegions = () => [+ layerContract('rg1', 'regional_guidance', { referenceImages: [referenceImage('ref1'), referenceImage('ref2')] }),+ layerContract('rg2', 'regional_guidance', { referenceImages: [referenceImage('ref3')] }),+ layerContract('r1', 'raster', { adjustments: entries() }),+ ];+ const adjustment = { itemId: 'a3', kind: 'adjustment-curves' as const, layerId: 'r1' };+ const reference = { itemId: 'ref1', kind: 'reference-image' as const, layerId: 'rg1' };++ it('reorders an adjustment within its layer and refuses cross-layer or no-op landings', () => {+ const document = documentFrom(twoRegions());+ const moved = layerChildDropCommand(document, adjustment, { beforeItemId: 'a1', layerId: 'r1' });+ expect(+ ((moved as { config: unknown }).config as { adjustments: { id: string }[] }).adjustments.map((e) => e.id)+ ).toEqual(['a3', 'a1', 'a2']);+ expect(layerChildDropCommand(document, adjustment, { beforeItemId: null, layerId: 'r1' })).toBeNull();+ expect(layerChildDropCommand(document, adjustment, { beforeItemId: 'a3', layerId: 'r1' })).toBeNull();+ expect(layerChildDropCommand(document, adjustment, { beforeItemId: null, layerId: 'rg1' })).toBeNull();+ });++ it('reorders a reference image within its layer', () => {+ const document = documentFrom(twoRegions());+ const moved = layerChildDropCommand(document, reference, { beforeItemId: null, layerId: 'rg1' });+ expect(+ ((moved as { config: unknown }).config as { referenceImages: { id: string }[] }).referenceImages.map((r) => r.id)+ ).toEqual(['ref2', 'ref1']);+ });++ it('moves a reference image between regional layers as one atomic batch', () => {+ const document = documentFrom(twoRegions());+ const command = layerChildDropCommand(document, reference, { beforeItemId: 'ref3', layerId: 'rg2' });+ expect(command).toMatchObject({ type: 'patch-config-batch' });+ const patches = (command as unknown as { patches: { id: string; config: { referenceImages: { id: string }[] } }[] })+ .patches;+ expect(patches.map((patch) => [patch.id, patch.config.referenceImages.map((r) => r.id)])).toEqual([+ ['rg1', ['ref2']],+ ['rg2', ['ref1', 'ref3']],+ ]);+ expect(layerChildDropCommand(document, reference, { beforeItemId: null, layerId: 'r1' })).toBeNull();+ expect(+ layerChildDropCommand(document, { ...reference, itemId: 'gone' }, { beforeItemId: null, layerId: 'rg2' })+ ).toBeNull();+ });+});++describe('layerChildDropCommand id collisions', () => {+ it('refuses a cross-layer move whose destination already holds the item id', () => {+ const document = documentFrom([+ layerContract('rg1', 'regional_guidance', { referenceImages: [referenceImage('ref1')] }),+ layerContract('rg2', 'regional_guidance', { referenceImages: [referenceImage('ref1')] }),+ ]);+ expect(+ layerChildDropCommand(+ document,+ { itemId: 'ref1', kind: 'reference-image', layerId: 'rg1' },+ { beforeItemId: null, layerId: 'rg2' }+ )+ ).toBeNull();+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.tsindex b6bf8968cd..3b41acdacf 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.ts@@ -204,6 +204,112 @@ export const layerChildRemoveLabelKey = (kind: LayerChildRowKind): string => {type PatchConfigCommand = Extract<DocumentCommand, { type: 'patch-config' }>;+/** Where a dragged child row lands: before `beforeItemId` among `layerId`'s items, or at the end. */+export interface LayerChildDropTarget {+ readonly layerId: string;+ readonly beforeItemId: string | null;+}++const insertAt = <T extends { id: string }>(items: readonly T[], item: T, beforeItemId: string | null): T[] => {+ const index = beforeItemId === null ? items.length : items.findIndex((candidate) => candidate.id === beforeItemId);+ return index < 0 ? [...items, item] : [...items.slice(0, index), item, ...items.slice(index)];+};++/**+ * The document command a child-row drag resolves to, or `null` when it is a+ * no-op or the landing is invalid. Adjustment entries reorder within their+ * layer; a reference image also moves to another regional layer as ONE atomic+ * cross-layer edit.+ */+export const layerChildDropCommand = (+ document: CanvasDocumentContractV3,+ child: Pick<ProjectedChildRow, 'kind' | 'layerId' | 'itemId'>,+ target: LayerChildDropTarget+): DocumentCommand | null => {+ if (target.beforeItemId === child.itemId) {+ return null;+ }+ const source = getDocumentLayer(document, child.layerId);+ if (isOrderedChildKind(child.kind)) {+ if (target.layerId !== child.layerId || source?.type !== 'raster') {+ return null;+ }+ const before = source.adjustments ?? [];+ const entry = before.find((candidate) => candidate.id === child.itemId);+ if (!entry) {+ return null;+ }+ const next = insertAt(+ before.filter((candidate) => candidate.id !== child.itemId),+ entry,+ target.beforeItemId+ );+ if (next.every((candidate, index) => candidate === before[index])) {+ return null;+ }+ return {+ before: { adjustments: [...before], layerType: 'raster' },+ config: { adjustments: next, layerType: 'raster' },+ id: child.layerId,+ type: 'patch-config',+ };+ }+ if (child.kind !== 'reference-image' || source?.type !== 'regional_guidance') {+ return null;+ }+ const ref = source.referenceImages.find((candidate) => candidate.id === child.itemId);+ if (!ref) {+ return null;+ }+ if (target.layerId === child.layerId) {+ const before = source.referenceImages;+ const next = insertAt(+ before.filter((candidate) => candidate.id !== child.itemId),+ ref,+ target.beforeItemId+ );+ if (next.every((candidate, index) => candidate === before[index])) {+ return null;+ }+ return {+ before: { layerType: 'regional_guidance', referenceImages: [...before] },+ config: { layerType: 'regional_guidance', referenceImages: next },+ id: child.layerId,+ type: 'patch-config',+ };+ }+ const destination = getDocumentLayer(document, target.layerId);+ if (destination?.type !== 'regional_guidance') {+ return null;+ }+ // A duplicated layer can carry the same item id (cloneSubtree re-mints only+ // node ids); landing there would alias two rows onto one key. Refuse.+ if (destination.referenceImages.some((candidate) => candidate.id === child.itemId)) {+ return null;+ }+ return {+ patches: [+ {+ before: { layerType: 'regional_guidance', referenceImages: [...source.referenceImages] },+ config: {+ layerType: 'regional_guidance',+ referenceImages: source.referenceImages.filter((candidate) => candidate.id !== child.itemId),+ },+ id: child.layerId,+ },+ {+ before: { layerType: 'regional_guidance', referenceImages: [...destination.referenceImages] },+ config: {+ layerType: 'regional_guidance',+ referenceImages: insertAt(destination.referenceImages, ref, target.beforeItemId),+ },+ id: target.layerId,+ },+ ],+ type: 'patch-config-batch',+ };+};+/*** The document command a child-row action resolves to, or `null` when the* layer or item is gone or the action changes nothing. Both sides of the patchdiff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerRowCommands.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerRowCommands.tsindex e23ff1d743..58763c1988 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerRowCommands.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerRowCommands.ts@@ -41,6 +41,8 @@ export interface LayerRowCommands {removeChild(child: ProjectedChildRow): void;/** Ordered kinds only (adjustment entries): swap with the neighbour in `direction`. */moveChild(child: ProjectedChildRow, direction: -1 | 1): void;+ /** Reference images only: append the item to another regional layer as one atomic edit. */+ moveChildToLayer(child: ProjectedChildRow, layerId: string): void;/** Ordered kinds only: insert a copy directly after the entry. */duplicateChild(child: ProjectedChildRow): void;openChildMenu(child: ProjectedChildRow, anchor: LayerSurfaceAnchor): void;