From d1500ee2eff9790302b2fd35c924df62ac141409 Mon Sep 17 00:00:00 2001 From: cohitre Date: Thu, 8 Aug 2024 11:50:12 -0700 Subject: [PATCH] Polishing TuneMenu arrows --- .../helpers/block-wrappers/TuneMenu.tsx | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/editor-sample/src/documents/blocks/helpers/block-wrappers/TuneMenu.tsx b/packages/editor-sample/src/documents/blocks/helpers/block-wrappers/TuneMenu.tsx index 2b2d7f9..0392018 100644 --- a/packages/editor-sample/src/documents/blocks/helpers/block-wrappers/TuneMenu.tsx +++ b/packages/editor-sample/src/documents/blocks/helpers/block-wrappers/TuneMenu.tsx @@ -4,7 +4,7 @@ import { ArrowDownwardOutlined, ArrowUpwardOutlined, DeleteOutlined } from '@mui import { IconButton, Paper, Stack, Tooltip } from '@mui/material'; import { TEditorBlock } from '../../../editor/core'; -import { resetDocument, useDocument } from '../../../editor/EditorContext'; +import { resetDocument, setSelectedBlockId, useDocument } from '../../../editor/EditorContext'; import { ColumnsContainerProps } from '../../ColumnsContainer/ColumnsContainerPropsSchema'; const STYLE: CSSProperties = { @@ -12,6 +12,7 @@ const STYLE: CSSProperties = { top: 0, left: -52, borderRadius: 64, + padding: 2, }; type Props = { @@ -78,19 +79,20 @@ export default function TuneMenu({ blockId }: Props) { }; const handleMoveClick = (direction: 'up' | 'down') => { - const moveChildrenIds = (childrenIds: string[] | null | undefined) => { - if (!childrenIds) { - return childrenIds; + const moveChildrenIds = (ids: string[] | null | undefined) => { + if (!ids) { + return ids; } - const index = childrenIds.indexOf(blockId); - if (index !== -1) { - if (direction === 'up' && index > 0) { - [childrenIds[index], childrenIds[index - 1]] = [childrenIds[index - 1], childrenIds[index]]; - } else if (direction === 'down' && index < childrenIds.length - 1) { - [childrenIds[index], childrenIds[index + 1]] = [childrenIds[index + 1], childrenIds[index]]; - } + const index = ids.indexOf(blockId); + if (index < 0) { + return ids; + } + const childrenIds = [...ids]; + if (direction === 'up' && index > 0) { + [childrenIds[index], childrenIds[index - 1]] = [childrenIds[index - 1], childrenIds[index]]; + } else if (direction === 'down' && index < childrenIds.length - 1) { + [childrenIds[index], childrenIds[index + 1]] = [childrenIds[index + 1], childrenIds[index]]; } - return childrenIds; }; const nDocument: typeof document = { ...document }; @@ -139,8 +141,9 @@ export default function TuneMenu({ blockId }: Props) { nDocument[id] = block; } } - console.log(nDocument); + resetDocument(nDocument); + setSelectedBlockId(blockId); }; return (