From 751edcf9b8e0976a1d073603c9eff5dc6e714490 Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Tue, 14 Mar 2023 14:42:40 +0100 Subject: [PATCH] feat(frontend): app components output panel (#1283) * feat(frontend): hierarchical output panel WIP * feat(frontend): wip * feat(frontend): working animations * feat(frontend): working animations * feat(frontend): wip * feat(frontend): wip * feat(frontend): improving connection * feat(frontend): fix search * feat(frontend): output panel v2 * feat(frontend): support table actions * feat(frontend): support table actions * feat(frontend): support background script * feat(frontend): fix background scripts * feat(frontend): simplify code * feat(frontend): fix animation * feat(frontend): fix wording * feat(frontend): fix bg script click * feat(frontend): fix bg script click * feat(frontend): fix bg script click --- .../components/apps/editor/AppEditor.svelte | 4 +- .../lib/components/apps/editor/appUtils.ts | 86 ++++++- .../component/ComponentNavigation.svelte | 32 +-- .../contextPanel/ComponentOutput.svelte | 79 ++++++ .../contextPanel/ComponentOutputViewer.svelte | 15 +- .../editor/contextPanel/ContextPanel.svelte | 234 +++++++----------- .../editor/contextPanel/SubGridOutput.svelte | 72 ++++++ .../components/BackgroundScriptOutput.svelte | 42 ++++ .../components/BackgroundScriptsOutput.svelte | 14 ++ .../components/MinMaxButton.svelte | 27 ++ .../components/OutputHeader.svelte | 86 +++++++ .../components/TableActionOutput.svelte | 23 ++ .../components/TableActionsOutput.svelte | 17 ++ 13 files changed, 544 insertions(+), 187 deletions(-) create mode 100644 frontend/src/lib/components/apps/editor/contextPanel/ComponentOutput.svelte create mode 100644 frontend/src/lib/components/apps/editor/contextPanel/SubGridOutput.svelte create mode 100644 frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptOutput.svelte create mode 100644 frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptsOutput.svelte create mode 100644 frontend/src/lib/components/apps/editor/contextPanel/components/MinMaxButton.svelte create mode 100644 frontend/src/lib/components/apps/editor/contextPanel/components/OutputHeader.svelte create mode 100644 frontend/src/lib/components/apps/editor/contextPanel/components/TableActionOutput.svelte create mode 100644 frontend/src/lib/components/apps/editor/contextPanel/components/TableActionsOutput.svelte diff --git a/frontend/src/lib/components/apps/editor/AppEditor.svelte b/frontend/src/lib/components/apps/editor/AppEditor.svelte index bedc6f8744..51cdc1fdb5 100644 --- a/frontend/src/lib/components/apps/editor/AppEditor.svelte +++ b/frontend/src/lib/components/apps/editor/AppEditor.svelte @@ -186,13 +186,13 @@ {:else} - + - +
{ $selectedComponent = undefined diff --git a/frontend/src/lib/components/apps/editor/appUtils.ts b/frontend/src/lib/components/apps/editor/appUtils.ts index 81116fb748..094355cfb1 100644 --- a/frontend/src/lib/components/apps/editor/appUtils.ts +++ b/frontend/src/lib/components/apps/editor/appUtils.ts @@ -1,5 +1,5 @@ import { getNextId } from '$lib/components/flows/flowStateUtils' -import type { App, EditorBreakpoint, FocusedGrid, GridItem } from '../types' +import type { App, ConnectingInput, EditorBreakpoint, FocusedGrid, GridItem } from '../types' import { getRecommendedDimensionsByComponent, type AppComponent } from './component' import { gridColumns } from '../gridUtils' import { allItems } from '../utils' @@ -34,6 +34,17 @@ export function findGridItemParentGrid(app: App, id: string): string | undefined } } +export function isIdInsideGriditem(app: App, gridItem: GridItem, id: string | undefined): boolean { + const path: string[] = [] + let currentId = id + while (currentId) { + path.push(currentId) + currentId = findGridItemParentGrid(app, currentId)?.split('-')[0] + } + + return path.includes(gridItem.id) +} + export function findGridItem(app: App, id: string): GridItem | undefined { return findGridItemById(app.grid, app.subgrids, id) } @@ -325,3 +336,76 @@ export function expandGriditem( item.w = item.w + left + right item.h = item.h + top + bottom } + +export function sortGridItemsPosition( + gridItems: GridItem[], + breakpoint: EditorBreakpoint +): GridItem[] { + return gridItems.sort((a: GridItem, b: GridItem) => { + const width = breakpoint === 'lg' ? 12 : 3 + + const aX = a[width].x + const aY = a[width].y + const bX = b[width].x + const bY = b[width].y + + if (aY < bY) { + return -1 + } else if (aY > bY) { + return 1 + } else { + if (aX < bX) { + return -1 + } else if (aX > bX) { + return 1 + } else { + return 0 + } + } + }) +} + +export function connectInput( + connectingInput: ConnectingInput, + componentId: string, + path: string +): ConnectingInput { + if (connectingInput) { + connectingInput = { + opened: false, + input: { + connection: { + componentId, + path + }, + type: 'connected' + }, + hoveredComponent: undefined + } + } + + return connectingInput +} + +export function recursivelyFilterKeyInJSON( + json: object, + search: string, + extraSearch?: string | undefined +): object { + let filteredJSON = {} + Object.keys(json).forEach((key) => { + if ( + key.toLowerCase().includes(search.toLowerCase()) || + extraSearch?.toLowerCase().includes(search.toLowerCase()) + ) { + filteredJSON[key] = json[key] + } else if (typeof json[key] === 'object') { + const res = recursivelyFilterKeyInJSON(json[key], search, extraSearch) + + if (Object.keys(res).length !== 0) { + filteredJSON[key] = res + } + } + }) + return filteredJSON +} diff --git a/frontend/src/lib/components/apps/editor/component/ComponentNavigation.svelte b/frontend/src/lib/components/apps/editor/component/ComponentNavigation.svelte index d9c463d356..00c6ff1f94 100644 --- a/frontend/src/lib/components/apps/editor/component/ComponentNavigation.svelte +++ b/frontend/src/lib/components/apps/editor/component/ComponentNavigation.svelte @@ -1,12 +1,11 @@ diff --git a/frontend/src/lib/components/apps/editor/contextPanel/ComponentOutput.svelte b/frontend/src/lib/components/apps/editor/contextPanel/ComponentOutput.svelte new file mode 100644 index 0000000000..22c192e691 --- /dev/null +++ b/frontend/src/lib/components/apps/editor/contextPanel/ComponentOutput.svelte @@ -0,0 +1,79 @@ + + +{#if $staticOutputs[gridItem.id] || gridItem.data.numberOfSubgrids > 1} + { + onHeaderClick(e.detail.manuallyOpen) + }} + id={gridItem.id} + name={getComponentNameById(gridItem.id)} + {first} + {nested} + {expanded} + > +
+ { + $connectingInput = connectInput($connectingInput, gridItem.id, detail) + }} + /> +
+ + + +
+{/if} diff --git a/frontend/src/lib/components/apps/editor/contextPanel/ComponentOutputViewer.svelte b/frontend/src/lib/components/apps/editor/contextPanel/ComponentOutputViewer.svelte index fbbd21e5cc..3f6ac1436e 100644 --- a/frontend/src/lib/components/apps/editor/contextPanel/ComponentOutputViewer.svelte +++ b/frontend/src/lib/components/apps/editor/contextPanel/ComponentOutputViewer.svelte @@ -1,19 +1,22 @@ -{#if Object.keys(object).length > 0} - -{:else} -
No outputs
+{#if Object.keys(filtered).length > 0} + +{:else if $search.length > 0} +
No results
{/if} diff --git a/frontend/src/lib/components/apps/editor/contextPanel/ContextPanel.svelte b/frontend/src/lib/components/apps/editor/contextPanel/ContextPanel.svelte index 68cd12dadf..05c068ceb0 100644 --- a/frontend/src/lib/components/apps/editor/contextPanel/ContextPanel.svelte +++ b/frontend/src/lib/components/apps/editor/contextPanel/ContextPanel.svelte @@ -1,167 +1,99 @@ -
-
-
- - {#if search} - - {/if} -
-
-
- {#each filteredPanels as [componentId, outputs] (componentId)} -
- {#if outputs.length > 0 && $worldStore?.outputsById[componentId]} - {@const name = getComponentNameById(componentId)} -
-
- - - {name} - -
-
- {#key $selectedComponent} - {#key $connectingInput?.opened} - { - connectInput(componentId, detail) - }} - /> - {/key} - {/key} -
-
+
+
+
+
+ + {#if search} + {/if}
- {:else} -
- No outputs found -
- {/each} -
- -
- {#key $state} - - {/key}
-
+ +
+ +
+ +
+
+ State & Context + + + { + $connectingInput = connectInput($connectingInput, 'ctx', detail) + }} + /> + + + + {#key $state} + {#if Object.keys(filteredState).length > 0} + + {:else} +
No results
+ {/if} + {/key} +
+
+ +
+ Components + {#each sortGridItemsPosition($app.grid, $breakpoint) as gridItem, index} + + {/each} +
+
+ Background scripts +
+ +
+
+
+
diff --git a/frontend/src/lib/components/apps/editor/contextPanel/SubGridOutput.svelte b/frontend/src/lib/components/apps/editor/contextPanel/SubGridOutput.svelte new file mode 100644 index 0000000000..399afcf270 --- /dev/null +++ b/frontend/src/lib/components/apps/editor/contextPanel/SubGridOutput.svelte @@ -0,0 +1,72 @@ + + +{#each subGrids as subGridId, index} +
+ {#if subGrids.length > 1} + +
{ + selected = index + }} + > +
+ {name ? name : 'Should implement name'} + {index + 1} +
+
+ {/if} + + {#if selected === index || name !== 'Tabs'} +
+ {#if $app.subgrids && $app.subgrids[subGridId].length > 0} + {#each sortGridItemsPosition($app.subgrids[subGridId], $breakpoint) as subGridItem, index} + { + $connectingInput = connectInput($connectingInput, subGridItem.id, detail) + }} + /> + {/each} + {:else} +
No components
+ {/if} +
+ {/if} +
+{/each} diff --git a/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptOutput.svelte b/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptOutput.svelte new file mode 100644 index 0000000000..b821334163 --- /dev/null +++ b/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptOutput.svelte @@ -0,0 +1,42 @@ + + + { + onHeaderClick(e.detail.manuallyOpen) + }} + shouldOpen={$selectedComponent === id} +> + { + $connectingInput = connectInput($connectingInput, id, detail) + }} + /> + diff --git a/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptsOutput.svelte b/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptsOutput.svelte new file mode 100644 index 0000000000..8958896eb8 --- /dev/null +++ b/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptsOutput.svelte @@ -0,0 +1,14 @@ + + +{#each $app.hiddenInlineScripts as action, index} + +{/each} diff --git a/frontend/src/lib/components/apps/editor/contextPanel/components/MinMaxButton.svelte b/frontend/src/lib/components/apps/editor/contextPanel/components/MinMaxButton.svelte new file mode 100644 index 0000000000..da21e4b1d9 --- /dev/null +++ b/frontend/src/lib/components/apps/editor/contextPanel/components/MinMaxButton.svelte @@ -0,0 +1,27 @@ + + + diff --git a/frontend/src/lib/components/apps/editor/contextPanel/components/OutputHeader.svelte b/frontend/src/lib/components/apps/editor/contextPanel/components/OutputHeader.svelte new file mode 100644 index 0000000000..d24cf40bb1 --- /dev/null +++ b/frontend/src/lib/components/apps/editor/contextPanel/components/OutputHeader.svelte @@ -0,0 +1,86 @@ + + + +
{ + dispatch('handleClick', { manuallyOpen }) + manuallyOpen = !manuallyOpen + }} +> +
+ {id} +
+
+ {name} + {#if !open && !manuallyOpen} + + {:else if manuallyOpen} + + {:else} + + {/if} +
+
+{#if open || manuallyOpen} +
+
+ +
+
+{/if} diff --git a/frontend/src/lib/components/apps/editor/contextPanel/components/TableActionOutput.svelte b/frontend/src/lib/components/apps/editor/contextPanel/components/TableActionOutput.svelte new file mode 100644 index 0000000000..7537e070c7 --- /dev/null +++ b/frontend/src/lib/components/apps/editor/contextPanel/components/TableActionOutput.svelte @@ -0,0 +1,23 @@ + + + + { + $connectingInput = connectInput($connectingInput, id, detail) + }} + /> + diff --git a/frontend/src/lib/components/apps/editor/contextPanel/components/TableActionsOutput.svelte b/frontend/src/lib/components/apps/editor/contextPanel/components/TableActionsOutput.svelte new file mode 100644 index 0000000000..cfa4f0ac75 --- /dev/null +++ b/frontend/src/lib/components/apps/editor/contextPanel/components/TableActionsOutput.svelte @@ -0,0 +1,17 @@ + + +
+ {#if gridItem.data.type === 'tablecomponent' && gridItem.data.actionButtons.length > 0} +
+ {#each gridItem.data.actionButtons as action, index} + + {/each} +
+ {/if} +