dsh-plugin-greeting-bubble 1.5.1 → 1.5.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/README.md +2 -2
- package/client.js +25 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
- 详情里可以**隐藏金额(隐私模式)**:金额变为 `••••` 并记住,适合截图/录屏。
|
|
43
43
|
- 未登录、账号服务不可用或请求失败时显示 `--`,不影响其他功能。
|
|
44
44
|
- 展开后用右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
|
|
45
|
-
-
|
|
45
|
+
- **按住机器人或卡片可以拖动**:光标变成抓手,拖到任意位置松手即可;位置按“距右下角的偏移”记录,所以窗口缩放、最大化后会继续贴着右下角,不会跑到屏幕外。
|
|
46
46
|
- 默认位置刻意抬到输入框上方,不会盖住发送按钮;拖动后由你决定位置。控件需要接收拖动事件,所以它所在的小块区域会接住点击,其余区域不受影响。
|
|
47
47
|
- 在「插件」「设置」等页面同样显示(浮层属于整个应用框架)。
|
|
48
48
|
- 进入动画在系统开启“减少动态效果”时自动关闭;窄窗口下气泡最大宽度自动收缩,不会被拖出屏幕(拖动时自动限制在可视区内)。
|
|
@@ -106,7 +106,7 @@ git clone https://github.com/liwei169/dsh-plugin-greeting-bubble.git
|
|
|
106
106
|
| 详情里的「隐藏金额 / 显示金额」 | 切换隐私模式并记住 |
|
|
107
107
|
| 余额低于 ¥8 | 机器人变橙,胶囊显示橙色圆点 |
|
|
108
108
|
| 连接断开 | 机器人变灰、闭眼 |
|
|
109
|
-
| 刷新页面 |
|
|
109
|
+
| 刷新页面 | 挂件再次出现,保持上次拖动的右下角偏移 |
|
|
110
110
|
| 插件页关闭该包的开关 | 挂件立即消失(HMR 生效时无需刷新) |
|
|
111
111
|
| 插件页卸载该包 | 彻底移除,不再出现 |
|
|
112
112
|
|
package/client.js
CHANGED
|
@@ -27,8 +27,8 @@ window.__ModuleLoader__.load({
|
|
|
27
27
|
/** Locale namespace owned by this plugin (registered in `apply`). */
|
|
28
28
|
const NS = 'greetingBubble';
|
|
29
29
|
|
|
30
|
-
/** Where the reader last dropped the widget, as
|
|
31
|
-
const POSITION_KEY = 'dsh-greeting-bubble:position:
|
|
30
|
+
/** Where the reader last dropped the widget, as offsets from the bottom-right corner. */
|
|
31
|
+
const POSITION_KEY = 'dsh-greeting-bubble:position:v3';
|
|
32
32
|
|
|
33
33
|
/** Whether amounts are hidden. */
|
|
34
34
|
const PRIVACY_KEY = 'dsh-greeting-bubble:privacy:v1';
|
|
@@ -56,8 +56,8 @@ window.__ModuleLoader__.load({
|
|
|
56
56
|
const raw = window.localStorage.getItem(POSITION_KEY);
|
|
57
57
|
if (!raw) return null;
|
|
58
58
|
const value = JSON.parse(raw);
|
|
59
|
-
if (typeof value?.
|
|
60
|
-
return {
|
|
59
|
+
if (typeof value?.right === 'number' && typeof value?.bottom === 'number') {
|
|
60
|
+
return { right: value.right, bottom: value.bottom };
|
|
61
61
|
}
|
|
62
62
|
} catch {
|
|
63
63
|
// Private mode, blocked storage, or malformed JSON: fall through.
|
|
@@ -510,7 +510,6 @@ window.__ModuleLoader__.load({
|
|
|
510
510
|
const [refreshing, setRefreshing] = React.useState(false);
|
|
511
511
|
const widgetRef = React.useRef(null);
|
|
512
512
|
const dragRef = React.useRef(null);
|
|
513
|
-
const bottomAnchorRef = React.useRef(null);
|
|
514
513
|
const suppressClickRef = React.useRef(false);
|
|
515
514
|
const inFlightRef = React.useRef(null);
|
|
516
515
|
const profileRef = React.useRef(null);
|
|
@@ -604,35 +603,34 @@ window.__ModuleLoader__.load({
|
|
|
604
603
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
605
604
|
}, []);
|
|
606
605
|
|
|
607
|
-
// Keep
|
|
606
|
+
// Keep the remembered offsets valid when the window shrinks.
|
|
608
607
|
React.useEffect(() => {
|
|
609
608
|
function handleResize() {
|
|
610
609
|
setPosition((current) => {
|
|
611
610
|
const element = widgetRef.current;
|
|
612
611
|
if (current === null || element === null) return current;
|
|
613
|
-
const
|
|
614
|
-
const
|
|
615
|
-
return
|
|
612
|
+
const right = clamp(current.right, 0, Math.max(0, window.innerWidth - element.offsetWidth));
|
|
613
|
+
const bottom = clamp(current.bottom, 0, Math.max(0, window.innerHeight - element.offsetHeight));
|
|
614
|
+
return right === current.right && bottom === current.bottom ? current : { right, bottom };
|
|
616
615
|
});
|
|
617
616
|
}
|
|
618
617
|
window.addEventListener('resize', handleResize);
|
|
619
618
|
return () => { window.removeEventListener('resize', handleResize); };
|
|
620
619
|
}, []);
|
|
621
620
|
|
|
622
|
-
//
|
|
623
|
-
//
|
|
621
|
+
// Bottom-anchored: expansion grows upward. Only nudge down when the card
|
|
622
|
+
// is taller than the room above it.
|
|
624
623
|
React.useEffect(() => {
|
|
624
|
+
if (!expanded) return;
|
|
625
625
|
const element = widgetRef.current;
|
|
626
|
-
|
|
627
|
-
if (!element || bottom === null) return;
|
|
628
|
-
bottomAnchorRef.current = null;
|
|
626
|
+
if (!element) return;
|
|
629
627
|
const rect = element.getBoundingClientRect();
|
|
630
628
|
const margin = 8;
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
629
|
+
if (rect.top < margin) {
|
|
630
|
+
setPosition((current) => current === null ? current : {
|
|
631
|
+
right: current.right,
|
|
632
|
+
bottom: Math.max(0, window.innerHeight - rect.height - margin),
|
|
633
|
+
});
|
|
636
634
|
}
|
|
637
635
|
}, [expanded]);
|
|
638
636
|
|
|
@@ -670,8 +668,6 @@ window.__ModuleLoader__.load({
|
|
|
670
668
|
|
|
671
669
|
/** Expand/collapse; the first expansion loads the account profile. */
|
|
672
670
|
function toggleExpanded() {
|
|
673
|
-
const element = widgetRef.current;
|
|
674
|
-
if (element) bottomAnchorRef.current = element.getBoundingClientRect().bottom;
|
|
675
671
|
setExpanded((current) => {
|
|
676
672
|
const next = !current;
|
|
677
673
|
if (next && profile === null) {
|
|
@@ -703,13 +699,13 @@ window.__ModuleLoader__.load({
|
|
|
703
699
|
pointerId: event.pointerId,
|
|
704
700
|
startX: event.clientX,
|
|
705
701
|
startY: event.clientY,
|
|
706
|
-
|
|
707
|
-
|
|
702
|
+
startRight: window.innerWidth - rect.right,
|
|
703
|
+
startBottom: window.innerHeight - rect.bottom,
|
|
708
704
|
width: rect.width,
|
|
709
705
|
height: rect.height,
|
|
710
706
|
moved: false,
|
|
711
707
|
};
|
|
712
|
-
setPosition({
|
|
708
|
+
setPosition({ right: dragRef.current.startRight, bottom: dragRef.current.startBottom });
|
|
713
709
|
setDragging(true);
|
|
714
710
|
if (typeof element.setPointerCapture === 'function') {
|
|
715
711
|
element.setPointerCapture(event.pointerId);
|
|
@@ -725,8 +721,8 @@ window.__ModuleLoader__.load({
|
|
|
725
721
|
const dy = event.clientY - drag.startY;
|
|
726
722
|
if (!drag.moved && Math.abs(dx) + Math.abs(dy) > DRAG_THRESHOLD) drag.moved = true;
|
|
727
723
|
setPosition({
|
|
728
|
-
|
|
729
|
-
|
|
724
|
+
right: clamp(drag.startRight - dx, 0, Math.max(0, window.innerWidth - drag.width)),
|
|
725
|
+
bottom: clamp(drag.startBottom - dy, 0, Math.max(0, window.innerHeight - drag.height)),
|
|
730
726
|
});
|
|
731
727
|
}
|
|
732
728
|
|
|
@@ -740,8 +736,8 @@ window.__ModuleLoader__.load({
|
|
|
740
736
|
if (!element) return;
|
|
741
737
|
const rect = element.getBoundingClientRect();
|
|
742
738
|
const dropped = {
|
|
743
|
-
|
|
744
|
-
|
|
739
|
+
right: Math.round(clamp(window.innerWidth - rect.right, 0, Math.max(0, window.innerWidth - rect.width))),
|
|
740
|
+
bottom: Math.round(clamp(window.innerHeight - rect.bottom, 0, Math.max(0, window.innerHeight - rect.height))),
|
|
745
741
|
};
|
|
746
742
|
setPosition(dropped);
|
|
747
743
|
writePosition(dropped);
|
|
@@ -777,7 +773,7 @@ window.__ModuleLoader__.load({
|
|
|
777
773
|
'data-disconnected': connectionState === 'disconnected' ? '' : undefined,
|
|
778
774
|
style: position === null
|
|
779
775
|
? undefined
|
|
780
|
-
: {
|
|
776
|
+
: { right: position.right, bottom: position.bottom, left: 'auto', top: 'auto' },
|
|
781
777
|
onPointerDown: beginDrag,
|
|
782
778
|
onPointerMove: moveDrag,
|
|
783
779
|
onPointerUp: endDrag,
|