Skip to content

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.

refactor(webv2): state the wildcard collection formats once

joshistoastabf7931428c0
diff --git a/invokeai/frontend/webv2/performance/architecture-baseline.json b/invokeai/frontend/webv2/performance/architecture-baseline.json
index ec2b1bc000..1e333ccfb9 100644
--- a/invokeai/frontend/webv2/performance/architecture-baseline.json
+++ b/invokeai/frontend/webv2/performance/architecture-baseline.json
@@ -2,15 +2,15 @@
"build": {
"launchpad": {
"baseline": {
- "brotliBytes": 798403,
+ "brotliBytes": 798478,
"cssRawBytes": 2159,
"fontRawBytes": 219480,
- "gzipBytes": 798539,
+ "gzipBytes": 798624,
"imageRawBytes": 156376,
- "initialRawBytes": 1832477,
+ "initialRawBytes": 1832637,
"largestAssetRawBytes": 737748,
"otherAssetRawBytes": 0,
- "ownedRawBytes": 57670,
+ "ownedRawBytes": 57830,
"requestCount": 31,
"scriptRequestCount": 15,
"sourceOwners": [
@@ -161,6 +161,7 @@
"source:src/features/nodes/data/transport.ts",
"source:src/features/nodes/index.ts",
"source:src/features/nodes/ui/NodesPage.tsx",
+ "source:src/platform/browser/downloadBlob.ts",
"source:src/platform/browser/knownBrowserIssues.ts",
"source:src/platform/i18n/client.ts",
"source:src/platform/i18n/languages.ts",
@@ -238,15 +239,15 @@
]
},
"limits": {
- "brotliBytes": 806388,
+ "brotliBytes": 806463,
"cssRawBytes": 2181,
"fontRawBytes": 221675,
- "gzipBytes": 806525,
+ "gzipBytes": 806611,
"imageRawBytes": 157940,
- "initialRawBytes": 1850802,
+ "initialRawBytes": 1850964,
"largestAssetRawBytes": 745126,
"otherAssetRawBytes": 0,
- "ownedRawBytes": 57670,
+ "ownedRawBytes": 57830,
"requestCount": 31,
"scriptRequestCount": 15
},
@@ -256,15 +257,15 @@
},
"editor": {
"baseline": {
- "brotliBytes": 974958,
+ "brotliBytes": 975403,
"cssRawBytes": 2159,
"fontRawBytes": 219480,
- "gzipBytes": 973739,
+ "gzipBytes": 974277,
"imageRawBytes": 156376,
- "initialRawBytes": 2368342,
+ "initialRawBytes": 2369740,
"largestAssetRawBytes": 737748,
"otherAssetRawBytes": 0,
- "ownedRawBytes": 108542,
+ "ownedRawBytes": 108562,
"requestCount": 75,
"scriptRequestCount": 59,
"sourceOwners": [
@@ -533,6 +534,7 @@
"source:src/features/workflow/ui/workflowUiStore.ts",
"source:src/features/workflow/utility.ts",
"source:src/features/workflow/widget.ts",
+ "source:src/platform/browser/downloadBlob.ts",
"source:src/platform/browser/knownBrowserIssues.ts",
"source:src/platform/i18n/client.ts",
"source:src/platform/i18n/languages.ts",
@@ -731,15 +733,15 @@
]
},
"limits": {
- "brotliBytes": 984708,
+ "brotliBytes": 985158,
"cssRawBytes": 2181,
"fontRawBytes": 221675,
- "gzipBytes": 983477,
+ "gzipBytes": 984020,
"imageRawBytes": 157940,
- "initialRawBytes": 2392026,
+ "initialRawBytes": 2393438,
"largestAssetRawBytes": 745126,
"otherAssetRawBytes": 0,
- "ownedRawBytes": 108542,
+ "ownedRawBytes": 108562,
"requestCount": 75,
"scriptRequestCount": 59
},
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.json
index f6a70a76ac..058e8a35f4 100644
--- a/invokeai/frontend/webv2/performance/browser-baseline.json
+++ b/invokeai/frontend/webv2/performance/browser-baseline.json
@@ -25,11 +25,11 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 119.5,
+ "domContentLoadedMedianMs": 109.30000000447035,
"id": "launchpad",
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 119.5,
- "longestTaskMaxMs": 75,
+ "loadMedianMs": 109.30000000447035,
+ "longestTaskMaxMs": 67,
"owner": "app",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:launchpad",
@@ -39,24 +39,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 0,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 95070,
+ "otherRawBytes": 95265,
"requestCount": 19,
- "scriptRawBytes": 1454462,
+ "scriptRawBytes": 1454622,
"scriptRequestCount": 15,
- "totalRawBytes": 1575355
+ "totalRawBytes": 1575710
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 0,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 96021,
+ "otherRawBytes": 96218,
"requestCount": 19,
- "scriptRawBytes": 1469007,
+ "scriptRawBytes": 1469169,
"scriptRequestCount": 15,
- "totalRawBytes": 1591109
+ "totalRawBytes": 1591468
},
- "routeReadyMedianMs": 249.5,
+ "routeReadyMedianMs": 224.60000000149012,
"scriptSourceOwnerSet": "launchpad-static",
"stateProfile": "empty"
},
@@ -83,11 +83,11 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 121.70000000298023,
+ "domContentLoadedMedianMs": 107.5,
"id": "launchpad",
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 121.70000000298023,
- "longestTaskMaxMs": 74,
+ "loadMedianMs": 107.5,
+ "longestTaskMaxMs": 66,
"owner": "app",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:launchpad",
@@ -97,24 +97,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 0,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 95070,
+ "otherRawBytes": 95265,
"requestCount": 19,
- "scriptRawBytes": 1454462,
+ "scriptRawBytes": 1454622,
"scriptRequestCount": 15,
- "totalRawBytes": 1575355
+ "totalRawBytes": 1575710
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 0,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 96021,
+ "otherRawBytes": 96218,
"requestCount": 19,
- "scriptRawBytes": 1469007,
+ "scriptRawBytes": 1469169,
"scriptRequestCount": 15,
- "totalRawBytes": 1591109
+ "totalRawBytes": 1591468
},
- "routeReadyMedianMs": 313.1000000014901,
+ "routeReadyMedianMs": 277.90000000596046,
"scriptSourceOwnerSet": "launchpad-static",
"stateProfile": "representative"
},
@@ -141,13 +141,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 116.70000000298023,
+ "domContentLoadedMedianMs": 107.89999999850988,
"id": "editor-minimal",
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 116.70000000298023,
- "longestTaskMaxMs": 121,
+ "loadMedianMs": 107.89999999850988,
+ "longestTaskMaxMs": 108,
"owner": "workbench",
- "projectSwitchMedianMs": 68.02830799999902,
+ "projectSwitchMedianMs": 65.07688899999994,
"readyMark": "invokeai:ready:widget:center:preview",
"remediationTicket": "deepen-widget-registry-loading",
"resourceBaseline": {
@@ -155,24 +155,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 95070,
+ "otherRawBytes": 95265,
"requestCount": 95,
- "scriptRawBytes": 3003431,
+ "scriptRawBytes": 3005732,
"scriptRequestCount": 89,
- "totalRawBytes": 3296113
+ "totalRawBytes": 3298609
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 96021,
+ "otherRawBytes": 96218,
"requestCount": 95,
- "scriptRawBytes": 3033466,
+ "scriptRawBytes": 3035790,
"scriptRequestCount": 89,
- "totalRawBytes": 3329075
+ "totalRawBytes": 3331596
},
- "routeReadyMedianMs": 645.0999999940395,
+ "routeReadyMedianMs": 605.5,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -199,13 +199,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 122.20000000298023,
+ "domContentLoadedMedianMs": 108.10000000149012,
"id": "editor-minimal",
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 122.29999999701977,
- "longestTaskMaxMs": 139,
+ "loadMedianMs": 108.10000000149012,
+ "longestTaskMaxMs": 120,
"owner": "workbench",
- "projectSwitchMedianMs": 100.80139599999893,
+ "projectSwitchMedianMs": 87.70442700000058,
"readyMark": "invokeai:ready:widget:center:preview",
"remediationTicket": "deepen-widget-registry-loading",
"resourceBaseline": {
@@ -213,24 +213,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 95070,
+ "otherRawBytes": 95265,
"requestCount": 95,
- "scriptRawBytes": 3003431,
+ "scriptRawBytes": 3005732,
"scriptRequestCount": 89,
- "totalRawBytes": 3296113
+ "totalRawBytes": 3298609
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 96021,
+ "otherRawBytes": 96218,
"requestCount": 95,
- "scriptRawBytes": 3033466,
+ "scriptRawBytes": 3035790,
"scriptRequestCount": 89,
- "totalRawBytes": 3329075
+ "totalRawBytes": 3331596
},
- "routeReadyMedianMs": 695.3999999985099,
+ "routeReadyMedianMs": 652,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
},
@@ -257,11 +257,11 @@
"scriptRequestCount": 7,
"totalRawBytes": 293334
},
- "domContentLoadedMedianMs": 121.60000000149012,
+ "domContentLoadedMedianMs": 108.60000000149012,
"id": "editor-canvas",
- "layoutSwitchMedianMs": 90.59999999403954,
- "loadMedianMs": 121.70000000298023,
- "longestTaskMaxMs": 124,
+ "layoutSwitchMedianMs": 74.10000000149012,
+ "loadMedianMs": 108.60000000149012,
+ "longestTaskMaxMs": 109,
"owner": "canvas",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:canvas",
@@ -271,24 +271,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 95070,
+ "otherRawBytes": 95265,
"requestCount": 99,
- "scriptRawBytes": 3279625,
+ "scriptRawBytes": 3281926,
"scriptRequestCount": 93,
- "totalRawBytes": 3572307
+ "totalRawBytes": 3574803
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 96021,
+ "otherRawBytes": 96218,
"requestCount": 99,
- "scriptRawBytes": 3312422,
+ "scriptRawBytes": 3314746,
"scriptRequestCount": 93,
- "totalRawBytes": 3608031
+ "totalRawBytes": 3610552
},
- "routeReadyMedianMs": 822,
+ "routeReadyMedianMs": 755,
"scriptSourceOwnerSet": "editor-canvas-static",
"stateProfile": "empty"
},
@@ -315,11 +315,11 @@
"scriptRequestCount": 7,
"totalRawBytes": 293334
},
- "domContentLoadedMedianMs": 119.89999999850988,
+ "domContentLoadedMedianMs": 108.19999999552965,
"id": "editor-canvas",
- "layoutSwitchMedianMs": 354.3999999985099,
- "loadMedianMs": 119.89999999850988,
- "longestTaskMaxMs": 421,
+ "layoutSwitchMedianMs": 310.1000000014901,
+ "loadMedianMs": 108.19999999552965,
+ "longestTaskMaxMs": 363,
"owner": "canvas",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:canvas",
@@ -329,24 +329,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 95070,
+ "otherRawBytes": 95265,
"requestCount": 99,
- "scriptRawBytes": 3279625,
+ "scriptRawBytes": 3281926,
"scriptRequestCount": 93,
- "totalRawBytes": 3572307
+ "totalRawBytes": 3574803
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 96021,
+ "otherRawBytes": 96218,
"requestCount": 99,
- "scriptRawBytes": 3312422,
+ "scriptRawBytes": 3314746,
"scriptRequestCount": 93,
- "totalRawBytes": 3608031
+ "totalRawBytes": 3610552
},
- "routeReadyMedianMs": 1285.6999999955297,
+ "routeReadyMedianMs": 1127.0999999940395,
"scriptSourceOwnerSet": "editor-canvas-static",
"stateProfile": "representative"
},
@@ -373,11 +373,11 @@
"scriptRequestCount": 3,
"totalRawBytes": 14378
},
- "domContentLoadedMedianMs": 119.5,
+ "domContentLoadedMedianMs": 106.79999999701977,
"id": "editor-workflow",
- "layoutSwitchMedianMs": 83.89999999850988,
- "loadMedianMs": 119.5,
- "longestTaskMaxMs": 124,
+ "layoutSwitchMedianMs": 71.20000000298023,
+ "loadMedianMs": 106.79999999701977,
+ "longestTaskMaxMs": 108,
"owner": "workflow",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:workflow",
@@ -387,24 +387,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 95070,
+ "otherRawBytes": 95265,
"requestCount": 95,
- "scriptRawBytes": 3003431,
+ "scriptRawBytes": 3005732,
"scriptRequestCount": 89,
- "totalRawBytes": 3296113
+ "totalRawBytes": 3298609
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 96021,
+ "otherRawBytes": 96218,
"requestCount": 95,
- "scriptRawBytes": 3033466,
+ "scriptRawBytes": 3035790,
"scriptRequestCount": 89,
- "totalRawBytes": 3329075
+ "totalRawBytes": 3331596
},
- "routeReadyMedianMs": 811.0999999940395,
+ "routeReadyMedianMs": 742.2000000029802,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -431,11 +431,11 @@
"scriptRequestCount": 3,
"totalRawBytes": 14378
},
- "domContentLoadedMedianMs": 121.20000000298023,
+ "domContentLoadedMedianMs": 108.5,
"id": "editor-workflow",
- "layoutSwitchMedianMs": 137.60000000149012,
- "loadMedianMs": 121.20000000298023,
- "longestTaskMaxMs": 460,
+ "layoutSwitchMedianMs": 122.80000000447035,
+ "loadMedianMs": 108.5,
+ "longestTaskMaxMs": 403,
"owner": "workflow",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:workflow",
@@ -445,24 +445,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 95070,
+ "otherRawBytes": 95265,
"requestCount": 95,
- "scriptRawBytes": 3003431,
+ "scriptRawBytes": 3005732,
"scriptRequestCount": 89,
- "totalRawBytes": 3296113
+ "totalRawBytes": 3298609
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 96021,
+ "otherRawBytes": 96218,
"requestCount": 95,
- "scriptRawBytes": 3033466,
+ "scriptRawBytes": 3035790,
"scriptRequestCount": 89,
- "totalRawBytes": 3329075
+ "totalRawBytes": 3331596
},
- "routeReadyMedianMs": 1060.8999999985099,
+ "routeReadyMedianMs": 945.1000000014901,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
},
@@ -489,11 +489,11 @@
"scriptRequestCount": 3,
"totalRawBytes": 14378
},
- "domContentLoadedMedianMs": 119.29999999701977,
+ "domContentLoadedMedianMs": 107.29999999701977,
"id": "editor-gallery",
- "layoutSwitchMedianMs": 31.900000005960464,
- "loadMedianMs": 119.29999999701977,
- "longestTaskMaxMs": 120,
+ "layoutSwitchMedianMs": 27.100000001490116,
+ "loadMedianMs": 107.29999999701977,
+ "longestTaskMaxMs": 106,
"owner": "gallery",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:gallery",
@@ -503,24 +503,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 95070,
+ "otherRawBytes": 95265,
"requestCount": 95,
- "scriptRawBytes": 3003431,
+ "scriptRawBytes": 3005732,
"scriptRequestCount": 89,
- "totalRawBytes": 3296113
+ "totalRawBytes": 3298609
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 96021,
+ "otherRawBytes": 96218,
"requestCount": 95,
- "scriptRawBytes": 3033466,
+ "scriptRawBytes": 3035790,
"scriptRequestCount": 89,
- "totalRawBytes": 3329075
+ "totalRawBytes": 3331596
},
- "routeReadyMedianMs": 762.3999999985099,
+ "routeReadyMedianMs": 704.5,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -547,11 +547,11 @@
"scriptRequestCount": 3,
"totalRawBytes": 14378
},
- "domContentLoadedMedianMs": 119.30000000447035,
+ "domContentLoadedMedianMs": 109.69999999552965,
"id": "editor-gallery",
- "layoutSwitchMedianMs": 42.5,
- "loadMedianMs": 119.30000000447035,
- "longestTaskMaxMs": 129,
+ "layoutSwitchMedianMs": 36.29999999701977,
+ "loadMedianMs": 109.69999999552965,
+ "longestTaskMaxMs": 118,
"owner": "gallery",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:gallery",
@@ -561,24 +561,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 95070,
+ "otherRawBytes": 95265,
"requestCount": 95,
- "scriptRawBytes": 3003431,
+ "scriptRawBytes": 3005732,
"scriptRequestCount": 89,
- "totalRawBytes": 3296113
+ "totalRawBytes": 3298609
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 96021,
+ "otherRawBytes": 96218,
"requestCount": 95,
- "scriptRawBytes": 3033466,
+ "scriptRawBytes": 3035790,
"scriptRequestCount": 89,
- "totalRawBytes": 3329075
+ "totalRawBytes": 3331596
},
- "routeReadyMedianMs": 929.9000000059605,
+ "routeReadyMedianMs": 857.6999999955297,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
}
@@ -738,6 +738,7 @@
"source:src/features/nodes/data/transport.ts",
"source:src/features/nodes/index.ts",
"source:src/features/nodes/ui/NodesPage.tsx",
+ "source:src/platform/browser/downloadBlob.ts",
"source:src/platform/browser/knownBrowserIssues.ts",
"source:src/platform/i18n/client.ts",
"source:src/platform/i18n/languages.ts",
@@ -1233,6 +1234,7 @@
"source:src/features/workflow/ui/workflowUiStore.ts",
"source:src/features/workflow/utility.ts",
"source:src/features/workflow/widget.ts",
+ "source:src/platform/browser/downloadBlob.ts",
"source:src/platform/browser/knownBrowserIssues.ts",
"source:src/platform/i18n/client.ts",
"source:src/platform/i18n/languages.ts",
@@ -2035,6 +2037,7 @@
"source:src/features/workflow/ui/workflowUiStore.ts",
"source:src/features/workflow/utility.ts",
"source:src/features/workflow/widget.ts",
+ "source:src/platform/browser/downloadBlob.ts",
"source:src/platform/browser/knownBrowserIssues.ts",
"source:src/platform/i18n/client.ts",
"source:src/platform/i18n/languages.ts",
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardTransferActions.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardTransferActions.tsx
index 4344b3471b..7981f276b7 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardTransferActions.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardTransferActions.tsx
@@ -10,6 +10,7 @@ import { WildcardImportDialog } from '@features/generation/ui/promptFields/Wildc
import { WildcardWriteError } from '@features/generation/ui/useWildcards';
import {
downloadWildcards,
+ WILDCARD_COLLECTION_FORMATS,
isSupportedWildcardFile,
readWildcardFiles,
WILDCARD_IMPORT_ACCEPT,
@@ -22,7 +23,6 @@ import { DownloadIcon, UploadIcon } from 'lucide-react';
import { useCallback, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
-const EXPORT_FORMATS: WildcardExportFormat[] = ['yaml', 'json'];
const IMPORT_SOURCES = ['files', 'folder'] as const;
/** Not in React's DOM typings, and `multiple` comes along with it implicitly. */
@@ -208,11 +208,9 @@ export const WildcardTransferActions = ({ catalog }: { catalog: WildcardCatalog
<Portal>
<Menu.Positioner>
<MenuContent minW="10rem">
- {EXPORT_FORMATS.map((format) => (
- <Menu.Item key={format} value={format}>
- <Menu.ItemText fontSize="xs">
- {t(`widgets.generate.dynamicPrompts.exportAs${format === 'yaml' ? 'Yaml' : 'Json'}`)}
- </Menu.ItemText>
+ {WILDCARD_COLLECTION_FORMATS.map((format) => (
+ <Menu.Item key={format.id} value={format.id}>
+ <Menu.ItemText fontSize="xs">{t(format.labelKey)}</Menu.ItemText>
</Menu.Item>
))}
</MenuContent>
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/wildcardFiles.ts b/invokeai/frontend/webv2/src/features/generation/ui/wildcardFiles.ts
index 1bf6d14a3d..9ffe30db73 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/wildcardFiles.ts
+++ b/invokeai/frontend/webv2/src/features/generation/ui/wildcardFiles.ts
@@ -17,9 +17,41 @@ import {
} from '@features/generation/core/wildcardTransfer';
import { downloadText } from '@platform/browser/downloadBlob';
-export type WildcardExportFormat = 'json' | 'yaml';
-
-export const WILDCARD_IMPORT_ACCEPT = '.txt,.yaml,.yml,.json,text/plain,application/json';
+/**
+ * Every collection format, stated once.
+ *
+ * Adding one used to mean editing five places that had no idea about each
+ * other: a union type, two ternaries here, the export menu's array, and an i18n
+ * key built by string concatenation — which silently fell back to "Json" for
+ * anything it did not recognise rather than failing to compile.
+ */
+export const WILDCARD_COLLECTION_FORMATS = [
+ {
+ extensions: ['.yaml', '.yml'],
+ id: 'yaml',
+ labelKey: 'widgets.generate.dynamicPrompts.exportAsYaml',
+ mimeType: 'text/yaml',
+ parse: async (text: string): Promise<unknown> => (await import('yaml')).parse(text),
+ stringify: async (value: unknown): Promise<string> => (await import('yaml')).stringify(value),
+ },
+ {
+ extensions: ['.json'],
+ id: 'json',
+ labelKey: 'widgets.generate.dynamicPrompts.exportAsJson',
+ mimeType: 'application/json',
+ parse: (text: string): Promise<unknown> => Promise.resolve(JSON.parse(text) as unknown),
+ stringify: (value: unknown): Promise<string> => Promise.resolve(`${JSON.stringify(value, null, 2)}\n`),
+ },
+] as const;
+
+export type WildcardExportFormat = (typeof WILDCARD_COLLECTION_FORMATS)[number]['id'];
+
+export const WILDCARD_IMPORT_ACCEPT = [
+ '.txt',
+ ...WILDCARD_COLLECTION_FORMATS.flatMap((format) => format.extensions),
+ 'text/plain',
+ 'application/json',
+].join(',');
/** Directory picking supplies a relative path; a plain pick only has a name. */
const getFilePath = (file: File): string =>
@@ -81,7 +113,9 @@ const isTextWildcardFile = (path: string): boolean => {
export const isSupportedWildcardFile = (file: File): boolean => {
const path = getFilePath(file);
- return hasExtension(path, '.yaml', '.yml', '.json') || isTextWildcardFile(path);
+ return (
+ WILDCARD_COLLECTION_FORMATS.some((format) => hasExtension(path, ...format.extensions)) || isTextWildcardFile(path)
+ );
};
export const readWildcardFiles = async (files: readonly File[]): Promise<ParsedWildcard[]> => {
@@ -108,20 +142,11 @@ export const readWildcardFiles = async (files: readonly File[]): Promise<ParsedW
const contents = await file.text();
- if (hasExtension(path, '.yaml', '.yml')) {
- const { parse } = await import('yaml');
-
- try {
- collect(wildcardsFromNestedRecord(parse(contents)), file.name);
- } catch {
- throw new WildcardFileError(file.name);
- }
- continue;
- }
+ const collectionFormat = WILDCARD_COLLECTION_FORMATS.find((format) => hasExtension(path, ...format.extensions));
- if (hasExtension(path, '.json')) {
+ if (collectionFormat) {
try {
- collect(wildcardsFromNestedRecord(JSON.parse(contents)), file.name);
+ collect(wildcardsFromNestedRecord(await collectionFormat.parse(contents)), file.name);
} catch {
throw new WildcardFileError(file.name);
}
@@ -152,9 +177,13 @@ export const readWildcardFiles = async (files: readonly File[]): Promise<ParsedW
*/
export const downloadWildcards = async (
wildcards: readonly ParsedWildcard[],
- format: WildcardExportFormat
+ formatId: WildcardExportFormat
): Promise<void> => {
- const nested = wildcardsToNestedRecord(wildcards);
- const text = format === 'json' ? `${JSON.stringify(nested, null, 2)}\n` : (await import('yaml')).stringify(nested);
- downloadText(text, `wildcards.${format}`, format === 'json' ? 'application/json' : 'text/yaml');
+ const format = WILDCARD_COLLECTION_FORMATS.find((candidate) => candidate.id === formatId);
+
+ if (!format) {
+ throw new Error(`Unknown wildcard export format: ${formatId}`);
+ }
+
+ downloadText(await format.stringify(wildcardsToNestedRecord(wildcards)), `wildcards.${format.id}`, format.mimeType);
};