@atlaskit/smart-card 26.5.13 → 26.5.15
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/version.json +1 -1
- package/dist/cjs/view/HoverCard/components/HoverCardComponent.js +9 -49
- package/dist/cjs/view/HoverCard/components/HoverCardContent.js +13 -16
- package/dist/cjs/view/HoverCard/index.js +4 -33
- package/dist/cjs/view/LinkUrl/LinkWarningModal/hooks/use-link-warning-modal.js +36 -19
- package/dist/cjs/view/LinkUrl/index.js +23 -4
- package/dist/es2019/version.json +1 -1
- package/dist/es2019/view/HoverCard/components/HoverCardComponent.js +6 -46
- package/dist/es2019/view/HoverCard/components/HoverCardContent.js +13 -16
- package/dist/es2019/view/HoverCard/index.js +5 -33
- package/dist/es2019/view/LinkUrl/LinkWarningModal/hooks/use-link-warning-modal.js +36 -19
- package/dist/es2019/view/LinkUrl/index.js +22 -3
- package/dist/esm/version.json +1 -1
- package/dist/esm/view/HoverCard/components/HoverCardComponent.js +7 -49
- package/dist/esm/view/HoverCard/components/HoverCardContent.js +13 -16
- package/dist/esm/view/HoverCard/index.js +5 -33
- package/dist/esm/view/LinkUrl/LinkWarningModal/hooks/use-link-warning-modal.js +36 -19
- package/dist/esm/view/LinkUrl/index.js +23 -4
- package/dist/types/view/Card/index.d.ts +1 -1
- package/dist/types/view/LinkUrl/LinkWarningModal/hooks/use-link-warning-modal.d.ts +4 -3
- package/dist/types-ts4.5/view/Card/index.d.ts +1 -1
- package/dist/types-ts4.5/view/LinkUrl/LinkWarningModal/hooks/use-link-warning-modal.d.ts +4 -3
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/smart-card
|
|
2
2
|
|
|
3
|
+
## 26.5.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`7b2d54a82d0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7b2d54a82d0) - Cleans up a FF introduced in 26.3.3 & Fixes HoverCard component providing hover card analytics context to the wrapped trigger component
|
|
8
|
+
|
|
9
|
+
## 26.5.14
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`fd2375e6f26`](https://bitbucket.org/atlassian/atlassian-frontend/commits/fd2375e6f26) - [ux] Prevent skipping of warning modal when onClick callback programatically opens a window. OnClick function is no longer called if the warning modal is shown. This will prevent link click analytics from firing but there is no easy way to distinguish the effects of what happens within onClick. Additionally, clicking continue in the warning modal will always open the link in a new tab.
|
|
14
|
+
|
|
3
15
|
## 26.5.13
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/cjs/version.json
CHANGED
|
@@ -7,9 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.HoverCardComponent = void 0;
|
|
9
9
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
11
|
var _popup = _interopRequireDefault(require("@atlaskit/popup"));
|
|
14
12
|
var _react = require("@emotion/react");
|
|
15
13
|
var _react2 = _interopRequireWildcard(require("react"));
|
|
@@ -22,15 +20,14 @@ var _constants = require("../../../constants");
|
|
|
22
20
|
var _SmartLinkAnalyticsContext = require("../../../utils/analytics/SmartLinkAnalyticsContext");
|
|
23
21
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
24
22
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
/** @jsx jsx */
|
|
24
|
+
|
|
27
25
|
var HOVER_CARD_SOURCE = 'smartLinkPreviewHoverCard';
|
|
28
26
|
var HoverCardComponent = function HoverCardComponent(_ref) {
|
|
29
27
|
var children = _ref.children,
|
|
30
28
|
url = _ref.url,
|
|
31
29
|
id = _ref.id,
|
|
32
30
|
analyticsHandler = _ref.analyticsHandler,
|
|
33
|
-
analytics = _ref.analytics,
|
|
34
31
|
_ref$canOpen = _ref.canOpen,
|
|
35
32
|
canOpen = _ref$canOpen === void 0 ? true : _ref$canOpen,
|
|
36
33
|
_ref$closeOnChildClic = _ref.closeOnChildClick,
|
|
@@ -46,15 +43,11 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
|
|
|
46
43
|
setIsOpen = _React$useState2[1];
|
|
47
44
|
var fadeOutTimeoutId = (0, _react2.useRef)();
|
|
48
45
|
var fadeInTimeoutId = (0, _react2.useRef)();
|
|
49
|
-
var cardOpenTime = (0, _react2.useRef)();
|
|
50
46
|
var mousePos = (0, _react2.useRef)();
|
|
51
47
|
var popupOffset = (0, _react2.useRef)();
|
|
52
48
|
var parentSpan = (0, _react2.useRef)(null);
|
|
53
49
|
var renderers = (0, _renderers.useSmartLinkRenderers)();
|
|
54
50
|
var linkState = (0, _store.useSmartCardState)(url);
|
|
55
|
-
var linkStatus = linkState.status;
|
|
56
|
-
var hoverDisplay = 'card';
|
|
57
|
-
var invokeMethod = 'mouse_hover';
|
|
58
51
|
var setMousePosition = (0, _react2.useCallback)(function (event) {
|
|
59
52
|
if (isOpen) {
|
|
60
53
|
return;
|
|
@@ -65,24 +58,8 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
|
|
|
65
58
|
};
|
|
66
59
|
}, [isOpen]);
|
|
67
60
|
var hideCard = (0, _react2.useCallback)(function () {
|
|
68
|
-
if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.smart-card.refactor-hover-card-analytics')) {
|
|
69
|
-
/**
|
|
70
|
-
* Defer to inner HoverCardContent to fire this event
|
|
71
|
-
*/
|
|
72
|
-
} else {
|
|
73
|
-
//Check its previously open to avoid firing events when moving between the child and hover card components
|
|
74
|
-
if (isOpen === true && cardOpenTime.current) {
|
|
75
|
-
var hoverTime = Date.now() - cardOpenTime.current;
|
|
76
|
-
analytics === null || analytics === void 0 ? void 0 : analytics.ui.hoverCardDismissedEvent({
|
|
77
|
-
previewDisplay: 'card',
|
|
78
|
-
hoverTime: hoverTime,
|
|
79
|
-
previewInvokeMethod: 'mouse_hover',
|
|
80
|
-
status: linkStatus
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
61
|
setIsOpen(false);
|
|
85
|
-
}, [
|
|
62
|
+
}, []);
|
|
86
63
|
var initHideCard = (0, _react2.useCallback)(function () {
|
|
87
64
|
if (fadeInTimeoutId.current) {
|
|
88
65
|
clearTimeout(fadeInTimeoutId.current);
|
|
@@ -98,21 +75,6 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
|
|
|
98
75
|
//Set mouse position in the case it's not already set by onMouseMove, as in the case of scrolling
|
|
99
76
|
setMousePosition(event);
|
|
100
77
|
fadeInTimeoutId.current = setTimeout(function () {
|
|
101
|
-
if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.smart-card.refactor-hover-card-analytics')) {
|
|
102
|
-
/**
|
|
103
|
-
* Defer to inner HoverCardContent to fire this event
|
|
104
|
-
*/
|
|
105
|
-
} else {
|
|
106
|
-
//Check if its previously closed to avoid firing events when moving between the child and hover card components
|
|
107
|
-
if (isOpen === false) {
|
|
108
|
-
cardOpenTime.current = Date.now();
|
|
109
|
-
analytics === null || analytics === void 0 ? void 0 : analytics.ui.hoverCardViewedEvent({
|
|
110
|
-
previewDisplay: hoverDisplay,
|
|
111
|
-
previewInvokeMethod: invokeMethod,
|
|
112
|
-
status: linkStatus
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
78
|
//If these are undefined then popupOffset is undefined and we fallback to default bottom-start placement
|
|
117
79
|
if (parentSpan.current && mousePos.current) {
|
|
118
80
|
var _parentSpan$current$g = parentSpan.current.getBoundingClientRect(),
|
|
@@ -122,7 +84,7 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
|
|
|
122
84
|
}
|
|
123
85
|
setIsOpen(true);
|
|
124
86
|
}, delay);
|
|
125
|
-
}, [
|
|
87
|
+
}, [setMousePosition]);
|
|
126
88
|
var linkActions = (0, _useSmartLinkActions.useSmartLinkActions)({
|
|
127
89
|
url: url,
|
|
128
90
|
appearance: _constants.CardDisplay.HoverCardPreview,
|
|
@@ -150,7 +112,7 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
|
|
|
150
112
|
}, [closeOnChildClick, hideCard]);
|
|
151
113
|
var content = (0, _react2.useCallback)(function (_ref2) {
|
|
152
114
|
var update = _ref2.update;
|
|
153
|
-
var hoverCardContentProps =
|
|
115
|
+
var hoverCardContentProps = {
|
|
154
116
|
onMouseEnter: initShowCard,
|
|
155
117
|
onMouseLeave: initHideCard,
|
|
156
118
|
cardActions: filteredActions,
|
|
@@ -161,16 +123,14 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
|
|
|
161
123
|
showServerActions: showServerActions,
|
|
162
124
|
url: url,
|
|
163
125
|
id: id
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
});
|
|
167
|
-
return (0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.smart-card.enable-analytics-context') ? (0, _react.jsx)(_SmartLinkAnalyticsContext.SmartLinkAnalyticsContext, {
|
|
126
|
+
};
|
|
127
|
+
return (0, _react.jsx)(_SmartLinkAnalyticsContext.SmartLinkAnalyticsContext, {
|
|
168
128
|
url: url,
|
|
169
129
|
display: _constants.CardDisplay.HoverCardPreview,
|
|
170
130
|
id: id,
|
|
171
131
|
source: HOVER_CARD_SOURCE
|
|
172
|
-
}, (0, _react.jsx)(_HoverCardContent.default, hoverCardContentProps))
|
|
173
|
-
}, [
|
|
132
|
+
}, (0, _react.jsx)(_HoverCardContent.default, hoverCardContentProps));
|
|
133
|
+
}, [initHideCard, initShowCard, filteredActions, linkState, onActionClick, renderers, showServerActions, url, id]);
|
|
174
134
|
var trigger = (0, _react2.useCallback)(function (triggerProps) {
|
|
175
135
|
return (0, _react.jsx)("span", {
|
|
176
136
|
ref: parentSpan
|
|
@@ -10,7 +10,6 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
|
10
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
11
|
var _react = require("@emotion/react");
|
|
12
12
|
var _analyticsNext = require("@atlaskit/analytics-next");
|
|
13
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
13
|
var _shortcut = _interopRequireDefault(require("@atlaskit/icon/glyph/shortcut"));
|
|
15
14
|
var _copy = _interopRequireDefault(require("@atlaskit/icon/glyph/copy"));
|
|
16
15
|
var _react2 = _interopRequireWildcard(require("react"));
|
|
@@ -135,25 +134,23 @@ var HoverCardContent = function HoverCardContent(_ref) {
|
|
|
135
134
|
}
|
|
136
135
|
}, [analytics, linkStatus]);
|
|
137
136
|
(0, _react2.useEffect)(function () {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
var previewDisplay = 'card';
|
|
138
|
+
var previewInvokeMethod = 'mouse_hover';
|
|
139
|
+
var cardOpenTime = Date.now();
|
|
140
|
+
analyticsRef.current.ui.hoverCardViewedEvent({
|
|
141
|
+
previewDisplay: previewDisplay,
|
|
142
|
+
previewInvokeMethod: previewInvokeMethod,
|
|
143
|
+
status: statusRef.current
|
|
144
|
+
});
|
|
145
|
+
return function () {
|
|
146
|
+
var hoverTime = Date.now() - cardOpenTime;
|
|
147
|
+
analyticsRef.current.ui.hoverCardDismissedEvent({
|
|
143
148
|
previewDisplay: previewDisplay,
|
|
144
149
|
previewInvokeMethod: previewInvokeMethod,
|
|
150
|
+
hoverTime: hoverTime,
|
|
145
151
|
status: statusRef.current
|
|
146
152
|
});
|
|
147
|
-
|
|
148
|
-
var hoverTime = Date.now() - cardOpenTime;
|
|
149
|
-
analyticsRef.current.ui.hoverCardDismissedEvent({
|
|
150
|
-
previewDisplay: previewDisplay,
|
|
151
|
-
previewInvokeMethod: previewInvokeMethod,
|
|
152
|
-
hoverTime: hoverTime,
|
|
153
|
-
status: statusRef.current
|
|
154
|
-
});
|
|
155
|
-
};
|
|
156
|
-
}
|
|
153
|
+
};
|
|
157
154
|
}, []);
|
|
158
155
|
var onClick = (0, _react2.useCallback)(function (event) {
|
|
159
156
|
var isModifierKeyPressed = (0, _utils.isSpecialEvent)(event);
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.HoverCard = void 0;
|
|
8
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
7
|
var _analyticsNext = require("@atlaskit/analytics-next");
|
|
10
8
|
var _react = require("@emotion/react");
|
|
11
9
|
var _react2 = require("react");
|
|
12
10
|
var _reactErrorBoundary = require("react-error-boundary");
|
|
13
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
11
|
var _analytics = require("../../state/analytics");
|
|
15
|
-
var _analytics2 = require("../../utils/analytics");
|
|
16
12
|
var _HoverCardComponent = require("./components/HoverCardComponent");
|
|
17
13
|
var _constants = require("../../constants");
|
|
18
14
|
/** @jsx jsx */
|
|
@@ -20,16 +16,8 @@ var _constants = require("../../constants");
|
|
|
20
16
|
var HoverCardWithErrorBoundary = function HoverCardWithErrorBoundary(props) {
|
|
21
17
|
var url = props.url,
|
|
22
18
|
id = props.id,
|
|
23
|
-
children = props.children
|
|
24
|
-
|
|
25
|
-
var analyticsHandler = (0, _react2.useCallback)(function (analyticsPayload) {
|
|
26
|
-
(0, _analytics2.fireSmartLinkEvent)(analyticsPayload, createAnalyticsEvent);
|
|
27
|
-
}, [createAnalyticsEvent]);
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Feature flag disables prop drilling of analytics handlers
|
|
31
|
-
*/
|
|
32
|
-
var analytics = (0, _analytics.useSmartLinkAnalytics)(url, (0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.smart-card.refactor-hover-card-analytics') ? undefined : analyticsHandler, id);
|
|
19
|
+
children = props.children;
|
|
20
|
+
var analytics = (0, _analytics.useSmartLinkAnalytics)(url, undefined, id);
|
|
33
21
|
var onError = (0, _react2.useCallback)(function (error, info) {
|
|
34
22
|
analytics.ui.renderFailedEvent({
|
|
35
23
|
display: _constants.CardDisplay.HoverCardPreview,
|
|
@@ -38,30 +26,13 @@ var HoverCardWithErrorBoundary = function HoverCardWithErrorBoundary(props) {
|
|
|
38
26
|
errorInfo: info
|
|
39
27
|
});
|
|
40
28
|
}, [analytics.ui, id]);
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Feature flag disables the prop drilling of analytics handlers to hover card component
|
|
44
|
-
*/
|
|
45
|
-
var analyticsProps = (0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.smart-card.refactor-hover-card-analytics') ? {} : {
|
|
46
|
-
analyticsHandler: analyticsHandler,
|
|
47
|
-
analytics: analytics
|
|
48
|
-
};
|
|
49
29
|
return (0, _react.jsx)(_reactErrorBoundary.ErrorBoundary, {
|
|
50
30
|
fallback: children,
|
|
51
31
|
onError: onError
|
|
52
|
-
}, (0, _react.jsx)(_HoverCardComponent.HoverCardComponent,
|
|
32
|
+
}, (0, _react.jsx)(_HoverCardComponent.HoverCardComponent, props, children));
|
|
53
33
|
};
|
|
54
|
-
var HoverCardWithAnalyticsContext = (0, _analyticsNext.withAnalyticsContext)({
|
|
55
|
-
source: 'smartLinkPreviewHoverCard',
|
|
56
|
-
attributes: {
|
|
57
|
-
display: _constants.CardDisplay.HoverCardPreview
|
|
58
|
-
}
|
|
59
|
-
})((0, _analyticsNext.withAnalyticsEvents)()(HoverCardWithErrorBoundary));
|
|
60
34
|
var HoverCardWithoutAnalyticsContext = (0, _analyticsNext.withAnalyticsEvents)()(HoverCardWithErrorBoundary);
|
|
61
35
|
var HoverCard = function HoverCard(props) {
|
|
62
|
-
|
|
63
|
-
return (0, _react.jsx)(HoverCardWithoutAnalyticsContext, props);
|
|
64
|
-
}
|
|
65
|
-
return (0, _react.jsx)(HoverCardWithAnalyticsContext, props);
|
|
36
|
+
return (0, _react.jsx)(HoverCardWithoutAnalyticsContext, props);
|
|
66
37
|
};
|
|
67
38
|
exports.HoverCard = HoverCard;
|
|
@@ -25,37 +25,46 @@ var useLinkWarningModal = function useLinkWarningModal() {
|
|
|
25
25
|
setIsOpen = _useState6[1];
|
|
26
26
|
var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
|
|
27
27
|
createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
|
|
28
|
-
var
|
|
28
|
+
var sendWarningModalViewedEvent = function sendWarningModalViewedEvent() {
|
|
29
29
|
createAnalyticsEvent({
|
|
30
|
-
action: '
|
|
31
|
-
actionSubject: '
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
action: 'viewed',
|
|
31
|
+
actionSubject: 'linkSafetyWarningModal',
|
|
32
|
+
eventType: 'screen',
|
|
33
|
+
name: 'linkSafetyWarningModal'
|
|
34
|
+
}).fire(_analytics.ANALYTICS_CHANNEL);
|
|
35
|
+
};
|
|
36
|
+
var sendContinueClickedEvent = function sendContinueClickedEvent() {
|
|
37
|
+
createAnalyticsEvent({
|
|
38
|
+
action: 'clicked',
|
|
39
|
+
actionSubject: 'button',
|
|
40
|
+
actionSubjectId: 'linkSafetyWarningModalContinue',
|
|
41
|
+
eventType: 'ui',
|
|
42
|
+
screen: 'linkSafetyWarningModal'
|
|
34
43
|
}).fire(_analytics.ANALYTICS_CHANNEL);
|
|
35
44
|
};
|
|
36
45
|
|
|
37
46
|
/**
|
|
38
47
|
* It checks and warns if a link text is a URL and different from an actual link destination
|
|
39
48
|
*/
|
|
40
|
-
var
|
|
49
|
+
var isLinkSafe = function isLinkSafe(event, href) {
|
|
41
50
|
if (!href) {
|
|
42
|
-
return;
|
|
51
|
+
return true;
|
|
43
52
|
}
|
|
44
53
|
var anchor = event.currentTarget;
|
|
45
54
|
var linkText = anchor.innerText;
|
|
46
55
|
var normalisedUrlFromLinkText = (0, _url.normalizeUrl)(linkText);
|
|
47
56
|
if (!normalisedUrlFromLinkText) {
|
|
48
|
-
return;
|
|
57
|
+
return true;
|
|
49
58
|
}
|
|
50
59
|
var anchorLinkRegex = new RegExp(/^#/im);
|
|
51
60
|
var isAnchorLink = anchorLinkRegex.test(linkText);
|
|
52
61
|
if (isAnchorLink) {
|
|
53
|
-
return;
|
|
62
|
+
return true;
|
|
54
63
|
}
|
|
55
64
|
var relativeLinkRegex = new RegExp(/^\//im);
|
|
56
65
|
var isRelativeHrefLink = relativeLinkRegex.test(href);
|
|
57
66
|
if (isRelativeHrefLink) {
|
|
58
|
-
return;
|
|
67
|
+
return true;
|
|
59
68
|
}
|
|
60
69
|
var hrefUrl = new URL(href, window.location.origin);
|
|
61
70
|
var linkTextUrl = new URL(normalisedUrlFromLinkText, hrefUrl.origin);
|
|
@@ -69,12 +78,18 @@ var useLinkWarningModal = function useLinkWarningModal() {
|
|
|
69
78
|
}
|
|
70
79
|
var areEquivalentLinks = linkTextUrl.hostname === hrefUrl.hostname && linkTextUrl.pathname === hrefUrl.pathname && linkTextUrl.search === hrefUrl.search && linkTextUrl.username === hrefUrl.username && linkTextUrl.password === hrefUrl.password && areProtocolsEquivalent;
|
|
71
80
|
if (!areEquivalentLinks) {
|
|
72
|
-
|
|
73
|
-
setUnsafeLinkText(linkText);
|
|
74
|
-
href && setUrl(href);
|
|
75
|
-
setIsOpen(true);
|
|
76
|
-
sendAnalyticsEvent();
|
|
81
|
+
return false;
|
|
77
82
|
}
|
|
83
|
+
return true;
|
|
84
|
+
};
|
|
85
|
+
var showSafetyWarningModal = function showSafetyWarningModal(event, href) {
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
var anchor = event.currentTarget;
|
|
88
|
+
var linkText = anchor.innerText;
|
|
89
|
+
setUnsafeLinkText(linkText);
|
|
90
|
+
href && setUrl(href);
|
|
91
|
+
setIsOpen(true);
|
|
92
|
+
sendWarningModalViewedEvent();
|
|
78
93
|
};
|
|
79
94
|
var onClose = function onClose() {
|
|
80
95
|
setIsOpen(false);
|
|
@@ -83,14 +98,16 @@ var useLinkWarningModal = function useLinkWarningModal() {
|
|
|
83
98
|
};
|
|
84
99
|
var onContinue = function onContinue() {
|
|
85
100
|
onClose();
|
|
86
|
-
|
|
101
|
+
sendContinueClickedEvent();
|
|
102
|
+
url && window.open(url, '_blank', 'noopener noreferrer');
|
|
87
103
|
};
|
|
88
104
|
return {
|
|
89
|
-
|
|
90
|
-
|
|
105
|
+
isLinkSafe: isLinkSafe,
|
|
106
|
+
isOpen: isOpen,
|
|
91
107
|
onClose: onClose,
|
|
92
108
|
onContinue: onContinue,
|
|
93
|
-
|
|
109
|
+
showSafetyWarningModal: showSafetyWarningModal,
|
|
110
|
+
unsafeLinkText: unsafeLinkText,
|
|
94
111
|
url: url
|
|
95
112
|
};
|
|
96
113
|
};
|
|
@@ -14,8 +14,9 @@ var _click = require("../../utils/analytics/click");
|
|
|
14
14
|
var _LinkAnalyticsContext = require("../../utils/analytics/LinkAnalyticsContext");
|
|
15
15
|
var _useLinkWarningModal2 = require("./LinkWarningModal/hooks/use-link-warning-modal");
|
|
16
16
|
var _LinkWarningModal = _interopRequireDefault(require("./LinkWarningModal"));
|
|
17
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
17
18
|
var _excluded = ["href", "children", "checkSafety", "onClick", "testId"],
|
|
18
|
-
_excluded2 = ["
|
|
19
|
+
_excluded2 = ["isLinkSafe", "showSafetyWarningModal"];
|
|
19
20
|
var PACKAGE_DATA = {
|
|
20
21
|
packageName: _version.name,
|
|
21
22
|
packageVersion: _version.version,
|
|
@@ -32,7 +33,8 @@ var LinkUrl = function LinkUrl(_ref) {
|
|
|
32
33
|
testId = _ref$testId === void 0 ? 'link-with-safety' : _ref$testId,
|
|
33
34
|
props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
34
35
|
var _useLinkWarningModal = (0, _useLinkWarningModal2.useLinkWarningModal)(),
|
|
35
|
-
|
|
36
|
+
isLinkSafe = _useLinkWarningModal.isLinkSafe,
|
|
37
|
+
showSafetyWarningModal = _useLinkWarningModal.showSafetyWarningModal,
|
|
36
38
|
linkWarningModalProps = (0, _objectWithoutProperties2.default)(_useLinkWarningModal, _excluded2);
|
|
37
39
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_LinkAnalyticsContext.LinkAnalyticsContext, {
|
|
38
40
|
url: href,
|
|
@@ -41,8 +43,25 @@ var LinkUrl = function LinkUrl(_ref) {
|
|
|
41
43
|
"data-testid": testId,
|
|
42
44
|
href: href,
|
|
43
45
|
onClick: function onClick(e) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.smart-card.should-call-onclick-in-warning-modal-only-when-safe')) {
|
|
47
|
+
if (!checkSafety) {
|
|
48
|
+
_onClick && _onClick(e);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Only call the onClick if the link is safe
|
|
53
|
+
if (isLinkSafe(e, href)) {
|
|
54
|
+
_onClick && _onClick(e);
|
|
55
|
+
} else {
|
|
56
|
+
showSafetyWarningModal(e, href);
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
if (checkSafety && !isLinkSafe(e, href)) {
|
|
60
|
+
showSafetyWarningModal(e, href);
|
|
61
|
+
}
|
|
62
|
+
// Call the onClick regardless of the link safety
|
|
63
|
+
_onClick && _onClick(e);
|
|
64
|
+
}
|
|
46
65
|
}
|
|
47
66
|
}, props), children)), checkSafety && /*#__PURE__*/_react.default.createElement(_LinkWarningModal.default, linkWarningModalProps));
|
|
48
67
|
};
|
package/dist/es2019/version.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
/** @jsx jsx */
|
|
3
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
4
3
|
import Popup from '@atlaskit/popup';
|
|
5
4
|
import { jsx } from '@emotion/react';
|
|
6
5
|
import React, { useCallback, useMemo, useRef } from 'react';
|
|
@@ -17,7 +16,6 @@ export const HoverCardComponent = ({
|
|
|
17
16
|
url,
|
|
18
17
|
id,
|
|
19
18
|
analyticsHandler,
|
|
20
|
-
analytics,
|
|
21
19
|
canOpen = true,
|
|
22
20
|
closeOnChildClick = false,
|
|
23
21
|
hidePreviewButton = false,
|
|
@@ -27,15 +25,11 @@ export const HoverCardComponent = ({
|
|
|
27
25
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
28
26
|
const fadeOutTimeoutId = useRef();
|
|
29
27
|
const fadeInTimeoutId = useRef();
|
|
30
|
-
const cardOpenTime = useRef();
|
|
31
28
|
const mousePos = useRef();
|
|
32
29
|
const popupOffset = useRef();
|
|
33
30
|
const parentSpan = useRef(null);
|
|
34
31
|
const renderers = useSmartLinkRenderers();
|
|
35
32
|
const linkState = useLinkState(url);
|
|
36
|
-
const linkStatus = linkState.status;
|
|
37
|
-
const hoverDisplay = 'card';
|
|
38
|
-
const invokeMethod = 'mouse_hover';
|
|
39
33
|
const setMousePosition = useCallback(event => {
|
|
40
34
|
if (isOpen) {
|
|
41
35
|
return;
|
|
@@ -46,24 +40,8 @@ export const HoverCardComponent = ({
|
|
|
46
40
|
};
|
|
47
41
|
}, [isOpen]);
|
|
48
42
|
const hideCard = useCallback(() => {
|
|
49
|
-
if (getBooleanFF('platform.linking-platform.smart-card.refactor-hover-card-analytics')) {
|
|
50
|
-
/**
|
|
51
|
-
* Defer to inner HoverCardContent to fire this event
|
|
52
|
-
*/
|
|
53
|
-
} else {
|
|
54
|
-
//Check its previously open to avoid firing events when moving between the child and hover card components
|
|
55
|
-
if (isOpen === true && cardOpenTime.current) {
|
|
56
|
-
const hoverTime = Date.now() - cardOpenTime.current;
|
|
57
|
-
analytics === null || analytics === void 0 ? void 0 : analytics.ui.hoverCardDismissedEvent({
|
|
58
|
-
previewDisplay: 'card',
|
|
59
|
-
hoverTime,
|
|
60
|
-
previewInvokeMethod: 'mouse_hover',
|
|
61
|
-
status: linkStatus
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
43
|
setIsOpen(false);
|
|
66
|
-
}, [
|
|
44
|
+
}, []);
|
|
67
45
|
const initHideCard = useCallback(() => {
|
|
68
46
|
if (fadeInTimeoutId.current) {
|
|
69
47
|
clearTimeout(fadeInTimeoutId.current);
|
|
@@ -77,21 +55,6 @@ export const HoverCardComponent = ({
|
|
|
77
55
|
//Set mouse position in the case it's not already set by onMouseMove, as in the case of scrolling
|
|
78
56
|
setMousePosition(event);
|
|
79
57
|
fadeInTimeoutId.current = setTimeout(() => {
|
|
80
|
-
if (getBooleanFF('platform.linking-platform.smart-card.refactor-hover-card-analytics')) {
|
|
81
|
-
/**
|
|
82
|
-
* Defer to inner HoverCardContent to fire this event
|
|
83
|
-
*/
|
|
84
|
-
} else {
|
|
85
|
-
//Check if its previously closed to avoid firing events when moving between the child and hover card components
|
|
86
|
-
if (isOpen === false) {
|
|
87
|
-
cardOpenTime.current = Date.now();
|
|
88
|
-
analytics === null || analytics === void 0 ? void 0 : analytics.ui.hoverCardViewedEvent({
|
|
89
|
-
previewDisplay: hoverDisplay,
|
|
90
|
-
previewInvokeMethod: invokeMethod,
|
|
91
|
-
status: linkStatus
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
58
|
//If these are undefined then popupOffset is undefined and we fallback to default bottom-start placement
|
|
96
59
|
if (parentSpan.current && mousePos.current) {
|
|
97
60
|
const {
|
|
@@ -102,7 +65,7 @@ export const HoverCardComponent = ({
|
|
|
102
65
|
}
|
|
103
66
|
setIsOpen(true);
|
|
104
67
|
}, delay);
|
|
105
|
-
}, [
|
|
68
|
+
}, [setMousePosition]);
|
|
106
69
|
const linkActions = useSmartLinkActions({
|
|
107
70
|
url,
|
|
108
71
|
appearance: CardDisplay.HoverCardPreview,
|
|
@@ -139,18 +102,15 @@ export const HoverCardComponent = ({
|
|
|
139
102
|
renderers,
|
|
140
103
|
showServerActions,
|
|
141
104
|
url,
|
|
142
|
-
id
|
|
143
|
-
...(getBooleanFF('platform.linking-platform.smart-card.refactor-hover-card-analytics') ? {} : {
|
|
144
|
-
analytics
|
|
145
|
-
})
|
|
105
|
+
id
|
|
146
106
|
};
|
|
147
|
-
return
|
|
107
|
+
return jsx(SmartLinkAnalyticsContext, {
|
|
148
108
|
url: url,
|
|
149
109
|
display: CardDisplay.HoverCardPreview,
|
|
150
110
|
id: id,
|
|
151
111
|
source: HOVER_CARD_SOURCE
|
|
152
|
-
}, jsx(HoverCardContent, hoverCardContentProps))
|
|
153
|
-
}, [
|
|
112
|
+
}, jsx(HoverCardContent, hoverCardContentProps));
|
|
113
|
+
}, [initHideCard, initShowCard, filteredActions, linkState, onActionClick, renderers, showServerActions, url, id]);
|
|
154
114
|
const trigger = useCallback(triggerProps => jsx("span", {
|
|
155
115
|
ref: parentSpan
|
|
156
116
|
}, jsx("span", _extends({}, triggerProps, {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
2
|
import { jsx } from '@emotion/react';
|
|
3
3
|
import { useAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
4
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
5
4
|
import ShortcutIcon from '@atlaskit/icon/glyph/shortcut';
|
|
6
5
|
import CopyIcon from '@atlaskit/icon/glyph/copy';
|
|
7
6
|
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
@@ -94,25 +93,23 @@ const HoverCardContent = ({
|
|
|
94
93
|
}
|
|
95
94
|
}, [analytics, linkStatus]);
|
|
96
95
|
useEffect(() => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
const previewDisplay = 'card';
|
|
97
|
+
const previewInvokeMethod = 'mouse_hover';
|
|
98
|
+
const cardOpenTime = Date.now();
|
|
99
|
+
analyticsRef.current.ui.hoverCardViewedEvent({
|
|
100
|
+
previewDisplay,
|
|
101
|
+
previewInvokeMethod,
|
|
102
|
+
status: statusRef.current
|
|
103
|
+
});
|
|
104
|
+
return () => {
|
|
105
|
+
const hoverTime = Date.now() - cardOpenTime;
|
|
106
|
+
analyticsRef.current.ui.hoverCardDismissedEvent({
|
|
102
107
|
previewDisplay,
|
|
103
108
|
previewInvokeMethod,
|
|
109
|
+
hoverTime,
|
|
104
110
|
status: statusRef.current
|
|
105
111
|
});
|
|
106
|
-
|
|
107
|
-
const hoverTime = Date.now() - cardOpenTime;
|
|
108
|
-
analyticsRef.current.ui.hoverCardDismissedEvent({
|
|
109
|
-
previewDisplay,
|
|
110
|
-
previewInvokeMethod,
|
|
111
|
-
hoverTime,
|
|
112
|
-
status: statusRef.current
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
}
|
|
112
|
+
};
|
|
116
113
|
}, []);
|
|
117
114
|
const onClick = useCallback(event => {
|
|
118
115
|
const isModifierKeyPressed = isSpecialEvent(event);
|
|
@@ -1,29 +1,18 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
/** @jsx jsx */
|
|
3
|
-
import {
|
|
2
|
+
import { withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
4
3
|
import { jsx } from '@emotion/react';
|
|
5
4
|
import { useCallback } from 'react';
|
|
6
5
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
7
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
8
6
|
import { useSmartLinkAnalytics } from '../../state/analytics';
|
|
9
|
-
import { fireSmartLinkEvent } from '../../utils/analytics';
|
|
10
7
|
import { HoverCardComponent } from './components/HoverCardComponent';
|
|
11
8
|
import { CardDisplay } from '../../constants';
|
|
12
9
|
const HoverCardWithErrorBoundary = props => {
|
|
13
10
|
const {
|
|
14
11
|
url,
|
|
15
12
|
id,
|
|
16
|
-
children
|
|
17
|
-
createAnalyticsEvent
|
|
13
|
+
children
|
|
18
14
|
} = props;
|
|
19
|
-
const
|
|
20
|
-
fireSmartLinkEvent(analyticsPayload, createAnalyticsEvent);
|
|
21
|
-
}, [createAnalyticsEvent]);
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Feature flag disables prop drilling of analytics handlers
|
|
25
|
-
*/
|
|
26
|
-
const analytics = useSmartLinkAnalytics(url, getBooleanFF('platform.linking-platform.smart-card.refactor-hover-card-analytics') ? undefined : analyticsHandler, id);
|
|
15
|
+
const analytics = useSmartLinkAnalytics(url, undefined, id);
|
|
27
16
|
const onError = useCallback((error, info) => {
|
|
28
17
|
analytics.ui.renderFailedEvent({
|
|
29
18
|
display: CardDisplay.HoverCardPreview,
|
|
@@ -32,29 +21,12 @@ const HoverCardWithErrorBoundary = props => {
|
|
|
32
21
|
errorInfo: info
|
|
33
22
|
});
|
|
34
23
|
}, [analytics.ui, id]);
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Feature flag disables the prop drilling of analytics handlers to hover card component
|
|
38
|
-
*/
|
|
39
|
-
const analyticsProps = getBooleanFF('platform.linking-platform.smart-card.refactor-hover-card-analytics') ? {} : {
|
|
40
|
-
analyticsHandler,
|
|
41
|
-
analytics
|
|
42
|
-
};
|
|
43
24
|
return jsx(ErrorBoundary, {
|
|
44
25
|
fallback: children,
|
|
45
26
|
onError: onError
|
|
46
|
-
}, jsx(HoverCardComponent,
|
|
27
|
+
}, jsx(HoverCardComponent, props, children));
|
|
47
28
|
};
|
|
48
|
-
const HoverCardWithAnalyticsContext = withAnalyticsContext({
|
|
49
|
-
source: 'smartLinkPreviewHoverCard',
|
|
50
|
-
attributes: {
|
|
51
|
-
display: CardDisplay.HoverCardPreview
|
|
52
|
-
}
|
|
53
|
-
})(withAnalyticsEvents()(HoverCardWithErrorBoundary));
|
|
54
29
|
const HoverCardWithoutAnalyticsContext = withAnalyticsEvents()(HoverCardWithErrorBoundary);
|
|
55
30
|
export const HoverCard = props => {
|
|
56
|
-
|
|
57
|
-
return jsx(HoverCardWithoutAnalyticsContext, props);
|
|
58
|
-
}
|
|
59
|
-
return jsx(HoverCardWithAnalyticsContext, props);
|
|
31
|
+
return jsx(HoverCardWithoutAnalyticsContext, props);
|
|
60
32
|
};
|