@atlaskit/analytics-next 10.1.0 → 10.2.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 (58) hide show
  1. package/AnalyticsDecorator/package.json +15 -0
  2. package/AnalyticsDelegate/package.json +15 -0
  3. package/CHANGELOG.md +16 -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 +2 -2
  8. package/dist/cjs/components/AnalyticsContext/ModernAnalyticsContext.js +1 -1
  9. package/dist/cjs/components/AnalyticsContext/index.js +1 -1
  10. package/dist/cjs/components/AnalyticsDecorator/index.js +107 -0
  11. package/dist/cjs/components/AnalyticsDelegate/index.js +75 -0
  12. package/dist/cjs/components/AnalyticsErrorBoundary.js +3 -3
  13. package/dist/cjs/components/AnalyticsListener/LegacyAnalyticsListener.js +2 -2
  14. package/dist/cjs/components/AnalyticsListener/ModernAnalyticsListener.js +1 -1
  15. package/dist/cjs/components/AnalyticsListener/index.js +1 -1
  16. package/dist/cjs/components/matchEvent/index.js +23 -0
  17. package/dist/cjs/events/UIAnalyticsEvent.js +2 -2
  18. package/dist/cjs/hocs/withAnalyticsContext.js +1 -1
  19. package/dist/cjs/hocs/withAnalyticsEvents.js +1 -1
  20. package/dist/cjs/index.js +22 -1
  21. package/dist/cjs/utils/isModernContextEnabledEnv.js +1 -0
  22. package/dist/cjs/utils/withAnalytics.js +147 -0
  23. package/dist/es2019/components/AnalyticsContext/index.js +1 -1
  24. package/dist/es2019/components/AnalyticsDecorator/index.js +79 -0
  25. package/dist/es2019/components/AnalyticsDelegate/index.js +48 -0
  26. package/dist/es2019/components/AnalyticsErrorBoundary.js +1 -1
  27. package/dist/es2019/components/AnalyticsListener/index.js +1 -1
  28. package/dist/es2019/components/matchEvent/index.js +17 -0
  29. package/dist/es2019/events/UIAnalyticsEvent.js +1 -0
  30. package/dist/es2019/index.js +6 -1
  31. package/dist/es2019/utils/isModernContextEnabledEnv.js +1 -0
  32. package/dist/es2019/utils/withAnalytics.js +121 -0
  33. package/dist/esm/components/AnalyticsContext/LegacyAnalyticsContext.js +1 -1
  34. package/dist/esm/components/AnalyticsContext/index.js +1 -1
  35. package/dist/esm/components/AnalyticsDecorator/index.js +97 -0
  36. package/dist/esm/components/AnalyticsDelegate/index.js +65 -0
  37. package/dist/esm/components/AnalyticsErrorBoundary.js +2 -2
  38. package/dist/esm/components/AnalyticsListener/LegacyAnalyticsListener.js +1 -1
  39. package/dist/esm/components/AnalyticsListener/index.js +1 -1
  40. package/dist/esm/components/matchEvent/index.js +17 -0
  41. package/dist/esm/events/UIAnalyticsEvent.js +2 -1
  42. package/dist/esm/index.js +6 -1
  43. package/dist/esm/utils/isModernContextEnabledEnv.js +1 -0
  44. package/dist/esm/utils/withAnalytics.js +137 -0
  45. package/dist/types/components/AnalyticsDecorator/index.d.ts +46 -0
  46. package/dist/types/components/AnalyticsDelegate/index.d.ts +25 -0
  47. package/dist/types/components/matchEvent/index.d.ts +3 -0
  48. package/dist/types/hocs/withAnalyticsEvents.d.ts +1 -1
  49. package/dist/types/index.d.ts +3 -0
  50. package/dist/types/utils/withAnalytics.d.ts +80 -0
  51. package/dist/types-ts4.5/components/AnalyticsDecorator/index.d.ts +46 -0
  52. package/dist/types-ts4.5/components/AnalyticsDelegate/index.d.ts +25 -0
  53. package/dist/types-ts4.5/components/matchEvent/index.d.ts +3 -0
  54. package/dist/types-ts4.5/hocs/withAnalyticsEvents.d.ts +1 -1
  55. package/dist/types-ts4.5/index.d.ts +3 -0
  56. package/dist/types-ts4.5/utils/withAnalytics.d.ts +80 -0
  57. package/package.json +8 -11
  58. package/withAnalytics/package.json +15 -0
