@stephenov/feedbackwidget 2.0.0 → 2.0.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/index.js +44 -56
- package/dist/index.mjs +1448 -21
- package/package.json +6 -13
- package/dist/auto.d.mts +0 -5
- package/dist/auto.d.ts +0 -5
- package/dist/auto.js +0 -1530
- package/dist/auto.mjs +0 -47
- package/dist/chunk-WCFS4MGE.mjs +0 -1459
package/dist/index.js
CHANGED
|
@@ -288,61 +288,45 @@ function FeedbackTrigger({
|
|
|
288
288
|
accentColor = "#BDE0C2",
|
|
289
289
|
tooltip = "Send feedback"
|
|
290
290
|
}) {
|
|
291
|
-
const [
|
|
291
|
+
const [offsets, setOffsets] = (0, import_react.useState)(null);
|
|
292
292
|
const [isDragging, setIsDragging] = (0, import_react.useState)(false);
|
|
293
293
|
const [dragStart, setDragStart] = (0, import_react.useState)(null);
|
|
294
294
|
const [hasMoved, setHasMoved] = (0, import_react.useState)(false);
|
|
295
295
|
const buttonRef = (0, import_react.useRef)(null);
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
case "bottom-left":
|
|
305
|
-
return { x: DEFAULT_OFFSET, y: h - BUTTON_SIZE - DEFAULT_OFFSET - 80 };
|
|
306
|
-
case "bottom-right":
|
|
307
|
-
default:
|
|
308
|
-
return { x: w - BUTTON_SIZE - DEFAULT_OFFSET, y: h - BUTTON_SIZE - DEFAULT_OFFSET - 80 };
|
|
309
|
-
}
|
|
310
|
-
}, [position]);
|
|
296
|
+
const getDefaultOffsets = (0, import_react.useCallback)(() => {
|
|
297
|
+
return {
|
|
298
|
+
right: DEFAULT_OFFSET,
|
|
299
|
+
bottom: DEFAULT_OFFSET + 80,
|
|
300
|
+
// Extra offset from bottom
|
|
301
|
+
hasBeenDragged: false
|
|
302
|
+
};
|
|
303
|
+
}, []);
|
|
311
304
|
(0, import_react.useEffect)(() => {
|
|
312
305
|
const saved = localStorage.getItem(POSITION_KEY);
|
|
313
306
|
if (saved) {
|
|
314
307
|
try {
|
|
315
308
|
const parsed = JSON.parse(saved);
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
309
|
+
if (typeof parsed.right === "number" && typeof parsed.bottom === "number") {
|
|
310
|
+
setOffsets({
|
|
311
|
+
right: Math.max(DEFAULT_OFFSET, parsed.right),
|
|
312
|
+
bottom: Math.max(DEFAULT_OFFSET, parsed.bottom),
|
|
313
|
+
hasBeenDragged: true
|
|
314
|
+
});
|
|
315
|
+
} else {
|
|
316
|
+
setOffsets(getDefaultOffsets());
|
|
317
|
+
}
|
|
322
318
|
} catch {
|
|
323
|
-
|
|
319
|
+
setOffsets(getDefaultOffsets());
|
|
324
320
|
}
|
|
325
321
|
} else {
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
}, [
|
|
329
|
-
(0, import_react.
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const newX = Math.min(coords.x, maxX);
|
|
335
|
-
const newY = Math.min(coords.y, maxY);
|
|
336
|
-
if (newX !== coords.x || newY !== coords.y) {
|
|
337
|
-
setCoords({ x: newX, y: newY });
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
window.addEventListener("resize", handleResize);
|
|
342
|
-
return () => window.removeEventListener("resize", handleResize);
|
|
343
|
-
}, [coords]);
|
|
344
|
-
const savePosition = (0, import_react.useCallback)((pos) => {
|
|
345
|
-
localStorage.setItem(POSITION_KEY, JSON.stringify(pos));
|
|
322
|
+
setOffsets(getDefaultOffsets());
|
|
323
|
+
}
|
|
324
|
+
}, [getDefaultOffsets]);
|
|
325
|
+
const savePosition = (0, import_react.useCallback)((newOffsets) => {
|
|
326
|
+
localStorage.setItem(POSITION_KEY, JSON.stringify({
|
|
327
|
+
right: newOffsets.right,
|
|
328
|
+
bottom: newOffsets.bottom
|
|
329
|
+
}));
|
|
346
330
|
}, []);
|
|
347
331
|
const handleMouseDown = (e) => {
|
|
348
332
|
if (e.button !== 0) return;
|
|
@@ -359,20 +343,24 @@ function FeedbackTrigger({
|
|
|
359
343
|
};
|
|
360
344
|
const handleMove = (0, import_react.useCallback)(
|
|
361
345
|
(clientX, clientY) => {
|
|
362
|
-
if (!isDragging || !dragStart || !
|
|
346
|
+
if (!isDragging || !dragStart || !offsets) return;
|
|
363
347
|
const deltaX = clientX - dragStart.x;
|
|
364
348
|
const deltaY = clientY - dragStart.y;
|
|
365
349
|
if (Math.abs(deltaX) > 5 || Math.abs(deltaY) > 5) {
|
|
366
350
|
setHasMoved(true);
|
|
367
351
|
}
|
|
368
|
-
const
|
|
369
|
-
const
|
|
370
|
-
const
|
|
371
|
-
const
|
|
372
|
-
|
|
352
|
+
const maxRight = window.innerWidth - BUTTON_SIZE - DEFAULT_OFFSET;
|
|
353
|
+
const maxBottom = window.innerHeight - BUTTON_SIZE - DEFAULT_OFFSET;
|
|
354
|
+
const newRight = Math.min(Math.max(DEFAULT_OFFSET, offsets.right - deltaX), maxRight);
|
|
355
|
+
const newBottom = Math.min(Math.max(DEFAULT_OFFSET, offsets.bottom - deltaY), maxBottom);
|
|
356
|
+
setOffsets({
|
|
357
|
+
right: newRight,
|
|
358
|
+
bottom: newBottom,
|
|
359
|
+
hasBeenDragged: true
|
|
360
|
+
});
|
|
373
361
|
setDragStart({ x: clientX, y: clientY });
|
|
374
362
|
},
|
|
375
|
-
[isDragging, dragStart,
|
|
363
|
+
[isDragging, dragStart, offsets]
|
|
376
364
|
);
|
|
377
365
|
const handleMouseMove = (0, import_react.useCallback)(
|
|
378
366
|
(e) => handleMove(e.clientX, e.clientY),
|
|
@@ -383,12 +371,12 @@ function FeedbackTrigger({
|
|
|
383
371
|
[handleMove]
|
|
384
372
|
);
|
|
385
373
|
const handleEnd = (0, import_react.useCallback)(() => {
|
|
386
|
-
if (isDragging &&
|
|
387
|
-
savePosition(
|
|
374
|
+
if (isDragging && offsets) {
|
|
375
|
+
savePosition(offsets);
|
|
388
376
|
}
|
|
389
377
|
setIsDragging(false);
|
|
390
378
|
setDragStart(null);
|
|
391
|
-
}, [isDragging,
|
|
379
|
+
}, [isDragging, offsets, savePosition]);
|
|
392
380
|
(0, import_react.useEffect)(() => {
|
|
393
381
|
if (isDragging) {
|
|
394
382
|
window.addEventListener("mousemove", handleMouseMove);
|
|
@@ -408,7 +396,7 @@ function FeedbackTrigger({
|
|
|
408
396
|
onClick();
|
|
409
397
|
}
|
|
410
398
|
};
|
|
411
|
-
if (!
|
|
399
|
+
if (!offsets || isOpen) return null;
|
|
412
400
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
413
401
|
"button",
|
|
414
402
|
{
|
|
@@ -421,8 +409,8 @@ function FeedbackTrigger({
|
|
|
421
409
|
isDragging && "fw-trigger--dragging"
|
|
422
410
|
),
|
|
423
411
|
style: {
|
|
424
|
-
|
|
425
|
-
|
|
412
|
+
right: offsets.right,
|
|
413
|
+
bottom: offsets.bottom,
|
|
426
414
|
width: BUTTON_SIZE,
|
|
427
415
|
height: BUTTON_SIZE,
|
|
428
416
|
backgroundColor: accentColor
|