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