@use-kona/editor 0.1.4 → 0.1.5
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.
|
@@ -16,6 +16,7 @@ const Menu = (props)=>{
|
|
|
16
16
|
const selection = useSlateSelection();
|
|
17
17
|
const editor = useSlate();
|
|
18
18
|
const isFocused = useFocused();
|
|
19
|
+
const ref = useRef(null);
|
|
19
20
|
const entry = Editor.above(editor, {
|
|
20
21
|
match: (n)=>Editor.isBlock(editor, n)
|
|
21
22
|
});
|
|
@@ -95,7 +96,8 @@ const Menu = (props)=>{
|
|
|
95
96
|
}, [
|
|
96
97
|
store.filter
|
|
97
98
|
]);
|
|
98
|
-
|
|
99
|
+
useLayoutEffect(()=>{
|
|
100
|
+
const element = ref.current;
|
|
99
101
|
if (element) {
|
|
100
102
|
const { height, top } = element.getBoundingClientRect();
|
|
101
103
|
const domSelection = window.getSelection();
|
|
@@ -106,7 +108,7 @@ const Menu = (props)=>{
|
|
|
106
108
|
top: `${top - height - (rect?.height ?? 22)}px`
|
|
107
109
|
}));
|
|
108
110
|
}
|
|
109
|
-
};
|
|
111
|
+
}, []);
|
|
110
112
|
if (!commands.length) return null;
|
|
111
113
|
if (entry && ignoreNodes.includes(entry[0].type)) return null;
|
|
112
114
|
return /*#__PURE__*/ createPortal(renderMenu(/*#__PURE__*/ jsxs(Fragment, {
|
|
@@ -118,7 +120,7 @@ const Menu = (props)=>{
|
|
|
118
120
|
}
|
|
119
121
|
}),
|
|
120
122
|
/*#__PURE__*/ jsx("div", {
|
|
121
|
-
ref:
|
|
123
|
+
ref: ref,
|
|
122
124
|
style: style,
|
|
123
125
|
className: styles_module.menu,
|
|
124
126
|
onMouseDown: (event)=>{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useLayoutEffect, useState } from "react";
|
|
2
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
3
3
|
import { createPortal } from "react-dom";
|
|
4
4
|
import { useFocused, useSlateSelection } from "slate-react";
|
|
5
5
|
import styles_module from "./styles.module.js";
|
|
@@ -7,6 +7,7 @@ const Menu = (props)=>{
|
|
|
7
7
|
const { isOpen, children } = props;
|
|
8
8
|
const isFocused = useFocused();
|
|
9
9
|
const selection = useSlateSelection();
|
|
10
|
+
const ref = useRef(null);
|
|
10
11
|
const [style, setStyle] = useState({});
|
|
11
12
|
useLayoutEffect(()=>{
|
|
12
13
|
if (!selection || !isFocused) return void setStyle(void 0);
|
|
@@ -29,7 +30,8 @@ const Menu = (props)=>{
|
|
|
29
30
|
isFocused,
|
|
30
31
|
isOpen
|
|
31
32
|
]);
|
|
32
|
-
|
|
33
|
+
useLayoutEffect(()=>{
|
|
34
|
+
const element = ref.current;
|
|
33
35
|
if (element) {
|
|
34
36
|
const { height, top } = element.getBoundingClientRect();
|
|
35
37
|
const domSelection = window.getSelection();
|
|
@@ -40,9 +42,9 @@ const Menu = (props)=>{
|
|
|
40
42
|
top: `${top - height - (rect?.height ?? 22)}px`
|
|
41
43
|
}));
|
|
42
44
|
}
|
|
43
|
-
};
|
|
45
|
+
}, []);
|
|
44
46
|
return /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx("div", {
|
|
45
|
-
ref:
|
|
47
|
+
ref: ref,
|
|
46
48
|
style: style,
|
|
47
49
|
className: styles_module.root,
|
|
48
50
|
children: children
|
package/package.json
CHANGED
|
@@ -35,6 +35,7 @@ export const Menu = (props: Props) => {
|
|
|
35
35
|
const selection = useSlateSelection();
|
|
36
36
|
const editor = useSlate() as Editor;
|
|
37
37
|
const isFocused = useFocused();
|
|
38
|
+
const ref = useRef<HTMLDivElement>(null)
|
|
38
39
|
|
|
39
40
|
const entry = Editor.above<CustomElement>(editor, {
|
|
40
41
|
match: (n) => Editor.isBlock(editor, n as CustomElement),
|
|
@@ -137,7 +138,8 @@ export const Menu = (props: Props) => {
|
|
|
137
138
|
}
|
|
138
139
|
}, [store.filter]);
|
|
139
140
|
|
|
140
|
-
|
|
141
|
+
useLayoutEffect(() => {
|
|
142
|
+
const element = ref.current;
|
|
141
143
|
if (element) {
|
|
142
144
|
const { height, top } = element.getBoundingClientRect();
|
|
143
145
|
|
|
@@ -152,7 +154,7 @@ export const Menu = (props: Props) => {
|
|
|
152
154
|
}));
|
|
153
155
|
}
|
|
154
156
|
}
|
|
155
|
-
};
|
|
157
|
+
}, []);
|
|
156
158
|
|
|
157
159
|
if (!commands.length) {
|
|
158
160
|
return null;
|
|
@@ -174,7 +176,7 @@ export const Menu = (props: Props) => {
|
|
|
174
176
|
/>
|
|
175
177
|
)}
|
|
176
178
|
<div
|
|
177
|
-
ref={
|
|
179
|
+
ref={ref}
|
|
178
180
|
style={style}
|
|
179
181
|
className={styles.menu}
|
|
180
182
|
onMouseDown={(event) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type CSSProperties,
|
|
3
3
|
type ReactNode,
|
|
4
|
-
useLayoutEffect,
|
|
4
|
+
useLayoutEffect, useRef,
|
|
5
5
|
useState,
|
|
6
6
|
} from 'react';
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
@@ -18,6 +18,7 @@ export const Menu = (props: Props) => {
|
|
|
18
18
|
|
|
19
19
|
const isFocused = useFocused();
|
|
20
20
|
const selection = useSlateSelection();
|
|
21
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
21
22
|
|
|
22
23
|
const [style, setStyle] = useState<CSSProperties | undefined>({});
|
|
23
24
|
|
|
@@ -48,7 +49,8 @@ export const Menu = (props: Props) => {
|
|
|
48
49
|
}, 0);
|
|
49
50
|
}, [selection, isFocused, isOpen]);
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
useLayoutEffect(() => {
|
|
53
|
+
const element = ref.current;
|
|
52
54
|
if (element) {
|
|
53
55
|
const { height, top } = element.getBoundingClientRect();
|
|
54
56
|
|
|
@@ -63,10 +65,11 @@ export const Menu = (props: Props) => {
|
|
|
63
65
|
}));
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
|
-
};
|
|
68
|
+
}, []);
|
|
69
|
+
|
|
67
70
|
|
|
68
71
|
return createPortal(
|
|
69
|
-
<div ref={
|
|
72
|
+
<div ref={ref} style={style} className={styles.root}>
|
|
70
73
|
{children}
|
|
71
74
|
</div>,
|
|
72
75
|
document.body,
|