@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
@@ -4,7 +4,7 @@ import isModernContextEnabledEnv from '../../utils/isModernContextEnabledEnv';
4
4
  import LegacyAnalyticsContext from './LegacyAnalyticsContext';
5
5
  import ModernAnalyticsContext from './ModernAnalyticsContext';
6
6
  var ExportedAnalyticsContext = function ExportedAnalyticsContext(props) {
7
- var isModernContext = isModernContextEnabledEnv || fg('platform.analytics-next-use-modern-context_fqgbx');
7
+ var 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,94 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
2
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/createClass";
4
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
+ import _inherits from "@babel/runtime/helpers/inherits";
7
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
+ 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; }
9
+ 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) { _defineProperty(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; }
10
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
11
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
12
+ import React, { Component } from 'react';
13
+ import PropTypes from 'prop-types';
14
+ import index from '../matchEvent';
15
+ export var ContextTypes = {
16
+ onAnalyticsEvent: PropTypes.func,
17
+ getParentAnalyticsData: PropTypes.func
18
+ };
19
+
20
+ /**
21
+ * The Decorator component extends analytics event data
22
+ * for any events fired by its descendents,
23
+ * then passes the event up the hierarchy
24
+ */
25
+ // eslint-disable-next-line @repo/internal/react/no-class-components
26
+ export var AnalyticsDecorator = /*#__PURE__*/function (_Component) {
27
+ function AnalyticsDecorator() {
28
+ var _this;
29
+ _classCallCheck(this, AnalyticsDecorator);
30
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
31
+ args[_key] = arguments[_key];
32
+ }
33
+ _this = _callSuper(this, AnalyticsDecorator, [].concat(args));
34
+ _defineProperty(_this, "getDecoratedAnalyticsData", function (name, srcData, isPrivate) {
35
+ var _this$props = _this.props,
36
+ data = _this$props.data,
37
+ getData = _this$props.getData,
38
+ match = _this$props.match,
39
+ matchPrivate = _this$props.matchPrivate;
40
+ var decoratedData = _objectSpread({}, srcData);
41
+ if (matchPrivate === isPrivate && index(match, name)) {
42
+ if (_typeof(data) === 'object') {
43
+ Object.assign(decoratedData, data);
44
+ }
45
+ if (typeof getData === 'function') {
46
+ Object.assign(decoratedData, getData(name, decoratedData));
47
+ }
48
+ }
49
+ return decoratedData;
50
+ });
51
+ _defineProperty(_this, "onAnalyticsEvent", function (name, srcData, isPrivate) {
52
+ var _ref = _this.context,
53
+ onAnalyticsEvent = _ref.onAnalyticsEvent;
54
+ if (typeof onAnalyticsEvent !== 'function') {
55
+ return;
56
+ }
57
+ var decoratedData = _this.getDecoratedAnalyticsData(name, srcData, isPrivate);
58
+ onAnalyticsEvent(name, decoratedData, isPrivate);
59
+ });
60
+ _defineProperty(_this, "getParentAnalyticsData", function (name, isPrivate) {
61
+ var parentData = _this.getDecoratedAnalyticsData(name, {}, isPrivate);
62
+ var _ref2 = _this.context,
63
+ getParentAnalyticsData = _ref2.getParentAnalyticsData;
64
+ if (typeof getParentAnalyticsData === 'function') {
65
+ Object.assign(parentData, getParentAnalyticsData(name, isPrivate));
66
+ }
67
+ return parentData;
68
+ });
69
+ return _this;
70
+ }
71
+ _inherits(AnalyticsDecorator, _Component);
72
+ return _createClass(AnalyticsDecorator, [{
73
+ key: "getChildContext",
74
+ value: function getChildContext() {
75
+ return {
76
+ onAnalyticsEvent: this.onAnalyticsEvent,
77
+ getParentAnalyticsData: this.getParentAnalyticsData
78
+ };
79
+ }
80
+ }, {
81
+ key: "render",
82
+ value: function render() {
83
+ var children = this.props.children;
84
+ return React.Children.only(children);
85
+ }
86
+ }]);
87
+ }(Component);
88
+ _defineProperty(AnalyticsDecorator, "defaultProps", {
89
+ match: '*',
90
+ matchPrivate: false
91
+ });
92
+ _defineProperty(AnalyticsDecorator, "contextTypes", ContextTypes);
93
+ _defineProperty(AnalyticsDecorator, "childContextTypes", ContextTypes);
94
+ export default AnalyticsDecorator;
@@ -0,0 +1,62 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
+ import _inherits from "@babel/runtime/helpers/inherits";
6
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
+ 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; }
8
+ 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) { _defineProperty(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; }
9
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
10
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
+ import React, { Component } from 'react';
12
+ import PropTypes from 'prop-types';
13
+ var ContextTypes = {
14
+ onAnalyticsEvent: PropTypes.func
15
+ };
16
+
17
+ /**
18
+ * Listens to public and private events and delegates to an analytics
19
+ * stack in a different React root.
20
+ */
21
+ // eslint-disable-next-line @repo/internal/react/no-class-components
22
+ var AnalyticsDelegate = /*#__PURE__*/function (_Component) {
23
+ function AnalyticsDelegate() {
24
+ var _this;
25
+ _classCallCheck(this, AnalyticsDelegate);
26
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
27
+ args[_key] = arguments[_key];
28
+ }
29
+ _this = _callSuper(this, AnalyticsDelegate, [].concat(args));
30
+ _defineProperty(_this, "onAnalyticsEvent", function (name, data, isPrivate) {
31
+ var delegateAnalyticsEvent = _this.props.delegateAnalyticsEvent;
32
+ var eventData = _objectSpread({}, data);
33
+ if (delegateAnalyticsEvent) {
34
+ delegateAnalyticsEvent(name, eventData, isPrivate);
35
+ }
36
+ var _ref = _this.context,
37
+ onAnalyticsEvent = _ref.onAnalyticsEvent;
38
+ if (typeof onAnalyticsEvent === 'function') {
39
+ onAnalyticsEvent(name, data, isPrivate);
40
+ }
41
+ });
42
+ return _this;
43
+ }
44
+ _inherits(AnalyticsDelegate, _Component);
45
+ return _createClass(AnalyticsDelegate, [{
46
+ key: "getChildContext",
47
+ value: function getChildContext() {
48
+ return {
49
+ onAnalyticsEvent: this.onAnalyticsEvent
50
+ };
51
+ }
52
+ }, {
53
+ key: "render",
54
+ value: function render() {
55
+ var children = this.props.children;
56
+ return React.Children.only(children);
57
+ }
58
+ }]);
59
+ }(Component);
60
+ _defineProperty(AnalyticsDelegate, "contextTypes", ContextTypes);
61
+ _defineProperty(AnalyticsDelegate, "childContextTypes", ContextTypes);
62
+ export default AnalyticsDelegate;
@@ -1,9 +1,9 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
3
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
4
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
- 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); }; }
5
+ import _inherits from "@babel/runtime/helpers/inherits";
6
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
7
7
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
8
  import React, { Component } from 'react';
