From 8c4ddf76128b43e8fb83118c9d8f57b4bbce3950 Mon Sep 17 00:00:00 2001 From: hyrious Date: Tue, 30 Jul 2024 10:31:40 +0800 Subject: [PATCH] add move up/down buttons to editor blocks --- src/components/Build.svelte | 42 +++++++++++++++++++++++------------ src/components/Editor.svelte | 26 +++++++++++++++++++--- src/components/Options.svelte | 2 +- src/helpers/completion.ts | 2 +- 4 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/components/Build.svelte b/src/components/Build.svelte index 294bb5e..ed1d725 100644 --- a/src/components/Build.svelte +++ b/src/components/Build.svelte @@ -10,13 +10,13 @@ import Editor from './Editor.svelte' import NpmPackage from './NpmPackage.svelte' import Options from './Options.svelte' + import { flip } from 'svelte/animate' export let show = true let dependencies: Record = Object.create(null) - const default_options = - '--bundle --format=esm --splitting --outdir=/ --packages=external --allow-overwrite'.replace(/[ ]/g, '\n') + const default_options = '--bundle --format=esm --splitting --outdir=. --packages=external' let build_options = $mode === 'build' ? $options : '' $: if ($mode === 'build') { $options = build_options @@ -103,6 +103,15 @@ $files = $files } + function move_file(index: number, direction: -1 | 1) { + const i = index + direction + if (i < 0 || i >= $files.length) return + const temp = $files[i] + $files[i] = $files[index] + $files[index] = temp + $files = $files + } + async function npm_install(raw?: MouseEvent | string | null) { if (typeof raw !== 'string') { raw = prompt('Enter package name:') @@ -209,17 +218,22 @@
- {#each $files as { entry, path, content }, i} - remove_file(i)} - header - rows={2} - label="INPUT" - placeholder="(enter your code here)" - /> + {#each $files as file, i (file)} +
+ remove_file(i)} + on:up={() => move_file(i, -1)} + on:down={() => move_file(i, 1)} + pos={i ? (i === $files.length - 1 ? 2 : 1) : 0} + header + rows={2} + label="INPUT" + placeholder="(enter your code here)" + /> +
{/each}