Код: Выделить всё
...
export const ToggleBlock = (editor: CustomEditor, format: CustomElementFormat) => {
...
let newProperties: Partial
if (isAlignType(format)) {
newProperties = {
align: isActive ? undefined : format,
}
} else {
newProperties = {
type: isActive ? "paragraph" : isList ? "list-item" : format,
} as Element
}
Transforms.setNodes(editor, newProperties)
...
}
export const renderElement = ({attributes, element, children}: RenderElementProps) => {
const style: React.CSSProperties = {}
console.log(`element type ${element.type}`)
if (isAlignElement(element)) {
style.textAlign = element.align as AlignType;
}
switch (element.type) {
case 'heading-one': {
console.log(`h1 ${children}`)
return (
{children}
);
}
case 'heading-two': {
console.log("h2")
return (
{children}
);
}
case 'heading-three': {
console.log("h3")
return (
{children}
);
}
case 'heading-four': {
console.log("h4")
return (
[h4]{children}[/h4]
);
}
case 'quote': {
console.log("quote")
return (
{children}
);
}
case 'list-item': {
console.log("list-item")
return (
[*]{children}
);
}
case 'bulleted-list': {
console.log("bulleted-list")
return (
[list]{children}[/list]
);
}
case 'numbered-list': {
console.log("numbered-list")
return (
[list]{children}[/list]
);
}
default: {
console.log("paragraph")
return (
{children}
);
}
}
}
...
Код: Выделить всё
...
export const BlockButton = ({ format, Icon }: BlockButtonProps) => {
const editor = useSlate();
return (
{
event.preventDefault();
}}
onClick={() => ToggleBlock(editor, format)} // Calling ToggleBlock
/>
)
}
...
Код: Выделить всё
...
function App() {
...
return (
Editor
...
keyHandler(event)}
/>
)
}
export default App
Подробнее здесь: https://stackoverflow.com/questions/797 ... te-js-edit
Мобильная версия