vgapp 1.2.4 → 1.2.5

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.
@@ -0,0 +1,64 @@
1
+ /**
2
+ *--------------------------------------------------------------------------
3
+ * Модуль: VGTooltip
4
+ * Автор: Vegas DEV
5
+ * Лицензия: смотри LICENSE
6
+ *--------------------------------------------------------------------------
7
+ **/
8
+
9
+ @import "../../../utils/scss/functions";
10
+ @import "../../../utils/scss/mixin";
11
+ @import "../../../utils/scss/variables";
12
+ @import "variables";
13
+
14
+ .vg-tooltip {
15
+ @include mix-vars('tooltip', $tooltip-map );
16
+ position: absolute;
17
+ z-index: var(--vg-tooltip-zindex);
18
+ pointer-events: none;
19
+ opacity: 0;
20
+ visibility: hidden;
21
+ transition: opacity .15s ease, transform .15s ease, visibility .15s ease;
22
+ transform: none !important;
23
+
24
+ &.show {
25
+ opacity: 1;
26
+ visibility: visible;
27
+ }
28
+
29
+ &-inner {
30
+ position: relative;
31
+ max-width: var(--vg-tooltip-max-width);
32
+ padding: var(--vg-tooltip-padding);
33
+ font-size: var(--vg-tooltip-font-size);
34
+ line-height: var(--vg-tooltip-line-height);
35
+ color: var(--vg-tooltip-color);
36
+ background: var(--vg-tooltip-background);
37
+ border-radius: var(--vg-tooltip-border-radius);
38
+ box-shadow: var(--vg-tooltip-box-shadow);
39
+ word-break: var(--vg-tooltip-word-break);
40
+ }
41
+
42
+ &-arrow {
43
+ position: absolute;
44
+ width: var(--vg-tooltip-arrow-width);
45
+ height: var(--vg-tooltip-arrow-height);
46
+ background: var(--vg-tooltip-background, #222);
47
+ transform: rotate(45deg);
48
+ }
49
+
50
+ &-popover {
51
+ .vg-tooltip-inner {
52
+ padding: 0;
53
+
54
+ &--title {
55
+ padding: var(--vg-tooltip-padding);
56
+ border-bottom: 1px solid var(--vg-tooltip-border-color);
57
+ }
58
+
59
+ &--content {
60
+ padding: var(--vg-tooltip-padding);
61
+ }
62
+ }
63
+ }
64
+ }
@@ -1,9 +1,4 @@
1
- import {mergeDeepObject, normalizeData} from "../functions";
2
- import {Classes} from "../dom/manipulator";
3
-
4
- /**
5
- * Класс Placement, определяет и устанавливает местоположение элемента на странице.
6
- */
1
+ import {mergeDeepObject} from "../functions";
7
2
 
8
3
  class Placement {
9
4
  constructor(config) {
@@ -16,20 +11,9 @@ class Placement {
16
11
  this.placement = config.placement || 'bottom';
17
12
  this.fallbackPlacements = config.fallbackPlacements || [];
18
13
 
19
- this._builtInPlacements = {
20
- top: 'top',
21
- 'top-start': 'top-start',
22
- 'top-end': 'top-end',
23
- bottom: 'bottom',
24
- 'bottom-start': 'bottom-start',
25
- 'bottom-end': 'bottom-end',
26
- left: 'left',
27
- 'left-start': 'left-start',
28
- 'left-end': 'left-end',
29
- right: 'right',
30
- 'right-start': 'right-start',
31
- 'right-end': 'right-end'
32
- };
14
+ this.clamp = config.clamp === true;
15
+ this.clampPadding = config.clampPadding ?? 8;
16
+ this.isMerge = config.isMerge !== false;
33
17
  }
34
18
 
35
19
  _getPlacementRect(element) {
@@ -38,6 +22,7 @@ class Placement {
38
22
 
39
23
  _getViewportRect() {
40
24
  const doc = document.documentElement;
25
+
41
26
  return {
42
27
  width: doc.clientWidth,
43
28
  height: doc.clientHeight,
@@ -60,56 +45,102 @@ class Placement {
60
45
  const fallbacks = [this.placement, ...this.fallbackPlacements];
61
46
  let best = null;
62
47
 
63
- for (let p of fallbacks) {
64
- let pos = this._calculatePosition(p, refRect, dropRect, xOffset, yOffset);
65
- let overflow = this._calculateOverflow(pos, viewRect);
48
+ for (const p of fallbacks) {
49
+ const position = this._calculatePosition(p, refRect, dropRect, xOffset, yOffset);
50
+ const overflow = this._calculateOverflow(position, dropRect, viewRect);
66
51
 
67
52
  if (!best || overflow < best.overflow) {
68
- best = { placement: p, position: pos, overflow };
53
+ best = { placement: p, position, overflow };
54
+
69
55
  if (overflow === 0) break;
70
56
  }
71
57
  }
72
58
 
73
59
  placement = best.placement;
74
- this._setStyles(best.position);
60
+
61
+ const finalPosition = this.clamp
62
+ ? this._clampPosition(best.position, dropRect, viewRect)
63
+ : best.position;
64
+
65
+ this._setStyles(finalPosition);
75
66
  } else {
76
- const pos = this._calculatePosition(placement, refRect, dropRect, xOffset, yOffset);
77
- this._setStyles(pos);
67
+ const position = this._calculatePosition(placement, refRect, dropRect, xOffset, yOffset);
68
+
69
+ const finalPosition = this.clamp
70
+ ? this._clampPosition(position, dropRect, viewRect)
71
+ : position;
72
+
73
+ this._setStyles(finalPosition);
78
74
  }
79
75
 
80
76
  this.drop.setAttribute('data-vg-placement', placement);
81
77
  }
82
78
 
83
79
  _calculatePosition(placement, refRect, dropRect, xOffset = 0, yOffset = 0) {
84
- let top, left;
80
+ let top;
81
+ let left;
85
82
 
86
83
  switch (placement) {
87
84
  case 'top':
85
+ top = refRect.top - dropRect.height - yOffset;
86
+ left = refRect.left + (refRect.width - dropRect.width) / 2;
87
+ break;
88
+
88
89
  case 'top-start':
89
90
  top = refRect.top - dropRect.height - yOffset;
90
- left = placement === 'top-start' ? refRect.left + xOffset : refRect.left + (refRect.width - dropRect.width) / 2;
91
+ left = refRect.left + xOffset;
91
92
  break;
93
+
92
94
  case 'top-end':
93
95
  top = refRect.top - dropRect.height - yOffset;
94
96
  left = refRect.right - dropRect.width - xOffset;
95
97
  break;
98
+
96
99
  case 'bottom':
100
+ top = refRect.bottom + yOffset;
101
+ left = refRect.left + (refRect.width - dropRect.width) / 2;
102
+ break;
103
+
97
104
  case 'bottom-start':
98
105
  top = refRect.bottom + yOffset;
99
- left = placement === 'bottom-start' ? refRect.left + xOffset : refRect.left + (refRect.width - dropRect.width) / 2;
106
+ left = refRect.left + xOffset;
100
107
  break;
108
+
101
109
  case 'bottom-end':
102
110
  top = refRect.bottom + yOffset;
103
111
  left = refRect.right - dropRect.width - xOffset;
104
112
  break;
113
+
105
114
  case 'left':
106
115
  top = refRect.top + (refRect.height - dropRect.height) / 2;
107
116
  left = refRect.left - dropRect.width - xOffset;
108
117
  break;
118
+
119
+ case 'left-start':
120
+ top = refRect.top + yOffset;
121
+ left = refRect.left - dropRect.width - xOffset;
122
+ break;
123
+
124
+ case 'left-end':
125
+ top = refRect.bottom - dropRect.height - yOffset;
126
+ left = refRect.left - dropRect.width - xOffset;
127
+ break;
128
+
109
129
  case 'right':
110
130
  top = refRect.top + (refRect.height - dropRect.height) / 2;
111
131
  left = refRect.right + xOffset;
112
132
  break;
133
+
134
+ case 'right-start':
135
+ top = refRect.top + yOffset;
136
+ left = refRect.right + xOffset;
137
+ break;
138
+
139
+ case 'right-end':
140
+ top = refRect.bottom - dropRect.height - yOffset;
141
+ left = refRect.right + xOffset;
142
+ break;
143
+
113
144
  default:
114
145
  top = refRect.bottom + yOffset;
115
146
  left = refRect.left + xOffset;
@@ -118,22 +149,62 @@ class Placement {
118
149
  return { top, left };
119
150
  }
120
151
 
121
- _calculateOverflow(pos, viewRect) {
152
+ _calculateOverflow(pos, dropRect, viewRect) {
122
153
  let overflow = 0;
123
- if (pos.left < viewRect.left) overflow += viewRect.left - pos.left;
124
- if (pos.top < viewRect.top) overflow += viewRect.top - pos.top;
125
- if (pos.left + this.drop.offsetWidth > viewRect.right) overflow += (pos.left + this.drop.offsetWidth) - viewRect.right;
126
- if (pos.top + this.drop.offsetHeight > viewRect.bottom) overflow += (pos.top + this.drop.offsetHeight) - viewRect.bottom;
154
+
155
+ if (pos.left < viewRect.left) {
156
+ overflow += viewRect.left - pos.left;
157
+ }
158
+
159
+ if (pos.top < viewRect.top) {
160
+ overflow += viewRect.top - pos.top;
161
+ }
162
+
163
+ if (pos.left + dropRect.width > viewRect.right) {
164
+ overflow += (pos.left + dropRect.width) - viewRect.right;
165
+ }
166
+
167
+ if (pos.top + dropRect.height > viewRect.bottom) {
168
+ overflow += (pos.top + dropRect.height) - viewRect.bottom;
169
+ }
170
+
127
171
  return overflow;
128
172
  }
129
173
 
174
+ _clampPosition(pos, dropRect, viewRect) {
175
+ const padding = this.clampPadding;
176
+
177
+ const maxTop = viewRect.bottom - dropRect.height - padding;
178
+ const maxLeft = viewRect.right - dropRect.width - padding;
179
+
180
+ return {
181
+ top: Math.min(
182
+ Math.max(pos.top, viewRect.top + padding),
183
+ maxTop
184
+ ),
185
+ left: Math.min(
186
+ Math.max(pos.left, viewRect.left + padding),
187
+ maxLeft
188
+ )
189
+ };
190
+ }
191
+
130
192
  _setStyles(pos) {
131
- mergeDeepObject(this.drop.style, {
132
- position: 'absolute',
133
- top: `${pos.top}px`,
134
- left: `${pos.left}px`,
135
- margin: 0
136
- })
193
+ if (!pos || !this.drop) return;
194
+
195
+ if (this.isMerge) {
196
+ mergeDeepObject(this.drop.style, {
197
+ position: 'absolute',
198
+ top: `${pos.top + window.pageYOffset}px`,
199
+ left: `${pos.left + window.pageXOffset}px`,
200
+ margin: '0'
201
+ });
202
+ } else {
203
+ this.drop.style.position = 'absolute';
204
+ this.drop.style.top = `${pos.top + window.pageYOffset}px`;
205
+ this.drop.style.left = `${pos.left + window.pageXOffset}px`;
206
+ this.drop.style.margin = '0';
207
+ }
137
208
  }
138
209
 
139
210
  _setPlacement() {