@lobehub/editor 1.25.0 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- 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";
|
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