@tldraw/editor 5.3.0-next.fc37bd96825b → 5.3.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 +138 -3
- package/dist-cjs/index.js +13 -3
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +24 -19
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/EditorPortal.js +44 -0
- package/dist-cjs/lib/components/EditorPortal.js.map +7 -0
- package/dist-cjs/lib/components/LiveCollaborators.js +102 -0
- package/dist-cjs/lib/components/LiveCollaborators.js.map +7 -0
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +4 -10
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +3 -3
- package/dist-cjs/lib/components/default-components/DefaultCursor.js +59 -0
- package/dist-cjs/lib/components/default-components/DefaultCursor.js.map +7 -0
- package/dist-cjs/lib/editor/Editor.js +7 -2
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js +4 -4
- package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
- package/dist-cjs/lib/hooks/EditorComponentsContext.js.map +2 -2
- package/dist-cjs/lib/hooks/useCursor.js +1 -0
- package/dist-cjs/lib/hooks/useCursor.js.map +2 -2
- package/dist-cjs/lib/hooks/useEditorComponents.js +2 -0
- package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +49 -18
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +3 -3
- package/dist-cjs/lib/hooks/useTransform.js +45 -0
- package/dist-cjs/lib/hooks/useTransform.js.map +7 -0
- package/dist-cjs/lib/license/LicenseManager.js +51 -2
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/license/useLicenseManagerState.js +7 -0
- package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
- package/dist-cjs/lib/utils/collaborators.js +27 -0
- package/dist-cjs/lib/utils/collaborators.js.map +7 -0
- package/dist-cjs/lib/utils/getHtmlLayerTransform.js +33 -0
- package/dist-cjs/lib/utils/getHtmlLayerTransform.js.map +7 -0
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +138 -3
- package/dist-esm/index.mjs +19 -4
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +23 -18
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/EditorPortal.mjs +24 -0
- package/dist-esm/lib/components/EditorPortal.mjs.map +7 -0
- package/dist-esm/lib/components/LiveCollaborators.mjs +82 -0
- package/dist-esm/lib/components/LiveCollaborators.mjs.map +7 -0
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +5 -11
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCursor.mjs +29 -0
- package/dist-esm/lib/components/default-components/DefaultCursor.mjs.map +7 -0
- package/dist-esm/lib/editor/Editor.mjs +7 -2
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs +5 -5
- package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/hooks/EditorComponentsContext.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCursor.mjs +1 -0
- package/dist-esm/lib/hooks/useCursor.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditorComponents.mjs +2 -0
- package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +50 -19
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +3 -3
- package/dist-esm/lib/hooks/useTransform.mjs +25 -0
- package/dist-esm/lib/hooks/useTransform.mjs.map +7 -0
- package/dist-esm/lib/license/LicenseManager.mjs +52 -3
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/license/useLicenseManagerState.mjs +7 -0
- package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
- package/dist-esm/lib/utils/collaborators.mjs +7 -0
- package/dist-esm/lib/utils/collaborators.mjs.map +7 -0
- package/dist-esm/lib/utils/getHtmlLayerTransform.mjs +13 -0
- package/dist-esm/lib/utils/getHtmlLayerTransform.mjs.map +7 -0
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +43 -4
- package/package.json +7 -7
- package/src/index.ts +14 -2
- package/src/lib/TldrawEditor.tsx +21 -13
- package/src/lib/components/EditorPortal.tsx +77 -0
- package/src/lib/components/LiveCollaborators.tsx +133 -0
- package/src/lib/components/default-components/DefaultCanvas.tsx +5 -17
- package/src/lib/components/default-components/DefaultCursor.tsx +65 -0
- package/src/lib/editor/Editor.ts +14 -2
- package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.test.ts +46 -1
- package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.ts +10 -5
- package/src/lib/editor/shapes/ShapeUtil.ts +24 -0
- package/src/lib/editor/types/external-content.ts +5 -0
- package/src/lib/hooks/EditorComponentsContext.tsx +2 -0
- package/src/lib/hooks/useCursor.ts +1 -0
- package/src/lib/hooks/useEditorComponents.tsx +2 -0
- package/src/lib/hooks/usePassThroughWheelEvents.ts +83 -24
- package/src/lib/hooks/useTransform.ts +38 -0
- package/src/lib/license/LicenseManager.test.ts +146 -0
- package/src/lib/license/LicenseManager.ts +98 -2
- package/src/lib/license/useLicenseManagerState.ts +17 -1
- package/src/lib/test/EditorPortal.test.tsx +48 -0
- package/src/lib/test/usePassThroughWheelEvents.test.tsx +77 -0
- package/src/lib/utils/collaborators.test.ts +34 -0
- package/src/lib/utils/collaborators.ts +25 -0
- package/src/lib/utils/getHtmlLayerTransform.ts +22 -0
- package/src/version.ts +3 -3
- package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +0 -51
- package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +0 -7
- package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +0 -31
- package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +0 -7
- package/src/lib/hooks/usePassThroughMouseOverEvents.ts +0 -32
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { isCursorInViewport } from './collaborators'
|
|
3
|
+
|
|
4
|
+
// The viewport (page coords) all cases test against; zoom 1 so the 12/16px margins map 1:1.
|
|
5
|
+
const viewport = { minX: 0, minY: 0, maxX: 100, maxY: 100 }
|
|
6
|
+
|
|
7
|
+
describe('isCursorInViewport', () => {
|
|
8
|
+
it('is true for a cursor well inside the viewport', () => {
|
|
9
|
+
expect(isCursorInViewport({ x: 50, y: 50 }, viewport, 1)).toBe(true)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('keeps a cursor just past the left/top edges (12/16px margin)', () => {
|
|
13
|
+
expect(isCursorInViewport({ x: -11, y: 50 }, viewport, 1)).toBe(true) // within 12 of left
|
|
14
|
+
expect(isCursorInViewport({ x: -13, y: 50 }, viewport, 1)).toBe(false) // past it
|
|
15
|
+
expect(isCursorInViewport({ x: 50, y: -15 }, viewport, 1)).toBe(true) // within 16 of top
|
|
16
|
+
expect(isCursorInViewport({ x: 50, y: -17 }, viewport, 1)).toBe(false) // past it
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('culls a cursor beyond the right/bottom edges', () => {
|
|
20
|
+
// Asymmetric with the left/top edges: the max checks subtract the margin rather than add
|
|
21
|
+
// it, so the cull starts *inside* the far edge (maxX - 12, maxY - 16) — a known quirk
|
|
22
|
+
// carried over from the pre-canvas implementation.
|
|
23
|
+
expect(isCursorInViewport({ x: 87, y: 50 }, viewport, 1)).toBe(true) // < maxX - 12 (88)
|
|
24
|
+
expect(isCursorInViewport({ x: 89, y: 50 }, viewport, 1)).toBe(false) // > 88, culled
|
|
25
|
+
expect(isCursorInViewport({ x: 50, y: 83 }, viewport, 1)).toBe(true) // < maxY - 16 (84)
|
|
26
|
+
expect(isCursorInViewport({ x: 50, y: 85 }, viewport, 1)).toBe(false) // > 84, culled
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('scales the margins by zoom', () => {
|
|
30
|
+
// At zoom 2 the left margin is 12/2 = 6px, so -7 is now culled where -11 survived at zoom 1.
|
|
31
|
+
expect(isCursorInViewport({ x: -5, y: 50 }, viewport, 2)).toBe(true)
|
|
32
|
+
expect(isCursorInViewport({ x: -7, y: 50 }, viewport, 2)).toBe(false)
|
|
33
|
+
})
|
|
34
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { VecLike } from '../primitives/Vec'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whether a collaborator's cursor (page coords) is inside the viewport, with a small margin for the
|
|
5
|
+
* cursor glyph so it isn't culled the instant its hotspot crosses the edge.
|
|
6
|
+
*
|
|
7
|
+
* Single source of truth for the cursor/hint split: the DOM cursor layer renders a collaborator
|
|
8
|
+
* when this is true, and `CollaboratorHintOverlayUtil` draws the viewport-edge hint when it's
|
|
9
|
+
* false. Sharing the predicate keeps those two exhaustive and mutually exclusive — a margin change
|
|
10
|
+
* can't open a dead zone (neither renders) or a double-render (both).
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export function isCursorInViewport(
|
|
15
|
+
cursor: VecLike,
|
|
16
|
+
viewport: { minX: number; minY: number; maxX: number; maxY: number },
|
|
17
|
+
zoom: number
|
|
18
|
+
): boolean {
|
|
19
|
+
return !(
|
|
20
|
+
cursor.x < viewport.minX - 12 / zoom ||
|
|
21
|
+
cursor.y < viewport.minY - 16 / zoom ||
|
|
22
|
+
cursor.x > viewport.maxX - 12 / zoom ||
|
|
23
|
+
cursor.y > viewport.maxY - 16 / zoom
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { modulate } from '@tldraw/utils'
|
|
2
|
+
import type { Editor } from '../editor/Editor'
|
|
3
|
+
import { toDomPrecision } from '../primitives/utils'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The CSS `transform` that puts a 1px-sized html layer into page space under the current camera.
|
|
7
|
+
* Shared by every camera-tracked DOM layer (the canvas's shape layer, the collaborator cursor
|
|
8
|
+
* layer) so they line up exactly and can't drift apart.
|
|
9
|
+
*
|
|
10
|
+
* The offset compensates for the layer's 1px width/height when zoomed, so it registers precisely
|
|
11
|
+
* with the other layers.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export function getHtmlLayerTransform(editor: Editor): string {
|
|
16
|
+
const { x, y, z } = editor.getCamera()
|
|
17
|
+
const offset =
|
|
18
|
+
z >= 1 ? modulate(z, [1, 8], [0.125, 0.5], true) : modulate(z, [0.1, 1], [-2, 0.125], true)
|
|
19
|
+
return `scale(${toDomPrecision(z)}) translate(${toDomPrecision(x + offset)}px,${toDomPrecision(
|
|
20
|
+
y + offset
|
|
21
|
+
)}px)`
|
|
22
|
+
}
|
package/src/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 = '5.3.0
|
|
4
|
+
export const version = '5.3.0'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2026-05-06T16:28:18.473Z',
|
|
7
|
-
minor: '2026-
|
|
8
|
-
patch: '2026-
|
|
7
|
+
minor: '2026-08-05T11:39:54.978Z',
|
|
8
|
+
patch: '2026-08-05T11:39:54.978Z',
|
|
9
9
|
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var usePassThroughMouseOverEvents_exports = {};
|
|
20
|
-
__export(usePassThroughMouseOverEvents_exports, {
|
|
21
|
-
usePassThroughMouseOverEvents: () => usePassThroughMouseOverEvents
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(usePassThroughMouseOverEvents_exports);
|
|
24
|
-
var import_react = require("react");
|
|
25
|
-
var import_dom = require("../utils/dom");
|
|
26
|
-
var import_useContainer = require("./useContainer");
|
|
27
|
-
var import_useEditor = require("./useEditor");
|
|
28
|
-
function usePassThroughMouseOverEvents(ref) {
|
|
29
|
-
if (!ref) throw Error("usePassThroughWheelEvents must be passed a ref");
|
|
30
|
-
const container = (0, import_useContainer.useContainer)();
|
|
31
|
-
const editor = (0, import_useEditor.useMaybeEditor)();
|
|
32
|
-
(0, import_react.useEffect)(() => {
|
|
33
|
-
function onMouseOver(e) {
|
|
34
|
-
if (!editor?.getInstanceState().isFocused) return;
|
|
35
|
-
if (e.isSpecialRedispatchedEvent) return;
|
|
36
|
-
(0, import_dom.preventDefault)(e);
|
|
37
|
-
const cvs = container.querySelector(".tl-canvas");
|
|
38
|
-
if (!cvs) return;
|
|
39
|
-
const newEvent = new PointerEvent(e.type, e);
|
|
40
|
-
newEvent.isSpecialRedispatchedEvent = true;
|
|
41
|
-
cvs.dispatchEvent(newEvent);
|
|
42
|
-
}
|
|
43
|
-
const elm = ref.current;
|
|
44
|
-
if (!elm) return;
|
|
45
|
-
elm.addEventListener("mouseover", onMouseOver, { passive: false });
|
|
46
|
-
return () => {
|
|
47
|
-
elm.removeEventListener("mouseover", onMouseOver);
|
|
48
|
-
};
|
|
49
|
-
}, [container, editor, ref]);
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=usePassThroughMouseOverEvents.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/lib/hooks/usePassThroughMouseOverEvents.ts"],
|
|
4
|
-
"sourcesContent": ["import { RefObject, useEffect } from 'react'\nimport { preventDefault } from '../utils/dom'\nimport { useContainer } from './useContainer'\nimport { useMaybeEditor } from './useEditor'\n\n/** @public */\nexport function usePassThroughMouseOverEvents(ref: RefObject<HTMLElement | null>) {\n\tif (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')\n\tconst container = useContainer()\n\tconst editor = useMaybeEditor()\n\n\tuseEffect(() => {\n\t\tfunction onMouseOver(e: MouseEvent) {\n\t\t\tif (!editor?.getInstanceState().isFocused) return\n\t\t\tif ((e as any).isSpecialRedispatchedEvent) return\n\t\t\tpreventDefault(e)\n\t\t\tconst cvs = container.querySelector('.tl-canvas')\n\t\t\tif (!cvs) return\n\t\t\tconst newEvent = new PointerEvent(e.type, e as any)\n\t\t\t;(newEvent as any).isSpecialRedispatchedEvent = true\n\t\t\tcvs.dispatchEvent(newEvent)\n\t\t}\n\n\t\tconst elm = ref.current\n\t\tif (!elm) return\n\n\t\telm.addEventListener('mouseover', onMouseOver, { passive: false })\n\t\treturn () => {\n\t\t\telm.removeEventListener('mouseover', onMouseOver)\n\t\t}\n\t}, [container, editor, ref])\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqC;AACrC,iBAA+B;AAC/B,0BAA6B;AAC7B,uBAA+B;AAGxB,SAAS,8BAA8B,KAAoC;AACjF,MAAI,CAAC,IAAK,OAAM,MAAM,gDAAgD;AACtE,QAAM,gBAAY,kCAAa;AAC/B,QAAM,aAAS,iCAAe;AAE9B,8BAAU,MAAM;AACf,aAAS,YAAY,GAAe;AACnC,UAAI,CAAC,QAAQ,iBAAiB,EAAE,UAAW;AAC3C,UAAK,EAAU,2BAA4B;AAC3C,qCAAe,CAAC;AAChB,YAAM,MAAM,UAAU,cAAc,YAAY;AAChD,UAAI,CAAC,IAAK;AACV,YAAM,WAAW,IAAI,aAAa,EAAE,MAAM,CAAQ;AACjD,MAAC,SAAiB,6BAA6B;AAChD,UAAI,cAAc,QAAQ;AAAA,IAC3B;AAEA,UAAM,MAAM,IAAI;AAChB,QAAI,CAAC,IAAK;AAEV,QAAI,iBAAiB,aAAa,aAAa,EAAE,SAAS,MAAM,CAAC;AACjE,WAAO,MAAM;AACZ,UAAI,oBAAoB,aAAa,WAAW;AAAA,IACjD;AAAA,EACD,GAAG,CAAC,WAAW,QAAQ,GAAG,CAAC;AAC5B;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
import { preventDefault } from "../utils/dom.mjs";
|
|
3
|
-
import { useContainer } from "./useContainer.mjs";
|
|
4
|
-
import { useMaybeEditor } from "./useEditor.mjs";
|
|
5
|
-
function usePassThroughMouseOverEvents(ref) {
|
|
6
|
-
if (!ref) throw Error("usePassThroughWheelEvents must be passed a ref");
|
|
7
|
-
const container = useContainer();
|
|
8
|
-
const editor = useMaybeEditor();
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
function onMouseOver(e) {
|
|
11
|
-
if (!editor?.getInstanceState().isFocused) return;
|
|
12
|
-
if (e.isSpecialRedispatchedEvent) return;
|
|
13
|
-
preventDefault(e);
|
|
14
|
-
const cvs = container.querySelector(".tl-canvas");
|
|
15
|
-
if (!cvs) return;
|
|
16
|
-
const newEvent = new PointerEvent(e.type, e);
|
|
17
|
-
newEvent.isSpecialRedispatchedEvent = true;
|
|
18
|
-
cvs.dispatchEvent(newEvent);
|
|
19
|
-
}
|
|
20
|
-
const elm = ref.current;
|
|
21
|
-
if (!elm) return;
|
|
22
|
-
elm.addEventListener("mouseover", onMouseOver, { passive: false });
|
|
23
|
-
return () => {
|
|
24
|
-
elm.removeEventListener("mouseover", onMouseOver);
|
|
25
|
-
};
|
|
26
|
-
}, [container, editor, ref]);
|
|
27
|
-
}
|
|
28
|
-
export {
|
|
29
|
-
usePassThroughMouseOverEvents
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=usePassThroughMouseOverEvents.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/lib/hooks/usePassThroughMouseOverEvents.ts"],
|
|
4
|
-
"sourcesContent": ["import { RefObject, useEffect } from 'react'\nimport { preventDefault } from '../utils/dom'\nimport { useContainer } from './useContainer'\nimport { useMaybeEditor } from './useEditor'\n\n/** @public */\nexport function usePassThroughMouseOverEvents(ref: RefObject<HTMLElement | null>) {\n\tif (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')\n\tconst container = useContainer()\n\tconst editor = useMaybeEditor()\n\n\tuseEffect(() => {\n\t\tfunction onMouseOver(e: MouseEvent) {\n\t\t\tif (!editor?.getInstanceState().isFocused) return\n\t\t\tif ((e as any).isSpecialRedispatchedEvent) return\n\t\t\tpreventDefault(e)\n\t\t\tconst cvs = container.querySelector('.tl-canvas')\n\t\t\tif (!cvs) return\n\t\t\tconst newEvent = new PointerEvent(e.type, e as any)\n\t\t\t;(newEvent as any).isSpecialRedispatchedEvent = true\n\t\t\tcvs.dispatchEvent(newEvent)\n\t\t}\n\n\t\tconst elm = ref.current\n\t\tif (!elm) return\n\n\t\telm.addEventListener('mouseover', onMouseOver, { passive: false })\n\t\treturn () => {\n\t\t\telm.removeEventListener('mouseover', onMouseOver)\n\t\t}\n\t}, [container, editor, ref])\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAoB,iBAAiB;AACrC,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAGxB,SAAS,8BAA8B,KAAoC;AACjF,MAAI,CAAC,IAAK,OAAM,MAAM,gDAAgD;AACtE,QAAM,YAAY,aAAa;AAC/B,QAAM,SAAS,eAAe;AAE9B,YAAU,MAAM;AACf,aAAS,YAAY,GAAe;AACnC,UAAI,CAAC,QAAQ,iBAAiB,EAAE,UAAW;AAC3C,UAAK,EAAU,2BAA4B;AAC3C,qBAAe,CAAC;AAChB,YAAM,MAAM,UAAU,cAAc,YAAY;AAChD,UAAI,CAAC,IAAK;AACV,YAAM,WAAW,IAAI,aAAa,EAAE,MAAM,CAAQ;AACjD,MAAC,SAAiB,6BAA6B;AAChD,UAAI,cAAc,QAAQ;AAAA,IAC3B;AAEA,UAAM,MAAM,IAAI;AAChB,QAAI,CAAC,IAAK;AAEV,QAAI,iBAAiB,aAAa,aAAa,EAAE,SAAS,MAAM,CAAC;AACjE,WAAO,MAAM;AACZ,UAAI,oBAAoB,aAAa,WAAW;AAAA,IACjD;AAAA,EACD,GAAG,CAAC,WAAW,QAAQ,GAAG,CAAC;AAC5B;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { RefObject, useEffect } from 'react'
|
|
2
|
-
import { preventDefault } from '../utils/dom'
|
|
3
|
-
import { useContainer } from './useContainer'
|
|
4
|
-
import { useMaybeEditor } from './useEditor'
|
|
5
|
-
|
|
6
|
-
/** @public */
|
|
7
|
-
export function usePassThroughMouseOverEvents(ref: RefObject<HTMLElement | null>) {
|
|
8
|
-
if (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')
|
|
9
|
-
const container = useContainer()
|
|
10
|
-
const editor = useMaybeEditor()
|
|
11
|
-
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
function onMouseOver(e: MouseEvent) {
|
|
14
|
-
if (!editor?.getInstanceState().isFocused) return
|
|
15
|
-
if ((e as any).isSpecialRedispatchedEvent) return
|
|
16
|
-
preventDefault(e)
|
|
17
|
-
const cvs = container.querySelector('.tl-canvas')
|
|
18
|
-
if (!cvs) return
|
|
19
|
-
const newEvent = new PointerEvent(e.type, e as any)
|
|
20
|
-
;(newEvent as any).isSpecialRedispatchedEvent = true
|
|
21
|
-
cvs.dispatchEvent(newEvent)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const elm = ref.current
|
|
25
|
-
if (!elm) return
|
|
26
|
-
|
|
27
|
-
elm.addEventListener('mouseover', onMouseOver, { passive: false })
|
|
28
|
-
return () => {
|
|
29
|
-
elm.removeEventListener('mouseover', onMouseOver)
|
|
30
|
-
}
|
|
31
|
-
}, [container, editor, ref])
|
|
32
|
-
}
|