@atlaskit/smart-card 25.9.0 → 25.9.2

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 (52) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/extractors/flexible/extract-state.js +4 -1
  3. package/dist/cjs/state/actions/index.js +11 -27
  4. package/dist/cjs/state/hooks/use-resolve/index.js +12 -21
  5. package/dist/cjs/version.json +1 -1
  6. package/dist/cjs/view/CardWithUrl/component.js +3 -12
  7. package/dist/cjs/view/EmbedModal/components/analytics/index.js +9 -9
  8. package/dist/cjs/view/EmbedModal/utils.js +111 -0
  9. package/dist/cjs/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -83
  10. package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/index.js +24 -18
  11. package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +35 -5
  12. package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +6 -4
  13. package/dist/cjs/view/FlexibleCard/components/elements/link/index.js +3 -1
  14. package/dist/cjs/view/HoverCard/components/HoverCardComponent.js +4 -11
  15. package/dist/es2019/extractors/flexible/extract-state.js +4 -1
  16. package/dist/es2019/state/actions/index.js +12 -32
  17. package/dist/es2019/state/hooks/use-resolve/index.js +12 -21
  18. package/dist/es2019/version.json +1 -1
  19. package/dist/es2019/view/CardWithUrl/component.js +2 -8
  20. package/dist/es2019/view/EmbedModal/components/analytics/index.js +9 -9
  21. package/dist/es2019/view/EmbedModal/utils.js +77 -0
  22. package/dist/es2019/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -56
  23. package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/index.js +11 -7
  24. package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +35 -5
  25. package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +9 -1
  26. package/dist/es2019/view/FlexibleCard/components/elements/link/index.js +11 -4
  27. package/dist/es2019/view/HoverCard/components/HoverCardComponent.js +3 -10
  28. package/dist/esm/extractors/flexible/extract-state.js +4 -1
  29. package/dist/esm/state/actions/index.js +11 -27
  30. package/dist/esm/state/hooks/use-resolve/index.js +12 -21
  31. package/dist/esm/version.json +1 -1
  32. package/dist/esm/view/CardWithUrl/component.js +2 -10
  33. package/dist/esm/view/EmbedModal/components/analytics/index.js +9 -9
  34. package/dist/esm/view/EmbedModal/utils.js +98 -0
  35. package/dist/esm/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -78
  36. package/dist/esm/view/FlexibleCard/components/common/lozenge-action/index.js +24 -18
  37. package/dist/esm/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +37 -5
  38. package/dist/esm/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +4 -3
  39. package/dist/esm/view/FlexibleCard/components/elements/link/index.js +3 -1
  40. package/dist/esm/view/HoverCard/components/HoverCardComponent.js +4 -11
  41. package/dist/types/state/hooks/use-invoke/types.d.ts +5 -0
  42. package/dist/types/view/CardWithUrl/component.d.ts +1 -1
  43. package/dist/types/view/EmbedModal/components/analytics/types.d.ts +1 -1
  44. package/dist/types/view/EmbedModal/utils.d.ts +10 -0
  45. package/dist/types/view/FlexibleCard/components/actions/action/preview-action/index.d.ts +1 -2
  46. package/dist/types/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.d.ts +1 -0
  47. package/dist/types/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/types.d.ts +18 -0
  48. package/package.json +1 -2
  49. package/dist/cjs/utils/analytics/SmartLinkAnalyticsContext.js +0 -47
  50. package/dist/es2019/utils/analytics/SmartLinkAnalyticsContext.js +0 -35
  51. package/dist/esm/utils/analytics/SmartLinkAnalyticsContext.js +0 -36
  52. package/dist/types/utils/analytics/SmartLinkAnalyticsContext.d.ts +0 -9
@@ -36,6 +36,7 @@ var isInvokeCustomError = function isInvokeCustomError(err) {
36
36
  return err.message !== undefined && err.errorCode !== undefined;
37
37
  };
