tldraw 4.3.0-canary.fd6b7f2a8adc → 4.3.0-next.2b3bfbba757b
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.
- package/dist-cjs/index.d.ts +5 -14
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/bindings/arrow/ArrowBindingUtil.js.map +2 -2
- package/dist-cjs/lib/canvas/TldrawSelectionForeground.js.map +2 -2
- package/dist-cjs/lib/defaultExternalContentHandlers.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/arrowLabel.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/arrowTargetState.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/elbow/elbowArrowSnapLines.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/shared.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/bookmark/bookmarks.js.map +2 -2
- package/dist-cjs/lib/shapes/draw/toolStates/Drawing.js.map +2 -2
- package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/frame/FrameShapeTool.js.map +1 -1
- package/dist-cjs/lib/shapes/geo/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/line/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/note/noteHelpers.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/PlainTextLabel.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/RichTextLabel.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/crop.js +0 -1
- package/dist-cjs/lib/shapes/shared/crop.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/useEditablePlainText.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/useEditableRichText.js.map +2 -2
- package/dist-cjs/lib/shapes/text/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js.map +2 -2
- package/dist-cjs/lib/tools/EraserTool/childStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/DragAndDropManager.js +4 -1
- package/dist-cjs/lib/tools/SelectTool/DragAndDropManager.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Brushing.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/Idle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js +1 -1
- package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/EditingShape.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingArrowLabel.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingHandle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingSelection.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/ScribbleBrushing.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
- package/dist-cjs/lib/ui/components/EditLinkDialog.js +1 -11
- package/dist-cjs/lib/ui/components/EditLinkDialog.js.map +2 -2
- package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js.map +2 -2
- package/dist-cjs/lib/ui/components/menu-items.js.map +2 -2
- package/dist-cjs/lib/ui/context/actions.js +2 -1
- package/dist-cjs/lib/ui/context/actions.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/menu-hooks.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useFlatten.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useTools.js.map +2 -2
- package/dist-cjs/lib/ui/version.js +3 -3
- package/dist-cjs/lib/ui/version.js.map +1 -1
- package/dist-cjs/lib/utils/excalidraw/putExcalidrawContent.js +0 -8
- package/dist-cjs/lib/utils/excalidraw/putExcalidrawContent.js.map +2 -2
- package/dist-cjs/lib/utils/export/exportAs.js.map +2 -2
- package/dist-cjs/lib/utils/frames/frames.js.map +2 -2
- package/dist-cjs/lib/utils/tldr/buildFromV1Document.js.map +2 -2
- package/dist-esm/index.d.mts +5 -14
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/bindings/arrow/ArrowBindingUtil.mjs.map +2 -2
- package/dist-esm/lib/canvas/TldrawSelectionForeground.mjs.map +2 -2
- package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/arrowLabel.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/arrowTargetState.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/elbow/elbowArrowSnapLines.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/shared.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/bookmark/bookmarks.mjs.map +2 -2
- package/dist-esm/lib/shapes/draw/toolStates/Drawing.mjs.map +2 -2
- package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/frame/FrameShapeTool.mjs.map +1 -1
- package/dist-esm/lib/shapes/geo/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/line/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/note/noteHelpers.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/RichTextLabel.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/crop.mjs +0 -1
- package/dist-esm/lib/shapes/shared/crop.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/useEditablePlainText.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/useEditableRichText.mjs.map +2 -2
- package/dist-esm/lib/shapes/text/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs.map +2 -2
- package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs +4 -1
- package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/DragAndDropManager.mjs +4 -1
- package/dist-esm/lib/tools/SelectTool/DragAndDropManager.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Brushing.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/Idle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs +1 -1
- package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/EditingShape.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/PointingArrowLabel.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/PointingHandle.mjs +4 -1
- package/dist-esm/lib/tools/SelectTool/childStates/PointingHandle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/PointingSelection.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/ScribbleBrushing.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
- package/dist-esm/lib/ui/components/EditLinkDialog.mjs +1 -11
- package/dist-esm/lib/ui/components/EditLinkDialog.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs.map +2 -2
- package/dist-esm/lib/ui/components/menu-items.mjs +4 -1
- package/dist-esm/lib/ui/components/menu-items.mjs.map +2 -2
- package/dist-esm/lib/ui/context/actions.mjs +2 -1
- package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/menu-hooks.mjs +4 -1
- package/dist-esm/lib/ui/hooks/menu-hooks.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useFlatten.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useTools.mjs.map +2 -2
- package/dist-esm/lib/ui/version.mjs +3 -3
- package/dist-esm/lib/ui/version.mjs.map +1 -1
- package/dist-esm/lib/utils/excalidraw/putExcalidrawContent.mjs +0 -8
- package/dist-esm/lib/utils/excalidraw/putExcalidrawContent.mjs.map +2 -2
- package/dist-esm/lib/utils/export/exportAs.mjs +3 -1
- package/dist-esm/lib/utils/export/exportAs.mjs.map +2 -2
- package/dist-esm/lib/utils/frames/frames.mjs.map +2 -2
- package/dist-esm/lib/utils/tldr/buildFromV1Document.mjs.map +2 -2
- package/package.json +10 -10
- package/src/lib/bindings/arrow/ArrowBindingUtil.ts +1 -1
- package/src/lib/canvas/TldrawSelectionForeground.tsx +9 -4
- package/src/lib/defaultExternalContentHandlers.ts +4 -3
- package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +2 -2
- package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +1 -1
- package/src/lib/shapes/arrow/arrowLabel.ts +1 -1
- package/src/lib/shapes/arrow/arrowTargetState.ts +1 -1
- package/src/lib/shapes/arrow/elbow/elbowArrowSnapLines.tsx +3 -3
- package/src/lib/shapes/arrow/shared.ts +4 -4
- package/src/lib/shapes/arrow/toolStates/Pointing.tsx +1 -1
- package/src/lib/shapes/bookmark/bookmarks.ts +3 -3
- package/src/lib/shapes/draw/toolStates/Drawing.ts +4 -4
- package/src/lib/shapes/embed/EmbedShapeUtil.tsx +1 -1
- package/src/lib/shapes/frame/FrameShapeTool.ts +1 -1
- package/src/lib/shapes/geo/GeoShapeUtil.test.tsx +2 -10
- package/src/lib/shapes/geo/toolStates/Pointing.ts +3 -3
- package/src/lib/shapes/line/LineShapeTool.test.ts +6 -6
- package/src/lib/shapes/line/LineShapeUtil.test.tsx +5 -5
- package/src/lib/shapes/line/toolStates/Pointing.ts +1 -1
- package/src/lib/shapes/note/NoteShapeTool.test.ts +1 -2
- package/src/lib/shapes/note/noteHelpers.ts +2 -2
- package/src/lib/shapes/shared/PlainTextLabel.tsx +1 -2
- package/src/lib/shapes/shared/RichTextLabel.tsx +1 -2
- package/src/lib/shapes/shared/crop.ts +0 -1
- package/src/lib/shapes/shared/useEditablePlainText.ts +3 -7
- package/src/lib/shapes/shared/useEditableRichText.ts +3 -7
- package/src/lib/shapes/text/TextShapeTool.test.ts +4 -4
- package/src/lib/shapes/text/toolStates/Pointing.ts +1 -1
- package/src/lib/tools/EraserTool/childStates/Erasing.ts +5 -3
- package/src/lib/tools/EraserTool/childStates/Pointing.ts +16 -3
- package/src/lib/tools/SelectTool/DragAndDropManager.ts +4 -2
- package/src/lib/tools/SelectTool/childStates/Brushing.ts +6 -2
- package/src/lib/tools/SelectTool/childStates/Crop/children/Idle.ts +3 -2
- package/src/lib/tools/SelectTool/childStates/DraggingHandle.tsx +7 -4
- package/src/lib/tools/SelectTool/childStates/EditingShape.ts +4 -2
- package/src/lib/tools/SelectTool/childStates/Idle.ts +10 -6
- package/src/lib/tools/SelectTool/childStates/PointingArrowLabel.ts +1 -1
- package/src/lib/tools/SelectTool/childStates/PointingHandle.ts +12 -4
- package/src/lib/tools/SelectTool/childStates/PointingSelection.ts +2 -2
- package/src/lib/tools/SelectTool/childStates/Resizing.ts +4 -2
- package/src/lib/tools/SelectTool/childStates/ScribbleBrushing.ts +4 -2
- package/src/lib/tools/SelectTool/childStates/Translating.ts +3 -1
- package/src/lib/ui/components/EditLinkDialog.tsx +6 -16
- package/src/lib/ui/components/Toolbar/AltTextEditor.tsx +2 -2
- package/src/lib/ui/components/menu-items.tsx +14 -6
- package/src/lib/ui/context/actions.tsx +13 -9
- package/src/lib/ui/hooks/menu-hooks.ts +19 -9
- package/src/lib/ui/hooks/useFlatten.ts +2 -1
- package/src/lib/ui/hooks/useTools.tsx +2 -1
- package/src/lib/ui/version.ts +3 -3
- package/src/lib/utils/excalidraw/putExcalidrawContent.ts +0 -8
- package/src/lib/utils/export/exportAs.ts +9 -2
- package/src/lib/utils/frames/frames.ts +1 -1
- package/src/lib/utils/tldr/buildFromV1Document.ts +17 -12
- package/src/test/Editor.test.tsx +12 -38
- package/src/test/SelectTool.test.ts +19 -11
- package/src/test/TestEditor.ts +4 -1
- package/src/test/TldrawEditor.test.tsx +16 -18
- package/src/test/bindings.test.tsx +25 -29
- package/src/test/bindingsIndex.test.tsx +4 -4
- package/src/test/commands/createShapes.test.ts +1 -15
- package/src/test/commands/getSvgString.test.ts +2 -2
- package/src/test/commands/putContent.test.ts +0 -1
- package/src/test/commands/updateShapes.test.ts +5 -21
- package/src/test/custom-clipping.test.ts +35 -36
- package/src/test/customSnapping.test.tsx +62 -77
- package/src/test/duplicate.test.ts +1 -1
- package/src/test/frames.test.ts +2 -2
- package/src/test/getCulledShapes.test.tsx +3 -11
- package/src/test/getShapeAtPoint.test.ts +2 -2
- package/src/test/groups.test.tsx +3 -6
- package/src/test/resizing.test.ts +13 -9
- package/src/test/selection-omnibus.test.ts +11 -11
- package/src/test/shapeutils.test.ts +1 -1
- package/src/test/styles2.test.tsx +1 -1
- package/src/test/styles3.test.ts +5 -5
- package/src/test/test-jsx.tsx +57 -69
- package/src/test/text.test.ts +17 -15
- package/src/test/translating.test.ts +8 -6
- package/src/test/commands/createShape.test.ts +0 -64
- package/src/test/commands/isShapeOfType.test.ts +0 -44
- package/src/test/commands/updateShape.test.ts +0 -67
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Geometry2d,
|
|
3
3
|
StateNode,
|
|
4
|
+
TLFrameShape,
|
|
5
|
+
TLGroupShape,
|
|
4
6
|
TLShape,
|
|
5
7
|
TLShapeId,
|
|
6
8
|
Vec,
|
|
@@ -102,7 +104,7 @@ export class ScribbleBrushing extends StateNode {
|
|
|
102
104
|
|
|
103
105
|
// If the shape is a group or is already selected or locked, don't select it
|
|
104
106
|
if (
|
|
105
|
-
editor.isShapeOfType(shape, 'group') ||
|
|
107
|
+
editor.isShapeOfType<TLGroupShape>(shape, 'group') ||
|
|
106
108
|
newlySelectedShapeIds.has(shape.id) ||
|
|
107
109
|
editor.isShapeOrAncestorLocked(shape)
|
|
108
110
|
) {
|
|
@@ -113,7 +115,7 @@ export class ScribbleBrushing extends StateNode {
|
|
|
113
115
|
|
|
114
116
|
// If the scribble started inside of the frame, don't select it
|
|
115
117
|
if (
|
|
116
|
-
editor.isShapeOfType(shape, 'frame') &&
|
|
118
|
+
editor.isShapeOfType<TLFrameShape>(shape, 'frame') &&
|
|
117
119
|
geometry.bounds.containsPoint(editor.getPointInShapeSpace(shape, originPagePoint))
|
|
118
120
|
) {
|
|
119
121
|
continue
|
|
@@ -407,7 +407,9 @@ function getTranslatingSnapshot(editor: Editor) {
|
|
|
407
407
|
const { originPagePoint } = editor.inputs
|
|
408
408
|
|
|
409
409
|
const allHoveredNotes = shapeSnapshots.filter(
|
|
410
|
-
(s) =>
|
|
410
|
+
(s) =>
|
|
411
|
+
editor.isShapeOfType<TLNoteShape>(s.shape, 'note') &&
|
|
412
|
+
editor.isPointInShape(s.shape, originPagePoint)
|
|
411
413
|
) as (MovingShapeSnapshot & { shape: TLNoteShape })[]
|
|
412
414
|
|
|
413
415
|
if (allHoveredNotes.length === 0) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { T, TLBaseShape, track, useEditor } from '@tldraw/editor'
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
3
3
|
import { TLUiDialogProps } from '../context/dialogs'
|
|
4
4
|
import { useTranslation } from '../hooks/useTranslation/useTranslation'
|
|
@@ -25,28 +25,20 @@ function validateUrl(url: string) {
|
|
|
25
25
|
return { isValid: false, hasProtocol: false }
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
type ShapeWithUrl =
|
|
29
|
-
|
|
30
|
-
function isShapeWithUrl(shape: TLShape | null | undefined): shape is ShapeWithUrl {
|
|
31
|
-
return !!(shape && 'url' in shape.props && typeof shape.props.url === 'string')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function assertShapeWithUrl(shape: TLShape | null | undefined): asserts shape is ShapeWithUrl {
|
|
35
|
-
if (!isShapeWithUrl(shape)) {
|
|
36
|
-
throw new Error('Shape is not a valid ShapeWithUrl')
|
|
37
|
-
}
|
|
38
|
-
}
|
|
28
|
+
type ShapeWithUrl = TLBaseShape<string, { url: string }>
|
|
39
29
|
|
|
40
30
|
export const EditLinkDialog = track(function EditLinkDialog({ onClose }: TLUiDialogProps) {
|
|
41
31
|
const editor = useEditor()
|
|
42
32
|
|
|
43
33
|
const selectedShape = editor.getOnlySelectedShape()
|
|
44
34
|
|
|
45
|
-
if (
|
|
35
|
+
if (
|
|
36
|
+
!(selectedShape && 'url' in selectedShape.props && typeof selectedShape.props.url === 'string')
|
|
37
|
+
) {
|
|
46
38
|
return null
|
|
47
39
|
}
|
|
48
40
|
|
|
49
|
-
return <EditLinkDialogInner onClose={onClose} selectedShape={selectedShape} />
|
|
41
|
+
return <EditLinkDialogInner onClose={onClose} selectedShape={selectedShape as ShapeWithUrl} />
|
|
50
42
|
})
|
|
51
43
|
|
|
52
44
|
export const EditLinkDialogInner = track(function EditLinkDialogInner({
|
|
@@ -106,7 +98,6 @@ export const EditLinkDialogInner = track(function EditLinkDialogInner({
|
|
|
106
98
|
const handleClear = useCallback(() => {
|
|
107
99
|
const onlySelectedShape = editor.getOnlySelectedShape()
|
|
108
100
|
if (!onlySelectedShape) return
|
|
109
|
-
assertShapeWithUrl(onlySelectedShape)
|
|
110
101
|
editor.updateShapes([
|
|
111
102
|
{ id: onlySelectedShape.id, type: onlySelectedShape.type, props: { url: '' } },
|
|
112
103
|
])
|
|
@@ -117,7 +108,6 @@ export const EditLinkDialogInner = track(function EditLinkDialogInner({
|
|
|
117
108
|
const onlySelectedShape = editor.getOnlySelectedShape()
|
|
118
109
|
|
|
119
110
|
if (!onlySelectedShape) return
|
|
120
|
-
assertShapeWithUrl(onlySelectedShape)
|
|
121
111
|
|
|
122
112
|
// ? URL is a magic value
|
|
123
113
|
if (onlySelectedShape && 'url' in onlySelectedShape.props) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { preventDefault, TLShape, TLShapeId, useEditor } from '@tldraw/editor'
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
3
3
|
import { useUiEvents } from '../../context/events'
|
|
4
4
|
import { useTranslation } from '../../hooks/useTranslation/useTranslation'
|
|
@@ -31,7 +31,7 @@ export function AltTextEditor({ shapeId, onClose, source }: AltTextEditorProps)
|
|
|
31
31
|
|
|
32
32
|
const handleComplete = () => {
|
|
33
33
|
trackEvent('set-alt-text', { source })
|
|
34
|
-
const shape = editor.getShape<
|
|
34
|
+
const shape = editor.getShape<TLShape & { props: { altText: string } }>(shapeId)
|
|
35
35
|
if (!shape) return
|
|
36
36
|
editor.updateShapes([
|
|
37
37
|
{
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
TLBookmarkShape,
|
|
3
|
+
TLEmbedShape,
|
|
4
|
+
TLFrameShape,
|
|
5
|
+
TLImageShape,
|
|
6
|
+
TLPageId,
|
|
7
|
+
useEditor,
|
|
8
|
+
useValue,
|
|
9
|
+
} from '@tldraw/editor'
|
|
2
10
|
import { supportsDownloadingOriginal } from '../context/actions'
|
|
3
11
|
import { useUiEvents } from '../context/events'
|
|
4
12
|
import { useToasts } from '../context/toasts'
|
|
@@ -56,7 +64,7 @@ export function FlattenMenuItem() {
|
|
|
56
64
|
const selectedShapeIds = editor.getSelectedShapeIds()
|
|
57
65
|
if (selectedShapeIds.length === 0) return false
|
|
58
66
|
const onlySelectedShape = editor.getOnlySelectedShape()
|
|
59
|
-
if (onlySelectedShape && editor.isShapeOfType(onlySelectedShape, 'image')) {
|
|
67
|
+
if (onlySelectedShape && editor.isShapeOfType<TLImageShape>(onlySelectedShape, 'image')) {
|
|
60
68
|
return false
|
|
61
69
|
}
|
|
62
70
|
return true
|
|
@@ -109,7 +117,7 @@ export function RemoveFrameMenuItem() {
|
|
|
109
117
|
() => {
|
|
110
118
|
const selectedShapes = editor.getSelectedShapes()
|
|
111
119
|
if (selectedShapes.length === 0) return false
|
|
112
|
-
return selectedShapes.every((shape) => editor.isShapeOfType(shape, 'frame'))
|
|
120
|
+
return selectedShapes.every((shape) => editor.isShapeOfType<TLFrameShape>(shape, 'frame'))
|
|
113
121
|
},
|
|
114
122
|
[editor]
|
|
115
123
|
)
|
|
@@ -127,7 +135,7 @@ export function FitFrameToContentMenuItem() {
|
|
|
127
135
|
const onlySelectedShape = editor.getOnlySelectedShape()
|
|
128
136
|
if (!onlySelectedShape) return false
|
|
129
137
|
return (
|
|
130
|
-
editor.isShapeOfType(onlySelectedShape, 'frame') &&
|
|
138
|
+
editor.isShapeOfType<TLFrameShape>(onlySelectedShape, 'frame') &&
|
|
131
139
|
editor.getSortedChildIdsForParent(onlySelectedShape).length > 0
|
|
132
140
|
)
|
|
133
141
|
},
|
|
@@ -510,7 +518,7 @@ export function ConvertToBookmarkMenuItem() {
|
|
|
510
518
|
const onlySelectedShape = editor.getOnlySelectedShape()
|
|
511
519
|
if (!onlySelectedShape) return false
|
|
512
520
|
return !!(
|
|
513
|
-
editor.isShapeOfType(onlySelectedShape, 'embed') &&
|
|
521
|
+
editor.isShapeOfType<TLEmbedShape>(onlySelectedShape, 'embed') &&
|
|
514
522
|
onlySelectedShape.props.url &&
|
|
515
523
|
!editor.isShapeOrAncestorLocked(onlySelectedShape)
|
|
516
524
|
)
|
|
@@ -534,7 +542,7 @@ export function ConvertToEmbedMenuItem() {
|
|
|
534
542
|
const onlySelectedShape = editor.getOnlySelectedShape()
|
|
535
543
|
if (!onlySelectedShape) return false
|
|
536
544
|
return !!(
|
|
537
|
-
editor.isShapeOfType(onlySelectedShape, 'bookmark') &&
|
|
545
|
+
editor.isShapeOfType<TLBookmarkShape>(onlySelectedShape, 'bookmark') &&
|
|
538
546
|
onlySelectedShape.props.url &&
|
|
539
547
|
getEmbedDefinition(onlySelectedShape.props.url) &&
|
|
540
548
|
!editor.isShapeOrAncestorLocked(onlySelectedShape)
|
|
@@ -6,7 +6,10 @@ import {
|
|
|
6
6
|
HALF_PI,
|
|
7
7
|
PageRecordType,
|
|
8
8
|
Result,
|
|
9
|
+
TLBookmarkShape,
|
|
9
10
|
TLEmbedShape,
|
|
11
|
+
TLFrameShape,
|
|
12
|
+
TLGroupShape,
|
|
10
13
|
TLImageShape,
|
|
11
14
|
TLShape,
|
|
12
15
|
TLShapeId,
|
|
@@ -324,7 +327,7 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
324
327
|
.getSelectedShapes()
|
|
325
328
|
.filter(
|
|
326
329
|
(shape): shape is TLTextShape =>
|
|
327
|
-
editor.isShapeOfType(shape, 'text') && shape.props.autoSize === false
|
|
330
|
+
editor.isShapeOfType<TLTextShape>(shape, 'text') && shape.props.autoSize === false
|
|
328
331
|
)
|
|
329
332
|
editor.updateShapes(
|
|
330
333
|
shapes.map((shape) => {
|
|
@@ -359,7 +362,7 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
359
362
|
return
|
|
360
363
|
}
|
|
361
364
|
const shape = editor.getShape(ids[0])
|
|
362
|
-
if (!shape || !editor.isShapeOfType(shape, 'embed')) {
|
|
365
|
+
if (!shape || !editor.isShapeOfType<TLEmbedShape>(shape, 'embed')) {
|
|
363
366
|
console.error(warnMsg)
|
|
364
367
|
return
|
|
365
368
|
}
|
|
@@ -398,7 +401,8 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
398
401
|
const creationPromises: Promise<Result<any, any>>[] = []
|
|
399
402
|
|
|
400
403
|
for (const shape of shapes) {
|
|
401
|
-
if (!shape || !editor.isShapeOfType(shape, 'embed') || !shape.props.url)
|
|
404
|
+
if (!shape || !editor.isShapeOfType<TLEmbedShape>(shape, 'embed') || !shape.props.url)
|
|
405
|
+
continue
|
|
402
406
|
|
|
403
407
|
const center = editor.getShapePageBounds(shape)?.center
|
|
404
408
|
|
|
@@ -437,7 +441,7 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
437
441
|
const createList: TLShapePartial[] = []
|
|
438
442
|
const deleteList: TLShapeId[] = []
|
|
439
443
|
for (const shape of shapes) {
|
|
440
|
-
if (!editor.isShapeOfType(shape, 'bookmark')) continue
|
|
444
|
+
if (!editor.isShapeOfType<TLBookmarkShape>(shape, 'bookmark')) continue
|
|
441
445
|
|
|
442
446
|
const { url } = shape.props
|
|
443
447
|
|
|
@@ -548,7 +552,7 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
548
552
|
|
|
549
553
|
trackEvent('group-shapes', { source })
|
|
550
554
|
const onlySelectedShape = editor.getOnlySelectedShape()
|
|
551
|
-
if (onlySelectedShape && editor.isShapeOfType(onlySelectedShape, 'group')) {
|
|
555
|
+
if (onlySelectedShape && editor.isShapeOfType<TLGroupShape>(onlySelectedShape, 'group')) {
|
|
552
556
|
editor.markHistoryStoppingPoint('ungroup')
|
|
553
557
|
editor.ungroupShapes(editor.getSelectedShapeIds())
|
|
554
558
|
} else {
|
|
@@ -568,7 +572,7 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
568
572
|
const selectedShapes = editor.getSelectedShapes()
|
|
569
573
|
if (
|
|
570
574
|
selectedShapes.length > 0 &&
|
|
571
|
-
selectedShapes.every((shape) => editor.isShapeOfType(shape, 'frame'))
|
|
575
|
+
selectedShapes.every((shape) => editor.isShapeOfType<TLFrameShape>(shape, 'frame'))
|
|
572
576
|
) {
|
|
573
577
|
editor.markHistoryStoppingPoint('remove-frame')
|
|
574
578
|
removeFrame(
|
|
@@ -586,7 +590,7 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
586
590
|
|
|
587
591
|
trackEvent('fit-frame-to-content', { source })
|
|
588
592
|
const onlySelectedShape = editor.getOnlySelectedShape()
|
|
589
|
-
if (onlySelectedShape && editor.isShapeOfType(onlySelectedShape, 'frame')) {
|
|
593
|
+
if (onlySelectedShape && editor.isShapeOfType<TLFrameShape>(onlySelectedShape, 'frame')) {
|
|
590
594
|
editor.markHistoryStoppingPoint('fit-frame-to-content')
|
|
591
595
|
fitFrameToContent(editor, onlySelectedShape.id)
|
|
592
596
|
}
|
|
@@ -1595,8 +1599,8 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
1595
1599
|
const onlySelectedShape = editor.getOnlySelectedShape()
|
|
1596
1600
|
if (
|
|
1597
1601
|
onlySelectedShape &&
|
|
1598
|
-
(editor.isShapeOfType(onlySelectedShape, 'image') ||
|
|
1599
|
-
editor.isShapeOfType(onlySelectedShape, 'video'))
|
|
1602
|
+
(editor.isShapeOfType<TLImageShape>(onlySelectedShape, 'image') ||
|
|
1603
|
+
editor.isShapeOfType<TLVideoShape>(onlySelectedShape, 'video'))
|
|
1600
1604
|
) {
|
|
1601
1605
|
const firstToolbarButton = editor
|
|
1602
1606
|
.getContainer()
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Editor,
|
|
3
|
+
TLArrowShape,
|
|
4
|
+
TLDrawShape,
|
|
5
|
+
TLGroupShape,
|
|
6
|
+
TLImageShape,
|
|
7
|
+
TLLineShape,
|
|
8
|
+
TLTextShape,
|
|
9
|
+
useEditor,
|
|
10
|
+
useValue,
|
|
11
|
+
} from '@tldraw/editor'
|
|
2
12
|
import { getArrowBindings } from '../../shapes/arrow/shared'
|
|
3
13
|
|
|
4
14
|
function shapesWithUnboundArrows(editor: Editor) {
|
|
@@ -9,7 +19,7 @@ function shapesWithUnboundArrows(editor: Editor) {
|
|
|
9
19
|
|
|
10
20
|
return selectedShapes.filter((shape) => {
|
|
11
21
|
if (!shape) return false
|
|
12
|
-
if (editor.isShapeOfType(shape, 'arrow')) {
|
|
22
|
+
if (editor.isShapeOfType<TLArrowShape>(shape, 'arrow')) {
|
|
13
23
|
const bindings = getArrowBindings(editor, shape)
|
|
14
24
|
if (bindings.start || bindings.end) return false
|
|
15
25
|
}
|
|
@@ -42,7 +52,7 @@ export const useAllowGroup = () => {
|
|
|
42
52
|
if (selectedShapes.length < 2) return false
|
|
43
53
|
|
|
44
54
|
for (const shape of selectedShapes) {
|
|
45
|
-
if (editor.isShapeOfType(shape, 'arrow')) {
|
|
55
|
+
if (editor.isShapeOfType<TLArrowShape>(shape, 'arrow')) {
|
|
46
56
|
const bindings = getArrowBindings(editor, shape)
|
|
47
57
|
if (bindings.start) {
|
|
48
58
|
// if the other shape is not among the selected shapes...
|
|
@@ -153,7 +163,7 @@ export function useShowAutoSizeToggle() {
|
|
|
153
163
|
const selectedShapes = editor.getSelectedShapes()
|
|
154
164
|
return (
|
|
155
165
|
selectedShapes.length === 1 &&
|
|
156
|
-
editor.isShapeOfType(selectedShapes[0], 'text') &&
|
|
166
|
+
editor.isShapeOfType<TLTextShape>(selectedShapes[0], 'text') &&
|
|
157
167
|
selectedShapes[0].props.autoSize === false
|
|
158
168
|
)
|
|
159
169
|
},
|
|
@@ -186,11 +196,11 @@ export function useOnlyFlippableShape() {
|
|
|
186
196
|
const shape = editor.getOnlySelectedShape()
|
|
187
197
|
return (
|
|
188
198
|
shape &&
|
|
189
|
-
(editor.isShapeOfType(shape, 'group') ||
|
|
190
|
-
editor.isShapeOfType(shape, 'image') ||
|
|
191
|
-
editor.isShapeOfType(shape, 'arrow') ||
|
|
192
|
-
editor.isShapeOfType(shape, 'line') ||
|
|
193
|
-
editor.isShapeOfType(shape, 'draw'))
|
|
199
|
+
(editor.isShapeOfType<TLGroupShape>(shape, 'group') ||
|
|
200
|
+
editor.isShapeOfType<TLImageShape>(shape, 'image') ||
|
|
201
|
+
editor.isShapeOfType<TLArrowShape>(shape, 'arrow') ||
|
|
202
|
+
editor.isShapeOfType<TLLineShape>(shape, 'line') ||
|
|
203
|
+
editor.isShapeOfType<TLDrawShape>(shape, 'draw'))
|
|
194
204
|
)
|
|
195
205
|
},
|
|
196
206
|
[editor]
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
Editor,
|
|
4
4
|
IndexKey,
|
|
5
5
|
TLImageAsset,
|
|
6
|
+
TLImageShape,
|
|
6
7
|
TLShape,
|
|
7
8
|
TLShapeId,
|
|
8
9
|
Vec,
|
|
@@ -165,7 +166,7 @@ export async function flattenShapesToImages(
|
|
|
165
166
|
const shapeId = createShapeId()
|
|
166
167
|
|
|
167
168
|
// create an image shape in the same place as the shapes
|
|
168
|
-
editor.createShape({
|
|
169
|
+
editor.createShape<TLImageShape>({
|
|
169
170
|
id: shapeId,
|
|
170
171
|
type: 'image',
|
|
171
172
|
index,
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
Editor,
|
|
5
5
|
GeoShapeGeoStyle,
|
|
6
6
|
getIndicesBetween,
|
|
7
|
+
TLLineShape,
|
|
7
8
|
TLPointerEventInfo,
|
|
8
9
|
TLShapeId,
|
|
9
10
|
toRichText,
|
|
@@ -194,7 +195,7 @@ export function ToolsProvider({ overrides, children }: TLUiToolsProviderProps) {
|
|
|
194
195
|
onDragFromToolbarToCreateShape(editor, info, {
|
|
195
196
|
createShape: (id) => {
|
|
196
197
|
const [start, end] = getIndicesBetween(null, null, 2)
|
|
197
|
-
editor.createShape({
|
|
198
|
+
editor.createShape<TLLineShape>({
|
|
198
199
|
id,
|
|
199
200
|
type: 'line',
|
|
200
201
|
props: {
|
package/src/lib/ui/version.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// This file is automatically generated by internal/scripts/refresh-assets.ts.
|
|
2
2
|
// Do not edit manually. Or do, I'm a comment, not a cop.
|
|
3
3
|
|
|
4
|
-
export const version = '4.3.0-
|
|
4
|
+
export const version = '4.3.0-next.2b3bfbba757b'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2025-09-18T14:39:22.803Z',
|
|
7
|
-
minor: '2025-11-
|
|
8
|
-
patch: '2025-11-
|
|
7
|
+
minor: '2025-11-25T08:43:48.918Z',
|
|
8
|
+
patch: '2025-11-25T08:43:48.918Z',
|
|
9
9
|
}
|
|
@@ -133,7 +133,6 @@ export async function putExcalidrawContent(
|
|
|
133
133
|
...base,
|
|
134
134
|
type: 'geo',
|
|
135
135
|
props: {
|
|
136
|
-
...editor.getShapeUtil('geo').getDefaultProps(),
|
|
137
136
|
geo: element.type,
|
|
138
137
|
url: element.link ?? '',
|
|
139
138
|
w: element.width,
|
|
@@ -153,7 +152,6 @@ export async function putExcalidrawContent(
|
|
|
153
152
|
...base,
|
|
154
153
|
type: 'draw',
|
|
155
154
|
props: {
|
|
156
|
-
...editor.getShapeUtil('draw').getDefaultProps(),
|
|
157
155
|
dash: getDash(element),
|
|
158
156
|
size: strokeWidthsToSizes[element.strokeWidth],
|
|
159
157
|
color: colorsToColors[element.strokeColor] ?? 'black',
|
|
@@ -182,7 +180,6 @@ export async function putExcalidrawContent(
|
|
|
182
180
|
...base,
|
|
183
181
|
type: 'line',
|
|
184
182
|
props: {
|
|
185
|
-
...editor.getShapeUtil('line').getDefaultProps(),
|
|
186
183
|
dash: getDash(element),
|
|
187
184
|
size: strokeWidthsToSizes[element.strokeWidth],
|
|
188
185
|
color: colorsToColors[element.strokeColor] ?? 'black',
|
|
@@ -224,7 +221,6 @@ export async function putExcalidrawContent(
|
|
|
224
221
|
...base,
|
|
225
222
|
type: 'arrow',
|
|
226
223
|
props: {
|
|
227
|
-
...editor.getShapeUtil('arrow').getDefaultProps(),
|
|
228
224
|
richText: toRichText(text),
|
|
229
225
|
kind: element.elbowed ? 'elbow' : 'arc',
|
|
230
226
|
bend: getBend(element, start, end),
|
|
@@ -247,7 +243,6 @@ export async function putExcalidrawContent(
|
|
|
247
243
|
toId: startTargetId,
|
|
248
244
|
props: {
|
|
249
245
|
terminal: 'start',
|
|
250
|
-
snap: 'none',
|
|
251
246
|
normalizedAnchor: { x: 0.5, y: 0.5 },
|
|
252
247
|
isPrecise: false,
|
|
253
248
|
isExact: false,
|
|
@@ -264,7 +259,6 @@ export async function putExcalidrawContent(
|
|
|
264
259
|
toId: endTargetId,
|
|
265
260
|
props: {
|
|
266
261
|
terminal: 'end',
|
|
267
|
-
snap: 'none',
|
|
268
262
|
normalizedAnchor: { x: 0.5, y: 0.5 },
|
|
269
263
|
isPrecise: false,
|
|
270
264
|
isExact: false,
|
|
@@ -281,7 +275,6 @@ export async function putExcalidrawContent(
|
|
|
281
275
|
...base,
|
|
282
276
|
type: 'text',
|
|
283
277
|
props: {
|
|
284
|
-
...editor.getShapeUtil('text').getDefaultProps(),
|
|
285
278
|
size,
|
|
286
279
|
scale,
|
|
287
280
|
font: fontFamilyToFontType[element.fontFamily] ?? 'draw',
|
|
@@ -317,7 +310,6 @@ export async function putExcalidrawContent(
|
|
|
317
310
|
...base,
|
|
318
311
|
type: 'image',
|
|
319
312
|
props: {
|
|
320
|
-
...editor.getShapeUtil('image').getDefaultProps(),
|
|
321
313
|
w: element.width,
|
|
322
314
|
h: element.height,
|
|
323
315
|
assetId,
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Editor,
|
|
3
|
+
sanitizeId,
|
|
4
|
+
TLExportType,
|
|
5
|
+
TLFrameShape,
|
|
6
|
+
TLImageExportOptions,
|
|
7
|
+
TLShapeId,
|
|
8
|
+
} from '@tldraw/editor'
|
|
2
9
|
|
|
3
10
|
/** @public */
|
|
4
11
|
export interface ExportAsOptions extends TLImageExportOptions {
|
|
@@ -28,7 +35,7 @@ export async function exportAs(
|
|
|
28
35
|
name = `shapes at ${getTimestamp()}`
|
|
29
36
|
if (ids.length === 1) {
|
|
30
37
|
const first = editor.getShape(ids[0])!
|
|
31
|
-
if (editor.isShapeOfType(first, 'frame')) {
|
|
38
|
+
if (editor.isShapeOfType<TLFrameShape>(first, 'frame')) {
|
|
32
39
|
name = first.props.name || 'frame'
|
|
33
40
|
} else {
|
|
34
41
|
name = `${sanitizeId(first.id)} at ${getTimestamp()}`
|
|
@@ -22,7 +22,7 @@ export function removeFrame(editor: Editor, ids: TLShapeId[]) {
|
|
|
22
22
|
const frames = compact(
|
|
23
23
|
ids
|
|
24
24
|
.map((id) => editor.getShape<TLFrameShape>(id))
|
|
25
|
-
.filter((f) => f && editor.isShapeOfType(f, 'frame'))
|
|
25
|
+
.filter((f) => f && editor.isShapeOfType<TLFrameShape>(f, 'frame'))
|
|
26
26
|
)
|
|
27
27
|
if (!frames.length) return
|
|
28
28
|
|
|
@@ -12,9 +12,14 @@ import {
|
|
|
12
12
|
TLDefaultHorizontalAlignStyle,
|
|
13
13
|
TLDefaultSizeStyle,
|
|
14
14
|
TLDefaultTextAlignStyle,
|
|
15
|
+
TLDrawShape,
|
|
15
16
|
TLGeoShape,
|
|
17
|
+
TLImageShape,
|
|
18
|
+
TLNoteShape,
|
|
16
19
|
TLPageId,
|
|
17
20
|
TLShapeId,
|
|
21
|
+
TLTextShape,
|
|
22
|
+
TLVideoShape,
|
|
18
23
|
Vec,
|
|
19
24
|
VecModel,
|
|
20
25
|
clamp,
|
|
@@ -182,7 +187,7 @@ export function buildFromV1Document(editor: Editor, _document: unknown) {
|
|
|
182
187
|
|
|
183
188
|
switch (v1Shape.type) {
|
|
184
189
|
case TLV1ShapeType.Sticky: {
|
|
185
|
-
editor.createShapes([
|
|
190
|
+
editor.createShapes<TLNoteShape>([
|
|
186
191
|
{
|
|
187
192
|
...inCommon,
|
|
188
193
|
type: 'note',
|
|
@@ -198,7 +203,7 @@ export function buildFromV1Document(editor: Editor, _document: unknown) {
|
|
|
198
203
|
break
|
|
199
204
|
}
|
|
200
205
|
case TLV1ShapeType.Rectangle: {
|
|
201
|
-
editor.createShapes([
|
|
206
|
+
editor.createShapes<TLGeoShape>([
|
|
202
207
|
{
|
|
203
208
|
...inCommon,
|
|
204
209
|
type: 'geo',
|
|
@@ -220,7 +225,7 @@ export function buildFromV1Document(editor: Editor, _document: unknown) {
|
|
|
220
225
|
|
|
221
226
|
const pageBoundsBeforeLabel = editor.getShapePageBounds(inCommon.id)!
|
|
222
227
|
|
|
223
|
-
editor.updateShapes([
|
|
228
|
+
editor.updateShapes<TLGeoShape>([
|
|
224
229
|
{
|
|
225
230
|
id: inCommon.id,
|
|
226
231
|
type: 'geo',
|
|
@@ -254,7 +259,7 @@ export function buildFromV1Document(editor: Editor, _document: unknown) {
|
|
|
254
259
|
break
|
|
255
260
|
}
|
|
256
261
|
case TLV1ShapeType.Triangle: {
|
|
257
|
-
editor.createShapes([
|
|
262
|
+
editor.createShapes<TLGeoShape>([
|
|
258
263
|
{
|
|
259
264
|
...inCommon,
|
|
260
265
|
type: 'geo',
|
|
@@ -275,7 +280,7 @@ export function buildFromV1Document(editor: Editor, _document: unknown) {
|
|
|
275
280
|
|
|
276
281
|
const pageBoundsBeforeLabel = editor.getShapePageBounds(inCommon.id)!
|
|
277
282
|
|
|
278
|
-
editor.updateShapes([
|
|
283
|
+
editor.updateShapes<TLGeoShape>([
|
|
279
284
|
{
|
|
280
285
|
id: inCommon.id,
|
|
281
286
|
type: 'geo',
|
|
@@ -309,7 +314,7 @@ export function buildFromV1Document(editor: Editor, _document: unknown) {
|
|
|
309
314
|
break
|
|
310
315
|
}
|
|
311
316
|
case TLV1ShapeType.Ellipse: {
|
|
312
|
-
editor.createShapes([
|
|
317
|
+
editor.createShapes<TLGeoShape>([
|
|
313
318
|
{
|
|
314
319
|
...inCommon,
|
|
315
320
|
type: 'geo',
|
|
@@ -330,7 +335,7 @@ export function buildFromV1Document(editor: Editor, _document: unknown) {
|
|
|
330
335
|
|
|
331
336
|
const pageBoundsBeforeLabel = editor.getShapePageBounds(inCommon.id)!
|
|
332
337
|
|
|
333
|
-
editor.updateShapes([
|
|
338
|
+
editor.updateShapes<TLGeoShape>([
|
|
334
339
|
{
|
|
335
340
|
id: inCommon.id,
|
|
336
341
|
type: 'geo',
|
|
@@ -370,7 +375,7 @@ export function buildFromV1Document(editor: Editor, _document: unknown) {
|
|
|
370
375
|
break
|
|
371
376
|
}
|
|
372
377
|
|
|
373
|
-
editor.createShapes([
|
|
378
|
+
editor.createShapes<TLDrawShape>([
|
|
374
379
|
{
|
|
375
380
|
...inCommon,
|
|
376
381
|
type: 'draw',
|
|
@@ -395,7 +400,7 @@ export function buildFromV1Document(editor: Editor, _document: unknown) {
|
|
|
395
400
|
const v2Bend = (dist * -v1Bend) / 2
|
|
396
401
|
|
|
397
402
|
// Could also be a line... but we'll use it as an arrow anyway
|
|
398
|
-
editor.createShapes([
|
|
403
|
+
editor.createShapes<TLArrowShape>([
|
|
399
404
|
{
|
|
400
405
|
...inCommon,
|
|
401
406
|
type: 'arrow',
|
|
@@ -424,7 +429,7 @@ export function buildFromV1Document(editor: Editor, _document: unknown) {
|
|
|
424
429
|
break
|
|
425
430
|
}
|
|
426
431
|
case TLV1ShapeType.Text: {
|
|
427
|
-
editor.createShapes([
|
|
432
|
+
editor.createShapes<TLTextShape>([
|
|
428
433
|
{
|
|
429
434
|
...inCommon,
|
|
430
435
|
type: 'text',
|
|
@@ -448,7 +453,7 @@ export function buildFromV1Document(editor: Editor, _document: unknown) {
|
|
|
448
453
|
return
|
|
449
454
|
}
|
|
450
455
|
|
|
451
|
-
editor.createShapes([
|
|
456
|
+
editor.createShapes<TLImageShape>([
|
|
452
457
|
{
|
|
453
458
|
...inCommon,
|
|
454
459
|
type: 'image',
|
|
@@ -469,7 +474,7 @@ export function buildFromV1Document(editor: Editor, _document: unknown) {
|
|
|
469
474
|
return
|
|
470
475
|
}
|
|
471
476
|
|
|
472
|
-
editor.createShapes([
|
|
477
|
+
editor.createShapes<TLVideoShape>([
|
|
473
478
|
{
|
|
474
479
|
...inCommon,
|
|
475
480
|
type: 'video',
|
package/src/test/Editor.test.tsx
CHANGED
|
@@ -472,20 +472,12 @@ describe('isFocused', () => {
|
|
|
472
472
|
})
|
|
473
473
|
})
|
|
474
474
|
|
|
475
|
-
const BLORG_TYPE = 'blorg'
|
|
476
|
-
|
|
477
|
-
declare module '@tldraw/tlschema' {
|
|
478
|
-
export interface TLGlobalShapePropsMap {
|
|
479
|
-
[BLORG_TYPE]: { w: number; h: number }
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
475
|
describe('getShapeUtil', () => {
|
|
484
476
|
let myUtil: any
|
|
485
477
|
|
|
486
478
|
beforeEach(() => {
|
|
487
479
|
class _MyFakeShapeUtil extends BaseBoxShapeUtil<any> {
|
|
488
|
-
static override type =
|
|
480
|
+
static override type = 'blorg'
|
|
489
481
|
|
|
490
482
|
getDefaultProps() {
|
|
491
483
|
return {
|
|
@@ -527,22 +519,16 @@ describe('getShapeUtil', () => {
|
|
|
527
519
|
})
|
|
528
520
|
|
|
529
521
|
it('throws if that shape type isnt registered', () => {
|
|
530
|
-
const myMissingShape = { type: 'missing' }
|
|
531
|
-
expect(() =>
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
myMissingShape
|
|
535
|
-
)
|
|
536
|
-
).toThrowErrorMatchingInlineSnapshot(`[Error: No shape util found for type "missing"]`)
|
|
522
|
+
const myMissingShape = { type: 'missing' } as TLShape
|
|
523
|
+
expect(() => editor.getShapeUtil(myMissingShape)).toThrowErrorMatchingInlineSnapshot(
|
|
524
|
+
`[Error: No shape util found for type "missing"]`
|
|
525
|
+
)
|
|
537
526
|
})
|
|
538
527
|
|
|
539
528
|
it('throws if that type isnt registered', () => {
|
|
540
|
-
expect(() =>
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
'missing'
|
|
544
|
-
)
|
|
545
|
-
).toThrowErrorMatchingInlineSnapshot(`[Error: No shape util found for type "missing"]`)
|
|
529
|
+
expect(() => editor.getShapeUtil('missing')).toThrowErrorMatchingInlineSnapshot(
|
|
530
|
+
`[Error: No shape util found for type "missing"]`
|
|
531
|
+
)
|
|
546
532
|
})
|
|
547
533
|
})
|
|
548
534
|
|
|
@@ -880,19 +866,9 @@ describe('instance.isReadonly', () => {
|
|
|
880
866
|
})
|
|
881
867
|
})
|
|
882
868
|
|
|
883
|
-
const MY_CUSTOM_SHAPE_TYPE = 'myCustomShape'
|
|
884
|
-
|
|
885
|
-
type MyCustomShape = TLShape<typeof MY_CUSTOM_SHAPE_TYPE>
|
|
886
|
-
|
|
887
|
-
declare module '@tldraw/tlschema' {
|
|
888
|
-
export interface TLGlobalShapePropsMap {
|
|
889
|
-
[MY_CUSTOM_SHAPE_TYPE]: { w: number; h: number }
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
|
|
893
869
|
describe('the geometry cache', () => {
|
|
894
|
-
class CustomShapeUtil extends BaseBoxShapeUtil<
|
|
895
|
-
static override type =
|
|
870
|
+
class CustomShapeUtil extends BaseBoxShapeUtil<any> {
|
|
871
|
+
static override type = 'custom'
|
|
896
872
|
|
|
897
873
|
getDefaultProps() {
|
|
898
874
|
return {
|
|
@@ -918,11 +894,9 @@ describe('the geometry cache', () => {
|
|
|
918
894
|
editor = new TestEditor({
|
|
919
895
|
shapeUtils: [CustomShapeUtil],
|
|
920
896
|
})
|
|
921
|
-
const { A } = editor.createShapesFromJsx([
|
|
922
|
-
<TL.myCustomShape ref="A" x={0} y={0} w={100} h={100} />,
|
|
923
|
-
])
|
|
897
|
+
const { A } = editor.createShapesFromJsx([<TL.custom ref="A" x={0} y={0} w={100} h={100} />])
|
|
924
898
|
expect(editor.getShapePageBounds(A)!.width).toBe(100)
|
|
925
|
-
editor.updateShape({ id: A, type: '
|
|
899
|
+
editor.updateShape({ id: A, type: 'custom', meta: { double: true } })
|
|
926
900
|
expect(editor.getShapePageBounds(A)!.width).toBe(200)
|
|
927
901
|
})
|
|
928
902
|
})
|