@atlaskit/smart-card 23.3.1 → 23.4.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 (96) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/cjs/constants.js +3 -0
  3. package/dist/cjs/extractors/common/actions/extractActions.js +3 -0
  4. package/dist/cjs/extractors/flexible/actions/extract-download-action.js +26 -0
  5. package/dist/cjs/extractors/flexible/actions/extract-preview-action.js +36 -0
  6. package/dist/cjs/extractors/flexible/actions/extract-view-action.js +26 -0
  7. package/dist/cjs/extractors/flexible/index.js +9 -0
  8. package/dist/cjs/state/flexible-ui-context/index.js +15 -2
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/cjs/view/FlexibleCard/components/actions/action/download-action/index.js +110 -0
  11. package/dist/cjs/view/FlexibleCard/components/actions/action/download-action/types.js +5 -0
  12. package/dist/cjs/view/FlexibleCard/components/actions/action/preview-action/index.js +167 -0
  13. package/dist/cjs/view/FlexibleCard/components/actions/action/preview-action/types.js +5 -0
  14. package/dist/cjs/view/FlexibleCard/components/actions/action/view-action/index.js +92 -0
  15. package/dist/cjs/view/FlexibleCard/components/actions/action/view-action/types.js +5 -0
  16. package/dist/cjs/view/FlexibleCard/components/actions/index.js +26 -2
  17. package/dist/cjs/view/FlexibleCard/components/actions/utils.js +51 -2
  18. package/dist/cjs/view/FlexibleCard/components/blocks/action-group/index.js +19 -13
  19. package/dist/cjs/view/FlexibleCard/components/blocks/utils.js +9 -4
  20. package/dist/cjs/view/FlexibleCard/components/elements/media/index.js +1 -1
  21. package/dist/cjs/view/FlexibleCard/index.js +6 -3
  22. package/dist/cjs/view/InlineCard/UnauthorisedView/index.js +8 -1
  23. package/dist/cjs/view/InlineCard/index.js +1 -0
  24. package/dist/cjs/view/common/Icon.js +25 -13
  25. package/dist/es2019/constants.js +3 -0
  26. package/dist/es2019/extractors/common/actions/extractActions.js +1 -2
  27. package/dist/es2019/extractors/flexible/actions/extract-download-action.js +13 -0
  28. package/dist/es2019/extractors/flexible/actions/extract-preview-action.js +23 -0
  29. package/dist/es2019/extractors/flexible/actions/extract-view-action.js +13 -0
  30. package/dist/es2019/extractors/flexible/index.js +7 -1
  31. package/dist/es2019/state/flexible-ui-context/index.js +8 -1
  32. package/dist/es2019/version.json +1 -1
  33. package/dist/es2019/view/FlexibleCard/components/actions/action/download-action/index.js +66 -0
  34. package/dist/es2019/view/FlexibleCard/components/actions/action/download-action/types.js +1 -0
  35. package/dist/es2019/view/FlexibleCard/components/actions/action/preview-action/index.js +104 -0
  36. package/dist/es2019/view/FlexibleCard/components/actions/action/preview-action/types.js +1 -0
  37. package/dist/es2019/view/FlexibleCard/components/actions/action/view-action/index.js +46 -0
  38. package/dist/es2019/view/FlexibleCard/components/actions/action/view-action/types.js +1 -0
  39. package/dist/es2019/view/FlexibleCard/components/actions/index.js +23 -2
  40. package/dist/es2019/view/FlexibleCard/components/actions/utils.js +48 -2
  41. package/dist/es2019/view/FlexibleCard/components/blocks/action-group/index.js +12 -9
  42. package/dist/es2019/view/FlexibleCard/components/blocks/utils.js +9 -4
  43. package/dist/es2019/view/FlexibleCard/components/elements/media/index.js +1 -1
  44. package/dist/es2019/view/FlexibleCard/index.js +7 -4
  45. package/dist/es2019/view/InlineCard/UnauthorisedView/index.js +7 -1
  46. package/dist/es2019/view/InlineCard/index.js +1 -0
  47. package/dist/es2019/view/common/Icon.js +31 -13
  48. package/dist/esm/constants.js +3 -0
  49. package/dist/esm/extractors/common/actions/extractActions.js +1 -2
  50. package/dist/esm/extractors/flexible/actions/extract-download-action.js +15 -0
  51. package/dist/esm/extractors/flexible/actions/extract-preview-action.js +23 -0
  52. package/dist/esm/extractors/flexible/actions/extract-view-action.js +15 -0
  53. package/dist/esm/extractors/flexible/index.js +7 -1
  54. package/dist/esm/state/flexible-ui-context/index.js +9 -0
  55. package/dist/esm/version.json +1 -1
  56. package/dist/esm/view/FlexibleCard/components/actions/action/download-action/index.js +96 -0
  57. package/dist/esm/view/FlexibleCard/components/actions/action/download-action/types.js +1 -0
  58. package/dist/esm/view/FlexibleCard/components/actions/action/preview-action/index.js +136 -0
  59. package/dist/esm/view/FlexibleCard/components/actions/action/preview-action/types.js +1 -0
  60. package/dist/esm/view/FlexibleCard/components/actions/action/view-action/index.js +77 -0
  61. package/dist/esm/view/FlexibleCard/components/actions/action/view-action/types.js +1 -0
  62. package/dist/esm/view/FlexibleCard/components/actions/index.js +23 -2
  63. package/dist/esm/view/FlexibleCard/components/actions/utils.js +45 -2
  64. package/dist/esm/view/FlexibleCard/components/blocks/action-group/index.js +19 -13
  65. package/dist/esm/view/FlexibleCard/components/blocks/utils.js +9 -4
  66. package/dist/esm/view/FlexibleCard/components/elements/media/index.js +1 -1
  67. package/dist/esm/view/FlexibleCard/index.js +7 -4
  68. package/dist/esm/view/InlineCard/UnauthorisedView/index.js +7 -1
  69. package/dist/esm/view/InlineCard/index.js +1 -0
  70. package/dist/esm/view/common/Icon.js +27 -13
  71. package/dist/types/constants.d.ts +3 -0
  72. package/dist/types/extractors/common/__mocks__/jsonld.d.ts +112 -0
  73. package/dist/types/extractors/common/actions/extractActions.d.ts +1 -0
  74. package/dist/types/extractors/flexible/actions/extract-download-action.d.ts +3 -0
  75. package/dist/types/extractors/flexible/actions/extract-preview-action.d.ts +3 -0
  76. package/dist/types/extractors/flexible/actions/extract-view-action.d.ts +3 -0
  77. package/dist/types/state/flexible-ui-context/index.d.ts +76 -0
  78. package/dist/types/state/flexible-ui-context/types.d.ts +32 -0
  79. package/dist/types/view/BlockCard/actions/PreviewAction.d.ts +2 -2
  80. package/dist/types/view/EmbedModal/index.d.ts +20 -2
  81. package/dist/types/view/EmbedModal/types.d.ts +1 -2
  82. package/dist/types/view/FlexibleCard/components/actions/action/download-action/index.d.ts +4 -0
  83. package/dist/types/view/FlexibleCard/components/actions/action/download-action/types.d.ts +8 -0
  84. package/dist/types/view/FlexibleCard/components/actions/action/preview-action/index.d.ts +5 -0
  85. package/dist/types/view/FlexibleCard/components/actions/action/preview-action/types.d.ts +15 -0
  86. package/dist/types/view/FlexibleCard/components/actions/action/view-action/index.d.ts +5 -0
  87. package/dist/types/view/FlexibleCard/components/actions/action/view-action/types.d.ts +8 -0
  88. package/dist/types/view/FlexibleCard/components/actions/index.d.ts +21 -0
  89. package/dist/types/view/FlexibleCard/components/blocks/types.d.ts +50 -3
  90. package/dist/types/view/FlexibleCard/components/blocks/utils.d.ts +1 -1
  91. package/dist/types/view/FlexibleCard/types.d.ts +6 -0
  92. package/dist/types/view/InlineCard/UnauthorisedView/index.d.ts +2 -0
  93. package/dist/types/view/common/Icon.d.ts +2 -1
  94. package/package.json +1 -1
  95. package/report.api.md +30 -2
  96. package/tmp/api-report-tmp.d.ts +25 -3
