Skip to content

Commit

Permalink
add id to manipulations
Browse files Browse the repository at this point in the history
  • Loading branch information
mishankov committed Jan 17, 2024
1 parent e5212aa commit 161d850
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 17 deletions.
20 changes: 12 additions & 8 deletions src/manipulations/components/AddManipulation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion src/manipulations/components/Append.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts" context="module">
export interface AppendManipulation {
import type { ManipulationBase } from "..";
export interface AppendManipulation extends ManipulationBase {
type: "append"
suffix: string
}
Expand Down
4 changes: 3 additions & 1 deletion src/manipulations/components/Compose.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts" context="module">
export interface ComposeManipulation {
import type { ManipulationBase } from "..";
export interface ComposeManipulation extends ManipulationBase {
type: "compose"
pattern: string
placeholder: string
Expand Down
4 changes: 3 additions & 1 deletion src/manipulations/components/Prepend.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts" context="module">
export interface PrependManipulation {
import type { ManipulationBase } from "..";
export interface PrependManipulation extends ManipulationBase {
type: "prepend"
prefix: string
}
Expand Down
4 changes: 3 additions & 1 deletion src/manipulations/components/Replace.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts" context="module">
export interface ReplaceManipulation {
import type { ManipulationBase } from "..";
export interface ReplaceManipulation extends ManipulationBase {
type: "replace"
from: string
to: string
Expand Down
4 changes: 3 additions & 1 deletion src/manipulations/components/Slice.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts" context="module">
export interface SliceManipulation {
import type { ManipulationBase } from "..";
export interface SliceManipulation extends ManipulationBase {
type: "slice"
start: number
end: number
Expand Down
4 changes: 3 additions & 1 deletion src/manipulations/components/SplitCompose.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts" context="module">
export interface SplitComposeManipulation {
import type { ManipulationBase } from "..";
export interface SplitComposeManipulation extends ManipulationBase {
type: "splitCompose"
splitString: string
placeholder: string
Expand Down
4 changes: 3 additions & 1 deletion src/manipulations/components/SplitGetFromIndex.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts" context="module">
export interface SplitGetFromIndexManipulation {
import type { ManipulationBase } from "..";
export interface SplitGetFromIndexManipulation extends ManipulationBase {
type: "splitGetFromIndex"
splitString: string
index: number
Expand Down
4 changes: 2 additions & 2 deletions src/manipulations/components/SplitJoin.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script lang="ts" context="module">
import { type InnerSplitJoinManipulation } from ".."
import type { InnerSplitJoinManipulation, ManipulationBase } from ".."
import { Manipulation, AddManipulation } from ".."
export interface SplitJoinManipulation {
export interface SplitJoinManipulation extends ManipulationBase {
type: "splitJoin"
splitString: string
joinString: string
Expand Down
4 changes: 4 additions & 0 deletions src/manipulations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export {
AddManipulation,
};

export interface ManipulationBase {
id?: string
}

// Union type for all manipulations
export type TManipulation =
| AppendManipulation
Expand Down

0 comments on commit 161d850

Please sign in to comment.