9
9
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -16,18 +16,17 @@ import ModernAnalyticsContext from './AnalyticsContext/ModernAnalyticsContext';
16
16
  */
17
17
  // eslint-disable-next-line @repo/internal/react/no-class-components
18
18
  var AnalyticsErrorBoundary = /*#__PURE__*/function (_Component) {
19
- _inherits(AnalyticsErrorBoundary, _Component);
20
- var _super = _createSuper(AnalyticsErrorBoundary);
21
19
  function AnalyticsErrorBoundary(props) {
22
20
  var _this;
23
21
  _classCallCheck(this, AnalyticsErrorBoundary);
24
- _this = _super.call(this, props);
22
+ _this = _callSuper(this, AnalyticsErrorBoundary, [props]);
25
23
  _this.state = {
26
24
  hasError: false
27
25
  };
28
26
  return _this;
29
27
  }
30
- _createClass(AnalyticsErrorBoundary, [{
28
+ _inherits(AnalyticsErrorBoundary, _Component);
29
+ return _createClass(AnalyticsErrorBoundary, [{
31
30
  key: "componentDidCatch",
32
31
  value: function componentDidCatch(error, info) {
33
32
  var onError = this.props.onError;
@@ -44,7 +43,7 @@ var AnalyticsErrorBoundary = /*#__PURE__*/function (_Component) {
44
43
  children = _this$props.children,
45
44
  ErrorComponent = _this$props.ErrorComponent;
46
45
  var hasError = this.state.hasError;
47
- var isModernContext = isModernContextEnabledEnv || fg('platform.analytics-next-use-modern-context_fqgbx');
46
+ var isModernContext = isModernContextEnabledEnv || fg('analytics-next-use-modern-context_jira');
48
47
  if (hasError) {
49
48
  if (ErrorComponent) {
50
49
  if (isModernContext) {
@@ -68,6 +67,5 @@ var AnalyticsErrorBoundary = /*#__PURE__*/function (_Component) {
68
67
  }, children);
69
68
  }
70
69
  }]);
71
- return AnalyticsErrorBoundary;
72
70
  }(Component);
73
71
  export { AnalyticsErrorBoundary as default };
@@ -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,19 +20,17 @@ var noop = function noop() {
21
20
 
22
21
  // eslint-disable-next-line @repo/internal/react/no-class-components
23
22
  var AnalyticsListener = /*#__PURE__*/function (_Component) {
24
- _inherits(AnalyticsListener, _Component);
25
- var _super = _createSuper(AnalyticsListener);
26
23
  function AnalyticsListener(props) {
27
24
  var _this;
28
25
  _classCallCheck(this, AnalyticsListener);
29
- _this = _super.call(this, props);
30
- _defineProperty(_assertThisInitialized(_this), "getChildContext", function () {
26
+ _this = _callSuper(this, AnalyticsListener, [props]);
27
+ _defineProperty(_this, "getChildContext", function () {
31
28
  return {
32
29
  getAtlaskitAnalyticsEventHandlers: _this.getAnalyticsEventHandlers,
33
30
  getAtlaskitAnalyticsContext: _this.getAtlaskitAnalyticsContext
34
31
  };
35
32
  });
36
- _defineProperty(_assertThisInitialized(_this), "getAnalyticsEventHandlers", function () {
33
+ _defineProperty(_this, "getAnalyticsEventHandlers", function () {
37
34
  var _this$props = _this.props,
38
35
  channel = _this$props.channel,
39
36
  onEvent = _this$props.onEvent;
@@ -46,7 +43,7 @@ var AnalyticsListener = /*#__PURE__*/function (_Component) {
46
43
  };
47
44
  return [handler].concat(_toConsumableArray(getAtlaskitAnalyticsEventHandlers()));
48
45
  });
49
- _defineProperty(_assertThisInitialized(_this), "getAtlaskitAnalyticsContext", function () {
46
+ _defineProperty(_this, "getAtlaskitAnalyticsContext", function () {
50
47
  var _this$context$getAtla2 = _this.context.getAtlaskitAnalyticsContext,
51
48
  getAtlaskitAnalyticsContext = _this$context$getAtla2 === void 0 ? noop : _this$context$getAtla2;
52
49
  return getAtlaskitAnalyticsContext();
@@ -57,7 +54,8 @@ var AnalyticsListener = /*#__PURE__*/function (_Component) {
57
54
  };
58
55
  return _this;
59
56
  }
60
- _createClass(AnalyticsListener, [{
57
+ _inherits(AnalyticsListener, _Component);
58
+ return _createClass(AnalyticsListener, [{
61
59
  key: "render",
62
60
  value: function render() {
63
61
  var children = this.props.children;
@@ -66,7 +64,6 @@ var AnalyticsListener = /*#__PURE__*/function (_Component) {
66
64
  }, children);
67
65
  }
68
66
  }]);
69
- return AnalyticsListener;
70
67
  }(Component);
71
68
  _defineProperty(AnalyticsListener, "contextTypes", ContextTypes);
72
69
  _defineProperty(AnalyticsListener, "childContextTypes", ContextTypes);
@@ -4,7 +4,7 @@ import isModernContextEnabledEnv from '../../utils/isModernContextEnabledEnv';
4
4
  import LegacyAnalyticsListener from './LegacyAnalyticsListener';
5
5
  import ModernAnalyticsListener from './ModernAnalyticsListener';
6
6
  var ExportedAnalyticsListener = function ExportedAnalyticsListener(props) {
7
- var isModernContext = isModernContextEnabledEnv || fg('platform.analytics-next-use-modern-context_fqgbx');
7
+ var 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
+ var 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;
@@ -25,7 +25,7 @@ var AnalyticsEvent = /*#__PURE__*/function () {
25
25
  });
26
26
  this.payload = props.payload;
27
27
  }
28
- _createClass(AnalyticsEvent, [{
28
+ return _createClass(AnalyticsEvent, [{
29
29
  key: "update",
30
30
  value: function update(updater) {
31
31
  if (typeof updater === 'function') {
@@ -37,6 +37,5 @@ var AnalyticsEvent = /*#__PURE__*/function () {
37
37
  return this;
38
38
  }
39
39
  }]);
40
- return AnalyticsEvent;
41
40
  }();
42
41
  export { AnalyticsEvent as default };
@@ -1,14 +1,15 @@
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 _get from "@babel/runtime/helpers/get";
6
- import _inherits from "@babel/runtime/helpers/inherits";
7
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
8
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
+ import _get from "@babel/runtime/helpers/get";
7
+ import _inherits from "@babel/runtime/helpers/inherits";
9
8
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
10
- 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); }; }
9
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
11
10
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
+ function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
12
+ /// <reference types="node" />
12
13
  import AnalyticsEvent from './AnalyticsEvent';
13
14
  export var isUIAnalyticsEvent = function isUIAnalyticsEvent(obj) {
14
15
  var _obj$constructor;
@@ -17,14 +18,12 @@ export var isUIAnalyticsEvent = function isUIAnalyticsEvent(obj) {
17
18
  (obj === null || obj === void 0 || (_obj$constructor = obj.constructor) === null || _obj$constructor === void 0 ? void 0 : _obj$constructor.name) === 'UIAnalyticsEvent';
18
19
  };
19
20
  var UIAnalyticsEvent = /*#__PURE__*/function (_AnalyticsEvent) {
20
- _inherits(UIAnalyticsEvent, _AnalyticsEvent);
21
- var _super = _createSuper(UIAnalyticsEvent);
22
21
  function UIAnalyticsEvent(props) {
23
22
  var _this;
24
23
  _classCallCheck(this, UIAnalyticsEvent);
25
- _this = _super.call(this, props);
26
- _defineProperty(_assertThisInitialized(_this), "_isUIAnalyticsEvent", true);
27
- _defineProperty(_assertThisInitialized(_this), "clone", function () {
24
+ _this = _callSuper(this, UIAnalyticsEvent, [props]);
25
+ _defineProperty(_this, "_isUIAnalyticsEvent", true);
26
+ _defineProperty(_this, "clone", function () {
28
27
  if (_this.hasFired) {
29
28
  if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
30
29
  // eslint-disable-next-line no-console
@@ -47,7 +46,7 @@ var UIAnalyticsEvent = /*#__PURE__*/function (_AnalyticsEvent) {
47
46
  payload: payload
48
47
  });
49
48
  });
50
- _defineProperty(_assertThisInitialized(_this), "fire", function (channel) {
49
+ _defineProperty(_this, "fire", function (channel) {
51
50
  if (_this.hasFired) {
52
51
  if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
53
52
  // eslint-disable-next-line no-console
@@ -56,7 +55,7 @@ var UIAnalyticsEvent = /*#__PURE__*/function (_AnalyticsEvent) {
56
55
  return;
57
56
  }
58
57
  _this.handlers.forEach(function (handler) {
59
- return handler(_assertThisInitialized(_this), channel);
58
+ return handler(_this, channel);
60
59
  });
61
60
  _this.hasFired = true;
62
61
  });
@@ -65,7 +64,8 @@ var UIAnalyticsEvent = /*#__PURE__*/function (_AnalyticsEvent) {
65
64
  _this.hasFired = false;
66
65
  return _this;
67
66
  }
68
- _createClass(UIAnalyticsEvent, [{
67
+ _inherits(UIAnalyticsEvent, _AnalyticsEvent);
68
+ return _createClass(UIAnalyticsEvent, [{
69
69
  key: "update",
70
70
  value: function update(updater) {
71
71
  if (this.hasFired) {
@@ -75,9 +75,8 @@ var UIAnalyticsEvent = /*#__PURE__*/function (_AnalyticsEvent) {
75
75
  }
76
76
  return this;
77
77
  }
78
- return _get(_getPrototypeOf(UIAnalyticsEvent.prototype), "update", this).call(this, updater);
78
+ return _superPropGet(UIAnalyticsEvent, "update", this, 3)([updater]);
79
79
  }
80
80
  }]);
81
- return UIAnalyticsEvent;
82
81
  }(AnalyticsEvent);
83
82
  export { UIAnalyticsEvent as default };
package/dist/esm/index.js CHANGED
@@ -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,134 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/createClass";
5
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
+ import _inherits from "@babel/runtime/helpers/inherits";
8
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
+ var _excluded = ["analyticsId", "analyticsData"];
10
+ 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; }
11
+ 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) { _defineProperty(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; }
12
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
13
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
+ import React, { Component } from 'react';
15
+ import PropTypes from 'prop-types';
16
+ /**
17
+ * The withAnalytics HOC wraps a component and provides the `fireAnalyticsEvent`
18
+ * and `firePrivateAnalyticsEvent` methods to it as props. It contains the logic
19
+ * for how to fire events, including handling the analyticsId and analyticsData
20
+ * props. The `map` argument may be an object or a function that returns an object.
21
+ * The properties of the `map` object/result can be strings (the name of the event
22
+ * that will be fired) or functions (which are responsible for firing the event).
23
+ * You can specify a default `analyticsId` and `analyticsData` with the `defaultProps`
24
+ * param. Please be aware that specifying a default `analyticsId` will cause public
25
+ * events to always fire for your component unless it has been set to a falsy by
26
+ * the component consumer.
27
+ *
28
+ * @param WrappedComponent
29
+ * @param map
30
+ * @param defaultProps
31
+ * @param withDelegation
32
+ */
33
+ var withAnalytics = function withAnalytics(WrappedComponent) {
34
+ var _WithAnalytics;
35
+ var map = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
36
+ var defaultProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
37
+ var withDelegation = arguments.length > 3 ? arguments[3] : undefined;
38
+ return _WithAnalytics = /*#__PURE__*/function (_Component) {
39
+ function WithAnalytics(props) {
40
+ var _this;
41
+ _classCallCheck(this, WithAnalytics);
42
+ _this = _callSuper(this, WithAnalytics, [props]);
43
+ _defineProperty(_this, "delegateAnalyticsEvent", function (analyticsId, data, isPrivate) {
44
+ var _ref = _this.context,
45
+ onAnalyticsEvent = _ref.onAnalyticsEvent;
46
+ if (!onAnalyticsEvent) {
47
+ return;
48
+ }
49
+ onAnalyticsEvent(analyticsId, data, isPrivate);
50
+ });
51
+ _defineProperty(_this, "fireAnalyticsEvent", function (name, data) {
52
+ var _this$props = _this.props,
53
+ analyticsData = _this$props.analyticsData,
54
+ analyticsId = _this$props.analyticsId;
55
+ var _ref2 = _this.context,
56
+ onAnalyticsEvent = _ref2.onAnalyticsEvent;
57
+ if (!analyticsId || !onAnalyticsEvent) {
58
+ return;
59
+ }
60
+ var eventData = _objectSpread(_objectSpread({}, analyticsData), data);
61
+ onAnalyticsEvent("".concat(analyticsId, ".").concat(name), eventData, false);
62
+ });
63
+ _defineProperty(_this, "privateAnalyticsEvent", function (name, data) {
64
+ var _ref3 = _this.context,
65
+ onAnalyticsEvent = _ref3.onAnalyticsEvent;
66
+ if (!onAnalyticsEvent) {
67
+ return;
68
+ }
69
+ onAnalyticsEvent("".concat(name), data, true);
70
+ });
71
+ _defineProperty(_this, "getParentAnalyticsData", function (name) {
72
+ var _ref4 = _this.context,
73
+ getParentAnalyticsData = _ref4.getParentAnalyticsData;
74
+ var parentData = {};
75
+ if (typeof getParentAnalyticsData === 'function' && _this.props.analyticsId) {
76
+ var analyticsId = _this.props.analyticsId;
77
+ parentData = getParentAnalyticsData("".concat(analyticsId, ".").concat(name), false);
78
+ }
79
+ return parentData;
80
+ });
81
+ _this.state = {
82
+ evaluatedMap: {}
83
+ };
84
+ return _this;
85
+ }
86
+ _inherits(WithAnalytics, _Component);
87
+ return _createClass(WithAnalytics, [{
88
+ key: "componentDidMount",
89
+ value: function componentDidMount() {
90
+ this.setState({
91
+ evaluatedMap: typeof map === 'function' ? map(this.fireAnalyticsEvent) : map
92
+ });
93
+ }
94
+ }, {
95
+ key: "render",
96
+ value: function render() {
97
+ var _this2 = this;
98
+ var _this$props2 = this.props,
99
+ analyticsId = _this$props2.analyticsId,
100
+ analyticsData = _this$props2.analyticsData,
101
+ componentProps = _objectWithoutProperties(_this$props2, _excluded);
102
+ Object.keys(this.state.evaluatedMap).forEach(function (prop) {
103
+ var handler = _this2.state.evaluatedMap[prop];
104
+ var originalProp = componentProps[prop];
105
+ componentProps[prop] = function () {
106
+ if (typeof handler === 'function') {
107
+ handler.apply(void 0, arguments);
108
+ } else {
109
+ _this2.fireAnalyticsEvent(handler);
110
+ }
111
+ if (typeof originalProp === 'function') {
112
+ originalProp.apply(void 0, arguments);
113
+ }
114
+ };
115
+ });
116
+ return /*#__PURE__*/React.createElement(WrappedComponent, _extends({
117
+ fireAnalyticsEvent: this.fireAnalyticsEvent,
118
+ firePrivateAnalyticsEvent: this.privateAnalyticsEvent,
119
+ getParentAnalyticsData: this.getParentAnalyticsData,
120
+ delegateAnalyticsEvent: withDelegation ? this.delegateAnalyticsEvent : undefined,
121
+ analyticsId: analyticsId,
122
+ ref: this.props.innerRef
123
+ }, componentProps));
124
+ }
125
+ }]);
126
+ }(Component), _defineProperty(_WithAnalytics, "displayName", "WithAnalytics(".concat(WrappedComponent.displayName || WrappedComponent.name, ")")), _defineProperty(_WithAnalytics, "contextTypes", {
127
+ onAnalyticsEvent: PropTypes.func,
128
+ getParentAnalyticsData: PropTypes.func
129
+ }), _defineProperty(_WithAnalytics, "defaultProps", {
130
+ analyticsId: defaultProps.analyticsId,
131
+ analyticsData: defaultProps.analyticsData
132
+ }), _WithAnalytics;
133
+ };
134
+ export default withAnalytics;
@@ -0,0 +1,46 @@
1
+ import React, { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { type Matcher } from '../matchEvent';
4
+ type AnalyticsData = {
5
+ [key: string]: any;
6
+ };
7
+ type AnalyticsDecoratorProps = {
8
+ match: Matcher;
9
+ matchPrivate: boolean;
10
+ data?: AnalyticsData;
11
+ getData?: (name: string, data: AnalyticsData) => AnalyticsData;
12
+ children: React.ReactNode;
13
+ };
14
+ type AnalyticsDecoratorContext = {
15
+ onAnalyticsEvent?: (name: string, data: AnalyticsData, isPrivate: boolean) => void;
16
+ getParentAnalyticsData?: (name: string, isPrivate: boolean) => AnalyticsData;
17
+ };
18
+ export declare const ContextTypes: {
19
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
20
+ getParentAnalyticsData: PropTypes.Requireable<(...args: any[]) => any>;
21
+ };
22
+ /**
23
+ * The Decorator component extends analytics event data
24
+ * for any events fired by its descendents,
25
+ * then passes the event up the hierarchy
26
+ */
27
+ export declare class AnalyticsDecorator extends Component<AnalyticsDecoratorProps> {
28
+ static defaultProps: {
29
+ match: string;
30
+ matchPrivate: boolean;
31
+ };
32
+ static contextTypes: {
33
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
34
+ getParentAnalyticsData: PropTypes.Requireable<(...args: any[]) => any>;
35
+ };
36
+ static childContextTypes: {
37
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
38
+ getParentAnalyticsData: PropTypes.Requireable<(...args: any[]) => any>;
39
+ };
40
+ getChildContext(): AnalyticsDecoratorContext;
41
+ getDecoratedAnalyticsData: (name: string, srcData: AnalyticsData, isPrivate: boolean) => AnalyticsData;
42
+ onAnalyticsEvent: (name: string, srcData: AnalyticsData, isPrivate: boolean) => void;
43
+ getParentAnalyticsData: (name: string, isPrivate: boolean) => AnalyticsData;
44
+ render(): boolean | {} | React.ReactChild | React.ReactPortal | null | undefined;
45
+ }
46
+ export default AnalyticsDecorator;
@@ -0,0 +1,25 @@
1
+ import React, { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ type AnalyticsDelegateProps = {
4
+ delegateAnalyticsEvent?: (name: string, data: any, isPrivate: boolean) => void;
5
+ children: React.ReactNode;
6
+ };
7
+ type AnalyticsDelegateContext = {
8
+ onAnalyticsEvent?: (name: string, data: any, isPrivate: boolean) => void;
9
+ };
10
+ /**
11
+ * Listens to public and private events and delegates to an analytics
12
+ * stack in a different React root.
13
+ */
14
+ declare class AnalyticsDelegate extends Component<AnalyticsDelegateProps> {
15
+ static contextTypes: {
16
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
17
+ };
18
+ static childContextTypes: {
19
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
20
+ };
21
+ getChildContext(): AnalyticsDelegateContext;
22
+ onAnalyticsEvent: (name: string, data: any, isPrivate: boolean) => void;
23
+ render(): boolean | {} | React.ReactChild | React.ReactPortal | null | undefined;
24
+ }
25
+ export default AnalyticsDelegate;
@@ -0,0 +1,3 @@
1
+ export type Matcher = string | RegExp | ((name: string) => boolean) | '*';
2
+ declare function matchEvent(matcher: Matcher, name: string): boolean;
3
+ export default matchEvent;
@@ -8,5 +8,5 @@ export interface WithAnalyticsEventsProps {
8
8
  createAnalyticsEvent?: CreateUIAnalyticsEvent;
9
9
  ref?: React.Ref<any>;
10
10
  }
11
- declare const withAnalyticsEvents: (createEventMap?: CreateEventMap) => <Props extends WithAnalyticsEventsProps, Component>(WrappedComponent: React.ComponentType<Props> & Component) => React.ForwardRefExoticComponent<React.PropsWithoutRef<JSX.LibraryManagedAttributes<Component, Omit<Props, keyof WithAnalyticsEventsProps>>> & React.RefAttributes<any>>;
11
+ declare const withAnalyticsEvents: (createEventMap?: CreateEventMap) => <Props, Component>(WrappedComponent: React.ComponentType<WithAnalyticsEventsProps & Props> & Component) => React.ForwardRefExoticComponent<React.PropsWithoutRef<JSX.LibraryManagedAttributes<Component, Omit<Props, keyof WithAnalyticsEventsProps>>> & React.RefAttributes<any>>;
12
12
  export default withAnalyticsEvents;