@farm-investimentos/front-mfe-components 15.14.2 → 15.14.4

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": "@farm-investimentos/front-mfe-components",
3
- "version": "15.14.2",
3
+ "version": "15.14.4",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -28,7 +28,9 @@
28
28
  <div class="farm-tooltip__title">
29
29
  <slot name="title"></slot>
30
30
  </div>
31
- <span v-if="externalControl" class="farm-tooltip__close" @click="onClose">×</span>
31
+ <span v-if="externalControl" class="farm-tooltip__close" @click="onClose"
32
+
33
+ </span>
32
34
  </div>
33
35
  <div class="farm-tooltip__content">
34
36
  <slot />
@@ -103,6 +105,9 @@ export default defineComponent({
103
105
  const hasTitle = computed(() => !!slots.title);
104
106
 
105
107
  let hasBeenBoostrapped = false;
108
+ let scrollListener = null;
109
+ let isInsideModal = false;
110
+ let modalScrollElements = [];
106
111
 
107
112
  const calculatePosition = () => {
108
113
  const parentBoundingClientRect = parent.value.getBoundingClientRect();
@@ -117,50 +122,87 @@ export default defineComponent({
117
122
  let left = 0;
118
123
  let top = 0;
119
124
 
120
- if (!props.position) {
121
- left =
122
- parentBoundingClientRect.left +
123
- window.scrollX +
124
- activatorWidth / 2 -
125
- popupWidth / 2;
125
+ // Se estiver dentro de um modal, usar coordenadas da viewport (position fixed)
126
+ if (isInsideModal) {
127
+ if (!props.position) {
128
+ left = activatorBoundingClientRect.left + activatorWidth / 2 - popupWidth / 2;
129
+ top = activatorBoundingClientRect.top - popupHeight - 8;
130
+ } else {
131
+ const [verticalPosition, horizontalAlignment] = props.position.split('-');
126
132
 
127
- top = parentBoundingClientRect.top + window.scrollY - popupHeight - 8;
128
- } else {
129
- const [verticalPosition, horizontalAlignment] = props.position.split('-');
130
-
131
- switch (horizontalAlignment) {
132
- case 'left':
133
- left = parentBoundingClientRect.left + window.scrollX - 8;
134
- break;
135
- case 'right':
136
- left =
137
- parentBoundingClientRect.left +
138
- window.scrollX +
139
- activatorWidth -
140
- popupWidth +
141
- 8;
142
- break;
143
- case 'center':
144
- default:
145
- left =
146
- parentBoundingClientRect.left +
147
- window.scrollX +
148
- activatorWidth / 2 -
149
- popupWidth / 2;
150
- break;
133
+ switch (horizontalAlignment) {
134
+ case 'left':
135
+ left = activatorBoundingClientRect.left - 8;
136
+ break;
137
+ case 'right':
138
+ left = activatorBoundingClientRect.left + activatorWidth - popupWidth + 8;
139
+ break;
140
+ case 'center':
141
+ default:
142
+ left = activatorBoundingClientRect.left + activatorWidth / 2 - popupWidth / 2;
143
+ break;
144
+ }
145
+
146
+ if (verticalPosition === 'top') {
147
+ top = activatorBoundingClientRect.top - popupHeight - 8;
148
+ } else {
149
+ top = activatorBoundingClientRect.top + activatorHeight + 8;
150
+ }
151
+ }
152
+
153
+ // Ajustar para não sair da viewport
154
+ if (left < 5) {
155
+ left = 5;
156
+ } else if (left + popupWidth > window.innerWidth - 5) {
157
+ left = window.innerWidth - popupWidth - 5;
151
158
  }
159
+ } else {
160
+ // Comportamento original para tooltips fora de modais
161
+ if (!props.position) {
162
+ left =
163
+ parentBoundingClientRect.left +
164
+ window.scrollX +
165
+ activatorWidth / 2 -
166
+ popupWidth / 2;
152
167
 
153
- if (verticalPosition === 'top') {
154
168
  top = parentBoundingClientRect.top + window.scrollY - popupHeight - 8;
155
169
  } else {
156
- top = parentBoundingClientRect.top + window.scrollY + activatorHeight + 8;
170
+ const [verticalPosition, horizontalAlignment] = props.position.split('-');
171
+
172
+ switch (horizontalAlignment) {
173
+ case 'left':
174
+ left = parentBoundingClientRect.left + window.scrollX - 8;
175
+ break;
176
+ case 'right':
177
+ left =
178
+ parentBoundingClientRect.left +
179
+ window.scrollX +
180
+ activatorWidth -
181
+ popupWidth +
182
+ 8;
183
+ break;
184
+ case 'center':
185
+ default:
186
+ left =
187
+ parentBoundingClientRect.left +
188
+ window.scrollX +
189
+ activatorWidth / 2 -
190
+ popupWidth / 2;
191
+ break;
192
+ }
193
+
194
+ if (verticalPosition === 'top') {
195
+ top = parentBoundingClientRect.top + window.scrollY - popupHeight - 8;
196
+ } else {
197
+ top = parentBoundingClientRect.top + window.scrollY + activatorHeight + 8;
198
+ }
157
199
  }
158
- }
159
200
 
160
- if (left < window.scrollX) {
161
- left = window.scrollX + 5;
162
- } else if (left + popupWidth > window.innerWidth + window.scrollX) {
163
- left = window.innerWidth + window.scrollX - popupWidth - 5;
201
+ if (left < window.scrollX) {
202
+ left = window.scrollX + 5;
203
+ } else if (left + popupWidth > window.innerWidth + window.scrollX) {
204
+ left = window.innerWidth + window.scrollX - popupWidth - 5;
205
+ }
164
206
  }
165
207
 
166
208
  return { left, top };
@@ -177,8 +219,62 @@ export default defineComponent({
177
219
 
178
220
  if (!hasBeenBoostrapped) {
179
221
  document.querySelector('body').appendChild(popup.value);
222
+
223
+ // Detectar se está dentro de um modal
224
+ isInsideModal = !!parent.value.closest('.farm-modal');
225
+
226
+ if (isInsideModal) {
227
+ // Usar position fixed para tooltips dentro de modais
228
+ popup.value.style.position = 'fixed';
229
+ // Adicionar listener de scroll para recalcular posição
230
+ scrollListener = () => {
231
+ const { left, top } = calculatePosition();
232
+ styles.left = `${left}px`;
233
+ styles.top = `${top}px`;
234
+ };
235
+
236
+ // Escutar scroll da window E do modal
237
+ window.addEventListener('scroll', scrollListener, true);
238
+
239
+ // Encontrar o modal e escutar seu scroll interno também
240
+ const modalElement = parent.value.closest('.farm-modal');
241
+ if (modalElement) {
242
+ // Função para detectar elementos scrolláveis
243
+ const isScrollable = (element) => {
244
+ const style = window.getComputedStyle(element);
245
+ return (
246
+ style.overflow === 'auto' ||
247
+ style.overflow === 'scroll' ||
248
+ style.overflowY === 'auto' ||
249
+ style.overflowY === 'scroll' ||
250
+ style.overflowX === 'auto' ||
251
+ style.overflowX === 'scroll'
252
+ );
253
+ };
254
+
255
+ // Buscar todos os elementos dentro do modal
256
+ const allElements = modalElement.querySelectorAll('*');
257
+ const scrollableElements = Array.from(allElements).filter(isScrollable);
258
+
259
+ // Adicionar elementos específicos do modal que podem ter scroll
260
+ const modalSpecificElements = modalElement.querySelectorAll(
261
+ '.farm-modal--content, .farm-modal--content > div, [data-simplebar], .simplebar-content-wrapper'
262
+ );
263
+
264
+ // Combinar e remover duplicatas
265
+ const elementsToWatch = [...new Set([...scrollableElements, ...modalSpecificElements, modalElement])];
266
+
267
+ elementsToWatch.forEach(element => {
268
+ element.addEventListener('scroll', scrollListener, true);
269
+ modalScrollElements.push(element);
270
+ });
271
+ }
272
+ } else {
273
+ // Comportamento original para tooltips fora de modais
274
+ popup.value.style.position = 'absolute';
275
+ }
276
+
180
277
  const { left, top } = calculatePosition();
181
-
182
278
  styles.left = `${left}px`;
183
279
  styles.top = `${top}px`;
184
280
  styles.zIndex = calculateMainZindex();
@@ -202,6 +298,20 @@ export default defineComponent({
202
298
  // Se não está no parent, agenda o hide com um pequeno delay para evitar flickering
203
299
  hideTimeout = window.setTimeout(() => {
204
300
  showOver.value = false;
301
+
302
+ // Remover listeners de scroll quando tooltip for escondido
303
+ if (scrollListener) {
304
+ window.removeEventListener('scroll', scrollListener, true);
305
+
306
+ // Remover listeners dos elementos de scroll do modal
307
+ modalScrollElements.forEach(element => {
308
+ element.removeEventListener('scroll', scrollListener, true);
309
+ });
310
+ modalScrollElements = [];
311
+
312
+ scrollListener = null;
313
+ }
314
+
205
315
  hideTimeout = null;
206
316
  }, 50);
207
317
  }
@@ -221,6 +331,19 @@ export default defineComponent({
221
331
  hideTimeout = null;
222
332
  }
223
333
 
334
+ // Limpar listeners de scroll se existirem
335
+ if (scrollListener) {
336
+ window.removeEventListener('scroll', scrollListener, true);
337
+
338
+ // Remover listeners dos elementos de scroll do modal
339
+ modalScrollElements.forEach(element => {
340
+ element.removeEventListener('scroll', scrollListener, true);
341
+ });
342
+ modalScrollElements = [];
343
+
344
+ scrollListener = null;
345
+ }
346
+
224
347
  if (hasBeenBoostrapped) {
225
348
  document.querySelector('body').removeChild(popup.value);
226
349
  }