@block-kit/plugin 1.0.6 → 1.0.8

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.
Files changed (37) hide show
  1. package/dist/es/bullet-list/index.js +1 -1
  2. package/dist/es/divider/index.js +1 -1
  3. package/dist/es/emoji/index.js +1 -1
  4. package/dist/es/font-size/index.js +2 -2
  5. package/dist/es/image/index.js +1 -1
  6. package/dist/es/image/view/image.js +2 -2
  7. package/dist/es/indent/index.js +1 -1
  8. package/dist/es/index.js +1 -1
  9. package/dist/es/inline-code/index.js +1 -1
  10. package/dist/es/link/index.js +1 -1
  11. package/dist/es/mention/modules/suggest.js +1 -1
  12. package/dist/es/order-list/index.js +1 -1
  13. package/dist/es/quote/index.js +1 -1
  14. package/dist/es/shared/components/selection.js +2 -4
  15. package/dist/es/shared/modules/selection.js +1 -1
  16. package/dist/es/shortcut/index.js +1 -1
  17. package/dist/es/toolbar/context/float.js +13 -11
  18. package/dist/lib/bullet-list/index.js +1 -1
  19. package/dist/lib/divider/index.js +1 -1
  20. package/dist/lib/emoji/index.js +1 -1
  21. package/dist/lib/font-size/index.js +1 -1
  22. package/dist/lib/image/index.js +1 -1
  23. package/dist/lib/image/view/image.js +1 -1
  24. package/dist/lib/indent/index.js +1 -1
  25. package/dist/lib/index.js +1 -1
  26. package/dist/lib/inline-code/index.js +1 -1
  27. package/dist/lib/link/index.js +1 -1
  28. package/dist/lib/mention/modules/suggest.js +1 -1
  29. package/dist/lib/order-list/index.js +1 -1
  30. package/dist/lib/quote/index.js +1 -1
  31. package/dist/lib/shared/components/selection.js +2 -4
  32. package/dist/lib/shared/modules/selection.js +1 -1
  33. package/dist/lib/shortcut/index.js +1 -1
  34. package/dist/lib/toolbar/context/float.js +12 -10
  35. package/package.json +9 -9
  36. /package/dist/es/{tslib.es6-2af4ba24.js → tslib.es6-46499da4.js} +0 -0
  37. /package/dist/lib/{tslib.es6-8deb1cdb.js → tslib.es6-d0928055.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { _ as __decorate } from '../tslib.es6-2af4ba24.js';
1
+ import { _ as __decorate } from '../tslib.es6-46499da4.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { EDITOR_EVENT, RawPoint, Point } from '@block-kit/core';
4
4
  import { Delta } from '@block-kit/delta';
@@ -1,4 +1,4 @@
1
- import { _ as __decorate } from '../tslib.es6-2af4ba24.js';
1
+ import { _ as __decorate } from '../tslib.es6-46499da4.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { Point, Range } from '@block-kit/core';
4
4
  import { Delta } from '@block-kit/delta';
@@ -1,4 +1,4 @@
1
- import { _ as __decorate } from '../tslib.es6-2af4ba24.js';
1
+ import { _ as __decorate } from '../tslib.es6-46499da4.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { RawRange } from '@block-kit/core';
4
4
  import { Delta } from '@block-kit/delta';
@@ -1,5 +1,5 @@
1
1
  import { EditorPlugin } from '@block-kit/react';
2
- import { Styles } from '@block-kit/utils';
2
+ import { Facade } from '@block-kit/utils';
3
3
  import { FONT_SIZE_KEY } from './types/index.js';
4
4
 
5
5
  class FontSizePlugin extends EditorPlugin {
@@ -19,7 +19,7 @@ class FontSizePlugin extends EditorPlugin {
19
19
  const attrs = context.attributes || {};
20
20
  const size = attrs[FONT_SIZE_KEY];
21
21
  if (size) {
22
- context.style.fontSize = Styles.pixelate(size);
22
+ context.style.fontSize = Facade.pixelate(size);
23
23
  }
24
24
  return context.children;
25
25
  }
@@ -1,4 +1,4 @@
1
- import { _ as __decorate, a as __awaiter } from '../tslib.es6-2af4ba24.js';
1
+ import { _ as __decorate, a as __awaiter } from '../tslib.es6-46499da4.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { Point, Range, RawRange, APPLY_SOURCE } from '@block-kit/core';
4
4
  import { Delta } from '@block-kit/delta';
@@ -3,7 +3,7 @@ import IconLoading from '@arco-design/web-react/icon/react-icon/IconLoading';
3
3
  import { RawRange, APPLY_SOURCE } from '@block-kit/core';
4
4
  import { Delta } from '@block-kit/delta';
5
5
  import { Void } from '@block-kit/react';
6
- import { Styles } from '@block-kit/utils';
6
+ import { Facade } from '@block-kit/utils';
7
7
  import { SelectionHOC } from '../../shared/components/selection.js';
8
8
  import { IMAGE_SRC, IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_STATUS, LOADING_STATUS, IMAGE_SCALE } from '../types/index.js';
9
9
  import { ImageWrapper } from './wrapper.js';
@@ -33,7 +33,7 @@ const ImageView = props => {
33
33
  const delta = new Delta().retain(rawRange.start).retain(rawRange.len, next);
34
34
  editor.state.apply(delta, { source: APPLY_SOURCE.NO_UNDO, autoCaret: false });
35
35
  };
36
- return (jsxs(Void, { className: "block-kit-image-container", context: context, children: [status === LOADING_STATUS.LOADING && (jsx("div", { className: "block-kit-image-loading", children: jsx(IconLoading, {}) })), jsx(SelectionHOC, { selection: selection, leaf: context.leafState, children: jsx(ImageWrapper, { editor: props.editor, src: src, leaf: context.leafState, children: jsx("img", { className: "block-kit-image", src: src, onLoad: onImageLoad, width: Styles.pixelate(width), height: Styles.pixelate(height) }) }) })] }));
36
+ return (jsxs(Void, { className: "block-kit-image-container", context: context, children: [status === LOADING_STATUS.LOADING && (jsx("div", { className: "block-kit-image-loading", children: jsx(IconLoading, {}) })), jsx(SelectionHOC, { selection: selection, leaf: context.leafState, children: jsx(ImageWrapper, { editor: props.editor, src: src, leaf: context.leafState, children: jsx("img", { className: "block-kit-image", src: src, onLoad: onImageLoad, width: Facade.pixelate(width), height: Facade.pixelate(height) }) }) })] }));
37
37
  };
38
38
 
39
39
  export { ImageView };
@@ -1,4 +1,4 @@
1
- import { _ as __decorate } from '../tslib.es6-2af4ba24.js';
1
+ import { _ as __decorate } from '../tslib.es6-46499da4.js';
2
2
  import { EDITOR_EVENT, RawPoint, Point } from '@block-kit/core';
3
3
  import { Delta } from '@block-kit/delta';
4
4
  import { EditorPlugin } from '@block-kit/react';
package/dist/es/index.js CHANGED
@@ -49,6 +49,6 @@ export { UNDERLINE_KEY } from './underline/types/index.js';
49
49
  export { FloatToolbar } from './toolbar/context/float.js';
50
50
  export { Toolbar } from './toolbar/context/basic.js';
51
51
 
52
- const BLOCK_KIT_VERSION = "1.0.6" ;
52
+ const BLOCK_KIT_VERSION = "1.0.8" ;
53
53
 
54
54
  export { BLOCK_KIT_VERSION };
@@ -1,4 +1,4 @@
1
- import { _ as __decorate } from '../tslib.es6-2af4ba24.js';
1
+ import { _ as __decorate } from '../tslib.es6-46499da4.js';
2
2
  import { Priority } from '@block-kit/core';
3
3
  import { EditorPlugin } from '@block-kit/react';
4
4
  import { INLINE_CODE_KEY } from './types/index.js';
@@ -1,4 +1,4 @@
1
- import { _ as __decorate } from '../tslib.es6-2af4ba24.js';
1
+ import { _ as __decorate } from '../tslib.es6-46499da4.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { InjectWrapKeys, EditorPlugin } from '@block-kit/react';
4
4
  import { Bind } from '@block-kit/utils';
@@ -1,4 +1,4 @@
1
- import { _ as __decorate } from '../../tslib.es6-2af4ba24.js';
1
+ import { _ as __decorate } from '../../tslib.es6-46499da4.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { Point, EDITOR_EVENT, relativeTo, Range } from '@block-kit/core';
4
4
  import { deltaToText, Delta } from '@block-kit/delta';
@@ -1,4 +1,4 @@
1
- import { _ as __decorate } from '../tslib.es6-2af4ba24.js';
1
+ import { _ as __decorate } from '../tslib.es6-46499da4.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { EDITOR_EVENT, RawPoint, Point } from '@block-kit/core';
4
4
  import { Delta } from '@block-kit/delta';
@@ -1,4 +1,4 @@
1
- import { _ as __decorate } from '../tslib.es6-2af4ba24.js';
1
+ import { _ as __decorate } from '../tslib.es6-46499da4.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { EDITOR_EVENT, RawPoint, Point } from '@block-kit/core';
4
4
  import { Delta } from '@block-kit/delta';
@@ -25,7 +25,7 @@ class SelectionHOC extends React.PureComponent {
25
25
  onSelectionChange(range) {
26
26
  const leaf = this.props.leaf;
27
27
  const leafRange = leaf.toRange();
28
- const nextState = range ? Range.intersection(leafRange, range) : false;
28
+ const nextState = range ? Range.intersects(leafRange, range) : false;
29
29
  if (this.state.selected !== nextState) {
30
30
  this.setState({ selected: nextState });
31
31
  }
@@ -42,9 +42,7 @@ class SelectionHOC extends React.PureComponent {
42
42
  const { props } = child;
43
43
  return React.cloneElement(child, Object.assign(Object.assign({}, props), { selected: selected }));
44
44
  }
45
- else {
46
- return child;
47
- }
45
+ return child;
48
46
  }) }));
