@atlaskit/analytics-next 10.1.1 → 10.2.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.
Files changed (56) hide show
  1. package/AnalyticsDecorator/package.json +15 -0
  2. package/AnalyticsDelegate/package.json +15 -0
  3. package/CHANGELOG.md +18 -0
  4. package/afm-cc/tsconfig.json +1 -2
  5. package/afm-jira/tsconfig.json +24 -24
  6. package/afm-post-office/tsconfig.json +24 -24
  7. package/dist/cjs/components/AnalyticsContext/LegacyAnalyticsContext.js +8 -11
  8. package/dist/cjs/components/AnalyticsContext/index.js +1 -1
  9. package/dist/cjs/components/AnalyticsDecorator/index.js +104 -0
  10. package/dist/cjs/components/AnalyticsDelegate/index.js +72 -0
  11. package/dist/cjs/components/AnalyticsErrorBoundary.js +6 -8
  12. package/dist/cjs/components/AnalyticsListener/LegacyAnalyticsListener.js +8 -11
  13. package/dist/cjs/components/AnalyticsListener/index.js +1 -1
  14. package/dist/cjs/components/matchEvent/index.js +23 -0
  15. package/dist/cjs/events/AnalyticsEvent.js +1 -2
  16. package/dist/cjs/events/UIAnalyticsEvent.js +12 -14
  17. package/dist/cjs/index.js +21 -0
  18. package/dist/cjs/utils/isModernContextEnabledEnv.js +1 -0
  19. package/dist/cjs/utils/withAnalytics.js +144 -0
  20. package/dist/es2019/components/AnalyticsContext/index.js +1 -1
  21. package/dist/es2019/components/AnalyticsDecorator/index.js +79 -0
  22. package/dist/es2019/components/AnalyticsDelegate/index.js +48 -0
  23. package/dist/es2019/components/AnalyticsErrorBoundary.js +1 -1
  24. package/dist/es2019/components/AnalyticsListener/index.js +1 -1
  25. package/dist/es2019/components/matchEvent/index.js +17 -0
  26. package/dist/es2019/events/UIAnalyticsEvent.js +1 -0
  27. package/dist/es2019/index.js +6 -1
  28. package/dist/es2019/utils/isModernContextEnabledEnv.js +1 -0
  29. package/dist/es2019/utils/withAnalytics.js +121 -0
  30. package/dist/esm/components/AnalyticsContext/LegacyAnalyticsContext.js +8 -11
  31. package/dist/esm/components/AnalyticsContext/index.js +1 -1
  32. package/dist/esm/components/AnalyticsDecorator/index.js +94 -0
  33. package/dist/esm/components/AnalyticsDelegate/index.js +62 -0
  34. package/dist/esm/components/AnalyticsErrorBoundary.js +6 -8
  35. package/dist/esm/components/AnalyticsListener/LegacyAnalyticsListener.js +8 -11
  36. package/dist/esm/components/AnalyticsListener/index.js +1 -1
  37. package/dist/esm/components/matchEvent/index.js +17 -0
  38. package/dist/esm/events/AnalyticsEvent.js +1 -2
  39. package/dist/esm/events/UIAnalyticsEvent.js +13 -14
  40. package/dist/esm/index.js +6 -1
  41. package/dist/esm/utils/isModernContextEnabledEnv.js +1 -0
  42. package/dist/esm/utils/withAnalytics.js +134 -0
  43. package/dist/types/components/AnalyticsDecorator/index.d.ts +46 -0
  44. package/dist/types/components/AnalyticsDelegate/index.d.ts +25 -0
  45. package/dist/types/components/matchEvent/index.d.ts +3 -0
  46. package/dist/types/hocs/withAnalyticsEvents.d.ts +1 -1
  47. package/dist/types/index.d.ts +3 -0
  48. package/dist/types/utils/withAnalytics.d.ts +80 -0
  49. package/dist/types-ts4.5/components/AnalyticsDecorator/index.d.ts +46 -0
  50. package/dist/types-ts4.5/components/AnalyticsDelegate/index.d.ts +25 -0
  51. package/dist/types-ts4.5/components/matchEvent/index.d.ts +3 -0
  52. package/dist/types-ts4.5/hocs/withAnalyticsEvents.d.ts +1 -1
  53. package/dist/types-ts4.5/index.d.ts +3 -0
  54. package/dist/types-ts4.5/utils/withAnalytics.d.ts +80 -0
  55. package/package.json +13 -5
  56. package/withAnalytics/package.json +15 -0
