@atlaskit/smart-card 26.49.0 → 26.49.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/state/hooks/use-ai-summary/ai-summary-service/index.js +39 -27
  3. package/dist/cjs/state/hooks/use-ai-summary/index.js +16 -38
  4. package/dist/cjs/utils/analytics/analytics.js +1 -1
  5. package/dist/cjs/view/FlexibleCard/components/blocks/ai-summary-block/resolved/index.js +37 -29
  6. package/dist/cjs/view/HoverCard/components/ContentContainer.js +42 -13
  7. package/dist/cjs/view/HoverCard/components/HoverCardContent.js +1 -10
  8. package/dist/cjs/view/HoverCard/components/views/resolved/index.js +63 -16
  9. package/dist/cjs/view/LinkUrl/index.js +1 -1
  10. package/dist/cjs/view/common/ai-summary/index.js +9 -3
  11. package/dist/es2019/state/hooks/use-ai-summary/ai-summary-service/index.js +14 -5
  12. package/dist/es2019/state/hooks/use-ai-summary/index.js +17 -35
  13. package/dist/es2019/utils/analytics/analytics.js +1 -1
  14. package/dist/es2019/view/FlexibleCard/components/blocks/ai-summary-block/resolved/index.js +33 -26
  15. package/dist/es2019/view/HoverCard/components/ContentContainer.js +35 -10
  16. package/dist/es2019/view/HoverCard/components/HoverCardContent.js +2 -7
  17. package/dist/es2019/view/HoverCard/components/views/resolved/index.js +56 -7
  18. package/dist/es2019/view/LinkUrl/index.js +1 -1
  19. package/dist/es2019/view/common/ai-summary/index.js +7 -3
  20. package/dist/esm/state/hooks/use-ai-summary/ai-summary-service/index.js +39 -27
  21. package/dist/esm/state/hooks/use-ai-summary/index.js +17 -39
  22. package/dist/esm/utils/analytics/analytics.js +1 -1
  23. package/dist/esm/view/FlexibleCard/components/blocks/ai-summary-block/resolved/index.js +38 -30
  24. package/dist/esm/view/HoverCard/components/ContentContainer.js +39 -13
  25. package/dist/esm/view/HoverCard/components/HoverCardContent.js +2 -11
  26. package/dist/esm/view/HoverCard/components/views/resolved/index.js +66 -18
  27. package/dist/esm/view/LinkUrl/index.js +1 -1
  28. package/dist/esm/view/common/ai-summary/index.js +9 -3
  29. package/dist/types/state/hooks/use-ai-summary/ai-summary-service/types.d.ts +3 -1
  30. package/dist/types/state/hooks/use-ai-summary/index.d.ts +0 -1
  31. package/dist/types/view/FlexibleCard/components/blocks/ai-summary-block/ai-state-indicator/types.d.ts +2 -2
  32. package/dist/types/view/FlexibleCard/components/blocks/ai-summary-block/types.d.ts +2 -3
  33. package/dist/types/view/HoverCard/components/views/resolved/types.d.ts +0 -2
  34. package/dist/types/view/HoverCard/types.d.ts +1 -1
  35. package/dist/types/view/common/ai-summary/index.d.ts +4 -0
  36. package/dist/types-ts4.5/state/hooks/use-ai-summary/ai-summary-service/types.d.ts +3 -1
  37. package/dist/types-ts4.5/state/hooks/use-ai-summary/index.d.ts +0 -1
  38. package/dist/types-ts4.5/view/FlexibleCard/components/blocks/ai-summary-block/ai-state-indicator/types.d.ts +2 -2
  39. package/dist/types-ts4.5/view/FlexibleCard/components/blocks/ai-summary-block/types.d.ts +2 -3
  40. package/dist/types-ts4.5/view/HoverCard/components/views/resolved/types.d.ts +0 -2
  41. package/dist/types-ts4.5/view/HoverCard/types.d.ts +1 -1
  42. package/dist/types-ts4.5/view/common/ai-summary/index.d.ts +4 -0
  43. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 26.49.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#78725](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/78725) [`9eec85250f70`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9eec85250f70) - Hover Card: AI Summary UI controlled by aiSummary hook
8
+ - Updated dependencies
9
+
3
10
  ## 26.49.0
4
11
 
5
12
  ### Minor Changes
@@ -51,8 +51,14 @@ var AISummaryService = exports.AISummaryService = /*#__PURE__*/function () {
51
51
  return fetch(requestUrl, options);
52
52
  case 6:
53
53
  response = _context.sent;
54
+ if (!(!response.ok || response.status >= 400)) {
55
+ _context.next = 11;
56
+ break;
57
+ }
58
+ throw new Error("Status: ".concat(response.status, "\n URL: ").concat(_this.url, "\n StatusText ").concat(response.statusText));
59
+ case 11:
54
60
  return _context.abrupt("return", (0, _utils.readStream)(response));
55
- case 8:
61
+ case 12:
56
62
  case "end":
57
63
  return _context.stop();
58
64
  }
