Skip to content

Commit d1500ee

Browse files
committed
Polishing TuneMenu arrows
1 parent 029ca67 commit d1500ee

File tree

1 file changed

+16
-13
lines changed
  • packages/editor-sample/src/documents/blocks/helpers/block-wrappers

1 file changed

+16
-13
lines changed

packages/editor-sample/src/documents/blocks/helpers/block-wrappers/TuneMenu.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { ArrowDownwardOutlined, ArrowUpwardOutlined, DeleteOutlined } from '@mui
44
import { IconButton, Paper, Stack, Tooltip } from '@mui/material';
55

66
import { TEditorBlock } from '../../../editor/core';
7-
import { resetDocument, useDocument } from '../../../editor/EditorContext';
7+
import { resetDocument, setSelectedBlockId, useDocument } from '../../../editor/EditorContext';
88
import { ColumnsContainerProps } from '../../ColumnsContainer/ColumnsContainerPropsSchema';
99

1010
const STYLE: CSSProperties = {
1111
position: 'absolute',
1212
top: 0,
1313
left: -52,
1414
borderRadius: 64,
15+
padding: 2,
1516
};
1617

1718
type Props = {
@@ -78,19 +79,20 @@ export default function TuneMenu({ blockId }: Props) {
7879
};
7980

8081
const handleMoveClick = (direction: 'up' | 'down') => {
81-
const moveChildrenIds = (childrenIds: string[] | null | undefined) => {
82-
if (!childrenIds) {
83-
return childrenIds;
82+
const moveChildrenIds = (ids: string[] | null | undefined) => {
83+
if (!ids) {
84+
return ids;
8485
}
85-
const index = childrenIds.indexOf(blockId);
86-
if (index !== -1) {
87-
if (direction === 'up' && index > 0) {
88-
[childrenIds[index], childrenIds[index - 1]] = [childrenIds[index - 1], childrenIds[index]];
89-
} else if (direction === 'down' && index < childrenIds.length - 1) {
90-
[childrenIds[index], childrenIds[index + 1]] = [childrenIds[index + 1], childrenIds[index]];
91-
}
86+
const index = ids.indexOf(blockId);
87+
if (index < 0) {
88+
return ids;
89+
}
90+
const childrenIds = [...ids];
91+
if (direction === 'up' && index > 0) {
92+
[childrenIds[index], childrenIds[index - 1]] = [childrenIds[index - 1], childrenIds[index]];
93+
} else if (direction === 'down' && index < childrenIds.length - 1) {
94+
[childrenIds[index], childrenIds[index + 1]] = [childrenIds[index + 1], childrenIds[index]];
9295
}
93-
9496
return childrenIds;
9597
};
9698
const nDocument: typeof document = { ...document };
@@ -139,8 +141,9 @@ export default function TuneMenu({ blockId }: Props) {
139141
nDocument[id] = block;
140142
}
141143
}
142-
console.log(nDocument);
144+
143145
resetDocument(nDocument);
146+
setSelectedBlockId(blockId);
144147
};
145148

146149
return (

0 commit comments

Comments
 (0)