@@ -29,6 +29,18 @@ var _cross = _interopRequireDefault(require("@atlaskit/icon/glyph/cross"));
29
29
 
30
30
  var _edit = _interopRequireDefault(require("@atlaskit/icon/glyph/edit"));
31
31
 
32
+ var _previewAction = _interopRequireDefault(require("./action/preview-action"));
33
+
34
+ var _vidFullScreenOn = _interopRequireDefault(require("@atlaskit/icon/glyph/vid-full-screen-on"));
35
+
36
+ var _viewAction = _interopRequireDefault(require("./action/view-action"));
37
+
38
+ var _shortcut = _interopRequireDefault(require("@atlaskit/icon/glyph/shortcut"));
39
+
40
+ var _downloadAction = _interopRequireDefault(require("./action/download-action"));
41
+
42
+ var _download = _interopRequireDefault(require("@atlaskit/icon/glyph/download"));
43
+
32
44
  var _actionMappings;
33
45
 
34
46
  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); }
@@ -62,6 +74,36 @@ var actionMappings = (_actionMappings = {}, (0, _defineProperty2.default)(_actio
62
74
  }),
63
75
  tooltipMessage: /*#__PURE__*/_react.default.createElement(_reactIntlNext.FormattedMessage, _messages.messages.edit)
