@bwp-web/canvas 0.15.0 → 1.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/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
package/dist/index.js
CHANGED
|
@@ -165,6 +165,7 @@ function setupMousePan(canvas, getMode, isEnabled) {
|
|
|
165
165
|
const isModifiedSelect = e instanceof MouseEvent && mode === "select" && (e.metaKey || e.ctrlKey);
|
|
166
166
|
const shouldPan = mode === "pan" || isMiddleButton || isModifiedSelect || mode === "select" && !opt.target;
|
|
167
167
|
if (shouldPan) {
|
|
168
|
+
e.preventDefault();
|
|
168
169
|
isPanning = true;
|
|
169
170
|
lastPanX = pos.x;
|
|
170
171
|
lastPanY = pos.y;
|
|
@@ -3183,8 +3184,10 @@ function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
|
3183
3184
|
const [state, setState] = useState3({
|
|
3184
3185
|
visible: false,
|
|
3185
3186
|
content: null,
|
|
3186
|
-
position: { x: 0, y: 0 }
|
|
3187
|
+
position: { x: 0, y: 0 },
|
|
3188
|
+
ref: { current: null }
|
|
3187
3189
|
});
|
|
3190
|
+
const tooltipElRef = useRef5(null);
|
|
3188
3191
|
const hoveredObjectRef = useRef5(null);
|
|
3189
3192
|
const optionsRef = useRef5(options);
|
|
3190
3193
|
optionsRef.current = options;
|
|
@@ -3201,6 +3204,12 @@ function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
|
3201
3204
|
y: bounds.top * zoom + vt[5] - 10
|
|
3202
3205
|
};
|
|
3203
3206
|
}
|
|
3207
|
+
function applyPositionToDOM(position) {
|
|
3208
|
+
const el = tooltipElRef.current;
|
|
3209
|
+
if (!el) return;
|
|
3210
|
+
el.style.left = `${position.x}px`;
|
|
3211
|
+
el.style.top = `${position.y}px`;
|
|
3212
|
+
}
|
|
3204
3213
|
const handleMouseOver = (e) => {
|
|
3205
3214
|
const target = e.target;
|
|
3206
3215
|
if (!target) return;
|
|
@@ -3210,7 +3219,7 @@ function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
|
3210
3219
|
hoveredObjectRef.current = target;
|
|
3211
3220
|
const position = calculatePosition(target);
|
|
3212
3221
|
if (position) {
|
|
3213
|
-
setState({ visible: true, content, position });
|
|
3222
|
+
setState({ visible: true, content, position, ref: tooltipElRef });
|
|
3214
3223
|
}
|
|
3215
3224
|
}
|
|
3216
3225
|
};
|
|
@@ -3224,7 +3233,7 @@ function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
|
3224
3233
|
if (!hoveredObjectRef.current) return;
|
|
3225
3234
|
const position = calculatePosition(hoveredObjectRef.current);
|
|
3226
3235
|
if (position) {
|
|
3227
|
-
|
|
3236
|
+
applyPositionToDOM(position);
|
|
3228
3237
|
}
|
|
3229
3238
|
};
|
|
3230
3239
|
canvas.on("mouse:over", handleMouseOver);
|