UNPKG

tldraw

Version:

A tiny little drawing editor.

8 lines (7 loc) 1.55 kB
{ "version": 3, "sources": ["../../../../../src/lib/ui/hooks/clipboard/pasteTldrawContent.ts"], "sourcesContent": ["import { Editor, TLContent, VecLike } from '@tldraw/editor'\n\n/**\n * When the clipboard has tldraw content, paste it into the scene.\n *\n * @param editor - The editor instance.\n * @param clipboard - The clipboard model.\n * @param point - The point at which to paste the text.\n * @internal\n */\nexport function pasteTldrawContent(editor: Editor, clipboard: TLContent, point?: VecLike) {\n\tconst selectionBoundsBefore = editor.getSelectionPageBounds()\n\teditor.markHistoryStoppingPoint('paste')\n\teditor.putContentOntoCurrentPage(clipboard, {\n\t\tpoint: point,\n\t\tselect: true,\n\t})\n\tconst selectedBoundsAfter = editor.getSelectionPageBounds()\n\tif (\n\t\tselectionBoundsBefore &&\n\t\tselectedBoundsAfter &&\n\t\tselectionBoundsBefore?.collides(selectedBoundsAfter)\n\t) {\n\t\t// Creates a 'puff' to show a paste has happened.\n\t\teditor.updateInstanceState({ isChangingStyle: true })\n\t\teditor.timers.setTimeout(() => {\n\t\t\teditor.updateInstanceState({ isChangingStyle: false })\n\t\t}, 150)\n\t}\n}\n"], "mappings": "AAUO,SAAS,mBAAmB,QAAgB,WAAsB,OAAiB;AACzF,QAAM,wBAAwB,OAAO,uBAAuB;AAC5D,SAAO,yBAAyB,OAAO;AACvC,SAAO,0BAA0B,WAAW;AAAA,IAC3C;AAAA,IACA,QAAQ;AAAA,EACT,CAAC;AACD,QAAM,sBAAsB,OAAO,uBAAuB;AAC1D,MACC,yBACA,uBACA,uBAAuB,SAAS,mBAAmB,GAClD;AAED,WAAO,oBAAoB,EAAE,iBAAiB,KAAK,CAAC;AACpD,WAAO,OAAO,WAAW,MAAM;AAC9B,aAAO,oBAAoB,EAAE,iBAAiB,MAAM,CAAC;AAAA,IACtD,GAAG,GAAG;AAAA,EACP;AACD;", "names": [] }