tldraw 4.2.0-next.47462e908ff5 → 4.2.0-next.6aa322101785

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist-cjs/index.d.ts +21 -4
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/shapes/shared/RichTextLabel.js +1 -1
  5. package/dist-cjs/lib/shapes/shared/RichTextLabel.js.map +2 -2
  6. package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js +14 -6
  7. package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js.map +2 -2
  8. package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js +2 -2
  9. package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js.map +2 -2
  10. package/dist-cjs/lib/ui/components/DebugMenu/DefaultDebugMenuContent.js +10 -7
  11. package/dist-cjs/lib/ui/components/DebugMenu/DefaultDebugMenuContent.js.map +2 -2
  12. package/dist-cjs/lib/ui/components/Toolbar/DefaultRichTextToolbar.js +6 -2
  13. package/dist-cjs/lib/ui/components/Toolbar/DefaultRichTextToolbar.js.map +2 -2
  14. package/dist-cjs/lib/ui/components/Toolbar/DefaultRichTextToolbarContent.js +2 -1
  15. package/dist-cjs/lib/ui/components/Toolbar/DefaultRichTextToolbarContent.js.map +2 -2
  16. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js +2 -2
  17. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js.map +2 -2
  18. package/dist-cjs/lib/ui/context/events.js.map +2 -2
  19. package/dist-cjs/lib/ui/getLocalFiles.js +18 -3
  20. package/dist-cjs/lib/ui/getLocalFiles.js.map +2 -2
  21. package/dist-cjs/lib/ui/hooks/useClipboardEvents.js +18 -16
  22. package/dist-cjs/lib/ui/hooks/useClipboardEvents.js.map +3 -3
  23. package/dist-cjs/lib/ui/version.js +3 -3
  24. package/dist-cjs/lib/ui/version.js.map +1 -1
  25. package/dist-cjs/lib/utils/text/richText.js +5 -6
  26. package/dist-cjs/lib/utils/text/richText.js.map +3 -3
  27. package/dist-esm/index.d.mts +21 -4
  28. package/dist-esm/index.mjs +1 -1
  29. package/dist-esm/index.mjs.map +2 -2
  30. package/dist-esm/lib/shapes/shared/RichTextLabel.mjs +2 -1
  31. package/dist-esm/lib/shapes/shared/RichTextLabel.mjs.map +2 -2
  32. package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs +14 -6
  33. package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs.map +2 -2
  34. package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs +2 -2
  35. package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs.map +2 -2
  36. package/dist-esm/lib/ui/components/DebugMenu/DefaultDebugMenuContent.mjs +10 -7
  37. package/dist-esm/lib/ui/components/DebugMenu/DefaultDebugMenuContent.mjs.map +2 -2
  38. package/dist-esm/lib/ui/components/Toolbar/DefaultRichTextToolbar.mjs +6 -2
  39. package/dist-esm/lib/ui/components/Toolbar/DefaultRichTextToolbar.mjs.map +2 -2
  40. package/dist-esm/lib/ui/components/Toolbar/DefaultRichTextToolbarContent.mjs +2 -1
  41. package/dist-esm/lib/ui/components/Toolbar/DefaultRichTextToolbarContent.mjs.map +2 -2
  42. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs +3 -3
  43. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs.map +2 -2
  44. package/dist-esm/lib/ui/context/events.mjs.map +2 -2
  45. package/dist-esm/lib/ui/getLocalFiles.mjs +18 -3
  46. package/dist-esm/lib/ui/getLocalFiles.mjs.map +2 -2
  47. package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs +18 -16
  48. package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs.map +3 -3
  49. package/dist-esm/lib/ui/version.mjs +3 -3
  50. package/dist-esm/lib/ui/version.mjs.map +1 -1
  51. package/dist-esm/lib/utils/text/richText.mjs +5 -6
  52. package/dist-esm/lib/utils/text/richText.mjs.map +2 -2
  53. package/package.json +10 -10
  54. package/src/index.ts +3 -0
  55. package/src/lib/shapes/shared/RichTextLabel.tsx +2 -1
  56. package/src/lib/tools/SelectTool/childStates/DraggingHandle.tsx +19 -8
  57. package/src/lib/tools/SelectTool/childStates/Idle.ts +2 -2
  58. package/src/lib/ui/components/DebugMenu/DefaultDebugMenuContent.tsx +27 -7
  59. package/src/lib/ui/components/Toolbar/DefaultRichTextToolbar.tsx +6 -2
  60. package/src/lib/ui/components/Toolbar/DefaultRichTextToolbarContent.tsx +4 -1
  61. package/src/lib/ui/components/Toolbar/LinkEditor.tsx +3 -3
  62. package/src/lib/ui/context/events.tsx +1 -0
  63. package/src/lib/ui/getLocalFiles.ts +20 -3
  64. package/src/lib/ui/hooks/useClipboardEvents.ts +12 -9
  65. package/src/lib/ui/version.ts +3 -3
  66. package/src/lib/utils/text/richText.ts +5 -5
  67. package/src/test/customSnapping.test.tsx +185 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/tools/SelectTool/childStates/Idle.ts"],
