@instructure/ui-position 8.33.1 → 8.33.2
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/CHANGELOG.md +4 -0
- package/es/Position/PositionContentLocator.js +1 -0
- package/es/Position/PositionLocator.js +2 -7
- package/es/Position/PositionTargetLocator.js +1 -0
- package/es/Position/index.js +4 -41
- package/es/Position/locator.js +1 -0
- package/es/Position/props.js +1 -0
- package/es/Position/styles.js +0 -1
- package/es/Position/theme.js +2 -2
- package/es/PositionPropTypes.js +2 -2
- package/es/calculateElementPosition.js +34 -101
- package/es/executeMirrorFunction.js +4 -6
- package/es/mirrorHorizontalPlacement.js +2 -2
- package/es/mirrorPlacement.js +2 -2
- package/lib/Position/PositionContentLocator.js +1 -3
- package/lib/Position/PositionLocator.js +1 -11
- package/lib/Position/PositionTargetLocator.js +1 -3
- package/lib/Position/index.js +4 -59
- package/lib/Position/locator.js +0 -2
- package/lib/Position/props.js +1 -5
- package/lib/Position/styles.js +0 -2
- package/lib/Position/theme.js +2 -3
- package/lib/PositionPropTypes.js +2 -7
- package/lib/calculateElementPosition.js +32 -110
- package/lib/executeMirrorFunction.js +4 -8
- package/lib/index.js +0 -7
- package/lib/mirrorHorizontalPlacement.js +0 -5
- package/lib/mirrorPlacement.js +0 -5
- package/lib/parsePlacement.js +0 -1
- package/package.json +16 -16
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,32 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.calculateElementPosition = calculateElementPosition;
|
|
9
8
|
exports.default = void 0;
|
|
10
9
|
exports.parsePlacement = parsePlacement;
|
|
11
|
-
|
|
12
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
-
|
|
14
11
|
var _getBoundingClientRect = require("@instructure/ui-dom-utils/lib/getBoundingClientRect.js");
|
|
15
|
-
|
|
16
12
|
var _getScrollParents = require("@instructure/ui-dom-utils/lib/getScrollParents.js");
|
|
17
|
-
|
|
18
13
|
var _getOffsetParents = require("@instructure/ui-dom-utils/lib/getOffsetParents.js");
|
|
19
|
-
|
|
20
14
|
var _canUseDOM = require("@instructure/ui-dom-utils/lib/canUseDOM.js");
|
|
21
|
-
|
|
22
15
|
var _findDOMNode = require("@instructure/ui-dom-utils/lib/findDOMNode.js");
|
|
23
|
-
|
|
24
16
|
var _ownerDocument = require("@instructure/ui-dom-utils/lib/ownerDocument.js");
|
|
25
|
-
|
|
26
17
|
var _ownerWindow = require("@instructure/ui-dom-utils/lib/ownerWindow.js");
|
|
27
|
-
|
|
28
18
|
var _mirrorPlacement = require("./mirrorPlacement");
|
|
29
|
-
|
|
30
19
|
/*
|
|
31
20
|
* The MIT License (MIT)
|
|
32
21
|
*
|
|
@@ -50,9 +39,9 @@ var _mirrorPlacement = require("./mirrorPlacement");
|
|
|
50
39
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
51
40
|
* SOFTWARE.
|
|
52
41
|
*/
|
|
42
|
+
|
|
53
43
|
function calculateElementPosition(element, target) {
|
|
54
44
|
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
55
|
-
|
|
56
45
|
if (!element || options.placement === 'offscreen') {
|
|
57
46
|
// hide offscreen content at the bottom of the DOM from screenreaders
|
|
58
47
|
// unless content is contained somewhere else
|
|
@@ -68,14 +57,12 @@ function calculateElementPosition(element, target) {
|
|
|
68
57
|
}
|
|
69
58
|
};
|
|
70
59
|
}
|
|
71
|
-
|
|
72
60
|
const pos = new PositionData(element, target, options);
|
|
73
61
|
return {
|
|
74
62
|
placement: pos.placement,
|
|
75
63
|
style: pos.style
|
|
76
64
|
};
|
|
77
65
|
}
|
|
78
|
-
|
|
79
66
|
class PositionedElement {
|
|
80
67
|
constructor(element, placement) {
|
|
81
68
|
let offset = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
|
|
@@ -87,7 +74,6 @@ class PositionedElement {
|
|
|
87
74
|
this.rect = void 0;
|
|
88
75
|
this._offset = void 0;
|
|
89
76
|
this.node = (0, _findDOMNode.findDOMNode)(element);
|
|
90
|
-
|
|
91
77
|
if (typeof placement === 'string') {
|
|
92
78
|
this.placement = parsePlacement(placement);
|
|
93
79
|
} else if (Array.isArray(placement)) {
|
|
@@ -95,53 +81,42 @@ class PositionedElement {
|
|
|
95
81
|
} else {
|
|
96
82
|
this.placement = ['bottom', 'center'];
|
|
97
83
|
}
|
|
98
|
-
|
|
99
84
|
this.rect = (0, _getBoundingClientRect.getBoundingClientRect)(this.node);
|
|
100
85
|
this._offset = offsetToPx(offset, this.size, this.node);
|
|
101
86
|
}
|
|
102
|
-
|
|
103
87
|
get width() {
|
|
104
88
|
return this.rect.width;
|
|
105
89
|
}
|
|
106
|
-
|
|
107
90
|
get height() {
|
|
108
91
|
return this.rect.height;
|
|
109
92
|
}
|
|
110
|
-
|
|
111
93
|
get size() {
|
|
112
94
|
return {
|
|
113
95
|
width: this.width,
|
|
114
96
|
height: this.height
|
|
115
97
|
};
|
|
116
98
|
}
|
|
117
|
-
|
|
118
99
|
get position() {
|
|
119
100
|
return {
|
|
120
101
|
top: this.rect.top,
|
|
121
102
|
left: this.rect.left
|
|
122
103
|
};
|
|
123
104
|
}
|
|
124
|
-
|
|
125
105
|
get hasVerticalPlacement() {
|
|
126
106
|
return ['top', 'bottom'].indexOf(this.placement[0]) >= 0;
|
|
127
107
|
}
|
|
128
|
-
|
|
129
108
|
get hasHorizontalPlacement() {
|
|
130
109
|
return ['start', 'end'].indexOf(this.placement[0]) >= 0;
|
|
131
110
|
}
|
|
132
|
-
|
|
133
111
|
get shouldStretchVertically() {
|
|
134
112
|
return this.placement[1] === 'stretch' && this.hasVerticalPlacement;
|
|
135
113
|
}
|
|
136
|
-
|
|
137
114
|
get shouldStretchHorizontally() {
|
|
138
115
|
return this.placement[1] === 'stretch' && this.hasHorizontalPlacement;
|
|
139
116
|
}
|
|
140
|
-
|
|
141
117
|
get mirroredPlacement() {
|
|
142
118
|
return (0, _mirrorPlacement.mirrorPlacement)(this.placement);
|
|
143
119
|
}
|
|
144
|
-
|
|
145
120
|
calculateOffset(placement) {
|
|
146
121
|
const offsetMap = {
|
|
147
122
|
top: 0,
|
|
@@ -151,103 +126,86 @@ class PositionedElement {
|
|
|
151
126
|
end: '100%',
|
|
152
127
|
stretch: 0
|
|
153
128
|
};
|
|
154
|
-
|
|
155
129
|
let _placement = (0, _slicedToArray2.default)(placement, 2),
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
130
|
+
first = _placement[0],
|
|
131
|
+
second = _placement[1];
|
|
159
132
|
if (['start', 'end'].indexOf(first) >= 0) {
|
|
160
133
|
;
|
|
161
134
|
var _ref = [second, first];
|
|
162
135
|
first = _ref[0];
|
|
163
136
|
second = _ref[1];
|
|
164
137
|
}
|
|
165
|
-
|
|
166
138
|
let top = 0;
|
|
167
139
|
let left = 0;
|
|
168
|
-
|
|
169
140
|
if (typeof offsetMap[first] !== 'undefined') {
|
|
170
141
|
top = offsetMap[first];
|
|
171
142
|
}
|
|
172
|
-
|
|
173
143
|
if (typeof offsetMap[second] !== 'undefined') {
|
|
174
144
|
left = offsetMap[second];
|
|
175
145
|
}
|
|
176
|
-
|
|
177
146
|
return addOffsets([offsetToPx({
|
|
178
147
|
top,
|
|
179
148
|
left
|
|
180
149
|
}, this.size, this.node), parseOffset(this._offset, this.placement)]);
|
|
181
150
|
}
|
|
182
|
-
|
|
183
151
|
get scrollParentsOffset() {
|
|
184
152
|
const parents = (0, _getScrollParents.getScrollParents)(this.node);
|
|
185
153
|
let offsetY = 0;
|
|
186
154
|
let offsetX = 0;
|
|
187
|
-
|
|
188
155
|
for (let i = 1; i < parents.length; i++) {
|
|
189
156
|
const parent = parents[i];
|
|
190
157
|
const child = parents[i - 1];
|
|
191
|
-
|
|
192
158
|
if (parent) {
|
|
193
159
|
offsetY = offsetY + (this.normalizeScrollTop(parent) - this.normalizeScrollTop(child));
|
|
194
160
|
offsetX = offsetX + (parent.scrollLeft - child.scrollLeft);
|
|
195
161
|
}
|
|
196
162
|
}
|
|
197
|
-
|
|
198
163
|
return {
|
|
199
164
|
top: offsetY,
|
|
200
165
|
left: offsetX
|
|
201
166
|
};
|
|
202
167
|
}
|
|
203
|
-
|
|
204
168
|
get positionedParentsOffset() {
|
|
205
169
|
// If the element container is within a positioned
|
|
206
170
|
// element, it will position absolutely with respect to that
|
|
207
171
|
// ancestor. We calculate the offset between the child and
|
|
208
172
|
// positioned parent so we can negate that distance
|
|
209
173
|
const parents = (0, _getOffsetParents.getOffsetParents)(this.node);
|
|
210
|
-
const doc = (0, _ownerDocument.ownerDocument)(this.node);
|
|
174
|
+
const doc = (0, _ownerDocument.ownerDocument)(this.node);
|
|
175
|
+
|
|
176
|
+
// If there is more than one parent, the offset on the
|
|
211
177
|
// documentElement should be calculated appropriately.
|
|
212
178
|
// Otherwise we need to explictly account for that offset
|
|
213
|
-
|
|
214
179
|
let offsetY = parents.length > 1 ? 0 : (0, _getBoundingClientRect.getBoundingClientRect)(doc.documentElement).top;
|
|
215
180
|
let offsetX = 0;
|
|
216
181
|
let scrollY = 0;
|
|
217
|
-
|
|
218
182
|
for (let i = 1; i < parents.length; i++) {
|
|
219
183
|
const parent = (0, _getBoundingClientRect.getBoundingClientRect)(parents[i]);
|
|
220
184
|
const child = (0, _getBoundingClientRect.getBoundingClientRect)(parents[i - 1]);
|
|
221
185
|
offsetY = offsetY + (child.top - parent.top);
|
|
222
186
|
offsetX = offsetX + (child.left - parent.left);
|
|
223
|
-
|
|
224
187
|
if (parents[i] === doc.body) {
|
|
225
188
|
// accounts for any margin on body
|
|
226
189
|
offsetY = offsetY + parent.top;
|
|
227
190
|
offsetX = offsetX + parent.left;
|
|
228
191
|
}
|
|
229
|
-
|
|
230
192
|
scrollY = scrollY + this.normalizeScrollTop(parents[i]);
|
|
231
|
-
}
|
|
193
|
+
}
|
|
194
|
+
// Account for any scrolling on positioned parents
|
|
232
195
|
// Without this, unnecessary scroll offset could be applied
|
|
233
196
|
// to our target element
|
|
234
|
-
|
|
235
|
-
|
|
236
197
|
offsetY = offsetY + scrollY;
|
|
237
198
|
return {
|
|
238
199
|
top: offsetY,
|
|
239
200
|
left: offsetX
|
|
240
201
|
};
|
|
241
202
|
}
|
|
242
|
-
|
|
243
203
|
normalizeScrollTop(element) {
|
|
244
204
|
// Account for cross browser differences with scrollTop attribute on the
|
|
245
205
|
// body element https://bugs.chromium.org/p/chromium/issues/detail?id=766938
|
|
246
206
|
return (0, _ownerDocument.ownerDocument)(this.node).body === element ? 0 : element.scrollTop;
|
|
247
207
|
}
|
|
248
|
-
|
|
249
208
|
}
|
|
250
|
-
|
|
251
209
|
class PositionData {
|
|
252
210
|
constructor(element, target, options) {
|
|
253
211
|
this.options = void 0;
|
|
@@ -256,10 +214,10 @@ class PositionData {
|
|
|
256
214
|
this.target = void 0;
|
|
257
215
|
this.options = options || {};
|
|
258
216
|
const _this$options = this.options,
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
217
|
+
container = _this$options.container,
|
|
218
|
+
constrain = _this$options.constrain,
|
|
219
|
+
placement = _this$options.placement,
|
|
220
|
+
over = _this$options.over;
|
|
263
221
|
if (!element || placement === 'offscreen') return;
|
|
264
222
|
this.container = container || (0, _ownerDocument.ownerDocument)(element).body;
|
|
265
223
|
this.element = new PositionedElement(element, placement, {
|
|
@@ -267,7 +225,6 @@ class PositionData {
|
|
|
267
225
|
left: this.options.offsetX
|
|
268
226
|
});
|
|
269
227
|
this.target = new PositionedElement(target || this.container, over ? this.element.placement : this.element.mirroredPlacement);
|
|
270
|
-
|
|
271
228
|
if (constrain === 'window') {
|
|
272
229
|
this.constrainTo((0, _ownerWindow.ownerWindow)(element));
|
|
273
230
|
} else if (constrain === 'scroll-parent') {
|
|
@@ -280,59 +237,48 @@ class PositionData {
|
|
|
280
237
|
this.constrainTo((0, _findDOMNode.findDOMNode)(constrain));
|
|
281
238
|
}
|
|
282
239
|
}
|
|
283
|
-
|
|
284
240
|
get offset() {
|
|
285
241
|
const _this$target$calculat = this.target.calculateOffset(this.element.placement),
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
242
|
+
top = _this$target$calculat.top,
|
|
243
|
+
left = _this$target$calculat.left;
|
|
289
244
|
const offset = addOffsets([this.element.calculateOffset(this.target.placement), this.element.scrollParentsOffset, this.element.positionedParentsOffset]);
|
|
290
245
|
return {
|
|
291
246
|
top: top - offset.top,
|
|
292
247
|
left: left - offset.left
|
|
293
248
|
};
|
|
294
249
|
}
|
|
295
|
-
|
|
296
250
|
get placement() {
|
|
297
251
|
return formatPlacement(this.element.placement);
|
|
298
252
|
}
|
|
299
|
-
|
|
300
253
|
get minWidth() {
|
|
301
254
|
return this.element.shouldStretchVertically ? this.target.width : null;
|
|
302
255
|
}
|
|
303
|
-
|
|
304
256
|
get minHeight() {
|
|
305
257
|
return this.element.shouldStretchHorizontally ? this.target.height : null;
|
|
306
258
|
}
|
|
307
|
-
|
|
308
259
|
get position() {
|
|
309
260
|
const win = (0, _ownerWindow.ownerWindow)(this.target.node);
|
|
310
|
-
|
|
311
261
|
let _addOffsets = addOffsets([this.target.position, this.offset]),
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
262
|
+
left = _addOffsets.left,
|
|
263
|
+
top = _addOffsets.top;
|
|
315
264
|
if (_canUseDOM.canUseDOM && win !== null && win !== void 0 && win.matchMedia) {
|
|
316
265
|
const retina = win.matchMedia('only screen and (min-resolution: 1.3dppx)').matches || win.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 1.3)').matches;
|
|
317
|
-
|
|
318
266
|
if (!retina) {
|
|
319
267
|
left = Math.round(left);
|
|
320
268
|
top = Math.round(top);
|
|
321
269
|
}
|
|
322
270
|
}
|
|
323
|
-
|
|
324
271
|
return {
|
|
325
272
|
left,
|
|
326
273
|
top
|
|
327
274
|
};
|
|
328
275
|
}
|
|
329
|
-
|
|
330
276
|
get style() {
|
|
331
277
|
// when rendered offscreen first, element has no dimension on first calculation,
|
|
332
278
|
// so we hide it offscreen until measurements are completed
|
|
333
279
|
const _this$element$size = this.element.size,
|
|
334
|
-
|
|
335
|
-
|
|
280
|
+
width = _this$element$size.width,
|
|
281
|
+
height = _this$element$size.height;
|
|
336
282
|
const elementNotFullyRendered = width === 0 && height === 0;
|
|
337
283
|
return {
|
|
338
284
|
top: 0,
|
|
@@ -343,7 +289,6 @@ class PositionData {
|
|
|
343
289
|
transform: `translateX(${this.position.left}px) translateY(${this.position.top}px) translateZ(0)`
|
|
344
290
|
};
|
|
345
291
|
}
|
|
346
|
-
|
|
347
292
|
overflow(element) {
|
|
348
293
|
const parentWindow = (0, _ownerWindow.ownerWindow)(element);
|
|
349
294
|
const elementBounds = (0, _getBoundingClientRect.getBoundingClientRect)(element);
|
|
@@ -356,33 +301,31 @@ class PositionData {
|
|
|
356
301
|
let left = offsets.left + parentOffset.left;
|
|
357
302
|
let right = offsets.left + this.element.width + parentOffset.left;
|
|
358
303
|
let top = offsets.top + parentOffset.top;
|
|
359
|
-
let bottom = offsets.top + this.element.height + parentOffset.top;
|
|
304
|
+
let bottom = offsets.top + this.element.height + parentOffset.top;
|
|
360
305
|
|
|
306
|
+
// adjust for vertical placements
|
|
361
307
|
if (this.element.placement[0] === 'bottom') {
|
|
362
308
|
top -= this.element.height + this.target.height;
|
|
363
309
|
} else if (this.element.placement[0] === 'top') {
|
|
364
310
|
bottom += this.element.height + this.target.height;
|
|
365
311
|
}
|
|
366
|
-
|
|
367
312
|
if (this.element.placement[1] === 'start') {
|
|
368
313
|
left -= this.element.width - this.target.width;
|
|
369
314
|
} else if (this.element.placement[1] === 'end') {
|
|
370
315
|
right += this.element.width - this.target.width;
|
|
371
|
-
}
|
|
372
|
-
|
|
316
|
+
}
|
|
373
317
|
|
|
318
|
+
// adjust for horizontal placements
|
|
374
319
|
if (this.element.placement[1] === 'top') {
|
|
375
320
|
top -= this.element.height - this.target.height;
|
|
376
321
|
} else if (this.element.placement[1] === 'bottom') {
|
|
377
322
|
bottom += this.element.height - this.target.height;
|
|
378
323
|
}
|
|
379
|
-
|
|
380
324
|
if (this.element.placement[0] === 'end') {
|
|
381
325
|
left -= this.element.width + this.target.width;
|
|
382
326
|
} else if (this.element.placement[0] === 'start') {
|
|
383
327
|
right += this.element.width + this.target.width;
|
|
384
328
|
}
|
|
385
|
-
|
|
386
329
|
const bounds = element === parentWindow ? elementBounds : {
|
|
387
330
|
top: windowBounds.top + elementBounds.top,
|
|
388
331
|
bottom: elementBounds.top + elementBounds.height,
|
|
@@ -396,7 +339,6 @@ class PositionData {
|
|
|
396
339
|
right: right > bounds.right ? right - bounds.right : 0
|
|
397
340
|
};
|
|
398
341
|
}
|
|
399
|
-
|
|
400
342
|
constrainTo(element) {
|
|
401
343
|
if (!element) return;
|
|
402
344
|
const overflow = this.overflow(element);
|
|
@@ -406,7 +348,6 @@ class PositionData {
|
|
|
406
348
|
left: overflow.left > 0,
|
|
407
349
|
right: overflow.right > 0
|
|
408
350
|
};
|
|
409
|
-
|
|
410
351
|
if (this.element.hasVerticalPlacement) {
|
|
411
352
|
if (this.element.placement[1] !== 'stretch') {
|
|
412
353
|
if (oob.left && oob.right) {
|
|
@@ -420,7 +361,6 @@ class PositionData {
|
|
|
420
361
|
this.target.placement[1] = 'end';
|
|
421
362
|
}
|
|
422
363
|
}
|
|
423
|
-
|
|
424
364
|
if (oob.top && oob.bottom) {
|
|
425
365
|
// if top and bottom bounds broken
|
|
426
366
|
if (overflow.bottom < overflow.top) {
|
|
@@ -452,7 +392,6 @@ class PositionData {
|
|
|
452
392
|
this.element.placement[1] = 'bottom';
|
|
453
393
|
this.target.placement[1] = 'bottom';
|
|
454
394
|
}
|
|
455
|
-
|
|
456
395
|
if (oob.left && oob.right) {
|
|
457
396
|
// if left and right bounds broken
|
|
458
397
|
if (overflow.left > overflow.right) {
|
|
@@ -475,9 +414,7 @@ class PositionData {
|
|
|
475
414
|
}
|
|
476
415
|
}
|
|
477
416
|
}
|
|
478
|
-
|
|
479
417
|
}
|
|
480
|
-
|
|
481
418
|
function addOffsets(offsets) {
|
|
482
419
|
return offsets.reduce((sum, offset) => {
|
|
483
420
|
return {
|
|
@@ -489,88 +426,73 @@ function addOffsets(offsets) {
|
|
|
489
426
|
left: 0
|
|
490
427
|
});
|
|
491
428
|
}
|
|
492
|
-
|
|
493
429
|
function parseOffset(offset, placement) {
|
|
494
430
|
let top = offset.top,
|
|
495
|
-
|
|
496
|
-
|
|
431
|
+
left = offset.left;
|
|
497
432
|
if (typeof left === 'string') {
|
|
498
433
|
left = parseFloat(left);
|
|
499
434
|
}
|
|
500
|
-
|
|
501
435
|
if (typeof top === 'string') {
|
|
502
436
|
top = parseFloat(top);
|
|
503
437
|
}
|
|
504
|
-
|
|
505
438
|
if (placement[0] === 'bottom') {
|
|
506
439
|
top = 0 - top;
|
|
507
440
|
}
|
|
508
|
-
|
|
509
441
|
if (placement[0] === 'end') {
|
|
510
442
|
left = 0 - left;
|
|
511
443
|
}
|
|
512
|
-
|
|
513
444
|
return {
|
|
514
445
|
top,
|
|
515
446
|
left
|
|
516
447
|
};
|
|
517
448
|
}
|
|
518
|
-
|
|
519
|
-
|
|
449
|
+
function offsetToPx(offset, size,
|
|
450
|
+
// @ts-expect-error will be needed for the TODO below
|
|
520
451
|
node) {
|
|
521
452
|
let left = offset.left,
|
|
522
|
-
|
|
523
|
-
|
|
453
|
+
top = offset.top;
|
|
524
454
|
if (typeof left === 'string') {
|
|
525
455
|
if (left.indexOf('%') !== -1) {
|
|
526
456
|
left = parseFloat(left) / 100 * size.width;
|
|
527
|
-
} else {
|
|
457
|
+
} else {
|
|
458
|
+
// TODO this fixes INSTUI-3505, but it is a breaking change, so uncomment it in V9 with the appropriate release notes
|
|
528
459
|
// left = px(left, node)
|
|
529
460
|
}
|
|
530
461
|
}
|
|
531
|
-
|
|
532
462
|
if (typeof top === 'string') {
|
|
533
463
|
if (top.indexOf('%') !== -1) {
|
|
534
464
|
top = parseFloat(top) / 100 * size.height;
|
|
535
|
-
} else {
|
|
465
|
+
} else {
|
|
466
|
+
// TODO this fixes INSTUI-3505, but it is a breaking change, so uncomment it in V9 with the appropriate release notes
|
|
536
467
|
// top = px(top, node)
|
|
537
468
|
}
|
|
538
469
|
}
|
|
539
|
-
|
|
540
470
|
return {
|
|
541
471
|
top,
|
|
542
472
|
left
|
|
543
473
|
};
|
|
544
474
|
}
|
|
545
|
-
|
|
546
475
|
function sortPlacement(placement) {
|
|
547
476
|
let _placement2 = (0, _slicedToArray2.default)(placement, 2),
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
477
|
+
first = _placement2[0],
|
|
478
|
+
second = _placement2[1];
|
|
551
479
|
if (first === 'center' || first === 'stretch') {
|
|
552
480
|
;
|
|
553
481
|
var _ref2 = [second, first];
|
|
554
482
|
first = _ref2[0];
|
|
555
483
|
second = _ref2[1];
|
|
556
484
|
}
|
|
557
|
-
|
|
558
485
|
return [first, second];
|
|
559
486
|
}
|
|
560
|
-
|
|
561
487
|
function parsePlacement(placement) {
|
|
562
488
|
let parsed = placement.split(' ');
|
|
563
|
-
|
|
564
489
|
if (parsed.length === 1) {
|
|
565
490
|
parsed = [placement, 'center'];
|
|
566
491
|
}
|
|
567
|
-
|
|
568
492
|
return sortPlacement(parsed);
|
|
569
493
|
}
|
|
570
|
-
|
|
571
494
|
function formatPlacement(placement) {
|
|
572
495
|
return placement.join(' ');
|
|
573
496
|
}
|
|
574
|
-
|
|
575
497
|
var _default = calculateElementPosition;
|
|
576
498
|
exports.default = _default;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
8
|
exports.executeMirrorFunction = executeMirrorFunction;
|
|
10
|
-
|
|
11
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
|
-
|
|
13
10
|
/*
|
|
14
11
|
* The MIT License (MIT)
|
|
15
12
|
*
|
|
@@ -33,15 +30,14 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
33
30
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
34
31
|
* SOFTWARE.
|
|
35
32
|
*/
|
|
33
|
+
|
|
36
34
|
function executeMirrorFunction(placement, mirrorFunction, delimiter) {
|
|
37
35
|
const _ref = Array.isArray(placement) ? placement : placement.split(' '),
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
_ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
37
|
+
first = _ref2[0],
|
|
38
|
+
second = _ref2[1];
|
|
42
39
|
const result = mirrorFunction(first, second).filter(value => value);
|
|
43
40
|
return delimiter ? result.join(delimiter) : result;
|
|
44
41
|
}
|
|
45
|
-
|
|
46
42
|
var _default = executeMirrorFunction;
|
|
47
43
|
exports.default = _default;
|
package/lib/index.js
CHANGED
|
@@ -45,17 +45,10 @@ Object.defineProperty(exports, "parsePlacement", {
|
|
|
45
45
|
return _parsePlacement.parsePlacement;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
-
|
|
49
48
|
var _Position = require("./Position");
|
|
50
|
-
|
|
51
49
|
var _calculateElementPosition = require("./calculateElementPosition");
|
|
52
|
-
|
|
53
50
|
var _executeMirrorFunction = require("./executeMirrorFunction");
|
|
54
|
-
|
|
55
51
|
var _PositionPropTypes = require("./PositionPropTypes");
|
|
56
|
-
|
|
57
52
|
var _mirrorHorizontalPlacement = require("./mirrorHorizontalPlacement");
|
|
58
|
-
|
|
59
53
|
var _mirrorPlacement = require("./mirrorPlacement");
|
|
60
|
-
|
|
61
54
|
var _parsePlacement = require("./parsePlacement");
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
8
|
exports.mirrorHorizontalPlacement = mirrorHorizontalPlacement;
|
|
10
|
-
|
|
11
9
|
var _PositionPropTypes = require("./PositionPropTypes");
|
|
12
|
-
|
|
13
10
|
var _executeMirrorFunction = _interopRequireDefault(require("./executeMirrorFunction"));
|
|
14
|
-
|
|
15
11
|
/*
|
|
16
12
|
* The MIT License (MIT)
|
|
17
13
|
*
|
|
@@ -61,6 +57,5 @@ function mirrorHorizontalPlacement(placement, delimiter) {
|
|
|
61
57
|
});
|
|
62
58
|
}, delimiter);
|
|
63
59
|
}
|
|
64
|
-
|
|
65
60
|
var _default = mirrorHorizontalPlacement;
|
|
66
61
|
exports.default = _default;
|
package/lib/mirrorPlacement.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
8
|
exports.mirrorPlacement = mirrorPlacement;
|
|
10
|
-
|
|
11
9
|
var _PositionPropTypes = require("./PositionPropTypes");
|
|
12
|
-
|
|
13
10
|
var _executeMirrorFunction = _interopRequireDefault(require("./executeMirrorFunction"));
|
|
14
|
-
|
|
15
11
|
/*
|
|
16
12
|
* The MIT License (MIT)
|
|
17
13
|
*
|
|
@@ -64,6 +60,5 @@ function mirrorPlacement(placement, delimiter) {
|
|
|
64
60
|
return [_PositionPropTypes.mirrorMap[first], second];
|
|
65
61
|
}, delimiter);
|
|
66
62
|
}
|
|
67
|
-
|
|
68
63
|
var _default = mirrorPlacement;
|
|
69
64
|
exports.default = _default;
|
package/lib/parsePlacement.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-position",
|
|
3
|
-
"version": "8.33.
|
|
3
|
+
"version": "8.33.2",
|
|
4
4
|
"description": "A component for positioning content with respect to a designated target.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -24,24 +24,24 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.13.10",
|
|
27
|
-
"@instructure/debounce": "8.33.
|
|
28
|
-
"@instructure/emotion": "8.33.
|
|
29
|
-
"@instructure/shared-types": "8.33.
|
|
30
|
-
"@instructure/ui-dom-utils": "8.33.
|
|
31
|
-
"@instructure/ui-portal": "8.33.
|
|
32
|
-
"@instructure/ui-prop-types": "8.33.
|
|
33
|
-
"@instructure/ui-react-utils": "8.33.
|
|
34
|
-
"@instructure/ui-testable": "8.33.
|
|
35
|
-
"@instructure/ui-utils": "8.33.
|
|
36
|
-
"@instructure/uid": "8.33.
|
|
27
|
+
"@instructure/debounce": "8.33.2",
|
|
28
|
+
"@instructure/emotion": "8.33.2",
|
|
29
|
+
"@instructure/shared-types": "8.33.2",
|
|
30
|
+
"@instructure/ui-dom-utils": "8.33.2",
|
|
31
|
+
"@instructure/ui-portal": "8.33.2",
|
|
32
|
+
"@instructure/ui-prop-types": "8.33.2",
|
|
33
|
+
"@instructure/ui-react-utils": "8.33.2",
|
|
34
|
+
"@instructure/ui-testable": "8.33.2",
|
|
35
|
+
"@instructure/ui-utils": "8.33.2",
|
|
36
|
+
"@instructure/uid": "8.33.2",
|
|
37
37
|
"prop-types": "^15"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@instructure/ui-babel-preset": "8.33.
|
|
41
|
-
"@instructure/ui-color-utils": "8.33.
|
|
42
|
-
"@instructure/ui-test-locator": "8.33.
|
|
43
|
-
"@instructure/ui-test-utils": "8.33.
|
|
44
|
-
"@instructure/ui-themes": "8.33.
|
|
40
|
+
"@instructure/ui-babel-preset": "8.33.2",
|
|
41
|
+
"@instructure/ui-color-utils": "8.33.2",
|
|
42
|
+
"@instructure/ui-test-locator": "8.33.2",
|
|
43
|
+
"@instructure/ui-test-utils": "8.33.2",
|
|
44
|
+
"@instructure/ui-themes": "8.33.2"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": ">=16.8 <=18"
|