@lobehub/editor 1.8.2 → 1.8.3
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/react/PortalAnchor.d.ts +5 -0
- package/es/editor-kernel/react/PortalAnchor.js +13 -0
- package/es/editor-kernel/react/useAnchor.d.ts +1 -0
- package/es/editor-kernel/react/useAnchor.js +23 -0
- package/es/plugins/link/react/ReactLinkPlugin.js +9 -104
- package/es/plugins/link/react/components/LinkEdit.d.ts +6 -2
- package/es/plugins/link/react/components/LinkEdit.js +21 -25
- package/es/plugins/link/react/components/LinkToolbar.d.ts +1 -4
- package/es/plugins/link/react/components/LinkToolbar.js +103 -21
- package/es/plugins/math/react/{component → components}/MathEditor.js +11 -8
- package/es/plugins/math/react/{component → components}/MathEditorContainer.d.ts +2 -1
- package/es/plugins/math/react/{component → components}/MathEditorContainer.js +3 -2
- package/es/plugins/math/react/{component → components}/MathEditorContent.d.ts +2 -1
- package/es/plugins/math/react/{component → components}/MathEditorContent.js +3 -2
- package/es/plugins/math/react/index.js +2 -2
- package/es/plugins/slash/react/components/DefaultSlashMenu.d.ts +5 -0
- package/es/plugins/slash/react/components/DefaultSlashMenu.js +48 -0
- package/es/plugins/slash/react/components/SlashMenu.d.ts +2 -2
- package/es/plugins/slash/react/components/SlashMenu.js +16 -36
- package/es/plugins/table/react/TableActionMenu/ActionMenu.d.ts +18 -0
- package/es/plugins/table/react/TableActionMenu/ActionMenu.js +309 -0
- package/es/plugins/table/react/TableActionMenu/index.d.ts +2 -3
- package/es/plugins/table/react/TableActionMenu/index.js +17 -321
- package/es/plugins/table/react/TableHoverActions/index.d.ts +3 -4
- package/es/plugins/table/react/TableHoverActions/index.js +7 -20
- package/es/plugins/table/react/index.js +8 -5
- package/package.json +1 -1
- /package/es/plugins/math/react/{component → components}/MathEditor.d.ts +0 -0
- /package/es/plugins/math/react/{component → components}/MathInline.d.ts +0 -0
- /package/es/plugins/math/react/{component → components}/MathInline.js +0 -0
- /package/es/plugins/math/react/{component → components}/Placeholder.d.ts +0 -0
- /package/es/plugins/math/react/{component → components}/Placeholder.js +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { memo } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { useAnchor } from "./useAnchor";
|
|
6
|
+
var PortalAnchor = /*#__PURE__*/memo(function (_ref) {
|
|
7
|
+
var children = _ref.children;
|
|
8
|
+
var targetElement = useAnchor();
|
|
9
|
+
if (!targetElement) return null;
|
|
10
|
+
return /*#__PURE__*/createPortal(children, targetElement);
|
|
11
|
+
});
|
|
12
|
+
PortalAnchor.displayName = 'PortalAnchor';
|
|
13
|
+
export default PortalAnchor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useAnchor: () => HTMLElement | undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
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."); }
|
|
5
|
+
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); }
|
|
6
|
+
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; }
|
|
7
|
+
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; } }
|
|
8
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
|
+
import { useMemo } from 'react';
|
|
10
|
+
import { useLexicalComposerContext } from "./react-context";
|
|
11
|
+
export var useAnchor = function useAnchor() {
|
|
12
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
13
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
14
|
+
editor = _useLexicalComposerCo2[0];
|
|
15
|
+
// Don't render portal on server side
|
|
16
|
+
|
|
17
|
+
return useMemo(function () {
|
|
18
|
+
if (typeof document === 'undefined' || !editor) return;
|
|
19
|
+
var root = editor.getRootElement();
|
|
20
|
+
var anchor = root ? root.parentElement : null;
|
|
21
|
+
return anchor || document.body;
|
|
22
|
+
}, [editor]);
|
|
23
|
+
};
|
|
@@ -6,25 +6,17 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
6
6
|
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; }
|
|
7
7
|
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; } }
|
|
8
8
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_NORMAL } from 'lexical';
|
|
12
|
-
import { useLayoutEffect, useRef, useState } from 'react';
|
|
13
|
-
import { createPortal } from 'react-dom';
|
|
14
|
-
import { useLexicalEditor } from "../../../editor-kernel/react";
|
|
9
|
+
import { useLayoutEffect } from 'react';
|
|
10
|
+
import PortalAnchor from "../../../editor-kernel/react/PortalAnchor";
|
|
15
11
|
import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
|
|
16
12
|
import { MarkdownPlugin } from "../../markdown";
|
|
17
|
-
import { $isLinkNode, HOVER_LINK_COMMAND, HOVER_OUT_LINK_COMMAND } from "../node/LinkNode";
|
|
18
13
|
import { LinkPlugin } from "../plugin";
|
|
19
|
-
import
|
|
20
|
-
import LinkEdit, { EDIT_LINK_COMMAND } from "./components/LinkEdit";
|
|
14
|
+
import LinkEdit from "./components/LinkEdit";
|
|
21
15
|
import LinkToolbar from "./components/LinkToolbar";
|
|
22
16
|
import { useStyles } from "./style";
|
|
23
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
25
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
26
19
|
export var ReactLinkPlugin = function ReactLinkPlugin(_ref) {
|
|
27
|
-
var _editor$getLexicalEdi, _lexicalEditor$getRoo;
|
|
28
20
|
var theme = _ref.theme,
|
|
29
21
|
_ref$enableHotkey = _ref.enableHotkey,
|
|
30
22
|
enableHotkey = _ref$enableHotkey === void 0 ? true : _ref$enableHotkey,
|
|
@@ -33,16 +25,6 @@ export var ReactLinkPlugin = function ReactLinkPlugin(_ref) {
|
|
|
33
25
|
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
34
26
|
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
35
27
|
editor = _useLexicalComposerCo2[0];
|
|
36
|
-
var _useState = useState(null),
|
|
37
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
38
|
-
linkNode = _useState2[0],
|
|
39
|
-
setLinkNode = _useState2[1];
|
|
40
|
-
var state = useRef({
|
|
41
|
-
isLink: false
|
|
42
|
-
});
|
|
43
|
-
var divRef = useRef(null);
|
|
44
|
-
var LinkRef = useRef(null);
|
|
45
|
-
var clearTimerRef = useRef(-1);
|
|
46
28
|
var _useStyles = useStyles(),
|
|
47
29
|
styles = _useStyles.styles;
|
|
48
30
|
useLayoutEffect(function () {
|
|
@@ -54,90 +36,13 @@ export var ReactLinkPlugin = function ReactLinkPlugin(_ref) {
|
|
|
54
36
|
validateUrl: validateUrl
|
|
55
37
|
});
|
|
56
38
|
}, [attributes, enableHotkey, styles, theme, validateUrl]);
|
|
57
|
-
|
|
58
|
-
return mergeRegister(editor.registerUpdateListener(function () {
|
|
59
|
-
var selection = editor.read(function () {
|
|
60
|
-
return $getSelection();
|
|
61
|
-
});
|
|
62
|
-
if (!selection) return;
|
|
63
|
-
if ($isRangeSelection(selection)) {
|
|
64
|
-
// Update links for UI components
|
|
65
|
-
editor.read(function () {
|
|
66
|
-
var node = getSelectedNode(selection);
|
|
67
|
-
var parent = node.getParent();
|
|
68
|
-
var isLink = $isLinkNode(parent) || $isLinkNode(node);
|
|
69
|
-
state.current.isLink = isLink;
|
|
70
|
-
if (isLink) {
|
|
71
|
-
var _linkNode = $isLinkNode(parent) ? parent : node;
|
|
72
|
-
editor.dispatchCommand(EDIT_LINK_COMMAND, {
|
|
73
|
-
linkNode: _linkNode,
|
|
74
|
-
linkNodeDOM: editor.getElementByKey(_linkNode.getKey())
|
|
75
|
-
});
|
|
76
|
-
} else {
|
|
77
|
-
editor.dispatchCommand(EDIT_LINK_COMMAND, {
|
|
78
|
-
linkNode: null,
|
|
79
|
-
linkNodeDOM: null
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
} else {
|
|
84
|
-
state.current.isLink = false;
|
|
85
|
-
}
|
|
86
|
-
}), editor.registerCommand(HOVER_LINK_COMMAND, function (payload) {
|
|
87
|
-
if (!payload.event.target || divRef.current === null) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
// Cancel any pending hide timers when hovering a link again
|
|
91
|
-
clearTimeout(clearTimerRef.current);
|
|
92
|
-
setLinkNode(payload.linkNode);
|
|
93
|
-
computePosition(payload.event.target, divRef.current, {
|
|
94
|
-
middleware: [offset(5), flip(), shift()],
|
|
95
|
-
placement: 'top-start'
|
|
96
|
-
}).then(function (_ref2) {
|
|
97
|
-
var x = _ref2.x,
|
|
98
|
-
y = _ref2.y;
|
|
99
|
-
if (!payload.event.target || divRef.current === null) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
LinkRef.current = payload.event.target;
|
|
103
|
-
divRef.current.style.left = "".concat(x, "px");
|
|
104
|
-
divRef.current.style.top = "".concat(y, "px");
|
|
105
|
-
});
|
|
106
|
-
return false;
|
|
107
|
-
}, COMMAND_PRIORITY_NORMAL), editor.registerCommand(HOVER_OUT_LINK_COMMAND, function () {
|
|
108
|
-
clearTimeout(clearTimerRef.current);
|
|
109
|
-
clearTimerRef.current = setTimeout(function () {
|
|
110
|
-
if (divRef.current) {
|
|
111
|
-
divRef.current.style.left = '-9999px';
|
|
112
|
-
divRef.current.style.top = '-9999px';
|
|
113
|
-
}
|
|
114
|
-
}, 300);
|
|
115
|
-
return true;
|
|
116
|
-
}, COMMAND_PRIORITY_NORMAL));
|
|
117
|
-
}, []);
|
|
118
|
-
|
|
119
|
-
// Determine anchor element (editor inner wrapper)
|
|
120
|
-
var lexicalEditor = (_editor$getLexicalEdi = editor.getLexicalEditor) === null || _editor$getLexicalEdi === void 0 ? void 0 : _editor$getLexicalEdi.call(editor);
|
|
121
|
-
var root = lexicalEditor === null || lexicalEditor === void 0 || (_lexicalEditor$getRoo = lexicalEditor.getRootElement) === null || _lexicalEditor$getRoo === void 0 ? void 0 : _lexicalEditor$getRoo.call(lexicalEditor);
|
|
122
|
-
var anchor = root ? root.parentElement : null;
|
|
123
|
-
var targetElement = anchor || (typeof document !== 'undefined' ? document.body : null);
|
|
124
|
-
return targetElement ? /*#__PURE__*/createPortal( /*#__PURE__*/_jsxs(_Fragment, {
|
|
39
|
+
return /*#__PURE__*/_jsxs(PortalAnchor, {
|
|
125
40
|
children: [/*#__PURE__*/_jsx(LinkToolbar, {
|
|
126
|
-
editor: editor.getLexicalEditor()
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
onMouseLeave: function onMouseLeave() {
|
|
132
|
-
clearTimeout(clearTimerRef.current);
|
|
133
|
-
if (divRef.current) {
|
|
134
|
-
divRef.current.style.left = '-9999px';
|
|
135
|
-
divRef.current.style.top = '-9999px';
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
ref: divRef
|
|
139
|
-
}), /*#__PURE__*/_jsx(LinkEdit, {})]
|
|
140
|
-
}), targetElement) : null;
|
|
41
|
+
editor: editor.getLexicalEditor()
|
|
42
|
+
}), /*#__PURE__*/_jsx(LinkEdit, {
|
|
43
|
+
editor: editor.getLexicalEditor()
|
|
44
|
+
})]
|
|
45
|
+
});
|
|
141
46
|
};
|
|
142
47
|
ReactLinkPlugin.displayName = 'ReactLinkPlugin';
|
|
143
48
|
export default ReactLinkPlugin;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { LexicalEditor } from 'lexical';
|
|
2
3
|
import { LinkNode } from '../../node/LinkNode';
|
|
3
4
|
export declare const EDIT_LINK_COMMAND: import("lexical").LexicalCommand<{
|
|
4
5
|
linkNode: LinkNode | null;
|
|
5
6
|
linkNodeDOM: HTMLElement | null;
|
|
6
7
|
}>;
|
|
7
|
-
|
|
8
|
+
interface LinkEditProps {
|
|
9
|
+
editor: LexicalEditor;
|
|
10
|
+
}
|
|
11
|
+
declare const LinkEdit: import("react").NamedExoticComponent<LinkEditProps>;
|
|
8
12
|
export default LinkEdit;
|
|
@@ -9,16 +9,17 @@ import { mergeRegister } from '@lexical/utils';
|
|
|
9
9
|
import { Block, Button, Hotkey, Icon, Input, Text } from '@lobehub/ui';
|
|
10
10
|
import { COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_NORMAL, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND, createCommand } from 'lexical';
|
|
11
11
|
import { BaselineIcon, LinkIcon } from 'lucide-react';
|
|
12
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
12
|
+
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
13
13
|
import { Flexbox } from 'react-layout-kit';
|
|
14
|
-
import {
|
|
14
|
+
import { useLexicalEditor } from "../../../../editor-kernel/react";
|
|
15
15
|
import { useTranslation } from "../../../../editor-kernel/react/useTranslation";
|
|
16
16
|
import { UPDATE_LINK_TEXT_COMMAND } from "../../command";
|
|
17
17
|
import { useStyles } from "../style";
|
|
18
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
19
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
20
|
export var EDIT_LINK_COMMAND = createCommand();
|
|
21
|
-
var LinkEdit = function
|
|
21
|
+
var LinkEdit = /*#__PURE__*/memo(function (_ref) {
|
|
22
|
+
var editor = _ref.editor;
|
|
22
23
|
var divRef = useRef(null);
|
|
23
24
|
var linkNodeRef = useRef(null);
|
|
24
25
|
var linkInputRef = useRef(null);
|
|
@@ -35,9 +36,6 @@ var LinkEdit = function LinkEdit() {
|
|
|
35
36
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
36
37
|
linkDom = _useState6[0],
|
|
37
38
|
setLinkDom = _useState6[1];
|
|
38
|
-
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
39
|
-
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
40
|
-
editor = _useLexicalComposerCo2[0];
|
|
41
39
|
var t = useTranslation();
|
|
42
40
|
var _useStyles = useStyles(),
|
|
43
41
|
styles = _useStyles.styles,
|
|
@@ -45,11 +43,10 @@ var LinkEdit = function LinkEdit() {
|
|
|
45
43
|
|
|
46
44
|
// 取消编辑,不保存更改
|
|
47
45
|
var handleCancel = useCallback(function () {
|
|
48
|
-
|
|
49
|
-
if (!lexicalEditor) return;
|
|
46
|
+
if (!editor) return;
|
|
50
47
|
|
|
51
48
|
// 将焦点返回到编辑器
|
|
52
|
-
|
|
49
|
+
editor.focus();
|
|
53
50
|
|
|
54
51
|
// 隐藏编辑面板
|
|
55
52
|
if (divRef.current) {
|
|
@@ -68,9 +65,9 @@ var LinkEdit = function LinkEdit() {
|
|
|
68
65
|
computePosition(linkDom, divRef.current, {
|
|
69
66
|
middleware: [offset(8), flip(), shift()],
|
|
70
67
|
placement: 'bottom-start'
|
|
71
|
-
}).then(function (
|
|
72
|
-
var x =
|
|
73
|
-
y =
|
|
68
|
+
}).then(function (_ref2) {
|
|
69
|
+
var x = _ref2.x,
|
|
70
|
+
y = _ref2.y;
|
|
74
71
|
if (divRef.current) {
|
|
75
72
|
divRef.current.style.left = "".concat(x, "px");
|
|
76
73
|
divRef.current.style.top = "".concat(y, "px");
|
|
@@ -101,8 +98,7 @@ var LinkEdit = function LinkEdit() {
|
|
|
101
98
|
|
|
102
99
|
// 提取提交逻辑到独立函数
|
|
103
100
|
var handleSubmit = useCallback(function () {
|
|
104
|
-
|
|
105
|
-
if (!linkNodeRef.current || !linkInputRef.current || !linkTextInputRef.current || !lexicalEditor) {
|
|
101
|
+
if (!linkNodeRef.current || !linkInputRef.current || !linkTextInputRef.current || !editor) {
|
|
106
102
|
return;
|
|
107
103
|
}
|
|
108
104
|
var linkNode = linkNodeRef.current;
|
|
@@ -112,28 +108,28 @@ var LinkEdit = function LinkEdit() {
|
|
|
112
108
|
var textInputDOM = textInput.input;
|
|
113
109
|
|
|
114
110
|
// 更新链接URL
|
|
115
|
-
var currentURL =
|
|
111
|
+
var currentURL = editor.read(function () {
|
|
116
112
|
return linkNode.getURL();
|
|
117
113
|
});
|
|
118
114
|
if (currentURL !== inputDOM.value) {
|
|
119
|
-
|
|
115
|
+
editor.update(function () {
|
|
120
116
|
linkNode.setURL(inputDOM.value);
|
|
121
117
|
});
|
|
122
118
|
}
|
|
123
119
|
|
|
124
120
|
// 更新链接文本
|
|
125
|
-
var currentText =
|
|
121
|
+
var currentText = editor.read(function () {
|
|
126
122
|
return linkNode.getTextContent();
|
|
127
123
|
});
|
|
128
124
|
if (currentText !== textInputDOM.value) {
|
|
129
|
-
|
|
125
|
+
editor.dispatchCommand(UPDATE_LINK_TEXT_COMMAND, {
|
|
130
126
|
key: linkNode.getKey(),
|
|
131
127
|
text: textInputDOM.value
|
|
132
128
|
});
|
|
133
129
|
}
|
|
134
130
|
|
|
135
131
|
// 关闭编辑器并聚焦到编辑器
|
|
136
|
-
|
|
132
|
+
editor.focus();
|
|
137
133
|
|
|
138
134
|
// 隐藏编辑面板
|
|
139
135
|
if (divRef.current) {
|
|
@@ -146,8 +142,7 @@ var LinkEdit = function LinkEdit() {
|
|
|
146
142
|
setLinkDom(null);
|
|
147
143
|
}, [editor, linkNodeRef, linkInputRef, linkTextInputRef]);
|
|
148
144
|
var handleKeyDown = useCallback(function (event) {
|
|
149
|
-
|
|
150
|
-
if (!linkNodeRef.current || !linkInputRef.current || !linkTextInputRef.current || !lexicalEditor) {
|
|
145
|
+
if (!linkNodeRef.current || !linkInputRef.current || !linkTextInputRef.current || !editor) {
|
|
151
146
|
return;
|
|
152
147
|
}
|
|
153
148
|
var linkNode = linkNodeRef.current;
|
|
@@ -160,11 +155,11 @@ var LinkEdit = function LinkEdit() {
|
|
|
160
155
|
{
|
|
161
156
|
event.preventDefault();
|
|
162
157
|
if (event.currentTarget === textInputDOM) {
|
|
163
|
-
var currentText =
|
|
158
|
+
var currentText = editor.read(function () {
|
|
164
159
|
return linkNode.getTextContent();
|
|
165
160
|
});
|
|
166
161
|
if (currentText !== textInputDOM.value) {
|
|
167
|
-
|
|
162
|
+
editor.dispatchCommand(UPDATE_LINK_TEXT_COMMAND, {
|
|
168
163
|
key: linkNode.getKey(),
|
|
169
164
|
text: textInputDOM.value
|
|
170
165
|
});
|
|
@@ -186,7 +181,7 @@ var LinkEdit = function LinkEdit() {
|
|
|
186
181
|
if (event.currentTarget === textInputDOM) {
|
|
187
182
|
inputDOM.focus();
|
|
188
183
|
} else {
|
|
189
|
-
|
|
184
|
+
editor.focus();
|
|
190
185
|
}
|
|
191
186
|
return;
|
|
192
187
|
}
|
|
@@ -298,5 +293,6 @@ var LinkEdit = function LinkEdit() {
|
|
|
298
293
|
})
|
|
299
294
|
})]
|
|
300
295
|
});
|
|
301
|
-
};
|
|
296
|
+
});
|
|
297
|
+
LinkEdit.displayName = 'LinkEdit';
|
|
302
298
|
export default LinkEdit;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { type ActionIconGroupProps } from '@lobehub/ui';
|
|
3
2
|
import { LexicalEditor } from 'lexical';
|
|
4
|
-
|
|
5
|
-
interface LinkToolbarProps extends Omit<ActionIconGroupProps, 'items'> {
|
|
3
|
+
interface LinkToolbarProps {
|
|
6
4
|
editor: LexicalEditor;
|
|
7
|
-
linkNode: LinkNode | null;
|
|
8
5
|
}
|
|
9
6
|
declare const LinkToolbar: import("react").NamedExoticComponent<LinkToolbarProps>;
|
|
10
7
|
export default LinkToolbar;
|
|
@@ -1,32 +1,99 @@
|
|
|
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", "onMouseLeave"];
|
|
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); }
|
|
8
1
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
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."); }
|
|
9
4
|
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); }
|
|
10
5
|
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; }
|
|
11
|
-
function
|
|
12
|
-
function
|
|
6
|
+
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; } }
|
|
7
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
+
import { computePosition, flip, offset, shift } from '@floating-ui/dom';
|
|
9
|
+
import { mergeRegister } from '@lexical/utils';
|
|
13
10
|
import { ActionIconGroup } from '@lobehub/ui';
|
|
14
|
-
import { $createRangeSelection, $getNodeByKey, $getSelection, $isRangeSelection, $isTextNode, $setSelection } from 'lexical';
|
|
11
|
+
import { $createRangeSelection, $getNodeByKey, $getSelection, $isRangeSelection, $isTextNode, $setSelection, COMMAND_PRIORITY_NORMAL } from 'lexical';
|
|
15
12
|
import { EditIcon, ExternalLinkIcon, UnlinkIcon } from 'lucide-react';
|
|
16
|
-
import { memo, useCallback } from 'react';
|
|
13
|
+
import { memo, useCallback, useRef, useState } from 'react';
|
|
14
|
+
import { useLexicalEditor } from "../../../../editor-kernel/react";
|
|
17
15
|
import { useTranslation } from "../../../../editor-kernel/react/useTranslation";
|
|
18
|
-
import {
|
|
16
|
+
import { getSelectedNode } from "../../utils";
|
|
17
|
+
import { $isLinkNode, HOVER_LINK_COMMAND, HOVER_OUT_LINK_COMMAND, TOGGLE_LINK_COMMAND } from "../../node/LinkNode";
|
|
19
18
|
import { useStyles } from "../style";
|
|
20
19
|
import { EDIT_LINK_COMMAND } from "./LinkEdit";
|
|
21
20
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
21
|
var LinkToolbar = /*#__PURE__*/memo(function (_ref) {
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
rest = _objectWithoutProperties(_ref, _excluded);
|
|
22
|
+
var editor = _ref.editor;
|
|
23
|
+
var divRef = useRef(null);
|
|
24
|
+
var LinkRef = useRef(null);
|
|
27
25
|
var _useStyles = useStyles(),
|
|
28
26
|
styles = _useStyles.styles;
|
|
27
|
+
var _useState = useState(null),
|
|
28
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
29
|
+
linkNode = _useState2[0],
|
|
30
|
+
setLinkNode = _useState2[1];
|
|
31
|
+
var state = useRef({
|
|
32
|
+
isLink: false
|
|
33
|
+
});
|
|
29
34
|
var t = useTranslation();
|
|
35
|
+
var clearTimerRef = useRef(-1);
|
|
36
|
+
useLexicalEditor(function (editor) {
|
|
37
|
+
return mergeRegister(editor.registerUpdateListener(function () {
|
|
38
|
+
var selection = editor.read(function () {
|
|
39
|
+
return $getSelection();
|
|
40
|
+
});
|
|
41
|
+
if (!selection) return;
|
|
42
|
+
if ($isRangeSelection(selection)) {
|
|
43
|
+
// Update links for UI components
|
|
44
|
+
editor.read(function () {
|
|
45
|
+
var node = getSelectedNode(selection);
|
|
46
|
+
var parent = node.getParent();
|
|
47
|
+
var isLink = $isLinkNode(parent) || $isLinkNode(node);
|
|
48
|
+
state.current.isLink = isLink;
|
|
49
|
+
if (isLink) {
|
|
50
|
+
var _linkNode = $isLinkNode(parent) ? parent : node;
|
|
51
|
+
editor.dispatchCommand(EDIT_LINK_COMMAND, {
|
|
52
|
+
linkNode: _linkNode,
|
|
53
|
+
linkNodeDOM: editor.getElementByKey(_linkNode.getKey())
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
editor.dispatchCommand(EDIT_LINK_COMMAND, {
|
|
57
|
+
linkNode: null,
|
|
58
|
+
linkNodeDOM: null
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
state.current.isLink = false;
|
|
64
|
+
}
|
|
65
|
+
}), editor.registerCommand(HOVER_LINK_COMMAND, function (payload) {
|
|
66
|
+
if (!payload.event.target || divRef.current === null) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
// Cancel any pending hide timers when hovering a link again
|
|
70
|
+
clearTimeout(clearTimerRef.current);
|
|
71
|
+
setLinkNode(payload.linkNode);
|
|
72
|
+
computePosition(payload.event.target, divRef.current, {
|
|
73
|
+
middleware: [offset(5), flip(), shift()],
|
|
74
|
+
placement: 'top-start'
|
|
75
|
+
}).then(function (_ref2) {
|
|
76
|
+
var x = _ref2.x,
|
|
77
|
+
y = _ref2.y;
|
|
78
|
+
if (!payload.event.target || divRef.current === null) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
LinkRef.current = payload.event.target;
|
|
82
|
+
divRef.current.style.left = "".concat(x, "px");
|
|
83
|
+
divRef.current.style.top = "".concat(y, "px");
|
|
84
|
+
});
|
|
85
|
+
return false;
|
|
86
|
+
}, COMMAND_PRIORITY_NORMAL), editor.registerCommand(HOVER_OUT_LINK_COMMAND, function () {
|
|
87
|
+
clearTimeout(clearTimerRef.current);
|
|
88
|
+
clearTimerRef.current = setTimeout(function () {
|
|
89
|
+
if (divRef.current) {
|
|
90
|
+
divRef.current.style.left = '-9999px';
|
|
91
|
+
divRef.current.style.top = '-9999px';
|
|
92
|
+
}
|
|
93
|
+
}, 300);
|
|
94
|
+
return true;
|
|
95
|
+
}, COMMAND_PRIORITY_NORMAL));
|
|
96
|
+
}, []);
|
|
30
97
|
var handleEdit = useCallback(function () {
|
|
31
98
|
if (!linkNode) return;
|
|
32
99
|
editor.dispatchCommand(EDIT_LINK_COMMAND, {
|
|
@@ -79,7 +146,7 @@ var LinkToolbar = /*#__PURE__*/memo(function (_ref) {
|
|
|
79
146
|
});
|
|
80
147
|
window.open(url, '_blank');
|
|
81
148
|
}, [editor, linkNode]);
|
|
82
|
-
return /*#__PURE__*/_jsx(ActionIconGroup,
|
|
149
|
+
return /*#__PURE__*/_jsx(ActionIconGroup, {
|
|
83
150
|
className: styles.linkToolbar,
|
|
84
151
|
items: [{
|
|
85
152
|
icon: EditIcon,
|
|
@@ -95,18 +162,33 @@ var LinkToolbar = /*#__PURE__*/memo(function (_ref) {
|
|
|
95
162
|
icon: UnlinkIcon,
|
|
96
163
|
key: 'unlink',
|
|
97
164
|
label: t('link.unlink'),
|
|
98
|
-
onClick: function onClick(
|
|
165
|
+
onClick: function onClick() {
|
|
99
166
|
handleRemove();
|
|
100
|
-
|
|
167
|
+
clearTimeout(clearTimerRef.current);
|
|
168
|
+
if (divRef.current) {
|
|
169
|
+
divRef.current.style.left = '-9999px';
|
|
170
|
+
divRef.current.style.top = '-9999px';
|
|
171
|
+
}
|
|
101
172
|
}
|
|
102
173
|
}],
|
|
103
|
-
|
|
174
|
+
onMouseEnter: function onMouseEnter() {
|
|
175
|
+
clearTimeout(clearTimerRef.current);
|
|
176
|
+
},
|
|
177
|
+
onMouseLeave: function onMouseLeave() {
|
|
178
|
+
clearTimeout(clearTimerRef.current);
|
|
179
|
+
if (divRef.current) {
|
|
180
|
+
divRef.current.style.left = '-9999px';
|
|
181
|
+
divRef.current.style.top = '-9999px';
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
ref: divRef,
|
|
104
185
|
shadow: true,
|
|
105
186
|
size: {
|
|
106
187
|
blockSize: 32,
|
|
107
188
|
size: 16
|
|
108
189
|
},
|
|
109
190
|
variant: 'outlined'
|
|
110
|
-
}
|
|
191
|
+
});
|
|
111
192
|
});
|
|
193
|
+
LinkToolbar.displayName = 'LinkToolbar';
|
|
112
194
|
export default LinkToolbar;
|
|
@@ -8,10 +8,11 @@ import { mergeRegister } from '@lexical/utils';
|
|
|
8
8
|
import { $getSelection, $isElementNode, $isNodeSelection, $isRangeSelection, $isTextNode } from 'lexical';
|
|
9
9
|
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
10
10
|
import { useLexicalComposerContext, useLexicalEditor } from "../../../../editor-kernel/react";
|
|
11
|
+
import PortalAnchor from "../../../../editor-kernel/react/PortalAnchor";
|
|
11
12
|
import { SELECT_MATH_SIDE_COMMAND, UPDATE_MATH_COMMAND } from "../../command";
|
|
12
13
|
import { $isMathNode, MathBlockNode } from "../../node";
|
|
13
|
-
import
|
|
14
|
-
import
|
|
14
|
+
import MathEditorContainer from "./MathEditorContainer";
|
|
15
|
+
import MathEditorContent from "./MathEditorContent";
|
|
15
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
17
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
17
18
|
var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
@@ -294,12 +295,14 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
|
|
|
294
295
|
}
|
|
295
296
|
|
|
296
297
|
// 否则使用默认的 MathEditorContainer
|
|
297
|
-
return /*#__PURE__*/_jsx(
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
298
|
+
return /*#__PURE__*/_jsx(PortalAnchor, {
|
|
299
|
+
children: /*#__PURE__*/_jsx(MathEditorContainer, {
|
|
300
|
+
isBlockMode: isBlockMode,
|
|
301
|
+
mathDOM: mathDOM,
|
|
302
|
+
onFocus: handleFocus,
|
|
303
|
+
prev: prev,
|
|
304
|
+
children: mathEditorContent
|
|
305
|
+
})
|
|
303
306
|
});
|
|
304
307
|
});
|
|
305
308
|
export default MathEdit;
|
|
@@ -11,4 +11,5 @@ export interface MathEditorContainerProps {
|
|
|
11
11
|
/** 是否从前一个位置进入 */
|
|
12
12
|
prev: boolean;
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
declare const MathEditorContainer: import("react").NamedExoticComponent<MathEditorContainerProps>;
|
|
15
|
+
export default MathEditorContainer;
|
|
@@ -3,7 +3,7 @@ import { Block } from '@lobehub/ui';
|
|
|
3
3
|
import { memo, useEffect, useRef } from 'react';
|
|
4
4
|
import { useStyles } from "../style";
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
|
|
6
|
+
var MathEditorContainer = /*#__PURE__*/memo(function (_ref) {
|
|
7
7
|
var children = _ref.children,
|
|
8
8
|
isBlockMode = _ref.isBlockMode,
|
|
9
9
|
mathDOM = _ref.mathDOM,
|
|
@@ -76,4 +76,5 @@ export var MathEditorContainer = /*#__PURE__*/memo(function (_ref) {
|
|
|
76
76
|
children: children
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
|
-
MathEditorContainer.displayName = 'MathEditorContainer';
|
|
79
|
+
MathEditorContainer.displayName = 'MathEditorContainer';
|
|
80
|
+
export default MathEditorContainer;
|
|
@@ -25,4 +25,5 @@ export interface MathEditorContentProps {
|
|
|
25
25
|
/** 当前输入值 */
|
|
26
26
|
value: string;
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
declare const MathEditorContent: import("react").NamedExoticComponent<MathEditorContentProps>;
|
|
29
|
+
export default MathEditorContent;
|
|
@@ -15,7 +15,7 @@ import { useStyles } from "../style";
|
|
|
15
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
17
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
18
|
-
|
|
18
|
+
var MathEditorContent = /*#__PURE__*/memo(function (_ref) {
|
|
19
19
|
var focusRef = _ref.focusRef,
|
|
20
20
|
mathNode = _ref.mathNode,
|
|
21
21
|
onArrowLeft = _ref.onArrowLeft,
|
|
@@ -164,4 +164,5 @@ export var MathEditorContent = /*#__PURE__*/memo(function (_ref) {
|
|
|
164
164
|
})]
|
|
165
165
|
});
|
|
166
166
|
});
|
|
167
|
-
MathEditorContent.displayName = 'MathEditorContent';
|
|
167
|
+
MathEditorContent.displayName = 'MathEditorContent';
|
|
168
|
+
export default MathEditorContent;
|
|
@@ -10,8 +10,8 @@ import { useLayoutEffect } from 'react';
|
|
|
10
10
|
import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
|
|
11
11
|
import { MarkdownPlugin } from "../../markdown";
|
|
12
12
|
import { MathPlugin } from "../plugin";
|
|
13
|
-
import MathEdit from "./
|
|
14
|
-
import MathInline from "./
|
|
13
|
+
import MathEdit from "./components/MathEditor";
|
|
14
|
+
import MathInline from "./components/MathInline";
|
|
15
15
|
import { useStyles } from "./style";
|
|
16
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
17
|
export var ReactMathPlugin = function ReactMathPlugin(_ref) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { SlashMenuProps } from '../type';
|
|
3
|
+
type DefaultSlashMenuProps = Omit<SlashMenuProps, 'customRender' | 'onActiveKeyChange' | 'editor'>;
|
|
4
|
+
declare const DefaultSlashMenu: import("react").NamedExoticComponent<DefaultSlashMenuProps>;
|
|
5
|
+
export default DefaultSlashMenu;
|