@@ -3,7 +3,7 @@ import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _inherits from "@babel/runtime/helpers/inherits";
4
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
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); }; }
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';
@@ -44,7 +44,7 @@ var AnalyticsErrorBoundary = /*#__PURE__*/function (_Component) {
44
44
  children = _this$props.children,
45
45
  ErrorComponent = _this$props.ErrorComponent;
46
46
  var hasError = this.state.hasError;
47
- var isModernContext = isModernContextEnabledEnv || fg('platform.analytics-next-use-modern-context_fqgbx');
47
+ var isModernContext = isModernContextEnabledEnv || fg('analytics-next-use-modern-context_jira');
48
48
  if (hasError) {
49
49
  if (ErrorComponent) {
50
50
  if (isModernContext) {
@@ -6,7 +6,7 @@ import _inherits from "@babel/runtime/helpers/inherits";
6
6
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
7
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
8
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
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); }; }
10
10
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
11
  import React, { Component } from 'react';
12
12
  import PropTypes from 'prop-types';
@@ -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;
@@ -7,8 +7,9 @@ import _inherits from "@babel/runtime/helpers/inherits";
7
7
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
8
8
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
9
9
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
10
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
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); }; }
11
11
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
12
+ /// <reference types="node" />
12
13
  import AnalyticsEvent from './AnalyticsEvent';
