Compare commits

...

1 Commits

Author SHA1 Message Date
Zsolt Viczian
e4b17e77f8 publish handleLinkNavigation to app props 2022-02-03 19:18:09 +01:00
5 changed files with 16 additions and 0 deletions

View File

@ -2394,6 +2394,14 @@ class App extends React.Component<AppProps, AppState> {
if (lastPointerDownHittingLinkIcon && LastPointerUpHittingLinkIcon) {
const url = this.hitLinkElement?.link;
if (url) {
if (this.props.handleLinkNavigation) {
try {
this.props.handleLinkNavigation(url);
return;
} catch (error: any) {
console.error(error);
}
}
const target = isLocalLink(url) ? "_self" : "_blank";
const newWindow = window.open(undefined, target);
// https://mathiasbynens.github.io/rel-noopener/

View File

@ -17,6 +17,10 @@ Please add the latest change on the top under the correct section.
- [`exportToBlob`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#exportToBlob) now automatically sets `appState.exportBackground` to `true` if exporting to `image/jpeg` MIME type (to ensure that alpha channel is not compressed to black color).
## Excalidraw App Props
- `handleLinkNavigation (url: string) => void`. If provided Excalidraw will call this function to open element hyperlinks.
### Features
- Support updating library using [`updateScene`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#updateScene) API [#4546](https://github.com/excalidraw/excalidraw/pull/4546).

View File

@ -405,6 +405,7 @@ For a complete list of variables, check [theme.scss](https://github.com/excalidr
| [`onLibraryChange`](#onLibraryChange) | <pre>(items: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a>) => void &#124; Promise&lt;any&gt; </pre> | | The callback if supplied is triggered when the library is updated and receives the library items. |
| [`autoFocus`](#autoFocus) | boolean | false | Implies whether to focus the Excalidraw component on page load |
| [`generateIdForFile`](#generateIdForFile) | `(file: File) => string | Promise<string>` | Allows you to override `id` generation for files added on canvas |
| [`handleLinkNavigation`](#handleLinkNavigation) | `(url: string) => void` | If provided Excalidraw will call this function to open element hyperlinks |
### Dimensions of Excalidraw

View File

@ -35,6 +35,7 @@ const Excalidraw = (props: ExcalidrawProps) => {
onLibraryChange,
autoFocus = false,
generateIdForFile,
handleLinkNavigation,
} = props;
const canvasActions = props.UIOptions?.canvasActions;
@ -96,6 +97,7 @@ const Excalidraw = (props: ExcalidrawProps) => {
onLibraryChange={onLibraryChange}
autoFocus={autoFocus}
generateIdForFile={generateIdForFile}
handleLinkNavigation={handleLinkNavigation}
/>
</InitializeApp>
);

View File

@ -247,6 +247,7 @@ export interface ExcalidrawProps {
onLibraryChange?: (libraryItems: LibraryItems) => void | Promise<any>;
autoFocus?: boolean;
generateIdForFile?: (file: File) => string | Promise<string>;
handleLinkNavigation?: (url: string) => void;
}
export type SceneData = {