mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-20 08:52:59 +00:00
feat: chord editing
This commit is contained in:
@@ -80,6 +80,13 @@ const de = {
|
|||||||
search: {
|
search: {
|
||||||
PLACEHOLDER: "{0} Akkord{{|e}} durchsuchen",
|
PLACEHOLDER: "{0} Akkord{{|e}} durchsuchen",
|
||||||
},
|
},
|
||||||
|
conflict: {
|
||||||
|
TITLE: "Akkordkonflikt",
|
||||||
|
DESCRIPTION:
|
||||||
|
"Der Akkord {0} würde einen bereits existierenden Akkord überschreiben. Wirklich fortfahren?",
|
||||||
|
CONFIRM: "Überschreiben",
|
||||||
|
ABORT: "Überspringen",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
layout: {
|
layout: {
|
||||||
TITLE: "Layout",
|
TITLE: "Layout",
|
||||||
|
|||||||
@@ -78,6 +78,13 @@ const en = {
|
|||||||
search: {
|
search: {
|
||||||
PLACEHOLDER: "Search {0} chord{{|s}}",
|
PLACEHOLDER: "Search {0} chord{{|s}}",
|
||||||
},
|
},
|
||||||
|
conflict: {
|
||||||
|
TITLE: "Chord conflict",
|
||||||
|
DESCRIPTION:
|
||||||
|
"Your chord {0} conflicts with an existing chord. Are you sure you want to overwrite this chord?",
|
||||||
|
CONFIRM: "Overwrite",
|
||||||
|
ABORT: "Skip",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
layout: {
|
layout: {
|
||||||
TITLE: "Layout",
|
TITLE: "Layout",
|
||||||
|
|||||||
57
src/lib/ConfirmDialog.svelte
Normal file
57
src/lib/ConfirmDialog.svelte
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {createEventDispatcher} from "svelte"
|
||||||
|
|
||||||
|
export let title: string
|
||||||
|
export let message: string | undefined
|
||||||
|
export let abortTitle: string
|
||||||
|
export let confirmTitle: string
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
|
export function show() {
|
||||||
|
modal.showModal()
|
||||||
|
}
|
||||||
|
|
||||||
|
let modal: HTMLDialogElement
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<dialog bind:this={modal}>
|
||||||
|
<h1>{@html title}</h1>
|
||||||
|
{#if message}
|
||||||
|
<p>{@html message}</p>
|
||||||
|
{/if}
|
||||||
|
<div class="buttons">
|
||||||
|
<button on:click={() => dispatch("abort")}>{abortTitle}</button>
|
||||||
|
<button class="primary" on:click={() => dispatch("confirm")}>{confirmTitle}</button>
|
||||||
|
</div>
|
||||||
|
</dialog>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
h1 {
|
||||||
|
font-size: 2em;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog {
|
||||||
|
min-width: 300px;
|
||||||
|
max-width: 512px;
|
||||||
|
|
||||||
|
color: var(--md-sys-color-on-background);
|
||||||
|
|
||||||
|
background: var(--md-sys-color-background);
|
||||||
|
border: none;
|
||||||
|
border-radius: 38px;
|
||||||
|
box-shadow: 0 0 48px rgba(0 0 0 / 60%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttons {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog::backdrop {
|
||||||
|
opacity: 0.5;
|
||||||
|
background: black;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
32
src/lib/confirm-dialog.ts
Normal file
32
src/lib/confirm-dialog.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import ConfirmDialog from "$lib/ConfirmDialog.svelte"
|
||||||
|
|
||||||
|
export async function askForConfirmation(
|
||||||
|
title: string,
|
||||||
|
message: string,
|
||||||
|
confirmTitle: string,
|
||||||
|
abortTitle: string,
|
||||||
|
): Promise<boolean> {
|
||||||
|
const dialog = new ConfirmDialog({
|
||||||
|
target: document.body,
|
||||||
|
props: {
|
||||||
|
title,
|
||||||
|
message,
|
||||||
|
confirmTitle,
|
||||||
|
abortTitle,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
dialog.show()
|
||||||
|
|
||||||
|
let resolvePromise: (value: boolean) => void
|
||||||
|
const resultPromise = new Promise<boolean>(resolve => {
|
||||||
|
resolvePromise = resolve
|
||||||
|
})
|
||||||
|
|
||||||
|
dialog.$on("abort", () => resolvePromise(false))
|
||||||
|
dialog.$on("confirm", () => resolvePromise(true))
|
||||||
|
|
||||||
|
const result = await resultPromise
|
||||||
|
dialog.$destroy()
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
@@ -197,7 +197,7 @@ export class CharaDevice {
|
|||||||
*/
|
*/
|
||||||
async getChordPhrase(actions: number[]): Promise<number[] | undefined> {
|
async getChordPhrase(actions: number[]): Promise<number[] | undefined> {
|
||||||
const [phrase] = await this.send(`CML C2 ${stringifyChordActions(actions)}`)
|
const [phrase] = await this.send(`CML C2 ${stringifyChordActions(actions)}`)
|
||||||
return phrase === "0" ? undefined : parsePhrase(phrase)
|
return phrase === "2" ? undefined : parsePhrase(phrase)
|
||||||
}
|
}
|
||||||
|
|
||||||
async setChord(chord: Chord) {
|
async setChord(chord: Chord) {
|
||||||
@@ -211,9 +211,9 @@ export class CharaDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async deleteChord(chord: Pick<Chord, "actions">) {
|
async deleteChord(chord: Pick<Chord, "actions">) {
|
||||||
console.log(`CML C4 ${stringifyChordActions(chord.actions)}`)
|
|
||||||
const status = await this.send(`CML C4 ${stringifyChordActions(chord.actions)}`)
|
const status = await this.send(`CML C4 ${stringifyChordActions(chord.actions)}`)
|
||||||
if (status.at(-1) !== "0") throw new Error(`Failed with status ${status}`)
|
console.log(status)
|
||||||
|
if (status.at(-1) !== "2") throw new Error(`Failed with status ${status}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import {persistentWritable} from "$lib/storage"
|
import {persistentWritable} from "$lib/storage"
|
||||||
import {derived} from "svelte/store"
|
import {derived} from "svelte/store"
|
||||||
import {serializeActions} from "$lib/serial/chord"
|
|
||||||
import type {Chord} from "$lib/serial/chord"
|
import type {Chord} from "$lib/serial/chord"
|
||||||
import {deviceChords, deviceLayout, deviceSettings} from "$lib/serial/connection"
|
import {deviceChords, deviceLayout, deviceSettings} from "$lib/serial/connection"
|
||||||
|
|
||||||
@@ -19,6 +18,7 @@ export interface LayoutChange {
|
|||||||
|
|
||||||
export interface ChordChange {
|
export interface ChordChange {
|
||||||
type: ChangeType.Chord
|
type: ChangeType.Chord
|
||||||
|
id: number[]
|
||||||
actions: number[]
|
actions: number[]
|
||||||
phrase: number[]
|
phrase: number[]
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ export const changes = persistentWritable<Change[]>("changes", [])
|
|||||||
|
|
||||||
export interface Overlay {
|
export interface Overlay {
|
||||||
layout: [Map<number, number>, Map<number, number>, Map<number, number>]
|
layout: [Map<number, number>, Map<number, number>, Map<number, number>]
|
||||||
chords: Map<bigint, number[]>
|
chords: Map<string, Chord>
|
||||||
settings: Map<number, number>
|
settings: Map<number, number>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ export const overlay = derived(changes, changes => {
|
|||||||
overlay.layout[change.layer].set(change.id, change.action)
|
overlay.layout[change.layer].set(change.id, change.action)
|
||||||
break
|
break
|
||||||
case ChangeType.Chord:
|
case ChangeType.Chord:
|
||||||
overlay.chords.set(serializeActions(change.actions), change.phrase)
|
overlay.chords.set(JSON.stringify(change.id), {actions: change.actions, phrase: change.phrase})
|
||||||
break
|
break
|
||||||
case ChangeType.Setting:
|
case ChangeType.Setting:
|
||||||
overlay.settings.set(change.id, change.setting)
|
overlay.settings.set(change.id, change.setting)
|
||||||
@@ -88,24 +88,32 @@ export const layout = derived([overlay, deviceLayout], ([overlay, layout]) =>
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
export type ChordInfo = Chord & ChangeInfo
|
export type ChordInfo = Chord &
|
||||||
|
ChangeInfo & {phraseChanged: boolean; actionsChanged: boolean} & {id: number[]}
|
||||||
export const chords = derived([overlay, deviceChords], ([overlay, chords]) =>
|
export const chords = derived([overlay, deviceChords], ([overlay, chords]) =>
|
||||||
chords
|
chords
|
||||||
.map<ChordInfo>(chord => {
|
.map<ChordInfo>(chord => {
|
||||||
const key = serializeActions(chord.actions)
|
const id = JSON.stringify(chord.actions)
|
||||||
if (overlay.chords.has(key)) {
|
if (overlay.chords.has(id)) {
|
||||||
|
const changedChord = overlay.chords.get(id)!
|
||||||
return {
|
return {
|
||||||
actions: chord.actions,
|
id: chord.actions,
|
||||||
phrase: overlay.chords.get(key)!,
|
actions: changedChord.actions,
|
||||||
|
phrase: changedChord.phrase,
|
||||||
|
actionsChanged: id !== JSON.stringify(changedChord.actions),
|
||||||
|
phraseChanged: JSON.stringify(chord.phrase) !== JSON.stringify(changedChord.phrase),
|
||||||
isApplied: false,
|
isApplied: false,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
|
id: chord.actions,
|
||||||
actions: chord.actions,
|
actions: chord.actions,
|
||||||
phrase: chord.phrase,
|
phrase: chord.phrase,
|
||||||
|
phraseChanged: false,
|
||||||
|
actionsChanged: false,
|
||||||
isApplied: true,
|
isApplied: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.sort((a, b) => (a.actions.some((it, i) => it > b.actions[i]) ? 1 : -1)),
|
.sort((a, b) => a.phrase.map((it, i) => it - b.phrase[i]).find(it => it !== 0) ?? 0),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
import {fly} from "svelte/transition"
|
import {fly} from "svelte/transition"
|
||||||
import {action} from "$lib/title"
|
import {action} from "$lib/title"
|
||||||
import {deviceChords, deviceLayout, deviceSettings, serialPort, syncStatus} from "$lib/serial/connection"
|
import {deviceChords, deviceLayout, deviceSettings, serialPort, syncStatus} from "$lib/serial/connection"
|
||||||
import {deserializeActions} from "$lib/serial/chord"
|
import {askForConfirmation} from "$lib/confirm-dialog"
|
||||||
|
import {KEYMAP_CODES} from "$lib/serial/keymap-codes"
|
||||||
|
|
||||||
function undo(event: MouseEvent) {
|
function undo(event: MouseEvent) {
|
||||||
if (event.shiftKey) {
|
if (event.shiftKey) {
|
||||||
@@ -32,9 +33,29 @@
|
|||||||
|
|
||||||
$syncStatus = "uploading"
|
$syncStatus = "uploading"
|
||||||
|
|
||||||
for (const [id, phrase] of $overlay.chords) {
|
for (const [id, {actions, phrase}] of $overlay.chords) {
|
||||||
const actions = deserializeActions(id)
|
if (phrase.length > 0) {
|
||||||
if (actions.length > 0) {
|
if (id !== JSON.stringify(actions)) {
|
||||||
|
const existingChord = await port.getChordPhrase(actions)
|
||||||
|
if (
|
||||||
|
existingChord !== undefined &&
|
||||||
|
!(await askForConfirmation(
|
||||||
|
$LL.configure.chords.conflict.TITLE(),
|
||||||
|
$LL.configure.chords.conflict.DESCRIPTION(
|
||||||
|
actions.map(it => `<kbd>${KEYMAP_CODES[it].id}</kbd>`).join(" "),
|
||||||
|
),
|
||||||
|
$LL.configure.chords.conflict.CONFIRM(),
|
||||||
|
$LL.configure.chords.conflict.ABORT(),
|
||||||
|
))
|
||||||
|
) {
|
||||||
|
changes.update(changes =>
|
||||||
|
changes.filter(it => !(it.type === ChangeType.Chord && JSON.stringify(it.id) === id)),
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
await port.deleteChord({actions: JSON.parse(id)})
|
||||||
|
}
|
||||||
await port.setChord({actions, phrase})
|
await port.setChord({actions, phrase})
|
||||||
} else {
|
} else {
|
||||||
await port.deleteChord({actions})
|
await port.deleteChord({actions})
|
||||||
@@ -56,7 +77,9 @@
|
|||||||
number[],
|
number[],
|
||||||
number[],
|
number[],
|
||||||
]
|
]
|
||||||
$deviceChords = $chords.map(({actions, phrase}) => ({actions, phrase}))
|
$deviceChords = $chords
|
||||||
|
.map(({actions, phrase}) => ({actions, phrase}))
|
||||||
|
.filter(({phrase}) => phrase.length > 1)
|
||||||
$deviceSettings = $settings.map(({value}) => value)
|
$deviceSettings = $settings.map(({value}) => value)
|
||||||
$changes = []
|
$changes = []
|
||||||
$syncStatus = "done"
|
$syncStatus = "done"
|
||||||
|
|||||||
@@ -92,8 +92,10 @@
|
|||||||
<section bind:this={results}>
|
<section bind:this={results}>
|
||||||
<table>
|
<table>
|
||||||
{#if $lastPage !== -1}
|
{#if $lastPage !== -1}
|
||||||
{#each $items.slice(page * $pageSize, (page + 1) * $pageSize) as [chord], i (`${page}:${i}`)}
|
{#each $items.slice(page * $pageSize, (page + 1) * $pageSize) as [chord] (chord.id)}
|
||||||
<ChordEdit {chord} isApplied={chord.isApplied} />
|
<tr>
|
||||||
|
<ChordEdit {chord} />
|
||||||
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
{:else}
|
{:else}
|
||||||
<caption> No Results </caption>
|
<caption> No Results </caption>
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {Chord} from "$lib/serial/chord"
|
|
||||||
import {KEYMAP_CODES, KEYMAP_IDS} from "$lib/serial/keymap-codes"
|
import {KEYMAP_CODES, KEYMAP_IDS} from "$lib/serial/keymap-codes"
|
||||||
|
import type {ChordInfo} from "$lib/undo-redo"
|
||||||
|
import {changes, ChangeType} from "$lib/undo-redo"
|
||||||
|
|
||||||
export let chord: Chord
|
export let chord: ChordInfo
|
||||||
|
|
||||||
let pressedKeys = new Set<number>()
|
let pressedKeys = new Set<number>()
|
||||||
let editing = false
|
let editing = false
|
||||||
@@ -13,18 +14,35 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function keydown(event: KeyboardEvent) {
|
function keydown(event: KeyboardEvent) {
|
||||||
// TODO...
|
if (!editing) return
|
||||||
|
event.preventDefault()
|
||||||
pressedKeys.add(KEYMAP_IDS.get(event.key)!.code)
|
pressedKeys.add(KEYMAP_IDS.get(event.key)!.code)
|
||||||
pressedKeys = pressedKeys
|
pressedKeys = pressedKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
function keyup() {
|
function keyup() {
|
||||||
|
if (!editing) return
|
||||||
editing = false
|
editing = false
|
||||||
// TODO: apply
|
if (pressedKeys.size < 2) return
|
||||||
|
changes.update(changes => {
|
||||||
|
changes.push({
|
||||||
|
type: ChangeType.Chord,
|
||||||
|
id: chord.id,
|
||||||
|
actions: [...pressedKeys],
|
||||||
|
phrase: chord.phrase,
|
||||||
|
})
|
||||||
|
return changes
|
||||||
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button class:deleted={chord.phrase.length === 0} on:click={edit} on:keydown={keydown} on:keyup={keyup}>
|
<button
|
||||||
|
class:deleted={chord.phrase.length === 0}
|
||||||
|
class:edited={chord.actionsChanged}
|
||||||
|
on:click={edit}
|
||||||
|
on:keydown={keydown}
|
||||||
|
on:keyup={keyup}
|
||||||
|
>
|
||||||
{#if editing && pressedKeys.size === 0}
|
{#if editing && pressedKeys.size === 0}
|
||||||
<span>Press keys</span>
|
<span>Press keys</span>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -34,6 +52,7 @@
|
|||||||
{icon ?? id ?? `0x${code.toString(16)}`}
|
{icon ?? id ?? `0x${code.toString(16)}`}
|
||||||
</kbd>
|
</kbd>
|
||||||
{/each}
|
{/each}
|
||||||
|
<sup>•</sup>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@@ -41,10 +60,19 @@
|
|||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sup {
|
||||||
|
translate: 0 -60%;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 250ms ease;
|
||||||
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
|
|
||||||
|
height: 32px;
|
||||||
margin-inline: 4px;
|
margin-inline: 4px;
|
||||||
|
|
||||||
&:focus-within {
|
&:focus-within {
|
||||||
@@ -53,6 +81,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
kbd {
|
kbd {
|
||||||
|
height: 24px;
|
||||||
|
padding-block: auto;
|
||||||
transition: color 250ms ease;
|
transition: color 250ms ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +104,14 @@
|
|||||||
color 250ms ease;
|
color 250ms ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.edited {
|
||||||
|
color: var(--md-sys-color-primary);
|
||||||
|
|
||||||
|
& > sup {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.deleted {
|
.deleted {
|
||||||
color: var(--md-sys-color-error);
|
color: var(--md-sys-color-error);
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {changes, ChangeType} from "$lib/undo-redo.js"
|
import {changes, ChangeType} from "$lib/undo-redo.js"
|
||||||
|
import type {ChordInfo} from "$lib/undo-redo.js"
|
||||||
import ChordPhraseEdit from "./ChordPhraseEdit.svelte"
|
import ChordPhraseEdit from "./ChordPhraseEdit.svelte"
|
||||||
import ChordActionEdit from "./ChordActionEdit.svelte"
|
import ChordActionEdit from "./ChordActionEdit.svelte"
|
||||||
import type {Chord} from "$lib/serial/chord"
|
import type {Chord} from "$lib/serial/chord"
|
||||||
import {slide} from "svelte/transition"
|
import {slide} from "svelte/transition"
|
||||||
|
|
||||||
export let chord: Chord
|
export let chord: ChordInfo
|
||||||
export let isApplied: boolean
|
|
||||||
|
|
||||||
function remove() {
|
function remove() {
|
||||||
changes.update(changes => {
|
changes.update(changes => {
|
||||||
changes.push({type: ChangeType.Chord, actions: chord.actions, phrase: []})
|
changes.push({type: ChangeType.Chord, id: chord.id, actions: chord.actions, phrase: []})
|
||||||
return changes
|
return changes
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -24,24 +24,22 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<tr>
|
<th>
|
||||||
<th>
|
<ChordActionEdit {chord} />
|
||||||
<ChordActionEdit {chord} />
|
</th>
|
||||||
</th>
|
<td>
|
||||||
<td>
|
<ChordPhraseEdit {chord} />
|
||||||
<ChordPhraseEdit {chord} edited={!isApplied} />
|
</td>
|
||||||
</td>
|
<td class="table-buttons">
|
||||||
<td class="table-buttons">
|
{#if chord.phrase.length === 0}
|
||||||
{#if chord.phrase.length === 0}
|
<button transition:slide class="icon compact" on:click={restore}>restore_from_trash</button>
|
||||||
<button transition:slide class="icon compact" on:click={restore}>restore_from_trash</button>
|
{:else}
|
||||||
{:else}
|
<button transition:slide class="icon compact" on:click={remove}>delete</button>
|
||||||
<button transition:slide class="icon compact" on:click={remove}>delete</button>
|
{/if}
|
||||||
{/if}
|
<button class="icon compact" class:disabled={chord.isApplied} on:click={restore}>undo</button>
|
||||||
<button class="icon compact" class:disabled={isApplied} on:click={restore}>undo</button>
|
<div class="separator" />
|
||||||
<div class="separator" />
|
<button class="icon compact">share</button>
|
||||||
<button class="icon compact">share</button>
|
</td>
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.separator {
|
.separator {
|
||||||
@@ -63,8 +61,8 @@
|
|||||||
transition: opacity 75ms ease;
|
transition: opacity 75ms ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
tr:focus-within > .table-buttons,
|
:global(tr):focus-within > .table-buttons,
|
||||||
tr:hover > .table-buttons {
|
:global(tr):hover > .table-buttons {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -2,12 +2,11 @@
|
|||||||
import {KEYMAP_CODES, KEYMAP_IDS, specialKeycodes} from "$lib/serial/keymap-codes"
|
import {KEYMAP_CODES, KEYMAP_IDS, specialKeycodes} from "$lib/serial/keymap-codes"
|
||||||
import {tick} from "svelte"
|
import {tick} from "svelte"
|
||||||
import ActionSelector from "$lib/components/layout/ActionSelector.svelte"
|
import ActionSelector from "$lib/components/layout/ActionSelector.svelte"
|
||||||
import type {Chord} from "$lib/serial/chord"
|
|
||||||
import {changes, ChangeType} from "$lib/undo-redo"
|
import {changes, ChangeType} from "$lib/undo-redo"
|
||||||
|
import type {ChordInfo} from "$lib/undo-redo"
|
||||||
import {scale} from "svelte/transition"
|
import {scale} from "svelte/transition"
|
||||||
|
|
||||||
export let chord: Chord
|
export let chord: ChordInfo
|
||||||
export let edited: boolean
|
|
||||||
|
|
||||||
function keypress(event: KeyboardEvent) {
|
function keypress(event: KeyboardEvent) {
|
||||||
if (event.key === "ArrowUp") {
|
if (event.key === "ArrowUp") {
|
||||||
@@ -37,9 +36,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deleteAction(at: number, count = 1) {
|
function deleteAction(at: number, count = 1) {
|
||||||
|
if (!(at in chord.phrase)) return
|
||||||
changes.update(changes => {
|
changes.update(changes => {
|
||||||
changes.push({
|
changes.push({
|
||||||
type: ChangeType.Chord,
|
type: ChangeType.Chord,
|
||||||
|
id: chord.id,
|
||||||
actions: chord.actions,
|
actions: chord.actions,
|
||||||
phrase: chord.phrase.toSpliced(at, count),
|
phrase: chord.phrase.toSpliced(at, count),
|
||||||
})
|
})
|
||||||
@@ -51,6 +52,7 @@
|
|||||||
changes.update(changes => {
|
changes.update(changes => {
|
||||||
changes.push({
|
changes.push({
|
||||||
type: ChangeType.Chord,
|
type: ChangeType.Chord,
|
||||||
|
id: chord.id,
|
||||||
actions: chord.actions,
|
actions: chord.actions,
|
||||||
phrase: chord.phrase.toSpliced(at, 0, action),
|
phrase: chord.phrase.toSpliced(at, 0, action),
|
||||||
})
|
})
|
||||||
@@ -132,7 +134,7 @@
|
|||||||
role="textbox"
|
role="textbox"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
bind:this={box}
|
bind:this={box}
|
||||||
class:edited
|
class:edited={chord.phraseChanged}
|
||||||
on:focusin={() => (hasFocus = true)}
|
on:focusin={() => (hasFocus = true)}
|
||||||
on:focusout={() => (hasFocus = false)}
|
on:focusout={() => (hasFocus = false)}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user