64
76
  }
77
+ }), (0, _defineProperty2.default)(_actionMappings, _constants.ActionName.PreviewAction, {
78
+ component: _previewAction.default,
79
+ props: {
80
+ testId: 'smart-action-preview-action',
81
+ content: /*#__PURE__*/_react.default.createElement(_reactIntlNext.FormattedMessage, _messages.messages.preview),
82
+ icon: /*#__PURE__*/_react.default.createElement(_vidFullScreenOn.default, {
83
+ label: "Preview"
84
+ }),
85
+ tooltipMessage: /*#__PURE__*/_react.default.createElement(_reactIntlNext.FormattedMessage, _messages.messages.preview)
86
+ }
87
+ }), (0, _defineProperty2.default)(_actionMappings, _constants.ActionName.ViewAction, {
88
+ component: _viewAction.default,
89
+ props: {
90
+ testId: 'smart-action-view-action',
91
+ content: /*#__PURE__*/_react.default.createElement(_reactIntlNext.FormattedMessage, _messages.messages.view),
92
+ icon: /*#__PURE__*/_react.default.createElement(_shortcut.default, {
93
+ label: "View"
94
+ }),
95
+ tooltipMessage: /*#__PURE__*/_react.default.createElement(_reactIntlNext.FormattedMessage, _messages.messages.view)
96
+ }
97
+ }), (0, _defineProperty2.default)(_actionMappings, _constants.ActionName.DownloadAction, {
98
+ component: _downloadAction.default,
99
+ props: {
100
+ testId: 'smart-action-download-action',
101
+ content: /*#__PURE__*/_react.default.createElement(_reactIntlNext.FormattedMessage, _messages.messages.download),
102
+ icon: /*#__PURE__*/_react.default.createElement(_download.default, {
103
+ label: "Download"
104
+ }),
105
+ tooltipMessage: /*#__PURE__*/_react.default.createElement(_reactIntlNext.FormattedMessage, _messages.messages.download)
106
+ }
65
107
  }), _actionMappings);
66
108
 
67
109
  var getContextKey = function getContextKey(name) {
@@ -78,8 +120,13 @@ var getActionData = function getActionData(actionName, contextKey, context) {
78
120
  var data = context[contextKey];
79
121
 
80
122
  switch (actionName) {
81
- default:
123
+ case _constants.ActionName.PreviewAction:
124
+ case _constants.ActionName.ViewAction:
125
+ case _constants.ActionName.DownloadAction:
82
126
  return data;
127
+
128
+ default:
129
+ return undefined;
83
130
  }
84
131
  };
85
132
 
@@ -97,7 +144,9 @@ var createDataAction = function createDataAction(name) {
97
144
  return function (overrides) {
98
145
  var context = (0, _react.useContext)(_flexibleUiContext.FlexibleUiContext);
99
146
  var data = getActionData(name, contextKey, context);
100
- return /*#__PURE__*/_react.default.createElement(BaseAction, (0, _extends2.default)({}, props, data, overrides));
147
+ return data ? /*#__PURE__*/_react.default.createElement(BaseAction, (0, _extends2.default)({}, props, data, overrides, {
148
+ url: context === null || context === void 0 ? void 0 : context.url
149
+ })) : null;
101
150
  };
102
151
  };
103
152
 
@@ -68,17 +68,7 @@ var ActionGroup = function ActionGroup(_ref) {
68
68
  var _useState = (0, _react.useState)(false),
69
69
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
70
70
  isOpen = _useState2[0],
71
- setIsOpen = _useState2[1];
72
-
73
- var _useMemo = (0, _react.useMemo)(function () {
74
- var isMoreThenTwoItems = items.length > visibleButtonsNum;
75
- var buttons = isMoreThenTwoItems ? items.slice(0, visibleButtonsNum - 1) : items;
76
- var dropdownItems = isMoreThenTwoItems ? items.slice(visibleButtonsNum - 1) : [];
77
- return [buttons, dropdownItems];
78
- }, [items, visibleButtonsNum]),
79
- _useMemo2 = (0, _slicedToArray2.default)(_useMemo, 2),
80
- buttonActions = _useMemo2[0],
81
- dropdownItemActions = _useMemo2[1]; // Stop AK dropdown menu to propagate event on click.
71
+ setIsOpen = _useState2[1]; // Stop AK dropdown menu to propagate event on click.
82
72
 
83
73
 
84
74
  var onClick = (0, _react.useCallback)(function (e) {
@@ -98,11 +88,27 @@ var ActionGroup = function ActionGroup(_ref) {
98
88
  });
99
89
  }
100
90
  }, [isOpen, onOpenChange]);
