import { WarningOutlined } from '@ant-design/icons'; import React from 'react'; import { IconBtn } from '../../Components'; import { ELTYPE } from '../../config'; import './index.less'; import { alignToggle } from '../../HoveringToolbar'; import { Editor, Node, Range, Transforms } from '@src/components/slate-packages/slate'; import { insertCodeBlock } from '../../CodeBlock'; import storage from '@src/utils/storage'; import { insertOl } from '../../OLULList/OlList'; import { toggleBlock } from '../../block'; import { insertDivide } from '../../Divide'; import { newTable } from '../../table/newTable'; import { getCache } from '@src/utils/cacheUtils'; import { createUUID } from '@src/utils/randomId'; import { f } from '@src/resource/string'; import { getEditorEventEmitter } from '../../table/selection'; import { getSlateSlection } from '@src/utils/getSelection'; import { ReactEditor } from '@src/components/slate-packages/slate-react'; function ListIconItem(props: any) { const { onMouseDown, icon, text } = props; const Icon = icon; const iconStyle: object = { fontSize: '14px', color: 'rgba(0,0,0,.5)', marginRight: '8px', display: 'inline-block', }; console.log('icon', icon); return (
{ onMouseDown && onMouseDown(); }} >
{typeof icon === 'string' ? : }
{text.length === 4 ? {text} : {text}}
); } function execInsertComponent(props: any) { console.log('execInsertComponent', props); const { format, editor, selection, setShowCard } = props; const path = selection?.anchor?.path; if (!path) { setShowCard(false); return; } const { type } = Node.get(editor, path) as any; if (format.startsWith('align')) { const fo = format.split('-')[1]; alignToggle(editor, fo, selection); setShowCard(false); return; } else if (format === ELTYPE.CODE_BLOCK) { console.log('format', format); setShowCard(false); insertCodeBlock(editor, Range.start(selection).path); return; } else if (type !== format && [ELTYPE.OLLIST, ELTYPE.ULLIST].includes(format)) { let id = format + '=' + createUUID(); console.log('execInsertComponent list cur:', type, ',targetType:', format); const employee = storage.get('userInfo')?.employee; insertOl( editor, { type: format, tabLevel: 0, num: 1, id: id, authCls: 'auth-' + employee, elId: createUUID(), }, { at: selection } ); setShowCard(false); return; } if (selection && ReactEditor.hasRange(editor, selection) && selection[0] !== 0) { toggleBlock(editor, format, selection); getEditorEventEmitter(editor.docId).emit('updateOutlineAnchor', editor.docId); } else { if (selection) { toggleBlock(editor, format, selection); getEditorEventEmitter(editor.docId).emit('updateOutlineAnchor', editor.docId); } } setShowCard(false); } export const isInTable = editor => { let ret = null; const sel = getSlateSlection(editor.docId); if (sel) { ret = Editor.above(editor, { match: (n: any) => n.type === ELTYPE.TABLE, at: sel, }); } console.log('isInTable', editor, sel, ret); return ret; }; export default function (props: any) { const { setShowCard, editor, docWidth, docId } = props; const selection = getCache(docId, 'selection'); return (
{ setShowCard(false); }} >
{ e.preventDefault(); e.stopPropagation(); }} >
在下方添加
样式
{ execInsertComponent({ format: ELTYPE.HEADING_ONE, editor, selection, setShowCard, }); }} text="" /> { execInsertComponent({ format: ELTYPE.HEADING_TWO, editor, selection, setShowCard, }); }} text="" /> { execInsertComponent({ format: ELTYPE.HEADING_THREE, editor, selection, setShowCard, }); }} text="" /> { execInsertComponent({ format: ELTYPE.HEADING_FOUR, editor, selection, setShowCard, }); }} text="" /> { execInsertComponent({ format: ELTYPE.HEADING_FIVE, editor, selection, setShowCard, }); }} text="" /> { execInsertComponent({ format: ELTYPE.HEADING_SIX, editor, selection, setShowCard, }); }} text="" />
 
{ execInsertComponent({ format: ELTYPE.PARAGRAPH, editor, selection, setShowCard, }); }} text={f('normal')} /> { execInsertComponent({ format: ELTYPE.OLLIST, editor, selection, setShowCard, }); }} text={f('numberedList')} /> { execInsertComponent({ format: ELTYPE.ULLIST, editor, selection, setShowCard, }); }} text={f('bulletedList')} /> { execInsertComponent({ format: ELTYPE.TODO_LIST, editor, selection, setShowCard, }); }} text={f('toDoList')} /> { execInsertComponent({ format: ELTYPE.CODE_BLOCK, editor, selection, setShowCard, }); }} text={f('codeBlock')} /> { execInsertComponent({ format: ELTYPE.BLOCK_QUOTE, editor, selection, setShowCard, }); }} text={f('quote')} />
{f('common')}
{!isInTable(editor) && ( { newTable(editor, 2, 2, docWidth - 15, selection.anchor.path.slice(0, 1)); setShowCard(false); }} text={f('table')} /> )} { insertDivide(editor); setShowCard(false); }} text={f('divider')} />
); }