49
47
  }
50
48
  }
@@ -1,4 +1,4 @@
1
- import { _ as __decorate } from '../../tslib.es6-2af4ba24.js';
1
+ import { _ as __decorate } from '../../tslib.es6-46499da4.js';
2
2
  import { EDITOR_EVENT } from '@block-kit/core';
3
3
  import { Bind } from '@block-kit/utils';
4
4
 
@@ -1,4 +1,4 @@
1
- import { _ as __decorate } from '../tslib.es6-2af4ba24.js';
1
+ import { _ as __decorate } from '../tslib.es6-46499da4.js';
2
2
  import { CorePlugin, EDITOR_EVENT } from '@block-kit/core';
3
3
  import { Bind } from '@block-kit/utils';
4
4
  import { PLUGIN_EVENTS } from '../shared/utils/event.js';
@@ -2,7 +2,7 @@ import { jsx } from 'react/jsx-runtime';
2
2
  import { EDITOR_EVENT } from '@block-kit/core';
3
3
  import { useEditorStatic, useReadonly, MountNode } from '@block-kit/react';
4
4
  import { cs } from '@block-kit/utils';
5
- import { useMemoFn } from '@block-kit/utils/dist/es/hooks';
5
+ import { useForceUpdate, useMemoFn } from '@block-kit/utils/dist/es/hooks';
6
6
  import { useRef, useState, useEffect, useMemo } from 'react';
7
7
  import ReactDOM from 'react-dom';
8
8
  import { Toolbar } from './basic.js';
@@ -11,11 +11,13 @@ const FloatToolbar = props => {
11
11
  const { editor } = useEditorStatic();
12
12
  const { readonly } = useReadonly();
13
13
  const ref = useRef(null);
14
- const [visible, setVisible] = useState(false);
14
+ const { index, forceUpdate } = useForceUpdate();
15
15
  const [isMouseDown, setIsMouseDown] = useState(false);
16
- const onWeakUp = useMemoFn((wakeUp) => {
17
- if (editor.state.isFocused() && wakeUp) {
16
+ const [visible, setVisible] = useState(false);
17
+ const onCaretWeakUp = useMemoFn((wakeUp) => {
18
+ if (!readonly && editor.state.isFocused() && wakeUp) {
18
19
  setVisible(true);
20
+ !isMouseDown && forceUpdate();
19
21
  }
20
22
  else {
21
23
  setVisible(false);
@@ -36,7 +38,7 @@ const FloatToolbar = props => {
36
38
  const onSelectionChange = (e) => {
37
39
  const { current } = e;
38
40
  const isWakeUp = current ? !current.isCollapsed : false;
39
- onWeakUp(isWakeUp);
41
+ onCaretWeakUp(isWakeUp);
40
42
  };
41
43
  document.addEventListener(EDITOR_EVENT.MOUSE_UP, onMouseUp);
42
44
  document.addEventListener(EDITOR_EVENT.MOUSE_DOWN, onMouseDown);
@@ -46,14 +48,13 @@ const FloatToolbar = props => {
46
48
  document.removeEventListener(EDITOR_EVENT.MOUSE_DOWN, onMouseDown);
47
49
  editor.event.off(EDITOR_EVENT.SELECTION_CHANGE, onSelectionChange);
48
50
  };
49
- }, [editor, onWeakUp, readonly]);
50
- const overridePosition = useRef(props.overridePosition);
51
+ }, [editor, onCaretWeakUp, readonly]);
51
52
  const { left, top } = useMemo(() => {
52
53
  if (!readonly && visible && !isMouseDown) {
53
- if (overridePosition.current) {
54
- return overridePosition.current(); // overlay
54
+ if (props.overridePosition) {
55
+ return props.overridePosition(); // overlay
55
56
  }
56
- const rect = editor.rect.getSelectionRect();
57
+ const rect = editor.rect.getCaretRect();
57
58
  if (rect) {
58
59
  const topOffset = props.offsetTop || 0;
59
60
  const leftOffset = props.offsetLeft || 0;
@@ -63,7 +64,8 @@ const FloatToolbar = props => {
63
64
  }
64
65
  }
65
66
  return { top: -999999, left: -999999 };
66
- }, [editor.rect, readonly, visible, isMouseDown, props.offsetLeft, props.offsetTop]);
67
+ // eslint-disable-next-line react-hooks/exhaustive-deps
68
+ }, [index, readonly, visible, isMouseDown]);
67
69
  // 只读状态 / 不可见 / 鼠标按下 时隐藏
68
70
  return readonly || !visible || isMouseDown
69
71
  ? null
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-8deb1cdb.js');
5
+ var tslib_es6 = require('../tslib.es6-d0928055.js');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var core = require('@block-kit/core');
8
8
  var delta = require('@block-kit/delta');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-8deb1cdb.js');
5
+ var tslib_es6 = require('../tslib.es6-d0928055.js');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var core = require('@block-kit/core');
8
8
  var delta = require('@block-kit/delta');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-8deb1cdb.js');
5
+ var tslib_es6 = require('../tslib.es6-d0928055.js');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var core = require('@block-kit/core');
8
8
  var delta = require('@block-kit/delta');
@@ -23,7 +23,7 @@ class FontSizePlugin extends react.EditorPlugin {
23
23
  const attrs = context.attributes || {};
24
24
  const size = attrs[fontSize_types_index.FONT_SIZE_KEY];
25
25
  if (size) {
26
- context.style.fontSize = utils.Styles.pixelate(size);
26
+ context.style.fontSize = utils.Facade.pixelate(size);
27
27
  }
28
28
  return context.children;
29
29
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-8deb1cdb.js');
5
+ var tslib_es6 = require('../tslib.es6-d0928055.js');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var core = require('@block-kit/core');
8
8
  var delta = require('@block-kit/delta');
@@ -41,7 +41,7 @@ const ImageView = props => {
41
41
  const delta$1 = new delta.Delta().retain(rawRange.start).retain(rawRange.len, next);
42
42
  editor.state.apply(delta$1, { source: core.APPLY_SOURCE.NO_UNDO, autoCaret: false });
43
43
  };
44
- return (jsxRuntime.jsxs(react.Void, { className: "block-kit-image-container", context: context, children: [status === image_types_index.LOADING_STATUS.LOADING && (jsxRuntime.jsx("div", { className: "block-kit-image-loading", children: jsxRuntime.jsx(IconLoading__default["default"], {}) })), jsxRuntime.jsx(shared_components_selection.SelectionHOC, { selection: selection, leaf: context.leafState, children: jsxRuntime.jsx(image_view_wrapper.ImageWrapper, { editor: props.editor, src: src, leaf: context.leafState, children: jsxRuntime.jsx("img", { className: "block-kit-image", src: src, onLoad: onImageLoad, width: utils.Styles.pixelate(width), height: utils.Styles.pixelate(height) }) }) })] }));
44
+ return (jsxRuntime.jsxs(react.Void, { className: "block-kit-image-container", context: context, children: [status === image_types_index.LOADING_STATUS.LOADING && (jsxRuntime.jsx("div", { className: "block-kit-image-loading", children: jsxRuntime.jsx(IconLoading__default["default"], {}) })), jsxRuntime.jsx(shared_components_selection.SelectionHOC, { selection: selection, leaf: context.leafState, children: jsxRuntime.jsx(image_view_wrapper.ImageWrapper, { editor: props.editor, src: src, leaf: context.leafState, children: jsxRuntime.jsx("img", { className: "block-kit-image", src: src, onLoad: onImageLoad, width: utils.Facade.pixelate(width), height: utils.Facade.pixelate(height) }) }) })] }));
45
45
  };
46
46
 
47
47
  exports.ImageView = ImageView;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-8deb1cdb.js');
5
+ var tslib_es6 = require('../tslib.es6-d0928055.js');
6
6
  var core = require('@block-kit/core');
7
7
  var delta = require('@block-kit/delta');
8
8
  var react = require('@block-kit/react');
package/dist/lib/index.js CHANGED
@@ -53,7 +53,7 @@ var underline_types_index = require('./underline/types/index.js');
53
53
  var toolbar_context_float = require('./toolbar/context/float.js');
54
54
  var toolbar_context_basic = require('./toolbar/context/basic.js');
55
55
 
56
- const BLOCK_KIT_VERSION = "1.0.6" ;
56
+ const BLOCK_KIT_VERSION = "1.0.8" ;
57
57
 
58
58
  exports.AlignPlugin = align_index.AlignPlugin;
59
59
  exports.ALIGN_KEY = align_types_index.ALIGN_KEY;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-8deb1cdb.js');
5
+ var tslib_es6 = require('../tslib.es6-d0928055.js');
6
6
  var core = require('@block-kit/core');
7
7
  var react = require('@block-kit/react');
8
8
  var inlineCode_types_index = require('./types/index.js');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-8deb1cdb.js');
5
+ var tslib_es6 = require('../tslib.es6-d0928055.js');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var react = require('@block-kit/react');
8
8
  var utils = require('@block-kit/utils');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../../tslib.es6-8deb1cdb.js');
5
+ var tslib_es6 = require('../../tslib.es6-d0928055.js');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var core = require('@block-kit/core');
8
8
  var delta = require('@block-kit/delta');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-8deb1cdb.js');
5
+ var tslib_es6 = require('../tslib.es6-d0928055.js');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var core = require('@block-kit/core');
8
8
  var delta = require('@block-kit/delta');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-8deb1cdb.js');
5
+ var tslib_es6 = require('../tslib.es6-d0928055.js');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var core = require('@block-kit/core');
8
8
  var delta = require('@block-kit/delta');
@@ -33,7 +33,7 @@ class SelectionHOC extends React__default["default"].PureComponent {
33
33
  onSelectionChange(range) {
34
34
  const leaf = this.props.leaf;
35
35
  const leafRange = leaf.toRange();
36
- const nextState = range ? core.Range.intersection(leafRange, range) : false;
36
+ const nextState = range ? core.Range.intersects(leafRange, range) : false;
37
37
  if (this.state.selected !== nextState) {
38
38
  this.setState({ selected: nextState });
39
39
  }
@@ -50,9 +50,7 @@ class SelectionHOC extends React__default["default"].PureComponent {
50
50
  const { props } = child;
51
51
  return React__default["default"].cloneElement(child, Object.assign(Object.assign({}, props), { selected: selected }));
52
52
  }
53
- else {
54
- return child;
55
- }
53
+ return child;
56
54
  }) }));
57
55
  }
