Commit 09d32905 authored by Яков's avatar Яков
Browse files

верстка

parent 08d24f68
{
"name": "react-ag-qeditor",
"version": "1.1.47",
"version": "1.1.48",
"description": "WYSIWYG html editor",
"author": "atma",
"license": "MIT",
......
......@@ -51,42 +51,10 @@ import IframeModal from './modals/IframeModal'
import IframeCustomModal from './modals/IframeCustomModal'
import { isMobile } from 'react-device-detect'
import { ExportPdf } from './extensions/ExportPdf'
import { mergeAttributes, Extension } from "@tiptap/core";
import { mergeAttributes } from "@tiptap/core";
import Upload from "rc-upload";
import { NodeSelection } from 'prosemirror-state'
// Выход из code block по Enter на пустой последней строке
const ExitCodeBlock = Extension.create({
name: 'exitCodeBlock',
addKeyboardShortcuts() {
return {
Enter: ({ editor }) => {
if (!editor.isActive('codeBlock')) return false
const { $anchor } = editor.state.selection
if (!editor.state.selection.empty) return false
const nodeText = $anchor.parent.textContent
const offset = $anchor.parentOffset
// Если курсор на последней строке и она пустая — выходим из блока
const lastNewline = nodeText.lastIndexOf('\n', offset - 1)
const currentLine = nodeText.slice(lastNewline + 1, offset)
if (currentLine === '') {
// Удаляем пустую строку и создаём параграф после блока
return editor
.chain()
.command(({ tr, state }) => {
const from = $anchor.pos - 1
tr.delete(from, $anchor.pos)
return true
})
.exitCode()
.run()
}
return false
}
}
}
})
// const CustomImage = Image.extend({
// options: {inline: true},
// // addNodeView() {
......@@ -496,7 +464,25 @@ const QEditor = ({
},
codeBlock: {
title: 'Код',
onClick: () => editor.chain().focus().toggleCodeBlock().run()
onClick: () => {
const { empty, from, to } = editor.state.selection
if (!empty) {
// Есть выделение — применяем только к нему
editor.chain().focus().toggleCode().run()
} else {
// Нет выделения — выделяем весь текущий блок
const { $anchor } = editor.state.selection
const blockStart = $anchor.start()
const blockEnd = $anchor.end()
editor
.chain()
.focus()
.setTextSelection({ from: blockStart, to: blockEnd })
.toggleCode()
.setTextSelection(from) // возвращаем курсор на место
.run()
}
}
},
clearMarks: {
title: 'Очистить форматирование',
......@@ -705,7 +691,6 @@ const QEditor = ({
const editor = useEditor({
extensions: [
StarterKit,
ExitCodeBlock,
Underline,
ImageResize,
Link.configure({
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment