From 9e35b32e992345925c01cdac662fe742a9d4933b Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Sat, 6 May 2023 13:17:08 -0500 Subject: [PATCH] Accordion container --- package.json | 1 + pnpm-lock.yaml | 3 + src/lib/components/AccordionContainer.svelte | 192 +++++++++++++++++++ src/lib/components/Container.svelte | 3 + src/lib/components/TabsContainer.svelte | 13 +- src/lib/stores/layoutState.ts | 24 ++- vite.config.ts | 3 +- 7 files changed, 218 insertions(+), 21 deletions(-) create mode 100644 src/lib/components/AccordionContainer.svelte diff --git a/package.json b/package.json index a6e5b0d..f17a7d0 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ }, "type": "module", "dependencies": { + "@gradio/accordion": "workspace:*", "@gradio/atoms": "workspace:*", "@gradio/button": "workspace:*", "@gradio/client": "workspace:*", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2edccfd..294447b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,9 @@ importers: .: dependencies: + '@gradio/accordion': + specifier: workspace:* + version: link:gradio/js/accordion '@gradio/atoms': specifier: workspace:* version: link:gradio/js/atoms diff --git a/src/lib/components/AccordionContainer.svelte b/src/lib/components/AccordionContainer.svelte new file mode 100644 index 0000000..62b9926 --- /dev/null +++ b/src/lib/components/AccordionContainer.svelte @@ -0,0 +1,192 @@ + + +{#if container && children} +
+ {#if edit} + + +
+ {#each children.filter(item => item.id !== SHADOW_PLACEHOLDER_ITEM_ID) as item(item.id)} + {@const hidden = item?.attrs?.hidden} +
+ + {#if item[SHADOW_ITEM_MARKER_PROPERTY_NAME]} +
+ {/if} +
+ {/each} +
+ {#if container.attrs.hidden && edit} +
+ {/if} + {#if showHandles} +
+ {/if} + + + {:else} + + + {#each children.filter(item => item.id !== SHADOW_PLACEHOLDER_ITEM_ID) as item(item.id)} + + {/each} + + + {/if} +
+{/if} + + diff --git a/src/lib/components/Container.svelte b/src/lib/components/Container.svelte index bb756af..22d82d2 100644 --- a/src/lib/components/Container.svelte +++ b/src/lib/components/Container.svelte @@ -3,6 +3,7 @@ import uiState from "$lib/stores/uiState"; import WidgetContainer from "./WidgetContainer.svelte" import BlockContainer from "./BlockContainer.svelte" + import AccordionContainer from "./AccordionContainer.svelte" import TabsContainer from "./TabsContainer.svelte" import { dndzone, SHADOW_ITEM_MARKER_PROPERTY_NAME, SHADOW_PLACEHOLDER_ITEM_ID } from 'svelte-dnd-action'; @@ -34,6 +35,8 @@ {#key $attrsChanged} {#if container.attrs.variant === "tabs"} + {:else if container.attrs.variant === "accordion"} + {:else} {/if} diff --git a/src/lib/components/TabsContainer.svelte b/src/lib/components/TabsContainer.svelte index b8344c5..108bb35 100644 --- a/src/lib/components/TabsContainer.svelte +++ b/src/lib/components/TabsContainer.svelte @@ -47,13 +47,15 @@ }; function getTabName(container: ContainerLayout, i: number): string { - const tabNames = container.attrs.tabNames - if (!tabNames) - return `Tab ${i}` + const title = container.attrs.title + if (!title) + return `Tab ${i+1}` + + const tabNames = title.split(",").map(s => s.trim()); const tabName = tabNames[i] if (tabName == null || tabName === "") - return `Tab ${i}` + return `Tab ${i+1}` return tabName } @@ -68,9 +70,6 @@ class:edit={edit}> {#if edit} - {#if container.attrs.title && container.attrs.title !== ""} - {container.attrs.title} - {/if}
di.type === "container", refreshPanelOnChange: true }, - - { - name: "tabNames", - type: "string", - location: "widget", - editable: true, - defaultValue: ["Tab 1", "Tab 2", "Tab 3"], - canShow: (di: IDragItem) => di.type === "container" && di.attrs.variant === "tabs", - serialize: serializeStringArray, - deserialize: deserializeStringArray - }, - { name: "blockVariant", type: "enum", @@ -156,6 +144,16 @@ const ALL_ATTRIBUTES: AttributesSpecList = [ defaultValue: "block", canShow: (di: IDragItem) => di.type === "container" }, + + // Accordion + { + name: "openOnStartup", + type: "boolean", + location: "widget", + editable: true, + defaultValue: false, + canShow: (di: IDragItem) => di.type === "container" && di.attrs.variant === "accordion" + }, ] }, { diff --git a/vite.config.ts b/vite.config.ts index 4ed4baf..ac36164 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -11,9 +11,10 @@ export default defineConfig({ FullReload([ // "src/**/*.{js,ts,scss,svelte}" "src/**/*.{scss}", + "src/lib/stores/*.*", "src/**/ComfyApp.{ts,svelte}" ]), - svelte(), , + svelte(), viteStaticCopy({ targets: [ {