@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.
- package/AnalyticsDecorator/package.json +15 -0
- package/AnalyticsDelegate/package.json +15 -0
- package/CHANGELOG.md +16 -0
- package/afm-cc/tsconfig.json +1 -2
- package/afm-jira/tsconfig.json +24 -24
- package/afm-post-office/tsconfig.json +24 -24
- package/dist/cjs/components/AnalyticsContext/LegacyAnalyticsContext.js +2 -2
- package/dist/cjs/components/AnalyticsContext/ModernAnalyticsContext.js +1 -1
- package/dist/cjs/components/AnalyticsContext/index.js +1 -1
- package/dist/cjs/components/AnalyticsDecorator/index.js +107 -0
- package/dist/cjs/components/AnalyticsDelegate/index.js +75 -0
- package/dist/cjs/components/AnalyticsErrorBoundary.js +3 -3
- package/dist/cjs/components/AnalyticsListener/LegacyAnalyticsListener.js +2 -2
- package/dist/cjs/components/AnalyticsListener/ModernAnalyticsListener.js +1 -1
- package/dist/cjs/components/AnalyticsListener/index.js +1 -1
- package/dist/cjs/components/matchEvent/index.js +23 -0
- package/dist/cjs/events/UIAnalyticsEvent.js +2 -2
- package/dist/cjs/hocs/withAnalyticsContext.js +1 -1
- package/dist/cjs/hocs/withAnalyticsEvents.js +1 -1
- package/dist/cjs/index.js +22 -1
- package/dist/cjs/utils/isModernContextEnabledEnv.js +1 -0
- package/dist/cjs/utils/withAnalytics.js +147 -0
- package/dist/es2019/components/AnalyticsContext/index.js +1 -1
- package/dist/es2019/components/AnalyticsDecorator/index.js +79 -0
- package/dist/es2019/components/AnalyticsDelegate/index.js +48 -0
- package/dist/es2019/components/AnalyticsErrorBoundary.js +1 -1
- package/dist/es2019/components/AnalyticsListener/index.js +1 -1
- package/dist/es2019/components/matchEvent/index.js +17 -0
- package/dist/es2019/events/UIAnalyticsEvent.js +1 -0
- package/dist/es2019/index.js +6 -1
- package/dist/es2019/utils/isModernContextEnabledEnv.js +1 -0
- package/dist/es2019/utils/withAnalytics.js +121 -0
- package/dist/esm/components/AnalyticsContext/LegacyAnalyticsContext.js +1 -1
- package/dist/esm/components/AnalyticsContext/index.js +1 -1
- package/dist/esm/components/AnalyticsDecorator/index.js +97 -0
- package/dist/esm/components/AnalyticsDelegate/index.js +65 -0
- package/dist/esm/components/AnalyticsErrorBoundary.js +2 -2
- package/dist/esm/components/AnalyticsListener/LegacyAnalyticsListener.js +1 -1
- package/dist/esm/components/AnalyticsListener/index.js +1 -1
- package/dist/esm/components/matchEvent/index.js +17 -0
- package/dist/esm/events/UIAnalyticsEvent.js +2 -1
- package/dist/esm/index.js +6 -1
- package/dist/esm/utils/isModernContextEnabledEnv.js +1 -0
- package/dist/esm/utils/withAnalytics.js +137 -0
- package/dist/types/components/AnalyticsDecorator/index.d.ts +46 -0
- package/dist/types/components/AnalyticsDelegate/index.d.ts +25 -0
- package/dist/types/components/matchEvent/index.d.ts +3 -0
- package/dist/types/hocs/withAnalyticsEvents.d.ts +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/utils/withAnalytics.d.ts +80 -0
- package/dist/types-ts4.5/components/AnalyticsDecorator/index.d.ts +46 -0
- package/dist/types-ts4.5/components/AnalyticsDelegate/index.d.ts +25 -0
- package/dist/types-ts4.5/components/matchEvent/index.d.ts +3 -0
- package/dist/types-ts4.5/hocs/withAnalyticsEvents.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +3 -0
- package/dist/types-ts4.5/utils/withAnalytics.d.ts +80 -0
- package/package.json +8 -11
- package/withAnalytics/package.json +15 -0
|
@@ -0,0 +1,147 @@
|
|
|
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 _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
14
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
16
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
17
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
19
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
20
|
+
var _excluded = ["analyticsId", "analyticsData"];
|
|
21
|
+
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); }
|
|
22
|
+
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; }
|
|
23
|
+
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; }
|
|
24
|
+
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; }
|
|
25
|
+
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); }; }
|
|
26
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
27
|
+
/**
|
|
28
|
+
* The withAnalytics HOC wraps a component and provides the `fireAnalyticsEvent`
|
|
29
|
+
* and `firePrivateAnalyticsEvent` methods to it as props. It contains the logic
|
|
30
|
+
* for how to fire events, including handling the analyticsId and analyticsData
|
|
31
|
+
* props. The `map` argument may be an object or a function that returns an object.
|
|
32
|
+
* The properties of the `map` object/result can be strings (the name of the event
|
|
33
|
+
* that will be fired) or functions (which are responsible for firing the event).
|
|
34
|
+
* You can specify a default `analyticsId` and `analyticsData` with the `defaultProps`
|
|
35
|
+
* param. Please be aware that specifying a default `analyticsId` will cause public
|
|
36
|
+
* events to always fire for your component unless it has been set to a falsy by
|
|
37
|
+
* the component consumer.
|
|
38
|
+
*
|
|
39
|
+
* @param WrappedComponent
|
|
40
|
+
* @param map
|
|
41
|
+
* @param defaultProps
|
|
42
|
+
* @param withDelegation
|
|
43
|
+
*/
|
|
44
|
+
var withAnalytics = function withAnalytics(WrappedComponent) {
|
|
45
|
+
var _class;
|
|
46
|
+
var map = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
47
|
+
var defaultProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
48
|
+
var withDelegation = arguments.length > 3 ? arguments[3] : undefined;
|
|
49
|
+
return _class = /*#__PURE__*/function (_Component) {
|
|
50
|
+
(0, _inherits2.default)(WithAnalytics, _Component);
|
|
51
|
+
var _super = _createSuper(WithAnalytics);
|
|
52
|
+
function WithAnalytics(props) {
|
|
53
|
+
var _this;
|
|
54
|
+
(0, _classCallCheck2.default)(this, WithAnalytics);
|
|
55
|
+
_this = _super.call(this, props);
|
|
56
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "delegateAnalyticsEvent", function (analyticsId, data, isPrivate) {
|
|
57
|
+
var _ref = _this.context,
|
|
58
|
+
onAnalyticsEvent = _ref.onAnalyticsEvent;
|
|
59
|
+
if (!onAnalyticsEvent) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
onAnalyticsEvent(analyticsId, data, isPrivate);
|
|
63
|
+
});
|
|
64
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "fireAnalyticsEvent", function (name, data) {
|
|
65
|
+
var _this$props = _this.props,
|
|
66
|
+
analyticsData = _this$props.analyticsData,
|
|
67
|
+
analyticsId = _this$props.analyticsId;
|
|
68
|
+
var _ref2 = _this.context,
|
|
69
|
+
onAnalyticsEvent = _ref2.onAnalyticsEvent;
|
|
70
|
+
if (!analyticsId || !onAnalyticsEvent) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
var eventData = _objectSpread(_objectSpread({}, analyticsData), data);
|
|
74
|
+
onAnalyticsEvent("".concat(analyticsId, ".").concat(name), eventData, false);
|
|
75
|
+
});
|
|
76
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "privateAnalyticsEvent", function (name, data) {
|
|
77
|
+
var _ref3 = _this.context,
|
|
78
|
+
onAnalyticsEvent = _ref3.onAnalyticsEvent;
|
|
79
|
+
if (!onAnalyticsEvent) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
onAnalyticsEvent("".concat(name), data, true);
|
|
83
|
+
});
|
|
84
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getParentAnalyticsData", function (name) {
|
|
85
|
+
var _ref4 = _this.context,
|
|
86
|
+
getParentAnalyticsData = _ref4.getParentAnalyticsData;
|
|
87
|
+
var parentData = {};
|
|
88
|
+
if (typeof getParentAnalyticsData === 'function' && _this.props.analyticsId) {
|
|
89
|
+
var analyticsId = _this.props.analyticsId;
|
|
90
|
+
parentData = getParentAnalyticsData("".concat(analyticsId, ".").concat(name), false);
|
|
91
|
+
}
|
|
92
|
+
return parentData;
|
|
93
|
+
});
|
|
94
|
+
_this.state = {
|
|
95
|
+
evaluatedMap: {}
|
|
96
|
+
};
|
|
97
|
+
return _this;
|
|
98
|
+
}
|
|
99
|
+
(0, _createClass2.default)(WithAnalytics, [{
|
|
100
|
+
key: "componentDidMount",
|
|
101
|
+
value: function componentDidMount() {
|
|
102
|
+
this.setState({
|
|
103
|
+
evaluatedMap: typeof map === 'function' ? map(this.fireAnalyticsEvent) : map
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}, {
|
|
107
|
+
key: "render",
|
|
108
|
+
value: function render() {
|
|
109
|
+
var _this2 = this;
|
|
110
|
+
var _this$props2 = this.props,
|
|
111
|
+
analyticsId = _this$props2.analyticsId,
|
|
112
|
+
analyticsData = _this$props2.analyticsData,
|
|
113
|
+
componentProps = (0, _objectWithoutProperties2.default)(_this$props2, _excluded);
|
|
114
|
+
Object.keys(this.state.evaluatedMap).forEach(function (prop) {
|
|
115
|
+
var handler = _this2.state.evaluatedMap[prop];
|
|
116
|
+
var originalProp = componentProps[prop];
|
|
117
|
+
componentProps[prop] = function () {
|
|
118
|
+
if (typeof handler === 'function') {
|
|
119
|
+
handler.apply(void 0, arguments);
|
|
120
|
+
} else {
|
|
121
|
+
_this2.fireAnalyticsEvent(handler);
|
|
122
|
+
}
|
|
123
|
+
if (typeof originalProp === 'function') {
|
|
124
|
+
originalProp.apply(void 0, arguments);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
return /*#__PURE__*/_react.default.createElement(WrappedComponent, (0, _extends2.default)({
|
|
129
|
+
fireAnalyticsEvent: this.fireAnalyticsEvent,
|
|
130
|
+
firePrivateAnalyticsEvent: this.privateAnalyticsEvent,
|
|
131
|
+
getParentAnalyticsData: this.getParentAnalyticsData,
|
|
132
|
+
delegateAnalyticsEvent: withDelegation ? this.delegateAnalyticsEvent : undefined,
|
|
133
|
+
analyticsId: analyticsId,
|
|
134
|
+
ref: this.props.innerRef
|
|
135
|
+
}, componentProps));
|
|
136
|
+
}
|
|
137
|
+
}]);
|
|
138
|
+
return WithAnalytics;
|
|
139
|
+
}(_react.Component), (0, _defineProperty2.default)(_class, "displayName", "WithAnalytics(".concat(WrappedComponent.displayName || WrappedComponent.name, ")")), (0, _defineProperty2.default)(_class, "contextTypes", {
|
|
140
|
+
onAnalyticsEvent: _propTypes.default.func,
|
|
141
|
+
getParentAnalyticsData: _propTypes.default.func
|
|
142
|
+
}), (0, _defineProperty2.default)(_class, "defaultProps", {
|
|
143
|
+
analyticsId: defaultProps.analyticsId,
|
|
144
|
+
analyticsData: defaultProps.analyticsData
|
|
145
|
+
}), _class;
|
|
146
|
+
};
|
|
147
|
+
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('
|
|
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('
|
|
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('
|
|
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;
|
package/dist/es2019/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';
|
|
@@ -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 _class;
|
|
24
|
+
return _class = 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(_class, "displayName", `WithAnalytics(${WrappedComponent.displayName || WrappedComponent.name})`), _defineProperty(_class, "contextTypes", {
|
|
114
|
+
onAnalyticsEvent: PropTypes.func,
|
|
115
|
+
getParentAnalyticsData: PropTypes.func
|
|
116
|
+
}), _defineProperty(_class, "defaultProps", {
|
|
117
|
+
analyticsId: defaultProps.analyticsId,
|
|
118
|
+
analyticsData: defaultProps.analyticsData
|
|
119
|
+
}), _class;
|
|
120
|
+
};
|
|
121
|
+
export default withAnalytics;
|
|
@@ -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(
|
|
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 LegacyAnalyticsContext from './LegacyAnalyticsContext';
|
|
5
5
|
import ModernAnalyticsContext from './ModernAnalyticsContext';
|
|
6
6
|
var ExportedAnalyticsContext = function ExportedAnalyticsContext(props) {
|
|
7
|
-
var isModernContext = isModernContextEnabledEnv || fg('
|
|
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,97 @@
|
|
|
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 _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
5
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
7
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
8
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
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); }; }
|
|
12
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
13
|
+
import React, { Component } from 'react';
|
|
14
|
+
import PropTypes from 'prop-types';
|
|
15
|
+
import index from '../matchEvent';
|
|
16
|
+
export var ContextTypes = {
|
|
17
|
+
onAnalyticsEvent: PropTypes.func,
|
|
18
|
+
getParentAnalyticsData: PropTypes.func
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The Decorator component extends analytics event data
|
|
23
|
+
* for any events fired by its descendents,
|
|
24
|
+
* then passes the event up the hierarchy
|
|
25
|
+
*/
|
|
26
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
27
|
+
export var AnalyticsDecorator = /*#__PURE__*/function (_Component) {
|
|
28
|
+
_inherits(AnalyticsDecorator, _Component);
|
|
29
|
+
var _super = _createSuper(AnalyticsDecorator);
|
|
30
|
+
function AnalyticsDecorator() {
|
|
31
|
+
var _this;
|
|
32
|
+
_classCallCheck(this, AnalyticsDecorator);
|
|
33
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
34
|
+
args[_key] = arguments[_key];
|
|
35
|
+
}
|
|
36
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
37
|
+
_defineProperty(_assertThisInitialized(_this), "getDecoratedAnalyticsData", function (name, srcData, isPrivate) {
|
|
38
|
+
var _this$props = _this.props,
|
|
39
|
+
data = _this$props.data,
|
|
40
|
+
getData = _this$props.getData,
|
|
41
|
+
match = _this$props.match,
|
|
42
|
+
matchPrivate = _this$props.matchPrivate;
|
|
43
|
+
var decoratedData = _objectSpread({}, srcData);
|
|
44
|
+
if (matchPrivate === isPrivate && index(match, name)) {
|
|
45
|
+
if (_typeof(data) === 'object') {
|
|
46
|
+
Object.assign(decoratedData, data);
|
|
47
|
+
}
|
|
48
|
+
if (typeof getData === 'function') {
|
|
49
|
+
Object.assign(decoratedData, getData(name, decoratedData));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return decoratedData;
|
|
53
|
+
});
|
|
54
|
+
_defineProperty(_assertThisInitialized(_this), "onAnalyticsEvent", function (name, srcData, isPrivate) {
|
|
55
|
+
var _ref = _this.context,
|
|
56
|
+
onAnalyticsEvent = _ref.onAnalyticsEvent;
|
|
57
|
+
if (typeof onAnalyticsEvent !== 'function') {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
var decoratedData = _this.getDecoratedAnalyticsData(name, srcData, isPrivate);
|
|
61
|
+
onAnalyticsEvent(name, decoratedData, isPrivate);
|
|
62
|
+
});
|
|
63
|
+
_defineProperty(_assertThisInitialized(_this), "getParentAnalyticsData", function (name, isPrivate) {
|
|
64
|
+
var parentData = _this.getDecoratedAnalyticsData(name, {}, isPrivate);
|
|
65
|
+
var _ref2 = _this.context,
|
|
66
|
+
getParentAnalyticsData = _ref2.getParentAnalyticsData;
|
|
67
|
+
if (typeof getParentAnalyticsData === 'function') {
|
|
68
|
+
Object.assign(parentData, getParentAnalyticsData(name, isPrivate));
|
|
69
|
+
}
|
|
70
|
+
return parentData;
|
|
71
|
+
});
|
|
72
|
+
return _this;
|
|
73
|
+
}
|
|
74
|
+
_createClass(AnalyticsDecorator, [{
|
|
75
|
+
key: "getChildContext",
|
|
76
|
+
value: function getChildContext() {
|
|
77
|
+
return {
|
|
78
|
+
onAnalyticsEvent: this.onAnalyticsEvent,
|
|
79
|
+
getParentAnalyticsData: this.getParentAnalyticsData
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
key: "render",
|
|
84
|
+
value: function render() {
|
|
85
|
+
var children = this.props.children;
|
|
86
|
+
return React.Children.only(children);
|
|
87
|
+
}
|
|
88
|
+
}]);
|
|
89
|
+
return AnalyticsDecorator;
|
|
90
|
+
}(Component);
|
|
91
|
+
_defineProperty(AnalyticsDecorator, "defaultProps", {
|
|
92
|
+
match: '*',
|
|
93
|
+
matchPrivate: false
|
|
94
|
+
});
|
|
95
|
+
_defineProperty(AnalyticsDecorator, "contextTypes", ContextTypes);
|
|
96
|
+
_defineProperty(AnalyticsDecorator, "childContextTypes", ContextTypes);
|
|
97
|
+
export default AnalyticsDecorator;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
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 _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
|
+
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
|
+
var ContextTypes = {
|
|
15
|
+
onAnalyticsEvent: PropTypes.func
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Listens to public and private events and delegates to an analytics
|
|
20
|
+
* stack in a different React root.
|
|
21
|
+
*/
|
|
22
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
23
|
+
var AnalyticsDelegate = /*#__PURE__*/function (_Component) {
|
|
24
|
+
_inherits(AnalyticsDelegate, _Component);
|
|
25
|
+
var _super = _createSuper(AnalyticsDelegate);
|
|
26
|
+
function AnalyticsDelegate() {
|
|
27
|
+
var _this;
|
|
28
|
+
_classCallCheck(this, AnalyticsDelegate);
|
|
29
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
30
|
+
args[_key] = arguments[_key];
|
|
31
|
+
}
|
|
32
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
33
|
+
_defineProperty(_assertThisInitialized(_this), "onAnalyticsEvent", function (name, data, isPrivate) {
|
|
34
|
+
var delegateAnalyticsEvent = _this.props.delegateAnalyticsEvent;
|
|
35
|
+
var eventData = _objectSpread({}, data);
|
|
36
|
+
if (delegateAnalyticsEvent) {
|
|
37
|
+
delegateAnalyticsEvent(name, eventData, isPrivate);
|
|
38
|
+
}
|
|
39
|
+
var _ref = _this.context,
|
|
40
|
+
onAnalyticsEvent = _ref.onAnalyticsEvent;
|
|
41
|
+
if (typeof onAnalyticsEvent === 'function') {
|
|
42
|
+
onAnalyticsEvent(name, data, isPrivate);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return _this;
|
|
46
|
+
}
|
|
47
|
+
_createClass(AnalyticsDelegate, [{
|
|
48
|
+
key: "getChildContext",
|
|
49
|
+
value: function getChildContext() {
|
|
50
|
+
return {
|
|
51
|
+
onAnalyticsEvent: this.onAnalyticsEvent
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "render",
|
|
56
|
+
value: function render() {
|
|
57
|
+
var children = this.props.children;
|
|
58
|
+
return React.Children.only(children);
|
|
59
|
+
}
|
|
60
|
+
}]);
|
|
61
|
+
return AnalyticsDelegate;
|
|
62
|
+
}(Component);
|
|
63
|
+
_defineProperty(AnalyticsDelegate, "contextTypes", ContextTypes);
|
|
64
|
+
_defineProperty(AnalyticsDelegate, "childContextTypes", ContextTypes);
|
|
65
|
+
export default AnalyticsDelegate;
|