@atlaskit/react-ufo 5.0.12 → 5.1.0

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.
Files changed (28) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/experience-trace-id-context/context-manager.js +180 -0
  3. package/dist/cjs/experience-trace-id-context/index.js +67 -11
  4. package/dist/cjs/interaction-metrics-init/index.js +15 -6
  5. package/dist/cjs/vc/index.js +6 -6
  6. package/dist/cjs/vc/vc-observer/observers/ssr-placeholders/index.js +0 -3
  7. package/dist/es2019/experience-trace-id-context/context-manager.js +142 -0
  8. package/dist/es2019/experience-trace-id-context/index.js +65 -9
  9. package/dist/es2019/interaction-metrics-init/index.js +15 -6
  10. package/dist/es2019/vc/index.js +6 -6
  11. package/dist/es2019/vc/vc-observer/observers/ssr-placeholders/index.js +0 -3
  12. package/dist/esm/experience-trace-id-context/context-manager.js +172 -0
  13. package/dist/esm/experience-trace-id-context/index.js +67 -11
  14. package/dist/esm/interaction-metrics-init/index.js +15 -6
  15. package/dist/esm/vc/index.js +6 -6
  16. package/dist/esm/vc/vc-observer/observers/ssr-placeholders/index.js +0 -3
  17. package/dist/types/common/react-ufo-payload-schema.d.ts +5 -0
  18. package/dist/types/config/index.d.ts +6 -0
  19. package/dist/types/experience-trace-id-context/context-manager.d.ts +65 -0
  20. package/dist/types-ts4.5/common/react-ufo-payload-schema.d.ts +5 -0
  21. package/dist/types-ts4.5/config/index.d.ts +6 -0
  22. package/dist/types-ts4.5/experience-trace-id-context/context-manager.d.ts +65 -0
  23. package/package.json +6 -5
  24. package/dist/cjs/vc/vc-observer-new/viewport-observer/utils/get-mutated-elements.js +0 -68
  25. package/dist/es2019/vc/vc-observer-new/viewport-observer/utils/get-mutated-elements.js +0 -45
  26. package/dist/esm/vc/vc-observer-new/viewport-observer/utils/get-mutated-elements.js +0 -61
  27. package/dist/types/vc/vc-observer-new/viewport-observer/utils/get-mutated-elements.d.ts +0 -6
  28. package/dist/types-ts4.5/vc/vc-observer-new/viewport-observer/utils/get-mutated-elements.d.ts +0 -6
