@lobehub/editor 1.25.0 → 1.26.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/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/plugins/image/react/components/Image.d.ts +6 -3
- package/es/plugins/image/react/components/Image.js +34 -118
- package/es/plugins/image/react/components/ResizeHandle.d.ts +10 -0
- package/es/plugins/image/react/components/ResizeHandle.js +75 -0
- package/es/plugins/image/react/components/style.d.ts +5 -38
- package/es/plugins/image/react/components/style.js +11 -39
- package/es/plugins/image/react/style.d.ts +2 -19
- package/es/plugins/image/react/style.js +6 -20
- package/es/plugins/link/index.d.ts +1 -0
- package/es/plugins/link/index.js +2 -1
- package/es/plugins/link/plugin/index.js +3 -0
- package/es/plugins/link/react/ReactLinkPlugin.js +20 -2
- package/es/plugins/link/react/components/LinkToolbar.d.ts +1 -0
- package/es/plugins/link/react/components/LinkToolbar.js +4 -2
- package/es/plugins/link/service/i-link-service.d.ts +11 -0
- package/es/plugins/link/service/i-link-service.js +46 -0
- package/es/plugins/toolbar/index.d.ts +1 -0
- package/es/plugins/toolbar/index.js +1 -0
- package/es/plugins/toolbar/react/index.d.ts +3 -0
- package/es/plugins/toolbar/react/index.js +80 -0
- package/es/plugins/toolbar/react/style.d.ts +1 -0
- package/es/plugins/toolbar/react/style.js +9 -0
- package/es/plugins/toolbar/react/type.d.ts +5 -0
- package/es/plugins/toolbar/react/type.js +1 -0
- package/es/plugins/toolbar/utils/getDOMRangeRect.d.ts +8 -0
- package/es/plugins/toolbar/utils/getDOMRangeRect.js +21 -0
- package/es/plugins/toolbar/utils/setFloatingElemPosition.d.ts +1 -0
- package/es/plugins/toolbar/utils/setFloatingElemPosition.js +54 -0
- package/es/react/ChatInput/style.js +3 -2
- package/package.json +1 -1
package/es/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from './plugins/math';
|
|
|
15
15
|
export * from './plugins/mention';
|
|
16
16
|
export * from './plugins/slash';
|
|
17
17
|
export * from './plugins/table';
|
|
18
|
+
export * from './plugins/toolbar';
|
|
18
19
|
export * from './plugins/upload';
|
|
19
20
|
export type { IEditor } from './types';
|
|
20
21
|
export * from './types/hotkey';
|
package/es/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export * from "./plugins/math";
|
|
|
15
15
|
export * from "./plugins/mention";
|
|
16
16
|
export * from "./plugins/slash";
|
|
17
17
|
export * from "./plugins/table";
|
|
18
|
+
export * from "./plugins/toolbar";
|
|
18
19
|
export * from "./plugins/upload";
|
|
19
20
|
// Hotkey utilities
|
|
20
21
|
export * from "./types/hotkey";
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { BlockImageNode } from '../../node/block-image-node';
|
|
3
3
|
import { ImageNode } from '../../node/image-node';
|
|
4
|
-
|
|
5
|
-
className?: string
|
|
4
|
+
export interface ImageProps {
|
|
5
|
+
className?: string;
|
|
6
6
|
node: ImageNode | BlockImageNode;
|
|
7
|
-
|
|
7
|
+
/** Whether to show scale info when resizing. Defaults to false */
|
|
8
|
+
showScaleInfo?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const Image: React.NamedExoticComponent<ImageProps>;
|
|
8
11
|
export default Image;
|
|
@@ -1,15 +1,9 @@
|
|
|
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
1
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
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."); }
|
|
4
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); }
|
|
5
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; }
|
|
6
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; } }
|
|
7
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
-
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; }
|
|
9
|
-
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; }
|
|
10
|
-
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; }
|
|
11
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
-
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); }
|
|
13
7
|
import { COMMAND_PRIORITY_LOW, SELECTION_CHANGE_COMMAND } from 'lexical';
|
|
14
8
|
import React, { memo, useCallback, useMemo, useRef, useState } from 'react';
|
|
15
9
|
import { useLexicalEditor } from "../../../../editor-kernel/react/useLexicalEditor";
|
|
@@ -17,110 +11,16 @@ import { useLexicalNodeSelection } from "../../../../editor-kernel/react/useLexi
|
|
|
17
11
|
import { $isBlockImageNode } from "../../node/block-image-node";
|
|
18
12
|
import BrokenImage from "./BrokenImage";
|
|
19
13
|
import LazyImage from "./LazyImage";
|
|
14
|
+
import { ResizeHandle } from "./ResizeHandle";
|
|
20
15
|
import { useStyles } from "./style";
|
|
21
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
17
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
23
18
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
isBlock = _ref.isBlock,
|
|
30
|
-
imageRef = _ref.imageRef;
|
|
31
|
-
var startWidthRef = useRef(0);
|
|
32
|
-
var handleMouseDown = useCallback(function (e) {
|
|
33
|
-
var _imageRef$current;
|
|
34
|
-
e.preventDefault();
|
|
35
|
-
e.stopPropagation();
|
|
36
|
-
|
|
37
|
-
// Get the actual current width at mousedown time
|
|
38
|
-
var initialWidth = ((_imageRef$current = imageRef.current) === null || _imageRef$current === void 0 ? void 0 : _imageRef$current.offsetWidth) || 0;
|
|
39
|
-
startWidthRef.current = initialWidth;
|
|
40
|
-
|
|
41
|
-
// Notify parent component of the initial width
|
|
42
|
-
onResizeStart(initialWidth);
|
|
43
|
-
var startX = e.clientX;
|
|
44
|
-
var startY = e.clientY;
|
|
45
|
-
var rect = isBlock ? e.target.getBoundingClientRect() : {
|
|
46
|
-
height: 0,
|
|
47
|
-
left: 0,
|
|
48
|
-
top: 0,
|
|
49
|
-
width: 0
|
|
50
|
-
};
|
|
51
|
-
var centerX = rect.left + rect.width / 2;
|
|
52
|
-
var lastDeltaX = 0;
|
|
53
|
-
var lastDeltaY = 0;
|
|
54
|
-
var handleMouseMove = function handleMouseMove(e) {
|
|
55
|
-
var deltaX = e.clientX - startX;
|
|
56
|
-
var deltaY = e.clientY - startY;
|
|
57
|
-
|
|
58
|
-
// Only adjust deltaX based on the resize handle position
|
|
59
|
-
switch (position) {
|
|
60
|
-
case 'left':
|
|
61
|
-
{
|
|
62
|
-
deltaX = isBlock ? centerX - e.clientX : -deltaX;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
case 'right':
|
|
66
|
-
{
|
|
67
|
-
if (isBlock) {
|
|
68
|
-
deltaX = e.clientX - centerX;
|
|
69
|
-
}
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
lastDeltaX = deltaX;
|
|
74
|
-
lastDeltaY = deltaY;
|
|
75
|
-
onResize(deltaX, deltaY, position);
|
|
76
|
-
};
|
|
77
|
-
var handleMouseUp = function handleMouseUp() {
|
|
78
|
-
document.removeEventListener('mousemove', handleMouseMove);
|
|
79
|
-
document.removeEventListener('mouseup', handleMouseUp);
|
|
80
|
-
if (typeof onResizeEnd === 'function') {
|
|
81
|
-
onResizeEnd(lastDeltaX, lastDeltaY);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
document.addEventListener('mousemove', handleMouseMove);
|
|
85
|
-
document.addEventListener('mouseup', handleMouseUp);
|
|
86
|
-
}, [onResize, onResizeEnd, onResizeStart, position, imageRef]);
|
|
87
|
-
var getPositionStyle = function getPositionStyle() {
|
|
88
|
-
var baseStyle = {
|
|
89
|
-
backgroundColor: '#999999',
|
|
90
|
-
borderRadius: 2,
|
|
91
|
-
cursor: 'col-resize',
|
|
92
|
-
height: '60%',
|
|
93
|
-
opacity: 0.6,
|
|
94
|
-
pointerEvents: 'auto',
|
|
95
|
-
position: 'absolute',
|
|
96
|
-
top: '20%',
|
|
97
|
-
width: 4,
|
|
98
|
-
zIndex: 9999
|
|
99
|
-
};
|
|
100
|
-
switch (position) {
|
|
101
|
-
case 'left':
|
|
102
|
-
{
|
|
103
|
-
return _objectSpread(_objectSpread({}, baseStyle), {}, {
|
|
104
|
-
left: 20
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
case 'right':
|
|
108
|
-
{
|
|
109
|
-
return _objectSpread(_objectSpread({}, baseStyle), {}, {
|
|
110
|
-
right: 20
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
return /*#__PURE__*/_jsx("div", {
|
|
116
|
-
onMouseDown: handleMouseDown,
|
|
117
|
-
style: getPositionStyle()
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
ResizeHandle.displayName = 'ResizeHandle';
|
|
121
|
-
var Image = /*#__PURE__*/memo(function (_ref2) {
|
|
122
|
-
var node = _ref2.node,
|
|
123
|
-
className = _ref2.className;
|
|
19
|
+
var Image = /*#__PURE__*/memo(function (_ref) {
|
|
20
|
+
var node = _ref.node,
|
|
21
|
+
className = _ref.className,
|
|
22
|
+
_ref$showScaleInfo = _ref.showScaleInfo,
|
|
23
|
+
showScaleInfo = _ref$showScaleInfo === void 0 ? false : _ref$showScaleInfo;
|
|
124
24
|
var _useStyles = useStyles(),
|
|
125
25
|
styles = _useStyles.styles,
|
|
126
26
|
cx = _useStyles.cx;
|
|
@@ -128,21 +28,25 @@ var Image = /*#__PURE__*/memo(function (_ref2) {
|
|
|
128
28
|
_useLexicalNodeSelect2 = _slicedToArray(_useLexicalNodeSelect, 2),
|
|
129
29
|
isSelected = _useLexicalNodeSelect2[0],
|
|
130
30
|
setSelected = _useLexicalNodeSelect2[1];
|
|
131
|
-
var _useState = useState(
|
|
31
|
+
var _useState = useState(false),
|
|
132
32
|
_useState2 = _slicedToArray(_useState, 2),
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
var _useState3 = useState(
|
|
33
|
+
isHovered = _useState2[0],
|
|
34
|
+
setIsHovered = _useState2[1];
|
|
35
|
+
var _useState3 = useState(1),
|
|
36
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
37
|
+
scale = _useState4[0],
|
|
38
|
+
setScale = _useState4[1];
|
|
39
|
+
var _useState5 = useState({
|
|
136
40
|
height: 0,
|
|
137
41
|
width: 0
|
|
138
42
|
}),
|
|
139
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
140
|
-
size = _useState4[0],
|
|
141
|
-
setSize = _useState4[1];
|
|
142
|
-
var _useState5 = useState(null),
|
|
143
43
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
144
|
-
|
|
145
|
-
|
|
44
|
+
size = _useState6[0],
|
|
45
|
+
setSize = _useState6[1];
|
|
46
|
+
var _useState7 = useState(null),
|
|
47
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
48
|
+
newWidth = _useState8[0],
|
|
49
|
+
setNewWidth = _useState8[1];
|
|
146
50
|
var imageRef = useRef(null);
|
|
147
51
|
var originalSizeRef = useRef({
|
|
148
52
|
height: 0,
|
|
@@ -227,6 +131,16 @@ var Image = /*#__PURE__*/memo(function (_ref2) {
|
|
|
227
131
|
}
|
|
228
132
|
});
|
|
229
133
|
}, []);
|
|
134
|
+
|
|
135
|
+
// Mouse enter handler
|
|
136
|
+
var handleMouseEnter = useCallback(function () {
|
|
137
|
+
setIsHovered(true);
|
|
138
|
+
}, []);
|
|
139
|
+
|
|
140
|
+
// Mouse leave handler
|
|
141
|
+
var handleMouseLeave = useCallback(function () {
|
|
142
|
+
setIsHovered(false);
|
|
143
|
+
}, []);
|
|
230
144
|
var children = useMemo(function () {
|
|
231
145
|
switch (node.status) {
|
|
232
146
|
case 'error':
|
|
@@ -289,14 +203,16 @@ var Image = /*#__PURE__*/memo(function (_ref2) {
|
|
|
289
203
|
draggable: false,
|
|
290
204
|
onClick: handleClick,
|
|
291
205
|
onDoubleClick: handleDoubleClick,
|
|
206
|
+
onMouseEnter: handleMouseEnter,
|
|
207
|
+
onMouseLeave: handleMouseLeave,
|
|
292
208
|
ref: imageRef,
|
|
293
209
|
style: {
|
|
294
210
|
width: size.width || 'auto'
|
|
295
211
|
},
|
|
296
|
-
children: [children, isSelected && scale !== 1 && /*#__PURE__*/_jsxs("div", {
|
|
212
|
+
children: [children, showScaleInfo && isSelected && scale !== 1 && /*#__PURE__*/_jsxs("div", {
|
|
297
213
|
className: styles.scaleInfo,
|
|
298
214
|
children: [Math.round(scale * 100), "%"]
|
|
299
|
-
}),
|
|
215
|
+
}), isHovered && /*#__PURE__*/_jsxs(_Fragment, {
|
|
300
216
|
children: [/*#__PURE__*/_jsx(ResizeHandle, {
|
|
301
217
|
imageRef: imageRef,
|
|
302
218
|
isBlock: isBlock,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
export interface ResizeHandleProps {
|
|
3
|
+
imageRef: RefObject<HTMLDivElement | null>;
|
|
4
|
+
isBlock: boolean;
|
|
5
|
+
onResize: (deltaX: number, deltaY: number, position: 'left' | 'right') => void;
|
|
6
|
+
onResizeEnd?: (deltaX: number, deltaY: number) => void;
|
|
7
|
+
onResizeStart: (initialWidth: number) => void;
|
|
8
|
+
position: 'left' | 'right';
|
|
9
|
+
}
|
|
10
|
+
export declare const ResizeHandle: import("react").NamedExoticComponent<ResizeHandleProps>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { memo, useCallback, useRef } from 'react';
|
|
2
|
+
import { useStyles } from "./style";
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
export var ResizeHandle = /*#__PURE__*/memo(function (_ref) {
|
|
5
|
+
var imageRef = _ref.imageRef,
|
|
6
|
+
isBlock = _ref.isBlock,
|
|
7
|
+
onResize = _ref.onResize,
|
|
8
|
+
onResizeEnd = _ref.onResizeEnd,
|
|
9
|
+
onResizeStart = _ref.onResizeStart,
|
|
10
|
+
position = _ref.position;
|
|
11
|
+
var _useStyles = useStyles(),
|
|
12
|
+
styles = _useStyles.styles,
|
|
13
|
+
cx = _useStyles.cx;
|
|
14
|
+
var startWidthRef = useRef(0);
|
|
15
|
+
var handleMouseDown = useCallback(function (e) {
|
|
16
|
+
var _imageRef$current;
|
|
17
|
+
e.preventDefault();
|
|
18
|
+
e.stopPropagation();
|
|
19
|
+
|
|
20
|
+
// Get the actual current width at mousedown time
|
|
21
|
+
var initialWidth = ((_imageRef$current = imageRef.current) === null || _imageRef$current === void 0 ? void 0 : _imageRef$current.offsetWidth) || 0;
|
|
22
|
+
startWidthRef.current = initialWidth;
|
|
23
|
+
|
|
24
|
+
// Notify parent component of the initial width
|
|
25
|
+
onResizeStart(initialWidth);
|
|
26
|
+
var startX = e.clientX;
|
|
27
|
+
var startY = e.clientY;
|
|
28
|
+
var rect = isBlock ? e.target.getBoundingClientRect() : {
|
|
29
|
+
height: 0,
|
|
30
|
+
left: 0,
|
|
31
|
+
top: 0,
|
|
32
|
+
width: 0
|
|
33
|
+
};
|
|
34
|
+
var centerX = rect.left + rect.width / 2;
|
|
35
|
+
var lastDeltaX = 0;
|
|
36
|
+
var lastDeltaY = 0;
|
|
37
|
+
var handleMouseMove = function handleMouseMove(e) {
|
|
38
|
+
var deltaX = e.clientX - startX;
|
|
39
|
+
var deltaY = e.clientY - startY;
|
|
40
|
+
|
|
41
|
+
// Only adjust deltaX based on the resize handle position
|
|
42
|
+
switch (position) {
|
|
43
|
+
case 'left':
|
|
44
|
+
{
|
|
45
|
+
deltaX = isBlock ? centerX - e.clientX : -deltaX;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case 'right':
|
|
49
|
+
{
|
|
50
|
+
if (isBlock) {
|
|
51
|
+
deltaX = e.clientX - centerX;
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
lastDeltaX = deltaX;
|
|
57
|
+
lastDeltaY = deltaY;
|
|
58
|
+
onResize(deltaX, deltaY, position);
|
|
59
|
+
};
|
|
60
|
+
var handleMouseUp = function handleMouseUp() {
|
|
61
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
62
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
63
|
+
if (typeof onResizeEnd === 'function') {
|
|
64
|
+
onResizeEnd(lastDeltaX, lastDeltaY);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
68
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
69
|
+
}, [imageRef, isBlock, onResize, onResizeEnd, onResizeStart, position]);
|
|
70
|
+
return /*#__PURE__*/_jsx("div", {
|
|
71
|
+
className: cx(styles.resizeHandle, position === 'left' ? styles.resizeHandleLeft : styles.resizeHandleRight),
|
|
72
|
+
onMouseDown: handleMouseDown
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
ResizeHandle.displayName = 'ResizeHandle';
|
|
@@ -1,40 +1,7 @@
|
|
|
1
1
|
export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
|
|
2
|
-
imageContainer:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
'&.selected::after': {
|
|
8
|
-
backgroundColor: "rgba(0, 102, 255, 0.15)";
|
|
9
|
-
bottom: number;
|
|
10
|
-
content: "\"\"";
|
|
11
|
-
left: number;
|
|
12
|
-
pointerEvents: "none";
|
|
13
|
-
position: "absolute";
|
|
14
|
-
right: number;
|
|
15
|
-
top: number;
|
|
16
|
-
zIndex: number;
|
|
17
|
-
};
|
|
18
|
-
cursor: "default";
|
|
19
|
-
display: "inline-block";
|
|
20
|
-
height: string;
|
|
21
|
-
maxWidth: string;
|
|
22
|
-
outline: string;
|
|
23
|
-
position: "relative";
|
|
24
|
-
transition: "border-color 0.2s ease";
|
|
25
|
-
userSelect: "none";
|
|
26
|
-
width: string;
|
|
27
|
-
};
|
|
28
|
-
scaleInfo: {
|
|
29
|
-
backgroundColor: "rgba(0, 0, 0, 0.7)";
|
|
30
|
-
borderRadius: number;
|
|
31
|
-
color: "white";
|
|
32
|
-
fontSize: number;
|
|
33
|
-
left: number;
|
|
34
|
-
padding: string;
|
|
35
|
-
pointerEvents: "none";
|
|
36
|
-
position: "absolute";
|
|
37
|
-
top: number;
|
|
38
|
-
zIndex: number;
|
|
39
|
-
};
|
|
2
|
+
imageContainer: import("antd-style").SerializedStyles;
|
|
3
|
+
resizeHandle: import("antd-style").SerializedStyles;
|
|
4
|
+
resizeHandleLeft: import("antd-style").SerializedStyles;
|
|
5
|
+
resizeHandleRight: import("antd-style").SerializedStyles;
|
|
6
|
+
scaleInfo: import("antd-style").SerializedStyles;
|
|
40
7
|
}>;
|
|
@@ -1,43 +1,15 @@
|
|
|
1
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
|
|
2
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
1
3
|
import { createStyles } from 'antd-style';
|
|
2
|
-
|
|
4
|
+
import { rgba } from 'polished';
|
|
5
|
+
export var useStyles = createStyles(function (_ref) {
|
|
6
|
+
var css = _ref.css,
|
|
7
|
+
token = _ref.token;
|
|
3
8
|
return {
|
|
4
|
-
imageContainer: {
|
|
5
|
-
'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
'&.selected::after': {
|
|
10
|
-
backgroundColor: 'rgba(0, 102, 255, 0.15)',
|
|
11
|
-
bottom: 0,
|
|
12
|
-
content: '""',
|
|
13
|
-
left: 0,
|
|
14
|
-
pointerEvents: 'none',
|
|
15
|
-
position: 'absolute',
|
|
16
|
-
right: 0,
|
|
17
|
-
top: 0,
|
|
18
|
-
zIndex: 10
|
|
19
|
-
},
|
|
20
|
-
'cursor': 'default',
|
|
21
|
-
'display': 'inline-block',
|
|
22
|
-
'height': 'auto',
|
|
23
|
-
'maxWidth': '100%',
|
|
24
|
-
'outline': '2px solid transparent',
|
|
25
|
-
'position': 'relative',
|
|
26
|
-
'transition': 'border-color 0.2s ease',
|
|
27
|
-
'userSelect': 'none',
|
|
28
|
-
'width': 'auto'
|
|
29
|
-
},
|
|
30
|
-
scaleInfo: {
|
|
31
|
-
backgroundColor: 'rgba(0, 0, 0, 0.7)',
|
|
32
|
-
borderRadius: 3,
|
|
33
|
-
color: 'white',
|
|
34
|
-
fontSize: 12,
|
|
35
|
-
left: 0,
|
|
36
|
-
padding: '2px 6px',
|
|
37
|
-
pointerEvents: 'none',
|
|
38
|
-
position: 'absolute',
|
|
39
|
-
top: -25,
|
|
40
|
-
zIndex: 11
|
|
41
|
-
}
|
|
9
|
+
imageContainer: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: default;\n user-select: none;\n\n position: relative;\n\n overflow: hidden;\n display: inline-block;\n\n width: auto;\n max-width: 100%;\n height: auto;\n border-radius: ", "px;\n\n transition: border-color 0.2s ease;\n\n &.selected {\n cursor: pointer;\n outline: none;\n\n &::after {\n pointer-events: none;\n content: '';\n\n position: absolute;\n z-index: 10;\n inset: 0;\n\n background-color: ", ";\n }\n }\n "])), token.borderRadiusSM, rgba(token.yellow, 0.1)),
|
|
10
|
+
resizeHandle: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n pointer-events: auto;\n cursor: col-resize;\n\n position: absolute;\n z-index: 9999;\n inset-block-start: 0;\n\n width: 6px;\n height: 100%;\n\n &::after {\n pointer-events: none;\n content: '';\n\n position: absolute;\n inset-block-start: 50%;\n inset-inline-start: 0;\n transform: translateY(-50%);\n\n width: 6px;\n height: min(80px, 80%);\n border: 1px solid rgba(255, 255, 255, 75%);\n border-radius: 3px;\n\n background-color: rgba(0, 0, 0, 50%);\n }\n "]))),
|
|
11
|
+
resizeHandleLeft: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n inset-inline-start: 8px;\n "]))),
|
|
12
|
+
resizeHandleRight: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n inset-inline-end: 8px;\n "]))),
|
|
13
|
+
scaleInfo: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n pointer-events: none;\n\n position: absolute;\n z-index: 11;\n inset-block-start: 2px;\n inset-inline-start: 2px;\n\n padding-block: 2px;\n padding-inline: 6px;\n border-radius: ", "px;\n\n font-size: 12px;\n color: white;\n\n background-color: rgba(0, 0, 0, 50%);\n "])), token.borderRadiusSM)
|
|
42
14
|
};
|
|
43
15
|
});
|
|
@@ -1,22 +1,5 @@
|
|
|
1
1
|
export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
|
|
2
|
-
image:
|
|
3
|
-
|
|
4
|
-
position: "relative";
|
|
5
|
-
display: "inline-block";
|
|
6
|
-
cursor: "default";
|
|
7
|
-
'&.selected': {
|
|
8
|
-
backgroundColor: string;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
blockImage: {
|
|
12
|
-
userSelect: "none";
|
|
13
|
-
position: "relative";
|
|
14
|
-
display: "block";
|
|
15
|
-
textAlign: "center";
|
|
16
|
-
cursor: "default";
|
|
17
|
-
'&.selected': {
|
|
18
|
-
backgroundColor: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
2
|
+
image: import("antd-style").SerializedStyles;
|
|
3
|
+
blockImage: import("antd-style").SerializedStyles;
|
|
21
4
|
}>;
|
|
22
5
|
export declare const imageBroken = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9IjAgMCA2NDAgNDAwIj48cGF0aCBmaWxsPSIjM0IzQjNCIiBkPSJNMCAwaDY0MHY0MDBIMHoiLz48cGF0aCBzdHJva2U9IiM2MjYyNjIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIxNSIgZD0iTTM3Mi41IDEzMi41aC0xMDVjLTguMjg0IDAtMTUgNi43MTYtMTUgMTV2MTA1YzAgOC4yODQgNi43MTYgMTUgMTUgMTVoMTA1YzguMjg0IDAgMTUtNi43MTYgMTUtMTV2LTEwNWMwLTguMjg0LTYuNzE2LTE1LTE1LTE1eiIvPjxwYXRoIHN0cm9rZT0iIzYyNjI2MiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2Utd2lkdGg9IjE1IiBkPSJNMjk3LjUgMTkyLjVjOC4yODQgMCAxNS02LjcxNiAxNS0xNSAwLTguMjg0LTYuNzE2LTE1LTE1LTE1LTguMjg0IDAtMTUgNi43MTYtMTUgMTUgMCA4LjI4NCA2LjcxNiAxNSAxNSAxNXpNMzg3LjUgMjIyLjUwMmwtMjMuMTQ1LTIzLjE0NWExNS4wMDEgMTUuMDAxIDAgMDAtMjEuMjEgMEwyNzUgMjY3LjUwMiIvPjwvc3ZnPg==";
|
|
@@ -1,27 +1,13 @@
|
|
|
1
|
+
var _templateObject, _templateObject2;
|
|
2
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
1
3
|
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
2
4
|
import { createStyles } from 'antd-style';
|
|
3
5
|
export var useStyles = createStyles(function (_ref) {
|
|
4
|
-
var
|
|
6
|
+
var css = _ref.css,
|
|
7
|
+
token = _ref.token;
|
|
5
8
|
return {
|
|
6
|
-
image: {
|
|
7
|
-
|
|
8
|
-
'position': 'relative',
|
|
9
|
-
'display': 'inline-block',
|
|
10
|
-
'cursor': 'default',
|
|
11
|
-
'&.selected': {
|
|
12
|
-
backgroundColor: token.colorPrimaryBg
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
blockImage: {
|
|
16
|
-
'userSelect': 'none',
|
|
17
|
-
'position': 'relative',
|
|
18
|
-
'display': 'block',
|
|
19
|
-
'textAlign': 'center',
|
|
20
|
-
'cursor': 'default',
|
|
21
|
-
'&.selected': {
|
|
22
|
-
backgroundColor: token.colorPrimaryBg
|
|
23
|
-
}
|
|
24
|
-
}
|
|
9
|
+
image: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: default;\n user-select: none;\n position: relative;\n display: inline-block;\n\n &.selected {\n background-color: ", ";\n }\n "])), token.colorPrimaryBg),
|
|
10
|
+
blockImage: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n cursor: default;\n user-select: none;\n\n position: relative;\n\n display: block;\n\n text-align: center;\n\n &.selected {\n background-color: ", ";\n }\n "])), token.colorPrimaryBg)
|
|
25
11
|
};
|
|
26
12
|
});
|
|
27
13
|
export var imageBroken = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9IjAgMCA2NDAgNDAwIj48cGF0aCBmaWxsPSIjM0IzQjNCIiBkPSJNMCAwaDY0MHY0MDBIMHoiLz48cGF0aCBzdHJva2U9IiM2MjYyNjIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIxNSIgZD0iTTM3Mi41IDEzMi41aC0xMDVjLTguMjg0IDAtMTUgNi43MTYtMTUgMTV2MTA1YzAgOC4yODQgNi43MTYgMTUgMTUgMTVoMTA1YzguMjg0IDAgMTUtNi43MTYgMTUtMTV2LTEwNWMwLTguMjg0LTYuNzE2LTE1LTE1LTE1eiIvPjxwYXRoIHN0cm9rZT0iIzYyNjI2MiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2Utd2lkdGg9IjE1IiBkPSJNMjk3LjUgMTkyLjVjOC4yODQgMCAxNS02LjcxNiAxNS0xNSAwLTguMjg0LTYuNzE2LTE1LTE1LTE1LTguMjg0IDAtMTUgNi43MTYtMTUgMTUgMCA4LjI4NCA2LjcxNiAxNSAxNSAxNXpNMzg3LjUgMjIyLjUwMmwtMjMuMTQ1LTIzLjE0NWExNS4wMDEgMTUuMDAxIDAgMDAtMjEuMjEgMEwyNzUgMjY3LjUwMiIvPjwvc3ZnPg==';
|
package/es/plugins/link/index.js
CHANGED
|
@@ -25,6 +25,7 @@ import { KernelPlugin } from "../../../editor-kernel/plugin";
|
|
|
25
25
|
import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
|
|
26
26
|
import { INSERT_LINK_COMMAND, registerLinkCommand } from "../command";
|
|
27
27
|
import { $createLinkNode, $isLinkNode, AutoLinkNode, LinkNode } from "../node/LinkNode";
|
|
28
|
+
import { ILinkService, LinkService } from "../service/i-link-service";
|
|
28
29
|
import { registerLinkCommands } from "./registry";
|
|
29
30
|
export var LinkPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
30
31
|
_inherits(LinkPlugin, _KernelPlugin);
|
|
@@ -35,9 +36,11 @@ export var LinkPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
35
36
|
_this = _super.call(this);
|
|
36
37
|
// Register the link nodes
|
|
37
38
|
_defineProperty(_assertThisInitialized(_this), "linkRegex", /^https?:\/\/\S+$/);
|
|
39
|
+
_defineProperty(_assertThisInitialized(_this), "service", new LinkService());
|
|
38
40
|
_this.kernel = kernel;
|
|
39
41
|
_this.config = config;
|
|
40
42
|
kernel.registerNodes([LinkNode, AutoLinkNode]);
|
|
43
|
+
kernel.registerService(ILinkService, _this.service);
|
|
41
44
|
if (config !== null && config !== void 0 && config.theme) {
|
|
42
45
|
kernel.registerThemes(config.theme);
|
|
43
46
|
}
|
|
@@ -6,11 +6,13 @@ 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 { useLayoutEffect } from 'react';
|
|
9
|
+
import { useLayoutEffect, useState } from 'react';
|
|
10
|
+
import { useLexicalEditor } from "../../../editor-kernel/react";
|
|
10
11
|
import PortalAnchor from "../../../editor-kernel/react/PortalAnchor";
|
|
11
12
|
import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
|
|
12
13
|
import { MarkdownPlugin } from "../../markdown/plugin";
|
|
13
14
|
import { LinkPlugin } from "../plugin";
|
|
15
|
+
import { ILinkService } from "../service/i-link-service";
|
|
14
16
|
import LinkEdit from "./components/LinkEdit";
|
|
15
17
|
import LinkToolbar from "./components/LinkToolbar";
|
|
16
18
|
import { useStyles } from "./style";
|
|
@@ -22,6 +24,10 @@ export var ReactLinkPlugin = function ReactLinkPlugin(_ref) {
|
|
|
22
24
|
enableHotkey = _ref$enableHotkey === void 0 ? true : _ref$enableHotkey,
|
|
23
25
|
validateUrl = _ref.validateUrl,
|
|
24
26
|
attributes = _ref.attributes;
|
|
27
|
+
var _useState = useState(false),
|
|
28
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
29
|
+
enableToolbar = _useState2[0],
|
|
30
|
+
setEnableToolbar = _useState2[1];
|
|
25
31
|
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
26
32
|
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
27
33
|
editor = _useLexicalComposerCo2[0];
|
|
@@ -36,9 +42,21 @@ export var ReactLinkPlugin = function ReactLinkPlugin(_ref) {
|
|
|
36
42
|
validateUrl: validateUrl
|
|
37
43
|
});
|
|
38
44
|
}, [attributes, enableHotkey, styles, theme, validateUrl]);
|
|
45
|
+
useLexicalEditor(function () {
|
|
46
|
+
var linkService = editor.requireService(ILinkService);
|
|
47
|
+
setEnableToolbar(linkService.enableLinkToolbar);
|
|
48
|
+
var handleChange = function handleChange() {
|
|
49
|
+
setEnableToolbar(linkService.enableLinkToolbar);
|
|
50
|
+
};
|
|
51
|
+
linkService.on('linkToolbarChange', handleChange);
|
|
52
|
+
return function () {
|
|
53
|
+
linkService.off('linkToolbarChange', handleChange);
|
|
54
|
+
};
|
|
55
|
+
}, []);
|
|
39
56
|
return /*#__PURE__*/_jsxs(PortalAnchor, {
|
|
40
57
|
children: [/*#__PURE__*/_jsx(LinkToolbar, {
|
|
41
|
-
editor: editor.getLexicalEditor()
|
|
58
|
+
editor: editor.getLexicalEditor(),
|
|
59
|
+
enable: enableToolbar
|
|
42
60
|
}), /*#__PURE__*/_jsx(LinkEdit, {
|
|
43
61
|
editor: editor.getLexicalEditor()
|
|
44
62
|
})]
|
|
@@ -20,7 +20,8 @@ import { useStyles } from "../style";
|
|
|
20
20
|
import { EDIT_LINK_COMMAND } from "./LinkEdit";
|
|
21
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
22
|
var LinkToolbar = /*#__PURE__*/memo(function (_ref) {
|
|
23
|
-
var editor = _ref.editor
|
|
23
|
+
var editor = _ref.editor,
|
|
24
|
+
enable = _ref.enable;
|
|
24
25
|
var divRef = useRef(null);
|
|
25
26
|
var LinkRef = useRef(null);
|
|
26
27
|
var _useStyles = useStyles(),
|
|
@@ -123,6 +124,7 @@ var LinkToolbar = /*#__PURE__*/memo(function (_ref) {
|
|
|
123
124
|
state.current.isLink = false;
|
|
124
125
|
}
|
|
125
126
|
}), editor.registerCommand(HOVER_LINK_COMMAND, function (payload) {
|
|
127
|
+
if (!enable) return false;
|
|
126
128
|
if (!payload.event.target || divRef.current === null) return false;
|
|
127
129
|
// Cancel any pending hide timers when hovering a link again
|
|
128
130
|
clearTimeout(clearTimerRef.current);
|
|
@@ -141,7 +143,7 @@ var LinkToolbar = /*#__PURE__*/memo(function (_ref) {
|
|
|
141
143
|
clearTimerRef.current = setTimeout(handleCancel, 300);
|
|
142
144
|
return true;
|
|
143
145
|
}, COMMAND_PRIORITY_NORMAL));
|
|
144
|
-
}, [editable]);
|
|
146
|
+
}, [enable, editable]);
|
|
145
147
|
return /*#__PURE__*/_jsx(ActionIconGroup, {
|
|
146
148
|
className: styles.linkToolbar,
|
|
147
149
|
items: [{
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
import { IServiceID } from "../../../types";
|
|
3
|
+
export interface ILinkService {
|
|
4
|
+
setLinkToolbar(enable: boolean): void;
|
|
5
|
+
}
|
|
6
|
+
export declare const ILinkService: IServiceID<ILinkService>;
|
|
7
|
+
export declare class LinkService extends EventEmitter<'linkToolbarChange'> implements ILinkService {
|
|
8
|
+
private _enableLinkToolbar;
|
|
9
|
+
get enableLinkToolbar(): boolean;
|
|
10
|
+
setLinkToolbar(enable: boolean): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
6
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
7
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
8
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
9
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
10
|
+
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; } }
|
|
11
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
12
|
+
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; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
14
|
+
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); }
|
|
15
|
+
/* eslint-disable no-redeclare */
|
|
16
|
+
/* eslint-disable @typescript-eslint/no-redeclare */
|
|
17
|
+
import EventEmitter from 'eventemitter3';
|
|
18
|
+
import { genServiceId } from "../../../editor-kernel";
|
|
19
|
+
export var ILinkService = genServiceId('LinkService');
|
|
20
|
+
export var LinkService = /*#__PURE__*/function (_EventEmitter) {
|
|
21
|
+
_inherits(LinkService, _EventEmitter);
|
|
22
|
+
var _super = _createSuper(LinkService);
|
|
23
|
+
function LinkService() {
|
|
24
|
+
var _this;
|
|
25
|
+
_classCallCheck(this, LinkService);
|
|
26
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
27
|
+
args[_key] = arguments[_key];
|
|
28
|
+
}
|
|
29
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
30
|
+
_defineProperty(_assertThisInitialized(_this), "_enableLinkToolbar", true);
|
|
31
|
+
return _this;
|
|
32
|
+
}
|
|
33
|
+
_createClass(LinkService, [{
|
|
34
|
+
key: "enableLinkToolbar",
|
|
35
|
+
get: function get() {
|
|
36
|
+
return this._enableLinkToolbar;
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
key: "setLinkToolbar",
|
|
40
|
+
value: function setLinkToolbar(enable) {
|
|
41
|
+
this._enableLinkToolbar = enable;
|
|
42
|
+
this.emit('linkToolbarChange', enable);
|
|
43
|
+
}
|
|
44
|
+
}]);
|
|
45
|
+
return LinkService;
|
|
46
|
+
}(EventEmitter);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './react';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./react";
|
|
@@ -0,0 +1,80 @@
|
|
|
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 { mergeRegister } from '@lexical/utils';
|
|
8
|
+
import { Block } from '@lobehub/ui';
|
|
9
|
+
import { $getSelection, COMMAND_PRIORITY_LOW, SELECTION_CHANGE_COMMAND, getDOMSelection } from 'lexical';
|
|
10
|
+
import { useCallback, useRef } from 'react';
|
|
11
|
+
import { useLexicalComposerContext, useLexicalEditor } from "../../../editor-kernel/react";
|
|
12
|
+
import { ILinkService } from "../../link";
|
|
13
|
+
import { getDOMRangeRect } from "../utils/getDOMRangeRect";
|
|
14
|
+
import { setFloatingElemPosition } from "../utils/setFloatingElemPosition";
|
|
15
|
+
import { useStyles } from "./style";
|
|
16
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
+
export var ReactToolbarPlugin = function ReactToolbarPlugin(_ref) {
|
|
18
|
+
var className = _ref.className,
|
|
19
|
+
children = _ref.children;
|
|
20
|
+
var popupCharStylesEditorRef = useRef(null);
|
|
21
|
+
var anchorElemRef = useRef(null);
|
|
22
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
23
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
24
|
+
kernelEditor = _useLexicalComposerCo2[0];
|
|
25
|
+
var _useStyles = useStyles(),
|
|
26
|
+
cx = _useStyles.cx,
|
|
27
|
+
styles = _useStyles.styles;
|
|
28
|
+
var $updateTextFormatFloatingToolbar = useCallback(function (editor) {
|
|
29
|
+
if (!anchorElemRef.current) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
var selection = $getSelection();
|
|
33
|
+
var popupCharStylesEditorElem = popupCharStylesEditorRef.current;
|
|
34
|
+
var nativeSelection = getDOMSelection(editor._window);
|
|
35
|
+
if (popupCharStylesEditorElem === null) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
var rootElement = editor.getRootElement();
|
|
39
|
+
if (selection !== null && nativeSelection !== null && !nativeSelection.isCollapsed && rootElement !== null && rootElement.contains(nativeSelection.anchorNode)) {
|
|
40
|
+
var rangeRect = getDOMRangeRect(nativeSelection, rootElement);
|
|
41
|
+
setFloatingElemPosition(rangeRect, popupCharStylesEditorElem, anchorElemRef.current, false);
|
|
42
|
+
} else {
|
|
43
|
+
popupCharStylesEditorElem.style.opacity = '0';
|
|
44
|
+
popupCharStylesEditorElem.style.transform = 'translate(-10000px, -10000px)';
|
|
45
|
+
}
|
|
46
|
+
}, [anchorElemRef]);
|
|
47
|
+
useLexicalEditor(function () {
|
|
48
|
+
var service = kernelEditor.requireService(ILinkService);
|
|
49
|
+
if (service) {
|
|
50
|
+
service.setLinkToolbar(false);
|
|
51
|
+
return function () {
|
|
52
|
+
service.setLinkToolbar(true);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}, []);
|
|
56
|
+
useLexicalEditor(function (editor) {
|
|
57
|
+
return mergeRegister(editor.registerUpdateListener(function (_ref2) {
|
|
58
|
+
var editorState = _ref2.editorState;
|
|
59
|
+
editorState.read(function () {
|
|
60
|
+
$updateTextFormatFloatingToolbar(editor);
|
|
61
|
+
});
|
|
62
|
+
}), editor.registerCommand(SELECTION_CHANGE_COMMAND, function () {
|
|
63
|
+
$updateTextFormatFloatingToolbar(editor);
|
|
64
|
+
return false;
|
|
65
|
+
}, COMMAND_PRIORITY_LOW));
|
|
66
|
+
});
|
|
67
|
+
return /*#__PURE__*/_jsx("div", {
|
|
68
|
+
ref: anchorElemRef,
|
|
69
|
+
style: {
|
|
70
|
+
position: 'relative'
|
|
71
|
+
},
|
|
72
|
+
children: /*#__PURE__*/_jsx(Block, {
|
|
73
|
+
className: cx(styles, className),
|
|
74
|
+
padding: 4,
|
|
75
|
+
ref: popupCharStylesEditorRef,
|
|
76
|
+
variant: 'outlined',
|
|
77
|
+
children: children
|
|
78
|
+
})
|
|
79
|
+
});
|
|
80
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<import("antd-style").SerializedStyles>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var _templateObject;
|
|
2
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
|
+
import { createStyles } from 'antd-style';
|
|
4
|
+
export var useStyles = createStyles(function (_ref) {
|
|
5
|
+
var css = _ref.css,
|
|
6
|
+
token = _ref.token,
|
|
7
|
+
isDarkMode = _ref.isDarkMode;
|
|
8
|
+
return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n will-change: transform;\n\n position: absolute;\n z-index: 10;\n inset-block-start: 0;\n inset-inline-start: 0;\n transform: translate(-10000px, -10000px);\n\n display: flex;\n\n border-color: ", ";\n\n vertical-align: middle;\n\n opacity: 0;\n background: ", ";\n box-shadow: ", ";\n\n transition: opacity 0.12s ", ";\n "])), token.colorFillSecondary, token.colorBgElevated, isDarkMode ? '0px 14px 28px -6px #0003,0px 2px 4px -1px #0000001f' : '0 14px 28px -6px #0000001a, 0 2px 4px -1px #0000000f', token.motionEaseOut);
|
|
9
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export declare function getDOMRangeRect(nativeSelection: Selection, rootElement: HTMLElement): DOMRect;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export function getDOMRangeRect(nativeSelection, rootElement) {
|
|
9
|
+
var domRange = nativeSelection.getRangeAt(0);
|
|
10
|
+
var rect;
|
|
11
|
+
if (nativeSelection.anchorNode === rootElement) {
|
|
12
|
+
var inner = rootElement;
|
|
13
|
+
while (inner.firstElementChild !== null) {
|
|
14
|
+
inner = inner.firstElementChild;
|
|
15
|
+
}
|
|
16
|
+
rect = inner.getBoundingClientRect();
|
|
17
|
+
} else {
|
|
18
|
+
rect = domRange.getBoundingClientRect();
|
|
19
|
+
}
|
|
20
|
+
return rect;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setFloatingElemPosition(targetRect: DOMRect | null, floatingElem: HTMLElement, anchorElem: HTMLElement, isLink?: boolean, verticalGap?: number, horizontalOffset?: number): void;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
var VERTICAL_GAP = 4;
|
|
9
|
+
var HORIZONTAL_OFFSET = 0;
|
|
10
|
+
export function setFloatingElemPosition(targetRect, floatingElem, anchorElem) {
|
|
11
|
+
var isLink = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
12
|
+
var verticalGap = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : VERTICAL_GAP;
|
|
13
|
+
var horizontalOffset = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : HORIZONTAL_OFFSET;
|
|
14
|
+
var scrollerElem = anchorElem.parentElement;
|
|
15
|
+
if (targetRect === null || !scrollerElem) {
|
|
16
|
+
floatingElem.style.opacity = '0';
|
|
17
|
+
floatingElem.style.transform = 'translate(-10000px, -10000px)';
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
var floatingElemRect = floatingElem.getBoundingClientRect();
|
|
21
|
+
var anchorElementRect = anchorElem.getBoundingClientRect();
|
|
22
|
+
var editorScrollerRect = scrollerElem.getBoundingClientRect();
|
|
23
|
+
var top = targetRect.top - floatingElemRect.height - verticalGap;
|
|
24
|
+
var left = targetRect.left - horizontalOffset;
|
|
25
|
+
|
|
26
|
+
// Check if text is end-aligned
|
|
27
|
+
var selection = window.getSelection();
|
|
28
|
+
if (selection && selection.rangeCount > 0) {
|
|
29
|
+
var range = selection.getRangeAt(0);
|
|
30
|
+
var textNode = range.startContainer;
|
|
31
|
+
if (textNode.nodeType === Node.ELEMENT_NODE || textNode.parentElement) {
|
|
32
|
+
var textElement = textNode.nodeType === Node.ELEMENT_NODE ? textNode : textNode.parentElement;
|
|
33
|
+
var textAlign = window.getComputedStyle(textElement).textAlign;
|
|
34
|
+
if (textAlign === 'right' || textAlign === 'end') {
|
|
35
|
+
// For end-aligned text, position the toolbar relative to the text end
|
|
36
|
+
left = targetRect.right - floatingElemRect.width + horizontalOffset;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (top < editorScrollerRect.top) {
|
|
41
|
+
// adjusted height for link element if the element is at top
|
|
42
|
+
top += floatingElemRect.height + targetRect.height + verticalGap * (isLink ? 9 : 2);
|
|
43
|
+
}
|
|
44
|
+
if (left + floatingElemRect.width > editorScrollerRect.right) {
|
|
45
|
+
left = editorScrollerRect.right - floatingElemRect.width - horizontalOffset;
|
|
46
|
+
}
|
|
47
|
+
if (left < editorScrollerRect.left) {
|
|
48
|
+
left = editorScrollerRect.left + horizontalOffset;
|
|
49
|
+
}
|
|
50
|
+
top -= anchorElementRect.top + 12;
|
|
51
|
+
left -= anchorElementRect.left;
|
|
52
|
+
floatingElem.style.opacity = '1';
|
|
53
|
+
floatingElem.style.transform = "translate(".concat(left, "px, ").concat(top, "px)");
|
|
54
|
+
}
|
|
@@ -3,9 +3,10 @@ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(
|
|
|
3
3
|
import { createStyles } from 'antd-style';
|
|
4
4
|
export var useStyles = createStyles(function (_ref) {
|
|
5
5
|
var css = _ref.css,
|
|
6
|
-
token = _ref.token
|
|
6
|
+
token = _ref.token,
|
|
7
|
+
isDarkMode = _ref.isDarkMode;
|
|
7
8
|
return {
|
|
8
|
-
container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n\n display: flex;\n flex-direction: column;\n\n height: 100%;\n border: 1px solid ", ";\n border-radius: ", "px;\n\n background-color: ", ";\n box-shadow
|
|
9
|
+
container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n\n display: flex;\n flex-direction: column;\n\n height: 100%;\n border: 1px solid ", ";\n border-radius: ", "px;\n\n background-color: ", ";\n box-shadow: ", ";\n "])), isDarkMode ? token.colorFillSecondary : token.colorFill, token.borderRadiusLG, token.colorBgElevated, isDarkMode ? '0px 4px 4px rgba(0, 0, 0, 0.4)' : '0px 4px 4px rgba(0, 0, 0, 0.04)'),
|
|
9
10
|
editor: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n cursor: text;\n\n overflow: hidden auto;\n flex: 1;\n\n width: 100%;\n padding-block: 8px 0;\n padding-inline: 12px;\n "]))),
|
|
10
11
|
resizableContainer: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: relative;\n\n display: flex;\n flex: 1 1 auto;\n flex-direction: column;\n align-self: flex-end;\n\n width: 100%;\n\n &:hover .resize-handle {\n opacity: 1;\n }\n "]))),
|
|
11
12
|
resizeHandle: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: absolute;\n inset-block-start: -4px;\n inset-inline-start: 50%;\n transform: translateX(-50%);\n\n width: 100%;\n height: 8px;\n\n opacity: 0;\n\n transition: opacity 0.2s ease-in-out;\n\n &::before {\n content: '';\n\n position: absolute;\n inset-block-start: 0;\n inset-inline-start: 50%;\n transform: translateX(-50%);\n\n width: 32px;\n height: 4px;\n border-radius: 4px;\n\n background-color: ", ";\n box-shadow: 0 1px 2px ", "20;\n }\n\n &:hover {\n opacity: 1 !important;\n\n &::before {\n background-color: ", ";\n box-shadow: 0 2px 4px ", "40;\n }\n }\n\n &:active {\n &::before {\n background-color: ", ";\n }\n }\n "])), token.colorPrimary, token.colorTextSecondary, token.colorPrimaryHover, token.colorTextSecondary, token.colorPrimaryActive)
|
package/package.json
CHANGED