diff --git a/frontend/src/lib/components/FlowBuilder.svelte b/frontend/src/lib/components/FlowBuilder.svelte index 52431ee1e8..0a1fd73f79 100644 --- a/frontend/src/lib/components/FlowBuilder.svelte +++ b/frontend/src/lib/components/FlowBuilder.svelte @@ -85,9 +85,9 @@ import { Triggers } from './triggers/triggers.svelte' import { SplitPanesLayout, - setSplitPanesLayoutContext, - type PanesLayout + setSplitPanesLayoutContext } from './splitPanes/SplitPanesLayout.svelte' + import type { PanesLayout } from './splitPanes/types' import { setTabStateContext, TabsState } from './common/tabs/tabsState.svelte' export let initialPath: string = '' diff --git a/frontend/src/lib/components/common/tabs/Tabs.svelte b/frontend/src/lib/components/common/tabs/Tabs.svelte index 2c7eeb5c7d..90691e0b4e 100644 --- a/frontend/src/lib/components/common/tabs/Tabs.svelte +++ b/frontend/src/lib/components/common/tabs/Tabs.svelte @@ -66,7 +66,6 @@ if (id) { tabsState = getTabStateContext() - console.log('dbg tabsState', tabsState) const tabState = tabsState?.getSelected(id) if (tabState) { selected = tabState diff --git a/frontend/src/lib/components/flows/FlowEditor.svelte b/frontend/src/lib/components/flows/FlowEditor.svelte index 49a62bf28e..87db48e51f 100644 --- a/frontend/src/lib/components/flows/FlowEditor.svelte +++ b/frontend/src/lib/components/flows/FlowEditor.svelte @@ -46,8 +46,8 @@ $copilotCurrentStepStore !== undefined ? 'border-gray-500/75' : '' )} > - - + +
{#if loading}
@@ -69,7 +69,7 @@ {/if}
- + {#if loading}
diff --git a/frontend/src/lib/components/flows/content/FlowModuleComponent.svelte b/frontend/src/lib/components/flows/content/FlowModuleComponent.svelte index 90986d3053..a88ecf4f57 100644 --- a/frontend/src/lib/components/flows/content/FlowModuleComponent.svelte +++ b/frontend/src/lib/components/flows/content/FlowModuleComponent.svelte @@ -376,8 +376,8 @@ {/if}
- - + + {#if flowModule.value.type === 'rawscript'} {#if !noEditor} {#key flowModule.id} @@ -453,9 +453,9 @@ {/key} {/if} - - - + + + {#if !preprocessorModule} Step Input @@ -784,7 +784,7 @@
{#if selected === 'test'} - + @@ -116,7 +116,6 @@ import { Pane } from 'svelte-splitpanes' - import { getSplitPanesLayout } from './SplitPanesLayout.svelte' import type { Snippet } from 'svelte' - import { type ComponentProps, getContext, onDestroy, onMount } from 'svelte' + import { getContext, onMount, type ComponentProps } from 'svelte' + import type { SplitPanesContext } from './types' type SplitpanesProps = ComponentProps - type Props = SplitpanesProps & { + export type Props = SplitpanesProps & { index: number - defaultSize: number children?: Snippet } - let { index, defaultSize, children, ...rest }: Props = $props() + let { index, children, ...rest }: Props = $props() - const splitPanesId = getContext('splitPanesId') - - const splitPanesLayout = getSplitPanesLayout() + const { sizes, setActivePane } = getContext('splitPanesContext') ?? {} onMount(() => { - splitPanesLayout?.mountPane(splitPanesId, index, defaultSize) - }) - - onDestroy(() => { - splitPanesLayout?.unmountPane(splitPanesId, index) + setActivePane(index) }) - + {@render children?.()} diff --git a/frontend/src/lib/components/splitPanes/SplitPanesLayout.svelte.ts b/frontend/src/lib/components/splitPanes/SplitPanesLayout.svelte.ts index fe88020274..f4972232e1 100644 --- a/frontend/src/lib/components/splitPanes/SplitPanesLayout.svelte.ts +++ b/frontend/src/lib/components/splitPanes/SplitPanesLayout.svelte.ts @@ -1,14 +1,8 @@ import { setContext, getContext, tick } from 'svelte' +import type { Pane, PanesLayout } from './types' const KEY = 'splitPanesLayout' -export type Pane = { - size: number | undefined - active: boolean -} - -export type PanesLayout = Pane[] - export class SplitPanesLayout { #layout: Record = $state({}) #changeCb: (() => void) | undefined = undefined @@ -28,30 +22,27 @@ export class SplitPanesLayout { this.#changeCb?.() } - mountPane(layoutId: string, paneIndex: number, defaultSize: number) { - if (!this.#layout[layoutId]) { - this.#layout[layoutId] = [{ size: defaultSize, active: true }] - } else if (this.#readyPanes[layoutId]) { - // Ensure array is long enough - while (this.#layout[layoutId].length <= paneIndex) { - this.#layout[layoutId].push({ size: undefined, active: false }) - } - this.#layout[layoutId][paneIndex].active = true - this.#layout[layoutId][paneIndex].size = this.#layout[layoutId][paneIndex].size ?? defaultSize - this.#scalePanes(layoutId, paneIndex) + addPane(layoutId: string, paneIndex: number) { + if (!this.#readyPanes[layoutId] || !this.#layout[layoutId][paneIndex].size) { + return } else { - // Ensure array is long enough - while (this.#layout[layoutId].length <= paneIndex) { - this.#layout[layoutId].push({ size: undefined, active: false }) - } - - const currentPane = this.#layout[layoutId][paneIndex] - currentPane.active = true - currentPane.size = currentPane.size ?? defaultSize + this.#layout[layoutId][paneIndex].active = true + this.#scalePanes(layoutId, paneIndex) } this.#changeCb?.() } + setPanes(layoutId: string, panes: Pane[]) { + if (!this.#layout[layoutId]) { + this.#layout[layoutId] = [] + } + + this.#layout[layoutId] = panes + this.#scalePanesTo100(layoutId) + this.#readyPanes[layoutId] = true + this.#changeCb?.() + } + #scalePanes(layoutId: string, paneIndex: number) { // Scale other active panes while keeping the current pane size const otherPanesTotal = this.#layout[layoutId] @@ -70,6 +61,7 @@ export class SplitPanesLayout { const activePanesTotal = this.#layout[layoutId] .filter((pane) => pane.active) .reduce((sum, pane) => sum + (pane.size ?? 0), 0) + if (activePanesTotal > 0) { const scale = 100 / activePanesTotal this.#layout[layoutId] = this.#layout[layoutId].map((pane) => @@ -78,10 +70,10 @@ export class SplitPanesLayout { } } - async unmountPane(layoutId: string, paneIndex: number) { - // Wait for the dom refresh to avoid update in the case the splitpane has been removed + async removePane(layoutId: string, paneIndex: number) { + // Wait for the dom refresh to avoid update in the case the splitpane has been removed completly await tick() - if (this.#readyPanes[layoutId]) { + if (this.#readyPanes[layoutId] && this.#layout[layoutId][paneIndex].active) { this.#layout[layoutId][paneIndex].active = false this.#scalePanesTo100(layoutId) } @@ -98,12 +90,6 @@ export class SplitPanesLayout { this.#changeCb?.() } - handleSplitPaneReady(layoutId: string) { - this.#readyPanes[layoutId] = true - this.#scalePanesTo100(layoutId) - this.#changeCb?.() - } - handleSplitPaneDestroy(layoutId: string) { this.#readyPanes[layoutId] = false this.#changeCb?.() diff --git a/frontend/src/lib/components/splitPanes/Splitpanes.svelte b/frontend/src/lib/components/splitPanes/Splitpanes.svelte index b0ec6e6ff3..9886763f2e 100644 --- a/frontend/src/lib/components/splitPanes/Splitpanes.svelte +++ b/frontend/src/lib/components/splitPanes/Splitpanes.svelte @@ -1,30 +1,40 @@ @@ -35,6 +45,15 @@ detail.map((d, index) => ({ size: d.size, index })) ) }} + on:pane-add={({ detail }) => { + splitPanesLayout?.addPane(id, detail.index) + }} + on:pane-remove={({ detail }) => { + splitPanesLayout?.removePane(id, detail.removed.index) + }} + on:ready={() => { + splitPanesLayout?.setPanes(id, panes) + }} {...rest} > {@render children?.()} diff --git a/frontend/src/lib/components/splitPanes/types.ts b/frontend/src/lib/components/splitPanes/types.ts new file mode 100644 index 0000000000..103e29979b --- /dev/null +++ b/frontend/src/lib/components/splitPanes/types.ts @@ -0,0 +1,11 @@ +export type Pane = { + size: number | undefined + active: boolean +} + +export type PanesLayout = Pane[] + +export type SplitPanesContext = { + sizes: (index: number) => number | undefined + setActivePane: (index: number) => void +} diff --git a/frontend/src/routes/(root)/(logged)/flows/edit/[...path]/+page.svelte b/frontend/src/routes/(root)/(logged)/flows/edit/[...path]/+page.svelte index cadf01914c..5b8f9a2286 100644 --- a/frontend/src/routes/(root)/(logged)/flows/edit/[...path]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/flows/edit/[...path]/+page.svelte @@ -16,7 +16,7 @@ import type { ScheduleTrigger } from '$lib/components/triggers' import type { GetInitialAndModifiedValues } from '$lib/components/common/confirmationModal/unsavedTypes' import type { Trigger } from '$lib/components/triggers/utils' - import type { PanesLayout } from '$lib/components/splitPanes/SplitPanesLayout.svelte' + import type { PanesLayout } from '$lib/components/splitPanes/types' let version: undefined | number = undefined let nodraft = $page.url.searchParams.get('nodraft')