Skip to content

Commit

Permalink
Emit an event when camera options change
Browse files Browse the repository at this point in the history
This allows you to listen to changes to `autoWheelBehavior` and store it
in e.g. local storage so you can initialize it to the same value the
next time tldraw is laoded.
  • Loading branch information
trygve-aaberge-adsk committed Oct 22, 2024
1 parent 51e7311 commit f7f9f55
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/editor/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -2982,6 +2982,8 @@ export type TLEventInfo = TLCancelEventInfo | TLClickEventInfo | TLCompleteEvent

// @public (undocumented)
export interface TLEventMap {
// (undocumented)
'camera-options-changed': [TLCameraOptions];
// (undocumented)
'max-shapes': [{
count: number;
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/lib/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2440,6 +2440,7 @@ export class Editor extends EventEmitter<TLEventMap> {
if (next.zoomSteps?.length < 1) next.zoomSteps = [1]
this._cameraOptions.set(next)
this.setCamera(this.getCamera())
this.emit('camera-options-changed', next)
return this
}

Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/lib/editor/types/emit-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HistoryEntry } from '@tldraw/store'
import { TLPageId, TLRecord, TLShapeId } from '@tldraw/tlschema'
import { TLEventInfo } from './event-types'
import { TLCameraOptions } from './misc-types'

/** @public */
export interface TLEventMap {
Expand All @@ -16,6 +17,7 @@ export interface TLEventMap {
tick: [number]
frame: [number]
'select-all-text': [{ shapeId: TLShapeId }]
'camera-options-changed': [TLCameraOptions]
}

/** @public */
Expand Down

0 comments on commit f7f9f55

Please sign in to comment.