
Biome as it is now didn't work out for us 😢 Summary for posterity: * it IS much, much faster, fast enough to skip any sort of caching * we couldn't fully replace Prettier just yet. We use Prettier programmatically to format code in docs, and Biome's JS interface is officially alpha and [had legacy peer deps set](https://github.com/biomejs/biome/pull/1756) (which would fail our CI build as we don't allow installation warnings) * ternary formatting differs from Prettier, leading to a large diff https://github.com/biomejs/biome/issues/1661 * import sorting differs from Prettier's `prettier-plugin-organize-imports`, making the diff even bigger * the deal breaker is a multi-second delay on saving large files (for us it's [Editor.ts](https://github.com/tldraw/tldraw/blob/main/packages/editor/src/lib/editor/Editor.ts)) in VSCode when import sorting is enabled. There is a seemingly relevant Biome issue where I posted a small summary of our findings: https://github.com/biomejs/biome/issues/1569#issuecomment-1930411623 Further actions: * reevaluate in a few months as Biome matures ### Change Type - [x] `internal` — Any other changes that don't affect the published package
71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
import {
|
|
StateNode,
|
|
TLClickEvent,
|
|
TLEventHandlers,
|
|
TLGroupShape,
|
|
TLPointerEventInfo,
|
|
} from '@tldraw/editor'
|
|
import { selectOnCanvasPointerUp } from '../../selection-logic/selectOnCanvasPointerUp'
|
|
|
|
export class PointingSelection extends StateNode {
|
|
static override id = 'pointing_selection'
|
|
|
|
info = {} as TLPointerEventInfo & {
|
|
target: 'selection'
|
|
}
|
|
|
|
override onEnter = (info: TLPointerEventInfo & { target: 'selection' }) => {
|
|
this.info = info
|
|
}
|
|
|
|
override onPointerUp: TLEventHandlers['onPointerUp'] = (info) => {
|
|
selectOnCanvasPointerUp(this.editor)
|
|
this.parent.transition('idle', info)
|
|
}
|
|
|
|
override onPointerMove: TLEventHandlers['onPointerMove'] = (info) => {
|
|
if (this.editor.inputs.isDragging) {
|
|
if (this.editor.getInstanceState().isReadonly) return
|
|
this.parent.transition('translating', info)
|
|
}
|
|
}
|
|
|
|
override onDoubleClick?: TLClickEvent | undefined = (info) => {
|
|
const hoveredShape = this.editor.getHoveredShape()
|
|
const hitShape =
|
|
hoveredShape && !this.editor.isShapeOfType<TLGroupShape>(hoveredShape, 'group')
|
|
? hoveredShape
|
|
: this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint, {
|
|
hitInside: true,
|
|
margin: 0,
|
|
renderingOnly: true,
|
|
})
|
|
|
|
if (hitShape) {
|
|
// todo: extract the double click shape logic from idle so that we can share it here
|
|
this.parent.transition('idle')
|
|
this.parent.onDoubleClick?.({
|
|
...info,
|
|
target: 'shape',
|
|
shape: this.editor.getShape(hitShape)!,
|
|
})
|
|
return
|
|
}
|
|
}
|
|
|
|
override onCancel: TLEventHandlers['onCancel'] = () => {
|
|
this.cancel()
|
|
}
|
|
|
|
override onComplete: TLEventHandlers['onComplete'] = () => {
|
|
this.cancel()
|
|
}
|
|
|
|
override onInterrupt = () => {
|
|
this.cancel()
|
|
}
|
|
|
|
private cancel() {
|
|
this.parent.transition('idle')
|
|
}
|
|
}
|