Skip to content

Commit 673b9c4

Browse files
committed
chore: more
1 parent 3f44b1d commit 673b9c4

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

packages/react/src/components/LinkToolbar/LinkToolbarController.tsx

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,12 @@ function getMarkAtPos(
8585
return tr.doc.textBetween(markRange.from, markRange.to);
8686
},
8787
get position() {
88-
// toJSON is always a new reference, so we remove it
89-
const { toJSON, ...position } = posToDOMRect(
88+
// to minimize re-renders, we convert to JSON, which is the same shape anyway
89+
return posToDOMRect(
9090
editor.prosemirrorView,
9191
markRange.from,
9292
markRange.to,
93-
);
94-
return position;
93+
).toJSON() as DOMRect;
9594
},
9695
};
9796
});
@@ -125,12 +124,6 @@ export const LinkToolbarController = <
125124
editor,
126125
selector: ({ editor }) => {
127126
return getLinkAtSelection(editor);
128-
// if (!linkAtSelection) {
129-
// return;
130-
// }
131-
// const { range, text, mark, position } = linkAtSelection;
132-
// console.log(position);
133-
// return { range, text, mark };
134127
},
135128
});
136129

@@ -150,10 +143,7 @@ export const LinkToolbarController = <
150143
open: show,
151144
placement: "top-start",
152145
middleware: [offset(10), flip()],
153-
onOpenChange: (open, event, reason) => {
154-
console.log("openChange", open, event, reason);
155-
setShow(open);
156-
},
146+
onOpenChange: setShow,
157147
whileElementsMounted: autoUpdate,
158148
...props.floatingOptions,
159149
});
@@ -167,16 +157,14 @@ export const LinkToolbarController = <
167157
!isEventTargetWithin(e, editor.prosemirrorView.dom.parentElement),
168158
});
169159

170-
console.log(linkAtSelection);
171160
// Create element hover hook for link detection
172161
const elementHover = useElementHover(context, {
173162
enabled: !linkAtSelection,
174163
attachTo() {
175164
return editor.prosemirrorView.dom;
176165
},
177-
delay: { open: 250, close: 0 },
178-
restMs: 0,
179-
mouseOnly: true,
166+
delay: { open: 250, close: 400 },
167+
restMs: 300,
180168
getElementAtHover: (target) => {
181169
// Check if there's a link at the current selection first
182170
if (getLinkAtSelection(editor)) {
@@ -232,6 +220,7 @@ export const LinkToolbarController = <
232220
useEffect(() => {
233221
if (!linkAtSelection) {
234222
setReference(null);
223+
setShow(false);
235224
return;
236225
}
237226

@@ -267,7 +256,6 @@ export const LinkToolbarController = <
267256

268257
const Component = props.linkToolbar || LinkToolbar;
269258

270-
console.log("showing");
271259
return (
272260
<div ref={ref} style={style} {...getFloatingProps()}>
273261
<Component

0 commit comments

Comments
 (0)