@lobehub/editor 3.13.1 → 3.14.0
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/editor-kernel/kernel.js +3 -0
- package/es/editor-kernel/react/LexicalErrorBoundary.d.ts +1 -1
- package/es/editor-kernel/react/useDecorators.d.ts +1 -1
- package/es/plugins/code/plugin/registry.js +3 -1
- package/es/plugins/common/node/cursor.js +7 -1
- package/es/plugins/common/react/ReactPlainText.js +0 -9
- package/es/plugins/litexml/command/index.js +15 -5
- package/es/plugins/litexml/react/hooks/useHasDiffNode.d.ts +1 -1
- package/es/plugins/litexml/react/hooks/useHasDiffNode.js +10 -1
- package/es/plugins/math/react/components/MathEditor.js +2 -13
- package/es/plugins/math/react/components/MathEditorContainer.js +72 -35
- package/es/plugins/math/react/components/MathInline.js +9 -3
- package/es/plugins/math/react/style.d.ts +1 -0
- package/es/plugins/math/react/style.js +5 -4
- package/package.json +1 -1
|
@@ -271,6 +271,9 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
|
|
|
271
271
|
this.logger.error('❌ Editor not initialized');
|
|
272
272
|
throw new Error("Editor is not initialized.");
|
|
273
273
|
}
|
|
274
|
+
this.historyState.redoStack = [];
|
|
275
|
+
this.historyState.undoStack = [];
|
|
276
|
+
this.historyState.current = null;
|
|
274
277
|
datasource.read(this.editor, content, options);
|
|
275
278
|
this.emit('documentChange', type, content);
|
|
276
279
|
this.logger.debug("\uD83D\uDCE5 Set ".concat(type, " document"));
|
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
import type { JSX } from 'react';
|
|
9
9
|
export type LexicalErrorBoundaryProps = {
|
|
10
10
|
children: JSX.Element;
|
|
11
|
-
onError: (error:
|
|
11
|
+
onError: (error: unknown) => void;
|
|
12
12
|
};
|
|
13
13
|
export declare function LexicalErrorBoundary({ children, onError, }: LexicalErrorBoundaryProps): JSX.Element;
|
|
@@ -2,7 +2,7 @@ import { type ComponentClass, type FC, type JSX } from 'react';
|
|
|
2
2
|
import { IEditor } from "../../types";
|
|
3
3
|
type ErrorBoundaryProps = {
|
|
4
4
|
children: JSX.Element;
|
|
5
|
-
onError: (error:
|
|
5
|
+
onError: (error: unknown) => void;
|
|
6
6
|
};
|
|
7
7
|
export type ErrorBoundaryType = ComponentClass<ErrorBoundaryProps> | FC<ErrorBoundaryProps>;
|
|
8
8
|
export declare function useDecorators(editor: IEditor, ErrorBoundary: ErrorBoundaryType): Array<JSX.Element>;
|
|
@@ -2,7 +2,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
|
|
|
2
2
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(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(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
3
|
function _arrayLikeToArray(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; }
|
|
4
4
|
import { mergeRegister } from '@lexical/utils';
|
|
5
|
-
import { $getNodeByKey } from 'lexical';
|
|
5
|
+
import { $getNodeByKey, HISTORY_MERGE_TAG } from 'lexical';
|
|
6
6
|
import { $createCursorNode } from "../../common";
|
|
7
7
|
import { HotkeyEnum } from "../../../types/hotkey";
|
|
8
8
|
import { INSERT_CODEINLINE_COMMAND } from "../command";
|
|
@@ -45,6 +45,8 @@ export function registerCodeInline(editor, kernel, options) {
|
|
|
45
45
|
node.insertBefore($createCursorNode());
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
+
}, {
|
|
49
|
+
tag: HISTORY_MERGE_TAG
|
|
48
50
|
});
|
|
49
51
|
}
|
|
50
52
|
}), kernel.registerHotkey(HotkeyEnum.CodeInline, function () {
|
|
@@ -19,7 +19,7 @@ function _assertThisInitialized(self) { if (self === void 0) { throw new Referen
|
|
|
19
19
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
20
20
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
21
21
|
import { mergeRegister } from '@lexical/utils';
|
|
22
|
-
import { $createTextNode, $getNodeByKey, $getSelection, $isDecoratorNode, $isRangeSelection, $setSelection, COMMAND_PRIORITY_HIGH, DecoratorNode, ElementNode, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_BACKSPACE_COMMAND, TextNode } from 'lexical';
|
|
22
|
+
import { $createTextNode, $getNodeByKey, $getSelection, $isDecoratorNode, $isRangeSelection, $setSelection, COMMAND_PRIORITY_HIGH, DecoratorNode, ElementNode, HISTORY_MERGE_TAG, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_BACKSPACE_COMMAND, TextNode } from 'lexical';
|
|
23
23
|
import { createDebugLogger } from "../../../utils/debug";
|
|
24
24
|
var logger = createDebugLogger('common', 'cursor');
|
|
25
25
|
export var CardLikeElementNode = /*#__PURE__*/function (_ElementNode) {
|
|
@@ -120,6 +120,8 @@ export function registerCursorNode(editor) {
|
|
|
120
120
|
needAddCursor.forEach(function (node) {
|
|
121
121
|
node.insertAfter($createCursorNode());
|
|
122
122
|
});
|
|
123
|
+
}, {
|
|
124
|
+
tag: HISTORY_MERGE_TAG
|
|
123
125
|
});
|
|
124
126
|
}
|
|
125
127
|
return false;
|
|
@@ -164,6 +166,8 @@ export function registerCursorNode(editor) {
|
|
|
164
166
|
needRemove.forEach(function (node) {
|
|
165
167
|
node.remove();
|
|
166
168
|
});
|
|
169
|
+
}, {
|
|
170
|
+
tag: HISTORY_MERGE_TAG
|
|
167
171
|
});
|
|
168
172
|
}
|
|
169
173
|
return false;
|
|
@@ -189,6 +193,8 @@ export function registerCursorNode(editor) {
|
|
|
189
193
|
node.insertAfter(textNode);
|
|
190
194
|
textNode.selectEnd();
|
|
191
195
|
}
|
|
196
|
+
}, {
|
|
197
|
+
tag: HISTORY_MERGE_TAG
|
|
192
198
|
});
|
|
193
199
|
}
|
|
194
200
|
return false;
|
|
@@ -152,15 +152,6 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
|
|
|
152
152
|
}
|
|
153
153
|
});
|
|
154
154
|
}, [editor, type, content, onChange, onTextChange, isInitialized]);
|
|
155
|
-
useEffect(function () {
|
|
156
|
-
var handleDocumentChange = function handleDocumentChange() {
|
|
157
|
-
onTextChange === null || onTextChange === void 0 || onTextChange(editor);
|
|
158
|
-
};
|
|
159
|
-
editor.on('documentChange', handleDocumentChange);
|
|
160
|
-
return function () {
|
|
161
|
-
editor.off('documentChange', handleDocumentChange);
|
|
162
|
-
};
|
|
163
|
-
}, [editor, onTextChange]);
|
|
164
155
|
useEffect(function () {
|
|
165
156
|
if (!isInitialized) return;
|
|
166
157
|
if (typeof editable === 'boolean') {
|
|
@@ -10,7 +10,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
10
10
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
11
11
|
import { $isListItemNode } from '@lexical/list';
|
|
12
12
|
import { mergeRegister } from '@lexical/utils';
|
|
13
|
-
import { $createParagraphNode, $getNodeByKey, $insertNodes, $isElementNode, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
13
|
+
import { $createParagraphNode, $getNodeByKey, $getRoot, $insertNodes, $isElementNode, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
14
14
|
import { $closest } from "../../../editor-kernel";
|
|
15
15
|
import { createDebugLogger } from "../../../utils/debug";
|
|
16
16
|
import { $createDiffNode, DiffNode } from "../node/DiffNode";
|
|
@@ -361,9 +361,17 @@ function handleInsert(editor, payload, dataSource) {
|
|
|
361
361
|
try {
|
|
362
362
|
var referenceNode = null;
|
|
363
363
|
if (isBefore) {
|
|
364
|
-
|
|
364
|
+
if (payload.beforeId === 'root') {
|
|
365
|
+
referenceNode = $getRoot().getFirstChild();
|
|
366
|
+
} else {
|
|
367
|
+
referenceNode = $getNodeByKey(charToId(payload.beforeId));
|
|
368
|
+
}
|
|
365
369
|
} else {
|
|
366
|
-
|
|
370
|
+
if (payload.afterId === 'root') {
|
|
371
|
+
referenceNode = $getRoot().getLastChild();
|
|
372
|
+
} else {
|
|
373
|
+
referenceNode = $getNodeByKey(charToId(payload.afterId));
|
|
374
|
+
}
|
|
367
375
|
}
|
|
368
376
|
if (!referenceNode) {
|
|
369
377
|
throw new Error('Reference node not found for insertion.');
|
|
@@ -373,7 +381,9 @@ function handleInsert(editor, payload, dataSource) {
|
|
|
373
381
|
});
|
|
374
382
|
if (!delay) {
|
|
375
383
|
if (isBefore) {
|
|
376
|
-
|
|
384
|
+
newNodes.reverse().forEach(function (node) {
|
|
385
|
+
referenceNode = referenceNode.insertBefore(node);
|
|
386
|
+
});
|
|
377
387
|
} else {
|
|
378
388
|
newNodes.forEach(function (node) {
|
|
379
389
|
if (referenceNode) {
|
|
@@ -398,7 +408,7 @@ function handleInsert(editor, payload, dataSource) {
|
|
|
398
408
|
diffNode.append(node);
|
|
399
409
|
return diffNode;
|
|
400
410
|
});
|
|
401
|
-
diffNodes.forEach(function (diffNode) {
|
|
411
|
+
diffNodes.reverse().forEach(function (diffNode) {
|
|
402
412
|
if (referenceNode) {
|
|
403
413
|
referenceNode = referenceNode.insertBefore(diffNode);
|
|
404
414
|
}
|
|
@@ -8,6 +8,9 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
8
8
|
import { useEffect, useState } from 'react';
|
|
9
9
|
function hasDiffNode(editor) {
|
|
10
10
|
var _editor$getLexicalEdi;
|
|
11
|
+
if (!editor) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
11
14
|
var values = (_editor$getLexicalEdi = editor.getLexicalEditor()) === null || _editor$getLexicalEdi === void 0 ? void 0 : _editor$getLexicalEdi.getEditorState()._nodeMap.values();
|
|
12
15
|
if (!values) {
|
|
13
16
|
return false;
|
|
@@ -29,7 +32,7 @@ function hasDiffNode(editor) {
|
|
|
29
32
|
return false;
|
|
30
33
|
}
|
|
31
34
|
export function useHasDiffNode(editor) {
|
|
32
|
-
var _useState = useState(!!editor.getLexicalEditor()),
|
|
35
|
+
var _useState = useState(!!(editor !== null && editor !== void 0 && editor.getLexicalEditor())),
|
|
33
36
|
_useState2 = _slicedToArray(_useState, 2),
|
|
34
37
|
hasInit = _useState2[0],
|
|
35
38
|
setHasInit = _useState2[1];
|
|
@@ -38,6 +41,9 @@ export function useHasDiffNode(editor) {
|
|
|
38
41
|
hasDiff = _useState4[0],
|
|
39
42
|
setHasDiff = _useState4[1];
|
|
40
43
|
useEffect(function () {
|
|
44
|
+
if (!editor) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
41
47
|
var handle = function handle() {
|
|
42
48
|
setHasInit(true);
|
|
43
49
|
};
|
|
@@ -48,6 +54,9 @@ export function useHasDiffNode(editor) {
|
|
|
48
54
|
}, [editor]);
|
|
49
55
|
useEffect(function () {
|
|
50
56
|
var _editor$getLexicalEdi2;
|
|
57
|
+
if (!editor || !hasInit) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
51
60
|
var unregister = (_editor$getLexicalEdi2 = editor.getLexicalEditor()) === null || _editor$getLexicalEdi2 === void 0 ? void 0 : _editor$getLexicalEdi2.registerUpdateListener(function () {
|
|
52
61
|
setHasDiff(hasDiffNode(editor));
|
|
53
62
|
});
|
|
@@ -54,25 +54,14 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
54
54
|
// 实时更新节点内容(仅当输入可渲染时才同步到 document)
|
|
55
55
|
useEffect(function () {
|
|
56
56
|
if (!mathNode) return;
|
|
57
|
+
// 输入无效时不同步到文档,避免无限循环;提交时会使用 lastValidRef 作为回退
|
|
58
|
+
if (!isInputValidRef.current) return;
|
|
57
59
|
|
|
58
60
|
// 使用防抖来避免过于频繁的更新
|
|
59
61
|
var timeoutId = setTimeout(function () {
|
|
60
62
|
// 直接更新节点内容
|
|
61
63
|
var lexicalEditor = editor.getLexicalEditor();
|
|
62
64
|
if (lexicalEditor && !isUpdatingRef.current) {
|
|
63
|
-
if (!isInputValidRef.current) {
|
|
64
|
-
var currentNode = lexicalEditor.getEditorState().read(function () {
|
|
65
|
-
return lexicalEditor.getElementByKey(mathNode.getKey());
|
|
66
|
-
});
|
|
67
|
-
if (currentNode) {
|
|
68
|
-
lexicalEditor.update(function () {
|
|
69
|
-
var writableNode = mathNode.getWritable();
|
|
70
|
-
writableNode.__code = value;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
65
|
// 检查当前值是否与节点中的值不同,避免不必要的更新
|
|
77
66
|
var currentCode = mathNode.code;
|
|
78
67
|
if (value && currentCode && currentCode === value) {
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(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(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(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; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { Flexbox, Popover } from '@lobehub/ui';
|
|
8
|
+
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
3
9
|
import { cleanPosition, updatePosition } from "../../../../utils/updatePosition";
|
|
4
10
|
import { styles } from "../style";
|
|
5
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -9,66 +15,97 @@ var MathEditorContainer = /*#__PURE__*/memo(function (_ref) {
|
|
|
9
15
|
mathDOM = _ref.mathDOM,
|
|
10
16
|
onFocus = _ref.onFocus,
|
|
11
17
|
prev = _ref.prev;
|
|
12
|
-
var
|
|
13
|
-
var
|
|
18
|
+
var anchorRef = useRef(null);
|
|
19
|
+
var _useState = useState(undefined),
|
|
20
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
21
|
+
blockWidth = _useState2[0],
|
|
22
|
+
setBlockWidth = _useState2[1];
|
|
23
|
+
var lastBlockWidthRef = useRef(undefined);
|
|
24
|
+
var setBlockWidthIfNeeded = useCallback(function (nextWidth) {
|
|
25
|
+
var normalizedWidth = typeof nextWidth === 'number' ? Math.round(nextWidth) : undefined;
|
|
26
|
+
if (lastBlockWidthRef.current === normalizedWidth) return;
|
|
27
|
+
lastBlockWidthRef.current = normalizedWidth;
|
|
28
|
+
setBlockWidth(normalizedWidth);
|
|
29
|
+
}, []);
|
|
30
|
+
var updateBlockWidth = useCallback(function () {
|
|
31
|
+
if (!isBlockMode) {
|
|
32
|
+
setBlockWidthIfNeeded(undefined);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
var editorContainer = mathDOM === null || mathDOM === void 0 ? void 0 : mathDOM.closest('[contenteditable="true"]');
|
|
36
|
+
if (editorContainer) {
|
|
37
|
+
setBlockWidthIfNeeded(editorContainer.getBoundingClientRect().width);
|
|
38
|
+
}
|
|
39
|
+
}, [isBlockMode, mathDOM, setBlockWidthIfNeeded]);
|
|
40
|
+
var updateAnchorPosition = useCallback(function () {
|
|
14
41
|
return updatePosition({
|
|
15
42
|
callback: function callback() {
|
|
16
|
-
if (!
|
|
43
|
+
if (!anchorRef.current || !mathDOM) return;
|
|
17
44
|
// 展示的时候聚焦
|
|
18
45
|
onFocus === null || onFocus === void 0 || onFocus();
|
|
19
|
-
|
|
20
|
-
divRef.current.style.width = '';
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
var editorContainer = mathDOM.closest('[contenteditable="true"]');
|
|
24
|
-
if (editorContainer) {
|
|
25
|
-
var containerRect = editorContainer.getBoundingClientRect();
|
|
26
|
-
divRef.current.style.width = "".concat(containerRect.width, "px");
|
|
27
|
-
}
|
|
46
|
+
updateBlockWidth();
|
|
28
47
|
},
|
|
29
|
-
floating:
|
|
48
|
+
floating: anchorRef.current,
|
|
49
|
+
placement: isBlockMode ? 'bottom-start' : 'bottom',
|
|
30
50
|
reference: mathDOM
|
|
31
51
|
});
|
|
32
|
-
};
|
|
52
|
+
}, [isBlockMode, mathDOM, onFocus, updateBlockWidth]);
|
|
53
|
+
var handleAnchorClick = useCallback(function () {
|
|
54
|
+
if (!mathDOM) return;
|
|
55
|
+
updateAnchorPosition();
|
|
56
|
+
}, [mathDOM, updateAnchorPosition]);
|
|
33
57
|
useEffect(function () {
|
|
34
|
-
if (!mathDOM || !
|
|
35
|
-
var floating =
|
|
58
|
+
if (!mathDOM || !anchorRef.current) return;
|
|
59
|
+
var floating = anchorRef.current;
|
|
36
60
|
|
|
37
|
-
//
|
|
61
|
+
// 监听尺寸变化,仅更新宽度/位置(不跟随 trigger 尺寸变化)
|
|
38
62
|
var resizeObserver = new ResizeObserver(function () {
|
|
39
|
-
|
|
63
|
+
updateBlockWidth();
|
|
40
64
|
});
|
|
41
|
-
resizeObserver.observe(mathDOM);
|
|
42
65
|
resizeObserver.observe(floating);
|
|
43
66
|
var editorContainer = null;
|
|
44
67
|
if (isBlockMode) {
|
|
45
68
|
editorContainer = mathDOM.closest('[contenteditable="true"]');
|
|
46
69
|
if (editorContainer) resizeObserver.observe(editorContainer);
|
|
47
70
|
}
|
|
71
|
+
updateAnchorPosition();
|
|
48
72
|
|
|
49
73
|
// 窗口尺寸变化时也重新定位
|
|
50
|
-
window.addEventListener('resize',
|
|
74
|
+
window.addEventListener('resize', updateAnchorPosition);
|
|
51
75
|
return function () {
|
|
52
76
|
resizeObserver.disconnect();
|
|
53
|
-
window.removeEventListener('resize',
|
|
77
|
+
window.removeEventListener('resize', updateAnchorPosition);
|
|
54
78
|
};
|
|
55
|
-
}, [mathDOM, prev, isBlockMode,
|
|
79
|
+
}, [mathDOM, prev, isBlockMode, updateAnchorPosition]);
|
|
56
80
|
|
|
57
81
|
// 当没有 mathDOM 时,隐藏容器
|
|
58
82
|
useEffect(function () {
|
|
59
|
-
if (mathDOM || !
|
|
60
|
-
cleanPosition(
|
|
83
|
+
if (mathDOM || !anchorRef.current) return;
|
|
84
|
+
cleanPosition(anchorRef.current);
|
|
61
85
|
}, [mathDOM]);
|
|
62
|
-
return /*#__PURE__*/_jsx(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
86
|
+
return /*#__PURE__*/_jsx(Popover, {
|
|
87
|
+
arrow: false,
|
|
88
|
+
content: /*#__PURE__*/_jsx(Flexbox, {
|
|
89
|
+
className: styles.mathEditor,
|
|
90
|
+
"data-math-editor-container": true,
|
|
91
|
+
style: blockWidth ? {
|
|
92
|
+
width: blockWidth
|
|
93
|
+
} : undefined,
|
|
94
|
+
children: children
|
|
95
|
+
}),
|
|
96
|
+
open: !!mathDOM,
|
|
97
|
+
placement: isBlockMode ? 'bottomLeft' : 'bottom',
|
|
98
|
+
styles: {
|
|
99
|
+
content: {
|
|
100
|
+
borderRadius: '6px',
|
|
101
|
+
padding: 0
|
|
102
|
+
}
|
|
67
103
|
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
104
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
105
|
+
className: styles.mathEditorAnchor,
|
|
106
|
+
onClick: handleAnchorClick,
|
|
107
|
+
ref: anchorRef
|
|
108
|
+
})
|
|
72
109
|
});
|
|
73
110
|
});
|
|
74
111
|
MathEditorContainer.displayName = 'MathEditorContainer';
|
|
@@ -21,9 +21,10 @@ var MathInline = function MathInline(_ref) {
|
|
|
21
21
|
className = _ref.className;
|
|
22
22
|
var ref = useRef(null);
|
|
23
23
|
var _useLexicalNodeSelect = useLexicalNodeSelection(node.getKey()),
|
|
24
|
-
_useLexicalNodeSelect2 = _slicedToArray(_useLexicalNodeSelect,
|
|
24
|
+
_useLexicalNodeSelect2 = _slicedToArray(_useLexicalNodeSelect, 3),
|
|
25
25
|
isSelected = _useLexicalNodeSelect2[0],
|
|
26
|
-
setIsSelected = _useLexicalNodeSelect2[1]
|
|
26
|
+
setIsSelected = _useLexicalNodeSelect2[1],
|
|
27
|
+
clearSelected = _useLexicalNodeSelect2[2];
|
|
27
28
|
var _useState = useState(false),
|
|
28
29
|
_useState2 = _slicedToArray(_useState, 2),
|
|
29
30
|
isEditing = _useState2[0],
|
|
@@ -116,8 +117,13 @@ var MathInline = function MathInline(_ref) {
|
|
|
116
117
|
logger.debug('📊 Math click event:', e.target === ref.current);
|
|
117
118
|
e.preventDefault();
|
|
118
119
|
e.stopPropagation();
|
|
120
|
+
if (isSelected) {
|
|
121
|
+
// 强制触发一次 selection 更新,确保打开编辑器面板
|
|
122
|
+
clearSelected();
|
|
123
|
+
}
|
|
119
124
|
setIsSelected(true);
|
|
120
|
-
|
|
125
|
+
editor.focus();
|
|
126
|
+
}, [clearSelected, editor, isSelected, setIsSelected]);
|
|
121
127
|
return /*#__PURE__*/_jsx("span", {
|
|
122
128
|
className: className,
|
|
123
129
|
onClick: handleClick,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
|
|
1
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8;
|
|
2
2
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
3
|
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
4
4
|
import { createStaticStyles, cx } from 'antd-style';
|
|
@@ -9,9 +9,10 @@ export var styles = createStaticStyles(function (_ref) {
|
|
|
9
9
|
return {
|
|
10
10
|
mathInline: cx(latex, css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: inline-block;\n border-radius: calc(var(--lobe-markdown-border-radius) * 0.5px);\n "])))),
|
|
11
11
|
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 "])))),
|
|
12
|
-
mathEditor: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n
|
|
12
|
+
mathEditor: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n width: 320px;\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 "])), cssVar.colorBgElevated, cssVar.fontFamilyCode),
|
|
13
13
|
mathEditorFooter: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n border-block-start: 1px solid ", ";\n background: ", ";\n "])), cssVar.colorBorderSecondary, cssVar.colorFillQuaternary),
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
mathEditorAnchor: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n pointer-events: none;\n\n position: absolute;\n inset-block-start: -9999px;\n inset-inline-start: -9999px;\n\n width: 0;\n height: 0;\n "]))),
|
|
15
|
+
mathEditorTextArea: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n margin-block: 4px;\n "]))),
|
|
16
|
+
mathPlaceholder: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n padding-inline: 0.2em;\n font-style: italic;\n "])))
|
|
16
17
|
};
|
|
17
18
|
});
|
package/package.json
CHANGED