@@ -103,10 +109,11 @@ var AISummaryService = exports.AISummaryService = /*#__PURE__*/function () {
103
109
  return _regenerator.default.wrap(function _callee2$(_context2) {
104
110
  while (1) switch (_context2.prev = _context2.next) {
105
111
  case 0:
106
- summaryStyle = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : 'short';
107
- this.state = _objectSpread(_objectSpread({}, this.state), {}, {
108
- status: 'loading'
109
- });
112
+ summaryStyle = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : 'medium';
113
+ this.state = {
114
+ status: 'loading',
115
+ content: ''
116
+ };
110
117
  _iterator2 = _createForOfIteratorHelper(this.subscribedStateSetters);
111
118
  try {
112
119
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
@@ -133,7 +140,7 @@ var AISummaryService = exports.AISummaryService = /*#__PURE__*/function () {
133
140
  return _iterator.next();
134
141
  case 15:
135
142
  if (!(_iteratorAbruptCompletion = !(_step = _context2.sent).done)) {
136
- _context2.next = 21;
143
+ _context2.next = 22;
137
144
  break;
138
145
  }
139
146
  chunk = _step.value;
@@ -153,53 +160,58 @@ var AISummaryService = exports.AISummaryService = /*#__PURE__*/function () {
153
160
  _iterator3.f();
154
161
  }
155
162
  }
156
- case 18:
163
+
164
+ //if AI Mate service returns cached summary we get the summary text in one piece as the last message
165
+ if (chunk.type === 'FINAL_RESPONSE') {
166
+ bufferContent = chunk.message.message.content;
167
+ }
168
+ case 19:
157
169
  _iteratorAbruptCompletion = false;
158
170
  _context2.next = 13;
159
171
  break;
160
- case 21:
161
- _context2.next = 27;
172
+ case 22:
173
+ _context2.next = 28;
162
174
  break;
163
- case 23:
164
- _context2.prev = 23;
175
+ case 24:
176
+ _context2.prev = 24;
165
177
  _context2.t0 = _context2["catch"](11);
166
178
  _didIteratorError = true;
167
179
  _iteratorError = _context2.t0;
168
- case 27:
169
- _context2.prev = 27;
180
+ case 28:
170
181
  _context2.prev = 28;
182
+ _context2.prev = 29;
171
183
  if (!(_iteratorAbruptCompletion && _iterator.return != null)) {
172
- _context2.next = 32;
184
+ _context2.next = 33;
173
185
  break;
174
186
  }
175
- _context2.next = 32;
187
+ _context2.next = 33;
176
188
  return _iterator.return();
177
- case 32:
178
- _context2.prev = 32;
189
+ case 33:
190
+ _context2.prev = 33;
179
191
  if (!_didIteratorError) {
180
- _context2.next = 35;
192
+ _context2.next = 36;
181
193
  break;
182
194
  }
183
195
  throw _iteratorError;
184
- case 35:
185
- return _context2.finish(32);
186
196
  case 36:
187
- return _context2.finish(27);
197
+ return _context2.finish(33);
188
198
  case 37:
199
+ return _context2.finish(28);
200
+ case 38:
189
201
  this.state = {
190
202
  status: 'done',
191
203
  content: bufferContent
192
204
  };
193
- _context2.next = 43;
205
+ _context2.next = 44;
194
206
  break;
195
- case 40:
196
- _context2.prev = 40;
207
+ case 41:
208
+ _context2.prev = 41;
197
209
  _context2.t1 = _context2["catch"](4);
198
210
  this.state = {
199
211
  status: 'error',
200
212
  content: ''
201
213
  };
202
- case 43:
214
+ case 44:
203
215
  _iterator4 = _createForOfIteratorHelper(this.subscribedStateSetters);
204
216
  try {
205
217
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
@@ -211,11 +223,11 @@ var AISummaryService = exports.AISummaryService = /*#__PURE__*/function () {
211
223
  } finally {
212
224
  _iterator4.f();
213
225
  }
214
- case 45:
226
+ case 46:
215
227
  case "end":
216
228
  return _context2.stop();
217
229
  }
218
- }, _callee2, this, [[4, 40], [11, 23, 27, 37], [28,, 32, 36]]);
230
+ }, _callee2, this, [[4, 41], [11, 24, 28, 38], [29,, 33, 37]]);
219
231
  }));
