@atlaskit/smart-card 26.9.7 → 26.9.9

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 26.9.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [`4e254433494`](https://bitbucket.org/atlassian/atlassian-frontend/commits/4e254433494) - [ux] Remove 'open in new tab' button in Hover Cards
8
+
9
+ ## 26.9.8
10
+
11
+ ### Patch Changes
12
+
13
+ - [`4d66cb26fcb`](https://bitbucket.org/atlassian/atlassian-frontend/commits/4d66cb26fcb) - Bump jsdom to ^17.0.0
14
+ - [`2a6ebbbfdf1`](https://bitbucket.org/atlassian/atlassian-frontend/commits/2a6ebbbfdf1) - [ux] Hover Preview: Hide hover preview on scrolling (wheel event)
15
+ - Updated dependencies
16
+
3
17
  ## 26.9.7
4
18
 
5
19
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "26.9.7",
3
+ "version": "26.9.9",
4
4
  "sideEffects": false
5
5
  }
@@ -185,6 +185,7 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
185
185
  var hoverCardContentProps = {
186
186
  onMouseEnter: initShowCard,
187
187
  onMouseLeave: initHideCard,
188
+ onWheel: initHideCard,
188
189
  cardActions: filteredActions,
189
190
  cardState: linkState,
190
191
  onActionClick: onActionClick,
@@ -5,12 +5,11 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.hoverCardClassName = exports.getOpenAction = exports.getCopyAction = exports.default = void 0;
8
+ exports.hoverCardClassName = exports.getCopyAction = exports.default = void 0;
9
9
  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 _shortcut = _interopRequireDefault(require("@atlaskit/icon/glyph/shortcut"));
14
13
  var _copy = _interopRequireDefault(require("@atlaskit/icon/glyph/copy"));
15
14
  var _react2 = _interopRequireWildcard(require("react"));
16
15
  var _constants = require("../../../constants");
@@ -34,28 +33,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
34
33
 
35
34
  var hoverCardClassName = 'smart-links-hover-preview';
36
35
  exports.hoverCardClassName = hoverCardClassName;
37
- var getOpenAction = function getOpenAction(url, analytics, onActionClick) {
38
- return {
39
- name: _constants.ActionName.CustomAction,
40
- icon: (0, _react.jsx)(_shortcut.default, {
41
- label: "open in new tab",
42
- size: "medium"
43
- }),
44
- iconPosition: 'before',
45
- onClick: function onClick() {
46
- if (onActionClick) {
47
- onActionClick('open-content');
48
- }
49
- window.open(url, '_blank');
50
- analytics.ui.hoverCardOpenLinkClickedEvent({
51
- previewDisplay: 'card'
52
- });
53
- },
54
- tooltipMessage: (0, _react.jsx)(_reactIntlNext.FormattedMessage, _messages.messages.open_link_in_a_new_tab),
55
- testId: 'hover-card-open-button'
56
- };
57
- };
58
- exports.getOpenAction = getOpenAction;
59
36
  var getCopyAction = function getCopyAction(url) {
60
37
  return {
61
38
  name: _constants.ActionName.CustomAction,
@@ -103,6 +80,7 @@ var HoverCardContent = function HoverCardContent(_ref) {
103
80
  url = _ref.url,
104
81
  onMouseEnter = _ref.onMouseEnter,
105
82
  onMouseLeave = _ref.onMouseLeave,
83
+ onWheel = _ref.onWheel,
106
84
  showServerActions = _ref.showServerActions;
107
85
  var useLozengeAction = (0, _linkProvider.useFeatureFlag)('useLozengeAction');
108
86
  var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
@@ -116,6 +94,7 @@ var HoverCardContent = function HoverCardContent(_ref) {
116
94
  var linkStatus = (_linkState$status = linkState.status) !== null && _linkState$status !== void 0 ? _linkState$status : 'pending';
117
95
  var statusRef = (0, _react2.useRef)(linkStatus);
118
96
  var analyticsRef = (0, _react2.useRef)(analytics);
97
+ var wrapperRef = (0, _react2.useRef)(null);
119
98
  (0, _react2.useEffect)(function () {
120
99
  /**
121
100
  * Must access current analytics object value via ref because its not stable
@@ -147,6 +126,22 @@ var HoverCardContent = function HoverCardContent(_ref) {
147
126
  });
148
127
  };
149
128
  }, []);
129
+ (0, _react2.useEffect)(function () {
130
+ var wrapperRefValue = null;
131
+ if (wrapperRef.current && onWheel) {
132
+ // Detect wheel even on hover card content to close hover card
133
+ // Add event listener through ref because we want it to execute only once.
134
+ wrapperRef.current.addEventListener('wheel', onWheel, {
135
+ once: true
136
+ });
137
+ wrapperRefValue = wrapperRef.current;
138
+ }
139
+ return function () {
140
+ if (wrapperRefValue && onWheel) {
141
+ wrapperRefValue.removeEventListener('wheel', onWheel);
142
+ }
143
+ };
144
+ }, [onWheel]);
150
145
  var onClick = (0, _react2.useCallback)(function (event) {
151
146
  var isModifierKeyPressed = (0, _utils.isSpecialEvent)(event);
152
147
  analytics.ui.cardClickedEvent({
@@ -159,8 +154,8 @@ var HoverCardContent = function HoverCardContent(_ref) {
159
154
  (0, _click.fireLinkClickedEvent)(createAnalyticsEvent)(event);
160
155
  }, [createAnalyticsEvent, cardState.status, analytics.ui, id]);
161
156
  var titleActions = (0, _react2.useMemo)(function () {
162
- return [getCopyAction(url), getOpenAction(url, analytics, onActionClick)];
163
- }, [url, analytics, onActionClick]);
157
+ return [getCopyAction(url)];
158
+ }, [url]);
164
159
  var data = (_cardState$details = cardState.details) === null || _cardState$details === void 0 ? void 0 : _cardState$details.data;
165
160
  var _extractMetadata = (0, _extractMetadata2.extractMetadata)((0, _utils2.getSimulatedMetadata)(extensionKey, data)),
166
161
  subtitle = _extractMetadata.subtitle;
@@ -222,11 +217,13 @@ var HoverCardContent = function HoverCardContent(_ref) {
222
217
  };
223
218
  var cardView = getCardView(cardState);
224
219
  return cardView ? (0, _react.jsx)("div", {
220
+ "data-testid": "hover-card-content",
225
221
  onMouseEnter: onMouseEnter,
226
222
  onMouseLeave: onMouseLeave,
227
223
  onClick: onClickStopPropagation,
228
224
  className: hoverCardClassName,
229
- css: _styled.HoverCardContainer
225
+ css: _styled.HoverCardContainer,
226
+ ref: wrapperRef
230
227
  }, cardView) : null;
231
228
  };
232
229
  var _default = HoverCardContent;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "26.9.7",
3
+ "version": "26.9.9",
4
4
  "sideEffects": false
5
5
  }
@@ -160,6 +160,7 @@ export const HoverCardComponent = ({
160
160
  const hoverCardContentProps = {
161
161
  onMouseEnter: initShowCard,
162
162
  onMouseLeave: initHideCard,
163
+ onWheel: initHideCard,
163
164
  cardActions: filteredActions,
164
165
  cardState: linkState,
165
166
  onActionClick,
@@ -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 ShortcutIcon from '@atlaskit/icon/glyph/shortcut';
5
4
  import CopyIcon from '@atlaskit/icon/glyph/copy';
6
5
  import React, { useCallback, useEffect, useMemo, useRef } from 'react';
7
6
  import { ActionName, CardDisplay, SmartLinkPosition, SmartLinkSize } from '../../../constants';
@@ -20,25 +19,6 @@ import { fireLinkClickedEvent } from '../../../utils/analytics/click';
20
19
  import { useSmartCardState } from '../../../state/store';
21
20
  import { useFeatureFlag } from '@atlaskit/link-provider';
22
21
  export const hoverCardClassName = 'smart-links-hover-preview';
23
- export const getOpenAction = (url, analytics, onActionClick) => ({
24
- name: ActionName.CustomAction,
25
- icon: jsx(ShortcutIcon, {
26
- label: "open in new tab",
27
- size: "medium"
28
- }),
29
- iconPosition: 'before',
30
- onClick: () => {
31
- if (onActionClick) {
32
- onActionClick('open-content');
33
- }
34
- window.open(url, '_blank');
35
- analytics.ui.hoverCardOpenLinkClickedEvent({
36
- previewDisplay: 'card'
37
- });
38
- },
39
- tooltipMessage: jsx(FormattedMessage, messages.open_link_in_a_new_tab),
40
- testId: 'hover-card-open-button'
41
- });
42
22
  export const getCopyAction = url => ({
43
23
  name: ActionName.CustomAction,
44
24
  icon: jsx(CopyIcon, {
@@ -61,6 +41,7 @@ const HoverCardContent = ({
61
41
  url,
62
42
  onMouseEnter,
63
43
  onMouseLeave,
44
+ onWheel,
64
45
  showServerActions
65
46
  }) => {
66
47
  var _linkState$status, _cardState$details;
@@ -75,6 +56,7 @@ const HoverCardContent = ({
75
56
  const linkStatus = (_linkState$status = linkState.status) !== null && _linkState$status !== void 0 ? _linkState$status : 'pending';
76
57
  const statusRef = useRef(linkStatus);
77
58
  const analyticsRef = useRef(analytics);
59
+ const wrapperRef = useRef(null);
78
60
  useEffect(() => {
79
61
  /**
80
62
  * Must access current analytics object value via ref because its not stable
@@ -106,6 +88,22 @@ const HoverCardContent = ({
106
88
  });
107
89
  };
108
90
  }, []);
91
+ useEffect(() => {
92
+ let wrapperRefValue = null;
93
+ if (wrapperRef.current && onWheel) {
94
+ // Detect wheel even on hover card content to close hover card
95
+ // Add event listener through ref because we want it to execute only once.
96
+ wrapperRef.current.addEventListener('wheel', onWheel, {
97
+ once: true
98
+ });
99
+ wrapperRefValue = wrapperRef.current;
100
+ }
101
+ return () => {
102
+ if (wrapperRefValue && onWheel) {
103
+ wrapperRefValue.removeEventListener('wheel', onWheel);
104
+ }
105
+ };
106
+ }, [onWheel]);
109
107
  const onClick = useCallback(event => {
110
108
  const isModifierKeyPressed = isSpecialEvent(event);
111
109
  analytics.ui.cardClickedEvent({
@@ -117,7 +115,7 @@ const HoverCardContent = ({
117
115
  });
118
116
  fireLinkClickedEvent(createAnalyticsEvent)(event);
119
117
  }, [createAnalyticsEvent, cardState.status, analytics.ui, id]);
120
- const titleActions = useMemo(() => [getCopyAction(url), getOpenAction(url, analytics, onActionClick)], [url, analytics, onActionClick]);
118
+ const titleActions = useMemo(() => [getCopyAction(url)], [url]);
121
119
  const data = (_cardState$details = cardState.details) === null || _cardState$details === void 0 ? void 0 : _cardState$details.data;
122
120
  const {
123
121
  subtitle
@@ -178,11 +176,13 @@ const HoverCardContent = ({
178
176
  };
179
177
  const cardView = getCardView(cardState);
180
178
  return cardView ? jsx("div", {
179
+ "data-testid": "hover-card-content",
181
180
  onMouseEnter: onMouseEnter,
182
181
  onMouseLeave: onMouseLeave,
183
182
  onClick: onClickStopPropagation,
184
183
  className: hoverCardClassName,
185
- css: HoverCardContainer
184
+ css: HoverCardContainer,
185
+ ref: wrapperRef
186
186
  }, cardView) : null;
187
187
  };
188
188
  export default HoverCardContent;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "26.9.7",
3
+ "version": "26.9.9",
4
4
  "sideEffects": false
5
5
  }
@@ -174,6 +174,7 @@ export var HoverCardComponent = function HoverCardComponent(_ref) {
174
174
  var hoverCardContentProps = {
175
175
  onMouseEnter: initShowCard,
176
176
  onMouseLeave: initHideCard,
177
+ onWheel: initHideCard,
177
178
  cardActions: filteredActions,
178
179
  cardState: linkState,
179
180
  onActionClick: onActionClick,
@@ -3,7 +3,6 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  /** @jsx jsx */
4
4
  import { jsx } from '@emotion/react';
5
5
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
6
- import ShortcutIcon from '@atlaskit/icon/glyph/shortcut';
7
6
  import CopyIcon from '@atlaskit/icon/glyph/copy';
8
7
  import React, { useCallback, useEffect, useMemo, useRef } from 'react';
9
8
  import { ActionName, CardDisplay, SmartLinkPosition, SmartLinkSize } from '../../../constants';
@@ -22,27 +21,6 @@ import { fireLinkClickedEvent } from '../../../utils/analytics/click';
22
21
  import { useSmartCardState } from '../../../state/store';
23
22
  import { useFeatureFlag } from '@atlaskit/link-provider';
24
23
  export var hoverCardClassName = 'smart-links-hover-preview';
25
- export var getOpenAction = function getOpenAction(url, analytics, onActionClick) {
26
- return {
27
- name: ActionName.CustomAction,
28
- icon: jsx(ShortcutIcon, {
29
- label: "open in new tab",
30
- size: "medium"
31
- }),
32
- iconPosition: 'before',
33
- onClick: function onClick() {
34
- if (onActionClick) {
35
- onActionClick('open-content');
36
- }
37
- window.open(url, '_blank');
38
- analytics.ui.hoverCardOpenLinkClickedEvent({
39
- previewDisplay: 'card'
40
- });
41
- },
42
- tooltipMessage: jsx(FormattedMessage, messages.open_link_in_a_new_tab),
43
- testId: 'hover-card-open-button'
44
- };
45
- };
46
24
  export var getCopyAction = function getCopyAction(url) {
47
25
  return {
48
26
  name: ActionName.CustomAction,
@@ -89,6 +67,7 @@ var HoverCardContent = function HoverCardContent(_ref) {
89
67
  url = _ref.url,
90
68
  onMouseEnter = _ref.onMouseEnter,
91
69
  onMouseLeave = _ref.onMouseLeave,
70
+ onWheel = _ref.onWheel,
92
71
  showServerActions = _ref.showServerActions;
93
72
  var useLozengeAction = useFeatureFlag('useLozengeAction');
94
73
  var _useAnalyticsEvents = useAnalyticsEvents(),
@@ -102,6 +81,7 @@ var HoverCardContent = function HoverCardContent(_ref) {
102
81
  var linkStatus = (_linkState$status = linkState.status) !== null && _linkState$status !== void 0 ? _linkState$status : 'pending';
103
82
  var statusRef = useRef(linkStatus);
104
83
  var analyticsRef = useRef(analytics);
84
+ var wrapperRef = useRef(null);
105
85
  useEffect(function () {
106
86
  /**
107
87
  * Must access current analytics object value via ref because its not stable
@@ -133,6 +113,22 @@ var HoverCardContent = function HoverCardContent(_ref) {
133
113
  });
134
114
  };
135
115
  }, []);
116
+ useEffect(function () {
117
+ var wrapperRefValue = null;
118
+ if (wrapperRef.current && onWheel) {
119
+ // Detect wheel even on hover card content to close hover card
120
+ // Add event listener through ref because we want it to execute only once.
121
+ wrapperRef.current.addEventListener('wheel', onWheel, {
122
+ once: true
123
+ });
124
+ wrapperRefValue = wrapperRef.current;
125
+ }
126
+ return function () {
127
+ if (wrapperRefValue && onWheel) {
128
+ wrapperRefValue.removeEventListener('wheel', onWheel);
129
+ }
130
+ };
131
+ }, [onWheel]);
136
132
  var onClick = useCallback(function (event) {
137
133
  var isModifierKeyPressed = isSpecialEvent(event);
138
134
  analytics.ui.cardClickedEvent({
@@ -145,8 +141,8 @@ var HoverCardContent = function HoverCardContent(_ref) {
145
141
  fireLinkClickedEvent(createAnalyticsEvent)(event);
146
142
  }, [createAnalyticsEvent, cardState.status, analytics.ui, id]);
147
143
  var titleActions = useMemo(function () {
148
- return [getCopyAction(url), getOpenAction(url, analytics, onActionClick)];
149
- }, [url, analytics, onActionClick]);
144
+ return [getCopyAction(url)];
145
+ }, [url]);
150
146
  var data = (_cardState$details = cardState.details) === null || _cardState$details === void 0 ? void 0 : _cardState$details.data;
151
147
  var _extractMetadata = extractMetadata(getSimulatedMetadata(extensionKey, data)),
152
148
  subtitle = _extractMetadata.subtitle;
@@ -208,11 +204,13 @@ var HoverCardContent = function HoverCardContent(_ref) {
208
204
  };
209
205
  var cardView = getCardView(cardState);
210
206
  return cardView ? jsx("div", {
207
+ "data-testid": "hover-card-content",
211
208
  onMouseEnter: onMouseEnter,
212
209
  onMouseLeave: onMouseLeave,
213
210
  onClick: onClickStopPropagation,
214
211
  className: hoverCardClassName,
215
- css: HoverCardContainer
212
+ css: HoverCardContainer,
213
+ ref: wrapperRef
216
214
  }, cardView) : null;
217
215
  };
218
216
  export default HoverCardContent;
@@ -1,9 +1,7 @@
1
1
  import React from 'react';
2
- import { AnalyticsFacade } from '../../../state/analytics';
3
2
  import { ActionItem } from '../../FlexibleCard/components/blocks/types';
4
3
  import { HoverCardContentProps } from '../types';
5
4
  export declare const hoverCardClassName = "smart-links-hover-preview";
6
- export declare const getOpenAction: (url: string, analytics: AnalyticsFacade, onActionClick?: ((actionId: string) => void) | undefined) => ActionItem;
7
5
  export declare const getCopyAction: (url: string) => ActionItem;
8
6
  declare const HoverCardContent: React.FC<HoverCardContentProps>;
9
7
  export default HoverCardContent;
@@ -5,7 +5,7 @@ import { LinkAction } from '../../state/hooks-external/useSmartLinkActions';
5
5
  import { CardState } from '@atlaskit/linking-common';
6
6
  import { AnalyticsHandler } from '../../utils/types';
7
7
  import { CardProviderRenderers } from '@atlaskit/link-provider';
8
- import { ReactElement, MouseEventHandler } from 'react';
8
+ import { MouseEventHandler, ReactElement } from 'react';
9
9
  import { JsonLd } from 'json-ld-types';
10
10
  export interface HoverCardProps extends WithAnalyticsEventsProps {
11
11
  /**
@@ -80,6 +80,7 @@ export type HoverCardContentProps = {
80
80
  url: string;
81
81
  onMouseEnter?: MouseEventHandler;
82
82
  onMouseLeave?: MouseEventHandler;
83
+ onWheel?: EventListenerOrEventListenerObject;
83
84
  showServerActions?: boolean;
84
85
  };
85
86
  export type SnippetOrPreviewProps = {
@@ -1,9 +1,7 @@
1
1
  import React from 'react';
2
- import { AnalyticsFacade } from '../../../state/analytics';
3
2
  import { ActionItem } from '../../FlexibleCard/components/blocks/types';
4
3
  import { HoverCardContentProps } from '../types';
5
4
  export declare const hoverCardClassName = "smart-links-hover-preview";
6
- export declare const getOpenAction: (url: string, analytics: AnalyticsFacade, onActionClick?: ((actionId: string) => void) | undefined) => ActionItem;
7
5
  export declare const getCopyAction: (url: string) => ActionItem;
8
6
  declare const HoverCardContent: React.FC<HoverCardContentProps>;
9
7
  export default HoverCardContent;
@@ -5,7 +5,7 @@ import { LinkAction } from '../../state/hooks-external/useSmartLinkActions';
5
5
  import { CardState } from '@atlaskit/linking-common';
6
6
  import { AnalyticsHandler } from '../../utils/types';
7
7
  import { CardProviderRenderers } from '@atlaskit/link-provider';
8
- import { ReactElement, MouseEventHandler } from 'react';
8
+ import { MouseEventHandler, ReactElement } from 'react';
9
9
  import { JsonLd } from 'json-ld-types';
10
10
  export interface HoverCardProps extends WithAnalyticsEventsProps {
11
11
  /**
@@ -80,6 +80,7 @@ export type HoverCardContentProps = {
80
80
  url: string;
81
81
  onMouseEnter?: MouseEventHandler;
82
82
  onMouseLeave?: MouseEventHandler;
83
+ onWheel?: EventListenerOrEventListenerObject;
83
84
  showServerActions?: boolean;
84
85
  };
85
86
  export type SnippetOrPreviewProps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "26.9.7",
3
+ "version": "26.9.9",
4
4
  "description": "Smart card component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -48,7 +48,7 @@
48
48
  "@atlaskit/popup": "^1.8.0",
49
49
  "@atlaskit/spinner": "^15.5.0",
50
50
  "@atlaskit/theme": "^12.5.0",
51
- "@atlaskit/tokens": "^1.11.0",
51
+ "@atlaskit/tokens": "^1.12.0",
52
52
  "@atlaskit/tooltip": "^17.8.0",
53
53
  "@atlaskit/ufo": "^0.2.0",
54
54
  "@babel/runtime": "^7.0.0",
@@ -95,7 +95,7 @@
95
95
  "fetch-mock": "^8.0.0",
96
96
  "jest-emotion": "^10.0.32",
97
97
  "jest-extended": "^0.11.2",
98
- "jsdom": "^16.2.2",
98
+ "jsdom": "^17.0.0",
99
99
  "lorem-ipsum": "^1.0.6",
100
100
  "react": "^16.8.0",
101
101
  "react-ace": "^6.1.0",