import { css } from '@emotion/css';
import { Menu } from 'antd';
import React from 'react';
import { IconBtn } from '../docs/plugins/Components';
import { setVerticalAlign } from '../docs/plugins/HoveringToolbar';
import { min } from '../docs/plugins/siderMenu';
import { opsTable } from '../docs/plugins/table/tableOperation';
import { ReactEditor, useSlate } from '../slate-packages/slate-react';
import { Editor, Node, Range, Transforms } from '@src/components/slate-packages/slate';
import { f } from '@src/resource/string';
const tableMenu = (thisPath: any, setVisible) => (
<>
>
);
const TableOpsMenu: React.FC = (props: any) => {
const { ops, icon, text, format, path, valign, setVisible, ...attributes } = props;
const editor = useSlate();
let selection = path;
if (
editor.selection &&
ReactEditor.hasRange(editor, selection) &&
selection &&
ReactEditor.hasRange(editor, selection) &&
editor.selection.focus.path[0] === selection[0]
) {
selection = editor.selection;
}
if (ops === 'setVerticalAlign') {
return (
{
setVerticalAlign(editor, valign, selection);
setVisible(false);
}}
>
{text}
);
}
return (
}
style={{
color: ops === 'deleteTable' ? 'rgb(245, 74, 69)' : null,
}}
onMouseDown={(event: any) => {
if (
selection &&
ReactEditor.hasRange(editor, selection) &&
((selection.anchor && min(selection.anchor.path[0], selection.focus.path[0]) !== 0) || (!selection.anchor && selection[0] !== 0))
) {
opsTable(editor, ops, selection);
} else {
if (
selection &&
ReactEditor.hasRange(editor, selection) &&
selection.anchor &&
Range.start(selection).path[0] === path[0] &&
Range.end(selection).path[0] === path[0]
) {
if (selection.anchor.path[0] < selection.focus.path[0]) {
let sel = {
anchor: {
path: [selection.anchor.path[0] + 1, selection.anchor.path[1]],
offset: 0,
},
focus: selection.focus,
};
opsTable(editor, ops, sel);
} else {
let sel = {
anchor: selection.anchor,
focus: { path: [selection.focus.path[0] + 1, selection.focus.path[1]], offset: 0 },
};
opsTable(editor, ops, sel);
}
} else if (selection && ReactEditor.hasRange(editor, selection) && !selection.anchor) {
opsTable(editor, ops, selection);
}
}
setVisible(false);
}}
>
{text}
);
};
export default tableMenu;