{
  "version": 3,
  "sources": ["../../../../src/lib/shapes/frame/FrameShapeTool.ts"],
  "sourcesContent": ["import { BaseBoxShapeTool, Editor, TLShape, TLShapeId } from '@tldraw/editor'\n\n/** @public */\nexport class FrameShapeTool extends BaseBoxShapeTool {\n\tstatic override id = 'frame'\n\tstatic override initial = 'idle'\n\toverride shapeType = 'frame' as const\n\n\toverride onCreate(shape: TLShape | null): void {\n\t\tif (!shape) return\n\n\t\tthis.editor.reparentShapes(getEnclosedShapeIds(this.editor, shape), shape.id)\n\n\t\tif (this.editor.getInstanceState().isToolLocked) {\n\t\t\tthis.editor.setCurrentTool('frame')\n\t\t} else {\n\t\t\tthis.editor.setCurrentTool('select.idle')\n\t\t}\n\t}\n}\n\n/**\n * Get the ids of the sibling shapes that a frame would enclose at its current page bounds.\n *\n * @internal\n */\nexport function getEnclosedShapeIds(editor: Editor, shape: TLShape): TLShapeId[] {\n\tconst bounds = editor.getShapePageBounds(shape)\n\tif (!bounds) return []\n\n\tconst enclosedShapeIds: TLShapeId[] = []\n\tconst ancestorIds = editor.getShapeAncestors(shape).map((shape) => shape.id)\n\n\teditor.getSortedChildIdsForParent(shape.parentId).map((siblingShapeId) => {\n\t\tconst siblingShape = editor.getShape(siblingShapeId)\n\t\tif (!siblingShape) return\n\t\t// We don't want to frame the frame itself\n\t\tif (siblingShape.id === shape.id) return\n\t\tif (siblingShape.isLocked) return\n\n\t\tconst pageShapeBounds = editor.getShapePageBounds(siblingShape)\n\t\tif (!pageShapeBounds) return\n\n\t\t// Frame shape encloses page shape\n\t\tif (bounds.contains(pageShapeBounds)) {\n\t\t\tif (canEnclose(siblingShape, ancestorIds, shape)) {\n\t\t\t\tenclosedShapeIds.push(siblingShape.id)\n\t\t\t}\n\t\t}\n\t})\n\n\treturn enclosedShapeIds\n}\n\n/** @internal */\nfunction canEnclose(shape: TLShape, ancestorIds: TLShapeId[], frame: TLShape): boolean {\n\t// We don't want to pull in shapes that are ancestors of the frame (can create a cycle)\n\tif (ancestorIds.includes(shape.id)) {\n\t\treturn false\n\t}\n\t// We only want to pull in shapes that are siblings of the frame\n\tif (shape.parentId === frame.parentId) {\n\t\treturn true\n\t}\n\treturn false\n}\n"],
  "mappings": "AAAA,SAAS,wBAAoD;AAGtD,MAAM,uBAAuB,iBAAiB;AAAA,EACpD,OAAgB,KAAK;AAAA,EACrB,OAAgB,UAAU;AAAA,EACjB,YAAY;AAAA,EAEZ,SAAS,OAA6B;AAC9C,QAAI,CAAC,MAAO;AAEZ,SAAK,OAAO,eAAe,oBAAoB,KAAK,QAAQ,KAAK,GAAG,MAAM,EAAE;AAE5E,QAAI,KAAK,OAAO,iBAAiB,EAAE,cAAc;AAChD,WAAK,OAAO,eAAe,OAAO;AAAA,IACnC,OAAO;AACN,WAAK,OAAO,eAAe,aAAa;AAAA,IACzC;AAAA,EACD;AACD;AAOO,SAAS,oBAAoB,QAAgB,OAA6B;AAChF,QAAM,SAAS,OAAO,mBAAmB,KAAK;AAC9C,MAAI,CAAC,OAAQ,QAAO,CAAC;AAErB,QAAM,mBAAgC,CAAC;AACvC,QAAM,cAAc,OAAO,kBAAkB,KAAK,EAAE,IAAI,CAACA,WAAUA,OAAM,EAAE;AAE3E,SAAO,2BAA2B,MAAM,QAAQ,EAAE,IAAI,CAAC,mBAAmB;AACzE,UAAM,eAAe,OAAO,SAAS,cAAc;AACnD,QAAI,CAAC,aAAc;AAEnB,QAAI,aAAa,OAAO,MAAM,GAAI;AAClC,QAAI,aAAa,SAAU;AAE3B,UAAM,kBAAkB,OAAO,mBAAmB,YAAY;AAC9D,QAAI,CAAC,gBAAiB;AAGtB,QAAI,OAAO,SAAS,eAAe,GAAG;AACrC,UAAI,WAAW,cAAc,aAAa,KAAK,GAAG;AACjD,yBAAiB,KAAK,aAAa,EAAE;AAAA,MACtC;AAAA,IACD;AAAA,EACD,CAAC;AAED,SAAO;AACR;AAGA,SAAS,WAAW,OAAgB,aAA0B,OAAyB;AAEtF,MAAI,YAAY,SAAS,MAAM,EAAE,GAAG;AACnC,WAAO;AAAA,EACR;AAEA,MAAI,MAAM,aAAa,MAAM,UAAU;AACtC,WAAO;AAAA,EACR;AACA,SAAO;AACR;",
  "names": ["shape"]
}
