@invopop/popui 0.1.101 → 0.1.103

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.
@@ -15,6 +15,7 @@ declare class SidebarState {
15
15
  constructor(props: SidebarStateProps);
16
16
  get isMobile(): boolean;
17
17
  setWidth: (px: number) => void;
18
+ persistWidth: () => void;
18
19
  resetWidth: () => void;
19
20
  handleShortcutKeydown: (e: KeyboardEvent) => void;
20
21
  setOpenMobile: (value: boolean) => void;
@@ -26,13 +26,15 @@ class SidebarState {
26
26
  setWidth = (px) => {
27
27
  const clamped = Math.max(SIDEBAR_MIN_WIDTH_PX, Math.min(SIDEBAR_MAX_WIDTH_PX, px));
28
28
  this.width = `${clamped}px`;
29
- if (typeof localStorage !== 'undefined') {
30
- try {
31
- localStorage.setItem(SIDEBAR_WIDTH_STORAGE_KEY, this.width);
32
- }
33
- catch {
34
- // ignore quota / private-mode errors
35
- }
29
+ };
30
+ persistWidth = () => {
31
+ if (typeof localStorage === 'undefined')
32
+ return;
33
+ try {
34
+ localStorage.setItem(SIDEBAR_WIDTH_STORAGE_KEY, this.width);
35
+ }
36
+ catch {
37
+ // ignore quota / private-mode errors
36
38
  }
37
39
  };
38
40
  resetWidth = () => {
@@ -21,8 +21,10 @@
21
21
  let dragMoved = false
22
22
  let dragDirection: 1 | -1 = 1
23
23
  let activePointerId: number | null = null
24
+ let resizeCommitted = false
24
25
 
25
26
  let isDragging = $state(false)
27
+ let isPointerDown = $state(false)
26
28
  let tooltipOpen = $state(false)
27
29
  let cursorX = $state(0)
28
30
  let cursorY = $state(0)
@@ -30,8 +32,6 @@
30
32
  const TOOLTIP_HOVER_DELAY_MS = 700
31
33
  const TOOLTIP_CURSOR_OFFSET = 12
32
34
 
33
- let tooltipDelay = $derived(isDragging ? Number.MAX_SAFE_INTEGER : TOOLTIP_HOVER_DELAY_MS)
34
-
35
35
  let cursorAnchor = $derived.by(() => {
36
36
  const x = cursorX
37
37
  const y = cursorY
@@ -40,6 +40,27 @@
40
40
  }
41
41
  })
42
42
 
43
+ $effect(() => {
44
+ if ((isDragging || isPointerDown) && tooltipOpen) {
45
+ tooltipOpen = false
46
+ }
47
+ })
48
+
49
+ let globalDragStyleEl: HTMLStyleElement | null = null
50
+
51
+ function setGlobalDragStyles() {
52
+ if (globalDragStyleEl) return
53
+ globalDragStyleEl = document.createElement('style')
54
+ globalDragStyleEl.textContent =
55
+ '*, *::before, *::after { cursor: col-resize !important; user-select: none !important; }'
56
+ document.head.appendChild(globalDragStyleEl)
57
+ }
58
+
59
+ function clearGlobalDragStyles() {
60
+ globalDragStyleEl?.remove()
61
+ globalDragStyleEl = null
62
+ }
63
+
43
64
  const POST_DRAG_CLICK_GUARD_MS = 250
44
65
  let dragEndTime = 0
45
66
 
@@ -63,10 +84,14 @@
63
84
  window.removeEventListener('pointercancel', onWindowPointerUp)
64
85
  activePointerId = null
65
86
  }
66
- document.body.style.cursor = ''
67
- document.body.style.userSelect = ''
87
+ clearGlobalDragStyles()
68
88
  isDragging = false
89
+ isPointerDown = false
69
90
  sidebar.isResizing = false
91
+ if (dragMoved && !resizeCommitted) {
92
+ sidebar.persistWidth()
93
+ }
94
+ resizeCommitted = false
70
95
  if (dragMoved) {
71
96
  dragEndTime = Date.now()
72
97
  dragMoved = false
@@ -77,6 +102,7 @@
77
102
  if (e.pointerId !== activePointerId) return
78
103
  cursorX = e.clientX
79
104
  cursorY = e.clientY
105
+ if (resizeCommitted) return
80
106
  const delta = (e.clientX - dragStartX) * dragDirection
81
107
  if (Math.abs(delta) > SIDEBAR_DRAG_THRESHOLD_PX) {
82
108
  dragMoved = true
@@ -87,14 +113,14 @@
87
113
  if (!dragMoved) return
88
114
  if (sidebar.state === 'collapsed') {
89
115
  if (delta > 0) {
90
- endDrag()
116
+ resizeCommitted = true
91
117
  sidebar.setOpen(true)
92
118
  }
93
119
  return
94
120
  }
95
121
  const targetWidth = dragStartWidthPx + delta
96
122
  if (targetWidth < SIDEBAR_WIDTH_ICON_PX) {
97
- endDrag()
123
+ resizeCommitted = true
98
124
  sidebar.resetWidth()
99
125
  sidebar.setOpen(false)
100
126
  return
@@ -119,8 +145,9 @@
119
145
  dragStartX = e.clientX
120
146
  dragMoved = false
121
147
  activePointerId = e.pointerId
122
- document.body.style.cursor = 'col-resize'
123
- document.body.style.userSelect = 'none'
148
+ isPointerDown = true
149
+ tooltipOpen = false
150
+ setGlobalDragStyles()
124
151
  window.addEventListener('pointermove', onWindowPointerMove)
125
152
  window.addEventListener('pointerup', onWindowPointerUp)
126
153
  window.addEventListener('pointercancel', onWindowPointerUp)
@@ -153,7 +180,7 @@
153
180
 
154
181
  <TooltipPrimitive.Root
155
182
  bind:open={tooltipOpen}
156
- delayDuration={tooltipDelay}
183
+ delayDuration={TOOLTIP_HOVER_DELAY_MS}
157
184
  disableHoverableContent
158
185
  >
159
186
  <TooltipPrimitive.Trigger>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@invopop/popui",
3
3
  "license": "MIT",
4
- "version": "0.1.101",
4
+ "version": "0.1.103",
5
5
  "repository": {
6
6
  "url": "https://github.com/invopop/popui"
7
7
  },