You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dev-docs/docs/@excalidraw/excalidraw/api/children-components/sidebar.mdx
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ A given tab trigger button that switches to a given sidebar tab. It must be rend
80
80
|`className`|`string`| No ||
81
81
|`style`|`React.CSSProperties`| No ||
82
82
83
-
You can use the [`ref.toggleSidebar({ name: "custom" })`](/docs/@excalidraw/excalidraw/api/props/ref#toggleSidebar) api to control the sidebar, but we export a trigger button to make UI use cases easier.
83
+
You can use the [`ref.toggleSidebar({ name: "custom" })`](/docs/@excalidraw/excalidraw/api/props/excalidraw-api#toggleSidebar) api to control the sidebar, but we export a trigger button to make UI use cases easier.
|`elements`|[ExcalidrawElementSkeleton](https://github.com/excalidraw/excalidraw/blob/master/src/data/transform.ts#L137)|| The Excalidraw element Skeleton which needs to be converted to Excalidraw elements. |
23
+
|`opts`|`{ regenerateIds: boolean }`|` {regenerateIds: true}`| By default `id` will be regenerated for all the elements irrespective of whether you pass the `id` so if you don't want the ids to regenerated, you can set this attribute to `false`. |
This function converts the Excalidraw Element Skeleton to excalidraw elements which could be then rendered on the canvas. Hence calling this function is necessary before passing it to APIs like [`initialData`](https://docs.excalidraw.com/docs/@excalidraw/excalidraw/api/props/initialdata), [`updateScene`](https://docs.excalidraw.com/docs/@excalidraw/excalidraw/api/props/ref#updatescene) if you are using the Skeleton API
31
+
This function converts the Excalidraw Element Skeleton to excalidraw elements which could be then rendered on the canvas. Hence calling this function is necessary before passing it to APIs like [`initialData`](https://docs.excalidraw.com/docs/@excalidraw/excalidraw/api/props/initialdata), [`updateScene`](https://docs.excalidraw.com/docs/@excalidraw/excalidraw/api/props/excalidraw-api#updatescene) if you are using the Skeleton API
28
32
29
33
## Supported Features
30
34
31
35
### Rectangle, Ellipse, and Diamond
32
36
33
-
To create these shapes you need to pass its `type` and `x` and `y` coordinates for position. The rest of the attributes are optional_.
37
+
To create these shapes you need to pass its `type` and `x` and `y` coordinates for position. The rest of the attributes are optional\_.
34
38
35
39
For the Skeleton API to work, `convertToExcalidrawElements` needs to be called before passing it to Excalidraw Component via initialData, updateScene or any such API.
You can use this prop when you want to access some [Excalidraw APIs](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L616). We expose the below APIs :point_down:
20
21
21
22
| API | Signature | Usage |
22
23
| --- | --- | --- |
23
-
| ready |`boolean`| This is set to true once Excalidraw is rendered |
24
-
|[readyPromise](#readypromise)|`function`| This promise will be resolved with the api once excalidraw has rendered. This will be helpful when you want do some action on the host app once this promise resolves. For this to work you will have to pass ref as shown [here](#readypromise)|
25
24
|[updateScene](#updatescene)|`function`| updates the scene with the sceneData |
26
25
|[updateLibrary](#updatelibrary)|`function`| updates the scene with the sceneData |
27
26
|[addFiles](#addfiles)|`function`| add files data to the appState |
@@ -39,54 +38,15 @@ You can pass a `ref` when you want to access some excalidraw APIs. We expose the
39
38
|[setCursor](#setcursor)|`function`| This API can be used to set customise the mouse cursor on the canvas |
40
39
|[resetCursor](#resetcursor)|`function`| This API can be used to reset to default mouse cursor on the canvas |
41
40
|[toggleMenu](#togglemenu)|`function`| Toggles specific menus on/off |
41
+
|[onChange](#onChange)|`function`| Subscribes to change events |
42
+
|[onPointerDown](#onPointerDown)|`function`| Subscribes to `pointerdown` events |
43
+
|[onPointerUp](#onPointerUp)|`function`| Subscribes to `pointerup` events |
42
44
43
-
## readyPromise
45
+
:::info The `Ref` support has been removed in v0.17.0 so if you are using refs, please update the integration to use the `excalidrawAPI`.
Since plain object is passed as a `ref`, the `readyPromise` is resolved as soon as the component is mounted. Most of the time you will not need this unless you have a specific use case where you can't pass the `ref` in the react way and want to do some action on the host when this promise resolves.
54
-
55
-
```jsx showLineNumbers
56
-
constresolvablePromise= () => {
57
-
let resolve;
58
-
let reject;
59
-
constpromise=newPromise((_resolve, _reject) => {
60
-
resolve = _resolve;
61
-
reject = _reject;
62
-
});
63
-
promise.resolve= resolve;
64
-
promise.reject= reject;
65
-
return promise;
66
-
};
67
-
68
-
constApp= () => {
69
-
constexcalidrawRef=useMemo(
70
-
() => ({
71
-
current: {
72
-
readyPromise:resolvablePromise(),
73
-
},
74
-
}),
75
-
[],
76
-
);
47
+
Additionally `ready` and `readyPromise` from the API have been discontinued. These APIs were found to be superfluous, and as part of the effort to streamline the APIs and maintain simplicity, they were removed in version v0.17.0.
|`type`|[ToolType](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L91)|`selection`| The tool type which should be set as active tool. When setting `image` as active tool, the insertion onto canvas when using image tool is disabled by default, so you can enable it by setting `insertOnCanvasDirectly` to `true`|
368
+
|`locked`|`boolean`|`false`| Indicates whether the the active tool should be locked. It behaves the same way when using the `lock` tool in the editor interface |
398
369
399
370
## setCursor
400
371
@@ -421,3 +392,51 @@ This API is especially useful when you render a custom [`<Sidebar/>`](/docs/@exc
421
392
```
422
393
423
394
This API can be used to reset to default mouse cursor.
395
+
396
+
## onChange
397
+
398
+
```tsx
399
+
(
400
+
callback: (
401
+
elements: readonlyExcalidrawElement[],
402
+
appState: AppState,
403
+
files: BinaryFiles,
404
+
) =>void
405
+
) => () =>void
406
+
```
407
+
408
+
Subscribes to change events, similar to [`props.onChange`](/docs/@excalidraw/excalidraw/api/props#onchange).
Copy file name to clipboardExpand all lines: dev-docs/docs/@excalidraw/excalidraw/api/props/props.mdx
+30-15Lines changed: 30 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
# Props
2
2
3
-
All `props` are *optional*.
3
+
All `props` are _optional_.
4
4
5
5
| Name | Type | Default | Description |
6
6
| --- | --- | --- | --- |
7
-
|[`initialData`](/docs/@excalidraw/excalidraw/api/props/initialdata)|`object`|`null`| <code>Promise<object|null></code> |`null`| The initial data with which app loads. |
8
-
|[`ref`](/docs/@excalidraw/excalidraw/api/props/ref)|`object`|_|`Ref` to be passed to Excalidraw|
7
+
|[`initialData`](/docs/@excalidraw/excalidraw/api/props/initialdata)|`object`|`null`| <code>Promise<object|null></code> |`null`| The initial data with which app loads. |
8
+
|[`excalidrawAPI`](/docs/@excalidraw/excalidraw/api/props/excalidraw-api)|`function`|_|Callback triggered with the excalidraw api once rendered|
9
9
|[`isCollaborating`](#iscollaborating)|`boolean`|_| This indicates if the app is in `collaboration` mode |
10
10
|[`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`. |
11
11
|[`onPointerUpdate`](#onpointerupdate)|`function`|_| Callback triggered when mouse pointer is updated. |
@@ -37,7 +37,7 @@ Beyond attributes that Excalidraw elements already support, you can store `custo
37
37
38
38
You can use this to add any extra information you need to keep track of.
39
39
40
-
You can add `customData` to elements when passing them as [`initialData`](/docs/@excalidraw/excalidraw/api/props/initialdata), or using [`updateScene`](/docs/@excalidraw/excalidraw/api/props/ref#updatescene) / [`updateLibrary`](/docs/@excalidraw/excalidraw/api/props/ref#updatelibrary) afterwards.
40
+
You can add `customData` to elements when passing them as [`initialData`](/docs/@excalidraw/excalidraw/api/props/initialdata), or using [`updateScene`](/docs/@excalidraw/excalidraw/api/props/excalidraw-api#updatescene) / [`updateLibrary`](/docs/@excalidraw/excalidraw/api/props/excalidraw-api#updatelibrary) afterwards.
41
41
42
42
```js showLineNumbers
43
43
{
@@ -93,8 +93,16 @@ This callback is triggered when mouse pointer is updated.
93
93
94
94
This prop if passed will be triggered on pointer down events and has the below signature.
@@ -110,7 +118,11 @@ This prop if passed will be triggered when canvas is scrolled and has the below
110
118
This callback is triggered if passed when something is pasted into the scene. You can use this callback in case you want to do something additional when the paste event occurs.
This callback must return a `boolean` value or a [promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise) which resolves to a boolean value.
@@ -136,8 +148,11 @@ It is invoked with empty items when user clears the library. You can use this ca
136
148
This prop if passed will be triggered when clicked on `link`. To handle the redirect yourself (such as when using your own router for internal links), you must call `event.preventDefault()`.
@@ -180,30 +195,30 @@ import { defaultLang, languages } from "@excalidraw/excalidraw";
180
195
181
196
### viewModeEnabled
182
197
183
-
This prop indicates whether the app is in `view mode`. When supplied, the value takes precedence over *intialData.appState.viewModeEnabled*, the `view mode` will be fully controlled by the host app, and users won't be able to toggle it from within the app.
198
+
This prop indicates whether the app is in `view mode`. When supplied, the value takes precedence over _intialData.appState.viewModeEnabled_, the `view mode` will be fully controlled by the host app, and users won't be able to toggle it from within the app.
184
199
185
200
### zenModeEnabled
186
201
187
-
This prop indicates whether the app is in `zen mode`. When supplied, the value takes precedence over *intialData.appState.zenModeEnabled*, the `zen mode` will be fully controlled by the host app, and users won't be able to toggle it from within the app.
202
+
This prop indicates whether the app is in `zen mode`. When supplied, the value takes precedence over _intialData.appState.zenModeEnabled_, the `zen mode` will be fully controlled by the host app, and users won't be able to toggle it from within the app.
188
203
189
204
### gridModeEnabled
190
205
191
-
This prop indicates whether the shows the grid. When supplied, the value takes precedence over *intialData.appState.gridModeEnabled*, the grid will be fully controlled by the host app, and users won't be able to toggle it from within the app.
206
+
This prop indicates whether the shows the grid. When supplied, the value takes precedence over _intialData.appState.gridModeEnabled_, the grid will be fully controlled by the host app, and users won't be able to toggle it from within the app.
192
207
193
208
### libraryReturnUrl
194
209
195
210
If supplied, this URL will be used when user tries to install a library from [libraries.excalidraw.com](https://libraries.excalidraw.com).
196
-
Defaults to *window.location.origin + window.location.pathname*. To install the libraries in the same tab from which it was opened, you need to set `window.name` (to any alphanumeric string) — if it's not set it will open in a new tab.
211
+
Defaults to _window.location.origin + window.location.pathname_. To install the libraries in the same tab from which it was opened, you need to set `window.name` (to any alphanumeric string) — if it's not set it will open in a new tab.
197
212
198
213
### theme
199
214
200
-
This prop controls Excalidraw's theme. When supplied, the value takes precedence over *intialData.appState.theme*, the theme will be fully controlled by the host app, and users won't be able to toggle it from within the app unless *UIOptions.canvasActions.toggleTheme* is set to `true`, in which case the `theme` prop will control Excalidraw's default theme with ability to allow theme switching (you must take care of updating the `theme` prop when you detect a change to `appState.theme` from the [onChange](#onchange) callback).
215
+
This prop controls Excalidraw's theme. When supplied, the value takes precedence over _intialData.appState.theme_, the theme will be fully controlled by the host app, and users won't be able to toggle it from within the app unless _UIOptions.canvasActions.toggleTheme_ is set to `true`, in which case the `theme` prop will control Excalidraw's default theme with ability to allow theme switching (you must take care of updating the `theme` prop when you detect a change to `appState.theme` from the [onChange](#onchange) callback).
201
216
202
217
You can use [`THEME`](/docs/@excalidraw/excalidraw/api/utils#theme) to specify the theme.
203
218
204
219
### name
205
220
206
-
This prop sets the `name` of the drawing which will be used when exporting the drawing. When supplied, the value takes precedence over *intialData.appState.name*, the `name` will be fully controlled by host app and the users won't be able to edit from within Excalidraw.
221
+
This prop sets the `name` of the drawing which will be used when exporting the drawing. When supplied, the value takes precedence over _intialData.appState.name_, the `name` will be fully controlled by host app and the users won't be able to edit from within Excalidraw.
This is an optional property. By default we support a handful of well-known sites. You may allow additional sites or disallow the default ones by supplying a custom validator. If you pass `true`, all URLs will be allowed. You can also supply a list of hostnames, RegExp (or list of RegExp objects), or a function. If the function returns `undefined`, the built-in validator will be used.
238
253
239
-
Supplying a list of hostnames (with or without `www.`) is the preferred way to allow a specific list of domains.
254
+
Supplying a list of hostnames (with or without `www.`) is the preferred way to allow a specific list of domains.
0 commit comments