13
14
  export var isUIAnalyticsEvent = function isUIAnalyticsEvent(obj) {
14
15
  var _obj$constructor;
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,137 @@
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 _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
6
+ import _inherits from "@babel/runtime/helpers/inherits";
7
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
8
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
9
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
10
+ var _excluded = ["analyticsId", "analyticsData"];
11
+ 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; }
12
+ 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; }
13
+ 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); }; }
14
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
15
+ import React, { Component } from 'react';
16
+ import PropTypes from 'prop-types';
17
+ /**
18
+ * The withAnalytics HOC wraps a component and provides the `fireAnalyticsEvent`
19
+ * and `firePrivateAnalyticsEvent` methods to it as props. It contains the logic
20
+ * for how to fire events, including handling the analyticsId and analyticsData
21
+ * props. The `map` argument may be an object or a function that returns an object.
22
+ * The properties of the `map` object/result can be strings (the name of the event
23
+ * that will be fired) or functions (which are responsible for firing the event).
24
+ * You can specify a default `analyticsId` and `analyticsData` with the `defaultProps`
25
+ * param. Please be aware that specifying a default `analyticsId` will cause public
26
+ * events to always fire for your component unless it has been set to a falsy by
27
+ * the component consumer.
28
+ *
29
+ * @param WrappedComponent
30
+ * @param map
31
+ * @param defaultProps
32
+ * @param withDelegation
33
+ */
34
+ var withAnalytics = function withAnalytics(WrappedComponent) {
35
+ var _class;
36
+ var map = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
37
+ var defaultProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
38
+ var withDelegation = arguments.length > 3 ? arguments[3] : undefined;
39
+ return _class = /*#__PURE__*/function (_Component) {
40
+ _inherits(WithAnalytics, _Component);
41
+ var _super = _createSuper(WithAnalytics);
42
+ function WithAnalytics(props) {
43
+ var _this;
44
+ _classCallCheck(this, WithAnalytics);
45
+ _this = _super.call(this, props);
46
+ _defineProperty(_assertThisInitialized(_this), "delegateAnalyticsEvent", function (analyticsId, data, isPrivate) {
47
+ var _ref = _this.context,
48
+ onAnalyticsEvent = _ref.onAnalyticsEvent;
49
+ if (!onAnalyticsEvent) {
50
+ return;
51
+ }
52
+ onAnalyticsEvent(analyticsId, data, isPrivate);
53
+ });
54
+ _defineProperty(_assertThisInitialized(_this), "fireAnalyticsEvent", function (name, data) {
55
+ var _this$props = _this.props,
56
+ analyticsData = _this$props.analyticsData,
57
+ analyticsId = _this$props.analyticsId;
58
+ var _ref2 = _this.context,
59
+ onAnalyticsEvent = _ref2.onAnalyticsEvent;
60
+ if (!analyticsId || !onAnalyticsEvent) {
61
+ return;
62
+ }
63
+ var eventData = _objectSpread(_objectSpread({}, analyticsData), data);
64
+ onAnalyticsEvent("".concat(analyticsId, ".").concat(name), eventData, false);
65
+ });
66
+ _defineProperty(_assertThisInitialized(_this), "privateAnalyticsEvent", function (name, data) {
67
+ var _ref3 = _this.context,
68
+ onAnalyticsEvent = _ref3.onAnalyticsEvent;
69
+ if (!onAnalyticsEvent) {
70
+ return;
71
+ }
72
+ onAnalyticsEvent("".concat(name), data, true);
73
+ });
74
+ _defineProperty(_assertThisInitialized(_this), "getParentAnalyticsData", function (name) {
75
+ var _ref4 = _this.context,
76
+ getParentAnalyticsData = _ref4.getParentAnalyticsData;
77
+ var parentData = {};
78
+ if (typeof getParentAnalyticsData === 'function' && _this.props.analyticsId) {
79
+ var analyticsId = _this.props.analyticsId;
80
+ parentData = getParentAnalyticsData("".concat(analyticsId, ".").concat(name), false);
81
+ }
82
+ return parentData;
83
+ });
84
+ _this.state = {
85
+ evaluatedMap: {}
86
+ };
87
+ return _this;
88
+ }
89
+ _createClass(WithAnalytics, [{
90
+ key: "componentDidMount",
91
+ value: function componentDidMount() {
92
+ this.setState({
93
+ evaluatedMap: typeof map === 'function' ? map(this.fireAnalyticsEvent) : map
94
+ });
95
+ }
96
+ }, {
97
+ key: "render",
98
+ value: function render() {
99
+ var _this2 = this;
100
+ var _this$props2 = this.props,
101
+ analyticsId = _this$props2.analyticsId,
102
+ analyticsData = _this$props2.analyticsData,
103
+ componentProps = _objectWithoutProperties(_this$props2, _excluded);
104
+ Object.keys(this.state.evaluatedMap).forEach(function (prop) {
105
+ var handler = _this2.state.evaluatedMap[prop];
106
+ var originalProp = componentProps[prop];
107
+ componentProps[prop] = function () {
108
+ if (typeof handler === 'function') {
109
+ handler.apply(void 0, arguments);
110
+ } else {
111
+ _this2.fireAnalyticsEvent(handler);
112
+ }
113
+ if (typeof originalProp === 'function') {
114
+ originalProp.apply(void 0, arguments);
115
+ }
116
+ };
117
+ });
118
+ return /*#__PURE__*/React.createElement(WrappedComponent, _extends({
119
+ fireAnalyticsEvent: this.fireAnalyticsEvent,
120
+ firePrivateAnalyticsEvent: this.privateAnalyticsEvent,
121
+ getParentAnalyticsData: this.getParentAnalyticsData,
122
+ delegateAnalyticsEvent: withDelegation ? this.delegateAnalyticsEvent : undefined,
123
+ analyticsId: analyticsId,
124
+ ref: this.props.innerRef
125
+ }, componentProps));
126
+ }
127
+ }]);
128
+ return WithAnalytics;
129
+ }(Component), _defineProperty(_class, "displayName", "WithAnalytics(".concat(WrappedComponent.displayName || WrappedComponent.name, ")")), _defineProperty(_class, "contextTypes", {
130
+ onAnalyticsEvent: PropTypes.func,
131
+ getParentAnalyticsData: PropTypes.func
132
+ }), _defineProperty(_class, "defaultProps", {
133
+ analyticsId: defaultProps.analyticsId,
134
+ analyticsData: defaultProps.analyticsData
135
+ }), _class;
136
+ };
137
+ 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;
@@ -23,3 +23,6 @@ export { usePlatformLeafSyntheticEventHandler } from './hooks/usePlatformLeafSyn
23
23
  export type { UsePlatformLeafSyntheticEventHandlerHookArgs, UsePlatformLeafSyntheticEventHandlerHook, } from './hooks/usePlatformLeafSyntheticEventHandler';
24
24
  export { default as createAndFireEvent } from './utils/createAndFireEvent';
25
25
  export { default as cleanProps } from './utils/cleanProps';
