From 161d850e2fd9df81ea4593d29f365a3e98dfadd3 Mon Sep 17 00:00:00 2001 From: Denis Mishankov Date: Wed, 17 Jan 2024 06:11:57 +0300 Subject: [PATCH] add id to manipulations --- .../components/AddManipulation.svelte | 20 +++++++++++-------- src/manipulations/components/Append.svelte | 4 +++- src/manipulations/components/Compose.svelte | 4 +++- src/manipulations/components/Prepend.svelte | 4 +++- src/manipulations/components/Replace.svelte | 4 +++- src/manipulations/components/Slice.svelte | 4 +++- .../components/SplitCompose.svelte | 4 +++- .../components/SplitGetFromIndex.svelte | 4 +++- src/manipulations/components/SplitJoin.svelte | 4 ++-- src/manipulations/index.ts | 4 ++++ 10 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/manipulations/components/AddManipulation.svelte b/src/manipulations/components/AddManipulation.svelte index ee83cfc..36c401b 100644 --- a/src/manipulations/components/AddManipulation.svelte +++ b/src/manipulations/components/AddManipulation.svelte @@ -3,47 +3,51 @@ export let manipulations: TManipulation[] = [] + function randomId() { + return (Math.random() + 1).toString(36).substring(2); + } + function onNewManipulationSelect(event: Event) { const target = event.target as HTMLSelectElement switch (target.value) { case "replace": manipulations.push({ - type: "replace", from: "", to: "" + type: "replace", from: "", to: "", id: randomId() }) break case "append": manipulations.push({ - type: "append", suffix: "" + type: "append", suffix: "", id: randomId() }) break case "prepend": manipulations.push({ - type: "prepend", prefix: "" + type: "prepend", prefix: "", id: randomId() }) break case "splitGetFromIndex": manipulations.push({ - type: "splitGetFromIndex", splitString: "", index: 0 + type: "splitGetFromIndex", splitString: "", index: 0, id: randomId() }) break case "compose": manipulations.push({ - type: "compose", pattern: "{}", placeholder: "{}" + type: "compose", pattern: "{}", placeholder: "{}", id: randomId() }) break case "slice": manipulations.push({ - type: "slice", start: 0, end: -1 + type: "slice", start: 0, end: -1, id: randomId() }) break case "splitCompose": manipulations.push({ - type: "splitCompose", splitString: "!", placeholder: "{d}", pattern: "{1}, {0}" + type: "splitCompose", splitString: "!", placeholder: "{d}", pattern: "{1}, {0}", id: randomId() }) break case "splitJoin": manipulations.push({ - type: "splitJoin", splitString: ",", joinString: "!", innerManipulations: [] + type: "splitJoin", splitString: ",", joinString: "!", innerManipulations: [], id: randomId() }) break } diff --git a/src/manipulations/components/Append.svelte b/src/manipulations/components/Append.svelte index 51d63bd..f50aab8 100644 --- a/src/manipulations/components/Append.svelte +++ b/src/manipulations/components/Append.svelte @@ -1,5 +1,7 @@