tldraw
Version:
A tiny little drawing editor.
8 lines (7 loc) • 3.8 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/lib/defaultSideEffects.ts"],
"sourcesContent": ["import { Editor } from '@tldraw/editor'\nimport { updateHoveredShapeId } from './tools/selection-logic/updateHoveredShapeId'\n\n/** @public */\nexport function registerDefaultSideEffects(editor: Editor) {\n\treturn editor.sideEffects.register({\n\t\tinstance: {\n\t\t\tafterChange: (prev, next) => {\n\t\t\t\tif (prev.cameraState !== next.cameraState && next.cameraState === 'idle') {\n\t\t\t\t\tupdateHoveredShapeId(editor)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\tinstance_page_state: {\n\t\t\tafterChange: (prev, next) => {\n\t\t\t\tif (prev.croppingShapeId !== next.croppingShapeId) {\n\t\t\t\t\tconst isInCroppingState = editor.isIn('select.crop')\n\t\t\t\t\tif (!prev.croppingShapeId && next.croppingShapeId) {\n\t\t\t\t\t\tif (!isInCroppingState) {\n\t\t\t\t\t\t\teditor.setCurrentTool('select.crop.idle')\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (prev.croppingShapeId && !next.croppingShapeId) {\n\t\t\t\t\t\tif (isInCroppingState) {\n\t\t\t\t\t\t\teditor.setCurrentTool('select.idle')\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (prev.editingShapeId !== next.editingShapeId) {\n\t\t\t\t\tif (!prev.editingShapeId && next.editingShapeId) {\n\t\t\t\t\t\tif (!editor.isIn('select.editing_shape')) {\n\t\t\t\t\t\t\t// Here's where we handle the special tool locking case for text\n\t\t\t\t\t\t\t// If tool lock is enabled, and we just finished editing a text\n\t\t\t\t\t\t\t// shape and are setting that shape as the new editing shape,\n\t\t\t\t\t\t\t// then create the shape with a flag that will let it know to\n\t\t\t\t\t\t\t// go back to the text tool once the edit is complete.\n\t\t\t\t\t\t\tconst shape = editor.getEditingShape()\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tshape &&\n\t\t\t\t\t\t\t\tshape.type === 'text' &&\n\t\t\t\t\t\t\t\teditor.isInAny('text.pointing', 'select.resizing') &&\n\t\t\t\t\t\t\t\teditor.getInstanceState().isToolLocked\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\teditor.setCurrentTool('select.editing_shape', {\n\t\t\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\t\t\tshape: shape,\n\t\t\t\t\t\t\t\t\tisCreatingTextWhileToolLocked: true,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\teditor.setCurrentTool('select.editing_shape', {\n\t\t\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\t\t\tshape: shape,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (prev.editingShapeId && !next.editingShapeId) {\n\t\t\t\t\t\tif (editor.isIn('select.editing_shape')) {\n\t\t\t\t\t\t\teditor.setCurrentTool('select.idle')\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t})\n}\n"],
"mappings": "AACA,SAAS,4BAA4B;AAG9B,SAAS,2BAA2B,QAAgB;AAC1D,SAAO,OAAO,YAAY,SAAS;AAAA,IAClC,UAAU;AAAA,MACT,aAAa,CAAC,MAAM,SAAS;AAC5B,YAAI,KAAK,gBAAgB,KAAK,eAAe,KAAK,gBAAgB,QAAQ;AACzE,+BAAqB,MAAM;AAAA,QAC5B;AAAA,MACD;AAAA,IACD;AAAA,IACA,qBAAqB;AAAA,MACpB,aAAa,CAAC,MAAM,SAAS;AAC5B,YAAI,KAAK,oBAAoB,KAAK,iBAAiB;AAClD,gBAAM,oBAAoB,OAAO,KAAK,aAAa;AACnD,cAAI,CAAC,KAAK,mBAAmB,KAAK,iBAAiB;AAClD,gBAAI,CAAC,mBAAmB;AACvB,qBAAO,eAAe,kBAAkB;AAAA,Y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