4
- "sourcesContent": ["import {\n\tEditor,\n\tStateNode,\n\tTLAdjacentDirection,\n\tTLClickEventInfo,\n\tTLGroupShape,\n\tTLKeyboardEventInfo,\n\tTLPointerEventInfo,\n\tTLShape,\n\tTLTextShape,\n\tVec,\n\tVecLike,\n\tcreateShapeId,\n\tdebugFlags,\n\tkickoutOccludedShapes,\n\tpointInPolygon,\n\ttoRichText,\n} from '@tldraw/editor'\nimport { isOverArrowLabel } from '../../../shapes/arrow/arrowLabel'\nimport { getHitShapeOnCanvasPointerDown } from '../../selection-logic/getHitShapeOnCanvasPointerDown'\nimport { getShouldEnterCropMode } from '../../selection-logic/getShouldEnterCropModeOnPointerDown'\nimport { selectOnCanvasPointerUp } from '../../selection-logic/selectOnCanvasPointerUp'\nimport { updateHoveredShapeId } from '../../selection-logic/updateHoveredShapeId'\nimport { startEditingShapeWithLabel } from '../selectHelpers'\n\nconst SKIPPED_KEYS_FOR_AUTO_EDITING = [\n\t'Delete',\n\t'Backspace',\n\t'[',\n\t']',\n\t'Enter',\n\t' ',\n\t'Shift',\n\t'Tab',\n]\n\nexport class Idle extends StateNode {\n\tstatic override id = 'idle'\n\n\tselectedShapesOnKeyDown: TLShape[] = []\n\n\toverride onEnter() {\n\t\tthis.parent.setCurrentToolIdMask(undefined)\n\t\tupdateHoveredShapeId(this.editor)\n\t\tthis.selectedShapesOnKeyDown = []\n\t\tthis.editor.setCursor({ type: 'default', rotation: 0 })\n\t}\n\n\toverride onExit() {\n\t\tupdateHoveredShapeId.cancel()\n\t}\n\n\toverride onPointerMove() {\n\t\tupdateHoveredShapeId(this.editor)\n\t}\n\n\toverride onPointerDown(info: TLPointerEventInfo) {\n\t\tconst shouldEnterCropMode = info.ctrlKey && getShouldEnterCropMode(this.editor)\n\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\t// Check to see if we hit any shape under the pointer; if so,\n\t\t\t\t// handle this as a pointer down on the shape instead of the canvas\n\t\t\t\tconst hitShape = getHitShapeOnCanvasPointerDown(this.editor)\n\t\t\t\tif (hitShape && !hitShape.isLocked) {\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\n\t\t\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tconst {\n\t\t\t\t\tinputs: { currentPagePoint },\n\t\t\t\t} = this.editor\n\n\t\t\t\tif (\n\t\t\t\t\tselectedShapeIds.length > 1 ||\n\t\t\t\t\t(onlySelectedShape &&\n\t\t\t\t\t\t!this.editor.getShapeUtil(onlySelectedShape).hideSelectionBoundsBg(onlySelectedShape))\n\t\t\t\t) {\n\t\t\t\t\tif (isPointInRotatedSelectionBounds(this.editor, currentPagePoint)) {\n\t\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'selection',\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}\n\n\t\t\t\tthis.parent.transition('pointing_canvas', info)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tconst { shape } = info\n\n\t\t\t\tif (this.editor.isShapeOrAncestorLocked(shape)) {\n\t\t\t\t\tthis.parent.transition('pointing_canvas', info)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\t// If we're holding ctrl key, we might select it, or start brushing...\n\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'handle': {\n\t\t\t\tif (this.editor.getIsReadonly()) break\n\t\t\t\tif (this.editor.inputs.altKey) {\n\t\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\t} else {\n\t\t\t\t\t// If we're holding ctrl key, we might select it, or start brushing...\n\t\t\t\t\tthis.parent.transition('pointing_handle', info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'selection': {\n\t\t\t\tswitch (info.handle) {\n\t\t\t\t\tcase 'mobile_rotate':\n\t\t\t\t\tcase 'top_left_rotate':\n\t\t\t\t\tcase 'top_right_rotate':\n\t\t\t\t\tcase 'bottom_left_rotate':\n\t\t\t\t\tcase 'bottom_right_rotate': {\n\t\t\t\t\t\tif (info.accelKey) {\n\t\t\t\t\t\t\tthis.parent.transition('brushing', info)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.parent.transition('pointing_rotate_handle', info)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'top':\n\t\t\t\t\tcase 'right':\n\t\t\t\t\tcase 'bottom':\n\t\t\t\t\tcase 'left':\n\t\t\t\t\tcase 'top_left':\n\t\t\t\t\tcase 'top_right':\n\t\t\t\t\tcase 'bottom_left':\n\t\t\t\t\tcase 'bottom_right': {\n\t\t\t\t\t\tif (shouldEnterCropMode) {\n\t\t\t\t\t\t\tthis.parent.transition('crop.pointing_crop_handle', info)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (info.accelKey) {\n\t\t\t\t\t\t\t\tthis.parent.transition('brushing', info)\n\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.parent.transition('pointing_resize_handle', info)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tconst hoveredShape = this.editor.getHoveredShape()\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\thoveredShape &&\n\t\t\t\t\t\t\t!this.editor.getSelectedShapeIds().includes(hoveredShape.id) &&\n\t\t\t\t\t\t\t!hoveredShape.isLocked\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\t\tshape: hoveredShape,\n\t\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis.parent.transition('pointing_selection', info)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onDoubleClick(info: TLClickEventInfo) {\n\t\tif (this.editor.inputs.shiftKey || info.phase !== 'up') return\n\n\t\t// We don't want to double click while toggling shapes\n\t\tif (info.ctrlKey || info.shiftKey) return\n\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\tconst hoveredShape = this.editor.getHoveredShape()\n\n\t\t\t\t// todo\n\t\t\t\t// double clicking on the middle of a hollow geo shape without a label, or\n\t\t\t\t// over the label of a hollwo shape that has a label, should start editing\n\t\t\t\t// that shape's label. We can't support \"double click anywhere inside\"\n\t\t\t\t// of the shape yet because that also creates text shapes, and can produce\n\t\t\t\t// unexpected results when working \"inside of\" a hollow shape.\n\n\t\t\t\tconst hitShape =\n\t\t\t\t\thoveredShape && !this.editor.isShapeOfType<TLGroupShape>(hoveredShape, 'group')\n\t\t\t\t\t\t? hoveredShape\n\t\t\t\t\t\t: (this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint) ??\n\t\t\t\t\t\t\tthis.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint, {\n\t\t\t\t\t\t\t\tmargin: this.editor.options.hitTestMargin / this.editor.getZoomLevel(),\n\t\t\t\t\t\t\t\thitInside: false,\n\t\t\t\t\t\t\t}))\n\n\t\t\t\tconst focusedGroupId = this.editor.getFocusedGroupId()\n\n\t\t\t\tif (hitShape) {\n\t\t\t\t\tif (this.editor.isShapeOfType<TLGroupShape>(hitShape, 'group')) {\n\t\t\t\t\t\t// Probably select the shape\n\t\t\t\t\t\tselectOnCanvasPointerUp(this.editor, info)\n\t\t\t\t\t\treturn\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst parent = this.editor.getShape(hitShape.parentId)\n\t\t\t\t\t\tif (parent && this.editor.isShapeOfType<TLGroupShape>(parent, 'group')) {\n\t\t\t\t\t\t\t// The shape is the direct child of a group. If the group is\n\t\t\t\t\t\t\t// selected, then we can select the shape. If the group is the\n\t\t\t\t\t\t\t// focus layer id, then we can double click into it as usual.\n\t\t\t\t\t\t\tif (focusedGroupId && parent.id === focusedGroupId) {\n\t\t\t\t\t\t\t\t// noop, double click on the shape as normal below\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// The shape is the child of some group other than our current\n\t\t\t\t\t\t\t\t// focus layer. We should probably select the group instead.\n\t\t\t\t\t\t\t\tselectOnCanvasPointerUp(this.editor, info)\n\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// double click on the shape. We'll start editing the\n\t\t\t\t\t// shape if it's editable or else do a double click on\n\t\t\t\t\t// the canvas.\n\t\t\t\t\tthis.onDoubleClick({\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\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tif (!this.editor.inputs.shiftKey) {\n\t\t\t\t\tthis.handleDoubleClickOnCanvas(info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'selection': {\n\t\t\t\tif (this.editor.getIsReadonly()) break\n\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\n\t\t\t\tif (onlySelectedShape) {\n\t\t\t\t\tconst util = this.editor.getShapeUtil(onlySelectedShape)\n\n\t\t\t\t\tif (!this.canInteractWithShapeInReadOnly(onlySelectedShape)) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\t// Test edges for an onDoubleClickEdge handler\n\t\t\t\t\tif (\n\t\t\t\t\t\tinfo.handle === 'right' ||\n\t\t\t\t\t\tinfo.handle === 'left' ||\n\t\t\t\t\t\tinfo.handle === 'top' ||\n\t\t\t\t\t\tinfo.handle === 'bottom'\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst change = util.onDoubleClickEdge?.(onlySelectedShape, info)\n\t\t\t\t\t\tif (change) {\n\t\t\t\t\t\t\tthis.editor.markHistoryStoppingPoint('double click edge')\n\t\t\t\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t\t\t\t\tkickoutOccludedShapes(this.editor, [onlySelectedShape.id])\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tinfo.handle === 'top_left' ||\n\t\t\t\t\t\tinfo.handle === 'top_right' ||\n\t\t\t\t\t\tinfo.handle === 'bottom_right' ||\n\t\t\t\t\t\tinfo.handle === 'bottom_left'\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst change = util.onDoubleClickCorner?.(onlySelectedShape, info)\n\t\t\t\t\t\tif (change) {\n\t\t\t\t\t\t\tthis.editor.markHistoryStoppingPoint('double click corner')\n\t\t\t\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t\t\t\t\tkickoutOccludedShapes(this.editor, [onlySelectedShape.id])\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// For corners OR edges but NOT rotation corners\n\t\t\t\t\tif (\n\t\t\t\t\t\tutil.canCrop(onlySelectedShape) &&\n\t\t\t\t\t\t!this.editor.isShapeOrAncestorLocked(onlySelectedShape)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.parent.transition('crop', info)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.shouldStartEditingShape(onlySelectedShape)) {\n\t\t\t\t\t\tthis.startEditingShape(onlySelectedShape, info, true /* select all */)\n\t\t\t\t\t}\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 util = this.editor.getShapeUtil(shape)\n\n\t\t\t\t// Allow playing videos and embeds\n\t\t\t\tif (shape.type !== 'video' && shape.type !== 'embed' && this.editor.getIsReadonly()) break\n\n\t\t\t\tif (util.onDoubleClick) {\n\t\t\t\t\t// Call the shape's double click handler\n\t\t\t\t\tconst change = util.onDoubleClick?.(shape)\n\t\t\t\t\tif (change) {\n\t\t\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (util.canCrop(shape) && !this.editor.isShapeOrAncestorLocked(shape)) {\n\t\t\t\t\t// crop image etc on double click\n\t\t\t\t\tthis.editor.markHistoryStoppingPoint('select and crop')\n\t\t\t\t\tthis.editor.select(info.shape?.id)\n\t\t\t\t\tthis.parent.transition('crop', info)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// If the shape can edit, then begin editing\n\t\t\t\tif (this.shouldStartEditingShape(shape)) {\n\t\t\t\t\tthis.startEditingShape(shape, info, true /* select all */)\n\t\t\t\t} else {\n\t\t\t\t\t// If the shape's double click handler has not created a change,\n\t\t\t\t\t// and if the shape cannot edit, then create a text shape and\n\t\t\t\t\t// begin editing the text shape\n\t\t\t\t\tthis.handleDoubleClickOnCanvas(info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'handle': {\n\t\t\t\tif (this.editor.getIsReadonly()) break\n\t\t\t\tconst { shape, handle } = info\n\n\t\t\t\tconst util = this.editor.getShapeUtil(shape)\n\t\t\t\tconst changes = util.onDoubleClickHandle?.(shape, handle)\n\n\t\t\t\tif (changes) {\n\t\t\t\t\tthis.editor.updateShapes([changes])\n\t\t\t\t} else {\n\t\t\t\t\t// If the shape's double click handler has not created a change,\n\t\t\t\t\t// and if the shape can edit, then begin editing the shape.\n\t\t\t\t\tif (this.shouldStartEditingShape(shape)) {\n\t\t\t\t\t\tthis.startEditingShape(shape, info, true /* select all */)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onRightClick(info: TLPointerEventInfo) {\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\tconst hoveredShape = this.editor.getHoveredShape()\n\t\t\t\tconst hitShape =\n\t\t\t\t\thoveredShape && !this.editor.isShapeOfType<TLGroupShape>(hoveredShape, 'group')\n\t\t\t\t\t\t? hoveredShape\n\t\t\t\t\t\t: this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint, {\n\t\t\t\t\t\t\t\tmargin: this.editor.options.hitTestMargin / this.editor.getZoomLevel(),\n\t\t\t\t\t\t\t\thitInside: false,\n\t\t\t\t\t\t\t\thitLabels: true,\n\t\t\t\t\t\t\t\thitLocked: true,\n\t\t\t\t\t\t\t\thitFrameInside: true,\n\t\t\t\t\t\t\t\trenderingOnly: true,\n\t\t\t\t\t\t\t})\n\n\t\t\t\tif (hitShape) {\n\t\t\t\t\tthis.onRightClick({\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\n\t\t\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tconst {\n\t\t\t\t\tinputs: { currentPagePoint },\n\t\t\t\t} = this.editor\n\n\t\t\t\tif (\n\t\t\t\t\tselectedShapeIds.length > 1 ||\n\t\t\t\t\t(onlySelectedShape &&\n\t\t\t\t\t\t!this.editor.getShapeUtil(onlySelectedShape).hideSelectionBoundsBg(onlySelectedShape))\n\t\t\t\t) {\n\t\t\t\t\tif (isPointInRotatedSelectionBounds(this.editor, currentPagePoint)) {\n\t\t\t\t\t\tthis.onRightClick({\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'selection',\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}\n\n\t\t\t\tthis.editor.selectNone()\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tconst { selectedShapeIds } = this.editor.getCurrentPageState()\n\t\t\t\tconst { shape } = info\n\n\t\t\t\tconst targetShape = this.editor.getOutermostSelectableShape(\n\t\t\t\t\tshape,\n\t\t\t\t\t(parent) => !selectedShapeIds.includes(parent.id)\n\t\t\t\t)\n\n\t\t\t\tif (\n\t\t\t\t\t!selectedShapeIds.includes(targetShape.id) &&\n\t\t\t\t\t!this.editor.findShapeAncestor(targetShape, (shape) =>\n\t\t\t\t\t\tselectedShapeIds.includes(shape.id)\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tthis.editor.markHistoryStoppingPoint('selecting shape')\n\t\t\t\t\tthis.editor.setSelectedShapes([targetShape.id])\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onCancel() {\n\t\tif (\n\t\t\tthis.editor.getFocusedGroupId() !== this.editor.getCurrentPageId() &&\n\t\t\tthis.editor.getSelectedShapeIds().length > 0\n\t\t) {\n\t\t\tthis.editor.popFocusedGroupId()\n\t\t} else {\n\t\t\tthis.editor.markHistoryStoppingPoint('clearing selection')\n\t\t\tthis.editor.selectNone()\n\t\t}\n\t}\n\n\toverride onKeyDown(info: TLKeyboardEventInfo) {\n\t\tthis.selectedShapesOnKeyDown = this.editor.getSelectedShapes()\n\n\t\tswitch (info.code) {\n\t\t\tcase 'ArrowLeft':\n\t\t\tcase 'ArrowRight':\n\t\t\tcase 'ArrowUp':\n\t\t\tcase 'ArrowDown': {\n\t\t\t\tif (info.accelKey) {\n\t\t\t\t\tif (info.shiftKey) {\n\t\t\t\t\t\tif (info.code === 'ArrowDown') {\n\t\t\t\t\t\t\tthis.editor.selectFirstChildShape()\n\t\t\t\t\t\t} else if (info.code === 'ArrowUp') {\n\t\t\t\t\t\t\tthis.editor.selectParentShape()\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.editor.selectAdjacentShape(\n\t\t\t\t\t\t\tinfo.code.replace('Arrow', '').toLowerCase() as TLAdjacentDirection\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.nudgeSelectedShapes(false)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tif (debugFlags['editOnType'].get()) {\n\t\t\t// This feature flag lets us start editing a note shape's label when a key is pressed.\n\t\t\t// We exclude certain keys to avoid conflicting with modifiers, but there are conflicts\n\t\t\t// with other action kbds, hence why this is kept behind a feature flag.\n\t\t\tif (!SKIPPED_KEYS_FOR_AUTO_EDITING.includes(info.key) && !info.altKey && !info.ctrlKey) {\n\t\t\t\t// If the only selected shape is editable, then begin editing it\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tif (\n\t\t\t\t\tonlySelectedShape &&\n\t\t\t\t\t// If it's a note shape, then edit on type\n\t\t\t\t\tthis.editor.isShapeOfType(onlySelectedShape, 'note') &&\n\t\t\t\t\t// If it's not locked or anything\n\t\t\t\t\tthis.shouldStartEditingShape(onlySelectedShape)\n\t\t\t\t) {\n\t\t\t\t\tthis.startEditingShape(\n\t\t\t\t\t\tonlySelectedShape,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\tshape: onlySelectedShape,\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttrue /* select all */\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onKeyRepeat(info: TLKeyboardEventInfo) {\n\t\tswitch (info.code) {\n\t\t\tcase 'ArrowLeft':\n\t\t\tcase 'ArrowRight':\n\t\t\tcase 'ArrowUp':\n\t\t\tcase 'ArrowDown': {\n\t\t\t\tif (info.accelKey) {\n\t\t\t\t\tthis.editor.selectAdjacentShape(\n\t\t\t\t\t\tinfo.code.replace('Arrow', '').toLowerCase() as TLAdjacentDirection\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.nudgeSelectedShapes(true)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'Tab': {\n\t\t\t\tconst selectedShapes = this.editor.getSelectedShapes()\n\t\t\t\tif (selectedShapes.length) {\n\t\t\t\t\tthis.editor.selectAdjacentShape(info.shiftKey ? 'prev' : 'next')\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onKeyUp(info: TLKeyboardEventInfo) {\n\t\tswitch (info.key) {\n\t\t\tcase 'Enter': {\n\t\t\t\t// Because Enter onKeyDown can happen outside the canvas (but then focus the canvas potentially),\n\t\t\t\t// we need to check if the canvas was initially selecting something before continuing.\n\t\t\t\tif (!this.selectedShapesOnKeyDown.length) return\n\n\t\t\t\tconst selectedShapes = this.editor.getSelectedShapes()\n\n\t\t\t\t// On enter, if every selected shape is a group, then select all of the children of the groups\n\t\t\t\tif (\n\t\t\t\t\tselectedShapes.every((shape) => this.editor.isShapeOfType<TLGroupShape>(shape, 'group'))\n\t\t\t\t) {\n\t\t\t\t\tthis.editor.setSelectedShapes(\n\t\t\t\t\t\tselectedShapes.flatMap((shape) => this.editor.getSortedChildIdsForParent(shape.id))\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// If the only selected shape is editable, then begin editing it\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tif (onlySelectedShape && this.shouldStartEditingShape(onlySelectedShape)) {\n\t\t\t\t\tthis.startEditingShape(\n\t\t\t\t\t\tonlySelectedShape,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\tshape: onlySelectedShape,\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttrue /* select all */\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// If the only selected shape is croppable, then begin cropping it\n\t\t\t\tif (getShouldEnterCropMode(this.editor)) {\n\t\t\t\t\tthis.parent.transition('crop', info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'Tab': {\n\t\t\t\tconst selectedShapes = this.editor.getSelectedShapes()\n\t\t\t\tif (selectedShapes.length) {\n\t\t\t\t\tthis.editor.selectAdjacentShape(info.shiftKey ? 'prev' : 'next')\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate shouldStartEditingShape(\n\t\tshape: TLShape | null = this.editor.getOnlySelectedShape()\n\t): boolean {\n\t\tif (!shape) return false\n\t\tif (this.editor.isShapeOrAncestorLocked(shape) && shape.type !== 'embed') return false\n\t\tif (!this.canInteractWithShapeInReadOnly(shape)) return false\n\t\treturn this.editor.getShapeUtil(shape).canEdit(shape)\n\t}\n\n\tprivate startEditingShape(\n\t\tshape: TLShape,\n\t\tinfo: TLClickEventInfo | TLKeyboardEventInfo,\n\t\tshouldSelectAll?: boolean\n\t) {\n\t\tif (this.editor.isShapeOrAncestorLocked(shape) && shape.type !== 'embed') return\n\t\tthis.editor.markHistoryStoppingPoint('editing shape')\n\t\tstartEditingShapeWithLabel(this.editor, shape, shouldSelectAll)\n\t\tthis.parent.transition('editing_shape', info)\n\t}\n\n\tisOverArrowLabelTest(shape: TLShape | undefined) {\n\t\tif (!shape) return false\n\n\t\treturn isOverArrowLabel(this.editor, shape)\n\t}\n\n\thandleDoubleClickOnCanvas(info: TLClickEventInfo) {\n\t\t// Create text shape and transition to editing_shape\n\t\tif (this.editor.getIsReadonly()) return\n\n\t\tif (!this.editor.options.createTextOnCanvasDoubleClick) return\n\n\t\tthis.editor.markHistoryStoppingPoint('creating text shape')\n\n\t\tconst id = createShapeId()\n\n\t\tconst { x, y } = this.editor.inputs.currentPagePoint\n\n\t\t// Allow this to trigger the max shapes reached alert\n\t\tthis.editor.createShapes<TLTextShape>([\n\t\t\t{\n\t\t\t\tid,\n\t\t\t\ttype: 'text',\n\t\t\t\tx,\n\t\t\t\ty,\n\t\t\t\tprops: {\n\t\t\t\t\trichText: toRichText(''),\n\t\t\t\t\tautoSize: true,\n\t\t\t\t},\n\t\t\t},\n\t\t])\n\n\t\tconst shape = this.editor.getShape(id)\n\t\tif (!shape) return\n\n\t\tconst util = this.editor.getShapeUtil(shape)\n\t\tif (this.editor.getIsReadonly()) {\n\t\t\tif (!util.canEditInReadonly(shape)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthis.editor.setEditingShape(id)\n\t\tthis.editor.select(id)\n\t\tthis.parent.transition('editing_shape', info)\n\t}\n\n\tprivate nudgeSelectedShapes(ephemeral = false) {\n\t\tconst {\n\t\t\teditor: {\n\t\t\t\tinputs: { keys },\n\t\t\t},\n\t\t} = this\n\n\t\t// We want to use the \"actual\" shift key state,\n\t\t// not the one that's in the editor.inputs.shiftKey,\n\t\t// because that one uses a short timeout on release\n\t\tconst shiftKey = keys.has('ShiftLeft')\n\n\t\tconst delta = new Vec(0, 0)\n\n\t\tif (keys.has('ArrowLeft')) delta.x -= 1\n\t\tif (keys.has('ArrowRight')) delta.x += 1\n\t\tif (keys.has('ArrowUp')) delta.y -= 1\n\t\tif (keys.has('ArrowDown')) delta.y += 1\n\n\t\tif (delta.equals(new Vec(0, 0))) return\n\n\t\tif (!ephemeral) this.editor.markHistoryStoppingPoint('nudge shapes')\n\n\t\tconst { gridSize } = this.editor.getDocumentSettings()\n\n\t\tconst step = this.editor.getInstanceState().isGridMode\n\t\t\t? shiftKey\n\t\t\t\t? gridSize * GRID_INCREMENT\n\t\t\t\t: gridSize\n\t\t\t: shiftKey\n\t\t\t\t? MAJOR_NUDGE_FACTOR\n\t\t\t\t: MINOR_NUDGE_FACTOR\n\n\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\tthis.editor.nudgeShapes(selectedShapeIds, delta.mul(step))\n\t\tkickoutOccludedShapes(this.editor, selectedShapeIds)\n\t}\n\n\tprivate canInteractWithShapeInReadOnly(shape: TLShape) {\n\t\tif (!this.editor.getIsReadonly()) return true\n\t\tconst util = this.editor.getShapeUtil(shape)\n\t\tif (util.canEditInReadonly(shape)) return true\n\t\treturn false\n\t}\n}\n\nexport const MAJOR_NUDGE_FACTOR = 10\nexport const MINOR_NUDGE_FACTOR = 1\nexport const GRID_INCREMENT = 5\n\nfunction isPointInRotatedSelectionBounds(editor: Editor, point: VecLike) {\n\tconst selectionBounds = editor.getSelectionRotatedPageBounds()\n\tif (!selectionBounds) return false\n\n\tconst selectionRotation = editor.getSelectionRotation()\n\tif (!selectionRotation) return selectionBounds.containsPoint(point)\n\n\treturn pointInPolygon(\n\t\tpoint,\n\t\tselectionBounds.corners.map((c) => Vec.RotWith(c, selectionBounds.point, selectionRotation))\n\t)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAiBO;AACP,wBAAiC;AACjC,4CAA+C;AAC/C,iDAAuC;AACvC,qCAAwC;AACxC,kCAAqC;AACrC,2BAA2C;AAE3C,MAAM,gCAAgC;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEO,MAAM,aAAa,wBAAU;AAAA,EACnC,OAAgB,KAAK;AAAA,EAErB,0BAAqC,CAAC;AAAA,EAE7B,UAAU;AAClB,SAAK,OAAO,qBAAqB,MAAS;AAC1C,0DAAqB,KAAK,MAAM;AAChC,SAAK,0BAA0B,CAAC;AAChC,SAAK,OAAO,UAAU,EAAE,MAAM,WAAW,UAAU,EAAE,CAAC;AAAA,EACvD;AAAA,EAES,SAAS;AACjB,qDAAqB,OAAO;AAAA,EAC7B;AAAA,EAES,gBAAgB;AACxB,0DAAqB,KAAK,MAAM;AAAA,EACjC;AAAA,EAES,cAAc,MAA0B;AAChD,UAAM,sBAAsB,KAAK,eAAW,mEAAuB,KAAK,MAAM;AAE9E,YAAQ,KAAK,QAAQ;AAAA,MACpB,KAAK,UAAU;AAGd,cAAM,eAAW,sEAA+B,KAAK,MAAM;AAC3D,YAAI,YAAY,CAAC,SAAS,UAAU;AACnC,eAAK,cAAc;AAAA,YAClB,GAAG;AAAA,YACH,OAAO;AAAA,YACP,QAAQ;AAAA,UACT,CAAC;AACD;AAAA,QACD;AAEA,cAAM,mBAAmB,KAAK,OAAO,oBAAoB;AACzD,cAAM,oBAAoB,KAAK,OAAO,qBAAqB;AAC3D,cAAM;AAAA,UACL,QAAQ,EAAE,iBAAiB;AAAA,QAC5B,I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;AAErD,UAAM,OAAO,KAAK,OAAO,iBAAiB,EAAE,aACzC,WACC,WAAW,iBACX,WACD,WACC,qBACA;AAEJ,UAAM,mBAAmB,KAAK,OAAO,oBAAoB;AACzD,SAAK,OAAO,YAAY,kBAAkB,MAAM,IAAI,IAAI,CAAC;AACzD,6CAAsB,KAAK,QAAQ,gBAAgB;AAAA,EACpD;AAAA,EAEQ,+BAA+B,OAAgB;AACtD,QAAI,CAAC,KAAK,OAAO,cAAc,EAAG,QAAO;AACzC,UAAM,OAAO,KAAK,OAAO,aAAa,KAAK;AAC3C,QAAI,KAAK,kBAAkB,KAAK,EAAG,QAAO;AAC1C,WAAO;AAAA,EACR;AACD;AAEO,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAC3B,MAAM,iBAAiB;AAE9B,SAAS,gCAAgC,QAAgB,OAAgB;AACxE,QAAM,kBAAkB,OAAO,8BAA8B;AAC7D,MAAI,CAAC,gBAAiB,QAAO;AAE7B,QAAM,oBAAoB,OAAO,qBAAqB;AACtD,MAAI,CAAC,kBAAmB,QAAO,gBAAgB,cAAc,KAAK;AAElE,aAAO;AAAA,IACN;AAAA,IACA,gBAAgB,QAAQ,IAAI,CAAC,MAAM,kBAAI,QAAQ,GAAG,gBAAgB,OAAO,iBAAiB,CAAC;AAAA,EAC5F;AACD;",
4
+ "sourcesContent": ["import {\n\tEditor,\n\tStateNode,\n\tTLAdjacentDirection,\n\tTLClickEventInfo,\n\tTLGroupShape,\n\tTLKeyboardEventInfo,\n\tTLPointerEventInfo,\n\tTLShape,\n\tTLTextShape,\n\tVec,\n\tVecLike,\n\tcreateShapeId,\n\tdebugFlags,\n\tkickoutOccludedShapes,\n\tpointInPolygon,\n\ttoRichText,\n} from '@tldraw/editor'\nimport { isOverArrowLabel } from '../../../shapes/arrow/arrowLabel'\nimport { getHitShapeOnCanvasPointerDown } from '../../selection-logic/getHitShapeOnCanvasPointerDown'\nimport { getShouldEnterCropMode } from '../../selection-logic/getShouldEnterCropModeOnPointerDown'\nimport { selectOnCanvasPointerUp } from '../../selection-logic/selectOnCanvasPointerUp'\nimport { updateHoveredShapeId } from '../../selection-logic/updateHoveredShapeId'\nimport { startEditingShapeWithLabel } from '../selectHelpers'\n\nconst SKIPPED_KEYS_FOR_AUTO_EDITING = [\n\t'Delete',\n\t'Backspace',\n\t'[',\n\t']',\n\t'Enter',\n\t' ',\n\t'Shift',\n\t'Tab',\n]\n\nexport class Idle extends StateNode {\n\tstatic override id = 'idle'\n\n\tselectedShapesOnKeyDown: TLShape[] = []\n\n\toverride onEnter() {\n\t\tthis.parent.setCurrentToolIdMask(undefined)\n\t\tupdateHoveredShapeId(this.editor)\n\t\tthis.selectedShapesOnKeyDown = []\n\t\tthis.editor.setCursor({ type: 'default', rotation: 0 })\n\t}\n\n\toverride onExit() {\n\t\tupdateHoveredShapeId.cancel()\n\t}\n\n\toverride onPointerMove() {\n\t\tupdateHoveredShapeId(this.editor)\n\t}\n\n\toverride onPointerDown(info: TLPointerEventInfo) {\n\t\tconst shouldEnterCropMode = info.ctrlKey && getShouldEnterCropMode(this.editor)\n\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\t// Check to see if we hit any shape under the pointer; if so,\n\t\t\t\t// handle this as a pointer down on the shape instead of the canvas\n\t\t\t\tconst hitShape = getHitShapeOnCanvasPointerDown(this.editor)\n\t\t\t\tif (hitShape && !hitShape.isLocked) {\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\n\t\t\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tconst {\n\t\t\t\t\tinputs: { currentPagePoint },\n\t\t\t\t} = this.editor\n\n\t\t\t\tif (\n\t\t\t\t\tselectedShapeIds.length > 1 ||\n\t\t\t\t\t(onlySelectedShape &&\n\t\t\t\t\t\t!this.editor.getShapeUtil(onlySelectedShape).hideSelectionBoundsBg(onlySelectedShape))\n\t\t\t\t) {\n\t\t\t\t\tif (isPointInRotatedSelectionBounds(this.editor, currentPagePoint)) {\n\t\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'selection',\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}\n\n\t\t\t\tthis.parent.transition('pointing_canvas', info)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tconst { shape } = info\n\n\t\t\t\tif (this.editor.isShapeOrAncestorLocked(shape)) {\n\t\t\t\t\tthis.parent.transition('pointing_canvas', info)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\t// If we're holding ctrl key, we might select it, or start brushing...\n\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'handle': {\n\t\t\t\tif (this.editor.getIsReadonly()) break\n\t\t\t\tif (this.editor.inputs.altKey) {\n\t\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\t} else {\n\t\t\t\t\t// If we're holding ctrl key, we might select it, or start brushing...\n\t\t\t\t\tthis.parent.transition('pointing_handle', info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'selection': {\n\t\t\t\tswitch (info.handle) {\n\t\t\t\t\tcase 'mobile_rotate':\n\t\t\t\t\tcase 'top_left_rotate':\n\t\t\t\t\tcase 'top_right_rotate':\n\t\t\t\t\tcase 'bottom_left_rotate':\n\t\t\t\t\tcase 'bottom_right_rotate': {\n\t\t\t\t\t\tif (info.accelKey) {\n\t\t\t\t\t\t\tthis.parent.transition('brushing', info)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.parent.transition('pointing_rotate_handle', info)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'top':\n\t\t\t\t\tcase 'right':\n\t\t\t\t\tcase 'bottom':\n\t\t\t\t\tcase 'left':\n\t\t\t\t\tcase 'top_left':\n\t\t\t\t\tcase 'top_right':\n\t\t\t\t\tcase 'bottom_left':\n\t\t\t\t\tcase 'bottom_right': {\n\t\t\t\t\t\tif (shouldEnterCropMode) {\n\t\t\t\t\t\t\tthis.parent.transition('crop.pointing_crop_handle', info)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (info.accelKey) {\n\t\t\t\t\t\t\t\tthis.parent.transition('brushing', info)\n\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.parent.transition('pointing_resize_handle', info)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tconst hoveredShape = this.editor.getHoveredShape()\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\thoveredShape &&\n\t\t\t\t\t\t\t!this.editor.getSelectedShapeIds().includes(hoveredShape.id) &&\n\t\t\t\t\t\t\t!hoveredShape.isLocked\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\t\tshape: hoveredShape,\n\t\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis.parent.transition('pointing_selection', info)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onDoubleClick(info: TLClickEventInfo) {\n\t\tif (this.editor.inputs.shiftKey || info.phase !== 'up') return\n\n\t\t// We don't want to double click while toggling shapes\n\t\tif (info.ctrlKey || info.shiftKey) return\n\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\tconst hoveredShape = this.editor.getHoveredShape()\n\n\t\t\t\t// todo\n\t\t\t\t// double clicking on the middle of a hollow geo shape without a label, or\n\t\t\t\t// over the label of a hollwo shape that has a label, should start editing\n\t\t\t\t// that shape's label. We can't support \"double click anywhere inside\"\n\t\t\t\t// of the shape yet because that also creates text shapes, and can produce\n\t\t\t\t// unexpected results when working \"inside of\" a hollow shape.\n\n\t\t\t\tconst hitShape =\n\t\t\t\t\thoveredShape && !this.editor.isShapeOfType<TLGroupShape>(hoveredShape, 'group')\n\t\t\t\t\t\t? hoveredShape\n\t\t\t\t\t\t: (this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint) ??\n\t\t\t\t\t\t\tthis.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint, {\n\t\t\t\t\t\t\t\tmargin: this.editor.options.hitTestMargin / this.editor.getZoomLevel(),\n\t\t\t\t\t\t\t\thitInside: false,\n\t\t\t\t\t\t\t}))\n\n\t\t\t\tconst focusedGroupId = this.editor.getFocusedGroupId()\n\n\t\t\t\tif (hitShape) {\n\t\t\t\t\tif (this.editor.isShapeOfType<TLGroupShape>(hitShape, 'group')) {\n\t\t\t\t\t\t// Probably select the shape\n\t\t\t\t\t\tselectOnCanvasPointerUp(this.editor, info)\n\t\t\t\t\t\treturn\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst parent = this.editor.getShape(hitShape.parentId)\n\t\t\t\t\t\tif (parent && this.editor.isShapeOfType<TLGroupShape>(parent, 'group')) {\n\t\t\t\t\t\t\t// The shape is the direct child of a group. If the group is\n\t\t\t\t\t\t\t// selected, then we can select the shape. If the group is the\n\t\t\t\t\t\t\t// focus layer id, then we can double click into it as usual.\n\t\t\t\t\t\t\tif (focusedGroupId && parent.id === focusedGroupId) {\n\t\t\t\t\t\t\t\t// noop, double click on the shape as normal below\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// The shape is the child of some group other than our current\n\t\t\t\t\t\t\t\t// focus layer. We should probably select the group instead.\n\t\t\t\t\t\t\t\tselectOnCanvasPointerUp(this.editor, info)\n\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// double click on the shape. We'll start editing the\n\t\t\t\t\t// shape if it's editable or else do a double click on\n\t\t\t\t\t// the canvas.\n\t\t\t\t\tthis.onDoubleClick({\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\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tif (!this.editor.inputs.shiftKey) {\n\t\t\t\t\tthis.handleDoubleClickOnCanvas(info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'selection': {\n\t\t\t\tif (this.editor.getIsReadonly()) break\n\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\n\t\t\t\tif (onlySelectedShape) {\n\t\t\t\t\tconst util = this.editor.getShapeUtil(onlySelectedShape)\n\n\t\t\t\t\tif (!this.canInteractWithShapeInReadOnly(onlySelectedShape)) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\t// Test edges for an onDoubleClickEdge handler\n\t\t\t\t\tif (\n\t\t\t\t\t\tinfo.handle === 'right' ||\n\t\t\t\t\t\tinfo.handle === 'left' ||\n\t\t\t\t\t\tinfo.handle === 'top' ||\n\t\t\t\t\t\tinfo.handle === 'bottom'\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst change = util.onDoubleClickEdge?.(onlySelectedShape, info)\n\t\t\t\t\t\tif (change) {\n\t\t\t\t\t\t\tthis.editor.markHistoryStoppingPoint('double click edge')\n\t\t\t\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t\t\t\t\tkickoutOccludedShapes(this.editor, [onlySelectedShape.id])\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tinfo.handle === 'top_left' ||\n\t\t\t\t\t\tinfo.handle === 'top_right' ||\n\t\t\t\t\t\tinfo.handle === 'bottom_right' ||\n\t\t\t\t\t\tinfo.handle === 'bottom_left'\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst change = util.onDoubleClickCorner?.(onlySelectedShape, info)\n\t\t\t\t\t\tif (change) {\n\t\t\t\t\t\t\tthis.editor.markHistoryStoppingPoint('double click corner')\n\t\t\t\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t\t\t\t\tkickoutOccludedShapes(this.editor, [onlySelectedShape.id])\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// For corners OR edges but NOT rotation corners\n\t\t\t\t\tif (\n\t\t\t\t\t\tutil.canCrop(onlySelectedShape) &&\n\t\t\t\t\t\t!this.editor.isShapeOrAncestorLocked(onlySelectedShape)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.parent.transition('crop', info)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.shouldStartEditingShape(onlySelectedShape)) {\n\t\t\t\t\t\tthis.startEditingShape(onlySelectedShape, info, true /* select all */)\n\t\t\t\t\t}\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 util = this.editor.getShapeUtil(shape)\n\n\t\t\t\t// Allow playing videos and embeds\n\t\t\t\tif (shape.type !== 'video' && shape.type !== 'embed' && this.editor.getIsReadonly()) break\n\n\t\t\t\tif (util.onDoubleClick) {\n\t\t\t\t\t// Call the shape's double click handler\n\t\t\t\t\tconst change = util.onDoubleClick?.(shape)\n\t\t\t\t\tif (change) {\n\t\t\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (util.canCrop(shape) && !this.editor.isShapeOrAncestorLocked(shape)) {\n\t\t\t\t\t// crop image etc on double click\n\t\t\t\t\tthis.editor.markHistoryStoppingPoint('select and crop')\n\t\t\t\t\tthis.editor.select(info.shape?.id)\n\t\t\t\t\tthis.parent.transition('crop', info)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// If the shape can edit, then begin editing\n\t\t\t\tif (this.shouldStartEditingShape(shape)) {\n\t\t\t\t\tthis.startEditingShape(shape, info, true /* select all */)\n\t\t\t\t} else {\n\t\t\t\t\t// If the shape's double click handler has not created a change,\n\t\t\t\t\t// and if the shape cannot edit, then create a text shape and\n\t\t\t\t\t// begin editing the text shape\n\t\t\t\t\tthis.handleDoubleClickOnCanvas(info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'handle': {\n\t\t\t\tif (this.editor.getIsReadonly()) break\n\t\t\t\tconst { shape, handle } = info\n\n\t\t\t\tconst util = this.editor.getShapeUtil(shape)\n\t\t\t\tconst changes = util.onDoubleClickHandle?.(shape, handle)\n\n\t\t\t\tif (changes) {\n\t\t\t\t\tthis.editor.updateShapes([changes])\n\t\t\t\t} else {\n\t\t\t\t\t// If the shape's double click handler has not created a change,\n\t\t\t\t\t// and if the shape can edit, then begin editing the shape.\n\t\t\t\t\tif (this.shouldStartEditingShape(shape)) {\n\t\t\t\t\t\tthis.startEditingShape(shape, info, true /* select all */)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onRightClick(info: TLPointerEventInfo) {\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\tconst hoveredShape = this.editor.getHoveredShape()\n\t\t\t\tconst hitShape =\n\t\t\t\t\thoveredShape && !this.editor.isShapeOfType<TLGroupShape>(hoveredShape, 'group')\n\t\t\t\t\t\t? hoveredShape\n\t\t\t\t\t\t: this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint, {\n\t\t\t\t\t\t\t\tmargin: this.editor.options.hitTestMargin / this.editor.getZoomLevel(),\n\t\t\t\t\t\t\t\thitInside: false,\n\t\t\t\t\t\t\t\thitLabels: true,\n\t\t\t\t\t\t\t\thitLocked: true,\n\t\t\t\t\t\t\t\thitFrameInside: true,\n\t\t\t\t\t\t\t\trenderingOnly: true,\n\t\t\t\t\t\t\t})\n\n\t\t\t\tif (hitShape) {\n\t\t\t\t\tthis.onRightClick({\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\n\t\t\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tconst {\n\t\t\t\t\tinputs: { currentPagePoint },\n\t\t\t\t} = this.editor\n\n\t\t\t\tif (\n\t\t\t\t\tselectedShapeIds.length > 1 ||\n\t\t\t\t\t(onlySelectedShape &&\n\t\t\t\t\t\t!this.editor.getShapeUtil(onlySelectedShape).hideSelectionBoundsBg(onlySelectedShape))\n\t\t\t\t) {\n\t\t\t\t\tif (isPointInRotatedSelectionBounds(this.editor, currentPagePoint)) {\n\t\t\t\t\t\tthis.onRightClick({\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'selection',\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}\n\n\t\t\t\tthis.editor.selectNone()\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tconst { selectedShapeIds } = this.editor.getCurrentPageState()\n\t\t\t\tconst { shape } = info\n\n\t\t\t\tconst targetShape = this.editor.getOutermostSelectableShape(\n\t\t\t\t\tshape,\n\t\t\t\t\t(parent) => !selectedShapeIds.includes(parent.id)\n\t\t\t\t)\n\n\t\t\t\tif (\n\t\t\t\t\t!selectedShapeIds.includes(targetShape.id) &&\n\t\t\t\t\t!this.editor.findShapeAncestor(targetShape, (shape) =>\n\t\t\t\t\t\tselectedShapeIds.includes(shape.id)\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tthis.editor.markHistoryStoppingPoint('selecting shape')\n\t\t\t\t\tthis.editor.setSelectedShapes([targetShape.id])\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onCancel() {\n\t\tif (\n\t\t\tthis.editor.getFocusedGroupId() !== this.editor.getCurrentPageId() &&\n\t\t\tthis.editor.getSelectedShapeIds().length > 0\n\t\t) {\n\t\t\tthis.editor.popFocusedGroupId()\n\t\t} else {\n\t\t\tthis.editor.markHistoryStoppingPoint('clearing selection')\n\t\t\tthis.editor.selectNone()\n\t\t}\n\t}\n\n\toverride onKeyDown(info: TLKeyboardEventInfo) {\n\t\tthis.selectedShapesOnKeyDown = this.editor.getSelectedShapes()\n\n\t\tswitch (info.code) {\n\t\t\tcase 'ArrowLeft':\n\t\t\tcase 'ArrowRight':\n\t\t\tcase 'ArrowUp':\n\t\t\tcase 'ArrowDown': {\n\t\t\t\tif (info.accelKey) {\n\t\t\t\t\tif (info.shiftKey) {\n\t\t\t\t\t\tif (info.code === 'ArrowDown') {\n\t\t\t\t\t\t\tthis.editor.selectFirstChildShape()\n\t\t\t\t\t\t} else if (info.code === 'ArrowUp') {\n\t\t\t\t\t\t\tthis.editor.selectParentShape()\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.editor.selectAdjacentShape(\n\t\t\t\t\t\t\tinfo.code.replace('Arrow', '').toLowerCase() as TLAdjacentDirection\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.nudgeSelectedShapes(false)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tif (debugFlags['editOnType'].get()) {\n\t\t\t// This feature flag lets us start editing a note shape's label when a key is pressed.\n\t\t\t// We exclude certain keys to avoid conflicting with modifiers, but there are conflicts\n\t\t\t// with other action kbds, hence why this is kept behind a feature flag.\n\t\t\tif (!SKIPPED_KEYS_FOR_AUTO_EDITING.includes(info.key) && !info.altKey && !info.ctrlKey) {\n\t\t\t\t// If the only selected shape is editable, then begin editing it\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tif (\n\t\t\t\t\tonlySelectedShape &&\n\t\t\t\t\t// If it's a note shape, then edit on type\n\t\t\t\t\tthis.editor.isShapeOfType(onlySelectedShape, 'note') &&\n\t\t\t\t\t// If it's not locked or anything\n\t\t\t\t\tthis.shouldStartEditingShape(onlySelectedShape)\n\t\t\t\t) {\n\t\t\t\t\tthis.startEditingShape(\n\t\t\t\t\t\tonlySelectedShape,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\tshape: onlySelectedShape,\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttrue /* select all */\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onKeyRepeat(info: TLKeyboardEventInfo) {\n\t\tswitch (info.code) {\n\t\t\tcase 'ArrowLeft':\n\t\t\tcase 'ArrowRight':\n\t\t\tcase 'ArrowUp':\n\t\t\tcase 'ArrowDown': {\n\t\t\t\tif (info.accelKey) {\n\t\t\t\t\tthis.editor.selectAdjacentShape(\n\t\t\t\t\t\tinfo.code.replace('Arrow', '').toLowerCase() as TLAdjacentDirection\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.nudgeSelectedShapes(true)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'Tab': {\n\t\t\t\tconst selectedShapes = this.editor.getSelectedShapes()\n\t\t\t\tif (selectedShapes.length && !info.altKey) {\n\t\t\t\t\tthis.editor.selectAdjacentShape(info.shiftKey ? 'prev' : 'next')\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onKeyUp(info: TLKeyboardEventInfo) {\n\t\tswitch (info.key) {\n\t\t\tcase 'Enter': {\n\t\t\t\t// Because Enter onKeyDown can happen outside the canvas (but then focus the canvas potentially),\n\t\t\t\t// we need to check if the canvas was initially selecting something before continuing.\n\t\t\t\tif (!this.selectedShapesOnKeyDown.length) return\n\n\t\t\t\tconst selectedShapes = this.editor.getSelectedShapes()\n\n\t\t\t\t// On enter, if every selected shape is a group, then select all of the children of the groups\n\t\t\t\tif (\n\t\t\t\t\tselectedShapes.every((shape) => this.editor.isShapeOfType<TLGroupShape>(shape, 'group'))\n\t\t\t\t) {\n\t\t\t\t\tthis.editor.setSelectedShapes(\n\t\t\t\t\t\tselectedShapes.flatMap((shape) => this.editor.getSortedChildIdsForParent(shape.id))\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// If the only selected shape is editable, then begin editing it\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tif (onlySelectedShape && this.shouldStartEditingShape(onlySelectedShape)) {\n\t\t\t\t\tthis.startEditingShape(\n\t\t\t\t\t\tonlySelectedShape,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\tshape: onlySelectedShape,\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttrue /* select all */\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// If the only selected shape is croppable, then begin cropping it\n\t\t\t\tif (getShouldEnterCropMode(this.editor)) {\n\t\t\t\t\tthis.parent.transition('crop', info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'Tab': {\n\t\t\t\tconst selectedShapes = this.editor.getSelectedShapes()\n\t\t\t\tif (selectedShapes.length && !info.altKey) {\n\t\t\t\t\tthis.editor.selectAdjacentShape(info.shiftKey ? 'prev' : 'next')\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate shouldStartEditingShape(\n\t\tshape: TLShape | null = this.editor.getOnlySelectedShape()\n\t): boolean {\n\t\tif (!shape) return false\n\t\tif (this.editor.isShapeOrAncestorLocked(shape) && shape.type !== 'embed') return false\n\t\tif (!this.canInteractWithShapeInReadOnly(shape)) return false\n\t\treturn this.editor.getShapeUtil(shape).canEdit(shape)\n\t}\n\n\tprivate startEditingShape(\n\t\tshape: TLShape,\n\t\tinfo: TLClickEventInfo | TLKeyboardEventInfo,\n\t\tshouldSelectAll?: boolean\n\t) {\n\t\tif (this.editor.isShapeOrAncestorLocked(shape) && shape.type !== 'embed') return\n\t\tthis.editor.markHistoryStoppingPoint('editing shape')\n\t\tstartEditingShapeWithLabel(this.editor, shape, shouldSelectAll)\n\t\tthis.parent.transition('editing_shape', info)\n\t}\n\n\tisOverArrowLabelTest(shape: TLShape | undefined) {\n\t\tif (!shape) return false\n\n\t\treturn isOverArrowLabel(this.editor, shape)\n\t}\n\n\thandleDoubleClickOnCanvas(info: TLClickEventInfo) {\n\t\t// Create text shape and transition to editing_shape\n\t\tif (this.editor.getIsReadonly()) return\n\n\t\tif (!this.editor.options.createTextOnCanvasDoubleClick) return\n\n\t\tthis.editor.markHistoryStoppingPoint('creating text shape')\n\n\t\tconst id = createShapeId()\n\n\t\tconst { x, y } = this.editor.inputs.currentPagePoint\n\n\t\t// Allow this to trigger the max shapes reached alert\n\t\tthis.editor.createShapes<TLTextShape>([\n\t\t\t{\n\t\t\t\tid,\n\t\t\t\ttype: 'text',\n\t\t\t\tx,\n\t\t\t\ty,\n\t\t\t\tprops: {\n\t\t\t\t\trichText: toRichText(''),\n\t\t\t\t\tautoSize: true,\n\t\t\t\t},\n\t\t\t},\n\t\t])\n\n\t\tconst shape = this.editor.getShape(id)\n\t\tif (!shape) return\n\n\t\tconst util = this.editor.getShapeUtil(shape)\n\t\tif (this.editor.getIsReadonly()) {\n\t\t\tif (!util.canEditInReadonly(shape)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthis.editor.setEditingShape(id)\n\t\tthis.editor.select(id)\n\t\tthis.parent.transition('editing_shape', info)\n\t}\n\n\tprivate nudgeSelectedShapes(ephemeral = false) {\n\t\tconst {\n\t\t\teditor: {\n\t\t\t\tinputs: { keys },\n\t\t\t},\n\t\t} = this\n\n\t\t// We want to use the \"actual\" shift key state,\n\t\t// not the one that's in the editor.inputs.shiftKey,\n\t\t// because that one uses a short timeout on release\n\t\tconst shiftKey = keys.has('ShiftLeft')\n\n\t\tconst delta = new Vec(0, 0)\n\n\t\tif (keys.has('ArrowLeft')) delta.x -= 1\n\t\tif (keys.has('ArrowRight')) delta.x += 1\n\t\tif (keys.has('ArrowUp')) delta.y -= 1\n\t\tif (keys.has('ArrowDown')) delta.y += 1\n\n\t\tif (delta.equals(new Vec(0, 0))) return\n\n\t\tif (!ephemeral) this.editor.markHistoryStoppingPoint('nudge shapes')\n\n\t\tconst { gridSize } = this.editor.getDocumentSettings()\n\n\t\tconst step = this.editor.getInstanceState().isGridMode\n\t\t\t? shiftKey\n\t\t\t\t? gridSize * GRID_INCREMENT\n\t\t\t\t: gridSize\n\t\t\t: shiftKey\n\t\t\t\t? MAJOR_NUDGE_FACTOR\n\t\t\t\t: MINOR_NUDGE_FACTOR\n\n\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\tthis.editor.nudgeShapes(selectedShapeIds, delta.mul(step))\n\t\tkickoutOccludedShapes(this.editor, selectedShapeIds)\n\t}\n\n\tprivate canInteractWithShapeInReadOnly(shape: TLShape) {\n\t\tif (!this.editor.getIsReadonly()) return true\n\t\tconst util = this.editor.getShapeUtil(shape)\n\t\tif (util.canEditInReadonly(shape)) return true\n\t\treturn false\n\t}\n}\n\nexport const MAJOR_NUDGE_FACTOR = 10\nexport const MINOR_NUDGE_FACTOR = 1\nexport const GRID_INCREMENT = 5\n\nfunction isPointInRotatedSelectionBounds(editor: Editor, point: VecLike) {\n\tconst selectionBounds = editor.getSelectionRotatedPageBounds()\n\tif (!selectionBounds) return false\n\n\tconst selectionRotation = editor.getSelectionRotation()\n\tif (!selectionRotation) return selectionBounds.containsPoint(point)\n\n\treturn pointInPolygon(\n\t\tpoint,\n\t\tselectionBounds.corners.map((c) => Vec.RotWith(c, selectionBounds.point, selectionRotation))\n\t)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAiBO;AACP,wBAAiC;AACjC,4CAA+C;AAC/C,iDAAuC;AACvC,qCAAwC;AACxC,kCAAqC;AACrC,2BAA2C;AAE3C,MAAM,gCAAgC;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEO,MAAM,aAAa,wBAAU;AAAA,EACnC,OAAgB,KAAK;AAAA,EAErB,0BAAqC,CAAC;AAAA,EAE7B,UAAU;AAClB,SAAK,OAAO,qBAAqB,MAAS;AAC1C,0DAAqB,KAAK,MAAM;AAChC,SAAK,0BAA0B,CAAC;AAChC,SAAK,OAAO,UAAU,EAAE,MAAM,WAAW,UAAU,EAAE,CAAC;AAAA,EACvD;AAAA,EAES,SAAS;AACjB,qDAAqB,OAAO;AAAA,EAC7B;AAAA,EAES,gBAAgB;AACxB,0DAAqB,KAAK,MAAM;AAAA,EACjC;AAAA,EAES,cAAc,MAA0B;AAChD,UAAM,sBAAsB,KAAK,eAAW,mEAAuB,KAAK,MAAM;AAE9E,YAAQ,KAAK,QAAQ;AAAA,MACpB,KAAK,UAAU;AAGd,cAAM,eAAW,sEAA+B,KAAK,MAAM;AAC3D,YAAI,YAAY,CAAC,SAAS,UAAU;AACnC,eAAK,cAAc;AAAA,YAClB,GAAG;AAAA,YACH,OAAO;AAAA,YACP,QAAQ;AAAA,UACT,CAAC;AACD;AAAA,QACD;AAEA,cAAM,mBAAmB,KAA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I,MAAM,OAAO,IAAI,kBAAI,GAAG,CAAC,CAAC,EAAG;AAEjC,QAAI,CAAC,UAAW,MAAK,OAAO,yBAAyB,cAAc;AAEnE,UAAM,EAAE,SAAS,IAAI,KAAK,OAAO,oBAAoB;AAErD,UAAM,OAAO,KAAK,OAAO,iBAAiB,EAAE,aACzC,WACC,WAAW,iBACX,WACD,WACC,qBACA;AAEJ,UAAM,mBAAmB,KAAK,OAAO,oBAAoB;AACzD,SAAK,OAAO,YAAY,kBAAkB,MAAM,IAAI,IAAI,CAAC;AACzD,6CAAsB,KAAK,QAAQ,gBAAgB;AAAA,EACpD;AAAA,EAEQ,+BAA+B,OAAgB;AACtD,QAAI,CAAC,KAAK,OAAO,cAAc,EAAG,QAAO;AACzC,UAAM,OAAO,KAAK,OAAO,aAAa,KAAK;AAC3C,QAAI,KAAK,kBAAkB,KAAK,EAAG,QAAO;AAC1C,WAAO;AAAA,EACR;AACD;AAEO,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAC3B,MAAM,iBAAiB;AAE9B,SAAS,gCAAgC,QAAgB,OAAgB;AACxE,QAAM,kBAAkB,OAAO,8BAA8B;AAC7D,MAAI,CAAC,gBAAiB,QAAO;AAE7B,QAAM,oBAAoB,OAAO,qBAAqB;AACtD,MAAI,CAAC,kBAAmB,QAAO,gBAAgB,cAAc,KAAK;AAElE,aAAO;AAAA,IACN;AAAA,IACA,gBAAgB,QAAQ,IAAI,CAAC,MAAM,kBAAI,QAAQ,GAAG,gBAAgB,OAAO,iBAAiB,CAAC;AAAA,EAC5F;AACD;",
6
6
  "names": ["shape"]
7
7
  }
@@ -48,7 +48,10 @@ var import_TldrawUiMenuCheckboxItem = require("../primitives/menus/TldrawUiMenuC
48
48
  var import_TldrawUiMenuGroup = require("../primitives/menus/TldrawUiMenuGroup");
49
49
  var import_TldrawUiMenuItem = require("../primitives/menus/TldrawUiMenuItem");
50
50
  var import_TldrawUiMenuSubmenu = require("../primitives/menus/TldrawUiMenuSubmenu");
51
- function DefaultDebugMenuContent() {
51
+ function DefaultDebugMenuContent({
52
+ customDebugFlags,
53
+ customFeatureFlags
54
+ }) {
52
55
  const editor = (0, import_editor.useEditor)();
53
56
  const { addToast } = (0, import_toasts.useToasts)();
54
57
  const { addDialog } = (0, import_dialogs.useDialogs)();
@@ -182,18 +185,18 @@ function DefaultDebugMenuContent() {
182
185
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiMenuItem.TldrawUiMenuItem, { id: "throw-error", onSelect: () => setError(true), label: "Throw error" })
183
186
  ] }),
184
187
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_TldrawUiMenuGroup.TldrawUiMenuGroup, { id: "flags", children: [
185
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DebugFlags, {}),
186
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FeatureFlags, {})
188
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DebugFlags, { customDebugFlags }),
189
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FeatureFlags, { customFeatureFlags })
187
190
  ] })
