mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: Expose the API to calculate offsets and remove offsetTop and offsetLeft props (#3265)
* feat: Expose the API to calculate offsets and remove offsetTop and offsetLeft props * update * fix tests * fix * update readme and changelog * fix * better
This commit is contained in:
parent
add1785ace
commit
de99484a1f
6 changed files with 53 additions and 73 deletions
|
@ -18,6 +18,9 @@ Please add the latest change on the top under the correct section.
|
|||
|
||||
### Features
|
||||
|
||||
- Export API `setCanvasOffsets` via `ref` to set the offsets for Excalidraw[#3265](https://github.com/excalidraw/excalidraw/pull/3265).
|
||||
#### BREAKING CHANGE
|
||||
- `offsetLeft` and `offsetTop` props have been removed now so you have to use the `setCanvasOffsets` via `ref` to achieve the same.
|
||||
- Export API to export the drawing to canvas, svg and blob [#3258](https://github.com/excalidraw/excalidraw/pull/3258). For more info you can check the [readme](https://github.com/excalidraw/excalidraw/tree/master/src/packages/excalidraw/README.md#user-content-export-utils)
|
||||
- Add a `theme` prop to indicate Excalidraw's theme. [#3228](https://github.com/excalidraw/excalidraw/pull/3228). When this prop is passed, the theme is fully controlled by host app.
|
||||
- Support `libraryReturnUrl` prop to indicate what URL to install libraries to [#3227](https://github.com/excalidraw/excalidraw/pull/3227).
|
||||
|
|
|
@ -362,8 +362,6 @@ export default function IndexPage() {
|
|||
| --- | --- | --- | --- |
|
||||
| [`width`](#width) | Number | `window.innerWidth` | The width of Excalidraw component |
|
||||
| [`height`](#height) | Number | `window.innerHeight` | The height of Excalidraw component |
|
||||
| [`offsetLeft`](#offsetLeft) | Number | `0` | left position relative to which Excalidraw should be rendered |
|
||||
| [`offsetTop`](#offsetTop) | Number | `0` | top position relative to which Excalidraw should render |
|
||||
| [`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. |
|
||||
| [`initialData`](#initialData) | <pre>{elements?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>, appState?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L37">AppState<a> } </pre> | null | The initial data with which app loads. |
|
||||
| [`ref`](#ref) | [`createRef`](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) or [`callbackRef`](https://reactjs.org/docs/refs-and-the-dom.html#callback-refs) or <pre>{ current: { readyPromise: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/utils.ts#L317">resolvablePromise</a> } }</pre> | | Ref to be passed to Excalidraw |
|
||||
|
@ -387,14 +385,6 @@ This props defines the `width` of the Excalidraw component. Defaults to `window.
|
|||
|
||||
This props defines the `height` of the Excalidraw component. Defaults to `window.innerHeight` if not passed.
|
||||
|
||||
#### `offsetLeft`
|
||||
|
||||
This prop defines `left` position relative to which Excalidraw should be rendered. Defaults to `0` if not passed.
|
||||
|
||||
#### `offsetTop`
|
||||
|
||||
This prop defines `top` position relative to which Excalidraw should be rendered. Defaults to `0` if not passed.
|
||||
|
||||
#### `onChange`
|
||||
|
||||
Every time component updates, this callback if passed will get triggered and has the below signature.
|
||||
|
@ -465,6 +455,7 @@ You can pass a `ref` when you want to access some excalidraw APIs. We expose the
|
|||
| getAppState | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L37">AppState</a></pre> | Returns current appState |
|
||||
| history | `{ clear: () => void }` | This is the history API. `history.clear()` will clear the history |
|
||||
| setScrollToContent | <pre> (<a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>) => void </pre> | Scroll to the nearest element to center |
|
||||
| setCanvasOffsets | `() => void` | Updates the offsets for the Excalidraw component so that the coordinates are computed correctly (for example the cursor position). You should call this API when your app changes the dimensions/position of the Excalidraw container, such as when toggling a sidebar. You don't have to call this when the position is changed on page scroll (we handled that ourselves). |
|
||||
|
||||
#### `readyPromise`
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@ const Excalidraw = (props: ExcalidrawProps) => {
|
|||
const {
|
||||
width,
|
||||
height,
|
||||
offsetLeft,
|
||||
offsetTop,
|
||||
onChange,
|
||||
initialData,
|
||||
excalidrawRef,
|
||||
|
@ -57,8 +55,6 @@ const Excalidraw = (props: ExcalidrawProps) => {
|
|||
<App
|
||||
width={width}
|
||||
height={height}
|
||||
offsetLeft={offsetLeft}
|
||||
offsetTop={offsetTop}
|
||||
onChange={onChange}
|
||||
initialData={initialData}
|
||||
excalidrawRef={excalidrawRef}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue