@tldraw/editor 3.15.0 → 3.16.0-next.c30b1b5e551a
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 +101 -0
- package/dist-cjs/index.js +3 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/components/Shape.js +4 -26
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js +53 -0
- package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js.map +7 -0
- package/dist-cjs/lib/editor/Editor.js +64 -35
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
- package/dist-cjs/lib/hooks/useEditorComponents.js +2 -0
- package/dist-cjs/lib/hooks/useEditorComponents.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 +101 -0
- package/dist-esm/index.mjs +5 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/components/Shape.mjs +4 -26
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs +23 -0
- package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs.map +7 -0
- package/dist-esm/lib/editor/Editor.mjs +64 -35
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditorComponents.mjs +4 -0
- package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +4 -23
- package/package.json +7 -7
- package/src/index.ts +5 -0
- package/src/lib/components/Shape.tsx +6 -21
- package/src/lib/components/default-components/DefaultShapeWrapper.tsx +35 -0
- package/src/lib/editor/Editor.ts +71 -35
- package/src/lib/editor/shapes/ShapeUtil.ts +57 -0
- package/src/lib/editor/types/misc-types.ts +19 -0
- package/src/lib/hooks/useEditorComponents.tsx +7 -1
- package/src/version.ts +3 -3
|
@@ -18,7 +18,7 @@ const Shape = memo(function Shape2({
|
|
|
18
18
|
dprMultiple
|
|
19
19
|
}) {
|
|
20
20
|
const editor = useEditor();
|
|
21
|
-
const { ShapeErrorFallback } = useEditorComponents();
|
|
21
|
+
const { ShapeErrorFallback, ShapeWrapper } = useEditorComponents();
|
|
22
22
|
const containerRef = useRef(null);
|
|
23
23
|
const bgContainerRef = useRef(null);
|
|
24
24
|
useEffect(() => {
|
|
@@ -98,32 +98,10 @@ const Shape = memo(function Shape2({
|
|
|
98
98
|
(error) => editor.annotateError(error, { origin: "shape", willCrashApp: false }),
|
|
99
99
|
[editor]
|
|
100
100
|
);
|
|
101
|
-
if (!shape) return null;
|
|
102
|
-
const isFilledShape = "fill" in shape.props && shape.props.fill !== "none";
|
|
101
|
+
if (!shape || !ShapeWrapper) return null;
|
|
103
102
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
104
|
-
util.backgroundComponent && /* @__PURE__ */ jsx(
|
|
105
|
-
|
|
106
|
-
{
|
|
107
|
-
ref: bgContainerRef,
|
|
108
|
-
className: "tl-shape tl-shape-background",
|
|
109
|
-
"data-shape-type": shape.type,
|
|
110
|
-
"data-shape-id": shape.id,
|
|
111
|
-
draggable: false,
|
|
112
|
-
children: /* @__PURE__ */ jsx(OptionalErrorBoundary, { fallback: ShapeErrorFallback, onError: annotateError, children: /* @__PURE__ */ jsx(InnerShapeBackground, { shape, util }) })
|
|
113
|
-
}
|
|
114
|
-
),
|
|
115
|
-
/* @__PURE__ */ jsx(
|
|
116
|
-
"div",
|
|
117
|
-
{
|
|
118
|
-
ref: containerRef,
|
|
119
|
-
className: "tl-shape",
|
|
120
|
-
"data-shape-type": shape.type,
|
|
121
|
-
"data-shape-is-filled": isFilledShape,
|
|
122
|
-
"data-shape-id": shape.id,
|
|
123
|
-
draggable: false,
|
|
124
|
-
children: /* @__PURE__ */ jsx(OptionalErrorBoundary, { fallback: ShapeErrorFallback, onError: annotateError, children: /* @__PURE__ */ jsx(InnerShape, { shape, util }) })
|
|
125
|
-
}
|
|
126
|
-
)
|
|
103
|
+
util.backgroundComponent && /* @__PURE__ */ jsx(ShapeWrapper, { ref: bgContainerRef, shape, isBackground: true, children: /* @__PURE__ */ jsx(OptionalErrorBoundary, { fallback: ShapeErrorFallback, onError: annotateError, children: /* @__PURE__ */ jsx(InnerShapeBackground, { shape, util }) }) }),
|
|
104
|
+
/* @__PURE__ */ jsx(ShapeWrapper, { ref: containerRef, shape, isBackground: false, children: /* @__PURE__ */ jsx(OptionalErrorBoundary, { fallback: ShapeErrorFallback, onError: annotateError, children: /* @__PURE__ */ jsx(InnerShape, { shape, util }) }) })
|
|
127
105
|
] });
|
|
128
106
|
});
|
|
129
107
|
const InnerShape = memo(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/components/Shape.tsx"],
|
|
4
|
-
"sourcesContent": ["import { react } from '@tldraw/state'\nimport { useQuickReactor, useStateTracking } from '@tldraw/state-react'\nimport { TLShape, TLShapeId } from '@tldraw/tlschema'\nimport { memo, useCallback, useEffect, useLayoutEffect, useRef } from 'react'\nimport { ShapeUtil } from '../editor/shapes/ShapeUtil'\nimport { useEditor } from '../hooks/useEditor'\nimport { useEditorComponents } from '../hooks/useEditorComponents'\nimport { Mat } from '../primitives/Mat'\nimport { areShapesContentEqual } from '../utils/areShapesContentEqual'\nimport { setStyleProperty } from '../utils/dom'\nimport { OptionalErrorBoundary } from './ErrorBoundary'\n\n/*\nThis component renders shapes on the canvas. There are two stages: positioning\nand styling the shape's container using CSS, and then rendering the shape's \nJSX using its shape util's render method. Rendering the \"inside\" of a shape is\nmore expensive than positioning it or changing its color, so we use memo\nto wrap the inner shape and only re-render it when the shape's props change. \n\nThe shape also receives props for its index and opacity. The index is used to\ndetermine the z-index of the shape, and the opacity is used to set the shape's\nopacity based on its own opacity and that of its parent's.\n*/\nexport const Shape = memo(function Shape({\n\tid,\n\tshape,\n\tutil,\n\tindex,\n\tbackgroundIndex,\n\topacity,\n\tdprMultiple,\n}: {\n\tid: TLShapeId\n\tshape: TLShape\n\tutil: ShapeUtil\n\tindex: number\n\tbackgroundIndex: number\n\topacity: number\n\tdprMultiple: number\n}) {\n\tconst editor = useEditor()\n\n\tconst { ShapeErrorFallback } = useEditorComponents()\n\n\tconst containerRef = useRef<HTMLDivElement>(null)\n\tconst bgContainerRef = useRef<HTMLDivElement>(null)\n\n\tuseEffect(() => {\n\t\treturn react('load fonts', () => {\n\t\t\tconst fonts = editor.fonts.getShapeFontFaces(id)\n\t\t\teditor.fonts.requestFonts(fonts)\n\t\t})\n\t}, [editor, id])\n\n\tconst memoizedStuffRef = useRef({\n\t\ttransform: '',\n\t\tclipPath: 'none',\n\t\twidth: 0,\n\t\theight: 0,\n\t\tx: 0,\n\t\ty: 0,\n\t\tisCulled: false,\n\t})\n\n\tuseQuickReactor(\n\t\t'set shape stuff',\n\t\t() => {\n\t\t\tconst shape = editor.getShape(id)\n\t\t\tif (!shape) return // probably the shape was just deleted\n\n\t\t\tconst prev = memoizedStuffRef.current\n\n\t\t\t// Clip path\n\t\t\tconst clipPath = editor.getShapeClipPath(id) ?? 'none'\n\t\t\tif (clipPath !== prev.clipPath) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'clip-path', clipPath)\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'clip-path', clipPath)\n\t\t\t\tprev.clipPath = clipPath\n\t\t\t}\n\n\t\t\t// Page transform\n\t\t\tconst pageTransform = editor.getShapePageTransform(id)\n\t\t\tconst transform = Mat.toCssString(pageTransform)\n\t\t\tconst bounds = editor.getShapeGeometry(shape).bounds\n\n\t\t\t// Update if the tranform has changed\n\t\t\tif (transform !== prev.transform) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'transform', transform)\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'transform', transform)\n\t\t\t\tprev.transform = transform\n\t\t\t}\n\n\t\t\t// Width / Height\n\t\t\t// We round the shape width and height up to the nearest multiple of dprMultiple\n\t\t\t// to avoid the browser making miscalculations when applying the transform.\n\t\t\tconst widthRemainder = bounds.w % dprMultiple\n\t\t\tconst heightRemainder = bounds.h % dprMultiple\n\t\t\tconst width = widthRemainder === 0 ? bounds.w : bounds.w + (dprMultiple - widthRemainder)\n\t\t\tconst height = heightRemainder === 0 ? bounds.h : bounds.h + (dprMultiple - heightRemainder)\n\n\t\t\tif (width !== prev.width || height !== prev.height) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'width', Math.max(width, dprMultiple) + 'px')\n\t\t\t\tsetStyleProperty(containerRef.current, 'height', Math.max(height, dprMultiple) + 'px')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'width', Math.max(width, dprMultiple) + 'px')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'height', Math.max(height, dprMultiple) + 'px')\n\t\t\t\tprev.width = width\n\t\t\t\tprev.height = height\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n\n\t// This stuff changes pretty infrequently, so we can change them together\n\tuseLayoutEffect(() => {\n\t\tconst container = containerRef.current\n\t\tconst bgContainer = bgContainerRef.current\n\n\t\t// Opacity\n\t\tsetStyleProperty(container, 'opacity', opacity)\n\t\tsetStyleProperty(bgContainer, 'opacity', opacity)\n\n\t\t// Z-Index\n\t\tsetStyleProperty(container, 'z-index', index)\n\t\tsetStyleProperty(bgContainer, 'z-index', backgroundIndex)\n\t}, [opacity, index, backgroundIndex])\n\n\tuseQuickReactor(\n\t\t'set display',\n\t\t() => {\n\t\t\tconst shape = editor.getShape(id)\n\t\t\tif (!shape) return // probably the shape was just deleted\n\n\t\t\tconst culledShapes = editor.getCulledShapes()\n\t\t\tconst isCulled = culledShapes.has(id)\n\t\t\tif (isCulled !== memoizedStuffRef.current.isCulled) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'display', isCulled ? 'none' : 'block')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'display', isCulled ? 'none' : 'block')\n\t\t\t\tmemoizedStuffRef.current.isCulled = isCulled\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n\tconst annotateError = useCallback(\n\t\t(error: any) => editor.annotateError(error, { origin: 'shape', willCrashApp: false }),\n\t\t[editor]\n\t)\n\n\tif (!shape) return null\n\n\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { react } from '@tldraw/state'\nimport { useQuickReactor, useStateTracking } from '@tldraw/state-react'\nimport { TLShape, TLShapeId } from '@tldraw/tlschema'\nimport { memo, useCallback, useEffect, useLayoutEffect, useRef } from 'react'\nimport { ShapeUtil } from '../editor/shapes/ShapeUtil'\nimport { useEditor } from '../hooks/useEditor'\nimport { useEditorComponents } from '../hooks/useEditorComponents'\nimport { Mat } from '../primitives/Mat'\nimport { areShapesContentEqual } from '../utils/areShapesContentEqual'\nimport { setStyleProperty } from '../utils/dom'\nimport { OptionalErrorBoundary } from './ErrorBoundary'\n\n/*\nThis component renders shapes on the canvas. There are two stages: positioning\nand styling the shape's container using CSS, and then rendering the shape's \nJSX using its shape util's render method. Rendering the \"inside\" of a shape is\nmore expensive than positioning it or changing its color, so we use memo\nto wrap the inner shape and only re-render it when the shape's props change. \n\nThe shape also receives props for its index and opacity. The index is used to\ndetermine the z-index of the shape, and the opacity is used to set the shape's\nopacity based on its own opacity and that of its parent's.\n*/\nexport const Shape = memo(function Shape({\n\tid,\n\tshape,\n\tutil,\n\tindex,\n\tbackgroundIndex,\n\topacity,\n\tdprMultiple,\n}: {\n\tid: TLShapeId\n\tshape: TLShape\n\tutil: ShapeUtil\n\tindex: number\n\tbackgroundIndex: number\n\topacity: number\n\tdprMultiple: number\n}) {\n\tconst editor = useEditor()\n\n\tconst { ShapeErrorFallback, ShapeWrapper } = useEditorComponents()\n\n\tconst containerRef = useRef<HTMLDivElement>(null)\n\tconst bgContainerRef = useRef<HTMLDivElement>(null)\n\n\tuseEffect(() => {\n\t\treturn react('load fonts', () => {\n\t\t\tconst fonts = editor.fonts.getShapeFontFaces(id)\n\t\t\teditor.fonts.requestFonts(fonts)\n\t\t})\n\t}, [editor, id])\n\n\tconst memoizedStuffRef = useRef({\n\t\ttransform: '',\n\t\tclipPath: 'none',\n\t\twidth: 0,\n\t\theight: 0,\n\t\tx: 0,\n\t\ty: 0,\n\t\tisCulled: false,\n\t})\n\n\tuseQuickReactor(\n\t\t'set shape stuff',\n\t\t() => {\n\t\t\tconst shape = editor.getShape(id)\n\t\t\tif (!shape) return // probably the shape was just deleted\n\n\t\t\tconst prev = memoizedStuffRef.current\n\n\t\t\t// Clip path\n\t\t\tconst clipPath = editor.getShapeClipPath(id) ?? 'none'\n\t\t\tif (clipPath !== prev.clipPath) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'clip-path', clipPath)\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'clip-path', clipPath)\n\t\t\t\tprev.clipPath = clipPath\n\t\t\t}\n\n\t\t\t// Page transform\n\t\t\tconst pageTransform = editor.getShapePageTransform(id)\n\t\t\tconst transform = Mat.toCssString(pageTransform)\n\t\t\tconst bounds = editor.getShapeGeometry(shape).bounds\n\n\t\t\t// Update if the tranform has changed\n\t\t\tif (transform !== prev.transform) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'transform', transform)\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'transform', transform)\n\t\t\t\tprev.transform = transform\n\t\t\t}\n\n\t\t\t// Width / Height\n\t\t\t// We round the shape width and height up to the nearest multiple of dprMultiple\n\t\t\t// to avoid the browser making miscalculations when applying the transform.\n\t\t\tconst widthRemainder = bounds.w % dprMultiple\n\t\t\tconst heightRemainder = bounds.h % dprMultiple\n\t\t\tconst width = widthRemainder === 0 ? bounds.w : bounds.w + (dprMultiple - widthRemainder)\n\t\t\tconst height = heightRemainder === 0 ? bounds.h : bounds.h + (dprMultiple - heightRemainder)\n\n\t\t\tif (width !== prev.width || height !== prev.height) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'width', Math.max(width, dprMultiple) + 'px')\n\t\t\t\tsetStyleProperty(containerRef.current, 'height', Math.max(height, dprMultiple) + 'px')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'width', Math.max(width, dprMultiple) + 'px')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'height', Math.max(height, dprMultiple) + 'px')\n\t\t\t\tprev.width = width\n\t\t\t\tprev.height = height\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n\n\t// This stuff changes pretty infrequently, so we can change them together\n\tuseLayoutEffect(() => {\n\t\tconst container = containerRef.current\n\t\tconst bgContainer = bgContainerRef.current\n\n\t\t// Opacity\n\t\tsetStyleProperty(container, 'opacity', opacity)\n\t\tsetStyleProperty(bgContainer, 'opacity', opacity)\n\n\t\t// Z-Index\n\t\tsetStyleProperty(container, 'z-index', index)\n\t\tsetStyleProperty(bgContainer, 'z-index', backgroundIndex)\n\t}, [opacity, index, backgroundIndex])\n\n\tuseQuickReactor(\n\t\t'set display',\n\t\t() => {\n\t\t\tconst shape = editor.getShape(id)\n\t\t\tif (!shape) return // probably the shape was just deleted\n\n\t\t\tconst culledShapes = editor.getCulledShapes()\n\t\t\tconst isCulled = culledShapes.has(id)\n\t\t\tif (isCulled !== memoizedStuffRef.current.isCulled) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'display', isCulled ? 'none' : 'block')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'display', isCulled ? 'none' : 'block')\n\t\t\t\tmemoizedStuffRef.current.isCulled = isCulled\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n\tconst annotateError = useCallback(\n\t\t(error: any) => editor.annotateError(error, { origin: 'shape', willCrashApp: false }),\n\t\t[editor]\n\t)\n\n\tif (!shape || !ShapeWrapper) return null\n\n\treturn (\n\t\t<>\n\t\t\t{util.backgroundComponent && (\n\t\t\t\t<ShapeWrapper ref={bgContainerRef} shape={shape} isBackground={true}>\n\t\t\t\t\t<OptionalErrorBoundary fallback={ShapeErrorFallback} onError={annotateError}>\n\t\t\t\t\t\t<InnerShapeBackground shape={shape} util={util} />\n\t\t\t\t\t</OptionalErrorBoundary>\n\t\t\t\t</ShapeWrapper>\n\t\t\t)}\n\t\t\t<ShapeWrapper ref={containerRef} shape={shape} isBackground={false}>\n\t\t\t\t<OptionalErrorBoundary fallback={ShapeErrorFallback as any} onError={annotateError}>\n\t\t\t\t\t<InnerShape shape={shape} util={util} />\n\t\t\t\t</OptionalErrorBoundary>\n\t\t\t</ShapeWrapper>\n\t\t</>\n\t)\n})\n\nexport const InnerShape = memo(\n\tfunction InnerShape<T extends TLShape>({ shape, util }: { shape: T; util: ShapeUtil<T> }) {\n\t\treturn useStateTracking(\n\t\t\t'InnerShape:' + shape.type,\n\t\t\t() =>\n\t\t\t\t// always fetch the latest shape from the store even if the props/meta have not changed, to avoid\n\t\t\t\t// calling the render method with stale data.\n\t\t\t\tutil.component(util.editor.store.unsafeGetWithoutCapture(shape.id) as T),\n\t\t\t[util, shape.id]\n\t\t)\n\t},\n\t(prev, next) => areShapesContentEqual(prev.shape, next.shape) && prev.util === next.util\n)\n\nexport const InnerShapeBackground = memo(\n\tfunction InnerShapeBackground<T extends TLShape>({\n\t\tshape,\n\t\tutil,\n\t}: {\n\t\tshape: T\n\t\tutil: ShapeUtil<T>\n\t}) {\n\t\treturn useStateTracking(\n\t\t\t'InnerShape:' + shape.type,\n\t\t\t() =>\n\t\t\t\t// always fetch the latest shape from the store even if the props/meta have not changed, to avoid\n\t\t\t\t// calling the render method with stale data.\n\t\t\t\tutil.backgroundComponent?.(util.editor.store.unsafeGetWithoutCapture(shape.id) as T),\n\t\t\t[util, shape.id]\n\t\t)\n\t},\n\t(prev, next) =>\n\t\tprev.shape.props === next.shape.props &&\n\t\tprev.shape.meta === next.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N,gBAAgB,MAAM;AAAA,MACtB;AAAA;AAAA;AAAA,QAGC,KAAK,sBAAsB,KAAK,OAAO,MAAM,wBAAwB,MAAM,EAAE,CAAM;AAAA;AAAA,MACpF,CAAC,MAAM,MAAM,EAAE;AAAA,IAChB;AAAA,EACD;AAAA,EACA,CAAC,MAAM,SACN,KAAK,MAAM,UAAU,KAAK,MAAM,SAChC,KAAK,MAAM,SAAS,KAAK,MAAM,QAC/B,KAAK,SAAS,KAAK;AACrB;",
|
|
6
6
|
"names": ["Shape", "shape", "InnerShape", "InnerShapeBackground"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import classNames from "classnames";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
const DefaultShapeWrapper = forwardRef(function DefaultShapeWrapper2({ children, shape, isBackground, ...props }, ref) {
|
|
5
|
+
const isFilledShape = "fill" in shape.props && shape.props.fill !== "none";
|
|
6
|
+
return /* @__PURE__ */ jsx(
|
|
7
|
+
"div",
|
|
8
|
+
{
|
|
9
|
+
ref,
|
|
10
|
+
"data-shape-type": shape.type,
|
|
11
|
+
"data-shape-is-filled": isBackground ? void 0 : isFilledShape,
|
|
12
|
+
"data-shape-id": shape.id,
|
|
13
|
+
draggable: false,
|
|
14
|
+
...props,
|
|
15
|
+
className: classNames("tl-shape", isBackground && "tl-shape-background", props.className),
|
|
16
|
+
children
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
export {
|
|
21
|
+
DefaultShapeWrapper
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=DefaultShapeWrapper.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/lib/components/default-components/DefaultShapeWrapper.tsx"],
|
|
4
|
+
"sourcesContent": ["import { TLShape } from '@tldraw/tlschema'\nimport classNames from 'classnames'\nimport { forwardRef, ReactNode } from 'react'\n\n/** @public */\nexport interface TLShapeWrapperProps extends React.HTMLAttributes<HTMLDivElement> {\n\t/** The shape being rendered. */\n\tshape: TLShape\n\t/** Whether this is the shapes regular, or background component. */\n\tisBackground: boolean\n\t/** The shape's rendered component. */\n\tchildren: ReactNode\n}\n\n/** @public @react */\nexport const DefaultShapeWrapper = forwardRef(function DefaultShapeWrapper(\n\t{ children, shape, isBackground, ...props }: TLShapeWrapperProps,\n\tref: React.Ref<HTMLDivElement>\n) {\n\tconst isFilledShape = 'fill' in shape.props && shape.props.fill !== 'none'\n\n\treturn (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tdata-shape-type={shape.type}\n\t\t\tdata-shape-is-filled={isBackground ? undefined : isFilledShape}\n\t\t\tdata-shape-id={shape.id}\n\t\t\tdraggable={false}\n\t\t\t{...props}\n\t\t\tclassName={classNames('tl-shape', isBackground && 'tl-shape-background', props.className)}\n\t\t>\n\t\t\t{children}\n\t\t</div>\n\t)\n})\n"],
|
|
5
|
+
"mappings": "AAsBE;AArBF,OAAO,gBAAgB;AACvB,SAAS,kBAA6B;AAa/B,MAAM,sBAAsB,WAAW,SAASA,qBACtD,EAAE,UAAU,OAAO,cAAc,GAAG,MAAM,GAC1C,KACC;AACD,QAAM,gBAAgB,UAAU,MAAM,SAAS,MAAM,MAAM,SAAS;AAEpE,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA,mBAAiB,MAAM;AAAA,MACvB,wBAAsB,eAAe,SAAY;AAAA,MACjD,iBAAe,MAAM;AAAA,MACrB,WAAW;AAAA,MACV,GAAG;AAAA,MACJ,WAAW,WAAW,YAAY,gBAAgB,uBAAuB,MAAM,SAAS;AAAA,MAEvF;AAAA;AAAA,EACF;AAEF,CAAC;",
|
|
6
|
+
"names": ["DefaultShapeWrapper"]
|
|
7
|
+
}
|
|
@@ -2357,28 +2357,11 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
2357
2357
|
{ history: "ignore" }
|
|
2358
2358
|
);
|
|
2359
2359
|
const { currentScreenPoint, currentPagePoint } = this.inputs;
|
|
2360
|
-
const { screenBounds } = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID);
|
|
2361
2360
|
if (currentScreenPoint.x / z - x !== currentPagePoint.x || currentScreenPoint.y / z - y !== currentPagePoint.y) {
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
// weird but true: we need to put the screen point back into client space
|
|
2367
|
-
point: Vec.AddXY(currentScreenPoint, screenBounds.x, screenBounds.y),
|
|
2368
|
-
pointerId: INTERNAL_POINTER_IDS.CAMERA_MOVE,
|
|
2369
|
-
ctrlKey: this.inputs.ctrlKey,
|
|
2370
|
-
altKey: this.inputs.altKey,
|
|
2371
|
-
shiftKey: this.inputs.shiftKey,
|
|
2372
|
-
metaKey: this.inputs.metaKey,
|
|
2373
|
-
accelKey: isAccelKey(this.inputs),
|
|
2374
|
-
button: 0,
|
|
2375
|
-
isPen: this.getInstanceState().isPenMode ?? false
|
|
2376
|
-
};
|
|
2377
|
-
if (opts?.immediate) {
|
|
2378
|
-
this._flushEventForTick(event);
|
|
2379
|
-
} else {
|
|
2380
|
-
this.dispatch(event);
|
|
2381
|
-
}
|
|
2361
|
+
this.updatePointer({
|
|
2362
|
+
immediate: opts?.immediate,
|
|
2363
|
+
pointerId: INTERNAL_POINTER_IDS.CAMERA_MOVE
|
|
2364
|
+
});
|
|
2382
2365
|
}
|
|
2383
2366
|
this._tickCameraState();
|
|
2384
2367
|
});
|
|
@@ -3347,19 +3330,24 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
3347
3330
|
*/
|
|
3348
3331
|
deletePage(page) {
|
|
3349
3332
|
const id = typeof page === "string" ? page : page.id;
|
|
3350
|
-
this.run(
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3333
|
+
this.run(
|
|
3334
|
+
() => {
|
|
3335
|
+
if (this.getIsReadonly()) return;
|
|
3336
|
+
const pages = this.getPages();
|
|
3337
|
+
if (pages.length === 1) return;
|
|
3338
|
+
const deletedPage = this.getPage(id);
|
|
3339
|
+
if (!deletedPage) return;
|
|
3340
|
+
if (id === this.getCurrentPageId()) {
|
|
3341
|
+
const index = pages.findIndex((page2) => page2.id === id);
|
|
3342
|
+
const next = pages[index - 1] ?? pages[index + 1];
|
|
3343
|
+
this.setCurrentPage(next.id);
|
|
3344
|
+
}
|
|
3345
|
+
const shapes = this.getSortedChildIdsForParent(deletedPage.id);
|
|
3346
|
+
this.deleteShapes(shapes);
|
|
3347
|
+
this.store.remove([deletedPage.id]);
|
|
3348
|
+
},
|
|
3349
|
+
{ ignoreShapeLock: true }
|
|
3350
|
+
);
|
|
3363
3351
|
return this;
|
|
3364
3352
|
}
|
|
3365
3353
|
/**
|
|
@@ -3973,7 +3961,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
3973
3961
|
const geometry = this.getShapeGeometry(shape);
|
|
3974
3962
|
const isGroup = geometry instanceof Group2d;
|
|
3975
3963
|
const pointInShapeSpace = this.getPointInShapeSpace(shape, point);
|
|
3976
|
-
if (this.isShapeOfType(shape, "frame") || this.isShapeOfType(shape, "
|
|
3964
|
+
if (this.isShapeOfType(shape, "frame") || (this.isShapeOfType(shape, "note") || this.isShapeOfType(shape, "arrow") || this.isShapeOfType(shape, "geo") && shape.props.fill === "none") && this.getShapeUtil(shape).getText(shape)?.trim()) {
|
|
3977
3965
|
for (const childGeometry of geometry.children) {
|
|
3978
3966
|
if (childGeometry.isLabel && childGeometry.isPointInBounds(pointInShapeSpace)) {
|
|
3979
3967
|
return shape;
|
|
@@ -7062,6 +7050,47 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7062
7050
|
this.dispatch({ type: "misc", name: "complete" });
|
|
7063
7051
|
return this;
|
|
7064
7052
|
}
|
|
7053
|
+
/**
|
|
7054
|
+
* Dispatch a pointer move event in the current position of the pointer. This is useful when
|
|
7055
|
+
* external circumstances have changed (e.g. the camera moved or a shape was moved) and you want
|
|
7056
|
+
* the current interaction to respond to that change.
|
|
7057
|
+
*
|
|
7058
|
+
* @example
|
|
7059
|
+
* ```ts
|
|
7060
|
+
* editor.updatePointer()
|
|
7061
|
+
* ```
|
|
7062
|
+
*
|
|
7063
|
+
* @param options - The options for updating the pointer.
|
|
7064
|
+
* @returns The editor instance.
|
|
7065
|
+
* @public
|
|
7066
|
+
*/
|
|
7067
|
+
updatePointer(options) {
|
|
7068
|
+
const event = {
|
|
7069
|
+
type: "pointer",
|
|
7070
|
+
target: "canvas",
|
|
7071
|
+
name: "pointer_move",
|
|
7072
|
+
point: options?.point ?? // weird but true: what `inputs` calls screen-space is actually viewport space. so
|
|
7073
|
+
// we need to convert back into true screen space first. we should fix this...
|
|
7074
|
+
Vec.Add(
|
|
7075
|
+
this.inputs.currentScreenPoint,
|
|
7076
|
+
this.store.unsafeGetWithoutCapture(TLINSTANCE_ID).screenBounds
|
|
7077
|
+
),
|
|
7078
|
+
pointerId: options?.pointerId ?? 0,
|
|
7079
|
+
button: options?.button ?? 0,
|
|
7080
|
+
isPen: options?.isPen ?? this.inputs.isPen,
|
|
7081
|
+
shiftKey: options?.shiftKey ?? this.inputs.shiftKey,
|
|
7082
|
+
altKey: options?.altKey ?? this.inputs.altKey,
|
|
7083
|
+
ctrlKey: options?.ctrlKey ?? this.inputs.ctrlKey,
|
|
7084
|
+
metaKey: options?.metaKey ?? this.inputs.metaKey,
|
|
7085
|
+
accelKey: options?.accelKey ?? isAccelKey(this.inputs)
|
|
7086
|
+
};
|
|
7087
|
+
if (options?.immediate) {
|
|
7088
|
+
this._flushEventForTick(event);
|
|
7089
|
+
} else {
|
|
7090
|
+
this.dispatch(event);
|
|
7091
|
+
}
|
|
7092
|
+
return this;
|
|
7093
|
+
}
|
|
7065
7094
|
/**
|
|
7066
7095
|
* Puts the editor into focused mode.
|
|
7067
7096
|
*
|