[Theme] Loosen color palette schema (#2053)

This commit is contained in:
Chenlei Hu
2024-12-25 22:47:10 -05:00
committed by GitHub
parent e7528f13a2
commit 9d7a7dae62
3 changed files with 35 additions and 15 deletions

View File

@@ -131,11 +131,8 @@ const customColorPalettes = {
} }
test.describe('Color Palette', () => { test.describe('Color Palette', () => {
test.beforeEach(async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.CustomColorPalettes', customColorPalettes)
})
test('Can show custom color palette', async ({ comfyPage }) => { test('Can show custom color palette', async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.CustomColorPalettes', customColorPalettes)
await comfyPage.setSetting('Comfy.ColorPalette', 'custom_obsidian_dark') await comfyPage.setSetting('Comfy.ColorPalette', 'custom_obsidian_dark')
await comfyPage.nextFrame() await comfyPage.nextFrame()
await expect(comfyPage.canvas).toHaveScreenshot( await expect(comfyPage.canvas).toHaveScreenshot(
@@ -145,6 +142,19 @@ test.describe('Color Palette', () => {
await comfyPage.nextFrame() await comfyPage.nextFrame()
await expect(comfyPage.canvas).toHaveScreenshot('default-color-palette.png') await expect(comfyPage.canvas).toHaveScreenshot('default-color-palette.png')
}) })
test('Can add custom color palette', async ({ comfyPage }) => {
await comfyPage.page.evaluate((p) => {
window['app'].extensionManager.colorPalette.addCustomColorPalette(p)
}, customColorPalettes.obsidian_dark)
expect(await comfyPage.getToastErrorCount()).toBe(0)
await comfyPage.setSetting('Comfy.ColorPalette', 'custom_obsidian_dark')
await comfyPage.nextFrame()
await expect(comfyPage.canvas).toHaveScreenshot(
'custom-color-palette-obsidian-dark.png'
)
})
}) })
test.describe('Node Color Adjustments', () => { test.describe('Node Color Adjustments', () => {

View File

@@ -7,6 +7,7 @@ import { useCommandStore } from './commandStore'
import { useSidebarTabStore } from './workspace/sidebarTabStore' import { useSidebarTabStore } from './workspace/sidebarTabStore'
import { useSettingStore } from './settingStore' import { useSettingStore } from './settingStore'
import { useWorkflowStore } from './workflowStore' import { useWorkflowStore } from './workflowStore'
import { useColorPaletteService } from '@/services/colorPaletteService'
export const useWorkspaceStore = defineStore('workspace', () => { export const useWorkspaceStore = defineStore('workspace', () => {
const spinner = ref(false) const spinner = ref(false)
@@ -30,6 +31,7 @@ export const useWorkspaceStore = defineStore('workspace', () => {
set: useSettingStore().set set: useSettingStore().set
})) }))
const workflow = computed(() => useWorkflowStore()) const workflow = computed(() => useWorkflowStore())
const colorPalette = useColorPaletteService()
/** /**
* Registers a sidebar tab. * Registers a sidebar tab.
@@ -71,6 +73,7 @@ export const useWorkspaceStore = defineStore('workspace', () => {
sidebarTab, sidebarTab,
setting, setting,
workflow, workflow,
colorPalette,
registerSidebarTab, registerSidebarTab,
unregisterSidebarTab, unregisterSidebarTab,

View File

@@ -34,7 +34,9 @@ const litegraphBaseSchema = z.object({
NODE_DEFAULT_SHAPE: z.union([ NODE_DEFAULT_SHAPE: z.union([
z.literal(LiteGraph.BOX_SHAPE), z.literal(LiteGraph.BOX_SHAPE),
z.literal(LiteGraph.ROUND_SHAPE), z.literal(LiteGraph.ROUND_SHAPE),
z.literal(LiteGraph.CARD_SHAPE) z.literal(LiteGraph.CARD_SHAPE),
// Legacy palettes have string field for NODE_DEFAULT_SHAPE.
z.string()
]), ]),
NODE_BOX_OUTLINE_COLOR: z.string(), NODE_BOX_OUTLINE_COLOR: z.string(),
NODE_BYPASS_BGCOLOR: z.string(), NODE_BYPASS_BGCOLOR: z.string(),
@@ -85,17 +87,22 @@ const partialColorsSchema = z.object({
comfy_base: comfyBaseSchema.partial() comfy_base: comfyBaseSchema.partial()
}) })
export const paletteSchema = z.object({ // Palette in the wild can have custom metadata fields such as 'version'.
id: z.string(), export const paletteSchema = z
name: z.string(), .object({
colors: partialColorsSchema id: z.string(),
}) name: z.string(),
colors: partialColorsSchema
})
.passthrough()
export const completedPaletteSchema = z.object({ export const completedPaletteSchema = z
id: z.string(), .object({
name: z.string(), id: z.string(),
colors: colorsSchema name: z.string(),
}) colors: colorsSchema
})
.passthrough()
export const colorPalettesSchema = z.record(paletteSchema) export const colorPalettesSchema = z.record(paletteSchema)