@@ -0,0 +1,65 @@
1
+ import { type Context, type ContextManager } from '@opentelemetry/api';
2
+ export declare function setContextManager(ctxMgr: ContextManager): void;
3
+ export declare function getContextManager(): ContextManager;
4
+ /**
5
+ * The below is shamelessly borrowed from StackContextManager from @opentelemetry/sdk-trace-web
6
+ * Using this rather than importing the entire package because this is all we need for now
7
+ */
8
+ /**
9
+ * UFO Context Manager for managing the state in web
10
+ * it doesn't fully support the async calls though
11
+ */
12
+ export declare class UFOContextManager implements ContextManager {
13
+ /**
14
+ * whether the context manager is enabled or not
15
+ */
16
+ private _enabled;
17
+ /**
18
+ * Keeps the reference to current context
19
+ */
20
+ _currentContext: Context;
21
+ /**
22
+ *
23
+ * @param context
24
+ * @param target Function to be executed within the context
25
+ */
26
+ private _bindFunction;
27
+ /**
28
+ * Returns the active context
29
+ */
30
+ active(): Context;
31
+ /**
32
+ * Binds a the certain context or the active one to the target function and then returns the target
33
+ * @param context A context (span) to be bind to target
34
+ * @param target a function or event emitter. When target or one of its callbacks is called,
35
+ * the provided context will be used as the active context for the duration of the call.
36
+ */
37
+ bind<T>(context: Context, target: T): T;
38
+ /**
39
+ * Disable the context manager (clears the current context)
40
+ */
41
+ disable(): this;
42
+ /**
43
+ * Enables the context manager and creates a default(root) context
44
+ */
45
+ enable(): this;
46
+ /**
47
+ * Calls the callback function [fn] with the provided [context]. If [context] is undefined then it will use the window.
48
+ * The context will be set as active
49
+ * @param context
50
+ * @param fn Callback function
51
+ * @param thisArg optional receiver to be used for calling fn
52
+ * @param args optional arguments forwarded to fn
53
+ */
54
+ with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: Context | null, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
55
+ /**
56
+ * Sets the active context.
57
+ * This function is an extension of the OTel spec, in order to facilitate the current API of React UFO trace context handling.
58
+ * It doesn't keep track of any previously set active contexts, because it's assumed (for now) that only one trace context
59
+ * will ever exist at a time.
60
+ * The next step in the work to improve tracing in the FE will likely remove this function as we need to track the
61
+ * hierarchy of contexts (likely using the `with()` function above).
62
+ * @param context The context to be made the globally active one
63
+ */
64
+ setActive(context: Context): void;
65
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/react-ufo",
3
- "version": "5.0.12",
3
+ "version": "5.1.0",
4
4
  "description": "Parts of React UFO that are publicly available",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,6 +32,7 @@
32
32
  "@atlaskit/interaction-context": "^3.1.0",
33
33
  "@atlaskit/platform-feature-flags": "^1.1.0",
34
34
  "@babel/runtime": "^7.0.0",
35
+ "@opentelemetry/api": "^1.9.0",
35
36
  "bind-event-listener": "^3.0.0",
36
37
  "bowser-ultralight": "^1.0.6",
37
38
  "scheduler": "0.23.2",
@@ -42,7 +43,7 @@
42
43
  },