91
+ var renderableActions = items.filter(function (action) {
92
+ return (0, _utils.renderActionItems)([action]);
93
+ });
94
+
95
+ var _useMemo = (0, _react.useMemo)(function () {
96
+ var isMoreThenTwoItems = renderableActions && renderableActions.length > visibleButtonsNum;
97
+ var buttons = isMoreThenTwoItems ? renderableActions.slice(0, visibleButtonsNum - 1) : renderableActions;
98
+ var dropdownItems = isMoreThenTwoItems ? renderableActions.slice(visibleButtonsNum - 1) : [];
99
+ return [buttons, dropdownItems];
100
+ }, [renderableActions, visibleButtonsNum]),
101
+ _useMemo2 = (0, _slicedToArray2.default)(_useMemo, 2),
102
+ buttonActions = _useMemo2[0],
103
+ dropdownItemActions = _useMemo2[1];
104
+
105
+ var dropdownMenuElement = (0, _utils.renderActionItems)(dropdownItemActions, size, appearance, true, onActionClick);
106
+ var buttonGroupElement = (0, _utils.renderActionItems)(buttonActions, size, appearance, false, onActionClick);
101
107
  return (0, _react2.jsx)("div", {
102
108
  css: styles,
103
109
  className: "actions-button-group",
104
110
  onClick: onClick
105
- }, (0, _react2.jsx)(_buttonGroup.default, null, (0, _utils.renderActionItems)(buttonActions, size, appearance, false, onActionClick), dropdownItemActions.length > 0 ? (0, _react2.jsx)(_dropdownMenu.default, {
111
+ }, (0, _react2.jsx)(_buttonGroup.default, null, buttonGroupElement, dropdownItemActions.length > 0 && dropdownMenuElement && dropdownMenuElement.length > 0 ? (0, _react2.jsx)(_dropdownMenu.default, {
106
112
  isOpen: isOpen,
107
113
  onOpenChange: onOpenChange,
108
114
  trigger: function trigger(_ref2) {
@@ -123,7 +129,7 @@ var ActionGroup = function ActionGroup(_ref) {
123
129
  })));
124
130
  },
125
131
  testId: "action-group-dropdown"
126
- }, (0, _utils.renderActionItems)(dropdownItemActions, size, appearance, true, onActionClick)) : null));
132
+ }, dropdownMenuElement) : null));
127
133
  };
128
134
 
129
135
  var _default = ActionGroup;
@@ -99,7 +99,7 @@ var isElementDisplayValid = function isElementDisplayValid(name, display) {
99
99
  return (_ElementDisplaySchema2 = (_ElementDisplaySchema3 = ElementDisplaySchema[name]) === null || _ElementDisplaySchema3 === void 0 ? void 0 : _ElementDisplaySchema3.includes(display)) !== null && _ElementDisplaySchema2 !== void 0 ? _ElementDisplaySchema2 : false;
100
100
  };
101
101
 
102
- var isElementNull = function isElementNull(children) {
102
+ var isJSXElementNull = function isJSXElementNull(children) {
103
103
  return Boolean(children.type() === null);
104
104
  };
105
105
 
@@ -137,7 +137,7 @@ var renderElementItems = function renderElementItems() {
137
137
  key: idx
138
138
  }, typedProps));
139
139
 
140
- if (!isElementNull(element)) {
140
+ if (!isJSXElementNull(element)) {
141
141
  return [].concat((0, _toConsumableArray2.default)(acc), [element]);
142
142
  }
143
143
  }
@@ -187,13 +187,18 @@ var renderActionItems = function renderActionItems() {
187
187
  }
188
188
  };
189
189
 
190
- return [].concat((0, _toConsumableArray2.default)(acc), [/*#__PURE__*/_react.default.createElement(Action, (0, _extends2.default)({
190
+ var action = /*#__PURE__*/_react.default.createElement(Action, (0, _extends2.default)({
191
+ url: '',
191
192
  asDropDownItem: asDropDownItems,
192
193
  size: size,
193
194
  key: idx,
194
195
  appearance: appearance,
195
196
  onClick: handleOnClick
196
- }, actionProps))]);
197
+ }, actionProps));
198
+
199
+ if (!isJSXElementNull(action)) {
200
+ return [].concat((0, _toConsumableArray2.default)(acc), [action]);
201
+ }
197
202
  }
198
203
 
199
204
  return acc;
