@atlaskit/analytics-next 8.3.4 → 9.0.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/CHANGELOG.md +12 -0
- package/dist/cjs/components/AnalyticsContext/LegacyAnalyticsContext.js +4 -28
- package/dist/cjs/components/AnalyticsContext/ModernAnalyticsContext.js +1 -12
- package/dist/cjs/components/AnalyticsContext/index.js +2 -9
- package/dist/cjs/components/AnalyticsErrorBoundary.js +19 -68
- package/dist/cjs/components/AnalyticsListener/LegacyAnalyticsListener.js +6 -32
- package/dist/cjs/components/AnalyticsListener/ModernAnalyticsListener.js +2 -14
- package/dist/cjs/components/AnalyticsListener/index.js +2 -9
- package/dist/cjs/events/AnalyticsEvent.js +2 -18
- package/dist/cjs/events/UIAnalyticsEvent.js +3 -31
- package/dist/cjs/hocs/withAnalyticsContext.js +5 -17
- package/dist/cjs/hocs/withAnalyticsEvents.js +6 -16
- package/dist/cjs/hooks/useAnalyticsContext.js +0 -5
- package/dist/cjs/hooks/useAnalyticsEvents.js +0 -5
- package/dist/cjs/hooks/useCallbackWithAnalytics.js +1 -7
- package/dist/cjs/hooks/usePatchedProps.js +3 -19
- package/dist/cjs/hooks/usePlatformLeafEventHandler.js +20 -27
- package/dist/cjs/hooks/usePlatformLeafSyntheticEventHandler.js +19 -26
- package/dist/cjs/hooks/useTrackedRef.js +0 -3
- package/dist/cjs/index.js +0 -18
- package/dist/cjs/test-utils/useRenderCounter.js +0 -3
- package/dist/cjs/utils/cleanProps.js +1 -5
- package/dist/cjs/utils/createAndFireEvent.js +0 -4
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/components/AnalyticsContext/LegacyAnalyticsContext.js +2 -12
- package/dist/es2019/components/AnalyticsContext/ModernAnalyticsContext.js +0 -2
- package/dist/es2019/components/AnalyticsContext/index.js +2 -5
- package/dist/es2019/components/AnalyticsErrorBoundary.js +8 -37
- package/dist/es2019/components/AnalyticsListener/LegacyAnalyticsListener.js +2 -14
- package/dist/es2019/components/AnalyticsListener/ModernAnalyticsListener.js +0 -3
- package/dist/es2019/components/AnalyticsListener/index.js +2 -5
- package/dist/es2019/events/AnalyticsEvent.js +6 -10
- package/dist/es2019/events/UIAnalyticsEvent.js +3 -15
- package/dist/es2019/hocs/withAnalyticsContext.js +6 -5
- package/dist/es2019/hocs/withAnalyticsEvents.js +4 -4
- package/dist/es2019/hooks/usePatchedProps.js +6 -9
- package/dist/es2019/hooks/usePlatformLeafEventHandler.js +14 -10
- package/dist/es2019/hooks/usePlatformLeafSyntheticEventHandler.js +14 -10
- package/dist/es2019/index.js +2 -1
- package/dist/es2019/test-utils/useRenderCounter.js +2 -1
- package/dist/es2019/utils/createAndFireEvent.js +0 -2
- package/dist/es2019/version.json +1 -1
- package/dist/esm/components/AnalyticsContext/LegacyAnalyticsContext.js +4 -21
- package/dist/esm/components/AnalyticsContext/ModernAnalyticsContext.js +1 -3
- package/dist/esm/components/AnalyticsContext/index.js +2 -5
- package/dist/esm/components/AnalyticsErrorBoundary.js +18 -54
- package/dist/esm/components/AnalyticsListener/LegacyAnalyticsListener.js +6 -25
- package/dist/esm/components/AnalyticsListener/ModernAnalyticsListener.js +2 -5
- package/dist/esm/components/AnalyticsListener/index.js +2 -5
- package/dist/esm/events/AnalyticsEvent.js +2 -16
- package/dist/esm/events/UIAnalyticsEvent.js +3 -27
- package/dist/esm/hocs/withAnalyticsContext.js +5 -9
- package/dist/esm/hocs/withAnalyticsEvents.js +6 -8
- package/dist/esm/hooks/useCallbackWithAnalytics.js +1 -2
- package/dist/esm/hooks/usePatchedProps.js +3 -14
- package/dist/esm/hooks/usePlatformLeafEventHandler.js +20 -22
- package/dist/esm/hooks/usePlatformLeafSyntheticEventHandler.js +19 -21
- package/dist/esm/index.js +2 -1
- package/dist/esm/test-utils/useRenderCounter.js +2 -1
- package/dist/esm/utils/cleanProps.js +1 -2
- package/dist/esm/utils/createAndFireEvent.js +0 -2
- package/dist/esm/version.json +1 -1
- package/dist/types/components/AnalyticsErrorBoundary.d.ts +7 -12
- package/package.json +5 -9
- package/report.api.md +137 -7407
- package/dist/types-ts4.0/components/AnalyticsContext/LegacyAnalyticsContext.d.ts +0 -29
- package/dist/types-ts4.0/components/AnalyticsContext/ModernAnalyticsContext.d.ts +0 -3
- package/dist/types-ts4.0/components/AnalyticsContext/index.d.ts +0 -3
- package/dist/types-ts4.0/components/AnalyticsContext/types.d.ts +0 -9
- package/dist/types-ts4.0/components/AnalyticsErrorBoundary.d.ts +0 -29
- package/dist/types-ts4.0/components/AnalyticsListener/LegacyAnalyticsListener.d.ts +0 -33
- package/dist/types-ts4.0/components/AnalyticsListener/ModernAnalyticsListener.d.ts +0 -3
- package/dist/types-ts4.0/components/AnalyticsListener/index.d.ts +0 -3
- package/dist/types-ts4.0/components/AnalyticsListener/types.d.ts +0 -12
- package/dist/types-ts4.0/events/AnalyticsEvent.d.ts +0 -15
- package/dist/types-ts4.0/events/UIAnalyticsEvent.d.ts +0 -20
- package/dist/types-ts4.0/hocs/withAnalyticsContext.d.ts +0 -6
- package/dist/types-ts4.0/hocs/withAnalyticsEvents.d.ts +0 -12
- package/dist/types-ts4.0/hooks/useAnalyticsContext.d.ts +0 -2
- package/dist/types-ts4.0/hooks/useAnalyticsEvents.d.ts +0 -5
- package/dist/types-ts4.0/hooks/useCallbackWithAnalytics.d.ts +0 -2
- package/dist/types-ts4.0/hooks/usePatchedProps.d.ts +0 -5
- package/dist/types-ts4.0/hooks/usePlatformLeafEventHandler.d.ts +0 -12
- package/dist/types-ts4.0/hooks/usePlatformLeafSyntheticEventHandler.d.ts +0 -11
- package/dist/types-ts4.0/hooks/useTrackedRef.d.ts +0 -2
- package/dist/types-ts4.0/index.d.ts +0 -25
- package/dist/types-ts4.0/performance/examples.d.ts +0 -5
- package/dist/types-ts4.0/test-utils/useRenderCounter.d.ts +0 -1
- package/dist/types-ts4.0/types.d.ts +0 -6
- package/dist/types-ts4.0/utils/cleanProps.d.ts +0 -3
- package/dist/types-ts4.0/utils/createAndFireEvent.d.ts +0 -4
|
@@ -4,20 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _default = function _default(channel) {
|
|
9
8
|
return function (payload) {
|
|
10
9
|
return function (createAnalyticsEvent) {
|
|
11
10
|
var consumerEvent = createAnalyticsEvent(payload);
|
|
12
11
|
var clonedEvent = consumerEvent.clone();
|
|
13
|
-
|
|
14
12
|
if (clonedEvent) {
|
|
15
13
|
clonedEvent.fire(channel);
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
return consumerEvent;
|
|
19
16
|
};
|
|
20
17
|
};
|
|
21
18
|
};
|
|
22
|
-
|
|
23
19
|
exports.default = _default;
|
package/dist/cjs/version.json
CHANGED
|
@@ -6,18 +6,15 @@ const ContextTypes = {
|
|
|
6
6
|
getAtlaskitAnalyticsContext: PropTypes.func,
|
|
7
7
|
getAtlaskitAnalyticsEventHandlers: PropTypes.func
|
|
8
8
|
};
|
|
9
|
+
const noop = () => [];
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
13
12
|
class AnalyticsContext extends Component {
|
|
14
13
|
constructor(props) {
|
|
15
14
|
super(props);
|
|
16
|
-
|
|
17
15
|
_defineProperty(this, "getChildContext", () => ({
|
|
18
16
|
getAtlaskitAnalyticsContext: this.getAnalyticsContext
|
|
19
17
|
}));
|
|
20
|
-
|
|
21
18
|
_defineProperty(this, "getAnalyticsContext", () => {
|
|
22
19
|
const {
|
|
23
20
|
data
|
|
@@ -27,20 +24,17 @@ class AnalyticsContext extends Component {
|
|
|
27
24
|
} = this.context;
|
|
28
25
|
return [...getAtlaskitAnalyticsContext(), data];
|
|
29
26
|
});
|
|
30
|
-
|
|
31
27
|
_defineProperty(this, "getAnalyticsEventHandlers", () => {
|
|
32
28
|
const {
|
|
33
29
|
getAtlaskitAnalyticsEventHandlers = noop
|
|
34
30
|
} = this.context;
|
|
35
31
|
return getAtlaskitAnalyticsEventHandlers();
|
|
36
32
|
});
|
|
37
|
-
|
|
38
33
|
this.contextValue = {
|
|
39
34
|
getAtlaskitAnalyticsContext: this.getAnalyticsContext,
|
|
40
35
|
getAtlaskitAnalyticsEventHandlers: this.getAnalyticsEventHandlers
|
|
41
36
|
};
|
|
42
37
|
}
|
|
43
|
-
|
|
44
38
|
render() {
|
|
45
39
|
const {
|
|
46
40
|
children
|
|
@@ -49,11 +43,7 @@ class AnalyticsContext extends Component {
|
|
|
49
43
|
value: this.contextValue
|
|
50
44
|
}, children);
|
|
51
45
|
}
|
|
52
|
-
|
|
53
46
|
}
|
|
54
|
-
|
|
55
47
|
_defineProperty(AnalyticsContext, "contextTypes", ContextTypes);
|
|
56
|
-
|
|
57
48
|
_defineProperty(AnalyticsContext, "childContextTypes", ContextTypes);
|
|
58
|
-
|
|
59
49
|
export default AnalyticsContext;
|
|
@@ -2,7 +2,6 @@ import React, { useCallback, useMemo } from 'react';
|
|
|
2
2
|
import { default as AnalyticsReactContext } from '@atlaskit/analytics-next-stable-react-context';
|
|
3
3
|
import { useAnalyticsContext } from '../../hooks/useAnalyticsContext';
|
|
4
4
|
import { useTrackedRef } from '../../hooks/useTrackedRef';
|
|
5
|
-
|
|
6
5
|
const AnalyticsContext = ({
|
|
7
6
|
data,
|
|
8
7
|
children
|
|
@@ -20,5 +19,4 @@ const AnalyticsContext = ({
|
|
|
20
19
|
value: value
|
|
21
20
|
}, children);
|
|
22
21
|
};
|
|
23
|
-
|
|
24
22
|
export default AnalyticsContext;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
var _process
|
|
2
|
-
|
|
1
|
+
var _process$env;
|
|
3
2
|
import LegacyAnalyticsContext from './LegacyAnalyticsContext';
|
|
4
3
|
import ModernAnalyticsContext from './ModernAnalyticsContext';
|
|
5
4
|
let ExportedAnalyticsContext;
|
|
6
|
-
|
|
7
|
-
if ((_process = process) !== null && _process !== void 0 && (_process$env = _process.env) !== null && _process$env !== void 0 && _process$env['ANALYTICS_NEXT_MODERN_CONTEXT']) {
|
|
5
|
+
if (typeof process !== 'undefined' && process !== null && (_process$env = process.env) !== null && _process$env !== void 0 && _process$env['ANALYTICS_NEXT_MODERN_CONTEXT']) {
|
|
8
6
|
ExportedAnalyticsContext = ModernAnalyticsContext;
|
|
9
7
|
} else {
|
|
10
8
|
ExportedAnalyticsContext = LegacyAnalyticsContext;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
export default ExportedAnalyticsContext;
|
|
@@ -1,49 +1,25 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
1
|
import React, { Component } from 'react';
|
|
3
|
-
import withAnalyticsEvents from '../hocs/withAnalyticsEvents';
|
|
4
2
|
import AnalyticsContext from './AnalyticsContext/LegacyAnalyticsContext';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated
|
|
5
|
+
*/
|
|
5
6
|
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
6
|
-
export class
|
|
7
|
+
export default class AnalyticsErrorBoundary extends Component {
|
|
7
8
|
constructor(props) {
|
|
8
9
|
super(props);
|
|
9
|
-
|
|
10
|
-
_defineProperty(this, "fireAnalytics", analyticsErrorPayload => {
|
|
11
|
-
const {
|
|
12
|
-
createAnalyticsEvent,
|
|
13
|
-
channel,
|
|
14
|
-
data
|
|
15
|
-
} = this.props;
|
|
16
|
-
createAnalyticsEvent({
|
|
17
|
-
action: 'UnhandledError',
|
|
18
|
-
eventType: 'ui',
|
|
19
|
-
attributes: {
|
|
20
|
-
browserInfo: window && window.navigator && window.navigator.userAgent ? window.navigator.userAgent : 'unknown',
|
|
21
|
-
...data,
|
|
22
|
-
...analyticsErrorPayload
|
|
23
|
-
}
|
|
24
|
-
}).fire(channel);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
10
|
this.state = {
|
|
28
11
|
hasError: false
|
|
29
12
|
};
|
|
30
13
|
}
|
|
31
|
-
|
|
32
14
|
componentDidCatch(error, info) {
|
|
33
15
|
const {
|
|
34
16
|
onError
|
|
35
17
|
} = this.props;
|
|
36
|
-
const payload = {
|
|
37
|
-
error,
|
|
38
|
-
info
|
|
39
|
-
};
|
|
40
|
-
this.fireAnalytics(payload);
|
|
41
18
|
onError && onError(error, info);
|
|
42
19
|
this.setState({
|
|
43
20
|
hasError: true
|
|
44
21
|
});
|
|
45
22
|
}
|
|
46
|
-
|
|
47
23
|
render() {
|
|
48
24
|
const {
|
|
49
25
|
data,
|
|
@@ -53,18 +29,13 @@ export class BaseAnalyticsErrorBoundary extends Component {
|
|
|
53
29
|
const {
|
|
54
30
|
hasError
|
|
55
31
|
} = this.state;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return /*#__PURE__*/React.createElement(AnalyticsContext, {
|
|
32
|
+
if (hasError) {
|
|
33
|
+
return ErrorComponent ? /*#__PURE__*/React.createElement(AnalyticsContext, {
|
|
59
34
|
data: data
|
|
60
|
-
}, /*#__PURE__*/React.createElement(ErrorComponent, null));
|
|
35
|
+
}, /*#__PURE__*/React.createElement(ErrorComponent, null)) : null;
|
|
61
36
|
}
|
|
62
|
-
|
|
63
37
|
return /*#__PURE__*/React.createElement(AnalyticsContext, {
|
|
64
38
|
data: data
|
|
65
39
|
}, children);
|
|
66
40
|
}
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
const AnalyticsErrorBoundary = withAnalyticsEvents()(BaseAnalyticsErrorBoundary);
|
|
70
|
-
export default AnalyticsErrorBoundary;
|
|
41
|
+
}
|
|
@@ -6,19 +6,16 @@ const ContextTypes = {
|
|
|
6
6
|
getAtlaskitAnalyticsEventHandlers: PropTypes.func,
|
|
7
7
|
getAtlaskitAnalyticsContext: PropTypes.func
|
|
8
8
|
};
|
|
9
|
+
const noop = () => [];
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
13
12
|
class AnalyticsListener extends Component {
|
|
14
13
|
constructor(props) {
|
|
15
14
|
super(props);
|
|
16
|
-
|
|
17
15
|
_defineProperty(this, "getChildContext", () => ({
|
|
18
16
|
getAtlaskitAnalyticsEventHandlers: this.getAnalyticsEventHandlers,
|
|
19
17
|
getAtlaskitAnalyticsContext: this.getAtlaskitAnalyticsContext
|
|
20
18
|
}));
|
|
21
|
-
|
|
22
19
|
_defineProperty(this, "getAnalyticsEventHandlers", () => {
|
|
23
20
|
const {
|
|
24
21
|
channel,
|
|
@@ -27,29 +24,24 @@ class AnalyticsListener extends Component {
|
|
|
27
24
|
const {
|
|
28
25
|
getAtlaskitAnalyticsEventHandlers = noop
|
|
29
26
|
} = this.context;
|
|
30
|
-
|
|
31
27
|
const handler = (event, eventChannel) => {
|
|
32
28
|
if (channel === '*' || channel === eventChannel) {
|
|
33
29
|
onEvent(event, eventChannel);
|
|
34
30
|
}
|
|
35
31
|
};
|
|
36
|
-
|
|
37
32
|
return [handler, ...getAtlaskitAnalyticsEventHandlers()];
|
|
38
33
|
});
|
|
39
|
-
|
|
40
34
|
_defineProperty(this, "getAtlaskitAnalyticsContext", () => {
|
|
41
35
|
const {
|
|
42
36
|
getAtlaskitAnalyticsContext = noop
|
|
43
37
|
} = this.context;
|
|
44
38
|
return getAtlaskitAnalyticsContext();
|
|
45
39
|
});
|
|
46
|
-
|
|
47
40
|
this.contextValue = {
|
|
48
41
|
getAtlaskitAnalyticsContext: this.getAtlaskitAnalyticsContext,
|
|
49
42
|
getAtlaskitAnalyticsEventHandlers: this.getAnalyticsEventHandlers
|
|
50
43
|
};
|
|
51
44
|
}
|
|
52
|
-
|
|
53
45
|
render() {
|
|
54
46
|
const {
|
|
55
47
|
children
|
|
@@ -58,11 +50,7 @@ class AnalyticsListener extends Component {
|
|
|
58
50
|
value: this.contextValue
|
|
59
51
|
}, children);
|
|
60
52
|
}
|
|
61
|
-
|
|
62
53
|
}
|
|
63
|
-
|
|
64
54
|
_defineProperty(AnalyticsListener, "contextTypes", ContextTypes);
|
|
65
|
-
|
|
66
55
|
_defineProperty(AnalyticsListener, "childContextTypes", ContextTypes);
|
|
67
|
-
|
|
68
56
|
export default AnalyticsListener;
|
|
@@ -2,7 +2,6 @@ import React, { useCallback, useMemo } from 'react';
|
|
|
2
2
|
import { default as AnalyticsReactContext } from '@atlaskit/analytics-next-stable-react-context';
|
|
3
3
|
import { useAnalyticsContext } from '../../hooks/useAnalyticsContext';
|
|
4
4
|
import { useTrackedRef } from '../../hooks/useTrackedRef';
|
|
5
|
-
|
|
6
5
|
const AnalyticsListener = ({
|
|
7
6
|
children,
|
|
8
7
|
channel,
|
|
@@ -17,7 +16,6 @@ const AnalyticsListener = ({
|
|
|
17
16
|
onEventRef.current(event, eventChannel);
|
|
18
17
|
}
|
|
19
18
|
};
|
|
20
|
-
|
|
21
19
|
return [...analyticsContext.getAtlaskitAnalyticsEventHandlers(), thisHandler];
|
|
22
20
|
}, [analyticsContext, channelRef, onEventRef]);
|
|
23
21
|
const value = useMemo(() => {
|
|
@@ -30,5 +28,4 @@ const AnalyticsListener = ({
|
|
|
30
28
|
value: value
|
|
31
29
|
}, children);
|
|
32
30
|
};
|
|
33
|
-
|
|
34
31
|
export default AnalyticsListener;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
var _process
|
|
2
|
-
|
|
1
|
+
var _process$env;
|
|
3
2
|
import LegacyAnalyticsListener from './LegacyAnalyticsListener';
|
|
4
3
|
import ModernAnalyticsListener from './ModernAnalyticsListener';
|
|
5
4
|
let ExportedAnalyticsListener;
|
|
6
|
-
|
|
7
|
-
if ((_process = process) !== null && _process !== void 0 && (_process$env = _process.env) !== null && _process$env !== void 0 && _process$env['ANALYTICS_NEXT_MODERN_CONTEXT']) {
|
|
5
|
+
if (typeof process !== 'undefined' && process !== null && (_process$env = process.env) !== null && _process$env !== void 0 && _process$env['ANALYTICS_NEXT_MODERN_CONTEXT']) {
|
|
8
6
|
ExportedAnalyticsListener = ModernAnalyticsListener;
|
|
9
7
|
} else {
|
|
10
8
|
ExportedAnalyticsListener = LegacyAnalyticsListener;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
export default ExportedAnalyticsListener;
|
|
@@ -1,39 +1,35 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
export const isAnalyticsEvent = obj => {
|
|
3
3
|
var _obj$constructor;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
return obj instanceof AnalyticsEvent || !!(obj !== null && obj !== void 0 && obj._isAnalyticsEvent) ||
|
|
5
|
+
// Backwards compatibility with older analytics-next packages
|
|
6
6
|
(obj === null || obj === void 0 ? void 0 : (_obj$constructor = obj.constructor) === null || _obj$constructor === void 0 ? void 0 : _obj$constructor.name) === 'AnalyticsEvent';
|
|
7
7
|
};
|
|
8
8
|
export default class AnalyticsEvent {
|
|
9
9
|
constructor(props) {
|
|
10
10
|
_defineProperty(this, "_isAnalyticsEvent", true);
|
|
11
|
-
|
|
12
11
|
_defineProperty(this, "clone", () => {
|
|
13
12
|
// just a shallow clone, don't change sub refs unless you want to
|
|
14
13
|
// affect the original's too
|
|
15
|
-
const payload = {
|
|
14
|
+
const payload = {
|
|
15
|
+
...this.payload
|
|
16
16
|
};
|
|
17
17
|
return new AnalyticsEvent({
|
|
18
18
|
payload
|
|
19
19
|
});
|
|
20
20
|
});
|
|
21
|
-
|
|
22
21
|
this.payload = props.payload;
|
|
23
22
|
}
|
|
24
|
-
|
|
25
23
|
update(updater) {
|
|
26
24
|
if (typeof updater === 'function') {
|
|
27
25
|
this.payload = updater(this.payload);
|
|
28
26
|
}
|
|
29
|
-
|
|
30
27
|
if (typeof updater === 'object') {
|
|
31
|
-
this.payload = {
|
|
28
|
+
this.payload = {
|
|
29
|
+
...this.payload,
|
|
32
30
|
...updater
|
|
33
31
|
};
|
|
34
32
|
}
|
|
35
|
-
|
|
36
33
|
return this;
|
|
37
34
|
}
|
|
38
|
-
|
|
39
35
|
}
|
|
@@ -2,34 +2,30 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
import AnalyticsEvent from './AnalyticsEvent';
|
|
3
3
|
export const isUIAnalyticsEvent = obj => {
|
|
4
4
|
var _obj$constructor;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
return obj instanceof UIAnalyticsEvent || !!(obj !== null && obj !== void 0 && obj._isUIAnalyticsEvent) ||
|
|
6
|
+
// Backwards compatibility with older analytics-next packages
|
|
7
7
|
(obj === null || obj === void 0 ? void 0 : (_obj$constructor = obj.constructor) === null || _obj$constructor === void 0 ? void 0 : _obj$constructor.name) === 'UIAnalyticsEvent';
|
|
8
8
|
};
|
|
9
9
|
export default class UIAnalyticsEvent extends AnalyticsEvent {
|
|
10
10
|
constructor(props) {
|
|
11
11
|
super(props);
|
|
12
|
-
|
|
13
12
|
_defineProperty(this, "_isUIAnalyticsEvent", true);
|
|
14
|
-
|
|
15
13
|
_defineProperty(this, "clone", () => {
|
|
16
14
|
if (this.hasFired) {
|
|
17
15
|
if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
|
|
18
16
|
// eslint-disable-next-line no-console
|
|
19
17
|
console.warn("Cannot clone an event after it's been fired.");
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
return null;
|
|
23
20
|
}
|
|
24
|
-
|
|
25
21
|
const context = [...this.context];
|
|
26
22
|
const handlers = [...this.handlers];
|
|
23
|
+
|
|
27
24
|
/**
|
|
28
25
|
* A hacky "deep clone" of the object. This is limited in that it wont
|
|
29
26
|
* support functions, regexs, Maps, Sets, etc, but none of those need to
|
|
30
27
|
* be represented in our payload.
|
|
31
28
|
*/
|
|
32
|
-
|
|
33
29
|
const payload = JSON.parse(JSON.stringify(this.payload));
|
|
34
30
|
return new UIAnalyticsEvent({
|
|
35
31
|
context,
|
|
@@ -37,37 +33,29 @@ export default class UIAnalyticsEvent extends AnalyticsEvent {
|
|
|
37
33
|
payload
|
|
38
34
|
});
|
|
39
35
|
});
|
|
40
|
-
|
|
41
36
|
_defineProperty(this, "fire", channel => {
|
|
42
37
|
if (this.hasFired) {
|
|
43
38
|
if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
|
|
44
39
|
// eslint-disable-next-line no-console
|
|
45
40
|
console.warn('Cannot fire an event twice.');
|
|
46
41
|
}
|
|
47
|
-
|
|
48
42
|
return;
|
|
49
43
|
}
|
|
50
|
-
|
|
51
44
|
this.handlers.forEach(handler => handler(this, channel));
|
|
52
45
|
this.hasFired = true;
|
|
53
46
|
});
|
|
54
|
-
|
|
55
47
|
this.context = props.context || [];
|
|
56
48
|
this.handlers = props.handlers || [];
|
|
57
49
|
this.hasFired = false;
|
|
58
50
|
}
|
|
59
|
-
|
|
60
51
|
update(updater) {
|
|
61
52
|
if (this.hasFired) {
|
|
62
53
|
if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
|
|
63
54
|
// eslint-disable-next-line no-console
|
|
64
55
|
console.warn("Cannot update an event after it's been fired.");
|
|
65
56
|
}
|
|
66
|
-
|
|
67
57
|
return this;
|
|
68
58
|
}
|
|
69
|
-
|
|
70
59
|
return super.update(updater);
|
|
71
60
|
}
|
|
72
|
-
|
|
73
61
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import React, { forwardRef, useMemo } from 'react';
|
|
3
3
|
import AnalyticsContext from '../components/AnalyticsContext';
|
|
4
|
-
|
|
5
4
|
const withAnalyticsContext = defaultData => WrappedComponent => {
|
|
6
5
|
const WithAnalyticsContext = /*#__PURE__*/forwardRef(({
|
|
7
6
|
analyticsContext,
|
|
8
7
|
...rest
|
|
9
8
|
}, ref) => {
|
|
10
|
-
const analyticsData = useMemo(() => ({
|
|
9
|
+
const analyticsData = useMemo(() => ({
|
|
10
|
+
...defaultData,
|
|
11
11
|
...analyticsContext
|
|
12
12
|
}), [analyticsContext]);
|
|
13
13
|
return /*#__PURE__*/React.createElement(AnalyticsContext, {
|
|
@@ -15,11 +15,12 @@ const withAnalyticsContext = defaultData => WrappedComponent => {
|
|
|
15
15
|
}, /*#__PURE__*/React.createElement(WrappedComponent, _extends({}, rest, {
|
|
16
16
|
ref: ref
|
|
17
17
|
})));
|
|
18
|
-
});
|
|
18
|
+
});
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
WithAnalyticsContext.displayName = `WithAnalyticsContext(${
|
|
22
|
+
// @ts-ignore disneyName doesn't exist on type
|
|
21
23
|
WrappedComponent.displayName || WrappedComponent.name})`;
|
|
22
24
|
return WithAnalyticsContext;
|
|
23
25
|
};
|
|
24
|
-
|
|
25
26
|
export default withAnalyticsContext;
|
|
@@ -2,7 +2,6 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import React, { forwardRef } from 'react';
|
|
3
3
|
import { useAnalyticsEvents } from '../hooks/useAnalyticsEvents';
|
|
4
4
|
import { usePatchedProps } from '../hooks/usePatchedProps';
|
|
5
|
-
|
|
6
5
|
const withAnalyticsEvents = (createEventMap = {}) => WrappedComponent => {
|
|
7
6
|
const WithAnalyticsEvents = /*#__PURE__*/forwardRef((props, ref) => {
|
|
8
7
|
const {
|
|
@@ -15,11 +14,12 @@ const withAnalyticsEvents = (createEventMap = {}) => WrappedComponent => {
|
|
|
15
14
|
createAnalyticsEvent: createAnalyticsEvent,
|
|
16
15
|
ref: ref
|
|
17
16
|
}));
|
|
18
|
-
});
|
|
17
|
+
});
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
WithAnalyticsEvents.displayName = `WithAnalyticsEvents(${
|
|
21
|
+
// @ts-ignore disneyName doesn't exist on type
|
|
21
22
|
WrappedComponent.displayName || WrappedComponent.name})`;
|
|
22
23
|
return WithAnalyticsEvents;
|
|
23
24
|
};
|
|
24
|
-
|
|
25
25
|
export default withAnalyticsEvents;
|
|
@@ -6,38 +6,35 @@ export function usePatchedProps(createEventMap = {}, wrappedComponentProps) {
|
|
|
6
6
|
} = useAnalyticsEvents();
|
|
7
7
|
const handlerCache = useRef({});
|
|
8
8
|
const patchedProps = useMemo(() => {
|
|
9
|
-
const cache = handlerCache.current;
|
|
9
|
+
const cache = handlerCache.current;
|
|
10
10
|
|
|
11
|
+
// Clean up no longer used handlers in cache
|
|
11
12
|
Object.keys(cache).filter(key => !(key in createEventMap)).forEach(key => delete cache[key]);
|
|
12
13
|
return Object.keys(createEventMap).reduce((p, k) => {
|
|
13
14
|
const eventCreator = createEventMap[k];
|
|
14
|
-
|
|
15
15
|
if (!['object', 'function'].includes(typeof eventCreator)) {
|
|
16
16
|
return p;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
18
|
const propValue = wrappedComponentProps[k];
|
|
20
|
-
|
|
21
19
|
if (k in cache && cache[k].eventCreator === eventCreator && cache[k].propValue === propValue) {
|
|
22
|
-
return {
|
|
20
|
+
return {
|
|
21
|
+
...p,
|
|
23
22
|
[k]: cache[k].wrappedCallback
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
|
-
|
|
27
25
|
const wrappedCallback = (...args) => {
|
|
28
26
|
const analyticsEvent = typeof eventCreator === 'function' ? eventCreator(createAnalyticsEvent, wrappedComponentProps) : createAnalyticsEvent(eventCreator);
|
|
29
|
-
|
|
30
27
|
if (propValue && typeof propValue === 'function') {
|
|
31
28
|
propValue(...args, analyticsEvent);
|
|
32
29
|
}
|
|
33
30
|
};
|
|
34
|
-
|
|
35
31
|
cache[k] = {
|
|
36
32
|
eventCreator,
|
|
37
33
|
wrappedCallback,
|
|
38
34
|
propValue
|
|
39
35
|
};
|
|
40
|
-
return {
|
|
36
|
+
return {
|
|
37
|
+
...p,
|
|
41
38
|
[k]: wrappedCallback
|
|
42
39
|
};
|
|
43
40
|
}, {});
|
|
@@ -18,11 +18,12 @@ export function usePlatformLeafEventHandler({
|
|
|
18
18
|
}) {
|
|
19
19
|
const {
|
|
20
20
|
createAnalyticsEvent
|
|
21
|
-
} = useAnalyticsEvents();
|
|
21
|
+
} = useAnalyticsEvents();
|
|
22
|
+
|
|
23
|
+
// We put analyticsData and fn in a ref so that we don't need to break
|
|
22
24
|
// memoization.
|
|
23
25
|
// Generally these could be defined by consumers inline
|
|
24
26
|
// and so we do this to avoid breaking memoization of useCallback
|
|
25
|
-
|
|
26
27
|
const dataRef = useTrackedRef(analyticsData);
|
|
27
28
|
const fnRef = useTrackedRef(fn);
|
|
28
29
|
const handler = useCallback(value => {
|
|
@@ -34,28 +35,31 @@ export function usePlatformLeafEventHandler({
|
|
|
34
35
|
packageName,
|
|
35
36
|
packageVersion
|
|
36
37
|
}
|
|
37
|
-
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// To avoid wrapping this component in AnalyticsContext we manually
|
|
38
41
|
// push the parent context's meta data into the context.
|
|
39
42
|
// Note: this new 'context'
|
|
40
|
-
|
|
41
43
|
const context = {
|
|
42
44
|
componentName,
|
|
43
45
|
packageName,
|
|
44
46
|
packageVersion,
|
|
45
47
|
...dataRef.current
|
|
46
48
|
};
|
|
47
|
-
analyticsEvent.context.push(context);
|
|
49
|
+
analyticsEvent.context.push(context);
|
|
48
50
|
|
|
51
|
+
// fire an event on the atlaskit channel
|
|
49
52
|
const clone = analyticsEvent.clone();
|
|
50
|
-
|
|
51
53
|
if (clone) {
|
|
52
54
|
clone.fire('atlaskit');
|
|
53
55
|
}
|
|
54
|
-
|
|
55
56
|
fnRef.current(value, analyticsEvent);
|
|
56
|
-
}, [
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
}, [
|
|
58
|
+
// These are strings and won't change
|
|
59
|
+
action, componentName, actionSubject, packageName, packageVersion,
|
|
60
|
+
// This function is memoized in the context
|
|
61
|
+
createAnalyticsEvent,
|
|
62
|
+
// these are a stable ref because of the useTrackedRef hook
|
|
59
63
|
dataRef, fnRef]);
|
|
60
64
|
return handler;
|
|
61
65
|
}
|
|
@@ -17,11 +17,12 @@ export function usePlatformLeafSyntheticEventHandler({
|
|
|
17
17
|
}) {
|
|
18
18
|
const {
|
|
19
19
|
createAnalyticsEvent
|
|
20
|
-
} = useAnalyticsEvents();
|
|
20
|
+
} = useAnalyticsEvents();
|
|
21
|
+
|
|
22
|
+
// We put analyticsData and fn in a ref so that we don't need to break
|
|
21
23
|
// memoization.
|
|
22
24
|
// Generally these could be defined by consumers inline
|
|
23
25
|
// and so we do this to avoid breaking memoization of useCallback
|
|
24
|
-
|
|
25
26
|
const dataRef = useTrackedRef(analyticsData);
|
|
26
27
|
const fnRef = useTrackedRef(fn);
|
|
27
28
|
const handler = useCallback(() => {
|
|
@@ -33,28 +34,31 @@ export function usePlatformLeafSyntheticEventHandler({
|
|
|
33
34
|
packageName,
|
|
34
35
|
packageVersion
|
|
35
36
|
}
|
|
36
|
-
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// To avoid wrapping this component in AnalyticsContext we manually
|
|
37
40
|
// push the parent context's meta data into the context.
|
|
38
41
|
// Note: this new 'context'
|
|
39
|
-
|
|
40
42
|
const context = {
|
|
41
43
|
componentName,
|
|
42
44
|
packageName,
|
|
43
45
|
packageVersion,
|
|
44
46
|
...dataRef.current
|
|
45
47
|
};
|
|
46
|
-
analyticsEvent.context.push(context);
|
|
48
|
+
analyticsEvent.context.push(context);
|
|
47
49
|
|
|
50
|
+
// fire an event on the atlaskit channel
|
|
48
51
|
const clone = analyticsEvent.clone();
|
|
49
|
-
|
|
50
52
|
if (clone) {
|
|
51
53
|
clone.fire('atlaskit');
|
|
52
54
|
}
|
|
53
|
-
|
|
54
55
|
fnRef.current(analyticsEvent);
|
|
55
|
-
}, [
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
}, [
|
|
57
|
+
// These are strings and won't change
|
|
58
|
+
action, componentName, packageName, packageVersion,
|
|
59
|
+
// This function is memoized in the context
|
|
60
|
+
createAnalyticsEvent,
|
|
61
|
+
// these are a stable ref because of the useTrackedRef hook
|
|
58
62
|
dataRef, fnRef]);
|
|
59
63
|
return handler;
|
|
60
64
|
}
|
package/dist/es2019/index.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
export { default as AnalyticsEvent, isAnalyticsEvent } from './events/AnalyticsEvent';
|
|
3
3
|
export { default as UIAnalyticsEvent, isUIAnalyticsEvent } from './events/UIAnalyticsEvent';
|
|
4
4
|
// AnalyticsListener component
|
|
5
|
-
export { default as AnalyticsListener } from './components/AnalyticsListener/index';
|
|
5
|
+
export { default as AnalyticsListener } from './components/AnalyticsListener/index';
|
|
6
6
|
|
|
7
|
+
// AnalyticsContext component and HOC
|
|
7
8
|
export { default as AnalyticsContext } from './components/AnalyticsContext/index';
|
|
8
9
|
export { default as withAnalyticsContext } from './hocs/withAnalyticsContext';
|
|
9
10
|
// AnalyticsErrorBoundary component
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react';
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
2
|
|
|
3
|
+
// Hook to track the number of renders in tests
|
|
3
4
|
export const useRenderCounter = () => {
|
|
4
5
|
const ref = useRef(1);
|
|
5
6
|
useEffect(() => {
|
package/dist/es2019/version.json
CHANGED