tldraw
Version:
A tiny little drawing editor.
8 lines (7 loc) • 2.17 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../../src/lib/tools/SelectTool/selectHelpers.ts"],
"sourcesContent": ["import {\n\tEditor,\n\tExtractShapeByProps,\n\trichTextValidator,\n\tTLEventInfo,\n\tTLRichText,\n\tTLShape,\n\tTLShapeId,\n} from '@tldraw/editor'\n\n/** @internal */\nexport function hasRichText(\n\tshape: TLShape\n): shape is ExtractShapeByProps<{ richText: TLRichText }> {\n\treturn 'richText' in shape.props && richTextValidator.isValid(shape.props.richText)\n}\n/**\n * Start editing a shape that has rich text, such as text, note, geo, or arrow shapes.\n * This will enter the editing state for the shape and optionally select all the text.\n *\n * @param editor - The editor instance.\n * @param shapeOrId - The shape to start editing. This shape must have a richText property with a TLRichText value.\n * @param options - Options: selectAll or info (TLEventInfo)\n *\n * @public\n */\nexport function startEditingShapeWithRichText(\n\teditor: Editor,\n\tshapeOrId: TLShape | TLShapeId,\n\toptions: { selectAll?: boolean; info?: TLEventInfo } = {}\n) {\n\tconst shape = typeof shapeOrId === 'string' ? editor.getShape(shapeOrId) : shapeOrId\n\tif (!shape) return\n\n\tif (!editor.canEditShape(shape)) return\n\n\tif (!hasRichText(shape)) {\n\t\tthrow new Error('Shape does not have rich text')\n\t}\n\t// Finish this shape and start editing the next one\n\teditor.setEditingShape(shape)\n\teditor.setCurrentTool('select.editing_shape', {\n\t\t...options.info,\n\t\ttarget: 'shape',\n\t\tshape: shape,\n\t})\n\tif (options.selectAll) {\n\t\teditor.emit('select-all-text', { shapeId: shape.id })\n\t}\n}\n"],
"mappings": "AAAA;AAAA,EAGC;AAAA,OAKM;AAGA,SAAS,YACf,OACyD;AACzD,SAAO,cAAc,MAAM,SAAS,kBAAkB,QAAQ,MAAM,MAAM,QAAQ;AACnF;AAWO,SAAS,8BACf,QACA,WACA,UAAuD,CAAC,GACvD;AACD,QAAM,QAAQ,OAAO,cAAc,WAAW,OAAO,SAAS,SAAS,IAAI;AAC3E,MAAI,CAAC,MAAO;AAEZ,MAAI,CAAC,OAAO,aAAa,KAAK,EAAG;AAEjC,MAAI,CAAC,YAAY,KAAK,GAAG;AACxB,UAAM,IAAI,MAAM,+BAA+B;AAAA,EAChD;AAEA,SAAO,gBAAgB,KAAK;AAC5B,SAAO,eAAe,wBAAwB;AAAA,IAC7C,GAAG,QAAQ;AAAA,IACX,QAAQ;AAAA,IACR;AAAA,EACD,CAAC;AACD,MAAI,QAAQ,WAAW;AACtB,WAAO,KAAK,mBAAmB,EAAE,SAAS,MAAM,GAAG,CAAC;AAAA,EACrD;AACD;",
"names": []
}