@lobehub/editor 1.5.10 → 1.6.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.
- package/es/common/sys.d.ts +2 -0
- package/es/common/sys.js +5 -0
- package/es/const/hotkey.d.ts +3 -0
- package/es/const/hotkey.js +58 -0
- package/es/editor-kernel/kernel.d.ts +3 -0
- package/es/editor-kernel/kernel.js +20 -1
- package/es/index.d.ts +2 -0
- package/es/index.js +4 -0
- package/es/plugins/code/plugin/index.d.ts +1 -0
- package/es/plugins/code/plugin/index.js +7 -6
- package/es/plugins/code/plugin/registry.d.ts +4 -1
- package/es/plugins/code/plugin/registry.js +15 -13
- package/es/plugins/code/react/CodeReactPlugin.js +5 -2
- package/es/plugins/code/react/type.d.ts +1 -0
- package/es/plugins/common/plugin/index.d.ts +1 -0
- package/es/plugins/common/plugin/index.js +4 -1
- package/es/plugins/common/plugin/register.d.ts +4 -1
- package/es/plugins/common/plugin/register.js +43 -14
- package/es/plugins/common/react/ReactPlainText.js +4 -1
- package/es/plugins/common/react/type.d.ts +1 -0
- package/es/plugins/link/node/LinkNode.js +1 -3
- package/es/plugins/link/plugin/index.d.ts +4 -0
- package/es/plugins/link/plugin/index.js +11 -1
- package/es/plugins/link/plugin/registry.d.ts +9 -0
- package/es/plugins/link/plugin/registry.js +108 -0
- package/es/plugins/link/react/ReactLinkPlugin.js +21 -50
- package/es/plugins/link/react/components/LinkEdit.js +41 -21
- package/es/plugins/link/react/components/LinkToolbar.js +65 -26
- package/es/plugins/link/react/type.d.ts +1 -0
- package/es/plugins/link/utils/index.d.ts +5 -0
- package/es/plugins/link/utils/index.js +14 -0
- package/es/plugins/list/plugin/index.d.ts +1 -0
- package/es/plugins/list/plugin/index.js +9 -76
- package/es/plugins/list/plugin/registry.d.ts +6 -0
- package/es/plugins/list/plugin/registry.js +98 -0
- package/es/plugins/list/react/ReactListPlugin.js +5 -2
- package/es/plugins/list/react/type.d.ts +1 -0
- package/es/plugins/math/react/component/MathEditor.js +61 -9
- package/es/plugins/math/react/component/MathEditorContainer.js +44 -25
- package/es/plugins/math/react/component/MathEditorContent.d.ts +2 -0
- package/es/plugins/math/react/component/MathEditorContent.js +7 -3
- 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/es/react/ChatInputActions/components/ActionItem.js +8 -2
- package/es/react/ChatInputActions/components/ActionRender.js +10 -3
- package/es/react/ChatInputActions/type.d.ts +2 -1
- package/es/react/hooks/useEditorState/index.js +44 -8
- package/es/types/hotkey.d.ts +71 -0
- package/es/types/hotkey.js +71 -0
- package/es/types/kernel.d.ts +9 -0
- package/es/utils/hotkey/isHotkeyMatch.d.ts +1 -0
- package/es/utils/hotkey/isHotkeyMatch.js +9 -0
- package/es/utils/hotkey/parseHotkeys.d.ts +6 -0
- package/es/utils/hotkey/parseHotkeys.js +42 -0
- package/es/utils/hotkey/registerHotkey.d.ts +15 -0
- package/es/utils/hotkey/registerHotkey.js +32 -0
- package/package.json +2 -1
|
@@ -26,6 +26,9 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
26
26
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
27
27
|
value = _useState4[0],
|
|
28
28
|
setValue = _useState4[1];
|
|
29
|
+
// 最近一次成功渲染(校验通过)的 LaTeX
|
|
30
|
+
var lastValidRef = useRef('');
|
|
31
|
+
var isInputValidRef = useRef(true);
|
|
29
32
|
var _useState5 = useState(null),
|
|
30
33
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
31
34
|
mathDOM = _useState6[0],
|
|
@@ -46,7 +49,7 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
46
49
|
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
47
50
|
editor = _useLexicalComposerCo2[0];
|
|
48
51
|
|
|
49
|
-
//
|
|
52
|
+
// 实时更新节点内容(仅当输入可渲染时才同步到 document)
|
|
50
53
|
useEffect(function () {
|
|
51
54
|
if (!mathNode) return;
|
|
52
55
|
|
|
@@ -55,9 +58,20 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
55
58
|
// 直接更新节点内容
|
|
56
59
|
var lexicalEditor = editor.getLexicalEditor();
|
|
57
60
|
if (lexicalEditor && !isUpdatingRef.current) {
|
|
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
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
58
72
|
// 检查当前值是否与节点中的值不同,避免不必要的更新
|
|
59
73
|
var currentCode = mathNode.code;
|
|
60
|
-
if (currentCode === value) {
|
|
74
|
+
if (value && currentCode && currentCode === value) {
|
|
61
75
|
return; // 值相同,无需更新
|
|
62
76
|
}
|
|
63
77
|
isUpdatingRef.current = true;
|
|
@@ -66,16 +80,16 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
66
80
|
return lexicalEditor.getElementByKey(mathNode.getKey());
|
|
67
81
|
});
|
|
68
82
|
if (currentNode) {
|
|
69
|
-
var
|
|
70
|
-
|
|
83
|
+
var _writableNode = mathNode.getWritable();
|
|
84
|
+
_writableNode.__code = value;
|
|
71
85
|
}
|
|
72
86
|
});
|
|
73
87
|
// 延迟重置更新标志,确保更新监听器不会立即触发
|
|
74
88
|
setTimeout(function () {
|
|
75
89
|
isUpdatingRef.current = false;
|
|
76
|
-
},
|
|
90
|
+
}, 50);
|
|
77
91
|
}
|
|
78
|
-
},
|
|
92
|
+
}, 50); // 增加防抖延迟
|
|
79
93
|
|
|
80
94
|
return function () {
|
|
81
95
|
return clearTimeout(timeoutId);
|
|
@@ -87,9 +101,10 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
87
101
|
if (!mathNode) return;
|
|
88
102
|
var lexicalEditor = editor.getLexicalEditor();
|
|
89
103
|
if (lexicalEditor) {
|
|
90
|
-
//
|
|
104
|
+
// 提交时若当前不可渲染,则使用最近一次成功渲染的内容
|
|
105
|
+
var codeToCommit = isInputValidRef.current ? value : lastValidRef.current;
|
|
91
106
|
lexicalEditor.dispatchCommand(UPDATE_MATH_COMMAND, {
|
|
92
|
-
code:
|
|
107
|
+
code: codeToCommit,
|
|
93
108
|
key: mathNode.getKey()
|
|
94
109
|
});
|
|
95
110
|
}
|
|
@@ -180,6 +195,8 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
180
195
|
// 只有在不是同一个节点或值真正改变时才更新 value
|
|
181
196
|
if (!isSameNode && node.code !== value) {
|
|
182
197
|
setValue(node.code);
|
|
198
|
+
lastValidRef.current = node.code; // 切换节点时以节点里的内容作为最近一次有效值
|
|
199
|
+
isInputValidRef.current = true; // 重置有效状态
|
|
183
200
|
}
|
|
184
201
|
setMathDOM(editor.getElementByKey(node.getKey()));
|
|
185
202
|
setIsBlockMode(node instanceof MathBlockNode);
|
|
@@ -211,6 +228,8 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
211
228
|
setMathNode(null);
|
|
212
229
|
setMathDOM(null);
|
|
213
230
|
setValue('');
|
|
231
|
+
lastValidRef.current = '';
|
|
232
|
+
isInputValidRef.current = true;
|
|
214
233
|
setIsBlockMode(false);
|
|
215
234
|
setIsOpen(false);
|
|
216
235
|
}
|
|
@@ -226,16 +245,49 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
226
245
|
onCancel: handleCancel,
|
|
227
246
|
onDelete: handleDelete,
|
|
228
247
|
onSubmit: handleSubmit,
|
|
248
|
+
onValidationChange: function onValidationChange(isValid) {
|
|
249
|
+
isInputValidRef.current = isValid;
|
|
250
|
+
if (isValid) {
|
|
251
|
+
lastValidRef.current = value;
|
|
252
|
+
}
|
|
253
|
+
},
|
|
229
254
|
onValueChange: setValue,
|
|
230
255
|
prev: prev,
|
|
231
256
|
value: value
|
|
232
257
|
});
|
|
233
258
|
|
|
259
|
+
// 点击编辑器外部时关闭面板
|
|
260
|
+
useEffect(function () {
|
|
261
|
+
if (!isOpen) return;
|
|
262
|
+
var handlePointerDown = function handlePointerDown(event) {
|
|
263
|
+
var target = event.target;
|
|
264
|
+
if (!target) return;
|
|
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;
|
|
271
|
+
handleCancel();
|
|
272
|
+
};
|
|
273
|
+
document.addEventListener('mousedown', handlePointerDown);
|
|
274
|
+
document.addEventListener('touchstart', handlePointerDown);
|
|
275
|
+
return function () {
|
|
276
|
+
document.removeEventListener('mousedown', handlePointerDown);
|
|
277
|
+
document.removeEventListener('touchstart', handlePointerDown);
|
|
278
|
+
};
|
|
279
|
+
}, [isOpen, handleCancel]);
|
|
280
|
+
|
|
234
281
|
// 如果有自定义渲染组件,使用它来包装 MathEditorContent
|
|
235
282
|
if (renderComp) {
|
|
283
|
+
// 为自定义渲染的内容增加容器标记,便于外部点击检测
|
|
284
|
+
var wrapped = /*#__PURE__*/_jsx("div", {
|
|
285
|
+
"data-math-editor-container": true,
|
|
286
|
+
children: mathEditorContent
|
|
287
|
+
});
|
|
236
288
|
return /*#__PURE__*/_jsx(_Fragment, {
|
|
237
289
|
children: renderComp({
|
|
238
|
-
children:
|
|
290
|
+
children: wrapped,
|
|
239
291
|
open: isOpen
|
|
240
292
|
})
|
|
241
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 时,隐藏容器
|
|
@@ -51,6 +66,10 @@ export var MathEditorContainer = /*#__PURE__*/memo(function (_ref) {
|
|
|
51
66
|
}, [mathDOM]);
|
|
52
67
|
return /*#__PURE__*/_jsx(Block, {
|
|
53
68
|
className: styles.mathEditor,
|
|
69
|
+
"data-math-editor-container": true,
|
|
70
|
+
onClick: function onClick(e) {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
},
|
|
54
73
|
ref: divRef,
|
|
55
74
|
shadow: true,
|
|
56
75
|
variant: 'outlined',
|
|
@@ -23,6 +23,7 @@ export var MathEditorContent = /*#__PURE__*/memo(function (_ref) {
|
|
|
23
23
|
onCancel = _ref.onCancel,
|
|
24
24
|
onDelete = _ref.onDelete,
|
|
25
25
|
onSubmit = _ref.onSubmit,
|
|
26
|
+
onValidationChange = _ref.onValidationChange,
|
|
26
27
|
onValueChange = _ref.onValueChange,
|
|
27
28
|
prev = _ref.prev,
|
|
28
29
|
value = _ref.value;
|
|
@@ -57,6 +58,7 @@ export var MathEditorContent = /*#__PURE__*/memo(function (_ref) {
|
|
|
57
58
|
var isEmpty = !value.trim();
|
|
58
59
|
if (isEmpty) {
|
|
59
60
|
setLatexError('');
|
|
61
|
+
onValidationChange === null || onValidationChange === void 0 || onValidationChange(true); // 空值视为有效
|
|
60
62
|
return;
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -67,18 +69,20 @@ export var MathEditorContent = /*#__PURE__*/memo(function (_ref) {
|
|
|
67
69
|
displayMode: true,
|
|
68
70
|
throwOnError: true
|
|
69
71
|
});
|
|
70
|
-
//
|
|
72
|
+
// 验证成功:清除错误,通知父组件验证通过
|
|
71
73
|
setLatexError('');
|
|
74
|
+
onValidationChange === null || onValidationChange === void 0 || onValidationChange(true);
|
|
72
75
|
} catch (error) {
|
|
73
|
-
//
|
|
76
|
+
// 验证失败:设置错误信息,通知父组件验证失败
|
|
74
77
|
var errorMessage = error instanceof Error ? error.message : 'LaTeX Parse Error';
|
|
75
78
|
setLatexError(errorMessage);
|
|
79
|
+
onValidationChange === null || onValidationChange === void 0 || onValidationChange(false);
|
|
76
80
|
}
|
|
77
81
|
}, 50);
|
|
78
82
|
return function () {
|
|
79
83
|
return clearTimeout(timeoutId);
|
|
80
84
|
};
|
|
81
|
-
}, [value, mathNode]);
|
|
85
|
+
}, [value, mathNode, onValidationChange]);
|
|
82
86
|
var handleKeyDown = useCallback(function (e) {
|
|
83
87
|
if (!mathNode) return;
|
|
84
88
|
if (isModifierMatch(e, CONTROL_OR_META) && e.key === 'Enter') {
|
|
@@ -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
|
};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
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); }
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
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; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3
9
|
import { ActionIcon, Dropdown } from '@lobehub/ui';
|
|
4
10
|
import { memo } from 'react';
|
|
5
11
|
import ActionRender from "./ActionRender";
|
|
@@ -44,9 +50,9 @@ var ActionItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
44
50
|
size: 20
|
|
45
51
|
},
|
|
46
52
|
title: item.label,
|
|
47
|
-
tooltipProps: {
|
|
53
|
+
tooltipProps: _objectSpread({
|
|
48
54
|
placement: 'top'
|
|
49
|
-
}
|
|
55
|
+
}, item.tooltipProps)
|
|
50
56
|
})
|
|
51
57
|
}, item.key);
|
|
52
58
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
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 = ["wrapper", "icon", "key", "label", "onClick", "danger", "loading", "active", "tooltipProps"];
|
|
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
|
+
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
|
+
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; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
2
8
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
3
9
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
10
|
import { ActionIcon } from '@lobehub/ui';
|
|
@@ -30,6 +36,7 @@ var ActionRender = /*#__PURE__*/memo(function (_ref) {
|
|
|
30
36
|
danger = _ref2.danger,
|
|
31
37
|
loading = _ref2.loading,
|
|
32
38
|
active = _ref2.active,
|
|
39
|
+
tooltipProps = _ref2.tooltipProps,
|
|
33
40
|
itemRest = _objectWithoutProperties(_ref2, _excluded);
|
|
34
41
|
if (item.children && /*#__PURE__*/isValidElement(item.children)) {
|
|
35
42
|
if (!wrapper) return item.children;
|
|
@@ -54,9 +61,9 @@ var ActionRender = /*#__PURE__*/memo(function (_ref) {
|
|
|
54
61
|
size: 20
|
|
55
62
|
},
|
|
56
63
|
title: label,
|
|
57
|
-
tooltipProps: {
|
|
64
|
+
tooltipProps: _objectSpread({
|
|
58
65
|
placement: 'top'
|
|
59
|
-
}
|
|
66
|
+
}, tooltipProps)
|
|
60
67
|
});
|
|
61
68
|
if (!wrapper) return action;
|
|
62
69
|
return wrapper(action);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MenuInfo, MenuItemType } from '@lobehub/ui';
|
|
1
|
+
import type { MenuInfo, MenuItemType, TooltipProps } from '@lobehub/ui';
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
import type { FlexboxProps } from 'react-layout-kit';
|
|
4
4
|
export type ChatInputActionEvent = Pick<MenuInfo, 'key' | 'keyPath' | 'domEvent'>;
|
|
@@ -6,6 +6,7 @@ export interface ActionItem extends MenuItemType {
|
|
|
6
6
|
active?: boolean;
|
|
7
7
|
alwaysDisplay?: boolean;
|
|
8
8
|
children?: ReactNode;
|
|
9
|
+
tooltipProps?: TooltipProps;
|
|
9
10
|
wrapper?: (dom: ReactNode) => ReactNode;
|
|
10
11
|
}
|
|
11
12
|
export type DividerItem = {
|
|
@@ -15,8 +15,8 @@ import { INSERT_CODEINLINE_COMMAND } from "../../../plugins/code";
|
|
|
15
15
|
import { $isSelectionInCodeInline } from "../../../plugins/code/node/code";
|
|
16
16
|
import { UPDATE_CODEBLOCK_LANG } from "../../../plugins/codeblock";
|
|
17
17
|
import { $isRootTextContentEmpty } from "../../../plugins/common/utils";
|
|
18
|
-
import { $isLinkNode, TOGGLE_LINK_COMMAND } from "../../../plugins/link/node/LinkNode";
|
|
19
|
-
import { sanitizeUrl } from "../../../plugins/link/utils";
|
|
18
|
+
import { $isLinkNode, TOGGLE_LINK_COMMAND, formatUrl } from "../../../plugins/link/node/LinkNode";
|
|
19
|
+
import { extractUrlFromText, sanitizeUrl, validateUrl } from "../../../plugins/link/utils";
|
|
20
20
|
import { INSERT_CHECK_LIST_COMMAND } from "../../../plugins/list";
|
|
21
21
|
import { $createMathBlockNode, $createMathInlineNode } from "../../../plugins/math/node";
|
|
22
22
|
import { $findTopLevelElement, formatParagraph, getSelectedNode } from "./utils";
|
|
@@ -238,19 +238,55 @@ export function useEditorState(editor) {
|
|
|
238
238
|
});
|
|
239
239
|
}, [editor, isCodeblock]);
|
|
240
240
|
var insertLink = useCallback(function () {
|
|
241
|
+
var lexical = editor === null || editor === void 0 ? void 0 : editor.getLexicalEditor();
|
|
242
|
+
if (!lexical) return;
|
|
241
243
|
if (!isLink) {
|
|
242
|
-
var
|
|
244
|
+
var nextUrl = sanitizeUrl('https://');
|
|
245
|
+
var expandTo = null;
|
|
246
|
+
lexical.getEditorState().read(function () {
|
|
247
|
+
var selection = $getSelection();
|
|
248
|
+
if ($isRangeSelection(selection)) {
|
|
249
|
+
var text = selection.getTextContent();
|
|
250
|
+
if (!selection.isCollapsed()) {
|
|
251
|
+
var maybeUrl = formatUrl(text.trim());
|
|
252
|
+
if (validateUrl(maybeUrl)) {
|
|
253
|
+
nextUrl = maybeUrl;
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
var lineText = selection.anchor.getNode().getTextContent();
|
|
257
|
+
var found = extractUrlFromText(lineText);
|
|
258
|
+
if (found && validateUrl(formatUrl(found.url))) {
|
|
259
|
+
expandTo = {
|
|
260
|
+
index: found.index,
|
|
261
|
+
length: found.length
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
});
|
|
243
267
|
setIsLink(true);
|
|
244
|
-
|
|
268
|
+
console.log(nextUrl);
|
|
269
|
+
lexical.update(function () {
|
|
270
|
+
if (expandTo) {
|
|
271
|
+
var selection = $getSelection();
|
|
272
|
+
if ($isRangeSelection(selection)) {
|
|
273
|
+
var anchorNode = selection.anchor.getNode();
|
|
274
|
+
// Move selection to the URL range within the current text node
|
|
275
|
+
selection.anchor.set(anchorNode.getKey(), expandTo.index, 'text');
|
|
276
|
+
selection.focus.set(anchorNode.getKey(), expandTo.index + expandTo.length, 'text');
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
console.log(nextUrl);
|
|
280
|
+
lexical.dispatchCommand(TOGGLE_LINK_COMMAND, validateUrl(nextUrl) ? nextUrl : sanitizeUrl('https://'));
|
|
281
|
+
});
|
|
245
282
|
} else {
|
|
246
|
-
var _editor$getLexicalEdi5;
|
|
247
283
|
setIsLink(false);
|
|
248
|
-
|
|
284
|
+
lexical.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
249
285
|
}
|
|
250
286
|
}, [editor, isLink]);
|
|
251
287
|
var insertMath = useCallback(function () {
|
|
252
|
-
var _editor$
|
|
253
|
-
editor === null || editor === void 0 || (_editor$
|
|
288
|
+
var _editor$getLexicalEdi4;
|
|
289
|
+
editor === null || editor === void 0 || (_editor$getLexicalEdi4 = editor.getLexicalEditor()) === null || _editor$getLexicalEdi4 === void 0 || _editor$getLexicalEdi4.update(function () {
|
|
254
290
|
var selection = $getSelection();
|
|
255
291
|
if ($isRangeSelection(selection)) {
|
|
256
292
|
// 检查当前上下文来决定插入行内还是块级数学公式
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { CommandListenerPriority } from 'lexical';
|
|
2
|
+
export declare const KeyEnum: {
|
|
3
|
+
readonly Alt: "alt";
|
|
4
|
+
readonly Backquote: "backquote";
|
|
5
|
+
readonly Backslash: "backslash";
|
|
6
|
+
readonly Backspace: "backspace";
|
|
7
|
+
readonly BracketLeft: "bracketleft";
|
|
8
|
+
readonly BracketRight: "bracketright";
|
|
9
|
+
readonly Comma: "comma";
|
|
10
|
+
readonly Ctrl: "ctrl";
|
|
11
|
+
readonly Down: "down";
|
|
12
|
+
readonly Enter: "enter";
|
|
13
|
+
readonly Equal: "equal";
|
|
14
|
+
readonly Esc: "esc";
|
|
15
|
+
readonly Left: "left";
|
|
16
|
+
readonly LeftClick: "left-click";
|
|
17
|
+
readonly LeftDoubleClick: "left-double-click";
|
|
18
|
+
readonly Meta: "meta";
|
|
19
|
+
readonly MiddleClick: "middle-click";
|
|
20
|
+
readonly Minus: "minus";
|
|
21
|
+
readonly Mod: "mod";
|
|
22
|
+
readonly Number: "1-9";
|
|
23
|
+
readonly Period: "period";
|
|
24
|
+
readonly Plus: "equal";
|
|
25
|
+
readonly QuestionMark: "slash";
|
|
26
|
+
readonly Quote: "quote";
|
|
27
|
+
readonly Right: "right";
|
|
28
|
+
readonly RightClick: "right-click";
|
|
29
|
+
readonly RightDoubleClick: "right-double-click";
|
|
30
|
+
readonly Semicolon: "semicolon";
|
|
31
|
+
readonly Shift: "shift";
|
|
32
|
+
readonly Slash: "slash";
|
|
33
|
+
readonly Space: "space";
|
|
34
|
+
readonly Tab: "tab";
|
|
35
|
+
readonly Up: "up";
|
|
36
|
+
readonly Zero: "0";
|
|
37
|
+
};
|
|
38
|
+
export declare const HotkeyEnum: {
|
|
39
|
+
readonly Bold: "bold";
|
|
40
|
+
readonly BulletList: "bulletList";
|
|
41
|
+
readonly CodeInline: "codeInline";
|
|
42
|
+
readonly Italic: "italic";
|
|
43
|
+
readonly Link: "link";
|
|
44
|
+
readonly Mention: "mention";
|
|
45
|
+
readonly NumberList: "numberList";
|
|
46
|
+
readonly Redo: "redo";
|
|
47
|
+
readonly Slash: "slash";
|
|
48
|
+
readonly Strikethrough: "strikethrough";
|
|
49
|
+
readonly Underline: "underline";
|
|
50
|
+
readonly Undo: "undo";
|
|
51
|
+
};
|
|
52
|
+
export declare const HotkeyScopeEnum: {
|
|
53
|
+
readonly Format: "format";
|
|
54
|
+
readonly Insert: "insert";
|
|
55
|
+
readonly Plugin: "plugin";
|
|
56
|
+
readonly Slash: "slash";
|
|
57
|
+
};
|
|
58
|
+
export type HotkeyId = (typeof HotkeyEnum)[keyof typeof HotkeyEnum];
|
|
59
|
+
export type HotkeyScopeId = (typeof HotkeyScopeEnum)[keyof typeof HotkeyScopeEnum];
|
|
60
|
+
export interface HotkeyItem {
|
|
61
|
+
id: HotkeyId;
|
|
62
|
+
keys: string;
|
|
63
|
+
priority: CommandListenerPriority;
|
|
64
|
+
scopes?: HotkeyScopeId[];
|
|
65
|
+
}
|
|
66
|
+
export type ModifierCombination = {
|
|
67
|
+
altKey?: boolean;
|
|
68
|
+
ctrlKey?: boolean;
|
|
69
|
+
metaKey?: boolean;
|
|
70
|
+
shiftKey?: boolean;
|
|
71
|
+
} | Record<string, never>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export var KeyEnum = {
|
|
2
|
+
Alt: 'alt',
|
|
3
|
+
Backquote: 'backquote',
|
|
4
|
+
// `
|
|
5
|
+
Backslash: 'backslash',
|
|
6
|
+
// \
|
|
7
|
+
Backspace: 'backspace',
|
|
8
|
+
BracketLeft: 'bracketleft',
|
|
9
|
+
// [
|
|
10
|
+
BracketRight: 'bracketright',
|
|
11
|
+
// ]
|
|
12
|
+
Comma: 'comma',
|
|
13
|
+
// ,
|
|
14
|
+
Ctrl: 'ctrl',
|
|
15
|
+
Down: 'down',
|
|
16
|
+
Enter: 'enter',
|
|
17
|
+
Equal: 'equal',
|
|
18
|
+
// =
|
|
19
|
+
Esc: 'esc',
|
|
20
|
+
Left: 'left',
|
|
21
|
+
LeftClick: 'left-click',
|
|
22
|
+
LeftDoubleClick: 'left-double-click',
|
|
23
|
+
Meta: 'meta',
|
|
24
|
+
// Command on Mac, Win on Win
|
|
25
|
+
MiddleClick: 'middle-click',
|
|
26
|
+
Minus: 'minus',
|
|
27
|
+
// -
|
|
28
|
+
Mod: 'mod',
|
|
29
|
+
Number: '1-9',
|
|
30
|
+
// Command on Mac, Ctrl on Win
|
|
31
|
+
Period: 'period',
|
|
32
|
+
// .
|
|
33
|
+
Plus: 'equal',
|
|
34
|
+
// +
|
|
35
|
+
QuestionMark: 'slash',
|
|
36
|
+
// ?
|
|
37
|
+
Quote: 'quote',
|
|
38
|
+
// '
|
|
39
|
+
Right: 'right',
|
|
40
|
+
RightClick: 'right-click',
|
|
41
|
+
RightDoubleClick: 'right-double-click',
|
|
42
|
+
Semicolon: 'semicolon',
|
|
43
|
+
// ;
|
|
44
|
+
Shift: 'shift',
|
|
45
|
+
Slash: 'slash',
|
|
46
|
+
// /
|
|
47
|
+
Space: 'space',
|
|
48
|
+
Tab: 'tab',
|
|
49
|
+
Up: 'up',
|
|
50
|
+
Zero: '0'
|
|
51
|
+
};
|
|
52
|
+
export var HotkeyEnum = {
|
|
53
|
+
Bold: 'bold',
|
|
54
|
+
BulletList: 'bulletList',
|
|
55
|
+
CodeInline: 'codeInline',
|
|
56
|
+
Italic: 'italic',
|
|
57
|
+
Link: 'link',
|
|
58
|
+
Mention: 'mention',
|
|
59
|
+
NumberList: 'numberList',
|
|
60
|
+
Redo: 'redo',
|
|
61
|
+
Slash: 'slash',
|
|
62
|
+
Strikethrough: 'strikethrough',
|
|
63
|
+
Underline: 'underline',
|
|
64
|
+
Undo: 'undo'
|
|
65
|
+
};
|
|
66
|
+
export var HotkeyScopeEnum = {
|
|
67
|
+
Format: 'format',
|
|
68
|
+
Insert: 'insert',
|
|
69
|
+
Plugin: 'plugin',
|
|
70
|
+
Slash: 'slash'
|
|
71
|
+
};
|