its_ui_vite 1.1.11 → 1.1.13

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": "its_ui_vite",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "main": "./src/libIndex.js",
5
5
  "module": "./src/libIndex.js",
6
6
  "files": [
@@ -61,7 +61,7 @@ export function addTracingElement(target, moveFn = () => {}) {
61
61
  let positionInfo;
62
62
  let lockPosition = true;
63
63
 
64
- const handlesEvents = ['mousemove', 'wheel', 'load', 'fullscreenchange', 'webkitfullscreenchange', 'mozfullscreenchange', 'msfullscreenchange']
64
+ const handlesEvents = ['wheel', 'load', 'fullscreenchange', 'webkitfullscreenchange', 'mozfullscreenchange', 'msfullscreenchange']
65
65
 
66
66
  function setPositionInfo(position, e) {
67
67
  positionInfo = {
@@ -74,6 +74,10 @@ export function addTracingElement(target, moveFn = () => {}) {
74
74
  }
75
75
  }
76
76
 
77
+ function isMoveTarget(position) {
78
+ return position.top !== target.value?.getBoundingClientRect().top;
79
+ }
80
+
77
81
  function isVisible(position) {
78
82
  if (!position) return false
79
83
 
@@ -120,12 +124,15 @@ export function addTracingElement(target, moveFn = () => {}) {
120
124
  lockPosition = !e?.deltaY;
121
125
 
122
126
  if (timer) return;
123
- dispatch(positionInfo);
127
+ // это нужно чтобы проверить сдвинулся ли скролл
128
+ requestAnimationFrame(() => {
129
+ if (isMoveTarget(position)) dispatch(positionInfo);
130
+ });
124
131
 
125
132
  timer = setTimeout(() => {
126
133
  timer = undefined;
127
134
 
128
- dispatch(positionInfo);
135
+ if (isMoveTarget(position)) dispatch(positionInfo);
129
136
 
130
137
  // здесь debounce т.к. не всегда привязанный элемент встает на место
131
138
  clearTimeout(debounceTimer);
@@ -139,19 +146,31 @@ export function addTracingElement(target, moveFn = () => {}) {
139
146
  }, 100);
140
147
  }
141
148
 
149
+ function setDargHandler(e) {
150
+ if (e.type === 'mousedown') document.body.addEventListener('mousemove', targetMoveHandler)
151
+ else document.body.removeEventListener('mousemove', targetMoveHandler)
152
+ }
153
+
142
154
  function addListeners() {
143
155
  handlesEvents.forEach((eventName) => {
144
156
  const handleRoot = eventName === 'load' ? window : document.body
145
157
  handleRoot.addEventListener(eventName, targetMoveHandler)
146
158
  })
147
- targetMoveHandler()
159
+
160
+ document.body.addEventListener('mousedown', setDargHandler)
161
+ document.body.addEventListener('mouseup', setDargHandler)
162
+
163
+ dispatch(target.value?.getBoundingClientRect());
148
164
  }
149
165
 
150
166
  function removeListeners() {
151
167
  handlesEvents.forEach((eventName) => {
152
168
  const handleRoot = eventName === 'load' ? window : document.body
153
169
  handleRoot.removeEventListener(eventName, targetMoveHandler)
154
- })
170
+ });
171
+
172
+ document.body.removeEventListener('mousedown', setDargHandler)
173
+ document.body.removeEventListener('mouseup', setDargHandler)
155
174
  }
156
175
 
157
176
  return {