kopia lustrzana https://github.com/Tldraw/Tldraw
48 wiersze
1.3 KiB
TypeScript
48 wiersze
1.3 KiB
TypeScript
import { StateNode, TLEventHandlers } from '@tldraw/editor'
|
|
import { updateHoveredShapeId } from '../../../tools/selection-logic/updateHoveredShapeId'
|
|
|
|
export class Idle extends StateNode {
|
|
static override id = 'idle'
|
|
|
|
override onPointerMove: TLEventHandlers['onPointerMove'] = (info) => {
|
|
switch (info.target) {
|
|
case 'shape':
|
|
case 'canvas': {
|
|
updateHoveredShapeId(this.editor)
|
|
}
|
|
}
|
|
}
|
|
|
|
override onPointerDown: TLEventHandlers['onPointerDown'] = (info) => {
|
|
this.parent.transition('pointing', info)
|
|
}
|
|
|
|
override onEnter = () => {
|
|
this.editor.setCursor({ type: 'cross', rotation: 0 })
|
|
}
|
|
|
|
override onKeyDown: TLEventHandlers['onKeyDown'] = (info) => {
|
|
if (info.key === 'Enter') {
|
|
if (this.editor.getInstanceState().isReadonly) return null
|
|
const onlySelectedShape = this.editor.getOnlySelectedShape()
|
|
// If the only selected shape is editable, start editing it
|
|
if (
|
|
onlySelectedShape &&
|
|
this.editor.getShapeUtil(onlySelectedShape).canEdit(onlySelectedShape)
|
|
) {
|
|
this.editor.setCurrentTool('select')
|
|
this.editor.setEditingShape(onlySelectedShape.id)
|
|
this.editor.root.getCurrent()?.transition('editing_shape', {
|
|
...info,
|
|
target: 'shape',
|
|
shape: onlySelectedShape,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
override onCancel = () => {
|
|
this.editor.setCurrentTool('select')
|
|
}
|
|
}
|