2024-01-03 12:13:15 +00:00
|
|
|
import { TLHandle, TLShape, VecModel } from '@tldraw/tlschema'
|
|
|
|
import { VecLike } from '../../primitives/Vec'
|
2023-04-25 11:01:25 +00:00
|
|
|
import { TLSelectionHandle } from './selection-types'
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type UiEventType = 'pointer' | 'click' | 'keyboard' | 'wheel' | 'pinch' | 'zoom'
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLPointerEventTarget =
|
|
|
|
| { target: 'canvas'; shape?: undefined }
|
|
|
|
| { target: 'selection'; handle?: TLSelectionHandle; shape?: undefined }
|
|
|
|
| { target: 'shape'; shape: TLShape }
|
|
|
|
| { target: 'handle'; shape: TLShape; handle: TLHandle }
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLPointerEventName =
|
|
|
|
| 'pointer_down'
|
|
|
|
| 'pointer_move'
|
|
|
|
| 'pointer_up'
|
|
|
|
| 'right_click'
|
|
|
|
| 'middle_click'
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLCLickEventName = 'double_click' | 'triple_click' | 'quadruple_click'
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLPinchEventName = 'pinch_start' | 'pinch' | 'pinch_end'
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLKeyboardEventName = 'key_down' | 'key_up' | 'key_repeat'
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLEventName =
|
|
|
|
| TLPointerEventName
|
|
|
|
| TLCLickEventName
|
|
|
|
| TLPinchEventName
|
|
|
|
| TLKeyboardEventName
|
|
|
|
| 'wheel'
|
|
|
|
| 'cancel'
|
|
|
|
| 'complete'
|
|
|
|
| 'interrupt'
|
[fix] Batch tick events (#3181)
This PR fixes an issue where events happening on tick were not batched.
![Kapture 2024-03-17 at 22 49
52](https://github.com/tldraw/tldraw/assets/23072548/2bcfa335-a38f-46c4-a3f3-434cac61b6ce)
We were listening to the `tick` event directly from the state node,
rather than passing the event into the state chart at the top. This
meant that it was bypassing the regular state chart rules, which was
what got me looking at this; but then I noticed that we also weren't
batching the changes, either. This causes computed stuff to re-compute
after each atom is updated within the `onTick` handler, which can be a
LOT.
Before:
<img width="1557" alt="image"
src="https://github.com/tldraw/tldraw/assets/23072548/ba8791f2-faec-463d-945a-9f5920826aab">
After:
<img width="1204" alt="image"
src="https://github.com/tldraw/tldraw/assets/23072548/a00f8e4a-caca-406a-89a2-8cff0e01b642">
It's not game breaking but it's important enough to hotfix at least in
the dot com.
### Change Type
<!-- ❗ Please select a 'Scope' label ❗️ -->
- [x] `sdk` — Changes the tldraw SDK
- [ ] `dotcom` — Changes the tldraw.com web app
- [ ] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff
<!-- ❗ Please select a 'Type' label ❗️ -->
- [x] `bugfix` — Bug fix
- [ ] `feature` — New feature
- [ ] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `galaxy brain` — Architectural changes
- [ ] `tests` — Changes to any test code
- [ ] `tools` — Changes to infrastructure, CI, internal scripts,
debugging tools, etc.
- [ ] `dunno` — I don't know
### Test Plan
1. Select many shapes.
2. Resize them.
### Release Notes
- Fix a performance issue effecting resizing multiple shapes.
2024-03-18 14:33:36 +00:00
|
|
|
| 'tick'
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export interface TLBaseEventInfo {
|
|
|
|
type: UiEventType
|
|
|
|
shiftKey: boolean
|
|
|
|
altKey: boolean
|
|
|
|
ctrlKey: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLPointerEventInfo = TLBaseEventInfo & {
|
|
|
|
type: 'pointer'
|
|
|
|
name: TLPointerEventName
|
2024-02-04 12:03:49 +00:00
|
|
|
// The pointer position in client space, i.e. clientX / clientY
|
2023-04-25 11:01:25 +00:00
|
|
|
point: VecLike
|
|
|
|
pointerId: number
|
|
|
|
button: number
|
|
|
|
isPen: boolean
|
|
|
|
} & TLPointerEventTarget
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLClickEventInfo = TLBaseEventInfo & {
|
|
|
|
type: 'click'
|
|
|
|
name: TLCLickEventName
|
|
|
|
point: VecLike
|
|
|
|
pointerId: number
|
|
|
|
button: number
|
|
|
|
phase: 'down' | 'up' | 'settle'
|
|
|
|
} & TLPointerEventTarget
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLKeyboardEventInfo = TLBaseEventInfo & {
|
|
|
|
type: 'keyboard'
|
|
|
|
name: TLKeyboardEventName
|
|
|
|
key: string
|
|
|
|
code: string
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLPinchEventInfo = TLBaseEventInfo & {
|
|
|
|
type: 'pinch'
|
|
|
|
name: TLPinchEventName
|
2024-01-03 12:13:15 +00:00
|
|
|
point: VecModel
|
|
|
|
delta: VecModel
|
2023-04-25 11:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLWheelEventInfo = TLBaseEventInfo & {
|
|
|
|
type: 'wheel'
|
|
|
|
name: 'wheel'
|
2024-01-03 12:13:15 +00:00
|
|
|
delta: VecModel
|
|
|
|
point: VecModel
|
2023-04-25 11:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLCancelEventInfo = { type: 'misc'; name: 'cancel' }
|
|
|
|
/** @public */
|
|
|
|
export type TLCompleteEventInfo = { type: 'misc'; name: 'complete' }
|
|
|
|
/** @public */
|
|
|
|
export type TLInterruptEventInfo = { type: 'misc'; name: 'interrupt' }
|
[fix] Batch tick events (#3181)
This PR fixes an issue where events happening on tick were not batched.
![Kapture 2024-03-17 at 22 49
52](https://github.com/tldraw/tldraw/assets/23072548/2bcfa335-a38f-46c4-a3f3-434cac61b6ce)
We were listening to the `tick` event directly from the state node,
rather than passing the event into the state chart at the top. This
meant that it was bypassing the regular state chart rules, which was
what got me looking at this; but then I noticed that we also weren't
batching the changes, either. This causes computed stuff to re-compute
after each atom is updated within the `onTick` handler, which can be a
LOT.
Before:
<img width="1557" alt="image"
src="https://github.com/tldraw/tldraw/assets/23072548/ba8791f2-faec-463d-945a-9f5920826aab">
After:
<img width="1204" alt="image"
src="https://github.com/tldraw/tldraw/assets/23072548/a00f8e4a-caca-406a-89a2-8cff0e01b642">
It's not game breaking but it's important enough to hotfix at least in
the dot com.
### Change Type
<!-- ❗ Please select a 'Scope' label ❗️ -->
- [x] `sdk` — Changes the tldraw SDK
- [ ] `dotcom` — Changes the tldraw.com web app
- [ ] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff
<!-- ❗ Please select a 'Type' label ❗️ -->
- [x] `bugfix` — Bug fix
- [ ] `feature` — New feature
- [ ] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `galaxy brain` — Architectural changes
- [ ] `tests` — Changes to any test code
- [ ] `tools` — Changes to infrastructure, CI, internal scripts,
debugging tools, etc.
- [ ] `dunno` — I don't know
### Test Plan
1. Select many shapes.
2. Resize them.
### Release Notes
- Fix a performance issue effecting resizing multiple shapes.
2024-03-18 14:33:36 +00:00
|
|
|
/** @public */
|
|
|
|
export type TLTickEventInfo = { type: 'misc'; name: 'tick'; elapsed: number }
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLEventInfo =
|
|
|
|
| TLPointerEventInfo
|
|
|
|
| TLClickEventInfo
|
|
|
|
| TLKeyboardEventInfo
|
|
|
|
| TLPinchEventInfo
|
|
|
|
| TLWheelEventInfo
|
|
|
|
| TLCancelEventInfo
|
|
|
|
| TLCompleteEventInfo
|
|
|
|
| TLInterruptEventInfo
|
[fix] Batch tick events (#3181)
This PR fixes an issue where events happening on tick were not batched.
![Kapture 2024-03-17 at 22 49
52](https://github.com/tldraw/tldraw/assets/23072548/2bcfa335-a38f-46c4-a3f3-434cac61b6ce)
We were listening to the `tick` event directly from the state node,
rather than passing the event into the state chart at the top. This
meant that it was bypassing the regular state chart rules, which was
what got me looking at this; but then I noticed that we also weren't
batching the changes, either. This causes computed stuff to re-compute
after each atom is updated within the `onTick` handler, which can be a
LOT.
Before:
<img width="1557" alt="image"
src="https://github.com/tldraw/tldraw/assets/23072548/ba8791f2-faec-463d-945a-9f5920826aab">
After:
<img width="1204" alt="image"
src="https://github.com/tldraw/tldraw/assets/23072548/a00f8e4a-caca-406a-89a2-8cff0e01b642">
It's not game breaking but it's important enough to hotfix at least in
the dot com.
### Change Type
<!-- ❗ Please select a 'Scope' label ❗️ -->
- [x] `sdk` — Changes the tldraw SDK
- [ ] `dotcom` — Changes the tldraw.com web app
- [ ] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff
<!-- ❗ Please select a 'Type' label ❗️ -->
- [x] `bugfix` — Bug fix
- [ ] `feature` — New feature
- [ ] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `galaxy brain` — Architectural changes
- [ ] `tests` — Changes to any test code
- [ ] `tools` — Changes to infrastructure, CI, internal scripts,
debugging tools, etc.
- [ ] `dunno` — I don't know
### Test Plan
1. Select many shapes.
2. Resize them.
### Release Notes
- Fix a performance issue effecting resizing multiple shapes.
2024-03-18 14:33:36 +00:00
|
|
|
| TLTickEventInfo
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLPointerEvent = (info: TLPointerEventInfo) => void
|
|
|
|
/** @public */
|
|
|
|
export type TLClickEvent = (info: TLClickEventInfo) => void
|
|
|
|
/** @public */
|
|
|
|
export type TLKeyboardEvent = (info: TLKeyboardEventInfo) => void
|
|
|
|
/** @public */
|
|
|
|
export type TLPinchEvent = (info: TLPinchEventInfo) => void
|
|
|
|
/** @public */
|
|
|
|
export type TLWheelEvent = (info: TLWheelEventInfo) => void
|
|
|
|
/** @public */
|
|
|
|
export type TLCancelEvent = (info: TLCancelEventInfo) => void
|
|
|
|
/** @public */
|
|
|
|
export type TLCompleteEvent = (info: TLCompleteEventInfo) => void
|
|
|
|
/** @public */
|
|
|
|
export type TLInterruptEvent = (info: TLInterruptEventInfo) => void
|
[fix] Batch tick events (#3181)
This PR fixes an issue where events happening on tick were not batched.
![Kapture 2024-03-17 at 22 49
52](https://github.com/tldraw/tldraw/assets/23072548/2bcfa335-a38f-46c4-a3f3-434cac61b6ce)
We were listening to the `tick` event directly from the state node,
rather than passing the event into the state chart at the top. This
meant that it was bypassing the regular state chart rules, which was
what got me looking at this; but then I noticed that we also weren't
batching the changes, either. This causes computed stuff to re-compute
after each atom is updated within the `onTick` handler, which can be a
LOT.
Before:
<img width="1557" alt="image"
src="https://github.com/tldraw/tldraw/assets/23072548/ba8791f2-faec-463d-945a-9f5920826aab">
After:
<img width="1204" alt="image"
src="https://github.com/tldraw/tldraw/assets/23072548/a00f8e4a-caca-406a-89a2-8cff0e01b642">
It's not game breaking but it's important enough to hotfix at least in
the dot com.
### Change Type
<!-- ❗ Please select a 'Scope' label ❗️ -->
- [x] `sdk` — Changes the tldraw SDK
- [ ] `dotcom` — Changes the tldraw.com web app
- [ ] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff
<!-- ❗ Please select a 'Type' label ❗️ -->
- [x] `bugfix` — Bug fix
- [ ] `feature` — New feature
- [ ] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `galaxy brain` — Architectural changes
- [ ] `tests` — Changes to any test code
- [ ] `tools` — Changes to infrastructure, CI, internal scripts,
debugging tools, etc.
- [ ] `dunno` — I don't know
### Test Plan
1. Select many shapes.
2. Resize them.
### Release Notes
- Fix a performance issue effecting resizing multiple shapes.
2024-03-18 14:33:36 +00:00
|
|
|
/** @public */
|
|
|
|
export type TLTickEvent = (info: TLTickEventInfo) => void
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type UiEvent =
|
|
|
|
| TLPointerEvent
|
|
|
|
| TLClickEvent
|
|
|
|
| TLKeyboardEvent
|
|
|
|
| TLPinchEvent
|
|
|
|
| TLCancelEvent
|
|
|
|
| TLCompleteEvent
|
|
|
|
|
|
|
|
/** @public */
|
2023-06-04 10:38:53 +00:00
|
|
|
export type TLEnterEventHandler = (info: any, from: string) => void
|
2023-04-25 11:01:25 +00:00
|
|
|
/** @public */
|
2023-06-04 10:38:53 +00:00
|
|
|
export type TLExitEventHandler = (info: any, to: string) => void
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export interface TLEventHandlers {
|
|
|
|
onPointerDown: TLPointerEvent
|
|
|
|
onPointerMove: TLPointerEvent
|
|
|
|
onRightClick: TLPointerEvent
|
|
|
|
onDoubleClick: TLClickEvent
|
|
|
|
onTripleClick: TLClickEvent
|
|
|
|
onQuadrupleClick: TLClickEvent
|
|
|
|
onMiddleClick: TLPointerEvent
|
|
|
|
onPointerUp: TLPointerEvent
|
|
|
|
onKeyDown: TLKeyboardEvent
|
|
|
|
onKeyUp: TLKeyboardEvent
|
|
|
|
onKeyRepeat: TLKeyboardEvent
|
|
|
|
onWheel: TLWheelEvent
|
|
|
|
onCancel: TLCancelEvent
|
|
|
|
onComplete: TLCompleteEvent
|
|
|
|
onInterrupt: TLInterruptEvent
|
[fix] Batch tick events (#3181)
This PR fixes an issue where events happening on tick were not batched.
![Kapture 2024-03-17 at 22 49
52](https://github.com/tldraw/tldraw/assets/23072548/2bcfa335-a38f-46c4-a3f3-434cac61b6ce)
We were listening to the `tick` event directly from the state node,
rather than passing the event into the state chart at the top. This
meant that it was bypassing the regular state chart rules, which was
what got me looking at this; but then I noticed that we also weren't
batching the changes, either. This causes computed stuff to re-compute
after each atom is updated within the `onTick` handler, which can be a
LOT.
Before:
<img width="1557" alt="image"
src="https://github.com/tldraw/tldraw/assets/23072548/ba8791f2-faec-463d-945a-9f5920826aab">
After:
<img width="1204" alt="image"
src="https://github.com/tldraw/tldraw/assets/23072548/a00f8e4a-caca-406a-89a2-8cff0e01b642">
It's not game breaking but it's important enough to hotfix at least in
the dot com.
### Change Type
<!-- ❗ Please select a 'Scope' label ❗️ -->
- [x] `sdk` — Changes the tldraw SDK
- [ ] `dotcom` — Changes the tldraw.com web app
- [ ] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff
<!-- ❗ Please select a 'Type' label ❗️ -->
- [x] `bugfix` — Bug fix
- [ ] `feature` — New feature
- [ ] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `galaxy brain` — Architectural changes
- [ ] `tests` — Changes to any test code
- [ ] `tools` — Changes to infrastructure, CI, internal scripts,
debugging tools, etc.
- [ ] `dunno` — I don't know
### Test Plan
1. Select many shapes.
2. Resize them.
### Release Notes
- Fix a performance issue effecting resizing multiple shapes.
2024-03-18 14:33:36 +00:00
|
|
|
onTick: TLTickEvent
|
2023-04-25 11:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export const EVENT_NAME_MAP: Record<
|
|
|
|
Exclude<TLEventName, TLPinchEventName>,
|
|
|
|
keyof TLEventHandlers
|
|
|
|
> = {
|
|
|
|
wheel: 'onWheel',
|
|
|
|
pointer_down: 'onPointerDown',
|
|
|
|
pointer_move: 'onPointerMove',
|
|
|
|
pointer_up: 'onPointerUp',
|
|
|
|
right_click: 'onRightClick',
|
|
|
|
middle_click: 'onMiddleClick',
|
|
|
|
key_down: 'onKeyDown',
|
|
|
|
key_up: 'onKeyUp',
|
|
|
|
key_repeat: 'onKeyRepeat',
|
|
|
|
cancel: 'onCancel',
|
|
|
|
complete: 'onComplete',
|
|
|
|
interrupt: 'onInterrupt',
|
|
|
|
double_click: 'onDoubleClick',
|
|
|
|
triple_click: 'onTripleClick',
|
|
|
|
quadruple_click: 'onQuadrupleClick',
|
[fix] Batch tick events (#3181)
This PR fixes an issue where events happening on tick were not batched.
![Kapture 2024-03-17 at 22 49
52](https://github.com/tldraw/tldraw/assets/23072548/2bcfa335-a38f-46c4-a3f3-434cac61b6ce)
We were listening to the `tick` event directly from the state node,
rather than passing the event into the state chart at the top. This
meant that it was bypassing the regular state chart rules, which was
what got me looking at this; but then I noticed that we also weren't
batching the changes, either. This causes computed stuff to re-compute
after each atom is updated within the `onTick` handler, which can be a
LOT.
Before:
<img width="1557" alt="image"
src="https://github.com/tldraw/tldraw/assets/23072548/ba8791f2-faec-463d-945a-9f5920826aab">
After:
<img width="1204" alt="image"
src="https://github.com/tldraw/tldraw/assets/23072548/a00f8e4a-caca-406a-89a2-8cff0e01b642">
It's not game breaking but it's important enough to hotfix at least in
the dot com.
### Change Type
<!-- ❗ Please select a 'Scope' label ❗️ -->
- [x] `sdk` — Changes the tldraw SDK
- [ ] `dotcom` — Changes the tldraw.com web app
- [ ] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff
<!-- ❗ Please select a 'Type' label ❗️ -->
- [x] `bugfix` — Bug fix
- [ ] `feature` — New feature
- [ ] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `galaxy brain` — Architectural changes
- [ ] `tests` — Changes to any test code
- [ ] `tools` — Changes to infrastructure, CI, internal scripts,
debugging tools, etc.
- [ ] `dunno` — I don't know
### Test Plan
1. Select many shapes.
2. Resize them.
### Release Notes
- Fix a performance issue effecting resizing multiple shapes.
2024-03-18 14:33:36 +00:00
|
|
|
tick: 'onTick',
|
2023-04-25 11:01:25 +00:00
|
|
|
}
|