38
38
  var LozengeAction = function LozengeAction(_ref) {
39
+ var _action$update;
39
40
  var action = _ref.action,
40
41
  appearance = _ref.appearance,
41
42
  _ref$testId = _ref.testId,
@@ -64,8 +65,12 @@ var LozengeAction = function LozengeAction(_ref) {
64
65
  setErrorMessage = _useState10[1];
65
66
  var invoke = (0, _useInvoke.default)();
66
67
  var reload = (0, _useResolve.default)();
68
+ var _ref2 = (action === null || action === void 0 ? void 0 : (_action$update = action.update) === null || _action$update === void 0 ? void 0 : _action$update.details) || {},
69
+ url = _ref2.url,
70
+ linkId = _ref2.id,
71
+ previewData = _ref2.previewData;
67
72
  var handleOpenChange = (0, _react2.useCallback)( /*#__PURE__*/function () {
68
- var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(args) {
73
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(args) {
69
74
  var responseItems, validItems;
70
75
  return _regeneratorRuntime().wrap(function _callee$(_context) {
71
76
  while (1) {
@@ -112,7 +117,7 @@ var LozengeAction = function LozengeAction(_ref) {
112
117
  }, _callee, null, [[2, 13, 17, 20]]);
113
118
  }));
114
119
  return function (_x) {
115
- return _ref2.apply(this, arguments);
120
+ return _ref3.apply(this, arguments);
116
121
  };
117
122
  }(), [action === null || action === void 0 ? void 0 : action.read, invoke, isLoaded, text]);
118
123
  var trigger = (0, _react2.useCallback)(function (props) {
@@ -123,8 +128,8 @@ var LozengeAction = function LozengeAction(_ref) {
123
128
  }));
124
129
  }, [appearance, testId, text]);
125
130
  var handleItemClick = (0, _react2.useCallback)( /*#__PURE__*/function () {
126
- var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(id) {
127
- var updateAction, request, _ref4, url, linkId;
131
+ var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(id) {
132
+ var updateAction, request;
128
133
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
129
134
  while (1) {
130
135
  switch (_context2.prev = _context2.next) {
@@ -132,7 +137,7 @@ var LozengeAction = function LozengeAction(_ref) {
132
137
  _context2.prev = 0;
133
138
  updateAction = action === null || action === void 0 ? void 0 : action.update;
134
139
  if (!(updateAction && id)) {
135
- _context2.next = 15;
140
+ _context2.next = 14;
136
141
  break;
137
142
  }
138
143
  setIsLoading(true);
@@ -144,18 +149,17 @@ var LozengeAction = function LozengeAction(_ref) {
144
149
  setIsLoaded(false);
145
150
  setIsOpen(false);
146
151
  setItems([]);
147
- _ref4 = updateAction.details || {}, url = _ref4.url, linkId = _ref4.id;
148
152
  if (!url) {
149
- _context2.next = 15;
153
+ _context2.next = 14;
150
154
  break;
151
155
  }
152
- _context2.next = 15;
156
+ _context2.next = 14;
153
157
  return reload(url, true, undefined, linkId);
154
- case 15:
155
- _context2.next = 21;
158
+ case 14:
159
+ _context2.next = 20;
156
160
  break;
157
- case 17:
158
- _context2.prev = 17;
161
+ case 16:
162
+ _context2.prev = 16;
159
163
  _context2.t0 = _context2["catch"](0);
160
164
  setIsLoading(false);
161
165
  if (isInvokeCustomError(_context2.t0)) {
@@ -163,22 +167,24 @@ var LozengeAction = function LozengeAction(_ref) {
163
167
  } else {
164
168
  setErrorMessage(_types.LozengeActionErrorMessages.updateFailed);
165
169
  }
166
- case 21:
170
+ case 20:
167
171
  case "end":
168
172
  return _context2.stop();
169
173
  }
170
174
  }
171
- }, _callee2, null, [[0, 17]]);
175
+ }, _callee2, null, [[0, 16]]);
172
176
  }));
173
177
  return function (_x2) {
174
- return _ref3.apply(this, arguments);
178
+ return _ref4.apply(this, arguments);
175
179
  };
176
- }(), [action === null || action === void 0 ? void 0 : action.update, invoke, reload]);
180
+ }(), [action === null || action === void 0 ? void 0 : action.update, invoke, linkId, reload, url]);
177
181
  var dropdownItemGroup = (0, _react2.useMemo)(function () {
178
182
  if (errorMessage) {
179
183
  return (0, _react.jsx)(_lozengeActionError.default, {
180
184
  errorMessage: errorMessage,
181
- testId: testId
185
+ testId: testId,
186
+ url: url,
187
+ previewData: previewData
182
188
  });
183
189
  }
184
190
  if (items && items.length > 0) {
@@ -193,7 +199,7 @@ var LozengeAction = function LozengeAction(_ref) {
193
199
  }));
194
200
  })));
