-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from Cycling74/fde/midi_mapping_view
Add Global MIDI Mapping View
- Loading branch information
Showing
26 changed files
with
964 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import { NumberInput, Table, TextInput } from "@mantine/core"; | ||
import { ChangeEvent, FC, KeyboardEvent, memo, useCallback, useEffect, useState } from "react"; | ||
import classes from "./elements.module.css"; | ||
|
||
export type EditableTableNumberCellProps = { | ||
className?: string; | ||
min: number; | ||
max: number; | ||
name: string; | ||
onUpdate: (val: number) => void; | ||
prefix?: string; | ||
value: number; | ||
}; | ||
|
||
export const EditableTableNumberCell: FC<EditableTableNumberCellProps> = memo(function WrappedEditableNumberField({ | ||
className = "", | ||
min, | ||
max, | ||
name, | ||
onUpdate, | ||
prefix, | ||
value | ||
}) { | ||
const [isEditing, setIsEditing] = useState<boolean>(false); | ||
const [currentValue, setCurrentValue] = useState<number>(value); | ||
|
||
const onTriggerEdit = useCallback(() => { | ||
if (isEditing) return; | ||
setIsEditing(true); | ||
setCurrentValue(value); | ||
}, [isEditing, setIsEditing, setCurrentValue, value]); | ||
|
||
const onChange = useCallback((val: number) => { | ||
setCurrentValue(val); | ||
}, [setCurrentValue]); | ||
|
||
const onBlur = useCallback(() => { | ||
setIsEditing(false); | ||
if (currentValue === value) return; | ||
onUpdate(currentValue); | ||
}, [setIsEditing, value, currentValue, onUpdate]); | ||
|
||
const onKeyDown = useCallback((e: KeyboardEvent<HTMLInputElement>): void => { | ||
if (e.key === "Escape") { | ||
setIsEditing(false); | ||
setCurrentValue(value); | ||
return void e.preventDefault(); | ||
} else if (e.key === "Enter") { | ||
setIsEditing(false); | ||
if (currentValue === value) return; | ||
onUpdate(currentValue); | ||
return void e.preventDefault(); | ||
} | ||
}, [setIsEditing, setCurrentValue, value, currentValue, onUpdate]); | ||
|
||
useEffect(() => { | ||
setCurrentValue(value); | ||
}, [value, setCurrentValue]); | ||
|
||
return ( | ||
<Table.Td className={ className } onClick={ onTriggerEdit } py={ 0 } > | ||
{ | ||
isEditing ? ( | ||
<NumberInput | ||
autoFocus | ||
className={ classes.editableTableCellInput } | ||
variant="unstyled" | ||
onBlur={ onBlur } | ||
onChange={ onChange } | ||
onKeyDown={ onKeyDown } | ||
name={ name } | ||
min={ min } | ||
max={ max } | ||
prefix={ prefix } | ||
size="xs" | ||
value={ currentValue } | ||
/> | ||
) : `${prefix || ""}${value}` | ||
} | ||
|
||
</Table.Td> | ||
); | ||
}); | ||
|
||
export type EditableTableTextCellProps = { | ||
className?: string; | ||
name: string; | ||
onUpdate: (val: string) => void; | ||
value: string; | ||
}; | ||
|
||
export const EditableTableTextCell: FC<EditableTableTextCellProps> = memo(function WrappedEditableTextField({ | ||
className = "", | ||
name, | ||
onUpdate, | ||
value | ||
}) { | ||
const [isEditing, setIsEditing] = useState<boolean>(false); | ||
const [currentValue, setCurrentValue] = useState<string>(value); | ||
|
||
const onTriggerEdit = useCallback(() => { | ||
if (isEditing) return; | ||
setIsEditing(true); | ||
setCurrentValue(value); | ||
}, [isEditing, setIsEditing, setCurrentValue, value]); | ||
|
||
const onChange = useCallback((e: ChangeEvent<HTMLInputElement>) => { | ||
setCurrentValue(e.target.value); | ||
}, [setCurrentValue]); | ||
|
||
const onBlur = useCallback(() => { | ||
setIsEditing(false); | ||
if (currentValue === value) return; | ||
onUpdate(currentValue); | ||
}, [setIsEditing, value, currentValue, onUpdate]); | ||
|
||
const onKeyDown = useCallback((e: KeyboardEvent<HTMLInputElement>): void => { | ||
if (e.key === "Escape") { | ||
setIsEditing(false); | ||
setCurrentValue(value); | ||
return void e.preventDefault(); | ||
} else if (e.key === "Enter") { | ||
setIsEditing(false); | ||
if (currentValue === value) return; | ||
onUpdate(currentValue); | ||
return void e.preventDefault(); | ||
} | ||
}, [setIsEditing, setCurrentValue, value, currentValue, onUpdate]); | ||
|
||
useEffect(() => { | ||
setCurrentValue(value); | ||
}, [value, setCurrentValue]); | ||
|
||
return ( | ||
<Table.Td className={ className } onClick={ onTriggerEdit } py={ 0 } > | ||
{ | ||
isEditing ? ( | ||
<TextInput | ||
autoFocus | ||
className={ classes.editableTableCellInput } | ||
variant="unstyled" | ||
onBlur={ onBlur } | ||
onChange={ onChange } | ||
onKeyDown={ onKeyDown } | ||
name={ name } | ||
size="xs" | ||
value={ currentValue } | ||
/> | ||
) : value | ||
} | ||
|
||
</Table.Td> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
.icon { | ||
width: 1.3em; | ||
} | ||
|
||
.editableTableCellInput { | ||
border-bottom: 1px solid var(--mantine-primary-color-filled); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Group, MantineFontSize, Table, Text, UnstyledButton } from "@mantine/core"; | ||
import { FC, PropsWithChildren, useCallback } from "react"; | ||
import { SortOrder } from "../../lib/constants"; | ||
import { IconElement } from "./icon"; | ||
import { mdiChevronDown, mdiChevronUp, mdiUnfoldMoreHorizontal } from "@mdi/js"; | ||
|
||
export type TableHeaderCellProps = PropsWithChildren<{ | ||
className?: string; | ||
fz?: MantineFontSize; | ||
|
||
onSort?: (sortKey: string) => void; | ||
sorted?: boolean; | ||
sortKey?: string; | ||
sortOrder?: SortOrder; | ||
}>; | ||
|
||
export const TableHeaderCell: FC<TableHeaderCellProps> = ({ | ||
children, | ||
className, | ||
fz = "sm", | ||
|
||
onSort, | ||
sorted = false, | ||
sortKey, | ||
sortOrder = SortOrder.Asc | ||
|
||
}) => { | ||
|
||
const onTriggerSort = useCallback(() => { | ||
onSort?.(sortKey); | ||
}, [onSort, sortKey]); | ||
|
||
return ( | ||
<Table.Th className={ className } > | ||
{ | ||
onSort ? ( | ||
<UnstyledButton onClick={ onTriggerSort } > | ||
<Group justify="space-between"> | ||
<Text fw="bold" fz={ fz } > | ||
{ children } | ||
</Text> | ||
{ | ||
sorted | ||
? <IconElement size={ 0.7 } path={ sortOrder === SortOrder.Asc ? mdiChevronDown : mdiChevronUp } /> | ||
: <IconElement size={ 0.5 } path={ mdiUnfoldMoreHorizontal } color={ "gray.6" } /> | ||
} | ||
</Group> | ||
</UnstyledButton> | ||
) : ( | ||
<Text fw="bold" fz={ fz } > | ||
{ children } | ||
</Text> | ||
) | ||
} | ||
</Table.Th> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.