@instructure/ui-position 11.7.3-snapshot-7 → 11.7.3-snapshot-26
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 +5 -2
- package/es/Position/index.js +64 -58
- package/es/Position/theme.js +4 -2
- package/es/calculateElementPosition.js +43 -46
- package/es/executeMirrorFunction.js +1 -5
- package/lib/Position/index.js +64 -58
- package/lib/Position/theme.js +4 -2
- package/lib/calculateElementPosition.js +45 -49
- package/lib/executeMirrorFunction.js +1 -6
- package/package.json +13 -13
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.calculateElementPosition = calculateElementPosition;
|
|
8
7
|
exports.default = void 0;
|
|
9
8
|
exports.parsePlacement = parsePlacement;
|
|
10
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
9
|
var _getBoundingClientRect = require("@instructure/ui-dom-utils/lib/getBoundingClientRect.js");
|
|
12
10
|
var _getScrollParents = require("@instructure/ui-dom-utils/lib/getScrollParents.js");
|
|
13
11
|
var _getOffsetParents = require("@instructure/ui-dom-utils/lib/getOffsetParents.js");
|
|
14
12
|
var _canUseDOM = require("@instructure/ui-dom-utils/lib/canUseDOM.js");
|
|
15
13
|
var _findDOMNode = require("@instructure/ui-dom-utils/lib/findDOMNode.js");
|
|
16
|
-
var
|
|
14
|
+
var _ownerDocument = require("@instructure/ui-dom-utils/lib/ownerDocument.js");
|
|
17
15
|
var _ownerWindow = require("@instructure/ui-dom-utils/lib/ownerWindow.js");
|
|
18
16
|
var _mirrorPlacement = require("./mirrorPlacement");
|
|
19
17
|
/*
|
|
@@ -91,10 +89,6 @@ class PositionedElement {
|
|
|
91
89
|
top: 0,
|
|
92
90
|
left: 0
|
|
93
91
|
}) {
|
|
94
|
-
this.node = void 0;
|
|
95
|
-
this.placement = void 0;
|
|
96
|
-
this.rect = void 0;
|
|
97
|
-
this._offset = void 0;
|
|
98
92
|
this.node = (0, _findDOMNode.findDOMNode)(element);
|
|
99
93
|
if (typeof placement === 'string') {
|
|
100
94
|
this.placement = parsePlacement(placement);
|
|
@@ -106,6 +100,10 @@ class PositionedElement {
|
|
|
106
100
|
this.rect = (0, _getBoundingClientRect.getBoundingClientRect)(this.node);
|
|
107
101
|
this._offset = offsetToPx(offset, this.size, this.node);
|
|
108
102
|
}
|
|
103
|
+
node;
|
|
104
|
+
placement;
|
|
105
|
+
rect;
|
|
106
|
+
_offset;
|
|
109
107
|
get width() {
|
|
110
108
|
return this.rect.width;
|
|
111
109
|
}
|
|
@@ -148,14 +146,10 @@ class PositionedElement {
|
|
|
148
146
|
end: '100%',
|
|
149
147
|
stretch: 0
|
|
150
148
|
};
|
|
151
|
-
let
|
|
152
|
-
first = _placement[0],
|
|
153
|
-
second = _placement[1];
|
|
149
|
+
let [first, second] = placement;
|
|
154
150
|
if (['start', 'end'].indexOf(first) >= 0) {
|
|
155
151
|
;
|
|
156
|
-
|
|
157
|
-
first = _ref[0];
|
|
158
|
-
second = _ref[1];
|
|
152
|
+
[first, second] = [second, first];
|
|
159
153
|
}
|
|
160
154
|
let top = 0;
|
|
161
155
|
let left = 0;
|
|
@@ -193,12 +187,12 @@ class PositionedElement {
|
|
|
193
187
|
// ancestor. We calculate the offset between the child and
|
|
194
188
|
// positioned parent so we can negate that distance
|
|
195
189
|
const parents = (0, _getOffsetParents.getOffsetParents)(this.node);
|
|
196
|
-
const doc = (0,
|
|
190
|
+
const doc = (0, _ownerDocument.ownerDocument)(this.node);
|
|
197
191
|
|
|
198
192
|
// If there is more than one parent, the offset on the
|
|
199
193
|
// documentElement should be calculated appropriately.
|
|
200
194
|
// Otherwise we need to explictly account for that offset
|
|
201
|
-
let offsetY = parents.length > 1 ? 0 : (0, _getBoundingClientRect.getBoundingClientRect)(doc
|
|
195
|
+
let offsetY = parents.length > 1 ? 0 : (0, _getBoundingClientRect.getBoundingClientRect)(doc?.documentElement).top;
|
|
202
196
|
let offsetX = 0;
|
|
203
197
|
let scrollY = 0;
|
|
204
198
|
for (let i = 1; i < parents.length; i++) {
|
|
@@ -206,7 +200,7 @@ class PositionedElement {
|
|
|
206
200
|
const child = (0, _getBoundingClientRect.getBoundingClientRect)(parents[i - 1]);
|
|
207
201
|
offsetY = offsetY + (child.top - parent.top);
|
|
208
202
|
offsetX = offsetX + (child.left - parent.left);
|
|
209
|
-
if (parents[i] ===
|
|
203
|
+
if (parents[i] === doc?.body) {
|
|
210
204
|
// accounts for any margin on body
|
|
211
205
|
offsetY = offsetY + parent.top;
|
|
212
206
|
offsetX = offsetX + parent.left;
|
|
@@ -223,27 +217,22 @@ class PositionedElement {
|
|
|
223
217
|
};
|
|
224
218
|
}
|
|
225
219
|
normalizeScrollTop(element) {
|
|
226
|
-
var _ownerDocument;
|
|
227
220
|
// Account for cross browser differences with scrollTop attribute on the
|
|
228
221
|
// body element https://bugs.chromium.org/p/chromium/issues/detail?id=766938
|
|
229
|
-
return (
|
|
222
|
+
return (0, _ownerDocument.ownerDocument)(this.node)?.body === element ? 0 : element.scrollTop;
|
|
230
223
|
}
|
|
231
224
|
}
|
|
232
225
|
class PositionData {
|
|
233
226
|
constructor(element, target, options) {
|
|
234
|
-
var _ownerDocument2;
|
|
235
|
-
this.options = void 0;
|
|
236
|
-
this.container = void 0;
|
|
237
|
-
this.element = void 0;
|
|
238
|
-
this.target = void 0;
|
|
239
227
|
this.options = options || {};
|
|
240
|
-
const
|
|
241
|
-
container
|
|
242
|
-
constrain
|
|
243
|
-
placement
|
|
244
|
-
over
|
|
228
|
+
const {
|
|
229
|
+
container,
|
|
230
|
+
constrain,
|
|
231
|
+
placement,
|
|
232
|
+
over
|
|
233
|
+
} = this.options;
|
|
245
234
|
if (!element || placement === 'offscreen') return;
|
|
246
|
-
this.container = container || (
|
|
235
|
+
this.container = container || (0, _ownerDocument.ownerDocument)(element)?.body;
|
|
247
236
|
this.element = new PositionedElement(element, placement, {
|
|
248
237
|
top: this.options.offsetY,
|
|
249
238
|
left: this.options.offsetX
|
|
@@ -261,10 +250,15 @@ class PositionData {
|
|
|
261
250
|
this.constrainTo((0, _findDOMNode.findDOMNode)(constrain));
|
|
262
251
|
}
|
|
263
252
|
}
|
|
253
|
+
options;
|
|
254
|
+
container;
|
|
255
|
+
element;
|
|
256
|
+
target;
|
|
264
257
|
get offset() {
|
|
265
|
-
const
|
|
266
|
-
top
|
|
267
|
-
left
|
|
258
|
+
const {
|
|
259
|
+
top,
|
|
260
|
+
left
|
|
261
|
+
} = this.target.calculateOffset(this.element.placement);
|
|
268
262
|
const offset = addOffsets([this.element.calculateOffset(this.target.placement), this.element.scrollParentsOffset, this.element.positionedParentsOffset]);
|
|
269
263
|
return {
|
|
270
264
|
top: top - offset.top,
|
|
@@ -282,10 +276,11 @@ class PositionData {
|
|
|
282
276
|
}
|
|
283
277
|
get position() {
|
|
284
278
|
const win = (0, _ownerWindow.ownerWindow)(this.target.node);
|
|
285
|
-
let
|
|
286
|
-
left
|
|
287
|
-
top
|
|
288
|
-
|
|
279
|
+
let {
|
|
280
|
+
left,
|
|
281
|
+
top
|
|
282
|
+
} = addOffsets([this.target.position, this.offset]);
|
|
283
|
+
if (_canUseDOM.canUseDOM && win?.matchMedia) {
|
|
289
284
|
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;
|
|
290
285
|
if (!retina) {
|
|
291
286
|
left = Math.round(left);
|
|
@@ -300,9 +295,10 @@ class PositionData {
|
|
|
300
295
|
get style() {
|
|
301
296
|
// when rendered offscreen first, element has no dimension on first calculation,
|
|
302
297
|
// so we hide it offscreen until measurements are completed
|
|
303
|
-
const
|
|
304
|
-
width
|
|
305
|
-
height
|
|
298
|
+
const {
|
|
299
|
+
width,
|
|
300
|
+
height
|
|
301
|
+
} = this.element.size;
|
|
306
302
|
const elementNotFullyRendered = width === 0 && height === 0;
|
|
307
303
|
return {
|
|
308
304
|
top: 0,
|
|
@@ -451,8 +447,10 @@ function addOffsets(offsets) {
|
|
|
451
447
|
});
|
|
452
448
|
}
|
|
453
449
|
function parseOffset(offset, placement) {
|
|
454
|
-
let
|
|
455
|
-
|
|
450
|
+
let {
|
|
451
|
+
top,
|
|
452
|
+
left
|
|
453
|
+
} = offset;
|
|
456
454
|
if (typeof left === 'string') {
|
|
457
455
|
left = parseFloat(left);
|
|
458
456
|
}
|
|
@@ -473,8 +471,10 @@ function parseOffset(offset, placement) {
|
|
|
473
471
|
function offsetToPx(offset, size,
|
|
474
472
|
// @ts-expect-error will be needed for the TODO below
|
|
475
473
|
node) {
|
|
476
|
-
let
|
|
477
|
-
|
|
474
|
+
let {
|
|
475
|
+
left,
|
|
476
|
+
top
|
|
477
|
+
} = offset;
|
|
478
478
|
if (typeof left === 'string') {
|
|
479
479
|
if (left.indexOf('%') !== -1) {
|
|
480
480
|
left = parseFloat(left) / 100 * size.width;
|
|
@@ -497,14 +497,10 @@ node) {
|
|
|
497
497
|
};
|
|
498
498
|
}
|
|
499
499
|
function sortPlacement(placement) {
|
|
500
|
-
let
|
|
501
|
-
first = _placement2[0],
|
|
502
|
-
second = _placement2[1];
|
|
500
|
+
let [first, second] = placement;
|
|
503
501
|
if (first === 'center') {
|
|
504
502
|
;
|
|
505
|
-
|
|
506
|
-
first = _ref2[0];
|
|
507
|
-
second = _ref2[1];
|
|
503
|
+
[first, second] = [second, first];
|
|
508
504
|
}
|
|
509
505
|
return [first, second];
|
|
510
506
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
7
|
exports.executeMirrorFunction = executeMirrorFunction;
|
|
9
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
8
|
/*
|
|
11
9
|
* The MIT License (MIT)
|
|
12
10
|
*
|
|
@@ -32,10 +30,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
32
30
|
*/
|
|
33
31
|
|
|
34
32
|
function executeMirrorFunction(placement, mirrorFunction, delimiter) {
|
|
35
|
-
const
|
|
36
|
-
_ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
37
|
-
first = _ref2[0],
|
|
38
|
-
second = _ref2[1];
|
|
33
|
+
const [first, second] = Array.isArray(placement) ? placement : placement.split(' ');
|
|
39
34
|
const result = mirrorFunction(first, second).filter(value => value);
|
|
40
35
|
return delimiter ? result.join(delimiter) : result;
|
|
41
36
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-position",
|
|
3
|
-
"version": "11.7.3-snapshot-
|
|
3
|
+
"version": "11.7.3-snapshot-26",
|
|
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",
|
|
@@ -14,23 +14,23 @@
|
|
|
14
14
|
"bugs": "https://github.com/instructure/instructure-ui/issues",
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@babel/runtime": "^7.
|
|
18
|
-
"@instructure/debounce": "11.7.3-snapshot-
|
|
19
|
-
"@instructure/emotion": "11.7.3-snapshot-
|
|
20
|
-
"@instructure/
|
|
21
|
-
"@instructure/ui-portal": "11.7.3-snapshot-
|
|
22
|
-
"@instructure/
|
|
23
|
-
"@instructure/ui-react-utils": "11.7.3-snapshot-
|
|
24
|
-
"@instructure/ui-
|
|
25
|
-
"@instructure/
|
|
26
|
-
"@instructure/
|
|
17
|
+
"@babel/runtime": "^7.29.2",
|
|
18
|
+
"@instructure/debounce": "11.7.3-snapshot-26",
|
|
19
|
+
"@instructure/emotion": "11.7.3-snapshot-26",
|
|
20
|
+
"@instructure/shared-types": "11.7.3-snapshot-26",
|
|
21
|
+
"@instructure/ui-portal": "11.7.3-snapshot-26",
|
|
22
|
+
"@instructure/ui-dom-utils": "11.7.3-snapshot-26",
|
|
23
|
+
"@instructure/ui-react-utils": "11.7.3-snapshot-26",
|
|
24
|
+
"@instructure/ui-themes": "11.7.3-snapshot-26",
|
|
25
|
+
"@instructure/ui-utils": "11.7.3-snapshot-26",
|
|
26
|
+
"@instructure/uid": "11.7.3-snapshot-26"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@testing-library/jest-dom": "^6.6.3",
|
|
30
30
|
"@testing-library/react": "15.0.7",
|
|
31
31
|
"vitest": "^3.2.2",
|
|
32
|
-
"@instructure/ui-
|
|
33
|
-
"@instructure/ui-
|
|
32
|
+
"@instructure/ui-babel-preset": "11.7.3-snapshot-26",
|
|
33
|
+
"@instructure/ui-color-utils": "11.7.3-snapshot-26"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": ">=18 <=19"
|