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 ? ( ) : showColorPopup ? ( ) : (
} callback={() => { setCache(docId, 'isShowMobileMenuPopup', true); ReactEditor.blur(editor); setTimeout(() => { setShowCardPopup(true); }, 300); }} /> } callback={() => {}} /> } callback={() => { setCache(docId, 'isShowMobileMenuPopup', true); ReactEditor.blur(editor); setTimeout(() => { setShowColorPopup(true); }, 300); }} /> } callback={() => {}} /> } callback={e => { toggleBlock(editor, ELTYPE.TODO_LIST, editor.selection); }} /> {} {}
} callback={e => { e.preventDefault(); ReactEditor.blur(editor); const dom = document.getElementById('editor-content-' + docId); if (dom && dom.firstChild) { const input = dom.firstChild; input?.blur(); } }} />
); } function MobileToolbarButton(props: any) { const { icon, type, editor, callback } = props; const popoverContent = { format: (
} /> } /> } /> } /> } />
), align: (
} /> } /> } />
), }; const activableTypes = ['todo-list']; let active; if (activableTypes.includes(type)) { active = editor && isBlockActive(editor, type, editor.selection); } return (
{ e.preventDefault(); callback && callback(e); }} onPointerMove={e => { e.preventDefault(); }} > { if (visible && type === 'align') { const aligns = ['align-left', 'align-center', 'align-right']; const activeAlignFormat = aligns.find(align => isAlignActive(editor, align, editor.selection)); editor?.docId && getEditorEventEmitter(editor.docId).emit('mobileAlignButtonClick', editor.docId, activeAlignFormat); } }} trigger={['click']} overlayClassName={css` & { border-radius: 4px; .ant-popover-arrow { display: none; } .ant-popover-inner { border-radius: 4px; .ant-popover-inner-content { padding: 0; } } } `} > {icon}
); } function VerticalDivider() { return ( ); } function InlineButton({ button }) { return (
{ e.preventDefault(); }} > {button}
); }