@@ -8,15 +8,15 @@ exports.isUIAnalyticsEvent = exports.default = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
12
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
13
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
11
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
15
12
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
14
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
16
15
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
16
  var _AnalyticsEvent2 = _interopRequireDefault(require("./AnalyticsEvent"));
18
- function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = (0, _getPrototypeOf2.default)(t); if (r) { var s = (0, _getPrototypeOf2.default)(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return (0, _possibleConstructorReturn2.default)(this, e); }; }
17
+ function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
19
18
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
19
+ function _superPropGet(t, o, e, r) { var p = (0, _get2.default)((0, _getPrototypeOf2.default)(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; } /// <reference types="node" />
20
20
  var isUIAnalyticsEvent = exports.isUIAnalyticsEvent = function isUIAnalyticsEvent(obj) {
21
21
  var _obj$constructor;
22
22
  return obj instanceof UIAnalyticsEvent || !!(obj !== null && obj !== void 0 && obj._isUIAnalyticsEvent) ||
@@ -24,14 +24,12 @@ var isUIAnalyticsEvent = exports.isUIAnalyticsEvent = function isUIAnalyticsEven
24
24
  (obj === null || obj === void 0 || (_obj$constructor = obj.constructor) === null || _obj$constructor === void 0 ? void 0 : _obj$constructor.name) === 'UIAnalyticsEvent';
25
25
  };
26
26
  var UIAnalyticsEvent = exports.default = /*#__PURE__*/function (_AnalyticsEvent) {
27
- (0, _inherits2.default)(UIAnalyticsEvent, _AnalyticsEvent);
28
- var _super = _createSuper(UIAnalyticsEvent);
29
27
  function UIAnalyticsEvent(props) {
30
28
  var _this;
31
29
  (0, _classCallCheck2.default)(this, UIAnalyticsEvent);
32
- _this = _super.call(this, props);
33
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_isUIAnalyticsEvent", true);
34
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "clone", function () {
30
+ _this = _callSuper(this, UIAnalyticsEvent, [props]);
31
+ (0, _defineProperty2.default)(_this, "_isUIAnalyticsEvent", true);
32
+ (0, _defineProperty2.default)(_this, "clone", function () {
35
33
  if (_this.hasFired) {
36
34
  if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
37
35
  // eslint-disable-next-line no-console
@@ -54,7 +52,7 @@ var UIAnalyticsEvent = exports.default = /*#__PURE__*/function (_AnalyticsEvent)
54
52
  payload: payload
55
53
  });
56
54
  });
57
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "fire", function (channel) {
55
+ (0, _defineProperty2.default)(_this, "fire", function (channel) {
58
56
  if (_this.hasFired) {
59
57
  if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
60
58
  // eslint-disable-next-line no-console
@@ -63,7 +61,7 @@ var UIAnalyticsEvent = exports.default = /*#__PURE__*/function (_AnalyticsEvent)
63
61
  return;
64
62
  }
65
63
  _this.handlers.forEach(function (handler) {
66
- return handler((0, _assertThisInitialized2.default)(_this), channel);
64
+ return handler(_this, channel);
67
65
  });
68
66
  _this.hasFired = true;
69
67
  });
@@ -72,7 +70,8 @@ var UIAnalyticsEvent = exports.default = /*#__PURE__*/function (_AnalyticsEvent)
72
70
  _this.hasFired = false;
73
71
  return _this;
74
72
  }
75
- (0, _createClass2.default)(UIAnalyticsEvent, [{
73
+ (0, _inherits2.default)(UIAnalyticsEvent, _AnalyticsEvent);
74
+ return (0, _createClass2.default)(UIAnalyticsEvent, [{
76
75
  key: "update",
77
76
  value: function update(updater) {
78
77
  if (this.hasFired) {
@@ -82,8 +81,7 @@ var UIAnalyticsEvent = exports.default = /*#__PURE__*/function (_AnalyticsEvent)
82
81
  }
83
82
  return this;
84
83
  }
85
- return (0, _get2.default)((0, _getPrototypeOf2.default)(UIAnalyticsEvent.prototype), "update", this).call(this, updater);
84
+ return _superPropGet(UIAnalyticsEvent, "update", this, 3)([updater]);
86
85
  }
87
86
  }]);
88
- return UIAnalyticsEvent;
89
87
  }(_AnalyticsEvent2.default);
package/dist/cjs/index.js CHANGED
@@ -11,6 +11,18 @@ Object.defineProperty(exports, "AnalyticsContext", {
11
11
  return _index2.default;
12
12
  }
13
13
  });
14
+ Object.defineProperty(exports, "AnalyticsDecorator", {
15
+ enumerable: true,
16
+ get: function get() {
17
+ return _AnalyticsDecorator.default;
18
+ }
19
+ });
20
+ Object.defineProperty(exports, "AnalyticsDelegate", {
21
+ enumerable: true,
22
+ get: function get() {
23
+ return _AnalyticsDelegate.default;
24
+ }
25
+ });
14
26
  Object.defineProperty(exports, "AnalyticsErrorBoundary", {
15
27
  enumerable: true,
16
28
  get: function get() {
@@ -89,6 +101,12 @@ Object.defineProperty(exports, "usePlatformLeafSyntheticEventHandler", {
89
101
  return _usePlatformLeafSyntheticEventHandler.usePlatformLeafSyntheticEventHandler;
90
102
  }
91
103
  });
104
+ Object.defineProperty(exports, "withAnalytics", {
105
+ enumerable: true,
106
+ get: function get() {
107
+ return _withAnalytics.default;
108
+ }
109
+ });
92
110
  Object.defineProperty(exports, "withAnalyticsContext", {
93
111
  enumerable: true,
94
112
  get: function get() {
@@ -115,5 +133,8 @@ var _usePlatformLeafEventHandler = require("./hooks/usePlatformLeafEventHandler"
115
133
  var _usePlatformLeafSyntheticEventHandler = require("./hooks/usePlatformLeafSyntheticEventHandler");
116
134
  var _createAndFireEvent = _interopRequireDefault(require("./utils/createAndFireEvent"));
117
135
  var _cleanProps = _interopRequireDefault(require("./utils/cleanProps"));
136
+ var _AnalyticsDecorator = _interopRequireDefault(require("./components/AnalyticsDecorator"));
137
+ var _AnalyticsDelegate = _interopRequireDefault(require("./components/AnalyticsDelegate"));
138
+ var _withAnalytics = _interopRequireDefault(require("./utils/withAnalytics"));
118
139
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
119
140
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -5,4 +5,5 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _process$env;
8
+ /// <reference types="node" />
8
9
  var _default = exports.default = typeof process !== 'undefined' && process !== null && ((_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env['ANALYTICS_NEXT_MODERN_CONTEXT']);
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
14
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
15
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
16
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
+ var _react = _interopRequireWildcard(require("react"));
18
+ var _propTypes = _interopRequireDefault(require("prop-types"));
19
+ var _excluded = ["analyticsId", "analyticsData"];
20
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
21
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
22
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
23
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
24
+ function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
25
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
26
+ /**
27
+ * The withAnalytics HOC wraps a component and provides the `fireAnalyticsEvent`
28
+ * and `firePrivateAnalyticsEvent` methods to it as props. It contains the logic
29
+ * for how to fire events, including handling the analyticsId and analyticsData
30
+ * props. The `map` argument may be an object or a function that returns an object.
31
+ * The properties of the `map` object/result can be strings (the name of the event
32
+ * that will be fired) or functions (which are responsible for firing the event).
33
+ * You can specify a default `analyticsId` and `analyticsData` with the `defaultProps`
34
+ * param. Please be aware that specifying a default `analyticsId` will cause public
35
+ * events to always fire for your component unless it has been set to a falsy by
36
+ * the component consumer.
37
+ *
38
+ * @param WrappedComponent
39
+ * @param map
40
+ * @param defaultProps
41
+ * @param withDelegation
42
+ */
43
+ var withAnalytics = function withAnalytics(WrappedComponent) {
44
+ var _WithAnalytics;
45
+ var map = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
46
+ var defaultProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
47
+ var withDelegation = arguments.length > 3 ? arguments[3] : undefined;
48
+ return _WithAnalytics = /*#__PURE__*/function (_Component) {
49
+ function WithAnalytics(props) {
50
+ var _this;
51
+ (0, _classCallCheck2.default)(this, WithAnalytics);
52
+ _this = _callSuper(this, WithAnalytics, [props]);
53
+ (0, _defineProperty2.default)(_this, "delegateAnalyticsEvent", function (analyticsId, data, isPrivate) {
54
+ var _ref = _this.context,
55
+ onAnalyticsEvent = _ref.onAnalyticsEvent;
56
+ if (!onAnalyticsEvent) {
57
+ return;
58
+ }
59
+ onAnalyticsEvent(analyticsId, data, isPrivate);
60
+ });
61
+ (0, _defineProperty2.default)(_this, "fireAnalyticsEvent", function (name, data) {
62
+ var _this$props = _this.props,
63
+ analyticsData = _this$props.analyticsData,
64
+ analyticsId = _this$props.analyticsId;
65
+ var _ref2 = _this.context,
66
+ onAnalyticsEvent = _ref2.onAnalyticsEvent;
67
+ if (!analyticsId || !onAnalyticsEvent) {
68
+ return;
69
+ }
70
+ var eventData = _objectSpread(_objectSpread({}, analyticsData), data);
71
+ onAnalyticsEvent("".concat(analyticsId, ".").concat(name), eventData, false);
72
+ });
73
+ (0, _defineProperty2.default)(_this, "privateAnalyticsEvent", function (name, data) {
74
+ var _ref3 = _this.context,
75
+ onAnalyticsEvent = _ref3.onAnalyticsEvent;
76
+ if (!onAnalyticsEvent) {
77
+ return;
78
+ }
79
+ onAnalyticsEvent("".concat(name), data, true);
80
+ });
81
+ (0, _defineProperty2.default)(_this, "getParentAnalyticsData", function (name) {
82
+ var _ref4 = _this.context,
83
+ getParentAnalyticsData = _ref4.getParentAnalyticsData;
84
+ var parentData = {};
85
+ if (typeof getParentAnalyticsData === 'function' && _this.props.analyticsId) {
86
+ var analyticsId = _this.props.analyticsId;
87
+ parentData = getParentAnalyticsData("".concat(analyticsId, ".").concat(name), false);
88
+ }
89
+ return parentData;
90
+ });
91
+ _this.state = {
92
+ evaluatedMap: {}
93
+ };
94
+ return _this;
95
+ }
96
+ (0, _inherits2.default)(WithAnalytics, _Component);
97
+ return (0, _createClass2.default)(WithAnalytics, [{
98
+ key: "componentDidMount",
99
+ value: function componentDidMount() {
100
+ this.setState({
101
+ evaluatedMap: typeof map === 'function' ? map(this.fireAnalyticsEvent) : map
102
+ });
103
+ }
104
+ }, {
105
+ key: "render",
106
+ value: function render() {
107
+ var _this2 = this;
108
+ var _this$props2 = this.props,
109
+ analyticsId = _this$props2.analyticsId,
110
+ analyticsData = _this$props2.analyticsData,
111
+ componentProps = (0, _objectWithoutProperties2.default)(_this$props2, _excluded);
112
+ Object.keys(this.state.evaluatedMap).forEach(function (prop) {
113
+ var handler = _this2.state.evaluatedMap[prop];
114
+ var originalProp = componentProps[prop];
115
+ componentProps[prop] = function () {
116
+ if (typeof handler === 'function') {
117
+ handler.apply(void 0, arguments);
118
+ } else {
119
+ _this2.fireAnalyticsEvent(handler);
120
+ }
121
+ if (typeof originalProp === 'function') {
122
+ originalProp.apply(void 0, arguments);
123
+ }
124
+ };
125
+ });
126
+ return /*#__PURE__*/_react.default.createElement(WrappedComponent, (0, _extends2.default)({
127
+ fireAnalyticsEvent: this.fireAnalyticsEvent,
128
+ firePrivateAnalyticsEvent: this.privateAnalyticsEvent,
129
+ getParentAnalyticsData: this.getParentAnalyticsData,
130
+ delegateAnalyticsEvent: withDelegation ? this.delegateAnalyticsEvent : undefined,
131
+ analyticsId: analyticsId,
132
+ ref: this.props.innerRef
133
+ }, componentProps));
134
+ }
135
+ }]);
136
+ }(_react.Component), (0, _defineProperty2.default)(_WithAnalytics, "displayName", "WithAnalytics(".concat(WrappedComponent.displayName || WrappedComponent.name, ")")), (0, _defineProperty2.default)(_WithAnalytics, "contextTypes", {
137
+ onAnalyticsEvent: _propTypes.default.func,
138
+ getParentAnalyticsData: _propTypes.default.func
139
+ }), (0, _defineProperty2.default)(_WithAnalytics, "defaultProps", {
140
+ analyticsId: defaultProps.analyticsId,
141
+ analyticsData: defaultProps.analyticsData
142
+ }), _WithAnalytics;
143
+ };
144
+ var _default = exports.default = withAnalytics;
@@ -4,7 +4,7 @@ import isModernContextEnabledEnv from '../../utils/isModernContextEnabledEnv';
4
4
  import LegacyAnalyticsContext from './LegacyAnalyticsContext';
5
5
  import ModernAnalyticsContext from './ModernAnalyticsContext';
6
6
  const ExportedAnalyticsContext = props => {
7
- const isModernContext = isModernContextEnabledEnv || fg('platform.analytics-next-use-modern-context_fqgbx');
7
+ const isModernContext = isModernContextEnabledEnv || fg('analytics-next-use-modern-context_jira');
8
8
  return isModernContext ? /*#__PURE__*/React.createElement(ModernAnalyticsContext, props) : /*#__PURE__*/React.createElement(LegacyAnalyticsContext, props);
9
9
  };
10
10
  export default ExportedAnalyticsContext;
@@ -0,0 +1,79 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import React, { Component } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import index from '../matchEvent';
5
+ export const ContextTypes = {
6
+ onAnalyticsEvent: PropTypes.func,
7
+ getParentAnalyticsData: PropTypes.func
8
+ };
9
+
10
+ /**
11
+ * The Decorator component extends analytics event data
12
+ * for any events fired by its descendents,
13
+ * then passes the event up the hierarchy
14
+ */
15
+ // eslint-disable-next-line @repo/internal/react/no-class-components
16
+ export class AnalyticsDecorator extends Component {
17
+ constructor(...args) {
18
+ super(...args);
19
+ _defineProperty(this, "getDecoratedAnalyticsData", (name, srcData, isPrivate) => {
20
+ const {
21
+ data,
22
+ getData,
23
+ match,
24
+ matchPrivate
25
+ } = this.props;
26
+ const decoratedData = {
27
+ ...srcData
28
+ };
29
+ if (matchPrivate === isPrivate && index(match, name)) {
30
+ if (typeof data === 'object') {
31
+ Object.assign(decoratedData, data);
32
+ }
33
+ if (typeof getData === 'function') {
34
+ Object.assign(decoratedData, getData(name, decoratedData));
35
+ }
36
+ }
37
+ return decoratedData;
38
+ });
39
+ _defineProperty(this, "onAnalyticsEvent", (name, srcData, isPrivate) => {
40
+ const {
41
+ onAnalyticsEvent
42
+ } = this.context;
43
+ if (typeof onAnalyticsEvent !== 'function') {
44
+ return;
45
+ }
46
+ const decoratedData = this.getDecoratedAnalyticsData(name, srcData, isPrivate);
47
+ onAnalyticsEvent(name, decoratedData, isPrivate);
48
+ });
49
+ _defineProperty(this, "getParentAnalyticsData", (name, isPrivate) => {
50
+ const parentData = this.getDecoratedAnalyticsData(name, {}, isPrivate);
51
+ const {
52
+ getParentAnalyticsData
53
+ } = this.context;
54
+ if (typeof getParentAnalyticsData === 'function') {
55
+ Object.assign(parentData, getParentAnalyticsData(name, isPrivate));
56
+ }
57
+ return parentData;
58
+ });
59
+ }
60
+ getChildContext() {
61
+ return {
62
+ onAnalyticsEvent: this.onAnalyticsEvent,
63
+ getParentAnalyticsData: this.getParentAnalyticsData
64
+ };
65
+ }
66
+ render() {
67
+ const {
68
+ children
69
+ } = this.props;
70
+ return React.Children.only(children);
71
+ }
72
+ }
73
+ _defineProperty(AnalyticsDecorator, "defaultProps", {
74
+ match: '*',
75
+ matchPrivate: false
76
+ });
77
+ _defineProperty(AnalyticsDecorator, "contextTypes", ContextTypes);
78
+ _defineProperty(AnalyticsDecorator, "childContextTypes", ContextTypes);
79
+ export default AnalyticsDecorator;
@@ -0,0 +1,48 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import React, { Component } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ const ContextTypes = {
5
+ onAnalyticsEvent: PropTypes.func
6
+ };
7
+
8
+ /**
9
+ * Listens to public and private events and delegates to an analytics
10
+ * stack in a different React root.
11
+ */
12
+ // eslint-disable-next-line @repo/internal/react/no-class-components
13
+ class AnalyticsDelegate extends Component {
14
+ constructor(...args) {
15
+ super(...args);
16
+ _defineProperty(this, "onAnalyticsEvent", (name, data, isPrivate) => {
17
+ const {
18
+ delegateAnalyticsEvent
19
+ } = this.props;
20
+ const eventData = {
21
+ ...data
22
+ };
23
+ if (delegateAnalyticsEvent) {
24
+ delegateAnalyticsEvent(name, eventData, isPrivate);
25
+ }
26
+ const {
27
+ onAnalyticsEvent
28
+ } = this.context;
29
+ if (typeof onAnalyticsEvent === 'function') {
30
+ onAnalyticsEvent(name, data, isPrivate);
31
+ }
32
+ });
33
+ }
34
+ getChildContext() {
35
+ return {
36
+ onAnalyticsEvent: this.onAnalyticsEvent
37
+ };
38
+ }
39
+ render() {
40
+ const {
41
+ children
42
+ } = this.props;
43
+ return React.Children.only(children);
44
+ }
45
+ }
46
+ _defineProperty(AnalyticsDelegate, "contextTypes", ContextTypes);
47
+ _defineProperty(AnalyticsDelegate, "childContextTypes", ContextTypes);
48
+ export default AnalyticsDelegate;
@@ -33,7 +33,7 @@ export default class AnalyticsErrorBoundary extends Component {
33
33
  const {
34
34
  hasError
35
35
  } = this.state;
36
- const isModernContext = isModernContextEnabledEnv || fg('platform.analytics-next-use-modern-context_fqgbx');
36
+ const isModernContext = isModernContextEnabledEnv || fg('analytics-next-use-modern-context_jira');
37
37
  if (hasError) {
38
38
  if (ErrorComponent) {
39
39
  if (isModernContext) {
@@ -4,7 +4,7 @@ import isModernContextEnabledEnv from '../../utils/isModernContextEnabledEnv';
4
4
  import LegacyAnalyticsListener from './LegacyAnalyticsListener';
5
5
  import ModernAnalyticsListener from './ModernAnalyticsListener';
6
6
  const ExportedAnalyticsListener = props => {
7
- const isModernContext = isModernContextEnabledEnv || fg('platform.analytics-next-use-modern-context_fqgbx');
7
+ const isModernContext = isModernContextEnabledEnv || fg('analytics-next-use-modern-context_jira');
8
8
  return isModernContext ? /*#__PURE__*/React.createElement(ModernAnalyticsListener, props) : /*#__PURE__*/React.createElement(LegacyAnalyticsListener, props);
9
9
  };
10
10
  export default ExportedAnalyticsListener;
@@ -0,0 +1,17 @@
1
+ const ENDS_WITH_DOT = /\.$/;
2
+ function matchEvent(matcher, name) {
3
+ if (matcher === '*' || name === undefined) {
4
+ return true;
5
+ }
6
+ if (typeof matcher === 'string') {
7
+ if (ENDS_WITH_DOT.test(matcher)) {
8
+ return name.substr(0, matcher.length) === matcher;
9
+ }
10
+ return name === matcher;
11
+ }
12
+ if (typeof matcher === 'function') {
13
+ return matcher(name);
14
+ }
15
+ return matcher.test(name);
16
+ }
17
+ export default matchEvent;
@@ -1,4 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ /// <reference types="node" />
2
3
  import AnalyticsEvent from './AnalyticsEvent';
3
4
  export const isUIAnalyticsEvent = obj => {
4
5
  var _obj$constructor;
@@ -20,4 +20,9 @@ export { usePlatformLeafEventHandler } from './hooks/usePlatformLeafEventHandler
20
20
  export { usePlatformLeafSyntheticEventHandler } from './hooks/usePlatformLeafSyntheticEventHandler';
21
21
  // Helper functions
22
22
  export { default as createAndFireEvent } from './utils/createAndFireEvent';
23
- export { default as cleanProps } from './utils/cleanProps';
23
+ export { default as cleanProps } from './utils/cleanProps';
24
+
25
+ // Moved from deprecated @atlaskit/analytics
26
+ export { default as AnalyticsDecorator } from './components/AnalyticsDecorator';
27
+ export { default as AnalyticsDelegate } from './components/AnalyticsDelegate';
28
+ export { default as withAnalytics } from './utils/withAnalytics';
@@ -1,2 +1,3 @@
1
1
  var _process$env;
2
+ /// <reference types="node" />
2
3
  export default typeof process !== 'undefined' && process !== null && ((_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env['ANALYTICS_NEXT_MODERN_CONTEXT']);
@@ -0,0 +1,121 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import React, { Component } from 'react';
4
+ import PropTypes from 'prop-types';
5
+ /**
6
+ * The withAnalytics HOC wraps a component and provides the `fireAnalyticsEvent`
7
+ * and `firePrivateAnalyticsEvent` methods to it as props. It contains the logic
8
+ * for how to fire events, including handling the analyticsId and analyticsData
9
+ * props. The `map` argument may be an object or a function that returns an object.
10
+ * The properties of the `map` object/result can be strings (the name of the event
11
+ * that will be fired) or functions (which are responsible for firing the event).
12
+ * You can specify a default `analyticsId` and `analyticsData` with the `defaultProps`
13
+ * param. Please be aware that specifying a default `analyticsId` will cause public
14
+ * events to always fire for your component unless it has been set to a falsy by
15
+ * the component consumer.
16
+ *
17
+ * @param WrappedComponent
18
+ * @param map
19
+ * @param defaultProps
20
+ * @param withDelegation
21
+ */
22
+ const withAnalytics = (WrappedComponent, map = {}, defaultProps = {}, withDelegation) => {
23
+ var _WithAnalytics;
24
+ return _WithAnalytics = class WithAnalytics extends Component {
25
+ constructor(props) {
26
+ super(props);
27
+ _defineProperty(this, "delegateAnalyticsEvent", (analyticsId, data, isPrivate) => {
28
+ const {
29
+ onAnalyticsEvent
30
+ } = this.context;
31
+ if (!onAnalyticsEvent) {
32
+ return;
33
+ }
34
+ onAnalyticsEvent(analyticsId, data, isPrivate);
35
+ });
36
+ _defineProperty(this, "fireAnalyticsEvent", (name, data) => {
37
+ const {
38
+ analyticsData,
39
+ analyticsId
40
+ } = this.props;
41
+ const {
42
+ onAnalyticsEvent
43
+ } = this.context;
44
+ if (!analyticsId || !onAnalyticsEvent) {
45
+ return;
46
+ }
47
+ const eventData = {
48
+ ...analyticsData,
49
+ ...data
50
+ };
51
+ onAnalyticsEvent(`${analyticsId}.${name}`, eventData, false);
52
+ });
53
+ _defineProperty(this, "privateAnalyticsEvent", (name, data) => {
54
+ const {
55
+ onAnalyticsEvent
56
+ } = this.context;
57
+ if (!onAnalyticsEvent) {
58
+ return;
59
+ }
60
+ onAnalyticsEvent(`${name}`, data, true);
61
+ });
62
+ _defineProperty(this, "getParentAnalyticsData", name => {
63
+ const {
64
+ getParentAnalyticsData
65
+ } = this.context;
66
+ let parentData = {};
67
+ if (typeof getParentAnalyticsData === 'function' && this.props.analyticsId) {
68
+ const {
69
+ analyticsId
70
+ } = this.props;
71
+ parentData = getParentAnalyticsData(`${analyticsId}.${name}`, false);
72
+ }
73
+ return parentData;
74
+ });
75
+ this.state = {
76
+ evaluatedMap: {}
77
+ };
78
+ }
79
+ componentDidMount() {
80
+ this.setState({
81
+ evaluatedMap: typeof map === 'function' ? map(this.fireAnalyticsEvent) : map
82
+ });
83
+ }
84
+ render() {
85
+ const {
86
+ analyticsId,
87
+ analyticsData,
88
+ ...componentProps
89
+ } = this.props;
90
+ Object.keys(this.state.evaluatedMap).forEach(prop => {
91
+ const handler = this.state.evaluatedMap[prop];
92
+ const originalProp = componentProps[prop];
93
+ componentProps[prop] = (...args) => {
94
+ if (typeof handler === 'function') {
95
+ handler(...args);
96
+ } else {
97
+ this.fireAnalyticsEvent(handler);
98
+ }
99
+ if (typeof originalProp === 'function') {
100
+ originalProp(...args);
101
+ }
102
+ };
103
+ });
104
+ return /*#__PURE__*/React.createElement(WrappedComponent, _extends({
105
+ fireAnalyticsEvent: this.fireAnalyticsEvent,
106
+ firePrivateAnalyticsEvent: this.privateAnalyticsEvent,
107
+ getParentAnalyticsData: this.getParentAnalyticsData,
108
+ delegateAnalyticsEvent: withDelegation ? this.delegateAnalyticsEvent : undefined,
109
+ analyticsId: analyticsId,
110
+ ref: this.props.innerRef
111
+ }, componentProps));
112
+ }
113
+ }, _defineProperty(_WithAnalytics, "displayName", `WithAnalytics(${WrappedComponent.displayName || WrappedComponent.name})`), _defineProperty(_WithAnalytics, "contextTypes", {
114
+ onAnalyticsEvent: PropTypes.func,
115
+ getParentAnalyticsData: PropTypes.func
116
+ }), _defineProperty(_WithAnalytics, "defaultProps", {
117
+ analyticsId: defaultProps.analyticsId,
118
+ analyticsData: defaultProps.analyticsData
119
+ }), _WithAnalytics;
120
+ };
121
+ export default withAnalytics;
@@ -1,12 +1,11 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
+ import _inherits from "@babel/runtime/helpers/inherits";
8
7
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
- function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
8
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
10
9
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
10
  import React, { Component } from 'react';
12
11
  import PropTypes from 'prop-types';
@@ -21,24 +20,22 @@ var noop = function noop() {
21
20
 
22
21
  // eslint-disable-next-line @repo/internal/react/no-class-components
23
22
  var AnalyticsContext = /*#__PURE__*/function (_Component) {
24
- _inherits(AnalyticsContext, _Component);
25
- var _super = _createSuper(AnalyticsContext);
26
23
  function AnalyticsContext(props) {
27
24
  var _this;
28
25
  _classCallCheck(this, AnalyticsContext);
29
- _this = _super.call(this, props);
30
- _defineProperty(_assertThisInitialized(_this), "getChildContext", function () {
26
+ _this = _callSuper(this, AnalyticsContext, [props]);
27
+ _defineProperty(_this, "getChildContext", function () {
31
28
  return {
32
29
  getAtlaskitAnalyticsContext: _this.getAnalyticsContext
33
30
  };
34
31
  });
35
- _defineProperty(_assertThisInitialized(_this), "getAnalyticsContext", function () {
32
+ _defineProperty(_this, "getAnalyticsContext", function () {
36
33
  var data = _this.props.data;
37
34
  var _this$context$getAtla = _this.context.getAtlaskitAnalyticsContext,
38
35
  getAtlaskitAnalyticsContext = _this$context$getAtla === void 0 ? noop : _this$context$getAtla;
39
36
  return [].concat(_toConsumableArray(getAtlaskitAnalyticsContext()), [data]);
40
37
  });
41
- _defineProperty(_assertThisInitialized(_this), "getAnalyticsEventHandlers", function () {
38
+ _defineProperty(_this, "getAnalyticsEventHandlers", function () {
42
39
  var _this$context$getAtla2 = _this.context.getAtlaskitAnalyticsEventHandlers,
43
40
  getAtlaskitAnalyticsEventHandlers = _this$context$getAtla2 === void 0 ? noop : _this$context$getAtla2;
44
41
  return getAtlaskitAnalyticsEventHandlers();
@@ -49,7 +46,8 @@ var AnalyticsContext = /*#__PURE__*/function (_Component) {
49
46
  };
50
47
  return _this;
51
48
  }
52
- _createClass(AnalyticsContext, [{
49
+ _inherits(AnalyticsContext, _Component);
50
+ return _createClass(AnalyticsContext, [{
53
51
  key: "render",
54
52
  value: function render() {
55
53
  var children = this.props.children;
@@ -58,7 +56,6 @@ var AnalyticsContext = /*#__PURE__*/function (_Component) {
58
56
  }, children);
59
57
  }
60
58
  }]);
61
- return AnalyticsContext;
62
59
  }(Component);
63
60
  _defineProperty(AnalyticsContext, "contextTypes", ContextTypes);
64
61
  _defineProperty(AnalyticsContext, "childContextTypes", ContextTypes);