58
56
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../../tslib.es6-8deb1cdb.js');
5
+ var tslib_es6 = require('../../tslib.es6-d0928055.js');
6
6
  var core = require('@block-kit/core');
7
7
  var utils = require('@block-kit/utils');
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-8deb1cdb.js');
5
+ var tslib_es6 = require('../tslib.es6-d0928055.js');
6
6
  var core = require('@block-kit/core');
7
7
  var utils = require('@block-kit/utils');
8
8
  var shared_utils_event = require('../shared/utils/event.js');
@@ -19,11 +19,13 @@ const FloatToolbar = props => {
19
19
  const { editor } = react.useEditorStatic();
20
20
  const { readonly } = react.useReadonly();
21
21
  const ref = React.useRef(null);
22
- const [visible, setVisible] = React.useState(false);
22
+ const { index, forceUpdate } = hooks.useForceUpdate();
23
23
  const [isMouseDown, setIsMouseDown] = React.useState(false);
24
- const onWeakUp = hooks.useMemoFn((wakeUp) => {
25
- if (editor.state.isFocused() && wakeUp) {
24
+ const [visible, setVisible] = React.useState(false);
25
+ const onCaretWeakUp = hooks.useMemoFn((wakeUp) => {
26
+ if (!readonly && editor.state.isFocused() && wakeUp) {
26
27
  setVisible(true);
28
+ !isMouseDown && forceUpdate();
27
29
  }
28
30
  else {
29
31
  setVisible(false);
@@ -44,7 +46,7 @@ const FloatToolbar = props => {
44
46
  const onSelectionChange = (e) => {
45
47
  const { current } = e;
46
48
  const isWakeUp = current ? !current.isCollapsed : false;
47
- onWeakUp(isWakeUp);
49
+ onCaretWeakUp(isWakeUp);
48
50
  };
49
51
  document.addEventListener(core.EDITOR_EVENT.MOUSE_UP, onMouseUp);
50
52
  document.addEventListener(core.EDITOR_EVENT.MOUSE_DOWN, onMouseDown);
@@ -54,14 +56,13 @@ const FloatToolbar = props => {
54
56
  document.removeEventListener(core.EDITOR_EVENT.MOUSE_DOWN, onMouseDown);
55
57
  editor.event.off(core.EDITOR_EVENT.SELECTION_CHANGE, onSelectionChange);
56
58
  };
57
- }, [editor, onWeakUp, readonly]);
58
- const overridePosition = React.useRef(props.overridePosition);
59
+ }, [editor, onCaretWeakUp, readonly]);
59
60
  const { left, top } = React.useMemo(() => {
60
61
  if (!readonly && visible && !isMouseDown) {
61
- if (overridePosition.current) {
62
- return overridePosition.current(); // overlay
62
+ if (props.overridePosition) {
63
+ return props.overridePosition(); // overlay
63
64
  }
64
- const rect = editor.rect.getSelectionRect();
65
+ const rect = editor.rect.getCaretRect();
65
66
  if (rect) {
66
67
  const topOffset = props.offsetTop || 0;
67
68
  const leftOffset = props.offsetLeft || 0;
@@ -71,7 +72,8 @@ const FloatToolbar = props => {
71
72
  }
72
73
  }
73
74
  return { top: -999999, left: -999999 };
74
- }, [editor.rect, readonly, visible, isMouseDown, props.offsetLeft, props.offsetTop]);
75
+ // eslint-disable-next-line react-hooks/exhaustive-deps
76
+ }, [index, readonly, visible, isMouseDown]);
75
77
  // 只读状态 / 不可见 / 鼠标按下 时隐藏
76
78
  return readonly || !visible || isMouseDown
77
79
  ? null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@block-kit/plugin",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "",
5
5
  "main": "./dist/lib/index.js",
6
6
  "types": "./dist/es/index.d.ts",
@@ -38,14 +38,14 @@
38
38
  "react-dom": ">=16"
39
39
  },
40
40
  "dependencies": {
41
- "@arco-design/web-react": "^2.64.0",
42
- "@block-kit/core": "1.0.6",
43
- "@block-kit/delta": "1.0.6",
44
- "@block-kit/react": "1.0.6",
45
- "@block-kit/utils": "1.0.6",
46
- "@emoji-mart/data": "^1.2.1",
47
- "@emoji-mart/react": "^1.1.1",
48
- "emoji-mart": "^5.6.0"
41
+ "@arco-design/web-react": "2.64.0",
42
+ "@block-kit/core": "1.0.8",
43
+ "@block-kit/delta": "1.0.8",
44
+ "@block-kit/react": "1.0.8",
45
+ "@block-kit/utils": "1.0.8",
46
+ "@emoji-mart/data": "1.2.1",
47
+ "@emoji-mart/react": "1.1.1",
48
+ "emoji-mart": "5.6.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@rollup/plugin-commonjs": "22.0.1",