@lobehub/editor 1.6.0 → 1.6.2
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.
- package/es/plugins/common/react/Placeholder/index.js +1 -1
- package/es/plugins/link/react/ReactLinkPlugin.js +4 -6
- package/es/plugins/link/react/components/LinkToolbar.js +7 -2
- package/es/plugins/math/react/component/MathEditor.js +23 -7
- package/es/plugins/math/react/component/MathEditorContainer.js +43 -25
- package/es/plugins/math/react/component/MathInline.js +6 -1
- package/es/plugins/math/react/component/Placeholder.d.ts +3 -1
- package/es/plugins/math/react/component/Placeholder.js +11 -3
- package/es/plugins/math/react/style.js +2 -2
- package/package.json +1 -1
|
@@ -123,12 +123,10 @@ export var ReactLinkPlugin = function ReactLinkPlugin(_ref) {
|
|
|
123
123
|
},
|
|
124
124
|
onMouseLeave: function onMouseLeave() {
|
|
125
125
|
clearTimeout(clearTimerRef.current);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
}, 300);
|
|
126
|
+
if (divRef.current) {
|
|
127
|
+
divRef.current.style.left = '-9999px';
|
|
128
|
+
divRef.current.style.top = '-9999px';
|
|
129
|
+
}
|
|
132
130
|
},
|
|
133
131
|
ref: divRef
|
|
134
132
|
}), /*#__PURE__*/_jsx(LinkEdit, {})]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
var _excluded = ["linkNode", "editor"];
|
|
2
|
+
var _excluded = ["linkNode", "editor", "onMouseLeave"];
|
|
3
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -22,6 +22,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
22
22
|
var LinkToolbar = /*#__PURE__*/memo(function (_ref) {
|
|
23
23
|
var linkNode = _ref.linkNode,
|
|
24
24
|
editor = _ref.editor,
|
|
25
|
+
onMouseLeave = _ref.onMouseLeave,
|
|
25
26
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
26
27
|
var _useStyles = useStyles(),
|
|
27
28
|
styles = _useStyles.styles;
|
|
@@ -94,8 +95,12 @@ var LinkToolbar = /*#__PURE__*/memo(function (_ref) {
|
|
|
94
95
|
icon: UnlinkIcon,
|
|
95
96
|
key: 'unlink',
|
|
96
97
|
label: t('link.unlink'),
|
|
97
|
-
onClick:
|
|
98
|
+
onClick: function onClick(e) {
|
|
99
|
+
handleRemove();
|
|
100
|
+
onMouseLeave === null || onMouseLeave === void 0 || onMouseLeave(e);
|
|
101
|
+
}
|
|
98
102
|
}],
|
|
103
|
+
onMouseLeave: onMouseLeave,
|
|
99
104
|
shadow: true,
|
|
100
105
|
size: {
|
|
101
106
|
blockSize: 32,
|
|
@@ -58,13 +58,20 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
58
58
|
// 直接更新节点内容
|
|
59
59
|
var lexicalEditor = editor.getLexicalEditor();
|
|
60
60
|
if (lexicalEditor && !isUpdatingRef.current) {
|
|
61
|
-
// 仅在校验通过时更新文档;失败时不更新,保持最后一次成功渲染
|
|
62
61
|
if (!isInputValidRef.current) {
|
|
62
|
+
var currentNode = lexicalEditor.getEditorState().read(function () {
|
|
63
|
+
return lexicalEditor.getElementByKey(mathNode.getKey());
|
|
64
|
+
});
|
|
65
|
+
if (currentNode) {
|
|
66
|
+
var writableNode = mathNode.getWritable();
|
|
67
|
+
writableNode.__code = value;
|
|
68
|
+
}
|
|
63
69
|
return;
|
|
64
70
|
}
|
|
71
|
+
|
|
65
72
|
// 检查当前值是否与节点中的值不同,避免不必要的更新
|
|
66
73
|
var currentCode = mathNode.code;
|
|
67
|
-
if (currentCode === value) {
|
|
74
|
+
if (value && currentCode && currentCode === value) {
|
|
68
75
|
return; // 值相同,无需更新
|
|
69
76
|
}
|
|
70
77
|
isUpdatingRef.current = true;
|
|
@@ -73,8 +80,8 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
73
80
|
return lexicalEditor.getElementByKey(mathNode.getKey());
|
|
74
81
|
});
|
|
75
82
|
if (currentNode) {
|
|
76
|
-
var
|
|
77
|
-
|
|
83
|
+
var _writableNode = mathNode.getWritable();
|
|
84
|
+
_writableNode.__code = value;
|
|
78
85
|
}
|
|
79
86
|
});
|
|
80
87
|
// 延迟重置更新标志,确保更新监听器不会立即触发
|
|
@@ -255,8 +262,12 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
255
262
|
var handlePointerDown = function handlePointerDown(event) {
|
|
256
263
|
var target = event.target;
|
|
257
264
|
if (!target) return;
|
|
258
|
-
|
|
259
|
-
|
|
265
|
+
|
|
266
|
+
// 支持多个容器(例如使用 renderComp 渲染到外部节点时,会有额外容器)
|
|
267
|
+
var containers = Array.from(document.querySelectorAll('[data-math-editor-container]'));
|
|
268
|
+
if (containers.some(function (el) {
|
|
269
|
+
return el && el.contains(target);
|
|
270
|
+
})) return;
|
|
260
271
|
handleCancel();
|
|
261
272
|
};
|
|
262
273
|
document.addEventListener('mousedown', handlePointerDown);
|
|
@@ -269,9 +280,14 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
269
280
|
|
|
270
281
|
// 如果有自定义渲染组件,使用它来包装 MathEditorContent
|
|
271
282
|
if (renderComp) {
|
|
283
|
+
// 为自定义渲染的内容增加容器标记,便于外部点击检测
|
|
284
|
+
var wrapped = /*#__PURE__*/_jsx("div", {
|
|
285
|
+
"data-math-editor-container": true,
|
|
286
|
+
children: mathEditorContent
|
|
287
|
+
});
|
|
272
288
|
return /*#__PURE__*/_jsx(_Fragment, {
|
|
273
289
|
children: renderComp({
|
|
274
|
-
children:
|
|
290
|
+
children: wrapped,
|
|
275
291
|
open: isOpen
|
|
276
292
|
})
|
|
277
293
|
});
|
|
@@ -13,33 +13,48 @@ export var MathEditorContainer = /*#__PURE__*/memo(function (_ref) {
|
|
|
13
13
|
var _useStyles = useStyles(),
|
|
14
14
|
styles = _useStyles.styles;
|
|
15
15
|
useEffect(function () {
|
|
16
|
-
if (!mathDOM || !divRef.current)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (editorContainer) {
|
|
37
|
-
var containerRect = editorContainer.getBoundingClientRect();
|
|
38
|
-
divRef.current.style.width = "".concat(containerRect.width, "px");
|
|
39
|
-
onFocus === null || onFocus === void 0 || onFocus();
|
|
16
|
+
if (!mathDOM || !divRef.current) return;
|
|
17
|
+
var floating = divRef.current;
|
|
18
|
+
var updatePosition = function updatePosition() {
|
|
19
|
+
if (!mathDOM || !floating) return;
|
|
20
|
+
computePosition(mathDOM, floating, {
|
|
21
|
+
middleware: [offset(8), flip(), shift()],
|
|
22
|
+
placement: 'bottom-start'
|
|
23
|
+
}).then(function (_ref2) {
|
|
24
|
+
var x = _ref2.x,
|
|
25
|
+
y = _ref2.y;
|
|
26
|
+
if (!floating) return;
|
|
27
|
+
floating.style.left = "".concat(x, "px");
|
|
28
|
+
floating.style.top = "".concat(y, "px");
|
|
29
|
+
floating.style.width = '';
|
|
30
|
+
if (isBlockMode) {
|
|
31
|
+
var _editorContainer = mathDOM.closest('[contenteditable="true"]');
|
|
32
|
+
if (_editorContainer) {
|
|
33
|
+
var containerRect = _editorContainer.getBoundingClientRect();
|
|
34
|
+
floating.style.width = "".concat(containerRect.width, "px");
|
|
35
|
+
}
|
|
40
36
|
}
|
|
41
|
-
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// 监听尺寸变化,随内容变化重新定位
|
|
41
|
+
var resizeObserver = new ResizeObserver(function () {
|
|
42
|
+
return updatePosition();
|
|
42
43
|
});
|
|
44
|
+
resizeObserver.observe(mathDOM);
|
|
45
|
+
resizeObserver.observe(floating);
|
|
46
|
+
var editorContainer = null;
|
|
47
|
+
if (isBlockMode) {
|
|
48
|
+
editorContainer = mathDOM.closest('[contenteditable="true"]');
|
|
49
|
+
if (editorContainer) resizeObserver.observe(editorContainer);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 窗口尺寸变化时也重新定位
|
|
53
|
+
window.addEventListener('resize', updatePosition);
|
|
54
|
+
return function () {
|
|
55
|
+
resizeObserver.disconnect();
|
|
56
|
+
window.removeEventListener('resize', updatePosition);
|
|
57
|
+
};
|
|
43
58
|
}, [mathDOM, prev, isBlockMode, onFocus]);
|
|
44
59
|
|
|
45
60
|
// 当没有 mathDOM 时,隐藏容器
|
|
@@ -52,6 +67,9 @@ export var MathEditorContainer = /*#__PURE__*/memo(function (_ref) {
|
|
|
52
67
|
return /*#__PURE__*/_jsx(Block, {
|
|
53
68
|
className: styles.mathEditor,
|
|
54
69
|
"data-math-editor-container": true,
|
|
70
|
+
onClick: function onClick(e) {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
},
|
|
55
73
|
ref: divRef,
|
|
56
74
|
shadow: true,
|
|
57
75
|
variant: 'outlined',
|
|
@@ -28,9 +28,12 @@ var MathInline = /*#__PURE__*/memo(function (_ref) {
|
|
|
28
28
|
_useState2 = _slicedToArray(_useState, 2),
|
|
29
29
|
isEditing = _useState2[0],
|
|
30
30
|
setIsEditing = _useState2[1];
|
|
31
|
+
var isMathBlock = node instanceof MathBlockNode;
|
|
31
32
|
useEffect(function () {
|
|
32
33
|
if (ref.current && node.code) {
|
|
33
34
|
Katex.render(node.code, ref.current, {
|
|
35
|
+
// 使用 displayMode 渲染块级公式
|
|
36
|
+
displayMode: node instanceof MathBlockNode,
|
|
34
37
|
throwOnError: false
|
|
35
38
|
});
|
|
36
39
|
}
|
|
@@ -101,7 +104,9 @@ var MathInline = /*#__PURE__*/memo(function (_ref) {
|
|
|
101
104
|
return /*#__PURE__*/_jsx("span", {
|
|
102
105
|
className: className,
|
|
103
106
|
ref: ref,
|
|
104
|
-
children: node.code ? node.code : /*#__PURE__*/_jsx(Placeholder, {
|
|
107
|
+
children: node.code ? node.code : /*#__PURE__*/_jsx(Placeholder, {
|
|
108
|
+
mathBlock: isMathBlock
|
|
109
|
+
})
|
|
105
110
|
});
|
|
106
111
|
});
|
|
107
112
|
export default MathInline;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
declare const Placeholder: import("react").
|
|
2
|
+
declare const Placeholder: import("react").NamedExoticComponent<{
|
|
3
|
+
mathBlock?: boolean | undefined;
|
|
4
|
+
}>;
|
|
3
5
|
export default Placeholder;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { Text } from '@lobehub/ui';
|
|
2
2
|
import { memo } from 'react';
|
|
3
|
+
import { Center } from 'react-layout-kit';
|
|
3
4
|
import { useTranslation } from "../../../../editor-kernel/react/useTranslation";
|
|
4
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
var Placeholder = /*#__PURE__*/memo(function () {
|
|
6
|
+
var Placeholder = /*#__PURE__*/memo(function (_ref) {
|
|
7
|
+
var mathBlock = _ref.mathBlock;
|
|
6
8
|
var t = useTranslation();
|
|
7
|
-
|
|
9
|
+
var node = /*#__PURE__*/_jsx(Text, {
|
|
8
10
|
as: 'span',
|
|
9
11
|
className: 'katex',
|
|
10
|
-
fontSize: '1em',
|
|
12
|
+
fontSize: mathBlock ? '1.2em' : '1em',
|
|
11
13
|
style: {
|
|
12
14
|
fontStyle: 'italic',
|
|
13
15
|
paddingInline: '0.2em'
|
|
@@ -15,5 +17,11 @@ var Placeholder = /*#__PURE__*/memo(function () {
|
|
|
15
17
|
type: 'secondary',
|
|
16
18
|
children: t('math.placeholder')
|
|
17
19
|
});
|
|
20
|
+
if (!mathBlock) return node;
|
|
21
|
+
return /*#__PURE__*/_jsx(Center, {
|
|
22
|
+
padding: 18,
|
|
23
|
+
width: '100%',
|
|
24
|
+
children: node
|
|
25
|
+
});
|
|
18
26
|
});
|
|
19
27
|
export default Placeholder;
|
|
@@ -8,8 +8,8 @@ export var useStyles = createStyles(function (_ref) {
|
|
|
8
8
|
token = _ref.token;
|
|
9
9
|
var latex = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n user-select: none;\n font-size: 1em;\n\n .katex-error {\n color: ", " !important;\n }\n\n .katex-html {\n overflow: auto hidden;\n padding: 3px;\n\n .base {\n margin-block: 0;\n margin-inline: auto;\n }\n\n .tag {\n position: relative !important;\n display: inline-block;\n padding-inline-start: 0.5rem;\n }\n }\n\n &.selected {\n color: #000;\n background: ", ";\n }\n\n &:hover {\n background: ", ";\n }\n\n &.editing {\n background: ", ";\n }\n\n &:has(.katex-error) {\n background: ", ";\n }\n "])), token.colorError, token.yellow, token.colorFillTertiary, token.colorFillTertiary, token.colorErrorBg);
|
|
10
10
|
return {
|
|
11
|
-
mathInline: cx(latex, css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: inline-block;\n "])))),
|
|
12
|
-
mathBlock: cx(latex, css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n overflow: auto hidden;\n display: block;\n white-space: nowrap;\n "])))),
|
|
11
|
+
mathInline: cx(latex, css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: inline-block;\n border-radius: calc(var(--lobe-markdown-border-radius) * 0.5px);\n "])))),
|
|
12
|
+
mathBlock: cx(latex, css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n overflow: auto hidden;\n display: block;\n border-radius: calc(var(--lobe-markdown-border-radius) * 1px);\n white-space: nowrap;\n "])))),
|
|
13
13
|
mathEditor: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 999;\n inset-block-start: -9999px;\n inset-inline-start: -9999px;\n\n width: 320px;\n\n background: ", ";\n\n textarea {\n width: 100%;\n\n font-family: ", ";\n font-size: 13px;\n\n background: transparent !important;\n\n transition: none !important;\n }\n "])), token.colorBgElevated, token.fontFamilyCode),
|
|
14
14
|
mathEditorFooter: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n border-block-start: 1px solid ", ";\n background: ", ";\n "])), token.colorBorderSecondary, token.colorFillQuaternary)
|
|
15
15
|
};
|
package/package.json
CHANGED