195
201
  }
196
- }, [errorMessage, handleItemClick, items, testId]);
202
+ }, [errorMessage, handleItemClick, items, previewData, testId, url]);
197
203
  return (0, _react.jsx)(_dropdownMenu.default, {
198
204
  isLoading: isLoading,
199
205
  isOpen: isOpen,
@@ -5,21 +5,45 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
8
9
  var _react = require("@emotion/react");
9
10
  var _react2 = require("react");
11
+ var _reactIntlNext = require("react-intl-next");
10
12
  var _dropdownMenu = require("@atlaskit/dropdown-menu");
11
13
  var _colors = require("@atlaskit/theme/colors");
12
14
  var _error = _interopRequireDefault(require("@atlaskit/icon/glyph/error"));
13
15
  var _styled = require("./styled");
14
16
  var _utils = require("../../../utils");
15
- /** @jsx jsx */
16
-
17
+ var _messages = require("../../../../../../messages");
18
+ var _flexibleUiContext = require("../../../../../../state/flexible-ui-context");
19
+ var _utils2 = require("../../../../../EmbedModal/utils");
20
+ var _useResolve = _interopRequireDefault(require("../../../../../../state/hooks/use-resolve"));
21
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
22
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } /** @jsx jsx */
17
23
  var MAX_LINE_NUMBER = 8;
18
24
  var LozengeActionError = function LozengeActionError(_ref) {
19
25
  var errorMessage = _ref.errorMessage,
20
26
  testId = _ref.testId,
21
27
  _ref$maxLineNumber = _ref.maxLineNumber,
22
- maxLineNumber = _ref$maxLineNumber === void 0 ? MAX_LINE_NUMBER : _ref$maxLineNumber;
28
+ maxLineNumber = _ref$maxLineNumber === void 0 ? MAX_LINE_NUMBER : _ref$maxLineNumber,
29
+ url = _ref.url,
30
+ previewData = _ref.previewData;
31
+ var reload = (0, _useResolve.default)();
32
+ var analytics = (0, _flexibleUiContext.useFlexibleUiAnalyticsContext)();
33
+ var isPreviewAvailable = previewData && previewData.src !== undefined;
34
+ var handlePreviewClose = (0, _react2.useCallback)(function () {
35
+ if (url) {
36
+ reload(url, true);
37
+ }
38
+ }, [reload, url]);
39
+ var handlePreviewOpen = (0, _react2.useCallback)(function () {
40
+ if (isPreviewAvailable) {
41
+ return (0, _utils2.openPreviewModal)(_objectSpread(_objectSpread({}, previewData), {}, {
42
+ analytics: analytics,
43
+ onClose: handlePreviewClose
44
+ }));
45
+ }
46
+ }, [analytics, handlePreviewClose, isPreviewAvailable, previewData]);
23
47
  var content = (0, _react2.useMemo)(function () {
24
48
  return (0, _react.jsx)(_react2.Fragment, null, (0, _react.jsx)("div", {
25
49
  css: _styled.contentStyles
@@ -32,8 +56,14 @@ var LozengeActionError = function LozengeActionError(_ref) {
32
56
  }), (0, _react.jsx)("span", {
33
57
  css: (0, _styled.textStyles)(maxLineNumber),
34
58
  "data-testid": "".concat(testId, "-error-message")
35
- }, typeof errorMessage === 'string' ? errorMessage : (0, _utils.getFormattedMessage)(errorMessage))));
36
- }, [errorMessage, maxLineNumber, testId]);
59
+ }, typeof errorMessage === 'string' ? errorMessage : (0, _utils.getFormattedMessage)(errorMessage))), isPreviewAvailable ? (0, _react.jsx)("div", {
60
+ css: _styled.linkStyles
61
+ }, (0, _react.jsx)("a", {
62
+ target: "_blank",
63
+ "data-testid": "".concat(testId, "-open-embed"),
64
+ onClick: handlePreviewOpen
65
+ }, (0, _react.jsx)(_reactIntlNext.FormattedMessage, _messages.messages.open_issue_in_jira))) : null);
66
+ }, [errorMessage, handlePreviewOpen, isPreviewAvailable, maxLineNumber, testId]);
37
67
  return (0, _react.jsx)("span", {
38
68
  css: _styled.dropdownItemGroupStyles,
39
69
  "data-testid": "".concat(testId, "-error-item-group")
@@ -4,18 +4,20 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.textStyles = exports.dropdownItemGroupStyles = exports.contentStyles = void 0;
7
+ exports.textStyles = exports.linkStyles = exports.dropdownItemGroupStyles = exports.contentStyles = void 0;
8
8
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
9
9
  var _react = require("@emotion/react");
10
10
  var _colors = require("@atlaskit/theme/colors");
11
11
  var _utils = require("../../../utils");
12
- var _templateObject, _templateObject2, _templateObject3, _templateObject4;
12
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
13
13
  var dropdownItemGroupStyles = (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n button {\n width: 220px;\n\n &:hover {\n background-color: inherit;\n cursor: default;\n }\n }\n"])));
14
14
  exports.dropdownItemGroupStyles = dropdownItemGroupStyles;
15
15
  var sharedBlockStyles = (0, _react.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n display: flex;\n gap: 0.5rem;\n line-height: 1rem;\n min-width: 0;\n overflow: hidden;\n flex-direction: row;\n align-items: center;\n"])));
16
- var contentStyles = (0, _react.css)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n ", ";\n\n margin-top: 2px;\n align-items: flex-start;\n\n > span,\n > div {\n &[data-smart-element-text] {\n font-size: 0.875rem;\n color: ", ";\n }\n }\n"])), sharedBlockStyles, "var(--ds-text, ".concat(_colors.N800, ")"));
16
+ var contentStyles = (0, _react.css)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n ", ";\n\n margin-top: ", ";\n align-items: flex-start;\n\n > span,\n > div {\n &[data-smart-element-text] {\n font-size: 0.875rem;\n color: ", ";\n }\n }\n"])), sharedBlockStyles, "var(--ds-space-025, 2px)", "var(--ds-text, ".concat(_colors.N800, ")"));
17
17
  exports.contentStyles = contentStyles;
18
+ var linkStyles = (0, _react.css)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n ", ";\n\n font-size: 0.875rem;\n margin-top: 10px;\n margin-left: ", ";\n margin-bottom: ", ";\n"])), sharedBlockStyles, "var(--ds-space-400, 32px)", "var(--ds-space-025, 2px)");
19
+ exports.linkStyles = linkStyles;
18
20
  var textStyles = function textStyles(maxLines) {
19
- return (0, _react.css)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n line-height: 1rem;\n white-space: normal;\n ", ";\n"])), (0, _utils.getTruncateStyles)(maxLines));
21
+ return (0, _react.css)(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2.default)(["\n line-height: 1rem;\n white-space: normal;\n ", ";\n"])), (0, _utils.getTruncateStyles)(maxLines));
20
22
  };
21
23
  exports.textStyles = textStyles;
@@ -25,7 +25,9 @@ var containerStyles = (0, _react2.css)(_templateObject || (_templateObject = (0,
25
25
  var getThemeStyles = function getThemeStyles(theme) {
26
26
  switch (theme) {
27
27
  case _constants.SmartLinkInternalTheme.Grey:
28
- return (0, _react2.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n color: ", ";\n :hover {\n color: ", ";\n text-decoration: underline;\n }\n font-size: 12px;\n "])), "var(--ds-text-subtlest, #626F86)", "var(--ds-text-subtlest, #626F86)");
28
+ // We are being specifc with the CSS selectors to ensure that Confluence overrides
29
+ // do not affect our internal Smart Card styles
30
+ return (0, _react2.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n a& {\n color: ", ";\n &:active,\n &:visited,\n &:focus,\n &:hover {\n color: ", ";\n text-decoration: underline;\n }\n font-size: 12px;\n }\n "])), "var(--ds-text-subtlest, #626F86)", "var(--ds-text-subtlest, #626F86)");
29
31
  // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
30
32
  case _constants.SmartLinkTheme.Black:
31
33
  return (0, _react2.css)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n color: ", ";\n :active {\n color: ", ";\n }\n :hover {\n color: ", ";\n text-decoration: underline;\n }\n "])), _token.tokens.blackLink, _token.tokens.blackLinkPressed, _token.tokens.blackLink);
@@ -17,7 +17,6 @@ var _store = require("../../../state/store");
17
17
  var _HoverCardContent = _interopRequireDefault(require("../components/HoverCardContent"));
18
18
  var _styled = require("../styled");
19
19
  var _constants = require("../../../constants");
20
- var _SmartLinkAnalyticsContext = require("../../../utils/analytics/SmartLinkAnalyticsContext");
21
20
  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); }
22
21
  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; }
23
22
  /** @jsx jsx */
@@ -25,7 +24,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
25
24
  var HoverCardComponent = function HoverCardComponent(_ref) {
26
25
  var children = _ref.children,
27
26
  url = _ref.url,
28
- id = _ref.id,
29
27
  analyticsHandler = _ref.analyticsHandler,
30
28
  analytics = _ref.analytics,
31
29
  _ref$canOpen = _ref.canOpen,
@@ -135,11 +133,7 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
135
133
  }, [closeOnChildClick, hideCard]);
136
134
  var content = (0, _react2.useCallback)(function (_ref2) {
137
135
  var update = _ref2.update;
138
- return (0, _react.jsx)(_SmartLinkAnalyticsContext.SmartLinkAnalyticsContext, {
139
- url: url,
140
- appearance: _constants.CardDisplay.HoverCardPreview,
141
- id: id
142
- }, (0, _react.jsx)(_HoverCardContent.default, {
136
+ return (0, _react.jsx)(_HoverCardContent.default, {
143
137
  onMouseEnter: initShowCard,
144
138
  onMouseLeave: initHideCard,
145
139
  analytics: analytics,
@@ -149,10 +143,9 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
149
143
  onResolve: update,
150
144
  renderers: renderers,
151
145
  showServerActions: showServerActions,
152
- url: url,
153
- id: id
154
- }));
155
- }, [analytics, initHideCard, initShowCard, filteredActions, linkState, onActionClick, renderers, showServerActions, url, id]);
146
+ url: url
147
+ });
148
+ }, [analytics, initHideCard, initShowCard, filteredActions, linkState, onActionClick, renderers, showServerActions, url]);
156
149
  var trigger = (0, _react2.useCallback)(function (triggerProps) {
157
150
  return (0, _react.jsx)("span", {
158
151
  ref: parentSpan
@@ -2,6 +2,7 @@ import { extractLozenge } from '../common/lozenge';
2
2
  import { getExtensionKey } from '../../state/helpers';
3
3
  import extractServerAction from './extract-server-action';
4
4
  import { extractLink } from '@atlaskit/linking-common/extractors';
5
+ import { extractPreviewAction } from './actions/extract-preview-action';
5
6
  const toInvokeRequest = (extensionKey, resourceIdentifiers, actionType, details) => {
6
7
  if (!actionType) {
7
8
  return;
@@ -29,9 +30,11 @@ const extractAction = (response, id) => {
29
30
  }
30
31
  const read = toInvokeRequest(extensionKey, action.resourceIdentifiers, (_action$dataRetrieval = action.dataRetrievalAction) === null || _action$dataRetrieval === void 0 ? void 0 : _action$dataRetrieval.name);
31
32
  const url = extractLink(data);
33
+ const previewData = response ? extractPreviewAction(response) : null;
32
34
  const details = {
33
35
  id,
34
- url
36
+ url,
37
+ previewData
35
38
  };
36
39
  const update = toInvokeRequest(extensionKey, action.resourceIdentifiers, (_action$dataUpdateAct = action.dataUpdateAction) === null || _action$dataUpdateAct === void 0 ? void 0 : _action$dataUpdateAct.name, details);
37
40
  return read || update ? {
@@ -16,21 +16,14 @@ export const useSmartCardActions = (id, url, analytics) => {
16
16
  getState,
17
17
  dispatch
18
18
  } = store;
19
- const getSmartLinkState = useCallback(() => {
20
- var _getState$url;
21
- const {
22
- details,
23
- status,
24
- metadataStatus
25
- } = (_getState$url = getState()[url]) !== null && _getState$url !== void 0 ? _getState$url : {
26
- status: SmartLinkStatus.Pending
27
- };
28
- return {
29
- details,
30
- status,
31
- metadataStatus
32
- };
33
- }, [getState, url]);
19
+ const {
20
+ details,
21
+ status,
22
+ metadataStatus
23
+ } = getState()[url] || {
24
+ status: SmartLinkStatus.Pending,
25
+ details: undefined
26
+ };
34
27
  const setMetadataStatus = useCallback(metadataStatus => {
35
28
  dispatch(cardAction(ACTION_UPDATE_METADATA_STATUS, {
36
29
  url
@@ -38,9 +31,6 @@ export const useSmartCardActions = (id, url, analytics) => {
38
31
  }, [dispatch, url]);
39
32
  const resolve = useCallback(async (resourceUrl = url, isReloading = false, isMetadataRequest = false) => resolveUrl(resourceUrl, isReloading, isMetadataRequest, id), [id, resolveUrl, url]);
40
33
  const register = useCallback(() => {
41
- const {
42
- details
43
- } = getSmartLinkState();
44
34
  if (!details) {
45
35
  dispatch(cardAction(ACTION_RESOLVING, {
46
36
  url
@@ -48,33 +38,23 @@ export const useSmartCardActions = (id, url, analytics) => {
48
38
  setMetadataStatus('pending');
49
39
  }
50
40
  return resolve();
51
- }, [getSmartLinkState, resolve, dispatch, url, setMetadataStatus]);
41
+ }, [details, resolve, dispatch, url, setMetadataStatus]);
52
42
  const reload = useCallback(() => {
53
- const {
54
- details
55
- } = getSmartLinkState();
56
43
  const definitionId = getDefinitionId(details);
57
44
  if (definitionId) {
58
45
  getByDefinitionId(definitionId, getState()).map(url => resolve(url, true));
59
46
  } else {
60
47
  resolve(url, true);
61
48
  }
62
- }, [getSmartLinkState, url, getState, resolve]);
49
+ }, [details, url, getState, resolve]);
63
50
  const loadMetadata = useCallback(() => {
64
- const {
65
- metadataStatus
66
- } = getSmartLinkState();
67
51
  //metadataStatus will be undefined for SSR links only
68
52
  if (metadataStatus === undefined) {
69
53
  setMetadataStatus('pending');
70
54
  return resolve(url, false, true);
71
55
  }
72
- }, [getSmartLinkState, resolve, setMetadataStatus, url]);
56
+ }, [metadataStatus, resolve, setMetadataStatus, url]);
73
57
  const authorize = useCallback(appearance => {
74
- const {
75
- details,
76
- status
77
- } = getSmartLinkState();
78
58
  const definitionId = getDefinitionId(details);
79
59
  const extensionKey = getExtensionKey(details);
80
60
  const services = getServices(details);
@@ -126,7 +106,7 @@ export const useSmartCardActions = (id, url, analytics) => {
126
106
  reload();
127
107
  });
128
108
  }
129
- }, [getSmartLinkState, analytics.ui, analytics.screen, analytics.track, analytics.operational, id, reload]);
109
+ }, [analytics.ui, analytics.screen, analytics.track, analytics.operational, id, reload, details, status]);
130
110
  const invoke = useCallback(async (opts, appearance) => {
131
111
  const {
132
112
  key,
@@ -1,5 +1,4 @@
1
1
  import { useCallback } from 'react';
2
- import { unstable_batchedUpdates } from 'react-dom';
3
2
  import { addMetadataToExperience } from '../../analytics';
4
3
  import { getStatus } from '../../helpers';
5
4
  import { ACTION_ERROR, ACTION_ERROR_FALLBACK, ACTION_RELOADING, ACTION_RESOLVED, ACTION_UPDATE_METADATA_STATUS, APIError, cardAction } from '@atlaskit/linking-common';
@@ -99,26 +98,18 @@ const useResolve = () => {
99
98
  return;
100
99
  }
101
100
 
102
- /**
103
- * Using unstable_batchedUpdates because this store update happens async and trigers a rerender
104
- * more info:
105
- * https://github.com/facebook/react/blob/v18.2.0/packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js#L113
106
- * https://react-redux.js.org/api/batch
107
- */
108
- unstable_batchedUpdates(() => {
109
- //if a link resolves normally, metadata will also always be resolved
110
- setMetadataStatus(resourceUrl, 'resolved');
111
- // Dispatch Analytics and resolved card action - including unauthorized states.
112
- if (isReloading) {
113
- dispatch(cardAction(ACTION_RELOADING, {
114
- url: resourceUrl
115
- }, response));
116
- } else {
117
- dispatch(cardAction(ACTION_RESOLVED, {
118
- url: resourceUrl
119
- }, response, undefined, undefined, isMetadataRequest));
120
- }
121
- });
101
+ //if a link resolves normally, metadata will also always be resolved
102
+ setMetadataStatus(resourceUrl, 'resolved');
103
+ // Dispatch Analytics and resolved card action - including unauthorized states.
104
+ if (isReloading) {
105
+ dispatch(cardAction(ACTION_RELOADING, {
106
+ url: resourceUrl
107
+ }, response));
108
+ } else {
109
+ dispatch(cardAction(ACTION_RESOLVED, {
110
+ url: resourceUrl
111
+ }, response, undefined, undefined, isMetadataRequest));
112
+ }
122
113
  }, [dispatch, handleResolvedLinkError, hasAuthFlowSupported, setMetadataStatus]);
123
114
  return useCallback(async (url, isReloading = false, isMetadataRequest = false, id = '') => {
124
115
  const {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "25.9.0",
3
+ "version": "25.9.2",
4
4
  "sideEffects": false
5
5
  }
@@ -12,8 +12,7 @@ import { isFlexibleUiCard } from '../../utils/flexible';
12
12
  import FlexibleCard from '../FlexibleCard';
13
13
  import { CardDisplay } from '../../constants';
14
14
  import { fireLinkClickedEvent } from '../../utils/analytics/click';
15
- import { SmartLinkAnalyticsContext } from '../../utils/analytics/SmartLinkAnalyticsContext';
16
- function Component({
15
+ export function CardWithUrlContent({
17
16
  id,
18
17
  url,
19
18
  isSelected,
@@ -255,9 +254,4 @@ function Component({
255
254
  onIframeFocus: onIframeFocus
256
255
  });
257
256
  }
258
- }
259
- export const CardWithUrlContent = props => /*#__PURE__*/React.createElement(SmartLinkAnalyticsContext, {
260
- url: props.url,
261
- appearance: props.appearance,
262
- id: props.id
263
- }, /*#__PURE__*/React.createElement(Component, props));
257
+ }
@@ -13,23 +13,23 @@ const withAnalytics = Component => props => {
13
13
  origin
14
14
  } = props;
15
15
  const handleOnOpen = useCallback(context => {
16
- analytics.screen.modalViewedEvent({
16
+ analytics === null || analytics === void 0 ? void 0 : analytics.screen.modalViewedEvent({
17
17
  name: 'embedPreviewModal',
18
18
  attributes: {
19
19
  origin,
20
20
  size: context.size
21
21
  }
22
22
  });
23
- analytics.ui.renderSuccessEvent({
23
+ analytics === null || analytics === void 0 ? void 0 : analytics.ui.renderSuccessEvent({
24
24
  status: 'resolved',
25
25
  display: CardDisplay.EmbedPreview
26
26
  });
27
27
  if (onOpen) {
28
28
  onOpen(context);
29
29
  }
30
- }, [analytics.screen, analytics.ui, onOpen, origin]);
30
+ }, [analytics === null || analytics === void 0 ? void 0 : analytics.screen, analytics === null || analytics === void 0 ? void 0 : analytics.ui, onOpen, origin]);
31
31
  const handleOnOpenFailed = useCallback((error, errorInfo) => {
32
- analytics.ui.renderFailedEvent({
32
+ analytics === null || analytics === void 0 ? void 0 : analytics.ui.renderFailedEvent({
33
33
  display: CardDisplay.EmbedPreview,
34
34
  error,
35
35
  errorInfo
@@ -37,9 +37,9 @@ const withAnalytics = Component => props => {
37
37
  if (onOpenFailed) {
38
38
  onOpenFailed(error, errorInfo);
39
39
  }
40
- }, [analytics.ui, onOpenFailed]);
40
+ }, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onOpenFailed]);
41
41
  const handleOnClose = useCallback(context => {
42
- analytics.ui.modalClosedEvent({
42
+ analytics === null || analytics === void 0 ? void 0 : analytics.ui.modalClosedEvent({
43
43
  actionSubjectId: 'embedPreview',
44
44
  attributes: {
45
45
  origin,
@@ -50,9 +50,9 @@ const withAnalytics = Component => props => {
50
50
  if (onClose) {
51
51
  onClose(context);
52
52
  }
53
- }, [analytics.ui, onClose, origin]);
53
+ }, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onClose, origin]);
54
54
  const handleOnResize = useCallback(context => {
55
- analytics.ui.buttonClickedEvent({
55
+ analytics === null || analytics === void 0 ? void 0 : analytics.ui.buttonClickedEvent({
56
56
  actionSubjectId: 'embedPreviewResize',
57
57
  attributes: {
58
58
  newSize: context.size,
@@ -63,7 +63,7 @@ const withAnalytics = Component => props => {
63
63
  if (onResize) {
64
64
  onResize(context);
65
65
  }
66
- }, [analytics.ui, onResize, origin]);
66
+ }, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onResize, origin]);
67
67
  return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
68
68
  onClose: handleOnClose,
69
69
  onOpen: handleOnOpen,
@@ -0,0 +1,77 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React from 'react';
3
+ import ReactDOM from 'react-dom';
4
+ import { IntlProvider } from 'react-intl-next';
5
+ import Icon from '../FlexibleCard/components/elements/icon';
6
+ export const openPreviewModal = ({
7
+ analytics,
8
+ downloadUrl: download,
9
+ isSupportTheming,
10
+ linkIcon,
11
+ onClose = () => {},
12
+ providerName,
13
+ src,
14
+ title,
15
+ url
16
+ }) => {
17
+ const EmbedIcon = {
18
+ icon: /*#__PURE__*/React.createElement(Icon, linkIcon),
19
+ isFlexibleUi: true
20
+ };
21
+ return previewFunction({
22
+ popupMountPointId: 'twp-editor-preview-iframe',
23
+ showModal: true,
24
+ iframeName: 'twp-editor-preview-iframe',
25
+ onClose,
26
+ download,
27
+ icon: EmbedIcon,
28
+ providerName: providerName || 'Preview',
29
+ src,
30
+ title,
31
+ url,
32
+ analytics,
33
+ origin: 'smartLinkCard',
34
+ isSupportTheming
35
+ });
36
+ };
37
+
38
+ /*
39
+ Explanatory note:
40
+ Actions don't have access to the react tree of whatever is rendered them
41
+ (and this concept is fraught inside editor anyway) so we want to ensure
42
+ it is mounting to a new unique place. This function manages that, including
43
+ creating an element if it doesn't exist, as well as tidying up the react tree
44
+ (but not the element) upon closing the modal.
45
+
46
+ This may strike you as really uncomfortable as you read it, so I wanted to note
47
+ that a) this was discussed and agreed upon, and b) it's definitely odd, and if
48
+ you find an elegant solution around this, you should definitely feel free to
49
+ refactor it.
50
+ */
51
+ export async function previewFunction({
52
+ popupMountPointId,
53
+ onClose: onEmbedClose,
54
+ ...rest
55
+ }) {
56
+ let popupMountPoint;
57
+ popupMountPoint = document.getElementById(popupMountPointId);
58
+ if (!popupMountPoint) {
59
+ popupMountPoint = document.createElement('div');
60
+ popupMountPoint.id = popupMountPointId;
61
+ popupMountPoint.setAttribute('data-testid', 'preview-modal');
62
+ document.body.appendChild(popupMountPoint);
63
+ }
64
+ let Modal = await import('./index');
65
+ ReactDOM.render( /*#__PURE__*/React.createElement(IntlProvider, {
66
+ locale: "en"
67
+ }, /*#__PURE__*/React.createElement(Modal.default, _extends({}, rest, {
68
+ onClose: _context => {
69
+ if (popupMountPoint) {
70
+ ReactDOM.unmountComponentAtNode(popupMountPoint);
71
+ }
72
+ if (onEmbedClose) {
73
+ onEmbedClose(_context);
74
+ }
75
+ }
76
+ }))), popupMountPoint);
77
+ }