mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: add onLinkOpen
component prop (#4694)
Co-authored-by: ad1992 <aakansha1216@gmail.com>
This commit is contained in:
parent
050bc1ce2b
commit
a066317d3c
11 changed files with 128 additions and 32 deletions
|
@ -213,6 +213,7 @@ import {
|
|||
tupleToCoors,
|
||||
viewportCoordsToSceneCoords,
|
||||
withBatchedUpdates,
|
||||
wrapEvent,
|
||||
withBatchedUpdatesThrottled,
|
||||
} from "../utils";
|
||||
import ContextMenu, { ContextMenuOption } from "./ContextMenu";
|
||||
|
@ -526,6 +527,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
element={selectedElement[0]}
|
||||
appState={this.state}
|
||||
setAppState={this.setAppState}
|
||||
onLinkOpen={this.props.onLinkOpen}
|
||||
/>
|
||||
)}
|
||||
{this.state.showStats && (
|
||||
|
@ -2384,8 +2386,9 @@ class App extends React.Component<AppProps, AppState> {
|
|||
});
|
||||
};
|
||||
|
||||
private redirectToLink = () => {
|
||||
private redirectToLink = (event: React.PointerEvent<HTMLCanvasElement>) => {
|
||||
if (
|
||||
!this.hitLinkElement ||
|
||||
this.lastPointerDown!.clientX !== this.lastPointerUp!.clientX ||
|
||||
this.lastPointerDown!.clientY !== this.lastPointerUp!.clientY
|
||||
) {
|
||||
|
@ -2412,14 +2415,21 @@ class App extends React.Component<AppProps, AppState> {
|
|||
this.isMobile,
|
||||
);
|
||||
if (lastPointerDownHittingLinkIcon && LastPointerUpHittingLinkIcon) {
|
||||
const url = this.hitLinkElement?.link;
|
||||
const url = this.hitLinkElement.link;
|
||||
if (url) {
|
||||
const target = isLocalLink(url) ? "_self" : "_blank";
|
||||
const newWindow = window.open(undefined, target);
|
||||
// https://mathiasbynens.github.io/rel-noopener/
|
||||
if (newWindow) {
|
||||
newWindow.opener = null;
|
||||
newWindow.location = normalizeLink(url);
|
||||
let customEvent;
|
||||
if (this.props.onLinkOpen) {
|
||||
customEvent = wrapEvent(EVENT.EXCALIDRAW_LINK, event.nativeEvent);
|
||||
this.props.onLinkOpen(this.hitLinkElement, customEvent);
|
||||
}
|
||||
if (!customEvent?.defaultPrevented) {
|
||||
const target = isLocalLink(url) ? "_self" : "_blank";
|
||||
const newWindow = window.open(undefined, target);
|
||||
// https://mathiasbynens.github.io/rel-noopener/
|
||||
if (newWindow) {
|
||||
newWindow.opener = null;
|
||||
newWindow.location = normalizeLink(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2896,7 +2906,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
this.hitLinkElement &&
|
||||
!this.state.selectedElementIds[this.hitLinkElement.id]
|
||||
) {
|
||||
this.redirectToLink();
|
||||
this.redirectToLink(event);
|
||||
}
|
||||
|
||||
this.removePointer(event);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue