mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: Add scroll listener to the nearest scrollable container and allow consumer to disable it (#3408)
* fix: Add scroll listener to the nearest scrollable container * fix * use loop instead of recursion * fix * return document * calculate nearest scrollable container in settimeout to unblock main thread * Add prop detectNearestScroll and clear timeout on unmount * disable scroll listener on excal app * update prop name to detectScroll * update docs * remove settimeout * tweak docs Co-authored-by: David Luzar <luzar.david@gmail.com> * tweak changelog Co-authored-by: David Luzar <luzar.david@gmail.com> * lint Co-authored-by: David Luzar <luzar.david@gmail.com>
This commit is contained in:
parent
d91950bd03
commit
c19c8ecd27
8 changed files with 47 additions and 8 deletions
|
@ -15,6 +15,7 @@ Please add the latest change on the top under the correct section.
|
|||
|
||||
## Excalidraw API
|
||||
|
||||
- Recompute offsets on `scroll` of the nearest scrollable container [#3408](https://github.com/excalidraw/excalidraw/pull/3408). This can be disabled by setting [`detectScroll`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#detectScroll) to `false`.
|
||||
- Add `onPaste` prop to handle custom clipboard behaviours [#3420](https://github.com/excalidraw/excalidraw/pull/3420).
|
||||
|
||||
## Excalidraw Library
|
||||
|
|
|
@ -365,6 +365,7 @@ To view the full example visit :point_down:
|
|||
| [`name`](#name) | string | | Name of the drawing |
|
||||
| [`UIOptions`](#UIOptions) | <pre>{ canvasActions: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L208"> CanvasActions<a/> }</pre> | [DEFAULT UI OPTIONS](https://github.com/excalidraw/excalidraw/blob/master/src/constants.ts#L129) | To customise UI options. Currently we support customising [`canvas actions`](#canvasActions) |
|
||||
| [`onPaste`](#onPaste) | <pre>(data: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/clipboard.ts#L17">ClipboardData</a>, event: ClipboardEvent | null) => boolean</pre> | | Callback to be triggered if passed when the something is pasted in to the scene |
|
||||
| [`detectScroll`](#detectScroll) | boolean | true | Indicates whether to update the offsets when nearest ancestor is scrolled. |
|
||||
|
||||
### Dimensions of Excalidraw
|
||||
|
||||
|
@ -587,6 +588,10 @@ useEffect(() => {
|
|||
|
||||
Try out the [Demo](#Demo) to see it in action.
|
||||
|
||||
### detectScroll
|
||||
|
||||
Indicates whether Excalidraw should listen for `scroll` event on the nearest scrollable container in the DOM tree and recompute the coordinates (e.g. to correctly handle the cursor) when the component's position changes. You can disable this when you either know this doesn't affect your app or you want to take care of it yourself (calling the [`refresh()`](#ref) method).
|
||||
|
||||
### Extra API's
|
||||
|
||||
#### `getSceneVersion`
|
||||
|
|
|
@ -30,6 +30,7 @@ const Excalidraw = (props: ExcalidrawProps) => {
|
|||
name,
|
||||
renderCustomStats,
|
||||
onPaste,
|
||||
detectScroll = true,
|
||||
} = props;
|
||||
|
||||
const canvasActions = props.UIOptions?.canvasActions;
|
||||
|
@ -80,6 +81,7 @@ const Excalidraw = (props: ExcalidrawProps) => {
|
|||
renderCustomStats={renderCustomStats}
|
||||
UIOptions={UIOptions}
|
||||
onPaste={onPaste}
|
||||
detectScroll={detectScroll}
|
||||
/>
|
||||
</InitializeApp>
|
||||
);
|
||||
|
@ -102,11 +104,6 @@ const areEqual = (
|
|||
);
|
||||
};
|
||||
|
||||
Excalidraw.defaultProps = {
|
||||
lanCode: defaultLang.code,
|
||||
UIOptions: DEFAULT_UI_OPTIONS,
|
||||
};
|
||||
|
||||
const forwardedRefComp = forwardRef<
|
||||
ExcalidrawAPIRefValue,
|
||||
PublicExcalidrawProps
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue