import {
AlignLeftOutlined,
CalendarOutlined,
CaretDownOutlined,
CheckSquareOutlined,
FontColorsOutlined,
FontSizeOutlined,
KeyOutlined,
PictureOutlined,
PlusCircleOutlined,
} from '@ant-design/icons';
import { css, cx } from '@emotion/css';
import { Transforms, Node } from '@src/components/slate-packages/slate';
import { ReactEditor } from '@src/components/slate-packages/slate-react';
import { IS_IOS } from '@src/components/slate-packages/slate-react/utils/environment';
import { TripdocsSdkContext } from '@src/Docs';
import useVisualViewport from '@src/utils/apiOperations/hooks/useVisualViewport';
import { getCache, setCache } from '@src/utils/cacheUtils';
import storage from '@src/utils/storage';
import { Drawer, Popover } from 'antd';
import React, { useEffect, useRef, useState } from 'react';
import ReactDOM from 'react-dom';
import { isBlockActive, toggleBlock } from '../block';
import { COLOR_ACTIVE } from '../Components';
import { ELTYPE } from '../config';
import { AlignButton, isAlignActive, MarkButton } from '../HoveringToolbar';
import { getEditorEventEmitter } from '../table/selection';
import CardPopup from './CardPopup';
import ColorPopup from './ColorPopup';
export const BodyPortal = ({ children }) => {
return ReactDOM.createPortal(children, document.body);
};
export function MobileToolbar(props) {
const { editor, docWidth, modalState, currentColor, setCurrentColor, anchorTrigger, display } = props;
const [showCardPopup, setShowCardPopup] = useState(false);
const [showColorPopup, setShowColorPopup] = useState(false);
const { isReadOnly, docId } = React.useContext(TripdocsSdkContext);
const [theme, setTheme] = useState({ backgroundColor: '#fff', color: 'rgba(0, 0, 0, 0.85)' });
const clientHeight = window.document.body.clientHeight;
const viewport = useVisualViewport();
useEffect(() => {
const editorDom = document.getElementById(`editorarea-${docId}`);
const selection = getCache(docId, 'selection');
if (!editor) {
return;
}
if (showColorPopup || showCardPopup) {
if (!selection) {
return;
}
editorDom && (editorDom.style.padding = '10px 15px 100vh');
const node = Node.has(editor, selection.anchor.path) && Node.get(editor, selection.anchor.path);
if (node) {
const domNode = ReactEditor.toDOMNode(editor, node);
domNode.style.scrollMarginTop = `20vh`;
domNode && domNode.scrollIntoView(true);
}
setTimeout(() => ReactEditor.blur(editor));
} else {
if (selection) {
editorDom.focus();
Transforms.select(editor, selection);
}
setCache(docId, 'isShowMobileMenuPopup', false);
editorDom && (editorDom.style.padding = '10px 15px 160px');
}
}, [showCardPopup, showColorPopup]);
const isInElectron: boolean = getCache(docId, 'options')?.isInElectron;
const safeAreaBottom: number = getCache(docId, 'options')?.safeAreaBottom;
const [isViewport, setIsViewport] = useState(IS_IOS && !isInElectron);
const keyboardHeight = clientHeight - viewport.height;
return showCardPopup ? (