188
191
  ] });
189
192
  }
190
- function DebugFlags() {
191
- const items = Object.values(import_editor.debugFlags);
193
+ function DebugFlags(props) {
194
+ const items = Object.values(props.customDebugFlags ?? import_editor.debugFlags);
192
195
  if (!items.length) return null;
193
196
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiMenuSubmenu.TldrawUiMenuSubmenu, { id: "debug flags", label: "Debug flags", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiMenuGroup.TldrawUiMenuGroup, { id: "debug flags", children: items.map((flag) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DebugFlagToggle, { flag }, flag.name)) }) });
194
197
  }
195
- function FeatureFlags() {
196
- const items = Object.values(import_editor.featureFlags);
198
+ function FeatureFlags(props) {
199
+ const items = Object.values(props.customFeatureFlags ?? import_editor.featureFlags);
197
200
  if (!items.length) return null;
198
201
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiMenuSubmenu.TldrawUiMenuSubmenu, { id: "feature flags", label: "Feature flags", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiMenuGroup.TldrawUiMenuGroup, { id: "feature flags", children: items.map((flag) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DebugFlagToggle, { flag }, flag.name)) }) });
199
202
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/ui/components/DebugMenu/DefaultDebugMenuContent.tsx"],
4
- "sourcesContent": ["import {\n\tDebugFlag,\n\tEditor,\n\tTLShapePartial,\n\tcreateShapeId,\n\tdebugFlags,\n\tfeatureFlags,\n\thardResetEditor,\n\ttrack,\n\tuniqueId,\n\tuseEditor,\n} from '@tldraw/editor'\nimport React from 'react'\nimport { useDialogs } from '../../context/dialogs'\nimport { useToasts } from '../../context/toasts'\nimport { untranslated } from '../../hooks/useTranslation/useTranslation'\nimport { TldrawUiButton } from '../primitives/Button/TldrawUiButton'\nimport { TldrawUiButtonCheck } from '../primitives/Button/TldrawUiButtonCheck'\nimport { TldrawUiButtonLabel } from '../primitives/Button/TldrawUiButtonLabel'\nimport {\n\tTldrawUiDialogBody,\n\tTldrawUiDialogCloseButton,\n\tTldrawUiDialogFooter,\n\tTldrawUiDialogHeader,\n\tTldrawUiDialogTitle,\n} from '../primitives/TldrawUiDialog'\nimport { TldrawUiMenuCheckboxItem } from '../primitives/menus/TldrawUiMenuCheckboxItem'\nimport { TldrawUiMenuGroup } from '../primitives/menus/TldrawUiMenuGroup'\nimport { TldrawUiMenuItem } from '../primitives/menus/TldrawUiMenuItem'\nimport { TldrawUiMenuSubmenu } from '../primitives/menus/TldrawUiMenuSubmenu'\n\n/** @public @react */\nexport function DefaultDebugMenuContent() {\n\tconst editor = useEditor()\n\tconst { addToast } = useToasts()\n\tconst { addDialog } = useDialogs()\n\tconst [error, setError] = React.useState<boolean>(false)\n\n\treturn (\n\t\t<>\n\t\t\t<TldrawUiMenuGroup id=\"items\">\n\t\t\t\t<TldrawUiMenuItem id=\"hard-reset\" onSelect={hardResetEditor} label={'Hard reset'} />\n\t\t\t\t<TldrawUiMenuItem\n\t\t\t\t\tid=\"add-toast\"\n\t\t\t\t\tonSelect={() => {\n\t\t\t\t\t\taddToast({\n\t\t\t\t\t\t\tid: uniqueId(),\n\t\t\t\t\t\t\ttitle: 'Something good happened',\n\t\t\t\t\t\t\tdescription: 'Hey, attend to this thing over here. It might be important!',\n\t\t\t\t\t\t\tkeepOpen: true,\n\t\t\t\t\t\t\tseverity: 'success',\n\t\t\t\t\t\t})\n\t\t\t\t\t\taddToast({\n\t\t\t\t\t\t\tid: uniqueId(),\n\t\t\t\t\t\t\ttitle: 'Something happened',\n\t\t\t\t\t\t\tdescription: 'Hey, attend to this thing over here. It might be important!',\n\t\t\t\t\t\t\tkeepOpen: true,\n\t\t\t\t\t\t\tseverity: 'info',\n\t\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: 'Primary',\n\t\t\t\t\t\t\t\t\ttype: 'primary',\n\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: 'Normal',\n\t\t\t\t\t\t\t\t\ttype: 'normal',\n\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: 'Danger',\n\t\t\t\t\t\t\t\t\ttype: 'danger',\n\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t\t\t},\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\taddToast({\n\t\t\t\t\t\t\tid: uniqueId(),\n\t\t\t\t\t\t\ttitle: 'Something maybe bad happened',\n\t\t\t\t\t\t\tdescription: 'Hey, attend to this thing over here. It might be important!',\n\t\t\t\t\t\t\tkeepOpen: true,\n\t\t\t\t\t\t\tseverity: 'warning',\n\t\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: 'Primary',\n\t\t\t\t\t\t\t\t\ttype: 'primary',\n\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: 'Normal',\n\t\t\t\t\t\t\t\t\ttype: 'normal',\n\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: 'Danger',\n\t\t\t\t\t\t\t\t\ttype: 'danger',\n\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t\t\t},\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\taddToast({\n\t\t\t\t\t\t\tid: uniqueId(),\n\t\t\t\t\t\t\ttitle: 'Something bad happened',\n\t\t\t\t\t\t\tseverity: 'error',\n\t\t\t\t\t\t\tkeepOpen: true,\n\t\t\t\t\t\t})\n\t\t\t\t\t}}\n\t\t\t\t\tlabel={untranslated('Show toast')}\n\t\t\t\t/>\n\t\t\t\t<TldrawUiMenuItem\n\t\t\t\t\tid=\"show-dialog\"\n\t\t\t\t\tlabel={'Show dialog'}\n\t\t\t\t\tonSelect={() => {\n\t\t\t\t\t\taddDialog({\n\t\t\t\t\t\t\tcomponent: ({ onClose }) => (\n\t\t\t\t\t\t\t\t<ExampleDialog\n\t\t\t\t\t\t\t\t\tdisplayDontShowAgain\n\t\t\t\t\t\t\t\t\tonCancel={() => onClose()}\n\t\t\t\t\t\t\t\t\tonContinue={() => onClose()}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tonClose: () => {\n\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t}}\n\t\t\t\t/>\n\t\t\t\t<TldrawUiMenuItem\n\t\t\t\t\tid=\"create-shapes\"\n\t\t\t\t\tlabel={'Create 100 shapes'}\n\t\t\t\t\tonSelect={() => createNShapes(editor, 100)}\n\t\t\t\t/>\n\t\t\t\t<TldrawUiMenuItem\n\t\t\t\t\tid=\"count-nodes\"\n\t\t\t\t\tlabel={'Count shapes / nodes'}\n\t\t\t\t\tonSelect={() => {\n\t\t\t\t\t\tconst selectedShapes = editor.getSelectedShapes()\n\t\t\t\t\t\tconst shapes =\n\t\t\t\t\t\t\tselectedShapes.length === 0 ? editor.getRenderingShapes() : selectedShapes\n\t\t\t\t\t\twindow.alert(\n\t\t\t\t\t\t\t`Shapes ${shapes.length}, DOM nodes:${document.querySelector('.tl-shapes')!.querySelectorAll('*')?.length}`\n\t\t\t\t\t\t)\n\t\t\t\t\t}}\n\t\t\t\t/>\n\t\t\t\t{(() => {\n\t\t\t\t\tif (error) throw Error('oh no!')\n\t\t\t\t\treturn null\n\t\t\t\t})()}\n\t\t\t\t<TldrawUiMenuItem id=\"throw-error\" onSelect={() => setError(true)} label={'Throw error'} />\n\t\t\t</TldrawUiMenuGroup>\n\t\t\t<TldrawUiMenuGroup id=\"flags\">\n\t\t\t\t<DebugFlags />\n\t\t\t\t<FeatureFlags />\n\t\t\t</TldrawUiMenuGroup>\n\t\t</>\n\t)\n}\n/** @public @react */\nexport function DebugFlags() {\n\tconst items = Object.values(debugFlags)\n\tif (!items.length) return null\n\treturn (\n\t\t<TldrawUiMenuSubmenu id=\"debug flags\" label=\"Debug flags\">\n\t\t\t<TldrawUiMenuGroup id=\"debug flags\">\n\t\t\t\t{items.map((flag) => (\n\t\t\t\t\t<DebugFlagToggle key={flag.name} flag={flag} />\n\t\t\t\t))}\n\t\t\t</TldrawUiMenuGroup>\n\t\t</TldrawUiMenuSubmenu>\n\t)\n}\n/** @public @react */\nexport function FeatureFlags() {\n\tconst items = Object.values(featureFlags)\n\tif (!items.length) return null\n\treturn (\n\t\t<TldrawUiMenuSubmenu id=\"feature flags\" label=\"Feature flags\">\n\t\t\t<TldrawUiMenuGroup id=\"feature flags\">\n\t\t\t\t{items.map((flag) => (\n\t\t\t\t\t<DebugFlagToggle key={flag.name} flag={flag} />\n\t\t\t\t))}\n\t\t\t</TldrawUiMenuGroup>\n\t\t</TldrawUiMenuSubmenu>\n\t)\n}\n\n/** @public */\nexport interface ExampleDialogProps {\n\ttitle?: string\n\tbody?: React.ReactNode\n\tcancel?: string\n\tconfirm?: string\n\tdisplayDontShowAgain?: boolean\n\tmaxWidth?: string\n\tonCancel(): void\n\tonContinue(): void\n}\n\n/** @public @react */\nexport function ExampleDialog({\n\ttitle = 'title',\n\tbody = 'hello hello hello',\n\tcancel = 'Cancel',\n\tconfirm = 'Continue',\n\tdisplayDontShowAgain = false,\n\tmaxWidth = '350',\n\tonCancel,\n\tonContinue,\n}: ExampleDialogProps) {\n\tconst [dontShowAgain, setDontShowAgain] = React.useState(false)\n\n\treturn (\n\t\t<>\n\t\t\t<TldrawUiDialogHeader>\n\t\t\t\t<TldrawUiDialogTitle>{title}</TldrawUiDialogTitle>\n\t\t\t\t<TldrawUiDialogCloseButton />\n\t\t\t</TldrawUiDialogHeader>\n\t\t\t<TldrawUiDialogBody style={{ maxWidth }}>{body}</TldrawUiDialogBody>\n\t\t\t<TldrawUiDialogFooter className=\"tlui-dialog__footer__actions\">\n\t\t\t\t{displayDontShowAgain && (\n\t\t\t\t\t<TldrawUiButton\n\t\t\t\t\t\ttype=\"normal\"\n\t\t\t\t\t\tonClick={() => setDontShowAgain(!dontShowAgain)}\n\t\t\t\t\t\tstyle={{ marginRight: 'auto' }}\n\t\t\t\t\t>\n\t\t\t\t\t\t<TldrawUiButtonCheck checked={dontShowAgain} />\n\t\t\t\t\t\t<TldrawUiButtonLabel>Don\u2019t show again</TldrawUiButtonLabel>\n\t\t\t\t\t</TldrawUiButton>\n\t\t\t\t)}\n\t\t\t\t<TldrawUiButton type=\"normal\" onClick={onCancel}>\n\t\t\t\t\t<TldrawUiButtonLabel>{cancel}</TldrawUiButtonLabel>\n\t\t\t\t</TldrawUiButton>\n\t\t\t\t<TldrawUiButton type=\"primary\" onClick={async () => onContinue()}>\n\t\t\t\t\t<TldrawUiButtonLabel>{confirm}</TldrawUiButtonLabel>\n\t\t\t\t</TldrawUiButton>\n\t\t\t</TldrawUiDialogFooter>\n\t\t</>\n\t)\n}\n\nconst DebugFlagToggle = track(function DebugFlagToggle({\n\tflag,\n\tonChange,\n}: {\n\tflag: DebugFlag<boolean>\n\tonChange?(newValue: boolean): void\n}) {\n\tconst value = flag.get()\n\treturn (\n\t\t<TldrawUiMenuCheckboxItem\n\t\t\tid={flag.name}\n\t\t\ttitle={flag.name}\n\t\t\tlabel={flag.name\n\t\t\t\t.replace(/([a-z0-9])([A-Z])/g, (m) => `${m[0]} ${m[1].toLowerCase()}`)\n\t\t\t\t.replace(/^[a-z]/, (m) => m.toUpperCase())}\n\t\t\tchecked={value}\n\t\t\tonSelect={() => {\n\t\t\t\tflag.set(!value)\n\t\t\t\tonChange?.(!value)\n\t\t\t}}\n\t\t/>\n\t)\n})\n\nlet t = 0\n\nfunction createNShapes(editor: Editor, n: number) {\n\tconst gap = editor.options.adjacentShapeMargin\n\tconst shapesToCreate: TLShapePartial[] = Array(n)\n\tconst cols = Math.floor(Math.sqrt(n))\n\n\tfor (let i = 0; i < n; i++) {\n\t\tt++\n\t\tshapesToCreate[i] = {\n\t\t\tid: createShapeId('box' + t),\n\t\t\ttype: 'geo',\n\t\t\tx: (i % cols) * (100 + gap),\n\t\t\ty: Math.floor(i / cols) * (100 + gap),\n\t\t}\n\t}\n\n\teditor.run(() => {\n\t\t// allow this to trigger the max shapes alert\n\t\teditor.createShapes(shapesToCreate).setSelectedShapes(shapesToCreate.map((s) => s.id))\n\t})\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuCE;AAvCF,oBAWO;AACP,mBAAkB;AAClB,qBAA2B;AAC3B,oBAA0B;AAC1B,4BAA6B;AAC7B,4BAA+B;AAC/B,iCAAoC;AACpC,iCAAoC;AACpC,4BAMO;AACP,sCAAyC;AACzC,+BAAkC;AAClC,8BAAiC;AACjC,iCAAoC;AAG7B,SAAS,0BAA0B;AACzC,QAAM,aAAS,yBAAU;AACzB,QAAM,EAAE,SAAS,QAAI,yBAAU;AAC/B,QAAM,EAAE,UAAU,QAAI,2BAAW;AACjC,QAAM,CAAC,OAAO,QAAQ,IAAI,aAAAA,QAAM,SAAkB,KAAK;AAEvD,SACC,4EACC;AAAA,iDAAC,8CAAkB,IAAG,SACrB;AAAA,kDAAC,4CAAiB,IAAG,cAAa,UAAU,+BAAiB,OAAO,cAAc;AAAA,MAClF;AAAA,QAAC;AAAA;AAAA,UACA,IAAG;AAAA,UACH,UAAU,MAAM;AACf,qBAAS;AAAA,cACR,QAAI,wBAAS;AAAA,cACb,OAAO;AAAA,cACP,aAAa;AAAA,cACb,UAAU;AAAA,cACV,UAAU;AAAA,YACX,CAAC;AACD,qBAAS;AAAA,cACR,QAAI,wBAAS;AAAA,cACb,OAAO;AAAA,cACP,aAAa;AAAA,cACb,UAAU;AAAA,cACV,UAAU;AAAA,cACV,SAAS;AAAA,gBACR;AAAA,kBACC,OAAO;AAAA,kBACP,MAAM;AAAA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C,SAAS;AAAA,MACT,UAAU,MAAM;AACf,aAAK,IAAI,CAAC,KAAK;AACf,mBAAW,CAAC,KAAK;AAAA,MAClB;AAAA;AAAA,EACD;AAEF,CAAC;AAED,IAAI,IAAI;AAER,SAAS,cAAc,QAAgB,GAAW;AACjD,QAAM,MAAM,OAAO,QAAQ;AAC3B,QAAM,iBAAmC,MAAM,CAAC;AAChD,QAAM,OAAO,KAAK,MAAM,KAAK,KAAK,CAAC,CAAC;AAEpC,WAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC3B;AACA,mBAAe,CAAC,IAAI;AAAA,MACnB,QAAI,6BAAc,QAAQ,CAAC;AAAA,MAC3B,MAAM;AAAA,MACN,GAAI,IAAI,QAAS,MAAM;AAAA,MACvB,GAAG,KAAK,MAAM,IAAI,IAAI,KAAK,MAAM;AAAA,IAClC;AAAA,EACD;AAEA,SAAO,IAAI,MAAM;AAEhB,WAAO,aAAa,cAAc,EAAE,kBAAkB,eAAe,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;AAAA,EACtF,CAAC;AACF;",
4
+ "sourcesContent": ["import {\n\tDebugFlag,\n\tEditor,\n\tTLShapePartial,\n\tcreateShapeId,\n\tdebugFlags,\n\tfeatureFlags,\n\thardResetEditor,\n\ttrack,\n\tuniqueId,\n\tuseEditor,\n} from '@tldraw/editor'\nimport React from 'react'\nimport { useDialogs } from '../../context/dialogs'\nimport { useToasts } from '../../context/toasts'\nimport { untranslated } from '../../hooks/useTranslation/useTranslation'\nimport { TldrawUiButton } from '../primitives/Button/TldrawUiButton'\nimport { TldrawUiButtonCheck } from '../primitives/Button/TldrawUiButtonCheck'\nimport { TldrawUiButtonLabel } from '../primitives/Button/TldrawUiButtonLabel'\nimport {\n\tTldrawUiDialogBody,\n\tTldrawUiDialogCloseButton,\n\tTldrawUiDialogFooter,\n\tTldrawUiDialogHeader,\n\tTldrawUiDialogTitle,\n} from '../primitives/TldrawUiDialog'\nimport { TldrawUiMenuCheckboxItem } from '../primitives/menus/TldrawUiMenuCheckboxItem'\nimport { TldrawUiMenuGroup } from '../primitives/menus/TldrawUiMenuGroup'\nimport { TldrawUiMenuItem } from '../primitives/menus/TldrawUiMenuItem'\nimport { TldrawUiMenuSubmenu } from '../primitives/menus/TldrawUiMenuSubmenu'\n\n/** @public */\nexport interface CustomDebugFlags {\n\tcustomDebugFlags?: Record<string, DebugFlag<boolean>>\n\tcustomFeatureFlags?: Record<string, DebugFlag<boolean>>\n}\n\n/** @public @react */\nexport function DefaultDebugMenuContent({\n\tcustomDebugFlags,\n\tcustomFeatureFlags,\n}: CustomDebugFlags) {\n\tconst editor = useEditor()\n\tconst { addToast } = useToasts()\n\tconst { addDialog } = useDialogs()\n\tconst [error, setError] = React.useState<boolean>(false)\n\n\treturn (\n\t\t<>\n\t\t\t<TldrawUiMenuGroup id=\"items\">\n\t\t\t\t<TldrawUiMenuItem id=\"hard-reset\" onSelect={hardResetEditor} label={'Hard reset'} />\n\t\t\t\t<TldrawUiMenuItem\n\t\t\t\t\tid=\"add-toast\"\n\t\t\t\t\tonSelect={() => {\n\t\t\t\t\t\taddToast({\n\t\t\t\t\t\t\tid: uniqueId(),\n\t\t\t\t\t\t\ttitle: 'Something good happened',\n\t\t\t\t\t\t\tdescription: 'Hey, attend to this thing over here. It might be important!',\n\t\t\t\t\t\t\tkeepOpen: true,\n\t\t\t\t\t\t\tseverity: 'success',\n\t\t\t\t\t\t})\n\t\t\t\t\t\taddToast({\n\t\t\t\t\t\t\tid: uniqueId(),\n\t\t\t\t\t\t\ttitle: 'Something happened',\n\t\t\t\t\t\t\tdescription: 'Hey, attend to this thing over here. It might be important!',\n\t\t\t\t\t\t\tkeepOpen: true,\n\t\t\t\t\t\t\tseverity: 'info',\n\t\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: 'Primary',\n\t\t\t\t\t\t\t\t\ttype: 'primary',\n\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: 'Normal',\n\t\t\t\t\t\t\t\t\ttype: 'normal',\n\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: 'Danger',\n\t\t\t\t\t\t\t\t\ttype: 'danger',\n\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t\t\t},\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\taddToast({\n\t\t\t\t\t\t\tid: uniqueId(),\n\t\t\t\t\t\t\ttitle: 'Something maybe bad happened',\n\t\t\t\t\t\t\tdescription: 'Hey, attend to this thing over here. It might be important!',\n\t\t\t\t\t\t\tkeepOpen: true,\n\t\t\t\t\t\t\tseverity: 'warning',\n\t\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: 'Primary',\n\t\t\t\t\t\t\t\t\ttype: 'primary',\n\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: 'Normal',\n\t\t\t\t\t\t\t\t\ttype: 'normal',\n\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: 'Danger',\n\t\t\t\t\t\t\t\t\ttype: 'danger',\n\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t\t\t},\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\taddToast({\n\t\t\t\t\t\t\tid: uniqueId(),\n\t\t\t\t\t\t\ttitle: 'Something bad happened',\n\t\t\t\t\t\t\tseverity: 'error',\n\t\t\t\t\t\t\tkeepOpen: true,\n\t\t\t\t\t\t})\n\t\t\t\t\t}}\n\t\t\t\t\tlabel={untranslated('Show toast')}\n\t\t\t\t/>\n\t\t\t\t<TldrawUiMenuItem\n\t\t\t\t\tid=\"show-dialog\"\n\t\t\t\t\tlabel={'Show dialog'}\n\t\t\t\t\tonSelect={() => {\n\t\t\t\t\t\taddDialog({\n\t\t\t\t\t\t\tcomponent: ({ onClose }) => (\n\t\t\t\t\t\t\t\t<ExampleDialog\n\t\t\t\t\t\t\t\t\tdisplayDontShowAgain\n\t\t\t\t\t\t\t\t\tonCancel={() => onClose()}\n\t\t\t\t\t\t\t\t\tonContinue={() => onClose()}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tonClose: () => {\n\t\t\t\t\t\t\t\tvoid null\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t}}\n\t\t\t\t/>\n\t\t\t\t<TldrawUiMenuItem\n\t\t\t\t\tid=\"create-shapes\"\n\t\t\t\t\tlabel={'Create 100 shapes'}\n\t\t\t\t\tonSelect={() => createNShapes(editor, 100)}\n\t\t\t\t/>\n\t\t\t\t<TldrawUiMenuItem\n\t\t\t\t\tid=\"count-nodes\"\n\t\t\t\t\tlabel={'Count shapes / nodes'}\n\t\t\t\t\tonSelect={() => {\n\t\t\t\t\t\tconst selectedShapes = editor.getSelectedShapes()\n\t\t\t\t\t\tconst shapes =\n\t\t\t\t\t\t\tselectedShapes.length === 0 ? editor.getRenderingShapes() : selectedShapes\n\t\t\t\t\t\twindow.alert(\n\t\t\t\t\t\t\t`Shapes ${shapes.length}, DOM nodes:${document.querySelector('.tl-shapes')!.querySelectorAll('*')?.length}`\n\t\t\t\t\t\t)\n\t\t\t\t\t}}\n\t\t\t\t/>\n\t\t\t\t{(() => {\n\t\t\t\t\tif (error) throw Error('oh no!')\n\t\t\t\t\treturn null\n\t\t\t\t})()}\n\t\t\t\t<TldrawUiMenuItem id=\"throw-error\" onSelect={() => setError(true)} label={'Throw error'} />\n\t\t\t</TldrawUiMenuGroup>\n\t\t\t<TldrawUiMenuGroup id=\"flags\">\n\t\t\t\t<DebugFlags customDebugFlags={customDebugFlags} />\n\t\t\t\t<FeatureFlags customFeatureFlags={customFeatureFlags} />\n\t\t\t</TldrawUiMenuGroup>\n\t\t</>\n\t)\n}\n\n/** @public */\nexport interface DebugFlagsProps {\n\tcustomDebugFlags?: Record<string, DebugFlag<boolean>> | undefined\n}\n\n/** @public @react */\nexport function DebugFlags(props: DebugFlagsProps) {\n\tconst items = Object.values(props.customDebugFlags ?? debugFlags)\n\tif (!items.length) return null\n\treturn (\n\t\t<TldrawUiMenuSubmenu id=\"debug flags\" label=\"Debug flags\">\n\t\t\t<TldrawUiMenuGroup id=\"debug flags\">\n\t\t\t\t{items.map((flag) => (\n\t\t\t\t\t<DebugFlagToggle key={flag.name} flag={flag} />\n\t\t\t\t))}\n\t\t\t</TldrawUiMenuGroup>\n\t\t</TldrawUiMenuSubmenu>\n\t)\n}\n/** @public */\nexport interface FeatureFlagsProps {\n\tcustomFeatureFlags?: Record<string, DebugFlag<boolean>> | undefined\n}\n\n/** @public @react */\nexport function FeatureFlags(props: FeatureFlagsProps) {\n\tconst items = Object.values(props.customFeatureFlags ?? featureFlags)\n\tif (!items.length) return null\n\treturn (\n\t\t<TldrawUiMenuSubmenu id=\"feature flags\" label=\"Feature flags\">\n\t\t\t<TldrawUiMenuGroup id=\"feature flags\">\n\t\t\t\t{items.map((flag) => (\n\t\t\t\t\t<DebugFlagToggle key={flag.name} flag={flag} />\n\t\t\t\t))}\n\t\t\t</TldrawUiMenuGroup>\n\t\t</TldrawUiMenuSubmenu>\n\t)\n}\n\n/** @public */\nexport interface ExampleDialogProps {\n\ttitle?: string\n\tbody?: React.ReactNode\n\tcancel?: string\n\tconfirm?: string\n\tdisplayDontShowAgain?: boolean\n\tmaxWidth?: string\n\tonCancel(): void\n\tonContinue(): void\n}\n\n/** @public @react */\nexport function ExampleDialog({\n\ttitle = 'title',\n\tbody = 'hello hello hello',\n\tcancel = 'Cancel',\n\tconfirm = 'Continue',\n\tdisplayDontShowAgain = false,\n\tmaxWidth = '350',\n\tonCancel,\n\tonContinue,\n}: ExampleDialogProps) {\n\tconst [dontShowAgain, setDontShowAgain] = React.useState(false)\n\n\treturn (\n\t\t<>\n\t\t\t<TldrawUiDialogHeader>\n\t\t\t\t<TldrawUiDialogTitle>{title}</TldrawUiDialogTitle>\n\t\t\t\t<TldrawUiDialogCloseButton />\n\t\t\t</TldrawUiDialogHeader>\n\t\t\t<TldrawUiDialogBody style={{ maxWidth }}>{body}</TldrawUiDialogBody>\n\t\t\t<TldrawUiDialogFooter className=\"tlui-dialog__footer__actions\">\n\t\t\t\t{displayDontShowAgain && (\n\t\t\t\t\t<TldrawUiButton\n\t\t\t\t\t\ttype=\"normal\"\n\t\t\t\t\t\tonClick={() => setDontShowAgain(!dontShowAgain)}\n\t\t\t\t\t\tstyle={{ marginRight: 'auto' }}\n\t\t\t\t\t>\n\t\t\t\t\t\t<TldrawUiButtonCheck checked={dontShowAgain} />\n\t\t\t\t\t\t<TldrawUiButtonLabel>Don\u2019t show again</TldrawUiButtonLabel>\n\t\t\t\t\t</TldrawUiButton>\n\t\t\t\t)}\n\t\t\t\t<TldrawUiButton type=\"normal\" onClick={onCancel}>\n\t\t\t\t\t<TldrawUiButtonLabel>{cancel}</TldrawUiButtonLabel>\n\t\t\t\t</TldrawUiButton>\n\t\t\t\t<TldrawUiButton type=\"primary\" onClick={async () => onContinue()}>\n\t\t\t\t\t<TldrawUiButtonLabel>{confirm}</TldrawUiButtonLabel>\n\t\t\t\t</TldrawUiButton>\n\t\t\t</TldrawUiDialogFooter>\n\t\t</>\n\t)\n}\n\nconst DebugFlagToggle = track(function DebugFlagToggle({\n\tflag,\n\tonChange,\n}: {\n\tflag: DebugFlag<boolean>\n\tonChange?(newValue: boolean): void\n}) {\n\tconst value = flag.get()\n\treturn (\n\t\t<TldrawUiMenuCheckboxItem\n\t\t\tid={flag.name}\n\t\t\ttitle={flag.name}\n\t\t\tlabel={flag.name\n\t\t\t\t.replace(/([a-z0-9])([A-Z])/g, (m) => `${m[0]} ${m[1].toLowerCase()}`)\n\t\t\t\t.replace(/^[a-z]/, (m) => m.toUpperCase())}\n\t\t\tchecked={value}\n\t\t\tonSelect={() => {\n\t\t\t\tflag.set(!value)\n\t\t\t\tonChange?.(!value)\n\t\t\t}}\n\t\t/>\n\t)\n})\n\nlet t = 0\n\nfunction createNShapes(editor: Editor, n: number) {\n\tconst gap = editor.options.adjacentShapeMargin\n\tconst shapesToCreate: TLShapePartial[] = Array(n)\n\tconst cols = Math.floor(Math.sqrt(n))\n\n\tfor (let i = 0; i < n; i++) {\n\t\tt++\n\t\tshapesToCreate[i] = {\n\t\t\tid: createShapeId('box' + t),\n\t\t\ttype: 'geo',\n\t\t\tx: (i % cols) * (100 + gap),\n\t\t\ty: Math.floor(i / cols) * (100 + gap),\n\t\t}\n\t}\n\n\teditor.run(() => {\n\t\t// allow this to trigger the max shapes alert\n\t\teditor.createShapes(shapesToCreate).setSelectedShapes(shapesToCreate.map((s) => s.id))\n\t})\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgDE;AAhDF,oBAWO;AACP,mBAAkB;AAClB,qBAA2B;AAC3B,oBAA0B;AAC1B,4BAA6B;AAC7B,4BAA+B;AAC/B,iCAAoC;AACpC,iCAAoC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AAA,MAC3B,MAAM;AAAA,MACN,GAAI,IAAI,QAAS,MAAM;AAAA,MACvB,GAAG,KAAK,MAAM,IAAI,IAAI,KAAK,MAAM;AAAA,IAClC;AAAA,EACD;AAEA,SAAO,IAAI,MAAM;AAEhB,WAAO,aAAa,cAAc,EAAE,kBAAkB,eAAe,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;AAAA,EACtF,CAAC;AACF;",
6
6
  "names": ["React", "DebugFlagToggle"]
7
7
  }
@@ -102,7 +102,9 @@ function useEditingLinkBehavior(textEditor) {
102
102
  };
103
103
  textEditor.view.dom.addEventListener("click", handleClick);
104
104
  return () => {
105
- textEditor.view.dom.removeEventListener("click", handleClick);
105
+ if (textEditor.isInitialized) {
106
+ textEditor.view.dom.removeEventListener("click", handleClick);
107
+ }
106
108
  };
107
109
  }, [textEditor, isEditingLink]);
