* Removed view field duplicate types * wip * wip 2 * wip 3 * Unified state for fields * Renaming * Wip * Post merge * Post post merge * wip * Delete unused file * Boolean and Probability * Finished InlineCell * Renamed EditableCell to TableCell * Finished double texts * Finished MoneyField * Fixed bug inline cell click outside * Fixed hotkey scope * Final fixes * Phone * Fix url and number input validation * Fix * Fix position * wip refactor activity editor * Fixed activity editor --------- Co-authored-by: Charles Bochet <charles@twenty.com>
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { useCurrentTableCellEditMode } from '../editable-cell/hooks/useCurrentTableCellEditMode';
|
|
import { useTableCell } from '../editable-cell/hooks/useTableCell';
|
|
|
|
import { useMoveSoftFocus } from './useMoveSoftFocus';
|
|
|
|
export const useCellInputEventHandlers = <T>({
|
|
onSubmit,
|
|
onCancel,
|
|
}: {
|
|
onSubmit?: (newValue: T) => void;
|
|
onCancel?: () => void;
|
|
}) => {
|
|
const { closeTableCell: closeEditableCell } = useTableCell();
|
|
const { isCurrentTableCellInEditMode: isCurrentCellInEditMode } =
|
|
useCurrentTableCellEditMode();
|
|
const { moveRight, moveLeft, moveDown } = useMoveSoftFocus();
|
|
|
|
return {
|
|
handleClickOutside: (event: MouseEvent | TouchEvent, newValue: T) => {
|
|
if (isCurrentCellInEditMode) {
|
|
event.stopImmediatePropagation();
|
|
|
|
onSubmit?.(newValue);
|
|
|
|
closeEditableCell();
|
|
}
|
|
},
|
|
handleEscape: () => {
|
|
closeEditableCell();
|
|
onCancel?.();
|
|
},
|
|
handleEnter: (newValue: T) => {
|
|
onSubmit?.(newValue);
|
|
closeEditableCell();
|
|
moveDown();
|
|
},
|
|
handleTab: (newValue: T) => {
|
|
onSubmit?.(newValue);
|
|
closeEditableCell();
|
|
moveRight();
|
|
},
|
|
handleShiftTab: (newValue: T) => {
|
|
onSubmit?.(newValue);
|
|
closeEditableCell();
|
|
moveLeft();
|
|
},
|
|
};
|
|
};
|