@tldraw/editor 4.6.0-next.fe1474dc57d8 → 5.0.0
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 +412 -179
- package/dist-cjs/index.js +12 -23
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +3 -0
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/default-components/CanvasOverlays.js +180 -0
- package/dist-cjs/lib/components/default-components/CanvasOverlays.js.map +7 -0
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +44 -249
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +3 -3
- package/dist-cjs/lib/editor/Editor.js +78 -28
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js +98 -0
- package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js +14 -0
- package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js.map +2 -2
- package/dist-cjs/lib/editor/overlays/OverlayManager.js +154 -0
- package/dist-cjs/lib/editor/overlays/OverlayManager.js.map +7 -0
- package/dist-cjs/lib/editor/overlays/OverlayUtil.js +92 -0
- package/dist-cjs/lib/editor/overlays/OverlayUtil.js.map +7 -0
- package/dist-cjs/lib/editor/overlays/ShapeIndicatorOverlayUtil.js +161 -0
- package/dist-cjs/lib/editor/overlays/ShapeIndicatorOverlayUtil.js.map +7 -0
- package/dist-cjs/lib/editor/overlays/getOverlayDisplayValues.js +39 -0
- package/dist-cjs/lib/editor/overlays/getOverlayDisplayValues.js.map +7 -0
- package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js +3 -0
- package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +25 -23
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +32 -2
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/types/event-types.js.map +2 -2
- package/dist-cjs/lib/exports/fetchCache.js +1 -1
- package/dist-cjs/lib/exports/fetchCache.js.map +2 -2
- package/dist-cjs/lib/hooks/EditorComponentsContext.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +3 -3
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useEditorComponents.js +0 -28
- package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePeerIds.js +1 -36
- package/dist-cjs/lib/hooks/usePeerIds.js.map +2 -2
- package/dist-cjs/lib/hooks/useShapeCulling.js +2 -1
- package/dist-cjs/lib/hooks/useShapeCulling.js.map +2 -2
- package/dist-cjs/lib/options.js +0 -1
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/utils/reparenting.js +20 -7
- package/dist-cjs/lib/utils/reparenting.js.map +2 -2
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +3 -0
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
- package/dist-cjs/version.js +4 -4
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +412 -179
- package/dist-esm/index.mjs +19 -41
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +3 -0
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/CanvasOverlays.mjs +160 -0
- package/dist-esm/lib/components/default-components/CanvasOverlays.mjs.map +7 -0
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +45 -250
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +3 -3
- package/dist-esm/lib/editor/Editor.mjs +78 -29
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs +83 -0
- package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs +14 -0
- package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs.map +2 -2
- package/dist-esm/lib/editor/overlays/OverlayManager.mjs +136 -0
- package/dist-esm/lib/editor/overlays/OverlayManager.mjs.map +7 -0
- package/dist-esm/lib/editor/overlays/OverlayUtil.mjs +72 -0
- package/dist-esm/lib/editor/overlays/OverlayUtil.mjs.map +7 -0
- package/dist-esm/lib/editor/overlays/ShapeIndicatorOverlayUtil.mjs +141 -0
- package/dist-esm/lib/editor/overlays/ShapeIndicatorOverlayUtil.mjs.map +7 -0
- package/dist-esm/lib/editor/overlays/getOverlayDisplayValues.mjs +19 -0
- package/dist-esm/lib/editor/overlays/getOverlayDisplayValues.mjs.map +7 -0
- package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs +3 -0
- package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +25 -23
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +32 -2
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/types/event-types.mjs.map +2 -2
- package/dist-esm/lib/exports/fetchCache.mjs +2 -2
- package/dist-esm/lib/exports/fetchCache.mjs.map +2 -2
- package/dist-esm/lib/hooks/EditorComponentsContext.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +3 -3
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditorComponents.mjs +0 -28
- package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePeerIds.mjs +2 -40
- package/dist-esm/lib/hooks/usePeerIds.mjs.map +2 -2
- package/dist-esm/lib/hooks/useShapeCulling.mjs +2 -1
- package/dist-esm/lib/hooks/useShapeCulling.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +0 -1
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/utils/reparenting.mjs +20 -7
- package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +3 -0
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
- package/dist-esm/version.mjs +4 -4
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +4 -239
- package/package.json +7 -7
- package/src/index.ts +17 -39
- package/src/lib/TldrawEditor.tsx +9 -0
- package/src/lib/components/default-components/CanvasOverlays.tsx +208 -0
- package/src/lib/components/default-components/DefaultCanvas.tsx +49 -324
- package/src/lib/editor/Editor.test.ts +3 -1
- package/src/lib/editor/Editor.ts +80 -24
- package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.ts +98 -0
- package/src/lib/editor/managers/ThemeManager/defaultThemes.ts +14 -0
- package/src/lib/editor/overlays/OverlayManager.ts +183 -0
- package/src/lib/editor/overlays/OverlayUtil.ts +143 -0
- package/src/lib/editor/overlays/ShapeIndicatorOverlayUtil.ts +216 -0
- package/src/lib/editor/overlays/getOverlayDisplayValues.ts +51 -0
- package/src/lib/editor/shapes/BaseFrameLikeShapeUtil.tsx +9 -2
- package/src/lib/editor/shapes/ShapeUtil.ts +34 -26
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +40 -3
- package/src/lib/editor/types/event-types.ts +2 -0
- package/src/lib/exports/fetchCache.ts +2 -4
- package/src/lib/exports/getSvgJsx.test.ts +3 -1
- package/src/lib/hooks/EditorComponentsContext.tsx +0 -27
- package/src/lib/hooks/useCanvasEvents.ts +13 -8
- package/src/lib/hooks/useEditorComponents.tsx +0 -28
- package/src/lib/hooks/usePeerIds.ts +6 -55
- package/src/lib/hooks/useShapeCulling.tsx +3 -1
- package/src/lib/options.ts +0 -7
- package/src/lib/utils/reparenting.ts +22 -9
- package/src/lib/utils/sync/TLLocalSyncClient.ts +3 -0
- package/src/version.ts +4 -4
- package/dist-cjs/lib/components/GeometryDebuggingView.js +0 -115
- package/dist-cjs/lib/components/GeometryDebuggingView.js.map +0 -7
- package/dist-cjs/lib/components/LiveCollaborators.js +0 -152
- package/dist-cjs/lib/components/LiveCollaborators.js.map +0 -7
- package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js +0 -234
- package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js.map +0 -7
- package/dist-cjs/lib/components/default-components/DefaultBrush.js +0 -38
- package/dist-cjs/lib/components/default-components/DefaultBrush.js.map +0 -7
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +0 -71
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +0 -7
- package/dist-cjs/lib/components/default-components/DefaultCursor.js +0 -59
- package/dist-cjs/lib/components/default-components/DefaultCursor.js.map +0 -7
- package/dist-cjs/lib/components/default-components/DefaultHandle.js +0 -56
- package/dist-cjs/lib/components/default-components/DefaultHandle.js.map +0 -7
- package/dist-cjs/lib/components/default-components/DefaultHandles.js +0 -28
- package/dist-cjs/lib/components/default-components/DefaultHandles.js.map +0 -7
- package/dist-cjs/lib/components/default-components/DefaultScribble.js +0 -51
- package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +0 -7
- package/dist-cjs/lib/components/default-components/DefaultSelectionForeground.js +0 -69
- package/dist-cjs/lib/components/default-components/DefaultSelectionForeground.js.map +0 -7
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +0 -107
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +0 -7
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicatorErrorFallback.js +0 -28
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicatorErrorFallback.js.map +0 -7
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js +0 -102
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js.map +0 -7
- package/dist-cjs/lib/components/default-components/DefaultSnapIndictor.js +0 -170
- package/dist-cjs/lib/components/default-components/DefaultSnapIndictor.js.map +0 -7
- package/dist-cjs/lib/hooks/useHandleEvents.js +0 -100
- package/dist-cjs/lib/hooks/useHandleEvents.js.map +0 -7
- package/dist-cjs/lib/hooks/useSelectionEvents.js +0 -98
- package/dist-cjs/lib/hooks/useSelectionEvents.js.map +0 -7
- package/dist-esm/lib/components/GeometryDebuggingView.mjs +0 -95
- package/dist-esm/lib/components/GeometryDebuggingView.mjs.map +0 -7
- package/dist-esm/lib/components/LiveCollaborators.mjs +0 -135
- package/dist-esm/lib/components/LiveCollaborators.mjs.map +0 -7
- package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs +0 -214
- package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs.map +0 -7
- package/dist-esm/lib/components/default-components/DefaultBrush.mjs +0 -18
- package/dist-esm/lib/components/default-components/DefaultBrush.mjs.map +0 -7
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +0 -41
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +0 -7
- package/dist-esm/lib/components/default-components/DefaultCursor.mjs +0 -29
- package/dist-esm/lib/components/default-components/DefaultCursor.mjs.map +0 -7
- package/dist-esm/lib/components/default-components/DefaultHandle.mjs +0 -26
- package/dist-esm/lib/components/default-components/DefaultHandle.mjs.map +0 -7
- package/dist-esm/lib/components/default-components/DefaultHandles.mjs +0 -8
- package/dist-esm/lib/components/default-components/DefaultHandles.mjs.map +0 -7
- package/dist-esm/lib/components/default-components/DefaultScribble.mjs +0 -21
- package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +0 -7
- package/dist-esm/lib/components/default-components/DefaultSelectionForeground.mjs +0 -39
- package/dist-esm/lib/components/default-components/DefaultSelectionForeground.mjs.map +0 -7
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +0 -77
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +0 -7
- package/dist-esm/lib/components/default-components/DefaultShapeIndicatorErrorFallback.mjs +0 -8
- package/dist-esm/lib/components/default-components/DefaultShapeIndicatorErrorFallback.mjs.map +0 -7
- package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs +0 -82
- package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs.map +0 -7
- package/dist-esm/lib/components/default-components/DefaultSnapIndictor.mjs +0 -142
- package/dist-esm/lib/components/default-components/DefaultSnapIndictor.mjs.map +0 -7
- package/dist-esm/lib/hooks/useHandleEvents.mjs +0 -70
- package/dist-esm/lib/hooks/useHandleEvents.mjs.map +0 -7
- package/dist-esm/lib/hooks/useSelectionEvents.mjs +0 -78
- package/dist-esm/lib/hooks/useSelectionEvents.mjs.map +0 -7
- package/src/lib/components/GeometryDebuggingView.tsx +0 -108
- package/src/lib/components/LiveCollaborators.tsx +0 -180
- package/src/lib/components/default-components/CanvasShapeIndicators.tsx +0 -300
- package/src/lib/components/default-components/DefaultBrush.tsx +0 -35
- package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +0 -52
- package/src/lib/components/default-components/DefaultCursor.tsx +0 -59
- package/src/lib/components/default-components/DefaultHandle.tsx +0 -42
- package/src/lib/components/default-components/DefaultHandles.tsx +0 -15
- package/src/lib/components/default-components/DefaultScribble.tsx +0 -31
- package/src/lib/components/default-components/DefaultSelectionForeground.tsx +0 -50
- package/src/lib/components/default-components/DefaultShapeIndicator.tsx +0 -104
- package/src/lib/components/default-components/DefaultShapeIndicatorErrorFallback.tsx +0 -9
- package/src/lib/components/default-components/DefaultShapeIndicators.tsx +0 -118
- package/src/lib/components/default-components/DefaultSnapIndictor.tsx +0 -174
- package/src/lib/hooks/useHandleEvents.ts +0 -88
- package/src/lib/hooks/useSelectionEvents.ts +0 -97
package/src/index.ts
CHANGED
|
@@ -14,62 +14,24 @@ export * from '@tldraw/utils'
|
|
|
14
14
|
export * from '@tldraw/validate'
|
|
15
15
|
|
|
16
16
|
export { DefaultBackground } from './lib/components/default-components/DefaultBackground'
|
|
17
|
-
export { DefaultBrush, type TLBrushProps } from './lib/components/default-components/DefaultBrush'
|
|
18
17
|
export {
|
|
19
18
|
DefaultCanvas,
|
|
20
19
|
type TLCanvasComponentProps,
|
|
21
20
|
} from './lib/components/default-components/DefaultCanvas'
|
|
22
|
-
export {
|
|
23
|
-
DefaultCollaboratorHint,
|
|
24
|
-
type TLCollaboratorHintProps,
|
|
25
|
-
} from './lib/components/default-components/DefaultCollaboratorHint'
|
|
26
|
-
export {
|
|
27
|
-
DefaultCursor,
|
|
28
|
-
type TLCursorProps,
|
|
29
|
-
} from './lib/components/default-components/DefaultCursor'
|
|
30
21
|
export {
|
|
31
22
|
DefaultErrorFallback,
|
|
32
23
|
type TLErrorFallbackComponent,
|
|
33
24
|
} from './lib/components/default-components/DefaultErrorFallback'
|
|
34
25
|
export { DefaultGrid, type TLGridProps } from './lib/components/default-components/DefaultGrid'
|
|
35
|
-
export {
|
|
36
|
-
DefaultHandle,
|
|
37
|
-
type TLHandleProps,
|
|
38
|
-
} from './lib/components/default-components/DefaultHandle'
|
|
39
|
-
export {
|
|
40
|
-
DefaultHandles,
|
|
41
|
-
type TLHandlesProps,
|
|
42
|
-
} from './lib/components/default-components/DefaultHandles'
|
|
43
|
-
export {
|
|
44
|
-
DefaultScribble,
|
|
45
|
-
type TLScribbleProps,
|
|
46
|
-
} from './lib/components/default-components/DefaultScribble'
|
|
47
26
|
export {
|
|
48
27
|
DefaultSelectionBackground,
|
|
49
28
|
type TLSelectionBackgroundProps,
|
|
50
29
|
} from './lib/components/default-components/DefaultSelectionBackground'
|
|
51
|
-
export {
|
|
52
|
-
DefaultSelectionForeground,
|
|
53
|
-
type TLSelectionForegroundProps,
|
|
54
|
-
} from './lib/components/default-components/DefaultSelectionForeground'
|
|
55
30
|
export { type TLShapeErrorFallbackComponent } from './lib/components/default-components/DefaultShapeErrorFallback'
|
|
56
|
-
export {
|
|
57
|
-
DefaultShapeIndicator,
|
|
58
|
-
type TLShapeIndicatorProps,
|
|
59
|
-
} from './lib/components/default-components/DefaultShapeIndicator'
|
|
60
|
-
export { type TLShapeIndicatorErrorFallbackComponent } from './lib/components/default-components/DefaultShapeIndicatorErrorFallback'
|
|
61
|
-
export {
|
|
62
|
-
DefaultShapeIndicators,
|
|
63
|
-
type TLShapeIndicatorsProps,
|
|
64
|
-
} from './lib/components/default-components/DefaultShapeIndicators'
|
|
65
31
|
export {
|
|
66
32
|
DefaultShapeWrapper,
|
|
67
33
|
type TLShapeWrapperProps,
|
|
68
34
|
} from './lib/components/default-components/DefaultShapeWrapper'
|
|
69
|
-
export {
|
|
70
|
-
DefaultSnapIndicator,
|
|
71
|
-
type TLSnapIndicatorProps,
|
|
72
|
-
} from './lib/components/default-components/DefaultSnapIndictor'
|
|
73
35
|
export { DefaultSpinner } from './lib/components/default-components/DefaultSpinner'
|
|
74
36
|
export { DefaultSvgDefs } from './lib/components/default-components/DefaultSvgDefs'
|
|
75
37
|
export {
|
|
@@ -174,6 +136,7 @@ export {
|
|
|
174
136
|
export { DEFAULT_THEME } from './lib/editor/managers/ThemeManager/defaultThemes'
|
|
175
137
|
export { ThemeManager, resolveThemes } from './lib/editor/managers/ThemeManager/ThemeManager'
|
|
176
138
|
export { TickManager } from './lib/editor/managers/TickManager/TickManager'
|
|
139
|
+
export { CollaboratorsManager } from './lib/editor/managers/CollaboratorsManager/CollaboratorsManager'
|
|
177
140
|
export { PerformanceApiAdapter } from './lib/editor/managers/PerformanceManager/PerformanceApiAdapter'
|
|
178
141
|
export { PerformanceManager } from './lib/editor/managers/PerformanceManager/PerformanceManager'
|
|
179
142
|
export {
|
|
@@ -211,6 +174,22 @@ export {
|
|
|
211
174
|
type TLShapeUtilCanvasSvgDef,
|
|
212
175
|
type TLShapeUtilConstructor,
|
|
213
176
|
} from './lib/editor/shapes/ShapeUtil'
|
|
177
|
+
export {
|
|
178
|
+
getOverlayDisplayValues,
|
|
179
|
+
type OverlayOptionsWithDisplayValues,
|
|
180
|
+
} from './lib/editor/overlays/getOverlayDisplayValues'
|
|
181
|
+
export { OverlayManager, type TLOverlayEntry } from './lib/editor/overlays/OverlayManager'
|
|
182
|
+
export {
|
|
183
|
+
OverlayUtil,
|
|
184
|
+
type TLAnyOverlayUtilConstructor,
|
|
185
|
+
type TLOverlay,
|
|
186
|
+
type TLOverlayUtilConstructor,
|
|
187
|
+
} from './lib/editor/overlays/OverlayUtil'
|
|
188
|
+
export {
|
|
189
|
+
ShapeIndicatorOverlayUtil,
|
|
190
|
+
strokeShapeIndicators,
|
|
191
|
+
type TLShapeIndicatorOverlay,
|
|
192
|
+
} from './lib/editor/overlays/ShapeIndicatorOverlayUtil'
|
|
214
193
|
export {
|
|
215
194
|
getPerfectDashProps,
|
|
216
195
|
type PerfectDashTerminal,
|
|
@@ -345,7 +324,6 @@ export {
|
|
|
345
324
|
useUniqueSafeId,
|
|
346
325
|
type SafeId,
|
|
347
326
|
} from './lib/hooks/useSafeId'
|
|
348
|
-
export { useSelectionEvents } from './lib/hooks/useSelectionEvents'
|
|
349
327
|
export { useTLSchemaFromUtils, useTLStore } from './lib/hooks/useTLStore'
|
|
350
328
|
export { useTransform } from './lib/hooks/useTransform'
|
|
351
329
|
export { useViewportHeight } from './lib/hooks/useViewportHeight'
|
package/src/lib/TldrawEditor.tsx
CHANGED
|
@@ -33,6 +33,7 @@ import { TLAnyShapeUtilConstructor } from './config/defaultShapes'
|
|
|
33
33
|
import { TLEditorSnapshot } from './config/TLEditorSnapshot'
|
|
34
34
|
import { Editor } from './editor/Editor'
|
|
35
35
|
import { resolveThemes } from './editor/managers/ThemeManager/ThemeManager'
|
|
36
|
+
import { TLAnyOverlayUtilConstructor } from './editor/overlays/OverlayUtil'
|
|
36
37
|
import { TLStateNodeConstructor } from './editor/tools/StateNode'
|
|
37
38
|
import { TLCameraOptions } from './editor/types/misc-types'
|
|
38
39
|
import { useEditorComponents } from './hooks/EditorComponentsContext'
|
|
@@ -137,6 +138,11 @@ export interface TldrawEditorBaseProps {
|
|
|
137
138
|
*/
|
|
138
139
|
assetUtils?: readonly TLAnyAssetUtilConstructor[]
|
|
139
140
|
|
|
141
|
+
/**
|
|
142
|
+
* An array of overlay utils to use in the editor for canvas overlay UI elements.
|
|
143
|
+
*/
|
|
144
|
+
overlayUtils?: readonly TLAnyOverlayUtilConstructor[]
|
|
145
|
+
|
|
140
146
|
/**
|
|
141
147
|
* An array of tools to add to the editor's state chart.
|
|
142
148
|
*/
|
|
@@ -461,6 +467,7 @@ function TldrawEditorWithReadyStore({
|
|
|
461
467
|
shapeUtils,
|
|
462
468
|
bindingUtils,
|
|
463
469
|
assetUtils,
|
|
470
|
+
overlayUtils,
|
|
464
471
|
user,
|
|
465
472
|
initialState,
|
|
466
473
|
autoFocus = true,
|
|
@@ -532,6 +539,7 @@ function TldrawEditorWithReadyStore({
|
|
|
532
539
|
shapeUtils,
|
|
533
540
|
bindingUtils,
|
|
534
541
|
assetUtils,
|
|
542
|
+
overlayUtils,
|
|
535
543
|
tools,
|
|
536
544
|
getContainer: () => container,
|
|
537
545
|
user,
|
|
@@ -575,6 +583,7 @@ function TldrawEditorWithReadyStore({
|
|
|
575
583
|
colorScheme,
|
|
576
584
|
container,
|
|
577
585
|
options,
|
|
586
|
+
overlayUtils,
|
|
578
587
|
shapeUtils,
|
|
579
588
|
store,
|
|
580
589
|
tools,
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { EffectScheduler, computed } from '@tldraw/state'
|
|
2
|
+
import { memo, useEffect, useRef } from 'react'
|
|
3
|
+
import { useEditor } from '../../hooks/useEditor'
|
|
4
|
+
import { Geometry2d } from '../../primitives/geometry/Geometry2d'
|
|
5
|
+
import { Group2d } from '../../primitives/geometry/Group2d'
|
|
6
|
+
import { debugFlags } from '../../utils/debug-flags'
|
|
7
|
+
|
|
8
|
+
interface RenderInputs {
|
|
9
|
+
dpr: number
|
|
10
|
+
w: number
|
|
11
|
+
h: number
|
|
12
|
+
cx: number
|
|
13
|
+
cy: number
|
|
14
|
+
zoom: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** @internal @react */
|
|
18
|
+
export const CanvasOverlays = memo(function CanvasOverlays() {
|
|
19
|
+
const editor = useEditor()
|
|
20
|
+
const canvasRef = useRef<HTMLCanvasElement>(null)
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
// Bundle the primitive scalars the renderer needs into one computed so the
|
|
24
|
+
// effect only refires on actual visual change. Reading the whole instance
|
|
25
|
+
// state directly would otherwise wake the renderer on every cursor move,
|
|
26
|
+
// brush update, etc.
|
|
27
|
+
|
|
28
|
+
const renderInputs$ = computed<RenderInputs>(
|
|
29
|
+
'canvas overlays render inputs',
|
|
30
|
+
() => {
|
|
31
|
+
const instance = editor.getInstanceState()
|
|
32
|
+
const camera = editor.getCamera()
|
|
33
|
+
return {
|
|
34
|
+
dpr: instance.devicePixelRatio,
|
|
35
|
+
w: instance.screenBounds.w,
|
|
36
|
+
h: instance.screenBounds.h,
|
|
37
|
+
cx: camera.x,
|
|
38
|
+
cy: camera.y,
|
|
39
|
+
zoom: camera.z,
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
isEqual: (a, b) =>
|
|
44
|
+
a.dpr === b.dpr &&
|
|
45
|
+
a.w === b.w &&
|
|
46
|
+
a.h === b.h &&
|
|
47
|
+
a.cx === b.cx &&
|
|
48
|
+
a.cy === b.cy &&
|
|
49
|
+
a.zoom === b.zoom,
|
|
50
|
+
}
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
const scheduler = new EffectScheduler('canvas overlays render', () => {
|
|
54
|
+
const canvas = canvasRef.current
|
|
55
|
+
if (!canvas) return
|
|
56
|
+
|
|
57
|
+
const ctx = canvas.getContext('2d')
|
|
58
|
+
if (!ctx) return
|
|
59
|
+
|
|
60
|
+
const { dpr, w, h, cx, cy, zoom } = renderInputs$.get()
|
|
61
|
+
|
|
62
|
+
const canvasWidth = Math.ceil(w * dpr)
|
|
63
|
+
const canvasHeight = Math.ceil(h * dpr)
|
|
64
|
+
|
|
65
|
+
if (canvas.width !== canvasWidth || canvas.height !== canvasHeight) {
|
|
66
|
+
canvas.width = canvasWidth
|
|
67
|
+
canvas.height = canvasHeight
|
|
68
|
+
canvas.style.width = `${w}px`
|
|
69
|
+
canvas.style.height = `${h}px`
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
|
73
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
|
74
|
+
|
|
75
|
+
// One setTransform = DPR scale * zoom scale * camera translate, into page space.
|
|
76
|
+
const s = dpr * zoom
|
|
77
|
+
ctx.setTransform(s, 0, 0, s, s * cx, s * cy)
|
|
78
|
+
|
|
79
|
+
// Render all active overlay utils in zIndex order (low to high).
|
|
80
|
+
for (const { util, overlays } of editor.overlays.getActiveOverlayEntries()) {
|
|
81
|
+
ctx.save()
|
|
82
|
+
util.render(ctx, overlays)
|
|
83
|
+
ctx.restore()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Debug: draw all geometry
|
|
87
|
+
if (debugFlags.debugGeometry.get()) {
|
|
88
|
+
const currentPagePoint = editor.inputs.getCurrentPagePoint()
|
|
89
|
+
|
|
90
|
+
// Shape geometries
|
|
91
|
+
const renderingShapes = editor.getRenderingShapes()
|
|
92
|
+
for (const result of renderingShapes) {
|
|
93
|
+
const shape = editor.getShape(result.id)
|
|
94
|
+
if (!shape || shape.type === 'group') continue
|
|
95
|
+
|
|
96
|
+
const geometry = editor.getShapeGeometry(shape)
|
|
97
|
+
const pageTransform = editor.getShapePageTransform(shape)
|
|
98
|
+
if (!pageTransform) continue
|
|
99
|
+
|
|
100
|
+
ctx.save()
|
|
101
|
+
const m = pageTransform
|
|
102
|
+
ctx.transform(m.a, m.b, m.c, m.d, m.e, m.f)
|
|
103
|
+
|
|
104
|
+
// Outline
|
|
105
|
+
ctx.strokeStyle = geometry.debugColor ?? 'red'
|
|
106
|
+
ctx.lineWidth = 2 / zoom
|
|
107
|
+
ctx.fillStyle = 'none'
|
|
108
|
+
drawGeometryStroke(ctx, geometry)
|
|
109
|
+
|
|
110
|
+
// Vertices
|
|
111
|
+
const { vertices } = geometry
|
|
112
|
+
for (let i = 0; i < vertices.length; i++) {
|
|
113
|
+
const v = vertices[i]
|
|
114
|
+
const hue = vertices.length > 1 ? 120 + ((200 - 120) * i) / (vertices.length - 1) : 160
|
|
115
|
+
ctx.fillStyle = `hsl(${hue}, 100%, 50%)`
|
|
116
|
+
ctx.strokeStyle = 'black'
|
|
117
|
+
ctx.lineWidth = 1 / zoom
|
|
118
|
+
ctx.beginPath()
|
|
119
|
+
ctx.arc(v.x, v.y, 2 / zoom, 0, Math.PI * 2)
|
|
120
|
+
ctx.fill()
|
|
121
|
+
ctx.stroke()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Nearest point line
|
|
125
|
+
const pointInShapeSpace = editor.getPointInShapeSpace(shape, currentPagePoint)
|
|
126
|
+
const dist = Math.abs(geometry.distanceToPoint(pointInShapeSpace, true)) * zoom
|
|
127
|
+
if (dist < 150) {
|
|
128
|
+
const nearestPoint = geometry.nearestPoint(pointInShapeSpace)
|
|
129
|
+
const hitInside = geometry.distanceToPoint(pointInShapeSpace, true) < 0
|
|
130
|
+
ctx.strokeStyle = hitInside ? 'goldenrod' : 'dodgerblue'
|
|
131
|
+
ctx.lineWidth = 2 / zoom
|
|
132
|
+
ctx.globalAlpha = 1 - dist / 150
|
|
133
|
+
ctx.beginPath()
|
|
134
|
+
ctx.moveTo(nearestPoint.x, nearestPoint.y)
|
|
135
|
+
ctx.lineTo(pointInShapeSpace.x, pointInShapeSpace.y)
|
|
136
|
+
ctx.stroke()
|
|
137
|
+
ctx.globalAlpha = 1
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
ctx.restore()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Overlay hit-test geometries
|
|
144
|
+
ctx.save()
|
|
145
|
+
ctx.strokeStyle = 'magenta'
|
|
146
|
+
ctx.fillStyle = 'rgba(255, 0, 255, 0.1)'
|
|
147
|
+
ctx.lineWidth = 1 / zoom
|
|
148
|
+
for (const { overlays } of editor.overlays.getActiveOverlayEntries()) {
|
|
149
|
+
for (const overlay of overlays) {
|
|
150
|
+
const geometry = editor.overlays.getOverlayGeometry(overlay)
|
|
151
|
+
if (!geometry) continue
|
|
152
|
+
const vertices = geometry.vertices
|
|
153
|
+
if (vertices.length < 2) continue
|
|
154
|
+
ctx.beginPath()
|
|
155
|
+
ctx.moveTo(vertices[0].x, vertices[0].y)
|
|
156
|
+
for (let i = 1; i < vertices.length; i++) {
|
|
157
|
+
ctx.lineTo(vertices[i].x, vertices[i].y)
|
|
158
|
+
}
|
|
159
|
+
if (geometry.isClosed) {
|
|
160
|
+
ctx.closePath()
|
|
161
|
+
ctx.fill()
|
|
162
|
+
}
|
|
163
|
+
ctx.stroke()
|
|
164
|
+
for (const v of vertices) {
|
|
165
|
+
ctx.beginPath()
|
|
166
|
+
ctx.arc(v.x, v.y, 2 / zoom, 0, Math.PI * 2)
|
|
167
|
+
ctx.fill()
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
ctx.restore()
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
scheduler.attach()
|
|
176
|
+
scheduler.execute()
|
|
177
|
+
return () => scheduler.detach()
|
|
178
|
+
}, [editor])
|
|
179
|
+
|
|
180
|
+
return <canvas ref={canvasRef} className="tl-canvas-overlays" />
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
function drawGeometryStroke(ctx: CanvasRenderingContext2D, geometry: Geometry2d) {
|
|
184
|
+
if (geometry instanceof Group2d) {
|
|
185
|
+
const prevStroke = ctx.strokeStyle
|
|
186
|
+
for (const child of geometry.children) {
|
|
187
|
+
if (child.debugColor) ctx.strokeStyle = child.debugColor
|
|
188
|
+
drawGeometryStroke(ctx, child)
|
|
189
|
+
ctx.strokeStyle = prevStroke
|
|
190
|
+
}
|
|
191
|
+
for (const child of geometry.ignoredChildren) {
|
|
192
|
+
if (child.debugColor) ctx.strokeStyle = child.debugColor
|
|
193
|
+
drawGeometryStroke(ctx, child)
|
|
194
|
+
ctx.strokeStyle = prevStroke
|
|
195
|
+
}
|
|
196
|
+
return
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const vertices = geometry.vertices
|
|
200
|
+
if (vertices.length < 2) return
|
|
201
|
+
ctx.beginPath()
|
|
202
|
+
ctx.moveTo(vertices[0].x, vertices[0].y)
|
|
203
|
+
for (let i = 1; i < vertices.length; i++) {
|
|
204
|
+
ctx.lineTo(vertices[i].x, vertices[i].y)
|
|
205
|
+
}
|
|
206
|
+
if (geometry.isClosed) ctx.closePath()
|
|
207
|
+
ctx.stroke()
|
|
208
|
+
}
|