26
+ export { default as AnalyticsDecorator } from './components/AnalyticsDecorator';
27
+ export { default as AnalyticsDelegate } from './components/AnalyticsDelegate';
28
+ export { default as withAnalytics } from './utils/withAnalytics';
@@ -0,0 +1,80 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ type AnalyticsData = {
4
+ [key: string]: any;
5
+ };
6
+ type WithAnalyticsProps = {
7
+ analyticsId?: string;
8
+ analyticsData?: AnalyticsData;
9
+ fireAnalyticsEvent?: (name: string, data?: AnalyticsData) => void;
10
+ firePrivateAnalyticsEvent?: (name: string, data?: AnalyticsData) => void;
11
+ getParentAnalyticsData?: (name: string) => AnalyticsData;
12
+ delegateAnalyticsEvent?: (analyticsId: string, data: any, isPrivate: boolean) => void;
13
+ innerRef?: React.Ref<any>;
14
+ [key: string]: any;
15
+ };
16
+ type WithAnalyticsState = {
17
+ evaluatedMap: {
18
+ [key: string]: string | ((...args: any[]) => void);
19
+ };
20
+ };
21
+ /**
22
+ * The withAnalytics HOC wraps a component and provides the `fireAnalyticsEvent`
23
+ * and `firePrivateAnalyticsEvent` methods to it as props. It contains the logic
24
+ * for how to fire events, including handling the analyticsId and analyticsData
25
+ * props. The `map` argument may be an object or a function that returns an object.
26
+ * The properties of the `map` object/result can be strings (the name of the event
27
+ * that will be fired) or functions (which are responsible for firing the event).
28
+ * You can specify a default `analyticsId` and `analyticsData` with the `defaultProps`
29
+ * param. Please be aware that specifying a default `analyticsId` will cause public
30
+ * events to always fire for your component unless it has been set to a falsy by
31
+ * the component consumer.
32
+ *
33
+ * @param WrappedComponent
34
+ * @param map
35
+ * @param defaultProps
36
+ * @param withDelegation
37
+ */
38
+ declare const withAnalytics: (WrappedComponent: React.ComponentType<any>, map?: {
39
+ [key: string]: string | ((...args: any[]) => void);
40
+ } | ((fireAnalyticsEvent: (name: string, data?: AnalyticsData) => void) => {
41
+ [key: string]: string | ((...args: any[]) => void);
42
+ }), defaultProps?: Partial<WithAnalyticsProps>, withDelegation?: boolean) => {
43
+ new (props: WithAnalyticsProps): {
44
+ componentDidMount(): void;
45
+ delegateAnalyticsEvent: (analyticsId: string, data: any, isPrivate: boolean) => void;
46
+ fireAnalyticsEvent: (name: string, data?: AnalyticsData) => void;
47
+ privateAnalyticsEvent: (name: string, data?: AnalyticsData) => void;
48
+ getParentAnalyticsData: (name: string) => AnalyticsData;
49
+ render(): JSX.Element;
50
+ context: any;
51
+ setState<K extends "evaluatedMap">(state: WithAnalyticsState | ((prevState: Readonly<WithAnalyticsState>, props: Readonly<WithAnalyticsProps>) => WithAnalyticsState | Pick<WithAnalyticsState, K> | null) | Pick<WithAnalyticsState, K> | null, callback?: (() => void) | undefined): void;
52
+ forceUpdate(callback?: (() => void) | undefined): void;
53
+ readonly props: Readonly<WithAnalyticsProps> & Readonly<{
54
+ children?: React.ReactNode;
55
+ }>;
56
+ state: Readonly<WithAnalyticsState>;
57
+ refs: {
58
+ [key: string]: React.ReactInstance;
59
+ };
60
+ shouldComponentUpdate?(nextProps: Readonly<WithAnalyticsProps>, nextState: Readonly<WithAnalyticsState>, nextContext: any): boolean;
61
+ componentWillUnmount?(): void;
62
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
63
+ getSnapshotBeforeUpdate?(prevProps: Readonly<WithAnalyticsProps>, prevState: Readonly<WithAnalyticsState>): any;
64
+ componentDidUpdate?(prevProps: Readonly<WithAnalyticsProps>, prevState: Readonly<WithAnalyticsState>, snapshot?: any): void;
65
+ componentWillMount?(): void;
66
+ UNSAFE_componentWillMount?(): void;
67
+ componentWillReceiveProps?(nextProps: Readonly<WithAnalyticsProps>, nextContext: any): void;
68
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<WithAnalyticsProps>, nextContext: any): void;
69
+ componentWillUpdate?(nextProps: Readonly<WithAnalyticsProps>, nextState: Readonly<WithAnalyticsState>, nextContext: any): void;
70
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<WithAnalyticsProps>, nextState: Readonly<WithAnalyticsState>, nextContext: any): void;
71
+ };
72
+ displayName: string;
73
+ contextTypes: {
74
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
75
+ getParentAnalyticsData: PropTypes.Requireable<(...args: any[]) => any>;
76
+ };
77
+ defaultProps: Partial<WithAnalyticsProps>;
78
+ contextType?: React.Context<any> | undefined;
79
+ };
80
+ 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;
@@ -23,3 +23,6 @@ export { usePlatformLeafSyntheticEventHandler } from './hooks/usePlatformLeafSyn
23
23
  export type { UsePlatformLeafSyntheticEventHandlerHookArgs, UsePlatformLeafSyntheticEventHandlerHook, } from './hooks/usePlatformLeafSyntheticEventHandler';
