@atlaskit/react-ufo 4.13.1 → 4.14.1
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 +14 -0
- package/dist/cjs/create-payload/index.js +12 -9
- package/dist/cjs/create-payload/utils/get-battery-info.js +97 -0
- package/dist/cjs/vc/vc-observer/observers/ssr-placeholders/index.js +27 -33
- package/dist/cjs/vc/vc-observer/observers/ssr-placeholders/ssr-scripts/collectSSRPlaceholderDimensions.js +2 -12
- package/dist/cjs/vc/vc-observer-new/viewport-observer/index.js +131 -273
- package/dist/es2019/create-payload/index.js +3 -1
- package/dist/es2019/create-payload/utils/get-battery-info.js +42 -0
- package/dist/es2019/vc/vc-observer/observers/ssr-placeholders/index.js +27 -33
- package/dist/es2019/vc/vc-observer/observers/ssr-placeholders/ssr-scripts/collectSSRPlaceholderDimensions.js +2 -13
- package/dist/es2019/vc/vc-observer-new/viewport-observer/index.js +39 -132
- package/dist/esm/create-payload/index.js +12 -9
- package/dist/esm/create-payload/utils/get-battery-info.js +93 -0
- package/dist/esm/vc/vc-observer/observers/ssr-placeholders/index.js +27 -33
- package/dist/esm/vc/vc-observer/observers/ssr-placeholders/ssr-scripts/collectSSRPlaceholderDimensions.js +2 -13
- package/dist/esm/vc/vc-observer-new/viewport-observer/index.js +129 -271
- package/dist/types/create-payload/index.d.ts +192 -0
- package/dist/types/create-payload/utils/get-battery-info.d.ts +10 -0
- package/dist/types-ts4.5/create-payload/index.d.ts +192 -0
- package/dist/types-ts4.5/create-payload/utils/get-battery-info.d.ts +10 -0
- package/package.json +4 -7
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
2
|
const ANCESTOR_LOOKUP_LIMIT = 10;
|
|
4
3
|
const PAGE_LAYOUT_ID = 'page-layout.root';
|
|
5
4
|
export class SSRPlaceholderHandlers {
|
|
@@ -247,45 +246,40 @@ export class SSRPlaceholderHandlers {
|
|
|
247
246
|
* by collecting dimensions from their children instead
|
|
248
247
|
*/
|
|
249
248
|
getEffectiveBoundingRect(el) {
|
|
250
|
-
const
|
|
249
|
+
const computedStyle = window.getComputedStyle(el);
|
|
251
250
|
|
|
252
|
-
//
|
|
253
|
-
if (
|
|
254
|
-
const
|
|
251
|
+
// If element has display: contents, collect bounding rect from children
|
|
252
|
+
if (computedStyle.display === 'contents') {
|
|
253
|
+
const children = Array.from(el.children);
|
|
254
|
+
if (children.length === 0) {
|
|
255
|
+
// No children, return zero rect
|
|
256
|
+
return new DOMRect(0, 0, 0, 0);
|
|
257
|
+
}
|
|
255
258
|
|
|
256
|
-
//
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
// Calculate union of all children's bounding rects
|
|
260
|
+
let minX = Infinity;
|
|
261
|
+
let minY = Infinity;
|
|
262
|
+
let maxX = -Infinity;
|
|
263
|
+
let maxY = -Infinity;
|
|
264
|
+
children.forEach(child => {
|
|
265
|
+
const childRect = child.getBoundingClientRect();
|
|
266
|
+
// Skip children with zero dimensions (likely also display: contents)
|
|
267
|
+
if (childRect.width > 0 || childRect.height > 0) {
|
|
268
|
+
minX = Math.min(minX, childRect.left);
|
|
269
|
+
minY = Math.min(minY, childRect.top);
|
|
270
|
+
maxX = Math.max(maxX, childRect.right);
|
|
271
|
+
maxY = Math.max(maxY, childRect.bottom);
|
|
262
272
|
}
|
|
273
|
+
});
|
|
263
274
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
let maxX = -Infinity;
|
|
268
|
-
let maxY = -Infinity;
|
|
269
|
-
children.forEach(child => {
|
|
270
|
-
const childRect = child.getBoundingClientRect();
|
|
271
|
-
// Skip children with zero dimensions (likely also display: contents)
|
|
272
|
-
if (childRect.width > 0 || childRect.height > 0) {
|
|
273
|
-
minX = Math.min(minX, childRect.left);
|
|
274
|
-
minY = Math.min(minY, childRect.top);
|
|
275
|
-
maxX = Math.max(maxX, childRect.right);
|
|
276
|
-
maxY = Math.max(maxY, childRect.bottom);
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
// If no children with dimensions found, return zero rect
|
|
281
|
-
if (minX === Infinity) {
|
|
282
|
-
return new DOMRect(0, 0, 0, 0);
|
|
283
|
-
}
|
|
284
|
-
return new DOMRect(minX, minY, maxX - minX, maxY - minY);
|
|
275
|
+
// If no children with dimensions found, return zero rect
|
|
276
|
+
if (minX === Infinity) {
|
|
277
|
+
return new DOMRect(0, 0, 0, 0);
|
|
285
278
|
}
|
|
279
|
+
return new DOMRect(minX, minY, maxX - minX, maxY - minY);
|
|
286
280
|
}
|
|
287
281
|
|
|
288
|
-
// Normal element
|
|
282
|
+
// Normal element, return its bounding rect
|
|
289
283
|
return el.getBoundingClientRect();
|
|
290
284
|
}
|
|
291
285
|
isDummyRect(rect) {
|
|
@@ -1,31 +1,20 @@
|
|
|
1
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
-
|
|
3
1
|
// lightweight script to scan the SSR response and collect all elements with data-ssr-placeholder attribute
|
|
4
2
|
// and save their size/positions in a map __SSR_PLACEHOLDERS_DIMENSIONS__ on the Window object. Each placeholderId is
|
|
5
3
|
// unique and maps to its corresponding elements bounding client rectangle dimensions.
|
|
6
4
|
export function collectSSRPlaceholderDimensions(document, window, enablePageLayoutPlaceholder = false) {
|
|
7
|
-
const enableDisplayContentsSupport = fg('platform_ufo_ssr_placeholders_for_display_contents');
|
|
8
5
|
const ssrPlaceholders = document === null || document === void 0 ? void 0 : document.querySelectorAll('[data-ssr-placeholder]');
|
|
9
6
|
ssrPlaceholders.forEach(elem => {
|
|
10
7
|
const placeholderId = elem.getAttribute('data-ssr-placeholder');
|
|
11
8
|
if (placeholderId) {
|
|
12
9
|
window.__SSR_PLACEHOLDERS_DIMENSIONS__ = window.__SSR_PLACEHOLDERS_DIMENSIONS__ || {};
|
|
13
|
-
|
|
14
|
-
window.__SSR_PLACEHOLDERS_DIMENSIONS__[placeholderId] = getEffectiveBoundingRect(elem, window);
|
|
15
|
-
} else {
|
|
16
|
-
window.__SSR_PLACEHOLDERS_DIMENSIONS__[placeholderId] = elem.getBoundingClientRect();
|
|
17
|
-
}
|
|
10
|
+
window.__SSR_PLACEHOLDERS_DIMENSIONS__[placeholderId] = getEffectiveBoundingRect(elem, window);
|
|
18
11
|
}
|
|
19
12
|
});
|
|
20
13
|
if (enablePageLayoutPlaceholder) {
|
|
21
14
|
const pageLayoutRoot = document === null || document === void 0 ? void 0 : document.getElementById('unsafe-design-system-page-layout-root');
|
|
22
15
|
if (pageLayoutRoot) {
|
|
23
16
|
window.__SSR_PLACEHOLDERS_DIMENSIONS__ = window.__SSR_PLACEHOLDERS_DIMENSIONS__ || {};
|
|
24
|
-
|
|
25
|
-
window.__SSR_PLACEHOLDERS_DIMENSIONS__['page-layout.root'] = getEffectiveBoundingRect(pageLayoutRoot, window);
|
|
26
|
-
} else {
|
|
27
|
-
window.__SSR_PLACEHOLDERS_DIMENSIONS__['page-layout.root'] = pageLayoutRoot.getBoundingClientRect();
|
|
28
|
-
}
|
|
17
|
+
window.__SSR_PLACEHOLDERS_DIMENSIONS__['page-layout.root'] = getEffectiveBoundingRect(pageLayoutRoot, window);
|
|
29
18
|
}
|
|
30
19
|
}
|
|
31
20
|
}
|
|
@@ -80,100 +80,10 @@ export default class ViewportObserver {
|
|
|
80
80
|
if (!addedNode) {
|
|
81
81
|
continue;
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
} of getMutatedElements(addedNode)) {
|
|
88
|
-
// SSR hydration logic
|
|
89
|
-
if (this.getSSRState) {
|
|
90
|
-
const ssrState = this.getSSRState();
|
|
91
|
-
const SSRStateEnum = {
|
|
92
|
-
normal: 1,
|
|
93
|
-
waitingForFirstRender: 2,
|
|
94
|
-
ignoring: 3
|
|
95
|
-
};
|
|
96
|
-
if (ssrState.state === SSRStateEnum.waitingForFirstRender && timestamp > ssrState.renderStart && targetNode === ssrState.reactRootElement) {
|
|
97
|
-
var _this$intersectionObs;
|
|
98
|
-
ssrState.state = SSRStateEnum.ignoring;
|
|
99
|
-
if (ssrState.renderStop === -1) {
|
|
100
|
-
// arbitrary 500ms DOM update window
|
|
101
|
-
ssrState.renderStop = timestamp + 500;
|
|
102
|
-
}
|
|
103
|
-
(_this$intersectionObs = this.intersectionObserver) === null || _this$intersectionObs === void 0 ? void 0 : _this$intersectionObs.watchAndTag(element, 'ssr-hydration');
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
if (ssrState.state === SSRStateEnum.ignoring && timestamp > ssrState.renderStart && targetNode === ssrState.reactRootElement) {
|
|
107
|
-
if (timestamp <= ssrState.renderStop) {
|
|
108
|
-
var _this$intersectionObs2;
|
|
109
|
-
(_this$intersectionObs2 = this.intersectionObserver) === null || _this$intersectionObs2 === void 0 ? void 0 : _this$intersectionObs2.watchAndTag(element, 'ssr-hydration');
|
|
110
|
-
continue;
|
|
111
|
-
} else {
|
|
112
|
-
ssrState.state = SSRStateEnum.normal;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// SSR placeholder logic - check and handle with await
|
|
118
|
-
if (this.getSSRPlaceholderHandler) {
|
|
119
|
-
const ssrPlaceholderHandler = this.getSSRPlaceholderHandler();
|
|
120
|
-
if (ssrPlaceholderHandler) {
|
|
121
|
-
if (ssrPlaceholderHandler.isPlaceholder(element) || ssrPlaceholderHandler.isPlaceholderIgnored(element)) {
|
|
122
|
-
if (ssrPlaceholderHandler.checkIfExistedAndSizeMatchingV3(element)) {
|
|
123
|
-
var _this$intersectionObs3;
|
|
124
|
-
(_this$intersectionObs3 = this.intersectionObserver) === null || _this$intersectionObs3 === void 0 ? void 0 : _this$intersectionObs3.watchAndTag(element, 'mutation:ssr-placeholder');
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
// If result is false, continue to normal mutation logic below
|
|
128
|
-
}
|
|
129
|
-
if (ssrPlaceholderHandler.isPlaceholderReplacement(element) || ssrPlaceholderHandler.isPlaceholderIgnored(element)) {
|
|
130
|
-
const result = await ssrPlaceholderHandler.validateReactComponentMatchToPlaceholder(element);
|
|
131
|
-
if (result !== false) {
|
|
132
|
-
var _this$intersectionObs4;
|
|
133
|
-
(_this$intersectionObs4 = this.intersectionObserver) === null || _this$intersectionObs4 === void 0 ? void 0 : _this$intersectionObs4.watchAndTag(element, 'mutation:ssr-placeholder');
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
// If result is false, continue to normal mutation logic below
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
const sameDeletedNode = removedNodes.find(ref => {
|
|
141
|
-
const n = ref.deref();
|
|
142
|
-
if (!n || !element) {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
return n.isEqualNode(element);
|
|
146
|
-
});
|
|
147
|
-
const isInIgnoreLsMarker = element instanceof HTMLElement ? isInVCIgnoreIfNoLayoutShiftMarker(element) : false;
|
|
148
|
-
if (sameDeletedNode && isInIgnoreLsMarker) {
|
|
149
|
-
var _this$intersectionObs5;
|
|
150
|
-
(_this$intersectionObs5 = this.intersectionObserver) === null || _this$intersectionObs5 === void 0 ? void 0 : _this$intersectionObs5.watchAndTag(element, 'mutation:remount');
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
if (isContainedWithinMediaWrapper(element)) {
|
|
154
|
-
var _this$intersectionObs6;
|
|
155
|
-
(_this$intersectionObs6 = this.intersectionObserver) === null || _this$intersectionObs6 === void 0 ? void 0 : _this$intersectionObs6.watchAndTag(element, 'mutation:media');
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
const {
|
|
159
|
-
isWithin: isWithinThirdPartySegment
|
|
160
|
-
} = element instanceof HTMLElement ? checkWithinComponent(element, 'UFOThirdPartySegment', this.mapIs3pResult) : {
|
|
161
|
-
isWithin: false
|
|
162
|
-
};
|
|
163
|
-
if (isWithinThirdPartySegment) {
|
|
164
|
-
var _this$intersectionObs7;
|
|
165
|
-
(_this$intersectionObs7 = this.intersectionObserver) === null || _this$intersectionObs7 === void 0 ? void 0 : _this$intersectionObs7.watchAndTag(element, 'mutation:third-party-element');
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
if (isDisplayContentsElementChildren) {
|
|
169
|
-
var _this$intersectionObs8;
|
|
170
|
-
(_this$intersectionObs8 = this.intersectionObserver) === null || _this$intersectionObs8 === void 0 ? void 0 : _this$intersectionObs8.watchAndTag(element, 'mutation:display-contents-children-element');
|
|
171
|
-
} else {
|
|
172
|
-
var _this$intersectionObs9;
|
|
173
|
-
(_this$intersectionObs9 = this.intersectionObserver) === null || _this$intersectionObs9 === void 0 ? void 0 : _this$intersectionObs9.watchAndTag(element, createElementMutationsWatcher(removedNodeRects));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
} else {
|
|
83
|
+
for (const {
|
|
84
|
+
isDisplayContentsElementChildren,
|
|
85
|
+
element
|
|
86
|
+
} of getMutatedElements(addedNode)) {
|
|
177
87
|
// SSR hydration logic
|
|
178
88
|
if (this.getSSRState) {
|
|
179
89
|
const ssrState = this.getSSRState();
|
|
@@ -183,19 +93,19 @@ export default class ViewportObserver {
|
|
|
183
93
|
ignoring: 3
|
|
184
94
|
};
|
|
185
95
|
if (ssrState.state === SSRStateEnum.waitingForFirstRender && timestamp > ssrState.renderStart && targetNode === ssrState.reactRootElement) {
|
|
186
|
-
var _this$
|
|
96
|
+
var _this$intersectionObs;
|
|
187
97
|
ssrState.state = SSRStateEnum.ignoring;
|
|
188
98
|
if (ssrState.renderStop === -1) {
|
|
189
99
|
// arbitrary 500ms DOM update window
|
|
190
100
|
ssrState.renderStop = timestamp + 500;
|
|
191
101
|
}
|
|
192
|
-
(_this$
|
|
102
|
+
(_this$intersectionObs = this.intersectionObserver) === null || _this$intersectionObs === void 0 ? void 0 : _this$intersectionObs.watchAndTag(element, 'ssr-hydration');
|
|
193
103
|
continue;
|
|
194
104
|
}
|
|
195
105
|
if (ssrState.state === SSRStateEnum.ignoring && timestamp > ssrState.renderStart && targetNode === ssrState.reactRootElement) {
|
|
196
106
|
if (timestamp <= ssrState.renderStop) {
|
|
197
|
-
var _this$
|
|
198
|
-
(_this$
|
|
107
|
+
var _this$intersectionObs2;
|
|
108
|
+
(_this$intersectionObs2 = this.intersectionObserver) === null || _this$intersectionObs2 === void 0 ? void 0 : _this$intersectionObs2.watchAndTag(element, 'ssr-hydration');
|
|
199
109
|
continue;
|
|
200
110
|
} else {
|
|
201
111
|
ssrState.state = SSRStateEnum.normal;
|
|
@@ -207,19 +117,19 @@ export default class ViewportObserver {
|
|
|
207
117
|
if (this.getSSRPlaceholderHandler) {
|
|
208
118
|
const ssrPlaceholderHandler = this.getSSRPlaceholderHandler();
|
|
209
119
|
if (ssrPlaceholderHandler) {
|
|
210
|
-
if (ssrPlaceholderHandler.isPlaceholder(
|
|
211
|
-
if (ssrPlaceholderHandler.checkIfExistedAndSizeMatchingV3(
|
|
212
|
-
var _this$
|
|
213
|
-
(_this$
|
|
120
|
+
if (ssrPlaceholderHandler.isPlaceholder(element) || ssrPlaceholderHandler.isPlaceholderIgnored(element)) {
|
|
121
|
+
if (ssrPlaceholderHandler.checkIfExistedAndSizeMatchingV3(element)) {
|
|
122
|
+
var _this$intersectionObs3;
|
|
123
|
+
(_this$intersectionObs3 = this.intersectionObserver) === null || _this$intersectionObs3 === void 0 ? void 0 : _this$intersectionObs3.watchAndTag(element, 'mutation:ssr-placeholder');
|
|
214
124
|
continue;
|
|
215
125
|
}
|
|
216
126
|
// If result is false, continue to normal mutation logic below
|
|
217
127
|
}
|
|
218
|
-
if (ssrPlaceholderHandler.isPlaceholderReplacement(
|
|
219
|
-
const result = await ssrPlaceholderHandler.validateReactComponentMatchToPlaceholder(
|
|
128
|
+
if (ssrPlaceholderHandler.isPlaceholderReplacement(element) || ssrPlaceholderHandler.isPlaceholderIgnored(element)) {
|
|
129
|
+
const result = await ssrPlaceholderHandler.validateReactComponentMatchToPlaceholder(element);
|
|
220
130
|
if (result !== false) {
|
|
221
|
-
var _this$
|
|
222
|
-
(_this$
|
|
131
|
+
var _this$intersectionObs4;
|
|
132
|
+
(_this$intersectionObs4 = this.intersectionObserver) === null || _this$intersectionObs4 === void 0 ? void 0 : _this$intersectionObs4.watchAndTag(element, 'mutation:ssr-placeholder');
|
|
223
133
|
continue;
|
|
224
134
|
}
|
|
225
135
|
// If result is false, continue to normal mutation logic below
|
|
@@ -228,41 +138,38 @@ export default class ViewportObserver {
|
|
|
228
138
|
}
|
|
229
139
|
const sameDeletedNode = removedNodes.find(ref => {
|
|
230
140
|
const n = ref.deref();
|
|
231
|
-
if (!n || !
|
|
141
|
+
if (!n || !element) {
|
|
232
142
|
return false;
|
|
233
143
|
}
|
|
234
|
-
return n.isEqualNode(
|
|
144
|
+
return n.isEqualNode(element);
|
|
235
145
|
});
|
|
236
|
-
const isInIgnoreLsMarker = isInVCIgnoreIfNoLayoutShiftMarker(
|
|
146
|
+
const isInIgnoreLsMarker = element instanceof HTMLElement ? isInVCIgnoreIfNoLayoutShiftMarker(element) : false;
|
|
237
147
|
if (sameDeletedNode && isInIgnoreLsMarker) {
|
|
238
|
-
var _this$
|
|
239
|
-
(_this$
|
|
148
|
+
var _this$intersectionObs5;
|
|
149
|
+
(_this$intersectionObs5 = this.intersectionObserver) === null || _this$intersectionObs5 === void 0 ? void 0 : _this$intersectionObs5.watchAndTag(element, 'mutation:remount');
|
|
240
150
|
continue;
|
|
241
151
|
}
|
|
242
|
-
if (isContainedWithinMediaWrapper(
|
|
243
|
-
var _this$
|
|
244
|
-
(_this$
|
|
152
|
+
if (isContainedWithinMediaWrapper(element)) {
|
|
153
|
+
var _this$intersectionObs6;
|
|
154
|
+
(_this$intersectionObs6 = this.intersectionObserver) === null || _this$intersectionObs6 === void 0 ? void 0 : _this$intersectionObs6.watchAndTag(element, 'mutation:media');
|
|
245
155
|
continue;
|
|
246
156
|
}
|
|
247
157
|
const {
|
|
248
158
|
isWithin: isWithinThirdPartySegment
|
|
249
|
-
} = checkWithinComponent(
|
|
159
|
+
} = element instanceof HTMLElement ? checkWithinComponent(element, 'UFOThirdPartySegment', this.mapIs3pResult) : {
|
|
160
|
+
isWithin: false
|
|
161
|
+
};
|
|
250
162
|
if (isWithinThirdPartySegment) {
|
|
251
|
-
var _this$
|
|
252
|
-
(_this$
|
|
163
|
+
var _this$intersectionObs7;
|
|
164
|
+
(_this$intersectionObs7 = this.intersectionObserver) === null || _this$intersectionObs7 === void 0 ? void 0 : _this$intersectionObs7.watchAndTag(element, 'mutation:third-party-element');
|
|
253
165
|
continue;
|
|
254
166
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
element
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
(_this$intersectionObs15 = this.intersectionObserver) === null || _this$intersectionObs15 === void 0 ? void 0 : _this$intersectionObs15.watchAndTag(element, 'mutation:display-contents-children-element');
|
|
262
|
-
} else {
|
|
263
|
-
var _this$intersectionObs16;
|
|
264
|
-
(_this$intersectionObs16 = this.intersectionObserver) === null || _this$intersectionObs16 === void 0 ? void 0 : _this$intersectionObs16.watchAndTag(element, createElementMutationsWatcher(removedNodeRects));
|
|
265
|
-
}
|
|
167
|
+
if (isDisplayContentsElementChildren) {
|
|
168
|
+
var _this$intersectionObs8;
|
|
169
|
+
(_this$intersectionObs8 = this.intersectionObserver) === null || _this$intersectionObs8 === void 0 ? void 0 : _this$intersectionObs8.watchAndTag(element, 'mutation:display-contents-children-element');
|
|
170
|
+
} else {
|
|
171
|
+
var _this$intersectionObs9;
|
|
172
|
+
(_this$intersectionObs9 = this.intersectionObserver) === null || _this$intersectionObs9 === void 0 ? void 0 : _this$intersectionObs9.watchAndTag(element, createElementMutationsWatcher(removedNodeRects));
|
|
266
173
|
}
|
|
267
174
|
}
|
|
268
175
|
}
|
|
@@ -273,8 +180,8 @@ export default class ViewportObserver {
|
|
|
273
180
|
oldValue,
|
|
274
181
|
newValue
|
|
275
182
|
}) => {
|
|
276
|
-
var _this$
|
|
277
|
-
(_this$
|
|
183
|
+
var _this$intersectionObs0;
|
|
184
|
+
(_this$intersectionObs0 = this.intersectionObserver) === null || _this$intersectionObs0 === void 0 ? void 0 : _this$intersectionObs0.watchAndTag(target, ({
|
|
278
185
|
target,
|
|
279
186
|
rect
|
|
280
187
|
}) => {
|
|
@@ -416,12 +323,12 @@ export default class ViewportObserver {
|
|
|
416
323
|
this.isStarted = true;
|
|
417
324
|
}
|
|
418
325
|
stop() {
|
|
419
|
-
var _this$mutationObserve2, _this$
|
|
326
|
+
var _this$mutationObserve2, _this$intersectionObs1, _this$performanceObse2;
|
|
420
327
|
if (!this.isStarted) {
|
|
421
328
|
return;
|
|
422
329
|
}
|
|
423
330
|
(_this$mutationObserve2 = this.mutationObserver) === null || _this$mutationObserve2 === void 0 ? void 0 : _this$mutationObserve2.disconnect();
|
|
424
|
-
(_this$
|
|
331
|
+
(_this$intersectionObs1 = this.intersectionObserver) === null || _this$intersectionObs1 === void 0 ? void 0 : _this$intersectionObs1.disconnect();
|
|
425
332
|
(_this$performanceObse2 = this.performanceObserver) === null || _this$performanceObse2 === void 0 ? void 0 : _this$performanceObse2.disconnect();
|
|
426
333
|
this.isStarted = false;
|
|
427
334
|
// Clean up caches when stopping
|
|
@@ -31,6 +31,7 @@ import * as ssr from '../ssr';
|
|
|
31
31
|
import { buildSegmentTree, getOldSegmentsLabelStack, labelStackStartWith, optimizeLabelStack, sanitizeUfoName, stringifyLabelStackFully } from './common/utils';
|
|
32
32
|
import { createCriticalMetricsPayloads } from './critical-metrics-payload';
|
|
33
33
|
import { addPerformanceMeasures } from './utils/add-performance-measures';
|
|
34
|
+
import { getBatteryInfoToLegacyFormat } from './utils/get-battery-info';
|
|
34
35
|
import { getBrowserMetadataToLegacyFormat } from './utils/get-browser-metadata';
|
|
35
36
|
import getInteractionStatus from './utils/get-interaction-status';
|
|
36
37
|
import { getMoreAccuratePageVisibilityUpToTTAI } from './utils/get-more-accurate-page-visibility-up-to-ttai';
|
|
@@ -389,7 +390,7 @@ function createInteractionMetricsPayload(_x, _x2, _x3, _x4, _x5) {
|
|
|
389
390
|
function _createInteractionMetricsPayload() {
|
|
390
391
|
_createInteractionMetricsPayload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(interaction, interactionId, experimental, criticalPayloadCount, vcMetrics) {
|
|
391
392
|
var _window$location, _config$additionalPay;
|
|
392
|
-
var interactionPayloadStart, config, end, start, ufoName, knownSegments, rate, type, abortReason, routeName, featureFlags, previousInteractionName, isPreviousInteractionAborted, abortedByInteractionName, responsiveness, unknownElementName, unknownElementHierarchy, hydration, pageVisibilityAtTTI, pageVisibilityAtTTAI, segments, segmentTree, isDetailedPayload, isPageLoad, calculatePageVisibilityFromTheStartOfPageLoad, moreAccuratePageVisibilityAtTTI, moreAccuratePageVisibilityAtTTAI, labelStack, getInitialPageLoadSSRMetrics, pageLoadInteractionMetrics, getDetailedInteractionMetrics, getPageLoadDetailedInteractionMetrics, newUFOName, resourceTimings, _yield$Promise$all, _yield$Promise$all2, finalVCMetrics, experimentalMetrics, paintMetrics, getReactHydrationStats, payload;
|
|
393
|
+
var interactionPayloadStart, config, end, start, ufoName, knownSegments, rate, type, abortReason, routeName, featureFlags, previousInteractionName, isPreviousInteractionAborted, abortedByInteractionName, responsiveness, unknownElementName, unknownElementHierarchy, hydration, pageVisibilityAtTTI, pageVisibilityAtTTAI, segments, segmentTree, isDetailedPayload, isPageLoad, calculatePageVisibilityFromTheStartOfPageLoad, moreAccuratePageVisibilityAtTTI, moreAccuratePageVisibilityAtTTAI, labelStack, getInitialPageLoadSSRMetrics, pageLoadInteractionMetrics, getDetailedInteractionMetrics, getPageLoadDetailedInteractionMetrics, newUFOName, resourceTimings, _yield$Promise$all, _yield$Promise$all2, finalVCMetrics, experimentalMetrics, paintMetrics, batteryInfo, getReactHydrationStats, payload;
|
|
393
394
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
394
395
|
while (1) switch (_context.prev = _context.next) {
|
|
395
396
|
case 0:
|
|
@@ -502,15 +503,17 @@ function _createInteractionMetricsPayload() {
|
|
|
502
503
|
_context.t2 = _context.t1;
|
|
503
504
|
_context.t3 = experimental ? getExperimentalVCMetrics(interaction) : Promise.resolve(undefined);
|
|
504
505
|
_context.t4 = getPaintMetricsToLegacyFormat(type, end);
|
|
505
|
-
_context.t5 =
|
|
506
|
-
_context.
|
|
507
|
-
|
|
508
|
-
|
|
506
|
+
_context.t5 = getBatteryInfoToLegacyFormat();
|
|
507
|
+
_context.t6 = [_context.t2, _context.t3, _context.t4, _context.t5];
|
|
508
|
+
_context.next = 35;
|
|
509
|
+
return _context.t0.all.call(_context.t0, _context.t6);
|
|
510
|
+
case 35:
|
|
509
511
|
_yield$Promise$all = _context.sent;
|
|
510
|
-
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all,
|
|
512
|
+
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 4);
|
|
511
513
|
finalVCMetrics = _yield$Promise$all2[0];
|
|
512
514
|
experimentalMetrics = _yield$Promise$all2[1];
|
|
513
515
|
paintMetrics = _yield$Promise$all2[2];
|
|
516
|
+
batteryInfo = _yield$Promise$all2[3];
|
|
514
517
|
if (!experimental) {
|
|
515
518
|
addPerformanceMeasures(interaction.start, _toConsumableArray((finalVCMetrics === null || finalVCMetrics === void 0 ? void 0 : finalVCMetrics['ufo:vc:rev']) || []));
|
|
516
519
|
}
|
|
@@ -529,7 +532,7 @@ function _createInteractionMetricsPayload() {
|
|
|
529
532
|
source: 'measured',
|
|
530
533
|
tags: ['observability'],
|
|
531
534
|
attributes: {
|
|
532
|
-
properties: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
535
|
+
properties: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
533
536
|
// basic
|
|
534
537
|
'event:hostname': ((_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.hostname) || 'unknown',
|
|
535
538
|
'event:product': config.product,
|
|
@@ -548,7 +551,7 @@ function _createInteractionMetricsPayload() {
|
|
|
548
551
|
}, criticalPayloadCount !== undefined ? {
|
|
549
552
|
'ufo:multipayload': true,
|
|
550
553
|
'ufo:criticalPayloadCount': criticalPayloadCount
|
|
551
|
-
} : {}), getBrowserMetadataToLegacyFormat()), getSSRProperties(type)), getAssetsMetrics(interaction, pageLoadInteractionMetrics === null || pageLoadInteractionMetrics === void 0 ? void 0 : pageLoadInteractionMetrics.SSRDoneTime)), getPPSMetrics(interaction)), paintMetrics), getNavigationMetricsToLegacyFormat(type)), finalVCMetrics), experimentalMetrics), (_config$additionalPay = config.additionalPayloadData) === null || _config$additionalPay === void 0 ? void 0 : _config$additionalPay.call(config, interaction)), getTracingContextData(interaction)), getStylesheetMetrics()), getErrorCounts(interaction)), getReactHydrationStats()), {}, {
|
|
554
|
+
} : {}), getBrowserMetadataToLegacyFormat()), batteryInfo), getSSRProperties(type)), getAssetsMetrics(interaction, pageLoadInteractionMetrics === null || pageLoadInteractionMetrics === void 0 ? void 0 : pageLoadInteractionMetrics.SSRDoneTime)), getPPSMetrics(interaction)), paintMetrics), getNavigationMetricsToLegacyFormat(type)), finalVCMetrics), experimentalMetrics), (_config$additionalPay = config.additionalPayloadData) === null || _config$additionalPay === void 0 ? void 0 : _config$additionalPay.call(config, interaction)), getTracingContextData(interaction)), getStylesheetMetrics()), getErrorCounts(interaction)), getReactHydrationStats()), {}, {
|
|
552
555
|
interactionMetrics: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
553
556
|
namePrefix: config.namePrefix || '',
|
|
554
557
|
segmentPrefix: config.segmentPrefix || '',
|
|
@@ -595,7 +598,7 @@ function _createInteractionMetricsPayload() {
|
|
|
595
598
|
}
|
|
596
599
|
payload.attributes.properties['event:sizeInKb'] = getPayloadSize(payload.attributes.properties);
|
|
597
600
|
return _context.abrupt("return", payload);
|
|
598
|
-
case
|
|
601
|
+
case 47:
|
|
599
602
|
case "end":
|
|
600
603
|
return _context.stop();
|
|
601
604
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
|
+
|
|
5
|
+
// Type definitions for battery info
|
|
6
|
+
|
|
7
|
+
// Main function returns compact nested format
|
|
8
|
+
export default function getBatteryInfo() {
|
|
9
|
+
return _getBatteryInfo.apply(this, arguments);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Helper function to get battery info in legacy colon format for backward compatibility
|
|
13
|
+
function _getBatteryInfo() {
|
|
14
|
+
_getBatteryInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
15
|
+
var battery;
|
|
16
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
17
|
+
while (1) switch (_context.prev = _context.next) {
|
|
18
|
+
case 0:
|
|
19
|
+
if (fg('react_ufo_battery_info')) {
|
|
20
|
+
_context.next = 2;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
return _context.abrupt("return", {});
|
|
24
|
+
case 2:
|
|
25
|
+
if (!(typeof navigator === 'undefined')) {
|
|
26
|
+
_context.next = 4;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
return _context.abrupt("return", {});
|
|
30
|
+
case 4:
|
|
31
|
+
_context.prev = 4;
|
|
32
|
+
if (!('getBattery' in navigator)) {
|
|
33
|
+
_context.next = 11;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
_context.next = 8;
|
|
37
|
+
return navigator.getBattery();
|
|
38
|
+
case 8:
|
|
39
|
+
battery = _context.sent;
|
|
40
|
+
if (!(battery && typeof battery.level === 'number' && typeof battery.charging === 'boolean')) {
|
|
41
|
+
_context.next = 11;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
return _context.abrupt("return", {
|
|
45
|
+
level: Math.round(battery.level * 100) / 100,
|
|
46
|
+
// Round to 0.01
|
|
47
|
+
charging: battery.charging
|
|
48
|
+
});
|
|
49
|
+
case 11:
|
|
50
|
+
_context.next = 15;
|
|
51
|
+
break;
|
|
52
|
+
case 13:
|
|
53
|
+
_context.prev = 13;
|
|
54
|
+
_context.t0 = _context["catch"](4);
|
|
55
|
+
case 15:
|
|
56
|
+
return _context.abrupt("return", {});
|
|
57
|
+
case 16:
|
|
58
|
+
case "end":
|
|
59
|
+
return _context.stop();
|
|
60
|
+
}
|
|
61
|
+
}, _callee, null, [[4, 13]]);
|
|
62
|
+
}));
|
|
63
|
+
return _getBatteryInfo.apply(this, arguments);
|
|
64
|
+
}
|
|
65
|
+
export function getBatteryInfoToLegacyFormat() {
|
|
66
|
+
return _getBatteryInfoToLegacyFormat.apply(this, arguments);
|
|
67
|
+
}
|
|
68
|
+
function _getBatteryInfoToLegacyFormat() {
|
|
69
|
+
_getBatteryInfoToLegacyFormat = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
70
|
+
var battery, legacyFormat;
|
|
71
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
72
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
73
|
+
case 0:
|
|
74
|
+
_context2.next = 2;
|
|
75
|
+
return getBatteryInfo();
|
|
76
|
+
case 2:
|
|
77
|
+
battery = _context2.sent;
|
|
78
|
+
legacyFormat = {};
|
|
79
|
+
if (battery.level !== undefined) {
|
|
80
|
+
legacyFormat['event:battery:level'] = battery.level;
|
|
81
|
+
}
|
|
82
|
+
if (battery.charging !== undefined) {
|
|
83
|
+
legacyFormat['event:battery:charging'] = battery.charging;
|
|
84
|
+
}
|
|
85
|
+
return _context2.abrupt("return", legacyFormat);
|
|
86
|
+
case 7:
|
|
87
|
+
case "end":
|
|
88
|
+
return _context2.stop();
|
|
89
|
+
}
|
|
90
|
+
}, _callee2);
|
|
91
|
+
}));
|
|
92
|
+
return _getBatteryInfoToLegacyFormat.apply(this, arguments);
|
|
93
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
4
|
var ANCESTOR_LOOKUP_LIMIT = 10;
|
|
6
5
|
var PAGE_LAYOUT_ID = 'page-layout.root';
|
|
7
6
|
export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
|
|
@@ -284,45 +283,40 @@ export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
|
|
|
284
283
|
}, {
|
|
285
284
|
key: "getEffectiveBoundingRect",
|
|
286
285
|
value: function getEffectiveBoundingRect(el) {
|
|
287
|
-
var
|
|
286
|
+
var computedStyle = window.getComputedStyle(el);
|
|
288
287
|
|
|
289
|
-
//
|
|
290
|
-
if (
|
|
291
|
-
var
|
|
288
|
+
// If element has display: contents, collect bounding rect from children
|
|
289
|
+
if (computedStyle.display === 'contents') {
|
|
290
|
+
var children = Array.from(el.children);
|
|
291
|
+
if (children.length === 0) {
|
|
292
|
+
// No children, return zero rect
|
|
293
|
+
return new DOMRect(0, 0, 0, 0);
|
|
294
|
+
}
|
|
292
295
|
|
|
293
|
-
//
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
296
|
+
// Calculate union of all children's bounding rects
|
|
297
|
+
var minX = Infinity;
|
|
298
|
+
var minY = Infinity;
|
|
299
|
+
var maxX = -Infinity;
|
|
300
|
+
var maxY = -Infinity;
|
|
301
|
+
children.forEach(function (child) {
|
|
302
|
+
var childRect = child.getBoundingClientRect();
|
|
303
|
+
// Skip children with zero dimensions (likely also display: contents)
|
|
304
|
+
if (childRect.width > 0 || childRect.height > 0) {
|
|
305
|
+
minX = Math.min(minX, childRect.left);
|
|
306
|
+
minY = Math.min(minY, childRect.top);
|
|
307
|
+
maxX = Math.max(maxX, childRect.right);
|
|
308
|
+
maxY = Math.max(maxY, childRect.bottom);
|
|
299
309
|
}
|
|
310
|
+
});
|
|
300
311
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
var maxX = -Infinity;
|
|
305
|
-
var maxY = -Infinity;
|
|
306
|
-
children.forEach(function (child) {
|
|
307
|
-
var childRect = child.getBoundingClientRect();
|
|
308
|
-
// Skip children with zero dimensions (likely also display: contents)
|
|
309
|
-
if (childRect.width > 0 || childRect.height > 0) {
|
|
310
|
-
minX = Math.min(minX, childRect.left);
|
|
311
|
-
minY = Math.min(minY, childRect.top);
|
|
312
|
-
maxX = Math.max(maxX, childRect.right);
|
|
313
|
-
maxY = Math.max(maxY, childRect.bottom);
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
// If no children with dimensions found, return zero rect
|
|
318
|
-
if (minX === Infinity) {
|
|
319
|
-
return new DOMRect(0, 0, 0, 0);
|
|
320
|
-
}
|
|
321
|
-
return new DOMRect(minX, minY, maxX - minX, maxY - minY);
|
|
312
|
+
// If no children with dimensions found, return zero rect
|
|
313
|
+
if (minX === Infinity) {
|
|
314
|
+
return new DOMRect(0, 0, 0, 0);
|
|
322
315
|
}
|
|
316
|
+
return new DOMRect(minX, minY, maxX - minX, maxY - minY);
|
|
323
317
|
}
|
|
324
318
|
|
|
325
|
-
// Normal element
|
|
319
|
+
// Normal element, return its bounding rect
|
|
326
320
|
return el.getBoundingClientRect();
|
|
327
321
|
}
|
|
328
322
|
}, {
|
|
@@ -1,32 +1,21 @@
|
|
|
1
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
-
|
|
3
1
|
// lightweight script to scan the SSR response and collect all elements with data-ssr-placeholder attribute
|
|
4
2
|
// and save their size/positions in a map __SSR_PLACEHOLDERS_DIMENSIONS__ on the Window object. Each placeholderId is
|
|
5
3
|
// unique and maps to its corresponding elements bounding client rectangle dimensions.
|
|
6
4
|
export function collectSSRPlaceholderDimensions(document, window) {
|
|
7
5
|
var enablePageLayoutPlaceholder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
8
|
-
var enableDisplayContentsSupport = fg('platform_ufo_ssr_placeholders_for_display_contents');
|
|
9
6
|
var ssrPlaceholders = document === null || document === void 0 ? void 0 : document.querySelectorAll('[data-ssr-placeholder]');
|
|
10
7
|
ssrPlaceholders.forEach(function (elem) {
|
|
11
8
|
var placeholderId = elem.getAttribute('data-ssr-placeholder');
|
|
12
9
|
if (placeholderId) {
|
|
13
10
|
window.__SSR_PLACEHOLDERS_DIMENSIONS__ = window.__SSR_PLACEHOLDERS_DIMENSIONS__ || {};
|
|
14
|
-
|
|
15
|
-
window.__SSR_PLACEHOLDERS_DIMENSIONS__[placeholderId] = getEffectiveBoundingRect(elem, window);
|
|
16
|
-
} else {
|
|
17
|
-
window.__SSR_PLACEHOLDERS_DIMENSIONS__[placeholderId] = elem.getBoundingClientRect();
|
|
18
|
-
}
|
|
11
|
+
window.__SSR_PLACEHOLDERS_DIMENSIONS__[placeholderId] = getEffectiveBoundingRect(elem, window);
|
|
19
12
|
}
|
|
20
13
|
});
|
|
21
14
|
if (enablePageLayoutPlaceholder) {
|
|
22
15
|
var pageLayoutRoot = document === null || document === void 0 ? void 0 : document.getElementById('unsafe-design-system-page-layout-root');
|
|
23
16
|
if (pageLayoutRoot) {
|
|
24
17
|
window.__SSR_PLACEHOLDERS_DIMENSIONS__ = window.__SSR_PLACEHOLDERS_DIMENSIONS__ || {};
|
|
25
|
-
|
|
26
|
-
window.__SSR_PLACEHOLDERS_DIMENSIONS__['page-layout.root'] = getEffectiveBoundingRect(pageLayoutRoot, window);
|
|
27
|
-
} else {
|
|
28
|
-
window.__SSR_PLACEHOLDERS_DIMENSIONS__['page-layout.root'] = pageLayoutRoot.getBoundingClientRect();
|
|
29
|
-
}
|
|
18
|
+
window.__SSR_PLACEHOLDERS_DIMENSIONS__['page-layout.root'] = getEffectiveBoundingRect(pageLayoutRoot, window);
|
|
30
19
|
}
|
|
31
20
|
}
|
|
32
21
|
}
|