@mingxy/opencode-mascot 0.3.9 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mingxy/opencode-mascot",
3
- "version": "0.3.9",
3
+ "version": "0.4.0",
4
4
  "description": "OpenCode TUI mascot plugin framework - customizable ASCII mascots for your terminal",
5
5
  "author": "mingxy",
6
6
  "license": "MIT",
@@ -20,7 +20,8 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
20
20
  const initialName = names[Math.floor(Math.random() * names.length)];
21
21
 
22
22
  const [currentName, setCurrentName] = createSignal(initialName);
23
- let boxRef: any = null;
23
+ const [posX, setPosX] = createSignal(0);
24
+ const [posY, setPosY] = createSignal(0);
24
25
  let dragStartX = 0;
25
26
  let dragStartY = 0;
26
27
  let dragAnchorX = 0;
@@ -47,12 +48,18 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
47
48
  renderers[currentName()].showVersion(version);
48
49
  });
49
50
 
51
+ const stopDrag = () => {
52
+ isDragging = false;
53
+ renderers[currentName()].setDragging(false);
54
+ };
55
+
50
56
  return (
51
57
  <box
58
+ left={posX()}
59
+ top={posY()}
52
60
  alignItems="center"
53
61
  zIndex={9999}
54
62
  flexDirection="column"
55
- ref={(node: any) => { boxRef = node; }}
56
63
  onMouseDown={(e: any) => {
57
64
  const now = Date.now();
58
65
  if (now - lastClickTime < 300) {
@@ -62,35 +69,30 @@ export function HomeMascot(props: HomeMascotProps): JSX.Element {
62
69
  }
63
70
  lastClickTime = now;
64
71
 
65
- if (e.modifiers?.alt && boxRef) {
72
+ if (e.modifiers?.alt) {
66
73
  dragStartX = e.x;
67
74
  dragStartY = e.y;
68
- dragAnchorX = boxRef.translateX || 0;
69
- dragAnchorY = boxRef.translateY || 0;
75
+ dragAnchorX = posX();
76
+ dragAnchorY = posY();
70
77
  isDragging = true;
71
78
  renderers[currentName()].setDragging(true);
79
+ e.preventDefault();
80
+ e.stopPropagation();
81
+ props.api.renderer.clearSelection();
72
82
  }
73
83
  }}
74
84
  onMouseDrag={(e: any) => {
75
- if (e.modifiers?.alt && isDragging && boxRef) {
76
- boxRef.translateX = dragAnchorX + (e.x - dragStartX);
77
- boxRef.translateY = dragAnchorY + (e.y - dragStartY);
78
- }
79
- }}
80
- onMouseUp={() => {
81
- isDragging = false;
82
- renderers[currentName()].setDragging(false);
83
- }}
84
- onMouseDragEnd={() => {
85
- isDragging = false;
86
- renderers[currentName()].setDragging(false);
87
- }}
88
- onMouseOut={() => {
89
- if (isDragging) {
90
- isDragging = false;
91
- renderers[currentName()].setDragging(false);
85
+ if (e.modifiers?.alt && isDragging) {
86
+ setPosX(dragAnchorX + (e.x - dragStartX));
87
+ setPosY(dragAnchorY + (e.y - dragStartY));
88
+ e.preventDefault();
89
+ e.stopPropagation();
90
+ props.api.renderer.clearSelection();
92
91
  }
93
92
  }}
93
+ onMouseUp={() => { stopDrag(); }}
94
+ onMouseDragEnd={() => { stopDrag(); }}
95
+ onMouseOut={() => { stopDrag(); }}
94
96
  >
95
97
  {renderers[currentName()]?.element() ?? null}
96
98
  </box>
@@ -225,6 +225,9 @@ export function SidebarMascot(props: SidebarMascotProps): JSX.Element {
225
225
  if (e.modifiers?.alt && isDragging) {
226
226
  setPosX(clampX(dragAnchorX + (e.x - dragStartX)));
227
227
  setPosY(clampY(dragAnchorY + (e.y - dragStartY)));
228
+ e.preventDefault();
229
+ e.stopPropagation();
230
+ props.api.renderer.clearSelection();
228
231
  }
229
232
  }}
230
233
  onMouseUp={() => {