@bwp-web/canvas 0.14.0 → 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 +22 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -11
- package/dist/index.js.map +1 -1
- package/dist/interactions/drawToCreate.d.ts.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;
|
|
@@ -1836,10 +1837,11 @@ function enableDrawToCreate(canvas, options) {
|
|
|
1836
1837
|
const finalize = () => {
|
|
1837
1838
|
removePreviewElements();
|
|
1838
1839
|
snapping.clearSnapResult();
|
|
1839
|
-
const
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
}
|
|
1840
|
+
const styleWithData = {
|
|
1841
|
+
...options?.style,
|
|
1842
|
+
...options?.data != null && { data: options.data }
|
|
1843
|
+
};
|
|
1844
|
+
const obj = options?.factory ? options.factory(canvas, [...points]) : createPolygonFromVertices(canvas, points, styleWithData);
|
|
1843
1845
|
canvas.selection = previousSelection;
|
|
1844
1846
|
canvas.requestRenderAll();
|
|
1845
1847
|
restoreViewport(options?.viewport);
|
|
@@ -1999,6 +2001,10 @@ function enableDrawToCreate(canvas, options) {
|
|
|
1999
2001
|
placeVertex(dragStartX, dragStartY);
|
|
2000
2002
|
return;
|
|
2001
2003
|
}
|
|
2004
|
+
const dragStyleWithData = {
|
|
2005
|
+
...options?.style,
|
|
2006
|
+
...options?.data != null && { data: options.data }
|
|
2007
|
+
};
|
|
2002
2008
|
const obj = createPolygonFromVertices(
|
|
2003
2009
|
canvas,
|
|
2004
2010
|
[
|
|
@@ -2007,11 +2013,8 @@ function enableDrawToCreate(canvas, options) {
|
|
|
2007
2013
|
{ x: dragStartX + width, y: dragStartY + height },
|
|
2008
2014
|
{ x: dragStartX, y: dragStartY + height }
|
|
2009
2015
|
],
|
|
2010
|
-
|
|
2016
|
+
dragStyleWithData
|
|
2011
2017
|
);
|
|
2012
|
-
if (options?.data) {
|
|
2013
|
-
obj.data = options.data;
|
|
2014
|
-
}
|
|
2015
2018
|
canvas.selection = previousSelection;
|
|
2016
2019
|
canvas.requestRenderAll();
|
|
2017
2020
|
restoreViewport(options?.viewport);
|
|
@@ -3181,8 +3184,10 @@ function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
|
3181
3184
|
const [state, setState] = useState3({
|
|
3182
3185
|
visible: false,
|
|
3183
3186
|
content: null,
|
|
3184
|
-
position: { x: 0, y: 0 }
|
|
3187
|
+
position: { x: 0, y: 0 },
|
|
3188
|
+
ref: { current: null }
|
|
3185
3189
|
});
|
|
3190
|
+
const tooltipElRef = useRef5(null);
|
|
3186
3191
|
const hoveredObjectRef = useRef5(null);
|
|
3187
3192
|
const optionsRef = useRef5(options);
|
|
3188
3193
|
optionsRef.current = options;
|
|
@@ -3199,6 +3204,12 @@ function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
|
3199
3204
|
y: bounds.top * zoom + vt[5] - 10
|
|
3200
3205
|
};
|
|
3201
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
|
+
}
|
|
3202
3213
|
const handleMouseOver = (e) => {
|
|
3203
3214
|
const target = e.target;
|
|
3204
3215
|
if (!target) return;
|
|
@@ -3208,7 +3219,7 @@ function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
|
3208
3219
|
hoveredObjectRef.current = target;
|
|
3209
3220
|
const position = calculatePosition(target);
|
|
3210
3221
|
if (position) {
|
|
3211
|
-
setState({ visible: true, content, position });
|
|
3222
|
+
setState({ visible: true, content, position, ref: tooltipElRef });
|
|
3212
3223
|
}
|
|
3213
3224
|
}
|
|
3214
3225
|
};
|
|
@@ -3222,7 +3233,7 @@ function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
|
3222
3233
|
if (!hoveredObjectRef.current) return;
|
|
3223
3234
|
const position = calculatePosition(hoveredObjectRef.current);
|
|
3224
3235
|
if (position) {
|
|
3225
|
-
|
|
3236
|
+
applyPositionToDOM(position);
|
|
3226
3237
|
}
|
|
3227
3238
|
};
|
|
3228
3239
|
canvas.on("mouse:over", handleMouseOver);
|