@tldraw/editor 3.12.0-canary.a6c2905c622f → 3.12.0-canary.a880bf3ec9cb
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 +158 -17
- package/dist-cjs/index.js +3 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +5 -0
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/GeometryDebuggingView.js +2 -2
- package/dist-cjs/lib/components/GeometryDebuggingView.js.map +2 -2
- package/dist-cjs/lib/components/Shape.js +10 -14
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +10 -1
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +224 -32
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +1 -1
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FocusManager.js +1 -1
- package/dist-cjs/lib/editor/managers/FocusManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FontManager.js +1 -1
- package/dist-cjs/lib/editor/managers/FontManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +12 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +4 -13
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/tools/StateNode.js +4 -1
- package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
- package/dist-cjs/lib/editor/types/selection-types.js.map +1 -1
- package/dist-cjs/lib/exports/StyleEmbedder.js +19 -5
- package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
- package/dist-cjs/lib/exports/cssRules.js +127 -0
- package/dist-cjs/lib/exports/cssRules.js.map +7 -0
- package/dist-cjs/lib/exports/parseCss.js +0 -69
- package/dist-cjs/lib/exports/parseCss.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +13 -8
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +3 -3
- package/dist-cjs/lib/hooks/useDocumentEvents.js +16 -0
- package/dist-cjs/lib/hooks/useDocumentEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useGestureEvents.js +12 -6
- package/dist-cjs/lib/hooks/useGestureEvents.js.map +2 -2
- package/dist-cjs/lib/license/Watermark.js +10 -20
- package/dist-cjs/lib/license/Watermark.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js +133 -16
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +3 -3
- package/dist-cjs/lib/primitives/geometry/Group2d.js +53 -10
- package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
- package/dist-cjs/lib/primitives/intersect.js +20 -0
- package/dist-cjs/lib/primitives/intersect.js.map +2 -2
- package/dist-cjs/lib/utils/debug-flags.js +2 -1
- package/dist-cjs/lib/utils/debug-flags.js.map +2 -2
- package/dist-cjs/lib/utils/reorderShapes.js +2 -8
- package/dist-cjs/lib/utils/reorderShapes.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +158 -17
- package/dist-esm/index.mjs +8 -2
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +5 -0
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/GeometryDebuggingView.mjs +3 -3
- package/dist-esm/lib/components/GeometryDebuggingView.mjs.map +2 -2
- package/dist-esm/lib/components/Shape.mjs +11 -15
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +10 -1
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +225 -32
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +1 -1
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FocusManager.mjs +1 -1
- package/dist-esm/lib/editor/managers/FocusManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FontManager.mjs +1 -1
- package/dist-esm/lib/editor/managers/FontManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +12 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +4 -13
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/StateNode.mjs +4 -1
- package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
- package/dist-esm/lib/exports/StyleEmbedder.mjs +21 -12
- package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
- package/dist-esm/lib/exports/cssRules.mjs +107 -0
- package/dist-esm/lib/exports/cssRules.mjs.map +7 -0
- package/dist-esm/lib/exports/parseCss.mjs +0 -69
- package/dist-esm/lib/exports/parseCss.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +13 -8
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +3 -3
- package/dist-esm/lib/hooks/useDocumentEvents.mjs +16 -0
- package/dist-esm/lib/hooks/useDocumentEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useGestureEvents.mjs +12 -6
- package/dist-esm/lib/hooks/useGestureEvents.mjs.map +2 -2
- package/dist-esm/lib/license/Watermark.mjs +10 -20
- package/dist-esm/lib/license/Watermark.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +137 -14
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Group2d.mjs +54 -11
- package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/intersect.mjs +20 -0
- package/dist-esm/lib/primitives/intersect.mjs.map +2 -2
- package/dist-esm/lib/utils/debug-flags.mjs +2 -1
- package/dist-esm/lib/utils/debug-flags.mjs.map +2 -2
- package/dist-esm/lib/utils/reorderShapes.mjs +2 -8
- package/dist-esm/lib/utils/reorderShapes.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +51 -30
- package/package.json +7 -7
- package/src/index.ts +11 -2
- package/src/lib/TldrawEditor.tsx +30 -3
- package/src/lib/components/GeometryDebuggingView.tsx +3 -3
- package/src/lib/components/Shape.tsx +15 -19
- package/src/lib/components/default-components/DefaultCanvas.tsx +6 -1
- package/src/lib/editor/Editor.ts +334 -39
- package/src/lib/editor/derivations/notVisibleShapes.ts +1 -1
- package/src/lib/editor/managers/FocusManager.ts +1 -1
- package/src/lib/editor/managers/FontManager.ts +1 -1
- package/src/lib/editor/shapes/ShapeUtil.ts +14 -0
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +7 -15
- package/src/lib/editor/tools/StateNode.ts +6 -1
- package/src/lib/editor/types/selection-types.ts +3 -0
- package/src/lib/exports/StyleEmbedder.ts +25 -15
- package/src/lib/exports/cssRules.ts +126 -0
- package/src/lib/exports/parseCss.ts +0 -79
- package/src/lib/hooks/useCanvasEvents.ts +15 -8
- package/src/lib/hooks/useDocumentEvents.ts +18 -0
- package/src/lib/hooks/useGestureEvents.ts +12 -6
- package/src/lib/license/Watermark.tsx +18 -29
- package/src/lib/primitives/geometry/Geometry2d.ts +196 -16
- package/src/lib/primitives/geometry/Group2d.ts +75 -12
- package/src/lib/primitives/intersect.ts +41 -0
- package/src/lib/utils/debug-flags.ts +1 -0
- package/src/lib/utils/reorderShapes.ts +2 -9
- package/src/version.ts +3 -3
package/src/index.ts
CHANGED
|
@@ -293,7 +293,11 @@ export {
|
|
|
293
293
|
type TLSvgExportOptions,
|
|
294
294
|
type TLSvgOptions,
|
|
295
295
|
} from './lib/editor/types/misc-types'
|
|
296
|
-
export {
|
|
296
|
+
export {
|
|
297
|
+
type TLAdjacentDirection,
|
|
298
|
+
type TLResizeHandle,
|
|
299
|
+
type TLSelectionHandle,
|
|
300
|
+
} from './lib/editor/types/selection-types'
|
|
297
301
|
export { getSvgAsImage } from './lib/exports/getSvgAsImage'
|
|
298
302
|
export { tlenv } from './lib/globals/environment'
|
|
299
303
|
export { tlmenus } from './lib/globals/menus'
|
|
@@ -360,7 +364,12 @@ export { CubicBezier2d } from './lib/primitives/geometry/CubicBezier2d'
|
|
|
360
364
|
export { CubicSpline2d } from './lib/primitives/geometry/CubicSpline2d'
|
|
361
365
|
export { Edge2d } from './lib/primitives/geometry/Edge2d'
|
|
362
366
|
export { Ellipse2d } from './lib/primitives/geometry/Ellipse2d'
|
|
363
|
-
export {
|
|
367
|
+
export {
|
|
368
|
+
Geometry2d,
|
|
369
|
+
Geometry2dFilters,
|
|
370
|
+
TransformedGeometry2d,
|
|
371
|
+
type Geometry2dOptions,
|
|
372
|
+
} from './lib/primitives/geometry/Geometry2d'
|
|
364
373
|
export { Group2d } from './lib/primitives/geometry/Group2d'
|
|
365
374
|
export { Point2d } from './lib/primitives/geometry/Point2d'
|
|
366
375
|
export { Polygon2d } from './lib/primitives/geometry/Polygon2d'
|
package/src/lib/TldrawEditor.tsx
CHANGED
|
@@ -50,7 +50,7 @@ import { TLStoreWithStatus } from './utils/sync/StoreWithStatus'
|
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components, when passing in a
|
|
53
|
-
*
|
|
53
|
+
* `TLStore` directly. If you would like tldraw to create a store for you, use
|
|
54
54
|
* {@link TldrawEditorWithoutStoreProps}.
|
|
55
55
|
*
|
|
56
56
|
* @public
|
|
@@ -64,7 +64,7 @@ export interface TldrawEditorWithStoreProps {
|
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components, when not passing in a
|
|
67
|
-
*
|
|
67
|
+
* `TLStore` directly. If you would like to pass in a store directly, use
|
|
68
68
|
* {@link TldrawEditorWithStoreProps}.
|
|
69
69
|
*
|
|
70
70
|
* @public
|
|
@@ -191,11 +191,33 @@ export interface TldrawEditorBaseProps {
|
|
|
191
191
|
/**
|
|
192
192
|
* Predicate for whether or not a shape should be hidden.
|
|
193
193
|
*
|
|
194
|
+
* @deprecated Use {@link TldrawEditorBaseProps#getShapeVisibility} instead.
|
|
195
|
+
*/
|
|
196
|
+
isShapeHidden?(shape: TLShape, editor: Editor): boolean
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Provides a way to hide shapes.
|
|
200
|
+
*
|
|
194
201
|
* Hidden shapes will not render in the editor, and they will not be eligible for hit test via
|
|
195
202
|
* {@link Editor#getShapeAtPoint} and {@link Editor#getShapesAtPoint}. But otherwise they will
|
|
196
203
|
* remain in the store and participate in all other operations.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* getShapeVisibility={(shape, editor) => shape.meta.hidden ? 'hidden' : 'inherit'}
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* - `'inherit' | undefined` - (default) The shape will be visible unless its parent is hidden.
|
|
211
|
+
* - `'hidden'` - The shape will be hidden.
|
|
212
|
+
* - `'visible'` - The shape will be visible.
|
|
213
|
+
*
|
|
214
|
+
* @param shape - The shape to check.
|
|
215
|
+
* @param editor - The editor instance.
|
|
197
216
|
*/
|
|
198
|
-
|
|
217
|
+
getShapeVisibility?(
|
|
218
|
+
shape: TLShape,
|
|
219
|
+
editor: Editor
|
|
220
|
+
): 'visible' | 'hidden' | 'inherit' | null | undefined
|
|
199
221
|
|
|
200
222
|
/**
|
|
201
223
|
* The URLs for the fonts to use in the editor.
|
|
@@ -262,6 +284,7 @@ export const TldrawEditor = memo(function TldrawEditor({
|
|
|
262
284
|
className={classNames(`${TL_CONTAINER_CLASS} tl-theme__light`, className)}
|
|
263
285
|
onPointerDown={stopEventPropagation}
|
|
264
286
|
tabIndex={-1}
|
|
287
|
+
role="application"
|
|
265
288
|
>
|
|
266
289
|
<OptionalErrorBoundary
|
|
267
290
|
fallback={ErrorFallback}
|
|
@@ -387,7 +410,9 @@ function TldrawEditorWithReadyStore({
|
|
|
387
410
|
options,
|
|
388
411
|
licenseKey,
|
|
389
412
|
deepLinks: _deepLinks,
|
|
413
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
390
414
|
isShapeHidden,
|
|
415
|
+
getShapeVisibility,
|
|
391
416
|
assetUrls,
|
|
392
417
|
}: Required<
|
|
393
418
|
TldrawEditorProps & {
|
|
@@ -447,6 +472,7 @@ function TldrawEditorWithReadyStore({
|
|
|
447
472
|
options,
|
|
448
473
|
licenseKey,
|
|
449
474
|
isShapeHidden,
|
|
475
|
+
getShapeVisibility,
|
|
450
476
|
fontAssetUrls: assetUrls?.fonts,
|
|
451
477
|
})
|
|
452
478
|
|
|
@@ -482,6 +508,7 @@ function TldrawEditorWithReadyStore({
|
|
|
482
508
|
setEditor,
|
|
483
509
|
licenseKey,
|
|
484
510
|
isShapeHidden,
|
|
511
|
+
getShapeVisibility,
|
|
485
512
|
textOptions,
|
|
486
513
|
assetUrls,
|
|
487
514
|
]
|
|
@@ -114,13 +114,13 @@ export const GeometryDebuggingView = track(function GeometryDebuggingView({
|
|
|
114
114
|
function GeometryStroke({ geometry }: { geometry: Geometry2d }) {
|
|
115
115
|
if (geometry instanceof Group2d) {
|
|
116
116
|
return (
|
|
117
|
-
|
|
117
|
+
<g stroke={geometry.debugColor}>
|
|
118
118
|
{[...geometry.children, ...geometry.ignoredChildren].map((child, i) => (
|
|
119
119
|
<GeometryStroke geometry={child} key={i} />
|
|
120
120
|
))}
|
|
121
|
-
|
|
121
|
+
</g>
|
|
122
122
|
)
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
return <path d={geometry.toSimpleSvgPath()} />
|
|
125
|
+
return <path d={geometry.toSimpleSvgPath()} stroke={geometry.debugColor} />
|
|
126
126
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { react } from '@tldraw/state'
|
|
2
2
|
import { useQuickReactor, useStateTracking } from '@tldraw/state-react'
|
|
3
3
|
import { TLShape, TLShapeId } from '@tldraw/tlschema'
|
|
4
|
-
import { memo, useCallback, useEffect, useRef } from 'react'
|
|
4
|
+
import { memo, useCallback, useEffect, useLayoutEffect, useRef } from 'react'
|
|
5
5
|
import { ShapeUtil } from '../editor/shapes/ShapeUtil'
|
|
6
6
|
import { useEditor } from '../hooks/useEditor'
|
|
7
7
|
import { useEditorComponents } from '../hooks/useEditorComponents'
|
|
@@ -44,10 +44,10 @@ export const Shape = memo(function Shape({
|
|
|
44
44
|
|
|
45
45
|
useEffect(() => {
|
|
46
46
|
return react('load fonts', () => {
|
|
47
|
-
const fonts = editor.fonts.getShapeFontFaces(
|
|
47
|
+
const fonts = editor.fonts.getShapeFontFaces(id)
|
|
48
48
|
editor.fonts.requestFonts(fonts)
|
|
49
49
|
})
|
|
50
|
-
}, [editor,
|
|
50
|
+
}, [editor, id])
|
|
51
51
|
|
|
52
52
|
const memoizedStuffRef = useRef({
|
|
53
53
|
transform: '',
|
|
@@ -104,22 +104,18 @@ export const Shape = memo(function Shape({
|
|
|
104
104
|
)
|
|
105
105
|
|
|
106
106
|
// This stuff changes pretty infrequently, so we can change them together
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
setStyleProperty(bgContainer, 'z-index', backgroundIndex)
|
|
120
|
-
},
|
|
121
|
-
[opacity, index, backgroundIndex]
|
|
122
|
-
)
|
|
107
|
+
useLayoutEffect(() => {
|
|
108
|
+
const container = containerRef.current
|
|
109
|
+
const bgContainer = bgContainerRef.current
|
|
110
|
+
|
|
111
|
+
// Opacity
|
|
112
|
+
setStyleProperty(container, 'opacity', opacity)
|
|
113
|
+
setStyleProperty(bgContainer, 'opacity', opacity)
|
|
114
|
+
|
|
115
|
+
// Z-Index
|
|
116
|
+
setStyleProperty(container, 'z-index', index)
|
|
117
|
+
setStyleProperty(bgContainer, 'z-index', backgroundIndex)
|
|
118
|
+
}, [opacity, index, backgroundIndex])
|
|
123
119
|
|
|
124
120
|
useQuickReactor(
|
|
125
121
|
'set display',
|
|
@@ -361,7 +361,12 @@ function HandleWrapper({
|
|
|
361
361
|
if (!Handle) return null
|
|
362
362
|
|
|
363
363
|
return (
|
|
364
|
-
<g
|
|
364
|
+
<g
|
|
365
|
+
role="button"
|
|
366
|
+
aria-label="handle"
|
|
367
|
+
transform={`translate(${handle.x}, ${handle.y})`}
|
|
368
|
+
{...events}
|
|
369
|
+
>
|
|
365
370
|
<Handle shapeId={shapeId} handle={handle} zoom={zoom} isCoarse={isCoarse} />
|
|
366
371
|
</g>
|
|
367
372
|
)
|