{ "version": 3, "sources": ["../../../../../src/lib/tools/SelectTool/children/EditingShape.ts"], "sourcesContent": ["import {\n\tGroup2d,\n\tStateNode,\n\tTLArrowShape,\n\tTLEventHandlers,\n\tTLFrameShape,\n\tTLGeoShape,\n} from '@tldraw/editor'\nimport { getHitShapeOnCanvasPointerDown } from '../../selection-logic/getHitShapeOnCanvasPointerDown'\nimport { updateHoveredId } from '../../selection-logic/updateHoveredId'\n\nexport class EditingShape extends StateNode {\n\tstatic override id = 'editing_shape'\n\n\toverride onEnter = () => {\n\t\tconst { editingShape } = this.editor\n\t\tif (!editingShape) throw Error('Entered editing state without an editing shape')\n\t\tupdateHoveredId(this.editor)\n\t\tthis.editor.select(editingShape)\n\t}\n\n\toverride onExit = () => {\n\t\tconst { editingShapeId } = this.editor.currentPageState\n\t\tif (!editingShapeId) return\n\n\t\t// Clear the editing shape\n\t\tthis.editor.setEditingShape(null)\n\n\t\tconst shape = this.editor.getShape(editingShapeId)!\n\t\tconst util = this.editor.getShapeUtil(shape)\n\n\t\t// Check for changes on editing end\n\t\tutil.onEditEnd?.(shape)\n\n\t\tsetTimeout(() => {\n\t\t\tthis.editor.updateViewportScreenBounds()\n\t\t}, 500)\n\t}\n\n\toverride onPointerMove: TLEventHandlers['onPointerMove'] = (info) => {\n\t\tswitch (info.target) {\n\t\t\tcase 'shape':\n\t\t\tcase 'canvas': {\n\t\t\t\tupdateHoveredId(this.editor)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\toverride onPointerDown: TLEventHandlers['onPointerDown'] = (info) => {\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\tconst hitShape = getHitShapeOnCanvasPointerDown(this.editor)\n\t\t\t\tif (hitShape) {\n\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t...info,\n\t\t\t\t\t\tshape: hitShape,\n\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tconst { shape } = info\n\t\t\t\tconst { editingShape } = this.editor\n\n\t\t\t\tif (!editingShape) {\n\t\t\t\t\tthrow Error('Expected an editing shape!')\n\t\t\t\t}\n\n\t\t\t\tif (shape.type === editingShape.type) {\n\t\t\t\t\t// clicked a shape of the same type as the editing shape\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.editor.isShapeOfType(shape, 'geo') ||\n\t\t\t\t\t\tthis.editor.isShapeOfType(shape, 'arrow')\n\t\t\t\t\t) {\n\t\t\t\t\t\t// for shapes with labels, check to see if the click was inside of the shape's label\n\t\t\t\t\t\tconst geometry = this.editor.getShapeUtil(shape).getGeometry(shape) as Group2d\n\t\t\t\t\t\tconst labelGeometry = geometry.children[1]\n\t\t\t\t\t\tif (labelGeometry) {\n\t\t\t\t\t\t\tconst pointInShapeSpace = this.editor.getPointInShapeSpace(\n\t\t\t\t\t\t\t\tshape,\n\t\t\t\t\t\t\t\tthis.editor.inputs.currentPagePoint\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (labelGeometry.bounds.containsPoint(pointInShapeSpace)) {\n\t\t\t\t\t\t\t\t// it's a hit to the label!\n\t\t\t\t\t\t\t\tif (shape.id === editingShape.id) {\n\t\t\t\t\t\t\t\t\t// If we clicked on the editing geo / arrow shape's label, do nothing\n\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\t\t\t\t\t\treturn\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 {\n\t\t\t\t\t\tif (shape.id === editingShape.id) {\n\t\t\t\t\t\t\t// If we clicked on a frame, while editing its heading, cancel editing\n\t\t\t\t\t\t\tif (this.editor.isShapeOfType(shape, 'frame')) {\n\t\t\t\t\t\t\t\tthis.editor.setEditingShape(null)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// If we clicked on the editing shape (which isn't a shape with a label), do nothing\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// But if we clicked on a different shape of the same type, transition to pointing_shape instead\n\t\t\t\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// clicked a different kind of shape\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\t// still here? Cancel editing and transition back to select idle\n\t\tthis.parent.transition('idle', info)\n\t\t// then feed the pointer down event back into the state chart as if it happened in that state\n\t\tthis.editor.root.handleEvent(info)\n\t}\n\n\toverride onComplete: TLEventHandlers['onComplete'] = (info) => {\n\t\tthis.parent.transition('idle', info)\n\t}\n\n\toverride onCancel: TLEventHandlers['onCancel'] = (info) => {\n\t\tthis.parent.transition('idle', info)\n\t}\n}\n"], "mappings": "AAAA;AAAA,EAEC;AAAA,OAKM;AACP,SAAS,sCAAsC;AAC/C,SAAS,uBAAuB;AAEzB,MAAM,qBAAqB,UAAU;AAAA,EAC3C,OAAgB,KAAK;AAAA,EAEZ,UAAU,MAAM;AACxB,UAAM,EAAE,aAAa,IAAI,KAAK;AAC9B,QAAI,CAAC;AAAc,YAAM,MAAM,gDAAgD;AAC/E,oBAAgB,KAAK,MAAM;AAC3B,SAAK,OAAO,OAAO,YAAY;AAAA,EAChC;AAAA,EAES,SAAS,MAAM;AACvB,UAAM,EAAE,eAAe,IAAI,KAAK,OAAO;AACvC,QAAI,CAAC;AAAgB;AAGrB,SAAK,OAAO,gBAAgB,IAAI;AAEhC,UAAM,QAAQ,KAAK,OAAO,SAAS,cAAc;AACjD,UAAM,OAAO,KAAK,OAAO,aAAa,KAAK;AAG3C,SAAK,YAAY,KAAK;AAEtB,eAAW,MAAM;AAChB,WAAK,OAAO,2BAA2B;AAAA,IACxC,GAAG,GAAG;AAAA,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