@bwp-web/canvas 0.14.1 → 0.14.2
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/hooks/useCanvasTooltip.d.ts +13 -1
- package/dist/hooks/useCanvasTooltip.d.ts.map +1 -1
- package/dist/index.cjs +12 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/dist/viewport.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -14,6 +14,12 @@ export interface CanvasTooltipState<T> {
|
|
|
14
14
|
x: number;
|
|
15
15
|
y: number;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Ref to attach to the tooltip container element. When attached, position
|
|
19
|
+
* updates during pan/zoom are applied directly to the DOM — no React
|
|
20
|
+
* re-renders. The element should use `position: absolute`.
|
|
21
|
+
*/
|
|
22
|
+
ref: RefObject<HTMLDivElement | null>;
|
|
17
23
|
}
|
|
18
24
|
/**
|
|
19
25
|
* Track mouse hover over canvas objects and return tooltip state, using the
|
|
@@ -36,6 +42,9 @@ export declare function useCanvasTooltip<T>(options: UseCanvasTooltipOptions<T>)
|
|
|
36
42
|
* coordinates relative to the canvas container element — suitable for absolute
|
|
37
43
|
* positioning of a tooltip component.
|
|
38
44
|
*
|
|
45
|
+
* Attach {@link CanvasTooltipState.ref | tooltip.ref} to the tooltip container
|
|
46
|
+
* for smooth, re-render-free position updates during pan and zoom.
|
|
47
|
+
*
|
|
39
48
|
* @example
|
|
40
49
|
* ```tsx
|
|
41
50
|
* const tooltip = useCanvasTooltip(view.canvasRef, {
|
|
@@ -46,7 +55,10 @@ export declare function useCanvasTooltip<T>(options: UseCanvasTooltipOptions<T>)
|
|
|
46
55
|
* <>
|
|
47
56
|
* <Canvas onReady={view.onReady} />
|
|
48
57
|
* {tooltip.visible && (
|
|
49
|
-
* <div
|
|
58
|
+
* <div
|
|
59
|
+
* ref={tooltip.ref}
|
|
60
|
+
* style={{ position: 'absolute', left: tooltip.position.x, top: tooltip.position.y }}
|
|
61
|
+
* >
|
|
50
62
|
* {tooltip.content?.id}
|
|
51
63
|
* </div>
|
|
52
64
|
* )}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCanvasTooltip.d.ts","sourceRoot":"","sources":["../../src/hooks/useCanvasTooltip.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EACV,MAAM,IAAI,YAAY,EAEtB,YAAY,EACb,MAAM,QAAQ,CAAC;AAGhB,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACxC,wFAAwF;IACxF,UAAU,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,CAAC,GAAG,IAAI,CAAC;CAC7C;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAC;IACjB,4EAA4E;IAC5E,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;IAClB,gFAAgF;IAChF,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"useCanvasTooltip.d.ts","sourceRoot":"","sources":["../../src/hooks/useCanvasTooltip.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EACV,MAAM,IAAI,YAAY,EAEtB,YAAY,EACb,MAAM,QAAQ,CAAC;AAGhB,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACxC,wFAAwF;IACxF,UAAU,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,CAAC,GAAG,IAAI,CAAC;CAC7C;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAC;IACjB,4EAA4E;IAC5E,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;IAClB,gFAAgF;IAChF,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnC;;;;OAIG;IACH,GAAG,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAClC,kBAAkB,CAAC,CAAC,CAAC,CAAC;AACzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,SAAS,EAAE,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,EACzC,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAClC,kBAAkB,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -258,6 +258,7 @@ function setupMousePan(canvas, getMode, isEnabled) {
|
|
|
258
258
|
const isModifiedSelect = e instanceof MouseEvent && mode === "select" && (e.metaKey || e.ctrlKey);
|
|
259
259
|
const shouldPan = mode === "pan" || isMiddleButton || isModifiedSelect || mode === "select" && !opt.target;
|
|
260
260
|
if (shouldPan) {
|
|
261
|
+
e.preventDefault();
|
|
261
262
|
isPanning = true;
|
|
262
263
|
lastPanX = pos.x;
|
|
263
264
|
lastPanY = pos.y;
|
|
@@ -3260,8 +3261,10 @@ function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
|
3260
3261
|
const [state, setState] = (0, import_react7.useState)({
|
|
3261
3262
|
visible: false,
|
|
3262
3263
|
content: null,
|
|
3263
|
-
position: { x: 0, y: 0 }
|
|
3264
|
+
position: { x: 0, y: 0 },
|
|
3265
|
+
ref: { current: null }
|
|
3264
3266
|
});
|
|
3267
|
+
const tooltipElRef = (0, import_react7.useRef)(null);
|
|
3265
3268
|
const hoveredObjectRef = (0, import_react7.useRef)(null);
|
|
3266
3269
|
const optionsRef = (0, import_react7.useRef)(options);
|
|
3267
3270
|
optionsRef.current = options;
|
|
@@ -3278,6 +3281,12 @@ function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
|
3278
3281
|
y: bounds.top * zoom + vt[5] - 10
|
|
3279
3282
|
};
|
|
3280
3283
|
}
|
|
3284
|
+
function applyPositionToDOM(position) {
|
|
3285
|
+
const el = tooltipElRef.current;
|
|
3286
|
+
if (!el) return;
|
|
3287
|
+
el.style.left = `${position.x}px`;
|
|
3288
|
+
el.style.top = `${position.y}px`;
|
|
3289
|
+
}
|
|
3281
3290
|
const handleMouseOver = (e) => {
|
|
3282
3291
|
const target = e.target;
|
|
3283
3292
|
if (!target) return;
|
|
@@ -3287,7 +3296,7 @@ function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
|
3287
3296
|
hoveredObjectRef.current = target;
|
|
3288
3297
|
const position = calculatePosition(target);
|
|
3289
3298
|
if (position) {
|
|
3290
|
-
setState({ visible: true, content, position });
|
|
3299
|
+
setState({ visible: true, content, position, ref: tooltipElRef });
|
|
3291
3300
|
}
|
|
3292
3301
|
}
|
|
3293
3302
|
};
|
|
@@ -3301,7 +3310,7 @@ function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
|
3301
3310
|
if (!hoveredObjectRef.current) return;
|
|
3302
3311
|
const position = calculatePosition(hoveredObjectRef.current);
|
|
3303
3312
|
if (position) {
|
|
3304
|
-
|
|
3313
|
+
applyPositionToDOM(position);
|
|
3305
3314
|
}
|
|
3306
3315
|
};
|
|
3307
3316
|
canvas.on("mouse:over", handleMouseOver);
|