24
24
  export { default as createAndFireEvent } from './utils/createAndFireEvent';
25
25
  export { default as cleanProps } from './utils/cleanProps';
26
+ export { default as AnalyticsDecorator } from './components/AnalyticsDecorator';
27
+ export { default as AnalyticsDelegate } from './components/AnalyticsDelegate';
28
+ export { default as withAnalytics } from './utils/withAnalytics';
@@ -0,0 +1,80 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ type AnalyticsData = {
4
+ [key: string]: any;
5
+ };
6
+ type WithAnalyticsProps = {
7
+ analyticsId?: string;
8
+ analyticsData?: AnalyticsData;
9
+ fireAnalyticsEvent?: (name: string, data?: AnalyticsData) => void;
10
+ firePrivateAnalyticsEvent?: (name: string, data?: AnalyticsData) => void;
11
+ getParentAnalyticsData?: (name: string) => AnalyticsData;
12
+ delegateAnalyticsEvent?: (analyticsId: string, data: any, isPrivate: boolean) => void;
13
+ innerRef?: React.Ref<any>;
14
+ [key: string]: any;
15
+ };
16
+ type WithAnalyticsState = {
17
+ evaluatedMap: {
18
+ [key: string]: string | ((...args: any[]) => void);
19
+ };
20
+ };
21
+ /**
22
+ * The withAnalytics HOC wraps a component and provides the `fireAnalyticsEvent`
23
+ * and `firePrivateAnalyticsEvent` methods to it as props. It contains the logic
24
+ * for how to fire events, including handling the analyticsId and analyticsData
25
+ * props. The `map` argument may be an object or a function that returns an object.
26
+ * The properties of the `map` object/result can be strings (the name of the event
27
+ * that will be fired) or functions (which are responsible for firing the event).
28
+ * You can specify a default `analyticsId` and `analyticsData` with the `defaultProps`
29
+ * param. Please be aware that specifying a default `analyticsId` will cause public
30
+ * events to always fire for your component unless it has been set to a falsy by
31
+ * the component consumer.
32
+ *
33
+ * @param WrappedComponent
34
+ * @param map
35
+ * @param defaultProps
36
+ * @param withDelegation
37
+ */
38
+ declare const withAnalytics: (WrappedComponent: React.ComponentType<any>, map?: {
39
+ [key: string]: string | ((...args: any[]) => void);
40
+ } | ((fireAnalyticsEvent: (name: string, data?: AnalyticsData) => void) => {
41
+ [key: string]: string | ((...args: any[]) => void);
42
+ }), defaultProps?: Partial<WithAnalyticsProps>, withDelegation?: boolean) => {
43
+ new (props: WithAnalyticsProps): {
44
+ componentDidMount(): void;
45
+ delegateAnalyticsEvent: (analyticsId: string, data: any, isPrivate: boolean) => void;
46
+ fireAnalyticsEvent: (name: string, data?: AnalyticsData) => void;
47
+ privateAnalyticsEvent: (name: string, data?: AnalyticsData) => void;
48
+ getParentAnalyticsData: (name: string) => AnalyticsData;
49
+ render(): JSX.Element;
50
+ context: any;
51
+ setState<K extends "evaluatedMap">(state: WithAnalyticsState | ((prevState: Readonly<WithAnalyticsState>, props: Readonly<WithAnalyticsProps>) => WithAnalyticsState | Pick<WithAnalyticsState, K> | null) | Pick<WithAnalyticsState, K> | null, callback?: (() => void) | undefined): void;
52
+ forceUpdate(callback?: (() => void) | undefined): void;
53
+ readonly props: Readonly<WithAnalyticsProps> & Readonly<{
54
+ children?: React.ReactNode;
55
+ }>;
56
+ state: Readonly<WithAnalyticsState>;
57
+ refs: {
58
+ [key: string]: React.ReactInstance;
59
+ };
60
+ shouldComponentUpdate?(nextProps: Readonly<WithAnalyticsProps>, nextState: Readonly<WithAnalyticsState>, nextContext: any): boolean;
61
+ componentWillUnmount?(): void;
62
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
63
+ getSnapshotBeforeUpdate?(prevProps: Readonly<WithAnalyticsProps>, prevState: Readonly<WithAnalyticsState>): any;
64
+ componentDidUpdate?(prevProps: Readonly<WithAnalyticsProps>, prevState: Readonly<WithAnalyticsState>, snapshot?: any): void;
65
+ componentWillMount?(): void;
66
+ UNSAFE_componentWillMount?(): void;
67
+ componentWillReceiveProps?(nextProps: Readonly<WithAnalyticsProps>, nextContext: any): void;
68
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<WithAnalyticsProps>, nextContext: any): void;
69
+ componentWillUpdate?(nextProps: Readonly<WithAnalyticsProps>, nextState: Readonly<WithAnalyticsState>, nextContext: any): void;
70
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<WithAnalyticsProps>, nextState: Readonly<WithAnalyticsState>, nextContext: any): void;
71
+ };
72
+ displayName: string;
73
+ contextTypes: {
74
+ onAnalyticsEvent: PropTypes.Requireable<(...args: any[]) => any>;
75
+ getParentAnalyticsData: PropTypes.Requireable<(...args: any[]) => any>;
76
+ };
77
+ defaultProps: Partial<WithAnalyticsProps>;
78
+ contextType?: React.Context<any> | undefined;
79
+ };
80
+ export default withAnalytics;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/analytics-next",
3
- "version": "10.1.0",
3
+ "version": "10.2.0",
4
4
  "description": "React components, HOCs and hooks to assist with tracking user activity with React components",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -24,18 +24,18 @@
