|
@@ -1,11 +1,8 @@
|
|
|
import { CellIdentifier } from '$app/stores/effects/database/cell/cell_bd_svc';
|
|
|
-import { CellCache } from '$app/stores/effects/database/cell/cell_cache';
|
|
|
-import { FieldController } from '$app/stores/effects/database/field/field_controller';
|
|
|
import { KeyboardEventHandler, useEffect, useRef, useState } from 'react';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
-import { SelectOptionCellDataPB, SelectOptionColorPB, SelectOptionPB } from '@/services/backend';
|
|
|
+import { SelectOptionColorPB, SelectOptionPB } from '@/services/backend';
|
|
|
import { getBgColor } from '$app/components/_shared/getColor';
|
|
|
-import { CloseSvg } from '$app/components/_shared/svg/CloseSvg';
|
|
|
import { SelectOptionCellBackendService } from '$app/stores/effects/database/cell/select_option_bd_svc';
|
|
|
import useOutsideClick from '$app/components/_shared/useOutsideClick';
|
|
|
import { TrashSvg } from '$app/components/_shared/svg/TrashSvg';
|
|
@@ -16,36 +13,39 @@ export const EditCellOptionPopup = ({
|
|
|
top,
|
|
|
cellIdentifier,
|
|
|
editingSelectOption,
|
|
|
- cellCache,
|
|
|
- fieldController,
|
|
|
onOutsideClick,
|
|
|
}: {
|
|
|
left: number;
|
|
|
top: number;
|
|
|
cellIdentifier: CellIdentifier;
|
|
|
editingSelectOption: SelectOptionPB;
|
|
|
- cellCache: CellCache;
|
|
|
- fieldController: FieldController;
|
|
|
onOutsideClick: () => void;
|
|
|
}) => {
|
|
|
const ref = useRef<HTMLDivElement>(null);
|
|
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
|
const { t } = useTranslation('');
|
|
|
const [adjustedTop, setAdjustedTop] = useState(-100);
|
|
|
+ const [adjustedLeft, setAdjustedLeft] = useState(-100);
|
|
|
const [value, setValue] = useState('');
|
|
|
|
|
|
useOutsideClick(ref, async () => {
|
|
|
+ await onBlur();
|
|
|
onOutsideClick();
|
|
|
});
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (!ref.current) return;
|
|
|
- const { height } = ref.current.getBoundingClientRect();
|
|
|
+ const { height, width } = ref.current.getBoundingClientRect();
|
|
|
if (top + height > window.innerHeight) {
|
|
|
setAdjustedTop(window.innerHeight - height);
|
|
|
} else {
|
|
|
setAdjustedTop(top);
|
|
|
}
|
|
|
+ if (left + width > window.innerWidth) {
|
|
|
+ setAdjustedLeft(window.innerWidth - width);
|
|
|
+ } else {
|
|
|
+ setAdjustedLeft(left);
|
|
|
+ }
|
|
|
}, [ref, window, top, left]);
|
|
|
|
|
|
useEffect(() => {
|
|
@@ -97,9 +97,9 @@ export const EditCellOptionPopup = ({
|
|
|
ref={ref}
|
|
|
onKeyDown={onKeyDownWrapper}
|
|
|
className={`fixed z-10 rounded-lg bg-white px-2 py-2 text-xs shadow-md transition-opacity duration-300 ${
|
|
|
- adjustedTop === -100 ? 'opacity-0' : 'opacity-100'
|
|
|
+ adjustedTop === -100 && adjustedLeft === -100 ? 'opacity-0' : 'opacity-100'
|
|
|
}`}
|
|
|
- style={{ top: `${adjustedTop}px`, left: `${left}px` }}
|
|
|
+ style={{ top: `${adjustedTop}px`, left: `${adjustedLeft}px` }}
|
|
|
>
|
|
|
<div className={'flex flex-col gap-2 p-2'}>
|
|
|
<div className={'border-shades-3 flex flex-1 items-center gap-2 rounded border bg-main-selector px-2 '}>
|