@lobehub/editor 3.13.0 → 3.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,8 +6,8 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
7
|
import { addClassNamesToElement, removeClassNamesFromElement } from '@lexical/utils';
|
|
8
8
|
import Katex from 'katex';
|
|
9
|
-
import { $getSelection, $isNodeSelection
|
|
10
|
-
import { useEffect, useRef, useState } from 'react';
|
|
9
|
+
import { $getSelection, $isNodeSelection } from 'lexical';
|
|
10
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
11
11
|
import { useLexicalEditor } from "../../../../editor-kernel/react";
|
|
12
12
|
import { useLexicalNodeSelection } from "../../../../editor-kernel/react/useLexicalNodeSelection";
|
|
13
13
|
import { createDebugLogger } from "../../../../utils/debug";
|
|
@@ -23,7 +23,7 @@ var MathInline = function MathInline(_ref) {
|
|
|
23
23
|
var _useLexicalNodeSelect = useLexicalNodeSelection(node.getKey()),
|
|
24
24
|
_useLexicalNodeSelect2 = _slicedToArray(_useLexicalNodeSelect, 2),
|
|
25
25
|
isSelected = _useLexicalNodeSelect2[0],
|
|
26
|
-
|
|
26
|
+
setIsSelected = _useLexicalNodeSelect2[1];
|
|
27
27
|
var _useState = useState(false),
|
|
28
28
|
_useState2 = _slicedToArray(_useState, 2),
|
|
29
29
|
isEditing = _useState2[0],
|
|
@@ -59,24 +59,35 @@ var MathInline = function MathInline(_ref) {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
}, [isSelected, isEditing, editor, node]);
|
|
62
|
-
useLexicalEditor(function (editor) {
|
|
63
|
-
return editor.registerCommand(CLICK_COMMAND, function (payload) {
|
|
64
|
-
logger.debug('📊 Math click event:', payload.target === ref.current);
|
|
65
|
-
if (payload.target && payload.target instanceof Node) {
|
|
66
|
-
var _ref$current;
|
|
67
|
-
// 获取节点对应的 DOM 元素
|
|
68
|
-
var nodeElement = editor.getElementByKey(node.getKey());
|
|
69
62
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
63
|
+
// useLexicalEditor(
|
|
64
|
+
// (editor) => {
|
|
65
|
+
// return editor.registerCommand(
|
|
66
|
+
// CLICK_COMMAND,
|
|
67
|
+
// (payload) => {
|
|
68
|
+
// logger.debug('📊 Math click event:', payload.target === ref.current);
|
|
69
|
+
// if (payload.target && payload.target instanceof Node) {
|
|
70
|
+
// // 获取节点对应的 DOM 元素
|
|
71
|
+
// const nodeElement = editor.getElementByKey(node.getKey());
|
|
72
|
+
|
|
73
|
+
// // 对于 block 模式,检查是否点击在整个节点容器内
|
|
74
|
+
// // 对于 inline 模式,仍然检查是否点击在渲染内容内
|
|
75
|
+
// const isClickInNode =
|
|
76
|
+
// node instanceof MathBlockNode
|
|
77
|
+
// ? nodeElement?.contains(payload.target)
|
|
78
|
+
// : ref.current?.contains(payload.target);
|
|
79
|
+
|
|
80
|
+
// if (isClickInNode) {
|
|
81
|
+
// setSelected(true);
|
|
82
|
+
// }
|
|
83
|
+
// }
|
|
84
|
+
// return false;
|
|
85
|
+
// },
|
|
86
|
+
// COMMAND_PRIORITY_NORMAL,
|
|
87
|
+
// );
|
|
88
|
+
// },
|
|
89
|
+
// [node],
|
|
90
|
+
// );
|
|
80
91
|
|
|
81
92
|
// 监听编辑器状态变化来检测编辑状态
|
|
82
93
|
useLexicalEditor(function (editor) {
|
|
@@ -101,8 +112,15 @@ var MathInline = function MathInline(_ref) {
|
|
|
101
112
|
});
|
|
102
113
|
});
|
|
103
114
|
}, [node]);
|
|
115
|
+
var handleClick = useCallback(function (e) {
|
|
116
|
+
logger.debug('📊 Math click event:', e.target === ref.current);
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
e.stopPropagation();
|
|
119
|
+
setIsSelected(true);
|
|
120
|
+
}, [editor, node]);
|
|
104
121
|
return /*#__PURE__*/_jsx("span", {
|
|
105
122
|
className: className,
|
|
123
|
+
onClick: handleClick,
|
|
106
124
|
ref: ref,
|
|
107
125
|
children: node.code ? node.code : /*#__PURE__*/_jsx(Placeholder, {
|
|
108
126
|
mathBlock: isMathBlock
|
package/package.json
CHANGED