From c0b80a03bd1ec92ff450452d1dc77644333d42fe Mon Sep 17 00:00:00 2001 From: Ryan Di Date: Wed, 27 Nov 2024 01:53:25 +0800 Subject: [PATCH] feat: in canvas links between shapes (#8812) Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com> --- .../excalidraw/api/props/props.mdx | 50 +++-- excalidraw-app/App.tsx | 7 + packages/excalidraw/actions/actionCanvas.tsx | 3 +- .../excalidraw/actions/actionElementLink.ts | 105 +++++++++ packages/excalidraw/actions/types.ts | 2 + packages/excalidraw/appState.ts | 2 + packages/excalidraw/components/App.tsx | 180 ++++++++++++++-- .../CommandPalette/CommandPalette.tsx | 6 + .../components/ElementLinkDialog.scss | 87 ++++++++ .../components/ElementLinkDialog.tsx | 174 +++++++++++++++ packages/excalidraw/components/LayerUI.tsx | 175 ++++++++------- packages/excalidraw/components/MobileMenu.tsx | 17 +- .../components/canvases/InteractiveCanvas.tsx | 1 + .../components/canvases/StaticCanvas.tsx | 2 + .../components/hyperlink/Hyperlink.tsx | 86 +++++--- .../components/hyperlink/helpers.ts | 5 + packages/excalidraw/components/icons.tsx | 15 ++ packages/excalidraw/constants.ts | 3 + packages/excalidraw/element/elementLink.ts | 102 +++++++++ .../element/showSelectedShapeActions.ts | 1 + packages/excalidraw/index.tsx | 3 + packages/excalidraw/locales/en.json | 21 +- packages/excalidraw/renderer/renderElement.ts | 12 +- packages/excalidraw/renderer/staticScene.ts | 65 +++--- packages/excalidraw/scene/Scene.ts | 13 ++ .../__snapshots__/contextmenu.test.tsx.snap | 202 ++++++++++++++++++ .../tests/__snapshots__/history.test.tsx.snap | 58 +++++ .../regressionTests.test.tsx.snap | 52 +++++ .../excalidraw/tests/contextmenu.test.tsx | 19 +- packages/excalidraw/types.ts | 8 +- .../utils/__snapshots__/export.test.ts.snap | 1 + yarn.lock | 21 +- 32 files changed, 1281 insertions(+), 217 deletions(-) create mode 100644 packages/excalidraw/actions/actionElementLink.ts create mode 100644 packages/excalidraw/components/ElementLinkDialog.scss create mode 100644 packages/excalidraw/components/ElementLinkDialog.tsx create mode 100644 packages/excalidraw/element/elementLink.ts diff --git a/dev-docs/docs/@excalidraw/excalidraw/api/props/props.mdx b/dev-docs/docs/@excalidraw/excalidraw/api/props/props.mdx index a3af78938c..e25aedcf40 100644 --- a/dev-docs/docs/@excalidraw/excalidraw/api/props/props.mdx +++ b/dev-docs/docs/@excalidraw/excalidraw/api/props/props.mdx @@ -3,31 +3,32 @@ All `props` are _optional_. | Name | Type | Default | Description | -| --- | --- | --- | --- | +| --- | --- | --- | --- | --- | --- | --- | --- | --- | | [`initialData`](/docs/@excalidraw/excalidraw/api/props/initialdata) | `object` | `null` | Promise | `null` | The initial data with which app loads. | -| [`excalidrawAPI`](/docs/@excalidraw/excalidraw/api/props/excalidraw-api) | `function` | _ | Callback triggered with the excalidraw api once rendered | -| [`isCollaborating`](#iscollaborating) | `boolean` | _ | This indicates if the app is in `collaboration` mode | -| [`onChange`](#onchange) | `function` | _ | This callback is triggered whenever the component updates due to any change. This callback will receive the excalidraw `elements` and the current `app state`. | -| [`onPointerUpdate`](#onpointerupdate) | `function` | _ | Callback triggered when mouse pointer is updated. | -| [`onPointerDown`](#onpointerdown) | `function` | _ | This prop if passed gets triggered on pointer down events | -| [`onScrollChange`](#onscrollchange) | `function` | _ | This prop if passed gets triggered when scrolling the canvas. | -| [`onPaste`](#onpaste) | `function` | _ | Callback to be triggered if passed when something is pasted into the scene | -| [`onLibraryChange`](#onlibrarychange) | `function` | _ | The callback if supplied is triggered when the library is updated and receives the library items. | -| [`onLinkOpen`](#onlinkopen) | `function` | _ | The callback if supplied is triggered when any link is opened. | +| [`excalidrawAPI`](/docs/@excalidraw/excalidraw/api/props/excalidraw-api) | `function` | \_ | Callback triggered with the excalidraw api once rendered | +| [`isCollaborating`](#iscollaborating) | `boolean` | \_ | This indicates if the app is in `collaboration` mode | +| [`onChange`](#onchange) | `function` | \_ | This callback is triggered whenever the component updates due to any change. This callback will receive the excalidraw `elements` and the current `app state`. | +| [`onPointerUpdate`](#onpointerupdate) | `function` | \_ | Callback triggered when mouse pointer is updated. | +| [`onPointerDown`](#onpointerdown) | `function` | \_ | This prop if passed gets triggered on pointer down events | +| [`onScrollChange`](#onscrollchange) | `function` | \_ | This prop if passed gets triggered when scrolling the canvas. | +| [`onPaste`](#onpaste) | `function` | \_ | Callback to be triggered if passed when something is pasted into the scene | +| [`onLibraryChange`](#onlibrarychange) | `function` | \_ | The callback if supplied is triggered when the library is updated and receives the library items. | +| [`generateLinkForSelection`](#generateLinkForSelection) | `function` | \_ | Allows you to override `url` generation when linking to Excalidraw elements. | +| [`onLinkOpen`](#onlinkopen) | `function` | \_ | The callback if supplied is triggered when any link is opened. | | [`langCode`](#langcode) | `string` | `en` | Language code string to be used in Excalidraw | -| [`renderTopRightUI`](/docs/@excalidraw/excalidraw/api/props/render-props#rendertoprightui) | `function` | _ | Render function that renders custom UI in top right corner | -| [`renderCustomStats`](/docs/@excalidraw/excalidraw/api/props/render-props#rendercustomstats) | `function` | _ | Render function that can be used to render custom stats on the stats dialog. | -| [`viewModeEnabled`](#viewmodeenabled) | `boolean` | _ | This indicates if the app is in `view` mode. | -| [`zenModeEnabled`](#zenmodeenabled) | `boolean` | _ | This indicates if the `zen` mode is enabled | -| [`gridModeEnabled`](#gridmodeenabled) | `boolean` | _ | This indicates if the `grid` mode is enabled | -| [`libraryReturnUrl`](#libraryreturnurl) | `string` | _ | What URL should [libraries.excalidraw.com](https://libraries.excalidraw.com) be installed to | +| [`renderTopRightUI`](/docs/@excalidraw/excalidraw/api/props/render-props#rendertoprightui) | `function` | \_ | Render function that renders custom UI in top right corner | +| [`renderCustomStats`](/docs/@excalidraw/excalidraw/api/props/render-props#rendercustomstats) | `function` | \_ | Render function that can be used to render custom stats on the stats dialog. | +| [`viewModeEnabled`](#viewmodeenabled) | `boolean` | \_ | This indicates if the app is in `view` mode. | +| [`zenModeEnabled`](#zenmodeenabled) | `boolean` | \_ | This indicates if the `zen` mode is enabled | +| [`gridModeEnabled`](#gridmodeenabled) | `boolean` | \_ | This indicates if the `grid` mode is enabled | +| [`libraryReturnUrl`](#libraryreturnurl) | `string` | \_ | What URL should [libraries.excalidraw.com](https://libraries.excalidraw.com) be installed to | | [`theme`](#theme) | `"light"` | `"dark"` | `"light"` | The theme of the Excalidraw component | | [`name`](#name) | `string` | | Name of the drawing | | [`UIOptions`](/docs/@excalidraw/excalidraw/api/props/ui-options) | `object` | [DEFAULT UI OPTIONS](https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/constants.ts#L151) | To customise UI options. Currently we support customising [`canvas actions`](/docs/@excalidraw/excalidraw/api/props/ui-options#canvasactions) | | [`detectScroll`](#detectscroll) | `boolean` | `true` | Indicates whether to update the offsets when nearest ancestor is scrolled. | | [`handleKeyboardGlobally`](#handlekeyboardglobally) | `boolean` | `false` | Indicates whether to bind the keyboard events to document. | | [`autoFocus`](#autofocus) | `boolean` | `false` | Indicates whether to focus the Excalidraw component on page load | -| [`generateIdForFile`](#generateidforfile) | `function` | _ | Allows you to override `id` generation for files added on canvas | +| [`generateIdForFile`](#generateidforfile) | `function` | \_ | Allows you to override `id` generation for files added on canvas | | [`validateEmbeddable`](#validateEmbeddable) | string[] | `boolean | RegExp | RegExp[] | ((link: string) => boolean | undefined)` | \_ | use for custom src url validation | | [`renderEmbeddable`](/docs/@excalidraw/excalidraw/api/props/render-props#renderEmbeddable) | `function` | \_ | Render function that can override the built-in `