220
232
  function summariseUrl() {
221
233
  return _summariseUrl.apply(this, arguments);
@@ -13,8 +13,8 @@ var useAISummary = exports.useAISummary = function useAISummary(props) {
13
13
  var _AISummariesStore$get;
14
14
  var url = props.url,
15
15
  baseUrl = props.baseUrl,
16
- product = props.product,
17
- headers = props.headers;
16
+ headers = props.headers,
17
+ product = props.product;
18
18
  var _useState = (0, _react.useState)(((_AISummariesStore$get = _store.AISummariesStore.get(url)) === null || _AISummariesStore$get === void 0 ? void 0 : _AISummariesStore$get.state) || {
19
19
  status: 'ready',
20
20
  content: ''
@@ -22,47 +22,25 @@ var useAISummary = exports.useAISummary = function useAISummary(props) {
22
22
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
23
23
  state = _useState2[0],
24
24
  setState = _useState2[1];
25
-
26
- // Can be used to know the summary status upon mounting a component (HoverCard UI state for example).
27
- // For other scenarios, opt for dynamic status updates via state.status.
28
- var isSummarisedOnMount = (0, _react.useMemo)(function () {
29
- var _AISummariesStore$get2;
30
- return ((_AISummariesStore$get2 = _store.AISummariesStore.get(url)) === null || _AISummariesStore$get2 === void 0 ? void 0 : _AISummariesStore$get2.state.status) === 'done';
31
- }, [url]);
32
25
  (0, _react.useEffect)(function () {
33
- // Create or subscribe to an AI service only if a summary has not been previously generated.
34
- // Otherwise, use the data from the current state synchronized with a cache (AISummariesStore).
35
- if (!isSummarisedOnMount) {
36
- var aISummaryService = _store.AISummariesStore.get(url);
37
- var isAISummaryServiceInitiated = !!aISummaryService;
38
- if (isAISummaryServiceInitiated) {
39
- //if we want to subscribe to updates from an existing AI service that has not yet provided a summary or is currently in progress.
40
- var unsubscribe = aISummaryService.subscribe(setState);
41
- return function () {
42
- return unsubscribe();
43
- };
44
- } else {
45
- var _AISummariesStore$get3;
46
- //if we want to create a new AI service and wish to subscribe for updates
47
- _store.AISummariesStore.set(url, new _aiSummaryService.AISummaryService({
48
- url: url,
49
- baseUrl: baseUrl,
50
- product: product,
51
- headers: headers
52
- }));
53
- var _unsubscribe = (_AISummariesStore$get3 = _store.AISummariesStore.get(url)) === null || _AISummariesStore$get3 === void 0 ? void 0 : _AISummariesStore$get3.subscribe(setState);
54
- return function () {
55
- return _unsubscribe && _unsubscribe();
56
- };
57
- }
26
+ var _AISummariesStore$get2;
27
+ if (!_store.AISummariesStore.get(url)) {
28
+ _store.AISummariesStore.set(url, new _aiSummaryService.AISummaryService({
29
+ url: url,
30
+ baseUrl: baseUrl,
31
+ headers: headers,
32
+ product: product
33
+ }));
58
34
  }
59
- }, [isSummarisedOnMount, url, baseUrl, product, headers]);
35
+
36
+ //returns function that calls unsubscribe method
37
+ return (_AISummariesStore$get2 = _store.AISummariesStore.get(url)) === null || _AISummariesStore$get2 === void 0 ? void 0 : _AISummariesStore$get2.subscribe(setState);
38
+ }, [url, baseUrl, headers, product]);
60
39
  var summariseUrl = function summariseUrl() {
61
- var _AISummariesStore$get4;
62
- return (_AISummariesStore$get4 = _store.AISummariesStore.get(url)) === null || _AISummariesStore$get4 === void 0 ? void 0 : _AISummariesStore$get4.summariseUrl();
40
+ var _AISummariesStore$get3;
41
+ return (_AISummariesStore$get3 = _store.AISummariesStore.get(url)) === null || _AISummariesStore$get3 === void 0 ? void 0 : _AISummariesStore$get3.summariseUrl();
63
42
  };
64
43
  return {
65
- isSummarisedOnMount: isSummarisedOnMount,
66
44
  summariseUrl: summariseUrl,
67
45
  state: state
68
46
  };
@@ -22,7 +22,7 @@ var ANALYTICS_CHANNEL = exports.ANALYTICS_CHANNEL = 'media';
22
22
  var context = exports.context = {
23
23
  componentName: 'smart-cards',
24
24
  packageName: "@atlaskit/smart-card",
25
- packageVersion: "26.49.0"
25
+ packageVersion: "26.49.1"
26
26
  };
27
27
  var TrackQuickActionType = exports.TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
28
28
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -33,39 +33,46 @@ var AISummaryBlockResolvedView = function AISummaryBlockResolvedView(props) {
33
33
  actions = _props$actions === void 0 ? [] : _props$actions,
34
34
  metadata = props.metadata,
35
35
  onActionMenuOpenChange = props.onActionMenuOpenChange,
36
- onAIActionChange = props.onAIActionChange,
37
36
  _props$size = props.size,
38
37
  size = _props$size === void 0 ? _constants.SmartLinkSize.Medium : _props$size,
39
- testId = props.testId;
40
- var _useState = (0, _react.useState)('ready'),
41
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
42
- aiState = _useState2[0],
43
- setAIState = _useState2[1];
38
+ testId = props.testId,
39
+ aiSummaryMinHeight = props.aiSummaryMinHeight;
40
+ var metadataElements = (0, _utils.renderElementItems)(metadata);
44
41
  var _useAnalyticsEvents = (0, _useAnalyticsEvents2.useAnalyticsEvents)(),
45
42
  fireEvent = _useAnalyticsEvents.fireEvent;
46
- var metadataElements = (0, _utils.renderElementItems)(metadata);
47
43
  var context = (0, _flexibleUiContext.useFlexibleUiContext)();
48
44
  var url = (context === null || context === void 0 ? void 0 : context.url) || '';
49
- var aiSummary = (0, _useAiSummary.useAISummary)({
50
- url: url
51
- });
52
- var _aiSummary$state = aiSummary.state,
53
- content = _aiSummary$state.content,
54
- status = _aiSummary$state.status,
55
- isSummarisedOnMount = aiSummary.isSummarisedOnMount;
56
- var onAIActionClick = (0, _react.useCallback)(function () {
57
- fireEvent('ui.button.clicked.aiSummary', {});
58
- setAIState('loading');
59
- if (onAIActionChange) {
60
- onAIActionChange('loading');
45
+ var _useAISummary = (0, _useAiSummary.useAISummary)({
46
+ url: url
47
+ }),
48
+ summariseUrl = _useAISummary.summariseUrl,
49
+ _useAISummary$state = _useAISummary.state,
50
+ content = _useAISummary$state.content,
51
+ status = _useAISummary$state.status;
52
+ var showAISummary = status !== 'ready' && status !== 'error';
53
+ var isSummarisedOnMountRef = (0, _react.useRef)(status === 'done');
54
+ var isErroredOnMountRef = (0, _react.useRef)(status === 'error');
55
+ var _useState = (0, _react.useState)(false),
56
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
57
+ showAISummaryErrorMessage = _useState2[0],
58
+ setShowAISummaryErrorMessage = _useState2[1];
59
+ (0, _react.useEffect)(function () {
60
+ if (isErroredOnMountRef.current && status === 'loading') {
61
+ isErroredOnMountRef.current = false;
62
+ setShowAISummaryErrorMessage(true);
63
+ } else {
64
+ setShowAISummaryErrorMessage(!isErroredOnMountRef.current && status === 'error');
61
65
  }
62
- }, [onAIActionChange, fireEvent]);
66
+ }, [status]);
63
67
  var combinedActions = (0, _react.useMemo)(function () {
64
- if (aiState === 'ready') {
68
+ if (status === 'ready' || status === 'error') {
65
69
  var aiAction = {
66
70
  content: /*#__PURE__*/_react.default.createElement(_reactIntlNext.FormattedMessage, _messages.messages.ai_summarize),
67
71
  name: _constants.ActionName.CustomAction,
68
- onClick: onAIActionClick,
72
+ onClick: function onClick() {
73
+ fireEvent('ui.button.clicked.aiSummary', {});
74
+ summariseUrl();
75
+ },
69
76
  testId: "".concat(testId, "-ai-summary-action"),
70
77
  icon: /*#__PURE__*/_react.default.createElement(_aiIcon.default, {
71
78
  label: "AIIcon"
@@ -74,7 +81,7 @@ var AISummaryBlockResolvedView = function AISummaryBlockResolvedView(props) {
74
81
  return [aiAction].concat((0, _toConsumableArray2.default)(actions));
75
82
  }
76
83
  return actions;
77
- }, [actions, aiState, onAIActionClick, testId]);
84
+ }, [actions, status, testId, summariseUrl, fireEvent]);
78
85
  var onDropdownOpenChange = (0, _react.useCallback)(function (isOpen) {
79
86
  if (onActionMenuOpenChange) {
80
87
  onActionMenuOpenChange({
@@ -86,17 +93,18 @@ var AISummaryBlockResolvedView = function AISummaryBlockResolvedView(props) {
86
93
  direction: _constants.SmartLinkDirection.Vertical,
87
94
  testId: "".concat(testId, "-resolved-view")
88
95
  }), status === 'done' && /*#__PURE__*/_react.default.createElement(_aiEventSummaryViewed.default, {
89
- fromCache: isSummarisedOnMount
90
- }), /*#__PURE__*/_react.default.createElement(_aiSummary.default, {
96
+ fromCache: isSummarisedOnMountRef.current
97
+ }), showAISummary && /*#__PURE__*/_react.default.createElement(_aiSummary.default, {
98
+ minHeight: aiSummaryMinHeight,
91
99
  content: content,
92
- showIcon: isSummarisedOnMount
100
+ showIcon: isSummarisedOnMountRef.current
93
101
  }), /*#__PURE__*/_react.default.createElement(_primitives.Inline, {
94
102
  alignBlock: "center",
95
103
  alignInline: "end",
96
104
  grow: "fill",
97
105
  spread: "space-between"
98
- }, /*#__PURE__*/_react.default.createElement(_primitives.Box, null, !isSummarisedOnMount && (aiState === 'loading' || aiState === 'done') ? /*#__PURE__*/_react.default.createElement(_aiStateIndicator.default, {
99
- state: aiState,
106
+ }, /*#__PURE__*/_react.default.createElement(_primitives.Box, null, !isSummarisedOnMountRef.current && (status === 'loading' || status === 'done') ? /*#__PURE__*/_react.default.createElement(_aiStateIndicator.default, {
107
+ state: status,
100
108
  testId: "".concat(testId, "-state-indicator")
101
109
  }) : /*#__PURE__*/_react.default.createElement(_elementGroup.default, {
102
110
  width: _constants.SmartLinkWidth.FitToContent,
@@ -106,7 +114,7 @@ var AISummaryBlockResolvedView = function AISummaryBlockResolvedView(props) {
106
114
  items: combinedActions,
107
115
  appearance: "default",
108
116
  size: size
109
- }))), status === 'error' && /*#__PURE__*/_react.default.createElement(_primitives.Inline, {
117
+ }))), showAISummaryErrorMessage && /*#__PURE__*/_react.default.createElement(_primitives.Inline, {
110
118
  grow: "fill"
111
119
  }, /*#__PURE__*/_react.default.createElement(_aiEventErrorViewed.default, null), /*#__PURE__*/_react.default.createElement(_aiStateIndicator.default, {
112
120
  state: status,
@@ -1,38 +1,67 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.default = void 0;
8
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
11
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
12
  var _react = require("@emotion/react");
11
- var _react2 = _interopRequireDefault(require("react"));
13
+ var _react2 = _interopRequireWildcard(require("react"));
12
14
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
15
  var _styled = require("../styled");
14
16
  var _aiPrism = _interopRequireDefault(require("../../common/ai-prism"));
15
17
  var _HoverCardContent = require("./HoverCardContent");
16
- var _excluded = ["children", "isAIEnabled", "showPrism", "testId"];
18
+ var _useAiSummary = require("../../../state/hooks/use-ai-summary");
19
+ var _excluded = ["children", "isAIEnabled", "testId", "url"],
20
+ _excluded2 = ["children", "isAIEnabled", "testId", "url"];
17
21
  /** @jsx jsx */
18
- var ContentContainer = function ContentContainer(_ref) {
22
+ 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); }
23
+ 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 && Object.prototype.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; }
24
+ var ConnectedAIPrismContainer = function ConnectedAIPrismContainer(_ref) {
19
25
  var children = _ref.children,
20
26
  _ref$isAIEnabled = _ref.isAIEnabled,
21
27
  isAIEnabled = _ref$isAIEnabled === void 0 ? false : _ref$isAIEnabled,
22
- _ref$showPrism = _ref.showPrism,
23
- showPrism = _ref$showPrism === void 0 ? false : _ref$showPrism,
24
28
  testId = _ref.testId,
29
+ url = _ref.url,
25
30
  props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
31
+ var _useAISummary = (0, _useAiSummary.useAISummary)({
32
+ url: url
33
+ }),
34
+ status = _useAISummary.state.status;
35
+ var _useState = (0, _react2.useState)(status === 'loading'),
36
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
37
+ showPrism = _useState2[0],
38
+ setShowPrism = _useState2[1];
39
+ (0, _react2.useEffect)(function () {
40
+ setShowPrism(status === 'loading');
41
+ }, [status]);
42
+ var container = (0, _react.jsx)("div", (0, _extends2.default)({
43
+ className: _HoverCardContent.hoverCardClassName,
44
+ css: [_styled.HoverCardContainer, isAIEnabled && showPrism ? undefined : _styled.popupContainerStyles],
45
+ "data-testid": testId
46
+ }, props), children);
47
+ return isAIEnabled ? (0, _react.jsx)(_aiPrism.default, {
48
+ isVisible: showPrism,
49
+ testId: "".concat(testId, "-prism")
50
+ }, container) : container;
51
+ };
52
+ var ContentContainer = function ContentContainer(_ref2) {
53
+ var children = _ref2.children,
54
+ _ref2$isAIEnabled = _ref2.isAIEnabled,
55
+ isAIEnabled = _ref2$isAIEnabled === void 0 ? false : _ref2$isAIEnabled,
56
+ testId = _ref2.testId,
57
+ url = _ref2.url,
58
+ props = (0, _objectWithoutProperties2.default)(_ref2, _excluded2);
26
59
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.smart-card.hover-card-ai-summaries')) {
27
- var container = (0, _react.jsx)("div", (0, _extends2.default)({
28
- className: _HoverCardContent.hoverCardClassName,
29
- css: [_styled.HoverCardContainer, isAIEnabled && showPrism ? undefined : _styled.popupContainerStyles],
30
- "data-testid": testId
60
+ return (0, _react.jsx)(ConnectedAIPrismContainer, (0, _extends2.default)({
61
+ isAIEnabled: isAIEnabled,
62
+ url: url,
63
+ testId: testId
31
64
  }, props), children);
32
- return isAIEnabled ? (0, _react.jsx)(_aiPrism.default, {
33
- isVisible: showPrism,
34
- testId: "".concat(testId, "-prism")
35
- }, container) : container;
36
65
  }
37
66
  return (0, _react.jsx)("div", (0, _extends2.default)({
38
67
  className: _HoverCardContent.hoverCardClassName,
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.hoverCardClassName = exports.getCopyAction = exports.default = void 0;
9
9
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
11
  var _react = require("@emotion/react");
13
12
  var _analyticsNext = require("@atlaskit/analytics-next");
@@ -97,10 +96,6 @@ var HoverCardContent = function HoverCardContent(_ref) {
97
96
  var services = (0, _helpers.getServices)(linkState.details);
98
97
  var statusRef = (0, _react2.useRef)(linkStatus);
99
98
  var analyticsRef = (0, _react2.useRef)(analytics);
100
- var _useState = (0, _react2.useState)(false),
101
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
102
- showPrism = _useState2[0],
103
- setShowPrism = _useState2[1];
104
99
  (0, _react2.useEffect)(function () {
105
100
  /**
106
101
  * Must access current analytics object value via ref because its not stable
@@ -173,9 +168,6 @@ var HoverCardContent = function HoverCardContent(_ref) {
173
168
  var onClickStopPropagation = (0, _react2.useCallback)(function (e) {
174
169
  return e.stopPropagation();
175
170
  }, []);
176
- var onAIActionChange = (0, _react2.useCallback)(function (state) {
177
- setShowPrism(state === 'loading');
178
- }, []);
179
171
  var getCardView = function getCardView(cardState) {
180
172
  if (cardState.metadataStatus === 'pending') {
181
173
  return (0, _react.jsx)(_resolving.default, {
@@ -208,7 +200,6 @@ var HoverCardContent = function HoverCardContent(_ref) {
208
200
  flexibleCardProps: flexibleCardProps,
209
201
  isAISummaryEnabled: isAISummaryEnabled,
210
202
  onActionClick: onActionClick,
211
- onAIActionChange: onAIActionChange,
212
203
  titleBlockProps: titleBlockProps
213
204
  });
214
205
  }
@@ -220,7 +211,7 @@ var HoverCardContent = function HoverCardContent(_ref) {
220
211
  onMouseLeave: onMouseLeave,
221
212
  onClick: onClickStopPropagation,
222
213
  isAIEnabled: isAISummaryEnabled,
223
- showPrism: showPrism
214
+ url: url
224
215
  }, cardView) : null;
225
216
  };
226
217
  var _default = exports.default = HoverCardContent;
@@ -20,6 +20,7 @@ var _messages = require("../../../../../messages");
20
20
  var _reactIntlNext = require("react-intl-next");
21
21
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
22
22
  var _helpers = require("../../../../../state/helpers");
23
+ var _useAiSummary = require("../../../../../state/hooks/use-ai-summary");
23
24
  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); }
24
25
  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 && Object.prototype.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; }
25
26
  var toFooterActions = exports.toFooterActions = function toFooterActions(cardActions, onActionClick) {
@@ -56,19 +57,41 @@ var toFooterActions = exports.toFooterActions = function toFooterActions(cardAct
56
57
  });
57
58
  return [followAction].concat((0, _toConsumableArray2.default)(actions));
58
59
  };
59
- var HoverCardResolvedView = function HoverCardResolvedView(_ref) {
60
+
61
+ //This component encapsulates useAISummary hook under the AI Summary FF 'platform.linking-platform.smart-card.hover-card-ai-summaries'
62
+ var ConnectedAIBlock = function ConnectedAIBlock(_ref) {
63
+ var bottomPrimary = _ref.bottomPrimary,
64
+ url = _ref.url,
65
+ imagePreview = _ref.imagePreview;
66
+ var aiSummary = (0, _useAiSummary.useAISummary)({
67
+ url: url
68
+ });
69
+ var aiStatus = aiSummary.state.status;
70
+ var showData = aiStatus === 'ready' || aiStatus === 'error';
71
+ return showData ? /*#__PURE__*/_react.default.createElement(_blocks.CustomBlock, {
72
+ direction: _constants.SmartLinkDirection.Vertical
73
+ }, !imagePreview && /*#__PURE__*/_react.default.createElement(_blocks.SnippetBlock, {
74
+ status: _constants.SmartLinkStatus.Resolved
75
+ }), /*#__PURE__*/_react.default.createElement(_blocks.MetadataBlock, {
76
+ primary: bottomPrimary,
77
+ size: _constants.SmartLinkSize.Large,
78
+ overrideCss: _styled.metadataBlockCss,
79
+ maxLines: 1,
80
+ status: _constants.SmartLinkStatus.Resolved
81
+ })) : null;
82
+ };
83
+ var HoverCardResolvedView = function HoverCardResolvedView(_ref2) {
60
84
  var _cardState$details;
61
- var flexibleCardProps = _ref.flexibleCardProps,
62
- titleBlockProps = _ref.titleBlockProps,
63
- analytics = _ref.analytics,
64
- cardState = _ref.cardState,
65
- _ref$cardActions = _ref.cardActions,
66
- cardActions = _ref$cardActions === void 0 ? [] : _ref$cardActions,
67
- isAISummaryEnabled = _ref.isAISummaryEnabled,
68
- onActionClick = _ref.onActionClick,
69
- onAIActionChange = _ref.onAIActionChange,
70
- extensionKey = _ref.extensionKey,
71
- url = _ref.url;
85
+ var flexibleCardProps = _ref2.flexibleCardProps,
86
+ titleBlockProps = _ref2.titleBlockProps,
87
+ analytics = _ref2.analytics,
88
+ cardState = _ref2.cardState,
89
+ _ref2$cardActions = _ref2.cardActions,
90
+ cardActions = _ref2$cardActions === void 0 ? [] : _ref2$cardActions,
91
+ isAISummaryEnabled = _ref2.isAISummaryEnabled,
92
+ onActionClick = _ref2.onActionClick,
93
+ extensionKey = _ref2.extensionKey,
94
+ url = _ref2.url;
72
95
  var canBeDatasource = (0, _helpers.getCanBeDatasource)(cardState.details);
73
96
  (0, _react.useEffect)(function () {
74
97
  // Since this hover view is only rendered on resolved status,
@@ -100,6 +123,15 @@ var HoverCardResolvedView = function HoverCardResolvedView(_ref) {
100
123
  var _snippetBlockRef$curr, _snippetBlockRef$curr2;
101
124
  snippetHeight.current = (_snippetBlockRef$curr = (_snippetBlockRef$curr2 = snippetBlockRef.current) === null || _snippetBlockRef$curr2 === void 0 ? void 0 : _snippetBlockRef$curr2.getBoundingClientRect().height) !== null && _snippetBlockRef$curr !== void 0 ? _snippetBlockRef$curr : 0;
102
125
  }, []);
126
+
127
+ // We want to maintain the height of the HoverCard while summarizing and pass this height to the AISummaryBlock.
128
+ // This approach will prevent any abrupt changes in the height of the HoverCard.
129
+ var connectedAIBlockHeight = _react.default.useRef(0);
130
+ var connectedAIBlockRef = (0, _react.useRef)(null);
131
+ var onConnectedAIBlockRender = (0, _react.useCallback)(function () {
132
+ var _connectedAIBlockRef$, _connectedAIBlockRef$2;
133
+ connectedAIBlockHeight.current = (_connectedAIBlockRef$ = (_connectedAIBlockRef$2 = connectedAIBlockRef.current) === null || _connectedAIBlockRef$2 === void 0 ? void 0 : _connectedAIBlockRef$2.getBoundingClientRect().height) !== null && _connectedAIBlockRef$ !== void 0 ? _connectedAIBlockRef$ : 0;
134
+ }, []);
103
135
  var imagePreview = (0, _ImagePreview.default)({
104
136
  data: data,
105
137
  fallbackElementHeight: snippetHeight.current
@@ -112,16 +144,31 @@ var HoverCardResolvedView = function HoverCardResolvedView(_ref) {
112
144
  overrideCss: _styled.metadataBlockCss,
113
145
  maxLines: 1,
114
146
  size: _constants.SmartLinkSize.Medium
115
- }), !imagePreview && /*#__PURE__*/_react.default.createElement(_blocks.SnippetBlock, null), /*#__PURE__*/_react.default.createElement(_blocks.SnippetBlock, {
147
+ }), isAISummaryEnabled &&
148
+ /*#__PURE__*/
149
+ // All custom elements should be contained within a CustomBlock.
150
+ // Flex Container components check whether the direct child is a flex blocks. It removes anything that isn't
151
+ _react.default.createElement(_blocks.CustomBlock, {
152
+ direction: _constants.SmartLinkDirection.Vertical,
153
+ onRender: onConnectedAIBlockRender,
154
+ blockRef: connectedAIBlockRef
155
+ }, /*#__PURE__*/_react.default.createElement(ConnectedAIBlock, {
156
+ imagePreview: !!imagePreview,
157
+ url: url,
158
+ bottomPrimary: bottomPrimary
159
+ })), !isAISummaryEnabled && !imagePreview && /*#__PURE__*/_react.default.createElement(_blocks.SnippetBlock, {
160
+ status: _constants.SmartLinkStatus.Resolved
161
+ }), /*#__PURE__*/_react.default.createElement(_blocks.SnippetBlock, {
116
162
  testId: 'hidden-snippet',
117
163
  onRender: onSnippetRender,
118
164
  blockRef: snippetBlockRef,
119
165
  overrideCss: _styled.hiddenSnippetStyles
120
- }), /*#__PURE__*/_react.default.createElement(_blocks.MetadataBlock, {
166
+ }), !isAISummaryEnabled && /*#__PURE__*/_react.default.createElement(_blocks.MetadataBlock, {
121
167
  primary: bottomPrimary,
122
168
  size: _constants.SmartLinkSize.Large,
123
169
  overrideCss: _styled.metadataBlockCss,
124
- maxLines: 1
170
+ maxLines: 1,
171
+ status: _constants.SmartLinkStatus.Resolved
125
172
  }), (0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.smart-card.enable-hover-card-related-urls') && /*#__PURE__*/_react.default.createElement(_blocks.RelatedUrlsBlock, {
126
173
  url: url,
127
174
  size: _constants.SmartLinkSize.Small
@@ -130,7 +177,7 @@ var HoverCardResolvedView = function HoverCardResolvedView(_ref) {
130
177
  name: _constants.ElementName.Provider
131
178
  }],
132
179
  actions: footerActions,
133
- onAIActionChange: onAIActionChange
180
+ aiSummaryMinHeight: connectedAIBlockHeight.current
134
181
  }) : /*#__PURE__*/_react.default.createElement(_blocks.FooterBlock, {
135
182
  actions: footerActions,
136
183
  size: _constants.SmartLinkSize.Large,
@@ -17,7 +17,7 @@ var _excluded = ["href", "children", "checkSafety", "onClick", "testId"],
17
17
  _excluded2 = ["isLinkSafe", "showSafetyWarningModal"];
18
18
  var PACKAGE_DATA = {
19
19
  packageName: "@atlaskit/smart-card",
20
- packageVersion: "26.49.0",
20
+ packageVersion: "26.49.1",
21
21
  componentName: 'linkUrl'
22
22
  };
23
23
  var Link = (0, _click.withLinkClickedEvent)('a');
@@ -31,14 +31,17 @@ var AISummaryCSS = (0, _react2.css)({
31
31
  */
32
32
 
33
33
  var AISummary = function AISummary(_ref) {
34
- var content = _ref.content,
34
+ var _ref$content = _ref.content,
35
+ content = _ref$content === void 0 ? '' : _ref$content,
35
36
  _ref$showIcon = _ref.showIcon,
36
37
  showIcon = _ref$showIcon === void 0 ? false : _ref$showIcon,
37
38
  iconComponent = _ref.iconComponent,
38
39
  overrideCss = _ref.overrideCss,
39
40
  _ref$testId = _ref.testId,
40
- testId = _ref$testId === void 0 ? 'ai-summary' : _ref$testId;
41
- if (!content) {
41
+ testId = _ref$testId === void 0 ? 'ai-summary' : _ref$testId,
42
+ _ref$minHeight = _ref.minHeight,
43
+ minHeight = _ref$minHeight === void 0 ? 0 : _ref$minHeight;
44
+ if (!content && minHeight === 0) {
42
45
  return null;
43
46
  }
44
47
  return (0, _react2.jsx)(_markdownToJsx.default, {
@@ -50,6 +53,9 @@ var AISummary = function AISummary(_ref) {
50
53
  overrides: {
51
54
  Icon: iconComponent !== null && iconComponent !== void 0 ? iconComponent : AITooltipIcon
52
55
  }
56
+ },
57
+ style: {
58
+ minHeight: minHeight
53
59
  }
54
60
  });
55
61
  };