function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _array_without_holes(arr) {
    if (Array.isArray(arr)) return _array_like_to_array(arr);
}
function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _iterable_to_array(iter) {
    if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _non_iterable_spread() {
    throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _to_consumable_array(arr) {
    return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import { Editor, Node, Path, Range, Transforms } from "slate";
import { ReactEditor } from "slate-react";
export var inlineNode = new Set([
    'break',
    'inline-katex'
]);
var voidNode = new Set([
    'hr',
    'break'
]);
function hasRange(editor, range) {
    var anchor = range.anchor, focus = range.focus;
    return Editor.hasPath(editor, anchor.path) && Editor.hasPath(editor, focus.path);
}
/**
 * 清空卡片区域的文本内容 - 使用零宽字符替换
 * @param editor - Slate编辑器实例
 * @param path - 要清空的节点路径
 */ var clearCardAreaText = function(editor, path) {
    try {
        var node = Node.get(editor, path);
        if (node) {
            // 尝试直接DOM操作，设置为零宽字符
            try {
                var domNode = ReactEditor.toDOMNode(editor, node);
                if (domNode) {
                    var zeroWidthNode = domNode === null || domNode === void 0 ? void 0 : domNode.querySelector('[data-slate-zero-width]');
                    if (zeroWidthNode) {
                        zeroWidthNode.textContent = '\uFEFF';
                    }
                }
            } catch (domError) {
            // DOM operation failed, falling back to Slate transforms
            }
        }
    } catch (error) {
    // 如果操作失败，忽略错误
    }
};
/**
 * 检查卡片是否为空
 * @param cardNode - 卡片节点
 * @returns 如果卡片为空则返回true
 */ var isCardEmpty = function(cardNode) {
    if (!cardNode || cardNode.type !== 'card' || !cardNode.children) {
        return false;
    }
    // 查找实际内容节点（非card-before和card-after的节点）
    var contentNodes = cardNode.children.filter(function(child) {
        return child.type !== 'card-before' && child.type !== 'card-after';
    });
    // 如果没有内容节点，则为空
    if (contentNodes.length === 0) {
        return true;
    }
    // 检查内容节点是否为空
    return contentNodes.every(function(node) {
        if (!node.children || node.children.length === 0) {
            return true;
        }
        // 检查是否只包含空文本
        return node.children.every(function(child) {
            return child.text === '' || child.text && child.text.trim() === '';
        });
    });
};
/**
 * 处理卡片相关节点的操作
 *
 * @param editor - Slate编辑器实例
 * @param operation - 要处理的操作
 * @param apply - 原始的apply函数
 * @returns 如果操作被处理则返回true，否则返回false
 *
 * @description
 * 处理以下卡片相关操作:
 * - 删除卡片节点 (remove_node)，包括card、card-before和card-after
 * - 在卡片后插入文本 (insert_text)
 * - 在卡片内插入节点 (insert_node)
 * - 检查并删除空卡片
 */ var handleCardOperation = function(editor, operation, apply) {
    if (operation.type === 'remove_node') {
        var node = operation.node;
        // 删除card时，直接删除整个卡片
        if (node.type === 'card') {
            // 直接执行原始操作，避免递归
            apply(operation);
            return true;
        }
        // 删除card-after时，删除整个卡片
        if (node.type === 'card-after') {
            Transforms.removeNodes(editor, {
                at: Path.parent(operation.path)
            });
            return true;
        }
        // 删除card-before时，阻止操作
        if (node.type === 'card-before') {
            return true;
        }
        // 检查操作后的父级是否为空卡片，如果是则删除
        if (operation.path && operation.path.length > 0) {
            try {
                var parentPath = Path.parent(operation.path);
                var parentNode = Node.get(editor, parentPath);
                if (parentNode && parentNode.type === 'card' && isCardEmpty(parentNode)) {
                    Transforms.removeNodes(editor, {
                        at: parentPath
                    });
                    return true;
                }
            } catch (error) {
            // 如果无法获取父节点，忽略错误
            }
        }
    }
    if (operation.type === 'insert_text') {
        try {
            var parentNode1 = Node.get(editor, Path.parent(operation.path));
            // card-before 不允许任何文本输入
            if (parentNode1.type === 'card-before') {
                return true; // 阻止输入
            }
            // card-after 的输入会插入到卡片后面的新段落中
            if (parentNode1.type === 'card-after') {
                try {
                    var grandParentPath = Path.parent(Path.parent(operation.path));
                    var grandParentNode = Node.get(editor, grandParentPath);
                    if (grandParentNode.type === 'card') {
                        // 使用 Editor.withoutNormalizing 确保操作的原子性
                        Editor.withoutNormalizing(editor, function() {
                            // 先创建新段落
                            Transforms.insertNodes(editor, {
                                type: 'paragraph',
                                children: [
                                    {
                                        text: operation.text
                                    }
                                ]
                            }, {
                                at: Path.next(grandParentPath)
                            });
                            // 然后选中新创建的段落
                            var newParagraphPath = Path.next(grandParentPath);
                            var textPath = _to_consumable_array(newParagraphPath).concat([
                                0
                            ]);
                            Transforms.select(editor, {
                                anchor: {
                                    path: textPath,
                                    offset: operation.text.length
                                },
                                focus: {
                                    path: textPath,
                                    offset: operation.text.length
                                }
                            });
                            clearCardAreaText(editor, operation.path);
                        });
                        return true;
                    }
                } catch (error) {
                // 如果获取父级节点失败，继续阻止输入
                }
                return true;
            }
        } catch (error) {
        // 如果无法获取父节点，允许操作继续
        }
    }
    if (operation.type === 'insert_node') {
        var parentNode2 = Node.get(editor, Path.parent(operation.path));
        // card-before 不允许任何节点插入
        if (parentNode2.type === 'card-before') {
            return true; // 阻止插入
        }
        // card-after 的节点插入会放到卡片后面
        if (parentNode2.type === 'card-after') {
            if (Node.get(editor, Path.parent(Path.parent(operation.path))).type === 'card') {
                var cardPath = Path.parent(Path.parent(operation.path));
                Transforms.insertNodes(editor, operation.node, {
                    at: Path.next(cardPath)
                });
                return true;
            }
            Transforms.insertNodes(editor, operation.node, {
                at: Path.parent(operation.path)
            });
            return true;
        }
    }
    // 对于删除文本操作，我们需要在操作执行后检查卡片是否变空
    // 这将在 editor.apply 的最后处理
    return false;
};
/**
 * 处理链接卡片和媒体相关节点的操作
 *
 * @param editor - Slate编辑器实例
 * @param operation - 要处理的操作
 * @param apply - 原始的apply函数
 * @returns 如果操作被处理则返回true，否则返回false
 *
 * @description
 * 处理以下链接和媒体相关操作:
 * - 拆分链接卡片或媒体节点 (split_node)
 * - 删除链接卡片内的节点 (remove_node)
 */ var handleLinkAndMediaOperation = function(editor, operation) {
    var _operation_properties, _operation_properties1;
    if (operation.type === 'split_node' && (((_operation_properties = operation.properties) === null || _operation_properties === void 0 ? void 0 : _operation_properties.type) === 'link-card' || ((_operation_properties1 = operation.properties) === null || _operation_properties1 === void 0 ? void 0 : _operation_properties1.type) === 'media')) {
        var node = Node.get(editor, operation.path);
        if ([
            'link-card',
            'media'
        ].includes(node === null || node === void 0 ? void 0 : node.type)) {
            Transforms.insertNodes(editor, [
                {
                    type: 'paragraph',
                    children: [
                        {
                            text: '',
                            p: 'true'
                        }
                    ]
                }
            ], {
                at: Path.next([
                    operation.path.at(0)
                ]),
                select: true
            });
        }
        return true;
    }
    if (operation.type === 'remove_node') {
        var parentNode = Node.get(editor, Path.parent(operation.path));
        if ('link-card' === parentNode.type) {
            Transforms.removeNodes(editor, {
                at: Path.parent(operation.path)
            });
            return true;
        }
    }
    return false;
};
/**
 * 处理schema相关节点的操作
 *
 * @param editor - Slate编辑器实例
 * @param operation - 要处理的操作
 * @param apply - 原始的apply函数
 * @returns 如果操作被处理则返回true，否则返回false
 *
 * @description
 * 处理以下schema相关操作:
 * - 拆分schema节点 (split_node)，在拆分点之后插入新的段落节点
 */ var handleSchemaOperation = function(editor, operation) {
    var _operation_properties;
    if (operation.type === 'split_node' && ((_operation_properties = operation.properties) === null || _operation_properties === void 0 ? void 0 : _operation_properties.type) === 'schema') {
        var node = Node.get(editor, operation.path);
        if ((node === null || node === void 0 ? void 0 : node.type) === 'schema') {
            Transforms.insertNodes(editor, [
                {
                    type: 'paragraph',
                    children: [
                        {
                            text: '',
                            p: 'true'
                        }
                    ]
                }
            ], {
                at: Path.next(operation.path),
                select: true
            });
        }
        return true;
    }
    return false;
};
/**
 * 处理代码和标签相关节点的操作
 *
 * @param editor - Slate编辑器实例
 * @param operation - 要处理的操作
 * @param apply - 原始的apply函数
 * @returns 如果操作被处理则返回true，否则返回false
 *
 * @description
 * 处理以下代码和标签相关操作:
 * - 删除文本 (remove_text)，处理特殊触发文本和空标签
 * - 删除节点 (remove_node)，处理代码块周围的空格
 * - 插入文本 (insert_text)，处理代码块中的空格插入
 */ var handleCodeTagOperation = function(editor, operation, apply) {
    if (operation.type === 'remove_text') {
        var currentNode = Node.get(editor, operation.path);
        if (currentNode === null || currentNode === void 0 ? void 0 : currentNode.tag) {
            var _currentNode_text;
            // 处理空标签的删除
            if (((_currentNode_text = currentNode.text) === null || _currentNode_text === void 0 ? void 0 : _currentNode_text.trim()) === '') {
                Editor.withoutNormalizing(editor, function() {
                    Transforms.setNodes(editor, {
                        tag: false,
                        code: false,
                        text: ' ',
                        triggerText: undefined
                    }, {
                        at: operation.path
                    });
                });
                return true;
            }
            if (currentNode.text === operation.text) {
                Editor.withoutNormalizing(editor, function() {
                    Transforms.removeNodes(editor, {
                        at: operation.path
                    });
                    Transforms.insertNodes(editor, _object_spread_props(_object_spread({}, currentNode), {
                        tag: true,
                        code: true,
                        text: ' '
                    }), {
                        at: operation.path,
                        select: true
                    });
                });
                return true;
            }
            // 光标在 tag 内部，执行原始的删除操作
            apply(operation);
            return true;
        }
    }
    if (operation.type === 'insert_text') {
        var _editor_selection;
        var currentNode1 = Node.get(editor, operation.path);
        if ((currentNode1 === null || currentNode1 === void 0 ? void 0 : currentNode1.tag) && operation.text === ' ' && ((_editor_selection = editor.selection) === null || _editor_selection === void 0 ? void 0 : _editor_selection.focus.offset) === currentNode1.text.length) {
            // 检查前一个字符是否是空格
            var lastChar = currentNode1.text.charAt(currentNode1.text.length - 1);
            if (lastChar === ' ') {
                // 如果前一个输入是空格，且当前输入也是空格，则插入一个空格到 tag 节点外
                Transforms.insertNodes(editor, [
                    {
                        text: ' '
                    }
                ]);
                return true;
            }
        }
        if ((currentNode1 === null || currentNode1 === void 0 ? void 0 : currentNode1.tag) && operation.text.trim().length > 0 && currentNode1.text.trim().length === 0) {
            Editor.withoutNormalizing(editor, function() {
                Transforms.removeNodes(editor, {
                    at: operation.path
                });
                Transforms.insertNodes(editor, _object_spread_props(_object_spread({}, currentNode1), {
                    tag: true,
                    code: true,
                    text: operation.text
                }), {
                    at: operation.path,
                    select: true
                });
            });
            return true;
        }
    }
    if (operation.type === 'split_node') {
        var node = Node.get(editor, operation.path);
        if ((node === null || node === void 0 ? void 0 : node.tag) || (node === null || node === void 0 ? void 0 : node.code)) {
            return true;
        }
    }
    return false;
};
// 将所有处理函数放入数组
var operationHandlers = [
    handleCardOperation,
    handleLinkAndMediaOperation,
    handleSchemaOperation,
    handleCodeTagOperation
];
/**
 * 为Slate编辑器添加Markdown支持的插件函数
 *
 * @param editor - 要扩展的Slate编辑器实例
 * @returns 增强后的编辑器实例，具有Markdown处理能力
 *
 * @description
 * 该插件通过扩展编辑器的基本功能，使其能够处理和渲染Markdown内容：
 * - 扩展`isInline`方法，识别特定的行内元素
 * - 扩展`isVoid`方法，识别特定的空元素
 * - 重写`apply`方法，添加自定义操作处理逻辑
 * - 重写`deleteBackward`方法，处理特殊节点的删除行为
 *
 * 自定义操作处理流程：
 * 1. 按顺序尝试所有专用处理函数（表格、卡片、链接、Schema等）
 * 2. 如果任一处理函数返回true，则操作被消费
 * 3. 否则，调用原始的apply方法处理操作
 */ export var withMarkdown = function(editor) {
    var isInline = editor.isInline, isVoid = editor.isVoid, apply = editor.apply, deleteBackward = editor.deleteBackward, insertText = editor.insertText, insertFragment = editor.insertFragment;
    editor.isInline = function(element) {
        return inlineNode.has(element.type) || isInline(element);
    };
    editor.isVoid = function(element) {
        return voidNode.has(element.type) || isVoid(element);
    };
    editor.apply = function(operation) {
        var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
        try {
            // 依次尝试每个处理函数
            for(var _iterator = operationHandlers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                var handler = _step.value;
                if (handler(editor, operation, apply)) {
                    return;
                }
            }
        } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion && _iterator.return != null) {
                    _iterator.return();
                }
            } finally{
                if (_didIteratorError) {
                    throw _iteratorError;
                }
            }
        }
        // 记录操作前可能涉及的卡片路径，用于操作后检查
        var cardPathsToCheck = [];
        if (operation.type === 'remove_text' || operation.type === 'insert_text') {
            if (operation.path && operation.path.length > 0) {
                try {
                    // 向上查找是否在卡片内
                    var currentPath = operation.path;
                    while(currentPath.length > 0){
                        var node = Node.get(editor, currentPath);
                        if (node && node.type === 'card') {
                            cardPathsToCheck.push(currentPath);
                            break;
                        }
                        currentPath = Path.parent(currentPath);
                    }
                } catch (error) {
                // 如果无法获取节点，忽略错误
                }
            }
        }
        // 执行原始操作
        apply(operation);
        var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
        try {
            // 操作执行后，检查涉及的卡片是否变空
            for(var _iterator1 = cardPathsToCheck[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                var cardPath = _step1.value;
                try {
                    var cardNode = Node.get(editor, cardPath);
                    if (cardNode && cardNode.type === 'card' && isCardEmpty(cardNode)) {
                        Transforms.removeNodes(editor, {
                            at: cardPath
                        });
                    }
                } catch (error) {
                // 如果节点已被删除或不存在，忽略错误
                }
            }
        } catch (err) {
            _didIteratorError1 = true;
            _iteratorError1 = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                    _iterator1.return();
                }
            } finally{
                if (_didIteratorError1) {
                    throw _iteratorError1;
                }
            }
        }
    };
    editor.insertText = function(text) {
        var selection = editor.selection;
        if (selection && Range.isCollapsed(selection)) {
            try {
                var node = Node.get(editor, Path.parent(selection.anchor.path));
                // card-before 不允许任何文本输入
                if (node.type === 'card-before') {
                    return; // 阻止输入
                }
                // card-after 的输入会插入到卡片后面的新段落中
                if (node.type === 'card-after') {
                    var grandParentPath = Path.parent(Path.parent(selection.anchor.path));
                    var grandParent = Node.get(editor, grandParentPath);
                    if (grandParent.type === 'card') {
                        Editor.withoutNormalizing(editor, function() {
                            Transforms.insertNodes(editor, {
                                type: 'paragraph',
                                children: [
                                    {
                                        text: text
                                    }
                                ]
                            }, {
                                at: Path.next(grandParentPath)
                            });
                            // 选中新创建的段落
                            var newParagraphPath = Path.next(grandParentPath);
                            var textPath = _to_consumable_array(newParagraphPath).concat([
                                0
                            ]);
                            Transforms.select(editor, {
                                anchor: {
                                    path: textPath,
                                    offset: text.length
                                },
                                focus: {
                                    path: textPath,
                                    offset: text.length
                                }
                            });
                            var cardAfterPath = _to_consumable_array(grandParentPath).concat([
                                2,
                                0
                            ]);
                            clearCardAreaText(editor, cardAfterPath);
                        });
                        return;
                    }
                }
            } catch (error) {
            // 如果无法获取节点，继续原有逻辑
            }
        }
        insertText(text);
    };
    editor.insertFragment = function(fragment) {
        var selection = editor.selection;
        if (selection && Range.isCollapsed(selection)) {
            try {
                var node = Node.get(editor, Path.parent(selection.anchor.path));
                // card-before 不允许任何片段插入
                if (node.type === 'card-before') {
                    return; // 阻止插入
                }
                // card-after 的片段插入会放到卡片后面
                if (node.type === 'card-after') {
                    var grandParentPath = Path.parent(Path.parent(selection.anchor.path));
                    var grandParent = Node.get(editor, grandParentPath);
                    if (grandParent.type === 'card') {
                        // 将片段内容插入到卡片后面
                        Transforms.insertNodes(editor, fragment, {
                            at: Path.next(grandParentPath),
                            select: true
                        });
                        return;
                    }
                }
            } catch (error) {
            // 如果无法获取节点，继续原有逻辑
            }
        }
        insertFragment(fragment);
    };
    editor.deleteBackward = function(unit) {
        var selection = editor.selection;
        if (selection && hasRange(editor, selection) && Range.isCollapsed(selection)) {
            var node = Node.get(editor, Path.parent(selection.anchor.path));
            if (node.type === 'card-before') {
                return;
            }
            if (node.type === 'card-after') {
                Transforms.removeNodes(editor, {
                    at: Path.parent(selection.anchor.path)
                });
                return;
            }
            var curNode = Node.get(editor, selection.anchor.path);
            // 检查前一个节点是否是 tag
            try {
                var _ref = _sliced_to_array(Editor.previous(editor, {
                    at: selection.anchor.path
                }) || [], 2), previousNode = _ref[0], previousPath = _ref[1];
                var isBeforeTag = selection && selection.anchor.offset <= 1;
                if ((previousNode === null || previousNode === void 0 ? void 0 : previousNode.tag) && previousPath && isBeforeTag) {
                    var _curNode_text, _curNode_text1;
                    // 如果当前节点不为空,且只有一个文本
                    if (((_curNode_text = curNode.text) === null || _curNode_text === void 0 ? void 0 : _curNode_text.trim()) && curNode.text.trimEnd().length === 1 && selection.anchor.offset > 0) {
                        Transforms.insertText(editor, '', {
                            at: selection.anchor.path
                        });
                        Transforms.insertNodes(editor, {
                            type: 'paragraph',
                            children: [
                                {
                                    text: ' '
                                }
                            ]
                        }, {
                            at: selection.anchor.path,
                            select: true
                        });
                        return;
                    } else if (((_curNode_text1 = curNode.text) === null || _curNode_text1 === void 0 ? void 0 : _curNode_text1.trim()) && selection.anchor.offset > 0) {
                        deleteBackward(unit);
                        return;
                    }
                    // 如果前一个节点是 tag，直接删除整个 tag
                    Editor.withoutNormalizing(editor, function() {
                        var parent = Node.get(editor, Path.parent(previousPath));
                        var index = previousPath[previousPath.length - 1];
                        if (parent.children.length === 1) {
                            // 如果是唯一的节点，转换为普通文本
                            Transforms.setNodes(editor, {
                                tag: false,
                                code: false,
                                text: ' ',
                                triggerText: undefined
                            }, {
                                at: previousPath
                            });
                        } else if (index === 0) {
                            // 如果是第一个节点，删除并合并下一个节点
                            Transforms.removeNodes(editor, {
                                at: previousPath
                            });
                        } else {
                            // 如果是中间或最后节点，先合并再删除
                            Transforms.removeNodes(editor, {
                                at: previousPath
                            });
                        }
                    });
                    return;
                }
            } catch (error) {
            // 如果获取前一个节点失败，继续执行原始删除操作
            }
            try {
                var _node_text_trim, _node_text, _selection_anchor;
                var node1 = Node.get(editor, selection.anchor.path);
                if ((node1 === null || node1 === void 0 ? void 0 : node1.tag) && (node1 === null || node1 === void 0 ? void 0 : (_node_text = node1.text) === null || _node_text === void 0 ? void 0 : (_node_text_trim = _node_text.trim()) === null || _node_text_trim === void 0 ? void 0 : _node_text_trim.length) < 1 && (selection === null || selection === void 0 ? void 0 : (_selection_anchor = selection.anchor) === null || _selection_anchor === void 0 ? void 0 : _selection_anchor.offset) < 1) {
                    var _node_text1;
                    var text = node1 === null || node1 === void 0 ? void 0 : (_node_text1 = node1.text) === null || _node_text1 === void 0 ? void 0 : _node_text1.replace(node1.triggerText || '', '');
                    Transforms.setNodes(editor, {
                        tag: false,
                        code: false
                    }, {
                        at: selection.anchor.path
                    });
                    Transforms.insertText(editor, text, {
                        at: selection.anchor.path
                    });
                    return;
                }
            } catch (unused) {}
        }
        deleteBackward(unit);
    };
    return editor;
};