108
110
  (0, import_react.useEffect)(() => {
@@ -155,7 +157,9 @@ function useIsMousingDownOnTextEditor(textEditor) {
155
157
  });
156
158
  return () => {
157
159
  touchDownEvents.forEach((eventName) => {
158
- textEditor.view.dom.removeEventListener(eventName, handlePointingDown);
160
+ if (textEditor.isInitialized) {
161
+ textEditor.view.dom.removeEventListener(eventName, handlePointingDown);
162
+ }
159
163
  });
160
164
  touchUpEvents.forEach((eventName) => {
161
165
  document.body.removeEventListener(eventName, handlePointingUp);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/ui/components/Toolbar/DefaultRichTextToolbar.tsx"],
4
- "sourcesContent": ["import { getMarkRange, Range, EditorEvents as TextEditorEvents } from '@tiptap/core'\nimport { MarkType } from '@tiptap/pm/model'\nimport { Box, debounce, TiptapEditor, track, useEditor, useValue } from '@tldraw/editor'\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { rectToBox, TldrawUiContextualToolbar } from '../primitives/TldrawUiContextualToolbar'\nimport { DefaultRichTextToolbarContent } from './DefaultRichTextToolbarContent'\nimport { LinkEditor } from './LinkEditor'\n\n/** @public */\nexport interface TLUiRichTextToolbarProps {\n\tchildren?: React.ReactNode\n}\n\n/**\n * The default rich text toolbar.\n *\n * @public @react\n */\nexport const DefaultRichTextToolbar = track(function DefaultRichTextToolbar({\n\tchildren,\n}: TLUiRichTextToolbarProps) {\n\tconst editor = useEditor()\n\n\tconst textEditor = useValue('textEditor', () => editor.getRichTextEditor(), [editor])\n\n\tif (editor.getInstanceState().isCoarsePointer || !textEditor) return null\n\n\treturn <ContextualToolbarInner textEditor={textEditor}>{children}</ContextualToolbarInner>\n})\n\nfunction ContextualToolbarInner({\n\ttextEditor,\n\tchildren,\n}: {\n\tchildren?: React.ReactNode\n\ttextEditor: TiptapEditor\n}) {\n\tconst { isEditingLink, onEditLinkStart, onEditLinkClose } = useEditingLinkBehavior(textEditor)\n\tconst [currentSelection, setCurrentSelection] = useState<Range | null>(null)\n\tconst previousSelectionBounds = useRef<Box | undefined>()\n\tconst isMousingDown = useIsMousingDownOnTextEditor(textEditor)\n\tconst msg = useTranslation()\n\n\tconst getSelectionBounds = useCallback(() => {\n\t\tif (isEditingLink) {\n\t\t\t// If we're editing a link we don't have selection bounds temporarily.\n\t\t\treturn previousSelectionBounds.current\n\t\t}\n\t\t// Get the text selection rects as a box. This will be undefined if there are no selections.\n\t\tconst selection = window.getSelection()\n\n\t\t// If there are no selections, don't return a box\n\t\tif (!currentSelection || !selection || selection.rangeCount === 0 || selection.isCollapsed)\n\t\t\treturn\n\n\t\t// Get a common box from all of the ranges' screen rects\n\t\tconst rangeBoxes: Box[] = []\n\t\tfor (let i = 0; i < selection.rangeCount; i++) {\n\t\t\tconst range = selection.getRangeAt(i)\n\t\t\trangeBoxes.push(rectToBox(range.getBoundingClientRect()))\n\t\t}\n\n\t\tconst bounds = Box.Common(rangeBoxes)\n\t\tpreviousSelectionBounds.current = bounds\n\t\treturn bounds\n\t}, [currentSelection, isEditingLink])\n\n\tuseEffect(() => {\n\t\tconst handleSelectionUpdate = ({ editor: textEditor }: TextEditorEvents['selectionUpdate']) =>\n\t\t\tsetCurrentSelection(textEditor.state.selection)\n\t\ttextEditor.on('selectionUpdate', handleSelectionUpdate)\n\t\t// Need to kick off the selection update manually to get the initial selection, esp. if select-all.\n\t\thandleSelectionUpdate({ editor: textEditor } as TextEditorEvents['selectionUpdate'])\n\t\treturn () => {\n\t\t\ttextEditor.off('selectionUpdate', handleSelectionUpdate)\n\t\t}\n\t}, [textEditor])\n\n\treturn (\n\t\t<TldrawUiContextualToolbar\n\t\t\tclassName=\"tlui-rich-text__toolbar\"\n\t\t\tgetSelectionBounds={getSelectionBounds}\n\t\t\tisMousingDown={isMousingDown}\n\t\t\tchangeOnlyWhenYChanges={true}\n\t\t\tlabel={msg('tool.rich-text-toolbar-title')}\n\t\t>\n\t\t\t{children ? (\n\t\t\t\tchildren\n\t\t\t) : isEditingLink ? (\n\t\t\t\t<LinkEditor\n\t\t\t\t\ttextEditor={textEditor}\n\t\t\t\t\tvalue={textEditor.isActive('link') ? textEditor.getAttributes('link').href : ''}\n\t\t\t\t\tonClose={onEditLinkClose}\n\t\t\t\t/>\n\t\t\t) : (\n\t\t\t\t<DefaultRichTextToolbarContent textEditor={textEditor} onEditLinkStart={onEditLinkStart} />\n\t\t\t)}\n\t\t</TldrawUiContextualToolbar>\n\t)\n}\n\nfunction useEditingLinkBehavior(textEditor?: TiptapEditor) {\n\tconst [isEditingLink, setIsEditingLink] = useState(false)\n\n\t// Set up text editor event listeners.\n\tuseEffect(() => {\n\t\tif (!textEditor) {\n\t\t\tsetIsEditingLink(false)\n\t\t\treturn\n\t\t}\n\n\t\tconst handleClick = () => {\n\t\t\tconst isLinkActive = textEditor.isActive('link')\n\t\t\tsetIsEditingLink(isLinkActive)\n\t\t}\n\n\t\ttextEditor.view.dom.addEventListener('click', handleClick)\n\t\treturn () => {\n\t\t\ttextEditor.view.dom.removeEventListener('click', handleClick)\n\t\t}\n\t}, [textEditor, isEditingLink])\n\n\t// If we're editing a link, select the entire link.\n\t// This can happen via a click or via keyboarding over to the link and then\n\t// clicking the toolbar button.\n\tuseEffect(() => {\n\t\tif (!textEditor) {\n\t\t\treturn\n\t\t}\n\n\t\t// N.B. This specifically isn't checking the isEditingLink state but\n\t\t// the current active state of the text editor. This is because there's\n\t\t// a subtelty where when going edit-to-edit, that is text editor-to-text editor\n\t\t// in different shapes, the isEditingLink state doesn't get reset quickly enough.\n\t\tif (textEditor.isActive('link')) {\n\t\t\ttry {\n\t\t\t\tconst { from, to } = getMarkRange(\n\t\t\t\t\ttextEditor.state.doc.resolve(textEditor.state.selection.from),\n\t\t\t\t\ttextEditor.schema.marks.link as MarkType\n\t\t\t\t) as Range\n\t\t\t\t// Select the entire link if we just clicked on it while in edit mode, but not if there's\n\t\t\t\t// a specific selection.\n\t\t\t\tif (textEditor.state.selection.empty) {\n\t\t\t\t\ttextEditor.commands.setTextSelection({ from, to })\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Sometimes getMarkRange throws an error when the selection is the entire document.\n\t\t\t\t// This is somewhat mysterious but it's harmless. We just need to ignore it.\n\t\t\t\t// Also, this seems to have recently broken with the React 19 preparation changes.\n\t\t\t}\n\t\t}\n\t}, [textEditor, isEditingLink])\n\n\tconst onEditLinkStart = useCallback(() => {\n\t\tsetIsEditingLink(true)\n\t}, [])\n\n\tconst onEditLinkCancel = useCallback(() => {\n\t\tsetIsEditingLink(false)\n\t}, [])\n\n\tconst onEditLinkClose = useCallback(() => {\n\t\tsetIsEditingLink(false)\n\t\tif (!textEditor) return\n\t\tconst from = textEditor.state.selection.from\n\t\ttextEditor.commands.setTextSelection({ from, to: from })\n\t}, [textEditor])\n\n\treturn { isEditingLink, onEditLinkStart, onEditLinkClose, onEditLinkCancel }\n}\n\nfunction useIsMousingDownOnTextEditor(textEditor: TiptapEditor) {\n\tconst [isMousingDown, setIsMousingDown] = useState(false)\n\n\t// Set up general event listeners for text selection.\n\tuseEffect(() => {\n\t\tif (!textEditor) return\n\n\t\tconst handlePointingStateChange = debounce(({ isPointing }: { isPointing: boolean }) => {\n\t\t\tsetIsMousingDown(isPointing)\n\t\t}, 16)\n\t\tconst handlePointingDown = () => handlePointingStateChange({ isPointing: true })\n\t\tconst handlePointingUp = () => handlePointingStateChange({ isPointing: false })\n\n\t\tconst touchDownEvents = ['touchstart', 'pointerdown', 'mousedown']\n\t\tconst touchUpEvents = ['touchend', 'pointerup', 'mouseup']\n\t\ttouchDownEvents.forEach((eventName: string) => {\n\t\t\ttextEditor.view.dom.addEventListener(eventName, handlePointingDown)\n\t\t})\n\t\ttouchUpEvents.forEach((eventName: string) => {\n\t\t\tdocument.body.addEventListener(eventName, handlePointingUp)\n\t\t})\n\t\treturn () => {\n\t\t\ttouchDownEvents.forEach((eventName: string) => {\n\t\t\t\ttextEditor.view.dom.removeEventListener(eventName, handlePointingDown)\n\t\t\t})\n\t\t\ttouchUpEvents.forEach((eventName: string) => {\n\t\t\t\tdocument.body.removeEventListener(eventName, handlePointingUp)\n\t\t\t})\n\t\t}\n\t}, [textEditor])\n\n\treturn isMousingDown\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BQ;AA5BR,kBAAsE;AAEtE,oBAAwE;AACxE,mBAAgE;AAChE,4BAA+B;AAC/B,uCAAqD;AACrD,2CAA8C;AAC9C,wBAA2B;AAYpB,MAAM,6BAAyB,qBAAM,SAASA,wBAAuB;AAAA,EAC3E;AACD,GAA6B;AAC5B,QAAM,aAAS,yBAAU;AAEzB,QAAM,iBAAa,wBAAS,cAAc,MAAM,OAAO,kBAAkB,GAAG,CAAC,MAAM,CAAC;AAEpF,MAAI,OAAO,iBAAiB,EAAE,mBAAmB,CAAC,WAAY,QAAO;AAErE,SAAO,4CAAC,0BAAuB,YAAyB,UAAS;AAClE,CAAC;AAED,SAAS,uBAAuB;AAAA,EAC/B;AAAA,EACA;AACD,GAGG;AACF,QAAM,EAAE,eAAe,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I,KAAK,CAAC;AAAA,EACxD,GAAG,CAAC,UAAU,CAAC;AAEf,SAAO,EAAE,eAAe,iBAAiB,iBAAiB,iBAAiB;AAC5E;AAEA,SAAS,6BAA6B,YAA0B;AAC/D,QAAM,CAAC,eAAe,gBAAgB,QAAI,uBAAS,KAAK;AAGxD,8BAAU,MAAM;AACf,QAAI,CAAC,WAAY;AAEjB,UAAM,gCAA4B,wBAAS,CAAC,EAAE,WAAW,MAA+B;AACvF,uBAAiB,UAAU;AAAA,IAC5B,GAAG,EAAE;AACL,UAAM,qBAAqB,MAAM,0BAA0B,EAAE,YAAY,KAAK,CAAC;AAC/E,UAAM,mBAAmB,MAAM,0BAA0B,EAAE,YAAY,MAAM,CAAC;AAE9E,UAAM,kBAAkB,CAAC,cAAc,eAAe,WAAW;AACjE,UAAM,gBAAgB,CAAC,YAAY,aAAa,SAAS;AACzD,oBAAgB,QAAQ,CAAC,cAAsB;AAC9C,iBAAW,KAAK,IAAI,iBAAiB,WAAW,kBAAkB;AAAA,IACnE,CAAC;AACD,kBAAc,QAAQ,CAAC,cAAsB;AAC5C,eAAS,KAAK,iBAAiB,WAAW,gBAAgB;AAAA,IAC3D,CAAC;AACD,WAAO,MAAM;AACZ,sBAAgB,QAAQ,CAAC,cAAsB;AAC9C,mBAAW,KAAK,IAAI,oBAAoB,WAAW,kBAAkB;AAAA,MACtE,CAAC;AACD,oBAAc,QAAQ,CAAC,cAAsB;AAC5C,iBAAS,KAAK,oBAAoB,WAAW,gBAAgB;AAAA,MAC9D,CAAC;AAAA,IACF;AAAA,EACD,GAAG,CAAC,UAAU,CAAC;AAEf,SAAO;AACR;",
4
+ "sourcesContent": ["import { getMarkRange, Range, EditorEvents as TextEditorEvents } from '@tiptap/core'\nimport { MarkType } from '@tiptap/pm/model'\nimport { Box, debounce, TiptapEditor, track, useEditor, useValue } from '@tldraw/editor'\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { rectToBox, TldrawUiContextualToolbar } from '../primitives/TldrawUiContextualToolbar'\nimport { DefaultRichTextToolbarContent } from './DefaultRichTextToolbarContent'\nimport { LinkEditor } from './LinkEditor'\n\n/** @public */\nexport interface TLUiRichTextToolbarProps {\n\tchildren?: React.ReactNode\n}\n\n/**\n * The default rich text toolbar.\n *\n * @public @react\n */\nexport const DefaultRichTextToolbar = track(function DefaultRichTextToolbar({\n\tchildren,\n}: TLUiRichTextToolbarProps) {\n\tconst editor = useEditor()\n\n\tconst textEditor = useValue('textEditor', () => editor.getRichTextEditor(), [editor])\n\n\tif (editor.getInstanceState().isCoarsePointer || !textEditor) return null\n\n\treturn <ContextualToolbarInner textEditor={textEditor}>{children}</ContextualToolbarInner>\n})\n\nfunction ContextualToolbarInner({\n\ttextEditor,\n\tchildren,\n}: {\n\tchildren?: React.ReactNode\n\ttextEditor: TiptapEditor\n}) {\n\tconst { isEditingLink, onEditLinkStart, onEditLinkClose } = useEditingLinkBehavior(textEditor)\n\tconst [currentSelection, setCurrentSelection] = useState<Range | null>(null)\n\tconst previousSelectionBounds = useRef<Box | undefined>()\n\tconst isMousingDown = useIsMousingDownOnTextEditor(textEditor)\n\tconst msg = useTranslation()\n\n\tconst getSelectionBounds = useCallback(() => {\n\t\tif (isEditingLink) {\n\t\t\t// If we're editing a link we don't have selection bounds temporarily.\n\t\t\treturn previousSelectionBounds.current\n\t\t}\n\t\t// Get the text selection rects as a box. This will be undefined if there are no selections.\n\t\tconst selection = window.getSelection()\n\n\t\t// If there are no selections, don't return a box\n\t\tif (!currentSelection || !selection || selection.rangeCount === 0 || selection.isCollapsed)\n\t\t\treturn\n\n\t\t// Get a common box from all of the ranges' screen rects\n\t\tconst rangeBoxes: Box[] = []\n\t\tfor (let i = 0; i < selection.rangeCount; i++) {\n\t\t\tconst range = selection.getRangeAt(i)\n\t\t\trangeBoxes.push(rectToBox(range.getBoundingClientRect()))\n\t\t}\n\n\t\tconst bounds = Box.Common(rangeBoxes)\n\t\tpreviousSelectionBounds.current = bounds\n\t\treturn bounds\n\t}, [currentSelection, isEditingLink])\n\n\tuseEffect(() => {\n\t\tconst handleSelectionUpdate = ({ editor: textEditor }: TextEditorEvents['selectionUpdate']) =>\n\t\t\tsetCurrentSelection(textEditor.state.selection)\n\t\ttextEditor.on('selectionUpdate', handleSelectionUpdate)\n\t\t// Need to kick off the selection update manually to get the initial selection, esp. if select-all.\n\t\thandleSelectionUpdate({ editor: textEditor } as TextEditorEvents['selectionUpdate'])\n\t\treturn () => {\n\t\t\ttextEditor.off('selectionUpdate', handleSelectionUpdate)\n\t\t}\n\t}, [textEditor])\n\n\treturn (\n\t\t<TldrawUiContextualToolbar\n\t\t\tclassName=\"tlui-rich-text__toolbar\"\n\t\t\tgetSelectionBounds={getSelectionBounds}\n\t\t\tisMousingDown={isMousingDown}\n\t\t\tchangeOnlyWhenYChanges={true}\n\t\t\tlabel={msg('tool.rich-text-toolbar-title')}\n\t\t>\n\t\t\t{children ? (\n\t\t\t\tchildren\n\t\t\t) : isEditingLink ? (\n\t\t\t\t<LinkEditor\n\t\t\t\t\ttextEditor={textEditor}\n\t\t\t\t\tvalue={textEditor.isActive('link') ? textEditor.getAttributes('link').href : ''}\n\t\t\t\t\tonClose={onEditLinkClose}\n\t\t\t\t/>\n\t\t\t) : (\n\t\t\t\t<DefaultRichTextToolbarContent textEditor={textEditor} onEditLinkStart={onEditLinkStart} />\n\t\t\t)}\n\t\t</TldrawUiContextualToolbar>\n\t)\n}\n\nfunction useEditingLinkBehavior(textEditor?: TiptapEditor) {\n\tconst [isEditingLink, setIsEditingLink] = useState(false)\n\n\t// Set up text editor event listeners.\n\tuseEffect(() => {\n\t\tif (!textEditor) {\n\t\t\tsetIsEditingLink(false)\n\t\t\treturn\n\t\t}\n\n\t\tconst handleClick = () => {\n\t\t\tconst isLinkActive = textEditor.isActive('link')\n\t\t\tsetIsEditingLink(isLinkActive)\n\t\t}\n\n\t\ttextEditor.view.dom.addEventListener('click', handleClick)\n\t\treturn () => {\n\t\t\tif (textEditor.isInitialized) {\n\t\t\t\ttextEditor.view.dom.removeEventListener('click', handleClick)\n\t\t\t}\n\t\t}\n\t}, [textEditor, isEditingLink])\n\n\t// If we're editing a link, select the entire link.\n\t// This can happen via a click or via keyboarding over to the link and then\n\t// clicking the toolbar button.\n\tuseEffect(() => {\n\t\tif (!textEditor) {\n\t\t\treturn\n\t\t}\n\n\t\t// N.B. This specifically isn't checking the isEditingLink state but\n\t\t// the current active state of the text editor. This is because there's\n\t\t// a subtelty where when going edit-to-edit, that is text editor-to-text editor\n\t\t// in different shapes, the isEditingLink state doesn't get reset quickly enough.\n\t\tif (textEditor.isActive('link')) {\n\t\t\ttry {\n\t\t\t\tconst { from, to } = getMarkRange(\n\t\t\t\t\ttextEditor.state.doc.resolve(textEditor.state.selection.from),\n\t\t\t\t\ttextEditor.schema.marks.link as MarkType\n\t\t\t\t) as Range\n\t\t\t\t// Select the entire link if we just clicked on it while in edit mode, but not if there's\n\t\t\t\t// a specific selection.\n\t\t\t\tif (textEditor.state.selection.empty) {\n\t\t\t\t\ttextEditor.commands.setTextSelection({ from, to })\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Sometimes getMarkRange throws an error when the selection is the entire document.\n\t\t\t\t// This is somewhat mysterious but it's harmless. We just need to ignore it.\n\t\t\t\t// Also, this seems to have recently broken with the React 19 preparation changes.\n\t\t\t}\n\t\t}\n\t}, [textEditor, isEditingLink])\n\n\tconst onEditLinkStart = useCallback(() => {\n\t\tsetIsEditingLink(true)\n\t}, [])\n\n\tconst onEditLinkCancel = useCallback(() => {\n\t\tsetIsEditingLink(false)\n\t}, [])\n\n\tconst onEditLinkClose = useCallback(() => {\n\t\tsetIsEditingLink(false)\n\t\tif (!textEditor) return\n\t\tconst from = textEditor.state.selection.from\n\t\ttextEditor.commands.setTextSelection({ from, to: from })\n\t}, [textEditor])\n\n\treturn { isEditingLink, onEditLinkStart, onEditLinkClose, onEditLinkCancel }\n}\n\nfunction useIsMousingDownOnTextEditor(textEditor: TiptapEditor) {\n\tconst [isMousingDown, setIsMousingDown] = useState(false)\n\n\t// Set up general event listeners for text selection.\n\tuseEffect(() => {\n\t\tif (!textEditor) return\n\n\t\tconst handlePointingStateChange = debounce(({ isPointing }: { isPointing: boolean }) => {\n\t\t\tsetIsMousingDown(isPointing)\n\t\t}, 16)\n\t\tconst handlePointingDown = () => handlePointingStateChange({ isPointing: true })\n\t\tconst handlePointingUp = () => handlePointingStateChange({ isPointing: false })\n\n\t\tconst touchDownEvents = ['touchstart', 'pointerdown', 'mousedown']\n\t\tconst touchUpEvents = ['touchend', 'pointerup', 'mouseup']\n\t\ttouchDownEvents.forEach((eventName: string) => {\n\t\t\ttextEditor.view.dom.addEventListener(eventName, handlePointingDown)\n\t\t})\n\t\ttouchUpEvents.forEach((eventName: string) => {\n\t\t\tdocument.body.addEventListener(eventName, handlePointingUp)\n\t\t})\n\t\treturn () => {\n\t\t\ttouchDownEvents.forEach((eventName: string) => {\n\t\t\t\tif (textEditor.isInitialized) {\n\t\t\t\t\ttextEditor.view.dom.removeEventListener(eventName, handlePointingDown)\n\t\t\t\t}\n\t\t\t})\n\t\t\ttouchUpEvents.forEach((eventName: string) => {\n\t\t\t\tdocument.body.removeEventListener(eventName, handlePointingUp)\n\t\t\t})\n\t\t}\n\t}, [textEditor])\n\n\treturn isMousingDown\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BQ;AA5BR,kBAAsE;AAEtE,oBAAwE;AACxE,mBAAgE;AAChE,4BAA+B;AAC/B,uCAAqD;AACrD,2CAA8C;AAC9C,wBAA2B;AAYpB,MAAM,6BAAyB,qBAAM,SAASA,wBAAuB;AAAA,EAC3E;AACD,GAA6B;AAC5B,QAAM,aAAS,yBAAU;AAEzB,QAAM,iBAAa,wBAAS,cAAc,MAAM,OAAO,kBAAkB,GAAG,CAAC,MAAM,CAAC;AAEpF,MAAI,OAAO,iBAAiB,EAA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SAAO;AACR;",
6
6
  "names": ["DefaultRichTextToolbar", "textEditor"]
7
7
  }
@@ -60,6 +60,7 @@ function DefaultRichTextToolbarContent({
60
60
  }, [onEditLinkStart]);
61
61
  const actions = (0, import_react.useMemo)(() => {
62
62
  function handleOp(name, op) {
63
+ if (!textEditor.view) return;
63
64
  trackEvent("rich-text", { operation: name, source });
64
65
  textEditor.chain().focus()[op]().run();
65
66
  }
@@ -107,7 +108,7 @@ function DefaultRichTextToolbarContent({
107
108
  ].filter(Boolean);
108
109
  }, [textEditor, trackEvent, onEditLinkStart]);
109
110
  return actions.map(({ name, attrs, onSelect }) => {
110
- const isActive = textEditor.isActive(name, attrs);
111
+ const isActive = textEditor.view ? textEditor.isActive(name, attrs) : false;
111
112
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
112
113
  import_TldrawUiToolbar.TldrawUiToolbarButton,
113
114
  {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/ui/components/Toolbar/DefaultRichTextToolbarContent.tsx"],
4
- "sourcesContent": ["import { isAccelKey, preventDefault, TiptapEditor } from '@tldraw/editor'\nimport { useEffect, useMemo, useState } from 'react'\nimport { useUiEvents } from '../../context/events'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon'\nimport { TldrawUiToolbarButton } from '../primitives/TldrawUiToolbar'\n\n/** @public */\nexport interface DefaultRichTextToolbarContentProps {\n\tonEditLinkStart?(): void\n\ttextEditor: TiptapEditor\n}\n\n/**\n * Rich text toolbar items that have the basics.\n *\n * @public @react\n */\nexport function DefaultRichTextToolbarContent({\n\ttextEditor,\n\tonEditLinkStart,\n}: DefaultRichTextToolbarContentProps) {\n\tconst trackEvent = useUiEvents()\n\tconst msg = useTranslation()\n\tconst source = 'rich-text-menu'\n\n\t// We need to force this one to update when the editor updates or when selection changes\n\tconst [_, set] = useState(0)\n\tuseEffect(\n\t\tfunction forceUpdateWhenContentChanges() {\n\t\t\tfunction forceUpdate() {\n\t\t\t\tset((t) => t + 1)\n\t\t\t}\n\t\t\ttextEditor.on('update', forceUpdate)\n\t\t\ttextEditor.on('selectionUpdate', forceUpdate)\n\t\t},\n\t\t[textEditor]\n\t)\n\n\tuseEffect(() => {\n\t\tfunction handleKeyDown(event: KeyboardEvent) {\n\t\t\tif (onEditLinkStart && isAccelKey(event) && event.shiftKey && event.key === 'k') {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tonEditLinkStart()\n\t\t\t}\n\t\t}\n\n\t\tdocument.addEventListener('keydown', handleKeyDown)\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('keydown', handleKeyDown)\n\t\t}\n\t}, [onEditLinkStart])\n\n\t// todo: we could make this a prop\n\tconst actions = useMemo(() => {\n\t\tfunction handleOp(name: string, op: string) {\n\t\t\ttrackEvent('rich-text', { operation: name as any, source })\n\t\t\t// @ts-expect-error typing this is annoying at the moment.\n\t\t\ttextEditor.chain().focus()[op]().run()\n\t\t}\n\n\t\treturn [\n\t\t\t// { name: 'heading', attrs: { level: 3 }, onSelect() { textEditor.chain().focus().toggleHeading({ level: 3}).run() }},\n\t\t\t{\n\t\t\t\tname: 'bold',\n\t\t\t\tonSelect() {\n\t\t\t\t\thandleOp('bold', 'toggleBold')\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'italic',\n\t\t\t\tonSelect() {\n\t\t\t\t\thandleOp('bold', 'toggleItalic')\n\t\t\t\t},\n\t\t\t},\n\t\t\t// { name: 'underline', onSelect() { handleOp('underline', 'toggleUnderline') }},\n\t\t\t// { name: 'strike', onSelect() { handleOp('strike', 'toggleStrike') }},\n\t\t\t{\n\t\t\t\tname: 'code',\n\t\t\t\tonSelect() {\n\t\t\t\t\thandleOp('bold', 'toggleCode')\n\t\t\t\t},\n\t\t\t},\n\t\t\tonEditLinkStart\n\t\t\t\t? {\n\t\t\t\t\t\tname: 'link',\n\t\t\t\t\t\tonSelect() {\n\t\t\t\t\t\t\tonEditLinkStart()\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: undefined, // ? is this really optional?\n\t\t\t{\n\t\t\t\tname: 'bulletList',\n\t\t\t\tonSelect() {\n\t\t\t\t\thandleOp('bulletList', 'toggleBulletList')\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'highlight',\n\t\t\t\tonSelect() {\n\t\t\t\t\thandleOp('bulletList', 'toggleHighlight')\n\t\t\t\t},\n\t\t\t},\n\t\t].filter(Boolean) as {\n\t\t\tname: string\n\t\t\tattrs?: string\n\t\t\tonSelect(): void\n\t\t}[]\n\t}, [textEditor, trackEvent, onEditLinkStart])\n\n\treturn actions.map(({ name, attrs, onSelect }) => {\n\t\tconst isActive = textEditor.isActive(name, attrs)\n\t\treturn (\n\t\t\t<TldrawUiToolbarButton\n\t\t\t\tkey={name}\n\t\t\t\ttitle={msg(`tool.rich-text-${name}`)}\n\t\t\t\tdata-testid={`rich-text.${name}`}\n\t\t\t\ttype=\"icon\"\n\t\t\t\tisActive={isActive} // todo: we need to update this only when the text editor \"settles\", ie not during a change of selection\n\t\t\t\tonPointerDown={preventDefault}\n\t\t\t\tonClick={onSelect}\n\t\t\t\trole=\"option\"\n\t\t\t\taria-pressed={isActive}\n\t\t\t>\n\t\t\t\t<TldrawUiButtonIcon small icon={name} />\n\t\t\t</TldrawUiToolbarButton>\n\t\t)\n\t})\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4HI;AA5HJ,oBAAyD;AACzD,mBAA6C;AAC7C,oBAA4B;AAC5B,4BAA+B;AAC/B,gCAAmC;AACnC,6BAAsC;AAa/B,SAAS,8BAA8B;AAAA,EAC7C;AAAA,EACA;AACD,GAAuC;AACtC,QAAM,iBAAa,2BAAY;AAC/B,QAAM,UAAM,sCAAe;AAC3B,QAAM,SAAS;AAGf,QAAM,CAAC,GAAG,GA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AA,MACA;AAAA,QACC,MAAM;AAAA,QACN,WAAW;AACV,mBAAS,cAAc,iBAAiB;AAAA,QACzC;AAAA,MACD;AAAA,IACD,EAAE,OAAO,OAAO;AAAA,EAKjB,GAAG,CAAC,YAAY,YAAY,eAAe,CAAC;AAE5C,SAAO,QAAQ,IAAI,CAAC,EAAE,MAAM,OAAO,SAAS,MAAM;AACjD,UAAM,WAAW,WAAW,SAAS,MAAM,KAAK;AAChD,WACC;AAAA,MAAC;AAAA;AAAA,QAEA,OAAO,IAAI,kBAAkB,IAAI,EAAE;AAAA,QACnC,eAAa,aAAa,IAAI;AAAA,QAC9B,MAAK;AAAA,QACL;AAAA,QACA,eAAe;AAAA,QACf,SAAS;AAAA,QACT,MAAK;AAAA,QACL,gBAAc;AAAA,QAEd,sDAAC,gDAAmB,OAAK,MAAC,MAAM,MAAM;AAAA;AAAA,MAVjC;AAAA,IAWN;AAAA,EAEF,CAAC;AACF;",
4
+ "sourcesContent": ["import { isAccelKey, preventDefault, TiptapEditor } from '@tldraw/editor'\nimport { useEffect, useMemo, useState } from 'react'\nimport { useUiEvents } from '../../context/events'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon'\nimport { TldrawUiToolbarButton } from '../primitives/TldrawUiToolbar'\n\n/** @public */\nexport interface DefaultRichTextToolbarContentProps {\n\tonEditLinkStart?(): void\n\ttextEditor: TiptapEditor\n}\n\n/**\n * Rich text toolbar items that have the basics.\n *\n * @public @react\n */\nexport function DefaultRichTextToolbarContent({\n\ttextEditor,\n\tonEditLinkStart,\n}: DefaultRichTextToolbarContentProps) {\n\tconst trackEvent = useUiEvents()\n\tconst msg = useTranslation()\n\tconst source = 'rich-text-menu'\n\n\t// We need to force this one to update when the editor updates or when selection changes\n\tconst [_, set] = useState(0)\n\tuseEffect(\n\t\tfunction forceUpdateWhenContentChanges() {\n\t\t\tfunction forceUpdate() {\n\t\t\t\tset((t) => t + 1)\n\t\t\t}\n\t\t\ttextEditor.on('update', forceUpdate)\n\t\t\ttextEditor.on('selectionUpdate', forceUpdate)\n\t\t},\n\t\t[textEditor]\n\t)\n\n\tuseEffect(() => {\n\t\tfunction handleKeyDown(event: KeyboardEvent) {\n\t\t\tif (onEditLinkStart && isAccelKey(event) && event.shiftKey && event.key === 'k') {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tonEditLinkStart()\n\t\t\t}\n\t\t}\n\n\t\tdocument.addEventListener('keydown', handleKeyDown)\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('keydown', handleKeyDown)\n\t\t}\n\t}, [onEditLinkStart])\n\n\t// todo: we could make this a prop\n\tconst actions = useMemo(() => {\n\t\tfunction handleOp(name: string, op: string) {\n\t\t\t// Check if the editor view is available before calling operations\n\t\t\tif (!textEditor.view) return\n\n\t\t\ttrackEvent('rich-text', { operation: name as any, source })\n\t\t\t// @ts-expect-error typing this is annoying at the moment.\n\t\t\ttextEditor.chain().focus()[op]().run()\n\t\t}\n\n\t\treturn [\n\t\t\t// { name: 'heading', attrs: { level: 3 }, onSelect() { textEditor.chain().focus().toggleHeading({ level: 3}).run() }},\n\t\t\t{\n\t\t\t\tname: 'bold',\n\t\t\t\tonSelect() {\n\t\t\t\t\thandleOp('bold', 'toggleBold')\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'italic',\n\t\t\t\tonSelect() {\n\t\t\t\t\thandleOp('bold', 'toggleItalic')\n\t\t\t\t},\n\t\t\t},\n\t\t\t// { name: 'underline', onSelect() { handleOp('underline', 'toggleUnderline') }},\n\t\t\t// { name: 'strike', onSelect() { handleOp('strike', 'toggleStrike') }},\n\t\t\t{\n\t\t\t\tname: 'code',\n\t\t\t\tonSelect() {\n\t\t\t\t\thandleOp('bold', 'toggleCode')\n\t\t\t\t},\n\t\t\t},\n\t\t\tonEditLinkStart\n\t\t\t\t? {\n\t\t\t\t\t\tname: 'link',\n\t\t\t\t\t\tonSelect() {\n\t\t\t\t\t\t\tonEditLinkStart()\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: undefined, // ? is this really optional?\n\t\t\t{\n\t\t\t\tname: 'bulletList',\n\t\t\t\tonSelect() {\n\t\t\t\t\thandleOp('bulletList', 'toggleBulletList')\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'highlight',\n\t\t\t\tonSelect() {\n\t\t\t\t\thandleOp('bulletList', 'toggleHighlight')\n\t\t\t\t},\n\t\t\t},\n\t\t].filter(Boolean) as {\n\t\t\tname: string\n\t\t\tattrs?: string\n\t\t\tonSelect(): void\n\t\t}[]\n\t}, [textEditor, trackEvent, onEditLinkStart])\n\n\treturn actions.map(({ name, attrs, onSelect }) => {\n\t\tconst isActive = textEditor.view ? textEditor.isActive(name, attrs) : false\n\t\treturn (\n\t\t\t<TldrawUiToolbarButton\n\t\t\t\tkey={name}\n\t\t\t\ttitle={msg(`tool.rich-text-${name}`)}\n\t\t\t\tdata-testid={`rich-text.${name}`}\n\t\t\t\ttype=\"icon\"\n\t\t\t\tisActive={isActive} // todo: we need to update this only when the text editor \"settles\", ie not during a change of selection\n\t\t\t\tonPointerDown={preventDefault}\n\t\t\t\tonClick={onSelect}\n\t\t\t\trole=\"option\"\n\t\t\t\taria-pressed={isActive}\n\t\t\t>\n\t\t\t\t<TldrawUiButtonIcon small icon={name} />\n\t\t\t</TldrawUiToolbarButton>\n\t\t)\n\t})\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+HI;AA/HJ,oBAAyD;AACzD,mBAA6C;AAC7C,oBAA4B;AAC5B,4BAA+B;AAC/B,gCAAmC;AACnC,6BAAsC;AAa/B,SAAS,8BAA8B;AAAA,EAC7C;AAAA,EACA;AACD,GAAuC;AACtC,QAAM,iBAAa,2BAAY;AAC/B,QAAM,UAAM,sCAAe;AAC3B,QAAM,SAAS;AAGf,QAAM,CAAC,GAAG,GAAG,Q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AAAA,QAC1C;AAAA,MACD;AAAA,MACA;AAAA,QACC,MAAM;AAAA,QACN,WAAW;AACV,mBAAS,cAAc,iBAAiB;AAAA,QACzC;AAAA,MACD;AAAA,IACD,EAAE,OAAO,OAAO;AAAA,EAKjB,GAAG,CAAC,YAAY,YAAY,eAAe,CAAC;AAE5C,SAAO,QAAQ,IAAI,CAAC,EAAE,MAAM,OAAO,SAAS,MAAM;AACjD,UAAM,WAAW,WAAW,OAAO,WAAW,SAAS,MAAM,KAAK,IAAI;AACtE,WACC;AAAA,MAAC;AAAA;AAAA,QAEA,OAAO,IAAI,kBAAkB,IAAI,EAAE;AAAA,QACnC,eAAa,aAAa,IAAI;AAAA,QAC9B,MAAK;AAAA,QACL;AAAA,QACA,eAAe;AAAA,QACf,SAAS;AAAA,QACT,MAAK;AAAA,QACL,gBAAc;AAAA,QAEd,sDAAC,gDAAmB,OAAK,MAAC,MAAM,MAAM;AAAA;AAAA,MAVjC;AAAA,IAWN;AAAA,EAEF,CAAC;AACF;",
6
6
  "names": []
7
7
  }
@@ -43,7 +43,7 @@ function LinkEditor({ textEditor, value: initialValue, onClose }) {
43
43
  if (!link.startsWith("http://") && !link.startsWith("https://")) {
44
44
  link = `https://${link}`;
45
45
  }
46
- textEditor.commands.setLink({ href: link });
46
+ textEditor.chain().setLink({ href: link }).run();
47
47
  if (editor.getInstanceState().isCoarsePointer) {
48
48
  textEditor.commands.blur();
49
49
  } else {
@@ -53,7 +53,7 @@ function LinkEditor({ textEditor, value: initialValue, onClose }) {
53
53
  };
54
54
  const handleVisitLink = () => {
55
55
  trackEvent("rich-text", { operation: "link-visit", source });
56
- window.open(linkifiedValue, "_blank", "noopener, noreferrer");
56
+ (0, import_editor.openWindow)(linkifiedValue, "_blank");
57
57
  onClose();
58
58
  };
59
59
  const handleRemoveLink = () => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/ui/components/Toolbar/LinkEditor.tsx"],
4
- "sourcesContent": ["import { preventDefault, TiptapEditor, useEditor } from '@tldraw/editor'\nimport { useEffect, useRef, useState } from 'react'\nimport { useUiEvents } from '../../context/events'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { TldrawUiButton } from '../primitives/Button/TldrawUiButton'\nimport { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon'\nimport { TldrawUiInput } from '../primitives/TldrawUiInput'\n\n/** @public */\nexport interface LinkEditorProps {\n\ttextEditor: TiptapEditor\n\tvalue: string\n\tonClose(): void\n}\n\n/** @public @react */\nexport function LinkEditor({ textEditor, value: initialValue, onClose }: LinkEditorProps) {\n\tconst editor = useEditor()\n\tconst [value, setValue] = useState(initialValue)\n\tconst msg = useTranslation()\n\tconst ref = useRef<HTMLInputElement>(null)\n\tconst trackEvent = useUiEvents()\n\tconst source = 'rich-text-menu'\n\tconst linkifiedValue = value.startsWith('http') ? value : `https://${value}`\n\n\tconst handleValueChange = (value: string) => setValue(value)\n\n\tconst handleLinkComplete = (link: string) => {\n\t\ttrackEvent('rich-text', { operation: 'link-edit', source })\n\t\tif (!link.startsWith('http://') && !link.startsWith('https://')) {\n\t\t\tlink = `https://${link}`\n\t\t}\n\n\t\ttextEditor.commands.setLink({ href: link })\n\t\t// N.B. We shouldn't focus() on mobile because it causes the\n\t\t// Return key to replace the link with a newline :facepalm:\n\t\tif (editor.getInstanceState().isCoarsePointer) {\n\t\t\ttextEditor.commands.blur()\n\t\t} else {\n\t\t\ttextEditor.commands.focus()\n\t\t}\n\t\tonClose()\n\t}\n\n\tconst handleVisitLink = () => {\n\t\ttrackEvent('rich-text', { operation: 'link-visit', source })\n\t\twindow.open(linkifiedValue, '_blank', 'noopener, noreferrer')\n\t\tonClose()\n\t}\n\n\tconst handleRemoveLink = () => {\n\t\ttrackEvent('rich-text', { operation: 'link-remove', source })\n\t\ttextEditor.chain().unsetLink().focus().run()\n\t\tonClose()\n\t}\n\n\tconst handleLinkCancel = () => onClose()\n\n\tuseEffect(() => {\n\t\tref.current?.focus()\n\t}, [value])\n\n\tuseEffect(() => {\n\t\tsetValue(initialValue)\n\t}, [initialValue])\n\n\treturn (\n\t\t<>\n\t\t\t<TldrawUiInput\n\t\t\t\tref={ref}\n\t\t\t\tdata-testid=\"rich-text.link-input\"\n\t\t\t\tclassName=\"tlui-rich-text__toolbar-link-input\"\n\t\t\t\tvalue={value}\n\t\t\t\tonValueChange={handleValueChange}\n\t\t\t\tonComplete={handleLinkComplete}\n\t\t\t\tonCancel={handleLinkCancel}\n\t\t\t\tplaceholder=\"example.com\"\n\t\t\t\taria-label=\"example.com\"\n\t\t\t/>\n\t\t\t<TldrawUiButton\n\t\t\t\tclassName=\"tlui-rich-text__toolbar-link-visit\"\n\t\t\t\ttitle={msg('tool.rich-text-link-visit')}\n\t\t\t\ttype=\"icon\"\n\t\t\t\tonPointerDown={preventDefault}\n\t\t\t\tonClick={handleVisitLink}\n\t\t\t\tdisabled={!value}\n\t\t\t>\n\t\t\t\t<TldrawUiButtonIcon small icon=\"external-link\" />\n\t\t\t</TldrawUiButton>\n\t\t\t<TldrawUiButton\n\t\t\t\tclassName=\"tlui-rich-text__toolbar-link-remove\"\n\t\t\t\ttitle={msg('tool.rich-text-link-remove')}\n\t\t\t\tdata-testid=\"rich-text.link-remove\"\n\t\t\t\ttype=\"icon\"\n\t\t\t\tonPointerDown={preventDefault}\n\t\t\t\tonClick={handleRemoveLink}\n\t\t\t>\n\t\t\t\t<TldrawUiButtonIcon small icon=\"trash\" />\n\t\t\t</TldrawUiButton>\n\t\t</>\n\t)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmEE;AAnEF,oBAAwD;AACxD,mBAA4C;AAC5C,oBAA4B;AAC5B,4BAA+B;AAC/B,4BAA+B;AAC/B,gCAAmC;AACnC,2BAA8B;AAUvB,SAAS,WAAW,EAAE,YAAY,OAAO,cAAc,QAAQ,GAAoB;AACzF,QAAM,aAAS,yBAA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AAAA,QACV;AAAA,QACA,eAAe;AAAA,QACf,YAAY;AAAA,QACZ,UAAU;AAAA,QACV,aAAY;AAAA,QACZ,cAAW;AAAA;AAAA,IACZ;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,OAAO,IAAI,2BAA2B;AAAA,QACtC,MAAK;AAAA,QACL,eAAe;AAAA,QACf,SAAS;AAAA,QACT,UAAU,CAAC;AAAA,QAEX,sDAAC,gDAAmB,OAAK,MAAC,MAAK,iBAAgB;AAAA;AAAA,IAChD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,OAAO,IAAI,4BAA4B;AAAA,QACvC,eAAY;AAAA,QACZ,MAAK;AAAA,QACL,eAAe;AAAA,QACf,SAAS;AAAA,QAET,sDAAC,gDAAmB,OAAK,MAAC,MAAK,SAAQ;AAAA;AAAA,IACxC;AAAA,KACD;AAEF;",
4
+ "sourcesContent": ["import { openWindow, preventDefault, TiptapEditor, useEditor } from '@tldraw/editor'\nimport { useEffect, useRef, useState } from 'react'\nimport { useUiEvents } from '../../context/events'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { TldrawUiButton } from '../primitives/Button/TldrawUiButton'\nimport { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon'\nimport { TldrawUiInput } from '../primitives/TldrawUiInput'\n\n/** @public */\nexport interface LinkEditorProps {\n\ttextEditor: TiptapEditor\n\tvalue: string\n\tonClose(): void\n}\n\n/** @public @react */\nexport function LinkEditor({ textEditor, value: initialValue, onClose }: LinkEditorProps) {\n\tconst editor = useEditor()\n\tconst [value, setValue] = useState(initialValue)\n\tconst msg = useTranslation()\n\tconst ref = useRef<HTMLInputElement>(null)\n\tconst trackEvent = useUiEvents()\n\tconst source = 'rich-text-menu'\n\tconst linkifiedValue = value.startsWith('http') ? value : `https://${value}`\n\n\tconst handleValueChange = (value: string) => setValue(value)\n\n\tconst handleLinkComplete = (link: string) => {\n\t\ttrackEvent('rich-text', { operation: 'link-edit', source })\n\t\tif (!link.startsWith('http://') && !link.startsWith('https://')) {\n\t\t\tlink = `https://${link}`\n\t\t}\n\n\t\ttextEditor.chain().setLink({ href: link }).run()\n\t\t// N.B. We shouldn't focus() on mobile because it causes the\n\t\t// Return key to replace the link with a newline :facepalm:\n\t\tif (editor.getInstanceState().isCoarsePointer) {\n\t\t\ttextEditor.commands.blur()\n\t\t} else {\n\t\t\ttextEditor.commands.focus()\n\t\t}\n\t\tonClose()\n\t}\n\n\tconst handleVisitLink = () => {\n\t\ttrackEvent('rich-text', { operation: 'link-visit', source })\n\t\topenWindow(linkifiedValue, '_blank')\n\t\tonClose()\n\t}\n\n\tconst handleRemoveLink = () => {\n\t\ttrackEvent('rich-text', { operation: 'link-remove', source })\n\t\ttextEditor.chain().unsetLink().focus().run()\n\t\tonClose()\n\t}\n\n\tconst handleLinkCancel = () => onClose()\n\n\tuseEffect(() => {\n\t\tref.current?.focus()\n\t}, [value])\n\n\tuseEffect(() => {\n\t\tsetValue(initialValue)\n\t}, [initialValue])\n\n\treturn (\n\t\t<>\n\t\t\t<TldrawUiInput\n\t\t\t\tref={ref}\n\t\t\t\tdata-testid=\"rich-text.link-input\"\n\t\t\t\tclassName=\"tlui-rich-text__toolbar-link-input\"\n\t\t\t\tvalue={value}\n\t\t\t\tonValueChange={handleValueChange}\n\t\t\t\tonComplete={handleLinkComplete}\n\t\t\t\tonCancel={handleLinkCancel}\n\t\t\t\tplaceholder=\"example.com\"\n\t\t\t\taria-label=\"example.com\"\n\t\t\t/>\n\t\t\t<TldrawUiButton\n\t\t\t\tclassName=\"tlui-rich-text__toolbar-link-visit\"\n\t\t\t\ttitle={msg('tool.rich-text-link-visit')}\n\t\t\t\ttype=\"icon\"\n\t\t\t\tonPointerDown={preventDefault}\n\t\t\t\tonClick={handleVisitLink}\n\t\t\t\tdisabled={!value}\n\t\t\t>\n\t\t\t\t<TldrawUiButtonIcon small icon=\"external-link\" />\n\t\t\t</TldrawUiButton>\n\t\t\t<TldrawUiButton\n\t\t\t\tclassName=\"tlui-rich-text__toolbar-link-remove\"\n\t\t\t\ttitle={msg('tool.rich-text-link-remove')}\n\t\t\t\tdata-testid=\"rich-text.link-remove\"\n\t\t\t\ttype=\"icon\"\n\t\t\t\tonPointerDown={preventDefault}\n\t\t\t\tonClick={handleRemoveLink}\n\t\t\t>\n\t\t\t\t<TldrawUiButtonIcon small icon=\"trash\" />\n\t\t\t</TldrawUiButton>\n\t\t</>\n\t)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmEE;AAnEF,oBAAoE;AACpE,mBAA4C;AAC5C,oBAA4B;AAC5B,4BAA+B;AAC/B,4BAA+B;AAC/B,gCAAmC;AACnC,2BAA8B;AAUvB,SAAS,WAAW,EAAE,YAAY,OAAO,cAAc,QAAQ,GAAoB;AACzF,QAAM,aAAS,yBAAU;AACzB,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAS,YAAY;AAC/C,QAAM,UAAM,sCAAe;AAC3B,QAAM,UAAM,qBAAyB,IAAI;AACzC,QAAM,iBAAa,2BAAY;AAC/B,QAAM,SAAS;AACf,QAAM,iBAAiB,MAAM,WAAW,MAAM,IAAI,QAAQ,WAAW,KAAK;AAE1E,QAAM,oBAAoB,CAACA,WAAkB,SAASA,MAAK;AAE3D,QAAM,qBAAqB,CAAC,SAAiB;AAC5C,eAAW,aAAa,EAAE,WAAW,aAAa,OAAO,CAAC;AAC1D,QAAI,CAAC,KAAK,WAAW,SAAS,KAAK,CAAC,KAAK,WAAW,UAAU,GAAG;AAChE,aAAO,WAAW,IAAI;AAAA,IACvB;AAEA,eAAW,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC,EAAE,IAAI;AAG/C,QAAI,OAAO,iBAAiB,EAAE,iBAAiB;AAC9C,iBAAW,SAAS,KAAK;AAAA,IAC1B,OAAO;AACN,iBAAW,SAAS,MAAM;AAAA,IAC3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  "sources": ["../../../../src/lib/ui/context/events.tsx"],
4
- "sourcesContent": ["import * as React from 'react'\n\n/** @public */\nexport type TLUiEventSource =\n\t| 'menu'\n\t| 'main-menu'\n\t| 'context-menu'\n\t| 'zoom-menu'\n\t| 'document-name'\n\t| 'navigation-zone'\n\t| 'quick-actions'\n\t| 'actions-menu'\n\t| 'kbd'\n\t| 'debug-panel'\n\t| 'page-menu'\n\t| 'share-menu'\n\t| 'export-menu'\n\t| 'toolbar'\n\t| 'people-menu'\n\t| 'dialog'\n\t| 'help-menu'\n\t| 'helper-buttons'\n\t| 'style-panel'\n\t| 'rich-text-menu'\n\t| 'image-toolbar'\n\t| 'video-toolbar'\n\t| 'unknown'\n\n/** @public */\nexport interface TLUiEventMap {\n\t// Actions\n\tundo: null\n\tredo: null\n\t'change-language': { locale: string }\n\t'change-page': { direction?: 'prev' | 'next' }\n\t'select-adjacent-shape': { direction: 'prev' | 'next' | 'left' | 'right' | 'up' | 'down' }\n\t'delete-page': null\n\t'duplicate-page': null\n\t'move-page': null\n\t'new-page': null\n\t'rename-page': null\n\t'move-to-page': null\n\t'move-to-new-page': null\n\t'rename-document': null\n\t'group-shapes': null\n\t'ungroup-shapes': null\n\t'remove-frame': null\n\t'fit-frame-to-content': null\n\t'convert-to-embed': null\n\t'convert-to-bookmark': null\n\t'open-embed-link': null\n\t'toggle-auto-size': null\n\t'copy-as': { format: 'svg' | 'png' | 'json' }\n\t'export-as': { format: 'svg' | 'png' | 'json' }\n\t'export-all-as': { format: 'svg' | 'png' | 'json' }\n\t'download-original': null\n\t'edit-link': null\n\t'insert-embed': null\n\t'insert-media': null\n\t'replace-media': null\n\t'image-manipulate': null\n\t'alt-text-start': null\n\t'set-alt-text': null\n\t'align-shapes': {\n\t\toperation: 'left' | 'center-horizontal' | 'right' | 'top' | 'center-vertical' | 'bottom'\n\t}\n\t'duplicate-shapes': null\n\t'pack-shapes': null\n\t'stack-shapes': { operation: 'horizontal' | 'vertical' }\n\t'flip-shapes': { operation: 'horizontal' | 'vertical' }\n\t'distribute-shapes': { operation: 'horizontal' | 'vertical' }\n\t'stretch-shapes': { operation: 'horizontal' | 'vertical' }\n\t'reorder-shapes': {\n\t\toperation: 'toBack' | 'toFront' | 'forward' | 'backward'\n\t}\n\t'delete-shapes': null\n\t'select-all-shapes': null\n\t'select-none-shapes': null\n\t'rotate-ccw': { fine: boolean }\n\t'rotate-cw': { fine: boolean }\n\t'zoom-in': { towardsCursor: boolean }\n\t'zoom-out': { towardsCursor: boolean }\n\t'zoom-to-fit': null\n\t'zoom-to-selection': null\n\t'reset-zoom': null\n\t'zoom-into-view': null\n\t'zoom-to-content': null\n\t'open-menu': { id: string }\n\t'close-menu': { id: string }\n\t'create-new-project': null\n\t'save-project-to-file': null\n\t'open-file': null\n\t'select-tool': { id: string }\n\tprint: null\n\tcopy: null\n\tpaste: null\n\tcut: null\n\t'set-style': { id: string; value: string | number }\n\t'toggle-transparent': null\n\t'toggle-snap-mode': null\n\t'toggle-tool-lock': null\n\t'toggle-grid-mode': null\n\t'toggle-wrap-mode': null\n\t'toggle-focus-mode': null\n\t'input-mode': { value: string }\n\t'toggle-debug-mode': null\n\t'toggle-dynamic-size-mode': null\n\t'toggle-paste-at-cursor': null\n\t'toggle-lock': null\n\t'toggle-reduce-motion': null\n\t'toggle-keyboard-shortcuts': null\n\t'enhanced-a11y-mode': null\n\t'toggle-edge-scrolling': null\n\t'color-scheme': { value: string }\n\t'exit-pen-mode': null\n\t'start-following': null\n\t'stop-following': null\n\t'set-color': null\n\t'change-user-name': null\n\t'open-cursor-chat': null\n\t'zoom-tool': null\n\t'unlock-all': null\n\t'enlarge-shapes': null\n\t'shrink-shapes': null\n\t'flatten-to-image': null\n\t'a11y-repeat-shape-announce': null\n\t'open-url': { destinationUrl: string }\n\t'open-context-menu': null\n\t'adjust-shape-styles': null\n\t'copy-link': null\n\t'drag-tool': { id: string }\n\t'image-replace': null\n\t'video-replace': null\n\t'open-kbd-shortcuts': null\n\t'rich-text': {\n\t\toperation:\n\t\t\t| 'bold'\n\t\t\t| 'strike'\n\t\t\t| 'link'\n\t\t\t| 'link-edit'\n\t\t\t| 'link-visit'\n\t\t\t| 'link-remove'\n\t\t\t| 'heading'\n\t\t\t| 'bulletList'\n\t}\n\tedit: null\n}\n\n/** @public */\nexport type TLUiEventData<K> = K extends null\n\t? { source: TLUiEventSource }\n\t: { source: TLUiEventSource } & K\n\n/** @public */\nexport type TLUiEventHandler = <T extends keyof TLUiEventMap>(\n\tname: T,\n\tdata: TLUiEventData<TLUiEventMap[T]>\n) => void\n\n/** @public */\nexport type TLUiEventContextType = TLUiEventHandler\n\n/** @internal */\nconst defaultEventHandler: TLUiEventContextType = () => void null\n\n/** @internal */\nexport const EventsContext = React.createContext<TLUiEventContextType | null>(null)\n\n/** @public */\nexport interface EventsProviderProps {\n\tonEvent?: TLUiEventHandler\n\tchildren: React.ReactNode\n}\n\n/** @public @react */\nexport function TldrawUiEventsProvider({ onEvent, children }: EventsProviderProps) {\n\treturn (\n\t\t<EventsContext.Provider value={onEvent ?? defaultEventHandler}>\n\t\t\t{children}\n\t\t</EventsContext.Provider>\n\t)\n}\n\n/** @public */\nexport function useUiEvents(): TLUiEventContextType {\n\tconst eventHandler = React.useContext(EventsContext)\n\treturn eventHandler ?? defaultEventHandler\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiLE;AAjLF,YAAuB;AAmKvB,MAAM,sBAA4C,MAAM;AAGjD,MAAM,gBAAgB,MAAM,cAA2C,IAAI;AAS3E,SAAS,uBAAuB,EAAE,SAAS,SAAS,GAAwB;AAClF,SACC,4CAAC,cAAc,UAAd,EAAuB,OAAO,WAAW,qBACxC,UACF;AAEF;AAGO,SAAS,cAAoC;AACnD,QAAM,eAAe,MAAM,WAAW,aAAa;AACnD,SAAO,gBAAgB;AACxB;",
4
+ "sourcesContent": ["import * as React from 'react'\n\n/** @public */\nexport type TLUiEventSource =\n\t| 'menu'\n\t| 'main-menu'\n\t| 'context-menu'\n\t| 'zoom-menu'\n\t| 'document-name'\n\t| 'navigation-zone'\n\t| 'quick-actions'\n\t| 'actions-menu'\n\t| 'kbd'\n\t| 'debug-panel'\n\t| 'page-menu'\n\t| 'share-menu'\n\t| 'export-menu'\n\t| 'toolbar'\n\t| 'people-menu'\n\t| 'dialog'\n\t| 'help-menu'\n\t| 'helper-buttons'\n\t| 'style-panel'\n\t| 'rich-text-menu'\n\t| 'image-toolbar'\n\t| 'video-toolbar'\n\t| 'fairy-panel'\n\t| 'unknown'\n\n/** @public */\nexport interface TLUiEventMap {\n\t// Actions\n\tundo: null\n\tredo: null\n\t'change-language': { locale: string }\n\t'change-page': { direction?: 'prev' | 'next' }\n\t'select-adjacent-shape': { direction: 'prev' | 'next' | 'left' | 'right' | 'up' | 'down' }\n\t'delete-page': null\n\t'duplicate-page': null\n\t'move-page': null\n\t'new-page': null\n\t'rename-page': null\n\t'move-to-page': null\n\t'move-to-new-page': null\n\t'rename-document': null\n\t'group-shapes': null\n\t'ungroup-shapes': null\n\t'remove-frame': null\n\t'fit-frame-to-content': null\n\t'convert-to-embed': null\n\t'convert-to-bookmark': null\n\t'open-embed-link': null\n\t'toggle-auto-size': null\n\t'copy-as': { format: 'svg' | 'png' | 'json' }\n\t'export-as': { format: 'svg' | 'png' | 'json' }\n\t'export-all-as': { format: 'svg' | 'png' | 'json' }\n\t'download-original': null\n\t'edit-link': null\n\t'insert-embed': null\n\t'insert-media': null\n\t'replace-media': null\n\t'image-manipulate': null\n\t'alt-text-start': null\n\t'set-alt-text': null\n\t'align-shapes': {\n\t\toperation: 'left' | 'center-horizontal' | 'right' | 'top' | 'center-vertical' | 'bottom'\n\t}\n\t'duplicate-shapes': null\n\t'pack-shapes': null\n\t'stack-shapes': { operation: 'horizontal' | 'vertical' }\n\t'flip-shapes': { operation: 'horizontal' | 'vertical' }\n\t'distribute-shapes': { operation: 'horizontal' | 'vertical' }\n\t'stretch-shapes': { operation: 'horizontal' | 'vertical' }\n\t'reorder-shapes': {\n\t\toperation: 'toBack' | 'toFront' | 'forward' | 'backward'\n\t}\n\t'delete-shapes': null\n\t'select-all-shapes': null\n\t'select-none-shapes': null\n\t'rotate-ccw': { fine: boolean }\n\t'rotate-cw': { fine: boolean }\n\t'zoom-in': { towardsCursor: boolean }\n\t'zoom-out': { towardsCursor: boolean }\n\t'zoom-to-fit': null\n\t'zoom-to-selection': null\n\t'reset-zoom': null\n\t'zoom-into-view': null\n\t'zoom-to-content': null\n\t'open-menu': { id: string }\n\t'close-menu': { id: string }\n\t'create-new-project': null\n\t'save-project-to-file': null\n\t'open-file': null\n\t'select-tool': { id: string }\n\tprint: null\n\tcopy: null\n\tpaste: null\n\tcut: null\n\t'set-style': { id: string; value: string | number }\n\t'toggle-transparent': null\n\t'toggle-snap-mode': null\n\t'toggle-tool-lock': null\n\t'toggle-grid-mode': null\n\t'toggle-wrap-mode': null\n\t'toggle-focus-mode': null\n\t'input-mode': { value: string }\n\t'toggle-debug-mode': null\n\t'toggle-dynamic-size-mode': null\n\t'toggle-paste-at-cursor': null\n\t'toggle-lock': null\n\t'toggle-reduce-motion': null\n\t'toggle-keyboard-shortcuts': null\n\t'enhanced-a11y-mode': null\n\t'toggle-edge-scrolling': null\n\t'color-scheme': { value: string }\n\t'exit-pen-mode': null\n\t'start-following': null\n\t'stop-following': null\n\t'set-color': null\n\t'change-user-name': null\n\t'open-cursor-chat': null\n\t'zoom-tool': null\n\t'unlock-all': null\n\t'enlarge-shapes': null\n\t'shrink-shapes': null\n\t'flatten-to-image': null\n\t'a11y-repeat-shape-announce': null\n\t'open-url': { destinationUrl: string }\n\t'open-context-menu': null\n\t'adjust-shape-styles': null\n\t'copy-link': null\n\t'drag-tool': { id: string }\n\t'image-replace': null\n\t'video-replace': null\n\t'open-kbd-shortcuts': null\n\t'rich-text': {\n\t\toperation:\n\t\t\t| 'bold'\n\t\t\t| 'strike'\n\t\t\t| 'link'\n\t\t\t| 'link-edit'\n\t\t\t| 'link-visit'\n\t\t\t| 'link-remove'\n\t\t\t| 'heading'\n\t\t\t| 'bulletList'\n\t}\n\tedit: null\n}\n\n/** @public */\nexport type TLUiEventData<K> = K extends null\n\t? { source: TLUiEventSource }\n\t: { source: TLUiEventSource } & K\n\n/** @public */\nexport type TLUiEventHandler = <T extends keyof TLUiEventMap>(\n\tname: T,\n\tdata: TLUiEventData<TLUiEventMap[T]>\n) => void\n\n/** @public */\nexport type TLUiEventContextType = TLUiEventHandler\n\n/** @internal */\nconst defaultEventHandler: TLUiEventContextType = () => void null\n\n/** @internal */\nexport const EventsContext = React.createContext<TLUiEventContextType | null>(null)\n\n/** @public */\nexport interface EventsProviderProps {\n\tonEvent?: TLUiEventHandler\n\tchildren: React.ReactNode\n}\n\n/** @public @react */\nexport function TldrawUiEventsProvider({ onEvent, children }: EventsProviderProps) {\n\treturn (\n\t\t<EventsContext.Provider value={onEvent ?? defaultEventHandler}>\n\t\t\t{children}\n\t\t</EventsContext.Provider>\n\t)\n}\n\n/** @public */\nexport function useUiEvents(): TLUiEventContextType {\n\tconst eventHandler = React.useContext(EventsContext)\n\treturn eventHandler ?? defaultEventHandler\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkLE;AAlLF,YAAuB;AAoKvB,MAAM,sBAA4C,MAAM;AAGjD,MAAM,gBAAgB,MAAM,cAA2C,IAAI;AAS3E,SAAS,uBAAuB,EAAE,SAAS,SAAS,GAAwB;AAClF,SACC,4CAAC,cAAc,UAAd,EAAuB,OAAO,WAAW,qBACxC,UACF;AAEF;AAGO,SAAS,cAAoC;AACnD,QAAM,eAAe,MAAM,WAAW,aAAa;AACnD,SAAO,gBAAgB;AACxB;",
6
6
  "names": []
7
7
  }
@@ -28,15 +28,30 @@ function getLocalFiles(options) {
28
28
  input.type = "file";
29
29
  input.accept = mimeTypes?.join(",");
30
30
  input.multiple = allowMultiple;
31
+ input.style.display = "none";
32
+ function dispose() {
33
+ input.removeEventListener("change", onchange);
34
+ input.removeEventListener("cancel", oncancel);
35
+ input.remove();
36
+ }
31
37
  async function onchange(e) {
32
38
  const fileList = e.target.files;
33
- if (!fileList || fileList.length === 0) return;
39
+ if (!fileList || fileList.length === 0) {
40
+ resolve([]);
41
+ dispose();
42
+ return;
43
+ }
34
44
  const files = Array.from(fileList);
35
45
  input.value = "";
36
46
  resolve(files);
37
- input.removeEventListener("change", onchange);
38
- input.remove();
47
+ dispose();
48
+ }
49
+ function oncancel() {
50
+ resolve([]);
51
+ dispose();
39
52
  }
53
+ document.body.appendChild(input);
54
+ input.addEventListener("cancel", oncancel);
40
55
  input.addEventListener("change", onchange);
41
56
  input?.click();
42
57
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/ui/getLocalFiles.ts"],
4
- "sourcesContent": ["export function getLocalFiles(options?: {\n\tallowMultiple?: boolean\n\tmimeTypes?: string[] | readonly string[]\n}) {\n\treturn new Promise<File[]>((resolve) => {\n\t\tconst { allowMultiple = true, mimeTypes = [] } = options || {}\n\n\t\tconst input = document.createElement('input')\n\t\tinput.type = 'file'\n\t\tinput.accept = mimeTypes?.join(',')\n\t\tinput.multiple = allowMultiple\n\n\t\tasync function onchange(e: Event) {\n\t\t\tconst fileList = (e.target as HTMLInputElement).files\n\t\t\tif (!fileList || fileList.length === 0) return\n\t\t\tconst files = Array.from(fileList)\n\t\t\tinput.value = ''\n\t\t\tresolve(files)\n\t\t\tinput.removeEventListener('change', onchange)\n\t\t\tinput.remove()\n\t\t}\n\n\t\tinput.addEventListener('change', onchange)\n\t\tinput?.click()\n\t})\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,cAAc,SAG3B;AACF,SAAO,IAAI,QAAgB,CAAC,YAAY;AACvC,UAAM,EAAE,gBAAgB,MAAM,YAAY,CAAC,EAAE,IAAI,WAAW,CAAC;AAE7D,UAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,UAAM,OAAO;AACb,UAAM,SAAS,WAAW,KAAK,GAAG;AAClC,UAAM,WAAW;AAEjB,mBAAe,SAAS,GAAU;AACjC,YAAM,WAAY,EAAE,OAA4B;AAChD,UAAI,CAAC,YAAY,SAAS,WAAW,EAAG;AACxC,YAAM,QAAQ,MAAM,KAAK,QAAQ;AACjC,YAAM,QAAQ;AACd,cAAQ,KAAK;AACb,YAAM,oBAAoB,UAAU,QAAQ;AAC5C,YAAM,OAAO;AAAA,IACd;AAEA,UAAM,iBAAiB,UAAU,QAAQ;AACzC,WAAO,MAAM;AAAA,EACd,CAAC;AACF;",
4
+ "sourcesContent": ["export function getLocalFiles(options?: {\n\tallowMultiple?: boolean\n\tmimeTypes?: string[] | readonly string[]\n}) {\n\treturn new Promise<File[]>((resolve) => {\n\t\tconst { allowMultiple = true, mimeTypes = [] } = options || {}\n\n\t\tconst input = document.createElement('input')\n\t\tinput.type = 'file'\n\t\tinput.accept = mimeTypes?.join(',')\n\t\tinput.multiple = allowMultiple\n\t\tinput.style.display = 'none'\n\n\t\tfunction dispose() {\n\t\t\tinput.removeEventListener('change', onchange)\n\t\t\tinput.removeEventListener('cancel', oncancel)\n\t\t\tinput.remove()\n\t\t}\n\n\t\tasync function onchange(e: Event) {\n\t\t\tconst fileList = (e.target as HTMLInputElement).files\n\t\t\tif (!fileList || fileList.length === 0) {\n\t\t\t\tresolve([])\n\t\t\t\tdispose()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst files = Array.from(fileList)\n\t\t\tinput.value = ''\n\t\t\tresolve(files)\n\t\t\tdispose()\n\t\t}\n\n\t\tfunction oncancel() {\n\t\t\tresolve([])\n\t\t\tdispose()\n\t\t}\n\n\t\tdocument.body.appendChild(input)\n\t\tinput.addEventListener('cancel', oncancel)\n\t\tinput.addEventListener('change', onchange)\n\t\tinput?.click()\n\t})\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,cAAc,SAG3B;AACF,SAAO,IAAI,QAAgB,CAAC,YAAY;AACvC,UAAM,EAAE,gBAAgB,MAAM,YAAY,CAAC,EAAE,IAAI,WAAW,CAAC;AAE7D,UAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,UAAM,OAAO;AACb,UAAM,SAAS,WAAW,KAAK,GAAG;AAClC,UAAM,WAAW;AACjB,UAAM,MAAM,UAAU;AAEtB,aAAS,UAAU;AAClB,YAAM,oBAAoB,UAAU,QAAQ;AAC5C,YAAM,oBAAoB,UAAU,QAAQ;AAC5C,YAAM,OAAO;AAAA,IACd;AAEA,mBAAe,SAAS,GAAU;AACjC,YAAM,WAAY,EAAE,OAA4B;AAChD,UAAI,CAAC,YAAY,SAAS,WAAW,GAAG;AACvC,gBAAQ,CAAC,CAAC;AACV,gBAAQ;AACR;AAAA,MACD;AACA,YAAM,QAAQ,MAAM,KAAK,QAAQ;AACjC,YAAM,QAAQ;AACd,cAAQ,KAAK;AACb,cAAQ;AAAA,IACT;AAEA,aAAS,WAAW;AACnB,cAAQ,CAAC,CAAC;AACV,cAAQ;AAAA,IACT;AAEA,aAAS,KAAK,YAAY,KAAK;AAC/B,UAAM,iBAAiB,UAAU,QAAQ;AACzC,UAAM,iBAAiB,UAAU,QAAQ;AACzC,WAAO,MAAM;AAAA,EACd,CAAC;AACF;",
6
6
  "names": []
7
7
  }