@@ -51,7 +51,7 @@ var Media = function Media(_ref) {
51
51
  return (0, _react2.jsx)("div", {
52
52
  css: [styles, overrideCss],
53
53
  "data-smart-element": name,
54
- "data-smart-element-media": true,
54
+ "data-smart-element-media": type,
55
55
  "data-testid": testId
56
56
  }, (0, _react2.jsx)(_imageIcon.default, {
57
57
  testId: "".concat(testId, "-image"),
@@ -41,7 +41,8 @@ var FlexibleCard = function FlexibleCard(_ref) {
41
41
  ui = _ref.ui,
42
42
  url = _ref.url,
43
43
  onClick = _ref.onClick,
44
- testId = _ref.testId;
44
+ testId = _ref.testId,
45
+ analytics = _ref.analytics;
45
46
  var cardType = cardState.status,
46
47
  details = cardState.details;
47
48
  var status = cardType;
@@ -78,7 +79,9 @@ var FlexibleCard = function FlexibleCard(_ref) {
78
79
  break;
79
80
  }
80
81
  }, [onError, onResolve, status, title, url]);
81
- return /*#__PURE__*/_react.default.createElement(_flexibleUiContext.FlexibleUiContext.Provider, {
82
+ return /*#__PURE__*/_react.default.createElement(_flexibleUiContext.FlexibleUiAnalyticsContext.Provider, {
83
+ value: analytics
84
+ }, /*#__PURE__*/_react.default.createElement(_flexibleUiContext.FlexibleUiContext.Provider, {
82
85
  value: context
83
86
  }, /*#__PURE__*/_react.default.createElement(_container.default, (0, _extends2.default)({
84
87
  testId: testId
@@ -86,7 +89,7 @@ var FlexibleCard = function FlexibleCard(_ref) {
86
89
  onClick: onClick,
87
90
  retry: retry,
88
91
  status: status
89
- }), children));
92
+ }), children)));
90
93
  };
91
94
 
92
95
  var _default = FlexibleCard;
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.InlineCardUnauthorizedView = void 0;
9
9
 
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
10
12
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
13
 
12
14
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -76,6 +78,7 @@ var InlineCardUnauthorizedView = /*#__PURE__*/function (_React$Component) {
76
78
  });
77
79
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderMessage", function () {
78
80
  var _this$props = _this.props,
81
+ context = _this$props.context,
79
82
  onAuthorise = _this$props.onAuthorise,
80
83
  url = _this$props.url;
81
84
 
@@ -87,7 +90,11 @@ var InlineCardUnauthorizedView = /*#__PURE__*/function (_React$Component) {
87
90
  component: _styled.IconStyledButton,
88
91
  onClick: _this.handleConnectAccount,
89
92
  testId: "button-connect-account"
90
- }, /*#__PURE__*/_react.default.createElement(_reactIntlNext.FormattedMessage, _messages.messages.connect_link_account)));
93
+ }, /*#__PURE__*/_react.default.createElement(_reactIntlNext.FormattedMessage, (0, _extends2.default)({}, _messages.messages.connect_link_account_card_name, {
94
+ values: {
95
+ context: context
96
+ }
97
+ }))));
91
98
  });
92
99
  return _this;
93
100
  }
