Persist table cell values on cell close (#655)

* Persist table cell values on cell close

* Apply to all cells
This commit is contained in:
Charles Bochet
2023-07-13 21:20:08 -07:00
committed by GitHub
parent ca1723f2e6
commit 551c3b5e60
20 changed files with 260 additions and 133 deletions

View File

@ -1,13 +1,9 @@
import { ReactElement, useRef } from 'react';
import styled from '@emotion/styled';
import { useScopedHotkeys } from '@/hotkeys/hooks/useScopedHotkeys';
import { InternalHotkeysScope } from '@/hotkeys/types/internal/InternalHotkeysScope';
import { useListenClickOutsideArrayOfRef } from '@/ui/hooks/useListenClickOutsideArrayOfRef';
import { useMoveSoftFocus } from '@/ui/tables/hooks/useMoveSoftFocus';
import { overlayBackground } from '@/ui/themes/effects';
import { useEditableCell } from './hooks/useEditableCell';
import { useRegisterCloseCellHandlers } from './hooks/useRegisterCloseCellHandlers';
export const EditableCellEditModeContainer = styled.div<OwnProps>`
align-items: center;
@ -33,60 +29,20 @@ type OwnProps = {
editModeHorizontalAlign?: 'left' | 'right';
editModeVerticalPosition?: 'over' | 'below';
onOutsideClick?: () => void;
onCancel?: () => void;
onSubmit?: () => void;
};
export function EditableCellEditMode({
editModeHorizontalAlign,
editModeVerticalPosition,
children,
onCancel,
onSubmit,
}: OwnProps) {
const wrapperRef = useRef(null);
const { closeEditableCell } = useEditableCell();
const { moveRight, moveLeft, moveDown } = useMoveSoftFocus();
useListenClickOutsideArrayOfRef([wrapperRef], () => {
closeEditableCell();
});
useScopedHotkeys(
'enter',
() => {
closeEditableCell();
moveDown();
},
InternalHotkeysScope.CellEditMode,
[closeEditableCell],
);
useScopedHotkeys(
'esc',
() => {
closeEditableCell();
},
InternalHotkeysScope.CellEditMode,
[closeEditableCell],
);
useScopedHotkeys(
'tab',
() => {
closeEditableCell();
moveRight();
},
InternalHotkeysScope.CellEditMode,
[closeEditableCell, moveRight],
);
useScopedHotkeys(
'shift+tab',
() => {
closeEditableCell();
moveLeft();
},
InternalHotkeysScope.CellEditMode,
[closeEditableCell, moveRight],
);
useRegisterCloseCellHandlers(wrapperRef, onSubmit, onCancel);
return (
<EditableCellEditModeContainer