From a2265f7f41bb82be7e98c216ad5b73ced29959b2 Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Wed, 31 Aug 2022 18:50:36 +0200 Subject: [PATCH] feat(frontend): Script editor (#518) * feat(frontend): Migrate Tabs * feat(frontend): Generalise Menu * feat(frontend): Menu component done * feat(frontend): Fix placements * feat(frontend): Rework component splitting * feat(frontend): Clean unused imports * feat(frontend): Script editor done * feat(frontend): Code cleanup * feat(frontend): Fix linting * feat(frontend): Add running animation Co-authored-by: Ruben Fiszel --- frontend/src/lib/components/EditorBar.svelte | 84 ++-- .../src/lib/components/FlowBuilder.svelte | 2 +- .../src/lib/components/ScriptBuilder.svelte | 260 +++++----- .../src/lib/components/ScriptEditor.svelte | 451 +++++------------- .../{ => common/drawer}/Drawer.svelte | 0 .../common/drawer/DrawerContent.svelte | 21 + .../components/script_editor/LogPanel.svelte | 184 +++++++ frontend/src/routes/__layout@root.svelte | 4 +- frontend/src/routes/scripts/add.svelte | 4 +- .../src/routes/scripts/edit/[...hash].svelte | 5 +- 10 files changed, 497 insertions(+), 518 deletions(-) rename frontend/src/lib/components/{ => common/drawer}/Drawer.svelte (100%) create mode 100644 frontend/src/lib/components/common/drawer/DrawerContent.svelte create mode 100644 frontend/src/lib/components/script_editor/LogPanel.svelte diff --git a/frontend/src/lib/components/EditorBar.svelte b/frontend/src/lib/components/EditorBar.svelte index 2d3646f0f6..2df3910a97 100644 --- a/frontend/src/lib/components/EditorBar.svelte +++ b/frontend/src/lib/components/EditorBar.svelte @@ -2,11 +2,10 @@ import { ResourceService, ScriptService, VariableService } from '$lib/gen' import { getScriptByPath, loadHubScripts, sendUserToast } from '$lib/utils' - import { faSearch } from '@fortawesome/free-solid-svg-icons' + import { faCode, faCube, faFile, faRotate, faRotateLeft } from '@fortawesome/free-solid-svg-icons' import Icon from 'svelte-awesome' import { hubScripts, workspaceStore } from '$lib/stores' - import { Button } from 'flowbite-svelte' import { Highlight } from 'svelte-highlight' import { python, typescript } from 'svelte-highlight/languages' import type Editor from './Editor.svelte' @@ -170,55 +169,69 @@ - -
-
- - - +
+
+ + + Insert resource + +
- + + Search script +
-
- +
+
+ - +
diff --git a/frontend/src/lib/components/FlowBuilder.svelte b/frontend/src/lib/components/FlowBuilder.svelte index 2100853090..8897e340c0 100644 --- a/frontend/src/lib/components/FlowBuilder.svelte +++ b/frontend/src/lib/components/FlowBuilder.svelte @@ -16,7 +16,7 @@ import { onDestroy, onMount } from 'svelte' import Icon from 'svelte-awesome' import { OFFSET } from './CronInput.svelte' - import Drawer from './Drawer.svelte' + import Drawer from './common/drawer/Drawer.svelte' import FlowEditor from './FlowEditor.svelte' import FlowPreviewContent from './FlowPreviewContent.svelte' import { flowStateStore, flowStateToFlow, type FlowState } from './flows/flowState' diff --git a/frontend/src/lib/components/ScriptBuilder.svelte b/frontend/src/lib/components/ScriptBuilder.svelte index c1152c9d67..e399ea3ebe 100644 --- a/frontend/src/lib/components/ScriptBuilder.svelte +++ b/frontend/src/lib/components/ScriptBuilder.svelte @@ -20,10 +20,10 @@ import Required from './Required.svelte' import ScriptEditor from './ScriptEditor.svelte' import ScriptSchema from './ScriptSchema.svelte' + import CenteredPage from './CenteredPage.svelte' let editor: ScriptEditor let scriptSchema: ScriptSchema - $: step = Number($page.url.searchParams.get('step')) || 1 export let script: Script export let initialPath: string = '' @@ -32,7 +32,7 @@ let pathError = '' $: setQueryWithoutLoad($page.url, 'state', encodeState(script)) - + $: step = Number($page.url.searchParams.get('step')) || 1 $: { if (script.language == 'python3') { script.is_trigger = false @@ -103,11 +103,11 @@ }) -
+
-
-
-
+
+
+
+ Next + {:else} {/if} @@ -151,8 +153,10 @@ class="default-button-secondary px-6 max-h-8 mr-2" on:click={async () => { changeStep(step - 1) - }}>Back + Back + {/if} {#if step == 2} + Save (commit) + {/if}
-
- - sync from github instead - - - {#if script.hash != ''} Editing from {script.hash} with path{/if} - {#if initialPath && initialPath != script.path} {initialPath} → {/if} - {script.path} - -
{#if step === 1} -
- changeStep(2)} - namePlaceholder="my_script" - kind="script" - > -
- Script permissions depend on their path. Select the group all - to share your script, and user to keep it private. - docs -
-
-

Language

-
- initContent(e.detail, template)} - bind:value={script.language} - /> -
- {#if script.language == 'deno'} -

Template

- + +
+ changeStep(2)} + namePlaceholder="my_script" + kind="script" + > +
+ Script permissions depend on their path. Select the group + all + to share your script, and user to keep it private. + docs +
+
+

Language

initContent(script.language, e.detail)} - bind:value={template} + on:change={(e) => initContent(e.detail, template)} + bind:value={script.language} />
- {/if} + {#if script.language == 'deno'} +

Template

-

Metadata

+
+ initContent(script.language, e.detail)} + bind:value={template} + /> +
+ {/if} -