@@ -122,6 +122,7 @@ var InlineCard = function InlineCard(_ref) {
122
122
  var provider = (0, _extractors.extractProvider)(cardDetails);
123
123
  return /*#__PURE__*/_react.default.createElement(_UnauthorisedView.InlineCardUnauthorizedView, {
124
124
  icon: provider && provider.icon,
125
+ context: provider && provider.text,
125
126
  url: url,
126
127
  isSelected: isSelected,
127
128
  onClick: handleFrameClick,
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.blockCardIconImageClassName = exports.Icon = void 0;
9
9
 
10
+ var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
11
+
10
12
  var _react = require("@emotion/react");
11
13
 
12
14
  var _react2 = _interopRequireDefault(require("react"));
@@ -17,16 +19,35 @@ var _link = _interopRequireDefault(require("@atlaskit/icon/glyph/link"));
17
19
 
18
20
  var _utils = require("./utils");
19
21
 
20
- /** @jsx jsx */
22
+ var _templateObject, _templateObject2;
23
+
21
24
  var blockCardIconImageClassName = 'block-card-icon-image';
22
25
  exports.blockCardIconImageClassName = blockCardIconImageClassName;
23
26
 
27
+ var getImageStyles = function getImageStyles(isFlexibleUi) {
28
+ if (isFlexibleUi) {
29
+ return;
30
+ }
31
+
32
+ return (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n height: ", ";\n width: ", ";\n "])), (0, _utils.gs)(2), (0, _utils.gs)(2));
33
+ };
34
+
35
+ var getSpanStyles = function getSpanStyles(isFlexibleUi) {
36
+ if (isFlexibleUi) {
37
+ return;
38
+ }
39
+
40
+ return (0, _react.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n height: ", ";\n width: ", ";\n display: flex;\n align-items: center;\n justify-content: center;\n "])), (0, _utils.gs)(2.5), (0, _utils.gs)(2));
41
+ };
42
+
24
43
  var Icon = function Icon(_ref) {
25
44
  var url = _ref.url,
26
45
  icon = _ref.icon,
27
46
  defaultIcon = _ref.defaultIcon,
28
47
  _ref$testId = _ref.testId,
29
- testId = _ref$testId === void 0 ? 'block-card-icon' : _ref$testId;
48
+ testId = _ref$testId === void 0 ? 'block-card-icon' : _ref$testId,
49
+ _ref$isFlexibleUi = _ref.isFlexibleUi,
50
+ isFlexibleUi = _ref$isFlexibleUi === void 0 ? false : _ref$isFlexibleUi;
30
51
  var placeholder = defaultIcon || (0, _react.jsx)(_link.default, {
31
52
  label: "link",
32
53
  size: "small",
@@ -35,23 +56,14 @@ var Icon = function Icon(_ref) {
35
56
  var image = url && (0, _react.jsx)(_reactRenderImage.default, {
36
57
  src: url,
37
58
  loaded: (0, _react.jsx)("img", {
38
- css: {
39
- height: (0, _utils.gs)(2),
40
- width: (0, _utils.gs)(2)
41
- },
59
+ css: getImageStyles(isFlexibleUi),
42
60
  src: url,
43
61
  "data-testid": "".concat(testId, "-image")
44
62
  }),
45
63
  errored: placeholder
46
64
  });
47
65
  return (0, _react.jsx)("span", {
48
- css: {
49
- height: (0, _utils.gs)(2.5),
50
- width: (0, _utils.gs)(2),
51
- display: 'flex',
52
- alignItems: 'center',
53
- justifyContent: 'center'
54
- },
66
+ css: getSpanStyles(isFlexibleUi),
55
67
  "data-testid": testId,
56
68
  className: blockCardIconImageClassName
57
69
  }, icon || image || placeholder);
@@ -142,6 +142,9 @@ export let ActionName;
142
142
  (function (ActionName) {
143
143
  ActionName["DeleteAction"] = "DeleteAction";
144
144
  ActionName["EditAction"] = "EditAction";
145
+ ActionName["PreviewAction"] = "PreviewAction";
146
+ ActionName["ViewAction"] = "ViewAction";
147
+ ActionName["DownloadAction"] = "DownloadAction";
145
148
  ActionName["CustomAction"] = "CustomAction";
146
149
  })(ActionName || (ActionName = {}));
147
150
 
@@ -54,7 +54,7 @@ const getServerActionProps = (jsonLd, action, handler) => {
54
54
  };
55
55
  };
56
56
 
57
- const getActionsFromJsonLd = jsonLd => {
57
+ export const getActionsFromJsonLd = jsonLd => {
58
58
  let actions = jsonLd && jsonLd['schema:potentialAction'];
59
59
 
60
60
  if (!actions) {
@@ -67,7 +67,6 @@ const getActionsFromJsonLd = jsonLd => {
67
67
 
68
68
  return actions;
69
69
  };
70
-
71
70
  export function extractActions(jsonLd, handler) {
72
71
  const actions = getActionsFromJsonLd(jsonLd);
73
72
  const clientActions = actions.filter(isClientAction);
@@ -0,0 +1,13 @@
1
+ import { getActionsFromJsonLd } from '../../common/actions/extractActions';
2
+ import { extractDownloadUrl } from '../../common/detail';
3
+ export const extractDownloadAction = data => {
4
+ const downloadActionExists = getActionsFromJsonLd(data).find(action => action['@type'] === 'DownloadAction');
5
+
6
+ if (downloadActionExists) {
7
+ return {
8
+ downloadUrl: extractDownloadUrl(data)
9
+ };
10
+ }
11
+
12
+ return undefined;
13
+ };
@@ -0,0 +1,23 @@
1
+ import { extractDownloadUrl } from '../../common/detail';
2
+ import { extractPreview as extractPreviewData } from '@atlaskit/linking-common';
3
+ import { extractLink, extractProvider, extractTitle } from '@atlaskit/linking-common/extractors';
4
+ import { extractLinkIcon } from '../icon';
5
+ export const extractPreviewAction = response => {
6
+ var _extractPreviewData;
7
+
8
+ const data = response.data;
9
+ const src = (_extractPreviewData = extractPreviewData(data, 'web')) === null || _extractPreviewData === void 0 ? void 0 : _extractPreviewData.src;
10
+
11
+ if (src) {
12
+ var _extractProvider;
13
+
14
+ return {
15
+ downloadUrl: extractDownloadUrl(data),
16
+ providerName: (_extractProvider = extractProvider(data)) === null || _extractProvider === void 0 ? void 0 : _extractProvider.text,
17
+ src,
18
+ title: extractTitle(data),
19
+ linkIcon: extractLinkIcon(response),
20
+ url: extractLink(data)
21
+ };
22
+ }
23
+ };
@@ -0,0 +1,13 @@
1
+ import { extractLink } from '@atlaskit/linking-common/extractors';
2
+ import { getActionsFromJsonLd } from '../../common/actions/extractActions';
3
+ export const extractViewAction = data => {
4
+ const viewActionExists = getActionsFromJsonLd(data).find(action => action['@type'] === 'ViewAction');
5
+
6
+ if (viewActionExists) {
7
+ return {
8
+ viewUrl: extractLink(data)
9
+ };
10
+ }
11
+
12
+ return undefined;
13
+ };
@@ -3,11 +3,14 @@ import { extractLozenge } from '../common/lozenge';
3
3
  import { extractLinkIcon } from './icon';
4
4
  import { extractAttachmentCount, extractCommentCount, extractCreatedBy, extractModifiedBy, extractProgrammingLanguage, extractSubscriberCount, extractViewCount, extractReactCount, extractVoteCount, extractSourceBranch, extractTargetBranch, extractDueOn } from './utils';
5
5
  import { extractPersonsUpdatedBy } from './collaboratorGroup';
6
- import { extractPersonCreatedBy, extractLink, extractTitle, extractDateUpdated, extractDateCreated } from '@atlaskit/linking-common/extractors';
6
+ import { extractPersonCreatedBy, extractTitle, extractDateUpdated, extractDateCreated, extractLink } from '@atlaskit/linking-common/extractors';
7
7
  import extractPriority from './extract-priority';
8
8
  import extractProviderIcon from './icon/extract-provider-icon';
9
9
  import extractPreview from './extract-preview';
10
10
  import { extractLatestCommit } from './latest-commit';
11
+ import { extractPreviewAction } from './actions/extract-preview-action';
12
+ import { extractDownloadAction } from './actions/extract-download-action';
13
+ import { extractViewAction } from './actions/extract-view-action';
11
14
 
12
15
  const extractFlexibleUiContext = (response, renderers) => {
13
16
  if (!response) {
@@ -27,6 +30,9 @@ const extractFlexibleUiContext = (response, renderers) => {
27
30
  createdBy: extractCreatedBy(data),
28
31
  createdOn: extractDateCreated(data),
29
32
  dueOn: extractDueOn(data),
33
+ previewAction: extractPreviewAction(response),
34
+ viewAction: extractViewAction(data),
35
+ downloadAction: extractDownloadAction(data),
30
36
  latestCommit: extractLatestCommit(data),
31
37
  linkIcon: extractLinkIcon(response, renderers),
32
38
  modifiedBy: extractModifiedBy(data),
@@ -5,4 +5,11 @@ import { useContext, createContext } from 'react';
5
5
  * underlying elements.
6
6
  */
7
7
  export const FlexibleUiContext = /*#__PURE__*/createContext(undefined);
8
- export const useFlexibleUiContext = () => useContext(FlexibleUiContext);
8
+ export const useFlexibleUiContext = () => useContext(FlexibleUiContext);
9
+ /**
10
+ * This provides the data that will be used by Smart Links Flexible UI to populate it's
11
+ * underlying elements.
12
+ */
13
+
14
+ export const FlexibleUiAnalyticsContext = /*#__PURE__*/createContext(undefined);
15
+ export const useFlexibleUiAnalyticsContext = () => useContext(FlexibleUiAnalyticsContext);
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "23.3.1",
3
+ "version": "23.4.1",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,66 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React from 'react';
3
+ import Action from '../index';
4
+
5
+ const DownloadAction = props => {
6
+ const {
7
+ appearance,
8
+ asDropDownItem,
9
+ downloadUrl,
10
+ onClick,
11
+ testId,
12
+ url
13
+ } = props;
14
+
15
+ if (downloadUrl && url) {
16
+ const action = { ...props,
17
+ onClick: () => {
18
+ downloadFunction({
19
+ url: downloadUrl
20
+ });
21
+
22
+ if (onClick) {
23
+ onClick();
24
+ }
25
+ }
26
+ };
27
+ return /*#__PURE__*/React.createElement(Action, _extends({}, action, {
28
+ appearance: appearance,
29
+ asDropDownItem: asDropDownItem,
30
+ testId: testId
31
+ }));
32
+ } else {
33
+ return null;
34
+ }
35
+ };
36
+
37
+ async function downloadFunction({
38
+ url
39
+ }) {
40
+ if (!url) {
41
+ return;
42
+ }
43
+
44
+ const isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
45
+ const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
46
+ const iframeName = 'media-download-iframe';
47
+ const link = document.createElement('a');
48
+ let iframe = document.getElementById(iframeName);
49
+
50
+ if (!iframe) {
51
+ iframe = document.createElement('iframe');
52
+ iframe.style.display = 'none';
53
+ iframe.id = iframeName;
54
+ iframe.name = iframeName;
55
+ document.body.appendChild(iframe);
56
+ }
57
+
58
+ link.href = url;
59
+ link.download = url;
60
+ link.target = isIE11 || isSafari ? '_blank' : iframeName;
61
+ document.body.appendChild(link);
62
+ link.click();
63
+ document.body.removeChild(link);
64
+ }
65
+
66
+ export default DownloadAction;
@@ -0,0 +1,104 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React from 'react';
3
+ import Action from '../index';
4
+ import ReactDOM from 'react-dom';
5
+ import { IntlProvider } from 'react-intl-next';
6
+ import { useFlexibleUiAnalyticsContext } from '../../../../../../state/flexible-ui-context';
7
+ import { useSmartLinkAnalytics } from '../../../../../../state';
8
+ import Icon from '../../../elements/icon';
9
+
10
+ const PreviewAction = props => {
11
+ const {
12
+ appearance,
13
+ asDropDownItem,
14
+ testId,
15
+ onClick,
16
+ linkIcon,
17
+ src,
18
+ url,
19
+ title,
20
+ providerName,
21
+ downloadUrl
22
+ } = props;
23
+ const defaultAnalytics = useSmartLinkAnalytics(url, () => {});
24
+ const analytics = useFlexibleUiAnalyticsContext() || defaultAnalytics;
25
+ const EmbedIcon = {
26
+ icon: /*#__PURE__*/React.createElement(Icon, linkIcon),
27
+ isFlexibleUi: true
28
+ };
29
+
30
+ if (src && url) {
31
+ const embedModal = () => previewFunction({
32
+ popupMountPointId: 'twp-editor-preview-iframe',
33
+ showModal: true,
34
+ iframeName: 'twp-editor-preview-iframe',
35
+ onClose: () => {},
36
+ download: downloadUrl,
37
+ icon: EmbedIcon,
38
+ providerName: providerName || 'Preview',
39
+ src,
40
+ title,
41
+ url,
42
+ analytics,
43
+ origin: 'smartLinkCard'
44
+ });
45
+
46
+ const action = { ...props,
47
+ onClick: () => {
48
+ embedModal();
49
+
50
+ if (onClick) {
51
+ onClick();
52
+ }
53
+ }
54
+ };
55
+ return /*#__PURE__*/React.createElement(Action, _extends({}, action, {
56
+ appearance: appearance,
57
+ asDropDownItem: asDropDownItem,
58
+ testId: testId
59
+ }));
60
+ } else {
61
+ return null;
62
+ }
63
+ };
64
+ /*
65
+ Explanatory note:
66
+ Actions don't have access to the react tree of whatever is rendered them
67
+ (and this concept is fraught inside editor anyway) so we want to ensure
68
+ it is mounting to a new unique place. This function manages that, including
69
+ creating an element if it doesn't exist, as well as tidying up the react tree
70
+ (but not the element) upon closing the modal.
71
+
72
+ This may strike you as really uncomfortable as you read it, so I wanted to note
73
+ that a) this was discussed and agreed upon, and b) it's definitely odd, and if
74
+ you find an elegant solution around this, you should definitely feel free to
75
+ refactor it.
76
+ */
77
+
78
+
79
+ export async function previewFunction({
80
+ popupMountPointId,
81
+ ...rest
82
+ }) {
83
+ let popupMountPoint;
84
+ popupMountPoint = document.getElementById(popupMountPointId);
85
+
86
+ if (!popupMountPoint) {
87
+ popupMountPoint = document.createElement('div');
88
+ popupMountPoint.id = popupMountPointId;
89
+ popupMountPoint.setAttribute('data-testid', 'preview-modal');
90
+ document.body.appendChild(popupMountPoint);
91
+ }
92
+
93
+ let Modal = await import('../../../../../EmbedModal');
94
+ ReactDOM.render( /*#__PURE__*/React.createElement(IntlProvider, {
95
+ locale: "en"
96
+ }, /*#__PURE__*/React.createElement(Modal.default, _extends({}, rest, {
97
+ onClose: _context => {
98
+ if (popupMountPoint) {
99
+ ReactDOM.unmountComponentAtNode(popupMountPoint);
100
+ }
101
+ }
102
+ }))), popupMountPoint);
103
+ }
104
+ export default PreviewAction;