24
24
  "atlaskit:src": "src/index.ts",
25
25
  "atlassian": {
26
26
  "team": "UIP Frontend Observability",
27
- "releaseModel": "continuous",
28
- "productPushConsumption": [
29
- "jira"
30
- ],
31
27
  "website": {
32
28
  "name": "Analytics next"
33
- }
29
+ },
30
+ "runReact18": true
34
31
  },
35
32
  "./types": "./src/types.ts",
36
33
  "af:exports": {
37
34
  "./types": "./src/types.ts",
38
35
  "./AnalyticsContext": "./src/components/AnalyticsContext/index.tsx",
36
+ "./AnalyticsDecorator": "./src/components/AnalyticsDecorator/index.ts",
37
+ "./AnalyticsDelegate": "./src/components/AnalyticsDelegate/index.ts",
38
+ "./withAnalytics": "./src/utils/withAnalytics.tsx",
39
39
  "./AnalyticsListener": "./src/components/AnalyticsListener/index.tsx",
40
40
  "./AnalyticsErrorBoundary": "./src/components/AnalyticsErrorBoundary.tsx",
41
41
  "./withAnalyticsEvents": "./src/hocs/withAnalyticsEvents.tsx",
@@ -60,14 +60,11 @@
60
60
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
61
61
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
62
62
  },
63
- "runReact18": true,
64
63
  "devDependencies": {
65
64
  "@atlaskit/ssr": "*",
66
65
  "@atlassian/feature-flags-test-utils": "*",
67
66
  "@testing-library/react": "^12.1.5",
68
- "enzyme": "^3.10.0",
69
- "redux": "^3.7.2",
70
- "storybook-addon-performance": "^0.16.0",
67
+ "storybook-addon-performance": "^0.17.3",
71
68
  "typescript": "~5.4.2"
72
69
  },
73
70
  "techstack": {
@@ -93,7 +90,7 @@
93
90
  }
94
91
  },
95
92
  "platform-feature-flags": {
96
- "platform.analytics-next-use-modern-context_fqgbx": {
93
+ "analytics-next-use-modern-context_jira": {
97
94
  "type": "boolean"
98
95
  }
99
96
  }