43
44
  "devDependencies": {
44
45
  "@af/integration-testing": "workspace:^",
45
- "@atlassian/a11y-jest-testing": "^0.8.0",
46
+ "@atlassian/a11y-jest-testing": "^0.9.0",
46
47
  "@atlassian/feature-flags-test-utils": "^1.0.0",
47
48
  "@testing-library/react": "^16.3.0",
48
49
  "@types/is-ci": "^3.0.0",
@@ -115,9 +116,6 @@
115
116
  "platform_ufo_critical_metrics_payload": {
116
117
  "type": "boolean"
117
118
  },
118
- "platform_ufo_disable_vcnext_observations": {
119
- "type": "boolean"
120
- },
121
119
  "platform_ufo_exclude_3p_elements_from_ttai": {
122
120
  "type": "boolean"
123
121
  },
@@ -196,6 +194,9 @@
196
194
  "platform_ufo_keypress_interaction_abort": {
197
195
  "type": "boolean"
198
196
  },
197
+ "platform_ufo_enable_otel_context_manager": {
198
+ "type": "boolean"
199
+ },
199
200
  "platform_ufo_raw_data_thirdparty": {
200
201
  "type": "boolean"
201
202
  },
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getMutatedElements = getMutatedElements;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
11
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
13
- function isElementStyledWithDisplayContents(element) {
14
- var _window2;
15
- // To minimise calling `getComputedStyle`, we are making an assumption that if an element is from the Entrypoints framework, then it will have `display: contents` styling
16
- // as per https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/e4ccf437262ef4c0fd3c651ffb7ad4770b15aed4/jira/src/packages/platform/entry-points/entry-point-placeholder/src/index.tsx#lines-136
17
- if ((0, _platformFeatureFlags.fg)('platform_ufo_detect_entrypoint_parent')) {
18
- var _window;
19
- if (element.hasAttribute('data-ep-placeholder-id')) {
20
- return true;
21
- }
22
- return ((_window = window) === null || _window === void 0 || (_window = _window.getComputedStyle(element)) === null || _window === void 0 ? void 0 : _window.display) === 'contents';
23
- }
24
- return ((_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.getComputedStyle(element)) === null || _window2 === void 0 ? void 0 : _window2.display) === 'contents';
25
- }
26
- var MAX_NESTED_LEVELS_OF_DISPLAY_CONTENT_ELEMENTS_HANDLED = 3;
27
- function getMutatedElements(element) {
28
- var depthLevel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
29
- if ((0, _platformFeatureFlags.fg)('platform_ufo_disable_vcnext_observations')) {
30
- return [{
31
- element: element,
32
- isDisplayContentsElementChildren: false
33
- }];
34
- }
35
- if (isElementStyledWithDisplayContents(element)) {
36
- var mutatedElements = [];
37
- var nestedDisplayContentsElementChildren = [];
38
- var _iterator = _createForOfIteratorHelper(element.children),
39
- _step;
40
- try {
41
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
42
- var child = _step.value;
43
- if (isElementStyledWithDisplayContents(child)) {
44
- nestedDisplayContentsElementChildren.push(child);
45
- }
46
- mutatedElements.push({
47
- element: child,
48
- isDisplayContentsElementChildren: true
49
- });
50
- }
51
- } catch (err) {
52
- _iterator.e(err);
53
- } finally {
54
- _iterator.f();
55
- }
56
- if (depthLevel < MAX_NESTED_LEVELS_OF_DISPLAY_CONTENT_ELEMENTS_HANDLED && nestedDisplayContentsElementChildren.length > 0) {
57
- return [].concat(mutatedElements, (0, _toConsumableArray2.default)(nestedDisplayContentsElementChildren.map(function (element) {
58
- return getMutatedElements(element, depthLevel + 1);
59
- }).flat()));
60
- }
61
- return mutatedElements;
62
- } else {
63
- return [{
64
- element: element,
65
- isDisplayContentsElementChildren: false
66
- }];
67
- }
68
- }
@@ -1,45 +0,0 @@
1
- import { fg } from '@atlaskit/platform-feature-flags';
2
- function isElementStyledWithDisplayContents(element) {
3
- var _window2, _window2$getComputedS;
4
- // To minimise calling `getComputedStyle`, we are making an assumption that if an element is from the Entrypoints framework, then it will have `display: contents` styling
5
- // as per https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/e4ccf437262ef4c0fd3c651ffb7ad4770b15aed4/jira/src/packages/platform/entry-points/entry-point-placeholder/src/index.tsx#lines-136
6
- if (fg('platform_ufo_detect_entrypoint_parent')) {
7
- var _window, _window$getComputedSt;
8
- if (element.hasAttribute('data-ep-placeholder-id')) {
9
- return true;
10
- }
11
- return ((_window = window) === null || _window === void 0 ? void 0 : (_window$getComputedSt = _window.getComputedStyle(element)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.display) === 'contents';
12
- }
13
- return ((_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$getComputedS = _window2.getComputedStyle(element)) === null || _window2$getComputedS === void 0 ? void 0 : _window2$getComputedS.display) === 'contents';
14
- }
15
- const MAX_NESTED_LEVELS_OF_DISPLAY_CONTENT_ELEMENTS_HANDLED = 3;
16
- export function getMutatedElements(element, depthLevel = 0) {
17
- if (fg('platform_ufo_disable_vcnext_observations')) {
18
- return [{
19
- element,
20
- isDisplayContentsElementChildren: false
21
- }];
22
- }
23
- if (isElementStyledWithDisplayContents(element)) {
24
- const mutatedElements = [];
25
- const nestedDisplayContentsElementChildren = [];
26
- for (const child of element.children) {
27
- if (isElementStyledWithDisplayContents(child)) {
28
- nestedDisplayContentsElementChildren.push(child);
29
- }
30
- mutatedElements.push({
31
- element: child,
32
- isDisplayContentsElementChildren: true
33
- });
34
- }
35
- if (depthLevel < MAX_NESTED_LEVELS_OF_DISPLAY_CONTENT_ELEMENTS_HANDLED && nestedDisplayContentsElementChildren.length > 0) {
36
- return [...mutatedElements, ...nestedDisplayContentsElementChildren.map(element => getMutatedElements(element, depthLevel + 1)).flat()];
37
- }
38
- return mutatedElements;
39
- } else {
40
- return [{
41
- element,
42
- isDisplayContentsElementChildren: false
43
- }];
44
- }
45
- }
@@ -1,61 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
3
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
- import { fg } from '@atlaskit/platform-feature-flags';
6
- function isElementStyledWithDisplayContents(element) {
7
- var _window2;
8
- // To minimise calling `getComputedStyle`, we are making an assumption that if an element is from the Entrypoints framework, then it will have `display: contents` styling
9
- // as per https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/e4ccf437262ef4c0fd3c651ffb7ad4770b15aed4/jira/src/packages/platform/entry-points/entry-point-placeholder/src/index.tsx#lines-136
10
- if (fg('platform_ufo_detect_entrypoint_parent')) {
11
- var _window;
12
- if (element.hasAttribute('data-ep-placeholder-id')) {
13
- return true;
14
- }
15
- return ((_window = window) === null || _window === void 0 || (_window = _window.getComputedStyle(element)) === null || _window === void 0 ? void 0 : _window.display) === 'contents';
16
- }
17
- return ((_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.getComputedStyle(element)) === null || _window2 === void 0 ? void 0 : _window2.display) === 'contents';
18
- }
19
- var MAX_NESTED_LEVELS_OF_DISPLAY_CONTENT_ELEMENTS_HANDLED = 3;
20
- export function getMutatedElements(element) {
21
- var depthLevel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
22
- if (fg('platform_ufo_disable_vcnext_observations')) {
23
- return [{
24
- element: element,
25
- isDisplayContentsElementChildren: false
26
- }];
27
- }
28
- if (isElementStyledWithDisplayContents(element)) {
29
- var mutatedElements = [];
30
- var nestedDisplayContentsElementChildren = [];
31
- var _iterator = _createForOfIteratorHelper(element.children),
32
- _step;
33
- try {
34
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
35
- var child = _step.value;
36
- if (isElementStyledWithDisplayContents(child)) {
37
- nestedDisplayContentsElementChildren.push(child);
38
- }
39
- mutatedElements.push({
40
- element: child,
41
- isDisplayContentsElementChildren: true
42
- });
43
- }
44
- } catch (err) {
45
- _iterator.e(err);
46
- } finally {
47
- _iterator.f();
48
- }
49
- if (depthLevel < MAX_NESTED_LEVELS_OF_DISPLAY_CONTENT_ELEMENTS_HANDLED && nestedDisplayContentsElementChildren.length > 0) {
50
- return [].concat(mutatedElements, _toConsumableArray(nestedDisplayContentsElementChildren.map(function (element) {
51
- return getMutatedElements(element, depthLevel + 1);
52
- }).flat()));
53
- }
54
- return mutatedElements;
55
- } else {
56
- return [{
57
- element: element,
58
- isDisplayContentsElementChildren: false
59
- }];
60
- }
61
- }
@@ -1,6 +0,0 @@
1
- type MutatedElement = {
2
- isDisplayContentsElementChildren: boolean;
3
- element: Element;
4
- };
5
- export declare function getMutatedElements(element: Element, depthLevel?: number): MutatedElement[];
6
- export {};
@@ -1,6 +0,0 @@
1
- type MutatedElement = {
2
- isDisplayContentsElementChildren: boolean;
3
- element: Element;
4
- };
5
- export declare function getMutatedElements(element: Element, depthLevel?: number): MutatedElement[];
6
- export {};